aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CREDITS3
-rw-r--r--Documentation/ABI/testing/sysfs-dev20
-rw-r--r--Documentation/DMA-attributes.txt9
-rw-r--r--Documentation/DocBook/gadget.tmpl38
-rw-r--r--Documentation/DocBook/uio-howto.tmpl63
-rw-r--r--Documentation/HOWTO2
-rw-r--r--Documentation/feature-removal-schedule.txt10
-rw-r--r--Documentation/filesystems/bfs.txt10
-rw-r--r--Documentation/filesystems/sysfs.txt6
-rw-r--r--Documentation/ia64/paravirt_ops.txt137
-rw-r--r--Documentation/input/gameport-programming.txt2
-rw-r--r--Documentation/input/input.txt1
-rw-r--r--Documentation/input/joystick-api.txt2
-rw-r--r--Documentation/input/joystick-parport.txt1
-rw-r--r--Documentation/input/joystick.txt1
-rw-r--r--Documentation/kernel-parameters.txt7
-rw-r--r--Documentation/md.txt30
-rw-r--r--Documentation/powerpc/booting-without-of.txt189
-rw-r--r--Documentation/powerpc/dts-bindings/fsl/cpm_qe/gpio.txt38
-rw-r--r--Documentation/powerpc/dts-bindings/fsl/cpm_qe/qe/usb.txt53
-rw-r--r--Documentation/powerpc/dts-bindings/fsl/mcu-mpc8349emitx.txt17
-rw-r--r--Documentation/powerpc/dts-bindings/fsl/pmc.txt63
-rw-r--r--Documentation/powerpc/dts-bindings/fsl/tsec.txt31
-rw-r--r--Documentation/powerpc/dts-bindings/fsl/upm-nand.txt28
-rw-r--r--Documentation/powerpc/dts-bindings/gpio/led.txt15
-rw-r--r--Documentation/sound/alsa/DocBook/alsa-driver-api.tmpl2
-rw-r--r--Documentation/specialix.txt8
-rw-r--r--Documentation/sysfs-rules.txt5
-rw-r--r--Documentation/telephony/ixj.txt13
-rw-r--r--Documentation/usb/gadget_serial.txt35
-rw-r--r--Documentation/usb/persist.txt7
-rw-r--r--Documentation/usb/uhci.txt165
-rw-r--r--Documentation/video4linux/w9968cf.txt3
-rw-r--r--MAINTAINERS13
-rw-r--r--Makefile3
-rw-r--r--arch/arm/common/dmabounce.c22
-rw-r--r--arch/arm/common/locomo.c2
-rw-r--r--arch/arm/common/sa1111.c10
-rw-r--r--arch/arm/common/scoop.c2
-rw-r--r--arch/arm/kernel/ecard.c5
-rw-r--r--arch/arm/kernel/time.c4
-rw-r--r--arch/arm/mach-integrator/impd1.c7
-rw-r--r--arch/arm/mach-integrator/lm.c6
-rw-r--r--arch/arm/plat-omap/mailbox.c2
-rw-r--r--arch/avr32/kernel/cpu.c38
-rw-r--r--arch/blackfin/Kconfig4
-rw-r--r--arch/ia64/Kconfig4
-rw-r--r--arch/ia64/Makefile6
-rw-r--r--arch/ia64/kernel/Makefile44
-rw-r--r--arch/ia64/kernel/acpi.c5
-rw-r--r--arch/ia64/kernel/cpufreq/acpi-cpufreq.c4
-rw-r--r--arch/ia64/kernel/entry.S115
-rw-r--r--arch/ia64/kernel/err_inject.c22
-rw-r--r--arch/ia64/kernel/head.S41
-rw-r--r--arch/ia64/kernel/iosapic.c45
-rw-r--r--arch/ia64/kernel/irq_ia64.c19
-rw-r--r--arch/ia64/kernel/ivt.S462
-rw-r--r--arch/ia64/kernel/minstate.h13
-rw-r--r--arch/ia64/kernel/module.c3
-rw-r--r--arch/ia64/kernel/nr-irqs.c24
-rw-r--r--arch/ia64/kernel/paravirt.c369
-rw-r--r--arch/ia64/kernel/paravirt_inst.h29
-rw-r--r--arch/ia64/kernel/paravirtentry.S60
-rw-r--r--arch/ia64/kernel/setup.c10
-rw-r--r--arch/ia64/kernel/smpboot.c2
-rw-r--r--arch/ia64/kernel/time.c23
-rw-r--r--arch/ia64/kernel/vmlinux.lds.S1
-rw-r--r--arch/mips/kernel/rtlx.c4
-rw-r--r--arch/mips/sibyte/common/sb_tbprof.c3
-rw-r--r--arch/powerpc/Kconfig14
-rw-r--r--arch/powerpc/boot/Makefile4
-rw-r--r--arch/powerpc/boot/dts/mpc7448hpc2.dts24
-rw-r--r--arch/powerpc/boot/dts/mpc8313erdb.dts241
-rw-r--r--arch/powerpc/boot/dts/mpc8610_hpcd.dts14
-rw-r--r--arch/powerpc/configs/85xx/mpc8544_ds_defconfig8
-rw-r--r--arch/powerpc/configs/85xx/mpc8572_ds_defconfig8
-rw-r--r--arch/powerpc/configs/mpc85xx_defconfig8
-rw-r--r--arch/powerpc/configs/mpc8610_hpcd_defconfig121
-rw-r--r--arch/powerpc/configs/mpc8641_hpcn_defconfig8
-rw-r--r--arch/powerpc/configs/ppc6xx_defconfig3304
-rw-r--r--arch/powerpc/configs/ps3_defconfig196
-rw-r--r--arch/powerpc/kernel/cputable.c20
-rw-r--r--arch/powerpc/kernel/head_fsl_booke.S187
-rw-r--r--arch/powerpc/kernel/iommu.c13
-rw-r--r--arch/powerpc/kernel/pci-common.c1
-rw-r--r--arch/powerpc/kernel/prom_parse.c44
-rw-r--r--arch/powerpc/kernel/stacktrace.c2
-rw-r--r--arch/powerpc/kernel/sysfs.c15
-rw-r--r--arch/powerpc/kernel/vmlinux.lds.S31
-rw-r--r--arch/powerpc/lib/feature-fixups.c2
-rw-r--r--arch/powerpc/lib/string.S18
-rw-r--r--arch/powerpc/platforms/52xx/Kconfig1
-rw-r--r--arch/powerpc/platforms/82xx/Kconfig1
-rw-r--r--arch/powerpc/platforms/82xx/ep8248e.c4
-rw-r--r--arch/powerpc/platforms/83xx/Kconfig3
-rw-r--r--arch/powerpc/platforms/83xx/Makefile2
-rw-r--r--arch/powerpc/platforms/83xx/mpc831x_rdb.c1
-rw-r--r--arch/powerpc/platforms/83xx/mpc832x_mds.c1
-rw-r--r--arch/powerpc/platforms/83xx/mpc832x_rdb.c1
-rw-r--r--arch/powerpc/platforms/83xx/mpc834x_itx.c1
-rw-r--r--arch/powerpc/platforms/83xx/mpc834x_mds.c1
-rw-r--r--arch/powerpc/platforms/83xx/mpc836x_mds.c1
-rw-r--r--arch/powerpc/platforms/83xx/mpc836x_rdk.c1
-rw-r--r--arch/powerpc/platforms/83xx/mpc837x_mds.c1
-rw-r--r--arch/powerpc/platforms/83xx/mpc837x_rdb.c1
-rw-r--r--arch/powerpc/platforms/83xx/mpc83xx.h5
-rw-r--r--arch/powerpc/platforms/83xx/pci.c91
-rw-r--r--arch/powerpc/platforms/83xx/sbc834x.c1
-rw-r--r--arch/powerpc/platforms/83xx/suspend-asm.S533
-rw-r--r--arch/powerpc/platforms/83xx/suspend.c388
-rw-r--r--arch/powerpc/platforms/83xx/usb.c24
-rw-r--r--arch/powerpc/platforms/85xx/Kconfig3
-rw-r--r--arch/powerpc/platforms/85xx/mpc85xx_ds.c2
-rw-r--r--arch/powerpc/platforms/86xx/Kconfig3
-rw-r--r--arch/powerpc/platforms/86xx/mpc8610_hpcd.c87
-rw-r--r--arch/powerpc/platforms/86xx/mpc86xx_hpcn.c2
-rw-r--r--arch/powerpc/platforms/Kconfig6
-rw-r--r--arch/powerpc/platforms/Kconfig.cputype5
-rw-r--r--arch/powerpc/platforms/cell/Kconfig25
-rw-r--r--arch/powerpc/platforms/cell/Makefile3
-rw-r--r--arch/powerpc/platforms/cell/cbe_powerbutton.c117
-rw-r--r--arch/powerpc/platforms/cell/cbe_thermal.c45
-rw-r--r--arch/powerpc/platforms/cell/cpufreq_spudemand.c184
-rw-r--r--arch/powerpc/platforms/cell/iommu.c118
-rw-r--r--arch/powerpc/platforms/cell/pervasive.c27
-rw-r--r--arch/powerpc/platforms/cell/pervasive.h9
-rw-r--r--arch/powerpc/platforms/cell/ras.c46
-rw-r--r--arch/powerpc/platforms/cell/spu_base.c3
-rw-r--r--arch/powerpc/platforms/chrp/pci.c2
-rw-r--r--arch/powerpc/platforms/fsl_uli1575.c117
-rw-r--r--arch/powerpc/platforms/iseries/Kconfig1
-rw-r--r--arch/powerpc/platforms/iseries/iommu.c3
-rw-r--r--arch/powerpc/platforms/pasemi/iommu.c3
-rw-r--r--arch/powerpc/platforms/ps3/Kconfig1
-rw-r--r--arch/powerpc/platforms/ps3/device-init.c1
-rw-r--r--arch/powerpc/platforms/ps3/system-bus.c21
-rw-r--r--arch/powerpc/platforms/pseries/Kconfig1
-rw-r--r--arch/powerpc/platforms/pseries/eeh.c26
-rw-r--r--arch/powerpc/platforms/pseries/iommu.c14
-rw-r--r--arch/powerpc/sysdev/axonram.c28
-rw-r--r--arch/powerpc/sysdev/dart_iommu.c3
-rw-r--r--arch/powerpc/sysdev/fsl_pci.c61
-rw-r--r--arch/powerpc/sysdev/fsl_pci.h1
-rw-r--r--arch/powerpc/sysdev/fsl_soc.c90
-rw-r--r--arch/powerpc/sysdev/fsl_soc.h1
-rw-r--r--arch/powerpc/sysdev/ipic.c71
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe.c6
-rw-r--r--arch/powerpc/sysdev/qe_lib/ucc.c6
-rw-r--r--arch/powerpc/sysdev/qe_lib/ucc_fast.c16
-rw-r--r--arch/s390/kernel/smp.c36
-rw-r--r--arch/s390/kernel/time.c35
-rw-r--r--arch/sh/drivers/dma/dma-sysfs.c15
-rw-r--r--arch/sparc/kernel/apc.c42
-rw-r--r--arch/sparc/kernel/asm-offsets.c12
-rw-r--r--arch/sparc/kernel/ebus.c9
-rw-r--r--arch/sparc/kernel/entry.S5
-rw-r--r--arch/sparc/kernel/etrap.S1
-rw-r--r--arch/sparc/kernel/head.S2
-rw-r--r--arch/sparc/kernel/idprom.c2
-rw-r--r--arch/sparc/kernel/ioport.c13
-rw-r--r--arch/sparc/kernel/irq.c2
-rw-r--r--arch/sparc/kernel/process.c14
-rw-r--r--arch/sparc/kernel/rtrap.S2
-rw-r--r--arch/sparc/kernel/setup.c4
-rw-r--r--arch/sparc/kernel/smp.c7
-rw-r--r--arch/sparc/kernel/sun4c_irq.c3
-rw-r--r--arch/sparc/kernel/sun4d_irq.c7
-rw-r--r--arch/sparc/kernel/sun4m_irq.c7
-rw-r--r--arch/sparc/kernel/sun4m_smp.c9
-rw-r--r--arch/sparc/kernel/time.c4
-rw-r--r--arch/sparc/kernel/traps.c16
-rw-r--r--arch/sparc/kernel/wof.S1
-rw-r--r--arch/sparc/kernel/wuf.S1
-rw-r--r--arch/sparc/mm/fault.c2
-rw-r--r--arch/sparc/mm/init.c9
-rw-r--r--arch/sparc/mm/srmmu.c38
-rw-r--r--arch/sparc/mm/tsunami.S1
-rw-r--r--arch/sparc64/Kconfig20
-rw-r--r--arch/sparc64/Makefile4
-rw-r--r--arch/sparc64/defconfig145
-rw-r--r--arch/sparc64/kernel/central.c14
-rw-r--r--arch/sparc64/kernel/ds.c2
-rw-r--r--arch/sparc64/kernel/ebus.c4
-rw-r--r--arch/sparc64/kernel/hvapi.c4
-rw-r--r--arch/sparc64/kernel/of_device.c4
-rw-r--r--arch/sparc64/kernel/pci.c2
-rw-r--r--arch/sparc64/kernel/pci_msi.c10
-rw-r--r--arch/sparc64/kernel/pci_sun4v.c2
-rw-r--r--arch/sparc64/kernel/process.c32
-rw-r--r--arch/sparc64/kernel/smp.c87
-rw-r--r--arch/sparc64/kernel/sparc64_ksyms.c2
-rw-r--r--arch/sparc64/kernel/sys_sparc.c6
-rw-r--r--arch/sparc64/kernel/sys_sparc32.c7
-rw-r--r--arch/sparc64/kernel/sysfs.c16
-rw-r--r--arch/sparc64/kernel/traps.c40
-rw-r--r--arch/sparc64/kernel/ttable.S7
-rw-r--r--arch/sparc64/kernel/unaligned.c7
-rw-r--r--arch/sparc64/kernel/vio.c18
-rw-r--r--arch/sparc64/lib/copy_page.S6
-rw-r--r--arch/sparc64/mm/fault.c5
-rw-r--r--arch/sparc64/mm/tsb.c6
-rw-r--r--arch/sparc64/mm/ultra.S5
-rw-r--r--arch/x86/Kconfig.debug2
-rw-r--r--arch/x86/kernel/cpu/cpufreq/powernow-k7.h1
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce_64.c18
-rw-r--r--arch/x86/kernel/cpu/mcheck/therm_throt.c1
-rw-r--r--arch/x86/kernel/cpuid.c4
-rw-r--r--arch/x86/kernel/microcode.c10
-rw-r--r--arch/x86/kernel/msr.c4
-rw-r--r--arch/x86/kernel/pci-dma.c6
-rw-r--r--arch/x86/kernel/pci-gart_64.c4
-rw-r--r--arch/xtensa/Kconfig4
-rw-r--r--block/bsg.c3
-rw-r--r--block/genhd.c205
-rw-r--r--drivers/acpi/fan.c10
-rw-r--r--drivers/acpi/glue.c6
-rw-r--r--drivers/acpi/processor_core.c5
-rw-r--r--drivers/acpi/scan.c2
-rw-r--r--drivers/acpi/thermal.c4
-rw-r--r--drivers/acpi/video.c5
-rw-r--r--drivers/base/Kconfig3
-rw-r--r--drivers/base/base.h27
-rw-r--r--drivers/base/class.c153
-rw-r--r--drivers/base/core.c196
-rw-r--r--drivers/base/cpu.c10
-rw-r--r--drivers/base/memory.c12
-rw-r--r--drivers/base/node.c15
-rw-r--r--drivers/base/power/trace.c2
-rw-r--r--drivers/base/sys.c64
-rw-r--r--drivers/base/topology.c17
-rw-r--r--drivers/block/aoe/aoechr.c5
-rw-r--r--drivers/block/paride/pg.c5
-rw-r--r--drivers/block/paride/pt.c10
-rw-r--r--drivers/block/pktcdvd.c4
-rw-r--r--drivers/char/Kconfig10
-rw-r--r--drivers/char/Makefile2
-rw-r--r--drivers/char/amiserial.c3
-rw-r--r--drivers/char/cyclades.c8
-rw-r--r--drivers/char/dsp56k.c3
-rw-r--r--drivers/char/epca.c58
-rw-r--r--drivers/char/esp.c5
-rw-r--r--drivers/char/hw_random/Kconfig13
-rw-r--r--drivers/char/hw_random/Makefile2
-rw-r--r--drivers/char/hw_random/n2-asm.S79
-rw-r--r--drivers/char/hw_random/n2-drv.c771
-rw-r--r--drivers/char/hw_random/n2rng.h118
-rw-r--r--drivers/char/ip2/ip2main.c12
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c2
-rw-r--r--drivers/char/isicom.c30
-rw-r--r--drivers/char/istallion.c41
-rw-r--r--drivers/char/keyboard.c2
-rw-r--r--drivers/char/lp.c3
-rw-r--r--drivers/char/mem.c6
-rw-r--r--drivers/char/misc.c4
-rw-r--r--drivers/char/mmtimer.c29
-rw-r--r--drivers/char/moxa.c3
-rw-r--r--drivers/char/mxser.c49
-rw-r--r--drivers/char/n_hdlc.c4
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c2
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c3
-rw-r--r--drivers/char/pcmcia/synclink_cs.c5
-rw-r--r--drivers/char/ppdev.c5
-rw-r--r--drivers/char/raw.c7
-rw-r--r--drivers/char/riscom8.c27
-rw-r--r--drivers/char/rocket.c5
-rw-r--r--drivers/char/snsc.c3
-rw-r--r--drivers/char/specialix.c803
-rw-r--r--drivers/char/stallion.c20
-rw-r--r--drivers/char/sx.c3
-rw-r--r--drivers/char/synclink.c7
-rw-r--r--drivers/char/synclink_gt.c154
-rw-r--r--drivers/char/synclinkmp.c9
-rw-r--r--drivers/char/tty_io.c719
-rw-r--r--drivers/char/tty_ldisc.c714
-rw-r--r--drivers/char/vc_screen.c12
-rw-r--r--drivers/char/viotape.c8
-rw-r--r--drivers/char/vme_scc.c5
-rw-r--r--drivers/char/vt.c14
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c5
-rw-r--r--drivers/cpufreq/cpufreq.c45
-rw-r--r--drivers/cpufreq/cpufreq_stats.c24
-rw-r--r--drivers/cpufreq/freq_table.c12
-rw-r--r--drivers/cpuidle/sysfs.c10
-rw-r--r--drivers/dca/dca-sysfs.c8
-rw-r--r--drivers/edac/cell_edac.c5
-rw-r--r--drivers/eisa/Makefile2
-rw-r--r--drivers/eisa/eisa-bus.c4
-rw-r--r--drivers/gpio/Kconfig11
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/max7301.c339
-rw-r--r--drivers/gpio/pcf857x.c33
-rw-r--r--drivers/hid/hidraw.c5
-rw-r--r--drivers/hid/usbhid/hid-core.c2
-rw-r--r--drivers/hwmon/hdaps.c2
-rw-r--r--drivers/hwmon/hwmon.c3
-rw-r--r--drivers/i2c/i2c-core.c6
-rw-r--r--drivers/i2c/i2c-dev.c6
-rw-r--r--drivers/ide/ide-tape.c10
-rw-r--r--drivers/ieee1394/dv1394.c7
-rw-r--r--drivers/ieee1394/nodemgr.c23
-rw-r--r--drivers/ieee1394/raw1394.c4
-rw-r--r--drivers/ieee1394/video1394.c6
-rw-r--r--drivers/infiniband/core/cm.c72
-rw-r--r--drivers/infiniband/hw/ipath/ipath_file_ops.c2
-rw-r--r--drivers/input/evbug.c12
-rw-r--r--drivers/input/evdev.c101
-rw-r--r--drivers/input/ff-memless.c4
-rw-r--r--drivers/input/gameport/emu10k1-gp.c2
-rw-r--r--drivers/input/gameport/gameport.c22
-rw-r--r--drivers/input/gameport/lightning.c2
-rw-r--r--drivers/input/gameport/ns558.c2
-rw-r--r--drivers/input/input.c2
-rw-r--r--drivers/input/joystick/a3d.c2
-rw-r--r--drivers/input/joystick/amijoy.c2
-rw-r--r--drivers/input/joystick/cobra.c2
-rw-r--r--drivers/input/joystick/db9.c2
-rw-r--r--drivers/input/joystick/gf2k.c2
-rw-r--r--drivers/input/joystick/grip.c2
-rw-r--r--drivers/input/joystick/grip_mp.c2
-rw-r--r--drivers/input/joystick/guillemot.c2
-rw-r--r--drivers/input/joystick/iforce/iforce-ff.c2
-rw-r--r--drivers/input/joystick/iforce/iforce-main.c2
-rw-r--r--drivers/input/joystick/iforce/iforce-packets.c2
-rw-r--r--drivers/input/joystick/iforce/iforce-serio.c2
-rw-r--r--drivers/input/joystick/iforce/iforce-usb.c8
-rw-r--r--drivers/input/joystick/iforce/iforce.h2
-rw-r--r--drivers/input/joystick/interact.c2
-rw-r--r--drivers/input/joystick/joydump.c2
-rw-r--r--drivers/input/joystick/magellan.c2
-rw-r--r--drivers/input/joystick/spaceball.c2
-rw-r--r--drivers/input/joystick/spaceorb.c2
-rw-r--r--drivers/input/joystick/stinger.c2
-rw-r--r--drivers/input/joystick/tmdc.c2
-rw-r--r--drivers/input/joystick/turbografx.c2
-rw-r--r--drivers/input/joystick/twidjoy.c4
-rw-r--r--drivers/input/joystick/warrior.c2
-rw-r--r--drivers/input/joystick/xpad.c12
-rw-r--r--drivers/input/keyboard/amikbd.c2
-rw-r--r--drivers/input/keyboard/atkbd.c46
-rw-r--r--drivers/input/keyboard/gpio_keys.c89
-rw-r--r--drivers/input/keyboard/lkkbd.c6
-rw-r--r--drivers/input/keyboard/pxa27x_keypad.c15
-rw-r--r--drivers/input/keyboard/sunkbd.c2
-rw-r--r--drivers/input/keyboard/xtkbd.c2
-rw-r--r--drivers/input/misc/Kconfig10
-rw-r--r--drivers/input/misc/Makefile1
-rw-r--r--drivers/input/misc/ati_remote.c18
-rw-r--r--drivers/input/misc/ati_remote2.c18
-rw-r--r--drivers/input/misc/keyspan_remote.c20
-rw-r--r--drivers/input/misc/powermate.c6
-rw-r--r--drivers/input/misc/sgi_btns.c178
-rw-r--r--drivers/input/misc/wistron_btns.c19
-rw-r--r--drivers/input/misc/yealink.c50
-rw-r--r--drivers/input/mouse/appletouch.c299
-rw-r--r--drivers/input/mouse/atarimouse.c27
-rw-r--r--drivers/input/mouse/hil_ptr.c37
-rw-r--r--drivers/input/mouse/inport.c2
-rw-r--r--drivers/input/mouse/logibm.c2
-rw-r--r--drivers/input/mouse/pc110pad.c2
-rw-r--r--drivers/input/mouse/sermouse.c2
-rw-r--r--drivers/input/serio/Kconfig10
-rw-r--r--drivers/input/serio/Makefile1
-rw-r--r--drivers/input/serio/ct82c710.c2
-rw-r--r--drivers/input/serio/hil_mlc.c6
-rw-r--r--drivers/input/serio/hp_sdc.c9
-rw-r--r--drivers/input/serio/hp_sdc_mlc.c2
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h67
-rw-r--r--drivers/input/serio/libps2.c52
-rw-r--r--drivers/input/serio/q40kbd.c4
-rw-r--r--drivers/input/serio/rpckbd.c2
-rw-r--r--drivers/input/serio/serio.c9
-rw-r--r--drivers/input/serio/xilinx_ps2.c380
-rw-r--r--drivers/input/tablet/acecad.c4
-rw-r--r--drivers/input/tablet/aiptek.c6
-rw-r--r--drivers/input/tablet/gtco.c2
-rw-r--r--drivers/input/tablet/kbtab.c6
-rw-r--r--drivers/input/tablet/wacom.h2
-rw-r--r--drivers/input/tablet/wacom_sys.c6
-rw-r--r--drivers/input/tablet/wacom_wac.c39
-rw-r--r--drivers/input/touchscreen/Kconfig46
-rw-r--r--drivers/input/touchscreen/Makefile4
-rw-r--r--drivers/input/touchscreen/gunze.c2
-rw-r--r--drivers/input/touchscreen/h3600_ts_input.c2
-rw-r--r--drivers/input/touchscreen/htcpen.c255
-rw-r--r--drivers/input/touchscreen/inexio.c207
-rw-r--r--drivers/input/touchscreen/migor_ts.c250
-rw-r--r--drivers/input/touchscreen/touchit213.c234
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c42
-rw-r--r--drivers/input/touchscreen/wm9712.c18
-rw-r--r--drivers/isdn/capi/capi.c6
-rw-r--r--drivers/macintosh/adb.c3
-rw-r--r--drivers/macintosh/adbhid.c61
-rw-r--r--drivers/mca/mca-bus.c2
-rw-r--r--drivers/md/bitmap.c54
-rw-r--r--drivers/md/dm-crypt.c18
-rw-r--r--drivers/md/dm-linear.c38
-rw-r--r--drivers/md/dm-log.c4
-rw-r--r--drivers/md/dm-mpath.c10
-rw-r--r--drivers/md/dm-snap.c163
-rw-r--r--drivers/md/dm-snap.h11
-rw-r--r--drivers/md/dm-table.c13
-rw-r--r--drivers/md/dm.c46
-rw-r--r--drivers/md/dm.h6
-rw-r--r--drivers/md/faulty.c2
-rw-r--r--drivers/md/linear.c20
-rw-r--r--drivers/md/md.c615
-rw-r--r--drivers/md/multipath.c17
-rw-r--r--drivers/md/raid0.c8
-rw-r--r--drivers/md/raid1.c30
-rw-r--r--drivers/md/raid10.c22
-rw-r--r--drivers/md/raid5.c745
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c4
-rw-r--r--drivers/memstick/host/jmb38x_ms.c4
-rw-r--r--drivers/message/fusion/mptbase.c3
-rw-r--r--drivers/message/fusion/mptbase.h4
-rw-r--r--drivers/message/fusion/mptfc.c4
-rw-r--r--drivers/misc/Kconfig13
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/hpilo.c768
-rw-r--r--drivers/misc/hpilo.h189
-rw-r--r--drivers/misc/phantom.c5
-rw-r--r--drivers/mtd/devices/block2mtd.c8
-rw-r--r--drivers/mtd/mtdchar.c9
-rw-r--r--drivers/net/3c59x.c2
-rw-r--r--drivers/net/arm/at91_ether.c2
-rw-r--r--drivers/net/arm/ep93xx_eth.c2
-rw-r--r--drivers/net/arm/etherh.c6
-rw-r--r--drivers/net/atlx/atl1.c3
-rw-r--r--drivers/net/fs_enet/Makefile5
-rw-r--r--drivers/net/fs_enet/fs_enet-main.c312
-rw-r--r--drivers/net/fs_enet/fs_enet.h4
-rw-r--r--drivers/net/fs_enet/mac-fcc.c67
-rw-r--r--drivers/net/fs_enet/mac-fec.c23
-rw-r--r--drivers/net/fs_enet/mac-scc.c37
-rw-r--r--drivers/net/fs_enet/mii-bitbang.c107
-rw-r--r--drivers/net/fs_enet/mii-fec.c144
-rw-r--r--drivers/net/gianfar.c123
-rw-r--r--drivers/net/gianfar.h12
-rw-r--r--drivers/net/gianfar_ethtool.c41
-rw-r--r--drivers/net/hamradio/hdlcdrv.c1
-rw-r--r--drivers/net/ppp_generic.c3
-rw-r--r--drivers/net/sunhme.c4
-rw-r--r--drivers/net/ucc_geth.c1
-rw-r--r--drivers/net/wan/cosa.c6
-rw-r--r--drivers/pci/hotplug/acpiphp.h4
-rw-r--r--drivers/pci/pci.c6
-rw-r--r--drivers/power/apm_power.c2
-rw-r--r--drivers/power/power_supply_core.c4
-rw-r--r--drivers/rtc/interface.c2
-rw-r--r--drivers/s390/char/raw3270.c14
-rw-r--r--drivers/s390/char/tape_class.c7
-rw-r--r--drivers/s390/char/vmur.c5
-rw-r--r--drivers/sbus/char/uctrl.c16
-rw-r--r--drivers/sbus/char/vfc.h4
-rw-r--r--drivers/sbus/char/vfc_dev.c39
-rw-r--r--drivers/sbus/char/vfc_i2c.c12
-rw-r--r--drivers/sbus/dvma.c2
-rw-r--r--drivers/sbus/sbus.c6
-rw-r--r--drivers/scsi/dpt_i2o.c4
-rw-r--r--drivers/scsi/hosts.c7
-rw-r--r--drivers/scsi/scsi_transport_fc.c9
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c8
-rw-r--r--drivers/serial/8250.c8
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c2
-rw-r--r--drivers/serial/icom.c2
-rw-r--r--drivers/serial/samsung.c2
-rw-r--r--drivers/serial/serial_core.c3
-rw-r--r--drivers/serial/serial_txx9.c2
-rw-r--r--drivers/spi/spi.c2
-rw-r--r--drivers/spi/spidev.c4
-rw-r--r--drivers/uio/Kconfig10
-rw-r--r--drivers/uio/Makefile1
-rw-r--r--drivers/uio/uio.c26
-rw-r--r--drivers/uio/uio_pdrv.c118
-rw-r--r--drivers/usb/atm/cxacru.c1
-rw-r--r--drivers/usb/atm/speedtch.c1
-rw-r--r--drivers/usb/class/cdc-acm.c186
-rw-r--r--drivers/usb/class/cdc-acm.h5
-rw-r--r--drivers/usb/class/cdc-wdm.c127
-rw-r--r--drivers/usb/core/devices.c4
-rw-r--r--drivers/usb/core/devio.c99
-rw-r--r--drivers/usb/core/driver.c168
-rw-r--r--drivers/usb/core/endpoint.c4
-rw-r--r--drivers/usb/core/file.c15
-rw-r--r--drivers/usb/core/hcd.c6
-rw-r--r--drivers/usb/core/hcd.h4
-rw-r--r--drivers/usb/core/hub.c536
-rw-r--r--drivers/usb/core/inode.c16
-rw-r--r--drivers/usb/core/message.c22
-rw-r--r--drivers/usb/core/usb.c7
-rw-r--r--drivers/usb/core/usb.h19
-rw-r--r--drivers/usb/gadget/Kconfig14
-rw-r--r--drivers/usb/gadget/Makefile13
-rw-r--r--drivers/usb/gadget/amd5536udc.c2
-rw-r--r--drivers/usb/gadget/at91_udc.c13
-rw-r--r--drivers/usb/gadget/cdc2.c246
-rw-r--r--drivers/usb/gadget/composite.c1041
-rw-r--r--drivers/usb/gadget/config.c76
-rw-r--r--drivers/usb/gadget/dummy_hcd.c4
-rw-r--r--drivers/usb/gadget/epautoconf.c1
-rw-r--r--drivers/usb/gadget/ether.c2631
-rw-r--r--drivers/usb/gadget/f_acm.c589
-rw-r--r--drivers/usb/gadget/f_ecm.c833
-rw-r--r--drivers/usb/gadget/f_loopback.c381
-rw-r--r--drivers/usb/gadget/f_rndis.c827
-rw-r--r--drivers/usb/gadget/f_serial.c296
-rw-r--r--drivers/usb/gadget/f_sourcesink.c587
-rw-r--r--drivers/usb/gadget/f_subset.c423
-rw-r--r--drivers/usb/gadget/file_storage.c4
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.c2
-rw-r--r--drivers/usb/gadget/g_zero.h25
-rw-r--r--drivers/usb/gadget/gadget_chips.h23
-rw-r--r--drivers/usb/gadget/goku_udc.c2
-rw-r--r--drivers/usb/gadget/inode.c23
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c2
-rw-r--r--drivers/usb/gadget/m66592-udc.c2
-rw-r--r--drivers/usb/gadget/ndis.h10
-rw-r--r--drivers/usb/gadget/net2280.c2
-rw-r--r--drivers/usb/gadget/omap_udc.c2
-rw-r--r--drivers/usb/gadget/printer.c11
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c2
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c1
-rw-r--r--drivers/usb/gadget/rndis.c421
-rw-r--r--drivers/usb/gadget/rndis.h9
-rw-r--r--drivers/usb/gadget/serial.c2315
-rw-r--r--drivers/usb/gadget/u_ether.c967
-rw-r--r--drivers/usb/gadget/u_ether.h127
-rw-r--r--drivers/usb/gadget/u_serial.c1246
-rw-r--r--drivers/usb/gadget/u_serial.h58
-rw-r--r--drivers/usb/gadget/zero.c1162
-rw-r--r--drivers/usb/host/ehci-au1xxx.c369
-rw-r--r--drivers/usb/host/ehci-dbg.c4
-rw-r--r--drivers/usb/host/ehci-fsl.c17
-rw-r--r--drivers/usb/host/ehci-hcd.c2
-rw-r--r--drivers/usb/host/ehci-ixp4xx.c8
-rw-r--r--drivers/usb/host/ehci-orion.c8
-rw-r--r--drivers/usb/host/ehci-ps3.c2
-rw-r--r--drivers/usb/host/ehci-q.c17
-rw-r--r--drivers/usb/host/ehci.h5
-rw-r--r--drivers/usb/host/isp116x-hcd.c25
-rw-r--r--drivers/usb/host/isp1760-hcd.c81
-rw-r--r--drivers/usb/host/isp1760-hcd.h20
-rw-r--r--drivers/usb/host/isp1760-if.c37
-rw-r--r--drivers/usb/host/ohci-at91.c9
-rw-r--r--drivers/usb/host/ohci-au1xxx.c327
-rw-r--r--drivers/usb/host/ohci-dbg.c2
-rw-r--r--drivers/usb/host/ohci-hcd.c2
-rw-r--r--drivers/usb/host/ohci-omap.c2
-rw-r--r--drivers/usb/host/ohci-pnx4008.c28
-rw-r--r--drivers/usb/host/ohci-ppc-of.c2
-rw-r--r--drivers/usb/host/ohci-ps3.c2
-rw-r--r--drivers/usb/host/ohci-q.c3
-rw-r--r--drivers/usb/host/ohci-sm501.c2
-rw-r--r--drivers/usb/host/ohci-ssb.c2
-rw-r--r--drivers/usb/host/r8a66597-hcd.c44
-rw-r--r--drivers/usb/host/sl811-hcd.c2
-rw-r--r--drivers/usb/host/u132-hcd.c2
-rw-r--r--drivers/usb/host/uhci-hub.c2
-rw-r--r--drivers/usb/misc/auerswald.c10
-rw-r--r--drivers/usb/misc/emi62.c2
-rw-r--r--drivers/usb/misc/ftdi-elan.c24
-rw-r--r--drivers/usb/misc/iowarrior.c8
-rw-r--r--drivers/usb/misc/rio500.c8
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c13
-rw-r--r--drivers/usb/misc/usblcd.c6
-rw-r--r--drivers/usb/mon/mon_bin.c5
-rw-r--r--drivers/usb/mon/mon_stat.c14
-rw-r--r--drivers/usb/serial/Kconfig8
-rw-r--r--drivers/usb/serial/Makefile1
-rw-r--r--drivers/usb/serial/aircable.c19
-rw-r--r--drivers/usb/serial/airprime.c12
-rw-r--r--drivers/usb/serial/ark3116.c32
-rw-r--r--drivers/usb/serial/belkin_sa.c201
-rw-r--r--drivers/usb/serial/belkin_sa.h15
-rw-r--r--drivers/usb/serial/bus.c20
-rw-r--r--drivers/usb/serial/ch341.c10
-rw-r--r--drivers/usb/serial/console.c136
-rw-r--r--drivers/usb/serial/cp2101.c392
-rw-r--r--drivers/usb/serial/cyberjack.c176
-rw-r--r--drivers/usb/serial/cypress_m8.c703
-rw-r--r--drivers/usb/serial/cypress_m8.h2
-rw-r--r--drivers/usb/serial/digi_acceleport.c460
-rw-r--r--drivers/usb/serial/empeg.c257
-rw-r--r--drivers/usb/serial/ezusb.c22
-rw-r--r--drivers/usb/serial/ftdi_sio.c1247
-rw-r--r--drivers/usb/serial/ftdi_sio.h126
-rw-r--r--drivers/usb/serial/funsoft.c2
-rw-r--r--drivers/usb/serial/garmin_gps.c400
-rw-r--r--drivers/usb/serial/generic.c122
-rw-r--r--drivers/usb/serial/hp4x.c3
-rw-r--r--drivers/usb/serial/io_edgeport.c1964
-rw-r--r--drivers/usb/serial/io_tables.h6
-rw-r--r--drivers/usb/serial/io_ti.c1875
-rw-r--r--drivers/usb/serial/ipaq.c146
-rw-r--r--drivers/usb/serial/ipw.c294
-rw-r--r--drivers/usb/serial/ir-usb.c481
-rw-r--r--drivers/usb/serial/iuu_phoenix.c58
-rw-r--r--drivers/usb/serial/keyspan.c955
-rw-r--r--drivers/usb/serial/keyspan.h44
-rw-r--r--drivers/usb/serial/keyspan_pda.c233
-rw-r--r--drivers/usb/serial/kl5kusb105.c417
-rw-r--r--drivers/usb/serial/kobil_sct.c617
-rw-r--r--drivers/usb/serial/mct_u232.c364
-rw-r--r--drivers/usb/serial/mos7720.c308
-rw-r--r--drivers/usb/serial/mos7840.c557
-rw-r--r--drivers/usb/serial/navman.c10
-rw-r--r--drivers/usb/serial/omninet.c171
-rw-r--r--drivers/usb/serial/option.c168
-rw-r--r--drivers/usb/serial/oti6858.c255
-rw-r--r--drivers/usb/serial/pl2303.c140
-rw-r--r--drivers/usb/serial/safe_serial.c298
-rw-r--r--drivers/usb/serial/sierra.c95
-rw-r--r--drivers/usb/serial/spcp8x5.c73
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c449
-rw-r--r--drivers/usb/serial/usb-serial.c400
-rw-r--r--drivers/usb/serial/usb_debug.c10
-rw-r--r--drivers/usb/serial/visor.c384
-rw-r--r--drivers/usb/serial/whiteheat.c441
-rw-r--r--drivers/usb/serial/whiteheat.h78
-rw-r--r--drivers/usb/storage/datafab.c2
-rw-r--r--drivers/usb/storage/debug.c2
-rw-r--r--drivers/usb/storage/debug.h2
-rw-r--r--drivers/usb/storage/dpcm.c2
-rw-r--r--drivers/usb/storage/dpcm.h2
-rw-r--r--drivers/usb/storage/freecom.c2
-rw-r--r--drivers/usb/storage/freecom.h2
-rw-r--r--drivers/usb/storage/initializers.c2
-rw-r--r--drivers/usb/storage/initializers.h2
-rw-r--r--drivers/usb/storage/isd200.c8
-rw-r--r--drivers/usb/storage/jumpshot.c2
-rw-r--r--drivers/usb/storage/protocol.c2
-rw-r--r--drivers/usb/storage/protocol.h2
-rw-r--r--drivers/usb/storage/scsiglue.c53
-rw-r--r--drivers/usb/storage/scsiglue.h2
-rw-r--r--drivers/usb/storage/sddr09.c1
-rw-r--r--drivers/usb/storage/sddr09.h2
-rw-r--r--drivers/usb/storage/sddr55.c2
-rw-r--r--drivers/usb/storage/sddr55.h2
-rw-r--r--drivers/usb/storage/shuttle_usbat.c2
-rw-r--r--drivers/usb/storage/shuttle_usbat.h2
-rw-r--r--drivers/usb/storage/transport.c83
-rw-r--r--drivers/usb/storage/transport.h2
-rw-r--r--drivers/usb/storage/unusual_devs.h13
-rw-r--r--drivers/usb/storage/usb.c111
-rw-r--r--drivers/usb/storage/usb.h25
-rw-r--r--drivers/video/aty/aty128fb.c2
-rw-r--r--drivers/video/aty/radeonfb.h2
-rw-r--r--drivers/video/console/fbcon.c3
-rw-r--r--drivers/video/fbmem.c5
-rw-r--r--drivers/video/offb.c192
-rw-r--r--drivers/video/ps3fb.c1
-rw-r--r--drivers/xen/balloon.c1
-rw-r--r--fs/binfmt_elf.c1
-rw-r--r--fs/coda/psdev.c5
-rw-r--r--fs/debugfs/inode.c114
-rw-r--r--fs/partitions/check.c2
-rw-r--r--fs/proc/task_mmu.c2
-rw-r--r--fs/sysfs/dir.c37
-rw-r--r--fs/sysfs/file.c5
-rw-r--r--fs/sysfs/symlink.c41
-rw-r--r--fs/sysfs/sysfs.h1
-rw-r--r--include/asm-ia64/Kbuild2
-rw-r--r--include/asm-ia64/gcc_intrin.h24
-rw-r--r--include/asm-ia64/hw_irq.h23
-rw-r--r--include/asm-ia64/intel_intrin.h41
-rw-r--r--include/asm-ia64/intrinsics.h55
-rw-r--r--include/asm-ia64/iosapic.h18
-rw-r--r--include/asm-ia64/irq.h9
-rw-r--r--include/asm-ia64/mmu_context.h6
-rw-r--r--include/asm-ia64/native/inst.h175
-rw-r--r--include/asm-ia64/native/irq.h35
-rw-r--r--include/asm-ia64/paravirt.h255
-rw-r--r--include/asm-ia64/paravirt_privop.h114
-rw-r--r--include/asm-ia64/smp.h2
-rw-r--r--include/asm-ia64/system.h11
-rw-r--r--include/asm-ia64/uv/uv_mmrs.h423
-rw-r--r--include/asm-powerpc/asm-compat.h2
-rw-r--r--include/asm-powerpc/machdep.h3
-rw-r--r--include/asm-powerpc/pgtable-ppc32.h15
-rw-r--r--include/asm-powerpc/pmi.h1
-rw-r--r--include/asm-powerpc/ps3.h7
-rw-r--r--include/asm-powerpc/reg.h4
-rw-r--r--include/asm-powerpc/uaccess.h21
-rw-r--r--include/asm-powerpc/ucc_fast.h8
-rw-r--r--include/asm-sparc/Kbuild15
-rw-r--r--include/asm-sparc/agp.h20
-rw-r--r--include/asm-sparc/apb.h36
-rw-r--r--include/asm-sparc/asi.h153
-rw-r--r--include/asm-sparc/atomic.h169
-rw-r--r--include/asm-sparc/atomic_32.h165
-rw-r--r--include/asm-sparc/atomic_64.h128
-rw-r--r--include/asm-sparc/auxio.h97
-rw-r--r--include/asm-sparc/auxio_32.h89
-rw-r--r--include/asm-sparc/auxio_64.h100
-rw-r--r--include/asm-sparc/backoff.h31
-rw-r--r--include/asm-sparc/bbc.h225
-rw-r--r--include/asm-sparc/bitops.h117
-rw-r--r--include/asm-sparc/bitops_32.h111
-rw-r--r--include/asm-sparc/bitops_64.h107
-rw-r--r--include/asm-sparc/cacheflush.h93
-rw-r--r--include/asm-sparc/cacheflush_32.h85
-rw-r--r--include/asm-sparc/cacheflush_64.h76
-rw-r--r--include/asm-sparc/chafsr.h241
-rw-r--r--include/asm-sparc/checksum.h249
-rw-r--r--include/asm-sparc/checksum_32.h241
-rw-r--r--include/asm-sparc/checksum_64.h167
-rw-r--r--include/asm-sparc/chmctrl.h183
-rw-r--r--include/asm-sparc/cmt.h59
-rw-r--r--include/asm-sparc/compat.h243
-rw-r--r--include/asm-sparc/compat_signal.h29
-rw-r--r--include/asm-sparc/cpudata.h35
-rw-r--r--include/asm-sparc/cpudata_32.h27
-rw-r--r--include/asm-sparc/cpudata_64.h240
-rw-r--r--include/asm-sparc/dcr.h14
-rw-r--r--include/asm-sparc/dcu.h27
-rw-r--r--include/asm-sparc/delay.h42
-rw-r--r--include/asm-sparc/delay_32.h34
-rw-r--r--include/asm-sparc/delay_64.h17
-rw-r--r--include/asm-sparc/display7seg.h79
-rw-r--r--include/asm-sparc/dma-mapping.h17
-rw-r--r--include/asm-sparc/dma-mapping_32.h11
-rw-r--r--include/asm-sparc/dma-mapping_64.h154
-rw-r--r--include/asm-sparc/dma.h290
-rw-r--r--include/asm-sparc/dma_32.h288
-rw-r--r--include/asm-sparc/dma_64.h205
-rw-r--r--include/asm-sparc/ebus.h105
-rw-r--r--include/asm-sparc/ebus_32.h99
-rw-r--r--include/asm-sparc/ebus_64.h94
-rw-r--r--include/asm-sparc/elf.h149
-rw-r--r--include/asm-sparc/elf_32.h145
-rw-r--r--include/asm-sparc/elf_64.h217
-rw-r--r--include/asm-sparc/envctrl.h103
-rw-r--r--include/asm-sparc/estate.h49
-rw-r--r--include/asm-sparc/fbio.h37
-rw-r--r--include/asm-sparc/fcntl.h4
-rw-r--r--include/asm-sparc/fhc.h121
-rw-r--r--include/asm-sparc/floppy.h394
-rw-r--r--include/asm-sparc/floppy_32.h388
-rw-r--r--include/asm-sparc/floppy_64.h782
-rw-r--r--include/asm-sparc/fpumacro.h33
-rw-r--r--include/asm-sparc/futex.h12
-rw-r--r--include/asm-sparc/futex_32.h6
-rw-r--r--include/asm-sparc/futex_64.h110
-rw-r--r--include/asm-sparc/hardirq.h31
-rw-r--r--include/asm-sparc/hardirq_32.h23
-rw-r--r--include/asm-sparc/hardirq_64.h19
-rw-r--r--include/asm-sparc/head.h106
-rw-r--r--include/asm-sparc/head_32.h102
-rw-r--r--include/asm-sparc/head_64.h76
-rw-r--r--include/asm-sparc/hugetlb.h84
-rw-r--r--include/asm-sparc/hvtramp.h37
-rw-r--r--include/asm-sparc/hypervisor.h2949
-rw-r--r--include/asm-sparc/ide.h103
-rw-r--r--include/asm-sparc/ide_32.h95
-rw-r--r--include/asm-sparc/ide_64.h118
-rw-r--r--include/asm-sparc/idprom.h2
-rw-r--r--include/asm-sparc/intr_queue.h15
-rw-r--r--include/asm-sparc/io.h331
-rw-r--r--include/asm-sparc/io_32.h325
-rw-r--r--include/asm-sparc/io_64.h511
-rw-r--r--include/asm-sparc/ioctls.h4
-rw-r--r--include/asm-sparc/iommu.h129
-rw-r--r--include/asm-sparc/iommu_32.h121
-rw-r--r--include/asm-sparc/iommu_64.h62
-rw-r--r--include/asm-sparc/ipcbuf.h39
-rw-r--r--include/asm-sparc/ipcbuf_32.h31
-rw-r--r--include/asm-sparc/ipcbuf_64.h28
-rw-r--r--include/asm-sparc/irq.h21
-rw-r--r--include/asm-sparc/irq_32.h15
-rw-r--r--include/asm-sparc/irq_64.h93
-rw-r--r--include/asm-sparc/irqflags.h47
-rw-r--r--include/asm-sparc/irqflags_32.h39
-rw-r--r--include/asm-sparc/irqflags_64.h89
-rw-r--r--include/asm-sparc/kdebug.h81
-rw-r--r--include/asm-sparc/kdebug_32.h73
-rw-r--r--include/asm-sparc/kdebug_64.h19
-rw-r--r--include/asm-sparc/kmap_types.h4
-rw-r--r--include/asm-sparc/kprobes.h49
-rw-r--r--include/asm-sparc/ldc.h138
-rw-r--r--include/asm-sparc/lmb.h10
-rw-r--r--include/asm-sparc/lsu.h19
-rw-r--r--include/asm-sparc/machines.h2
-rw-r--r--include/asm-sparc/mbus.h2
-rw-r--r--include/asm-sparc/mc146818rtc.h35
-rw-r--r--include/asm-sparc/mc146818rtc_32.h29
-rw-r--r--include/asm-sparc/mc146818rtc_64.h34
-rw-r--r--include/asm-sparc/mdesc.h78
-rw-r--r--include/asm-sparc/mmu.h13
-rw-r--r--include/asm-sparc/mmu_32.h7
-rw-r--r--include/asm-sparc/mmu_64.h123
-rw-r--r--include/asm-sparc/mmu_context.h50
-rw-r--r--include/asm-sparc/mmu_context_32.h42
-rw-r--r--include/asm-sparc/mmu_context_64.h155
-rw-r--r--include/asm-sparc/mmzone.h17
-rw-r--r--include/asm-sparc/module.h15
-rw-r--r--include/asm-sparc/module_32.h7
-rw-r--r--include/asm-sparc/module_64.h7
-rw-r--r--include/asm-sparc/mostek.h175
-rw-r--r--include/asm-sparc/mostek_32.h171
-rw-r--r--include/asm-sparc/mostek_64.h143
-rw-r--r--include/asm-sparc/msgbuf.h23
-rw-r--r--include/asm-sparc/namei.h21
-rw-r--r--include/asm-sparc/namei_32.h13
-rw-r--r--include/asm-sparc/namei_64.h13
-rw-r--r--include/asm-sparc/ns87303.h118
-rw-r--r--include/asm-sparc/of_platform.h32
-rw-r--r--include/asm-sparc/of_platform_32.h24
-rw-r--r--include/asm-sparc/of_platform_64.h25
-rw-r--r--include/asm-sparc/openprom.h265
-rw-r--r--include/asm-sparc/openprom_32.h255
-rw-r--r--include/asm-sparc/openprom_64.h280
-rw-r--r--include/asm-sparc/oplib.h279
-rw-r--r--include/asm-sparc/oplib_32.h272
-rw-r--r--include/asm-sparc/oplib_64.h322
-rw-r--r--include/asm-sparc/page.h167
-rw-r--r--include/asm-sparc/page_32.h163
-rw-r--r--include/asm-sparc/page_64.h138
-rw-r--r--include/asm-sparc/parport.h246
-rw-r--r--include/asm-sparc/pci.h176
-rw-r--r--include/asm-sparc/pci_32.h170
-rw-r--r--include/asm-sparc/pci_64.h209
-rw-r--r--include/asm-sparc/percpu.h14
-rw-r--r--include/asm-sparc/percpu_32.h6
-rw-r--r--include/asm-sparc/percpu_64.h28
-rw-r--r--include/asm-sparc/pgalloc.h76
-rw-r--r--include/asm-sparc/pgalloc_32.h68
-rw-r--r--include/asm-sparc/pgalloc_64.h81
-rw-r--r--include/asm-sparc/pgtable.h477
-rw-r--r--include/asm-sparc/pgtable_32.h480
-rw-r--r--include/asm-sparc/pgtable_64.h775
-rw-r--r--include/asm-sparc/pil.h22
-rw-r--r--include/asm-sparc/posix_types.h124
-rw-r--r--include/asm-sparc/posix_types_32.h118
-rw-r--r--include/asm-sparc/posix_types_64.h122
-rw-r--r--include/asm-sparc/processor.h132
-rw-r--r--include/asm-sparc/processor_32.h128
-rw-r--r--include/asm-sparc/processor_64.h237
-rw-r--r--include/asm-sparc/psrcompat.h45
-rw-r--r--include/asm-sparc/pstate.h91
-rw-r--r--include/asm-sparc/ptrace.h179
-rw-r--r--include/asm-sparc/ptrace_32.h175
-rw-r--r--include/asm-sparc/ptrace_64.h346
-rw-r--r--include/asm-sparc/reboot.h6
-rw-r--r--include/asm-sparc/reg.h87
-rw-r--r--include/asm-sparc/reg_32.h79
-rw-r--r--include/asm-sparc/reg_64.h56
-rw-r--r--include/asm-sparc/resource.h6
-rw-r--r--include/asm-sparc/rwsem-const.h12
-rw-r--r--include/asm-sparc/rwsem.h84
-rw-r--r--include/asm-sparc/sbus.h161
-rw-r--r--include/asm-sparc/sbus_32.h153
-rw-r--r--include/asm-sparc/sbus_64.h190
-rw-r--r--include/asm-sparc/scatterlist.h32
-rw-r--r--include/asm-sparc/scatterlist_32.h26
-rw-r--r--include/asm-sparc/scatterlist_64.h27
-rw-r--r--include/asm-sparc/scratchpad.h14
-rw-r--r--include/asm-sparc/seccomp.h21
-rw-r--r--include/asm-sparc/sections.h12
-rw-r--r--include/asm-sparc/sections_32.h6
-rw-r--r--include/asm-sparc/sections_64.h9
-rw-r--r--include/asm-sparc/sembuf.h12
-rw-r--r--include/asm-sparc/setup.h6
-rw-r--r--include/asm-sparc/sfafsr.h82
-rw-r--r--include/asm-sparc/sfp-machine.h214
-rw-r--r--include/asm-sparc/sfp-machine_32.h212
-rw-r--r--include/asm-sparc/sfp-machine_64.h93
-rw-r--r--include/asm-sparc/shmbuf.h14
-rw-r--r--include/asm-sparc/shmparam.h19
-rw-r--r--include/asm-sparc/shmparam_32.h11
-rw-r--r--include/asm-sparc/shmparam_64.h10
-rw-r--r--include/asm-sparc/sigcontext.h70
-rw-r--r--include/asm-sparc/sigcontext_32.h62
-rw-r--r--include/asm-sparc/sigcontext_64.h87
-rw-r--r--include/asm-sparc/siginfo.h25
-rw-r--r--include/asm-sparc/siginfo_32.h17
-rw-r--r--include/asm-sparc/siginfo_64.h32
-rw-r--r--include/asm-sparc/signal.h209
-rw-r--r--include/asm-sparc/signal_32.h207
-rw-r--r--include/asm-sparc/signal_64.h194
-rw-r--r--include/asm-sparc/smp.h177
-rw-r--r--include/asm-sparc/smp_32.h173
-rw-r--r--include/asm-sparc/smp_64.h67
-rw-r--r--include/asm-sparc/sparsemem.h12
-rw-r--r--include/asm-sparc/spinlock.h200
-rw-r--r--include/asm-sparc/spinlock_32.h192
-rw-r--r--include/asm-sparc/spinlock_64.h250
-rw-r--r--include/asm-sparc/spinlock_types.h2
-rw-r--r--include/asm-sparc/spitfire.h342
-rw-r--r--include/asm-sparc/sstate.h13
-rw-r--r--include/asm-sparc/stacktrace.h6
-rw-r--r--include/asm-sparc/starfire.h21
-rw-r--r--include/asm-sparc/stat.h82
-rw-r--r--include/asm-sparc/stat_32.h76
-rw-r--r--include/asm-sparc/stat_64.h47
-rw-r--r--include/asm-sparc/statfs.h12
-rw-r--r--include/asm-sparc/statfs_32.h6
-rw-r--r--include/asm-sparc/statfs_64.h54
-rw-r--r--include/asm-sparc/string.h213
-rw-r--r--include/asm-sparc/string_32.h205
-rw-r--r--include/asm-sparc/string_64.h83
-rw-r--r--include/asm-sparc/syscalls.h13
-rw-r--r--include/asm-sparc/system.h290
-rw-r--r--include/asm-sparc/system_32.h288
-rw-r--r--include/asm-sparc/system_64.h355
-rw-r--r--include/asm-sparc/termbits.h5
-rw-r--r--include/asm-sparc/termios.h79
-rw-r--r--include/asm-sparc/thread_info.h157
-rw-r--r--include/asm-sparc/thread_info_32.h151
-rw-r--r--include/asm-sparc/thread_info_64.h277
-rw-r--r--include/asm-sparc/timer.h113
-rw-r--r--include/asm-sparc/timer_32.h107
-rw-r--r--include/asm-sparc/timer_64.h30
-rw-r--r--include/asm-sparc/timex.h21
-rw-r--r--include/asm-sparc/timex_32.h15
-rw-r--r--include/asm-sparc/timex_64.h19
-rw-r--r--include/asm-sparc/tlb.h32
-rw-r--r--include/asm-sparc/tlb_32.h24
-rw-r--r--include/asm-sparc/tlb_64.h111
-rw-r--r--include/asm-sparc/tlbflush.h68
-rw-r--r--include/asm-sparc/tlbflush_32.h60
-rw-r--r--include/asm-sparc/tlbflush_64.h44
-rw-r--r--include/asm-sparc/topology.h14
-rw-r--r--include/asm-sparc/topology_32.h6
-rw-r--r--include/asm-sparc/topology_64.h86
-rw-r--r--include/asm-sparc/tsb.h283
-rw-r--r--include/asm-sparc/ttable.h658
-rw-r--r--include/asm-sparc/types.h32
-rw-r--r--include/asm-sparc/uaccess.h342
-rw-r--r--include/asm-sparc/uaccess_32.h336
-rw-r--r--include/asm-sparc/uaccess_64.h273
-rw-r--r--include/asm-sparc/uctx.h71
-rw-r--r--include/asm-sparc/unistd.h386
-rw-r--r--include/asm-sparc/unistd_32.h378
-rw-r--r--include/asm-sparc/unistd_64.h373
-rw-r--r--include/asm-sparc/upa.h109
-rw-r--r--include/asm-sparc/utrap.h51
-rw-r--r--include/asm-sparc/vaddrs.h5
-rw-r--r--include/asm-sparc/vio.h406
-rw-r--r--include/asm-sparc/visasm.h62
-rw-r--r--include/asm-sparc/watchdog.h31
-rw-r--r--include/asm-sparc/xor.h277
-rw-r--r--include/asm-sparc/xor_32.h269
-rw-r--r--include/asm-sparc/xor_64.h70
-rw-r--r--include/asm-sparc64/Kbuild24
-rw-r--r--include/asm-sparc64/agp.h21
-rw-r--r--include/asm-sparc64/apb.h37
-rw-r--r--include/asm-sparc64/asi.h161
-rw-r--r--include/asm-sparc64/atomic.h129
-rw-r--r--include/asm-sparc64/auxio.h101
-rw-r--r--include/asm-sparc64/backoff.h32
-rw-r--r--include/asm-sparc64/bbc.h226
-rw-r--r--include/asm-sparc64/bitops.h108
-rw-r--r--include/asm-sparc64/cacheflush.h77
-rw-r--r--include/asm-sparc64/chafsr.h242
-rw-r--r--include/asm-sparc64/checksum.h168
-rw-r--r--include/asm-sparc64/chmctrl.h184
-rw-r--r--include/asm-sparc64/cmt.h60
-rw-r--r--include/asm-sparc64/compat.h244
-rw-r--r--include/asm-sparc64/compat_signal.h30
-rw-r--r--include/asm-sparc64/cpudata.h241
-rw-r--r--include/asm-sparc64/dcr.h15
-rw-r--r--include/asm-sparc64/dcu.h28
-rw-r--r--include/asm-sparc64/delay.h18
-rw-r--r--include/asm-sparc64/display7seg.h80
-rw-r--r--include/asm-sparc64/dma-mapping.h155
-rw-r--r--include/asm-sparc64/dma.h206
-rw-r--r--include/asm-sparc64/ebus.h95
-rw-r--r--include/asm-sparc64/elf.h218
-rw-r--r--include/asm-sparc64/envctrl.h104
-rw-r--r--include/asm-sparc64/estate.h50
-rw-r--r--include/asm-sparc64/fbio.h331
-rw-r--r--include/asm-sparc64/fcntl.h36
-rw-r--r--include/asm-sparc64/fhc.h132
-rw-r--r--include/asm-sparc64/floppy.h783
-rw-r--r--include/asm-sparc64/fpumacro.h34
-rw-r--r--include/asm-sparc64/futex.h111
-rw-r--r--include/asm-sparc64/hardirq.h20
-rw-r--r--include/asm-sparc64/head.h77
-rw-r--r--include/asm-sparc64/hugetlb.h85
-rw-r--r--include/asm-sparc64/hvtramp.h38
-rw-r--r--include/asm-sparc64/hw_irq.h5
-rw-r--r--include/asm-sparc64/hypervisor.h2946
-rw-r--r--include/asm-sparc64/ide.h119
-rw-r--r--include/asm-sparc64/idprom.h26
-rw-r--r--include/asm-sparc64/intr_queue.h16
-rw-r--r--include/asm-sparc64/io.h512
-rw-r--r--include/asm-sparc64/ioctl.h68
-rw-r--r--include/asm-sparc64/ioctls.h137
-rw-r--r--include/asm-sparc64/iommu.h63
-rw-r--r--include/asm-sparc64/ipcbuf.h29
-rw-r--r--include/asm-sparc64/irq.h94
-rw-r--r--include/asm-sparc64/irq_regs.h2
-rw-r--r--include/asm-sparc64/irqflags.h90
-rw-r--r--include/asm-sparc64/kdebug.h20
-rw-r--r--include/asm-sparc64/kmap_types.h26
-rw-r--r--include/asm-sparc64/kprobes.h50
-rw-r--r--include/asm-sparc64/kvm.h7
-rw-r--r--include/asm-sparc64/ldc.h139
-rw-r--r--include/asm-sparc64/linkage.h7
-rw-r--r--include/asm-sparc64/lmb.h11
-rw-r--r--include/asm-sparc64/lsu.h20
-rw-r--r--include/asm-sparc64/mc146818rtc.h35
-rw-r--r--include/asm-sparc64/mdesc.h79
-rw-r--r--include/asm-sparc64/mman.h32
-rw-r--r--include/asm-sparc64/mmu.h128
-rw-r--r--include/asm-sparc64/mmu_context.h156
-rw-r--r--include/asm-sparc64/mmzone.h18
-rw-r--r--include/asm-sparc64/module.h8
-rw-r--r--include/asm-sparc64/mostek.h144
-rw-r--r--include/asm-sparc64/msgbuf.h28
-rw-r--r--include/asm-sparc64/mutex.h10
-rw-r--r--include/asm-sparc64/namei.h14
-rw-r--r--include/asm-sparc64/ns87303.h119
-rw-r--r--include/asm-sparc64/of_platform.h26
-rw-r--r--include/asm-sparc64/openprom.h281
-rw-r--r--include/asm-sparc64/openpromio.h70
-rw-r--r--include/asm-sparc64/oplib.h323
-rw-r--r--include/asm-sparc64/page.h143
-rw-r--r--include/asm-sparc64/param.h24
-rw-r--r--include/asm-sparc64/parport.h247
-rw-r--r--include/asm-sparc64/pci.h210
-rw-r--r--include/asm-sparc64/percpu.h29
-rw-r--r--include/asm-sparc64/perfctr.h174
-rw-r--r--include/asm-sparc64/pgalloc.h82
-rw-r--r--include/asm-sparc64/pgtable.h782
-rw-r--r--include/asm-sparc64/pil.h22
-rw-r--r--include/asm-sparc64/poll.h13
-rw-r--r--include/asm-sparc64/posix_types.h123
-rw-r--r--include/asm-sparc64/processor.h238
-rw-r--r--include/asm-sparc64/psrcompat.h46
-rw-r--r--include/asm-sparc64/pstate.h92
-rw-r--r--include/asm-sparc64/ptrace.h347
-rw-r--r--include/asm-sparc64/reboot.h7
-rw-r--r--include/asm-sparc64/reg.h57
-rw-r--r--include/asm-sparc64/resource.h20
-rw-r--r--include/asm-sparc64/rtc.h27
-rw-r--r--include/asm-sparc64/rwsem-const.h13
-rw-r--r--include/asm-sparc64/rwsem.h85
-rw-r--r--include/asm-sparc64/sbus.h191
-rw-r--r--include/asm-sparc64/scatterlist.h28
-rw-r--r--include/asm-sparc64/scratchpad.h15
-rw-r--r--include/asm-sparc64/seccomp.h22
-rw-r--r--include/asm-sparc64/sections.h10
-rw-r--r--include/asm-sparc64/semaphore.h2
-rw-r--r--include/asm-sparc64/sembuf.h23
-rw-r--r--include/asm-sparc64/setup.h11
-rw-r--r--include/asm-sparc64/sfafsr.h83
-rw-r--r--include/asm-sparc64/sfp-machine.h94
-rw-r--r--include/asm-sparc64/shmbuf.h39
-rw-r--r--include/asm-sparc64/shmparam.h11
-rw-r--r--include/asm-sparc64/sigcontext.h88
-rw-r--r--include/asm-sparc64/siginfo.h33
-rw-r--r--include/asm-sparc64/signal.h195
-rw-r--r--include/asm-sparc64/smp.h65
-rw-r--r--include/asm-sparc64/socket.h58
-rw-r--r--include/asm-sparc64/sockios.h15
-rw-r--r--include/asm-sparc64/sparsemem.h13
-rw-r--r--include/asm-sparc64/spinlock.h251
-rw-r--r--include/asm-sparc64/spinlock_types.h21
-rw-r--r--include/asm-sparc64/spitfire.h343
-rw-r--r--include/asm-sparc64/sstate.h14
-rw-r--r--include/asm-sparc64/stacktrace.h7
-rw-r--r--include/asm-sparc64/starfire.h22
-rw-r--r--include/asm-sparc64/stat.h48
-rw-r--r--include/asm-sparc64/statfs.h55
-rw-r--r--include/asm-sparc64/string.h84
-rw-r--r--include/asm-sparc64/sunbpp.h81
-rw-r--r--include/asm-sparc64/syscalls.h14
-rw-r--r--include/asm-sparc64/system.h356
-rw-r--r--include/asm-sparc64/termbits.h261
-rw-r--r--include/asm-sparc64/termios.h187
-rw-r--r--include/asm-sparc64/thread_info.h278
-rw-r--r--include/asm-sparc64/timer.h31
-rw-r--r--include/asm-sparc64/timex.h20
-rw-r--r--include/asm-sparc64/tlb.h112
-rw-r--r--include/asm-sparc64/tlbflush.h45
-rw-r--r--include/asm-sparc64/topology.h87
-rw-r--r--include/asm-sparc64/tsb.h284
-rw-r--r--include/asm-sparc64/ttable.h659
-rw-r--r--include/asm-sparc64/types.h35
-rw-r--r--include/asm-sparc64/uaccess.h274
-rw-r--r--include/asm-sparc64/uctx.h72
-rw-r--r--include/asm-sparc64/unaligned.h11
-rw-r--r--include/asm-sparc64/unistd.h374
-rw-r--r--include/asm-sparc64/upa.h110
-rw-r--r--include/asm-sparc64/utrap.h52
-rw-r--r--include/asm-sparc64/vga.h34
-rw-r--r--include/asm-sparc64/vio.h407
-rw-r--r--include/asm-sparc64/visasm.h63
-rw-r--r--include/asm-sparc64/watchdog.h32
-rw-r--r--include/asm-sparc64/xor.h71
-rw-r--r--include/linux/auxvec.h4
-rw-r--r--include/linux/cpufreq.h3
-rw-r--r--include/linux/debugfs.h4
-rw-r--r--include/linux/device-mapper.h6
-rw-r--r--include/linux/device.h58
-rw-r--r--include/linux/dm-ioctl.h4
-rw-r--r--include/linux/dma-attrs.h1
-rw-r--r--include/linux/eisa.h2
-rw-r--r--include/linux/fs_enet_pd.h4
-rw-r--r--include/linux/fsl_devices.h7
-rw-r--r--include/linux/gameport.h1
-rw-r--r--include/linux/gpio_keys.h1
-rw-r--r--include/linux/input.h9
-rw-r--r--include/linux/joystick.h2
-rw-r--r--include/linux/kmod.h5
-rw-r--r--include/linux/kobject.h3
-rw-r--r--include/linux/libps2.h1
-rw-r--r--include/linux/module.h50
-rw-r--r--include/linux/mtd/map.h2
-rw-r--r--include/linux/mtd/mtd.h2
-rw-r--r--include/linux/netfilter/nf_conntrack_common.h8
-rw-r--r--include/linux/netfilter/nfnetlink_conntrack.h8
-rw-r--r--include/linux/netfilter/nfnetlink_log.h3
-rw-r--r--include/linux/of_gpio.h2
-rw-r--r--include/linux/raid/bitmap.h1
-rw-r--r--include/linux/raid/linear.h2
-rw-r--r--include/linux/raid/md.h2
-rw-r--r--include/linux/raid/md_k.h17
-rw-r--r--include/linux/raid/md_p.h3
-rw-r--r--include/linux/raid/raid5.h64
-rw-r--r--include/linux/serio.h4
-rw-r--r--include/linux/spi/max7301.h9
-rw-r--r--include/linux/spi/spi.h2
-rw-r--r--include/linux/synclink.h1
-rw-r--r--include/linux/sysdev.h39
-rw-r--r--include/linux/sysfs.h10
-rw-r--r--include/linux/tty.h11
-rw-r--r--include/linux/tty_driver.h14
-rw-r--r--include/linux/uio_driver.h8
-rw-r--r--include/linux/usb.h12
-rw-r--r--include/linux/usb/composite.h338
-rw-r--r--include/linux/usb/gadget.h27
-rw-r--r--include/linux/usb/irda.h151
-rw-r--r--include/linux/usb/serial.h56
-rw-r--r--include/linux/usbdevice_fs.h2
-rw-r--r--include/net/netfilter/nf_conntrack.h6
-rw-r--r--include/net/netfilter/nf_conntrack_acct.h51
-rw-r--r--include/net/netfilter/nf_conntrack_extend.h2
-rw-r--r--include/net/netlink.h3
-rw-r--r--include/scsi/scsi_host.h2
-rw-r--r--include/scsi/scsi_transport_fc.h4
-rw-r--r--include/scsi/scsi_transport_iscsi.h2
-rw-r--r--init/Kconfig15
-rw-r--r--kernel/cpuset.c4
-rw-r--r--kernel/exec_domain.c2
-rw-r--r--kernel/kmod.c2
-rw-r--r--kernel/module.c336
-rw-r--r--kernel/rtmutex-tester.c7
-rw-r--r--kernel/sched.c8
-rw-r--r--kernel/sys_ni.c1
-rw-r--r--kernel/sysctl.c4
-rw-r--r--kernel/time/clocksource.c8
-rw-r--r--lib/Kconfig.debug3
-rw-r--r--lib/kobject.c10
-rw-r--r--lib/kobject_uevent.c3
-rw-r--r--lib/textsearch.c2
-rw-r--r--mm/slub.c10
-rw-r--r--net/bluetooth/hci_sysfs.c7
-rw-r--r--net/core/dev.c37
-rw-r--r--net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c18
-rw-r--r--net/ipv4/netfilter/nf_nat_core.c8
-rw-r--r--net/ipv4/netfilter/nf_nat_sip.c38
-rw-r--r--net/netfilter/Kconfig9
-rw-r--r--net/netfilter/Makefile2
-rw-r--r--net/netfilter/nf_conntrack_acct.c104
-rw-r--r--net/netfilter/nf_conntrack_core.c39
-rw-r--r--net/netfilter/nf_conntrack_netlink.c44
-rw-r--r--net/netfilter/nf_conntrack_proto_sctp.c8
-rw-r--r--net/netfilter/nf_conntrack_standalone.c18
-rw-r--r--net/netfilter/nfnetlink_log.c8
-rw-r--r--net/netfilter/xt_TCPMSS.c42
-rw-r--r--net/netfilter/xt_connbytes.c8
-rw-r--r--net/netfilter/xt_time.c2
-rw-r--r--net/sched/sch_generic.c102
-rw-r--r--samples/firmware_class/firmware_sample_firmware_class.c2
-rw-r--r--samples/kobject/kset-example.c2
-rw-r--r--scripts/Makefile.modpost1
-rw-r--r--scripts/mod/file2alias.c24
-rw-r--r--scripts/mod/modpost.c3
-rw-r--r--sound/core/init.c5
-rw-r--r--sound/oss/soundcard.c14
-rw-r--r--sound/sound_core.c5
1183 files changed, 62408 insertions, 48131 deletions
diff --git a/CREDITS b/CREDITS
index e97bea06b59f..077b147388bd 100644
--- a/CREDITS
+++ b/CREDITS
@@ -3344,8 +3344,7 @@ S: Spain
3344N: Linus Torvalds 3344N: Linus Torvalds
3345E: torvalds@linux-foundation.org 3345E: torvalds@linux-foundation.org
3346D: Original kernel hacker 3346D: Original kernel hacker
3347S: 12725 SW Millikan Way, Suite 400 3347S: Portland, Oregon 97005
3348S: Beaverton, Oregon 97005
3349S: USA 3348S: USA
3350 3349
3351N: Marcelo Tosatti 3350N: Marcelo Tosatti
diff --git a/Documentation/ABI/testing/sysfs-dev b/Documentation/ABI/testing/sysfs-dev
new file mode 100644
index 000000000000..a9f2b8b0530f
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-dev
@@ -0,0 +1,20 @@
1What: /sys/dev
2Date: April 2008
3KernelVersion: 2.6.26
4Contact: Dan Williams <dan.j.williams@intel.com>
5Description: The /sys/dev tree provides a method to look up the sysfs
6 path for a device using the information returned from
7 stat(2). There are two directories, 'block' and 'char',
8 beneath /sys/dev containing symbolic links with names of
9 the form "<major>:<minor>". These links point to the
10 corresponding sysfs path for the given device.
11
12 Example:
13 $ readlink /sys/dev/block/8:32
14 ../../block/sdc
15
16 Entries in /sys/dev/char and /sys/dev/block will be
17 dynamically created and destroyed as devices enter and
18 leave the system.
19
20Users: mdadm <linux-raid@vger.kernel.org>
diff --git a/Documentation/DMA-attributes.txt b/Documentation/DMA-attributes.txt
index 6d772f84b477..b768cc0e402b 100644
--- a/Documentation/DMA-attributes.txt
+++ b/Documentation/DMA-attributes.txt
@@ -22,3 +22,12 @@ ready and available in memory. The DMA of the "completion indication"
22could race with data DMA. Mapping the memory used for completion 22could race with data DMA. Mapping the memory used for completion
23indications with DMA_ATTR_WRITE_BARRIER would prevent the race. 23indications with DMA_ATTR_WRITE_BARRIER would prevent the race.
24 24
25DMA_ATTR_WEAK_ORDERING
26----------------------
27
28DMA_ATTR_WEAK_ORDERING specifies that reads and writes to the mapping
29may be weakly ordered, that is that reads and writes may pass each other.
30
31Since it is optional for platforms to implement DMA_ATTR_WEAK_ORDERING,
32those that do not will simply ignore the attribute and exhibit default
33behavior.
diff --git a/Documentation/DocBook/gadget.tmpl b/Documentation/DocBook/gadget.tmpl
index 5a8ffa761e09..ea3bc9565e6a 100644
--- a/Documentation/DocBook/gadget.tmpl
+++ b/Documentation/DocBook/gadget.tmpl
@@ -524,6 +524,44 @@ These utilities include endpoint autoconfiguration.
524<!-- !Edrivers/usb/gadget/epautoconf.c --> 524<!-- !Edrivers/usb/gadget/epautoconf.c -->
525</sect1> 525</sect1>
526 526
527<sect1 id="composite"><title>Composite Device Framework</title>
528
529<para>The core API is sufficient for writing drivers for composite
530USB devices (with more than one function in a given configuration),
531and also multi-configuration devices (also more than one function,
532but not necessarily sharing a given configuration).
533There is however an optional framework which makes it easier to
534reuse and combine functions.
535</para>
536
537<para>Devices using this framework provide a <emphasis>struct
538usb_composite_driver</emphasis>, which in turn provides one or
539more <emphasis>struct usb_configuration</emphasis> instances.
540Each such configuration includes at least one
541<emphasis>struct usb_function</emphasis>, which packages a user
542visible role such as "network link" or "mass storage device".
543Management functions may also exist, such as "Device Firmware
544Upgrade".
545</para>
546
547!Iinclude/linux/usb/composite.h
548!Edrivers/usb/gadget/composite.c
549
550</sect1>
551
552<sect1 id="functions"><title>Composite Device Functions</title>
553
554<para>At this writing, a few of the current gadget drivers have
555been converted to this framework.
556Near-term plans include converting all of them, except for "gadgetfs".
557</para>
558
559!Edrivers/usb/gadget/f_acm.c
560!Edrivers/usb/gadget/f_serial.c
561
562</sect1>
563
564
527</chapter> 565</chapter>
528 566
529<chapter id="controllers"><title>Peripheral Controller Drivers</title> 567<chapter id="controllers"><title>Peripheral Controller Drivers</title>
diff --git a/Documentation/DocBook/uio-howto.tmpl b/Documentation/DocBook/uio-howto.tmpl
index fdd7f4f887b7..df87d1b93605 100644
--- a/Documentation/DocBook/uio-howto.tmpl
+++ b/Documentation/DocBook/uio-howto.tmpl
@@ -21,6 +21,18 @@
21 </affiliation> 21 </affiliation>
22</author> 22</author>
23 23
24<copyright>
25 <year>2006-2008</year>
26 <holder>Hans-Jürgen Koch.</holder>
27</copyright>
28
29<legalnotice>
30<para>
31This documentation is Free Software licensed under the terms of the
32GPL version 2.
33</para>
34</legalnotice>
35
24<pubdate>2006-12-11</pubdate> 36<pubdate>2006-12-11</pubdate>
25 37
26<abstract> 38<abstract>
@@ -30,6 +42,12 @@
30 42
31<revhistory> 43<revhistory>
32 <revision> 44 <revision>
45 <revnumber>0.5</revnumber>
46 <date>2008-05-22</date>
47 <authorinitials>hjk</authorinitials>
48 <revremark>Added description of write() function.</revremark>
49 </revision>
50 <revision>
33 <revnumber>0.4</revnumber> 51 <revnumber>0.4</revnumber>
34 <date>2007-11-26</date> 52 <date>2007-11-26</date>
35 <authorinitials>hjk</authorinitials> 53 <authorinitials>hjk</authorinitials>
@@ -57,20 +75,9 @@
57</bookinfo> 75</bookinfo>
58 76
59<chapter id="aboutthisdoc"> 77<chapter id="aboutthisdoc">
60<?dbhtml filename="about.html"?> 78<?dbhtml filename="aboutthis.html"?>
61<title>About this document</title> 79<title>About this document</title>
62 80
63<sect1 id="copyright">
64<?dbhtml filename="copyright.html"?>
65<title>Copyright and License</title>
66<para>
67 Copyright (c) 2006 by Hans-Jürgen Koch.</para>
68<para>
69This documentation is Free Software licensed under the terms of the
70GPL version 2.
71</para>
72</sect1>
73
74<sect1 id="translations"> 81<sect1 id="translations">
75<?dbhtml filename="translations.html"?> 82<?dbhtml filename="translations.html"?>
76<title>Translations</title> 83<title>Translations</title>
@@ -189,6 +196,30 @@ interested in translating it, please email me
189 represents the total interrupt count. You can use this number 196 represents the total interrupt count. You can use this number
190 to figure out if you missed some interrupts. 197 to figure out if you missed some interrupts.
191 </para> 198 </para>
199 <para>
200 For some hardware that has more than one interrupt source internally,
201 but not separate IRQ mask and status registers, there might be
202 situations where userspace cannot determine what the interrupt source
203 was if the kernel handler disables them by writing to the chip's IRQ
204 register. In such a case, the kernel has to disable the IRQ completely
205 to leave the chip's register untouched. Now the userspace part can
206 determine the cause of the interrupt, but it cannot re-enable
207 interrupts. Another cornercase is chips where re-enabling interrupts
208 is a read-modify-write operation to a combined IRQ status/acknowledge
209 register. This would be racy if a new interrupt occurred
210 simultaneously.
211 </para>
212 <para>
213 To address these problems, UIO also implements a write() function. It
214 is normally not used and can be ignored for hardware that has only a
215 single interrupt source or has separate IRQ mask and status registers.
216 If you need it, however, a write to <filename>/dev/uioX</filename>
217 will call the <function>irqcontrol()</function> function implemented
218 by the driver. You have to write a 32-bit value that is usually either
219 0 or 1 to disable or enable interrupts. If a driver does not implement
220 <function>irqcontrol()</function>, <function>write()</function> will
221 return with <varname>-ENOSYS</varname>.
222 </para>
192 223
193 <para> 224 <para>
194 To handle interrupts properly, your custom kernel module can 225 To handle interrupts properly, your custom kernel module can
@@ -362,6 +393,14 @@ device is actually used.
362<function>open()</function>, you will probably also want a custom 393<function>open()</function>, you will probably also want a custom
363<function>release()</function> function. 394<function>release()</function> function.
364</para></listitem> 395</para></listitem>
396
397<listitem><para>
398<varname>int (*irqcontrol)(struct uio_info *info, s32 irq_on)
399</varname>: Optional. If you need to be able to enable or disable
400interrupts from userspace by writing to <filename>/dev/uioX</filename>,
401you can implement this function. The parameter <varname>irq_on</varname>
402will be 0 to disable interrupts and 1 to enable them.
403</para></listitem>
365</itemizedlist> 404</itemizedlist>
366 405
367<para> 406<para>
diff --git a/Documentation/HOWTO b/Documentation/HOWTO
index 619e8caf30db..c2371c5a98f9 100644
--- a/Documentation/HOWTO
+++ b/Documentation/HOWTO
@@ -358,7 +358,7 @@ Here is a list of some of the different kernel trees available:
358 - pcmcia, Dominik Brodowski <linux@dominikbrodowski.net> 358 - pcmcia, Dominik Brodowski <linux@dominikbrodowski.net>
359 git.kernel.org:/pub/scm/linux/kernel/git/brodo/pcmcia-2.6.git 359 git.kernel.org:/pub/scm/linux/kernel/git/brodo/pcmcia-2.6.git
360 360
361 - SCSI, James Bottomley <James.Bottomley@SteelEye.com> 361 - SCSI, James Bottomley <James.Bottomley@hansenpartnership.com>
362 git.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git 362 git.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git
363 363
364 - x86, Ingo Molnar <mingo@elte.hu> 364 - x86, Ingo Molnar <mingo@elte.hu>
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 86334b6f8238..9f73587219e8 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -336,3 +336,13 @@ When: After the only user (hal) has seen a release with the patches
336Why: Over 1K .text/.data size reduction, data is available in other 336Why: Over 1K .text/.data size reduction, data is available in other
337 ways (ioctls) 337 ways (ioctls)
338Who: Johannes Berg <johannes@sipsolutions.net> 338Who: Johannes Berg <johannes@sipsolutions.net>
339
340---------------------------
341
342What: CONFIG_NF_CT_ACCT
343When: 2.6.29
344Why: Accounting can now be enabled/disabled without kernel recompilation.
345 Currently used only to set a default value for a feature that is also
346 controlled by a kernel/module/sysfs/sysctl parameter.
347Who: Krzysztof Piotr Oledzki <ole@ans.pl>
348
diff --git a/Documentation/filesystems/bfs.txt b/Documentation/filesystems/bfs.txt
index ea825e178e79..78043d5a8fc3 100644
--- a/Documentation/filesystems/bfs.txt
+++ b/Documentation/filesystems/bfs.txt
@@ -26,11 +26,11 @@ You can simplify mounting by just typing:
26 26
27this will allocate the first available loopback device (and load loop.o 27this will allocate the first available loopback device (and load loop.o
28kernel module if necessary) automatically. If the loopback driver is not 28kernel module if necessary) automatically. If the loopback driver is not
29loaded automatically, make sure that your kernel is compiled with kmod 29loaded automatically, make sure that you have compiled the module and
30support (CONFIG_KMOD) enabled. Beware that umount will not 30that modprobe is functioning. Beware that umount will not deallocate
31deallocate /dev/loopN device if /etc/mtab file on your system is a 31/dev/loopN device if /etc/mtab file on your system is a symbolic link to
32symbolic link to /proc/mounts. You will need to do it manually using 32/proc/mounts. You will need to do it manually using "-d" switch of
33"-d" switch of losetup(8). Read losetup(8) manpage for more info. 33losetup(8). Read losetup(8) manpage for more info.
34 34
35To create the BFS image under UnixWare you need to find out first which 35To create the BFS image under UnixWare you need to find out first which
36slice contains it. The command prtvtoc(1M) is your friend: 36slice contains it. The command prtvtoc(1M) is your friend:
diff --git a/Documentation/filesystems/sysfs.txt b/Documentation/filesystems/sysfs.txt
index 7f27b8f840d0..9e9c348275a9 100644
--- a/Documentation/filesystems/sysfs.txt
+++ b/Documentation/filesystems/sysfs.txt
@@ -248,6 +248,7 @@ The top level sysfs directory looks like:
248block/ 248block/
249bus/ 249bus/
250class/ 250class/
251dev/
251devices/ 252devices/
252firmware/ 253firmware/
253net/ 254net/
@@ -274,6 +275,11 @@ fs/ contains a directory for some filesystems. Currently each
274filesystem wanting to export attributes must create its own hierarchy 275filesystem wanting to export attributes must create its own hierarchy
275below fs/ (see ./fuse.txt for an example). 276below fs/ (see ./fuse.txt for an example).
276 277
278dev/ contains two directories char/ and block/. Inside these two
279directories there are symlinks named <major>:<minor>. These symlinks
280point to the sysfs directory for the given device. /sys/dev provides a
281quick way to lookup the sysfs interface for a device from the result of
282a stat(2) operation.
277 283
278More information can driver-model specific features can be found in 284More information can driver-model specific features can be found in
279Documentation/driver-model/. 285Documentation/driver-model/.
diff --git a/Documentation/ia64/paravirt_ops.txt b/Documentation/ia64/paravirt_ops.txt
new file mode 100644
index 000000000000..39ded02ec33f
--- /dev/null
+++ b/Documentation/ia64/paravirt_ops.txt
@@ -0,0 +1,137 @@
1Paravirt_ops on IA64
2====================
3 21 May 2008, Isaku Yamahata <yamahata@valinux.co.jp>
4
5
6Introduction
7------------
8The aim of this documentation is to help with maintainability and/or to
9encourage people to use paravirt_ops/IA64.
10
11paravirt_ops (pv_ops in short) is a way for virtualization support of
12Linux kernel on x86. Several ways for virtualization support were
13proposed, paravirt_ops is the winner.
14On the other hand, now there are also several IA64 virtualization
15technologies like kvm/IA64, xen/IA64 and many other academic IA64
16hypervisors so that it is good to add generic virtualization
17infrastructure on Linux/IA64.
18
19
20What is paravirt_ops?
21---------------------
22It has been developed on x86 as virtualization support via API, not ABI.
23It allows each hypervisor to override operations which are important for
24hypervisors at API level. And it allows a single kernel binary to run on
25all supported execution environments including native machine.
26Essentially paravirt_ops is a set of function pointers which represent
27operations corresponding to low level sensitive instructions and high
28level functionalities in various area. But one significant difference
29from usual function pointer table is that it allows optimization with
30binary patch. It is because some of these operations are very
31performance sensitive and indirect call overhead is not negligible.
32With binary patch, indirect C function call can be transformed into
33direct C function call or in-place execution to eliminate the overhead.
34
35Thus, operations of paravirt_ops are classified into three categories.
36- simple indirect call
37 These operations correspond to high level functionality so that the
38 overhead of indirect call isn't very important.
39
40- indirect call which allows optimization with binary patch
41 Usually these operations correspond to low level instructions. They
42 are called frequently and performance critical. So the overhead is
43 very important.
44
45- a set of macros for hand written assembly code
46 Hand written assembly codes (.S files) also need paravirtualization
47 because they include sensitive instructions or some of code paths in
48 them are very performance critical.
49
50
51The relation to the IA64 machine vector
52---------------------------------------
53Linux/IA64 has the IA64 machine vector functionality which allows the
54kernel to switch implementations (e.g. initialization, ipi, dma api...)
55depending on executing platform.
56We can replace some implementations very easily defining a new machine
57vector. Thus another approach for virtualization support would be
58enhancing the machine vector functionality.
59But paravirt_ops approach was taken because
60- virtualization support needs wider support than machine vector does.
61 e.g. low level instruction paravirtualization. It must be
62 initialized very early before platform detection.
63
64- virtualization support needs more functionality like binary patch.
65 Probably the calling overhead might not be very large compared to the
66 emulation overhead of virtualization. However in the native case, the
67 overhead should be eliminated completely.
68 A single kernel binary should run on each environment including native,
69 and the overhead of paravirt_ops on native environment should be as
70 small as possible.
71
72- for full virtualization technology, e.g. KVM/IA64 or
73 Xen/IA64 HVM domain, the result would be
74 (the emulated platform machine vector. probably dig) + (pv_ops).
75 This means that the virtualization support layer should be under
76 the machine vector layer.
77
78Possibly it might be better to move some function pointers from
79paravirt_ops to machine vector. In fact, Xen domU case utilizes both
80pv_ops and machine vector.
81
82
83IA64 paravirt_ops
84-----------------
85In this section, the concrete paravirt_ops will be discussed.
86Because of the architecture difference between ia64 and x86, the
87resulting set of functions is very different from x86 pv_ops.
88
89- C function pointer tables
90They are not very performance critical so that simple C indirect
91function call is acceptable. The following structures are defined at
92this moment. For details see linux/include/asm-ia64/paravirt.h
93 - struct pv_info
94 This structure describes the execution environment.
95 - struct pv_init_ops
96 This structure describes the various initialization hooks.
97 - struct pv_iosapic_ops
98 This structure describes hooks to iosapic operations.
99 - struct pv_irq_ops
100 This structure describes hooks to irq related operations
101 - struct pv_time_op
102 This structure describes hooks to steal time accounting.
103
104- a set of indirect calls which need optimization
105Currently this class of functions correspond to a subset of IA64
106intrinsics. At this moment the optimization with binary patch isn't
107implemented yet.
108struct pv_cpu_op is defined. For details see
109linux/include/asm-ia64/paravirt_privop.h
110Mostly they correspond to ia64 intrinsics 1-to-1.
111Caveat: Now they are defined as C indirect function pointers, but in
112order to support binary patch optimization, they will be changed
113using GCC extended inline assembly code.
114
115- a set of macros for hand written assembly code (.S files)
116For maintenance purpose, the taken approach for .S files is single
117source code and compile multiple times with different macros definitions.
118Each pv_ops instance must define those macros to compile.
119The important thing here is that sensitive, but non-privileged
120instructions must be paravirtualized and that some privileged
121instructions also need paravirtualization for reasonable performance.
122Developers who modify .S files must be aware of that. At this moment
123an easy checker is implemented to detect paravirtualization breakage.
124But it doesn't cover all the cases.
125
126Sometimes this set of macros is called pv_cpu_asm_op. But there is no
127corresponding structure in the source code.
128Those macros mostly 1:1 correspond to a subset of privileged
129instructions. See linux/include/asm-ia64/native/inst.h.
130And some functions written in assembly also need to be overrided so
131that each pv_ops instance have to define some macros. Again see
132linux/include/asm-ia64/native/inst.h.
133
134
135Those structures must be initialized very early before start_kernel.
136Probably initialized in head.S using multi entry point or some other trick.
137For native case implementation see linux/arch/ia64/kernel/paravirt.c.
diff --git a/Documentation/input/gameport-programming.txt b/Documentation/input/gameport-programming.txt
index 14e0a8b70225..03a74fc3b496 100644
--- a/Documentation/input/gameport-programming.txt
+++ b/Documentation/input/gameport-programming.txt
@@ -1,5 +1,3 @@
1$Id: gameport-programming.txt,v 1.3 2001/04/24 13:51:37 vojtech Exp $
2
3Programming gameport drivers 1Programming gameport drivers
4~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 3
diff --git a/Documentation/input/input.txt b/Documentation/input/input.txt
index ff8cea0225f9..686ee9932dff 100644
--- a/Documentation/input/input.txt
+++ b/Documentation/input/input.txt
@@ -1,7 +1,6 @@
1 Linux Input drivers v1.0 1 Linux Input drivers v1.0
2 (c) 1999-2001 Vojtech Pavlik <vojtech@ucw.cz> 2 (c) 1999-2001 Vojtech Pavlik <vojtech@ucw.cz>
3 Sponsored by SuSE 3 Sponsored by SuSE
4 $Id: input.txt,v 1.8 2002/05/29 03:15:01 bradleym Exp $
5---------------------------------------------------------------------------- 4----------------------------------------------------------------------------
6 5
70. Disclaimer 60. Disclaimer
diff --git a/Documentation/input/joystick-api.txt b/Documentation/input/joystick-api.txt
index acbd32b88454..c507330740cd 100644
--- a/Documentation/input/joystick-api.txt
+++ b/Documentation/input/joystick-api.txt
@@ -5,8 +5,6 @@
5 5
6 7 Aug 1998 6 7 Aug 1998
7 7
8 $Id: joystick-api.txt,v 1.2 2001/05/08 21:21:23 vojtech Exp $
9
101. Initialization 81. Initialization
11~~~~~~~~~~~~~~~~~ 9~~~~~~~~~~~~~~~~~
12 10
diff --git a/Documentation/input/joystick-parport.txt b/Documentation/input/joystick-parport.txt
index ede5f33daad3..1c856f32ff2c 100644
--- a/Documentation/input/joystick-parport.txt
+++ b/Documentation/input/joystick-parport.txt
@@ -2,7 +2,6 @@
2 (c) 1998-2000 Vojtech Pavlik <vojtech@ucw.cz> 2 (c) 1998-2000 Vojtech Pavlik <vojtech@ucw.cz>
3 (c) 1998 Andree Borrmann <a.borrmann@tu-bs.de> 3 (c) 1998 Andree Borrmann <a.borrmann@tu-bs.de>
4 Sponsored by SuSE 4 Sponsored by SuSE
5 $Id: joystick-parport.txt,v 1.6 2001/09/25 09:31:32 vojtech Exp $
6---------------------------------------------------------------------------- 5----------------------------------------------------------------------------
7 6
80. Disclaimer 70. Disclaimer
diff --git a/Documentation/input/joystick.txt b/Documentation/input/joystick.txt
index 389de9bd9878..154d767b2acb 100644
--- a/Documentation/input/joystick.txt
+++ b/Documentation/input/joystick.txt
@@ -1,7 +1,6 @@
1 Linux Joystick driver v2.0.0 1 Linux Joystick driver v2.0.0
2 (c) 1996-2000 Vojtech Pavlik <vojtech@ucw.cz> 2 (c) 1996-2000 Vojtech Pavlik <vojtech@ucw.cz>
3 Sponsored by SuSE 3 Sponsored by SuSE
4 $Id: joystick.txt,v 1.12 2002/03/03 12:13:07 jdeneux Exp $
5---------------------------------------------------------------------------- 4----------------------------------------------------------------------------
6 5
70. Disclaimer 60. Disclaimer
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 25e88cf5d84e..30d44b78171a 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1279,6 +1279,13 @@ and is between 256 and 4096 characters. It is defined in the file
1279 This usage is only documented in each driver source 1279 This usage is only documented in each driver source
1280 file if at all. 1280 file if at all.
1281 1281
1282 nf_conntrack.acct=
1283 [NETFILTER] Enable connection tracking flow accounting
1284 0 to disable accounting
1285 1 to enable accounting
1286 Default value depends on CONFIG_NF_CT_ACCT that is
1287 going to be removed in 2.6.29.
1288
1282 nfsaddrs= [NFS] 1289 nfsaddrs= [NFS]
1283 See Documentation/filesystems/nfsroot.txt. 1290 See Documentation/filesystems/nfsroot.txt.
1284 1291
diff --git a/Documentation/md.txt b/Documentation/md.txt
index a8b430627473..1da9d1b1793f 100644
--- a/Documentation/md.txt
+++ b/Documentation/md.txt
@@ -236,6 +236,11 @@ All md devices contain:
236 writing the word for the desired state, however some states 236 writing the word for the desired state, however some states
237 cannot be explicitly set, and some transitions are not allowed. 237 cannot be explicitly set, and some transitions are not allowed.
238 238
239 Select/poll works on this file. All changes except between
240 active_idle and active (which can be frequent and are not
241 very interesting) are notified. active->active_idle is
242 reported if the metadata is externally managed.
243
239 clear 244 clear
240 No devices, no size, no level 245 No devices, no size, no level
241 Writing is equivalent to STOP_ARRAY ioctl 246 Writing is equivalent to STOP_ARRAY ioctl
@@ -292,6 +297,10 @@ Each directory contains:
292 writemostly - device will only be subject to read 297 writemostly - device will only be subject to read
293 requests if there are no other options. 298 requests if there are no other options.
294 This applies only to raid1 arrays. 299 This applies only to raid1 arrays.
300 blocked - device has failed, metadata is "external",
301 and the failure hasn't been acknowledged yet.
302 Writes that would write to this device if
303 it were not faulty are blocked.
295 spare - device is working, but not a full member. 304 spare - device is working, but not a full member.
296 This includes spares that are in the process 305 This includes spares that are in the process
297 of being recovered to 306 of being recovered to
@@ -301,6 +310,12 @@ Each directory contains:
301 Writing "remove" removes the device from the array. 310 Writing "remove" removes the device from the array.
302 Writing "writemostly" sets the writemostly flag. 311 Writing "writemostly" sets the writemostly flag.
303 Writing "-writemostly" clears the writemostly flag. 312 Writing "-writemostly" clears the writemostly flag.
313 Writing "blocked" sets the "blocked" flag.
314 Writing "-blocked" clear the "blocked" flag and allows writes
315 to complete.
316
317 This file responds to select/poll. Any change to 'faulty'
318 or 'blocked' causes an event.
304 319
305 errors 320 errors
306 An approximate count of read errors that have been detected on 321 An approximate count of read errors that have been detected on
@@ -332,7 +347,7 @@ Each directory contains:
332 for storage of data. This will normally be the same as the 347 for storage of data. This will normally be the same as the
333 component_size. This can be written while assembling an 348 component_size. This can be written while assembling an
334 array. If a value less than the current component_size is 349 array. If a value less than the current component_size is
335 written, component_size will be reduced to this value. 350 written, it will be rejected.
336 351
337 352
338An active md device will also contain and entry for each active device 353An active md device will also contain and entry for each active device
@@ -381,6 +396,19 @@ also have
381 'check' and 'repair' will start the appropriate process 396 'check' and 'repair' will start the appropriate process
382 providing the current state is 'idle'. 397 providing the current state is 'idle'.
383 398
399 This file responds to select/poll. Any important change in the value
400 triggers a poll event. Sometimes the value will briefly be
401 "recover" if a recovery seems to be needed, but cannot be
402 achieved. In that case, the transition to "recover" isn't
403 notified, but the transition away is.
404
405 degraded
406 This contains a count of the number of devices by which the
407 arrays is degraded. So an optimal array with show '0'. A
408 single failed/missing drive will show '1', etc.
409 This file responds to select/poll, any increase or decrease
410 in the count of missing devices will trigger an event.
411
384 mismatch_count 412 mismatch_count
385 When performing 'check' and 'repair', and possibly when 413 When performing 'check' and 'repair', and possibly when
386 performing 'resync', md will count the number of errors that are 414 performing 'resync', md will count the number of errors that are
diff --git a/Documentation/powerpc/booting-without-of.txt b/Documentation/powerpc/booting-without-of.txt
index aee243a846a2..ea1b70b35793 100644
--- a/Documentation/powerpc/booting-without-of.txt
+++ b/Documentation/powerpc/booting-without-of.txt
@@ -89,10 +89,12 @@ Table of Contents
89 3) OpenPIC Interrupt Controllers 89 3) OpenPIC Interrupt Controllers
90 4) ISA Interrupt Controllers 90 4) ISA Interrupt Controllers
91 91
92 VIII - Specifying GPIO information for devices 92 IX - Specifying GPIO information for devices
93 1) gpios property 93 1) gpios property
94 2) gpio-controller nodes 94 2) gpio-controller nodes
95 95
96 X - Specifying device power management information (sleep property)
97
96 Appendix A - Sample SOC node for MPC8540 98 Appendix A - Sample SOC node for MPC8540
97 99
98 100
@@ -2488,8 +2490,8 @@ encodings listed below:
2488 2 = high to low edge sensitive type enabled 2490 2 = high to low edge sensitive type enabled
2489 3 = low to high edge sensitive type enabled 2491 3 = low to high edge sensitive type enabled
2490 2492
2491VIII - Specifying GPIO information for devices 2493IX - Specifying GPIO information for devices
2492============================================== 2494============================================
2493 2495
24941) gpios property 24961) gpios property
2495----------------- 2497-----------------
@@ -2537,116 +2539,151 @@ Example of two SOC GPIO banks defined as gpio-controller nodes:
2537 gpio-controller; 2539 gpio-controller;
2538 }; 2540 };
2539 2541
2542X - Specifying Device Power Management Information (sleep property)
2543===================================================================
2544
2545Devices on SOCs often have mechanisms for placing devices into low-power
2546states that are decoupled from the devices' own register blocks. Sometimes,
2547this information is more complicated than a cell-index property can
2548reasonably describe. Thus, each device controlled in such a manner
2549may contain a "sleep" property which describes these connections.
2550
2551The sleep property consists of one or more sleep resources, each of
2552which consists of a phandle to a sleep controller, followed by a
2553controller-specific sleep specifier of zero or more cells.
2554
2555The semantics of what type of low power modes are possible are defined
2556by the sleep controller. Some examples of the types of low power modes
2557that may be supported are:
2558
2559 - Dynamic: The device may be disabled or enabled at any time.
2560 - System Suspend: The device may request to be disabled or remain
2561 awake during system suspend, but will not be disabled until then.
2562 - Permanent: The device is disabled permanently (until the next hard
2563 reset).
2564
2565Some devices may share a clock domain with each other, such that they should
2566only be suspended when none of the devices are in use. Where reasonable,
2567such nodes should be placed on a virtual bus, where the bus has the sleep
2568property. If the clock domain is shared among devices that cannot be
2569reasonably grouped in this manner, then create a virtual sleep controller
2570(similar to an interrupt nexus, except that defining a standardized
2571sleep-map should wait until its necessity is demonstrated).
2572
2540Appendix A - Sample SOC node for MPC8540 2573Appendix A - Sample SOC node for MPC8540
2541======================================== 2574========================================
2542 2575
2543Note that the #address-cells and #size-cells for the SoC node 2576 soc@e0000000 {
2544in this example have been explicitly listed; these are likely
2545not necessary as they are usually the same as the root node.
2546
2547 soc8540@e0000000 {
2548 #address-cells = <1>; 2577 #address-cells = <1>;
2549 #size-cells = <1>; 2578 #size-cells = <1>;
2550 #interrupt-cells = <2>; 2579 compatible = "fsl,mpc8540-ccsr", "simple-bus";
2551 device_type = "soc"; 2580 device_type = "soc";
2552 ranges = <00000000 e0000000 00100000> 2581 ranges = <0x00000000 0xe0000000 0x00100000>
2553 reg = <e0000000 00003000>;
2554 bus-frequency = <0>; 2582 bus-frequency = <0>;
2555 2583 interrupt-parent = <&pic>;
2556 mdio@24520 {
2557 reg = <24520 20>;
2558 device_type = "mdio";
2559 compatible = "gianfar";
2560
2561 ethernet-phy@0 {
2562 linux,phandle = <2452000>
2563 interrupt-parent = <40000>;
2564 interrupts = <35 1>;
2565 reg = <0>;
2566 device_type = "ethernet-phy";
2567 };
2568
2569 ethernet-phy@1 {
2570 linux,phandle = <2452001>
2571 interrupt-parent = <40000>;
2572 interrupts = <35 1>;
2573 reg = <1>;
2574 device_type = "ethernet-phy";
2575 };
2576
2577 ethernet-phy@3 {
2578 linux,phandle = <2452002>
2579 interrupt-parent = <40000>;
2580 interrupts = <35 1>;
2581 reg = <3>;
2582 device_type = "ethernet-phy";
2583 };
2584
2585 };
2586 2584
2587 ethernet@24000 { 2585 ethernet@24000 {
2588 #size-cells = <0>; 2586 #address-cells = <1>;
2587 #size-cells = <1>;
2589 device_type = "network"; 2588 device_type = "network";
2590 model = "TSEC"; 2589 model = "TSEC";
2591 compatible = "gianfar"; 2590 compatible = "gianfar", "simple-bus";
2592 reg = <24000 1000>; 2591 reg = <0x24000 0x1000>;
2593 mac-address = [ 00 E0 0C 00 73 00 ]; 2592 local-mac-address = [ 00 E0 0C 00 73 00 ];
2594 interrupts = <d 3 e 3 12 3>; 2593 interrupts = <29 2 30 2 34 2>;
2595 interrupt-parent = <40000>; 2594 phy-handle = <&phy0>;
2596 phy-handle = <2452000>; 2595 sleep = <&pmc 00000080>;
2596 ranges;
2597
2598 mdio@24520 {
2599 reg = <0x24520 0x20>;
2600 compatible = "fsl,gianfar-mdio";
2601
2602 phy0: ethernet-phy@0 {
2603 interrupts = <5 1>;
2604 reg = <0>;
2605 device_type = "ethernet-phy";
2606 };
2607
2608 phy1: ethernet-phy@1 {
2609 interrupts = <5 1>;
2610 reg = <1>;
2611 device_type = "ethernet-phy";
2612 };
2613
2614 phy3: ethernet-phy@3 {
2615 interrupts = <7 1>;
2616 reg = <3>;
2617 device_type = "ethernet-phy";
2618 };
2619 };
2597 }; 2620 };
2598 2621
2599 ethernet@25000 { 2622 ethernet@25000 {
2600 #address-cells = <1>;
2601 #size-cells = <0>;
2602 device_type = "network"; 2623 device_type = "network";
2603 model = "TSEC"; 2624 model = "TSEC";
2604 compatible = "gianfar"; 2625 compatible = "gianfar";
2605 reg = <25000 1000>; 2626 reg = <0x25000 0x1000>;
2606 mac-address = [ 00 E0 0C 00 73 01 ]; 2627 local-mac-address = [ 00 E0 0C 00 73 01 ];
2607 interrupts = <13 3 14 3 18 3>; 2628 interrupts = <13 2 14 2 18 2>;
2608 interrupt-parent = <40000>; 2629 phy-handle = <&phy1>;
2609 phy-handle = <2452001>; 2630 sleep = <&pmc 00000040>;
2610 }; 2631 };
2611 2632
2612 ethernet@26000 { 2633 ethernet@26000 {
2613 #address-cells = <1>;
2614 #size-cells = <0>;
2615 device_type = "network"; 2634 device_type = "network";
2616 model = "FEC"; 2635 model = "FEC";
2617 compatible = "gianfar"; 2636 compatible = "gianfar";
2618 reg = <26000 1000>; 2637 reg = <0x26000 0x1000>;
2619 mac-address = [ 00 E0 0C 00 73 02 ]; 2638 local-mac-address = [ 00 E0 0C 00 73 02 ];
2620 interrupts = <19 3>; 2639 interrupts = <41 2>;
2621 interrupt-parent = <40000>; 2640 phy-handle = <&phy3>;
2622 phy-handle = <2452002>; 2641 sleep = <&pmc 00000020>;
2623 }; 2642 };
2624 2643
2625 serial@4500 { 2644 serial@4500 {
2626 device_type = "serial"; 2645 #address-cells = <1>;
2627 compatible = "ns16550"; 2646 #size-cells = <1>;
2628 reg = <4500 100>; 2647 compatible = "fsl,mpc8540-duart", "simple-bus";
2629 clock-frequency = <0>; 2648 sleep = <&pmc 00000002>;
2630 interrupts = <1a 3>; 2649 ranges;
2631 interrupt-parent = <40000>; 2650
2651 serial@4500 {
2652 device_type = "serial";
2653 compatible = "ns16550";
2654 reg = <0x4500 0x100>;
2655 clock-frequency = <0>;
2656 interrupts = <42 2>;
2657 };
2658
2659 serial@4600 {
2660 device_type = "serial";
2661 compatible = "ns16550";
2662 reg = <0x4600 0x100>;
2663 clock-frequency = <0>;
2664 interrupts = <42 2>;
2665 };
2632 }; 2666 };
2633 2667
2634 pic@40000 { 2668 pic: pic@40000 {
2635 linux,phandle = <40000>;
2636 interrupt-controller; 2669 interrupt-controller;
2637 #address-cells = <0>; 2670 #address-cells = <0>;
2638 reg = <40000 40000>; 2671 #interrupt-cells = <2>;
2672 reg = <0x40000 0x40000>;
2639 compatible = "chrp,open-pic"; 2673 compatible = "chrp,open-pic";
2640 device_type = "open-pic"; 2674 device_type = "open-pic";
2641 }; 2675 };
2642 2676
2643 i2c@3000 { 2677 i2c@3000 {
2644 interrupt-parent = <40000>; 2678 interrupts = <43 2>;
2645 interrupts = <1b 3>; 2679 reg = <0x3000 0x100>;
2646 reg = <3000 18>;
2647 device_type = "i2c";
2648 compatible = "fsl-i2c"; 2680 compatible = "fsl-i2c";
2649 dfsrr; 2681 dfsrr;
2682 sleep = <&pmc 00000004>;
2650 }; 2683 };
2651 2684
2685 pmc: power@e0070 {
2686 compatible = "fsl,mpc8540-pmc", "fsl,mpc8548-pmc";
2687 reg = <0xe0070 0x20>;
2688 };
2652 }; 2689 };
diff --git a/Documentation/powerpc/dts-bindings/fsl/cpm_qe/gpio.txt b/Documentation/powerpc/dts-bindings/fsl/cpm_qe/gpio.txt
new file mode 100644
index 000000000000..1815dfede1bc
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/fsl/cpm_qe/gpio.txt
@@ -0,0 +1,38 @@
1Every GPIO controller node must have #gpio-cells property defined,
2this information will be used to translate gpio-specifiers.
3
4On CPM1 devices, all ports are using slightly different register layouts.
5Ports A, C and D are 16bit ports and Ports B and E are 32bit ports.
6
7On CPM2 devices, all ports are 32bit ports and use a common register layout.
8
9Required properties:
10- compatible : "fsl,cpm1-pario-bank-a", "fsl,cpm1-pario-bank-b",
11 "fsl,cpm1-pario-bank-c", "fsl,cpm1-pario-bank-d",
12 "fsl,cpm1-pario-bank-e", "fsl,cpm2-pario-bank"
13- #gpio-cells : Should be two. The first cell is the pin number and the
14 second cell is used to specify optional paramters (currently unused).
15- gpio-controller : Marks the port as GPIO controller.
16
17Example of three SOC GPIO banks defined as gpio-controller nodes:
18
19 CPM1_PIO_A: gpio-controller@950 {
20 #gpio-cells = <2>;
21 compatible = "fsl,cpm1-pario-bank-a";
22 reg = <0x950 0x10>;
23 gpio-controller;
24 };
25
26 CPM1_PIO_B: gpio-controller@ab8 {
27 #gpio-cells = <2>;
28 compatible = "fsl,cpm1-pario-bank-b";
29 reg = <0xab8 0x10>;
30 gpio-controller;
31 };
32
33 CPM1_PIO_E: gpio-controller@ac8 {
34 #gpio-cells = <2>;
35 compatible = "fsl,cpm1-pario-bank-e";
36 reg = <0xac8 0x18>;
37 gpio-controller;
38 };
diff --git a/Documentation/powerpc/dts-bindings/fsl/cpm_qe/qe/usb.txt b/Documentation/powerpc/dts-bindings/fsl/cpm_qe/qe/usb.txt
index c8f44d6bcbcf..9ccd5f30405b 100644
--- a/Documentation/powerpc/dts-bindings/fsl/cpm_qe/qe/usb.txt
+++ b/Documentation/powerpc/dts-bindings/fsl/cpm_qe/qe/usb.txt
@@ -1,22 +1,37 @@
1* USB (Universal Serial Bus Controller) 1Freescale QUICC Engine USB Controller
2 2
3Required properties: 3Required properties:
4- compatible : could be "qe_udc" or "fhci-hcd". 4- compatible : should be "fsl,<chip>-qe-usb", "fsl,mpc8323-qe-usb".
5- mode : the could be "host" or "slave". 5- reg : the first two cells should contain usb registers location and
6- reg : Offset and length of the register set for the device 6 length, the next two two cells should contain PRAM location and
7- interrupts : <a b> where a is the interrupt number and b is a 7 length.
8 field that represents an encoding of the sense and level 8- interrupts : should contain USB interrupt.
9 information for the interrupt. This should be encoded based on 9- interrupt-parent : interrupt source phandle.
10 the information in section 2) depending on the type of interrupt 10- fsl,fullspeed-clock : specifies the full speed USB clock source:
11 controller you have. 11 "none": clock source is disabled
12- interrupt-parent : the phandle for the interrupt controller that 12 "brg1" through "brg16": clock source is BRG1-BRG16, respectively
13 services interrupts for this device. 13 "clk1" through "clk24": clock source is CLK1-CLK24, respectively
14- fsl,lowspeed-clock : specifies the low speed USB clock source:
15 "none": clock source is disabled
16 "brg1" through "brg16": clock source is BRG1-BRG16, respectively
17 "clk1" through "clk24": clock source is CLK1-CLK24, respectively
18- hub-power-budget : USB power budget for the root hub, in mA.
19- gpios : should specify GPIOs in this order: USBOE, USBTP, USBTN, USBRP,
20 USBRN, SPEED (optional), and POWER (optional).
14 21
15Example(slave): 22Example:
16 usb@6c0 { 23
17 compatible = "qe_udc"; 24usb@6c0 {
18 reg = <6c0 40>; 25 compatible = "fsl,mpc8360-qe-usb", "fsl,mpc8323-qe-usb";
19 interrupts = <8b 0>; 26 reg = <0x6c0 0x40 0x8b00 0x100>;
20 interrupt-parent = <700>; 27 interrupts = <11>;
21 mode = "slave"; 28 interrupt-parent = <&qeic>;
22 }; 29 fsl,fullspeed-clock = "clk21";
30 gpios = <&qe_pio_b 2 0 /* USBOE */
31 &qe_pio_b 3 0 /* USBTP */
32 &qe_pio_b 8 0 /* USBTN */
33 &qe_pio_b 9 0 /* USBRP */
34 &qe_pio_b 11 0 /* USBRN */
35 &qe_pio_e 20 0 /* SPEED */
36 &qe_pio_e 21 0 /* POWER */>;
37};
diff --git a/Documentation/powerpc/dts-bindings/fsl/mcu-mpc8349emitx.txt b/Documentation/powerpc/dts-bindings/fsl/mcu-mpc8349emitx.txt
new file mode 100644
index 000000000000..0f766333b6eb
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/fsl/mcu-mpc8349emitx.txt
@@ -0,0 +1,17 @@
1Freescale MPC8349E-mITX-compatible Power Management Micro Controller Unit (MCU)
2
3Required properties:
4- compatible : "fsl,<mcu-chip>-<board>", "fsl,mcu-mpc8349emitx".
5- reg : should specify I2C address (0x0a).
6- #gpio-cells : should be 2.
7- gpio-controller : should be present.
8
9Example:
10
11mcu@0a {
12 #gpio-cells = <2>;
13 compatible = "fsl,mc9s08qg8-mpc8349emitx",
14 "fsl,mcu-mpc8349emitx";
15 reg = <0x0a>;
16 gpio-controller;
17};
diff --git a/Documentation/powerpc/dts-bindings/fsl/pmc.txt b/Documentation/powerpc/dts-bindings/fsl/pmc.txt
new file mode 100644
index 000000000000..02f6f43ee1b7
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/fsl/pmc.txt
@@ -0,0 +1,63 @@
1* Power Management Controller
2
3Properties:
4- compatible: "fsl,<chip>-pmc".
5
6 "fsl,mpc8349-pmc" should be listed for any chip whose PMC is
7 compatible. "fsl,mpc8313-pmc" should also be listed for any chip
8 whose PMC is compatible, and implies deep-sleep capability.
9
10 "fsl,mpc8548-pmc" should be listed for any chip whose PMC is
11 compatible. "fsl,mpc8536-pmc" should also be listed for any chip
12 whose PMC is compatible, and implies deep-sleep capability.
13
14 "fsl,mpc8641d-pmc" should be listed for any chip whose PMC is
15 compatible; all statements below that apply to "fsl,mpc8548-pmc" also
16 apply to "fsl,mpc8641d-pmc".
17
18 Compatibility does not include bit assigments in SCCR/PMCDR/DEVDISR; these
19 bit assigments are indicated via the sleep specifier in each device's
20 sleep property.
21
22- reg: For devices compatible with "fsl,mpc8349-pmc", the first resource
23 is the PMC block, and the second resource is the Clock Configuration
24 block.
25
26 For devices compatible with "fsl,mpc8548-pmc", the first resource
27 is a 32-byte block beginning with DEVDISR.
28
29- interrupts: For "fsl,mpc8349-pmc"-compatible devices, the first
30 resource is the PMC block interrupt.
31
32- fsl,mpc8313-wakeup-timer: For "fsl,mpc8313-pmc"-compatible devices,
33 this is a phandle to an "fsl,gtm" node on which timer 4 can be used as
34 a wakeup source from deep sleep.
35
36Sleep specifiers:
37
38 fsl,mpc8349-pmc: Sleep specifiers consist of one cell. For each bit
39 that is set in the cell, the corresponding bit in SCCR will be saved
40 and cleared on suspend, and restored on resume. This sleep controller
41 supports disabling and resuming devices at any time.
42
43 fsl,mpc8536-pmc: Sleep specifiers consist of three cells, the third of
44 which will be ORed into PMCDR upon suspend, and cleared from PMCDR
45 upon resume. The first two cells are as described for fsl,mpc8578-pmc.
46 This sleep controller only supports disabling devices during system
47 sleep, or permanently.
48
49 fsl,mpc8548-pmc: Sleep specifiers consist of one or two cells, the
50 first of which will be ORed into DEVDISR (and the second into
51 DEVDISR2, if present -- this cell should be zero or absent if the
52 hardware does not have DEVDISR2) upon a request for permanent device
53 disabling. This sleep controller does not support configuring devices
54 to disable during system sleep (unless supported by another compatible
55 match), or dynamically.
56
57Example:
58
59 power@b00 {
60 compatible = "fsl,mpc8313-pmc", "fsl,mpc8349-pmc";
61 reg = <0xb00 0x100 0xa00 0x100>;
62 interrupts = <80 8>;
63 };
diff --git a/Documentation/powerpc/dts-bindings/fsl/tsec.txt b/Documentation/powerpc/dts-bindings/fsl/tsec.txt
index 583ef6b56c43..cf55fa4112d2 100644
--- a/Documentation/powerpc/dts-bindings/fsl/tsec.txt
+++ b/Documentation/powerpc/dts-bindings/fsl/tsec.txt
@@ -24,46 +24,39 @@ Example:
24 24
25* Gianfar-compatible ethernet nodes 25* Gianfar-compatible ethernet nodes
26 26
27Required properties: 27Properties:
28 28
29 - device_type : Should be "network" 29 - device_type : Should be "network"
30 - model : Model of the device. Can be "TSEC", "eTSEC", or "FEC" 30 - model : Model of the device. Can be "TSEC", "eTSEC", or "FEC"
31 - compatible : Should be "gianfar" 31 - compatible : Should be "gianfar"
32 - reg : Offset and length of the register set for the device 32 - reg : Offset and length of the register set for the device
33 - mac-address : List of bytes representing the ethernet address of 33 - local-mac-address : List of bytes representing the ethernet address of
34 this controller 34 this controller
35 - interrupts : <a b> where a is the interrupt number and b is a 35 - interrupts : For FEC devices, the first interrupt is the device's
36 field that represents an encoding of the sense and level 36 interrupt. For TSEC and eTSEC devices, the first interrupt is
37 information for the interrupt. This should be encoded based on 37 transmit, the second is receive, and the third is error.
38 the information in section 2) depending on the type of interrupt
39 controller you have.
40 - interrupt-parent : the phandle for the interrupt controller that
41 services interrupts for this device.
42 - phy-handle : The phandle for the PHY connected to this ethernet 38 - phy-handle : The phandle for the PHY connected to this ethernet
43 controller. 39 controller.
44 - fixed-link : <a b c d e> where a is emulated phy id - choose any, 40 - fixed-link : <a b c d e> where a is emulated phy id - choose any,
45 but unique to the all specified fixed-links, b is duplex - 0 half, 41 but unique to the all specified fixed-links, b is duplex - 0 half,
46 1 full, c is link speed - d#10/d#100/d#1000, d is pause - 0 no 42 1 full, c is link speed - d#10/d#100/d#1000, d is pause - 0 no
47 pause, 1 pause, e is asym_pause - 0 no asym_pause, 1 asym_pause. 43 pause, 1 pause, e is asym_pause - 0 no asym_pause, 1 asym_pause.
48
49Recommended properties:
50
51 - phy-connection-type : a string naming the controller/PHY interface type, 44 - phy-connection-type : a string naming the controller/PHY interface type,
52 i.e., "mii" (default), "rmii", "gmii", "rgmii", "rgmii-id", "sgmii", 45 i.e., "mii" (default), "rmii", "gmii", "rgmii", "rgmii-id", "sgmii",
53 "tbi", or "rtbi". This property is only really needed if the connection 46 "tbi", or "rtbi". This property is only really needed if the connection
54 is of type "rgmii-id", as all other connection types are detected by 47 is of type "rgmii-id", as all other connection types are detected by
55 hardware. 48 hardware.
56 49 - fsl,magic-packet : If present, indicates that the hardware supports
50 waking up via magic packet.
57 51
58Example: 52Example:
59 ethernet@24000 { 53 ethernet@24000 {
60 #size-cells = <0>;
61 device_type = "network"; 54 device_type = "network";
62 model = "TSEC"; 55 model = "TSEC";
63 compatible = "gianfar"; 56 compatible = "gianfar";
64 reg = <24000 1000>; 57 reg = <0x24000 0x1000>;
65 mac-address = [ 00 E0 0C 00 73 00 ]; 58 local-mac-address = [ 00 E0 0C 00 73 00 ];
66 interrupts = <d 3 e 3 12 3>; 59 interrupts = <29 2 30 2 34 2>;
67 interrupt-parent = <40000>; 60 interrupt-parent = <&mpic>;
68 phy-handle = <2452000> 61 phy-handle = <&phy0>
69 }; 62 };
diff --git a/Documentation/powerpc/dts-bindings/fsl/upm-nand.txt b/Documentation/powerpc/dts-bindings/fsl/upm-nand.txt
new file mode 100644
index 000000000000..84a04d5eb8e6
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/fsl/upm-nand.txt
@@ -0,0 +1,28 @@
1Freescale Localbus UPM programmed to work with NAND flash
2
3Required properties:
4- compatible : "fsl,upm-nand".
5- reg : should specify localbus chip select and size used for the chip.
6- fsl,upm-addr-offset : UPM pattern offset for the address latch.
7- fsl,upm-cmd-offset : UPM pattern offset for the command latch.
8- gpios : may specify optional GPIO connected to the Ready-Not-Busy pin.
9
10Example:
11
12upm@1,0 {
13 compatible = "fsl,upm-nand";
14 reg = <1 0 1>;
15 fsl,upm-addr-offset = <16>;
16 fsl,upm-cmd-offset = <8>;
17 gpios = <&qe_pio_e 18 0>;
18
19 flash {
20 #address-cells = <1>;
21 #size-cells = <1>;
22 compatible = "...";
23
24 partition@0 {
25 ...
26 };
27 };
28};
diff --git a/Documentation/powerpc/dts-bindings/gpio/led.txt b/Documentation/powerpc/dts-bindings/gpio/led.txt
new file mode 100644
index 000000000000..ff51f4c0fa9d
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/gpio/led.txt
@@ -0,0 +1,15 @@
1LED connected to GPIO
2
3Required properties:
4- compatible : should be "gpio-led".
5- label : (optional) the label for this LED. If omitted, the label is
6 taken from the node name (excluding the unit address).
7- gpios : should specify LED GPIO.
8
9Example:
10
11led@0 {
12 compatible = "gpio-led";
13 label = "hdd";
14 gpios = <&mcu_pio 0 1>;
15};
diff --git a/Documentation/sound/alsa/DocBook/alsa-driver-api.tmpl b/Documentation/sound/alsa/DocBook/alsa-driver-api.tmpl
index c4d2e3507af9..9d644f7e241e 100644
--- a/Documentation/sound/alsa/DocBook/alsa-driver-api.tmpl
+++ b/Documentation/sound/alsa/DocBook/alsa-driver-api.tmpl
@@ -42,7 +42,7 @@
42 <sect1><title>Device Components</title> 42 <sect1><title>Device Components</title>
43!Esound/core/device.c 43!Esound/core/device.c
44 </sect1> 44 </sect1>
45 <sect1><title>KMOD and Device File Entries</title> 45 <sect1><title>Module requests and Device File Entries</title>
46!Esound/core/sound.c 46!Esound/core/sound.c
47 </sect1> 47 </sect1>
48 <sect1><title>Memory Management Helpers</title> 48 <sect1><title>Memory Management Helpers</title>
diff --git a/Documentation/specialix.txt b/Documentation/specialix.txt
index 4a4b428ce8f6..6eb6f3a3331c 100644
--- a/Documentation/specialix.txt
+++ b/Documentation/specialix.txt
@@ -270,8 +270,8 @@ The pinout of the connectors on the IO8+ is:
270Hardware handshaking issues. 270Hardware handshaking issues.
271============================ 271============================
272 272
273The driver can be compiled in two different ways. The default 273The driver can be told to operate in two different ways. The default
274("Specialix DTR/RTS pin is RTS" is off) the pin behaves as DTR when 274behaviour is specialix.sx_rtscts = 0 where the pin behaves as DTR when
275hardware handshaking is off. It behaves as the RTS hardware 275hardware handshaking is off. It behaves as the RTS hardware
276handshaking signal when hardware handshaking is selected. 276handshaking signal when hardware handshaking is selected.
277 277
@@ -280,7 +280,7 @@ cable will either be compatible with hardware handshaking or with
280software handshaking. So switching on the fly is not really an 280software handshaking. So switching on the fly is not really an
281option. 281option.
282 282
283I actually prefer to use the "Specialix DTR/RTS pin is RTS" option. 283I actually prefer to use the "specialix.sx_rtscts=1" option.
284This makes the DTR/RTS pin always an RTS pin, and ioctls to 284This makes the DTR/RTS pin always an RTS pin, and ioctls to
285change DTR are always ignored. I have a cable that is configured 285change DTR are always ignored. I have a cable that is configured
286for this. 286for this.
@@ -379,7 +379,5 @@ it doesn't fit in your computer, bring back the card.
379 You have to WRITE to the address register to even 379 You have to WRITE to the address register to even
380 read-probe a CD186x register. Disable autodetection? 380 read-probe a CD186x register. Disable autodetection?
381 -- Specialix: any suggestions? 381 -- Specialix: any suggestions?
382 - Arbitrary baud rates are not implemented yet.
383 If you need this, bug me about it.
384 382
385 383
diff --git a/Documentation/sysfs-rules.txt b/Documentation/sysfs-rules.txt
index 80ef562160bb..6049a2a84dda 100644
--- a/Documentation/sysfs-rules.txt
+++ b/Documentation/sysfs-rules.txt
@@ -3,9 +3,8 @@ Rules on how to access information in the Linux kernel sysfs
3The kernel-exported sysfs exports internal kernel implementation details 3The kernel-exported sysfs exports internal kernel implementation details
4and depends on internal kernel structures and layout. It is agreed upon 4and depends on internal kernel structures and layout. It is agreed upon
5by the kernel developers that the Linux kernel does not provide a stable 5by the kernel developers that the Linux kernel does not provide a stable
6internal API. As sysfs is a direct export of kernel internal 6internal API. Therefore, there are aspects of the sysfs interface that
7structures, the sysfs interface cannot provide a stable interface either; 7may not be stable across kernel releases.
8it may always change along with internal kernel changes.
9 8
10To minimize the risk of breaking users of sysfs, which are in most cases 9To minimize the risk of breaking users of sysfs, which are in most cases
11low-level userspace applications, with a new kernel release, the users 10low-level userspace applications, with a new kernel release, the users
diff --git a/Documentation/telephony/ixj.txt b/Documentation/telephony/ixj.txt
index 621024fd3a18..44d124005bad 100644
--- a/Documentation/telephony/ixj.txt
+++ b/Documentation/telephony/ixj.txt
@@ -305,21 +305,14 @@ driver, like this:
305 305
306which will result in the needed drivers getting loaded automatically. 306which will result in the needed drivers getting loaded automatically.
307 307
308 g. if you are planning on using kerneld to automatically load the 308 g. if you are planning on having the kernel automatically request
309module for you, then you need to edit /etc/conf.modules and add the 309the module for you, then you need to edit /etc/conf.modules and add the
310following lines: 310following lines:
311 311
312 options ixj dspio=0x340 xio=0x330 ixjdebug=0 312 options ixj dspio=0x340 xio=0x330 ixjdebug=0
313 313
314If you do this, then when you execute an application that uses the 314If you do this, then when you execute an application that uses the
315module kerneld will load the module for you. Note that to do this, 315module the kernel will request that it is loaded.
316you need to have your kernel set to support kerneld. You can check
317for this by looking at /usr/src/linux/.config and you should see this:
318
319 # Loadable module support
320 #
321 <snip>
322 CONFIG_KMOD=y
323 316
324 h. if you want non-root users to be able to read and write to the 317 h. if you want non-root users to be able to read and write to the
325ixj devices (this is a good idea!) you should do the following: 318ixj devices (this is a good idea!) you should do the following:
diff --git a/Documentation/usb/gadget_serial.txt b/Documentation/usb/gadget_serial.txt
index 815f5c2301ff..9b22bd14c348 100644
--- a/Documentation/usb/gadget_serial.txt
+++ b/Documentation/usb/gadget_serial.txt
@@ -1,6 +1,7 @@
1 1
2 Linux Gadget Serial Driver v2.0 2 Linux Gadget Serial Driver v2.0
3 11/20/2004 3 11/20/2004
4 (updated 8-May-2008 for v2.3)
4 5
5 6
6License and Disclaimer 7License and Disclaimer
@@ -31,7 +32,7 @@ Prerequisites
31------------- 32-------------
32Versions of the gadget serial driver are available for the 33Versions of the gadget serial driver are available for the
332.4 Linux kernels, but this document assumes you are using 342.4 Linux kernels, but this document assumes you are using
34version 2.0 or later of the gadget serial driver in a 2.6 35version 2.3 or later of the gadget serial driver in a 2.6
35Linux kernel. 36Linux kernel.
36 37
37This document assumes that you are familiar with Linux and 38This document assumes that you are familiar with Linux and
@@ -40,6 +41,12 @@ standard utilities, use minicom and HyperTerminal, and work with
40USB and serial devices. It also assumes you configure the Linux 41USB and serial devices. It also assumes you configure the Linux
41gadget and usb drivers as modules. 42gadget and usb drivers as modules.
42 43
44With version 2.3 of the driver, major and minor device nodes are
45no longer statically defined. Your Linux based system should mount
46sysfs in /sys, and use "mdev" (in Busybox) or "udev" to make the
47/dev nodes matching the sysfs /sys/class/tty files.
48
49
43 50
44Overview 51Overview
45-------- 52--------
@@ -104,15 +111,8 @@ driver. All this are listed under "USB Gadget Support" when
104configuring the kernel. Then rebuild and install the kernel or 111configuring the kernel. Then rebuild and install the kernel or
105modules. 112modules.
106 113
107The gadget serial driver uses major number 127, for now. So you
108will need to create a device node for it, like this:
109
110 mknod /dev/ttygserial c 127 0
111
112You only need to do this once.
113
114Then you must load the gadget serial driver. To load it as an 114Then you must load the gadget serial driver. To load it as an
115ACM device, do this: 115ACM device (recommended for interoperability), do this:
116 116
117 modprobe g_serial use_acm=1 117 modprobe g_serial use_acm=1
118 118
@@ -125,6 +125,23 @@ controller driver. This must be done each time you reboot the gadget
125side Linux system. You can add this to the start up scripts, if 125side Linux system. You can add this to the start up scripts, if
126desired. 126desired.
127 127
128Your system should use mdev (from busybox) or udev to make the
129device nodes. After this gadget driver has been set up you should
130then see a /dev/ttyGS0 node:
131
132 # ls -l /dev/ttyGS0 | cat
133 crw-rw---- 1 root root 253, 0 May 8 14:10 /dev/ttyGS0
134 #
135
136Note that the major number (253, above) is system-specific. If
137you need to create /dev nodes by hand, the right numbers to use
138will be in the /sys/class/tty/ttyGS0/dev file.
139
140When you link this gadget driver early, perhaps even statically,
141you may want to set up an /etc/inittab entry to run "getty" on it.
142The /dev/ttyGS0 line should work like most any other serial port.
143
144
128If gadget serial is loaded as an ACM device you will want to use 145If gadget serial is loaded as an ACM device you will want to use
129either the Windows or Linux ACM driver on the host side. If gadget 146either the Windows or Linux ACM driver on the host side. If gadget
130serial is loaded as a bulk in/out device, you will want to use the 147serial is loaded as a bulk in/out device, you will want to use the
diff --git a/Documentation/usb/persist.txt b/Documentation/usb/persist.txt
index d56cb1a11550..074b159b77c2 100644
--- a/Documentation/usb/persist.txt
+++ b/Documentation/usb/persist.txt
@@ -81,8 +81,11 @@ re-enumeration shows that the device now attached to that port has the
81same descriptors as before, including the Vendor and Product IDs, then 81same descriptors as before, including the Vendor and Product IDs, then
82the kernel continues to use the same device structure. In effect, the 82the kernel continues to use the same device structure. In effect, the
83kernel treats the device as though it had merely been reset instead of 83kernel treats the device as though it had merely been reset instead of
84unplugged. The same thing happens if the host controller is in the 84unplugged.
85expected state but a USB device was unplugged and then replugged. 85
86The same thing happens if the host controller is in the expected state
87but a USB device was unplugged and then replugged, or if a USB device
88fails to carry out a normal resume.
86 89
87If no device is now attached to the port, or if the descriptors are 90If no device is now attached to the port, or if the descriptors are
88different from what the kernel remembers, then the treatment is what 91different from what the kernel remembers, then the treatment is what
diff --git a/Documentation/usb/uhci.txt b/Documentation/usb/uhci.txt
deleted file mode 100644
index 2f25952c86c6..000000000000
--- a/Documentation/usb/uhci.txt
+++ /dev/null
@@ -1,165 +0,0 @@
1Specification and Internals for the New UHCI Driver (Whitepaper...)
2
3 brought to you by
4
5 Georg Acher, acher@in.tum.de (executive slave) (base guitar)
6 Deti Fliegl, deti@fliegl.de (executive slave) (lead voice)
7 Thomas Sailer, sailer@ife.ee.ethz.ch (chief consultant) (cheer leader)
8
9 $Id: README.uhci,v 1.1 1999/12/14 14:03:02 fliegl Exp $
10
11This document and the new uhci sources can be found on
12 http://hotswap.in.tum.de/usb
13
141. General issues
15
161.1 Why a new UHCI driver, we already have one?!?
17
18Correct, but its internal structure got more and more mixed up by the (still
19ongoing) efforts to get isochronous transfers (ISO) to work.
20Since there is an increasing need for reliable ISO-transfers (especially
21for USB-audio needed by TS and for a DAB-USB-Receiver build by GA and DF),
22this state was a bit unsatisfying in our opinion, so we've decided (based
23on knowledge and experiences with the old UHCI driver) to start
24from scratch with a new approach, much simpler but at the same time more
25powerful.
26It is inspired by the way Win98/Win2000 handles USB requests via URBs,
27but it's definitely 100% free of MS-code and doesn't crash while
28unplugging an used ISO-device like Win98 ;-)
29Some code for HW setup and root hub management was taken from the
30original UHCI driver, but heavily modified to fit into the new code.
31The invention of the basic concept, and major coding were completed in two
32days (and nights) on the 16th and 17th of October 1999, now known as the
33great USB-October-Revolution started by GA, DF, and TS ;-)
34
35Since the concept is in no way UHCI dependent, we hope that it will also be
36transferred to the OHCI-driver, so both drivers share a common API.
37
381.2. Advantages and disadvantages
39
40+ All USB transfer types work now!
41+ Asynchronous operation
42+ Simple, but powerful interface (only two calls for start and cancel)
43+ Easy migration to the new API, simplified by a compatibility API
44+ Simple usage of ISO transfers
45+ Automatic linking of requests
46+ ISO transfers allow variable length for each frame and striping
47+ No CPU dependent and non-portable atomic memory access, no asm()-inlines
48+ Tested on x86 and Alpha
49
50- Rewriting for ISO transfers needed
51
521.3. Is there some compatibility to the old API?
53
54Yes, but only for control, bulk and interrupt transfers. We've implemented
55some wrapper calls for these transfer types. The usbcore works fine with
56these wrappers. For ISO there's no compatibility, because the old ISO-API
57and its semantics were unnecessary complicated in our opinion.
58
591.4. What's really working?
60
61As said above, CTRL and BULK already work fine even with the wrappers,
62so legacy code wouldn't notice the change.
63Regarding to Thomas, ISO transfers now run stable with USB audio.
64INT transfers (e.g. mouse driver) work fine, too.
65
661.5. Are there any bugs?
67
68No ;-)
69Hm...
70Well, of course this implementation needs extensive testing on all available
71hardware, but we believe that any fixes shouldn't harm the overall concept.
72
731.6. What should be done next?
74
75A large part of the request handling seems to be identical for UHCI and
76OHCI, so it would be a good idea to extract the common parts and have only
77the HW specific stuff in uhci.c. Furthermore, all other USB device drivers
78should need URBification, if they use isochronous or interrupt transfers.
79One thing missing in the current implementation (and the old UHCI driver)
80is fair queueing for BULK transfers. Since this would need (in principle)
81the alteration of already constructed TD chains (to switch from depth to
82breadth execution), another way has to be found. Maybe some simple
83heuristics work with the same effect.
84
85---------------------------------------------------------------------------
86
872. Internal structure and mechanisms
88
89To get quickly familiar with the internal structures, here's a short
90description how the new UHCI driver works. However, the ultimate source of
91truth is only uhci.c!
92
932.1. Descriptor structure (QHs and TDs)
94
95During initialization, the following skeleton is allocated in init_skel:
96
97 framespecific | common chain
98
99framelist[]
100[ 0 ]-----> TD --> TD -------\
101[ 1 ]-----> TD --> TD --------> TD ----> QH -------> QH -------> QH ---> NULL
102 ... TD --> TD -------/
103[1023]-----> TD --> TD ------/
104
105 ^^ ^^ ^^ ^^ ^^ ^^
106 1024 TDs for 7 TDs for 1 TD for Start of Start of End Chain
107 ISO INT (2-128ms) 1ms-INT CTRL Chain BULK Chain
108
109For each CTRL or BULK transfer a new QH is allocated and the containing data
110transfers are appended as (vertical) TDs. After building the whole QH with its
111dangling TDs, the QH is inserted before the BULK Chain QH (for CTRL) or
112before the End Chain QH (for BULK). Since only the QH->next pointers are
113affected, no atomic memory operation is required. The three QHs in the
114common chain are never equipped with TDs!
115
116For ISO or INT, the TD for each frame is simply inserted into the appropriate
117ISO/INT-TD-chain for the desired frame. The 7 skeleton INT-TDs are scattered
118among the 1024 frames similar to the old UHCI driver.
119
120For CTRL/BULK/ISO, the last TD in the transfer has the IOC-bit set. For INT,
121every TD (there is only one...) has the IOC-bit set.
122
123Besides the data for the UHCI controller (2 or 4 32bit words), the descriptors
124are double-linked through the .vertical and .horizontal elements in the
125SW data of the descriptor (using the double-linked list structures and
126operations), but SW-linking occurs only in closed domains, i.e. for each of
127the 1024 ISO-chains and the 8 INT-chains there is a closed cycle. This
128simplifies all insertions and unlinking operations and avoids costly
129bus_to_virt()-calls.
130
1312.2. URB structure and linking to QH/TDs
132
133During assembly of the QH and TDs of the requested action, these descriptors
134are stored in urb->urb_list, so the allocated QH/TD descriptors are bound to
135this URB.
136If the assembly was successful and the descriptors were added to the HW chain,
137the corresponding URB is inserted into a global URB list for this controller.
138This list stores all pending URBs.
139
1402.3. Interrupt processing
141
142Since UHCI provides no means to directly detect completed transactions, the
143following is done in each UHCI interrupt (uhci_interrupt()):
144
145For each URB in the pending queue (process_urb()), the ACTIVE-flag of the
146associated TDs are processed (depending on the transfer type
147process_{transfer|interrupt|iso}()). If the TDs are not active anymore,
148they indicate the completion of the transaction and the status is calculated.
149Inactive QH/TDs are removed from the HW chain (since the host controller
150already removed the TDs from the QH, no atomic access is needed) and
151eventually the URB is marked as completed (OK or errors) and removed from the
152pending queue. Then the next linked URB is submitted. After (or immediately
153before) that, the completion handler is called.
154
1552.4. Unlinking URBs
156
157First, all QH/TDs stored in the URB are unlinked from the HW chain.
158To ensure that the host controller really left a vertical TD chain, we
159wait for one frame. After that, the TDs are physically destroyed.
160
1612.5. URB linking and the consequences
162
163Since URBs can be linked and the corresponding submit_urb is called in
164the UHCI-interrupt, all work associated with URB/QH/TD assembly has to be
165interrupt save. This forces kmalloc to use GFP_ATOMIC in the interrupt.
diff --git a/Documentation/video4linux/w9968cf.txt b/Documentation/video4linux/w9968cf.txt
index e0bba8393c77..05138e8aea07 100644
--- a/Documentation/video4linux/w9968cf.txt
+++ b/Documentation/video4linux/w9968cf.txt
@@ -193,9 +193,6 @@ Description: Automatic 'ovcamchip' module loading: 0 disabled, 1 enabled.
193 loads that module automatically. This action is performed as 193 loads that module automatically. This action is performed as
194 once soon as the 'w9968cf' module is loaded into memory. 194 once soon as the 'w9968cf' module is loaded into memory.
195Default: 1 195Default: 1
196Note: The kernel must be compiled with the CONFIG_KMOD option
197 enabled for the 'ovcamchip' module to be loaded and for
198 this parameter to be present.
199------------------------------------------------------------------------------- 196-------------------------------------------------------------------------------
200Name: simcams 197Name: simcams
201Type: int 198Type: int
diff --git a/MAINTAINERS b/MAINTAINERS
index ec0c9c914f17..11944b44c2ff 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1988,6 +1988,12 @@ M: mikulas@artax.karlin.mff.cuni.cz
1988W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi 1988W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi
1989S: Maintained 1989S: Maintained
1990 1990
1991HTCPEN TOUCHSCREEN DRIVER
1992P: Pau Oliva Fora
1993M: pof@eslack.org
1994L: linux-input@vger.kernel.org
1995S: Maintained
1996
1991HUGETLB FILESYSTEM 1997HUGETLB FILESYSTEM
1992P: William Irwin 1998P: William Irwin
1993M: wli@holomorphy.com 1999M: wli@holomorphy.com
@@ -4041,9 +4047,10 @@ W: http://www.buzzard.org.uk/toshiba/
4041S: Maintained 4047S: Maintained
4042 4048
4043TPM DEVICE DRIVER 4049TPM DEVICE DRIVER
4044P: Debora Velarde 4050P: Debora Velarde
4045P: Rajiv Andrade 4051M: debora@linux.vnet.ibm.com
4046M: tpmdd-devel@lists.sourceforge.net 4052P: Rajiv Andrade
4053M: srajiv@linux.vnet.ibm.com
4047W: http://tpmdd.sourceforge.net 4054W: http://tpmdd.sourceforge.net
4048P: Marcel Selhorst 4055P: Marcel Selhorst
4049M: tpm@selhorst.net 4056M: tpm@selhorst.net
diff --git a/Makefile b/Makefile
index 6192922de9c0..4bcd1cf90cb1 100644
--- a/Makefile
+++ b/Makefile
@@ -1148,7 +1148,8 @@ clean: archclean $(clean-dirs)
1148 @find . $(RCS_FIND_IGNORE) \ 1148 @find . $(RCS_FIND_IGNORE) \
1149 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ 1149 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
1150 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ 1150 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
1151 -o -name '*.symtypes' -o -name 'modules.order' \) \ 1151 -o -name '*.symtypes' -o -name 'modules.order' \
1152 -o -name 'Module.markers' \) \
1152 -type f -print | xargs rm -f 1153 -type f -print | xargs rm -f
1153 1154
1154# mrproper - Delete all generated files, including .config 1155# mrproper - Delete all generated files, including .config
diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c
index 2744673314b4..dd2947342604 100644
--- a/arch/arm/common/dmabounce.c
+++ b/arch/arm/common/dmabounce.c
@@ -554,9 +554,8 @@ dmabounce_register_dev(struct device *dev, unsigned long small_buffer_size,
554 554
555 device_info = kmalloc(sizeof(struct dmabounce_device_info), GFP_ATOMIC); 555 device_info = kmalloc(sizeof(struct dmabounce_device_info), GFP_ATOMIC);
556 if (!device_info) { 556 if (!device_info) {
557 printk(KERN_ERR 557 dev_err(dev,
558 "Could not allocated dmabounce_device_info for %s", 558 "Could not allocated dmabounce_device_info\n");
559 dev->bus_id);
560 return -ENOMEM; 559 return -ENOMEM;
561 } 560 }
562 561
@@ -594,8 +593,7 @@ dmabounce_register_dev(struct device *dev, unsigned long small_buffer_size,
594 593
595 dev->archdata.dmabounce = device_info; 594 dev->archdata.dmabounce = device_info;
596 595
597 printk(KERN_INFO "dmabounce: registered device %s on %s bus\n", 596 dev_info(dev, "dmabounce: registered device\n");
598 dev->bus_id, dev->bus->name);
599 597
600 return 0; 598 return 0;
601 599
@@ -614,16 +612,15 @@ dmabounce_unregister_dev(struct device *dev)
614 dev->archdata.dmabounce = NULL; 612 dev->archdata.dmabounce = NULL;
615 613
616 if (!device_info) { 614 if (!device_info) {
617 printk(KERN_WARNING 615 dev_warn(dev,
618 "%s: Never registered with dmabounce but attempting" \ 616 "Never registered with dmabounce but attempting"
619 "to unregister!\n", dev->bus_id); 617 "to unregister!\n");
620 return; 618 return;
621 } 619 }
622 620
623 if (!list_empty(&device_info->safe_buffers)) { 621 if (!list_empty(&device_info->safe_buffers)) {
624 printk(KERN_ERR 622 dev_err(dev,
625 "%s: Removing from dmabounce with pending buffers!\n", 623 "Removing from dmabounce with pending buffers!\n");
626 dev->bus_id);
627 BUG(); 624 BUG();
628 } 625 }
629 626
@@ -639,8 +636,7 @@ dmabounce_unregister_dev(struct device *dev)
639 636
640 kfree(device_info); 637 kfree(device_info);
641 638
642 printk(KERN_INFO "dmabounce: device %s on %s bus unregistered\n", 639 dev_info(dev, "dmabounce: device unregistered\n");
643 dev->bus_id, dev->bus->name);
644} 640}
645 641
646 642
diff --git a/arch/arm/common/locomo.c b/arch/arm/common/locomo.c
index d973c986f721..c3c3a3339049 100644
--- a/arch/arm/common/locomo.c
+++ b/arch/arm/common/locomo.c
@@ -543,7 +543,6 @@ locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
543 goto out; 543 goto out;
544 } 544 }
545 545
546 strncpy(dev->dev.bus_id, info->name, sizeof(dev->dev.bus_id));
547 /* 546 /*
548 * If the parent device has a DMA mask associated with it, 547 * If the parent device has a DMA mask associated with it,
549 * propagate it down to the children. 548 * propagate it down to the children.
@@ -553,6 +552,7 @@ locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
553 dev->dev.dma_mask = &dev->dma_mask; 552 dev->dev.dma_mask = &dev->dma_mask;
554 } 553 }
555 554
555 dev_set_name(&dev->dev, "%s", info->name);
556 dev->devid = info->devid; 556 dev->devid = info->devid;
557 dev->dev.parent = lchip->dev; 557 dev->dev.parent = lchip->dev;
558 dev->dev.bus = &locomo_bus_type; 558 dev->dev.bus = &locomo_bus_type;
diff --git a/arch/arm/common/sa1111.c b/arch/arm/common/sa1111.c
index eb06d0b2cb74..c8e8f0ea59e1 100644
--- a/arch/arm/common/sa1111.c
+++ b/arch/arm/common/sa1111.c
@@ -550,9 +550,7 @@ sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent,
550 goto out; 550 goto out;
551 } 551 }
552 552
553 snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id), 553 dev_set_name(&dev->dev, "%4.4lx", info->offset);
554 "%4.4lx", info->offset);
555
556 dev->devid = info->devid; 554 dev->devid = info->devid;
557 dev->dev.parent = sachip->dev; 555 dev->dev.parent = sachip->dev;
558 dev->dev.bus = &sa1111_bus_type; 556 dev->dev.bus = &sa1111_bus_type;
@@ -560,7 +558,7 @@ sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent,
560 dev->dev.coherent_dma_mask = sachip->dev->coherent_dma_mask; 558 dev->dev.coherent_dma_mask = sachip->dev->coherent_dma_mask;
561 dev->res.start = sachip->phys + info->offset; 559 dev->res.start = sachip->phys + info->offset;
562 dev->res.end = dev->res.start + 511; 560 dev->res.end = dev->res.start + 511;
563 dev->res.name = dev->dev.bus_id; 561 dev->res.name = dev_name(&dev->dev);
564 dev->res.flags = IORESOURCE_MEM; 562 dev->res.flags = IORESOURCE_MEM;
565 dev->mapbase = sachip->base + info->offset; 563 dev->mapbase = sachip->base + info->offset;
566 dev->skpcr_mask = info->skpcr_mask; 564 dev->skpcr_mask = info->skpcr_mask;
@@ -570,6 +568,7 @@ sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent,
570 if (ret) { 568 if (ret) {
571 printk("SA1111: failed to allocate resource for %s\n", 569 printk("SA1111: failed to allocate resource for %s\n",
572 dev->res.name); 570 dev->res.name);
571 dev_set_name(&dev->dev, NULL);
573 kfree(dev); 572 kfree(dev);
574 goto out; 573 goto out;
575 } 574 }
@@ -593,7 +592,8 @@ sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent,
593 if (dev->dma_mask != 0xffffffffUL) { 592 if (dev->dma_mask != 0xffffffffUL) {
594 ret = dmabounce_register_dev(&dev->dev, 1024, 4096); 593 ret = dmabounce_register_dev(&dev->dev, 1024, 4096);
595 if (ret) { 594 if (ret) {
596 printk("SA1111: Failed to register %s with dmabounce", dev->dev.bus_id); 595 dev_err(&dev->dev, "SA1111: Failed to register"
596 " with dmabounce\n");
597 device_unregister(&dev->dev); 597 device_unregister(&dev->dev);
598 } 598 }
599 } 599 }
diff --git a/arch/arm/common/scoop.c b/arch/arm/common/scoop.c
index bc299b07a6fa..ae39553589dd 100644
--- a/arch/arm/common/scoop.c
+++ b/arch/arm/common/scoop.c
@@ -247,7 +247,7 @@ static int __devinit scoop_probe(struct platform_device *pdev)
247 devptr->gpio.base = -1; 247 devptr->gpio.base = -1;
248 248
249 if (inf->gpio_base != 0) { 249 if (inf->gpio_base != 0) {
250 devptr->gpio.label = pdev->dev.bus_id; 250 devptr->gpio.label = dev_name(&pdev->dev);
251 devptr->gpio.base = inf->gpio_base; 251 devptr->gpio.base = inf->gpio_base;
252 devptr->gpio.ngpio = 12; /* PA11 = 0, PA12 = 1, etc. up to PA22 = 11 */ 252 devptr->gpio.ngpio = 12; /* PA11 = 0, PA12 = 1, etc. up to PA22 = 11 */
253 devptr->gpio.set = scoop_gpio_set; 253 devptr->gpio.set = scoop_gpio_set;
diff --git a/arch/arm/kernel/ecard.c b/arch/arm/kernel/ecard.c
index 8bfd299bfe77..f5cfdabcb87d 100644
--- a/arch/arm/kernel/ecard.c
+++ b/arch/arm/kernel/ecard.c
@@ -783,7 +783,7 @@ static void ecard_proc_init(void)
783 783
784#define ec_set_resource(ec,nr,st,sz) \ 784#define ec_set_resource(ec,nr,st,sz) \
785 do { \ 785 do { \
786 (ec)->resource[nr].name = ec->dev.bus_id; \ 786 (ec)->resource[nr].name = dev_name(&ec->dev); \
787 (ec)->resource[nr].start = st; \ 787 (ec)->resource[nr].start = st; \
788 (ec)->resource[nr].end = (st) + (sz) - 1; \ 788 (ec)->resource[nr].end = (st) + (sz) - 1; \
789 (ec)->resource[nr].flags = IORESOURCE_MEM; \ 789 (ec)->resource[nr].flags = IORESOURCE_MEM; \
@@ -853,8 +853,7 @@ static struct expansion_card *__init ecard_alloc_card(int type, int slot)
853 for (i = 0; i < ECARD_NUM_RESOURCES; i++) { 853 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
854 if (ec->resource[i].flags && 854 if (ec->resource[i].flags &&
855 request_resource(&iomem_resource, &ec->resource[i])) { 855 request_resource(&iomem_resource, &ec->resource[i])) {
856 printk(KERN_ERR "%s: resource(s) not available\n", 856 dev_err(&ec->dev, "resource(s) not available\n");
857 ec->dev.bus_id);
858 ec->resource[i].end -= ec->resource[i].start; 857 ec->resource[i].end -= ec->resource[i].start;
859 ec->resource[i].start = 0; 858 ec->resource[i].start = 0;
860 ec->resource[i].flags = 0; 859 ec->resource[i].flags = 0;
diff --git a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c
index cc5145b28e7f..368d171754cf 100644
--- a/arch/arm/kernel/time.c
+++ b/arch/arm/kernel/time.c
@@ -130,7 +130,9 @@ static const struct leds_evt_name evt_names[] = {
130 { "red", led_red_on, led_red_off }, 130 { "red", led_red_on, led_red_off },
131}; 131};
132 132
133static ssize_t leds_store(struct sys_device *dev, const char *buf, size_t size) 133static ssize_t leds_store(struct sys_device *dev,
134 struct sysdev_attribute *attr,
135 const char *buf, size_t size)
134{ 136{
135 int ret = -EINVAL, len = strcspn(buf, " "); 137 int ret = -EINVAL, len = strcspn(buf, " ");
136 138
diff --git a/arch/arm/mach-integrator/impd1.c b/arch/arm/mach-integrator/impd1.c
index 62e653a3ea1a..5a1588cf8242 100644
--- a/arch/arm/mach-integrator/impd1.c
+++ b/arch/arm/mach-integrator/impd1.c
@@ -393,9 +393,7 @@ static int impd1_probe(struct lm_device *dev)
393 if (!d) 393 if (!d)
394 continue; 394 continue;
395 395
396 snprintf(d->dev.bus_id, sizeof(d->dev.bus_id), 396 dev_set_name(&d->dev, "lm%x:%5.5lx", dev->id, idev->offset >> 12);
397 "lm%x:%5.5lx", dev->id, idev->offset >> 12);
398
399 d->dev.parent = &dev->dev; 397 d->dev.parent = &dev->dev;
400 d->res.start = dev->resource.start + idev->offset; 398 d->res.start = dev->resource.start + idev->offset;
401 d->res.end = d->res.start + SZ_4K - 1; 399 d->res.end = d->res.start + SZ_4K - 1;
@@ -407,8 +405,7 @@ static int impd1_probe(struct lm_device *dev)
407 405
408 ret = amba_device_register(d, &dev->resource); 406 ret = amba_device_register(d, &dev->resource);
409 if (ret) { 407 if (ret) {
410 printk("unable to register device %s: %d\n", 408 dev_err(&d->dev, "unable to register device: %d\n");
411 d->dev.bus_id, ret);
412 kfree(d); 409 kfree(d);
413 } 410 }
414 } 411 }
diff --git a/arch/arm/mach-integrator/lm.c b/arch/arm/mach-integrator/lm.c
index 622cdc4212dd..f939c5091405 100644
--- a/arch/arm/mach-integrator/lm.c
+++ b/arch/arm/mach-integrator/lm.c
@@ -81,8 +81,10 @@ int lm_device_register(struct lm_device *dev)
81 dev->dev.release = lm_device_release; 81 dev->dev.release = lm_device_release;
82 dev->dev.bus = &lm_bustype; 82 dev->dev.bus = &lm_bustype;
83 83
84 snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id), "lm%d", dev->id); 84 ret = dev_set_name(&dev->dev, "lm%d", dev->id);
85 dev->resource.name = dev->dev.bus_id; 85 if (ret)
86 return ret;
87 dev->resource.name = dev_name(&dev->dev);
86 88
87 ret = request_resource(&iomem_resource, &dev->resource); 89 ret = request_resource(&iomem_resource, &dev->resource);
88 if (ret == 0) { 90 if (ret == 0) {
diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c
index 6f33f58bca45..ff1413eae0b8 100644
--- a/arch/arm/plat-omap/mailbox.c
+++ b/arch/arm/plat-omap/mailbox.c
@@ -334,7 +334,7 @@ static int omap_mbox_init(struct omap_mbox *mbox)
334 } 334 }
335 335
336 mbox->dev.class = &omap_mbox_class; 336 mbox->dev.class = &omap_mbox_class;
337 strlcpy(mbox->dev.bus_id, mbox->name, KOBJ_NAME_LEN); 337 dev_set_name(&mbox->dev, "%s", mbox->name);
338 dev_set_drvdata(&mbox->dev, mbox); 338 dev_set_drvdata(&mbox->dev, mbox);
339 339
340 ret = device_register(&mbox->dev); 340 ret = device_register(&mbox->dev);
diff --git a/arch/avr32/kernel/cpu.c b/arch/avr32/kernel/cpu.c
index b8409caeb23d..e84faffbbeca 100644
--- a/arch/avr32/kernel/cpu.c
+++ b/arch/avr32/kernel/cpu.c
@@ -26,14 +26,16 @@ static DEFINE_PER_CPU(struct cpu, cpu_devices);
26 * XXX: If/when a SMP-capable implementation of AVR32 will ever be 26 * XXX: If/when a SMP-capable implementation of AVR32 will ever be
27 * made, we must make sure that the code executes on the correct CPU. 27 * made, we must make sure that the code executes on the correct CPU.
28 */ 28 */
29static ssize_t show_pc0event(struct sys_device *dev, char *buf) 29static ssize_t show_pc0event(struct sys_device *dev,
30 struct sysdev_attribute *attr, char *buf)
30{ 31{
31 unsigned long pccr; 32 unsigned long pccr;
32 33
33 pccr = sysreg_read(PCCR); 34 pccr = sysreg_read(PCCR);
34 return sprintf(buf, "0x%lx\n", (pccr >> 12) & 0x3f); 35 return sprintf(buf, "0x%lx\n", (pccr >> 12) & 0x3f);
35} 36}
36static ssize_t store_pc0event(struct sys_device *dev, const char *buf, 37static ssize_t store_pc0event(struct sys_device *dev,
38 struct sysdev_attribute *attr, const char *buf,
37 size_t count) 39 size_t count)
38{ 40{
39 unsigned long val; 41 unsigned long val;
@@ -46,15 +48,17 @@ static ssize_t store_pc0event(struct sys_device *dev, const char *buf,
46 sysreg_write(PCCR, val); 48 sysreg_write(PCCR, val);
47 return count; 49 return count;
48} 50}
49static ssize_t show_pc0count(struct sys_device *dev, char *buf) 51static ssize_t show_pc0count(struct sys_device *dev,
52 struct sysdev_attribute *attr, char *buf)
50{ 53{
51 unsigned long pcnt0; 54 unsigned long pcnt0;
52 55
53 pcnt0 = sysreg_read(PCNT0); 56 pcnt0 = sysreg_read(PCNT0);
54 return sprintf(buf, "%lu\n", pcnt0); 57 return sprintf(buf, "%lu\n", pcnt0);
55} 58}
56static ssize_t store_pc0count(struct sys_device *dev, const char *buf, 59static ssize_t store_pc0count(struct sys_device *dev,
57 size_t count) 60 struct sysdev_attribute *attr,
61 const char *buf, size_t count)
58{ 62{
59 unsigned long val; 63 unsigned long val;
60 char *endp; 64 char *endp;
@@ -67,14 +71,16 @@ static ssize_t store_pc0count(struct sys_device *dev, const char *buf,
67 return count; 71 return count;
68} 72}
69 73
70static ssize_t show_pc1event(struct sys_device *dev, char *buf) 74static ssize_t show_pc1event(struct sys_device *dev,
75 struct sysdev_attribute *attr, char *buf)
71{ 76{
72 unsigned long pccr; 77 unsigned long pccr;
73 78
74 pccr = sysreg_read(PCCR); 79 pccr = sysreg_read(PCCR);
75 return sprintf(buf, "0x%lx\n", (pccr >> 18) & 0x3f); 80 return sprintf(buf, "0x%lx\n", (pccr >> 18) & 0x3f);
76} 81}
77static ssize_t store_pc1event(struct sys_device *dev, const char *buf, 82static ssize_t store_pc1event(struct sys_device *dev,
83 struct sysdev_attribute *attr, const char *buf,
78 size_t count) 84 size_t count)
79{ 85{
80 unsigned long val; 86 unsigned long val;
@@ -87,14 +93,16 @@ static ssize_t store_pc1event(struct sys_device *dev, const char *buf,
87 sysreg_write(PCCR, val); 93 sysreg_write(PCCR, val);
88 return count; 94 return count;
89} 95}
90static ssize_t show_pc1count(struct sys_device *dev, char *buf) 96static ssize_t show_pc1count(struct sys_device *dev,
97 struct sysdev_attribute *attr, char *buf)
91{ 98{
92 unsigned long pcnt1; 99 unsigned long pcnt1;
93 100
94 pcnt1 = sysreg_read(PCNT1); 101 pcnt1 = sysreg_read(PCNT1);
95 return sprintf(buf, "%lu\n", pcnt1); 102 return sprintf(buf, "%lu\n", pcnt1);
96} 103}
97static ssize_t store_pc1count(struct sys_device *dev, const char *buf, 104static ssize_t store_pc1count(struct sys_device *dev,
105 struct sysdev_attribute *attr, const char *buf,
98 size_t count) 106 size_t count)
99{ 107{
100 unsigned long val; 108 unsigned long val;
@@ -108,14 +116,16 @@ static ssize_t store_pc1count(struct sys_device *dev, const char *buf,
108 return count; 116 return count;
109} 117}
110 118
111static ssize_t show_pccycles(struct sys_device *dev, char *buf) 119static ssize_t show_pccycles(struct sys_device *dev,
120 struct sysdev_attribute *attr, char *buf)
112{ 121{
113 unsigned long pccnt; 122 unsigned long pccnt;
114 123
115 pccnt = sysreg_read(PCCNT); 124 pccnt = sysreg_read(PCCNT);
116 return sprintf(buf, "%lu\n", pccnt); 125 return sprintf(buf, "%lu\n", pccnt);
117} 126}
118static ssize_t store_pccycles(struct sys_device *dev, const char *buf, 127static ssize_t store_pccycles(struct sys_device *dev,
128 struct sysdev_attribute *attr, const char *buf,
119 size_t count) 129 size_t count)
120{ 130{
121 unsigned long val; 131 unsigned long val;
@@ -129,14 +139,16 @@ static ssize_t store_pccycles(struct sys_device *dev, const char *buf,
129 return count; 139 return count;
130} 140}
131 141
132static ssize_t show_pcenable(struct sys_device *dev, char *buf) 142static ssize_t show_pcenable(struct sys_device *dev,
143 struct sysdev_attribute *attr, char *buf)
133{ 144{
134 unsigned long pccr; 145 unsigned long pccr;
135 146
136 pccr = sysreg_read(PCCR); 147 pccr = sysreg_read(PCCR);
137 return sprintf(buf, "%c\n", (pccr & 1)?'1':'0'); 148 return sprintf(buf, "%c\n", (pccr & 1)?'1':'0');
138} 149}
139static ssize_t store_pcenable(struct sys_device *dev, const char *buf, 150static ssize_t store_pcenable(struct sys_device *dev,
151 struct sysdev_attribute *attr, const char *buf,
140 size_t count) 152 size_t count)
141{ 153{
142 unsigned long pccr, val; 154 unsigned long pccr, val;
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index b87634e75f20..b83b8ef84e91 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -873,8 +873,8 @@ config HOTPLUG
873 plugged into slots found on all modern laptop computers. Another 873 plugged into slots found on all modern laptop computers. Another
874 example, used on modern desktops as well as laptops, is USB. 874 example, used on modern desktops as well as laptops, is USB.
875 875
876 Enable HOTPLUG and KMOD, and build a modular kernel. Get agent 876 Enable HOTPLUG and build a modular kernel. Get agent software
877 software (at <http://linux-hotplug.sourceforge.net/>) and install it. 877 (from <http://linux-hotplug.sourceforge.net/>) and install it.
878 Then your kernel will automatically call out to a user mode "policy 878 Then your kernel will automatically call out to a user mode "policy
879 agent" (/sbin/hotplug) to load modules and set up software needed 879 agent" (/sbin/hotplug) to load modules and set up software needed
880 to use devices as you hotplug them. 880 to use devices as you hotplug them.
diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
index 18bcc10903b4..451f2ffb137b 100644
--- a/arch/ia64/Kconfig
+++ b/arch/ia64/Kconfig
@@ -540,8 +540,8 @@ config KEXEC
540 strongly in flux, so no good recommendation can be made. 540 strongly in flux, so no good recommendation can be made.
541 541
542config CRASH_DUMP 542config CRASH_DUMP
543 bool "kernel crash dumps (EXPERIMENTAL)" 543 bool "kernel crash dumps"
544 depends on EXPERIMENTAL && IA64_MCA_RECOVERY && !IA64_HP_SIM && (!SMP || HOTPLUG_CPU) 544 depends on IA64_MCA_RECOVERY && !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
545 help 545 help
546 Generate crash dump after being started by kexec. 546 Generate crash dump after being started by kexec.
547 547
diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
index e67ee3f27698..905d25b13d5a 100644
--- a/arch/ia64/Makefile
+++ b/arch/ia64/Makefile
@@ -100,3 +100,9 @@ define archhelp
100 echo ' boot - Build vmlinux and bootloader for Ski simulator' 100 echo ' boot - Build vmlinux and bootloader for Ski simulator'
101 echo '* unwcheck - Check vmlinux for invalid unwind info' 101 echo '* unwcheck - Check vmlinux for invalid unwind info'
102endef 102endef
103
104archprepare: make_nr_irqs_h FORCE
105PHONY += make_nr_irqs_h FORCE
106
107make_nr_irqs_h: FORCE
108 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/asm-ia64/nr-irqs.h
diff --git a/arch/ia64/kernel/Makefile b/arch/ia64/kernel/Makefile
index 13fd10e8699e..87fea11aecb7 100644
--- a/arch/ia64/kernel/Makefile
+++ b/arch/ia64/kernel/Makefile
@@ -36,6 +36,8 @@ obj-$(CONFIG_PCI_MSI) += msi_ia64.o
36mca_recovery-y += mca_drv.o mca_drv_asm.o 36mca_recovery-y += mca_drv.o mca_drv_asm.o
37obj-$(CONFIG_IA64_MC_ERR_INJECT)+= err_inject.o 37obj-$(CONFIG_IA64_MC_ERR_INJECT)+= err_inject.o
38 38
39obj-$(CONFIG_PARAVIRT) += paravirt.o paravirtentry.o
40
39obj-$(CONFIG_IA64_ESI) += esi.o 41obj-$(CONFIG_IA64_ESI) += esi.o
40ifneq ($(CONFIG_IA64_ESI),) 42ifneq ($(CONFIG_IA64_ESI),)
41obj-y += esi_stub.o # must be in kernel proper 43obj-y += esi_stub.o # must be in kernel proper
@@ -70,3 +72,45 @@ $(obj)/gate-syms.o: $(obj)/gate.lds $(obj)/gate.o FORCE
70# We must build gate.so before we can assemble it. 72# We must build gate.so before we can assemble it.
71# Note: kbuild does not track this dependency due to usage of .incbin 73# Note: kbuild does not track this dependency due to usage of .incbin
72$(obj)/gate-data.o: $(obj)/gate.so 74$(obj)/gate-data.o: $(obj)/gate.so
75
76# Calculate NR_IRQ = max(IA64_NATIVE_NR_IRQS, XEN_NR_IRQS, ...) based on config
77define sed-y
78 "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"
79endef
80quiet_cmd_nr_irqs = GEN $@
81define cmd_nr_irqs
82 (set -e; \
83 echo "#ifndef __ASM_NR_IRQS_H__"; \
84 echo "#define __ASM_NR_IRQS_H__"; \
85 echo "/*"; \
86 echo " * DO NOT MODIFY."; \
87 echo " *"; \
88 echo " * This file was generated by Kbuild"; \
89 echo " *"; \
90 echo " */"; \
91 echo ""; \
92 sed -ne $(sed-y) $<; \
93 echo ""; \
94 echo "#endif" ) > $@
95endef
96
97# We use internal kbuild rules to avoid the "is up to date" message from make
98arch/$(SRCARCH)/kernel/nr-irqs.s: $(srctree)/arch/$(SRCARCH)/kernel/nr-irqs.c \
99 $(wildcard $(srctree)/include/asm-ia64/*/irq.h)
100 $(Q)mkdir -p $(dir $@)
101 $(call if_changed_dep,cc_s_c)
102
103include/asm-ia64/nr-irqs.h: arch/$(SRCARCH)/kernel/nr-irqs.s
104 $(Q)mkdir -p $(dir $@)
105 $(call cmd,nr_irqs)
106
107clean-files += $(objtree)/include/asm-ia64/nr-irqs.h
108
109#
110# native ivt.S and entry.S
111#
112ASM_PARAVIRT_OBJS = ivt.o entry.o
113define paravirtualized_native
114AFLAGS_$(1) += -D__IA64_ASM_PARAVIRTUALIZED_NATIVE
115endef
116$(foreach obj,$(ASM_PARAVIRT_OBJS),$(eval $(call paravirtualized_native,$(obj))))
diff --git a/arch/ia64/kernel/acpi.c b/arch/ia64/kernel/acpi.c
index 43687cc60dfb..5d1eb7ee2bf6 100644
--- a/arch/ia64/kernel/acpi.c
+++ b/arch/ia64/kernel/acpi.c
@@ -774,7 +774,7 @@ int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
774 */ 774 */
775#ifdef CONFIG_ACPI_HOTPLUG_CPU 775#ifdef CONFIG_ACPI_HOTPLUG_CPU
776static 776static
777int acpi_map_cpu2node(acpi_handle handle, int cpu, long physid) 777int acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
778{ 778{
779#ifdef CONFIG_ACPI_NUMA 779#ifdef CONFIG_ACPI_NUMA
780 int pxm_id; 780 int pxm_id;
@@ -854,8 +854,7 @@ int acpi_map_lsapic(acpi_handle handle, int *pcpu)
854 union acpi_object *obj; 854 union acpi_object *obj;
855 struct acpi_madt_local_sapic *lsapic; 855 struct acpi_madt_local_sapic *lsapic;
856 cpumask_t tmp_map; 856 cpumask_t tmp_map;
857 long physid; 857 int cpu, physid;
858 int cpu;
859 858
860 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer))) 859 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
861 return -EINVAL; 860 return -EINVAL;
diff --git a/arch/ia64/kernel/cpufreq/acpi-cpufreq.c b/arch/ia64/kernel/cpufreq/acpi-cpufreq.c
index b8498ea62068..7b435451b3dc 100644
--- a/arch/ia64/kernel/cpufreq/acpi-cpufreq.c
+++ b/arch/ia64/kernel/cpufreq/acpi-cpufreq.c
@@ -51,7 +51,7 @@ processor_set_pstate (
51 retval = ia64_pal_set_pstate((u64)value); 51 retval = ia64_pal_set_pstate((u64)value);
52 52
53 if (retval) { 53 if (retval) {
54 dprintk("Failed to set freq to 0x%x, with error 0x%x\n", 54 dprintk("Failed to set freq to 0x%x, with error 0x%lx\n",
55 value, retval); 55 value, retval);
56 return -ENODEV; 56 return -ENODEV;
57 } 57 }
@@ -74,7 +74,7 @@ processor_get_pstate (
74 74
75 if (retval) 75 if (retval)
76 dprintk("Failed to get current freq with " 76 dprintk("Failed to get current freq with "
77 "error 0x%x, idx 0x%x\n", retval, *value); 77 "error 0x%lx, idx 0x%x\n", retval, *value);
78 78
79 return (int)retval; 79 return (int)retval;
80} 80}
diff --git a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S
index ca2bb95726de..56ab156c48ae 100644
--- a/arch/ia64/kernel/entry.S
+++ b/arch/ia64/kernel/entry.S
@@ -23,6 +23,11 @@
23 * 11/07/2000 23 * 11/07/2000
24 */ 24 */
25/* 25/*
26 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
27 * VA Linux Systems Japan K.K.
28 * pv_ops.
29 */
30/*
26 * Global (preserved) predicate usage on syscall entry/exit path: 31 * Global (preserved) predicate usage on syscall entry/exit path:
27 * 32 *
28 * pKStk: See entry.h. 33 * pKStk: See entry.h.
@@ -45,6 +50,7 @@
45 50
46#include "minstate.h" 51#include "minstate.h"
47 52
53#ifdef __IA64_ASM_PARAVIRTUALIZED_NATIVE
48 /* 54 /*
49 * execve() is special because in case of success, we need to 55 * execve() is special because in case of success, we need to
50 * setup a null register window frame. 56 * setup a null register window frame.
@@ -173,6 +179,7 @@ GLOBAL_ENTRY(sys_clone)
173 mov rp=loc0 179 mov rp=loc0
174 br.ret.sptk.many rp 180 br.ret.sptk.many rp
175END(sys_clone) 181END(sys_clone)
182#endif /* __IA64_ASM_PARAVIRTUALIZED_NATIVE */
176 183
177/* 184/*
178 * prev_task <- ia64_switch_to(struct task_struct *next) 185 * prev_task <- ia64_switch_to(struct task_struct *next)
@@ -180,7 +187,7 @@ END(sys_clone)
180 * called. The code starting at .map relies on this. The rest of the code 187 * called. The code starting at .map relies on this. The rest of the code
181 * doesn't care about the interrupt masking status. 188 * doesn't care about the interrupt masking status.
182 */ 189 */
183GLOBAL_ENTRY(ia64_switch_to) 190GLOBAL_ENTRY(__paravirt_switch_to)
184 .prologue 191 .prologue
185 alloc r16=ar.pfs,1,0,0,0 192 alloc r16=ar.pfs,1,0,0,0
186 DO_SAVE_SWITCH_STACK 193 DO_SAVE_SWITCH_STACK
@@ -204,7 +211,7 @@ GLOBAL_ENTRY(ia64_switch_to)
204 ;; 211 ;;
205.done: 212.done:
206 ld8 sp=[r21] // load kernel stack pointer of new task 213 ld8 sp=[r21] // load kernel stack pointer of new task
207 mov IA64_KR(CURRENT)=in0 // update "current" application register 214 MOV_TO_KR(CURRENT, in0, r8, r9) // update "current" application register
208 mov r8=r13 // return pointer to previously running task 215 mov r8=r13 // return pointer to previously running task
209 mov r13=in0 // set "current" pointer 216 mov r13=in0 // set "current" pointer
210 ;; 217 ;;
@@ -216,26 +223,25 @@ GLOBAL_ENTRY(ia64_switch_to)
216 br.ret.sptk.many rp // boogie on out in new context 223 br.ret.sptk.many rp // boogie on out in new context
217 224
218.map: 225.map:
219 rsm psr.ic // interrupts (psr.i) are already disabled here 226 RSM_PSR_IC(r25) // interrupts (psr.i) are already disabled here
220 movl r25=PAGE_KERNEL 227 movl r25=PAGE_KERNEL
221 ;; 228 ;;
222 srlz.d 229 srlz.d
223 or r23=r25,r20 // construct PA | page properties 230 or r23=r25,r20 // construct PA | page properties
224 mov r25=IA64_GRANULE_SHIFT<<2 231 mov r25=IA64_GRANULE_SHIFT<<2
225 ;; 232 ;;
226 mov cr.itir=r25 233 MOV_TO_ITIR(p0, r25, r8)
227 mov cr.ifa=in0 // VA of next task... 234 MOV_TO_IFA(in0, r8) // VA of next task...
228 ;; 235 ;;
229 mov r25=IA64_TR_CURRENT_STACK 236 mov r25=IA64_TR_CURRENT_STACK
230 mov IA64_KR(CURRENT_STACK)=r26 // remember last page we mapped... 237 MOV_TO_KR(CURRENT_STACK, r26, r8, r9) // remember last page we mapped...
231 ;; 238 ;;
232 itr.d dtr[r25]=r23 // wire in new mapping... 239 itr.d dtr[r25]=r23 // wire in new mapping...
233 ssm psr.ic // reenable the psr.ic bit 240 SSM_PSR_IC_AND_SRLZ_D(r8, r9) // reenable the psr.ic bit
234 ;;
235 srlz.d
236 br.cond.sptk .done 241 br.cond.sptk .done
237END(ia64_switch_to) 242END(__paravirt_switch_to)
238 243
244#ifdef __IA64_ASM_PARAVIRTUALIZED_NATIVE
239/* 245/*
240 * Note that interrupts are enabled during save_switch_stack and load_switch_stack. This 246 * Note that interrupts are enabled during save_switch_stack and load_switch_stack. This
241 * means that we may get an interrupt with "sp" pointing to the new kernel stack while 247 * means that we may get an interrupt with "sp" pointing to the new kernel stack while
@@ -375,7 +381,7 @@ END(save_switch_stack)
375 * - b7 holds address to return to 381 * - b7 holds address to return to
376 * - must not touch r8-r11 382 * - must not touch r8-r11
377 */ 383 */
378ENTRY(load_switch_stack) 384GLOBAL_ENTRY(load_switch_stack)
379 .prologue 385 .prologue
380 .altrp b7 386 .altrp b7
381 387
@@ -571,7 +577,7 @@ GLOBAL_ENTRY(ia64_trace_syscall)
571.ret3: 577.ret3:
572(pUStk) cmp.eq.unc p6,p0=r0,r0 // p6 <- pUStk 578(pUStk) cmp.eq.unc p6,p0=r0,r0 // p6 <- pUStk
573(pUStk) rsm psr.i // disable interrupts 579(pUStk) rsm psr.i // disable interrupts
574 br.cond.sptk .work_pending_syscall_end 580 br.cond.sptk ia64_work_pending_syscall_end
575 581
576strace_error: 582strace_error:
577 ld8 r3=[r2] // load pt_regs.r8 583 ld8 r3=[r2] // load pt_regs.r8
@@ -636,8 +642,17 @@ GLOBAL_ENTRY(ia64_ret_from_syscall)
636 adds r2=PT(R8)+16,sp // r2 = &pt_regs.r8 642 adds r2=PT(R8)+16,sp // r2 = &pt_regs.r8
637 mov r10=r0 // clear error indication in r10 643 mov r10=r0 // clear error indication in r10
638(p7) br.cond.spnt handle_syscall_error // handle potential syscall failure 644(p7) br.cond.spnt handle_syscall_error // handle potential syscall failure
645#ifdef CONFIG_PARAVIRT
646 ;;
647 br.cond.sptk.few ia64_leave_syscall
648 ;;
649#endif /* CONFIG_PARAVIRT */
639END(ia64_ret_from_syscall) 650END(ia64_ret_from_syscall)
651#ifndef CONFIG_PARAVIRT
640 // fall through 652 // fall through
653#endif
654#endif /* __IA64_ASM_PARAVIRTUALIZED_NATIVE */
655
641/* 656/*
642 * ia64_leave_syscall(): Same as ia64_leave_kernel, except that it doesn't 657 * ia64_leave_syscall(): Same as ia64_leave_kernel, except that it doesn't
643 * need to switch to bank 0 and doesn't restore the scratch registers. 658 * need to switch to bank 0 and doesn't restore the scratch registers.
@@ -682,7 +697,7 @@ END(ia64_ret_from_syscall)
682 * ar.csd: cleared 697 * ar.csd: cleared
683 * ar.ssd: cleared 698 * ar.ssd: cleared
684 */ 699 */
685ENTRY(ia64_leave_syscall) 700GLOBAL_ENTRY(__paravirt_leave_syscall)
686 PT_REGS_UNWIND_INFO(0) 701 PT_REGS_UNWIND_INFO(0)
687 /* 702 /*
688 * work.need_resched etc. mustn't get changed by this CPU before it returns to 703 * work.need_resched etc. mustn't get changed by this CPU before it returns to
@@ -692,11 +707,11 @@ ENTRY(ia64_leave_syscall)
692 * extra work. We always check for extra work when returning to user-level. 707 * extra work. We always check for extra work when returning to user-level.
693 * With CONFIG_PREEMPT, we also check for extra work when the preempt_count 708 * With CONFIG_PREEMPT, we also check for extra work when the preempt_count
694 * is 0. After extra work processing has been completed, execution 709 * is 0. After extra work processing has been completed, execution
695 * resumes at .work_processed_syscall with p6 set to 1 if the extra-work-check 710 * resumes at ia64_work_processed_syscall with p6 set to 1 if the extra-work-check
696 * needs to be redone. 711 * needs to be redone.
697 */ 712 */
698#ifdef CONFIG_PREEMPT 713#ifdef CONFIG_PREEMPT
699 rsm psr.i // disable interrupts 714 RSM_PSR_I(p0, r2, r18) // disable interrupts
700 cmp.eq pLvSys,p0=r0,r0 // pLvSys=1: leave from syscall 715 cmp.eq pLvSys,p0=r0,r0 // pLvSys=1: leave from syscall
701(pKStk) adds r20=TI_PRE_COUNT+IA64_TASK_SIZE,r13 716(pKStk) adds r20=TI_PRE_COUNT+IA64_TASK_SIZE,r13
702 ;; 717 ;;
@@ -706,11 +721,12 @@ ENTRY(ia64_leave_syscall)
706 ;; 721 ;;
707 cmp.eq p6,p0=r21,r0 // p6 <- pUStk || (preempt_count == 0) 722 cmp.eq p6,p0=r21,r0 // p6 <- pUStk || (preempt_count == 0)
708#else /* !CONFIG_PREEMPT */ 723#else /* !CONFIG_PREEMPT */
709(pUStk) rsm psr.i 724 RSM_PSR_I(pUStk, r2, r18)
710 cmp.eq pLvSys,p0=r0,r0 // pLvSys=1: leave from syscall 725 cmp.eq pLvSys,p0=r0,r0 // pLvSys=1: leave from syscall
711(pUStk) cmp.eq.unc p6,p0=r0,r0 // p6 <- pUStk 726(pUStk) cmp.eq.unc p6,p0=r0,r0 // p6 <- pUStk
712#endif 727#endif
713.work_processed_syscall: 728.global __paravirt_work_processed_syscall;
729__paravirt_work_processed_syscall:
714#ifdef CONFIG_VIRT_CPU_ACCOUNTING 730#ifdef CONFIG_VIRT_CPU_ACCOUNTING
715 adds r2=PT(LOADRS)+16,r12 731 adds r2=PT(LOADRS)+16,r12
716(pUStk) mov.m r22=ar.itc // fetch time at leave 732(pUStk) mov.m r22=ar.itc // fetch time at leave
@@ -744,7 +760,7 @@ ENTRY(ia64_leave_syscall)
744(pNonSys) break 0 // bug check: we shouldn't be here if pNonSys is TRUE! 760(pNonSys) break 0 // bug check: we shouldn't be here if pNonSys is TRUE!
745 ;; 761 ;;
746 invala // M0|1 invalidate ALAT 762 invala // M0|1 invalidate ALAT
747 rsm psr.i | psr.ic // M2 turn off interrupts and interruption collection 763 RSM_PSR_I_IC(r28, r29, r30) // M2 turn off interrupts and interruption collection
748 cmp.eq p9,p0=r0,r0 // A set p9 to indicate that we should restore cr.ifs 764 cmp.eq p9,p0=r0,r0 // A set p9 to indicate that we should restore cr.ifs
749 765
750 ld8 r29=[r2],16 // M0|1 load cr.ipsr 766 ld8 r29=[r2],16 // M0|1 load cr.ipsr
@@ -765,7 +781,7 @@ ENTRY(ia64_leave_syscall)
765 ;; 781 ;;
766#endif 782#endif
767 ld8 r26=[r2],PT(B0)-PT(AR_PFS) // M0|1 load ar.pfs 783 ld8 r26=[r2],PT(B0)-PT(AR_PFS) // M0|1 load ar.pfs
768(pKStk) mov r22=psr // M2 read PSR now that interrupts are disabled 784 MOV_FROM_PSR(pKStk, r22, r21) // M2 read PSR now that interrupts are disabled
769 nop 0 785 nop 0
770 ;; 786 ;;
771 ld8 r21=[r2],PT(AR_RNAT)-PT(B0) // M0|1 load b0 787 ld8 r21=[r2],PT(AR_RNAT)-PT(B0) // M0|1 load b0
@@ -798,7 +814,7 @@ ENTRY(ia64_leave_syscall)
798 814
799 srlz.d // M0 ensure interruption collection is off (for cover) 815 srlz.d // M0 ensure interruption collection is off (for cover)
800 shr.u r18=r19,16 // I0|1 get byte size of existing "dirty" partition 816 shr.u r18=r19,16 // I0|1 get byte size of existing "dirty" partition
801 cover // B add current frame into dirty partition & set cr.ifs 817 COVER // B add current frame into dirty partition & set cr.ifs
802 ;; 818 ;;
803#ifdef CONFIG_VIRT_CPU_ACCOUNTING 819#ifdef CONFIG_VIRT_CPU_ACCOUNTING
804 mov r19=ar.bsp // M2 get new backing store pointer 820 mov r19=ar.bsp // M2 get new backing store pointer
@@ -823,8 +839,9 @@ ENTRY(ia64_leave_syscall)
823 mov.m ar.ssd=r0 // M2 clear ar.ssd 839 mov.m ar.ssd=r0 // M2 clear ar.ssd
824 mov f11=f0 // F clear f11 840 mov f11=f0 // F clear f11
825 br.cond.sptk.many rbs_switch // B 841 br.cond.sptk.many rbs_switch // B
826END(ia64_leave_syscall) 842END(__paravirt_leave_syscall)
827 843
844#ifdef __IA64_ASM_PARAVIRTUALIZED_NATIVE
828#ifdef CONFIG_IA32_SUPPORT 845#ifdef CONFIG_IA32_SUPPORT
829GLOBAL_ENTRY(ia64_ret_from_ia32_execve) 846GLOBAL_ENTRY(ia64_ret_from_ia32_execve)
830 PT_REGS_UNWIND_INFO(0) 847 PT_REGS_UNWIND_INFO(0)
@@ -835,10 +852,20 @@ GLOBAL_ENTRY(ia64_ret_from_ia32_execve)
835 st8.spill [r2]=r8 // store return value in slot for r8 and set unat bit 852 st8.spill [r2]=r8 // store return value in slot for r8 and set unat bit
836 .mem.offset 8,0 853 .mem.offset 8,0
837 st8.spill [r3]=r0 // clear error indication in slot for r10 and set unat bit 854 st8.spill [r3]=r0 // clear error indication in slot for r10 and set unat bit
855#ifdef CONFIG_PARAVIRT
856 ;;
857 // don't fall through, ia64_leave_kernel may be #define'd
858 br.cond.sptk.few ia64_leave_kernel
859 ;;
860#endif /* CONFIG_PARAVIRT */
838END(ia64_ret_from_ia32_execve) 861END(ia64_ret_from_ia32_execve)
862#ifndef CONFIG_PARAVIRT
839 // fall through 863 // fall through
864#endif
840#endif /* CONFIG_IA32_SUPPORT */ 865#endif /* CONFIG_IA32_SUPPORT */
841GLOBAL_ENTRY(ia64_leave_kernel) 866#endif /* __IA64_ASM_PARAVIRTUALIZED_NATIVE */
867
868GLOBAL_ENTRY(__paravirt_leave_kernel)
842 PT_REGS_UNWIND_INFO(0) 869 PT_REGS_UNWIND_INFO(0)
843 /* 870 /*
844 * work.need_resched etc. mustn't get changed by this CPU before it returns to 871 * work.need_resched etc. mustn't get changed by this CPU before it returns to
@@ -852,7 +879,7 @@ GLOBAL_ENTRY(ia64_leave_kernel)
852 * needs to be redone. 879 * needs to be redone.
853 */ 880 */
854#ifdef CONFIG_PREEMPT 881#ifdef CONFIG_PREEMPT
855 rsm psr.i // disable interrupts 882 RSM_PSR_I(p0, r17, r31) // disable interrupts
856 cmp.eq p0,pLvSys=r0,r0 // pLvSys=0: leave from kernel 883 cmp.eq p0,pLvSys=r0,r0 // pLvSys=0: leave from kernel
857(pKStk) adds r20=TI_PRE_COUNT+IA64_TASK_SIZE,r13 884(pKStk) adds r20=TI_PRE_COUNT+IA64_TASK_SIZE,r13
858 ;; 885 ;;
@@ -862,7 +889,7 @@ GLOBAL_ENTRY(ia64_leave_kernel)
862 ;; 889 ;;
863 cmp.eq p6,p0=r21,r0 // p6 <- pUStk || (preempt_count == 0) 890 cmp.eq p6,p0=r21,r0 // p6 <- pUStk || (preempt_count == 0)
864#else 891#else
865(pUStk) rsm psr.i 892 RSM_PSR_I(pUStk, r17, r31)
866 cmp.eq p0,pLvSys=r0,r0 // pLvSys=0: leave from kernel 893 cmp.eq p0,pLvSys=r0,r0 // pLvSys=0: leave from kernel
867(pUStk) cmp.eq.unc p6,p0=r0,r0 // p6 <- pUStk 894(pUStk) cmp.eq.unc p6,p0=r0,r0 // p6 <- pUStk
868#endif 895#endif
@@ -910,7 +937,7 @@ GLOBAL_ENTRY(ia64_leave_kernel)
910 mov ar.csd=r30 937 mov ar.csd=r30
911 mov ar.ssd=r31 938 mov ar.ssd=r31
912 ;; 939 ;;
913 rsm psr.i | psr.ic // initiate turning off of interrupt and interruption collection 940 RSM_PSR_I_IC(r23, r22, r25) // initiate turning off of interrupt and interruption collection
914 invala // invalidate ALAT 941 invala // invalidate ALAT
915 ;; 942 ;;
916 ld8.fill r22=[r2],24 943 ld8.fill r22=[r2],24
@@ -942,7 +969,7 @@ GLOBAL_ENTRY(ia64_leave_kernel)
942 mov ar.ccv=r15 969 mov ar.ccv=r15
943 ;; 970 ;;
944 ldf.fill f11=[r2] 971 ldf.fill f11=[r2]
945 bsw.0 // switch back to bank 0 (no stop bit required beforehand...) 972 BSW_0(r2, r3, r15) // switch back to bank 0 (no stop bit required beforehand...)
946 ;; 973 ;;
947(pUStk) mov r18=IA64_KR(CURRENT)// M2 (12 cycle read latency) 974(pUStk) mov r18=IA64_KR(CURRENT)// M2 (12 cycle read latency)
948 adds r16=PT(CR_IPSR)+16,r12 975 adds r16=PT(CR_IPSR)+16,r12
@@ -950,12 +977,12 @@ GLOBAL_ENTRY(ia64_leave_kernel)
950 977
951#ifdef CONFIG_VIRT_CPU_ACCOUNTING 978#ifdef CONFIG_VIRT_CPU_ACCOUNTING
952 .pred.rel.mutex pUStk,pKStk 979 .pred.rel.mutex pUStk,pKStk
953(pKStk) mov r22=psr // M2 read PSR now that interrupts are disabled 980 MOV_FROM_PSR(pKStk, r22, r29) // M2 read PSR now that interrupts are disabled
954(pUStk) mov.m r22=ar.itc // M fetch time at leave 981(pUStk) mov.m r22=ar.itc // M fetch time at leave
955 nop.i 0 982 nop.i 0
956 ;; 983 ;;
957#else 984#else
958(pKStk) mov r22=psr // M2 read PSR now that interrupts are disabled 985 MOV_FROM_PSR(pKStk, r22, r29) // M2 read PSR now that interrupts are disabled
959 nop.i 0 986 nop.i 0
960 nop.i 0 987 nop.i 0
961 ;; 988 ;;
@@ -1027,7 +1054,7 @@ GLOBAL_ENTRY(ia64_leave_kernel)
1027 * NOTE: alloc, loadrs, and cover can't be predicated. 1054 * NOTE: alloc, loadrs, and cover can't be predicated.
1028 */ 1055 */
1029(pNonSys) br.cond.dpnt dont_preserve_current_frame 1056(pNonSys) br.cond.dpnt dont_preserve_current_frame
1030 cover // add current frame into dirty partition and set cr.ifs 1057 COVER // add current frame into dirty partition and set cr.ifs
1031 ;; 1058 ;;
1032 mov r19=ar.bsp // get new backing store pointer 1059 mov r19=ar.bsp // get new backing store pointer
1033rbs_switch: 1060rbs_switch:
@@ -1130,16 +1157,16 @@ skip_rbs_switch:
1130(pKStk) dep r29=r22,r29,21,1 // I0 update ipsr.pp with psr.pp 1157(pKStk) dep r29=r22,r29,21,1 // I0 update ipsr.pp with psr.pp
1131(pLvSys)mov r16=r0 // A clear r16 for leave_syscall, no-op otherwise 1158(pLvSys)mov r16=r0 // A clear r16 for leave_syscall, no-op otherwise
1132 ;; 1159 ;;
1133 mov cr.ipsr=r29 // M2 1160 MOV_TO_IPSR(p0, r29, r25) // M2
1134 mov ar.pfs=r26 // I0 1161 mov ar.pfs=r26 // I0
1135(pLvSys)mov r17=r0 // A clear r17 for leave_syscall, no-op otherwise 1162(pLvSys)mov r17=r0 // A clear r17 for leave_syscall, no-op otherwise
1136 1163
1137(p9) mov cr.ifs=r30 // M2 1164 MOV_TO_IFS(p9, r30, r25)// M2
1138 mov b0=r21 // I0 1165 mov b0=r21 // I0
1139(pLvSys)mov r18=r0 // A clear r18 for leave_syscall, no-op otherwise 1166(pLvSys)mov r18=r0 // A clear r18 for leave_syscall, no-op otherwise
1140 1167
1141 mov ar.fpsr=r20 // M2 1168 mov ar.fpsr=r20 // M2
1142 mov cr.iip=r28 // M2 1169 MOV_TO_IIP(r28, r25) // M2
1143 nop 0 1170 nop 0
1144 ;; 1171 ;;
1145(pUStk) mov ar.rnat=r24 // M2 must happen with RSE in lazy mode 1172(pUStk) mov ar.rnat=r24 // M2 must happen with RSE in lazy mode
@@ -1148,7 +1175,7 @@ skip_rbs_switch:
1148 1175
1149 mov ar.rsc=r27 // M2 1176 mov ar.rsc=r27 // M2
1150 mov pr=r31,-1 // I0 1177 mov pr=r31,-1 // I0
1151 rfi // B 1178 RFI // B
1152 1179
1153 /* 1180 /*
1154 * On entry: 1181 * On entry:
@@ -1174,35 +1201,36 @@ skip_rbs_switch:
1174 ;; 1201 ;;
1175(pKStk) st4 [r20]=r21 1202(pKStk) st4 [r20]=r21
1176#endif 1203#endif
1177 ssm psr.i // enable interrupts 1204 SSM_PSR_I(p0, p6, r2) // enable interrupts
1178 br.call.spnt.many rp=schedule 1205 br.call.spnt.many rp=schedule
1179.ret9: cmp.eq p6,p0=r0,r0 // p6 <- 1 (re-check) 1206.ret9: cmp.eq p6,p0=r0,r0 // p6 <- 1 (re-check)
1180 rsm psr.i // disable interrupts 1207 RSM_PSR_I(p0, r2, r20) // disable interrupts
1181 ;; 1208 ;;
1182#ifdef CONFIG_PREEMPT 1209#ifdef CONFIG_PREEMPT
1183(pKStk) adds r20=TI_PRE_COUNT+IA64_TASK_SIZE,r13 1210(pKStk) adds r20=TI_PRE_COUNT+IA64_TASK_SIZE,r13
1184 ;; 1211 ;;
1185(pKStk) st4 [r20]=r0 // preempt_count() <- 0 1212(pKStk) st4 [r20]=r0 // preempt_count() <- 0
1186#endif 1213#endif
1187(pLvSys)br.cond.sptk.few .work_pending_syscall_end 1214(pLvSys)br.cond.sptk.few __paravirt_pending_syscall_end
1188 br.cond.sptk.many .work_processed_kernel 1215 br.cond.sptk.many .work_processed_kernel
1189 1216
1190.notify: 1217.notify:
1191(pUStk) br.call.spnt.many rp=notify_resume_user 1218(pUStk) br.call.spnt.many rp=notify_resume_user
1192.ret10: cmp.ne p6,p0=r0,r0 // p6 <- 0 (don't re-check) 1219.ret10: cmp.ne p6,p0=r0,r0 // p6 <- 0 (don't re-check)
1193(pLvSys)br.cond.sptk.few .work_pending_syscall_end 1220(pLvSys)br.cond.sptk.few __paravirt_pending_syscall_end
1194 br.cond.sptk.many .work_processed_kernel 1221 br.cond.sptk.many .work_processed_kernel
1195 1222
1196.work_pending_syscall_end: 1223.global __paravirt_pending_syscall_end;
1224__paravirt_pending_syscall_end:
1197 adds r2=PT(R8)+16,r12 1225 adds r2=PT(R8)+16,r12
1198 adds r3=PT(R10)+16,r12 1226 adds r3=PT(R10)+16,r12
1199 ;; 1227 ;;
1200 ld8 r8=[r2] 1228 ld8 r8=[r2]
1201 ld8 r10=[r3] 1229 ld8 r10=[r3]
1202 br.cond.sptk.many .work_processed_syscall 1230 br.cond.sptk.many __paravirt_work_processed_syscall_target
1203 1231END(__paravirt_leave_kernel)
1204END(ia64_leave_kernel)
1205 1232
1233#ifdef __IA64_ASM_PARAVIRTUALIZED_NATIVE
1206ENTRY(handle_syscall_error) 1234ENTRY(handle_syscall_error)
1207 /* 1235 /*
1208 * Some system calls (e.g., ptrace, mmap) can return arbitrary values which could 1236 * Some system calls (e.g., ptrace, mmap) can return arbitrary values which could
@@ -1244,7 +1272,7 @@ END(ia64_invoke_schedule_tail)
1244 * We declare 8 input registers so the system call args get preserved, 1272 * We declare 8 input registers so the system call args get preserved,
1245 * in case we need to restart a system call. 1273 * in case we need to restart a system call.
1246 */ 1274 */
1247ENTRY(notify_resume_user) 1275GLOBAL_ENTRY(notify_resume_user)
1248 .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(8) 1276 .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(8)
1249 alloc loc1=ar.pfs,8,2,3,0 // preserve all eight input regs in case of syscall restart! 1277 alloc loc1=ar.pfs,8,2,3,0 // preserve all eight input regs in case of syscall restart!
1250 mov r9=ar.unat 1278 mov r9=ar.unat
@@ -1306,7 +1334,7 @@ ENTRY(sys_rt_sigreturn)
1306 adds sp=16,sp 1334 adds sp=16,sp
1307 ;; 1335 ;;
1308 ld8 r9=[sp] // load new ar.unat 1336 ld8 r9=[sp] // load new ar.unat
1309 mov.sptk b7=r8,ia64_leave_kernel 1337 mov.sptk b7=r8,ia64_native_leave_kernel
1310 ;; 1338 ;;
1311 mov ar.unat=r9 1339 mov ar.unat=r9
1312 br.many b7 1340 br.many b7
@@ -1665,3 +1693,4 @@ sys_call_table:
1665 data8 sys_timerfd_gettime 1693 data8 sys_timerfd_gettime
1666 1694
1667 .org sys_call_table + 8*NR_syscalls // guard against failures to increase NR_syscalls 1695 .org sys_call_table + 8*NR_syscalls // guard against failures to increase NR_syscalls
1696#endif /* __IA64_ASM_PARAVIRTUALIZED_NATIVE */
diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
index b642648cc2ac..c539c689493b 100644
--- a/arch/ia64/kernel/err_inject.c
+++ b/arch/ia64/kernel/err_inject.c
@@ -55,7 +55,8 @@ static u64 resources[NR_CPUS];
55 55
56#define show(name) \ 56#define show(name) \
57static ssize_t \ 57static ssize_t \
58show_##name(struct sys_device *dev, char *buf) \ 58show_##name(struct sys_device *dev, struct sysdev_attribute *attr, \
59 char *buf) \
59{ \ 60{ \
60 u32 cpu=dev->id; \ 61 u32 cpu=dev->id; \
61 return sprintf(buf, "%lx\n", name[cpu]); \ 62 return sprintf(buf, "%lx\n", name[cpu]); \
@@ -63,7 +64,8 @@ show_##name(struct sys_device *dev, char *buf) \
63 64
64#define store(name) \ 65#define store(name) \
65static ssize_t \ 66static ssize_t \
66store_##name(struct sys_device *dev, const char *buf, size_t size) \ 67store_##name(struct sys_device *dev, struct sysdev_attribute *attr, \
68 const char *buf, size_t size) \
67{ \ 69{ \
68 unsigned int cpu=dev->id; \ 70 unsigned int cpu=dev->id; \
69 name[cpu] = simple_strtoull(buf, NULL, 16); \ 71 name[cpu] = simple_strtoull(buf, NULL, 16); \
@@ -76,7 +78,8 @@ show(call_start)
76 * processor. The cpu number in driver is only used for storing data. 78 * processor. The cpu number in driver is only used for storing data.
77 */ 79 */
78static ssize_t 80static ssize_t
79store_call_start(struct sys_device *dev, const char *buf, size_t size) 81store_call_start(struct sys_device *dev, struct sysdev_attribute *attr,
82 const char *buf, size_t size)
80{ 83{
81 unsigned int cpu=dev->id; 84 unsigned int cpu=dev->id;
82 unsigned long call_start = simple_strtoull(buf, NULL, 16); 85 unsigned long call_start = simple_strtoull(buf, NULL, 16);
@@ -124,14 +127,16 @@ show(err_type_info)
124store(err_type_info) 127store(err_type_info)
125 128
126static ssize_t 129static ssize_t
127show_virtual_to_phys(struct sys_device *dev, char *buf) 130show_virtual_to_phys(struct sys_device *dev, struct sysdev_attribute *attr,
131 char *buf)
128{ 132{
129 unsigned int cpu=dev->id; 133 unsigned int cpu=dev->id;
130 return sprintf(buf, "%lx\n", phys_addr[cpu]); 134 return sprintf(buf, "%lx\n", phys_addr[cpu]);
131} 135}
132 136
133static ssize_t 137static ssize_t
134store_virtual_to_phys(struct sys_device *dev, const char *buf, size_t size) 138store_virtual_to_phys(struct sys_device *dev, struct sysdev_attribute *attr,
139 const char *buf, size_t size)
135{ 140{
136 unsigned int cpu=dev->id; 141 unsigned int cpu=dev->id;
137 u64 virt_addr=simple_strtoull(buf, NULL, 16); 142 u64 virt_addr=simple_strtoull(buf, NULL, 16);
@@ -154,7 +159,8 @@ show(err_struct_info)
154store(err_struct_info) 159store(err_struct_info)
155 160
156static ssize_t 161static ssize_t
157show_err_data_buffer(struct sys_device *dev, char *buf) 162show_err_data_buffer(struct sys_device *dev,
163 struct sysdev_attribute *attr, char *buf)
158{ 164{
159 unsigned int cpu=dev->id; 165 unsigned int cpu=dev->id;
160 166
@@ -165,7 +171,9 @@ show_err_data_buffer(struct sys_device *dev, char *buf)
165} 171}
166 172
167static ssize_t 173static ssize_t
168store_err_data_buffer(struct sys_device *dev, const char *buf, size_t size) 174store_err_data_buffer(struct sys_device *dev,
175 struct sysdev_attribute *attr,
176 const char *buf, size_t size)
169{ 177{
170 unsigned int cpu=dev->id; 178 unsigned int cpu=dev->id;
171 int ret; 179 int ret;
diff --git a/arch/ia64/kernel/head.S b/arch/ia64/kernel/head.S
index ddeab4e36fd5..db540e58c783 100644
--- a/arch/ia64/kernel/head.S
+++ b/arch/ia64/kernel/head.S
@@ -26,11 +26,14 @@
26#include <asm/mmu_context.h> 26#include <asm/mmu_context.h>
27#include <asm/asm-offsets.h> 27#include <asm/asm-offsets.h>
28#include <asm/pal.h> 28#include <asm/pal.h>
29#include <asm/paravirt.h>
29#include <asm/pgtable.h> 30#include <asm/pgtable.h>
30#include <asm/processor.h> 31#include <asm/processor.h>
31#include <asm/ptrace.h> 32#include <asm/ptrace.h>
32#include <asm/system.h> 33#include <asm/system.h>
33#include <asm/mca_asm.h> 34#include <asm/mca_asm.h>
35#include <linux/init.h>
36#include <linux/linkage.h>
34 37
35#ifdef CONFIG_HOTPLUG_CPU 38#ifdef CONFIG_HOTPLUG_CPU
36#define SAL_PSR_BITS_TO_SET \ 39#define SAL_PSR_BITS_TO_SET \
@@ -367,6 +370,44 @@ start_ap:
367 ;; 370 ;;
368(isBP) st8 [r2]=r28 // save the address of the boot param area passed by the bootloader 371(isBP) st8 [r2]=r28 // save the address of the boot param area passed by the bootloader
369 372
373#ifdef CONFIG_PARAVIRT
374
375 movl r14=hypervisor_setup_hooks
376 movl r15=hypervisor_type
377 mov r16=num_hypervisor_hooks
378 ;;
379 ld8 r2=[r15]
380 ;;
381 cmp.ltu p7,p0=r2,r16 // array size check
382 shladd r8=r2,3,r14
383 ;;
384(p7) ld8 r9=[r8]
385 ;;
386(p7) mov b1=r9
387(p7) cmp.ne.unc p7,p0=r9,r0 // no actual branch to NULL
388 ;;
389(p7) br.call.sptk.many rp=b1
390
391 __INITDATA
392
393default_setup_hook = 0 // Currently nothing needs to be done.
394
395 .weak xen_setup_hook
396
397 .global hypervisor_type
398hypervisor_type:
399 data8 PARAVIRT_HYPERVISOR_TYPE_DEFAULT
400
401 // must have the same order with PARAVIRT_HYPERVISOR_TYPE_xxx
402
403hypervisor_setup_hooks:
404 data8 default_setup_hook
405 data8 xen_setup_hook
406num_hypervisor_hooks = (. - hypervisor_setup_hooks) / 8
407 .previous
408
409#endif
410
370#ifdef CONFIG_SMP 411#ifdef CONFIG_SMP
371(isAP) br.call.sptk.many rp=start_secondary 412(isAP) br.call.sptk.many rp=start_secondary
372.ret0: 413.ret0:
diff --git a/arch/ia64/kernel/iosapic.c b/arch/ia64/kernel/iosapic.c
index 39752cdef6ff..3bc2fa64f87f 100644
--- a/arch/ia64/kernel/iosapic.c
+++ b/arch/ia64/kernel/iosapic.c
@@ -585,6 +585,15 @@ static inline int irq_is_shared (int irq)
585 return (iosapic_intr_info[irq].count > 1); 585 return (iosapic_intr_info[irq].count > 1);
586} 586}
587 587
588struct irq_chip*
589ia64_native_iosapic_get_irq_chip(unsigned long trigger)
590{
591 if (trigger == IOSAPIC_EDGE)
592 return &irq_type_iosapic_edge;
593 else
594 return &irq_type_iosapic_level;
595}
596
588static int 597static int
589register_intr (unsigned int gsi, int irq, unsigned char delivery, 598register_intr (unsigned int gsi, int irq, unsigned char delivery,
590 unsigned long polarity, unsigned long trigger) 599 unsigned long polarity, unsigned long trigger)
@@ -635,13 +644,10 @@ register_intr (unsigned int gsi, int irq, unsigned char delivery,
635 iosapic_intr_info[irq].dmode = delivery; 644 iosapic_intr_info[irq].dmode = delivery;
636 iosapic_intr_info[irq].trigger = trigger; 645 iosapic_intr_info[irq].trigger = trigger;
637 646
638 if (trigger == IOSAPIC_EDGE) 647 irq_type = iosapic_get_irq_chip(trigger);
639 irq_type = &irq_type_iosapic_edge;
640 else
641 irq_type = &irq_type_iosapic_level;
642 648
643 idesc = irq_desc + irq; 649 idesc = irq_desc + irq;
644 if (idesc->chip != irq_type) { 650 if (irq_type != NULL && idesc->chip != irq_type) {
645 if (idesc->chip != &no_irq_type) 651 if (idesc->chip != &no_irq_type)
646 printk(KERN_WARNING 652 printk(KERN_WARNING
647 "%s: changing vector %d from %s to %s\n", 653 "%s: changing vector %d from %s to %s\n",
@@ -974,6 +980,22 @@ iosapic_override_isa_irq (unsigned int isa_irq, unsigned int gsi,
974} 980}
975 981
976void __init 982void __init
983ia64_native_iosapic_pcat_compat_init(void)
984{
985 if (pcat_compat) {
986 /*
987 * Disable the compatibility mode interrupts (8259 style),
988 * needs IN/OUT support enabled.
989 */
990 printk(KERN_INFO
991 "%s: Disabling PC-AT compatible 8259 interrupts\n",
992 __func__);
993 outb(0xff, 0xA1);
994 outb(0xff, 0x21);
995 }
996}
997
998void __init
977iosapic_system_init (int system_pcat_compat) 999iosapic_system_init (int system_pcat_compat)
978{ 1000{
979 int irq; 1001 int irq;
@@ -987,17 +1009,8 @@ iosapic_system_init (int system_pcat_compat)
987 } 1009 }
988 1010
989 pcat_compat = system_pcat_compat; 1011 pcat_compat = system_pcat_compat;
990 if (pcat_compat) { 1012 if (pcat_compat)
991 /* 1013 iosapic_pcat_compat_init();
992 * Disable the compatibility mode interrupts (8259 style),
993 * needs IN/OUT support enabled.
994 */
995 printk(KERN_INFO
996 "%s: Disabling PC-AT compatible 8259 interrupts\n",
997 __func__);
998 outb(0xff, 0xA1);
999 outb(0xff, 0x21);
1000 }
1001} 1014}
1002 1015
1003static inline int 1016static inline int
diff --git a/arch/ia64/kernel/irq_ia64.c b/arch/ia64/kernel/irq_ia64.c
index 5538471e8d68..28d3d483db92 100644
--- a/arch/ia64/kernel/irq_ia64.c
+++ b/arch/ia64/kernel/irq_ia64.c
@@ -196,7 +196,7 @@ static void clear_irq_vector(int irq)
196} 196}
197 197
198int 198int
199assign_irq_vector (int irq) 199ia64_native_assign_irq_vector (int irq)
200{ 200{
201 unsigned long flags; 201 unsigned long flags;
202 int vector, cpu; 202 int vector, cpu;
@@ -222,7 +222,7 @@ assign_irq_vector (int irq)
222} 222}
223 223
224void 224void
225free_irq_vector (int vector) 225ia64_native_free_irq_vector (int vector)
226{ 226{
227 if (vector < IA64_FIRST_DEVICE_VECTOR || 227 if (vector < IA64_FIRST_DEVICE_VECTOR ||
228 vector > IA64_LAST_DEVICE_VECTOR) 228 vector > IA64_LAST_DEVICE_VECTOR)
@@ -600,7 +600,6 @@ static irqreturn_t dummy_handler (int irq, void *dev_id)
600{ 600{
601 BUG(); 601 BUG();
602} 602}
603extern irqreturn_t handle_IPI (int irq, void *dev_id);
604 603
605static struct irqaction ipi_irqaction = { 604static struct irqaction ipi_irqaction = {
606 .handler = handle_IPI, 605 .handler = handle_IPI,
@@ -623,7 +622,7 @@ static struct irqaction tlb_irqaction = {
623#endif 622#endif
624 623
625void 624void
626register_percpu_irq (ia64_vector vec, struct irqaction *action) 625ia64_native_register_percpu_irq (ia64_vector vec, struct irqaction *action)
627{ 626{
628 irq_desc_t *desc; 627 irq_desc_t *desc;
629 unsigned int irq; 628 unsigned int irq;
@@ -638,13 +637,21 @@ register_percpu_irq (ia64_vector vec, struct irqaction *action)
638} 637}
639 638
640void __init 639void __init
641init_IRQ (void) 640ia64_native_register_ipi(void)
642{ 641{
643 register_percpu_irq(IA64_SPURIOUS_INT_VECTOR, NULL);
644#ifdef CONFIG_SMP 642#ifdef CONFIG_SMP
645 register_percpu_irq(IA64_IPI_VECTOR, &ipi_irqaction); 643 register_percpu_irq(IA64_IPI_VECTOR, &ipi_irqaction);
646 register_percpu_irq(IA64_IPI_RESCHEDULE, &resched_irqaction); 644 register_percpu_irq(IA64_IPI_RESCHEDULE, &resched_irqaction);
647 register_percpu_irq(IA64_IPI_LOCAL_TLB_FLUSH, &tlb_irqaction); 645 register_percpu_irq(IA64_IPI_LOCAL_TLB_FLUSH, &tlb_irqaction);
646#endif
647}
648
649void __init
650init_IRQ (void)
651{
652 ia64_register_ipi();
653 register_percpu_irq(IA64_SPURIOUS_INT_VECTOR, NULL);
654#ifdef CONFIG_SMP
648#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_DIG) 655#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_DIG)
649 if (vector_domain_type != VECTOR_DOMAIN_NONE) { 656 if (vector_domain_type != VECTOR_DOMAIN_NONE) {
650 BUG_ON(IA64_FIRST_DEVICE_VECTOR != IA64_IRQ_MOVE_VECTOR); 657 BUG_ON(IA64_FIRST_DEVICE_VECTOR != IA64_IRQ_MOVE_VECTOR);
diff --git a/arch/ia64/kernel/ivt.S b/arch/ia64/kernel/ivt.S
index 80b44ea052d7..c39627df3cde 100644
--- a/arch/ia64/kernel/ivt.S
+++ b/arch/ia64/kernel/ivt.S
@@ -12,6 +12,14 @@
12 * 12 *
13 * 00/08/23 Asit Mallick <asit.k.mallick@intel.com> TLB handling for SMP 13 * 00/08/23 Asit Mallick <asit.k.mallick@intel.com> TLB handling for SMP
14 * 00/12/20 David Mosberger-Tang <davidm@hpl.hp.com> DTLB/ITLB handler now uses virtual PT. 14 * 00/12/20 David Mosberger-Tang <davidm@hpl.hp.com> DTLB/ITLB handler now uses virtual PT.
15 *
16 * Copyright (C) 2005 Hewlett-Packard Co
17 * Dan Magenheimer <dan.magenheimer@hp.com>
18 * Xen paravirtualization
19 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
20 * VA Linux Systems Japan K.K.
21 * pv_ops.
22 * Yaozu (Eddie) Dong <eddie.dong@intel.com>
15 */ 23 */
16/* 24/*
17 * This file defines the interruption vector table used by the CPU. 25 * This file defines the interruption vector table used by the CPU.
@@ -102,13 +110,13 @@ ENTRY(vhpt_miss)
102 * - the faulting virtual address uses unimplemented address bits 110 * - the faulting virtual address uses unimplemented address bits
103 * - the faulting virtual address has no valid page table mapping 111 * - the faulting virtual address has no valid page table mapping
104 */ 112 */
105 mov r16=cr.ifa // get address that caused the TLB miss 113 MOV_FROM_IFA(r16) // get address that caused the TLB miss
106#ifdef CONFIG_HUGETLB_PAGE 114#ifdef CONFIG_HUGETLB_PAGE
107 movl r18=PAGE_SHIFT 115 movl r18=PAGE_SHIFT
108 mov r25=cr.itir 116 MOV_FROM_ITIR(r25)
109#endif 117#endif
110 ;; 118 ;;
111 rsm psr.dt // use physical addressing for data 119 RSM_PSR_DT // use physical addressing for data
112 mov r31=pr // save the predicate registers 120 mov r31=pr // save the predicate registers
113 mov r19=IA64_KR(PT_BASE) // get page table base address 121 mov r19=IA64_KR(PT_BASE) // get page table base address
114 shl r21=r16,3 // shift bit 60 into sign bit 122 shl r21=r16,3 // shift bit 60 into sign bit
@@ -168,21 +176,21 @@ ENTRY(vhpt_miss)
168 dep r21=r19,r20,3,(PAGE_SHIFT-3) // r21=pte_offset(pmd,addr) 176 dep r21=r19,r20,3,(PAGE_SHIFT-3) // r21=pte_offset(pmd,addr)
169 ;; 177 ;;
170(p7) ld8 r18=[r21] // read *pte 178(p7) ld8 r18=[r21] // read *pte
171 mov r19=cr.isr // cr.isr bit 32 tells us if this is an insn miss 179 MOV_FROM_ISR(r19) // cr.isr bit 32 tells us if this is an insn miss
172 ;; 180 ;;
173(p7) tbit.z p6,p7=r18,_PAGE_P_BIT // page present bit cleared? 181(p7) tbit.z p6,p7=r18,_PAGE_P_BIT // page present bit cleared?
174 mov r22=cr.iha // get the VHPT address that caused the TLB miss 182 MOV_FROM_IHA(r22) // get the VHPT address that caused the TLB miss
175 ;; // avoid RAW on p7 183 ;; // avoid RAW on p7
176(p7) tbit.nz.unc p10,p11=r19,32 // is it an instruction TLB miss? 184(p7) tbit.nz.unc p10,p11=r19,32 // is it an instruction TLB miss?
177 dep r23=0,r20,0,PAGE_SHIFT // clear low bits to get page address 185 dep r23=0,r20,0,PAGE_SHIFT // clear low bits to get page address
178 ;; 186 ;;
179(p10) itc.i r18 // insert the instruction TLB entry 187 ITC_I_AND_D(p10, p11, r18, r24) // insert the instruction TLB entry and
180(p11) itc.d r18 // insert the data TLB entry 188 // insert the data TLB entry
181(p6) br.cond.spnt.many page_fault // handle bad address/page not present (page fault) 189(p6) br.cond.spnt.many page_fault // handle bad address/page not present (page fault)
182 mov cr.ifa=r22 190 MOV_TO_IFA(r22, r24)
183 191
184#ifdef CONFIG_HUGETLB_PAGE 192#ifdef CONFIG_HUGETLB_PAGE
185(p8) mov cr.itir=r25 // change to default page-size for VHPT 193 MOV_TO_ITIR(p8, r25, r24) // change to default page-size for VHPT
186#endif 194#endif
187 195
188 /* 196 /*
@@ -192,7 +200,7 @@ ENTRY(vhpt_miss)
192 */ 200 */
193 adds r24=__DIRTY_BITS_NO_ED|_PAGE_PL_0|_PAGE_AR_RW,r23 201 adds r24=__DIRTY_BITS_NO_ED|_PAGE_PL_0|_PAGE_AR_RW,r23
194 ;; 202 ;;
195(p7) itc.d r24 203 ITC_D(p7, r24, r25)
196 ;; 204 ;;
197#ifdef CONFIG_SMP 205#ifdef CONFIG_SMP
198 /* 206 /*
@@ -234,7 +242,7 @@ ENTRY(vhpt_miss)
234#endif 242#endif
235 243
236 mov pr=r31,-1 // restore predicate registers 244 mov pr=r31,-1 // restore predicate registers
237 rfi 245 RFI
238END(vhpt_miss) 246END(vhpt_miss)
239 247
240 .org ia64_ivt+0x400 248 .org ia64_ivt+0x400
@@ -248,11 +256,11 @@ ENTRY(itlb_miss)
248 * mode, walk the page table, and then re-execute the PTE read and 256 * mode, walk the page table, and then re-execute the PTE read and
249 * go on normally after that. 257 * go on normally after that.
250 */ 258 */
251 mov r16=cr.ifa // get virtual address 259 MOV_FROM_IFA(r16) // get virtual address
252 mov r29=b0 // save b0 260 mov r29=b0 // save b0
253 mov r31=pr // save predicates 261 mov r31=pr // save predicates
254.itlb_fault: 262.itlb_fault:
255 mov r17=cr.iha // get virtual address of PTE 263 MOV_FROM_IHA(r17) // get virtual address of PTE
256 movl r30=1f // load nested fault continuation point 264 movl r30=1f // load nested fault continuation point
257 ;; 265 ;;
2581: ld8 r18=[r17] // read *pte 2661: ld8 r18=[r17] // read *pte
@@ -261,7 +269,7 @@ ENTRY(itlb_miss)
261 tbit.z p6,p0=r18,_PAGE_P_BIT // page present bit cleared? 269 tbit.z p6,p0=r18,_PAGE_P_BIT // page present bit cleared?
262(p6) br.cond.spnt page_fault 270(p6) br.cond.spnt page_fault
263 ;; 271 ;;
264 itc.i r18 272 ITC_I(p0, r18, r19)
265 ;; 273 ;;
266#ifdef CONFIG_SMP 274#ifdef CONFIG_SMP
267 /* 275 /*
@@ -278,7 +286,7 @@ ENTRY(itlb_miss)
278(p7) ptc.l r16,r20 286(p7) ptc.l r16,r20
279#endif 287#endif
280 mov pr=r31,-1 288 mov pr=r31,-1
281 rfi 289 RFI
282END(itlb_miss) 290END(itlb_miss)
283 291
284 .org ia64_ivt+0x0800 292 .org ia64_ivt+0x0800
@@ -292,11 +300,11 @@ ENTRY(dtlb_miss)
292 * mode, walk the page table, and then re-execute the PTE read and 300 * mode, walk the page table, and then re-execute the PTE read and
293 * go on normally after that. 301 * go on normally after that.
294 */ 302 */
295 mov r16=cr.ifa // get virtual address 303 MOV_FROM_IFA(r16) // get virtual address
296 mov r29=b0 // save b0 304 mov r29=b0 // save b0
297 mov r31=pr // save predicates 305 mov r31=pr // save predicates
298dtlb_fault: 306dtlb_fault:
299 mov r17=cr.iha // get virtual address of PTE 307 MOV_FROM_IHA(r17) // get virtual address of PTE
300 movl r30=1f // load nested fault continuation point 308 movl r30=1f // load nested fault continuation point
301 ;; 309 ;;
3021: ld8 r18=[r17] // read *pte 3101: ld8 r18=[r17] // read *pte
@@ -305,7 +313,7 @@ dtlb_fault:
305 tbit.z p6,p0=r18,_PAGE_P_BIT // page present bit cleared? 313 tbit.z p6,p0=r18,_PAGE_P_BIT // page present bit cleared?
306(p6) br.cond.spnt page_fault 314(p6) br.cond.spnt page_fault
307 ;; 315 ;;
308 itc.d r18 316 ITC_D(p0, r18, r19)
309 ;; 317 ;;
310#ifdef CONFIG_SMP 318#ifdef CONFIG_SMP
311 /* 319 /*
@@ -322,7 +330,7 @@ dtlb_fault:
322(p7) ptc.l r16,r20 330(p7) ptc.l r16,r20
323#endif 331#endif
324 mov pr=r31,-1 332 mov pr=r31,-1
325 rfi 333 RFI
326END(dtlb_miss) 334END(dtlb_miss)
327 335
328 .org ia64_ivt+0x0c00 336 .org ia64_ivt+0x0c00
@@ -330,9 +338,9 @@ END(dtlb_miss)
330// 0x0c00 Entry 3 (size 64 bundles) Alt ITLB (19) 338// 0x0c00 Entry 3 (size 64 bundles) Alt ITLB (19)
331ENTRY(alt_itlb_miss) 339ENTRY(alt_itlb_miss)
332 DBG_FAULT(3) 340 DBG_FAULT(3)
333 mov r16=cr.ifa // get address that caused the TLB miss 341 MOV_FROM_IFA(r16) // get address that caused the TLB miss
334 movl r17=PAGE_KERNEL 342 movl r17=PAGE_KERNEL
335 mov r21=cr.ipsr 343 MOV_FROM_IPSR(p0, r21)
336 movl r19=(((1 << IA64_MAX_PHYS_BITS) - 1) & ~0xfff) 344 movl r19=(((1 << IA64_MAX_PHYS_BITS) - 1) & ~0xfff)
337 mov r31=pr 345 mov r31=pr
338 ;; 346 ;;
@@ -341,9 +349,9 @@ ENTRY(alt_itlb_miss)
341 ;; 349 ;;
342 cmp.gt p8,p0=6,r22 // user mode 350 cmp.gt p8,p0=6,r22 // user mode
343 ;; 351 ;;
344(p8) thash r17=r16 352 THASH(p8, r17, r16, r23)
345 ;; 353 ;;
346(p8) mov cr.iha=r17 354 MOV_TO_IHA(p8, r17, r23)
347(p8) mov r29=b0 // save b0 355(p8) mov r29=b0 // save b0
348(p8) br.cond.dptk .itlb_fault 356(p8) br.cond.dptk .itlb_fault
349#endif 357#endif
@@ -358,9 +366,9 @@ ENTRY(alt_itlb_miss)
358 or r19=r19,r18 // set bit 4 (uncached) if the access was to region 6 366 or r19=r19,r18 // set bit 4 (uncached) if the access was to region 6
359(p8) br.cond.spnt page_fault 367(p8) br.cond.spnt page_fault
360 ;; 368 ;;
361 itc.i r19 // insert the TLB entry 369 ITC_I(p0, r19, r18) // insert the TLB entry
362 mov pr=r31,-1 370 mov pr=r31,-1
363 rfi 371 RFI
364END(alt_itlb_miss) 372END(alt_itlb_miss)
365 373
366 .org ia64_ivt+0x1000 374 .org ia64_ivt+0x1000
@@ -368,11 +376,11 @@ END(alt_itlb_miss)
368// 0x1000 Entry 4 (size 64 bundles) Alt DTLB (7,46) 376// 0x1000 Entry 4 (size 64 bundles) Alt DTLB (7,46)
369ENTRY(alt_dtlb_miss) 377ENTRY(alt_dtlb_miss)
370 DBG_FAULT(4) 378 DBG_FAULT(4)
371 mov r16=cr.ifa // get address that caused the TLB miss 379 MOV_FROM_IFA(r16) // get address that caused the TLB miss
372 movl r17=PAGE_KERNEL 380 movl r17=PAGE_KERNEL
373 mov r20=cr.isr 381 MOV_FROM_ISR(r20)
374 movl r19=(((1 << IA64_MAX_PHYS_BITS) - 1) & ~0xfff) 382 movl r19=(((1 << IA64_MAX_PHYS_BITS) - 1) & ~0xfff)
375 mov r21=cr.ipsr 383 MOV_FROM_IPSR(p0, r21)
376 mov r31=pr 384 mov r31=pr
377 mov r24=PERCPU_ADDR 385 mov r24=PERCPU_ADDR
378 ;; 386 ;;
@@ -381,9 +389,9 @@ ENTRY(alt_dtlb_miss)
381 ;; 389 ;;
382 cmp.gt p8,p0=6,r22 // access to region 0-5 390 cmp.gt p8,p0=6,r22 // access to region 0-5
383 ;; 391 ;;
384(p8) thash r17=r16 392 THASH(p8, r17, r16, r25)
385 ;; 393 ;;
386(p8) mov cr.iha=r17 394 MOV_TO_IHA(p8, r17, r25)
387(p8) mov r29=b0 // save b0 395(p8) mov r29=b0 // save b0
388(p8) br.cond.dptk dtlb_fault 396(p8) br.cond.dptk dtlb_fault
389#endif 397#endif
@@ -402,7 +410,7 @@ ENTRY(alt_dtlb_miss)
402 tbit.nz p9,p0=r20,IA64_ISR_NA_BIT // is non-access bit on? 410 tbit.nz p9,p0=r20,IA64_ISR_NA_BIT // is non-access bit on?
403 ;; 411 ;;
404(p10) sub r19=r19,r26 412(p10) sub r19=r19,r26
405(p10) mov cr.itir=r25 413 MOV_TO_ITIR(p10, r25, r24)
406 cmp.ne p8,p0=r0,r23 414 cmp.ne p8,p0=r0,r23
407(p9) cmp.eq.or.andcm p6,p7=IA64_ISR_CODE_LFETCH,r22 // check isr.code field 415(p9) cmp.eq.or.andcm p6,p7=IA64_ISR_CODE_LFETCH,r22 // check isr.code field
408(p12) dep r17=-1,r17,4,1 // set ma=UC for region 6 addr 416(p12) dep r17=-1,r17,4,1 // set ma=UC for region 6 addr
@@ -411,11 +419,11 @@ ENTRY(alt_dtlb_miss)
411 dep r21=-1,r21,IA64_PSR_ED_BIT,1 419 dep r21=-1,r21,IA64_PSR_ED_BIT,1
412 ;; 420 ;;
413 or r19=r19,r17 // insert PTE control bits into r19 421 or r19=r19,r17 // insert PTE control bits into r19
414(p6) mov cr.ipsr=r21 422 MOV_TO_IPSR(p6, r21, r24)
415 ;; 423 ;;
416(p7) itc.d r19 // insert the TLB entry 424 ITC_D(p7, r19, r18) // insert the TLB entry
417 mov pr=r31,-1 425 mov pr=r31,-1
418 rfi 426 RFI
419END(alt_dtlb_miss) 427END(alt_dtlb_miss)
420 428
421 .org ia64_ivt+0x1400 429 .org ia64_ivt+0x1400
@@ -444,10 +452,10 @@ ENTRY(nested_dtlb_miss)
444 * 452 *
445 * Clobbered: b0, r18, r19, r21, r22, psr.dt (cleared) 453 * Clobbered: b0, r18, r19, r21, r22, psr.dt (cleared)
446 */ 454 */
447 rsm psr.dt // switch to using physical data addressing 455 RSM_PSR_DT // switch to using physical data addressing
448 mov r19=IA64_KR(PT_BASE) // get the page table base address 456 mov r19=IA64_KR(PT_BASE) // get the page table base address
449 shl r21=r16,3 // shift bit 60 into sign bit 457 shl r21=r16,3 // shift bit 60 into sign bit
450 mov r18=cr.itir 458 MOV_FROM_ITIR(r18)
451 ;; 459 ;;
452 shr.u r17=r16,61 // get the region number into r17 460 shr.u r17=r16,61 // get the region number into r17
453 extr.u r18=r18,2,6 // get the faulting page size 461 extr.u r18=r18,2,6 // get the faulting page size
@@ -507,33 +515,6 @@ ENTRY(ikey_miss)
507 FAULT(6) 515 FAULT(6)
508END(ikey_miss) 516END(ikey_miss)
509 517
510 //-----------------------------------------------------------------------------------
511 // call do_page_fault (predicates are in r31, psr.dt may be off, r16 is faulting address)
512ENTRY(page_fault)
513 ssm psr.dt
514 ;;
515 srlz.i
516 ;;
517 SAVE_MIN_WITH_COVER
518 alloc r15=ar.pfs,0,0,3,0
519 mov out0=cr.ifa
520 mov out1=cr.isr
521 adds r3=8,r2 // set up second base pointer
522 ;;
523 ssm psr.ic | PSR_DEFAULT_BITS
524 ;;
525 srlz.i // guarantee that interruption collectin is on
526 ;;
527(p15) ssm psr.i // restore psr.i
528 movl r14=ia64_leave_kernel
529 ;;
530 SAVE_REST
531 mov rp=r14
532 ;;
533 adds out2=16,r12 // out2 = pointer to pt_regs
534 br.call.sptk.many b6=ia64_do_page_fault // ignore return address
535END(page_fault)
536
537 .org ia64_ivt+0x1c00 518 .org ia64_ivt+0x1c00
538///////////////////////////////////////////////////////////////////////////////////////// 519/////////////////////////////////////////////////////////////////////////////////////////
539// 0x1c00 Entry 7 (size 64 bundles) Data Key Miss (12,51) 520// 0x1c00 Entry 7 (size 64 bundles) Data Key Miss (12,51)
@@ -556,10 +537,10 @@ ENTRY(dirty_bit)
556 * page table TLB entry isn't present, we take a nested TLB miss hit where we look 537 * page table TLB entry isn't present, we take a nested TLB miss hit where we look
557 * up the physical address of the L3 PTE and then continue at label 1 below. 538 * up the physical address of the L3 PTE and then continue at label 1 below.
558 */ 539 */
559 mov r16=cr.ifa // get the address that caused the fault 540 MOV_FROM_IFA(r16) // get the address that caused the fault
560 movl r30=1f // load continuation point in case of nested fault 541 movl r30=1f // load continuation point in case of nested fault
561 ;; 542 ;;
562 thash r17=r16 // compute virtual address of L3 PTE 543 THASH(p0, r17, r16, r18) // compute virtual address of L3 PTE
563 mov r29=b0 // save b0 in case of nested fault 544 mov r29=b0 // save b0 in case of nested fault
564 mov r31=pr // save pr 545 mov r31=pr // save pr
565#ifdef CONFIG_SMP 546#ifdef CONFIG_SMP
@@ -576,7 +557,7 @@ ENTRY(dirty_bit)
576 ;; 557 ;;
577(p6) cmp.eq p6,p7=r26,r18 // Only compare if page is present 558(p6) cmp.eq p6,p7=r26,r18 // Only compare if page is present
578 ;; 559 ;;
579(p6) itc.d r25 // install updated PTE 560 ITC_D(p6, r25, r18) // install updated PTE
580 ;; 561 ;;
581 /* 562 /*
582 * Tell the assemblers dependency-violation checker that the above "itc" instructions 563 * Tell the assemblers dependency-violation checker that the above "itc" instructions
@@ -602,7 +583,7 @@ ENTRY(dirty_bit)
602 itc.d r18 // install updated PTE 583 itc.d r18 // install updated PTE
603#endif 584#endif
604 mov pr=r31,-1 // restore pr 585 mov pr=r31,-1 // restore pr
605 rfi 586 RFI
606END(dirty_bit) 587END(dirty_bit)
607 588
608 .org ia64_ivt+0x2400 589 .org ia64_ivt+0x2400
@@ -611,22 +592,22 @@ END(dirty_bit)
611ENTRY(iaccess_bit) 592ENTRY(iaccess_bit)
612 DBG_FAULT(9) 593 DBG_FAULT(9)
613 // Like Entry 8, except for instruction access 594 // Like Entry 8, except for instruction access
614 mov r16=cr.ifa // get the address that caused the fault 595 MOV_FROM_IFA(r16) // get the address that caused the fault
615 movl r30=1f // load continuation point in case of nested fault 596 movl r30=1f // load continuation point in case of nested fault
616 mov r31=pr // save predicates 597 mov r31=pr // save predicates
617#ifdef CONFIG_ITANIUM 598#ifdef CONFIG_ITANIUM
618 /* 599 /*
619 * Erratum 10 (IFA may contain incorrect address) has "NoFix" status. 600 * Erratum 10 (IFA may contain incorrect address) has "NoFix" status.
620 */ 601 */
621 mov r17=cr.ipsr 602 MOV_FROM_IPSR(p0, r17)
622 ;; 603 ;;
623 mov r18=cr.iip 604 MOV_FROM_IIP(r18)
624 tbit.z p6,p0=r17,IA64_PSR_IS_BIT // IA64 instruction set? 605 tbit.z p6,p0=r17,IA64_PSR_IS_BIT // IA64 instruction set?
625 ;; 606 ;;
626(p6) mov r16=r18 // if so, use cr.iip instead of cr.ifa 607(p6) mov r16=r18 // if so, use cr.iip instead of cr.ifa
627#endif /* CONFIG_ITANIUM */ 608#endif /* CONFIG_ITANIUM */
628 ;; 609 ;;
629 thash r17=r16 // compute virtual address of L3 PTE 610 THASH(p0, r17, r16, r18) // compute virtual address of L3 PTE
630 mov r29=b0 // save b0 in case of nested fault) 611 mov r29=b0 // save b0 in case of nested fault)
631#ifdef CONFIG_SMP 612#ifdef CONFIG_SMP
632 mov r28=ar.ccv // save ar.ccv 613 mov r28=ar.ccv // save ar.ccv
@@ -642,7 +623,7 @@ ENTRY(iaccess_bit)
642 ;; 623 ;;
643(p6) cmp.eq p6,p7=r26,r18 // Only if page present 624(p6) cmp.eq p6,p7=r26,r18 // Only if page present
644 ;; 625 ;;
645(p6) itc.i r25 // install updated PTE 626 ITC_I(p6, r25, r26) // install updated PTE
646 ;; 627 ;;
647 /* 628 /*
648 * Tell the assemblers dependency-violation checker that the above "itc" instructions 629 * Tell the assemblers dependency-violation checker that the above "itc" instructions
@@ -668,7 +649,7 @@ ENTRY(iaccess_bit)
668 itc.i r18 // install updated PTE 649 itc.i r18 // install updated PTE
669#endif /* !CONFIG_SMP */ 650#endif /* !CONFIG_SMP */
670 mov pr=r31,-1 651 mov pr=r31,-1
671 rfi 652 RFI
672END(iaccess_bit) 653END(iaccess_bit)
673 654
674 .org ia64_ivt+0x2800 655 .org ia64_ivt+0x2800
@@ -677,10 +658,10 @@ END(iaccess_bit)
677ENTRY(daccess_bit) 658ENTRY(daccess_bit)
678 DBG_FAULT(10) 659 DBG_FAULT(10)
679 // Like Entry 8, except for data access 660 // Like Entry 8, except for data access
680 mov r16=cr.ifa // get the address that caused the fault 661 MOV_FROM_IFA(r16) // get the address that caused the fault
681 movl r30=1f // load continuation point in case of nested fault 662 movl r30=1f // load continuation point in case of nested fault
682 ;; 663 ;;
683 thash r17=r16 // compute virtual address of L3 PTE 664 THASH(p0, r17, r16, r18) // compute virtual address of L3 PTE
684 mov r31=pr 665 mov r31=pr
685 mov r29=b0 // save b0 in case of nested fault) 666 mov r29=b0 // save b0 in case of nested fault)
686#ifdef CONFIG_SMP 667#ifdef CONFIG_SMP
@@ -697,7 +678,7 @@ ENTRY(daccess_bit)
697 ;; 678 ;;
698(p6) cmp.eq p6,p7=r26,r18 // Only if page is present 679(p6) cmp.eq p6,p7=r26,r18 // Only if page is present
699 ;; 680 ;;
700(p6) itc.d r25 // install updated PTE 681 ITC_D(p6, r25, r26) // install updated PTE
701 /* 682 /*
702 * Tell the assemblers dependency-violation checker that the above "itc" instructions 683 * Tell the assemblers dependency-violation checker that the above "itc" instructions
703 * cannot possibly affect the following loads: 684 * cannot possibly affect the following loads:
@@ -721,7 +702,7 @@ ENTRY(daccess_bit)
721#endif 702#endif
722 mov b0=r29 // restore b0 703 mov b0=r29 // restore b0
723 mov pr=r31,-1 704 mov pr=r31,-1
724 rfi 705 RFI
725END(daccess_bit) 706END(daccess_bit)
726 707
727 .org ia64_ivt+0x2c00 708 .org ia64_ivt+0x2c00
@@ -745,10 +726,10 @@ ENTRY(break_fault)
745 */ 726 */
746 DBG_FAULT(11) 727 DBG_FAULT(11)
747 mov.m r16=IA64_KR(CURRENT) // M2 r16 <- current task (12 cyc) 728 mov.m r16=IA64_KR(CURRENT) // M2 r16 <- current task (12 cyc)
748 mov r29=cr.ipsr // M2 (12 cyc) 729 MOV_FROM_IPSR(p0, r29) // M2 (12 cyc)
749 mov r31=pr // I0 (2 cyc) 730 mov r31=pr // I0 (2 cyc)
750 731
751 mov r17=cr.iim // M2 (2 cyc) 732 MOV_FROM_IIM(r17) // M2 (2 cyc)
752 mov.m r27=ar.rsc // M2 (12 cyc) 733 mov.m r27=ar.rsc // M2 (12 cyc)
753 mov r18=__IA64_BREAK_SYSCALL // A 734 mov r18=__IA64_BREAK_SYSCALL // A
754 735
@@ -767,7 +748,7 @@ ENTRY(break_fault)
767 nop.m 0 748 nop.m 0
768 movl r30=sys_call_table // X 749 movl r30=sys_call_table // X
769 750
770 mov r28=cr.iip // M2 (2 cyc) 751 MOV_FROM_IIP(r28) // M2 (2 cyc)
771 cmp.eq p0,p7=r18,r17 // I0 is this a system call? 752 cmp.eq p0,p7=r18,r17 // I0 is this a system call?
772(p7) br.cond.spnt non_syscall // B no -> 753(p7) br.cond.spnt non_syscall // B no ->
773 // 754 //
@@ -864,18 +845,17 @@ ENTRY(break_fault)
864#endif 845#endif
865 mov ar.rsc=0x3 // M2 set eager mode, pl 0, LE, loadrs=0 846 mov ar.rsc=0x3 // M2 set eager mode, pl 0, LE, loadrs=0
866 nop 0 847 nop 0
867 bsw.1 // B (6 cyc) regs are saved, switch to bank 1 848 BSW_1(r2, r14) // B (6 cyc) regs are saved, switch to bank 1
868 ;; 849 ;;
869 850
870 ssm psr.ic | PSR_DEFAULT_BITS // M2 now it's safe to re-enable intr.-collection 851 SSM_PSR_IC_AND_DEFAULT_BITS_AND_SRLZ_I(r3, r16) // M2 now it's safe to re-enable intr.-collection
852 // M0 ensure interruption collection is on
871 movl r3=ia64_ret_from_syscall // X 853 movl r3=ia64_ret_from_syscall // X
872 ;; 854 ;;
873
874 srlz.i // M0 ensure interruption collection is on
875 mov rp=r3 // I0 set the real return addr 855 mov rp=r3 // I0 set the real return addr
876(p10) br.cond.spnt.many ia64_ret_from_syscall // B return if bad call-frame or r15 is a NaT 856(p10) br.cond.spnt.many ia64_ret_from_syscall // B return if bad call-frame or r15 is a NaT
877 857
878(p15) ssm psr.i // M2 restore psr.i 858 SSM_PSR_I(p15, p15, r16) // M2 restore psr.i
879(p14) br.call.sptk.many b6=b6 // B invoke syscall-handker (ignore return addr) 859(p14) br.call.sptk.many b6=b6 // B invoke syscall-handker (ignore return addr)
880 br.cond.spnt.many ia64_trace_syscall // B do syscall-tracing thingamagic 860 br.cond.spnt.many ia64_trace_syscall // B do syscall-tracing thingamagic
881 // NOT REACHED 861 // NOT REACHED
@@ -895,27 +875,8 @@ END(break_fault)
895///////////////////////////////////////////////////////////////////////////////////////// 875/////////////////////////////////////////////////////////////////////////////////////////
896// 0x3000 Entry 12 (size 64 bundles) External Interrupt (4) 876// 0x3000 Entry 12 (size 64 bundles) External Interrupt (4)
897ENTRY(interrupt) 877ENTRY(interrupt)
898 DBG_FAULT(12) 878 /* interrupt handler has become too big to fit this area. */
899 mov r31=pr // prepare to save predicates 879 br.sptk.many __interrupt
900 ;;
901 SAVE_MIN_WITH_COVER // uses r31; defines r2 and r3
902 ssm psr.ic | PSR_DEFAULT_BITS
903 ;;
904 adds r3=8,r2 // set up second base pointer for SAVE_REST
905 srlz.i // ensure everybody knows psr.ic is back on
906 ;;
907 SAVE_REST
908 ;;
909 MCA_RECOVER_RANGE(interrupt)
910 alloc r14=ar.pfs,0,0,2,0 // must be first in an insn group
911 mov out0=cr.ivr // pass cr.ivr as first arg
912 add out1=16,sp // pass pointer to pt_regs as second arg
913 ;;
914 srlz.d // make sure we see the effect of cr.ivr
915 movl r14=ia64_leave_kernel
916 ;;
917 mov rp=r14
918 br.call.sptk.many b6=ia64_handle_irq
919END(interrupt) 880END(interrupt)
920 881
921 .org ia64_ivt+0x3400 882 .org ia64_ivt+0x3400
@@ -978,6 +939,7 @@ END(interrupt)
978 * - ar.fpsr: set to kernel settings 939 * - ar.fpsr: set to kernel settings
979 * - b6: preserved (same as on entry) 940 * - b6: preserved (same as on entry)
980 */ 941 */
942#ifdef __IA64_ASM_PARAVIRTUALIZED_NATIVE
981GLOBAL_ENTRY(ia64_syscall_setup) 943GLOBAL_ENTRY(ia64_syscall_setup)
982#if PT(B6) != 0 944#if PT(B6) != 0
983# error This code assumes that b6 is the first field in pt_regs. 945# error This code assumes that b6 is the first field in pt_regs.
@@ -1069,6 +1031,7 @@ GLOBAL_ENTRY(ia64_syscall_setup)
1069(p10) mov r8=-EINVAL 1031(p10) mov r8=-EINVAL
1070 br.ret.sptk.many b7 1032 br.ret.sptk.many b7
1071END(ia64_syscall_setup) 1033END(ia64_syscall_setup)
1034#endif /* __IA64_ASM_PARAVIRTUALIZED_NATIVE */
1072 1035
1073 .org ia64_ivt+0x3c00 1036 .org ia64_ivt+0x3c00
1074///////////////////////////////////////////////////////////////////////////////////////// 1037/////////////////////////////////////////////////////////////////////////////////////////
@@ -1082,7 +1045,7 @@ END(ia64_syscall_setup)
1082 DBG_FAULT(16) 1045 DBG_FAULT(16)
1083 FAULT(16) 1046 FAULT(16)
1084 1047
1085#ifdef CONFIG_VIRT_CPU_ACCOUNTING 1048#if defined(CONFIG_VIRT_CPU_ACCOUNTING) && defined(__IA64_ASM_PARAVIRTUALIZED_NATIVE)
1086 /* 1049 /*
1087 * There is no particular reason for this code to be here, other than 1050 * There is no particular reason for this code to be here, other than
1088 * that there happens to be space here that would go unused otherwise. 1051 * that there happens to be space here that would go unused otherwise.
@@ -1092,7 +1055,7 @@ END(ia64_syscall_setup)
1092 * account_sys_enter is called from SAVE_MIN* macros if accounting is 1055 * account_sys_enter is called from SAVE_MIN* macros if accounting is
1093 * enabled and if the macro is entered from user mode. 1056 * enabled and if the macro is entered from user mode.
1094 */ 1057 */
1095ENTRY(account_sys_enter) 1058GLOBAL_ENTRY(account_sys_enter)
1096 // mov.m r20=ar.itc is called in advance, and r13 is current 1059 // mov.m r20=ar.itc is called in advance, and r13 is current
1097 add r16=TI_AC_STAMP+IA64_TASK_SIZE,r13 1060 add r16=TI_AC_STAMP+IA64_TASK_SIZE,r13
1098 add r17=TI_AC_LEAVE+IA64_TASK_SIZE,r13 1061 add r17=TI_AC_LEAVE+IA64_TASK_SIZE,r13
@@ -1123,110 +1086,18 @@ END(account_sys_enter)
1123 DBG_FAULT(17) 1086 DBG_FAULT(17)
1124 FAULT(17) 1087 FAULT(17)
1125 1088
1126ENTRY(non_syscall)
1127 mov ar.rsc=r27 // restore ar.rsc before SAVE_MIN_WITH_COVER
1128 ;;
1129 SAVE_MIN_WITH_COVER
1130
1131 // There is no particular reason for this code to be here, other than that
1132 // there happens to be space here that would go unused otherwise. If this
1133 // fault ever gets "unreserved", simply moved the following code to a more
1134 // suitable spot...
1135
1136 alloc r14=ar.pfs,0,0,2,0
1137 mov out0=cr.iim
1138 add out1=16,sp
1139 adds r3=8,r2 // set up second base pointer for SAVE_REST
1140
1141 ssm psr.ic | PSR_DEFAULT_BITS
1142 ;;
1143 srlz.i // guarantee that interruption collection is on
1144 ;;
1145(p15) ssm psr.i // restore psr.i
1146 movl r15=ia64_leave_kernel
1147 ;;
1148 SAVE_REST
1149 mov rp=r15
1150 ;;
1151 br.call.sptk.many b6=ia64_bad_break // avoid WAW on CFM and ignore return addr
1152END(non_syscall)
1153
1154 .org ia64_ivt+0x4800 1089 .org ia64_ivt+0x4800
1155///////////////////////////////////////////////////////////////////////////////////////// 1090/////////////////////////////////////////////////////////////////////////////////////////
1156// 0x4800 Entry 18 (size 64 bundles) Reserved 1091// 0x4800 Entry 18 (size 64 bundles) Reserved
1157 DBG_FAULT(18) 1092 DBG_FAULT(18)
1158 FAULT(18) 1093 FAULT(18)
1159 1094
1160 /*
1161 * There is no particular reason for this code to be here, other than that
1162 * there happens to be space here that would go unused otherwise. If this
1163 * fault ever gets "unreserved", simply moved the following code to a more
1164 * suitable spot...
1165 */
1166
1167ENTRY(dispatch_unaligned_handler)
1168 SAVE_MIN_WITH_COVER
1169 ;;
1170 alloc r14=ar.pfs,0,0,2,0 // now it's safe (must be first in insn group!)
1171 mov out0=cr.ifa
1172 adds out1=16,sp
1173
1174 ssm psr.ic | PSR_DEFAULT_BITS
1175 ;;
1176 srlz.i // guarantee that interruption collection is on
1177 ;;
1178(p15) ssm psr.i // restore psr.i
1179 adds r3=8,r2 // set up second base pointer
1180 ;;
1181 SAVE_REST
1182 movl r14=ia64_leave_kernel
1183 ;;
1184 mov rp=r14
1185 br.sptk.many ia64_prepare_handle_unaligned
1186END(dispatch_unaligned_handler)
1187
1188 .org ia64_ivt+0x4c00 1095 .org ia64_ivt+0x4c00
1189///////////////////////////////////////////////////////////////////////////////////////// 1096/////////////////////////////////////////////////////////////////////////////////////////
1190// 0x4c00 Entry 19 (size 64 bundles) Reserved 1097// 0x4c00 Entry 19 (size 64 bundles) Reserved
1191 DBG_FAULT(19) 1098 DBG_FAULT(19)
1192 FAULT(19) 1099 FAULT(19)
1193 1100
1194 /*
1195 * There is no particular reason for this code to be here, other than that
1196 * there happens to be space here that would go unused otherwise. If this
1197 * fault ever gets "unreserved", simply moved the following code to a more
1198 * suitable spot...
1199 */
1200
1201ENTRY(dispatch_to_fault_handler)
1202 /*
1203 * Input:
1204 * psr.ic: off
1205 * r19: fault vector number (e.g., 24 for General Exception)
1206 * r31: contains saved predicates (pr)
1207 */
1208 SAVE_MIN_WITH_COVER_R19
1209 alloc r14=ar.pfs,0,0,5,0
1210 mov out0=r15
1211 mov out1=cr.isr
1212 mov out2=cr.ifa
1213 mov out3=cr.iim
1214 mov out4=cr.itir
1215 ;;
1216 ssm psr.ic | PSR_DEFAULT_BITS
1217 ;;
1218 srlz.i // guarantee that interruption collection is on
1219 ;;
1220(p15) ssm psr.i // restore psr.i
1221 adds r3=8,r2 // set up second base pointer for SAVE_REST
1222 ;;
1223 SAVE_REST
1224 movl r14=ia64_leave_kernel
1225 ;;
1226 mov rp=r14
1227 br.call.sptk.many b6=ia64_fault
1228END(dispatch_to_fault_handler)
1229
1230// 1101//
1231// --- End of long entries, Beginning of short entries 1102// --- End of long entries, Beginning of short entries
1232// 1103//
@@ -1236,8 +1107,8 @@ END(dispatch_to_fault_handler)
1236// 0x5000 Entry 20 (size 16 bundles) Page Not Present (10,22,49) 1107// 0x5000 Entry 20 (size 16 bundles) Page Not Present (10,22,49)
1237ENTRY(page_not_present) 1108ENTRY(page_not_present)
1238 DBG_FAULT(20) 1109 DBG_FAULT(20)
1239 mov r16=cr.ifa 1110 MOV_FROM_IFA(r16)
1240 rsm psr.dt 1111 RSM_PSR_DT
1241 /* 1112 /*
1242 * The Linux page fault handler doesn't expect non-present pages to be in 1113 * The Linux page fault handler doesn't expect non-present pages to be in
1243 * the TLB. Flush the existing entry now, so we meet that expectation. 1114 * the TLB. Flush the existing entry now, so we meet that expectation.
@@ -1256,8 +1127,8 @@ END(page_not_present)
1256// 0x5100 Entry 21 (size 16 bundles) Key Permission (13,25,52) 1127// 0x5100 Entry 21 (size 16 bundles) Key Permission (13,25,52)
1257ENTRY(key_permission) 1128ENTRY(key_permission)
1258 DBG_FAULT(21) 1129 DBG_FAULT(21)
1259 mov r16=cr.ifa 1130 MOV_FROM_IFA(r16)
1260 rsm psr.dt 1131 RSM_PSR_DT
1261 mov r31=pr 1132 mov r31=pr
1262 ;; 1133 ;;
1263 srlz.d 1134 srlz.d
@@ -1269,8 +1140,8 @@ END(key_permission)
1269// 0x5200 Entry 22 (size 16 bundles) Instruction Access Rights (26) 1140// 0x5200 Entry 22 (size 16 bundles) Instruction Access Rights (26)
1270ENTRY(iaccess_rights) 1141ENTRY(iaccess_rights)
1271 DBG_FAULT(22) 1142 DBG_FAULT(22)
1272 mov r16=cr.ifa 1143 MOV_FROM_IFA(r16)
1273 rsm psr.dt 1144 RSM_PSR_DT
1274 mov r31=pr 1145 mov r31=pr
1275 ;; 1146 ;;
1276 srlz.d 1147 srlz.d
@@ -1282,8 +1153,8 @@ END(iaccess_rights)
1282// 0x5300 Entry 23 (size 16 bundles) Data Access Rights (14,53) 1153// 0x5300 Entry 23 (size 16 bundles) Data Access Rights (14,53)
1283ENTRY(daccess_rights) 1154ENTRY(daccess_rights)
1284 DBG_FAULT(23) 1155 DBG_FAULT(23)
1285 mov r16=cr.ifa 1156 MOV_FROM_IFA(r16)
1286 rsm psr.dt 1157 RSM_PSR_DT
1287 mov r31=pr 1158 mov r31=pr
1288 ;; 1159 ;;
1289 srlz.d 1160 srlz.d
@@ -1295,7 +1166,7 @@ END(daccess_rights)
1295// 0x5400 Entry 24 (size 16 bundles) General Exception (5,32,34,36,38,39) 1166// 0x5400 Entry 24 (size 16 bundles) General Exception (5,32,34,36,38,39)
1296ENTRY(general_exception) 1167ENTRY(general_exception)
1297 DBG_FAULT(24) 1168 DBG_FAULT(24)
1298 mov r16=cr.isr 1169 MOV_FROM_ISR(r16)
1299 mov r31=pr 1170 mov r31=pr
1300 ;; 1171 ;;
1301 cmp4.eq p6,p0=0,r16 1172 cmp4.eq p6,p0=0,r16
@@ -1324,8 +1195,8 @@ END(disabled_fp_reg)
1324ENTRY(nat_consumption) 1195ENTRY(nat_consumption)
1325 DBG_FAULT(26) 1196 DBG_FAULT(26)
1326 1197
1327 mov r16=cr.ipsr 1198 MOV_FROM_IPSR(p0, r16)
1328 mov r17=cr.isr 1199 MOV_FROM_ISR(r17)
1329 mov r31=pr // save PR 1200 mov r31=pr // save PR
1330 ;; 1201 ;;
1331 and r18=0xf,r17 // r18 = cr.ipsr.code{3:0} 1202 and r18=0xf,r17 // r18 = cr.ipsr.code{3:0}
@@ -1335,10 +1206,10 @@ ENTRY(nat_consumption)
1335 dep r16=-1,r16,IA64_PSR_ED_BIT,1 1206 dep r16=-1,r16,IA64_PSR_ED_BIT,1
1336(p6) br.cond.spnt 1f // branch if (cr.ispr.na == 0 || cr.ipsr.code{3:0} != LFETCH) 1207(p6) br.cond.spnt 1f // branch if (cr.ispr.na == 0 || cr.ipsr.code{3:0} != LFETCH)
1337 ;; 1208 ;;
1338 mov cr.ipsr=r16 // set cr.ipsr.na 1209 MOV_TO_IPSR(p0, r16, r18)
1339 mov pr=r31,-1 1210 mov pr=r31,-1
1340 ;; 1211 ;;
1341 rfi 1212 RFI
1342 1213
13431: mov pr=r31,-1 12141: mov pr=r31,-1
1344 ;; 1215 ;;
@@ -1360,26 +1231,26 @@ ENTRY(speculation_vector)
1360 * 1231 *
1361 * cr.imm contains zero_ext(imm21) 1232 * cr.imm contains zero_ext(imm21)
1362 */ 1233 */
1363 mov r18=cr.iim 1234 MOV_FROM_IIM(r18)
1364 ;; 1235 ;;
1365 mov r17=cr.iip 1236 MOV_FROM_IIP(r17)
1366 shl r18=r18,43 // put sign bit in position (43=64-21) 1237 shl r18=r18,43 // put sign bit in position (43=64-21)
1367 ;; 1238 ;;
1368 1239
1369 mov r16=cr.ipsr 1240 MOV_FROM_IPSR(p0, r16)
1370 shr r18=r18,39 // sign extend (39=43-4) 1241 shr r18=r18,39 // sign extend (39=43-4)
1371 ;; 1242 ;;
1372 1243
1373 add r17=r17,r18 // now add the offset 1244 add r17=r17,r18 // now add the offset
1374 ;; 1245 ;;
1375 mov cr.iip=r17 1246 MOV_FROM_IIP(r17)
1376 dep r16=0,r16,41,2 // clear EI 1247 dep r16=0,r16,41,2 // clear EI
1377 ;; 1248 ;;
1378 1249
1379 mov cr.ipsr=r16 1250 MOV_FROM_IPSR(p0, r16)
1380 ;; 1251 ;;
1381 1252
1382 rfi // and go back 1253 RFI
1383END(speculation_vector) 1254END(speculation_vector)
1384 1255
1385 .org ia64_ivt+0x5800 1256 .org ia64_ivt+0x5800
@@ -1517,11 +1388,11 @@ ENTRY(ia32_intercept)
1517 DBG_FAULT(46) 1388 DBG_FAULT(46)
1518#ifdef CONFIG_IA32_SUPPORT 1389#ifdef CONFIG_IA32_SUPPORT
1519 mov r31=pr 1390 mov r31=pr
1520 mov r16=cr.isr 1391 MOV_FROM_ISR(r16)
1521 ;; 1392 ;;
1522 extr.u r17=r16,16,8 // get ISR.code 1393 extr.u r17=r16,16,8 // get ISR.code
1523 mov r18=ar.eflag 1394 mov r18=ar.eflag
1524 mov r19=cr.iim // old eflag value 1395 MOV_FROM_IIM(r19) // old eflag value
1525 ;; 1396 ;;
1526 cmp.ne p6,p0=2,r17 1397 cmp.ne p6,p0=2,r17
1527(p6) br.cond.spnt 1f // not a system flag fault 1398(p6) br.cond.spnt 1f // not a system flag fault
@@ -1533,7 +1404,7 @@ ENTRY(ia32_intercept)
1533(p6) br.cond.spnt 1f // eflags.ac bit didn't change 1404(p6) br.cond.spnt 1f // eflags.ac bit didn't change
1534 ;; 1405 ;;
1535 mov pr=r31,-1 // restore predicate registers 1406 mov pr=r31,-1 // restore predicate registers
1536 rfi 1407 RFI
1537 1408
15381: 14091:
1539#endif // CONFIG_IA32_SUPPORT 1410#endif // CONFIG_IA32_SUPPORT
@@ -1673,6 +1544,137 @@ END(ia32_interrupt)
1673 DBG_FAULT(67) 1544 DBG_FAULT(67)
1674 FAULT(67) 1545 FAULT(67)
1675 1546
1547 //-----------------------------------------------------------------------------------
1548 // call do_page_fault (predicates are in r31, psr.dt may be off, r16 is faulting address)
1549ENTRY(page_fault)
1550 SSM_PSR_DT_AND_SRLZ_I
1551 ;;
1552 SAVE_MIN_WITH_COVER
1553 alloc r15=ar.pfs,0,0,3,0
1554 MOV_FROM_IFA(out0)
1555 MOV_FROM_ISR(out1)
1556 SSM_PSR_IC_AND_DEFAULT_BITS_AND_SRLZ_I(r14, r3)
1557 adds r3=8,r2 // set up second base pointer
1558 SSM_PSR_I(p15, p15, r14) // restore psr.i
1559 movl r14=ia64_leave_kernel
1560 ;;
1561 SAVE_REST
1562 mov rp=r14
1563 ;;
1564 adds out2=16,r12 // out2 = pointer to pt_regs
1565 br.call.sptk.many b6=ia64_do_page_fault // ignore return address
1566END(page_fault)
1567
1568ENTRY(non_syscall)
1569 mov ar.rsc=r27 // restore ar.rsc before SAVE_MIN_WITH_COVER
1570 ;;
1571 SAVE_MIN_WITH_COVER
1572
1573 // There is no particular reason for this code to be here, other than that
1574 // there happens to be space here that would go unused otherwise. If this
1575 // fault ever gets "unreserved", simply moved the following code to a more
1576 // suitable spot...
1577
1578 alloc r14=ar.pfs,0,0,2,0
1579 MOV_FROM_IIM(out0)
1580 add out1=16,sp
1581 adds r3=8,r2 // set up second base pointer for SAVE_REST
1582
1583 SSM_PSR_IC_AND_DEFAULT_BITS_AND_SRLZ_I(r15, r24)
1584 // guarantee that interruption collection is on
1585 SSM_PSR_I(p15, p15, r15) // restore psr.i
1586 movl r15=ia64_leave_kernel
1587 ;;
1588 SAVE_REST
1589 mov rp=r15
1590 ;;
1591 br.call.sptk.many b6=ia64_bad_break // avoid WAW on CFM and ignore return addr
1592END(non_syscall)
1593
1594ENTRY(__interrupt)
1595 DBG_FAULT(12)
1596 mov r31=pr // prepare to save predicates
1597 ;;
1598 SAVE_MIN_WITH_COVER // uses r31; defines r2 and r3
1599 SSM_PSR_IC_AND_DEFAULT_BITS_AND_SRLZ_I(r3, r14)
1600 // ensure everybody knows psr.ic is back on
1601 adds r3=8,r2 // set up second base pointer for SAVE_REST
1602 ;;
1603 SAVE_REST
1604 ;;
1605 MCA_RECOVER_RANGE(interrupt)
1606 alloc r14=ar.pfs,0,0,2,0 // must be first in an insn group
1607 MOV_FROM_IVR(out0, r8) // pass cr.ivr as first arg
1608 add out1=16,sp // pass pointer to pt_regs as second arg
1609 ;;
1610 srlz.d // make sure we see the effect of cr.ivr
1611 movl r14=ia64_leave_kernel
1612 ;;
1613 mov rp=r14
1614 br.call.sptk.many b6=ia64_handle_irq
1615END(__interrupt)
1616
1617 /*
1618 * There is no particular reason for this code to be here, other than that
1619 * there happens to be space here that would go unused otherwise. If this
1620 * fault ever gets "unreserved", simply moved the following code to a more
1621 * suitable spot...
1622 */
1623
1624ENTRY(dispatch_unaligned_handler)
1625 SAVE_MIN_WITH_COVER
1626 ;;
1627 alloc r14=ar.pfs,0,0,2,0 // now it's safe (must be first in insn group!)
1628 MOV_FROM_IFA(out0)
1629 adds out1=16,sp
1630
1631 SSM_PSR_IC_AND_DEFAULT_BITS_AND_SRLZ_I(r3, r24)
1632 // guarantee that interruption collection is on
1633 SSM_PSR_I(p15, p15, r3) // restore psr.i
1634 adds r3=8,r2 // set up second base pointer
1635 ;;
1636 SAVE_REST
1637 movl r14=ia64_leave_kernel
1638 ;;
1639 mov rp=r14
1640 br.sptk.many ia64_prepare_handle_unaligned
1641END(dispatch_unaligned_handler)
1642
1643 /*
1644 * There is no particular reason for this code to be here, other than that
1645 * there happens to be space here that would go unused otherwise. If this
1646 * fault ever gets "unreserved", simply moved the following code to a more
1647 * suitable spot...
1648 */
1649
1650ENTRY(dispatch_to_fault_handler)
1651 /*
1652 * Input:
1653 * psr.ic: off
1654 * r19: fault vector number (e.g., 24 for General Exception)
1655 * r31: contains saved predicates (pr)
1656 */
1657 SAVE_MIN_WITH_COVER_R19
1658 alloc r14=ar.pfs,0,0,5,0
1659 MOV_FROM_ISR(out1)
1660 MOV_FROM_IFA(out2)
1661 MOV_FROM_IIM(out3)
1662 MOV_FROM_ITIR(out4)
1663 ;;
1664 SSM_PSR_IC_AND_DEFAULT_BITS_AND_SRLZ_I(r3, out0)
1665 // guarantee that interruption collection is on
1666 mov out0=r15
1667 ;;
1668 SSM_PSR_I(p15, p15, r3) // restore psr.i
1669 adds r3=8,r2 // set up second base pointer for SAVE_REST
1670 ;;
1671 SAVE_REST
1672 movl r14=ia64_leave_kernel
1673 ;;
1674 mov rp=r14
1675 br.call.sptk.many b6=ia64_fault
1676END(dispatch_to_fault_handler)
1677
1676 /* 1678 /*
1677 * Squatting in this space ... 1679 * Squatting in this space ...
1678 * 1680 *
@@ -1686,11 +1688,10 @@ ENTRY(dispatch_illegal_op_fault)
1686 .prologue 1688 .prologue
1687 .body 1689 .body
1688 SAVE_MIN_WITH_COVER 1690 SAVE_MIN_WITH_COVER
1689 ssm psr.ic | PSR_DEFAULT_BITS 1691 SSM_PSR_IC_AND_DEFAULT_BITS_AND_SRLZ_I(r3, r24)
1690 ;; 1692 // guarantee that interruption collection is on
1691 srlz.i // guarantee that interruption collection is on
1692 ;; 1693 ;;
1693(p15) ssm psr.i // restore psr.i 1694 SSM_PSR_I(p15, p15, r3) // restore psr.i
1694 adds r3=8,r2 // set up second base pointer for SAVE_REST 1695 adds r3=8,r2 // set up second base pointer for SAVE_REST
1695 ;; 1696 ;;
1696 alloc r14=ar.pfs,0,0,1,0 // must be first in insn group 1697 alloc r14=ar.pfs,0,0,1,0 // must be first in insn group
@@ -1729,12 +1730,11 @@ END(dispatch_illegal_op_fault)
1729ENTRY(dispatch_to_ia32_handler) 1730ENTRY(dispatch_to_ia32_handler)
1730 SAVE_MIN 1731 SAVE_MIN
1731 ;; 1732 ;;
1732 mov r14=cr.isr 1733 MOV_FROM_ISR(r14)
1733 ssm psr.ic | PSR_DEFAULT_BITS 1734 SSM_PSR_IC_AND_DEFAULT_BITS_AND_SRLZ_I(r3, r24)
1734 ;; 1735 // guarantee that interruption collection is on
1735 srlz.i // guarantee that interruption collection is on
1736 ;; 1736 ;;
1737(p15) ssm psr.i 1737 SSM_PSR_I(p15, p15, r3)
1738 adds r3=8,r2 // Base pointer for SAVE_REST 1738 adds r3=8,r2 // Base pointer for SAVE_REST
1739 ;; 1739 ;;
1740 SAVE_REST 1740 SAVE_REST
diff --git a/arch/ia64/kernel/minstate.h b/arch/ia64/kernel/minstate.h
index 74b6d670aaef..292e214a3b84 100644
--- a/arch/ia64/kernel/minstate.h
+++ b/arch/ia64/kernel/minstate.h
@@ -2,6 +2,7 @@
2#include <asm/cache.h> 2#include <asm/cache.h>
3 3
4#include "entry.h" 4#include "entry.h"
5#include "paravirt_inst.h"
5 6
6#ifdef CONFIG_VIRT_CPU_ACCOUNTING 7#ifdef CONFIG_VIRT_CPU_ACCOUNTING
7/* read ar.itc in advance, and use it before leaving bank 0 */ 8/* read ar.itc in advance, and use it before leaving bank 0 */
@@ -43,16 +44,16 @@
43 * Note that psr.ic is NOT turned on by this macro. This is so that 44 * Note that psr.ic is NOT turned on by this macro. This is so that
44 * we can pass interruption state as arguments to a handler. 45 * we can pass interruption state as arguments to a handler.
45 */ 46 */
46#define DO_SAVE_MIN(COVER,SAVE_IFS,EXTRA,WORKAROUND) \ 47#define IA64_NATIVE_DO_SAVE_MIN(__COVER,SAVE_IFS,EXTRA,WORKAROUND) \
47 mov r16=IA64_KR(CURRENT); /* M */ \ 48 mov r16=IA64_KR(CURRENT); /* M */ \
48 mov r27=ar.rsc; /* M */ \ 49 mov r27=ar.rsc; /* M */ \
49 mov r20=r1; /* A */ \ 50 mov r20=r1; /* A */ \
50 mov r25=ar.unat; /* M */ \ 51 mov r25=ar.unat; /* M */ \
51 mov r29=cr.ipsr; /* M */ \ 52 MOV_FROM_IPSR(p0,r29); /* M */ \
52 mov r26=ar.pfs; /* I */ \ 53 mov r26=ar.pfs; /* I */ \
53 mov r28=cr.iip; /* M */ \ 54 MOV_FROM_IIP(r28); /* M */ \
54 mov r21=ar.fpsr; /* M */ \ 55 mov r21=ar.fpsr; /* M */ \
55 COVER; /* B;; (or nothing) */ \ 56 __COVER; /* B;; (or nothing) */ \
56 ;; \ 57 ;; \
57 adds r16=IA64_TASK_THREAD_ON_USTACK_OFFSET,r16; \ 58 adds r16=IA64_TASK_THREAD_ON_USTACK_OFFSET,r16; \
58 ;; \ 59 ;; \
@@ -244,6 +245,6 @@
2441: \ 2451: \
245 .pred.rel "mutex", pKStk, pUStk 246 .pred.rel "mutex", pKStk, pUStk
246 247
247#define SAVE_MIN_WITH_COVER DO_SAVE_MIN(cover, mov r30=cr.ifs, , RSE_WORKAROUND) 248#define SAVE_MIN_WITH_COVER DO_SAVE_MIN(COVER, mov r30=cr.ifs, , RSE_WORKAROUND)
248#define SAVE_MIN_WITH_COVER_R19 DO_SAVE_MIN(cover, mov r30=cr.ifs, mov r15=r19, RSE_WORKAROUND) 249#define SAVE_MIN_WITH_COVER_R19 DO_SAVE_MIN(COVER, mov r30=cr.ifs, mov r15=r19, RSE_WORKAROUND)
249#define SAVE_MIN DO_SAVE_MIN( , mov r30=r0, , ) 250#define SAVE_MIN DO_SAVE_MIN( , mov r30=r0, , )
diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
index e83e2ea3b3e0..29aad349e0c4 100644
--- a/arch/ia64/kernel/module.c
+++ b/arch/ia64/kernel/module.c
@@ -321,7 +321,8 @@ module_alloc (unsigned long size)
321void 321void
322module_free (struct module *mod, void *module_region) 322module_free (struct module *mod, void *module_region)
323{ 323{
324 if (mod->arch.init_unw_table && module_region == mod->module_init) { 324 if (mod && mod->arch.init_unw_table &&
325 module_region == mod->module_init) {
325 unw_remove_unwind_table(mod->arch.init_unw_table); 326 unw_remove_unwind_table(mod->arch.init_unw_table);
326 mod->arch.init_unw_table = NULL; 327 mod->arch.init_unw_table = NULL;
327 } 328 }
diff --git a/arch/ia64/kernel/nr-irqs.c b/arch/ia64/kernel/nr-irqs.c
new file mode 100644
index 000000000000..1ae049181e83
--- /dev/null
+++ b/arch/ia64/kernel/nr-irqs.c
@@ -0,0 +1,24 @@
1/*
2 * calculate
3 * NR_IRQS = max(IA64_NATIVE_NR_IRQS, XEN_NR_IRQS, FOO_NR_IRQS...)
4 * depending on config.
5 * This must be calculated before processing asm-offset.c.
6 */
7
8#define ASM_OFFSETS_C 1
9
10#include <linux/kbuild.h>
11#include <linux/threads.h>
12#include <asm-ia64/native/irq.h>
13
14void foo(void)
15{
16 union paravirt_nr_irqs_max {
17 char ia64_native_nr_irqs[IA64_NATIVE_NR_IRQS];
18#ifdef CONFIG_XEN
19 char xen_nr_irqs[XEN_NR_IRQS];
20#endif
21 };
22
23 DEFINE(NR_IRQS, sizeof (union paravirt_nr_irqs_max));
24}
diff --git a/arch/ia64/kernel/paravirt.c b/arch/ia64/kernel/paravirt.c
new file mode 100644
index 000000000000..afaf5b9a2cf0
--- /dev/null
+++ b/arch/ia64/kernel/paravirt.c
@@ -0,0 +1,369 @@
1/******************************************************************************
2 * arch/ia64/kernel/paravirt.c
3 *
4 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
6 * Yaozu (Eddie) Dong <eddie.dong@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include <linux/init.h>
25
26#include <linux/compiler.h>
27#include <linux/io.h>
28#include <linux/irq.h>
29#include <linux/module.h>
30#include <linux/types.h>
31
32#include <asm/iosapic.h>
33#include <asm/paravirt.h>
34
35/***************************************************************************
36 * general info
37 */
38struct pv_info pv_info = {
39 .kernel_rpl = 0,
40 .paravirt_enabled = 0,
41 .name = "bare hardware"
42};
43
44/***************************************************************************
45 * pv_init_ops
46 * initialization hooks.
47 */
48
49struct pv_init_ops pv_init_ops;
50
51/***************************************************************************
52 * pv_cpu_ops
53 * intrinsics hooks.
54 */
55
56/* ia64_native_xxx are macros so that we have to make them real functions */
57
58#define DEFINE_VOID_FUNC1(name) \
59 static void \
60 ia64_native_ ## name ## _func(unsigned long arg) \
61 { \
62 ia64_native_ ## name(arg); \
63 } \
64
65#define DEFINE_VOID_FUNC2(name) \
66 static void \
67 ia64_native_ ## name ## _func(unsigned long arg0, \
68 unsigned long arg1) \
69 { \
70 ia64_native_ ## name(arg0, arg1); \
71 } \
72
73#define DEFINE_FUNC0(name) \
74 static unsigned long \
75 ia64_native_ ## name ## _func(void) \
76 { \
77 return ia64_native_ ## name(); \
78 }
79
80#define DEFINE_FUNC1(name, type) \
81 static unsigned long \
82 ia64_native_ ## name ## _func(type arg) \
83 { \
84 return ia64_native_ ## name(arg); \
85 } \
86
87DEFINE_VOID_FUNC1(fc);
88DEFINE_VOID_FUNC1(intrin_local_irq_restore);
89
90DEFINE_VOID_FUNC2(ptcga);
91DEFINE_VOID_FUNC2(set_rr);
92
93DEFINE_FUNC0(get_psr_i);
94
95DEFINE_FUNC1(thash, unsigned long);
96DEFINE_FUNC1(get_cpuid, int);
97DEFINE_FUNC1(get_pmd, int);
98DEFINE_FUNC1(get_rr, unsigned long);
99
100static void
101ia64_native_ssm_i_func(void)
102{
103 ia64_native_ssm(IA64_PSR_I);
104}
105
106static void
107ia64_native_rsm_i_func(void)
108{
109 ia64_native_rsm(IA64_PSR_I);
110}
111
112static void
113ia64_native_set_rr0_to_rr4_func(unsigned long val0, unsigned long val1,
114 unsigned long val2, unsigned long val3,
115 unsigned long val4)
116{
117 ia64_native_set_rr0_to_rr4(val0, val1, val2, val3, val4);
118}
119
120#define CASE_GET_REG(id) \
121 case _IA64_REG_ ## id: \
122 res = ia64_native_getreg(_IA64_REG_ ## id); \
123 break;
124#define CASE_GET_AR(id) CASE_GET_REG(AR_ ## id)
125#define CASE_GET_CR(id) CASE_GET_REG(CR_ ## id)
126
127unsigned long
128ia64_native_getreg_func(int regnum)
129{
130 unsigned long res = -1;
131 switch (regnum) {
132 CASE_GET_REG(GP);
133 CASE_GET_REG(IP);
134 CASE_GET_REG(PSR);
135 CASE_GET_REG(TP);
136 CASE_GET_REG(SP);
137
138 CASE_GET_AR(KR0);
139 CASE_GET_AR(KR1);
140 CASE_GET_AR(KR2);
141 CASE_GET_AR(KR3);
142 CASE_GET_AR(KR4);
143 CASE_GET_AR(KR5);
144 CASE_GET_AR(KR6);
145 CASE_GET_AR(KR7);
146 CASE_GET_AR(RSC);
147 CASE_GET_AR(BSP);
148 CASE_GET_AR(BSPSTORE);
149 CASE_GET_AR(RNAT);
150 CASE_GET_AR(FCR);
151 CASE_GET_AR(EFLAG);
152 CASE_GET_AR(CSD);
153 CASE_GET_AR(SSD);
154 CASE_GET_AR(CFLAG);
155 CASE_GET_AR(FSR);
156 CASE_GET_AR(FIR);
157 CASE_GET_AR(FDR);
158 CASE_GET_AR(CCV);
159 CASE_GET_AR(UNAT);
160 CASE_GET_AR(FPSR);
161 CASE_GET_AR(ITC);
162 CASE_GET_AR(PFS);
163 CASE_GET_AR(LC);
164 CASE_GET_AR(EC);
165
166 CASE_GET_CR(DCR);
167 CASE_GET_CR(ITM);
168 CASE_GET_CR(IVA);
169 CASE_GET_CR(PTA);
170 CASE_GET_CR(IPSR);
171 CASE_GET_CR(ISR);
172 CASE_GET_CR(IIP);
173 CASE_GET_CR(IFA);
174 CASE_GET_CR(ITIR);
175 CASE_GET_CR(IIPA);
176 CASE_GET_CR(IFS);
177 CASE_GET_CR(IIM);
178 CASE_GET_CR(IHA);
179 CASE_GET_CR(LID);
180 CASE_GET_CR(IVR);
181 CASE_GET_CR(TPR);
182 CASE_GET_CR(EOI);
183 CASE_GET_CR(IRR0);
184 CASE_GET_CR(IRR1);
185 CASE_GET_CR(IRR2);
186 CASE_GET_CR(IRR3);
187 CASE_GET_CR(ITV);
188 CASE_GET_CR(PMV);
189 CASE_GET_CR(CMCV);
190 CASE_GET_CR(LRR0);
191 CASE_GET_CR(LRR1);
192
193 default:
194 printk(KERN_CRIT "wrong_getreg %d\n", regnum);
195 break;
196 }
197 return res;
198}
199
200#define CASE_SET_REG(id) \
201 case _IA64_REG_ ## id: \
202 ia64_native_setreg(_IA64_REG_ ## id, val); \
203 break;
204#define CASE_SET_AR(id) CASE_SET_REG(AR_ ## id)
205#define CASE_SET_CR(id) CASE_SET_REG(CR_ ## id)
206
207void
208ia64_native_setreg_func(int regnum, unsigned long val)
209{
210 switch (regnum) {
211 case _IA64_REG_PSR_L:
212 ia64_native_setreg(_IA64_REG_PSR_L, val);
213 ia64_dv_serialize_data();
214 break;
215 CASE_SET_REG(SP);
216 CASE_SET_REG(GP);
217
218 CASE_SET_AR(KR0);
219 CASE_SET_AR(KR1);
220 CASE_SET_AR(KR2);
221 CASE_SET_AR(KR3);
222 CASE_SET_AR(KR4);
223 CASE_SET_AR(KR5);
224 CASE_SET_AR(KR6);
225 CASE_SET_AR(KR7);
226 CASE_SET_AR(RSC);
227 CASE_SET_AR(BSP);
228 CASE_SET_AR(BSPSTORE);
229 CASE_SET_AR(RNAT);
230 CASE_SET_AR(FCR);
231 CASE_SET_AR(EFLAG);
232 CASE_SET_AR(CSD);
233 CASE_SET_AR(SSD);
234 CASE_SET_AR(CFLAG);
235 CASE_SET_AR(FSR);
236 CASE_SET_AR(FIR);
237 CASE_SET_AR(FDR);
238 CASE_SET_AR(CCV);
239 CASE_SET_AR(UNAT);
240 CASE_SET_AR(FPSR);
241 CASE_SET_AR(ITC);
242 CASE_SET_AR(PFS);
243 CASE_SET_AR(LC);
244 CASE_SET_AR(EC);
245
246 CASE_SET_CR(DCR);
247 CASE_SET_CR(ITM);
248 CASE_SET_CR(IVA);
249 CASE_SET_CR(PTA);
250 CASE_SET_CR(IPSR);
251 CASE_SET_CR(ISR);
252 CASE_SET_CR(IIP);
253 CASE_SET_CR(IFA);
254 CASE_SET_CR(ITIR);
255 CASE_SET_CR(IIPA);
256 CASE_SET_CR(IFS);
257 CASE_SET_CR(IIM);
258 CASE_SET_CR(IHA);
259 CASE_SET_CR(LID);
260 CASE_SET_CR(IVR);
261 CASE_SET_CR(TPR);
262 CASE_SET_CR(EOI);
263 CASE_SET_CR(IRR0);
264 CASE_SET_CR(IRR1);
265 CASE_SET_CR(IRR2);
266 CASE_SET_CR(IRR3);
267 CASE_SET_CR(ITV);
268 CASE_SET_CR(PMV);
269 CASE_SET_CR(CMCV);
270 CASE_SET_CR(LRR0);
271 CASE_SET_CR(LRR1);
272 default:
273 printk(KERN_CRIT "wrong setreg %d\n", regnum);
274 break;
275 }
276}
277
278struct pv_cpu_ops pv_cpu_ops = {
279 .fc = ia64_native_fc_func,
280 .thash = ia64_native_thash_func,
281 .get_cpuid = ia64_native_get_cpuid_func,
282 .get_pmd = ia64_native_get_pmd_func,
283 .ptcga = ia64_native_ptcga_func,
284 .get_rr = ia64_native_get_rr_func,
285 .set_rr = ia64_native_set_rr_func,
286 .set_rr0_to_rr4 = ia64_native_set_rr0_to_rr4_func,
287 .ssm_i = ia64_native_ssm_i_func,
288 .getreg = ia64_native_getreg_func,
289 .setreg = ia64_native_setreg_func,
290 .rsm_i = ia64_native_rsm_i_func,
291 .get_psr_i = ia64_native_get_psr_i_func,
292 .intrin_local_irq_restore
293 = ia64_native_intrin_local_irq_restore_func,
294};
295EXPORT_SYMBOL(pv_cpu_ops);
296
297/******************************************************************************
298 * replacement of hand written assembly codes.
299 */
300
301void
302paravirt_cpu_asm_init(const struct pv_cpu_asm_switch *cpu_asm_switch)
303{
304 extern unsigned long paravirt_switch_to_targ;
305 extern unsigned long paravirt_leave_syscall_targ;
306 extern unsigned long paravirt_work_processed_syscall_targ;
307 extern unsigned long paravirt_leave_kernel_targ;
308
309 paravirt_switch_to_targ = cpu_asm_switch->switch_to;
310 paravirt_leave_syscall_targ = cpu_asm_switch->leave_syscall;
311 paravirt_work_processed_syscall_targ =
312 cpu_asm_switch->work_processed_syscall;
313 paravirt_leave_kernel_targ = cpu_asm_switch->leave_kernel;
314}
315
316/***************************************************************************
317 * pv_iosapic_ops
318 * iosapic read/write hooks.
319 */
320
321static unsigned int
322ia64_native_iosapic_read(char __iomem *iosapic, unsigned int reg)
323{
324 return __ia64_native_iosapic_read(iosapic, reg);
325}
326
327static void
328ia64_native_iosapic_write(char __iomem *iosapic, unsigned int reg, u32 val)
329{
330 __ia64_native_iosapic_write(iosapic, reg, val);
331}
332
333struct pv_iosapic_ops pv_iosapic_ops = {
334 .pcat_compat_init = ia64_native_iosapic_pcat_compat_init,
335 .get_irq_chip = ia64_native_iosapic_get_irq_chip,
336
337 .__read = ia64_native_iosapic_read,
338 .__write = ia64_native_iosapic_write,
339};
340
341/***************************************************************************
342 * pv_irq_ops
343 * irq operations
344 */
345
346struct pv_irq_ops pv_irq_ops = {
347 .register_ipi = ia64_native_register_ipi,
348
349 .assign_irq_vector = ia64_native_assign_irq_vector,
350 .free_irq_vector = ia64_native_free_irq_vector,
351 .register_percpu_irq = ia64_native_register_percpu_irq,
352
353 .resend_irq = ia64_native_resend_irq,
354};
355
356/***************************************************************************
357 * pv_time_ops
358 * time operations
359 */
360
361static int
362ia64_native_do_steal_accounting(unsigned long *new_itm)
363{
364 return 0;
365}
366
367struct pv_time_ops pv_time_ops = {
368 .do_steal_accounting = ia64_native_do_steal_accounting,
369};
diff --git a/arch/ia64/kernel/paravirt_inst.h b/arch/ia64/kernel/paravirt_inst.h
new file mode 100644
index 000000000000..5cad6fb2ed19
--- /dev/null
+++ b/arch/ia64/kernel/paravirt_inst.h
@@ -0,0 +1,29 @@
1/******************************************************************************
2 * linux/arch/ia64/xen/paravirt_inst.h
3 *
4 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#ifdef __IA64_ASM_PARAVIRTUALIZED_XEN
24#include <asm/xen/inst.h>
25#include <asm/xen/minstate.h>
26#else
27#include <asm/native/inst.h>
28#endif
29
diff --git a/arch/ia64/kernel/paravirtentry.S b/arch/ia64/kernel/paravirtentry.S
new file mode 100644
index 000000000000..2f42fcb9776a
--- /dev/null
+++ b/arch/ia64/kernel/paravirtentry.S
@@ -0,0 +1,60 @@
1/******************************************************************************
2 * linux/arch/ia64/xen/paravirtentry.S
3 *
4 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include <asm/asmmacro.h>
24#include <asm/asm-offsets.h>
25#include "entry.h"
26
27#define DATA8(sym, init_value) \
28 .pushsection .data.read_mostly ; \
29 .align 8 ; \
30 .global sym ; \
31 sym: ; \
32 data8 init_value ; \
33 .popsection
34
35#define BRANCH(targ, reg, breg) \
36 movl reg=targ ; \
37 ;; \
38 ld8 reg=[reg] ; \
39 ;; \
40 mov breg=reg ; \
41 br.cond.sptk.many breg
42
43#define BRANCH_PROC(sym, reg, breg) \
44 DATA8(paravirt_ ## sym ## _targ, ia64_native_ ## sym) ; \
45 GLOBAL_ENTRY(paravirt_ ## sym) ; \
46 BRANCH(paravirt_ ## sym ## _targ, reg, breg) ; \
47 END(paravirt_ ## sym)
48
49#define BRANCH_PROC_UNWINFO(sym, reg, breg) \
50 DATA8(paravirt_ ## sym ## _targ, ia64_native_ ## sym) ; \
51 GLOBAL_ENTRY(paravirt_ ## sym) ; \
52 PT_REGS_UNWIND_INFO(0) ; \
53 BRANCH(paravirt_ ## sym ## _targ, reg, breg) ; \
54 END(paravirt_ ## sym)
55
56
57BRANCH_PROC(switch_to, r22, b7)
58BRANCH_PROC_UNWINFO(leave_syscall, r22, b7)
59BRANCH_PROC(work_processed_syscall, r2, b7)
60BRANCH_PROC_UNWINFO(leave_kernel, r22, b7)
diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c
index 632cda8f2e76..e5c2de9b29a5 100644
--- a/arch/ia64/kernel/setup.c
+++ b/arch/ia64/kernel/setup.c
@@ -51,6 +51,7 @@
51#include <asm/mca.h> 51#include <asm/mca.h>
52#include <asm/meminit.h> 52#include <asm/meminit.h>
53#include <asm/page.h> 53#include <asm/page.h>
54#include <asm/paravirt.h>
54#include <asm/patch.h> 55#include <asm/patch.h>
55#include <asm/pgtable.h> 56#include <asm/pgtable.h>
56#include <asm/processor.h> 57#include <asm/processor.h>
@@ -341,6 +342,8 @@ reserve_memory (void)
341 rsvd_region[n].end = (unsigned long) ia64_imva(_end); 342 rsvd_region[n].end = (unsigned long) ia64_imva(_end);
342 n++; 343 n++;
343 344
345 n += paravirt_reserve_memory(&rsvd_region[n]);
346
344#ifdef CONFIG_BLK_DEV_INITRD 347#ifdef CONFIG_BLK_DEV_INITRD
345 if (ia64_boot_param->initrd_start) { 348 if (ia64_boot_param->initrd_start) {
346 rsvd_region[n].start = (unsigned long)__va(ia64_boot_param->initrd_start); 349 rsvd_region[n].start = (unsigned long)__va(ia64_boot_param->initrd_start);
@@ -519,6 +522,8 @@ setup_arch (char **cmdline_p)
519{ 522{
520 unw_init(); 523 unw_init();
521 524
525 paravirt_arch_setup_early();
526
522 ia64_patch_vtop((u64) __start___vtop_patchlist, (u64) __end___vtop_patchlist); 527 ia64_patch_vtop((u64) __start___vtop_patchlist, (u64) __end___vtop_patchlist);
523 528
524 *cmdline_p = __va(ia64_boot_param->command_line); 529 *cmdline_p = __va(ia64_boot_param->command_line);
@@ -583,6 +588,9 @@ setup_arch (char **cmdline_p)
583 acpi_boot_init(); 588 acpi_boot_init();
584#endif 589#endif
585 590
591 paravirt_banner();
592 paravirt_arch_setup_console(cmdline_p);
593
586#ifdef CONFIG_VT 594#ifdef CONFIG_VT
587 if (!conswitchp) { 595 if (!conswitchp) {
588# if defined(CONFIG_DUMMY_CONSOLE) 596# if defined(CONFIG_DUMMY_CONSOLE)
@@ -602,6 +610,8 @@ setup_arch (char **cmdline_p)
602#endif 610#endif
603 611
604 /* enable IA-64 Machine Check Abort Handling unless disabled */ 612 /* enable IA-64 Machine Check Abort Handling unless disabled */
613 if (paravirt_arch_setup_nomca())
614 nomca = 1;
605 if (!nomca) 615 if (!nomca)
606 ia64_mca_init(); 616 ia64_mca_init();
607 617
diff --git a/arch/ia64/kernel/smpboot.c b/arch/ia64/kernel/smpboot.c
index 9d1d429c6c59..03f1a9908afc 100644
--- a/arch/ia64/kernel/smpboot.c
+++ b/arch/ia64/kernel/smpboot.c
@@ -50,6 +50,7 @@
50#include <asm/machvec.h> 50#include <asm/machvec.h>
51#include <asm/mca.h> 51#include <asm/mca.h>
52#include <asm/page.h> 52#include <asm/page.h>
53#include <asm/paravirt.h>
53#include <asm/pgalloc.h> 54#include <asm/pgalloc.h>
54#include <asm/pgtable.h> 55#include <asm/pgtable.h>
55#include <asm/processor.h> 56#include <asm/processor.h>
@@ -642,6 +643,7 @@ void __devinit smp_prepare_boot_cpu(void)
642 cpu_set(smp_processor_id(), cpu_online_map); 643 cpu_set(smp_processor_id(), cpu_online_map);
643 cpu_set(smp_processor_id(), cpu_callin_map); 644 cpu_set(smp_processor_id(), cpu_callin_map);
644 per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE; 645 per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
646 paravirt_post_smp_prepare_boot_cpu();
645} 647}
646 648
647#ifdef CONFIG_HOTPLUG_CPU 649#ifdef CONFIG_HOTPLUG_CPU
diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
index aad1b7b1fff9..65c10a42c88f 100644
--- a/arch/ia64/kernel/time.c
+++ b/arch/ia64/kernel/time.c
@@ -24,6 +24,7 @@
24#include <asm/machvec.h> 24#include <asm/machvec.h>
25#include <asm/delay.h> 25#include <asm/delay.h>
26#include <asm/hw_irq.h> 26#include <asm/hw_irq.h>
27#include <asm/paravirt.h>
27#include <asm/ptrace.h> 28#include <asm/ptrace.h>
28#include <asm/sal.h> 29#include <asm/sal.h>
29#include <asm/sections.h> 30#include <asm/sections.h>
@@ -48,6 +49,15 @@ EXPORT_SYMBOL(last_cli_ip);
48 49
49#endif 50#endif
50 51
52#ifdef CONFIG_PARAVIRT
53static void
54paravirt_clocksource_resume(void)
55{
56 if (pv_time_ops.clocksource_resume)
57 pv_time_ops.clocksource_resume();
58}
59#endif
60
51static struct clocksource clocksource_itc = { 61static struct clocksource clocksource_itc = {
52 .name = "itc", 62 .name = "itc",
53 .rating = 350, 63 .rating = 350,
@@ -56,6 +66,9 @@ static struct clocksource clocksource_itc = {
56 .mult = 0, /*to be calculated*/ 66 .mult = 0, /*to be calculated*/
57 .shift = 16, 67 .shift = 16,
58 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 68 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
69#ifdef CONFIG_PARAVIRT
70 .resume = paravirt_clocksource_resume,
71#endif
59}; 72};
60static struct clocksource *itc_clocksource; 73static struct clocksource *itc_clocksource;
61 74
@@ -157,6 +170,9 @@ timer_interrupt (int irq, void *dev_id)
157 170
158 profile_tick(CPU_PROFILING); 171 profile_tick(CPU_PROFILING);
159 172
173 if (paravirt_do_steal_accounting(&new_itm))
174 goto skip_process_time_accounting;
175
160 while (1) { 176 while (1) {
161 update_process_times(user_mode(get_irq_regs())); 177 update_process_times(user_mode(get_irq_regs()));
162 178
@@ -186,6 +202,8 @@ timer_interrupt (int irq, void *dev_id)
186 local_irq_disable(); 202 local_irq_disable();
187 } 203 }
188 204
205skip_process_time_accounting:
206
189 do { 207 do {
190 /* 208 /*
191 * If we're too close to the next clock tick for 209 * If we're too close to the next clock tick for
@@ -335,6 +353,11 @@ ia64_init_itm (void)
335 */ 353 */
336 clocksource_itc.rating = 50; 354 clocksource_itc.rating = 50;
337 355
356 paravirt_init_missing_ticks_accounting(smp_processor_id());
357
358 /* avoid softlock up message when cpu is unplug and plugged again. */
359 touch_softlockup_watchdog();
360
338 /* Setup the CPU local timer tick */ 361 /* Setup the CPU local timer tick */
339 ia64_cpu_local_tick(); 362 ia64_cpu_local_tick();
340 363
diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
index 5929ab10a289..5a77206c2492 100644
--- a/arch/ia64/kernel/vmlinux.lds.S
+++ b/arch/ia64/kernel/vmlinux.lds.S
@@ -4,7 +4,6 @@
4#include <asm/system.h> 4#include <asm/system.h>
5#include <asm/pgtable.h> 5#include <asm/pgtable.h>
6 6
7#define LOAD_OFFSET (KERNEL_START - KERNEL_TR_PAGE_SIZE)
8#include <asm-generic/vmlinux.lds.h> 7#include <asm-generic/vmlinux.lds.h>
9 8
10#define IVT_TEXT \ 9#define IVT_TEXT \
diff --git a/arch/mips/kernel/rtlx.c b/arch/mips/kernel/rtlx.c
index b55641961232..dfd868b68364 100644
--- a/arch/mips/kernel/rtlx.c
+++ b/arch/mips/kernel/rtlx.c
@@ -522,8 +522,8 @@ static int __init rtlx_module_init(void)
522 atomic_set(&channel_wqs[i].in_open, 0); 522 atomic_set(&channel_wqs[i].in_open, 0);
523 mutex_init(&channel_wqs[i].mutex); 523 mutex_init(&channel_wqs[i].mutex);
524 524
525 dev = device_create(mt_class, NULL, MKDEV(major, i), 525 dev = device_create_drvdata(mt_class, NULL, MKDEV(major, i),
526 "%s%d", module_name, i); 526 NULL, "%s%d", module_name, i);
527 if (IS_ERR(dev)) { 527 if (IS_ERR(dev)) {
528 err = PTR_ERR(dev); 528 err = PTR_ERR(dev);
529 goto out_chrdev; 529 goto out_chrdev;
diff --git a/arch/mips/sibyte/common/sb_tbprof.c b/arch/mips/sibyte/common/sb_tbprof.c
index 28b012ab8dcb..66e3e3fb311f 100644
--- a/arch/mips/sibyte/common/sb_tbprof.c
+++ b/arch/mips/sibyte/common/sb_tbprof.c
@@ -576,7 +576,8 @@ static int __init sbprof_tb_init(void)
576 576
577 tb_class = tbc; 577 tb_class = tbc;
578 578
579 dev = device_create(tbc, NULL, MKDEV(SBPROF_TB_MAJOR, 0), "tb"); 579 dev = device_create_drvdata(tbc, NULL, MKDEV(SBPROF_TB_MAJOR, 0),
580 NULL, "tb");
580 if (IS_ERR(dev)) { 581 if (IS_ERR(dev)) {
581 err = PTR_ERR(dev); 582 err = PTR_ERR(dev);
582 goto out_class; 583 goto out_class;
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index de88972c5896..4c22242b396f 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -199,7 +199,7 @@ config ARCH_HIBERNATION_POSSIBLE
199 199
200config ARCH_SUSPEND_POSSIBLE 200config ARCH_SUSPEND_POSSIBLE
201 def_bool y 201 def_bool y
202 depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200 202 depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200 || PPC_83xx
203 203
204config PPC_DCR_NATIVE 204config PPC_DCR_NATIVE
205 bool 205 bool
@@ -568,11 +568,15 @@ config FSL_GTM
568config MCA 568config MCA
569 bool 569 bool
570 570
571# Platforms that what PCI turned unconditionally just do select PCI
572# in their config node. Platforms that want to choose at config
573# time should select PPC_PCI_CHOICE
574config PPC_PCI_CHOICE
575 bool
576
571config PCI 577config PCI
572 bool "PCI support" if 40x || CPM2 || PPC_83xx || PPC_85xx || PPC_86xx \ 578 bool "PCI support" if PPC_PCI_CHOICE
573 || PPC_MPC52xx || (EMBEDDED && (PPC_PSERIES || PPC_ISERIES)) \ 579 default y if !40x && !CPM2 && !8xx && !PPC_83xx \
574 || PPC_PS3 || 44x
575 default y if !40x && !CPM2 && !8xx && !PPC_MPC512x && !PPC_83xx \
576 && !PPC_85xx && !PPC_86xx 580 && !PPC_85xx && !PPC_86xx
577 default PCI_PERMEDIA if !4xx && !CPM2 && !8xx 581 default PCI_PERMEDIA if !4xx && !CPM2 && !8xx
578 default PCI_QSPAN if !4xx && !CPM2 && 8xx 582 default PCI_QSPAN if !4xx && !CPM2 && 8xx
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 19f83c8f219d..14174aa24074 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -163,12 +163,12 @@ quiet_cmd_flex = FLEX $@
163 cmd_flex = $(FLEX) -o$@ $<; cp $@ $@_shipped 163 cmd_flex = $(FLEX) -o$@ $<; cp $@ $@_shipped
164 164
165$(obj)/dtc-src/dtc-parser.tab.c: $(src)/dtc-src/dtc-parser.y FORCE 165$(obj)/dtc-src/dtc-parser.tab.c: $(src)/dtc-src/dtc-parser.y FORCE
166 $(call if_changed,bison) 166 $(call if_changed,bison)
167 167
168$(obj)/dtc-src/dtc-parser.tab.h: $(obj)/dtc-src/dtc-parser.tab.c 168$(obj)/dtc-src/dtc-parser.tab.h: $(obj)/dtc-src/dtc-parser.tab.c
169 169
170$(obj)/dtc-src/dtc-lexer.lex.c: $(src)/dtc-src/dtc-lexer.l FORCE 170$(obj)/dtc-src/dtc-lexer.lex.c: $(src)/dtc-src/dtc-lexer.l FORCE
171 $(call if_changed,flex) 171 $(call if_changed,flex)
172endif 172endif
173 173
174############# 174#############
diff --git a/arch/powerpc/boot/dts/mpc7448hpc2.dts b/arch/powerpc/boot/dts/mpc7448hpc2.dts
index 705c23c14f32..2544f3ecd6e9 100644
--- a/arch/powerpc/boot/dts/mpc7448hpc2.dts
+++ b/arch/powerpc/boot/dts/mpc7448hpc2.dts
@@ -18,6 +18,16 @@
18 #address-cells = <1>; 18 #address-cells = <1>;
19 #size-cells = <1>; 19 #size-cells = <1>;
20 20
21 aliases {
22 ethernet0 = &enet0;
23 ethernet1 = &enet1;
24
25 serial0 = &serial0;
26 serial1 = &serial1;
27
28 pci0 = &pci0;
29 };
30
21 cpus { 31 cpus {
22 #address-cells = <1>; 32 #address-cells = <1>;
23 #size-cells =<0>; 33 #size-cells =<0>;
@@ -78,7 +88,7 @@
78 88
79 }; 89 };
80 90
81 ethernet@6200 { 91 enet0: ethernet@6200 {
82 linux,network-index = <0>; 92 linux,network-index = <0>;
83 #size-cells = <0>; 93 #size-cells = <0>;
84 device_type = "network"; 94 device_type = "network";
@@ -91,7 +101,7 @@
91 phy-handle = <&phy8>; 101 phy-handle = <&phy8>;
92 }; 102 };
93 103
94 ethernet@6600 { 104 enet1: ethernet@6600 {
95 linux,network-index = <1>; 105 linux,network-index = <1>;
96 #address-cells = <1>; 106 #address-cells = <1>;
97 #size-cells = <0>; 107 #size-cells = <0>;
@@ -105,7 +115,7 @@
105 phy-handle = <&phy9>; 115 phy-handle = <&phy9>;
106 }; 116 };
107 117
108 serial@7808 { 118 serial0: serial@7808 {
109 device_type = "serial"; 119 device_type = "serial";
110 compatible = "ns16550"; 120 compatible = "ns16550";
111 reg = <0x7808 0x200>; 121 reg = <0x7808 0x200>;
@@ -114,7 +124,7 @@
114 interrupt-parent = <&mpic>; 124 interrupt-parent = <&mpic>;
115 }; 125 };
116 126
117 serial@7c08 { 127 serial1: serial@7c08 {
118 device_type = "serial"; 128 device_type = "serial";
119 compatible = "ns16550"; 129 compatible = "ns16550";
120 reg = <0x7c08 0x200>; 130 reg = <0x7c08 0x200>;
@@ -131,7 +141,7 @@
131 compatible = "chrp,open-pic"; 141 compatible = "chrp,open-pic";
132 device_type = "open-pic"; 142 device_type = "open-pic";
133 }; 143 };
134 pci@1000 { 144 pci0: pci@1000 {
135 compatible = "tsi108-pci"; 145 compatible = "tsi108-pci";
136 device_type = "pci"; 146 device_type = "pci";
137 #interrupt-cells = <1>; 147 #interrupt-cells = <1>;
@@ -184,8 +194,4 @@
184 }; 194 };
185 }; 195 };
186 }; 196 };
187 chosen {
188 linux,stdout-path = "/tsi108@c0000000/serial@7808";
189 };
190
191}; 197};
diff --git a/arch/powerpc/boot/dts/mpc8313erdb.dts b/arch/powerpc/boot/dts/mpc8313erdb.dts
index 3664fb584026..2a94ae0dc8b8 100644
--- a/arch/powerpc/boot/dts/mpc8313erdb.dts
+++ b/arch/powerpc/boot/dts/mpc8313erdb.dts
@@ -109,18 +109,38 @@
109 reg = <0x200 0x100>; 109 reg = <0x200 0x100>;
110 }; 110 };
111 111
112 i2c@3000 { 112 sleep-nexus {
113 #address-cells = <1>; 113 #address-cells = <1>;
114 #size-cells = <0>; 114 #size-cells = <1>;
115 cell-index = <0>; 115 compatible = "simple-bus";
116 compatible = "fsl-i2c"; 116 sleep = <&pmc 0x03000000>;
117 reg = <0x3000 0x100>; 117 ranges;
118 interrupts = <14 0x8>; 118
119 interrupt-parent = <&ipic>; 119 i2c@3000 {
120 dfsrr; 120 #address-cells = <1>;
121 rtc@68 { 121 #size-cells = <0>;
122 compatible = "dallas,ds1339"; 122 cell-index = <0>;
123 reg = <0x68>; 123 compatible = "fsl-i2c";
124 reg = <0x3000 0x100>;
125 interrupts = <14 0x8>;
126 interrupt-parent = <&ipic>;
127 dfsrr;
128 rtc@68 {
129 compatible = "dallas,ds1339";
130 reg = <0x68>;
131 };
132 };
133
134 crypto@30000 {
135 compatible = "fsl,sec2.2", "fsl,sec2.1",
136 "fsl,sec2.0";
137 reg = <0x30000 0x10000>;
138 interrupts = <11 0x8>;
139 interrupt-parent = <&ipic>;
140 fsl,num-channels = <1>;
141 fsl,channel-fifo-len = <24>;
142 fsl,exec-units-mask = <0x4c>;
143 fsl,descriptor-types-mask = <0x0122003f>;
124 }; 144 };
125 }; 145 };
126 146
@@ -188,37 +208,44 @@
188 interrupt-parent = <&ipic>; 208 interrupt-parent = <&ipic>;
189 interrupts = <38 0x8>; 209 interrupts = <38 0x8>;
190 phy_type = "utmi_wide"; 210 phy_type = "utmi_wide";
211 sleep = <&pmc 0x00300000>;
191 }; 212 };
192 213
193 mdio@24520 { 214 enet0: ethernet@24000 {
194 #address-cells = <1>; 215 #address-cells = <1>;
195 #size-cells = <0>; 216 #size-cells = <1>;
196 compatible = "fsl,gianfar-mdio"; 217 sleep = <&pmc 0x20000000>;
197 reg = <0x24520 0x20>; 218 ranges;
198 phy1: ethernet-phy@1 {
199 interrupt-parent = <&ipic>;
200 interrupts = <19 0x8>;
201 reg = <0x1>;
202 device_type = "ethernet-phy";
203 };
204 phy4: ethernet-phy@4 {
205 interrupt-parent = <&ipic>;
206 interrupts = <20 0x8>;
207 reg = <0x4>;
208 device_type = "ethernet-phy";
209 };
210 };
211 219
212 enet0: ethernet@24000 {
213 cell-index = <0>; 220 cell-index = <0>;
214 device_type = "network"; 221 device_type = "network";
215 model = "eTSEC"; 222 model = "eTSEC";
216 compatible = "gianfar"; 223 compatible = "gianfar", "simple-bus";
217 reg = <0x24000 0x1000>; 224 reg = <0x24000 0x1000>;
218 local-mac-address = [ 00 00 00 00 00 00 ]; 225 local-mac-address = [ 00 00 00 00 00 00 ];
219 interrupts = <37 0x8 36 0x8 35 0x8>; 226 interrupts = <37 0x8 36 0x8 35 0x8>;
220 interrupt-parent = <&ipic>; 227 interrupt-parent = <&ipic>;
221 phy-handle = < &phy1 >; 228 phy-handle = < &phy1 >;
229 fsl,magic-packet;
230
231 mdio@24520 {
232 #address-cells = <1>;
233 #size-cells = <0>;
234 compatible = "fsl,gianfar-mdio";
235 reg = <0x24520 0x20>;
236 phy1: ethernet-phy@1 {
237 interrupt-parent = <&ipic>;
238 interrupts = <19 0x8>;
239 reg = <0x1>;
240 device_type = "ethernet-phy";
241 };
242 phy4: ethernet-phy@4 {
243 interrupt-parent = <&ipic>;
244 interrupts = <20 0x8>;
245 reg = <0x4>;
246 device_type = "ethernet-phy";
247 };
248 };
222 }; 249 };
223 250
224 enet1: ethernet@25000 { 251 enet1: ethernet@25000 {
@@ -231,6 +258,8 @@
231 interrupts = <34 0x8 33 0x8 32 0x8>; 258 interrupts = <34 0x8 33 0x8 32 0x8>;
232 interrupt-parent = <&ipic>; 259 interrupt-parent = <&ipic>;
233 phy-handle = < &phy4 >; 260 phy-handle = < &phy4 >;
261 sleep = <&pmc 0x10000000>;
262 fsl,magic-packet;
234 }; 263 };
235 264
236 serial0: serial@4500 { 265 serial0: serial@4500 {
@@ -253,17 +282,6 @@
253 interrupt-parent = <&ipic>; 282 interrupt-parent = <&ipic>;
254 }; 283 };
255 284
256 crypto@30000 {
257 compatible = "fsl,sec2.2", "fsl,sec2.1", "fsl,sec2.0";
258 reg = <0x30000 0x10000>;
259 interrupts = <11 0x8>;
260 interrupt-parent = <&ipic>;
261 fsl,num-channels = <1>;
262 fsl,channel-fifo-len = <24>;
263 fsl,exec-units-mask = <0x4c>;
264 fsl,descriptor-types-mask = <0x0122003f>;
265 };
266
267 /* IPIC 285 /* IPIC
268 * interrupts cell = <intr #, sense> 286 * interrupts cell = <intr #, sense>
269 * sense values match linux IORESOURCE_IRQ_* defines: 287 * sense values match linux IORESOURCE_IRQ_* defines:
@@ -277,36 +295,119 @@
277 reg = <0x700 0x100>; 295 reg = <0x700 0x100>;
278 device_type = "ipic"; 296 device_type = "ipic";
279 }; 297 };
298
299 pmc: power@b00 {
300 compatible = "fsl,mpc8313-pmc", "fsl,mpc8349-pmc";
301 reg = <0xb00 0x100 0xa00 0x100>;
302 interrupts = <80 8>;
303 interrupt-parent = <&ipic>;
304 fsl,mpc8313-wakeup-timer = <&gtm1>;
305
306 /* Remove this (or change to "okay") if you have
307 * a REVA3 or later board, if you apply one of the
308 * workarounds listed in section 8.5 of the board
309 * manual, or if you are adapting this device tree
310 * to a different board.
311 */
312 status = "fail";
313 };
314
315 gtm1: timer@500 {
316 compatible = "fsl,mpc8313-gtm", "fsl,gtm";
317 reg = <0x500 0x100>;
318 interrupts = <90 8 78 8 84 8 72 8>;
319 interrupt-parent = <&ipic>;
320 };
321
322 timer@600 {
323 compatible = "fsl,mpc8313-gtm", "fsl,gtm";
324 reg = <0x600 0x100>;
325 interrupts = <91 8 79 8 85 8 73 8>;
326 interrupt-parent = <&ipic>;
327 };
280 }; 328 };
281 329
282 pci0: pci@e0008500 { 330 sleep-nexus {
283 cell-index = <1>; 331 #address-cells = <1>;
284 interrupt-map-mask = <0xf800 0x0 0x0 0x7>; 332 #size-cells = <1>;
285 interrupt-map = < 333 compatible = "simple-bus";
286 334 sleep = <&pmc 0x00010000>;
287 /* IDSEL 0x0E -mini PCI */ 335 ranges;
288 0x7000 0x0 0x0 0x1 &ipic 18 0x8 336
289 0x7000 0x0 0x0 0x2 &ipic 18 0x8 337 pci0: pci@e0008500 {
290 0x7000 0x0 0x0 0x3 &ipic 18 0x8 338 cell-index = <1>;
291 0x7000 0x0 0x0 0x4 &ipic 18 0x8 339 interrupt-map-mask = <0xf800 0x0 0x0 0x7>;
292 340 interrupt-map = <
293 /* IDSEL 0x0F - PCI slot */ 341 /* IDSEL 0x0E -mini PCI */
294 0x7800 0x0 0x0 0x1 &ipic 17 0x8 342 0x7000 0x0 0x0 0x1 &ipic 18 0x8
295 0x7800 0x0 0x0 0x2 &ipic 18 0x8 343 0x7000 0x0 0x0 0x2 &ipic 18 0x8
296 0x7800 0x0 0x0 0x3 &ipic 17 0x8 344 0x7000 0x0 0x0 0x3 &ipic 18 0x8
297 0x7800 0x0 0x0 0x4 &ipic 18 0x8>; 345 0x7000 0x0 0x0 0x4 &ipic 18 0x8
298 interrupt-parent = <&ipic>; 346
299 interrupts = <66 0x8>; 347 /* IDSEL 0x0F - PCI slot */
300 bus-range = <0x0 0x0>; 348 0x7800 0x0 0x0 0x1 &ipic 17 0x8
301 ranges = <0x02000000 0x0 0x90000000 0x90000000 0x0 0x10000000 349 0x7800 0x0 0x0 0x2 &ipic 18 0x8
302 0x42000000 0x0 0x80000000 0x80000000 0x0 0x10000000 350 0x7800 0x0 0x0 0x3 &ipic 17 0x8
303 0x01000000 0x0 0x00000000 0xe2000000 0x0 0x00100000>; 351 0x7800 0x0 0x0 0x4 &ipic 18 0x8>;
304 clock-frequency = <66666666>; 352 interrupt-parent = <&ipic>;
305 #interrupt-cells = <1>; 353 interrupts = <66 0x8>;
306 #size-cells = <2>; 354 bus-range = <0x0 0x0>;
307 #address-cells = <3>; 355 ranges = <0x02000000 0x0 0x90000000 0x90000000 0x0 0x10000000
308 reg = <0xe0008500 0x100>; 356 0x42000000 0x0 0x80000000 0x80000000 0x0 0x10000000
309 compatible = "fsl,mpc8349-pci"; 357 0x01000000 0x0 0x00000000 0xe2000000 0x0 0x00100000>;
310 device_type = "pci"; 358 clock-frequency = <66666666>;
359 #interrupt-cells = <1>;
360 #size-cells = <2>;
361 #address-cells = <3>;
362 reg = <0xe0008500 0x100>;
363 compatible = "fsl,mpc8349-pci";
364 device_type = "pci";
365 };
366
367 dma@82a8 {
368 #address-cells = <1>;
369 #size-cells = <1>;
370 compatible = "fsl,mpc8313-dma", "fsl,elo-dma";
371 reg = <0xe00082a8 4>;
372 ranges = <0 0xe0008100 0x1a8>;
373 interrupt-parent = <&ipic>;
374 interrupts = <71 8>;
375
376 dma-channel@0 {
377 compatible = "fsl,mpc8313-dma-channel",
378 "fsl,elo-dma-channel";
379 reg = <0 0x28>;
380 interrupt-parent = <&ipic>;
381 interrupts = <71 8>;
382 cell-index = <0>;
383 };
384
385 dma-channel@80 {
386 compatible = "fsl,mpc8313-dma-channel",
387 "fsl,elo-dma-channel";
388 reg = <0x80 0x28>;
389 interrupt-parent = <&ipic>;
390 interrupts = <71 8>;
391 cell-index = <1>;
392 };
393
394 dma-channel@100 {
395 compatible = "fsl,mpc8313-dma-channel",
396 "fsl,elo-dma-channel";
397 reg = <0x100 0x28>;
398 interrupt-parent = <&ipic>;
399 interrupts = <71 8>;
400 cell-index = <2>;
401 };
402
403 dma-channel@180 {
404 compatible = "fsl,mpc8313-dma-channel",
405 "fsl,elo-dma-channel";
406 reg = <0x180 0x28>;
407 interrupt-parent = <&ipic>;
408 interrupts = <71 8>;
409 cell-index = <3>;
410 };
411 };
311 }; 412 };
312}; 413};
diff --git a/arch/powerpc/boot/dts/mpc8610_hpcd.dts b/arch/powerpc/boot/dts/mpc8610_hpcd.dts
index 981941e5d7a5..666185f59459 100644
--- a/arch/powerpc/boot/dts/mpc8610_hpcd.dts
+++ b/arch/powerpc/boot/dts/mpc8610_hpcd.dts
@@ -388,6 +388,20 @@
388 0x01000000 0x0 0x00000000 388 0x01000000 0x0 0x00000000
389 0x01000000 0x0 0x00000000 389 0x01000000 0x0 0x00000000
390 0x0 0x00100000>; 390 0x0 0x00100000>;
391
392 isa@1e {
393 device_type = "isa";
394 #size-cells = <1>;
395 #address-cells = <2>;
396 reg = <0xf000 0 0 0 0>;
397 ranges = <1 0 0x01000000 0 0
398 0x00001000>;
399
400 rtc@70 {
401 compatible = "pnpPNP,b00";
402 reg = <1 0x70 2>;
403 };
404 };
391 }; 405 };
392 }; 406 };
393 }; 407 };
diff --git a/arch/powerpc/configs/85xx/mpc8544_ds_defconfig b/arch/powerpc/configs/85xx/mpc8544_ds_defconfig
index 042a85ea7b72..a0583e5119f5 100644
--- a/arch/powerpc/configs/85xx/mpc8544_ds_defconfig
+++ b/arch/powerpc/configs/85xx/mpc8544_ds_defconfig
@@ -997,10 +997,12 @@ CONFIG_SND=y
997CONFIG_SND_TIMER=y 997CONFIG_SND_TIMER=y
998CONFIG_SND_PCM=y 998CONFIG_SND_PCM=y
999# CONFIG_SND_SEQUENCER is not set 999# CONFIG_SND_SEQUENCER is not set
1000# CONFIG_SND_MIXER_OSS is not set 1000CONFIG_SND_OSSEMUL=y
1001# CONFIG_SND_PCM_OSS is not set 1001CONFIG_SND_MIXER_OSS=y
1002CONFIG_SND_PCM_OSS=y
1003CONFIG_SND_PCM_OSS_PLUGINS=y
1002# CONFIG_SND_DYNAMIC_MINORS is not set 1004# CONFIG_SND_DYNAMIC_MINORS is not set
1003CONFIG_SND_SUPPORT_OLD_API=y 1005# CONFIG_SND_SUPPORT_OLD_API is not set
1004CONFIG_SND_VERBOSE_PROCFS=y 1006CONFIG_SND_VERBOSE_PROCFS=y
1005# CONFIG_SND_VERBOSE_PRINTK is not set 1007# CONFIG_SND_VERBOSE_PRINTK is not set
1006# CONFIG_SND_DEBUG is not set 1008# CONFIG_SND_DEBUG is not set
diff --git a/arch/powerpc/configs/85xx/mpc8572_ds_defconfig b/arch/powerpc/configs/85xx/mpc8572_ds_defconfig
index 03627cfebcb4..164fd9606ee6 100644
--- a/arch/powerpc/configs/85xx/mpc8572_ds_defconfig
+++ b/arch/powerpc/configs/85xx/mpc8572_ds_defconfig
@@ -997,10 +997,12 @@ CONFIG_SND=y
997CONFIG_SND_TIMER=y 997CONFIG_SND_TIMER=y
998CONFIG_SND_PCM=y 998CONFIG_SND_PCM=y
999# CONFIG_SND_SEQUENCER is not set 999# CONFIG_SND_SEQUENCER is not set
1000# CONFIG_SND_MIXER_OSS is not set 1000CONFIG_SND_OSSEMUL=y
1001# CONFIG_SND_PCM_OSS is not set 1001CONFIG_SND_MIXER_OSS=y
1002CONFIG_SND_PCM_OSS=y
1003CONFIG_SND_PCM_OSS_PLUGINS=y
1002# CONFIG_SND_DYNAMIC_MINORS is not set 1004# CONFIG_SND_DYNAMIC_MINORS is not set
1003CONFIG_SND_SUPPORT_OLD_API=y 1005# CONFIG_SND_SUPPORT_OLD_API is not set
1004CONFIG_SND_VERBOSE_PROCFS=y 1006CONFIG_SND_VERBOSE_PROCFS=y
1005# CONFIG_SND_VERBOSE_PRINTK is not set 1007# CONFIG_SND_VERBOSE_PRINTK is not set
1006# CONFIG_SND_DEBUG is not set 1008# CONFIG_SND_DEBUG is not set
diff --git a/arch/powerpc/configs/mpc85xx_defconfig b/arch/powerpc/configs/mpc85xx_defconfig
index 3efab71a603b..fa0170504b88 100644
--- a/arch/powerpc/configs/mpc85xx_defconfig
+++ b/arch/powerpc/configs/mpc85xx_defconfig
@@ -1005,10 +1005,12 @@ CONFIG_SND=y
1005CONFIG_SND_TIMER=y 1005CONFIG_SND_TIMER=y
1006CONFIG_SND_PCM=y 1006CONFIG_SND_PCM=y
1007# CONFIG_SND_SEQUENCER is not set 1007# CONFIG_SND_SEQUENCER is not set
1008# CONFIG_SND_MIXER_OSS is not set 1008CONFIG_SND_OSSEMUL=y
1009# CONFIG_SND_PCM_OSS is not set 1009CONFIG_SND_MIXER_OSS=y
1010CONFIG_SND_PCM_OSS=y
1011CONFIG_SND_PCM_OSS_PLUGINS=y
1010# CONFIG_SND_DYNAMIC_MINORS is not set 1012# CONFIG_SND_DYNAMIC_MINORS is not set
1011CONFIG_SND_SUPPORT_OLD_API=y 1013# CONFIG_SND_SUPPORT_OLD_API is not set
1012CONFIG_SND_VERBOSE_PROCFS=y 1014CONFIG_SND_VERBOSE_PROCFS=y
1013# CONFIG_SND_VERBOSE_PRINTK is not set 1015# CONFIG_SND_VERBOSE_PRINTK is not set
1014# CONFIG_SND_DEBUG is not set 1016# CONFIG_SND_DEBUG is not set
diff --git a/arch/powerpc/configs/mpc8610_hpcd_defconfig b/arch/powerpc/configs/mpc8610_hpcd_defconfig
index 5612d40d0463..cdf98ae3682b 100644
--- a/arch/powerpc/configs/mpc8610_hpcd_defconfig
+++ b/arch/powerpc/configs/mpc8610_hpcd_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.26-rc5 3# Linux kernel version: 2.6.26
4# Mon Jun 9 08:50:24 2008 4# Tue Jul 15 08:31:01 2008
5# 5#
6# CONFIG_PPC64 is not set 6# CONFIG_PPC64 is not set
7 7
@@ -51,6 +51,8 @@ CONFIG_PPC_UDBG_16550=y
51CONFIG_AUDIT_ARCH=y 51CONFIG_AUDIT_ARCH=y
52CONFIG_GENERIC_BUG=y 52CONFIG_GENERIC_BUG=y
53CONFIG_DEFAULT_UIMAGE=y 53CONFIG_DEFAULT_UIMAGE=y
54CONFIG_HIBERNATE_32=y
55CONFIG_ARCH_HIBERNATION_POSSIBLE=y
54# CONFIG_PPC_DCR_NATIVE is not set 56# CONFIG_PPC_DCR_NATIVE is not set
55# CONFIG_PPC_DCR_MMIO is not set 57# CONFIG_PPC_DCR_MMIO is not set
56CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 58CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
@@ -97,6 +99,7 @@ CONFIG_HOTPLUG=y
97CONFIG_PRINTK=y 99CONFIG_PRINTK=y
98CONFIG_BUG=y 100CONFIG_BUG=y
99# CONFIG_ELF_CORE is not set 101# CONFIG_ELF_CORE is not set
102CONFIG_PCSPKR_PLATFORM=y
100CONFIG_COMPAT_BRK=y 103CONFIG_COMPAT_BRK=y
101CONFIG_BASE_FULL=y 104CONFIG_BASE_FULL=y
102CONFIG_FUTEX=y 105CONFIG_FUTEX=y
@@ -117,7 +120,7 @@ CONFIG_HAVE_OPROFILE=y
117# CONFIG_KPROBES is not set 120# CONFIG_KPROBES is not set
118CONFIG_HAVE_KPROBES=y 121CONFIG_HAVE_KPROBES=y
119CONFIG_HAVE_KRETPROBES=y 122CONFIG_HAVE_KRETPROBES=y
120# CONFIG_HAVE_DMA_ATTRS is not set 123CONFIG_HAVE_DMA_ATTRS=y
121CONFIG_PROC_PAGE_MONITOR=y 124CONFIG_PROC_PAGE_MONITOR=y
122CONFIG_SLABINFO=y 125CONFIG_SLABINFO=y
123CONFIG_RT_MUTEXES=y 126CONFIG_RT_MUTEXES=y
@@ -153,31 +156,43 @@ CONFIG_CLASSIC_RCU=y
153# 156#
154# Platform support 157# Platform support
155# 158#
156# CONFIG_PPC_MULTIPLATFORM is not set 159CONFIG_PPC_MULTIPLATFORM=y
157# CONFIG_PPC_82xx is not set 160CONFIG_CLASSIC32=y
158# CONFIG_PPC_83xx is not set 161CONFIG_PPC_CHRP=y
159CONFIG_PPC_86xx=y
160# CONFIG_PPC_MPC512x is not set 162# CONFIG_PPC_MPC512x is not set
161# CONFIG_PPC_MPC5121 is not set 163# CONFIG_PPC_MPC5121 is not set
164# CONFIG_MPC5121_ADS is not set
165# CONFIG_PPC_MPC52xx is not set
166CONFIG_PPC_PMAC=y
162# CONFIG_PPC_CELL is not set 167# CONFIG_PPC_CELL is not set
163# CONFIG_PPC_CELL_NATIVE is not set 168# CONFIG_PPC_CELL_NATIVE is not set
169# CONFIG_PPC_82xx is not set
164# CONFIG_PQ2ADS is not set 170# CONFIG_PQ2ADS is not set
171# CONFIG_PPC_83xx is not set
172CONFIG_PPC_86xx=y
165# CONFIG_MPC8641_HPCN is not set 173# CONFIG_MPC8641_HPCN is not set
166# CONFIG_SBC8641D is not set 174# CONFIG_SBC8641D is not set
167CONFIG_MPC8610_HPCD=y 175CONFIG_MPC8610_HPCD=y
168CONFIG_MPC8610=y 176CONFIG_MPC8610=y
177# CONFIG_EMBEDDED6xx is not set
178CONFIG_PPC_NATIVE=y
179# CONFIG_UDBG_RTAS_CONSOLE is not set
169# CONFIG_IPIC is not set 180# CONFIG_IPIC is not set
170CONFIG_MPIC=y 181CONFIG_MPIC=y
171# CONFIG_MPIC_WEIRD is not set 182# CONFIG_MPIC_WEIRD is not set
172# CONFIG_PPC_I8259 is not set 183CONFIG_PPC_I8259=y
173# CONFIG_PPC_RTAS is not set 184CONFIG_PPC_RTAS=y
185# CONFIG_RTAS_ERROR_LOGGING is not set
186CONFIG_RTAS_PROC=y
174# CONFIG_MMIO_NVRAM is not set 187# CONFIG_MMIO_NVRAM is not set
175# CONFIG_PPC_MPC106 is not set 188CONFIG_PPC_MPC106=y
176# CONFIG_PPC_970_NAP is not set 189# CONFIG_PPC_970_NAP is not set
177# CONFIG_PPC_INDIRECT_IO is not set 190# CONFIG_PPC_INDIRECT_IO is not set
178# CONFIG_GENERIC_IOMAP is not set 191# CONFIG_GENERIC_IOMAP is not set
179# CONFIG_CPU_FREQ is not set 192# CONFIG_CPU_FREQ is not set
180# CONFIG_FSL_ULI1575 is not set 193# CONFIG_PPC601_SYNC_FIX is not set
194# CONFIG_TAU is not set
195CONFIG_FSL_ULI1575=y
181 196
182# 197#
183# Kernel options 198# Kernel options
@@ -202,6 +217,7 @@ CONFIG_BINFMT_ELF=y
202CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y 217CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
203CONFIG_ARCH_HAS_WALK_MEMORY=y 218CONFIG_ARCH_HAS_WALK_MEMORY=y
204CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y 219CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
220# CONFIG_KEXEC is not set
205CONFIG_ARCH_FLATMEM_ENABLE=y 221CONFIG_ARCH_FLATMEM_ENABLE=y
206CONFIG_ARCH_POPULATES_NODE_MAP=y 222CONFIG_ARCH_POPULATES_NODE_MAP=y
207CONFIG_SELECT_MEMORY_MODEL=y 223CONFIG_SELECT_MEMORY_MODEL=y
@@ -228,11 +244,13 @@ CONFIG_ISA_DMA_API=y
228# 244#
229# Bus options 245# Bus options
230# 246#
247# CONFIG_ISA is not set
231CONFIG_ZONE_DMA=y 248CONFIG_ZONE_DMA=y
232CONFIG_GENERIC_ISA_DMA=y 249CONFIG_GENERIC_ISA_DMA=y
233CONFIG_PPC_INDIRECT_PCI=y 250CONFIG_PPC_INDIRECT_PCI=y
234CONFIG_FSL_SOC=y 251CONFIG_FSL_SOC=y
235CONFIG_FSL_PCI=y 252CONFIG_FSL_PCI=y
253CONFIG_PPC_PCI_CHOICE=y
236CONFIG_PCI=y 254CONFIG_PCI=y
237CONFIG_PCI_DOMAINS=y 255CONFIG_PCI_DOMAINS=y
238CONFIG_PCI_SYSCALL=y 256CONFIG_PCI_SYSCALL=y
@@ -469,6 +487,7 @@ CONFIG_OF_I2C=y
469# CONFIG_PARPORT is not set 487# CONFIG_PARPORT is not set
470CONFIG_BLK_DEV=y 488CONFIG_BLK_DEV=y
471# CONFIG_BLK_DEV_FD is not set 489# CONFIG_BLK_DEV_FD is not set
490# CONFIG_MAC_FLOPPY is not set
472# CONFIG_BLK_CPQ_DA is not set 491# CONFIG_BLK_CPQ_DA is not set
473# CONFIG_BLK_CPQ_CISS_DA is not set 492# CONFIG_BLK_CPQ_CISS_DA is not set
474# CONFIG_BLK_DEV_DAC960 is not set 493# CONFIG_BLK_DEV_DAC960 is not set
@@ -571,6 +590,8 @@ CONFIG_SCSI_LOWLEVEL=y
571# CONFIG_SCSI_DC390T is not set 590# CONFIG_SCSI_DC390T is not set
572# CONFIG_SCSI_NSP32 is not set 591# CONFIG_SCSI_NSP32 is not set
573# CONFIG_SCSI_DEBUG is not set 592# CONFIG_SCSI_DEBUG is not set
593# CONFIG_SCSI_MESH is not set
594# CONFIG_SCSI_MAC53C94 is not set
574# CONFIG_SCSI_SRP is not set 595# CONFIG_SCSI_SRP is not set
575CONFIG_ATA=y 596CONFIG_ATA=y
576# CONFIG_ATA_NONSTANDARD is not set 597# CONFIG_ATA_NONSTANDARD is not set
@@ -639,6 +660,10 @@ CONFIG_PATA_ALI=y
639# 660#
640# IEEE 1394 (FireWire) support 661# IEEE 1394 (FireWire) support
641# 662#
663
664#
665# Enable only one of the two stacks, unless you know what you are doing
666#
642# CONFIG_FIREWIRE is not set 667# CONFIG_FIREWIRE is not set
643# CONFIG_IEEE1394 is not set 668# CONFIG_IEEE1394 is not set
644# CONFIG_I2O is not set 669# CONFIG_I2O is not set
@@ -655,6 +680,8 @@ CONFIG_DUMMY=y
655# CONFIG_PHYLIB is not set 680# CONFIG_PHYLIB is not set
656CONFIG_NET_ETHERNET=y 681CONFIG_NET_ETHERNET=y
657# CONFIG_MII is not set 682# CONFIG_MII is not set
683# CONFIG_MACE is not set
684# CONFIG_BMAC is not set
658# CONFIG_HAPPYMEAL is not set 685# CONFIG_HAPPYMEAL is not set
659# CONFIG_SUNGEM is not set 686# CONFIG_SUNGEM is not set
660# CONFIG_CASSINI is not set 687# CONFIG_CASSINI is not set
@@ -762,14 +789,16 @@ CONFIG_SERIAL_8250_RSA=y
762# CONFIG_SERIAL_UARTLITE is not set 789# CONFIG_SERIAL_UARTLITE is not set
763CONFIG_SERIAL_CORE=y 790CONFIG_SERIAL_CORE=y
764CONFIG_SERIAL_CORE_CONSOLE=y 791CONFIG_SERIAL_CORE_CONSOLE=y
792# CONFIG_SERIAL_PMACZILOG is not set
765# CONFIG_SERIAL_JSM is not set 793# CONFIG_SERIAL_JSM is not set
766# CONFIG_SERIAL_OF_PLATFORM is not set 794# CONFIG_SERIAL_OF_PLATFORM is not set
767CONFIG_UNIX98_PTYS=y 795CONFIG_UNIX98_PTYS=y
768# CONFIG_LEGACY_PTYS is not set 796# CONFIG_LEGACY_PTYS is not set
797# CONFIG_BRIQ_PANEL is not set
798# CONFIG_HVC_RTAS is not set
769# CONFIG_IPMI_HANDLER is not set 799# CONFIG_IPMI_HANDLER is not set
770# CONFIG_HW_RANDOM is not set 800# CONFIG_HW_RANDOM is not set
771# CONFIG_NVRAM is not set 801# CONFIG_NVRAM is not set
772# CONFIG_GEN_RTC is not set
773# CONFIG_R3964 is not set 802# CONFIG_R3964 is not set
774# CONFIG_APPLICOM is not set 803# CONFIG_APPLICOM is not set
775# CONFIG_RAW_DRIVER is not set 804# CONFIG_RAW_DRIVER is not set
@@ -787,9 +816,11 @@ CONFIG_I2C_BOARDINFO=y
787# CONFIG_I2C_ALI15X3 is not set 816# CONFIG_I2C_ALI15X3 is not set
788# CONFIG_I2C_AMD756 is not set 817# CONFIG_I2C_AMD756 is not set
789# CONFIG_I2C_AMD8111 is not set 818# CONFIG_I2C_AMD8111 is not set
819# CONFIG_I2C_HYDRA is not set
790# CONFIG_I2C_I801 is not set 820# CONFIG_I2C_I801 is not set
791# CONFIG_I2C_I810 is not set 821# CONFIG_I2C_I810 is not set
792# CONFIG_I2C_PIIX4 is not set 822# CONFIG_I2C_PIIX4 is not set
823CONFIG_I2C_POWERMAC=y
793CONFIG_I2C_MPC=y 824CONFIG_I2C_MPC=y
794# CONFIG_I2C_NFORCE2 is not set 825# CONFIG_I2C_NFORCE2 is not set
795# CONFIG_I2C_OCORES is not set 826# CONFIG_I2C_OCORES is not set
@@ -826,6 +857,7 @@ CONFIG_I2C_MPC=y
826# CONFIG_POWER_SUPPLY is not set 857# CONFIG_POWER_SUPPLY is not set
827# CONFIG_HWMON is not set 858# CONFIG_HWMON is not set
828# CONFIG_THERMAL is not set 859# CONFIG_THERMAL is not set
860# CONFIG_THERMAL_HWMON is not set
829# CONFIG_WATCHDOG is not set 861# CONFIG_WATCHDOG is not set
830 862
831# 863#
@@ -888,6 +920,9 @@ CONFIG_FB_CFB_IMAGEBLIT=y
888# CONFIG_FB_PM2 is not set 920# CONFIG_FB_PM2 is not set
889# CONFIG_FB_CYBER2000 is not set 921# CONFIG_FB_CYBER2000 is not set
890# CONFIG_FB_OF is not set 922# CONFIG_FB_OF is not set
923# CONFIG_FB_CONTROL is not set
924# CONFIG_FB_PLATINUM is not set
925# CONFIG_FB_VALKYRIE is not set
891# CONFIG_FB_CT65550 is not set 926# CONFIG_FB_CT65550 is not set
892# CONFIG_FB_ASILIANT is not set 927# CONFIG_FB_ASILIANT is not set
893# CONFIG_FB_IMSTT is not set 928# CONFIG_FB_IMSTT is not set
@@ -1027,12 +1062,19 @@ CONFIG_SND_VERBOSE_PROCFS=y
1027# 1062#
1028# ALSA PowerMac devices 1063# ALSA PowerMac devices
1029# 1064#
1065# CONFIG_SND_POWERMAC is not set
1030 1066
1031# 1067#
1032# ALSA PowerPC devices 1068# ALSA PowerPC devices
1033# 1069#
1034 1070
1035# 1071#
1072# Apple Onboard Audio driver
1073#
1074# CONFIG_SND_AOA is not set
1075# CONFIG_SND_AOA_SOUNDBUS is not set
1076
1077#
1036# System on Chip audio support 1078# System on Chip audio support
1037# 1079#
1038CONFIG_SND_SOC=y 1080CONFIG_SND_SOC=y
@@ -1075,7 +1117,57 @@ CONFIG_USB_ARCH_HAS_EHCI=y
1075# CONFIG_ACCESSIBILITY is not set 1117# CONFIG_ACCESSIBILITY is not set
1076# CONFIG_INFINIBAND is not set 1118# CONFIG_INFINIBAND is not set
1077# CONFIG_EDAC is not set 1119# CONFIG_EDAC is not set
1078# CONFIG_RTC_CLASS is not set 1120CONFIG_RTC_LIB=y
1121CONFIG_RTC_CLASS=y
1122CONFIG_RTC_HCTOSYS=y
1123CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
1124# CONFIG_RTC_DEBUG is not set
1125
1126#
1127# RTC interfaces
1128#
1129CONFIG_RTC_INTF_SYSFS=y
1130CONFIG_RTC_INTF_PROC=y
1131CONFIG_RTC_INTF_DEV=y
1132# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1133# CONFIG_RTC_DRV_TEST is not set
1134
1135#
1136# I2C RTC drivers
1137#
1138# CONFIG_RTC_DRV_DS1307 is not set
1139# CONFIG_RTC_DRV_DS1374 is not set
1140# CONFIG_RTC_DRV_DS1672 is not set
1141# CONFIG_RTC_DRV_MAX6900 is not set
1142# CONFIG_RTC_DRV_RS5C372 is not set
1143# CONFIG_RTC_DRV_ISL1208 is not set
1144# CONFIG_RTC_DRV_X1205 is not set
1145# CONFIG_RTC_DRV_PCF8563 is not set
1146# CONFIG_RTC_DRV_PCF8583 is not set
1147# CONFIG_RTC_DRV_M41T80 is not set
1148# CONFIG_RTC_DRV_S35390A is not set
1149# CONFIG_RTC_DRV_FM3130 is not set
1150
1151#
1152# SPI RTC drivers
1153#
1154
1155#
1156# Platform RTC drivers
1157#
1158CONFIG_RTC_DRV_CMOS=y
1159# CONFIG_RTC_DRV_DS1511 is not set
1160# CONFIG_RTC_DRV_DS1553 is not set
1161# CONFIG_RTC_DRV_DS1742 is not set
1162# CONFIG_RTC_DRV_STK17TA8 is not set
1163# CONFIG_RTC_DRV_M48T86 is not set
1164# CONFIG_RTC_DRV_M48T59 is not set
1165# CONFIG_RTC_DRV_V3020 is not set
1166
1167#
1168# on-CPU RTC drivers
1169#
1170# CONFIG_RTC_DRV_PPC is not set
1079# CONFIG_DMADEVICES is not set 1171# CONFIG_DMADEVICES is not set
1080# CONFIG_UIO is not set 1172# CONFIG_UIO is not set
1081 1173
@@ -1295,8 +1387,11 @@ CONFIG_DEBUG_INFO=y
1295# CONFIG_DEBUG_STACK_USAGE is not set 1387# CONFIG_DEBUG_STACK_USAGE is not set
1296# CONFIG_DEBUG_PAGEALLOC is not set 1388# CONFIG_DEBUG_PAGEALLOC is not set
1297# CONFIG_DEBUGGER is not set 1389# CONFIG_DEBUGGER is not set
1390# CONFIG_CODE_PATCHING_SELFTEST is not set
1391# CONFIG_FTR_FIXUP_SELFTEST is not set
1298# CONFIG_IRQSTACKS is not set 1392# CONFIG_IRQSTACKS is not set
1299# CONFIG_BDI_SWITCH is not set 1393# CONFIG_BDI_SWITCH is not set
1394# CONFIG_BOOTX_TEXT is not set
1300# CONFIG_PPC_EARLY_DEBUG is not set 1395# CONFIG_PPC_EARLY_DEBUG is not set
1301 1396
1302# 1397#
diff --git a/arch/powerpc/configs/mpc8641_hpcn_defconfig b/arch/powerpc/configs/mpc8641_hpcn_defconfig
index 4a8171507391..867b8c0215f3 100644
--- a/arch/powerpc/configs/mpc8641_hpcn_defconfig
+++ b/arch/powerpc/configs/mpc8641_hpcn_defconfig
@@ -991,10 +991,12 @@ CONFIG_SND=y
991CONFIG_SND_TIMER=y 991CONFIG_SND_TIMER=y
992CONFIG_SND_PCM=y 992CONFIG_SND_PCM=y
993# CONFIG_SND_SEQUENCER is not set 993# CONFIG_SND_SEQUENCER is not set
994# CONFIG_SND_MIXER_OSS is not set 994CONFIG_SND_OSSEMUL=y
995# CONFIG_SND_PCM_OSS is not set 995CONFIG_SND_MIXER_OSS=y
996CONFIG_SND_PCM_OSS=y
997CONFIG_SND_PCM_OSS_PLUGINS=y
996# CONFIG_SND_DYNAMIC_MINORS is not set 998# CONFIG_SND_DYNAMIC_MINORS is not set
997CONFIG_SND_SUPPORT_OLD_API=y 999# CONFIG_SND_SUPPORT_OLD_API is not set
998CONFIG_SND_VERBOSE_PROCFS=y 1000CONFIG_SND_VERBOSE_PROCFS=y
999# CONFIG_SND_VERBOSE_PRINTK is not set 1001# CONFIG_SND_VERBOSE_PRINTK is not set
1000# CONFIG_SND_DEBUG is not set 1002# CONFIG_SND_DEBUG is not set
diff --git a/arch/powerpc/configs/ppc6xx_defconfig b/arch/powerpc/configs/ppc6xx_defconfig
new file mode 100644
index 000000000000..e6e91c85da31
--- /dev/null
+++ b/arch/powerpc/configs/ppc6xx_defconfig
@@ -0,0 +1,3304 @@
1# powerpc
2#
3# Automatically generated make config: don't edit
4# Linux kernel version: 2.6.26-git2
5# Tue Jul 15 23:54:18 2008
6#
7# CONFIG_PPC64 is not set
8
9#
10# Processor support
11#
12CONFIG_6xx=y
13# CONFIG_PPC_85xx is not set
14# CONFIG_PPC_8xx is not set
15# CONFIG_40x is not set
16# CONFIG_44x is not set
17# CONFIG_E200 is not set
18CONFIG_PPC_FPU=y
19CONFIG_FSL_EMB_PERFMON=y
20CONFIG_ALTIVEC=y
21CONFIG_PPC_STD_MMU=y
22CONFIG_PPC_STD_MMU_32=y
23# CONFIG_PPC_MM_SLICES is not set
24# CONFIG_SMP is not set
25CONFIG_PPC32=y
26CONFIG_WORD_SIZE=32
27CONFIG_PPC_MERGE=y
28CONFIG_MMU=y
29CONFIG_GENERIC_CMOS_UPDATE=y
30CONFIG_GENERIC_TIME=y
31CONFIG_GENERIC_TIME_VSYSCALL=y
32CONFIG_GENERIC_CLOCKEVENTS=y
33CONFIG_GENERIC_HARDIRQS=y
34# CONFIG_HAVE_SETUP_PER_CPU_AREA is not set
35CONFIG_IRQ_PER_CPU=y
36CONFIG_STACKTRACE_SUPPORT=y
37CONFIG_HAVE_LATENCYTOP_SUPPORT=y
38CONFIG_LOCKDEP_SUPPORT=y
39CONFIG_RWSEM_XCHGADD_ALGORITHM=y
40CONFIG_ARCH_HAS_ILOG2_U32=y
41CONFIG_GENERIC_HWEIGHT=y
42CONFIG_GENERIC_CALIBRATE_DELAY=y
43CONFIG_GENERIC_FIND_NEXT_BIT=y
44CONFIG_GENERIC_GPIO=y
45# CONFIG_ARCH_NO_VIRT_TO_BUS is not set
46CONFIG_PPC=y
47CONFIG_EARLY_PRINTK=y
48CONFIG_GENERIC_NVRAM=y
49CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
50CONFIG_ARCH_MAY_HAVE_PC_FDC=y
51CONFIG_PPC_OF=y
52CONFIG_OF=y
53CONFIG_PPC_UDBG_16550=y
54# CONFIG_GENERIC_TBSYNC is not set
55CONFIG_AUDIT_ARCH=y
56CONFIG_GENERIC_BUG=y
57CONFIG_SYS_SUPPORTS_APM_EMULATION=y
58CONFIG_DEFAULT_UIMAGE=y
59CONFIG_REDBOOT=y
60CONFIG_HIBERNATE_32=y
61CONFIG_ARCH_HIBERNATION_POSSIBLE=y
62CONFIG_ARCH_SUSPEND_POSSIBLE=y
63# CONFIG_PPC_DCR_NATIVE is not set
64# CONFIG_PPC_DCR_MMIO is not set
65CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
66
67#
68# General setup
69#
70CONFIG_EXPERIMENTAL=y
71CONFIG_BROKEN_ON_SMP=y
72CONFIG_INIT_ENV_ARG_LIMIT=32
73CONFIG_LOCALVERSION=""
74# CONFIG_LOCALVERSION_AUTO is not set
75CONFIG_SWAP=y
76CONFIG_SYSVIPC=y
77CONFIG_SYSVIPC_SYSCTL=y
78CONFIG_POSIX_MQUEUE=y
79CONFIG_BSD_PROCESS_ACCT=y
80# CONFIG_BSD_PROCESS_ACCT_V3 is not set
81CONFIG_TASKSTATS=y
82CONFIG_TASK_DELAY_ACCT=y
83CONFIG_TASK_XACCT=y
84CONFIG_TASK_IO_ACCOUNTING=y
85CONFIG_AUDIT=y
86CONFIG_AUDITSYSCALL=y
87CONFIG_AUDIT_TREE=y
88# CONFIG_IKCONFIG is not set
89CONFIG_LOG_BUF_SHIFT=17
90CONFIG_CGROUPS=y
91# CONFIG_CGROUP_DEBUG is not set
92CONFIG_CGROUP_NS=y
93CONFIG_CGROUP_DEVICE=y
94CONFIG_GROUP_SCHED=y
95CONFIG_FAIR_GROUP_SCHED=y
96CONFIG_RT_GROUP_SCHED=y
97# CONFIG_USER_SCHED is not set
98CONFIG_CGROUP_SCHED=y
99CONFIG_CGROUP_CPUACCT=y
100CONFIG_RESOURCE_COUNTERS=y
101# CONFIG_CGROUP_MEM_RES_CTLR is not set
102# CONFIG_SYSFS_DEPRECATED_V2 is not set
103CONFIG_RELAY=y
104CONFIG_NAMESPACES=y
105CONFIG_UTS_NS=y
106CONFIG_IPC_NS=y
107CONFIG_USER_NS=y
108CONFIG_PID_NS=y
109CONFIG_BLK_DEV_INITRD=y
110CONFIG_INITRAMFS_SOURCE=""
111CONFIG_CC_OPTIMIZE_FOR_SIZE=y
112CONFIG_SYSCTL=y
113# CONFIG_EMBEDDED is not set
114CONFIG_SYSCTL_SYSCALL=y
115CONFIG_SYSCTL_SYSCALL_CHECK=y
116CONFIG_KALLSYMS=y
117CONFIG_KALLSYMS_ALL=y
118CONFIG_KALLSYMS_EXTRA_PASS=y
119CONFIG_HOTPLUG=y
120CONFIG_PRINTK=y
121CONFIG_BUG=y
122CONFIG_ELF_CORE=y
123CONFIG_PCSPKR_PLATFORM=y
124# CONFIG_COMPAT_BRK is not set
125CONFIG_BASE_FULL=y
126CONFIG_FUTEX=y
127CONFIG_ANON_INODES=y
128CONFIG_EPOLL=y
129CONFIG_SIGNALFD=y
130CONFIG_TIMERFD=y
131CONFIG_EVENTFD=y
132CONFIG_SHMEM=y
133CONFIG_VM_EVENT_COUNTERS=y
134CONFIG_SLUB_DEBUG=y
135# CONFIG_SLAB is not set
136CONFIG_SLUB=y
137# CONFIG_SLOB is not set
138CONFIG_PROFILING=y
139CONFIG_MARKERS=y
140CONFIG_OPROFILE=m
141CONFIG_HAVE_OPROFILE=y
142CONFIG_KPROBES=y
143CONFIG_KRETPROBES=y
144CONFIG_HAVE_KPROBES=y
145CONFIG_HAVE_KRETPROBES=y
146# CONFIG_HAVE_DMA_ATTRS is not set
147# CONFIG_USE_GENERIC_SMP_HELPERS is not set
148CONFIG_PROC_PAGE_MONITOR=y
149CONFIG_SLABINFO=y
150CONFIG_RT_MUTEXES=y
151# CONFIG_TINY_SHMEM is not set
152CONFIG_BASE_SMALL=0
153CONFIG_MODULES=y
154# CONFIG_MODULE_FORCE_LOAD is not set
155CONFIG_MODULE_UNLOAD=y
156# CONFIG_MODULE_FORCE_UNLOAD is not set
157# CONFIG_MODVERSIONS is not set
158CONFIG_MODULE_SRCVERSION_ALL=y
159CONFIG_KMOD=y
160CONFIG_BLOCK=y
161CONFIG_LBD=y
162CONFIG_BLK_DEV_IO_TRACE=y
163CONFIG_LSF=y
164CONFIG_BLK_DEV_BSG=y
165CONFIG_BLK_DEV_INTEGRITY=y
166
167#
168# IO Schedulers
169#
170CONFIG_IOSCHED_NOOP=y
171CONFIG_IOSCHED_AS=y
172CONFIG_IOSCHED_DEADLINE=y
173CONFIG_IOSCHED_CFQ=y
174# CONFIG_DEFAULT_AS is not set
175# CONFIG_DEFAULT_DEADLINE is not set
176CONFIG_DEFAULT_CFQ=y
177# CONFIG_DEFAULT_NOOP is not set
178CONFIG_DEFAULT_IOSCHED="cfq"
179CONFIG_CLASSIC_RCU=y
180
181#
182# Platform support
183#
184CONFIG_PPC_MULTIPLATFORM=y
185CONFIG_CLASSIC32=y
186CONFIG_PPC_CHRP=y
187# CONFIG_MPC5121_ADS is not set
188# CONFIG_MPC5121_GENERIC is not set
189CONFIG_PPC_MPC52xx=y
190# CONFIG_PPC_MPC5200_SIMPLE is not set
191CONFIG_PPC_EFIKA=y
192# CONFIG_PPC_LITE5200 is not set
193CONFIG_PPC_MPC5200_BUGFIX=y
194CONFIG_PPC_MPC5200_GPIO=y
195CONFIG_PPC_PMAC=y
196# CONFIG_PPC_CELL is not set
197# CONFIG_PPC_CELL_NATIVE is not set
198CONFIG_PPC_82xx=y
199CONFIG_MPC8272_ADS=y
200CONFIG_PQ2FADS=y
201CONFIG_EP8248E=y
202CONFIG_PQ2ADS=y
203CONFIG_8260=y
204CONFIG_8272=y
205CONFIG_PQ2_ADS_PCI_PIC=y
206CONFIG_PPC_83xx=y
207CONFIG_MPC831x_RDB=y
208CONFIG_MPC832x_MDS=y
209CONFIG_MPC832x_RDB=y
210CONFIG_MPC834x_MDS=y
211CONFIG_MPC834x_ITX=y
212CONFIG_MPC836x_MDS=y
213CONFIG_MPC836x_RDK=y
214CONFIG_MPC837x_MDS=y
215CONFIG_MPC837x_RDB=y
216CONFIG_SBC834x=y
217CONFIG_ASP834x=y
218CONFIG_PPC_MPC831x=y
219CONFIG_PPC_MPC832x=y
220CONFIG_PPC_MPC834x=y
221CONFIG_PPC_MPC837x=y
222CONFIG_PPC_86xx=y
223CONFIG_MPC8641_HPCN=y
224CONFIG_SBC8641D=y
225CONFIG_MPC8610_HPCD=y
226CONFIG_MPC8641=y
227CONFIG_MPC8610=y
228# CONFIG_EMBEDDED6xx is not set
229CONFIG_PPC_NATIVE=y
230# CONFIG_UDBG_RTAS_CONSOLE is not set
231CONFIG_IPIC=y
232CONFIG_MPIC=y
233# CONFIG_MPIC_WEIRD is not set
234CONFIG_PPC_I8259=y
235CONFIG_PPC_RTAS=y
236# CONFIG_RTAS_ERROR_LOGGING is not set
237CONFIG_RTAS_PROC=y
238# CONFIG_MMIO_NVRAM is not set
239CONFIG_PPC_MPC106=y
240# CONFIG_PPC_970_NAP is not set
241# CONFIG_PPC_INDIRECT_IO is not set
242# CONFIG_GENERIC_IOMAP is not set
243CONFIG_CPU_FREQ=y
244CONFIG_CPU_FREQ_TABLE=y
245CONFIG_CPU_FREQ_DEBUG=y
246CONFIG_CPU_FREQ_STAT=m
247CONFIG_CPU_FREQ_STAT_DETAILS=y
248# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set
249# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set
250CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y
251# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set
252# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set
253CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
254CONFIG_CPU_FREQ_GOV_POWERSAVE=m
255CONFIG_CPU_FREQ_GOV_USERSPACE=y
256CONFIG_CPU_FREQ_GOV_ONDEMAND=m
257CONFIG_CPU_FREQ_GOV_CONSERVATIVE=m
258
259#
260# CPU Frequency drivers
261#
262CONFIG_CPU_FREQ_PMAC=y
263# CONFIG_PPC601_SYNC_FIX is not set
264CONFIG_TAU=y
265# CONFIG_TAU_INT is not set
266CONFIG_TAU_AVERAGE=y
267CONFIG_QUICC_ENGINE=y
268CONFIG_CPM2=y
269CONFIG_PPC_CPM_NEW_BINDING=y
270CONFIG_FSL_ULI1575=y
271CONFIG_CPM=y
272CONFIG_PPC_BESTCOMM=y
273CONFIG_PPC_BESTCOMM_ATA=m
274CONFIG_PPC_BESTCOMM_FEC=m
275CONFIG_PPC_BESTCOMM_GEN_BD=m
276
277#
278# Kernel options
279#
280CONFIG_HIGHMEM=y
281CONFIG_TICK_ONESHOT=y
282CONFIG_NO_HZ=y
283CONFIG_HIGH_RES_TIMERS=y
284CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
285# CONFIG_HZ_100 is not set
286# CONFIG_HZ_250 is not set
287# CONFIG_HZ_300 is not set
288CONFIG_HZ_1000=y
289CONFIG_HZ=1000
290# CONFIG_SCHED_HRTICK is not set
291# CONFIG_PREEMPT_NONE is not set
292CONFIG_PREEMPT_VOLUNTARY=y
293# CONFIG_PREEMPT is not set
294CONFIG_BINFMT_ELF=y
295CONFIG_BINFMT_MISC=y
296# CONFIG_MATH_EMULATION is not set
297# CONFIG_IOMMU_HELPER is not set
298CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
299CONFIG_ARCH_HAS_WALK_MEMORY=y
300CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
301# CONFIG_KEXEC is not set
302CONFIG_ARCH_FLATMEM_ENABLE=y
303CONFIG_ARCH_POPULATES_NODE_MAP=y
304CONFIG_SELECT_MEMORY_MODEL=y
305CONFIG_FLATMEM_MANUAL=y
306# CONFIG_DISCONTIGMEM_MANUAL is not set
307# CONFIG_SPARSEMEM_MANUAL is not set
308CONFIG_FLATMEM=y
309CONFIG_FLAT_NODE_MEM_MAP=y
310# CONFIG_SPARSEMEM_STATIC is not set
311# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
312CONFIG_PAGEFLAGS_EXTENDED=y
313CONFIG_SPLIT_PTLOCK_CPUS=4
314CONFIG_RESOURCES_64BIT=y
315CONFIG_ZONE_DMA_FLAG=1
316CONFIG_BOUNCE=y
317CONFIG_VIRT_TO_BUS=y
318CONFIG_FORCE_MAX_ZONEORDER=11
319CONFIG_PROC_DEVICETREE=y
320# CONFIG_CMDLINE_BOOL is not set
321CONFIG_EXTRA_TARGETS=""
322CONFIG_ARCH_WANTS_FREEZER_CONTROL=y
323CONFIG_PM=y
324CONFIG_PM_DEBUG=y
325# CONFIG_PM_VERBOSE is not set
326CONFIG_CAN_PM_TRACE=y
327CONFIG_PM_SLEEP=y
328CONFIG_SUSPEND=y
329CONFIG_SUSPEND_FREEZER=y
330CONFIG_HIBERNATION=y
331CONFIG_PM_STD_PARTITION=""
332CONFIG_APM_EMULATION=y
333CONFIG_SECCOMP=y
334CONFIG_ISA_DMA_API=y
335
336#
337# Bus options
338#
339CONFIG_ISA=y
340CONFIG_ZONE_DMA=y
341CONFIG_GENERIC_ISA_DMA=y
342CONFIG_PPC_INDIRECT_PCI=y
343CONFIG_FSL_SOC=y
344CONFIG_FSL_PCI=y
345CONFIG_FSL_LBC=y
346CONFIG_FSL_GTM=y
347CONFIG_PCI=y
348CONFIG_PCI_DOMAINS=y
349CONFIG_PCI_SYSCALL=y
350CONFIG_PCI_8260=y
351CONFIG_PCIEPORTBUS=y
352CONFIG_PCIEAER=y
353CONFIG_PCIEASPM=y
354# CONFIG_PCIEASPM_DEBUG is not set
355CONFIG_ARCH_SUPPORTS_MSI=y
356CONFIG_PCI_MSI=y
357CONFIG_PCI_LEGACY=y
358# CONFIG_PCI_DEBUG is not set
359CONFIG_PCCARD=y
360# CONFIG_PCMCIA_DEBUG is not set
361CONFIG_PCMCIA=y
362CONFIG_PCMCIA_LOAD_CIS=y
363CONFIG_PCMCIA_IOCTL=y
364CONFIG_CARDBUS=y
365
366#
367# PC-card bridges
368#
369CONFIG_YENTA=y
370CONFIG_YENTA_O2=y
371CONFIG_YENTA_RICOH=y
372CONFIG_YENTA_TI=y
373CONFIG_YENTA_ENE_TUNE=y
374CONFIG_YENTA_TOSHIBA=y
375CONFIG_PD6729=m
376CONFIG_I82092=m
377CONFIG_I82365=m
378# CONFIG_TCIC is not set
379CONFIG_PCMCIA_PROBE=y
380CONFIG_PCCARD_NONSTATIC=y
381# CONFIG_HOTPLUG_PCI is not set
382CONFIG_HAS_RAPIDIO=y
383# CONFIG_RAPIDIO is not set
384
385#
386# Advanced setup
387#
388CONFIG_ADVANCED_OPTIONS=y
389# CONFIG_LOWMEM_SIZE_BOOL is not set
390CONFIG_LOWMEM_SIZE=0x30000000
391# CONFIG_PAGE_OFFSET_BOOL is not set
392CONFIG_PAGE_OFFSET=0xc0000000
393# CONFIG_KERNEL_START_BOOL is not set
394CONFIG_KERNEL_START=0xc0000000
395CONFIG_PHYSICAL_START=0x00000000
396# CONFIG_TASK_SIZE_BOOL is not set
397CONFIG_TASK_SIZE=0xc0000000
398
399#
400# Networking
401#
402CONFIG_NET=y
403
404#
405# Networking options
406#
407CONFIG_PACKET=y
408CONFIG_PACKET_MMAP=y
409CONFIG_UNIX=y
410CONFIG_XFRM=y
411CONFIG_XFRM_USER=y
412CONFIG_XFRM_SUB_POLICY=y
413CONFIG_XFRM_MIGRATE=y
414CONFIG_XFRM_STATISTICS=y
415CONFIG_NET_KEY=m
416CONFIG_NET_KEY_MIGRATE=y
417CONFIG_INET=y
418CONFIG_IP_MULTICAST=y
419CONFIG_IP_ADVANCED_ROUTER=y
420CONFIG_ASK_IP_FIB_HASH=y
421# CONFIG_IP_FIB_TRIE is not set
422CONFIG_IP_FIB_HASH=y
423CONFIG_IP_MULTIPLE_TABLES=y
424CONFIG_IP_ROUTE_MULTIPATH=y
425CONFIG_IP_ROUTE_VERBOSE=y
426# CONFIG_IP_PNP is not set
427CONFIG_NET_IPIP=m
428CONFIG_NET_IPGRE=m
429CONFIG_NET_IPGRE_BROADCAST=y
430CONFIG_IP_MROUTE=y
431CONFIG_IP_PIMSM_V1=y
432CONFIG_IP_PIMSM_V2=y
433# CONFIG_ARPD is not set
434CONFIG_SYN_COOKIES=y
435CONFIG_INET_AH=m
436CONFIG_INET_ESP=m
437CONFIG_INET_IPCOMP=m
438CONFIG_INET_XFRM_TUNNEL=m
439CONFIG_INET_TUNNEL=m
440CONFIG_INET_XFRM_MODE_TRANSPORT=m
441CONFIG_INET_XFRM_MODE_TUNNEL=m
442CONFIG_INET_XFRM_MODE_BEET=m
443CONFIG_INET_LRO=y
444CONFIG_INET_DIAG=m
445CONFIG_INET_TCP_DIAG=m
446CONFIG_TCP_CONG_ADVANCED=y
447CONFIG_TCP_CONG_BIC=m
448CONFIG_TCP_CONG_CUBIC=y
449CONFIG_TCP_CONG_WESTWOOD=m
450CONFIG_TCP_CONG_HTCP=m
451CONFIG_TCP_CONG_HSTCP=m
452CONFIG_TCP_CONG_HYBLA=m
453CONFIG_TCP_CONG_VEGAS=m
454CONFIG_TCP_CONG_SCALABLE=m
455CONFIG_TCP_CONG_LP=m
456CONFIG_TCP_CONG_VENO=m
457CONFIG_TCP_CONG_YEAH=m
458CONFIG_TCP_CONG_ILLINOIS=m
459# CONFIG_DEFAULT_BIC is not set
460CONFIG_DEFAULT_CUBIC=y
461# CONFIG_DEFAULT_HTCP is not set
462# CONFIG_DEFAULT_VEGAS is not set
463# CONFIG_DEFAULT_WESTWOOD is not set
464# CONFIG_DEFAULT_RENO is not set
465CONFIG_DEFAULT_TCP_CONG="cubic"
466CONFIG_TCP_MD5SIG=y
467# CONFIG_IP_VS is not set
468CONFIG_IPV6=m
469CONFIG_IPV6_PRIVACY=y
470CONFIG_IPV6_ROUTER_PREF=y
471CONFIG_IPV6_ROUTE_INFO=y
472CONFIG_IPV6_OPTIMISTIC_DAD=y
473CONFIG_INET6_AH=m
474CONFIG_INET6_ESP=m
475CONFIG_INET6_IPCOMP=m
476CONFIG_IPV6_MIP6=m
477CONFIG_INET6_XFRM_TUNNEL=m
478CONFIG_INET6_TUNNEL=m
479CONFIG_INET6_XFRM_MODE_TRANSPORT=m
480CONFIG_INET6_XFRM_MODE_TUNNEL=m
481CONFIG_INET6_XFRM_MODE_BEET=m
482CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m
483CONFIG_IPV6_SIT=m
484CONFIG_IPV6_NDISC_NODETYPE=y
485CONFIG_IPV6_TUNNEL=m
486CONFIG_IPV6_MULTIPLE_TABLES=y
487CONFIG_IPV6_SUBTREES=y
488CONFIG_IPV6_MROUTE=y
489CONFIG_IPV6_PIMSM_V2=y
490CONFIG_NETLABEL=y
491CONFIG_NETWORK_SECMARK=y
492CONFIG_NETFILTER=y
493# CONFIG_NETFILTER_DEBUG is not set
494CONFIG_NETFILTER_ADVANCED=y
495CONFIG_BRIDGE_NETFILTER=y
496
497#
498# Core Netfilter Configuration
499#
500CONFIG_NETFILTER_NETLINK=m
501CONFIG_NETFILTER_NETLINK_QUEUE=m
502CONFIG_NETFILTER_NETLINK_LOG=m
503CONFIG_NF_CONNTRACK=m
504CONFIG_NF_CT_ACCT=y
505CONFIG_NF_CONNTRACK_MARK=y
506CONFIG_NF_CONNTRACK_SECMARK=y
507CONFIG_NF_CONNTRACK_EVENTS=y
508CONFIG_NF_CT_PROTO_DCCP=m
509CONFIG_NF_CT_PROTO_GRE=m
510CONFIG_NF_CT_PROTO_SCTP=m
511CONFIG_NF_CT_PROTO_UDPLITE=m
512CONFIG_NF_CONNTRACK_AMANDA=m
513CONFIG_NF_CONNTRACK_FTP=m
514CONFIG_NF_CONNTRACK_H323=m
515CONFIG_NF_CONNTRACK_IRC=m
516CONFIG_NF_CONNTRACK_NETBIOS_NS=m
517CONFIG_NF_CONNTRACK_PPTP=m
518CONFIG_NF_CONNTRACK_SANE=m
519CONFIG_NF_CONNTRACK_SIP=m
520CONFIG_NF_CONNTRACK_TFTP=m
521CONFIG_NF_CT_NETLINK=m
522CONFIG_NETFILTER_XTABLES=m
523CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
524CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
525CONFIG_NETFILTER_XT_TARGET_DSCP=m
526CONFIG_NETFILTER_XT_TARGET_MARK=m
527CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
528CONFIG_NETFILTER_XT_TARGET_NFLOG=m
529CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
530CONFIG_NETFILTER_XT_TARGET_RATEEST=m
531CONFIG_NETFILTER_XT_TARGET_TRACE=m
532CONFIG_NETFILTER_XT_TARGET_SECMARK=m
533CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=m
534CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
535CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
536CONFIG_NETFILTER_XT_MATCH_COMMENT=m
537CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
538CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
539CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
540CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
541CONFIG_NETFILTER_XT_MATCH_DCCP=m
542CONFIG_NETFILTER_XT_MATCH_DSCP=m
543CONFIG_NETFILTER_XT_MATCH_ESP=m
544CONFIG_NETFILTER_XT_MATCH_HELPER=m
545CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
546CONFIG_NETFILTER_XT_MATCH_LENGTH=m
547CONFIG_NETFILTER_XT_MATCH_LIMIT=m
548CONFIG_NETFILTER_XT_MATCH_MAC=m
549CONFIG_NETFILTER_XT_MATCH_MARK=m
550CONFIG_NETFILTER_XT_MATCH_OWNER=m
551CONFIG_NETFILTER_XT_MATCH_POLICY=m
552CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
553CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
554CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
555CONFIG_NETFILTER_XT_MATCH_QUOTA=m
556CONFIG_NETFILTER_XT_MATCH_RATEEST=m
557CONFIG_NETFILTER_XT_MATCH_REALM=m
558CONFIG_NETFILTER_XT_MATCH_SCTP=m
559CONFIG_NETFILTER_XT_MATCH_STATE=m
560CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
561CONFIG_NETFILTER_XT_MATCH_STRING=m
562CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
563CONFIG_NETFILTER_XT_MATCH_TIME=m
564CONFIG_NETFILTER_XT_MATCH_U32=m
565CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
566
567#
568# IP: Netfilter Configuration
569#
570CONFIG_NF_CONNTRACK_IPV4=m
571# CONFIG_NF_CONNTRACK_PROC_COMPAT is not set
572CONFIG_IP_NF_QUEUE=m
573CONFIG_IP_NF_IPTABLES=m
574CONFIG_IP_NF_MATCH_RECENT=m
575CONFIG_IP_NF_MATCH_ECN=m
576CONFIG_IP_NF_MATCH_AH=m
577CONFIG_IP_NF_MATCH_TTL=m
578CONFIG_IP_NF_MATCH_ADDRTYPE=m
579CONFIG_IP_NF_FILTER=m
580CONFIG_IP_NF_TARGET_REJECT=m
581CONFIG_IP_NF_TARGET_LOG=m
582CONFIG_IP_NF_TARGET_ULOG=m
583CONFIG_NF_NAT=m
584CONFIG_NF_NAT_NEEDED=y
585CONFIG_IP_NF_TARGET_MASQUERADE=m
586CONFIG_IP_NF_TARGET_REDIRECT=m
587CONFIG_IP_NF_TARGET_NETMAP=m
588CONFIG_NF_NAT_SNMP_BASIC=m
589CONFIG_NF_NAT_PROTO_DCCP=m
590CONFIG_NF_NAT_PROTO_GRE=m
591CONFIG_NF_NAT_PROTO_UDPLITE=m
592CONFIG_NF_NAT_PROTO_SCTP=m
593CONFIG_NF_NAT_FTP=m
594CONFIG_NF_NAT_IRC=m
595CONFIG_NF_NAT_TFTP=m
596CONFIG_NF_NAT_AMANDA=m
597CONFIG_NF_NAT_PPTP=m
598CONFIG_NF_NAT_H323=m
599CONFIG_NF_NAT_SIP=m
600CONFIG_IP_NF_MANGLE=m
601CONFIG_IP_NF_TARGET_ECN=m
602CONFIG_IP_NF_TARGET_TTL=m
603CONFIG_IP_NF_TARGET_CLUSTERIP=m
604CONFIG_IP_NF_RAW=m
605CONFIG_IP_NF_ARPTABLES=m
606CONFIG_IP_NF_ARPFILTER=m
607CONFIG_IP_NF_ARP_MANGLE=m
608
609#
610# IPv6: Netfilter Configuration
611#
612CONFIG_NF_CONNTRACK_IPV6=m
613CONFIG_IP6_NF_QUEUE=m
614CONFIG_IP6_NF_IPTABLES=m
615CONFIG_IP6_NF_MATCH_RT=m
616CONFIG_IP6_NF_MATCH_OPTS=m
617CONFIG_IP6_NF_MATCH_FRAG=m
618CONFIG_IP6_NF_MATCH_HL=m
619CONFIG_IP6_NF_MATCH_IPV6HEADER=m
620CONFIG_IP6_NF_MATCH_AH=m
621CONFIG_IP6_NF_MATCH_MH=m
622CONFIG_IP6_NF_MATCH_EUI64=m
623CONFIG_IP6_NF_FILTER=m
624CONFIG_IP6_NF_TARGET_LOG=m
625CONFIG_IP6_NF_TARGET_REJECT=m
626CONFIG_IP6_NF_MANGLE=m
627CONFIG_IP6_NF_TARGET_HL=m
628CONFIG_IP6_NF_RAW=m
629
630#
631# DECnet: Netfilter Configuration
632#
633# CONFIG_DECNET_NF_GRABULATOR is not set
634
635#
636# Bridge: Netfilter Configuration
637#
638CONFIG_BRIDGE_NF_EBTABLES=m
639CONFIG_BRIDGE_EBT_BROUTE=m
640CONFIG_BRIDGE_EBT_T_FILTER=m
641CONFIG_BRIDGE_EBT_T_NAT=m
642CONFIG_BRIDGE_EBT_802_3=m
643CONFIG_BRIDGE_EBT_AMONG=m
644CONFIG_BRIDGE_EBT_ARP=m
645CONFIG_BRIDGE_EBT_IP=m
646CONFIG_BRIDGE_EBT_LIMIT=m
647CONFIG_BRIDGE_EBT_MARK=m
648CONFIG_BRIDGE_EBT_PKTTYPE=m
649CONFIG_BRIDGE_EBT_STP=m
650CONFIG_BRIDGE_EBT_VLAN=m
651CONFIG_BRIDGE_EBT_ARPREPLY=m
652CONFIG_BRIDGE_EBT_DNAT=m
653CONFIG_BRIDGE_EBT_MARK_T=m
654CONFIG_BRIDGE_EBT_REDIRECT=m
655CONFIG_BRIDGE_EBT_SNAT=m
656CONFIG_BRIDGE_EBT_LOG=m
657CONFIG_BRIDGE_EBT_ULOG=m
658CONFIG_BRIDGE_EBT_NFLOG=m
659CONFIG_IP_DCCP=m
660CONFIG_INET_DCCP_DIAG=m
661CONFIG_IP_DCCP_ACKVEC=y
662
663#
664# DCCP CCIDs Configuration (EXPERIMENTAL)
665#
666CONFIG_IP_DCCP_CCID2=m
667# CONFIG_IP_DCCP_CCID2_DEBUG is not set
668CONFIG_IP_DCCP_CCID3=m
669# CONFIG_IP_DCCP_CCID3_DEBUG is not set
670CONFIG_IP_DCCP_CCID3_RTO=100
671CONFIG_IP_DCCP_TFRC_LIB=m
672
673#
674# DCCP Kernel Hacking
675#
676# CONFIG_IP_DCCP_DEBUG is not set
677CONFIG_NET_DCCPPROBE=m
678CONFIG_IP_SCTP=m
679# CONFIG_SCTP_DBG_MSG is not set
680# CONFIG_SCTP_DBG_OBJCNT is not set
681# CONFIG_SCTP_HMAC_NONE is not set
682# CONFIG_SCTP_HMAC_SHA1 is not set
683CONFIG_SCTP_HMAC_MD5=y
684CONFIG_TIPC=m
685# CONFIG_TIPC_ADVANCED is not set
686# CONFIG_TIPC_DEBUG is not set
687CONFIG_ATM=m
688CONFIG_ATM_CLIP=m
689# CONFIG_ATM_CLIP_NO_ICMP is not set
690CONFIG_ATM_LANE=m
691# CONFIG_ATM_MPOA is not set
692CONFIG_ATM_BR2684=m
693# CONFIG_ATM_BR2684_IPFILTER is not set
694CONFIG_BRIDGE=m
695CONFIG_VLAN_8021Q=m
696CONFIG_DECNET=m
697CONFIG_DECNET_ROUTER=y
698CONFIG_LLC=m
699# CONFIG_LLC2 is not set
700CONFIG_IPX=m
701# CONFIG_IPX_INTERN is not set
702CONFIG_ATALK=m
703CONFIG_DEV_APPLETALK=m
704# CONFIG_LTPC is not set
705# CONFIG_COPS is not set
706CONFIG_IPDDP=m
707CONFIG_IPDDP_ENCAP=y
708CONFIG_IPDDP_DECAP=y
709# CONFIG_X25 is not set
710# CONFIG_LAPB is not set
711# CONFIG_ECONET is not set
712CONFIG_WAN_ROUTER=m
713CONFIG_NET_SCHED=y
714
715#
716# Queueing/Scheduling
717#
718CONFIG_NET_SCH_CBQ=m
719CONFIG_NET_SCH_HTB=m
720CONFIG_NET_SCH_HFSC=m
721CONFIG_NET_SCH_ATM=m
722CONFIG_NET_SCH_PRIO=m
723CONFIG_NET_SCH_RED=m
724CONFIG_NET_SCH_SFQ=m
725CONFIG_NET_SCH_TEQL=m
726CONFIG_NET_SCH_TBF=m
727CONFIG_NET_SCH_GRED=m
728CONFIG_NET_SCH_DSMARK=m
729CONFIG_NET_SCH_NETEM=m
730CONFIG_NET_SCH_INGRESS=m
731
732#
733# Classification
734#
735CONFIG_NET_CLS=y
736CONFIG_NET_CLS_BASIC=m
737CONFIG_NET_CLS_TCINDEX=m
738CONFIG_NET_CLS_ROUTE4=m
739CONFIG_NET_CLS_ROUTE=y
740CONFIG_NET_CLS_FW=m
741CONFIG_NET_CLS_U32=m
742CONFIG_CLS_U32_PERF=y
743CONFIG_CLS_U32_MARK=y
744CONFIG_NET_CLS_RSVP=m
745CONFIG_NET_CLS_RSVP6=m
746CONFIG_NET_CLS_FLOW=m
747CONFIG_NET_EMATCH=y
748CONFIG_NET_EMATCH_STACK=32
749CONFIG_NET_EMATCH_CMP=m
750CONFIG_NET_EMATCH_NBYTE=m
751CONFIG_NET_EMATCH_U32=m
752CONFIG_NET_EMATCH_META=m
753CONFIG_NET_EMATCH_TEXT=m
754CONFIG_NET_CLS_ACT=y
755CONFIG_NET_ACT_POLICE=m
756CONFIG_NET_ACT_GACT=m
757CONFIG_GACT_PROB=y
758CONFIG_NET_ACT_MIRRED=m
759CONFIG_NET_ACT_IPT=m
760CONFIG_NET_ACT_NAT=m
761CONFIG_NET_ACT_PEDIT=m
762CONFIG_NET_ACT_SIMP=m
763CONFIG_NET_CLS_IND=y
764CONFIG_NET_SCH_FIFO=y
765
766#
767# Network testing
768#
769# CONFIG_NET_PKTGEN is not set
770# CONFIG_NET_TCPPROBE is not set
771# CONFIG_HAMRADIO is not set
772# CONFIG_CAN is not set
773CONFIG_IRDA=m
774
775#
776# IrDA protocols
777#
778CONFIG_IRLAN=m
779CONFIG_IRNET=m
780CONFIG_IRCOMM=m
781# CONFIG_IRDA_ULTRA is not set
782
783#
784# IrDA options
785#
786CONFIG_IRDA_CACHE_LAST_LSAP=y
787CONFIG_IRDA_FAST_RR=y
788# CONFIG_IRDA_DEBUG is not set
789
790#
791# Infrared-port device drivers
792#
793
794#
795# SIR device drivers
796#
797CONFIG_IRTTY_SIR=m
798
799#
800# Dongle support
801#
802# CONFIG_DONGLE is not set
803CONFIG_KINGSUN_DONGLE=m
804CONFIG_KSDAZZLE_DONGLE=m
805CONFIG_KS959_DONGLE=m
806
807#
808# FIR device drivers
809#
810CONFIG_USB_IRDA=m
811CONFIG_SIGMATEL_FIR=m
812CONFIG_NSC_FIR=m
813CONFIG_WINBOND_FIR=m
814CONFIG_TOSHIBA_FIR=m
815CONFIG_SMC_IRCC_FIR=m
816CONFIG_ALI_FIR=m
817CONFIG_VLSI_FIR=m
818CONFIG_VIA_FIR=m
819CONFIG_MCS_FIR=m
820CONFIG_BT=m
821CONFIG_BT_L2CAP=m
822CONFIG_BT_SCO=m
823CONFIG_BT_RFCOMM=m
824CONFIG_BT_RFCOMM_TTY=y
825CONFIG_BT_BNEP=m
826CONFIG_BT_BNEP_MC_FILTER=y
827CONFIG_BT_BNEP_PROTO_FILTER=y
828CONFIG_BT_HIDP=m
829
830#
831# Bluetooth device drivers
832#
833CONFIG_BT_HCIUSB=m
834CONFIG_BT_HCIUSB_SCO=y
835CONFIG_BT_HCIUART=m
836CONFIG_BT_HCIUART_H4=y
837CONFIG_BT_HCIUART_BCSP=y
838CONFIG_BT_HCIUART_LL=y
839CONFIG_BT_HCIBCM203X=m
840CONFIG_BT_HCIBPA10X=m
841CONFIG_BT_HCIBFUSB=m
842CONFIG_BT_HCIDTL1=m
843CONFIG_BT_HCIBT3C=m
844CONFIG_BT_HCIBLUECARD=m
845CONFIG_BT_HCIBTUART=m
846CONFIG_BT_HCIVHCI=m
847# CONFIG_AF_RXRPC is not set
848CONFIG_FIB_RULES=y
849
850#
851# Wireless
852#
853CONFIG_CFG80211=m
854CONFIG_NL80211=y
855CONFIG_WIRELESS_EXT=y
856CONFIG_WIRELESS_EXT_SYSFS=y
857CONFIG_MAC80211=m
858CONFIG_MAC80211_QOS=y
859
860#
861# Rate control algorithm selection
862#
863CONFIG_MAC80211_RC_PID=y
864CONFIG_MAC80211_RC_DEFAULT_PID=y
865CONFIG_MAC80211_RC_DEFAULT="pid"
866CONFIG_MAC80211_MESH=y
867CONFIG_MAC80211_LEDS=y
868CONFIG_MAC80211_DEBUGFS=y
869# CONFIG_MAC80211_DEBUG_MENU is not set
870CONFIG_IEEE80211=m
871CONFIG_IEEE80211_DEBUG=y
872CONFIG_IEEE80211_CRYPT_WEP=m
873CONFIG_IEEE80211_CRYPT_CCMP=m
874CONFIG_IEEE80211_CRYPT_TKIP=m
875# CONFIG_RFKILL is not set
876CONFIG_NET_9P=m
877CONFIG_NET_9P_VIRTIO=m
878# CONFIG_NET_9P_DEBUG is not set
879
880#
881# Device Drivers
882#
883
884#
885# Generic Driver Options
886#
887CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
888CONFIG_STANDALONE=y
889CONFIG_PREVENT_FIRMWARE_BUILD=y
890CONFIG_FW_LOADER=y
891# CONFIG_FIRMWARE_IN_KERNEL is not set
892CONFIG_EXTRA_FIRMWARE=""
893# CONFIG_DEBUG_DRIVER is not set
894CONFIG_DEBUG_DEVRES=y
895# CONFIG_SYS_HYPERVISOR is not set
896CONFIG_CONNECTOR=y
897CONFIG_PROC_EVENTS=y
898# CONFIG_MTD is not set
899CONFIG_OF_DEVICE=y
900CONFIG_OF_GPIO=y
901CONFIG_OF_I2C=y
902CONFIG_PARPORT=m
903CONFIG_PARPORT_PC=m
904CONFIG_PARPORT_SERIAL=m
905# CONFIG_PARPORT_PC_FIFO is not set
906# CONFIG_PARPORT_PC_SUPERIO is not set
907# CONFIG_PARPORT_PC_PCMCIA is not set
908# CONFIG_PARPORT_GSC is not set
909# CONFIG_PARPORT_AX88796 is not set
910CONFIG_PARPORT_1284=y
911CONFIG_PARPORT_NOT_PC=y
912CONFIG_PNP=y
913# CONFIG_PNP_DEBUG is not set
914
915#
916# Protocols
917#
918CONFIG_ISAPNP=y
919# CONFIG_PNPACPI is not set
920CONFIG_BLK_DEV=y
921# CONFIG_BLK_DEV_FD is not set
922CONFIG_MAC_FLOPPY=m
923# CONFIG_BLK_DEV_XD is not set
924# CONFIG_PARIDE is not set
925# CONFIG_BLK_CPQ_DA is not set
926# CONFIG_BLK_CPQ_CISS_DA is not set
927# CONFIG_BLK_DEV_DAC960 is not set
928# CONFIG_BLK_DEV_UMEM is not set
929# CONFIG_BLK_DEV_COW_COMMON is not set
930CONFIG_BLK_DEV_LOOP=m
931CONFIG_BLK_DEV_CRYPTOLOOP=m
932CONFIG_BLK_DEV_NBD=m
933# CONFIG_BLK_DEV_SX8 is not set
934# CONFIG_BLK_DEV_UB is not set
935CONFIG_BLK_DEV_RAM=y
936CONFIG_BLK_DEV_RAM_COUNT=16
937CONFIG_BLK_DEV_RAM_SIZE=16384
938# CONFIG_BLK_DEV_XIP is not set
939CONFIG_CDROM_PKTCDVD=m
940CONFIG_CDROM_PKTCDVD_BUFFERS=8
941# CONFIG_CDROM_PKTCDVD_WCACHE is not set
942# CONFIG_ATA_OVER_ETH is not set
943CONFIG_VIRTIO_BLK=m
944CONFIG_MISC_DEVICES=y
945# CONFIG_PHANTOM is not set
946CONFIG_EEPROM_93CX6=m
947# CONFIG_SGI_IOC4 is not set
948# CONFIG_TIFM_CORE is not set
949CONFIG_ENCLOSURE_SERVICES=m
950CONFIG_HAVE_IDE=y
951CONFIG_IDE=y
952CONFIG_BLK_DEV_IDE=y
953
954#
955# Please see Documentation/ide/ide.txt for help/info on IDE drives
956#
957CONFIG_IDE_ATAPI=y
958# CONFIG_BLK_DEV_IDE_SATA is not set
959CONFIG_BLK_DEV_IDEDISK=y
960CONFIG_IDEDISK_MULTI_MODE=y
961# CONFIG_BLK_DEV_IDECS is not set
962# CONFIG_BLK_DEV_DELKIN is not set
963CONFIG_BLK_DEV_IDECD=m
964CONFIG_BLK_DEV_IDECD_VERBOSE_ERRORS=y
965# CONFIG_BLK_DEV_IDETAPE is not set
966CONFIG_BLK_DEV_IDEFLOPPY=m
967# CONFIG_BLK_DEV_IDESCSI is not set
968CONFIG_IDE_TASK_IOCTL=y
969CONFIG_IDE_PROC_FS=y
970
971#
972# IDE chipset support/bugfixes
973#
974# CONFIG_IDE_GENERIC is not set
975# CONFIG_BLK_DEV_PLATFORM is not set
976# CONFIG_BLK_DEV_IDEPNP is not set
977CONFIG_BLK_DEV_IDEDMA_SFF=y
978
979#
980# PCI IDE chipsets support
981#
982CONFIG_BLK_DEV_IDEPCI=y
983# CONFIG_IDEPCI_PCIBUS_ORDER is not set
984# CONFIG_BLK_DEV_OFFBOARD is not set
985CONFIG_BLK_DEV_GENERIC=y
986# CONFIG_BLK_DEV_OPTI621 is not set
987CONFIG_BLK_DEV_IDEDMA_PCI=y
988# CONFIG_BLK_DEV_AEC62XX is not set
989# CONFIG_BLK_DEV_ALI15X3 is not set
990# CONFIG_BLK_DEV_AMD74XX is not set
991# CONFIG_BLK_DEV_CMD64X is not set
992# CONFIG_BLK_DEV_TRIFLEX is not set
993# CONFIG_BLK_DEV_CY82C693 is not set
994# CONFIG_BLK_DEV_CS5520 is not set
995# CONFIG_BLK_DEV_CS5530 is not set
996# CONFIG_BLK_DEV_HPT34X is not set
997# CONFIG_BLK_DEV_HPT366 is not set
998# CONFIG_BLK_DEV_JMICRON is not set
999# CONFIG_BLK_DEV_SC1200 is not set
1000# CONFIG_BLK_DEV_PIIX is not set
1001# CONFIG_BLK_DEV_IT8213 is not set
1002# CONFIG_BLK_DEV_IT821X is not set
1003# CONFIG_BLK_DEV_NS87415 is not set
1004# CONFIG_BLK_DEV_PDC202XX_OLD is not set
1005# CONFIG_BLK_DEV_PDC202XX_NEW is not set
1006# CONFIG_BLK_DEV_SVWKS is not set
1007# CONFIG_BLK_DEV_SIIMAGE is not set
1008# CONFIG_BLK_DEV_SL82C105 is not set
1009# CONFIG_BLK_DEV_SLC90E66 is not set
1010# CONFIG_BLK_DEV_TRM290 is not set
1011# CONFIG_BLK_DEV_VIA82CXXX is not set
1012# CONFIG_BLK_DEV_TC86C001 is not set
1013CONFIG_BLK_DEV_IDE_PMAC=y
1014CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST=y
1015CONFIG_BLK_DEV_IDEDMA_PMAC=y
1016CONFIG_BLK_DEV_IDEDMA=y
1017CONFIG_BLK_DEV_HD_ONLY=y
1018CONFIG_BLK_DEV_HD=y
1019
1020#
1021# SCSI device support
1022#
1023CONFIG_RAID_ATTRS=m
1024CONFIG_SCSI=y
1025CONFIG_SCSI_DMA=y
1026CONFIG_SCSI_TGT=m
1027# CONFIG_SCSI_NETLINK is not set
1028CONFIG_SCSI_PROC_FS=y
1029
1030#
1031# SCSI support type (disk, tape, CD-ROM)
1032#
1033CONFIG_BLK_DEV_SD=y
1034CONFIG_CHR_DEV_ST=m
1035CONFIG_CHR_DEV_OSST=m
1036CONFIG_BLK_DEV_SR=m
1037CONFIG_BLK_DEV_SR_VENDOR=y
1038CONFIG_CHR_DEV_SG=y
1039CONFIG_CHR_DEV_SCH=m
1040CONFIG_SCSI_ENCLOSURE=m
1041
1042#
1043# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
1044#
1045CONFIG_SCSI_MULTI_LUN=y
1046CONFIG_SCSI_CONSTANTS=y
1047CONFIG_SCSI_LOGGING=y
1048CONFIG_SCSI_SCAN_ASYNC=y
1049CONFIG_SCSI_WAIT_SCAN=m
1050
1051#
1052# SCSI Transports
1053#
1054CONFIG_SCSI_SPI_ATTRS=m
1055# CONFIG_SCSI_FC_ATTRS is not set
1056# CONFIG_SCSI_ISCSI_ATTRS is not set
1057# CONFIG_SCSI_SAS_ATTRS is not set
1058# CONFIG_SCSI_SAS_LIBSAS is not set
1059CONFIG_SCSI_SRP_ATTRS=m
1060CONFIG_SCSI_SRP_TGT_ATTRS=y
1061CONFIG_SCSI_LOWLEVEL=y
1062# CONFIG_ISCSI_TCP is not set
1063# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
1064# CONFIG_SCSI_3W_9XXX is not set
1065# CONFIG_SCSI_7000FASST is not set
1066# CONFIG_SCSI_ACARD is not set
1067# CONFIG_SCSI_AHA152X is not set
1068# CONFIG_SCSI_AHA1542 is not set
1069# CONFIG_SCSI_AACRAID is not set
1070# CONFIG_SCSI_AIC7XXX is not set
1071# CONFIG_SCSI_AIC7XXX_OLD is not set
1072# CONFIG_SCSI_AIC79XX is not set
1073# CONFIG_SCSI_AIC94XX is not set
1074# CONFIG_SCSI_DPT_I2O is not set
1075# CONFIG_SCSI_ADVANSYS is not set
1076# CONFIG_SCSI_IN2000 is not set
1077# CONFIG_SCSI_ARCMSR is not set
1078# CONFIG_MEGARAID_NEWGEN is not set
1079# CONFIG_MEGARAID_LEGACY is not set
1080# CONFIG_MEGARAID_SAS is not set
1081# CONFIG_SCSI_HPTIOP is not set
1082# CONFIG_SCSI_BUSLOGIC is not set
1083# CONFIG_SCSI_DMX3191D is not set
1084# CONFIG_SCSI_DTC3280 is not set
1085# CONFIG_SCSI_EATA is not set
1086# CONFIG_SCSI_FUTURE_DOMAIN is not set
1087# CONFIG_SCSI_GDTH is not set
1088# CONFIG_SCSI_GENERIC_NCR5380 is not set
1089# CONFIG_SCSI_GENERIC_NCR5380_MMIO is not set
1090# CONFIG_SCSI_IPS is not set
1091# CONFIG_SCSI_INITIO is not set
1092# CONFIG_SCSI_INIA100 is not set
1093# CONFIG_SCSI_PPA is not set
1094# CONFIG_SCSI_IMM is not set
1095# CONFIG_SCSI_MVSAS is not set
1096# CONFIG_SCSI_NCR53C406A is not set
1097# CONFIG_SCSI_STEX is not set
1098# CONFIG_SCSI_SYM53C8XX_2 is not set
1099# CONFIG_SCSI_IPR is not set
1100# CONFIG_SCSI_PAS16 is not set
1101# CONFIG_SCSI_QLOGIC_FAS is not set
1102# CONFIG_SCSI_QLOGIC_1280 is not set
1103# CONFIG_SCSI_QLA_FC is not set
1104# CONFIG_SCSI_QLA_ISCSI is not set
1105# CONFIG_SCSI_LPFC is not set
1106# CONFIG_SCSI_SYM53C416 is not set
1107# CONFIG_SCSI_DC395x is not set
1108# CONFIG_SCSI_DC390T is not set
1109# CONFIG_SCSI_T128 is not set
1110# CONFIG_SCSI_U14_34F is not set
1111# CONFIG_SCSI_NSP32 is not set
1112# CONFIG_SCSI_DEBUG is not set
1113CONFIG_SCSI_MESH=m
1114CONFIG_SCSI_MESH_SYNC_RATE=5
1115CONFIG_SCSI_MESH_RESET_DELAY_MS=4000
1116CONFIG_SCSI_MAC53C94=m
1117CONFIG_SCSI_SRP=m
1118CONFIG_SCSI_LOWLEVEL_PCMCIA=y
1119# CONFIG_PCMCIA_AHA152X is not set
1120# CONFIG_PCMCIA_FDOMAIN is not set
1121# CONFIG_PCMCIA_NINJA_SCSI is not set
1122# CONFIG_PCMCIA_QLOGIC is not set
1123# CONFIG_PCMCIA_SYM53C500 is not set
1124CONFIG_SCSI_DH=y
1125CONFIG_SCSI_DH_RDAC=m
1126CONFIG_SCSI_DH_HP_SW=m
1127CONFIG_SCSI_DH_EMC=m
1128CONFIG_ATA=y
1129# CONFIG_ATA_NONSTANDARD is not set
1130# CONFIG_SATA_PMP is not set
1131# CONFIG_SATA_AHCI is not set
1132# CONFIG_SATA_SIL24 is not set
1133CONFIG_SATA_FSL=m
1134CONFIG_ATA_SFF=y
1135# CONFIG_SATA_SVW is not set
1136CONFIG_ATA_PIIX=m
1137# CONFIG_SATA_MV is not set
1138# CONFIG_SATA_NV is not set
1139CONFIG_PDC_ADMA=m
1140# CONFIG_SATA_QSTOR is not set
1141# CONFIG_SATA_PROMISE is not set
1142# CONFIG_SATA_SX4 is not set
1143# CONFIG_SATA_SIL is not set
1144# CONFIG_SATA_SIS is not set
1145# CONFIG_SATA_ULI is not set
1146# CONFIG_SATA_VIA is not set
1147# CONFIG_SATA_VITESSE is not set
1148# CONFIG_SATA_INIC162X is not set
1149# CONFIG_PATA_ALI is not set
1150# CONFIG_PATA_AMD is not set
1151# CONFIG_PATA_ARTOP is not set
1152# CONFIG_PATA_ATIIXP is not set
1153# CONFIG_PATA_CMD640_PCI is not set
1154# CONFIG_PATA_CMD64X is not set
1155# CONFIG_PATA_CS5520 is not set
1156# CONFIG_PATA_CS5530 is not set
1157# CONFIG_PATA_CYPRESS is not set
1158# CONFIG_PATA_EFAR is not set
1159CONFIG_ATA_GENERIC=m
1160# CONFIG_PATA_HPT366 is not set
1161# CONFIG_PATA_HPT37X is not set
1162# CONFIG_PATA_HPT3X2N is not set
1163# CONFIG_PATA_HPT3X3 is not set
1164# CONFIG_PATA_ISAPNP is not set
1165# CONFIG_PATA_IT821X is not set
1166# CONFIG_PATA_IT8213 is not set
1167# CONFIG_PATA_JMICRON is not set
1168# CONFIG_PATA_LEGACY is not set
1169# CONFIG_PATA_TRIFLEX is not set
1170# CONFIG_PATA_MARVELL is not set
1171CONFIG_PATA_MPC52xx=m
1172# CONFIG_PATA_MPIIX is not set
1173# CONFIG_PATA_OLDPIIX is not set
1174# CONFIG_PATA_NETCELL is not set
1175# CONFIG_PATA_NINJA32 is not set
1176# CONFIG_PATA_NS87410 is not set
1177# CONFIG_PATA_NS87415 is not set
1178# CONFIG_PATA_OPTI is not set
1179CONFIG_PATA_OPTIDMA=m
1180# CONFIG_PATA_PCMCIA is not set
1181# CONFIG_PATA_PDC_OLD is not set
1182# CONFIG_PATA_QDI is not set
1183# CONFIG_PATA_RADISYS is not set
1184# CONFIG_PATA_RZ1000 is not set
1185# CONFIG_PATA_SC1200 is not set
1186# CONFIG_PATA_SERVERWORKS is not set
1187# CONFIG_PATA_PDC2027X is not set
1188# CONFIG_PATA_SIL680 is not set
1189# CONFIG_PATA_SIS is not set
1190CONFIG_PATA_VIA=m
1191# CONFIG_PATA_WINBOND is not set
1192# CONFIG_PATA_WINBOND_VLB is not set
1193CONFIG_PATA_PLATFORM=m
1194CONFIG_PATA_OF_PLATFORM=m
1195CONFIG_PATA_SCH=m
1196CONFIG_MD=y
1197CONFIG_BLK_DEV_MD=y
1198CONFIG_MD_LINEAR=m
1199CONFIG_MD_RAID0=m
1200CONFIG_MD_RAID1=m
1201CONFIG_MD_RAID10=m
1202CONFIG_MD_RAID456=m
1203CONFIG_MD_RAID5_RESHAPE=y
1204CONFIG_MD_MULTIPATH=m
1205CONFIG_MD_FAULTY=m
1206CONFIG_BLK_DEV_DM=m
1207CONFIG_DM_DEBUG=y
1208CONFIG_DM_CRYPT=m
1209CONFIG_DM_SNAPSHOT=m
1210CONFIG_DM_MIRROR=m
1211CONFIG_DM_ZERO=m
1212CONFIG_DM_MULTIPATH=m
1213# CONFIG_DM_DELAY is not set
1214CONFIG_DM_UEVENT=y
1215# CONFIG_FUSION is not set
1216
1217#
1218# IEEE 1394 (FireWire) support
1219#
1220
1221#
1222# Enable only one of the two stacks, unless you know what you are doing
1223#
1224CONFIG_FIREWIRE=m
1225CONFIG_FIREWIRE_OHCI=m
1226CONFIG_FIREWIRE_OHCI_DEBUG=y
1227CONFIG_FIREWIRE_SBP2=m
1228# CONFIG_IEEE1394 is not set
1229# CONFIG_I2O is not set
1230CONFIG_MACINTOSH_DRIVERS=y
1231CONFIG_ADB=y
1232CONFIG_ADB_CUDA=y
1233CONFIG_ADB_PMU=y
1234CONFIG_ADB_PMU_LED=y
1235CONFIG_ADB_PMU_LED_IDE=y
1236CONFIG_PMAC_APM_EMU=y
1237CONFIG_PMAC_MEDIABAY=y
1238CONFIG_PMAC_BACKLIGHT=y
1239# CONFIG_PMAC_BACKLIGHT_LEGACY is not set
1240CONFIG_ADB_MACIO=y
1241CONFIG_INPUT_ADBHID=y
1242CONFIG_MAC_EMUMOUSEBTN=y
1243CONFIG_THERM_WINDTUNNEL=m
1244CONFIG_THERM_ADT746X=m
1245CONFIG_WINDFARM=y
1246# CONFIG_ANSLCD is not set
1247CONFIG_PMAC_RACKMETER=m
1248CONFIG_NETDEVICES=y
1249CONFIG_NETDEVICES_MULTIQUEUE=y
1250CONFIG_IFB=m
1251CONFIG_DUMMY=m
1252CONFIG_BONDING=m
1253CONFIG_MACVLAN=m
1254CONFIG_EQUALIZER=m
1255CONFIG_TUN=m
1256CONFIG_VETH=m
1257CONFIG_NET_SB1000=m
1258# CONFIG_ARCNET is not set
1259CONFIG_PHYLIB=m
1260
1261#
1262# MII PHY device drivers
1263#
1264CONFIG_MARVELL_PHY=m
1265CONFIG_DAVICOM_PHY=m
1266CONFIG_QSEMI_PHY=m
1267CONFIG_LXT_PHY=m
1268CONFIG_CICADA_PHY=m
1269CONFIG_VITESSE_PHY=m
1270CONFIG_SMSC_PHY=m
1271CONFIG_BROADCOM_PHY=m
1272CONFIG_ICPLUS_PHY=m
1273CONFIG_REALTEK_PHY=m
1274CONFIG_MDIO_BITBANG=y
1275CONFIG_NET_ETHERNET=y
1276CONFIG_MII=m
1277CONFIG_MACE=m
1278# CONFIG_MACE_AAUI_PORT is not set
1279CONFIG_BMAC=m
1280CONFIG_HAPPYMEAL=m
1281CONFIG_SUNGEM=m
1282CONFIG_CASSINI=m
1283CONFIG_NET_VENDOR_3COM=y
1284# CONFIG_EL1 is not set
1285# CONFIG_EL2 is not set
1286# CONFIG_ELPLUS is not set
1287# CONFIG_EL16 is not set
1288CONFIG_EL3=m
1289# CONFIG_3C515 is not set
1290CONFIG_VORTEX=m
1291CONFIG_TYPHOON=m
1292# CONFIG_LANCE is not set
1293CONFIG_NET_VENDOR_SMC=y
1294# CONFIG_WD80x3 is not set
1295CONFIG_ULTRA=m
1296# CONFIG_SMC9194 is not set
1297# CONFIG_NET_VENDOR_RACAL is not set
1298CONFIG_NET_TULIP=y
1299CONFIG_DE2104X=m
1300CONFIG_TULIP=m
1301# CONFIG_TULIP_MWI is not set
1302CONFIG_TULIP_MMIO=y
1303# CONFIG_TULIP_NAPI is not set
1304CONFIG_DE4X5=m
1305CONFIG_WINBOND_840=m
1306CONFIG_DM9102=m
1307CONFIG_ULI526X=m
1308CONFIG_PCMCIA_XIRCOM=m
1309# CONFIG_AT1700 is not set
1310# CONFIG_DEPCA is not set
1311# CONFIG_HP100 is not set
1312CONFIG_NET_ISA=y
1313# CONFIG_E2100 is not set
1314CONFIG_EWRK3=m
1315# CONFIG_EEXPRESS is not set
1316# CONFIG_EEXPRESS_PRO is not set
1317# CONFIG_HPLAN_PLUS is not set
1318# CONFIG_HPLAN is not set
1319# CONFIG_LP486E is not set
1320# CONFIG_ETH16I is not set
1321CONFIG_NE2000=m
1322# CONFIG_ZNET is not set
1323# CONFIG_SEEQ8005 is not set
1324# CONFIG_IBM_NEW_EMAC_ZMII is not set
1325# CONFIG_IBM_NEW_EMAC_RGMII is not set
1326# CONFIG_IBM_NEW_EMAC_TAH is not set
1327# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
1328CONFIG_NET_PCI=y
1329CONFIG_PCNET32=m
1330CONFIG_AMD8111_ETH=m
1331CONFIG_AMD8111E_NAPI=y
1332CONFIG_ADAPTEC_STARFIRE=m
1333CONFIG_ADAPTEC_STARFIRE_NAPI=y
1334# CONFIG_AC3200 is not set
1335# CONFIG_APRICOT is not set
1336CONFIG_B44=m
1337CONFIG_B44_PCI_AUTOSELECT=y
1338CONFIG_B44_PCICORE_AUTOSELECT=y
1339CONFIG_B44_PCI=y
1340CONFIG_FORCEDETH=m
1341CONFIG_FORCEDETH_NAPI=y
1342# CONFIG_CS89x0 is not set
1343# CONFIG_EEPRO100 is not set
1344CONFIG_E100=m
1345CONFIG_FEALNX=m
1346CONFIG_NATSEMI=m
1347CONFIG_NE2K_PCI=m
1348CONFIG_8139CP=m
1349CONFIG_8139TOO=m
1350# CONFIG_8139TOO_PIO is not set
1351# CONFIG_8139TOO_TUNE_TWISTER is not set
1352CONFIG_8139TOO_8129=y
1353# CONFIG_8139_OLD_RX_RESET is not set
1354CONFIG_R6040=m
1355CONFIG_SIS900=m
1356CONFIG_EPIC100=m
1357CONFIG_SUNDANCE=m
1358# CONFIG_SUNDANCE_MMIO is not set
1359CONFIG_TLAN=m
1360CONFIG_VIA_RHINE=m
1361CONFIG_VIA_RHINE_MMIO=y
1362CONFIG_VIA_RHINE_NAPI=y
1363CONFIG_SC92031=m
1364CONFIG_NET_POCKET=y
1365CONFIG_DE600=m
1366CONFIG_DE620=m
1367CONFIG_FEC_MPC52xx=m
1368CONFIG_FEC_MPC52xx_MDIO=y
1369# CONFIG_FS_ENET is not set
1370CONFIG_NETDEV_1000=y
1371CONFIG_ACENIC=m
1372# CONFIG_ACENIC_OMIT_TIGON_I is not set
1373CONFIG_DL2K=m
1374CONFIG_E1000=m
1375CONFIG_E1000_NAPI=y
1376# CONFIG_E1000_DISABLE_PACKET_SPLIT is not set
1377CONFIG_E1000E=m
1378CONFIG_E1000E_ENABLED=y
1379CONFIG_IP1000=m
1380CONFIG_IGB=m
1381CONFIG_NS83820=m
1382CONFIG_HAMACHI=m
1383CONFIG_YELLOWFIN=m
1384CONFIG_R8169=m
1385CONFIG_R8169_NAPI=y
1386CONFIG_R8169_VLAN=y
1387CONFIG_SIS190=m
1388CONFIG_SKGE=m
1389# CONFIG_SKGE_DEBUG is not set
1390CONFIG_SKY2=m
1391# CONFIG_SKY2_DEBUG is not set
1392CONFIG_VIA_VELOCITY=m
1393CONFIG_TIGON3=m
1394CONFIG_BNX2=m
1395CONFIG_GIANFAR=m
1396CONFIG_GFAR_NAPI=y
1397# CONFIG_UCC_GETH is not set
1398CONFIG_MV643XX_ETH=m
1399CONFIG_QLA3XXX=m
1400CONFIG_ATL1=m
1401CONFIG_NETDEV_10000=y
1402CONFIG_CHELSIO_T1=m
1403CONFIG_CHELSIO_T1_1G=y
1404CONFIG_CHELSIO_T1_NAPI=y
1405CONFIG_CHELSIO_T3=m
1406CONFIG_IXGBE=m
1407CONFIG_IXGB=m
1408CONFIG_IXGB_NAPI=y
1409CONFIG_S2IO=m
1410CONFIG_S2IO_NAPI=y
1411CONFIG_MYRI10GE=m
1412CONFIG_NETXEN_NIC=m
1413CONFIG_NIU=m
1414# CONFIG_MLX4_CORE is not set
1415CONFIG_TEHUTI=m
1416CONFIG_BNX2X=m
1417CONFIG_SFC=m
1418# CONFIG_TR is not set
1419
1420#
1421# Wireless LAN
1422#
1423# CONFIG_WLAN_PRE80211 is not set
1424# CONFIG_WLAN_80211 is not set
1425# CONFIG_IWLWIFI_LEDS is not set
1426
1427#
1428# USB Network Adapters
1429#
1430CONFIG_USB_CATC=m
1431CONFIG_USB_KAWETH=m
1432CONFIG_USB_PEGASUS=m
1433CONFIG_USB_RTL8150=m
1434CONFIG_USB_USBNET=m
1435CONFIG_USB_NET_AX8817X=m
1436CONFIG_USB_NET_CDCETHER=m
1437CONFIG_USB_NET_DM9601=m
1438CONFIG_USB_NET_GL620A=m
1439CONFIG_USB_NET_NET1080=m
1440CONFIG_USB_NET_PLUSB=m
1441CONFIG_USB_NET_MCS7830=m
1442CONFIG_USB_NET_RNDIS_HOST=m
1443CONFIG_USB_NET_CDC_SUBSET=m
1444CONFIG_USB_ALI_M5632=y
1445CONFIG_USB_AN2720=y
1446CONFIG_USB_BELKIN=y
1447CONFIG_USB_ARMLINUX=y
1448CONFIG_USB_EPSON2888=y
1449CONFIG_USB_KC2190=y
1450CONFIG_USB_NET_ZAURUS=m
1451CONFIG_NET_PCMCIA=y
1452CONFIG_PCMCIA_3C589=m
1453CONFIG_PCMCIA_3C574=m
1454CONFIG_PCMCIA_FMVJ18X=m
1455CONFIG_PCMCIA_PCNET=m
1456CONFIG_PCMCIA_NMCLAN=m
1457CONFIG_PCMCIA_SMC91C92=m
1458CONFIG_PCMCIA_XIRC2PS=m
1459CONFIG_PCMCIA_AXNET=m
1460# CONFIG_WAN is not set
1461CONFIG_ATM_DRIVERS=y
1462# CONFIG_ATM_DUMMY is not set
1463CONFIG_ATM_TCP=m
1464CONFIG_ATM_LANAI=m
1465CONFIG_ATM_ENI=m
1466# CONFIG_ATM_ENI_DEBUG is not set
1467# CONFIG_ATM_ENI_TUNE_BURST is not set
1468# CONFIG_ATM_FIRESTREAM is not set
1469# CONFIG_ATM_ZATM is not set
1470CONFIG_ATM_NICSTAR=m
1471# CONFIG_ATM_NICSTAR_USE_SUNI is not set
1472# CONFIG_ATM_NICSTAR_USE_IDT77105 is not set
1473CONFIG_ATM_IDT77252=m
1474# CONFIG_ATM_IDT77252_DEBUG is not set
1475# CONFIG_ATM_IDT77252_RCV_ALL is not set
1476CONFIG_ATM_IDT77252_USE_SUNI=y
1477# CONFIG_ATM_AMBASSADOR is not set
1478# CONFIG_ATM_HORIZON is not set
1479# CONFIG_ATM_IA is not set
1480CONFIG_ATM_FORE200E_MAYBE=m
1481# CONFIG_ATM_FORE200E_PCA is not set
1482CONFIG_ATM_HE=m
1483# CONFIG_ATM_HE_USE_SUNI is not set
1484CONFIG_FDDI=y
1485# CONFIG_DEFXX is not set
1486CONFIG_SKFP=m
1487# CONFIG_HIPPI is not set
1488CONFIG_PLIP=m
1489CONFIG_PPP=m
1490CONFIG_PPP_MULTILINK=y
1491CONFIG_PPP_FILTER=y
1492CONFIG_PPP_ASYNC=m
1493CONFIG_PPP_SYNC_TTY=m
1494CONFIG_PPP_DEFLATE=m
1495# CONFIG_PPP_BSDCOMP is not set
1496CONFIG_PPP_MPPE=m
1497CONFIG_PPPOE=m
1498CONFIG_PPPOATM=m
1499CONFIG_PPPOL2TP=m
1500CONFIG_SLIP=m
1501CONFIG_SLIP_COMPRESSED=y
1502CONFIG_SLHC=m
1503CONFIG_SLIP_SMART=y
1504# CONFIG_SLIP_MODE_SLIP6 is not set
1505CONFIG_NET_FC=y
1506CONFIG_NETCONSOLE=m
1507CONFIG_NETCONSOLE_DYNAMIC=y
1508CONFIG_NETPOLL=y
1509CONFIG_NETPOLL_TRAP=y
1510CONFIG_NET_POLL_CONTROLLER=y
1511CONFIG_VIRTIO_NET=m
1512# CONFIG_ISDN is not set
1513# CONFIG_PHONE is not set
1514
1515#
1516# Input device support
1517#
1518CONFIG_INPUT=y
1519CONFIG_INPUT_FF_MEMLESS=y
1520CONFIG_INPUT_POLLDEV=m
1521
1522#
1523# Userland interfaces
1524#
1525CONFIG_INPUT_MOUSEDEV=y
1526# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
1527CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
1528CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
1529CONFIG_INPUT_JOYDEV=m
1530CONFIG_INPUT_EVDEV=y
1531# CONFIG_INPUT_EVBUG is not set
1532
1533#
1534# Input Device Drivers
1535#
1536CONFIG_INPUT_KEYBOARD=y
1537CONFIG_KEYBOARD_ATKBD=y
1538# CONFIG_KEYBOARD_SUNKBD is not set
1539# CONFIG_KEYBOARD_LKKBD is not set
1540# CONFIG_KEYBOARD_XTKBD is not set
1541# CONFIG_KEYBOARD_NEWTON is not set
1542# CONFIG_KEYBOARD_STOWAWAY is not set
1543# CONFIG_KEYBOARD_GPIO is not set
1544CONFIG_INPUT_MOUSE=y
1545CONFIG_MOUSE_PS2=y
1546CONFIG_MOUSE_PS2_ALPS=y
1547CONFIG_MOUSE_PS2_LOGIPS2PP=y
1548CONFIG_MOUSE_PS2_SYNAPTICS=y
1549CONFIG_MOUSE_PS2_LIFEBOOK=y
1550CONFIG_MOUSE_PS2_TRACKPOINT=y
1551# CONFIG_MOUSE_PS2_TOUCHKIT is not set
1552CONFIG_MOUSE_SERIAL=m
1553CONFIG_MOUSE_APPLETOUCH=m
1554# CONFIG_MOUSE_INPORT is not set
1555# CONFIG_MOUSE_LOGIBM is not set
1556# CONFIG_MOUSE_PC110PAD is not set
1557CONFIG_MOUSE_VSXXXAA=m
1558# CONFIG_MOUSE_GPIO is not set
1559CONFIG_INPUT_JOYSTICK=y
1560CONFIG_JOYSTICK_ANALOG=m
1561CONFIG_JOYSTICK_A3D=m
1562CONFIG_JOYSTICK_ADI=m
1563CONFIG_JOYSTICK_COBRA=m
1564CONFIG_JOYSTICK_GF2K=m
1565CONFIG_JOYSTICK_GRIP=m
1566CONFIG_JOYSTICK_GRIP_MP=m
1567CONFIG_JOYSTICK_GUILLEMOT=m
1568CONFIG_JOYSTICK_INTERACT=m
1569CONFIG_JOYSTICK_SIDEWINDER=m
1570CONFIG_JOYSTICK_TMDC=m
1571CONFIG_JOYSTICK_IFORCE=m
1572CONFIG_JOYSTICK_IFORCE_USB=y
1573CONFIG_JOYSTICK_IFORCE_232=y
1574CONFIG_JOYSTICK_WARRIOR=m
1575CONFIG_JOYSTICK_MAGELLAN=m
1576CONFIG_JOYSTICK_SPACEORB=m
1577CONFIG_JOYSTICK_SPACEBALL=m
1578CONFIG_JOYSTICK_STINGER=m
1579CONFIG_JOYSTICK_TWIDJOY=m
1580CONFIG_JOYSTICK_ZHENHUA=m
1581CONFIG_JOYSTICK_DB9=m
1582CONFIG_JOYSTICK_GAMECON=m
1583CONFIG_JOYSTICK_TURBOGRAFX=m
1584CONFIG_JOYSTICK_JOYDUMP=m
1585CONFIG_JOYSTICK_XPAD=m
1586CONFIG_JOYSTICK_XPAD_FF=y
1587CONFIG_JOYSTICK_XPAD_LEDS=y
1588CONFIG_INPUT_TABLET=y
1589CONFIG_TABLET_USB_ACECAD=m
1590CONFIG_TABLET_USB_AIPTEK=m
1591CONFIG_TABLET_USB_GTCO=m
1592CONFIG_TABLET_USB_KBTAB=m
1593CONFIG_TABLET_USB_WACOM=m
1594# CONFIG_INPUT_TOUCHSCREEN is not set
1595CONFIG_INPUT_MISC=y
1596CONFIG_INPUT_PCSPKR=m
1597CONFIG_INPUT_ATI_REMOTE=m
1598CONFIG_INPUT_ATI_REMOTE2=m
1599CONFIG_INPUT_KEYSPAN_REMOTE=m
1600CONFIG_INPUT_POWERMATE=m
1601CONFIG_INPUT_YEALINK=m
1602CONFIG_INPUT_UINPUT=m
1603
1604#
1605# Hardware I/O ports
1606#
1607CONFIG_SERIO=y
1608CONFIG_SERIO_I8042=y
1609CONFIG_SERIO_SERPORT=y
1610# CONFIG_SERIO_PARKBD is not set
1611# CONFIG_SERIO_PCIPS2 is not set
1612CONFIG_SERIO_LIBPS2=y
1613CONFIG_SERIO_RAW=m
1614CONFIG_GAMEPORT=m
1615CONFIG_GAMEPORT_NS558=m
1616CONFIG_GAMEPORT_L4=m
1617CONFIG_GAMEPORT_EMU10K1=m
1618CONFIG_GAMEPORT_FM801=m
1619CONFIG_INPUT_LIRC=y
1620CONFIG_LIRC_DEV=m
1621CONFIG_LIRC_ATIUSB=m
1622CONFIG_LIRC_BT829=m
1623CONFIG_LIRC_CMDIR=m
1624CONFIG_LIRC_I2C=m
1625CONFIG_LIRC_IGORPLUGUSB=m
1626CONFIG_LIRC_IMON=m
1627CONFIG_LIRC_IT87=m
1628CONFIG_LIRC_MCEUSB=m
1629CONFIG_LIRC_MCEUSB2=m
1630CONFIG_LIRC_PVR150=m
1631CONFIG_LIRC_PARALLEL=m
1632CONFIG_LIRC_SERIAL=m
1633CONFIG_LIRC_SIR=m
1634CONFIG_LIRC_STREAMZAP=m
1635CONFIG_LIRC_TTUSBIR=m
1636
1637#
1638# Character devices
1639#
1640CONFIG_VT=y
1641CONFIG_VT_CONSOLE=y
1642CONFIG_HW_CONSOLE=y
1643CONFIG_VT_HW_CONSOLE_BINDING=y
1644# CONFIG_DEVKMEM is not set
1645CONFIG_SERIAL_NONSTANDARD=y
1646# CONFIG_COMPUTONE is not set
1647CONFIG_ROCKETPORT=m
1648CONFIG_CYCLADES=m
1649# CONFIG_CYZ_INTR is not set
1650# CONFIG_DIGIEPCA is not set
1651# CONFIG_ESPSERIAL is not set
1652# CONFIG_MOXA_INTELLIO is not set
1653# CONFIG_MOXA_SMARTIO is not set
1654# CONFIG_ISI is not set
1655CONFIG_SYNCLINK=m
1656CONFIG_SYNCLINKMP=m
1657CONFIG_SYNCLINK_GT=m
1658CONFIG_N_HDLC=m
1659# CONFIG_RISCOM8 is not set
1660# CONFIG_SPECIALIX is not set
1661# CONFIG_SX is not set
1662# CONFIG_RIO is not set
1663# CONFIG_STALDRV is not set
1664CONFIG_NOZOMI=m
1665
1666#
1667# Serial drivers
1668#
1669CONFIG_SERIAL_8250=y
1670CONFIG_SERIAL_8250_CONSOLE=y
1671CONFIG_SERIAL_8250_PCI=y
1672CONFIG_SERIAL_8250_PNP=y
1673CONFIG_SERIAL_8250_CS=m
1674CONFIG_SERIAL_8250_NR_UARTS=32
1675CONFIG_SERIAL_8250_RUNTIME_UARTS=4
1676CONFIG_SERIAL_8250_EXTENDED=y
1677CONFIG_SERIAL_8250_MANY_PORTS=y
1678# CONFIG_SERIAL_8250_FOURPORT is not set
1679# CONFIG_SERIAL_8250_ACCENT is not set
1680# CONFIG_SERIAL_8250_BOCA is not set
1681# CONFIG_SERIAL_8250_EXAR_ST16C554 is not set
1682# CONFIG_SERIAL_8250_HUB6 is not set
1683CONFIG_SERIAL_8250_SHARE_IRQ=y
1684CONFIG_SERIAL_8250_DETECT_IRQ=y
1685CONFIG_SERIAL_8250_RSA=y
1686
1687#
1688# Non-8250 serial port support
1689#
1690CONFIG_SERIAL_UARTLITE=m
1691CONFIG_SERIAL_CORE=y
1692CONFIG_SERIAL_CORE_CONSOLE=y
1693CONFIG_SERIAL_PMACZILOG=m
1694# CONFIG_SERIAL_PMACZILOG_TTYS is not set
1695# CONFIG_SERIAL_CPM is not set
1696CONFIG_SERIAL_MPC52xx=y
1697CONFIG_SERIAL_MPC52xx_CONSOLE=y
1698CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD=115200
1699CONFIG_SERIAL_JSM=m
1700CONFIG_SERIAL_OF_PLATFORM=y
1701# CONFIG_SERIAL_QE is not set
1702CONFIG_UNIX98_PTYS=y
1703# CONFIG_LEGACY_PTYS is not set
1704# CONFIG_CRASH is not set
1705CONFIG_BRIQ_PANEL=m
1706CONFIG_PRINTER=m
1707CONFIG_LP_CONSOLE=y
1708CONFIG_PPDEV=m
1709# CONFIG_HVC_RTAS is not set
1710# CONFIG_IPMI_HANDLER is not set
1711CONFIG_HW_RANDOM=y
1712CONFIG_HW_RANDOM_VIRTIO=m
1713CONFIG_NVRAM=y
1714CONFIG_DTLK=m
1715CONFIG_R3964=m
1716# CONFIG_APPLICOM is not set
1717
1718#
1719# PCMCIA character devices
1720#
1721# CONFIG_SYNCLINK_CS is not set
1722CONFIG_CARDMAN_4000=m
1723CONFIG_CARDMAN_4040=m
1724CONFIG_IPWIRELESS=m
1725# CONFIG_RAW_DRIVER is not set
1726# CONFIG_TCG_TPM is not set
1727CONFIG_DEVPORT=y
1728CONFIG_I2C=y
1729CONFIG_I2C_BOARDINFO=y
1730CONFIG_I2C_CHARDEV=m
1731CONFIG_I2C_ALGOBIT=y
1732CONFIG_I2C_ALGOPCA=m
1733
1734#
1735# I2C Hardware Bus support
1736#
1737
1738#
1739# PC SMBus host controller drivers
1740#
1741# CONFIG_I2C_ALI1535 is not set
1742# CONFIG_I2C_ALI1563 is not set
1743# CONFIG_I2C_ALI15X3 is not set
1744# CONFIG_I2C_AMD756 is not set
1745# CONFIG_I2C_AMD8111 is not set
1746# CONFIG_I2C_I801 is not set
1747# CONFIG_I2C_ISCH is not set
1748# CONFIG_I2C_PIIX4 is not set
1749# CONFIG_I2C_NFORCE2 is not set
1750# CONFIG_I2C_SIS5595 is not set
1751# CONFIG_I2C_SIS630 is not set
1752# CONFIG_I2C_SIS96X is not set
1753# CONFIG_I2C_VIA is not set
1754# CONFIG_I2C_VIAPRO is not set
1755
1756#
1757# Mac SMBus host controller drivers
1758#
1759CONFIG_I2C_HYDRA=m
1760CONFIG_I2C_POWERMAC=y
1761
1762#
1763# I2C system bus drivers (mostly embedded / system-on-chip)
1764#
1765# CONFIG_I2C_CPM is not set
1766# CONFIG_I2C_GPIO is not set
1767CONFIG_I2C_MPC=m
1768# CONFIG_I2C_OCORES is not set
1769CONFIG_I2C_SIMTEC=m
1770
1771#
1772# External I2C/SMBus adapter drivers
1773#
1774CONFIG_I2C_PARPORT=m
1775CONFIG_I2C_PARPORT_LIGHT=m
1776# CONFIG_I2C_TAOS_EVM is not set
1777CONFIG_I2C_TINY_USB=m
1778
1779#
1780# Graphics adapter I2C/DDC channel drivers
1781#
1782CONFIG_I2C_VOODOO3=m
1783
1784#
1785# Other I2C/SMBus bus drivers
1786#
1787# CONFIG_I2C_ELEKTOR is not set
1788CONFIG_I2C_PCA_ISA=m
1789CONFIG_I2C_PCA_PLATFORM=m
1790CONFIG_I2C_STUB=m
1791
1792#
1793# Miscellaneous I2C Chip support
1794#
1795# CONFIG_DS1682 is not set
1796CONFIG_AT24=m
1797CONFIG_SENSORS_EEPROM=m
1798CONFIG_SENSORS_PCF8574=m
1799CONFIG_PCF8575=m
1800CONFIG_SENSORS_PCA9539=m
1801CONFIG_SENSORS_PCF8591=m
1802# CONFIG_TPS65010 is not set
1803CONFIG_SENSORS_MAX6875=m
1804CONFIG_SENSORS_TSL2550=m
1805# CONFIG_I2C_DEBUG_CORE is not set
1806# CONFIG_I2C_DEBUG_ALGO is not set
1807# CONFIG_I2C_DEBUG_BUS is not set
1808# CONFIG_I2C_DEBUG_CHIP is not set
1809# CONFIG_SPI is not set
1810CONFIG_HAVE_GPIO_LIB=y
1811
1812#
1813# GPIO Support
1814#
1815# CONFIG_DEBUG_GPIO is not set
1816
1817#
1818# I2C GPIO expanders:
1819#
1820# CONFIG_GPIO_PCA953X is not set
1821# CONFIG_GPIO_PCF857X is not set
1822
1823#
1824# SPI GPIO expanders:
1825#
1826CONFIG_W1=m
1827CONFIG_W1_CON=y
1828
1829#
1830# 1-wire Bus Masters
1831#
1832# CONFIG_W1_MASTER_MATROX is not set
1833CONFIG_W1_MASTER_DS2490=m
1834CONFIG_W1_MASTER_DS2482=m
1835# CONFIG_W1_MASTER_GPIO is not set
1836
1837#
1838# 1-wire Slaves
1839#
1840CONFIG_W1_SLAVE_THERM=m
1841CONFIG_W1_SLAVE_SMEM=m
1842CONFIG_W1_SLAVE_DS2433=m
1843CONFIG_W1_SLAVE_DS2433_CRC=y
1844CONFIG_W1_SLAVE_DS2760=m
1845CONFIG_POWER_SUPPLY=m
1846# CONFIG_POWER_SUPPLY_DEBUG is not set
1847# CONFIG_PDA_POWER is not set
1848CONFIG_APM_POWER=m
1849# CONFIG_BATTERY_DS2760 is not set
1850CONFIG_BATTERY_PMU=m
1851CONFIG_HWMON=m
1852CONFIG_HWMON_VID=m
1853CONFIG_SENSORS_AD7418=m
1854CONFIG_SENSORS_ADM1021=m
1855CONFIG_SENSORS_ADM1025=m
1856CONFIG_SENSORS_ADM1026=m
1857CONFIG_SENSORS_ADM1029=m
1858CONFIG_SENSORS_ADM1031=m
1859CONFIG_SENSORS_ADM9240=m
1860CONFIG_SENSORS_ADT7470=m
1861CONFIG_SENSORS_ADT7473=m
1862CONFIG_SENSORS_AMS=m
1863CONFIG_SENSORS_AMS_PMU=y
1864CONFIG_SENSORS_AMS_I2C=y
1865CONFIG_SENSORS_ATXP1=m
1866CONFIG_SENSORS_DS1621=m
1867# CONFIG_SENSORS_I5K_AMB is not set
1868CONFIG_SENSORS_F71805F=m
1869CONFIG_SENSORS_F71882FG=m
1870CONFIG_SENSORS_F75375S=m
1871CONFIG_SENSORS_GL518SM=m
1872CONFIG_SENSORS_GL520SM=m
1873CONFIG_SENSORS_IT87=m
1874CONFIG_SENSORS_LM63=m
1875CONFIG_SENSORS_LM75=m
1876CONFIG_SENSORS_LM77=m
1877CONFIG_SENSORS_LM78=m
1878CONFIG_SENSORS_LM80=m
1879CONFIG_SENSORS_LM83=m
1880CONFIG_SENSORS_LM85=m
1881CONFIG_SENSORS_LM87=m
1882CONFIG_SENSORS_LM90=m
1883CONFIG_SENSORS_LM92=m
1884CONFIG_SENSORS_LM93=m
1885CONFIG_SENSORS_MAX1619=m
1886CONFIG_SENSORS_MAX6650=m
1887CONFIG_SENSORS_PC87360=m
1888CONFIG_SENSORS_PC87427=m
1889CONFIG_SENSORS_SIS5595=m
1890CONFIG_SENSORS_DME1737=m
1891CONFIG_SENSORS_SMSC47M1=m
1892CONFIG_SENSORS_SMSC47M192=m
1893CONFIG_SENSORS_SMSC47B397=m
1894CONFIG_SENSORS_ADS7828=m
1895CONFIG_SENSORS_THMC50=m
1896CONFIG_SENSORS_VIA686A=m
1897CONFIG_SENSORS_VT1211=m
1898CONFIG_SENSORS_VT8231=m
1899CONFIG_SENSORS_W83781D=m
1900CONFIG_SENSORS_W83791D=m
1901CONFIG_SENSORS_W83792D=m
1902CONFIG_SENSORS_W83793=m
1903CONFIG_SENSORS_W83L785TS=m
1904CONFIG_SENSORS_W83L786NG=m
1905CONFIG_SENSORS_W83627HF=m
1906CONFIG_SENSORS_W83627EHF=m
1907# CONFIG_HWMON_DEBUG_CHIP is not set
1908CONFIG_THERMAL=y
1909CONFIG_WATCHDOG=y
1910# CONFIG_WATCHDOG_NOWAYOUT is not set
1911
1912#
1913# Watchdog Device Drivers
1914#
1915CONFIG_SOFT_WATCHDOG=m
1916# CONFIG_MPC5200_WDT is not set
1917CONFIG_83xx_WDT=m
1918CONFIG_WATCHDOG_RTAS=m
1919
1920#
1921# ISA-based Watchdog Cards
1922#
1923# CONFIG_PCWATCHDOG is not set
1924# CONFIG_MIXCOMWD is not set
1925# CONFIG_WDT is not set
1926
1927#
1928# PCI-based Watchdog Cards
1929#
1930# CONFIG_PCIPCWATCHDOG is not set
1931# CONFIG_WDTPCI is not set
1932
1933#
1934# USB-based Watchdog Cards
1935#
1936CONFIG_USBPCWATCHDOG=m
1937
1938#
1939# Sonics Silicon Backplane
1940#
1941CONFIG_SSB_POSSIBLE=y
1942CONFIG_SSB=m
1943CONFIG_SSB_SPROM=y
1944CONFIG_SSB_PCIHOST_POSSIBLE=y
1945CONFIG_SSB_PCIHOST=y
1946# CONFIG_SSB_B43_PCI_BRIDGE is not set
1947CONFIG_SSB_PCMCIAHOST_POSSIBLE=y
1948CONFIG_SSB_PCMCIAHOST=y
1949# CONFIG_SSB_DEBUG is not set
1950CONFIG_SSB_DRIVER_PCICORE_POSSIBLE=y
1951CONFIG_SSB_DRIVER_PCICORE=y
1952
1953#
1954# Multifunction device drivers
1955#
1956CONFIG_MFD_SM501=m
1957# CONFIG_HTC_PASIC3 is not set
1958
1959#
1960# Multimedia devices
1961#
1962
1963#
1964# Multimedia core support
1965#
1966CONFIG_VIDEO_DEV=m
1967CONFIG_VIDEO_V4L2_COMMON=m
1968CONFIG_VIDEO_ALLOW_V4L1=y
1969CONFIG_VIDEO_V4L1_COMPAT=y
1970CONFIG_DVB_CORE=m
1971CONFIG_VIDEO_MEDIA=m
1972
1973#
1974# Multimedia drivers
1975#
1976CONFIG_VIDEO_SAA7146=m
1977CONFIG_VIDEO_SAA7146_VV=m
1978CONFIG_MEDIA_ATTACH=y
1979CONFIG_MEDIA_TUNER=m
1980# CONFIG_MEDIA_TUNER_CUSTOMIZE is not set
1981CONFIG_MEDIA_TUNER_SIMPLE=m
1982CONFIG_MEDIA_TUNER_TDA8290=m
1983CONFIG_MEDIA_TUNER_TDA827X=m
1984CONFIG_MEDIA_TUNER_TDA18271=m
1985CONFIG_MEDIA_TUNER_TDA9887=m
1986CONFIG_MEDIA_TUNER_TEA5761=m
1987CONFIG_MEDIA_TUNER_TEA5767=m
1988CONFIG_MEDIA_TUNER_MT20XX=m
1989CONFIG_MEDIA_TUNER_MT2060=m
1990CONFIG_MEDIA_TUNER_MT2266=m
1991CONFIG_MEDIA_TUNER_MT2131=m
1992CONFIG_MEDIA_TUNER_QT1010=m
1993CONFIG_MEDIA_TUNER_XC2028=m
1994CONFIG_MEDIA_TUNER_XC5000=m
1995CONFIG_MEDIA_TUNER_MXL5005S=m
1996CONFIG_VIDEO_V4L2=m
1997CONFIG_VIDEO_V4L1=m
1998CONFIG_VIDEOBUF_GEN=m
1999CONFIG_VIDEOBUF_DMA_SG=m
2000CONFIG_VIDEOBUF_VMALLOC=m
2001CONFIG_VIDEOBUF_DVB=m
2002CONFIG_VIDEO_BTCX=m
2003CONFIG_VIDEO_IR_I2C=m
2004CONFIG_VIDEO_IR=m
2005CONFIG_VIDEO_TVEEPROM=m
2006CONFIG_VIDEO_TUNER=m
2007CONFIG_VIDEO_CAPTURE_DRIVERS=y
2008# CONFIG_VIDEO_ADV_DEBUG is not set
2009# CONFIG_VIDEO_HELPER_CHIPS_AUTO is not set
2010
2011#
2012# Encoders/decoders and other helper chips
2013#
2014
2015#
2016# Audio decoders
2017#
2018CONFIG_VIDEO_TVAUDIO=m
2019CONFIG_VIDEO_TDA7432=m
2020CONFIG_VIDEO_TDA9840=m
2021CONFIG_VIDEO_TDA9875=m
2022CONFIG_VIDEO_TEA6415C=m
2023CONFIG_VIDEO_TEA6420=m
2024CONFIG_VIDEO_MSP3400=m
2025CONFIG_VIDEO_CS5345=m
2026CONFIG_VIDEO_CS53L32A=m
2027CONFIG_VIDEO_M52790=m
2028CONFIG_VIDEO_TLV320AIC23B=m
2029CONFIG_VIDEO_WM8775=m
2030CONFIG_VIDEO_WM8739=m
2031CONFIG_VIDEO_VP27SMPX=m
2032
2033#
2034# Video decoders
2035#
2036CONFIG_VIDEO_BT819=m
2037CONFIG_VIDEO_BT856=m
2038CONFIG_VIDEO_BT866=m
2039CONFIG_VIDEO_KS0127=m
2040CONFIG_VIDEO_OV7670=m
2041CONFIG_VIDEO_TCM825X=m
2042CONFIG_VIDEO_SAA7110=m
2043CONFIG_VIDEO_SAA7111=m
2044CONFIG_VIDEO_SAA7114=m
2045CONFIG_VIDEO_SAA711X=m
2046CONFIG_VIDEO_SAA717X=m
2047CONFIG_VIDEO_SAA7191=m
2048CONFIG_VIDEO_TVP5150=m
2049CONFIG_VIDEO_VPX3220=m
2050
2051#
2052# Video and audio decoders
2053#
2054CONFIG_VIDEO_CX25840=m
2055
2056#
2057# MPEG video encoders
2058#
2059CONFIG_VIDEO_CX2341X=m
2060
2061#
2062# Video encoders
2063#
2064CONFIG_VIDEO_SAA7127=m
2065CONFIG_VIDEO_SAA7185=m
2066CONFIG_VIDEO_ADV7170=m
2067CONFIG_VIDEO_ADV7175=m
2068
2069#
2070# Video improvement chips
2071#
2072CONFIG_VIDEO_UPD64031A=m
2073CONFIG_VIDEO_UPD64083=m
2074# CONFIG_VIDEO_VIVI is not set
2075CONFIG_VIDEO_BT848=m
2076CONFIG_VIDEO_BT848_DVB=y
2077CONFIG_VIDEO_SAA6588=m
2078# CONFIG_VIDEO_PMS is not set
2079CONFIG_VIDEO_BWQCAM=m
2080CONFIG_VIDEO_CQCAM=m
2081CONFIG_VIDEO_W9966=m
2082CONFIG_VIDEO_CPIA=m
2083CONFIG_VIDEO_CPIA_PP=m
2084CONFIG_VIDEO_CPIA_USB=m
2085CONFIG_VIDEO_CPIA2=m
2086CONFIG_VIDEO_SAA5246A=m
2087CONFIG_VIDEO_SAA5249=m
2088CONFIG_TUNER_3036=m
2089# CONFIG_VIDEO_STRADIS is not set
2090# CONFIG_VIDEO_ZORAN is not set
2091CONFIG_VIDEO_SAA7134=m
2092CONFIG_VIDEO_SAA7134_ALSA=m
2093CONFIG_VIDEO_SAA7134_DVB=m
2094CONFIG_VIDEO_MXB=m
2095CONFIG_VIDEO_DPC=m
2096CONFIG_VIDEO_HEXIUM_ORION=m
2097CONFIG_VIDEO_HEXIUM_GEMINI=m
2098CONFIG_VIDEO_CX88=m
2099CONFIG_VIDEO_CX88_ALSA=m
2100CONFIG_VIDEO_CX88_BLACKBIRD=m
2101CONFIG_VIDEO_CX88_DVB=m
2102CONFIG_VIDEO_CX88_VP3054=m
2103CONFIG_VIDEO_CX23885=m
2104CONFIG_VIDEO_AU0828=m
2105CONFIG_VIDEO_IVTV=m
2106CONFIG_VIDEO_FB_IVTV=m
2107CONFIG_VIDEO_CX18=m
2108# CONFIG_VIDEO_CAFE_CCIC is not set
2109CONFIG_V4L_USB_DRIVERS=y
2110CONFIG_USB_VIDEO_CLASS=m
2111CONFIG_VIDEO_PVRUSB2=m
2112CONFIG_VIDEO_PVRUSB2_SYSFS=y
2113CONFIG_VIDEO_PVRUSB2_DVB=y
2114# CONFIG_VIDEO_PVRUSB2_DEBUGIFC is not set
2115CONFIG_VIDEO_EM28XX=m
2116CONFIG_VIDEO_EM28XX_ALSA=m
2117CONFIG_VIDEO_EM28XX_DVB=m
2118CONFIG_VIDEO_USBVISION=m
2119CONFIG_VIDEO_USBVIDEO=m
2120CONFIG_USB_VICAM=m
2121CONFIG_USB_IBMCAM=m
2122CONFIG_USB_KONICAWC=m
2123CONFIG_USB_QUICKCAM_MESSENGER=m
2124CONFIG_USB_ET61X251=m
2125CONFIG_VIDEO_OVCAMCHIP=m
2126CONFIG_USB_W9968CF=m
2127CONFIG_USB_OV511=m
2128CONFIG_USB_SE401=m
2129CONFIG_USB_SN9C102=m
2130CONFIG_USB_STV680=m
2131CONFIG_USB_ZC0301=m
2132CONFIG_USB_PWC=m
2133# CONFIG_USB_PWC_DEBUG is not set
2134CONFIG_USB_ZR364XX=m
2135CONFIG_USB_STKWEBCAM=m
2136CONFIG_SOC_CAMERA=m
2137CONFIG_SOC_CAMERA_MT9M001=m
2138# CONFIG_MT9M001_PCA9536_SWITCH is not set
2139CONFIG_SOC_CAMERA_MT9V022=m
2140# CONFIG_MT9V022_PCA9536_SWITCH is not set
2141CONFIG_RADIO_ADAPTERS=y
2142# CONFIG_RADIO_CADET is not set
2143# CONFIG_RADIO_RTRACK is not set
2144# CONFIG_RADIO_RTRACK2 is not set
2145# CONFIG_RADIO_AZTECH is not set
2146# CONFIG_RADIO_GEMTEK is not set
2147CONFIG_RADIO_GEMTEK_PCI=m
2148CONFIG_RADIO_MAXIRADIO=m
2149CONFIG_RADIO_MAESTRO=m
2150# CONFIG_RADIO_SF16FMI is not set
2151# CONFIG_RADIO_SF16FMR2 is not set
2152# CONFIG_RADIO_TERRATEC is not set
2153# CONFIG_RADIO_TRUST is not set
2154# CONFIG_RADIO_TYPHOON is not set
2155# CONFIG_RADIO_ZOLTRIX is not set
2156CONFIG_USB_DSBR=m
2157CONFIG_USB_SI470X=m
2158CONFIG_DVB_CAPTURE_DRIVERS=y
2159
2160#
2161# Supported SAA7146 based PCI Adapters
2162#
2163CONFIG_TTPCI_EEPROM=m
2164CONFIG_DVB_AV7110=m
2165CONFIG_DVB_AV7110_OSD=y
2166CONFIG_DVB_BUDGET_CORE=m
2167CONFIG_DVB_BUDGET=m
2168CONFIG_DVB_BUDGET_CI=m
2169CONFIG_DVB_BUDGET_AV=m
2170CONFIG_DVB_BUDGET_PATCH=m
2171
2172#
2173# Supported USB Adapters
2174#
2175CONFIG_DVB_USB=m
2176# CONFIG_DVB_USB_DEBUG is not set
2177CONFIG_DVB_USB_A800=m
2178CONFIG_DVB_USB_DIBUSB_MB=m
2179# CONFIG_DVB_USB_DIBUSB_MB_FAULTY is not set
2180CONFIG_DVB_USB_DIBUSB_MC=m
2181CONFIG_DVB_USB_DIB0700=m
2182CONFIG_DVB_USB_UMT_010=m
2183CONFIG_DVB_USB_CXUSB=m
2184CONFIG_DVB_USB_M920X=m
2185CONFIG_DVB_USB_GL861=m
2186CONFIG_DVB_USB_AU6610=m
2187CONFIG_DVB_USB_DIGITV=m
2188CONFIG_DVB_USB_VP7045=m
2189CONFIG_DVB_USB_VP702X=m
2190CONFIG_DVB_USB_GP8PSK=m
2191CONFIG_DVB_USB_NOVA_T_USB2=m
2192CONFIG_DVB_USB_TTUSB2=m
2193CONFIG_DVB_USB_DTT200U=m
2194CONFIG_DVB_USB_OPERA1=m
2195CONFIG_DVB_USB_AF9005=m
2196CONFIG_DVB_USB_AF9005_REMOTE=m
2197CONFIG_DVB_TTUSB_BUDGET=m
2198CONFIG_DVB_TTUSB_DEC=m
2199CONFIG_DVB_CINERGYT2=m
2200CONFIG_DVB_CINERGYT2_TUNING=y
2201CONFIG_DVB_CINERGYT2_STREAM_URB_COUNT=32
2202CONFIG_DVB_CINERGYT2_STREAM_BUF_SIZE=512
2203CONFIG_DVB_CINERGYT2_QUERY_INTERVAL=250
2204CONFIG_DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE=y
2205CONFIG_DVB_CINERGYT2_RC_QUERY_INTERVAL=100
2206
2207#
2208# Supported FlexCopII (B2C2) Adapters
2209#
2210CONFIG_DVB_B2C2_FLEXCOP=m
2211CONFIG_DVB_B2C2_FLEXCOP_PCI=m
2212CONFIG_DVB_B2C2_FLEXCOP_USB=m
2213# CONFIG_DVB_B2C2_FLEXCOP_DEBUG is not set
2214
2215#
2216# Supported BT878 Adapters
2217#
2218CONFIG_DVB_BT8XX=m
2219
2220#
2221# Supported Pluto2 Adapters
2222#
2223CONFIG_DVB_PLUTO2=m
2224
2225#
2226# Supported DVB Frontends
2227#
2228
2229#
2230# Customise DVB Frontends
2231#
2232# CONFIG_DVB_FE_CUSTOMISE is not set
2233
2234#
2235# DVB-S (satellite) frontends
2236#
2237CONFIG_DVB_CX24110=m
2238CONFIG_DVB_CX24123=m
2239CONFIG_DVB_MT312=m
2240CONFIG_DVB_S5H1420=m
2241CONFIG_DVB_STV0299=m
2242CONFIG_DVB_TDA8083=m
2243CONFIG_DVB_TDA10086=m
2244CONFIG_DVB_VES1X93=m
2245CONFIG_DVB_TUNER_ITD1000=m
2246CONFIG_DVB_TDA826X=m
2247CONFIG_DVB_TUA6100=m
2248
2249#
2250# DVB-T (terrestrial) frontends
2251#
2252CONFIG_DVB_SP8870=m
2253CONFIG_DVB_SP887X=m
2254CONFIG_DVB_CX22700=m
2255CONFIG_DVB_CX22702=m
2256CONFIG_DVB_L64781=m
2257CONFIG_DVB_TDA1004X=m
2258CONFIG_DVB_NXT6000=m
2259CONFIG_DVB_MT352=m
2260CONFIG_DVB_ZL10353=m
2261CONFIG_DVB_DIB3000MB=m
2262CONFIG_DVB_DIB3000MC=m
2263CONFIG_DVB_DIB7000M=m
2264CONFIG_DVB_DIB7000P=m
2265CONFIG_DVB_TDA10048=m
2266
2267#
2268# DVB-C (cable) frontends
2269#
2270CONFIG_DVB_VES1820=m
2271CONFIG_DVB_TDA10021=m
2272CONFIG_DVB_TDA10023=m
2273CONFIG_DVB_STV0297=m
2274
2275#
2276# ATSC (North American/Korean Terrestrial/Cable DTV) frontends
2277#
2278CONFIG_DVB_NXT200X=m
2279CONFIG_DVB_OR51211=m
2280CONFIG_DVB_OR51132=m
2281CONFIG_DVB_BCM3510=m
2282CONFIG_DVB_LGDT330X=m
2283CONFIG_DVB_S5H1409=m
2284CONFIG_DVB_AU8522=m
2285CONFIG_DVB_S5H1411=m
2286
2287#
2288# Digital terrestrial only tuners/PLL
2289#
2290CONFIG_DVB_PLL=m
2291CONFIG_DVB_TUNER_DIB0070=m
2292
2293#
2294# SEC control devices for DVB-S
2295#
2296CONFIG_DVB_LNBP21=m
2297CONFIG_DVB_ISL6405=m
2298CONFIG_DVB_ISL6421=m
2299CONFIG_DAB=y
2300CONFIG_USB_DABUSB=m
2301
2302#
2303# Graphics support
2304#
2305CONFIG_AGP=y
2306CONFIG_AGP_UNINORTH=y
2307CONFIG_DRM=m
2308CONFIG_DRM_TDFX=m
2309CONFIG_DRM_R128=m
2310CONFIG_DRM_RADEON=m
2311CONFIG_DRM_MGA=m
2312CONFIG_DRM_SIS=m
2313CONFIG_DRM_VIA=m
2314CONFIG_DRM_SAVAGE=m
2315CONFIG_VGASTATE=y
2316CONFIG_VIDEO_OUTPUT_CONTROL=m
2317CONFIG_FB=y
2318# CONFIG_FIRMWARE_EDID is not set
2319CONFIG_FB_DDC=y
2320CONFIG_FB_CFB_FILLRECT=y
2321CONFIG_FB_CFB_COPYAREA=y
2322CONFIG_FB_CFB_IMAGEBLIT=y
2323# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
2324# CONFIG_FB_SYS_FILLRECT is not set
2325# CONFIG_FB_SYS_COPYAREA is not set
2326# CONFIG_FB_SYS_IMAGEBLIT is not set
2327# CONFIG_FB_FOREIGN_ENDIAN is not set
2328# CONFIG_FB_SYS_FOPS is not set
2329CONFIG_FB_SVGALIB=m
2330CONFIG_FB_MACMODES=y
2331CONFIG_FB_BACKLIGHT=y
2332CONFIG_FB_MODE_HELPERS=y
2333CONFIG_FB_TILEBLITTING=y
2334
2335#
2336# Frame buffer hardware drivers
2337#
2338CONFIG_FB_CIRRUS=m
2339# CONFIG_FB_PM2 is not set
2340# CONFIG_FB_CYBER2000 is not set
2341CONFIG_FB_OF=y
2342# CONFIG_FB_CONTROL is not set
2343CONFIG_FB_PLATINUM=y
2344CONFIG_FB_VALKYRIE=y
2345CONFIG_FB_CT65550=y
2346# CONFIG_FB_ASILIANT is not set
2347# CONFIG_FB_IMSTT is not set
2348# CONFIG_FB_VGA16 is not set
2349# CONFIG_FB_UVESA is not set
2350# CONFIG_FB_S1D13XXX is not set
2351CONFIG_FB_NVIDIA=y
2352CONFIG_FB_NVIDIA_I2C=y
2353# CONFIG_FB_NVIDIA_DEBUG is not set
2354CONFIG_FB_NVIDIA_BACKLIGHT=y
2355CONFIG_FB_RIVA=m
2356# CONFIG_FB_RIVA_I2C is not set
2357# CONFIG_FB_RIVA_DEBUG is not set
2358CONFIG_FB_RIVA_BACKLIGHT=y
2359CONFIG_FB_MATROX=y
2360CONFIG_FB_MATROX_MILLENIUM=y
2361CONFIG_FB_MATROX_MYSTIQUE=y
2362CONFIG_FB_MATROX_G=y
2363CONFIG_FB_MATROX_I2C=m
2364CONFIG_FB_MATROX_MAVEN=m
2365CONFIG_FB_MATROX_MULTIHEAD=y
2366CONFIG_FB_RADEON=y
2367CONFIG_FB_RADEON_I2C=y
2368CONFIG_FB_RADEON_BACKLIGHT=y
2369# CONFIG_FB_RADEON_DEBUG is not set
2370CONFIG_FB_ATY128=y
2371CONFIG_FB_ATY128_BACKLIGHT=y
2372CONFIG_FB_ATY=y
2373CONFIG_FB_ATY_CT=y
2374CONFIG_FB_ATY_GENERIC_LCD=y
2375CONFIG_FB_ATY_GX=y
2376CONFIG_FB_ATY_BACKLIGHT=y
2377CONFIG_FB_S3=m
2378CONFIG_FB_SAVAGE=m
2379CONFIG_FB_SAVAGE_I2C=y
2380CONFIG_FB_SAVAGE_ACCEL=y
2381# CONFIG_FB_SIS is not set
2382CONFIG_FB_NEOMAGIC=m
2383CONFIG_FB_KYRO=m
2384CONFIG_FB_3DFX=m
2385CONFIG_FB_3DFX_ACCEL=y
2386CONFIG_FB_VOODOO1=m
2387# CONFIG_FB_VT8623 is not set
2388CONFIG_FB_TRIDENT=m
2389CONFIG_FB_TRIDENT_ACCEL=y
2390# CONFIG_FB_ARK is not set
2391# CONFIG_FB_PM3 is not set
2392# CONFIG_FB_FSL_DIU is not set
2393CONFIG_FB_SM501=m
2394CONFIG_FB_IBM_GXT4500=y
2395# CONFIG_FB_VIRTUAL is not set
2396CONFIG_BACKLIGHT_LCD_SUPPORT=y
2397CONFIG_LCD_CLASS_DEVICE=m
2398CONFIG_BACKLIGHT_CLASS_DEVICE=y
2399# CONFIG_BACKLIGHT_CORGI is not set
2400
2401#
2402# Display device support
2403#
2404CONFIG_DISPLAY_SUPPORT=m
2405
2406#
2407# Display hardware drivers
2408#
2409
2410#
2411# Console display driver support
2412#
2413CONFIG_VGA_CONSOLE=y
2414CONFIG_VGACON_SOFT_SCROLLBACK=y
2415CONFIG_VGACON_SOFT_SCROLLBACK_SIZE=64
2416# CONFIG_MDA_CONSOLE is not set
2417CONFIG_DUMMY_CONSOLE=y
2418CONFIG_FRAMEBUFFER_CONSOLE=y
2419CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
2420CONFIG_FRAMEBUFFER_CONSOLE_ROTATION=y
2421# CONFIG_FONTS is not set
2422CONFIG_FONT_8x8=y
2423CONFIG_FONT_8x16=y
2424CONFIG_LOGO=y
2425# CONFIG_LOGO_LINUX_MONO is not set
2426# CONFIG_LOGO_LINUX_VGA16 is not set
2427CONFIG_LOGO_LINUX_CLUT224=y
2428CONFIG_SOUND=m
2429CONFIG_SND=m
2430CONFIG_SND_TIMER=m
2431CONFIG_SND_PCM=m
2432CONFIG_SND_HWDEP=m
2433CONFIG_SND_RAWMIDI=m
2434CONFIG_SND_SEQUENCER=m
2435CONFIG_SND_SEQ_DUMMY=m
2436CONFIG_SND_OSSEMUL=y
2437CONFIG_SND_MIXER_OSS=m
2438CONFIG_SND_PCM_OSS=m
2439CONFIG_SND_PCM_OSS_PLUGINS=y
2440CONFIG_SND_SEQUENCER_OSS=y
2441CONFIG_SND_DYNAMIC_MINORS=y
2442# CONFIG_SND_SUPPORT_OLD_API is not set
2443CONFIG_SND_VERBOSE_PROCFS=y
2444CONFIG_SND_VERBOSE_PRINTK=y
2445CONFIG_SND_DEBUG=y
2446CONFIG_SND_DEBUG_VERBOSE=y
2447CONFIG_SND_PCM_XRUN_DEBUG=y
2448CONFIG_SND_VMASTER=y
2449CONFIG_SND_MPU401_UART=m
2450CONFIG_SND_OPL3_LIB=m
2451CONFIG_SND_VX_LIB=m
2452CONFIG_SND_AC97_CODEC=m
2453CONFIG_SND_DRIVERS=y
2454CONFIG_SND_DUMMY=m
2455CONFIG_SND_VIRMIDI=m
2456CONFIG_SND_MTPAV=m
2457CONFIG_SND_MTS64=m
2458CONFIG_SND_SERIAL_U16550=m
2459CONFIG_SND_MPU401=m
2460CONFIG_SND_PORTMAN2X4=m
2461CONFIG_SND_AC97_POWER_SAVE=y
2462CONFIG_SND_AC97_POWER_SAVE_DEFAULT=5
2463CONFIG_SND_SB_COMMON=m
2464CONFIG_SND_SB16_DSP=m
2465CONFIG_SND_ISA=y
2466# CONFIG_SND_ADLIB is not set
2467# CONFIG_SND_AD1816A is not set
2468# CONFIG_SND_AD1848 is not set
2469# CONFIG_SND_ALS100 is not set
2470# CONFIG_SND_AZT2320 is not set
2471# CONFIG_SND_CMI8330 is not set
2472# CONFIG_SND_CS4231 is not set
2473# CONFIG_SND_CS4232 is not set
2474# CONFIG_SND_CS4236 is not set
2475# CONFIG_SND_DT019X is not set
2476# CONFIG_SND_ES968 is not set
2477# CONFIG_SND_ES1688 is not set
2478# CONFIG_SND_ES18XX is not set
2479# CONFIG_SND_SC6000 is not set
2480# CONFIG_SND_GUSCLASSIC is not set
2481# CONFIG_SND_GUSEXTREME is not set
2482# CONFIG_SND_GUSMAX is not set
2483# CONFIG_SND_INTERWAVE is not set
2484# CONFIG_SND_INTERWAVE_STB is not set
2485# CONFIG_SND_OPL3SA2 is not set
2486# CONFIG_SND_OPTI92X_AD1848 is not set
2487# CONFIG_SND_OPTI92X_CS4231 is not set
2488# CONFIG_SND_OPTI93X is not set
2489# CONFIG_SND_MIRO is not set
2490# CONFIG_SND_SB8 is not set
2491# CONFIG_SND_SB16 is not set
2492# CONFIG_SND_SBAWE is not set
2493# CONFIG_SND_SGALAXY is not set
2494# CONFIG_SND_SSCAPE is not set
2495# CONFIG_SND_WAVEFRONT is not set
2496CONFIG_SND_PCI=y
2497CONFIG_SND_AD1889=m
2498CONFIG_SND_ALS300=m
2499CONFIG_SND_ALS4000=m
2500CONFIG_SND_ALI5451=m
2501CONFIG_SND_ATIIXP=m
2502CONFIG_SND_ATIIXP_MODEM=m
2503CONFIG_SND_AU8810=m
2504CONFIG_SND_AU8820=m
2505CONFIG_SND_AU8830=m
2506CONFIG_SND_AW2=m
2507CONFIG_SND_AZT3328=m
2508CONFIG_SND_BT87X=m
2509# CONFIG_SND_BT87X_OVERCLOCK is not set
2510CONFIG_SND_CA0106=m
2511CONFIG_SND_CMIPCI=m
2512CONFIG_SND_OXYGEN_LIB=m
2513CONFIG_SND_OXYGEN=m
2514CONFIG_SND_CS4281=m
2515CONFIG_SND_CS46XX=m
2516CONFIG_SND_CS46XX_NEW_DSP=y
2517CONFIG_SND_CS5530=m
2518CONFIG_SND_DARLA20=m
2519CONFIG_SND_GINA20=m
2520CONFIG_SND_LAYLA20=m
2521CONFIG_SND_DARLA24=m
2522CONFIG_SND_GINA24=m
2523CONFIG_SND_LAYLA24=m
2524CONFIG_SND_MONA=m
2525CONFIG_SND_MIA=m
2526CONFIG_SND_ECHO3G=m
2527CONFIG_SND_INDIGO=m
2528CONFIG_SND_INDIGOIO=m
2529CONFIG_SND_INDIGODJ=m
2530CONFIG_SND_EMU10K1=m
2531CONFIG_SND_EMU10K1X=m
2532CONFIG_SND_ENS1370=m
2533CONFIG_SND_ENS1371=m
2534CONFIG_SND_ES1938=m
2535CONFIG_SND_ES1968=m
2536CONFIG_SND_FM801=m
2537CONFIG_SND_FM801_TEA575X_BOOL=y
2538CONFIG_SND_FM801_TEA575X=m
2539# CONFIG_SND_HDA_INTEL is not set
2540CONFIG_SND_HDSP=m
2541CONFIG_SND_HDSPM=m
2542CONFIG_SND_HIFIER=m
2543CONFIG_SND_ICE1712=m
2544CONFIG_SND_ICE1724=m
2545# CONFIG_SND_INTEL8X0 is not set
2546# CONFIG_SND_INTEL8X0M is not set
2547CONFIG_SND_KORG1212=m
2548CONFIG_SND_MAESTRO3=m
2549CONFIG_SND_MIXART=m
2550CONFIG_SND_NM256=m
2551CONFIG_SND_PCXHR=m
2552CONFIG_SND_RIPTIDE=m
2553CONFIG_SND_RME32=m
2554CONFIG_SND_RME96=m
2555CONFIG_SND_RME9652=m
2556CONFIG_SND_SONICVIBES=m
2557CONFIG_SND_TRIDENT=m
2558CONFIG_SND_VIA82XX=m
2559CONFIG_SND_VIA82XX_MODEM=m
2560CONFIG_SND_VIRTUOSO=m
2561CONFIG_SND_VX222=m
2562# CONFIG_SND_YMFPCI is not set
2563CONFIG_SND_PPC=y
2564CONFIG_SND_POWERMAC=m
2565CONFIG_SND_POWERMAC_AUTO_DRC=y
2566CONFIG_SND_AOA=m
2567CONFIG_SND_AOA_FABRIC_LAYOUT=m
2568CONFIG_SND_AOA_ONYX=m
2569CONFIG_SND_AOA_TAS=m
2570CONFIG_SND_AOA_TOONIE=m
2571CONFIG_SND_AOA_SOUNDBUS=m
2572CONFIG_SND_AOA_SOUNDBUS_I2S=m
2573CONFIG_SND_USB=y
2574CONFIG_SND_USB_AUDIO=m
2575CONFIG_SND_USB_USX2Y=m
2576CONFIG_SND_USB_CAIAQ=m
2577CONFIG_SND_USB_CAIAQ_INPUT=y
2578# CONFIG_SND_PCMCIA is not set
2579# CONFIG_SND_SOC is not set
2580# CONFIG_SOUND_PRIME is not set
2581CONFIG_AC97_BUS=m
2582CONFIG_HID_SUPPORT=y
2583CONFIG_HID=y
2584CONFIG_HID_DEBUG=y
2585CONFIG_HIDRAW=y
2586
2587#
2588# USB Input Devices
2589#
2590CONFIG_USB_HID=y
2591CONFIG_USB_HIDINPUT_POWERBOOK=y
2592CONFIG_HID_FF=y
2593CONFIG_HID_PID=y
2594CONFIG_LOGITECH_FF=y
2595CONFIG_LOGIRUMBLEPAD2_FF=y
2596CONFIG_PANTHERLORD_FF=y
2597CONFIG_THRUSTMASTER_FF=y
2598CONFIG_ZEROPLUS_FF=y
2599CONFIG_USB_HIDDEV=y
2600CONFIG_USB_SUPPORT=y
2601CONFIG_USB_ARCH_HAS_HCD=y
2602CONFIG_USB_ARCH_HAS_OHCI=y
2603CONFIG_USB_ARCH_HAS_EHCI=y
2604CONFIG_USB=y
2605CONFIG_USB_DEBUG=y
2606CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
2607
2608#
2609# Miscellaneous USB options
2610#
2611CONFIG_USB_DEVICEFS=y
2612# CONFIG_USB_DEVICE_CLASS is not set
2613# CONFIG_USB_DYNAMIC_MINORS is not set
2614CONFIG_USB_SUSPEND=y
2615# CONFIG_USB_OTG is not set
2616
2617#
2618# USB Host Controller Drivers
2619#
2620# CONFIG_USB_C67X00_HCD is not set
2621CONFIG_USB_EHCI_HCD=m
2622CONFIG_USB_EHCI_ROOT_HUB_TT=y
2623CONFIG_USB_EHCI_TT_NEWSCHED=y
2624CONFIG_USB_EHCI_FSL=y
2625CONFIG_USB_EHCI_HCD_PPC_OF=y
2626# CONFIG_USB_ISP116X_HCD is not set
2627# CONFIG_USB_ISP1760_HCD is not set
2628CONFIG_USB_OHCI_HCD=m
2629CONFIG_USB_OHCI_HCD_PPC_SOC=y
2630CONFIG_USB_OHCI_HCD_PPC_OF=y
2631CONFIG_USB_OHCI_HCD_PPC_OF_BE=y
2632CONFIG_USB_OHCI_HCD_PPC_OF_LE=y
2633CONFIG_USB_OHCI_HCD_PCI=y
2634# CONFIG_USB_OHCI_HCD_SSB is not set
2635CONFIG_USB_OHCI_BIG_ENDIAN_DESC=y
2636CONFIG_USB_OHCI_BIG_ENDIAN_MMIO=y
2637CONFIG_USB_OHCI_LITTLE_ENDIAN=y
2638CONFIG_USB_UHCI_HCD=m
2639CONFIG_USB_U132_HCD=m
2640CONFIG_USB_SL811_HCD=m
2641# CONFIG_USB_SL811_CS is not set
2642# CONFIG_USB_R8A66597_HCD is not set
2643
2644#
2645# USB Device Class drivers
2646#
2647CONFIG_USB_ACM=m
2648CONFIG_USB_PRINTER=m
2649CONFIG_USB_WDM=m
2650
2651#
2652# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
2653#
2654
2655#
2656# may also be needed; see USB_STORAGE Help for more information
2657#
2658CONFIG_USB_STORAGE=m
2659# CONFIG_USB_STORAGE_DEBUG is not set
2660CONFIG_USB_STORAGE_DATAFAB=y
2661CONFIG_USB_STORAGE_FREECOM=y
2662# CONFIG_USB_STORAGE_ISD200 is not set
2663CONFIG_USB_STORAGE_DPCM=y
2664CONFIG_USB_STORAGE_USBAT=y
2665CONFIG_USB_STORAGE_SDDR09=y
2666CONFIG_USB_STORAGE_SDDR55=y
2667CONFIG_USB_STORAGE_JUMPSHOT=y
2668CONFIG_USB_STORAGE_ALAUDA=y
2669CONFIG_USB_STORAGE_ONETOUCH=y
2670CONFIG_USB_STORAGE_KARMA=y
2671CONFIG_USB_STORAGE_CYPRESS_ATACB=y
2672# CONFIG_USB_LIBUSUAL is not set
2673
2674#
2675# USB Imaging devices
2676#
2677CONFIG_USB_MDC800=m
2678CONFIG_USB_MICROTEK=m
2679CONFIG_USB_MON=y
2680
2681#
2682# USB port drivers
2683#
2684CONFIG_USB_USS720=m
2685CONFIG_USB_SERIAL=m
2686CONFIG_USB_EZUSB=y
2687CONFIG_USB_SERIAL_GENERIC=y
2688CONFIG_USB_SERIAL_AIRCABLE=m
2689CONFIG_USB_SERIAL_AIRPRIME=m
2690CONFIG_USB_SERIAL_ARK3116=m
2691CONFIG_USB_SERIAL_BELKIN=m
2692CONFIG_USB_SERIAL_CH341=m
2693CONFIG_USB_SERIAL_WHITEHEAT=m
2694CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
2695CONFIG_USB_SERIAL_CP2101=m
2696CONFIG_USB_SERIAL_CYPRESS_M8=m
2697CONFIG_USB_SERIAL_EMPEG=m
2698CONFIG_USB_SERIAL_FTDI_SIO=m
2699CONFIG_USB_SERIAL_FUNSOFT=m
2700CONFIG_USB_SERIAL_VISOR=m
2701CONFIG_USB_SERIAL_IPAQ=m
2702CONFIG_USB_SERIAL_IR=m
2703CONFIG_USB_SERIAL_EDGEPORT=m
2704CONFIG_USB_SERIAL_EDGEPORT_TI=m
2705# CONFIG_USB_SERIAL_GARMIN is not set
2706CONFIG_USB_SERIAL_IPW=m
2707CONFIG_USB_SERIAL_IUU=m
2708CONFIG_USB_SERIAL_KEYSPAN_PDA=m
2709CONFIG_USB_SERIAL_KEYSPAN=m
2710CONFIG_USB_SERIAL_KLSI=m
2711CONFIG_USB_SERIAL_KOBIL_SCT=m
2712CONFIG_USB_SERIAL_MCT_U232=m
2713CONFIG_USB_SERIAL_MOS7720=m
2714CONFIG_USB_SERIAL_MOS7840=m
2715CONFIG_USB_SERIAL_MOTOROLA=m
2716CONFIG_USB_SERIAL_NAVMAN=m
2717CONFIG_USB_SERIAL_PL2303=m
2718CONFIG_USB_SERIAL_OTI6858=m
2719CONFIG_USB_SERIAL_SPCP8X5=m
2720CONFIG_USB_SERIAL_HP4X=m
2721CONFIG_USB_SERIAL_SAFE=m
2722CONFIG_USB_SERIAL_SAFE_PADDED=y
2723CONFIG_USB_SERIAL_SIERRAWIRELESS=m
2724CONFIG_USB_SERIAL_TI=m
2725CONFIG_USB_SERIAL_CYBERJACK=m
2726CONFIG_USB_SERIAL_XIRCOM=m
2727CONFIG_USB_SERIAL_OPTION=m
2728CONFIG_USB_SERIAL_OMNINET=m
2729CONFIG_USB_SERIAL_DEBUG=m
2730
2731#
2732# USB Miscellaneous drivers
2733#
2734CONFIG_USB_EMI62=m
2735CONFIG_USB_EMI26=m
2736CONFIG_USB_ADUTUX=m
2737CONFIG_USB_AUERSWALD=m
2738# CONFIG_USB_RIO500 is not set
2739CONFIG_USB_LEGOTOWER=m
2740CONFIG_USB_LCD=m
2741CONFIG_USB_BERRY_CHARGE=m
2742CONFIG_USB_LED=m
2743# CONFIG_USB_CYPRESS_CY7C63 is not set
2744# CONFIG_USB_CYTHERM is not set
2745CONFIG_USB_PHIDGET=m
2746CONFIG_USB_PHIDGETKIT=m
2747CONFIG_USB_PHIDGETMOTORCONTROL=m
2748CONFIG_USB_PHIDGETSERVO=m
2749CONFIG_USB_IDMOUSE=m
2750CONFIG_USB_FTDI_ELAN=m
2751CONFIG_USB_APPLEDISPLAY=m
2752CONFIG_USB_SISUSBVGA=m
2753CONFIG_USB_SISUSBVGA_CON=y
2754CONFIG_USB_LD=m
2755CONFIG_USB_TRANCEVIBRATOR=m
2756CONFIG_USB_IOWARRIOR=m
2757# CONFIG_USB_TEST is not set
2758CONFIG_USB_ISIGHTFW=m
2759CONFIG_USB_ATM=m
2760CONFIG_USB_SPEEDTOUCH=m
2761CONFIG_USB_CXACRU=m
2762CONFIG_USB_UEAGLEATM=m
2763CONFIG_USB_XUSBATM=m
2764# CONFIG_USB_GADGET is not set
2765# CONFIG_MMC is not set
2766# CONFIG_MEMSTICK is not set
2767CONFIG_NEW_LEDS=y
2768CONFIG_LEDS_CLASS=y
2769
2770#
2771# LED drivers
2772#
2773# CONFIG_LEDS_GPIO is not set
2774
2775#
2776# LED Triggers
2777#
2778CONFIG_LEDS_TRIGGERS=y
2779CONFIG_LEDS_TRIGGER_TIMER=m
2780CONFIG_LEDS_TRIGGER_IDE_DISK=y
2781CONFIG_LEDS_TRIGGER_HEARTBEAT=m
2782CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
2783CONFIG_ACCESSIBILITY=y
2784CONFIG_A11Y_BRAILLE_CONSOLE=y
2785# CONFIG_INFINIBAND is not set
2786CONFIG_EDAC=y
2787
2788#
2789# Reporting subsystems
2790#
2791# CONFIG_EDAC_DEBUG is not set
2792CONFIG_EDAC_MM_EDAC=m
2793CONFIG_RTC_LIB=y
2794CONFIG_RTC_CLASS=y
2795# CONFIG_RTC_HCTOSYS is not set
2796# CONFIG_RTC_DEBUG is not set
2797
2798#
2799# RTC interfaces
2800#
2801CONFIG_RTC_INTF_SYSFS=y
2802CONFIG_RTC_INTF_PROC=y
2803CONFIG_RTC_INTF_DEV=y
2804# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
2805# CONFIG_RTC_DRV_TEST is not set
2806
2807#
2808# I2C RTC drivers
2809#
2810CONFIG_RTC_DRV_DS1307=m
2811CONFIG_RTC_DRV_DS1374=m
2812CONFIG_RTC_DRV_DS1672=m
2813CONFIG_RTC_DRV_MAX6900=m
2814CONFIG_RTC_DRV_RS5C372=m
2815CONFIG_RTC_DRV_ISL1208=m
2816CONFIG_RTC_DRV_X1205=m
2817CONFIG_RTC_DRV_PCF8563=m
2818CONFIG_RTC_DRV_PCF8583=m
2819CONFIG_RTC_DRV_M41T80=m
2820CONFIG_RTC_DRV_M41T80_WDT=y
2821# CONFIG_RTC_DRV_S35390A is not set
2822CONFIG_RTC_DRV_FM3130=m
2823
2824#
2825# SPI RTC drivers
2826#
2827
2828#
2829# Platform RTC drivers
2830#
2831CONFIG_RTC_DRV_CMOS=y
2832CONFIG_RTC_DRV_DS1511=m
2833CONFIG_RTC_DRV_DS1553=m
2834CONFIG_RTC_DRV_DS1742=m
2835CONFIG_RTC_DRV_STK17TA8=m
2836# CONFIG_RTC_DRV_M48T86 is not set
2837CONFIG_RTC_DRV_M48T59=m
2838CONFIG_RTC_DRV_V3020=m
2839
2840#
2841# on-CPU RTC drivers
2842#
2843CONFIG_RTC_DRV_PPC=y
2844CONFIG_DMADEVICES=y
2845
2846#
2847# DMA Devices
2848#
2849# CONFIG_FSL_DMA is not set
2850CONFIG_AUXDISPLAY=y
2851CONFIG_KS0108=m
2852CONFIG_KS0108_PORT=0x378
2853CONFIG_KS0108_DELAY=2
2854CONFIG_UIO=m
2855CONFIG_UIO_CIF=m
2856CONFIG_UIO_SMX=m
2857
2858#
2859# File systems
2860#
2861CONFIG_EXT2_FS=m
2862CONFIG_EXT2_FS_XATTR=y
2863CONFIG_EXT2_FS_POSIX_ACL=y
2864CONFIG_EXT2_FS_SECURITY=y
2865CONFIG_EXT2_FS_XIP=y
2866CONFIG_FS_XIP=y
2867CONFIG_EXT3_FS=m
2868CONFIG_EXT3_FS_XATTR=y
2869CONFIG_EXT3_FS_POSIX_ACL=y
2870CONFIG_EXT3_FS_SECURITY=y
2871CONFIG_EXT4DEV_FS=m
2872CONFIG_EXT4DEV_FS_XATTR=y
2873CONFIG_EXT4DEV_FS_POSIX_ACL=y
2874CONFIG_EXT4DEV_FS_SECURITY=y
2875CONFIG_JBD=m
2876# CONFIG_JBD_DEBUG is not set
2877CONFIG_JBD2=m
2878CONFIG_JBD2_DEBUG=y
2879CONFIG_FS_MBCACHE=m
2880CONFIG_REISERFS_FS=m
2881# CONFIG_REISERFS_CHECK is not set
2882CONFIG_REISERFS_PROC_INFO=y
2883CONFIG_REISERFS_FS_XATTR=y
2884CONFIG_REISERFS_FS_POSIX_ACL=y
2885CONFIG_REISERFS_FS_SECURITY=y
2886CONFIG_JFS_FS=m
2887CONFIG_JFS_POSIX_ACL=y
2888CONFIG_JFS_SECURITY=y
2889# CONFIG_JFS_DEBUG is not set
2890# CONFIG_JFS_STATISTICS is not set
2891CONFIG_FS_POSIX_ACL=y
2892CONFIG_XFS_FS=m
2893CONFIG_XFS_QUOTA=y
2894CONFIG_XFS_POSIX_ACL=y
2895# CONFIG_XFS_RT is not set
2896# CONFIG_XFS_DEBUG is not set
2897CONFIG_GFS2_FS=m
2898CONFIG_GFS2_FS_LOCKING_DLM=m
2899CONFIG_OCFS2_FS=m
2900CONFIG_OCFS2_FS_O2CB=m
2901CONFIG_OCFS2_FS_USERSPACE_CLUSTER=m
2902# CONFIG_OCFS2_DEBUG_MASKLOG is not set
2903# CONFIG_OCFS2_DEBUG_FS is not set
2904CONFIG_DNOTIFY=y
2905CONFIG_INOTIFY=y
2906CONFIG_INOTIFY_USER=y
2907CONFIG_QUOTA=y
2908CONFIG_QUOTA_NETLINK_INTERFACE=y
2909# CONFIG_PRINT_QUOTA_WARNING is not set
2910# CONFIG_QFMT_V1 is not set
2911CONFIG_QFMT_V2=y
2912CONFIG_QUOTACTL=y
2913CONFIG_AUTOFS_FS=m
2914CONFIG_AUTOFS4_FS=m
2915CONFIG_FUSE_FS=m
2916CONFIG_GENERIC_ACL=y
2917
2918#
2919# CD-ROM/DVD Filesystems
2920#
2921CONFIG_ISO9660_FS=y
2922CONFIG_JOLIET=y
2923CONFIG_ZISOFS=y
2924CONFIG_UDF_FS=m
2925CONFIG_UDF_NLS=y
2926
2927#
2928# DOS/FAT/NT Filesystems
2929#
2930CONFIG_FAT_FS=m
2931CONFIG_MSDOS_FS=m
2932CONFIG_VFAT_FS=m
2933CONFIG_FAT_DEFAULT_CODEPAGE=437
2934CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
2935# CONFIG_NTFS_FS is not set
2936
2937#
2938# Pseudo filesystems
2939#
2940CONFIG_PROC_FS=y
2941CONFIG_PROC_KCORE=y
2942CONFIG_PROC_SYSCTL=y
2943CONFIG_SYSFS=y
2944CONFIG_TMPFS=y
2945CONFIG_TMPFS_POSIX_ACL=y
2946# CONFIG_HUGETLB_PAGE is not set
2947CONFIG_CONFIGFS_FS=m
2948
2949#
2950# Miscellaneous filesystems
2951#
2952# CONFIG_ADFS_FS is not set
2953CONFIG_AFFS_FS=m
2954CONFIG_ECRYPT_FS=m
2955CONFIG_HFS_FS=m
2956CONFIG_HFSPLUS_FS=m
2957CONFIG_BEFS_FS=m
2958# CONFIG_BEFS_DEBUG is not set
2959CONFIG_BFS_FS=m
2960CONFIG_EFS_FS=m
2961CONFIG_CRAMFS=m
2962CONFIG_SQUASHFS=m
2963# CONFIG_SQUASHFS_EMBEDDED is not set
2964CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3
2965CONFIG_VXFS_FS=m
2966CONFIG_MINIX_FS=m
2967# CONFIG_HPFS_FS is not set
2968CONFIG_QNX4FS_FS=m
2969CONFIG_ROMFS_FS=m
2970CONFIG_SYSV_FS=m
2971CONFIG_UFS_FS=m
2972# CONFIG_UFS_FS_WRITE is not set
2973# CONFIG_UFS_DEBUG is not set
2974CONFIG_NETWORK_FILESYSTEMS=y
2975CONFIG_NFS_FS=m
2976CONFIG_NFS_V3=y
2977CONFIG_NFS_V3_ACL=y
2978CONFIG_NFS_V4=y
2979CONFIG_NFSD=m
2980CONFIG_NFSD_V2_ACL=y
2981CONFIG_NFSD_V3=y
2982CONFIG_NFSD_V3_ACL=y
2983CONFIG_NFSD_V4=y
2984CONFIG_LOCKD=m
2985CONFIG_LOCKD_V4=y
2986CONFIG_EXPORTFS=m
2987CONFIG_NFS_ACL_SUPPORT=m
2988CONFIG_NFS_COMMON=y
2989CONFIG_SUNRPC=m
2990CONFIG_SUNRPC_GSS=m
2991CONFIG_SUNRPC_BIND34=y
2992CONFIG_RPCSEC_GSS_KRB5=m
2993CONFIG_RPCSEC_GSS_SPKM3=m
2994# CONFIG_SMB_FS is not set
2995CONFIG_CIFS=m
2996# CONFIG_CIFS_STATS is not set
2997CONFIG_CIFS_WEAK_PW_HASH=y
2998CONFIG_CIFS_XATTR=y
2999CONFIG_CIFS_POSIX=y
3000# CONFIG_CIFS_DEBUG2 is not set
3001CONFIG_CIFS_EXPERIMENTAL=y
3002CONFIG_CIFS_UPCALL=y
3003CONFIG_CIFS_DFS_UPCALL=y
3004CONFIG_NCP_FS=m
3005CONFIG_NCPFS_PACKET_SIGNING=y
3006CONFIG_NCPFS_IOCTL_LOCKING=y
3007CONFIG_NCPFS_STRONG=y
3008CONFIG_NCPFS_NFS_NS=y
3009CONFIG_NCPFS_OS2_NS=y
3010CONFIG_NCPFS_SMALLDOS=y
3011CONFIG_NCPFS_NLS=y
3012CONFIG_NCPFS_EXTRAS=y
3013CONFIG_CODA_FS=m
3014# CONFIG_CODA_FS_OLD_API is not set
3015# CONFIG_AFS_FS is not set
3016CONFIG_9P_FS=m
3017
3018#
3019# Partition Types
3020#
3021CONFIG_PARTITION_ADVANCED=y
3022# CONFIG_ACORN_PARTITION is not set
3023CONFIG_OSF_PARTITION=y
3024CONFIG_AMIGA_PARTITION=y
3025# CONFIG_ATARI_PARTITION is not set
3026CONFIG_MAC_PARTITION=y
3027CONFIG_MSDOS_PARTITION=y
3028CONFIG_BSD_DISKLABEL=y
3029CONFIG_MINIX_SUBPARTITION=y
3030CONFIG_SOLARIS_X86_PARTITION=y
3031CONFIG_UNIXWARE_DISKLABEL=y
3032# CONFIG_LDM_PARTITION is not set
3033CONFIG_SGI_PARTITION=y
3034# CONFIG_ULTRIX_PARTITION is not set
3035CONFIG_SUN_PARTITION=y
3036CONFIG_KARMA_PARTITION=y
3037CONFIG_EFI_PARTITION=y
3038# CONFIG_SYSV68_PARTITION is not set
3039CONFIG_NLS=y
3040CONFIG_NLS_DEFAULT="utf8"
3041CONFIG_NLS_CODEPAGE_437=y
3042CONFIG_NLS_CODEPAGE_737=m
3043CONFIG_NLS_CODEPAGE_775=m
3044CONFIG_NLS_CODEPAGE_850=m
3045CONFIG_NLS_CODEPAGE_852=m
3046CONFIG_NLS_CODEPAGE_855=m
3047CONFIG_NLS_CODEPAGE_857=m
3048CONFIG_NLS_CODEPAGE_860=m
3049CONFIG_NLS_CODEPAGE_861=m
3050CONFIG_NLS_CODEPAGE_862=m
3051CONFIG_NLS_CODEPAGE_863=m
3052CONFIG_NLS_CODEPAGE_864=m
3053CONFIG_NLS_CODEPAGE_865=m
3054CONFIG_NLS_CODEPAGE_866=m
3055CONFIG_NLS_CODEPAGE_869=m
3056CONFIG_NLS_CODEPAGE_936=m
3057CONFIG_NLS_CODEPAGE_950=m
3058CONFIG_NLS_CODEPAGE_932=m
3059CONFIG_NLS_CODEPAGE_949=m
3060CONFIG_NLS_CODEPAGE_874=m
3061CONFIG_NLS_ISO8859_8=m
3062CONFIG_NLS_CODEPAGE_1250=m
3063CONFIG_NLS_CODEPAGE_1251=m
3064CONFIG_NLS_ASCII=y
3065CONFIG_NLS_ISO8859_1=m
3066CONFIG_NLS_ISO8859_2=m
3067CONFIG_NLS_ISO8859_3=m
3068CONFIG_NLS_ISO8859_4=m
3069CONFIG_NLS_ISO8859_5=m
3070CONFIG_NLS_ISO8859_6=m
3071CONFIG_NLS_ISO8859_7=m
3072CONFIG_NLS_ISO8859_9=m
3073CONFIG_NLS_ISO8859_13=m
3074CONFIG_NLS_ISO8859_14=m
3075CONFIG_NLS_ISO8859_15=m
3076CONFIG_NLS_KOI8_R=m
3077CONFIG_NLS_KOI8_U=m
3078CONFIG_NLS_UTF8=m
3079CONFIG_DLM=m
3080CONFIG_DLM_DEBUG=y
3081CONFIG_QE_GPIO=y
3082
3083#
3084# Library routines
3085#
3086CONFIG_BITREVERSE=y
3087# CONFIG_GENERIC_FIND_FIRST_BIT is not set
3088CONFIG_CRC_CCITT=m
3089CONFIG_CRC16=m
3090CONFIG_CRC_T10DIF=m
3091CONFIG_CRC_ITU_T=m
3092CONFIG_CRC32=y
3093# CONFIG_CRC7 is not set
3094CONFIG_LIBCRC32C=m
3095CONFIG_ZLIB_INFLATE=y
3096CONFIG_ZLIB_DEFLATE=m
3097CONFIG_LZO_COMPRESS=m
3098CONFIG_LZO_DECOMPRESS=m
3099CONFIG_TEXTSEARCH=y
3100CONFIG_TEXTSEARCH_KMP=m
3101CONFIG_TEXTSEARCH_BM=m
3102CONFIG_TEXTSEARCH_FSM=m
3103CONFIG_PLIST=y
3104CONFIG_HAS_IOMEM=y
3105CONFIG_HAS_IOPORT=y
3106CONFIG_HAS_DMA=y
3107CONFIG_HAVE_LMB=y
3108
3109#
3110# Kernel hacking
3111#
3112# CONFIG_PRINTK_TIME is not set
3113# CONFIG_ENABLE_WARN_DEPRECATED is not set
3114CONFIG_ENABLE_MUST_CHECK=y
3115CONFIG_FRAME_WARN=1024
3116CONFIG_MAGIC_SYSRQ=y
3117CONFIG_UNUSED_SYMBOLS=y
3118CONFIG_DEBUG_FS=y
3119CONFIG_HEADERS_CHECK=y
3120CONFIG_DEBUG_KERNEL=y
3121CONFIG_DEBUG_SHIRQ=y
3122CONFIG_DETECT_SOFTLOCKUP=y
3123CONFIG_SCHED_DEBUG=y
3124CONFIG_SCHEDSTATS=y
3125CONFIG_TIMER_STATS=y
3126CONFIG_DEBUG_OBJECTS=y
3127# CONFIG_DEBUG_OBJECTS_SELFTEST is not set
3128CONFIG_DEBUG_OBJECTS_FREE=y
3129CONFIG_DEBUG_OBJECTS_TIMERS=y
3130CONFIG_SLUB_DEBUG_ON=y
3131# CONFIG_SLUB_STATS is not set
3132CONFIG_DEBUG_RT_MUTEXES=y
3133CONFIG_DEBUG_PI_LIST=y
3134# CONFIG_RT_MUTEX_TESTER is not set
3135CONFIG_DEBUG_SPINLOCK=y
3136CONFIG_DEBUG_MUTEXES=y
3137CONFIG_DEBUG_SPINLOCK_SLEEP=y
3138# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
3139CONFIG_STACKTRACE=y
3140# CONFIG_DEBUG_KOBJECT is not set
3141CONFIG_DEBUG_HIGHMEM=y
3142CONFIG_DEBUG_BUGVERBOSE=y
3143CONFIG_DEBUG_INFO=y
3144CONFIG_DEBUG_VM=y
3145CONFIG_DEBUG_WRITECOUNT=y
3146CONFIG_DEBUG_LIST=y
3147CONFIG_DEBUG_SG=y
3148CONFIG_FRAME_POINTER=y
3149CONFIG_BOOT_PRINTK_DELAY=y
3150# CONFIG_RCU_TORTURE_TEST is not set
3151# CONFIG_KPROBES_SANITY_TEST is not set
3152# CONFIG_BACKTRACE_SELF_TEST is not set
3153# CONFIG_LKDTM is not set
3154CONFIG_FAULT_INJECTION=y
3155CONFIG_FAILSLAB=y
3156CONFIG_FAIL_PAGE_ALLOC=y
3157CONFIG_FAIL_MAKE_REQUEST=y
3158CONFIG_FAULT_INJECTION_DEBUG_FS=y
3159CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y
3160CONFIG_LATENCYTOP=y
3161CONFIG_HAVE_FTRACE=y
3162CONFIG_HAVE_DYNAMIC_FTRACE=y
3163CONFIG_TRACER_MAX_TRACE=y
3164CONFIG_TRACING=y
3165CONFIG_FTRACE=y
3166CONFIG_SCHED_TRACER=y
3167CONFIG_CONTEXT_SWITCH_TRACER=y
3168CONFIG_DYNAMIC_FTRACE=y
3169# CONFIG_FTRACE_STARTUP_TEST is not set
3170# CONFIG_FIREWIRE_OHCI_REMOTE_DMA is not set
3171# CONFIG_SAMPLES is not set
3172CONFIG_DEBUG_STACKOVERFLOW=y
3173CONFIG_DEBUG_STACK_USAGE=y
3174CONFIG_DEBUGGER=y
3175# CONFIG_CODE_PATCHING_SELFTEST is not set
3176# CONFIG_FTR_FIXUP_SELFTEST is not set
3177# CONFIG_KGDB_CONSOLE is not set
3178CONFIG_XMON=y
3179# CONFIG_XMON_DEFAULT is not set
3180CONFIG_XMON_DISASSEMBLY=y
3181CONFIG_IRQSTACKS=y
3182# CONFIG_VIRQ_DEBUG is not set
3183# CONFIG_BDI_SWITCH is not set
3184CONFIG_BOOTX_TEXT=y
3185# CONFIG_PPC_EARLY_DEBUG is not set
3186
3187#
3188# Security options
3189#
3190CONFIG_KEYS=y
3191CONFIG_KEYS_DEBUG_PROC_KEYS=y
3192CONFIG_SECURITY=y
3193CONFIG_SECURITY_NETWORK=y
3194CONFIG_SECURITY_NETWORK_XFRM=y
3195CONFIG_SECURITY_FILE_CAPABILITIES=y
3196# CONFIG_SECURITY_ROOTPLUG is not set
3197CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR=65536
3198CONFIG_SECURITY_SELINUX=y
3199CONFIG_SECURITY_SELINUX_BOOTPARAM=y
3200CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=1
3201CONFIG_SECURITY_SELINUX_DISABLE=y
3202CONFIG_SECURITY_SELINUX_DEVELOP=y
3203CONFIG_SECURITY_SELINUX_AVC_STATS=y
3204CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE=1
3205CONFIG_SECURITY_SELINUX_ENABLE_SECMARK_DEFAULT=y
3206# CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX is not set
3207# CONFIG_SECURITY_SMACK is not set
3208CONFIG_XOR_BLOCKS=m
3209CONFIG_ASYNC_CORE=m
3210CONFIG_ASYNC_MEMCPY=m
3211CONFIG_ASYNC_XOR=m
3212CONFIG_CRYPTO=y
3213
3214#
3215# Crypto core or helper
3216#
3217CONFIG_CRYPTO_ALGAPI=y
3218CONFIG_CRYPTO_AEAD=m
3219CONFIG_CRYPTO_BLKCIPHER=m
3220CONFIG_CRYPTO_HASH=y
3221CONFIG_CRYPTO_MANAGER=y
3222CONFIG_CRYPTO_GF128MUL=m
3223CONFIG_CRYPTO_NULL=m
3224# CONFIG_CRYPTO_CRYPTD is not set
3225CONFIG_CRYPTO_AUTHENC=m
3226CONFIG_CRYPTO_TEST=m
3227
3228#
3229# Authenticated Encryption with Associated Data
3230#
3231CONFIG_CRYPTO_CCM=m
3232CONFIG_CRYPTO_GCM=m
3233CONFIG_CRYPTO_SEQIV=m
3234
3235#
3236# Block modes
3237#
3238CONFIG_CRYPTO_CBC=m
3239CONFIG_CRYPTO_CTR=m
3240CONFIG_CRYPTO_CTS=m
3241CONFIG_CRYPTO_ECB=m
3242CONFIG_CRYPTO_LRW=m
3243CONFIG_CRYPTO_PCBC=m
3244CONFIG_CRYPTO_XTS=m
3245
3246#
3247# Hash modes
3248#
3249CONFIG_CRYPTO_HMAC=y
3250CONFIG_CRYPTO_XCBC=m
3251
3252#
3253# Digest
3254#
3255CONFIG_CRYPTO_CRC32C=m
3256CONFIG_CRYPTO_MD4=m
3257CONFIG_CRYPTO_MD5=y
3258CONFIG_CRYPTO_MICHAEL_MIC=m
3259CONFIG_CRYPTO_RMD128=m
3260CONFIG_CRYPTO_RMD160=m
3261CONFIG_CRYPTO_RMD256=m
3262CONFIG_CRYPTO_RMD320=m
3263CONFIG_CRYPTO_SHA1=y
3264CONFIG_CRYPTO_SHA256=m
3265CONFIG_CRYPTO_SHA512=m
3266CONFIG_CRYPTO_TGR192=m
3267CONFIG_CRYPTO_WP512=m
3268
3269#
3270# Ciphers
3271#
3272CONFIG_CRYPTO_AES=m
3273CONFIG_CRYPTO_ANUBIS=m
3274CONFIG_CRYPTO_ARC4=m
3275CONFIG_CRYPTO_BLOWFISH=m
3276CONFIG_CRYPTO_CAMELLIA=m
3277CONFIG_CRYPTO_CAST5=m
3278CONFIG_CRYPTO_CAST6=m
3279CONFIG_CRYPTO_DES=m
3280CONFIG_CRYPTO_FCRYPT=m
3281CONFIG_CRYPTO_KHAZAD=m
3282CONFIG_CRYPTO_SALSA20=m
3283CONFIG_CRYPTO_SEED=m
3284CONFIG_CRYPTO_SERPENT=m
3285CONFIG_CRYPTO_TEA=m
3286CONFIG_CRYPTO_TWOFISH=m
3287CONFIG_CRYPTO_TWOFISH_COMMON=m
3288
3289#
3290# Compression
3291#
3292CONFIG_CRYPTO_DEFLATE=m
3293CONFIG_CRYPTO_LZO=m
3294CONFIG_CRYPTO_HW=y
3295CONFIG_CRYPTO_DEV_HIFN_795X=m
3296CONFIG_CRYPTO_DEV_HIFN_795X_RNG=y
3297CONFIG_CRYPTO_DEV_TALITOS=m
3298CONFIG_PPC_CLOCK=y
3299CONFIG_PPC_LIB_RHEAP=y
3300CONFIG_VIRTUALIZATION=y
3301CONFIG_VIRTIO=m
3302CONFIG_VIRTIO_RING=m
3303CONFIG_VIRTIO_PCI=m
3304CONFIG_VIRTIO_BALLOON=m
diff --git a/arch/powerpc/configs/ps3_defconfig b/arch/powerpc/configs/ps3_defconfig
index 71d79e428d20..f9a3d3b394cf 100644
--- a/arch/powerpc/configs/ps3_defconfig
+++ b/arch/powerpc/configs/ps3_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.25 3# Linux kernel version: 2.6.26
4# Mon Apr 28 12:39:10 2008 4# Wed Jul 16 13:59:24 2008
5# 5#
6CONFIG_PPC64=y 6CONFIG_PPC64=y
7 7
@@ -14,8 +14,9 @@ CONFIG_POWER4=y
14CONFIG_TUNE_CELL=y 14CONFIG_TUNE_CELL=y
15CONFIG_PPC_FPU=y 15CONFIG_PPC_FPU=y
16CONFIG_ALTIVEC=y 16CONFIG_ALTIVEC=y
17# CONFIG_VSX is not set
17CONFIG_PPC_STD_MMU=y 18CONFIG_PPC_STD_MMU=y
18# CONFIG_PPC_MM_SLICES is not set 19CONFIG_PPC_MM_SLICES=y
19CONFIG_VIRT_CPU_ACCOUNTING=y 20CONFIG_VIRT_CPU_ACCOUNTING=y
20CONFIG_SMP=y 21CONFIG_SMP=y
21CONFIG_NR_CPUS=2 22CONFIG_NR_CPUS=2
@@ -31,6 +32,7 @@ CONFIG_GENERIC_HARDIRQS=y
31CONFIG_HAVE_SETUP_PER_CPU_AREA=y 32CONFIG_HAVE_SETUP_PER_CPU_AREA=y
32CONFIG_IRQ_PER_CPU=y 33CONFIG_IRQ_PER_CPU=y
33CONFIG_STACKTRACE_SUPPORT=y 34CONFIG_STACKTRACE_SUPPORT=y
35CONFIG_HAVE_LATENCYTOP_SUPPORT=y
34CONFIG_TRACE_IRQFLAGS_SUPPORT=y 36CONFIG_TRACE_IRQFLAGS_SUPPORT=y
35CONFIG_LOCKDEP_SUPPORT=y 37CONFIG_LOCKDEP_SUPPORT=y
36CONFIG_RWSEM_XCHGADD_ALGORITHM=y 38CONFIG_RWSEM_XCHGADD_ALGORITHM=y
@@ -90,6 +92,7 @@ CONFIG_CC_OPTIMIZE_FOR_SIZE=y
90CONFIG_SYSCTL=y 92CONFIG_SYSCTL=y
91# CONFIG_EMBEDDED is not set 93# CONFIG_EMBEDDED is not set
92CONFIG_SYSCTL_SYSCALL=y 94CONFIG_SYSCTL_SYSCALL=y
95CONFIG_SYSCTL_SYSCALL_CHECK=y
93CONFIG_KALLSYMS=y 96CONFIG_KALLSYMS=y
94CONFIG_KALLSYMS_ALL=y 97CONFIG_KALLSYMS_ALL=y
95CONFIG_KALLSYMS_EXTRA_PASS=y 98CONFIG_KALLSYMS_EXTRA_PASS=y
@@ -117,12 +120,15 @@ CONFIG_HAVE_OPROFILE=y
117# CONFIG_KPROBES is not set 120# CONFIG_KPROBES is not set
118CONFIG_HAVE_KPROBES=y 121CONFIG_HAVE_KPROBES=y
119CONFIG_HAVE_KRETPROBES=y 122CONFIG_HAVE_KRETPROBES=y
123CONFIG_HAVE_DMA_ATTRS=y
124CONFIG_USE_GENERIC_SMP_HELPERS=y
120CONFIG_PROC_PAGE_MONITOR=y 125CONFIG_PROC_PAGE_MONITOR=y
121CONFIG_SLABINFO=y 126CONFIG_SLABINFO=y
122CONFIG_RT_MUTEXES=y 127CONFIG_RT_MUTEXES=y
123# CONFIG_TINY_SHMEM is not set 128# CONFIG_TINY_SHMEM is not set
124CONFIG_BASE_SMALL=0 129CONFIG_BASE_SMALL=0
125CONFIG_MODULES=y 130CONFIG_MODULES=y
131# CONFIG_MODULE_FORCE_LOAD is not set
126CONFIG_MODULE_UNLOAD=y 132CONFIG_MODULE_UNLOAD=y
127# CONFIG_MODULE_FORCE_UNLOAD is not set 133# CONFIG_MODULE_FORCE_UNLOAD is not set
128# CONFIG_MODVERSIONS is not set 134# CONFIG_MODVERSIONS is not set
@@ -132,6 +138,7 @@ CONFIG_STOP_MACHINE=y
132CONFIG_BLOCK=y 138CONFIG_BLOCK=y
133# CONFIG_BLK_DEV_IO_TRACE is not set 139# CONFIG_BLK_DEV_IO_TRACE is not set
134CONFIG_BLK_DEV_BSG=y 140CONFIG_BLK_DEV_BSG=y
141# CONFIG_BLK_DEV_INTEGRITY is not set
135CONFIG_BLOCK_COMPAT=y 142CONFIG_BLOCK_COMPAT=y
136 143
137# 144#
@@ -152,13 +159,8 @@ CONFIG_CLASSIC_RCU=y
152# Platform support 159# Platform support
153# 160#
154CONFIG_PPC_MULTIPLATFORM=y 161CONFIG_PPC_MULTIPLATFORM=y
155# CONFIG_PPC_82xx is not set
156# CONFIG_PPC_83xx is not set
157# CONFIG_PPC_86xx is not set
158# CONFIG_PPC_PSERIES is not set 162# CONFIG_PPC_PSERIES is not set
159# CONFIG_PPC_ISERIES is not set 163# CONFIG_PPC_ISERIES is not set
160# CONFIG_PPC_MPC512x is not set
161# CONFIG_PPC_MPC5121 is not set
162# CONFIG_PPC_PMAC is not set 164# CONFIG_PPC_PMAC is not set
163# CONFIG_PPC_MAPLE is not set 165# CONFIG_PPC_MAPLE is not set
164# CONFIG_PPC_PASEMI is not set 166# CONFIG_PPC_PASEMI is not set
@@ -187,6 +189,7 @@ CONFIG_PPC_CELL=y
187# Cell Broadband Engine options 189# Cell Broadband Engine options
188# 190#
189CONFIG_SPU_FS=y 191CONFIG_SPU_FS=y
192CONFIG_SPU_FS_64K_LS=y
190CONFIG_SPU_BASE=y 193CONFIG_SPU_BASE=y
191# CONFIG_PQ2ADS is not set 194# CONFIG_PQ2ADS is not set
192# CONFIG_IPIC is not set 195# CONFIG_IPIC is not set
@@ -222,6 +225,7 @@ CONFIG_PREEMPT_NONE=y
222CONFIG_BINFMT_ELF=y 225CONFIG_BINFMT_ELF=y
223CONFIG_COMPAT_BINFMT_ELF=y 226CONFIG_COMPAT_BINFMT_ELF=y
224CONFIG_BINFMT_MISC=y 227CONFIG_BINFMT_MISC=y
228CONFIG_HUGETLB_PAGE_SIZE_VARIABLE=y
225# CONFIG_IOMMU_VMERGE is not set 229# CONFIG_IOMMU_VMERGE is not set
226CONFIG_IOMMU_HELPER=y 230CONFIG_IOMMU_HELPER=y
227CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y 231CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
@@ -248,18 +252,22 @@ CONFIG_SPARSEMEM_VMEMMAP_ENABLE=y
248# CONFIG_SPARSEMEM_VMEMMAP is not set 252# CONFIG_SPARSEMEM_VMEMMAP is not set
249CONFIG_MEMORY_HOTPLUG=y 253CONFIG_MEMORY_HOTPLUG=y
250CONFIG_MEMORY_HOTPLUG_SPARSE=y 254CONFIG_MEMORY_HOTPLUG_SPARSE=y
255CONFIG_PAGEFLAGS_EXTENDED=y
251CONFIG_SPLIT_PTLOCK_CPUS=4 256CONFIG_SPLIT_PTLOCK_CPUS=4
252CONFIG_RESOURCES_64BIT=y 257CONFIG_RESOURCES_64BIT=y
253CONFIG_ZONE_DMA_FLAG=1 258CONFIG_ZONE_DMA_FLAG=1
254CONFIG_BOUNCE=y 259CONFIG_BOUNCE=y
255CONFIG_ARCH_MEMORY_PROBE=y 260CONFIG_ARCH_MEMORY_PROBE=y
256# CONFIG_PPC_HAS_HASH_64K is not set 261CONFIG_PPC_HAS_HASH_64K=y
257# CONFIG_PPC_64K_PAGES is not set 262# CONFIG_PPC_64K_PAGES is not set
258CONFIG_FORCE_MAX_ZONEORDER=13 263CONFIG_FORCE_MAX_ZONEORDER=13
259# CONFIG_SCHED_SMT is not set 264CONFIG_SCHED_SMT=y
260CONFIG_PROC_DEVICETREE=y 265CONFIG_PROC_DEVICETREE=y
261# CONFIG_CMDLINE_BOOL is not set 266# CONFIG_CMDLINE_BOOL is not set
262# CONFIG_PM is not set 267CONFIG_EXTRA_TARGETS=""
268CONFIG_PM=y
269CONFIG_PM_DEBUG=y
270# CONFIG_PM_VERBOSE is not set
263# CONFIG_SECCOMP is not set 271# CONFIG_SECCOMP is not set
264CONFIG_ISA_DMA_API=y 272CONFIG_ISA_DMA_API=y
265 273
@@ -273,6 +281,7 @@ CONFIG_GENERIC_ISA_DMA=y
273# CONFIG_PCI_SYSCALL is not set 281# CONFIG_PCI_SYSCALL is not set
274# CONFIG_ARCH_SUPPORTS_MSI is not set 282# CONFIG_ARCH_SUPPORTS_MSI is not set
275# CONFIG_PCCARD is not set 283# CONFIG_PCCARD is not set
284# CONFIG_HAS_RAPIDIO is not set
276CONFIG_PAGE_OFFSET=0xc000000000000000 285CONFIG_PAGE_OFFSET=0xc000000000000000
277CONFIG_KERNEL_START=0xc000000000000000 286CONFIG_KERNEL_START=0xc000000000000000
278CONFIG_PHYSICAL_START=0x00000000 287CONFIG_PHYSICAL_START=0x00000000
@@ -412,6 +421,8 @@ CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
412CONFIG_STANDALONE=y 421CONFIG_STANDALONE=y
413CONFIG_PREVENT_FIRMWARE_BUILD=y 422CONFIG_PREVENT_FIRMWARE_BUILD=y
414CONFIG_FW_LOADER=m 423CONFIG_FW_LOADER=m
424# CONFIG_FIRMWARE_IN_KERNEL is not set
425CONFIG_EXTRA_FIRMWARE=""
415# CONFIG_DEBUG_DRIVER is not set 426# CONFIG_DEBUG_DRIVER is not set
416# CONFIG_DEBUG_DEVRES is not set 427# CONFIG_DEBUG_DEVRES is not set
417# CONFIG_SYS_HYPERVISOR is not set 428# CONFIG_SYS_HYPERVISOR is not set
@@ -478,6 +489,7 @@ CONFIG_SCSI_WAIT_SCAN=m
478# CONFIG_SCSI_SAS_LIBSAS is not set 489# CONFIG_SCSI_SAS_LIBSAS is not set
479# CONFIG_SCSI_SRP_ATTRS is not set 490# CONFIG_SCSI_SRP_ATTRS is not set
480# CONFIG_SCSI_LOWLEVEL is not set 491# CONFIG_SCSI_LOWLEVEL is not set
492# CONFIG_SCSI_DH is not set
481# CONFIG_ATA is not set 493# CONFIG_ATA is not set
482# CONFIG_MD is not set 494# CONFIG_MD is not set
483# CONFIG_MACINTOSH_DRIVERS is not set 495# CONFIG_MACINTOSH_DRIVERS is not set
@@ -533,8 +545,18 @@ CONFIG_USB_NET_MCS7830=m
533# CONFIG_USB_NET_CDC_SUBSET is not set 545# CONFIG_USB_NET_CDC_SUBSET is not set
534# CONFIG_USB_NET_ZAURUS is not set 546# CONFIG_USB_NET_ZAURUS is not set
535# CONFIG_WAN is not set 547# CONFIG_WAN is not set
536# CONFIG_PPP is not set 548CONFIG_PPP=m
549CONFIG_PPP_MULTILINK=y
550# CONFIG_PPP_FILTER is not set
551CONFIG_PPP_ASYNC=m
552# CONFIG_PPP_SYNC_TTY is not set
553CONFIG_PPP_DEFLATE=m
554# CONFIG_PPP_BSDCOMP is not set
555# CONFIG_PPP_MPPE is not set
556CONFIG_PPPOE=m
557# CONFIG_PPPOL2TP is not set
537# CONFIG_SLIP is not set 558# CONFIG_SLIP is not set
559CONFIG_SLHC=m
538# CONFIG_NETCONSOLE is not set 560# CONFIG_NETCONSOLE is not set
539# CONFIG_NETPOLL is not set 561# CONFIG_NETPOLL is not set
540# CONFIG_NET_POLL_CONTROLLER is not set 562# CONFIG_NET_POLL_CONTROLLER is not set
@@ -603,6 +625,7 @@ CONFIG_VT=y
603CONFIG_VT_CONSOLE=y 625CONFIG_VT_CONSOLE=y
604CONFIG_HW_CONSOLE=y 626CONFIG_HW_CONSOLE=y
605CONFIG_VT_HW_CONSOLE_BINDING=y 627CONFIG_VT_HW_CONSOLE_BINDING=y
628CONFIG_DEVKMEM=y
606# CONFIG_SERIAL_NONSTANDARD is not set 629# CONFIG_SERIAL_NONSTANDARD is not set
607 630
608# 631#
@@ -618,23 +641,17 @@ CONFIG_LEGACY_PTYS=y
618CONFIG_LEGACY_PTY_COUNT=16 641CONFIG_LEGACY_PTY_COUNT=16
619# CONFIG_IPMI_HANDLER is not set 642# CONFIG_IPMI_HANDLER is not set
620# CONFIG_HW_RANDOM is not set 643# CONFIG_HW_RANDOM is not set
621CONFIG_GEN_RTC=y
622# CONFIG_GEN_RTC_X is not set
623# CONFIG_R3964 is not set 644# CONFIG_R3964 is not set
624# CONFIG_RAW_DRIVER is not set 645# CONFIG_RAW_DRIVER is not set
625# CONFIG_HANGCHECK_TIMER is not set 646# CONFIG_HANGCHECK_TIMER is not set
626# CONFIG_TCG_TPM is not set 647# CONFIG_TCG_TPM is not set
627# CONFIG_I2C is not set 648# CONFIG_I2C is not set
628
629#
630# SPI support
631#
632# CONFIG_SPI is not set 649# CONFIG_SPI is not set
633# CONFIG_SPI_MASTER is not set
634# CONFIG_W1 is not set 650# CONFIG_W1 is not set
635# CONFIG_POWER_SUPPLY is not set 651# CONFIG_POWER_SUPPLY is not set
636# CONFIG_HWMON is not set 652# CONFIG_HWMON is not set
637# CONFIG_THERMAL is not set 653# CONFIG_THERMAL is not set
654# CONFIG_THERMAL_HWMON is not set
638# CONFIG_WATCHDOG is not set 655# CONFIG_WATCHDOG is not set
639 656
640# 657#
@@ -652,8 +669,17 @@ CONFIG_SSB_POSSIBLE=y
652# 669#
653# Multimedia devices 670# Multimedia devices
654# 671#
672
673#
674# Multimedia core support
675#
655# CONFIG_VIDEO_DEV is not set 676# CONFIG_VIDEO_DEV is not set
656# CONFIG_DVB_CORE is not set 677# CONFIG_DVB_CORE is not set
678# CONFIG_VIDEO_MEDIA is not set
679
680#
681# Multimedia drivers
682#
657# CONFIG_DAB is not set 683# CONFIG_DAB is not set
658 684
659# 685#
@@ -671,8 +697,8 @@ CONFIG_FB=y
671CONFIG_FB_SYS_FILLRECT=y 697CONFIG_FB_SYS_FILLRECT=y
672CONFIG_FB_SYS_COPYAREA=y 698CONFIG_FB_SYS_COPYAREA=y
673CONFIG_FB_SYS_IMAGEBLIT=y 699CONFIG_FB_SYS_IMAGEBLIT=y
700# CONFIG_FB_FOREIGN_ENDIAN is not set
674CONFIG_FB_SYS_FOPS=y 701CONFIG_FB_SYS_FOPS=y
675CONFIG_FB_DEFERRED_IO=y
676# CONFIG_FB_SVGALIB is not set 702# CONFIG_FB_SVGALIB is not set
677# CONFIG_FB_MACMODES is not set 703# CONFIG_FB_MACMODES is not set
678# CONFIG_FB_BACKLIGHT is not set 704# CONFIG_FB_BACKLIGHT is not set
@@ -712,18 +738,12 @@ CONFIG_FB_LOGO_EXTRA=y
712# CONFIG_LOGO_LINUX_MONO is not set 738# CONFIG_LOGO_LINUX_MONO is not set
713# CONFIG_LOGO_LINUX_VGA16 is not set 739# CONFIG_LOGO_LINUX_VGA16 is not set
714CONFIG_LOGO_LINUX_CLUT224=y 740CONFIG_LOGO_LINUX_CLUT224=y
715
716#
717# Sound
718#
719CONFIG_SOUND=m 741CONFIG_SOUND=m
720
721#
722# Advanced Linux Sound Architecture
723#
724CONFIG_SND=m 742CONFIG_SND=m
725CONFIG_SND_TIMER=m 743CONFIG_SND_TIMER=m
726CONFIG_SND_PCM=m 744CONFIG_SND_PCM=m
745CONFIG_SND_HWDEP=m
746CONFIG_SND_RAWMIDI=m
727# CONFIG_SND_SEQUENCER is not set 747# CONFIG_SND_SEQUENCER is not set
728# CONFIG_SND_MIXER_OSS is not set 748# CONFIG_SND_MIXER_OSS is not set
729# CONFIG_SND_PCM_OSS is not set 749# CONFIG_SND_PCM_OSS is not set
@@ -732,53 +752,20 @@ CONFIG_SND_SUPPORT_OLD_API=y
732CONFIG_SND_VERBOSE_PROCFS=y 752CONFIG_SND_VERBOSE_PROCFS=y
733# CONFIG_SND_VERBOSE_PRINTK is not set 753# CONFIG_SND_VERBOSE_PRINTK is not set
734# CONFIG_SND_DEBUG is not set 754# CONFIG_SND_DEBUG is not set
735 755# CONFIG_SND_DRIVERS is not set
736# 756CONFIG_SND_PPC=y
737# Generic devices
738#
739# CONFIG_SND_DUMMY is not set
740# CONFIG_SND_MTPAV is not set
741# CONFIG_SND_SERIAL_U16550 is not set
742# CONFIG_SND_MPU401 is not set
743
744#
745# ALSA PowerMac devices
746#
747
748#
749# ALSA PowerMac requires I2C
750#
751
752#
753# ALSA PowerPC devices
754#
755CONFIG_SND_PS3=m 757CONFIG_SND_PS3=m
756CONFIG_SND_PS3_DEFAULT_START_DELAY=2000 758CONFIG_SND_PS3_DEFAULT_START_DELAY=2000
757 759CONFIG_SND_USB=y
758# 760CONFIG_SND_USB_AUDIO=m
759# USB devices
760#
761# CONFIG_SND_USB_AUDIO is not set
762# CONFIG_SND_USB_USX2Y is not set 761# CONFIG_SND_USB_USX2Y is not set
763# CONFIG_SND_USB_CAIAQ is not set 762# CONFIG_SND_USB_CAIAQ is not set
764
765#
766# System on Chip audio support
767#
768# CONFIG_SND_SOC is not set 763# CONFIG_SND_SOC is not set
769
770#
771# ALSA SoC audio for Freescale SOCs
772#
773
774#
775# Open Sound System
776#
777# CONFIG_SOUND_PRIME is not set 764# CONFIG_SOUND_PRIME is not set
778CONFIG_HID_SUPPORT=y 765CONFIG_HID_SUPPORT=y
779CONFIG_HID=y 766CONFIG_HID=y
780# CONFIG_HID_DEBUG is not set 767# CONFIG_HID_DEBUG is not set
781# CONFIG_HIDRAW is not set 768CONFIG_HIDRAW=y
782 769
783# 770#
784# USB Input Devices 771# USB Input Devices
@@ -807,17 +794,20 @@ CONFIG_USB=m
807CONFIG_USB_DEVICEFS=y 794CONFIG_USB_DEVICEFS=y
808# CONFIG_USB_DEVICE_CLASS is not set 795# CONFIG_USB_DEVICE_CLASS is not set
809# CONFIG_USB_DYNAMIC_MINORS is not set 796# CONFIG_USB_DYNAMIC_MINORS is not set
797CONFIG_USB_SUSPEND=y
810# CONFIG_USB_OTG is not set 798# CONFIG_USB_OTG is not set
811 799
812# 800#
813# USB Host Controller Drivers 801# USB Host Controller Drivers
814# 802#
803# CONFIG_USB_C67X00_HCD is not set
815CONFIG_USB_EHCI_HCD=m 804CONFIG_USB_EHCI_HCD=m
816# CONFIG_USB_EHCI_ROOT_HUB_TT is not set 805# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
817# CONFIG_USB_EHCI_TT_NEWSCHED is not set 806# CONFIG_USB_EHCI_TT_NEWSCHED is not set
818CONFIG_USB_EHCI_BIG_ENDIAN_MMIO=y 807CONFIG_USB_EHCI_BIG_ENDIAN_MMIO=y
819# CONFIG_USB_EHCI_HCD_PPC_OF is not set 808# CONFIG_USB_EHCI_HCD_PPC_OF is not set
820# CONFIG_USB_ISP116X_HCD is not set 809# CONFIG_USB_ISP116X_HCD is not set
810# CONFIG_USB_ISP1760_HCD is not set
821CONFIG_USB_OHCI_HCD=m 811CONFIG_USB_OHCI_HCD=m
822# CONFIG_USB_OHCI_HCD_PPC_OF is not set 812# CONFIG_USB_OHCI_HCD_PPC_OF is not set
823# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set 813# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
@@ -831,6 +821,7 @@ CONFIG_USB_OHCI_LITTLE_ENDIAN=y
831# 821#
832# CONFIG_USB_ACM is not set 822# CONFIG_USB_ACM is not set
833# CONFIG_USB_PRINTER is not set 823# CONFIG_USB_PRINTER is not set
824# CONFIG_USB_WDM is not set
834 825
835# 826#
836# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' 827# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
@@ -890,12 +881,45 @@ CONFIG_USB_MON=y
890# CONFIG_USB_TRANCEVIBRATOR is not set 881# CONFIG_USB_TRANCEVIBRATOR is not set
891# CONFIG_USB_IOWARRIOR is not set 882# CONFIG_USB_IOWARRIOR is not set
892# CONFIG_USB_TEST is not set 883# CONFIG_USB_TEST is not set
884# CONFIG_USB_ISIGHTFW is not set
893# CONFIG_USB_GADGET is not set 885# CONFIG_USB_GADGET is not set
894# CONFIG_MMC is not set 886# CONFIG_MMC is not set
895# CONFIG_MEMSTICK is not set 887# CONFIG_MEMSTICK is not set
896# CONFIG_NEW_LEDS is not set 888# CONFIG_NEW_LEDS is not set
889# CONFIG_ACCESSIBILITY is not set
897# CONFIG_EDAC is not set 890# CONFIG_EDAC is not set
898# CONFIG_RTC_CLASS is not set 891CONFIG_RTC_LIB=m
892CONFIG_RTC_CLASS=m
893
894#
895# RTC interfaces
896#
897CONFIG_RTC_INTF_SYSFS=y
898CONFIG_RTC_INTF_PROC=y
899CONFIG_RTC_INTF_DEV=y
900# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
901# CONFIG_RTC_DRV_TEST is not set
902
903#
904# SPI RTC drivers
905#
906
907#
908# Platform RTC drivers
909#
910# CONFIG_RTC_DRV_CMOS is not set
911# CONFIG_RTC_DRV_DS1511 is not set
912# CONFIG_RTC_DRV_DS1553 is not set
913# CONFIG_RTC_DRV_DS1742 is not set
914# CONFIG_RTC_DRV_STK17TA8 is not set
915# CONFIG_RTC_DRV_M48T86 is not set
916# CONFIG_RTC_DRV_M48T59 is not set
917# CONFIG_RTC_DRV_V3020 is not set
918
919#
920# on-CPU RTC drivers
921#
922CONFIG_RTC_DRV_PPC=m
899# CONFIG_DMADEVICES is not set 923# CONFIG_DMADEVICES is not set
900# CONFIG_UIO is not set 924# CONFIG_UIO is not set
901 925
@@ -911,6 +935,7 @@ CONFIG_EXT3_FS_XATTR=y
911# CONFIG_EXT3_FS_SECURITY is not set 935# CONFIG_EXT3_FS_SECURITY is not set
912# CONFIG_EXT4DEV_FS is not set 936# CONFIG_EXT4DEV_FS is not set
913CONFIG_JBD=y 937CONFIG_JBD=y
938# CONFIG_JBD_DEBUG is not set
914CONFIG_FS_MBCACHE=y 939CONFIG_FS_MBCACHE=y
915# CONFIG_REISERFS_FS is not set 940# CONFIG_REISERFS_FS is not set
916# CONFIG_JFS_FS is not set 941# CONFIG_JFS_FS is not set
@@ -959,8 +984,8 @@ CONFIG_PROC_SYSCTL=y
959CONFIG_SYSFS=y 984CONFIG_SYSFS=y
960CONFIG_TMPFS=y 985CONFIG_TMPFS=y
961# CONFIG_TMPFS_POSIX_ACL is not set 986# CONFIG_TMPFS_POSIX_ACL is not set
962# CONFIG_HUGETLBFS is not set 987CONFIG_HUGETLBFS=y
963# CONFIG_HUGETLB_PAGE is not set 988CONFIG_HUGETLB_PAGE=y
964# CONFIG_CONFIGFS_FS is not set 989# CONFIG_CONFIGFS_FS is not set
965 990
966# 991#
@@ -1059,12 +1084,15 @@ CONFIG_NLS_ISO8859_1=y
1059# 1084#
1060CONFIG_BITREVERSE=y 1085CONFIG_BITREVERSE=y
1061# CONFIG_GENERIC_FIND_FIRST_BIT is not set 1086# CONFIG_GENERIC_FIND_FIRST_BIT is not set
1062# CONFIG_CRC_CCITT is not set 1087CONFIG_CRC_CCITT=m
1063# CONFIG_CRC16 is not set 1088# CONFIG_CRC16 is not set
1089# CONFIG_CRC_T10DIF is not set
1064CONFIG_CRC_ITU_T=m 1090CONFIG_CRC_ITU_T=m
1065CONFIG_CRC32=y 1091CONFIG_CRC32=y
1066# CONFIG_CRC7 is not set 1092# CONFIG_CRC7 is not set
1067# CONFIG_LIBCRC32C is not set 1093# CONFIG_LIBCRC32C is not set
1094CONFIG_ZLIB_INFLATE=m
1095CONFIG_ZLIB_DEFLATE=m
1068CONFIG_LZO_COMPRESS=m 1096CONFIG_LZO_COMPRESS=m
1069CONFIG_LZO_DECOMPRESS=m 1097CONFIG_LZO_DECOMPRESS=m
1070CONFIG_PLIST=y 1098CONFIG_PLIST=y
@@ -1082,7 +1110,7 @@ CONFIG_ENABLE_MUST_CHECK=y
1082CONFIG_FRAME_WARN=2048 1110CONFIG_FRAME_WARN=2048
1083CONFIG_MAGIC_SYSRQ=y 1111CONFIG_MAGIC_SYSRQ=y
1084# CONFIG_UNUSED_SYMBOLS is not set 1112# CONFIG_UNUSED_SYMBOLS is not set
1085# CONFIG_DEBUG_FS is not set 1113CONFIG_DEBUG_FS=y
1086# CONFIG_HEADERS_CHECK is not set 1114# CONFIG_HEADERS_CHECK is not set
1087CONFIG_DEBUG_KERNEL=y 1115CONFIG_DEBUG_KERNEL=y
1088# CONFIG_DEBUG_SHIRQ is not set 1116# CONFIG_DEBUG_SHIRQ is not set
@@ -1090,33 +1118,49 @@ CONFIG_DETECT_SOFTLOCKUP=y
1090CONFIG_SCHED_DEBUG=y 1118CONFIG_SCHED_DEBUG=y
1091# CONFIG_SCHEDSTATS is not set 1119# CONFIG_SCHEDSTATS is not set
1092# CONFIG_TIMER_STATS is not set 1120# CONFIG_TIMER_STATS is not set
1121# CONFIG_DEBUG_OBJECTS is not set
1093# CONFIG_DEBUG_SLAB is not set 1122# CONFIG_DEBUG_SLAB is not set
1094# CONFIG_DEBUG_RT_MUTEXES is not set 1123# CONFIG_DEBUG_RT_MUTEXES is not set
1095# CONFIG_RT_MUTEX_TESTER is not set 1124# CONFIG_RT_MUTEX_TESTER is not set
1096CONFIG_DEBUG_SPINLOCK=y 1125CONFIG_DEBUG_SPINLOCK=y
1097CONFIG_DEBUG_MUTEXES=y 1126CONFIG_DEBUG_MUTEXES=y
1098# CONFIG_DEBUG_LOCK_ALLOC is not set 1127CONFIG_DEBUG_LOCK_ALLOC=y
1099# CONFIG_PROVE_LOCKING is not set 1128CONFIG_PROVE_LOCKING=y
1129CONFIG_LOCKDEP=y
1100# CONFIG_LOCK_STAT is not set 1130# CONFIG_LOCK_STAT is not set
1131CONFIG_DEBUG_LOCKDEP=y
1132CONFIG_TRACE_IRQFLAGS=y
1101CONFIG_DEBUG_SPINLOCK_SLEEP=y 1133CONFIG_DEBUG_SPINLOCK_SLEEP=y
1102# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set 1134# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1135CONFIG_STACKTRACE=y
1103# CONFIG_DEBUG_KOBJECT is not set 1136# CONFIG_DEBUG_KOBJECT is not set
1104CONFIG_DEBUG_BUGVERBOSE=y 1137CONFIG_DEBUG_BUGVERBOSE=y
1105CONFIG_DEBUG_INFO=y 1138CONFIG_DEBUG_INFO=y
1106# CONFIG_DEBUG_VM is not set 1139# CONFIG_DEBUG_VM is not set
1107# CONFIG_DEBUG_WRITECOUNT is not set 1140CONFIG_DEBUG_WRITECOUNT=y
1108CONFIG_DEBUG_LIST=y 1141CONFIG_DEBUG_LIST=y
1109# CONFIG_DEBUG_SG is not set 1142# CONFIG_DEBUG_SG is not set
1143CONFIG_FRAME_POINTER=y
1110# CONFIG_BOOT_PRINTK_DELAY is not set 1144# CONFIG_BOOT_PRINTK_DELAY is not set
1111# CONFIG_RCU_TORTURE_TEST is not set 1145# CONFIG_RCU_TORTURE_TEST is not set
1112# CONFIG_BACKTRACE_SELF_TEST is not set 1146# CONFIG_BACKTRACE_SELF_TEST is not set
1113# CONFIG_FAULT_INJECTION is not set 1147# CONFIG_FAULT_INJECTION is not set
1148# CONFIG_LATENCYTOP is not set
1149CONFIG_HAVE_FTRACE=y
1150CONFIG_HAVE_DYNAMIC_FTRACE=y
1151# CONFIG_FTRACE is not set
1152# CONFIG_IRQSOFF_TRACER is not set
1153# CONFIG_SCHED_TRACER is not set
1154# CONFIG_CONTEXT_SWITCH_TRACER is not set
1114# CONFIG_SAMPLES is not set 1155# CONFIG_SAMPLES is not set
1115CONFIG_DEBUG_STACKOVERFLOW=y 1156CONFIG_DEBUG_STACKOVERFLOW=y
1116# CONFIG_DEBUG_STACK_USAGE is not set 1157# CONFIG_DEBUG_STACK_USAGE is not set
1117# CONFIG_DEBUG_PAGEALLOC is not set 1158# CONFIG_DEBUG_PAGEALLOC is not set
1118# CONFIG_DEBUGGER is not set 1159# CONFIG_DEBUGGER is not set
1160# CONFIG_CODE_PATCHING_SELFTEST is not set
1161# CONFIG_FTR_FIXUP_SELFTEST is not set
1119CONFIG_IRQSTACKS=y 1162CONFIG_IRQSTACKS=y
1163# CONFIG_VIRQ_DEBUG is not set
1120# CONFIG_BOOTX_TEXT is not set 1164# CONFIG_BOOTX_TEXT is not set
1121# CONFIG_PPC_EARLY_DEBUG is not set 1165# CONFIG_PPC_EARLY_DEBUG is not set
1122 1166
@@ -1172,6 +1216,10 @@ CONFIG_CRYPTO_PCBC=m
1172# CONFIG_CRYPTO_MD4 is not set 1216# CONFIG_CRYPTO_MD4 is not set
1173CONFIG_CRYPTO_MD5=y 1217CONFIG_CRYPTO_MD5=y
1174CONFIG_CRYPTO_MICHAEL_MIC=m 1218CONFIG_CRYPTO_MICHAEL_MIC=m
1219# CONFIG_CRYPTO_RMD128 is not set
1220# CONFIG_CRYPTO_RMD160 is not set
1221# CONFIG_CRYPTO_RMD256 is not set
1222# CONFIG_CRYPTO_RMD320 is not set
1175# CONFIG_CRYPTO_SHA1 is not set 1223# CONFIG_CRYPTO_SHA1 is not set
1176# CONFIG_CRYPTO_SHA256 is not set 1224# CONFIG_CRYPTO_SHA256 is not set
1177# CONFIG_CRYPTO_SHA512 is not set 1225# CONFIG_CRYPTO_SHA512 is not set
diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index f7f3c215d06f..b936a1dd0a50 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -355,6 +355,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
355 .icache_bsize = 128, 355 .icache_bsize = 128,
356 .dcache_bsize = 128, 356 .dcache_bsize = 128,
357 .machine_check = machine_check_generic, 357 .machine_check = machine_check_generic,
358 .oprofile_cpu_type = "ppc64/compat-power5+",
358 .platform = "power5+", 359 .platform = "power5+",
359 }, 360 },
360 { /* Power6 */ 361 { /* Power6 */
@@ -386,6 +387,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
386 .icache_bsize = 128, 387 .icache_bsize = 128,
387 .dcache_bsize = 128, 388 .dcache_bsize = 128,
388 .machine_check = machine_check_generic, 389 .machine_check = machine_check_generic,
390 .oprofile_cpu_type = "ppc64/compat-power6",
389 .platform = "power6", 391 .platform = "power6",
390 }, 392 },
391 { /* 2.06-compliant processor, i.e. Power7 "architected" mode */ 393 { /* 2.06-compliant processor, i.e. Power7 "architected" mode */
@@ -397,6 +399,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
397 .icache_bsize = 128, 399 .icache_bsize = 128,
398 .dcache_bsize = 128, 400 .dcache_bsize = 128,
399 .machine_check = machine_check_generic, 401 .machine_check = machine_check_generic,
402 .oprofile_cpu_type = "ppc64/compat-power7",
400 .platform = "power7", 403 .platform = "power7",
401 }, 404 },
402 { /* Power7 */ 405 { /* Power7 */
@@ -1629,6 +1632,23 @@ struct cpu_spec * __init identify_cpu(unsigned long offset, unsigned int pvr)
1629 t->cpu_setup = s->cpu_setup; 1632 t->cpu_setup = s->cpu_setup;
1630 t->cpu_restore = s->cpu_restore; 1633 t->cpu_restore = s->cpu_restore;
1631 t->platform = s->platform; 1634 t->platform = s->platform;
1635 /*
1636 * If we have passed through this logic once
1637 * before and have pulled the default case
1638 * because the real PVR was not found inside
1639 * cpu_specs[], then we are possibly running in
1640 * compatibility mode. In that case, let the
1641 * oprofiler know which set of compatibility
1642 * counters to pull from by making sure the
1643 * oprofile_cpu_type string is set to that of
1644 * compatibility mode. If the oprofile_cpu_type
1645 * already has a value, then we are possibly
1646 * overriding a real PVR with a logical one, and,
1647 * in that case, keep the current value for
1648 * oprofile_cpu_type.
1649 */
1650 if (t->oprofile_cpu_type == NULL)
1651 t->oprofile_cpu_type = s->oprofile_cpu_type;
1632 } else 1652 } else
1633 *t = *s; 1653 *t = *s;
1634 *PTRRELOC(&cur_cpu_spec) = &the_cpu_spec; 1654 *PTRRELOC(&cur_cpu_spec) = &the_cpu_spec;
diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl_booke.S
index c4268500e856..3cb52fa0eda3 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -151,16 +151,11 @@ skpinv: addi r6,r6,1 /* Increment */
151 /* Invalidate TLB0 */ 151 /* Invalidate TLB0 */
152 li r6,0x04 152 li r6,0x04
153 tlbivax 0,r6 153 tlbivax 0,r6
154#ifdef CONFIG_SMP 154 TLBSYNC
155 tlbsync
156#endif
157 /* Invalidate TLB1 */ 155 /* Invalidate TLB1 */
158 li r6,0x0c 156 li r6,0x0c
159 tlbivax 0,r6 157 tlbivax 0,r6
160#ifdef CONFIG_SMP 158 TLBSYNC
161 tlbsync
162#endif
163 msync
164 159
165/* 3. Setup a temp mapping and jump to it */ 160/* 3. Setup a temp mapping and jump to it */
166 andi. r5, r3, 0x1 /* Find an entry not used and is non-zero */ 161 andi. r5, r3, 0x1 /* Find an entry not used and is non-zero */
@@ -238,10 +233,7 @@ skpinv: addi r6,r6,1 /* Increment */
238 /* Invalidate TLB1 */ 233 /* Invalidate TLB1 */
239 li r9,0x0c 234 li r9,0x0c
240 tlbivax 0,r9 235 tlbivax 0,r9
241#ifdef CONFIG_SMP 236 TLBSYNC
242 tlbsync
243#endif
244 msync
245 237
246/* 6. Setup KERNELBASE mapping in TLB1[0] */ 238/* 6. Setup KERNELBASE mapping in TLB1[0] */
247 lis r6,0x1000 /* Set MAS0(TLBSEL) = TLB1(1), ESEL = 0 */ 239 lis r6,0x1000 /* Set MAS0(TLBSEL) = TLB1(1), ESEL = 0 */
@@ -283,10 +275,7 @@ skpinv: addi r6,r6,1 /* Increment */
283 /* Invalidate TLB1 */ 275 /* Invalidate TLB1 */
284 li r9,0x0c 276 li r9,0x0c
285 tlbivax 0,r9 277 tlbivax 0,r9
286#ifdef CONFIG_SMP 278 TLBSYNC
287 tlbsync
288#endif
289 msync
290 279
291 /* Establish the interrupt vector offsets */ 280 /* Establish the interrupt vector offsets */
292 SET_IVOR(0, CriticalInput); 281 SET_IVOR(0, CriticalInput);
@@ -483,90 +472,16 @@ interrupt_base:
483 472
484 /* Data Storage Interrupt */ 473 /* Data Storage Interrupt */
485 START_EXCEPTION(DataStorage) 474 START_EXCEPTION(DataStorage)
486 mtspr SPRN_SPRG0, r10 /* Save some working registers */ 475 NORMAL_EXCEPTION_PROLOG
487 mtspr SPRN_SPRG1, r11 476 mfspr r5,SPRN_ESR /* Grab the ESR, save it, pass arg3 */
488 mtspr SPRN_SPRG4W, r12 477 stw r5,_ESR(r11)
489 mtspr SPRN_SPRG5W, r13 478 mfspr r4,SPRN_DEAR /* Grab the DEAR, save it, pass arg2 */
490 mfcr r11 479 andis. r10,r5,(ESR_ILK|ESR_DLK)@h
491 mtspr SPRN_SPRG7W, r11 480 bne 1f
492 481 EXC_XFER_EE_LITE(0x0300, handle_page_fault)
493 /* 4821:
494 * Check if it was a store fault, if not then bail 483 addi r3,r1,STACK_FRAME_OVERHEAD
495 * because a user tried to access a kernel or 484 EXC_XFER_EE_LITE(0x0300, CacheLockingException)
496 * read-protected page. Otherwise, get the
497 * offending address and handle it.
498 */
499 mfspr r10, SPRN_ESR
500 andis. r10, r10, ESR_ST@h
501 beq 2f
502
503 mfspr r10, SPRN_DEAR /* Get faulting address */
504
505 /* If we are faulting a kernel address, we have to use the
506 * kernel page tables.
507 */
508 lis r11, PAGE_OFFSET@h
509 cmplw 0, r10, r11
510 bge 2f
511
512 /* Get the PGD for the current thread */
5133:
514 mfspr r11,SPRN_SPRG3
515 lwz r11,PGDIR(r11)
5164:
517 FIND_PTE
518
519 /* Are _PAGE_USER & _PAGE_RW set & _PAGE_HWWRITE not? */
520 andi. r13, r11, _PAGE_RW|_PAGE_USER|_PAGE_HWWRITE
521 cmpwi 0, r13, _PAGE_RW|_PAGE_USER
522 bne 2f /* Bail if not */
523
524 /* Update 'changed'. */
525 ori r11, r11, _PAGE_DIRTY|_PAGE_ACCESSED|_PAGE_HWWRITE
526 stw r11, PTE_FLAGS_OFFSET(r12) /* Update Linux page table */
527
528 /* MAS2 not updated as the entry does exist in the tlb, this
529 fault taken to detect state transition (eg: COW -> DIRTY)
530 */
531 andi. r11, r11, _PAGE_HWEXEC
532 rlwimi r11, r11, 31, 27, 27 /* SX <- _PAGE_HWEXEC */
533 ori r11, r11, (MAS3_UW|MAS3_SW|MAS3_UR|MAS3_SR)@l /* set static perms */
534
535 /* update search PID in MAS6, AS = 0 */
536 mfspr r12, SPRN_PID0
537 slwi r12, r12, 16
538 mtspr SPRN_MAS6, r12
539
540 /* find the TLB index that caused the fault. It has to be here. */
541 tlbsx 0, r10
542
543 /* only update the perm bits, assume the RPN is fine */
544 mfspr r12, SPRN_MAS3
545 rlwimi r12, r11, 0, 20, 31
546 mtspr SPRN_MAS3,r12
547 tlbwe
548
549 /* Done...restore registers and get out of here. */
550 mfspr r11, SPRN_SPRG7R
551 mtcr r11
552 mfspr r13, SPRN_SPRG5R
553 mfspr r12, SPRN_SPRG4R
554 mfspr r11, SPRN_SPRG1
555 mfspr r10, SPRN_SPRG0
556 rfi /* Force context change */
557
5582:
559 /*
560 * The bailout. Restore registers to pre-exception conditions
561 * and call the heavyweights to help us out.
562 */
563 mfspr r11, SPRN_SPRG7R
564 mtcr r11
565 mfspr r13, SPRN_SPRG5R
566 mfspr r12, SPRN_SPRG4R
567 mfspr r11, SPRN_SPRG1
568 mfspr r10, SPRN_SPRG0
569 b data_access
570 485
571 /* Instruction Storage Interrupt */ 486 /* Instruction Storage Interrupt */
572 INSTRUCTION_STORAGE_EXCEPTION 487 INSTRUCTION_STORAGE_EXCEPTION
@@ -645,15 +560,30 @@ interrupt_base:
645 lwz r11,PGDIR(r11) 560 lwz r11,PGDIR(r11)
646 561
6474: 5624:
563 /* Mask of required permission bits. Note that while we
564 * do copy ESR:ST to _PAGE_RW position as trying to write
565 * to an RO page is pretty common, we don't do it with
566 * _PAGE_DIRTY. We could do it, but it's a fairly rare
567 * event so I'd rather take the overhead when it happens
568 * rather than adding an instruction here. We should measure
569 * whether the whole thing is worth it in the first place
570 * as we could avoid loading SPRN_ESR completely in the first
571 * place...
572 *
573 * TODO: Is it worth doing that mfspr & rlwimi in the first
574 * place or can we save a couple of instructions here ?
575 */
576 mfspr r12,SPRN_ESR
577 li r13,_PAGE_PRESENT|_PAGE_ACCESSED
578 rlwimi r13,r12,11,29,29
579
648 FIND_PTE 580 FIND_PTE
649 andi. r13, r11, _PAGE_PRESENT /* Is the page present? */ 581 andc. r13,r13,r11 /* Check permission */
650 beq 2f /* Bail if not present */ 582 bne 2f /* Bail if permission mismach */
651 583
652#ifdef CONFIG_PTE_64BIT 584#ifdef CONFIG_PTE_64BIT
653 lwz r13, 0(r12) 585 lwz r13, 0(r12)
654#endif 586#endif
655 ori r11, r11, _PAGE_ACCESSED
656 stw r11, PTE_FLAGS_OFFSET(r12)
657 587
658 /* Jump to common tlb load */ 588 /* Jump to common tlb load */
659 b finish_tlb_load 589 b finish_tlb_load
@@ -667,7 +597,7 @@ interrupt_base:
667 mfspr r12, SPRN_SPRG4R 597 mfspr r12, SPRN_SPRG4R
668 mfspr r11, SPRN_SPRG1 598 mfspr r11, SPRN_SPRG1
669 mfspr r10, SPRN_SPRG0 599 mfspr r10, SPRN_SPRG0
670 b data_access 600 b DataStorage
671 601
672 /* Instruction TLB Error Interrupt */ 602 /* Instruction TLB Error Interrupt */
673 /* 603 /*
@@ -705,15 +635,16 @@ interrupt_base:
705 lwz r11,PGDIR(r11) 635 lwz r11,PGDIR(r11)
706 636
7074: 6374:
638 /* Make up the required permissions */
639 li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_HWEXEC
640
708 FIND_PTE 641 FIND_PTE
709 andi. r13, r11, _PAGE_PRESENT /* Is the page present? */ 642 andc. r13,r13,r11 /* Check permission */
710 beq 2f /* Bail if not present */ 643 bne 2f /* Bail if permission mismach */
711 644
712#ifdef CONFIG_PTE_64BIT 645#ifdef CONFIG_PTE_64BIT
713 lwz r13, 0(r12) 646 lwz r13, 0(r12)
714#endif 647#endif
715 ori r11, r11, _PAGE_ACCESSED
716 stw r11, PTE_FLAGS_OFFSET(r12)
717 648
718 /* Jump to common TLB load point */ 649 /* Jump to common TLB load point */
719 b finish_tlb_load 650 b finish_tlb_load
@@ -768,29 +699,13 @@ interrupt_base:
768 * Local functions 699 * Local functions
769 */ 700 */
770 701
771 /*
772 * Data TLB exceptions will bail out to this point
773 * if they can't resolve the lightweight TLB fault.
774 */
775data_access:
776 NORMAL_EXCEPTION_PROLOG
777 mfspr r5,SPRN_ESR /* Grab the ESR, save it, pass arg3 */
778 stw r5,_ESR(r11)
779 mfspr r4,SPRN_DEAR /* Grab the DEAR, save it, pass arg2 */
780 andis. r10,r5,(ESR_ILK|ESR_DLK)@h
781 bne 1f
782 EXC_XFER_EE_LITE(0x0300, handle_page_fault)
7831:
784 addi r3,r1,STACK_FRAME_OVERHEAD
785 EXC_XFER_EE_LITE(0x0300, CacheLockingException)
786
787/* 702/*
788
789 * Both the instruction and data TLB miss get to this 703 * Both the instruction and data TLB miss get to this
790 * point to load the TLB. 704 * point to load the TLB.
791 * r10 - EA of fault 705 * r10 - EA of fault
792 * r11 - TLB (info from Linux PTE) 706 * r11 - TLB (info from Linux PTE)
793 * r12, r13 - available to use 707 * r12 - available to use
708 * r13 - upper bits of PTE (if PTE_64BIT) or available to use
794 * CR5 - results of addr >= PAGE_OFFSET 709 * CR5 - results of addr >= PAGE_OFFSET
795 * MAS0, MAS1 - loaded with proper value when we get here 710 * MAS0, MAS1 - loaded with proper value when we get here
796 * MAS2, MAS3 - will need additional info from Linux PTE 711 * MAS2, MAS3 - will need additional info from Linux PTE
@@ -812,20 +727,14 @@ finish_tlb_load:
812#endif 727#endif
813 mtspr SPRN_MAS2, r12 728 mtspr SPRN_MAS2, r12
814 729
815 bge 5, 1f 730 li r10, (_PAGE_HWEXEC | _PAGE_PRESENT)
816 731 rlwimi r10, r11, 31, 29, 29 /* extract _PAGE_DIRTY into SW */
817 /* is user addr */ 732 and r12, r11, r10
818 andi. r12, r11, (_PAGE_USER | _PAGE_HWWRITE | _PAGE_HWEXEC)
819 andi. r10, r11, _PAGE_USER /* Test for _PAGE_USER */ 733 andi. r10, r11, _PAGE_USER /* Test for _PAGE_USER */
820 srwi r10, r12, 1 734 slwi r10, r12, 1
821 or r12, r12, r10 /* Copy user perms into supervisor */ 735 or r10, r10, r12
822 iseleq r12, 0, r12 736 iseleq r12, r12, r10
823 b 2f 737
824
825 /* is kernel addr */
8261: rlwinm r12, r11, 31, 29, 29 /* Extract _PAGE_HWWRITE into SW */
827 ori r12, r12, (MAS3_SX | MAS3_SR)
828
829#ifdef CONFIG_PTE_64BIT 738#ifdef CONFIG_PTE_64BIT
8302: rlwimi r12, r13, 24, 0, 7 /* grab RPN[32:39] */ 7392: rlwimi r12, r13, 24, 0, 7 /* grab RPN[32:39] */
831 rlwimi r12, r11, 24, 8, 19 /* grab RPN[40:51] */ 740 rlwimi r12, r11, 24, 8, 19 /* grab RPN[40:51] */
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index 8c68ee9e5d1c..2385f68c1751 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -186,7 +186,8 @@ static unsigned long iommu_range_alloc(struct device *dev,
186static dma_addr_t iommu_alloc(struct device *dev, struct iommu_table *tbl, 186static dma_addr_t iommu_alloc(struct device *dev, struct iommu_table *tbl,
187 void *page, unsigned int npages, 187 void *page, unsigned int npages,
188 enum dma_data_direction direction, 188 enum dma_data_direction direction,
189 unsigned long mask, unsigned int align_order) 189 unsigned long mask, unsigned int align_order,
190 struct dma_attrs *attrs)
190{ 191{
191 unsigned long entry, flags; 192 unsigned long entry, flags;
192 dma_addr_t ret = DMA_ERROR_CODE; 193 dma_addr_t ret = DMA_ERROR_CODE;
@@ -205,7 +206,7 @@ static dma_addr_t iommu_alloc(struct device *dev, struct iommu_table *tbl,
205 206
206 /* Put the TCEs in the HW table */ 207 /* Put the TCEs in the HW table */
207 ppc_md.tce_build(tbl, entry, npages, (unsigned long)page & IOMMU_PAGE_MASK, 208 ppc_md.tce_build(tbl, entry, npages, (unsigned long)page & IOMMU_PAGE_MASK,
208 direction); 209 direction, attrs);
209 210
210 211
211 /* Flush/invalidate TLB caches if necessary */ 212 /* Flush/invalidate TLB caches if necessary */
@@ -336,7 +337,8 @@ int iommu_map_sg(struct device *dev, struct iommu_table *tbl,
336 npages, entry, dma_addr); 337 npages, entry, dma_addr);
337 338
338 /* Insert into HW table */ 339 /* Insert into HW table */
339 ppc_md.tce_build(tbl, entry, npages, vaddr & IOMMU_PAGE_MASK, direction); 340 ppc_md.tce_build(tbl, entry, npages, vaddr & IOMMU_PAGE_MASK,
341 direction, attrs);
340 342
341 /* If we are in an open segment, try merging */ 343 /* If we are in an open segment, try merging */
342 if (segstart != s) { 344 if (segstart != s) {
@@ -573,7 +575,8 @@ dma_addr_t iommu_map_single(struct device *dev, struct iommu_table *tbl,
573 align = PAGE_SHIFT - IOMMU_PAGE_SHIFT; 575 align = PAGE_SHIFT - IOMMU_PAGE_SHIFT;
574 576
575 dma_handle = iommu_alloc(dev, tbl, vaddr, npages, direction, 577 dma_handle = iommu_alloc(dev, tbl, vaddr, npages, direction,
576 mask >> IOMMU_PAGE_SHIFT, align); 578 mask >> IOMMU_PAGE_SHIFT, align,
579 attrs);
577 if (dma_handle == DMA_ERROR_CODE) { 580 if (dma_handle == DMA_ERROR_CODE) {
578 if (printk_ratelimit()) { 581 if (printk_ratelimit()) {
579 printk(KERN_INFO "iommu_alloc failed, " 582 printk(KERN_INFO "iommu_alloc failed, "
@@ -642,7 +645,7 @@ void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl,
642 nio_pages = size >> IOMMU_PAGE_SHIFT; 645 nio_pages = size >> IOMMU_PAGE_SHIFT;
643 io_order = get_iommu_order(size); 646 io_order = get_iommu_order(size);
644 mapping = iommu_alloc(dev, tbl, ret, nio_pages, DMA_BIDIRECTIONAL, 647 mapping = iommu_alloc(dev, tbl, ret, nio_pages, DMA_BIDIRECTIONAL,
645 mask >> IOMMU_PAGE_SHIFT, io_order); 648 mask >> IOMMU_PAGE_SHIFT, io_order, NULL);
646 if (mapping == DMA_ERROR_CODE) { 649 if (mapping == DMA_ERROR_CODE) {
647 free_pages((unsigned long)ret, order); 650 free_pages((unsigned long)ret, order);
648 return NULL; 651 return NULL;
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index 063cdd413049..224e9a11765c 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -598,6 +598,7 @@ void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
598 res->start = pci_addr; 598 res->start = pci_addr;
599 break; 599 break;
600 case 2: /* PCI Memory space */ 600 case 2: /* PCI Memory space */
601 case 3: /* PCI 64 bits Memory space */
601 printk(KERN_INFO 602 printk(KERN_INFO
602 " MEM 0x%016llx..0x%016llx -> 0x%016llx %s\n", 603 " MEM 0x%016llx..0x%016llx -> 0x%016llx %s\n",
603 cpu_addr, cpu_addr + size - 1, pci_addr, 604 cpu_addr, cpu_addr + size - 1, pci_addr,
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index 90eb3a3e383e..bc1fb27368af 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -128,12 +128,35 @@ static void of_bus_pci_count_cells(struct device_node *np,
128 *sizec = 2; 128 *sizec = 2;
129} 129}
130 130
131static unsigned int of_bus_pci_get_flags(const u32 *addr)
132{
133 unsigned int flags = 0;
134 u32 w = addr[0];
135
136 switch((w >> 24) & 0x03) {
137 case 0x01:
138 flags |= IORESOURCE_IO;
139 break;
140 case 0x02: /* 32 bits */
141 case 0x03: /* 64 bits */
142 flags |= IORESOURCE_MEM;
143 break;
144 }
145 if (w & 0x40000000)
146 flags |= IORESOURCE_PREFETCH;
147 return flags;
148}
149
131static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna) 150static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna)
132{ 151{
133 u64 cp, s, da; 152 u64 cp, s, da;
153 unsigned int af, rf;
154
155 af = of_bus_pci_get_flags(addr);
156 rf = of_bus_pci_get_flags(range);
134 157
135 /* Check address type match */ 158 /* Check address type match */
136 if ((addr[0] ^ range[0]) & 0x03000000) 159 if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
137 return OF_BAD_ADDR; 160 return OF_BAD_ADDR;
138 161
139 /* Read address values, skipping high cell */ 162 /* Read address values, skipping high cell */
@@ -153,25 +176,6 @@ static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
153 return of_bus_default_translate(addr + 1, offset, na - 1); 176 return of_bus_default_translate(addr + 1, offset, na - 1);
154} 177}
155 178
156static unsigned int of_bus_pci_get_flags(const u32 *addr)
157{
158 unsigned int flags = 0;
159 u32 w = addr[0];
160
161 switch((w >> 24) & 0x03) {
162 case 0x01:
163 flags |= IORESOURCE_IO;
164 break;
165 case 0x02: /* 32 bits */
166 case 0x03: /* 64 bits */
167 flags |= IORESOURCE_MEM;
168 break;
169 }
170 if (w & 0x40000000)
171 flags |= IORESOURCE_PREFETCH;
172 return flags;
173}
174
175const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size, 179const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
176 unsigned int *flags) 180 unsigned int *flags)
177{ 181{
diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c
index 071bee3ec749..f2589645870a 100644
--- a/arch/powerpc/kernel/stacktrace.c
+++ b/arch/powerpc/kernel/stacktrace.c
@@ -59,6 +59,6 @@ EXPORT_SYMBOL_GPL(save_stack_trace);
59 59
60void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) 60void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
61{ 61{
62 save_context_stack(trace, tsk->thread.regs->gpr[1], tsk, 0); 62 save_context_stack(trace, tsk->thread.ksp, tsk, 0);
63} 63}
64EXPORT_SYMBOL_GPL(save_stack_trace_tsk); 64EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
index c8127f832df0..aba0ba95f062 100644
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -28,7 +28,9 @@ static DEFINE_PER_CPU(struct cpu, cpu_devices);
28/* Time in microseconds we delay before sleeping in the idle loop */ 28/* Time in microseconds we delay before sleeping in the idle loop */
29DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 }; 29DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 };
30 30
31static ssize_t store_smt_snooze_delay(struct sys_device *dev, const char *buf, 31static ssize_t store_smt_snooze_delay(struct sys_device *dev,
32 struct sysdev_attribute *attr,
33 const char *buf,
32 size_t count) 34 size_t count)
33{ 35{
34 struct cpu *cpu = container_of(dev, struct cpu, sysdev); 36 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
@@ -44,7 +46,9 @@ static ssize_t store_smt_snooze_delay(struct sys_device *dev, const char *buf,
44 return count; 46 return count;
45} 47}
46 48
47static ssize_t show_smt_snooze_delay(struct sys_device *dev, char *buf) 49static ssize_t show_smt_snooze_delay(struct sys_device *dev,
50 struct sysdev_attribute *attr,
51 char *buf)
48{ 52{
49 struct cpu *cpu = container_of(dev, struct cpu, sysdev); 53 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
50 54
@@ -152,14 +156,17 @@ static unsigned long write_##NAME(unsigned long val) \
152 mtspr(ADDRESS, val); \ 156 mtspr(ADDRESS, val); \
153 return 0; \ 157 return 0; \
154} \ 158} \
155static ssize_t show_##NAME(struct sys_device *dev, char *buf) \ 159static ssize_t show_##NAME(struct sys_device *dev, \
160 struct sysdev_attribute *attr, \
161 char *buf) \
156{ \ 162{ \
157 struct cpu *cpu = container_of(dev, struct cpu, sysdev); \ 163 struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
158 unsigned long val = run_on_cpu(cpu->sysdev.id, read_##NAME, 0); \ 164 unsigned long val = run_on_cpu(cpu->sysdev.id, read_##NAME, 0); \
159 return sprintf(buf, "%lx\n", val); \ 165 return sprintf(buf, "%lx\n", val); \
160} \ 166} \
161static ssize_t __used \ 167static ssize_t __used \
162 store_##NAME(struct sys_device *dev, const char *buf, size_t count) \ 168 store_##NAME(struct sys_device *dev, struct sysdev_attribute *attr, \
169 const char *buf, size_t count) \
163{ \ 170{ \
164 struct cpu *cpu = container_of(dev, struct cpu, sysdev); \ 171 struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
165 unsigned long val; \ 172 unsigned long val; \
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 87a72c66ce27..a914411bced5 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -9,6 +9,25 @@
9 9
10ENTRY(_stext) 10ENTRY(_stext)
11 11
12PHDRS {
13 kernel PT_LOAD FLAGS(7); /* RWX */
14 notes PT_NOTE FLAGS(0);
15 dummy PT_NOTE FLAGS(0);
16
17 /* binutils < 2.18 has a bug that makes it misbehave when taking an
18 ELF file with all segments at load address 0 as input. This
19 happens when running "strip" on vmlinux, because of the AT() magic
20 in this linker script. People using GCC >= 4.2 won't run into
21 this problem, because the "build-id" support will put some data
22 into the "notes" segment (at a non-zero load address).
23
24 To work around this, we force some data into both the "dummy"
25 segment and the kernel segment, so the dummy segment will get a
26 non-zero load address. It's not enough to always create the
27 "notes" segment, since if nothing gets assigned to it, its load
28 address will be zero. */
29}
30
12#ifdef CONFIG_PPC64 31#ifdef CONFIG_PPC64
13OUTPUT_ARCH(powerpc:common64) 32OUTPUT_ARCH(powerpc:common64)
14jiffies = jiffies_64; 33jiffies = jiffies_64;
@@ -50,7 +69,7 @@ SECTIONS
50 . = ALIGN(PAGE_SIZE); 69 . = ALIGN(PAGE_SIZE);
51 _etext = .; 70 _etext = .;
52 PROVIDE32 (etext = .); 71 PROVIDE32 (etext = .);
53 } 72 } :kernel
54 73
55 /* Read-only data */ 74 /* Read-only data */
56 RODATA 75 RODATA
@@ -62,7 +81,13 @@ SECTIONS
62 __stop___ex_table = .; 81 __stop___ex_table = .;
63 } 82 }
64 83
65 NOTES 84 NOTES :kernel :notes
85
86 /* The dummy segment contents for the bug workaround mentioned above
87 near PHDRS. */
88 .dummy : {
89 LONG(0xf177)
90 } :kernel :dummy
66 91
67/* 92/*
68 * Init sections discarded at runtime 93 * Init sections discarded at runtime
@@ -74,7 +99,7 @@ SECTIONS
74 _sinittext = .; 99 _sinittext = .;
75 INIT_TEXT 100 INIT_TEXT
76 _einittext = .; 101 _einittext = .;
77 } 102 } :kernel
78 103
79 /* .exit.text is discarded at runtime, not link time, 104 /* .exit.text is discarded at runtime, not link time,
80 * to deal with references from __bug_table 105 * to deal with references from __bug_table
diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
index 4e43702b9813..8c5a03be31e0 100644
--- a/arch/powerpc/lib/feature-fixups.c
+++ b/arch/powerpc/lib/feature-fixups.c
@@ -99,7 +99,7 @@ void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end)
99 99
100 for (; fcur < fend; fcur++) { 100 for (; fcur < fend; fcur++) {
101 if (patch_feature_section(value, fcur)) { 101 if (patch_feature_section(value, fcur)) {
102 __WARN(); 102 WARN_ON(1);
103 printk("Unable to patch feature section at %p - %p" \ 103 printk("Unable to patch feature section at %p - %p" \
104 " with %p - %p\n", 104 " with %p - %p\n",
105 calc_addr(fcur, fcur->start_off), 105 calc_addr(fcur, fcur->start_off),
diff --git a/arch/powerpc/lib/string.S b/arch/powerpc/lib/string.S
index 49eb1f1a2bb4..64e2e499e32a 100644
--- a/arch/powerpc/lib/string.S
+++ b/arch/powerpc/lib/string.S
@@ -13,13 +13,7 @@
13#include <asm/ppc_asm.h> 13#include <asm/ppc_asm.h>
14 14
15 .section __ex_table,"a" 15 .section __ex_table,"a"
16#ifdef CONFIG_PPC64 16 PPC_LONG_ALIGN
17 .align 3
18#define EXTBL .llong
19#else
20 .align 2
21#define EXTBL .long
22#endif
23 .text 17 .text
24 18
25_GLOBAL(strcpy) 19_GLOBAL(strcpy)
@@ -160,9 +154,9 @@ _GLOBAL(__clear_user)
160 blr 154 blr
161 155
162 .section __ex_table,"a" 156 .section __ex_table,"a"
163 EXTBL 11b,90b 157 PPC_LONG 11b,90b
164 EXTBL 1b,91b 158 PPC_LONG 1b,91b
165 EXTBL 8b,92b 159 PPC_LONG 8b,92b
166 .text 160 .text
167 161
168_GLOBAL(__strncpy_from_user) 162_GLOBAL(__strncpy_from_user)
@@ -183,7 +177,7 @@ _GLOBAL(__strncpy_from_user)
183 blr 177 blr
184 178
185 .section __ex_table,"a" 179 .section __ex_table,"a"
186 EXTBL 1b,99b 180 PPC_LONG 1b,99b
187 .text 181 .text
188 182
189/* r3 = str, r4 = len (> 0), r5 = top (highest addr) */ 183/* r3 = str, r4 = len (> 0), r5 = top (highest addr) */
@@ -208,4 +202,4 @@ _GLOBAL(__strnlen_user)
208 blr 202 blr
209 203
210 .section __ex_table,"a" 204 .section __ex_table,"a"
211 EXTBL 1b,99b 205 PPC_LONG 1b,99b
diff --git a/arch/powerpc/platforms/52xx/Kconfig b/arch/powerpc/platforms/52xx/Kconfig
index acd2fc8cf492..d664b1bce381 100644
--- a/arch/powerpc/platforms/52xx/Kconfig
+++ b/arch/powerpc/platforms/52xx/Kconfig
@@ -3,6 +3,7 @@ config PPC_MPC52xx
3 depends on PPC_MULTIPLATFORM && PPC32 3 depends on PPC_MULTIPLATFORM && PPC32
4 select FSL_SOC 4 select FSL_SOC
5 select PPC_CLOCK 5 select PPC_CLOCK
6 select PPC_PCI_CHOICE
6 7
7config PPC_MPC5200_SIMPLE 8config PPC_MPC5200_SIMPLE
8 bool "Generic support for simple MPC5200 based boards" 9 bool "Generic support for simple MPC5200 based boards"
diff --git a/arch/powerpc/platforms/82xx/Kconfig b/arch/powerpc/platforms/82xx/Kconfig
index 1c8034bfa796..75eb1ede5497 100644
--- a/arch/powerpc/platforms/82xx/Kconfig
+++ b/arch/powerpc/platforms/82xx/Kconfig
@@ -30,6 +30,7 @@ config EP8248E
30 select 8272 30 select 8272
31 select 8260 31 select 8260
32 select FSL_SOC 32 select FSL_SOC
33 select PHYLIB
33 select MDIO_BITBANG 34 select MDIO_BITBANG
34 help 35 help
35 This enables support for the Embedded Planet EP8248E board. 36 This enables support for the Embedded Planet EP8248E board.
diff --git a/arch/powerpc/platforms/82xx/ep8248e.c b/arch/powerpc/platforms/82xx/ep8248e.c
index 373e993a5ed5..d5770fdf7f09 100644
--- a/arch/powerpc/platforms/82xx/ep8248e.c
+++ b/arch/powerpc/platforms/82xx/ep8248e.c
@@ -59,7 +59,6 @@ static void __init ep8248e_pic_init(void)
59 of_node_put(np); 59 of_node_put(np);
60} 60}
61 61
62#ifdef CONFIG_FS_ENET_MDIO_FCC
63static void ep8248e_set_mdc(struct mdiobb_ctrl *ctrl, int level) 62static void ep8248e_set_mdc(struct mdiobb_ctrl *ctrl, int level)
64{ 63{
65 if (level) 64 if (level)
@@ -165,7 +164,6 @@ static struct of_platform_driver ep8248e_mdio_driver = {
165 .probe = ep8248e_mdio_probe, 164 .probe = ep8248e_mdio_probe,
166 .remove = ep8248e_mdio_remove, 165 .remove = ep8248e_mdio_remove,
167}; 166};
168#endif
169 167
170struct cpm_pin { 168struct cpm_pin {
171 int port, pin, flags; 169 int port, pin, flags;
@@ -298,9 +296,7 @@ static __initdata struct of_device_id of_bus_ids[] = {
298static int __init declare_of_platform_devices(void) 296static int __init declare_of_platform_devices(void)
299{ 297{
300 of_platform_bus_probe(NULL, of_bus_ids, NULL); 298 of_platform_bus_probe(NULL, of_bus_ids, NULL);
301#ifdef CONFIG_FS_ENET_MDIO_FCC
302 of_register_platform_driver(&ep8248e_mdio_driver); 299 of_register_platform_driver(&ep8248e_mdio_driver);
303#endif
304 300
305 return 0; 301 return 0;
306} 302}
diff --git a/arch/powerpc/platforms/83xx/Kconfig b/arch/powerpc/platforms/83xx/Kconfig
index 27d9bf86de01..6159c5d4e5f1 100644
--- a/arch/powerpc/platforms/83xx/Kconfig
+++ b/arch/powerpc/platforms/83xx/Kconfig
@@ -2,7 +2,8 @@ menuconfig PPC_83xx
2 bool "83xx-based boards" 2 bool "83xx-based boards"
3 depends on 6xx && PPC_MULTIPLATFORM 3 depends on 6xx && PPC_MULTIPLATFORM
4 select PPC_UDBG_16550 4 select PPC_UDBG_16550
5 select PPC_INDIRECT_PCI 5 select PPC_PCI_CHOICE
6 select FSL_PCI if PCI
6 select FSL_SOC 7 select FSL_SOC
7 select IPIC 8 select IPIC
8 9
diff --git a/arch/powerpc/platforms/83xx/Makefile b/arch/powerpc/platforms/83xx/Makefile
index f331fd7dd836..ba5028e29890 100644
--- a/arch/powerpc/platforms/83xx/Makefile
+++ b/arch/powerpc/platforms/83xx/Makefile
@@ -2,7 +2,7 @@
2# Makefile for the PowerPC 83xx linux kernel. 2# Makefile for the PowerPC 83xx linux kernel.
3# 3#
4obj-y := misc.o usb.o 4obj-y := misc.o usb.o
5obj-$(CONFIG_PCI) += pci.o 5obj-$(CONFIG_SUSPEND) += suspend.o suspend-asm.o
6obj-$(CONFIG_MPC831x_RDB) += mpc831x_rdb.o 6obj-$(CONFIG_MPC831x_RDB) += mpc831x_rdb.o
7obj-$(CONFIG_MPC832x_RDB) += mpc832x_rdb.o 7obj-$(CONFIG_MPC832x_RDB) += mpc832x_rdb.o
8obj-$(CONFIG_MPC834x_MDS) += mpc834x_mds.o 8obj-$(CONFIG_MPC834x_MDS) += mpc834x_mds.o
diff --git a/arch/powerpc/platforms/83xx/mpc831x_rdb.c b/arch/powerpc/platforms/83xx/mpc831x_rdb.c
index c4db5172b27a..a428f8d1ac80 100644
--- a/arch/powerpc/platforms/83xx/mpc831x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc831x_rdb.c
@@ -19,6 +19,7 @@
19#include <asm/time.h> 19#include <asm/time.h>
20#include <asm/ipic.h> 20#include <asm/ipic.h>
21#include <asm/udbg.h> 21#include <asm/udbg.h>
22#include <sysdev/fsl_pci.h>
22 23
23#include "mpc83xx.h" 24#include "mpc83xx.h"
24 25
diff --git a/arch/powerpc/platforms/83xx/mpc832x_mds.c b/arch/powerpc/platforms/83xx/mpc832x_mds.c
index 6dbc6eabcb02..dd4be4aee314 100644
--- a/arch/powerpc/platforms/83xx/mpc832x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc832x_mds.c
@@ -36,6 +36,7 @@
36#include <asm/prom.h> 36#include <asm/prom.h>
37#include <asm/udbg.h> 37#include <asm/udbg.h>
38#include <sysdev/fsl_soc.h> 38#include <sysdev/fsl_soc.h>
39#include <sysdev/fsl_pci.h>
39#include <asm/qe.h> 40#include <asm/qe.h>
40#include <asm/qe_ic.h> 41#include <asm/qe_ic.h>
41 42
diff --git a/arch/powerpc/platforms/83xx/mpc832x_rdb.c b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
index e7f706b624fe..f049d692d4c8 100644
--- a/arch/powerpc/platforms/83xx/mpc832x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
@@ -27,6 +27,7 @@
27#include <asm/qe.h> 27#include <asm/qe.h>
28#include <asm/qe_ic.h> 28#include <asm/qe_ic.h>
29#include <sysdev/fsl_soc.h> 29#include <sysdev/fsl_soc.h>
30#include <sysdev/fsl_pci.h>
30 31
31#include "mpc83xx.h" 32#include "mpc83xx.h"
32 33
diff --git a/arch/powerpc/platforms/83xx/mpc834x_itx.c b/arch/powerpc/platforms/83xx/mpc834x_itx.c
index 50e8f632061c..7301d77a08ee 100644
--- a/arch/powerpc/platforms/83xx/mpc834x_itx.c
+++ b/arch/powerpc/platforms/83xx/mpc834x_itx.c
@@ -35,6 +35,7 @@
35#include <asm/prom.h> 35#include <asm/prom.h>
36#include <asm/udbg.h> 36#include <asm/udbg.h>
37#include <sysdev/fsl_soc.h> 37#include <sysdev/fsl_soc.h>
38#include <sysdev/fsl_pci.h>
38 39
39#include "mpc83xx.h" 40#include "mpc83xx.h"
40 41
diff --git a/arch/powerpc/platforms/83xx/mpc834x_mds.c b/arch/powerpc/platforms/83xx/mpc834x_mds.c
index 2b8a0a3f8557..30d509aa9f08 100644
--- a/arch/powerpc/platforms/83xx/mpc834x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc834x_mds.c
@@ -35,6 +35,7 @@
35#include <asm/prom.h> 35#include <asm/prom.h>
36#include <asm/udbg.h> 36#include <asm/udbg.h>
37#include <sysdev/fsl_soc.h> 37#include <sysdev/fsl_soc.h>
38#include <sysdev/fsl_pci.h>
38 39
39#include "mpc83xx.h" 40#include "mpc83xx.h"
40 41
diff --git a/arch/powerpc/platforms/83xx/mpc836x_mds.c b/arch/powerpc/platforms/83xx/mpc836x_mds.c
index c2e5de60c055..75b80e836576 100644
--- a/arch/powerpc/platforms/83xx/mpc836x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc836x_mds.c
@@ -42,6 +42,7 @@
42#include <asm/prom.h> 42#include <asm/prom.h>
43#include <asm/udbg.h> 43#include <asm/udbg.h>
44#include <sysdev/fsl_soc.h> 44#include <sysdev/fsl_soc.h>
45#include <sysdev/fsl_pci.h>
45#include <asm/qe.h> 46#include <asm/qe.h>
46#include <asm/qe_ic.h> 47#include <asm/qe_ic.h>
47 48
diff --git a/arch/powerpc/platforms/83xx/mpc836x_rdk.c b/arch/powerpc/platforms/83xx/mpc836x_rdk.c
index c10dec4bf178..a5273bb28e1b 100644
--- a/arch/powerpc/platforms/83xx/mpc836x_rdk.c
+++ b/arch/powerpc/platforms/83xx/mpc836x_rdk.c
@@ -23,6 +23,7 @@
23#include <asm/qe.h> 23#include <asm/qe.h>
24#include <asm/qe_ic.h> 24#include <asm/qe_ic.h>
25#include <sysdev/fsl_soc.h> 25#include <sysdev/fsl_soc.h>
26#include <sysdev/fsl_pci.h>
26 27
27#include "mpc83xx.h" 28#include "mpc83xx.h"
28 29
diff --git a/arch/powerpc/platforms/83xx/mpc837x_mds.c b/arch/powerpc/platforms/83xx/mpc837x_mds.c
index 64d17b0d6455..be62de23bead 100644
--- a/arch/powerpc/platforms/83xx/mpc837x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc837x_mds.c
@@ -19,6 +19,7 @@
19#include <asm/ipic.h> 19#include <asm/ipic.h>
20#include <asm/udbg.h> 20#include <asm/udbg.h>
21#include <asm/prom.h> 21#include <asm/prom.h>
22#include <sysdev/fsl_pci.h>
22 23
23#include "mpc83xx.h" 24#include "mpc83xx.h"
24 25
diff --git a/arch/powerpc/platforms/83xx/mpc837x_rdb.c b/arch/powerpc/platforms/83xx/mpc837x_rdb.c
index c00356bdb1dd..da030afa2e2c 100644
--- a/arch/powerpc/platforms/83xx/mpc837x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc837x_rdb.c
@@ -17,6 +17,7 @@
17#include <asm/time.h> 17#include <asm/time.h>
18#include <asm/ipic.h> 18#include <asm/ipic.h>
19#include <asm/udbg.h> 19#include <asm/udbg.h>
20#include <sysdev/fsl_pci.h>
20 21
21#include "mpc83xx.h" 22#include "mpc83xx.h"
22 23
diff --git a/arch/powerpc/platforms/83xx/mpc83xx.h b/arch/powerpc/platforms/83xx/mpc83xx.h
index 88a3b5cabb18..2a7cbabb410a 100644
--- a/arch/powerpc/platforms/83xx/mpc83xx.h
+++ b/arch/powerpc/platforms/83xx/mpc83xx.h
@@ -26,6 +26,8 @@
26#define MPC834X_SICRL_USB1 0x20000000 26#define MPC834X_SICRL_USB1 0x20000000
27#define MPC831X_SICRL_USB_MASK 0x00000c00 27#define MPC831X_SICRL_USB_MASK 0x00000c00
28#define MPC831X_SICRL_USB_ULPI 0x00000800 28#define MPC831X_SICRL_USB_ULPI 0x00000800
29#define MPC8315_SICRL_USB_MASK 0x000000fc
30#define MPC8315_SICRL_USB_ULPI 0x00000054
29#define MPC837X_SICRL_USB_MASK 0xf0000000 31#define MPC837X_SICRL_USB_MASK 0xf0000000
30#define MPC837X_SICRL_USB_ULPI 0x50000000 32#define MPC837X_SICRL_USB_ULPI 0x50000000
31 33
@@ -34,6 +36,8 @@
34#define MPC834X_SICRH_USB_UTMI 0x00020000 36#define MPC834X_SICRH_USB_UTMI 0x00020000
35#define MPC831X_SICRH_USB_MASK 0x000000e0 37#define MPC831X_SICRH_USB_MASK 0x000000e0
36#define MPC831X_SICRH_USB_ULPI 0x000000a0 38#define MPC831X_SICRH_USB_ULPI 0x000000a0
39#define MPC8315_SICRH_USB_MASK 0x0000ff00
40#define MPC8315_SICRH_USB_ULPI 0x00000000
37 41
38/* USB Control Register */ 42/* USB Control Register */
39#define FSL_USB2_CONTROL_OFFS 0x500 43#define FSL_USB2_CONTROL_OFFS 0x500
@@ -55,7 +59,6 @@
55 * mpc83xx_* files. Mostly for use by mpc83xx_setup 59 * mpc83xx_* files. Mostly for use by mpc83xx_setup
56 */ 60 */
57 61
58extern int mpc83xx_add_bridge(struct device_node *dev);
59extern void mpc83xx_restart(char *cmd); 62extern void mpc83xx_restart(char *cmd);
60extern long mpc83xx_time_init(void); 63extern long mpc83xx_time_init(void);
61extern int mpc834x_usb_cfg(void); 64extern int mpc834x_usb_cfg(void);
diff --git a/arch/powerpc/platforms/83xx/pci.c b/arch/powerpc/platforms/83xx/pci.c
deleted file mode 100644
index 14f1080c6c9d..000000000000
--- a/arch/powerpc/platforms/83xx/pci.c
+++ /dev/null
@@ -1,91 +0,0 @@
1/*
2 * FSL SoC setup code
3 *
4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <linux/stddef.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/errno.h>
16#include <linux/pci.h>
17#include <linux/delay.h>
18#include <linux/irq.h>
19#include <linux/module.h>
20
21#include <asm/system.h>
22#include <asm/atomic.h>
23#include <asm/io.h>
24#include <asm/pci-bridge.h>
25#include <asm/prom.h>
26#include <sysdev/fsl_soc.h>
27
28#undef DEBUG
29
30#ifdef DEBUG
31#define DBG(x...) printk(x)
32#else
33#define DBG(x...)
34#endif
35
36int __init mpc83xx_add_bridge(struct device_node *dev)
37{
38 int len;
39 struct pci_controller *hose;
40 struct resource rsrc;
41 const int *bus_range;
42 int primary = 1, has_address = 0;
43 phys_addr_t immr = get_immrbase();
44
45 DBG("Adding PCI host bridge %s\n", dev->full_name);
46
47 /* Fetch host bridge registers address */
48 has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
49
50 /* Get bus range if any */
51 bus_range = of_get_property(dev, "bus-range", &len);
52 if (bus_range == NULL || len < 2 * sizeof(int)) {
53 printk(KERN_WARNING "Can't get bus-range for %s, assume"
54 " bus 0\n", dev->full_name);
55 }
56
57 ppc_pci_flags |= PPC_PCI_REASSIGN_ALL_BUS;
58 hose = pcibios_alloc_controller(dev);
59 if (!hose)
60 return -ENOMEM;
61
62 hose->first_busno = bus_range ? bus_range[0] : 0;
63 hose->last_busno = bus_range ? bus_range[1] : 0xff;
64
65 /* MPC83xx supports up to two host controllers one at 0x8500 from immrbar
66 * the other at 0x8600, we consider the 0x8500 the primary controller
67 */
68 /* PCI 1 */
69 if ((rsrc.start & 0xfffff) == 0x8500) {
70 setup_indirect_pci(hose, immr + 0x8300, immr + 0x8304, 0);
71 }
72 /* PCI 2 */
73 if ((rsrc.start & 0xfffff) == 0x8600) {
74 setup_indirect_pci(hose, immr + 0x8380, immr + 0x8384, 0);
75 primary = 0;
76 }
77
78 printk(KERN_INFO "Found MPC83xx PCI host bridge at 0x%016llx. "
79 "Firmware bus number: %d->%d\n",
80 (unsigned long long)rsrc.start, hose->first_busno,
81 hose->last_busno);
82
83 DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
84 hose, hose->cfg_addr, hose->cfg_data);
85
86 /* Interpret the "ranges" property */
87 /* This also maps the I/O region and sets isa_io/mem_base */
88 pci_process_bridge_OF_ranges(hose, dev, primary);
89
90 return 0;
91}
diff --git a/arch/powerpc/platforms/83xx/sbc834x.c b/arch/powerpc/platforms/83xx/sbc834x.c
index cf382474a83d..fc21f5c15bab 100644
--- a/arch/powerpc/platforms/83xx/sbc834x.c
+++ b/arch/powerpc/platforms/83xx/sbc834x.c
@@ -37,6 +37,7 @@
37#include <asm/prom.h> 37#include <asm/prom.h>
38#include <asm/udbg.h> 38#include <asm/udbg.h>
39#include <sysdev/fsl_soc.h> 39#include <sysdev/fsl_soc.h>
40#include <sysdev/fsl_pci.h>
40 41
41#include "mpc83xx.h" 42#include "mpc83xx.h"
42 43
diff --git a/arch/powerpc/platforms/83xx/suspend-asm.S b/arch/powerpc/platforms/83xx/suspend-asm.S
new file mode 100644
index 000000000000..1930543c98d3
--- /dev/null
+++ b/arch/powerpc/platforms/83xx/suspend-asm.S
@@ -0,0 +1,533 @@
1/*
2 * Enter and leave deep sleep state on MPC83xx
3 *
4 * Copyright (c) 2006-2008 Freescale Semiconductor, Inc.
5 * Author: Scott Wood <scottwood@freescale.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12#include <asm/page.h>
13#include <asm/ppc_asm.h>
14#include <asm/reg.h>
15#include <asm/asm-offsets.h>
16
17#define SS_MEMSAVE 0x00 /* First 8 bytes of RAM */
18#define SS_HID 0x08 /* 3 HIDs */
19#define SS_IABR 0x14 /* 2 IABRs */
20#define SS_IBCR 0x1c
21#define SS_DABR 0x20 /* 2 DABRs */
22#define SS_DBCR 0x28
23#define SS_SP 0x2c
24#define SS_SR 0x30 /* 16 segment registers */
25#define SS_R2 0x70
26#define SS_MSR 0x74
27#define SS_SDR1 0x78
28#define SS_LR 0x7c
29#define SS_SPRG 0x80 /* 4 SPRGs */
30#define SS_DBAT 0x90 /* 8 DBATs */
31#define SS_IBAT 0xd0 /* 8 IBATs */
32#define SS_TB 0x110
33#define SS_CR 0x118
34#define SS_GPREG 0x11c /* r12-r31 */
35#define STATE_SAVE_SIZE 0x16c
36
37 .section .data
38 .align 5
39
40mpc83xx_sleep_save_area:
41 .space STATE_SAVE_SIZE
42immrbase:
43 .long 0
44
45 .section .text
46 .align 5
47
48 /* r3 = physical address of IMMR */
49_GLOBAL(mpc83xx_enter_deep_sleep)
50 lis r4, immrbase@ha
51 stw r3, immrbase@l(r4)
52
53 /* The first 2 words of memory are used to communicate with the
54 * bootloader, to tell it how to resume.
55 *
56 * The first word is the magic number 0xf5153ae5, and the second
57 * is the pointer to mpc83xx_deep_resume.
58 *
59 * The original content of these two words is saved in SS_MEMSAVE.
60 */
61
62 lis r3, mpc83xx_sleep_save_area@h
63 ori r3, r3, mpc83xx_sleep_save_area@l
64
65 lis r4, KERNELBASE@h
66 lwz r5, 0(r4)
67 lwz r6, 4(r4)
68
69 stw r5, SS_MEMSAVE+0(r3)
70 stw r6, SS_MEMSAVE+4(r3)
71
72 mfspr r5, SPRN_HID0
73 mfspr r6, SPRN_HID1
74 mfspr r7, SPRN_HID2
75
76 stw r5, SS_HID+0(r3)
77 stw r6, SS_HID+4(r3)
78 stw r7, SS_HID+8(r3)
79
80 mfspr r4, SPRN_IABR
81 mfspr r5, SPRN_IABR2
82 mfspr r6, SPRN_IBCR
83 mfspr r7, SPRN_DABR
84 mfspr r8, SPRN_DABR2
85 mfspr r9, SPRN_DBCR
86
87 stw r4, SS_IABR+0(r3)
88 stw r5, SS_IABR+4(r3)
89 stw r6, SS_IBCR(r3)
90 stw r7, SS_DABR+0(r3)
91 stw r8, SS_DABR+4(r3)
92 stw r9, SS_DBCR(r3)
93
94 mfspr r4, SPRN_SPRG0
95 mfspr r5, SPRN_SPRG1
96 mfspr r6, SPRN_SPRG2
97 mfspr r7, SPRN_SPRG3
98 mfsdr1 r8
99
100 stw r4, SS_SPRG+0(r3)
101 stw r5, SS_SPRG+4(r3)
102 stw r6, SS_SPRG+8(r3)
103 stw r7, SS_SPRG+12(r3)
104 stw r8, SS_SDR1(r3)
105
106 mfspr r4, SPRN_DBAT0U
107 mfspr r5, SPRN_DBAT0L
108 mfspr r6, SPRN_DBAT1U
109 mfspr r7, SPRN_DBAT1L
110
111 stw r4, SS_DBAT+0x00(r3)
112 stw r5, SS_DBAT+0x04(r3)
113 stw r6, SS_DBAT+0x08(r3)
114 stw r7, SS_DBAT+0x0c(r3)
115
116 mfspr r4, SPRN_DBAT2U
117 mfspr r5, SPRN_DBAT2L
118 mfspr r6, SPRN_DBAT3U
119 mfspr r7, SPRN_DBAT3L
120
121 stw r4, SS_DBAT+0x10(r3)
122 stw r5, SS_DBAT+0x14(r3)
123 stw r6, SS_DBAT+0x18(r3)
124 stw r7, SS_DBAT+0x1c(r3)
125
126 mfspr r4, SPRN_DBAT4U
127 mfspr r5, SPRN_DBAT4L
128 mfspr r6, SPRN_DBAT5U
129 mfspr r7, SPRN_DBAT5L
130
131 stw r4, SS_DBAT+0x20(r3)
132 stw r5, SS_DBAT+0x24(r3)
133 stw r6, SS_DBAT+0x28(r3)
134 stw r7, SS_DBAT+0x2c(r3)
135
136 mfspr r4, SPRN_DBAT6U
137 mfspr r5, SPRN_DBAT6L
138 mfspr r6, SPRN_DBAT7U
139 mfspr r7, SPRN_DBAT7L
140
141 stw r4, SS_DBAT+0x30(r3)
142 stw r5, SS_DBAT+0x34(r3)
143 stw r6, SS_DBAT+0x38(r3)
144 stw r7, SS_DBAT+0x3c(r3)
145
146 mfspr r4, SPRN_IBAT0U
147 mfspr r5, SPRN_IBAT0L
148 mfspr r6, SPRN_IBAT1U
149 mfspr r7, SPRN_IBAT1L
150
151 stw r4, SS_IBAT+0x00(r3)
152 stw r5, SS_IBAT+0x04(r3)
153 stw r6, SS_IBAT+0x08(r3)
154 stw r7, SS_IBAT+0x0c(r3)
155
156 mfspr r4, SPRN_IBAT2U
157 mfspr r5, SPRN_IBAT2L
158 mfspr r6, SPRN_IBAT3U
159 mfspr r7, SPRN_IBAT3L
160
161 stw r4, SS_IBAT+0x10(r3)
162 stw r5, SS_IBAT+0x14(r3)
163 stw r6, SS_IBAT+0x18(r3)
164 stw r7, SS_IBAT+0x1c(r3)
165
166 mfspr r4, SPRN_IBAT4U
167 mfspr r5, SPRN_IBAT4L
168 mfspr r6, SPRN_IBAT5U
169 mfspr r7, SPRN_IBAT5L
170
171 stw r4, SS_IBAT+0x20(r3)
172 stw r5, SS_IBAT+0x24(r3)
173 stw r6, SS_IBAT+0x28(r3)
174 stw r7, SS_IBAT+0x2c(r3)
175
176 mfspr r4, SPRN_IBAT6U
177 mfspr r5, SPRN_IBAT6L
178 mfspr r6, SPRN_IBAT7U
179 mfspr r7, SPRN_IBAT7L
180
181 stw r4, SS_IBAT+0x30(r3)
182 stw r5, SS_IBAT+0x34(r3)
183 stw r6, SS_IBAT+0x38(r3)
184 stw r7, SS_IBAT+0x3c(r3)
185
186 mfmsr r4
187 mflr r5
188 mfcr r6
189
190 stw r4, SS_MSR(r3)
191 stw r5, SS_LR(r3)
192 stw r6, SS_CR(r3)
193 stw r1, SS_SP(r3)
194 stw r2, SS_R2(r3)
195
1961: mftbu r4
197 mftb r5
198 mftbu r6
199 cmpw r4, r6
200 bne 1b
201
202 stw r4, SS_TB+0(r3)
203 stw r5, SS_TB+4(r3)
204
205 stmw r12, SS_GPREG(r3)
206
207 li r4, 0
208 addi r6, r3, SS_SR-4
2091: mfsrin r5, r4
210 stwu r5, 4(r6)
211 addis r4, r4, 0x1000
212 cmpwi r4, 0
213 bne 1b
214
215 /* Disable machine checks and critical exceptions */
216 mfmsr r4
217 rlwinm r4, r4, 0, ~MSR_CE
218 rlwinm r4, r4, 0, ~MSR_ME
219 mtmsr r4
220 isync
221
222#define TMP_VIRT_IMMR 0xf0000000
223#define DEFAULT_IMMR_VALUE 0xff400000
224#define IMMRBAR_BASE 0x0000
225
226 lis r4, immrbase@ha
227 lwz r4, immrbase@l(r4)
228
229 /* Use DBAT0 to address the current IMMR space */
230
231 ori r4, r4, 0x002a
232 mtspr SPRN_DBAT0L, r4
233 lis r8, TMP_VIRT_IMMR@h
234 ori r4, r8, 0x001e /* 1 MByte accessable from Kernel Space only */
235 mtspr SPRN_DBAT0U, r4
236 isync
237
238 /* Use DBAT1 to address the original IMMR space */
239
240 lis r4, DEFAULT_IMMR_VALUE@h
241 ori r4, r4, 0x002a
242 mtspr SPRN_DBAT1L, r4
243 lis r9, (TMP_VIRT_IMMR + 0x01000000)@h
244 ori r4, r9, 0x001e /* 1 MByte accessable from Kernel Space only */
245 mtspr SPRN_DBAT1U, r4
246 isync
247
248 /* Use DBAT2 to address the beginning of RAM. This isn't done
249 * using the normal virtual mapping, because with page debugging
250 * enabled it will be read-only.
251 */
252
253 li r4, 0x0002
254 mtspr SPRN_DBAT2L, r4
255 lis r4, KERNELBASE@h
256 ori r4, r4, 0x001e /* 1 MByte accessable from Kernel Space only */
257 mtspr SPRN_DBAT2U, r4
258 isync
259
260 /* Flush the cache with our BAT, as there will be TLB misses
261 * otherwise if page debugging is enabled, and these misses
262 * will disturb the PLRU algorithm.
263 */
264
265 bl __flush_disable_L1
266
267 /* Keep the i-cache enabled, so the hack below for low-boot
268 * flash will work.
269 */
270 mfspr r3, SPRN_HID0
271 ori r3, r3, HID0_ICE
272 mtspr SPRN_HID0, r3
273 isync
274
275 lis r6, 0xf515
276 ori r6, r6, 0x3ae5
277
278 lis r7, mpc83xx_deep_resume@h
279 ori r7, r7, mpc83xx_deep_resume@l
280 tophys(r7, r7)
281
282 lis r5, KERNELBASE@h
283 stw r6, 0(r5)
284 stw r7, 4(r5)
285
286 /* Reset BARs */
287
288 li r4, 0
289 stw r4, 0x0024(r8)
290 stw r4, 0x002c(r8)
291 stw r4, 0x0034(r8)
292 stw r4, 0x003c(r8)
293 stw r4, 0x0064(r8)
294 stw r4, 0x006c(r8)
295
296 /* Rev 1 of the 8313 has problems with wakeup events that are
297 * pending during the transition to deep sleep state (such as if
298 * the PCI host sets the state to D3 and then D0 in rapid
299 * succession). This check shrinks the race window somewhat.
300 *
301 * See erratum PCI23, though the problem is not limited
302 * to PCI.
303 */
304
305 lwz r3, 0x0b04(r8)
306 andi. r3, r3, 1
307 bne- mpc83xx_deep_resume
308
309 /* Move IMMR back to the default location, following the
310 * procedure specified in the MPC8313 manual.
311 */
312 lwz r4, IMMRBAR_BASE(r8)
313 isync
314 lis r4, DEFAULT_IMMR_VALUE@h
315 stw r4, IMMRBAR_BASE(r8)
316 lis r4, KERNELBASE@h
317 lwz r4, 0(r4)
318 isync
319 lwz r4, IMMRBAR_BASE(r9)
320 mr r8, r9
321 isync
322
323 /* Check the Reset Configuration Word to see whether flash needs
324 * to be mapped at a low address or a high address.
325 */
326
327 lwz r4, 0x0904(r8)
328 andis. r4, r4, 0x0400
329 li r4, 0
330 beq boot_low
331 lis r4, 0xff80
332boot_low:
333 stw r4, 0x0020(r8)
334 lis r7, 0x8000
335 ori r7, r7, 0x0016
336
337 mfspr r5, SPRN_HID0
338 rlwinm r5, r5, 0, ~(HID0_DOZE | HID0_NAP)
339 oris r5, r5, HID0_SLEEP@h
340 mtspr SPRN_HID0, r5
341 isync
342
343 mfmsr r5
344 oris r5, r5, MSR_POW@h
345
346 /* Enable the flash mapping at the appropriate address. This
347 * mapping will override the RAM mapping if booting low, so there's
348 * no need to disable the latter. This must be done inside the same
349 * cache line as setting MSR_POW, so that no instruction fetches
350 * from RAM happen after the flash mapping is turned on.
351 */
352
353 .align 5
354 stw r7, 0x0024(r8)
355 sync
356 isync
357 mtmsr r5
358 isync
3591: b 1b
360
361mpc83xx_deep_resume:
362 lis r4, 1f@h
363 ori r4, r4, 1f@l
364 tophys(r4, r4)
365 mtsrr0 r4
366
367 mfmsr r4
368 rlwinm r4, r4, 0, ~(MSR_IR | MSR_DR)
369 mtsrr1 r4
370
371 rfi
372
3731: tlbia
374 bl __inval_enable_L1
375
376 lis r3, mpc83xx_sleep_save_area@h
377 ori r3, r3, mpc83xx_sleep_save_area@l
378 tophys(r3, r3)
379
380 lwz r5, SS_MEMSAVE+0(r3)
381 lwz r6, SS_MEMSAVE+4(r3)
382
383 stw r5, 0(0)
384 stw r6, 4(0)
385
386 lwz r5, SS_HID+0(r3)
387 lwz r6, SS_HID+4(r3)
388 lwz r7, SS_HID+8(r3)
389
390 mtspr SPRN_HID0, r5
391 mtspr SPRN_HID1, r6
392 mtspr SPRN_HID2, r7
393
394 lwz r4, SS_IABR+0(r3)
395 lwz r5, SS_IABR+4(r3)
396 lwz r6, SS_IBCR(r3)
397 lwz r7, SS_DABR+0(r3)
398 lwz r8, SS_DABR+4(r3)
399 lwz r9, SS_DBCR(r3)
400
401 mtspr SPRN_IABR, r4
402 mtspr SPRN_IABR2, r5
403 mtspr SPRN_IBCR, r6
404 mtspr SPRN_DABR, r7
405 mtspr SPRN_DABR2, r8
406 mtspr SPRN_DBCR, r9
407
408 li r4, 0
409 addi r6, r3, SS_SR-4
4101: lwzu r5, 4(r6)
411 mtsrin r5, r4
412 addis r4, r4, 0x1000
413 cmpwi r4, 0
414 bne 1b
415
416 lwz r4, SS_DBAT+0x00(r3)
417 lwz r5, SS_DBAT+0x04(r3)
418 lwz r6, SS_DBAT+0x08(r3)
419 lwz r7, SS_DBAT+0x0c(r3)
420
421 mtspr SPRN_DBAT0U, r4
422 mtspr SPRN_DBAT0L, r5
423 mtspr SPRN_DBAT1U, r6
424 mtspr SPRN_DBAT1L, r7
425
426 lwz r4, SS_DBAT+0x10(r3)
427 lwz r5, SS_DBAT+0x14(r3)
428 lwz r6, SS_DBAT+0x18(r3)
429 lwz r7, SS_DBAT+0x1c(r3)
430
431 mtspr SPRN_DBAT2U, r4
432 mtspr SPRN_DBAT2L, r5
433 mtspr SPRN_DBAT3U, r6
434 mtspr SPRN_DBAT3L, r7
435
436 lwz r4, SS_DBAT+0x20(r3)
437 lwz r5, SS_DBAT+0x24(r3)
438 lwz r6, SS_DBAT+0x28(r3)
439 lwz r7, SS_DBAT+0x2c(r3)
440
441 mtspr SPRN_DBAT4U, r4
442 mtspr SPRN_DBAT4L, r5
443 mtspr SPRN_DBAT5U, r6
444 mtspr SPRN_DBAT5L, r7
445
446 lwz r4, SS_DBAT+0x30(r3)
447 lwz r5, SS_DBAT+0x34(r3)
448 lwz r6, SS_DBAT+0x38(r3)
449 lwz r7, SS_DBAT+0x3c(r3)
450
451 mtspr SPRN_DBAT6U, r4
452 mtspr SPRN_DBAT6L, r5
453 mtspr SPRN_DBAT7U, r6
454 mtspr SPRN_DBAT7L, r7
455
456 lwz r4, SS_IBAT+0x00(r3)
457 lwz r5, SS_IBAT+0x04(r3)
458 lwz r6, SS_IBAT+0x08(r3)
459 lwz r7, SS_IBAT+0x0c(r3)
460
461 mtspr SPRN_IBAT0U, r4
462 mtspr SPRN_IBAT0L, r5
463 mtspr SPRN_IBAT1U, r6
464 mtspr SPRN_IBAT1L, r7
465
466 lwz r4, SS_IBAT+0x10(r3)
467 lwz r5, SS_IBAT+0x14(r3)
468 lwz r6, SS_IBAT+0x18(r3)
469 lwz r7, SS_IBAT+0x1c(r3)
470
471 mtspr SPRN_IBAT2U, r4
472 mtspr SPRN_IBAT2L, r5
473 mtspr SPRN_IBAT3U, r6
474 mtspr SPRN_IBAT3L, r7
475
476 lwz r4, SS_IBAT+0x20(r3)
477 lwz r5, SS_IBAT+0x24(r3)
478 lwz r6, SS_IBAT+0x28(r3)
479 lwz r7, SS_IBAT+0x2c(r3)
480
481 mtspr SPRN_IBAT4U, r4
482 mtspr SPRN_IBAT4L, r5
483 mtspr SPRN_IBAT5U, r6
484 mtspr SPRN_IBAT5L, r7
485
486 lwz r4, SS_IBAT+0x30(r3)
487 lwz r5, SS_IBAT+0x34(r3)
488 lwz r6, SS_IBAT+0x38(r3)
489 lwz r7, SS_IBAT+0x3c(r3)
490
491 mtspr SPRN_IBAT6U, r4
492 mtspr SPRN_IBAT6L, r5
493 mtspr SPRN_IBAT7U, r6
494 mtspr SPRN_IBAT7L, r7
495
496 lwz r4, SS_SPRG+0(r3)
497 lwz r5, SS_SPRG+4(r3)
498 lwz r6, SS_SPRG+8(r3)
499 lwz r7, SS_SPRG+12(r3)
500 lwz r8, SS_SDR1(r3)
501
502 mtspr SPRN_SPRG0, r4
503 mtspr SPRN_SPRG1, r5
504 mtspr SPRN_SPRG2, r6
505 mtspr SPRN_SPRG3, r7
506 mtsdr1 r8
507
508 lwz r4, SS_MSR(r3)
509 lwz r5, SS_LR(r3)
510 lwz r6, SS_CR(r3)
511 lwz r1, SS_SP(r3)
512 lwz r2, SS_R2(r3)
513
514 mtsrr1 r4
515 mtsrr0 r5
516 mtcr r6
517
518 li r4, 0
519 mtspr SPRN_TBWL, r4
520
521 lwz r4, SS_TB+0(r3)
522 lwz r5, SS_TB+4(r3)
523
524 mtspr SPRN_TBWU, r4
525 mtspr SPRN_TBWL, r5
526
527 lmw r12, SS_GPREG(r3)
528
529 /* Kick decrementer */
530 li r0, 1
531 mtdec r0
532
533 rfi
diff --git a/arch/powerpc/platforms/83xx/suspend.c b/arch/powerpc/platforms/83xx/suspend.c
new file mode 100644
index 000000000000..08e65fc8b98c
--- /dev/null
+++ b/arch/powerpc/platforms/83xx/suspend.c
@@ -0,0 +1,388 @@
1/*
2 * MPC83xx suspend support
3 *
4 * Author: Scott Wood <scottwood@freescale.com>
5 *
6 * Copyright (c) 2006-2007 Freescale Semiconductor, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 */
12
13#include <linux/init.h>
14#include <linux/pm.h>
15#include <linux/types.h>
16#include <linux/ioport.h>
17#include <linux/interrupt.h>
18#include <linux/wait.h>
19#include <linux/kthread.h>
20#include <linux/freezer.h>
21#include <linux/suspend.h>
22#include <linux/fsl_devices.h>
23#include <linux/of_platform.h>
24
25#include <asm/reg.h>
26#include <asm/io.h>
27#include <asm/time.h>
28#include <asm/mpc6xx.h>
29
30#include <sysdev/fsl_soc.h>
31
32#define PMCCR1_NEXT_STATE 0x0C /* Next state for power management */
33#define PMCCR1_NEXT_STATE_SHIFT 2
34#define PMCCR1_CURR_STATE 0x03 /* Current state for power management*/
35#define IMMR_RCW_OFFSET 0x900
36#define RCW_PCI_HOST 0x80000000
37
38void mpc83xx_enter_deep_sleep(phys_addr_t immrbase);
39
40struct mpc83xx_pmc {
41 u32 config;
42#define PMCCR_DLPEN 2 /* DDR SDRAM low power enable */
43#define PMCCR_SLPEN 1 /* System low power enable */
44
45 u32 event;
46 u32 mask;
47/* All but PMCI are deep-sleep only */
48#define PMCER_GPIO 0x100
49#define PMCER_PCI 0x080
50#define PMCER_USB 0x040
51#define PMCER_ETSEC1 0x020
52#define PMCER_ETSEC2 0x010
53#define PMCER_TIMER 0x008
54#define PMCER_INT1 0x004
55#define PMCER_INT2 0x002
56#define PMCER_PMCI 0x001
57#define PMCER_ALL 0x1FF
58
59 /* deep-sleep only */
60 u32 config1;
61#define PMCCR1_USE_STATE 0x80000000
62#define PMCCR1_PME_EN 0x00000080
63#define PMCCR1_ASSERT_PME 0x00000040
64#define PMCCR1_POWER_OFF 0x00000020
65
66 /* deep-sleep only */
67 u32 config2;
68};
69
70struct mpc83xx_rcw {
71 u32 rcwlr;
72 u32 rcwhr;
73};
74
75struct mpc83xx_clock {
76 u32 spmr;
77 u32 occr;
78 u32 sccr;
79};
80
81struct pmc_type {
82 int has_deep_sleep;
83};
84
85static struct of_device *pmc_dev;
86static int has_deep_sleep, deep_sleeping;
87static int pmc_irq;
88static struct mpc83xx_pmc __iomem *pmc_regs;
89static struct mpc83xx_clock __iomem *clock_regs;
90static int is_pci_agent, wake_from_pci;
91static phys_addr_t immrbase;
92static int pci_pm_state;
93static DECLARE_WAIT_QUEUE_HEAD(agent_wq);
94
95int fsl_deep_sleep(void)
96{
97 return deep_sleeping;
98}
99
100static int mpc83xx_change_state(void)
101{
102 u32 curr_state;
103 u32 reg_cfg1 = in_be32(&pmc_regs->config1);
104
105 if (is_pci_agent) {
106 pci_pm_state = (reg_cfg1 & PMCCR1_NEXT_STATE) >>
107 PMCCR1_NEXT_STATE_SHIFT;
108 curr_state = reg_cfg1 & PMCCR1_CURR_STATE;
109
110 if (curr_state != pci_pm_state) {
111 reg_cfg1 &= ~PMCCR1_CURR_STATE;
112 reg_cfg1 |= pci_pm_state;
113 out_be32(&pmc_regs->config1, reg_cfg1);
114
115 wake_up(&agent_wq);
116 return 1;
117 }
118 }
119
120 return 0;
121}
122
123static irqreturn_t pmc_irq_handler(int irq, void *dev_id)
124{
125 u32 event = in_be32(&pmc_regs->event);
126 int ret = IRQ_NONE;
127
128 if (mpc83xx_change_state())
129 ret = IRQ_HANDLED;
130
131 if (event) {
132 out_be32(&pmc_regs->event, event);
133 ret = IRQ_HANDLED;
134 }
135
136 return ret;
137}
138
139static int mpc83xx_suspend_enter(suspend_state_t state)
140{
141 int ret = -EAGAIN;
142
143 /* Don't go to sleep if there's a race where pci_pm_state changes
144 * between the agent thread checking it and the PM code disabling
145 * interrupts.
146 */
147 if (wake_from_pci) {
148 if (pci_pm_state != (deep_sleeping ? 3 : 2))
149 goto out;
150
151 out_be32(&pmc_regs->config1,
152 in_be32(&pmc_regs->config1) | PMCCR1_PME_EN);
153 }
154
155 /* Put the system into low-power mode and the RAM
156 * into self-refresh mode once the core goes to
157 * sleep.
158 */
159
160 out_be32(&pmc_regs->config, PMCCR_SLPEN | PMCCR_DLPEN);
161
162 /* If it has deep sleep (i.e. it's an 831x or compatible),
163 * disable power to the core upon entering sleep mode. This will
164 * require going through the boot firmware upon a wakeup event.
165 */
166
167 if (deep_sleeping) {
168 out_be32(&pmc_regs->mask, PMCER_ALL);
169
170 out_be32(&pmc_regs->config1,
171 in_be32(&pmc_regs->config1) | PMCCR1_POWER_OFF);
172
173 enable_kernel_fp();
174
175 mpc83xx_enter_deep_sleep(immrbase);
176
177 out_be32(&pmc_regs->config1,
178 in_be32(&pmc_regs->config1) & ~PMCCR1_POWER_OFF);
179
180 out_be32(&pmc_regs->mask, PMCER_PMCI);
181 } else {
182 out_be32(&pmc_regs->mask, PMCER_PMCI);
183
184 mpc6xx_enter_standby();
185 }
186
187 ret = 0;
188
189out:
190 out_be32(&pmc_regs->config1,
191 in_be32(&pmc_regs->config1) & ~PMCCR1_PME_EN);
192
193 return ret;
194}
195
196static void mpc83xx_suspend_finish(void)
197{
198 deep_sleeping = 0;
199}
200
201static int mpc83xx_suspend_valid(suspend_state_t state)
202{
203 return state == PM_SUSPEND_STANDBY || state == PM_SUSPEND_MEM;
204}
205
206static int mpc83xx_suspend_begin(suspend_state_t state)
207{
208 switch (state) {
209 case PM_SUSPEND_STANDBY:
210 deep_sleeping = 0;
211 return 0;
212
213 case PM_SUSPEND_MEM:
214 if (has_deep_sleep)
215 deep_sleeping = 1;
216
217 return 0;
218
219 default:
220 return -EINVAL;
221 }
222}
223
224static int agent_thread_fn(void *data)
225{
226 while (1) {
227 wait_event_interruptible(agent_wq, pci_pm_state >= 2);
228 try_to_freeze();
229
230 if (signal_pending(current) || pci_pm_state < 2)
231 continue;
232
233 /* With a preemptible kernel (or SMP), this could race with
234 * a userspace-driven suspend request. It's probably best
235 * to avoid mixing the two with such a configuration (or
236 * else fix it by adding a mutex to state_store that we can
237 * synchronize with).
238 */
239
240 wake_from_pci = 1;
241
242 pm_suspend(pci_pm_state == 3 ? PM_SUSPEND_MEM :
243 PM_SUSPEND_STANDBY);
244
245 wake_from_pci = 0;
246 }
247
248 return 0;
249}
250
251static void mpc83xx_set_agent(void)
252{
253 out_be32(&pmc_regs->config1, PMCCR1_USE_STATE);
254 out_be32(&pmc_regs->mask, PMCER_PMCI);
255
256 kthread_run(agent_thread_fn, NULL, "PCI power mgt");
257}
258
259static int mpc83xx_is_pci_agent(void)
260{
261 struct mpc83xx_rcw __iomem *rcw_regs;
262 int ret;
263
264 rcw_regs = ioremap(get_immrbase() + IMMR_RCW_OFFSET,
265 sizeof(struct mpc83xx_rcw));
266
267 if (!rcw_regs)
268 return -ENOMEM;
269
270 ret = !(in_be32(&rcw_regs->rcwhr) & RCW_PCI_HOST);
271
272 iounmap(rcw_regs);
273 return ret;
274}
275
276static struct platform_suspend_ops mpc83xx_suspend_ops = {
277 .valid = mpc83xx_suspend_valid,
278 .begin = mpc83xx_suspend_begin,
279 .enter = mpc83xx_suspend_enter,
280 .finish = mpc83xx_suspend_finish,
281};
282
283static int pmc_probe(struct of_device *ofdev,
284 const struct of_device_id *match)
285{
286 struct device_node *np = ofdev->node;
287 struct resource res;
288 struct pmc_type *type = match->data;
289 int ret = 0;
290
291 if (!of_device_is_available(np))
292 return -ENODEV;
293
294 has_deep_sleep = type->has_deep_sleep;
295 immrbase = get_immrbase();
296 pmc_dev = ofdev;
297
298 is_pci_agent = mpc83xx_is_pci_agent();
299 if (is_pci_agent < 0)
300 return is_pci_agent;
301
302 ret = of_address_to_resource(np, 0, &res);
303 if (ret)
304 return -ENODEV;
305
306 pmc_irq = irq_of_parse_and_map(np, 0);
307 if (pmc_irq != NO_IRQ) {
308 ret = request_irq(pmc_irq, pmc_irq_handler, IRQF_SHARED,
309 "pmc", ofdev);
310
311 if (ret)
312 return -EBUSY;
313 }
314
315 pmc_regs = ioremap(res.start, sizeof(struct mpc83xx_pmc));
316
317 if (!pmc_regs) {
318 ret = -ENOMEM;
319 goto out;
320 }
321
322 ret = of_address_to_resource(np, 1, &res);
323 if (ret) {
324 ret = -ENODEV;
325 goto out_pmc;
326 }
327
328 clock_regs = ioremap(res.start, sizeof(struct mpc83xx_pmc));
329
330 if (!clock_regs) {
331 ret = -ENOMEM;
332 goto out_pmc;
333 }
334
335 if (is_pci_agent)
336 mpc83xx_set_agent();
337
338 suspend_set_ops(&mpc83xx_suspend_ops);
339 return 0;
340
341out_pmc:
342 iounmap(pmc_regs);
343out:
344 if (pmc_irq != NO_IRQ)
345 free_irq(pmc_irq, ofdev);
346
347 return ret;
348}
349
350static int pmc_remove(struct of_device *ofdev)
351{
352 return -EPERM;
353};
354
355static struct pmc_type pmc_types[] = {
356 {
357 .has_deep_sleep = 1,
358 },
359 {
360 .has_deep_sleep = 0,
361 }
362};
363
364static struct of_device_id pmc_match[] = {
365 {
366 .compatible = "fsl,mpc8313-pmc",
367 .data = &pmc_types[0],
368 },
369 {
370 .compatible = "fsl,mpc8349-pmc",
371 .data = &pmc_types[1],
372 },
373 {}
374};
375
376static struct of_platform_driver pmc_driver = {
377 .name = "mpc83xx-pmc",
378 .match_table = pmc_match,
379 .probe = pmc_probe,
380 .remove = pmc_remove
381};
382
383static int pmc_init(void)
384{
385 return of_register_platform_driver(&pmc_driver);
386}
387
388module_init(pmc_init);
diff --git a/arch/powerpc/platforms/83xx/usb.c b/arch/powerpc/platforms/83xx/usb.c
index 64bcf0a33c71..cc99c280aad9 100644
--- a/arch/powerpc/platforms/83xx/usb.c
+++ b/arch/powerpc/platforms/83xx/usb.c
@@ -137,15 +137,21 @@ int mpc831x_usb_cfg(void)
137 137
138 /* Configure pin mux for ULPI. There is no pin mux for UTMI */ 138 /* Configure pin mux for ULPI. There is no pin mux for UTMI */
139 if (prop && !strcmp(prop, "ulpi")) { 139 if (prop && !strcmp(prop, "ulpi")) {
140 temp = in_be32(immap + MPC83XX_SICRL_OFFS); 140 if (of_device_is_compatible(immr_node, "fsl,mpc8315-immr")) {
141 temp &= ~MPC831X_SICRL_USB_MASK; 141 clrsetbits_be32(immap + MPC83XX_SICRL_OFFS,
142 temp |= MPC831X_SICRL_USB_ULPI; 142 MPC8315_SICRL_USB_MASK,
143 out_be32(immap + MPC83XX_SICRL_OFFS, temp); 143 MPC8315_SICRL_USB_ULPI);
144 144 clrsetbits_be32(immap + MPC83XX_SICRH_OFFS,
145 temp = in_be32(immap + MPC83XX_SICRH_OFFS); 145 MPC8315_SICRH_USB_MASK,
146 temp &= ~MPC831X_SICRH_USB_MASK; 146 MPC8315_SICRH_USB_ULPI);
147 temp |= MPC831X_SICRH_USB_ULPI; 147 } else {
148 out_be32(immap + MPC83XX_SICRH_OFFS, temp); 148 clrsetbits_be32(immap + MPC83XX_SICRL_OFFS,
149 MPC831X_SICRL_USB_MASK,
150 MPC831X_SICRL_USB_ULPI);
151 clrsetbits_be32(immap + MPC83XX_SICRH_OFFS,
152 MPC831X_SICRH_USB_MASK,
153 MPC831X_SICRH_USB_ULPI);
154 }
149 } 155 }
150 156
151 iounmap(immap); 157 iounmap(immap);
diff --git a/arch/powerpc/platforms/85xx/Kconfig b/arch/powerpc/platforms/85xx/Kconfig
index cebea5cadbc1..291675b0097a 100644
--- a/arch/powerpc/platforms/85xx/Kconfig
+++ b/arch/powerpc/platforms/85xx/Kconfig
@@ -2,8 +2,8 @@ menuconfig MPC85xx
2 bool "Machine Type" 2 bool "Machine Type"
3 depends on PPC_85xx 3 depends on PPC_85xx
4 select PPC_UDBG_16550 4 select PPC_UDBG_16550
5 select PPC_INDIRECT_PCI if PCI
6 select MPIC 5 select MPIC
6 select PPC_PCI_CHOICE
7 select FSL_PCI if PCI 7 select FSL_PCI if PCI
8 select SERIAL_8250_SHARE_IRQ if SERIAL_8250 8 select SERIAL_8250_SHARE_IRQ if SERIAL_8250
9 default y 9 default y
@@ -86,7 +86,6 @@ config TQM8548
86 help 86 help
87 This option enables support for the TQ Components TQM8548 board. 87 This option enables support for the TQ Components TQM8548 board.
88 select DEFAULT_UIMAGE 88 select DEFAULT_UIMAGE
89 select PPC_CPM_NEW_BINDING
90 select TQM85xx 89 select TQM85xx
91 90
92config TQM8555 91config TQM8555
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_ds.c b/arch/powerpc/platforms/85xx/mpc85xx_ds.c
index 25f41cd2d33a..00c535806647 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_ds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_ds.c
@@ -115,7 +115,6 @@ void __init mpc85xx_ds_pic_init(void)
115 115
116#ifdef CONFIG_PCI 116#ifdef CONFIG_PCI
117static int primary_phb_addr; 117static int primary_phb_addr;
118extern int uses_fsl_uli_m1575;
119extern int uli_exclude_device(struct pci_controller *hose, 118extern int uli_exclude_device(struct pci_controller *hose,
120 u_char bus, u_char devfn); 119 u_char bus, u_char devfn);
121 120
@@ -161,7 +160,6 @@ static void __init mpc85xx_ds_setup_arch(void)
161 } 160 }
162 } 161 }
163 162
164 uses_fsl_uli_m1575 = 1;
165 ppc_md.pci_exclude_device = mpc85xx_exclude_device; 163 ppc_md.pci_exclude_device = mpc85xx_exclude_device;
166#endif 164#endif
167 165
diff --git a/arch/powerpc/platforms/86xx/Kconfig b/arch/powerpc/platforms/86xx/Kconfig
index 80a81e02bb55..9355a5269431 100644
--- a/arch/powerpc/platforms/86xx/Kconfig
+++ b/arch/powerpc/platforms/86xx/Kconfig
@@ -27,6 +27,7 @@ config SBC8641D
27config MPC8610_HPCD 27config MPC8610_HPCD
28 bool "Freescale MPC8610 HPCD" 28 bool "Freescale MPC8610 HPCD"
29 select DEFAULT_UIMAGE 29 select DEFAULT_UIMAGE
30 select FSL_ULI1575
30 help 31 help
31 This option enables support for the MPC8610 HPCD board. 32 This option enables support for the MPC8610 HPCD board.
32 33
@@ -34,6 +35,7 @@ endif
34 35
35config MPC8641 36config MPC8641
36 bool 37 bool
38 select PPC_PCI_CHOICE
37 select FSL_PCI if PCI 39 select FSL_PCI if PCI
38 select PPC_UDBG_16550 40 select PPC_UDBG_16550
39 select MPIC 41 select MPIC
@@ -41,6 +43,7 @@ config MPC8641
41 43
42config MPC8610 44config MPC8610
43 bool 45 bool
46 select PPC_PCI_CHOICE
44 select FSL_PCI if PCI 47 select FSL_PCI if PCI
45 select PPC_UDBG_16550 48 select PPC_UDBG_16550
46 select MPIC 49 select MPIC
diff --git a/arch/powerpc/platforms/86xx/mpc8610_hpcd.c b/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
index 30725302884a..5eedb710896e 100644
--- a/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
+++ b/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
@@ -58,93 +58,6 @@ static int __init mpc8610_declare_of_platform_devices(void)
58} 58}
59machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices); 59machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
60 60
61#ifdef CONFIG_PCI
62static void __devinit quirk_uli1575(struct pci_dev *dev)
63{
64 u32 temp32;
65
66 /* Disable INTx */
67 pci_read_config_dword(dev, 0x48, &temp32);
68 pci_write_config_dword(dev, 0x48, (temp32 | 1<<26));
69
70 /* Enable sideband interrupt */
71 pci_read_config_dword(dev, 0x90, &temp32);
72 pci_write_config_dword(dev, 0x90, (temp32 | 1<<22));
73}
74
75static void __devinit quirk_uli5288(struct pci_dev *dev)
76{
77 unsigned char c;
78 unsigned short temp;
79
80 /* Interrupt Disable, Needed when SATA disabled */
81 pci_read_config_word(dev, PCI_COMMAND, &temp);
82 temp |= 1<<10;
83 pci_write_config_word(dev, PCI_COMMAND, temp);
84
85 pci_read_config_byte(dev, 0x83, &c);
86 c |= 0x80;
87 pci_write_config_byte(dev, 0x83, c);
88
89 pci_write_config_byte(dev, PCI_CLASS_PROG, 0x01);
90 pci_write_config_byte(dev, PCI_CLASS_DEVICE, 0x06);
91
92 pci_read_config_byte(dev, 0x83, &c);
93 c &= 0x7f;
94 pci_write_config_byte(dev, 0x83, c);
95}
96
97/*
98 * Since 8259PIC was disabled on the board, the IDE device can not
99 * use the legacy IRQ, we need to let the IDE device work under
100 * native mode and use the interrupt line like other PCI devices.
101 * IRQ14 is a sideband interrupt from IDE device to CPU and we use this
102 * as the interrupt for IDE device.
103 */
104static void __devinit quirk_uli5229(struct pci_dev *dev)
105{
106 unsigned char c;
107
108 pci_read_config_byte(dev, 0x4b, &c);
109 c |= 0x10;
110 pci_write_config_byte(dev, 0x4b, c);
111}
112
113/*
114 * SATA interrupt pin bug fix
115 * There's a chip bug for 5288, The interrupt pin should be 2,
116 * not the read only value 1, So it use INTB#, not INTA# which
117 * actually used by the IDE device 5229.
118 * As of this bug, during the PCI initialization, 5288 read the
119 * irq of IDE device from the device tree, this function fix this
120 * bug by re-assigning a correct irq to 5288.
121 *
122 */
123static void __devinit final_uli5288(struct pci_dev *dev)
124{
125 struct pci_controller *hose = pci_bus_to_host(dev->bus);
126 struct device_node *hosenode = hose ? hose->dn : NULL;
127 struct of_irq oirq;
128 int virq, pin = 2;
129 u32 laddr[3];
130
131 if (!hosenode)
132 return;
133
134 laddr[0] = (hose->first_busno << 16) | (PCI_DEVFN(31, 0) << 8);
135 laddr[1] = laddr[2] = 0;
136 of_irq_map_raw(hosenode, &pin, 1, laddr, &oirq);
137 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
138 oirq.size);
139 dev->irq = virq;
140}
141
142DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, quirk_uli1575);
143DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, quirk_uli5288);
144DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
145DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5288, final_uli5288);
146#endif /* CONFIG_PCI */
147
148#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE) 61#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
149 62
150static u32 get_busfreq(void) 63static u32 get_busfreq(void)
diff --git a/arch/powerpc/platforms/86xx/mpc86xx_hpcn.c b/arch/powerpc/platforms/86xx/mpc86xx_hpcn.c
index 7916599c9126..f712d9c0991b 100644
--- a/arch/powerpc/platforms/86xx/mpc86xx_hpcn.c
+++ b/arch/powerpc/platforms/86xx/mpc86xx_hpcn.c
@@ -45,7 +45,6 @@
45#endif 45#endif
46 46
47#ifdef CONFIG_PCI 47#ifdef CONFIG_PCI
48extern int uses_fsl_uli_m1575;
49extern int uli_exclude_device(struct pci_controller *hose, 48extern int uli_exclude_device(struct pci_controller *hose,
50 u_char bus, u_char devfn); 49 u_char bus, u_char devfn);
51 50
@@ -87,7 +86,6 @@ mpc86xx_hpcn_setup_arch(void)
87 fsl_add_bridge(np, 0); 86 fsl_add_bridge(np, 0);
88 } 87 }
89 88
90 uses_fsl_uli_m1575 = 1;
91 ppc_md.pci_exclude_device = mpc86xx_exclude_device; 89 ppc_md.pci_exclude_device = mpc86xx_exclude_device;
92 90
93#endif 91#endif
diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index 690c1f46e698..1d0968775c0a 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -253,17 +253,13 @@ config CPM2
253 depends on MPC85xx || 8260 253 depends on MPC85xx || 8260
254 select CPM 254 select CPM
255 select PPC_LIB_RHEAP 255 select PPC_LIB_RHEAP
256 select PPC_PCI_CHOICE
256 help 257 help
257 The CPM2 (Communications Processor Module) is a coprocessor on 258 The CPM2 (Communications Processor Module) is a coprocessor on
258 embedded CPUs made by Freescale. Selecting this option means that 259 embedded CPUs made by Freescale. Selecting this option means that
259 you wish to build a kernel for a machine with a CPM2 coprocessor 260 you wish to build a kernel for a machine with a CPM2 coprocessor
260 on it (826x, 827x, 8560). 261 on it (826x, 827x, 8560).
261 262
262config PPC_CPM_NEW_BINDING
263 bool
264 depends on CPM1 || CPM2
265 default y
266
267config AXON_RAM 263config AXON_RAM
268 tristate "Axon DDR2 memory device driver" 264 tristate "Axon DDR2 memory device driver"
269 depends on PPC_IBM_CELL_BLADE 265 depends on PPC_IBM_CELL_BLADE
diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
index 5bc4b611ff88..7f6512733862 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -42,12 +42,14 @@ config 40x
42 select PPC_DCR_NATIVE 42 select PPC_DCR_NATIVE
43 select PPC_UDBG_16550 43 select PPC_UDBG_16550
44 select 4xx_SOC 44 select 4xx_SOC
45 select PPC_PCI_CHOICE
45 46
46config 44x 47config 44x
47 bool "AMCC 44x" 48 bool "AMCC 44x"
48 select PPC_DCR_NATIVE 49 select PPC_DCR_NATIVE
49 select PPC_UDBG_16550 50 select PPC_UDBG_16550
50 select 4xx_SOC 51 select 4xx_SOC
52 select PPC_PCI_CHOICE
51 53
52config E200 54config E200
53 bool "Freescale e200" 55 bool "Freescale e200"
@@ -84,9 +86,6 @@ config TUNE_CELL
84 machines. When building a kernel that is supposed to run only 86 machines. When building a kernel that is supposed to run only
85 on Cell, you should also select the POWER4_ONLY option. 87 on Cell, you should also select the POWER4_ONLY option.
86 88
87config 6xx
88 bool
89
90# this is temp to handle compat with arch=ppc 89# this is temp to handle compat with arch=ppc
91config 8xx 90config 8xx
92 bool 91 bool
diff --git a/arch/powerpc/platforms/cell/Kconfig b/arch/powerpc/platforms/cell/Kconfig
index 3959fcfe731c..c14d7d8d96c8 100644
--- a/arch/powerpc/platforms/cell/Kconfig
+++ b/arch/powerpc/platforms/cell/Kconfig
@@ -83,6 +83,22 @@ config CBE_RAS
83 depends on PPC_CELL_NATIVE 83 depends on PPC_CELL_NATIVE
84 default y 84 default y
85 85
86config PPC_IBM_CELL_RESETBUTTON
87 bool "IBM Cell Blade Pinhole reset button"
88 depends on CBE_RAS && PPC_IBM_CELL_BLADE
89 default y
90 help
91 Support Pinhole Resetbutton on IBM Cell blades.
92 This adds a method to trigger system reset via front panel pinhole button.
93
94config PPC_IBM_CELL_POWERBUTTON
95 tristate "IBM Cell Blade power button"
96 depends on PPC_IBM_CELL_BLADE && PPC_PMI && INPUT_EVDEV
97 default y
98 help
99 Support Powerbutton on IBM Cell blades.
100 This will enable the powerbutton as an input device.
101
86config CBE_THERM 102config CBE_THERM
87 tristate "CBE thermal support" 103 tristate "CBE thermal support"
88 default m 104 default m
@@ -107,6 +123,15 @@ config CBE_CPUFREQ_PMI
107 processor will not only be able to run at lower speed, 123 processor will not only be able to run at lower speed,
108 but also at lower core voltage. 124 but also at lower core voltage.
109 125
126config CBE_CPUFREQ_SPU_GOVERNOR
127 tristate "CBE frequency scaling based on SPU usage"
128 depends on SPU_FS && CPU_FREQ
129 default m
130 help
131 This governor checks for spu usage to adjust the cpu frequency.
132 If no spu is running on a given cpu, that cpu will be throttled to
133 the minimal possible frequency.
134
110endmenu 135endmenu
111 136
112config OPROFILE_CELL 137config OPROFILE_CELL
diff --git a/arch/powerpc/platforms/cell/Makefile b/arch/powerpc/platforms/cell/Makefile
index c2a7e4e5ddf9..7fd830872c43 100644
--- a/arch/powerpc/platforms/cell/Makefile
+++ b/arch/powerpc/platforms/cell/Makefile
@@ -8,6 +8,9 @@ obj-$(CONFIG_CBE_THERM) += cbe_thermal.o
8obj-$(CONFIG_CBE_CPUFREQ_PMI) += cbe_cpufreq_pmi.o 8obj-$(CONFIG_CBE_CPUFREQ_PMI) += cbe_cpufreq_pmi.o
9obj-$(CONFIG_CBE_CPUFREQ) += cbe-cpufreq.o 9obj-$(CONFIG_CBE_CPUFREQ) += cbe-cpufreq.o
10cbe-cpufreq-y += cbe_cpufreq_pervasive.o cbe_cpufreq.o 10cbe-cpufreq-y += cbe_cpufreq_pervasive.o cbe_cpufreq.o
11obj-$(CONFIG_CBE_CPUFREQ_SPU_GOVERNOR) += cpufreq_spudemand.o
12
13obj-$(CONFIG_PPC_IBM_CELL_POWERBUTTON) += cbe_powerbutton.o
11 14
12ifeq ($(CONFIG_SMP),y) 15ifeq ($(CONFIG_SMP),y)
13obj-$(CONFIG_PPC_CELL_NATIVE) += smp.o 16obj-$(CONFIG_PPC_CELL_NATIVE) += smp.o
diff --git a/arch/powerpc/platforms/cell/cbe_powerbutton.c b/arch/powerpc/platforms/cell/cbe_powerbutton.c
new file mode 100644
index 000000000000..dcddaa5fcb66
--- /dev/null
+++ b/arch/powerpc/platforms/cell/cbe_powerbutton.c
@@ -0,0 +1,117 @@
1/*
2 * driver for powerbutton on IBM cell blades
3 *
4 * (C) Copyright IBM Corp. 2005-2008
5 *
6 * Author: Christian Krafft <krafft@de.ibm.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/input.h>
24#include <linux/platform_device.h>
25#include <asm/pmi.h>
26#include <asm/prom.h>
27
28static struct input_dev *button_dev;
29static struct platform_device *button_pdev;
30
31static void cbe_powerbutton_handle_pmi(pmi_message_t pmi_msg)
32{
33 BUG_ON(pmi_msg.type != PMI_TYPE_POWER_BUTTON);
34
35 input_report_key(button_dev, KEY_POWER, 1);
36 input_sync(button_dev);
37 input_report_key(button_dev, KEY_POWER, 0);
38 input_sync(button_dev);
39}
40
41static struct pmi_handler cbe_pmi_handler = {
42 .type = PMI_TYPE_POWER_BUTTON,
43 .handle_pmi_message = cbe_powerbutton_handle_pmi,
44};
45
46static int __init cbe_powerbutton_init(void)
47{
48 int ret = 0;
49 struct input_dev *dev;
50
51 if (!machine_is_compatible("IBM,CBPLUS-1.0")) {
52 printk(KERN_ERR "%s: Not a cell blade.\n", __func__);
53 ret = -ENODEV;
54 goto out;
55 }
56
57 dev = input_allocate_device();
58 if (!dev) {
59 ret = -ENOMEM;
60 printk(KERN_ERR "%s: Not enough memory.\n", __func__);
61 goto out;
62 }
63
64 set_bit(EV_KEY, dev->evbit);
65 set_bit(KEY_POWER, dev->keybit);
66
67 dev->name = "Power Button";
68 dev->id.bustype = BUS_HOST;
69
70 /* this makes the button look like an acpi power button
71 * no clue whether anyone relies on that though */
72 dev->id.product = 0x02;
73 dev->phys = "LNXPWRBN/button/input0";
74
75 button_pdev = platform_device_register_simple("power_button", 0, NULL, 0);
76 if (IS_ERR(button_pdev)) {
77 ret = PTR_ERR(button_pdev);
78 goto out_free_input;
79 }
80
81 dev->dev.parent = &button_pdev->dev;
82 ret = input_register_device(dev);
83 if (ret) {
84 printk(KERN_ERR "%s: Failed to register device\n", __func__);
85 goto out_free_pdev;
86 }
87
88 button_dev = dev;
89
90 ret = pmi_register_handler(&cbe_pmi_handler);
91 if (ret) {
92 printk(KERN_ERR "%s: Failed to register with pmi.\n", __func__);
93 goto out_free_pdev;
94 }
95
96 goto out;
97
98out_free_pdev:
99 platform_device_unregister(button_pdev);
100out_free_input:
101 input_free_device(dev);
102out:
103 return ret;
104}
105
106static void __exit cbe_powerbutton_exit(void)
107{
108 pmi_unregister_handler(&cbe_pmi_handler);
109 platform_device_unregister(button_pdev);
110 input_free_device(button_dev);
111}
112
113module_init(cbe_powerbutton_init);
114module_exit(cbe_powerbutton_exit);
115
116MODULE_LICENSE("GPL");
117MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");
diff --git a/arch/powerpc/platforms/cell/cbe_thermal.c b/arch/powerpc/platforms/cell/cbe_thermal.c
index 4852bf312d83..4d4c8c169124 100644
--- a/arch/powerpc/platforms/cell/cbe_thermal.c
+++ b/arch/powerpc/platforms/cell/cbe_thermal.c
@@ -97,7 +97,8 @@ static u8 spu_read_register_value(struct sys_device *sysdev, union spe_reg __iom
97 return value.spe[spu->spe_id]; 97 return value.spe[spu->spe_id];
98} 98}
99 99
100static ssize_t spu_show_temp(struct sys_device *sysdev, char *buf) 100static ssize_t spu_show_temp(struct sys_device *sysdev, struct sysdev_attribute *attr,
101 char *buf)
101{ 102{
102 u8 value; 103 u8 value;
103 struct cbe_pmd_regs __iomem *pmd_regs; 104 struct cbe_pmd_regs __iomem *pmd_regs;
@@ -146,32 +147,38 @@ static ssize_t store_throttle(struct cbe_pmd_regs __iomem *pmd_regs, const char
146 return size; 147 return size;
147} 148}
148 149
149static ssize_t spu_show_throttle_end(struct sys_device *sysdev, char *buf) 150static ssize_t spu_show_throttle_end(struct sys_device *sysdev,
151 struct sysdev_attribute *attr, char *buf)
150{ 152{
151 return show_throttle(get_pmd_regs(sysdev), buf, 0); 153 return show_throttle(get_pmd_regs(sysdev), buf, 0);
152} 154}
153 155
154static ssize_t spu_show_throttle_begin(struct sys_device *sysdev, char *buf) 156static ssize_t spu_show_throttle_begin(struct sys_device *sysdev,
157 struct sysdev_attribute *attr, char *buf)
155{ 158{
156 return show_throttle(get_pmd_regs(sysdev), buf, 8); 159 return show_throttle(get_pmd_regs(sysdev), buf, 8);
157} 160}
158 161
159static ssize_t spu_show_throttle_full_stop(struct sys_device *sysdev, char *buf) 162static ssize_t spu_show_throttle_full_stop(struct sys_device *sysdev,
163 struct sysdev_attribute *attr, char *buf)
160{ 164{
161 return show_throttle(get_pmd_regs(sysdev), buf, 16); 165 return show_throttle(get_pmd_regs(sysdev), buf, 16);
162} 166}
163 167
164static ssize_t spu_store_throttle_end(struct sys_device *sysdev, const char *buf, size_t size) 168static ssize_t spu_store_throttle_end(struct sys_device *sysdev,
169 struct sysdev_attribute *attr, const char *buf, size_t size)
165{ 170{
166 return store_throttle(get_pmd_regs(sysdev), buf, size, 0); 171 return store_throttle(get_pmd_regs(sysdev), buf, size, 0);
167} 172}
168 173
169static ssize_t spu_store_throttle_begin(struct sys_device *sysdev, const char *buf, size_t size) 174static ssize_t spu_store_throttle_begin(struct sys_device *sysdev,
175 struct sysdev_attribute *attr, const char *buf, size_t size)
170{ 176{
171 return store_throttle(get_pmd_regs(sysdev), buf, size, 8); 177 return store_throttle(get_pmd_regs(sysdev), buf, size, 8);
172} 178}
173 179
174static ssize_t spu_store_throttle_full_stop(struct sys_device *sysdev, const char *buf, size_t size) 180static ssize_t spu_store_throttle_full_stop(struct sys_device *sysdev,
181 struct sysdev_attribute *attr, const char *buf, size_t size)
175{ 182{
176 return store_throttle(get_pmd_regs(sysdev), buf, size, 16); 183 return store_throttle(get_pmd_regs(sysdev), buf, size, 16);
177} 184}
@@ -192,43 +199,51 @@ static ssize_t ppe_show_temp(struct sys_device *sysdev, char *buf, int pos)
192 199
193/* shows the temperature of the DTS on the PPE, 200/* shows the temperature of the DTS on the PPE,
194 * located near the linear thermal sensor */ 201 * located near the linear thermal sensor */
195static ssize_t ppe_show_temp0(struct sys_device *sysdev, char *buf) 202static ssize_t ppe_show_temp0(struct sys_device *sysdev,
203 struct sysdev_attribute *attr, char *buf)
196{ 204{
197 return ppe_show_temp(sysdev, buf, 32); 205 return ppe_show_temp(sysdev, buf, 32);
198} 206}
199 207
200/* shows the temperature of the second DTS on the PPE */ 208/* shows the temperature of the second DTS on the PPE */
201static ssize_t ppe_show_temp1(struct sys_device *sysdev, char *buf) 209static ssize_t ppe_show_temp1(struct sys_device *sysdev,
210 struct sysdev_attribute *attr, char *buf)
202{ 211{
203 return ppe_show_temp(sysdev, buf, 0); 212 return ppe_show_temp(sysdev, buf, 0);
204} 213}
205 214
206static ssize_t ppe_show_throttle_end(struct sys_device *sysdev, char *buf) 215static ssize_t ppe_show_throttle_end(struct sys_device *sysdev,
216 struct sysdev_attribute *attr, char *buf)
207{ 217{
208 return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 32); 218 return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 32);
209} 219}
210 220
211static ssize_t ppe_show_throttle_begin(struct sys_device *sysdev, char *buf) 221static ssize_t ppe_show_throttle_begin(struct sys_device *sysdev,
222 struct sysdev_attribute *attr, char *buf)
212{ 223{
213 return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 40); 224 return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 40);
214} 225}
215 226
216static ssize_t ppe_show_throttle_full_stop(struct sys_device *sysdev, char *buf) 227static ssize_t ppe_show_throttle_full_stop(struct sys_device *sysdev,
228 struct sysdev_attribute *attr, char *buf)
217{ 229{
218 return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 48); 230 return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 48);
219} 231}
220 232
221static ssize_t ppe_store_throttle_end(struct sys_device *sysdev, const char *buf, size_t size) 233static ssize_t ppe_store_throttle_end(struct sys_device *sysdev,
234 struct sysdev_attribute *attr, const char *buf, size_t size)
222{ 235{
223 return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 32); 236 return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 32);
224} 237}
225 238
226static ssize_t ppe_store_throttle_begin(struct sys_device *sysdev, const char *buf, size_t size) 239static ssize_t ppe_store_throttle_begin(struct sys_device *sysdev,
240 struct sysdev_attribute *attr, const char *buf, size_t size)
227{ 241{
228 return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 40); 242 return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 40);
229} 243}
230 244
231static ssize_t ppe_store_throttle_full_stop(struct sys_device *sysdev, const char *buf, size_t size) 245static ssize_t ppe_store_throttle_full_stop(struct sys_device *sysdev,
246 struct sysdev_attribute *attr, const char *buf, size_t size)
232{ 247{
233 return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 48); 248 return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 48);
234} 249}
diff --git a/arch/powerpc/platforms/cell/cpufreq_spudemand.c b/arch/powerpc/platforms/cell/cpufreq_spudemand.c
new file mode 100644
index 000000000000..a3c6c01bd6db
--- /dev/null
+++ b/arch/powerpc/platforms/cell/cpufreq_spudemand.c
@@ -0,0 +1,184 @@
1/*
2 * spu aware cpufreq governor for the cell processor
3 *
4 * © Copyright IBM Corporation 2006-2008
5 *
6 * Author: Christian Krafft <krafft@de.ibm.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/cpufreq.h>
24#include <linux/sched.h>
25#include <linux/timer.h>
26#include <linux/workqueue.h>
27#include <asm/atomic.h>
28#include <asm/machdep.h>
29#include <asm/spu.h>
30
31#define POLL_TIME 100000 /* in µs */
32#define EXP 753 /* exp(-1) in fixed-point */
33
34struct spu_gov_info_struct {
35 unsigned long busy_spus; /* fixed-point */
36 struct cpufreq_policy *policy;
37 struct delayed_work work;
38 unsigned int poll_int; /* µs */
39};
40static DEFINE_PER_CPU(struct spu_gov_info_struct, spu_gov_info);
41
42static struct workqueue_struct *kspugov_wq;
43
44static int calc_freq(struct spu_gov_info_struct *info)
45{
46 int cpu;
47 int busy_spus;
48
49 cpu = info->policy->cpu;
50 busy_spus = atomic_read(&cbe_spu_info[cpu_to_node(cpu)].busy_spus);
51
52 CALC_LOAD(info->busy_spus, EXP, busy_spus * FIXED_1);
53 pr_debug("cpu %d: busy_spus=%d, info->busy_spus=%ld\n",
54 cpu, busy_spus, info->busy_spus);
55
56 return info->policy->max * info->busy_spus / FIXED_1;
57}
58
59static void spu_gov_work(struct work_struct *work)
60{
61 struct spu_gov_info_struct *info;
62 int delay;
63 unsigned long target_freq;
64
65 info = container_of(work, struct spu_gov_info_struct, work.work);
66
67 /* after cancel_delayed_work_sync we unset info->policy */
68 BUG_ON(info->policy == NULL);
69
70 target_freq = calc_freq(info);
71 __cpufreq_driver_target(info->policy, target_freq, CPUFREQ_RELATION_H);
72
73 delay = usecs_to_jiffies(info->poll_int);
74 queue_delayed_work_on(info->policy->cpu, kspugov_wq, &info->work, delay);
75}
76
77static void spu_gov_init_work(struct spu_gov_info_struct *info)
78{
79 int delay = usecs_to_jiffies(info->poll_int);
80 INIT_DELAYED_WORK_DEFERRABLE(&info->work, spu_gov_work);
81 queue_delayed_work_on(info->policy->cpu, kspugov_wq, &info->work, delay);
82}
83
84static void spu_gov_cancel_work(struct spu_gov_info_struct *info)
85{
86 cancel_delayed_work_sync(&info->work);
87}
88
89static int spu_gov_govern(struct cpufreq_policy *policy, unsigned int event)
90{
91 unsigned int cpu = policy->cpu;
92 struct spu_gov_info_struct *info, *affected_info;
93 int i;
94 int ret = 0;
95
96 info = &per_cpu(spu_gov_info, cpu);
97
98 switch (event) {
99 case CPUFREQ_GOV_START:
100 if (!cpu_online(cpu)) {
101 printk(KERN_ERR "cpu %d is not online\n", cpu);
102 ret = -EINVAL;
103 break;
104 }
105
106 if (!policy->cur) {
107 printk(KERN_ERR "no cpu specified in policy\n");
108 ret = -EINVAL;
109 break;
110 }
111
112 /* initialize spu_gov_info for all affected cpus */
113 for_each_cpu_mask(i, policy->cpus) {
114 affected_info = &per_cpu(spu_gov_info, i);
115 affected_info->policy = policy;
116 }
117
118 info->poll_int = POLL_TIME;
119
120 /* setup timer */
121 spu_gov_init_work(info);
122
123 break;
124
125 case CPUFREQ_GOV_STOP:
126 /* cancel timer */
127 spu_gov_cancel_work(info);
128
129 /* clean spu_gov_info for all affected cpus */
130 for_each_cpu_mask (i, policy->cpus) {
131 info = &per_cpu(spu_gov_info, i);
132 info->policy = NULL;
133 }
134
135 break;
136 }
137
138 return ret;
139}
140
141static struct cpufreq_governor spu_governor = {
142 .name = "spudemand",
143 .governor = spu_gov_govern,
144 .owner = THIS_MODULE,
145};
146
147/*
148 * module init and destoy
149 */
150
151static int __init spu_gov_init(void)
152{
153 int ret;
154
155 kspugov_wq = create_workqueue("kspugov");
156 if (!kspugov_wq) {
157 printk(KERN_ERR "creation of kspugov failed\n");
158 ret = -EFAULT;
159 goto out;
160 }
161
162 ret = cpufreq_register_governor(&spu_governor);
163 if (ret) {
164 printk(KERN_ERR "registration of governor failed\n");
165 destroy_workqueue(kspugov_wq);
166 goto out;
167 }
168out:
169 return ret;
170}
171
172static void __exit spu_gov_exit(void)
173{
174 cpufreq_unregister_governor(&spu_governor);
175 destroy_workqueue(kspugov_wq);
176}
177
178
179module_init(spu_gov_init);
180module_exit(spu_gov_exit);
181
182MODULE_LICENSE("GPL");
183MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");
184
diff --git a/arch/powerpc/platforms/cell/iommu.c b/arch/powerpc/platforms/cell/iommu.c
index eeacb3a52ca1..208005ca262c 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -173,7 +173,8 @@ static void invalidate_tce_cache(struct cbe_iommu *iommu, unsigned long *pte,
173} 173}
174 174
175static void tce_build_cell(struct iommu_table *tbl, long index, long npages, 175static void tce_build_cell(struct iommu_table *tbl, long index, long npages,
176 unsigned long uaddr, enum dma_data_direction direction) 176 unsigned long uaddr, enum dma_data_direction direction,
177 struct dma_attrs *attrs)
177{ 178{
178 int i; 179 int i;
179 unsigned long *io_pte, base_pte; 180 unsigned long *io_pte, base_pte;
@@ -198,6 +199,8 @@ static void tce_build_cell(struct iommu_table *tbl, long index, long npages,
198 base_pte = IOPTE_PP_W | IOPTE_PP_R | IOPTE_M | IOPTE_SO_RW | 199 base_pte = IOPTE_PP_W | IOPTE_PP_R | IOPTE_M | IOPTE_SO_RW |
199 (window->ioid & IOPTE_IOID_Mask); 200 (window->ioid & IOPTE_IOID_Mask);
200#endif 201#endif
202 if (unlikely(dma_get_attr(DMA_ATTR_WEAK_ORDERING, attrs)))
203 base_pte &= ~IOPTE_SO_RW;
201 204
202 io_pte = (unsigned long *)tbl->it_base + (index - tbl->it_offset); 205 io_pte = (unsigned long *)tbl->it_base + (index - tbl->it_offset);
203 206
@@ -519,7 +522,7 @@ cell_iommu_setup_window(struct cbe_iommu *iommu, struct device_node *np,
519 522
520 __set_bit(0, window->table.it_map); 523 __set_bit(0, window->table.it_map);
521 tce_build_cell(&window->table, window->table.it_offset, 1, 524 tce_build_cell(&window->table, window->table.it_offset, 1,
522 (unsigned long)iommu->pad_page, DMA_TO_DEVICE); 525 (unsigned long)iommu->pad_page, DMA_TO_DEVICE, NULL);
523 window->table.it_hint = window->table.it_blocksize; 526 window->table.it_hint = window->table.it_blocksize;
524 527
525 return window; 528 return window;
@@ -538,7 +541,9 @@ static struct cbe_iommu *cell_iommu_for_node(int nid)
538static unsigned long cell_dma_direct_offset; 541static unsigned long cell_dma_direct_offset;
539 542
540static unsigned long dma_iommu_fixed_base; 543static unsigned long dma_iommu_fixed_base;
541struct dma_mapping_ops dma_iommu_fixed_ops; 544
545/* iommu_fixed_is_weak is set if booted with iommu_fixed=weak */
546static int iommu_fixed_is_weak;
542 547
543static struct iommu_table *cell_get_iommu_table(struct device *dev) 548static struct iommu_table *cell_get_iommu_table(struct device *dev)
544{ 549{
@@ -562,6 +567,98 @@ static struct iommu_table *cell_get_iommu_table(struct device *dev)
562 return &window->table; 567 return &window->table;
563} 568}
564 569
570/* A coherent allocation implies strong ordering */
571
572static void *dma_fixed_alloc_coherent(struct device *dev, size_t size,
573 dma_addr_t *dma_handle, gfp_t flag)
574{
575 if (iommu_fixed_is_weak)
576 return iommu_alloc_coherent(dev, cell_get_iommu_table(dev),
577 size, dma_handle,
578 device_to_mask(dev), flag,
579 dev->archdata.numa_node);
580 else
581 return dma_direct_ops.alloc_coherent(dev, size, dma_handle,
582 flag);
583}
584
585static void dma_fixed_free_coherent(struct device *dev, size_t size,
586 void *vaddr, dma_addr_t dma_handle)
587{
588 if (iommu_fixed_is_weak)
589 iommu_free_coherent(cell_get_iommu_table(dev), size, vaddr,
590 dma_handle);
591 else
592 dma_direct_ops.free_coherent(dev, size, vaddr, dma_handle);
593}
594
595static dma_addr_t dma_fixed_map_single(struct device *dev, void *ptr,
596 size_t size,
597 enum dma_data_direction direction,
598 struct dma_attrs *attrs)
599{
600 if (iommu_fixed_is_weak == dma_get_attr(DMA_ATTR_WEAK_ORDERING, attrs))
601 return dma_direct_ops.map_single(dev, ptr, size, direction,
602 attrs);
603 else
604 return iommu_map_single(dev, cell_get_iommu_table(dev), ptr,
605 size, device_to_mask(dev), direction,
606 attrs);
607}
608
609static void dma_fixed_unmap_single(struct device *dev, dma_addr_t dma_addr,
610 size_t size,
611 enum dma_data_direction direction,
612 struct dma_attrs *attrs)
613{
614 if (iommu_fixed_is_weak == dma_get_attr(DMA_ATTR_WEAK_ORDERING, attrs))
615 dma_direct_ops.unmap_single(dev, dma_addr, size, direction,
616 attrs);
617 else
618 iommu_unmap_single(cell_get_iommu_table(dev), dma_addr, size,
619 direction, attrs);
620}
621
622static int dma_fixed_map_sg(struct device *dev, struct scatterlist *sg,
623 int nents, enum dma_data_direction direction,
624 struct dma_attrs *attrs)
625{
626 if (iommu_fixed_is_weak == dma_get_attr(DMA_ATTR_WEAK_ORDERING, attrs))
627 return dma_direct_ops.map_sg(dev, sg, nents, direction, attrs);
628 else
629 return iommu_map_sg(dev, cell_get_iommu_table(dev), sg, nents,
630 device_to_mask(dev), direction, attrs);
631}
632
633static void dma_fixed_unmap_sg(struct device *dev, struct scatterlist *sg,
634 int nents, enum dma_data_direction direction,
635 struct dma_attrs *attrs)
636{
637 if (iommu_fixed_is_weak == dma_get_attr(DMA_ATTR_WEAK_ORDERING, attrs))
638 dma_direct_ops.unmap_sg(dev, sg, nents, direction, attrs);
639 else
640 iommu_unmap_sg(cell_get_iommu_table(dev), sg, nents, direction,
641 attrs);
642}
643
644static int dma_fixed_dma_supported(struct device *dev, u64 mask)
645{
646 return mask == DMA_64BIT_MASK;
647}
648
649static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
650
651struct dma_mapping_ops dma_iommu_fixed_ops = {
652 .alloc_coherent = dma_fixed_alloc_coherent,
653 .free_coherent = dma_fixed_free_coherent,
654 .map_single = dma_fixed_map_single,
655 .unmap_single = dma_fixed_unmap_single,
656 .map_sg = dma_fixed_map_sg,
657 .unmap_sg = dma_fixed_unmap_sg,
658 .dma_supported = dma_fixed_dma_supported,
659 .set_dma_mask = dma_set_mask_and_switch,
660};
661
565static void cell_dma_dev_setup_fixed(struct device *dev); 662static void cell_dma_dev_setup_fixed(struct device *dev);
566 663
567static void cell_dma_dev_setup(struct device *dev) 664static void cell_dma_dev_setup(struct device *dev)
@@ -918,9 +1015,16 @@ static void cell_iommu_setup_fixed_ptab(struct cbe_iommu *iommu,
918 1015
919 pr_debug("iommu: mapping 0x%lx pages from 0x%lx\n", fsize, fbase); 1016 pr_debug("iommu: mapping 0x%lx pages from 0x%lx\n", fsize, fbase);
920 1017
921 base_pte = IOPTE_PP_W | IOPTE_PP_R | IOPTE_M | IOPTE_SO_RW 1018 base_pte = IOPTE_PP_W | IOPTE_PP_R | IOPTE_M
922 | (cell_iommu_get_ioid(np) & IOPTE_IOID_Mask); 1019 | (cell_iommu_get_ioid(np) & IOPTE_IOID_Mask);
923 1020
1021 if (iommu_fixed_is_weak)
1022 pr_info("IOMMU: Using weak ordering for fixed mapping\n");
1023 else {
1024 pr_info("IOMMU: Using strong ordering for fixed mapping\n");
1025 base_pte |= IOPTE_SO_RW;
1026 }
1027
924 for (uaddr = 0; uaddr < fsize; uaddr += (1 << 24)) { 1028 for (uaddr = 0; uaddr < fsize; uaddr += (1 << 24)) {
925 /* Don't touch the dynamic region */ 1029 /* Don't touch the dynamic region */
926 ioaddr = uaddr + fbase; 1030 ioaddr = uaddr + fbase;
@@ -1036,9 +1140,6 @@ static int __init cell_iommu_fixed_mapping_init(void)
1036 cell_iommu_setup_window(iommu, np, dbase, dsize, 0); 1140 cell_iommu_setup_window(iommu, np, dbase, dsize, 0);
1037 } 1141 }
1038 1142
1039 dma_iommu_fixed_ops = dma_direct_ops;
1040 dma_iommu_fixed_ops.set_dma_mask = dma_set_mask_and_switch;
1041
1042 dma_iommu_ops.set_dma_mask = dma_set_mask_and_switch; 1143 dma_iommu_ops.set_dma_mask = dma_set_mask_and_switch;
1043 set_pci_dma_ops(&dma_iommu_ops); 1144 set_pci_dma_ops(&dma_iommu_ops);
1044 1145
@@ -1052,6 +1153,9 @@ static int __init setup_iommu_fixed(char *str)
1052 if (strcmp(str, "off") == 0) 1153 if (strcmp(str, "off") == 0)
1053 iommu_fixed_disabled = 1; 1154 iommu_fixed_disabled = 1;
1054 1155
1156 else if (strcmp(str, "weak") == 0)
1157 iommu_fixed_is_weak = 1;
1158
1055 return 1; 1159 return 1;
1056} 1160}
1057__setup("iommu_fixed=", setup_iommu_fixed); 1161__setup("iommu_fixed=", setup_iommu_fixed);
diff --git a/arch/powerpc/platforms/cell/pervasive.c b/arch/powerpc/platforms/cell/pervasive.c
index 8a3631ce912b..efdacc829576 100644
--- a/arch/powerpc/platforms/cell/pervasive.c
+++ b/arch/powerpc/platforms/cell/pervasive.c
@@ -38,8 +38,6 @@
38 38
39#include "pervasive.h" 39#include "pervasive.h"
40 40
41static int sysreset_hack;
42
43static void cbe_power_save(void) 41static void cbe_power_save(void)
44{ 42{
45 unsigned long ctrl, thread_switch_control; 43 unsigned long ctrl, thread_switch_control;
@@ -87,9 +85,6 @@ static void cbe_power_save(void)
87 85
88static int cbe_system_reset_exception(struct pt_regs *regs) 86static int cbe_system_reset_exception(struct pt_regs *regs)
89{ 87{
90 int cpu;
91 struct cbe_pmd_regs __iomem *pmd;
92
93 switch (regs->msr & SRR1_WAKEMASK) { 88 switch (regs->msr & SRR1_WAKEMASK) {
94 case SRR1_WAKEEE: 89 case SRR1_WAKEEE:
95 do_IRQ(regs); 90 do_IRQ(regs);
@@ -98,19 +93,7 @@ static int cbe_system_reset_exception(struct pt_regs *regs)
98 timer_interrupt(regs); 93 timer_interrupt(regs);
99 break; 94 break;
100 case SRR1_WAKEMT: 95 case SRR1_WAKEMT:
101 /* 96 return cbe_sysreset_hack();
102 * The BMC can inject user triggered system reset exceptions,
103 * but cannot set the system reset reason in srr1,
104 * so check an extra register here.
105 */
106 if (sysreset_hack && (cpu = smp_processor_id()) == 0) {
107 pmd = cbe_get_cpu_pmd_regs(cpu);
108 if (in_be64(&pmd->ras_esc_0) & 0xffff) {
109 out_be64(&pmd->ras_esc_0, 0);
110 return 0;
111 }
112 }
113 break;
114#ifdef CONFIG_CBE_RAS 97#ifdef CONFIG_CBE_RAS
115 case SRR1_WAKESYSERR: 98 case SRR1_WAKESYSERR:
116 cbe_system_error_exception(regs); 99 cbe_system_error_exception(regs);
@@ -134,8 +117,6 @@ void __init cbe_pervasive_init(void)
134 if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO)) 117 if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO))
135 return; 118 return;
136 119
137 sysreset_hack = machine_is_compatible("IBM,CBPLUS-1.0");
138
139 for_each_possible_cpu(cpu) { 120 for_each_possible_cpu(cpu) {
140 struct cbe_pmd_regs __iomem *regs = cbe_get_cpu_pmd_regs(cpu); 121 struct cbe_pmd_regs __iomem *regs = cbe_get_cpu_pmd_regs(cpu);
141 if (!regs) 122 if (!regs)
@@ -144,12 +125,6 @@ void __init cbe_pervasive_init(void)
144 /* Enable Pause(0) control bit */ 125 /* Enable Pause(0) control bit */
145 out_be64(&regs->pmcr, in_be64(&regs->pmcr) | 126 out_be64(&regs->pmcr, in_be64(&regs->pmcr) |
146 CBE_PMD_PAUSE_ZERO_CONTROL); 127 CBE_PMD_PAUSE_ZERO_CONTROL);
147
148 /* Enable JTAG system-reset hack */
149 if (sysreset_hack)
150 out_be32(&regs->fir_mode_reg,
151 in_be32(&regs->fir_mode_reg) |
152 CBE_PMD_FIR_MODE_M8);
153 } 128 }
154 129
155 ppc_md.power_save = cbe_power_save; 130 ppc_md.power_save = cbe_power_save;
diff --git a/arch/powerpc/platforms/cell/pervasive.h b/arch/powerpc/platforms/cell/pervasive.h
index 7b50947f8044..fd4d7b7092b4 100644
--- a/arch/powerpc/platforms/cell/pervasive.h
+++ b/arch/powerpc/platforms/cell/pervasive.h
@@ -30,4 +30,13 @@ extern void cbe_system_error_exception(struct pt_regs *regs);
30extern void cbe_maintenance_exception(struct pt_regs *regs); 30extern void cbe_maintenance_exception(struct pt_regs *regs);
31extern void cbe_thermal_exception(struct pt_regs *regs); 31extern void cbe_thermal_exception(struct pt_regs *regs);
32 32
33#ifdef CONFIG_PPC_IBM_CELL_RESETBUTTON
34extern int cbe_sysreset_hack(void);
35#else
36static inline int cbe_sysreset_hack(void)
37{
38 return 1;
39}
40#endif /* CONFIG_PPC_IBM_CELL_RESETBUTTON */
41
33#endif 42#endif
diff --git a/arch/powerpc/platforms/cell/ras.c b/arch/powerpc/platforms/cell/ras.c
index 505f9b9bdf0c..2a14b052abcd 100644
--- a/arch/powerpc/platforms/cell/ras.c
+++ b/arch/powerpc/platforms/cell/ras.c
@@ -236,6 +236,52 @@ static struct notifier_block cbe_ptcal_reboot_notifier = {
236 .notifier_call = cbe_ptcal_notify_reboot 236 .notifier_call = cbe_ptcal_notify_reboot
237}; 237};
238 238
239#ifdef CONFIG_PPC_IBM_CELL_RESETBUTTON
240static int sysreset_hack;
241
242static int __init cbe_sysreset_init(void)
243{
244 struct cbe_pmd_regs __iomem *regs;
245
246 sysreset_hack = machine_is_compatible("IBM,CBPLUS-1.0");
247 if (!sysreset_hack)
248 return 0;
249
250 regs = cbe_get_cpu_pmd_regs(0);
251 if (!regs)
252 return 0;
253
254 /* Enable JTAG system-reset hack */
255 out_be32(&regs->fir_mode_reg,
256 in_be32(&regs->fir_mode_reg) |
257 CBE_PMD_FIR_MODE_M8);
258
259 return 0;
260}
261device_initcall(cbe_sysreset_init);
262
263int cbe_sysreset_hack(void)
264{
265 struct cbe_pmd_regs __iomem *regs;
266
267 /*
268 * The BMC can inject user triggered system reset exceptions,
269 * but cannot set the system reset reason in srr1,
270 * so check an extra register here.
271 */
272 if (sysreset_hack && (smp_processor_id() == 0)) {
273 regs = cbe_get_cpu_pmd_regs(0);
274 if (!regs)
275 return 0;
276 if (in_be64(&regs->ras_esc_0) & 0x0000ffff) {
277 out_be64(&regs->ras_esc_0, 0);
278 return 0;
279 }
280 }
281 return 1;
282}
283#endif /* CONFIG_PPC_IBM_CELL_RESETBUTTON */
284
239int __init cbe_ptcal_init(void) 285int __init cbe_ptcal_init(void)
240{ 286{
241 int ret; 287 int ret;
diff --git a/arch/powerpc/platforms/cell/spu_base.c b/arch/powerpc/platforms/cell/spu_base.c
index 78f905bc6a42..a5bdb89a17c3 100644
--- a/arch/powerpc/platforms/cell/spu_base.c
+++ b/arch/powerpc/platforms/cell/spu_base.c
@@ -703,7 +703,8 @@ static unsigned long long spu_acct_time(struct spu *spu,
703} 703}
704 704
705 705
706static ssize_t spu_stat_show(struct sys_device *sysdev, char *buf) 706static ssize_t spu_stat_show(struct sys_device *sysdev,
707 struct sysdev_attribute *attr, char *buf)
707{ 708{
708 struct spu *spu = container_of(sysdev, struct spu, sysdev); 709 struct spu *spu = container_of(sysdev, struct spu, sysdev);
709 710
diff --git a/arch/powerpc/platforms/chrp/pci.c b/arch/powerpc/platforms/chrp/pci.c
index 609c46db4a1b..768c262b9368 100644
--- a/arch/powerpc/platforms/chrp/pci.c
+++ b/arch/powerpc/platforms/chrp/pci.c
@@ -367,7 +367,7 @@ static void chrp_pci_fixup_vt8231_ata(struct pci_dev *viaide)
367 viaisa = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, NULL); 367 viaisa = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, NULL);
368 if (!viaisa) 368 if (!viaisa)
369 return; 369 return;
370 printk("Fixing VIA IDE, force legacy mode on '%s'\n", viaide->dev.bus_id); 370 dev_info(&viaide->dev, "Fixing VIA IDE, force legacy mode on\n");
371 371
372 pci_read_config_byte(viaide, PCI_CLASS_PROG, &progif); 372 pci_read_config_byte(viaide, PCI_CLASS_PROG, &progif);
373 pci_write_config_byte(viaide, PCI_CLASS_PROG, progif & ~0x5); 373 pci_write_config_byte(viaide, PCI_CLASS_PROG, progif & ~0x5);
diff --git a/arch/powerpc/platforms/fsl_uli1575.c b/arch/powerpc/platforms/fsl_uli1575.c
index afc9141be63e..ef74a0763ec1 100644
--- a/arch/powerpc/platforms/fsl_uli1575.c
+++ b/arch/powerpc/platforms/fsl_uli1575.c
@@ -51,15 +51,13 @@ u8 uli_pirq_to_irq[8] = {
51 ULI_8259_NONE, /* PIRQH */ 51 ULI_8259_NONE, /* PIRQH */
52}; 52};
53 53
54/* set in board code if you want this quirks to do something */
55int uses_fsl_uli_m1575;
56
57/* Bridge */ 54/* Bridge */
58static void __devinit early_uli5249(struct pci_dev *dev) 55static void __devinit early_uli5249(struct pci_dev *dev)
59{ 56{
60 unsigned char temp; 57 unsigned char temp;
61 58
62 if (!uses_fsl_uli_m1575) 59 if (!machine_is(mpc86xx_hpcn) && !machine_is(mpc8544_ds) &&
60 !machine_is(mpc8572_ds))
63 return; 61 return;
64 62
65 pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_IO | 63 pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_IO |
@@ -82,7 +80,8 @@ static void __devinit quirk_uli1575(struct pci_dev *dev)
82{ 80{
83 int i; 81 int i;
84 82
85 if (!uses_fsl_uli_m1575) 83 if (!machine_is(mpc86xx_hpcn) && !machine_is(mpc8544_ds) &&
84 !machine_is(mpc8572_ds))
86 return; 85 return;
87 86
88 /* 87 /*
@@ -150,7 +149,8 @@ static void __devinit quirk_final_uli1575(struct pci_dev *dev)
150 * IRQ 14: Edge 149 * IRQ 14: Edge
151 * IRQ 15: Edge 150 * IRQ 15: Edge
152 */ 151 */
153 if (!uses_fsl_uli_m1575) 152 if (!machine_is(mpc86xx_hpcn) && !machine_is(mpc8544_ds) &&
153 !machine_is(mpc8572_ds))
154 return; 154 return;
155 155
156 outb(0xfa, 0x4d0); 156 outb(0xfa, 0x4d0);
@@ -176,7 +176,8 @@ static void __devinit quirk_uli5288(struct pci_dev *dev)
176 unsigned char c; 176 unsigned char c;
177 unsigned int d; 177 unsigned int d;
178 178
179 if (!uses_fsl_uli_m1575) 179 if (!machine_is(mpc86xx_hpcn) && !machine_is(mpc8544_ds) &&
180 !machine_is(mpc8572_ds))
180 return; 181 return;
181 182
182 /* read/write lock */ 183 /* read/write lock */
@@ -200,7 +201,8 @@ static void __devinit quirk_uli5229(struct pci_dev *dev)
200{ 201{
201 unsigned short temp; 202 unsigned short temp;
202 203
203 if (!uses_fsl_uli_m1575) 204 if (!machine_is(mpc86xx_hpcn) && !machine_is(mpc8544_ds) &&
205 !machine_is(mpc8572_ds))
204 return; 206 return;
205 207
206 pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE | 208 pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE |
@@ -221,7 +223,7 @@ static void __devinit quirk_final_uli5249(struct pci_dev *dev)
221 for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { 223 for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
222 if ((bus->resource[i]) && 224 if ((bus->resource[i]) &&
223 (bus->resource[i]->flags & IORESOURCE_MEM)) { 225 (bus->resource[i]->flags & IORESOURCE_MEM)) {
224 dummy = ioremap(bus->resource[i]->start, 0x4); 226 dummy = ioremap(bus->resource[i]->end - 3, 0x4);
225 if (dummy) { 227 if (dummy) {
226 in_8(dummy); 228 in_8(dummy);
227 iounmap(dummy); 229 iounmap(dummy);
@@ -238,6 +240,103 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
238DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5249, quirk_final_uli5249); 240DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5249, quirk_final_uli5249);
239DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x1575, quirk_final_uli1575); 241DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x1575, quirk_final_uli1575);
240 242
243static void __devinit hpcd_quirk_uli1575(struct pci_dev *dev)
244{
245 u32 temp32;
246
247 if (!machine_is(mpc86xx_hpcd))
248 return;
249
250 /* Disable INTx */
251 pci_read_config_dword(dev, 0x48, &temp32);
252 pci_write_config_dword(dev, 0x48, (temp32 | 1<<26));
253
254 /* Enable sideband interrupt */
255 pci_read_config_dword(dev, 0x90, &temp32);
256 pci_write_config_dword(dev, 0x90, (temp32 | 1<<22));
257}
258
259static void __devinit hpcd_quirk_uli5288(struct pci_dev *dev)
260{
261 unsigned char c;
262 unsigned short temp;
263
264 if (!machine_is(mpc86xx_hpcd))
265 return;
266
267 /* Interrupt Disable, Needed when SATA disabled */
268 pci_read_config_word(dev, PCI_COMMAND, &temp);
269 temp |= 1<<10;
270 pci_write_config_word(dev, PCI_COMMAND, temp);
271
272 pci_read_config_byte(dev, 0x83, &c);
273 c |= 0x80;
274 pci_write_config_byte(dev, 0x83, c);
275
276 pci_write_config_byte(dev, PCI_CLASS_PROG, 0x01);
277 pci_write_config_byte(dev, PCI_CLASS_DEVICE, 0x06);
278
279 pci_read_config_byte(dev, 0x83, &c);
280 c &= 0x7f;
281 pci_write_config_byte(dev, 0x83, c);
282}
283
284/*
285 * Since 8259PIC was disabled on the board, the IDE device can not
286 * use the legacy IRQ, we need to let the IDE device work under
287 * native mode and use the interrupt line like other PCI devices.
288 * IRQ14 is a sideband interrupt from IDE device to CPU and we use this
289 * as the interrupt for IDE device.
290 */
291static void __devinit hpcd_quirk_uli5229(struct pci_dev *dev)
292{
293 unsigned char c;
294
295 if (!machine_is(mpc86xx_hpcd))
296 return;
297
298 pci_read_config_byte(dev, 0x4b, &c);
299 c |= 0x10;
300 pci_write_config_byte(dev, 0x4b, c);
301}
302
303/*
304 * SATA interrupt pin bug fix
305 * There's a chip bug for 5288, The interrupt pin should be 2,
306 * not the read only value 1, So it use INTB#, not INTA# which
307 * actually used by the IDE device 5229.
308 * As of this bug, during the PCI initialization, 5288 read the
309 * irq of IDE device from the device tree, this function fix this
310 * bug by re-assigning a correct irq to 5288.
311 *
312 */
313static void __devinit hpcd_final_uli5288(struct pci_dev *dev)
314{
315 struct pci_controller *hose = pci_bus_to_host(dev->bus);
316 struct device_node *hosenode = hose ? hose->dn : NULL;
317 struct of_irq oirq;
318 int virq, pin = 2;
319 u32 laddr[3];
320
321 if (!machine_is(mpc86xx_hpcd))
322 return;
323
324 if (!hosenode)
325 return;
326
327 laddr[0] = (hose->first_busno << 16) | (PCI_DEVFN(31, 0) << 8);
328 laddr[1] = laddr[2] = 0;
329 of_irq_map_raw(hosenode, &pin, 1, laddr, &oirq);
330 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
331 oirq.size);
332 dev->irq = virq;
333}
334
335DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, hpcd_quirk_uli1575);
336DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, hpcd_quirk_uli5288);
337DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, hpcd_quirk_uli5229);
338DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5288, hpcd_final_uli5288);
339
241int uli_exclude_device(struct pci_controller *hose, 340int uli_exclude_device(struct pci_controller *hose,
242 u_char bus, u_char devfn) 341 u_char bus, u_char devfn)
243{ 342{
diff --git a/arch/powerpc/platforms/iseries/Kconfig b/arch/powerpc/platforms/iseries/Kconfig
index 761d9e971fc4..ea3e541ac74f 100644
--- a/arch/powerpc/platforms/iseries/Kconfig
+++ b/arch/powerpc/platforms/iseries/Kconfig
@@ -2,6 +2,7 @@ config PPC_ISERIES
2 bool "IBM Legacy iSeries" 2 bool "IBM Legacy iSeries"
3 depends on PPC_MULTIPLATFORM && PPC64 3 depends on PPC_MULTIPLATFORM && PPC64
4 select PPC_INDIRECT_IO 4 select PPC_INDIRECT_IO
5 select PPC_PCI_CHOICE if EMBEDDED
5 6
6menu "iSeries device drivers" 7menu "iSeries device drivers"
7 depends on PPC_ISERIES 8 depends on PPC_ISERIES
diff --git a/arch/powerpc/platforms/iseries/iommu.c b/arch/powerpc/platforms/iseries/iommu.c
index ab5d8687c3cf..bc818e4e2033 100644
--- a/arch/powerpc/platforms/iseries/iommu.c
+++ b/arch/powerpc/platforms/iseries/iommu.c
@@ -42,7 +42,8 @@
42#include <asm/iseries/iommu.h> 42#include <asm/iseries/iommu.h>
43 43
44static void tce_build_iSeries(struct iommu_table *tbl, long index, long npages, 44static void tce_build_iSeries(struct iommu_table *tbl, long index, long npages,
45 unsigned long uaddr, enum dma_data_direction direction) 45 unsigned long uaddr, enum dma_data_direction direction,
46 struct dma_attrs *attrs)
46{ 47{
47 u64 rc; 48 u64 rc;
48 u64 tce, rpn; 49 u64 tce, rpn;
diff --git a/arch/powerpc/platforms/pasemi/iommu.c b/arch/powerpc/platforms/pasemi/iommu.c
index 86967bdd8774..70541b7a5013 100644
--- a/arch/powerpc/platforms/pasemi/iommu.c
+++ b/arch/powerpc/platforms/pasemi/iommu.c
@@ -85,7 +85,8 @@ static int iommu_table_iobmap_inited;
85 85
86static void iobmap_build(struct iommu_table *tbl, long index, 86static void iobmap_build(struct iommu_table *tbl, long index,
87 long npages, unsigned long uaddr, 87 long npages, unsigned long uaddr,
88 enum dma_data_direction direction) 88 enum dma_data_direction direction,
89 struct dma_attrs *attrs)
89{ 90{
90 u32 *ip; 91 u32 *ip;
91 u32 rpn; 92 u32 rpn;
diff --git a/arch/powerpc/platforms/ps3/Kconfig b/arch/powerpc/platforms/ps3/Kconfig
index a5f4e95dfc3d..920cf7a454b1 100644
--- a/arch/powerpc/platforms/ps3/Kconfig
+++ b/arch/powerpc/platforms/ps3/Kconfig
@@ -8,6 +8,7 @@ config PPC_PS3
8 select USB_ARCH_HAS_EHCI 8 select USB_ARCH_HAS_EHCI
9 select USB_EHCI_BIG_ENDIAN_MMIO 9 select USB_EHCI_BIG_ENDIAN_MMIO
10 select MEMORY_HOTPLUG 10 select MEMORY_HOTPLUG
11 select PPC_PCI_CHOICE
11 help 12 help
12 This option enables support for the Sony PS3 game console 13 This option enables support for the Sony PS3 game console
13 and other platforms using the PS3 hypervisor. Enabling this 14 and other platforms using the PS3 hypervisor. Enabling this
diff --git a/arch/powerpc/platforms/ps3/device-init.c b/arch/powerpc/platforms/ps3/device-init.c
index 3866debfa3c4..ffdd8e963fbd 100644
--- a/arch/powerpc/platforms/ps3/device-init.c
+++ b/arch/powerpc/platforms/ps3/device-init.c
@@ -486,6 +486,7 @@ static int __init ps3_register_graphics_devices(void)
486 return -ENOMEM; 486 return -ENOMEM;
487 487
488 p->dev.match_id = PS3_MATCH_ID_GRAPHICS; 488 p->dev.match_id = PS3_MATCH_ID_GRAPHICS;
489 p->dev.match_sub_id = PS3_MATCH_SUB_ID_FB;
489 p->dev.dev_type = PS3_DEVICE_TYPE_IOC0; 490 p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;
490 491
491 result = ps3_system_bus_device_register(&p->dev); 492 result = ps3_system_bus_device_register(&p->dev);
diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platforms/ps3/system-bus.c
index d66c3628a112..280ee88cb0b0 100644
--- a/arch/powerpc/platforms/ps3/system-bus.c
+++ b/arch/powerpc/platforms/ps3/system-bus.c
@@ -347,16 +347,23 @@ static int ps3_system_bus_match(struct device *_dev,
347 struct ps3_system_bus_driver *drv = ps3_drv_to_system_bus_drv(_drv); 347 struct ps3_system_bus_driver *drv = ps3_drv_to_system_bus_drv(_drv);
348 struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); 348 struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
349 349
350 result = dev->match_id == drv->match_id; 350 if (!dev->match_sub_id)
351 result = dev->match_id == drv->match_id;
352 else
353 result = dev->match_sub_id == drv->match_sub_id &&
354 dev->match_id == drv->match_id;
351 355
352 if (result) 356 if (result)
353 pr_info("%s:%d: dev=%u(%s), drv=%u(%s): match\n", __func__, 357 pr_info("%s:%d: dev=%u.%u(%s), drv=%u.%u(%s): match\n",
354 __LINE__, dev->match_id, dev->core.bus_id, 358 __func__, __LINE__,
355 drv->match_id, drv->core.name); 359 dev->match_id, dev->match_sub_id, dev->core.bus_id,
360 drv->match_id, drv->match_sub_id, drv->core.name);
356 else 361 else
357 pr_debug("%s:%d: dev=%u(%s), drv=%u(%s): miss\n", __func__, 362 pr_debug("%s:%d: dev=%u.%u(%s), drv=%u.%u(%s): miss\n",
358 __LINE__, dev->match_id, dev->core.bus_id, 363 __func__, __LINE__,
359 drv->match_id, drv->core.name); 364 dev->match_id, dev->match_sub_id, dev->core.bus_id,
365 drv->match_id, drv->match_sub_id, drv->core.name);
366
360 return result; 367 return result;
361} 368}
362 369
diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
index 07fe5b69b9e2..757c0296e0b8 100644
--- a/arch/powerpc/platforms/pseries/Kconfig
+++ b/arch/powerpc/platforms/pseries/Kconfig
@@ -7,6 +7,7 @@ config PPC_PSERIES
7 select RTAS_ERROR_LOGGING 7 select RTAS_ERROR_LOGGING
8 select PPC_UDBG_16550 8 select PPC_UDBG_16550
9 select PPC_NATIVE 9 select PPC_NATIVE
10 select PPC_PCI_CHOICE if EMBEDDED
10 default y 11 default y
11 12
12config PPC_SPLPAR 13config PPC_SPLPAR
diff --git a/arch/powerpc/platforms/pseries/eeh.c b/arch/powerpc/platforms/pseries/eeh.c
index c027f0a70a04..54816d75b578 100644
--- a/arch/powerpc/platforms/pseries/eeh.c
+++ b/arch/powerpc/platforms/pseries/eeh.c
@@ -75,9 +75,9 @@
75 */ 75 */
76 76
77/* If a device driver keeps reading an MMIO register in an interrupt 77/* If a device driver keeps reading an MMIO register in an interrupt
78 * handler after a slot isolation event has occurred, we assume it 78 * handler after a slot isolation event, it might be broken.
79 * is broken and panic. This sets the threshold for how many read 79 * This sets the threshold for how many read attempts we allow
80 * attempts we allow before panicking. 80 * before printing an error message.
81 */ 81 */
82#define EEH_MAX_FAILS 2100000 82#define EEH_MAX_FAILS 2100000
83 83
@@ -470,6 +470,7 @@ int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
470 unsigned long flags; 470 unsigned long flags;
471 struct pci_dn *pdn; 471 struct pci_dn *pdn;
472 int rc = 0; 472 int rc = 0;
473 const char *location;
473 474
474 total_mmio_ffs++; 475 total_mmio_ffs++;
475 476
@@ -509,18 +510,15 @@ int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
509 rc = 1; 510 rc = 1;
510 if (pdn->eeh_mode & EEH_MODE_ISOLATED) { 511 if (pdn->eeh_mode & EEH_MODE_ISOLATED) {
511 pdn->eeh_check_count ++; 512 pdn->eeh_check_count ++;
512 if (pdn->eeh_check_count >= EEH_MAX_FAILS) { 513 if (pdn->eeh_check_count % EEH_MAX_FAILS == 0) {
513 printk (KERN_ERR "EEH: Device driver ignored %d bad reads, panicing\n", 514 location = of_get_property(dn, "ibm,loc-code", NULL);
514 pdn->eeh_check_count); 515 printk (KERN_ERR "EEH: %d reads ignored for recovering device at "
516 "location=%s driver=%s pci addr=%s\n",
517 pdn->eeh_check_count, location,
518 dev->driver->name, pci_name(dev));
519 printk (KERN_ERR "EEH: Might be infinite loop in %s driver\n",
520 dev->driver->name);
515 dump_stack(); 521 dump_stack();
516 msleep(5000);
517
518 /* re-read the slot reset state */
519 if (read_slot_reset_state(pdn, rets) != 0)
520 rets[0] = -1; /* reset state unknown */
521
522 /* If we are here, then we hit an infinite loop. Stop. */
523 panic("EEH: MMIO halt (%d) on device:%s\n", rets[0], pci_name(dev));
524 } 522 }
525 goto dn_unlock; 523 goto dn_unlock;
526 } 524 }
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
index 9a12908510fb..5377dd4b849a 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -50,7 +50,8 @@
50 50
51static void tce_build_pSeries(struct iommu_table *tbl, long index, 51static void tce_build_pSeries(struct iommu_table *tbl, long index,
52 long npages, unsigned long uaddr, 52 long npages, unsigned long uaddr,
53 enum dma_data_direction direction) 53 enum dma_data_direction direction,
54 struct dma_attrs *attrs)
54{ 55{
55 u64 proto_tce; 56 u64 proto_tce;
56 u64 *tcep; 57 u64 *tcep;
@@ -95,7 +96,8 @@ static unsigned long tce_get_pseries(struct iommu_table *tbl, long index)
95 96
96static void tce_build_pSeriesLP(struct iommu_table *tbl, long tcenum, 97static void tce_build_pSeriesLP(struct iommu_table *tbl, long tcenum,
97 long npages, unsigned long uaddr, 98 long npages, unsigned long uaddr,
98 enum dma_data_direction direction) 99 enum dma_data_direction direction,
100 struct dma_attrs *attrs)
99{ 101{
100 u64 rc; 102 u64 rc;
101 u64 proto_tce, tce; 103 u64 proto_tce, tce;
@@ -127,7 +129,8 @@ static DEFINE_PER_CPU(u64 *, tce_page) = NULL;
127 129
128static void tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum, 130static void tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum,
129 long npages, unsigned long uaddr, 131 long npages, unsigned long uaddr,
130 enum dma_data_direction direction) 132 enum dma_data_direction direction,
133 struct dma_attrs *attrs)
131{ 134{
132 u64 rc; 135 u64 rc;
133 u64 proto_tce; 136 u64 proto_tce;
@@ -136,7 +139,8 @@ static void tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum,
136 long l, limit; 139 long l, limit;
137 140
138 if (npages == 1) { 141 if (npages == 1) {
139 tce_build_pSeriesLP(tbl, tcenum, npages, uaddr, direction); 142 tce_build_pSeriesLP(tbl, tcenum, npages, uaddr,
143 direction, attrs);
140 return; 144 return;
141 } 145 }
142 146
@@ -150,7 +154,7 @@ static void tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum,
150 /* If allocation fails, fall back to the loop implementation */ 154 /* If allocation fails, fall back to the loop implementation */
151 if (!tcep) { 155 if (!tcep) {
152 tce_build_pSeriesLP(tbl, tcenum, npages, uaddr, 156 tce_build_pSeriesLP(tbl, tcenum, npages, uaddr,
153 direction); 157 direction, attrs);
154 return; 158 return;
155 } 159 }
156 __get_cpu_var(tce_page) = tcep; 160 __get_cpu_var(tce_page) = tcep;
diff --git a/arch/powerpc/sysdev/axonram.c b/arch/powerpc/sysdev/axonram.c
index 7f59188cd9a1..9e105cbc5e5f 100644
--- a/arch/powerpc/sysdev/axonram.c
+++ b/arch/powerpc/sysdev/axonram.c
@@ -57,6 +57,8 @@
57#define AXON_RAM_SECTOR_SIZE 1 << AXON_RAM_SECTOR_SHIFT 57#define AXON_RAM_SECTOR_SIZE 1 << AXON_RAM_SECTOR_SHIFT
58#define AXON_RAM_IRQ_FLAGS IRQF_SHARED | IRQF_TRIGGER_RISING 58#define AXON_RAM_IRQ_FLAGS IRQF_SHARED | IRQF_TRIGGER_RISING
59 59
60static int azfs_major, azfs_minor;
61
60struct axon_ram_bank { 62struct axon_ram_bank {
61 struct of_device *device; 63 struct of_device *device;
62 struct gendisk *disk; 64 struct gendisk *disk;
@@ -148,7 +150,10 @@ axon_ram_direct_access(struct block_device *device, sector_t sector,
148 struct axon_ram_bank *bank = device->bd_disk->private_data; 150 struct axon_ram_bank *bank = device->bd_disk->private_data;
149 loff_t offset; 151 loff_t offset;
150 152
151 offset = sector << AXON_RAM_SECTOR_SHIFT; 153 offset = sector;
154 if (device->bd_part != NULL)
155 offset += device->bd_part->start_sect;
156 offset <<= AXON_RAM_SECTOR_SHIFT;
152 if (offset >= bank->size) { 157 if (offset >= bank->size) {
153 dev_err(&bank->device->dev, "Access outside of address space\n"); 158 dev_err(&bank->device->dev, "Access outside of address space\n");
154 return -ERANGE; 159 return -ERANGE;
@@ -227,19 +232,14 @@ axon_ram_probe(struct of_device *device, const struct of_device_id *device_id)
227 goto failed; 232 goto failed;
228 } 233 }
229 234
230 bank->disk->first_minor = 0; 235 bank->disk->major = azfs_major;
236 bank->disk->first_minor = azfs_minor;
231 bank->disk->fops = &axon_ram_devops; 237 bank->disk->fops = &axon_ram_devops;
232 bank->disk->private_data = bank; 238 bank->disk->private_data = bank;
233 bank->disk->driverfs_dev = &device->dev; 239 bank->disk->driverfs_dev = &device->dev;
234 240
235 sprintf(bank->disk->disk_name, "%s%d", 241 sprintf(bank->disk->disk_name, "%s%d",
236 AXON_RAM_DEVICE_NAME, axon_ram_bank_id); 242 AXON_RAM_DEVICE_NAME, axon_ram_bank_id);
237 bank->disk->major = register_blkdev(0, bank->disk->disk_name);
238 if (bank->disk->major < 0) {
239 dev_err(&device->dev, "Cannot register block device\n");
240 rc = -EFAULT;
241 goto failed;
242 }
243 243
244 bank->disk->queue = blk_alloc_queue(GFP_KERNEL); 244 bank->disk->queue = blk_alloc_queue(GFP_KERNEL);
245 if (bank->disk->queue == NULL) { 245 if (bank->disk->queue == NULL) {
@@ -276,6 +276,8 @@ axon_ram_probe(struct of_device *device, const struct of_device_id *device_id)
276 goto failed; 276 goto failed;
277 } 277 }
278 278
279 azfs_minor += bank->disk->minors;
280
279 return 0; 281 return 0;
280 282
281failed: 283failed:
@@ -310,7 +312,6 @@ axon_ram_remove(struct of_device *device)
310 312
311 device_remove_file(&device->dev, &dev_attr_ecc); 313 device_remove_file(&device->dev, &dev_attr_ecc);
312 free_irq(bank->irq_id, device); 314 free_irq(bank->irq_id, device);
313 unregister_blkdev(bank->disk->major, bank->disk->disk_name);
314 del_gendisk(bank->disk); 315 del_gendisk(bank->disk);
315 iounmap((void __iomem *) bank->io_addr); 316 iounmap((void __iomem *) bank->io_addr);
316 kfree(bank); 317 kfree(bank);
@@ -341,6 +342,14 @@ static struct of_platform_driver axon_ram_driver = {
341static int __init 342static int __init
342axon_ram_init(void) 343axon_ram_init(void)
343{ 344{
345 azfs_major = register_blkdev(azfs_major, AXON_RAM_DEVICE_NAME);
346 if (azfs_major < 0) {
347 printk(KERN_ERR "%s cannot become block device major number\n",
348 AXON_RAM_MODULE_NAME);
349 return -EFAULT;
350 }
351 azfs_minor = 0;
352
344 return of_register_platform_driver(&axon_ram_driver); 353 return of_register_platform_driver(&axon_ram_driver);
345} 354}
346 355
@@ -351,6 +360,7 @@ static void __exit
351axon_ram_exit(void) 360axon_ram_exit(void)
352{ 361{
353 of_unregister_platform_driver(&axon_ram_driver); 362 of_unregister_platform_driver(&axon_ram_driver);
363 unregister_blkdev(azfs_major, AXON_RAM_DEVICE_NAME);
354} 364}
355 365
356module_init(axon_ram_init); 366module_init(axon_ram_init);
diff --git a/arch/powerpc/sysdev/dart_iommu.c b/arch/powerpc/sysdev/dart_iommu.c
index 005c2ecf976f..de8c8b542cfa 100644
--- a/arch/powerpc/sysdev/dart_iommu.c
+++ b/arch/powerpc/sysdev/dart_iommu.c
@@ -149,7 +149,8 @@ static void dart_flush(struct iommu_table *tbl)
149 149
150static void dart_build(struct iommu_table *tbl, long index, 150static void dart_build(struct iommu_table *tbl, long index,
151 long npages, unsigned long uaddr, 151 long npages, unsigned long uaddr,
152 enum dma_data_direction direction) 152 enum dma_data_direction direction,
153 struct dma_attrs *attrs)
153{ 154{
154 unsigned int *dp; 155 unsigned int *dp;
155 unsigned int rpn; 156 unsigned int rpn;
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index 87b0aa13ab48..61e6d77efa4f 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -27,6 +27,7 @@
27#include <sysdev/fsl_soc.h> 27#include <sysdev/fsl_soc.h>
28#include <sysdev/fsl_pci.h> 28#include <sysdev/fsl_pci.h>
29 29
30#if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
30/* atmu setup for fsl pci/pcie controller */ 31/* atmu setup for fsl pci/pcie controller */
31void __init setup_pci_atmu(struct pci_controller *hose, struct resource *rsrc) 32void __init setup_pci_atmu(struct pci_controller *hose, struct resource *rsrc)
32{ 33{
@@ -248,3 +249,63 @@ DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8536, quirk_fsl_pcie_header);
248DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641, quirk_fsl_pcie_header); 249DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641, quirk_fsl_pcie_header);
249DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641D, quirk_fsl_pcie_header); 250DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641D, quirk_fsl_pcie_header);
250DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8610, quirk_fsl_pcie_header); 251DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8610, quirk_fsl_pcie_header);
252#endif /* CONFIG_PPC_85xx || CONFIG_PPC_86xx */
253
254#if defined(CONFIG_PPC_83xx)
255int __init mpc83xx_add_bridge(struct device_node *dev)
256{
257 int len;
258 struct pci_controller *hose;
259 struct resource rsrc;
260 const int *bus_range;
261 int primary = 1, has_address = 0;
262 phys_addr_t immr = get_immrbase();
263
264 pr_debug("Adding PCI host bridge %s\n", dev->full_name);
265
266 /* Fetch host bridge registers address */
267 has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
268
269 /* Get bus range if any */
270 bus_range = of_get_property(dev, "bus-range", &len);
271 if (bus_range == NULL || len < 2 * sizeof(int)) {
272 printk(KERN_WARNING "Can't get bus-range for %s, assume"
273 " bus 0\n", dev->full_name);
274 }
275
276 ppc_pci_flags |= PPC_PCI_REASSIGN_ALL_BUS;
277 hose = pcibios_alloc_controller(dev);
278 if (!hose)
279 return -ENOMEM;
280
281 hose->first_busno = bus_range ? bus_range[0] : 0;
282 hose->last_busno = bus_range ? bus_range[1] : 0xff;
283
284 /* MPC83xx supports up to two host controllers one at 0x8500 from immrbar
285 * the other at 0x8600, we consider the 0x8500 the primary controller
286 */
287 /* PCI 1 */
288 if ((rsrc.start & 0xfffff) == 0x8500) {
289 setup_indirect_pci(hose, immr + 0x8300, immr + 0x8304, 0);
290 }
291 /* PCI 2 */
292 if ((rsrc.start & 0xfffff) == 0x8600) {
293 setup_indirect_pci(hose, immr + 0x8380, immr + 0x8384, 0);
294 primary = 0;
295 }
296
297 printk(KERN_INFO "Found MPC83xx PCI host bridge at 0x%016llx. "
298 "Firmware bus number: %d->%d\n",
299 (unsigned long long)rsrc.start, hose->first_busno,
300 hose->last_busno);
301
302 pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
303 hose, hose->cfg_addr, hose->cfg_data);
304
305 /* Interpret the "ranges" property */
306 /* This also maps the I/O region and sets isa_io/mem_base */
307 pci_process_bridge_OF_ranges(hose, dev, primary);
308
309 return 0;
310}
311#endif /* CONFIG_PPC_83xx */
diff --git a/arch/powerpc/sysdev/fsl_pci.h b/arch/powerpc/sysdev/fsl_pci.h
index 37b04ad26571..13f30c2a61e7 100644
--- a/arch/powerpc/sysdev/fsl_pci.h
+++ b/arch/powerpc/sysdev/fsl_pci.h
@@ -83,6 +83,7 @@ struct ccsr_pci {
83 83
84extern int fsl_add_bridge(struct device_node *dev, int is_primary); 84extern int fsl_add_bridge(struct device_node *dev, int is_primary);
85extern void fsl_pcibios_fixup_bus(struct pci_bus *bus); 85extern void fsl_pcibios_fixup_bus(struct pci_bus *bus);
86extern int mpc83xx_add_bridge(struct device_node *dev);
86 87
87#endif /* __POWERPC_FSL_PCI_H */ 88#endif /* __POWERPC_FSL_PCI_H */
88#endif /* __KERNEL__ */ 89#endif /* __KERNEL__ */
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index ebcec7362f95..214388e11807 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -207,66 +207,58 @@ static int __init of_add_fixed_phys(void)
207arch_initcall(of_add_fixed_phys); 207arch_initcall(of_add_fixed_phys);
208#endif /* CONFIG_FIXED_PHY */ 208#endif /* CONFIG_FIXED_PHY */
209 209
210static int __init gfar_mdio_of_init(void) 210static int gfar_mdio_of_init_one(struct device_node *np)
211{ 211{
212 struct device_node *np = NULL; 212 int k;
213 struct device_node *child = NULL;
214 struct gianfar_mdio_data mdio_data;
213 struct platform_device *mdio_dev; 215 struct platform_device *mdio_dev;
214 struct resource res; 216 struct resource res;
215 int ret; 217 int ret;
216 218
217 np = of_find_compatible_node(np, NULL, "fsl,gianfar-mdio"); 219 memset(&res, 0, sizeof(res));
220 memset(&mdio_data, 0, sizeof(mdio_data));
218 221
219 /* try the deprecated version */ 222 ret = of_address_to_resource(np, 0, &res);
220 if (!np) 223 if (ret)
221 np = of_find_compatible_node(np, "mdio", "gianfar"); 224 return ret;
222 225
223 if (np) { 226 mdio_dev = platform_device_register_simple("fsl-gianfar_mdio",
224 int k; 227 res.start&0xfffff, &res, 1);
225 struct device_node *child = NULL; 228 if (IS_ERR(mdio_dev))
226 struct gianfar_mdio_data mdio_data; 229 return PTR_ERR(mdio_dev);
227 230
228 memset(&res, 0, sizeof(res)); 231 for (k = 0; k < 32; k++)
229 memset(&mdio_data, 0, sizeof(mdio_data)); 232 mdio_data.irq[k] = PHY_POLL;
230 233
231 ret = of_address_to_resource(np, 0, &res); 234 while ((child = of_get_next_child(np, child)) != NULL) {
232 if (ret) 235 int irq = irq_of_parse_and_map(child, 0);
233 goto err; 236 if (irq != NO_IRQ) {
234 237 const u32 *id = of_get_property(child, "reg", NULL);
235 mdio_dev = 238 mdio_data.irq[*id] = irq;
236 platform_device_register_simple("fsl-gianfar_mdio",
237 res.start, &res, 1);
238 if (IS_ERR(mdio_dev)) {
239 ret = PTR_ERR(mdio_dev);
240 goto err;
241 } 239 }
240 }
242 241
243 for (k = 0; k < 32; k++) 242 ret = platform_device_add_data(mdio_dev, &mdio_data,
244 mdio_data.irq[k] = PHY_POLL; 243 sizeof(struct gianfar_mdio_data));
244 if (ret)
245 platform_device_unregister(mdio_dev);
245 246
246 while ((child = of_get_next_child(np, child)) != NULL) { 247 return ret;
247 int irq = irq_of_parse_and_map(child, 0); 248}
248 if (irq != NO_IRQ) {
249 const u32 *id = of_get_property(child,
250 "reg", NULL);
251 mdio_data.irq[*id] = irq;
252 }
253 }
254 249
255 ret = 250static int __init gfar_mdio_of_init(void)
256 platform_device_add_data(mdio_dev, &mdio_data, 251{
257 sizeof(struct gianfar_mdio_data)); 252 struct device_node *np = NULL;
258 if (ret)
259 goto unreg;
260 }
261 253
262 of_node_put(np); 254 for_each_compatible_node(np, NULL, "fsl,gianfar-mdio")
263 return 0; 255 gfar_mdio_of_init_one(np);
264 256
265unreg: 257 /* try the deprecated version */
266 platform_device_unregister(mdio_dev); 258 for_each_compatible_node(np, "mdio", "gianfar");
267err: 259 gfar_mdio_of_init_one(np);
268 of_node_put(np); 260
269 return ret; 261 return 0;
270} 262}
271 263
272arch_initcall(gfar_mdio_of_init); 264arch_initcall(gfar_mdio_of_init);
@@ -296,6 +288,9 @@ static int __init gfar_of_init(void)
296 const phandle *ph; 288 const phandle *ph;
297 int n_res = 2; 289 int n_res = 2;
298 290
291 if (!of_device_is_available(np))
292 continue;
293
299 memset(r, 0, sizeof(r)); 294 memset(r, 0, sizeof(r));
300 memset(&gfar_data, 0, sizeof(gfar_data)); 295 memset(&gfar_data, 0, sizeof(gfar_data));
301 296
@@ -357,6 +352,9 @@ static int __init gfar_of_init(void)
357 else 352 else
358 gfar_data.interface = PHY_INTERFACE_MODE_MII; 353 gfar_data.interface = PHY_INTERFACE_MODE_MII;
359 354
355 if (of_get_property(np, "fsl,magic-packet", NULL))
356 gfar_data.device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
357
360 ph = of_get_property(np, "phy-handle", NULL); 358 ph = of_get_property(np, "phy-handle", NULL);
361 if (ph == NULL) { 359 if (ph == NULL) {
362 u32 *fixed_link; 360 u32 *fixed_link;
@@ -390,7 +388,7 @@ static int __init gfar_of_init(void)
390 388
391 gfar_data.phy_id = *id; 389 gfar_data.phy_id = *id;
392 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%llx", 390 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%llx",
393 (unsigned long long)res.start); 391 (unsigned long long)res.start&0xfffff);
394 392
395 of_node_put(phy); 393 of_node_put(phy);
396 of_node_put(mdio); 394 of_node_put(mdio);
diff --git a/arch/powerpc/sysdev/fsl_soc.h b/arch/powerpc/sysdev/fsl_soc.h
index 52c831fa1886..024299887352 100644
--- a/arch/powerpc/sysdev/fsl_soc.h
+++ b/arch/powerpc/sysdev/fsl_soc.h
@@ -10,6 +10,7 @@ extern u32 get_baudrate(void);
10extern u32 fsl_get_sys_freq(void); 10extern u32 fsl_get_sys_freq(void);
11 11
12struct spi_board_info; 12struct spi_board_info;
13struct device_node;
13 14
14extern int fsl_spi_init(struct spi_board_info *board_infos, 15extern int fsl_spi_init(struct spi_board_info *board_infos,
15 unsigned int num_board_infos, 16 unsigned int num_board_infos,
diff --git a/arch/powerpc/sysdev/ipic.c b/arch/powerpc/sysdev/ipic.c
index caba1c0be5a7..88a983ece5c9 100644
--- a/arch/powerpc/sysdev/ipic.c
+++ b/arch/powerpc/sysdev/ipic.c
@@ -22,6 +22,7 @@
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/bootmem.h> 23#include <linux/bootmem.h>
24#include <linux/spinlock.h> 24#include <linux/spinlock.h>
25#include <linux/fsl_devices.h>
25#include <asm/irq.h> 26#include <asm/irq.h>
26#include <asm/io.h> 27#include <asm/io.h>
27#include <asm/prom.h> 28#include <asm/prom.h>
@@ -889,8 +890,78 @@ unsigned int ipic_get_irq(void)
889 return irq_linear_revmap(primary_ipic->irqhost, irq); 890 return irq_linear_revmap(primary_ipic->irqhost, irq);
890} 891}
891 892
893#ifdef CONFIG_PM
894static struct {
895 u32 sicfr;
896 u32 siprr[2];
897 u32 simsr[2];
898 u32 sicnr;
899 u32 smprr[2];
900 u32 semsr;
901 u32 secnr;
902 u32 sermr;
903 u32 sercr;
904} ipic_saved_state;
905
906static int ipic_suspend(struct sys_device *sdev, pm_message_t state)
907{
908 struct ipic *ipic = primary_ipic;
909
910 ipic_saved_state.sicfr = ipic_read(ipic->regs, IPIC_SICFR);
911 ipic_saved_state.siprr[0] = ipic_read(ipic->regs, IPIC_SIPRR_A);
912 ipic_saved_state.siprr[1] = ipic_read(ipic->regs, IPIC_SIPRR_D);
913 ipic_saved_state.simsr[0] = ipic_read(ipic->regs, IPIC_SIMSR_H);
914 ipic_saved_state.simsr[1] = ipic_read(ipic->regs, IPIC_SIMSR_L);
915 ipic_saved_state.sicnr = ipic_read(ipic->regs, IPIC_SICNR);
916 ipic_saved_state.smprr[0] = ipic_read(ipic->regs, IPIC_SMPRR_A);
917 ipic_saved_state.smprr[1] = ipic_read(ipic->regs, IPIC_SMPRR_B);
918 ipic_saved_state.semsr = ipic_read(ipic->regs, IPIC_SEMSR);
919 ipic_saved_state.secnr = ipic_read(ipic->regs, IPIC_SECNR);
920 ipic_saved_state.sermr = ipic_read(ipic->regs, IPIC_SERMR);
921 ipic_saved_state.sercr = ipic_read(ipic->regs, IPIC_SERCR);
922
923 if (fsl_deep_sleep()) {
924 /* In deep sleep, make sure there can be no
925 * pending interrupts, as this can cause
926 * problems on 831x.
927 */
928 ipic_write(ipic->regs, IPIC_SIMSR_H, 0);
929 ipic_write(ipic->regs, IPIC_SIMSR_L, 0);
930 ipic_write(ipic->regs, IPIC_SEMSR, 0);
931 ipic_write(ipic->regs, IPIC_SERMR, 0);
932 }
933
934 return 0;
935}
936
937static int ipic_resume(struct sys_device *sdev)
938{
939 struct ipic *ipic = primary_ipic;
940
941 ipic_write(ipic->regs, IPIC_SICFR, ipic_saved_state.sicfr);
942 ipic_write(ipic->regs, IPIC_SIPRR_A, ipic_saved_state.siprr[0]);
943 ipic_write(ipic->regs, IPIC_SIPRR_D, ipic_saved_state.siprr[1]);
944 ipic_write(ipic->regs, IPIC_SIMSR_H, ipic_saved_state.simsr[0]);
945 ipic_write(ipic->regs, IPIC_SIMSR_L, ipic_saved_state.simsr[1]);
946 ipic_write(ipic->regs, IPIC_SICNR, ipic_saved_state.sicnr);
947 ipic_write(ipic->regs, IPIC_SMPRR_A, ipic_saved_state.smprr[0]);
948 ipic_write(ipic->regs, IPIC_SMPRR_B, ipic_saved_state.smprr[1]);
949 ipic_write(ipic->regs, IPIC_SEMSR, ipic_saved_state.semsr);
950 ipic_write(ipic->regs, IPIC_SECNR, ipic_saved_state.secnr);
951 ipic_write(ipic->regs, IPIC_SERMR, ipic_saved_state.sermr);
952 ipic_write(ipic->regs, IPIC_SERCR, ipic_saved_state.sercr);
953
954 return 0;
955}
956#else
957#define ipic_suspend NULL
958#define ipic_resume NULL
959#endif
960
892static struct sysdev_class ipic_sysclass = { 961static struct sysdev_class ipic_sysclass = {
893 .name = "ipic", 962 .name = "ipic",
963 .suspend = ipic_suspend,
964 .resume = ipic_resume,
894}; 965};
895 966
896static struct sys_device device_ipic = { 967static struct sys_device device_ipic = {
diff --git a/arch/powerpc/sysdev/qe_lib/qe.c b/arch/powerpc/sysdev/qe_lib/qe.c
index 9e82d7e725a5..b3b73ae57d6d 100644
--- a/arch/powerpc/sysdev/qe_lib/qe.c
+++ b/arch/powerpc/sysdev/qe_lib/qe.c
@@ -64,7 +64,7 @@ static phys_addr_t qebase = -1;
64phys_addr_t get_qe_base(void) 64phys_addr_t get_qe_base(void)
65{ 65{
66 struct device_node *qe; 66 struct device_node *qe;
67 unsigned int size; 67 int size;
68 const u32 *prop; 68 const u32 *prop;
69 69
70 if (qebase != -1) 70 if (qebase != -1)
@@ -158,7 +158,7 @@ static unsigned int brg_clk = 0;
158unsigned int qe_get_brg_clk(void) 158unsigned int qe_get_brg_clk(void)
159{ 159{
160 struct device_node *qe; 160 struct device_node *qe;
161 unsigned int size; 161 int size;
162 const u32 *prop; 162 const u32 *prop;
163 163
164 if (brg_clk) 164 if (brg_clk)
@@ -305,7 +305,7 @@ EXPORT_SYMBOL(qe_put_snum);
305 305
306static int qe_sdma_init(void) 306static int qe_sdma_init(void)
307{ 307{
308 struct sdma *sdma = &qe_immr->sdma; 308 struct sdma __iomem *sdma = &qe_immr->sdma;
309 unsigned long sdma_buf_offset; 309 unsigned long sdma_buf_offset;
310 310
311 if (!sdma) 311 if (!sdma)
diff --git a/arch/powerpc/sysdev/qe_lib/ucc.c b/arch/powerpc/sysdev/qe_lib/ucc.c
index d3c7f5af9bc8..1d78071aad7d 100644
--- a/arch/powerpc/sysdev/qe_lib/ucc.c
+++ b/arch/powerpc/sysdev/qe_lib/ucc.c
@@ -88,7 +88,7 @@ int ucc_set_type(unsigned int ucc_num, enum ucc_speed_type speed)
88 return 0; 88 return 0;
89} 89}
90 90
91static void get_cmxucr_reg(unsigned int ucc_num, __be32 **cmxucr, 91static void get_cmxucr_reg(unsigned int ucc_num, __be32 __iomem **cmxucr,
92 unsigned int *reg_num, unsigned int *shift) 92 unsigned int *reg_num, unsigned int *shift)
93{ 93{
94 unsigned int cmx = ((ucc_num & 1) << 1) + (ucc_num > 3); 94 unsigned int cmx = ((ucc_num & 1) << 1) + (ucc_num > 3);
@@ -100,7 +100,7 @@ static void get_cmxucr_reg(unsigned int ucc_num, __be32 **cmxucr,
100 100
101int ucc_mux_set_grant_tsa_bkpt(unsigned int ucc_num, int set, u32 mask) 101int ucc_mux_set_grant_tsa_bkpt(unsigned int ucc_num, int set, u32 mask)
102{ 102{
103 __be32 *cmxucr; 103 __be32 __iomem *cmxucr;
104 unsigned int reg_num; 104 unsigned int reg_num;
105 unsigned int shift; 105 unsigned int shift;
106 106
@@ -121,7 +121,7 @@ int ucc_mux_set_grant_tsa_bkpt(unsigned int ucc_num, int set, u32 mask)
121int ucc_set_qe_mux_rxtx(unsigned int ucc_num, enum qe_clock clock, 121int ucc_set_qe_mux_rxtx(unsigned int ucc_num, enum qe_clock clock,
122 enum comm_dir mode) 122 enum comm_dir mode)
123{ 123{
124 __be32 *cmxucr; 124 __be32 __iomem *cmxucr;
125 unsigned int reg_num; 125 unsigned int reg_num;
126 unsigned int shift; 126 unsigned int shift;
127 u32 clock_bits = 0; 127 u32 clock_bits = 0;
diff --git a/arch/powerpc/sysdev/qe_lib/ucc_fast.c b/arch/powerpc/sysdev/qe_lib/ucc_fast.c
index bcf88e6ce962..1aecb075a72e 100644
--- a/arch/powerpc/sysdev/qe_lib/ucc_fast.c
+++ b/arch/powerpc/sysdev/qe_lib/ucc_fast.c
@@ -46,7 +46,7 @@ void ucc_fast_dump_regs(struct ucc_fast_private * uccf)
46 printk(KERN_INFO "uccm : addr=0x%p, val=0x%08x\n", 46 printk(KERN_INFO "uccm : addr=0x%p, val=0x%08x\n",
47 &uccf->uf_regs->uccm, in_be32(&uccf->uf_regs->uccm)); 47 &uccf->uf_regs->uccm, in_be32(&uccf->uf_regs->uccm));
48 printk(KERN_INFO "uccs : addr=0x%p, val=0x%02x\n", 48 printk(KERN_INFO "uccs : addr=0x%p, val=0x%02x\n",
49 &uccf->uf_regs->uccs, uccf->uf_regs->uccs); 49 &uccf->uf_regs->uccs, in_8(&uccf->uf_regs->uccs));
50 printk(KERN_INFO "urfb : addr=0x%p, val=0x%08x\n", 50 printk(KERN_INFO "urfb : addr=0x%p, val=0x%08x\n",
51 &uccf->uf_regs->urfb, in_be32(&uccf->uf_regs->urfb)); 51 &uccf->uf_regs->urfb, in_be32(&uccf->uf_regs->urfb));
52 printk(KERN_INFO "urfs : addr=0x%p, val=0x%04x\n", 52 printk(KERN_INFO "urfs : addr=0x%p, val=0x%04x\n",
@@ -68,7 +68,7 @@ void ucc_fast_dump_regs(struct ucc_fast_private * uccf)
68 printk(KERN_INFO "urtry : addr=0x%p, val=0x%08x\n", 68 printk(KERN_INFO "urtry : addr=0x%p, val=0x%08x\n",
69 &uccf->uf_regs->urtry, in_be32(&uccf->uf_regs->urtry)); 69 &uccf->uf_regs->urtry, in_be32(&uccf->uf_regs->urtry));
70 printk(KERN_INFO "guemr : addr=0x%p, val=0x%02x\n", 70 printk(KERN_INFO "guemr : addr=0x%p, val=0x%02x\n",
71 &uccf->uf_regs->guemr, uccf->uf_regs->guemr); 71 &uccf->uf_regs->guemr, in_8(&uccf->uf_regs->guemr));
72} 72}
73EXPORT_SYMBOL(ucc_fast_dump_regs); 73EXPORT_SYMBOL(ucc_fast_dump_regs);
74 74
@@ -96,7 +96,7 @@ EXPORT_SYMBOL(ucc_fast_transmit_on_demand);
96 96
97void ucc_fast_enable(struct ucc_fast_private * uccf, enum comm_dir mode) 97void ucc_fast_enable(struct ucc_fast_private * uccf, enum comm_dir mode)
98{ 98{
99 struct ucc_fast *uf_regs; 99 struct ucc_fast __iomem *uf_regs;
100 u32 gumr; 100 u32 gumr;
101 101
102 uf_regs = uccf->uf_regs; 102 uf_regs = uccf->uf_regs;
@@ -117,7 +117,7 @@ EXPORT_SYMBOL(ucc_fast_enable);
117 117
118void ucc_fast_disable(struct ucc_fast_private * uccf, enum comm_dir mode) 118void ucc_fast_disable(struct ucc_fast_private * uccf, enum comm_dir mode)
119{ 119{
120 struct ucc_fast *uf_regs; 120 struct ucc_fast __iomem *uf_regs;
121 u32 gumr; 121 u32 gumr;
122 122
123 uf_regs = uccf->uf_regs; 123 uf_regs = uccf->uf_regs;
@@ -139,7 +139,7 @@ EXPORT_SYMBOL(ucc_fast_disable);
139int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** uccf_ret) 139int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** uccf_ret)
140{ 140{
141 struct ucc_fast_private *uccf; 141 struct ucc_fast_private *uccf;
142 struct ucc_fast *uf_regs; 142 struct ucc_fast __iomem *uf_regs;
143 u32 gumr; 143 u32 gumr;
144 int ret; 144 int ret;
145 145
@@ -216,10 +216,10 @@ int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** ucc
216 uccf->stopped_tx = 0; 216 uccf->stopped_tx = 0;
217 uccf->stopped_rx = 0; 217 uccf->stopped_rx = 0;
218 uf_regs = uccf->uf_regs; 218 uf_regs = uccf->uf_regs;
219 uccf->p_ucce = (u32 *) & (uf_regs->ucce); 219 uccf->p_ucce = &uf_regs->ucce;
220 uccf->p_uccm = (u32 *) & (uf_regs->uccm); 220 uccf->p_uccm = &uf_regs->uccm;
221#ifdef CONFIG_UGETH_TX_ON_DEMAND 221#ifdef CONFIG_UGETH_TX_ON_DEMAND
222 uccf->p_utodr = (u16 *) & (uf_regs->utodr); 222 uccf->p_utodr = &uf_regs->utodr;
223#endif 223#endif
224#ifdef STATISTICS 224#ifdef STATISTICS
225 uccf->tx_frames = 0; 225 uccf->tx_frames = 0;
diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
index b6781030cfbd..b795b3e24afd 100644
--- a/arch/s390/kernel/smp.c
+++ b/arch/s390/kernel/smp.c
@@ -864,7 +864,8 @@ int setup_profiling_timer(unsigned int multiplier)
864} 864}
865 865
866#ifdef CONFIG_HOTPLUG_CPU 866#ifdef CONFIG_HOTPLUG_CPU
867static ssize_t cpu_configure_show(struct sys_device *dev, char *buf) 867static ssize_t cpu_configure_show(struct sys_device *dev,
868 struct sysdev_attribute *attr, char *buf)
868{ 869{
869 ssize_t count; 870 ssize_t count;
870 871
@@ -874,8 +875,9 @@ static ssize_t cpu_configure_show(struct sys_device *dev, char *buf)
874 return count; 875 return count;
875} 876}
876 877
877static ssize_t cpu_configure_store(struct sys_device *dev, const char *buf, 878static ssize_t cpu_configure_store(struct sys_device *dev,
878 size_t count) 879 struct sysdev_attribute *attr,
880 const char *buf, size_t count)
879{ 881{
880 int cpu = dev->id; 882 int cpu = dev->id;
881 int val, rc; 883 int val, rc;
@@ -922,7 +924,8 @@ out:
922static SYSDEV_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store); 924static SYSDEV_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store);
923#endif /* CONFIG_HOTPLUG_CPU */ 925#endif /* CONFIG_HOTPLUG_CPU */
924 926
925static ssize_t cpu_polarization_show(struct sys_device *dev, char *buf) 927static ssize_t cpu_polarization_show(struct sys_device *dev,
928 struct sysdev_attribute *attr, char *buf)
926{ 929{
927 int cpu = dev->id; 930 int cpu = dev->id;
928 ssize_t count; 931 ssize_t count;
@@ -950,7 +953,8 @@ static ssize_t cpu_polarization_show(struct sys_device *dev, char *buf)
950} 953}
951static SYSDEV_ATTR(polarization, 0444, cpu_polarization_show, NULL); 954static SYSDEV_ATTR(polarization, 0444, cpu_polarization_show, NULL);
952 955
953static ssize_t show_cpu_address(struct sys_device *dev, char *buf) 956static ssize_t show_cpu_address(struct sys_device *dev,
957 struct sysdev_attribute *attr, char *buf)
954{ 958{
955 return sprintf(buf, "%d\n", __cpu_logical_map[dev->id]); 959 return sprintf(buf, "%d\n", __cpu_logical_map[dev->id]);
956} 960}
@@ -970,7 +974,8 @@ static struct attribute_group cpu_common_attr_group = {
970 .attrs = cpu_common_attrs, 974 .attrs = cpu_common_attrs,
971}; 975};
972 976
973static ssize_t show_capability(struct sys_device *dev, char *buf) 977static ssize_t show_capability(struct sys_device *dev,
978 struct sysdev_attribute *attr, char *buf)
974{ 979{
975 unsigned int capability; 980 unsigned int capability;
976 int rc; 981 int rc;
@@ -982,7 +987,8 @@ static ssize_t show_capability(struct sys_device *dev, char *buf)
982} 987}
983static SYSDEV_ATTR(capability, 0444, show_capability, NULL); 988static SYSDEV_ATTR(capability, 0444, show_capability, NULL);
984 989
985static ssize_t show_idle_count(struct sys_device *dev, char *buf) 990static ssize_t show_idle_count(struct sys_device *dev,
991 struct sysdev_attribute *attr, char *buf)
986{ 992{
987 struct s390_idle_data *idle; 993 struct s390_idle_data *idle;
988 unsigned long long idle_count; 994 unsigned long long idle_count;
@@ -995,7 +1001,8 @@ static ssize_t show_idle_count(struct sys_device *dev, char *buf)
995} 1001}
996static SYSDEV_ATTR(idle_count, 0444, show_idle_count, NULL); 1002static SYSDEV_ATTR(idle_count, 0444, show_idle_count, NULL);
997 1003
998static ssize_t show_idle_time(struct sys_device *dev, char *buf) 1004static ssize_t show_idle_time(struct sys_device *dev,
1005 struct sysdev_attribute *attr, char *buf)
999{ 1006{
1000 struct s390_idle_data *idle; 1007 struct s390_idle_data *idle;
1001 unsigned long long new_time; 1008 unsigned long long new_time;
@@ -1112,7 +1119,9 @@ out:
1112 return rc; 1119 return rc;
1113} 1120}
1114 1121
1115static ssize_t __ref rescan_store(struct sys_device *dev, const char *buf, 1122static ssize_t __ref rescan_store(struct sys_device *dev,
1123 struct sysdev_attribute *attr,
1124 const char *buf,
1116 size_t count) 1125 size_t count)
1117{ 1126{
1118 int rc; 1127 int rc;
@@ -1123,7 +1132,9 @@ static ssize_t __ref rescan_store(struct sys_device *dev, const char *buf,
1123static SYSDEV_ATTR(rescan, 0200, NULL, rescan_store); 1132static SYSDEV_ATTR(rescan, 0200, NULL, rescan_store);
1124#endif /* CONFIG_HOTPLUG_CPU */ 1133#endif /* CONFIG_HOTPLUG_CPU */
1125 1134
1126static ssize_t dispatching_show(struct sys_device *dev, char *buf) 1135static ssize_t dispatching_show(struct sys_device *dev,
1136 struct sysdev_attribute *attr,
1137 char *buf)
1127{ 1138{
1128 ssize_t count; 1139 ssize_t count;
1129 1140
@@ -1133,8 +1144,9 @@ static ssize_t dispatching_show(struct sys_device *dev, char *buf)
1133 return count; 1144 return count;
1134} 1145}
1135 1146
1136static ssize_t dispatching_store(struct sys_device *dev, const char *buf, 1147static ssize_t dispatching_store(struct sys_device *dev,
1137 size_t count) 1148 struct sysdev_attribute *attr,
1149 const char *buf, size_t count)
1138{ 1150{
1139 int val, rc; 1151 int val, rc;
1140 char delim; 1152 char delim;
diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
index f2cede3947b2..ab70d9bd9261 100644
--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -1100,7 +1100,9 @@ static inline struct etr_aib *etr_aib_from_dev(struct sys_device *dev)
1100 return etr_port1_online ? &etr_port1 : NULL; 1100 return etr_port1_online ? &etr_port1 : NULL;
1101} 1101}
1102 1102
1103static ssize_t etr_online_show(struct sys_device *dev, char *buf) 1103static ssize_t etr_online_show(struct sys_device *dev,
1104 struct sysdev_attribute *attr,
1105 char *buf)
1104{ 1106{
1105 unsigned int online; 1107 unsigned int online;
1106 1108
@@ -1109,7 +1111,8 @@ static ssize_t etr_online_show(struct sys_device *dev, char *buf)
1109} 1111}
1110 1112
1111static ssize_t etr_online_store(struct sys_device *dev, 1113static ssize_t etr_online_store(struct sys_device *dev,
1112 const char *buf, size_t count) 1114 struct sysdev_attribute *attr,
1115 const char *buf, size_t count)
1113{ 1116{
1114 unsigned int value; 1117 unsigned int value;
1115 1118
@@ -1136,7 +1139,9 @@ static ssize_t etr_online_store(struct sys_device *dev,
1136 1139
1137static SYSDEV_ATTR(online, 0600, etr_online_show, etr_online_store); 1140static SYSDEV_ATTR(online, 0600, etr_online_show, etr_online_store);
1138 1141
1139static ssize_t etr_stepping_control_show(struct sys_device *dev, char *buf) 1142static ssize_t etr_stepping_control_show(struct sys_device *dev,
1143 struct sysdev_attribute *attr,
1144 char *buf)
1140{ 1145{
1141 return sprintf(buf, "%i\n", (dev == &etr_port0_dev) ? 1146 return sprintf(buf, "%i\n", (dev == &etr_port0_dev) ?
1142 etr_eacr.e0 : etr_eacr.e1); 1147 etr_eacr.e0 : etr_eacr.e1);
@@ -1144,7 +1149,8 @@ static ssize_t etr_stepping_control_show(struct sys_device *dev, char *buf)
1144 1149
1145static SYSDEV_ATTR(stepping_control, 0400, etr_stepping_control_show, NULL); 1150static SYSDEV_ATTR(stepping_control, 0400, etr_stepping_control_show, NULL);
1146 1151
1147static ssize_t etr_mode_code_show(struct sys_device *dev, char *buf) 1152static ssize_t etr_mode_code_show(struct sys_device *dev,
1153 struct sysdev_attribute *attr, char *buf)
1148{ 1154{
1149 if (!etr_port0_online && !etr_port1_online) 1155 if (!etr_port0_online && !etr_port1_online)
1150 /* Status word is not uptodate if both ports are offline. */ 1156 /* Status word is not uptodate if both ports are offline. */
@@ -1155,7 +1161,8 @@ static ssize_t etr_mode_code_show(struct sys_device *dev, char *buf)
1155 1161
1156static SYSDEV_ATTR(state_code, 0400, etr_mode_code_show, NULL); 1162static SYSDEV_ATTR(state_code, 0400, etr_mode_code_show, NULL);
1157 1163
1158static ssize_t etr_untuned_show(struct sys_device *dev, char *buf) 1164static ssize_t etr_untuned_show(struct sys_device *dev,
1165 struct sysdev_attribute *attr, char *buf)
1159{ 1166{
1160 struct etr_aib *aib = etr_aib_from_dev(dev); 1167 struct etr_aib *aib = etr_aib_from_dev(dev);
1161 1168
@@ -1166,7 +1173,8 @@ static ssize_t etr_untuned_show(struct sys_device *dev, char *buf)
1166 1173
1167static SYSDEV_ATTR(untuned, 0400, etr_untuned_show, NULL); 1174static SYSDEV_ATTR(untuned, 0400, etr_untuned_show, NULL);
1168 1175
1169static ssize_t etr_network_id_show(struct sys_device *dev, char *buf) 1176static ssize_t etr_network_id_show(struct sys_device *dev,
1177 struct sysdev_attribute *attr, char *buf)
1170{ 1178{
1171 struct etr_aib *aib = etr_aib_from_dev(dev); 1179 struct etr_aib *aib = etr_aib_from_dev(dev);
1172 1180
@@ -1177,7 +1185,8 @@ static ssize_t etr_network_id_show(struct sys_device *dev, char *buf)
1177 1185
1178static SYSDEV_ATTR(network, 0400, etr_network_id_show, NULL); 1186static SYSDEV_ATTR(network, 0400, etr_network_id_show, NULL);
1179 1187
1180static ssize_t etr_id_show(struct sys_device *dev, char *buf) 1188static ssize_t etr_id_show(struct sys_device *dev,
1189 struct sysdev_attribute *attr, char *buf)
1181{ 1190{
1182 struct etr_aib *aib = etr_aib_from_dev(dev); 1191 struct etr_aib *aib = etr_aib_from_dev(dev);
1183 1192
@@ -1188,7 +1197,8 @@ static ssize_t etr_id_show(struct sys_device *dev, char *buf)
1188 1197
1189static SYSDEV_ATTR(id, 0400, etr_id_show, NULL); 1198static SYSDEV_ATTR(id, 0400, etr_id_show, NULL);
1190 1199
1191static ssize_t etr_port_number_show(struct sys_device *dev, char *buf) 1200static ssize_t etr_port_number_show(struct sys_device *dev,
1201 struct sysdev_attribute *attr, char *buf)
1192{ 1202{
1193 struct etr_aib *aib = etr_aib_from_dev(dev); 1203 struct etr_aib *aib = etr_aib_from_dev(dev);
1194 1204
@@ -1199,7 +1209,8 @@ static ssize_t etr_port_number_show(struct sys_device *dev, char *buf)
1199 1209
1200static SYSDEV_ATTR(port, 0400, etr_port_number_show, NULL); 1210static SYSDEV_ATTR(port, 0400, etr_port_number_show, NULL);
1201 1211
1202static ssize_t etr_coupled_show(struct sys_device *dev, char *buf) 1212static ssize_t etr_coupled_show(struct sys_device *dev,
1213 struct sysdev_attribute *attr, char *buf)
1203{ 1214{
1204 struct etr_aib *aib = etr_aib_from_dev(dev); 1215 struct etr_aib *aib = etr_aib_from_dev(dev);
1205 1216
@@ -1210,7 +1221,8 @@ static ssize_t etr_coupled_show(struct sys_device *dev, char *buf)
1210 1221
1211static SYSDEV_ATTR(coupled, 0400, etr_coupled_show, NULL); 1222static SYSDEV_ATTR(coupled, 0400, etr_coupled_show, NULL);
1212 1223
1213static ssize_t etr_local_time_show(struct sys_device *dev, char *buf) 1224static ssize_t etr_local_time_show(struct sys_device *dev,
1225 struct sysdev_attribute *attr, char *buf)
1214{ 1226{
1215 struct etr_aib *aib = etr_aib_from_dev(dev); 1227 struct etr_aib *aib = etr_aib_from_dev(dev);
1216 1228
@@ -1221,7 +1233,8 @@ static ssize_t etr_local_time_show(struct sys_device *dev, char *buf)
1221 1233
1222static SYSDEV_ATTR(local_time, 0400, etr_local_time_show, NULL); 1234static SYSDEV_ATTR(local_time, 0400, etr_local_time_show, NULL);
1223 1235
1224static ssize_t etr_utc_offset_show(struct sys_device *dev, char *buf) 1236static ssize_t etr_utc_offset_show(struct sys_device *dev,
1237 struct sysdev_attribute *attr, char *buf)
1225{ 1238{
1226 struct etr_aib *aib = etr_aib_from_dev(dev); 1239 struct etr_aib *aib = etr_aib_from_dev(dev);
1227 1240
diff --git a/arch/sh/drivers/dma/dma-sysfs.c b/arch/sh/drivers/dma/dma-sysfs.c
index 51b57c0d1a3c..347ee11351ec 100644
--- a/arch/sh/drivers/dma/dma-sysfs.c
+++ b/arch/sh/drivers/dma/dma-sysfs.c
@@ -23,7 +23,8 @@ static struct sysdev_class dma_sysclass = {
23}; 23};
24EXPORT_SYMBOL(dma_sysclass); 24EXPORT_SYMBOL(dma_sysclass);
25 25
26static ssize_t dma_show_devices(struct sys_device *dev, char *buf) 26static ssize_t dma_show_devices(struct sys_device *dev,
27 struct sysdev_attribute *attr, char *buf)
27{ 28{
28 ssize_t len = 0; 29 ssize_t len = 0;
29 int i; 30 int i;
@@ -57,13 +58,15 @@ static int __init dma_sysclass_init(void)
57} 58}
58postcore_initcall(dma_sysclass_init); 59postcore_initcall(dma_sysclass_init);
59 60
60static ssize_t dma_show_dev_id(struct sys_device *dev, char *buf) 61static ssize_t dma_show_dev_id(struct sys_device *dev,
62 struct sysdev_attribute *attr, char *buf)
61{ 63{
62 struct dma_channel *channel = to_dma_channel(dev); 64 struct dma_channel *channel = to_dma_channel(dev);
63 return sprintf(buf, "%s\n", channel->dev_id); 65 return sprintf(buf, "%s\n", channel->dev_id);
64} 66}
65 67
66static ssize_t dma_store_dev_id(struct sys_device *dev, 68static ssize_t dma_store_dev_id(struct sys_device *dev,
69 struct sysdev_attribute *attr,
67 const char *buf, size_t count) 70 const char *buf, size_t count)
68{ 71{
69 struct dma_channel *channel = to_dma_channel(dev); 72 struct dma_channel *channel = to_dma_channel(dev);
@@ -74,6 +77,7 @@ static ssize_t dma_store_dev_id(struct sys_device *dev,
74static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id); 77static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
75 78
76static ssize_t dma_store_config(struct sys_device *dev, 79static ssize_t dma_store_config(struct sys_device *dev,
80 struct sysdev_attribute *attr,
77 const char *buf, size_t count) 81 const char *buf, size_t count)
78{ 82{
79 struct dma_channel *channel = to_dma_channel(dev); 83 struct dma_channel *channel = to_dma_channel(dev);
@@ -87,13 +91,15 @@ static ssize_t dma_store_config(struct sys_device *dev,
87 91
88static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config); 92static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
89 93
90static ssize_t dma_show_mode(struct sys_device *dev, char *buf) 94static ssize_t dma_show_mode(struct sys_device *dev,
95 struct sysdev_attribute *attr, char *buf)
91{ 96{
92 struct dma_channel *channel = to_dma_channel(dev); 97 struct dma_channel *channel = to_dma_channel(dev);
93 return sprintf(buf, "0x%08x\n", channel->mode); 98 return sprintf(buf, "0x%08x\n", channel->mode);
94} 99}
95 100
96static ssize_t dma_store_mode(struct sys_device *dev, 101static ssize_t dma_store_mode(struct sys_device *dev,
102 struct sysdev_attribute *attr,
97 const char *buf, size_t count) 103 const char *buf, size_t count)
98{ 104{
99 struct dma_channel *channel = to_dma_channel(dev); 105 struct dma_channel *channel = to_dma_channel(dev);
@@ -104,7 +110,8 @@ static ssize_t dma_store_mode(struct sys_device *dev,
104static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode); 110static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
105 111
106#define dma_ro_attr(field, fmt) \ 112#define dma_ro_attr(field, fmt) \
107static ssize_t dma_show_##field(struct sys_device *dev, char *buf) \ 113static ssize_t dma_show_##field(struct sys_device *dev, \
114 struct sysdev_attribute *attr, char *buf)\
108{ \ 115{ \
109 struct dma_channel *channel = to_dma_channel(dev); \ 116 struct dma_channel *channel = to_dma_channel(dev); \
110 return sprintf(buf, fmt, channel->field); \ 117 return sprintf(buf, fmt, channel->field); \
diff --git a/arch/sparc/kernel/apc.c b/arch/sparc/kernel/apc.c
index 6707422c9847..5267d48fb2c6 100644
--- a/arch/sparc/kernel/apc.c
+++ b/arch/sparc/kernel/apc.c
@@ -56,7 +56,7 @@ __setup("apc=", apc_setup);
56 * CPU idle callback function 56 * CPU idle callback function
57 * See .../arch/sparc/kernel/process.c 57 * See .../arch/sparc/kernel/process.c
58 */ 58 */
59void apc_swift_idle(void) 59static void apc_swift_idle(void)
60{ 60{
61#ifdef APC_DEBUG_LED 61#ifdef APC_DEBUG_LED
62 set_auxio(0x00, AUXIO_LED); 62 set_auxio(0x00, AUXIO_LED);
@@ -85,54 +85,70 @@ static int apc_release(struct inode *inode, struct file *f)
85 return 0; 85 return 0;
86} 86}
87 87
88static int apc_ioctl(struct inode *inode, struct file *f, 88static long apc_ioctl(struct file *f, unsigned int cmd, unsigned long __arg)
89 unsigned int cmd, unsigned long __arg)
90{ 89{
91 __u8 inarg, __user *arg; 90 __u8 inarg, __user *arg;
92 91
93 arg = (__u8 __user *) __arg; 92 arg = (__u8 __user *) __arg;
93
94 lock_kernel();
95
94 switch (cmd) { 96 switch (cmd) {
95 case APCIOCGFANCTL: 97 case APCIOCGFANCTL:
96 if (put_user(apc_readb(APC_FANCTL_REG) & APC_REGMASK, arg)) 98 if (put_user(apc_readb(APC_FANCTL_REG) & APC_REGMASK, arg)) {
97 return -EFAULT; 99 unlock_kernel();
100 return -EFAULT;
101 }
98 break; 102 break;
99 103
100 case APCIOCGCPWR: 104 case APCIOCGCPWR:
101 if (put_user(apc_readb(APC_CPOWER_REG) & APC_REGMASK, arg)) 105 if (put_user(apc_readb(APC_CPOWER_REG) & APC_REGMASK, arg)) {
106 unlock_kernel();
102 return -EFAULT; 107 return -EFAULT;
108 }
103 break; 109 break;
104 110
105 case APCIOCGBPORT: 111 case APCIOCGBPORT:
106 if (put_user(apc_readb(APC_BPORT_REG) & APC_BPMASK, arg)) 112 if (put_user(apc_readb(APC_BPORT_REG) & APC_BPMASK, arg)) {
113 unlock_kernel();
107 return -EFAULT; 114 return -EFAULT;
115 }
108 break; 116 break;
109 117
110 case APCIOCSFANCTL: 118 case APCIOCSFANCTL:
111 if (get_user(inarg, arg)) 119 if (get_user(inarg, arg)) {
120 unlock_kernel();
112 return -EFAULT; 121 return -EFAULT;
122 }
113 apc_writeb(inarg & APC_REGMASK, APC_FANCTL_REG); 123 apc_writeb(inarg & APC_REGMASK, APC_FANCTL_REG);
114 break; 124 break;
115 case APCIOCSCPWR: 125 case APCIOCSCPWR:
116 if (get_user(inarg, arg)) 126 if (get_user(inarg, arg)) {
127 unlock_kernel();
117 return -EFAULT; 128 return -EFAULT;
129 }
118 apc_writeb(inarg & APC_REGMASK, APC_CPOWER_REG); 130 apc_writeb(inarg & APC_REGMASK, APC_CPOWER_REG);
119 break; 131 break;
120 case APCIOCSBPORT: 132 case APCIOCSBPORT:
121 if (get_user(inarg, arg)) 133 if (get_user(inarg, arg)) {
134 unlock_kernel();
122 return -EFAULT; 135 return -EFAULT;
136 }
123 apc_writeb(inarg & APC_BPMASK, APC_BPORT_REG); 137 apc_writeb(inarg & APC_BPMASK, APC_BPORT_REG);
124 break; 138 break;
125 default: 139 default:
140 unlock_kernel();
126 return -EINVAL; 141 return -EINVAL;
127 }; 142 };
128 143
144 unlock_kernel();
129 return 0; 145 return 0;
130} 146}
131 147
132static const struct file_operations apc_fops = { 148static const struct file_operations apc_fops = {
133 .ioctl = apc_ioctl, 149 .unlocked_ioctl = apc_ioctl,
134 .open = apc_open, 150 .open = apc_open,
135 .release = apc_release, 151 .release = apc_release,
136}; 152};
137 153
138static struct miscdevice apc_miscdev = { APC_MINOR, APC_DEVNAME, &apc_fops }; 154static struct miscdevice apc_miscdev = { APC_MINOR, APC_DEVNAME, &apc_fops };
diff --git a/arch/sparc/kernel/asm-offsets.c b/arch/sparc/kernel/asm-offsets.c
index cd3f7694e9b9..b5bb99ed892c 100644
--- a/arch/sparc/kernel/asm-offsets.c
+++ b/arch/sparc/kernel/asm-offsets.c
@@ -18,18 +18,6 @@ int foo(void)
18{ 18{
19 DEFINE(AOFF_task_thread, offsetof(struct task_struct, thread)); 19 DEFINE(AOFF_task_thread, offsetof(struct task_struct, thread));
20 BLANK(); 20 BLANK();
21 /* XXX This is the stuff for sclow.S, kill it. */
22 DEFINE(AOFF_task_pid, offsetof(struct task_struct, pid));
23 DEFINE(AOFF_task_uid, offsetof(struct task_struct, uid));
24 DEFINE(AOFF_task_gid, offsetof(struct task_struct, gid));
25 DEFINE(AOFF_task_euid, offsetof(struct task_struct, euid));
26 DEFINE(AOFF_task_egid, offsetof(struct task_struct, egid));
27 /* DEFINE(THREAD_INFO, offsetof(struct task_struct, stack)); */
28 DEFINE(ASIZ_task_uid, sizeof(current->uid));
29 DEFINE(ASIZ_task_gid, sizeof(current->gid));
30 DEFINE(ASIZ_task_euid, sizeof(current->euid));
31 DEFINE(ASIZ_task_egid, sizeof(current->egid));
32 BLANK();
33 DEFINE(AOFF_thread_fork_kpsr, 21 DEFINE(AOFF_thread_fork_kpsr,
34 offsetof(struct thread_struct, fork_kpsr)); 22 offsetof(struct thread_struct, fork_kpsr));
35 BLANK(); 23 BLANK();
diff --git a/arch/sparc/kernel/ebus.c b/arch/sparc/kernel/ebus.c
index 92c6fc07e59c..97294232259c 100644
--- a/arch/sparc/kernel/ebus.c
+++ b/arch/sparc/kernel/ebus.c
@@ -69,7 +69,7 @@ static inline unsigned long ebus_alloc(size_t size)
69 69
70/* 70/*
71 */ 71 */
72int __init ebus_blacklist_irq(const char *name) 72static int __init ebus_blacklist_irq(const char *name)
73{ 73{
74 struct ebus_device_irq *dp; 74 struct ebus_device_irq *dp;
75 75
@@ -83,8 +83,8 @@ int __init ebus_blacklist_irq(const char *name)
83 return 0; 83 return 0;
84} 84}
85 85
86void __init fill_ebus_child(struct device_node *dp, 86static void __init fill_ebus_child(struct device_node *dp,
87 struct linux_ebus_child *dev) 87 struct linux_ebus_child *dev)
88{ 88{
89 const int *regs; 89 const int *regs;
90 const int *irqs; 90 const int *irqs;
@@ -144,7 +144,8 @@ void __init fill_ebus_child(struct device_node *dp,
144 } 144 }
145} 145}
146 146
147void __init fill_ebus_device(struct device_node *dp, struct linux_ebus_device *dev) 147static void __init fill_ebus_device(struct device_node *dp,
148 struct linux_ebus_device *dev)
148{ 149{
149 const struct linux_prom_registers *regs; 150 const struct linux_prom_registers *regs;
150 struct linux_ebus_child *child; 151 struct linux_ebus_child *child;
diff --git a/arch/sparc/kernel/entry.S b/arch/sparc/kernel/entry.S
index 4bcfe54f878d..2f96256dc515 100644
--- a/arch/sparc/kernel/entry.S
+++ b/arch/sparc/kernel/entry.S
@@ -19,6 +19,7 @@
19#include <asm/vaddrs.h> 19#include <asm/vaddrs.h>
20#include <asm/memreg.h> 20#include <asm/memreg.h>
21#include <asm/page.h> 21#include <asm/page.h>
22#include <asm/pgtable.h>
22#ifdef CONFIG_SUN4 23#ifdef CONFIG_SUN4
23#include <asm/pgtsun4.h> 24#include <asm/pgtsun4.h>
24#else 25#else
@@ -1317,7 +1318,6 @@ linux_sparc_syscall:
1317 bne linux_fast_syscall 1318 bne linux_fast_syscall
1318 /* Just do first insn from SAVE_ALL in the delay slot */ 1319 /* Just do first insn from SAVE_ALL in the delay slot */
1319 1320
1320 .globl syscall_is_too_hard
1321syscall_is_too_hard: 1321syscall_is_too_hard:
1322 SAVE_ALL_HEAD 1322 SAVE_ALL_HEAD
1323 rd %wim, %l3 1323 rd %wim, %l3
@@ -1544,8 +1544,7 @@ kgdb_trap_low:
1544#endif 1544#endif
1545 1545
1546 .align 4 1546 .align 4
1547 .globl __handle_exception, flush_patch_exception 1547 .globl flush_patch_exception
1548__handle_exception:
1549flush_patch_exception: 1548flush_patch_exception:
1550 FLUSH_ALL_KERNEL_WINDOWS; 1549 FLUSH_ALL_KERNEL_WINDOWS;
1551 ldd [%o0], %o6 1550 ldd [%o0], %o6
diff --git a/arch/sparc/kernel/etrap.S b/arch/sparc/kernel/etrap.S
index f37d961d67a6..e806fcdc46db 100644
--- a/arch/sparc/kernel/etrap.S
+++ b/arch/sparc/kernel/etrap.S
@@ -228,7 +228,6 @@ tsetup_mmu_patchme:
228 */ 228 */
229#define glob_tmp g1 229#define glob_tmp g1
230 230
231 .globl tsetup_sun4c_stackchk
232tsetup_sun4c_stackchk: 231tsetup_sun4c_stackchk:
233 /* Done by caller: andcc %sp, 0x7, %g0 */ 232 /* Done by caller: andcc %sp, 0x7, %g0 */
234 bne trap_setup_user_stack_is_bolixed 233 bne trap_setup_user_stack_is_bolixed
diff --git a/arch/sparc/kernel/head.S b/arch/sparc/kernel/head.S
index 3bfd6085a91d..50d9a16af795 100644
--- a/arch/sparc/kernel/head.S
+++ b/arch/sparc/kernel/head.S
@@ -32,7 +32,6 @@
32 */ 32 */
33 33
34 .align 4 34 .align 4
35 .globl cputyp
36cputyp: 35cputyp:
37 .word 1 36 .word 1
38 37
@@ -1280,7 +1279,6 @@ halt_me:
1280 * gets initialized in c-code so all routines can use it. 1279 * gets initialized in c-code so all routines can use it.
1281 */ 1280 */
1282 1281
1283 .globl prom_vector_p
1284prom_vector_p: 1282prom_vector_p:
1285 .word 0 1283 .word 0
1286 1284
diff --git a/arch/sparc/kernel/idprom.c b/arch/sparc/kernel/idprom.c
index 7220562cdb34..fc511f3c4c18 100644
--- a/arch/sparc/kernel/idprom.c
+++ b/arch/sparc/kernel/idprom.c
@@ -24,7 +24,7 @@ static struct idprom idprom_buffer;
24 * of the Sparc CPU and have a meaningful IDPROM machtype value that we 24 * of the Sparc CPU and have a meaningful IDPROM machtype value that we
25 * know about. See asm-sparc/machines.h for empirical constants. 25 * know about. See asm-sparc/machines.h for empirical constants.
26 */ 26 */
27struct Sun_Machine_Models Sun_Machines[NUM_SUN_MACHINES] = { 27static struct Sun_Machine_Models Sun_Machines[NUM_SUN_MACHINES] = {
28/* First, Sun4's */ 28/* First, Sun4's */
29{ "Sun 4/100 Series", (SM_SUN4 | SM_4_110) }, 29{ "Sun 4/100 Series", (SM_SUN4 | SM_4_110) },
30{ "Sun 4/200 Series", (SM_SUN4 | SM_4_260) }, 30{ "Sun 4/200 Series", (SM_SUN4 | SM_4_260) },
diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c
index 7b17522f59bf..487960919f1f 100644
--- a/arch/sparc/kernel/ioport.c
+++ b/arch/sparc/kernel/ioport.c
@@ -49,13 +49,16 @@
49 49
50#define mmu_inval_dma_area(p, l) /* Anton pulled it out for 2.4.0-xx */ 50#define mmu_inval_dma_area(p, l) /* Anton pulled it out for 2.4.0-xx */
51 51
52struct resource *_sparc_find_resource(struct resource *r, unsigned long); 52static struct resource *_sparc_find_resource(struct resource *r,
53 unsigned long);
53 54
54static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz); 55static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz);
55static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys, 56static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
56 unsigned long size, char *name); 57 unsigned long size, char *name);
57static void _sparc_free_io(struct resource *res); 58static void _sparc_free_io(struct resource *res);
58 59
60static void register_proc_sparc_ioport(void);
61
59/* This points to the next to use virtual memory for DVMA mappings */ 62/* This points to the next to use virtual memory for DVMA mappings */
60static struct resource _sparc_dvma = { 63static struct resource _sparc_dvma = {
61 .name = "sparc_dvma", .start = DVMA_VADDR, .end = DVMA_END - 1 64 .name = "sparc_dvma", .start = DVMA_VADDR, .end = DVMA_END - 1
@@ -539,8 +542,6 @@ void __init sbus_setup_arch_props(struct sbus_bus *sbus, struct device_node *dp)
539 542
540int __init sbus_arch_preinit(void) 543int __init sbus_arch_preinit(void)
541{ 544{
542 extern void register_proc_sparc_ioport(void);
543
544 register_proc_sparc_ioport(); 545 register_proc_sparc_ioport();
545 546
546#ifdef CONFIG_SUN4 547#ifdef CONFIG_SUN4
@@ -853,8 +854,8 @@ _sparc_io_get_info(char *buf, char **start, off_t fpos, int length, int *eof,
853 * XXX Too slow. Can have 8192 DVMA pages on sun4m in the worst case. 854 * XXX Too slow. Can have 8192 DVMA pages on sun4m in the worst case.
854 * This probably warrants some sort of hashing. 855 * This probably warrants some sort of hashing.
855 */ 856 */
856struct resource * 857static struct resource *_sparc_find_resource(struct resource *root,
857_sparc_find_resource(struct resource *root, unsigned long hit) 858 unsigned long hit)
858{ 859{
859 struct resource *tmp; 860 struct resource *tmp;
860 861
@@ -865,7 +866,7 @@ _sparc_find_resource(struct resource *root, unsigned long hit)
865 return NULL; 866 return NULL;
866} 867}
867 868
868void register_proc_sparc_ioport(void) 869static void register_proc_sparc_ioport(void)
869{ 870{
870#ifdef CONFIG_PROC_FS 871#ifdef CONFIG_PROC_FS
871 create_proc_read_entry("io_map",0,NULL,_sparc_io_get_info,&sparc_iomap); 872 create_proc_read_entry("io_map",0,NULL,_sparc_io_get_info,&sparc_iomap);
diff --git a/arch/sparc/kernel/irq.c b/arch/sparc/kernel/irq.c
index 087390b092b0..93e1d1c65290 100644
--- a/arch/sparc/kernel/irq.c
+++ b/arch/sparc/kernel/irq.c
@@ -154,7 +154,7 @@ void (*sparc_init_timers)(irq_handler_t ) =
154struct irqaction static_irqaction[MAX_STATIC_ALLOC]; 154struct irqaction static_irqaction[MAX_STATIC_ALLOC];
155int static_irq_count; 155int static_irq_count;
156 156
157struct { 157static struct {
158 struct irqaction *action; 158 struct irqaction *action;
159 int flags; 159 int flags;
160} sparc_irq[NR_IRQS]; 160} sparc_irq[NR_IRQS];
diff --git a/arch/sparc/kernel/process.c b/arch/sparc/kernel/process.c
index da48d248cc17..4bb430940a61 100644
--- a/arch/sparc/kernel/process.c
+++ b/arch/sparc/kernel/process.c
@@ -1,6 +1,6 @@
1/* linux/arch/sparc/kernel/process.c 1/* linux/arch/sparc/kernel/process.c
2 * 2 *
3 * Copyright (C) 1995 David S. Miller (davem@davemloft.net) 3 * Copyright (C) 1995, 2008 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be) 4 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
5 */ 5 */
6 6
@@ -14,7 +14,6 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/kallsyms.h>
18#include <linux/mm.h> 17#include <linux/mm.h>
19#include <linux/stddef.h> 18#include <linux/stddef.h>
20#include <linux/ptrace.h> 19#include <linux/ptrace.h>
@@ -177,6 +176,8 @@ void machine_power_off(void)
177 machine_halt(); 176 machine_halt();
178} 177}
179 178
179#if 0
180
180static DEFINE_SPINLOCK(sparc_backtrace_lock); 181static DEFINE_SPINLOCK(sparc_backtrace_lock);
181 182
182void __show_backtrace(unsigned long fp) 183void __show_backtrace(unsigned long fp)
@@ -196,7 +197,7 @@ void __show_backtrace(unsigned long fp)
196 rw->ins[4], rw->ins[5], 197 rw->ins[4], rw->ins[5],
197 rw->ins[6], 198 rw->ins[6],
198 rw->ins[7]); 199 rw->ins[7]);
199 print_symbol("%s\n", rw->ins[7]); 200 printk("%pS\n", (void *) rw->ins[7]);
200 rw = (struct reg_window *) rw->ins[6]; 201 rw = (struct reg_window *) rw->ins[6];
201 } 202 }
202 spin_unlock_irqrestore(&sparc_backtrace_lock, flags); 203 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
@@ -228,7 +229,6 @@ void smp_show_backtrace_all_cpus(void)
228} 229}
229#endif 230#endif
230 231
231#if 0
232void show_stackframe(struct sparc_stackf *sf) 232void show_stackframe(struct sparc_stackf *sf)
233{ 233{
234 unsigned long size; 234 unsigned long size;
@@ -264,14 +264,14 @@ void show_regs(struct pt_regs *r)
264 264
265 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n", 265 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
266 r->psr, r->pc, r->npc, r->y, print_tainted()); 266 r->psr, r->pc, r->npc, r->y, print_tainted());
267 print_symbol("PC: <%s>\n", r->pc); 267 printk("PC: <%pS>\n", (void *) r->pc);
268 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", 268 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
269 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3], 269 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
270 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]); 270 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
271 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", 271 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
272 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11], 272 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
273 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]); 273 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
274 print_symbol("RPC: <%s>\n", r->u_regs[15]); 274 printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
275 275
276 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", 276 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
277 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3], 277 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
@@ -306,7 +306,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
306 rw = (struct reg_window *) fp; 306 rw = (struct reg_window *) fp;
307 pc = rw->ins[7]; 307 pc = rw->ins[7];
308 printk("[%08lx : ", pc); 308 printk("[%08lx : ", pc);
309 print_symbol("%s ] ", pc); 309 printk("%pS ] ", (void *) pc);
310 fp = rw->ins[6]; 310 fp = rw->ins[6];
311 } while (++count < 16); 311 } while (++count < 16);
312 printk("\n"); 312 printk("\n");
diff --git a/arch/sparc/kernel/rtrap.S b/arch/sparc/kernel/rtrap.S
index ce30082ab266..891f460b7b96 100644
--- a/arch/sparc/kernel/rtrap.S
+++ b/arch/sparc/kernel/rtrap.S
@@ -224,8 +224,6 @@ ret_trap_user_stack_is_bolixed:
224 b signal_p 224 b signal_p
225 ld [%curptr + TI_FLAGS], %g2 225 ld [%curptr + TI_FLAGS], %g2
226 226
227
228 .globl sun4c_rett_stackchk
229sun4c_rett_stackchk: 227sun4c_rett_stackchk:
230 be 1f 228 be 1f
231 and %fp, 0xfff, %g1 ! delay slot 229 and %fp, 0xfff, %g1 ! delay slot
diff --git a/arch/sparc/kernel/setup.c b/arch/sparc/kernel/setup.c
index a0ea0bc6f471..9e451b21202e 100644
--- a/arch/sparc/kernel/setup.c
+++ b/arch/sparc/kernel/setup.c
@@ -67,7 +67,7 @@ struct screen_info screen_info = {
67extern unsigned long trapbase; 67extern unsigned long trapbase;
68 68
69/* Pretty sick eh? */ 69/* Pretty sick eh? */
70void prom_sync_me(void) 70static void prom_sync_me(void)
71{ 71{
72 unsigned long prom_tbr, flags; 72 unsigned long prom_tbr, flags;
73 73
@@ -97,7 +97,7 @@ void prom_sync_me(void)
97 return; 97 return;
98} 98}
99 99
100unsigned int boot_flags __initdata = 0; 100static unsigned int boot_flags __initdata = 0;
101#define BOOTME_DEBUG 0x1 101#define BOOTME_DEBUG 0x1
102 102
103/* Exported for mm/init.c:paging_init. */ 103/* Exported for mm/init.c:paging_init. */
diff --git a/arch/sparc/kernel/smp.c b/arch/sparc/kernel/smp.c
index 6724ab90f82b..1619ec15c099 100644
--- a/arch/sparc/kernel/smp.c
+++ b/arch/sparc/kernel/smp.c
@@ -35,13 +35,9 @@
35 35
36#include "irq.h" 36#include "irq.h"
37 37
38int smp_num_cpus = 1;
39volatile unsigned long cpu_callin_map[NR_CPUS] __initdata = {0,}; 38volatile unsigned long cpu_callin_map[NR_CPUS] __initdata = {0,};
40unsigned char boot_cpu_id = 0; 39unsigned char boot_cpu_id = 0;
41unsigned char boot_cpu_id4 = 0; /* boot_cpu_id << 2 */ 40unsigned char boot_cpu_id4 = 0; /* boot_cpu_id << 2 */
42int smp_activated = 0;
43volatile int __cpu_number_map[NR_CPUS];
44volatile int __cpu_logical_map[NR_CPUS];
45 41
46cpumask_t cpu_online_map = CPU_MASK_NONE; 42cpumask_t cpu_online_map = CPU_MASK_NONE;
47cpumask_t phys_cpu_present_map = CPU_MASK_NONE; 43cpumask_t phys_cpu_present_map = CPU_MASK_NONE;
@@ -55,9 +51,6 @@ cpumask_t smp_commenced_mask = CPU_MASK_NONE;
55 * instruction which is much better... 51 * instruction which is much better...
56 */ 52 */
57 53
58/* Used to make bitops atomic */
59unsigned char bitops_spinlock = 0;
60
61void __cpuinit smp_store_cpu_info(int id) 54void __cpuinit smp_store_cpu_info(int id)
62{ 55{
63 int cpu_node; 56 int cpu_node;
diff --git a/arch/sparc/kernel/sun4c_irq.c b/arch/sparc/kernel/sun4c_irq.c
index c6ac9fc52563..340fc395fe2d 100644
--- a/arch/sparc/kernel/sun4c_irq.c
+++ b/arch/sparc/kernel/sun4c_irq.c
@@ -68,7 +68,8 @@ unsigned char *interrupt_enable = NULL;
68 68
69static int sun4c_pil_map[] = { 0, 1, 2, 3, 5, 7, 8, 9 }; 69static int sun4c_pil_map[] = { 0, 1, 2, 3, 5, 7, 8, 9 };
70 70
71unsigned int sun4c_sbint_to_irq(struct sbus_dev *sdev, unsigned int sbint) 71static unsigned int sun4c_sbint_to_irq(struct sbus_dev *sdev,
72 unsigned int sbint)
72{ 73{
73 if (sbint >= sizeof(sun4c_pil_map)) { 74 if (sbint >= sizeof(sun4c_pil_map)) {
74 printk(KERN_ERR "%s: bogus SBINT %d\n", sdev->prom_name, sbint); 75 printk(KERN_ERR "%s: bogus SBINT %d\n", sdev->prom_name, sbint);
diff --git a/arch/sparc/kernel/sun4d_irq.c b/arch/sparc/kernel/sun4d_irq.c
index 8ac5661cafff..1290b5998f83 100644
--- a/arch/sparc/kernel/sun4d_irq.c
+++ b/arch/sparc/kernel/sun4d_irq.c
@@ -52,13 +52,13 @@ extern struct irqaction static_irqaction[MAX_STATIC_ALLOC];
52extern int static_irq_count; 52extern int static_irq_count;
53unsigned char cpu_leds[32]; 53unsigned char cpu_leds[32];
54#ifdef CONFIG_SMP 54#ifdef CONFIG_SMP
55unsigned char sbus_tid[32]; 55static unsigned char sbus_tid[32];
56#endif 56#endif
57 57
58static struct irqaction *irq_action[NR_IRQS]; 58static struct irqaction *irq_action[NR_IRQS];
59extern spinlock_t irq_action_lock; 59extern spinlock_t irq_action_lock;
60 60
61struct sbus_action { 61static struct sbus_action {
62 struct irqaction *action; 62 struct irqaction *action;
63 /* For SMP this needs to be extended */ 63 /* For SMP this needs to be extended */
64} *sbus_actions; 64} *sbus_actions;
@@ -267,7 +267,8 @@ unsigned int sun4d_build_irq(struct sbus_dev *sdev, int irq)
267 return irq; 267 return irq;
268} 268}
269 269
270unsigned int sun4d_sbint_to_irq(struct sbus_dev *sdev, unsigned int sbint) 270static unsigned int sun4d_sbint_to_irq(struct sbus_dev *sdev,
271 unsigned int sbint)
271{ 272{
272 if (sbint >= sizeof(sbus_to_pil)) { 273 if (sbint >= sizeof(sbus_to_pil)) {
273 printk(KERN_ERR "%s: bogus SBINT %d\n", sdev->prom_name, sbint); 274 printk(KERN_ERR "%s: bogus SBINT %d\n", sdev->prom_name, sbint);
diff --git a/arch/sparc/kernel/sun4m_irq.c b/arch/sparc/kernel/sun4m_irq.c
index b92d6d2d5b04..94e02de960ea 100644
--- a/arch/sparc/kernel/sun4m_irq.c
+++ b/arch/sparc/kernel/sun4m_irq.c
@@ -154,7 +154,8 @@ static unsigned long irq_mask[] = {
154 154
155static int sun4m_pil_map[] = { 0, 2, 3, 5, 7, 9, 11, 13 }; 155static int sun4m_pil_map[] = { 0, 2, 3, 5, 7, 9, 11, 13 };
156 156
157unsigned int sun4m_sbint_to_irq(struct sbus_dev *sdev, unsigned int sbint) 157static unsigned int sun4m_sbint_to_irq(struct sbus_dev *sdev,
158 unsigned int sbint)
158{ 159{
159 if (sbint >= sizeof(sun4m_pil_map)) { 160 if (sbint >= sizeof(sun4m_pil_map)) {
160 printk(KERN_ERR "%s: bogus SBINT %d\n", sdev->prom_name, sbint); 161 printk(KERN_ERR "%s: bogus SBINT %d\n", sdev->prom_name, sbint);
@@ -163,7 +164,7 @@ unsigned int sun4m_sbint_to_irq(struct sbus_dev *sdev, unsigned int sbint)
163 return sun4m_pil_map[sbint] | 0x30; 164 return sun4m_pil_map[sbint] | 0x30;
164} 165}
165 166
166inline unsigned long sun4m_get_irqmask(unsigned int irq) 167static unsigned long sun4m_get_irqmask(unsigned int irq)
167{ 168{
168 unsigned long mask; 169 unsigned long mask;
169 170
@@ -281,7 +282,7 @@ static void sun4m_set_udt(int cpu)
281#define TIMER_IRQ (OBIO_INTR | 10) 282#define TIMER_IRQ (OBIO_INTR | 10)
282#define PROFILE_IRQ (OBIO_INTR | 14) 283#define PROFILE_IRQ (OBIO_INTR | 14)
283 284
284struct sun4m_timer_regs *sun4m_timers; 285static struct sun4m_timer_regs *sun4m_timers;
285unsigned int lvl14_resolution = (((1000000/HZ) + 1) << 10); 286unsigned int lvl14_resolution = (((1000000/HZ) + 1) << 10);
286 287
287static void sun4m_clear_clock_irq(void) 288static void sun4m_clear_clock_irq(void)
diff --git a/arch/sparc/kernel/sun4m_smp.c b/arch/sparc/kernel/sun4m_smp.c
index ffb875aacb7e..406ac1abc83a 100644
--- a/arch/sparc/kernel/sun4m_smp.c
+++ b/arch/sparc/kernel/sun4m_smp.c
@@ -244,8 +244,9 @@ static struct smp_funcall {
244static DEFINE_SPINLOCK(cross_call_lock); 244static DEFINE_SPINLOCK(cross_call_lock);
245 245
246/* Cross calls must be serialized, at least currently. */ 246/* Cross calls must be serialized, at least currently. */
247void smp4m_cross_call(smpfunc_t func, unsigned long arg1, unsigned long arg2, 247static void smp4m_cross_call(smpfunc_t func, unsigned long arg1,
248 unsigned long arg3, unsigned long arg4, unsigned long arg5) 248 unsigned long arg2, unsigned long arg3,
249 unsigned long arg4, unsigned long arg5)
249{ 250{
250 register int ncpus = SUN4M_NCPUS; 251 register int ncpus = SUN4M_NCPUS;
251 unsigned long flags; 252 unsigned long flags;
@@ -344,7 +345,7 @@ static void __init smp_setup_percpu_timer(void)
344 enable_pil_irq(14); 345 enable_pil_irq(14);
345} 346}
346 347
347void __init smp4m_blackbox_id(unsigned *addr) 348static void __init smp4m_blackbox_id(unsigned *addr)
348{ 349{
349 int rd = *addr & 0x3e000000; 350 int rd = *addr & 0x3e000000;
350 int rs1 = rd >> 11; 351 int rs1 = rd >> 11;
@@ -354,7 +355,7 @@ void __init smp4m_blackbox_id(unsigned *addr)
354 addr[2] = 0x80082003 | rd | rs1; /* and reg, 3, reg */ 355 addr[2] = 0x80082003 | rd | rs1; /* and reg, 3, reg */
355} 356}
356 357
357void __init smp4m_blackbox_current(unsigned *addr) 358static void __init smp4m_blackbox_current(unsigned *addr)
358{ 359{
359 int rd = *addr & 0x3e000000; 360 int rd = *addr & 0x3e000000;
360 int rs1 = rd >> 11; 361 int rs1 = rd >> 11;
diff --git a/arch/sparc/kernel/time.c b/arch/sparc/kernel/time.c
index 53caacbb3982..ab3dd0b257d3 100644
--- a/arch/sparc/kernel/time.c
+++ b/arch/sparc/kernel/time.c
@@ -46,7 +46,7 @@
46#include "irq.h" 46#include "irq.h"
47 47
48DEFINE_SPINLOCK(rtc_lock); 48DEFINE_SPINLOCK(rtc_lock);
49enum sparc_clock_type sp_clock_typ; 49static enum sparc_clock_type sp_clock_typ;
50DEFINE_SPINLOCK(mostek_lock); 50DEFINE_SPINLOCK(mostek_lock);
51void __iomem *mstk48t02_regs = NULL; 51void __iomem *mstk48t02_regs = NULL;
52static struct mostek48t08 __iomem *mstk48t08_regs = NULL; 52static struct mostek48t08 __iomem *mstk48t08_regs = NULL;
@@ -366,7 +366,7 @@ static int __init clock_init(void)
366fs_initcall(clock_init); 366fs_initcall(clock_init);
367#endif /* !CONFIG_SUN4 */ 367#endif /* !CONFIG_SUN4 */
368 368
369void __init sbus_time_init(void) 369static void __init sbus_time_init(void)
370{ 370{
371 371
372 BTFIXUPSET_CALL(bus_do_settimeofday, sbus_do_settimeofday, BTFIXUPCALL_NORM); 372 BTFIXUPSET_CALL(bus_do_settimeofday, sbus_do_settimeofday, BTFIXUPCALL_NORM);
diff --git a/arch/sparc/kernel/traps.c b/arch/sparc/kernel/traps.c
index 978e9d85949e..5d45d5fd8c99 100644
--- a/arch/sparc/kernel/traps.c
+++ b/arch/sparc/kernel/traps.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * arch/sparc/kernel/traps.c 2 * arch/sparc/kernel/traps.c
3 * 3 *
4 * Copyright 1995 David S. Miller (davem@caip.rutgers.edu) 4 * Copyright 1995, 2008 David S. Miller (davem@davemloft.net)
5 * Copyright 2000 Jakub Jelinek (jakub@redhat.com) 5 * Copyright 2000 Jakub Jelinek (jakub@redhat.com)
6 */ 6 */
7 7
@@ -11,7 +11,6 @@
11 11
12#include <linux/sched.h> /* for jiffies */ 12#include <linux/sched.h> /* for jiffies */
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/kallsyms.h>
15#include <linux/signal.h> 14#include <linux/signal.h>
16#include <linux/smp.h> 15#include <linux/smp.h>
17#include <linux/smp_lock.h> 16#include <linux/smp_lock.h>
@@ -33,9 +32,6 @@ struct trap_trace_entry {
33 unsigned long type; 32 unsigned long type;
34}; 33};
35 34
36int trap_curbuf = 0;
37struct trap_trace_entry trapbuf[1024];
38
39void syscall_trace_entry(struct pt_regs *regs) 35void syscall_trace_entry(struct pt_regs *regs)
40{ 36{
41 printk("%s[%d]: ", current->comm, task_pid_nr(current)); 37 printk("%s[%d]: ", current->comm, task_pid_nr(current));
@@ -72,7 +68,7 @@ void sun4d_nmi(struct pt_regs *regs)
72 prom_halt(); 68 prom_halt();
73} 69}
74 70
75void instruction_dump (unsigned long *pc) 71static void instruction_dump(unsigned long *pc)
76{ 72{
77 int i; 73 int i;
78 74
@@ -119,8 +115,8 @@ void die_if_kernel(char *str, struct pt_regs *regs)
119 count++ < 30 && 115 count++ < 30 &&
120 (((unsigned long) rw) >= PAGE_OFFSET) && 116 (((unsigned long) rw) >= PAGE_OFFSET) &&
121 !(((unsigned long) rw) & 0x7)) { 117 !(((unsigned long) rw) & 0x7)) {
122 printk("Caller[%08lx]", rw->ins[7]); 118 printk("Caller[%08lx]: %pS\n", rw->ins[7],
123 print_symbol(": %s\n", rw->ins[7]); 119 (void *) rw->ins[7]);
124 rw = (struct reg_window *)rw->ins[6]; 120 rw = (struct reg_window *)rw->ins[6];
125 } 121 }
126 } 122 }
@@ -479,10 +475,6 @@ void do_BUG(const char *file, int line)
479 475
480extern void sparc_cpu_startup(void); 476extern void sparc_cpu_startup(void);
481 477
482int linux_smp_still_initting;
483unsigned int thiscpus_tbr;
484int thiscpus_mid;
485
486void trap_init(void) 478void trap_init(void)
487{ 479{
488 extern void thread_info_offsets_are_bolixed_pete(void); 480 extern void thread_info_offsets_are_bolixed_pete(void);
diff --git a/arch/sparc/kernel/wof.S b/arch/sparc/kernel/wof.S
index 4bce38dfe3c5..3bbcd8dc9abf 100644
--- a/arch/sparc/kernel/wof.S
+++ b/arch/sparc/kernel/wof.S
@@ -306,7 +306,6 @@ spwin_bad_ustack_from_kernel:
306 * As noted above %curptr cannot be touched by this routine at all. 306 * As noted above %curptr cannot be touched by this routine at all.
307 */ 307 */
308 308
309 .globl spwin_sun4c_stackchk
310spwin_sun4c_stackchk: 309spwin_sun4c_stackchk:
311 /* LOCATION: Window to be saved on the stack */ 310 /* LOCATION: Window to be saved on the stack */
312 311
diff --git a/arch/sparc/kernel/wuf.S b/arch/sparc/kernel/wuf.S
index 82e5145b0f77..779ff750603d 100644
--- a/arch/sparc/kernel/wuf.S
+++ b/arch/sparc/kernel/wuf.S
@@ -243,7 +243,6 @@ fwin_user_finish_up:
243 */ 243 */
244 244
245 .align 4 245 .align 4
246 .globl sun4c_fwin_stackchk
247sun4c_fwin_stackchk: 246sun4c_fwin_stackchk:
248 /* LOCATION: Window 'W' */ 247 /* LOCATION: Window 'W' */
249 248
diff --git a/arch/sparc/mm/fault.c b/arch/sparc/mm/fault.c
index 0a3cd8f6cfe4..3604c2e86709 100644
--- a/arch/sparc/mm/fault.c
+++ b/arch/sparc/mm/fault.c
@@ -451,7 +451,7 @@ asmlinkage void do_sun4c_fault(struct pt_regs *regs, int text_fault, int write,
451} 451}
452 452
453/* This always deals with user addresses. */ 453/* This always deals with user addresses. */
454inline void force_user_fault(unsigned long address, int write) 454static void force_user_fault(unsigned long address, int write)
455{ 455{
456 struct vm_area_struct *vma; 456 struct vm_area_struct *vma;
457 struct task_struct *tsk = current; 457 struct task_struct *tsk = current;
diff --git a/arch/sparc/mm/init.c b/arch/sparc/mm/init.c
index 7794ecb896e3..e103f1bb3777 100644
--- a/arch/sparc/mm/init.c
+++ b/arch/sparc/mm/init.c
@@ -22,6 +22,7 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/highmem.h> 23#include <linux/highmem.h>
24#include <linux/bootmem.h> 24#include <linux/bootmem.h>
25#include <linux/pagemap.h>
25 26
26#include <asm/system.h> 27#include <asm/system.h>
27#include <asm/vac-ops.h> 28#include <asm/vac-ops.h>
@@ -128,7 +129,7 @@ unsigned long calc_highpages(void)
128 return nr; 129 return nr;
129} 130}
130 131
131unsigned long calc_max_low_pfn(void) 132static unsigned long calc_max_low_pfn(void)
132{ 133{
133 int i; 134 int i;
134 unsigned long tmp = pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT); 135 unsigned long tmp = pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT);
@@ -292,7 +293,7 @@ unsigned long __init bootmem_init(unsigned long *pages_avail)
292 * 293 *
293 * We simply copy the 2.4 implementation for now. 294 * We simply copy the 2.4 implementation for now.
294 */ 295 */
295int pgt_cache_water[2] = { 25, 50 }; 296static int pgt_cache_water[2] = { 25, 50 };
296 297
297void check_pgt_cache(void) 298void check_pgt_cache(void)
298{ 299{
@@ -356,8 +357,6 @@ void __init paging_init(void)
356 device_scan(); 357 device_scan();
357} 358}
358 359
359struct cache_palias *sparc_aliases;
360
361static void __init taint_real_pages(void) 360static void __init taint_real_pages(void)
362{ 361{
363 int i; 362 int i;
@@ -375,7 +374,7 @@ static void __init taint_real_pages(void)
375 } 374 }
376} 375}
377 376
378void map_high_region(unsigned long start_pfn, unsigned long end_pfn) 377static void map_high_region(unsigned long start_pfn, unsigned long end_pfn)
379{ 378{
380 unsigned long tmp; 379 unsigned long tmp;
381 380
diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
index 23d3291a3e81..c624e04ff03e 100644
--- a/arch/sparc/mm/srmmu.c
+++ b/arch/sparc/mm/srmmu.c
@@ -50,7 +50,7 @@
50#include <asm/btfixup.h> 50#include <asm/btfixup.h>
51 51
52enum mbus_module srmmu_modtype; 52enum mbus_module srmmu_modtype;
53unsigned int hwbug_bitmask; 53static unsigned int hwbug_bitmask;
54int vac_cache_size; 54int vac_cache_size;
55int vac_line_size; 55int vac_line_size;
56 56
@@ -60,7 +60,7 @@ extern unsigned long last_valid_pfn;
60 60
61extern unsigned long page_kernel; 61extern unsigned long page_kernel;
62 62
63pgd_t *srmmu_swapper_pg_dir; 63static pgd_t *srmmu_swapper_pg_dir;
64 64
65#ifdef CONFIG_SMP 65#ifdef CONFIG_SMP
66#define FLUSH_BEGIN(mm) 66#define FLUSH_BEGIN(mm)
@@ -83,12 +83,12 @@ BTFIXUPDEF_CALL(void, local_flush_page_for_dma, unsigned long)
83char *srmmu_name; 83char *srmmu_name;
84 84
85ctxd_t *srmmu_ctx_table_phys; 85ctxd_t *srmmu_ctx_table_phys;
86ctxd_t *srmmu_context_table; 86static ctxd_t *srmmu_context_table;
87 87
88int viking_mxcc_present; 88int viking_mxcc_present;
89static DEFINE_SPINLOCK(srmmu_context_spinlock); 89static DEFINE_SPINLOCK(srmmu_context_spinlock);
90 90
91int is_hypersparc; 91static int is_hypersparc;
92 92
93/* 93/*
94 * In general all page table modifications should use the V8 atomic 94 * In general all page table modifications should use the V8 atomic
@@ -112,11 +112,11 @@ static inline int srmmu_device_memory(unsigned long x)
112 return ((x & 0xF0000000) != 0); 112 return ((x & 0xF0000000) != 0);
113} 113}
114 114
115int srmmu_cache_pagetables; 115static int srmmu_cache_pagetables;
116 116
117/* these will be initialized in srmmu_nocache_calcsize() */ 117/* these will be initialized in srmmu_nocache_calcsize() */
118unsigned long srmmu_nocache_size; 118static unsigned long srmmu_nocache_size;
119unsigned long srmmu_nocache_end; 119static unsigned long srmmu_nocache_end;
120 120
121/* 1 bit <=> 256 bytes of nocache <=> 64 PTEs */ 121/* 1 bit <=> 256 bytes of nocache <=> 64 PTEs */
122#define SRMMU_NOCACHE_BITMAP_SHIFT (PAGE_SHIFT - 4) 122#define SRMMU_NOCACHE_BITMAP_SHIFT (PAGE_SHIFT - 4)
@@ -324,7 +324,7 @@ static unsigned long __srmmu_get_nocache(int size, int align)
324 return (SRMMU_NOCACHE_VADDR + (offset << SRMMU_NOCACHE_BITMAP_SHIFT)); 324 return (SRMMU_NOCACHE_VADDR + (offset << SRMMU_NOCACHE_BITMAP_SHIFT));
325} 325}
326 326
327unsigned inline long srmmu_get_nocache(int size, int align) 327static unsigned long srmmu_get_nocache(int size, int align)
328{ 328{
329 unsigned long tmp; 329 unsigned long tmp;
330 330
@@ -336,7 +336,7 @@ unsigned inline long srmmu_get_nocache(int size, int align)
336 return tmp; 336 return tmp;
337} 337}
338 338
339void srmmu_free_nocache(unsigned long vaddr, int size) 339static void srmmu_free_nocache(unsigned long vaddr, int size)
340{ 340{
341 int offset; 341 int offset;
342 342
@@ -369,7 +369,8 @@ void srmmu_free_nocache(unsigned long vaddr, int size)
369 bit_map_clear(&srmmu_nocache_map, offset, size); 369 bit_map_clear(&srmmu_nocache_map, offset, size);
370} 370}
371 371
372void srmmu_early_allocate_ptable_skeleton(unsigned long start, unsigned long end); 372static void srmmu_early_allocate_ptable_skeleton(unsigned long start,
373 unsigned long end);
373 374
374extern unsigned long probe_memory(void); /* in fault.c */ 375extern unsigned long probe_memory(void); /* in fault.c */
375 376
@@ -377,7 +378,7 @@ extern unsigned long probe_memory(void); /* in fault.c */
377 * Reserve nocache dynamically proportionally to the amount of 378 * Reserve nocache dynamically proportionally to the amount of
378 * system RAM. -- Tomas Szepe <szepe@pinerecords.com>, June 2002 379 * system RAM. -- Tomas Szepe <szepe@pinerecords.com>, June 2002
379 */ 380 */
380void srmmu_nocache_calcsize(void) 381static void srmmu_nocache_calcsize(void)
381{ 382{
382 unsigned long sysmemavail = probe_memory() / 1024; 383 unsigned long sysmemavail = probe_memory() / 1024;
383 int srmmu_nocache_npages; 384 int srmmu_nocache_npages;
@@ -398,7 +399,7 @@ void srmmu_nocache_calcsize(void)
398 srmmu_nocache_end = SRMMU_NOCACHE_VADDR + srmmu_nocache_size; 399 srmmu_nocache_end = SRMMU_NOCACHE_VADDR + srmmu_nocache_size;
399} 400}
400 401
401void __init srmmu_nocache_init(void) 402static void __init srmmu_nocache_init(void)
402{ 403{
403 unsigned int bitmap_bits; 404 unsigned int bitmap_bits;
404 pgd_t *pgd; 405 pgd_t *pgd;
@@ -645,7 +646,7 @@ static void srmmu_unmapiorange(unsigned long virt_addr, unsigned int len)
645 * mappings on the kernel stack without any special code as we did 646 * mappings on the kernel stack without any special code as we did
646 * need on the sun4c. 647 * need on the sun4c.
647 */ 648 */
648struct thread_info *srmmu_alloc_thread_info(void) 649static struct thread_info *srmmu_alloc_thread_info(void)
649{ 650{
650 struct thread_info *ret; 651 struct thread_info *ret;
651 652
@@ -1045,13 +1046,14 @@ extern void hypersparc_setup_blockops(void);
1045 * around 8mb mapped for us. 1046 * around 8mb mapped for us.
1046 */ 1047 */
1047 1048
1048void __init early_pgtable_allocfail(char *type) 1049static void __init early_pgtable_allocfail(char *type)
1049{ 1050{
1050 prom_printf("inherit_prom_mappings: Cannot alloc kernel %s.\n", type); 1051 prom_printf("inherit_prom_mappings: Cannot alloc kernel %s.\n", type);
1051 prom_halt(); 1052 prom_halt();
1052} 1053}
1053 1054
1054void __init srmmu_early_allocate_ptable_skeleton(unsigned long start, unsigned long end) 1055static void __init srmmu_early_allocate_ptable_skeleton(unsigned long start,
1056 unsigned long end)
1055{ 1057{
1056 pgd_t *pgdp; 1058 pgd_t *pgdp;
1057 pmd_t *pmdp; 1059 pmd_t *pmdp;
@@ -1081,7 +1083,8 @@ void __init srmmu_early_allocate_ptable_skeleton(unsigned long start, unsigned l
1081 } 1083 }
1082} 1084}
1083 1085
1084void __init srmmu_allocate_ptable_skeleton(unsigned long start, unsigned long end) 1086static void __init srmmu_allocate_ptable_skeleton(unsigned long start,
1087 unsigned long end)
1085{ 1088{
1086 pgd_t *pgdp; 1089 pgd_t *pgdp;
1087 pmd_t *pmdp; 1090 pmd_t *pmdp;
@@ -1116,7 +1119,8 @@ void __init srmmu_allocate_ptable_skeleton(unsigned long start, unsigned long en
1116 * looking at the prom's page table directly which is what most 1119 * looking at the prom's page table directly which is what most
1117 * other OS's do. Yuck... this is much better. 1120 * other OS's do. Yuck... this is much better.
1118 */ 1121 */
1119void __init srmmu_inherit_prom_mappings(unsigned long start,unsigned long end) 1122static void __init srmmu_inherit_prom_mappings(unsigned long start,
1123 unsigned long end)
1120{ 1124{
1121 pgd_t *pgdp; 1125 pgd_t *pgdp;
1122 pmd_t *pmdp; 1126 pmd_t *pmdp;
diff --git a/arch/sparc/mm/tsunami.S b/arch/sparc/mm/tsunami.S
index db0d6de33a87..4e55e8f76648 100644
--- a/arch/sparc/mm/tsunami.S
+++ b/arch/sparc/mm/tsunami.S
@@ -93,7 +93,6 @@ tsunami_flush_tlb_page_out:
93 ldd [src + offset + 0x00], t2; \ 93 ldd [src + offset + 0x00], t2; \
94 std t2, [dst + offset + 0x00]; 94 std t2, [dst + offset + 0x00];
95 95
96 .globl tsunami_copy_1page
97tsunami_copy_1page: 96tsunami_copy_1page:
98/* NOTE: This routine has to be shorter than 70insns --jj */ 97/* NOTE: This routine has to be shorter than 70insns --jj */
99 or %g0, (PAGE_SIZE >> 8), %g1 98 or %g0, (PAGE_SIZE >> 8), %g1
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index fca9246470b1..7c88263256af 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -16,6 +16,7 @@ config SPARC64
16 select HAVE_IDE 16 select HAVE_IDE
17 select HAVE_LMB 17 select HAVE_LMB
18 select HAVE_ARCH_KGDB 18 select HAVE_ARCH_KGDB
19 select USE_GENERIC_SMP_HELPERS if SMP
19 20
20config GENERIC_TIME 21config GENERIC_TIME
21 bool 22 bool
@@ -81,6 +82,10 @@ config GENERIC_HARDIRQS_NO__DO_IRQ
81 bool 82 bool
82 def_bool y 83 def_bool y
83 84
85source "init/Kconfig"
86
87menu "Processor type and features"
88
84choice 89choice
85 prompt "Kernel page size" 90 prompt "Kernel page size"
86 default SPARC64_PAGE_SIZE_8KB 91 default SPARC64_PAGE_SIZE_8KB
@@ -93,19 +98,11 @@ config SPARC64_PAGE_SIZE_8KB
93 8KB and 64KB work quite well, since SPARC ELF sections 98 8KB and 64KB work quite well, since SPARC ELF sections
94 provide for up to 64KB alignment. 99 provide for up to 64KB alignment.
95 100
96 Therefore, 512KB and 4MB are for expert hackers only.
97
98 If you don't know what to do, choose 8KB. 101 If you don't know what to do, choose 8KB.
99 102
100config SPARC64_PAGE_SIZE_64KB 103config SPARC64_PAGE_SIZE_64KB
101 bool "64KB" 104 bool "64KB"
102 105
103config SPARC64_PAGE_SIZE_512KB
104 bool "512KB"
105
106config SPARC64_PAGE_SIZE_4MB
107 bool "4MB"
108
109endchoice 106endchoice
110 107
111config SECCOMP 108config SECCOMP
@@ -136,14 +133,10 @@ config HOTPLUG_CPU
136 can be controlled through /sys/devices/system/cpu/cpu#. 133 can be controlled through /sys/devices/system/cpu/cpu#.
137 Say N if you want to disable CPU hotplug. 134 Say N if you want to disable CPU hotplug.
138 135
139source "init/Kconfig"
140
141config GENERIC_HARDIRQS 136config GENERIC_HARDIRQS
142 bool 137 bool
143 default y 138 default y
144 139
145menu "General machine setup"
146
147source "kernel/time/Kconfig" 140source "kernel/time/Kconfig"
148 141
149config SMP 142config SMP
@@ -225,11 +218,10 @@ config HUGETLB_PAGE_SIZE_4MB
225 bool "4MB" 218 bool "4MB"
226 219
227config HUGETLB_PAGE_SIZE_512K 220config HUGETLB_PAGE_SIZE_512K
228 depends on !SPARC64_PAGE_SIZE_4MB && !SPARC64_PAGE_SIZE_512KB
229 bool "512K" 221 bool "512K"
230 222
231config HUGETLB_PAGE_SIZE_64K 223config HUGETLB_PAGE_SIZE_64K
232 depends on !SPARC64_PAGE_SIZE_4MB && !SPARC64_PAGE_SIZE_512KB && !SPARC64_PAGE_SIZE_64KB 224 depends on !SPARC64_PAGE_SIZE_64KB
233 bool "64K" 225 bool "64K"
234 226
235endchoice 227endchoice
diff --git a/arch/sparc64/Makefile b/arch/sparc64/Makefile
index 4b8f2b084c21..b785a395b12f 100644
--- a/arch/sparc64/Makefile
+++ b/arch/sparc64/Makefile
@@ -9,7 +9,9 @@
9 9
10CHECKFLAGS += -D__sparc__ -D__sparc_v9__ -m64 10CHECKFLAGS += -D__sparc__ -D__sparc_v9__ -m64
11 11
12CPPFLAGS_vmlinux.lds += -Usparc 12# Undefine sparc when processing vmlinux.lds - it is used
13# And teach CPP we are doing 64 bit builds (for this case)
14CPPFLAGS_vmlinux.lds += -m64 -Usparc
13 15
14LDFLAGS := -m elf64_sparc 16LDFLAGS := -m elf64_sparc
15 17
diff --git a/arch/sparc64/defconfig b/arch/sparc64/defconfig
index 76eb832527f2..82cab5cc8070 100644
--- a/arch/sparc64/defconfig
+++ b/arch/sparc64/defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.26-rc2 3# Linux kernel version: 2.6.26
4# Fri May 16 13:36:07 2008 4# Fri Jul 18 00:47:07 2008
5# 5#
6CONFIG_SPARC=y 6CONFIG_SPARC=y
7CONFIG_SPARC64=y 7CONFIG_SPARC64=y
@@ -22,18 +22,6 @@ CONFIG_HAVE_SETUP_PER_CPU_AREA=y
22CONFIG_ARCH_NO_VIRT_TO_BUS=y 22CONFIG_ARCH_NO_VIRT_TO_BUS=y
23CONFIG_OF=y 23CONFIG_OF=y
24CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y 24CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
25CONFIG_SPARC64_PAGE_SIZE_8KB=y
26# CONFIG_SPARC64_PAGE_SIZE_64KB is not set
27# CONFIG_SPARC64_PAGE_SIZE_512KB is not set
28# CONFIG_SPARC64_PAGE_SIZE_4MB is not set
29CONFIG_SECCOMP=y
30CONFIG_HZ_100=y
31# CONFIG_HZ_250 is not set
32# CONFIG_HZ_300 is not set
33# CONFIG_HZ_1000 is not set
34CONFIG_HZ=100
35# CONFIG_SCHED_HRTICK is not set
36CONFIG_HOTPLUG_CPU=y
37CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 25CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
38 26
39# 27#
@@ -105,6 +93,7 @@ CONFIG_KRETPROBES=y
105CONFIG_HAVE_KPROBES=y 93CONFIG_HAVE_KPROBES=y
106CONFIG_HAVE_KRETPROBES=y 94CONFIG_HAVE_KRETPROBES=y
107# CONFIG_HAVE_DMA_ATTRS is not set 95# CONFIG_HAVE_DMA_ATTRS is not set
96CONFIG_USE_GENERIC_SMP_HELPERS=y
108CONFIG_PROC_PAGE_MONITOR=y 97CONFIG_PROC_PAGE_MONITOR=y
109CONFIG_SLABINFO=y 98CONFIG_SLABINFO=y
110CONFIG_RT_MUTEXES=y 99CONFIG_RT_MUTEXES=y
@@ -121,6 +110,7 @@ CONFIG_STOP_MACHINE=y
121CONFIG_BLOCK=y 110CONFIG_BLOCK=y
122CONFIG_BLK_DEV_IO_TRACE=y 111CONFIG_BLK_DEV_IO_TRACE=y
123CONFIG_BLK_DEV_BSG=y 112CONFIG_BLK_DEV_BSG=y
113# CONFIG_BLK_DEV_INTEGRITY is not set
124CONFIG_BLOCK_COMPAT=y 114CONFIG_BLOCK_COMPAT=y
125 115
126# 116#
@@ -136,11 +126,21 @@ CONFIG_DEFAULT_AS=y
136# CONFIG_DEFAULT_NOOP is not set 126# CONFIG_DEFAULT_NOOP is not set
137CONFIG_DEFAULT_IOSCHED="anticipatory" 127CONFIG_DEFAULT_IOSCHED="anticipatory"
138CONFIG_CLASSIC_RCU=y 128CONFIG_CLASSIC_RCU=y
139CONFIG_GENERIC_HARDIRQS=y
140 129
141# 130#
142# General machine setup 131# Processor type and features
143# 132#
133CONFIG_SPARC64_PAGE_SIZE_8KB=y
134# CONFIG_SPARC64_PAGE_SIZE_64KB is not set
135CONFIG_SECCOMP=y
136CONFIG_HZ_100=y
137# CONFIG_HZ_250 is not set
138# CONFIG_HZ_300 is not set
139# CONFIG_HZ_1000 is not set
140CONFIG_HZ=100
141# CONFIG_SCHED_HRTICK is not set
142CONFIG_HOTPLUG_CPU=y
143CONFIG_GENERIC_HARDIRQS=y
144CONFIG_TICK_ONESHOT=y 144CONFIG_TICK_ONESHOT=y
145CONFIG_NO_HZ=y 145CONFIG_NO_HZ=y
146CONFIG_HIGH_RES_TIMERS=y 146CONFIG_HIGH_RES_TIMERS=y
@@ -342,6 +342,8 @@ CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
342CONFIG_STANDALONE=y 342CONFIG_STANDALONE=y
343# CONFIG_PREVENT_FIRMWARE_BUILD is not set 343# CONFIG_PREVENT_FIRMWARE_BUILD is not set
344CONFIG_FW_LOADER=y 344CONFIG_FW_LOADER=y
345CONFIG_FIRMWARE_IN_KERNEL=y
346CONFIG_EXTRA_FIRMWARE=""
345# CONFIG_DEBUG_DRIVER is not set 347# CONFIG_DEBUG_DRIVER is not set
346# CONFIG_DEBUG_DEVRES is not set 348# CONFIG_DEBUG_DEVRES is not set
347# CONFIG_SYS_HYPERVISOR is not set 349# CONFIG_SYS_HYPERVISOR is not set
@@ -366,6 +368,7 @@ CONFIG_CDROM_PKTCDVD_BUFFERS=8
366CONFIG_CDROM_PKTCDVD_WCACHE=y 368CONFIG_CDROM_PKTCDVD_WCACHE=y
367CONFIG_ATA_OVER_ETH=m 369CONFIG_ATA_OVER_ETH=m
368CONFIG_SUNVDC=m 370CONFIG_SUNVDC=m
371# CONFIG_BLK_DEV_HD is not set
369CONFIG_MISC_DEVICES=y 372CONFIG_MISC_DEVICES=y
370# CONFIG_PHANTOM is not set 373# CONFIG_PHANTOM is not set
371# CONFIG_EEPROM_93CX6 is not set 374# CONFIG_EEPROM_93CX6 is not set
@@ -379,6 +382,7 @@ CONFIG_BLK_DEV_IDE=y
379# 382#
380# Please see Documentation/ide/ide.txt for help/info on IDE drives 383# Please see Documentation/ide/ide.txt for help/info on IDE drives
381# 384#
385CONFIG_IDE_TIMINGS=y
382# CONFIG_BLK_DEV_IDE_SATA is not set 386# CONFIG_BLK_DEV_IDE_SATA is not set
383CONFIG_BLK_DEV_IDEDISK=y 387CONFIG_BLK_DEV_IDEDISK=y
384# CONFIG_IDEDISK_MULTI_MODE is not set 388# CONFIG_IDEDISK_MULTI_MODE is not set
@@ -429,8 +433,6 @@ CONFIG_BLK_DEV_ALI15X3=y
429# CONFIG_BLK_DEV_VIA82CXXX is not set 433# CONFIG_BLK_DEV_VIA82CXXX is not set
430# CONFIG_BLK_DEV_TC86C001 is not set 434# CONFIG_BLK_DEV_TC86C001 is not set
431CONFIG_BLK_DEV_IDEDMA=y 435CONFIG_BLK_DEV_IDEDMA=y
432# CONFIG_BLK_DEV_HD_ONLY is not set
433# CONFIG_BLK_DEV_HD is not set
434 436
435# 437#
436# SCSI device support 438# SCSI device support
@@ -504,6 +506,7 @@ CONFIG_SCSI_LOWLEVEL=y
504# CONFIG_SCSI_DEBUG is not set 506# CONFIG_SCSI_DEBUG is not set
505# CONFIG_SCSI_SUNESP is not set 507# CONFIG_SCSI_SUNESP is not set
506# CONFIG_SCSI_SRP is not set 508# CONFIG_SCSI_SRP is not set
509# CONFIG_SCSI_DH is not set
507# CONFIG_ATA is not set 510# CONFIG_ATA is not set
508CONFIG_MD=y 511CONFIG_MD=y
509CONFIG_BLK_DEV_MD=m 512CONFIG_BLK_DEV_MD=m
@@ -529,6 +532,10 @@ CONFIG_DM_ZERO=m
529# 532#
530# IEEE 1394 (FireWire) support 533# IEEE 1394 (FireWire) support
531# 534#
535
536#
537# Enable only one of the two stacks, unless you know what you are doing
538#
532# CONFIG_FIREWIRE is not set 539# CONFIG_FIREWIRE is not set
533# CONFIG_IEEE1394 is not set 540# CONFIG_IEEE1394 is not set
534# CONFIG_I2O is not set 541# CONFIG_I2O is not set
@@ -745,7 +752,8 @@ CONFIG_SERIAL_CORE_CONSOLE=y
745CONFIG_UNIX98_PTYS=y 752CONFIG_UNIX98_PTYS=y
746# CONFIG_LEGACY_PTYS is not set 753# CONFIG_LEGACY_PTYS is not set
747# CONFIG_IPMI_HANDLER is not set 754# CONFIG_IPMI_HANDLER is not set
748# CONFIG_HW_RANDOM is not set 755CONFIG_HW_RANDOM=m
756CONFIG_HW_RANDOM_N2RNG=m
749# CONFIG_R3964 is not set 757# CONFIG_R3964 is not set
750# CONFIG_APPLICOM is not set 758# CONFIG_APPLICOM is not set
751# CONFIG_RAW_DRIVER is not set 759# CONFIG_RAW_DRIVER is not set
@@ -759,38 +767,58 @@ CONFIG_I2C_ALGOBIT=y
759# 767#
760# I2C Hardware Bus support 768# I2C Hardware Bus support
761# 769#
770
771#
772# PC SMBus host controller drivers
773#
762# CONFIG_I2C_ALI1535 is not set 774# CONFIG_I2C_ALI1535 is not set
763# CONFIG_I2C_ALI1563 is not set 775# CONFIG_I2C_ALI1563 is not set
764# CONFIG_I2C_ALI15X3 is not set 776# CONFIG_I2C_ALI15X3 is not set
765# CONFIG_I2C_AMD756 is not set 777# CONFIG_I2C_AMD756 is not set
766# CONFIG_I2C_AMD8111 is not set 778# CONFIG_I2C_AMD8111 is not set
767# CONFIG_I2C_I801 is not set 779# CONFIG_I2C_I801 is not set
768# CONFIG_I2C_I810 is not set 780# CONFIG_I2C_ISCH is not set
769# CONFIG_I2C_PIIX4 is not set 781# CONFIG_I2C_PIIX4 is not set
770# CONFIG_I2C_NFORCE2 is not set 782# CONFIG_I2C_NFORCE2 is not set
771# CONFIG_I2C_OCORES is not set
772# CONFIG_I2C_PARPORT_LIGHT is not set
773# CONFIG_I2C_PROSAVAGE is not set
774# CONFIG_I2C_SAVAGE4 is not set
775# CONFIG_I2C_SIMTEC is not set
776# CONFIG_I2C_SIS5595 is not set 783# CONFIG_I2C_SIS5595 is not set
777# CONFIG_I2C_SIS630 is not set 784# CONFIG_I2C_SIS630 is not set
778# CONFIG_I2C_SIS96X is not set 785# CONFIG_I2C_SIS96X is not set
779# CONFIG_I2C_TAOS_EVM is not set
780# CONFIG_I2C_STUB is not set
781# CONFIG_I2C_TINY_USB is not set
782# CONFIG_I2C_VIA is not set 786# CONFIG_I2C_VIA is not set
783# CONFIG_I2C_VIAPRO is not set 787# CONFIG_I2C_VIAPRO is not set
788
789#
790# I2C system bus drivers (mostly embedded / system-on-chip)
791#
792# CONFIG_I2C_OCORES is not set
793# CONFIG_I2C_SIMTEC is not set
794
795#
796# External I2C/SMBus adapter drivers
797#
798# CONFIG_I2C_PARPORT_LIGHT is not set
799# CONFIG_I2C_TAOS_EVM is not set
800# CONFIG_I2C_TINY_USB is not set
801
802#
803# Graphics adapter I2C/DDC channel drivers
804#
784# CONFIG_I2C_VOODOO3 is not set 805# CONFIG_I2C_VOODOO3 is not set
806
807#
808# Other I2C/SMBus bus drivers
809#
785# CONFIG_I2C_PCA_PLATFORM is not set 810# CONFIG_I2C_PCA_PLATFORM is not set
811# CONFIG_I2C_STUB is not set
786 812
787# 813#
788# Miscellaneous I2C Chip support 814# Miscellaneous I2C Chip support
789# 815#
790# CONFIG_DS1682 is not set 816# CONFIG_DS1682 is not set
817# CONFIG_AT24 is not set
791# CONFIG_SENSORS_EEPROM is not set 818# CONFIG_SENSORS_EEPROM is not set
792# CONFIG_SENSORS_PCF8574 is not set 819# CONFIG_SENSORS_PCF8574 is not set
793# CONFIG_PCF8575 is not set 820# CONFIG_PCF8575 is not set
821# CONFIG_SENSORS_PCA9539 is not set
794# CONFIG_SENSORS_PCF8591 is not set 822# CONFIG_SENSORS_PCF8591 is not set
795# CONFIG_SENSORS_MAX6875 is not set 823# CONFIG_SENSORS_MAX6875 is not set
796# CONFIG_SENSORS_TSL2550 is not set 824# CONFIG_SENSORS_TSL2550 is not set
@@ -856,6 +884,7 @@ CONFIG_HWMON=y
856# CONFIG_SENSORS_W83627EHF is not set 884# CONFIG_SENSORS_W83627EHF is not set
857# CONFIG_HWMON_DEBUG_CHIP is not set 885# CONFIG_HWMON_DEBUG_CHIP is not set
858# CONFIG_THERMAL is not set 886# CONFIG_THERMAL is not set
887# CONFIG_THERMAL_HWMON is not set
859# CONFIG_WATCHDOG is not set 888# CONFIG_WATCHDOG is not set
860 889
861# 890#
@@ -985,15 +1014,7 @@ CONFIG_LOGO=y
985# CONFIG_LOGO_LINUX_VGA16 is not set 1014# CONFIG_LOGO_LINUX_VGA16 is not set
986# CONFIG_LOGO_LINUX_CLUT224 is not set 1015# CONFIG_LOGO_LINUX_CLUT224 is not set
987CONFIG_LOGO_SUN_CLUT224=y 1016CONFIG_LOGO_SUN_CLUT224=y
988
989#
990# Sound
991#
992CONFIG_SOUND=m 1017CONFIG_SOUND=m
993
994#
995# Advanced Linux Sound Architecture
996#
997CONFIG_SND=m 1018CONFIG_SND=m
998CONFIG_SND_TIMER=m 1019CONFIG_SND_TIMER=m
999CONFIG_SND_PCM=m 1020CONFIG_SND_PCM=m
@@ -1010,21 +1031,17 @@ CONFIG_SND_SUPPORT_OLD_API=y
1010CONFIG_SND_VERBOSE_PROCFS=y 1031CONFIG_SND_VERBOSE_PROCFS=y
1011# CONFIG_SND_VERBOSE_PRINTK is not set 1032# CONFIG_SND_VERBOSE_PRINTK is not set
1012# CONFIG_SND_DEBUG is not set 1033# CONFIG_SND_DEBUG is not set
1013 1034CONFIG_SND_VMASTER=y
1014#
1015# Generic devices
1016#
1017CONFIG_SND_MPU401_UART=m 1035CONFIG_SND_MPU401_UART=m
1018CONFIG_SND_AC97_CODEC=m 1036CONFIG_SND_AC97_CODEC=m
1037CONFIG_SND_DRIVERS=y
1019CONFIG_SND_DUMMY=m 1038CONFIG_SND_DUMMY=m
1020CONFIG_SND_VIRMIDI=m 1039CONFIG_SND_VIRMIDI=m
1021CONFIG_SND_MTPAV=m 1040CONFIG_SND_MTPAV=m
1022# CONFIG_SND_SERIAL_U16550 is not set 1041# CONFIG_SND_SERIAL_U16550 is not set
1023# CONFIG_SND_MPU401 is not set 1042# CONFIG_SND_MPU401 is not set
1024 1043# CONFIG_SND_AC97_POWER_SAVE is not set
1025# 1044CONFIG_SND_PCI=y
1026# PCI devices
1027#
1028# CONFIG_SND_AD1889 is not set 1045# CONFIG_SND_AD1889 is not set
1029# CONFIG_SND_ALS300 is not set 1046# CONFIG_SND_ALS300 is not set
1030CONFIG_SND_ALI5451=m 1047CONFIG_SND_ALI5451=m
@@ -1084,37 +1101,14 @@ CONFIG_SND_ALI5451=m
1084# CONFIG_SND_VIRTUOSO is not set 1101# CONFIG_SND_VIRTUOSO is not set
1085# CONFIG_SND_VX222 is not set 1102# CONFIG_SND_VX222 is not set
1086# CONFIG_SND_YMFPCI is not set 1103# CONFIG_SND_YMFPCI is not set
1087# CONFIG_SND_AC97_POWER_SAVE is not set 1104CONFIG_SND_USB=y
1088
1089#
1090# USB devices
1091#
1092# CONFIG_SND_USB_AUDIO is not set 1105# CONFIG_SND_USB_AUDIO is not set
1093# CONFIG_SND_USB_CAIAQ is not set 1106# CONFIG_SND_USB_CAIAQ is not set
1094 1107CONFIG_SND_SPARC=y
1095#
1096# ALSA Sparc devices
1097#
1098# CONFIG_SND_SUN_AMD7930 is not set 1108# CONFIG_SND_SUN_AMD7930 is not set
1099CONFIG_SND_SUN_CS4231=m 1109CONFIG_SND_SUN_CS4231=m
1100# CONFIG_SND_SUN_DBRI is not set 1110# CONFIG_SND_SUN_DBRI is not set
1101
1102#
1103# System on Chip audio support
1104#
1105# CONFIG_SND_SOC is not set 1111# CONFIG_SND_SOC is not set
1106
1107#
1108# ALSA SoC audio for Freescale SOCs
1109#
1110
1111#
1112# SoC Audio for the Texas Instruments OMAP
1113#
1114
1115#
1116# Open Sound System
1117#
1118# CONFIG_SOUND_PRIME is not set 1112# CONFIG_SOUND_PRIME is not set
1119CONFIG_AC97_BUS=m 1113CONFIG_AC97_BUS=m
1120CONFIG_HID_SUPPORT=y 1114CONFIG_HID_SUPPORT=y
@@ -1167,6 +1161,7 @@ CONFIG_USB_UHCI_HCD=m
1167# 1161#
1168# CONFIG_USB_ACM is not set 1162# CONFIG_USB_ACM is not set
1169# CONFIG_USB_PRINTER is not set 1163# CONFIG_USB_PRINTER is not set
1164# CONFIG_USB_WDM is not set
1170 1165
1171# 1166#
1172# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' 1167# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
@@ -1226,6 +1221,7 @@ CONFIG_USB_STORAGE=m
1226# CONFIG_USB_TRANCEVIBRATOR is not set 1221# CONFIG_USB_TRANCEVIBRATOR is not set
1227# CONFIG_USB_IOWARRIOR is not set 1222# CONFIG_USB_IOWARRIOR is not set
1228# CONFIG_USB_TEST is not set 1223# CONFIG_USB_TEST is not set
1224# CONFIG_USB_ISIGHTFW is not set
1229# CONFIG_USB_GADGET is not set 1225# CONFIG_USB_GADGET is not set
1230# CONFIG_MMC is not set 1226# CONFIG_MMC is not set
1231# CONFIG_MEMSTICK is not set 1227# CONFIG_MEMSTICK is not set
@@ -1420,6 +1416,12 @@ CONFIG_DEBUG_BUGVERBOSE=y
1420# CONFIG_BACKTRACE_SELF_TEST is not set 1416# CONFIG_BACKTRACE_SELF_TEST is not set
1421# CONFIG_LKDTM is not set 1417# CONFIG_LKDTM is not set
1422# CONFIG_FAULT_INJECTION is not set 1418# CONFIG_FAULT_INJECTION is not set
1419CONFIG_HAVE_FTRACE=y
1420CONFIG_HAVE_DYNAMIC_FTRACE=y
1421# CONFIG_FTRACE is not set
1422# CONFIG_IRQSOFF_TRACER is not set
1423# CONFIG_SCHED_TRACER is not set
1424# CONFIG_CONTEXT_SWITCH_TRACER is not set
1423# CONFIG_SAMPLES is not set 1425# CONFIG_SAMPLES is not set
1424CONFIG_HAVE_ARCH_KGDB=y 1426CONFIG_HAVE_ARCH_KGDB=y
1425# CONFIG_KGDB is not set 1427# CONFIG_KGDB is not set
@@ -1486,6 +1488,10 @@ CONFIG_CRYPTO_CRC32C=m
1486CONFIG_CRYPTO_MD4=y 1488CONFIG_CRYPTO_MD4=y
1487CONFIG_CRYPTO_MD5=y 1489CONFIG_CRYPTO_MD5=y
1488CONFIG_CRYPTO_MICHAEL_MIC=m 1490CONFIG_CRYPTO_MICHAEL_MIC=m
1491# CONFIG_CRYPTO_RMD128 is not set
1492# CONFIG_CRYPTO_RMD160 is not set
1493# CONFIG_CRYPTO_RMD256 is not set
1494# CONFIG_CRYPTO_RMD320 is not set
1489CONFIG_CRYPTO_SHA1=y 1495CONFIG_CRYPTO_SHA1=y
1490CONFIG_CRYPTO_SHA256=m 1496CONFIG_CRYPTO_SHA256=m
1491CONFIG_CRYPTO_SHA512=m 1497CONFIG_CRYPTO_SHA512=m
@@ -1527,6 +1533,7 @@ CONFIG_BITREVERSE=y
1527# CONFIG_GENERIC_FIND_FIRST_BIT is not set 1533# CONFIG_GENERIC_FIND_FIRST_BIT is not set
1528CONFIG_CRC_CCITT=m 1534CONFIG_CRC_CCITT=m
1529CONFIG_CRC16=m 1535CONFIG_CRC16=m
1536# CONFIG_CRC_T10DIF is not set
1530# CONFIG_CRC_ITU_T is not set 1537# CONFIG_CRC_ITU_T is not set
1531CONFIG_CRC32=y 1538CONFIG_CRC32=y
1532# CONFIG_CRC7 is not set 1539# CONFIG_CRC7 is not set
diff --git a/arch/sparc64/kernel/central.c b/arch/sparc64/kernel/central.c
index b61b8dfb09cf..f2e87d0d7e1d 100644
--- a/arch/sparc64/kernel/central.c
+++ b/arch/sparc64/kernel/central.c
@@ -16,8 +16,8 @@
16#include <asm/fhc.h> 16#include <asm/fhc.h>
17#include <asm/starfire.h> 17#include <asm/starfire.h>
18 18
19struct linux_central *central_bus = NULL; 19static struct linux_central *central_bus = NULL;
20struct linux_fhc *fhc_list = NULL; 20static struct linux_fhc *fhc_list = NULL;
21 21
22#define IS_CENTRAL_FHC(__fhc) ((__fhc) == central_bus->child) 22#define IS_CENTRAL_FHC(__fhc) ((__fhc) == central_bus->child)
23 23
@@ -79,9 +79,9 @@ static void adjust_regs(struct linux_prom_registers *regp, int nregs,
79} 79}
80 80
81/* Apply probed fhc ranges to registers passed, if no ranges return. */ 81/* Apply probed fhc ranges to registers passed, if no ranges return. */
82void apply_fhc_ranges(struct linux_fhc *fhc, 82static void apply_fhc_ranges(struct linux_fhc *fhc,
83 struct linux_prom_registers *regs, 83 struct linux_prom_registers *regs,
84 int nregs) 84 int nregs)
85{ 85{
86 if (fhc->num_fhc_ranges) 86 if (fhc->num_fhc_ranges)
87 adjust_regs(regs, nregs, fhc->fhc_ranges, 87 adjust_regs(regs, nregs, fhc->fhc_ranges,
@@ -89,8 +89,8 @@ void apply_fhc_ranges(struct linux_fhc *fhc,
89} 89}
90 90
91/* Apply probed central ranges to registers passed, if no ranges return. */ 91/* Apply probed central ranges to registers passed, if no ranges return. */
92void apply_central_ranges(struct linux_central *central, 92static void apply_central_ranges(struct linux_central *central,
93 struct linux_prom_registers *regs, int nregs) 93 struct linux_prom_registers *regs, int nregs)
94{ 94{
95 if (central->num_central_ranges) 95 if (central->num_central_ranges)
96 adjust_regs(regs, nregs, central->central_ranges, 96 adjust_regs(regs, nregs, central->central_ranges,
diff --git a/arch/sparc64/kernel/ds.c b/arch/sparc64/kernel/ds.c
index edb74f5a1186..d0fa5aa38934 100644
--- a/arch/sparc64/kernel/ds.c
+++ b/arch/sparc64/kernel/ds.c
@@ -159,7 +159,7 @@ static void ds_var_data(struct ds_info *dp,
159 struct ds_cap_state *cp, 159 struct ds_cap_state *cp,
160 void *buf, int len); 160 void *buf, int len);
161 161
162struct ds_cap_state ds_states_template[] = { 162static struct ds_cap_state ds_states_template[] = {
163 { 163 {
164 .service_id = "md-update", 164 .service_id = "md-update",
165 .data = md_update_data, 165 .data = md_update_data,
diff --git a/arch/sparc64/kernel/ebus.c b/arch/sparc64/kernel/ebus.c
index c49d0388b793..4d58d7ce708d 100644
--- a/arch/sparc64/kernel/ebus.c
+++ b/arch/sparc64/kernel/ebus.c
@@ -401,7 +401,7 @@ static void __init fill_ebus_device(struct device_node *dp, struct linux_ebus_de
401 dev->ofdev.node = dp; 401 dev->ofdev.node = dp;
402 dev->ofdev.dev.parent = &dev->bus->ofdev.dev; 402 dev->ofdev.dev.parent = &dev->bus->ofdev.dev;
403 dev->ofdev.dev.bus = &ebus_bus_type; 403 dev->ofdev.dev.bus = &ebus_bus_type;
404 sprintf(dev->ofdev.dev.bus_id, "ebus[%08x]", dp->node); 404 dev_set_name(&dev->ofdev.dev, "ebus[%08x]", dp->node);
405 405
406 /* Register with core */ 406 /* Register with core */
407 if (of_device_register(&dev->ofdev) != 0) 407 if (of_device_register(&dev->ofdev) != 0)
@@ -501,7 +501,7 @@ void __init ebus_init(void)
501 ebus->ofdev.node = dp; 501 ebus->ofdev.node = dp;
502 ebus->ofdev.dev.parent = &pdev->dev; 502 ebus->ofdev.dev.parent = &pdev->dev;
503 ebus->ofdev.dev.bus = &ebus_bus_type; 503 ebus->ofdev.dev.bus = &ebus_bus_type;
504 sprintf(ebus->ofdev.dev.bus_id, "ebus%d", num_ebus); 504 dev_set_name(&ebus->ofdev.dev, "ebus%d", num_ebus);
505 505
506 /* Register with core */ 506 /* Register with core */
507 if (of_device_register(&ebus->ofdev) != 0) 507 if (of_device_register(&ebus->ofdev) != 0)
diff --git a/arch/sparc64/kernel/hvapi.c b/arch/sparc64/kernel/hvapi.c
index f34f5d6181ef..691760b5b012 100644
--- a/arch/sparc64/kernel/hvapi.c
+++ b/arch/sparc64/kernel/hvapi.c
@@ -34,8 +34,12 @@ static struct api_info api_table[] = {
34 { .group = HV_GRP_LDOM, }, 34 { .group = HV_GRP_LDOM, },
35 { .group = HV_GRP_SVC_CHAN, .flags = FLAG_PRE_API }, 35 { .group = HV_GRP_SVC_CHAN, .flags = FLAG_PRE_API },
36 { .group = HV_GRP_NCS, .flags = FLAG_PRE_API }, 36 { .group = HV_GRP_NCS, .flags = FLAG_PRE_API },
37 { .group = HV_GRP_RNG, },
37 { .group = HV_GRP_NIAG_PERF, .flags = FLAG_PRE_API }, 38 { .group = HV_GRP_NIAG_PERF, .flags = FLAG_PRE_API },
38 { .group = HV_GRP_FIRE_PERF, }, 39 { .group = HV_GRP_FIRE_PERF, },
40 { .group = HV_GRP_N2_CPU, },
41 { .group = HV_GRP_NIU, },
42 { .group = HV_GRP_VF_CPU, },
39 { .group = HV_GRP_DIAG, .flags = FLAG_PRE_API }, 43 { .group = HV_GRP_DIAG, .flags = FLAG_PRE_API },
40}; 44};
41 45
diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c
index d569f60c24b8..4fd48ab7dda4 100644
--- a/arch/sparc64/kernel/of_device.c
+++ b/arch/sparc64/kernel/of_device.c
@@ -797,9 +797,9 @@ static struct of_device * __init scan_one_device(struct device_node *dp,
797 op->dev.parent = parent; 797 op->dev.parent = parent;
798 op->dev.bus = &of_platform_bus_type; 798 op->dev.bus = &of_platform_bus_type;
799 if (!parent) 799 if (!parent)
800 strcpy(op->dev.bus_id, "root"); 800 dev_set_name(&op->dev, "root");
801 else 801 else
802 sprintf(op->dev.bus_id, "%08x", dp->node); 802 dev_set_name(&op->dev, "%08x", dp->node);
803 803
804 if (of_device_register(op)) { 804 if (of_device_register(op)) {
805 printk("%s: Could not register of device.\n", 805 printk("%s: Could not register of device.\n",
diff --git a/arch/sparc64/kernel/pci.c b/arch/sparc64/kernel/pci.c
index d00a3656c287..55096195458f 100644
--- a/arch/sparc64/kernel/pci.c
+++ b/arch/sparc64/kernel/pci.c
@@ -408,7 +408,7 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
408 dev->class = class >> 8; 408 dev->class = class >> 8;
409 dev->revision = class & 0xff; 409 dev->revision = class & 0xff;
410 410
411 sprintf(dev->dev.bus_id, "%04x:%02x:%02x.%d", pci_domain_nr(bus), 411 dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(bus),
412 dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn)); 412 dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
413 413
414 if (ofpci_verbose) 414 if (ofpci_verbose)
diff --git a/arch/sparc64/kernel/pci_msi.c b/arch/sparc64/kernel/pci_msi.c
index db5e8fd8f674..60c71e350212 100644
--- a/arch/sparc64/kernel/pci_msi.c
+++ b/arch/sparc64/kernel/pci_msi.c
@@ -120,9 +120,9 @@ static struct irq_chip msi_irq = {
120 /* XXX affinity XXX */ 120 /* XXX affinity XXX */
121}; 121};
122 122
123int sparc64_setup_msi_irq(unsigned int *virt_irq_p, 123static int sparc64_setup_msi_irq(unsigned int *virt_irq_p,
124 struct pci_dev *pdev, 124 struct pci_dev *pdev,
125 struct msi_desc *entry) 125 struct msi_desc *entry)
126{ 126{
127 struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller; 127 struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
128 const struct sparc64_msiq_ops *ops = pbm->msi_ops; 128 const struct sparc64_msiq_ops *ops = pbm->msi_ops;
@@ -179,8 +179,8 @@ out_err:
179 return err; 179 return err;
180} 180}
181 181
182void sparc64_teardown_msi_irq(unsigned int virt_irq, 182static void sparc64_teardown_msi_irq(unsigned int virt_irq,
183 struct pci_dev *pdev) 183 struct pci_dev *pdev)
184{ 184{
185 struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller; 185 struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
186 const struct sparc64_msiq_ops *ops = pbm->msi_ops; 186 const struct sparc64_msiq_ops *ops = pbm->msi_ops;
diff --git a/arch/sparc64/kernel/pci_sun4v.c b/arch/sparc64/kernel/pci_sun4v.c
index e2bb9790039c..a104c80d319d 100644
--- a/arch/sparc64/kernel/pci_sun4v.c
+++ b/arch/sparc64/kernel/pci_sun4v.c
@@ -531,7 +531,7 @@ static void dma_4v_sync_sg_for_cpu(struct device *dev,
531 /* Nothing to do... */ 531 /* Nothing to do... */
532} 532}
533 533
534const struct dma_ops sun4v_dma_ops = { 534static const struct dma_ops sun4v_dma_ops = {
535 .alloc_coherent = dma_4v_alloc_coherent, 535 .alloc_coherent = dma_4v_alloc_coherent,
536 .free_coherent = dma_4v_free_coherent, 536 .free_coherent = dma_4v_free_coherent,
537 .map_single = dma_4v_map_single, 537 .map_single = dma_4v_map_single,
diff --git a/arch/sparc64/kernel/process.c b/arch/sparc64/kernel/process.c
index 2084f81a76e1..31ea752d307b 100644
--- a/arch/sparc64/kernel/process.c
+++ b/arch/sparc64/kernel/process.c
@@ -15,7 +15,6 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/sched.h> 16#include <linux/sched.h>
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/kallsyms.h>
19#include <linux/mm.h> 18#include <linux/mm.h>
20#include <linux/fs.h> 19#include <linux/fs.h>
21#include <linux/smp.h> 20#include <linux/smp.h>
@@ -211,7 +210,7 @@ static void show_regwindow(struct pt_regs *regs)
211 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n", 210 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
212 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]); 211 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
213 if (regs->tstate & TSTATE_PRIV) 212 if (regs->tstate & TSTATE_PRIV)
214 print_symbol("I7: <%s>\n", rwk->ins[7]); 213 printk("I7: <%pS>\n", (void *) rwk->ins[7]);
215} 214}
216 215
217#ifdef CONFIG_SMP 216#ifdef CONFIG_SMP
@@ -232,7 +231,7 @@ void __show_regs(struct pt_regs * regs)
232#endif 231#endif
233 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate, 232 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
234 regs->tpc, regs->tnpc, regs->y, print_tainted()); 233 regs->tpc, regs->tnpc, regs->y, print_tainted());
235 print_symbol("TPC: <%s>\n", regs->tpc); 234 printk("TPC: <%pS>\n", (void *) regs->tpc);
236 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n", 235 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
237 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2], 236 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
238 regs->u_regs[3]); 237 regs->u_regs[3]);
@@ -245,7 +244,7 @@ void __show_regs(struct pt_regs * regs)
245 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n", 244 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
246 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14], 245 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
247 regs->u_regs[15]); 246 regs->u_regs[15]);
248 print_symbol("RPC: <%s>\n", regs->u_regs[15]); 247 printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
249 show_regwindow(regs); 248 show_regwindow(regs);
250#ifdef CONFIG_SMP 249#ifdef CONFIG_SMP
251 spin_unlock(&regdump_lock); 250 spin_unlock(&regdump_lock);
@@ -346,9 +345,6 @@ static void sysrq_handle_globreg(int key, struct tty_struct *tty)
346{ 345{
347 struct thread_info *tp = current_thread_info(); 346 struct thread_info *tp = current_thread_info();
348 struct pt_regs *regs = get_irq_regs(); 347 struct pt_regs *regs = get_irq_regs();
349#ifdef CONFIG_KALLSYMS
350 char buffer[KSYM_SYMBOL_LEN];
351#endif
352 unsigned long flags; 348 unsigned long flags;
353 int this_cpu, cpu; 349 int this_cpu, cpu;
354 350
@@ -377,17 +373,13 @@ static void sysrq_handle_globreg(int key, struct tty_struct *tty)
377 gp->tstate, gp->tpc, gp->tnpc, 373 gp->tstate, gp->tpc, gp->tnpc,
378 ((tp && tp->task) ? tp->task->comm : "NULL"), 374 ((tp && tp->task) ? tp->task->comm : "NULL"),
379 ((tp && tp->task) ? tp->task->pid : -1)); 375 ((tp && tp->task) ? tp->task->pid : -1));
380#ifdef CONFIG_KALLSYMS 376
381 if (gp->tstate & TSTATE_PRIV) { 377 if (gp->tstate & TSTATE_PRIV) {
382 sprint_symbol(buffer, gp->tpc); 378 printk(" TPC[%pS] O7[%pS] I7[%pS]\n",
383 printk(" TPC[%s] ", buffer); 379 (void *) gp->tpc,
384 sprint_symbol(buffer, gp->o7); 380 (void *) gp->o7,
385 printk("O7[%s] ", buffer); 381 (void *) gp->i7);
386 sprint_symbol(buffer, gp->i7); 382 } else {
387 printk("I7[%s]\n", buffer);
388 } else
389#endif
390 {
391 printk(" TPC[%lx] O7[%lx] I7[%lx]\n", 383 printk(" TPC[%lx] O7[%lx] I7[%lx]\n",
392 gp->tpc, gp->o7, gp->i7); 384 gp->tpc, gp->o7, gp->i7);
393 } 385 }
@@ -691,9 +683,9 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
691 ((unsigned long) child_sf) - STACK_BIAS; 683 ((unsigned long) child_sf) - STACK_BIAS;
692 684
693 /* Special case, if we are spawning a kernel thread from 685 /* Special case, if we are spawning a kernel thread from
694 * a userspace task (via KMOD, NFS, or similar) we must 686 * a userspace task (usermode helper, NFS or similar), we
695 * disable performance counters in the child because the 687 * must disable performance counters in the child because
696 * address space and protection realm are changing. 688 * the address space and protection realm are changing.
697 */ 689 */
698 if (t->flags & _TIF_PERFCTR) { 690 if (t->flags & _TIF_PERFCTR) {
699 t->user_cntd0 = t->user_cntd1 = NULL; 691 t->user_cntd0 = t->user_cntd1 = NULL;
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c
index c099d96f1239..7cf72b4bb108 100644
--- a/arch/sparc64/kernel/smp.c
+++ b/arch/sparc64/kernel/smp.c
@@ -788,89 +788,36 @@ static void smp_start_sync_tick_client(int cpu)
788 0, 0, 0, mask); 788 0, 0, 0, mask);
789} 789}
790 790
791/* Send cross call to all processors except self. */
792#define smp_cross_call(func, ctx, data1, data2) \
793 smp_cross_call_masked(func, ctx, data1, data2, cpu_online_map)
794
795struct call_data_struct {
796 void (*func) (void *info);
797 void *info;
798 atomic_t finished;
799 int wait;
800};
801
802static struct call_data_struct *call_data;
803
804extern unsigned long xcall_call_function; 791extern unsigned long xcall_call_function;
805 792
806/** 793void arch_send_call_function_ipi(cpumask_t mask)
807 * smp_call_function(): Run a function on all other CPUs.
808 * @func: The function to run. This must be fast and non-blocking.
809 * @info: An arbitrary pointer to pass to the function.
810 * @wait: If true, wait (atomically) until function has completed on other CPUs.
811 *
812 * Returns 0 on success, else a negative status code. Does not return until
813 * remote CPUs are nearly ready to execute <<func>> or are or have executed.
814 *
815 * You must not call this function with disabled interrupts or from a
816 * hardware interrupt handler or from a bottom half handler.
817 */
818static int sparc64_smp_call_function_mask(void (*func)(void *info), void *info,
819 int wait, cpumask_t mask)
820{ 794{
821 struct call_data_struct data;
822 int cpus;
823
824 /* Can deadlock when called with interrupts disabled */
825 WARN_ON(irqs_disabled());
826
827 data.func = func;
828 data.info = info;
829 atomic_set(&data.finished, 0);
830 data.wait = wait;
831
832 spin_lock(&call_lock);
833
834 cpu_clear(smp_processor_id(), mask);
835 cpus = cpus_weight(mask);
836 if (!cpus)
837 goto out_unlock;
838
839 call_data = &data;
840 mb();
841
842 smp_cross_call_masked(&xcall_call_function, 0, 0, 0, mask); 795 smp_cross_call_masked(&xcall_call_function, 0, 0, 0, mask);
796}
843 797
844 /* Wait for response */ 798extern unsigned long xcall_call_function_single;
845 while (atomic_read(&data.finished) != cpus)
846 cpu_relax();
847 799
848out_unlock: 800void arch_send_call_function_single_ipi(int cpu)
849 spin_unlock(&call_lock); 801{
802 cpumask_t mask = cpumask_of_cpu(cpu);
850 803
851 return 0; 804 smp_cross_call_masked(&xcall_call_function_single, 0, 0, 0, mask);
852} 805}
853 806
854int smp_call_function(void (*func)(void *info), void *info, int wait) 807/* Send cross call to all processors except self. */
855{ 808#define smp_cross_call(func, ctx, data1, data2) \
856 return sparc64_smp_call_function_mask(func, info, wait, cpu_online_map); 809 smp_cross_call_masked(func, ctx, data1, data2, cpu_online_map)
857}
858 810
859void smp_call_function_client(int irq, struct pt_regs *regs) 811void smp_call_function_client(int irq, struct pt_regs *regs)
860{ 812{
861 void (*func) (void *info) = call_data->func; 813 clear_softint(1 << irq);
862 void *info = call_data->info; 814 generic_smp_call_function_interrupt();
815}
863 816
817void smp_call_function_single_client(int irq, struct pt_regs *regs)
818{
864 clear_softint(1 << irq); 819 clear_softint(1 << irq);
865 if (call_data->wait) { 820 generic_smp_call_function_single_interrupt();
866 /* let initiator proceed only after completion */
867 func(info);
868 atomic_inc(&call_data->finished);
869 } else {
870 /* let initiator proceed after getting data */
871 atomic_inc(&call_data->finished);
872 func(info);
873 }
874} 821}
875 822
876static void tsb_sync(void *info) 823static void tsb_sync(void *info)
@@ -890,7 +837,7 @@ static void tsb_sync(void *info)
890 837
891void smp_tsb_sync(struct mm_struct *mm) 838void smp_tsb_sync(struct mm_struct *mm)
892{ 839{
893 sparc64_smp_call_function_mask(tsb_sync, mm, 1, mm->cpu_vm_mask); 840 smp_call_function_mask(mm->cpu_vm_mask, tsb_sync, mm, 1);
894} 841}
895 842
896extern unsigned long xcall_flush_tlb_mm; 843extern unsigned long xcall_flush_tlb_mm;
diff --git a/arch/sparc64/kernel/sparc64_ksyms.c b/arch/sparc64/kernel/sparc64_ksyms.c
index 49d3ea50c247..504e678ee128 100644
--- a/arch/sparc64/kernel/sparc64_ksyms.c
+++ b/arch/sparc64/kernel/sparc64_ksyms.c
@@ -108,8 +108,6 @@ EXPORT_SYMBOL(__read_unlock);
108EXPORT_SYMBOL(__write_lock); 108EXPORT_SYMBOL(__write_lock);
109EXPORT_SYMBOL(__write_unlock); 109EXPORT_SYMBOL(__write_unlock);
110EXPORT_SYMBOL(__write_trylock); 110EXPORT_SYMBOL(__write_trylock);
111
112EXPORT_SYMBOL(smp_call_function);
113#endif /* CONFIG_SMP */ 111#endif /* CONFIG_SMP */
114 112
115#ifdef CONFIG_MCOUNT 113#ifdef CONFIG_MCOUNT
diff --git a/arch/sparc64/kernel/sys_sparc.c b/arch/sparc64/kernel/sys_sparc.c
index ac1bff58c1ac..e1f4eba2e576 100644
--- a/arch/sparc64/kernel/sys_sparc.c
+++ b/arch/sparc64/kernel/sys_sparc.c
@@ -542,7 +542,7 @@ asmlinkage long sparc64_personality(unsigned long personality)
542 return ret; 542 return ret;
543} 543}
544 544
545int sparc64_mmap_check(unsigned long addr, unsigned long len) 545int sparc_mmap_check(unsigned long addr, unsigned long len)
546{ 546{
547 if (test_thread_flag(TIF_32BIT)) { 547 if (test_thread_flag(TIF_32BIT)) {
548 if (len >= STACK_TOP32) 548 if (len >= STACK_TOP32)
@@ -614,9 +614,9 @@ asmlinkage unsigned long sys64_mremap(unsigned long addr,
614 goto out; 614 goto out;
615 if (unlikely(new_len >= VA_EXCLUDE_START)) 615 if (unlikely(new_len >= VA_EXCLUDE_START))
616 goto out; 616 goto out;
617 if (unlikely(sparc64_mmap_check(addr, old_len))) 617 if (unlikely(sparc_mmap_check(addr, old_len)))
618 goto out; 618 goto out;
619 if (unlikely(sparc64_mmap_check(new_addr, new_len))) 619 if (unlikely(sparc_mmap_check(new_addr, new_len)))
620 goto out; 620 goto out;
621 621
622 down_write(&current->mm->mmap_sem); 622 down_write(&current->mm->mmap_sem);
diff --git a/arch/sparc64/kernel/sys_sparc32.c b/arch/sparc64/kernel/sys_sparc32.c
index ba5bd626b39e..97b77fb5c50e 100644
--- a/arch/sparc64/kernel/sys_sparc32.c
+++ b/arch/sparc64/kernel/sys_sparc32.c
@@ -359,7 +359,8 @@ int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
359 return err; 359 return err;
360} 360}
361 361
362int cp_compat_stat64(struct kstat *stat, struct compat_stat64 __user *statbuf) 362static int cp_compat_stat64(struct kstat *stat,
363 struct compat_stat64 __user *statbuf)
363{ 364{
364 int err; 365 int err;
365 366
@@ -870,9 +871,9 @@ asmlinkage unsigned long sys32_mremap(unsigned long addr,
870 unsigned long ret = -EINVAL; 871 unsigned long ret = -EINVAL;
871 unsigned long new_addr = __new_addr; 872 unsigned long new_addr = __new_addr;
872 873
873 if (unlikely(sparc64_mmap_check(addr, old_len))) 874 if (unlikely(sparc_mmap_check(addr, old_len)))
874 goto out; 875 goto out;
875 if (unlikely(sparc64_mmap_check(new_addr, new_len))) 876 if (unlikely(sparc_mmap_check(new_addr, new_len)))
876 goto out; 877 goto out;
877 down_write(&current->mm->mmap_sem); 878 down_write(&current->mm->mmap_sem);
878 ret = do_mremap(addr, old_len, new_len, flags, new_addr); 879 ret = do_mremap(addr, old_len, new_len, flags, new_addr);
diff --git a/arch/sparc64/kernel/sysfs.c b/arch/sparc64/kernel/sysfs.c
index e885034a6b73..84e5ce146713 100644
--- a/arch/sparc64/kernel/sysfs.c
+++ b/arch/sparc64/kernel/sysfs.c
@@ -14,7 +14,8 @@
14static DEFINE_PER_CPU(struct hv_mmu_statistics, mmu_stats) __attribute__((aligned(64))); 14static DEFINE_PER_CPU(struct hv_mmu_statistics, mmu_stats) __attribute__((aligned(64)));
15 15
16#define SHOW_MMUSTAT_ULONG(NAME) \ 16#define SHOW_MMUSTAT_ULONG(NAME) \
17static ssize_t show_##NAME(struct sys_device *dev, char *buf) \ 17static ssize_t show_##NAME(struct sys_device *dev, \
18 struct sysdev_attribute *attr, char *buf) \
18{ \ 19{ \
19 struct hv_mmu_statistics *p = &per_cpu(mmu_stats, dev->id); \ 20 struct hv_mmu_statistics *p = &per_cpu(mmu_stats, dev->id); \
20 return sprintf(buf, "%lu\n", p->NAME); \ 21 return sprintf(buf, "%lu\n", p->NAME); \
@@ -135,13 +136,16 @@ static unsigned long write_mmustat_enable(unsigned long val)
135 return sun4v_mmustat_conf(ra, &orig_ra); 136 return sun4v_mmustat_conf(ra, &orig_ra);
136} 137}
137 138
138static ssize_t show_mmustat_enable(struct sys_device *s, char *buf) 139static ssize_t show_mmustat_enable(struct sys_device *s,
140 struct sysdev_attribute *attr, char *buf)
139{ 141{
140 unsigned long val = run_on_cpu(s->id, read_mmustat_enable, 0); 142 unsigned long val = run_on_cpu(s->id, read_mmustat_enable, 0);
141 return sprintf(buf, "%lx\n", val); 143 return sprintf(buf, "%lx\n", val);
142} 144}
143 145
144static ssize_t store_mmustat_enable(struct sys_device *s, const char *buf, size_t count) 146static ssize_t store_mmustat_enable(struct sys_device *s,
147 struct sysdev_attribute *attr, const char *buf,
148 size_t count)
145{ 149{
146 unsigned long val, err; 150 unsigned long val, err;
147 int ret = sscanf(buf, "%ld", &val); 151 int ret = sscanf(buf, "%ld", &val);
@@ -179,14 +183,16 @@ static void unregister_mmu_stats(struct sys_device *s)
179#endif 183#endif
180 184
181#define SHOW_CPUDATA_ULONG_NAME(NAME, MEMBER) \ 185#define SHOW_CPUDATA_ULONG_NAME(NAME, MEMBER) \
182static ssize_t show_##NAME(struct sys_device *dev, char *buf) \ 186static ssize_t show_##NAME(struct sys_device *dev, \
187 struct sysdev_attribute *attr, char *buf) \
183{ \ 188{ \
184 cpuinfo_sparc *c = &cpu_data(dev->id); \ 189 cpuinfo_sparc *c = &cpu_data(dev->id); \
185 return sprintf(buf, "%lu\n", c->MEMBER); \ 190 return sprintf(buf, "%lu\n", c->MEMBER); \
186} 191}
187 192
188#define SHOW_CPUDATA_UINT_NAME(NAME, MEMBER) \ 193#define SHOW_CPUDATA_UINT_NAME(NAME, MEMBER) \
189static ssize_t show_##NAME(struct sys_device *dev, char *buf) \ 194static ssize_t show_##NAME(struct sys_device *dev, \
195 struct sysdev_attribute *attr, char *buf) \
190{ \ 196{ \
191 cpuinfo_sparc *c = &cpu_data(dev->id); \ 197 cpuinfo_sparc *c = &cpu_data(dev->id); \
192 return sprintf(buf, "%u\n", c->MEMBER); \ 198 return sprintf(buf, "%u\n", c->MEMBER); \
diff --git a/arch/sparc64/kernel/traps.c b/arch/sparc64/kernel/traps.c
index 369749262653..bd30ecba5630 100644
--- a/arch/sparc64/kernel/traps.c
+++ b/arch/sparc64/kernel/traps.c
@@ -1,6 +1,6 @@
1/* arch/sparc64/kernel/traps.c 1/* arch/sparc64/kernel/traps.c
2 * 2 *
3 * Copyright (C) 1995,1997 David S. Miller (davem@davemloft.net) 3 * Copyright (C) 1995,1997,2008 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1997,1999,2000 Jakub Jelinek (jakub@redhat.com) 4 * Copyright (C) 1997,1999,2000 Jakub Jelinek (jakub@redhat.com)
5 */ 5 */
6 6
@@ -11,7 +11,6 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/sched.h> 12#include <linux/sched.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/kallsyms.h>
15#include <linux/signal.h> 14#include <linux/signal.h>
16#include <linux/smp.h> 15#include <linux/smp.h>
17#include <linux/mm.h> 16#include <linux/mm.h>
@@ -37,9 +36,6 @@
37#include <asm/processor.h> 36#include <asm/processor.h>
38#include <asm/timer.h> 37#include <asm/timer.h>
39#include <asm/head.h> 38#include <asm/head.h>
40#ifdef CONFIG_KMOD
41#include <linux/kmod.h>
42#endif
43#include <asm/prom.h> 39#include <asm/prom.h>
44 40
45#include "entry.h" 41#include "entry.h"
@@ -74,7 +70,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
74 i + 1, 70 i + 1,
75 p->trapstack[i].tstate, p->trapstack[i].tpc, 71 p->trapstack[i].tstate, p->trapstack[i].tpc,
76 p->trapstack[i].tnpc, p->trapstack[i].tt); 72 p->trapstack[i].tnpc, p->trapstack[i].tt);
77 print_symbol("TRAPLOG: TPC<%s>\n", p->trapstack[i].tpc); 73 printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
78 } 74 }
79} 75}
80 76
@@ -1081,7 +1077,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
1081 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate); 1077 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
1082 printk("%s" "ERROR(%d): ", 1078 printk("%s" "ERROR(%d): ",
1083 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id()); 1079 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
1084 print_symbol("TPC<%s>\n", regs->tpc); 1080 printk("TPC<%pS>\n", (void *) regs->tpc);
1085 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n", 1081 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
1086 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(), 1082 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1087 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT, 1083 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
@@ -1689,7 +1685,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
1689 smp_processor_id(), 1685 smp_processor_id(),
1690 (type & 0x1) ? 'I' : 'D', 1686 (type & 0x1) ? 'I' : 'D',
1691 regs->tpc); 1687 regs->tpc);
1692 print_symbol(KERN_EMERG "TPC<%s>\n", regs->tpc); 1688 printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
1693 panic("Irrecoverable Cheetah+ parity error."); 1689 panic("Irrecoverable Cheetah+ parity error.");
1694 } 1690 }
1695 1691
@@ -1697,7 +1693,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
1697 smp_processor_id(), 1693 smp_processor_id(),
1698 (type & 0x1) ? 'I' : 'D', 1694 (type & 0x1) ? 'I' : 'D',
1699 regs->tpc); 1695 regs->tpc);
1700 print_symbol(KERN_WARNING "TPC<%s>\n", regs->tpc); 1696 printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
1701} 1697}
1702 1698
1703struct sun4v_error_entry { 1699struct sun4v_error_entry {
@@ -1904,9 +1900,10 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
1904 1900
1905 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n", 1901 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
1906 regs->tpc, tl); 1902 regs->tpc, tl);
1907 print_symbol(KERN_EMERG "SUN4V-ITLB: TPC<%s>\n", regs->tpc); 1903 printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
1908 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]); 1904 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
1909 print_symbol(KERN_EMERG "SUN4V-ITLB: O7<%s>\n", regs->u_regs[UREG_I7]); 1905 printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
1906 (void *) regs->u_regs[UREG_I7]);
1910 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] " 1907 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
1911 "pte[%lx] error[%lx]\n", 1908 "pte[%lx] error[%lx]\n",
1912 sun4v_err_itlb_vaddr, sun4v_err_itlb_ctx, 1909 sun4v_err_itlb_vaddr, sun4v_err_itlb_ctx,
@@ -1927,9 +1924,10 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
1927 1924
1928 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n", 1925 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
1929 regs->tpc, tl); 1926 regs->tpc, tl);
1930 print_symbol(KERN_EMERG "SUN4V-DTLB: TPC<%s>\n", regs->tpc); 1927 printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
1931 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]); 1928 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
1932 print_symbol(KERN_EMERG "SUN4V-DTLB: O7<%s>\n", regs->u_regs[UREG_I7]); 1929 printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
1930 (void *) regs->u_regs[UREG_I7]);
1933 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] " 1931 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
1934 "pte[%lx] error[%lx]\n", 1932 "pte[%lx] error[%lx]\n",
1935 sun4v_err_dtlb_vaddr, sun4v_err_dtlb_ctx, 1933 sun4v_err_dtlb_vaddr, sun4v_err_dtlb_ctx,
@@ -2111,10 +2109,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
2111 fp = ksp + STACK_BIAS; 2109 fp = ksp + STACK_BIAS;
2112 thread_base = (unsigned long) tp; 2110 thread_base = (unsigned long) tp;
2113 2111
2114 printk("Call Trace:"); 2112 printk("Call Trace:\n");
2115#ifdef CONFIG_KALLSYMS
2116 printk("\n");
2117#endif
2118 do { 2113 do {
2119 struct sparc_stackf *sf; 2114 struct sparc_stackf *sf;
2120 struct pt_regs *regs; 2115 struct pt_regs *regs;
@@ -2137,12 +2132,8 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
2137 fp = (unsigned long)sf->fp + STACK_BIAS; 2132 fp = (unsigned long)sf->fp + STACK_BIAS;
2138 } 2133 }
2139 2134
2140 printk(" [%016lx] ", pc); 2135 printk(" [%016lx] %pS\n", pc, (void *) pc);
2141 print_symbol("%s\n", pc);
2142 } while (++count < 16); 2136 } while (++count < 16);
2143#ifndef CONFIG_KALLSYMS
2144 printk("\n");
2145#endif
2146} 2137}
2147 2138
2148void dump_stack(void) 2139void dump_stack(void)
@@ -2211,9 +2202,8 @@ void die_if_kernel(char *str, struct pt_regs *regs)
2211 while (rw && 2202 while (rw &&
2212 count++ < 30&& 2203 count++ < 30&&
2213 is_kernel_stack(current, rw)) { 2204 is_kernel_stack(current, rw)) {
2214 printk("Caller[%016lx]", rw->ins[7]); 2205 printk("Caller[%016lx]: %pS\n", rw->ins[7],
2215 print_symbol(": %s", rw->ins[7]); 2206 (void *) rw->ins[7]);
2216 printk("\n");
2217 2207
2218 rw = kernel_stack_up(rw); 2208 rw = kernel_stack_up(rw);
2219 } 2209 }
diff --git a/arch/sparc64/kernel/ttable.S b/arch/sparc64/kernel/ttable.S
index 450053af039e..1ade3d6fb7fc 100644
--- a/arch/sparc64/kernel/ttable.S
+++ b/arch/sparc64/kernel/ttable.S
@@ -58,7 +58,12 @@ tl0_irq3: BTRAP(0x43)
58tl0_irq4: BTRAP(0x44) 58tl0_irq4: BTRAP(0x44)
59#endif 59#endif
60tl0_irq5: TRAP_IRQ(handler_irq, 5) 60tl0_irq5: TRAP_IRQ(handler_irq, 5)
61tl0_irq6: BTRAP(0x46) BTRAP(0x47) BTRAP(0x48) BTRAP(0x49) 61#ifdef CONFIG_SMP
62tl0_irq6: TRAP_IRQ(smp_call_function_single_client, 6)
63#else
64tl0_irq6: BTRAP(0x46)
65#endif
66tl0_irq7: BTRAP(0x47) BTRAP(0x48) BTRAP(0x49)
62tl0_irq10: BTRAP(0x4a) BTRAP(0x4b) BTRAP(0x4c) BTRAP(0x4d) 67tl0_irq10: BTRAP(0x4a) BTRAP(0x4b) BTRAP(0x4c) BTRAP(0x4d)
63tl0_irq14: TRAP_IRQ(timer_interrupt, 14) 68tl0_irq14: TRAP_IRQ(timer_interrupt, 14)
64tl0_irq15: TRAP_IRQ(handler_irq, 15) 69tl0_irq15: TRAP_IRQ(handler_irq, 15)
diff --git a/arch/sparc64/kernel/unaligned.c b/arch/sparc64/kernel/unaligned.c
index afa7fc4f5193..203ddfad9f27 100644
--- a/arch/sparc64/kernel/unaligned.c
+++ b/arch/sparc64/kernel/unaligned.c
@@ -2,7 +2,7 @@
2 * unaligned.c: Unaligned load/store trap handling with special 2 * unaligned.c: Unaligned load/store trap handling with special
3 * cases for the kernel to do them more quickly. 3 * cases for the kernel to do them more quickly.
4 * 4 *
5 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 5 * Copyright (C) 1996,2008 David S. Miller (davem@davemloft.net)
6 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 6 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 */ 7 */
8 8
@@ -20,7 +20,6 @@
20#include <asm/uaccess.h> 20#include <asm/uaccess.h>
21#include <linux/smp.h> 21#include <linux/smp.h>
22#include <linux/bitops.h> 22#include <linux/bitops.h>
23#include <linux/kallsyms.h>
24#include <asm/fpumacro.h> 23#include <asm/fpumacro.h>
25 24
26/* #define DEBUG_MNA */ 25/* #define DEBUG_MNA */
@@ -289,8 +288,8 @@ static void log_unaligned(struct pt_regs *regs)
289 if (count < 5) { 288 if (count < 5) {
290 last_time = jiffies; 289 last_time = jiffies;
291 count++; 290 count++;
292 printk("Kernel unaligned access at TPC[%lx] ", regs->tpc); 291 printk("Kernel unaligned access at TPC[%lx] %pS\n",
293 print_symbol("%s\n", regs->tpc); 292 regs->tpc, (void *) regs->tpc);
294 } 293 }
295} 294}
296 295
diff --git a/arch/sparc64/kernel/vio.c b/arch/sparc64/kernel/vio.c
index e78b3517940b..a490077891a4 100644
--- a/arch/sparc64/kernel/vio.c
+++ b/arch/sparc64/kernel/vio.c
@@ -224,7 +224,7 @@ static struct vio_dev *vio_create_one(struct mdesc_handle *hp, u64 mp,
224 if (!strcmp(type, "domain-services-port")) 224 if (!strcmp(type, "domain-services-port"))
225 bus_id_name = "ds"; 225 bus_id_name = "ds";
226 226
227 if (strlen(bus_id_name) >= KOBJ_NAME_LEN - 4) { 227 if (strlen(bus_id_name) >= BUS_ID_SIZE - 4) {
228 printk(KERN_ERR "VIO: bus_id_name [%s] is too long.\n", 228 printk(KERN_ERR "VIO: bus_id_name [%s] is too long.\n",
229 bus_id_name); 229 bus_id_name);
230 return NULL; 230 return NULL;
@@ -260,16 +260,14 @@ static struct vio_dev *vio_create_one(struct mdesc_handle *hp, u64 mp,
260 vio_fill_channel_info(hp, mp, vdev); 260 vio_fill_channel_info(hp, mp, vdev);
261 261
262 if (!id) { 262 if (!id) {
263 snprintf(vdev->dev.bus_id, BUS_ID_SIZE, "%s", 263 dev_set_name(&vdev->dev, "%s", bus_id_name);
264 bus_id_name);
265 vdev->dev_no = ~(u64)0; 264 vdev->dev_no = ~(u64)0;
266 } else if (!cfg_handle) { 265 } else if (!cfg_handle) {
267 snprintf(vdev->dev.bus_id, BUS_ID_SIZE, "%s-%lu", 266 dev_set_name(&vdev->dev, "%s-%lu", bus_id_name, *id);
268 bus_id_name, *id);
269 vdev->dev_no = *id; 267 vdev->dev_no = *id;
270 } else { 268 } else {
271 snprintf(vdev->dev.bus_id, BUS_ID_SIZE, "%s-%lu-%lu", 269 dev_set_name(&vdev->dev, "%s-%lu-%lu", bus_id_name,
272 bus_id_name, *cfg_handle, *id); 270 *cfg_handle, *id);
273 vdev->dev_no = *cfg_handle; 271 vdev->dev_no = *cfg_handle;
274 } 272 }
275 273
@@ -292,12 +290,12 @@ static struct vio_dev *vio_create_one(struct mdesc_handle *hp, u64 mp,
292 } 290 }
293 vdev->dp = dp; 291 vdev->dp = dp;
294 292
295 printk(KERN_INFO "VIO: Adding device %s\n", vdev->dev.bus_id); 293 printk(KERN_INFO "VIO: Adding device %s\n", dev_name(&vdev->dev));
296 294
297 err = device_register(&vdev->dev); 295 err = device_register(&vdev->dev);
298 if (err) { 296 if (err) {
299 printk(KERN_ERR "VIO: Could not register device %s, err=%d\n", 297 printk(KERN_ERR "VIO: Could not register device %s, err=%d\n",
300 vdev->dev.bus_id, err); 298 dev_name(&vdev->dev), err);
301 kfree(vdev); 299 kfree(vdev);
302 return NULL; 300 return NULL;
303 } 301 }
@@ -330,7 +328,7 @@ static void vio_remove(struct mdesc_handle *hp, u64 node)
330 dev = device_find_child(&root_vdev->dev, (void *) node, 328 dev = device_find_child(&root_vdev->dev, (void *) node,
331 vio_md_node_match); 329 vio_md_node_match);
332 if (dev) { 330 if (dev) {
333 printk(KERN_INFO "VIO: Removing device %s\n", dev->bus_id); 331 printk(KERN_INFO "VIO: Removing device %s\n", dev_name(dev));
334 332
335 device_unregister(dev); 333 device_unregister(dev);
336 } 334 }
diff --git a/arch/sparc64/lib/copy_page.S b/arch/sparc64/lib/copy_page.S
index 37460666a5c3..b243d3b606ba 100644
--- a/arch/sparc64/lib/copy_page.S
+++ b/arch/sparc64/lib/copy_page.S
@@ -25,9 +25,9 @@
25 25
26#define DCACHE_SIZE (PAGE_SIZE * 2) 26#define DCACHE_SIZE (PAGE_SIZE * 2)
27 27
28#if (PAGE_SHIFT == 13) || (PAGE_SHIFT == 19) 28#if (PAGE_SHIFT == 13)
29#define PAGE_SIZE_REM 0x80 29#define PAGE_SIZE_REM 0x80
30#elif (PAGE_SHIFT == 16) || (PAGE_SHIFT == 22) 30#elif (PAGE_SHIFT == 16)
31#define PAGE_SIZE_REM 0x100 31#define PAGE_SIZE_REM 0x100
32#else 32#else
33#error Wrong PAGE_SHIFT specified 33#error Wrong PAGE_SHIFT specified
@@ -198,7 +198,7 @@ cheetah_copy_page_insn:
198 cmp %o2, PAGE_SIZE_REM 198 cmp %o2, PAGE_SIZE_REM
199 bne,pt %xcc, 1b 199 bne,pt %xcc, 1b
200 add %o0, 0x40, %o0 200 add %o0, 0x40, %o0
201#if (PAGE_SHIFT == 16) || (PAGE_SHIFT == 22) 201#if (PAGE_SHIFT == 16)
202 TOUCH(f0, f2, f4, f6, f8, f10, f12, f14) 202 TOUCH(f0, f2, f4, f6, f8, f10, f12, f14)
203 ldda [%o1] ASI_BLK_P, %f32 203 ldda [%o1] ASI_BLK_P, %f32
204 stda %f48, [%o0] %asi 204 stda %f48, [%o0] %asi
diff --git a/arch/sparc64/mm/fault.c b/arch/sparc64/mm/fault.c
index 236f4d228d2b..ea7d7ae76bc2 100644
--- a/arch/sparc64/mm/fault.c
+++ b/arch/sparc64/mm/fault.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * arch/sparc64/mm/fault.c: Page fault handlers for the 64-bit Sparc. 2 * arch/sparc64/mm/fault.c: Page fault handlers for the 64-bit Sparc.
3 * 3 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 4 * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
5 * Copyright (C) 1997, 1999 Jakub Jelinek (jj@ultra.linux.cz) 5 * Copyright (C) 1997, 1999 Jakub Jelinek (jj@ultra.linux.cz)
6 */ 6 */
7 7
@@ -18,7 +18,6 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/kprobes.h> 20#include <linux/kprobes.h>
21#include <linux/kallsyms.h>
22#include <linux/kdebug.h> 21#include <linux/kdebug.h>
23 22
24#include <asm/page.h> 23#include <asm/page.h>
@@ -115,7 +114,7 @@ static void bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
115 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n", 114 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
116 regs->tpc); 115 regs->tpc);
117 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]); 116 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
118 print_symbol("RPC: <%s>\n", regs->u_regs[15]); 117 printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
119 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr); 118 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
120 dump_stack(); 119 dump_stack();
121 unhandled_fault(regs->tpc, current, regs); 120 unhandled_fault(regs->tpc, current, regs);
diff --git a/arch/sparc64/mm/tsb.c b/arch/sparc64/mm/tsb.c
index fe70c8a557b5..3547937b17a2 100644
--- a/arch/sparc64/mm/tsb.c
+++ b/arch/sparc64/mm/tsb.c
@@ -96,12 +96,6 @@ void flush_tsb_user(struct mmu_gather *mp)
96#elif defined(CONFIG_SPARC64_PAGE_SIZE_64KB) 96#elif defined(CONFIG_SPARC64_PAGE_SIZE_64KB)
97#define HV_PGSZ_IDX_BASE HV_PGSZ_IDX_64K 97#define HV_PGSZ_IDX_BASE HV_PGSZ_IDX_64K
98#define HV_PGSZ_MASK_BASE HV_PGSZ_MASK_64K 98#define HV_PGSZ_MASK_BASE HV_PGSZ_MASK_64K
99#elif defined(CONFIG_SPARC64_PAGE_SIZE_512KB)
100#define HV_PGSZ_IDX_BASE HV_PGSZ_IDX_512K
101#define HV_PGSZ_MASK_BASE HV_PGSZ_MASK_512K
102#elif defined(CONFIG_SPARC64_PAGE_SIZE_4MB)
103#define HV_PGSZ_IDX_BASE HV_PGSZ_IDX_4MB
104#define HV_PGSZ_MASK_BASE HV_PGSZ_MASK_4MB
105#else 99#else
106#error Broken base page size setting... 100#error Broken base page size setting...
107#endif 101#endif
diff --git a/arch/sparc64/mm/ultra.S b/arch/sparc64/mm/ultra.S
index 9bb2d90a9df6..4c8ca131ffaf 100644
--- a/arch/sparc64/mm/ultra.S
+++ b/arch/sparc64/mm/ultra.S
@@ -688,6 +688,11 @@ xcall_call_function:
688 wr %g0, (1 << PIL_SMP_CALL_FUNC), %set_softint 688 wr %g0, (1 << PIL_SMP_CALL_FUNC), %set_softint
689 retry 689 retry
690 690
691 .globl xcall_call_function_single
692xcall_call_function_single:
693 wr %g0, (1 << PIL_SMP_CALL_FUNC_SNGL), %set_softint
694 retry
695
691 .globl xcall_receive_signal 696 .globl xcall_receive_signal
692xcall_receive_signal: 697xcall_receive_signal:
693 wr %g0, (1 << PIL_SMP_RECEIVE_SIGNAL), %set_softint 698 wr %g0, (1 << PIL_SMP_RECEIVE_SIGNAL), %set_softint
diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
index 85a87d2ac0c0..092f019e033a 100644
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -8,7 +8,7 @@ source "lib/Kconfig.debug"
8config STRICT_DEVMEM 8config STRICT_DEVMEM
9 bool "Filter access to /dev/mem" 9 bool "Filter access to /dev/mem"
10 help 10 help
11 If this option is left on, you allow userspace (root) access to all 11 If this option is disabled, you allow userspace (root) access to all
12 of memory, including kernel and userspace memory. Accidental 12 of memory, including kernel and userspace memory. Accidental
13 access to this is obviously disastrous, but specific access can 13 access to this is obviously disastrous, but specific access can
14 be used by people debugging the kernel. Note that with PAT support 14 be used by people debugging the kernel. Note that with PAT support
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k7.h b/arch/x86/kernel/cpu/cpufreq/powernow-k7.h
index f8a63b3664e3..35fb4eaf6e1c 100644
--- a/arch/x86/kernel/cpu/cpufreq/powernow-k7.h
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k7.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: powernow-k7.h,v 1.2 2003/02/10 18:26:01 davej Exp $
3 * (C) 2003 Dave Jones. 2 * (C) 2003 Dave Jones.
4 * 3 *
5 * Licensed under the terms of the GNU GPL License version 2. 4 * Licensed under the terms of the GNU GPL License version 2.
diff --git a/arch/x86/kernel/cpu/mcheck/mce_64.c b/arch/x86/kernel/cpu/mcheck/mce_64.c
index c4a7ec31394c..9ab65be82427 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_64.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_64.c
@@ -762,10 +762,14 @@ DEFINE_PER_CPU(struct sys_device, device_mce);
762 762
763/* Why are there no generic functions for this? */ 763/* Why are there no generic functions for this? */
764#define ACCESSOR(name, var, start) \ 764#define ACCESSOR(name, var, start) \
765 static ssize_t show_ ## name(struct sys_device *s, char *buf) { \ 765 static ssize_t show_ ## name(struct sys_device *s, \
766 struct sysdev_attribute *attr, \
767 char *buf) { \
766 return sprintf(buf, "%lx\n", (unsigned long)var); \ 768 return sprintf(buf, "%lx\n", (unsigned long)var); \
767 } \ 769 } \
768 static ssize_t set_ ## name(struct sys_device *s,const char *buf,size_t siz) { \ 770 static ssize_t set_ ## name(struct sys_device *s, \
771 struct sysdev_attribute *attr, \
772 const char *buf, size_t siz) { \
769 char *end; \ 773 char *end; \
770 unsigned long new = simple_strtoul(buf, &end, 0); \ 774 unsigned long new = simple_strtoul(buf, &end, 0); \
771 if (end == buf) return -EINVAL; \ 775 if (end == buf) return -EINVAL; \
@@ -786,14 +790,16 @@ ACCESSOR(bank3ctl,bank[3],mce_restart())
786ACCESSOR(bank4ctl,bank[4],mce_restart()) 790ACCESSOR(bank4ctl,bank[4],mce_restart())
787ACCESSOR(bank5ctl,bank[5],mce_restart()) 791ACCESSOR(bank5ctl,bank[5],mce_restart())
788 792
789static ssize_t show_trigger(struct sys_device *s, char *buf) 793static ssize_t show_trigger(struct sys_device *s, struct sysdev_attribute *attr,
794 char *buf)
790{ 795{
791 strcpy(buf, trigger); 796 strcpy(buf, trigger);
792 strcat(buf, "\n"); 797 strcat(buf, "\n");
793 return strlen(trigger) + 1; 798 return strlen(trigger) + 1;
794} 799}
795 800
796static ssize_t set_trigger(struct sys_device *s,const char *buf,size_t siz) 801static ssize_t set_trigger(struct sys_device *s, struct sysdev_attribute *attr,
802 const char *buf,size_t siz)
797{ 803{
798 char *p; 804 char *p;
799 int len; 805 int len;
@@ -806,12 +812,12 @@ static ssize_t set_trigger(struct sys_device *s,const char *buf,size_t siz)
806} 812}
807 813
808static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger); 814static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger);
809ACCESSOR(tolerant,tolerant,) 815static SYSDEV_INT_ATTR(tolerant, 0644, tolerant);
810ACCESSOR(check_interval,check_interval,mce_restart()) 816ACCESSOR(check_interval,check_interval,mce_restart())
811static struct sysdev_attribute *mce_attributes[] = { 817static struct sysdev_attribute *mce_attributes[] = {
812 &attr_bank0ctl, &attr_bank1ctl, &attr_bank2ctl, 818 &attr_bank0ctl, &attr_bank1ctl, &attr_bank2ctl,
813 &attr_bank3ctl, &attr_bank4ctl, &attr_bank5ctl, 819 &attr_bank3ctl, &attr_bank4ctl, &attr_bank5ctl,
814 &attr_tolerant, &attr_check_interval, &attr_trigger, 820 &attr_tolerant.attr, &attr_check_interval, &attr_trigger,
815 NULL 821 NULL
816}; 822};
817 823
diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
index 1f4cc48c14c6..d5ae2243f0b9 100644
--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
@@ -35,6 +35,7 @@ atomic_t therm_throt_en = ATOMIC_INIT(0);
35 35
36#define define_therm_throt_sysdev_show_func(name) \ 36#define define_therm_throt_sysdev_show_func(name) \
37static ssize_t therm_throt_sysdev_show_##name(struct sys_device *dev, \ 37static ssize_t therm_throt_sysdev_show_##name(struct sys_device *dev, \
38 struct sysdev_attribute *attr, \
38 char *buf) \ 39 char *buf) \
39{ \ 40{ \
40 unsigned int cpu = dev->id; \ 41 unsigned int cpu = dev->id; \
diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
index 2de5fa2bbf77..14b11b3be31c 100644
--- a/arch/x86/kernel/cpuid.c
+++ b/arch/x86/kernel/cpuid.c
@@ -141,8 +141,8 @@ static __cpuinit int cpuid_device_create(int cpu)
141{ 141{
142 struct device *dev; 142 struct device *dev;
143 143
144 dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), 144 dev = device_create_drvdata(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu),
145 "cpu%d", cpu); 145 NULL, "cpu%d", cpu);
146 return IS_ERR(dev) ? PTR_ERR(dev) : 0; 146 return IS_ERR(dev) ? PTR_ERR(dev) : 0;
147} 147}
148 148
diff --git a/arch/x86/kernel/microcode.c b/arch/x86/kernel/microcode.c
index 56b933119a04..fc4790638b69 100644
--- a/arch/x86/kernel/microcode.c
+++ b/arch/x86/kernel/microcode.c
@@ -644,7 +644,9 @@ static void microcode_fini_cpu(int cpu)
644 mutex_unlock(&microcode_mutex); 644 mutex_unlock(&microcode_mutex);
645} 645}
646 646
647static ssize_t reload_store(struct sys_device *dev, const char *buf, size_t sz) 647static ssize_t reload_store(struct sys_device *dev,
648 struct sysdev_attribute *attr,
649 const char *buf, size_t sz)
648{ 650{
649 struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; 651 struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
650 char *end; 652 char *end;
@@ -674,14 +676,16 @@ static ssize_t reload_store(struct sys_device *dev, const char *buf, size_t sz)
674 return sz; 676 return sz;
675} 677}
676 678
677static ssize_t version_show(struct sys_device *dev, char *buf) 679static ssize_t version_show(struct sys_device *dev,
680 struct sysdev_attribute *attr, char *buf)
678{ 681{
679 struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; 682 struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
680 683
681 return sprintf(buf, "0x%x\n", uci->rev); 684 return sprintf(buf, "0x%x\n", uci->rev);
682} 685}
683 686
684static ssize_t pf_show(struct sys_device *dev, char *buf) 687static ssize_t pf_show(struct sys_device *dev,
688 struct sysdev_attribute *attr, char *buf)
685{ 689{
686 struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; 690 struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
687 691
diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
index a153b3905f60..9fd809552447 100644
--- a/arch/x86/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
@@ -149,8 +149,8 @@ static int __cpuinit msr_device_create(int cpu)
149{ 149{
150 struct device *dev; 150 struct device *dev;
151 151
152 dev = device_create(msr_class, NULL, MKDEV(MSR_MAJOR, cpu), 152 dev = device_create_drvdata(msr_class, NULL, MKDEV(MSR_MAJOR, cpu),
153 "msr%d", cpu); 153 NULL, "msr%d", cpu);
154 return IS_ERR(dev) ? PTR_ERR(dev) : 0; 154 return IS_ERR(dev) ? PTR_ERR(dev) : 0;
155} 155}
156 156
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index a4213c00dffc..cbecb05551bb 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -314,8 +314,7 @@ int dma_supported(struct device *dev, u64 mask)
314{ 314{
315#ifdef CONFIG_PCI 315#ifdef CONFIG_PCI
316 if (mask > 0xffffffff && forbid_dac > 0) { 316 if (mask > 0xffffffff && forbid_dac > 0) {
317 printk(KERN_INFO "PCI: Disallowing DAC for device %s\n", 317 dev_info(dev, "PCI: Disallowing DAC for device\n");
318 dev->bus_id);
319 return 0; 318 return 0;
320 } 319 }
321#endif 320#endif
@@ -342,8 +341,7 @@ int dma_supported(struct device *dev, u64 mask)
342 type. Normally this doesn't make any difference, but gives 341 type. Normally this doesn't make any difference, but gives
343 more gentle handling of IOMMU overflow. */ 342 more gentle handling of IOMMU overflow. */
344 if (iommu_sac_force && (mask >= DMA_40BIT_MASK)) { 343 if (iommu_sac_force && (mask >= DMA_40BIT_MASK)) {
345 printk(KERN_INFO "%s: Force SAC with mask %Lx\n", 344 dev_info(dev, "Force SAC with mask %Lx\n", mask);
346 dev->bus_id, mask);
347 return 0; 345 return 0;
348 } 346 }
349 347
diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
index be60961f8695..df5f142657d2 100644
--- a/arch/x86/kernel/pci-gart_64.c
+++ b/arch/x86/kernel/pci-gart_64.c
@@ -198,9 +198,7 @@ static void iommu_full(struct device *dev, size_t size, int dir)
198 * out. Hopefully no network devices use single mappings that big. 198 * out. Hopefully no network devices use single mappings that big.
199 */ 199 */
200 200
201 printk(KERN_ERR 201 dev_err(dev, "PCI-DMA: Out of IOMMU space for %lu bytes\n", size);
202 "PCI-DMA: Out of IOMMU space for %lu bytes at device %s\n",
203 size, dev->bus_id);
204 202
205 if (size > PAGE_SIZE*EMERGENCY_PAGES) { 203 if (size > PAGE_SIZE*EMERGENCY_PAGES) {
206 if (dir == PCI_DMA_FROMDEVICE || dir == PCI_DMA_BIDIRECTIONAL) 204 if (dir == PCI_DMA_FROMDEVICE || dir == PCI_DMA_BIDIRECTIONAL)
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index 9fc8551a1cf6..02e417d3d8e9 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -194,8 +194,8 @@ config HOTPLUG
194 plugged into slots found on all modern laptop computers. Another 194 plugged into slots found on all modern laptop computers. Another
195 example, used on modern desktops as well as laptops, is USB. 195 example, used on modern desktops as well as laptops, is USB.
196 196
197 Enable HOTPLUG and KMOD, and build a modular kernel. Get agent 197 Enable HOTPLUG and build a modular kernel. Get agent software
198 software (at <http://linux-hotplug.sourceforge.net/>) and install it. 198 (from <http://linux-hotplug.sourceforge.net/>) and install it.
199 Then your kernel will automatically call out to a user mode "policy 199 Then your kernel will automatically call out to a user mode "policy
200 agent" (/sbin/hotplug) to load modules and set up software needed 200 agent" (/sbin/hotplug) to load modules and set up software needed
201 to use devices as you hotplug them. 201 to use devices as you hotplug them.
diff --git a/block/bsg.c b/block/bsg.c
index 5fb9b0bdbe85..5a68b09a69ba 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -1044,7 +1044,8 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
1044 bcd->release = release; 1044 bcd->release = release;
1045 kref_init(&bcd->ref); 1045 kref_init(&bcd->ref);
1046 dev = MKDEV(bsg_major, bcd->minor); 1046 dev = MKDEV(bsg_major, bcd->minor);
1047 class_dev = device_create(bsg_class, parent, dev, "%s", devname); 1047 class_dev = device_create_drvdata(bsg_class, parent, dev, NULL,
1048 "%s", devname);
1048 if (IS_ERR(class_dev)) { 1049 if (IS_ERR(class_dev)) {
1049 ret = PTR_ERR(class_dev); 1050 ret = PTR_ERR(class_dev);
1050 goto put_dev; 1051 goto put_dev;
diff --git a/block/genhd.c b/block/genhd.c
index 9074f384b097..c13cc77291af 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -183,6 +183,7 @@ static int exact_lock(dev_t devt, void *data)
183void add_disk(struct gendisk *disk) 183void add_disk(struct gendisk *disk)
184{ 184{
185 struct backing_dev_info *bdi; 185 struct backing_dev_info *bdi;
186 int retval;
186 187
187 disk->flags |= GENHD_FL_UP; 188 disk->flags |= GENHD_FL_UP;
188 blk_register_region(MKDEV(disk->major, disk->first_minor), 189 blk_register_region(MKDEV(disk->major, disk->first_minor),
@@ -193,7 +194,8 @@ void add_disk(struct gendisk *disk)
193 194
194 bdi = &disk->queue->backing_dev_info; 195 bdi = &disk->queue->backing_dev_info;
195 bdi_register_dev(bdi, MKDEV(disk->major, disk->first_minor)); 196 bdi_register_dev(bdi, MKDEV(disk->major, disk->first_minor));
196 sysfs_create_link(&disk->dev.kobj, &bdi->dev->kobj, "bdi"); 197 retval = sysfs_create_link(&disk->dev.kobj, &bdi->dev->kobj, "bdi");
198 WARN_ON(retval);
197} 199}
198 200
199EXPORT_SYMBOL(add_disk); 201EXPORT_SYMBOL(add_disk);
@@ -225,89 +227,111 @@ struct gendisk *get_gendisk(dev_t devt, int *part)
225} 227}
226 228
227/* 229/*
228 * print a full list of all partitions - intended for places where the root 230 * print a partitions - intended for places where the root filesystem can't be
229 * filesystem can't be mounted and thus to give the victim some idea of what 231 * mounted and thus to give the victim some idea of what went wrong
230 * went wrong
231 */ 232 */
232void __init printk_all_partitions(void) 233static int printk_partition(struct device *dev, void *data)
233{ 234{
234 struct device *dev;
235 struct gendisk *sgp; 235 struct gendisk *sgp;
236 char buf[BDEVNAME_SIZE]; 236 char buf[BDEVNAME_SIZE];
237 int n; 237 int n;
238 238
239 mutex_lock(&block_class_lock); 239 if (dev->type != &disk_type)
240 /* For each block device... */ 240 goto exit;
241 list_for_each_entry(dev, &block_class.devices, node) {
242 if (dev->type != &disk_type)
243 continue;
244 sgp = dev_to_disk(dev);
245 /*
246 * Don't show empty devices or things that have been surpressed
247 */
248 if (get_capacity(sgp) == 0 ||
249 (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
250 continue;
251 241
252 /* 242 sgp = dev_to_disk(dev);
253 * Note, unlike /proc/partitions, I am showing the numbers in 243 /*
254 * hex - the same format as the root= option takes. 244 * Don't show empty devices or things that have been surpressed
255 */ 245 */
256 printk("%02x%02x %10llu %s", 246 if (get_capacity(sgp) == 0 ||
257 sgp->major, sgp->first_minor, 247 (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
258 (unsigned long long)get_capacity(sgp) >> 1, 248 goto exit;
259 disk_name(sgp, 0, buf)); 249
260 if (sgp->driverfs_dev != NULL && 250 /*
261 sgp->driverfs_dev->driver != NULL) 251 * Note, unlike /proc/partitions, I am showing the numbers in
262 printk(" driver: %s\n", 252 * hex - the same format as the root= option takes.
263 sgp->driverfs_dev->driver->name); 253 */
264 else 254 printk("%02x%02x %10llu %s",
265 printk(" (driver?)\n"); 255 sgp->major, sgp->first_minor,
266 256 (unsigned long long)get_capacity(sgp) >> 1,
267 /* now show the partitions */ 257 disk_name(sgp, 0, buf));
268 for (n = 0; n < sgp->minors - 1; ++n) { 258 if (sgp->driverfs_dev != NULL &&
269 if (sgp->part[n] == NULL) 259 sgp->driverfs_dev->driver != NULL)
270 continue; 260 printk(" driver: %s\n",
271 if (sgp->part[n]->nr_sects == 0) 261 sgp->driverfs_dev->driver->name);
272 continue; 262 else
273 printk(" %02x%02x %10llu %s\n", 263 printk(" (driver?)\n");
274 sgp->major, n + 1 + sgp->first_minor, 264
275 (unsigned long long)sgp->part[n]->nr_sects >> 1, 265 /* now show the partitions */
276 disk_name(sgp, n + 1, buf)); 266 for (n = 0; n < sgp->minors - 1; ++n) {
277 } 267 if (sgp->part[n] == NULL)
268 goto exit;
269 if (sgp->part[n]->nr_sects == 0)
270 goto exit;
271 printk(" %02x%02x %10llu %s\n",
272 sgp->major, n + 1 + sgp->first_minor,
273 (unsigned long long)sgp->part[n]->nr_sects >> 1,
274 disk_name(sgp, n + 1, buf));
278 } 275 }
276exit:
277 return 0;
278}
279 279
280/*
281 * print a full list of all partitions - intended for places where the root
282 * filesystem can't be mounted and thus to give the victim some idea of what
283 * went wrong
284 */
285void __init printk_all_partitions(void)
286{
287 mutex_lock(&block_class_lock);
288 class_for_each_device(&block_class, NULL, NULL, printk_partition);
280 mutex_unlock(&block_class_lock); 289 mutex_unlock(&block_class_lock);
281} 290}
282 291
283#ifdef CONFIG_PROC_FS 292#ifdef CONFIG_PROC_FS
284/* iterator */ 293/* iterator */
294static int find_start(struct device *dev, void *data)
295{
296 loff_t k = *(loff_t *)data;
297
298 if (dev->type != &disk_type)
299 return 0;
300 if (!k--)
301 return 1;
302 return 0;
303}
304
285static void *part_start(struct seq_file *part, loff_t *pos) 305static void *part_start(struct seq_file *part, loff_t *pos)
286{ 306{
287 loff_t k = *pos;
288 struct device *dev; 307 struct device *dev;
308 loff_t n = *pos;
309
310 if (!n)
311 seq_puts(part, "major minor #blocks name\n\n");
289 312
290 mutex_lock(&block_class_lock); 313 mutex_lock(&block_class_lock);
291 list_for_each_entry(dev, &block_class.devices, node) { 314 dev = class_find_device(&block_class, NULL, (void *)pos, find_start);
292 if (dev->type != &disk_type) 315 if (dev)
293 continue; 316 return dev_to_disk(dev);
294 if (!k--)
295 return dev_to_disk(dev);
296 }
297 return NULL; 317 return NULL;
298} 318}
299 319
320static int find_next(struct device *dev, void *data)
321{
322 if (dev->type == &disk_type)
323 return 1;
324 return 0;
325}
326
300static void *part_next(struct seq_file *part, void *v, loff_t *pos) 327static void *part_next(struct seq_file *part, void *v, loff_t *pos)
301{ 328{
302 struct gendisk *gp = v; 329 struct gendisk *gp = v;
303 struct device *dev; 330 struct device *dev;
304 ++*pos; 331 ++*pos;
305 list_for_each_entry(dev, &gp->dev.node, node) { 332 dev = class_find_device(&block_class, &gp->dev, NULL, find_next);
306 if (&dev->node == &block_class.devices) 333 if (dev)
307 return NULL; 334 return dev_to_disk(dev);
308 if (dev->type == &disk_type)
309 return dev_to_disk(dev);
310 }
311 return NULL; 335 return NULL;
312} 336}
313 337
@@ -322,9 +346,6 @@ static int show_partition(struct seq_file *part, void *v)
322 int n; 346 int n;
323 char buf[BDEVNAME_SIZE]; 347 char buf[BDEVNAME_SIZE];
324 348
325 if (&sgp->dev.node == block_class.devices.next)
326 seq_puts(part, "major minor #blocks name\n\n");
327
328 /* Don't show non-partitionable removeable devices or empty devices */ 349 /* Don't show non-partitionable removeable devices or empty devices */
329 if (!get_capacity(sgp) || 350 if (!get_capacity(sgp) ||
330 (sgp->minors == 1 && (sgp->flags & GENHD_FL_REMOVABLE))) 351 (sgp->minors == 1 && (sgp->flags & GENHD_FL_REMOVABLE)))
@@ -370,7 +391,10 @@ static struct kobject *base_probe(dev_t devt, int *part, void *data)
370 391
371static int __init genhd_device_init(void) 392static int __init genhd_device_init(void)
372{ 393{
373 int error = class_register(&block_class); 394 int error;
395
396 block_class.dev_kobj = sysfs_dev_block_kobj;
397 error = class_register(&block_class);
374 if (unlikely(error)) 398 if (unlikely(error))
375 return error; 399 return error;
376 bdev_map = kobj_map_init(base_probe, &block_class_lock); 400 bdev_map = kobj_map_init(base_probe, &block_class_lock);
@@ -532,6 +556,7 @@ static struct device_type disk_type = {
532 .release = disk_release, 556 .release = disk_release,
533}; 557};
534 558
559#ifdef CONFIG_PROC_FS
535/* 560/*
536 * aggregate disk stat collector. Uses the same stats that the sysfs 561 * aggregate disk stat collector. Uses the same stats that the sysfs
537 * entries do, above, but makes them available through one seq_file. 562 * entries do, above, but makes them available through one seq_file.
@@ -542,16 +567,12 @@ static struct device_type disk_type = {
542 567
543static void *diskstats_start(struct seq_file *part, loff_t *pos) 568static void *diskstats_start(struct seq_file *part, loff_t *pos)
544{ 569{
545 loff_t k = *pos;
546 struct device *dev; 570 struct device *dev;
547 571
548 mutex_lock(&block_class_lock); 572 mutex_lock(&block_class_lock);
549 list_for_each_entry(dev, &block_class.devices, node) { 573 dev = class_find_device(&block_class, NULL, (void *)pos, find_start);
550 if (dev->type != &disk_type) 574 if (dev)
551 continue; 575 return dev_to_disk(dev);
552 if (!k--)
553 return dev_to_disk(dev);
554 }
555 return NULL; 576 return NULL;
556} 577}
557 578
@@ -561,12 +582,9 @@ static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos)
561 struct device *dev; 582 struct device *dev;
562 583
563 ++*pos; 584 ++*pos;
564 list_for_each_entry(dev, &gp->dev.node, node) { 585 dev = class_find_device(&block_class, &gp->dev, NULL, find_next);
565 if (&dev->node == &block_class.devices) 586 if (dev)
566 return NULL; 587 return dev_to_disk(dev);
567 if (dev->type == &disk_type)
568 return dev_to_disk(dev);
569 }
570 return NULL; 588 return NULL;
571} 589}
572 590
@@ -641,6 +659,7 @@ const struct seq_operations diskstats_op = {
641 .stop = diskstats_stop, 659 .stop = diskstats_stop,
642 .show = diskstats_show 660 .show = diskstats_show
643}; 661};
662#endif /* CONFIG_PROC_FS */
644 663
645static void media_change_notify_thread(struct work_struct *work) 664static void media_change_notify_thread(struct work_struct *work)
646{ 665{
@@ -665,24 +684,38 @@ void genhd_media_change_notify(struct gendisk *disk)
665EXPORT_SYMBOL_GPL(genhd_media_change_notify); 684EXPORT_SYMBOL_GPL(genhd_media_change_notify);
666#endif /* 0 */ 685#endif /* 0 */
667 686
687struct find_block {
688 const char *name;
689 int part;
690};
691
692static int match_id(struct device *dev, void *data)
693{
694 struct find_block *find = data;
695
696 if (dev->type != &disk_type)
697 return 0;
698 if (strcmp(dev->bus_id, find->name) == 0) {
699 struct gendisk *disk = dev_to_disk(dev);
700 if (find->part < disk->minors)
701 return 1;
702 }
703 return 0;
704}
705
668dev_t blk_lookup_devt(const char *name, int part) 706dev_t blk_lookup_devt(const char *name, int part)
669{ 707{
670 struct device *dev; 708 struct device *dev;
671 dev_t devt = MKDEV(0, 0); 709 dev_t devt = MKDEV(0, 0);
710 struct find_block find;
672 711
673 mutex_lock(&block_class_lock); 712 mutex_lock(&block_class_lock);
674 list_for_each_entry(dev, &block_class.devices, node) { 713 find.name = name;
675 if (dev->type != &disk_type) 714 find.part = part;
676 continue; 715 dev = class_find_device(&block_class, NULL, (void *)&find, match_id);
677 if (strcmp(dev->bus_id, name) == 0) { 716 if (dev)
678 struct gendisk *disk = dev_to_disk(dev); 717 devt = MKDEV(MAJOR(dev->devt),
679 718 MINOR(dev->devt) + part);
680 if (part < disk->minors)
681 devt = MKDEV(MAJOR(dev->devt),
682 MINOR(dev->devt) + part);
683 break;
684 }
685 }
686 mutex_unlock(&block_class_lock); 719 mutex_unlock(&block_class_lock);
687 720
688 return devt; 721 return devt;
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 55c17afbe669..2655bc1b4eeb 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -263,22 +263,22 @@ static int acpi_fan_add(struct acpi_device *device)
263 goto end; 263 goto end;
264 } 264 }
265 265
266 printk(KERN_INFO PREFIX 266 dev_info(&device->dev, "registered as cooling_device%d\n", cdev->id);
267 "%s is registered as cooling_device%d\n",
268 device->dev.bus_id, cdev->id);
269 267
270 acpi_driver_data(device) = cdev; 268 acpi_driver_data(device) = cdev;
271 result = sysfs_create_link(&device->dev.kobj, 269 result = sysfs_create_link(&device->dev.kobj,
272 &cdev->device.kobj, 270 &cdev->device.kobj,
273 "thermal_cooling"); 271 "thermal_cooling");
274 if (result) 272 if (result)
275 printk(KERN_ERR PREFIX "Create sysfs link\n"); 273 dev_err(&device->dev, "Failed to create sysfs link "
274 "'thermal_cooling'\n");
276 275
277 result = sysfs_create_link(&cdev->device.kobj, 276 result = sysfs_create_link(&cdev->device.kobj,
278 &device->dev.kobj, 277 &device->dev.kobj,
279 "device"); 278 "device");
280 if (result) 279 if (result)
281 printk(KERN_ERR PREFIX "Create sysfs link\n"); 280 dev_err(&device->dev, "Failed to create sysfs link "
281 "'device'\n");
282 282
283 result = acpi_fan_add_fs(device); 283 result = acpi_fan_add_fs(device);
284 if (result) 284 if (result)
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 2f173e83f8a7..084109507c9f 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -146,8 +146,7 @@ static int acpi_bind_one(struct device *dev, acpi_handle handle)
146 acpi_status status; 146 acpi_status status;
147 147
148 if (dev->archdata.acpi_handle) { 148 if (dev->archdata.acpi_handle) {
149 printk(KERN_WARNING PREFIX 149 dev_warn(dev, "Drivers changed 'acpi_handle'\n");
150 "Drivers changed 'acpi_handle' for %s\n", dev->bus_id);
151 return -EINVAL; 150 return -EINVAL;
152 } 151 }
153 get_device(dev); 152 get_device(dev);
@@ -195,8 +194,7 @@ static int acpi_unbind_one(struct device *dev)
195 /* acpi_bind_one increase refcnt by one */ 194 /* acpi_bind_one increase refcnt by one */
196 put_device(dev); 195 put_device(dev);
197 } else { 196 } else {
198 printk(KERN_ERR PREFIX 197 dev_err(dev, "Oops, 'acpi_handle' corrupt\n");
199 "Oops, 'acpi_handle' corrupt for %s\n", dev->bus_id);
200 } 198 }
201 return 0; 199 return 0;
202} 200}
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index ec0f2d581ece..e36422a7122c 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -714,9 +714,8 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
714 goto end; 714 goto end;
715 } 715 }
716 716
717 printk(KERN_INFO PREFIX 717 dev_info(&device->dev, "registered as cooling_device%d\n",
718 "%s is registered as cooling_device%d\n", 718 pr->cdev->id);
719 device->dev.bus_id, pr->cdev->id);
720 719
721 result = sysfs_create_link(&device->dev.kobj, 720 result = sysfs_create_link(&device->dev.kobj,
722 &pr->cdev->device.kobj, 721 &pr->cdev->device.kobj,
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index f3132aa47a69..f6f52c1a2aba 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -471,7 +471,7 @@ static int acpi_device_register(struct acpi_device *device,
471 device->dev.release = &acpi_device_release; 471 device->dev.release = &acpi_device_release;
472 result = device_add(&device->dev); 472 result = device_add(&device->dev);
473 if(result) { 473 if(result) {
474 printk(KERN_ERR PREFIX "Error adding device %s", device->dev.bus_id); 474 dev_err(&device->dev, "Error adding device\n");
475 goto end; 475 goto end;
476 } 476 }
477 477
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 84c795fb9b1e..30a341337933 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -1179,8 +1179,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
1179 1179
1180 tz->tz_enabled = 1; 1180 tz->tz_enabled = 1;
1181 1181
1182 printk(KERN_INFO PREFIX "%s is registered as thermal_zone%d\n", 1182 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
1183 tz->device->dev.bus_id, tz->thermal_zone->id); 1183 tz->thermal_zone->id);
1184 return 0; 1184 return 0;
1185} 1185}
1186 1186
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 64c889331f3b..37b9e16710d6 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -762,9 +762,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
762 if (IS_ERR(device->cdev)) 762 if (IS_ERR(device->cdev))
763 return; 763 return;
764 764
765 printk(KERN_INFO PREFIX 765 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
766 "%s is registered as cooling_device%d\n", 766 device->cdev->id);
767 device->dev->dev.bus_id, device->cdev->id);
768 result = sysfs_create_link(&device->dev->dev.kobj, 767 result = sysfs_create_link(&device->dev->dev.kobj,
769 &device->cdev->device.kobj, 768 &device->cdev->device.kobj,
770 "thermal_cooling"); 769 "thermal_cooling");
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index d47482fa1d21..6318f6b57360 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -27,8 +27,9 @@ config PREVENT_FIRMWARE_BUILD
27 If unsure say Y here. 27 If unsure say Y here.
28 28
29config FW_LOADER 29config FW_LOADER
30 tristate "Userspace firmware loading support" 30 tristate "Userspace firmware loading support" if EMBEDDED
31 depends on HOTPLUG 31 depends on HOTPLUG
32 default y
32 ---help--- 33 ---help---
33 This option is provided for the case where no in-kernel-tree modules 34 This option is provided for the case where no in-kernel-tree modules
34 require userspace firmware loading support, but a module built outside 35 require userspace firmware loading support, but a module built outside
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 2c9ae43e2219..31dc0cd84afa 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -36,6 +36,33 @@ struct driver_private {
36}; 36};
37#define to_driver(obj) container_of(obj, struct driver_private, kobj) 37#define to_driver(obj) container_of(obj, struct driver_private, kobj)
38 38
39
40/**
41 * struct class_private - structure to hold the private to the driver core portions of the class structure.
42 *
43 * @class_subsys - the struct kset that defines this class. This is the main kobject
44 * @class_devices - list of devices associated with this class
45 * @class_interfaces - list of class_interfaces associated with this class
46 * @class_dirs - "glue" directory for virtual devices associated with this class
47 * @class_mutex - mutex to protect the children, devices, and interfaces lists.
48 * @class - pointer back to the struct class that this structure is associated
49 * with.
50 *
51 * This structure is the one that is the actual kobject allowing struct
52 * class to be statically allocated safely. Nothing outside of the driver
53 * core should ever touch these fields.
54 */
55struct class_private {
56 struct kset class_subsys;
57 struct list_head class_devices;
58 struct list_head class_interfaces;
59 struct kset class_dirs;
60 struct mutex class_mutex;
61 struct class *class;
62};
63#define to_class(obj) \
64 container_of(obj, struct class_private, class_subsys.kobj)
65
39/* initialisation functions */ 66/* initialisation functions */
40extern int devices_init(void); 67extern int devices_init(void);
41extern int buses_init(void); 68extern int buses_init(void);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index e085af0ff94f..839d27cecb36 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -18,20 +18,20 @@
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/genhd.h> 20#include <linux/genhd.h>
21#include <linux/mutex.h>
21#include "base.h" 22#include "base.h"
22 23
23#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) 24#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
24#define to_class(obj) container_of(obj, struct class, subsys.kobj)
25 25
26static ssize_t class_attr_show(struct kobject *kobj, struct attribute *attr, 26static ssize_t class_attr_show(struct kobject *kobj, struct attribute *attr,
27 char *buf) 27 char *buf)
28{ 28{
29 struct class_attribute *class_attr = to_class_attr(attr); 29 struct class_attribute *class_attr = to_class_attr(attr);
30 struct class *dc = to_class(kobj); 30 struct class_private *cp = to_class(kobj);
31 ssize_t ret = -EIO; 31 ssize_t ret = -EIO;
32 32
33 if (class_attr->show) 33 if (class_attr->show)
34 ret = class_attr->show(dc, buf); 34 ret = class_attr->show(cp->class, buf);
35 return ret; 35 return ret;
36} 36}
37 37
@@ -39,17 +39,18 @@ static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr,
39 const char *buf, size_t count) 39 const char *buf, size_t count)
40{ 40{
41 struct class_attribute *class_attr = to_class_attr(attr); 41 struct class_attribute *class_attr = to_class_attr(attr);
42 struct class *dc = to_class(kobj); 42 struct class_private *cp = to_class(kobj);
43 ssize_t ret = -EIO; 43 ssize_t ret = -EIO;
44 44
45 if (class_attr->store) 45 if (class_attr->store)
46 ret = class_attr->store(dc, buf, count); 46 ret = class_attr->store(cp->class, buf, count);
47 return ret; 47 return ret;
48} 48}
49 49
50static void class_release(struct kobject *kobj) 50static void class_release(struct kobject *kobj)
51{ 51{
52 struct class *class = to_class(kobj); 52 struct class_private *cp = to_class(kobj);
53 struct class *class = cp->class;
53 54
54 pr_debug("class '%s': release.\n", class->name); 55 pr_debug("class '%s': release.\n", class->name);
55 56
@@ -70,7 +71,7 @@ static struct kobj_type class_ktype = {
70 .release = class_release, 71 .release = class_release,
71}; 72};
72 73
73/* Hotplug events for classes go to the class_obj subsys */ 74/* Hotplug events for classes go to the class class_subsys */
74static struct kset *class_kset; 75static struct kset *class_kset;
75 76
76 77
@@ -78,7 +79,8 @@ int class_create_file(struct class *cls, const struct class_attribute *attr)
78{ 79{
79 int error; 80 int error;
80 if (cls) 81 if (cls)
81 error = sysfs_create_file(&cls->subsys.kobj, &attr->attr); 82 error = sysfs_create_file(&cls->p->class_subsys.kobj,
83 &attr->attr);
82 else 84 else
83 error = -EINVAL; 85 error = -EINVAL;
84 return error; 86 return error;
@@ -87,21 +89,20 @@ int class_create_file(struct class *cls, const struct class_attribute *attr)
87void class_remove_file(struct class *cls, const struct class_attribute *attr) 89void class_remove_file(struct class *cls, const struct class_attribute *attr)
88{ 90{
89 if (cls) 91 if (cls)
90 sysfs_remove_file(&cls->subsys.kobj, &attr->attr); 92 sysfs_remove_file(&cls->p->class_subsys.kobj, &attr->attr);
91} 93}
92 94
93static struct class *class_get(struct class *cls) 95static struct class *class_get(struct class *cls)
94{ 96{
95 if (cls) 97 if (cls)
96 return container_of(kset_get(&cls->subsys), 98 kset_get(&cls->p->class_subsys);
97 struct class, subsys); 99 return cls;
98 return NULL;
99} 100}
100 101
101static void class_put(struct class *cls) 102static void class_put(struct class *cls)
102{ 103{
103 if (cls) 104 if (cls)
104 kset_put(&cls->subsys); 105 kset_put(&cls->p->class_subsys);
105} 106}
106 107
107static int add_class_attrs(struct class *cls) 108static int add_class_attrs(struct class *cls)
@@ -134,42 +135,57 @@ static void remove_class_attrs(struct class *cls)
134 } 135 }
135} 136}
136 137
137int class_register(struct class *cls) 138int __class_register(struct class *cls, struct lock_class_key *key)
138{ 139{
140 struct class_private *cp;
139 int error; 141 int error;
140 142
141 pr_debug("device class '%s': registering\n", cls->name); 143 pr_debug("device class '%s': registering\n", cls->name);
142 144
143 INIT_LIST_HEAD(&cls->devices); 145 cp = kzalloc(sizeof(*cp), GFP_KERNEL);
144 INIT_LIST_HEAD(&cls->interfaces); 146 if (!cp)
145 kset_init(&cls->class_dirs); 147 return -ENOMEM;
146 init_MUTEX(&cls->sem); 148 INIT_LIST_HEAD(&cp->class_devices);
147 error = kobject_set_name(&cls->subsys.kobj, "%s", cls->name); 149 INIT_LIST_HEAD(&cp->class_interfaces);
148 if (error) 150 kset_init(&cp->class_dirs);
151 __mutex_init(&cp->class_mutex, "struct class mutex", key);
152 error = kobject_set_name(&cp->class_subsys.kobj, "%s", cls->name);
153 if (error) {
154 kfree(cp);
149 return error; 155 return error;
156 }
157
158 /* set the default /sys/dev directory for devices of this class */
159 if (!cls->dev_kobj)
160 cls->dev_kobj = sysfs_dev_char_kobj;
150 161
151#if defined(CONFIG_SYSFS_DEPRECATED) && defined(CONFIG_BLOCK) 162#if defined(CONFIG_SYSFS_DEPRECATED) && defined(CONFIG_BLOCK)
152 /* let the block class directory show up in the root of sysfs */ 163 /* let the block class directory show up in the root of sysfs */
153 if (cls != &block_class) 164 if (cls != &block_class)
154 cls->subsys.kobj.kset = class_kset; 165 cp->class_subsys.kobj.kset = class_kset;
155#else 166#else
156 cls->subsys.kobj.kset = class_kset; 167 cp->class_subsys.kobj.kset = class_kset;
157#endif 168#endif
158 cls->subsys.kobj.ktype = &class_ktype; 169 cp->class_subsys.kobj.ktype = &class_ktype;
170 cp->class = cls;
171 cls->p = cp;
159 172
160 error = kset_register(&cls->subsys); 173 error = kset_register(&cp->class_subsys);
161 if (!error) { 174 if (error) {
162 error = add_class_attrs(class_get(cls)); 175 kfree(cp);
163 class_put(cls); 176 return error;
164 } 177 }
178 error = add_class_attrs(class_get(cls));
179 class_put(cls);
165 return error; 180 return error;
166} 181}
182EXPORT_SYMBOL_GPL(__class_register);
167 183
168void class_unregister(struct class *cls) 184void class_unregister(struct class *cls)
169{ 185{
170 pr_debug("device class '%s': unregistering\n", cls->name); 186 pr_debug("device class '%s': unregistering\n", cls->name);
171 remove_class_attrs(cls); 187 remove_class_attrs(cls);
172 kset_unregister(&cls->subsys); 188 kset_unregister(&cls->p->class_subsys);
173} 189}
174 190
175static void class_create_release(struct class *cls) 191static void class_create_release(struct class *cls)
@@ -189,7 +205,8 @@ static void class_create_release(struct class *cls)
189 * Note, the pointer created here is to be destroyed when finished by 205 * Note, the pointer created here is to be destroyed when finished by
190 * making a call to class_destroy(). 206 * making a call to class_destroy().
191 */ 207 */
192struct class *class_create(struct module *owner, const char *name) 208struct class *__class_create(struct module *owner, const char *name,
209 struct lock_class_key *key)
193{ 210{
194 struct class *cls; 211 struct class *cls;
195 int retval; 212 int retval;
@@ -204,7 +221,7 @@ struct class *class_create(struct module *owner, const char *name)
204 cls->owner = owner; 221 cls->owner = owner;
205 cls->class_release = class_create_release; 222 cls->class_release = class_create_release;
206 223
207 retval = class_register(cls); 224 retval = __class_register(cls, key);
208 if (retval) 225 if (retval)
209 goto error; 226 goto error;
210 227
@@ -214,6 +231,7 @@ error:
214 kfree(cls); 231 kfree(cls);
215 return ERR_PTR(retval); 232 return ERR_PTR(retval);
216} 233}
234EXPORT_SYMBOL_GPL(__class_create);
217 235
218/** 236/**
219 * class_destroy - destroys a struct class structure 237 * class_destroy - destroys a struct class structure
@@ -252,39 +270,44 @@ char *make_class_name(const char *name, struct kobject *kobj)
252/** 270/**
253 * class_for_each_device - device iterator 271 * class_for_each_device - device iterator
254 * @class: the class we're iterating 272 * @class: the class we're iterating
273 * @start: the device to start with in the list, if any.
255 * @data: data for the callback 274 * @data: data for the callback
256 * @fn: function to be called for each device 275 * @fn: function to be called for each device
257 * 276 *
258 * Iterate over @class's list of devices, and call @fn for each, 277 * Iterate over @class's list of devices, and call @fn for each,
259 * passing it @data. 278 * passing it @data. If @start is set, the list iteration will start
279 * there, otherwise if it is NULL, the iteration starts at the
280 * beginning of the list.
260 * 281 *
261 * We check the return of @fn each time. If it returns anything 282 * We check the return of @fn each time. If it returns anything
262 * other than 0, we break out and return that value. 283 * other than 0, we break out and return that value.
263 * 284 *
264 * Note, we hold class->sem in this function, so it can not be 285 * Note, we hold class->class_mutex in this function, so it can not be
265 * re-acquired in @fn, otherwise it will self-deadlocking. For 286 * re-acquired in @fn, otherwise it will self-deadlocking. For
266 * example, calls to add or remove class members would be verboten. 287 * example, calls to add or remove class members would be verboten.
267 */ 288 */
268int class_for_each_device(struct class *class, void *data, 289int class_for_each_device(struct class *class, struct device *start,
269 int (*fn)(struct device *, void *)) 290 void *data, int (*fn)(struct device *, void *))
270{ 291{
271 struct device *dev; 292 struct device *dev;
272 int error = 0; 293 int error = 0;
273 294
274 if (!class) 295 if (!class)
275 return -EINVAL; 296 return -EINVAL;
276 down(&class->sem); 297 mutex_lock(&class->p->class_mutex);
277 list_for_each_entry(dev, &class->devices, node) { 298 list_for_each_entry(dev, &class->p->class_devices, node) {
299 if (start) {
300 if (start == dev)
301 start = NULL;
302 continue;
303 }
278 dev = get_device(dev); 304 dev = get_device(dev);
279 if (dev) { 305 error = fn(dev, data);
280 error = fn(dev, data); 306 put_device(dev);
281 put_device(dev);
282 } else
283 error = -ENODEV;
284 if (error) 307 if (error)
285 break; 308 break;
286 } 309 }
287 up(&class->sem); 310 mutex_unlock(&class->p->class_mutex);
288 311
289 return error; 312 return error;
290} 313}
@@ -293,6 +316,7 @@ EXPORT_SYMBOL_GPL(class_for_each_device);
293/** 316/**
294 * class_find_device - device iterator for locating a particular device 317 * class_find_device - device iterator for locating a particular device
295 * @class: the class we're iterating 318 * @class: the class we're iterating
319 * @start: Device to begin with
296 * @data: data for the match function 320 * @data: data for the match function
297 * @match: function to check device 321 * @match: function to check device
298 * 322 *
@@ -306,12 +330,13 @@ EXPORT_SYMBOL_GPL(class_for_each_device);
306 * 330 *
307 * Note, you will need to drop the reference with put_device() after use. 331 * Note, you will need to drop the reference with put_device() after use.
308 * 332 *
309 * We hold class->sem in this function, so it can not be 333 * We hold class->class_mutex in this function, so it can not be
310 * re-acquired in @match, otherwise it will self-deadlocking. For 334 * re-acquired in @match, otherwise it will self-deadlocking. For
311 * example, calls to add or remove class members would be verboten. 335 * example, calls to add or remove class members would be verboten.
312 */ 336 */
313struct device *class_find_device(struct class *class, void *data, 337struct device *class_find_device(struct class *class, struct device *start,
314 int (*match)(struct device *, void *)) 338 void *data,
339 int (*match)(struct device *, void *))
315{ 340{
316 struct device *dev; 341 struct device *dev;
317 int found = 0; 342 int found = 0;
@@ -319,19 +344,21 @@ struct device *class_find_device(struct class *class, void *data,
319 if (!class) 344 if (!class)
320 return NULL; 345 return NULL;
321 346
322 down(&class->sem); 347 mutex_lock(&class->p->class_mutex);
323 list_for_each_entry(dev, &class->devices, node) { 348 list_for_each_entry(dev, &class->p->class_devices, node) {
349 if (start) {
350 if (start == dev)
351 start = NULL;
352 continue;
353 }
324 dev = get_device(dev); 354 dev = get_device(dev);
325 if (dev) { 355 if (match(dev, data)) {
326 if (match(dev, data)) { 356 found = 1;
327 found = 1;
328 break;
329 } else
330 put_device(dev);
331 } else
332 break; 357 break;
358 } else
359 put_device(dev);
333 } 360 }
334 up(&class->sem); 361 mutex_unlock(&class->p->class_mutex);
335 362
336 return found ? dev : NULL; 363 return found ? dev : NULL;
337} 364}
@@ -349,13 +376,13 @@ int class_interface_register(struct class_interface *class_intf)
349 if (!parent) 376 if (!parent)
350 return -EINVAL; 377 return -EINVAL;
351 378
352 down(&parent->sem); 379 mutex_lock(&parent->p->class_mutex);
353 list_add_tail(&class_intf->node, &parent->interfaces); 380 list_add_tail(&class_intf->node, &parent->p->class_interfaces);
354 if (class_intf->add_dev) { 381 if (class_intf->add_dev) {
355 list_for_each_entry(dev, &parent->devices, node) 382 list_for_each_entry(dev, &parent->p->class_devices, node)
356 class_intf->add_dev(dev, class_intf); 383 class_intf->add_dev(dev, class_intf);
357 } 384 }
358 up(&parent->sem); 385 mutex_unlock(&parent->p->class_mutex);
359 386
360 return 0; 387 return 0;
361} 388}
@@ -368,13 +395,13 @@ void class_interface_unregister(struct class_interface *class_intf)
368 if (!parent) 395 if (!parent)
369 return; 396 return;
370 397
371 down(&parent->sem); 398 mutex_lock(&parent->p->class_mutex);
372 list_del_init(&class_intf->node); 399 list_del_init(&class_intf->node);
373 if (class_intf->remove_dev) { 400 if (class_intf->remove_dev) {
374 list_for_each_entry(dev, &parent->devices, node) 401 list_for_each_entry(dev, &parent->p->class_devices, node)
375 class_intf->remove_dev(dev, class_intf); 402 class_intf->remove_dev(dev, class_intf);
376 } 403 }
377 up(&parent->sem); 404 mutex_unlock(&parent->p->class_mutex);
378 405
379 class_put(parent); 406 class_put(parent);
380} 407}
@@ -389,9 +416,7 @@ int __init classes_init(void)
389 416
390EXPORT_SYMBOL_GPL(class_create_file); 417EXPORT_SYMBOL_GPL(class_create_file);
391EXPORT_SYMBOL_GPL(class_remove_file); 418EXPORT_SYMBOL_GPL(class_remove_file);
392EXPORT_SYMBOL_GPL(class_register);
393EXPORT_SYMBOL_GPL(class_unregister); 419EXPORT_SYMBOL_GPL(class_unregister);
394EXPORT_SYMBOL_GPL(class_create);
395EXPORT_SYMBOL_GPL(class_destroy); 420EXPORT_SYMBOL_GPL(class_destroy);
396 421
397EXPORT_SYMBOL_GPL(class_interface_register); 422EXPORT_SYMBOL_GPL(class_interface_register);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index ee0a51a3a41d..7d5c63c81a59 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -21,12 +21,16 @@
21#include <linux/genhd.h> 21#include <linux/genhd.h>
22#include <linux/kallsyms.h> 22#include <linux/kallsyms.h>
23#include <linux/semaphore.h> 23#include <linux/semaphore.h>
24#include <linux/mutex.h>
24 25
25#include "base.h" 26#include "base.h"
26#include "power/power.h" 27#include "power/power.h"
27 28
28int (*platform_notify)(struct device *dev) = NULL; 29int (*platform_notify)(struct device *dev) = NULL;
29int (*platform_notify_remove)(struct device *dev) = NULL; 30int (*platform_notify_remove)(struct device *dev) = NULL;
31static struct kobject *dev_kobj;
32struct kobject *sysfs_dev_char_kobj;
33struct kobject *sysfs_dev_block_kobj;
30 34
31#ifdef CONFIG_BLOCK 35#ifdef CONFIG_BLOCK
32static inline int device_is_not_partition(struct device *dev) 36static inline int device_is_not_partition(struct device *dev)
@@ -548,7 +552,7 @@ static struct kobject *get_device_parent(struct device *dev,
548{ 552{
549 /* class devices without a parent live in /sys/class/<classname>/ */ 553 /* class devices without a parent live in /sys/class/<classname>/ */
550 if (dev->class && (!parent || parent->class != dev->class)) 554 if (dev->class && (!parent || parent->class != dev->class))
551 return &dev->class->subsys.kobj; 555 return &dev->class->p->class_subsys.kobj;
552 /* all other devices keep their parent */ 556 /* all other devices keep their parent */
553 else if (parent) 557 else if (parent)
554 return &parent->kobj; 558 return &parent->kobj;
@@ -594,13 +598,13 @@ static struct kobject *get_device_parent(struct device *dev,
594 parent_kobj = &parent->kobj; 598 parent_kobj = &parent->kobj;
595 599
596 /* find our class-directory at the parent and reference it */ 600 /* find our class-directory at the parent and reference it */
597 spin_lock(&dev->class->class_dirs.list_lock); 601 spin_lock(&dev->class->p->class_dirs.list_lock);
598 list_for_each_entry(k, &dev->class->class_dirs.list, entry) 602 list_for_each_entry(k, &dev->class->p->class_dirs.list, entry)
599 if (k->parent == parent_kobj) { 603 if (k->parent == parent_kobj) {
600 kobj = kobject_get(k); 604 kobj = kobject_get(k);
601 break; 605 break;
602 } 606 }
603 spin_unlock(&dev->class->class_dirs.list_lock); 607 spin_unlock(&dev->class->p->class_dirs.list_lock);
604 if (kobj) 608 if (kobj)
605 return kobj; 609 return kobj;
606 610
@@ -608,7 +612,7 @@ static struct kobject *get_device_parent(struct device *dev,
608 k = kobject_create(); 612 k = kobject_create();
609 if (!k) 613 if (!k)
610 return NULL; 614 return NULL;
611 k->kset = &dev->class->class_dirs; 615 k->kset = &dev->class->p->class_dirs;
612 retval = kobject_add(k, parent_kobj, "%s", dev->class->name); 616 retval = kobject_add(k, parent_kobj, "%s", dev->class->name);
613 if (retval < 0) { 617 if (retval < 0) {
614 kobject_put(k); 618 kobject_put(k);
@@ -627,7 +631,7 @@ static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
627{ 631{
628 /* see if we live in a "glue" directory */ 632 /* see if we live in a "glue" directory */
629 if (!glue_dir || !dev->class || 633 if (!glue_dir || !dev->class ||
630 glue_dir->kset != &dev->class->class_dirs) 634 glue_dir->kset != &dev->class->p->class_dirs)
631 return; 635 return;
632 636
633 kobject_put(glue_dir); 637 kobject_put(glue_dir);
@@ -654,17 +658,18 @@ static int device_add_class_symlinks(struct device *dev)
654 if (!dev->class) 658 if (!dev->class)
655 return 0; 659 return 0;
656 660
657 error = sysfs_create_link(&dev->kobj, &dev->class->subsys.kobj, 661 error = sysfs_create_link(&dev->kobj,
662 &dev->class->p->class_subsys.kobj,
658 "subsystem"); 663 "subsystem");
659 if (error) 664 if (error)
660 goto out; 665 goto out;
661 666
662#ifdef CONFIG_SYSFS_DEPRECATED 667#ifdef CONFIG_SYSFS_DEPRECATED
663 /* stacked class devices need a symlink in the class directory */ 668 /* stacked class devices need a symlink in the class directory */
664 if (dev->kobj.parent != &dev->class->subsys.kobj && 669 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
665 device_is_not_partition(dev)) { 670 device_is_not_partition(dev)) {
666 error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj, 671 error = sysfs_create_link(&dev->class->p->class_subsys.kobj,
667 dev->bus_id); 672 &dev->kobj, dev->bus_id);
668 if (error) 673 if (error)
669 goto out_subsys; 674 goto out_subsys;
670 } 675 }
@@ -701,13 +706,14 @@ out_device:
701 if (dev->parent && device_is_not_partition(dev)) 706 if (dev->parent && device_is_not_partition(dev))
702 sysfs_remove_link(&dev->kobj, "device"); 707 sysfs_remove_link(&dev->kobj, "device");
703out_busid: 708out_busid:
704 if (dev->kobj.parent != &dev->class->subsys.kobj && 709 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
705 device_is_not_partition(dev)) 710 device_is_not_partition(dev))
706 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); 711 sysfs_remove_link(&dev->class->p->class_subsys.kobj,
712 dev->bus_id);
707#else 713#else
708 /* link in the class directory pointing to the device */ 714 /* link in the class directory pointing to the device */
709 error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj, 715 error = sysfs_create_link(&dev->class->p->class_subsys.kobj,
710 dev->bus_id); 716 &dev->kobj, dev->bus_id);
711 if (error) 717 if (error)
712 goto out_subsys; 718 goto out_subsys;
713 719
@@ -720,7 +726,7 @@ out_busid:
720 return 0; 726 return 0;
721 727
722out_busid: 728out_busid:
723 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); 729 sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev->bus_id);
724#endif 730#endif
725 731
726out_subsys: 732out_subsys:
@@ -746,14 +752,15 @@ static void device_remove_class_symlinks(struct device *dev)
746 sysfs_remove_link(&dev->kobj, "device"); 752 sysfs_remove_link(&dev->kobj, "device");
747 } 753 }
748 754
749 if (dev->kobj.parent != &dev->class->subsys.kobj && 755 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
750 device_is_not_partition(dev)) 756 device_is_not_partition(dev))
751 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); 757 sysfs_remove_link(&dev->class->p->class_subsys.kobj,
758 dev->bus_id);
752#else 759#else
753 if (dev->parent && device_is_not_partition(dev)) 760 if (dev->parent && device_is_not_partition(dev))
754 sysfs_remove_link(&dev->kobj, "device"); 761 sysfs_remove_link(&dev->kobj, "device");
755 762
756 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); 763 sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev->bus_id);
757#endif 764#endif
758 765
759 sysfs_remove_link(&dev->kobj, "subsystem"); 766 sysfs_remove_link(&dev->kobj, "subsystem");
@@ -776,6 +783,54 @@ int dev_set_name(struct device *dev, const char *fmt, ...)
776EXPORT_SYMBOL_GPL(dev_set_name); 783EXPORT_SYMBOL_GPL(dev_set_name);
777 784
778/** 785/**
786 * device_to_dev_kobj - select a /sys/dev/ directory for the device
787 * @dev: device
788 *
789 * By default we select char/ for new entries. Setting class->dev_obj
790 * to NULL prevents an entry from being created. class->dev_kobj must
791 * be set (or cleared) before any devices are registered to the class
792 * otherwise device_create_sys_dev_entry() and
793 * device_remove_sys_dev_entry() will disagree about the the presence
794 * of the link.
795 */
796static struct kobject *device_to_dev_kobj(struct device *dev)
797{
798 struct kobject *kobj;
799
800 if (dev->class)
801 kobj = dev->class->dev_kobj;
802 else
803 kobj = sysfs_dev_char_kobj;
804
805 return kobj;
806}
807
808static int device_create_sys_dev_entry(struct device *dev)
809{
810 struct kobject *kobj = device_to_dev_kobj(dev);
811 int error = 0;
812 char devt_str[15];
813
814 if (kobj) {
815 format_dev_t(devt_str, dev->devt);
816 error = sysfs_create_link(kobj, &dev->kobj, devt_str);
817 }
818
819 return error;
820}
821
822static void device_remove_sys_dev_entry(struct device *dev)
823{
824 struct kobject *kobj = device_to_dev_kobj(dev);
825 char devt_str[15];
826
827 if (kobj) {
828 format_dev_t(devt_str, dev->devt);
829 sysfs_remove_link(kobj, devt_str);
830 }
831}
832
833/**
779 * device_add - add device to device hierarchy. 834 * device_add - add device to device hierarchy.
780 * @dev: device. 835 * @dev: device.
781 * 836 *
@@ -829,6 +884,10 @@ int device_add(struct device *dev)
829 error = device_create_file(dev, &devt_attr); 884 error = device_create_file(dev, &devt_attr);
830 if (error) 885 if (error)
831 goto ueventattrError; 886 goto ueventattrError;
887
888 error = device_create_sys_dev_entry(dev);
889 if (error)
890 goto devtattrError;
832 } 891 }
833 892
834 error = device_add_class_symlinks(dev); 893 error = device_add_class_symlinks(dev);
@@ -849,15 +908,16 @@ int device_add(struct device *dev)
849 klist_add_tail(&dev->knode_parent, &parent->klist_children); 908 klist_add_tail(&dev->knode_parent, &parent->klist_children);
850 909
851 if (dev->class) { 910 if (dev->class) {
852 down(&dev->class->sem); 911 mutex_lock(&dev->class->p->class_mutex);
853 /* tie the class to the device */ 912 /* tie the class to the device */
854 list_add_tail(&dev->node, &dev->class->devices); 913 list_add_tail(&dev->node, &dev->class->p->class_devices);
855 914
856 /* notify any interfaces that the device is here */ 915 /* notify any interfaces that the device is here */
857 list_for_each_entry(class_intf, &dev->class->interfaces, node) 916 list_for_each_entry(class_intf,
917 &dev->class->p->class_interfaces, node)
858 if (class_intf->add_dev) 918 if (class_intf->add_dev)
859 class_intf->add_dev(dev, class_intf); 919 class_intf->add_dev(dev, class_intf);
860 up(&dev->class->sem); 920 mutex_unlock(&dev->class->p->class_mutex);
861 } 921 }
862 Done: 922 Done:
863 put_device(dev); 923 put_device(dev);
@@ -873,6 +933,9 @@ int device_add(struct device *dev)
873 device_remove_class_symlinks(dev); 933 device_remove_class_symlinks(dev);
874 SymlinkError: 934 SymlinkError:
875 if (MAJOR(dev->devt)) 935 if (MAJOR(dev->devt))
936 device_remove_sys_dev_entry(dev);
937 devtattrError:
938 if (MAJOR(dev->devt))
876 device_remove_file(dev, &devt_attr); 939 device_remove_file(dev, &devt_attr);
877 ueventattrError: 940 ueventattrError:
878 device_remove_file(dev, &uevent_attr); 941 device_remove_file(dev, &uevent_attr);
@@ -948,19 +1011,22 @@ void device_del(struct device *dev)
948 device_pm_remove(dev); 1011 device_pm_remove(dev);
949 if (parent) 1012 if (parent)
950 klist_del(&dev->knode_parent); 1013 klist_del(&dev->knode_parent);
951 if (MAJOR(dev->devt)) 1014 if (MAJOR(dev->devt)) {
1015 device_remove_sys_dev_entry(dev);
952 device_remove_file(dev, &devt_attr); 1016 device_remove_file(dev, &devt_attr);
1017 }
953 if (dev->class) { 1018 if (dev->class) {
954 device_remove_class_symlinks(dev); 1019 device_remove_class_symlinks(dev);
955 1020
956 down(&dev->class->sem); 1021 mutex_lock(&dev->class->p->class_mutex);
957 /* notify any interfaces that the device is now gone */ 1022 /* notify any interfaces that the device is now gone */
958 list_for_each_entry(class_intf, &dev->class->interfaces, node) 1023 list_for_each_entry(class_intf,
1024 &dev->class->p->class_interfaces, node)
959 if (class_intf->remove_dev) 1025 if (class_intf->remove_dev)
960 class_intf->remove_dev(dev, class_intf); 1026 class_intf->remove_dev(dev, class_intf);
961 /* remove the device from the class list */ 1027 /* remove the device from the class list */
962 list_del_init(&dev->node); 1028 list_del_init(&dev->node);
963 up(&dev->class->sem); 1029 mutex_unlock(&dev->class->p->class_mutex);
964 } 1030 }
965 device_remove_file(dev, &uevent_attr); 1031 device_remove_file(dev, &uevent_attr);
966 device_remove_attrs(dev); 1032 device_remove_attrs(dev);
@@ -1074,7 +1140,25 @@ int __init devices_init(void)
1074 devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL); 1140 devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL);
1075 if (!devices_kset) 1141 if (!devices_kset)
1076 return -ENOMEM; 1142 return -ENOMEM;
1143 dev_kobj = kobject_create_and_add("dev", NULL);
1144 if (!dev_kobj)
1145 goto dev_kobj_err;
1146 sysfs_dev_block_kobj = kobject_create_and_add("block", dev_kobj);
1147 if (!sysfs_dev_block_kobj)
1148 goto block_kobj_err;
1149 sysfs_dev_char_kobj = kobject_create_and_add("char", dev_kobj);
1150 if (!sysfs_dev_char_kobj)
1151 goto char_kobj_err;
1152
1077 return 0; 1153 return 0;
1154
1155 char_kobj_err:
1156 kobject_put(sysfs_dev_block_kobj);
1157 block_kobj_err:
1158 kobject_put(dev_kobj);
1159 dev_kobj_err:
1160 kset_unregister(devices_kset);
1161 return -ENOMEM;
1078} 1162}
1079 1163
1080EXPORT_SYMBOL_GPL(device_for_each_child); 1164EXPORT_SYMBOL_GPL(device_for_each_child);
@@ -1158,48 +1242,11 @@ error:
1158EXPORT_SYMBOL_GPL(device_create_vargs); 1242EXPORT_SYMBOL_GPL(device_create_vargs);
1159 1243
1160/** 1244/**
1161 * device_create_drvdata - creates a device and registers it with sysfs
1162 * @class: pointer to the struct class that this device should be registered to
1163 * @parent: pointer to the parent struct device of this new device, if any
1164 * @devt: the dev_t for the char device to be added
1165 * @drvdata: the data to be added to the device for callbacks
1166 * @fmt: string for the device's name
1167 *
1168 * This function can be used by char device classes. A struct device
1169 * will be created in sysfs, registered to the specified class.
1170 *
1171 * A "dev" file will be created, showing the dev_t for the device, if
1172 * the dev_t is not 0,0.
1173 * If a pointer to a parent struct device is passed in, the newly created
1174 * struct device will be a child of that device in sysfs.
1175 * The pointer to the struct device will be returned from the call.
1176 * Any further sysfs files that might be required can be created using this
1177 * pointer.
1178 *
1179 * Note: the struct class passed to this function must have previously
1180 * been created with a call to class_create().
1181 */
1182struct device *device_create_drvdata(struct class *class,
1183 struct device *parent,
1184 dev_t devt,
1185 void *drvdata,
1186 const char *fmt, ...)
1187{
1188 va_list vargs;
1189 struct device *dev;
1190
1191 va_start(vargs, fmt);
1192 dev = device_create_vargs(class, parent, devt, drvdata, fmt, vargs);
1193 va_end(vargs);
1194 return dev;
1195}
1196EXPORT_SYMBOL_GPL(device_create_drvdata);
1197
1198/**
1199 * device_create - creates a device and registers it with sysfs 1245 * device_create - creates a device and registers it with sysfs
1200 * @class: pointer to the struct class that this device should be registered to 1246 * @class: pointer to the struct class that this device should be registered to
1201 * @parent: pointer to the parent struct device of this new device, if any 1247 * @parent: pointer to the parent struct device of this new device, if any
1202 * @devt: the dev_t for the char device to be added 1248 * @devt: the dev_t for the char device to be added
1249 * @drvdata: the data to be added to the device for callbacks
1203 * @fmt: string for the device's name 1250 * @fmt: string for the device's name
1204 * 1251 *
1205 * This function can be used by char device classes. A struct device 1252 * This function can be used by char device classes. A struct device
@@ -1217,13 +1264,13 @@ EXPORT_SYMBOL_GPL(device_create_drvdata);
1217 * been created with a call to class_create(). 1264 * been created with a call to class_create().
1218 */ 1265 */
1219struct device *device_create(struct class *class, struct device *parent, 1266struct device *device_create(struct class *class, struct device *parent,
1220 dev_t devt, const char *fmt, ...) 1267 dev_t devt, void *drvdata, const char *fmt, ...)
1221{ 1268{
1222 va_list vargs; 1269 va_list vargs;
1223 struct device *dev; 1270 struct device *dev;
1224 1271
1225 va_start(vargs, fmt); 1272 va_start(vargs, fmt);
1226 dev = device_create_vargs(class, parent, devt, NULL, fmt, vargs); 1273 dev = device_create_vargs(class, parent, devt, drvdata, fmt, vargs);
1227 va_end(vargs); 1274 va_end(vargs);
1228 return dev; 1275 return dev;
1229} 1276}
@@ -1248,7 +1295,7 @@ void device_destroy(struct class *class, dev_t devt)
1248{ 1295{
1249 struct device *dev; 1296 struct device *dev;
1250 1297
1251 dev = class_find_device(class, &devt, __match_devt); 1298 dev = class_find_device(class, NULL, &devt, __match_devt);
1252 if (dev) { 1299 if (dev) {
1253 put_device(dev); 1300 put_device(dev);
1254 device_unregister(dev); 1301 device_unregister(dev);
@@ -1298,8 +1345,9 @@ int device_rename(struct device *dev, char *new_name)
1298 if (old_class_name) { 1345 if (old_class_name) {
1299 new_class_name = make_class_name(dev->class->name, &dev->kobj); 1346 new_class_name = make_class_name(dev->class->name, &dev->kobj);
1300 if (new_class_name) { 1347 if (new_class_name) {
1301 error = sysfs_create_link(&dev->parent->kobj, 1348 error = sysfs_create_link_nowarn(&dev->parent->kobj,
1302 &dev->kobj, new_class_name); 1349 &dev->kobj,
1350 new_class_name);
1303 if (error) 1351 if (error)
1304 goto out; 1352 goto out;
1305 sysfs_remove_link(&dev->parent->kobj, old_class_name); 1353 sysfs_remove_link(&dev->parent->kobj, old_class_name);
@@ -1307,11 +1355,12 @@ int device_rename(struct device *dev, char *new_name)
1307 } 1355 }
1308#else 1356#else
1309 if (dev->class) { 1357 if (dev->class) {
1310 error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj, 1358 error = sysfs_create_link_nowarn(&dev->class->p->class_subsys.kobj,
1311 dev->bus_id); 1359 &dev->kobj, dev->bus_id);
1312 if (error) 1360 if (error)
1313 goto out; 1361 goto out;
1314 sysfs_remove_link(&dev->class->subsys.kobj, old_device_name); 1362 sysfs_remove_link(&dev->class->p->class_subsys.kobj,
1363 old_device_name);
1315 } 1364 }
1316#endif 1365#endif
1317 1366
@@ -1447,4 +1496,7 @@ void device_shutdown(void)
1447 dev->driver->shutdown(dev); 1496 dev->driver->shutdown(dev);
1448 } 1497 }
1449 } 1498 }
1499 kobject_put(sysfs_dev_char_kobj);
1500 kobject_put(sysfs_dev_block_kobj);
1501 kobject_put(dev_kobj);
1450} 1502}
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index e38dfed41d80..20537d507909 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -21,15 +21,16 @@ EXPORT_SYMBOL(cpu_sysdev_class);
21static DEFINE_PER_CPU(struct sys_device *, cpu_sys_devices); 21static DEFINE_PER_CPU(struct sys_device *, cpu_sys_devices);
22 22
23#ifdef CONFIG_HOTPLUG_CPU 23#ifdef CONFIG_HOTPLUG_CPU
24static ssize_t show_online(struct sys_device *dev, char *buf) 24static ssize_t show_online(struct sys_device *dev, struct sysdev_attribute *attr,
25 char *buf)
25{ 26{
26 struct cpu *cpu = container_of(dev, struct cpu, sysdev); 27 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
27 28
28 return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id)); 29 return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id));
29} 30}
30 31
31static ssize_t __ref store_online(struct sys_device *dev, const char *buf, 32static ssize_t __ref store_online(struct sys_device *dev, struct sysdev_attribute *attr,
32 size_t count) 33 const char *buf, size_t count)
33{ 34{
34 struct cpu *cpu = container_of(dev, struct cpu, sysdev); 35 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
35 ssize_t ret; 36 ssize_t ret;
@@ -80,7 +81,8 @@ static inline void register_cpu_control(struct cpu *cpu)
80#ifdef CONFIG_KEXEC 81#ifdef CONFIG_KEXEC
81#include <linux/kexec.h> 82#include <linux/kexec.h>
82 83
83static ssize_t show_crash_notes(struct sys_device *dev, char *buf) 84static ssize_t show_crash_notes(struct sys_device *dev, struct sysdev_attribute *attr,
85 char *buf)
84{ 86{
85 struct cpu *cpu = container_of(dev, struct cpu, sysdev); 87 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
86 ssize_t rc; 88 ssize_t rc;
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 937e8258981d..4d4e0e7b6e92 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -92,7 +92,8 @@ unregister_memory(struct memory_block *memory, struct mem_section *section)
92 * uses. 92 * uses.
93 */ 93 */
94 94
95static ssize_t show_mem_phys_index(struct sys_device *dev, char *buf) 95static ssize_t show_mem_phys_index(struct sys_device *dev,
96 struct sysdev_attribute *attr, char *buf)
96{ 97{
97 struct memory_block *mem = 98 struct memory_block *mem =
98 container_of(dev, struct memory_block, sysdev); 99 container_of(dev, struct memory_block, sysdev);
@@ -102,7 +103,8 @@ static ssize_t show_mem_phys_index(struct sys_device *dev, char *buf)
102/* 103/*
103 * online, offline, going offline, etc. 104 * online, offline, going offline, etc.
104 */ 105 */
105static ssize_t show_mem_state(struct sys_device *dev, char *buf) 106static ssize_t show_mem_state(struct sys_device *dev,
107 struct sysdev_attribute *attr, char *buf)
106{ 108{
107 struct memory_block *mem = 109 struct memory_block *mem =
108 container_of(dev, struct memory_block, sysdev); 110 container_of(dev, struct memory_block, sysdev);
@@ -217,7 +219,8 @@ out:
217} 219}
218 220
219static ssize_t 221static ssize_t
220store_mem_state(struct sys_device *dev, const char *buf, size_t count) 222store_mem_state(struct sys_device *dev,
223 struct sysdev_attribute *attr, const char *buf, size_t count)
221{ 224{
222 struct memory_block *mem; 225 struct memory_block *mem;
223 unsigned int phys_section_nr; 226 unsigned int phys_section_nr;
@@ -248,7 +251,8 @@ out:
248 * s.t. if I offline all of these sections I can then 251 * s.t. if I offline all of these sections I can then
249 * remove the physical device? 252 * remove the physical device?
250 */ 253 */
251static ssize_t show_phys_device(struct sys_device *dev, char *buf) 254static ssize_t show_phys_device(struct sys_device *dev,
255 struct sysdev_attribute *attr, char *buf)
252{ 256{
253 struct memory_block *mem = 257 struct memory_block *mem =
254 container_of(dev, struct memory_block, sysdev); 258 container_of(dev, struct memory_block, sysdev);
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 0f867a083338..5116b78c6325 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -36,11 +36,13 @@ static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf)
36 return len; 36 return len;
37} 37}
38 38
39static inline ssize_t node_read_cpumask(struct sys_device *dev, char *buf) 39static inline ssize_t node_read_cpumask(struct sys_device *dev,
40 struct sysdev_attribute *attr, char *buf)
40{ 41{
41 return node_read_cpumap(dev, 0, buf); 42 return node_read_cpumap(dev, 0, buf);
42} 43}
43static inline ssize_t node_read_cpulist(struct sys_device *dev, char *buf) 44static inline ssize_t node_read_cpulist(struct sys_device *dev,
45 struct sysdev_attribute *attr, char *buf)
44{ 46{
45 return node_read_cpumap(dev, 1, buf); 47 return node_read_cpumap(dev, 1, buf);
46} 48}
@@ -49,7 +51,8 @@ static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL);
49static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); 51static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL);
50 52
51#define K(x) ((x) << (PAGE_SHIFT - 10)) 53#define K(x) ((x) << (PAGE_SHIFT - 10))
52static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) 54static ssize_t node_read_meminfo(struct sys_device * dev,
55 struct sysdev_attribute *attr, char * buf)
53{ 56{
54 int n; 57 int n;
55 int nid = dev->id; 58 int nid = dev->id;
@@ -112,7 +115,8 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
112#undef K 115#undef K
113static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL); 116static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
114 117
115static ssize_t node_read_numastat(struct sys_device * dev, char * buf) 118static ssize_t node_read_numastat(struct sys_device * dev,
119 struct sysdev_attribute *attr, char * buf)
116{ 120{
117 return sprintf(buf, 121 return sprintf(buf,
118 "numa_hit %lu\n" 122 "numa_hit %lu\n"
@@ -130,7 +134,8 @@ static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
130} 134}
131static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); 135static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
132 136
133static ssize_t node_read_distance(struct sys_device * dev, char * buf) 137static ssize_t node_read_distance(struct sys_device * dev,
138 struct sysdev_attribute *attr, char * buf)
134{ 139{
135 int nid = dev->id; 140 int nid = dev->id;
136 int len = 0; 141 int len = 0;
diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c
index 9b1b20b59e0a..2aa6e8fc4def 100644
--- a/drivers/base/power/trace.c
+++ b/drivers/base/power/trace.c
@@ -194,7 +194,7 @@ static int show_dev_hash(unsigned int value)
194 struct device * dev = to_device(entry); 194 struct device * dev = to_device(entry);
195 unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH); 195 unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH);
196 if (hash == value) { 196 if (hash == value) {
197 printk(" hash matches device %s\n", dev->bus_id); 197 dev_info(dev, "hash matches\n");
198 match++; 198 match++;
199 } 199 }
200 entry = entry->prev; 200 entry = entry->prev;
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 358bb0be3c08..40fc14f03540 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -36,7 +36,7 @@ sysdev_show(struct kobject * kobj, struct attribute * attr, char * buffer)
36 struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); 36 struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr);
37 37
38 if (sysdev_attr->show) 38 if (sysdev_attr->show)
39 return sysdev_attr->show(sysdev, buffer); 39 return sysdev_attr->show(sysdev, sysdev_attr, buffer);
40 return -EIO; 40 return -EIO;
41} 41}
42 42
@@ -49,7 +49,7 @@ sysdev_store(struct kobject * kobj, struct attribute * attr,
49 struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); 49 struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr);
50 50
51 if (sysdev_attr->store) 51 if (sysdev_attr->store)
52 return sysdev_attr->store(sysdev, buffer, count); 52 return sysdev_attr->store(sysdev, sysdev_attr, buffer, count);
53 return -EIO; 53 return -EIO;
54} 54}
55 55
@@ -130,8 +130,8 @@ static struct kset *system_kset;
130 130
131int sysdev_class_register(struct sysdev_class * cls) 131int sysdev_class_register(struct sysdev_class * cls)
132{ 132{
133 pr_debug("Registering sysdev class '%s'\n", 133 pr_debug("Registering sysdev class '%s'\n", cls->name);
134 kobject_name(&cls->kset.kobj)); 134
135 INIT_LIST_HEAD(&cls->drivers); 135 INIT_LIST_HEAD(&cls->drivers);
136 memset(&cls->kset.kobj, 0x00, sizeof(struct kobject)); 136 memset(&cls->kset.kobj, 0x00, sizeof(struct kobject));
137 cls->kset.kobj.parent = &system_kset->kobj; 137 cls->kset.kobj.parent = &system_kset->kobj;
@@ -241,7 +241,8 @@ int sysdev_register(struct sys_device * sysdev)
241 if (!cls) 241 if (!cls)
242 return -EINVAL; 242 return -EINVAL;
243 243
244 pr_debug("Registering sys device '%s'\n", kobject_name(&sysdev->kobj)); 244 pr_debug("Registering sys device of class '%s'\n",
245 kobject_name(&cls->kset.kobj));
245 246
246 /* initialize the kobject to 0, in case it had previously been used */ 247 /* initialize the kobject to 0, in case it had previously been used */
247 memset(&sysdev->kobj, 0x00, sizeof(struct kobject)); 248 memset(&sysdev->kobj, 0x00, sizeof(struct kobject));
@@ -257,6 +258,9 @@ int sysdev_register(struct sys_device * sysdev)
257 if (!error) { 258 if (!error) {
258 struct sysdev_driver * drv; 259 struct sysdev_driver * drv;
259 260
261 pr_debug("Registering sys device '%s'\n",
262 kobject_name(&sysdev->kobj));
263
260 mutex_lock(&sysdev_drivers_lock); 264 mutex_lock(&sysdev_drivers_lock);
261 /* Generic notification is implicit, because it's that 265 /* Generic notification is implicit, because it's that
262 * code that should have called us. 266 * code that should have called us.
@@ -269,6 +273,7 @@ int sysdev_register(struct sys_device * sysdev)
269 } 273 }
270 mutex_unlock(&sysdev_drivers_lock); 274 mutex_unlock(&sysdev_drivers_lock);
271 } 275 }
276
272 kobject_uevent(&sysdev->kobj, KOBJ_ADD); 277 kobject_uevent(&sysdev->kobj, KOBJ_ADD);
273 return error; 278 return error;
274} 279}
@@ -474,3 +479,52 @@ int __init system_bus_init(void)
474 479
475EXPORT_SYMBOL_GPL(sysdev_register); 480EXPORT_SYMBOL_GPL(sysdev_register);
476EXPORT_SYMBOL_GPL(sysdev_unregister); 481EXPORT_SYMBOL_GPL(sysdev_unregister);
482
483#define to_ext_attr(x) container_of(x, struct sysdev_ext_attribute, attr)
484
485ssize_t sysdev_store_ulong(struct sys_device *sysdev,
486 struct sysdev_attribute *attr,
487 const char *buf, size_t size)
488{
489 struct sysdev_ext_attribute *ea = to_ext_attr(attr);
490 char *end;
491 unsigned long new = simple_strtoul(buf, &end, 0);
492 if (end == buf)
493 return -EINVAL;
494 *(unsigned long *)(ea->var) = new;
495 return end - buf;
496}
497EXPORT_SYMBOL_GPL(sysdev_store_ulong);
498
499ssize_t sysdev_show_ulong(struct sys_device *sysdev,
500 struct sysdev_attribute *attr,
501 char *buf)
502{
503 struct sysdev_ext_attribute *ea = to_ext_attr(attr);
504 return snprintf(buf, PAGE_SIZE, "%lx\n", *(unsigned long *)(ea->var));
505}
506EXPORT_SYMBOL_GPL(sysdev_show_ulong);
507
508ssize_t sysdev_store_int(struct sys_device *sysdev,
509 struct sysdev_attribute *attr,
510 const char *buf, size_t size)
511{
512 struct sysdev_ext_attribute *ea = to_ext_attr(attr);
513 char *end;
514 long new = simple_strtol(buf, &end, 0);
515 if (end == buf || new > INT_MAX || new < INT_MIN)
516 return -EINVAL;
517 *(int *)(ea->var) = new;
518 return end - buf;
519}
520EXPORT_SYMBOL_GPL(sysdev_store_int);
521
522ssize_t sysdev_show_int(struct sys_device *sysdev,
523 struct sysdev_attribute *attr,
524 char *buf)
525{
526 struct sysdev_ext_attribute *ea = to_ext_attr(attr);
527 return snprintf(buf, PAGE_SIZE, "%d\n", *(int *)(ea->var));
528}
529EXPORT_SYMBOL_GPL(sysdev_show_int);
530
diff --git a/drivers/base/topology.c b/drivers/base/topology.c
index 3f6d9b0a6abe..199cd97e32e6 100644
--- a/drivers/base/topology.c
+++ b/drivers/base/topology.c
@@ -34,7 +34,8 @@
34static SYSDEV_ATTR(_name, 0444, show_##_name, NULL) 34static SYSDEV_ATTR(_name, 0444, show_##_name, NULL)
35 35
36#define define_id_show_func(name) \ 36#define define_id_show_func(name) \
37static ssize_t show_##name(struct sys_device *dev, char *buf) \ 37static ssize_t show_##name(struct sys_device *dev, \
38 struct sysdev_attribute *attr, char *buf) \
38{ \ 39{ \
39 unsigned int cpu = dev->id; \ 40 unsigned int cpu = dev->id; \
40 return sprintf(buf, "%d\n", topology_##name(cpu)); \ 41 return sprintf(buf, "%d\n", topology_##name(cpu)); \
@@ -59,14 +60,17 @@ static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf)
59 60
60#ifdef arch_provides_topology_pointers 61#ifdef arch_provides_topology_pointers
61#define define_siblings_show_map(name) \ 62#define define_siblings_show_map(name) \
62static ssize_t show_##name(struct sys_device *dev, char *buf) \ 63static ssize_t show_##name(struct sys_device *dev, \
64 struct sysdev_attribute *attr, char *buf) \
63{ \ 65{ \
64 unsigned int cpu = dev->id; \ 66 unsigned int cpu = dev->id; \
65 return show_cpumap(0, &(topology_##name(cpu)), buf); \ 67 return show_cpumap(0, &(topology_##name(cpu)), buf); \
66} 68}
67 69
68#define define_siblings_show_list(name) \ 70#define define_siblings_show_list(name) \
69static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ 71static ssize_t show_##name##_list(struct sys_device *dev, \
72 struct sysdev_attribute *attr, \
73 char *buf) \
70{ \ 74{ \
71 unsigned int cpu = dev->id; \ 75 unsigned int cpu = dev->id; \
72 return show_cpumap(1, &(topology_##name(cpu)), buf); \ 76 return show_cpumap(1, &(topology_##name(cpu)), buf); \
@@ -74,7 +78,8 @@ static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \
74 78
75#else 79#else
76#define define_siblings_show_map(name) \ 80#define define_siblings_show_map(name) \
77static ssize_t show_##name(struct sys_device *dev, char *buf) \ 81static ssize_t show_##name(struct sys_device *dev, \
82 struct sysdev_attribute *attr, char *buf) \
78{ \ 83{ \
79 unsigned int cpu = dev->id; \ 84 unsigned int cpu = dev->id; \
80 cpumask_t mask = topology_##name(cpu); \ 85 cpumask_t mask = topology_##name(cpu); \
@@ -82,7 +87,9 @@ static ssize_t show_##name(struct sys_device *dev, char *buf) \
82} 87}
83 88
84#define define_siblings_show_list(name) \ 89#define define_siblings_show_list(name) \
85static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ 90static ssize_t show_##name##_list(struct sys_device *dev, \
91 struct sysdev_attribute *attr, \
92 char *buf) \
86{ \ 93{ \
87 unsigned int cpu = dev->id; \ 94 unsigned int cpu = dev->id; \
88 cpumask_t mask = topology_##name(cpu); \ 95 cpumask_t mask = topology_##name(cpu); \
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index d1de68a31920..c04440cd6a32 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -277,8 +277,9 @@ aoechr_init(void)
277 return PTR_ERR(aoe_class); 277 return PTR_ERR(aoe_class);
278 } 278 }
279 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 279 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
280 device_create(aoe_class, NULL, 280 device_create_drvdata(aoe_class, NULL,
281 MKDEV(AOE_MAJOR, chardevs[i].minor), chardevs[i].name); 281 MKDEV(AOE_MAJOR, chardevs[i].minor),
282 NULL, chardevs[i].name);
282 283
283 return 0; 284 return 0;
284} 285}
diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index 9d92636350e5..d731ca42f802 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -686,8 +686,9 @@ static int __init pg_init(void)
686 for (unit = 0; unit < PG_UNITS; unit++) { 686 for (unit = 0; unit < PG_UNITS; unit++) {
687 struct pg *dev = &devices[unit]; 687 struct pg *dev = &devices[unit];
688 if (dev->present) 688 if (dev->present)
689 device_create(pg_class, NULL, MKDEV(major, unit), 689 device_create_drvdata(pg_class, NULL,
690 "pg%u", unit); 690 MKDEV(major, unit), NULL,
691 "pg%u", unit);
691 } 692 }
692 err = 0; 693 err = 0;
693 goto out; 694 goto out;
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index 5c74c3574a5a..673b8b2fd337 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -979,10 +979,12 @@ static int __init pt_init(void)
979 979
980 for (unit = 0; unit < PT_UNITS; unit++) 980 for (unit = 0; unit < PT_UNITS; unit++)
981 if (pt[unit].present) { 981 if (pt[unit].present) {
982 device_create(pt_class, NULL, MKDEV(major, unit), 982 device_create_drvdata(pt_class, NULL,
983 "pt%d", unit); 983 MKDEV(major, unit), NULL,
984 device_create(pt_class, NULL, MKDEV(major, unit + 128), 984 "pt%d", unit);
985 "pt%dn", unit); 985 device_create_drvdata(pt_class, NULL,
986 MKDEV(major, unit + 128), NULL,
987 "pt%dn", unit);
986 } 988 }
987 goto out; 989 goto out;
988 990
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 45bee918c46a..158eed4d5161 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -303,7 +303,9 @@ static struct kobj_type kobj_pkt_type_wqueue = {
303static void pkt_sysfs_dev_new(struct pktcdvd_device *pd) 303static void pkt_sysfs_dev_new(struct pktcdvd_device *pd)
304{ 304{
305 if (class_pktcdvd) { 305 if (class_pktcdvd) {
306 pd->dev = device_create(class_pktcdvd, NULL, pd->pkt_dev, "%s", pd->name); 306 pd->dev = device_create_drvdata(class_pktcdvd, NULL,
307 pd->pkt_dev, NULL,
308 "%s", pd->name);
307 if (IS_ERR(pd->dev)) 309 if (IS_ERR(pd->dev))
308 pd->dev = NULL; 310 pd->dev = NULL;
309 } 311 }
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 650e6b44ce65..e0bbbfb6a36b 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -300,16 +300,6 @@ config SPECIALIX
300 and compile this driver as kernel loadable module which will be 300 and compile this driver as kernel loadable module which will be
301 called specialix. 301 called specialix.
302 302
303config SPECIALIX_RTSCTS
304 bool "Specialix DTR/RTS pin is RTS"
305 depends on SPECIALIX
306 help
307 The Specialix IO8+ card can only support either RTS or DTR. If you
308 say N here, the driver will use the pin as "DTR" when the tty is in
309 software handshake mode. If you say Y here or hardware handshake is
310 on, it will always be RTS. Read the file
311 <file:Documentation/specialix.txt> for more information.
312
313config SX 303config SX
314 tristate "Specialix SX (and SI) card support" 304 tristate "Specialix SX (and SI) card support"
315 depends on SERIAL_NONSTANDARD && (PCI || EISA || ISA) 305 depends on SERIAL_NONSTANDARD && (PCI || EISA || ISA)
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 0e0d12a06462..dc5a327d72d5 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -7,7 +7,7 @@
7# 7#
8FONTMAPFILE = cp437.uni 8FONTMAPFILE = cp437.uni
9 9
10obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o 10obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o
11 11
12obj-$(CONFIG_LEGACY_PTYS) += pty.o 12obj-$(CONFIG_LEGACY_PTYS) += pty.o
13obj-$(CONFIG_UNIX98_PTYS) += pty.o 13obj-$(CONFIG_UNIX98_PTYS) += pty.o
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 37457e5a4f2b..3530ff417a51 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -1248,7 +1248,7 @@ static int rs_tiocmset(struct tty_struct *tty, struct file *file,
1248/* 1248/*
1249 * rs_break() --- routine which turns the break handling on or off 1249 * rs_break() --- routine which turns the break handling on or off
1250 */ 1250 */
1251static void rs_break(struct tty_struct *tty, int break_state) 1251static int rs_break(struct tty_struct *tty, int break_state)
1252{ 1252{
1253 struct async_struct * info = (struct async_struct *)tty->driver_data; 1253 struct async_struct * info = (struct async_struct *)tty->driver_data;
1254 unsigned long flags; 1254 unsigned long flags;
@@ -1263,6 +1263,7 @@ static void rs_break(struct tty_struct *tty, int break_state)
1263 custom.adkcon = AC_UARTBRK; 1263 custom.adkcon = AC_UARTBRK;
1264 mb(); 1264 mb();
1265 local_irq_restore(flags); 1265 local_irq_restore(flags);
1266 return 0;
1266} 1267}
1267 1268
1268 1269
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index e991dc85f2fb..fe6d774fe2e4 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -3700,14 +3700,15 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3700/* 3700/*
3701 * cy_break() --- routine which turns the break handling on or off 3701 * cy_break() --- routine which turns the break handling on or off
3702 */ 3702 */
3703static void cy_break(struct tty_struct *tty, int break_state) 3703static int cy_break(struct tty_struct *tty, int break_state)
3704{ 3704{
3705 struct cyclades_port *info = tty->driver_data; 3705 struct cyclades_port *info = tty->driver_data;
3706 struct cyclades_card *card; 3706 struct cyclades_card *card;
3707 unsigned long flags; 3707 unsigned long flags;
3708 int retval = 0;
3708 3709
3709 if (serial_paranoia_check(info, tty->name, "cy_break")) 3710 if (serial_paranoia_check(info, tty->name, "cy_break"))
3710 return; 3711 return -EINVAL;
3711 3712
3712 card = info->card; 3713 card = info->card;
3713 3714
@@ -3736,8 +3737,6 @@ static void cy_break(struct tty_struct *tty, int break_state)
3736 } 3737 }
3737 } 3738 }
3738 } else { 3739 } else {
3739 int retval;
3740
3741 if (break_state == -1) { 3740 if (break_state == -1) {
3742 retval = cyz_issue_cmd(card, 3741 retval = cyz_issue_cmd(card,
3743 info->line - card->first_line, 3742 info->line - card->first_line,
@@ -3758,6 +3757,7 @@ static void cy_break(struct tty_struct *tty, int break_state)
3758 } 3757 }
3759 } 3758 }
3760 spin_unlock_irqrestore(&card->card_lock, flags); 3759 spin_unlock_irqrestore(&card->card_lock, flags);
3760 return retval;
3761} /* cy_break */ 3761} /* cy_break */
3762 3762
3763static int get_mon_info(struct cyclades_port *info, 3763static int get_mon_info(struct cyclades_port *info,
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index b9a30c30e2b8..33c466a4888f 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -500,7 +500,8 @@ static int __init dsp56k_init_driver(void)
500 err = PTR_ERR(dsp56k_class); 500 err = PTR_ERR(dsp56k_class);
501 goto out_chrdev; 501 goto out_chrdev;
502 } 502 }
503 device_create(dsp56k_class, NULL, MKDEV(DSP56K_MAJOR, 0), "dsp56k"); 503 device_create_drvdata(dsp56k_class, NULL, MKDEV(DSP56K_MAJOR, 0),
504 NULL, "dsp56k");
504 505
505 printk(banner); 506 printk(banner);
506 goto out; 507 goto out;
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index ac9995f6578b..456e4ede049f 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -184,9 +184,8 @@ static void pc_stop(struct tty_struct *);
184static void pc_start(struct tty_struct *); 184static void pc_start(struct tty_struct *);
185static void pc_throttle(struct tty_struct *tty); 185static void pc_throttle(struct tty_struct *tty);
186static void pc_unthrottle(struct tty_struct *tty); 186static void pc_unthrottle(struct tty_struct *tty);
187static void digi_send_break(struct channel *ch, int msec); 187static int pc_send_break(struct tty_struct *tty, int msec);
188static void setup_empty_event(struct tty_struct *tty, struct channel *ch); 188static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
189static void epca_setup(char *, int *);
190 189
191static int pc_write(struct tty_struct *, const unsigned char *, int); 190static int pc_write(struct tty_struct *, const unsigned char *, int);
192static int pc_init(void); 191static int pc_init(void);
@@ -1040,6 +1039,7 @@ static const struct tty_operations pc_ops = {
1040 .throttle = pc_throttle, 1039 .throttle = pc_throttle,
1041 .unthrottle = pc_unthrottle, 1040 .unthrottle = pc_unthrottle,
1042 .hangup = pc_hangup, 1041 .hangup = pc_hangup,
1042 .break_ctl = pc_send_break
1043}; 1043};
1044 1044
1045static int info_open(struct tty_struct *tty, struct file *filp) 1045static int info_open(struct tty_struct *tty, struct file *filp)
@@ -1132,7 +1132,7 @@ static int __init pc_init(void)
1132 pc_driver->init_termios.c_lflag = 0; 1132 pc_driver->init_termios.c_lflag = 0;
1133 pc_driver->init_termios.c_ispeed = 9600; 1133 pc_driver->init_termios.c_ispeed = 9600;
1134 pc_driver->init_termios.c_ospeed = 9600; 1134 pc_driver->init_termios.c_ospeed = 9600;
1135 pc_driver->flags = TTY_DRIVER_REAL_RAW; 1135 pc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1136 tty_set_operations(pc_driver, &pc_ops); 1136 tty_set_operations(pc_driver, &pc_ops);
1137 1137
1138 pc_info->owner = THIS_MODULE; 1138 pc_info->owner = THIS_MODULE;
@@ -2177,7 +2177,6 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file,
2177 unsigned int cmd, unsigned long arg) 2177 unsigned int cmd, unsigned long arg)
2178{ 2178{
2179 digiflow_t dflow; 2179 digiflow_t dflow;
2180 int retval;
2181 unsigned long flags; 2180 unsigned long flags;
2182 unsigned int mflag, mstat; 2181 unsigned int mflag, mstat;
2183 unsigned char startc, stopc; 2182 unsigned char startc, stopc;
@@ -2189,37 +2188,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file,
2189 bc = ch->brdchan; 2188 bc = ch->brdchan;
2190 else 2189 else
2191 return -EINVAL; 2190 return -EINVAL;
2192 /*
2193 * For POSIX compliance we need to add more ioctls. See tty_ioctl.c in
2194 * /usr/src/linux/drivers/char for a good example. In particular think
2195 * about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2196 */
2197 switch (cmd) { 2191 switch (cmd) {
2198 case TCSBRK: /* SVID version: non-zero arg --> no break */
2199 retval = tty_check_change(tty);
2200 if (retval)
2201 return retval;
2202 /* Setup an event to indicate when the transmit
2203 buffer empties */
2204 spin_lock_irqsave(&epca_lock, flags);
2205 setup_empty_event(tty, ch);
2206 spin_unlock_irqrestore(&epca_lock, flags);
2207 tty_wait_until_sent(tty, 0);
2208 if (!arg)
2209 digi_send_break(ch, HZ / 4); /* 1/4 second */
2210 return 0;
2211 case TCSBRKP: /* support for POSIX tcsendbreak() */
2212 retval = tty_check_change(tty);
2213 if (retval)
2214 return retval;
2215 /* Setup an event to indicate when the transmit buffer
2216 empties */
2217 spin_lock_irqsave(&epca_lock, flags);
2218 setup_empty_event(tty, ch);
2219 spin_unlock_irqrestore(&epca_lock, flags);
2220 tty_wait_until_sent(tty, 0);
2221 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2222 return 0;
2223 case TIOCMODG: 2192 case TIOCMODG:
2224 mflag = pc_tiocmget(tty, file); 2193 mflag = pc_tiocmget(tty, file);
2225 if (put_user(mflag, (unsigned long __user *)argp)) 2194 if (put_user(mflag, (unsigned long __user *)argp))
@@ -2505,10 +2474,14 @@ static void pc_unthrottle(struct tty_struct *tty)
2505 } 2474 }
2506} 2475}
2507 2476
2508static void digi_send_break(struct channel *ch, int msec) 2477static int pc_send_break(struct tty_struct *tty, int msec)
2509{ 2478{
2479 struct channel *ch = (struct channel *) tty->driver_data;
2510 unsigned long flags; 2480 unsigned long flags;
2511 2481
2482 if (msec == -1)
2483 return -EOPNOTSUPP;
2484
2512 spin_lock_irqsave(&epca_lock, flags); 2485 spin_lock_irqsave(&epca_lock, flags);
2513 globalwinon(ch); 2486 globalwinon(ch);
2514 /* 2487 /*
@@ -2521,6 +2494,7 @@ static void digi_send_break(struct channel *ch, int msec)
2521 fepcmd(ch, SENDBREAK, msec, 0, 10, 0); 2494 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2522 memoff(ch); 2495 memoff(ch);
2523 spin_unlock_irqrestore(&epca_lock, flags); 2496 spin_unlock_irqrestore(&epca_lock, flags);
2497 return 0;
2524} 2498}
2525 2499
2526/* Caller MUST hold the lock */ 2500/* Caller MUST hold the lock */
@@ -2538,7 +2512,8 @@ static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2538 memoff(ch); 2512 memoff(ch);
2539} 2513}
2540 2514
2541static void epca_setup(char *str, int *ints) 2515#ifndef MODULE
2516static void __init epca_setup(char *str, int *ints)
2542{ 2517{
2543 struct board_info board; 2518 struct board_info board;
2544 int index, loop, last; 2519 int index, loop, last;
@@ -2792,6 +2767,17 @@ static void epca_setup(char *str, int *ints)
2792 num_cards++; 2767 num_cards++;
2793} 2768}
2794 2769
2770static int __init epca_real_setup(char *str)
2771{
2772 int ints[11];
2773
2774 epca_setup(get_options(str, 11, ints), ints);
2775 return 1;
2776}
2777
2778__setup("digiepca", epca_real_setup);
2779#endif
2780
2795enum epic_board_types { 2781enum epic_board_types {
2796 brd_xr = 0, 2782 brd_xr = 0,
2797 brd_xem, 2783 brd_xem,
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
index 2eaf09f93e3d..7f077c0097f6 100644
--- a/drivers/char/esp.c
+++ b/drivers/char/esp.c
@@ -1725,13 +1725,13 @@ static int esp_tiocmset(struct tty_struct *tty, struct file *file,
1725/* 1725/*
1726 * rs_break() --- routine which turns the break handling on or off 1726 * rs_break() --- routine which turns the break handling on or off
1727 */ 1727 */
1728static void esp_break(struct tty_struct *tty, int break_state) 1728static int esp_break(struct tty_struct *tty, int break_state)
1729{ 1729{
1730 struct esp_struct *info = tty->driver_data; 1730 struct esp_struct *info = tty->driver_data;
1731 unsigned long flags; 1731 unsigned long flags;
1732 1732
1733 if (serial_paranoia_check(info, tty->name, "esp_break")) 1733 if (serial_paranoia_check(info, tty->name, "esp_break"))
1734 return; 1734 return -EINVAL;
1735 1735
1736 if (break_state == -1) { 1736 if (break_state == -1) {
1737 spin_lock_irqsave(&info->lock, flags); 1737 spin_lock_irqsave(&info->lock, flags);
@@ -1747,6 +1747,7 @@ static void esp_break(struct tty_struct *tty, int break_state)
1747 serial_out(info, UART_ESI_CMD2, 0x00); 1747 serial_out(info, UART_ESI_CMD2, 0x00);
1748 spin_unlock_irqrestore(&info->lock, flags); 1748 spin_unlock_irqrestore(&info->lock, flags);
1749 } 1749 }
1750 return 0;
1750} 1751}
1751 1752
1752static int rs_ioctl(struct tty_struct *tty, struct file *file, 1753static int rs_ioctl(struct tty_struct *tty, struct file *file,
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index efd0b4db7c8e..8822eca58ffa 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -59,6 +59,19 @@ config HW_RANDOM_GEODE
59 59
60 If unsure, say Y. 60 If unsure, say Y.
61 61
62config HW_RANDOM_N2RNG
63 tristate "Niagara2 Random Number Generator support"
64 depends on HW_RANDOM && SPARC64
65 default HW_RANDOM
66 ---help---
67 This driver provides kernel-side support for the Random Number
68 Generator hardware found on Niagara2 cpus.
69
70 To compile this driver as a module, choose M here: the
71 module will be called n2-rng.
72
73 If unsure, say Y.
74
62config HW_RANDOM_VIA 75config HW_RANDOM_VIA
63 tristate "VIA HW Random Number Generator support" 76 tristate "VIA HW Random Number Generator support"
64 depends on HW_RANDOM && X86_32 77 depends on HW_RANDOM && X86_32
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index b4940ddbb35f..b6effb7522c2 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -7,6 +7,8 @@ rng-core-y := core.o
7obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o 7obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o
8obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o 8obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o
9obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o 9obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o
10obj-$(CONFIG_HW_RANDOM_N2RNG) += n2-rng.o
11n2-rng-y := n2-drv.o n2-asm.o
10obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o 12obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o
11obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o 13obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
12obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o 14obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
diff --git a/drivers/char/hw_random/n2-asm.S b/drivers/char/hw_random/n2-asm.S
new file mode 100644
index 000000000000..9b6eb5cd59f6
--- /dev/null
+++ b/drivers/char/hw_random/n2-asm.S
@@ -0,0 +1,79 @@
1/* n2-asm.S: Niagara2 RNG hypervisor call assembler.
2 *
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
4 */
5#include <linux/linkage.h>
6#include <asm/hypervisor.h>
7#include "n2rng.h"
8
9 .text
10
11ENTRY(sun4v_rng_get_diag_ctl)
12 mov HV_FAST_RNG_GET_DIAG_CTL, %o5
13 ta HV_FAST_TRAP
14 retl
15 nop
16ENDPROC(sun4v_rng_get_diag_ctl)
17
18ENTRY(sun4v_rng_ctl_read_v1)
19 mov %o1, %o3
20 mov %o2, %o4
21 mov HV_FAST_RNG_CTL_READ, %o5
22 ta HV_FAST_TRAP
23 stx %o1, [%o3]
24 retl
25 stx %o2, [%o4]
26ENDPROC(sun4v_rng_ctl_read_v1)
27
28ENTRY(sun4v_rng_ctl_read_v2)
29 save %sp, -192, %sp
30 mov %i0, %o0
31 mov %i1, %o1
32 mov HV_FAST_RNG_CTL_READ, %o5
33 ta HV_FAST_TRAP
34 stx %o1, [%i2]
35 stx %o2, [%i3]
36 stx %o3, [%i4]
37 stx %o4, [%i5]
38 ret
39 restore %g0, %o0, %o0
40ENDPROC(sun4v_rng_ctl_read_v2)
41
42ENTRY(sun4v_rng_ctl_write_v1)
43 mov %o3, %o4
44 mov HV_FAST_RNG_CTL_WRITE, %o5
45 ta HV_FAST_TRAP
46 retl
47 stx %o1, [%o4]
48ENDPROC(sun4v_rng_ctl_write_v1)
49
50ENTRY(sun4v_rng_ctl_write_v2)
51 mov HV_FAST_RNG_CTL_WRITE, %o5
52 ta HV_FAST_TRAP
53 retl
54 nop
55ENDPROC(sun4v_rng_ctl_write_v2)
56
57ENTRY(sun4v_rng_data_read_diag_v1)
58 mov %o2, %o4
59 mov HV_FAST_RNG_DATA_READ_DIAG, %o5
60 ta HV_FAST_TRAP
61 retl
62 stx %o1, [%o4]
63ENDPROC(sun4v_rng_data_read_diag_v1)
64
65ENTRY(sun4v_rng_data_read_diag_v2)
66 mov %o3, %o4
67 mov HV_FAST_RNG_DATA_READ_DIAG, %o5
68 ta HV_FAST_TRAP
69 retl
70 stx %o1, [%o4]
71ENDPROC(sun4v_rng_data_read_diag_v2)
72
73ENTRY(sun4v_rng_data_read)
74 mov %o1, %o4
75 mov HV_FAST_RNG_DATA_READ, %o5
76 ta HV_FAST_TRAP
77 retl
78 stx %o1, [%o4]
79ENDPROC(sun4v_rng_data_read)
diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c
new file mode 100644
index 000000000000..5220f541df25
--- /dev/null
+++ b/drivers/char/hw_random/n2-drv.c
@@ -0,0 +1,771 @@
1/* n2-drv.c: Niagara-2 RNG driver.
2 *
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/types.h>
9#include <linux/delay.h>
10#include <linux/init.h>
11#include <linux/slab.h>
12#include <linux/workqueue.h>
13#include <linux/preempt.h>
14#include <linux/hw_random.h>
15
16#include <linux/of.h>
17#include <linux/of_device.h>
18
19#include <asm/hypervisor.h>
20
21#include "n2rng.h"
22
23#define DRV_MODULE_NAME "n2rng"
24#define PFX DRV_MODULE_NAME ": "
25#define DRV_MODULE_VERSION "0.1"
26#define DRV_MODULE_RELDATE "May 15, 2008"
27
28static char version[] __devinitdata =
29 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
30
31MODULE_AUTHOR("David S. Miller (davem@davemloft.net)");
32MODULE_DESCRIPTION("Niagara2 RNG driver");
33MODULE_LICENSE("GPL");
34MODULE_VERSION(DRV_MODULE_VERSION);
35
36/* The Niagara2 RNG provides a 64-bit read-only random number
37 * register, plus a control register. Access to the RNG is
38 * virtualized through the hypervisor so that both guests and control
39 * nodes can access the device.
40 *
41 * The entropy source consists of raw entropy sources, each
42 * constructed from a voltage controlled oscillator whose phase is
43 * jittered by thermal noise sources.
44 *
45 * The oscillator in each of the three raw entropy sources run at
46 * different frequencies. Normally, all three generator outputs are
47 * gathered, xored together, and fed into a CRC circuit, the output of
48 * which is the 64-bit read-only register.
49 *
50 * Some time is necessary for all the necessary entropy to build up
51 * such that a full 64-bits of entropy are available in the register.
52 * In normal operating mode (RNG_CTL_LFSR is set), the chip implements
53 * an interlock which blocks register reads until sufficient entropy
54 * is available.
55 *
56 * A control register is provided for adjusting various aspects of RNG
57 * operation, and to enable diagnostic modes. Each of the three raw
58 * entropy sources has an enable bit (RNG_CTL_ES{1,2,3}). Also
59 * provided are fields for controlling the minimum time in cycles
60 * between read accesses to the register (RNG_CTL_WAIT, this controls
61 * the interlock described in the previous paragraph).
62 *
63 * The standard setting is to have the mode bit (RNG_CTL_LFSR) set,
64 * all three entropy sources enabled, and the interlock time set
65 * appropriately.
66 *
67 * The CRC polynomial used by the chip is:
68 *
69 * P(X) = x64 + x61 + x57 + x56 + x52 + x51 + x50 + x48 + x47 + x46 +
70 * x43 + x42 + x41 + x39 + x38 + x37 + x35 + x32 + x28 + x25 +
71 * x22 + x21 + x17 + x15 + x13 + x12 + x11 + x7 + x5 + x + 1
72 *
73 * The RNG_CTL_VCO value of each noise cell must be programmed
74 * seperately. This is why 4 control register values must be provided
75 * to the hypervisor. During a write, the hypervisor writes them all,
76 * one at a time, to the actual RNG_CTL register. The first three
77 * values are used to setup the desired RNG_CTL_VCO for each entropy
78 * source, for example:
79 *
80 * control 0: (1 << RNG_CTL_VCO_SHIFT) | RNG_CTL_ES1
81 * control 1: (2 << RNG_CTL_VCO_SHIFT) | RNG_CTL_ES2
82 * control 2: (3 << RNG_CTL_VCO_SHIFT) | RNG_CTL_ES3
83 *
84 * And then the fourth value sets the final chip state and enables
85 * desired.
86 */
87
88static int n2rng_hv_err_trans(unsigned long hv_err)
89{
90 switch (hv_err) {
91 case HV_EOK:
92 return 0;
93 case HV_EWOULDBLOCK:
94 return -EAGAIN;
95 case HV_ENOACCESS:
96 return -EPERM;
97 case HV_EIO:
98 return -EIO;
99 case HV_EBUSY:
100 return -EBUSY;
101 case HV_EBADALIGN:
102 case HV_ENORADDR:
103 return -EFAULT;
104 default:
105 return -EINVAL;
106 }
107}
108
109static unsigned long n2rng_generic_read_control_v2(unsigned long ra,
110 unsigned long unit)
111{
112 unsigned long hv_err, state, ticks, watchdog_delta, watchdog_status;
113 int block = 0, busy = 0;
114
115 while (1) {
116 hv_err = sun4v_rng_ctl_read_v2(ra, unit, &state,
117 &ticks,
118 &watchdog_delta,
119 &watchdog_status);
120 if (hv_err == HV_EOK)
121 break;
122
123 if (hv_err == HV_EBUSY) {
124 if (++busy >= N2RNG_BUSY_LIMIT)
125 break;
126
127 udelay(1);
128 } else if (hv_err == HV_EWOULDBLOCK) {
129 if (++block >= N2RNG_BLOCK_LIMIT)
130 break;
131
132 __delay(ticks);
133 } else
134 break;
135 }
136
137 return hv_err;
138}
139
140/* In multi-socket situations, the hypervisor might need to
141 * queue up the RNG control register write if it's for a unit
142 * that is on a cpu socket other than the one we are executing on.
143 *
144 * We poll here waiting for a successful read of that control
145 * register to make sure the write has been actually performed.
146 */
147static unsigned long n2rng_control_settle_v2(struct n2rng *np, int unit)
148{
149 unsigned long ra = __pa(&np->scratch_control[0]);
150
151 return n2rng_generic_read_control_v2(ra, unit);
152}
153
154static unsigned long n2rng_write_ctl_one(struct n2rng *np, int unit,
155 unsigned long state,
156 unsigned long control_ra,
157 unsigned long watchdog_timeout,
158 unsigned long *ticks)
159{
160 unsigned long hv_err;
161
162 if (np->hvapi_major == 1) {
163 hv_err = sun4v_rng_ctl_write_v1(control_ra, state,
164 watchdog_timeout, ticks);
165 } else {
166 hv_err = sun4v_rng_ctl_write_v2(control_ra, state,
167 watchdog_timeout, unit);
168 if (hv_err == HV_EOK)
169 hv_err = n2rng_control_settle_v2(np, unit);
170 *ticks = N2RNG_ACCUM_CYCLES_DEFAULT;
171 }
172
173 return hv_err;
174}
175
176static int n2rng_generic_read_data(unsigned long data_ra)
177{
178 unsigned long ticks, hv_err;
179 int block = 0, hcheck = 0;
180
181 while (1) {
182 hv_err = sun4v_rng_data_read(data_ra, &ticks);
183 if (hv_err == HV_EOK)
184 return 0;
185
186 if (hv_err == HV_EWOULDBLOCK) {
187 if (++block >= N2RNG_BLOCK_LIMIT)
188 return -EWOULDBLOCK;
189 __delay(ticks);
190 } else if (hv_err == HV_ENOACCESS) {
191 return -EPERM;
192 } else if (hv_err == HV_EIO) {
193 if (++hcheck >= N2RNG_HCHECK_LIMIT)
194 return -EIO;
195 udelay(10000);
196 } else
197 return -ENODEV;
198 }
199}
200
201static unsigned long n2rng_read_diag_data_one(struct n2rng *np,
202 unsigned long unit,
203 unsigned long data_ra,
204 unsigned long data_len,
205 unsigned long *ticks)
206{
207 unsigned long hv_err;
208
209 if (np->hvapi_major == 1) {
210 hv_err = sun4v_rng_data_read_diag_v1(data_ra, data_len, ticks);
211 } else {
212 hv_err = sun4v_rng_data_read_diag_v2(data_ra, data_len,
213 unit, ticks);
214 if (!*ticks)
215 *ticks = N2RNG_ACCUM_CYCLES_DEFAULT;
216 }
217 return hv_err;
218}
219
220static int n2rng_generic_read_diag_data(struct n2rng *np,
221 unsigned long unit,
222 unsigned long data_ra,
223 unsigned long data_len)
224{
225 unsigned long ticks, hv_err;
226 int block = 0;
227
228 while (1) {
229 hv_err = n2rng_read_diag_data_one(np, unit,
230 data_ra, data_len,
231 &ticks);
232 if (hv_err == HV_EOK)
233 return 0;
234
235 if (hv_err == HV_EWOULDBLOCK) {
236 if (++block >= N2RNG_BLOCK_LIMIT)
237 return -EWOULDBLOCK;
238 __delay(ticks);
239 } else if (hv_err == HV_ENOACCESS) {
240 return -EPERM;
241 } else if (hv_err == HV_EIO) {
242 return -EIO;
243 } else
244 return -ENODEV;
245 }
246}
247
248
249static int n2rng_generic_write_control(struct n2rng *np,
250 unsigned long control_ra,
251 unsigned long unit,
252 unsigned long state)
253{
254 unsigned long hv_err, ticks;
255 int block = 0, busy = 0;
256
257 while (1) {
258 hv_err = n2rng_write_ctl_one(np, unit, state, control_ra,
259 np->wd_timeo, &ticks);
260 if (hv_err == HV_EOK)
261 return 0;
262
263 if (hv_err == HV_EWOULDBLOCK) {
264 if (++block >= N2RNG_BLOCK_LIMIT)
265 return -EWOULDBLOCK;
266 __delay(ticks);
267 } else if (hv_err == HV_EBUSY) {
268 if (++busy >= N2RNG_BUSY_LIMIT)
269 return -EBUSY;
270 udelay(1);
271 } else
272 return -ENODEV;
273 }
274}
275
276/* Just try to see if we can successfully access the control register
277 * of the RNG on the domain on which we are currently executing.
278 */
279static int n2rng_try_read_ctl(struct n2rng *np)
280{
281 unsigned long hv_err;
282 unsigned long x;
283
284 if (np->hvapi_major == 1) {
285 hv_err = sun4v_rng_get_diag_ctl();
286 } else {
287 /* We purposefully give invalid arguments, HV_NOACCESS
288 * is higher priority than the errors we'd get from
289 * these other cases, and that's the error we are
290 * truly interested in.
291 */
292 hv_err = sun4v_rng_ctl_read_v2(0UL, ~0UL, &x, &x, &x, &x);
293 switch (hv_err) {
294 case HV_EWOULDBLOCK:
295 case HV_ENOACCESS:
296 break;
297 default:
298 hv_err = HV_EOK;
299 break;
300 }
301 }
302
303 return n2rng_hv_err_trans(hv_err);
304}
305
306#define CONTROL_DEFAULT_BASE \
307 ((2 << RNG_CTL_ASEL_SHIFT) | \
308 (N2RNG_ACCUM_CYCLES_DEFAULT << RNG_CTL_WAIT_SHIFT) | \
309 RNG_CTL_LFSR)
310
311#define CONTROL_DEFAULT_0 \
312 (CONTROL_DEFAULT_BASE | \
313 (1 << RNG_CTL_VCO_SHIFT) | \
314 RNG_CTL_ES1)
315#define CONTROL_DEFAULT_1 \
316 (CONTROL_DEFAULT_BASE | \
317 (2 << RNG_CTL_VCO_SHIFT) | \
318 RNG_CTL_ES2)
319#define CONTROL_DEFAULT_2 \
320 (CONTROL_DEFAULT_BASE | \
321 (3 << RNG_CTL_VCO_SHIFT) | \
322 RNG_CTL_ES3)
323#define CONTROL_DEFAULT_3 \
324 (CONTROL_DEFAULT_BASE | \
325 RNG_CTL_ES1 | RNG_CTL_ES2 | RNG_CTL_ES3)
326
327static void n2rng_control_swstate_init(struct n2rng *np)
328{
329 int i;
330
331 np->flags |= N2RNG_FLAG_CONTROL;
332
333 np->health_check_sec = N2RNG_HEALTH_CHECK_SEC_DEFAULT;
334 np->accum_cycles = N2RNG_ACCUM_CYCLES_DEFAULT;
335 np->wd_timeo = N2RNG_WD_TIMEO_DEFAULT;
336
337 for (i = 0; i < np->num_units; i++) {
338 struct n2rng_unit *up = &np->units[i];
339
340 up->control[0] = CONTROL_DEFAULT_0;
341 up->control[1] = CONTROL_DEFAULT_1;
342 up->control[2] = CONTROL_DEFAULT_2;
343 up->control[3] = CONTROL_DEFAULT_3;
344 }
345
346 np->hv_state = HV_RNG_STATE_UNCONFIGURED;
347}
348
349static int n2rng_grab_diag_control(struct n2rng *np)
350{
351 int i, busy_count, err = -ENODEV;
352
353 busy_count = 0;
354 for (i = 0; i < 100; i++) {
355 err = n2rng_try_read_ctl(np);
356 if (err != -EAGAIN)
357 break;
358
359 if (++busy_count > 100) {
360 dev_err(&np->op->dev,
361 "Grab diag control timeout.\n");
362 return -ENODEV;
363 }
364
365 udelay(1);
366 }
367
368 return err;
369}
370
371static int n2rng_init_control(struct n2rng *np)
372{
373 int err = n2rng_grab_diag_control(np);
374
375 /* Not in the control domain, that's OK we are only a consumer
376 * of the RNG data, we don't setup and program it.
377 */
378 if (err == -EPERM)
379 return 0;
380 if (err)
381 return err;
382
383 n2rng_control_swstate_init(np);
384
385 return 0;
386}
387
388static int n2rng_data_read(struct hwrng *rng, u32 *data)
389{
390 struct n2rng *np = (struct n2rng *) rng->priv;
391 unsigned long ra = __pa(&np->test_data);
392 int len;
393
394 if (!(np->flags & N2RNG_FLAG_READY)) {
395 len = 0;
396 } else if (np->flags & N2RNG_FLAG_BUFFER_VALID) {
397 np->flags &= ~N2RNG_FLAG_BUFFER_VALID;
398 *data = np->buffer;
399 len = 4;
400 } else {
401 int err = n2rng_generic_read_data(ra);
402 if (!err) {
403 np->buffer = np->test_data >> 32;
404 *data = np->test_data & 0xffffffff;
405 len = 4;
406 } else {
407 dev_err(&np->op->dev, "RNG error, restesting\n");
408 np->flags &= ~N2RNG_FLAG_READY;
409 if (!(np->flags & N2RNG_FLAG_SHUTDOWN))
410 schedule_delayed_work(&np->work, 0);
411 len = 0;
412 }
413 }
414
415 return len;
416}
417
418/* On a guest node, just make sure we can read random data properly.
419 * If a control node reboots or reloads it's n2rng driver, this won't
420 * work during that time. So we have to keep probing until the device
421 * becomes usable.
422 */
423static int n2rng_guest_check(struct n2rng *np)
424{
425 unsigned long ra = __pa(&np->test_data);
426
427 return n2rng_generic_read_data(ra);
428}
429
430static int n2rng_entropy_diag_read(struct n2rng *np, unsigned long unit,
431 u64 *pre_control, u64 pre_state,
432 u64 *buffer, unsigned long buf_len,
433 u64 *post_control, u64 post_state)
434{
435 unsigned long post_ctl_ra = __pa(post_control);
436 unsigned long pre_ctl_ra = __pa(pre_control);
437 unsigned long buffer_ra = __pa(buffer);
438 int err;
439
440 err = n2rng_generic_write_control(np, pre_ctl_ra, unit, pre_state);
441 if (err)
442 return err;
443
444 err = n2rng_generic_read_diag_data(np, unit,
445 buffer_ra, buf_len);
446
447 (void) n2rng_generic_write_control(np, post_ctl_ra, unit,
448 post_state);
449
450 return err;
451}
452
453static u64 advance_polynomial(u64 poly, u64 val, int count)
454{
455 int i;
456
457 for (i = 0; i < count; i++) {
458 int highbit_set = ((s64)val < 0);
459
460 val <<= 1;
461 if (highbit_set)
462 val ^= poly;
463 }
464
465 return val;
466}
467
468static int n2rng_test_buffer_find(struct n2rng *np, u64 val)
469{
470 int i, count = 0;
471
472 /* Purposefully skip over the first word. */
473 for (i = 1; i < SELFTEST_BUFFER_WORDS; i++) {
474 if (np->test_buffer[i] == val)
475 count++;
476 }
477 return count;
478}
479
480static void n2rng_dump_test_buffer(struct n2rng *np)
481{
482 int i;
483
484 for (i = 0; i < SELFTEST_BUFFER_WORDS; i++)
485 dev_err(&np->op->dev, "Test buffer slot %d [0x%016lx]\n",
486 i, np->test_buffer[i]);
487}
488
489static int n2rng_check_selftest_buffer(struct n2rng *np, unsigned long unit)
490{
491 u64 val = SELFTEST_VAL;
492 int err, matches, limit;
493
494 matches = 0;
495 for (limit = 0; limit < SELFTEST_LOOPS_MAX; limit++) {
496 matches += n2rng_test_buffer_find(np, val);
497 if (matches >= SELFTEST_MATCH_GOAL)
498 break;
499 val = advance_polynomial(SELFTEST_POLY, val, 1);
500 }
501
502 err = 0;
503 if (limit >= SELFTEST_LOOPS_MAX) {
504 err = -ENODEV;
505 dev_err(&np->op->dev, "Selftest failed on unit %lu\n", unit);
506 n2rng_dump_test_buffer(np);
507 } else
508 dev_info(&np->op->dev, "Selftest passed on unit %lu\n", unit);
509
510 return err;
511}
512
513static int n2rng_control_selftest(struct n2rng *np, unsigned long unit)
514{
515 int err;
516
517 np->test_control[0] = (0x2 << RNG_CTL_ASEL_SHIFT);
518 np->test_control[1] = (0x2 << RNG_CTL_ASEL_SHIFT);
519 np->test_control[2] = (0x2 << RNG_CTL_ASEL_SHIFT);
520 np->test_control[3] = ((0x2 << RNG_CTL_ASEL_SHIFT) |
521 RNG_CTL_LFSR |
522 ((SELFTEST_TICKS - 2) << RNG_CTL_WAIT_SHIFT));
523
524
525 err = n2rng_entropy_diag_read(np, unit, np->test_control,
526 HV_RNG_STATE_HEALTHCHECK,
527 np->test_buffer,
528 sizeof(np->test_buffer),
529 &np->units[unit].control[0],
530 np->hv_state);
531 if (err)
532 return err;
533
534 return n2rng_check_selftest_buffer(np, unit);
535}
536
537static int n2rng_control_check(struct n2rng *np)
538{
539 int i;
540
541 for (i = 0; i < np->num_units; i++) {
542 int err = n2rng_control_selftest(np, i);
543 if (err)
544 return err;
545 }
546 return 0;
547}
548
549/* The sanity checks passed, install the final configuration into the
550 * chip, it's ready to use.
551 */
552static int n2rng_control_configure_units(struct n2rng *np)
553{
554 int unit, err;
555
556 err = 0;
557 for (unit = 0; unit < np->num_units; unit++) {
558 struct n2rng_unit *up = &np->units[unit];
559 unsigned long ctl_ra = __pa(&up->control[0]);
560 int esrc;
561 u64 base;
562
563 base = ((np->accum_cycles << RNG_CTL_WAIT_SHIFT) |
564 (2 << RNG_CTL_ASEL_SHIFT) |
565 RNG_CTL_LFSR);
566
567 /* XXX This isn't the best. We should fetch a bunch
568 * XXX of words using each entropy source combined XXX
569 * with each VCO setting, and see which combinations
570 * XXX give the best random data.
571 */
572 for (esrc = 0; esrc < 3; esrc++)
573 up->control[esrc] = base |
574 (esrc << RNG_CTL_VCO_SHIFT) |
575 (RNG_CTL_ES1 << esrc);
576
577 up->control[3] = base |
578 (RNG_CTL_ES1 | RNG_CTL_ES2 | RNG_CTL_ES3);
579
580 err = n2rng_generic_write_control(np, ctl_ra, unit,
581 HV_RNG_STATE_CONFIGURED);
582 if (err)
583 break;
584 }
585
586 return err;
587}
588
589static void n2rng_work(struct work_struct *work)
590{
591 struct n2rng *np = container_of(work, struct n2rng, work.work);
592 int err = 0;
593
594 if (!(np->flags & N2RNG_FLAG_CONTROL)) {
595 err = n2rng_guest_check(np);
596 } else {
597 preempt_disable();
598 err = n2rng_control_check(np);
599 preempt_enable();
600
601 if (!err)
602 err = n2rng_control_configure_units(np);
603 }
604
605 if (!err) {
606 np->flags |= N2RNG_FLAG_READY;
607 dev_info(&np->op->dev, "RNG ready\n");
608 }
609
610 if (err && !(np->flags & N2RNG_FLAG_SHUTDOWN))
611 schedule_delayed_work(&np->work, HZ * 2);
612}
613
614static void __devinit n2rng_driver_version(void)
615{
616 static int n2rng_version_printed;
617
618 if (n2rng_version_printed++ == 0)
619 pr_info("%s", version);
620}
621
622static int __devinit n2rng_probe(struct of_device *op,
623 const struct of_device_id *match)
624{
625 int victoria_falls = (match->data != NULL);
626 int err = -ENOMEM;
627 struct n2rng *np;
628
629 n2rng_driver_version();
630
631 np = kzalloc(sizeof(*np), GFP_KERNEL);
632 if (!np)
633 goto out;
634 np->op = op;
635
636 INIT_DELAYED_WORK(&np->work, n2rng_work);
637
638 if (victoria_falls)
639 np->flags |= N2RNG_FLAG_VF;
640
641 err = -ENODEV;
642 np->hvapi_major = 2;
643 if (sun4v_hvapi_register(HV_GRP_RNG,
644 np->hvapi_major,
645 &np->hvapi_minor)) {
646 np->hvapi_major = 1;
647 if (sun4v_hvapi_register(HV_GRP_RNG,
648 np->hvapi_major,
649 &np->hvapi_minor)) {
650 dev_err(&op->dev, "Cannot register suitable "
651 "HVAPI version.\n");
652 goto out_free;
653 }
654 }
655
656 if (np->flags & N2RNG_FLAG_VF) {
657 if (np->hvapi_major < 2) {
658 dev_err(&op->dev, "VF RNG requires HVAPI major "
659 "version 2 or later, got %lu\n",
660 np->hvapi_major);
661 goto out_hvapi_unregister;
662 }
663 np->num_units = of_getintprop_default(op->node,
664 "rng-#units", 0);
665 if (!np->num_units) {
666 dev_err(&op->dev, "VF RNG lacks rng-#units property\n");
667 goto out_hvapi_unregister;
668 }
669 } else
670 np->num_units = 1;
671
672 dev_info(&op->dev, "Registered RNG HVAPI major %lu minor %lu\n",
673 np->hvapi_major, np->hvapi_minor);
674
675 np->units = kzalloc(sizeof(struct n2rng_unit) * np->num_units,
676 GFP_KERNEL);
677 err = -ENOMEM;
678 if (!np->units)
679 goto out_hvapi_unregister;
680
681 err = n2rng_init_control(np);
682 if (err)
683 goto out_free_units;
684
685 dev_info(&op->dev, "Found %s RNG, units: %d\n",
686 ((np->flags & N2RNG_FLAG_VF) ?
687 "Victoria Falls" : "Niagara2"),
688 np->num_units);
689
690 np->hwrng.name = "n2rng";
691 np->hwrng.data_read = n2rng_data_read;
692 np->hwrng.priv = (unsigned long) np;
693
694 err = hwrng_register(&np->hwrng);
695 if (err)
696 goto out_free_units;
697
698 dev_set_drvdata(&op->dev, np);
699
700 schedule_delayed_work(&np->work, 0);
701
702 return 0;
703
704out_free_units:
705 kfree(np->units);
706 np->units = NULL;
707
708out_hvapi_unregister:
709 sun4v_hvapi_unregister(HV_GRP_RNG);
710
711out_free:
712 kfree(np);
713out:
714 return err;
715}
716
717static int __devexit n2rng_remove(struct of_device *op)
718{
719 struct n2rng *np = dev_get_drvdata(&op->dev);
720
721 np->flags |= N2RNG_FLAG_SHUTDOWN;
722
723 cancel_delayed_work_sync(&np->work);
724
725 hwrng_unregister(&np->hwrng);
726
727 sun4v_hvapi_unregister(HV_GRP_RNG);
728
729 kfree(np->units);
730 np->units = NULL;
731
732 kfree(np);
733
734 dev_set_drvdata(&op->dev, NULL);
735
736 return 0;
737}
738
739static struct of_device_id n2rng_match[] = {
740 {
741 .name = "random-number-generator",
742 .compatible = "SUNW,n2-rng",
743 },
744 {
745 .name = "random-number-generator",
746 .compatible = "SUNW,vf-rng",
747 .data = (void *) 1,
748 },
749 {},
750};
751MODULE_DEVICE_TABLE(of, n2rng_match);
752
753static struct of_platform_driver n2rng_driver = {
754 .name = "n2rng",
755 .match_table = n2rng_match,
756 .probe = n2rng_probe,
757 .remove = __devexit_p(n2rng_remove),
758};
759
760static int __init n2rng_init(void)
761{
762 return of_register_driver(&n2rng_driver, &of_bus_type);
763}
764
765static void __exit n2rng_exit(void)
766{
767 of_unregister_driver(&n2rng_driver);
768}
769
770module_init(n2rng_init);
771module_exit(n2rng_exit);
diff --git a/drivers/char/hw_random/n2rng.h b/drivers/char/hw_random/n2rng.h
new file mode 100644
index 000000000000..a2b81e7bfc18
--- /dev/null
+++ b/drivers/char/hw_random/n2rng.h
@@ -0,0 +1,118 @@
1/* n2rng.h: Niagara2 RNG defines.
2 *
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
4 */
5
6#ifndef _N2RNG_H
7#define _N2RNG_H
8
9#define RNG_CTL_WAIT 0x0000000001fffe00ULL /* Minimum wait time */
10#define RNG_CTL_WAIT_SHIFT 9
11#define RNG_CTL_BYPASS 0x0000000000000100ULL /* VCO voltage source */
12#define RNG_CTL_VCO 0x00000000000000c0ULL /* VCO rate control */
13#define RNG_CTL_VCO_SHIFT 6
14#define RNG_CTL_ASEL 0x0000000000000030ULL /* Analog MUX select */
15#define RNG_CTL_ASEL_SHIFT 4
16#define RNG_CTL_LFSR 0x0000000000000008ULL /* Use LFSR or plain shift */
17#define RNG_CTL_ES3 0x0000000000000004ULL /* Enable entropy source 3 */
18#define RNG_CTL_ES2 0x0000000000000002ULL /* Enable entropy source 2 */
19#define RNG_CTL_ES1 0x0000000000000001ULL /* Enable entropy source 1 */
20
21#define HV_FAST_RNG_GET_DIAG_CTL 0x130
22#define HV_FAST_RNG_CTL_READ 0x131
23#define HV_FAST_RNG_CTL_WRITE 0x132
24#define HV_FAST_RNG_DATA_READ_DIAG 0x133
25#define HV_FAST_RNG_DATA_READ 0x134
26
27#define HV_RNG_STATE_UNCONFIGURED 0
28#define HV_RNG_STATE_CONFIGURED 1
29#define HV_RNG_STATE_HEALTHCHECK 2
30#define HV_RNG_STATE_ERROR 3
31
32#define HV_RNG_NUM_CONTROL 4
33
34#ifndef __ASSEMBLY__
35extern unsigned long sun4v_rng_get_diag_ctl(void);
36extern unsigned long sun4v_rng_ctl_read_v1(unsigned long ctl_regs_ra,
37 unsigned long *state,
38 unsigned long *tick_delta);
39extern unsigned long sun4v_rng_ctl_read_v2(unsigned long ctl_regs_ra,
40 unsigned long unit,
41 unsigned long *state,
42 unsigned long *tick_delta,
43 unsigned long *watchdog,
44 unsigned long *write_status);
45extern unsigned long sun4v_rng_ctl_write_v1(unsigned long ctl_regs_ra,
46 unsigned long state,
47 unsigned long write_timeout,
48 unsigned long *tick_delta);
49extern unsigned long sun4v_rng_ctl_write_v2(unsigned long ctl_regs_ra,
50 unsigned long state,
51 unsigned long write_timeout,
52 unsigned long unit);
53extern unsigned long sun4v_rng_data_read_diag_v1(unsigned long data_ra,
54 unsigned long len,
55 unsigned long *tick_delta);
56extern unsigned long sun4v_rng_data_read_diag_v2(unsigned long data_ra,
57 unsigned long len,
58 unsigned long unit,
59 unsigned long *tick_delta);
60extern unsigned long sun4v_rng_data_read(unsigned long data_ra,
61 unsigned long *tick_delta);
62
63struct n2rng_unit {
64 u64 control[HV_RNG_NUM_CONTROL];
65};
66
67struct n2rng {
68 struct of_device *op;
69
70 unsigned long flags;
71#define N2RNG_FLAG_VF 0x00000001 /* Victoria Falls RNG, else N2 */
72#define N2RNG_FLAG_CONTROL 0x00000002 /* Operating in control domain */
73#define N2RNG_FLAG_READY 0x00000008 /* Ready for hw-rng layer */
74#define N2RNG_FLAG_SHUTDOWN 0x00000010 /* Driver unregistering */
75#define N2RNG_FLAG_BUFFER_VALID 0x00000020 /* u32 buffer holds valid data */
76
77 int num_units;
78 struct n2rng_unit *units;
79
80 struct hwrng hwrng;
81 u32 buffer;
82
83 /* Registered hypervisor group API major and minor version. */
84 unsigned long hvapi_major;
85 unsigned long hvapi_minor;
86
87 struct delayed_work work;
88
89 unsigned long hv_state; /* HV_RNG_STATE_foo */
90
91 unsigned long health_check_sec;
92 unsigned long accum_cycles;
93 unsigned long wd_timeo;
94#define N2RNG_HEALTH_CHECK_SEC_DEFAULT 0
95#define N2RNG_ACCUM_CYCLES_DEFAULT 2048
96#define N2RNG_WD_TIMEO_DEFAULT 0
97
98 u64 scratch_control[HV_RNG_NUM_CONTROL];
99
100#define SELFTEST_TICKS 38859
101#define SELFTEST_VAL ((u64)0xB8820C7BD387E32C)
102#define SELFTEST_POLY ((u64)0x231DCEE91262B8A3)
103#define SELFTEST_MATCH_GOAL 6
104#define SELFTEST_LOOPS_MAX 40000
105#define SELFTEST_BUFFER_WORDS 8
106
107 u64 test_data;
108 u64 test_control[HV_RNG_NUM_CONTROL];
109 u64 test_buffer[SELFTEST_BUFFER_WORDS];
110};
111
112#define N2RNG_BLOCK_LIMIT 60000
113#define N2RNG_BUSY_LIMIT 100
114#define N2RNG_HCHECK_LIMIT 100
115
116#endif /* !(__ASSEMBLY__) */
117
118#endif /* _N2RNG_H */
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 5dc74404058f..9cb48fcd316c 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -718,12 +718,12 @@ ip2_loadmain(int *iop, int *irqp)
718 } 718 }
719 719
720 if ( NULL != ( pB = i2BoardPtrTable[i] ) ) { 720 if ( NULL != ( pB = i2BoardPtrTable[i] ) ) {
721 device_create(ip2_class, NULL, 721 device_create_drvdata(ip2_class, NULL,
722 MKDEV(IP2_IPL_MAJOR, 4 * i), 722 MKDEV(IP2_IPL_MAJOR, 4 * i),
723 "ipl%d", i); 723 NULL, "ipl%d", i);
724 device_create(ip2_class, NULL, 724 device_create_drvdata(ip2_class, NULL,
725 MKDEV(IP2_IPL_MAJOR, 4 * i + 1), 725 MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
726 "stat%d", i); 726 NULL, "stat%d", i);
727 727
728 for ( box = 0; box < ABS_MAX_BOXES; ++box ) 728 for ( box = 0; box < ABS_MAX_BOXES; ++box )
729 { 729 {
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index c11a40483459..64e1c169e826 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -871,7 +871,7 @@ static void ipmi_new_smi(int if_num, struct device *device)
871 entry->dev = dev; 871 entry->dev = dev;
872 872
873 mutex_lock(&reg_list_mutex); 873 mutex_lock(&reg_list_mutex);
874 device_create(ipmi_class, device, dev, "ipmi%d", if_num); 874 device_create_drvdata(ipmi_class, device, dev, NULL, "ipmi%d", if_num);
875 list_add(&entry->link, &reg_list); 875 list_add(&entry->link, &reg_list);
876 mutex_unlock(&reg_list_mutex); 876 mutex_unlock(&reg_list_mutex);
877} 877}
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index d4281df10c22..8f7cc190b62d 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -1181,14 +1181,17 @@ static int isicom_chars_in_buffer(struct tty_struct *tty)
1181} 1181}
1182 1182
1183/* ioctl et all */ 1183/* ioctl et all */
1184static inline void isicom_send_break(struct isi_port *port, 1184static int isicom_send_break(struct tty_struct *tty, int length)
1185 unsigned long length)
1186{ 1185{
1186 struct isi_port *port = tty->driver_data;
1187 struct isi_board *card = port->card; 1187 struct isi_board *card = port->card;
1188 unsigned long base = card->base; 1188 unsigned long base = card->base;
1189 1189
1190 if (length == -1)
1191 return -EOPNOTSUPP;
1192
1190 if (!lock_card(card)) 1193 if (!lock_card(card))
1191 return; 1194 return -EINVAL;
1192 1195
1193 outw(0x8000 | ((port->channel) << (card->shift_count)) | 0x3, base); 1196 outw(0x8000 | ((port->channel) << (card->shift_count)) | 0x3, base);
1194 outw((length & 0xff) << 8 | 0x00, base); 1197 outw((length & 0xff) << 8 | 0x00, base);
@@ -1196,6 +1199,7 @@ static inline void isicom_send_break(struct isi_port *port,
1196 InterruptTheCard(base); 1199 InterruptTheCard(base);
1197 1200
1198 unlock_card(card); 1201 unlock_card(card);
1202 return 0;
1199} 1203}
1200 1204
1201static int isicom_tiocmget(struct tty_struct *tty, struct file *file) 1205static int isicom_tiocmget(struct tty_struct *tty, struct file *file)
@@ -1305,28 +1309,11 @@ static int isicom_ioctl(struct tty_struct *tty, struct file *filp,
1305{ 1309{
1306 struct isi_port *port = tty->driver_data; 1310 struct isi_port *port = tty->driver_data;
1307 void __user *argp = (void __user *)arg; 1311 void __user *argp = (void __user *)arg;
1308 int retval;
1309 1312
1310 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) 1313 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
1311 return -ENODEV; 1314 return -ENODEV;
1312 1315
1313 switch (cmd) { 1316 switch (cmd) {
1314 case TCSBRK:
1315 retval = tty_check_change(tty);
1316 if (retval)
1317 return retval;
1318 tty_wait_until_sent(tty, 0);
1319 if (!arg)
1320 isicom_send_break(port, HZ/4);
1321 return 0;
1322
1323 case TCSBRKP:
1324 retval = tty_check_change(tty);
1325 if (retval)
1326 return retval;
1327 tty_wait_until_sent(tty, 0);
1328 isicom_send_break(port, arg ? arg * (HZ/10) : HZ/4);
1329 return 0;
1330 case TIOCGSERIAL: 1317 case TIOCGSERIAL:
1331 return isicom_get_serial_info(port, argp); 1318 return isicom_get_serial_info(port, argp);
1332 1319
@@ -1459,6 +1446,7 @@ static const struct tty_operations isicom_ops = {
1459 .flush_buffer = isicom_flush_buffer, 1446 .flush_buffer = isicom_flush_buffer,
1460 .tiocmget = isicom_tiocmget, 1447 .tiocmget = isicom_tiocmget,
1461 .tiocmset = isicom_tiocmset, 1448 .tiocmset = isicom_tiocmset,
1449 .break_ctl = isicom_send_break,
1462}; 1450};
1463 1451
1464static int __devinit reset_card(struct pci_dev *pdev, 1452static int __devinit reset_card(struct pci_dev *pdev,
@@ -1832,7 +1820,7 @@ static int __init isicom_init(void)
1832 isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | 1820 isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
1833 CLOCAL; 1821 CLOCAL;
1834 isicom_normal->flags = TTY_DRIVER_REAL_RAW | 1822 isicom_normal->flags = TTY_DRIVER_REAL_RAW |
1835 TTY_DRIVER_DYNAMIC_DEV; 1823 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK;
1836 tty_set_operations(isicom_normal, &isicom_ops); 1824 tty_set_operations(isicom_normal, &isicom_ops);
1837 1825
1838 retval = tty_register_driver(isicom_normal); 1826 retval = tty_register_driver(isicom_normal);
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 6ef1c565705c..843a2afaf204 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -598,7 +598,7 @@ static int stli_parsebrd(struct stlconf *confp, char **argp);
598static int stli_open(struct tty_struct *tty, struct file *filp); 598static int stli_open(struct tty_struct *tty, struct file *filp);
599static void stli_close(struct tty_struct *tty, struct file *filp); 599static void stli_close(struct tty_struct *tty, struct file *filp);
600static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count); 600static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
601static void stli_putchar(struct tty_struct *tty, unsigned char ch); 601static int stli_putchar(struct tty_struct *tty, unsigned char ch);
602static void stli_flushchars(struct tty_struct *tty); 602static void stli_flushchars(struct tty_struct *tty);
603static int stli_writeroom(struct tty_struct *tty); 603static int stli_writeroom(struct tty_struct *tty);
604static int stli_charsinbuffer(struct tty_struct *tty); 604static int stli_charsinbuffer(struct tty_struct *tty);
@@ -609,7 +609,7 @@ static void stli_unthrottle(struct tty_struct *tty);
609static void stli_stop(struct tty_struct *tty); 609static void stli_stop(struct tty_struct *tty);
610static void stli_start(struct tty_struct *tty); 610static void stli_start(struct tty_struct *tty);
611static void stli_flushbuffer(struct tty_struct *tty); 611static void stli_flushbuffer(struct tty_struct *tty);
612static void stli_breakctl(struct tty_struct *tty, int state); 612static int stli_breakctl(struct tty_struct *tty, int state);
613static void stli_waituntilsent(struct tty_struct *tty, int timeout); 613static void stli_waituntilsent(struct tty_struct *tty, int timeout);
614static void stli_sendxchar(struct tty_struct *tty, char ch); 614static void stli_sendxchar(struct tty_struct *tty, char ch);
615static void stli_hangup(struct tty_struct *tty); 615static void stli_hangup(struct tty_struct *tty);
@@ -826,7 +826,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
826 */ 826 */
827 portp->port.tty = tty; 827 portp->port.tty = tty;
828 tty->driver_data = portp; 828 tty->driver_data = portp;
829 portp->refcount++; 829 portp->port.count++;
830 830
831 wait_event_interruptible(portp->raw_wait, 831 wait_event_interruptible(portp->raw_wait,
832 !test_bit(ST_INITIALIZING, &portp->state)); 832 !test_bit(ST_INITIALIZING, &portp->state));
@@ -888,9 +888,9 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
888 spin_unlock_irqrestore(&stli_lock, flags); 888 spin_unlock_irqrestore(&stli_lock, flags);
889 return; 889 return;
890 } 890 }
891 if ((tty->count == 1) && (portp->refcount != 1)) 891 if ((tty->count == 1) && (portp->port.count != 1))
892 portp->refcount = 1; 892 portp->port.count = 1;
893 if (portp->refcount-- > 1) { 893 if (portp->port.count-- > 1) {
894 spin_unlock_irqrestore(&stli_lock, flags); 894 spin_unlock_irqrestore(&stli_lock, flags);
895 return; 895 return;
896 } 896 }
@@ -925,8 +925,7 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
925 clear_bit(ST_TXBUSY, &portp->state); 925 clear_bit(ST_TXBUSY, &portp->state);
926 clear_bit(ST_RXSTOP, &portp->state); 926 clear_bit(ST_RXSTOP, &portp->state);
927 set_bit(TTY_IO_ERROR, &tty->flags); 927 set_bit(TTY_IO_ERROR, &tty->flags);
928 if (tty->ldisc.flush_buffer) 928 tty_ldisc_flush(tty);
929 (tty->ldisc.flush_buffer)(tty);
930 set_bit(ST_DOFLUSHRX, &portp->state); 929 set_bit(ST_DOFLUSHRX, &portp->state);
931 stli_flushbuffer(tty); 930 stli_flushbuffer(tty);
932 931
@@ -1202,7 +1201,7 @@ static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct
1202 spin_lock_irqsave(&stli_lock, flags); 1201 spin_lock_irqsave(&stli_lock, flags);
1203 portp->openwaitcnt++; 1202 portp->openwaitcnt++;
1204 if (! tty_hung_up_p(filp)) 1203 if (! tty_hung_up_p(filp))
1205 portp->refcount--; 1204 portp->port.count--;
1206 spin_unlock_irqrestore(&stli_lock, flags); 1205 spin_unlock_irqrestore(&stli_lock, flags);
1207 1206
1208 for (;;) { 1207 for (;;) {
@@ -1231,7 +1230,7 @@ static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct
1231 1230
1232 spin_lock_irqsave(&stli_lock, flags); 1231 spin_lock_irqsave(&stli_lock, flags);
1233 if (! tty_hung_up_p(filp)) 1232 if (! tty_hung_up_p(filp))
1234 portp->refcount++; 1233 portp->port.count++;
1235 portp->openwaitcnt--; 1234 portp->openwaitcnt--;
1236 spin_unlock_irqrestore(&stli_lock, flags); 1235 spin_unlock_irqrestore(&stli_lock, flags);
1237 1236
@@ -1333,7 +1332,7 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1333 * first them do the new ports. 1332 * first them do the new ports.
1334 */ 1333 */
1335 1334
1336static void stli_putchar(struct tty_struct *tty, unsigned char ch) 1335static int stli_putchar(struct tty_struct *tty, unsigned char ch)
1337{ 1336{
1338 if (tty != stli_txcooktty) { 1337 if (tty != stli_txcooktty) {
1339 if (stli_txcooktty != NULL) 1338 if (stli_txcooktty != NULL)
@@ -1342,6 +1341,7 @@ static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1342 } 1341 }
1343 1342
1344 stli_txcookbuf[stli_txcooksize++] = ch; 1343 stli_txcookbuf[stli_txcooksize++] = ch;
1344 return 0;
1345} 1345}
1346 1346
1347/*****************************************************************************/ 1347/*****************************************************************************/
@@ -1660,7 +1660,6 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
1660{ 1660{
1661 struct stliport *portp; 1661 struct stliport *portp;
1662 struct stlibrd *brdp; 1662 struct stlibrd *brdp;
1663 unsigned int ival;
1664 int rc; 1663 int rc;
1665 void __user *argp = (void __user *)arg; 1664 void __user *argp = (void __user *)arg;
1666 1665
@@ -1857,7 +1856,7 @@ static void stli_hangup(struct tty_struct *tty)
1857 set_bit(TTY_IO_ERROR, &tty->flags); 1856 set_bit(TTY_IO_ERROR, &tty->flags);
1858 portp->port.tty = NULL; 1857 portp->port.tty = NULL;
1859 portp->port.flags &= ~ASYNC_NORMAL_ACTIVE; 1858 portp->port.flags &= ~ASYNC_NORMAL_ACTIVE;
1860 portp->refcount = 0; 1859 portp->port.count = 0;
1861 spin_unlock_irqrestore(&stli_lock, flags); 1860 spin_unlock_irqrestore(&stli_lock, flags);
1862 1861
1863 wake_up_interruptible(&portp->port.open_wait); 1862 wake_up_interruptible(&portp->port.open_wait);
@@ -1909,7 +1908,7 @@ static void stli_flushbuffer(struct tty_struct *tty)
1909 1908
1910/*****************************************************************************/ 1909/*****************************************************************************/
1911 1910
1912static void stli_breakctl(struct tty_struct *tty, int state) 1911static int stli_breakctl(struct tty_struct *tty, int state)
1913{ 1912{
1914 struct stlibrd *brdp; 1913 struct stlibrd *brdp;
1915 struct stliport *portp; 1914 struct stliport *portp;
@@ -1917,15 +1916,16 @@ static void stli_breakctl(struct tty_struct *tty, int state)
1917 1916
1918 portp = tty->driver_data; 1917 portp = tty->driver_data;
1919 if (portp == NULL) 1918 if (portp == NULL)
1920 return; 1919 return -EINVAL;
1921 if (portp->brdnr >= stli_nrbrds) 1920 if (portp->brdnr >= stli_nrbrds)
1922 return; 1921 return -EINVAL;
1923 brdp = stli_brds[portp->brdnr]; 1922 brdp = stli_brds[portp->brdnr];
1924 if (brdp == NULL) 1923 if (brdp == NULL)
1925 return; 1924 return -EINVAL;
1926 1925
1927 arg = (state == -1) ? BREAKON : BREAKOFF; 1926 arg = (state == -1) ? BREAKON : BREAKOFF;
1928 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0); 1927 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
1928 return 0;
1929} 1929}
1930 1930
1931/*****************************************************************************/ 1931/*****************************************************************************/
@@ -4246,7 +4246,7 @@ static int stli_portcmdstats(struct stliport *portp)
4246 stli_comstats.panel = portp->panelnr; 4246 stli_comstats.panel = portp->panelnr;
4247 stli_comstats.port = portp->portnr; 4247 stli_comstats.port = portp->portnr;
4248 stli_comstats.state = portp->state; 4248 stli_comstats.state = portp->state;
4249 stli_comstats.flags = portp->port.flag; 4249 stli_comstats.flags = portp->port.flags;
4250 4250
4251 spin_lock_irqsave(&brd_lock, flags); 4251 spin_lock_irqsave(&brd_lock, flags);
4252 if (portp->port.tty != NULL) { 4252 if (portp->port.tty != NULL) {
@@ -4599,8 +4599,9 @@ static int __init istallion_module_init(void)
4599 4599
4600 istallion_class = class_create(THIS_MODULE, "staliomem"); 4600 istallion_class = class_create(THIS_MODULE, "staliomem");
4601 for (i = 0; i < 4; i++) 4601 for (i = 0; i < 4; i++)
4602 device_create(istallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i), 4602 device_create_drvdata(istallion_class, NULL,
4603 "staliomem%d", i); 4603 MKDEV(STL_SIOMEMMAJOR, i),
4604 NULL, "staliomem%d", i);
4604 4605
4605 return 0; 4606 return 0;
4606err_deinit: 4607err_deinit:
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index d9a0a53c842d..7b3a212c86b1 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -46,6 +46,8 @@
46 46
47extern void ctrl_alt_del(void); 47extern void ctrl_alt_del(void);
48 48
49#define to_handle_h(n) container_of(n, struct input_handle, h_node)
50
49/* 51/*
50 * Exported functions/variables 52 * Exported functions/variables
51 */ 53 */
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 71abb4c33aa2..3f2719b9f77b 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -813,7 +813,8 @@ static int lp_register(int nr, struct parport *port)
813 if (reset) 813 if (reset)
814 lp_reset(nr); 814 lp_reset(nr);
815 815
816 device_create(lp_class, port->dev, MKDEV(LP_MAJOR, nr), "lp%d", nr); 816 device_create_drvdata(lp_class, port->dev, MKDEV(LP_MAJOR, nr), NULL,
817 "lp%d", nr);
817 818
818 printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name, 819 printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name,
819 (port->irq == PARPORT_IRQ_NONE)?"polling":"interrupt-driven"); 820 (port->irq == PARPORT_IRQ_NONE)?"polling":"interrupt-driven");
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index b6772d657547..c2dba82eb5f7 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -989,9 +989,9 @@ static int __init chr_dev_init(void)
989 989
990 mem_class = class_create(THIS_MODULE, "mem"); 990 mem_class = class_create(THIS_MODULE, "mem");
991 for (i = 0; i < ARRAY_SIZE(devlist); i++) 991 for (i = 0; i < ARRAY_SIZE(devlist); i++)
992 device_create(mem_class, NULL, 992 device_create_drvdata(mem_class, NULL,
993 MKDEV(MEM_MAJOR, devlist[i].minor), 993 MKDEV(MEM_MAJOR, devlist[i].minor),
994 devlist[i].name); 994 NULL, devlist[i].name);
995 995
996 return 0; 996 return 0;
997} 997}
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 6e1563c3d30a..999aa779c08a 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -217,8 +217,8 @@ int misc_register(struct miscdevice * misc)
217 misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7); 217 misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
218 dev = MKDEV(MISC_MAJOR, misc->minor); 218 dev = MKDEV(MISC_MAJOR, misc->minor);
219 219
220 misc->this_device = device_create(misc_class, misc->parent, dev, 220 misc->this_device = device_create_drvdata(misc_class, misc->parent,
221 "%s", misc->name); 221 dev, NULL, "%s", misc->name);
222 if (IS_ERR(misc->this_device)) { 222 if (IS_ERR(misc->this_device)) {
223 err = PTR_ERR(misc->this_device); 223 err = PTR_ERR(misc->this_device);
224 goto out; 224 goto out;
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 192961fd7173..918711aa56f3 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -32,6 +32,7 @@
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/time.h> 33#include <linux/time.h>
34#include <linux/math64.h> 34#include <linux/math64.h>
35#include <linux/smp_lock.h>
35 36
36#include <asm/uaccess.h> 37#include <asm/uaccess.h>
37#include <asm/sn/addrs.h> 38#include <asm/sn/addrs.h>
@@ -57,8 +58,8 @@ extern unsigned long sn_rtc_cycles_per_second;
57 58
58#define rtc_time() (*RTC_COUNTER_ADDR) 59#define rtc_time() (*RTC_COUNTER_ADDR)
59 60
60static int mmtimer_ioctl(struct inode *inode, struct file *file, 61static long mmtimer_ioctl(struct file *file, unsigned int cmd,
61 unsigned int cmd, unsigned long arg); 62 unsigned long arg);
62static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma); 63static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma);
63 64
64/* 65/*
@@ -67,9 +68,9 @@ static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma);
67static unsigned long mmtimer_femtoperiod = 0; 68static unsigned long mmtimer_femtoperiod = 0;
68 69
69static const struct file_operations mmtimer_fops = { 70static const struct file_operations mmtimer_fops = {
70 .owner = THIS_MODULE, 71 .owner = THIS_MODULE,
71 .mmap = mmtimer_mmap, 72 .mmap = mmtimer_mmap,
72 .ioctl = mmtimer_ioctl, 73 .unlocked_ioctl = mmtimer_ioctl,
73}; 74};
74 75
75/* 76/*
@@ -339,7 +340,6 @@ restart:
339 340
340/** 341/**
341 * mmtimer_ioctl - ioctl interface for /dev/mmtimer 342 * mmtimer_ioctl - ioctl interface for /dev/mmtimer
342 * @inode: inode of the device
343 * @file: file structure for the device 343 * @file: file structure for the device
344 * @cmd: command to execute 344 * @cmd: command to execute
345 * @arg: optional argument to command 345 * @arg: optional argument to command
@@ -365,11 +365,13 @@ restart:
365 * %MMTIMER_GETCOUNTER - Gets the current value in the counter and places it 365 * %MMTIMER_GETCOUNTER - Gets the current value in the counter and places it
366 * in the address specified by @arg. 366 * in the address specified by @arg.
367 */ 367 */
368static int mmtimer_ioctl(struct inode *inode, struct file *file, 368static long mmtimer_ioctl(struct file *file, unsigned int cmd,
369 unsigned int cmd, unsigned long arg) 369 unsigned long arg)
370{ 370{
371 int ret = 0; 371 int ret = 0;
372 372
373 lock_kernel();
374
373 switch (cmd) { 375 switch (cmd) {
374 case MMTIMER_GETOFFSET: /* offset of the counter */ 376 case MMTIMER_GETOFFSET: /* offset of the counter */
375 /* 377 /*
@@ -384,15 +386,14 @@ static int mmtimer_ioctl(struct inode *inode, struct file *file,
384 case MMTIMER_GETRES: /* resolution of the clock in 10^-15 s */ 386 case MMTIMER_GETRES: /* resolution of the clock in 10^-15 s */
385 if(copy_to_user((unsigned long __user *)arg, 387 if(copy_to_user((unsigned long __user *)arg,
386 &mmtimer_femtoperiod, sizeof(unsigned long))) 388 &mmtimer_femtoperiod, sizeof(unsigned long)))
387 return -EFAULT; 389 ret = -EFAULT;
388 break; 390 break;
389 391
390 case MMTIMER_GETFREQ: /* frequency in Hz */ 392 case MMTIMER_GETFREQ: /* frequency in Hz */
391 if(copy_to_user((unsigned long __user *)arg, 393 if(copy_to_user((unsigned long __user *)arg,
392 &sn_rtc_cycles_per_second, 394 &sn_rtc_cycles_per_second,
393 sizeof(unsigned long))) 395 sizeof(unsigned long)))
394 return -EFAULT; 396 ret = -EFAULT;
395 ret = 0;
396 break; 397 break;
397 398
398 case MMTIMER_GETBITS: /* number of bits in the clock */ 399 case MMTIMER_GETBITS: /* number of bits in the clock */
@@ -406,13 +407,13 @@ static int mmtimer_ioctl(struct inode *inode, struct file *file,
406 case MMTIMER_GETCOUNTER: 407 case MMTIMER_GETCOUNTER:
407 if(copy_to_user((unsigned long __user *)arg, 408 if(copy_to_user((unsigned long __user *)arg,
408 RTC_COUNTER_ADDR, sizeof(unsigned long))) 409 RTC_COUNTER_ADDR, sizeof(unsigned long)))
409 return -EFAULT; 410 ret = -EFAULT;
410 break; 411 break;
411 default: 412 default:
412 ret = -ENOSYS; 413 ret = -ENOTTY;
413 break; 414 break;
414 } 415 }
415 416 unlock_kernel();
416 return ret; 417 return ret;
417} 418}
418 419
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 2bba250ffc8e..d3d7864e0c1e 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -374,12 +374,13 @@ copy:
374 return ret; 374 return ret;
375} 375}
376 376
377static void moxa_break_ctl(struct tty_struct *tty, int state) 377static int moxa_break_ctl(struct tty_struct *tty, int state)
378{ 378{
379 struct moxa_port *port = tty->driver_data; 379 struct moxa_port *port = tty->driver_data;
380 380
381 moxafunc(port->tableAddr, state ? FC_SendBreak : FC_StopBreak, 381 moxafunc(port->tableAddr, state ? FC_SendBreak : FC_StopBreak,
382 Magic_code); 382 Magic_code);
383 return 0;
383} 384}
384 385
385static const struct tty_operations moxa_ops = { 386static const struct tty_operations moxa_ops = {
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 6307e301bd26..4c756bbba948 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -47,7 +47,7 @@
47 47
48#include "mxser.h" 48#include "mxser.h"
49 49
50#define MXSER_VERSION "2.0.3" /* 1.11 */ 50#define MXSER_VERSION "2.0.4" /* 1.12 */
51#define MXSERMAJOR 174 51#define MXSERMAJOR 174
52#define MXSERCUMAJOR 175 52#define MXSERCUMAJOR 175
53 53
@@ -71,12 +71,13 @@
71#define UART_MCR_AFE 0x20 71#define UART_MCR_AFE 0x20
72#define UART_LSR_SPECIAL 0x1E 72#define UART_LSR_SPECIAL 0x1E
73 73
74#define PCI_DEVICE_ID_POS104UL 0x1044
74#define PCI_DEVICE_ID_CB108 0x1080 75#define PCI_DEVICE_ID_CB108 0x1080
76#define PCI_DEVICE_ID_CP102UF 0x1023
75#define PCI_DEVICE_ID_CB114 0x1142 77#define PCI_DEVICE_ID_CB114 0x1142
76#define PCI_DEVICE_ID_CP114UL 0x1143 78#define PCI_DEVICE_ID_CP114UL 0x1143
77#define PCI_DEVICE_ID_CB134I 0x1341 79#define PCI_DEVICE_ID_CB134I 0x1341
78#define PCI_DEVICE_ID_CP138U 0x1380 80#define PCI_DEVICE_ID_CP138U 0x1380
79#define PCI_DEVICE_ID_POS104UL 0x1044
80 81
81 82
82#define C168_ASIC_ID 1 83#define C168_ASIC_ID 1
@@ -142,7 +143,8 @@ static const struct mxser_cardinfo mxser_cards[] = {
142 { "CB-134I series", 4, }, 143 { "CB-134I series", 4, },
143 { "CP-138U series", 8, }, 144 { "CP-138U series", 8, },
144 { "POS-104UL series", 4, }, 145 { "POS-104UL series", 4, },
145 { "CP-114UL series", 4, } 146 { "CP-114UL series", 4, },
147/*30*/ { "CP-102UF series", 2, }
146}; 148};
147 149
148/* driver_data correspond to the lines in the structure above 150/* driver_data correspond to the lines in the structure above
@@ -172,6 +174,7 @@ static struct pci_device_id mxser_pcibrds[] = {
172 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U), .driver_data = 27 }, 174 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U), .driver_data = 27 },
173 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_POS104UL), .driver_data = 28 }, 175 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_POS104UL), .driver_data = 28 },
174 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP114UL), .driver_data = 29 }, 176 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP114UL), .driver_data = 29 },
177 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP102UF), .driver_data = 30 },
175 { } 178 { }
176}; 179};
177MODULE_DEVICE_TABLE(pci, mxser_pcibrds); 180MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
@@ -1414,7 +1417,6 @@ static int mxser_set_serial_info(struct mxser_port *info,
1414 info->port.closing_wait = new_serial.closing_wait * HZ / 100; 1417 info->port.closing_wait = new_serial.closing_wait * HZ / 100;
1415 info->port.tty->low_latency = 1418 info->port.tty->low_latency =
1416 (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1419 (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1417 info->port.tty->low_latency = 0;
1418 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST && 1420 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST &&
1419 (new_serial.baud_base != info->baud_base || 1421 (new_serial.baud_base != info->baud_base ||
1420 new_serial.custom_divisor != 1422 new_serial.custom_divisor !=
@@ -1464,27 +1466,6 @@ static int mxser_get_lsr_info(struct mxser_port *info,
1464 return put_user(result, value); 1466 return put_user(result, value);
1465} 1467}
1466 1468
1467/*
1468 * This routine sends a break character out the serial port.
1469 */
1470static void mxser_send_break(struct mxser_port *info, int duration)
1471{
1472 unsigned long flags;
1473
1474 if (!info->ioaddr)
1475 return;
1476 set_current_state(TASK_INTERRUPTIBLE);
1477 spin_lock_irqsave(&info->slock, flags);
1478 outb(inb(info->ioaddr + UART_LCR) | UART_LCR_SBC,
1479 info->ioaddr + UART_LCR);
1480 spin_unlock_irqrestore(&info->slock, flags);
1481 schedule_timeout(duration);
1482 spin_lock_irqsave(&info->slock, flags);
1483 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
1484 info->ioaddr + UART_LCR);
1485 spin_unlock_irqrestore(&info->slock, flags);
1486}
1487
1488static int mxser_tiocmget(struct tty_struct *tty, struct file *file) 1469static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
1489{ 1470{
1490 struct mxser_port *info = tty->driver_data; 1471 struct mxser_port *info = tty->driver_data;
@@ -1872,21 +1853,6 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1872 return -EIO; 1853 return -EIO;
1873 1854
1874 switch (cmd) { 1855 switch (cmd) {
1875 case TCSBRK: /* SVID version: non-zero arg --> no break */
1876 retval = tty_check_change(tty);
1877 if (retval)
1878 return retval;
1879 tty_wait_until_sent(tty, 0);
1880 if (!arg)
1881 mxser_send_break(info, HZ / 4); /* 1/4 second */
1882 return 0;
1883 case TCSBRKP: /* support for POSIX tcsendbreak() */
1884 retval = tty_check_change(tty);
1885 if (retval)
1886 return retval;
1887 tty_wait_until_sent(tty, 0);
1888 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1889 return 0;
1890 case TIOCGSERIAL: 1856 case TIOCGSERIAL:
1891 lock_kernel(); 1857 lock_kernel();
1892 retval = mxser_get_serial_info(info, argp); 1858 retval = mxser_get_serial_info(info, argp);
@@ -2219,7 +2185,7 @@ static void mxser_hangup(struct tty_struct *tty)
2219/* 2185/*
2220 * mxser_rs_break() --- routine which turns the break handling on or off 2186 * mxser_rs_break() --- routine which turns the break handling on or off
2221 */ 2187 */
2222static void mxser_rs_break(struct tty_struct *tty, int break_state) 2188static int mxser_rs_break(struct tty_struct *tty, int break_state)
2223{ 2189{
2224 struct mxser_port *info = tty->driver_data; 2190 struct mxser_port *info = tty->driver_data;
2225 unsigned long flags; 2191 unsigned long flags;
@@ -2232,6 +2198,7 @@ static void mxser_rs_break(struct tty_struct *tty, int break_state)
2232 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC, 2198 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
2233 info->ioaddr + UART_LCR); 2199 info->ioaddr + UART_LCR);
2234 spin_unlock_irqrestore(&info->slock, flags); 2200 spin_unlock_irqrestore(&info->slock, flags);
2201 return 0;
2235} 2202}
2236 2203
2237static void mxser_receive_chars(struct mxser_port *port, int *status) 2204static void mxser_receive_chars(struct mxser_port *port, int *status)
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c
index ed4e03333ab4..69ec6399c714 100644
--- a/drivers/char/n_hdlc.c
+++ b/drivers/char/n_hdlc.c
@@ -677,6 +677,10 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
677 /* Allocate transmit buffer */ 677 /* Allocate transmit buffer */
678 /* sleep until transmit buffer available */ 678 /* sleep until transmit buffer available */
679 while (!(tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list))) { 679 while (!(tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list))) {
680 if (file->f_flags & O_NONBLOCK) {
681 error = -EAGAIN;
682 break;
683 }
680 schedule(); 684 schedule();
681 685
682 n_hdlc = tty2n_hdlc (tty); 686 n_hdlc = tty2n_hdlc (tty);
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index e4a4fbd37d7a..f070ae7bd91a 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -1896,7 +1896,7 @@ static int cm4000_probe(struct pcmcia_device *link)
1896 return ret; 1896 return ret;
1897 } 1897 }
1898 1898
1899 device_create(cmm_class, NULL, MKDEV(major, i), "cmm%d", i); 1899 device_create_drvdata(cmm_class, NULL, MKDEV(major, i), NULL, "cmm%d", i);
1900 1900
1901 return 0; 1901 return 0;
1902} 1902}
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 6181f8a9b0bd..0b5934bef7a4 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -653,7 +653,8 @@ static int reader_probe(struct pcmcia_device *link)
653 return ret; 653 return ret;
654 } 654 }
655 655
656 device_create(cmx_class, NULL, MKDEV(major, i), "cmx%d", i); 656 device_create_drvdata(cmx_class, NULL, MKDEV(major, i), NULL,
657 "cmx%d", i);
657 658
658 return 0; 659 return 0;
659} 660}
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index b694d430f10e..d1fceabe3aef 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2230,7 +2230,7 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
2230 * Arguments: tty pointer to tty instance data 2230 * Arguments: tty pointer to tty instance data
2231 * break_state -1=set break condition, 0=clear 2231 * break_state -1=set break condition, 0=clear
2232 */ 2232 */
2233static void mgslpc_break(struct tty_struct *tty, int break_state) 2233static int mgslpc_break(struct tty_struct *tty, int break_state)
2234{ 2234{
2235 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data; 2235 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
2236 unsigned long flags; 2236 unsigned long flags;
@@ -2240,7 +2240,7 @@ static void mgslpc_break(struct tty_struct *tty, int break_state)
2240 __FILE__,__LINE__, info->device_name, break_state); 2240 __FILE__,__LINE__, info->device_name, break_state);
2241 2241
2242 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_break")) 2242 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_break"))
2243 return; 2243 return -EINVAL;
2244 2244
2245 spin_lock_irqsave(&info->lock,flags); 2245 spin_lock_irqsave(&info->lock,flags);
2246 if (break_state == -1) 2246 if (break_state == -1)
@@ -2248,6 +2248,7 @@ static void mgslpc_break(struct tty_struct *tty, int break_state)
2248 else 2248 else
2249 clear_reg_bits(info, CHA+DAFO, BIT6); 2249 clear_reg_bits(info, CHA+DAFO, BIT6);
2250 spin_unlock_irqrestore(&info->lock,flags); 2250 spin_unlock_irqrestore(&info->lock,flags);
2251 return 0;
2251} 2252}
2252 2253
2253/* Service an IOCTL request 2254/* Service an IOCTL request
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index f6e6acadd9a0..7af7a7e6b9c2 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -752,8 +752,9 @@ static const struct file_operations pp_fops = {
752 752
753static void pp_attach(struct parport *port) 753static void pp_attach(struct parport *port)
754{ 754{
755 device_create(ppdev_class, port->dev, MKDEV(PP_MAJOR, port->number), 755 device_create_drvdata(ppdev_class, port->dev,
756 "parport%d", port->number); 756 MKDEV(PP_MAJOR, port->number),
757 NULL, "parport%d", port->number);
757} 758}
758 759
759static void pp_detach(struct parport *port) 760static void pp_detach(struct parport *port)
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 505fcbe884a4..47b8cf281d4a 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -131,8 +131,8 @@ raw_ioctl(struct inode *inode, struct file *filp,
131static void bind_device(struct raw_config_request *rq) 131static void bind_device(struct raw_config_request *rq)
132{ 132{
133 device_destroy(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor)); 133 device_destroy(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor));
134 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, rq->raw_minor), 134 device_create_drvdata(raw_class, NULL, MKDEV(RAW_MAJOR, rq->raw_minor),
135 "raw%d", rq->raw_minor); 135 NULL, "raw%d", rq->raw_minor);
136} 136}
137 137
138/* 138/*
@@ -283,7 +283,8 @@ static int __init raw_init(void)
283 ret = PTR_ERR(raw_class); 283 ret = PTR_ERR(raw_class);
284 goto error_region; 284 goto error_region;
285 } 285 }
286 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), "rawctl"); 286 device_create_drvdata(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL,
287 "rawctl");
287 288
288 return 0; 289 return 0;
289 290
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index 724b2b20f4b2..2c6c8f33d6b4 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -1250,11 +1250,15 @@ static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1250 return 0; 1250 return 0;
1251} 1251}
1252 1252
1253static void rc_send_break(struct riscom_port *port, unsigned long length) 1253static int rc_send_break(struct tty_struct *tty, int length)
1254{ 1254{
1255 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1255 struct riscom_board *bp = port_Board(port); 1256 struct riscom_board *bp = port_Board(port);
1256 unsigned long flags; 1257 unsigned long flags;
1257 1258
1259 if (length == 0 || length == -1)
1260 return -EOPNOTSUPP;
1261
1258 spin_lock_irqsave(&riscom_lock, flags); 1262 spin_lock_irqsave(&riscom_lock, flags);
1259 1263
1260 port->break_length = RISCOM_TPS / HZ * length; 1264 port->break_length = RISCOM_TPS / HZ * length;
@@ -1268,6 +1272,7 @@ static void rc_send_break(struct riscom_port *port, unsigned long length)
1268 rc_wait_CCR(bp); 1272 rc_wait_CCR(bp);
1269 1273
1270 spin_unlock_irqrestore(&riscom_lock, flags); 1274 spin_unlock_irqrestore(&riscom_lock, flags);
1275 return 0;
1271} 1276}
1272 1277
1273static int rc_set_serial_info(struct riscom_port *port, 1278static int rc_set_serial_info(struct riscom_port *port,
@@ -1342,27 +1347,12 @@ static int rc_ioctl(struct tty_struct *tty, struct file *filp,
1342{ 1347{
1343 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1348 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1344 void __user *argp = (void __user *)arg; 1349 void __user *argp = (void __user *)arg;
1345 int retval = 0; 1350 int retval;
1346 1351
1347 if (rc_paranoia_check(port, tty->name, "rc_ioctl")) 1352 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1348 return -ENODEV; 1353 return -ENODEV;
1349 1354
1350 switch (cmd) { 1355 switch (cmd) {
1351 case TCSBRK: /* SVID version: non-zero arg --> no break */
1352 retval = tty_check_change(tty);
1353 if (retval)
1354 return retval;
1355 tty_wait_until_sent(tty, 0);
1356 if (!arg)
1357 rc_send_break(port, HZ/4); /* 1/4 second */
1358 break;
1359 case TCSBRKP: /* support for POSIX tcsendbreak() */
1360 retval = tty_check_change(tty);
1361 if (retval)
1362 return retval;
1363 tty_wait_until_sent(tty, 0);
1364 rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1365 break;
1366 case TIOCGSERIAL: 1356 case TIOCGSERIAL:
1367 lock_kernel(); 1357 lock_kernel();
1368 retval = rc_get_serial_info(port, argp); 1358 retval = rc_get_serial_info(port, argp);
@@ -1517,6 +1507,7 @@ static const struct tty_operations riscom_ops = {
1517 .hangup = rc_hangup, 1507 .hangup = rc_hangup,
1518 .tiocmget = rc_tiocmget, 1508 .tiocmget = rc_tiocmget,
1519 .tiocmset = rc_tiocmset, 1509 .tiocmset = rc_tiocmset,
1510 .break_ctl = rc_send_break,
1520}; 1511};
1521 1512
1522static int __init rc_init_drivers(void) 1513static int __init rc_init_drivers(void)
@@ -1538,7 +1529,7 @@ static int __init rc_init_drivers(void)
1538 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1529 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1539 riscom_driver->init_termios.c_ispeed = 9600; 1530 riscom_driver->init_termios.c_ispeed = 9600;
1540 riscom_driver->init_termios.c_ospeed = 9600; 1531 riscom_driver->init_termios.c_ospeed = 9600;
1541 riscom_driver->flags = TTY_DRIVER_REAL_RAW; 1532 riscom_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1542 tty_set_operations(riscom_driver, &riscom_ops); 1533 tty_set_operations(riscom_driver, &riscom_ops);
1543 error = tty_register_driver(riscom_driver); 1534 error = tty_register_driver(riscom_driver);
1544 if (error != 0) { 1535 if (error != 0) {
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index e670eae2f510..584d791e84a6 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -1236,13 +1236,13 @@ static void rp_set_termios(struct tty_struct *tty,
1236 } 1236 }
1237} 1237}
1238 1238
1239static void rp_break(struct tty_struct *tty, int break_state) 1239static int rp_break(struct tty_struct *tty, int break_state)
1240{ 1240{
1241 struct r_port *info = (struct r_port *) tty->driver_data; 1241 struct r_port *info = (struct r_port *) tty->driver_data;
1242 unsigned long flags; 1242 unsigned long flags;
1243 1243
1244 if (rocket_paranoia_check(info, "rp_break")) 1244 if (rocket_paranoia_check(info, "rp_break"))
1245 return; 1245 return -EINVAL;
1246 1246
1247 spin_lock_irqsave(&info->slock, flags); 1247 spin_lock_irqsave(&info->slock, flags);
1248 if (break_state == -1) 1248 if (break_state == -1)
@@ -1250,6 +1250,7 @@ static void rp_break(struct tty_struct *tty, int break_state)
1250 else 1250 else
1251 sClrBreak(&info->channel); 1251 sClrBreak(&info->channel);
1252 spin_unlock_irqrestore(&info->slock, flags); 1252 spin_unlock_irqrestore(&info->slock, flags);
1253 return 0;
1253} 1254}
1254 1255
1255/* 1256/*
diff --git a/drivers/char/snsc.c b/drivers/char/snsc.c
index 0b799ac1b049..3ce60df14c0a 100644
--- a/drivers/char/snsc.c
+++ b/drivers/char/snsc.c
@@ -444,7 +444,8 @@ scdrv_init(void)
444 continue; 444 continue;
445 } 445 }
446 446
447 device_create(snsc_class, NULL, dev, "%s", devname); 447 device_create_drvdata(snsc_class, NULL, dev, NULL,
448 "%s", devname);
448 449
449 ia64_sn_irtr_intr_enable(scd->scd_nasid, 450 ia64_sn_irtr_intr_enable(scd->scd_nasid,
450 0 /*ignored */ , 451 0 /*ignored */ ,
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 037dc47e4cb1..242fd46fda22 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -77,7 +77,7 @@
77 77
78#include <linux/module.h> 78#include <linux/module.h>
79 79
80#include <asm/io.h> 80#include <linux/io.h>
81#include <linux/kernel.h> 81#include <linux/kernel.h>
82#include <linux/sched.h> 82#include <linux/sched.h>
83#include <linux/ioport.h> 83#include <linux/ioport.h>
@@ -92,7 +92,7 @@
92#include <linux/delay.h> 92#include <linux/delay.h>
93#include <linux/pci.h> 93#include <linux/pci.h>
94#include <linux/init.h> 94#include <linux/init.h>
95#include <asm/uaccess.h> 95#include <linux/uaccess.h>
96 96
97#include "specialix_io8.h" 97#include "specialix_io8.h"
98#include "cd1865.h" 98#include "cd1865.h"
@@ -110,9 +110,10 @@
110 110
111static int sx_debug; 111static int sx_debug;
112static int sx_rxfifo = SPECIALIX_RXFIFO; 112static int sx_rxfifo = SPECIALIX_RXFIFO;
113static int sx_rtscts;
113 114
114#ifdef DEBUG 115#ifdef DEBUG
115#define dprintk(f, str...) if (sx_debug & f) printk (str) 116#define dprintk(f, str...) if (sx_debug & f) printk(str)
116#else 117#else
117#define dprintk(f, str...) /* nothing */ 118#define dprintk(f, str...) /* nothing */
118#endif 119#endif
@@ -131,10 +132,8 @@ static int sx_rxfifo = SPECIALIX_RXFIFO;
131#define SX_DEBUG_FIFO 0x0800 132#define SX_DEBUG_FIFO 0x0800
132 133
133 134
134#define func_enter() dprintk (SX_DEBUG_FLOW, "io8: enter %s\n",__func__) 135#define func_enter() dprintk(SX_DEBUG_FLOW, "io8: enter %s\n", __func__)
135#define func_exit() dprintk (SX_DEBUG_FLOW, "io8: exit %s\n", __func__) 136#define func_exit() dprintk(SX_DEBUG_FLOW, "io8: exit %s\n", __func__)
136
137#define jiffies_from_ms(a) ((((a) * HZ)/1000)+1)
138 137
139 138
140/* Configurable options: */ 139/* Configurable options: */
@@ -142,17 +141,6 @@ static int sx_rxfifo = SPECIALIX_RXFIFO;
142/* Am I paranoid or not ? ;-) */ 141/* Am I paranoid or not ? ;-) */
143#define SPECIALIX_PARANOIA_CHECK 142#define SPECIALIX_PARANOIA_CHECK
144 143
145/* Do I trust the IRQ from the card? (enabeling it doesn't seem to help)
146 When the IRQ routine leaves the chip in a state that is keeps on
147 requiring attention, the timer doesn't help either. */
148#undef SPECIALIX_TIMER
149
150#ifdef SPECIALIX_TIMER
151static int sx_poll = HZ;
152#endif
153
154
155
156/* 144/*
157 * The following defines are mostly for testing purposes. But if you need 145 * The following defines are mostly for testing purposes. But if you need
158 * some nice reporting in your syslog, you can define them also. 146 * some nice reporting in your syslog, you can define them also.
@@ -162,16 +150,6 @@ static int sx_poll = HZ;
162 150
163 151
164 152
165#ifdef CONFIG_SPECIALIX_RTSCTS
166#define SX_CRTSCTS(bla) 1
167#else
168#define SX_CRTSCTS(tty) C_CRTSCTS(tty)
169#endif
170
171
172/* Used to be outb (0xff, 0x80); */
173#define short_pause() udelay (1)
174
175 153
176#define SPECIALIX_LEGAL_FLAGS \ 154#define SPECIALIX_LEGAL_FLAGS \
177 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \ 155 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
@@ -190,21 +168,14 @@ static struct specialix_board sx_board[SX_NBOARD] = {
190static struct specialix_port sx_port[SX_NBOARD * SX_NPORT]; 168static struct specialix_port sx_port[SX_NBOARD * SX_NPORT];
191 169
192 170
193#ifdef SPECIALIX_TIMER 171static int sx_paranoia_check(struct specialix_port const *port,
194static struct timer_list missed_irq_timer;
195static irqreturn_t sx_interrupt(int irq, void * dev_id);
196#endif
197
198
199
200static inline int sx_paranoia_check(struct specialix_port const * port,
201 char *name, const char *routine) 172 char *name, const char *routine)
202{ 173{
203#ifdef SPECIALIX_PARANOIA_CHECK 174#ifdef SPECIALIX_PARANOIA_CHECK
204 static const char *badmagic = 175 static const char *badmagic = KERN_ERR
205 KERN_ERR "sx: Warning: bad specialix port magic number for device %s in %s\n"; 176 "sx: Warning: bad specialix port magic number for device %s in %s\n";
206 static const char *badinfo = 177 static const char *badinfo = KERN_ERR
207 KERN_ERR "sx: Warning: null specialix port for device %s in %s\n"; 178 "sx: Warning: null specialix port for device %s in %s\n";
208 179
209 if (!port) { 180 if (!port) {
210 printk(badinfo, name, routine); 181 printk(badinfo, name, routine);
@@ -226,66 +197,69 @@ static inline int sx_paranoia_check(struct specialix_port const * port,
226 */ 197 */
227 198
228/* Get board number from pointer */ 199/* Get board number from pointer */
229static inline int board_No (struct specialix_board * bp) 200static inline int board_No(struct specialix_board *bp)
230{ 201{
231 return bp - sx_board; 202 return bp - sx_board;
232} 203}
233 204
234 205
235/* Get port number from pointer */ 206/* Get port number from pointer */
236static inline int port_No (struct specialix_port const * port) 207static inline int port_No(struct specialix_port const *port)
237{ 208{
238 return SX_PORT(port - sx_port); 209 return SX_PORT(port - sx_port);
239} 210}
240 211
241 212
242/* Get pointer to board from pointer to port */ 213/* Get pointer to board from pointer to port */
243static inline struct specialix_board * port_Board(struct specialix_port const * port) 214static inline struct specialix_board *port_Board(
215 struct specialix_port const *port)
244{ 216{
245 return &sx_board[SX_BOARD(port - sx_port)]; 217 return &sx_board[SX_BOARD(port - sx_port)];
246} 218}
247 219
248 220
249/* Input Byte from CL CD186x register */ 221/* Input Byte from CL CD186x register */
250static inline unsigned char sx_in(struct specialix_board * bp, unsigned short reg) 222static inline unsigned char sx_in(struct specialix_board *bp,
223 unsigned short reg)
251{ 224{
252 bp->reg = reg | 0x80; 225 bp->reg = reg | 0x80;
253 outb (reg | 0x80, bp->base + SX_ADDR_REG); 226 outb(reg | 0x80, bp->base + SX_ADDR_REG);
254 return inb (bp->base + SX_DATA_REG); 227 return inb(bp->base + SX_DATA_REG);
255} 228}
256 229
257 230
258/* Output Byte to CL CD186x register */ 231/* Output Byte to CL CD186x register */
259static inline void sx_out(struct specialix_board * bp, unsigned short reg, 232static inline void sx_out(struct specialix_board *bp, unsigned short reg,
260 unsigned char val) 233 unsigned char val)
261{ 234{
262 bp->reg = reg | 0x80; 235 bp->reg = reg | 0x80;
263 outb (reg | 0x80, bp->base + SX_ADDR_REG); 236 outb(reg | 0x80, bp->base + SX_ADDR_REG);
264 outb (val, bp->base + SX_DATA_REG); 237 outb(val, bp->base + SX_DATA_REG);
265} 238}
266 239
267 240
268/* Input Byte from CL CD186x register */ 241/* Input Byte from CL CD186x register */
269static inline unsigned char sx_in_off(struct specialix_board * bp, unsigned short reg) 242static inline unsigned char sx_in_off(struct specialix_board *bp,
243 unsigned short reg)
270{ 244{
271 bp->reg = reg; 245 bp->reg = reg;
272 outb (reg, bp->base + SX_ADDR_REG); 246 outb(reg, bp->base + SX_ADDR_REG);
273 return inb (bp->base + SX_DATA_REG); 247 return inb(bp->base + SX_DATA_REG);
274} 248}
275 249
276 250
277/* Output Byte to CL CD186x register */ 251/* Output Byte to CL CD186x register */
278static inline void sx_out_off(struct specialix_board * bp, unsigned short reg, 252static inline void sx_out_off(struct specialix_board *bp,
279 unsigned char val) 253 unsigned short reg, unsigned char val)
280{ 254{
281 bp->reg = reg; 255 bp->reg = reg;
282 outb (reg, bp->base + SX_ADDR_REG); 256 outb(reg, bp->base + SX_ADDR_REG);
283 outb (val, bp->base + SX_DATA_REG); 257 outb(val, bp->base + SX_DATA_REG);
284} 258}
285 259
286 260
287/* Wait for Channel Command Register ready */ 261/* Wait for Channel Command Register ready */
288static inline void sx_wait_CCR(struct specialix_board * bp) 262static void sx_wait_CCR(struct specialix_board *bp)
289{ 263{
290 unsigned long delay, flags; 264 unsigned long delay, flags;
291 unsigned char ccr; 265 unsigned char ccr;
@@ -296,7 +270,7 @@ static inline void sx_wait_CCR(struct specialix_board * bp)
296 spin_unlock_irqrestore(&bp->lock, flags); 270 spin_unlock_irqrestore(&bp->lock, flags);
297 if (!ccr) 271 if (!ccr)
298 return; 272 return;
299 udelay (1); 273 udelay(1);
300 } 274 }
301 275
302 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp)); 276 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
@@ -304,7 +278,7 @@ static inline void sx_wait_CCR(struct specialix_board * bp)
304 278
305 279
306/* Wait for Channel Command Register ready */ 280/* Wait for Channel Command Register ready */
307static inline void sx_wait_CCR_off(struct specialix_board * bp) 281static void sx_wait_CCR_off(struct specialix_board *bp)
308{ 282{
309 unsigned long delay; 283 unsigned long delay;
310 unsigned char crr; 284 unsigned char crr;
@@ -316,7 +290,7 @@ static inline void sx_wait_CCR_off(struct specialix_board * bp)
316 spin_unlock_irqrestore(&bp->lock, flags); 290 spin_unlock_irqrestore(&bp->lock, flags);
317 if (!crr) 291 if (!crr)
318 return; 292 return;
319 udelay (1); 293 udelay(1);
320 } 294 }
321 295
322 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp)); 296 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
@@ -327,7 +301,7 @@ static inline void sx_wait_CCR_off(struct specialix_board * bp)
327 * specialix IO8+ IO range functions. 301 * specialix IO8+ IO range functions.
328 */ 302 */
329 303
330static inline int sx_request_io_range(struct specialix_board * bp) 304static int sx_request_io_range(struct specialix_board *bp)
331{ 305{
332 return request_region(bp->base, 306 return request_region(bp->base,
333 bp->flags & SX_BOARD_IS_PCI ? SX_PCI_IO_SPACE : SX_IO_SPACE, 307 bp->flags & SX_BOARD_IS_PCI ? SX_PCI_IO_SPACE : SX_IO_SPACE,
@@ -335,15 +309,15 @@ static inline int sx_request_io_range(struct specialix_board * bp)
335} 309}
336 310
337 311
338static inline void sx_release_io_range(struct specialix_board * bp) 312static void sx_release_io_range(struct specialix_board *bp)
339{ 313{
340 release_region(bp->base, 314 release_region(bp->base, bp->flags & SX_BOARD_IS_PCI ?
341 bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE); 315 SX_PCI_IO_SPACE : SX_IO_SPACE);
342} 316}
343 317
344 318
345/* Set the IRQ using the RTS lines that run to the PAL on the board.... */ 319/* Set the IRQ using the RTS lines that run to the PAL on the board.... */
346static int sx_set_irq ( struct specialix_board *bp) 320static int sx_set_irq(struct specialix_board *bp)
347{ 321{
348 int virq; 322 int virq;
349 int i; 323 int i;
@@ -353,15 +327,24 @@ static int sx_set_irq ( struct specialix_board *bp)
353 return 1; 327 return 1;
354 switch (bp->irq) { 328 switch (bp->irq) {
355 /* In the same order as in the docs... */ 329 /* In the same order as in the docs... */
356 case 15: virq = 0;break; 330 case 15:
357 case 12: virq = 1;break; 331 virq = 0;
358 case 11: virq = 2;break; 332 break;
359 case 9: virq = 3;break; 333 case 12:
360 default: printk (KERN_ERR "Speclialix: cannot set irq to %d.\n", bp->irq); 334 virq = 1;
361 return 0; 335 break;
336 case 11:
337 virq = 2;
338 break;
339 case 9:
340 virq = 3;
341 break;
342 default:printk(KERN_ERR
343 "Speclialix: cannot set irq to %d.\n", bp->irq);
344 return 0;
362 } 345 }
363 spin_lock_irqsave(&bp->lock, flags); 346 spin_lock_irqsave(&bp->lock, flags);
364 for (i=0;i<2;i++) { 347 for (i = 0; i < 2; i++) {
365 sx_out(bp, CD186x_CAR, i); 348 sx_out(bp, CD186x_CAR, i);
366 sx_out(bp, CD186x_MSVRTS, ((virq >> i) & 0x1)? MSVR_RTS:0); 349 sx_out(bp, CD186x_MSVRTS, ((virq >> i) & 0x1)? MSVR_RTS:0);
367 } 350 }
@@ -371,7 +354,7 @@ static int sx_set_irq ( struct specialix_board *bp)
371 354
372 355
373/* Reset and setup CD186x chip */ 356/* Reset and setup CD186x chip */
374static int sx_init_CD186x(struct specialix_board * bp) 357static int sx_init_CD186x(struct specialix_board *bp)
375{ 358{
376 unsigned long flags; 359 unsigned long flags;
377 int scaler; 360 int scaler;
@@ -390,7 +373,7 @@ static int sx_init_CD186x(struct specialix_board * bp)
390 sx_out_off(bp, CD186x_PILR2, SX_ACK_TINT); /* Prio for transmitter intr */ 373 sx_out_off(bp, CD186x_PILR2, SX_ACK_TINT); /* Prio for transmitter intr */
391 sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT); /* Prio for receiver intr */ 374 sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT); /* Prio for receiver intr */
392 /* Set RegAckEn */ 375 /* Set RegAckEn */
393 sx_out_off(bp, CD186x_SRCR, sx_in (bp, CD186x_SRCR) | SRCR_REGACKEN); 376 sx_out_off(bp, CD186x_SRCR, sx_in(bp, CD186x_SRCR) | SRCR_REGACKEN);
394 377
395 /* Setting up prescaler. We need 4 ticks per 1 ms */ 378 /* Setting up prescaler. We need 4 ticks per 1 ms */
396 scaler = SX_OSCFREQ/SPECIALIX_TPS; 379 scaler = SX_OSCFREQ/SPECIALIX_TPS;
@@ -399,9 +382,9 @@ static int sx_init_CD186x(struct specialix_board * bp)
399 sx_out_off(bp, CD186x_PPRL, scaler & 0xff); 382 sx_out_off(bp, CD186x_PPRL, scaler & 0xff);
400 spin_unlock_irqrestore(&bp->lock, flags); 383 spin_unlock_irqrestore(&bp->lock, flags);
401 384
402 if (!sx_set_irq (bp)) { 385 if (!sx_set_irq(bp)) {
403 /* Figure out how to pass this along... */ 386 /* Figure out how to pass this along... */
404 printk (KERN_ERR "Cannot set irq to %d.\n", bp->irq); 387 printk(KERN_ERR "Cannot set irq to %d.\n", bp->irq);
405 rv = 0; 388 rv = 0;
406 } 389 }
407 390
@@ -410,16 +393,16 @@ static int sx_init_CD186x(struct specialix_board * bp)
410} 393}
411 394
412 395
413static int read_cross_byte (struct specialix_board *bp, int reg, int bit) 396static int read_cross_byte(struct specialix_board *bp, int reg, int bit)
414{ 397{
415 int i; 398 int i;
416 int t; 399 int t;
417 unsigned long flags; 400 unsigned long flags;
418 401
419 spin_lock_irqsave(&bp->lock, flags); 402 spin_lock_irqsave(&bp->lock, flags);
420 for (i=0, t=0;i<8;i++) { 403 for (i = 0, t = 0; i < 8; i++) {
421 sx_out_off (bp, CD186x_CAR, i); 404 sx_out_off(bp, CD186x_CAR, i);
422 if (sx_in_off (bp, reg) & bit) 405 if (sx_in_off(bp, reg) & bit)
423 t |= 1 << i; 406 t |= 1 << i;
424 } 407 }
425 spin_unlock_irqrestore(&bp->lock, flags); 408 spin_unlock_irqrestore(&bp->lock, flags);
@@ -428,37 +411,10 @@ static int read_cross_byte (struct specialix_board *bp, int reg, int bit)
428} 411}
429 412
430 413
431#ifdef SPECIALIX_TIMER
432void missed_irq (unsigned long data)
433{
434 unsigned char irq;
435 unsigned long flags;
436 struct specialix_board *bp = (struct specialix_board *)data;
437
438 spin_lock_irqsave(&bp->lock, flags);
439 irq = sx_in ((struct specialix_board *)data, CD186x_SRSR) &
440 (SRSR_RREQint |
441 SRSR_TREQint |
442 SRSR_MREQint);
443 spin_unlock_irqrestore(&bp->lock, flags);
444 if (irq) {
445 printk (KERN_INFO "Missed interrupt... Calling int from timer. \n");
446 sx_interrupt (-1, bp);
447 }
448 mod_timer(&missed_irq_timer, jiffies + sx_poll);
449}
450#endif
451
452
453
454/* Main probing routine, also sets irq. */ 414/* Main probing routine, also sets irq. */
455static int sx_probe(struct specialix_board *bp) 415static int sx_probe(struct specialix_board *bp)
456{ 416{
457 unsigned char val1, val2; 417 unsigned char val1, val2;
458#if 0
459 int irqs = 0;
460 int retries;
461#endif
462 int rev; 418 int rev;
463 int chip; 419 int chip;
464 420
@@ -471,17 +427,18 @@ static int sx_probe(struct specialix_board *bp)
471 427
472 /* Are the I/O ports here ? */ 428 /* Are the I/O ports here ? */
473 sx_out_off(bp, CD186x_PPRL, 0x5a); 429 sx_out_off(bp, CD186x_PPRL, 0x5a);
474 short_pause (); 430 udelay(1);
475 val1 = sx_in_off(bp, CD186x_PPRL); 431 val1 = sx_in_off(bp, CD186x_PPRL);
476 432
477 sx_out_off(bp, CD186x_PPRL, 0xa5); 433 sx_out_off(bp, CD186x_PPRL, 0xa5);
478 short_pause (); 434 udelay(1);
479 val2 = sx_in_off(bp, CD186x_PPRL); 435 val2 = sx_in_off(bp, CD186x_PPRL);
480 436
481 437
482 if ((val1 != 0x5a) || (val2 != 0xa5)) { 438 if (val1 != 0x5a || val2 != 0xa5) {
483 printk(KERN_INFO "sx%d: specialix IO8+ Board at 0x%03x not found.\n", 439 printk(KERN_INFO
484 board_No(bp), bp->base); 440 "sx%d: specialix IO8+ Board at 0x%03x not found.\n",
441 board_No(bp), bp->base);
485 sx_release_io_range(bp); 442 sx_release_io_range(bp);
486 func_exit(); 443 func_exit();
487 return 1; 444 return 1;
@@ -489,10 +446,11 @@ static int sx_probe(struct specialix_board *bp)
489 446
490 /* Check the DSR lines that Specialix uses as board 447 /* Check the DSR lines that Specialix uses as board
491 identification */ 448 identification */
492 val1 = read_cross_byte (bp, CD186x_MSVR, MSVR_DSR); 449 val1 = read_cross_byte(bp, CD186x_MSVR, MSVR_DSR);
493 val2 = read_cross_byte (bp, CD186x_MSVR, MSVR_RTS); 450 val2 = read_cross_byte(bp, CD186x_MSVR, MSVR_RTS);
494 dprintk (SX_DEBUG_INIT, "sx%d: DSR lines are: %02x, rts lines are: %02x\n", 451 dprintk(SX_DEBUG_INIT,
495 board_No(bp), val1, val2); 452 "sx%d: DSR lines are: %02x, rts lines are: %02x\n",
453 board_No(bp), val1, val2);
496 454
497 /* They managed to switch the bit order between the docs and 455 /* They managed to switch the bit order between the docs and
498 the IO8+ card. The new PCI card now conforms to old docs. 456 the IO8+ card. The new PCI card now conforms to old docs.
@@ -500,7 +458,8 @@ static int sx_probe(struct specialix_board *bp)
500 old card. */ 458 old card. */
501 val2 = (bp->flags & SX_BOARD_IS_PCI)?0x4d : 0xb2; 459 val2 = (bp->flags & SX_BOARD_IS_PCI)?0x4d : 0xb2;
502 if (val1 != val2) { 460 if (val1 != val2) {
503 printk(KERN_INFO "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n", 461 printk(KERN_INFO
462 "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n",
504 board_No(bp), val2, bp->base, val1); 463 board_No(bp), val2, bp->base, val1);
505 sx_release_io_range(bp); 464 sx_release_io_range(bp);
506 func_exit(); 465 func_exit();
@@ -508,47 +467,6 @@ static int sx_probe(struct specialix_board *bp)
508 } 467 }
509 468
510 469
511#if 0
512 /* It's time to find IRQ for this board */
513 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
514 irqs = probe_irq_on();
515 sx_init_CD186x(bp); /* Reset CD186x chip */
516 sx_out(bp, CD186x_CAR, 2); /* Select port 2 */
517 sx_wait_CCR(bp);
518 sx_out(bp, CD186x_CCR, CCR_TXEN); /* Enable transmitter */
519 sx_out(bp, CD186x_IER, IER_TXRDY); /* Enable tx empty intr */
520 msleep(50);
521 irqs = probe_irq_off(irqs);
522
523 dprintk (SX_DEBUG_INIT, "SRSR = %02x, ", sx_in(bp, CD186x_SRSR));
524 dprintk (SX_DEBUG_INIT, "TRAR = %02x, ", sx_in(bp, CD186x_TRAR));
525 dprintk (SX_DEBUG_INIT, "GIVR = %02x, ", sx_in(bp, CD186x_GIVR));
526 dprintk (SX_DEBUG_INIT, "GICR = %02x, ", sx_in(bp, CD186x_GICR));
527 dprintk (SX_DEBUG_INIT, "\n");
528
529 /* Reset CD186x again */
530 if (!sx_init_CD186x(bp)) {
531 /* Hmmm. This is dead code anyway. */
532 }
533
534 dprintk (SX_DEBUG_INIT "val1 = %02x, val2 = %02x, val3 = %02x.\n",
535 val1, val2, val3);
536
537 }
538
539#if 0
540 if (irqs <= 0) {
541 printk(KERN_ERR "sx%d: Can't find IRQ for specialix IO8+ board at 0x%03x.\n",
542 board_No(bp), bp->base);
543 sx_release_io_range(bp);
544 func_exit();
545 return 1;
546 }
547#endif
548 printk (KERN_INFO "Started with irq=%d, but now have irq=%d.\n", bp->irq, irqs);
549 if (irqs > 0)
550 bp->irq = irqs;
551#endif
552 /* Reset CD186x again */ 470 /* Reset CD186x again */
553 if (!sx_init_CD186x(bp)) { 471 if (!sx_init_CD186x(bp)) {
554 sx_release_io_range(bp); 472 sx_release_io_range(bp);
@@ -560,7 +478,7 @@ static int sx_probe(struct specialix_board *bp)
560 bp->flags |= SX_BOARD_PRESENT; 478 bp->flags |= SX_BOARD_PRESENT;
561 479
562 /* Chip revcode pkgtype 480 /* Chip revcode pkgtype
563 GFRCR SRCR bit 7 481 GFRCR SRCR bit 7
564 CD180 rev B 0x81 0 482 CD180 rev B 0x81 0
565 CD180 rev C 0x82 0 483 CD180 rev C 0x82 0
566 CD1864 rev A 0x82 1 484 CD1864 rev A 0x82 1
@@ -570,24 +488,32 @@ static int sx_probe(struct specialix_board *bp)
570 */ 488 */
571 489
572 switch (sx_in_off(bp, CD186x_GFRCR)) { 490 switch (sx_in_off(bp, CD186x_GFRCR)) {
573 case 0x82:chip = 1864;rev='A';break; 491 case 0x82:
574 case 0x83:chip = 1865;rev='A';break; 492 chip = 1864;
575 case 0x84:chip = 1865;rev='B';break; 493 rev = 'A';
576 case 0x85:chip = 1865;rev='C';break; /* Does not exist at this time */ 494 break;
577 default:chip=-1;rev='x'; 495 case 0x83:
496 chip = 1865;
497 rev = 'A';
498 break;
499 case 0x84:
500 chip = 1865;
501 rev = 'B';
502 break;
503 case 0x85:
504 chip = 1865;
505 rev = 'C';
506 break; /* Does not exist at this time */
507 default:
508 chip = -1;
509 rev = 'x';
578 } 510 }
579 511
580 dprintk (SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) ); 512 dprintk(SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR));
581
582#ifdef SPECIALIX_TIMER
583 setup_timer(&missed_irq_timer, missed_irq, (unsigned long)bp);
584 mod_timer(&missed_irq_timer, jiffies + sx_poll);
585#endif
586 513
587 printk(KERN_INFO"sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n", 514 printk(KERN_INFO
588 board_No(bp), 515 "sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n",
589 bp->base, bp->irq, 516 board_No(bp), bp->base, bp->irq, chip, rev);
590 chip, rev);
591 517
592 func_exit(); 518 func_exit();
593 return 0; 519 return 0;
@@ -598,20 +524,22 @@ static int sx_probe(struct specialix_board *bp)
598 * Interrupt processing routines. 524 * Interrupt processing routines.
599 * */ 525 * */
600 526
601static inline struct specialix_port * sx_get_port(struct specialix_board * bp, 527static struct specialix_port *sx_get_port(struct specialix_board *bp,
602 unsigned char const * what) 528 unsigned char const *what)
603{ 529{
604 unsigned char channel; 530 unsigned char channel;
605 struct specialix_port * port = NULL; 531 struct specialix_port *port = NULL;
606 532
607 channel = sx_in(bp, CD186x_GICR) >> GICR_CHAN_OFF; 533 channel = sx_in(bp, CD186x_GICR) >> GICR_CHAN_OFF;
608 dprintk (SX_DEBUG_CHAN, "channel: %d\n", channel); 534 dprintk(SX_DEBUG_CHAN, "channel: %d\n", channel);
609 if (channel < CD186x_NCH) { 535 if (channel < CD186x_NCH) {
610 port = &sx_port[board_No(bp) * SX_NPORT + channel]; 536 port = &sx_port[board_No(bp) * SX_NPORT + channel];
611 dprintk (SX_DEBUG_CHAN, "port: %d %p flags: 0x%lx\n",board_No(bp) * SX_NPORT + channel, port, port->port.flags & ASYNC_INITIALIZED); 537 dprintk(SX_DEBUG_CHAN, "port: %d %p flags: 0x%lx\n",
538 board_No(bp) * SX_NPORT + channel, port,
539 port->port.flags & ASYNC_INITIALIZED);
612 540
613 if (port->port.flags & ASYNC_INITIALIZED) { 541 if (port->port.flags & ASYNC_INITIALIZED) {
614 dprintk (SX_DEBUG_CHAN, "port: %d %p\n", channel, port); 542 dprintk(SX_DEBUG_CHAN, "port: %d %p\n", channel, port);
615 func_exit(); 543 func_exit();
616 return port; 544 return port;
617 } 545 }
@@ -622,7 +550,7 @@ static inline struct specialix_port * sx_get_port(struct specialix_board * bp,
622} 550}
623 551
624 552
625static inline void sx_receive_exc(struct specialix_board * bp) 553static void sx_receive_exc(struct specialix_board *bp)
626{ 554{
627 struct specialix_port *port; 555 struct specialix_port *port;
628 struct tty_struct *tty; 556 struct tty_struct *tty;
@@ -633,7 +561,7 @@ static inline void sx_receive_exc(struct specialix_board * bp)
633 561
634 port = sx_get_port(bp, "Receive"); 562 port = sx_get_port(bp, "Receive");
635 if (!port) { 563 if (!port) {
636 dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n"); 564 dprintk(SX_DEBUG_RX, "Hmm, couldn't find port.\n");
637 func_exit(); 565 func_exit();
638 return; 566 return;
639 } 567 }
@@ -641,19 +569,21 @@ static inline void sx_receive_exc(struct specialix_board * bp)
641 569
642 status = sx_in(bp, CD186x_RCSR); 570 status = sx_in(bp, CD186x_RCSR);
643 571
644 dprintk (SX_DEBUG_RX, "status: 0x%x\n", status); 572 dprintk(SX_DEBUG_RX, "status: 0x%x\n", status);
645 if (status & RCSR_OE) { 573 if (status & RCSR_OE) {
646 port->overrun++; 574 port->overrun++;
647 dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Overrun. Total %ld overruns.\n", 575 dprintk(SX_DEBUG_FIFO,
648 board_No(bp), port_No(port), port->overrun); 576 "sx%d: port %d: Overrun. Total %ld overruns.\n",
577 board_No(bp), port_No(port), port->overrun);
649 } 578 }
650 status &= port->mark_mask; 579 status &= port->mark_mask;
651 580
652 /* This flip buffer check needs to be below the reading of the 581 /* This flip buffer check needs to be below the reading of the
653 status register to reset the chip's IRQ.... */ 582 status register to reset the chip's IRQ.... */
654 if (tty_buffer_request_room(tty, 1) == 0) { 583 if (tty_buffer_request_room(tty, 1) == 0) {
655 dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Working around flip buffer overflow.\n", 584 dprintk(SX_DEBUG_FIFO,
656 board_No(bp), port_No(port)); 585 "sx%d: port %d: Working around flip buffer overflow.\n",
586 board_No(bp), port_No(port));
657 func_exit(); 587 func_exit();
658 return; 588 return;
659 } 589 }
@@ -664,8 +594,9 @@ static inline void sx_receive_exc(struct specialix_board * bp)
664 return; 594 return;
665 } 595 }
666 if (status & RCSR_TOUT) { 596 if (status & RCSR_TOUT) {
667 printk(KERN_INFO "sx%d: port %d: Receiver timeout. Hardware problems ?\n", 597 printk(KERN_INFO
668 board_No(bp), port_No(port)); 598 "sx%d: port %d: Receiver timeout. Hardware problems ?\n",
599 board_No(bp), port_No(port));
669 func_exit(); 600 func_exit();
670 return; 601 return;
671 602
@@ -688,13 +619,13 @@ static inline void sx_receive_exc(struct specialix_board * bp)
688 else 619 else
689 flag = TTY_NORMAL; 620 flag = TTY_NORMAL;
690 621
691 if(tty_insert_flip_char(tty, ch, flag)) 622 if (tty_insert_flip_char(tty, ch, flag))
692 tty_flip_buffer_push(tty); 623 tty_flip_buffer_push(tty);
693 func_exit(); 624 func_exit();
694} 625}
695 626
696 627
697static inline void sx_receive(struct specialix_board * bp) 628static void sx_receive(struct specialix_board *bp)
698{ 629{
699 struct specialix_port *port; 630 struct specialix_port *port;
700 struct tty_struct *tty; 631 struct tty_struct *tty;
@@ -702,15 +633,16 @@ static inline void sx_receive(struct specialix_board * bp)
702 633
703 func_enter(); 634 func_enter();
704 635
705 if (!(port = sx_get_port(bp, "Receive"))) { 636 port = sx_get_port(bp, "Receive");
706 dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n"); 637 if (port == NULL) {
638 dprintk(SX_DEBUG_RX, "Hmm, couldn't find port.\n");
707 func_exit(); 639 func_exit();
708 return; 640 return;
709 } 641 }
710 tty = port->port.tty; 642 tty = port->port.tty;
711 643
712 count = sx_in(bp, CD186x_RDCR); 644 count = sx_in(bp, CD186x_RDCR);
713 dprintk (SX_DEBUG_RX, "port: %p: count: %d\n", port, count); 645 dprintk(SX_DEBUG_RX, "port: %p: count: %d\n", port, count);
714 port->hits[count > 8 ? 9 : count]++; 646 port->hits[count > 8 ? 9 : count]++;
715 647
716 tty_buffer_request_room(tty, count); 648 tty_buffer_request_room(tty, count);
@@ -722,18 +654,19 @@ static inline void sx_receive(struct specialix_board * bp)
722} 654}
723 655
724 656
725static inline void sx_transmit(struct specialix_board * bp) 657static void sx_transmit(struct specialix_board *bp)
726{ 658{
727 struct specialix_port *port; 659 struct specialix_port *port;
728 struct tty_struct *tty; 660 struct tty_struct *tty;
729 unsigned char count; 661 unsigned char count;
730 662
731 func_enter(); 663 func_enter();
732 if (!(port = sx_get_port(bp, "Transmit"))) { 664 port = sx_get_port(bp, "Transmit");
665 if (port == NULL) {
733 func_exit(); 666 func_exit();
734 return; 667 return;
735 } 668 }
736 dprintk (SX_DEBUG_TX, "port: %p\n", port); 669 dprintk(SX_DEBUG_TX, "port: %p\n", port);
737 tty = port->port.tty; 670 tty = port->port.tty;
738 671
739 if (port->IER & IER_TXEMPTY) { 672 if (port->IER & IER_TXEMPTY) {
@@ -765,7 +698,8 @@ static inline void sx_transmit(struct specialix_board * bp)
765 sx_out(bp, CD186x_TDR, CD186x_C_ESC); 698 sx_out(bp, CD186x_TDR, CD186x_C_ESC);
766 sx_out(bp, CD186x_TDR, CD186x_C_DELAY); 699 sx_out(bp, CD186x_TDR, CD186x_C_DELAY);
767 sx_out(bp, CD186x_TDR, count); 700 sx_out(bp, CD186x_TDR, count);
768 if (!(port->break_length -= count)) 701 port->break_length -= count;
702 if (port->break_length == 0)
769 port->break_length--; 703 port->break_length--;
770 } else { 704 } else {
771 sx_out(bp, CD186x_TDR, CD186x_C_ESC); 705 sx_out(bp, CD186x_TDR, CD186x_C_ESC);
@@ -794,36 +728,36 @@ static inline void sx_transmit(struct specialix_board * bp)
794 sx_out(bp, CD186x_IER, port->IER); 728 sx_out(bp, CD186x_IER, port->IER);
795 } 729 }
796 if (port->xmit_cnt <= port->wakeup_chars) 730 if (port->xmit_cnt <= port->wakeup_chars)
797 tty_wakeup(tty); 731 tty_wakeup(tty);
798 732
799 func_exit(); 733 func_exit();
800} 734}
801 735
802 736
803static inline void sx_check_modem(struct specialix_board * bp) 737static void sx_check_modem(struct specialix_board *bp)
804{ 738{
805 struct specialix_port *port; 739 struct specialix_port *port;
806 struct tty_struct *tty; 740 struct tty_struct *tty;
807 unsigned char mcr; 741 unsigned char mcr;
808 int msvr_cd; 742 int msvr_cd;
809 743
810 dprintk (SX_DEBUG_SIGNALS, "Modem intr. "); 744 dprintk(SX_DEBUG_SIGNALS, "Modem intr. ");
811 if (!(port = sx_get_port(bp, "Modem"))) 745 port = sx_get_port(bp, "Modem");
746 if (port == NULL)
812 return; 747 return;
813 748
814 tty = port->port.tty; 749 tty = port->port.tty;
815 750
816 mcr = sx_in(bp, CD186x_MCR); 751 mcr = sx_in(bp, CD186x_MCR);
817 printk ("mcr = %02x.\n", mcr);
818 752
819 if ((mcr & MCR_CDCHG)) { 753 if ((mcr & MCR_CDCHG)) {
820 dprintk (SX_DEBUG_SIGNALS, "CD just changed... "); 754 dprintk(SX_DEBUG_SIGNALS, "CD just changed... ");
821 msvr_cd = sx_in(bp, CD186x_MSVR) & MSVR_CD; 755 msvr_cd = sx_in(bp, CD186x_MSVR) & MSVR_CD;
822 if (msvr_cd) { 756 if (msvr_cd) {
823 dprintk (SX_DEBUG_SIGNALS, "Waking up guys in open.\n"); 757 dprintk(SX_DEBUG_SIGNALS, "Waking up guys in open.\n");
824 wake_up_interruptible(&port->port.open_wait); 758 wake_up_interruptible(&port->port.open_wait);
825 } else { 759 } else {
826 dprintk (SX_DEBUG_SIGNALS, "Sending HUP.\n"); 760 dprintk(SX_DEBUG_SIGNALS, "Sending HUP.\n");
827 tty_hangup(tty); 761 tty_hangup(tty);
828 } 762 }
829 } 763 }
@@ -874,9 +808,12 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
874 808
875 spin_lock_irqsave(&bp->lock, flags); 809 spin_lock_irqsave(&bp->lock, flags);
876 810
877 dprintk (SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __func__, port_No(sx_get_port(bp, "INT")), SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1); 811 dprintk(SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __func__,
812 port_No(sx_get_port(bp, "INT")),
813 SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1);
878 if (!(bp->flags & SX_BOARD_ACTIVE)) { 814 if (!(bp->flags & SX_BOARD_ACTIVE)) {
879 dprintk (SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n", bp->irq); 815 dprintk(SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n",
816 bp->irq);
880 spin_unlock_irqrestore(&bp->lock, flags); 817 spin_unlock_irqrestore(&bp->lock, flags);
881 func_exit(); 818 func_exit();
882 return IRQ_NONE; 819 return IRQ_NONE;
@@ -884,10 +821,11 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
884 821
885 saved_reg = bp->reg; 822 saved_reg = bp->reg;
886 823
887 while ((++loop < 16) && (status = (sx_in(bp, CD186x_SRSR) & 824 while (++loop < 16) {
888 (SRSR_RREQint | 825 status = sx_in(bp, CD186x_SRSR) &
889 SRSR_TREQint | 826 (SRSR_RREQint | SRSR_TREQint | SRSR_MREQint);
890 SRSR_MREQint)))) { 827 if (status == 0)
828 break;
891 if (status & SRSR_RREQint) { 829 if (status & SRSR_RREQint) {
892 ack = sx_in(bp, CD186x_RRAR); 830 ack = sx_in(bp, CD186x_RRAR);
893 831
@@ -896,8 +834,9 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
896 else if (ack == (SX_ID | GIVR_IT_REXC)) 834 else if (ack == (SX_ID | GIVR_IT_REXC))
897 sx_receive_exc(bp); 835 sx_receive_exc(bp);
898 else 836 else
899 printk(KERN_ERR "sx%d: status: 0x%x Bad receive ack 0x%02x.\n", 837 printk(KERN_ERR
900 board_No(bp), status, ack); 838 "sx%d: status: 0x%x Bad receive ack 0x%02x.\n",
839 board_No(bp), status, ack);
901 840
902 } else if (status & SRSR_TREQint) { 841 } else if (status & SRSR_TREQint) {
903 ack = sx_in(bp, CD186x_TRAR); 842 ack = sx_in(bp, CD186x_TRAR);
@@ -906,14 +845,16 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
906 sx_transmit(bp); 845 sx_transmit(bp);
907 else 846 else
908 printk(KERN_ERR "sx%d: status: 0x%x Bad transmit ack 0x%02x. port: %d\n", 847 printk(KERN_ERR "sx%d: status: 0x%x Bad transmit ack 0x%02x. port: %d\n",
909 board_No(bp), status, ack, port_No (sx_get_port (bp, "Int"))); 848 board_No(bp), status, ack,
849 port_No(sx_get_port(bp, "Int")));
910 } else if (status & SRSR_MREQint) { 850 } else if (status & SRSR_MREQint) {
911 ack = sx_in(bp, CD186x_MRAR); 851 ack = sx_in(bp, CD186x_MRAR);
912 852
913 if (ack == (SX_ID | GIVR_IT_MODEM)) 853 if (ack == (SX_ID | GIVR_IT_MODEM))
914 sx_check_modem(bp); 854 sx_check_modem(bp);
915 else 855 else
916 printk(KERN_ERR "sx%d: status: 0x%x Bad modem ack 0x%02x.\n", 856 printk(KERN_ERR
857 "sx%d: status: 0x%x Bad modem ack 0x%02x.\n",
917 board_No(bp), status, ack); 858 board_No(bp), status, ack);
918 859
919 } 860 }
@@ -921,7 +862,7 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
921 sx_out(bp, CD186x_EOIR, 0); /* Mark end of interrupt */ 862 sx_out(bp, CD186x_EOIR, 0); /* Mark end of interrupt */
922 } 863 }
923 bp->reg = saved_reg; 864 bp->reg = saved_reg;
924 outb (bp->reg, bp->base + SX_ADDR_REG); 865 outb(bp->reg, bp->base + SX_ADDR_REG);
925 spin_unlock_irqrestore(&bp->lock, flags); 866 spin_unlock_irqrestore(&bp->lock, flags);
926 func_exit(); 867 func_exit();
927 return IRQ_HANDLED; 868 return IRQ_HANDLED;
@@ -932,36 +873,26 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
932 * Routines for open & close processing. 873 * Routines for open & close processing.
933 */ 874 */
934 875
935static void turn_ints_off (struct specialix_board *bp) 876static void turn_ints_off(struct specialix_board *bp)
936{ 877{
937 unsigned long flags; 878 unsigned long flags;
938 879
939 func_enter(); 880 func_enter();
940 if (bp->flags & SX_BOARD_IS_PCI) {
941 /* This was intended for enabeling the interrupt on the
942 * PCI card. However it seems that it's already enabled
943 * and as PCI interrupts can be shared, there is no real
944 * reason to have to turn it off. */
945 }
946
947 spin_lock_irqsave(&bp->lock, flags); 881 spin_lock_irqsave(&bp->lock, flags);
948 (void) sx_in_off (bp, 0); /* Turn off interrupts. */ 882 (void) sx_in_off(bp, 0); /* Turn off interrupts. */
949 spin_unlock_irqrestore(&bp->lock, flags); 883 spin_unlock_irqrestore(&bp->lock, flags);
950 884
951 func_exit(); 885 func_exit();
952} 886}
953 887
954static void turn_ints_on (struct specialix_board *bp) 888static void turn_ints_on(struct specialix_board *bp)
955{ 889{
956 unsigned long flags; 890 unsigned long flags;
957 891
958 func_enter(); 892 func_enter();
959 893
960 if (bp->flags & SX_BOARD_IS_PCI) {
961 /* play with the PCI chip. See comment above. */
962 }
963 spin_lock_irqsave(&bp->lock, flags); 894 spin_lock_irqsave(&bp->lock, flags);
964 (void) sx_in (bp, 0); /* Turn ON interrupts. */ 895 (void) sx_in(bp, 0); /* Turn ON interrupts. */
965 spin_unlock_irqrestore(&bp->lock, flags); 896 spin_unlock_irqrestore(&bp->lock, flags);
966 897
967 func_exit(); 898 func_exit();
@@ -969,7 +900,7 @@ static void turn_ints_on (struct specialix_board *bp)
969 900
970 901
971/* Called with disabled interrupts */ 902/* Called with disabled interrupts */
972static inline int sx_setup_board(struct specialix_board * bp) 903static int sx_setup_board(struct specialix_board *bp)
973{ 904{
974 int error; 905 int error;
975 906
@@ -977,14 +908,16 @@ static inline int sx_setup_board(struct specialix_board * bp)
977 return 0; 908 return 0;
978 909
979 if (bp->flags & SX_BOARD_IS_PCI) 910 if (bp->flags & SX_BOARD_IS_PCI)
980 error = request_irq(bp->irq, sx_interrupt, IRQF_DISABLED | IRQF_SHARED, "specialix IO8+", bp); 911 error = request_irq(bp->irq, sx_interrupt,
912 IRQF_DISABLED | IRQF_SHARED, "specialix IO8+", bp);
981 else 913 else
982 error = request_irq(bp->irq, sx_interrupt, IRQF_DISABLED, "specialix IO8+", bp); 914 error = request_irq(bp->irq, sx_interrupt,
915 IRQF_DISABLED, "specialix IO8+", bp);
983 916
984 if (error) 917 if (error)
985 return error; 918 return error;
986 919
987 turn_ints_on (bp); 920 turn_ints_on(bp);
988 bp->flags |= SX_BOARD_ACTIVE; 921 bp->flags |= SX_BOARD_ACTIVE;
989 922
990 return 0; 923 return 0;
@@ -992,7 +925,7 @@ static inline int sx_setup_board(struct specialix_board * bp)
992 925
993 926
994/* Called with disabled interrupts */ 927/* Called with disabled interrupts */
995static inline void sx_shutdown_board(struct specialix_board *bp) 928static void sx_shutdown_board(struct specialix_board *bp)
996{ 929{
997 func_enter(); 930 func_enter();
998 931
@@ -1003,22 +936,26 @@ static inline void sx_shutdown_board(struct specialix_board *bp)
1003 936
1004 bp->flags &= ~SX_BOARD_ACTIVE; 937 bp->flags &= ~SX_BOARD_ACTIVE;
1005 938
1006 dprintk (SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n", 939 dprintk(SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n",
1007 bp->irq, board_No (bp)); 940 bp->irq, board_No(bp));
1008 free_irq(bp->irq, bp); 941 free_irq(bp->irq, bp);
1009 942 turn_ints_off(bp);
1010 turn_ints_off (bp);
1011
1012
1013 func_exit(); 943 func_exit();
1014} 944}
1015 945
946static unsigned int sx_crtscts(struct tty_struct *tty)
947{
948 if (sx_rtscts)
949 return C_CRTSCTS(tty);
950 return 1;
951}
1016 952
1017/* 953/*
1018 * Setting up port characteristics. 954 * Setting up port characteristics.
1019 * Must be called with disabled interrupts 955 * Must be called with disabled interrupts
1020 */ 956 */
1021static void sx_change_speed(struct specialix_board *bp, struct specialix_port *port) 957static void sx_change_speed(struct specialix_board *bp,
958 struct specialix_port *port)
1022{ 959{
1023 struct tty_struct *tty; 960 struct tty_struct *tty;
1024 unsigned long baud; 961 unsigned long baud;
@@ -1030,7 +967,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1030 967
1031 func_enter(); 968 func_enter();
1032 969
1033 if (!(tty = port->port.tty) || !tty->termios) { 970 tty = port->port.tty;
971 if (!tty || !tty->termios) {
1034 func_exit(); 972 func_exit();
1035 return; 973 return;
1036 } 974 }
@@ -1043,12 +981,12 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1043 981
1044 /* The Specialix board doens't implement the RTS lines. 982 /* The Specialix board doens't implement the RTS lines.
1045 They are used to set the IRQ level. Don't touch them. */ 983 They are used to set the IRQ level. Don't touch them. */
1046 if (SX_CRTSCTS(tty)) 984 if (sx_crtscts(tty))
1047 port->MSVR = MSVR_DTR | (sx_in(bp, CD186x_MSVR) & MSVR_RTS); 985 port->MSVR = MSVR_DTR | (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
1048 else 986 else
1049 port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS); 987 port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
1050 spin_unlock_irqrestore(&bp->lock, flags); 988 spin_unlock_irqrestore(&bp->lock, flags);
1051 dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR); 989 dprintk(SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR);
1052 baud = tty_get_baud_rate(tty); 990 baud = tty_get_baud_rate(tty);
1053 991
1054 if (baud == 38400) { 992 if (baud == 38400) {
@@ -1060,21 +998,19 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1060 998
1061 if (!baud) { 999 if (!baud) {
1062 /* Drop DTR & exit */ 1000 /* Drop DTR & exit */
1063 dprintk (SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n"); 1001 dprintk(SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n");
1064 if (!SX_CRTSCTS (tty)) { 1002 if (!sx_crtscts(tty)) {
1065 port -> MSVR &= ~ MSVR_DTR; 1003 port->MSVR &= ~MSVR_DTR;
1066 spin_lock_irqsave(&bp->lock, flags); 1004 spin_lock_irqsave(&bp->lock, flags);
1067 sx_out(bp, CD186x_MSVR, port->MSVR ); 1005 sx_out(bp, CD186x_MSVR, port->MSVR);
1068 spin_unlock_irqrestore(&bp->lock, flags); 1006 spin_unlock_irqrestore(&bp->lock, flags);
1069 } 1007 } else
1070 else 1008 dprintk(SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n");
1071 dprintk (SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n");
1072 return; 1009 return;
1073 } else { 1010 } else {
1074 /* Set DTR on */ 1011 /* Set DTR on */
1075 if (!SX_CRTSCTS (tty)) { 1012 if (!sx_crtscts(tty))
1076 port ->MSVR |= MSVR_DTR; 1013 port->MSVR |= MSVR_DTR;
1077 }
1078 } 1014 }
1079 1015
1080 /* 1016 /*
@@ -1083,28 +1019,27 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1083 1019
1084 /* Set baud rate for port */ 1020 /* Set baud rate for port */
1085 tmp = port->custom_divisor ; 1021 tmp = port->custom_divisor ;
1086 if ( tmp ) 1022 if (tmp)
1087 printk (KERN_INFO "sx%d: Using custom baud rate divisor %ld. \n" 1023 printk(KERN_INFO
1088 "This is an untested option, please be carefull.\n", 1024 "sx%d: Using custom baud rate divisor %ld. \n"
1089 port_No (port), tmp); 1025 "This is an untested option, please be careful.\n",
1026 port_No(port), tmp);
1090 else 1027 else
1091 tmp = (((SX_OSCFREQ + baud/2) / baud + 1028 tmp = (((SX_OSCFREQ + baud/2) / baud + CD186x_TPC/2) /
1092 CD186x_TPC/2) / CD186x_TPC); 1029 CD186x_TPC);
1093 1030
1094 if ((tmp < 0x10) && time_before(again, jiffies)) { 1031 if (tmp < 0x10 && time_before(again, jiffies)) {
1095 again = jiffies + HZ * 60; 1032 again = jiffies + HZ * 60;
1096 /* Page 48 of version 2.0 of the CL-CD1865 databook */ 1033 /* Page 48 of version 2.0 of the CL-CD1865 databook */
1097 if (tmp >= 12) { 1034 if (tmp >= 12) {
1098 printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n" 1035 printk(KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
1099 "Performance degradation is possible.\n" 1036 "Performance degradation is possible.\n"
1100 "Read specialix.txt for more info.\n", 1037 "Read specialix.txt for more info.\n",
1101 port_No (port), tmp); 1038 port_No(port), tmp);
1102 } else { 1039 } else {
1103 printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n" 1040 printk(KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
1104 "Warning: overstressing Cirrus chip. " 1041 "Warning: overstressing Cirrus chip. This might not work.\n"
1105 "This might not work.\n" 1042 "Read specialix.txt for more info.\n", port_No(port), tmp);
1106 "Read specialix.txt for more info.\n",
1107 port_No (port), tmp);
1108 } 1043 }
1109 } 1044 }
1110 spin_lock_irqsave(&bp->lock, flags); 1045 spin_lock_irqsave(&bp->lock, flags);
@@ -1114,7 +1049,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1114 sx_out(bp, CD186x_TBPRL, tmp & 0xff); 1049 sx_out(bp, CD186x_TBPRL, tmp & 0xff);
1115 spin_unlock_irqrestore(&bp->lock, flags); 1050 spin_unlock_irqrestore(&bp->lock, flags);
1116 if (port->custom_divisor) 1051 if (port->custom_divisor)
1117 baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor; 1052 baud = (SX_OSCFREQ + port->custom_divisor/2) /
1053 port->custom_divisor;
1118 baud = (baud + 5) / 10; /* Estimated CPS */ 1054 baud = (baud + 5) / 10; /* Estimated CPS */
1119 1055
1120 /* Two timer ticks seems enough to wakeup something like SLIP driver */ 1056 /* Two timer ticks seems enough to wakeup something like SLIP driver */
@@ -1129,16 +1065,16 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1129 sx_out(bp, CD186x_RTPR, tmp); 1065 sx_out(bp, CD186x_RTPR, tmp);
1130 spin_unlock_irqrestore(&bp->lock, flags); 1066 spin_unlock_irqrestore(&bp->lock, flags);
1131 switch (C_CSIZE(tty)) { 1067 switch (C_CSIZE(tty)) {
1132 case CS5: 1068 case CS5:
1133 cor1 |= COR1_5BITS; 1069 cor1 |= COR1_5BITS;
1134 break; 1070 break;
1135 case CS6: 1071 case CS6:
1136 cor1 |= COR1_6BITS; 1072 cor1 |= COR1_6BITS;
1137 break; 1073 break;
1138 case CS7: 1074 case CS7:
1139 cor1 |= COR1_7BITS; 1075 cor1 |= COR1_7BITS;
1140 break; 1076 break;
1141 case CS8: 1077 case CS8:
1142 cor1 |= COR1_8BITS; 1078 cor1 |= COR1_8BITS;
1143 break; 1079 break;
1144 } 1080 }
@@ -1175,7 +1111,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1175 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD; 1111 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
1176 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD; 1112 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
1177 spin_lock_irqsave(&bp->lock, flags); 1113 spin_lock_irqsave(&bp->lock, flags);
1178 tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) & (MSVR_CTS|MSVR_DSR)); 1114 tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) &
1115 (MSVR_CTS|MSVR_DSR));
1179 spin_unlock_irqrestore(&bp->lock, flags); 1116 spin_unlock_irqrestore(&bp->lock, flags);
1180#else 1117#else
1181 port->COR2 |= COR2_CTSAE; 1118 port->COR2 |= COR2_CTSAE;
@@ -1219,7 +1156,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1219 spin_lock_irqsave(&bp->lock, flags); 1156 spin_lock_irqsave(&bp->lock, flags);
1220 sx_out(bp, CD186x_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3); 1157 sx_out(bp, CD186x_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
1221 /* Setting up modem option registers */ 1158 /* Setting up modem option registers */
1222 dprintk (SX_DEBUG_TERMIOS, "Mcor1 = %02x, mcor2 = %02x.\n", mcor1, mcor2); 1159 dprintk(SX_DEBUG_TERMIOS, "Mcor1 = %02x, mcor2 = %02x.\n",
1160 mcor1, mcor2);
1223 sx_out(bp, CD186x_MCOR1, mcor1); 1161 sx_out(bp, CD186x_MCOR1, mcor1);
1224 sx_out(bp, CD186x_MCOR2, mcor2); 1162 sx_out(bp, CD186x_MCOR2, mcor2);
1225 spin_unlock_irqrestore(&bp->lock, flags); 1163 spin_unlock_irqrestore(&bp->lock, flags);
@@ -1238,7 +1176,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1238 1176
1239 1177
1240/* Must be called with interrupts enabled */ 1178/* Must be called with interrupts enabled */
1241static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port) 1179static int sx_setup_port(struct specialix_board *bp,
1180 struct specialix_port *port)
1242{ 1181{
1243 unsigned long flags; 1182 unsigned long flags;
1244 1183
@@ -1253,7 +1192,8 @@ static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port
1253 /* We may sleep in get_zeroed_page() */ 1192 /* We may sleep in get_zeroed_page() */
1254 unsigned long tmp; 1193 unsigned long tmp;
1255 1194
1256 if (!(tmp = get_zeroed_page(GFP_KERNEL))) { 1195 tmp = get_zeroed_page(GFP_KERNEL);
1196 if (tmp == 0L) {
1257 func_exit(); 1197 func_exit();
1258 return -ENOMEM; 1198 return -ENOMEM;
1259 } 1199 }
@@ -1284,7 +1224,8 @@ static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port
1284 1224
1285 1225
1286/* Must be called with interrupts disabled */ 1226/* Must be called with interrupts disabled */
1287static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *port) 1227static void sx_shutdown_port(struct specialix_board *bp,
1228 struct specialix_port *port)
1288{ 1229{
1289 struct tty_struct *tty; 1230 struct tty_struct *tty;
1290 int i; 1231 int i;
@@ -1298,11 +1239,11 @@ static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *
1298 } 1239 }
1299 1240
1300 if (sx_debug & SX_DEBUG_FIFO) { 1241 if (sx_debug & SX_DEBUG_FIFO) {
1301 dprintk(SX_DEBUG_FIFO, "sx%d: port %d: %ld overruns, FIFO hits [ ", 1242 dprintk(SX_DEBUG_FIFO,
1302 board_No(bp), port_No(port), port->overrun); 1243 "sx%d: port %d: %ld overruns, FIFO hits [ ",
1303 for (i = 0; i < 10; i++) { 1244 board_No(bp), port_No(port), port->overrun);
1245 for (i = 0; i < 10; i++)
1304 dprintk(SX_DEBUG_FIFO, "%ld ", port->hits[i]); 1246 dprintk(SX_DEBUG_FIFO, "%ld ", port->hits[i]);
1305 }
1306 dprintk(SX_DEBUG_FIFO, "].\n"); 1247 dprintk(SX_DEBUG_FIFO, "].\n");
1307 } 1248 }
1308 1249
@@ -1315,7 +1256,8 @@ static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *
1315 spin_lock_irqsave(&bp->lock, flags); 1256 spin_lock_irqsave(&bp->lock, flags);
1316 sx_out(bp, CD186x_CAR, port_No(port)); 1257 sx_out(bp, CD186x_CAR, port_No(port));
1317 1258
1318 if (!(tty = port->port.tty) || C_HUPCL(tty)) { 1259 tty = port->port.tty;
1260 if (tty == NULL || C_HUPCL(tty)) {
1319 /* Drop DTR */ 1261 /* Drop DTR */
1320 sx_out(bp, CD186x_MSVDTR, 0); 1262 sx_out(bp, CD186x_MSVDTR, 0);
1321 } 1263 }
@@ -1338,8 +1280,8 @@ static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *
1338} 1280}
1339 1281
1340 1282
1341static int block_til_ready(struct tty_struct *tty, struct file * filp, 1283static int block_til_ready(struct tty_struct *tty, struct file *filp,
1342 struct specialix_port *port) 1284 struct specialix_port *port)
1343{ 1285{
1344 DECLARE_WAITQUEUE(wait, current); 1286 DECLARE_WAITQUEUE(wait, current);
1345 struct specialix_board *bp = port_Board(port); 1287 struct specialix_board *bp = port_Board(port);
@@ -1389,23 +1331,22 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1389 retval = 0; 1331 retval = 0;
1390 add_wait_queue(&port->port.open_wait, &wait); 1332 add_wait_queue(&port->port.open_wait, &wait);
1391 spin_lock_irqsave(&port->lock, flags); 1333 spin_lock_irqsave(&port->lock, flags);
1392 if (!tty_hung_up_p(filp)) { 1334 if (!tty_hung_up_p(filp))
1393 port->port.count--; 1335 port->port.count--;
1394 }
1395 spin_unlock_irqrestore(&port->lock, flags); 1336 spin_unlock_irqrestore(&port->lock, flags);
1396 port->port.blocked_open++; 1337 port->port.blocked_open++;
1397 while (1) { 1338 while (1) {
1398 spin_lock_irqsave(&bp->lock, flags); 1339 spin_lock_irqsave(&bp->lock, flags);
1399 sx_out(bp, CD186x_CAR, port_No(port)); 1340 sx_out(bp, CD186x_CAR, port_No(port));
1400 CD = sx_in(bp, CD186x_MSVR) & MSVR_CD; 1341 CD = sx_in(bp, CD186x_MSVR) & MSVR_CD;
1401 if (SX_CRTSCTS (tty)) { 1342 if (sx_crtscts(tty)) {
1402 /* Activate RTS */ 1343 /* Activate RTS */
1403 port->MSVR |= MSVR_DTR; /* WTF? */ 1344 port->MSVR |= MSVR_DTR; /* WTF? */
1404 sx_out (bp, CD186x_MSVR, port->MSVR); 1345 sx_out(bp, CD186x_MSVR, port->MSVR);
1405 } else { 1346 } else {
1406 /* Activate DTR */ 1347 /* Activate DTR */
1407 port->MSVR |= MSVR_DTR; 1348 port->MSVR |= MSVR_DTR;
1408 sx_out (bp, CD186x_MSVR, port->MSVR); 1349 sx_out(bp, CD186x_MSVR, port->MSVR);
1409 } 1350 }
1410 spin_unlock_irqrestore(&bp->lock, flags); 1351 spin_unlock_irqrestore(&bp->lock, flags);
1411 set_current_state(TASK_INTERRUPTIBLE); 1352 set_current_state(TASK_INTERRUPTIBLE);
@@ -1430,9 +1371,8 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1430 set_current_state(TASK_RUNNING); 1371 set_current_state(TASK_RUNNING);
1431 remove_wait_queue(&port->port.open_wait, &wait); 1372 remove_wait_queue(&port->port.open_wait, &wait);
1432 spin_lock_irqsave(&port->lock, flags); 1373 spin_lock_irqsave(&port->lock, flags);
1433 if (!tty_hung_up_p(filp)) { 1374 if (!tty_hung_up_p(filp))
1434 port->port.count++; 1375 port->port.count++;
1435 }
1436 port->port.blocked_open--; 1376 port->port.blocked_open--;
1437 spin_unlock_irqrestore(&port->lock, flags); 1377 spin_unlock_irqrestore(&port->lock, flags);
1438 if (retval) { 1378 if (retval) {
@@ -1446,12 +1386,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1446} 1386}
1447 1387
1448 1388
1449static int sx_open(struct tty_struct * tty, struct file * filp) 1389static int sx_open(struct tty_struct *tty, struct file *filp)
1450{ 1390{
1451 int board; 1391 int board;
1452 int error; 1392 int error;
1453 struct specialix_port * port; 1393 struct specialix_port *port;
1454 struct specialix_board * bp; 1394 struct specialix_board *bp;
1455 int i; 1395 int i;
1456 unsigned long flags; 1396 unsigned long flags;
1457 1397
@@ -1468,17 +1408,19 @@ static int sx_open(struct tty_struct * tty, struct file * filp)
1468 port = sx_port + board * SX_NPORT + SX_PORT(tty->index); 1408 port = sx_port + board * SX_NPORT + SX_PORT(tty->index);
1469 port->overrun = 0; 1409 port->overrun = 0;
1470 for (i = 0; i < 10; i++) 1410 for (i = 0; i < 10; i++)
1471 port->hits[i]=0; 1411 port->hits[i] = 0;
1472 1412
1473 dprintk (SX_DEBUG_OPEN, "Board = %d, bp = %p, port = %p, portno = %d.\n", 1413 dprintk(SX_DEBUG_OPEN,
1474 board, bp, port, SX_PORT(tty->index)); 1414 "Board = %d, bp = %p, port = %p, portno = %d.\n",
1415 board, bp, port, SX_PORT(tty->index));
1475 1416
1476 if (sx_paranoia_check(port, tty->name, "sx_open")) { 1417 if (sx_paranoia_check(port, tty->name, "sx_open")) {
1477 func_enter(); 1418 func_enter();
1478 return -ENODEV; 1419 return -ENODEV;
1479 } 1420 }
1480 1421
1481 if ((error = sx_setup_board(bp))) { 1422 error = sx_setup_board(bp);
1423 if (error) {
1482 func_exit(); 1424 func_exit();
1483 return error; 1425 return error;
1484 } 1426 }
@@ -1490,12 +1432,14 @@ static int sx_open(struct tty_struct * tty, struct file * filp)
1490 port->port.tty = tty; 1432 port->port.tty = tty;
1491 spin_unlock_irqrestore(&bp->lock, flags); 1433 spin_unlock_irqrestore(&bp->lock, flags);
1492 1434
1493 if ((error = sx_setup_port(bp, port))) { 1435 error = sx_setup_port(bp, port);
1436 if (error) {
1494 func_enter(); 1437 func_enter();
1495 return error; 1438 return error;
1496 } 1439 }
1497 1440
1498 if ((error = block_til_ready(tty, filp, port))) { 1441 error = block_til_ready(tty, filp, port);
1442 if (error) {
1499 func_enter(); 1443 func_enter();
1500 return error; 1444 return error;
1501 } 1445 }
@@ -1508,7 +1452,7 @@ static void sx_flush_buffer(struct tty_struct *tty)
1508{ 1452{
1509 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1453 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1510 unsigned long flags; 1454 unsigned long flags;
1511 struct specialix_board * bp; 1455 struct specialix_board *bp;
1512 1456
1513 func_enter(); 1457 func_enter();
1514 1458
@@ -1526,9 +1470,9 @@ static void sx_flush_buffer(struct tty_struct *tty)
1526 func_exit(); 1470 func_exit();
1527} 1471}
1528 1472
1529static void sx_close(struct tty_struct * tty, struct file * filp) 1473static void sx_close(struct tty_struct *tty, struct file *filp)
1530{ 1474{
1531 struct specialix_port *port = (struct specialix_port *) tty->driver_data; 1475 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1532 struct specialix_board *bp; 1476 struct specialix_board *bp;
1533 unsigned long flags; 1477 unsigned long flags;
1534 unsigned long timeout; 1478 unsigned long timeout;
@@ -1547,7 +1491,7 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1547 } 1491 }
1548 1492
1549 bp = port_Board(port); 1493 bp = port_Board(port);
1550 if ((tty->count == 1) && (port->port.count != 1)) { 1494 if (tty->count == 1 && port->port.count != 1) {
1551 printk(KERN_ERR "sx%d: sx_close: bad port count;" 1495 printk(KERN_ERR "sx%d: sx_close: bad port count;"
1552 " tty->count is 1, port count is %d\n", 1496 " tty->count is 1, port count is %d\n",
1553 board_No(bp), port->port.count); 1497 board_No(bp), port->port.count);
@@ -1570,17 +1514,16 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1570 */ 1514 */
1571 tty->closing = 1; 1515 tty->closing = 1;
1572 spin_unlock_irqrestore(&port->lock, flags); 1516 spin_unlock_irqrestore(&port->lock, flags);
1573 dprintk (SX_DEBUG_OPEN, "Closing\n"); 1517 dprintk(SX_DEBUG_OPEN, "Closing\n");
1574 if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) { 1518 if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
1575 tty_wait_until_sent(tty, port->port.closing_wait); 1519 tty_wait_until_sent(tty, port->port.closing_wait);
1576 }
1577 /* 1520 /*
1578 * At this point we stop accepting input. To do this, we 1521 * At this point we stop accepting input. To do this, we
1579 * disable the receive line status interrupts, and tell the 1522 * disable the receive line status interrupts, and tell the
1580 * interrupt driver to stop checking the data ready bit in the 1523 * interrupt driver to stop checking the data ready bit in the
1581 * line status register. 1524 * line status register.
1582 */ 1525 */
1583 dprintk (SX_DEBUG_OPEN, "Closed\n"); 1526 dprintk(SX_DEBUG_OPEN, "Closed\n");
1584 port->IER &= ~IER_RXD; 1527 port->IER &= ~IER_RXD;
1585 if (port->port.flags & ASYNC_INITIALIZED) { 1528 if (port->port.flags & ASYNC_INITIALIZED) {
1586 port->IER &= ~IER_TXRDY; 1529 port->IER &= ~IER_TXRDY;
@@ -1595,11 +1538,11 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1595 * important if there is a transmit FIFO! 1538 * important if there is a transmit FIFO!
1596 */ 1539 */
1597 timeout = jiffies+HZ; 1540 timeout = jiffies+HZ;
1598 while(port->IER & IER_TXEMPTY) { 1541 while (port->IER & IER_TXEMPTY) {
1599 set_current_state (TASK_INTERRUPTIBLE); 1542 set_current_state(TASK_INTERRUPTIBLE);
1600 msleep_interruptible(jiffies_to_msecs(port->timeout)); 1543 msleep_interruptible(jiffies_to_msecs(port->timeout));
1601 if (time_after(jiffies, timeout)) { 1544 if (time_after(jiffies, timeout)) {
1602 printk (KERN_INFO "Timeout waiting for close\n"); 1545 printk(KERN_INFO "Timeout waiting for close\n");
1603 break; 1546 break;
1604 } 1547 }
1605 } 1548 }
@@ -1607,13 +1550,15 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1607 } 1550 }
1608 1551
1609 if (--bp->count < 0) { 1552 if (--bp->count < 0) {
1610 printk(KERN_ERR "sx%d: sx_shutdown_port: bad board count: %d port: %d\n", 1553 printk(KERN_ERR
1611 board_No(bp), bp->count, tty->index); 1554 "sx%d: sx_shutdown_port: bad board count: %d port: %d\n",
1555 board_No(bp), bp->count, tty->index);
1612 bp->count = 0; 1556 bp->count = 0;
1613 } 1557 }
1614 if (--port->port.count < 0) { 1558 if (--port->port.count < 0) {
1615 printk(KERN_ERR "sx%d: sx_close: bad port count for tty%d: %d\n", 1559 printk(KERN_ERR
1616 board_No(bp), port_No(port), port->port.count); 1560 "sx%d: sx_close: bad port count for tty%d: %d\n",
1561 board_No(bp), port_No(port), port->port.count);
1617 port->port.count = 0; 1562 port->port.count = 0;
1618 } 1563 }
1619 1564
@@ -1625,9 +1570,9 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1625 port->port.tty = NULL; 1570 port->port.tty = NULL;
1626 spin_unlock_irqrestore(&port->lock, flags); 1571 spin_unlock_irqrestore(&port->lock, flags);
1627 if (port->port.blocked_open) { 1572 if (port->port.blocked_open) {
1628 if (port->port.close_delay) { 1573 if (port->port.close_delay)
1629 msleep_interruptible(jiffies_to_msecs(port->port.close_delay)); 1574 msleep_interruptible(
1630 } 1575 jiffies_to_msecs(port->port.close_delay));
1631 wake_up_interruptible(&port->port.open_wait); 1576 wake_up_interruptible(&port->port.open_wait);
1632 } 1577 }
1633 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1578 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
@@ -1637,8 +1582,8 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1637} 1582}
1638 1583
1639 1584
1640static int sx_write(struct tty_struct * tty, 1585static int sx_write(struct tty_struct *tty,
1641 const unsigned char *buf, int count) 1586 const unsigned char *buf, int count)
1642{ 1587{
1643 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1588 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1644 struct specialix_board *bp; 1589 struct specialix_board *bp;
@@ -1690,11 +1635,11 @@ static int sx_write(struct tty_struct * tty,
1690} 1635}
1691 1636
1692 1637
1693static int sx_put_char(struct tty_struct * tty, unsigned char ch) 1638static int sx_put_char(struct tty_struct *tty, unsigned char ch)
1694{ 1639{
1695 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1640 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1696 unsigned long flags; 1641 unsigned long flags;
1697 struct specialix_board * bp; 1642 struct specialix_board *bp;
1698 1643
1699 func_enter(); 1644 func_enter();
1700 1645
@@ -1702,7 +1647,7 @@ static int sx_put_char(struct tty_struct * tty, unsigned char ch)
1702 func_exit(); 1647 func_exit();
1703 return 0; 1648 return 0;
1704 } 1649 }
1705 dprintk (SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf); 1650 dprintk(SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf);
1706 if (!port->xmit_buf) { 1651 if (!port->xmit_buf) {
1707 func_exit(); 1652 func_exit();
1708 return 0; 1653 return 0;
@@ -1710,14 +1655,15 @@ static int sx_put_char(struct tty_struct * tty, unsigned char ch)
1710 bp = port_Board(port); 1655 bp = port_Board(port);
1711 spin_lock_irqsave(&port->lock, flags); 1656 spin_lock_irqsave(&port->lock, flags);
1712 1657
1713 dprintk (SX_DEBUG_TX, "xmit_cnt: %d xmit_buf: %p\n", port->xmit_cnt, port->xmit_buf); 1658 dprintk(SX_DEBUG_TX, "xmit_cnt: %d xmit_buf: %p\n",
1714 if ((port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) || (!port->xmit_buf)) { 1659 port->xmit_cnt, port->xmit_buf);
1660 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1 || !port->xmit_buf) {
1715 spin_unlock_irqrestore(&port->lock, flags); 1661 spin_unlock_irqrestore(&port->lock, flags);
1716 dprintk (SX_DEBUG_TX, "Exit size\n"); 1662 dprintk(SX_DEBUG_TX, "Exit size\n");
1717 func_exit(); 1663 func_exit();
1718 return 0; 1664 return 0;
1719 } 1665 }
1720 dprintk (SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf); 1666 dprintk(SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf);
1721 port->xmit_buf[port->xmit_head++] = ch; 1667 port->xmit_buf[port->xmit_head++] = ch;
1722 port->xmit_head &= SERIAL_XMIT_SIZE - 1; 1668 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1723 port->xmit_cnt++; 1669 port->xmit_cnt++;
@@ -1728,11 +1674,11 @@ static int sx_put_char(struct tty_struct * tty, unsigned char ch)
1728} 1674}
1729 1675
1730 1676
1731static void sx_flush_chars(struct tty_struct * tty) 1677static void sx_flush_chars(struct tty_struct *tty)
1732{ 1678{
1733 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1679 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1734 unsigned long flags; 1680 unsigned long flags;
1735 struct specialix_board * bp = port_Board(port); 1681 struct specialix_board *bp = port_Board(port);
1736 1682
1737 func_enter(); 1683 func_enter();
1738 1684
@@ -1755,7 +1701,7 @@ static void sx_flush_chars(struct tty_struct * tty)
1755} 1701}
1756 1702
1757 1703
1758static int sx_write_room(struct tty_struct * tty) 1704static int sx_write_room(struct tty_struct *tty)
1759{ 1705{
1760 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1706 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1761 int ret; 1707 int ret;
@@ -1790,12 +1736,10 @@ static int sx_chars_in_buffer(struct tty_struct *tty)
1790 return port->xmit_cnt; 1736 return port->xmit_cnt;
1791} 1737}
1792 1738
1793
1794
1795static int sx_tiocmget(struct tty_struct *tty, struct file *file) 1739static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1796{ 1740{
1797 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1741 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1798 struct specialix_board * bp; 1742 struct specialix_board *bp;
1799 unsigned char status; 1743 unsigned char status;
1800 unsigned int result; 1744 unsigned int result;
1801 unsigned long flags; 1745 unsigned long flags;
@@ -1808,25 +1752,23 @@ static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1808 } 1752 }
1809 1753
1810 bp = port_Board(port); 1754 bp = port_Board(port);
1811 spin_lock_irqsave (&bp->lock, flags); 1755 spin_lock_irqsave(&bp->lock, flags);
1812 sx_out(bp, CD186x_CAR, port_No(port)); 1756 sx_out(bp, CD186x_CAR, port_No(port));
1813 status = sx_in(bp, CD186x_MSVR); 1757 status = sx_in(bp, CD186x_MSVR);
1814 spin_unlock_irqrestore(&bp->lock, flags); 1758 spin_unlock_irqrestore(&bp->lock, flags);
1815 dprintk (SX_DEBUG_INIT, "Got msvr[%d] = %02x, car = %d.\n", 1759 dprintk(SX_DEBUG_INIT, "Got msvr[%d] = %02x, car = %d.\n",
1816 port_No(port), status, sx_in (bp, CD186x_CAR)); 1760 port_No(port), status, sx_in(bp, CD186x_CAR));
1817 dprintk (SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port); 1761 dprintk(SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port);
1818 if (SX_CRTSCTS(port->port.tty)) { 1762 if (sx_crtscts(port->port.tty)) {
1819 result = /* (status & MSVR_RTS) ? */ TIOCM_DTR /* : 0) */ 1763 result = TIOCM_DTR | TIOCM_DSR
1820 | ((status & MSVR_DTR) ? TIOCM_RTS : 0) 1764 | ((status & MSVR_DTR) ? TIOCM_RTS : 0)
1821 | ((status & MSVR_CD) ? TIOCM_CAR : 0) 1765 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1822 |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */ 1766 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1823 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1824 } else { 1767 } else {
1825 result = /* (status & MSVR_RTS) ? */ TIOCM_RTS /* : 0) */ 1768 result = TIOCM_RTS | TIOCM_DSR
1826 | ((status & MSVR_DTR) ? TIOCM_DTR : 0) 1769 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1827 | ((status & MSVR_CD) ? TIOCM_CAR : 0) 1770 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1828 |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */ 1771 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1829 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1830 } 1772 }
1831 1773
1832 func_exit(); 1774 func_exit();
@@ -1852,24 +1794,14 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1852 bp = port_Board(port); 1794 bp = port_Board(port);
1853 1795
1854 spin_lock_irqsave(&port->lock, flags); 1796 spin_lock_irqsave(&port->lock, flags);
1855 /* if (set & TIOCM_RTS) 1797 if (sx_crtscts(port->port.tty)) {
1856 port->MSVR |= MSVR_RTS; */
1857 /* if (set & TIOCM_DTR)
1858 port->MSVR |= MSVR_DTR; */
1859
1860 if (SX_CRTSCTS(port->port.tty)) {
1861 if (set & TIOCM_RTS) 1798 if (set & TIOCM_RTS)
1862 port->MSVR |= MSVR_DTR; 1799 port->MSVR |= MSVR_DTR;
1863 } else { 1800 } else {
1864 if (set & TIOCM_DTR) 1801 if (set & TIOCM_DTR)
1865 port->MSVR |= MSVR_DTR; 1802 port->MSVR |= MSVR_DTR;
1866 } 1803 }
1867 1804 if (sx_crtscts(port->port.tty)) {
1868 /* if (clear & TIOCM_RTS)
1869 port->MSVR &= ~MSVR_RTS; */
1870 /* if (clear & TIOCM_DTR)
1871 port->MSVR &= ~MSVR_DTR; */
1872 if (SX_CRTSCTS(port->port.tty)) {
1873 if (clear & TIOCM_RTS) 1805 if (clear & TIOCM_RTS)
1874 port->MSVR &= ~MSVR_DTR; 1806 port->MSVR &= ~MSVR_DTR;
1875 } else { 1807 } else {
@@ -1886,14 +1818,17 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1886} 1818}
1887 1819
1888 1820
1889static inline void sx_send_break(struct specialix_port * port, unsigned long length) 1821static int sx_send_break(struct tty_struct *tty, int length)
1890{ 1822{
1823 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1891 struct specialix_board *bp = port_Board(port); 1824 struct specialix_board *bp = port_Board(port);
1892 unsigned long flags; 1825 unsigned long flags;
1893 1826
1894 func_enter(); 1827 func_enter();
1828 if (length == 0 || length == -1)
1829 return -EOPNOTSUPP;
1895 1830
1896 spin_lock_irqsave (&port->lock, flags); 1831 spin_lock_irqsave(&port->lock, flags);
1897 port->break_length = SPECIALIX_TPS / HZ * length; 1832 port->break_length = SPECIALIX_TPS / HZ * length;
1898 port->COR2 |= COR2_ETC; 1833 port->COR2 |= COR2_ETC;
1899 port->IER |= IER_TXRDY; 1834 port->IER |= IER_TXRDY;
@@ -1902,7 +1837,7 @@ static inline void sx_send_break(struct specialix_port * port, unsigned long len
1902 sx_out(bp, CD186x_COR2, port->COR2); 1837 sx_out(bp, CD186x_COR2, port->COR2);
1903 sx_out(bp, CD186x_IER, port->IER); 1838 sx_out(bp, CD186x_IER, port->IER);
1904 spin_unlock_irqrestore(&bp->lock, flags); 1839 spin_unlock_irqrestore(&bp->lock, flags);
1905 spin_unlock_irqrestore (&port->lock, flags); 1840 spin_unlock_irqrestore(&port->lock, flags);
1906 sx_wait_CCR(bp); 1841 sx_wait_CCR(bp);
1907 spin_lock_irqsave(&bp->lock, flags); 1842 spin_lock_irqsave(&bp->lock, flags);
1908 sx_out(bp, CD186x_CCR, CCR_CORCHG2); 1843 sx_out(bp, CD186x_CCR, CCR_CORCHG2);
@@ -1910,11 +1845,12 @@ static inline void sx_send_break(struct specialix_port * port, unsigned long len
1910 sx_wait_CCR(bp); 1845 sx_wait_CCR(bp);
1911 1846
1912 func_exit(); 1847 func_exit();
1848 return 0;
1913} 1849}
1914 1850
1915 1851
1916static inline int sx_set_serial_info(struct specialix_port * port, 1852static int sx_set_serial_info(struct specialix_port *port,
1917 struct serial_struct __user * newinfo) 1853 struct serial_struct __user *newinfo)
1918{ 1854{
1919 struct serial_struct tmp; 1855 struct serial_struct tmp;
1920 struct specialix_board *bp = port_Board(port); 1856 struct specialix_board *bp = port_Board(port);
@@ -1943,25 +1879,25 @@ static inline int sx_set_serial_info(struct specialix_port * port,
1943 return -EPERM; 1879 return -EPERM;
1944 } 1880 }
1945 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) | 1881 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) |
1946 (tmp.flags & ASYNC_USR_MASK)); 1882 (tmp.flags & ASYNC_USR_MASK));
1947 port->custom_divisor = tmp.custom_divisor; 1883 port->custom_divisor = tmp.custom_divisor;
1948 } else { 1884 } else {
1949 port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) | 1885 port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) |
1950 (tmp.flags & ASYNC_FLAGS)); 1886 (tmp.flags & ASYNC_FLAGS));
1951 port->port.close_delay = tmp.close_delay; 1887 port->port.close_delay = tmp.close_delay;
1952 port->port.closing_wait = tmp.closing_wait; 1888 port->port.closing_wait = tmp.closing_wait;
1953 port->custom_divisor = tmp.custom_divisor; 1889 port->custom_divisor = tmp.custom_divisor;
1954 } 1890 }
1955 if (change_speed) { 1891 if (change_speed)
1956 sx_change_speed(bp, port); 1892 sx_change_speed(bp, port);
1957 } 1893
1958 func_exit(); 1894 func_exit();
1959 unlock_kernel(); 1895 unlock_kernel();
1960 return 0; 1896 return 0;
1961} 1897}
1962 1898
1963 1899
1964static inline int sx_get_serial_info(struct specialix_port * port, 1900static int sx_get_serial_info(struct specialix_port *port,
1965 struct serial_struct __user *retinfo) 1901 struct serial_struct __user *retinfo)
1966{ 1902{
1967 struct serial_struct tmp; 1903 struct serial_struct tmp;
@@ -1992,11 +1928,10 @@ static inline int sx_get_serial_info(struct specialix_port * port,
1992} 1928}
1993 1929
1994 1930
1995static int sx_ioctl(struct tty_struct * tty, struct file * filp, 1931static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1996 unsigned int cmd, unsigned long arg) 1932 unsigned int cmd, unsigned long arg)
1997{ 1933{
1998 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1934 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1999 int retval;
2000 void __user *argp = (void __user *)arg; 1935 void __user *argp = (void __user *)arg;
2001 1936
2002 func_enter(); 1937 func_enter();
@@ -2007,34 +1942,14 @@ static int sx_ioctl(struct tty_struct * tty, struct file * filp,
2007 } 1942 }
2008 1943
2009 switch (cmd) { 1944 switch (cmd) {
2010 case TCSBRK: /* SVID version: non-zero arg --> no break */ 1945 case TIOCGSERIAL:
2011 retval = tty_check_change(tty);
2012 if (retval) {
2013 func_exit();
2014 return retval;
2015 }
2016 tty_wait_until_sent(tty, 0);
2017 if (!arg)
2018 sx_send_break(port, HZ/4); /* 1/4 second */
2019 return 0;
2020 case TCSBRKP: /* support for POSIX tcsendbreak() */
2021 retval = tty_check_change(tty);
2022 if (retval) {
2023 func_exit();
2024 return retval;
2025 }
2026 tty_wait_until_sent(tty, 0);
2027 sx_send_break(port, arg ? arg*(HZ/10) : HZ/4);
2028 func_exit(); 1946 func_exit();
2029 return 0;
2030 case TIOCGSERIAL:
2031 func_exit();
2032 return sx_get_serial_info(port, argp); 1947 return sx_get_serial_info(port, argp);
2033 case TIOCSSERIAL: 1948 case TIOCSSERIAL:
2034 func_exit(); 1949 func_exit();
2035 return sx_set_serial_info(port, argp); 1950 return sx_set_serial_info(port, argp);
2036 default: 1951 default:
2037 func_exit(); 1952 func_exit();
2038 return -ENOIOCTLCMD; 1953 return -ENOIOCTLCMD;
2039 } 1954 }
2040 func_exit(); 1955 func_exit();
@@ -2042,7 +1957,7 @@ static int sx_ioctl(struct tty_struct * tty, struct file * filp,
2042} 1957}
2043 1958
2044 1959
2045static void sx_throttle(struct tty_struct * tty) 1960static void sx_throttle(struct tty_struct *tty)
2046{ 1961{
2047 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1962 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2048 struct specialix_board *bp; 1963 struct specialix_board *bp;
@@ -2058,15 +1973,16 @@ static void sx_throttle(struct tty_struct * tty)
2058 bp = port_Board(port); 1973 bp = port_Board(port);
2059 1974
2060 /* Use DTR instead of RTS ! */ 1975 /* Use DTR instead of RTS ! */
2061 if (SX_CRTSCTS (tty)) 1976 if (sx_crtscts(tty))
2062 port->MSVR &= ~MSVR_DTR; 1977 port->MSVR &= ~MSVR_DTR;
2063 else { 1978 else {
2064 /* Auch!!! I think the system shouldn't call this then. */ 1979 /* Auch!!! I think the system shouldn't call this then. */
2065 /* Or maybe we're supposed (allowed?) to do our side of hw 1980 /* Or maybe we're supposed (allowed?) to do our side of hw
2066 handshake anyway, even when hardware handshake is off. 1981 handshake anyway, even when hardware handshake is off.
2067 When you see this in your logs, please report.... */ 1982 When you see this in your logs, please report.... */
2068 printk (KERN_ERR "sx%d: Need to throttle, but can't (hardware hs is off)\n", 1983 printk(KERN_ERR
2069 port_No (port)); 1984 "sx%d: Need to throttle, but can't (hardware hs is off)\n",
1985 port_No(port));
2070 } 1986 }
2071 spin_lock_irqsave(&bp->lock, flags); 1987 spin_lock_irqsave(&bp->lock, flags);
2072 sx_out(bp, CD186x_CAR, port_No(port)); 1988 sx_out(bp, CD186x_CAR, port_No(port));
@@ -2086,7 +2002,7 @@ static void sx_throttle(struct tty_struct * tty)
2086} 2002}
2087 2003
2088 2004
2089static void sx_unthrottle(struct tty_struct * tty) 2005static void sx_unthrottle(struct tty_struct *tty)
2090{ 2006{
2091 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2007 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2092 struct specialix_board *bp; 2008 struct specialix_board *bp;
@@ -2103,9 +2019,9 @@ static void sx_unthrottle(struct tty_struct * tty)
2103 2019
2104 spin_lock_irqsave(&port->lock, flags); 2020 spin_lock_irqsave(&port->lock, flags);
2105 /* XXXX Use DTR INSTEAD???? */ 2021 /* XXXX Use DTR INSTEAD???? */
2106 if (SX_CRTSCTS(tty)) { 2022 if (sx_crtscts(tty))
2107 port->MSVR |= MSVR_DTR; 2023 port->MSVR |= MSVR_DTR;
2108 } /* Else clause: see remark in "sx_throttle"... */ 2024 /* Else clause: see remark in "sx_throttle"... */
2109 spin_lock_irqsave(&bp->lock, flags); 2025 spin_lock_irqsave(&bp->lock, flags);
2110 sx_out(bp, CD186x_CAR, port_No(port)); 2026 sx_out(bp, CD186x_CAR, port_No(port));
2111 spin_unlock_irqrestore(&bp->lock, flags); 2027 spin_unlock_irqrestore(&bp->lock, flags);
@@ -2127,7 +2043,7 @@ static void sx_unthrottle(struct tty_struct * tty)
2127} 2043}
2128 2044
2129 2045
2130static void sx_stop(struct tty_struct * tty) 2046static void sx_stop(struct tty_struct *tty)
2131{ 2047{
2132 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2048 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2133 struct specialix_board *bp; 2049 struct specialix_board *bp;
@@ -2154,7 +2070,7 @@ static void sx_stop(struct tty_struct * tty)
2154} 2070}
2155 2071
2156 2072
2157static void sx_start(struct tty_struct * tty) 2073static void sx_start(struct tty_struct *tty)
2158{ 2074{
2159 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2075 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2160 struct specialix_board *bp; 2076 struct specialix_board *bp;
@@ -2182,7 +2098,7 @@ static void sx_start(struct tty_struct * tty)
2182 func_exit(); 2098 func_exit();
2183} 2099}
2184 2100
2185static void sx_hangup(struct tty_struct * tty) 2101static void sx_hangup(struct tty_struct *tty)
2186{ 2102{
2187 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2103 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2188 struct specialix_board *bp; 2104 struct specialix_board *bp;
@@ -2201,8 +2117,9 @@ static void sx_hangup(struct tty_struct * tty)
2201 spin_lock_irqsave(&port->lock, flags); 2117 spin_lock_irqsave(&port->lock, flags);
2202 bp->count -= port->port.count; 2118 bp->count -= port->port.count;
2203 if (bp->count < 0) { 2119 if (bp->count < 0) {
2204 printk(KERN_ERR "sx%d: sx_hangup: bad board count: %d port: %d\n", 2120 printk(KERN_ERR
2205 board_No(bp), bp->count, tty->index); 2121 "sx%d: sx_hangup: bad board count: %d port: %d\n",
2122 board_No(bp), bp->count, tty->index);
2206 bp->count = 0; 2123 bp->count = 0;
2207 } 2124 }
2208 port->port.count = 0; 2125 port->port.count = 0;
@@ -2215,11 +2132,12 @@ static void sx_hangup(struct tty_struct * tty)
2215} 2132}
2216 2133
2217 2134
2218static void sx_set_termios(struct tty_struct * tty, struct ktermios * old_termios) 2135static void sx_set_termios(struct tty_struct *tty,
2136 struct ktermios *old_termios)
2219{ 2137{
2220 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2138 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2221 unsigned long flags; 2139 unsigned long flags;
2222 struct specialix_board * bp; 2140 struct specialix_board *bp;
2223 2141
2224 if (sx_paranoia_check(port, tty->name, "sx_set_termios")) 2142 if (sx_paranoia_check(port, tty->name, "sx_set_termios"))
2225 return; 2143 return;
@@ -2254,6 +2172,7 @@ static const struct tty_operations sx_ops = {
2254 .hangup = sx_hangup, 2172 .hangup = sx_hangup,
2255 .tiocmget = sx_tiocmget, 2173 .tiocmget = sx_tiocmget,
2256 .tiocmset = sx_tiocmset, 2174 .tiocmset = sx_tiocmset,
2175 .break_ctl = sx_send_break,
2257}; 2176};
2258 2177
2259static int sx_init_drivers(void) 2178static int sx_init_drivers(void)
@@ -2280,13 +2199,16 @@ static int sx_init_drivers(void)
2280 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2199 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2281 specialix_driver->init_termios.c_ispeed = 9600; 2200 specialix_driver->init_termios.c_ispeed = 9600;
2282 specialix_driver->init_termios.c_ospeed = 9600; 2201 specialix_driver->init_termios.c_ospeed = 9600;
2283 specialix_driver->flags = TTY_DRIVER_REAL_RAW; 2202 specialix_driver->flags = TTY_DRIVER_REAL_RAW |
2203 TTY_DRIVER_HARDWARE_BREAK;
2284 tty_set_operations(specialix_driver, &sx_ops); 2204 tty_set_operations(specialix_driver, &sx_ops);
2285 2205
2286 if ((error = tty_register_driver(specialix_driver))) { 2206 error = tty_register_driver(specialix_driver);
2207 if (error) {
2287 put_tty_driver(specialix_driver); 2208 put_tty_driver(specialix_driver);
2288 printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n", 2209 printk(KERN_ERR
2289 error); 2210 "sx: Couldn't register specialix IO8+ driver, error = %d\n",
2211 error);
2290 func_exit(); 2212 func_exit();
2291 return 1; 2213 return 1;
2292 } 2214 }
@@ -2322,11 +2244,11 @@ static int __init specialix_init(void)
2322 2244
2323 printk(KERN_INFO "sx: Specialix IO8+ driver v" VERSION ", (c) R.E.Wolff 1997/1998.\n"); 2245 printk(KERN_INFO "sx: Specialix IO8+ driver v" VERSION ", (c) R.E.Wolff 1997/1998.\n");
2324 printk(KERN_INFO "sx: derived from work (c) D.Gorodchanin 1994-1996.\n"); 2246 printk(KERN_INFO "sx: derived from work (c) D.Gorodchanin 1994-1996.\n");
2325#ifdef CONFIG_SPECIALIX_RTSCTS 2247 if (sx_rtscts)
2326 printk (KERN_INFO "sx: DTR/RTS pin is always RTS.\n"); 2248 printk(KERN_INFO
2327#else 2249 "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n");
2328 printk (KERN_INFO "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n"); 2250 else
2329#endif 2251 printk(KERN_INFO "sx: DTR/RTS pin is always RTS.\n");
2330 2252
2331 for (i = 0; i < SX_NBOARD; i++) 2253 for (i = 0; i < SX_NBOARD; i++)
2332 spin_lock_init(&sx_board[i].lock); 2254 spin_lock_init(&sx_board[i].lock);
@@ -2344,27 +2266,27 @@ static int __init specialix_init(void)
2344 { 2266 {
2345 struct pci_dev *pdev = NULL; 2267 struct pci_dev *pdev = NULL;
2346 2268
2347 i=0; 2269 i = 0;
2348 while (i < SX_NBOARD) { 2270 while (i < SX_NBOARD) {
2349 if (sx_board[i].flags & SX_BOARD_PRESENT) { 2271 if (sx_board[i].flags & SX_BOARD_PRESENT) {
2350 i++; 2272 i++;
2351 continue; 2273 continue;
2352 } 2274 }
2353 pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX, 2275 pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX,
2354 PCI_DEVICE_ID_SPECIALIX_IO8, 2276 PCI_DEVICE_ID_SPECIALIX_IO8, pdev);
2355 pdev); 2277 if (!pdev)
2356 if (!pdev) break; 2278 break;
2357 2279
2358 if (pci_enable_device(pdev)) 2280 if (pci_enable_device(pdev))
2359 continue; 2281 continue;
2360 2282
2361 sx_board[i].irq = pdev->irq; 2283 sx_board[i].irq = pdev->irq;
2362 2284
2363 sx_board[i].base = pci_resource_start (pdev, 2); 2285 sx_board[i].base = pci_resource_start(pdev, 2);
2364 2286
2365 sx_board[i].flags |= SX_BOARD_IS_PCI; 2287 sx_board[i].flags |= SX_BOARD_IS_PCI;
2366 if (!sx_probe(&sx_board[i])) 2288 if (!sx_probe(&sx_board[i]))
2367 found ++; 2289 found++;
2368 } 2290 }
2369 /* May exit pci_get sequence early with lots of boards */ 2291 /* May exit pci_get sequence early with lots of boards */
2370 if (pdev != NULL) 2292 if (pdev != NULL)
@@ -2384,16 +2306,13 @@ static int __init specialix_init(void)
2384} 2306}
2385 2307
2386static int iobase[SX_NBOARD] = {0,}; 2308static int iobase[SX_NBOARD] = {0,};
2387 2309static int irq[SX_NBOARD] = {0,};
2388static int irq [SX_NBOARD] = {0,};
2389 2310
2390module_param_array(iobase, int, NULL, 0); 2311module_param_array(iobase, int, NULL, 0);
2391module_param_array(irq, int, NULL, 0); 2312module_param_array(irq, int, NULL, 0);
2392module_param(sx_debug, int, 0); 2313module_param(sx_debug, int, 0);
2314module_param(sx_rtscts, int, 0);
2393module_param(sx_rxfifo, int, 0); 2315module_param(sx_rxfifo, int, 0);
2394#ifdef SPECIALIX_TIMER
2395module_param(sx_poll, int, 0);
2396#endif
2397 2316
2398/* 2317/*
2399 * You can setup up to 4 boards. 2318 * You can setup up to 4 boards.
@@ -2411,10 +2330,10 @@ static int __init specialix_init_module(void)
2411 func_enter(); 2330 func_enter();
2412 2331
2413 if (iobase[0] || iobase[1] || iobase[2] || iobase[3]) { 2332 if (iobase[0] || iobase[1] || iobase[2] || iobase[3]) {
2414 for(i = 0; i < SX_NBOARD; i++) { 2333 for (i = 0; i < SX_NBOARD; i++) {
2415 sx_board[i].base = iobase[i]; 2334 sx_board[i].base = iobase[i];
2416 sx_board[i].irq = irq[i]; 2335 sx_board[i].irq = irq[i];
2417 sx_board[i].count= 0; 2336 sx_board[i].count = 0;
2418 } 2337 }
2419 } 2338 }
2420 2339
@@ -2433,10 +2352,6 @@ static void __exit specialix_exit_module(void)
2433 for (i = 0; i < SX_NBOARD; i++) 2352 for (i = 0; i < SX_NBOARD; i++)
2434 if (sx_board[i].flags & SX_BOARD_PRESENT) 2353 if (sx_board[i].flags & SX_BOARD_PRESENT)
2435 sx_release_io_range(&sx_board[i]); 2354 sx_release_io_range(&sx_board[i]);
2436#ifdef SPECIALIX_TIMER
2437 del_timer_sync(&missed_irq_timer);
2438#endif
2439
2440 func_exit(); 2355 func_exit();
2441} 2356}
2442 2357
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 0243efb0be95..b976248e1072 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -1025,7 +1025,7 @@ static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count
1025 1025
1026/*****************************************************************************/ 1026/*****************************************************************************/
1027 1027
1028static void stl_putchar(struct tty_struct *tty, unsigned char ch) 1028static int stl_putchar(struct tty_struct *tty, unsigned char ch)
1029{ 1029{
1030 struct stlport *portp; 1030 struct stlport *portp;
1031 unsigned int len; 1031 unsigned int len;
@@ -1034,12 +1034,12 @@ static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1034 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch); 1034 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1035 1035
1036 if (tty == NULL) 1036 if (tty == NULL)
1037 return; 1037 return -EINVAL;
1038 portp = tty->driver_data; 1038 portp = tty->driver_data;
1039 if (portp == NULL) 1039 if (portp == NULL)
1040 return; 1040 return -EINVAL;
1041 if (portp->tx.buf == NULL) 1041 if (portp->tx.buf == NULL)
1042 return; 1042 return -EINVAL;
1043 1043
1044 head = portp->tx.head; 1044 head = portp->tx.head;
1045 tail = portp->tx.tail; 1045 tail = portp->tx.tail;
@@ -1053,6 +1053,7 @@ static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1053 head = portp->tx.buf; 1053 head = portp->tx.buf;
1054 } 1054 }
1055 portp->tx.head = head; 1055 portp->tx.head = head;
1056 return 0;
1056} 1057}
1057 1058
1058/*****************************************************************************/ 1059/*****************************************************************************/
@@ -1460,19 +1461,20 @@ static void stl_hangup(struct tty_struct *tty)
1460 1461
1461/*****************************************************************************/ 1462/*****************************************************************************/
1462 1463
1463static void stl_breakctl(struct tty_struct *tty, int state) 1464static int stl_breakctl(struct tty_struct *tty, int state)
1464{ 1465{
1465 struct stlport *portp; 1466 struct stlport *portp;
1466 1467
1467 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state); 1468 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1468 1469
1469 if (tty == NULL) 1470 if (tty == NULL)
1470 return; 1471 return -EINVAL;
1471 portp = tty->driver_data; 1472 portp = tty->driver_data;
1472 if (portp == NULL) 1473 if (portp == NULL)
1473 return; 1474 return -EINVAL;
1474 1475
1475 stl_sendbreak(portp, ((state == -1) ? 1 : 2)); 1476 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1477 return 0;
1476} 1478}
1477 1479
1478/*****************************************************************************/ 1480/*****************************************************************************/
@@ -4753,8 +4755,8 @@ static int __init stallion_module_init(void)
4753 if (IS_ERR(stallion_class)) 4755 if (IS_ERR(stallion_class))
4754 printk("STALLION: failed to create class\n"); 4756 printk("STALLION: failed to create class\n");
4755 for (i = 0; i < 4; i++) 4757 for (i = 0; i < 4; i++)
4756 device_create(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i), 4758 device_create_drvdata(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i),
4757 "staliomem%d", i); 4759 NULL, "staliomem%d", i);
4758 4760
4759 return 0; 4761 return 0;
4760err_unrtty: 4762err_unrtty:
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index d5cffcd6a572..2162439bbe48 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -1840,7 +1840,7 @@ static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1840 return rc; 1840 return rc;
1841} 1841}
1842 1842
1843static void sx_break(struct tty_struct *tty, int flag) 1843static int sx_break(struct tty_struct *tty, int flag)
1844{ 1844{
1845 struct sx_port *port = tty->driver_data; 1845 struct sx_port *port = tty->driver_data;
1846 int rv; 1846 int rv;
@@ -1857,6 +1857,7 @@ static void sx_break(struct tty_struct *tty, int flag)
1857 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat))); 1857 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat)));
1858 unlock_kernel(); 1858 unlock_kernel();
1859 func_exit(); 1859 func_exit();
1860 return 0;
1860} 1861}
1861 1862
1862static int sx_tiocmget(struct tty_struct *tty, struct file *file) 1863static int sx_tiocmget(struct tty_struct *tty, struct file *file)
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 527d220aa4aa..ef6706f09061 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -2897,9 +2897,9 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
2897 * 2897 *
2898 * Arguments: tty pointer to tty instance data 2898 * Arguments: tty pointer to tty instance data
2899 * break_state -1=set break condition, 0=clear 2899 * break_state -1=set break condition, 0=clear
2900 * Return Value: None 2900 * Return Value: error code
2901 */ 2901 */
2902static void mgsl_break(struct tty_struct *tty, int break_state) 2902static int mgsl_break(struct tty_struct *tty, int break_state)
2903{ 2903{
2904 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; 2904 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data;
2905 unsigned long flags; 2905 unsigned long flags;
@@ -2909,7 +2909,7 @@ static void mgsl_break(struct tty_struct *tty, int break_state)
2909 __FILE__,__LINE__, info->device_name, break_state); 2909 __FILE__,__LINE__, info->device_name, break_state);
2910 2910
2911 if (mgsl_paranoia_check(info, tty->name, "mgsl_break")) 2911 if (mgsl_paranoia_check(info, tty->name, "mgsl_break"))
2912 return; 2912 return -EINVAL;
2913 2913
2914 spin_lock_irqsave(&info->irq_spinlock,flags); 2914 spin_lock_irqsave(&info->irq_spinlock,flags);
2915 if (break_state == -1) 2915 if (break_state == -1)
@@ -2917,6 +2917,7 @@ static void mgsl_break(struct tty_struct *tty, int break_state)
2917 else 2917 else
2918 usc_OutReg(info,IOCR,(u16)(usc_InReg(info,IOCR) & ~BIT7)); 2918 usc_OutReg(info,IOCR,(u16)(usc_InReg(info,IOCR) & ~BIT7));
2919 spin_unlock_irqrestore(&info->irq_spinlock,flags); 2919 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2920 return 0;
2920 2921
2921} /* end of mgsl_break() */ 2922} /* end of mgsl_break() */
2922 2923
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 2c3e43bb2cc9..3e9058993e41 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -165,7 +165,7 @@ static int read_proc(char *page, char **start, off_t off, int count,int *eof, v
165static int chars_in_buffer(struct tty_struct *tty); 165static int chars_in_buffer(struct tty_struct *tty);
166static void throttle(struct tty_struct * tty); 166static void throttle(struct tty_struct * tty);
167static void unthrottle(struct tty_struct * tty); 167static void unthrottle(struct tty_struct * tty);
168static void set_break(struct tty_struct *tty, int break_state); 168static int set_break(struct tty_struct *tty, int break_state);
169 169
170/* 170/*
171 * generic HDLC support and callbacks 171 * generic HDLC support and callbacks
@@ -214,6 +214,7 @@ struct slgt_desc
214 char *buf; /* virtual address of data buffer */ 214 char *buf; /* virtual address of data buffer */
215 unsigned int pdesc; /* physical address of this descriptor */ 215 unsigned int pdesc; /* physical address of this descriptor */
216 dma_addr_t buf_dma_addr; 216 dma_addr_t buf_dma_addr;
217 unsigned short buf_count;
217}; 218};
218 219
219#define set_desc_buffer(a,b) (a).pbuf = cpu_to_le32((unsigned int)(b)) 220#define set_desc_buffer(a,b) (a).pbuf = cpu_to_le32((unsigned int)(b))
@@ -302,7 +303,7 @@ struct slgt_info {
302 u32 idle_mode; 303 u32 idle_mode;
303 u32 max_frame_size; /* as set by device config */ 304 u32 max_frame_size; /* as set by device config */
304 305
305 unsigned int raw_rx_size; 306 unsigned int rbuf_fill_level;
306 unsigned int if_mode; 307 unsigned int if_mode;
307 308
308 /* device status */ 309 /* device status */
@@ -466,6 +467,7 @@ static void tx_start(struct slgt_info *info);
466static void tx_stop(struct slgt_info *info); 467static void tx_stop(struct slgt_info *info);
467static void tx_set_idle(struct slgt_info *info); 468static void tx_set_idle(struct slgt_info *info);
468static unsigned int free_tbuf_count(struct slgt_info *info); 469static unsigned int free_tbuf_count(struct slgt_info *info);
470static unsigned int tbuf_bytes(struct slgt_info *info);
469static void reset_tbufs(struct slgt_info *info); 471static void reset_tbufs(struct slgt_info *info);
470static void tdma_reset(struct slgt_info *info); 472static void tdma_reset(struct slgt_info *info);
471static void tdma_start(struct slgt_info *info); 473static void tdma_start(struct slgt_info *info);
@@ -513,7 +515,7 @@ static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr);
513static int tiocmget(struct tty_struct *tty, struct file *file); 515static int tiocmget(struct tty_struct *tty, struct file *file);
514static int tiocmset(struct tty_struct *tty, struct file *file, 516static int tiocmset(struct tty_struct *tty, struct file *file,
515 unsigned int set, unsigned int clear); 517 unsigned int set, unsigned int clear);
516static void set_break(struct tty_struct *tty, int break_state); 518static int set_break(struct tty_struct *tty, int break_state);
517static int get_interface(struct slgt_info *info, int __user *if_mode); 519static int get_interface(struct slgt_info *info, int __user *if_mode);
518static int set_interface(struct slgt_info *info, int if_mode); 520static int set_interface(struct slgt_info *info, int if_mode);
519static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio); 521static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
@@ -849,6 +851,7 @@ static int write(struct tty_struct *tty,
849 int ret = 0; 851 int ret = 0;
850 struct slgt_info *info = tty->driver_data; 852 struct slgt_info *info = tty->driver_data;
851 unsigned long flags; 853 unsigned long flags;
854 unsigned int bufs_needed;
852 855
853 if (sanity_check(info, tty->name, "write")) 856 if (sanity_check(info, tty->name, "write"))
854 goto cleanup; 857 goto cleanup;
@@ -865,25 +868,16 @@ static int write(struct tty_struct *tty,
865 if (!count) 868 if (!count)
866 goto cleanup; 869 goto cleanup;
867 870
868 if (info->params.mode == MGSL_MODE_RAW || 871 if (!info->tx_active && info->tx_count) {
869 info->params.mode == MGSL_MODE_MONOSYNC || 872 /* send accumulated data from send_char() */
870 info->params.mode == MGSL_MODE_BISYNC) { 873 tx_load(info, info->tx_buf, info->tx_count);
871 unsigned int bufs_needed = (count/DMABUFSIZE); 874 goto start;
872 unsigned int bufs_free = free_tbuf_count(info);
873 if (count % DMABUFSIZE)
874 ++bufs_needed;
875 if (bufs_needed > bufs_free)
876 goto cleanup;
877 } else {
878 if (info->tx_active)
879 goto cleanup;
880 if (info->tx_count) {
881 /* send accumulated data from send_char() calls */
882 /* as frame and wait before accepting more data. */
883 tx_load(info, info->tx_buf, info->tx_count);
884 goto start;
885 }
886 } 875 }
876 bufs_needed = (count/DMABUFSIZE);
877 if (count % DMABUFSIZE)
878 ++bufs_needed;
879 if (bufs_needed > free_tbuf_count(info))
880 goto cleanup;
887 881
888 ret = info->tx_count = count; 882 ret = info->tx_count = count;
889 tx_load(info, buf, count); 883 tx_load(info, buf, count);
@@ -1396,10 +1390,12 @@ done:
1396static int chars_in_buffer(struct tty_struct *tty) 1390static int chars_in_buffer(struct tty_struct *tty)
1397{ 1391{
1398 struct slgt_info *info = tty->driver_data; 1392 struct slgt_info *info = tty->driver_data;
1393 int count;
1399 if (sanity_check(info, tty->name, "chars_in_buffer")) 1394 if (sanity_check(info, tty->name, "chars_in_buffer"))
1400 return 0; 1395 return 0;
1401 DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, info->tx_count)); 1396 count = tbuf_bytes(info);
1402 return info->tx_count; 1397 DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, count));
1398 return count;
1403} 1399}
1404 1400
1405/* 1401/*
@@ -1452,14 +1448,14 @@ static void unthrottle(struct tty_struct * tty)
1452 * set or clear transmit break condition 1448 * set or clear transmit break condition
1453 * break_state -1=set break condition, 0=clear 1449 * break_state -1=set break condition, 0=clear
1454 */ 1450 */
1455static void set_break(struct tty_struct *tty, int break_state) 1451static int set_break(struct tty_struct *tty, int break_state)
1456{ 1452{
1457 struct slgt_info *info = tty->driver_data; 1453 struct slgt_info *info = tty->driver_data;
1458 unsigned short value; 1454 unsigned short value;
1459 unsigned long flags; 1455 unsigned long flags;
1460 1456
1461 if (sanity_check(info, tty->name, "set_break")) 1457 if (sanity_check(info, tty->name, "set_break"))
1462 return; 1458 return -EINVAL;
1463 DBGINFO(("%s set_break(%d)\n", info->device_name, break_state)); 1459 DBGINFO(("%s set_break(%d)\n", info->device_name, break_state));
1464 1460
1465 spin_lock_irqsave(&info->lock,flags); 1461 spin_lock_irqsave(&info->lock,flags);
@@ -1470,6 +1466,7 @@ static void set_break(struct tty_struct *tty, int break_state)
1470 value &= ~BIT6; 1466 value &= ~BIT6;
1471 wr_reg16(info, TCR, value); 1467 wr_reg16(info, TCR, value);
1472 spin_unlock_irqrestore(&info->lock,flags); 1468 spin_unlock_irqrestore(&info->lock,flags);
1469 return 0;
1473} 1470}
1474 1471
1475#if SYNCLINK_GENERIC_HDLC 1472#if SYNCLINK_GENERIC_HDLC
@@ -2679,8 +2676,31 @@ static int tx_abort(struct slgt_info *info)
2679static int rx_enable(struct slgt_info *info, int enable) 2676static int rx_enable(struct slgt_info *info, int enable)
2680{ 2677{
2681 unsigned long flags; 2678 unsigned long flags;
2682 DBGINFO(("%s rx_enable(%d)\n", info->device_name, enable)); 2679 unsigned int rbuf_fill_level;
2680 DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable));
2683 spin_lock_irqsave(&info->lock,flags); 2681 spin_lock_irqsave(&info->lock,flags);
2682 /*
2683 * enable[31..16] = receive DMA buffer fill level
2684 * 0 = noop (leave fill level unchanged)
2685 * fill level must be multiple of 4 and <= buffer size
2686 */
2687 rbuf_fill_level = ((unsigned int)enable) >> 16;
2688 if (rbuf_fill_level) {
2689 if ((rbuf_fill_level > DMABUFSIZE) || (rbuf_fill_level % 4)) {
2690 spin_unlock_irqrestore(&info->lock, flags);
2691 return -EINVAL;
2692 }
2693 info->rbuf_fill_level = rbuf_fill_level;
2694 rx_stop(info); /* restart receiver to use new fill level */
2695 }
2696
2697 /*
2698 * enable[1..0] = receiver enable command
2699 * 0 = disable
2700 * 1 = enable
2701 * 2 = enable or force hunt mode if already enabled
2702 */
2703 enable &= 3;
2684 if (enable) { 2704 if (enable) {
2685 if (!info->rx_enabled) 2705 if (!info->rx_enabled)
2686 rx_start(info); 2706 rx_start(info);
@@ -3447,7 +3467,7 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
3447 info->magic = MGSL_MAGIC; 3467 info->magic = MGSL_MAGIC;
3448 INIT_WORK(&info->task, bh_handler); 3468 INIT_WORK(&info->task, bh_handler);
3449 info->max_frame_size = 4096; 3469 info->max_frame_size = 4096;
3450 info->raw_rx_size = DMABUFSIZE; 3470 info->rbuf_fill_level = DMABUFSIZE;
3451 info->port.close_delay = 5*HZ/10; 3471 info->port.close_delay = 5*HZ/10;
3452 info->port.closing_wait = 30*HZ; 3472 info->port.closing_wait = 30*HZ;
3453 init_waitqueue_head(&info->status_event_wait_q); 3473 init_waitqueue_head(&info->status_event_wait_q);
@@ -3934,15 +3954,7 @@ static void tdma_start(struct slgt_info *info)
3934 3954
3935 /* set 1st descriptor address */ 3955 /* set 1st descriptor address */
3936 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); 3956 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
3937 switch(info->params.mode) { 3957 wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */
3938 case MGSL_MODE_RAW:
3939 case MGSL_MODE_MONOSYNC:
3940 case MGSL_MODE_BISYNC:
3941 wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */
3942 break;
3943 default:
3944 wr_reg32(info, TDCSR, BIT0); /* DMA enable */
3945 }
3946} 3958}
3947 3959
3948static void tx_stop(struct slgt_info *info) 3960static void tx_stop(struct slgt_info *info)
@@ -4145,7 +4157,7 @@ static void sync_mode(struct slgt_info *info)
4145 * 01 enable 4157 * 01 enable
4146 * 00 auto-CTS enable 4158 * 00 auto-CTS enable
4147 */ 4159 */
4148 val = 0; 4160 val = BIT2;
4149 4161
4150 switch(info->params.mode) { 4162 switch(info->params.mode) {
4151 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break; 4163 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
@@ -4418,6 +4430,8 @@ static void msc_set_vcr(struct slgt_info *info)
4418 break; 4430 break;
4419 } 4431 }
4420 4432
4433 if (info->if_mode & MGSL_INTERFACE_MSB_FIRST)
4434 val |= BIT4;
4421 if (info->signals & SerialSignal_DTR) 4435 if (info->signals & SerialSignal_DTR)
4422 val |= BIT3; 4436 val |= BIT3;
4423 if (info->signals & SerialSignal_RTS) 4437 if (info->signals & SerialSignal_RTS)
@@ -4456,16 +4470,7 @@ static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last
4456 while(!done) { 4470 while(!done) {
4457 /* reset current buffer for reuse */ 4471 /* reset current buffer for reuse */
4458 info->rbufs[i].status = 0; 4472 info->rbufs[i].status = 0;
4459 switch(info->params.mode) { 4473 set_desc_count(info->rbufs[i], info->rbuf_fill_level);
4460 case MGSL_MODE_RAW:
4461 case MGSL_MODE_MONOSYNC:
4462 case MGSL_MODE_BISYNC:
4463 set_desc_count(info->rbufs[i], info->raw_rx_size);
4464 break;
4465 default:
4466 set_desc_count(info->rbufs[i], DMABUFSIZE);
4467 }
4468
4469 if (i == last) 4474 if (i == last)
4470 done = 1; 4475 done = 1;
4471 if (++i == info->rbuf_count) 4476 if (++i == info->rbuf_count)
@@ -4572,7 +4577,7 @@ check_again:
4572 4577
4573 DBGBH(("%s rx frame status=%04X size=%d\n", 4578 DBGBH(("%s rx frame status=%04X size=%d\n",
4574 info->device_name, status, framesize)); 4579 info->device_name, status, framesize));
4575 DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, DMABUFSIZE), "rx"); 4580 DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx");
4576 4581
4577 if (framesize) { 4582 if (framesize) {
4578 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) { 4583 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) {
@@ -4592,7 +4597,7 @@ check_again:
4592 info->icount.rxok++; 4597 info->icount.rxok++;
4593 4598
4594 while(copy_count) { 4599 while(copy_count) {
4595 int partial_count = min(copy_count, DMABUFSIZE); 4600 int partial_count = min_t(int, copy_count, info->rbuf_fill_level);
4596 memcpy(p, info->rbufs[i].buf, partial_count); 4601 memcpy(p, info->rbufs[i].buf, partial_count);
4597 p += partial_count; 4602 p += partial_count;
4598 copy_count -= partial_count; 4603 copy_count -= partial_count;
@@ -4684,6 +4689,56 @@ static unsigned int free_tbuf_count(struct slgt_info *info)
4684} 4689}
4685 4690
4686/* 4691/*
4692 * return number of bytes in unsent transmit DMA buffers
4693 * and the serial controller tx FIFO
4694 */
4695static unsigned int tbuf_bytes(struct slgt_info *info)
4696{
4697 unsigned int total_count = 0;
4698 unsigned int i = info->tbuf_current;
4699 unsigned int reg_value;
4700 unsigned int count;
4701 unsigned int active_buf_count = 0;
4702
4703 /*
4704 * Add descriptor counts for all tx DMA buffers.
4705 * If count is zero (cleared by DMA controller after read),
4706 * the buffer is complete or is actively being read from.
4707 *
4708 * Record buf_count of last buffer with zero count starting
4709 * from current ring position. buf_count is mirror
4710 * copy of count and is not cleared by serial controller.
4711 * If DMA controller is active, that buffer is actively
4712 * being read so add to total.
4713 */
4714 do {
4715 count = desc_count(info->tbufs[i]);
4716 if (count)
4717 total_count += count;
4718 else if (!total_count)
4719 active_buf_count = info->tbufs[i].buf_count;
4720 if (++i == info->tbuf_count)
4721 i = 0;
4722 } while (i != info->tbuf_current);
4723
4724 /* read tx DMA status register */
4725 reg_value = rd_reg32(info, TDCSR);
4726
4727 /* if tx DMA active, last zero count buffer is in use */
4728 if (reg_value & BIT0)
4729 total_count += active_buf_count;
4730
4731 /* add tx FIFO count = reg_value[15..8] */
4732 total_count += (reg_value >> 8) & 0xff;
4733
4734 /* if transmitter active add one byte for shift register */
4735 if (info->tx_active)
4736 total_count++;
4737
4738 return total_count;
4739}
4740
4741/*
4687 * load transmit DMA buffer(s) with data 4742 * load transmit DMA buffer(s) with data
4688 */ 4743 */
4689static void tx_load(struct slgt_info *info, const char *buf, unsigned int size) 4744static void tx_load(struct slgt_info *info, const char *buf, unsigned int size)
@@ -4721,6 +4776,7 @@ static void tx_load(struct slgt_info *info, const char *buf, unsigned int size)
4721 set_desc_eof(*d, 0); 4776 set_desc_eof(*d, 0);
4722 4777
4723 set_desc_count(*d, count); 4778 set_desc_count(*d, count);
4779 d->buf_count = count;
4724 } 4780 }
4725 4781
4726 info->tbuf_current = i; 4782 info->tbuf_current = i;
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 5768c4136342..c0490cbd0db2 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -527,7 +527,7 @@ static int read_proc(char *page, char **start, off_t off, int count,int *eof, v
527static int chars_in_buffer(struct tty_struct *tty); 527static int chars_in_buffer(struct tty_struct *tty);
528static void throttle(struct tty_struct * tty); 528static void throttle(struct tty_struct * tty);
529static void unthrottle(struct tty_struct * tty); 529static void unthrottle(struct tty_struct * tty);
530static void set_break(struct tty_struct *tty, int break_state); 530static int set_break(struct tty_struct *tty, int break_state);
531 531
532#if SYNCLINK_GENERIC_HDLC 532#if SYNCLINK_GENERIC_HDLC
533#define dev_to_port(D) (dev_to_hdlc(D)->priv) 533#define dev_to_port(D) (dev_to_hdlc(D)->priv)
@@ -552,7 +552,7 @@ static int wait_mgsl_event(SLMP_INFO *info, int __user *mask_ptr);
552static int tiocmget(struct tty_struct *tty, struct file *file); 552static int tiocmget(struct tty_struct *tty, struct file *file);
553static int tiocmset(struct tty_struct *tty, struct file *file, 553static int tiocmset(struct tty_struct *tty, struct file *file,
554 unsigned int set, unsigned int clear); 554 unsigned int set, unsigned int clear);
555static void set_break(struct tty_struct *tty, int break_state); 555static int set_break(struct tty_struct *tty, int break_state);
556 556
557static void add_device(SLMP_INFO *info); 557static void add_device(SLMP_INFO *info);
558static void device_init(int adapter_num, struct pci_dev *pdev); 558static void device_init(int adapter_num, struct pci_dev *pdev);
@@ -1587,7 +1587,7 @@ static void unthrottle(struct tty_struct * tty)
1587/* set or clear transmit break condition 1587/* set or clear transmit break condition
1588 * break_state -1=set break condition, 0=clear 1588 * break_state -1=set break condition, 0=clear
1589 */ 1589 */
1590static void set_break(struct tty_struct *tty, int break_state) 1590static int set_break(struct tty_struct *tty, int break_state)
1591{ 1591{
1592 unsigned char RegValue; 1592 unsigned char RegValue;
1593 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data; 1593 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
@@ -1598,7 +1598,7 @@ static void set_break(struct tty_struct *tty, int break_state)
1598 __FILE__,__LINE__, info->device_name, break_state); 1598 __FILE__,__LINE__, info->device_name, break_state);
1599 1599
1600 if (sanity_check(info, tty->name, "set_break")) 1600 if (sanity_check(info, tty->name, "set_break"))
1601 return; 1601 return -EINVAL;
1602 1602
1603 spin_lock_irqsave(&info->lock,flags); 1603 spin_lock_irqsave(&info->lock,flags);
1604 RegValue = read_reg(info, CTL); 1604 RegValue = read_reg(info, CTL);
@@ -1608,6 +1608,7 @@ static void set_break(struct tty_struct *tty, int break_state)
1608 RegValue &= ~BIT3; 1608 RegValue &= ~BIT3;
1609 write_reg(info, CTL, RegValue); 1609 write_reg(info, CTL, RegValue);
1610 spin_unlock_irqrestore(&info->lock,flags); 1610 spin_unlock_irqrestore(&info->lock,flags);
1611 return 0;
1611} 1612}
1612 1613
1613#if SYNCLINK_GENERIC_HDLC 1614#if SYNCLINK_GENERIC_HDLC
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 82f6a8c86332..15e597d03002 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -656,558 +656,6 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
656 656
657 657
658/** 658/**
659 * tty_set_termios_ldisc - set ldisc field
660 * @tty: tty structure
661 * @num: line discipline number
662 *
663 * This is probably overkill for real world processors but
664 * they are not on hot paths so a little discipline won't do
665 * any harm.
666 *
667 * Locking: takes termios_mutex
668 */
669
670static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
671{
672 mutex_lock(&tty->termios_mutex);
673 tty->termios->c_line = num;
674 mutex_unlock(&tty->termios_mutex);
675}
676
677/*
678 * This guards the refcounted line discipline lists. The lock
679 * must be taken with irqs off because there are hangup path
680 * callers who will do ldisc lookups and cannot sleep.
681 */
682
683static DEFINE_SPINLOCK(tty_ldisc_lock);
684static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
685/* Line disc dispatch table */
686static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS];
687
688/**
689 * tty_register_ldisc - install a line discipline
690 * @disc: ldisc number
691 * @new_ldisc: pointer to the ldisc object
692 *
693 * Installs a new line discipline into the kernel. The discipline
694 * is set up as unreferenced and then made available to the kernel
695 * from this point onwards.
696 *
697 * Locking:
698 * takes tty_ldisc_lock to guard against ldisc races
699 */
700
701int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
702{
703 unsigned long flags;
704 int ret = 0;
705
706 if (disc < N_TTY || disc >= NR_LDISCS)
707 return -EINVAL;
708
709 spin_lock_irqsave(&tty_ldisc_lock, flags);
710 tty_ldiscs[disc] = new_ldisc;
711 new_ldisc->num = disc;
712 new_ldisc->refcount = 0;
713 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
714
715 return ret;
716}
717EXPORT_SYMBOL(tty_register_ldisc);
718
719/**
720 * tty_unregister_ldisc - unload a line discipline
721 * @disc: ldisc number
722 * @new_ldisc: pointer to the ldisc object
723 *
724 * Remove a line discipline from the kernel providing it is not
725 * currently in use.
726 *
727 * Locking:
728 * takes tty_ldisc_lock to guard against ldisc races
729 */
730
731int tty_unregister_ldisc(int disc)
732{
733 unsigned long flags;
734 int ret = 0;
735
736 if (disc < N_TTY || disc >= NR_LDISCS)
737 return -EINVAL;
738
739 spin_lock_irqsave(&tty_ldisc_lock, flags);
740 if (tty_ldiscs[disc]->refcount)
741 ret = -EBUSY;
742 else
743 tty_ldiscs[disc] = NULL;
744 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
745
746 return ret;
747}
748EXPORT_SYMBOL(tty_unregister_ldisc);
749
750
751/**
752 * tty_ldisc_try_get - try and reference an ldisc
753 * @disc: ldisc number
754 * @ld: tty ldisc structure to complete
755 *
756 * Attempt to open and lock a line discipline into place. Return
757 * the line discipline refcounted and assigned in ld. On an error
758 * report the error code back
759 */
760
761static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld)
762{
763 unsigned long flags;
764 struct tty_ldisc_ops *ldops;
765 int err = -EINVAL;
766
767 spin_lock_irqsave(&tty_ldisc_lock, flags);
768 ld->ops = NULL;
769 ldops = tty_ldiscs[disc];
770 /* Check the entry is defined */
771 if (ldops) {
772 /* If the module is being unloaded we can't use it */
773 if (!try_module_get(ldops->owner))
774 err = -EAGAIN;
775 else {
776 /* lock it */
777 ldops->refcount++;
778 ld->ops = ldops;
779 err = 0;
780 }
781 }
782 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
783 return err;
784}
785
786/**
787 * tty_ldisc_get - take a reference to an ldisc
788 * @disc: ldisc number
789 * @ld: tty line discipline structure to use
790 *
791 * Takes a reference to a line discipline. Deals with refcounts and
792 * module locking counts. Returns NULL if the discipline is not available.
793 * Returns a pointer to the discipline and bumps the ref count if it is
794 * available
795 *
796 * Locking:
797 * takes tty_ldisc_lock to guard against ldisc races
798 */
799
800static int tty_ldisc_get(int disc, struct tty_ldisc *ld)
801{
802 int err;
803
804 if (disc < N_TTY || disc >= NR_LDISCS)
805 return -EINVAL;
806 err = tty_ldisc_try_get(disc, ld);
807 if (err == -EAGAIN) {
808 request_module("tty-ldisc-%d", disc);
809 err = tty_ldisc_try_get(disc, ld);
810 }
811 return err;
812}
813
814/**
815 * tty_ldisc_put - drop ldisc reference
816 * @disc: ldisc number
817 *
818 * Drop a reference to a line discipline. Manage refcounts and
819 * module usage counts
820 *
821 * Locking:
822 * takes tty_ldisc_lock to guard against ldisc races
823 */
824
825static void tty_ldisc_put(struct tty_ldisc_ops *ld)
826{
827 unsigned long flags;
828 int disc = ld->num;
829
830 BUG_ON(disc < N_TTY || disc >= NR_LDISCS);
831
832 spin_lock_irqsave(&tty_ldisc_lock, flags);
833 ld = tty_ldiscs[disc];
834 BUG_ON(ld->refcount == 0);
835 ld->refcount--;
836 module_put(ld->owner);
837 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
838}
839
840static void * tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos)
841{
842 return (*pos < NR_LDISCS) ? pos : NULL;
843}
844
845static void * tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos)
846{
847 (*pos)++;
848 return (*pos < NR_LDISCS) ? pos : NULL;
849}
850
851static void tty_ldiscs_seq_stop(struct seq_file *m, void *v)
852{
853}
854
855static int tty_ldiscs_seq_show(struct seq_file *m, void *v)
856{
857 int i = *(loff_t *)v;
858 struct tty_ldisc ld;
859
860 if (tty_ldisc_get(i, &ld) < 0)
861 return 0;
862 seq_printf(m, "%-10s %2d\n", ld.ops->name ? ld.ops->name : "???", i);
863 tty_ldisc_put(ld.ops);
864 return 0;
865}
866
867static const struct seq_operations tty_ldiscs_seq_ops = {
868 .start = tty_ldiscs_seq_start,
869 .next = tty_ldiscs_seq_next,
870 .stop = tty_ldiscs_seq_stop,
871 .show = tty_ldiscs_seq_show,
872};
873
874static int proc_tty_ldiscs_open(struct inode *inode, struct file *file)
875{
876 return seq_open(file, &tty_ldiscs_seq_ops);
877}
878
879const struct file_operations tty_ldiscs_proc_fops = {
880 .owner = THIS_MODULE,
881 .open = proc_tty_ldiscs_open,
882 .read = seq_read,
883 .llseek = seq_lseek,
884 .release = seq_release,
885};
886
887/**
888 * tty_ldisc_assign - set ldisc on a tty
889 * @tty: tty to assign
890 * @ld: line discipline
891 *
892 * Install an instance of a line discipline into a tty structure. The
893 * ldisc must have a reference count above zero to ensure it remains/
894 * The tty instance refcount starts at zero.
895 *
896 * Locking:
897 * Caller must hold references
898 */
899
900static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld)
901{
902 ld->refcount = 0;
903 tty->ldisc = *ld;
904}
905
906/**
907 * tty_ldisc_try - internal helper
908 * @tty: the tty
909 *
910 * Make a single attempt to grab and bump the refcount on
911 * the tty ldisc. Return 0 on failure or 1 on success. This is
912 * used to implement both the waiting and non waiting versions
913 * of tty_ldisc_ref
914 *
915 * Locking: takes tty_ldisc_lock
916 */
917
918static int tty_ldisc_try(struct tty_struct *tty)
919{
920 unsigned long flags;
921 struct tty_ldisc *ld;
922 int ret = 0;
923
924 spin_lock_irqsave(&tty_ldisc_lock, flags);
925 ld = &tty->ldisc;
926 if (test_bit(TTY_LDISC, &tty->flags)) {
927 ld->refcount++;
928 ret = 1;
929 }
930 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
931 return ret;
932}
933
934/**
935 * tty_ldisc_ref_wait - wait for the tty ldisc
936 * @tty: tty device
937 *
938 * Dereference the line discipline for the terminal and take a
939 * reference to it. If the line discipline is in flux then
940 * wait patiently until it changes.
941 *
942 * Note: Must not be called from an IRQ/timer context. The caller
943 * must also be careful not to hold other locks that will deadlock
944 * against a discipline change, such as an existing ldisc reference
945 * (which we check for)
946 *
947 * Locking: call functions take tty_ldisc_lock
948 */
949
950struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
951{
952 /* wait_event is a macro */
953 wait_event(tty_ldisc_wait, tty_ldisc_try(tty));
954 if (tty->ldisc.refcount == 0)
955 printk(KERN_ERR "tty_ldisc_ref_wait\n");
956 return &tty->ldisc;
957}
958
959EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
960
961/**
962 * tty_ldisc_ref - get the tty ldisc
963 * @tty: tty device
964 *
965 * Dereference the line discipline for the terminal and take a
966 * reference to it. If the line discipline is in flux then
967 * return NULL. Can be called from IRQ and timer functions.
968 *
969 * Locking: called functions take tty_ldisc_lock
970 */
971
972struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
973{
974 if (tty_ldisc_try(tty))
975 return &tty->ldisc;
976 return NULL;
977}
978
979EXPORT_SYMBOL_GPL(tty_ldisc_ref);
980
981/**
982 * tty_ldisc_deref - free a tty ldisc reference
983 * @ld: reference to free up
984 *
985 * Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May
986 * be called in IRQ context.
987 *
988 * Locking: takes tty_ldisc_lock
989 */
990
991void tty_ldisc_deref(struct tty_ldisc *ld)
992{
993 unsigned long flags;
994
995 BUG_ON(ld == NULL);
996
997 spin_lock_irqsave(&tty_ldisc_lock, flags);
998 if (ld->refcount == 0)
999 printk(KERN_ERR "tty_ldisc_deref: no references.\n");
1000 else
1001 ld->refcount--;
1002 if (ld->refcount == 0)
1003 wake_up(&tty_ldisc_wait);
1004 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1005}
1006
1007EXPORT_SYMBOL_GPL(tty_ldisc_deref);
1008
1009/**
1010 * tty_ldisc_enable - allow ldisc use
1011 * @tty: terminal to activate ldisc on
1012 *
1013 * Set the TTY_LDISC flag when the line discipline can be called
1014 * again. Do necessary wakeups for existing sleepers.
1015 *
1016 * Note: nobody should set this bit except via this function. Clearing
1017 * directly is allowed.
1018 */
1019
1020static void tty_ldisc_enable(struct tty_struct *tty)
1021{
1022 set_bit(TTY_LDISC, &tty->flags);
1023 wake_up(&tty_ldisc_wait);
1024}
1025
1026/**
1027 * tty_ldisc_restore - helper for tty ldisc change
1028 * @tty: tty to recover
1029 * @old: previous ldisc
1030 *
1031 * Restore the previous line discipline or N_TTY when a line discipline
1032 * change fails due to an open error
1033 */
1034
1035static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
1036{
1037 char buf[64];
1038 struct tty_ldisc new_ldisc;
1039
1040 /* There is an outstanding reference here so this is safe */
1041 tty_ldisc_get(old->ops->num, old);
1042 tty_ldisc_assign(tty, old);
1043 tty_set_termios_ldisc(tty, old->ops->num);
1044 if (old->ops->open && (old->ops->open(tty) < 0)) {
1045 tty_ldisc_put(old->ops);
1046 /* This driver is always present */
1047 if (tty_ldisc_get(N_TTY, &new_ldisc) < 0)
1048 panic("n_tty: get");
1049 tty_ldisc_assign(tty, &new_ldisc);
1050 tty_set_termios_ldisc(tty, N_TTY);
1051 if (new_ldisc.ops->open) {
1052 int r = new_ldisc.ops->open(tty);
1053 if (r < 0)
1054 panic("Couldn't open N_TTY ldisc for "
1055 "%s --- error %d.",
1056 tty_name(tty, buf), r);
1057 }
1058 }
1059}
1060
1061/**
1062 * tty_set_ldisc - set line discipline
1063 * @tty: the terminal to set
1064 * @ldisc: the line discipline
1065 *
1066 * Set the discipline of a tty line. Must be called from a process
1067 * context.
1068 *
1069 * Locking: takes tty_ldisc_lock.
1070 * called functions take termios_mutex
1071 */
1072
1073static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
1074{
1075 int retval;
1076 struct tty_ldisc o_ldisc, new_ldisc;
1077 int work;
1078 unsigned long flags;
1079 struct tty_struct *o_tty;
1080
1081restart:
1082 /* This is a bit ugly for now but means we can break the 'ldisc
1083 is part of the tty struct' assumption later */
1084 retval = tty_ldisc_get(ldisc, &new_ldisc);
1085 if (retval)
1086 return retval;
1087
1088 /*
1089 * Problem: What do we do if this blocks ?
1090 */
1091
1092 tty_wait_until_sent(tty, 0);
1093
1094 if (tty->ldisc.ops->num == ldisc) {
1095 tty_ldisc_put(new_ldisc.ops);
1096 return 0;
1097 }
1098
1099 /*
1100 * No more input please, we are switching. The new ldisc
1101 * will update this value in the ldisc open function
1102 */
1103
1104 tty->receive_room = 0;
1105
1106 o_ldisc = tty->ldisc;
1107 o_tty = tty->link;
1108
1109 /*
1110 * Make sure we don't change while someone holds a
1111 * reference to the line discipline. The TTY_LDISC bit
1112 * prevents anyone taking a reference once it is clear.
1113 * We need the lock to avoid racing reference takers.
1114 */
1115
1116 spin_lock_irqsave(&tty_ldisc_lock, flags);
1117 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) {
1118 if (tty->ldisc.refcount) {
1119 /* Free the new ldisc we grabbed. Must drop the lock
1120 first. */
1121 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1122 tty_ldisc_put(o_ldisc.ops);
1123 /*
1124 * There are several reasons we may be busy, including
1125 * random momentary I/O traffic. We must therefore
1126 * retry. We could distinguish between blocking ops
1127 * and retries if we made tty_ldisc_wait() smarter.
1128 * That is up for discussion.
1129 */
1130 if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0)
1131 return -ERESTARTSYS;
1132 goto restart;
1133 }
1134 if (o_tty && o_tty->ldisc.refcount) {
1135 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1136 tty_ldisc_put(o_tty->ldisc.ops);
1137 if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0)
1138 return -ERESTARTSYS;
1139 goto restart;
1140 }
1141 }
1142 /*
1143 * If the TTY_LDISC bit is set, then we are racing against
1144 * another ldisc change
1145 */
1146 if (!test_bit(TTY_LDISC, &tty->flags)) {
1147 struct tty_ldisc *ld;
1148 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1149 tty_ldisc_put(new_ldisc.ops);
1150 ld = tty_ldisc_ref_wait(tty);
1151 tty_ldisc_deref(ld);
1152 goto restart;
1153 }
1154
1155 clear_bit(TTY_LDISC, &tty->flags);
1156 if (o_tty)
1157 clear_bit(TTY_LDISC, &o_tty->flags);
1158 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1159
1160 /*
1161 * From this point on we know nobody has an ldisc
1162 * usage reference, nor can they obtain one until
1163 * we say so later on.
1164 */
1165
1166 work = cancel_delayed_work(&tty->buf.work);
1167 /*
1168 * Wait for ->hangup_work and ->buf.work handlers to terminate
1169 * MUST NOT hold locks here.
1170 */
1171 flush_scheduled_work();
1172 /* Shutdown the current discipline. */
1173 if (o_ldisc.ops->close)
1174 (o_ldisc.ops->close)(tty);
1175
1176 /* Now set up the new line discipline. */
1177 tty_ldisc_assign(tty, &new_ldisc);
1178 tty_set_termios_ldisc(tty, ldisc);
1179 if (new_ldisc.ops->open)
1180 retval = (new_ldisc.ops->open)(tty);
1181 if (retval < 0) {
1182 tty_ldisc_put(new_ldisc.ops);
1183 tty_ldisc_restore(tty, &o_ldisc);
1184 }
1185 /* At this point we hold a reference to the new ldisc and a
1186 a reference to the old ldisc. If we ended up flipping back
1187 to the existing ldisc we have two references to it */
1188
1189 if (tty->ldisc.ops->num != o_ldisc.ops->num && tty->ops->set_ldisc)
1190 tty->ops->set_ldisc(tty);
1191
1192 tty_ldisc_put(o_ldisc.ops);
1193
1194 /*
1195 * Allow ldisc referencing to occur as soon as the driver
1196 * ldisc callback completes.
1197 */
1198
1199 tty_ldisc_enable(tty);
1200 if (o_tty)
1201 tty_ldisc_enable(o_tty);
1202
1203 /* Restart it in case no characters kick it off. Safe if
1204 already running */
1205 if (work)
1206 schedule_delayed_work(&tty->buf.work, 1);
1207 return retval;
1208}
1209
1210/**
1211 * get_tty_driver - find device of a tty 659 * get_tty_driver - find device of a tty
1212 * @dev_t: device identifier 660 * @dev_t: device identifier
1213 * @index: returns the index of the tty 661 * @index: returns the index of the tty
@@ -2193,7 +1641,6 @@ static int init_dev(struct tty_driver *driver, int idx,
2193 struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc; 1641 struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc;
2194 struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; 1642 struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
2195 int retval = 0; 1643 int retval = 0;
2196 struct tty_ldisc *ld;
2197 1644
2198 /* check whether we're reopening an existing tty */ 1645 /* check whether we're reopening an existing tty */
2199 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { 1646 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) {
@@ -2342,25 +1789,12 @@ static int init_dev(struct tty_driver *driver, int idx,
2342 * If we fail here just call release_tty to clean up. No need 1789 * If we fail here just call release_tty to clean up. No need
2343 * to decrement the use counts, as release_tty doesn't care. 1790 * to decrement the use counts, as release_tty doesn't care.
2344 */ 1791 */
2345
2346 ld = &tty->ldisc;
2347 1792
2348 if (ld->ops->open) { 1793 retval = tty_ldisc_setup(tty, o_tty);
2349 retval = (ld->ops->open)(tty); 1794
2350 if (retval) 1795 if (retval)
2351 goto release_mem_out; 1796 goto release_mem_out;
2352 } 1797 goto success;
2353 if (o_tty && o_tty->ldisc.ops->open) {
2354 retval = (o_tty->ldisc.ops->open)(o_tty);
2355 if (retval) {
2356 if (ld->ops->close)
2357 (ld->ops->close)(tty);
2358 goto release_mem_out;
2359 }
2360 tty_ldisc_enable(o_tty);
2361 }
2362 tty_ldisc_enable(tty);
2363 goto success;
2364 1798
2365 /* 1799 /*
2366 * This fast open can be used if the tty is already open. 1800 * This fast open can be used if the tty is already open.
@@ -2498,12 +1932,10 @@ static void release_tty(struct tty_struct *tty, int idx)
2498static void release_dev(struct file *filp) 1932static void release_dev(struct file *filp)
2499{ 1933{
2500 struct tty_struct *tty, *o_tty; 1934 struct tty_struct *tty, *o_tty;
2501 struct tty_ldisc ld;
2502 int pty_master, tty_closing, o_tty_closing, do_sleep; 1935 int pty_master, tty_closing, o_tty_closing, do_sleep;
2503 int devpts; 1936 int devpts;
2504 int idx; 1937 int idx;
2505 char buf[64]; 1938 char buf[64];
2506 unsigned long flags;
2507 1939
2508 tty = (struct tty_struct *)filp->private_data; 1940 tty = (struct tty_struct *)filp->private_data;
2509 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, 1941 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode,
@@ -2705,56 +2137,9 @@ static void release_dev(struct file *filp)
2705 printk(KERN_DEBUG "freeing tty structure..."); 2137 printk(KERN_DEBUG "freeing tty structure...");
2706#endif 2138#endif
2707 /* 2139 /*
2708 * Prevent flush_to_ldisc() from rescheduling the work for later. Then 2140 * Ask the line discipline code to release its structures
2709 * kill any delayed work. As this is the final close it does not
2710 * race with the set_ldisc code path.
2711 */ 2141 */
2712 clear_bit(TTY_LDISC, &tty->flags); 2142 tty_ldisc_release(tty, o_tty);
2713 cancel_delayed_work(&tty->buf.work);
2714
2715 /*
2716 * Wait for ->hangup_work and ->buf.work handlers to terminate
2717 */
2718
2719 flush_scheduled_work();
2720
2721 /*
2722 * Wait for any short term users (we know they are just driver
2723 * side waiters as the file is closing so user count on the file
2724 * side is zero.
2725 */
2726 spin_lock_irqsave(&tty_ldisc_lock, flags);
2727 while (tty->ldisc.refcount) {
2728 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
2729 wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0);
2730 spin_lock_irqsave(&tty_ldisc_lock, flags);
2731 }
2732 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
2733 /*
2734 * Shutdown the current line discipline, and reset it to N_TTY.
2735 *
2736 * FIXME: this MUST get fixed for the new reflocking
2737 */
2738 if (tty->ldisc.ops->close)
2739 (tty->ldisc.ops->close)(tty);
2740 tty_ldisc_put(tty->ldisc.ops);
2741
2742 /*
2743 * Switch the line discipline back
2744 */
2745 WARN_ON(tty_ldisc_get(N_TTY, &ld));
2746 tty_ldisc_assign(tty, &ld);
2747 tty_set_termios_ldisc(tty, N_TTY);
2748 if (o_tty) {
2749 /* FIXME: could o_tty be in setldisc here ? */
2750 clear_bit(TTY_LDISC, &o_tty->flags);
2751 if (o_tty->ldisc.ops->close)
2752 (o_tty->ldisc.ops->close)(o_tty);
2753 tty_ldisc_put(o_tty->ldisc.ops);
2754 WARN_ON(tty_ldisc_get(N_TTY, &ld));
2755 tty_ldisc_assign(o_tty, &ld);
2756 tty_set_termios_ldisc(o_tty, N_TTY);
2757 }
2758 /* 2143 /*
2759 * The release_tty function takes care of the details of clearing 2144 * The release_tty function takes care of the details of clearing
2760 * the slots and preserving the termios structure. 2145 * the slots and preserving the termios structure.
@@ -3464,16 +2849,29 @@ static int tiocsetd(struct tty_struct *tty, int __user *p)
3464 2849
3465static int send_break(struct tty_struct *tty, unsigned int duration) 2850static int send_break(struct tty_struct *tty, unsigned int duration)
3466{ 2851{
3467 if (tty_write_lock(tty, 0) < 0) 2852 int retval;
3468 return -EINTR; 2853
3469 tty->ops->break_ctl(tty, -1); 2854 if (tty->ops->break_ctl == NULL)
3470 if (!signal_pending(current)) 2855 return 0;
3471 msleep_interruptible(duration); 2856
3472 tty->ops->break_ctl(tty, 0); 2857 if (tty->driver->flags & TTY_DRIVER_HARDWARE_BREAK)
3473 tty_write_unlock(tty); 2858 retval = tty->ops->break_ctl(tty, duration);
3474 if (signal_pending(current)) 2859 else {
3475 return -EINTR; 2860 /* Do the work ourselves */
3476 return 0; 2861 if (tty_write_lock(tty, 0) < 0)
2862 return -EINTR;
2863 retval = tty->ops->break_ctl(tty, -1);
2864 if (retval)
2865 goto out;
2866 if (!signal_pending(current))
2867 msleep_interruptible(duration);
2868 retval = tty->ops->break_ctl(tty, 0);
2869out:
2870 tty_write_unlock(tty);
2871 if (signal_pending(current))
2872 retval = -EINTR;
2873 }
2874 return retval;
3477} 2875}
3478 2876
3479/** 2877/**
@@ -3564,36 +2962,6 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3564 tty->driver->subtype == PTY_TYPE_MASTER) 2962 tty->driver->subtype == PTY_TYPE_MASTER)
3565 real_tty = tty->link; 2963 real_tty = tty->link;
3566 2964
3567 /*
3568 * Break handling by driver
3569 */
3570
3571 retval = -EINVAL;
3572
3573 if (!tty->ops->break_ctl) {
3574 switch (cmd) {
3575 case TIOCSBRK:
3576 case TIOCCBRK:
3577 if (tty->ops->ioctl)
3578 retval = tty->ops->ioctl(tty, file, cmd, arg);
3579 if (retval != -EINVAL && retval != -ENOIOCTLCMD)
3580 printk(KERN_WARNING "tty: driver %s needs updating to use break_ctl\n", tty->driver->name);
3581 return retval;
3582
3583 /* These two ioctl's always return success; even if */
3584 /* the driver doesn't support them. */
3585 case TCSBRK:
3586 case TCSBRKP:
3587 if (!tty->ops->ioctl)
3588 return 0;
3589 retval = tty->ops->ioctl(tty, file, cmd, arg);
3590 if (retval != -EINVAL && retval != -ENOIOCTLCMD)
3591 printk(KERN_WARNING "tty: driver %s needs updating to use break_ctl\n", tty->driver->name);
3592 if (retval == -ENOIOCTLCMD)
3593 retval = 0;
3594 return retval;
3595 }
3596 }
3597 2965
3598 /* 2966 /*
3599 * Factor out some common prep work 2967 * Factor out some common prep work
@@ -3615,6 +2983,9 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3615 break; 2983 break;
3616 } 2984 }
3617 2985
2986 /*
2987 * Now do the stuff.
2988 */
3618 switch (cmd) { 2989 switch (cmd) {
3619 case TIOCSTI: 2990 case TIOCSTI:
3620 return tiocsti(tty, p); 2991 return tiocsti(tty, p);
@@ -3658,12 +3029,11 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3658 */ 3029 */
3659 case TIOCSBRK: /* Turn break on, unconditionally */ 3030 case TIOCSBRK: /* Turn break on, unconditionally */
3660 if (tty->ops->break_ctl) 3031 if (tty->ops->break_ctl)
3661 tty->ops->break_ctl(tty, -1); 3032 return tty->ops->break_ctl(tty, -1);
3662 return 0; 3033 return 0;
3663
3664 case TIOCCBRK: /* Turn break off, unconditionally */ 3034 case TIOCCBRK: /* Turn break off, unconditionally */
3665 if (tty->ops->break_ctl) 3035 if (tty->ops->break_ctl)
3666 tty->ops->break_ctl(tty, 0); 3036 return tty->ops->break_ctl(tty, 0);
3667 return 0; 3037 return 0;
3668 case TCSBRK: /* SVID version: non-zero arg --> no break */ 3038 case TCSBRK: /* SVID version: non-zero arg --> no break */
3669 /* non-zero arg means wait for all output data 3039 /* non-zero arg means wait for all output data
@@ -3962,12 +3332,9 @@ EXPORT_SYMBOL(tty_flip_buffer_push);
3962 3332
3963static void initialize_tty_struct(struct tty_struct *tty) 3333static void initialize_tty_struct(struct tty_struct *tty)
3964{ 3334{
3965 struct tty_ldisc ld;
3966 memset(tty, 0, sizeof(struct tty_struct)); 3335 memset(tty, 0, sizeof(struct tty_struct));
3967 tty->magic = TTY_MAGIC; 3336 tty->magic = TTY_MAGIC;
3968 if (tty_ldisc_get(N_TTY, &ld) < 0) 3337 tty_ldisc_init(tty);
3969 panic("n_tty: init_tty");
3970 tty_ldisc_assign(tty, &ld);
3971 tty->session = NULL; 3338 tty->session = NULL;
3972 tty->pgrp = NULL; 3339 tty->pgrp = NULL;
3973 tty->overrun_time = jiffies; 3340 tty->overrun_time = jiffies;
@@ -4045,7 +3412,7 @@ struct device *tty_register_device(struct tty_driver *driver, unsigned index,
4045 else 3412 else
4046 tty_line_name(driver, index, name); 3413 tty_line_name(driver, index, name);
4047 3414
4048 return device_create(tty_class, device, dev, name); 3415 return device_create_drvdata(tty_class, device, dev, NULL, name);
4049} 3416}
4050 3417
4051/** 3418/**
@@ -4280,7 +3647,7 @@ void __init console_init(void)
4280 initcall_t *call; 3647 initcall_t *call;
4281 3648
4282 /* Setup the default TTY line discipline. */ 3649 /* Setup the default TTY line discipline. */
4283 (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY); 3650 tty_ldisc_begin();
4284 3651
4285 /* 3652 /*
4286 * set up the console device so that later boot sequences can 3653 * set up the console device so that later boot sequences can
@@ -4323,20 +3690,22 @@ static int __init tty_init(void)
4323 if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) || 3690 if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||
4324 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) 3691 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
4325 panic("Couldn't register /dev/tty driver\n"); 3692 panic("Couldn't register /dev/tty driver\n");
4326 device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), "tty"); 3693 device_create_drvdata(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL,
3694 "tty");
4327 3695
4328 cdev_init(&console_cdev, &console_fops); 3696 cdev_init(&console_cdev, &console_fops);
4329 if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) || 3697 if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
4330 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0) 3698 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
4331 panic("Couldn't register /dev/console driver\n"); 3699 panic("Couldn't register /dev/console driver\n");
4332 device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), "console"); 3700 device_create_drvdata(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL,
3701 "console");
4333 3702
4334#ifdef CONFIG_UNIX98_PTYS 3703#ifdef CONFIG_UNIX98_PTYS
4335 cdev_init(&ptmx_cdev, &ptmx_fops); 3704 cdev_init(&ptmx_cdev, &ptmx_fops);
4336 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) || 3705 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
4337 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0) 3706 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
4338 panic("Couldn't register /dev/ptmx driver\n"); 3707 panic("Couldn't register /dev/ptmx driver\n");
4339 device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), "ptmx"); 3708 device_create_drvdata(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
4340#endif 3709#endif
4341 3710
4342#ifdef CONFIG_VT 3711#ifdef CONFIG_VT
@@ -4344,7 +3713,7 @@ static int __init tty_init(void)
4344 if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) || 3713 if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
4345 register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) 3714 register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
4346 panic("Couldn't register /dev/tty0 driver\n"); 3715 panic("Couldn't register /dev/tty0 driver\n");
4347 device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), "tty0"); 3716 device_create_drvdata(tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, "tty0");
4348 3717
4349 vty_init(); 3718 vty_init();
4350#endif 3719#endif
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
new file mode 100644
index 000000000000..241cbdea65ab
--- /dev/null
+++ b/drivers/char/tty_ldisc.c
@@ -0,0 +1,714 @@
1#include <linux/types.h>
2#include <linux/major.h>
3#include <linux/errno.h>
4#include <linux/signal.h>
5#include <linux/fcntl.h>
6#include <linux/sched.h>
7#include <linux/interrupt.h>
8#include <linux/tty.h>
9#include <linux/tty_driver.h>
10#include <linux/tty_flip.h>
11#include <linux/devpts_fs.h>
12#include <linux/file.h>
13#include <linux/fdtable.h>
14#include <linux/console.h>
15#include <linux/timer.h>
16#include <linux/ctype.h>
17#include <linux/kd.h>
18#include <linux/mm.h>
19#include <linux/string.h>
20#include <linux/slab.h>
21#include <linux/poll.h>
22#include <linux/proc_fs.h>
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/smp_lock.h>
26#include <linux/device.h>
27#include <linux/wait.h>
28#include <linux/bitops.h>
29#include <linux/delay.h>
30#include <linux/seq_file.h>
31
32#include <linux/uaccess.h>
33#include <asm/system.h>
34
35#include <linux/kbd_kern.h>
36#include <linux/vt_kern.h>
37#include <linux/selection.h>
38
39#include <linux/kmod.h>
40#include <linux/nsproxy.h>
41
42/*
43 * This guards the refcounted line discipline lists. The lock
44 * must be taken with irqs off because there are hangup path
45 * callers who will do ldisc lookups and cannot sleep.
46 */
47
48static DEFINE_SPINLOCK(tty_ldisc_lock);
49static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
50/* Line disc dispatch table */
51static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS];
52
53/**
54 * tty_register_ldisc - install a line discipline
55 * @disc: ldisc number
56 * @new_ldisc: pointer to the ldisc object
57 *
58 * Installs a new line discipline into the kernel. The discipline
59 * is set up as unreferenced and then made available to the kernel
60 * from this point onwards.
61 *
62 * Locking:
63 * takes tty_ldisc_lock to guard against ldisc races
64 */
65
66int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
67{
68 unsigned long flags;
69 int ret = 0;
70
71 if (disc < N_TTY || disc >= NR_LDISCS)
72 return -EINVAL;
73
74 spin_lock_irqsave(&tty_ldisc_lock, flags);
75 tty_ldiscs[disc] = new_ldisc;
76 new_ldisc->num = disc;
77 new_ldisc->refcount = 0;
78 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
79
80 return ret;
81}
82EXPORT_SYMBOL(tty_register_ldisc);
83
84/**
85 * tty_unregister_ldisc - unload a line discipline
86 * @disc: ldisc number
87 * @new_ldisc: pointer to the ldisc object
88 *
89 * Remove a line discipline from the kernel providing it is not
90 * currently in use.
91 *
92 * Locking:
93 * takes tty_ldisc_lock to guard against ldisc races
94 */
95
96int tty_unregister_ldisc(int disc)
97{
98 unsigned long flags;
99 int ret = 0;
100
101 if (disc < N_TTY || disc >= NR_LDISCS)
102 return -EINVAL;
103
104 spin_lock_irqsave(&tty_ldisc_lock, flags);
105 if (tty_ldiscs[disc]->refcount)
106 ret = -EBUSY;
107 else
108 tty_ldiscs[disc] = NULL;
109 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
110
111 return ret;
112}
113EXPORT_SYMBOL(tty_unregister_ldisc);
114
115
116/**
117 * tty_ldisc_try_get - try and reference an ldisc
118 * @disc: ldisc number
119 * @ld: tty ldisc structure to complete
120 *
121 * Attempt to open and lock a line discipline into place. Return
122 * the line discipline refcounted and assigned in ld. On an error
123 * report the error code back
124 */
125
126static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld)
127{
128 unsigned long flags;
129 struct tty_ldisc_ops *ldops;
130 int err = -EINVAL;
131
132 spin_lock_irqsave(&tty_ldisc_lock, flags);
133 ld->ops = NULL;
134 ldops = tty_ldiscs[disc];
135 /* Check the entry is defined */
136 if (ldops) {
137 /* If the module is being unloaded we can't use it */
138 if (!try_module_get(ldops->owner))
139 err = -EAGAIN;
140 else {
141 /* lock it */
142 ldops->refcount++;
143 ld->ops = ldops;
144 err = 0;
145 }
146 }
147 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
148 return err;
149}
150
151/**
152 * tty_ldisc_get - take a reference to an ldisc
153 * @disc: ldisc number
154 * @ld: tty line discipline structure to use
155 *
156 * Takes a reference to a line discipline. Deals with refcounts and
157 * module locking counts. Returns NULL if the discipline is not available.
158 * Returns a pointer to the discipline and bumps the ref count if it is
159 * available
160 *
161 * Locking:
162 * takes tty_ldisc_lock to guard against ldisc races
163 */
164
165static int tty_ldisc_get(int disc, struct tty_ldisc *ld)
166{
167 int err;
168
169 if (disc < N_TTY || disc >= NR_LDISCS)
170 return -EINVAL;
171 err = tty_ldisc_try_get(disc, ld);
172 if (err == -EAGAIN) {
173 request_module("tty-ldisc-%d", disc);
174 err = tty_ldisc_try_get(disc, ld);
175 }
176 return err;
177}
178
179/**
180 * tty_ldisc_put - drop ldisc reference
181 * @disc: ldisc number
182 *
183 * Drop a reference to a line discipline. Manage refcounts and
184 * module usage counts
185 *
186 * Locking:
187 * takes tty_ldisc_lock to guard against ldisc races
188 */
189
190static void tty_ldisc_put(struct tty_ldisc_ops *ld)
191{
192 unsigned long flags;
193 int disc = ld->num;
194
195 BUG_ON(disc < N_TTY || disc >= NR_LDISCS);
196
197 spin_lock_irqsave(&tty_ldisc_lock, flags);
198 ld = tty_ldiscs[disc];
199 BUG_ON(ld->refcount == 0);
200 ld->refcount--;
201 module_put(ld->owner);
202 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
203}
204
205static void * tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos)
206{
207 return (*pos < NR_LDISCS) ? pos : NULL;
208}
209
210static void * tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos)
211{
212 (*pos)++;
213 return (*pos < NR_LDISCS) ? pos : NULL;
214}
215
216static void tty_ldiscs_seq_stop(struct seq_file *m, void *v)
217{
218}
219
220static int tty_ldiscs_seq_show(struct seq_file *m, void *v)
221{
222 int i = *(loff_t *)v;
223 struct tty_ldisc ld;
224
225 if (tty_ldisc_get(i, &ld) < 0)
226 return 0;
227 seq_printf(m, "%-10s %2d\n", ld.ops->name ? ld.ops->name : "???", i);
228 tty_ldisc_put(ld.ops);
229 return 0;
230}
231
232static const struct seq_operations tty_ldiscs_seq_ops = {
233 .start = tty_ldiscs_seq_start,
234 .next = tty_ldiscs_seq_next,
235 .stop = tty_ldiscs_seq_stop,
236 .show = tty_ldiscs_seq_show,
237};
238
239static int proc_tty_ldiscs_open(struct inode *inode, struct file *file)
240{
241 return seq_open(file, &tty_ldiscs_seq_ops);
242}
243
244const struct file_operations tty_ldiscs_proc_fops = {
245 .owner = THIS_MODULE,
246 .open = proc_tty_ldiscs_open,
247 .read = seq_read,
248 .llseek = seq_lseek,
249 .release = seq_release,
250};
251
252/**
253 * tty_ldisc_assign - set ldisc on a tty
254 * @tty: tty to assign
255 * @ld: line discipline
256 *
257 * Install an instance of a line discipline into a tty structure. The
258 * ldisc must have a reference count above zero to ensure it remains/
259 * The tty instance refcount starts at zero.
260 *
261 * Locking:
262 * Caller must hold references
263 */
264
265static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld)
266{
267 ld->refcount = 0;
268 tty->ldisc = *ld;
269}
270
271/**
272 * tty_ldisc_try - internal helper
273 * @tty: the tty
274 *
275 * Make a single attempt to grab and bump the refcount on
276 * the tty ldisc. Return 0 on failure or 1 on success. This is
277 * used to implement both the waiting and non waiting versions
278 * of tty_ldisc_ref
279 *
280 * Locking: takes tty_ldisc_lock
281 */
282
283static int tty_ldisc_try(struct tty_struct *tty)
284{
285 unsigned long flags;
286 struct tty_ldisc *ld;
287 int ret = 0;
288
289 spin_lock_irqsave(&tty_ldisc_lock, flags);
290 ld = &tty->ldisc;
291 if (test_bit(TTY_LDISC, &tty->flags)) {
292 ld->refcount++;
293 ret = 1;
294 }
295 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
296 return ret;
297}
298
299/**
300 * tty_ldisc_ref_wait - wait for the tty ldisc
301 * @tty: tty device
302 *
303 * Dereference the line discipline for the terminal and take a
304 * reference to it. If the line discipline is in flux then
305 * wait patiently until it changes.
306 *
307 * Note: Must not be called from an IRQ/timer context. The caller
308 * must also be careful not to hold other locks that will deadlock
309 * against a discipline change, such as an existing ldisc reference
310 * (which we check for)
311 *
312 * Locking: call functions take tty_ldisc_lock
313 */
314
315struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
316{
317 /* wait_event is a macro */
318 wait_event(tty_ldisc_wait, tty_ldisc_try(tty));
319 if (tty->ldisc.refcount == 0)
320 printk(KERN_ERR "tty_ldisc_ref_wait\n");
321 return &tty->ldisc;
322}
323
324EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
325
326/**
327 * tty_ldisc_ref - get the tty ldisc
328 * @tty: tty device
329 *
330 * Dereference the line discipline for the terminal and take a
331 * reference to it. If the line discipline is in flux then
332 * return NULL. Can be called from IRQ and timer functions.
333 *
334 * Locking: called functions take tty_ldisc_lock
335 */
336
337struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
338{
339 if (tty_ldisc_try(tty))
340 return &tty->ldisc;
341 return NULL;
342}
343
344EXPORT_SYMBOL_GPL(tty_ldisc_ref);
345
346/**
347 * tty_ldisc_deref - free a tty ldisc reference
348 * @ld: reference to free up
349 *
350 * Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May
351 * be called in IRQ context.
352 *
353 * Locking: takes tty_ldisc_lock
354 */
355
356void tty_ldisc_deref(struct tty_ldisc *ld)
357{
358 unsigned long flags;
359
360 BUG_ON(ld == NULL);
361
362 spin_lock_irqsave(&tty_ldisc_lock, flags);
363 if (ld->refcount == 0)
364 printk(KERN_ERR "tty_ldisc_deref: no references.\n");
365 else
366 ld->refcount--;
367 if (ld->refcount == 0)
368 wake_up(&tty_ldisc_wait);
369 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
370}
371
372EXPORT_SYMBOL_GPL(tty_ldisc_deref);
373
374/**
375 * tty_ldisc_enable - allow ldisc use
376 * @tty: terminal to activate ldisc on
377 *
378 * Set the TTY_LDISC flag when the line discipline can be called
379 * again. Do necessary wakeups for existing sleepers.
380 *
381 * Note: nobody should set this bit except via this function. Clearing
382 * directly is allowed.
383 */
384
385void tty_ldisc_enable(struct tty_struct *tty)
386{
387 set_bit(TTY_LDISC, &tty->flags);
388 wake_up(&tty_ldisc_wait);
389}
390
391/**
392 * tty_set_termios_ldisc - set ldisc field
393 * @tty: tty structure
394 * @num: line discipline number
395 *
396 * This is probably overkill for real world processors but
397 * they are not on hot paths so a little discipline won't do
398 * any harm.
399 *
400 * Locking: takes termios_mutex
401 */
402
403static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
404{
405 mutex_lock(&tty->termios_mutex);
406 tty->termios->c_line = num;
407 mutex_unlock(&tty->termios_mutex);
408}
409
410
411/**
412 * tty_ldisc_restore - helper for tty ldisc change
413 * @tty: tty to recover
414 * @old: previous ldisc
415 *
416 * Restore the previous line discipline or N_TTY when a line discipline
417 * change fails due to an open error
418 */
419
420static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
421{
422 char buf[64];
423 struct tty_ldisc new_ldisc;
424
425 /* There is an outstanding reference here so this is safe */
426 tty_ldisc_get(old->ops->num, old);
427 tty_ldisc_assign(tty, old);
428 tty_set_termios_ldisc(tty, old->ops->num);
429 if (old->ops->open && (old->ops->open(tty) < 0)) {
430 tty_ldisc_put(old->ops);
431 /* This driver is always present */
432 if (tty_ldisc_get(N_TTY, &new_ldisc) < 0)
433 panic("n_tty: get");
434 tty_ldisc_assign(tty, &new_ldisc);
435 tty_set_termios_ldisc(tty, N_TTY);
436 if (new_ldisc.ops->open) {
437 int r = new_ldisc.ops->open(tty);
438 if (r < 0)
439 panic("Couldn't open N_TTY ldisc for "
440 "%s --- error %d.",
441 tty_name(tty, buf), r);
442 }
443 }
444}
445
446/**
447 * tty_set_ldisc - set line discipline
448 * @tty: the terminal to set
449 * @ldisc: the line discipline
450 *
451 * Set the discipline of a tty line. Must be called from a process
452 * context.
453 *
454 * Locking: takes tty_ldisc_lock.
455 * called functions take termios_mutex
456 */
457
458int tty_set_ldisc(struct tty_struct *tty, int ldisc)
459{
460 int retval;
461 struct tty_ldisc o_ldisc, new_ldisc;
462 int work;
463 unsigned long flags;
464 struct tty_struct *o_tty;
465
466restart:
467 /* This is a bit ugly for now but means we can break the 'ldisc
468 is part of the tty struct' assumption later */
469 retval = tty_ldisc_get(ldisc, &new_ldisc);
470 if (retval)
471 return retval;
472
473 /*
474 * Problem: What do we do if this blocks ?
475 */
476
477 tty_wait_until_sent(tty, 0);
478
479 if (tty->ldisc.ops->num == ldisc) {
480 tty_ldisc_put(new_ldisc.ops);
481 return 0;
482 }
483
484 /*
485 * No more input please, we are switching. The new ldisc
486 * will update this value in the ldisc open function
487 */
488
489 tty->receive_room = 0;
490
491 o_ldisc = tty->ldisc;
492 o_tty = tty->link;
493
494 /*
495 * Make sure we don't change while someone holds a
496 * reference to the line discipline. The TTY_LDISC bit
497 * prevents anyone taking a reference once it is clear.
498 * We need the lock to avoid racing reference takers.
499 */
500
501 spin_lock_irqsave(&tty_ldisc_lock, flags);
502 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) {
503 if (tty->ldisc.refcount) {
504 /* Free the new ldisc we grabbed. Must drop the lock
505 first. */
506 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
507 tty_ldisc_put(o_ldisc.ops);
508 /*
509 * There are several reasons we may be busy, including
510 * random momentary I/O traffic. We must therefore
511 * retry. We could distinguish between blocking ops
512 * and retries if we made tty_ldisc_wait() smarter.
513 * That is up for discussion.
514 */
515 if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0)
516 return -ERESTARTSYS;
517 goto restart;
518 }
519 if (o_tty && o_tty->ldisc.refcount) {
520 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
521 tty_ldisc_put(o_tty->ldisc.ops);
522 if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0)
523 return -ERESTARTSYS;
524 goto restart;
525 }
526 }
527 /*
528 * If the TTY_LDISC bit is set, then we are racing against
529 * another ldisc change
530 */
531 if (!test_bit(TTY_LDISC, &tty->flags)) {
532 struct tty_ldisc *ld;
533 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
534 tty_ldisc_put(new_ldisc.ops);
535 ld = tty_ldisc_ref_wait(tty);
536 tty_ldisc_deref(ld);
537 goto restart;
538 }
539
540 clear_bit(TTY_LDISC, &tty->flags);
541 if (o_tty)
542 clear_bit(TTY_LDISC, &o_tty->flags);
543 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
544
545 /*
546 * From this point on we know nobody has an ldisc
547 * usage reference, nor can they obtain one until
548 * we say so later on.
549 */
550
551 work = cancel_delayed_work(&tty->buf.work);
552 /*
553 * Wait for ->hangup_work and ->buf.work handlers to terminate
554 * MUST NOT hold locks here.
555 */
556 flush_scheduled_work();
557 /* Shutdown the current discipline. */
558 if (o_ldisc.ops->close)
559 (o_ldisc.ops->close)(tty);
560
561 /* Now set up the new line discipline. */
562 tty_ldisc_assign(tty, &new_ldisc);
563 tty_set_termios_ldisc(tty, ldisc);
564 if (new_ldisc.ops->open)
565 retval = (new_ldisc.ops->open)(tty);
566 if (retval < 0) {
567 tty_ldisc_put(new_ldisc.ops);
568 tty_ldisc_restore(tty, &o_ldisc);
569 }
570 /* At this point we hold a reference to the new ldisc and a
571 a reference to the old ldisc. If we ended up flipping back
572 to the existing ldisc we have two references to it */
573
574 if (tty->ldisc.ops->num != o_ldisc.ops->num && tty->ops->set_ldisc)
575 tty->ops->set_ldisc(tty);
576
577 tty_ldisc_put(o_ldisc.ops);
578
579 /*
580 * Allow ldisc referencing to occur as soon as the driver
581 * ldisc callback completes.
582 */
583
584 tty_ldisc_enable(tty);
585 if (o_tty)
586 tty_ldisc_enable(o_tty);
587
588 /* Restart it in case no characters kick it off. Safe if
589 already running */
590 if (work)
591 schedule_delayed_work(&tty->buf.work, 1);
592 return retval;
593}
594
595
596/**
597 * tty_ldisc_setup - open line discipline
598 * @tty: tty being shut down
599 * @o_tty: pair tty for pty/tty pairs
600 *
601 * Called during the initial open of a tty/pty pair in order to set up the
602 * line discplines and bind them to the tty.
603 */
604
605int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
606{
607 struct tty_ldisc *ld = &tty->ldisc;
608 int retval;
609
610 if (ld->ops->open) {
611 retval = (ld->ops->open)(tty);
612 if (retval)
613 return retval;
614 }
615 if (o_tty && o_tty->ldisc.ops->open) {
616 retval = (o_tty->ldisc.ops->open)(o_tty);
617 if (retval) {
618 if (ld->ops->close)
619 (ld->ops->close)(tty);
620 return retval;
621 }
622 tty_ldisc_enable(o_tty);
623 }
624 tty_ldisc_enable(tty);
625 return 0;
626}
627
628/**
629 * tty_ldisc_release - release line discipline
630 * @tty: tty being shut down
631 * @o_tty: pair tty for pty/tty pairs
632 *
633 * Called during the final close of a tty/pty pair in order to shut down the
634 * line discpline layer.
635 */
636
637void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
638{
639 unsigned long flags;
640 struct tty_ldisc ld;
641 /*
642 * Prevent flush_to_ldisc() from rescheduling the work for later. Then
643 * kill any delayed work. As this is the final close it does not
644 * race with the set_ldisc code path.
645 */
646 clear_bit(TTY_LDISC, &tty->flags);
647 cancel_delayed_work(&tty->buf.work);
648
649 /*
650 * Wait for ->hangup_work and ->buf.work handlers to terminate
651 */
652
653 flush_scheduled_work();
654
655 /*
656 * Wait for any short term users (we know they are just driver
657 * side waiters as the file is closing so user count on the file
658 * side is zero.
659 */
660 spin_lock_irqsave(&tty_ldisc_lock, flags);
661 while (tty->ldisc.refcount) {
662 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
663 wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0);
664 spin_lock_irqsave(&tty_ldisc_lock, flags);
665 }
666 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
667 /*
668 * Shutdown the current line discipline, and reset it to N_TTY.
669 *
670 * FIXME: this MUST get fixed for the new reflocking
671 */
672 if (tty->ldisc.ops->close)
673 (tty->ldisc.ops->close)(tty);
674 tty_ldisc_put(tty->ldisc.ops);
675
676 /*
677 * Switch the line discipline back
678 */
679 WARN_ON(tty_ldisc_get(N_TTY, &ld));
680 tty_ldisc_assign(tty, &ld);
681 tty_set_termios_ldisc(tty, N_TTY);
682 if (o_tty) {
683 /* FIXME: could o_tty be in setldisc here ? */
684 clear_bit(TTY_LDISC, &o_tty->flags);
685 if (o_tty->ldisc.ops->close)
686 (o_tty->ldisc.ops->close)(o_tty);
687 tty_ldisc_put(o_tty->ldisc.ops);
688 WARN_ON(tty_ldisc_get(N_TTY, &ld));
689 tty_ldisc_assign(o_tty, &ld);
690 tty_set_termios_ldisc(o_tty, N_TTY);
691 }
692}
693
694/**
695 * tty_ldisc_init - ldisc setup for new tty
696 * @tty: tty being allocated
697 *
698 * Set up the line discipline objects for a newly allocated tty. Note that
699 * the tty structure is not completely set up when this call is made.
700 */
701
702void tty_ldisc_init(struct tty_struct *tty)
703{
704 struct tty_ldisc ld;
705 if (tty_ldisc_get(N_TTY, &ld) < 0)
706 panic("n_tty: init_tty");
707 tty_ldisc_assign(tty, &ld);
708}
709
710void tty_ldisc_begin(void)
711{
712 /* Setup the default TTY line discipline. */
713 (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY);
714}
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index eebfad2777d2..c2ae52dd53d1 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -481,10 +481,10 @@ static struct class *vc_class;
481 481
482void vcs_make_sysfs(struct tty_struct *tty) 482void vcs_make_sysfs(struct tty_struct *tty)
483{ 483{
484 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 1), 484 device_create_drvdata(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 1),
485 "vcs%u", tty->index + 1); 485 NULL, "vcs%u", tty->index + 1);
486 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 129), 486 device_create_drvdata(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 129),
487 "vcsa%u", tty->index + 1); 487 NULL, "vcsa%u", tty->index + 1);
488} 488}
489 489
490void vcs_remove_sysfs(struct tty_struct *tty) 490void vcs_remove_sysfs(struct tty_struct *tty)
@@ -499,7 +499,7 @@ int __init vcs_init(void)
499 panic("unable to get major %d for vcs device", VCS_MAJOR); 499 panic("unable to get major %d for vcs device", VCS_MAJOR);
500 vc_class = class_create(THIS_MODULE, "vc"); 500 vc_class = class_create(THIS_MODULE, "vc");
501 501
502 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 0), "vcs"); 502 device_create_drvdata(vc_class, NULL, MKDEV(VCS_MAJOR, 0), NULL, "vcs");
503 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 128), "vcsa"); 503 device_create_drvdata(vc_class, NULL, MKDEV(VCS_MAJOR, 128), NULL, "vcsa");
504 return 0; 504 return 0;
505} 505}
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index e5da98d8f9cd..7a70a40ad639 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -886,10 +886,10 @@ static int viotape_probe(struct vio_dev *vdev, const struct vio_device_id *id)
886 state[i].cur_part = 0; 886 state[i].cur_part = 0;
887 for (j = 0; j < MAX_PARTITIONS; ++j) 887 for (j = 0; j < MAX_PARTITIONS; ++j)
888 state[i].part_stat_rwi[j] = VIOT_IDLE; 888 state[i].part_stat_rwi[j] = VIOT_IDLE;
889 device_create(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i), 889 device_create_drvdata(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i),
890 "iseries!vt%d", i); 890 NULL, "iseries!vt%d", i);
891 device_create(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i | 0x80), 891 device_create_drvdata(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i | 0x80),
892 "iseries!nvt%d", i); 892 NULL, "iseries!nvt%d", i);
893 printk(VIOTAPE_KERN_INFO "tape iseries/vt%d is iSeries " 893 printk(VIOTAPE_KERN_INFO "tape iseries/vt%d is iSeries "
894 "resource %10.10s type %4.4s, model %3.3s\n", 894 "resource %10.10s type %4.4s, model %3.3s\n",
895 i, viotape_unitinfo[i].rsrcname, 895 i, viotape_unitinfo[i].rsrcname,
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index f17ac043b551..69c5afe97f19 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -85,7 +85,7 @@ static irqreturn_t scc_rx_int(int irq, void *data);
85static irqreturn_t scc_stat_int(int irq, void *data); 85static irqreturn_t scc_stat_int(int irq, void *data);
86static irqreturn_t scc_spcond_int(int irq, void *data); 86static irqreturn_t scc_spcond_int(int irq, void *data);
87static void scc_setsignals(struct scc_port *port, int dtr, int rts); 87static void scc_setsignals(struct scc_port *port, int dtr, int rts);
88static void scc_break_ctl(struct tty_struct *tty, int break_state); 88static int scc_break_ctl(struct tty_struct *tty, int break_state);
89 89
90static struct tty_driver *scc_driver; 90static struct tty_driver *scc_driver;
91 91
@@ -942,7 +942,7 @@ static int scc_ioctl(struct tty_struct *tty, struct file *file,
942} 942}
943 943
944 944
945static void scc_break_ctl(struct tty_struct *tty, int break_state) 945static int scc_break_ctl(struct tty_struct *tty, int break_state)
946{ 946{
947 struct scc_port *port = (struct scc_port *)tty->driver_data; 947 struct scc_port *port = (struct scc_port *)tty->driver_data;
948 unsigned long flags; 948 unsigned long flags;
@@ -952,6 +952,7 @@ static void scc_break_ctl(struct tty_struct *tty, int break_state)
952 SCCmod(TX_CTRL_REG, ~TCR_SEND_BREAK, 952 SCCmod(TX_CTRL_REG, ~TCR_SEND_BREAK,
953 break_state ? TCR_SEND_BREAK : 0); 953 break_state ? TCR_SEND_BREAK : 0);
954 local_irq_restore(flags); 954 local_irq_restore(flags);
955 return 0;
955} 956}
956 957
957 958
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 935f1c207a1f..e32a076d5f1f 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -3425,9 +3425,10 @@ int register_con_driver(const struct consw *csw, int first, int last)
3425 if (retval) 3425 if (retval)
3426 goto err; 3426 goto err;
3427 3427
3428 con_driver->dev = device_create(vtconsole_class, NULL, 3428 con_driver->dev = device_create_drvdata(vtconsole_class, NULL,
3429 MKDEV(0, con_driver->node), 3429 MKDEV(0, con_driver->node),
3430 "vtcon%i", con_driver->node); 3430 NULL, "vtcon%i",
3431 con_driver->node);
3431 3432
3432 if (IS_ERR(con_driver->dev)) { 3433 if (IS_ERR(con_driver->dev)) {
3433 printk(KERN_WARNING "Unable to create device for %s; " 3434 printk(KERN_WARNING "Unable to create device for %s; "
@@ -3535,9 +3536,10 @@ static int __init vtconsole_class_init(void)
3535 struct con_driver *con = &registered_con_driver[i]; 3536 struct con_driver *con = &registered_con_driver[i];
3536 3537
3537 if (con->con && !con->dev) { 3538 if (con->con && !con->dev) {
3538 con->dev = device_create(vtconsole_class, NULL, 3539 con->dev = device_create_drvdata(vtconsole_class, NULL,
3539 MKDEV(0, con->node), 3540 MKDEV(0, con->node),
3540 "vtcon%i", con->node); 3541 NULL, "vtcon%i",
3542 con->node);
3541 3543
3542 if (IS_ERR(con->dev)) { 3544 if (IS_ERR(con->dev)) {
3543 printk(KERN_WARNING "Unable to create " 3545 printk(KERN_WARNING "Unable to create "
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index 1e1b81e57cdc..51966ccf4ea3 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -658,8 +658,9 @@ static int __devinit hwicap_setup(struct device *dev, int id,
658 dev_err(dev, "cdev_add() failed\n"); 658 dev_err(dev, "cdev_add() failed\n");
659 goto failed3; 659 goto failed3;
660 } 660 }
661 /* devfs_mk_cdev(devt, S_IFCHR|S_IRUGO|S_IWUGO, DRIVER_NAME); */ 661
662 device_create(icap_class, dev, devt, "%s%d", DRIVER_NAME, id); 662 device_create_drvdata(icap_class, dev, devt, NULL,
663 "%s%d", DRIVER_NAME, id);
663 return 0; /* success */ 664 return 0; /* success */
664 665
665 failed3: 666 failed3:
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 1d41496ed2f8..ee1df0d45e81 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -38,10 +38,10 @@
38 * also protects the cpufreq_cpu_data array. 38 * also protects the cpufreq_cpu_data array.
39 */ 39 */
40static struct cpufreq_driver *cpufreq_driver; 40static struct cpufreq_driver *cpufreq_driver;
41static struct cpufreq_policy *cpufreq_cpu_data[NR_CPUS]; 41static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
42#ifdef CONFIG_HOTPLUG_CPU 42#ifdef CONFIG_HOTPLUG_CPU
43/* This one keeps track of the previously set governor of a removed CPU */ 43/* This one keeps track of the previously set governor of a removed CPU */
44static struct cpufreq_governor *cpufreq_cpu_governor[NR_CPUS]; 44static DEFINE_PER_CPU(struct cpufreq_governor *, cpufreq_cpu_governor);
45#endif 45#endif
46static DEFINE_SPINLOCK(cpufreq_driver_lock); 46static DEFINE_SPINLOCK(cpufreq_driver_lock);
47 47
@@ -135,7 +135,7 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
135 struct cpufreq_policy *data; 135 struct cpufreq_policy *data;
136 unsigned long flags; 136 unsigned long flags;
137 137
138 if (cpu >= NR_CPUS) 138 if (cpu >= nr_cpu_ids)
139 goto err_out; 139 goto err_out;
140 140
141 /* get the cpufreq driver */ 141 /* get the cpufreq driver */
@@ -149,7 +149,7 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
149 149
150 150
151 /* get the CPU */ 151 /* get the CPU */
152 data = cpufreq_cpu_data[cpu]; 152 data = per_cpu(cpufreq_cpu_data, cpu);
153 153
154 if (!data) 154 if (!data)
155 goto err_out_put_module; 155 goto err_out_put_module;
@@ -327,7 +327,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
327 dprintk("notification %u of frequency transition to %u kHz\n", 327 dprintk("notification %u of frequency transition to %u kHz\n",
328 state, freqs->new); 328 state, freqs->new);
329 329
330 policy = cpufreq_cpu_data[freqs->cpu]; 330 policy = per_cpu(cpufreq_cpu_data, freqs->cpu);
331 switch (state) { 331 switch (state) {
332 332
333 case CPUFREQ_PRECHANGE: 333 case CPUFREQ_PRECHANGE:
@@ -828,8 +828,8 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
828#ifdef CONFIG_SMP 828#ifdef CONFIG_SMP
829 829
830#ifdef CONFIG_HOTPLUG_CPU 830#ifdef CONFIG_HOTPLUG_CPU
831 if (cpufreq_cpu_governor[cpu]){ 831 if (per_cpu(cpufreq_cpu_governor, cpu)) {
832 policy->governor = cpufreq_cpu_governor[cpu]; 832 policy->governor = per_cpu(cpufreq_cpu_governor, cpu);
833 dprintk("Restoring governor %s for cpu %d\n", 833 dprintk("Restoring governor %s for cpu %d\n",
834 policy->governor->name, cpu); 834 policy->governor->name, cpu);
835 } 835 }
@@ -854,7 +854,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
854 854
855 spin_lock_irqsave(&cpufreq_driver_lock, flags); 855 spin_lock_irqsave(&cpufreq_driver_lock, flags);
856 managed_policy->cpus = policy->cpus; 856 managed_policy->cpus = policy->cpus;
857 cpufreq_cpu_data[cpu] = managed_policy; 857 per_cpu(cpufreq_cpu_data, cpu) = managed_policy;
858 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 858 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
859 859
860 dprintk("CPU already managed, adding link\n"); 860 dprintk("CPU already managed, adding link\n");
@@ -899,7 +899,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
899 899
900 spin_lock_irqsave(&cpufreq_driver_lock, flags); 900 spin_lock_irqsave(&cpufreq_driver_lock, flags);
901 for_each_cpu_mask(j, policy->cpus) { 901 for_each_cpu_mask(j, policy->cpus) {
902 cpufreq_cpu_data[j] = policy; 902 per_cpu(cpufreq_cpu_data, j) = policy;
903 per_cpu(policy_cpu, j) = policy->cpu; 903 per_cpu(policy_cpu, j) = policy->cpu;
904 } 904 }
905 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 905 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
@@ -946,7 +946,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
946err_out_unregister: 946err_out_unregister:
947 spin_lock_irqsave(&cpufreq_driver_lock, flags); 947 spin_lock_irqsave(&cpufreq_driver_lock, flags);
948 for_each_cpu_mask(j, policy->cpus) 948 for_each_cpu_mask(j, policy->cpus)
949 cpufreq_cpu_data[j] = NULL; 949 per_cpu(cpufreq_cpu_data, j) = NULL;
950 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 950 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
951 951
952 kobject_put(&policy->kobj); 952 kobject_put(&policy->kobj);
@@ -989,7 +989,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
989 dprintk("unregistering CPU %u\n", cpu); 989 dprintk("unregistering CPU %u\n", cpu);
990 990
991 spin_lock_irqsave(&cpufreq_driver_lock, flags); 991 spin_lock_irqsave(&cpufreq_driver_lock, flags);
992 data = cpufreq_cpu_data[cpu]; 992 data = per_cpu(cpufreq_cpu_data, cpu);
993 993
994 if (!data) { 994 if (!data) {
995 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 995 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
@@ -997,7 +997,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
997 unlock_policy_rwsem_write(cpu); 997 unlock_policy_rwsem_write(cpu);
998 return -EINVAL; 998 return -EINVAL;
999 } 999 }
1000 cpufreq_cpu_data[cpu] = NULL; 1000 per_cpu(cpufreq_cpu_data, cpu) = NULL;
1001 1001
1002 1002
1003#ifdef CONFIG_SMP 1003#ifdef CONFIG_SMP
@@ -1019,19 +1019,19 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
1019#ifdef CONFIG_SMP 1019#ifdef CONFIG_SMP
1020 1020
1021#ifdef CONFIG_HOTPLUG_CPU 1021#ifdef CONFIG_HOTPLUG_CPU
1022 cpufreq_cpu_governor[cpu] = data->governor; 1022 per_cpu(cpufreq_cpu_governor, cpu) = data->governor;
1023#endif 1023#endif
1024 1024
1025 /* if we have other CPUs still registered, we need to unlink them, 1025 /* if we have other CPUs still registered, we need to unlink them,
1026 * or else wait_for_completion below will lock up. Clean the 1026 * or else wait_for_completion below will lock up. Clean the
1027 * cpufreq_cpu_data[] while holding the lock, and remove the sysfs 1027 * per_cpu(cpufreq_cpu_data) while holding the lock, and remove
1028 * links afterwards. 1028 * the sysfs links afterwards.
1029 */ 1029 */
1030 if (unlikely(cpus_weight(data->cpus) > 1)) { 1030 if (unlikely(cpus_weight(data->cpus) > 1)) {
1031 for_each_cpu_mask(j, data->cpus) { 1031 for_each_cpu_mask(j, data->cpus) {
1032 if (j == cpu) 1032 if (j == cpu)
1033 continue; 1033 continue;
1034 cpufreq_cpu_data[j] = NULL; 1034 per_cpu(cpufreq_cpu_data, j) = NULL;
1035 } 1035 }
1036 } 1036 }
1037 1037
@@ -1043,7 +1043,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
1043 continue; 1043 continue;
1044 dprintk("removing link for cpu %u\n", j); 1044 dprintk("removing link for cpu %u\n", j);
1045#ifdef CONFIG_HOTPLUG_CPU 1045#ifdef CONFIG_HOTPLUG_CPU
1046 cpufreq_cpu_governor[j] = data->governor; 1046 per_cpu(cpufreq_cpu_governor, j) = data->governor;
1047#endif 1047#endif
1048 cpu_sys_dev = get_cpu_sysdev(j); 1048 cpu_sys_dev = get_cpu_sysdev(j);
1049 sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq"); 1049 sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq");
@@ -1153,7 +1153,7 @@ EXPORT_SYMBOL(cpufreq_quick_get);
1153 1153
1154static unsigned int __cpufreq_get(unsigned int cpu) 1154static unsigned int __cpufreq_get(unsigned int cpu)
1155{ 1155{
1156 struct cpufreq_policy *policy = cpufreq_cpu_data[cpu]; 1156 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
1157 unsigned int ret_freq = 0; 1157 unsigned int ret_freq = 0;
1158 1158
1159 if (!cpufreq_driver->get) 1159 if (!cpufreq_driver->get)
@@ -1822,16 +1822,19 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
1822 cpufreq_driver = driver_data; 1822 cpufreq_driver = driver_data;
1823 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 1823 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1824 1824
1825 ret = sysdev_driver_register(&cpu_sysdev_class,&cpufreq_sysdev_driver); 1825 ret = sysdev_driver_register(&cpu_sysdev_class,
1826 &cpufreq_sysdev_driver);
1826 1827
1827 if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) { 1828 if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) {
1828 int i; 1829 int i;
1829 ret = -ENODEV; 1830 ret = -ENODEV;
1830 1831
1831 /* check for at least one working CPU */ 1832 /* check for at least one working CPU */
1832 for (i=0; i<NR_CPUS; i++) 1833 for (i = 0; i < nr_cpu_ids; i++)
1833 if (cpufreq_cpu_data[i]) 1834 if (cpu_possible(i) && per_cpu(cpufreq_cpu_data, i)) {
1834 ret = 0; 1835 ret = 0;
1836 break;
1837 }
1835 1838
1836 /* if all ->init() calls failed, unregister */ 1839 /* if all ->init() calls failed, unregister */
1837 if (ret) { 1840 if (ret) {
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index ae70d63a8b26..c0ff97d375d7 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -43,7 +43,7 @@ struct cpufreq_stats {
43#endif 43#endif
44}; 44};
45 45
46static struct cpufreq_stats *cpufreq_stats_table[NR_CPUS]; 46static DEFINE_PER_CPU(struct cpufreq_stats *, cpufreq_stats_table);
47 47
48struct cpufreq_stats_attribute { 48struct cpufreq_stats_attribute {
49 struct attribute attr; 49 struct attribute attr;
@@ -58,7 +58,7 @@ cpufreq_stats_update (unsigned int cpu)
58 58
59 cur_time = get_jiffies_64(); 59 cur_time = get_jiffies_64();
60 spin_lock(&cpufreq_stats_lock); 60 spin_lock(&cpufreq_stats_lock);
61 stat = cpufreq_stats_table[cpu]; 61 stat = per_cpu(cpufreq_stats_table, cpu);
62 if (stat->time_in_state) 62 if (stat->time_in_state)
63 stat->time_in_state[stat->last_index] = 63 stat->time_in_state[stat->last_index] =
64 cputime64_add(stat->time_in_state[stat->last_index], 64 cputime64_add(stat->time_in_state[stat->last_index],
@@ -71,11 +71,11 @@ cpufreq_stats_update (unsigned int cpu)
71static ssize_t 71static ssize_t
72show_total_trans(struct cpufreq_policy *policy, char *buf) 72show_total_trans(struct cpufreq_policy *policy, char *buf)
73{ 73{
74 struct cpufreq_stats *stat = cpufreq_stats_table[policy->cpu]; 74 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
75 if (!stat) 75 if (!stat)
76 return 0; 76 return 0;
77 return sprintf(buf, "%d\n", 77 return sprintf(buf, "%d\n",
78 cpufreq_stats_table[stat->cpu]->total_trans); 78 per_cpu(cpufreq_stats_table, stat->cpu)->total_trans);
79} 79}
80 80
81static ssize_t 81static ssize_t
@@ -83,7 +83,7 @@ show_time_in_state(struct cpufreq_policy *policy, char *buf)
83{ 83{
84 ssize_t len = 0; 84 ssize_t len = 0;
85 int i; 85 int i;
86 struct cpufreq_stats *stat = cpufreq_stats_table[policy->cpu]; 86 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
87 if (!stat) 87 if (!stat)
88 return 0; 88 return 0;
89 cpufreq_stats_update(stat->cpu); 89 cpufreq_stats_update(stat->cpu);
@@ -101,7 +101,7 @@ show_trans_table(struct cpufreq_policy *policy, char *buf)
101 ssize_t len = 0; 101 ssize_t len = 0;
102 int i, j; 102 int i, j;
103 103
104 struct cpufreq_stats *stat = cpufreq_stats_table[policy->cpu]; 104 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
105 if (!stat) 105 if (!stat)
106 return 0; 106 return 0;
107 cpufreq_stats_update(stat->cpu); 107 cpufreq_stats_update(stat->cpu);
@@ -170,7 +170,7 @@ freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq)
170 170
171static void cpufreq_stats_free_table(unsigned int cpu) 171static void cpufreq_stats_free_table(unsigned int cpu)
172{ 172{
173 struct cpufreq_stats *stat = cpufreq_stats_table[cpu]; 173 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, cpu);
174 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 174 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
175 if (policy && policy->cpu == cpu) 175 if (policy && policy->cpu == cpu)
176 sysfs_remove_group(&policy->kobj, &stats_attr_group); 176 sysfs_remove_group(&policy->kobj, &stats_attr_group);
@@ -178,7 +178,7 @@ static void cpufreq_stats_free_table(unsigned int cpu)
178 kfree(stat->time_in_state); 178 kfree(stat->time_in_state);
179 kfree(stat); 179 kfree(stat);
180 } 180 }
181 cpufreq_stats_table[cpu] = NULL; 181 per_cpu(cpufreq_stats_table, cpu) = NULL;
182 if (policy) 182 if (policy)
183 cpufreq_cpu_put(policy); 183 cpufreq_cpu_put(policy);
184} 184}
@@ -192,7 +192,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
192 struct cpufreq_policy *data; 192 struct cpufreq_policy *data;
193 unsigned int alloc_size; 193 unsigned int alloc_size;
194 unsigned int cpu = policy->cpu; 194 unsigned int cpu = policy->cpu;
195 if (cpufreq_stats_table[cpu]) 195 if (per_cpu(cpufreq_stats_table, cpu))
196 return -EBUSY; 196 return -EBUSY;
197 if ((stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL)) == NULL) 197 if ((stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL)) == NULL)
198 return -ENOMEM; 198 return -ENOMEM;
@@ -207,7 +207,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
207 goto error_out; 207 goto error_out;
208 208
209 stat->cpu = cpu; 209 stat->cpu = cpu;
210 cpufreq_stats_table[cpu] = stat; 210 per_cpu(cpufreq_stats_table, cpu) = stat;
211 211
212 for (i=0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 212 for (i=0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
213 unsigned int freq = table[i].frequency; 213 unsigned int freq = table[i].frequency;
@@ -251,7 +251,7 @@ error_out:
251 cpufreq_cpu_put(data); 251 cpufreq_cpu_put(data);
252error_get_fail: 252error_get_fail:
253 kfree(stat); 253 kfree(stat);
254 cpufreq_stats_table[cpu] = NULL; 254 per_cpu(cpufreq_stats_table, cpu) = NULL;
255 return ret; 255 return ret;
256} 256}
257 257
@@ -284,7 +284,7 @@ cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val,
284 if (val != CPUFREQ_POSTCHANGE) 284 if (val != CPUFREQ_POSTCHANGE)
285 return 0; 285 return 0;
286 286
287 stat = cpufreq_stats_table[freq->cpu]; 287 stat = per_cpu(cpufreq_stats_table, freq->cpu);
288 if (!stat) 288 if (!stat)
289 return 0; 289 return 0;
290 290
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index b64c6bc445e3..9071d80fbba2 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -174,7 +174,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
174} 174}
175EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target); 175EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target);
176 176
177static struct cpufreq_frequency_table *show_table[NR_CPUS]; 177static DEFINE_PER_CPU(struct cpufreq_frequency_table *, show_table);
178/** 178/**
179 * show_available_freqs - show available frequencies for the specified CPU 179 * show_available_freqs - show available frequencies for the specified CPU
180 */ 180 */
@@ -185,10 +185,10 @@ static ssize_t show_available_freqs (struct cpufreq_policy *policy, char *buf)
185 ssize_t count = 0; 185 ssize_t count = 0;
186 struct cpufreq_frequency_table *table; 186 struct cpufreq_frequency_table *table;
187 187
188 if (!show_table[cpu]) 188 if (!per_cpu(show_table, cpu))
189 return -ENODEV; 189 return -ENODEV;
190 190
191 table = show_table[cpu]; 191 table = per_cpu(show_table, cpu);
192 192
193 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 193 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
194 if (table[i].frequency == CPUFREQ_ENTRY_INVALID) 194 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
@@ -217,20 +217,20 @@ void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
217 unsigned int cpu) 217 unsigned int cpu)
218{ 218{
219 dprintk("setting show_table for cpu %u to %p\n", cpu, table); 219 dprintk("setting show_table for cpu %u to %p\n", cpu, table);
220 show_table[cpu] = table; 220 per_cpu(show_table, cpu) = table;
221} 221}
222EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr); 222EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr);
223 223
224void cpufreq_frequency_table_put_attr(unsigned int cpu) 224void cpufreq_frequency_table_put_attr(unsigned int cpu)
225{ 225{
226 dprintk("clearing show_table for cpu %u\n", cpu); 226 dprintk("clearing show_table for cpu %u\n", cpu);
227 show_table[cpu] = NULL; 227 per_cpu(show_table, cpu) = NULL;
228} 228}
229EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr); 229EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr);
230 230
231struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu) 231struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu)
232{ 232{
233 return show_table[cpu]; 233 return per_cpu(show_table, cpu);
234} 234}
235EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table); 235EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table);
236 236
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index e949618b9be0..31a0e0b455b6 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -21,7 +21,8 @@ static int __init cpuidle_sysfs_setup(char *unused)
21} 21}
22__setup("cpuidle_sysfs_switch", cpuidle_sysfs_setup); 22__setup("cpuidle_sysfs_switch", cpuidle_sysfs_setup);
23 23
24static ssize_t show_available_governors(struct sys_device *dev, char *buf) 24static ssize_t show_available_governors(struct sys_device *dev,
25 struct sysdev_attribute *attr, char *buf)
25{ 26{
26 ssize_t i = 0; 27 ssize_t i = 0;
27 struct cpuidle_governor *tmp; 28 struct cpuidle_governor *tmp;
@@ -39,7 +40,8 @@ out:
39 return i; 40 return i;
40} 41}
41 42
42static ssize_t show_current_driver(struct sys_device *dev, char *buf) 43static ssize_t show_current_driver(struct sys_device *dev,
44 struct sysdev_attribute *attr, char *buf)
43{ 45{
44 ssize_t ret; 46 ssize_t ret;
45 47
@@ -53,7 +55,8 @@ static ssize_t show_current_driver(struct sys_device *dev, char *buf)
53 return ret; 55 return ret;
54} 56}
55 57
56static ssize_t show_current_governor(struct sys_device *dev, char *buf) 58static ssize_t show_current_governor(struct sys_device *dev,
59 struct sysdev_attribute *attr, char *buf)
57{ 60{
58 ssize_t ret; 61 ssize_t ret;
59 62
@@ -68,6 +71,7 @@ static ssize_t show_current_governor(struct sys_device *dev, char *buf)
68} 71}
69 72
70static ssize_t store_current_governor(struct sys_device *dev, 73static ssize_t store_current_governor(struct sys_device *dev,
74 struct sysdev_attribute *attr,
71 const char *buf, size_t count) 75 const char *buf, size_t count)
72{ 76{
73 char gov_name[CPUIDLE_NAME_LEN]; 77 char gov_name[CPUIDLE_NAME_LEN];
diff --git a/drivers/dca/dca-sysfs.c b/drivers/dca/dca-sysfs.c
index 011328faa5f2..9a70377bfb34 100644
--- a/drivers/dca/dca-sysfs.c
+++ b/drivers/dca/dca-sysfs.c
@@ -14,8 +14,9 @@ int dca_sysfs_add_req(struct dca_provider *dca, struct device *dev, int slot)
14{ 14{
15 struct device *cd; 15 struct device *cd;
16 16
17 cd = device_create(dca_class, dca->cd, MKDEV(0, slot + 1), 17 cd = device_create_drvdata(dca_class, dca->cd,
18 "requester%d", slot); 18 MKDEV(0, slot + 1), NULL,
19 "requester%d", slot);
19 if (IS_ERR(cd)) 20 if (IS_ERR(cd))
20 return PTR_ERR(cd); 21 return PTR_ERR(cd);
21 return 0; 22 return 0;
@@ -46,7 +47,8 @@ idr_try_again:
46 return err; 47 return err;
47 } 48 }
48 49
49 cd = device_create(dca_class, dev, MKDEV(0, 0), "dca%d", dca->id); 50 cd = device_create_drvdata(dca_class, dev, MKDEV(0, 0), NULL,
51 "dca%d", dca->id);
50 if (IS_ERR(cd)) { 52 if (IS_ERR(cd)) {
51 spin_lock(&dca_idr_lock); 53 spin_lock(&dca_idr_lock);
52 idr_remove(&dca_idr, dca->id); 54 idr_remove(&dca_idr, dca->id);
diff --git a/drivers/edac/cell_edac.c b/drivers/edac/cell_edac.c
index b54112ffd282..0e024fe2d8c4 100644
--- a/drivers/edac/cell_edac.c
+++ b/drivers/edac/cell_edac.c
@@ -33,7 +33,7 @@ static void cell_edac_count_ce(struct mem_ctl_info *mci, int chan, u64 ar)
33{ 33{
34 struct cell_edac_priv *priv = mci->pvt_info; 34 struct cell_edac_priv *priv = mci->pvt_info;
35 struct csrow_info *csrow = &mci->csrows[0]; 35 struct csrow_info *csrow = &mci->csrows[0];
36 unsigned long address, pfn, offset; 36 unsigned long address, pfn, offset, syndrome;
37 37
38 dev_dbg(mci->dev, "ECC CE err on node %d, channel %d, ar = 0x%016lx\n", 38 dev_dbg(mci->dev, "ECC CE err on node %d, channel %d, ar = 0x%016lx\n",
39 priv->node, chan, ar); 39 priv->node, chan, ar);
@@ -44,10 +44,11 @@ static void cell_edac_count_ce(struct mem_ctl_info *mci, int chan, u64 ar)
44 address = (address << 1) | chan; 44 address = (address << 1) | chan;
45 pfn = address >> PAGE_SHIFT; 45 pfn = address >> PAGE_SHIFT;
46 offset = address & ~PAGE_MASK; 46 offset = address & ~PAGE_MASK;
47 syndrome = (ar & 0x000000001fe00000ul) >> 21;
47 48
48 /* TODO: Decoding of the error addresss */ 49 /* TODO: Decoding of the error addresss */
49 edac_mc_handle_ce(mci, csrow->first_page + pfn, offset, 50 edac_mc_handle_ce(mci, csrow->first_page + pfn, offset,
50 0, 0, chan, ""); 51 syndrome, 0, chan, "");
51} 52}
52 53
53static void cell_edac_count_ue(struct mem_ctl_info *mci, int chan, u64 ar) 54static void cell_edac_count_ue(struct mem_ctl_info *mci, int chan, u64 ar)
diff --git a/drivers/eisa/Makefile b/drivers/eisa/Makefile
index 70abf93fe6b0..5369ce957c6d 100644
--- a/drivers/eisa/Makefile
+++ b/drivers/eisa/Makefile
@@ -9,7 +9,7 @@ obj-${CONFIG_EISA_VIRTUAL_ROOT} += virtual_root.o
9 9
10 10
11# Ugly hack to get DEVICE_NAME_SIZE value... 11# Ugly hack to get DEVICE_NAME_SIZE value...
12DEVICE_NAME_SIZE =$(shell awk '$$1=="\#define" && $$2=="DEVICE_NAME_SIZE" {print $$3-1}' $(srctree)/include/linux/device.h) 12DEVICE_NAME_SIZE = 50
13 13
14$(obj)/eisa-bus.o: $(obj)/devlist.h 14$(obj)/eisa-bus.o: $(obj)/devlist.h
15 15
diff --git a/drivers/eisa/eisa-bus.c b/drivers/eisa/eisa-bus.c
index 65dcf0432653..c950bf8606d9 100644
--- a/drivers/eisa/eisa-bus.c
+++ b/drivers/eisa/eisa-bus.c
@@ -22,7 +22,7 @@
22 22
23struct eisa_device_info { 23struct eisa_device_info {
24 struct eisa_device_id id; 24 struct eisa_device_id id;
25 char name[DEVICE_NAME_SIZE]; 25 char name[50];
26}; 26};
27 27
28#ifdef CONFIG_EISA_NAMES 28#ifdef CONFIG_EISA_NAMES
@@ -63,7 +63,7 @@ static void __init eisa_name_device (struct eisa_device *edev)
63 if (!strcmp (edev->id.sig, eisa_table[i].id.sig)) { 63 if (!strcmp (edev->id.sig, eisa_table[i].id.sig)) {
64 strlcpy (edev->pretty_name, 64 strlcpy (edev->pretty_name,
65 eisa_table[i].name, 65 eisa_table[i].name,
66 DEVICE_NAME_SIZE); 66 sizeof(edev->pretty_name));
67 return; 67 return;
68 } 68 }
69 } 69 }
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 008c38ba774f..fced1909cbba 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -45,7 +45,7 @@ config GPIO_PCA953X
45 will be called pca953x. 45 will be called pca953x.
46 46
47config GPIO_PCF857X 47config GPIO_PCF857X
48 tristate "PCF857x, PCA857x, and PCA967x I2C GPIO expanders" 48 tristate "PCF857x, PCA{85,96}7x, and MAX732[89] I2C GPIO expanders"
49 depends on I2C 49 depends on I2C
50 help 50 help
51 Say yes here to provide access to most "quasi-bidirectional" I2C 51 Say yes here to provide access to most "quasi-bidirectional" I2C
@@ -54,7 +54,8 @@ config GPIO_PCF857X
54 some of them. Compatible models include: 54 some of them. Compatible models include:
55 55
56 8 bits: pcf8574, pcf8574a, pca8574, pca8574a, 56 8 bits: pcf8574, pcf8574a, pca8574, pca8574a,
57 pca9670, pca9672, pca9674, pca9674a 57 pca9670, pca9672, pca9674, pca9674a,
58 max7328, max7329
58 59
59 16 bits: pcf8575, pcf8575c, pca8575, 60 16 bits: pcf8575, pcf8575c, pca8575,
60 pca9671, pca9673, pca9675 61 pca9671, pca9673, pca9675
@@ -69,6 +70,12 @@ config GPIO_PCF857X
69 70
70comment "SPI GPIO expanders:" 71comment "SPI GPIO expanders:"
71 72
73config GPIO_MAX7301
74 tristate "Maxim MAX7301 GPIO expander"
75 depends on SPI_MASTER
76 help
77 gpio driver for Maxim MAX7301 SPI GPIO expander.
78
72config GPIO_MCP23S08 79config GPIO_MCP23S08
73 tristate "Microchip MCP23S08 I/O expander" 80 tristate "Microchip MCP23S08 I/O expander"
74 depends on SPI_MASTER 81 depends on SPI_MASTER
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index fdde9923cf33..16e796dc5410 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -4,6 +4,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG
4 4
5obj-$(CONFIG_HAVE_GPIO_LIB) += gpiolib.o 5obj-$(CONFIG_HAVE_GPIO_LIB) += gpiolib.o
6 6
7obj-$(CONFIG_GPIO_MAX7301) += max7301.o
7obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o 8obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
8obj-$(CONFIG_GPIO_PCA953X) += pca953x.o 9obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
9obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o 10obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
diff --git a/drivers/gpio/max7301.c b/drivers/gpio/max7301.c
new file mode 100644
index 000000000000..39c795ad8312
--- /dev/null
+++ b/drivers/gpio/max7301.c
@@ -0,0 +1,339 @@
1/**
2 * drivers/gpio/max7301.c
3 *
4 * Copyright (C) 2006 Juergen Beisert, Pengutronix
5 * Copyright (C) 2008 Guennadi Liakhovetski, Pengutronix
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * The Maxim's MAX7301 device is an SPI driven GPIO expander. There are
12 * 28 GPIOs. 8 of them can trigger an interrupt. See datasheet for more
13 * details
14 * Note:
15 * - DIN must be stable at the rising edge of clock.
16 * - when writing:
17 * - always clock in 16 clocks at once
18 * - at DIN: D15 first, D0 last
19 * - D0..D7 = databyte, D8..D14 = commandbyte
20 * - D15 = low -> write command
21 * - when reading
22 * - always clock in 16 clocks at once
23 * - at DIN: D15 first, D0 last
24 * - D0..D7 = dummy, D8..D14 = register address
25 * - D15 = high -> read command
26 * - raise CS and assert it again
27 * - always clock in 16 clocks at once
28 * - at DOUT: D15 first, D0 last
29 * - D0..D7 contains the data from the first cycle
30 *
31 * The driver exports a standard gpiochip interface
32 */
33
34#include <linux/init.h>
35#include <linux/platform_device.h>
36#include <linux/mutex.h>
37#include <linux/spi/spi.h>
38#include <linux/spi/max7301.h>
39#include <linux/gpio.h>
40
41#define DRIVER_NAME "max7301"
42
43/*
44 * Pin configurations, see MAX7301 datasheet page 6
45 */
46#define PIN_CONFIG_MASK 0x03
47#define PIN_CONFIG_IN_PULLUP 0x03
48#define PIN_CONFIG_IN_WO_PULLUP 0x02
49#define PIN_CONFIG_OUT 0x01
50
51#define PIN_NUMBER 28
52
53
54/*
55 * Some registers must be read back to modify.
56 * To save time we cache them here in memory
57 */
58struct max7301 {
59 struct mutex lock;
60 u8 port_config[8]; /* field 0 is unused */
61 u32 out_level; /* cached output levels */
62 struct gpio_chip chip;
63 struct spi_device *spi;
64};
65
66/**
67 * max7301_write - Write a new register content
68 * @spi: The SPI device
69 * @reg: Register offset
70 * @val: Value to write
71 *
72 * A write to the MAX7301 means one message with one transfer
73 *
74 * Returns 0 if successful or a negative value on error
75 */
76static int max7301_write(struct spi_device *spi, unsigned int reg, unsigned int val)
77{
78 u16 word = ((reg & 0x7F) << 8) | (val & 0xFF);
79 return spi_write(spi, (const u8 *)&word, sizeof(word));
80}
81
82/**
83 * max7301_read - Read back register content
84 * @spi: The SPI device
85 * @reg: Register offset
86 *
87 * A read from the MAX7301 means two transfers; here, one message each
88 *
89 * Returns positive 8 bit value from device if successful or a
90 * negative value on error
91 */
92static int max7301_read(struct spi_device *spi, unsigned int reg)
93{
94 int ret;
95 u16 word;
96
97 word = 0x8000 | (reg << 8);
98 ret = spi_write(spi, (const u8 *)&word, sizeof(word));
99 if (ret)
100 return ret;
101 /*
102 * This relies on the fact, that a transfer with NULL tx_buf shifts out
103 * zero bytes (=NOOP for MAX7301)
104 */
105 ret = spi_read(spi, (u8 *)&word, sizeof(word));
106 if (ret)
107 return ret;
108 return word & 0xff;
109}
110
111static int max7301_direction_input(struct gpio_chip *chip, unsigned offset)
112{
113 struct max7301 *ts = container_of(chip, struct max7301, chip);
114 u8 *config;
115 int ret;
116
117 /* First 4 pins are unused in the controller */
118 offset += 4;
119
120 config = &ts->port_config[offset >> 2];
121
122 mutex_lock(&ts->lock);
123
124 /* Standard GPIO API doesn't support pull-ups, has to be extended.
125 * Hard-coding no pollup for now. */
126 *config = (*config & ~(3 << (offset & 3))) | (1 << (offset & 3));
127
128 ret = max7301_write(ts->spi, 0x08 + (offset >> 2), *config);
129
130 mutex_unlock(&ts->lock);
131
132 return ret;
133}
134
135static int __max7301_set(struct max7301 *ts, unsigned offset, int value)
136{
137 if (value) {
138 ts->out_level |= 1 << offset;
139 return max7301_write(ts->spi, 0x20 + offset, 0x01);
140 } else {
141 ts->out_level &= ~(1 << offset);
142 return max7301_write(ts->spi, 0x20 + offset, 0x00);
143 }
144}
145
146static int max7301_direction_output(struct gpio_chip *chip, unsigned offset,
147 int value)
148{
149 struct max7301 *ts = container_of(chip, struct max7301, chip);
150 u8 *config;
151 int ret;
152
153 /* First 4 pins are unused in the controller */
154 offset += 4;
155
156 config = &ts->port_config[offset >> 2];
157
158 mutex_lock(&ts->lock);
159
160 *config = (*config & ~(3 << (offset & 3))) | (1 << (offset & 3));
161
162 ret = __max7301_set(ts, offset, value);
163
164 if (!ret)
165 ret = max7301_write(ts->spi, 0x08 + (offset >> 2), *config);
166
167 mutex_unlock(&ts->lock);
168
169 return ret;
170}
171
172static int max7301_get(struct gpio_chip *chip, unsigned offset)
173{
174 struct max7301 *ts = container_of(chip, struct max7301, chip);
175 int config, level = -EINVAL;
176
177 /* First 4 pins are unused in the controller */
178 offset += 4;
179
180 mutex_lock(&ts->lock);
181
182 config = (ts->port_config[offset >> 2] >> ((offset & 3) * 2)) & 3;
183
184 switch (config) {
185 case 1:
186 /* Output: return cached level */
187 level = !!(ts->out_level & (1 << offset));
188 break;
189 case 2:
190 case 3:
191 /* Input: read out */
192 level = max7301_read(ts->spi, 0x20 + offset) & 0x01;
193 }
194 mutex_unlock(&ts->lock);
195
196 return level;
197}
198
199static void max7301_set(struct gpio_chip *chip, unsigned offset, int value)
200{
201 struct max7301 *ts = container_of(chip, struct max7301, chip);
202
203 /* First 4 pins are unused in the controller */
204 offset += 4;
205
206 mutex_lock(&ts->lock);
207
208 __max7301_set(ts, offset, value);
209
210 mutex_unlock(&ts->lock);
211}
212
213static int __devinit max7301_probe(struct spi_device *spi)
214{
215 struct max7301 *ts;
216 struct max7301_platform_data *pdata;
217 int i, ret;
218
219 pdata = spi->dev.platform_data;
220 if (!pdata || !pdata->base)
221 return -ENODEV;
222
223 /*
224 * bits_per_word cannot be configured in platform data
225 */
226 spi->bits_per_word = 16;
227
228 ret = spi_setup(spi);
229 if (ret < 0)
230 return ret;
231
232 ts = kzalloc(sizeof(struct max7301), GFP_KERNEL);
233 if (!ts)
234 return -ENOMEM;
235
236 mutex_init(&ts->lock);
237
238 dev_set_drvdata(&spi->dev, ts);
239
240 /* Power up the chip and disable IRQ output */
241 max7301_write(spi, 0x04, 0x01);
242
243 ts->spi = spi;
244
245 ts->chip.label = DRIVER_NAME,
246
247 ts->chip.direction_input = max7301_direction_input;
248 ts->chip.get = max7301_get;
249 ts->chip.direction_output = max7301_direction_output;
250 ts->chip.set = max7301_set;
251
252 ts->chip.base = pdata->base;
253 ts->chip.ngpio = PIN_NUMBER;
254 ts->chip.can_sleep = 1;
255 ts->chip.dev = &spi->dev;
256 ts->chip.owner = THIS_MODULE;
257
258 ret = gpiochip_add(&ts->chip);
259 if (ret)
260 goto exit_destroy;
261
262 /*
263 * tristate all pins in hardware and cache the
264 * register values for later use.
265 */
266 for (i = 1; i < 8; i++) {
267 int j;
268 /* 0xAA means input with internal pullup disabled */
269 max7301_write(spi, 0x08 + i, 0xAA);
270 ts->port_config[i] = 0xAA;
271 for (j = 0; j < 4; j++) {
272 int idx = ts->chip.base + (i - 1) * 4 + j;
273 ret = gpio_direction_input(idx);
274 if (ret)
275 goto exit_remove;
276 gpio_free(idx);
277 }
278 }
279 return ret;
280
281exit_remove:
282 gpiochip_remove(&ts->chip);
283exit_destroy:
284 dev_set_drvdata(&spi->dev, NULL);
285 mutex_destroy(&ts->lock);
286 kfree(ts);
287 return ret;
288}
289
290static int max7301_remove(struct spi_device *spi)
291{
292 struct max7301 *ts;
293 int ret;
294
295 ts = dev_get_drvdata(&spi->dev);
296 if (ts == NULL)
297 return -ENODEV;
298
299 dev_set_drvdata(&spi->dev, NULL);
300
301 /* Power down the chip and disable IRQ output */
302 max7301_write(spi, 0x04, 0x00);
303
304 ret = gpiochip_remove(&ts->chip);
305 if (!ret) {
306 mutex_destroy(&ts->lock);
307 kfree(ts);
308 } else
309 dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n",
310 ret);
311
312 return ret;
313}
314
315static struct spi_driver max7301_driver = {
316 .driver = {
317 .name = DRIVER_NAME,
318 .owner = THIS_MODULE,
319 },
320 .probe = max7301_probe,
321 .remove = __devexit_p(max7301_remove),
322};
323
324static int __init max7301_init(void)
325{
326 return spi_register_driver(&max7301_driver);
327}
328
329static void __exit max7301_exit(void)
330{
331 spi_unregister_driver(&max7301_driver);
332}
333
334module_init(max7301_init);
335module_exit(max7301_exit);
336
337MODULE_AUTHOR("Juergen Beisert");
338MODULE_LICENSE("GPL v2");
339MODULE_DESCRIPTION("MAX7301 SPI based GPIO-Expander");
diff --git a/drivers/gpio/pcf857x.c b/drivers/gpio/pcf857x.c
index aa6cc8b2a2bc..d25d356c4f20 100644
--- a/drivers/gpio/pcf857x.c
+++ b/drivers/gpio/pcf857x.c
@@ -37,6 +37,8 @@ static const struct i2c_device_id pcf857x_id[] = {
37 { "pca9671", 16 }, 37 { "pca9671", 16 },
38 { "pca9673", 16 }, 38 { "pca9673", 16 },
39 { "pca9675", 16 }, 39 { "pca9675", 16 },
40 { "max7328", 8 },
41 { "max7329", 8 },
40 { } 42 { }
41}; 43};
42MODULE_DEVICE_TABLE(i2c, pcf857x_id); 44MODULE_DEVICE_TABLE(i2c, pcf857x_id);
@@ -56,6 +58,7 @@ MODULE_DEVICE_TABLE(i2c, pcf857x_id);
56struct pcf857x { 58struct pcf857x {
57 struct gpio_chip chip; 59 struct gpio_chip chip;
58 struct i2c_client *client; 60 struct i2c_client *client;
61 struct mutex lock; /* protect 'out' */
59 unsigned out; /* software latch */ 62 unsigned out; /* software latch */
60}; 63};
61 64
@@ -66,9 +69,14 @@ struct pcf857x {
66static int pcf857x_input8(struct gpio_chip *chip, unsigned offset) 69static int pcf857x_input8(struct gpio_chip *chip, unsigned offset)
67{ 70{
68 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 71 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
72 int status;
69 73
74 mutex_lock(&gpio->lock);
70 gpio->out |= (1 << offset); 75 gpio->out |= (1 << offset);
71 return i2c_smbus_write_byte(gpio->client, gpio->out); 76 status = i2c_smbus_write_byte(gpio->client, gpio->out);
77 mutex_unlock(&gpio->lock);
78
79 return status;
72} 80}
73 81
74static int pcf857x_get8(struct gpio_chip *chip, unsigned offset) 82static int pcf857x_get8(struct gpio_chip *chip, unsigned offset)
@@ -84,12 +92,17 @@ static int pcf857x_output8(struct gpio_chip *chip, unsigned offset, int value)
84{ 92{
85 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 93 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
86 unsigned bit = 1 << offset; 94 unsigned bit = 1 << offset;
95 int status;
87 96
97 mutex_lock(&gpio->lock);
88 if (value) 98 if (value)
89 gpio->out |= bit; 99 gpio->out |= bit;
90 else 100 else
91 gpio->out &= ~bit; 101 gpio->out &= ~bit;
92 return i2c_smbus_write_byte(gpio->client, gpio->out); 102 status = i2c_smbus_write_byte(gpio->client, gpio->out);
103 mutex_unlock(&gpio->lock);
104
105 return status;
93} 106}
94 107
95static void pcf857x_set8(struct gpio_chip *chip, unsigned offset, int value) 108static void pcf857x_set8(struct gpio_chip *chip, unsigned offset, int value)
@@ -124,9 +137,14 @@ static int i2c_read_le16(struct i2c_client *client)
124static int pcf857x_input16(struct gpio_chip *chip, unsigned offset) 137static int pcf857x_input16(struct gpio_chip *chip, unsigned offset)
125{ 138{
126 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 139 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
140 int status;
127 141
142 mutex_lock(&gpio->lock);
128 gpio->out |= (1 << offset); 143 gpio->out |= (1 << offset);
129 return i2c_write_le16(gpio->client, gpio->out); 144 status = i2c_write_le16(gpio->client, gpio->out);
145 mutex_unlock(&gpio->lock);
146
147 return status;
130} 148}
131 149
132static int pcf857x_get16(struct gpio_chip *chip, unsigned offset) 150static int pcf857x_get16(struct gpio_chip *chip, unsigned offset)
@@ -142,12 +160,17 @@ static int pcf857x_output16(struct gpio_chip *chip, unsigned offset, int value)
142{ 160{
143 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 161 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
144 unsigned bit = 1 << offset; 162 unsigned bit = 1 << offset;
163 int status;
145 164
165 mutex_lock(&gpio->lock);
146 if (value) 166 if (value)
147 gpio->out |= bit; 167 gpio->out |= bit;
148 else 168 else
149 gpio->out &= ~bit; 169 gpio->out &= ~bit;
150 return i2c_write_le16(gpio->client, gpio->out); 170 status = i2c_write_le16(gpio->client, gpio->out);
171 mutex_unlock(&gpio->lock);
172
173 return status;
151} 174}
152 175
153static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value) 176static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value)
@@ -173,6 +196,8 @@ static int pcf857x_probe(struct i2c_client *client,
173 if (!gpio) 196 if (!gpio)
174 return -ENOMEM; 197 return -ENOMEM;
175 198
199 mutex_init(&gpio->lock);
200
176 gpio->chip.base = pdata->gpio_base; 201 gpio->chip.base = pdata->gpio_base;
177 gpio->chip.can_sleep = 1; 202 gpio->chip.can_sleep = 1;
178 gpio->chip.owner = THIS_MODULE; 203 gpio->chip.owner = THIS_MODULE;
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 2fde6c63f47d..0c6b4d4e7e27 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -322,8 +322,9 @@ int hidraw_connect(struct hid_device *hid)
322 goto out; 322 goto out;
323 } 323 }
324 324
325 dev->dev = device_create(hidraw_class, NULL, MKDEV(hidraw_major, minor), 325 dev->dev = device_create_drvdata(hidraw_class, NULL,
326 "%s%d", "hidraw", minor); 326 MKDEV(hidraw_major, minor), NULL,
327 "%s%d", "hidraw", minor);
327 328
328 if (IS_ERR(dev->dev)) { 329 if (IS_ERR(dev->dev)) {
329 spin_lock(&minors_lock); 330 spin_lock(&minors_lock);
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 01427c51c7cc..27fe4d8912cb 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -122,7 +122,7 @@ static void hid_reset(struct work_struct *work)
122 dev_dbg(&usbhid->intf->dev, "resetting device\n"); 122 dev_dbg(&usbhid->intf->dev, "resetting device\n");
123 rc = rc_lock = usb_lock_device_for_reset(hid_to_usb_dev(hid), usbhid->intf); 123 rc = rc_lock = usb_lock_device_for_reset(hid_to_usb_dev(hid), usbhid->intf);
124 if (rc_lock >= 0) { 124 if (rc_lock >= 0) {
125 rc = usb_reset_composite_device(hid_to_usb_dev(hid), usbhid->intf); 125 rc = usb_reset_device(hid_to_usb_dev(hid));
126 if (rc_lock) 126 if (rc_lock)
127 usb_unlock_device(hid_to_usb_dev(hid)); 127 usb_unlock_device(hid_to_usb_dev(hid));
128 } 128 }
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c
index 50f22690d611..a4d92d246d52 100644
--- a/drivers/hwmon/hdaps.c
+++ b/drivers/hwmon/hdaps.c
@@ -581,6 +581,8 @@ static int __init hdaps_init(void)
581 /* initialize the input class */ 581 /* initialize the input class */
582 idev = hdaps_idev->input; 582 idev = hdaps_idev->input;
583 idev->name = "hdaps"; 583 idev->name = "hdaps";
584 idev->phys = "isa1600/input0";
585 idev->id.bustype = BUS_ISA;
584 idev->dev.parent = &pdev->dev; 586 idev->dev.parent = &pdev->dev;
585 idev->evbit[0] = BIT_MASK(EV_ABS); 587 idev->evbit[0] = BIT_MASK(EV_ABS);
586 input_set_abs_params(idev, ABS_X, 588 input_set_abs_params(idev, ABS_X,
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 3db28450a3b3..7321a88a5112 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -55,7 +55,8 @@ again:
55 return ERR_PTR(err); 55 return ERR_PTR(err);
56 56
57 id = id & MAX_ID_MASK; 57 id = id & MAX_ID_MASK;
58 hwdev = device_create(hwmon_class, dev, MKDEV(0,0), HWMON_ID_FORMAT, id); 58 hwdev = device_create_drvdata(hwmon_class, dev, MKDEV(0, 0), NULL,
59 HWMON_ID_FORMAT, id);
59 60
60 if (IS_ERR(hwdev)) { 61 if (IS_ERR(hwdev)) {
61 spin_lock(&idr_lock); 62 spin_lock(&idr_lock);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7608df83d6d1..7bf38c418086 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -722,7 +722,8 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
722 722
723 INIT_LIST_HEAD(&driver->clients); 723 INIT_LIST_HEAD(&driver->clients);
724 /* Walk the adapters that are already present */ 724 /* Walk the adapters that are already present */
725 class_for_each_device(&i2c_adapter_class, driver, __attach_adapter); 725 class_for_each_device(&i2c_adapter_class, NULL, driver,
726 __attach_adapter);
726 727
727 mutex_unlock(&core_lock); 728 mutex_unlock(&core_lock);
728 return 0; 729 return 0;
@@ -782,7 +783,8 @@ void i2c_del_driver(struct i2c_driver *driver)
782{ 783{
783 mutex_lock(&core_lock); 784 mutex_lock(&core_lock);
784 785
785 class_for_each_device(&i2c_adapter_class, driver, __detach_adapter); 786 class_for_each_device(&i2c_adapter_class, NULL, driver,
787 __detach_adapter);
786 788
787 driver_unregister(&driver->driver); 789 driver_unregister(&driver->driver);
788 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 790 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 86727fa8858f..9d55c6383b23 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -521,9 +521,9 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
521 return PTR_ERR(i2c_dev); 521 return PTR_ERR(i2c_dev);
522 522
523 /* register this i2c device with the driver core */ 523 /* register this i2c device with the driver core */
524 i2c_dev->dev = device_create(i2c_dev_class, &adap->dev, 524 i2c_dev->dev = device_create_drvdata(i2c_dev_class, &adap->dev,
525 MKDEV(I2C_MAJOR, adap->nr), 525 MKDEV(I2C_MAJOR, adap->nr),
526 "i2c-%d", adap->nr); 526 NULL, "i2c-%d", adap->nr);
527 if (IS_ERR(i2c_dev->dev)) { 527 if (IS_ERR(i2c_dev->dev)) {
528 res = PTR_ERR(i2c_dev->dev); 528 res = PTR_ERR(i2c_dev->dev);
529 goto error; 529 goto error;
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index b711ab96e287..353dd11b9283 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -2697,10 +2697,12 @@ static int ide_tape_probe(ide_drive_t *drive)
2697 2697
2698 idetape_setup(drive, tape, minor); 2698 idetape_setup(drive, tape, minor);
2699 2699
2700 device_create(idetape_sysfs_class, &drive->gendev, 2700 device_create_drvdata(idetape_sysfs_class, &drive->gendev,
2701 MKDEV(IDETAPE_MAJOR, minor), "%s", tape->name); 2701 MKDEV(IDETAPE_MAJOR, minor), NULL,
2702 device_create(idetape_sysfs_class, &drive->gendev, 2702 "%s", tape->name);
2703 MKDEV(IDETAPE_MAJOR, minor + 128), "n%s", tape->name); 2703 device_create_drvdata(idetape_sysfs_class, &drive->gendev,
2704 MKDEV(IDETAPE_MAJOR, minor + 128), NULL,
2705 "n%s", tape->name);
2704 2706
2705 g->fops = &idetape_block_ops; 2707 g->fops = &idetape_block_ops;
2706 ide_register_region(g); 2708 ide_register_region(g);
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
index 9d19aec5820a..b6eb2cf25914 100644
--- a/drivers/ieee1394/dv1394.c
+++ b/drivers/ieee1394/dv1394.c
@@ -2296,9 +2296,10 @@ static void dv1394_add_host(struct hpsb_host *host)
2296 2296
2297 ohci = (struct ti_ohci *)host->hostdata; 2297 ohci = (struct ti_ohci *)host->hostdata;
2298 2298
2299 device_create(hpsb_protocol_class, NULL, MKDEV( 2299 device_create_drvdata(hpsb_protocol_class, NULL,
2300 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)), 2300 MKDEV(IEEE1394_MAJOR,
2301 "dv1394-%d", id); 2301 IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)), NULL,
2302 "dv1394-%d", id);
2302 2303
2303 dv1394_init(ohci, DV1394_NTSC, MODE_RECEIVE); 2304 dv1394_init(ohci, DV1394_NTSC, MODE_RECEIVE);
2304 dv1394_init(ohci, DV1394_NTSC, MODE_TRANSMIT); 2305 dv1394_init(ohci, DV1394_NTSC, MODE_TRANSMIT);
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 05710c7c1220..994a21e5a0aa 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -754,7 +754,8 @@ static void nodemgr_remove_uds(struct node_entry *ne)
754 */ 754 */
755 mutex_lock(&nodemgr_serialize_remove_uds); 755 mutex_lock(&nodemgr_serialize_remove_uds);
756 for (;;) { 756 for (;;) {
757 dev = class_find_device(&nodemgr_ud_class, ne, __match_ne); 757 dev = class_find_device(&nodemgr_ud_class, NULL, ne,
758 __match_ne);
758 if (!dev) 759 if (!dev)
759 break; 760 break;
760 ud = container_of(dev, struct unit_directory, unit_dev); 761 ud = container_of(dev, struct unit_directory, unit_dev);
@@ -901,7 +902,8 @@ static struct node_entry *find_entry_by_guid(u64 guid)
901 struct device *dev; 902 struct device *dev;
902 struct node_entry *ne; 903 struct node_entry *ne;
903 904
904 dev = class_find_device(&nodemgr_ne_class, &guid, __match_ne_guid); 905 dev = class_find_device(&nodemgr_ne_class, NULL, &guid,
906 __match_ne_guid);
905 if (!dev) 907 if (!dev)
906 return NULL; 908 return NULL;
907 ne = container_of(dev, struct node_entry, node_dev); 909 ne = container_of(dev, struct node_entry, node_dev);
@@ -940,7 +942,8 @@ static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host,
940 param.host = host; 942 param.host = host;
941 param.nodeid = nodeid; 943 param.nodeid = nodeid;
942 944
943 dev = class_find_device(&nodemgr_ne_class, &param, __match_ne_nodeid); 945 dev = class_find_device(&nodemgr_ne_class, NULL, &param,
946 __match_ne_nodeid);
944 if (!dev) 947 if (!dev)
945 return NULL; 948 return NULL;
946 ne = container_of(dev, struct node_entry, node_dev); 949 ne = container_of(dev, struct node_entry, node_dev);
@@ -1453,7 +1456,8 @@ static void nodemgr_suspend_ne(struct node_entry *ne)
1453 ne->in_limbo = 1; 1456 ne->in_limbo = 1;
1454 WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo)); 1457 WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo));
1455 1458
1456 class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_suspend); 1459 class_for_each_device(&nodemgr_ud_class, NULL, ne,
1460 __nodemgr_driver_suspend);
1457} 1461}
1458 1462
1459 1463
@@ -1462,7 +1466,8 @@ static void nodemgr_resume_ne(struct node_entry *ne)
1462 ne->in_limbo = 0; 1466 ne->in_limbo = 0;
1463 device_remove_file(&ne->device, &dev_attr_ne_in_limbo); 1467 device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
1464 1468
1465 class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_resume); 1469 class_for_each_device(&nodemgr_ud_class, NULL, ne,
1470 __nodemgr_driver_resume);
1466 HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]", 1471 HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
1467 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid); 1472 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
1468} 1473}
@@ -1498,7 +1503,8 @@ static int __nodemgr_update_pdrv(struct device *dev, void *data)
1498 1503
1499static void nodemgr_update_pdrv(struct node_entry *ne) 1504static void nodemgr_update_pdrv(struct node_entry *ne)
1500{ 1505{
1501 class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_update_pdrv); 1506 class_for_each_device(&nodemgr_ud_class, NULL, ne,
1507 __nodemgr_update_pdrv);
1502} 1508}
1503 1509
1504 1510
@@ -1591,7 +1597,8 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
1591 * while probes are time-consuming. (Well, those probes need some 1597 * while probes are time-consuming. (Well, those probes need some
1592 * improvement...) */ 1598 * improvement...) */
1593 1599
1594 class_for_each_device(&nodemgr_ne_class, &param, __nodemgr_node_probe); 1600 class_for_each_device(&nodemgr_ne_class, NULL, &param,
1601 __nodemgr_node_probe);
1595 1602
1596 /* If we had a bus reset while we were scanning the bus, it is 1603 /* If we had a bus reset while we were scanning the bus, it is
1597 * possible that we did not probe all nodes. In that case, we 1604 * possible that we did not probe all nodes. In that case, we
@@ -1826,7 +1833,7 @@ int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *))
1826 1833
1827 hip.cb = cb; 1834 hip.cb = cb;
1828 hip.data = data; 1835 hip.data = data;
1829 error = class_for_each_device(&hpsb_host_class, &hip, 1836 error = class_for_each_device(&hpsb_host_class, NULL, &hip,
1830 __nodemgr_for_each_host); 1837 __nodemgr_for_each_host);
1831 1838
1832 return error; 1839 return error;
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index 96f2847b0405..6fa9e4a21840 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -3010,10 +3010,10 @@ static int __init init_raw1394(void)
3010 hpsb_register_highlevel(&raw1394_highlevel); 3010 hpsb_register_highlevel(&raw1394_highlevel);
3011 3011
3012 if (IS_ERR 3012 if (IS_ERR
3013 (device_create( 3013 (device_create_drvdata(
3014 hpsb_protocol_class, NULL, 3014 hpsb_protocol_class, NULL,
3015 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16), 3015 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16),
3016 RAW1394_DEVICE_NAME))) { 3016 NULL, RAW1394_DEVICE_NAME))) {
3017 ret = -EFAULT; 3017 ret = -EFAULT;
3018 goto out_unreg; 3018 goto out_unreg;
3019 } 3019 }
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index 069b9f6bf16d..25db6e67fa4e 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -1341,9 +1341,9 @@ static void video1394_add_host (struct hpsb_host *host)
1341 hpsb_set_hostinfo_key(&video1394_highlevel, host, ohci->host->id); 1341 hpsb_set_hostinfo_key(&video1394_highlevel, host, ohci->host->id);
1342 1342
1343 minor = IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id; 1343 minor = IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id;
1344 device_create(hpsb_protocol_class, NULL, 1344 device_create_drvdata(hpsb_protocol_class, NULL,
1345 MKDEV(IEEE1394_MAJOR, minor), 1345 MKDEV(IEEE1394_MAJOR, minor), NULL,
1346 "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id); 1346 "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1347} 1347}
1348 1348
1349 1349
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 55738eead3bf..922d35f4fc08 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -44,6 +44,7 @@
44#include <linux/spinlock.h> 44#include <linux/spinlock.h>
45#include <linux/sysfs.h> 45#include <linux/sysfs.h>
46#include <linux/workqueue.h> 46#include <linux/workqueue.h>
47#include <linux/kdev_t.h>
47 48
48#include <rdma/ib_cache.h> 49#include <rdma/ib_cache.h>
49#include <rdma/ib_cm.h> 50#include <rdma/ib_cm.h>
@@ -162,8 +163,8 @@ struct cm_port {
162 163
163struct cm_device { 164struct cm_device {
164 struct list_head list; 165 struct list_head list;
165 struct ib_device *device; 166 struct ib_device *ib_device;
166 struct kobject dev_obj; 167 struct device *device;
167 u8 ack_delay; 168 u8 ack_delay;
168 struct cm_port *port[0]; 169 struct cm_port *port[0];
169}; 170};
@@ -339,7 +340,7 @@ static void cm_init_av_for_response(struct cm_port *port, struct ib_wc *wc,
339{ 340{
340 av->port = port; 341 av->port = port;
341 av->pkey_index = wc->pkey_index; 342 av->pkey_index = wc->pkey_index;
342 ib_init_ah_from_wc(port->cm_dev->device, port->port_num, wc, 343 ib_init_ah_from_wc(port->cm_dev->ib_device, port->port_num, wc,
343 grh, &av->ah_attr); 344 grh, &av->ah_attr);
344} 345}
345 346
@@ -353,7 +354,7 @@ static int cm_init_av_by_path(struct ib_sa_path_rec *path, struct cm_av *av)
353 354
354 read_lock_irqsave(&cm.device_lock, flags); 355 read_lock_irqsave(&cm.device_lock, flags);
355 list_for_each_entry(cm_dev, &cm.device_list, list) { 356 list_for_each_entry(cm_dev, &cm.device_list, list) {
356 if (!ib_find_cached_gid(cm_dev->device, &path->sgid, 357 if (!ib_find_cached_gid(cm_dev->ib_device, &path->sgid,
357 &p, NULL)) { 358 &p, NULL)) {
358 port = cm_dev->port[p-1]; 359 port = cm_dev->port[p-1];
359 break; 360 break;
@@ -364,13 +365,13 @@ static int cm_init_av_by_path(struct ib_sa_path_rec *path, struct cm_av *av)
364 if (!port) 365 if (!port)
365 return -EINVAL; 366 return -EINVAL;
366 367
367 ret = ib_find_cached_pkey(cm_dev->device, port->port_num, 368 ret = ib_find_cached_pkey(cm_dev->ib_device, port->port_num,
368 be16_to_cpu(path->pkey), &av->pkey_index); 369 be16_to_cpu(path->pkey), &av->pkey_index);
369 if (ret) 370 if (ret)
370 return ret; 371 return ret;
371 372
372 av->port = port; 373 av->port = port;
373 ib_init_ah_from_path(cm_dev->device, port->port_num, path, 374 ib_init_ah_from_path(cm_dev->ib_device, port->port_num, path,
374 &av->ah_attr); 375 &av->ah_attr);
375 av->timeout = path->packet_life_time + 1; 376 av->timeout = path->packet_life_time + 1;
376 return 0; 377 return 0;
@@ -1515,7 +1516,7 @@ static int cm_req_handler(struct cm_work *work)
1515 1516
1516 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad; 1517 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad;
1517 1518
1518 cm_id = ib_create_cm_id(work->port->cm_dev->device, NULL, NULL); 1519 cm_id = ib_create_cm_id(work->port->cm_dev->ib_device, NULL, NULL);
1519 if (IS_ERR(cm_id)) 1520 if (IS_ERR(cm_id))
1520 return PTR_ERR(cm_id); 1521 return PTR_ERR(cm_id);
1521 1522
@@ -1550,7 +1551,7 @@ static int cm_req_handler(struct cm_work *work)
1550 cm_format_paths_from_req(req_msg, &work->path[0], &work->path[1]); 1551 cm_format_paths_from_req(req_msg, &work->path[0], &work->path[1]);
1551 ret = cm_init_av_by_path(&work->path[0], &cm_id_priv->av); 1552 ret = cm_init_av_by_path(&work->path[0], &cm_id_priv->av);
1552 if (ret) { 1553 if (ret) {
1553 ib_get_cached_gid(work->port->cm_dev->device, 1554 ib_get_cached_gid(work->port->cm_dev->ib_device,
1554 work->port->port_num, 0, &work->path[0].sgid); 1555 work->port->port_num, 0, &work->path[0].sgid);
1555 ib_send_cm_rej(cm_id, IB_CM_REJ_INVALID_GID, 1556 ib_send_cm_rej(cm_id, IB_CM_REJ_INVALID_GID,
1556 &work->path[0].sgid, sizeof work->path[0].sgid, 1557 &work->path[0].sgid, sizeof work->path[0].sgid,
@@ -2950,7 +2951,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
2950 struct cm_sidr_req_msg *sidr_req_msg; 2951 struct cm_sidr_req_msg *sidr_req_msg;
2951 struct ib_wc *wc; 2952 struct ib_wc *wc;
2952 2953
2953 cm_id = ib_create_cm_id(work->port->cm_dev->device, NULL, NULL); 2954 cm_id = ib_create_cm_id(work->port->cm_dev->ib_device, NULL, NULL);
2954 if (IS_ERR(cm_id)) 2955 if (IS_ERR(cm_id))
2955 return PTR_ERR(cm_id); 2956 return PTR_ERR(cm_id);
2956 cm_id_priv = container_of(cm_id, struct cm_id_private, id); 2957 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
@@ -3578,7 +3579,7 @@ static void cm_get_ack_delay(struct cm_device *cm_dev)
3578{ 3579{
3579 struct ib_device_attr attr; 3580 struct ib_device_attr attr;
3580 3581
3581 if (ib_query_device(cm_dev->device, &attr)) 3582 if (ib_query_device(cm_dev->ib_device, &attr))
3582 cm_dev->ack_delay = 0; /* acks will rely on packet life time */ 3583 cm_dev->ack_delay = 0; /* acks will rely on packet life time */
3583 else 3584 else
3584 cm_dev->ack_delay = attr.local_ca_ack_delay; 3585 cm_dev->ack_delay = attr.local_ca_ack_delay;
@@ -3618,18 +3619,6 @@ static struct kobj_type cm_port_obj_type = {
3618 .release = cm_release_port_obj 3619 .release = cm_release_port_obj
3619}; 3620};
3620 3621
3621static void cm_release_dev_obj(struct kobject *obj)
3622{
3623 struct cm_device *cm_dev;
3624
3625 cm_dev = container_of(obj, struct cm_device, dev_obj);
3626 kfree(cm_dev);
3627}
3628
3629static struct kobj_type cm_dev_obj_type = {
3630 .release = cm_release_dev_obj
3631};
3632
3633struct class cm_class = { 3622struct class cm_class = {
3634 .name = "infiniband_cm", 3623 .name = "infiniband_cm",
3635}; 3624};
@@ -3640,7 +3629,7 @@ static int cm_create_port_fs(struct cm_port *port)
3640 int i, ret; 3629 int i, ret;
3641 3630
3642 ret = kobject_init_and_add(&port->port_obj, &cm_port_obj_type, 3631 ret = kobject_init_and_add(&port->port_obj, &cm_port_obj_type,
3643 &port->cm_dev->dev_obj, 3632 &port->cm_dev->device->kobj,
3644 "%d", port->port_num); 3633 "%d", port->port_num);
3645 if (ret) { 3634 if (ret) {
3646 kfree(port); 3635 kfree(port);
@@ -3676,7 +3665,7 @@ static void cm_remove_port_fs(struct cm_port *port)
3676 kobject_put(&port->port_obj); 3665 kobject_put(&port->port_obj);
3677} 3666}
3678 3667
3679static void cm_add_one(struct ib_device *device) 3668static void cm_add_one(struct ib_device *ib_device)
3680{ 3669{
3681 struct cm_device *cm_dev; 3670 struct cm_device *cm_dev;
3682 struct cm_port *port; 3671 struct cm_port *port;
@@ -3691,26 +3680,27 @@ static void cm_add_one(struct ib_device *device)
3691 int ret; 3680 int ret;
3692 u8 i; 3681 u8 i;
3693 3682
3694 if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB) 3683 if (rdma_node_get_transport(ib_device->node_type) != RDMA_TRANSPORT_IB)
3695 return; 3684 return;
3696 3685
3697 cm_dev = kzalloc(sizeof(*cm_dev) + sizeof(*port) * 3686 cm_dev = kzalloc(sizeof(*cm_dev) + sizeof(*port) *
3698 device->phys_port_cnt, GFP_KERNEL); 3687 ib_device->phys_port_cnt, GFP_KERNEL);
3699 if (!cm_dev) 3688 if (!cm_dev)
3700 return; 3689 return;
3701 3690
3702 cm_dev->device = device; 3691 cm_dev->ib_device = ib_device;
3703 cm_get_ack_delay(cm_dev); 3692 cm_get_ack_delay(cm_dev);
3704 3693
3705 ret = kobject_init_and_add(&cm_dev->dev_obj, &cm_dev_obj_type, 3694 cm_dev->device = device_create_drvdata(&cm_class, &ib_device->dev,
3706 &cm_class.subsys.kobj, "%s", device->name); 3695 MKDEV(0, 0), NULL,
3707 if (ret) { 3696 "%s", ib_device->name);
3697 if (!cm_dev->device) {
3708 kfree(cm_dev); 3698 kfree(cm_dev);
3709 return; 3699 return;
3710 } 3700 }
3711 3701
3712 set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask); 3702 set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask);
3713 for (i = 1; i <= device->phys_port_cnt; i++) { 3703 for (i = 1; i <= ib_device->phys_port_cnt; i++) {
3714 port = kzalloc(sizeof *port, GFP_KERNEL); 3704 port = kzalloc(sizeof *port, GFP_KERNEL);
3715 if (!port) 3705 if (!port)
3716 goto error1; 3706 goto error1;
@@ -3723,7 +3713,7 @@ static void cm_add_one(struct ib_device *device)
3723 if (ret) 3713 if (ret)
3724 goto error1; 3714 goto error1;
3725 3715
3726 port->mad_agent = ib_register_mad_agent(device, i, 3716 port->mad_agent = ib_register_mad_agent(ib_device, i,
3727 IB_QPT_GSI, 3717 IB_QPT_GSI,
3728 &reg_req, 3718 &reg_req,
3729 0, 3719 0,
@@ -3733,11 +3723,11 @@ static void cm_add_one(struct ib_device *device)
3733 if (IS_ERR(port->mad_agent)) 3723 if (IS_ERR(port->mad_agent))
3734 goto error2; 3724 goto error2;
3735 3725
3736 ret = ib_modify_port(device, i, 0, &port_modify); 3726 ret = ib_modify_port(ib_device, i, 0, &port_modify);
3737 if (ret) 3727 if (ret)
3738 goto error3; 3728 goto error3;
3739 } 3729 }
3740 ib_set_client_data(device, &cm_client, cm_dev); 3730 ib_set_client_data(ib_device, &cm_client, cm_dev);
3741 3731
3742 write_lock_irqsave(&cm.device_lock, flags); 3732 write_lock_irqsave(&cm.device_lock, flags);
3743 list_add_tail(&cm_dev->list, &cm.device_list); 3733 list_add_tail(&cm_dev->list, &cm.device_list);
@@ -3753,14 +3743,14 @@ error1:
3753 port_modify.clr_port_cap_mask = IB_PORT_CM_SUP; 3743 port_modify.clr_port_cap_mask = IB_PORT_CM_SUP;
3754 while (--i) { 3744 while (--i) {
3755 port = cm_dev->port[i-1]; 3745 port = cm_dev->port[i-1];
3756 ib_modify_port(device, port->port_num, 0, &port_modify); 3746 ib_modify_port(ib_device, port->port_num, 0, &port_modify);
3757 ib_unregister_mad_agent(port->mad_agent); 3747 ib_unregister_mad_agent(port->mad_agent);
3758 cm_remove_port_fs(port); 3748 cm_remove_port_fs(port);
3759 } 3749 }
3760 kobject_put(&cm_dev->dev_obj); 3750 device_unregister(cm_dev->device);
3761} 3751}
3762 3752
3763static void cm_remove_one(struct ib_device *device) 3753static void cm_remove_one(struct ib_device *ib_device)
3764{ 3754{
3765 struct cm_device *cm_dev; 3755 struct cm_device *cm_dev;
3766 struct cm_port *port; 3756 struct cm_port *port;
@@ -3770,7 +3760,7 @@ static void cm_remove_one(struct ib_device *device)
3770 unsigned long flags; 3760 unsigned long flags;
3771 int i; 3761 int i;
3772 3762
3773 cm_dev = ib_get_client_data(device, &cm_client); 3763 cm_dev = ib_get_client_data(ib_device, &cm_client);
3774 if (!cm_dev) 3764 if (!cm_dev)
3775 return; 3765 return;
3776 3766
@@ -3778,14 +3768,14 @@ static void cm_remove_one(struct ib_device *device)
3778 list_del(&cm_dev->list); 3768 list_del(&cm_dev->list);
3779 write_unlock_irqrestore(&cm.device_lock, flags); 3769 write_unlock_irqrestore(&cm.device_lock, flags);
3780 3770
3781 for (i = 1; i <= device->phys_port_cnt; i++) { 3771 for (i = 1; i <= ib_device->phys_port_cnt; i++) {
3782 port = cm_dev->port[i-1]; 3772 port = cm_dev->port[i-1];
3783 ib_modify_port(device, port->port_num, 0, &port_modify); 3773 ib_modify_port(ib_device, port->port_num, 0, &port_modify);
3784 ib_unregister_mad_agent(port->mad_agent); 3774 ib_unregister_mad_agent(port->mad_agent);
3785 flush_workqueue(cm.wq); 3775 flush_workqueue(cm.wq);
3786 cm_remove_port_fs(port); 3776 cm_remove_port_fs(port);
3787 } 3777 }
3788 kobject_put(&cm_dev->dev_obj); 3778 device_unregister(cm_dev->device);
3789} 3779}
3790 3780
3791static int __init ib_cm_init(void) 3781static int __init ib_cm_init(void)
diff --git a/drivers/infiniband/hw/ipath/ipath_file_ops.c b/drivers/infiniband/hw/ipath/ipath_file_ops.c
index 35f301c88b57..56c0eda3c077 100644
--- a/drivers/infiniband/hw/ipath/ipath_file_ops.c
+++ b/drivers/infiniband/hw/ipath/ipath_file_ops.c
@@ -2455,7 +2455,7 @@ static int init_cdev(int minor, char *name, const struct file_operations *fops,
2455 goto err_cdev; 2455 goto err_cdev;
2456 } 2456 }
2457 2457
2458 device = device_create(ipath_class, NULL, dev, name); 2458 device = device_create_drvdata(ipath_class, NULL, dev, NULL, name);
2459 2459
2460 if (IS_ERR(device)) { 2460 if (IS_ERR(device)) {
2461 ret = PTR_ERR(device); 2461 ret = PTR_ERR(device);
diff --git a/drivers/input/evbug.c b/drivers/input/evbug.c
index c21f2f127234..0353601ac3b5 100644
--- a/drivers/input/evbug.c
+++ b/drivers/input/evbug.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: evbug.c,v 1.10 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 */ 3 */
6 4
@@ -41,7 +39,7 @@ MODULE_LICENSE("GPL");
41static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) 39static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
42{ 40{
43 printk(KERN_DEBUG "evbug.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n", 41 printk(KERN_DEBUG "evbug.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n",
44 handle->dev->phys, type, code, value); 42 handle->dev->dev.bus_id, type, code, value);
45} 43}
46 44
47static int evbug_connect(struct input_handler *handler, struct input_dev *dev, 45static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
@@ -66,7 +64,10 @@ static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
66 if (error) 64 if (error)
67 goto err_unregister_handle; 65 goto err_unregister_handle;
68 66
69 printk(KERN_DEBUG "evbug.c: Connected device: \"%s\", %s\n", dev->name, dev->phys); 67 printk(KERN_DEBUG "evbug.c: Connected device: %s (%s at %s)\n",
68 dev->dev.bus_id,
69 dev->name ?: "unknown",
70 dev->phys ?: "unknown");
70 71
71 return 0; 72 return 0;
72 73
@@ -79,7 +80,8 @@ static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
79 80
80static void evbug_disconnect(struct input_handle *handle) 81static void evbug_disconnect(struct input_handle *handle)
81{ 82{
82 printk(KERN_DEBUG "evbug.c: Disconnected device: %s\n", handle->dev->phys); 83 printk(KERN_DEBUG "evbug.c: Disconnected device: %s\n",
84 handle->dev->dev.bus_id);
83 85
84 input_close_device(handle); 86 input_close_device(handle);
85 input_unregister_handle(handle); 87 input_unregister_handle(handle);
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index b32984bc516f..2d65411f6763 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -300,6 +300,35 @@ struct input_event_compat {
300 __s32 value; 300 __s32 value;
301}; 301};
302 302
303struct ff_periodic_effect_compat {
304 __u16 waveform;
305 __u16 period;
306 __s16 magnitude;
307 __s16 offset;
308 __u16 phase;
309
310 struct ff_envelope envelope;
311
312 __u32 custom_len;
313 compat_uptr_t custom_data;
314};
315
316struct ff_effect_compat {
317 __u16 type;
318 __s16 id;
319 __u16 direction;
320 struct ff_trigger trigger;
321 struct ff_replay replay;
322
323 union {
324 struct ff_constant_effect constant;
325 struct ff_ramp_effect ramp;
326 struct ff_periodic_effect_compat periodic;
327 struct ff_condition_effect condition[2]; /* One for each axis */
328 struct ff_rumble_effect rumble;
329 } u;
330};
331
303/* Note to the author of this code: did it ever occur to 332/* Note to the author of this code: did it ever occur to
304 you why the ifdefs are needed? Think about it again. -AK */ 333 you why the ifdefs are needed? Think about it again. -AK */
305#ifdef CONFIG_X86_64 334#ifdef CONFIG_X86_64
@@ -368,6 +397,42 @@ static int evdev_event_to_user(char __user *buffer,
368 return 0; 397 return 0;
369} 398}
370 399
400static int evdev_ff_effect_from_user(const char __user *buffer, size_t size,
401 struct ff_effect *effect)
402{
403 if (COMPAT_TEST) {
404 struct ff_effect_compat *compat_effect;
405
406 if (size != sizeof(struct ff_effect_compat))
407 return -EINVAL;
408
409 /*
410 * It so happens that the pointer which needs to be changed
411 * is the last field in the structure, so we can copy the
412 * whole thing and replace just the pointer.
413 */
414
415 compat_effect = (struct ff_effect_compat *)effect;
416
417 if (copy_from_user(compat_effect, buffer,
418 sizeof(struct ff_effect_compat)))
419 return -EFAULT;
420
421 if (compat_effect->type == FF_PERIODIC &&
422 compat_effect->u.periodic.waveform == FF_CUSTOM)
423 effect->u.periodic.custom_data =
424 compat_ptr(compat_effect->u.periodic.custom_data);
425 } else {
426 if (size != sizeof(struct ff_effect))
427 return -EINVAL;
428
429 if (copy_from_user(effect, buffer, sizeof(struct ff_effect)))
430 return -EFAULT;
431 }
432
433 return 0;
434}
435
371#else 436#else
372 437
373static inline size_t evdev_event_size(void) 438static inline size_t evdev_event_size(void)
@@ -393,6 +458,18 @@ static int evdev_event_to_user(char __user *buffer,
393 return 0; 458 return 0;
394} 459}
395 460
461static int evdev_ff_effect_from_user(const char __user *buffer, size_t size,
462 struct ff_effect *effect)
463{
464 if (size != sizeof(struct ff_effect))
465 return -EINVAL;
466
467 if (copy_from_user(effect, buffer, sizeof(struct ff_effect)))
468 return -EFAULT;
469
470 return 0;
471}
472
396#endif /* CONFIG_COMPAT */ 473#endif /* CONFIG_COMPAT */
397 474
398static ssize_t evdev_write(struct file *file, const char __user *buffer, 475static ssize_t evdev_write(struct file *file, const char __user *buffer,
@@ -633,17 +710,6 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
633 710
634 return input_set_keycode(dev, t, v); 711 return input_set_keycode(dev, t, v);
635 712
636 case EVIOCSFF:
637 if (copy_from_user(&effect, p, sizeof(effect)))
638 return -EFAULT;
639
640 error = input_ff_upload(dev, &effect, file);
641
642 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
643 return -EFAULT;
644
645 return error;
646
647 case EVIOCRMFF: 713 case EVIOCRMFF:
648 return input_ff_erase(dev, (int)(unsigned long) p, file); 714 return input_ff_erase(dev, (int)(unsigned long) p, file);
649 715
@@ -733,6 +799,19 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
733 799
734 if (_IOC_DIR(cmd) == _IOC_WRITE) { 800 if (_IOC_DIR(cmd) == _IOC_WRITE) {
735 801
802 if (_IOC_NR(cmd) == _IOC_NR(EVIOCSFF)) {
803
804 if (evdev_ff_effect_from_user(p, _IOC_SIZE(cmd), &effect))
805 return -EFAULT;
806
807 error = input_ff_upload(dev, &effect, file);
808
809 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
810 return -EFAULT;
811
812 return error;
813 }
814
736 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) { 815 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
737 816
738 t = _IOC_NR(cmd) & ABS_MAX; 817 t = _IOC_NR(cmd) & ABS_MAX;
diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c
index d226d935b0dc..6790e975a98c 100644
--- a/drivers/input/ff-memless.c
+++ b/drivers/input/ff-memless.c
@@ -247,9 +247,9 @@ static void ml_combine_effects(struct ff_effect *effect,
247 * in s8, this should be changed to something more generic 247 * in s8, this should be changed to something more generic
248 */ 248 */
249 effect->u.ramp.start_level = 249 effect->u.ramp.start_level =
250 max(min(effect->u.ramp.start_level + x, 0x7f), -0x80); 250 clamp_val(effect->u.ramp.start_level + x, -0x80, 0x7f);
251 effect->u.ramp.end_level = 251 effect->u.ramp.end_level =
252 max(min(effect->u.ramp.end_level + y, 0x7f), -0x80); 252 clamp_val(effect->u.ramp.end_level + y, -0x80, 0x7f);
253 break; 253 break;
254 254
255 case FF_RUMBLE: 255 case FF_RUMBLE:
diff --git a/drivers/input/gameport/emu10k1-gp.c b/drivers/input/gameport/emu10k1-gp.c
index 9793ac36d17f..b04930f7ea7d 100644
--- a/drivers/input/gameport/emu10k1-gp.c
+++ b/drivers/input/gameport/emu10k1-gp.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: emu10k1-gp.c,v 1.8 2002/01/22 20:40:46 vojtech Exp $
3 *
4 * Copyright (c) 2001 Vojtech Pavlik 2 * Copyright (c) 2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index c5600ac5feb3..078e4eed0894 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -36,7 +36,6 @@ EXPORT_SYMBOL(__gameport_register_driver);
36EXPORT_SYMBOL(gameport_unregister_driver); 36EXPORT_SYMBOL(gameport_unregister_driver);
37EXPORT_SYMBOL(gameport_open); 37EXPORT_SYMBOL(gameport_open);
38EXPORT_SYMBOL(gameport_close); 38EXPORT_SYMBOL(gameport_close);
39EXPORT_SYMBOL(gameport_rescan);
40EXPORT_SYMBOL(gameport_set_phys); 39EXPORT_SYMBOL(gameport_set_phys);
41EXPORT_SYMBOL(gameport_start_polling); 40EXPORT_SYMBOL(gameport_start_polling);
42EXPORT_SYMBOL(gameport_stop_polling); 41EXPORT_SYMBOL(gameport_stop_polling);
@@ -230,8 +229,6 @@ static void gameport_find_driver(struct gameport *gameport)
230 */ 229 */
231 230
232enum gameport_event_type { 231enum gameport_event_type {
233 GAMEPORT_RESCAN,
234 GAMEPORT_RECONNECT,
235 GAMEPORT_REGISTER_PORT, 232 GAMEPORT_REGISTER_PORT,
236 GAMEPORT_REGISTER_DRIVER, 233 GAMEPORT_REGISTER_DRIVER,
237}; 234};
@@ -365,15 +362,6 @@ static void gameport_handle_event(void)
365 gameport_add_port(event->object); 362 gameport_add_port(event->object);
366 break; 363 break;
367 364
368 case GAMEPORT_RECONNECT:
369 gameport_reconnect_port(event->object);
370 break;
371
372 case GAMEPORT_RESCAN:
373 gameport_disconnect_port(event->object);
374 gameport_find_driver(event->object);
375 break;
376
377 case GAMEPORT_REGISTER_DRIVER: 365 case GAMEPORT_REGISTER_DRIVER:
378 gameport_add_driver(event->object); 366 gameport_add_driver(event->object);
379 break; 367 break;
@@ -651,16 +639,6 @@ static void gameport_disconnect_port(struct gameport *gameport)
651 device_release_driver(&gameport->dev); 639 device_release_driver(&gameport->dev);
652} 640}
653 641
654void gameport_rescan(struct gameport *gameport)
655{
656 gameport_queue_event(gameport, NULL, GAMEPORT_RESCAN);
657}
658
659void gameport_reconnect(struct gameport *gameport)
660{
661 gameport_queue_event(gameport, NULL, GAMEPORT_RECONNECT);
662}
663
664/* 642/*
665 * Submits register request to kgameportd for subsequent execution. 643 * Submits register request to kgameportd for subsequent execution.
666 * Note that port registration is always asynchronous. 644 * Note that port registration is always asynchronous.
diff --git a/drivers/input/gameport/lightning.c b/drivers/input/gameport/lightning.c
index 6b4d4561d465..06ad36ed3483 100644
--- a/drivers/input/gameport/lightning.c
+++ b/drivers/input/gameport/lightning.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: lightning.c,v 1.20 2002/01/22 20:41:31 vojtech Exp $
3 *
4 * Copyright (c) 1998-2001 Vojtech Pavlik 2 * Copyright (c) 1998-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/gameport/ns558.c b/drivers/input/gameport/ns558.c
index 7b7a546323cf..2b282cde4b89 100644
--- a/drivers/input/gameport/ns558.c
+++ b/drivers/input/gameport/ns558.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: ns558.c,v 1.43 2002/01/24 19:23:21 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * Copyright (c) 1999 Brian Gerst 3 * Copyright (c) 1999 Brian Gerst
6 */ 4 */
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 408df0bd6be5..c13ced3e0d3d 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -242,7 +242,7 @@ static void input_handle_event(struct input_dev *dev,
242 break; 242 break;
243 } 243 }
244 244
245 if (type != EV_SYN) 245 if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
246 dev->sync = 0; 246 dev->sync = 0;
247 247
248 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) 248 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
index 52ba16f487c7..92498d470b1f 100644
--- a/drivers/input/joystick/a3d.c
+++ b/drivers/input/joystick/a3d.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: a3d.c,v 1.21 2002/01/22 20:11:50 vojtech Exp $
3 *
4 * Copyright (c) 1998-2001 Vojtech Pavlik 2 * Copyright (c) 1998-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index deb9f825f92c..05022f07ec77 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: amijoy.c,v 1.13 2002/01/22 20:26:32 vojtech Exp $
3 *
4 * Copyright (c) 1998-2001 Vojtech Pavlik 2 * Copyright (c) 1998-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/joystick/cobra.c b/drivers/input/joystick/cobra.c
index 55646a6d89f5..639b975a8ed7 100644
--- a/drivers/input/joystick/cobra.c
+++ b/drivers/input/joystick/cobra.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: cobra.c,v 1.19 2002/01/22 20:26:52 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index 960e501c60c8..523959484753 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: db9.c,v 1.13 2002/04/07 20:13:37 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index 1f6302c0eb3f..cb6eef1f2d99 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: gf2k.c,v 1.19 2002/01/22 20:27:43 vojtech Exp $
3 *
4 * Copyright (c) 1998-2001 Vojtech Pavlik 2 * Copyright (c) 1998-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c
index fd3853ab1aad..684e07cfccc8 100644
--- a/drivers/input/joystick/grip.c
+++ b/drivers/input/joystick/grip.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: grip.c,v 1.21 2002/01/22 20:27:57 vojtech Exp $
3 *
4 * Copyright (c) 1998-2001 Vojtech Pavlik 2 * Copyright (c) 1998-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index c57e21d68c00..8279481b16e7 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: grip_mp.c,v 1.9 2002/07/20 19:28:45 bonnland Exp $
3 *
4 * Driver for the Gravis Grip Multiport, a gamepad "hub" that 2 * Driver for the Gravis Grip Multiport, a gamepad "hub" that
5 * connects up to four 9-pin digital gamepads/joysticks. 3 * connects up to four 9-pin digital gamepads/joysticks.
6 * Driver tested on SMP and UP kernel versions 2.4.18-4 and 2.4.18-5. 4 * Driver tested on SMP and UP kernel versions 2.4.18-4 and 2.4.18-5.
diff --git a/drivers/input/joystick/guillemot.c b/drivers/input/joystick/guillemot.c
index aa6bfb3fb8cd..25ec3fad9f27 100644
--- a/drivers/input/joystick/guillemot.c
+++ b/drivers/input/joystick/guillemot.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: guillemot.c,v 1.10 2002/01/22 20:28:12 vojtech Exp $
3 *
4 * Copyright (c) 2001 Vojtech Pavlik 2 * Copyright (c) 2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/joystick/iforce/iforce-ff.c b/drivers/input/joystick/iforce/iforce-ff.c
index f2a4381d0ab8..7839b7b6fa96 100644
--- a/drivers/input/joystick/iforce/iforce-ff.c
+++ b/drivers/input/joystick/iforce/iforce-ff.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: iforce-ff.c,v 1.9 2002/02/02 19:28:35 jdeneux Exp $
3 *
4 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz> 2 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
5 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com> 3 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
6 * 4 *
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index a2517fa72eb8..61ee6e38739d 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: iforce-main.c,v 1.19 2002/07/07 10:22:50 jdeneux Exp $
3 *
4 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz> 2 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
5 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com> 3 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
6 * 4 *
diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c
index 45c4939ced75..015b50aa76fc 100644
--- a/drivers/input/joystick/iforce/iforce-packets.c
+++ b/drivers/input/joystick/iforce/iforce-packets.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: iforce-packets.c,v 1.16 2002/07/07 10:22:50 jdeneux Exp $
3 *
4 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz> 2 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
5 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com> 3 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
6 * 4 *
diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c
index 7b4bc19cef27..46d5041d2d9d 100644
--- a/drivers/input/joystick/iforce/iforce-serio.c
+++ b/drivers/input/joystick/iforce/iforce-serio.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: iforce-serio.c,v 1.4 2002/01/28 22:45:00 jdeneux Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik <vojtech@ucw.cz> 2 * Copyright (c) 2000-2001 Vojtech Pavlik <vojtech@ucw.cz>
5 * Copyright (c) 2001, 2007 Johann Deneux <johann.deneux@gmail.com> 3 * Copyright (c) 2001, 2007 Johann Deneux <johann.deneux@gmail.com>
6 * 4 *
diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c
index 7fb3cf81cfbf..851cc4087c2f 100644
--- a/drivers/input/joystick/iforce/iforce-usb.c
+++ b/drivers/input/joystick/iforce/iforce-usb.c
@@ -1,6 +1,4 @@
1 /* 1 /*
2 * $Id: iforce-usb.c,v 1.16 2002/06/09 11:08:04 jdeneux Exp $
3 *
4 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz> 2 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
5 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com> 3 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
6 * 4 *
@@ -89,10 +87,10 @@ static void iforce_usb_irq(struct urb *urb)
89 case -ESHUTDOWN: 87 case -ESHUTDOWN:
90 /* this urb is terminated, clean up */ 88 /* this urb is terminated, clean up */
91 dbg("%s - urb shutting down with status: %d", 89 dbg("%s - urb shutting down with status: %d",
92 __FUNCTION__, urb->status); 90 __func__, urb->status);
93 return; 91 return;
94 default: 92 default:
95 dbg("%s - urb has status of: %d", __FUNCTION__, urb->status); 93 dbg("%s - urb has status of: %d", __func__, urb->status);
96 goto exit; 94 goto exit;
97 } 95 }
98 96
@@ -103,7 +101,7 @@ exit:
103 status = usb_submit_urb (urb, GFP_ATOMIC); 101 status = usb_submit_urb (urb, GFP_ATOMIC);
104 if (status) 102 if (status)
105 err ("%s - usb_submit_urb failed with result %d", 103 err ("%s - usb_submit_urb failed with result %d",
106 __FUNCTION__, status); 104 __func__, status);
107} 105}
108 106
109static void iforce_usb_out(struct urb *urb) 107static void iforce_usb_out(struct urb *urb)
diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h
index a964a7cfd210..f2d91f4028ca 100644
--- a/drivers/input/joystick/iforce/iforce.h
+++ b/drivers/input/joystick/iforce/iforce.h
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: iforce.h,v 1.13 2002/07/07 10:22:50 jdeneux Exp $
3 *
4 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz> 2 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
5 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com> 3 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
6 * 4 *
diff --git a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
index bc8ea95dfd0e..8c3290b68205 100644
--- a/drivers/input/joystick/interact.c
+++ b/drivers/input/joystick/interact.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: interact.c,v 1.16 2002/01/22 20:28:25 vojtech Exp $
3 *
4 * Copyright (c) 2001 Vojtech Pavlik 2 * Copyright (c) 2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
diff --git a/drivers/input/joystick/joydump.c b/drivers/input/joystick/joydump.c
index 88ec5a918f2e..2a1b82c8b31c 100644
--- a/drivers/input/joystick/joydump.c
+++ b/drivers/input/joystick/joydump.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: joydump.c,v 1.1 2002/01/23 06:56:16 jsimmons Exp $
3 *
4 * Copyright (c) 1996-2001 Vojtech Pavlik 2 * Copyright (c) 1996-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/joystick/magellan.c b/drivers/input/joystick/magellan.c
index 54e676948ebb..40e40780747d 100644
--- a/drivers/input/joystick/magellan.c
+++ b/drivers/input/joystick/magellan.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: magellan.c,v 1.16 2002/01/22 20:28:39 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/joystick/spaceball.c b/drivers/input/joystick/spaceball.c
index d4087fd49656..0cd9b29356a8 100644
--- a/drivers/input/joystick/spaceball.c
+++ b/drivers/input/joystick/spaceball.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: spaceball.c,v 1.17 2002/01/22 20:29:03 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
diff --git a/drivers/input/joystick/spaceorb.c b/drivers/input/joystick/spaceorb.c
index f7ce4004f4ba..a694bf8e557b 100644
--- a/drivers/input/joystick/spaceorb.c
+++ b/drivers/input/joystick/spaceorb.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: spaceorb.c,v 1.15 2002/01/22 20:29:19 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
diff --git a/drivers/input/joystick/stinger.c b/drivers/input/joystick/stinger.c
index baa10b2f7ba1..e0db9f5e4b41 100644
--- a/drivers/input/joystick/stinger.c
+++ b/drivers/input/joystick/stinger.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: stinger.c,v 1.10 2002/01/22 20:29:31 vojtech Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik 2 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * Copyright (c) 2000 Mark Fletcher 3 * Copyright (c) 2000 Mark Fletcher
6 */ 4 */
diff --git a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
index 0feeb8acb532..60c37bcb938d 100644
--- a/drivers/input/joystick/tmdc.c
+++ b/drivers/input/joystick/tmdc.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: tmdc.c,v 1.31 2002/01/22 20:29:52 vojtech Exp $
3 *
4 * Copyright (c) 1998-2001 Vojtech Pavlik 2 * Copyright (c) 1998-2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index 989483f53160..b6f859869540 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: turbografx.c,v 1.14 2002/01/22 20:30:39 vojtech Exp $
3 *
4 * Copyright (c) 1998-2001 Vojtech Pavlik 2 * Copyright (c) 1998-2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
diff --git a/drivers/input/joystick/twidjoy.c b/drivers/input/joystick/twidjoy.c
index 1085c841fec4..3f4ec73c9553 100644
--- a/drivers/input/joystick/twidjoy.c
+++ b/drivers/input/joystick/twidjoy.c
@@ -1,8 +1,4 @@
1/* 1/*
2 * $Id: twidjoy.c,v 1.5 2002/01/22 20:31:53 vojtech Exp $
3 *
4 * derived from CVS-ID "stinger.c,v 1.5 2001/05/29 12:57:18 vojtech Exp"
5 *
6 * Copyright (c) 2001 Arndt Schoenewald 2 * Copyright (c) 2001 Arndt Schoenewald
7 * Copyright (c) 2000-2001 Vojtech Pavlik 3 * Copyright (c) 2000-2001 Vojtech Pavlik
8 * Copyright (c) 2000 Mark Fletcher 4 * Copyright (c) 2000 Mark Fletcher
diff --git a/drivers/input/joystick/warrior.c b/drivers/input/joystick/warrior.c
index e928b6e3724a..f72c83e15e60 100644
--- a/drivers/input/joystick/warrior.c
+++ b/drivers/input/joystick/warrior.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: warrior.c,v 1.14 2002/01/22 20:32:10 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index b29e3affb805..87d3e7eabffd 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -418,11 +418,11 @@ static void xpad_irq_in(struct urb *urb)
418 case -ESHUTDOWN: 418 case -ESHUTDOWN:
419 /* this urb is terminated, clean up */ 419 /* this urb is terminated, clean up */
420 dbg("%s - urb shutting down with status: %d", 420 dbg("%s - urb shutting down with status: %d",
421 __FUNCTION__, status); 421 __func__, status);
422 return; 422 return;
423 default: 423 default:
424 dbg("%s - nonzero urb status received: %d", 424 dbg("%s - nonzero urb status received: %d",
425 __FUNCTION__, status); 425 __func__, status);
426 goto exit; 426 goto exit;
427 } 427 }
428 428
@@ -441,7 +441,7 @@ exit:
441 retval = usb_submit_urb (urb, GFP_ATOMIC); 441 retval = usb_submit_urb (urb, GFP_ATOMIC);
442 if (retval) 442 if (retval)
443 err ("%s - usb_submit_urb failed with result %d", 443 err ("%s - usb_submit_urb failed with result %d",
444 __FUNCTION__, retval); 444 __func__, retval);
445} 445}
446 446
447static void xpad_bulk_out(struct urb *urb) 447static void xpad_bulk_out(struct urb *urb)
@@ -477,11 +477,11 @@ static void xpad_irq_out(struct urb *urb)
477 case -ESHUTDOWN: 477 case -ESHUTDOWN:
478 /* this urb is terminated, clean up */ 478 /* this urb is terminated, clean up */
479 dbg("%s - urb shutting down with status: %d", 479 dbg("%s - urb shutting down with status: %d",
480 __FUNCTION__, status); 480 __func__, status);
481 return; 481 return;
482 default: 482 default:
483 dbg("%s - nonzero urb status received: %d", 483 dbg("%s - nonzero urb status received: %d",
484 __FUNCTION__, status); 484 __func__, status);
485 goto exit; 485 goto exit;
486 } 486 }
487 487
@@ -489,7 +489,7 @@ exit:
489 retval = usb_submit_urb(urb, GFP_ATOMIC); 489 retval = usb_submit_urb(urb, GFP_ATOMIC);
490 if (retval) 490 if (retval)
491 err("%s - usb_submit_urb failed with result %d", 491 err("%s - usb_submit_urb failed with result %d",
492 __FUNCTION__, retval); 492 __func__, retval);
493} 493}
494 494
495static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) 495static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index 81bf7562aca0..35149ec455a9 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: amikbd.c,v 1.13 2002/02/01 16:02:24 vojtech Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik 2 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index af58a6f1e898..b1ce10f50bcf 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -68,7 +68,7 @@ MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and
68 * are loadable via an userland utility. 68 * are loadable via an userland utility.
69 */ 69 */
70 70
71static unsigned char atkbd_set2_keycode[512] = { 71static const unsigned short atkbd_set2_keycode[512] = {
72 72
73#ifdef CONFIG_KEYBOARD_ATKBD_HP_KEYCODES 73#ifdef CONFIG_KEYBOARD_ATKBD_HP_KEYCODES
74 74
@@ -99,7 +99,7 @@ static unsigned char atkbd_set2_keycode[512] = {
99#endif 99#endif
100}; 100};
101 101
102static unsigned char atkbd_set3_keycode[512] = { 102static const unsigned short atkbd_set3_keycode[512] = {
103 103
104 0, 0, 0, 0, 0, 0, 0, 59, 1,138,128,129,130, 15, 41, 60, 104 0, 0, 0, 0, 0, 0, 0, 59, 1,138,128,129,130, 15, 41, 60,
105 131, 29, 42, 86, 58, 16, 2, 61,133, 56, 44, 31, 30, 17, 3, 62, 105 131, 29, 42, 86, 58, 16, 2, 61,133, 56, 44, 31, 30, 17, 3, 62,
@@ -115,7 +115,7 @@ static unsigned char atkbd_set3_keycode[512] = {
115 148,149,147,140 115 148,149,147,140
116}; 116};
117 117
118static unsigned char atkbd_unxlate_table[128] = { 118static const unsigned short atkbd_unxlate_table[128] = {
119 0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13, 119 0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13,
120 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27, 120 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27,
121 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42, 121 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42,
@@ -161,7 +161,7 @@ static unsigned char atkbd_unxlate_table[128] = {
161#define ATKBD_SCR_LEFT 249 161#define ATKBD_SCR_LEFT 249
162#define ATKBD_SCR_RIGHT 248 162#define ATKBD_SCR_RIGHT 248
163 163
164#define ATKBD_SPECIAL 248 164#define ATKBD_SPECIAL ATKBD_SCR_RIGHT
165 165
166#define ATKBD_LED_EVENT_BIT 0 166#define ATKBD_LED_EVENT_BIT 0
167#define ATKBD_REP_EVENT_BIT 1 167#define ATKBD_REP_EVENT_BIT 1
@@ -173,7 +173,7 @@ static unsigned char atkbd_unxlate_table[128] = {
173#define ATKBD_XL_HANGEUL 0x10 173#define ATKBD_XL_HANGEUL 0x10
174#define ATKBD_XL_HANJA 0x20 174#define ATKBD_XL_HANJA 0x20
175 175
176static struct { 176static const struct {
177 unsigned char keycode; 177 unsigned char keycode;
178 unsigned char set2; 178 unsigned char set2;
179} atkbd_scroll_keys[] = { 179} atkbd_scroll_keys[] = {
@@ -200,7 +200,7 @@ struct atkbd {
200 char phys[32]; 200 char phys[32];
201 201
202 unsigned short id; 202 unsigned short id;
203 unsigned char keycode[512]; 203 unsigned short keycode[512];
204 DECLARE_BITMAP(force_release_mask, 512); 204 DECLARE_BITMAP(force_release_mask, 512);
205 unsigned char set; 205 unsigned char set;
206 unsigned char translated; 206 unsigned char translated;
@@ -357,7 +357,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
357 unsigned int code = data; 357 unsigned int code = data;
358 int scroll = 0, hscroll = 0, click = -1; 358 int scroll = 0, hscroll = 0, click = -1;
359 int value; 359 int value;
360 unsigned char keycode; 360 unsigned short keycode;
361 361
362#ifdef ATKBD_DEBUG 362#ifdef ATKBD_DEBUG
363 printk(KERN_DEBUG "atkbd.c: Received %02x flags %02x\n", data, flags); 363 printk(KERN_DEBUG "atkbd.c: Received %02x flags %02x\n", data, flags);
@@ -851,6 +851,23 @@ static void atkbd_latitude_keymap_fixup(struct atkbd *atkbd)
851} 851}
852 852
853/* 853/*
854 * Perform fixup for HP system that doesn't generate release
855 * for its video switch
856 */
857static void atkbd_hp_keymap_fixup(struct atkbd *atkbd)
858{
859 const unsigned int forced_release_keys[] = {
860 0x94,
861 };
862 int i;
863
864 if (atkbd->set == 2)
865 for (i = 0; i < ARRAY_SIZE(forced_release_keys); i++)
866 __set_bit(forced_release_keys[i],
867 atkbd->force_release_mask);
868}
869
870/*
854 * atkbd_set_keycode_table() initializes keyboard's keycode table 871 * atkbd_set_keycode_table() initializes keyboard's keycode table
855 * according to the selected scancode set 872 * according to the selected scancode set
856 */ 873 */
@@ -961,16 +978,16 @@ static void atkbd_set_device_attrs(struct atkbd *atkbd)
961 input_dev->evbit[0] |= BIT_MASK(EV_REL); 978 input_dev->evbit[0] |= BIT_MASK(EV_REL);
962 input_dev->relbit[0] = BIT_MASK(REL_WHEEL) | 979 input_dev->relbit[0] = BIT_MASK(REL_WHEEL) |
963 BIT_MASK(REL_HWHEEL); 980 BIT_MASK(REL_HWHEEL);
964 set_bit(BTN_MIDDLE, input_dev->keybit); 981 __set_bit(BTN_MIDDLE, input_dev->keybit);
965 } 982 }
966 983
967 input_dev->keycode = atkbd->keycode; 984 input_dev->keycode = atkbd->keycode;
968 input_dev->keycodesize = sizeof(unsigned char); 985 input_dev->keycodesize = sizeof(unsigned short);
969 input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode); 986 input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode);
970 987
971 for (i = 0; i < 512; i++) 988 for (i = 0; i < 512; i++)
972 if (atkbd->keycode[i] && atkbd->keycode[i] < ATKBD_SPECIAL) 989 if (atkbd->keycode[i] && atkbd->keycode[i] < ATKBD_SPECIAL)
973 set_bit(atkbd->keycode[i], input_dev->keybit); 990 __set_bit(atkbd->keycode[i], input_dev->keybit);
974} 991}
975 992
976/* 993/*
@@ -1452,6 +1469,15 @@ static struct dmi_system_id atkbd_dmi_quirk_table[] __initdata = {
1452 .callback = atkbd_setup_fixup, 1469 .callback = atkbd_setup_fixup,
1453 .driver_data = atkbd_latitude_keymap_fixup, 1470 .driver_data = atkbd_latitude_keymap_fixup,
1454 }, 1471 },
1472 {
1473 .ident = "HP 2133",
1474 .matches = {
1475 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1476 DMI_MATCH(DMI_PRODUCT_NAME, "HP 2133"),
1477 },
1478 .callback = atkbd_setup_fixup,
1479 .driver_data = atkbd_hp_keymap_fixup,
1480 },
1455 { } 1481 { }
1456}; 1482};
1457 1483
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index bbd00c3fe98c..be58730e636a 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -26,23 +26,54 @@
26 26
27#include <asm/gpio.h> 27#include <asm/gpio.h>
28 28
29struct gpio_button_data {
30 struct gpio_keys_button *button;
31 struct input_dev *input;
32 struct timer_list timer;
33};
34
35struct gpio_keys_drvdata {
36 struct input_dev *input;
37 struct gpio_button_data data[0];
38};
39
40static void gpio_keys_report_event(struct gpio_keys_button *button,
41 struct input_dev *input)
42{
43 unsigned int type = button->type ?: EV_KEY;
44 int state = (gpio_get_value(button->gpio) ? 1 : 0) ^ button->active_low;
45
46 input_event(input, type, button->code, !!state);
47 input_sync(input);
48}
49
50static void gpio_check_button(unsigned long _data)
51{
52 struct gpio_button_data *data = (struct gpio_button_data *)_data;
53
54 gpio_keys_report_event(data->button, data->input);
55}
56
29static irqreturn_t gpio_keys_isr(int irq, void *dev_id) 57static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
30{ 58{
31 int i;
32 struct platform_device *pdev = dev_id; 59 struct platform_device *pdev = dev_id;
33 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; 60 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
34 struct input_dev *input = platform_get_drvdata(pdev); 61 struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
62 int i;
35 63
36 for (i = 0; i < pdata->nbuttons; i++) { 64 for (i = 0; i < pdata->nbuttons; i++) {
37 struct gpio_keys_button *button = &pdata->buttons[i]; 65 struct gpio_keys_button *button = &pdata->buttons[i];
38 int gpio = button->gpio;
39 66
40 if (irq == gpio_to_irq(gpio)) { 67 if (irq == gpio_to_irq(button->gpio)) {
41 unsigned int type = button->type ?: EV_KEY; 68 struct gpio_button_data *bdata = &ddata->data[i];
42 int state = (gpio_get_value(gpio) ? 1 : 0) ^ button->active_low; 69
70 if (button->debounce_interval)
71 mod_timer(&bdata->timer,
72 jiffies +
73 msecs_to_jiffies(button->debounce_interval));
74 else
75 gpio_keys_report_event(button, bdata->input);
43 76
44 input_event(input, type, button->code, !!state);
45 input_sync(input);
46 return IRQ_HANDLED; 77 return IRQ_HANDLED;
47 } 78 }
48 } 79 }
@@ -53,17 +84,21 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
53static int __devinit gpio_keys_probe(struct platform_device *pdev) 84static int __devinit gpio_keys_probe(struct platform_device *pdev)
54{ 85{
55 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; 86 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
87 struct gpio_keys_drvdata *ddata;
56 struct input_dev *input; 88 struct input_dev *input;
57 int i, error; 89 int i, error;
58 int wakeup = 0; 90 int wakeup = 0;
59 91
92 ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
93 pdata->nbuttons * sizeof(struct gpio_button_data),
94 GFP_KERNEL);
60 input = input_allocate_device(); 95 input = input_allocate_device();
61 if (!input) 96 if (!ddata || !input) {
62 return -ENOMEM; 97 error = -ENOMEM;
63 98 goto fail1;
64 platform_set_drvdata(pdev, input); 99 }
65 100
66 input->evbit[0] = BIT_MASK(EV_KEY); 101 platform_set_drvdata(pdev, ddata);
67 102
68 input->name = pdev->name; 103 input->name = pdev->name;
69 input->phys = "gpio-keys/input0"; 104 input->phys = "gpio-keys/input0";
@@ -74,16 +109,23 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
74 input->id.product = 0x0001; 109 input->id.product = 0x0001;
75 input->id.version = 0x0100; 110 input->id.version = 0x0100;
76 111
112 ddata->input = input;
113
77 for (i = 0; i < pdata->nbuttons; i++) { 114 for (i = 0; i < pdata->nbuttons; i++) {
78 struct gpio_keys_button *button = &pdata->buttons[i]; 115 struct gpio_keys_button *button = &pdata->buttons[i];
116 struct gpio_button_data *bdata = &ddata->data[i];
79 int irq; 117 int irq;
80 unsigned int type = button->type ?: EV_KEY; 118 unsigned int type = button->type ?: EV_KEY;
81 119
120 bdata->input = input;
121 setup_timer(&bdata->timer,
122 gpio_check_button, (unsigned long)bdata);
123
82 error = gpio_request(button->gpio, button->desc ?: "gpio_keys"); 124 error = gpio_request(button->gpio, button->desc ?: "gpio_keys");
83 if (error < 0) { 125 if (error < 0) {
84 pr_err("gpio-keys: failed to request GPIO %d," 126 pr_err("gpio-keys: failed to request GPIO %d,"
85 " error %d\n", button->gpio, error); 127 " error %d\n", button->gpio, error);
86 goto fail; 128 goto fail2;
87 } 129 }
88 130
89 error = gpio_direction_input(button->gpio); 131 error = gpio_direction_input(button->gpio);
@@ -92,7 +134,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
92 " direction for GPIO %d, error %d\n", 134 " direction for GPIO %d, error %d\n",
93 button->gpio, error); 135 button->gpio, error);
94 gpio_free(button->gpio); 136 gpio_free(button->gpio);
95 goto fail; 137 goto fail2;
96 } 138 }
97 139
98 irq = gpio_to_irq(button->gpio); 140 irq = gpio_to_irq(button->gpio);
@@ -102,7 +144,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
102 " for GPIO %d, error %d\n", 144 " for GPIO %d, error %d\n",
103 button->gpio, error); 145 button->gpio, error);
104 gpio_free(button->gpio); 146 gpio_free(button->gpio);
105 goto fail; 147 goto fail2;
106 } 148 }
107 149
108 error = request_irq(irq, gpio_keys_isr, 150 error = request_irq(irq, gpio_keys_isr,
@@ -114,7 +156,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
114 pr_err("gpio-keys: Unable to claim irq %d; error %d\n", 156 pr_err("gpio-keys: Unable to claim irq %d; error %d\n",
115 irq, error); 157 irq, error);
116 gpio_free(button->gpio); 158 gpio_free(button->gpio);
117 goto fail; 159 goto fail2;
118 } 160 }
119 161
120 if (button->wakeup) 162 if (button->wakeup)
@@ -127,21 +169,25 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
127 if (error) { 169 if (error) {
128 pr_err("gpio-keys: Unable to register input device, " 170 pr_err("gpio-keys: Unable to register input device, "
129 "error: %d\n", error); 171 "error: %d\n", error);
130 goto fail; 172 goto fail2;
131 } 173 }
132 174
133 device_init_wakeup(&pdev->dev, wakeup); 175 device_init_wakeup(&pdev->dev, wakeup);
134 176
135 return 0; 177 return 0;
136 178
137 fail: 179 fail2:
138 while (--i >= 0) { 180 while (--i >= 0) {
139 free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev); 181 free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev);
182 if (pdata->buttons[i].debounce_interval)
183 del_timer_sync(&ddata->data[i].timer);
140 gpio_free(pdata->buttons[i].gpio); 184 gpio_free(pdata->buttons[i].gpio);
141 } 185 }
142 186
143 platform_set_drvdata(pdev, NULL); 187 platform_set_drvdata(pdev, NULL);
188 fail1:
144 input_free_device(input); 189 input_free_device(input);
190 kfree(ddata);
145 191
146 return error; 192 return error;
147} 193}
@@ -149,7 +195,8 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
149static int __devexit gpio_keys_remove(struct platform_device *pdev) 195static int __devexit gpio_keys_remove(struct platform_device *pdev)
150{ 196{
151 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; 197 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
152 struct input_dev *input = platform_get_drvdata(pdev); 198 struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
199 struct input_dev *input = ddata->input;
153 int i; 200 int i;
154 201
155 device_init_wakeup(&pdev->dev, 0); 202 device_init_wakeup(&pdev->dev, 0);
@@ -157,6 +204,8 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
157 for (i = 0; i < pdata->nbuttons; i++) { 204 for (i = 0; i < pdata->nbuttons; i++) {
158 int irq = gpio_to_irq(pdata->buttons[i].gpio); 205 int irq = gpio_to_irq(pdata->buttons[i].gpio);
159 free_irq(irq, pdev); 206 free_irq(irq, pdev);
207 if (pdata->buttons[i].debounce_interval)
208 del_timer_sync(&ddata->data[i].timer);
160 gpio_free(pdata->buttons[i].gpio); 209 gpio_free(pdata->buttons[i].gpio);
161 } 210 }
162 211
diff --git a/drivers/input/keyboard/lkkbd.c b/drivers/input/keyboard/lkkbd.c
index 32e2c2605d95..4730ef35c732 100644
--- a/drivers/input/keyboard/lkkbd.c
+++ b/drivers/input/keyboard/lkkbd.c
@@ -538,11 +538,11 @@ lkkbd_event (struct input_dev *dev, unsigned int type, unsigned int code,
538 switch (code) { 538 switch (code) {
539 case SND_CLICK: 539 case SND_CLICK:
540 if (value == 0) { 540 if (value == 0) {
541 DBG ("%s: Deactivating key clicks\n", __FUNCTION__); 541 DBG ("%s: Deactivating key clicks\n", __func__);
542 lk->serio->write (lk->serio, LK_CMD_DISABLE_KEYCLICK); 542 lk->serio->write (lk->serio, LK_CMD_DISABLE_KEYCLICK);
543 lk->serio->write (lk->serio, LK_CMD_DISABLE_CTRCLICK); 543 lk->serio->write (lk->serio, LK_CMD_DISABLE_CTRCLICK);
544 } else { 544 } else {
545 DBG ("%s: Activating key clicks\n", __FUNCTION__); 545 DBG ("%s: Activating key clicks\n", __func__);
546 lk->serio->write (lk->serio, LK_CMD_ENABLE_KEYCLICK); 546 lk->serio->write (lk->serio, LK_CMD_ENABLE_KEYCLICK);
547 lk->serio->write (lk->serio, volume_to_hw (lk->keyclick_volume)); 547 lk->serio->write (lk->serio, volume_to_hw (lk->keyclick_volume));
548 lk->serio->write (lk->serio, LK_CMD_ENABLE_CTRCLICK); 548 lk->serio->write (lk->serio, LK_CMD_ENABLE_CTRCLICK);
@@ -560,7 +560,7 @@ lkkbd_event (struct input_dev *dev, unsigned int type, unsigned int code,
560 560
561 default: 561 default:
562 printk (KERN_ERR "%s (): Got unknown type %d, code %d, value %d\n", 562 printk (KERN_ERR "%s (): Got unknown type %d, code %d, value %d\n",
563 __FUNCTION__, type, code, value); 563 __func__, type, code, value);
564 } 564 }
565 565
566 return -1; 566 return -1;
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c
index 45767e73f071..6f1516f50750 100644
--- a/drivers/input/keyboard/pxa27x_keypad.c
+++ b/drivers/input/keyboard/pxa27x_keypad.c
@@ -105,6 +105,8 @@ struct pxa27x_keypad {
105 struct input_dev *input_dev; 105 struct input_dev *input_dev;
106 void __iomem *mmio_base; 106 void __iomem *mmio_base;
107 107
108 int irq;
109
108 /* matrix key code map */ 110 /* matrix key code map */
109 unsigned int matrix_keycodes[MAX_MATRIX_KEY_NUM]; 111 unsigned int matrix_keycodes[MAX_MATRIX_KEY_NUM];
110 112
@@ -392,6 +394,10 @@ static int pxa27x_keypad_suspend(struct platform_device *pdev, pm_message_t stat
392 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); 394 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev);
393 395
394 clk_disable(keypad->clk); 396 clk_disable(keypad->clk);
397
398 if (device_may_wakeup(&pdev->dev))
399 enable_irq_wake(keypad->irq);
400
395 return 0; 401 return 0;
396} 402}
397 403
@@ -400,6 +406,9 @@ static int pxa27x_keypad_resume(struct platform_device *pdev)
400 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); 406 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev);
401 struct input_dev *input_dev = keypad->input_dev; 407 struct input_dev *input_dev = keypad->input_dev;
402 408
409 if (device_may_wakeup(&pdev->dev))
410 disable_irq_wake(keypad->irq);
411
403 mutex_lock(&input_dev->mutex); 412 mutex_lock(&input_dev->mutex);
404 413
405 if (input_dev->users) { 414 if (input_dev->users) {
@@ -509,6 +518,8 @@ static int __devinit pxa27x_keypad_probe(struct platform_device *pdev)
509 goto failed_free_dev; 518 goto failed_free_dev;
510 } 519 }
511 520
521 keypad->irq = irq;
522
512 /* Register the input device */ 523 /* Register the input device */
513 error = input_register_device(input_dev); 524 error = input_register_device(input_dev);
514 if (error) { 525 if (error) {
@@ -516,6 +527,8 @@ static int __devinit pxa27x_keypad_probe(struct platform_device *pdev)
516 goto failed_free_irq; 527 goto failed_free_irq;
517 } 528 }
518 529
530 device_init_wakeup(&pdev->dev, 1);
531
519 return 0; 532 return 0;
520 533
521failed_free_irq: 534failed_free_irq:
@@ -539,7 +552,7 @@ static int __devexit pxa27x_keypad_remove(struct platform_device *pdev)
539 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); 552 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev);
540 struct resource *res; 553 struct resource *res;
541 554
542 free_irq(platform_get_irq(pdev, 0), pdev); 555 free_irq(keypad->irq, pdev);
543 556
544 clk_disable(keypad->clk); 557 clk_disable(keypad->clk);
545 clk_put(keypad->clk); 558 clk_put(keypad->clk);
diff --git a/drivers/input/keyboard/sunkbd.c b/drivers/input/keyboard/sunkbd.c
index be0f5d19d023..9fce6d1e29b2 100644
--- a/drivers/input/keyboard/sunkbd.c
+++ b/drivers/input/keyboard/sunkbd.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: sunkbd.c,v 1.14 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/keyboard/xtkbd.c b/drivers/input/keyboard/xtkbd.c
index 152a2c070508..37b01d777a4a 100644
--- a/drivers/input/keyboard/xtkbd.c
+++ b/drivers/input/keyboard/xtkbd.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: xtkbd.c,v 1.11 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 432699d61c58..e99b7882f382 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -189,6 +189,16 @@ config INPUT_UINPUT
189 To compile this driver as a module, choose M here: the 189 To compile this driver as a module, choose M here: the
190 module will be called uinput. 190 module will be called uinput.
191 191
192config INPUT_SGI_BTNS
193 tristate "SGI Indy/O2 volume button interface"
194 depends on SGI_IP22 || SGI_IP32
195 select INPUT_POLLDEV
196 help
197 Say Y here if you want to support SGI Indy/O2 volume button interface.
198
199 To compile this driver as a module, choose M here: the
200 module will be called sgi_btns.
201
192config HP_SDC_RTC 202config HP_SDC_RTC
193 tristate "HP SDC Real Time Clock" 203 tristate "HP SDC Real Time Clock"
194 depends on GSC || HP300 204 depends on GSC || HP300
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index ebd39f291d25..f48009b52226 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -19,3 +19,4 @@ obj-$(CONFIG_INPUT_YEALINK) += yealink.o
19obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o 19obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
20obj-$(CONFIG_INPUT_UINPUT) += uinput.o 20obj-$(CONFIG_INPUT_UINPUT) += uinput.o
21obj-$(CONFIG_INPUT_APANEL) += apanel.o 21obj-$(CONFIG_INPUT_APANEL) += apanel.o
22obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o
diff --git a/drivers/input/misc/ati_remote.c b/drivers/input/misc/ati_remote.c
index f3b86c2b0797..debfc1af9d95 100644
--- a/drivers/input/misc/ati_remote.c
+++ b/drivers/input/misc/ati_remote.c
@@ -330,7 +330,7 @@ static int ati_remote_open(struct input_dev *inputdev)
330 ati_remote->irq_urb->dev = ati_remote->udev; 330 ati_remote->irq_urb->dev = ati_remote->udev;
331 if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) { 331 if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) {
332 dev_err(&ati_remote->interface->dev, 332 dev_err(&ati_remote->interface->dev,
333 "%s: usb_submit_urb failed!\n", __FUNCTION__); 333 "%s: usb_submit_urb failed!\n", __func__);
334 return -EIO; 334 return -EIO;
335 } 335 }
336 336
@@ -356,7 +356,7 @@ static void ati_remote_irq_out(struct urb *urb)
356 356
357 if (urb->status) { 357 if (urb->status) {
358 dev_dbg(&ati_remote->interface->dev, "%s: status %d\n", 358 dev_dbg(&ati_remote->interface->dev, "%s: status %d\n",
359 __FUNCTION__, urb->status); 359 __func__, urb->status);
360 return; 360 return;
361 } 361 }
362 362
@@ -601,17 +601,17 @@ static void ati_remote_irq_in(struct urb *urb)
601 case -ENOENT: 601 case -ENOENT:
602 case -ESHUTDOWN: 602 case -ESHUTDOWN:
603 dev_dbg(&ati_remote->interface->dev, "%s: urb error status, unlink? \n", 603 dev_dbg(&ati_remote->interface->dev, "%s: urb error status, unlink? \n",
604 __FUNCTION__); 604 __func__);
605 return; 605 return;
606 default: /* error */ 606 default: /* error */
607 dev_dbg(&ati_remote->interface->dev, "%s: Nonzero urb status %d\n", 607 dev_dbg(&ati_remote->interface->dev, "%s: Nonzero urb status %d\n",
608 __FUNCTION__, urb->status); 608 __func__, urb->status);
609 } 609 }
610 610
611 retval = usb_submit_urb(urb, GFP_ATOMIC); 611 retval = usb_submit_urb(urb, GFP_ATOMIC);
612 if (retval) 612 if (retval)
613 dev_err(&ati_remote->interface->dev, "%s: usb_submit_urb()=%d\n", 613 dev_err(&ati_remote->interface->dev, "%s: usb_submit_urb()=%d\n",
614 __FUNCTION__, retval); 614 __func__, retval);
615} 615}
616 616
617/* 617/*
@@ -734,7 +734,7 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
734 int err = -ENOMEM; 734 int err = -ENOMEM;
735 735
736 if (iface_host->desc.bNumEndpoints != 2) { 736 if (iface_host->desc.bNumEndpoints != 2) {
737 err("%s: Unexpected desc.bNumEndpoints\n", __FUNCTION__); 737 err("%s: Unexpected desc.bNumEndpoints\n", __func__);
738 return -ENODEV; 738 return -ENODEV;
739 } 739 }
740 740
@@ -742,11 +742,11 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
742 endpoint_out = &iface_host->endpoint[1].desc; 742 endpoint_out = &iface_host->endpoint[1].desc;
743 743
744 if (!usb_endpoint_is_int_in(endpoint_in)) { 744 if (!usb_endpoint_is_int_in(endpoint_in)) {
745 err("%s: Unexpected endpoint_in\n", __FUNCTION__); 745 err("%s: Unexpected endpoint_in\n", __func__);
746 return -ENODEV; 746 return -ENODEV;
747 } 747 }
748 if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) { 748 if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) {
749 err("%s: endpoint_in message size==0? \n", __FUNCTION__); 749 err("%s: endpoint_in message size==0? \n", __func__);
750 return -ENODEV; 750 return -ENODEV;
751 } 751 }
752 752
@@ -814,7 +814,7 @@ static void ati_remote_disconnect(struct usb_interface *interface)
814 ati_remote = usb_get_intfdata(interface); 814 ati_remote = usb_get_intfdata(interface);
815 usb_set_intfdata(interface, NULL); 815 usb_set_intfdata(interface, NULL);
816 if (!ati_remote) { 816 if (!ati_remote) {
817 warn("%s - null device?\n", __FUNCTION__); 817 warn("%s - null device?\n", __func__);
818 return; 818 return;
819 } 819 }
820 820
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index f2709b82485c..a7fabafbd94c 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -137,14 +137,14 @@ static int ati_remote2_open(struct input_dev *idev)
137 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL); 137 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
138 if (r) { 138 if (r) {
139 dev_err(&ar2->intf[0]->dev, 139 dev_err(&ar2->intf[0]->dev,
140 "%s: usb_submit_urb() = %d\n", __FUNCTION__, r); 140 "%s: usb_submit_urb() = %d\n", __func__, r);
141 return r; 141 return r;
142 } 142 }
143 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL); 143 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
144 if (r) { 144 if (r) {
145 usb_kill_urb(ar2->urb[0]); 145 usb_kill_urb(ar2->urb[0]);
146 dev_err(&ar2->intf[1]->dev, 146 dev_err(&ar2->intf[1]->dev,
147 "%s: usb_submit_urb() = %d\n", __FUNCTION__, r); 147 "%s: usb_submit_urb() = %d\n", __func__, r);
148 return r; 148 return r;
149 } 149 }
150 150
@@ -294,17 +294,17 @@ static void ati_remote2_complete_mouse(struct urb *urb)
294 case -ECONNRESET: 294 case -ECONNRESET:
295 case -ESHUTDOWN: 295 case -ESHUTDOWN:
296 dev_dbg(&ar2->intf[0]->dev, 296 dev_dbg(&ar2->intf[0]->dev,
297 "%s(): urb status = %d\n", __FUNCTION__, urb->status); 297 "%s(): urb status = %d\n", __func__, urb->status);
298 return; 298 return;
299 default: 299 default:
300 dev_err(&ar2->intf[0]->dev, 300 dev_err(&ar2->intf[0]->dev,
301 "%s(): urb status = %d\n", __FUNCTION__, urb->status); 301 "%s(): urb status = %d\n", __func__, urb->status);
302 } 302 }
303 303
304 r = usb_submit_urb(urb, GFP_ATOMIC); 304 r = usb_submit_urb(urb, GFP_ATOMIC);
305 if (r) 305 if (r)
306 dev_err(&ar2->intf[0]->dev, 306 dev_err(&ar2->intf[0]->dev,
307 "%s(): usb_submit_urb() = %d\n", __FUNCTION__, r); 307 "%s(): usb_submit_urb() = %d\n", __func__, r);
308} 308}
309 309
310static void ati_remote2_complete_key(struct urb *urb) 310static void ati_remote2_complete_key(struct urb *urb)
@@ -321,17 +321,17 @@ static void ati_remote2_complete_key(struct urb *urb)
321 case -ECONNRESET: 321 case -ECONNRESET:
322 case -ESHUTDOWN: 322 case -ESHUTDOWN:
323 dev_dbg(&ar2->intf[1]->dev, 323 dev_dbg(&ar2->intf[1]->dev,
324 "%s(): urb status = %d\n", __FUNCTION__, urb->status); 324 "%s(): urb status = %d\n", __func__, urb->status);
325 return; 325 return;
326 default: 326 default:
327 dev_err(&ar2->intf[1]->dev, 327 dev_err(&ar2->intf[1]->dev,
328 "%s(): urb status = %d\n", __FUNCTION__, urb->status); 328 "%s(): urb status = %d\n", __func__, urb->status);
329 } 329 }
330 330
331 r = usb_submit_urb(urb, GFP_ATOMIC); 331 r = usb_submit_urb(urb, GFP_ATOMIC);
332 if (r) 332 if (r)
333 dev_err(&ar2->intf[1]->dev, 333 dev_err(&ar2->intf[1]->dev,
334 "%s(): usb_submit_urb() = %d\n", __FUNCTION__, r); 334 "%s(): usb_submit_urb() = %d\n", __func__, r);
335} 335}
336 336
337static int ati_remote2_input_init(struct ati_remote2 *ar2) 337static int ati_remote2_input_init(struct ati_remote2 *ar2)
@@ -438,7 +438,7 @@ static int ati_remote2_setup(struct ati_remote2 *ar2)
438 channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT); 438 channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT);
439 if (r) { 439 if (r) {
440 dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n", 440 dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n",
441 __FUNCTION__, r); 441 __func__, r);
442 return r; 442 return r;
443 } 443 }
444 444
diff --git a/drivers/input/misc/keyspan_remote.c b/drivers/input/misc/keyspan_remote.c
index 952938a8e991..86afdd1fdf9d 100644
--- a/drivers/input/misc/keyspan_remote.c
+++ b/drivers/input/misc/keyspan_remote.c
@@ -159,7 +159,7 @@ static int keyspan_load_tester(struct usb_keyspan* dev, int bits_needed)
159 if (dev->data.pos >= dev->data.len) { 159 if (dev->data.pos >= dev->data.len) {
160 dev_dbg(&dev->udev->dev, 160 dev_dbg(&dev->udev->dev,
161 "%s - Error ran out of data. pos: %d, len: %d\n", 161 "%s - Error ran out of data. pos: %d, len: %d\n",
162 __FUNCTION__, dev->data.pos, dev->data.len); 162 __func__, dev->data.pos, dev->data.len);
163 return -1; 163 return -1;
164 } 164 }
165 165
@@ -267,7 +267,7 @@ static void keyspan_check_data(struct usb_keyspan *remote)
267 remote->data.tester = remote->data.tester >> 6; 267 remote->data.tester = remote->data.tester >> 6;
268 remote->data.bits_left -= 6; 268 remote->data.bits_left -= 6;
269 } else { 269 } else {
270 err("%s - Unknown sequence found in system data.\n", __FUNCTION__); 270 err("%s - Unknown sequence found in system data.\n", __func__);
271 remote->stage = 0; 271 remote->stage = 0;
272 return; 272 return;
273 } 273 }
@@ -286,7 +286,7 @@ static void keyspan_check_data(struct usb_keyspan *remote)
286 remote->data.tester = remote->data.tester >> 6; 286 remote->data.tester = remote->data.tester >> 6;
287 remote->data.bits_left -= 6; 287 remote->data.bits_left -= 6;
288 } else { 288 } else {
289 err("%s - Unknown sequence found in button data.\n", __FUNCTION__); 289 err("%s - Unknown sequence found in button data.\n", __func__);
290 remote->stage = 0; 290 remote->stage = 0;
291 return; 291 return;
292 } 292 }
@@ -302,7 +302,7 @@ static void keyspan_check_data(struct usb_keyspan *remote)
302 remote->data.tester = remote->data.tester >> 6; 302 remote->data.tester = remote->data.tester >> 6;
303 remote->data.bits_left -= 6; 303 remote->data.bits_left -= 6;
304 } else { 304 } else {
305 err("%s - Error in message, invalid toggle.\n", __FUNCTION__); 305 err("%s - Error in message, invalid toggle.\n", __func__);
306 remote->stage = 0; 306 remote->stage = 0;
307 return; 307 return;
308 } 308 }
@@ -317,7 +317,7 @@ static void keyspan_check_data(struct usb_keyspan *remote)
317 317
318 dev_dbg(&remote->udev->dev, 318 dev_dbg(&remote->udev->dev,
319 "%s found valid message: system: %d, button: %d, toggle: %d\n", 319 "%s found valid message: system: %d, button: %d, toggle: %d\n",
320 __FUNCTION__, message.system, message.button, message.toggle); 320 __func__, message.system, message.button, message.toggle);
321 321
322 if (message.toggle != remote->toggle) { 322 if (message.toggle != remote->toggle) {
323 keyspan_report_button(remote, message.button, 1); 323 keyspan_report_button(remote, message.button, 1);
@@ -341,7 +341,7 @@ static int keyspan_setup(struct usb_device* dev)
341 0x11, 0x40, 0x5601, 0x0, NULL, 0, 0); 341 0x11, 0x40, 0x5601, 0x0, NULL, 0, 0);
342 if (retval) { 342 if (retval) {
343 dev_dbg(&dev->dev, "%s - failed to set bit rate due to error: %d\n", 343 dev_dbg(&dev->dev, "%s - failed to set bit rate due to error: %d\n",
344 __FUNCTION__, retval); 344 __func__, retval);
345 return(retval); 345 return(retval);
346 } 346 }
347 347
@@ -349,7 +349,7 @@ static int keyspan_setup(struct usb_device* dev)
349 0x44, 0x40, 0x0, 0x0, NULL, 0, 0); 349 0x44, 0x40, 0x0, 0x0, NULL, 0, 0);
350 if (retval) { 350 if (retval) {
351 dev_dbg(&dev->dev, "%s - failed to set resume sensitivity due to error: %d\n", 351 dev_dbg(&dev->dev, "%s - failed to set resume sensitivity due to error: %d\n",
352 __FUNCTION__, retval); 352 __func__, retval);
353 return(retval); 353 return(retval);
354 } 354 }
355 355
@@ -357,11 +357,11 @@ static int keyspan_setup(struct usb_device* dev)
357 0x22, 0x40, 0x0, 0x0, NULL, 0, 0); 357 0x22, 0x40, 0x0, 0x0, NULL, 0, 0);
358 if (retval) { 358 if (retval) {
359 dev_dbg(&dev->dev, "%s - failed to turn receive on due to error: %d\n", 359 dev_dbg(&dev->dev, "%s - failed to turn receive on due to error: %d\n",
360 __FUNCTION__, retval); 360 __func__, retval);
361 return(retval); 361 return(retval);
362 } 362 }
363 363
364 dev_dbg(&dev->dev, "%s - Setup complete.\n", __FUNCTION__); 364 dev_dbg(&dev->dev, "%s - Setup complete.\n", __func__);
365 return(retval); 365 return(retval);
366} 366}
367 367
@@ -397,7 +397,7 @@ static void keyspan_irq_recv(struct urb *urb)
397resubmit: 397resubmit:
398 retval = usb_submit_urb(urb, GFP_ATOMIC); 398 retval = usb_submit_urb(urb, GFP_ATOMIC);
399 if (retval) 399 if (retval)
400 err ("%s - usb_submit_urb failed with result: %d", __FUNCTION__, retval); 400 err ("%s - usb_submit_urb failed with result: %d", __func__, retval);
401} 401}
402 402
403static int keyspan_open(struct input_dev *dev) 403static int keyspan_open(struct input_dev *dev)
diff --git a/drivers/input/misc/powermate.c b/drivers/input/misc/powermate.c
index 7a7b8c7b9633..a53c4885fbad 100644
--- a/drivers/input/misc/powermate.c
+++ b/drivers/input/misc/powermate.c
@@ -96,10 +96,10 @@ static void powermate_irq(struct urb *urb)
96 case -ENOENT: 96 case -ENOENT:
97 case -ESHUTDOWN: 97 case -ESHUTDOWN:
98 /* this urb is terminated, clean up */ 98 /* this urb is terminated, clean up */
99 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 99 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
100 return; 100 return;
101 default: 101 default:
102 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 102 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
103 goto exit; 103 goto exit;
104 } 104 }
105 105
@@ -112,7 +112,7 @@ exit:
112 retval = usb_submit_urb (urb, GFP_ATOMIC); 112 retval = usb_submit_urb (urb, GFP_ATOMIC);
113 if (retval) 113 if (retval)
114 err ("%s - usb_submit_urb failed with result %d", 114 err ("%s - usb_submit_urb failed with result %d",
115 __FUNCTION__, retval); 115 __func__, retval);
116} 116}
117 117
118/* Decide if we need to issue a control message and do so. Must be called with pm->lock taken */ 118/* Decide if we need to issue a control message and do so. Must be called with pm->lock taken */
diff --git a/drivers/input/misc/sgi_btns.c b/drivers/input/misc/sgi_btns.c
new file mode 100644
index 000000000000..ce238f59b3c8
--- /dev/null
+++ b/drivers/input/misc/sgi_btns.c
@@ -0,0 +1,178 @@
1/*
2 * SGI Volume Button interface driver
3 *
4 * Copyright (C) 2008 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20#include <linux/init.h>
21#include <linux/input-polldev.h>
22#include <linux/ioport.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
25
26#ifdef CONFIG_SGI_IP22
27#include <asm/sgi/ioc.h>
28
29static inline u8 button_status(void)
30{
31 u8 status;
32
33 status = readb(&sgioc->panel) ^ 0xa0;
34 return ((status & 0x80) >> 6) | ((status & 0x20) >> 5);
35}
36#endif
37
38#ifdef CONFIG_SGI_IP32
39#include <asm/ip32/mace.h>
40
41static inline u8 button_status(void)
42{
43 u64 status;
44
45 status = readq(&mace->perif.audio.control);
46 writeq(status & ~(3U << 23), &mace->perif.audio.control);
47
48 return (status >> 23) & 3;
49}
50#endif
51
52#define BUTTONS_POLL_INTERVAL 30 /* msec */
53#define BUTTONS_COUNT_THRESHOLD 3
54
55static const unsigned short sgi_map[] = {
56 KEY_VOLUMEDOWN,
57 KEY_VOLUMEUP
58};
59
60struct buttons_dev {
61 struct input_polled_dev *poll_dev;
62 unsigned short keymap[ARRAY_SIZE(sgi_map)];
63 int count[ARRAY_SIZE(sgi_map)];
64};
65
66static void handle_buttons(struct input_polled_dev *dev)
67{
68 struct buttons_dev *bdev = dev->private;
69 struct input_dev *input = dev->input;
70 u8 status;
71 int i;
72
73 status = button_status();
74
75 for (i = 0; i < ARRAY_SIZE(bdev->keymap); i++) {
76 if (status & (1U << i)) {
77 if (++bdev->count[i] == BUTTONS_COUNT_THRESHOLD) {
78 input_event(input, EV_MSC, MSC_SCAN, i);
79 input_report_key(input, bdev->keymap[i], 1);
80 input_sync(input);
81 }
82 } else {
83 if (bdev->count[i] >= BUTTONS_COUNT_THRESHOLD) {
84 input_event(input, EV_MSC, MSC_SCAN, i);
85 input_report_key(input, bdev->keymap[i], 0);
86 input_sync(input);
87 }
88 bdev->count[i] = 0;
89 }
90 }
91}
92
93static int __devinit sgi_buttons_probe(struct platform_device *pdev)
94{
95 struct buttons_dev *bdev;
96 struct input_polled_dev *poll_dev;
97 struct input_dev *input;
98 int error, i;
99
100 bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL);
101 poll_dev = input_allocate_polled_device();
102 if (!bdev || !poll_dev) {
103 error = -ENOMEM;
104 goto err_free_mem;
105 }
106
107 memcpy(bdev->keymap, sgi_map, sizeof(bdev->keymap));
108
109 poll_dev->private = bdev;
110 poll_dev->poll = handle_buttons;
111 poll_dev->poll_interval = BUTTONS_POLL_INTERVAL;
112
113 input = poll_dev->input;
114 input->name = "SGI buttons";
115 input->phys = "sgi/input0";
116 input->id.bustype = BUS_HOST;
117 input->dev.parent = &pdev->dev;
118
119 input->keycode = bdev->keymap;
120 input->keycodemax = ARRAY_SIZE(bdev->keymap);
121 input->keycodesize = sizeof(unsigned short);
122
123 input_set_capability(input, EV_MSC, MSC_SCAN);
124 __set_bit(EV_KEY, input->evbit);
125 for (i = 0; i < ARRAY_SIZE(sgi_map); i++)
126 __set_bit(bdev->keymap[i], input->keybit);
127 __clear_bit(KEY_RESERVED, input->keybit);
128
129 bdev->poll_dev = poll_dev;
130 dev_set_drvdata(&pdev->dev, bdev);
131
132 error = input_register_polled_device(poll_dev);
133 if (error)
134 goto err_free_mem;
135
136 return 0;
137
138 err_free_mem:
139 input_free_polled_device(poll_dev);
140 kfree(bdev);
141 dev_set_drvdata(&pdev->dev, NULL);
142 return error;
143}
144
145static int __devexit sgi_buttons_remove(struct platform_device *pdev)
146{
147 struct device *dev = &pdev->dev;
148 struct buttons_dev *bdev = dev_get_drvdata(dev);
149
150 input_unregister_polled_device(bdev->poll_dev);
151 input_free_polled_device(bdev->poll_dev);
152 kfree(bdev);
153 dev_set_drvdata(dev, NULL);
154
155 return 0;
156}
157
158static struct platform_driver sgi_buttons_driver = {
159 .probe = sgi_buttons_probe,
160 .remove = __devexit_p(sgi_buttons_remove),
161 .driver = {
162 .name = "sgibtns",
163 .owner = THIS_MODULE,
164 },
165};
166
167static int __init sgi_buttons_init(void)
168{
169 return platform_driver_register(&sgi_buttons_driver);
170}
171
172static void __exit sgi_buttons_exit(void)
173{
174 platform_driver_unregister(&sgi_buttons_driver);
175}
176
177module_init(sgi_buttons_init);
178module_exit(sgi_buttons_exit);
diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c
index 72176f3d49cb..fe268be3293b 100644
--- a/drivers/input/misc/wistron_btns.c
+++ b/drivers/input/misc/wistron_btns.c
@@ -1186,7 +1186,7 @@ static int wistron_setkeycode(struct input_dev *dev, int scancode, int keycode)
1186 1186
1187static int __devinit setup_input_dev(void) 1187static int __devinit setup_input_dev(void)
1188{ 1188{
1189 const struct key_entry *key; 1189 struct key_entry *key;
1190 struct input_dev *input_dev; 1190 struct input_dev *input_dev;
1191 int error; 1191 int error;
1192 1192
@@ -1219,6 +1219,23 @@ static int __devinit setup_input_dev(void)
1219 set_bit(key->sw.code, input_dev->swbit); 1219 set_bit(key->sw.code, input_dev->swbit);
1220 break; 1220 break;
1221 1221
1222 /* if wifi or bluetooth are not available, create normal keys */
1223 case KE_WIFI:
1224 if (!have_wifi) {
1225 key->type = KE_KEY;
1226 key->keycode = KEY_WLAN;
1227 key--;
1228 }
1229 break;
1230
1231 case KE_BLUETOOTH:
1232 if (!have_bluetooth) {
1233 key->type = KE_KEY;
1234 key->keycode = KEY_BLUETOOTH;
1235 key--;
1236 }
1237 break;
1238
1222 default: 1239 default:
1223 break; 1240 break;
1224 } 1241 }
diff --git a/drivers/input/misc/yealink.c b/drivers/input/misc/yealink.c
index 46279ef2b649..facefd3dba29 100644
--- a/drivers/input/misc/yealink.c
+++ b/drivers/input/misc/yealink.c
@@ -119,6 +119,8 @@ struct yealink_dev {
119 u8 lcdMap[ARRAY_SIZE(lcdMap)]; /* state of LCD, LED ... */ 119 u8 lcdMap[ARRAY_SIZE(lcdMap)]; /* state of LCD, LED ... */
120 int key_code; /* last reported key */ 120 int key_code; /* last reported key */
121 121
122 unsigned int shutdown:1;
123
122 int stat_ix; 124 int stat_ix;
123 union { 125 union {
124 struct yld_status s; 126 struct yld_status s;
@@ -424,10 +426,10 @@ send_update:
424static void urb_irq_callback(struct urb *urb) 426static void urb_irq_callback(struct urb *urb)
425{ 427{
426 struct yealink_dev *yld = urb->context; 428 struct yealink_dev *yld = urb->context;
427 int ret; 429 int ret, status = urb->status;
428 430
429 if (urb->status) 431 if (status)
430 err("%s - urb status %d", __FUNCTION__, urb->status); 432 err("%s - urb status %d", __func__, status);
431 433
432 switch (yld->irq_data->cmd) { 434 switch (yld->irq_data->cmd) {
433 case CMD_KEYPRESS: 435 case CMD_KEYPRESS:
@@ -447,33 +449,38 @@ static void urb_irq_callback(struct urb *urb)
447 449
448 yealink_do_idle_tasks(yld); 450 yealink_do_idle_tasks(yld);
449 451
450 ret = usb_submit_urb(yld->urb_ctl, GFP_ATOMIC); 452 if (!yld->shutdown) {
451 if (ret) 453 ret = usb_submit_urb(yld->urb_ctl, GFP_ATOMIC);
452 err("%s - usb_submit_urb failed %d", __FUNCTION__, ret); 454 if (ret && ret != -EPERM)
455 err("%s - usb_submit_urb failed %d", __func__, ret);
456 }
453} 457}
454 458
455static void urb_ctl_callback(struct urb *urb) 459static void urb_ctl_callback(struct urb *urb)
456{ 460{
457 struct yealink_dev *yld = urb->context; 461 struct yealink_dev *yld = urb->context;
458 int ret; 462 int ret = 0, status = urb->status;
459 463
460 if (urb->status) 464 if (status)
461 err("%s - urb status %d", __FUNCTION__, urb->status); 465 err("%s - urb status %d", __func__, status);
462 466
463 switch (yld->ctl_data->cmd) { 467 switch (yld->ctl_data->cmd) {
464 case CMD_KEYPRESS: 468 case CMD_KEYPRESS:
465 case CMD_SCANCODE: 469 case CMD_SCANCODE:
466 /* ask for a response */ 470 /* ask for a response */
467 ret = usb_submit_urb(yld->urb_irq, GFP_ATOMIC); 471 if (!yld->shutdown)
472 ret = usb_submit_urb(yld->urb_irq, GFP_ATOMIC);
468 break; 473 break;
469 default: 474 default:
470 /* send new command */ 475 /* send new command */
471 yealink_do_idle_tasks(yld); 476 yealink_do_idle_tasks(yld);
472 ret = usb_submit_urb(yld->urb_ctl, GFP_ATOMIC); 477 if (!yld->shutdown)
478 ret = usb_submit_urb(yld->urb_ctl, GFP_ATOMIC);
479 break;
473 } 480 }
474 481
475 if (ret) 482 if (ret && ret != -EPERM)
476 err("%s - usb_submit_urb failed %d", __FUNCTION__, ret); 483 err("%s - usb_submit_urb failed %d", __func__, ret);
477} 484}
478 485
479/******************************************************************************* 486/*******************************************************************************
@@ -505,7 +512,7 @@ static int input_open(struct input_dev *dev)
505 struct yealink_dev *yld = input_get_drvdata(dev); 512 struct yealink_dev *yld = input_get_drvdata(dev);
506 int i, ret; 513 int i, ret;
507 514
508 dbg("%s", __FUNCTION__); 515 dbg("%s", __func__);
509 516
510 /* force updates to device */ 517 /* force updates to device */
511 for (i = 0; i<sizeof(yld->master); i++) 518 for (i = 0; i<sizeof(yld->master); i++)
@@ -521,7 +528,7 @@ static int input_open(struct input_dev *dev)
521 yld->ctl_data->sum = 0x100-CMD_INIT-10; 528 yld->ctl_data->sum = 0x100-CMD_INIT-10;
522 if ((ret = usb_submit_urb(yld->urb_ctl, GFP_KERNEL)) != 0) { 529 if ((ret = usb_submit_urb(yld->urb_ctl, GFP_KERNEL)) != 0) {
523 dbg("%s - usb_submit_urb failed with result %d", 530 dbg("%s - usb_submit_urb failed with result %d",
524 __FUNCTION__, ret); 531 __func__, ret);
525 return ret; 532 return ret;
526 } 533 }
527 return 0; 534 return 0;
@@ -531,8 +538,18 @@ static void input_close(struct input_dev *dev)
531{ 538{
532 struct yealink_dev *yld = input_get_drvdata(dev); 539 struct yealink_dev *yld = input_get_drvdata(dev);
533 540
541 yld->shutdown = 1;
542 /*
543 * Make sure the flag is seen by other CPUs before we start
544 * killing URBs so new URBs won't be submitted
545 */
546 smp_wmb();
547
534 usb_kill_urb(yld->urb_ctl); 548 usb_kill_urb(yld->urb_ctl);
535 usb_kill_urb(yld->urb_irq); 549 usb_kill_urb(yld->urb_irq);
550
551 yld->shutdown = 0;
552 smp_wmb();
536} 553}
537 554
538/******************************************************************************* 555/*******************************************************************************
@@ -809,9 +826,6 @@ static int usb_cleanup(struct yealink_dev *yld, int err)
809 if (yld == NULL) 826 if (yld == NULL)
810 return err; 827 return err;
811 828
812 usb_kill_urb(yld->urb_irq); /* parameter validation in core/urb */
813 usb_kill_urb(yld->urb_ctl); /* parameter validation in core/urb */
814
815 if (yld->idev) { 829 if (yld->idev) {
816 if (err) 830 if (err)
817 input_free_device(yld->idev); 831 input_free_device(yld->idev);
diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c
index ce6fdec19e14..1f41ae94f26b 100644
--- a/drivers/input/mouse/appletouch.c
+++ b/drivers/input/mouse/appletouch.c
@@ -2,12 +2,13 @@
2 * Apple USB Touchpad (for post-February 2005 PowerBooks and MacBooks) driver 2 * Apple USB Touchpad (for post-February 2005 PowerBooks and MacBooks) driver
3 * 3 *
4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com) 4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2005 Johannes Berg (johannes@sipsolutions.net) 5 * Copyright (C) 2005-2008 Johannes Berg (johannes@sipsolutions.net)
6 * Copyright (C) 2005 Stelian Pop (stelian@popies.net) 6 * Copyright (C) 2005 Stelian Pop (stelian@popies.net)
7 * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de) 7 * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de)
8 * Copyright (C) 2005 Peter Osterlund (petero2@telia.com) 8 * Copyright (C) 2005 Peter Osterlund (petero2@telia.com)
9 * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch) 9 * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch)
10 * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch) 10 * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch)
11 * Copyright (C) 2007-2008 Sven Anders (anders@anduras.de)
11 * 12 *
12 * Thanks to Alex Harper <basilisk@foobox.net> for his inputs. 13 * Thanks to Alex Harper <basilisk@foobox.net> for his inputs.
13 * 14 *
@@ -34,77 +35,64 @@
34#include <linux/module.h> 35#include <linux/module.h>
35#include <linux/usb/input.h> 36#include <linux/usb/input.h>
36 37
37/* Apple has powerbooks which have the keyboard with different Product IDs */ 38/* Type of touchpad */
38#define APPLE_VENDOR_ID 0x05AC 39enum atp_touchpad_type {
39 40 ATP_FOUNTAIN,
40/* These names come from Info.plist in AppleUSBTrackpad.kext */ 41 ATP_GEYSER1,
41#define FOUNTAIN_ANSI_PRODUCT_ID 0x020E 42 ATP_GEYSER2,
42#define FOUNTAIN_ISO_PRODUCT_ID 0x020F 43 ATP_GEYSER3,
43 44 ATP_GEYSER4
44#define FOUNTAIN_TP_ONLY_PRODUCT_ID 0x030A 45};
45
46#define GEYSER1_TP_ONLY_PRODUCT_ID 0x030B
47
48#define GEYSER_ANSI_PRODUCT_ID 0x0214
49#define GEYSER_ISO_PRODUCT_ID 0x0215
50#define GEYSER_JIS_PRODUCT_ID 0x0216
51
52/* MacBook devices */
53#define GEYSER3_ANSI_PRODUCT_ID 0x0217
54#define GEYSER3_ISO_PRODUCT_ID 0x0218
55#define GEYSER3_JIS_PRODUCT_ID 0x0219
56
57/*
58 * Geyser IV: same as Geyser III according to Info.plist in AppleUSBTrackpad.kext
59 * -> same IOClass (AppleUSBGrIIITrackpad), same acceleration tables
60 */
61#define GEYSER4_ANSI_PRODUCT_ID 0x021A
62#define GEYSER4_ISO_PRODUCT_ID 0x021B
63#define GEYSER4_JIS_PRODUCT_ID 0x021C
64
65#define GEYSER4_HF_ANSI_PRODUCT_ID 0x0229
66#define GEYSER4_HF_ISO_PRODUCT_ID 0x022A
67#define GEYSER4_HF_JIS_PRODUCT_ID 0x022B
68 46
69#define ATP_DEVICE(prod) \ 47#define ATP_DEVICE(prod, type) \
48{ \
70 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ 49 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
71 USB_DEVICE_ID_MATCH_INT_CLASS | \ 50 USB_DEVICE_ID_MATCH_INT_CLASS | \
72 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \ 51 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
73 .idVendor = APPLE_VENDOR_ID, \ 52 .idVendor = 0x05ac, /* Apple */ \
74 .idProduct = (prod), \ 53 .idProduct = (prod), \
75 .bInterfaceClass = 0x03, \ 54 .bInterfaceClass = 0x03, \
76 .bInterfaceProtocol = 0x02 55 .bInterfaceProtocol = 0x02, \
56 .driver_info = ATP_ ## type, \
57}
58
59/*
60 * Table of devices (Product IDs) that work with this driver.
61 * (The names come from Info.plist in AppleUSBTrackpad.kext,
62 * According to Info.plist Geyser IV is the same as Geyser III.)
63 */
77 64
78/* table of devices that work with this driver */
79static struct usb_device_id atp_table [] = { 65static struct usb_device_id atp_table [] = {
80 { ATP_DEVICE(FOUNTAIN_ANSI_PRODUCT_ID) }, 66 /* PowerBooks Feb 2005, iBooks G4 */
81 { ATP_DEVICE(FOUNTAIN_ISO_PRODUCT_ID) }, 67 ATP_DEVICE(0x020e, FOUNTAIN), /* FOUNTAIN ANSI */
82 { ATP_DEVICE(FOUNTAIN_TP_ONLY_PRODUCT_ID) }, 68 ATP_DEVICE(0x020f, FOUNTAIN), /* FOUNTAIN ISO */
83 { ATP_DEVICE(GEYSER1_TP_ONLY_PRODUCT_ID) }, 69 ATP_DEVICE(0x030a, FOUNTAIN), /* FOUNTAIN TP ONLY */
70 ATP_DEVICE(0x030b, GEYSER1), /* GEYSER 1 TP ONLY */
84 71
85 /* PowerBooks Oct 2005 */ 72 /* PowerBooks Oct 2005 */
86 { ATP_DEVICE(GEYSER_ANSI_PRODUCT_ID) }, 73 ATP_DEVICE(0x0214, GEYSER2), /* GEYSER 2 ANSI */
87 { ATP_DEVICE(GEYSER_ISO_PRODUCT_ID) }, 74 ATP_DEVICE(0x0215, GEYSER2), /* GEYSER 2 ISO */
88 { ATP_DEVICE(GEYSER_JIS_PRODUCT_ID) }, 75 ATP_DEVICE(0x0216, GEYSER2), /* GEYSER 2 JIS */
89 76
90 /* Core Duo MacBook & MacBook Pro */ 77 /* Core Duo MacBook & MacBook Pro */
91 { ATP_DEVICE(GEYSER3_ANSI_PRODUCT_ID) }, 78 ATP_DEVICE(0x0217, GEYSER3), /* GEYSER 3 ANSI */
92 { ATP_DEVICE(GEYSER3_ISO_PRODUCT_ID) }, 79 ATP_DEVICE(0x0218, GEYSER3), /* GEYSER 3 ISO */
93 { ATP_DEVICE(GEYSER3_JIS_PRODUCT_ID) }, 80 ATP_DEVICE(0x0219, GEYSER3), /* GEYSER 3 JIS */
94 81
95 /* Core2 Duo MacBook & MacBook Pro */ 82 /* Core2 Duo MacBook & MacBook Pro */
96 { ATP_DEVICE(GEYSER4_ANSI_PRODUCT_ID) }, 83 ATP_DEVICE(0x021a, GEYSER4), /* GEYSER 4 ANSI */
97 { ATP_DEVICE(GEYSER4_ISO_PRODUCT_ID) }, 84 ATP_DEVICE(0x021b, GEYSER4), /* GEYSER 4 ISO */
98 { ATP_DEVICE(GEYSER4_JIS_PRODUCT_ID) }, 85 ATP_DEVICE(0x021c, GEYSER4), /* GEYSER 4 JIS */
99 86
100 { ATP_DEVICE(GEYSER4_HF_ANSI_PRODUCT_ID) }, 87 /* Core2 Duo MacBook3,1 */
101 { ATP_DEVICE(GEYSER4_HF_ISO_PRODUCT_ID) }, 88 ATP_DEVICE(0x0229, GEYSER4), /* GEYSER 4 HF ANSI */
102 { ATP_DEVICE(GEYSER4_HF_JIS_PRODUCT_ID) }, 89 ATP_DEVICE(0x022a, GEYSER4), /* GEYSER 4 HF ISO */
90 ATP_DEVICE(0x022b, GEYSER4), /* GEYSER 4 HF JIS */
103 91
104 /* Terminating entry */ 92 /* Terminating entry */
105 { } 93 { }
106}; 94};
107MODULE_DEVICE_TABLE (usb, atp_table); 95MODULE_DEVICE_TABLE(usb, atp_table);
108 96
109/* 97/*
110 * number of sensors. Note that only 16 instead of 26 X (horizontal) 98 * number of sensors. Note that only 16 instead of 26 X (horizontal)
@@ -124,9 +112,13 @@ MODULE_DEVICE_TABLE (usb, atp_table);
124 * We try to keep the touchpad aspect ratio while still doing only simple 112 * We try to keep the touchpad aspect ratio while still doing only simple
125 * arithmetics. 113 * arithmetics.
126 * The factors below give coordinates like: 114 * The factors below give coordinates like:
127 * 0 <= x < 960 on 12" and 15" Powerbooks 115 *
128 * 0 <= x < 1600 on 17" Powerbooks 116 * 0 <= x < 960 on 12" and 15" Powerbooks
129 * 0 <= y < 646 117 * 0 <= x < 1600 on 17" Powerbooks and 17" MacBook Pro
118 * 0 <= x < 1216 on MacBooks and 15" MacBook Pro
119 *
120 * 0 <= y < 646 on all Powerbooks
121 * 0 <= y < 774 on all MacBooks
130 */ 122 */
131#define ATP_XFACT 64 123#define ATP_XFACT 64
132#define ATP_YFACT 43 124#define ATP_YFACT 43
@@ -147,43 +139,46 @@ MODULE_DEVICE_TABLE (usb, atp_table);
147/* Structure to hold all of our device specific stuff */ 139/* Structure to hold all of our device specific stuff */
148struct atp { 140struct atp {
149 char phys[64]; 141 char phys[64];
150 struct usb_device * udev; /* usb device */ 142 struct usb_device *udev; /* usb device */
151 struct urb * urb; /* usb request block */ 143 struct urb *urb; /* usb request block */
152 signed char * data; /* transferred data */ 144 signed char *data; /* transferred data */
153 struct input_dev * input; /* input dev */ 145 struct input_dev *input; /* input dev */
154 unsigned char open; /* non-zero if opened */ 146 enum atp_touchpad_type type; /* type of touchpad */
155 unsigned char valid; /* are the sensors valid ? */ 147 bool open;
156 unsigned char size_detect_done; 148 bool valid; /* are the samples valid? */
157 unsigned char overflowwarn; /* overflow warning printed? */ 149 bool size_detect_done;
150 bool overflow_warned;
158 int x_old; /* last reported x/y, */ 151 int x_old; /* last reported x/y, */
159 int y_old; /* used for smoothing */ 152 int y_old; /* used for smoothing */
160 /* current value of the sensors */
161 signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS]; 153 signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS];
162 /* last value of the sensors */
163 signed char xy_old[ATP_XSENSORS + ATP_YSENSORS]; 154 signed char xy_old[ATP_XSENSORS + ATP_YSENSORS];
164 /* accumulated sensors */
165 int xy_acc[ATP_XSENSORS + ATP_YSENSORS]; 155 int xy_acc[ATP_XSENSORS + ATP_YSENSORS];
166 int datalen; /* size of an USB urb transfer */ 156 int datalen; /* size of USB transfer */
167 int idlecount; /* number of empty packets */ 157 int idlecount; /* number of empty packets */
168 struct work_struct work; 158 struct work_struct work;
169}; 159};
170 160
171#define dbg_dump(msg, tab) \ 161#define dbg_dump(msg, tab) \
172 if (debug > 1) { \ 162 if (debug > 1) { \
173 int i; \ 163 int __i; \
174 printk("appletouch: %s %lld", msg, (long long)jiffies); \ 164 printk(KERN_DEBUG "appletouch: %s", msg); \
175 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) \ 165 for (__i = 0; __i < ATP_XSENSORS + ATP_YSENSORS; __i++) \
176 printk(" %02x", tab[i]); \ 166 printk(" %02x", tab[__i]); \
177 printk("\n"); \ 167 printk("\n"); \
178 } 168 }
179 169
180#define dprintk(format, a...) \ 170#define dprintk(format, a...) \
181 do { \ 171 do { \
182 if (debug) printk(KERN_DEBUG format, ##a); \ 172 if (debug) \
173 printk(KERN_DEBUG format, ##a); \
183 } while (0) 174 } while (0)
184 175
185MODULE_AUTHOR("Johannes Berg, Stelian Pop, Frank Arnold, Michael Hanselmann"); 176MODULE_AUTHOR("Johannes Berg");
186MODULE_DESCRIPTION("Apple PowerBooks USB touchpad driver"); 177MODULE_AUTHOR("Stelian Pop");
178MODULE_AUTHOR("Frank Arnold");
179MODULE_AUTHOR("Michael Hanselmann");
180MODULE_AUTHOR("Sven Anders");
181MODULE_DESCRIPTION("Apple PowerBook and MacBook USB touchpad driver");
187MODULE_LICENSE("GPL"); 182MODULE_LICENSE("GPL");
188 183
189/* 184/*
@@ -191,46 +186,14 @@ MODULE_LICENSE("GPL");
191 */ 186 */
192static int threshold = ATP_THRESHOLD; 187static int threshold = ATP_THRESHOLD;
193module_param(threshold, int, 0644); 188module_param(threshold, int, 0644);
194MODULE_PARM_DESC(threshold, "Discards any change in data from a sensor (trackpad has hundreds of these sensors) less than this value"); 189MODULE_PARM_DESC(threshold, "Discard any change in data from a sensor"
190 " (the trackpad has many of these sensors)"
191 " less than this value.");
195 192
196static int debug = 1; 193static int debug;
197module_param(debug, int, 0644); 194module_param(debug, int, 0644);
198MODULE_PARM_DESC(debug, "Activate debugging output"); 195MODULE_PARM_DESC(debug, "Activate debugging output");
199 196
200static inline int atp_is_fountain(struct atp *dev)
201{
202 u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
203
204 return productId == FOUNTAIN_ANSI_PRODUCT_ID ||
205 productId == FOUNTAIN_ISO_PRODUCT_ID ||
206 productId == FOUNTAIN_TP_ONLY_PRODUCT_ID;
207}
208
209/* Checks if the device a Geyser 2 (ANSI, ISO, JIS) */
210static inline int atp_is_geyser_2(struct atp *dev)
211{
212 u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
213
214 return (productId == GEYSER_ANSI_PRODUCT_ID) ||
215 (productId == GEYSER_ISO_PRODUCT_ID) ||
216 (productId == GEYSER_JIS_PRODUCT_ID);
217}
218
219static inline int atp_is_geyser_3(struct atp *dev)
220{
221 u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
222
223 return (productId == GEYSER3_ANSI_PRODUCT_ID) ||
224 (productId == GEYSER3_ISO_PRODUCT_ID) ||
225 (productId == GEYSER3_JIS_PRODUCT_ID) ||
226 (productId == GEYSER4_ANSI_PRODUCT_ID) ||
227 (productId == GEYSER4_ISO_PRODUCT_ID) ||
228 (productId == GEYSER4_JIS_PRODUCT_ID) ||
229 (productId == GEYSER4_HF_ANSI_PRODUCT_ID) ||
230 (productId == GEYSER4_HF_ISO_PRODUCT_ID) ||
231 (productId == GEYSER4_HF_JIS_PRODUCT_ID);
232}
233
234/* 197/*
235 * By default newer Geyser devices send standard USB HID mouse 198 * By default newer Geyser devices send standard USB HID mouse
236 * packets (Report ID 2). This code changes device mode, so it 199 * packets (Report ID 2). This code changes device mode, so it
@@ -240,6 +203,7 @@ static int atp_geyser_init(struct usb_device *udev)
240{ 203{
241 char data[8]; 204 char data[8];
242 int size; 205 int size;
206 int i;
243 207
244 size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 208 size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
245 ATP_GEYSER_MODE_READ_REQUEST_ID, 209 ATP_GEYSER_MODE_READ_REQUEST_ID,
@@ -248,8 +212,11 @@ static int atp_geyser_init(struct usb_device *udev)
248 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000); 212 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000);
249 213
250 if (size != 8) { 214 if (size != 8) {
251 err("Could not do mode read request from device" 215 dprintk("atp_geyser_init: read error\n");
252 " (Geyser Raw mode)"); 216 for (i = 0; i < 8; i++)
217 dprintk("appletouch[%d]: %d\n", i, data[i]);
218
219 err("Failed to read mode from device.");
253 return -EIO; 220 return -EIO;
254 } 221 }
255 222
@@ -263,8 +230,11 @@ static int atp_geyser_init(struct usb_device *udev)
263 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000); 230 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000);
264 231
265 if (size != 8) { 232 if (size != 8) {
266 err("Could not do mode write request to device" 233 dprintk("atp_geyser_init: write error\n");
267 " (Geyser Raw mode)"); 234 for (i = 0; i < 8; i++)
235 dprintk("appletouch[%d]: %d\n", i, data[i]);
236
237 err("Failed to request geyser raw mode");
268 return -EIO; 238 return -EIO;
269 } 239 }
270 return 0; 240 return 0;
@@ -280,15 +250,15 @@ static void atp_reinit(struct work_struct *work)
280 struct usb_device *udev = dev->udev; 250 struct usb_device *udev = dev->udev;
281 int retval; 251 int retval;
282 252
253 dprintk("appletouch: putting appletouch to sleep (reinit)\n");
283 dev->idlecount = 0; 254 dev->idlecount = 0;
284 255
285 atp_geyser_init(udev); 256 atp_geyser_init(udev);
286 257
287 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); 258 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
288 if (retval) { 259 if (retval)
289 err("%s - usb_submit_urb failed with result %d", 260 err("atp_reinit: usb_submit_urb failed with error %d",
290 __FUNCTION__, retval); 261 retval);
291 }
292} 262}
293 263
294static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact, 264static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
@@ -323,7 +293,8 @@ static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
323 * 293 *
324 * - Jason Parekh <jasonparekh@gmail.com> 294 * - Jason Parekh <jasonparekh@gmail.com>
325 */ 295 */
326 if (i < 1 || (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) { 296 if (i < 1 ||
297 (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) {
327 (*fingers)++; 298 (*fingers)++;
328 is_increasing = 1; 299 is_increasing = 1;
329 } else if (i > 0 && xy_sensors[i - 1] >= xy_sensors[i]) { 300 } else if (i > 0 && xy_sensors[i - 1] >= xy_sensors[i]) {
@@ -331,11 +302,11 @@ static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
331 } 302 }
332 303
333 /* 304 /*
334 * Subtracts threshold so a high sensor that just passes the threshold 305 * Subtracts threshold so a high sensor that just passes the
335 * won't skew the calculated absolute coordinate. Fixes an issue 306 * threshold won't skew the calculated absolute coordinate.
336 * where slowly moving the mouse would occassionaly jump a number of 307 * Fixes an issue where slowly moving the mouse would
337 * pixels (let me restate--slowly moving the mouse makes this issue 308 * occasionally jump a number of pixels (slowly moving the
338 * most apparent). 309 * finger makes this issue most apparent.)
339 */ 310 */
340 pcum += (xy_sensors[i] - threshold) * i; 311 pcum += (xy_sensors[i] - threshold) * i;
341 psum += (xy_sensors[i] - threshold); 312 psum += (xy_sensors[i] - threshold);
@@ -356,7 +327,7 @@ static inline void atp_report_fingers(struct input_dev *input, int fingers)
356 input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2); 327 input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2);
357} 328}
358 329
359static void atp_complete(struct urb* urb) 330static void atp_complete(struct urb *urb)
360{ 331{
361 int x, y, x_z, y_z, x_f, y_f; 332 int x, y, x_z, y_z, x_f, y_f;
362 int retval, i, j; 333 int retval, i, j;
@@ -368,22 +339,22 @@ static void atp_complete(struct urb* urb)
368 /* success */ 339 /* success */
369 break; 340 break;
370 case -EOVERFLOW: 341 case -EOVERFLOW:
371 if(!dev->overflowwarn) { 342 if (!dev->overflow_warned) {
372 printk(KERN_WARNING "appletouch: OVERFLOW with data " 343 printk(KERN_WARNING "appletouch: OVERFLOW with data "
373 "length %d, actual length is %d\n", 344 "length %d, actual length is %d\n",
374 dev->datalen, dev->urb->actual_length); 345 dev->datalen, dev->urb->actual_length);
375 dev->overflowwarn = 1; 346 dev->overflow_warned = true;
376 } 347 }
377 case -ECONNRESET: 348 case -ECONNRESET:
378 case -ENOENT: 349 case -ENOENT:
379 case -ESHUTDOWN: 350 case -ESHUTDOWN:
380 /* This urb is terminated, clean up */ 351 /* This urb is terminated, clean up */
381 dbg("%s - urb shutting down with status: %d", 352 dbg("atp_complete: urb shutting down with status: %d",
382 __FUNCTION__, urb->status); 353 urb->status);
383 return; 354 return;
384 default: 355 default:
385 dbg("%s - nonzero urb status received: %d", 356 dbg("atp_complete: nonzero urb status received: %d",
386 __FUNCTION__, urb->status); 357 urb->status);
387 goto exit; 358 goto exit;
388 } 359 }
389 360
@@ -396,7 +367,7 @@ static void atp_complete(struct urb* urb)
396 } 367 }
397 368
398 /* reorder the sensors values */ 369 /* reorder the sensors values */
399 if (atp_is_geyser_3(dev)) { 370 if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) {
400 memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); 371 memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
401 372
402 /* 373 /*
@@ -415,7 +386,7 @@ static void atp_complete(struct urb* urb)
415 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1]; 386 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1];
416 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2]; 387 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2];
417 } 388 }
418 } else if (atp_is_geyser_2(dev)) { 389 } else if (dev->type == ATP_GEYSER2) {
419 memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); 390 memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
420 391
421 /* 392 /*
@@ -438,7 +409,7 @@ static void atp_complete(struct urb* urb)
438 } else { 409 } else {
439 for (i = 0; i < 8; i++) { 410 for (i = 0; i < 8; i++) {
440 /* X values */ 411 /* X values */
441 dev->xy_cur[i ] = dev->data[5 * i + 2]; 412 dev->xy_cur[i + 0] = dev->data[5 * i + 2];
442 dev->xy_cur[i + 8] = dev->data[5 * i + 4]; 413 dev->xy_cur[i + 8] = dev->data[5 * i + 4];
443 dev->xy_cur[i + 16] = dev->data[5 * i + 42]; 414 dev->xy_cur[i + 16] = dev->data[5 * i + 42];
444 if (i < 2) 415 if (i < 2)
@@ -454,21 +425,22 @@ static void atp_complete(struct urb* urb)
454 425
455 if (!dev->valid) { 426 if (!dev->valid) {
456 /* first sample */ 427 /* first sample */
457 dev->valid = 1; 428 dev->valid = true;
458 dev->x_old = dev->y_old = -1; 429 dev->x_old = dev->y_old = -1;
459 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); 430 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
460 431
461 if (dev->size_detect_done || 432 if (dev->size_detect_done ||
462 atp_is_geyser_3(dev)) /* No 17" Macbooks (yet) */ 433 dev->type == ATP_GEYSER3) /* No 17" Macbooks (yet) */
463 goto exit; 434 goto exit;
464 435
465 /* 17" Powerbooks have extra X sensors */ 436 /* 17" Powerbooks have extra X sensors */
466 for (i = (atp_is_geyser_2(dev) ? 15 : 16); i < ATP_XSENSORS; i++) { 437 for (i = (dev->type == ATP_GEYSER2 ? 15 : 16);
438 i < ATP_XSENSORS; i++) {
467 if (!dev->xy_cur[i]) 439 if (!dev->xy_cur[i])
468 continue; 440 continue;
469 441
470 printk(KERN_INFO "appletouch: 17\" model detected.\n"); 442 printk(KERN_INFO "appletouch: 17\" model detected.\n");
471 if (atp_is_geyser_2(dev)) 443 if (dev->type == ATP_GEYSER2)
472 input_set_abs_params(dev->input, ABS_X, 0, 444 input_set_abs_params(dev->input, ABS_X, 0,
473 (20 - 1) * 445 (20 - 1) *
474 ATP_XFACT - 1, 446 ATP_XFACT - 1,
@@ -548,11 +520,15 @@ static void atp_complete(struct urb* urb)
548 * several hundred times a second. Re-initialization does not 520 * several hundred times a second. Re-initialization does not
549 * work on Fountain touchpads. 521 * work on Fountain touchpads.
550 */ 522 */
551 if (!atp_is_fountain(dev)) { 523 if (dev->type != ATP_FOUNTAIN) {
524 /*
525 * Button must not be pressed when entering suspend,
526 * otherwise we will never release the button.
527 */
552 if (!x && !y && !key) { 528 if (!x && !y && !key) {
553 dev->idlecount++; 529 dev->idlecount++;
554 if (dev->idlecount == 10) { 530 if (dev->idlecount == 10) {
555 dev->valid = 0; 531 dev->valid = false;
556 schedule_work(&dev->work); 532 schedule_work(&dev->work);
557 /* Don't resubmit urb here, wait for reinit */ 533 /* Don't resubmit urb here, wait for reinit */
558 return; 534 return;
@@ -561,12 +537,11 @@ static void atp_complete(struct urb* urb)
561 dev->idlecount = 0; 537 dev->idlecount = 0;
562 } 538 }
563 539
564exit: 540 exit:
565 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); 541 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
566 if (retval) { 542 if (retval)
567 err("%s - usb_submit_urb failed with result %d", 543 err("atp_complete: usb_submit_urb failed with result %d",
568 __FUNCTION__, retval); 544 retval);
569 }
570} 545}
571 546
572static int atp_open(struct input_dev *input) 547static int atp_open(struct input_dev *input)
@@ -593,7 +568,7 @@ static int atp_handle_geyser(struct atp *dev)
593{ 568{
594 struct usb_device *udev = dev->udev; 569 struct usb_device *udev = dev->udev;
595 570
596 if (!atp_is_fountain(dev)) { 571 if (dev->type != ATP_FOUNTAIN) {
597 /* switch to raw sensor mode */ 572 /* switch to raw sensor mode */
598 if (atp_geyser_init(udev)) 573 if (atp_geyser_init(udev))
599 return -EIO; 574 return -EIO;
@@ -604,7 +579,8 @@ static int atp_handle_geyser(struct atp *dev)
604 return 0; 579 return 0;
605} 580}
606 581
607static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id) 582static int atp_probe(struct usb_interface *iface,
583 const struct usb_device_id *id)
608{ 584{
609 struct atp *dev; 585 struct atp *dev;
610 struct input_dev *input_dev; 586 struct input_dev *input_dev;
@@ -640,13 +616,12 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
640 616
641 dev->udev = udev; 617 dev->udev = udev;
642 dev->input = input_dev; 618 dev->input = input_dev;
643 dev->overflowwarn = 0; 619 dev->type = id->driver_info;
644 if (atp_is_geyser_3(dev)) 620 dev->overflow_warned = false;
645 dev->datalen = 64; 621 if (dev->type == ATP_FOUNTAIN || dev->type == ATP_GEYSER1)
646 else if (atp_is_geyser_2(dev))
647 dev->datalen = 64;
648 else
649 dev->datalen = 81; 622 dev->datalen = 81;
623 else
624 dev->datalen = 64;
650 625
651 dev->urb = usb_alloc_urb(0, GFP_KERNEL); 626 dev->urb = usb_alloc_urb(0, GFP_KERNEL);
652 if (!dev->urb) 627 if (!dev->urb)
@@ -680,7 +655,7 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
680 655
681 set_bit(EV_ABS, input_dev->evbit); 656 set_bit(EV_ABS, input_dev->evbit);
682 657
683 if (atp_is_geyser_3(dev)) { 658 if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) {
684 /* 659 /*
685 * MacBook have 20 X sensors, 10 Y sensors 660 * MacBook have 20 X sensors, 10 Y sensors
686 */ 661 */
@@ -688,7 +663,7 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
688 ((20 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0); 663 ((20 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0);
689 input_set_abs_params(input_dev, ABS_Y, 0, 664 input_set_abs_params(input_dev, ABS_Y, 0,
690 ((10 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0); 665 ((10 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0);
691 } else if (atp_is_geyser_2(dev)) { 666 } else if (dev->type == ATP_GEYSER2) {
692 /* 667 /*
693 * Oct 2005 15" PowerBooks have 15 X sensors, 17" are detected 668 * Oct 2005 15" PowerBooks have 15 X sensors, 17" are detected
694 * later. 669 * later.
@@ -703,9 +678,11 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
703 * 17" models are detected later. 678 * 17" models are detected later.
704 */ 679 */
705 input_set_abs_params(input_dev, ABS_X, 0, 680 input_set_abs_params(input_dev, ABS_X, 0,
706 (16 - 1) * ATP_XFACT - 1, ATP_FUZZ, 0); 681 (16 - 1) * ATP_XFACT - 1,
682 ATP_FUZZ, 0);
707 input_set_abs_params(input_dev, ABS_Y, 0, 683 input_set_abs_params(input_dev, ABS_Y, 0,
708 (ATP_YSENSORS - 1) * ATP_YFACT - 1, ATP_FUZZ, 0); 684 (ATP_YSENSORS - 1) * ATP_YFACT - 1,
685 ATP_FUZZ, 0);
709 } 686 }
710 input_set_abs_params(input_dev, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0); 687 input_set_abs_params(input_dev, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0);
711 688
@@ -774,7 +751,7 @@ static int atp_suspend(struct usb_interface *iface, pm_message_t message)
774 struct atp *dev = usb_get_intfdata(iface); 751 struct atp *dev = usb_get_intfdata(iface);
775 752
776 usb_kill_urb(dev->urb); 753 usb_kill_urb(dev->urb);
777 dev->valid = 0; 754 dev->valid = false;
778 755
779 return 0; 756 return 0;
780} 757}
diff --git a/drivers/input/mouse/atarimouse.c b/drivers/input/mouse/atarimouse.c
index 98a3561d4b05..adf45b3040e9 100644
--- a/drivers/input/mouse/atarimouse.c
+++ b/drivers/input/mouse/atarimouse.c
@@ -57,15 +57,12 @@ MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
57MODULE_DESCRIPTION("Atari mouse driver"); 57MODULE_DESCRIPTION("Atari mouse driver");
58MODULE_LICENSE("GPL"); 58MODULE_LICENSE("GPL");
59 59
60static int mouse_threshold[2] = {2,2}; 60static int mouse_threshold[2] = {2, 2};
61module_param_array(mouse_threshold, int, NULL, 0);
61 62
62#ifdef __MODULE__
63MODULE_PARM(mouse_threshold, "2i");
64#endif
65#ifdef FIXED_ATARI_JOYSTICK 63#ifdef FIXED_ATARI_JOYSTICK
66extern int atari_mouse_buttons; 64extern int atari_mouse_buttons;
67#endif 65#endif
68static int atamouse_used = 0;
69 66
70static struct input_dev *atamouse_dev; 67static struct input_dev *atamouse_dev;
71 68
@@ -97,9 +94,6 @@ static void atamouse_interrupt(char *buf)
97 94
98static int atamouse_open(struct input_dev *dev) 95static int atamouse_open(struct input_dev *dev)
99{ 96{
100 if (atamouse_used++)
101 return 0;
102
103#ifdef FIXED_ATARI_JOYSTICK 97#ifdef FIXED_ATARI_JOYSTICK
104 atari_mouse_buttons = 0; 98 atari_mouse_buttons = 0;
105#endif 99#endif
@@ -107,23 +101,24 @@ static int atamouse_open(struct input_dev *dev)
107 ikbd_mouse_thresh(mouse_threshold[0], mouse_threshold[1]); 101 ikbd_mouse_thresh(mouse_threshold[0], mouse_threshold[1]);
108 ikbd_mouse_rel_pos(); 102 ikbd_mouse_rel_pos();
109 atari_input_mouse_interrupt_hook = atamouse_interrupt; 103 atari_input_mouse_interrupt_hook = atamouse_interrupt;
104
110 return 0; 105 return 0;
111} 106}
112 107
113static void atamouse_close(struct input_dev *dev) 108static void atamouse_close(struct input_dev *dev)
114{ 109{
115 if (!--atamouse_used) { 110 ikbd_mouse_disable();
116 ikbd_mouse_disable(); 111 atari_mouse_interrupt_hook = NULL;
117 atari_mouse_interrupt_hook = NULL;
118 }
119} 112}
120 113
121static int __init atamouse_init(void) 114static int __init atamouse_init(void)
122{ 115{
116 int error;
117
123 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP)) 118 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
124 return -ENODEV; 119 return -ENODEV;
125 120
126 if (!(atari_keyb_init())) 121 if (!atari_keyb_init())
127 return -ENODEV; 122 return -ENODEV;
128 123
129 atamouse_dev = input_allocate_device(); 124 atamouse_dev = input_allocate_device();
@@ -141,12 +136,14 @@ static int __init atamouse_init(void)
141 atamouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); 136 atamouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
142 atamouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | 137 atamouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
143 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); 138 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
139
144 atamouse_dev->open = atamouse_open; 140 atamouse_dev->open = atamouse_open;
145 atamouse_dev->close = atamouse_close; 141 atamouse_dev->close = atamouse_close;
146 142
147 if (input_register_device(atamouse_dev)) { 143 error = input_register_device(atamouse_dev);
144 if (error) {
148 input_free_device(atamouse_dev); 145 input_free_device(atamouse_dev);
149 return -ENOMEM; 146 return error;
150 } 147 }
151 148
152 return 0; 149 return 0;
diff --git a/drivers/input/mouse/hil_ptr.c b/drivers/input/mouse/hil_ptr.c
index 27f88fbb7136..e532c48410ea 100644
--- a/drivers/input/mouse/hil_ptr.c
+++ b/drivers/input/mouse/hil_ptr.c
@@ -247,19 +247,24 @@ static void hil_ptr_disconnect(struct serio *serio)
247 247
248static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver) 248static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
249{ 249{
250 struct hil_ptr *ptr; 250 struct hil_ptr *ptr;
251 const char *txt; 251 const char *txt;
252 unsigned int i, naxsets, btntype; 252 unsigned int i, naxsets, btntype;
253 uint8_t did, *idd; 253 uint8_t did, *idd;
254 254 int error;
255 if (!(ptr = kzalloc(sizeof(struct hil_ptr), GFP_KERNEL))) 255
256 ptr = kzalloc(sizeof(struct hil_ptr), GFP_KERNEL);
257 if (!ptr)
256 return -ENOMEM; 258 return -ENOMEM;
257 259
258 ptr->dev = input_allocate_device(); 260 ptr->dev = input_allocate_device();
259 if (!ptr->dev) 261 if (!ptr->dev) {
262 error = -ENOMEM;
260 goto bail0; 263 goto bail0;
264 }
261 265
262 if (serio_open(serio, driver)) 266 error = serio_open(serio, driver);
267 if (error)
263 goto bail1; 268 goto bail1;
264 269
265 serio_set_drvdata(serio, ptr); 270 serio_set_drvdata(serio, ptr);
@@ -297,6 +302,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
297 did = ptr->idd[0]; 302 did = ptr->idd[0];
298 idd = ptr->idd + 1; 303 idd = ptr->idd + 1;
299 txt = "unknown"; 304 txt = "unknown";
305
300 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) { 306 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
301 ptr->dev->evbit[0] = BIT_MASK(EV_REL); 307 ptr->dev->evbit[0] = BIT_MASK(EV_REL);
302 txt = "relative"; 308 txt = "relative";
@@ -306,8 +312,11 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
306 ptr->dev->evbit[0] = BIT_MASK(EV_ABS); 312 ptr->dev->evbit[0] = BIT_MASK(EV_ABS);
307 txt = "absolute"; 313 txt = "absolute";
308 } 314 }
309 if (!ptr->dev->evbit[0]) 315
316 if (!ptr->dev->evbit[0]) {
317 error = -ENODEV;
310 goto bail2; 318 goto bail2;
319 }
311 320
312 ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd); 321 ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd);
313 if (ptr->nbtn) 322 if (ptr->nbtn)
@@ -380,13 +389,19 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
380 ptr->dev->id.version = 0x0100; /* TODO: get from ptr->rsc */ 389 ptr->dev->id.version = 0x0100; /* TODO: get from ptr->rsc */
381 ptr->dev->dev.parent = &serio->dev; 390 ptr->dev->dev.parent = &serio->dev;
382 391
383 input_register_device(ptr->dev); 392 error = input_register_device(ptr->dev);
393 if (error) {
394 printk(KERN_INFO PREFIX "Unable to register input device\n");
395 goto bail2;
396 }
397
384 printk(KERN_INFO "input: %s (%s), ID: %d\n", 398 printk(KERN_INFO "input: %s (%s), ID: %d\n",
385 ptr->dev->name, 399 ptr->dev->name,
386 (btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad", 400 (btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad",
387 did); 401 did);
388 402
389 return 0; 403 return 0;
404
390 bail2: 405 bail2:
391 serio_close(serio); 406 serio_close(serio);
392 bail1: 407 bail1:
@@ -394,7 +409,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
394 bail0: 409 bail0:
395 kfree(ptr); 410 kfree(ptr);
396 serio_set_drvdata(serio, NULL); 411 serio_set_drvdata(serio, NULL);
397 return -ENODEV; 412 return error;
398} 413}
399 414
400static struct serio_device_id hil_ptr_ids[] = { 415static struct serio_device_id hil_ptr_ids[] = {
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
index 06c35fc553c0..3827a22362de 100644
--- a/drivers/input/mouse/inport.c
+++ b/drivers/input/mouse/inport.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: inport.c,v 1.11 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
diff --git a/drivers/input/mouse/logibm.c b/drivers/input/mouse/logibm.c
index 9ea895593b27..e2413113df22 100644
--- a/drivers/input/mouse/logibm.c
+++ b/drivers/input/mouse/logibm.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: logibm.c,v 1.11 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
index 61cff8374e6c..fd09c8df81f2 100644
--- a/drivers/input/mouse/pc110pad.c
+++ b/drivers/input/mouse/pc110pad.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: pc110pad.c,v 1.12 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik 2 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
diff --git a/drivers/input/mouse/sermouse.c b/drivers/input/mouse/sermouse.c
index ed917bfd086a..17ff137b9bd5 100644
--- a/drivers/input/mouse/sermouse.c
+++ b/drivers/input/mouse/sermouse.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: sermouse.c,v 1.17 2002/03/13 10:03:43 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index ec4b6610f730..27d70d326ff3 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -190,4 +190,14 @@ config SERIO_RAW
190 To compile this driver as a module, choose M here: the 190 To compile this driver as a module, choose M here: the
191 module will be called serio_raw. 191 module will be called serio_raw.
192 192
193config SERIO_XILINX_XPS_PS2
194 tristate "Xilinx XPS PS/2 Controller Support"
195 depends on PPC
196 help
197 This driver supports XPS PS/2 IP from the Xilinx EDK on
198 PowerPC platform.
199
200 To compile this driver as a module, choose M here: the
201 module will be called xilinx_ps2.
202
193endif 203endif
diff --git a/drivers/input/serio/Makefile b/drivers/input/serio/Makefile
index 38b886887cbc..9b6c8135955f 100644
--- a/drivers/input/serio/Makefile
+++ b/drivers/input/serio/Makefile
@@ -21,3 +21,4 @@ obj-$(CONFIG_SERIO_PCIPS2) += pcips2.o
21obj-$(CONFIG_SERIO_MACEPS2) += maceps2.o 21obj-$(CONFIG_SERIO_MACEPS2) += maceps2.o
22obj-$(CONFIG_SERIO_LIBPS2) += libps2.o 22obj-$(CONFIG_SERIO_LIBPS2) += libps2.o
23obj-$(CONFIG_SERIO_RAW) += serio_raw.o 23obj-$(CONFIG_SERIO_RAW) += serio_raw.o
24obj-$(CONFIG_SERIO_XILINX_XPS_PS2) += xilinx_ps2.o
diff --git a/drivers/input/serio/ct82c710.c b/drivers/input/serio/ct82c710.c
index 0d35018c23a9..d1380fc72cc6 100644
--- a/drivers/input/serio/ct82c710.c
+++ b/drivers/input/serio/ct82c710.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: ct82c710.c,v 1.11 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik 2 * Copyright (c) 1999-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/serio/hil_mlc.c b/drivers/input/serio/hil_mlc.c
index 93a1a6ba216a..37586a68d345 100644
--- a/drivers/input/serio/hil_mlc.c
+++ b/drivers/input/serio/hil_mlc.c
@@ -76,7 +76,7 @@ static struct timer_list hil_mlcs_kicker;
76static int hil_mlcs_probe; 76static int hil_mlcs_probe;
77 77
78static void hil_mlcs_process(unsigned long unused); 78static void hil_mlcs_process(unsigned long unused);
79DECLARE_TASKLET_DISABLED(hil_mlcs_tasklet, hil_mlcs_process, 0); 79static DECLARE_TASKLET_DISABLED(hil_mlcs_tasklet, hil_mlcs_process, 0);
80 80
81 81
82/* #define HIL_MLC_DEBUG */ 82/* #define HIL_MLC_DEBUG */
@@ -459,7 +459,7 @@ static int hilse_operate(hil_mlc *mlc, int repoll)
459#define OUT_LAST(pack) \ 459#define OUT_LAST(pack) \
460{ HILSE_OUT_LAST, { .packet = pack }, 0, 0, 0, 0 }, 460{ HILSE_OUT_LAST, { .packet = pack }, 0, 0, 0, 0 },
461 461
462const struct hilse_node hil_mlc_se[HILSEN_END] = { 462static const struct hilse_node hil_mlc_se[HILSEN_END] = {
463 463
464 /* 0 HILSEN_START */ 464 /* 0 HILSEN_START */
465 FUNC(hilse_init_lcv, 0, HILSEN_NEXT, HILSEN_SLEEP, 0) 465 FUNC(hilse_init_lcv, 0, HILSEN_NEXT, HILSEN_SLEEP, 0)
@@ -784,7 +784,7 @@ static void hil_mlcs_process(unsigned long unused)
784 784
785/************************* Keepalive timer task *********************/ 785/************************* Keepalive timer task *********************/
786 786
787void hil_mlcs_timer(unsigned long data) 787static void hil_mlcs_timer(unsigned long data)
788{ 788{
789 hil_mlcs_probe = 1; 789 hil_mlcs_probe = 1;
790 tasklet_schedule(&hil_mlcs_tasklet); 790 tasklet_schedule(&hil_mlcs_tasklet);
diff --git a/drivers/input/serio/hp_sdc.c b/drivers/input/serio/hp_sdc.c
index edfedd9a166c..7b233a492ad5 100644
--- a/drivers/input/serio/hp_sdc.c
+++ b/drivers/input/serio/hp_sdc.c
@@ -105,6 +105,10 @@ EXPORT_SYMBOL(__hp_sdc_enqueue_transaction);
105EXPORT_SYMBOL(hp_sdc_enqueue_transaction); 105EXPORT_SYMBOL(hp_sdc_enqueue_transaction);
106EXPORT_SYMBOL(hp_sdc_dequeue_transaction); 106EXPORT_SYMBOL(hp_sdc_dequeue_transaction);
107 107
108static unsigned int hp_sdc_disabled;
109module_param_named(no_hpsdc, hp_sdc_disabled, bool, 0);
110MODULE_PARM_DESC(no_hpsdc, "Do not enable HP SDC driver.");
111
108static hp_i8042_sdc hp_sdc; /* All driver state is kept in here. */ 112static hp_i8042_sdc hp_sdc; /* All driver state is kept in here. */
109 113
110/*************** primitives for use in any context *********************/ 114/*************** primitives for use in any context *********************/
@@ -980,6 +984,11 @@ static int __init hp_sdc_register(void)
980 unsigned char i; 984 unsigned char i;
981#endif 985#endif
982 986
987 if (hp_sdc_disabled) {
988 printk(KERN_WARNING PREFIX "HP SDC driver disabled by no_hpsdc=1.\n");
989 return -ENODEV;
990 }
991
983 hp_sdc.dev = NULL; 992 hp_sdc.dev = NULL;
984 hp_sdc.dev_err = 0; 993 hp_sdc.dev_err = 0;
985#if defined(__hppa__) 994#if defined(__hppa__)
diff --git a/drivers/input/serio/hp_sdc_mlc.c b/drivers/input/serio/hp_sdc_mlc.c
index 587398f5c9df..b587e2d576ac 100644
--- a/drivers/input/serio/hp_sdc_mlc.c
+++ b/drivers/input/serio/hp_sdc_mlc.c
@@ -50,7 +50,7 @@ MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
50MODULE_DESCRIPTION("Glue for onboard HIL MLC in HP-PARISC machines"); 50MODULE_DESCRIPTION("Glue for onboard HIL MLC in HP-PARISC machines");
51MODULE_LICENSE("Dual BSD/GPL"); 51MODULE_LICENSE("Dual BSD/GPL");
52 52
53struct hp_sdc_mlc_priv_s { 53static struct hp_sdc_mlc_priv_s {
54 int emtestmode; 54 int emtestmode;
55 hp_sdc_transaction trans; 55 hp_sdc_transaction trans;
56 u8 tseq[16]; 56 u8 tseq[16];
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 78eb7841174c..fe732a574ec2 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -63,13 +63,22 @@ static inline void i8042_write_command(int val)
63 outb(val, I8042_COMMAND_REG); 63 outb(val, I8042_COMMAND_REG);
64} 64}
65 65
66#if defined(__i386__) || defined(__x86_64__) 66#ifdef CONFIG_X86
67 67
68#include <linux/dmi.h> 68#include <linux/dmi.h>
69 69
70static struct dmi_system_id __initdata i8042_dmi_noloop_table[] = { 70static struct dmi_system_id __initdata i8042_dmi_noloop_table[] = {
71 { 71 {
72 /* AUX LOOP command does not raise AUX IRQ */ 72 /* AUX LOOP command does not raise AUX IRQ */
73 .ident = "Arima-Rioworks HDAMB",
74 .matches = {
75 DMI_MATCH(DMI_BOARD_VENDOR, "RIOWORKS"),
76 DMI_MATCH(DMI_BOARD_NAME, "HDAMB"),
77 DMI_MATCH(DMI_BOARD_VERSION, "Rev E"),
78 },
79 },
80 {
81 /* AUX LOOP command does not raise AUX IRQ */
73 .ident = "ASUS P65UP5", 82 .ident = "ASUS P65UP5",
74 .matches = { 83 .matches = {
75 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), 84 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
@@ -118,6 +127,14 @@ static struct dmi_system_id __initdata i8042_dmi_noloop_table[] = {
118 DMI_MATCH(DMI_PRODUCT_VERSION, "VS2005R2"), 127 DMI_MATCH(DMI_PRODUCT_VERSION, "VS2005R2"),
119 }, 128 },
120 }, 129 },
130 {
131 .ident = "Medion MAM 2070",
132 .matches = {
133 DMI_MATCH(DMI_SYS_VENDOR, "Notebook"),
134 DMI_MATCH(DMI_PRODUCT_NAME, "MAM 2070"),
135 DMI_MATCH(DMI_PRODUCT_VERSION, "5a"),
136 },
137 },
121 { } 138 { }
122}; 139};
123 140
@@ -291,17 +308,36 @@ static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = {
291 DMI_MATCH(DMI_PRODUCT_VERSION, "3000 N100"), 308 DMI_MATCH(DMI_PRODUCT_VERSION, "3000 N100"),
292 }, 309 },
293 }, 310 },
311 {
312 .ident = "Acer Aspire 1360",
313 .matches = {
314 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
315 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
316 },
317 },
318 {
319 .ident = "Gericom Bellagio",
320 .matches = {
321 DMI_MATCH(DMI_SYS_VENDOR, "Gericom"),
322 DMI_MATCH(DMI_PRODUCT_NAME, "N34AS6"),
323 },
324 },
294 { } 325 { }
295}; 326};
296 327
297 328#ifdef CONFIG_PNP
298 329static struct dmi_system_id __initdata i8042_dmi_nopnp_table[] = {
330 {
331 .ident = "Intel MBO Desktop D845PESV",
332 .matches = {
333 DMI_MATCH(DMI_BOARD_NAME, "D845PESV"),
334 DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"),
335 },
336 },
337 { }
338};
299#endif 339#endif
300 340
301#ifdef CONFIG_X86
302
303#include <linux/dmi.h>
304
305/* 341/*
306 * Some Wistron based laptops need us to explicitly enable the 'Dritek 342 * Some Wistron based laptops need us to explicitly enable the 'Dritek
307 * keyboard extension' to make their extra keys start generating scancodes. 343 * keyboard extension' to make their extra keys start generating scancodes.
@@ -331,6 +367,13 @@ static struct dmi_system_id __initdata i8042_dmi_dritek_table[] = {
331 }, 367 },
332 }, 368 },
333 { 369 {
370 .ident = "Acer Aspire 5720",
371 .matches = {
372 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
373 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5720"),
374 },
375 },
376 {
334 .ident = "Acer Aspire 9110", 377 .ident = "Acer Aspire 9110",
335 .matches = { 378 .matches = {
336 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 379 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
@@ -356,7 +399,6 @@ static struct dmi_system_id __initdata i8042_dmi_dritek_table[] = {
356 399
357#endif /* CONFIG_X86 */ 400#endif /* CONFIG_X86 */
358 401
359
360#ifdef CONFIG_PNP 402#ifdef CONFIG_PNP
361#include <linux/pnp.h> 403#include <linux/pnp.h>
362 404
@@ -466,6 +508,11 @@ static int __init i8042_pnp_init(void)
466 int pnp_data_busted = 0; 508 int pnp_data_busted = 0;
467 int err; 509 int err;
468 510
511#ifdef CONFIG_X86
512 if (dmi_check_system(i8042_dmi_nopnp_table))
513 i8042_nopnp = 1;
514#endif
515
469 if (i8042_nopnp) { 516 if (i8042_nopnp) {
470 printk(KERN_INFO "i8042: PNP detection disabled\n"); 517 printk(KERN_INFO "i8042: PNP detection disabled\n");
471 return 0; 518 return 0;
@@ -591,15 +638,13 @@ static int __init i8042_platform_init(void)
591 i8042_reset = 1; 638 i8042_reset = 1;
592#endif 639#endif
593 640
594#if defined(__i386__) || defined(__x86_64__) 641#ifdef CONFIG_X86
595 if (dmi_check_system(i8042_dmi_noloop_table)) 642 if (dmi_check_system(i8042_dmi_noloop_table))
596 i8042_noloop = 1; 643 i8042_noloop = 1;
597 644
598 if (dmi_check_system(i8042_dmi_nomux_table)) 645 if (dmi_check_system(i8042_dmi_nomux_table))
599 i8042_nomux = 1; 646 i8042_nomux = 1;
600#endif
601 647
602#ifdef CONFIG_X86
603 if (dmi_check_system(i8042_dmi_dritek_table)) 648 if (dmi_check_system(i8042_dmi_dritek_table))
604 i8042_dritek = 1; 649 i8042_dritek = 1;
605#endif /* CONFIG_X86 */ 650#endif /* CONFIG_X86 */
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c
index b819239d74dc..2b304c22c200 100644
--- a/drivers/input/serio/libps2.c
+++ b/drivers/input/serio/libps2.c
@@ -26,15 +26,6 @@ MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>");
26MODULE_DESCRIPTION("PS/2 driver library"); 26MODULE_DESCRIPTION("PS/2 driver library");
27MODULE_LICENSE("GPL"); 27MODULE_LICENSE("GPL");
28 28
29/* Work structure to schedule execution of a command */
30struct ps2work {
31 struct work_struct work;
32 struct ps2dev *ps2dev;
33 int command;
34 unsigned char param[0];
35};
36
37
38/* 29/*
39 * ps2_sendbyte() sends a byte to the device and waits for acknowledge. 30 * ps2_sendbyte() sends a byte to the device and waits for acknowledge.
40 * It doesn't handle retransmission, though it could - because if there 31 * It doesn't handle retransmission, though it could - because if there
@@ -246,49 +237,6 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
246EXPORT_SYMBOL(ps2_command); 237EXPORT_SYMBOL(ps2_command);
247 238
248/* 239/*
249 * ps2_execute_scheduled_command() sends a command, previously scheduled by
250 * ps2_schedule_command(), to a PS/2 device (keyboard, mouse, etc.)
251 */
252
253static void ps2_execute_scheduled_command(struct work_struct *work)
254{
255 struct ps2work *ps2work = container_of(work, struct ps2work, work);
256
257 ps2_command(ps2work->ps2dev, ps2work->param, ps2work->command);
258 kfree(ps2work);
259}
260
261/*
262 * ps2_schedule_command() allows to schedule delayed execution of a PS/2
263 * command and can be used to issue a command from an interrupt or softirq
264 * context.
265 */
266
267int ps2_schedule_command(struct ps2dev *ps2dev, unsigned char *param, int command)
268{
269 struct ps2work *ps2work;
270 int send = (command >> 12) & 0xf;
271 int receive = (command >> 8) & 0xf;
272
273 if (!(ps2work = kmalloc(sizeof(struct ps2work) + max(send, receive), GFP_ATOMIC)))
274 return -1;
275
276 memset(ps2work, 0, sizeof(struct ps2work));
277 ps2work->ps2dev = ps2dev;
278 ps2work->command = command;
279 memcpy(ps2work->param, param, send);
280 INIT_WORK(&ps2work->work, ps2_execute_scheduled_command);
281
282 if (!schedule_work(&ps2work->work)) {
283 kfree(ps2work);
284 return -1;
285 }
286
287 return 0;
288}
289EXPORT_SYMBOL(ps2_schedule_command);
290
291/*
292 * ps2_init() initializes ps2dev structure 240 * ps2_init() initializes ps2dev structure
293 */ 241 */
294 242
diff --git a/drivers/input/serio/q40kbd.c b/drivers/input/serio/q40kbd.c
index d962a8d78b14..e36a0901646c 100644
--- a/drivers/input/serio/q40kbd.c
+++ b/drivers/input/serio/q40kbd.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: q40kbd.c,v 1.12 2002/02/02 22:26:44 vojtech Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik 2 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * 3 *
6 * Based on the work of: 4 * Based on the work of:
@@ -49,7 +47,7 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
49MODULE_DESCRIPTION("Q40 PS/2 keyboard controller driver"); 47MODULE_DESCRIPTION("Q40 PS/2 keyboard controller driver");
50MODULE_LICENSE("GPL"); 48MODULE_LICENSE("GPL");
51 49
52DEFINE_SPINLOCK(q40kbd_lock); 50static DEFINE_SPINLOCK(q40kbd_lock);
53static struct serio *q40kbd_port; 51static struct serio *q40kbd_port;
54static struct platform_device *q40kbd_device; 52static struct platform_device *q40kbd_device;
55 53
diff --git a/drivers/input/serio/rpckbd.c b/drivers/input/serio/rpckbd.c
index 34c59d9c6205..1567b7782478 100644
--- a/drivers/input/serio/rpckbd.c
+++ b/drivers/input/serio/rpckbd.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: rpckbd.c,v 1.7 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik 2 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * Copyright (c) 2002 Russell King 3 * Copyright (c) 2002 Russell King
6 */ 4 */
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 7f5293828fbf..78f2abb5c11b 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -331,9 +331,10 @@ static void serio_handle_event(void)
331} 331}
332 332
333/* 333/*
334 * Remove all events that have been submitted for a given serio port. 334 * Remove all events that have been submitted for a given
335 * object, be it serio port or driver.
335 */ 336 */
336static void serio_remove_pending_events(struct serio *serio) 337static void serio_remove_pending_events(void *object)
337{ 338{
338 struct list_head *node, *next; 339 struct list_head *node, *next;
339 struct serio_event *event; 340 struct serio_event *event;
@@ -343,7 +344,7 @@ static void serio_remove_pending_events(struct serio *serio)
343 344
344 list_for_each_safe(node, next, &serio_event_list) { 345 list_for_each_safe(node, next, &serio_event_list) {
345 event = list_entry(node, struct serio_event, node); 346 event = list_entry(node, struct serio_event, node);
346 if (event->object == serio) { 347 if (event->object == object) {
347 list_del_init(node); 348 list_del_init(node);
348 serio_free_event(event); 349 serio_free_event(event);
349 } 350 }
@@ -837,7 +838,9 @@ void serio_unregister_driver(struct serio_driver *drv)
837 struct serio *serio; 838 struct serio *serio;
838 839
839 mutex_lock(&serio_mutex); 840 mutex_lock(&serio_mutex);
841
840 drv->manual_bind = 1; /* so serio_find_driver ignores it */ 842 drv->manual_bind = 1; /* so serio_find_driver ignores it */
843 serio_remove_pending_events(drv);
841 844
842start_over: 845start_over:
843 list_for_each_entry(serio, &serio_list, node) { 846 list_for_each_entry(serio, &serio_list, node) {
diff --git a/drivers/input/serio/xilinx_ps2.c b/drivers/input/serio/xilinx_ps2.c
new file mode 100644
index 000000000000..0ed044d5e685
--- /dev/null
+++ b/drivers/input/serio/xilinx_ps2.c
@@ -0,0 +1,380 @@
1/*
2 * Xilinx XPS PS/2 device driver
3 *
4 * (c) 2005 MontaVista Software, Inc.
5 * (c) 2008 Xilinx, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, write to the Free Software Foundation, Inc.,
14 * 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17
18#include <linux/module.h>
19#include <linux/serio.h>
20#include <linux/interrupt.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23#include <linux/list.h>
24#include <linux/io.h>
25
26#include <linux/of_device.h>
27#include <linux/of_platform.h>
28
29#define DRIVER_NAME "xilinx_ps2"
30
31/* Register offsets for the xps2 device */
32#define XPS2_SRST_OFFSET 0x00000000 /* Software Reset register */
33#define XPS2_STATUS_OFFSET 0x00000004 /* Status register */
34#define XPS2_RX_DATA_OFFSET 0x00000008 /* Receive Data register */
35#define XPS2_TX_DATA_OFFSET 0x0000000C /* Transmit Data register */
36#define XPS2_GIER_OFFSET 0x0000002C /* Global Interrupt Enable reg */
37#define XPS2_IPISR_OFFSET 0x00000030 /* Interrupt Status register */
38#define XPS2_IPIER_OFFSET 0x00000038 /* Interrupt Enable register */
39
40/* Reset Register Bit Definitions */
41#define XPS2_SRST_RESET 0x0000000A /* Software Reset */
42
43/* Status Register Bit Positions */
44#define XPS2_STATUS_RX_FULL 0x00000001 /* Receive Full */
45#define XPS2_STATUS_TX_FULL 0x00000002 /* Transmit Full */
46
47/* Bit definitions for ISR/IER registers. Both the registers have the same bit
48 * definitions and are only defined once. */
49#define XPS2_IPIXR_WDT_TOUT 0x00000001 /* Watchdog Timeout Interrupt */
50#define XPS2_IPIXR_TX_NOACK 0x00000002 /* Transmit No ACK Interrupt */
51#define XPS2_IPIXR_TX_ACK 0x00000004 /* Transmit ACK (Data) Interrupt */
52#define XPS2_IPIXR_RX_OVF 0x00000008 /* Receive Overflow Interrupt */
53#define XPS2_IPIXR_RX_ERR 0x00000010 /* Receive Error Interrupt */
54#define XPS2_IPIXR_RX_FULL 0x00000020 /* Receive Data Interrupt */
55
56/* Mask for all the Transmit Interrupts */
57#define XPS2_IPIXR_TX_ALL (XPS2_IPIXR_TX_NOACK | XPS2_IPIXR_TX_ACK)
58
59/* Mask for all the Receive Interrupts */
60#define XPS2_IPIXR_RX_ALL (XPS2_IPIXR_RX_OVF | XPS2_IPIXR_RX_ERR | \
61 XPS2_IPIXR_RX_FULL)
62
63/* Mask for all the Interrupts */
64#define XPS2_IPIXR_ALL (XPS2_IPIXR_TX_ALL | XPS2_IPIXR_RX_ALL | \
65 XPS2_IPIXR_WDT_TOUT)
66
67/* Global Interrupt Enable mask */
68#define XPS2_GIER_GIE_MASK 0x80000000
69
70struct xps2data {
71 int irq;
72 u32 phys_addr;
73 u32 remap_size;
74 spinlock_t lock;
75 u8 rxb; /* Rx buffer */
76 void __iomem *base_address; /* virt. address of control registers */
77 unsigned int dfl;
78 struct serio serio; /* serio */
79};
80
81/************************************/
82/* XPS PS/2 data transmission calls */
83/************************************/
84
85/*
86 * xps2_recv() will attempt to receive a byte of data from the PS/2 port.
87 */
88static int xps2_recv(struct xps2data *drvdata, u8 *byte)
89{
90 u32 sr;
91 int status = -1;
92
93 /* If there is data available in the PS/2 receiver, read it */
94 sr = in_be32(drvdata->base_address + XPS2_STATUS_OFFSET);
95 if (sr & XPS2_STATUS_RX_FULL) {
96 *byte = in_be32(drvdata->base_address + XPS2_RX_DATA_OFFSET);
97 status = 0;
98 }
99
100 return status;
101}
102
103/*********************/
104/* Interrupt handler */
105/*********************/
106static irqreturn_t xps2_interrupt(int irq, void *dev_id)
107{
108 struct xps2data *drvdata = dev_id;
109 u32 intr_sr;
110 u8 c;
111 int status;
112
113 /* Get the PS/2 interrupts and clear them */
114 intr_sr = in_be32(drvdata->base_address + XPS2_IPISR_OFFSET);
115 out_be32(drvdata->base_address + XPS2_IPISR_OFFSET, intr_sr);
116
117 /* Check which interrupt is active */
118 if (intr_sr & XPS2_IPIXR_RX_OVF)
119 printk(KERN_WARNING "%s: receive overrun error\n",
120 drvdata->serio.name);
121
122 if (intr_sr & XPS2_IPIXR_RX_ERR)
123 drvdata->dfl |= SERIO_PARITY;
124
125 if (intr_sr & (XPS2_IPIXR_TX_NOACK | XPS2_IPIXR_WDT_TOUT))
126 drvdata->dfl |= SERIO_TIMEOUT;
127
128 if (intr_sr & XPS2_IPIXR_RX_FULL) {
129 status = xps2_recv(drvdata, &drvdata->rxb);
130
131 /* Error, if a byte is not received */
132 if (status) {
133 printk(KERN_ERR
134 "%s: wrong rcvd byte count (%d)\n",
135 drvdata->serio.name, status);
136 } else {
137 c = drvdata->rxb;
138 serio_interrupt(&drvdata->serio, c, drvdata->dfl);
139 drvdata->dfl = 0;
140 }
141 }
142
143 if (intr_sr & XPS2_IPIXR_TX_ACK)
144 drvdata->dfl = 0;
145
146 return IRQ_HANDLED;
147}
148
149/*******************/
150/* serio callbacks */
151/*******************/
152
153/*
154 * sxps2_write() sends a byte out through the PS/2 interface.
155 */
156static int sxps2_write(struct serio *pserio, unsigned char c)
157{
158 struct xps2data *drvdata = pserio->port_data;
159 unsigned long flags;
160 u32 sr;
161 int status = -1;
162
163 spin_lock_irqsave(&drvdata->lock, flags);
164
165 /* If the PS/2 transmitter is empty send a byte of data */
166 sr = in_be32(drvdata->base_address + XPS2_STATUS_OFFSET);
167 if (!(sr & XPS2_STATUS_TX_FULL)) {
168 out_be32(drvdata->base_address + XPS2_TX_DATA_OFFSET, c);
169 status = 0;
170 }
171
172 spin_unlock_irqrestore(&drvdata->lock, flags);
173
174 return status;
175}
176
177/*
178 * sxps2_open() is called when a port is open by the higher layer.
179 */
180static int sxps2_open(struct serio *pserio)
181{
182 struct xps2data *drvdata = pserio->port_data;
183 int retval;
184
185 retval = request_irq(drvdata->irq, &xps2_interrupt, 0,
186 DRIVER_NAME, drvdata);
187 if (retval) {
188 printk(KERN_ERR
189 "%s: Couldn't allocate interrupt %d\n",
190 drvdata->serio.name, drvdata->irq);
191 return retval;
192 }
193
194 /* start reception by enabling the interrupts */
195 out_be32(drvdata->base_address + XPS2_GIER_OFFSET, XPS2_GIER_GIE_MASK);
196 out_be32(drvdata->base_address + XPS2_IPIER_OFFSET, XPS2_IPIXR_RX_ALL);
197 (void)xps2_recv(drvdata, &drvdata->rxb);
198
199 return 0; /* success */
200}
201
202/*
203 * sxps2_close() frees the interrupt.
204 */
205static void sxps2_close(struct serio *pserio)
206{
207 struct xps2data *drvdata = pserio->port_data;
208
209 /* Disable the PS2 interrupts */
210 out_be32(drvdata->base_address + XPS2_GIER_OFFSET, 0x00);
211 out_be32(drvdata->base_address + XPS2_IPIER_OFFSET, 0x00);
212 free_irq(drvdata->irq, drvdata);
213}
214
215/*********************/
216/* Device setup code */
217/*********************/
218
219static int xps2_setup(struct device *dev, struct resource *regs_res,
220 struct resource *irq_res)
221{
222 struct xps2data *drvdata;
223 struct serio *serio;
224 unsigned long remap_size;
225 int retval;
226
227 if (!dev)
228 return -EINVAL;
229
230 if (!regs_res || !irq_res) {
231 dev_err(dev, "IO resource(s) not found\n");
232 return -EINVAL;
233 }
234
235 drvdata = kzalloc(sizeof(struct xps2data), GFP_KERNEL);
236 if (!drvdata) {
237 dev_err(dev, "Couldn't allocate device private record\n");
238 return -ENOMEM;
239 }
240
241 dev_set_drvdata(dev, drvdata);
242
243 spin_lock_init(&drvdata->lock);
244 drvdata->irq = irq_res->start;
245
246 remap_size = regs_res->end - regs_res->start + 1;
247 if (!request_mem_region(regs_res->start, remap_size, DRIVER_NAME)) {
248 dev_err(dev, "Couldn't lock memory region at 0x%08X\n",
249 (unsigned int)regs_res->start);
250 retval = -EBUSY;
251 goto failed1;
252 }
253
254 /* Fill in configuration data and add them to the list */
255 drvdata->phys_addr = regs_res->start;
256 drvdata->remap_size = remap_size;
257 drvdata->base_address = ioremap(regs_res->start, remap_size);
258 if (drvdata->base_address == NULL) {
259 dev_err(dev, "Couldn't ioremap memory at 0x%08X\n",
260 (unsigned int)regs_res->start);
261 retval = -EFAULT;
262 goto failed2;
263 }
264
265 /* Disable all the interrupts, just in case */
266 out_be32(drvdata->base_address + XPS2_IPIER_OFFSET, 0);
267
268 /* Reset the PS2 device and abort any current transaction, to make sure
269 * we have the PS2 in a good state */
270 out_be32(drvdata->base_address + XPS2_SRST_OFFSET, XPS2_SRST_RESET);
271
272 dev_info(dev, "Xilinx PS2 at 0x%08X mapped to 0x%08X, irq=%d\n",
273 drvdata->phys_addr, (u32)drvdata->base_address, drvdata->irq);
274
275 serio = &drvdata->serio;
276 serio->id.type = SERIO_8042;
277 serio->write = sxps2_write;
278 serio->open = sxps2_open;
279 serio->close = sxps2_close;
280 serio->port_data = drvdata;
281 serio->dev.parent = dev;
282 snprintf(serio->name, sizeof(serio->name),
283 "Xilinx XPS PS/2 at %08X", drvdata->phys_addr);
284 snprintf(serio->phys, sizeof(serio->phys),
285 "xilinxps2/serio at %08X", drvdata->phys_addr);
286 serio_register_port(serio);
287
288 return 0; /* success */
289
290failed2:
291 release_mem_region(regs_res->start, remap_size);
292failed1:
293 kfree(drvdata);
294 dev_set_drvdata(dev, NULL);
295
296 return retval;
297}
298
299/***************************/
300/* OF Platform Bus Support */
301/***************************/
302
303static int __devinit xps2_of_probe(struct of_device *ofdev, const struct
304 of_device_id * match)
305{
306 struct resource r_irq; /* Interrupt resources */
307 struct resource r_mem; /* IO mem resources */
308 int rc = 0;
309
310 printk(KERN_INFO "Device Tree Probing \'%s\'\n",
311 ofdev->node->name);
312
313 /* Get iospace for the device */
314 rc = of_address_to_resource(ofdev->node, 0, &r_mem);
315 if (rc) {
316 dev_err(&ofdev->dev, "invalid address\n");
317 return rc;
318 }
319
320 /* Get IRQ for the device */
321 rc = of_irq_to_resource(ofdev->node, 0, &r_irq);
322 if (rc == NO_IRQ) {
323 dev_err(&ofdev->dev, "no IRQ found\n");
324 return rc;
325 }
326
327 return xps2_setup(&ofdev->dev, &r_mem, &r_irq);
328}
329
330static int __devexit xps2_of_remove(struct of_device *of_dev)
331{
332 struct device *dev = &of_dev->dev;
333 struct xps2data *drvdata;
334
335 if (!dev)
336 return -EINVAL;
337
338 drvdata = dev_get_drvdata(dev);
339
340 serio_unregister_port(&drvdata->serio);
341 iounmap(drvdata->base_address);
342 release_mem_region(drvdata->phys_addr, drvdata->remap_size);
343 kfree(drvdata);
344
345 dev_set_drvdata(dev, NULL);
346
347 return 0; /* success */
348}
349
350/* Match table for of_platform binding */
351static struct of_device_id xps2_of_match[] __devinitdata = {
352 { .compatible = "xlnx,xps-ps2-1.00.a", },
353 { /* end of list */ },
354};
355MODULE_DEVICE_TABLE(of, xps2_of_match);
356
357static struct of_platform_driver xps2_of_driver = {
358 .name = DRIVER_NAME,
359 .match_table = xps2_of_match,
360 .probe = xps2_of_probe,
361 .remove = __devexit_p(xps2_of_remove),
362};
363
364static int __init xps2_init(void)
365{
366 return of_register_platform_driver(&xps2_of_driver);
367}
368
369static void __exit xps2_cleanup(void)
370{
371 of_unregister_platform_driver(&xps2_of_driver);
372}
373
374module_init(xps2_init);
375module_exit(xps2_cleanup);
376
377MODULE_AUTHOR("Xilinx, Inc.");
378MODULE_DESCRIPTION("Xilinx XPS PS/2 driver");
379MODULE_LICENSE("GPL");
380
diff --git a/drivers/input/tablet/acecad.c b/drivers/input/tablet/acecad.c
index b973d0ef6d16..570e0e83ac46 100644
--- a/drivers/input/tablet/acecad.c
+++ b/drivers/input/tablet/acecad.c
@@ -73,10 +73,10 @@ static void usb_acecad_irq(struct urb *urb)
73 case -ENOENT: 73 case -ENOENT:
74 case -ESHUTDOWN: 74 case -ESHUTDOWN:
75 /* this urb is terminated, clean up */ 75 /* this urb is terminated, clean up */
76 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 76 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
77 return; 77 return;
78 default: 78 default:
79 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 79 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
80 goto resubmit; 80 goto resubmit;
81 } 81 }
82 82
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 55c1134d6137..8f037a1d44a6 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -449,12 +449,12 @@ static void aiptek_irq(struct urb *urb)
449 case -ESHUTDOWN: 449 case -ESHUTDOWN:
450 /* This urb is terminated, clean up */ 450 /* This urb is terminated, clean up */
451 dbg("%s - urb shutting down with status: %d", 451 dbg("%s - urb shutting down with status: %d",
452 __FUNCTION__, urb->status); 452 __func__, urb->status);
453 return; 453 return;
454 454
455 default: 455 default:
456 dbg("%s - nonzero urb status received: %d", 456 dbg("%s - nonzero urb status received: %d",
457 __FUNCTION__, urb->status); 457 __func__, urb->status);
458 goto exit; 458 goto exit;
459 } 459 }
460 460
@@ -813,7 +813,7 @@ exit:
813 retval = usb_submit_urb(urb, GFP_ATOMIC); 813 retval = usb_submit_urb(urb, GFP_ATOMIC);
814 if (retval != 0) { 814 if (retval != 0) {
815 err("%s - usb_submit_urb failed with result %d", 815 err("%s - usb_submit_urb failed with result %d",
816 __FUNCTION__, retval); 816 __func__, retval);
817 } 817 }
818} 818}
819 819
diff --git a/drivers/input/tablet/gtco.c b/drivers/input/tablet/gtco.c
index 1e748e46d12e..b9b7a98bc5a5 100644
--- a/drivers/input/tablet/gtco.c
+++ b/drivers/input/tablet/gtco.c
@@ -863,7 +863,7 @@ static int gtco_probe(struct usb_interface *usbinterface,
863 gtco->urbinfo = usb_alloc_urb(0, GFP_KERNEL); 863 gtco->urbinfo = usb_alloc_urb(0, GFP_KERNEL);
864 if (!gtco->urbinfo) { 864 if (!gtco->urbinfo) {
865 err("Failed to allocate URB"); 865 err("Failed to allocate URB");
866 return -ENOMEM; 866 error = -ENOMEM;
867 goto err_free_buf; 867 goto err_free_buf;
868 } 868 }
869 869
diff --git a/drivers/input/tablet/kbtab.c b/drivers/input/tablet/kbtab.c
index f23f5a97fb38..d89112fa6e6b 100644
--- a/drivers/input/tablet/kbtab.c
+++ b/drivers/input/tablet/kbtab.c
@@ -56,10 +56,10 @@ static void kbtab_irq(struct urb *urb)
56 case -ENOENT: 56 case -ENOENT:
57 case -ESHUTDOWN: 57 case -ESHUTDOWN:
58 /* this urb is terminated, clean up */ 58 /* this urb is terminated, clean up */
59 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 59 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
60 return; 60 return;
61 default: 61 default:
62 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 62 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
63 goto exit; 63 goto exit;
64 } 64 }
65 65
@@ -88,7 +88,7 @@ static void kbtab_irq(struct urb *urb)
88 retval = usb_submit_urb (urb, GFP_ATOMIC); 88 retval = usb_submit_urb (urb, GFP_ATOMIC);
89 if (retval) 89 if (retval)
90 err ("%s - usb_submit_urb failed with result %d", 90 err ("%s - usb_submit_urb failed with result %d",
91 __FUNCTION__, retval); 91 __func__, retval);
92} 92}
93 93
94static struct usb_device_id kbtab_ids[] = { 94static struct usb_device_id kbtab_ids[] = {
diff --git a/drivers/input/tablet/wacom.h b/drivers/input/tablet/wacom.h
index 706619d06f71..ca62ec639f8f 100644
--- a/drivers/input/tablet/wacom.h
+++ b/drivers/input/tablet/wacom.h
@@ -105,7 +105,7 @@ struct wacom {
105 struct urb *irq; 105 struct urb *irq;
106 struct wacom_wac * wacom_wac; 106 struct wacom_wac * wacom_wac;
107 struct mutex lock; 107 struct mutex lock;
108 int open:1; 108 unsigned int open:1;
109 char phys[32]; 109 char phys[32];
110}; 110};
111 111
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index 71cc0c140790..5fbc463baf5a 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -56,10 +56,10 @@ static void wacom_sys_irq(struct urb *urb)
56 case -ENOENT: 56 case -ENOENT:
57 case -ESHUTDOWN: 57 case -ESHUTDOWN:
58 /* this urb is terminated, clean up */ 58 /* this urb is terminated, clean up */
59 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 59 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
60 return; 60 return;
61 default: 61 default:
62 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 62 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
63 goto exit; 63 goto exit;
64 } 64 }
65 65
@@ -74,7 +74,7 @@ static void wacom_sys_irq(struct urb *urb)
74 retval = usb_submit_urb (urb, GFP_ATOMIC); 74 retval = usb_submit_urb (urb, GFP_ATOMIC);
75 if (retval) 75 if (retval)
76 err ("%s - usb_submit_urb failed with result %d", 76 err ("%s - usb_submit_urb failed with result %d",
77 __FUNCTION__, retval); 77 __func__, retval);
78} 78}
79 79
80void wacom_report_key(void *wcombo, unsigned int key_type, int key_data) 80void wacom_report_key(void *wcombo, unsigned int key_type, int key_data)
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index 192513e1f04c..bf3d9a8b2c1b 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -56,7 +56,7 @@ static int wacom_penpartner_irq(struct wacom_wac *wacom, void *wcombo)
56static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo) 56static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
57{ 57{
58 unsigned char *data = wacom->data; 58 unsigned char *data = wacom->data;
59 int prox, id, pressure; 59 int prox, pressure;
60 60
61 if (data[0] != 2) { 61 if (data[0] != 2) {
62 dbg("wacom_pl_irq: received unknown report #%d", data[0]); 62 dbg("wacom_pl_irq: received unknown report #%d", data[0]);
@@ -65,7 +65,7 @@ static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
65 65
66 prox = data[1] & 0x40; 66 prox = data[1] & 0x40;
67 67
68 id = ERASER_DEVICE_ID; 68 wacom->id[0] = ERASER_DEVICE_ID;
69 if (prox) { 69 if (prox) {
70 70
71 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1)); 71 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
@@ -99,10 +99,10 @@ static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
99 if (wacom->tool[1] != BTN_TOOL_RUBBER) { 99 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
100 /* Unknown tool selected default to pen tool */ 100 /* Unknown tool selected default to pen tool */
101 wacom->tool[1] = BTN_TOOL_PEN; 101 wacom->tool[1] = BTN_TOOL_PEN;
102 id = STYLUS_DEVICE_ID; 102 wacom->id[0] = STYLUS_DEVICE_ID;
103 } 103 }
104 wacom_report_key(wcombo, wacom->tool[1], prox); /* report in proximity for tool */ 104 wacom_report_key(wcombo, wacom->tool[1], prox); /* report in proximity for tool */
105 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */ 105 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
106 wacom_report_abs(wcombo, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14)); 106 wacom_report_abs(wcombo, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
107 wacom_report_abs(wcombo, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14)); 107 wacom_report_abs(wcombo, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
108 wacom_report_abs(wcombo, ABS_PRESSURE, pressure); 108 wacom_report_abs(wcombo, ABS_PRESSURE, pressure);
@@ -127,7 +127,6 @@ static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
127static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo) 127static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo)
128{ 128{
129 unsigned char *data = wacom->data; 129 unsigned char *data = wacom->data;
130 int id;
131 130
132 if (data[0] != 2) { 131 if (data[0] != 2) {
133 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]); 132 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
@@ -137,13 +136,13 @@ static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo)
137 if (data[1] & 0x04) { 136 if (data[1] & 0x04) {
138 wacom_report_key(wcombo, BTN_TOOL_RUBBER, data[1] & 0x20); 137 wacom_report_key(wcombo, BTN_TOOL_RUBBER, data[1] & 0x20);
139 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x08); 138 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x08);
140 id = ERASER_DEVICE_ID; 139 wacom->id[0] = ERASER_DEVICE_ID;
141 } else { 140 } else {
142 wacom_report_key(wcombo, BTN_TOOL_PEN, data[1] & 0x20); 141 wacom_report_key(wcombo, BTN_TOOL_PEN, data[1] & 0x20);
143 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01); 142 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01);
144 id = STYLUS_DEVICE_ID; 143 wacom->id[0] = STYLUS_DEVICE_ID;
145 } 144 }
146 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */ 145 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
147 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2])); 146 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2]));
148 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4])); 147 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
149 wacom_report_abs(wcombo, ABS_PRESSURE, wacom_le16_to_cpu(&data[6])); 148 wacom_report_abs(wcombo, ABS_PRESSURE, wacom_le16_to_cpu(&data[6]));
@@ -155,27 +154,26 @@ static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo)
155static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo) 154static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
156{ 155{
157 unsigned char *data = wacom->data; 156 unsigned char *data = wacom->data;
158 int x, y, id, rw; 157 int x, y, rw;
159 158
160 if (data[0] != 2) { 159 if (data[0] != 2) {
161 dbg("wacom_graphire_irq: received unknown report #%d", data[0]); 160 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
162 return 0; 161 return 0;
163 } 162 }
164 163
165 id = STYLUS_DEVICE_ID; 164 if (data[1] & 0x80) {
166 if ((data[1] & 0x80) && ((data[1] & 0x07) || data[2] || data[3] || data[4]
167 || data[5] || data[6] || (data[7] & 0x07))) {
168 /* in prox and not a pad data */ 165 /* in prox and not a pad data */
169 166
170 switch ((data[1] >> 5) & 3) { 167 switch ((data[1] >> 5) & 3) {
171 168
172 case 0: /* Pen */ 169 case 0: /* Pen */
173 wacom->tool[0] = BTN_TOOL_PEN; 170 wacom->tool[0] = BTN_TOOL_PEN;
171 wacom->id[0] = STYLUS_DEVICE_ID;
174 break; 172 break;
175 173
176 case 1: /* Rubber */ 174 case 1: /* Rubber */
177 wacom->tool[0] = BTN_TOOL_RUBBER; 175 wacom->tool[0] = BTN_TOOL_RUBBER;
178 id = ERASER_DEVICE_ID; 176 wacom->id[0] = ERASER_DEVICE_ID;
179 break; 177 break;
180 178
181 case 2: /* Mouse with wheel */ 179 case 2: /* Mouse with wheel */
@@ -190,7 +188,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
190 188
191 case 3: /* Mouse without wheel */ 189 case 3: /* Mouse without wheel */
192 wacom->tool[0] = BTN_TOOL_MOUSE; 190 wacom->tool[0] = BTN_TOOL_MOUSE;
193 id = CURSOR_DEVICE_ID; 191 wacom->id[0] = CURSOR_DEVICE_ID;
194 wacom_report_key(wcombo, BTN_LEFT, data[1] & 0x01); 192 wacom_report_key(wcombo, BTN_LEFT, data[1] & 0x01);
195 wacom_report_key(wcombo, BTN_RIGHT, data[1] & 0x02); 193 wacom_report_key(wcombo, BTN_RIGHT, data[1] & 0x02);
196 if (wacom->features->type == WACOM_G4 || 194 if (wacom->features->type == WACOM_G4 ||
@@ -210,9 +208,9 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
210 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02); 208 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
211 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04); 209 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04);
212 } 210 }
213 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */ 211 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
214 wacom_report_key(wcombo, wacom->tool[0], 1); 212 wacom_report_key(wcombo, wacom->tool[0], 1);
215 } else if (!(data[1] & 0x90)) { 213 } else if (wacom->id[0]) {
216 wacom_report_abs(wcombo, ABS_X, 0); 214 wacom_report_abs(wcombo, ABS_X, 0);
217 wacom_report_abs(wcombo, ABS_Y, 0); 215 wacom_report_abs(wcombo, ABS_Y, 0);
218 if (wacom->tool[0] == BTN_TOOL_MOUSE) { 216 if (wacom->tool[0] == BTN_TOOL_MOUSE) {
@@ -225,6 +223,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
225 wacom_report_key(wcombo, BTN_STYLUS, 0); 223 wacom_report_key(wcombo, BTN_STYLUS, 0);
226 wacom_report_key(wcombo, BTN_STYLUS2, 0); 224 wacom_report_key(wcombo, BTN_STYLUS2, 0);
227 } 225 }
226 wacom->id[0] = 0;
228 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ 227 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
229 wacom_report_key(wcombo, wacom->tool[0], 0); 228 wacom_report_key(wcombo, wacom->tool[0], 0);
230 } 229 }
@@ -234,13 +233,13 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
234 case WACOM_G4: 233 case WACOM_G4:
235 if (data[7] & 0xf8) { 234 if (data[7] & 0xf8) {
236 wacom_input_sync(wcombo); /* sync last event */ 235 wacom_input_sync(wcombo); /* sync last event */
237 wacom->id[1] = 1; 236 wacom->id[1] = PAD_DEVICE_ID;
238 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40)); 237 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
239 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80)); 238 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
240 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3); 239 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
241 wacom_report_rel(wcombo, REL_WHEEL, rw); 240 wacom_report_rel(wcombo, REL_WHEEL, rw);
242 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0); 241 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
243 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID); 242 wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]);
244 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 243 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
245 } else if (wacom->id[1]) { 244 } else if (wacom->id[1]) {
246 wacom_input_sync(wcombo); /* sync last event */ 245 wacom_input_sync(wcombo); /* sync last event */
@@ -255,14 +254,14 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
255 case WACOM_MO: 254 case WACOM_MO:
256 if ((data[7] & 0xf8) || (data[8] & 0xff)) { 255 if ((data[7] & 0xf8) || (data[8] & 0xff)) {
257 wacom_input_sync(wcombo); /* sync last event */ 256 wacom_input_sync(wcombo); /* sync last event */
258 wacom->id[1] = 1; 257 wacom->id[1] = PAD_DEVICE_ID;
259 wacom_report_key(wcombo, BTN_0, (data[7] & 0x08)); 258 wacom_report_key(wcombo, BTN_0, (data[7] & 0x08));
260 wacom_report_key(wcombo, BTN_1, (data[7] & 0x20)); 259 wacom_report_key(wcombo, BTN_1, (data[7] & 0x20));
261 wacom_report_key(wcombo, BTN_4, (data[7] & 0x10)); 260 wacom_report_key(wcombo, BTN_4, (data[7] & 0x10));
262 wacom_report_key(wcombo, BTN_5, (data[7] & 0x40)); 261 wacom_report_key(wcombo, BTN_5, (data[7] & 0x40));
263 wacom_report_abs(wcombo, ABS_WHEEL, (data[8] & 0x7f)); 262 wacom_report_abs(wcombo, ABS_WHEEL, (data[8] & 0x7f));
264 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0); 263 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
265 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID); 264 wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]);
266 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 265 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
267 } else if (wacom->id[1]) { 266 } else if (wacom->id[1]) {
268 wacom_input_sync(wcombo); /* sync last event */ 267 wacom_input_sync(wcombo); /* sync last event */
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 565ec711c2ee..e57366521572 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -103,6 +103,18 @@ config TOUCHSCREEN_MTOUCH
103 To compile this driver as a module, choose M here: the 103 To compile this driver as a module, choose M here: the
104 module will be called mtouch. 104 module will be called mtouch.
105 105
106config TOUCHSCREEN_INEXIO
107 tristate "iNexio serial touchscreens"
108 select SERIO
109 help
110 Say Y here if you have an iNexio serial touchscreen connected to
111 your system.
112
113 If unsure, say N.
114
115 To compile this driver as a module, choose M here: the
116 module will be called inexio.
117
106config TOUCHSCREEN_MK712 118config TOUCHSCREEN_MK712
107 tristate "ICS MicroClock MK712 touchscreen" 119 tristate "ICS MicroClock MK712 touchscreen"
108 help 120 help
@@ -134,6 +146,18 @@ config TOUCHSCREEN_HP7XX
134 To compile this driver as a module, choose M here: the 146 To compile this driver as a module, choose M here: the
135 module will be called jornada720_ts. 147 module will be called jornada720_ts.
136 148
149config TOUCHSCREEN_HTCPEN
150 tristate "HTC Shift X9500 touchscreen"
151 depends on ISA
152 help
153 Say Y here if you have an HTC Shift UMPC also known as HTC X9500
154 Clio / Shangrila and want to support the built-in touchscreen.
155
156 If unsure, say N.
157
158 To compile this driver as a module, choose M here: the
159 module will be called htcpen.
160
137config TOUCHSCREEN_PENMOUNT 161config TOUCHSCREEN_PENMOUNT
138 tristate "Penmount serial touchscreen" 162 tristate "Penmount serial touchscreen"
139 select SERIO 163 select SERIO
@@ -146,6 +170,17 @@ config TOUCHSCREEN_PENMOUNT
146 To compile this driver as a module, choose M here: the 170 To compile this driver as a module, choose M here: the
147 module will be called penmount. 171 module will be called penmount.
148 172
173config TOUCHSCREEN_MIGOR
174 tristate "Renesas MIGO-R touchscreen"
175 depends on SH_MIGOR && I2C
176 help
177 Say Y here to enable MIGO-R touchscreen support.
178
179 If unsure, say N.
180
181 To compile this driver as a module, choose M here: the
182 module will be called migor_ts.
183
149config TOUCHSCREEN_TOUCHRIGHT 184config TOUCHSCREEN_TOUCHRIGHT
150 tristate "Touchright serial touchscreen" 185 tristate "Touchright serial touchscreen"
151 select SERIO 186 select SERIO
@@ -316,4 +351,15 @@ config TOUCHSCREEN_USB_GOTOP
316 bool "GoTop Super_Q2/GogoPen/PenPower tablet device support" if EMBEDDED 351 bool "GoTop Super_Q2/GogoPen/PenPower tablet device support" if EMBEDDED
317 depends on TOUCHSCREEN_USB_COMPOSITE 352 depends on TOUCHSCREEN_USB_COMPOSITE
318 353
354config TOUCHSCREEN_TOUCHIT213
355 tristate "Sahara TouchIT-213 touchscreen"
356 select SERIO
357 help
358 Say Y here if you have a Sahara TouchIT-213 Tablet PC.
359
360 If unsure, say N.
361
362 To compile this driver as a module, choose M here: the
363 module will be called touchit213.
364
319endif 365endif
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 3c096d75651d..39a804cd80f1 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -12,12 +12,16 @@ obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o
12obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o 12obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
13obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o 13obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
14obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o 14obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o
15obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o
16obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o
15obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o 17obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
16obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o 18obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o
17obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o 19obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o
18obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o 20obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o
21obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o
19obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o 22obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o
20obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o 23obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
24obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o
21obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 25obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
22obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 26obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
23obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o 27obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
index a48a15868c4a..a54f90e02ab6 100644
--- a/drivers/input/touchscreen/gunze.c
+++ b/drivers/input/touchscreen/gunze.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: gunze.c,v 1.12 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik 2 * Copyright (c) 2000-2001 Vojtech Pavlik
5 */ 3 */
6 4
diff --git a/drivers/input/touchscreen/h3600_ts_input.c b/drivers/input/touchscreen/h3600_ts_input.c
index 28ae15ed12c5..4f86081dc7fc 100644
--- a/drivers/input/touchscreen/h3600_ts_input.c
+++ b/drivers/input/touchscreen/h3600_ts_input.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: h3600_ts_input.c,v 1.4 2002/01/23 06:39:37 jsimmons Exp $
3 *
4 * Copyright (c) 2001 "Crazy" James Simmons jsimmons@transvirtual.com 2 * Copyright (c) 2001 "Crazy" James Simmons jsimmons@transvirtual.com
5 * 3 *
6 * Sponsored by Transvirtual Technology. 4 * Sponsored by Transvirtual Technology.
diff --git a/drivers/input/touchscreen/htcpen.c b/drivers/input/touchscreen/htcpen.c
new file mode 100644
index 000000000000..62811de6f18f
--- /dev/null
+++ b/drivers/input/touchscreen/htcpen.c
@@ -0,0 +1,255 @@
1/*
2 * HTC Shift touchscreen driver
3 *
4 * Copyright (C) 2008 Pau Oliva Fora <pof@eslack.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11#include <linux/errno.h>
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/input.h>
15#include <linux/interrupt.h>
16#include <linux/io.h>
17#include <linux/init.h>
18#include <linux/irq.h>
19#include <linux/isa.h>
20#include <linux/ioport.h>
21#include <linux/dmi.h>
22
23MODULE_AUTHOR("Pau Oliva Fora <pau@eslack.org>");
24MODULE_DESCRIPTION("HTC Shift touchscreen driver");
25MODULE_LICENSE("GPL");
26
27#define HTCPEN_PORT_IRQ_CLEAR 0x068
28#define HTCPEN_PORT_INIT 0x06c
29#define HTCPEN_PORT_INDEX 0x0250
30#define HTCPEN_PORT_DATA 0x0251
31#define HTCPEN_IRQ 3
32
33#define DEVICE_ENABLE 0xa2
34#define DEVICE_DISABLE 0xa3
35
36#define X_INDEX 3
37#define Y_INDEX 5
38#define TOUCH_INDEX 0xb
39#define LSB_XY_INDEX 0xc
40#define X_AXIS_MAX 2040
41#define Y_AXIS_MAX 2040
42
43static int invert_x;
44module_param(invert_x, bool, 0644);
45MODULE_PARM_DESC(invert_x, "If set, X axis is inverted");
46static int invert_y;
47module_param(invert_y, bool, 0644);
48MODULE_PARM_DESC(invert_y, "If set, Y axis is inverted");
49
50static struct pnp_device_id pnp_ids[] = {
51 { .id = "PNP0cc0" },
52 { .id = "" }
53};
54MODULE_DEVICE_TABLE(pnp, pnp_ids);
55
56static irqreturn_t htcpen_interrupt(int irq, void *handle)
57{
58 struct input_dev *htcpen_dev = handle;
59 unsigned short x, y, xy;
60
61 /* 0 = press; 1 = release */
62 outb_p(TOUCH_INDEX, HTCPEN_PORT_INDEX);
63
64 if (inb_p(HTCPEN_PORT_DATA)) {
65 input_report_key(htcpen_dev, BTN_TOUCH, 0);
66 } else {
67 outb_p(X_INDEX, HTCPEN_PORT_INDEX);
68 x = inb_p(HTCPEN_PORT_DATA);
69
70 outb_p(Y_INDEX, HTCPEN_PORT_INDEX);
71 y = inb_p(HTCPEN_PORT_DATA);
72
73 outb_p(LSB_XY_INDEX, HTCPEN_PORT_INDEX);
74 xy = inb_p(HTCPEN_PORT_DATA);
75
76 /* get high resolution value of X and Y using LSB */
77 x = X_AXIS_MAX - ((x * 8) + ((xy >> 4) & 0xf));
78 y = (y * 8) + (xy & 0xf);
79 if (invert_x)
80 x = X_AXIS_MAX - x;
81 if (invert_y)
82 y = Y_AXIS_MAX - y;
83
84 if (x != X_AXIS_MAX && x != 0) {
85 input_report_key(htcpen_dev, BTN_TOUCH, 1);
86 input_report_abs(htcpen_dev, ABS_X, x);
87 input_report_abs(htcpen_dev, ABS_Y, y);
88 }
89 }
90
91 input_sync(htcpen_dev);
92
93 inb_p(HTCPEN_PORT_IRQ_CLEAR);
94
95 return IRQ_HANDLED;
96}
97
98static int htcpen_open(struct input_dev *dev)
99{
100 outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT);
101
102 return 0;
103}
104
105static void htcpen_close(struct input_dev *dev)
106{
107 outb_p(DEVICE_DISABLE, HTCPEN_PORT_INIT);
108 synchronize_irq(HTCPEN_IRQ);
109}
110
111static int __devinit htcpen_isa_probe(struct device *dev, unsigned int id)
112{
113 struct input_dev *htcpen_dev;
114 int err = -EBUSY;
115
116 if (!request_region(HTCPEN_PORT_IRQ_CLEAR, 1, "htcpen")) {
117 printk(KERN_ERR "htcpen: unable to get IO region 0x%x\n",
118 HTCPEN_PORT_IRQ_CLEAR);
119 goto request_region1_failed;
120 }
121
122 if (!request_region(HTCPEN_PORT_INIT, 1, "htcpen")) {
123 printk(KERN_ERR "htcpen: unable to get IO region 0x%x\n",
124 HTCPEN_PORT_INIT);
125 goto request_region2_failed;
126 }
127
128 if (!request_region(HTCPEN_PORT_INDEX, 2, "htcpen")) {
129 printk(KERN_ERR "htcpen: unable to get IO region 0x%x\n",
130 HTCPEN_PORT_INDEX);
131 goto request_region3_failed;
132 }
133
134 htcpen_dev = input_allocate_device();
135 if (!htcpen_dev) {
136 printk(KERN_ERR "htcpen: can't allocate device\n");
137 err = -ENOMEM;
138 goto input_alloc_failed;
139 }
140
141 htcpen_dev->name = "HTC Shift EC TouchScreen";
142 htcpen_dev->id.bustype = BUS_ISA;
143
144 htcpen_dev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
145 htcpen_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
146 input_set_abs_params(htcpen_dev, ABS_X, 0, X_AXIS_MAX, 0, 0);
147 input_set_abs_params(htcpen_dev, ABS_Y, 0, Y_AXIS_MAX, 0, 0);
148
149 htcpen_dev->open = htcpen_open;
150 htcpen_dev->close = htcpen_close;
151
152 err = request_irq(HTCPEN_IRQ, htcpen_interrupt, 0, "htcpen",
153 htcpen_dev);
154 if (err) {
155 printk(KERN_ERR "htcpen: irq busy\n");
156 goto request_irq_failed;
157 }
158
159 inb_p(HTCPEN_PORT_IRQ_CLEAR);
160
161 err = input_register_device(htcpen_dev);
162 if (err)
163 goto input_register_failed;
164
165 dev_set_drvdata(dev, htcpen_dev);
166
167 return 0;
168
169 input_register_failed:
170 free_irq(HTCPEN_IRQ, htcpen_dev);
171 request_irq_failed:
172 input_free_device(htcpen_dev);
173 input_alloc_failed:
174 release_region(HTCPEN_PORT_INDEX, 2);
175 request_region3_failed:
176 release_region(HTCPEN_PORT_INIT, 1);
177 request_region2_failed:
178 release_region(HTCPEN_PORT_IRQ_CLEAR, 1);
179 request_region1_failed:
180 return err;
181}
182
183static int __devexit htcpen_isa_remove(struct device *dev, unsigned int id)
184{
185 struct input_dev *htcpen_dev = dev_get_drvdata(dev);
186
187 input_unregister_device(htcpen_dev);
188
189 free_irq(HTCPEN_IRQ, htcpen_dev);
190
191 release_region(HTCPEN_PORT_INDEX, 2);
192 release_region(HTCPEN_PORT_INIT, 1);
193 release_region(HTCPEN_PORT_IRQ_CLEAR, 1);
194
195 dev_set_drvdata(dev, NULL);
196
197 return 0;
198}
199
200#ifdef CONFIG_PM
201static int htcpen_isa_suspend(struct device *dev, unsigned int n,
202 pm_message_t state)
203{
204 outb_p(DEVICE_DISABLE, HTCPEN_PORT_INIT);
205
206 return 0;
207}
208
209static int htcpen_isa_resume(struct device *dev, unsigned int n)
210{
211 outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT);
212
213 return 0;
214}
215#endif
216
217static struct isa_driver htcpen_isa_driver = {
218 .probe = htcpen_isa_probe,
219 .remove = __devexit_p(htcpen_isa_remove),
220#ifdef CONFIG_PM
221 .suspend = htcpen_isa_suspend,
222 .resume = htcpen_isa_resume,
223#endif
224 .driver = {
225 .owner = THIS_MODULE,
226 .name = "htcpen",
227 }
228};
229
230static struct dmi_system_id __initdata htcshift_dmi_table[] = {
231 {
232 .ident = "Shift",
233 .matches = {
234 DMI_MATCH(DMI_SYS_VENDOR, "High Tech Computer Corp"),
235 DMI_MATCH(DMI_PRODUCT_NAME, "Shift"),
236 },
237 },
238 { }
239};
240
241static int __init htcpen_isa_init(void)
242{
243 if (!dmi_check_system(htcshift_dmi_table))
244 return -ENODEV;
245
246 return isa_register_driver(&htcpen_isa_driver, 1);
247}
248
249static void __exit htcpen_isa_exit(void)
250{
251 isa_unregister_driver(&htcpen_isa_driver);
252}
253
254module_init(htcpen_isa_init);
255module_exit(htcpen_isa_exit);
diff --git a/drivers/input/touchscreen/inexio.c b/drivers/input/touchscreen/inexio.c
new file mode 100644
index 000000000000..192ade0a0fb9
--- /dev/null
+++ b/drivers/input/touchscreen/inexio.c
@@ -0,0 +1,207 @@
1/*
2 * iNexio serial touchscreen driver
3 *
4 * Copyright (c) 2008 Richard Lemon
5 * Based on the mtouch driver (c) Vojtech Pavlik and Dan Streetman
6 *
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 */
14
15/*
16 * 2008/06/19 Richard Lemon <richard@codelemon.com>
17 * Copied mtouch.c and edited for iNexio protocol
18 */
19
20#include <linux/errno.h>
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/input.h>
25#include <linux/serio.h>
26#include <linux/init.h>
27
28#define DRIVER_DESC "iNexio serial touchscreen driver"
29
30MODULE_AUTHOR("Richard Lemon <richard@codelemon.com>");
31MODULE_DESCRIPTION(DRIVER_DESC);
32MODULE_LICENSE("GPL");
33
34/*
35 * Definitions & global arrays.
36 */
37
38#define INEXIO_FORMAT_TOUCH_BIT 0x01
39#define INEXIO_FORMAT_LENGTH 5
40#define INEXIO_RESPONSE_BEGIN_BYTE 0x80
41
42/* todo: check specs for max length of all responses */
43#define INEXIO_MAX_LENGTH 16
44
45#define INEXIO_MIN_XC 0
46#define INEXIO_MAX_XC 0x3fff
47#define INEXIO_MIN_YC 0
48#define INEXIO_MAX_YC 0x3fff
49
50#define INEXIO_GET_XC(data) (((data[1])<<7) | data[2])
51#define INEXIO_GET_YC(data) (((data[3])<<7) | data[4])
52#define INEXIO_GET_TOUCHED(data) (INEXIO_FORMAT_TOUCH_BIT & data[0])
53
54/*
55 * Per-touchscreen data.
56 */
57
58struct inexio {
59 struct input_dev *dev;
60 struct serio *serio;
61 int idx;
62 unsigned char data[INEXIO_MAX_LENGTH];
63 char phys[32];
64};
65
66static void inexio_process_data(struct inexio *pinexio)
67{
68 struct input_dev *dev = pinexio->dev;
69
70 if (INEXIO_FORMAT_LENGTH == ++pinexio->idx) {
71 input_report_abs(dev, ABS_X, INEXIO_GET_XC(pinexio->data));
72 input_report_abs(dev, ABS_Y, INEXIO_GET_YC(pinexio->data));
73 input_report_key(dev, BTN_TOUCH, INEXIO_GET_TOUCHED(pinexio->data));
74 input_sync(dev);
75
76 pinexio->idx = 0;
77 }
78}
79
80static irqreturn_t inexio_interrupt(struct serio *serio,
81 unsigned char data, unsigned int flags)
82{
83 struct inexio* pinexio = serio_get_drvdata(serio);
84
85 pinexio->data[pinexio->idx] = data;
86
87 if (INEXIO_RESPONSE_BEGIN_BYTE&pinexio->data[0])
88 inexio_process_data(pinexio);
89 else
90 printk(KERN_DEBUG "inexio.c: unknown/unsynchronized data from device, byte %x\n",pinexio->data[0]);
91
92 return IRQ_HANDLED;
93}
94
95/*
96 * inexio_disconnect() is the opposite of inexio_connect()
97 */
98
99static void inexio_disconnect(struct serio *serio)
100{
101 struct inexio* pinexio = serio_get_drvdata(serio);
102
103 input_get_device(pinexio->dev);
104 input_unregister_device(pinexio->dev);
105 serio_close(serio);
106 serio_set_drvdata(serio, NULL);
107 input_put_device(pinexio->dev);
108 kfree(pinexio);
109}
110
111/*
112 * inexio_connect() is the routine that is called when someone adds a
113 * new serio device that supports iNexio protocol and registers it as
114 * an input device. This is usually accomplished using inputattach.
115 */
116
117static int inexio_connect(struct serio *serio, struct serio_driver *drv)
118{
119 struct inexio *pinexio;
120 struct input_dev *input_dev;
121 int err;
122
123 pinexio = kzalloc(sizeof(struct inexio), GFP_KERNEL);
124 input_dev = input_allocate_device();
125 if (!pinexio || !input_dev) {
126 err = -ENOMEM;
127 goto fail1;
128 }
129
130 pinexio->serio = serio;
131 pinexio->dev = input_dev;
132 snprintf(pinexio->phys, sizeof(pinexio->phys), "%s/input0", serio->phys);
133
134 input_dev->name = "iNexio Serial TouchScreen";
135 input_dev->phys = pinexio->phys;
136 input_dev->id.bustype = BUS_RS232;
137 input_dev->id.vendor = SERIO_INEXIO;
138 input_dev->id.product = 0;
139 input_dev->id.version = 0x0001;
140 input_dev->dev.parent = &serio->dev;
141 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
142 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
143 input_set_abs_params(pinexio->dev, ABS_X, INEXIO_MIN_XC, INEXIO_MAX_XC, 0, 0);
144 input_set_abs_params(pinexio->dev, ABS_Y, INEXIO_MIN_YC, INEXIO_MAX_YC, 0, 0);
145
146 serio_set_drvdata(serio, pinexio);
147
148 err = serio_open(serio, drv);
149 if (err)
150 goto fail2;
151
152 err = input_register_device(pinexio->dev);
153 if (err)
154 goto fail3;
155
156 return 0;
157
158 fail3: serio_close(serio);
159 fail2: serio_set_drvdata(serio, NULL);
160 fail1: input_free_device(input_dev);
161 kfree(pinexio);
162 return err;
163}
164
165/*
166 * The serio driver structure.
167 */
168
169static struct serio_device_id inexio_serio_ids[] = {
170 {
171 .type = SERIO_RS232,
172 .proto = SERIO_INEXIO,
173 .id = SERIO_ANY,
174 .extra = SERIO_ANY,
175 },
176 { 0 }
177};
178
179MODULE_DEVICE_TABLE(serio, inexio_serio_ids);
180
181static struct serio_driver inexio_drv = {
182 .driver = {
183 .name = "inexio",
184 },
185 .description = DRIVER_DESC,
186 .id_table = inexio_serio_ids,
187 .interrupt = inexio_interrupt,
188 .connect = inexio_connect,
189 .disconnect = inexio_disconnect,
190};
191
192/*
193 * The functions for inserting/removing us as a module.
194 */
195
196static int __init inexio_init(void)
197{
198 return serio_register_driver(&inexio_drv);
199}
200
201static void __exit inexio_exit(void)
202{
203 serio_unregister_driver(&inexio_drv);
204}
205
206module_init(inexio_init);
207module_exit(inexio_exit);
diff --git a/drivers/input/touchscreen/migor_ts.c b/drivers/input/touchscreen/migor_ts.c
new file mode 100644
index 000000000000..c1cd99d58981
--- /dev/null
+++ b/drivers/input/touchscreen/migor_ts.c
@@ -0,0 +1,250 @@
1/*
2 * Touch Screen driver for Renesas MIGO-R Platform
3 *
4 * Copyright (c) 2008 Magnus Damm
5 * Copyright (c) 2007 Ujjwal Pande <ujjwal@kenati.com>,
6 * Kenati Technologies Pvt Ltd.
7 *
8 * This file is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This file is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/input.h>
25#include <linux/interrupt.h>
26#include <asm/io.h>
27#include <linux/i2c.h>
28#include <linux/timer.h>
29
30#define EVENT_PENDOWN 1
31#define EVENT_REPEAT 2
32#define EVENT_PENUP 3
33
34struct migor_ts_priv {
35 struct i2c_client *client;
36 struct input_dev *input;
37 struct delayed_work work;
38 int irq;
39};
40
41static const u_int8_t migor_ts_ena_seq[17] = { 0x33, 0x22, 0x11,
42 0x01, 0x06, 0x07, };
43static const u_int8_t migor_ts_dis_seq[17] = { };
44
45static void migor_ts_poscheck(struct work_struct *work)
46{
47 struct migor_ts_priv *priv = container_of(work,
48 struct migor_ts_priv,
49 work.work);
50 unsigned short xpos, ypos;
51 unsigned char event;
52 u_int8_t buf[16];
53
54 memset(buf, 0, sizeof(buf));
55
56 /* Set Index 0 */
57 buf[0] = 0;
58 if (i2c_master_send(priv->client, buf, 1) != 1) {
59 dev_err(&priv->client->dev, "Unable to write i2c index\n");
60 goto out;
61 }
62
63 /* Now do Page Read */
64 if (i2c_master_recv(priv->client, buf, sizeof(buf)) != sizeof(buf)) {
65 dev_err(&priv->client->dev, "Unable to read i2c page\n");
66 goto out;
67 }
68
69 ypos = ((buf[9] & 0x03) << 8 | buf[8]);
70 xpos = ((buf[11] & 0x03) << 8 | buf[10]);
71 event = buf[12];
72
73 if (event == EVENT_PENDOWN || event == EVENT_REPEAT) {
74 input_report_key(priv->input, BTN_TOUCH, 1);
75 input_report_abs(priv->input, ABS_X, ypos); /*X-Y swap*/
76 input_report_abs(priv->input, ABS_Y, xpos);
77 input_sync(priv->input);
78 } else if (event == EVENT_PENUP) {
79 input_report_key(priv->input, BTN_TOUCH, 0);
80 input_sync(priv->input);
81 }
82 out:
83 enable_irq(priv->irq);
84}
85
86static irqreturn_t migor_ts_isr(int irq, void *dev_id)
87{
88 struct migor_ts_priv *priv = dev_id;
89
90 /* the touch screen controller chip is hooked up to the cpu
91 * using i2c and a single interrupt line. the interrupt line
92 * is pulled low whenever someone taps the screen. to deassert
93 * the interrupt line we need to acknowledge the interrupt by
94 * communicating with the controller over the slow i2c bus.
95 *
96 * we can't acknowledge from interrupt context since the i2c
97 * bus controller may sleep, so we just disable the interrupt
98 * here and handle the acknowledge using delayed work.
99 */
100
101 disable_irq_nosync(irq);
102 schedule_delayed_work(&priv->work, HZ / 20);
103
104 return IRQ_HANDLED;
105}
106
107
108static int migor_ts_open(struct input_dev *dev)
109{
110 struct migor_ts_priv *priv = input_get_drvdata(dev);
111 struct i2c_client *client = priv->client;
112 int count;
113
114 /* enable controller */
115 count = i2c_master_send(client, migor_ts_ena_seq,
116 sizeof(migor_ts_ena_seq));
117 if (count != sizeof(migor_ts_ena_seq)) {
118 dev_err(&client->dev, "Unable to enable touchscreen.\n");
119 return -ENXIO;
120 }
121
122 return 0;
123}
124
125static void migor_ts_close(struct input_dev *dev)
126{
127 struct migor_ts_priv *priv = input_get_drvdata(dev);
128 struct i2c_client *client = priv->client;
129
130 disable_irq(priv->irq);
131
132 /* cancel pending work and wait for migor_ts_poscheck() to finish */
133 if (cancel_delayed_work_sync(&priv->work)) {
134 /*
135 * if migor_ts_poscheck was canceled we need to enable IRQ
136 * here to balance disable done in migor_ts_isr.
137 */
138 enable_irq(priv->irq);
139 }
140
141 /* disable controller */
142 i2c_master_send(client, migor_ts_dis_seq, sizeof(migor_ts_dis_seq));
143
144 enable_irq(priv->irq);
145}
146
147static int migor_ts_probe(struct i2c_client *client,
148 const struct i2c_device_id *idp)
149{
150 struct migor_ts_priv *priv;
151 struct input_dev *input;
152 int error;
153
154 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
155 if (!priv) {
156 dev_err(&client->dev, "failed to allocate driver data\n");
157 error = -ENOMEM;
158 goto err0;
159 }
160
161 dev_set_drvdata(&client->dev, priv);
162
163 input = input_allocate_device();
164 if (!input) {
165 dev_err(&client->dev, "Failed to allocate input device.\n");
166 error = -ENOMEM;
167 goto err1;
168 }
169
170 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
171 input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
172
173 input_set_abs_params(input, ABS_X, 95, 955, 0, 0);
174 input_set_abs_params(input, ABS_Y, 85, 935, 0, 0);
175
176 input->name = client->driver_name;
177 input->id.bustype = BUS_I2C;
178 input->dev.parent = &client->dev;
179
180 input->open = migor_ts_open;
181 input->close = migor_ts_close;
182
183 input_set_drvdata(input, priv);
184
185 priv->client = client;
186 priv->input = input;
187 INIT_DELAYED_WORK(&priv->work, migor_ts_poscheck);
188 priv->irq = client->irq;
189
190 error = input_register_device(input);
191 if (error)
192 goto err1;
193
194 error = request_irq(priv->irq, migor_ts_isr, IRQF_TRIGGER_LOW,
195 client->driver_name, priv);
196 if (error) {
197 dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
198 goto err2;
199 }
200
201 return 0;
202
203 err2:
204 input_unregister_device(input);
205 input = NULL; /* so we dont try to free it below */
206 err1:
207 input_free_device(input);
208 kfree(priv);
209 err0:
210 dev_set_drvdata(&client->dev, NULL);
211 return error;
212}
213
214static int migor_ts_remove(struct i2c_client *client)
215{
216 struct migor_ts_priv *priv = dev_get_drvdata(&client->dev);
217
218 free_irq(priv->irq, priv);
219 input_unregister_device(priv->input);
220 kfree(priv);
221
222 dev_set_drvdata(&client->dev, NULL);
223
224 return 0;
225}
226
227static struct i2c_driver migor_ts_driver = {
228 .driver = {
229 .name = "migor_ts",
230 },
231 .probe = migor_ts_probe,
232 .remove = migor_ts_remove,
233};
234
235static int __init migor_ts_init(void)
236{
237 return i2c_add_driver(&migor_ts_driver);
238}
239
240static void __exit migor_ts_exit(void)
241{
242 i2c_del_driver(&migor_ts_driver);
243}
244
245MODULE_DESCRIPTION("MigoR Touchscreen driver");
246MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
247MODULE_LICENSE("GPL");
248
249module_init(migor_ts_init);
250module_exit(migor_ts_exit);
diff --git a/drivers/input/touchscreen/touchit213.c b/drivers/input/touchscreen/touchit213.c
new file mode 100644
index 000000000000..d1297ba19daf
--- /dev/null
+++ b/drivers/input/touchscreen/touchit213.c
@@ -0,0 +1,234 @@
1/*
2 * Sahara TouchIT-213 serial touchscreen driver
3 *
4 * Copyright (c) 2007-2008 Claudio Nieder <private@claudio.ch>
5 *
6 * Based on Touchright driver (drivers/input/touchscreen/touchright.c)
7 * Copyright (c) 2006 Rick Koch <n1gp@hotmail.com>
8 * Copyright (c) 2004 Vojtech Pavlik
9 * and Dan Streetman <ddstreet@ieee.org>
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License version 2 as published
15 * by the Free Software Foundation.
16 */
17
18#include <linux/errno.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/slab.h>
22#include <linux/input.h>
23#include <linux/serio.h>
24#include <linux/init.h>
25
26#define DRIVER_DESC "Sahara TouchIT-213 serial touchscreen driver"
27
28MODULE_AUTHOR("Claudio Nieder <private@claudio.ch>");
29MODULE_DESCRIPTION(DRIVER_DESC);
30MODULE_LICENSE("GPL");
31
32/*
33 * Definitions & global arrays.
34 */
35
36/*
37 * Data is received through COM1 at 9600bit/s,8bit,no parity in packets
38 * of 5 byte each.
39 *
40 * +--------+ +--------+ +--------+ +--------+ +--------+
41 * |1000000p| |0xxxxxxx| |0xxxxxxx| |0yyyyyyy| |0yyyyyyy|
42 * +--------+ +--------+ +--------+ +--------+ +--------+
43 * MSB LSB MSB LSB
44 *
45 * The value of p is 1 as long as the screen is touched and 0 when
46 * reporting the location where touching stopped, e.g. where the pen was
47 * lifted from the screen.
48 *
49 * When holding the screen in landscape mode as the BIOS text output is
50 * presented, x is the horizontal axis with values growing from left to
51 * right and y is the vertical axis with values growing from top to
52 * bottom.
53 *
54 * When holding the screen in portrait mode with the Sahara logo in its
55 * correct position, x ist the vertical axis with values growing from
56 * top to bottom and y is the horizontal axis with values growing from
57 * right to left.
58 */
59
60#define T213_FORMAT_TOUCH_BIT 0x01
61#define T213_FORMAT_STATUS_BYTE 0x80
62#define T213_FORMAT_STATUS_MASK ~T213_FORMAT_TOUCH_BIT
63
64/*
65 * On my Sahara Touch-IT 213 I have observed x values from 0 to 0x7f0
66 * and y values from 0x1d to 0x7e9, so the actual measurement is
67 * probably done with an 11 bit precision.
68 */
69#define T213_MIN_XC 0
70#define T213_MAX_XC 0x07ff
71#define T213_MIN_YC 0
72#define T213_MAX_YC 0x07ff
73
74/*
75 * Per-touchscreen data.
76 */
77
78struct touchit213 {
79 struct input_dev *dev;
80 struct serio *serio;
81 int idx;
82 unsigned char csum;
83 unsigned char data[5];
84 char phys[32];
85};
86
87static irqreturn_t touchit213_interrupt(struct serio *serio,
88 unsigned char data, unsigned int flags)
89{
90 struct touchit213 *touchit213 = serio_get_drvdata(serio);
91 struct input_dev *dev = touchit213->dev;
92
93 touchit213->data[touchit213->idx] = data;
94
95 switch (touchit213->idx++) {
96 case 0:
97 if ((touchit213->data[0] & T213_FORMAT_STATUS_MASK) !=
98 T213_FORMAT_STATUS_BYTE) {
99 pr_debug("unsynchronized data: 0x%02x\n", data);
100 touchit213->idx = 0;
101 }
102 break;
103
104 case 4:
105 touchit213->idx = 0;
106 input_report_abs(dev, ABS_X,
107 (touchit213->data[1] << 7) | touchit213->data[2]);
108 input_report_abs(dev, ABS_Y,
109 (touchit213->data[3] << 7) | touchit213->data[4]);
110 input_report_key(dev, BTN_TOUCH,
111 touchit213->data[0] & T213_FORMAT_TOUCH_BIT);
112 input_sync(dev);
113 break;
114 }
115
116 return IRQ_HANDLED;
117}
118
119/*
120 * touchit213_disconnect() is the opposite of touchit213_connect()
121 */
122
123static void touchit213_disconnect(struct serio *serio)
124{
125 struct touchit213 *touchit213 = serio_get_drvdata(serio);
126
127 input_get_device(touchit213->dev);
128 input_unregister_device(touchit213->dev);
129 serio_close(serio);
130 serio_set_drvdata(serio, NULL);
131 input_put_device(touchit213->dev);
132 kfree(touchit213);
133}
134
135/*
136 * touchit213_connect() is the routine that is called when someone adds a
137 * new serio device that supports the Touchright protocol and registers it as
138 * an input device.
139 */
140
141static int touchit213_connect(struct serio *serio, struct serio_driver *drv)
142{
143 struct touchit213 *touchit213;
144 struct input_dev *input_dev;
145 int err;
146
147 touchit213 = kzalloc(sizeof(struct touchit213), GFP_KERNEL);
148 input_dev = input_allocate_device();
149 if (!touchit213 || !input_dev) {
150 err = -ENOMEM;
151 goto fail1;
152 }
153
154 touchit213->serio = serio;
155 touchit213->dev = input_dev;
156 snprintf(touchit213->phys, sizeof(touchit213->phys),
157 "%s/input0", serio->phys);
158
159 input_dev->name = "Sahara Touch-iT213 Serial TouchScreen";
160 input_dev->phys = touchit213->phys;
161 input_dev->id.bustype = BUS_RS232;
162 input_dev->id.vendor = SERIO_TOUCHIT213;
163 input_dev->id.product = 0;
164 input_dev->id.version = 0x0100;
165 input_dev->dev.parent = &serio->dev;
166 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
167 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
168 input_set_abs_params(touchit213->dev, ABS_X,
169 T213_MIN_XC, T213_MAX_XC, 0, 0);
170 input_set_abs_params(touchit213->dev, ABS_Y,
171 T213_MIN_YC, T213_MAX_YC, 0, 0);
172
173 serio_set_drvdata(serio, touchit213);
174
175 err = serio_open(serio, drv);
176 if (err)
177 goto fail2;
178
179 err = input_register_device(touchit213->dev);
180 if (err)
181 goto fail3;
182
183 return 0;
184
185 fail3: serio_close(serio);
186 fail2: serio_set_drvdata(serio, NULL);
187 fail1: input_free_device(input_dev);
188 kfree(touchit213);
189 return err;
190}
191
192/*
193 * The serio driver structure.
194 */
195
196static struct serio_device_id touchit213_serio_ids[] = {
197 {
198 .type = SERIO_RS232,
199 .proto = SERIO_TOUCHIT213,
200 .id = SERIO_ANY,
201 .extra = SERIO_ANY,
202 },
203 { 0 }
204};
205
206MODULE_DEVICE_TABLE(serio, touchit213_serio_ids);
207
208static struct serio_driver touchit213_drv = {
209 .driver = {
210 .name = "touchit213",
211 },
212 .description = DRIVER_DESC,
213 .id_table = touchit213_serio_ids,
214 .interrupt = touchit213_interrupt,
215 .connect = touchit213_connect,
216 .disconnect = touchit213_disconnect,
217};
218
219/*
220 * The functions for inserting/removing us as a module.
221 */
222
223static int __init touchit213_init(void)
224{
225 return serio_register_driver(&touchit213_drv);
226}
227
228static void __exit touchit213_exit(void)
229{
230 serio_unregister_driver(&touchit213_drv);
231}
232
233module_init(touchit213_init);
234module_exit(touchit213_exit);
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 3a0a8ca57076..fdd645c214a2 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -49,6 +49,7 @@
49#include <linux/init.h> 49#include <linux/init.h>
50#include <linux/usb.h> 50#include <linux/usb.h>
51#include <linux/usb/input.h> 51#include <linux/usb/input.h>
52#include <linux/hid.h>
52 53
53 54
54#define DRIVER_VERSION "v0.6" 55#define DRIVER_VERSION "v0.6"
@@ -101,7 +102,7 @@ struct usbtouch_usb {
101 102
102/* device types */ 103/* device types */
103enum { 104enum {
104 DEVTPYE_DUMMY = -1, 105 DEVTYPE_IGNORE = -1,
105 DEVTYPE_EGALAX, 106 DEVTYPE_EGALAX,
106 DEVTYPE_PANJIT, 107 DEVTYPE_PANJIT,
107 DEVTYPE_3M, 108 DEVTYPE_3M,
@@ -115,8 +116,21 @@ enum {
115 DEVTYPE_GOTOP, 116 DEVTYPE_GOTOP,
116}; 117};
117 118
119#define USB_DEVICE_HID_CLASS(vend, prod) \
120 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
121 | USB_DEVICE_ID_MATCH_DEVICE, \
122 .idVendor = (vend), \
123 .idProduct = (prod), \
124 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
125 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
126
118static struct usb_device_id usbtouch_devices[] = { 127static struct usb_device_id usbtouch_devices[] = {
119#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX 128#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
129 /* ignore the HID capable devices, handled by usbhid */
130 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
131 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE},
132
133 /* normal device IDs */
120 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX}, 134 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
121 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX}, 135 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
122 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX}, 136 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
@@ -262,7 +276,7 @@ static int mtouch_init(struct usbtouch_usb *usbtouch)
262 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 276 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
263 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); 277 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
264 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d", 278 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
265 __FUNCTION__, ret); 279 __func__, ret);
266 if (ret < 0) 280 if (ret < 0)
267 return ret; 281 return ret;
268 msleep(150); 282 msleep(150);
@@ -273,7 +287,7 @@ static int mtouch_init(struct usbtouch_usb *usbtouch)
273 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 287 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
274 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT); 288 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
275 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d", 289 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
276 __FUNCTION__, ret); 290 __func__, ret);
277 if (ret >= 0) 291 if (ret >= 0)
278 break; 292 break;
279 if (ret != -EPIPE) 293 if (ret != -EPIPE)
@@ -793,18 +807,18 @@ static void usbtouch_irq(struct urb *urb)
793 case -ETIME: 807 case -ETIME:
794 /* this urb is timing out */ 808 /* this urb is timing out */
795 dbg("%s - urb timed out - was the device unplugged?", 809 dbg("%s - urb timed out - was the device unplugged?",
796 __FUNCTION__); 810 __func__);
797 return; 811 return;
798 case -ECONNRESET: 812 case -ECONNRESET:
799 case -ENOENT: 813 case -ENOENT:
800 case -ESHUTDOWN: 814 case -ESHUTDOWN:
801 /* this urb is terminated, clean up */ 815 /* this urb is terminated, clean up */
802 dbg("%s - urb shutting down with status: %d", 816 dbg("%s - urb shutting down with status: %d",
803 __FUNCTION__, urb->status); 817 __func__, urb->status);
804 return; 818 return;
805 default: 819 default:
806 dbg("%s - nonzero urb status received: %d", 820 dbg("%s - nonzero urb status received: %d",
807 __FUNCTION__, urb->status); 821 __func__, urb->status);
808 goto exit; 822 goto exit;
809 } 823 }
810 824
@@ -814,7 +828,7 @@ exit:
814 retval = usb_submit_urb(urb, GFP_ATOMIC); 828 retval = usb_submit_urb(urb, GFP_ATOMIC);
815 if (retval) 829 if (retval)
816 err("%s - usb_submit_urb failed with result: %d", 830 err("%s - usb_submit_urb failed with result: %d",
817 __FUNCTION__, retval); 831 __func__, retval);
818} 832}
819 833
820static int usbtouch_open(struct input_dev *input) 834static int usbtouch_open(struct input_dev *input)
@@ -857,6 +871,10 @@ static int usbtouch_probe(struct usb_interface *intf,
857 struct usbtouch_device_info *type; 871 struct usbtouch_device_info *type;
858 int err = -ENOMEM; 872 int err = -ENOMEM;
859 873
874 /* some devices are ignored */
875 if (id->driver_info == DEVTYPE_IGNORE)
876 return -ENODEV;
877
860 interface = intf->cur_altsetting; 878 interface = intf->cur_altsetting;
861 endpoint = &interface->endpoint[0].desc; 879 endpoint = &interface->endpoint[0].desc;
862 880
@@ -883,7 +901,7 @@ static int usbtouch_probe(struct usb_interface *intf,
883 901
884 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL); 902 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
885 if (!usbtouch->irq) { 903 if (!usbtouch->irq) {
886 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __FUNCTION__); 904 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__);
887 goto out_free_buffers; 905 goto out_free_buffers;
888 } 906 }
889 907
@@ -939,14 +957,14 @@ static int usbtouch_probe(struct usb_interface *intf,
939 if (type->init) { 957 if (type->init) {
940 err = type->init(usbtouch); 958 err = type->init(usbtouch);
941 if (err) { 959 if (err) {
942 dbg("%s - type->init() failed, err: %d", __FUNCTION__, err); 960 dbg("%s - type->init() failed, err: %d", __func__, err);
943 goto out_free_buffers; 961 goto out_free_buffers;
944 } 962 }
945 } 963 }
946 964
947 err = input_register_device(usbtouch->input); 965 err = input_register_device(usbtouch->input);
948 if (err) { 966 if (err) {
949 dbg("%s - input_register_device failed, err: %d", __FUNCTION__, err); 967 dbg("%s - input_register_device failed, err: %d", __func__, err);
950 goto out_free_buffers; 968 goto out_free_buffers;
951 } 969 }
952 970
@@ -966,12 +984,12 @@ static void usbtouch_disconnect(struct usb_interface *intf)
966{ 984{
967 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); 985 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
968 986
969 dbg("%s - called", __FUNCTION__); 987 dbg("%s - called", __func__);
970 988
971 if (!usbtouch) 989 if (!usbtouch)
972 return; 990 return;
973 991
974 dbg("%s - usbtouch is initialized, cleaning up", __FUNCTION__); 992 dbg("%s - usbtouch is initialized, cleaning up", __func__);
975 usb_set_intfdata(intf, NULL); 993 usb_set_intfdata(intf, NULL);
976 usb_kill_urb(usbtouch->irq); 994 usb_kill_urb(usbtouch->irq);
977 input_unregister_device(usbtouch->input); 995 input_unregister_device(usbtouch->input);
diff --git a/drivers/input/touchscreen/wm9712.c b/drivers/input/touchscreen/wm9712.c
index 0b6e4cfa6a21..4c5d85a249ae 100644
--- a/drivers/input/touchscreen/wm9712.c
+++ b/drivers/input/touchscreen/wm9712.c
@@ -168,6 +168,18 @@ static void wm9712_phy_init(struct wm97xx *wm)
168 64000 / rpu); 168 64000 / rpu);
169 } 169 }
170 170
171 /* WM9712 five wire */
172 if (five_wire) {
173 dig2 |= WM9712_45W;
174 dev_dbg(wm->dev, "setting 5-wire touchscreen mode.");
175
176 if (pil) {
177 dev_warn(wm->dev, "pressure measurement is not "
178 "supported in 5-wire mode\n");
179 pil = 0;
180 }
181 }
182
171 /* touchpanel pressure current*/ 183 /* touchpanel pressure current*/
172 if (pil == 2) { 184 if (pil == 2) {
173 dig2 |= WM9712_PIL; 185 dig2 |= WM9712_PIL;
@@ -179,12 +191,6 @@ static void wm9712_phy_init(struct wm97xx *wm)
179 if (!pil) 191 if (!pil)
180 pressure = 0; 192 pressure = 0;
181 193
182 /* WM9712 five wire */
183 if (five_wire) {
184 dig2 |= WM9712_45W;
185 dev_dbg(wm->dev, "setting 5-wire touchscreen mode.");
186 }
187
188 /* polling mode sample settling delay */ 194 /* polling mode sample settling delay */
189 if (delay < 0 || delay > 15) { 195 if (delay < 0 || delay > 15) {
190 dev_dbg(wm->dev, "supplied delay out of range."); 196 dev_dbg(wm->dev, "supplied delay out of range.");
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 8a35029caca0..871b0cbca5e4 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1302,11 +1302,12 @@ static void capinc_tty_hangup(struct tty_struct *tty)
1302#endif 1302#endif
1303} 1303}
1304 1304
1305static void capinc_tty_break_ctl(struct tty_struct *tty, int state) 1305static int capinc_tty_break_ctl(struct tty_struct *tty, int state)
1306{ 1306{
1307#ifdef _DEBUG_TTYFUNCS 1307#ifdef _DEBUG_TTYFUNCS
1308 printk(KERN_DEBUG "capinc_tty_break_ctl(%d)\n", state); 1308 printk(KERN_DEBUG "capinc_tty_break_ctl(%d)\n", state);
1309#endif 1309#endif
1310 return 0;
1310} 1311}
1311 1312
1312static void capinc_tty_flush_buffer(struct tty_struct *tty) 1313static void capinc_tty_flush_buffer(struct tty_struct *tty)
@@ -1552,7 +1553,8 @@ static int __init capi_init(void)
1552 return PTR_ERR(capi_class); 1553 return PTR_ERR(capi_class);
1553 } 1554 }
1554 1555
1555 device_create(capi_class, NULL, MKDEV(capi_major, 0), "capi"); 1556 device_create_drvdata(capi_class, NULL, MKDEV(capi_major, 0), NULL,
1557 "capi");
1556 1558
1557#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE 1559#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1558 if (capinc_tty_init() < 0) { 1560 if (capinc_tty_init() < 0) {
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index e5d446804d32..cae52485208a 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -862,7 +862,8 @@ adbdev_init(void)
862 adb_dev_class = class_create(THIS_MODULE, "adb"); 862 adb_dev_class = class_create(THIS_MODULE, "adb");
863 if (IS_ERR(adb_dev_class)) 863 if (IS_ERR(adb_dev_class))
864 return; 864 return;
865 device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), "adb"); 865 device_create_drvdata(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL,
866 "adb");
866 867
867 platform_device_register(&adb_pfdev); 868 platform_device_register(&adb_pfdev);
868 platform_driver_probe(&adb_pfdrv, adb_dummy_probe); 869 platform_driver_probe(&adb_pfdrv, adb_dummy_probe);
diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c
index 59ea520a5d7a..5396c67ba0a4 100644
--- a/drivers/macintosh/adbhid.c
+++ b/drivers/macintosh/adbhid.c
@@ -219,11 +219,13 @@ struct adbhid {
219 int flags; 219 int flags;
220}; 220};
221 221
222#define FLAG_FN_KEY_PRESSED 0x00000001 222#define FLAG_FN_KEY_PRESSED 0x00000001
223#define FLAG_POWER_FROM_FN 0x00000002 223#define FLAG_POWER_FROM_FN 0x00000002
224#define FLAG_EMU_FWDEL_DOWN 0x00000004 224#define FLAG_EMU_FWDEL_DOWN 0x00000004
225#define FLAG_CAPSLOCK_TRANSLATE 0x00000008 225#define FLAG_CAPSLOCK_TRANSLATE 0x00000008
226#define FLAG_CAPSLOCK_DOWN 0x00000010 226#define FLAG_CAPSLOCK_DOWN 0x00000010
227#define FLAG_CAPSLOCK_IGNORE_NEXT 0x00000020
228#define FLAG_POWER_KEY_PRESSED 0x00000040
227 229
228static struct adbhid *adbhid[16]; 230static struct adbhid *adbhid[16];
229 231
@@ -291,11 +293,20 @@ adbhid_input_keycode(int id, int scancode, int repeat)
291 if (keycode == ADB_KEY_CAPSLOCK && !up_flag) { 293 if (keycode == ADB_KEY_CAPSLOCK && !up_flag) {
292 /* Key pressed, turning on the CapsLock LED. 294 /* Key pressed, turning on the CapsLock LED.
293 * The next 0xff will be interpreted as a release. */ 295 * The next 0xff will be interpreted as a release. */
294 ahid->flags |= FLAG_CAPSLOCK_TRANSLATE 296 if (ahid->flags & FLAG_CAPSLOCK_IGNORE_NEXT) {
297 /* Throw away this key event if it happens
298 * just after resume. */
299 ahid->flags &= ~FLAG_CAPSLOCK_IGNORE_NEXT;
300 return;
301 } else {
302 ahid->flags |= FLAG_CAPSLOCK_TRANSLATE
295 | FLAG_CAPSLOCK_DOWN; 303 | FLAG_CAPSLOCK_DOWN;
296 } else if (scancode == 0xff) { 304 }
305 } else if (scancode == 0xff &&
306 !(ahid->flags & FLAG_POWER_KEY_PRESSED)) {
297 /* Scancode 0xff usually signifies that the capslock 307 /* Scancode 0xff usually signifies that the capslock
298 * key was either pressed or released. */ 308 * key was either pressed or released, or that the
309 * power button was released. */
299 if (ahid->flags & FLAG_CAPSLOCK_TRANSLATE) { 310 if (ahid->flags & FLAG_CAPSLOCK_TRANSLATE) {
300 keycode = ADB_KEY_CAPSLOCK; 311 keycode = ADB_KEY_CAPSLOCK;
301 if (ahid->flags & FLAG_CAPSLOCK_DOWN) { 312 if (ahid->flags & FLAG_CAPSLOCK_DOWN) {
@@ -309,7 +320,7 @@ adbhid_input_keycode(int id, int scancode, int repeat)
309 } 320 }
310 } else { 321 } else {
311 printk(KERN_INFO "Spurious caps lock event " 322 printk(KERN_INFO "Spurious caps lock event "
312 "(scancode 0xff)."); 323 "(scancode 0xff).\n");
313 } 324 }
314 } 325 }
315 } 326 }
@@ -336,6 +347,12 @@ adbhid_input_keycode(int id, int scancode, int repeat)
336 } 347 }
337 break; 348 break;
338 case ADB_KEY_POWER: 349 case ADB_KEY_POWER:
350 /* Keep track of the power key state */
351 if (up_flag)
352 ahid->flags &= ~FLAG_POWER_KEY_PRESSED;
353 else
354 ahid->flags |= FLAG_POWER_KEY_PRESSED;
355
339 /* Fn + Command will produce a bogus "power" keycode */ 356 /* Fn + Command will produce a bogus "power" keycode */
340 if (ahid->flags & FLAG_FN_KEY_PRESSED) { 357 if (ahid->flags & FLAG_FN_KEY_PRESSED) {
341 keycode = ADB_KEY_CMD; 358 keycode = ADB_KEY_CMD;
@@ -681,6 +698,21 @@ static int adbhid_kbd_event(struct input_dev *dev, unsigned int type, unsigned i
681 return -1; 698 return -1;
682} 699}
683 700
701static void
702adbhid_kbd_capslock_remember(void)
703{
704 struct adbhid *ahid;
705 int i;
706
707 for (i = 1; i < 16; i++) {
708 ahid = adbhid[i];
709
710 if (ahid && ahid->id == ADB_KEYBOARD)
711 if (ahid->flags & FLAG_CAPSLOCK_TRANSLATE)
712 ahid->flags |= FLAG_CAPSLOCK_IGNORE_NEXT;
713 }
714}
715
684static int 716static int
685adb_message_handler(struct notifier_block *this, unsigned long code, void *x) 717adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
686{ 718{
@@ -697,8 +729,17 @@ adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
697 } 729 }
698 730
699 /* Stop pending led requests */ 731 /* Stop pending led requests */
700 while(leds_req_pending) 732 while (leds_req_pending)
701 adb_poll(); 733 adb_poll();
734
735 /* After resume, and if the capslock LED is on, the PMU will
736 * send a "capslock down" key event. This confuses the
737 * restore_capslock_events logic. Remember if the capslock
738 * LED was on before suspend so the unwanted key event can
739 * be ignored after resume. */
740 if (restore_capslock_events)
741 adbhid_kbd_capslock_remember();
742
702 break; 743 break;
703 744
704 case ADB_MSG_POST_RESET: 745 case ADB_MSG_POST_RESET:
diff --git a/drivers/mca/mca-bus.c b/drivers/mca/mca-bus.c
index 67b8e9453b19..ef2dbfe74714 100644
--- a/drivers/mca/mca-bus.c
+++ b/drivers/mca/mca-bus.c
@@ -40,7 +40,7 @@ static struct mca_bus *mca_root_busses[MAX_MCA_BUSSES];
40 40
41struct mca_device_info { 41struct mca_device_info {
42 short pos_id; /* the 2 byte pos id for this card */ 42 short pos_id; /* the 2 byte pos id for this card */
43 char name[DEVICE_NAME_SIZE]; 43 char name[50];
44}; 44};
45 45
46static int mca_bus_match (struct device *dev, struct device_driver *drv) 46static int mca_bus_match (struct device *dev, struct device_driver *drv)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index b26927ce889c..621a272a2c74 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -225,7 +225,7 @@ static struct page *read_sb_page(mddev_t *mddev, long offset, unsigned long inde
225 || test_bit(Faulty, &rdev->flags)) 225 || test_bit(Faulty, &rdev->flags))
226 continue; 226 continue;
227 227
228 target = (rdev->sb_offset << 1) + offset + index * (PAGE_SIZE/512); 228 target = rdev->sb_start + offset + index * (PAGE_SIZE/512);
229 229
230 if (sync_page_io(rdev->bdev, target, PAGE_SIZE, page, READ)) { 230 if (sync_page_io(rdev->bdev, target, PAGE_SIZE, page, READ)) {
231 page->index = index; 231 page->index = index;
@@ -241,10 +241,10 @@ static struct page *read_sb_page(mddev_t *mddev, long offset, unsigned long inde
241static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait) 241static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
242{ 242{
243 mdk_rdev_t *rdev; 243 mdk_rdev_t *rdev;
244 struct list_head *tmp;
245 mddev_t *mddev = bitmap->mddev; 244 mddev_t *mddev = bitmap->mddev;
246 245
247 rdev_for_each(rdev, tmp, mddev) 246 rcu_read_lock();
247 rdev_for_each_rcu(rdev, mddev)
248 if (test_bit(In_sync, &rdev->flags) 248 if (test_bit(In_sync, &rdev->flags)
249 && !test_bit(Faulty, &rdev->flags)) { 249 && !test_bit(Faulty, &rdev->flags)) {
250 int size = PAGE_SIZE; 250 int size = PAGE_SIZE;
@@ -260,32 +260,37 @@ static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
260 + (long)(page->index * (PAGE_SIZE/512)) 260 + (long)(page->index * (PAGE_SIZE/512))
261 + size/512 > 0) 261 + size/512 > 0)
262 /* bitmap runs in to metadata */ 262 /* bitmap runs in to metadata */
263 return -EINVAL; 263 goto bad_alignment;
264 if (rdev->data_offset + mddev->size*2 264 if (rdev->data_offset + mddev->size*2
265 > rdev->sb_offset*2 + bitmap->offset) 265 > rdev->sb_start + bitmap->offset)
266 /* data runs in to bitmap */ 266 /* data runs in to bitmap */
267 return -EINVAL; 267 goto bad_alignment;
268 } else if (rdev->sb_offset*2 < rdev->data_offset) { 268 } else if (rdev->sb_start < rdev->data_offset) {
269 /* METADATA BITMAP DATA */ 269 /* METADATA BITMAP DATA */
270 if (rdev->sb_offset*2 270 if (rdev->sb_start
271 + bitmap->offset 271 + bitmap->offset
272 + page->index*(PAGE_SIZE/512) + size/512 272 + page->index*(PAGE_SIZE/512) + size/512
273 > rdev->data_offset) 273 > rdev->data_offset)
274 /* bitmap runs in to data */ 274 /* bitmap runs in to data */
275 return -EINVAL; 275 goto bad_alignment;
276 } else { 276 } else {
277 /* DATA METADATA BITMAP - no problems */ 277 /* DATA METADATA BITMAP - no problems */
278 } 278 }
279 md_super_write(mddev, rdev, 279 md_super_write(mddev, rdev,
280 (rdev->sb_offset<<1) + bitmap->offset 280 rdev->sb_start + bitmap->offset
281 + page->index * (PAGE_SIZE/512), 281 + page->index * (PAGE_SIZE/512),
282 size, 282 size,
283 page); 283 page);
284 } 284 }
285 rcu_read_unlock();
285 286
286 if (wait) 287 if (wait)
287 md_super_wait(mddev); 288 md_super_wait(mddev);
288 return 0; 289 return 0;
290
291 bad_alignment:
292 rcu_read_unlock();
293 return -EINVAL;
289} 294}
290 295
291static void bitmap_file_kick(struct bitmap *bitmap); 296static void bitmap_file_kick(struct bitmap *bitmap);
@@ -454,8 +459,11 @@ void bitmap_update_sb(struct bitmap *bitmap)
454 spin_unlock_irqrestore(&bitmap->lock, flags); 459 spin_unlock_irqrestore(&bitmap->lock, flags);
455 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0); 460 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0);
456 sb->events = cpu_to_le64(bitmap->mddev->events); 461 sb->events = cpu_to_le64(bitmap->mddev->events);
457 if (!bitmap->mddev->degraded) 462 if (bitmap->mddev->events < bitmap->events_cleared) {
458 sb->events_cleared = cpu_to_le64(bitmap->mddev->events); 463 /* rocking back to read-only */
464 bitmap->events_cleared = bitmap->mddev->events;
465 sb->events_cleared = cpu_to_le64(bitmap->events_cleared);
466 }
459 kunmap_atomic(sb, KM_USER0); 467 kunmap_atomic(sb, KM_USER0);
460 write_page(bitmap, bitmap->sb_page, 1); 468 write_page(bitmap, bitmap->sb_page, 1);
461} 469}
@@ -1085,9 +1093,19 @@ void bitmap_daemon_work(struct bitmap *bitmap)
1085 } else 1093 } else
1086 spin_unlock_irqrestore(&bitmap->lock, flags); 1094 spin_unlock_irqrestore(&bitmap->lock, flags);
1087 lastpage = page; 1095 lastpage = page;
1088/* 1096
1089 printk("bitmap clean at page %lu\n", j); 1097 /* We are possibly going to clear some bits, so make
1090*/ 1098 * sure that events_cleared is up-to-date.
1099 */
1100 if (bitmap->need_sync) {
1101 bitmap_super_t *sb;
1102 bitmap->need_sync = 0;
1103 sb = kmap_atomic(bitmap->sb_page, KM_USER0);
1104 sb->events_cleared =
1105 cpu_to_le64(bitmap->events_cleared);
1106 kunmap_atomic(sb, KM_USER0);
1107 write_page(bitmap, bitmap->sb_page, 1);
1108 }
1091 spin_lock_irqsave(&bitmap->lock, flags); 1109 spin_lock_irqsave(&bitmap->lock, flags);
1092 clear_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); 1110 clear_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
1093 } 1111 }
@@ -1257,6 +1275,12 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto
1257 return; 1275 return;
1258 } 1276 }
1259 1277
1278 if (success &&
1279 bitmap->events_cleared < bitmap->mddev->events) {
1280 bitmap->events_cleared = bitmap->mddev->events;
1281 bitmap->need_sync = 1;
1282 }
1283
1260 if (!success && ! (*bmc & NEEDED_MASK)) 1284 if (!success && ! (*bmc & NEEDED_MASK))
1261 *bmc |= NEEDED_MASK; 1285 *bmc |= NEEDED_MASK;
1262 1286
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index ab6a61db63ce..13956437bc81 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1216,9 +1216,24 @@ error:
1216 return -EINVAL; 1216 return -EINVAL;
1217} 1217}
1218 1218
1219static int crypt_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
1220 struct bio_vec *biovec, int max_size)
1221{
1222 struct crypt_config *cc = ti->private;
1223 struct request_queue *q = bdev_get_queue(cc->dev->bdev);
1224
1225 if (!q->merge_bvec_fn)
1226 return max_size;
1227
1228 bvm->bi_bdev = cc->dev->bdev;
1229 bvm->bi_sector = cc->start + bvm->bi_sector - ti->begin;
1230
1231 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
1232}
1233
1219static struct target_type crypt_target = { 1234static struct target_type crypt_target = {
1220 .name = "crypt", 1235 .name = "crypt",
1221 .version= {1, 5, 0}, 1236 .version= {1, 6, 0},
1222 .module = THIS_MODULE, 1237 .module = THIS_MODULE,
1223 .ctr = crypt_ctr, 1238 .ctr = crypt_ctr,
1224 .dtr = crypt_dtr, 1239 .dtr = crypt_dtr,
@@ -1228,6 +1243,7 @@ static struct target_type crypt_target = {
1228 .preresume = crypt_preresume, 1243 .preresume = crypt_preresume,
1229 .resume = crypt_resume, 1244 .resume = crypt_resume,
1230 .message = crypt_message, 1245 .message = crypt_message,
1246 .merge = crypt_merge,
1231}; 1247};
1232 1248
1233static int __init dm_crypt_init(void) 1249static int __init dm_crypt_init(void)
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 17753d80ad22..6449bcdf84ca 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -69,13 +69,25 @@ static void linear_dtr(struct dm_target *ti)
69 kfree(lc); 69 kfree(lc);
70} 70}
71 71
72static int linear_map(struct dm_target *ti, struct bio *bio, 72static sector_t linear_map_sector(struct dm_target *ti, sector_t bi_sector)
73 union map_info *map_context)
74{ 73{
75 struct linear_c *lc = (struct linear_c *) ti->private; 74 struct linear_c *lc = ti->private;
75
76 return lc->start + (bi_sector - ti->begin);
77}
78
79static void linear_map_bio(struct dm_target *ti, struct bio *bio)
80{
81 struct linear_c *lc = ti->private;
76 82
77 bio->bi_bdev = lc->dev->bdev; 83 bio->bi_bdev = lc->dev->bdev;
78 bio->bi_sector = lc->start + (bio->bi_sector - ti->begin); 84 bio->bi_sector = linear_map_sector(ti, bio->bi_sector);
85}
86
87static int linear_map(struct dm_target *ti, struct bio *bio,
88 union map_info *map_context)
89{
90 linear_map_bio(ti, bio);
79 91
80 return DM_MAPIO_REMAPPED; 92 return DM_MAPIO_REMAPPED;
81} 93}
@@ -114,15 +126,31 @@ static int linear_ioctl(struct dm_target *ti, struct inode *inode,
114 return blkdev_driver_ioctl(bdev->bd_inode, &fake_file, bdev->bd_disk, cmd, arg); 126 return blkdev_driver_ioctl(bdev->bd_inode, &fake_file, bdev->bd_disk, cmd, arg);
115} 127}
116 128
129static int linear_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
130 struct bio_vec *biovec, int max_size)
131{
132 struct linear_c *lc = ti->private;
133 struct request_queue *q = bdev_get_queue(lc->dev->bdev);
134
135 if (!q->merge_bvec_fn)
136 return max_size;
137
138 bvm->bi_bdev = lc->dev->bdev;
139 bvm->bi_sector = linear_map_sector(ti, bvm->bi_sector);
140
141 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
142}
143
117static struct target_type linear_target = { 144static struct target_type linear_target = {
118 .name = "linear", 145 .name = "linear",
119 .version= {1, 0, 2}, 146 .version= {1, 0, 3},
120 .module = THIS_MODULE, 147 .module = THIS_MODULE,
121 .ctr = linear_ctr, 148 .ctr = linear_ctr,
122 .dtr = linear_dtr, 149 .dtr = linear_dtr,
123 .map = linear_map, 150 .map = linear_map,
124 .status = linear_status, 151 .status = linear_status,
125 .ioctl = linear_ioctl, 152 .ioctl = linear_ioctl,
153 .merge = linear_merge,
126}; 154};
127 155
128int __init dm_linear_init(void) 156int __init dm_linear_init(void)
diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c
index 67a6f31b7fc3..5b48478c79f5 100644
--- a/drivers/md/dm-log.c
+++ b/drivers/md/dm-log.c
@@ -831,7 +831,7 @@ static struct dm_dirty_log_type _disk_type = {
831 .status = disk_status, 831 .status = disk_status,
832}; 832};
833 833
834int __init dm_dirty_log_init(void) 834static int __init dm_dirty_log_init(void)
835{ 835{
836 int r; 836 int r;
837 837
@@ -848,7 +848,7 @@ int __init dm_dirty_log_init(void)
848 return r; 848 return r;
849} 849}
850 850
851void __exit dm_dirty_log_exit(void) 851static void __exit dm_dirty_log_exit(void)
852{ 852{
853 dm_dirty_log_type_unregister(&_disk_type); 853 dm_dirty_log_type_unregister(&_disk_type);
854 dm_dirty_log_type_unregister(&_core_type); 854 dm_dirty_log_type_unregister(&_core_type);
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 9f7302d4878d..fea966d66f98 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -525,8 +525,10 @@ static int parse_path_selector(struct arg_set *as, struct priority_group *pg,
525 } 525 }
526 526
527 r = read_param(_params, shift(as), &ps_argc, &ti->error); 527 r = read_param(_params, shift(as), &ps_argc, &ti->error);
528 if (r) 528 if (r) {
529 dm_put_path_selector(pst);
529 return -EINVAL; 530 return -EINVAL;
531 }
530 532
531 r = pst->create(&pg->ps, ps_argc, as->argv); 533 r = pst->create(&pg->ps, ps_argc, as->argv);
532 if (r) { 534 if (r) {
@@ -623,8 +625,10 @@ static struct priority_group *parse_priority_group(struct arg_set *as,
623 struct pgpath *pgpath; 625 struct pgpath *pgpath;
624 struct arg_set path_args; 626 struct arg_set path_args;
625 627
626 if (as->argc < nr_params) 628 if (as->argc < nr_params) {
629 ti->error = "not enough path parameters";
627 goto bad; 630 goto bad;
631 }
628 632
629 path_args.argc = nr_params; 633 path_args.argc = nr_params;
630 path_args.argv = as->argv; 634 path_args.argv = as->argv;
@@ -867,7 +871,7 @@ static int reinstate_path(struct pgpath *pgpath)
867 if (pgpath->path.is_active) 871 if (pgpath->path.is_active)
868 goto out; 872 goto out;
869 873
870 if (!pgpath->pg->ps.type) { 874 if (!pgpath->pg->ps.type->reinstate_path) {
871 DMWARN("Reinstate path not supported by path selector %s", 875 DMWARN("Reinstate path not supported by path selector %s",
872 pgpath->pg->ps.type->name); 876 pgpath->pg->ps.type->name);
873 r = -EINVAL; 877 r = -EINVAL;
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 1ba8a47d61b1..6e5528aecc98 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -40,6 +40,11 @@
40 */ 40 */
41#define SNAPSHOT_PAGES (((1UL << 20) >> PAGE_SHIFT) ? : 1) 41#define SNAPSHOT_PAGES (((1UL << 20) >> PAGE_SHIFT) ? : 1)
42 42
43/*
44 * The size of the mempool used to track chunks in use.
45 */
46#define MIN_IOS 256
47
43static struct workqueue_struct *ksnapd; 48static struct workqueue_struct *ksnapd;
44static void flush_queued_bios(struct work_struct *work); 49static void flush_queued_bios(struct work_struct *work);
45 50
@@ -91,7 +96,63 @@ struct dm_snap_pending_exception {
91 */ 96 */
92static struct kmem_cache *exception_cache; 97static struct kmem_cache *exception_cache;
93static struct kmem_cache *pending_cache; 98static struct kmem_cache *pending_cache;
94static mempool_t *pending_pool; 99
100struct dm_snap_tracked_chunk {
101 struct hlist_node node;
102 chunk_t chunk;
103};
104
105static struct kmem_cache *tracked_chunk_cache;
106
107static struct dm_snap_tracked_chunk *track_chunk(struct dm_snapshot *s,
108 chunk_t chunk)
109{
110 struct dm_snap_tracked_chunk *c = mempool_alloc(s->tracked_chunk_pool,
111 GFP_NOIO);
112 unsigned long flags;
113
114 c->chunk = chunk;
115
116 spin_lock_irqsave(&s->tracked_chunk_lock, flags);
117 hlist_add_head(&c->node,
118 &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)]);
119 spin_unlock_irqrestore(&s->tracked_chunk_lock, flags);
120
121 return c;
122}
123
124static void stop_tracking_chunk(struct dm_snapshot *s,
125 struct dm_snap_tracked_chunk *c)
126{
127 unsigned long flags;
128
129 spin_lock_irqsave(&s->tracked_chunk_lock, flags);
130 hlist_del(&c->node);
131 spin_unlock_irqrestore(&s->tracked_chunk_lock, flags);
132
133 mempool_free(c, s->tracked_chunk_pool);
134}
135
136static int __chunk_is_tracked(struct dm_snapshot *s, chunk_t chunk)
137{
138 struct dm_snap_tracked_chunk *c;
139 struct hlist_node *hn;
140 int found = 0;
141
142 spin_lock_irq(&s->tracked_chunk_lock);
143
144 hlist_for_each_entry(c, hn,
145 &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)], node) {
146 if (c->chunk == chunk) {
147 found = 1;
148 break;
149 }
150 }
151
152 spin_unlock_irq(&s->tracked_chunk_lock);
153
154 return found;
155}
95 156
96/* 157/*
97 * One of these per registered origin, held in the snapshot_origins hash 158 * One of these per registered origin, held in the snapshot_origins hash
@@ -302,14 +363,19 @@ static void free_exception(struct dm_snap_exception *e)
302 kmem_cache_free(exception_cache, e); 363 kmem_cache_free(exception_cache, e);
303} 364}
304 365
305static struct dm_snap_pending_exception *alloc_pending_exception(void) 366static struct dm_snap_pending_exception *alloc_pending_exception(struct dm_snapshot *s)
306{ 367{
307 return mempool_alloc(pending_pool, GFP_NOIO); 368 struct dm_snap_pending_exception *pe = mempool_alloc(s->pending_pool,
369 GFP_NOIO);
370
371 pe->snap = s;
372
373 return pe;
308} 374}
309 375
310static void free_pending_exception(struct dm_snap_pending_exception *pe) 376static void free_pending_exception(struct dm_snap_pending_exception *pe)
311{ 377{
312 mempool_free(pe, pending_pool); 378 mempool_free(pe, pe->snap->pending_pool);
313} 379}
314 380
315static void insert_completed_exception(struct dm_snapshot *s, 381static void insert_completed_exception(struct dm_snapshot *s,
@@ -482,6 +548,7 @@ static int set_chunk_size(struct dm_snapshot *s, const char *chunk_size_arg,
482static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) 548static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
483{ 549{
484 struct dm_snapshot *s; 550 struct dm_snapshot *s;
551 int i;
485 int r = -EINVAL; 552 int r = -EINVAL;
486 char persistent; 553 char persistent;
487 char *origin_path; 554 char *origin_path;
@@ -564,11 +631,30 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
564 goto bad5; 631 goto bad5;
565 } 632 }
566 633
634 s->pending_pool = mempool_create_slab_pool(MIN_IOS, pending_cache);
635 if (!s->pending_pool) {
636 ti->error = "Could not allocate mempool for pending exceptions";
637 goto bad6;
638 }
639
640 s->tracked_chunk_pool = mempool_create_slab_pool(MIN_IOS,
641 tracked_chunk_cache);
642 if (!s->tracked_chunk_pool) {
643 ti->error = "Could not allocate tracked_chunk mempool for "
644 "tracking reads";
645 goto bad_tracked_chunk_pool;
646 }
647
648 for (i = 0; i < DM_TRACKED_CHUNK_HASH_SIZE; i++)
649 INIT_HLIST_HEAD(&s->tracked_chunk_hash[i]);
650
651 spin_lock_init(&s->tracked_chunk_lock);
652
567 /* Metadata must only be loaded into one table at once */ 653 /* Metadata must only be loaded into one table at once */
568 r = s->store.read_metadata(&s->store); 654 r = s->store.read_metadata(&s->store);
569 if (r < 0) { 655 if (r < 0) {
570 ti->error = "Failed to read snapshot metadata"; 656 ti->error = "Failed to read snapshot metadata";
571 goto bad6; 657 goto bad_load_and_register;
572 } else if (r > 0) { 658 } else if (r > 0) {
573 s->valid = 0; 659 s->valid = 0;
574 DMWARN("Snapshot is marked invalid."); 660 DMWARN("Snapshot is marked invalid.");
@@ -582,7 +668,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
582 if (register_snapshot(s)) { 668 if (register_snapshot(s)) {
583 r = -EINVAL; 669 r = -EINVAL;
584 ti->error = "Cannot register snapshot origin"; 670 ti->error = "Cannot register snapshot origin";
585 goto bad6; 671 goto bad_load_and_register;
586 } 672 }
587 673
588 ti->private = s; 674 ti->private = s;
@@ -590,6 +676,12 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
590 676
591 return 0; 677 return 0;
592 678
679 bad_load_and_register:
680 mempool_destroy(s->tracked_chunk_pool);
681
682 bad_tracked_chunk_pool:
683 mempool_destroy(s->pending_pool);
684
593 bad6: 685 bad6:
594 dm_kcopyd_client_destroy(s->kcopyd_client); 686 dm_kcopyd_client_destroy(s->kcopyd_client);
595 687
@@ -624,6 +716,9 @@ static void __free_exceptions(struct dm_snapshot *s)
624 716
625static void snapshot_dtr(struct dm_target *ti) 717static void snapshot_dtr(struct dm_target *ti)
626{ 718{
719#ifdef CONFIG_DM_DEBUG
720 int i;
721#endif
627 struct dm_snapshot *s = ti->private; 722 struct dm_snapshot *s = ti->private;
628 723
629 flush_workqueue(ksnapd); 724 flush_workqueue(ksnapd);
@@ -632,8 +727,17 @@ static void snapshot_dtr(struct dm_target *ti)
632 /* After this returns there can be no new kcopyd jobs. */ 727 /* After this returns there can be no new kcopyd jobs. */
633 unregister_snapshot(s); 728 unregister_snapshot(s);
634 729
730#ifdef CONFIG_DM_DEBUG
731 for (i = 0; i < DM_TRACKED_CHUNK_HASH_SIZE; i++)
732 BUG_ON(!hlist_empty(&s->tracked_chunk_hash[i]));
733#endif
734
735 mempool_destroy(s->tracked_chunk_pool);
736
635 __free_exceptions(s); 737 __free_exceptions(s);
636 738
739 mempool_destroy(s->pending_pool);
740
637 dm_put_device(ti, s->origin); 741 dm_put_device(ti, s->origin);
638 dm_put_device(ti, s->cow); 742 dm_put_device(ti, s->cow);
639 743
@@ -772,6 +876,13 @@ static void pending_complete(struct dm_snap_pending_exception *pe, int success)
772 } 876 }
773 877
774 /* 878 /*
879 * Check for conflicting reads. This is extremely improbable,
880 * so yield() is sufficient and there is no need for a wait queue.
881 */
882 while (__chunk_is_tracked(s, pe->e.old_chunk))
883 yield();
884
885 /*
775 * Add a proper exception, and remove the 886 * Add a proper exception, and remove the
776 * in-flight exception from the list. 887 * in-flight exception from the list.
777 */ 888 */
@@ -873,7 +984,7 @@ __find_pending_exception(struct dm_snapshot *s, struct bio *bio)
873 * to hold the lock while we do this. 984 * to hold the lock while we do this.
874 */ 985 */
875 up_write(&s->lock); 986 up_write(&s->lock);
876 pe = alloc_pending_exception(); 987 pe = alloc_pending_exception(s);
877 down_write(&s->lock); 988 down_write(&s->lock);
878 989
879 if (!s->valid) { 990 if (!s->valid) {
@@ -893,7 +1004,6 @@ __find_pending_exception(struct dm_snapshot *s, struct bio *bio)
893 bio_list_init(&pe->snapshot_bios); 1004 bio_list_init(&pe->snapshot_bios);
894 pe->primary_pe = NULL; 1005 pe->primary_pe = NULL;
895 atomic_set(&pe->ref_count, 0); 1006 atomic_set(&pe->ref_count, 0);
896 pe->snap = s;
897 pe->started = 0; 1007 pe->started = 0;
898 1008
899 if (s->store.prepare_exception(&s->store, &pe->e)) { 1009 if (s->store.prepare_exception(&s->store, &pe->e)) {
@@ -974,14 +1084,10 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
974 start_copy(pe); 1084 start_copy(pe);
975 goto out; 1085 goto out;
976 } 1086 }
977 } else 1087 } else {
978 /*
979 * FIXME: this read path scares me because we
980 * always use the origin when we have a pending
981 * exception. However I can't think of a
982 * situation where this is wrong - ejt.
983 */
984 bio->bi_bdev = s->origin->bdev; 1088 bio->bi_bdev = s->origin->bdev;
1089 map_context->ptr = track_chunk(s, chunk);
1090 }
985 1091
986 out_unlock: 1092 out_unlock:
987 up_write(&s->lock); 1093 up_write(&s->lock);
@@ -989,6 +1095,18 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
989 return r; 1095 return r;
990} 1096}
991 1097
1098static int snapshot_end_io(struct dm_target *ti, struct bio *bio,
1099 int error, union map_info *map_context)
1100{
1101 struct dm_snapshot *s = ti->private;
1102 struct dm_snap_tracked_chunk *c = map_context->ptr;
1103
1104 if (c)
1105 stop_tracking_chunk(s, c);
1106
1107 return 0;
1108}
1109
992static void snapshot_resume(struct dm_target *ti) 1110static void snapshot_resume(struct dm_target *ti)
993{ 1111{
994 struct dm_snapshot *s = ti->private; 1112 struct dm_snapshot *s = ti->private;
@@ -1266,6 +1384,7 @@ static struct target_type snapshot_target = {
1266 .ctr = snapshot_ctr, 1384 .ctr = snapshot_ctr,
1267 .dtr = snapshot_dtr, 1385 .dtr = snapshot_dtr,
1268 .map = snapshot_map, 1386 .map = snapshot_map,
1387 .end_io = snapshot_end_io,
1269 .resume = snapshot_resume, 1388 .resume = snapshot_resume,
1270 .status = snapshot_status, 1389 .status = snapshot_status,
1271}; 1390};
@@ -1306,9 +1425,9 @@ static int __init dm_snapshot_init(void)
1306 goto bad4; 1425 goto bad4;
1307 } 1426 }
1308 1427
1309 pending_pool = mempool_create_slab_pool(128, pending_cache); 1428 tracked_chunk_cache = KMEM_CACHE(dm_snap_tracked_chunk, 0);
1310 if (!pending_pool) { 1429 if (!tracked_chunk_cache) {
1311 DMERR("Couldn't create pending pool."); 1430 DMERR("Couldn't create cache to track chunks in use.");
1312 r = -ENOMEM; 1431 r = -ENOMEM;
1313 goto bad5; 1432 goto bad5;
1314 } 1433 }
@@ -1317,13 +1436,13 @@ static int __init dm_snapshot_init(void)
1317 if (!ksnapd) { 1436 if (!ksnapd) {
1318 DMERR("Failed to create ksnapd workqueue."); 1437 DMERR("Failed to create ksnapd workqueue.");
1319 r = -ENOMEM; 1438 r = -ENOMEM;
1320 goto bad6; 1439 goto bad_pending_pool;
1321 } 1440 }
1322 1441
1323 return 0; 1442 return 0;
1324 1443
1325 bad6: 1444 bad_pending_pool:
1326 mempool_destroy(pending_pool); 1445 kmem_cache_destroy(tracked_chunk_cache);
1327 bad5: 1446 bad5:
1328 kmem_cache_destroy(pending_cache); 1447 kmem_cache_destroy(pending_cache);
1329 bad4: 1448 bad4:
@@ -1352,9 +1471,9 @@ static void __exit dm_snapshot_exit(void)
1352 DMERR("origin unregister failed %d", r); 1471 DMERR("origin unregister failed %d", r);
1353 1472
1354 exit_origin_hash(); 1473 exit_origin_hash();
1355 mempool_destroy(pending_pool);
1356 kmem_cache_destroy(pending_cache); 1474 kmem_cache_destroy(pending_cache);
1357 kmem_cache_destroy(exception_cache); 1475 kmem_cache_destroy(exception_cache);
1476 kmem_cache_destroy(tracked_chunk_cache);
1358} 1477}
1359 1478
1360/* Module hooks */ 1479/* Module hooks */
diff --git a/drivers/md/dm-snap.h b/drivers/md/dm-snap.h
index 24f9fb73b982..292c15609ae3 100644
--- a/drivers/md/dm-snap.h
+++ b/drivers/md/dm-snap.h
@@ -130,6 +130,10 @@ struct exception_store {
130 void *context; 130 void *context;
131}; 131};
132 132
133#define DM_TRACKED_CHUNK_HASH_SIZE 16
134#define DM_TRACKED_CHUNK_HASH(x) ((unsigned long)(x) & \
135 (DM_TRACKED_CHUNK_HASH_SIZE - 1))
136
133struct dm_snapshot { 137struct dm_snapshot {
134 struct rw_semaphore lock; 138 struct rw_semaphore lock;
135 struct dm_target *ti; 139 struct dm_target *ti;
@@ -157,6 +161,8 @@ struct dm_snapshot {
157 /* The last percentage we notified */ 161 /* The last percentage we notified */
158 int last_percent; 162 int last_percent;
159 163
164 mempool_t *pending_pool;
165
160 struct exception_table pending; 166 struct exception_table pending;
161 struct exception_table complete; 167 struct exception_table complete;
162 168
@@ -174,6 +180,11 @@ struct dm_snapshot {
174 /* Queue of snapshot writes for ksnapd to flush */ 180 /* Queue of snapshot writes for ksnapd to flush */
175 struct bio_list queued_bios; 181 struct bio_list queued_bios;
176 struct work_struct queued_bios_work; 182 struct work_struct queued_bios_work;
183
184 /* Chunks with outstanding reads */
185 mempool_t *tracked_chunk_pool;
186 spinlock_t tracked_chunk_lock;
187 struct hlist_head tracked_chunk_hash[DM_TRACKED_CHUNK_HASH_SIZE];
177}; 188};
178 189
179/* 190/*
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 94116eaf4709..798e468103b8 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -506,14 +506,13 @@ void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev)
506 rs->max_sectors = 506 rs->max_sectors =
507 min_not_zero(rs->max_sectors, q->max_sectors); 507 min_not_zero(rs->max_sectors, q->max_sectors);
508 508
509 /* FIXME: Device-Mapper on top of RAID-0 breaks because DM 509 /*
510 * currently doesn't honor MD's merge_bvec_fn routine. 510 * Check if merge fn is supported.
511 * In this case, we'll force DM to use PAGE_SIZE or 511 * If not we'll force DM to use PAGE_SIZE or
512 * smaller I/O, just to be safe. A better fix is in the 512 * smaller I/O, just to be safe.
513 * works, but add this for the time being so it will at
514 * least operate correctly.
515 */ 513 */
516 if (q->merge_bvec_fn) 514
515 if (q->merge_bvec_fn && !ti->type->merge)
517 rs->max_sectors = 516 rs->max_sectors =
518 min_not_zero(rs->max_sectors, 517 min_not_zero(rs->max_sectors,
519 (unsigned int) (PAGE_SIZE >> 9)); 518 (unsigned int) (PAGE_SIZE >> 9));
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 372369b1cc20..bca448e11878 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -37,8 +37,8 @@ static DEFINE_SPINLOCK(_minor_lock);
37struct dm_io { 37struct dm_io {
38 struct mapped_device *md; 38 struct mapped_device *md;
39 int error; 39 int error;
40 struct bio *bio;
41 atomic_t io_count; 40 atomic_t io_count;
41 struct bio *bio;
42 unsigned long start_time; 42 unsigned long start_time;
43}; 43};
44 44
@@ -829,6 +829,49 @@ static int __split_bio(struct mapped_device *md, struct bio *bio)
829 * CRUD END 829 * CRUD END
830 *---------------------------------------------------------------*/ 830 *---------------------------------------------------------------*/
831 831
832static int dm_merge_bvec(struct request_queue *q,
833 struct bvec_merge_data *bvm,
834 struct bio_vec *biovec)
835{
836 struct mapped_device *md = q->queuedata;
837 struct dm_table *map = dm_get_table(md);
838 struct dm_target *ti;
839 sector_t max_sectors;
840 int max_size;
841
842 if (unlikely(!map))
843 return 0;
844
845 ti = dm_table_find_target(map, bvm->bi_sector);
846
847 /*
848 * Find maximum amount of I/O that won't need splitting
849 */
850 max_sectors = min(max_io_len(md, bvm->bi_sector, ti),
851 (sector_t) BIO_MAX_SECTORS);
852 max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size;
853 if (max_size < 0)
854 max_size = 0;
855
856 /*
857 * merge_bvec_fn() returns number of bytes
858 * it can accept at this offset
859 * max is precomputed maximal io size
860 */
861 if (max_size && ti->type->merge)
862 max_size = ti->type->merge(ti, bvm, biovec, max_size);
863
864 /*
865 * Always allow an entire first page
866 */
867 if (max_size <= biovec->bv_len && !(bvm->bi_size >> SECTOR_SHIFT))
868 max_size = biovec->bv_len;
869
870 dm_table_put(map);
871
872 return max_size;
873}
874
832/* 875/*
833 * The request function that just remaps the bio built up by 876 * The request function that just remaps the bio built up by
834 * dm_merge_bvec. 877 * dm_merge_bvec.
@@ -1032,6 +1075,7 @@ static struct mapped_device *alloc_dev(int minor)
1032 blk_queue_make_request(md->queue, dm_request); 1075 blk_queue_make_request(md->queue, dm_request);
1033 blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY); 1076 blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
1034 md->queue->unplug_fn = dm_unplug_all; 1077 md->queue->unplug_fn = dm_unplug_all;
1078 blk_queue_merge_bvec(md->queue, dm_merge_bvec);
1035 1079
1036 md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache); 1080 md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache);
1037 if (!md->io_pool) 1081 if (!md->io_pool)
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index 8c03b634e62e..1e59a0b0a78a 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -100,12 +100,6 @@ int dm_lock_for_deletion(struct mapped_device *md);
100 100
101void dm_kobject_uevent(struct mapped_device *md); 101void dm_kobject_uevent(struct mapped_device *md);
102 102
103/*
104 * Dirty log
105 */
106int dm_dirty_log_init(void);
107void dm_dirty_log_exit(void);
108
109int dm_kcopyd_init(void); 103int dm_kcopyd_init(void);
110void dm_kcopyd_exit(void); 104void dm_kcopyd_exit(void);
111 105
diff --git a/drivers/md/faulty.c b/drivers/md/faulty.c
index d107ddceefcd..268547dbfbd3 100644
--- a/drivers/md/faulty.c
+++ b/drivers/md/faulty.c
@@ -297,7 +297,7 @@ static int run(mddev_t *mddev)
297 rdev_for_each(rdev, tmp, mddev) 297 rdev_for_each(rdev, tmp, mddev)
298 conf->rdev = rdev; 298 conf->rdev = rdev;
299 299
300 mddev->array_size = mddev->size; 300 mddev->array_sectors = mddev->size * 2;
301 mddev->private = conf; 301 mddev->private = conf;
302 302
303 reconfig(mddev, mddev->layout, -1); 303 reconfig(mddev, mddev->layout, -1);
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index 6a866d7c8ae5..b1eebf88c209 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -122,13 +122,13 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
122 return NULL; 122 return NULL;
123 123
124 cnt = 0; 124 cnt = 0;
125 conf->array_size = 0; 125 conf->array_sectors = 0;
126 126
127 rdev_for_each(rdev, tmp, mddev) { 127 rdev_for_each(rdev, tmp, mddev) {
128 int j = rdev->raid_disk; 128 int j = rdev->raid_disk;
129 dev_info_t *disk = conf->disks + j; 129 dev_info_t *disk = conf->disks + j;
130 130
131 if (j < 0 || j > raid_disks || disk->rdev) { 131 if (j < 0 || j >= raid_disks || disk->rdev) {
132 printk("linear: disk numbering problem. Aborting!\n"); 132 printk("linear: disk numbering problem. Aborting!\n");
133 goto out; 133 goto out;
134 } 134 }
@@ -146,7 +146,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
146 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); 146 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
147 147
148 disk->size = rdev->size; 148 disk->size = rdev->size;
149 conf->array_size += rdev->size; 149 conf->array_sectors += rdev->size * 2;
150 150
151 cnt++; 151 cnt++;
152 } 152 }
@@ -155,7 +155,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
155 goto out; 155 goto out;
156 } 156 }
157 157
158 min_spacing = conf->array_size; 158 min_spacing = conf->array_sectors / 2;
159 sector_div(min_spacing, PAGE_SIZE/sizeof(struct dev_info *)); 159 sector_div(min_spacing, PAGE_SIZE/sizeof(struct dev_info *));
160 160
161 /* min_spacing is the minimum spacing that will fit the hash 161 /* min_spacing is the minimum spacing that will fit the hash
@@ -164,7 +164,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
164 * that is larger than min_spacing as use the size of that as 164 * that is larger than min_spacing as use the size of that as
165 * the actual spacing 165 * the actual spacing
166 */ 166 */
167 conf->hash_spacing = conf->array_size; 167 conf->hash_spacing = conf->array_sectors / 2;
168 for (i=0; i < cnt-1 ; i++) { 168 for (i=0; i < cnt-1 ; i++) {
169 sector_t sz = 0; 169 sector_t sz = 0;
170 int j; 170 int j;
@@ -194,7 +194,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
194 unsigned round; 194 unsigned round;
195 unsigned long base; 195 unsigned long base;
196 196
197 sz = conf->array_size >> conf->preshift; 197 sz = conf->array_sectors >> (conf->preshift + 1);
198 sz += 1; /* force round-up */ 198 sz += 1; /* force round-up */
199 base = conf->hash_spacing >> conf->preshift; 199 base = conf->hash_spacing >> conf->preshift;
200 round = sector_div(sz, base); 200 round = sector_div(sz, base);
@@ -221,7 +221,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
221 curr_offset = 0; 221 curr_offset = 0;
222 i = 0; 222 i = 0;
223 for (curr_offset = 0; 223 for (curr_offset = 0;
224 curr_offset < conf->array_size; 224 curr_offset < conf->array_sectors / 2;
225 curr_offset += conf->hash_spacing) { 225 curr_offset += conf->hash_spacing) {
226 226
227 while (i < raid_disks-1 && 227 while (i < raid_disks-1 &&
@@ -258,7 +258,7 @@ static int linear_run (mddev_t *mddev)
258 if (!conf) 258 if (!conf)
259 return 1; 259 return 1;
260 mddev->private = conf; 260 mddev->private = conf;
261 mddev->array_size = conf->array_size; 261 mddev->array_sectors = conf->array_sectors;
262 262
263 blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec); 263 blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec);
264 mddev->queue->unplug_fn = linear_unplug; 264 mddev->queue->unplug_fn = linear_unplug;
@@ -292,8 +292,8 @@ static int linear_add(mddev_t *mddev, mdk_rdev_t *rdev)
292 newconf->prev = mddev_to_conf(mddev); 292 newconf->prev = mddev_to_conf(mddev);
293 mddev->private = newconf; 293 mddev->private = newconf;
294 mddev->raid_disks++; 294 mddev->raid_disks++;
295 mddev->array_size = newconf->array_size; 295 mddev->array_sectors = newconf->array_sectors;
296 set_capacity(mddev->gendisk, mddev->array_size << 1); 296 set_capacity(mddev->gendisk, mddev->array_sectors);
297 return 0; 297 return 0;
298} 298}
299 299
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 2580ac1b9b0f..c2ff77ccec50 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -169,7 +169,6 @@ void md_new_event(mddev_t *mddev)
169{ 169{
170 atomic_inc(&md_event_count); 170 atomic_inc(&md_event_count);
171 wake_up(&md_event_waiters); 171 wake_up(&md_event_waiters);
172 sysfs_notify(&mddev->kobj, NULL, "sync_action");
173} 172}
174EXPORT_SYMBOL_GPL(md_new_event); 173EXPORT_SYMBOL_GPL(md_new_event);
175 174
@@ -274,10 +273,12 @@ static mddev_t * mddev_find(dev_t unit)
274 INIT_LIST_HEAD(&new->all_mddevs); 273 INIT_LIST_HEAD(&new->all_mddevs);
275 init_timer(&new->safemode_timer); 274 init_timer(&new->safemode_timer);
276 atomic_set(&new->active, 1); 275 atomic_set(&new->active, 1);
276 atomic_set(&new->openers, 0);
277 spin_lock_init(&new->write_lock); 277 spin_lock_init(&new->write_lock);
278 init_waitqueue_head(&new->sb_wait); 278 init_waitqueue_head(&new->sb_wait);
279 init_waitqueue_head(&new->recovery_wait); 279 init_waitqueue_head(&new->recovery_wait);
280 new->reshape_position = MaxSector; 280 new->reshape_position = MaxSector;
281 new->resync_min = 0;
281 new->resync_max = MaxSector; 282 new->resync_max = MaxSector;
282 new->level = LEVEL_NONE; 283 new->level = LEVEL_NONE;
283 284
@@ -347,21 +348,20 @@ static struct mdk_personality *find_pers(int level, char *clevel)
347 return NULL; 348 return NULL;
348} 349}
349 350
351/* return the offset of the super block in 512byte sectors */
350static inline sector_t calc_dev_sboffset(struct block_device *bdev) 352static inline sector_t calc_dev_sboffset(struct block_device *bdev)
351{ 353{
352 sector_t size = bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; 354 sector_t num_sectors = bdev->bd_inode->i_size / 512;
353 return MD_NEW_SIZE_BLOCKS(size); 355 return MD_NEW_SIZE_SECTORS(num_sectors);
354} 356}
355 357
356static sector_t calc_dev_size(mdk_rdev_t *rdev, unsigned chunk_size) 358static sector_t calc_num_sectors(mdk_rdev_t *rdev, unsigned chunk_size)
357{ 359{
358 sector_t size; 360 sector_t num_sectors = rdev->sb_start;
359
360 size = rdev->sb_offset;
361 361
362 if (chunk_size) 362 if (chunk_size)
363 size &= ~((sector_t)chunk_size/1024 - 1); 363 num_sectors &= ~((sector_t)chunk_size/512 - 1);
364 return size; 364 return num_sectors;
365} 365}
366 366
367static int alloc_disk_sb(mdk_rdev_t * rdev) 367static int alloc_disk_sb(mdk_rdev_t * rdev)
@@ -372,7 +372,7 @@ static int alloc_disk_sb(mdk_rdev_t * rdev)
372 rdev->sb_page = alloc_page(GFP_KERNEL); 372 rdev->sb_page = alloc_page(GFP_KERNEL);
373 if (!rdev->sb_page) { 373 if (!rdev->sb_page) {
374 printk(KERN_ALERT "md: out of memory.\n"); 374 printk(KERN_ALERT "md: out of memory.\n");
375 return -EINVAL; 375 return -ENOMEM;
376 } 376 }
377 377
378 return 0; 378 return 0;
@@ -384,7 +384,7 @@ static void free_disk_sb(mdk_rdev_t * rdev)
384 put_page(rdev->sb_page); 384 put_page(rdev->sb_page);
385 rdev->sb_loaded = 0; 385 rdev->sb_loaded = 0;
386 rdev->sb_page = NULL; 386 rdev->sb_page = NULL;
387 rdev->sb_offset = 0; 387 rdev->sb_start = 0;
388 rdev->size = 0; 388 rdev->size = 0;
389 } 389 }
390} 390}
@@ -530,7 +530,7 @@ static int read_disk_sb(mdk_rdev_t * rdev, int size)
530 return 0; 530 return 0;
531 531
532 532
533 if (!sync_page_io(rdev->bdev, rdev->sb_offset<<1, size, rdev->sb_page, READ)) 533 if (!sync_page_io(rdev->bdev, rdev->sb_start, size, rdev->sb_page, READ))
534 goto fail; 534 goto fail;
535 rdev->sb_loaded = 1; 535 rdev->sb_loaded = 1;
536 return 0; 536 return 0;
@@ -543,17 +543,12 @@ fail:
543 543
544static int uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2) 544static int uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2)
545{ 545{
546 if ( (sb1->set_uuid0 == sb2->set_uuid0) && 546 return sb1->set_uuid0 == sb2->set_uuid0 &&
547 (sb1->set_uuid1 == sb2->set_uuid1) && 547 sb1->set_uuid1 == sb2->set_uuid1 &&
548 (sb1->set_uuid2 == sb2->set_uuid2) && 548 sb1->set_uuid2 == sb2->set_uuid2 &&
549 (sb1->set_uuid3 == sb2->set_uuid3)) 549 sb1->set_uuid3 == sb2->set_uuid3;
550
551 return 1;
552
553 return 0;
554} 550}
555 551
556
557static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2) 552static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2)
558{ 553{
559 int ret; 554 int ret;
@@ -564,7 +559,7 @@ static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2)
564 559
565 if (!tmp1 || !tmp2) { 560 if (!tmp1 || !tmp2) {
566 ret = 0; 561 ret = 0;
567 printk(KERN_INFO "md.c: sb1 is not equal to sb2!\n"); 562 printk(KERN_INFO "md.c sb_equal(): failed to allocate memory!\n");
568 goto abort; 563 goto abort;
569 } 564 }
570 565
@@ -577,11 +572,7 @@ static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2)
577 tmp1->nr_disks = 0; 572 tmp1->nr_disks = 0;
578 tmp2->nr_disks = 0; 573 tmp2->nr_disks = 0;
579 574
580 if (memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4)) 575 ret = (memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4) == 0);
581 ret = 0;
582 else
583 ret = 1;
584
585abort: 576abort:
586 kfree(tmp1); 577 kfree(tmp1);
587 kfree(tmp2); 578 kfree(tmp2);
@@ -658,11 +649,14 @@ static unsigned int calc_sb_csum(mdp_super_t * sb)
658 */ 649 */
659 650
660struct super_type { 651struct super_type {
661 char *name; 652 char *name;
662 struct module *owner; 653 struct module *owner;
663 int (*load_super)(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version); 654 int (*load_super)(mdk_rdev_t *rdev, mdk_rdev_t *refdev,
664 int (*validate_super)(mddev_t *mddev, mdk_rdev_t *rdev); 655 int minor_version);
665 void (*sync_super)(mddev_t *mddev, mdk_rdev_t *rdev); 656 int (*validate_super)(mddev_t *mddev, mdk_rdev_t *rdev);
657 void (*sync_super)(mddev_t *mddev, mdk_rdev_t *rdev);
658 unsigned long long (*rdev_size_change)(mdk_rdev_t *rdev,
659 sector_t num_sectors);
666}; 660};
667 661
668/* 662/*
@@ -673,16 +667,14 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
673 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; 667 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
674 mdp_super_t *sb; 668 mdp_super_t *sb;
675 int ret; 669 int ret;
676 sector_t sb_offset;
677 670
678 /* 671 /*
679 * Calculate the position of the superblock, 672 * Calculate the position of the superblock (512byte sectors),
680 * it's at the end of the disk. 673 * it's at the end of the disk.
681 * 674 *
682 * It also happens to be a multiple of 4Kb. 675 * It also happens to be a multiple of 4Kb.
683 */ 676 */
684 sb_offset = calc_dev_sboffset(rdev->bdev); 677 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
685 rdev->sb_offset = sb_offset;
686 678
687 ret = read_disk_sb(rdev, MD_SB_BYTES); 679 ret = read_disk_sb(rdev, MD_SB_BYTES);
688 if (ret) return ret; 680 if (ret) return ret;
@@ -759,7 +751,7 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
759 else 751 else
760 ret = 0; 752 ret = 0;
761 } 753 }
762 rdev->size = calc_dev_size(rdev, sb->chunk_size); 754 rdev->size = calc_num_sectors(rdev, sb->chunk_size) / 2;
763 755
764 if (rdev->size < sb->size && sb->level > 1) 756 if (rdev->size < sb->size && sb->level > 1)
765 /* "this cannot possibly happen" ... */ 757 /* "this cannot possibly happen" ... */
@@ -1004,6 +996,26 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
1004} 996}
1005 997
1006/* 998/*
999 * rdev_size_change for 0.90.0
1000 */
1001static unsigned long long
1002super_90_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
1003{
1004 if (num_sectors && num_sectors < rdev->mddev->size * 2)
1005 return 0; /* component must fit device */
1006 if (rdev->mddev->bitmap_offset)
1007 return 0; /* can't move bitmap */
1008 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
1009 if (!num_sectors || num_sectors > rdev->sb_start)
1010 num_sectors = rdev->sb_start;
1011 md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size,
1012 rdev->sb_page);
1013 md_super_wait(rdev->mddev);
1014 return num_sectors / 2; /* kB for sysfs */
1015}
1016
1017
1018/*
1007 * version 1 superblock 1019 * version 1 superblock
1008 */ 1020 */
1009 1021
@@ -1034,12 +1046,12 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1034{ 1046{
1035 struct mdp_superblock_1 *sb; 1047 struct mdp_superblock_1 *sb;
1036 int ret; 1048 int ret;
1037 sector_t sb_offset; 1049 sector_t sb_start;
1038 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; 1050 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
1039 int bmask; 1051 int bmask;
1040 1052
1041 /* 1053 /*
1042 * Calculate the position of the superblock. 1054 * Calculate the position of the superblock in 512byte sectors.
1043 * It is always aligned to a 4K boundary and 1055 * It is always aligned to a 4K boundary and
1044 * depeding on minor_version, it can be: 1056 * depeding on minor_version, it can be:
1045 * 0: At least 8K, but less than 12K, from end of device 1057 * 0: At least 8K, but less than 12K, from end of device
@@ -1048,22 +1060,20 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1048 */ 1060 */
1049 switch(minor_version) { 1061 switch(minor_version) {
1050 case 0: 1062 case 0:
1051 sb_offset = rdev->bdev->bd_inode->i_size >> 9; 1063 sb_start = rdev->bdev->bd_inode->i_size >> 9;
1052 sb_offset -= 8*2; 1064 sb_start -= 8*2;
1053 sb_offset &= ~(sector_t)(4*2-1); 1065 sb_start &= ~(sector_t)(4*2-1);
1054 /* convert from sectors to K */
1055 sb_offset /= 2;
1056 break; 1066 break;
1057 case 1: 1067 case 1:
1058 sb_offset = 0; 1068 sb_start = 0;
1059 break; 1069 break;
1060 case 2: 1070 case 2:
1061 sb_offset = 4; 1071 sb_start = 8;
1062 break; 1072 break;
1063 default: 1073 default:
1064 return -EINVAL; 1074 return -EINVAL;
1065 } 1075 }
1066 rdev->sb_offset = sb_offset; 1076 rdev->sb_start = sb_start;
1067 1077
1068 /* superblock is rarely larger than 1K, but it can be larger, 1078 /* superblock is rarely larger than 1K, but it can be larger,
1069 * and it is safe to read 4k, so we do that 1079 * and it is safe to read 4k, so we do that
@@ -1077,7 +1087,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1077 if (sb->magic != cpu_to_le32(MD_SB_MAGIC) || 1087 if (sb->magic != cpu_to_le32(MD_SB_MAGIC) ||
1078 sb->major_version != cpu_to_le32(1) || 1088 sb->major_version != cpu_to_le32(1) ||
1079 le32_to_cpu(sb->max_dev) > (4096-256)/2 || 1089 le32_to_cpu(sb->max_dev) > (4096-256)/2 ||
1080 le64_to_cpu(sb->super_offset) != (rdev->sb_offset<<1) || 1090 le64_to_cpu(sb->super_offset) != rdev->sb_start ||
1081 (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0) 1091 (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0)
1082 return -EINVAL; 1092 return -EINVAL;
1083 1093
@@ -1113,7 +1123,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1113 rdev->sb_size = (rdev->sb_size | bmask) + 1; 1123 rdev->sb_size = (rdev->sb_size | bmask) + 1;
1114 1124
1115 if (minor_version 1125 if (minor_version
1116 && rdev->data_offset < sb_offset + (rdev->sb_size/512)) 1126 && rdev->data_offset < sb_start + (rdev->sb_size/512))
1117 return -EINVAL; 1127 return -EINVAL;
1118 1128
1119 if (sb->level == cpu_to_le32(LEVEL_MULTIPATH)) 1129 if (sb->level == cpu_to_le32(LEVEL_MULTIPATH))
@@ -1149,7 +1159,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1149 if (minor_version) 1159 if (minor_version)
1150 rdev->size = ((rdev->bdev->bd_inode->i_size>>9) - le64_to_cpu(sb->data_offset)) / 2; 1160 rdev->size = ((rdev->bdev->bd_inode->i_size>>9) - le64_to_cpu(sb->data_offset)) / 2;
1151 else 1161 else
1152 rdev->size = rdev->sb_offset; 1162 rdev->size = rdev->sb_start / 2;
1153 if (rdev->size < le64_to_cpu(sb->data_size)/2) 1163 if (rdev->size < le64_to_cpu(sb->data_size)/2)
1154 return -EINVAL; 1164 return -EINVAL;
1155 rdev->size = le64_to_cpu(sb->data_size)/2; 1165 rdev->size = le64_to_cpu(sb->data_size)/2;
@@ -1328,35 +1338,74 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
1328 sb->sb_csum = calc_sb_1_csum(sb); 1338 sb->sb_csum = calc_sb_1_csum(sb);
1329} 1339}
1330 1340
1341static unsigned long long
1342super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
1343{
1344 struct mdp_superblock_1 *sb;
1345 sector_t max_sectors;
1346 if (num_sectors && num_sectors < rdev->mddev->size * 2)
1347 return 0; /* component must fit device */
1348 if (rdev->sb_start < rdev->data_offset) {
1349 /* minor versions 1 and 2; superblock before data */
1350 max_sectors = rdev->bdev->bd_inode->i_size >> 9;
1351 max_sectors -= rdev->data_offset;
1352 if (!num_sectors || num_sectors > max_sectors)
1353 num_sectors = max_sectors;
1354 } else if (rdev->mddev->bitmap_offset) {
1355 /* minor version 0 with bitmap we can't move */
1356 return 0;
1357 } else {
1358 /* minor version 0; superblock after data */
1359 sector_t sb_start;
1360 sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2;
1361 sb_start &= ~(sector_t)(4*2 - 1);
1362 max_sectors = rdev->size * 2 + sb_start - rdev->sb_start;
1363 if (!num_sectors || num_sectors > max_sectors)
1364 num_sectors = max_sectors;
1365 rdev->sb_start = sb_start;
1366 }
1367 sb = (struct mdp_superblock_1 *) page_address(rdev->sb_page);
1368 sb->data_size = cpu_to_le64(num_sectors);
1369 sb->super_offset = rdev->sb_start;
1370 sb->sb_csum = calc_sb_1_csum(sb);
1371 md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size,
1372 rdev->sb_page);
1373 md_super_wait(rdev->mddev);
1374 return num_sectors / 2; /* kB for sysfs */
1375}
1331 1376
1332static struct super_type super_types[] = { 1377static struct super_type super_types[] = {
1333 [0] = { 1378 [0] = {
1334 .name = "0.90.0", 1379 .name = "0.90.0",
1335 .owner = THIS_MODULE, 1380 .owner = THIS_MODULE,
1336 .load_super = super_90_load, 1381 .load_super = super_90_load,
1337 .validate_super = super_90_validate, 1382 .validate_super = super_90_validate,
1338 .sync_super = super_90_sync, 1383 .sync_super = super_90_sync,
1384 .rdev_size_change = super_90_rdev_size_change,
1339 }, 1385 },
1340 [1] = { 1386 [1] = {
1341 .name = "md-1", 1387 .name = "md-1",
1342 .owner = THIS_MODULE, 1388 .owner = THIS_MODULE,
1343 .load_super = super_1_load, 1389 .load_super = super_1_load,
1344 .validate_super = super_1_validate, 1390 .validate_super = super_1_validate,
1345 .sync_super = super_1_sync, 1391 .sync_super = super_1_sync,
1392 .rdev_size_change = super_1_rdev_size_change,
1346 }, 1393 },
1347}; 1394};
1348 1395
1349static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2) 1396static int match_mddev_units(mddev_t *mddev1, mddev_t *mddev2)
1350{ 1397{
1351 struct list_head *tmp, *tmp2;
1352 mdk_rdev_t *rdev, *rdev2; 1398 mdk_rdev_t *rdev, *rdev2;
1353 1399
1354 rdev_for_each(rdev, tmp, mddev1) 1400 rcu_read_lock();
1355 rdev_for_each(rdev2, tmp2, mddev2) 1401 rdev_for_each_rcu(rdev, mddev1)
1402 rdev_for_each_rcu(rdev2, mddev2)
1356 if (rdev->bdev->bd_contains == 1403 if (rdev->bdev->bd_contains ==
1357 rdev2->bdev->bd_contains) 1404 rdev2->bdev->bd_contains) {
1405 rcu_read_unlock();
1358 return 1; 1406 return 1;
1359 1407 }
1408 rcu_read_unlock();
1360 return 0; 1409 return 0;
1361} 1410}
1362 1411
@@ -1423,7 +1472,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1423 kobject_del(&rdev->kobj); 1472 kobject_del(&rdev->kobj);
1424 goto fail; 1473 goto fail;
1425 } 1474 }
1426 list_add(&rdev->same_set, &mddev->disks); 1475 list_add_rcu(&rdev->same_set, &mddev->disks);
1427 bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); 1476 bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk);
1428 return 0; 1477 return 0;
1429 1478
@@ -1448,14 +1497,16 @@ static void unbind_rdev_from_array(mdk_rdev_t * rdev)
1448 return; 1497 return;
1449 } 1498 }
1450 bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk); 1499 bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk);
1451 list_del_init(&rdev->same_set); 1500 list_del_rcu(&rdev->same_set);
1452 printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); 1501 printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b));
1453 rdev->mddev = NULL; 1502 rdev->mddev = NULL;
1454 sysfs_remove_link(&rdev->kobj, "block"); 1503 sysfs_remove_link(&rdev->kobj, "block");
1455 1504
1456 /* We need to delay this, otherwise we can deadlock when 1505 /* We need to delay this, otherwise we can deadlock when
1457 * writing to 'remove' to "dev/state" 1506 * writing to 'remove' to "dev/state". We also need
1507 * to delay it due to rcu usage.
1458 */ 1508 */
1509 synchronize_rcu();
1459 INIT_WORK(&rdev->del_work, md_delayed_delete); 1510 INIT_WORK(&rdev->del_work, md_delayed_delete);
1460 kobject_get(&rdev->kobj); 1511 kobject_get(&rdev->kobj);
1461 schedule_work(&rdev->del_work); 1512 schedule_work(&rdev->del_work);
@@ -1511,7 +1562,6 @@ static void export_rdev(mdk_rdev_t * rdev)
1511 if (rdev->mddev) 1562 if (rdev->mddev)
1512 MD_BUG(); 1563 MD_BUG();
1513 free_disk_sb(rdev); 1564 free_disk_sb(rdev);
1514 list_del_init(&rdev->same_set);
1515#ifndef MODULE 1565#ifndef MODULE
1516 if (test_bit(AutoDetected, &rdev->flags)) 1566 if (test_bit(AutoDetected, &rdev->flags))
1517 md_autodetect_dev(rdev->bdev->bd_dev); 1567 md_autodetect_dev(rdev->bdev->bd_dev);
@@ -1758,11 +1808,11 @@ repeat:
1758 dprintk("%s ", bdevname(rdev->bdev,b)); 1808 dprintk("%s ", bdevname(rdev->bdev,b));
1759 if (!test_bit(Faulty, &rdev->flags)) { 1809 if (!test_bit(Faulty, &rdev->flags)) {
1760 md_super_write(mddev,rdev, 1810 md_super_write(mddev,rdev,
1761 rdev->sb_offset<<1, rdev->sb_size, 1811 rdev->sb_start, rdev->sb_size,
1762 rdev->sb_page); 1812 rdev->sb_page);
1763 dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", 1813 dprintk(KERN_INFO "(write) %s's sb offset: %llu\n",
1764 bdevname(rdev->bdev,b), 1814 bdevname(rdev->bdev,b),
1765 (unsigned long long)rdev->sb_offset); 1815 (unsigned long long)rdev->sb_start);
1766 rdev->sb_events = mddev->events; 1816 rdev->sb_events = mddev->events;
1767 1817
1768 } else 1818 } else
@@ -1787,7 +1837,7 @@ repeat:
1787 1837
1788} 1838}
1789 1839
1790/* words written to sysfs files may, or my not, be \n terminated. 1840/* words written to sysfs files may, or may not, be \n terminated.
1791 * We want to accept with case. For this we use cmd_match. 1841 * We want to accept with case. For this we use cmd_match.
1792 */ 1842 */
1793static int cmd_match(const char *cmd, const char *str) 1843static int cmd_match(const char *cmd, const char *str)
@@ -1886,6 +1936,8 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1886 1936
1887 err = 0; 1937 err = 0;
1888 } 1938 }
1939 if (!err)
1940 sysfs_notify(&rdev->kobj, NULL, "state");
1889 return err ? err : len; 1941 return err ? err : len;
1890} 1942}
1891static struct rdev_sysfs_entry rdev_state = 1943static struct rdev_sysfs_entry rdev_state =
@@ -1931,7 +1983,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1931 slot = -1; 1983 slot = -1;
1932 else if (e==buf || (*e && *e!= '\n')) 1984 else if (e==buf || (*e && *e!= '\n'))
1933 return -EINVAL; 1985 return -EINVAL;
1934 if (rdev->mddev->pers) { 1986 if (rdev->mddev->pers && slot == -1) {
1935 /* Setting 'slot' on an active array requires also 1987 /* Setting 'slot' on an active array requires also
1936 * updating the 'rd%d' link, and communicating 1988 * updating the 'rd%d' link, and communicating
1937 * with the personality with ->hot_*_disk. 1989 * with the personality with ->hot_*_disk.
@@ -1939,8 +1991,6 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1939 * failed/spare devices. This normally happens automatically, 1991 * failed/spare devices. This normally happens automatically,
1940 * but not when the metadata is externally managed. 1992 * but not when the metadata is externally managed.
1941 */ 1993 */
1942 if (slot != -1)
1943 return -EBUSY;
1944 if (rdev->raid_disk == -1) 1994 if (rdev->raid_disk == -1)
1945 return -EEXIST; 1995 return -EEXIST;
1946 /* personality does all needed checks */ 1996 /* personality does all needed checks */
@@ -1954,6 +2004,43 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1954 sysfs_remove_link(&rdev->mddev->kobj, nm); 2004 sysfs_remove_link(&rdev->mddev->kobj, nm);
1955 set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); 2005 set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
1956 md_wakeup_thread(rdev->mddev->thread); 2006 md_wakeup_thread(rdev->mddev->thread);
2007 } else if (rdev->mddev->pers) {
2008 mdk_rdev_t *rdev2;
2009 struct list_head *tmp;
2010 /* Activating a spare .. or possibly reactivating
2011 * if we every get bitmaps working here.
2012 */
2013
2014 if (rdev->raid_disk != -1)
2015 return -EBUSY;
2016
2017 if (rdev->mddev->pers->hot_add_disk == NULL)
2018 return -EINVAL;
2019
2020 rdev_for_each(rdev2, tmp, rdev->mddev)
2021 if (rdev2->raid_disk == slot)
2022 return -EEXIST;
2023
2024 rdev->raid_disk = slot;
2025 if (test_bit(In_sync, &rdev->flags))
2026 rdev->saved_raid_disk = slot;
2027 else
2028 rdev->saved_raid_disk = -1;
2029 err = rdev->mddev->pers->
2030 hot_add_disk(rdev->mddev, rdev);
2031 if (err) {
2032 rdev->raid_disk = -1;
2033 return err;
2034 } else
2035 sysfs_notify(&rdev->kobj, NULL, "state");
2036 sprintf(nm, "rd%d", rdev->raid_disk);
2037 if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm))
2038 printk(KERN_WARNING
2039 "md: cannot register "
2040 "%s for %s\n",
2041 nm, mdname(rdev->mddev));
2042
2043 /* don't wakeup anyone, leave that to userspace. */
1957 } else { 2044 } else {
1958 if (slot >= rdev->mddev->raid_disks) 2045 if (slot >= rdev->mddev->raid_disks)
1959 return -ENOSPC; 2046 return -ENOSPC;
@@ -1962,6 +2049,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1962 clear_bit(Faulty, &rdev->flags); 2049 clear_bit(Faulty, &rdev->flags);
1963 clear_bit(WriteMostly, &rdev->flags); 2050 clear_bit(WriteMostly, &rdev->flags);
1964 set_bit(In_sync, &rdev->flags); 2051 set_bit(In_sync, &rdev->flags);
2052 sysfs_notify(&rdev->kobj, NULL, "state");
1965 } 2053 }
1966 return len; 2054 return len;
1967} 2055}
@@ -1983,7 +2071,7 @@ offset_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1983 unsigned long long offset = simple_strtoull(buf, &e, 10); 2071 unsigned long long offset = simple_strtoull(buf, &e, 10);
1984 if (e==buf || (*e && *e != '\n')) 2072 if (e==buf || (*e && *e != '\n'))
1985 return -EINVAL; 2073 return -EINVAL;
1986 if (rdev->mddev->pers) 2074 if (rdev->mddev->pers && rdev->raid_disk >= 0)
1987 return -EBUSY; 2075 return -EBUSY;
1988 if (rdev->size && rdev->mddev->external) 2076 if (rdev->size && rdev->mddev->external)
1989 /* Must set offset before size, so overlap checks 2077 /* Must set offset before size, so overlap checks
@@ -2015,17 +2103,30 @@ static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2)
2015static ssize_t 2103static ssize_t
2016rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) 2104rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2017{ 2105{
2018 char *e; 2106 unsigned long long size;
2019 unsigned long long size = simple_strtoull(buf, &e, 10);
2020 unsigned long long oldsize = rdev->size; 2107 unsigned long long oldsize = rdev->size;
2021 mddev_t *my_mddev = rdev->mddev; 2108 mddev_t *my_mddev = rdev->mddev;
2022 2109
2023 if (e==buf || (*e && *e != '\n')) 2110 if (strict_strtoull(buf, 10, &size) < 0)
2024 return -EINVAL; 2111 return -EINVAL;
2025 if (my_mddev->pers) 2112 if (size < my_mddev->size)
2026 return -EBUSY; 2113 return -EINVAL;
2114 if (my_mddev->pers && rdev->raid_disk >= 0) {
2115 if (my_mddev->persistent) {
2116 size = super_types[my_mddev->major_version].
2117 rdev_size_change(rdev, size * 2);
2118 if (!size)
2119 return -EBUSY;
2120 } else if (!size) {
2121 size = (rdev->bdev->bd_inode->i_size >> 10);
2122 size -= rdev->data_offset/2;
2123 }
2124 if (size < my_mddev->size)
2125 return -EINVAL; /* component must fit device */
2126 }
2127
2027 rdev->size = size; 2128 rdev->size = size;
2028 if (size > oldsize && rdev->mddev->external) { 2129 if (size > oldsize && my_mddev->external) {
2029 /* need to check that all other rdevs with the same ->bdev 2130 /* need to check that all other rdevs with the same ->bdev
2030 * do not overlap. We need to unlock the mddev to avoid 2131 * do not overlap. We need to unlock the mddev to avoid
2031 * a deadlock. We have already changed rdev->size, and if 2132 * a deadlock. We have already changed rdev->size, and if
@@ -2044,8 +2145,9 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2044 if (test_bit(AllReserved, &rdev2->flags) || 2145 if (test_bit(AllReserved, &rdev2->flags) ||
2045 (rdev->bdev == rdev2->bdev && 2146 (rdev->bdev == rdev2->bdev &&
2046 rdev != rdev2 && 2147 rdev != rdev2 &&
2047 overlaps(rdev->data_offset, rdev->size, 2148 overlaps(rdev->data_offset, rdev->size * 2,
2048 rdev2->data_offset, rdev2->size))) { 2149 rdev2->data_offset,
2150 rdev2->size * 2))) {
2049 overlap = 1; 2151 overlap = 1;
2050 break; 2152 break;
2051 } 2153 }
@@ -2067,8 +2169,6 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2067 return -EBUSY; 2169 return -EBUSY;
2068 } 2170 }
2069 } 2171 }
2070 if (size < my_mddev->size || my_mddev->size == 0)
2071 my_mddev->size = size;
2072 return len; 2172 return len;
2073} 2173}
2074 2174
@@ -2512,7 +2612,7 @@ __ATTR(resync_start, S_IRUGO|S_IWUSR, resync_start_show, resync_start_store);
2512 * When written, doesn't tear down array, but just stops it 2612 * When written, doesn't tear down array, but just stops it
2513 * suspended (not supported yet) 2613 * suspended (not supported yet)
2514 * All IO requests will block. The array can be reconfigured. 2614 * All IO requests will block. The array can be reconfigured.
2515 * Writing this, if accepted, will block until array is quiessent 2615 * Writing this, if accepted, will block until array is quiescent
2516 * readonly 2616 * readonly
2517 * no resync can happen. no superblocks get written. 2617 * no resync can happen. no superblocks get written.
2518 * write requests fail 2618 * write requests fail
@@ -2585,7 +2685,7 @@ array_state_show(mddev_t *mddev, char *page)
2585 return sprintf(page, "%s\n", array_states[st]); 2685 return sprintf(page, "%s\n", array_states[st]);
2586} 2686}
2587 2687
2588static int do_md_stop(mddev_t * mddev, int ro); 2688static int do_md_stop(mddev_t * mddev, int ro, int is_open);
2589static int do_md_run(mddev_t * mddev); 2689static int do_md_run(mddev_t * mddev);
2590static int restart_array(mddev_t *mddev); 2690static int restart_array(mddev_t *mddev);
2591 2691
@@ -2599,16 +2699,16 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2599 break; 2699 break;
2600 case clear: 2700 case clear:
2601 /* stopping an active array */ 2701 /* stopping an active array */
2602 if (atomic_read(&mddev->active) > 1) 2702 if (atomic_read(&mddev->openers) > 0)
2603 return -EBUSY; 2703 return -EBUSY;
2604 err = do_md_stop(mddev, 0); 2704 err = do_md_stop(mddev, 0, 0);
2605 break; 2705 break;
2606 case inactive: 2706 case inactive:
2607 /* stopping an active array */ 2707 /* stopping an active array */
2608 if (mddev->pers) { 2708 if (mddev->pers) {
2609 if (atomic_read(&mddev->active) > 1) 2709 if (atomic_read(&mddev->openers) > 0)
2610 return -EBUSY; 2710 return -EBUSY;
2611 err = do_md_stop(mddev, 2); 2711 err = do_md_stop(mddev, 2, 0);
2612 } else 2712 } else
2613 err = 0; /* already inactive */ 2713 err = 0; /* already inactive */
2614 break; 2714 break;
@@ -2616,7 +2716,7 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2616 break; /* not supported yet */ 2716 break; /* not supported yet */
2617 case readonly: 2717 case readonly:
2618 if (mddev->pers) 2718 if (mddev->pers)
2619 err = do_md_stop(mddev, 1); 2719 err = do_md_stop(mddev, 1, 0);
2620 else { 2720 else {
2621 mddev->ro = 1; 2721 mddev->ro = 1;
2622 set_disk_ro(mddev->gendisk, 1); 2722 set_disk_ro(mddev->gendisk, 1);
@@ -2626,7 +2726,7 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2626 case read_auto: 2726 case read_auto:
2627 if (mddev->pers) { 2727 if (mddev->pers) {
2628 if (mddev->ro != 1) 2728 if (mddev->ro != 1)
2629 err = do_md_stop(mddev, 1); 2729 err = do_md_stop(mddev, 1, 0);
2630 else 2730 else
2631 err = restart_array(mddev); 2731 err = restart_array(mddev);
2632 if (err == 0) { 2732 if (err == 0) {
@@ -2681,8 +2781,10 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2681 } 2781 }
2682 if (err) 2782 if (err)
2683 return err; 2783 return err;
2684 else 2784 else {
2785 sysfs_notify(&mddev->kobj, NULL, "array_state");
2685 return len; 2786 return len;
2787 }
2686} 2788}
2687static struct md_sysfs_entry md_array_state = 2789static struct md_sysfs_entry md_array_state =
2688__ATTR(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_store); 2790__ATTR(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_store);
@@ -2785,7 +2887,7 @@ size_show(mddev_t *mddev, char *page)
2785 return sprintf(page, "%llu\n", (unsigned long long)mddev->size); 2887 return sprintf(page, "%llu\n", (unsigned long long)mddev->size);
2786} 2888}
2787 2889
2788static int update_size(mddev_t *mddev, unsigned long size); 2890static int update_size(mddev_t *mddev, sector_t num_sectors);
2789 2891
2790static ssize_t 2892static ssize_t
2791size_store(mddev_t *mddev, const char *buf, size_t len) 2893size_store(mddev_t *mddev, const char *buf, size_t len)
@@ -2802,7 +2904,7 @@ size_store(mddev_t *mddev, const char *buf, size_t len)
2802 return -EINVAL; 2904 return -EINVAL;
2803 2905
2804 if (mddev->pers) { 2906 if (mddev->pers) {
2805 err = update_size(mddev, size); 2907 err = update_size(mddev, size * 2);
2806 md_update_sb(mddev, 1); 2908 md_update_sb(mddev, 1);
2807 } else { 2909 } else {
2808 if (mddev->size == 0 || 2910 if (mddev->size == 0 ||
@@ -2899,7 +3001,7 @@ action_show(mddev_t *mddev, char *page)
2899 type = "check"; 3001 type = "check";
2900 else 3002 else
2901 type = "repair"; 3003 type = "repair";
2902 } else 3004 } else if (test_bit(MD_RECOVERY_RECOVER, &mddev->recovery))
2903 type = "recover"; 3005 type = "recover";
2904 } 3006 }
2905 return sprintf(page, "%s\n", type); 3007 return sprintf(page, "%s\n", type);
@@ -2921,15 +3023,19 @@ action_store(mddev_t *mddev, const char *page, size_t len)
2921 } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || 3023 } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
2922 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) 3024 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))
2923 return -EBUSY; 3025 return -EBUSY;
2924 else if (cmd_match(page, "resync") || cmd_match(page, "recover")) 3026 else if (cmd_match(page, "resync"))
3027 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
3028 else if (cmd_match(page, "recover")) {
3029 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
2925 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 3030 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
2926 else if (cmd_match(page, "reshape")) { 3031 } else if (cmd_match(page, "reshape")) {
2927 int err; 3032 int err;
2928 if (mddev->pers->start_reshape == NULL) 3033 if (mddev->pers->start_reshape == NULL)
2929 return -EINVAL; 3034 return -EINVAL;
2930 err = mddev->pers->start_reshape(mddev); 3035 err = mddev->pers->start_reshape(mddev);
2931 if (err) 3036 if (err)
2932 return err; 3037 return err;
3038 sysfs_notify(&mddev->kobj, NULL, "degraded");
2933 } else { 3039 } else {
2934 if (cmd_match(page, "check")) 3040 if (cmd_match(page, "check"))
2935 set_bit(MD_RECOVERY_CHECK, &mddev->recovery); 3041 set_bit(MD_RECOVERY_CHECK, &mddev->recovery);
@@ -2940,6 +3046,7 @@ action_store(mddev_t *mddev, const char *page, size_t len)
2940 } 3046 }
2941 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 3047 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
2942 md_wakeup_thread(mddev->thread); 3048 md_wakeup_thread(mddev->thread);
3049 sysfs_notify(&mddev->kobj, NULL, "sync_action");
2943 return len; 3050 return len;
2944} 3051}
2945 3052
@@ -3049,11 +3156,11 @@ static ssize_t
3049sync_speed_show(mddev_t *mddev, char *page) 3156sync_speed_show(mddev_t *mddev, char *page)
3050{ 3157{
3051 unsigned long resync, dt, db; 3158 unsigned long resync, dt, db;
3052 resync = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active)); 3159 resync = mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active);
3053 dt = ((jiffies - mddev->resync_mark) / HZ); 3160 dt = (jiffies - mddev->resync_mark) / HZ;
3054 if (!dt) dt++; 3161 if (!dt) dt++;
3055 db = resync - (mddev->resync_mark_cnt); 3162 db = resync - mddev->resync_mark_cnt;
3056 return sprintf(page, "%ld\n", db/dt/2); /* K/sec */ 3163 return sprintf(page, "%lu\n", db/dt/2); /* K/sec */
3057} 3164}
3058 3165
3059static struct md_sysfs_entry md_sync_speed = __ATTR_RO(sync_speed); 3166static struct md_sysfs_entry md_sync_speed = __ATTR_RO(sync_speed);
@@ -3075,6 +3182,36 @@ sync_completed_show(mddev_t *mddev, char *page)
3075static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed); 3182static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed);
3076 3183
3077static ssize_t 3184static ssize_t
3185min_sync_show(mddev_t *mddev, char *page)
3186{
3187 return sprintf(page, "%llu\n",
3188 (unsigned long long)mddev->resync_min);
3189}
3190static ssize_t
3191min_sync_store(mddev_t *mddev, const char *buf, size_t len)
3192{
3193 unsigned long long min;
3194 if (strict_strtoull(buf, 10, &min))
3195 return -EINVAL;
3196 if (min > mddev->resync_max)
3197 return -EINVAL;
3198 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
3199 return -EBUSY;
3200
3201 /* Must be a multiple of chunk_size */
3202 if (mddev->chunk_size) {
3203 if (min & (sector_t)((mddev->chunk_size>>9)-1))
3204 return -EINVAL;
3205 }
3206 mddev->resync_min = min;
3207
3208 return len;
3209}
3210
3211static struct md_sysfs_entry md_min_sync =
3212__ATTR(sync_min, S_IRUGO|S_IWUSR, min_sync_show, min_sync_store);
3213
3214static ssize_t
3078max_sync_show(mddev_t *mddev, char *page) 3215max_sync_show(mddev_t *mddev, char *page)
3079{ 3216{
3080 if (mddev->resync_max == MaxSector) 3217 if (mddev->resync_max == MaxSector)
@@ -3089,9 +3226,10 @@ max_sync_store(mddev_t *mddev, const char *buf, size_t len)
3089 if (strncmp(buf, "max", 3) == 0) 3226 if (strncmp(buf, "max", 3) == 0)
3090 mddev->resync_max = MaxSector; 3227 mddev->resync_max = MaxSector;
3091 else { 3228 else {
3092 char *ep; 3229 unsigned long long max;
3093 unsigned long long max = simple_strtoull(buf, &ep, 10); 3230 if (strict_strtoull(buf, 10, &max))
3094 if (ep == buf || (*ep != 0 && *ep != '\n')) 3231 return -EINVAL;
3232 if (max < mddev->resync_min)
3095 return -EINVAL; 3233 return -EINVAL;
3096 if (max < mddev->resync_max && 3234 if (max < mddev->resync_max &&
3097 test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) 3235 test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
@@ -3222,6 +3360,7 @@ static struct attribute *md_redundancy_attrs[] = {
3222 &md_sync_speed.attr, 3360 &md_sync_speed.attr,
3223 &md_sync_force_parallel.attr, 3361 &md_sync_force_parallel.attr,
3224 &md_sync_completed.attr, 3362 &md_sync_completed.attr,
3363 &md_min_sync.attr,
3225 &md_max_sync.attr, 3364 &md_max_sync.attr,
3226 &md_suspend_lo.attr, 3365 &md_suspend_lo.attr,
3227 &md_suspend_hi.attr, 3366 &md_suspend_hi.attr,
@@ -3326,9 +3465,9 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
3326 disk->queue = mddev->queue; 3465 disk->queue = mddev->queue;
3327 add_disk(disk); 3466 add_disk(disk);
3328 mddev->gendisk = disk; 3467 mddev->gendisk = disk;
3329 mutex_unlock(&disks_mutex);
3330 error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->dev.kobj, 3468 error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->dev.kobj,
3331 "%s", "md"); 3469 "%s", "md");
3470 mutex_unlock(&disks_mutex);
3332 if (error) 3471 if (error)
3333 printk(KERN_WARNING "md: cannot register %s/md - name in use\n", 3472 printk(KERN_WARNING "md: cannot register %s/md - name in use\n",
3334 disk->disk_name); 3473 disk->disk_name);
@@ -3341,7 +3480,11 @@ static void md_safemode_timeout(unsigned long data)
3341{ 3480{
3342 mddev_t *mddev = (mddev_t *) data; 3481 mddev_t *mddev = (mddev_t *) data;
3343 3482
3344 mddev->safemode = 1; 3483 if (!atomic_read(&mddev->writes_pending)) {
3484 mddev->safemode = 1;
3485 if (mddev->external)
3486 sysfs_notify(&mddev->kobj, NULL, "array_state");
3487 }
3345 md_wakeup_thread(mddev->thread); 3488 md_wakeup_thread(mddev->thread);
3346} 3489}
3347 3490
@@ -3432,22 +3575,23 @@ static int do_md_run(mddev_t * mddev)
3432 * We don't want the data to overlap the metadata, 3575 * We don't want the data to overlap the metadata,
3433 * Internal Bitmap issues has handled elsewhere. 3576 * Internal Bitmap issues has handled elsewhere.
3434 */ 3577 */
3435 if (rdev->data_offset < rdev->sb_offset) { 3578 if (rdev->data_offset < rdev->sb_start) {
3436 if (mddev->size && 3579 if (mddev->size &&
3437 rdev->data_offset + mddev->size*2 3580 rdev->data_offset + mddev->size*2
3438 > rdev->sb_offset*2) { 3581 > rdev->sb_start) {
3439 printk("md: %s: data overlaps metadata\n", 3582 printk("md: %s: data overlaps metadata\n",
3440 mdname(mddev)); 3583 mdname(mddev));
3441 return -EINVAL; 3584 return -EINVAL;
3442 } 3585 }
3443 } else { 3586 } else {
3444 if (rdev->sb_offset*2 + rdev->sb_size/512 3587 if (rdev->sb_start + rdev->sb_size/512
3445 > rdev->data_offset) { 3588 > rdev->data_offset) {
3446 printk("md: %s: metadata overlaps data\n", 3589 printk("md: %s: metadata overlaps data\n",
3447 mdname(mddev)); 3590 mdname(mddev));
3448 return -EINVAL; 3591 return -EINVAL;
3449 } 3592 }
3450 } 3593 }
3594 sysfs_notify(&rdev->kobj, NULL, "state");
3451 } 3595 }
3452 3596
3453 md_probe(mddev->unit, NULL, NULL); 3597 md_probe(mddev->unit, NULL, NULL);
@@ -3519,7 +3663,9 @@ static int do_md_run(mddev_t * mddev)
3519 mddev->ro = 2; /* read-only, but switch on first write */ 3663 mddev->ro = 2; /* read-only, but switch on first write */
3520 3664
3521 err = mddev->pers->run(mddev); 3665 err = mddev->pers->run(mddev);
3522 if (!err && mddev->pers->sync_request) { 3666 if (err)
3667 printk(KERN_ERR "md: pers->run() failed ...\n");
3668 else if (mddev->pers->sync_request) {
3523 err = bitmap_create(mddev); 3669 err = bitmap_create(mddev);
3524 if (err) { 3670 if (err) {
3525 printk(KERN_ERR "%s: failed to create bitmap (%d)\n", 3671 printk(KERN_ERR "%s: failed to create bitmap (%d)\n",
@@ -3528,7 +3674,6 @@ static int do_md_run(mddev_t * mddev)
3528 } 3674 }
3529 } 3675 }
3530 if (err) { 3676 if (err) {
3531 printk(KERN_ERR "md: pers->run() failed ...\n");
3532 module_put(mddev->pers->owner); 3677 module_put(mddev->pers->owner);
3533 mddev->pers = NULL; 3678 mddev->pers = NULL;
3534 bitmap_destroy(mddev); 3679 bitmap_destroy(mddev);
@@ -3563,7 +3708,7 @@ static int do_md_run(mddev_t * mddev)
3563 if (mddev->flags) 3708 if (mddev->flags)
3564 md_update_sb(mddev, 0); 3709 md_update_sb(mddev, 0);
3565 3710
3566 set_capacity(disk, mddev->array_size<<1); 3711 set_capacity(disk, mddev->array_sectors);
3567 3712
3568 /* If we call blk_queue_make_request here, it will 3713 /* If we call blk_queue_make_request here, it will
3569 * re-initialise max_sectors etc which may have been 3714 * re-initialise max_sectors etc which may have been
@@ -3608,6 +3753,9 @@ static int do_md_run(mddev_t * mddev)
3608 3753
3609 mddev->changed = 1; 3754 mddev->changed = 1;
3610 md_new_event(mddev); 3755 md_new_event(mddev);
3756 sysfs_notify(&mddev->kobj, NULL, "array_state");
3757 sysfs_notify(&mddev->kobj, NULL, "sync_action");
3758 sysfs_notify(&mddev->kobj, NULL, "degraded");
3611 kobject_uevent(&mddev->gendisk->dev.kobj, KOBJ_CHANGE); 3759 kobject_uevent(&mddev->gendisk->dev.kobj, KOBJ_CHANGE);
3612 return 0; 3760 return 0;
3613} 3761}
@@ -3615,38 +3763,25 @@ static int do_md_run(mddev_t * mddev)
3615static int restart_array(mddev_t *mddev) 3763static int restart_array(mddev_t *mddev)
3616{ 3764{
3617 struct gendisk *disk = mddev->gendisk; 3765 struct gendisk *disk = mddev->gendisk;
3618 int err;
3619 3766
3620 /* 3767 /* Complain if it has no devices */
3621 * Complain if it has no devices
3622 */
3623 err = -ENXIO;
3624 if (list_empty(&mddev->disks)) 3768 if (list_empty(&mddev->disks))
3625 goto out; 3769 return -ENXIO;
3626 3770 if (!mddev->pers)
3627 if (mddev->pers) { 3771 return -EINVAL;
3628 err = -EBUSY; 3772 if (!mddev->ro)
3629 if (!mddev->ro) 3773 return -EBUSY;
3630 goto out; 3774 mddev->safemode = 0;
3631 3775 mddev->ro = 0;
3632 mddev->safemode = 0; 3776 set_disk_ro(disk, 0);
3633 mddev->ro = 0; 3777 printk(KERN_INFO "md: %s switched to read-write mode.\n",
3634 set_disk_ro(disk, 0); 3778 mdname(mddev));
3635 3779 /* Kick recovery or resync if necessary */
3636 printk(KERN_INFO "md: %s switched to read-write mode.\n", 3780 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
3637 mdname(mddev)); 3781 md_wakeup_thread(mddev->thread);
3638 /* 3782 md_wakeup_thread(mddev->sync_thread);
3639 * Kick recovery or resync if necessary 3783 sysfs_notify(&mddev->kobj, NULL, "array_state");
3640 */ 3784 return 0;
3641 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
3642 md_wakeup_thread(mddev->thread);
3643 md_wakeup_thread(mddev->sync_thread);
3644 err = 0;
3645 } else
3646 err = -EINVAL;
3647
3648out:
3649 return err;
3650} 3785}
3651 3786
3652/* similar to deny_write_access, but accounts for our holding a reference 3787/* similar to deny_write_access, but accounts for our holding a reference
@@ -3680,16 +3815,17 @@ static void restore_bitmap_write_access(struct file *file)
3680 * 1 - switch to readonly 3815 * 1 - switch to readonly
3681 * 2 - stop but do not disassemble array 3816 * 2 - stop but do not disassemble array
3682 */ 3817 */
3683static int do_md_stop(mddev_t * mddev, int mode) 3818static int do_md_stop(mddev_t * mddev, int mode, int is_open)
3684{ 3819{
3685 int err = 0; 3820 int err = 0;
3686 struct gendisk *disk = mddev->gendisk; 3821 struct gendisk *disk = mddev->gendisk;
3687 3822
3823 if (atomic_read(&mddev->openers) > is_open) {
3824 printk("md: %s still in use.\n",mdname(mddev));
3825 return -EBUSY;
3826 }
3827
3688 if (mddev->pers) { 3828 if (mddev->pers) {
3689 if (atomic_read(&mddev->active)>2) {
3690 printk("md: %s still in use.\n",mdname(mddev));
3691 return -EBUSY;
3692 }
3693 3829
3694 if (mddev->sync_thread) { 3830 if (mddev->sync_thread) {
3695 set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); 3831 set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
@@ -3773,10 +3909,11 @@ static int do_md_stop(mddev_t * mddev, int mode)
3773 3909
3774 export_array(mddev); 3910 export_array(mddev);
3775 3911
3776 mddev->array_size = 0; 3912 mddev->array_sectors = 0;
3777 mddev->size = 0; 3913 mddev->size = 0;
3778 mddev->raid_disks = 0; 3914 mddev->raid_disks = 0;
3779 mddev->recovery_cp = 0; 3915 mddev->recovery_cp = 0;
3916 mddev->resync_min = 0;
3780 mddev->resync_max = MaxSector; 3917 mddev->resync_max = MaxSector;
3781 mddev->reshape_position = MaxSector; 3918 mddev->reshape_position = MaxSector;
3782 mddev->external = 0; 3919 mddev->external = 0;
@@ -3811,6 +3948,7 @@ static int do_md_stop(mddev_t * mddev, int mode)
3811 mdname(mddev)); 3948 mdname(mddev));
3812 err = 0; 3949 err = 0;
3813 md_new_event(mddev); 3950 md_new_event(mddev);
3951 sysfs_notify(&mddev->kobj, NULL, "array_state");
3814out: 3952out:
3815 return err; 3953 return err;
3816} 3954}
@@ -3836,7 +3974,7 @@ static void autorun_array(mddev_t *mddev)
3836 err = do_md_run (mddev); 3974 err = do_md_run (mddev);
3837 if (err) { 3975 if (err) {
3838 printk(KERN_WARNING "md: do_md_run() returned %d\n", err); 3976 printk(KERN_WARNING "md: do_md_run() returned %d\n", err);
3839 do_md_stop (mddev, 0); 3977 do_md_stop (mddev, 0, 0);
3840 } 3978 }
3841} 3979}
3842 3980
@@ -3927,8 +4065,10 @@ static void autorun_devices(int part)
3927 /* on success, candidates will be empty, on error 4065 /* on success, candidates will be empty, on error
3928 * it won't... 4066 * it won't...
3929 */ 4067 */
3930 rdev_for_each_list(rdev, tmp, candidates) 4068 rdev_for_each_list(rdev, tmp, candidates) {
4069 list_del_init(&rdev->same_set);
3931 export_rdev(rdev); 4070 export_rdev(rdev);
4071 }
3932 mddev_put(mddev); 4072 mddev_put(mddev);
3933 } 4073 }
3934 printk(KERN_INFO "md: ... autorun DONE.\n"); 4074 printk(KERN_INFO "md: ... autorun DONE.\n");
@@ -4009,9 +4149,11 @@ static int get_bitmap_file(mddev_t * mddev, void __user * arg)
4009 char *ptr, *buf = NULL; 4149 char *ptr, *buf = NULL;
4010 int err = -ENOMEM; 4150 int err = -ENOMEM;
4011 4151
4012 md_allow_write(mddev); 4152 if (md_allow_write(mddev))
4153 file = kmalloc(sizeof(*file), GFP_NOIO);
4154 else
4155 file = kmalloc(sizeof(*file), GFP_KERNEL);
4013 4156
4014 file = kmalloc(sizeof(*file), GFP_KERNEL);
4015 if (!file) 4157 if (!file)
4016 goto out; 4158 goto out;
4017 4159
@@ -4044,15 +4186,12 @@ out:
4044static int get_disk_info(mddev_t * mddev, void __user * arg) 4186static int get_disk_info(mddev_t * mddev, void __user * arg)
4045{ 4187{
4046 mdu_disk_info_t info; 4188 mdu_disk_info_t info;
4047 unsigned int nr;
4048 mdk_rdev_t *rdev; 4189 mdk_rdev_t *rdev;
4049 4190
4050 if (copy_from_user(&info, arg, sizeof(info))) 4191 if (copy_from_user(&info, arg, sizeof(info)))
4051 return -EFAULT; 4192 return -EFAULT;
4052 4193
4053 nr = info.number; 4194 rdev = find_rdev_nr(mddev, info.number);
4054
4055 rdev = find_rdev_nr(mddev, nr);
4056 if (rdev) { 4195 if (rdev) {
4057 info.major = MAJOR(rdev->bdev->bd_dev); 4196 info.major = MAJOR(rdev->bdev->bd_dev);
4058 info.minor = MINOR(rdev->bdev->bd_dev); 4197 info.minor = MINOR(rdev->bdev->bd_dev);
@@ -4172,8 +4311,12 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
4172 } 4311 }
4173 if (err) 4312 if (err)
4174 export_rdev(rdev); 4313 export_rdev(rdev);
4314 else
4315 sysfs_notify(&rdev->kobj, NULL, "state");
4175 4316
4176 md_update_sb(mddev, 1); 4317 md_update_sb(mddev, 1);
4318 if (mddev->degraded)
4319 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
4177 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 4320 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
4178 md_wakeup_thread(mddev->thread); 4321 md_wakeup_thread(mddev->thread);
4179 return err; 4322 return err;
@@ -4212,10 +4355,10 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
4212 4355
4213 if (!mddev->persistent) { 4356 if (!mddev->persistent) {
4214 printk(KERN_INFO "md: nonpersistent superblock ...\n"); 4357 printk(KERN_INFO "md: nonpersistent superblock ...\n");
4215 rdev->sb_offset = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; 4358 rdev->sb_start = rdev->bdev->bd_inode->i_size / 512;
4216 } else 4359 } else
4217 rdev->sb_offset = calc_dev_sboffset(rdev->bdev); 4360 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
4218 rdev->size = calc_dev_size(rdev, mddev->chunk_size); 4361 rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2;
4219 4362
4220 err = bind_rdev_to_array(rdev, mddev); 4363 err = bind_rdev_to_array(rdev, mddev);
4221 if (err) { 4364 if (err) {
@@ -4232,9 +4375,6 @@ static int hot_remove_disk(mddev_t * mddev, dev_t dev)
4232 char b[BDEVNAME_SIZE]; 4375 char b[BDEVNAME_SIZE];
4233 mdk_rdev_t *rdev; 4376 mdk_rdev_t *rdev;
4234 4377
4235 if (!mddev->pers)
4236 return -ENODEV;
4237
4238 rdev = find_rdev(mddev, dev); 4378 rdev = find_rdev(mddev, dev);
4239 if (!rdev) 4379 if (!rdev)
4240 return -ENXIO; 4380 return -ENXIO;
@@ -4257,7 +4397,6 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev)
4257{ 4397{
4258 char b[BDEVNAME_SIZE]; 4398 char b[BDEVNAME_SIZE];
4259 int err; 4399 int err;
4260 unsigned int size;
4261 mdk_rdev_t *rdev; 4400 mdk_rdev_t *rdev;
4262 4401
4263 if (!mddev->pers) 4402 if (!mddev->pers)
@@ -4285,13 +4424,11 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev)
4285 } 4424 }
4286 4425
4287 if (mddev->persistent) 4426 if (mddev->persistent)
4288 rdev->sb_offset = calc_dev_sboffset(rdev->bdev); 4427 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
4289 else 4428 else
4290 rdev->sb_offset = 4429 rdev->sb_start = rdev->bdev->bd_inode->i_size / 512;
4291 rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
4292 4430
4293 size = calc_dev_size(rdev, mddev->chunk_size); 4431 rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2;
4294 rdev->size = size;
4295 4432
4296 if (test_bit(Faulty, &rdev->flags)) { 4433 if (test_bit(Faulty, &rdev->flags)) {
4297 printk(KERN_WARNING 4434 printk(KERN_WARNING
@@ -4476,24 +4613,24 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
4476 return 0; 4613 return 0;
4477} 4614}
4478 4615
4479static int update_size(mddev_t *mddev, unsigned long size) 4616static int update_size(mddev_t *mddev, sector_t num_sectors)
4480{ 4617{
4481 mdk_rdev_t * rdev; 4618 mdk_rdev_t * rdev;
4482 int rv; 4619 int rv;
4483 struct list_head *tmp; 4620 struct list_head *tmp;
4484 int fit = (size == 0); 4621 int fit = (num_sectors == 0);
4485 4622
4486 if (mddev->pers->resize == NULL) 4623 if (mddev->pers->resize == NULL)
4487 return -EINVAL; 4624 return -EINVAL;
4488 /* The "size" is the amount of each device that is used. 4625 /* The "num_sectors" is the number of sectors of each device that
4489 * This can only make sense for arrays with redundancy. 4626 * is used. This can only make sense for arrays with redundancy.
4490 * linear and raid0 always use whatever space is available 4627 * linear and raid0 always use whatever space is available. We can only
4491 * We can only consider changing the size if no resync 4628 * consider changing this number if no resync or reconstruction is
4492 * or reconstruction is happening, and if the new size 4629 * happening, and if the new size is acceptable. It must fit before the
4493 * is acceptable. It must fit before the sb_offset or, 4630 * sb_start or, if that is <data_offset, it must fit before the size
4494 * if that is <data_offset, it must fit before the 4631 * of each device. If num_sectors is zero, we find the largest size
4495 * size of each device. 4632 * that fits.
4496 * If size is zero, we find the largest size that fits. 4633
4497 */ 4634 */
4498 if (mddev->sync_thread) 4635 if (mddev->sync_thread)
4499 return -EBUSY; 4636 return -EBUSY;
@@ -4501,19 +4638,20 @@ static int update_size(mddev_t *mddev, unsigned long size)
4501 sector_t avail; 4638 sector_t avail;
4502 avail = rdev->size * 2; 4639 avail = rdev->size * 2;
4503 4640
4504 if (fit && (size == 0 || size > avail/2)) 4641 if (fit && (num_sectors == 0 || num_sectors > avail))
4505 size = avail/2; 4642 num_sectors = avail;
4506 if (avail < ((sector_t)size << 1)) 4643 if (avail < num_sectors)
4507 return -ENOSPC; 4644 return -ENOSPC;
4508 } 4645 }
4509 rv = mddev->pers->resize(mddev, (sector_t)size *2); 4646 rv = mddev->pers->resize(mddev, num_sectors);
4510 if (!rv) { 4647 if (!rv) {
4511 struct block_device *bdev; 4648 struct block_device *bdev;
4512 4649
4513 bdev = bdget_disk(mddev->gendisk, 0); 4650 bdev = bdget_disk(mddev->gendisk, 0);
4514 if (bdev) { 4651 if (bdev) {
4515 mutex_lock(&bdev->bd_inode->i_mutex); 4652 mutex_lock(&bdev->bd_inode->i_mutex);
4516 i_size_write(bdev->bd_inode, (loff_t)mddev->array_size << 10); 4653 i_size_write(bdev->bd_inode,
4654 (loff_t)mddev->array_sectors << 9);
4517 mutex_unlock(&bdev->bd_inode->i_mutex); 4655 mutex_unlock(&bdev->bd_inode->i_mutex);
4518 bdput(bdev); 4656 bdput(bdev);
4519 } 4657 }
@@ -4588,7 +4726,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
4588 return mddev->pers->reconfig(mddev, info->layout, -1); 4726 return mddev->pers->reconfig(mddev, info->layout, -1);
4589 } 4727 }
4590 if (info->size >= 0 && mddev->size != info->size) 4728 if (info->size >= 0 && mddev->size != info->size)
4591 rv = update_size(mddev, info->size); 4729 rv = update_size(mddev, (sector_t)info->size * 2);
4592 4730
4593 if (mddev->raid_disks != info->raid_disks) 4731 if (mddev->raid_disks != info->raid_disks)
4594 rv = update_raid_disks(mddev, info->raid_disks); 4732 rv = update_raid_disks(mddev, info->raid_disks);
@@ -4641,6 +4779,12 @@ static int set_disk_faulty(mddev_t *mddev, dev_t dev)
4641 return 0; 4779 return 0;
4642} 4780}
4643 4781
4782/*
4783 * We have a problem here : there is no easy way to give a CHS
4784 * virtual geometry. We currently pretend that we have a 2 heads
4785 * 4 sectors (with a BIG number of cylinders...). This drives
4786 * dosfs just mad... ;-)
4787 */
4644static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo) 4788static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo)
4645{ 4789{
4646 mddev_t *mddev = bdev->bd_disk->private_data; 4790 mddev_t *mddev = bdev->bd_disk->private_data;
@@ -4785,19 +4929,13 @@ static int md_ioctl(struct inode *inode, struct file *file,
4785 goto done_unlock; 4929 goto done_unlock;
4786 4930
4787 case STOP_ARRAY: 4931 case STOP_ARRAY:
4788 err = do_md_stop (mddev, 0); 4932 err = do_md_stop (mddev, 0, 1);
4789 goto done_unlock; 4933 goto done_unlock;
4790 4934
4791 case STOP_ARRAY_RO: 4935 case STOP_ARRAY_RO:
4792 err = do_md_stop (mddev, 1); 4936 err = do_md_stop (mddev, 1, 1);
4793 goto done_unlock; 4937 goto done_unlock;
4794 4938
4795 /*
4796 * We have a problem here : there is no easy way to give a CHS
4797 * virtual geometry. We currently pretend that we have a 2 heads
4798 * 4 sectors (with a BIG number of cylinders...). This drives
4799 * dosfs just mad... ;-)
4800 */
4801 } 4939 }
4802 4940
4803 /* 4941 /*
@@ -4807,13 +4945,12 @@ static int md_ioctl(struct inode *inode, struct file *file,
4807 * here and hit the 'default' below, so only disallow 4945 * here and hit the 'default' below, so only disallow
4808 * 'md' ioctls, and switch to rw mode if started auto-readonly. 4946 * 'md' ioctls, and switch to rw mode if started auto-readonly.
4809 */ 4947 */
4810 if (_IOC_TYPE(cmd) == MD_MAJOR && 4948 if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) {
4811 mddev->ro && mddev->pers) {
4812 if (mddev->ro == 2) { 4949 if (mddev->ro == 2) {
4813 mddev->ro = 0; 4950 mddev->ro = 0;
4814 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 4951 sysfs_notify(&mddev->kobj, NULL, "array_state");
4815 md_wakeup_thread(mddev->thread); 4952 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
4816 4953 md_wakeup_thread(mddev->thread);
4817 } else { 4954 } else {
4818 err = -EROFS; 4955 err = -EROFS;
4819 goto abort_unlock; 4956 goto abort_unlock;
@@ -4883,6 +5020,7 @@ static int md_open(struct inode *inode, struct file *file)
4883 5020
4884 err = 0; 5021 err = 0;
4885 mddev_get(mddev); 5022 mddev_get(mddev);
5023 atomic_inc(&mddev->openers);
4886 mddev_unlock(mddev); 5024 mddev_unlock(mddev);
4887 5025
4888 check_disk_change(inode->i_bdev); 5026 check_disk_change(inode->i_bdev);
@@ -4895,6 +5033,7 @@ static int md_release(struct inode *inode, struct file * file)
4895 mddev_t *mddev = inode->i_bdev->bd_disk->private_data; 5033 mddev_t *mddev = inode->i_bdev->bd_disk->private_data;
4896 5034
4897 BUG_ON(!mddev); 5035 BUG_ON(!mddev);
5036 atomic_dec(&mddev->openers);
4898 mddev_put(mddev); 5037 mddev_put(mddev);
4899 5038
4900 return 0; 5039 return 0;
@@ -5029,6 +5168,9 @@ void md_error(mddev_t *mddev, mdk_rdev_t *rdev)
5029 if (!mddev->pers->error_handler) 5168 if (!mddev->pers->error_handler)
5030 return; 5169 return;
5031 mddev->pers->error_handler(mddev,rdev); 5170 mddev->pers->error_handler(mddev,rdev);
5171 if (mddev->degraded)
5172 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
5173 set_bit(StateChanged, &rdev->flags);
5032 set_bit(MD_RECOVERY_INTR, &mddev->recovery); 5174 set_bit(MD_RECOVERY_INTR, &mddev->recovery);
5033 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 5175 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5034 md_wakeup_thread(mddev->thread); 5176 md_wakeup_thread(mddev->thread);
@@ -5258,10 +5400,11 @@ static int md_seq_show(struct seq_file *seq, void *v)
5258 if (!list_empty(&mddev->disks)) { 5400 if (!list_empty(&mddev->disks)) {
5259 if (mddev->pers) 5401 if (mddev->pers)
5260 seq_printf(seq, "\n %llu blocks", 5402 seq_printf(seq, "\n %llu blocks",
5261 (unsigned long long)mddev->array_size); 5403 (unsigned long long)
5404 mddev->array_sectors / 2);
5262 else 5405 else
5263 seq_printf(seq, "\n %llu blocks", 5406 seq_printf(seq, "\n %llu blocks",
5264 (unsigned long long)size); 5407 (unsigned long long)size);
5265 } 5408 }
5266 if (mddev->persistent) { 5409 if (mddev->persistent) {
5267 if (mddev->major_version != 0 || 5410 if (mddev->major_version != 0 ||
@@ -5391,12 +5534,12 @@ int unregister_md_personality(struct mdk_personality *p)
5391static int is_mddev_idle(mddev_t *mddev) 5534static int is_mddev_idle(mddev_t *mddev)
5392{ 5535{
5393 mdk_rdev_t * rdev; 5536 mdk_rdev_t * rdev;
5394 struct list_head *tmp;
5395 int idle; 5537 int idle;
5396 long curr_events; 5538 long curr_events;
5397 5539
5398 idle = 1; 5540 idle = 1;
5399 rdev_for_each(rdev, tmp, mddev) { 5541 rcu_read_lock();
5542 rdev_for_each_rcu(rdev, mddev) {
5400 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk; 5543 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
5401 curr_events = disk_stat_read(disk, sectors[0]) + 5544 curr_events = disk_stat_read(disk, sectors[0]) +
5402 disk_stat_read(disk, sectors[1]) - 5545 disk_stat_read(disk, sectors[1]) -
@@ -5428,6 +5571,7 @@ static int is_mddev_idle(mddev_t *mddev)
5428 idle = 0; 5571 idle = 0;
5429 } 5572 }
5430 } 5573 }
5574 rcu_read_unlock();
5431 return idle; 5575 return idle;
5432} 5576}
5433 5577
@@ -5451,6 +5595,7 @@ void md_done_sync(mddev_t *mddev, int blocks, int ok)
5451 */ 5595 */
5452void md_write_start(mddev_t *mddev, struct bio *bi) 5596void md_write_start(mddev_t *mddev, struct bio *bi)
5453{ 5597{
5598 int did_change = 0;
5454 if (bio_data_dir(bi) != WRITE) 5599 if (bio_data_dir(bi) != WRITE)
5455 return; 5600 return;
5456 5601
@@ -5461,6 +5606,7 @@ void md_write_start(mddev_t *mddev, struct bio *bi)
5461 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 5606 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5462 md_wakeup_thread(mddev->thread); 5607 md_wakeup_thread(mddev->thread);
5463 md_wakeup_thread(mddev->sync_thread); 5608 md_wakeup_thread(mddev->sync_thread);
5609 did_change = 1;
5464 } 5610 }
5465 atomic_inc(&mddev->writes_pending); 5611 atomic_inc(&mddev->writes_pending);
5466 if (mddev->safemode == 1) 5612 if (mddev->safemode == 1)
@@ -5471,10 +5617,12 @@ void md_write_start(mddev_t *mddev, struct bio *bi)
5471 mddev->in_sync = 0; 5617 mddev->in_sync = 0;
5472 set_bit(MD_CHANGE_CLEAN, &mddev->flags); 5618 set_bit(MD_CHANGE_CLEAN, &mddev->flags);
5473 md_wakeup_thread(mddev->thread); 5619 md_wakeup_thread(mddev->thread);
5620 did_change = 1;
5474 } 5621 }
5475 spin_unlock_irq(&mddev->write_lock); 5622 spin_unlock_irq(&mddev->write_lock);
5476 sysfs_notify(&mddev->kobj, NULL, "array_state");
5477 } 5623 }
5624 if (did_change)
5625 sysfs_notify(&mddev->kobj, NULL, "array_state");
5478 wait_event(mddev->sb_wait, 5626 wait_event(mddev->sb_wait,
5479 !test_bit(MD_CHANGE_CLEAN, &mddev->flags) && 5627 !test_bit(MD_CHANGE_CLEAN, &mddev->flags) &&
5480 !test_bit(MD_CHANGE_PENDING, &mddev->flags)); 5628 !test_bit(MD_CHANGE_PENDING, &mddev->flags));
@@ -5495,13 +5643,18 @@ void md_write_end(mddev_t *mddev)
5495 * may proceed without blocking. It is important to call this before 5643 * may proceed without blocking. It is important to call this before
5496 * attempting a GFP_KERNEL allocation while holding the mddev lock. 5644 * attempting a GFP_KERNEL allocation while holding the mddev lock.
5497 * Must be called with mddev_lock held. 5645 * Must be called with mddev_lock held.
5646 *
5647 * In the ->external case MD_CHANGE_CLEAN can not be cleared until mddev->lock
5648 * is dropped, so return -EAGAIN after notifying userspace.
5498 */ 5649 */
5499void md_allow_write(mddev_t *mddev) 5650int md_allow_write(mddev_t *mddev)
5500{ 5651{
5501 if (!mddev->pers) 5652 if (!mddev->pers)
5502 return; 5653 return 0;
5503 if (mddev->ro) 5654 if (mddev->ro)
5504 return; 5655 return 0;
5656 if (!mddev->pers->sync_request)
5657 return 0;
5505 5658
5506 spin_lock_irq(&mddev->write_lock); 5659 spin_lock_irq(&mddev->write_lock);
5507 if (mddev->in_sync) { 5660 if (mddev->in_sync) {
@@ -5512,14 +5665,14 @@ void md_allow_write(mddev_t *mddev)
5512 mddev->safemode = 1; 5665 mddev->safemode = 1;
5513 spin_unlock_irq(&mddev->write_lock); 5666 spin_unlock_irq(&mddev->write_lock);
5514 md_update_sb(mddev, 0); 5667 md_update_sb(mddev, 0);
5515
5516 sysfs_notify(&mddev->kobj, NULL, "array_state"); 5668 sysfs_notify(&mddev->kobj, NULL, "array_state");
5517 /* wait for the dirty state to be recorded in the metadata */
5518 wait_event(mddev->sb_wait,
5519 !test_bit(MD_CHANGE_CLEAN, &mddev->flags) &&
5520 !test_bit(MD_CHANGE_PENDING, &mddev->flags));
5521 } else 5669 } else
5522 spin_unlock_irq(&mddev->write_lock); 5670 spin_unlock_irq(&mddev->write_lock);
5671
5672 if (test_bit(MD_CHANGE_CLEAN, &mddev->flags))
5673 return -EAGAIN;
5674 else
5675 return 0;
5523} 5676}
5524EXPORT_SYMBOL_GPL(md_allow_write); 5677EXPORT_SYMBOL_GPL(md_allow_write);
5525 5678
@@ -5625,9 +5778,11 @@ void md_do_sync(mddev_t *mddev)
5625 max_sectors = mddev->resync_max_sectors; 5778 max_sectors = mddev->resync_max_sectors;
5626 mddev->resync_mismatches = 0; 5779 mddev->resync_mismatches = 0;
5627 /* we don't use the checkpoint if there's a bitmap */ 5780 /* we don't use the checkpoint if there's a bitmap */
5628 if (!mddev->bitmap && 5781 if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
5629 !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) 5782 j = mddev->resync_min;
5783 else if (!mddev->bitmap)
5630 j = mddev->recovery_cp; 5784 j = mddev->recovery_cp;
5785
5631 } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) 5786 } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery))
5632 max_sectors = mddev->size << 1; 5787 max_sectors = mddev->size << 1;
5633 else { 5788 else {
@@ -5796,6 +5951,7 @@ void md_do_sync(mddev_t *mddev)
5796 5951
5797 skip: 5952 skip:
5798 mddev->curr_resync = 0; 5953 mddev->curr_resync = 0;
5954 mddev->resync_min = 0;
5799 mddev->resync_max = MaxSector; 5955 mddev->resync_max = MaxSector;
5800 sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 5956 sysfs_notify(&mddev->kobj, NULL, "sync_completed");
5801 wake_up(&resync_wait); 5957 wake_up(&resync_wait);
@@ -5845,7 +6001,8 @@ static int remove_and_add_spares(mddev_t *mddev)
5845 if (rdev->raid_disk < 0 6001 if (rdev->raid_disk < 0
5846 && !test_bit(Faulty, &rdev->flags)) { 6002 && !test_bit(Faulty, &rdev->flags)) {
5847 rdev->recovery_offset = 0; 6003 rdev->recovery_offset = 0;
5848 if (mddev->pers->hot_add_disk(mddev,rdev)) { 6004 if (mddev->pers->
6005 hot_add_disk(mddev, rdev) == 0) {
5849 char nm[20]; 6006 char nm[20];
5850 sprintf(nm, "rd%d", rdev->raid_disk); 6007 sprintf(nm, "rd%d", rdev->raid_disk);
5851 if (sysfs_create_link(&mddev->kobj, 6008 if (sysfs_create_link(&mddev->kobj,
@@ -5920,23 +6077,31 @@ void md_check_recovery(mddev_t *mddev)
5920 int spares = 0; 6077 int spares = 0;
5921 6078
5922 if (!mddev->external) { 6079 if (!mddev->external) {
6080 int did_change = 0;
5923 spin_lock_irq(&mddev->write_lock); 6081 spin_lock_irq(&mddev->write_lock);
5924 if (mddev->safemode && 6082 if (mddev->safemode &&
5925 !atomic_read(&mddev->writes_pending) && 6083 !atomic_read(&mddev->writes_pending) &&
5926 !mddev->in_sync && 6084 !mddev->in_sync &&
5927 mddev->recovery_cp == MaxSector) { 6085 mddev->recovery_cp == MaxSector) {
5928 mddev->in_sync = 1; 6086 mddev->in_sync = 1;
6087 did_change = 1;
5929 if (mddev->persistent) 6088 if (mddev->persistent)
5930 set_bit(MD_CHANGE_CLEAN, &mddev->flags); 6089 set_bit(MD_CHANGE_CLEAN, &mddev->flags);
5931 } 6090 }
5932 if (mddev->safemode == 1) 6091 if (mddev->safemode == 1)
5933 mddev->safemode = 0; 6092 mddev->safemode = 0;
5934 spin_unlock_irq(&mddev->write_lock); 6093 spin_unlock_irq(&mddev->write_lock);
6094 if (did_change)
6095 sysfs_notify(&mddev->kobj, NULL, "array_state");
5935 } 6096 }
5936 6097
5937 if (mddev->flags) 6098 if (mddev->flags)
5938 md_update_sb(mddev, 0); 6099 md_update_sb(mddev, 0);
5939 6100
6101 rdev_for_each(rdev, rtmp, mddev)
6102 if (test_and_clear_bit(StateChanged, &rdev->flags))
6103 sysfs_notify(&rdev->kobj, NULL, "state");
6104
5940 6105
5941 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) && 6106 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) &&
5942 !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) { 6107 !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) {
@@ -5951,7 +6116,9 @@ void md_check_recovery(mddev_t *mddev)
5951 if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { 6116 if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
5952 /* success...*/ 6117 /* success...*/
5953 /* activate any spares */ 6118 /* activate any spares */
5954 mddev->pers->spare_active(mddev); 6119 if (mddev->pers->spare_active(mddev))
6120 sysfs_notify(&mddev->kobj, NULL,
6121 "degraded");
5955 } 6122 }
5956 md_update_sb(mddev, 1); 6123 md_update_sb(mddev, 1);
5957 6124
@@ -5965,13 +6132,18 @@ void md_check_recovery(mddev_t *mddev)
5965 mddev->recovery = 0; 6132 mddev->recovery = 0;
5966 /* flag recovery needed just to double check */ 6133 /* flag recovery needed just to double check */
5967 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 6134 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
6135 sysfs_notify(&mddev->kobj, NULL, "sync_action");
5968 md_new_event(mddev); 6136 md_new_event(mddev);
5969 goto unlock; 6137 goto unlock;
5970 } 6138 }
6139 /* Set RUNNING before clearing NEEDED to avoid
6140 * any transients in the value of "sync_action".
6141 */
6142 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
6143 clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5971 /* Clear some bits that don't mean anything, but 6144 /* Clear some bits that don't mean anything, but
5972 * might be left set 6145 * might be left set
5973 */ 6146 */
5974 clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5975 clear_bit(MD_RECOVERY_INTR, &mddev->recovery); 6147 clear_bit(MD_RECOVERY_INTR, &mddev->recovery);
5976 clear_bit(MD_RECOVERY_DONE, &mddev->recovery); 6148 clear_bit(MD_RECOVERY_DONE, &mddev->recovery);
5977 6149
@@ -5989,17 +6161,19 @@ void md_check_recovery(mddev_t *mddev)
5989 /* Cannot proceed */ 6161 /* Cannot proceed */
5990 goto unlock; 6162 goto unlock;
5991 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); 6163 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
6164 clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
5992 } else if ((spares = remove_and_add_spares(mddev))) { 6165 } else if ((spares = remove_and_add_spares(mddev))) {
5993 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); 6166 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
5994 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); 6167 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
6168 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
5995 } else if (mddev->recovery_cp < MaxSector) { 6169 } else if (mddev->recovery_cp < MaxSector) {
5996 set_bit(MD_RECOVERY_SYNC, &mddev->recovery); 6170 set_bit(MD_RECOVERY_SYNC, &mddev->recovery);
6171 clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
5997 } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) 6172 } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
5998 /* nothing to be done ... */ 6173 /* nothing to be done ... */
5999 goto unlock; 6174 goto unlock;
6000 6175
6001 if (mddev->pers->sync_request) { 6176 if (mddev->pers->sync_request) {
6002 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
6003 if (spares && mddev->bitmap && ! mddev->bitmap->file) { 6177 if (spares && mddev->bitmap && ! mddev->bitmap->file) {
6004 /* We are adding a device or devices to an array 6178 /* We are adding a device or devices to an array
6005 * which has the bitmap stored on all devices. 6179 * which has the bitmap stored on all devices.
@@ -6018,9 +6192,16 @@ void md_check_recovery(mddev_t *mddev)
6018 mddev->recovery = 0; 6192 mddev->recovery = 0;
6019 } else 6193 } else
6020 md_wakeup_thread(mddev->sync_thread); 6194 md_wakeup_thread(mddev->sync_thread);
6195 sysfs_notify(&mddev->kobj, NULL, "sync_action");
6021 md_new_event(mddev); 6196 md_new_event(mddev);
6022 } 6197 }
6023 unlock: 6198 unlock:
6199 if (!mddev->sync_thread) {
6200 clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
6201 if (test_and_clear_bit(MD_RECOVERY_RECOVER,
6202 &mddev->recovery))
6203 sysfs_notify(&mddev->kobj, NULL, "sync_action");
6204 }
6024 mddev_unlock(mddev); 6205 mddev_unlock(mddev);
6025 } 6206 }
6026} 6207}
@@ -6047,7 +6228,7 @@ static int md_notify_reboot(struct notifier_block *this,
6047 6228
6048 for_each_mddev(mddev, tmp) 6229 for_each_mddev(mddev, tmp)
6049 if (mddev_trylock(mddev)) { 6230 if (mddev_trylock(mddev)) {
6050 do_md_stop (mddev, 1); 6231 do_md_stop (mddev, 1, 0);
6051 mddev_unlock(mddev); 6232 mddev_unlock(mddev);
6052 } 6233 }
6053 /* 6234 /*
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index e968116e0de9..c4779ccba1c3 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -281,13 +281,18 @@ static int multipath_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
281{ 281{
282 multipath_conf_t *conf = mddev->private; 282 multipath_conf_t *conf = mddev->private;
283 struct request_queue *q; 283 struct request_queue *q;
284 int found = 0; 284 int err = -EEXIST;
285 int path; 285 int path;
286 struct multipath_info *p; 286 struct multipath_info *p;
287 int first = 0;
288 int last = mddev->raid_disks - 1;
289
290 if (rdev->raid_disk >= 0)
291 first = last = rdev->raid_disk;
287 292
288 print_multipath_conf(conf); 293 print_multipath_conf(conf);
289 294
290 for (path=0; path<mddev->raid_disks; path++) 295 for (path = first; path <= last; path++)
291 if ((p=conf->multipaths+path)->rdev == NULL) { 296 if ((p=conf->multipaths+path)->rdev == NULL) {
292 q = rdev->bdev->bd_disk->queue; 297 q = rdev->bdev->bd_disk->queue;
293 blk_queue_stack_limits(mddev->queue, q); 298 blk_queue_stack_limits(mddev->queue, q);
@@ -307,11 +312,13 @@ static int multipath_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
307 rdev->raid_disk = path; 312 rdev->raid_disk = path;
308 set_bit(In_sync, &rdev->flags); 313 set_bit(In_sync, &rdev->flags);
309 rcu_assign_pointer(p->rdev, rdev); 314 rcu_assign_pointer(p->rdev, rdev);
310 found = 1; 315 err = 0;
316 break;
311 } 317 }
312 318
313 print_multipath_conf(conf); 319 print_multipath_conf(conf);
314 return found; 320
321 return err;
315} 322}
316 323
317static int multipath_remove_disk(mddev_t *mddev, int number) 324static int multipath_remove_disk(mddev_t *mddev, int number)
@@ -497,7 +504,7 @@ static int multipath_run (mddev_t *mddev)
497 /* 504 /*
498 * Ok, everything is just fine now 505 * Ok, everything is just fine now
499 */ 506 */
500 mddev->array_size = mddev->size; 507 mddev->array_sectors = mddev->size * 2;
501 508
502 mddev->queue->unplug_fn = multipath_unplug; 509 mddev->queue->unplug_fn = multipath_unplug;
503 mddev->queue->backing_dev_info.congested_fn = multipath_congested; 510 mddev->queue->backing_dev_info.congested_fn = multipath_congested;
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index bcbb82594a19..183610635661 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -295,16 +295,16 @@ static int raid0_run (mddev_t *mddev)
295 goto out_free_conf; 295 goto out_free_conf;
296 296
297 /* calculate array device size */ 297 /* calculate array device size */
298 mddev->array_size = 0; 298 mddev->array_sectors = 0;
299 rdev_for_each(rdev, tmp, mddev) 299 rdev_for_each(rdev, tmp, mddev)
300 mddev->array_size += rdev->size; 300 mddev->array_sectors += rdev->size * 2;
301 301
302 printk("raid0 : md_size is %llu blocks.\n", 302 printk("raid0 : md_size is %llu blocks.\n",
303 (unsigned long long)mddev->array_size); 303 (unsigned long long)mddev->array_sectors / 2);
304 printk("raid0 : conf->hash_spacing is %llu blocks.\n", 304 printk("raid0 : conf->hash_spacing is %llu blocks.\n",
305 (unsigned long long)conf->hash_spacing); 305 (unsigned long long)conf->hash_spacing);
306 { 306 {
307 sector_t s = mddev->array_size; 307 sector_t s = mddev->array_sectors / 2;
308 sector_t space = conf->hash_spacing; 308 sector_t space = conf->hash_spacing;
309 int round; 309 int round;
310 conf->preshift = 0; 310 conf->preshift = 0;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index c610b947218a..03a5ab705c20 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1100,11 +1100,16 @@ static int raid1_spare_active(mddev_t *mddev)
1100static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) 1100static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1101{ 1101{
1102 conf_t *conf = mddev->private; 1102 conf_t *conf = mddev->private;
1103 int found = 0; 1103 int err = -EEXIST;
1104 int mirror = 0; 1104 int mirror = 0;
1105 mirror_info_t *p; 1105 mirror_info_t *p;
1106 int first = 0;
1107 int last = mddev->raid_disks - 1;
1106 1108
1107 for (mirror=0; mirror < mddev->raid_disks; mirror++) 1109 if (rdev->raid_disk >= 0)
1110 first = last = rdev->raid_disk;
1111
1112 for (mirror = first; mirror <= last; mirror++)
1108 if ( !(p=conf->mirrors+mirror)->rdev) { 1113 if ( !(p=conf->mirrors+mirror)->rdev) {
1109 1114
1110 blk_queue_stack_limits(mddev->queue, 1115 blk_queue_stack_limits(mddev->queue,
@@ -1119,7 +1124,7 @@ static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1119 1124
1120 p->head_position = 0; 1125 p->head_position = 0;
1121 rdev->raid_disk = mirror; 1126 rdev->raid_disk = mirror;
1122 found = 1; 1127 err = 0;
1123 /* As all devices are equivalent, we don't need a full recovery 1128 /* As all devices are equivalent, we don't need a full recovery
1124 * if this was recently any drive of the array 1129 * if this was recently any drive of the array
1125 */ 1130 */
@@ -1130,7 +1135,7 @@ static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1130 } 1135 }
1131 1136
1132 print_conf(conf); 1137 print_conf(conf);
1133 return found; 1138 return err;
1134} 1139}
1135 1140
1136static int raid1_remove_disk(mddev_t *mddev, int number) 1141static int raid1_remove_disk(mddev_t *mddev, int number)
@@ -2038,7 +2043,7 @@ static int run(mddev_t *mddev)
2038 /* 2043 /*
2039 * Ok, everything is just fine now 2044 * Ok, everything is just fine now
2040 */ 2045 */
2041 mddev->array_size = mddev->size; 2046 mddev->array_sectors = mddev->size * 2;
2042 2047
2043 mddev->queue->unplug_fn = raid1_unplug; 2048 mddev->queue->unplug_fn = raid1_unplug;
2044 mddev->queue->backing_dev_info.congested_fn = raid1_congested; 2049 mddev->queue->backing_dev_info.congested_fn = raid1_congested;
@@ -2100,14 +2105,15 @@ static int raid1_resize(mddev_t *mddev, sector_t sectors)
2100 * any io in the removed space completes, but it hardly seems 2105 * any io in the removed space completes, but it hardly seems
2101 * worth it. 2106 * worth it.
2102 */ 2107 */
2103 mddev->array_size = sectors>>1; 2108 mddev->array_sectors = sectors;
2104 set_capacity(mddev->gendisk, mddev->array_size << 1); 2109 set_capacity(mddev->gendisk, mddev->array_sectors);
2105 mddev->changed = 1; 2110 mddev->changed = 1;
2106 if (mddev->array_size > mddev->size && mddev->recovery_cp == MaxSector) { 2111 if (mddev->array_sectors / 2 > mddev->size &&
2112 mddev->recovery_cp == MaxSector) {
2107 mddev->recovery_cp = mddev->size << 1; 2113 mddev->recovery_cp = mddev->size << 1;
2108 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 2114 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
2109 } 2115 }
2110 mddev->size = mddev->array_size; 2116 mddev->size = mddev->array_sectors / 2;
2111 mddev->resync_max_sectors = sectors; 2117 mddev->resync_max_sectors = sectors;
2112 return 0; 2118 return 0;
2113} 2119}
@@ -2131,7 +2137,7 @@ static int raid1_reshape(mddev_t *mddev)
2131 conf_t *conf = mddev_to_conf(mddev); 2137 conf_t *conf = mddev_to_conf(mddev);
2132 int cnt, raid_disks; 2138 int cnt, raid_disks;
2133 unsigned long flags; 2139 unsigned long flags;
2134 int d, d2; 2140 int d, d2, err;
2135 2141
2136 /* Cannot change chunk_size, layout, or level */ 2142 /* Cannot change chunk_size, layout, or level */
2137 if (mddev->chunk_size != mddev->new_chunk || 2143 if (mddev->chunk_size != mddev->new_chunk ||
@@ -2143,7 +2149,9 @@ static int raid1_reshape(mddev_t *mddev)
2143 return -EINVAL; 2149 return -EINVAL;
2144 } 2150 }
2145 2151
2146 md_allow_write(mddev); 2152 err = md_allow_write(mddev);
2153 if (err)
2154 return err;
2147 2155
2148 raid_disks = mddev->raid_disks + mddev->delta_disks; 2156 raid_disks = mddev->raid_disks + mddev->delta_disks;
2149 2157
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 22bb2b1b886d..159535d73567 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1114,24 +1114,30 @@ static int raid10_spare_active(mddev_t *mddev)
1114static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) 1114static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1115{ 1115{
1116 conf_t *conf = mddev->private; 1116 conf_t *conf = mddev->private;
1117 int found = 0; 1117 int err = -EEXIST;
1118 int mirror; 1118 int mirror;
1119 mirror_info_t *p; 1119 mirror_info_t *p;
1120 int first = 0;
1121 int last = mddev->raid_disks - 1;
1120 1122
1121 if (mddev->recovery_cp < MaxSector) 1123 if (mddev->recovery_cp < MaxSector)
1122 /* only hot-add to in-sync arrays, as recovery is 1124 /* only hot-add to in-sync arrays, as recovery is
1123 * very different from resync 1125 * very different from resync
1124 */ 1126 */
1125 return 0; 1127 return -EBUSY;
1126 if (!enough(conf)) 1128 if (!enough(conf))
1127 return 0; 1129 return -EINVAL;
1130
1131 if (rdev->raid_disk)
1132 first = last = rdev->raid_disk;
1128 1133
1129 if (rdev->saved_raid_disk >= 0 && 1134 if (rdev->saved_raid_disk >= 0 &&
1135 rdev->saved_raid_disk >= first &&
1130 conf->mirrors[rdev->saved_raid_disk].rdev == NULL) 1136 conf->mirrors[rdev->saved_raid_disk].rdev == NULL)
1131 mirror = rdev->saved_raid_disk; 1137 mirror = rdev->saved_raid_disk;
1132 else 1138 else
1133 mirror = 0; 1139 mirror = first;
1134 for ( ; mirror < mddev->raid_disks; mirror++) 1140 for ( ; mirror <= last ; mirror++)
1135 if ( !(p=conf->mirrors+mirror)->rdev) { 1141 if ( !(p=conf->mirrors+mirror)->rdev) {
1136 1142
1137 blk_queue_stack_limits(mddev->queue, 1143 blk_queue_stack_limits(mddev->queue,
@@ -1146,7 +1152,7 @@ static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1146 1152
1147 p->head_position = 0; 1153 p->head_position = 0;
1148 rdev->raid_disk = mirror; 1154 rdev->raid_disk = mirror;
1149 found = 1; 1155 err = 0;
1150 if (rdev->saved_raid_disk != mirror) 1156 if (rdev->saved_raid_disk != mirror)
1151 conf->fullsync = 1; 1157 conf->fullsync = 1;
1152 rcu_assign_pointer(p->rdev, rdev); 1158 rcu_assign_pointer(p->rdev, rdev);
@@ -1154,7 +1160,7 @@ static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1154 } 1160 }
1155 1161
1156 print_conf(conf); 1162 print_conf(conf);
1157 return found; 1163 return err;
1158} 1164}
1159 1165
1160static int raid10_remove_disk(mddev_t *mddev, int number) 1166static int raid10_remove_disk(mddev_t *mddev, int number)
@@ -2159,7 +2165,7 @@ static int run(mddev_t *mddev)
2159 /* 2165 /*
2160 * Ok, everything is just fine now 2166 * Ok, everything is just fine now
2161 */ 2167 */
2162 mddev->array_size = size << (conf->chunk_shift-1); 2168 mddev->array_sectors = size << conf->chunk_shift;
2163 mddev->resync_max_sectors = size << conf->chunk_shift; 2169 mddev->resync_max_sectors = size << conf->chunk_shift;
2164 2170
2165 mddev->queue->unplug_fn = raid10_unplug; 2171 mddev->queue->unplug_fn = raid10_unplug;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 9ce7154845c6..55e7c56045a0 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -115,15 +115,20 @@ static void return_io(struct bio *return_bi)
115 return_bi = bi->bi_next; 115 return_bi = bi->bi_next;
116 bi->bi_next = NULL; 116 bi->bi_next = NULL;
117 bi->bi_size = 0; 117 bi->bi_size = 0;
118 bi->bi_end_io(bi, 118 bio_endio(bi, 0);
119 test_bit(BIO_UPTODATE, &bi->bi_flags)
120 ? 0 : -EIO);
121 bi = return_bi; 119 bi = return_bi;
122 } 120 }
123} 121}
124 122
125static void print_raid5_conf (raid5_conf_t *conf); 123static void print_raid5_conf (raid5_conf_t *conf);
126 124
125static int stripe_operations_active(struct stripe_head *sh)
126{
127 return sh->check_state || sh->reconstruct_state ||
128 test_bit(STRIPE_BIOFILL_RUN, &sh->state) ||
129 test_bit(STRIPE_COMPUTE_RUN, &sh->state);
130}
131
127static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh) 132static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
128{ 133{
129 if (atomic_dec_and_test(&sh->count)) { 134 if (atomic_dec_and_test(&sh->count)) {
@@ -143,7 +148,7 @@ static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
143 } 148 }
144 md_wakeup_thread(conf->mddev->thread); 149 md_wakeup_thread(conf->mddev->thread);
145 } else { 150 } else {
146 BUG_ON(sh->ops.pending); 151 BUG_ON(stripe_operations_active(sh));
147 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { 152 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) {
148 atomic_dec(&conf->preread_active_stripes); 153 atomic_dec(&conf->preread_active_stripes);
149 if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) 154 if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD)
@@ -245,7 +250,7 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx, int
245 250
246 BUG_ON(atomic_read(&sh->count) != 0); 251 BUG_ON(atomic_read(&sh->count) != 0);
247 BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); 252 BUG_ON(test_bit(STRIPE_HANDLE, &sh->state));
248 BUG_ON(sh->ops.pending || sh->ops.ack || sh->ops.complete); 253 BUG_ON(stripe_operations_active(sh));
249 254
250 CHECK_DEVLOCK(); 255 CHECK_DEVLOCK();
251 pr_debug("init_stripe called, stripe %llu\n", 256 pr_debug("init_stripe called, stripe %llu\n",
@@ -346,62 +351,18 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
346 return sh; 351 return sh;
347} 352}
348 353
349/* test_and_ack_op() ensures that we only dequeue an operation once */
350#define test_and_ack_op(op, pend) \
351do { \
352 if (test_bit(op, &sh->ops.pending) && \
353 !test_bit(op, &sh->ops.complete)) { \
354 if (test_and_set_bit(op, &sh->ops.ack)) \
355 clear_bit(op, &pend); \
356 else \
357 ack++; \
358 } else \
359 clear_bit(op, &pend); \
360} while (0)
361
362/* find new work to run, do not resubmit work that is already
363 * in flight
364 */
365static unsigned long get_stripe_work(struct stripe_head *sh)
366{
367 unsigned long pending;
368 int ack = 0;
369
370 pending = sh->ops.pending;
371
372 test_and_ack_op(STRIPE_OP_BIOFILL, pending);
373 test_and_ack_op(STRIPE_OP_COMPUTE_BLK, pending);
374 test_and_ack_op(STRIPE_OP_PREXOR, pending);
375 test_and_ack_op(STRIPE_OP_BIODRAIN, pending);
376 test_and_ack_op(STRIPE_OP_POSTXOR, pending);
377 test_and_ack_op(STRIPE_OP_CHECK, pending);
378 if (test_and_clear_bit(STRIPE_OP_IO, &sh->ops.pending))
379 ack++;
380
381 sh->ops.count -= ack;
382 if (unlikely(sh->ops.count < 0)) {
383 printk(KERN_ERR "pending: %#lx ops.pending: %#lx ops.ack: %#lx "
384 "ops.complete: %#lx\n", pending, sh->ops.pending,
385 sh->ops.ack, sh->ops.complete);
386 BUG();
387 }
388
389 return pending;
390}
391
392static void 354static void
393raid5_end_read_request(struct bio *bi, int error); 355raid5_end_read_request(struct bio *bi, int error);
394static void 356static void
395raid5_end_write_request(struct bio *bi, int error); 357raid5_end_write_request(struct bio *bi, int error);
396 358
397static void ops_run_io(struct stripe_head *sh) 359static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
398{ 360{
399 raid5_conf_t *conf = sh->raid_conf; 361 raid5_conf_t *conf = sh->raid_conf;
400 int i, disks = sh->disks; 362 int i, disks = sh->disks;
401 363
402 might_sleep(); 364 might_sleep();
403 365
404 set_bit(STRIPE_IO_STARTED, &sh->state);
405 for (i = disks; i--; ) { 366 for (i = disks; i--; ) {
406 int rw; 367 int rw;
407 struct bio *bi; 368 struct bio *bi;
@@ -430,11 +391,11 @@ static void ops_run_io(struct stripe_head *sh)
430 rcu_read_unlock(); 391 rcu_read_unlock();
431 392
432 if (rdev) { 393 if (rdev) {
433 if (test_bit(STRIPE_SYNCING, &sh->state) || 394 if (s->syncing || s->expanding || s->expanded)
434 test_bit(STRIPE_EXPAND_SOURCE, &sh->state) ||
435 test_bit(STRIPE_EXPAND_READY, &sh->state))
436 md_sync_acct(rdev->bdev, STRIPE_SECTORS); 395 md_sync_acct(rdev->bdev, STRIPE_SECTORS);
437 396
397 set_bit(STRIPE_IO_STARTED, &sh->state);
398
438 bi->bi_bdev = rdev->bdev; 399 bi->bi_bdev = rdev->bdev;
439 pr_debug("%s: for %llu schedule op %ld on disc %d\n", 400 pr_debug("%s: for %llu schedule op %ld on disc %d\n",
440 __func__, (unsigned long long)sh->sector, 401 __func__, (unsigned long long)sh->sector,
@@ -528,38 +489,34 @@ static void ops_complete_biofill(void *stripe_head_ref)
528 (unsigned long long)sh->sector); 489 (unsigned long long)sh->sector);
529 490
530 /* clear completed biofills */ 491 /* clear completed biofills */
492 spin_lock_irq(&conf->device_lock);
531 for (i = sh->disks; i--; ) { 493 for (i = sh->disks; i--; ) {
532 struct r5dev *dev = &sh->dev[i]; 494 struct r5dev *dev = &sh->dev[i];
533 495
534 /* acknowledge completion of a biofill operation */ 496 /* acknowledge completion of a biofill operation */
535 /* and check if we need to reply to a read request, 497 /* and check if we need to reply to a read request,
536 * new R5_Wantfill requests are held off until 498 * new R5_Wantfill requests are held off until
537 * !test_bit(STRIPE_OP_BIOFILL, &sh->ops.pending) 499 * !STRIPE_BIOFILL_RUN
538 */ 500 */
539 if (test_and_clear_bit(R5_Wantfill, &dev->flags)) { 501 if (test_and_clear_bit(R5_Wantfill, &dev->flags)) {
540 struct bio *rbi, *rbi2; 502 struct bio *rbi, *rbi2;
541 503
542 /* The access to dev->read is outside of the
543 * spin_lock_irq(&conf->device_lock), but is protected
544 * by the STRIPE_OP_BIOFILL pending bit
545 */
546 BUG_ON(!dev->read); 504 BUG_ON(!dev->read);
547 rbi = dev->read; 505 rbi = dev->read;
548 dev->read = NULL; 506 dev->read = NULL;
549 while (rbi && rbi->bi_sector < 507 while (rbi && rbi->bi_sector <
550 dev->sector + STRIPE_SECTORS) { 508 dev->sector + STRIPE_SECTORS) {
551 rbi2 = r5_next_bio(rbi, dev->sector); 509 rbi2 = r5_next_bio(rbi, dev->sector);
552 spin_lock_irq(&conf->device_lock);
553 if (--rbi->bi_phys_segments == 0) { 510 if (--rbi->bi_phys_segments == 0) {
554 rbi->bi_next = return_bi; 511 rbi->bi_next = return_bi;
555 return_bi = rbi; 512 return_bi = rbi;
556 } 513 }
557 spin_unlock_irq(&conf->device_lock);
558 rbi = rbi2; 514 rbi = rbi2;
559 } 515 }
560 } 516 }
561 } 517 }
562 set_bit(STRIPE_OP_BIOFILL, &sh->ops.complete); 518 spin_unlock_irq(&conf->device_lock);
519 clear_bit(STRIPE_BIOFILL_RUN, &sh->state);
563 520
564 return_io(return_bi); 521 return_io(return_bi);
565 522
@@ -610,13 +567,14 @@ static void ops_complete_compute5(void *stripe_head_ref)
610 set_bit(R5_UPTODATE, &tgt->flags); 567 set_bit(R5_UPTODATE, &tgt->flags);
611 BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); 568 BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags));
612 clear_bit(R5_Wantcompute, &tgt->flags); 569 clear_bit(R5_Wantcompute, &tgt->flags);
613 set_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete); 570 clear_bit(STRIPE_COMPUTE_RUN, &sh->state);
571 if (sh->check_state == check_state_compute_run)
572 sh->check_state = check_state_compute_result;
614 set_bit(STRIPE_HANDLE, &sh->state); 573 set_bit(STRIPE_HANDLE, &sh->state);
615 release_stripe(sh); 574 release_stripe(sh);
616} 575}
617 576
618static struct dma_async_tx_descriptor * 577static struct dma_async_tx_descriptor *ops_run_compute5(struct stripe_head *sh)
619ops_run_compute5(struct stripe_head *sh, unsigned long pending)
620{ 578{
621 /* kernel stack size limits the total number of disks */ 579 /* kernel stack size limits the total number of disks */
622 int disks = sh->disks; 580 int disks = sh->disks;
@@ -646,10 +604,6 @@ ops_run_compute5(struct stripe_head *sh, unsigned long pending)
646 ASYNC_TX_XOR_ZERO_DST, NULL, 604 ASYNC_TX_XOR_ZERO_DST, NULL,
647 ops_complete_compute5, sh); 605 ops_complete_compute5, sh);
648 606
649 /* ack now if postxor is not set to be run */
650 if (tx && !test_bit(STRIPE_OP_POSTXOR, &pending))
651 async_tx_ack(tx);
652
653 return tx; 607 return tx;
654} 608}
655 609
@@ -659,8 +613,6 @@ static void ops_complete_prexor(void *stripe_head_ref)
659 613
660 pr_debug("%s: stripe %llu\n", __func__, 614 pr_debug("%s: stripe %llu\n", __func__,
661 (unsigned long long)sh->sector); 615 (unsigned long long)sh->sector);
662
663 set_bit(STRIPE_OP_PREXOR, &sh->ops.complete);
664} 616}
665 617
666static struct dma_async_tx_descriptor * 618static struct dma_async_tx_descriptor *
@@ -680,7 +632,7 @@ ops_run_prexor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx)
680 for (i = disks; i--; ) { 632 for (i = disks; i--; ) {
681 struct r5dev *dev = &sh->dev[i]; 633 struct r5dev *dev = &sh->dev[i];
682 /* Only process blocks that are known to be uptodate */ 634 /* Only process blocks that are known to be uptodate */
683 if (dev->towrite && test_bit(R5_Wantprexor, &dev->flags)) 635 if (test_bit(R5_Wantdrain, &dev->flags))
684 xor_srcs[count++] = dev->page; 636 xor_srcs[count++] = dev->page;
685 } 637 }
686 638
@@ -692,16 +644,10 @@ ops_run_prexor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx)
692} 644}
693 645
694static struct dma_async_tx_descriptor * 646static struct dma_async_tx_descriptor *
695ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx, 647ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx)
696 unsigned long pending)
697{ 648{
698 int disks = sh->disks; 649 int disks = sh->disks;
699 int pd_idx = sh->pd_idx, i; 650 int i;
700
701 /* check if prexor is active which means only process blocks
702 * that are part of a read-modify-write (Wantprexor)
703 */
704 int prexor = test_bit(STRIPE_OP_PREXOR, &pending);
705 651
706 pr_debug("%s: stripe %llu\n", __func__, 652 pr_debug("%s: stripe %llu\n", __func__,
707 (unsigned long long)sh->sector); 653 (unsigned long long)sh->sector);
@@ -709,20 +655,8 @@ ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
709 for (i = disks; i--; ) { 655 for (i = disks; i--; ) {
710 struct r5dev *dev = &sh->dev[i]; 656 struct r5dev *dev = &sh->dev[i];
711 struct bio *chosen; 657 struct bio *chosen;
712 int towrite;
713
714 towrite = 0;
715 if (prexor) { /* rmw */
716 if (dev->towrite &&
717 test_bit(R5_Wantprexor, &dev->flags))
718 towrite = 1;
719 } else { /* rcw */
720 if (i != pd_idx && dev->towrite &&
721 test_bit(R5_LOCKED, &dev->flags))
722 towrite = 1;
723 }
724 658
725 if (towrite) { 659 if (test_and_clear_bit(R5_Wantdrain, &dev->flags)) {
726 struct bio *wbi; 660 struct bio *wbi;
727 661
728 spin_lock(&sh->lock); 662 spin_lock(&sh->lock);
@@ -747,18 +681,6 @@ ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
747static void ops_complete_postxor(void *stripe_head_ref) 681static void ops_complete_postxor(void *stripe_head_ref)
748{ 682{
749 struct stripe_head *sh = stripe_head_ref; 683 struct stripe_head *sh = stripe_head_ref;
750
751 pr_debug("%s: stripe %llu\n", __func__,
752 (unsigned long long)sh->sector);
753
754 set_bit(STRIPE_OP_POSTXOR, &sh->ops.complete);
755 set_bit(STRIPE_HANDLE, &sh->state);
756 release_stripe(sh);
757}
758
759static void ops_complete_write(void *stripe_head_ref)
760{
761 struct stripe_head *sh = stripe_head_ref;
762 int disks = sh->disks, i, pd_idx = sh->pd_idx; 684 int disks = sh->disks, i, pd_idx = sh->pd_idx;
763 685
764 pr_debug("%s: stripe %llu\n", __func__, 686 pr_debug("%s: stripe %llu\n", __func__,
@@ -770,16 +692,21 @@ static void ops_complete_write(void *stripe_head_ref)
770 set_bit(R5_UPTODATE, &dev->flags); 692 set_bit(R5_UPTODATE, &dev->flags);
771 } 693 }
772 694
773 set_bit(STRIPE_OP_BIODRAIN, &sh->ops.complete); 695 if (sh->reconstruct_state == reconstruct_state_drain_run)
774 set_bit(STRIPE_OP_POSTXOR, &sh->ops.complete); 696 sh->reconstruct_state = reconstruct_state_drain_result;
697 else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run)
698 sh->reconstruct_state = reconstruct_state_prexor_drain_result;
699 else {
700 BUG_ON(sh->reconstruct_state != reconstruct_state_run);
701 sh->reconstruct_state = reconstruct_state_result;
702 }
775 703
776 set_bit(STRIPE_HANDLE, &sh->state); 704 set_bit(STRIPE_HANDLE, &sh->state);
777 release_stripe(sh); 705 release_stripe(sh);
778} 706}
779 707
780static void 708static void
781ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx, 709ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx)
782 unsigned long pending)
783{ 710{
784 /* kernel stack size limits the total number of disks */ 711 /* kernel stack size limits the total number of disks */
785 int disks = sh->disks; 712 int disks = sh->disks;
@@ -787,9 +714,8 @@ ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
787 714
788 int count = 0, pd_idx = sh->pd_idx, i; 715 int count = 0, pd_idx = sh->pd_idx, i;
789 struct page *xor_dest; 716 struct page *xor_dest;
790 int prexor = test_bit(STRIPE_OP_PREXOR, &pending); 717 int prexor = 0;
791 unsigned long flags; 718 unsigned long flags;
792 dma_async_tx_callback callback;
793 719
794 pr_debug("%s: stripe %llu\n", __func__, 720 pr_debug("%s: stripe %llu\n", __func__,
795 (unsigned long long)sh->sector); 721 (unsigned long long)sh->sector);
@@ -797,7 +723,8 @@ ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
797 /* check if prexor is active which means only process blocks 723 /* check if prexor is active which means only process blocks
798 * that are part of a read-modify-write (written) 724 * that are part of a read-modify-write (written)
799 */ 725 */
800 if (prexor) { 726 if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) {
727 prexor = 1;
801 xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; 728 xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page;
802 for (i = disks; i--; ) { 729 for (i = disks; i--; ) {
803 struct r5dev *dev = &sh->dev[i]; 730 struct r5dev *dev = &sh->dev[i];
@@ -813,10 +740,6 @@ ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
813 } 740 }
814 } 741 }
815 742
816 /* check whether this postxor is part of a write */
817 callback = test_bit(STRIPE_OP_BIODRAIN, &pending) ?
818 ops_complete_write : ops_complete_postxor;
819
820 /* 1/ if we prexor'd then the dest is reused as a source 743 /* 1/ if we prexor'd then the dest is reused as a source
821 * 2/ if we did not prexor then we are redoing the parity 744 * 2/ if we did not prexor then we are redoing the parity
822 * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST 745 * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST
@@ -830,25 +753,20 @@ ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
830 if (unlikely(count == 1)) { 753 if (unlikely(count == 1)) {
831 flags &= ~(ASYNC_TX_XOR_DROP_DST | ASYNC_TX_XOR_ZERO_DST); 754 flags &= ~(ASYNC_TX_XOR_DROP_DST | ASYNC_TX_XOR_ZERO_DST);
832 tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE, 755 tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE,
833 flags, tx, callback, sh); 756 flags, tx, ops_complete_postxor, sh);
834 } else 757 } else
835 tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, 758 tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE,
836 flags, tx, callback, sh); 759 flags, tx, ops_complete_postxor, sh);
837} 760}
838 761
839static void ops_complete_check(void *stripe_head_ref) 762static void ops_complete_check(void *stripe_head_ref)
840{ 763{
841 struct stripe_head *sh = stripe_head_ref; 764 struct stripe_head *sh = stripe_head_ref;
842 int pd_idx = sh->pd_idx;
843 765
844 pr_debug("%s: stripe %llu\n", __func__, 766 pr_debug("%s: stripe %llu\n", __func__,
845 (unsigned long long)sh->sector); 767 (unsigned long long)sh->sector);
846 768
847 if (test_and_clear_bit(STRIPE_OP_MOD_DMA_CHECK, &sh->ops.pending) && 769 sh->check_state = check_state_check_result;
848 sh->ops.zero_sum_result == 0)
849 set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags);
850
851 set_bit(STRIPE_OP_CHECK, &sh->ops.complete);
852 set_bit(STRIPE_HANDLE, &sh->state); 770 set_bit(STRIPE_HANDLE, &sh->state);
853 release_stripe(sh); 771 release_stripe(sh);
854} 772}
@@ -875,46 +793,42 @@ static void ops_run_check(struct stripe_head *sh)
875 tx = async_xor_zero_sum(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, 793 tx = async_xor_zero_sum(xor_dest, xor_srcs, 0, count, STRIPE_SIZE,
876 &sh->ops.zero_sum_result, 0, NULL, NULL, NULL); 794 &sh->ops.zero_sum_result, 0, NULL, NULL, NULL);
877 795
878 if (tx)
879 set_bit(STRIPE_OP_MOD_DMA_CHECK, &sh->ops.pending);
880 else
881 clear_bit(STRIPE_OP_MOD_DMA_CHECK, &sh->ops.pending);
882
883 atomic_inc(&sh->count); 796 atomic_inc(&sh->count);
884 tx = async_trigger_callback(ASYNC_TX_DEP_ACK | ASYNC_TX_ACK, tx, 797 tx = async_trigger_callback(ASYNC_TX_DEP_ACK | ASYNC_TX_ACK, tx,
885 ops_complete_check, sh); 798 ops_complete_check, sh);
886} 799}
887 800
888static void raid5_run_ops(struct stripe_head *sh, unsigned long pending) 801static void raid5_run_ops(struct stripe_head *sh, unsigned long ops_request)
889{ 802{
890 int overlap_clear = 0, i, disks = sh->disks; 803 int overlap_clear = 0, i, disks = sh->disks;
891 struct dma_async_tx_descriptor *tx = NULL; 804 struct dma_async_tx_descriptor *tx = NULL;
892 805
893 if (test_bit(STRIPE_OP_BIOFILL, &pending)) { 806 if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) {
894 ops_run_biofill(sh); 807 ops_run_biofill(sh);
895 overlap_clear++; 808 overlap_clear++;
896 } 809 }
897 810
898 if (test_bit(STRIPE_OP_COMPUTE_BLK, &pending)) 811 if (test_bit(STRIPE_OP_COMPUTE_BLK, &ops_request)) {
899 tx = ops_run_compute5(sh, pending); 812 tx = ops_run_compute5(sh);
813 /* terminate the chain if postxor is not set to be run */
814 if (tx && !test_bit(STRIPE_OP_POSTXOR, &ops_request))
815 async_tx_ack(tx);
816 }
900 817
901 if (test_bit(STRIPE_OP_PREXOR, &pending)) 818 if (test_bit(STRIPE_OP_PREXOR, &ops_request))
902 tx = ops_run_prexor(sh, tx); 819 tx = ops_run_prexor(sh, tx);
903 820
904 if (test_bit(STRIPE_OP_BIODRAIN, &pending)) { 821 if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) {
905 tx = ops_run_biodrain(sh, tx, pending); 822 tx = ops_run_biodrain(sh, tx);
906 overlap_clear++; 823 overlap_clear++;
907 } 824 }
908 825
909 if (test_bit(STRIPE_OP_POSTXOR, &pending)) 826 if (test_bit(STRIPE_OP_POSTXOR, &ops_request))
910 ops_run_postxor(sh, tx, pending); 827 ops_run_postxor(sh, tx);
911 828
912 if (test_bit(STRIPE_OP_CHECK, &pending)) 829 if (test_bit(STRIPE_OP_CHECK, &ops_request))
913 ops_run_check(sh); 830 ops_run_check(sh);
914 831
915 if (test_bit(STRIPE_OP_IO, &pending))
916 ops_run_io(sh);
917
918 if (overlap_clear) 832 if (overlap_clear)
919 for (i = disks; i--; ) { 833 for (i = disks; i--; ) {
920 struct r5dev *dev = &sh->dev[i]; 834 struct r5dev *dev = &sh->dev[i];
@@ -997,14 +911,16 @@ static int resize_stripes(raid5_conf_t *conf, int newsize)
997 struct stripe_head *osh, *nsh; 911 struct stripe_head *osh, *nsh;
998 LIST_HEAD(newstripes); 912 LIST_HEAD(newstripes);
999 struct disk_info *ndisks; 913 struct disk_info *ndisks;
1000 int err = 0; 914 int err;
1001 struct kmem_cache *sc; 915 struct kmem_cache *sc;
1002 int i; 916 int i;
1003 917
1004 if (newsize <= conf->pool_size) 918 if (newsize <= conf->pool_size)
1005 return 0; /* never bother to shrink */ 919 return 0; /* never bother to shrink */
1006 920
1007 md_allow_write(conf->mddev); 921 err = md_allow_write(conf->mddev);
922 if (err)
923 return err;
1008 924
1009 /* Step 1 */ 925 /* Step 1 */
1010 sc = kmem_cache_create(conf->cache_name[1-conf->active_name], 926 sc = kmem_cache_create(conf->cache_name[1-conf->active_name],
@@ -1703,11 +1619,11 @@ static void compute_block_2(struct stripe_head *sh, int dd_idx1, int dd_idx2)
1703 } 1619 }
1704} 1620}
1705 1621
1706static int 1622static void
1707handle_write_operations5(struct stripe_head *sh, int rcw, int expand) 1623schedule_reconstruction5(struct stripe_head *sh, struct stripe_head_state *s,
1624 int rcw, int expand)
1708{ 1625{
1709 int i, pd_idx = sh->pd_idx, disks = sh->disks; 1626 int i, pd_idx = sh->pd_idx, disks = sh->disks;
1710 int locked = 0;
1711 1627
1712 if (rcw) { 1628 if (rcw) {
1713 /* if we are not expanding this is a proper write request, and 1629 /* if we are not expanding this is a proper write request, and
@@ -1715,53 +1631,48 @@ handle_write_operations5(struct stripe_head *sh, int rcw, int expand)
1715 * stripe cache 1631 * stripe cache
1716 */ 1632 */
1717 if (!expand) { 1633 if (!expand) {
1718 set_bit(STRIPE_OP_BIODRAIN, &sh->ops.pending); 1634 sh->reconstruct_state = reconstruct_state_drain_run;
1719 sh->ops.count++; 1635 set_bit(STRIPE_OP_BIODRAIN, &s->ops_request);
1720 } 1636 } else
1637 sh->reconstruct_state = reconstruct_state_run;
1721 1638
1722 set_bit(STRIPE_OP_POSTXOR, &sh->ops.pending); 1639 set_bit(STRIPE_OP_POSTXOR, &s->ops_request);
1723 sh->ops.count++;
1724 1640
1725 for (i = disks; i--; ) { 1641 for (i = disks; i--; ) {
1726 struct r5dev *dev = &sh->dev[i]; 1642 struct r5dev *dev = &sh->dev[i];
1727 1643
1728 if (dev->towrite) { 1644 if (dev->towrite) {
1729 set_bit(R5_LOCKED, &dev->flags); 1645 set_bit(R5_LOCKED, &dev->flags);
1646 set_bit(R5_Wantdrain, &dev->flags);
1730 if (!expand) 1647 if (!expand)
1731 clear_bit(R5_UPTODATE, &dev->flags); 1648 clear_bit(R5_UPTODATE, &dev->flags);
1732 locked++; 1649 s->locked++;
1733 } 1650 }
1734 } 1651 }
1735 if (locked + 1 == disks) 1652 if (s->locked + 1 == disks)
1736 if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) 1653 if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state))
1737 atomic_inc(&sh->raid_conf->pending_full_writes); 1654 atomic_inc(&sh->raid_conf->pending_full_writes);
1738 } else { 1655 } else {
1739 BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || 1656 BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) ||
1740 test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); 1657 test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags)));
1741 1658
1742 set_bit(STRIPE_OP_PREXOR, &sh->ops.pending); 1659 sh->reconstruct_state = reconstruct_state_prexor_drain_run;
1743 set_bit(STRIPE_OP_BIODRAIN, &sh->ops.pending); 1660 set_bit(STRIPE_OP_PREXOR, &s->ops_request);
1744 set_bit(STRIPE_OP_POSTXOR, &sh->ops.pending); 1661 set_bit(STRIPE_OP_BIODRAIN, &s->ops_request);
1745 1662 set_bit(STRIPE_OP_POSTXOR, &s->ops_request);
1746 sh->ops.count += 3;
1747 1663
1748 for (i = disks; i--; ) { 1664 for (i = disks; i--; ) {
1749 struct r5dev *dev = &sh->dev[i]; 1665 struct r5dev *dev = &sh->dev[i];
1750 if (i == pd_idx) 1666 if (i == pd_idx)
1751 continue; 1667 continue;
1752 1668
1753 /* For a read-modify write there may be blocks that are
1754 * locked for reading while others are ready to be
1755 * written so we distinguish these blocks by the
1756 * R5_Wantprexor bit
1757 */
1758 if (dev->towrite && 1669 if (dev->towrite &&
1759 (test_bit(R5_UPTODATE, &dev->flags) || 1670 (test_bit(R5_UPTODATE, &dev->flags) ||
1760 test_bit(R5_Wantcompute, &dev->flags))) { 1671 test_bit(R5_Wantcompute, &dev->flags))) {
1761 set_bit(R5_Wantprexor, &dev->flags); 1672 set_bit(R5_Wantdrain, &dev->flags);
1762 set_bit(R5_LOCKED, &dev->flags); 1673 set_bit(R5_LOCKED, &dev->flags);
1763 clear_bit(R5_UPTODATE, &dev->flags); 1674 clear_bit(R5_UPTODATE, &dev->flags);
1764 locked++; 1675 s->locked++;
1765 } 1676 }
1766 } 1677 }
1767 } 1678 }
@@ -1771,13 +1682,11 @@ handle_write_operations5(struct stripe_head *sh, int rcw, int expand)
1771 */ 1682 */
1772 set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); 1683 set_bit(R5_LOCKED, &sh->dev[pd_idx].flags);
1773 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); 1684 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags);
1774 locked++; 1685 s->locked++;
1775 1686
1776 pr_debug("%s: stripe %llu locked: %d pending: %lx\n", 1687 pr_debug("%s: stripe %llu locked: %d ops_request: %lx\n",
1777 __func__, (unsigned long long)sh->sector, 1688 __func__, (unsigned long long)sh->sector,
1778 locked, sh->ops.pending); 1689 s->locked, s->ops_request);
1779
1780 return locked;
1781} 1690}
1782 1691
1783/* 1692/*
@@ -1876,7 +1785,7 @@ static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int disks)
1876} 1785}
1877 1786
1878static void 1787static void
1879handle_requests_to_failed_array(raid5_conf_t *conf, struct stripe_head *sh, 1788handle_failed_stripe(raid5_conf_t *conf, struct stripe_head *sh,
1880 struct stripe_head_state *s, int disks, 1789 struct stripe_head_state *s, int disks,
1881 struct bio **return_bi) 1790 struct bio **return_bi)
1882{ 1791{
@@ -1967,48 +1876,38 @@ handle_requests_to_failed_array(raid5_conf_t *conf, struct stripe_head *sh,
1967 md_wakeup_thread(conf->mddev->thread); 1876 md_wakeup_thread(conf->mddev->thread);
1968} 1877}
1969 1878
1970/* __handle_issuing_new_read_requests5 - returns 0 if there are no more disks 1879/* fetch_block5 - checks the given member device to see if its data needs
1971 * to process 1880 * to be read or computed to satisfy a request.
1881 *
1882 * Returns 1 when no more member devices need to be checked, otherwise returns
1883 * 0 to tell the loop in handle_stripe_fill5 to continue
1972 */ 1884 */
1973static int __handle_issuing_new_read_requests5(struct stripe_head *sh, 1885static int fetch_block5(struct stripe_head *sh, struct stripe_head_state *s,
1974 struct stripe_head_state *s, int disk_idx, int disks) 1886 int disk_idx, int disks)
1975{ 1887{
1976 struct r5dev *dev = &sh->dev[disk_idx]; 1888 struct r5dev *dev = &sh->dev[disk_idx];
1977 struct r5dev *failed_dev = &sh->dev[s->failed_num]; 1889 struct r5dev *failed_dev = &sh->dev[s->failed_num];
1978 1890
1979 /* don't schedule compute operations or reads on the parity block while
1980 * a check is in flight
1981 */
1982 if ((disk_idx == sh->pd_idx) &&
1983 test_bit(STRIPE_OP_CHECK, &sh->ops.pending))
1984 return ~0;
1985
1986 /* is the data in this block needed, and can we get it? */ 1891 /* is the data in this block needed, and can we get it? */
1987 if (!test_bit(R5_LOCKED, &dev->flags) && 1892 if (!test_bit(R5_LOCKED, &dev->flags) &&
1988 !test_bit(R5_UPTODATE, &dev->flags) && (dev->toread || 1893 !test_bit(R5_UPTODATE, &dev->flags) &&
1989 (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || 1894 (dev->toread ||
1990 s->syncing || s->expanding || (s->failed && 1895 (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) ||
1991 (failed_dev->toread || (failed_dev->towrite && 1896 s->syncing || s->expanding ||
1992 !test_bit(R5_OVERWRITE, &failed_dev->flags) 1897 (s->failed &&
1993 ))))) { 1898 (failed_dev->toread ||
1994 /* 1/ We would like to get this block, possibly by computing it, 1899 (failed_dev->towrite &&
1995 * but we might not be able to. 1900 !test_bit(R5_OVERWRITE, &failed_dev->flags)))))) {
1996 * 1901 /* We would like to get this block, possibly by computing it,
1997 * 2/ Since parity check operations potentially make the parity 1902 * otherwise read it if the backing disk is insync
1998 * block !uptodate it will need to be refreshed before any
1999 * compute operations on data disks are scheduled.
2000 *
2001 * 3/ We hold off parity block re-reads until check operations
2002 * have quiesced.
2003 */ 1903 */
2004 if ((s->uptodate == disks - 1) && 1904 if ((s->uptodate == disks - 1) &&
2005 (s->failed && disk_idx == s->failed_num) && 1905 (s->failed && disk_idx == s->failed_num)) {
2006 !test_bit(STRIPE_OP_CHECK, &sh->ops.pending)) { 1906 set_bit(STRIPE_COMPUTE_RUN, &sh->state);
2007 set_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending); 1907 set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request);
2008 set_bit(R5_Wantcompute, &dev->flags); 1908 set_bit(R5_Wantcompute, &dev->flags);
2009 sh->ops.target = disk_idx; 1909 sh->ops.target = disk_idx;
2010 s->req_compute = 1; 1910 s->req_compute = 1;
2011 sh->ops.count++;
2012 /* Careful: from this point on 'uptodate' is in the eye 1911 /* Careful: from this point on 'uptodate' is in the eye
2013 * of raid5_run_ops which services 'compute' operations 1912 * of raid5_run_ops which services 'compute' operations
2014 * before writes. R5_Wantcompute flags a block that will 1913 * before writes. R5_Wantcompute flags a block that will
@@ -2016,53 +1915,40 @@ static int __handle_issuing_new_read_requests5(struct stripe_head *sh,
2016 * subsequent operation. 1915 * subsequent operation.
2017 */ 1916 */
2018 s->uptodate++; 1917 s->uptodate++;
2019 return 0; /* uptodate + compute == disks */ 1918 return 1; /* uptodate + compute == disks */
2020 } else if (test_bit(R5_Insync, &dev->flags)) { 1919 } else if (test_bit(R5_Insync, &dev->flags)) {
2021 set_bit(R5_LOCKED, &dev->flags); 1920 set_bit(R5_LOCKED, &dev->flags);
2022 set_bit(R5_Wantread, &dev->flags); 1921 set_bit(R5_Wantread, &dev->flags);
2023 if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending))
2024 sh->ops.count++;
2025 s->locked++; 1922 s->locked++;
2026 pr_debug("Reading block %d (sync=%d)\n", disk_idx, 1923 pr_debug("Reading block %d (sync=%d)\n", disk_idx,
2027 s->syncing); 1924 s->syncing);
2028 } 1925 }
2029 } 1926 }
2030 1927
2031 return ~0; 1928 return 0;
2032} 1929}
2033 1930
2034static void handle_issuing_new_read_requests5(struct stripe_head *sh, 1931/**
1932 * handle_stripe_fill5 - read or compute data to satisfy pending requests.
1933 */
1934static void handle_stripe_fill5(struct stripe_head *sh,
2035 struct stripe_head_state *s, int disks) 1935 struct stripe_head_state *s, int disks)
2036{ 1936{
2037 int i; 1937 int i;
2038 1938
2039 /* Clear completed compute operations. Parity recovery
2040 * (STRIPE_OP_MOD_REPAIR_PD) implies a write-back which is handled
2041 * later on in this routine
2042 */
2043 if (test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete) &&
2044 !test_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending)) {
2045 clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete);
2046 clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.ack);
2047 clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending);
2048 }
2049
2050 /* look for blocks to read/compute, skip this if a compute 1939 /* look for blocks to read/compute, skip this if a compute
2051 * is already in flight, or if the stripe contents are in the 1940 * is already in flight, or if the stripe contents are in the
2052 * midst of changing due to a write 1941 * midst of changing due to a write
2053 */ 1942 */
2054 if (!test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending) && 1943 if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state &&
2055 !test_bit(STRIPE_OP_PREXOR, &sh->ops.pending) && 1944 !sh->reconstruct_state)
2056 !test_bit(STRIPE_OP_POSTXOR, &sh->ops.pending)) {
2057 for (i = disks; i--; ) 1945 for (i = disks; i--; )
2058 if (__handle_issuing_new_read_requests5( 1946 if (fetch_block5(sh, s, i, disks))
2059 sh, s, i, disks) == 0)
2060 break; 1947 break;
2061 }
2062 set_bit(STRIPE_HANDLE, &sh->state); 1948 set_bit(STRIPE_HANDLE, &sh->state);
2063} 1949}
2064 1950
2065static void handle_issuing_new_read_requests6(struct stripe_head *sh, 1951static void handle_stripe_fill6(struct stripe_head *sh,
2066 struct stripe_head_state *s, struct r6_state *r6s, 1952 struct stripe_head_state *s, struct r6_state *r6s,
2067 int disks) 1953 int disks)
2068{ 1954{
@@ -2121,12 +2007,12 @@ static void handle_issuing_new_read_requests6(struct stripe_head *sh,
2121} 2007}
2122 2008
2123 2009
2124/* handle_completed_write_requests 2010/* handle_stripe_clean_event
2125 * any written block on an uptodate or failed drive can be returned. 2011 * any written block on an uptodate or failed drive can be returned.
2126 * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but 2012 * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but
2127 * never LOCKED, so we don't need to test 'failed' directly. 2013 * never LOCKED, so we don't need to test 'failed' directly.
2128 */ 2014 */
2129static void handle_completed_write_requests(raid5_conf_t *conf, 2015static void handle_stripe_clean_event(raid5_conf_t *conf,
2130 struct stripe_head *sh, int disks, struct bio **return_bi) 2016 struct stripe_head *sh, int disks, struct bio **return_bi)
2131{ 2017{
2132 int i; 2018 int i;
@@ -2171,7 +2057,7 @@ static void handle_completed_write_requests(raid5_conf_t *conf,
2171 md_wakeup_thread(conf->mddev->thread); 2057 md_wakeup_thread(conf->mddev->thread);
2172} 2058}
2173 2059
2174static void handle_issuing_new_write_requests5(raid5_conf_t *conf, 2060static void handle_stripe_dirtying5(raid5_conf_t *conf,
2175 struct stripe_head *sh, struct stripe_head_state *s, int disks) 2061 struct stripe_head *sh, struct stripe_head_state *s, int disks)
2176{ 2062{
2177 int rmw = 0, rcw = 0, i; 2063 int rmw = 0, rcw = 0, i;
@@ -2215,9 +2101,6 @@ static void handle_issuing_new_write_requests5(raid5_conf_t *conf,
2215 "%d for r-m-w\n", i); 2101 "%d for r-m-w\n", i);
2216 set_bit(R5_LOCKED, &dev->flags); 2102 set_bit(R5_LOCKED, &dev->flags);
2217 set_bit(R5_Wantread, &dev->flags); 2103 set_bit(R5_Wantread, &dev->flags);
2218 if (!test_and_set_bit(
2219 STRIPE_OP_IO, &sh->ops.pending))
2220 sh->ops.count++;
2221 s->locked++; 2104 s->locked++;
2222 } else { 2105 } else {
2223 set_bit(STRIPE_DELAYED, &sh->state); 2106 set_bit(STRIPE_DELAYED, &sh->state);
@@ -2241,9 +2124,6 @@ static void handle_issuing_new_write_requests5(raid5_conf_t *conf,
2241 "%d for Reconstruct\n", i); 2124 "%d for Reconstruct\n", i);
2242 set_bit(R5_LOCKED, &dev->flags); 2125 set_bit(R5_LOCKED, &dev->flags);
2243 set_bit(R5_Wantread, &dev->flags); 2126 set_bit(R5_Wantread, &dev->flags);
2244 if (!test_and_set_bit(
2245 STRIPE_OP_IO, &sh->ops.pending))
2246 sh->ops.count++;
2247 s->locked++; 2127 s->locked++;
2248 } else { 2128 } else {
2249 set_bit(STRIPE_DELAYED, &sh->state); 2129 set_bit(STRIPE_DELAYED, &sh->state);
@@ -2261,14 +2141,13 @@ static void handle_issuing_new_write_requests5(raid5_conf_t *conf,
2261 * simultaneously. If this is not the case then new writes need to be 2141 * simultaneously. If this is not the case then new writes need to be
2262 * held off until the compute completes. 2142 * held off until the compute completes.
2263 */ 2143 */
2264 if ((s->req_compute || 2144 if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) &&
2265 !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending)) && 2145 (s->locked == 0 && (rcw == 0 || rmw == 0) &&
2266 (s->locked == 0 && (rcw == 0 || rmw == 0) && 2146 !test_bit(STRIPE_BIT_DELAY, &sh->state)))
2267 !test_bit(STRIPE_BIT_DELAY, &sh->state))) 2147 schedule_reconstruction5(sh, s, rcw == 0, 0);
2268 s->locked += handle_write_operations5(sh, rcw == 0, 0);
2269} 2148}
2270 2149
2271static void handle_issuing_new_write_requests6(raid5_conf_t *conf, 2150static void handle_stripe_dirtying6(raid5_conf_t *conf,
2272 struct stripe_head *sh, struct stripe_head_state *s, 2151 struct stripe_head *sh, struct stripe_head_state *s,
2273 struct r6_state *r6s, int disks) 2152 struct r6_state *r6s, int disks)
2274{ 2153{
@@ -2371,92 +2250,86 @@ static void handle_issuing_new_write_requests6(raid5_conf_t *conf,
2371static void handle_parity_checks5(raid5_conf_t *conf, struct stripe_head *sh, 2250static void handle_parity_checks5(raid5_conf_t *conf, struct stripe_head *sh,
2372 struct stripe_head_state *s, int disks) 2251 struct stripe_head_state *s, int disks)
2373{ 2252{
2374 int canceled_check = 0; 2253 struct r5dev *dev = NULL;
2375 2254
2376 set_bit(STRIPE_HANDLE, &sh->state); 2255 set_bit(STRIPE_HANDLE, &sh->state);
2377 2256
2378 /* complete a check operation */ 2257 switch (sh->check_state) {
2379 if (test_and_clear_bit(STRIPE_OP_CHECK, &sh->ops.complete)) { 2258 case check_state_idle:
2380 clear_bit(STRIPE_OP_CHECK, &sh->ops.ack); 2259 /* start a new check operation if there are no failures */
2381 clear_bit(STRIPE_OP_CHECK, &sh->ops.pending);
2382 if (s->failed == 0) { 2260 if (s->failed == 0) {
2383 if (sh->ops.zero_sum_result == 0)
2384 /* parity is correct (on disc,
2385 * not in buffer any more)
2386 */
2387 set_bit(STRIPE_INSYNC, &sh->state);
2388 else {
2389 conf->mddev->resync_mismatches +=
2390 STRIPE_SECTORS;
2391 if (test_bit(
2392 MD_RECOVERY_CHECK, &conf->mddev->recovery))
2393 /* don't try to repair!! */
2394 set_bit(STRIPE_INSYNC, &sh->state);
2395 else {
2396 set_bit(STRIPE_OP_COMPUTE_BLK,
2397 &sh->ops.pending);
2398 set_bit(STRIPE_OP_MOD_REPAIR_PD,
2399 &sh->ops.pending);
2400 set_bit(R5_Wantcompute,
2401 &sh->dev[sh->pd_idx].flags);
2402 sh->ops.target = sh->pd_idx;
2403 sh->ops.count++;
2404 s->uptodate++;
2405 }
2406 }
2407 } else
2408 canceled_check = 1; /* STRIPE_INSYNC is not set */
2409 }
2410
2411 /* start a new check operation if there are no failures, the stripe is
2412 * not insync, and a repair is not in flight
2413 */
2414 if (s->failed == 0 &&
2415 !test_bit(STRIPE_INSYNC, &sh->state) &&
2416 !test_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending)) {
2417 if (!test_and_set_bit(STRIPE_OP_CHECK, &sh->ops.pending)) {
2418 BUG_ON(s->uptodate != disks); 2261 BUG_ON(s->uptodate != disks);
2262 sh->check_state = check_state_run;
2263 set_bit(STRIPE_OP_CHECK, &s->ops_request);
2419 clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); 2264 clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags);
2420 sh->ops.count++;
2421 s->uptodate--; 2265 s->uptodate--;
2266 break;
2422 } 2267 }
2423 } 2268 dev = &sh->dev[s->failed_num];
2424 2269 /* fall through */
2425 /* check if we can clear a parity disk reconstruct */ 2270 case check_state_compute_result:
2426 if (test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete) && 2271 sh->check_state = check_state_idle;
2427 test_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending)) { 2272 if (!dev)
2428 2273 dev = &sh->dev[sh->pd_idx];
2429 clear_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending); 2274
2430 clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete); 2275 /* check that a write has not made the stripe insync */
2431 clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.ack); 2276 if (test_bit(STRIPE_INSYNC, &sh->state))
2432 clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending); 2277 break;
2433 }
2434
2435 2278
2436 /* Wait for check parity and compute block operations to complete
2437 * before write-back. If a failure occurred while the check operation
2438 * was in flight we need to cycle this stripe through handle_stripe
2439 * since the parity block may not be uptodate
2440 */
2441 if (!canceled_check && !test_bit(STRIPE_INSYNC, &sh->state) &&
2442 !test_bit(STRIPE_OP_CHECK, &sh->ops.pending) &&
2443 !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending)) {
2444 struct r5dev *dev;
2445 /* either failed parity check, or recovery is happening */ 2279 /* either failed parity check, or recovery is happening */
2446 if (s->failed == 0)
2447 s->failed_num = sh->pd_idx;
2448 dev = &sh->dev[s->failed_num];
2449 BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); 2280 BUG_ON(!test_bit(R5_UPTODATE, &dev->flags));
2450 BUG_ON(s->uptodate != disks); 2281 BUG_ON(s->uptodate != disks);
2451 2282
2452 set_bit(R5_LOCKED, &dev->flags); 2283 set_bit(R5_LOCKED, &dev->flags);
2284 s->locked++;
2453 set_bit(R5_Wantwrite, &dev->flags); 2285 set_bit(R5_Wantwrite, &dev->flags);
2454 if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending))
2455 sh->ops.count++;
2456 2286
2457 clear_bit(STRIPE_DEGRADED, &sh->state); 2287 clear_bit(STRIPE_DEGRADED, &sh->state);
2458 s->locked++;
2459 set_bit(STRIPE_INSYNC, &sh->state); 2288 set_bit(STRIPE_INSYNC, &sh->state);
2289 break;
2290 case check_state_run:
2291 break; /* we will be called again upon completion */
2292 case check_state_check_result:
2293 sh->check_state = check_state_idle;
2294
2295 /* if a failure occurred during the check operation, leave
2296 * STRIPE_INSYNC not set and let the stripe be handled again
2297 */
2298 if (s->failed)
2299 break;
2300
2301 /* handle a successful check operation, if parity is correct
2302 * we are done. Otherwise update the mismatch count and repair
2303 * parity if !MD_RECOVERY_CHECK
2304 */
2305 if (sh->ops.zero_sum_result == 0)
2306 /* parity is correct (on disc,
2307 * not in buffer any more)
2308 */
2309 set_bit(STRIPE_INSYNC, &sh->state);
2310 else {
2311 conf->mddev->resync_mismatches += STRIPE_SECTORS;
2312 if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery))
2313 /* don't try to repair!! */
2314 set_bit(STRIPE_INSYNC, &sh->state);
2315 else {
2316 sh->check_state = check_state_compute_run;
2317 set_bit(STRIPE_COMPUTE_RUN, &sh->state);
2318 set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request);
2319 set_bit(R5_Wantcompute,
2320 &sh->dev[sh->pd_idx].flags);
2321 sh->ops.target = sh->pd_idx;
2322 s->uptodate++;
2323 }
2324 }
2325 break;
2326 case check_state_compute_run:
2327 break;
2328 default:
2329 printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n",
2330 __func__, sh->check_state,
2331 (unsigned long long) sh->sector);
2332 BUG();
2460 } 2333 }
2461} 2334}
2462 2335
@@ -2641,15 +2514,14 @@ static void handle_stripe5(struct stripe_head *sh)
2641 struct bio *return_bi = NULL; 2514 struct bio *return_bi = NULL;
2642 struct stripe_head_state s; 2515 struct stripe_head_state s;
2643 struct r5dev *dev; 2516 struct r5dev *dev;
2644 unsigned long pending = 0;
2645 mdk_rdev_t *blocked_rdev = NULL; 2517 mdk_rdev_t *blocked_rdev = NULL;
2646 int prexor; 2518 int prexor;
2647 2519
2648 memset(&s, 0, sizeof(s)); 2520 memset(&s, 0, sizeof(s));
2649 pr_debug("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d " 2521 pr_debug("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d check:%d "
2650 "ops=%lx:%lx:%lx\n", (unsigned long long)sh->sector, sh->state, 2522 "reconstruct:%d\n", (unsigned long long)sh->sector, sh->state,
2651 atomic_read(&sh->count), sh->pd_idx, 2523 atomic_read(&sh->count), sh->pd_idx, sh->check_state,
2652 sh->ops.pending, sh->ops.ack, sh->ops.complete); 2524 sh->reconstruct_state);
2653 2525
2654 spin_lock(&sh->lock); 2526 spin_lock(&sh->lock);
2655 clear_bit(STRIPE_HANDLE, &sh->state); 2527 clear_bit(STRIPE_HANDLE, &sh->state);
@@ -2658,15 +2530,8 @@ static void handle_stripe5(struct stripe_head *sh)
2658 s.syncing = test_bit(STRIPE_SYNCING, &sh->state); 2530 s.syncing = test_bit(STRIPE_SYNCING, &sh->state);
2659 s.expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state); 2531 s.expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state);
2660 s.expanded = test_bit(STRIPE_EXPAND_READY, &sh->state); 2532 s.expanded = test_bit(STRIPE_EXPAND_READY, &sh->state);
2661 /* Now to look around and see what can be done */
2662
2663 /* clean-up completed biofill operations */
2664 if (test_bit(STRIPE_OP_BIOFILL, &sh->ops.complete)) {
2665 clear_bit(STRIPE_OP_BIOFILL, &sh->ops.pending);
2666 clear_bit(STRIPE_OP_BIOFILL, &sh->ops.ack);
2667 clear_bit(STRIPE_OP_BIOFILL, &sh->ops.complete);
2668 }
2669 2533
2534 /* Now to look around and see what can be done */
2670 rcu_read_lock(); 2535 rcu_read_lock();
2671 for (i=disks; i--; ) { 2536 for (i=disks; i--; ) {
2672 mdk_rdev_t *rdev; 2537 mdk_rdev_t *rdev;
@@ -2680,10 +2545,10 @@ static void handle_stripe5(struct stripe_head *sh)
2680 /* maybe we can request a biofill operation 2545 /* maybe we can request a biofill operation
2681 * 2546 *
2682 * new wantfill requests are only permitted while 2547 * new wantfill requests are only permitted while
2683 * STRIPE_OP_BIOFILL is clear 2548 * ops_complete_biofill is guaranteed to be inactive
2684 */ 2549 */
2685 if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && 2550 if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread &&
2686 !test_bit(STRIPE_OP_BIOFILL, &sh->ops.pending)) 2551 !test_bit(STRIPE_BIOFILL_RUN, &sh->state))
2687 set_bit(R5_Wantfill, &dev->flags); 2552 set_bit(R5_Wantfill, &dev->flags);
2688 2553
2689 /* now count some things */ 2554 /* now count some things */
@@ -2727,8 +2592,10 @@ static void handle_stripe5(struct stripe_head *sh)
2727 goto unlock; 2592 goto unlock;
2728 } 2593 }
2729 2594
2730 if (s.to_fill && !test_and_set_bit(STRIPE_OP_BIOFILL, &sh->ops.pending)) 2595 if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) {
2731 sh->ops.count++; 2596 set_bit(STRIPE_OP_BIOFILL, &s.ops_request);
2597 set_bit(STRIPE_BIOFILL_RUN, &sh->state);
2598 }
2732 2599
2733 pr_debug("locked=%d uptodate=%d to_read=%d" 2600 pr_debug("locked=%d uptodate=%d to_read=%d"
2734 " to_write=%d failed=%d failed_num=%d\n", 2601 " to_write=%d failed=%d failed_num=%d\n",
@@ -2738,8 +2605,7 @@ static void handle_stripe5(struct stripe_head *sh)
2738 * need to be failed 2605 * need to be failed
2739 */ 2606 */
2740 if (s.failed > 1 && s.to_read+s.to_write+s.written) 2607 if (s.failed > 1 && s.to_read+s.to_write+s.written)
2741 handle_requests_to_failed_array(conf, sh, &s, disks, 2608 handle_failed_stripe(conf, sh, &s, disks, &return_bi);
2742 &return_bi);
2743 if (s.failed > 1 && s.syncing) { 2609 if (s.failed > 1 && s.syncing) {
2744 md_done_sync(conf->mddev, STRIPE_SECTORS,0); 2610 md_done_sync(conf->mddev, STRIPE_SECTORS,0);
2745 clear_bit(STRIPE_SYNCING, &sh->state); 2611 clear_bit(STRIPE_SYNCING, &sh->state);
@@ -2755,48 +2621,25 @@ static void handle_stripe5(struct stripe_head *sh)
2755 !test_bit(R5_LOCKED, &dev->flags) && 2621 !test_bit(R5_LOCKED, &dev->flags) &&
2756 test_bit(R5_UPTODATE, &dev->flags)) || 2622 test_bit(R5_UPTODATE, &dev->flags)) ||
2757 (s.failed == 1 && s.failed_num == sh->pd_idx))) 2623 (s.failed == 1 && s.failed_num == sh->pd_idx)))
2758 handle_completed_write_requests(conf, sh, disks, &return_bi); 2624 handle_stripe_clean_event(conf, sh, disks, &return_bi);
2759 2625
2760 /* Now we might consider reading some blocks, either to check/generate 2626 /* Now we might consider reading some blocks, either to check/generate
2761 * parity, or to satisfy requests 2627 * parity, or to satisfy requests
2762 * or to load a block that is being partially written. 2628 * or to load a block that is being partially written.
2763 */ 2629 */
2764 if (s.to_read || s.non_overwrite || 2630 if (s.to_read || s.non_overwrite ||
2765 (s.syncing && (s.uptodate + s.compute < disks)) || s.expanding || 2631 (s.syncing && (s.uptodate + s.compute < disks)) || s.expanding)
2766 test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending)) 2632 handle_stripe_fill5(sh, &s, disks);
2767 handle_issuing_new_read_requests5(sh, &s, disks);
2768 2633
2769 /* Now we check to see if any write operations have recently 2634 /* Now we check to see if any write operations have recently
2770 * completed 2635 * completed
2771 */ 2636 */
2772
2773 /* leave prexor set until postxor is done, allows us to distinguish
2774 * a rmw from a rcw during biodrain
2775 */
2776 prexor = 0; 2637 prexor = 0;
2777 if (test_bit(STRIPE_OP_PREXOR, &sh->ops.complete) && 2638 if (sh->reconstruct_state == reconstruct_state_prexor_drain_result)
2778 test_bit(STRIPE_OP_POSTXOR, &sh->ops.complete)) {
2779
2780 prexor = 1; 2639 prexor = 1;
2781 clear_bit(STRIPE_OP_PREXOR, &sh->ops.complete); 2640 if (sh->reconstruct_state == reconstruct_state_drain_result ||
2782 clear_bit(STRIPE_OP_PREXOR, &sh->ops.ack); 2641 sh->reconstruct_state == reconstruct_state_prexor_drain_result) {
2783 clear_bit(STRIPE_OP_PREXOR, &sh->ops.pending); 2642 sh->reconstruct_state = reconstruct_state_idle;
2784
2785 for (i = disks; i--; )
2786 clear_bit(R5_Wantprexor, &sh->dev[i].flags);
2787 }
2788
2789 /* if only POSTXOR is set then this is an 'expand' postxor */
2790 if (test_bit(STRIPE_OP_BIODRAIN, &sh->ops.complete) &&
2791 test_bit(STRIPE_OP_POSTXOR, &sh->ops.complete)) {
2792
2793 clear_bit(STRIPE_OP_BIODRAIN, &sh->ops.complete);
2794 clear_bit(STRIPE_OP_BIODRAIN, &sh->ops.ack);
2795 clear_bit(STRIPE_OP_BIODRAIN, &sh->ops.pending);
2796
2797 clear_bit(STRIPE_OP_POSTXOR, &sh->ops.complete);
2798 clear_bit(STRIPE_OP_POSTXOR, &sh->ops.ack);
2799 clear_bit(STRIPE_OP_POSTXOR, &sh->ops.pending);
2800 2643
2801 /* All the 'written' buffers and the parity block are ready to 2644 /* All the 'written' buffers and the parity block are ready to
2802 * be written back to disk 2645 * be written back to disk
@@ -2808,9 +2651,6 @@ static void handle_stripe5(struct stripe_head *sh)
2808 (i == sh->pd_idx || dev->written)) { 2651 (i == sh->pd_idx || dev->written)) {
2809 pr_debug("Writing block %d\n", i); 2652 pr_debug("Writing block %d\n", i);
2810 set_bit(R5_Wantwrite, &dev->flags); 2653 set_bit(R5_Wantwrite, &dev->flags);
2811 if (!test_and_set_bit(
2812 STRIPE_OP_IO, &sh->ops.pending))
2813 sh->ops.count++;
2814 if (prexor) 2654 if (prexor)
2815 continue; 2655 continue;
2816 if (!test_bit(R5_Insync, &dev->flags) || 2656 if (!test_bit(R5_Insync, &dev->flags) ||
@@ -2832,20 +2672,18 @@ static void handle_stripe5(struct stripe_head *sh)
2832 * 2/ A 'check' operation is in flight, as it may clobber the parity 2672 * 2/ A 'check' operation is in flight, as it may clobber the parity
2833 * block. 2673 * block.
2834 */ 2674 */
2835 if (s.to_write && !test_bit(STRIPE_OP_POSTXOR, &sh->ops.pending) && 2675 if (s.to_write && !sh->reconstruct_state && !sh->check_state)
2836 !test_bit(STRIPE_OP_CHECK, &sh->ops.pending)) 2676 handle_stripe_dirtying5(conf, sh, &s, disks);
2837 handle_issuing_new_write_requests5(conf, sh, &s, disks);
2838 2677
2839 /* maybe we need to check and possibly fix the parity for this stripe 2678 /* maybe we need to check and possibly fix the parity for this stripe
2840 * Any reads will already have been scheduled, so we just see if enough 2679 * Any reads will already have been scheduled, so we just see if enough
2841 * data is available. The parity check is held off while parity 2680 * data is available. The parity check is held off while parity
2842 * dependent operations are in flight. 2681 * dependent operations are in flight.
2843 */ 2682 */
2844 if ((s.syncing && s.locked == 0 && 2683 if (sh->check_state ||
2845 !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending) && 2684 (s.syncing && s.locked == 0 &&
2846 !test_bit(STRIPE_INSYNC, &sh->state)) || 2685 !test_bit(STRIPE_COMPUTE_RUN, &sh->state) &&
2847 test_bit(STRIPE_OP_CHECK, &sh->ops.pending) || 2686 !test_bit(STRIPE_INSYNC, &sh->state)))
2848 test_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending))
2849 handle_parity_checks5(conf, sh, &s, disks); 2687 handle_parity_checks5(conf, sh, &s, disks);
2850 2688
2851 if (s.syncing && s.locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { 2689 if (s.syncing && s.locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) {
@@ -2864,52 +2702,35 @@ static void handle_stripe5(struct stripe_head *sh)
2864 dev = &sh->dev[s.failed_num]; 2702 dev = &sh->dev[s.failed_num];
2865 if (!test_bit(R5_ReWrite, &dev->flags)) { 2703 if (!test_bit(R5_ReWrite, &dev->flags)) {
2866 set_bit(R5_Wantwrite, &dev->flags); 2704 set_bit(R5_Wantwrite, &dev->flags);
2867 if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending))
2868 sh->ops.count++;
2869 set_bit(R5_ReWrite, &dev->flags); 2705 set_bit(R5_ReWrite, &dev->flags);
2870 set_bit(R5_LOCKED, &dev->flags); 2706 set_bit(R5_LOCKED, &dev->flags);
2871 s.locked++; 2707 s.locked++;
2872 } else { 2708 } else {
2873 /* let's read it back */ 2709 /* let's read it back */
2874 set_bit(R5_Wantread, &dev->flags); 2710 set_bit(R5_Wantread, &dev->flags);
2875 if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending))
2876 sh->ops.count++;
2877 set_bit(R5_LOCKED, &dev->flags); 2711 set_bit(R5_LOCKED, &dev->flags);
2878 s.locked++; 2712 s.locked++;
2879 } 2713 }
2880 } 2714 }
2881 2715
2882 /* Finish postxor operations initiated by the expansion 2716 /* Finish reconstruct operations initiated by the expansion process */
2883 * process 2717 if (sh->reconstruct_state == reconstruct_state_result) {
2884 */ 2718 sh->reconstruct_state = reconstruct_state_idle;
2885 if (test_bit(STRIPE_OP_POSTXOR, &sh->ops.complete) &&
2886 !test_bit(STRIPE_OP_BIODRAIN, &sh->ops.pending)) {
2887
2888 clear_bit(STRIPE_EXPANDING, &sh->state); 2719 clear_bit(STRIPE_EXPANDING, &sh->state);
2889 2720 for (i = conf->raid_disks; i--; )
2890 clear_bit(STRIPE_OP_POSTXOR, &sh->ops.pending);
2891 clear_bit(STRIPE_OP_POSTXOR, &sh->ops.ack);
2892 clear_bit(STRIPE_OP_POSTXOR, &sh->ops.complete);
2893
2894 for (i = conf->raid_disks; i--; ) {
2895 set_bit(R5_Wantwrite, &sh->dev[i].flags); 2721 set_bit(R5_Wantwrite, &sh->dev[i].flags);
2896 set_bit(R5_LOCKED, &dev->flags); 2722 set_bit(R5_LOCKED, &dev->flags);
2897 s.locked++; 2723 s.locked++;
2898 if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending))
2899 sh->ops.count++;
2900 }
2901 } 2724 }
2902 2725
2903 if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && 2726 if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) &&
2904 !test_bit(STRIPE_OP_POSTXOR, &sh->ops.pending)) { 2727 !sh->reconstruct_state) {
2905 /* Need to write out all blocks after computing parity */ 2728 /* Need to write out all blocks after computing parity */
2906 sh->disks = conf->raid_disks; 2729 sh->disks = conf->raid_disks;
2907 sh->pd_idx = stripe_to_pdidx(sh->sector, conf, 2730 sh->pd_idx = stripe_to_pdidx(sh->sector, conf,
2908 conf->raid_disks); 2731 conf->raid_disks);
2909 s.locked += handle_write_operations5(sh, 1, 1); 2732 schedule_reconstruction5(sh, &s, 1, 1);
2910 } else if (s.expanded && 2733 } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) {
2911 s.locked == 0 &&
2912 !test_bit(STRIPE_OP_POSTXOR, &sh->ops.pending)) {
2913 clear_bit(STRIPE_EXPAND_READY, &sh->state); 2734 clear_bit(STRIPE_EXPAND_READY, &sh->state);
2914 atomic_dec(&conf->reshape_stripes); 2735 atomic_dec(&conf->reshape_stripes);
2915 wake_up(&conf->wait_for_overlap); 2736 wake_up(&conf->wait_for_overlap);
@@ -2917,12 +2738,9 @@ static void handle_stripe5(struct stripe_head *sh)
2917 } 2738 }
2918 2739
2919 if (s.expanding && s.locked == 0 && 2740 if (s.expanding && s.locked == 0 &&
2920 !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending)) 2741 !test_bit(STRIPE_COMPUTE_RUN, &sh->state))
2921 handle_stripe_expansion(conf, sh, NULL); 2742 handle_stripe_expansion(conf, sh, NULL);
2922 2743
2923 if (sh->ops.count)
2924 pending = get_stripe_work(sh);
2925
2926 unlock: 2744 unlock:
2927 spin_unlock(&sh->lock); 2745 spin_unlock(&sh->lock);
2928 2746
@@ -2930,11 +2748,12 @@ static void handle_stripe5(struct stripe_head *sh)
2930 if (unlikely(blocked_rdev)) 2748 if (unlikely(blocked_rdev))
2931 md_wait_for_blocked_rdev(blocked_rdev, conf->mddev); 2749 md_wait_for_blocked_rdev(blocked_rdev, conf->mddev);
2932 2750
2933 if (pending) 2751 if (s.ops_request)
2934 raid5_run_ops(sh, pending); 2752 raid5_run_ops(sh, s.ops_request);
2935 2753
2936 return_io(return_bi); 2754 ops_run_io(sh, &s);
2937 2755
2756 return_io(return_bi);
2938} 2757}
2939 2758
2940static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page) 2759static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
@@ -3042,8 +2861,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
3042 * might need to be failed 2861 * might need to be failed
3043 */ 2862 */
3044 if (s.failed > 2 && s.to_read+s.to_write+s.written) 2863 if (s.failed > 2 && s.to_read+s.to_write+s.written)
3045 handle_requests_to_failed_array(conf, sh, &s, disks, 2864 handle_failed_stripe(conf, sh, &s, disks, &return_bi);
3046 &return_bi);
3047 if (s.failed > 2 && s.syncing) { 2865 if (s.failed > 2 && s.syncing) {
3048 md_done_sync(conf->mddev, STRIPE_SECTORS,0); 2866 md_done_sync(conf->mddev, STRIPE_SECTORS,0);
3049 clear_bit(STRIPE_SYNCING, &sh->state); 2867 clear_bit(STRIPE_SYNCING, &sh->state);
@@ -3068,7 +2886,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
3068 ( r6s.q_failed || ((test_bit(R5_Insync, &qdev->flags) 2886 ( r6s.q_failed || ((test_bit(R5_Insync, &qdev->flags)
3069 && !test_bit(R5_LOCKED, &qdev->flags) 2887 && !test_bit(R5_LOCKED, &qdev->flags)
3070 && test_bit(R5_UPTODATE, &qdev->flags))))) 2888 && test_bit(R5_UPTODATE, &qdev->flags)))))
3071 handle_completed_write_requests(conf, sh, disks, &return_bi); 2889 handle_stripe_clean_event(conf, sh, disks, &return_bi);
3072 2890
3073 /* Now we might consider reading some blocks, either to check/generate 2891 /* Now we might consider reading some blocks, either to check/generate
3074 * parity, or to satisfy requests 2892 * parity, or to satisfy requests
@@ -3076,11 +2894,11 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
3076 */ 2894 */
3077 if (s.to_read || s.non_overwrite || (s.to_write && s.failed) || 2895 if (s.to_read || s.non_overwrite || (s.to_write && s.failed) ||
3078 (s.syncing && (s.uptodate < disks)) || s.expanding) 2896 (s.syncing && (s.uptodate < disks)) || s.expanding)
3079 handle_issuing_new_read_requests6(sh, &s, &r6s, disks); 2897 handle_stripe_fill6(sh, &s, &r6s, disks);
3080 2898
3081 /* now to consider writing and what else, if anything should be read */ 2899 /* now to consider writing and what else, if anything should be read */
3082 if (s.to_write) 2900 if (s.to_write)
3083 handle_issuing_new_write_requests6(conf, sh, &s, &r6s, disks); 2901 handle_stripe_dirtying6(conf, sh, &s, &r6s, disks);
3084 2902
3085 /* maybe we need to check and possibly fix the parity for this stripe 2903 /* maybe we need to check and possibly fix the parity for this stripe
3086 * Any reads will already have been scheduled, so we just see if enough 2904 * Any reads will already have been scheduled, so we just see if enough
@@ -3136,7 +2954,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
3136 } 2954 }
3137 2955
3138 if (s.expanding && s.locked == 0 && 2956 if (s.expanding && s.locked == 0 &&
3139 !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending)) 2957 !test_bit(STRIPE_COMPUTE_RUN, &sh->state))
3140 handle_stripe_expansion(conf, sh, &r6s); 2958 handle_stripe_expansion(conf, sh, &r6s);
3141 2959
3142 unlock: 2960 unlock:
@@ -3146,68 +2964,9 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
3146 if (unlikely(blocked_rdev)) 2964 if (unlikely(blocked_rdev))
3147 md_wait_for_blocked_rdev(blocked_rdev, conf->mddev); 2965 md_wait_for_blocked_rdev(blocked_rdev, conf->mddev);
3148 2966
3149 return_io(return_bi); 2967 ops_run_io(sh, &s);
3150
3151 for (i=disks; i-- ;) {
3152 int rw;
3153 struct bio *bi;
3154 mdk_rdev_t *rdev;
3155 if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags))
3156 rw = WRITE;
3157 else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags))
3158 rw = READ;
3159 else
3160 continue;
3161
3162 set_bit(STRIPE_IO_STARTED, &sh->state);
3163
3164 bi = &sh->dev[i].req;
3165
3166 bi->bi_rw = rw;
3167 if (rw == WRITE)
3168 bi->bi_end_io = raid5_end_write_request;
3169 else
3170 bi->bi_end_io = raid5_end_read_request;
3171
3172 rcu_read_lock();
3173 rdev = rcu_dereference(conf->disks[i].rdev);
3174 if (rdev && test_bit(Faulty, &rdev->flags))
3175 rdev = NULL;
3176 if (rdev)
3177 atomic_inc(&rdev->nr_pending);
3178 rcu_read_unlock();
3179 2968
3180 if (rdev) { 2969 return_io(return_bi);
3181 if (s.syncing || s.expanding || s.expanded)
3182 md_sync_acct(rdev->bdev, STRIPE_SECTORS);
3183
3184 bi->bi_bdev = rdev->bdev;
3185 pr_debug("for %llu schedule op %ld on disc %d\n",
3186 (unsigned long long)sh->sector, bi->bi_rw, i);
3187 atomic_inc(&sh->count);
3188 bi->bi_sector = sh->sector + rdev->data_offset;
3189 bi->bi_flags = 1 << BIO_UPTODATE;
3190 bi->bi_vcnt = 1;
3191 bi->bi_max_vecs = 1;
3192 bi->bi_idx = 0;
3193 bi->bi_io_vec = &sh->dev[i].vec;
3194 bi->bi_io_vec[0].bv_len = STRIPE_SIZE;
3195 bi->bi_io_vec[0].bv_offset = 0;
3196 bi->bi_size = STRIPE_SIZE;
3197 bi->bi_next = NULL;
3198 if (rw == WRITE &&
3199 test_bit(R5_ReWrite, &sh->dev[i].flags))
3200 atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
3201 generic_make_request(bi);
3202 } else {
3203 if (rw == WRITE)
3204 set_bit(STRIPE_DEGRADED, &sh->state);
3205 pr_debug("skip op %ld on disc %d for sector %llu\n",
3206 bi->bi_rw, i, (unsigned long long)sh->sector);
3207 clear_bit(R5_LOCKED, &sh->dev[i].flags);
3208 set_bit(STRIPE_HANDLE, &sh->state);
3209 }
3210 }
3211} 2970}
3212 2971
3213static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) 2972static void handle_stripe(struct stripe_head *sh, struct page *tmp_page)
@@ -3697,9 +3456,7 @@ static int make_request(struct request_queue *q, struct bio * bi)
3697 if ( rw == WRITE ) 3456 if ( rw == WRITE )
3698 md_write_end(mddev); 3457 md_write_end(mddev);
3699 3458
3700 bi->bi_end_io(bi, 3459 bio_endio(bi, 0);
3701 test_bit(BIO_UPTODATE, &bi->bi_flags)
3702 ? 0 : -EIO);
3703 } 3460 }
3704 return 0; 3461 return 0;
3705} 3462}
@@ -3785,7 +3542,7 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
3785 j == raid6_next_disk(sh->pd_idx, sh->disks)) 3542 j == raid6_next_disk(sh->pd_idx, sh->disks))
3786 continue; 3543 continue;
3787 s = compute_blocknr(sh, j); 3544 s = compute_blocknr(sh, j);
3788 if (s < (mddev->array_size<<1)) { 3545 if (s < mddev->array_sectors) {
3789 skipped = 1; 3546 skipped = 1;
3790 continue; 3547 continue;
3791 } 3548 }
@@ -4002,12 +3759,8 @@ static int retry_aligned_read(raid5_conf_t *conf, struct bio *raid_bio)
4002 spin_lock_irq(&conf->device_lock); 3759 spin_lock_irq(&conf->device_lock);
4003 remaining = --raid_bio->bi_phys_segments; 3760 remaining = --raid_bio->bi_phys_segments;
4004 spin_unlock_irq(&conf->device_lock); 3761 spin_unlock_irq(&conf->device_lock);
4005 if (remaining == 0) { 3762 if (remaining == 0)
4006 3763 bio_endio(raid_bio, 0);
4007 raid_bio->bi_end_io(raid_bio,
4008 test_bit(BIO_UPTODATE, &raid_bio->bi_flags)
4009 ? 0 : -EIO);
4010 }
4011 if (atomic_dec_and_test(&conf->active_aligned_reads)) 3764 if (atomic_dec_and_test(&conf->active_aligned_reads))
4012 wake_up(&conf->wait_for_stripe); 3765 wake_up(&conf->wait_for_stripe);
4013 return handled; 3766 return handled;
@@ -4094,6 +3847,8 @@ raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
4094{ 3847{
4095 raid5_conf_t *conf = mddev_to_conf(mddev); 3848 raid5_conf_t *conf = mddev_to_conf(mddev);
4096 unsigned long new; 3849 unsigned long new;
3850 int err;
3851
4097 if (len >= PAGE_SIZE) 3852 if (len >= PAGE_SIZE)
4098 return -EINVAL; 3853 return -EINVAL;
4099 if (!conf) 3854 if (!conf)
@@ -4109,7 +3864,9 @@ raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
4109 else 3864 else
4110 break; 3865 break;
4111 } 3866 }
4112 md_allow_write(mddev); 3867 err = md_allow_write(mddev);
3868 if (err)
3869 return err;
4113 while (new > conf->max_nr_stripes) { 3870 while (new > conf->max_nr_stripes) {
4114 if (grow_one_stripe(conf)) 3871 if (grow_one_stripe(conf))
4115 conf->max_nr_stripes++; 3872 conf->max_nr_stripes++;
@@ -4434,7 +4191,7 @@ static int run(mddev_t *mddev)
4434 mddev->queue->backing_dev_info.congested_data = mddev; 4191 mddev->queue->backing_dev_info.congested_data = mddev;
4435 mddev->queue->backing_dev_info.congested_fn = raid5_congested; 4192 mddev->queue->backing_dev_info.congested_fn = raid5_congested;
4436 4193
4437 mddev->array_size = mddev->size * (conf->previous_raid_disks - 4194 mddev->array_sectors = 2 * mddev->size * (conf->previous_raid_disks -
4438 conf->max_degraded); 4195 conf->max_degraded);
4439 4196
4440 blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec); 4197 blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec);
@@ -4609,35 +4366,41 @@ abort:
4609static int raid5_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) 4366static int raid5_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
4610{ 4367{
4611 raid5_conf_t *conf = mddev->private; 4368 raid5_conf_t *conf = mddev->private;
4612 int found = 0; 4369 int err = -EEXIST;
4613 int disk; 4370 int disk;
4614 struct disk_info *p; 4371 struct disk_info *p;
4372 int first = 0;
4373 int last = conf->raid_disks - 1;
4615 4374
4616 if (mddev->degraded > conf->max_degraded) 4375 if (mddev->degraded > conf->max_degraded)
4617 /* no point adding a device */ 4376 /* no point adding a device */
4618 return 0; 4377 return -EINVAL;
4378
4379 if (rdev->raid_disk >= 0)
4380 first = last = rdev->raid_disk;
4619 4381
4620 /* 4382 /*
4621 * find the disk ... but prefer rdev->saved_raid_disk 4383 * find the disk ... but prefer rdev->saved_raid_disk
4622 * if possible. 4384 * if possible.
4623 */ 4385 */
4624 if (rdev->saved_raid_disk >= 0 && 4386 if (rdev->saved_raid_disk >= 0 &&
4387 rdev->saved_raid_disk >= first &&
4625 conf->disks[rdev->saved_raid_disk].rdev == NULL) 4388 conf->disks[rdev->saved_raid_disk].rdev == NULL)
4626 disk = rdev->saved_raid_disk; 4389 disk = rdev->saved_raid_disk;
4627 else 4390 else
4628 disk = 0; 4391 disk = first;
4629 for ( ; disk < conf->raid_disks; disk++) 4392 for ( ; disk <= last ; disk++)
4630 if ((p=conf->disks + disk)->rdev == NULL) { 4393 if ((p=conf->disks + disk)->rdev == NULL) {
4631 clear_bit(In_sync, &rdev->flags); 4394 clear_bit(In_sync, &rdev->flags);
4632 rdev->raid_disk = disk; 4395 rdev->raid_disk = disk;
4633 found = 1; 4396 err = 0;
4634 if (rdev->saved_raid_disk != disk) 4397 if (rdev->saved_raid_disk != disk)
4635 conf->fullsync = 1; 4398 conf->fullsync = 1;
4636 rcu_assign_pointer(p->rdev, rdev); 4399 rcu_assign_pointer(p->rdev, rdev);
4637 break; 4400 break;
4638 } 4401 }
4639 print_raid5_conf(conf); 4402 print_raid5_conf(conf);
4640 return found; 4403 return err;
4641} 4404}
4642 4405
4643static int raid5_resize(mddev_t *mddev, sector_t sectors) 4406static int raid5_resize(mddev_t *mddev, sector_t sectors)
@@ -4652,8 +4415,9 @@ static int raid5_resize(mddev_t *mddev, sector_t sectors)
4652 raid5_conf_t *conf = mddev_to_conf(mddev); 4415 raid5_conf_t *conf = mddev_to_conf(mddev);
4653 4416
4654 sectors &= ~((sector_t)mddev->chunk_size/512 - 1); 4417 sectors &= ~((sector_t)mddev->chunk_size/512 - 1);
4655 mddev->array_size = (sectors * (mddev->raid_disks-conf->max_degraded))>>1; 4418 mddev->array_sectors = sectors * (mddev->raid_disks
4656 set_capacity(mddev->gendisk, mddev->array_size << 1); 4419 - conf->max_degraded);
4420 set_capacity(mddev->gendisk, mddev->array_sectors);
4657 mddev->changed = 1; 4421 mddev->changed = 1;
4658 if (sectors/2 > mddev->size && mddev->recovery_cp == MaxSector) { 4422 if (sectors/2 > mddev->size && mddev->recovery_cp == MaxSector) {
4659 mddev->recovery_cp = mddev->size << 1; 4423 mddev->recovery_cp = mddev->size << 1;
@@ -4738,7 +4502,7 @@ static int raid5_start_reshape(mddev_t *mddev)
4738 rdev_for_each(rdev, rtmp, mddev) 4502 rdev_for_each(rdev, rtmp, mddev)
4739 if (rdev->raid_disk < 0 && 4503 if (rdev->raid_disk < 0 &&
4740 !test_bit(Faulty, &rdev->flags)) { 4504 !test_bit(Faulty, &rdev->flags)) {
4741 if (raid5_add_disk(mddev, rdev)) { 4505 if (raid5_add_disk(mddev, rdev) == 0) {
4742 char nm[20]; 4506 char nm[20];
4743 set_bit(In_sync, &rdev->flags); 4507 set_bit(In_sync, &rdev->flags);
4744 added_devices++; 4508 added_devices++;
@@ -4786,15 +4550,16 @@ static void end_reshape(raid5_conf_t *conf)
4786 struct block_device *bdev; 4550 struct block_device *bdev;
4787 4551
4788 if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { 4552 if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) {
4789 conf->mddev->array_size = conf->mddev->size * 4553 conf->mddev->array_sectors = 2 * conf->mddev->size *
4790 (conf->raid_disks - conf->max_degraded); 4554 (conf->raid_disks - conf->max_degraded);
4791 set_capacity(conf->mddev->gendisk, conf->mddev->array_size << 1); 4555 set_capacity(conf->mddev->gendisk, conf->mddev->array_sectors);
4792 conf->mddev->changed = 1; 4556 conf->mddev->changed = 1;
4793 4557
4794 bdev = bdget_disk(conf->mddev->gendisk, 0); 4558 bdev = bdget_disk(conf->mddev->gendisk, 0);
4795 if (bdev) { 4559 if (bdev) {
4796 mutex_lock(&bdev->bd_inode->i_mutex); 4560 mutex_lock(&bdev->bd_inode->i_mutex);
4797 i_size_write(bdev->bd_inode, (loff_t)conf->mddev->array_size << 10); 4561 i_size_write(bdev->bd_inode,
4562 (loff_t)conf->mddev->array_sectors << 9);
4798 mutex_unlock(&bdev->bd_inode->i_mutex); 4563 mutex_unlock(&bdev->bd_inode->i_mutex);
4799 bdput(bdev); 4564 bdput(bdev);
4800 } 4565 }
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index e208a60c048a..e7132770a3bf 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -233,9 +233,9 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
233 233
234 mutex_unlock(&dvbdev_register_lock); 234 mutex_unlock(&dvbdev_register_lock);
235 235
236 clsdev = device_create(dvb_class, adap->device, 236 clsdev = device_create_drvdata(dvb_class, adap->device,
237 MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)), 237 MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)),
238 "dvb%d.%s%d", adap->num, dnames[type], id); 238 NULL, "dvb%d.%s%d", adap->num, dnames[type], id);
239 if (IS_ERR(clsdev)) { 239 if (IS_ERR(clsdev)) {
240 printk(KERN_ERR "%s: failed to create device dvb%d.%s%d (%ld)\n", 240 printk(KERN_ERR "%s: failed to create device dvb%d.%s%d (%ld)\n",
241 __func__, adap->num, dnames[type], id, PTR_ERR(clsdev)); 241 __func__, adap->num, dnames[type], id, PTR_ERR(clsdev));
diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c
index a054668eda16..4e3bfbcdf155 100644
--- a/drivers/memstick/host/jmb38x_ms.c
+++ b/drivers/memstick/host/jmb38x_ms.c
@@ -51,7 +51,7 @@ struct jmb38x_ms_host {
51 void __iomem *addr; 51 void __iomem *addr;
52 spinlock_t lock; 52 spinlock_t lock;
53 int id; 53 int id;
54 char host_id[DEVICE_ID_SIZE]; 54 char host_id[32];
55 int irq; 55 int irq;
56 unsigned int block_pos; 56 unsigned int block_pos;
57 unsigned long timeout_jiffies; 57 unsigned long timeout_jiffies;
@@ -781,7 +781,7 @@ static struct memstick_host *jmb38x_ms_alloc_host(struct jmb38x_ms *jm, int cnt)
781 781
782 spin_lock_init(&host->lock); 782 spin_lock_init(&host->lock);
783 host->id = cnt; 783 host->id = cnt;
784 snprintf(host->host_id, DEVICE_ID_SIZE, DRIVER_NAME ":slot%d", 784 snprintf(host->host_id, sizeof(host->host_id), DRIVER_NAME ":slot%d",
785 host->id); 785 host->id);
786 host->irq = jm->pdev->irq; 786 host->irq = jm->pdev->irq;
787 host->timeout_jiffies = msecs_to_jiffies(1000); 787 host->timeout_jiffies = msecs_to_jiffies(1000);
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 75e599b85b64..34402c47027e 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -1670,7 +1670,8 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1670 INIT_DELAYED_WORK(&ioc->fault_reset_work, mpt_fault_reset_work); 1670 INIT_DELAYED_WORK(&ioc->fault_reset_work, mpt_fault_reset_work);
1671 spin_lock_init(&ioc->fault_reset_work_lock); 1671 spin_lock_init(&ioc->fault_reset_work_lock);
1672 1672
1673 snprintf(ioc->reset_work_q_name, KOBJ_NAME_LEN, "mpt_poll_%d", ioc->id); 1673 snprintf(ioc->reset_work_q_name, sizeof(ioc->reset_work_q_name),
1674 "mpt_poll_%d", ioc->id);
1674 ioc->reset_work_q = 1675 ioc->reset_work_q =
1675 create_singlethread_workqueue(ioc->reset_work_q_name); 1676 create_singlethread_workqueue(ioc->reset_work_q_name);
1676 if (!ioc->reset_work_q) { 1677 if (!ioc->reset_work_q) {
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index 6adab648dbb9..dff048cfa101 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -707,12 +707,12 @@ typedef struct _MPT_ADAPTER
707 u8 fc_link_speed[2]; 707 u8 fc_link_speed[2];
708 spinlock_t fc_rescan_work_lock; 708 spinlock_t fc_rescan_work_lock;
709 struct work_struct fc_rescan_work; 709 struct work_struct fc_rescan_work;
710 char fc_rescan_work_q_name[KOBJ_NAME_LEN]; 710 char fc_rescan_work_q_name[20];
711 struct workqueue_struct *fc_rescan_work_q; 711 struct workqueue_struct *fc_rescan_work_q;
712 struct scsi_cmnd **ScsiLookup; 712 struct scsi_cmnd **ScsiLookup;
713 spinlock_t scsi_lookup_lock; 713 spinlock_t scsi_lookup_lock;
714 714
715 char reset_work_q_name[KOBJ_NAME_LEN]; 715 char reset_work_q_name[20];
716 struct workqueue_struct *reset_work_q; 716 struct workqueue_struct *reset_work_q;
717 struct delayed_work fault_reset_work; 717 struct delayed_work fault_reset_work;
718 spinlock_t fault_reset_work_lock; 718 spinlock_t fault_reset_work_lock;
diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c
index fc31ca6829d8..b36cae9ec6db 100644
--- a/drivers/message/fusion/mptfc.c
+++ b/drivers/message/fusion/mptfc.c
@@ -1326,8 +1326,8 @@ mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1326 1326
1327 /* initialize workqueue */ 1327 /* initialize workqueue */
1328 1328
1329 snprintf(ioc->fc_rescan_work_q_name, KOBJ_NAME_LEN, "mptfc_wq_%d", 1329 snprintf(ioc->fc_rescan_work_q_name, sizeof(ioc->fc_rescan_work_q_name),
1330 sh->host_no); 1330 "mptfc_wq_%d", sh->host_no);
1331 ioc->fc_rescan_work_q = 1331 ioc->fc_rescan_work_q =
1332 create_singlethread_workqueue(ioc->fc_rescan_work_q_name); 1332 create_singlethread_workqueue(ioc->fc_rescan_work_q_name);
1333 if (!ioc->fc_rescan_work_q) 1333 if (!ioc->fc_rescan_work_q)
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 1921b8dbb242..ce67d973d349 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -420,4 +420,17 @@ config SGI_XP
420 this feature will allow for direct communication between SSIs 420 this feature will allow for direct communication between SSIs
421 based on a network adapter and DMA messaging. 421 based on a network adapter and DMA messaging.
422 422
423config HP_ILO
424 tristate "Channel interface driver for HP iLO/iLO2 processor"
425 default n
426 help
427 The channel interface driver allows applications to communicate
428 with iLO/iLO2 management processors present on HP ProLiant
429 servers. Upon loading, the driver creates /dev/hpilo/dXccbN files,
430 which can be used to gather data from the management processor,
431 via read and write system calls.
432
433 To compile this driver as a module, choose M here: the
434 module will be called hpilo.
435
423endif # MISC_DEVICES 436endif # MISC_DEVICES
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index a6dac6a2e7e5..688fe76135e0 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -27,3 +27,4 @@ obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
27obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o 27obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
28obj-$(CONFIG_KGDB_TESTS) += kgdbts.o 28obj-$(CONFIG_KGDB_TESTS) += kgdbts.o
29obj-$(CONFIG_SGI_XP) += sgi-xp/ 29obj-$(CONFIG_SGI_XP) += sgi-xp/
30obj-$(CONFIG_HP_ILO) += hpilo.o
diff --git a/drivers/misc/hpilo.c b/drivers/misc/hpilo.c
new file mode 100644
index 000000000000..05e298289238
--- /dev/null
+++ b/drivers/misc/hpilo.c
@@ -0,0 +1,768 @@
1/*
2 * Driver for HP iLO/iLO2 management processor.
3 *
4 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
5 * David Altobelli <david.altobelli@hp.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <linux/module.h>
14#include <linux/fs.h>
15#include <linux/pci.h>
16#include <linux/ioport.h>
17#include <linux/device.h>
18#include <linux/file.h>
19#include <linux/cdev.h>
20#include <linux/spinlock.h>
21#include <linux/delay.h>
22#include <linux/uaccess.h>
23#include <linux/io.h>
24#include "hpilo.h"
25
26static struct class *ilo_class;
27static unsigned int ilo_major;
28static char ilo_hwdev[MAX_ILO_DEV];
29
30static inline int get_entry_id(int entry)
31{
32 return (entry & ENTRY_MASK_DESCRIPTOR) >> ENTRY_BITPOS_DESCRIPTOR;
33}
34
35static inline int get_entry_len(int entry)
36{
37 return ((entry & ENTRY_MASK_QWORDS) >> ENTRY_BITPOS_QWORDS) << 3;
38}
39
40static inline int mk_entry(int id, int len)
41{
42 int qlen = len & 7 ? (len >> 3) + 1 : len >> 3;
43 return id << ENTRY_BITPOS_DESCRIPTOR | qlen << ENTRY_BITPOS_QWORDS;
44}
45
46static inline int desc_mem_sz(int nr_entry)
47{
48 return nr_entry << L2_QENTRY_SZ;
49}
50
51/*
52 * FIFO queues, shared with hardware.
53 *
54 * If a queue has empty slots, an entry is added to the queue tail,
55 * and that entry is marked as occupied.
56 * Entries can be dequeued from the head of the list, when the device
57 * has marked the entry as consumed.
58 *
59 * Returns true on successful queue/dequeue, false on failure.
60 */
61static int fifo_enqueue(struct ilo_hwinfo *hw, char *fifobar, int entry)
62{
63 struct fifo *fifo_q = FIFOBARTOHANDLE(fifobar);
64 int ret = 0;
65
66 spin_lock(&hw->fifo_lock);
67 if (!(fifo_q->fifobar[(fifo_q->tail + 1) & fifo_q->imask]
68 & ENTRY_MASK_O)) {
69 fifo_q->fifobar[fifo_q->tail & fifo_q->imask] |=
70 (entry & ENTRY_MASK_NOSTATE) | fifo_q->merge;
71 fifo_q->tail += 1;
72 ret = 1;
73 }
74 spin_unlock(&hw->fifo_lock);
75
76 return ret;
77}
78
79static int fifo_dequeue(struct ilo_hwinfo *hw, char *fifobar, int *entry)
80{
81 struct fifo *fifo_q = FIFOBARTOHANDLE(fifobar);
82 int ret = 0;
83 u64 c;
84
85 spin_lock(&hw->fifo_lock);
86 c = fifo_q->fifobar[fifo_q->head & fifo_q->imask];
87 if (c & ENTRY_MASK_C) {
88 if (entry)
89 *entry = c & ENTRY_MASK_NOSTATE;
90
91 fifo_q->fifobar[fifo_q->head & fifo_q->imask] =
92 (c | ENTRY_MASK) + 1;
93 fifo_q->head += 1;
94 ret = 1;
95 }
96 spin_unlock(&hw->fifo_lock);
97
98 return ret;
99}
100
101static int ilo_pkt_enqueue(struct ilo_hwinfo *hw, struct ccb *ccb,
102 int dir, int id, int len)
103{
104 char *fifobar;
105 int entry;
106
107 if (dir == SENDQ)
108 fifobar = ccb->ccb_u1.send_fifobar;
109 else
110 fifobar = ccb->ccb_u3.recv_fifobar;
111
112 entry = mk_entry(id, len);
113 return fifo_enqueue(hw, fifobar, entry);
114}
115
116static int ilo_pkt_dequeue(struct ilo_hwinfo *hw, struct ccb *ccb,
117 int dir, int *id, int *len, void **pkt)
118{
119 char *fifobar, *desc;
120 int entry = 0, pkt_id = 0;
121 int ret;
122
123 if (dir == SENDQ) {
124 fifobar = ccb->ccb_u1.send_fifobar;
125 desc = ccb->ccb_u2.send_desc;
126 } else {
127 fifobar = ccb->ccb_u3.recv_fifobar;
128 desc = ccb->ccb_u4.recv_desc;
129 }
130
131 ret = fifo_dequeue(hw, fifobar, &entry);
132 if (ret) {
133 pkt_id = get_entry_id(entry);
134 if (id)
135 *id = pkt_id;
136 if (len)
137 *len = get_entry_len(entry);
138 if (pkt)
139 *pkt = (void *)(desc + desc_mem_sz(pkt_id));
140 }
141
142 return ret;
143}
144
145static inline void doorbell_set(struct ccb *ccb)
146{
147 iowrite8(1, ccb->ccb_u5.db_base);
148}
149
150static inline void doorbell_clr(struct ccb *ccb)
151{
152 iowrite8(2, ccb->ccb_u5.db_base);
153}
154static inline int ctrl_set(int l2sz, int idxmask, int desclim)
155{
156 int active = 0, go = 1;
157 return l2sz << CTRL_BITPOS_L2SZ |
158 idxmask << CTRL_BITPOS_FIFOINDEXMASK |
159 desclim << CTRL_BITPOS_DESCLIMIT |
160 active << CTRL_BITPOS_A |
161 go << CTRL_BITPOS_G;
162}
163static void ctrl_setup(struct ccb *ccb, int nr_desc, int l2desc_sz)
164{
165 /* for simplicity, use the same parameters for send and recv ctrls */
166 ccb->send_ctrl = ctrl_set(l2desc_sz, nr_desc-1, nr_desc-1);
167 ccb->recv_ctrl = ctrl_set(l2desc_sz, nr_desc-1, nr_desc-1);
168}
169
170static inline int fifo_sz(int nr_entry)
171{
172 /* size of a fifo is determined by the number of entries it contains */
173 return (nr_entry * sizeof(u64)) + FIFOHANDLESIZE;
174}
175
176static void fifo_setup(void *base_addr, int nr_entry)
177{
178 struct fifo *fifo_q = base_addr;
179 int i;
180
181 /* set up an empty fifo */
182 fifo_q->head = 0;
183 fifo_q->tail = 0;
184 fifo_q->reset = 0;
185 fifo_q->nrents = nr_entry;
186 fifo_q->imask = nr_entry - 1;
187 fifo_q->merge = ENTRY_MASK_O;
188
189 for (i = 0; i < nr_entry; i++)
190 fifo_q->fifobar[i] = 0;
191}
192
193static void ilo_ccb_close(struct pci_dev *pdev, struct ccb_data *data)
194{
195 struct ccb *driver_ccb;
196 struct ccb __iomem *device_ccb;
197 int retries;
198
199 driver_ccb = &data->driver_ccb;
200 device_ccb = data->mapped_ccb;
201
202 /* complicated dance to tell the hw we are stopping */
203 doorbell_clr(driver_ccb);
204 iowrite32(ioread32(&device_ccb->send_ctrl) & ~(1 << CTRL_BITPOS_G),
205 &device_ccb->send_ctrl);
206 iowrite32(ioread32(&device_ccb->recv_ctrl) & ~(1 << CTRL_BITPOS_G),
207 &device_ccb->recv_ctrl);
208
209 /* give iLO some time to process stop request */
210 for (retries = 1000; retries > 0; retries--) {
211 doorbell_set(driver_ccb);
212 udelay(1);
213 if (!(ioread32(&device_ccb->send_ctrl) & (1 << CTRL_BITPOS_A))
214 &&
215 !(ioread32(&device_ccb->recv_ctrl) & (1 << CTRL_BITPOS_A)))
216 break;
217 }
218 if (retries == 0)
219 dev_err(&pdev->dev, "Closing, but controller still active\n");
220
221 /* clear the hw ccb */
222 memset_io(device_ccb, 0, sizeof(struct ccb));
223
224 /* free resources used to back send/recv queues */
225 pci_free_consistent(pdev, data->dma_size, data->dma_va, data->dma_pa);
226}
227
228static int ilo_ccb_open(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
229{
230 char *dma_va, *dma_pa;
231 int pkt_id, pkt_sz, i, error;
232 struct ccb *driver_ccb, *ilo_ccb;
233 struct pci_dev *pdev;
234
235 driver_ccb = &data->driver_ccb;
236 ilo_ccb = &data->ilo_ccb;
237 pdev = hw->ilo_dev;
238
239 data->dma_size = 2 * fifo_sz(NR_QENTRY) +
240 2 * desc_mem_sz(NR_QENTRY) +
241 ILO_START_ALIGN + ILO_CACHE_SZ;
242
243 error = -ENOMEM;
244 data->dma_va = pci_alloc_consistent(pdev, data->dma_size,
245 &data->dma_pa);
246 if (!data->dma_va)
247 goto out;
248
249 dma_va = (char *)data->dma_va;
250 dma_pa = (char *)data->dma_pa;
251
252 memset(dma_va, 0, data->dma_size);
253
254 dma_va = (char *)roundup((unsigned long)dma_va, ILO_START_ALIGN);
255 dma_pa = (char *)roundup((unsigned long)dma_pa, ILO_START_ALIGN);
256
257 /*
258 * Create two ccb's, one with virt addrs, one with phys addrs.
259 * Copy the phys addr ccb to device shared mem.
260 */
261 ctrl_setup(driver_ccb, NR_QENTRY, L2_QENTRY_SZ);
262 ctrl_setup(ilo_ccb, NR_QENTRY, L2_QENTRY_SZ);
263
264 fifo_setup(dma_va, NR_QENTRY);
265 driver_ccb->ccb_u1.send_fifobar = dma_va + FIFOHANDLESIZE;
266 ilo_ccb->ccb_u1.send_fifobar = dma_pa + FIFOHANDLESIZE;
267 dma_va += fifo_sz(NR_QENTRY);
268 dma_pa += fifo_sz(NR_QENTRY);
269
270 dma_va = (char *)roundup((unsigned long)dma_va, ILO_CACHE_SZ);
271 dma_pa = (char *)roundup((unsigned long)dma_pa, ILO_CACHE_SZ);
272
273 fifo_setup(dma_va, NR_QENTRY);
274 driver_ccb->ccb_u3.recv_fifobar = dma_va + FIFOHANDLESIZE;
275 ilo_ccb->ccb_u3.recv_fifobar = dma_pa + FIFOHANDLESIZE;
276 dma_va += fifo_sz(NR_QENTRY);
277 dma_pa += fifo_sz(NR_QENTRY);
278
279 driver_ccb->ccb_u2.send_desc = dma_va;
280 ilo_ccb->ccb_u2.send_desc = dma_pa;
281 dma_pa += desc_mem_sz(NR_QENTRY);
282 dma_va += desc_mem_sz(NR_QENTRY);
283
284 driver_ccb->ccb_u4.recv_desc = dma_va;
285 ilo_ccb->ccb_u4.recv_desc = dma_pa;
286
287 driver_ccb->channel = slot;
288 ilo_ccb->channel = slot;
289
290 driver_ccb->ccb_u5.db_base = hw->db_vaddr + (slot << L2_DB_SIZE);
291 ilo_ccb->ccb_u5.db_base = NULL; /* hw ccb's doorbell is not used */
292
293 /* copy the ccb with physical addrs to device memory */
294 data->mapped_ccb = (struct ccb __iomem *)
295 (hw->ram_vaddr + (slot * ILOHW_CCB_SZ));
296 memcpy_toio(data->mapped_ccb, ilo_ccb, sizeof(struct ccb));
297
298 /* put packets on the send and receive queues */
299 pkt_sz = 0;
300 for (pkt_id = 0; pkt_id < NR_QENTRY; pkt_id++) {
301 ilo_pkt_enqueue(hw, driver_ccb, SENDQ, pkt_id, pkt_sz);
302 doorbell_set(driver_ccb);
303 }
304
305 pkt_sz = desc_mem_sz(1);
306 for (pkt_id = 0; pkt_id < NR_QENTRY; pkt_id++)
307 ilo_pkt_enqueue(hw, driver_ccb, RECVQ, pkt_id, pkt_sz);
308
309 doorbell_clr(driver_ccb);
310
311 /* make sure iLO is really handling requests */
312 for (i = 1000; i > 0; i--) {
313 if (ilo_pkt_dequeue(hw, driver_ccb, SENDQ, &pkt_id, NULL, NULL))
314 break;
315 udelay(1);
316 }
317
318 if (i) {
319 ilo_pkt_enqueue(hw, driver_ccb, SENDQ, pkt_id, 0);
320 doorbell_set(driver_ccb);
321 } else {
322 dev_err(&pdev->dev, "Open could not dequeue a packet\n");
323 error = -EBUSY;
324 goto free;
325 }
326
327 return 0;
328free:
329 pci_free_consistent(pdev, data->dma_size, data->dma_va, data->dma_pa);
330out:
331 return error;
332}
333
334static inline int is_channel_reset(struct ccb *ccb)
335{
336 /* check for this particular channel needing a reset */
337 return FIFOBARTOHANDLE(ccb->ccb_u1.send_fifobar)->reset;
338}
339
340static inline void set_channel_reset(struct ccb *ccb)
341{
342 /* set a flag indicating this channel needs a reset */
343 FIFOBARTOHANDLE(ccb->ccb_u1.send_fifobar)->reset = 1;
344}
345
346static inline int is_device_reset(struct ilo_hwinfo *hw)
347{
348 /* check for global reset condition */
349 return ioread32(&hw->mmio_vaddr[DB_OUT]) & (1 << DB_RESET);
350}
351
352static inline void clear_device(struct ilo_hwinfo *hw)
353{
354 /* clear the device (reset bits, pending channel entries) */
355 iowrite32(-1, &hw->mmio_vaddr[DB_OUT]);
356}
357
358static void ilo_locked_reset(struct ilo_hwinfo *hw)
359{
360 int slot;
361
362 /*
363 * Mapped memory is zeroed on ilo reset, so set a per ccb flag
364 * to indicate that this ccb needs to be closed and reopened.
365 */
366 for (slot = 0; slot < MAX_CCB; slot++) {
367 if (!hw->ccb_alloc[slot])
368 continue;
369 set_channel_reset(&hw->ccb_alloc[slot]->driver_ccb);
370 }
371
372 clear_device(hw);
373}
374
375static void ilo_reset(struct ilo_hwinfo *hw)
376{
377 spin_lock(&hw->alloc_lock);
378
379 /* reset might have been handled after lock was taken */
380 if (is_device_reset(hw))
381 ilo_locked_reset(hw);
382
383 spin_unlock(&hw->alloc_lock);
384}
385
386static ssize_t ilo_read(struct file *fp, char __user *buf,
387 size_t len, loff_t *off)
388{
389 int err, found, cnt, pkt_id, pkt_len;
390 struct ccb_data *data;
391 struct ccb *driver_ccb;
392 struct ilo_hwinfo *hw;
393 void *pkt;
394
395 data = fp->private_data;
396 driver_ccb = &data->driver_ccb;
397 hw = data->ilo_hw;
398
399 if (is_device_reset(hw) || is_channel_reset(driver_ccb)) {
400 /*
401 * If the device has been reset, applications
402 * need to close and reopen all ccbs.
403 */
404 ilo_reset(hw);
405 return -ENODEV;
406 }
407
408 /*
409 * This function is to be called when data is expected
410 * in the channel, and will return an error if no packet is found
411 * during the loop below. The sleep/retry logic is to allow
412 * applications to call read() immediately post write(),
413 * and give iLO some time to process the sent packet.
414 */
415 cnt = 20;
416 do {
417 /* look for a received packet */
418 found = ilo_pkt_dequeue(hw, driver_ccb, RECVQ, &pkt_id,
419 &pkt_len, &pkt);
420 if (found)
421 break;
422 cnt--;
423 msleep(100);
424 } while (!found && cnt);
425
426 if (!found)
427 return -EAGAIN;
428
429 /* only copy the length of the received packet */
430 if (pkt_len < len)
431 len = pkt_len;
432
433 err = copy_to_user(buf, pkt, len);
434
435 /* return the received packet to the queue */
436 ilo_pkt_enqueue(hw, driver_ccb, RECVQ, pkt_id, desc_mem_sz(1));
437
438 return err ? -EFAULT : len;
439}
440
441static ssize_t ilo_write(struct file *fp, const char __user *buf,
442 size_t len, loff_t *off)
443{
444 int err, pkt_id, pkt_len;
445 struct ccb_data *data;
446 struct ccb *driver_ccb;
447 struct ilo_hwinfo *hw;
448 void *pkt;
449
450 data = fp->private_data;
451 driver_ccb = &data->driver_ccb;
452 hw = data->ilo_hw;
453
454 if (is_device_reset(hw) || is_channel_reset(driver_ccb)) {
455 /*
456 * If the device has been reset, applications
457 * need to close and reopen all ccbs.
458 */
459 ilo_reset(hw);
460 return -ENODEV;
461 }
462
463 /* get a packet to send the user command */
464 if (!ilo_pkt_dequeue(hw, driver_ccb, SENDQ, &pkt_id, &pkt_len, &pkt))
465 return -EBUSY;
466
467 /* limit the length to the length of the packet */
468 if (pkt_len < len)
469 len = pkt_len;
470
471 /* on failure, set the len to 0 to return empty packet to the device */
472 err = copy_from_user(pkt, buf, len);
473 if (err)
474 len = 0;
475
476 /* send the packet */
477 ilo_pkt_enqueue(hw, driver_ccb, SENDQ, pkt_id, len);
478 doorbell_set(driver_ccb);
479
480 return err ? -EFAULT : len;
481}
482
483static int ilo_close(struct inode *ip, struct file *fp)
484{
485 int slot;
486 struct ccb_data *data;
487 struct ilo_hwinfo *hw;
488
489 slot = iminor(ip) % MAX_CCB;
490 hw = container_of(ip->i_cdev, struct ilo_hwinfo, cdev);
491
492 spin_lock(&hw->alloc_lock);
493
494 if (is_device_reset(hw))
495 ilo_locked_reset(hw);
496
497 if (hw->ccb_alloc[slot]->ccb_cnt == 1) {
498
499 data = fp->private_data;
500
501 ilo_ccb_close(hw->ilo_dev, data);
502
503 kfree(data);
504 hw->ccb_alloc[slot] = NULL;
505 } else
506 hw->ccb_alloc[slot]->ccb_cnt--;
507
508 spin_unlock(&hw->alloc_lock);
509
510 return 0;
511}
512
513static int ilo_open(struct inode *ip, struct file *fp)
514{
515 int slot, error;
516 struct ccb_data *data;
517 struct ilo_hwinfo *hw;
518
519 slot = iminor(ip) % MAX_CCB;
520 hw = container_of(ip->i_cdev, struct ilo_hwinfo, cdev);
521
522 /* new ccb allocation */
523 data = kzalloc(sizeof(*data), GFP_KERNEL);
524 if (!data)
525 return -ENOMEM;
526
527 spin_lock(&hw->alloc_lock);
528
529 if (is_device_reset(hw))
530 ilo_locked_reset(hw);
531
532 /* each fd private_data holds sw/hw view of ccb */
533 if (hw->ccb_alloc[slot] == NULL) {
534 /* create a channel control block for this minor */
535 error = ilo_ccb_open(hw, data, slot);
536 if (!error) {
537 hw->ccb_alloc[slot] = data;
538 hw->ccb_alloc[slot]->ccb_cnt = 1;
539 hw->ccb_alloc[slot]->ccb_excl = fp->f_flags & O_EXCL;
540 hw->ccb_alloc[slot]->ilo_hw = hw;
541 } else
542 kfree(data);
543 } else {
544 kfree(data);
545 if (fp->f_flags & O_EXCL || hw->ccb_alloc[slot]->ccb_excl) {
546 /*
547 * The channel exists, and either this open
548 * or a previous open of this channel wants
549 * exclusive access.
550 */
551 error = -EBUSY;
552 } else {
553 hw->ccb_alloc[slot]->ccb_cnt++;
554 error = 0;
555 }
556 }
557 spin_unlock(&hw->alloc_lock);
558
559 if (!error)
560 fp->private_data = hw->ccb_alloc[slot];
561
562 return error;
563}
564
565static const struct file_operations ilo_fops = {
566 .owner = THIS_MODULE,
567 .read = ilo_read,
568 .write = ilo_write,
569 .open = ilo_open,
570 .release = ilo_close,
571};
572
573static void ilo_unmap_device(struct pci_dev *pdev, struct ilo_hwinfo *hw)
574{
575 pci_iounmap(pdev, hw->db_vaddr);
576 pci_iounmap(pdev, hw->ram_vaddr);
577 pci_iounmap(pdev, hw->mmio_vaddr);
578}
579
580static int __devinit ilo_map_device(struct pci_dev *pdev, struct ilo_hwinfo *hw)
581{
582 int error = -ENOMEM;
583
584 /* map the memory mapped i/o registers */
585 hw->mmio_vaddr = pci_iomap(pdev, 1, 0);
586 if (hw->mmio_vaddr == NULL) {
587 dev_err(&pdev->dev, "Error mapping mmio\n");
588 goto out;
589 }
590
591 /* map the adapter shared memory region */
592 hw->ram_vaddr = pci_iomap(pdev, 2, MAX_CCB * ILOHW_CCB_SZ);
593 if (hw->ram_vaddr == NULL) {
594 dev_err(&pdev->dev, "Error mapping shared mem\n");
595 goto mmio_free;
596 }
597
598 /* map the doorbell aperture */
599 hw->db_vaddr = pci_iomap(pdev, 3, MAX_CCB * ONE_DB_SIZE);
600 if (hw->db_vaddr == NULL) {
601 dev_err(&pdev->dev, "Error mapping doorbell\n");
602 goto ram_free;
603 }
604
605 return 0;
606ram_free:
607 pci_iounmap(pdev, hw->ram_vaddr);
608mmio_free:
609 pci_iounmap(pdev, hw->mmio_vaddr);
610out:
611 return error;
612}
613
614static void ilo_remove(struct pci_dev *pdev)
615{
616 int i, minor;
617 struct ilo_hwinfo *ilo_hw = pci_get_drvdata(pdev);
618
619 clear_device(ilo_hw);
620
621 minor = MINOR(ilo_hw->cdev.dev);
622 for (i = minor; i < minor + MAX_CCB; i++)
623 device_destroy(ilo_class, MKDEV(ilo_major, i));
624
625 cdev_del(&ilo_hw->cdev);
626 ilo_unmap_device(pdev, ilo_hw);
627 pci_release_regions(pdev);
628 pci_disable_device(pdev);
629 kfree(ilo_hw);
630 ilo_hwdev[(minor / MAX_CCB)] = 0;
631}
632
633static int __devinit ilo_probe(struct pci_dev *pdev,
634 const struct pci_device_id *ent)
635{
636 int devnum, minor, start, error;
637 struct ilo_hwinfo *ilo_hw;
638
639 /* find a free range for device files */
640 for (devnum = 0; devnum < MAX_ILO_DEV; devnum++) {
641 if (ilo_hwdev[devnum] == 0) {
642 ilo_hwdev[devnum] = 1;
643 break;
644 }
645 }
646
647 if (devnum == MAX_ILO_DEV) {
648 dev_err(&pdev->dev, "Error finding free device\n");
649 return -ENODEV;
650 }
651
652 /* track global allocations for this device */
653 error = -ENOMEM;
654 ilo_hw = kzalloc(sizeof(*ilo_hw), GFP_KERNEL);
655 if (!ilo_hw)
656 goto out;
657
658 ilo_hw->ilo_dev = pdev;
659 spin_lock_init(&ilo_hw->alloc_lock);
660 spin_lock_init(&ilo_hw->fifo_lock);
661
662 error = pci_enable_device(pdev);
663 if (error)
664 goto free;
665
666 pci_set_master(pdev);
667
668 error = pci_request_regions(pdev, ILO_NAME);
669 if (error)
670 goto disable;
671
672 error = ilo_map_device(pdev, ilo_hw);
673 if (error)
674 goto free_regions;
675
676 pci_set_drvdata(pdev, ilo_hw);
677 clear_device(ilo_hw);
678
679 cdev_init(&ilo_hw->cdev, &ilo_fops);
680 ilo_hw->cdev.owner = THIS_MODULE;
681 start = devnum * MAX_CCB;
682 error = cdev_add(&ilo_hw->cdev, MKDEV(ilo_major, start), MAX_CCB);
683 if (error) {
684 dev_err(&pdev->dev, "Could not add cdev\n");
685 goto unmap;
686 }
687
688 for (minor = 0 ; minor < MAX_CCB; minor++) {
689 struct device *dev;
690 dev = device_create(ilo_class, &pdev->dev,
691 MKDEV(ilo_major, minor), NULL,
692 "hpilo!d%dccb%d", devnum, minor);
693 if (IS_ERR(dev))
694 dev_err(&pdev->dev, "Could not create files\n");
695 }
696
697 return 0;
698unmap:
699 ilo_unmap_device(pdev, ilo_hw);
700free_regions:
701 pci_release_regions(pdev);
702disable:
703 pci_disable_device(pdev);
704free:
705 kfree(ilo_hw);
706out:
707 ilo_hwdev[devnum] = 0;
708 return error;
709}
710
711static struct pci_device_id ilo_devices[] = {
712 { PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xB204) },
713 { }
714};
715MODULE_DEVICE_TABLE(pci, ilo_devices);
716
717static struct pci_driver ilo_driver = {
718 .name = ILO_NAME,
719 .id_table = ilo_devices,
720 .probe = ilo_probe,
721 .remove = __devexit_p(ilo_remove),
722};
723
724static int __init ilo_init(void)
725{
726 int error;
727 dev_t dev;
728
729 ilo_class = class_create(THIS_MODULE, "iLO");
730 if (IS_ERR(ilo_class)) {
731 error = PTR_ERR(ilo_class);
732 goto out;
733 }
734
735 error = alloc_chrdev_region(&dev, 0, MAX_OPEN, ILO_NAME);
736 if (error)
737 goto class_destroy;
738
739 ilo_major = MAJOR(dev);
740
741 error = pci_register_driver(&ilo_driver);
742 if (error)
743 goto chr_remove;
744
745 return 0;
746chr_remove:
747 unregister_chrdev_region(dev, MAX_OPEN);
748class_destroy:
749 class_destroy(ilo_class);
750out:
751 return error;
752}
753
754static void __exit ilo_exit(void)
755{
756 pci_unregister_driver(&ilo_driver);
757 unregister_chrdev_region(MKDEV(ilo_major, 0), MAX_OPEN);
758 class_destroy(ilo_class);
759}
760
761MODULE_VERSION("0.05");
762MODULE_ALIAS(ILO_NAME);
763MODULE_DESCRIPTION(ILO_NAME);
764MODULE_AUTHOR("David Altobelli <david.altobelli@hp.com>");
765MODULE_LICENSE("GPL v2");
766
767module_init(ilo_init);
768module_exit(ilo_exit);
diff --git a/drivers/misc/hpilo.h b/drivers/misc/hpilo.h
new file mode 100644
index 000000000000..a281207696c1
--- /dev/null
+++ b/drivers/misc/hpilo.h
@@ -0,0 +1,189 @@
1/*
2 * linux/drivers/char/hpilo.h
3 *
4 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
5 * David Altobelli <david.altobelli@hp.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef __HPILO_H
12#define __HPILO_H
13
14#define ILO_NAME "hpilo"
15
16/* max number of open channel control blocks per device, hw limited to 32 */
17#define MAX_CCB 8
18/* max number of supported devices */
19#define MAX_ILO_DEV 1
20/* max number of files */
21#define MAX_OPEN (MAX_CCB * MAX_ILO_DEV)
22
23/*
24 * Per device, used to track global memory allocations.
25 */
26struct ilo_hwinfo {
27 /* mmio registers on device */
28 char __iomem *mmio_vaddr;
29
30 /* doorbell registers on device */
31 char __iomem *db_vaddr;
32
33 /* shared memory on device used for channel control blocks */
34 char __iomem *ram_vaddr;
35
36 /* files corresponding to this device */
37 struct ccb_data *ccb_alloc[MAX_CCB];
38
39 struct pci_dev *ilo_dev;
40
41 spinlock_t alloc_lock;
42 spinlock_t fifo_lock;
43
44 struct cdev cdev;
45};
46
47/* offset from mmio_vaddr */
48#define DB_OUT 0xD4
49/* DB_OUT reset bit */
50#define DB_RESET 26
51
52/*
53 * Channel control block. Used to manage hardware queues.
54 * The format must match hw's version. The hw ccb is 128 bytes,
55 * but the context area shouldn't be touched by the driver.
56 */
57#define ILOSW_CCB_SZ 64
58#define ILOHW_CCB_SZ 128
59struct ccb {
60 union {
61 char *send_fifobar;
62 u64 padding1;
63 } ccb_u1;
64 union {
65 char *send_desc;
66 u64 padding2;
67 } ccb_u2;
68 u64 send_ctrl;
69
70 union {
71 char *recv_fifobar;
72 u64 padding3;
73 } ccb_u3;
74 union {
75 char *recv_desc;
76 u64 padding4;
77 } ccb_u4;
78 u64 recv_ctrl;
79
80 union {
81 char __iomem *db_base;
82 u64 padding5;
83 } ccb_u5;
84
85 u64 channel;
86
87 /* unused context area (64 bytes) */
88};
89
90/* ccb queue parameters */
91#define SENDQ 1
92#define RECVQ 2
93#define NR_QENTRY 4
94#define L2_QENTRY_SZ 12
95
96/* ccb ctrl bitfields */
97#define CTRL_BITPOS_L2SZ 0
98#define CTRL_BITPOS_FIFOINDEXMASK 4
99#define CTRL_BITPOS_DESCLIMIT 18
100#define CTRL_BITPOS_A 30
101#define CTRL_BITPOS_G 31
102
103/* ccb doorbell macros */
104#define L2_DB_SIZE 14
105#define ONE_DB_SIZE (1 << L2_DB_SIZE)
106
107/*
108 * Per fd structure used to track the ccb allocated to that dev file.
109 */
110struct ccb_data {
111 /* software version of ccb, using virtual addrs */
112 struct ccb driver_ccb;
113
114 /* hardware version of ccb, using physical addrs */
115 struct ccb ilo_ccb;
116
117 /* hardware ccb is written to this shared mapped device memory */
118 struct ccb __iomem *mapped_ccb;
119
120 /* dma'able memory used for send/recv queues */
121 void *dma_va;
122 dma_addr_t dma_pa;
123 size_t dma_size;
124
125 /* pointer to hardware device info */
126 struct ilo_hwinfo *ilo_hw;
127
128 /* usage count, to allow for shared ccb's */
129 int ccb_cnt;
130
131 /* open wanted exclusive access to this ccb */
132 int ccb_excl;
133};
134
135/*
136 * FIFO queue structure, shared with hw.
137 */
138#define ILO_START_ALIGN 4096
139#define ILO_CACHE_SZ 128
140struct fifo {
141 u64 nrents; /* user requested number of fifo entries */
142 u64 imask; /* mask to extract valid fifo index */
143 u64 merge; /* O/C bits to merge in during enqueue operation */
144 u64 reset; /* set to non-zero when the target device resets */
145 u8 pad_0[ILO_CACHE_SZ - (sizeof(u64) * 4)];
146
147 u64 head;
148 u8 pad_1[ILO_CACHE_SZ - (sizeof(u64))];
149
150 u64 tail;
151 u8 pad_2[ILO_CACHE_SZ - (sizeof(u64))];
152
153 u64 fifobar[1];
154};
155
156/* convert between struct fifo, and the fifobar, which is saved in the ccb */
157#define FIFOHANDLESIZE (sizeof(struct fifo) - sizeof(u64))
158#define FIFOBARTOHANDLE(_fifo) \
159 ((struct fifo *)(((char *)(_fifo)) - FIFOHANDLESIZE))
160
161/* the number of qwords to consume from the entry descriptor */
162#define ENTRY_BITPOS_QWORDS 0
163/* descriptor index number (within a specified queue) */
164#define ENTRY_BITPOS_DESCRIPTOR 10
165/* state bit, fifo entry consumed by consumer */
166#define ENTRY_BITPOS_C 22
167/* state bit, fifo entry is occupied */
168#define ENTRY_BITPOS_O 23
169
170#define ENTRY_BITS_QWORDS 10
171#define ENTRY_BITS_DESCRIPTOR 12
172#define ENTRY_BITS_C 1
173#define ENTRY_BITS_O 1
174#define ENTRY_BITS_TOTAL \
175 (ENTRY_BITS_C + ENTRY_BITS_O + \
176 ENTRY_BITS_QWORDS + ENTRY_BITS_DESCRIPTOR)
177
178/* extract various entry fields */
179#define ENTRY_MASK ((1 << ENTRY_BITS_TOTAL) - 1)
180#define ENTRY_MASK_C (((1 << ENTRY_BITS_C) - 1) << ENTRY_BITPOS_C)
181#define ENTRY_MASK_O (((1 << ENTRY_BITS_O) - 1) << ENTRY_BITPOS_O)
182#define ENTRY_MASK_QWORDS \
183 (((1 << ENTRY_BITS_QWORDS) - 1) << ENTRY_BITPOS_QWORDS)
184#define ENTRY_MASK_DESCRIPTOR \
185 (((1 << ENTRY_BITS_DESCRIPTOR) - 1) << ENTRY_BITPOS_DESCRIPTOR)
186
187#define ENTRY_MASK_NOSTATE (ENTRY_MASK >> (ENTRY_BITS_C + ENTRY_BITS_O))
188
189#endif /* __HPILO_H */
diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index 186162470090..4ce3bdc2f959 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -399,8 +399,9 @@ static int __devinit phantom_probe(struct pci_dev *pdev,
399 goto err_irq; 399 goto err_irq;
400 } 400 }
401 401
402 if (IS_ERR(device_create(phantom_class, &pdev->dev, MKDEV(phantom_major, 402 if (IS_ERR(device_create_drvdata(phantom_class, &pdev->dev,
403 minor), "phantom%u", minor))) 403 MKDEV(phantom_major, minor),
404 NULL, "phantom%u", minor)))
404 dev_err(&pdev->dev, "can't create device\n"); 405 dev_err(&pdev->dev, "can't create device\n");
405 406
406 pci_set_drvdata(pdev, pht); 407 pci_set_drvdata(pdev, pht);
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 519d942e7940..7b72a1b36115 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -241,6 +241,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
241{ 241{
242 struct block_device *bdev; 242 struct block_device *bdev;
243 struct block2mtd_dev *dev; 243 struct block2mtd_dev *dev;
244 char *name;
244 245
245 if (!devname) 246 if (!devname)
246 return NULL; 247 return NULL;
@@ -279,12 +280,13 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
279 280
280 /* Setup the MTD structure */ 281 /* Setup the MTD structure */
281 /* make the name contain the block device in */ 282 /* make the name contain the block device in */
282 dev->mtd.name = kmalloc(sizeof("block2mtd: ") + strlen(devname), 283 name = kmalloc(sizeof("block2mtd: ") + strlen(devname) + 1,
283 GFP_KERNEL); 284 GFP_KERNEL);
284 if (!dev->mtd.name) 285 if (!name)
285 goto devinit_err; 286 goto devinit_err;
286 287
287 sprintf(dev->mtd.name, "block2mtd: %s", devname); 288 sprintf(name, "block2mtd: %s", devname);
289 dev->mtd.name = name;
288 290
289 dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK; 291 dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
290 dev->mtd.erasesize = erase_size; 292 dev->mtd.erasesize = erase_size;
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 129d429cd2da..aef9f4b687c9 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -28,10 +28,13 @@ static void mtd_notify_add(struct mtd_info* mtd)
28 if (!mtd) 28 if (!mtd)
29 return; 29 return;
30 30
31 device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), "mtd%d", mtd->index); 31 device_create_drvdata(mtd_class, NULL,
32 MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
33 NULL, "mtd%d", mtd->index);
32 34
33 device_create(mtd_class, NULL, 35 device_create_drvdata(mtd_class, NULL,
34 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), "mtd%dro", mtd->index); 36 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
37 NULL, "mtd%dro", mtd->index);
35} 38}
36 39
37static void mtd_notify_remove(struct mtd_info* mtd) 40static void mtd_notify_remove(struct mtd_info* mtd)
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index aabad8ce7458..8db4e6b89482 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -1010,7 +1010,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1010 static int printed_version; 1010 static int printed_version;
1011 int retval, print_info; 1011 int retval, print_info;
1012 struct vortex_chip_info * const vci = &vortex_info_tbl[chip_idx]; 1012 struct vortex_chip_info * const vci = &vortex_info_tbl[chip_idx];
1013 char *print_name = "3c59x"; 1013 const char *print_name = "3c59x";
1014 struct pci_dev *pdev = NULL; 1014 struct pci_dev *pdev = NULL;
1015 struct eisa_device *edev = NULL; 1015 struct eisa_device *edev = NULL;
1016 DECLARE_MAC_BUF(mac); 1016 DECLARE_MAC_BUF(mac);
diff --git a/drivers/net/arm/at91_ether.c b/drivers/net/arm/at91_ether.c
index 1e39e78f1778..71f7cec30911 100644
--- a/drivers/net/arm/at91_ether.c
+++ b/drivers/net/arm/at91_ether.c
@@ -677,7 +677,7 @@ static void at91ether_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo
677{ 677{
678 strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); 678 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
679 strlcpy(info->version, DRV_VERSION, sizeof(info->version)); 679 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
680 strlcpy(info->bus_info, dev->dev.parent->bus_id, sizeof(info->bus_info)); 680 strlcpy(info->bus_info, dev_name(dev->dev.parent), sizeof(info->bus_info));
681} 681}
682 682
683static const struct ethtool_ops at91ether_ethtool_ops = { 683static const struct ethtool_ops at91ether_ethtool_ops = {
diff --git a/drivers/net/arm/ep93xx_eth.c b/drivers/net/arm/ep93xx_eth.c
index ecd8fc6146e9..7a14980f3472 100644
--- a/drivers/net/arm/ep93xx_eth.c
+++ b/drivers/net/arm/ep93xx_eth.c
@@ -848,7 +848,7 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
848 848
849 ep->res = request_mem_region(pdev->resource[0].start, 849 ep->res = request_mem_region(pdev->resource[0].start,
850 pdev->resource[0].end - pdev->resource[0].start + 1, 850 pdev->resource[0].end - pdev->resource[0].start + 1,
851 pdev->dev.bus_id); 851 dev_name(&pdev->dev));
852 if (ep->res == NULL) { 852 if (ep->res == NULL) {
853 dev_err(&pdev->dev, "Could not reserve memory region\n"); 853 dev_err(&pdev->dev, "Could not reserve memory region\n");
854 err = -ENOMEM; 854 err = -ENOMEM;
diff --git a/drivers/net/arm/etherh.c b/drivers/net/arm/etherh.c
index e9d15eccad08..5c5f1e470d3c 100644
--- a/drivers/net/arm/etherh.c
+++ b/drivers/net/arm/etherh.c
@@ -535,7 +535,7 @@ static int __init etherh_addr(char *addr, struct expansion_card *ec)
535 535
536 if (!ecard_readchunk(&cd, ec, 0xf5, 0)) { 536 if (!ecard_readchunk(&cd, ec, 0xf5, 0)) {
537 printk(KERN_ERR "%s: unable to read podule description string\n", 537 printk(KERN_ERR "%s: unable to read podule description string\n",
538 ec->dev.bus_id); 538 dev_name(&ec->dev));
539 goto no_addr; 539 goto no_addr;
540 } 540 }
541 541
@@ -554,7 +554,7 @@ static int __init etherh_addr(char *addr, struct expansion_card *ec)
554 } 554 }
555 555
556 printk(KERN_ERR "%s: unable to parse MAC address: %s\n", 556 printk(KERN_ERR "%s: unable to parse MAC address: %s\n",
557 ec->dev.bus_id, cd.d.string); 557 dev_name(&ec->dev), cd.d.string);
558 558
559 no_addr: 559 no_addr:
560 return -ENODEV; 560 return -ENODEV;
@@ -585,7 +585,7 @@ static void etherh_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *i
585{ 585{
586 strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); 586 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
587 strlcpy(info->version, DRV_VERSION, sizeof(info->version)); 587 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
588 strlcpy(info->bus_info, dev->dev.parent->bus_id, 588 strlcpy(info->bus_info, dev_name(dev->dev.parent),
589 sizeof(info->bus_info)); 589 sizeof(info->bus_info));
590} 590}
591 591
diff --git a/drivers/net/atlx/atl1.c b/drivers/net/atlx/atl1.c
index 3e22e7817bc3..f12e3d12474b 100644
--- a/drivers/net/atlx/atl1.c
+++ b/drivers/net/atlx/atl1.c
@@ -1308,7 +1308,6 @@ static u32 atl1_check_link(struct atl1_adapter *adapter)
1308 dev_info(&adapter->pdev->dev, "link is down\n"); 1308 dev_info(&adapter->pdev->dev, "link is down\n");
1309 adapter->link_speed = SPEED_0; 1309 adapter->link_speed = SPEED_0;
1310 netif_carrier_off(netdev); 1310 netif_carrier_off(netdev);
1311 netif_stop_queue(netdev);
1312 } 1311 }
1313 return 0; 1312 return 0;
1314 } 1313 }
@@ -1358,7 +1357,6 @@ static u32 atl1_check_link(struct atl1_adapter *adapter)
1358 if (!netif_carrier_ok(netdev)) { 1357 if (!netif_carrier_ok(netdev)) {
1359 /* Link down -> Up */ 1358 /* Link down -> Up */
1360 netif_carrier_on(netdev); 1359 netif_carrier_on(netdev);
1361 netif_wake_queue(netdev);
1362 } 1360 }
1363 return 0; 1361 return 0;
1364 } 1362 }
@@ -2627,6 +2625,7 @@ static s32 atl1_up(struct atl1_adapter *adapter)
2627 mod_timer(&adapter->watchdog_timer, jiffies); 2625 mod_timer(&adapter->watchdog_timer, jiffies);
2628 atlx_irq_enable(adapter); 2626 atlx_irq_enable(adapter);
2629 atl1_check_link(adapter); 2627 atl1_check_link(adapter);
2628 netif_start_queue(netdev);
2630 return 0; 2629 return 0;
2631 2630
2632err_up: 2631err_up:
diff --git a/drivers/net/fs_enet/Makefile b/drivers/net/fs_enet/Makefile
index 1ffbe0756a0c..d4a305ee3455 100644
--- a/drivers/net/fs_enet/Makefile
+++ b/drivers/net/fs_enet/Makefile
@@ -8,12 +8,7 @@ fs_enet-$(CONFIG_FS_ENET_HAS_SCC) += mac-scc.o
8fs_enet-$(CONFIG_FS_ENET_HAS_FEC) += mac-fec.o 8fs_enet-$(CONFIG_FS_ENET_HAS_FEC) += mac-fec.o
9fs_enet-$(CONFIG_FS_ENET_HAS_FCC) += mac-fcc.o 9fs_enet-$(CONFIG_FS_ENET_HAS_FCC) += mac-fcc.o
10 10
11ifeq ($(CONFIG_PPC_CPM_NEW_BINDING),y)
12obj-$(CONFIG_FS_ENET_MDIO_FEC) += mii-fec.o 11obj-$(CONFIG_FS_ENET_MDIO_FEC) += mii-fec.o
13obj-$(CONFIG_FS_ENET_MDIO_FCC) += mii-bitbang.o 12obj-$(CONFIG_FS_ENET_MDIO_FCC) += mii-bitbang.o
14else
15fs_enet-$(CONFIG_FS_ENET_MDIO_FEC) += mii-fec.o
16fs_enet-$(CONFIG_FS_ENET_MDIO_FCC) += mii-bitbang.o
17endif
18 13
19fs_enet-objs := fs_enet-main.o $(fs_enet-m) 14fs_enet-objs := fs_enet-main.o $(fs_enet-m)
diff --git a/drivers/net/fs_enet/fs_enet-main.c b/drivers/net/fs_enet/fs_enet-main.c
index 445763e5648e..92591384afa5 100644
--- a/drivers/net/fs_enet/fs_enet-main.c
+++ b/drivers/net/fs_enet/fs_enet-main.c
@@ -36,26 +36,18 @@
36#include <linux/fs.h> 36#include <linux/fs.h>
37#include <linux/platform_device.h> 37#include <linux/platform_device.h>
38#include <linux/phy.h> 38#include <linux/phy.h>
39#include <linux/of_platform.h>
40#include <linux/of_gpio.h>
39 41
40#include <linux/vmalloc.h> 42#include <linux/vmalloc.h>
41#include <asm/pgtable.h> 43#include <asm/pgtable.h>
42#include <asm/irq.h> 44#include <asm/irq.h>
43#include <asm/uaccess.h> 45#include <asm/uaccess.h>
44 46
45#ifdef CONFIG_PPC_CPM_NEW_BINDING
46#include <linux/of_gpio.h>
47#include <linux/of_platform.h>
48#endif
49
50#include "fs_enet.h" 47#include "fs_enet.h"
51 48
52/*************************************************/ 49/*************************************************/
53 50
54#ifndef CONFIG_PPC_CPM_NEW_BINDING
55static char version[] __devinitdata =
56 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")" "\n";
57#endif
58
59MODULE_AUTHOR("Pantelis Antoniou <panto@intracom.gr>"); 51MODULE_AUTHOR("Pantelis Antoniou <panto@intracom.gr>");
60MODULE_DESCRIPTION("Freescale Ethernet Driver"); 52MODULE_DESCRIPTION("Freescale Ethernet Driver");
61MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
@@ -958,190 +950,6 @@ static int fs_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
958extern int fs_mii_connect(struct net_device *dev); 950extern int fs_mii_connect(struct net_device *dev);
959extern void fs_mii_disconnect(struct net_device *dev); 951extern void fs_mii_disconnect(struct net_device *dev);
960 952
961#ifndef CONFIG_PPC_CPM_NEW_BINDING
962static struct net_device *fs_init_instance(struct device *dev,
963 struct fs_platform_info *fpi)
964{
965 struct net_device *ndev = NULL;
966 struct fs_enet_private *fep = NULL;
967 int privsize, i, r, err = 0, registered = 0;
968
969 fpi->fs_no = fs_get_id(fpi);
970 /* guard */
971 if ((unsigned int)fpi->fs_no >= FS_MAX_INDEX)
972 return ERR_PTR(-EINVAL);
973
974 privsize = sizeof(*fep) + (sizeof(struct sk_buff **) *
975 (fpi->rx_ring + fpi->tx_ring));
976
977 ndev = alloc_etherdev(privsize);
978 if (!ndev) {
979 err = -ENOMEM;
980 goto err;
981 }
982
983 fep = netdev_priv(ndev);
984
985 fep->dev = dev;
986 dev_set_drvdata(dev, ndev);
987 fep->fpi = fpi;
988 if (fpi->init_ioports)
989 fpi->init_ioports((struct fs_platform_info *)fpi);
990
991#ifdef CONFIG_FS_ENET_HAS_FEC
992 if (fs_get_fec_index(fpi->fs_no) >= 0)
993 fep->ops = &fs_fec_ops;
994#endif
995
996#ifdef CONFIG_FS_ENET_HAS_SCC
997 if (fs_get_scc_index(fpi->fs_no) >=0)
998 fep->ops = &fs_scc_ops;
999#endif
1000
1001#ifdef CONFIG_FS_ENET_HAS_FCC
1002 if (fs_get_fcc_index(fpi->fs_no) >= 0)
1003 fep->ops = &fs_fcc_ops;
1004#endif
1005
1006 if (fep->ops == NULL) {
1007 printk(KERN_ERR DRV_MODULE_NAME
1008 ": %s No matching ops found (%d).\n",
1009 ndev->name, fpi->fs_no);
1010 err = -EINVAL;
1011 goto err;
1012 }
1013
1014 r = (*fep->ops->setup_data)(ndev);
1015 if (r != 0) {
1016 printk(KERN_ERR DRV_MODULE_NAME
1017 ": %s setup_data failed\n",
1018 ndev->name);
1019 err = r;
1020 goto err;
1021 }
1022
1023 /* point rx_skbuff, tx_skbuff */
1024 fep->rx_skbuff = (struct sk_buff **)&fep[1];
1025 fep->tx_skbuff = fep->rx_skbuff + fpi->rx_ring;
1026
1027 /* init locks */
1028 spin_lock_init(&fep->lock);
1029 spin_lock_init(&fep->tx_lock);
1030
1031 /*
1032 * Set the Ethernet address.
1033 */
1034 for (i = 0; i < 6; i++)
1035 ndev->dev_addr[i] = fpi->macaddr[i];
1036
1037 r = (*fep->ops->allocate_bd)(ndev);
1038
1039 if (fep->ring_base == NULL) {
1040 printk(KERN_ERR DRV_MODULE_NAME
1041 ": %s buffer descriptor alloc failed (%d).\n", ndev->name, r);
1042 err = r;
1043 goto err;
1044 }
1045
1046 /*
1047 * Set receive and transmit descriptor base.
1048 */
1049 fep->rx_bd_base = fep->ring_base;
1050 fep->tx_bd_base = fep->rx_bd_base + fpi->rx_ring;
1051
1052 /* initialize ring size variables */
1053 fep->tx_ring = fpi->tx_ring;
1054 fep->rx_ring = fpi->rx_ring;
1055
1056 /*
1057 * The FEC Ethernet specific entries in the device structure.
1058 */
1059 ndev->open = fs_enet_open;
1060 ndev->hard_start_xmit = fs_enet_start_xmit;
1061 ndev->tx_timeout = fs_timeout;
1062 ndev->watchdog_timeo = 2 * HZ;
1063 ndev->stop = fs_enet_close;
1064 ndev->get_stats = fs_enet_get_stats;
1065 ndev->set_multicast_list = fs_set_multicast_list;
1066
1067#ifdef CONFIG_NET_POLL_CONTROLLER
1068 ndev->poll_controller = fs_enet_netpoll;
1069#endif
1070
1071 netif_napi_add(ndev, &fep->napi,
1072 fs_enet_rx_napi, fpi->napi_weight);
1073
1074 ndev->ethtool_ops = &fs_ethtool_ops;
1075 ndev->do_ioctl = fs_ioctl;
1076
1077 init_timer(&fep->phy_timer_list);
1078
1079 netif_carrier_off(ndev);
1080
1081 err = register_netdev(ndev);
1082 if (err != 0) {
1083 printk(KERN_ERR DRV_MODULE_NAME
1084 ": %s register_netdev failed.\n", ndev->name);
1085 goto err;
1086 }
1087 registered = 1;
1088
1089
1090 return ndev;
1091
1092err:
1093 if (ndev != NULL) {
1094 if (registered)
1095 unregister_netdev(ndev);
1096
1097 if (fep && fep->ops) {
1098 (*fep->ops->free_bd)(ndev);
1099 (*fep->ops->cleanup_data)(ndev);
1100 }
1101
1102 free_netdev(ndev);
1103 }
1104
1105 dev_set_drvdata(dev, NULL);
1106
1107 return ERR_PTR(err);
1108}
1109
1110static int fs_cleanup_instance(struct net_device *ndev)
1111{
1112 struct fs_enet_private *fep;
1113 const struct fs_platform_info *fpi;
1114 struct device *dev;
1115
1116 if (ndev == NULL)
1117 return -EINVAL;
1118
1119 fep = netdev_priv(ndev);
1120 if (fep == NULL)
1121 return -EINVAL;
1122
1123 fpi = fep->fpi;
1124
1125 unregister_netdev(ndev);
1126
1127 dma_free_coherent(fep->dev, (fpi->tx_ring + fpi->rx_ring) * sizeof(cbd_t),
1128 (void __force *)fep->ring_base, fep->ring_mem_addr);
1129
1130 /* reset it */
1131 (*fep->ops->cleanup_data)(ndev);
1132
1133 dev = fep->dev;
1134 if (dev != NULL) {
1135 dev_set_drvdata(dev, NULL);
1136 fep->dev = NULL;
1137 }
1138
1139 free_netdev(ndev);
1140
1141 return 0;
1142}
1143#endif
1144
1145/**************************************************************************************/ 953/**************************************************************************************/
1146 954
1147/* handy pointer to the immap */ 955/* handy pointer to the immap */
@@ -1168,7 +976,6 @@ static void cleanup_immap(void)
1168 976
1169/**************************************************************************************/ 977/**************************************************************************************/
1170 978
1171#ifdef CONFIG_PPC_CPM_NEW_BINDING
1172static int __devinit find_phy(struct device_node *np, 979static int __devinit find_phy(struct device_node *np,
1173 struct fs_platform_info *fpi) 980 struct fs_platform_info *fpi)
1174{ 981{
@@ -1408,121 +1215,6 @@ static void __exit fs_cleanup(void)
1408 of_unregister_platform_driver(&fs_enet_driver); 1215 of_unregister_platform_driver(&fs_enet_driver);
1409 cleanup_immap(); 1216 cleanup_immap();
1410} 1217}
1411#else
1412static int __devinit fs_enet_probe(struct device *dev)
1413{
1414 struct net_device *ndev;
1415
1416 /* no fixup - no device */
1417 if (dev->platform_data == NULL) {
1418 printk(KERN_INFO "fs_enet: "
1419 "probe called with no platform data; "
1420 "remove unused devices\n");
1421 return -ENODEV;
1422 }
1423
1424 ndev = fs_init_instance(dev, dev->platform_data);
1425 if (IS_ERR(ndev))
1426 return PTR_ERR(ndev);
1427 return 0;
1428}
1429
1430static int fs_enet_remove(struct device *dev)
1431{
1432 return fs_cleanup_instance(dev_get_drvdata(dev));
1433}
1434
1435static struct device_driver fs_enet_fec_driver = {
1436 .name = "fsl-cpm-fec",
1437 .bus = &platform_bus_type,
1438 .probe = fs_enet_probe,
1439 .remove = fs_enet_remove,
1440#ifdef CONFIG_PM
1441/* .suspend = fs_enet_suspend, TODO */
1442/* .resume = fs_enet_resume, TODO */
1443#endif
1444};
1445
1446static struct device_driver fs_enet_scc_driver = {
1447 .name = "fsl-cpm-scc",
1448 .bus = &platform_bus_type,
1449 .probe = fs_enet_probe,
1450 .remove = fs_enet_remove,
1451#ifdef CONFIG_PM
1452/* .suspend = fs_enet_suspend, TODO */
1453/* .resume = fs_enet_resume, TODO */
1454#endif
1455};
1456
1457static struct device_driver fs_enet_fcc_driver = {
1458 .name = "fsl-cpm-fcc",
1459 .bus = &platform_bus_type,
1460 .probe = fs_enet_probe,
1461 .remove = fs_enet_remove,
1462#ifdef CONFIG_PM
1463/* .suspend = fs_enet_suspend, TODO */
1464/* .resume = fs_enet_resume, TODO */
1465#endif
1466};
1467
1468static int __init fs_init(void)
1469{
1470 int r;
1471
1472 printk(KERN_INFO
1473 "%s", version);
1474
1475 r = setup_immap();
1476 if (r != 0)
1477 return r;
1478
1479#ifdef CONFIG_FS_ENET_HAS_FCC
1480 /* let's insert mii stuff */
1481 r = fs_enet_mdio_bb_init();
1482
1483 if (r != 0) {
1484 printk(KERN_ERR DRV_MODULE_NAME
1485 "BB PHY init failed.\n");
1486 return r;
1487 }
1488 r = driver_register(&fs_enet_fcc_driver);
1489 if (r != 0)
1490 goto err;
1491#endif
1492
1493#ifdef CONFIG_FS_ENET_HAS_FEC
1494 r = fs_enet_mdio_fec_init();
1495 if (r != 0) {
1496 printk(KERN_ERR DRV_MODULE_NAME
1497 "FEC PHY init failed.\n");
1498 return r;
1499 }
1500
1501 r = driver_register(&fs_enet_fec_driver);
1502 if (r != 0)
1503 goto err;
1504#endif
1505
1506#ifdef CONFIG_FS_ENET_HAS_SCC
1507 r = driver_register(&fs_enet_scc_driver);
1508 if (r != 0)
1509 goto err;
1510#endif
1511
1512 return 0;
1513err:
1514 cleanup_immap();
1515 return r;
1516}
1517
1518static void __exit fs_cleanup(void)
1519{
1520 driver_unregister(&fs_enet_fec_driver);
1521 driver_unregister(&fs_enet_fcc_driver);
1522 driver_unregister(&fs_enet_scc_driver);
1523 cleanup_immap();
1524}
1525#endif
1526 1218
1527#ifdef CONFIG_NET_POLL_CONTROLLER 1219#ifdef CONFIG_NET_POLL_CONTROLLER
1528static void fs_enet_netpoll(struct net_device *dev) 1220static void fs_enet_netpoll(struct net_device *dev)
diff --git a/drivers/net/fs_enet/fs_enet.h b/drivers/net/fs_enet/fs_enet.h
index e05389c49bbb..db46d2e72329 100644
--- a/drivers/net/fs_enet/fs_enet.h
+++ b/drivers/net/fs_enet/fs_enet.h
@@ -138,10 +138,6 @@ struct fs_enet_private {
138}; 138};
139 139
140/***************************************************************************/ 140/***************************************************************************/
141#ifndef CONFIG_PPC_CPM_NEW_BINDING
142int fs_enet_mdio_bb_init(void);
143int fs_enet_mdio_fec_init(void);
144#endif
145 141
146void fs_init_bds(struct net_device *dev); 142void fs_init_bds(struct net_device *dev);
147void fs_cleanup_bds(struct net_device *dev); 143void fs_cleanup_bds(struct net_device *dev);
diff --git a/drivers/net/fs_enet/mac-fcc.c b/drivers/net/fs_enet/mac-fcc.c
index 8268b3535b30..0a97fc2d97ec 100644
--- a/drivers/net/fs_enet/mac-fcc.c
+++ b/drivers/net/fs_enet/mac-fcc.c
@@ -33,6 +33,7 @@
33#include <linux/fs.h> 33#include <linux/fs.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/phy.h> 35#include <linux/phy.h>
36#include <linux/of_device.h>
36 37
37#include <asm/immap_cpm2.h> 38#include <asm/immap_cpm2.h>
38#include <asm/mpc8260.h> 39#include <asm/mpc8260.h>
@@ -42,10 +43,6 @@
42#include <asm/irq.h> 43#include <asm/irq.h>
43#include <asm/uaccess.h> 44#include <asm/uaccess.h>
44 45
45#ifdef CONFIG_PPC_CPM_NEW_BINDING
46#include <asm/of_device.h>
47#endif
48
49#include "fs_enet.h" 46#include "fs_enet.h"
50 47
51/*************************************************/ 48/*************************************************/
@@ -87,7 +84,6 @@ static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 op)
87 84
88static int do_pd_setup(struct fs_enet_private *fep) 85static int do_pd_setup(struct fs_enet_private *fep)
89{ 86{
90#ifdef CONFIG_PPC_CPM_NEW_BINDING
91 struct of_device *ofdev = to_of_device(fep->dev); 87 struct of_device *ofdev = to_of_device(fep->dev);
92 struct fs_platform_info *fpi = fep->fpi; 88 struct fs_platform_info *fpi = fep->fpi;
93 int ret = -EINVAL; 89 int ret = -EINVAL;
@@ -125,44 +121,6 @@ out_fccp:
125 iounmap(fep->fcc.fccp); 121 iounmap(fep->fcc.fccp);
126out: 122out:
127 return ret; 123 return ret;
128#else
129 struct platform_device *pdev = to_platform_device(fep->dev);
130 struct resource *r;
131
132 /* Fill out IRQ field */
133 fep->interrupt = platform_get_irq(pdev, 0);
134 if (fep->interrupt < 0)
135 return -EINVAL;
136
137 /* Attach the memory for the FCC Parameter RAM */
138 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_pram");
139 fep->fcc.ep = ioremap(r->start, r->end - r->start + 1);
140 if (fep->fcc.ep == NULL)
141 return -EINVAL;
142
143 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_regs");
144 fep->fcc.fccp = ioremap(r->start, r->end - r->start + 1);
145 if (fep->fcc.fccp == NULL)
146 return -EINVAL;
147
148 if (fep->fpi->fcc_regs_c) {
149 fep->fcc.fcccp = (void __iomem *)fep->fpi->fcc_regs_c;
150 } else {
151 r = platform_get_resource_byname(pdev, IORESOURCE_MEM,
152 "fcc_regs_c");
153 fep->fcc.fcccp = ioremap(r->start,
154 r->end - r->start + 1);
155 }
156
157 if (fep->fcc.fcccp == NULL)
158 return -EINVAL;
159
160 fep->fcc.mem = (void __iomem *)fep->fpi->mem_offset;
161 if (fep->fcc.mem == NULL)
162 return -EINVAL;
163
164 return 0;
165#endif
166} 124}
167 125
168#define FCC_NAPI_RX_EVENT_MSK (FCC_ENET_RXF | FCC_ENET_RXB) 126#define FCC_NAPI_RX_EVENT_MSK (FCC_ENET_RXF | FCC_ENET_RXB)
@@ -173,17 +131,6 @@ out:
173static int setup_data(struct net_device *dev) 131static int setup_data(struct net_device *dev)
174{ 132{
175 struct fs_enet_private *fep = netdev_priv(dev); 133 struct fs_enet_private *fep = netdev_priv(dev);
176#ifndef CONFIG_PPC_CPM_NEW_BINDING
177 struct fs_platform_info *fpi = fep->fpi;
178
179 fpi->cp_command = (fpi->cp_page << 26) |
180 (fpi->cp_block << 21) |
181 (12 << 6);
182
183 fep->fcc.idx = fs_get_fcc_index(fpi->fs_no);
184 if ((unsigned int)fep->fcc.idx >= 3) /* max 3 FCCs */
185 return -EINVAL;
186#endif
187 134
188 if (do_pd_setup(fep) != 0) 135 if (do_pd_setup(fep) != 0)
189 return -EINVAL; 136 return -EINVAL;
@@ -304,9 +251,6 @@ static void restart(struct net_device *dev)
304 fcc_enet_t __iomem *ep = fep->fcc.ep; 251 fcc_enet_t __iomem *ep = fep->fcc.ep;
305 dma_addr_t rx_bd_base_phys, tx_bd_base_phys; 252 dma_addr_t rx_bd_base_phys, tx_bd_base_phys;
306 u16 paddrh, paddrm, paddrl; 253 u16 paddrh, paddrm, paddrl;
307#ifndef CONFIG_PPC_CPM_NEW_BINDING
308 u16 mem_addr;
309#endif
310 const unsigned char *mac; 254 const unsigned char *mac;
311 int i; 255 int i;
312 256
@@ -338,19 +282,10 @@ static void restart(struct net_device *dev)
338 * this area. 282 * this area.
339 */ 283 */
340 284
341#ifdef CONFIG_PPC_CPM_NEW_BINDING
342 W16(ep, fen_genfcc.fcc_riptr, fpi->dpram_offset); 285 W16(ep, fen_genfcc.fcc_riptr, fpi->dpram_offset);
343 W16(ep, fen_genfcc.fcc_tiptr, fpi->dpram_offset + 32); 286 W16(ep, fen_genfcc.fcc_tiptr, fpi->dpram_offset + 32);
344 287
345 W16(ep, fen_padptr, fpi->dpram_offset + 64); 288 W16(ep, fen_padptr, fpi->dpram_offset + 64);
346#else
347 mem_addr = (u32) fep->fcc.mem; /* de-fixup dpram offset */
348
349 W16(ep, fen_genfcc.fcc_riptr, (mem_addr & 0xffff));
350 W16(ep, fen_genfcc.fcc_tiptr, ((mem_addr + 32) & 0xffff));
351
352 W16(ep, fen_padptr, mem_addr + 64);
353#endif
354 289
355 /* fill with special symbol... */ 290 /* fill with special symbol... */
356 memset_io(fep->fcc.mem + fpi->dpram_offset + 64, 0x88, 32); 291 memset_io(fep->fcc.mem + fpi->dpram_offset + 64, 0x88, 32);
diff --git a/drivers/net/fs_enet/mac-fec.c b/drivers/net/fs_enet/mac-fec.c
index 8a311d1e435b..0a7d1c5c6524 100644
--- a/drivers/net/fs_enet/mac-fec.c
+++ b/drivers/net/fs_enet/mac-fec.c
@@ -32,6 +32,7 @@
32#include <linux/bitops.h> 32#include <linux/bitops.h>
33#include <linux/fs.h> 33#include <linux/fs.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/of_device.h>
35 36
36#include <asm/irq.h> 37#include <asm/irq.h>
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
@@ -43,10 +44,6 @@
43#include <asm/cpm1.h> 44#include <asm/cpm1.h>
44#endif 45#endif
45 46
46#ifdef CONFIG_PPC_CPM_NEW_BINDING
47#include <asm/of_device.h>
48#endif
49
50#include "fs_enet.h" 47#include "fs_enet.h"
51#include "fec.h" 48#include "fec.h"
52 49
@@ -99,7 +96,6 @@ static int whack_reset(fec_t __iomem *fecp)
99 96
100static int do_pd_setup(struct fs_enet_private *fep) 97static int do_pd_setup(struct fs_enet_private *fep)
101{ 98{
102#ifdef CONFIG_PPC_CPM_NEW_BINDING
103 struct of_device *ofdev = to_of_device(fep->dev); 99 struct of_device *ofdev = to_of_device(fep->dev);
104 100
105 fep->interrupt = of_irq_to_resource(ofdev->node, 0, NULL); 101 fep->interrupt = of_irq_to_resource(ofdev->node, 0, NULL);
@@ -111,23 +107,6 @@ static int do_pd_setup(struct fs_enet_private *fep)
111 return -EINVAL; 107 return -EINVAL;
112 108
113 return 0; 109 return 0;
114#else
115 struct platform_device *pdev = to_platform_device(fep->dev);
116 struct resource *r;
117
118 /* Fill out IRQ field */
119 fep->interrupt = platform_get_irq_byname(pdev,"interrupt");
120 if (fep->interrupt < 0)
121 return -EINVAL;
122
123 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
124 fep->fec.fecp = ioremap(r->start, r->end - r->start + 1);
125
126 if(fep->fec.fecp == NULL)
127 return -EINVAL;
128
129 return 0;
130#endif
131} 110}
132 111
133#define FEC_NAPI_RX_EVENT_MSK (FEC_ENET_RXF | FEC_ENET_RXB) 112#define FEC_NAPI_RX_EVENT_MSK (FEC_ENET_RXF | FEC_ENET_RXB)
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
index e3557eca7b6d..029b3c7ef29c 100644
--- a/drivers/net/fs_enet/mac-scc.c
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -32,6 +32,7 @@
32#include <linux/bitops.h> 32#include <linux/bitops.h>
33#include <linux/fs.h> 33#include <linux/fs.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/of_platform.h>
35 36
36#include <asm/irq.h> 37#include <asm/irq.h>
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
@@ -43,10 +44,6 @@
43#include <asm/cpm1.h> 44#include <asm/cpm1.h>
44#endif 45#endif
45 46
46#ifdef CONFIG_PPC_CPM_NEW_BINDING
47#include <linux/of_platform.h>
48#endif
49
50#include "fs_enet.h" 47#include "fs_enet.h"
51 48
52/*************************************************/ 49/*************************************************/
@@ -99,7 +96,6 @@ static inline int scc_cr_cmd(struct fs_enet_private *fep, u32 op)
99 96
100static int do_pd_setup(struct fs_enet_private *fep) 97static int do_pd_setup(struct fs_enet_private *fep)
101{ 98{
102#ifdef CONFIG_PPC_CPM_NEW_BINDING
103 struct of_device *ofdev = to_of_device(fep->dev); 99 struct of_device *ofdev = to_of_device(fep->dev);
104 100
105 fep->interrupt = of_irq_to_resource(ofdev->node, 0, NULL); 101 fep->interrupt = of_irq_to_resource(ofdev->node, 0, NULL);
@@ -115,27 +111,6 @@ static int do_pd_setup(struct fs_enet_private *fep)
115 iounmap(fep->scc.sccp); 111 iounmap(fep->scc.sccp);
116 return -EINVAL; 112 return -EINVAL;
117 } 113 }
118#else
119 struct platform_device *pdev = to_platform_device(fep->dev);
120 struct resource *r;
121
122 /* Fill out IRQ field */
123 fep->interrupt = platform_get_irq_byname(pdev, "interrupt");
124 if (fep->interrupt < 0)
125 return -EINVAL;
126
127 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
128 fep->scc.sccp = ioremap(r->start, r->end - r->start + 1);
129
130 if (fep->scc.sccp == NULL)
131 return -EINVAL;
132
133 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pram");
134 fep->scc.ep = ioremap(r->start, r->end - r->start + 1);
135
136 if (fep->scc.ep == NULL)
137 return -EINVAL;
138#endif
139 114
140 return 0; 115 return 0;
141} 116}
@@ -149,16 +124,6 @@ static int setup_data(struct net_device *dev)
149{ 124{
150 struct fs_enet_private *fep = netdev_priv(dev); 125 struct fs_enet_private *fep = netdev_priv(dev);
151 126
152#ifndef CONFIG_PPC_CPM_NEW_BINDING
153 struct fs_platform_info *fpi = fep->fpi;
154
155 fep->scc.idx = fs_get_scc_index(fpi->fs_no);
156 if ((unsigned int)fep->fcc.idx >= 4) /* max 4 SCCs */
157 return -EINVAL;
158
159 fpi->cp_command = fep->fcc.idx << 6;
160#endif
161
162 do_pd_setup(fep); 127 do_pd_setup(fep);
163 128
164 fep->scc.hthi = 0; 129 fep->scc.hthi = 0;
diff --git a/drivers/net/fs_enet/mii-bitbang.c b/drivers/net/fs_enet/mii-bitbang.c
index 1620030cd33c..be4b72f4f49a 100644
--- a/drivers/net/fs_enet/mii-bitbang.c
+++ b/drivers/net/fs_enet/mii-bitbang.c
@@ -22,10 +22,7 @@
22#include <linux/mii.h> 22#include <linux/mii.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/mdio-bitbang.h> 24#include <linux/mdio-bitbang.h>
25
26#ifdef CONFIG_PPC_CPM_NEW_BINDING
27#include <linux/of_platform.h> 25#include <linux/of_platform.h>
28#endif
29 26
30#include "fs_enet.h" 27#include "fs_enet.h"
31 28
@@ -110,7 +107,6 @@ static struct mdiobb_ops bb_ops = {
110 .get_mdio_data = mdio_read, 107 .get_mdio_data = mdio_read,
111}; 108};
112 109
113#ifdef CONFIG_PPC_CPM_NEW_BINDING
114static int __devinit fs_mii_bitbang_init(struct mii_bus *bus, 110static int __devinit fs_mii_bitbang_init(struct mii_bus *bus,
115 struct device_node *np) 111 struct device_node *np)
116{ 112{
@@ -271,106 +267,3 @@ static void fs_enet_mdio_bb_exit(void)
271 267
272module_init(fs_enet_mdio_bb_init); 268module_init(fs_enet_mdio_bb_init);
273module_exit(fs_enet_mdio_bb_exit); 269module_exit(fs_enet_mdio_bb_exit);
274#else
275static int __devinit fs_mii_bitbang_init(struct bb_info *bitbang,
276 struct fs_mii_bb_platform_info *fmpi)
277{
278 bitbang->dir = (u32 __iomem *)fmpi->mdio_dir.offset;
279 bitbang->dat = (u32 __iomem *)fmpi->mdio_dat.offset;
280 bitbang->mdio_msk = 1U << (31 - fmpi->mdio_dat.bit);
281 bitbang->mdc_msk = 1U << (31 - fmpi->mdc_dat.bit);
282
283 return 0;
284}
285
286static int __devinit fs_enet_mdio_probe(struct device *dev)
287{
288 struct platform_device *pdev = to_platform_device(dev);
289 struct fs_mii_bb_platform_info *pdata;
290 struct mii_bus *new_bus;
291 struct bb_info *bitbang;
292 int err = 0;
293
294 if (NULL == dev)
295 return -EINVAL;
296
297 bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
298
299 if (NULL == bitbang)
300 return -ENOMEM;
301
302 bitbang->ctrl.ops = &bb_ops;
303
304 new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
305
306 if (NULL == new_bus)
307 return -ENOMEM;
308
309 new_bus->name = "BB MII Bus",
310 snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id);
311
312 new_bus->phy_mask = ~0x9;
313 pdata = (struct fs_mii_bb_platform_info *)pdev->dev.platform_data;
314
315 if (NULL == pdata) {
316 printk(KERN_ERR "gfar mdio %d: Missing platform data!\n", pdev->id);
317 return -ENODEV;
318 }
319
320 /*set up workspace*/
321 fs_mii_bitbang_init(bitbang, pdata);
322
323 new_bus->priv = bitbang;
324
325 new_bus->irq = pdata->irq;
326
327 new_bus->dev = dev;
328 dev_set_drvdata(dev, new_bus);
329
330 err = mdiobus_register(new_bus);
331
332 if (0 != err) {
333 printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
334 new_bus->name);
335 goto bus_register_fail;
336 }
337
338 return 0;
339
340bus_register_fail:
341 free_mdio_bitbang(new_bus);
342 kfree(bitbang);
343
344 return err;
345}
346
347static int fs_enet_mdio_remove(struct device *dev)
348{
349 struct mii_bus *bus = dev_get_drvdata(dev);
350
351 mdiobus_unregister(bus);
352
353 dev_set_drvdata(dev, NULL);
354
355 free_mdio_bitbang(bus);
356
357 return 0;
358}
359
360static struct device_driver fs_enet_bb_mdio_driver = {
361 .name = "fsl-bb-mdio",
362 .bus = &platform_bus_type,
363 .probe = fs_enet_mdio_probe,
364 .remove = fs_enet_mdio_remove,
365};
366
367int fs_enet_mdio_bb_init(void)
368{
369 return driver_register(&fs_enet_bb_mdio_driver);
370}
371
372void fs_enet_mdio_bb_exit(void)
373{
374 driver_unregister(&fs_enet_bb_mdio_driver);
375}
376#endif
diff --git a/drivers/net/fs_enet/mii-fec.c b/drivers/net/fs_enet/mii-fec.c
index 8f6a43b0e0ff..695f74cc4398 100644
--- a/drivers/net/fs_enet/mii-fec.c
+++ b/drivers/net/fs_enet/mii-fec.c
@@ -31,15 +31,12 @@
31#include <linux/ethtool.h> 31#include <linux/ethtool.h>
32#include <linux/bitops.h> 32#include <linux/bitops.h>
33#include <linux/platform_device.h> 33#include <linux/platform_device.h>
34#include <linux/of_platform.h>
34 35
35#include <asm/pgtable.h> 36#include <asm/pgtable.h>
36#include <asm/irq.h> 37#include <asm/irq.h>
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
38 39
39#ifdef CONFIG_PPC_CPM_NEW_BINDING
40#include <linux/of_platform.h>
41#endif
42
43#include "fs_enet.h" 40#include "fs_enet.h"
44#include "fec.h" 41#include "fec.h"
45 42
@@ -51,52 +48,6 @@
51 48
52#define FEC_MII_LOOPS 10000 49#define FEC_MII_LOOPS 10000
53 50
54#ifndef CONFIG_PPC_CPM_NEW_BINDING
55static int match_has_phy (struct device *dev, void* data)
56{
57 struct platform_device* pdev = container_of(dev, struct platform_device, dev);
58 struct fs_platform_info* fpi;
59 if(strcmp(pdev->name, (char*)data))
60 {
61 return 0;
62 }
63
64 fpi = pdev->dev.platform_data;
65 if((fpi)&&(fpi->has_phy))
66 return 1;
67 return 0;
68}
69
70static int fs_mii_fec_init(struct fec_info* fec, struct fs_mii_fec_platform_info *fmpi)
71{
72 struct resource *r;
73 fec_t __iomem *fecp;
74 char* name = "fsl-cpm-fec";
75
76 /* we need fec in order to be useful */
77 struct platform_device *fec_pdev =
78 container_of(bus_find_device(&platform_bus_type, NULL, name, match_has_phy),
79 struct platform_device, dev);
80
81 if(fec_pdev == NULL) {
82 printk(KERN_ERR"Unable to find PHY for %s", name);
83 return -ENODEV;
84 }
85
86 r = platform_get_resource_byname(fec_pdev, IORESOURCE_MEM, "regs");
87
88 fec->fecp = fecp = ioremap(r->start,sizeof(fec_t));
89 fec->mii_speed = fmpi->mii_speed;
90
91 setbits32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
92 setbits32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
93 out_be32(&fecp->fec_ievent, FEC_ENET_MII);
94 out_be32(&fecp->fec_mii_speed, fec->mii_speed);
95
96 return 0;
97}
98#endif
99
100static int fs_enet_fec_mii_read(struct mii_bus *bus , int phy_id, int location) 51static int fs_enet_fec_mii_read(struct mii_bus *bus , int phy_id, int location)
101{ 52{
102 struct fec_info* fec = bus->priv; 53 struct fec_info* fec = bus->priv;
@@ -151,7 +102,6 @@ static int fs_enet_fec_mii_reset(struct mii_bus *bus)
151 return 0; 102 return 0;
152} 103}
153 104
154#ifdef CONFIG_PPC_CPM_NEW_BINDING
155static void __devinit add_phy(struct mii_bus *bus, struct device_node *np) 105static void __devinit add_phy(struct mii_bus *bus, struct device_node *np)
156{ 106{
157 const u32 *data; 107 const u32 *data;
@@ -286,95 +236,3 @@ static void fs_enet_mdio_fec_exit(void)
286 236
287module_init(fs_enet_mdio_fec_init); 237module_init(fs_enet_mdio_fec_init);
288module_exit(fs_enet_mdio_fec_exit); 238module_exit(fs_enet_mdio_fec_exit);
289#else
290static int __devinit fs_enet_fec_mdio_probe(struct device *dev)
291{
292 struct platform_device *pdev = to_platform_device(dev);
293 struct fs_mii_fec_platform_info *pdata;
294 struct mii_bus *new_bus;
295 struct fec_info *fec;
296 int err = 0;
297 if (NULL == dev)
298 return -EINVAL;
299 new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
300
301 if (NULL == new_bus)
302 return -ENOMEM;
303
304 fec = kzalloc(sizeof(struct fec_info), GFP_KERNEL);
305
306 if (NULL == fec)
307 return -ENOMEM;
308
309 new_bus->name = "FEC MII Bus",
310 new_bus->read = &fs_enet_fec_mii_read,
311 new_bus->write = &fs_enet_fec_mii_write,
312 new_bus->reset = &fs_enet_fec_mii_reset,
313 snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id);
314
315 pdata = (struct fs_mii_fec_platform_info *)pdev->dev.platform_data;
316
317 if (NULL == pdata) {
318 printk(KERN_ERR "fs_enet FEC mdio %d: Missing platform data!\n", pdev->id);
319 return -ENODEV;
320 }
321
322 /*set up workspace*/
323
324 fs_mii_fec_init(fec, pdata);
325 new_bus->priv = fec;
326
327 new_bus->irq = pdata->irq;
328
329 new_bus->dev = dev;
330 dev_set_drvdata(dev, new_bus);
331
332 err = mdiobus_register(new_bus);
333
334 if (0 != err) {
335 printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
336 new_bus->name);
337 goto bus_register_fail;
338 }
339
340 return 0;
341
342bus_register_fail:
343 kfree(new_bus);
344
345 return err;
346}
347
348
349static int fs_enet_fec_mdio_remove(struct device *dev)
350{
351 struct mii_bus *bus = dev_get_drvdata(dev);
352
353 mdiobus_unregister(bus);
354
355 dev_set_drvdata(dev, NULL);
356 kfree(bus->priv);
357
358 bus->priv = NULL;
359 kfree(bus);
360
361 return 0;
362}
363
364static struct device_driver fs_enet_fec_mdio_driver = {
365 .name = "fsl-cpm-fec-mdio",
366 .bus = &platform_bus_type,
367 .probe = fs_enet_fec_mdio_probe,
368 .remove = fs_enet_fec_mdio_remove,
369};
370
371int fs_enet_mdio_fec_init(void)
372{
373 return driver_register(&fs_enet_fec_mdio_driver);
374}
375
376void fs_enet_mdio_fec_exit(void)
377{
378 driver_unregister(&fs_enet_fec_mdio_driver);
379}
380#endif
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 45a63172852f..b8394cf134e8 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -134,6 +134,9 @@ static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int l
134static void gfar_vlan_rx_register(struct net_device *netdev, 134static void gfar_vlan_rx_register(struct net_device *netdev,
135 struct vlan_group *grp); 135 struct vlan_group *grp);
136void gfar_halt(struct net_device *dev); 136void gfar_halt(struct net_device *dev);
137#ifdef CONFIG_PM
138static void gfar_halt_nodisable(struct net_device *dev);
139#endif
137void gfar_start(struct net_device *dev); 140void gfar_start(struct net_device *dev);
138static void gfar_clear_exact_match(struct net_device *dev); 141static void gfar_clear_exact_match(struct net_device *dev);
139static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr); 142static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr);
@@ -207,6 +210,7 @@ static int gfar_probe(struct platform_device *pdev)
207 210
208 spin_lock_init(&priv->txlock); 211 spin_lock_init(&priv->txlock);
209 spin_lock_init(&priv->rxlock); 212 spin_lock_init(&priv->rxlock);
213 spin_lock_init(&priv->bflock);
210 214
211 platform_set_drvdata(pdev, dev); 215 platform_set_drvdata(pdev, dev);
212 216
@@ -378,6 +382,103 @@ static int gfar_remove(struct platform_device *pdev)
378 return 0; 382 return 0;
379} 383}
380 384
385#ifdef CONFIG_PM
386static int gfar_suspend(struct platform_device *pdev, pm_message_t state)
387{
388 struct net_device *dev = platform_get_drvdata(pdev);
389 struct gfar_private *priv = netdev_priv(dev);
390 unsigned long flags;
391 u32 tempval;
392
393 int magic_packet = priv->wol_en &&
394 (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
395
396 netif_device_detach(dev);
397
398 if (netif_running(dev)) {
399 spin_lock_irqsave(&priv->txlock, flags);
400 spin_lock(&priv->rxlock);
401
402 gfar_halt_nodisable(dev);
403
404 /* Disable Tx, and Rx if wake-on-LAN is disabled. */
405 tempval = gfar_read(&priv->regs->maccfg1);
406
407 tempval &= ~MACCFG1_TX_EN;
408
409 if (!magic_packet)
410 tempval &= ~MACCFG1_RX_EN;
411
412 gfar_write(&priv->regs->maccfg1, tempval);
413
414 spin_unlock(&priv->rxlock);
415 spin_unlock_irqrestore(&priv->txlock, flags);
416
417#ifdef CONFIG_GFAR_NAPI
418 napi_disable(&priv->napi);
419#endif
420
421 if (magic_packet) {
422 /* Enable interrupt on Magic Packet */
423 gfar_write(&priv->regs->imask, IMASK_MAG);
424
425 /* Enable Magic Packet mode */
426 tempval = gfar_read(&priv->regs->maccfg2);
427 tempval |= MACCFG2_MPEN;
428 gfar_write(&priv->regs->maccfg2, tempval);
429 } else {
430 phy_stop(priv->phydev);
431 }
432 }
433
434 return 0;
435}
436
437static int gfar_resume(struct platform_device *pdev)
438{
439 struct net_device *dev = platform_get_drvdata(pdev);
440 struct gfar_private *priv = netdev_priv(dev);
441 unsigned long flags;
442 u32 tempval;
443 int magic_packet = priv->wol_en &&
444 (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
445
446 if (!netif_running(dev)) {
447 netif_device_attach(dev);
448 return 0;
449 }
450
451 if (!magic_packet && priv->phydev)
452 phy_start(priv->phydev);
453
454 /* Disable Magic Packet mode, in case something
455 * else woke us up.
456 */
457
458 spin_lock_irqsave(&priv->txlock, flags);
459 spin_lock(&priv->rxlock);
460
461 tempval = gfar_read(&priv->regs->maccfg2);
462 tempval &= ~MACCFG2_MPEN;
463 gfar_write(&priv->regs->maccfg2, tempval);
464
465 gfar_start(dev);
466
467 spin_unlock(&priv->rxlock);
468 spin_unlock_irqrestore(&priv->txlock, flags);
469
470 netif_device_attach(dev);
471
472#ifdef CONFIG_GFAR_NAPI
473 napi_enable(&priv->napi);
474#endif
475
476 return 0;
477}
478#else
479#define gfar_suspend NULL
480#define gfar_resume NULL
481#endif
381 482
382/* Reads the controller's registers to determine what interface 483/* Reads the controller's registers to determine what interface
383 * connects it to the PHY. 484 * connects it to the PHY.
@@ -534,8 +635,9 @@ static void init_registers(struct net_device *dev)
534} 635}
535 636
536 637
638#ifdef CONFIG_PM
537/* Halt the receive and transmit queues */ 639/* Halt the receive and transmit queues */
538void gfar_halt(struct net_device *dev) 640static void gfar_halt_nodisable(struct net_device *dev)
539{ 641{
540 struct gfar_private *priv = netdev_priv(dev); 642 struct gfar_private *priv = netdev_priv(dev);
541 struct gfar __iomem *regs = priv->regs; 643 struct gfar __iomem *regs = priv->regs;
@@ -558,6 +660,15 @@ void gfar_halt(struct net_device *dev)
558 (IEVENT_GRSC | IEVENT_GTSC))) 660 (IEVENT_GRSC | IEVENT_GTSC)))
559 cpu_relax(); 661 cpu_relax();
560 } 662 }
663}
664#endif
665
666/* Halt the receive and transmit queues */
667void gfar_halt(struct net_device *dev)
668{
669 struct gfar_private *priv = netdev_priv(dev);
670 struct gfar __iomem *regs = priv->regs;
671 u32 tempval;
561 672
562 /* Disable Rx and Tx */ 673 /* Disable Rx and Tx */
563 tempval = gfar_read(&regs->maccfg1); 674 tempval = gfar_read(&regs->maccfg1);
@@ -1725,7 +1836,6 @@ static void adjust_link(struct net_device *dev)
1725 if (!priv->oldlink) { 1836 if (!priv->oldlink) {
1726 new_state = 1; 1837 new_state = 1;
1727 priv->oldlink = 1; 1838 priv->oldlink = 1;
1728 netif_tx_schedule_all(dev);
1729 } 1839 }
1730 } else if (priv->oldlink) { 1840 } else if (priv->oldlink) {
1731 new_state = 1; 1841 new_state = 1;
@@ -1910,7 +2020,12 @@ static irqreturn_t gfar_error(int irq, void *dev_id)
1910 u32 events = gfar_read(&priv->regs->ievent); 2020 u32 events = gfar_read(&priv->regs->ievent);
1911 2021
1912 /* Clear IEVENT */ 2022 /* Clear IEVENT */
1913 gfar_write(&priv->regs->ievent, IEVENT_ERR_MASK); 2023 gfar_write(&priv->regs->ievent, events & IEVENT_ERR_MASK);
2024
2025 /* Magic Packet is not an error. */
2026 if ((priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
2027 (events & IEVENT_MAG))
2028 events &= ~IEVENT_MAG;
1914 2029
1915 /* Hmm... */ 2030 /* Hmm... */
1916 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv)) 2031 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
@@ -1978,6 +2093,8 @@ MODULE_ALIAS("platform:fsl-gianfar");
1978static struct platform_driver gfar_driver = { 2093static struct platform_driver gfar_driver = {
1979 .probe = gfar_probe, 2094 .probe = gfar_probe,
1980 .remove = gfar_remove, 2095 .remove = gfar_remove,
2096 .suspend = gfar_suspend,
2097 .resume = gfar_resume,
1981 .driver = { 2098 .driver = {
1982 .name = "fsl-gianfar", 2099 .name = "fsl-gianfar",
1983 .owner = THIS_MODULE, 2100 .owner = THIS_MODULE,
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h
index bead71cb2b16..d59df98bd636 100644
--- a/drivers/net/gianfar.h
+++ b/drivers/net/gianfar.h
@@ -157,6 +157,7 @@ extern const char gfar_driver_version[];
157#define MACCFG2_GMII 0x00000200 157#define MACCFG2_GMII 0x00000200
158#define MACCFG2_HUGEFRAME 0x00000020 158#define MACCFG2_HUGEFRAME 0x00000020
159#define MACCFG2_LENGTHCHECK 0x00000010 159#define MACCFG2_LENGTHCHECK 0x00000010
160#define MACCFG2_MPEN 0x00000008
160 161
161#define ECNTRL_INIT_SETTINGS 0x00001000 162#define ECNTRL_INIT_SETTINGS 0x00001000
162#define ECNTRL_TBI_MODE 0x00000020 163#define ECNTRL_TBI_MODE 0x00000020
@@ -229,6 +230,7 @@ extern const char gfar_driver_version[];
229#define IEVENT_CRL 0x00020000 230#define IEVENT_CRL 0x00020000
230#define IEVENT_XFUN 0x00010000 231#define IEVENT_XFUN 0x00010000
231#define IEVENT_RXB0 0x00008000 232#define IEVENT_RXB0 0x00008000
233#define IEVENT_MAG 0x00000800
232#define IEVENT_GRSC 0x00000100 234#define IEVENT_GRSC 0x00000100
233#define IEVENT_RXF0 0x00000080 235#define IEVENT_RXF0 0x00000080
234#define IEVENT_FIR 0x00000008 236#define IEVENT_FIR 0x00000008
@@ -241,7 +243,8 @@ extern const char gfar_driver_version[];
241#define IEVENT_ERR_MASK \ 243#define IEVENT_ERR_MASK \
242(IEVENT_RXC | IEVENT_BSY | IEVENT_EBERR | IEVENT_MSRO | \ 244(IEVENT_RXC | IEVENT_BSY | IEVENT_EBERR | IEVENT_MSRO | \
243 IEVENT_BABT | IEVENT_TXC | IEVENT_TXE | IEVENT_LC \ 245 IEVENT_BABT | IEVENT_TXC | IEVENT_TXE | IEVENT_LC \
244 | IEVENT_CRL | IEVENT_XFUN | IEVENT_DPE | IEVENT_PERR) 246 | IEVENT_CRL | IEVENT_XFUN | IEVENT_DPE | IEVENT_PERR \
247 | IEVENT_MAG)
245 248
246#define IMASK_INIT_CLEAR 0x00000000 249#define IMASK_INIT_CLEAR 0x00000000
247#define IMASK_BABR 0x80000000 250#define IMASK_BABR 0x80000000
@@ -259,6 +262,7 @@ extern const char gfar_driver_version[];
259#define IMASK_CRL 0x00020000 262#define IMASK_CRL 0x00020000
260#define IMASK_XFUN 0x00010000 263#define IMASK_XFUN 0x00010000
261#define IMASK_RXB0 0x00008000 264#define IMASK_RXB0 0x00008000
265#define IMASK_MAG 0x00000800
262#define IMASK_GTSC 0x00000100 266#define IMASK_GTSC 0x00000100
263#define IMASK_RXFEN0 0x00000080 267#define IMASK_RXFEN0 0x00000080
264#define IMASK_FIR 0x00000008 268#define IMASK_FIR 0x00000008
@@ -726,10 +730,14 @@ struct gfar_private {
726 unsigned int fifo_starve; 730 unsigned int fifo_starve;
727 unsigned int fifo_starve_off; 731 unsigned int fifo_starve_off;
728 732
733 /* Bitfield update lock */
734 spinlock_t bflock;
735
729 unsigned char vlan_enable:1, 736 unsigned char vlan_enable:1,
730 rx_csum_enable:1, 737 rx_csum_enable:1,
731 extended_hash:1, 738 extended_hash:1,
732 bd_stash_en:1; 739 bd_stash_en:1,
740 wol_en:1; /* Wake-on-LAN enabled */
733 unsigned short padding; 741 unsigned short padding;
734 742
735 unsigned int interruptTransmit; 743 unsigned int interruptTransmit;
diff --git a/drivers/net/gianfar_ethtool.c b/drivers/net/gianfar_ethtool.c
index 6007147cc1e9..fb7d3ccc0fdc 100644
--- a/drivers/net/gianfar_ethtool.c
+++ b/drivers/net/gianfar_ethtool.c
@@ -479,14 +479,13 @@ static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rva
479static int gfar_set_rx_csum(struct net_device *dev, uint32_t data) 479static int gfar_set_rx_csum(struct net_device *dev, uint32_t data)
480{ 480{
481 struct gfar_private *priv = netdev_priv(dev); 481 struct gfar_private *priv = netdev_priv(dev);
482 unsigned long flags;
482 int err = 0; 483 int err = 0;
483 484
484 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) 485 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
485 return -EOPNOTSUPP; 486 return -EOPNOTSUPP;
486 487
487 if (dev->flags & IFF_UP) { 488 if (dev->flags & IFF_UP) {
488 unsigned long flags;
489
490 /* Halt TX and RX, and process the frames which 489 /* Halt TX and RX, and process the frames which
491 * have already been received */ 490 * have already been received */
492 spin_lock_irqsave(&priv->txlock, flags); 491 spin_lock_irqsave(&priv->txlock, flags);
@@ -502,7 +501,9 @@ static int gfar_set_rx_csum(struct net_device *dev, uint32_t data)
502 stop_gfar(dev); 501 stop_gfar(dev);
503 } 502 }
504 503
504 spin_lock_irqsave(&priv->bflock, flags);
505 priv->rx_csum_enable = data; 505 priv->rx_csum_enable = data;
506 spin_unlock_irqrestore(&priv->bflock, flags);
506 507
507 if (dev->flags & IFF_UP) 508 if (dev->flags & IFF_UP)
508 err = startup_gfar(dev); 509 err = startup_gfar(dev);
@@ -564,6 +565,38 @@ static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
564 priv->msg_enable = data; 565 priv->msg_enable = data;
565} 566}
566 567
568#ifdef CONFIG_PM
569static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
570{
571 struct gfar_private *priv = netdev_priv(dev);
572
573 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) {
574 wol->supported = WAKE_MAGIC;
575 wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0;
576 } else {
577 wol->supported = wol->wolopts = 0;
578 }
579}
580
581static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
582{
583 struct gfar_private *priv = netdev_priv(dev);
584 unsigned long flags;
585
586 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
587 wol->wolopts != 0)
588 return -EINVAL;
589
590 if (wol->wolopts & ~WAKE_MAGIC)
591 return -EINVAL;
592
593 spin_lock_irqsave(&priv->bflock, flags);
594 priv->wol_en = wol->wolopts & WAKE_MAGIC ? 1 : 0;
595 spin_unlock_irqrestore(&priv->bflock, flags);
596
597 return 0;
598}
599#endif
567 600
568const struct ethtool_ops gfar_ethtool_ops = { 601const struct ethtool_ops gfar_ethtool_ops = {
569 .get_settings = gfar_gsettings, 602 .get_settings = gfar_gsettings,
@@ -585,4 +618,8 @@ const struct ethtool_ops gfar_ethtool_ops = {
585 .set_tx_csum = gfar_set_tx_csum, 618 .set_tx_csum = gfar_set_tx_csum,
586 .get_msglevel = gfar_get_msglevel, 619 .get_msglevel = gfar_get_msglevel,
587 .set_msglevel = gfar_set_msglevel, 620 .set_msglevel = gfar_set_msglevel,
621#ifdef CONFIG_PM
622 .get_wol = gfar_get_wol,
623 .set_wol = gfar_set_wol,
624#endif
588}; 625};
diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
index ae9629fa6882..c258a0586e61 100644
--- a/drivers/net/hamradio/hdlcdrv.c
+++ b/drivers/net/hamradio/hdlcdrv.c
@@ -88,6 +88,7 @@
88static inline void append_crc_ccitt(unsigned char *buffer, int len) 88static inline void append_crc_ccitt(unsigned char *buffer, int len)
89{ 89{
90 unsigned int crc = crc_ccitt(0xffff, buffer, len) ^ 0xffff; 90 unsigned int crc = crc_ccitt(0xffff, buffer, len) ^ 0xffff;
91 buffer += len;
91 *buffer++ = crc; 92 *buffer++ = crc;
92 *buffer++ = crc >> 8; 93 *buffer++ = crc >> 8;
93} 94}
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 6b1d7a8edf15..739b3ab7bccc 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -866,7 +866,8 @@ static int __init ppp_init(void)
866 err = PTR_ERR(ppp_class); 866 err = PTR_ERR(ppp_class);
867 goto out_chrdev; 867 goto out_chrdev;
868 } 868 }
869 device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), "ppp"); 869 device_create_drvdata(ppp_class, NULL, MKDEV(PPP_MAJOR, 0),
870 NULL, "ppp");
870 } 871 }
871 872
872out: 873out:
diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c
index 1aa425be3067..b79d5f018f79 100644
--- a/drivers/net/sunhme.c
+++ b/drivers/net/sunhme.c
@@ -2377,8 +2377,6 @@ static void happy_meal_set_multicast(struct net_device *dev)
2377 2377
2378 spin_lock_irq(&hp->happy_lock); 2378 spin_lock_irq(&hp->happy_lock);
2379 2379
2380 netif_stop_queue(dev);
2381
2382 if ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > 64)) { 2380 if ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > 64)) {
2383 hme_write32(hp, bregs + BMAC_HTABLE0, 0xffff); 2381 hme_write32(hp, bregs + BMAC_HTABLE0, 0xffff);
2384 hme_write32(hp, bregs + BMAC_HTABLE1, 0xffff); 2382 hme_write32(hp, bregs + BMAC_HTABLE1, 0xffff);
@@ -2410,8 +2408,6 @@ static void happy_meal_set_multicast(struct net_device *dev)
2410 hme_write32(hp, bregs + BMAC_HTABLE3, hash_table[3]); 2408 hme_write32(hp, bregs + BMAC_HTABLE3, hash_table[3]);
2411 } 2409 }
2412 2410
2413 netif_wake_queue(dev);
2414
2415 spin_unlock_irq(&hp->happy_lock); 2411 spin_unlock_irq(&hp->happy_lock);
2416} 2412}
2417 2413
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 756ba10b79d6..8f944e57fd55 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -1588,7 +1588,6 @@ static void adjust_link(struct net_device *dev)
1588 if (!ugeth->oldlink) { 1588 if (!ugeth->oldlink) {
1589 new_state = 1; 1589 new_state = 1;
1590 ugeth->oldlink = 1; 1590 ugeth->oldlink = 1;
1591 netif_tx_schedule_all(dev);
1592 } 1591 }
1593 } else if (ugeth->oldlink) { 1592 } else if (ugeth->oldlink) {
1594 new_state = 1; 1593 new_state = 1;
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index 5827324e9d9f..f7d3349dc3ec 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -397,9 +397,9 @@ static int __init cosa_init(void)
397 err = PTR_ERR(cosa_class); 397 err = PTR_ERR(cosa_class);
398 goto out_chrdev; 398 goto out_chrdev;
399 } 399 }
400 for (i=0; i<nr_cards; i++) { 400 for (i = 0; i < nr_cards; i++)
401 device_create(cosa_class, NULL, MKDEV(cosa_major, i), "cosa%d", i); 401 device_create_drvdata(cosa_class, NULL, MKDEV(cosa_major, i),
402 } 402 NULL, "cosa%d", i);
403 err = 0; 403 err = 0;
404 goto out; 404 goto out;
405 405
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index eecf7cbf4139..5a58b075dd8d 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -36,7 +36,7 @@
36#define _ACPIPHP_H 36#define _ACPIPHP_H
37 37
38#include <linux/acpi.h> 38#include <linux/acpi.h>
39#include <linux/kobject.h> /* for KOBJ_NAME_LEN */ 39#include <linux/kobject.h>
40#include <linux/mutex.h> 40#include <linux/mutex.h>
41#include <linux/pci_hotplug.h> 41#include <linux/pci_hotplug.h>
42 42
@@ -51,7 +51,7 @@
51#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 51#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
52 52
53/* name size which is used for entries in pcihpfs */ 53/* name size which is used for entries in pcihpfs */
54#define SLOT_NAME_SIZE KOBJ_NAME_LEN /* {_SUN} */ 54#define SLOT_NAME_SIZE 20 /* {_SUN} */
55 55
56struct acpiphp_bridge; 56struct acpiphp_bridge;
57struct acpiphp_slot; 57struct acpiphp_slot;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 44a46c92b721..d00f0e0d8453 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1123,8 +1123,7 @@ int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
1123} 1123}
1124 1124
1125/** 1125/**
1126 * pci_prepare_to_sleep - prepare PCI device for system-wide transition into 1126 * pci_prepare_to_sleep - prepare PCI device for system-wide transition into a sleep state
1127 * a sleep state
1128 * @dev: Device to handle. 1127 * @dev: Device to handle.
1129 * 1128 *
1130 * Choose the power state appropriate for the device depending on whether 1129 * Choose the power state appropriate for the device depending on whether
@@ -1181,8 +1180,7 @@ int pci_prepare_to_sleep(struct pci_dev *dev)
1181} 1180}
1182 1181
1183/** 1182/**
1184 * pci_back_from_sleep - turn PCI device on during system-wide transition into 1183 * pci_back_from_sleep - turn PCI device on during system-wide transition into working state
1185 * the working state a sleep state
1186 * @dev: Device to handle. 1184 * @dev: Device to handle.
1187 * 1185 *
1188 * Disable device's sytem wake-up capability and put it into D0. 1186 * Disable device's sytem wake-up capability and put it into D0.
diff --git a/drivers/power/apm_power.c b/drivers/power/apm_power.c
index a4892275659d..936bae560fa1 100644
--- a/drivers/power/apm_power.c
+++ b/drivers/power/apm_power.c
@@ -78,7 +78,7 @@ static void find_main_battery(void)
78 main_battery = NULL; 78 main_battery = NULL;
79 bp.main = main_battery; 79 bp.main = main_battery;
80 80
81 error = class_for_each_device(power_supply_class, &bp, 81 error = class_for_each_device(power_supply_class, NULL, &bp,
82 __find_main_battery); 82 __find_main_battery);
83 if (error) { 83 if (error) {
84 main_battery = bp.main; 84 main_battery = bp.main;
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index af1633eb3b70..cb1ccb472921 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -41,7 +41,7 @@ static void power_supply_changed_work(struct work_struct *work)
41 41
42 dev_dbg(psy->dev, "%s\n", __func__); 42 dev_dbg(psy->dev, "%s\n", __func__);
43 43
44 class_for_each_device(power_supply_class, psy, 44 class_for_each_device(power_supply_class, NULL, psy,
45 __power_supply_changed_work); 45 __power_supply_changed_work);
46 46
47 power_supply_update_leds(psy); 47 power_supply_update_leds(psy);
@@ -79,7 +79,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)
79{ 79{
80 int error; 80 int error;
81 81
82 error = class_for_each_device(power_supply_class, psy, 82 error = class_for_each_device(power_supply_class, NULL, psy,
83 __power_supply_am_i_supplied); 83 __power_supply_am_i_supplied);
84 84
85 dev_dbg(psy->dev, "%s %d\n", __func__, error); 85 dev_dbg(psy->dev, "%s %d\n", __func__, error);
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 58b7336640ff..d397fa5f3a91 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -345,7 +345,7 @@ struct rtc_device *rtc_class_open(char *name)
345 struct device *dev; 345 struct device *dev;
346 struct rtc_device *rtc = NULL; 346 struct rtc_device *rtc = NULL;
347 347
348 dev = class_find_device(rtc_class, name, __rtc_match); 348 dev = class_find_device(rtc_class, NULL, name, __rtc_match);
349 if (dev) 349 if (dev)
350 rtc = to_rtc_device(dev); 350 rtc = to_rtc_device(dev);
351 351
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index 81a96e019080..c3dee900a5c8 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -1168,17 +1168,19 @@ static int raw3270_create_attributes(struct raw3270 *rp)
1168 if (rc) 1168 if (rc)
1169 goto out; 1169 goto out;
1170 1170
1171 rp->clttydev = device_create(class3270, &rp->cdev->dev, 1171 rp->clttydev = device_create_drvdata(class3270, &rp->cdev->dev,
1172 MKDEV(IBM_TTY3270_MAJOR, rp->minor), 1172 MKDEV(IBM_TTY3270_MAJOR, rp->minor),
1173 "tty%s", rp->cdev->dev.bus_id); 1173 NULL,
1174 "tty%s", rp->cdev->dev.bus_id);
1174 if (IS_ERR(rp->clttydev)) { 1175 if (IS_ERR(rp->clttydev)) {
1175 rc = PTR_ERR(rp->clttydev); 1176 rc = PTR_ERR(rp->clttydev);
1176 goto out_ttydev; 1177 goto out_ttydev;
1177 } 1178 }
1178 1179
1179 rp->cltubdev = device_create(class3270, &rp->cdev->dev, 1180 rp->cltubdev = device_create_drvdata(class3270, &rp->cdev->dev,
1180 MKDEV(IBM_FS3270_MAJOR, rp->minor), 1181 MKDEV(IBM_FS3270_MAJOR, rp->minor),
1181 "tub%s", rp->cdev->dev.bus_id); 1182 NULL,
1183 "tub%s", rp->cdev->dev.bus_id);
1182 if (!IS_ERR(rp->cltubdev)) 1184 if (!IS_ERR(rp->cltubdev))
1183 goto out; 1185 goto out;
1184 1186
diff --git a/drivers/s390/char/tape_class.c b/drivers/s390/char/tape_class.c
index 6dfdb7c17981..12c2a5aaf31b 100644
--- a/drivers/s390/char/tape_class.c
+++ b/drivers/s390/char/tape_class.c
@@ -69,10 +69,9 @@ struct tape_class_device *register_tape_dev(
69 if (rc) 69 if (rc)
70 goto fail_with_cdev; 70 goto fail_with_cdev;
71 71
72 tcd->class_device = device_create(tape_class, device, 72 tcd->class_device = device_create_drvdata(tape_class, device,
73 tcd->char_device->dev, 73 tcd->char_device->dev,
74 "%s", tcd->device_name 74 NULL, "%s", tcd->device_name);
75 );
76 rc = IS_ERR(tcd->class_device) ? PTR_ERR(tcd->class_device) : 0; 75 rc = IS_ERR(tcd->class_device) ? PTR_ERR(tcd->class_device) : 0;
77 if (rc) 76 if (rc)
78 goto fail_with_cdev; 77 goto fail_with_cdev;
diff --git a/drivers/s390/char/vmur.c b/drivers/s390/char/vmur.c
index b0ac44b27127..c1f352b84868 100644
--- a/drivers/s390/char/vmur.c
+++ b/drivers/s390/char/vmur.c
@@ -896,8 +896,9 @@ static int ur_set_online(struct ccw_device *cdev)
896 goto fail_free_cdev; 896 goto fail_free_cdev;
897 } 897 }
898 898
899 urd->device = device_create(vmur_class, NULL, urd->char_device->dev, 899 urd->device = device_create_drvdata(vmur_class, NULL,
900 "%s", node_id); 900 urd->char_device->dev, NULL,
901 "%s", node_id);
901 if (IS_ERR(urd->device)) { 902 if (IS_ERR(urd->device)) {
902 rc = PTR_ERR(urd->device); 903 rc = PTR_ERR(urd->device);
903 TRACE("ur_set_online: device_create rc=%d\n", rc); 904 TRACE("ur_set_online: device_create rc=%d\n", rc);
diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
index 513ba61ae966..777637594acd 100644
--- a/drivers/sbus/char/uctrl.c
+++ b/drivers/sbus/char/uctrl.c
@@ -195,8 +195,8 @@ struct uctrl_driver {
195 195
196static struct uctrl_driver drv; 196static struct uctrl_driver drv;
197 197
198void uctrl_get_event_status(void); 198static void uctrl_get_event_status(void);
199void uctrl_get_external_status(void); 199static void uctrl_get_external_status(void);
200 200
201static int 201static int
202uctrl_ioctl(struct inode *inode, struct file *file, 202uctrl_ioctl(struct inode *inode, struct file *file,
@@ -266,12 +266,6 @@ static struct miscdevice uctrl_dev = {
266 driver->regs->uctrl_stat = UCTRL_STAT_RXNE_STA; \ 266 driver->regs->uctrl_stat = UCTRL_STAT_RXNE_STA; \
267} 267}
268 268
269void uctrl_set_video(int status)
270{
271 struct uctrl_driver *driver = &drv;
272
273}
274
275static void uctrl_do_txn(struct uctrl_txn *txn) 269static void uctrl_do_txn(struct uctrl_txn *txn)
276{ 270{
277 struct uctrl_driver *driver = &drv; 271 struct uctrl_driver *driver = &drv;
@@ -311,7 +305,7 @@ static void uctrl_do_txn(struct uctrl_txn *txn)
311 } 305 }
312} 306}
313 307
314void uctrl_get_event_status(void) 308static void uctrl_get_event_status(void)
315{ 309{
316 struct uctrl_driver *driver = &drv; 310 struct uctrl_driver *driver = &drv;
317 struct uctrl_txn txn; 311 struct uctrl_txn txn;
@@ -331,7 +325,7 @@ void uctrl_get_event_status(void)
331 dprintk(("ev is %x\n", driver->status.event_status)); 325 dprintk(("ev is %x\n", driver->status.event_status));
332} 326}
333 327
334void uctrl_get_external_status(void) 328static void uctrl_get_external_status(void)
335{ 329{
336 struct uctrl_driver *driver = &drv; 330 struct uctrl_driver *driver = &drv;
337 struct uctrl_txn txn; 331 struct uctrl_txn txn;
@@ -363,7 +357,7 @@ void uctrl_get_external_status(void)
363static int __init ts102_uctrl_init(void) 357static int __init ts102_uctrl_init(void)
364{ 358{
365 struct uctrl_driver *driver = &drv; 359 struct uctrl_driver *driver = &drv;
366 int len, i; 360 int len;
367 struct linux_prom_irqs tmp_irq[2]; 361 struct linux_prom_irqs tmp_irq[2];
368 unsigned int vaddr[2] = { 0, 0 }; 362 unsigned int vaddr[2] = { 0, 0 };
369 int tmpnode, uctrlnode = prom_getchild(prom_root_node); 363 int tmpnode, uctrlnode = prom_getchild(prom_root_node);
diff --git a/drivers/sbus/char/vfc.h b/drivers/sbus/char/vfc.h
index f1aa1389ea4a..a5240c52aa0b 100644
--- a/drivers/sbus/char/vfc.h
+++ b/drivers/sbus/char/vfc.h
@@ -133,8 +133,6 @@ struct vfc_dev {
133 unsigned char saa9051_state_array[VFC_SAA9051_NR]; 133 unsigned char saa9051_state_array[VFC_SAA9051_NR];
134}; 134};
135 135
136extern struct vfc_dev **vfc_dev_lst;
137
138void captstat_reset(struct vfc_dev *); 136void captstat_reset(struct vfc_dev *);
139void memptr_reset(struct vfc_dev *); 137void memptr_reset(struct vfc_dev *);
140 138
@@ -145,8 +143,6 @@ int vfc_i2c_sendbuf(struct vfc_dev *, unsigned char, char *, int) ;
145int vfc_i2c_recvbuf(struct vfc_dev *, unsigned char, char *, int) ; 143int vfc_i2c_recvbuf(struct vfc_dev *, unsigned char, char *, int) ;
146int vfc_i2c_reset_bus(struct vfc_dev *); 144int vfc_i2c_reset_bus(struct vfc_dev *);
147int vfc_init_i2c_bus(struct vfc_dev *); 145int vfc_init_i2c_bus(struct vfc_dev *);
148void vfc_lock_device(struct vfc_dev *);
149void vfc_unlock_device(struct vfc_dev *);
150 146
151#define VFC_CONTROL_DIAGMODE 0x10000000 147#define VFC_CONTROL_DIAGMODE 0x10000000
152#define VFC_CONTROL_MEMPTR 0x20000000 148#define VFC_CONTROL_MEMPTR 0x20000000
diff --git a/drivers/sbus/char/vfc_dev.c b/drivers/sbus/char/vfc_dev.c
index 1f6cb8ae2784..25181bb7d627 100644
--- a/drivers/sbus/char/vfc_dev.c
+++ b/drivers/sbus/char/vfc_dev.c
@@ -45,7 +45,7 @@
45#include <asm/vfc_ioctls.h> 45#include <asm/vfc_ioctls.h>
46 46
47static const struct file_operations vfc_fops; 47static const struct file_operations vfc_fops;
48struct vfc_dev **vfc_dev_lst; 48static struct vfc_dev **vfc_dev_lst;
49static char vfcstr[]="vfc"; 49static char vfcstr[]="vfc";
50static unsigned char saa9051_init_array[VFC_SAA9051_NR] = { 50static unsigned char saa9051_init_array[VFC_SAA9051_NR] = {
51 0x00, 0x64, 0x72, 0x52, 51 0x00, 0x64, 0x72, 0x52,
@@ -54,18 +54,18 @@ static unsigned char saa9051_init_array[VFC_SAA9051_NR] = {
54 0x3e 54 0x3e
55}; 55};
56 56
57void vfc_lock_device(struct vfc_dev *dev) 57static void vfc_lock_device(struct vfc_dev *dev)
58{ 58{
59 mutex_lock(&dev->device_lock_mtx); 59 mutex_lock(&dev->device_lock_mtx);
60} 60}
61 61
62void vfc_unlock_device(struct vfc_dev *dev) 62static void vfc_unlock_device(struct vfc_dev *dev)
63{ 63{
64 mutex_unlock(&dev->device_lock_mtx); 64 mutex_unlock(&dev->device_lock_mtx);
65} 65}
66 66
67 67
68void vfc_captstat_reset(struct vfc_dev *dev) 68static void vfc_captstat_reset(struct vfc_dev *dev)
69{ 69{
70 dev->control_reg |= VFC_CONTROL_CAPTRESET; 70 dev->control_reg |= VFC_CONTROL_CAPTRESET;
71 sbus_writel(dev->control_reg, &dev->regs->control); 71 sbus_writel(dev->control_reg, &dev->regs->control);
@@ -75,7 +75,7 @@ void vfc_captstat_reset(struct vfc_dev *dev)
75 sbus_writel(dev->control_reg, &dev->regs->control); 75 sbus_writel(dev->control_reg, &dev->regs->control);
76} 76}
77 77
78void vfc_memptr_reset(struct vfc_dev *dev) 78static void vfc_memptr_reset(struct vfc_dev *dev)
79{ 79{
80 dev->control_reg |= VFC_CONTROL_MEMPTR; 80 dev->control_reg |= VFC_CONTROL_MEMPTR;
81 sbus_writel(dev->control_reg, &dev->regs->control); 81 sbus_writel(dev->control_reg, &dev->regs->control);
@@ -85,7 +85,7 @@ void vfc_memptr_reset(struct vfc_dev *dev)
85 sbus_writel(dev->control_reg, &dev->regs->control); 85 sbus_writel(dev->control_reg, &dev->regs->control);
86} 86}
87 87
88int vfc_csr_init(struct vfc_dev *dev) 88static int vfc_csr_init(struct vfc_dev *dev)
89{ 89{
90 dev->control_reg = 0x80000000; 90 dev->control_reg = 0x80000000;
91 sbus_writel(dev->control_reg, &dev->regs->control); 91 sbus_writel(dev->control_reg, &dev->regs->control);
@@ -107,7 +107,7 @@ int vfc_csr_init(struct vfc_dev *dev)
107 return 0; 107 return 0;
108} 108}
109 109
110int vfc_saa9051_init(struct vfc_dev *dev) 110static int vfc_saa9051_init(struct vfc_dev *dev)
111{ 111{
112 int i; 112 int i;
113 113
@@ -119,7 +119,7 @@ int vfc_saa9051_init(struct vfc_dev *dev)
119 return 0; 119 return 0;
120} 120}
121 121
122int init_vfc_hw(struct vfc_dev *dev) 122static int init_vfc_hw(struct vfc_dev *dev)
123{ 123{
124 vfc_lock_device(dev); 124 vfc_lock_device(dev);
125 vfc_csr_init(dev); 125 vfc_csr_init(dev);
@@ -132,7 +132,7 @@ int init_vfc_hw(struct vfc_dev *dev)
132 return 0; 132 return 0;
133} 133}
134 134
135int init_vfc_devstruct(struct vfc_dev *dev, int instance) 135static int init_vfc_devstruct(struct vfc_dev *dev, int instance)
136{ 136{
137 dev->instance=instance; 137 dev->instance=instance;
138 mutex_init(&dev->device_lock_mtx); 138 mutex_init(&dev->device_lock_mtx);
@@ -141,7 +141,8 @@ int init_vfc_devstruct(struct vfc_dev *dev, int instance)
141 return 0; 141 return 0;
142} 142}
143 143
144int init_vfc_device(struct sbus_dev *sdev,struct vfc_dev *dev, int instance) 144static int init_vfc_device(struct sbus_dev *sdev,struct vfc_dev *dev,
145 int instance)
145{ 146{
146 if(dev == NULL) { 147 if(dev == NULL) {
147 printk(KERN_ERR "VFC: Bogus pointer passed\n"); 148 printk(KERN_ERR "VFC: Bogus pointer passed\n");
@@ -168,7 +169,7 @@ int init_vfc_device(struct sbus_dev *sdev,struct vfc_dev *dev, int instance)
168} 169}
169 170
170 171
171struct vfc_dev *vfc_get_dev_ptr(int instance) 172static struct vfc_dev *vfc_get_dev_ptr(int instance)
172{ 173{
173 return vfc_dev_lst[instance]; 174 return vfc_dev_lst[instance];
174} 175}
@@ -292,7 +293,7 @@ static int vfc_debug(struct vfc_dev *dev, int cmd, void __user *argp)
292 return 0; 293 return 0;
293} 294}
294 295
295int vfc_capture_start(struct vfc_dev *dev) 296static int vfc_capture_start(struct vfc_dev *dev)
296{ 297{
297 vfc_captstat_reset(dev); 298 vfc_captstat_reset(dev);
298 dev->control_reg = sbus_readl(&dev->regs->control); 299 dev->control_reg = sbus_readl(&dev->regs->control);
@@ -314,7 +315,7 @@ int vfc_capture_start(struct vfc_dev *dev)
314 return 0; 315 return 0;
315} 316}
316 317
317int vfc_capture_poll(struct vfc_dev *dev) 318static int vfc_capture_poll(struct vfc_dev *dev)
318{ 319{
319 int timeout = 1000; 320 int timeout = 1000;
320 321
@@ -390,8 +391,8 @@ static int vfc_set_control_ioctl(struct inode *inode, struct file *file,
390} 391}
391 392
392 393
393int vfc_port_change_ioctl(struct inode *inode, struct file *file, 394static int vfc_port_change_ioctl(struct inode *inode, struct file *file,
394 struct vfc_dev *dev, unsigned long arg) 395 struct vfc_dev *dev, unsigned long arg)
395{ 396{
396 int ret = 0; 397 int ret = 0;
397 int cmd; 398 int cmd;
@@ -460,8 +461,8 @@ int vfc_port_change_ioctl(struct inode *inode, struct file *file,
460 return ret; 461 return ret;
461} 462}
462 463
463int vfc_set_video_ioctl(struct inode *inode, struct file *file, 464static int vfc_set_video_ioctl(struct inode *inode, struct file *file,
464 struct vfc_dev *dev, unsigned long arg) 465 struct vfc_dev *dev, unsigned long arg)
465{ 466{
466 int ret = 0; 467 int ret = 0;
467 int cmd; 468 int cmd;
@@ -511,8 +512,8 @@ int vfc_set_video_ioctl(struct inode *inode, struct file *file,
511 return ret; 512 return ret;
512} 513}
513 514
514int vfc_get_video_ioctl(struct inode *inode, struct file *file, 515static int vfc_get_video_ioctl(struct inode *inode, struct file *file,
515 struct vfc_dev *dev, unsigned long arg) 516 struct vfc_dev *dev, unsigned long arg)
516{ 517{
517 int ret = 0; 518 int ret = 0;
518 unsigned int status = NO_LOCK; 519 unsigned int status = NO_LOCK;
diff --git a/drivers/sbus/char/vfc_i2c.c b/drivers/sbus/char/vfc_i2c.c
index 9efed771f6c0..32b986e0ed78 100644
--- a/drivers/sbus/char/vfc_i2c.c
+++ b/drivers/sbus/char/vfc_i2c.c
@@ -114,7 +114,7 @@ int vfc_i2c_reset_bus(struct vfc_dev *dev)
114 return 0; 114 return 0;
115} 115}
116 116
117int vfc_i2c_wait_for_bus(struct vfc_dev *dev) 117static int vfc_i2c_wait_for_bus(struct vfc_dev *dev)
118{ 118{
119 int timeout = 1000; 119 int timeout = 1000;
120 120
@@ -126,7 +126,7 @@ int vfc_i2c_wait_for_bus(struct vfc_dev *dev)
126 return 0; 126 return 0;
127} 127}
128 128
129int vfc_i2c_wait_for_pin(struct vfc_dev *dev, int ack) 129static int vfc_i2c_wait_for_pin(struct vfc_dev *dev, int ack)
130{ 130{
131 int timeout = 1000; 131 int timeout = 1000;
132 int s1; 132 int s1;
@@ -144,7 +144,8 @@ int vfc_i2c_wait_for_pin(struct vfc_dev *dev, int ack)
144} 144}
145 145
146#define SHIFT(a) ((a) << 24) 146#define SHIFT(a) ((a) << 24)
147int vfc_i2c_xmit_addr(struct vfc_dev *dev, unsigned char addr, char mode) 147static int vfc_i2c_xmit_addr(struct vfc_dev *dev, unsigned char addr,
148 char mode)
148{ 149{
149 int ret, raddr; 150 int ret, raddr;
150#if 1 151#if 1
@@ -195,7 +196,7 @@ int vfc_i2c_xmit_addr(struct vfc_dev *dev, unsigned char addr, char mode)
195 return 0; 196 return 0;
196} 197}
197 198
198int vfc_i2c_xmit_byte(struct vfc_dev *dev,unsigned char *byte) 199static int vfc_i2c_xmit_byte(struct vfc_dev *dev,unsigned char *byte)
199{ 200{
200 int ret; 201 int ret;
201 u32 val = SHIFT((unsigned int)*byte); 202 u32 val = SHIFT((unsigned int)*byte);
@@ -218,7 +219,8 @@ int vfc_i2c_xmit_byte(struct vfc_dev *dev,unsigned char *byte)
218 return ret; 219 return ret;
219} 220}
220 221
221int vfc_i2c_recv_byte(struct vfc_dev *dev, unsigned char *byte, int last) 222static int vfc_i2c_recv_byte(struct vfc_dev *dev, unsigned char *byte,
223 int last)
222{ 224{
223 int ret; 225 int ret;
224 226
diff --git a/drivers/sbus/dvma.c b/drivers/sbus/dvma.c
index 57e1526746a2..ab0d2de3324c 100644
--- a/drivers/sbus/dvma.c
+++ b/drivers/sbus/dvma.c
@@ -16,7 +16,7 @@
16 16
17struct sbus_dma *dma_chain; 17struct sbus_dma *dma_chain;
18 18
19void __init init_one_dvma(struct sbus_dma *dma, int num_dma) 19static void __init init_one_dvma(struct sbus_dma *dma, int num_dma)
20{ 20{
21 printk("dma%d: ", num_dma); 21 printk("dma%d: ", num_dma);
22 22
diff --git a/drivers/sbus/sbus.c b/drivers/sbus/sbus.c
index c37d7c2587ff..73a86d09bba8 100644
--- a/drivers/sbus/sbus.c
+++ b/drivers/sbus/sbus.c
@@ -78,7 +78,7 @@ static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sde
78 else 78 else
79 sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev; 79 sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev;
80 sdev->ofdev.dev.bus = &sbus_bus_type; 80 sdev->ofdev.dev.bus = &sbus_bus_type;
81 sprintf(sdev->ofdev.dev.bus_id, "sbus[%08x]", dp->node); 81 dev_set_name(&sdev->ofdev.dev, "sbus[%08x]", dp->node);
82 82
83 if (of_device_register(&sdev->ofdev) != 0) 83 if (of_device_register(&sdev->ofdev) != 0)
84 printk(KERN_DEBUG "sbus: device registration error for %s!\n", 84 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
@@ -257,11 +257,11 @@ static void __init build_one_sbus(struct device_node *dp, int num_sbus)
257 sbus->ofdev.node = dp; 257 sbus->ofdev.node = dp;
258 sbus->ofdev.dev.parent = NULL; 258 sbus->ofdev.dev.parent = NULL;
259 sbus->ofdev.dev.bus = &sbus_bus_type; 259 sbus->ofdev.dev.bus = &sbus_bus_type;
260 sprintf(sbus->ofdev.dev.bus_id, "sbus%d", num_sbus); 260 dev_set_name(&sbus->ofdev.dev, "sbus%d", num_sbus);
261 261
262 if (of_device_register(&sbus->ofdev) != 0) 262 if (of_device_register(&sbus->ofdev) != 0)
263 printk(KERN_DEBUG "sbus: device registration error for %s!\n", 263 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
264 sbus->ofdev.dev.bus_id); 264 dev_name(&sbus->ofdev.dev));
265 265
266 dev_dp = dp->child; 266 dev_dp = dp->child;
267 while (dev_dp) { 267 while (dev_dp) {
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 2bc30e32b67a..1fe0901e8119 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -271,8 +271,8 @@ rebuild_sys_tab:
271 pHba->initialized = TRUE; 271 pHba->initialized = TRUE;
272 pHba->state &= ~DPTI_STATE_RESET; 272 pHba->state &= ~DPTI_STATE_RESET;
273 if (adpt_sysfs_class) { 273 if (adpt_sysfs_class) {
274 struct device *dev = device_create(adpt_sysfs_class, 274 struct device *dev = device_create_drvdata(adpt_sysfs_class,
275 NULL, MKDEV(DPTI_I2O_MAJOR, pHba->unit), 275 NULL, MKDEV(DPTI_I2O_MAJOR, pHba->unit), NULL,
276 "dpti%d", pHba->unit); 276 "dpti%d", pHba->unit);
277 if (IS_ERR(dev)) { 277 if (IS_ERR(dev)) {
278 printk(KERN_WARNING"dpti%d: unable to " 278 printk(KERN_WARNING"dpti%d: unable to "
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 35cd892dce04..fed0b02ebc1d 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -232,8 +232,8 @@ int scsi_add_host(struct Scsi_Host *shost, struct device *dev)
232 } 232 }
233 233
234 if (shost->transportt->create_work_queue) { 234 if (shost->transportt->create_work_queue) {
235 snprintf(shost->work_q_name, KOBJ_NAME_LEN, "scsi_wq_%d", 235 snprintf(shost->work_q_name, sizeof(shost->work_q_name),
236 shost->host_no); 236 "scsi_wq_%d", shost->host_no);
237 shost->work_q = create_singlethread_workqueue( 237 shost->work_q = create_singlethread_workqueue(
238 shost->work_q_name); 238 shost->work_q_name);
239 if (!shost->work_q) { 239 if (!shost->work_q) {
@@ -466,7 +466,8 @@ struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
466 struct device *cdev; 466 struct device *cdev;
467 struct Scsi_Host *shost = ERR_PTR(-ENXIO); 467 struct Scsi_Host *shost = ERR_PTR(-ENXIO);
468 468
469 cdev = class_find_device(&shost_class, &hostnum, __scsi_host_match); 469 cdev = class_find_device(&shost_class, NULL, &hostnum,
470 __scsi_host_match);
470 if (cdev) { 471 if (cdev) {
471 shost = scsi_host_get(class_to_shost(cdev)); 472 shost = scsi_host_get(class_to_shost(cdev));
472 put_device(cdev); 473 put_device(cdev);
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 5fd64e70029d..a272b9a2c869 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -417,15 +417,16 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev,
417 fc_host->next_vport_number = 0; 417 fc_host->next_vport_number = 0;
418 fc_host->npiv_vports_inuse = 0; 418 fc_host->npiv_vports_inuse = 0;
419 419
420 snprintf(fc_host->work_q_name, KOBJ_NAME_LEN, "fc_wq_%d", 420 snprintf(fc_host->work_q_name, sizeof(fc_host->work_q_name),
421 shost->host_no); 421 "fc_wq_%d", shost->host_no);
422 fc_host->work_q = create_singlethread_workqueue( 422 fc_host->work_q = create_singlethread_workqueue(
423 fc_host->work_q_name); 423 fc_host->work_q_name);
424 if (!fc_host->work_q) 424 if (!fc_host->work_q)
425 return -ENOMEM; 425 return -ENOMEM;
426 426
427 snprintf(fc_host->devloss_work_q_name, KOBJ_NAME_LEN, "fc_dl_%d", 427 snprintf(fc_host->devloss_work_q_name,
428 shost->host_no); 428 sizeof(fc_host->devloss_work_q_name),
429 "fc_dl_%d", shost->host_no);
429 fc_host->devloss_work_q = create_singlethread_workqueue( 430 fc_host->devloss_work_q = create_singlethread_workqueue(
430 fc_host->devloss_work_q_name); 431 fc_host->devloss_work_q_name);
431 if (!fc_host->devloss_work_q) { 432 if (!fc_host->devloss_work_q) {
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 3af7cbcc5c5d..043c3921164f 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -170,7 +170,7 @@ iscsi_create_endpoint(int dd_size)
170 int err; 170 int err;
171 171
172 for (id = 1; id < ISCSI_MAX_EPID; id++) { 172 for (id = 1; id < ISCSI_MAX_EPID; id++) {
173 dev = class_find_device(&iscsi_endpoint_class, &id, 173 dev = class_find_device(&iscsi_endpoint_class, NULL, &id,
174 iscsi_match_epid); 174 iscsi_match_epid);
175 if (!dev) 175 if (!dev)
176 break; 176 break;
@@ -222,7 +222,7 @@ struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
222 struct iscsi_endpoint *ep; 222 struct iscsi_endpoint *ep;
223 struct device *dev; 223 struct device *dev;
224 224
225 dev = class_find_device(&iscsi_endpoint_class, &handle, 225 dev = class_find_device(&iscsi_endpoint_class, NULL, &handle,
226 iscsi_match_epid); 226 iscsi_match_epid);
227 if (!dev) 227 if (!dev)
228 return NULL; 228 return NULL;
@@ -247,8 +247,8 @@ static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
247 atomic_set(&ihost->nr_scans, 0); 247 atomic_set(&ihost->nr_scans, 0);
248 mutex_init(&ihost->mutex); 248 mutex_init(&ihost->mutex);
249 249
250 snprintf(ihost->scan_workq_name, KOBJ_NAME_LEN, "iscsi_scan_%d", 250 snprintf(ihost->scan_workq_name, sizeof(ihost->scan_workq_name),
251 shost->host_no); 251 "iscsi_scan_%d", shost->host_no);
252 ihost->scan_workq = create_singlethread_workqueue( 252 ihost->scan_workq = create_singlethread_workqueue(
253 ihost->scan_workq_name); 253 ihost->scan_workq_name);
254 if (!ihost->scan_workq) 254 if (!ihost->scan_workq)
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index ce948b66bbd4..27f34a9f9cb7 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -1874,7 +1874,9 @@ static int serial8250_startup(struct uart_port *port)
1874 * the interrupt is enabled. Delays are necessary to 1874 * the interrupt is enabled. Delays are necessary to
1875 * allow register changes to become visible. 1875 * allow register changes to become visible.
1876 */ 1876 */
1877 spin_lock_irqsave(&up->port.lock, flags); 1877 spin_lock(&up->port.lock);
1878 if (up->port.flags & UPF_SHARE_IRQ)
1879 disable_irq_nosync(up->port.irq);
1878 1880
1879 wait_for_xmitr(up, UART_LSR_THRE); 1881 wait_for_xmitr(up, UART_LSR_THRE);
1880 serial_out_sync(up, UART_IER, UART_IER_THRI); 1882 serial_out_sync(up, UART_IER, UART_IER_THRI);
@@ -1886,7 +1888,9 @@ static int serial8250_startup(struct uart_port *port)
1886 iir = serial_in(up, UART_IIR); 1888 iir = serial_in(up, UART_IIR);
1887 serial_out(up, UART_IER, 0); 1889 serial_out(up, UART_IER, 0);
1888 1890
1889 spin_unlock_irqrestore(&up->port.lock, flags); 1891 if (up->port.flags & UPF_SHARE_IRQ)
1892 enable_irq(up->port.irq);
1893 spin_unlock(&up->port.lock);
1890 1894
1891 /* 1895 /*
1892 * If the interrupt is not reasserted, setup a timer to 1896 * If the interrupt is not reasserted, setup a timer to
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index abe129cc927a..93e407ee08b9 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -209,7 +209,7 @@ static void cpm_uart_int_rx(struct uart_port *port)
209 int i; 209 int i;
210 unsigned char ch; 210 unsigned char ch;
211 u8 *cp; 211 u8 *cp;
212 struct tty_struct *tty = port->info->tty; 212 struct tty_struct *tty = port->info->port.tty;
213 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 213 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
214 cbd_t __iomem *bdp; 214 cbd_t __iomem *bdp;
215 u16 status; 215 u16 status;
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c
index 9c2df5c857cf..2b7531d9f6ab 100644
--- a/drivers/serial/icom.c
+++ b/drivers/serial/icom.c
@@ -730,7 +730,7 @@ static void xmit_interrupt(u16 port_int_reg, struct icom_port *icom_port)
730static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port) 730static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port)
731{ 731{
732 short int count, rcv_buff; 732 short int count, rcv_buff;
733 struct tty_struct *tty = icom_port->uart_port.info->tty; 733 struct tty_struct *tty = icom_port->uart_port.info->port.tty;
734 unsigned short int status; 734 unsigned short int status;
735 struct uart_icount *icount; 735 struct uart_icount *icount;
736 unsigned long offset; 736 unsigned long offset;
diff --git a/drivers/serial/samsung.c b/drivers/serial/samsung.c
index 4a3ecaa629e6..d852f83f8900 100644
--- a/drivers/serial/samsung.c
+++ b/drivers/serial/samsung.c
@@ -202,7 +202,7 @@ s3c24xx_serial_rx_chars(int irq, void *dev_id)
202{ 202{
203 struct s3c24xx_uart_port *ourport = dev_id; 203 struct s3c24xx_uart_port *ourport = dev_id;
204 struct uart_port *port = &ourport->port; 204 struct uart_port *port = &ourport->port;
205 struct tty_struct *tty = port->info->tty; 205 struct tty_struct *tty = port->info->port.tty;
206 unsigned int ufcon, ch, flag, ufstat, uerstat; 206 unsigned int ufcon, ch, flag, ufstat, uerstat;
207 int max_count = 64; 207 int max_count = 64;
208 208
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 0bce1fe2c62a..f977c98cfa95 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -934,7 +934,7 @@ uart_tiocmset(struct tty_struct *tty, struct file *file,
934 return ret; 934 return ret;
935} 935}
936 936
937static void uart_break_ctl(struct tty_struct *tty, int break_state) 937static int uart_break_ctl(struct tty_struct *tty, int break_state)
938{ 938{
939 struct uart_state *state = tty->driver_data; 939 struct uart_state *state = tty->driver_data;
940 struct uart_port *port = state->port; 940 struct uart_port *port = state->port;
@@ -945,6 +945,7 @@ static void uart_break_ctl(struct tty_struct *tty, int break_state)
945 port->ops->break_ctl(port, break_state); 945 port->ops->break_ctl(port, break_state);
946 946
947 mutex_unlock(&state->mutex); 947 mutex_unlock(&state->mutex);
948 return 0;
948} 949}
949 950
950static int uart_do_autoconfig(struct uart_state *state) 951static int uart_do_autoconfig(struct uart_state *state)
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index 7ad21925869a..8fcb4c5b9a26 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -272,7 +272,7 @@ static void serial_txx9_initialize(struct uart_port *port)
272static inline void 272static inline void
273receive_chars(struct uart_txx9_port *up, unsigned int *status) 273receive_chars(struct uart_txx9_port *up, unsigned int *status)
274{ 274{
275 struct tty_struct *tty = up->port.info->tty; 275 struct tty_struct *tty = up->port.info->port.tty;
276 unsigned char ch; 276 unsigned char ch;
277 unsigned int disr = *status; 277 unsigned int disr = *status;
278 int max_count = 256; 278 int max_count = 256;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1ad12afc6ba0..1771b2456bfa 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -502,7 +502,7 @@ struct spi_master *spi_busnum_to_master(u16 bus_num)
502 struct device *dev; 502 struct device *dev;
503 struct spi_master *master = NULL; 503 struct spi_master *master = NULL;
504 504
505 dev = class_find_device(&spi_master_class, &bus_num, 505 dev = class_find_device(&spi_master_class, NULL, &bus_num,
506 __spi_master_match); 506 __spi_master_match);
507 if (dev) 507 if (dev)
508 master = container_of(dev, struct spi_master, dev); 508 master = container_of(dev, struct spi_master, dev);
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index ddbe1a5e970e..2833fd772a24 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -576,7 +576,8 @@ static int spidev_probe(struct spi_device *spi)
576 struct device *dev; 576 struct device *dev;
577 577
578 spidev->devt = MKDEV(SPIDEV_MAJOR, minor); 578 spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
579 dev = device_create(spidev_class, &spi->dev, spidev->devt, 579 dev = device_create_drvdata(spidev_class, &spi->dev,
580 spidev->devt, spidev,
580 "spidev%d.%d", 581 "spidev%d.%d",
581 spi->master->bus_num, spi->chip_select); 582 spi->master->bus_num, spi->chip_select);
582 status = IS_ERR(dev) ? PTR_ERR(dev) : 0; 583 status = IS_ERR(dev) ? PTR_ERR(dev) : 0;
@@ -586,7 +587,6 @@ static int spidev_probe(struct spi_device *spi)
586 } 587 }
587 if (status == 0) { 588 if (status == 0) {
588 set_bit(minor, minors); 589 set_bit(minor, minors);
589 spi_set_drvdata(spi, spidev);
590 list_add(&spidev->device_entry, &device_list); 590 list_add(&spidev->device_entry, &device_list);
591 } 591 }
592 mutex_unlock(&device_list_lock); 592 mutex_unlock(&device_list_lock);
diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
index a4aaab9c7ddc..2e9079df26b3 100644
--- a/drivers/uio/Kconfig
+++ b/drivers/uio/Kconfig
@@ -15,7 +15,7 @@ if UIO
15 15
16config UIO_CIF 16config UIO_CIF
17 tristate "generic Hilscher CIF Card driver" 17 tristate "generic Hilscher CIF Card driver"
18 depends on UIO && PCI 18 depends on PCI
19 default n 19 default n
20 help 20 help
21 Driver for Hilscher CIF DeviceNet and Profibus cards. This 21 Driver for Hilscher CIF DeviceNet and Profibus cards. This
@@ -26,9 +26,15 @@ config UIO_CIF
26 To compile this driver as a module, choose M here: the module 26 To compile this driver as a module, choose M here: the module
27 will be called uio_cif. 27 will be called uio_cif.
28 28
29config UIO_PDRV
30 tristate "Userspace I/O platform driver"
31 help
32 Generic platform driver for Userspace I/O devices.
33
34 If you don't know what to do here, say N.
35
29config UIO_SMX 36config UIO_SMX
30 tristate "SMX cryptengine UIO interface" 37 tristate "SMX cryptengine UIO interface"
31 depends on UIO
32 default n 38 default n
33 help 39 help
34 Userspace IO interface to the Cryptography engine found on the 40 Userspace IO interface to the Cryptography engine found on the
diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile
index 18c45662431e..e00ce0def1a0 100644
--- a/drivers/uio/Makefile
+++ b/drivers/uio/Makefile
@@ -1,3 +1,4 @@
1obj-$(CONFIG_UIO) += uio.o 1obj-$(CONFIG_UIO) += uio.o
2obj-$(CONFIG_UIO_CIF) += uio_cif.o 2obj-$(CONFIG_UIO_CIF) += uio_cif.o
3obj-$(CONFIG_UIO_PDRV) += uio_pdrv.o
3obj-$(CONFIG_UIO_SMX) += uio_smx.o 4obj-$(CONFIG_UIO_SMX) += uio_smx.o
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 5a7ca2e6094d..3a6934bf7131 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -427,6 +427,31 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
427 return retval; 427 return retval;
428} 428}
429 429
430static ssize_t uio_write(struct file *filep, const char __user *buf,
431 size_t count, loff_t *ppos)
432{
433 struct uio_listener *listener = filep->private_data;
434 struct uio_device *idev = listener->dev;
435 ssize_t retval;
436 s32 irq_on;
437
438 if (idev->info->irq == UIO_IRQ_NONE)
439 return -EIO;
440
441 if (count != sizeof(s32))
442 return -EINVAL;
443
444 if (!idev->info->irqcontrol)
445 return -ENOSYS;
446
447 if (copy_from_user(&irq_on, buf, count))
448 return -EFAULT;
449
450 retval = idev->info->irqcontrol(idev->info, irq_on);
451
452 return retval ? retval : sizeof(s32);
453}
454
430static int uio_find_mem_index(struct vm_area_struct *vma) 455static int uio_find_mem_index(struct vm_area_struct *vma)
431{ 456{
432 int mi; 457 int mi;
@@ -546,6 +571,7 @@ static const struct file_operations uio_fops = {
546 .open = uio_open, 571 .open = uio_open,
547 .release = uio_release, 572 .release = uio_release,
548 .read = uio_read, 573 .read = uio_read,
574 .write = uio_write,
549 .mmap = uio_mmap, 575 .mmap = uio_mmap,
550 .poll = uio_poll, 576 .poll = uio_poll,
551 .fasync = uio_fasync, 577 .fasync = uio_fasync,
diff --git a/drivers/uio/uio_pdrv.c b/drivers/uio/uio_pdrv.c
new file mode 100644
index 000000000000..5d0d2e85d982
--- /dev/null
+++ b/drivers/uio/uio_pdrv.c
@@ -0,0 +1,118 @@
1/*
2 * drivers/uio/uio_pdrv.c
3 *
4 * Copyright (C) 2008 by Digi International Inc.
5 * All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 */
11#include <linux/platform_device.h>
12#include <linux/uio_driver.h>
13#include <linux/stringify.h>
14
15#define DRIVER_NAME "uio"
16
17struct uio_platdata {
18 struct uio_info *uioinfo;
19};
20
21static int uio_pdrv_probe(struct platform_device *pdev)
22{
23 struct uio_info *uioinfo = pdev->dev.platform_data;
24 struct uio_platdata *pdata;
25 struct uio_mem *uiomem;
26 int ret = -ENODEV;
27 int i;
28
29 if (!uioinfo || !uioinfo->name || !uioinfo->version) {
30 dev_dbg(&pdev->dev, "%s: err_uioinfo\n", __func__);
31 goto err_uioinfo;
32 }
33
34 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
35 if (!pdata) {
36 ret = -ENOMEM;
37 dev_dbg(&pdev->dev, "%s: err_alloc_pdata\n", __func__);
38 goto err_alloc_pdata;
39 }
40
41 pdata->uioinfo = uioinfo;
42
43 uiomem = &uioinfo->mem[0];
44
45 for (i = 0; i < pdev->num_resources; ++i) {
46 struct resource *r = &pdev->resource[i];
47
48 if (r->flags != IORESOURCE_MEM)
49 continue;
50
51 if (uiomem >= &uioinfo->mem[MAX_UIO_MAPS]) {
52 dev_warn(&pdev->dev, "device has more than "
53 __stringify(MAX_UIO_MAPS)
54 " I/O memory resources.\n");
55 break;
56 }
57
58 uiomem->memtype = UIO_MEM_PHYS;
59 uiomem->addr = r->start;
60 uiomem->size = r->end - r->start + 1;
61 ++uiomem;
62 }
63
64 while (uiomem < &uioinfo->mem[MAX_UIO_MAPS]) {
65 uiomem->size = 0;
66 ++uiomem;
67 }
68
69 pdata->uioinfo->priv = pdata;
70
71 ret = uio_register_device(&pdev->dev, pdata->uioinfo);
72
73 if (ret) {
74 kfree(pdata);
75err_alloc_pdata:
76err_uioinfo:
77 return ret;
78 }
79
80 platform_set_drvdata(pdev, pdata);
81
82 return 0;
83}
84
85static int uio_pdrv_remove(struct platform_device *pdev)
86{
87 struct uio_platdata *pdata = platform_get_drvdata(pdev);
88
89 uio_unregister_device(pdata->uioinfo);
90
91 return 0;
92}
93
94static struct platform_driver uio_pdrv = {
95 .probe = uio_pdrv_probe,
96 .remove = uio_pdrv_remove,
97 .driver = {
98 .name = DRIVER_NAME,
99 .owner = THIS_MODULE,
100 },
101};
102
103static int __init uio_pdrv_init(void)
104{
105 return platform_driver_register(&uio_pdrv);
106}
107
108static void __exit uio_pdrv_exit(void)
109{
110 platform_driver_unregister(&uio_pdrv);
111}
112module_init(uio_pdrv_init);
113module_exit(uio_pdrv_exit);
114
115MODULE_AUTHOR("Uwe Kleine-Koenig");
116MODULE_DESCRIPTION("Userspace I/O platform driver");
117MODULE_LICENSE("GPL");
118MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index 90583d6a5949..507a9bd0d77c 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -1052,7 +1052,6 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance,
1052 1052
1053 instance->usbatm = usbatm_instance; 1053 instance->usbatm = usbatm_instance;
1054 instance->modem_type = (struct cxacru_modem_type *) id->driver_info; 1054 instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
1055 memset(instance->card_info, 0, sizeof(instance->card_info));
1056 1055
1057 mutex_init(&instance->poll_state_serialize); 1056 mutex_init(&instance->poll_state_serialize);
1058 instance->poll_state = CXPOLL_STOPPED; 1057 instance->poll_state = CXPOLL_STOPPED;
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 7d27c9cf3c43..76fce44c2f9a 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -829,7 +829,6 @@ static int speedtch_bind(struct usbatm_data *usbatm,
829 if (use_isoc) { 829 if (use_isoc) {
830 const struct usb_host_interface *desc = data_intf->cur_altsetting; 830 const struct usb_host_interface *desc = data_intf->cur_altsetting;
831 const __u8 target_address = USB_DIR_IN | usbatm->driver->isoc_in; 831 const __u8 target_address = USB_DIR_IN | usbatm->driver->isoc_in;
832 int i;
833 832
834 use_isoc = 0; /* fall back to bulk if endpoint not found */ 833 use_isoc = 0; /* fall back to bulk if endpoint not found */
835 834
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index c3201affa0b6..0725b1871f23 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -159,12 +159,34 @@ static void acm_write_done(struct acm *acm, struct acm_wb *wb)
159 spin_lock_irqsave(&acm->write_lock, flags); 159 spin_lock_irqsave(&acm->write_lock, flags);
160 acm->write_ready = 1; 160 acm->write_ready = 1;
161 wb->use = 0; 161 wb->use = 0;
162 acm->transmitting--;
162 spin_unlock_irqrestore(&acm->write_lock, flags); 163 spin_unlock_irqrestore(&acm->write_lock, flags);
163} 164}
164 165
165/* 166/*
166 * Poke write. 167 * Poke write.
168 *
169 * the caller is responsible for locking
167 */ 170 */
171
172static int acm_start_wb(struct acm *acm, struct acm_wb *wb)
173{
174 int rc;
175
176 acm->transmitting++;
177
178 wb->urb->transfer_buffer = wb->buf;
179 wb->urb->transfer_dma = wb->dmah;
180 wb->urb->transfer_buffer_length = wb->len;
181 wb->urb->dev = acm->dev;
182
183 if ((rc = usb_submit_urb(wb->urb, GFP_ATOMIC)) < 0) {
184 dbg("usb_submit_urb(write bulk) failed: %d", rc);
185 acm_write_done(acm, wb);
186 }
187 return rc;
188}
189
168static int acm_write_start(struct acm *acm, int wbn) 190static int acm_write_start(struct acm *acm, int wbn)
169{ 191{
170 unsigned long flags; 192 unsigned long flags;
@@ -182,26 +204,31 @@ static int acm_write_start(struct acm *acm, int wbn)
182 return 0; /* A white lie */ 204 return 0; /* A white lie */
183 } 205 }
184 206
207 wb = &acm->wb[wbn];
208 if(acm_wb_is_avail(acm) <= 1)
209 acm->write_ready = 0;
210
211 dbg("%s susp_count: %d", __func__, acm->susp_count);
212 if (acm->susp_count) {
213 acm->old_ready = acm->write_ready;
214 acm->delayed_wb = wb;
215 acm->write_ready = 0;
216 schedule_work(&acm->waker);
217 spin_unlock_irqrestore(&acm->write_lock, flags);
218 return 0; /* A white lie */
219 }
220 usb_mark_last_busy(acm->dev);
221
185 if (!acm_wb_is_used(acm, wbn)) { 222 if (!acm_wb_is_used(acm, wbn)) {
186 spin_unlock_irqrestore(&acm->write_lock, flags); 223 spin_unlock_irqrestore(&acm->write_lock, flags);
187 return 0; 224 return 0;
188 } 225 }
189 wb = &acm->wb[wbn];
190 226
191 if(acm_wb_is_avail(acm) <= 1) 227 rc = acm_start_wb(acm, wb);
192 acm->write_ready = 0;
193 spin_unlock_irqrestore(&acm->write_lock, flags); 228 spin_unlock_irqrestore(&acm->write_lock, flags);
194 229
195 wb->urb->transfer_buffer = wb->buf;
196 wb->urb->transfer_dma = wb->dmah;
197 wb->urb->transfer_buffer_length = wb->len;
198 wb->urb->dev = acm->dev;
199
200 if ((rc = usb_submit_urb(wb->urb, GFP_ATOMIC)) < 0) {
201 dbg("usb_submit_urb(write bulk) failed: %d", rc);
202 acm_write_done(acm, wb);
203 }
204 return rc; 230 return rc;
231
205} 232}
206/* 233/*
207 * attributes exported through sysfs 234 * attributes exported through sysfs
@@ -304,6 +331,7 @@ static void acm_ctrl_irq(struct urb *urb)
304 break; 331 break;
305 } 332 }
306exit: 333exit:
334 usb_mark_last_busy(acm->dev);
307 retval = usb_submit_urb (urb, GFP_ATOMIC); 335 retval = usb_submit_urb (urb, GFP_ATOMIC);
308 if (retval) 336 if (retval)
309 err ("%s - usb_submit_urb failed with result %d", 337 err ("%s - usb_submit_urb failed with result %d",
@@ -320,8 +348,11 @@ static void acm_read_bulk(struct urb *urb)
320 348
321 dbg("Entering acm_read_bulk with status %d", status); 349 dbg("Entering acm_read_bulk with status %d", status);
322 350
323 if (!ACM_READY(acm)) 351 if (!ACM_READY(acm)) {
352 dev_dbg(&acm->data->dev, "Aborting, acm not ready");
324 return; 353 return;
354 }
355 usb_mark_last_busy(acm->dev);
325 356
326 if (status) 357 if (status)
327 dev_dbg(&acm->data->dev, "bulk rx status %d\n", status); 358 dev_dbg(&acm->data->dev, "bulk rx status %d\n", status);
@@ -331,6 +362,7 @@ static void acm_read_bulk(struct urb *urb)
331 362
332 if (likely(status == 0)) { 363 if (likely(status == 0)) {
333 spin_lock(&acm->read_lock); 364 spin_lock(&acm->read_lock);
365 acm->processing++;
334 list_add_tail(&rcv->list, &acm->spare_read_urbs); 366 list_add_tail(&rcv->list, &acm->spare_read_urbs);
335 list_add_tail(&buf->list, &acm->filled_read_bufs); 367 list_add_tail(&buf->list, &acm->filled_read_bufs);
336 spin_unlock(&acm->read_lock); 368 spin_unlock(&acm->read_lock);
@@ -343,7 +375,8 @@ static void acm_read_bulk(struct urb *urb)
343 /* nevertheless the tasklet must be kicked unconditionally 375 /* nevertheless the tasklet must be kicked unconditionally
344 so the queue cannot dry up */ 376 so the queue cannot dry up */
345 } 377 }
346 tasklet_schedule(&acm->urb_task); 378 if (likely(!acm->susp_count))
379 tasklet_schedule(&acm->urb_task);
347} 380}
348 381
349static void acm_rx_tasklet(unsigned long _acm) 382static void acm_rx_tasklet(unsigned long _acm)
@@ -354,16 +387,23 @@ static void acm_rx_tasklet(unsigned long _acm)
354 struct acm_ru *rcv; 387 struct acm_ru *rcv;
355 unsigned long flags; 388 unsigned long flags;
356 unsigned char throttled; 389 unsigned char throttled;
390
357 dbg("Entering acm_rx_tasklet"); 391 dbg("Entering acm_rx_tasklet");
358 392
359 if (!ACM_READY(acm)) 393 if (!ACM_READY(acm))
394 {
395 dbg("acm_rx_tasklet: ACM not ready");
360 return; 396 return;
397 }
361 398
362 spin_lock_irqsave(&acm->throttle_lock, flags); 399 spin_lock_irqsave(&acm->throttle_lock, flags);
363 throttled = acm->throttle; 400 throttled = acm->throttle;
364 spin_unlock_irqrestore(&acm->throttle_lock, flags); 401 spin_unlock_irqrestore(&acm->throttle_lock, flags);
365 if (throttled) 402 if (throttled)
403 {
404 dbg("acm_rx_tasklet: throttled");
366 return; 405 return;
406 }
367 407
368next_buffer: 408next_buffer:
369 spin_lock_irqsave(&acm->read_lock, flags); 409 spin_lock_irqsave(&acm->read_lock, flags);
@@ -403,6 +443,7 @@ urbs:
403 while (!list_empty(&acm->spare_read_bufs)) { 443 while (!list_empty(&acm->spare_read_bufs)) {
404 spin_lock_irqsave(&acm->read_lock, flags); 444 spin_lock_irqsave(&acm->read_lock, flags);
405 if (list_empty(&acm->spare_read_urbs)) { 445 if (list_empty(&acm->spare_read_urbs)) {
446 acm->processing = 0;
406 spin_unlock_irqrestore(&acm->read_lock, flags); 447 spin_unlock_irqrestore(&acm->read_lock, flags);
407 return; 448 return;
408 } 449 }
@@ -425,18 +466,23 @@ urbs:
425 rcv->urb->transfer_dma = buf->dma; 466 rcv->urb->transfer_dma = buf->dma;
426 rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 467 rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
427 468
428 dbg("acm_rx_tasklet: sending urb 0x%p, rcv 0x%p, buf 0x%p", rcv->urb, rcv, buf);
429
430 /* This shouldn't kill the driver as unsuccessful URBs are returned to the 469 /* This shouldn't kill the driver as unsuccessful URBs are returned to the
431 free-urbs-pool and resubmited ASAP */ 470 free-urbs-pool and resubmited ASAP */
432 if (usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) { 471 spin_lock_irqsave(&acm->read_lock, flags);
472 if (acm->susp_count || usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) {
433 list_add(&buf->list, &acm->spare_read_bufs); 473 list_add(&buf->list, &acm->spare_read_bufs);
434 spin_lock_irqsave(&acm->read_lock, flags);
435 list_add(&rcv->list, &acm->spare_read_urbs); 474 list_add(&rcv->list, &acm->spare_read_urbs);
475 acm->processing = 0;
436 spin_unlock_irqrestore(&acm->read_lock, flags); 476 spin_unlock_irqrestore(&acm->read_lock, flags);
437 return; 477 return;
478 } else {
479 spin_unlock_irqrestore(&acm->read_lock, flags);
480 dbg("acm_rx_tasklet: sending urb 0x%p, rcv 0x%p, buf 0x%p", rcv->urb, rcv, buf);
438 } 481 }
439 } 482 }
483 spin_lock_irqsave(&acm->read_lock, flags);
484 acm->processing = 0;
485 spin_unlock_irqrestore(&acm->read_lock, flags);
440} 486}
441 487
442/* data interface wrote those outgoing bytes */ 488/* data interface wrote those outgoing bytes */
@@ -463,6 +509,27 @@ static void acm_softint(struct work_struct *work)
463 tty_wakeup(acm->tty); 509 tty_wakeup(acm->tty);
464} 510}
465 511
512static void acm_waker(struct work_struct *waker)
513{
514 struct acm *acm = container_of(waker, struct acm, waker);
515 long flags;
516 int rv;
517
518 rv = usb_autopm_get_interface(acm->control);
519 if (rv < 0) {
520 err("Autopm failure in %s", __func__);
521 return;
522 }
523 if (acm->delayed_wb) {
524 acm_start_wb(acm, acm->delayed_wb);
525 acm->delayed_wb = NULL;
526 }
527 spin_lock_irqsave(&acm->write_lock, flags);
528 acm->write_ready = acm->old_ready;
529 spin_unlock_irqrestore(&acm->write_lock, flags);
530 usb_autopm_put_interface(acm->control);
531}
532
466/* 533/*
467 * TTY handlers 534 * TTY handlers
468 */ 535 */
@@ -492,6 +559,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
492 559
493 if (usb_autopm_get_interface(acm->control) < 0) 560 if (usb_autopm_get_interface(acm->control) < 0)
494 goto early_bail; 561 goto early_bail;
562 else
563 acm->control->needs_remote_wakeup = 1;
495 564
496 mutex_lock(&acm->mutex); 565 mutex_lock(&acm->mutex);
497 if (acm->used++) { 566 if (acm->used++) {
@@ -509,6 +578,7 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
509 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && 578 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) &&
510 (acm->ctrl_caps & USB_CDC_CAP_LINE)) 579 (acm->ctrl_caps & USB_CDC_CAP_LINE))
511 goto full_bailout; 580 goto full_bailout;
581 usb_autopm_put_interface(acm->control);
512 582
513 INIT_LIST_HEAD(&acm->spare_read_urbs); 583 INIT_LIST_HEAD(&acm->spare_read_urbs);
514 INIT_LIST_HEAD(&acm->spare_read_bufs); 584 INIT_LIST_HEAD(&acm->spare_read_bufs);
@@ -570,12 +640,14 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
570 mutex_lock(&open_mutex); 640 mutex_lock(&open_mutex);
571 if (!--acm->used) { 641 if (!--acm->used) {
572 if (acm->dev) { 642 if (acm->dev) {
643 usb_autopm_get_interface(acm->control);
573 acm_set_control(acm, acm->ctrlout = 0); 644 acm_set_control(acm, acm->ctrlout = 0);
574 usb_kill_urb(acm->ctrlurb); 645 usb_kill_urb(acm->ctrlurb);
575 for (i = 0; i < ACM_NW; i++) 646 for (i = 0; i < ACM_NW; i++)
576 usb_kill_urb(acm->wb[i].urb); 647 usb_kill_urb(acm->wb[i].urb);
577 for (i = 0; i < nr; i++) 648 for (i = 0; i < nr; i++)
578 usb_kill_urb(acm->ru[i].urb); 649 usb_kill_urb(acm->ru[i].urb);
650 acm->control->needs_remote_wakeup = 0;
579 usb_autopm_put_interface(acm->control); 651 usb_autopm_put_interface(acm->control);
580 } else 652 } else
581 acm_tty_unregister(acm); 653 acm_tty_unregister(acm);
@@ -660,13 +732,16 @@ static void acm_tty_unthrottle(struct tty_struct *tty)
660 tasklet_schedule(&acm->urb_task); 732 tasklet_schedule(&acm->urb_task);
661} 733}
662 734
663static void acm_tty_break_ctl(struct tty_struct *tty, int state) 735static int acm_tty_break_ctl(struct tty_struct *tty, int state)
664{ 736{
665 struct acm *acm = tty->driver_data; 737 struct acm *acm = tty->driver_data;
738 int retval;
666 if (!ACM_READY(acm)) 739 if (!ACM_READY(acm))
667 return; 740 return -EINVAL;
668 if (acm_send_break(acm, state ? 0xffff : 0)) 741 retval = acm_send_break(acm, state ? 0xffff : 0);
742 if (retval < 0)
669 dbg("send break failed"); 743 dbg("send break failed");
744 return retval;
670} 745}
671 746
672static int acm_tty_tiocmget(struct tty_struct *tty, struct file *file) 747static int acm_tty_tiocmget(struct tty_struct *tty, struct file *file)
@@ -766,7 +841,7 @@ static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios
766 * USB probe and disconnect routines. 841 * USB probe and disconnect routines.
767 */ 842 */
768 843
769/* Little helper: write buffers free */ 844/* Little helpers: write/read buffers free */
770static void acm_write_buffers_free(struct acm *acm) 845static void acm_write_buffers_free(struct acm *acm)
771{ 846{
772 int i; 847 int i;
@@ -777,6 +852,15 @@ static void acm_write_buffers_free(struct acm *acm)
777 } 852 }
778} 853}
779 854
855static void acm_read_buffers_free(struct acm *acm)
856{
857 struct usb_device *usb_dev = interface_to_usbdev(acm->control);
858 int i, n = acm->rx_buflimit;
859
860 for (i = 0; i < n; i++)
861 usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma);
862}
863
780/* Little helper: write buffers allocate */ 864/* Little helper: write buffers allocate */
781static int acm_write_buffers_alloc(struct acm *acm) 865static int acm_write_buffers_alloc(struct acm *acm)
782{ 866{
@@ -987,6 +1071,7 @@ skip_normal_probe:
987 acm->urb_task.func = acm_rx_tasklet; 1071 acm->urb_task.func = acm_rx_tasklet;
988 acm->urb_task.data = (unsigned long) acm; 1072 acm->urb_task.data = (unsigned long) acm;
989 INIT_WORK(&acm->work, acm_softint); 1073 INIT_WORK(&acm->work, acm_softint);
1074 INIT_WORK(&acm->waker, acm_waker);
990 spin_lock_init(&acm->throttle_lock); 1075 spin_lock_init(&acm->throttle_lock);
991 spin_lock_init(&acm->write_lock); 1076 spin_lock_init(&acm->write_lock);
992 spin_lock_init(&acm->read_lock); 1077 spin_lock_init(&acm->read_lock);
@@ -1098,8 +1183,7 @@ alloc_fail8:
1098 for (i = 0; i < ACM_NW; i++) 1183 for (i = 0; i < ACM_NW; i++)
1099 usb_free_urb(acm->wb[i].urb); 1184 usb_free_urb(acm->wb[i].urb);
1100alloc_fail7: 1185alloc_fail7:
1101 for (i = 0; i < num_rx_buf; i++) 1186 acm_read_buffers_free(acm);
1102 usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma);
1103 for (i = 0; i < num_rx_buf; i++) 1187 for (i = 0; i < num_rx_buf; i++)
1104 usb_free_urb(acm->ru[i].urb); 1188 usb_free_urb(acm->ru[i].urb);
1105 usb_free_urb(acm->ctrlurb); 1189 usb_free_urb(acm->ctrlurb);
@@ -1116,6 +1200,7 @@ alloc_fail:
1116static void stop_data_traffic(struct acm *acm) 1200static void stop_data_traffic(struct acm *acm)
1117{ 1201{
1118 int i; 1202 int i;
1203 dbg("Entering stop_data_traffic");
1119 1204
1120 tasklet_disable(&acm->urb_task); 1205 tasklet_disable(&acm->urb_task);
1121 1206
@@ -1128,21 +1213,16 @@ static void stop_data_traffic(struct acm *acm)
1128 tasklet_enable(&acm->urb_task); 1213 tasklet_enable(&acm->urb_task);
1129 1214
1130 cancel_work_sync(&acm->work); 1215 cancel_work_sync(&acm->work);
1216 cancel_work_sync(&acm->waker);
1131} 1217}
1132 1218
1133static void acm_disconnect(struct usb_interface *intf) 1219static void acm_disconnect(struct usb_interface *intf)
1134{ 1220{
1135 struct acm *acm = usb_get_intfdata(intf); 1221 struct acm *acm = usb_get_intfdata(intf);
1136 struct usb_device *usb_dev = interface_to_usbdev(intf); 1222 struct usb_device *usb_dev = interface_to_usbdev(intf);
1137 int i;
1138
1139 if (!acm || !acm->dev) {
1140 dbg("disconnect on nonexisting interface");
1141 return;
1142 }
1143 1223
1144 mutex_lock(&open_mutex); 1224 mutex_lock(&open_mutex);
1145 if (!usb_get_intfdata(intf)) { 1225 if (!acm || !acm->dev) {
1146 mutex_unlock(&open_mutex); 1226 mutex_unlock(&open_mutex);
1147 return; 1227 return;
1148 } 1228 }
@@ -1161,10 +1241,10 @@ static void acm_disconnect(struct usb_interface *intf)
1161 1241
1162 acm_write_buffers_free(acm); 1242 acm_write_buffers_free(acm);
1163 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); 1243 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
1164 for (i = 0; i < acm->rx_buflimit; i++) 1244 acm_read_buffers_free(acm);
1165 usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma);
1166 1245
1167 usb_driver_release_interface(&acm_driver, intf == acm->control ? acm->data : intf); 1246 usb_driver_release_interface(&acm_driver, intf == acm->control ?
1247 acm->data : acm->control);
1168 1248
1169 if (!acm->used) { 1249 if (!acm->used) {
1170 acm_tty_unregister(acm); 1250 acm_tty_unregister(acm);
@@ -1178,11 +1258,31 @@ static void acm_disconnect(struct usb_interface *intf)
1178 tty_hangup(acm->tty); 1258 tty_hangup(acm->tty);
1179} 1259}
1180 1260
1261#ifdef CONFIG_PM
1181static int acm_suspend(struct usb_interface *intf, pm_message_t message) 1262static int acm_suspend(struct usb_interface *intf, pm_message_t message)
1182{ 1263{
1183 struct acm *acm = usb_get_intfdata(intf); 1264 struct acm *acm = usb_get_intfdata(intf);
1265 int cnt;
1266
1267 if (acm->dev->auto_pm) {
1268 int b;
1269
1270 spin_lock_irq(&acm->read_lock);
1271 spin_lock(&acm->write_lock);
1272 b = acm->processing + acm->transmitting;
1273 spin_unlock(&acm->write_lock);
1274 spin_unlock_irq(&acm->read_lock);
1275 if (b)
1276 return -EBUSY;
1277 }
1278
1279 spin_lock_irq(&acm->read_lock);
1280 spin_lock(&acm->write_lock);
1281 cnt = acm->susp_count++;
1282 spin_unlock(&acm->write_lock);
1283 spin_unlock_irq(&acm->read_lock);
1184 1284
1185 if (acm->susp_count++) 1285 if (cnt)
1186 return 0; 1286 return 0;
1187 /* 1287 /*
1188 we treat opened interfaces differently, 1288 we treat opened interfaces differently,
@@ -1201,15 +1301,21 @@ static int acm_resume(struct usb_interface *intf)
1201{ 1301{
1202 struct acm *acm = usb_get_intfdata(intf); 1302 struct acm *acm = usb_get_intfdata(intf);
1203 int rv = 0; 1303 int rv = 0;
1304 int cnt;
1305
1306 spin_lock_irq(&acm->read_lock);
1307 acm->susp_count -= 1;
1308 cnt = acm->susp_count;
1309 spin_unlock_irq(&acm->read_lock);
1204 1310
1205 if (--acm->susp_count) 1311 if (cnt)
1206 return 0; 1312 return 0;
1207 1313
1208 mutex_lock(&acm->mutex); 1314 mutex_lock(&acm->mutex);
1209 if (acm->used) { 1315 if (acm->used) {
1210 rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); 1316 rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO);
1211 if (rv < 0) 1317 if (rv < 0)
1212 goto err_out; 1318 goto err_out;
1213 1319
1214 tasklet_schedule(&acm->urb_task); 1320 tasklet_schedule(&acm->urb_task);
1215 } 1321 }
@@ -1218,6 +1324,8 @@ err_out:
1218 mutex_unlock(&acm->mutex); 1324 mutex_unlock(&acm->mutex);
1219 return rv; 1325 return rv;
1220} 1326}
1327
1328#endif /* CONFIG_PM */
1221/* 1329/*
1222 * USB driver structure. 1330 * USB driver structure.
1223 */ 1331 */
@@ -1273,10 +1381,14 @@ static struct usb_driver acm_driver = {
1273 .name = "cdc_acm", 1381 .name = "cdc_acm",
1274 .probe = acm_probe, 1382 .probe = acm_probe,
1275 .disconnect = acm_disconnect, 1383 .disconnect = acm_disconnect,
1384#ifdef CONFIG_PM
1276 .suspend = acm_suspend, 1385 .suspend = acm_suspend,
1277 .resume = acm_resume, 1386 .resume = acm_resume,
1387#endif
1278 .id_table = acm_ids, 1388 .id_table = acm_ids,
1389#ifdef CONFIG_PM
1279 .supports_autosuspend = 1, 1390 .supports_autosuspend = 1,
1391#endif
1280}; 1392};
1281 1393
1282/* 1394/*
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index 046e064b033a..85c3aaaab7c5 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -107,10 +107,14 @@ struct acm {
107 struct list_head filled_read_bufs; 107 struct list_head filled_read_bufs;
108 int write_used; /* number of non-empty write buffers */ 108 int write_used; /* number of non-empty write buffers */
109 int write_ready; /* write urb is not running */ 109 int write_ready; /* write urb is not running */
110 int old_ready;
111 int processing;
112 int transmitting;
110 spinlock_t write_lock; 113 spinlock_t write_lock;
111 struct mutex mutex; 114 struct mutex mutex;
112 struct usb_cdc_line_coding line; /* bits, stop, parity */ 115 struct usb_cdc_line_coding line; /* bits, stop, parity */
113 struct work_struct work; /* work queue entry for line discipline waking up */ 116 struct work_struct work; /* work queue entry for line discipline waking up */
117 struct work_struct waker;
114 struct tasklet_struct urb_task; /* rx processing */ 118 struct tasklet_struct urb_task; /* rx processing */
115 spinlock_t throttle_lock; /* synchronize throtteling and read callback */ 119 spinlock_t throttle_lock; /* synchronize throtteling and read callback */
116 unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */ 120 unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */
@@ -123,6 +127,7 @@ struct acm {
123 unsigned char clocal; /* termios CLOCAL */ 127 unsigned char clocal; /* termios CLOCAL */
124 unsigned int ctrl_caps; /* control capabilities from the class specific header */ 128 unsigned int ctrl_caps; /* control capabilities from the class specific header */
125 unsigned int susp_count; /* number of suspended interfaces */ 129 unsigned int susp_count; /* number of suspended interfaces */
130 struct acm_wb *delayed_wb; /* write queued for a device about to be woken */
126}; 131};
127 132
128#define CDC_DATA_INTERFACE_TYPE 0x0a 133#define CDC_DATA_INTERFACE_TYPE 0x0a
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 731db051070a..7e8e1235e4e5 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -28,8 +28,9 @@
28/* 28/*
29 * Version Information 29 * Version Information
30 */ 30 */
31#define DRIVER_VERSION "v0.02" 31#define DRIVER_VERSION "v0.03"
32#define DRIVER_AUTHOR "Oliver Neukum" 32#define DRIVER_AUTHOR "Oliver Neukum"
33#define DRIVER_DESC "USB Abstract Control Model driver for USB WCM Device Management"
33 34
34static struct usb_device_id wdm_ids[] = { 35static struct usb_device_id wdm_ids[] = {
35 { 36 {
@@ -87,6 +88,7 @@ struct wdm_device {
87 dma_addr_t ihandle; 88 dma_addr_t ihandle;
88 struct mutex wlock; 89 struct mutex wlock;
89 struct mutex rlock; 90 struct mutex rlock;
91 struct mutex plock;
90 wait_queue_head_t wait; 92 wait_queue_head_t wait;
91 struct work_struct rxwork; 93 struct work_struct rxwork;
92 int werr; 94 int werr;
@@ -205,7 +207,7 @@ static void wdm_int_callback(struct urb *urb)
205 req->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE; 207 req->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE;
206 req->wValue = 0; 208 req->wValue = 0;
207 req->wIndex = desc->inum; 209 req->wIndex = desc->inum;
208 req->wLength = cpu_to_le16(desc->bMaxPacketSize0); 210 req->wLength = cpu_to_le16(desc->wMaxCommand);
209 211
210 usb_fill_control_urb( 212 usb_fill_control_urb(
211 desc->response, 213 desc->response,
@@ -214,7 +216,7 @@ static void wdm_int_callback(struct urb *urb)
214 usb_rcvctrlpipe(interface_to_usbdev(desc->intf), 0), 216 usb_rcvctrlpipe(interface_to_usbdev(desc->intf), 0),
215 (unsigned char *)req, 217 (unsigned char *)req,
216 desc->inbuf, 218 desc->inbuf,
217 desc->bMaxPacketSize0, 219 desc->wMaxCommand,
218 wdm_in_callback, 220 wdm_in_callback,
219 desc 221 desc
220 ); 222 );
@@ -247,6 +249,7 @@ exit:
247 249
248static void kill_urbs(struct wdm_device *desc) 250static void kill_urbs(struct wdm_device *desc)
249{ 251{
252 /* the order here is essential */
250 usb_kill_urb(desc->command); 253 usb_kill_urb(desc->command);
251 usb_kill_urb(desc->validity); 254 usb_kill_urb(desc->validity);
252 usb_kill_urb(desc->response); 255 usb_kill_urb(desc->response);
@@ -266,7 +269,7 @@ static void cleanup(struct wdm_device *desc)
266 desc->sbuf, 269 desc->sbuf,
267 desc->validity->transfer_dma); 270 desc->validity->transfer_dma);
268 usb_buffer_free(interface_to_usbdev(desc->intf), 271 usb_buffer_free(interface_to_usbdev(desc->intf),
269 desc->wMaxPacketSize, 272 desc->wMaxCommand,
270 desc->inbuf, 273 desc->inbuf,
271 desc->response->transfer_dma); 274 desc->response->transfer_dma);
272 kfree(desc->orq); 275 kfree(desc->orq);
@@ -299,6 +302,9 @@ static ssize_t wdm_write
299 if (r) 302 if (r)
300 goto outnl; 303 goto outnl;
301 304
305 r = usb_autopm_get_interface(desc->intf);
306 if (r < 0)
307 goto outnp;
302 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE, 308 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
303 &desc->flags)); 309 &desc->flags));
304 if (r < 0) 310 if (r < 0)
@@ -347,11 +353,14 @@ static ssize_t wdm_write
347 if (rv < 0) { 353 if (rv < 0) {
348 kfree(buf); 354 kfree(buf);
349 clear_bit(WDM_IN_USE, &desc->flags); 355 clear_bit(WDM_IN_USE, &desc->flags);
356 err("Tx URB error: %d", rv);
350 } else { 357 } else {
351 dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d", 358 dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d",
352 req->wIndex); 359 req->wIndex);
353 } 360 }
354out: 361out:
362 usb_autopm_put_interface(desc->intf);
363outnp:
355 mutex_unlock(&desc->wlock); 364 mutex_unlock(&desc->wlock);
356outnl: 365outnl:
357 return rv < 0 ? rv : count; 366 return rv < 0 ? rv : count;
@@ -376,6 +385,11 @@ retry:
376 rv = wait_event_interruptible(desc->wait, 385 rv = wait_event_interruptible(desc->wait,
377 test_bit(WDM_READ, &desc->flags)); 386 test_bit(WDM_READ, &desc->flags));
378 387
388 if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
389 rv = -ENODEV;
390 goto err;
391 }
392 usb_mark_last_busy(interface_to_usbdev(desc->intf));
379 if (rv < 0) { 393 if (rv < 0) {
380 rv = -ERESTARTSYS; 394 rv = -ERESTARTSYS;
381 goto err; 395 goto err;
@@ -418,6 +432,9 @@ retry:
418 desc->ubuf[i] = desc->ubuf[i + cntr]; 432 desc->ubuf[i] = desc->ubuf[i + cntr];
419 433
420 desc->length -= cntr; 434 desc->length -= cntr;
435 /* in case we had outstanding data */
436 if (!desc->length)
437 clear_bit(WDM_READ, &desc->flags);
421 rv = cntr; 438 rv = cntr;
422 439
423err: 440err:
@@ -480,18 +497,28 @@ static int wdm_open(struct inode *inode, struct file *file)
480 if (test_bit(WDM_DISCONNECTING, &desc->flags)) 497 if (test_bit(WDM_DISCONNECTING, &desc->flags))
481 goto out; 498 goto out;
482 499
483 desc->count++; 500 ;
484 file->private_data = desc; 501 file->private_data = desc;
485 502
486 rv = usb_submit_urb(desc->validity, GFP_KERNEL); 503 rv = usb_autopm_get_interface(desc->intf);
487
488 if (rv < 0) { 504 if (rv < 0) {
489 desc->count--; 505 err("Error autopm - %d", rv);
490 err("Error submitting int urb - %d", rv);
491 goto out; 506 goto out;
492 } 507 }
493 rv = 0; 508 intf->needs_remote_wakeup = 1;
494 509
510 mutex_lock(&desc->plock);
511 if (!desc->count++) {
512 rv = usb_submit_urb(desc->validity, GFP_KERNEL);
513 if (rv < 0) {
514 desc->count--;
515 err("Error submitting int urb - %d", rv);
516 }
517 } else {
518 rv = 0;
519 }
520 mutex_unlock(&desc->plock);
521 usb_autopm_put_interface(desc->intf);
495out: 522out:
496 mutex_unlock(&wdm_mutex); 523 mutex_unlock(&wdm_mutex);
497 return rv; 524 return rv;
@@ -502,10 +529,15 @@ static int wdm_release(struct inode *inode, struct file *file)
502 struct wdm_device *desc = file->private_data; 529 struct wdm_device *desc = file->private_data;
503 530
504 mutex_lock(&wdm_mutex); 531 mutex_lock(&wdm_mutex);
532 mutex_lock(&desc->plock);
505 desc->count--; 533 desc->count--;
534 mutex_unlock(&desc->plock);
535
506 if (!desc->count) { 536 if (!desc->count) {
507 dev_dbg(&desc->intf->dev, "wdm_release: cleanup"); 537 dev_dbg(&desc->intf->dev, "wdm_release: cleanup");
508 kill_urbs(desc); 538 kill_urbs(desc);
539 if (!test_bit(WDM_DISCONNECTING, &desc->flags))
540 desc->intf->needs_remote_wakeup = 0;
509 } 541 }
510 mutex_unlock(&wdm_mutex); 542 mutex_unlock(&wdm_mutex);
511 return 0; 543 return 0;
@@ -597,6 +629,7 @@ next_desc:
597 goto out; 629 goto out;
598 mutex_init(&desc->wlock); 630 mutex_init(&desc->wlock);
599 mutex_init(&desc->rlock); 631 mutex_init(&desc->rlock);
632 mutex_init(&desc->plock);
600 spin_lock_init(&desc->iuspin); 633 spin_lock_init(&desc->iuspin);
601 init_waitqueue_head(&desc->wait); 634 init_waitqueue_head(&desc->wait);
602 desc->wMaxCommand = maxcom; 635 desc->wMaxCommand = maxcom;
@@ -698,6 +731,7 @@ static void wdm_disconnect(struct usb_interface *intf)
698 spin_lock_irqsave(&desc->iuspin, flags); 731 spin_lock_irqsave(&desc->iuspin, flags);
699 set_bit(WDM_DISCONNECTING, &desc->flags); 732 set_bit(WDM_DISCONNECTING, &desc->flags);
700 set_bit(WDM_READ, &desc->flags); 733 set_bit(WDM_READ, &desc->flags);
734 /* to terminate pending flushes */
701 clear_bit(WDM_IN_USE, &desc->flags); 735 clear_bit(WDM_IN_USE, &desc->flags);
702 spin_unlock_irqrestore(&desc->iuspin, flags); 736 spin_unlock_irqrestore(&desc->iuspin, flags);
703 cancel_work_sync(&desc->rxwork); 737 cancel_work_sync(&desc->rxwork);
@@ -708,11 +742,81 @@ static void wdm_disconnect(struct usb_interface *intf)
708 mutex_unlock(&wdm_mutex); 742 mutex_unlock(&wdm_mutex);
709} 743}
710 744
745static int wdm_suspend(struct usb_interface *intf, pm_message_t message)
746{
747 struct wdm_device *desc = usb_get_intfdata(intf);
748 int rv = 0;
749
750 dev_dbg(&desc->intf->dev, "wdm%d_suspend\n", intf->minor);
751
752 mutex_lock(&desc->plock);
753#ifdef CONFIG_PM
754 if (interface_to_usbdev(desc->intf)->auto_pm && test_bit(WDM_IN_USE, &desc->flags)) {
755 rv = -EBUSY;
756 } else {
757#endif
758 cancel_work_sync(&desc->rxwork);
759 kill_urbs(desc);
760#ifdef CONFIG_PM
761 }
762#endif
763 mutex_unlock(&desc->plock);
764
765 return rv;
766}
767
768static int recover_from_urb_loss(struct wdm_device *desc)
769{
770 int rv = 0;
771
772 if (desc->count) {
773 rv = usb_submit_urb(desc->validity, GFP_NOIO);
774 if (rv < 0)
775 err("Error resume submitting int urb - %d", rv);
776 }
777 return rv;
778}
779static int wdm_resume(struct usb_interface *intf)
780{
781 struct wdm_device *desc = usb_get_intfdata(intf);
782 int rv;
783
784 dev_dbg(&desc->intf->dev, "wdm%d_resume\n", intf->minor);
785 mutex_lock(&desc->plock);
786 rv = recover_from_urb_loss(desc);
787 mutex_unlock(&desc->plock);
788 return rv;
789}
790
791static int wdm_pre_reset(struct usb_interface *intf)
792{
793 struct wdm_device *desc = usb_get_intfdata(intf);
794
795 mutex_lock(&desc->plock);
796 return 0;
797}
798
799static int wdm_post_reset(struct usb_interface *intf)
800{
801 struct wdm_device *desc = usb_get_intfdata(intf);
802 int rv;
803
804 rv = recover_from_urb_loss(desc);
805 mutex_unlock(&desc->plock);
806 return 0;
807}
808
711static struct usb_driver wdm_driver = { 809static struct usb_driver wdm_driver = {
712 .name = "cdc_wdm", 810 .name = "cdc_wdm",
713 .probe = wdm_probe, 811 .probe = wdm_probe,
714 .disconnect = wdm_disconnect, 812 .disconnect = wdm_disconnect,
813 .suspend = wdm_suspend,
814 .resume = wdm_resume,
815 .reset_resume = wdm_resume,
816 .pre_reset = wdm_pre_reset,
817 .post_reset = wdm_post_reset,
715 .id_table = wdm_ids, 818 .id_table = wdm_ids,
819 .supports_autosuspend = 1,
716}; 820};
717 821
718/* --- low level module stuff --- */ 822/* --- low level module stuff --- */
@@ -735,6 +839,5 @@ module_init(wdm_init);
735module_exit(wdm_exit); 839module_exit(wdm_exit);
736 840
737MODULE_AUTHOR(DRIVER_AUTHOR); 841MODULE_AUTHOR(DRIVER_AUTHOR);
738MODULE_DESCRIPTION("USB Abstract Control Model driver for " 842MODULE_DESCRIPTION(DRIVER_DESC);
739 "USB WCM Device Management");
740MODULE_LICENSE("GPL"); 843MODULE_LICENSE("GPL");
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index 83d9dc379d96..6ec38175a817 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -46,8 +46,6 @@
46 * 2000-07-05: Ashley Montanaro <ashley@compsoc.man.ac.uk> 46 * 2000-07-05: Ashley Montanaro <ashley@compsoc.man.ac.uk>
47 * Converted file reading routine to dump to buffer once 47 * Converted file reading routine to dump to buffer once
48 * per device, not per bus 48 * per device, not per bus
49 *
50 * $Id: devices.c,v 1.5 2000/01/11 13:58:21 tom Exp $
51 */ 49 */
52 50
53#include <linux/fs.h> 51#include <linux/fs.h>
@@ -63,8 +61,6 @@
63#include "usb.h" 61#include "usb.h"
64#include "hcd.h" 62#include "hcd.h"
65 63
66#define MAX_TOPO_LEVEL 6
67
68/* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */ 64/* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */
69#define ALLOW_SERIAL_NUMBER 65#define ALLOW_SERIAL_NUMBER
70 66
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 9218cca21043..20290c5b1562 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -19,8 +19,6 @@
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 21 *
22 * $Id: devio.c,v 1.7 2000/02/01 17:28:48 fliegl Exp $
23 *
24 * This file implements the usbfs/x/y files, where 22 * This file implements the usbfs/x/y files, where
25 * x is the bus number and y the device number. 23 * x is the bus number and y the device number.
26 * 24 *
@@ -61,6 +59,22 @@
61/* Mutual exclusion for removal, open, and release */ 59/* Mutual exclusion for removal, open, and release */
62DEFINE_MUTEX(usbfs_mutex); 60DEFINE_MUTEX(usbfs_mutex);
63 61
62struct dev_state {
63 struct list_head list; /* state list */
64 struct usb_device *dev;
65 struct file *file;
66 spinlock_t lock; /* protects the async urb lists */
67 struct list_head async_pending;
68 struct list_head async_completed;
69 wait_queue_head_t wait; /* wake up if a request completed */
70 unsigned int discsignr;
71 struct pid *disc_pid;
72 uid_t disc_uid, disc_euid;
73 void __user *disccontext;
74 unsigned long ifclaimed;
75 u32 secid;
76};
77
64struct async { 78struct async {
65 struct list_head asynclist; 79 struct list_head asynclist;
66 struct dev_state *ps; 80 struct dev_state *ps;
@@ -536,23 +550,19 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype,
536 return ret; 550 return ret;
537} 551}
538 552
539static int __match_minor(struct device *dev, void *data) 553static int match_devt(struct device *dev, void *data)
540{ 554{
541 int minor = *((int *)data); 555 return dev->devt == (dev_t) (unsigned long) data;
542
543 if (dev->devt == MKDEV(USB_DEVICE_MAJOR, minor))
544 return 1;
545 return 0;
546} 556}
547 557
548static struct usb_device *usbdev_lookup_by_minor(int minor) 558static struct usb_device *usbdev_lookup_by_devt(dev_t devt)
549{ 559{
550 struct device *dev; 560 struct device *dev;
551 561
552 dev = bus_find_device(&usb_bus_type, NULL, &minor, __match_minor); 562 dev = bus_find_device(&usb_bus_type, NULL,
563 (void *) (unsigned long) devt, match_devt);
553 if (!dev) 564 if (!dev)
554 return NULL; 565 return NULL;
555 put_device(dev);
556 return container_of(dev, struct usb_device, dev); 566 return container_of(dev, struct usb_device, dev);
557} 567}
558 568
@@ -575,21 +585,27 @@ static int usbdev_open(struct inode *inode, struct file *file)
575 goto out; 585 goto out;
576 586
577 ret = -ENOENT; 587 ret = -ENOENT;
588
578 /* usbdev device-node */ 589 /* usbdev device-node */
579 if (imajor(inode) == USB_DEVICE_MAJOR) 590 if (imajor(inode) == USB_DEVICE_MAJOR)
580 dev = usbdev_lookup_by_minor(iminor(inode)); 591 dev = usbdev_lookup_by_devt(inode->i_rdev);
581#ifdef CONFIG_USB_DEVICEFS 592#ifdef CONFIG_USB_DEVICEFS
582 /* procfs file */ 593 /* procfs file */
583 if (!dev) 594 if (!dev) {
584 dev = inode->i_private; 595 dev = inode->i_private;
596 if (dev && dev->usbfs_dentry &&
597 dev->usbfs_dentry->d_inode == inode)
598 usb_get_dev(dev);
599 else
600 dev = NULL;
601 }
585#endif 602#endif
586 if (!dev) 603 if (!dev || dev->state == USB_STATE_NOTATTACHED)
587 goto out; 604 goto out;
588 ret = usb_autoresume_device(dev); 605 ret = usb_autoresume_device(dev);
589 if (ret) 606 if (ret)
590 goto out; 607 goto out;
591 608
592 usb_get_dev(dev);
593 ret = 0; 609 ret = 0;
594 ps->dev = dev; 610 ps->dev = dev;
595 ps->file = file; 611 ps->file = file;
@@ -609,8 +625,10 @@ static int usbdev_open(struct inode *inode, struct file *file)
609 list_add_tail(&ps->list, &dev->filelist); 625 list_add_tail(&ps->list, &dev->filelist);
610 file->private_data = ps; 626 file->private_data = ps;
611 out: 627 out:
612 if (ret) 628 if (ret) {
613 kfree(ps); 629 kfree(ps);
630 usb_put_dev(dev);
631 }
614 mutex_unlock(&usbfs_mutex); 632 mutex_unlock(&usbfs_mutex);
615 unlock_kernel(); 633 unlock_kernel();
616 return ret; 634 return ret;
@@ -874,7 +892,7 @@ static int proc_connectinfo(struct dev_state *ps, void __user *arg)
874 892
875static int proc_resetdevice(struct dev_state *ps) 893static int proc_resetdevice(struct dev_state *ps)
876{ 894{
877 return usb_reset_composite_device(ps->dev, NULL); 895 return usb_reset_device(ps->dev);
878} 896}
879 897
880static int proc_setintf(struct dev_state *ps, void __user *arg) 898static int proc_setintf(struct dev_state *ps, void __user *arg)
@@ -1682,25 +1700,49 @@ const struct file_operations usbdev_file_operations = {
1682 .release = usbdev_release, 1700 .release = usbdev_release,
1683}; 1701};
1684 1702
1703void usb_fs_classdev_common_remove(struct usb_device *udev)
1704{
1705 struct dev_state *ps;
1706 struct siginfo sinfo;
1707
1708 while (!list_empty(&udev->filelist)) {
1709 ps = list_entry(udev->filelist.next, struct dev_state, list);
1710 destroy_all_async(ps);
1711 wake_up_all(&ps->wait);
1712 list_del_init(&ps->list);
1713 if (ps->discsignr) {
1714 sinfo.si_signo = ps->discsignr;
1715 sinfo.si_errno = EPIPE;
1716 sinfo.si_code = SI_ASYNCIO;
1717 sinfo.si_addr = ps->disccontext;
1718 kill_pid_info_as_uid(ps->discsignr, &sinfo,
1719 ps->disc_pid, ps->disc_uid,
1720 ps->disc_euid, ps->secid);
1721 }
1722 }
1723}
1724
1685#ifdef CONFIG_USB_DEVICE_CLASS 1725#ifdef CONFIG_USB_DEVICE_CLASS
1686static struct class *usb_classdev_class; 1726static struct class *usb_classdev_class;
1687 1727
1688static int usb_classdev_add(struct usb_device *dev) 1728static int usb_classdev_add(struct usb_device *dev)
1689{ 1729{
1690 int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1); 1730 struct device *cldev;
1691 1731
1692 dev->usb_classdev = device_create(usb_classdev_class, &dev->dev, 1732 cldev = device_create_drvdata(usb_classdev_class, &dev->dev,
1693 MKDEV(USB_DEVICE_MAJOR, minor), 1733 dev->dev.devt, NULL, "usbdev%d.%d",
1694 "usbdev%d.%d", dev->bus->busnum, dev->devnum); 1734 dev->bus->busnum, dev->devnum);
1695 if (IS_ERR(dev->usb_classdev)) 1735 if (IS_ERR(cldev))
1696 return PTR_ERR(dev->usb_classdev); 1736 return PTR_ERR(cldev);
1697 1737 dev->usb_classdev = cldev;
1698 return 0; 1738 return 0;
1699} 1739}
1700 1740
1701static void usb_classdev_remove(struct usb_device *dev) 1741static void usb_classdev_remove(struct usb_device *dev)
1702{ 1742{
1703 device_unregister(dev->usb_classdev); 1743 if (dev->usb_classdev)
1744 device_unregister(dev->usb_classdev);
1745 usb_fs_classdev_common_remove(dev);
1704} 1746}
1705 1747
1706static int usb_classdev_notify(struct notifier_block *self, 1748static int usb_classdev_notify(struct notifier_block *self,
@@ -1750,6 +1792,11 @@ int __init usb_devio_init(void)
1750 usb_classdev_class = NULL; 1792 usb_classdev_class = NULL;
1751 goto out; 1793 goto out;
1752 } 1794 }
1795 /* devices of this class shadow the major:minor of their parent
1796 * device, so clear ->dev_kobj to prevent adding duplicate entries
1797 * to /sys/dev
1798 */
1799 usb_classdev_class->dev_kobj = NULL;
1753 1800
1754 usb_register_notify(&usbdev_nb); 1801 usb_register_notify(&usbdev_nb);
1755#endif 1802#endif
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 1e56f1cfa6dc..ddb54e14a5c5 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -201,6 +201,7 @@ static int usb_probe_interface(struct device *dev)
201 201
202 intf = to_usb_interface(dev); 202 intf = to_usb_interface(dev);
203 udev = interface_to_usbdev(intf); 203 udev = interface_to_usbdev(intf);
204 intf->needs_binding = 0;
204 205
205 if (udev->authorized == 0) { 206 if (udev->authorized == 0) {
206 dev_err(&intf->dev, "Device is not authorized for usage\n"); 207 dev_err(&intf->dev, "Device is not authorized for usage\n");
@@ -257,15 +258,16 @@ static int usb_unbind_interface(struct device *dev)
257 udev = interface_to_usbdev(intf); 258 udev = interface_to_usbdev(intf);
258 error = usb_autoresume_device(udev); 259 error = usb_autoresume_device(udev);
259 260
260 /* release all urbs for this interface */ 261 /* Terminate all URBs for this interface unless the driver
261 usb_disable_interface(interface_to_usbdev(intf), intf); 262 * supports "soft" unbinding.
263 */
264 if (!driver->soft_unbind)
265 usb_disable_interface(udev, intf);
262 266
263 driver->disconnect(intf); 267 driver->disconnect(intf);
264 268
265 /* reset other interface state */ 269 /* reset other interface state */
266 usb_set_interface(interface_to_usbdev(intf), 270 usb_set_interface(udev, intf->altsetting[0].desc.bInterfaceNumber, 0);
267 intf->altsetting[0].desc.bInterfaceNumber,
268 0);
269 usb_set_intfdata(intf, NULL); 271 usb_set_intfdata(intf, NULL);
270 272
271 intf->condition = USB_INTERFACE_UNBOUND; 273 intf->condition = USB_INTERFACE_UNBOUND;
@@ -310,6 +312,7 @@ int usb_driver_claim_interface(struct usb_driver *driver,
310 312
311 dev->driver = &driver->drvwrap.driver; 313 dev->driver = &driver->drvwrap.driver;
312 usb_set_intfdata(iface, priv); 314 usb_set_intfdata(iface, priv);
315 iface->needs_binding = 0;
313 316
314 usb_pm_lock(udev); 317 usb_pm_lock(udev);
315 iface->condition = USB_INTERFACE_BOUND; 318 iface->condition = USB_INTERFACE_BOUND;
@@ -586,7 +589,7 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
586 struct usb_device *usb_dev; 589 struct usb_device *usb_dev;
587 590
588 /* driver is often null here; dev_dbg() would oops */ 591 /* driver is often null here; dev_dbg() would oops */
589 pr_debug("usb %s: uevent\n", dev->bus_id); 592 pr_debug("usb %s: uevent\n", dev_name(dev));
590 593
591 if (is_usb_device(dev)) 594 if (is_usb_device(dev))
592 usb_dev = to_usb_device(dev); 595 usb_dev = to_usb_device(dev);
@@ -596,11 +599,11 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
596 } 599 }
597 600
598 if (usb_dev->devnum < 0) { 601 if (usb_dev->devnum < 0) {
599 pr_debug("usb %s: already deleted?\n", dev->bus_id); 602 pr_debug("usb %s: already deleted?\n", dev_name(dev));
600 return -ENODEV; 603 return -ENODEV;
601 } 604 }
602 if (!usb_dev->bus) { 605 if (!usb_dev->bus) {
603 pr_debug("usb %s: bus removed?\n", dev->bus_id); 606 pr_debug("usb %s: bus removed?\n", dev_name(dev));
604 return -ENODEV; 607 return -ENODEV;
605 } 608 }
606 609
@@ -771,6 +774,104 @@ void usb_deregister(struct usb_driver *driver)
771} 774}
772EXPORT_SYMBOL_GPL(usb_deregister); 775EXPORT_SYMBOL_GPL(usb_deregister);
773 776
777
778/* Forced unbinding of a USB interface driver, either because
779 * it doesn't support pre_reset/post_reset/reset_resume or
780 * because it doesn't support suspend/resume.
781 *
782 * The caller must hold @intf's device's lock, but not its pm_mutex
783 * and not @intf->dev.sem.
784 */
785void usb_forced_unbind_intf(struct usb_interface *intf)
786{
787 struct usb_driver *driver = to_usb_driver(intf->dev.driver);
788
789 dev_dbg(&intf->dev, "forced unbind\n");
790 usb_driver_release_interface(driver, intf);
791
792 /* Mark the interface for later rebinding */
793 intf->needs_binding = 1;
794}
795
796/* Delayed forced unbinding of a USB interface driver and scan
797 * for rebinding.
798 *
799 * The caller must hold @intf's device's lock, but not its pm_mutex
800 * and not @intf->dev.sem.
801 *
802 * FIXME: The caller must block system sleep transitions.
803 */
804void usb_rebind_intf(struct usb_interface *intf)
805{
806 int rc;
807
808 /* Delayed unbind of an existing driver */
809 if (intf->dev.driver) {
810 struct usb_driver *driver =
811 to_usb_driver(intf->dev.driver);
812
813 dev_dbg(&intf->dev, "forced unbind\n");
814 usb_driver_release_interface(driver, intf);
815 }
816
817 /* Try to rebind the interface */
818 intf->needs_binding = 0;
819 rc = device_attach(&intf->dev);
820 if (rc < 0)
821 dev_warn(&intf->dev, "rebind failed: %d\n", rc);
822}
823
824#define DO_UNBIND 0
825#define DO_REBIND 1
826
827/* Unbind drivers for @udev's interfaces that don't support suspend/resume,
828 * or rebind interfaces that have been unbound, according to @action.
829 *
830 * The caller must hold @udev's device lock.
831 * FIXME: For rebinds, the caller must block system sleep transitions.
832 */
833static void do_unbind_rebind(struct usb_device *udev, int action)
834{
835 struct usb_host_config *config;
836 int i;
837 struct usb_interface *intf;
838 struct usb_driver *drv;
839
840 config = udev->actconfig;
841 if (config) {
842 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
843 intf = config->interface[i];
844 switch (action) {
845 case DO_UNBIND:
846 if (intf->dev.driver) {
847 drv = to_usb_driver(intf->dev.driver);
848 if (!drv->suspend || !drv->resume)
849 usb_forced_unbind_intf(intf);
850 }
851 break;
852 case DO_REBIND:
853 if (intf->needs_binding) {
854
855 /* FIXME: The next line is needed because we are going to probe
856 * the interface, but as far as the PM core is concerned the
857 * interface is still suspended. The problem wouldn't exist
858 * if we could rebind the interface during the interface's own
859 * resume() call, but at the time the usb_device isn't locked!
860 *
861 * The real solution will be to carry this out during the device's
862 * complete() callback. Until that is implemented, we have to
863 * use this hack.
864 */
865// intf->dev.power.sleeping = 0;
866
867 usb_rebind_intf(intf);
868 }
869 break;
870 }
871 }
872 }
873}
874
774#ifdef CONFIG_PM 875#ifdef CONFIG_PM
775 876
776/* Caller has locked udev's pm_mutex */ 877/* Caller has locked udev's pm_mutex */
@@ -805,8 +906,6 @@ static int usb_resume_device(struct usb_device *udev)
805 906
806 if (udev->state == USB_STATE_NOTATTACHED) 907 if (udev->state == USB_STATE_NOTATTACHED)
807 goto done; 908 goto done;
808 if (udev->state != USB_STATE_SUSPENDED && !udev->reset_resume)
809 goto done;
810 909
811 /* Can't resume it if it doesn't have a driver. */ 910 /* Can't resume it if it doesn't have a driver. */
812 if (udev->dev.driver == NULL) { 911 if (udev->dev.driver == NULL) {
@@ -842,7 +941,7 @@ static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg)
842 goto done; 941 goto done;
843 driver = to_usb_driver(intf->dev.driver); 942 driver = to_usb_driver(intf->dev.driver);
844 943
845 if (driver->suspend && driver->resume) { 944 if (driver->suspend) {
846 status = driver->suspend(intf, msg); 945 status = driver->suspend(intf, msg);
847 if (status == 0) 946 if (status == 0)
848 mark_quiesced(intf); 947 mark_quiesced(intf);
@@ -850,12 +949,10 @@ static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg)
850 dev_err(&intf->dev, "%s error %d\n", 949 dev_err(&intf->dev, "%s error %d\n",
851 "suspend", status); 950 "suspend", status);
852 } else { 951 } else {
853 /* 952 /* Later we will unbind the driver and reprobe */
854 * FIXME else if there's no suspend method, disconnect... 953 intf->needs_binding = 1;
855 * Not possible if auto_pm is set... 954 dev_warn(&intf->dev, "no %s for driver %s?\n",
856 */ 955 "suspend", driver->name);
857 dev_warn(&intf->dev, "no suspend for driver %s?\n",
858 driver->name);
859 mark_quiesced(intf); 956 mark_quiesced(intf);
860 } 957 }
861 958
@@ -879,10 +976,12 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume)
879 goto done; 976 goto done;
880 977
881 /* Can't resume it if it doesn't have a driver. */ 978 /* Can't resume it if it doesn't have a driver. */
882 if (intf->condition == USB_INTERFACE_UNBOUND) { 979 if (intf->condition == USB_INTERFACE_UNBOUND)
883 status = -ENOTCONN; 980 goto done;
981
982 /* Don't resume if the interface is marked for rebinding */
983 if (intf->needs_binding)
884 goto done; 984 goto done;
885 }
886 driver = to_usb_driver(intf->dev.driver); 985 driver = to_usb_driver(intf->dev.driver);
887 986
888 if (reset_resume) { 987 if (reset_resume) {
@@ -892,7 +991,7 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume)
892 dev_err(&intf->dev, "%s error %d\n", 991 dev_err(&intf->dev, "%s error %d\n",
893 "reset_resume", status); 992 "reset_resume", status);
894 } else { 993 } else {
895 /* status = -EOPNOTSUPP; */ 994 intf->needs_binding = 1;
896 dev_warn(&intf->dev, "no %s for driver %s?\n", 995 dev_warn(&intf->dev, "no %s for driver %s?\n",
897 "reset_resume", driver->name); 996 "reset_resume", driver->name);
898 } 997 }
@@ -903,7 +1002,7 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume)
903 dev_err(&intf->dev, "%s error %d\n", 1002 dev_err(&intf->dev, "%s error %d\n",
904 "resume", status); 1003 "resume", status);
905 } else { 1004 } else {
906 /* status = -EOPNOTSUPP; */ 1005 intf->needs_binding = 1;
907 dev_warn(&intf->dev, "no %s for driver %s?\n", 1006 dev_warn(&intf->dev, "no %s for driver %s?\n",
908 "resume", driver->name); 1007 "resume", driver->name);
909 } 1008 }
@@ -911,11 +1010,10 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume)
911 1010
912done: 1011done:
913 dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status); 1012 dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status);
914 if (status == 0) 1013 if (status == 0 && intf->condition == USB_INTERFACE_BOUND)
915 mark_active(intf); 1014 mark_active(intf);
916 1015
917 /* FIXME: Unbind the driver and reprobe if the resume failed 1016 /* Later we will unbind the driver and/or reprobe, if necessary */
918 * (not possible if auto_pm is set) */
919 return status; 1017 return status;
920} 1018}
921 1019
@@ -1173,11 +1271,8 @@ static int usb_resume_both(struct usb_device *udev)
1173 * then we're stuck. */ 1271 * then we're stuck. */
1174 status = usb_resume_device(udev); 1272 status = usb_resume_device(udev);
1175 } 1273 }
1176 } else { 1274 } else if (udev->reset_resume)
1177
1178 /* Needed for reset-resume */
1179 status = usb_resume_device(udev); 1275 status = usb_resume_device(udev);
1180 }
1181 1276
1182 if (status == 0 && udev->actconfig) { 1277 if (status == 0 && udev->actconfig) {
1183 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { 1278 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
@@ -1474,6 +1569,7 @@ int usb_external_suspend_device(struct usb_device *udev, pm_message_t msg)
1474{ 1569{
1475 int status; 1570 int status;
1476 1571
1572 do_unbind_rebind(udev, DO_UNBIND);
1477 usb_pm_lock(udev); 1573 usb_pm_lock(udev);
1478 udev->auto_pm = 0; 1574 udev->auto_pm = 0;
1479 status = usb_suspend_both(udev, msg); 1575 status = usb_suspend_both(udev, msg);
@@ -1501,6 +1597,7 @@ int usb_external_resume_device(struct usb_device *udev)
1501 status = usb_resume_both(udev); 1597 status = usb_resume_both(udev);
1502 udev->last_busy = jiffies; 1598 udev->last_busy = jiffies;
1503 usb_pm_unlock(udev); 1599 usb_pm_unlock(udev);
1600 do_unbind_rebind(udev, DO_REBIND);
1504 1601
1505 /* Now that the device is awake, we can start trying to autosuspend 1602 /* Now that the device is awake, we can start trying to autosuspend
1506 * it again. */ 1603 * it again. */
@@ -1542,14 +1639,11 @@ static int usb_resume(struct device *dev)
1542 udev = to_usb_device(dev); 1639 udev = to_usb_device(dev);
1543 1640
1544 /* If udev->skip_sys_resume is set then udev was already suspended 1641 /* If udev->skip_sys_resume is set then udev was already suspended
1545 * when the system suspend started, so we don't want to resume 1642 * when the system sleep started, so we don't want to resume it
1546 * udev during this system wakeup. However a reset-resume counts 1643 * during this system wakeup.
1547 * as a wakeup event, so allow a reset-resume to occur if remote 1644 */
1548 * wakeup is enabled. */ 1645 if (udev->skip_sys_resume)
1549 if (udev->skip_sys_resume) { 1646 return 0;
1550 if (!(udev->reset_resume && udev->do_remote_wakeup))
1551 return -EHOSTUNREACH;
1552 }
1553 return usb_external_resume_device(udev); 1647 return usb_external_resume_device(udev);
1554} 1648}
1555 1649
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index fae55a31e26d..22912136fc14 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -296,7 +296,7 @@ int usb_create_ep_files(struct device *parent,
296 retval = endpoint_get_minor(ep_dev); 296 retval = endpoint_get_minor(ep_dev);
297 if (retval) { 297 if (retval) {
298 dev_err(parent, "can not allocate minor number for %s\n", 298 dev_err(parent, "can not allocate minor number for %s\n",
299 ep_dev->dev.bus_id); 299 dev_name(&ep_dev->dev));
300 goto error_register; 300 goto error_register;
301 } 301 }
302 302
@@ -307,7 +307,7 @@ int usb_create_ep_files(struct device *parent,
307 ep_dev->dev.class = ep_class->class; 307 ep_dev->dev.class = ep_class->class;
308 ep_dev->dev.parent = parent; 308 ep_dev->dev.parent = parent;
309 ep_dev->dev.release = ep_device_release; 309 ep_dev->dev.release = ep_device_release;
310 snprintf(ep_dev->dev.bus_id, BUS_ID_SIZE, "usbdev%d.%d_ep%02x", 310 dev_set_name(&ep_dev->dev, "usbdev%d.%d_ep%02x",
311 udev->bus->busnum, udev->devnum, 311 udev->bus->busnum, udev->devnum,
312 endpoint->desc.bEndpointAddress); 312 endpoint->desc.bEndpointAddress);
313 313
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index c6a95395e52a..6b1b229e38cd 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -150,7 +150,7 @@ int usb_register_dev(struct usb_interface *intf,
150 int retval = -EINVAL; 150 int retval = -EINVAL;
151 int minor_base = class_driver->minor_base; 151 int minor_base = class_driver->minor_base;
152 int minor = 0; 152 int minor = 0;
153 char name[BUS_ID_SIZE]; 153 char name[20];
154 char *temp; 154 char *temp;
155 155
156#ifdef CONFIG_USB_DYNAMIC_MINORS 156#ifdef CONFIG_USB_DYNAMIC_MINORS
@@ -190,14 +190,15 @@ int usb_register_dev(struct usb_interface *intf,
190 intf->minor = minor; 190 intf->minor = minor;
191 191
192 /* create a usb class device for this usb interface */ 192 /* create a usb class device for this usb interface */
193 snprintf(name, BUS_ID_SIZE, class_driver->name, minor - minor_base); 193 snprintf(name, sizeof(name), class_driver->name, minor - minor_base);
194 temp = strrchr(name, '/'); 194 temp = strrchr(name, '/');
195 if (temp && (temp[1] != 0x00)) 195 if (temp && (temp[1] != '\0'))
196 ++temp; 196 ++temp;
197 else 197 else
198 temp = name; 198 temp = name;
199 intf->usb_dev = device_create(usb_class->class, &intf->dev, 199 intf->usb_dev = device_create_drvdata(usb_class->class, &intf->dev,
200 MKDEV(USB_MAJOR, minor), "%s", temp); 200 MKDEV(USB_MAJOR, minor), NULL,
201 "%s", temp);
201 if (IS_ERR(intf->usb_dev)) { 202 if (IS_ERR(intf->usb_dev)) {
202 down_write(&minor_rwsem); 203 down_write(&minor_rwsem);
203 usb_minors[intf->minor] = NULL; 204 usb_minors[intf->minor] = NULL;
@@ -227,7 +228,7 @@ void usb_deregister_dev(struct usb_interface *intf,
227 struct usb_class_driver *class_driver) 228 struct usb_class_driver *class_driver)
228{ 229{
229 int minor_base = class_driver->minor_base; 230 int minor_base = class_driver->minor_base;
230 char name[BUS_ID_SIZE]; 231 char name[20];
231 232
232#ifdef CONFIG_USB_DYNAMIC_MINORS 233#ifdef CONFIG_USB_DYNAMIC_MINORS
233 minor_base = 0; 234 minor_base = 0;
@@ -242,7 +243,7 @@ void usb_deregister_dev(struct usb_interface *intf,
242 usb_minors[intf->minor] = NULL; 243 usb_minors[intf->minor] = NULL;
243 up_write(&minor_rwsem); 244 up_write(&minor_rwsem);
244 245
245 snprintf(name, BUS_ID_SIZE, class_driver->name, intf->minor - minor_base); 246 snprintf(name, sizeof(name), class_driver->name, intf->minor - minor_base);
246 device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); 247 device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor));
247 intf->usb_dev = NULL; 248 intf->usb_dev = NULL;
248 intf->minor = -1; 249 intf->minor = -1;
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 42a436478b78..f7bfd72ef115 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -900,14 +900,14 @@ static int register_root_hub(struct usb_hcd *hcd)
900 if (retval != sizeof usb_dev->descriptor) { 900 if (retval != sizeof usb_dev->descriptor) {
901 mutex_unlock(&usb_bus_list_lock); 901 mutex_unlock(&usb_bus_list_lock);
902 dev_dbg (parent_dev, "can't read %s device descriptor %d\n", 902 dev_dbg (parent_dev, "can't read %s device descriptor %d\n",
903 usb_dev->dev.bus_id, retval); 903 dev_name(&usb_dev->dev), retval);
904 return (retval < 0) ? retval : -EMSGSIZE; 904 return (retval < 0) ? retval : -EMSGSIZE;
905 } 905 }
906 906
907 retval = usb_new_device (usb_dev); 907 retval = usb_new_device (usb_dev);
908 if (retval) { 908 if (retval) {
909 dev_err (parent_dev, "can't register root hub for %s, %d\n", 909 dev_err (parent_dev, "can't register root hub for %s, %d\n",
910 usb_dev->dev.bus_id, retval); 910 dev_name(&usb_dev->dev), retval);
911 } 911 }
912 mutex_unlock(&usb_bus_list_lock); 912 mutex_unlock(&usb_bus_list_lock);
913 913
@@ -1764,7 +1764,7 @@ EXPORT_SYMBOL_GPL (usb_hc_died);
1764 * If memory is unavailable, returns NULL. 1764 * If memory is unavailable, returns NULL.
1765 */ 1765 */
1766struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, 1766struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
1767 struct device *dev, char *bus_name) 1767 struct device *dev, const char *bus_name)
1768{ 1768{
1769 struct usb_hcd *hcd; 1769 struct usb_hcd *hcd;
1770 1770
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index b9de1569b39e..5b0b59b0d89b 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -21,6 +21,8 @@
21 21
22#include <linux/rwsem.h> 22#include <linux/rwsem.h>
23 23
24#define MAX_TOPO_LEVEL 6
25
24/* This file contains declarations of usbcore internals that are mostly 26/* This file contains declarations of usbcore internals that are mostly
25 * used or exposed by Host Controller Drivers. 27 * used or exposed by Host Controller Drivers.
26 */ 28 */
@@ -235,7 +237,7 @@ extern void usb_hcd_disable_endpoint(struct usb_device *udev,
235extern int usb_hcd_get_frame_number(struct usb_device *udev); 237extern int usb_hcd_get_frame_number(struct usb_device *udev);
236 238
237extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, 239extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
238 struct device *dev, char *bus_name); 240 struct device *dev, const char *bus_name);
239extern struct usb_hcd *usb_get_hcd(struct usb_hcd *hcd); 241extern struct usb_hcd *usb_get_hcd(struct usb_hcd *hcd);
240extern void usb_put_hcd(struct usb_hcd *hcd); 242extern void usb_put_hcd(struct usb_hcd *hcd);
241extern int usb_add_hcd(struct usb_hcd *hcd, 243extern int usb_add_hcd(struct usb_hcd *hcd,
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 4cfe32a16c37..107e1d25ddec 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -72,7 +72,6 @@ struct usb_hub {
72 72
73 unsigned limited_power:1; 73 unsigned limited_power:1;
74 unsigned quiescing:1; 74 unsigned quiescing:1;
75 unsigned activating:1;
76 unsigned disconnected:1; 75 unsigned disconnected:1;
77 76
78 unsigned has_indicators:1; 77 unsigned has_indicators:1;
@@ -131,6 +130,12 @@ MODULE_PARM_DESC(use_both_schemes,
131DECLARE_RWSEM(ehci_cf_port_reset_rwsem); 130DECLARE_RWSEM(ehci_cf_port_reset_rwsem);
132EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem); 131EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem);
133 132
133#define HUB_DEBOUNCE_TIMEOUT 1500
134#define HUB_DEBOUNCE_STEP 25
135#define HUB_DEBOUNCE_STABLE 100
136
137
138static int usb_reset_and_verify_device(struct usb_device *udev);
134 139
135static inline char *portspeed(int portstatus) 140static inline char *portspeed(int portstatus)
136{ 141{
@@ -535,37 +540,6 @@ static void hub_power_on(struct usb_hub *hub)
535 msleep(max(pgood_delay, (unsigned) 100)); 540 msleep(max(pgood_delay, (unsigned) 100));
536} 541}
537 542
538static void hub_quiesce(struct usb_hub *hub)
539{
540 /* (nonblocking) khubd and related activity won't re-trigger */
541 hub->quiescing = 1;
542 hub->activating = 0;
543
544 /* (blocking) stop khubd and related activity */
545 usb_kill_urb(hub->urb);
546 if (hub->has_indicators)
547 cancel_delayed_work_sync(&hub->leds);
548 if (hub->tt.hub)
549 cancel_work_sync(&hub->tt.kevent);
550}
551
552static void hub_activate(struct usb_hub *hub)
553{
554 int status;
555
556 hub->quiescing = 0;
557 hub->activating = 1;
558
559 status = usb_submit_urb(hub->urb, GFP_NOIO);
560 if (status < 0)
561 dev_err(hub->intfdev, "activate --> %d\n", status);
562 if (hub->has_indicators && blinkenlights)
563 schedule_delayed_work(&hub->leds, LED_CYCLE_PERIOD);
564
565 /* scan all ports ASAP */
566 kick_khubd(hub);
567}
568
569static int hub_hub_status(struct usb_hub *hub, 543static int hub_hub_status(struct usb_hub *hub,
570 u16 *status, u16 *change) 544 u16 *status, u16 *change)
571{ 545{
@@ -624,136 +598,149 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
624 kick_khubd(hub); 598 kick_khubd(hub);
625} 599}
626 600
627/* caller has locked the hub device */ 601enum hub_activation_type {
628static void hub_stop(struct usb_hub *hub) 602 HUB_INIT, HUB_POST_RESET, HUB_RESUME, HUB_RESET_RESUME
603};
604
605static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
629{ 606{
630 struct usb_device *hdev = hub->hdev; 607 struct usb_device *hdev = hub->hdev;
631 int i; 608 int port1;
609 int status;
610 bool need_debounce_delay = false;
632 611
633 /* Disconnect all the children */ 612 /* After a resume, port power should still be on.
634 for (i = 0; i < hdev->maxchild; ++i) { 613 * For any other type of activation, turn it on.
635 if (hdev->children[i]) 614 */
636 usb_disconnect(&hdev->children[i]); 615 if (type != HUB_RESUME)
637 } 616 hub_power_on(hub);
638 hub_quiesce(hub);
639}
640 617
641#define HUB_RESET 1 618 /* Check each port and set hub->change_bits to let khubd know
642#define HUB_RESUME 2 619 * which ports need attention.
643#define HUB_RESET_RESUME 3 620 */
621 for (port1 = 1; port1 <= hdev->maxchild; ++port1) {
622 struct usb_device *udev = hdev->children[port1-1];
623 u16 portstatus, portchange;
644 624
645#ifdef CONFIG_PM 625 portstatus = portchange = 0;
626 status = hub_port_status(hub, port1, &portstatus, &portchange);
627 if (udev || (portstatus & USB_PORT_STAT_CONNECTION))
628 dev_dbg(hub->intfdev,
629 "port %d: status %04x change %04x\n",
630 port1, portstatus, portchange);
646 631
647/* Try to identify which devices need USB-PERSIST handling */ 632 /* After anything other than HUB_RESUME (i.e., initialization
648static int persistent_device(struct usb_device *udev) 633 * or any sort of reset), every port should be disabled.
649{ 634 * Unconnected ports should likewise be disabled (paranoia),
650 int i; 635 * and so should ports for which we have no usb_device.
651 int retval; 636 */
652 struct usb_host_config *actconfig; 637 if ((portstatus & USB_PORT_STAT_ENABLE) && (
638 type != HUB_RESUME ||
639 !(portstatus & USB_PORT_STAT_CONNECTION) ||
640 !udev ||
641 udev->state == USB_STATE_NOTATTACHED)) {
642 clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE);
643 portstatus &= ~USB_PORT_STAT_ENABLE;
644 }
653 645
654 /* Explicitly not marked persistent? */ 646 /* Clear status-change flags; we'll debounce later */
655 if (!udev->persist_enabled) 647 if (portchange & USB_PORT_STAT_C_CONNECTION) {
656 return 0; 648 need_debounce_delay = true;
649 clear_port_feature(hub->hdev, port1,
650 USB_PORT_FEAT_C_CONNECTION);
651 }
652 if (portchange & USB_PORT_STAT_C_ENABLE) {
653 need_debounce_delay = true;
654 clear_port_feature(hub->hdev, port1,
655 USB_PORT_FEAT_C_ENABLE);
656 }
657 657
658 /* No active config? */ 658 if (!udev || udev->state == USB_STATE_NOTATTACHED) {
659 actconfig = udev->actconfig; 659 /* Tell khubd to disconnect the device or
660 if (!actconfig) 660 * check for a new connection
661 return 0; 661 */
662 if (udev || (portstatus & USB_PORT_STAT_CONNECTION))
663 set_bit(port1, hub->change_bits);
664
665 } else if (portstatus & USB_PORT_STAT_ENABLE) {
666 /* The power session apparently survived the resume.
667 * If there was an overcurrent or suspend change
668 * (i.e., remote wakeup request), have khubd
669 * take care of it.
670 */
671 if (portchange)
672 set_bit(port1, hub->change_bits);
662 673
663 /* FIXME! We should check whether it's open here or not! */ 674 } else if (udev->persist_enabled) {
675#ifdef CONFIG_PM
676 udev->reset_resume = 1;
677#endif
678 set_bit(port1, hub->change_bits);
664 679
665 /* 680 } else {
666 * Check that all the interface drivers have a 681 /* The power session is gone; tell khubd */
667 * 'reset_resume' entrypoint 682 usb_set_device_state(udev, USB_STATE_NOTATTACHED);
683 set_bit(port1, hub->change_bits);
684 }
685 }
686
687 /* If no port-status-change flags were set, we don't need any
688 * debouncing. If flags were set we can try to debounce the
689 * ports all at once right now, instead of letting khubd do them
690 * one at a time later on.
691 *
692 * If any port-status changes do occur during this delay, khubd
693 * will see them later and handle them normally.
668 */ 694 */
669 retval = 0; 695 if (need_debounce_delay)
670 for (i = 0; i < actconfig->desc.bNumInterfaces; i++) { 696 msleep(HUB_DEBOUNCE_STABLE);
671 struct usb_interface *intf;
672 struct usb_driver *driver;
673 697
674 intf = actconfig->interface[i]; 698 hub->quiescing = 0;
675 if (!intf->dev.driver)
676 continue;
677 driver = to_usb_driver(intf->dev.driver);
678 if (!driver->reset_resume)
679 return 0;
680 /*
681 * We have at least one driver, and that one
682 * has a reset_resume method.
683 */
684 retval = 1;
685 }
686 return retval;
687}
688 699
689static void hub_restart(struct usb_hub *hub, int type) 700 status = usb_submit_urb(hub->urb, GFP_NOIO);
690{ 701 if (status < 0)
691 struct usb_device *hdev = hub->hdev; 702 dev_err(hub->intfdev, "activate --> %d\n", status);
692 int port1; 703 if (hub->has_indicators && blinkenlights)
704 schedule_delayed_work(&hub->leds, LED_CYCLE_PERIOD);
693 705
694 /* Check each of the children to see if they require 706 /* Scan all ports that need attention */
695 * USB-PERSIST handling or disconnection. Also check 707 kick_khubd(hub);
696 * each unoccupied port to make sure it is still disabled. 708}
697 */
698 for (port1 = 1; port1 <= hdev->maxchild; ++port1) {
699 struct usb_device *udev = hdev->children[port1-1];
700 int status = 0;
701 u16 portstatus, portchange;
702 709
703 if (!udev || udev->state == USB_STATE_NOTATTACHED) { 710enum hub_quiescing_type {
704 if (type != HUB_RESET) { 711 HUB_DISCONNECT, HUB_PRE_RESET, HUB_SUSPEND
705 status = hub_port_status(hub, port1, 712};
706 &portstatus, &portchange);
707 if (status == 0 && (portstatus &
708 USB_PORT_STAT_ENABLE))
709 clear_port_feature(hdev, port1,
710 USB_PORT_FEAT_ENABLE);
711 }
712 continue;
713 }
714 713
715 /* Was the power session lost while we were suspended? */ 714static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type)
716 status = hub_port_status(hub, port1, &portstatus, &portchange); 715{
716 struct usb_device *hdev = hub->hdev;
717 int i;
717 718
718 /* If the device is gone, khubd will handle it later */ 719 /* khubd and related activity won't re-trigger */
719 if (status == 0 && !(portstatus & USB_PORT_STAT_CONNECTION)) 720 hub->quiescing = 1;
720 continue;
721 721
722 /* For "USB_PERSIST"-enabled children we must 722 if (type != HUB_SUSPEND) {
723 * mark the child device for reset-resume and 723 /* Disconnect all the children */
724 * turn off the various status changes to prevent 724 for (i = 0; i < hdev->maxchild; ++i) {
725 * khubd from disconnecting it later. 725 if (hdev->children[i])
726 */ 726 usb_disconnect(&hdev->children[i]);
727 if (status == 0 && !(portstatus & USB_PORT_STAT_ENABLE) &&
728 persistent_device(udev)) {
729 if (portchange & USB_PORT_STAT_C_ENABLE)
730 clear_port_feature(hub->hdev, port1,
731 USB_PORT_FEAT_C_ENABLE);
732 if (portchange & USB_PORT_STAT_C_CONNECTION)
733 clear_port_feature(hub->hdev, port1,
734 USB_PORT_FEAT_C_CONNECTION);
735 udev->reset_resume = 1;
736 } 727 }
737
738 /* Otherwise for a reset_resume we must disconnect the child,
739 * but as we may not lock the child device here
740 * we have to do a "logical" disconnect.
741 */
742 else if (type == HUB_RESET_RESUME)
743 hub_port_logical_disconnect(hub, port1);
744 } 728 }
745 729
746 hub_activate(hub); 730 /* Stop khubd and related activity */
731 usb_kill_urb(hub->urb);
732 if (hub->has_indicators)
733 cancel_delayed_work_sync(&hub->leds);
734 if (hub->tt.hub)
735 cancel_work_sync(&hub->tt.kevent);
747} 736}
748 737
749#endif /* CONFIG_PM */
750
751/* caller has locked the hub device */ 738/* caller has locked the hub device */
752static int hub_pre_reset(struct usb_interface *intf) 739static int hub_pre_reset(struct usb_interface *intf)
753{ 740{
754 struct usb_hub *hub = usb_get_intfdata(intf); 741 struct usb_hub *hub = usb_get_intfdata(intf);
755 742
756 hub_stop(hub); 743 hub_quiesce(hub, HUB_PRE_RESET);
757 return 0; 744 return 0;
758} 745}
759 746
@@ -762,8 +749,7 @@ static int hub_post_reset(struct usb_interface *intf)
762{ 749{
763 struct usb_hub *hub = usb_get_intfdata(intf); 750 struct usb_hub *hub = usb_get_intfdata(intf);
764 751
765 hub_power_on(hub); 752 hub_activate(hub, HUB_POST_RESET);
766 hub_activate(hub);
767 return 0; 753 return 0;
768} 754}
769 755
@@ -1009,8 +995,7 @@ static int hub_configure(struct usb_hub *hub,
1009 if (hub->has_indicators && blinkenlights) 995 if (hub->has_indicators && blinkenlights)
1010 hub->indicator [0] = INDICATOR_CYCLE; 996 hub->indicator [0] = INDICATOR_CYCLE;
1011 997
1012 hub_power_on(hub); 998 hub_activate(hub, HUB_INIT);
1013 hub_activate(hub);
1014 return 0; 999 return 0;
1015 1000
1016fail: 1001fail:
@@ -1042,7 +1027,7 @@ static void hub_disconnect(struct usb_interface *intf)
1042 1027
1043 /* Disconnect all children and quiesce the hub */ 1028 /* Disconnect all children and quiesce the hub */
1044 hub->error = 0; 1029 hub->error = 0;
1045 hub_stop(hub); 1030 hub_quiesce(hub, HUB_DISCONNECT);
1046 1031
1047 usb_set_intfdata (intf, NULL); 1032 usb_set_intfdata (intf, NULL);
1048 1033
@@ -1068,6 +1053,12 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
1068 desc = intf->cur_altsetting; 1053 desc = intf->cur_altsetting;
1069 hdev = interface_to_usbdev(intf); 1054 hdev = interface_to_usbdev(intf);
1070 1055
1056 if (hdev->level == MAX_TOPO_LEVEL) {
1057 dev_err(&intf->dev, "Unsupported bus topology: "
1058 "hub nested too deep\n");
1059 return -E2BIG;
1060 }
1061
1071#ifdef CONFIG_USB_OTG_BLACKLIST_HUB 1062#ifdef CONFIG_USB_OTG_BLACKLIST_HUB
1072 if (hdev->parent) { 1063 if (hdev->parent) {
1073 dev_warn(&intf->dev, "ignoring external hub\n"); 1064 dev_warn(&intf->dev, "ignoring external hub\n");
@@ -1814,6 +1805,51 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
1814 1805
1815#ifdef CONFIG_PM 1806#ifdef CONFIG_PM
1816 1807
1808#define MASK_BITS (USB_PORT_STAT_POWER | USB_PORT_STAT_CONNECTION | \
1809 USB_PORT_STAT_SUSPEND)
1810#define WANT_BITS (USB_PORT_STAT_POWER | USB_PORT_STAT_CONNECTION)
1811
1812/* Determine whether the device on a port is ready for a normal resume,
1813 * is ready for a reset-resume, or should be disconnected.
1814 */
1815static int check_port_resume_type(struct usb_device *udev,
1816 struct usb_hub *hub, int port1,
1817 int status, unsigned portchange, unsigned portstatus)
1818{
1819 /* Is the device still present? */
1820 if (status || (portstatus & MASK_BITS) != WANT_BITS) {
1821 if (status >= 0)
1822 status = -ENODEV;
1823 }
1824
1825 /* Can't do a normal resume if the port isn't enabled,
1826 * so try a reset-resume instead.
1827 */
1828 else if (!(portstatus & USB_PORT_STAT_ENABLE) && !udev->reset_resume) {
1829 if (udev->persist_enabled)
1830 udev->reset_resume = 1;
1831 else
1832 status = -ENODEV;
1833 }
1834
1835 if (status) {
1836 dev_dbg(hub->intfdev,
1837 "port %d status %04x.%04x after resume, %d\n",
1838 port1, portchange, portstatus, status);
1839 } else if (udev->reset_resume) {
1840
1841 /* Late port handoff can set status-change bits */
1842 if (portchange & USB_PORT_STAT_C_CONNECTION)
1843 clear_port_feature(hub->hdev, port1,
1844 USB_PORT_FEAT_C_CONNECTION);
1845 if (portchange & USB_PORT_STAT_C_ENABLE)
1846 clear_port_feature(hub->hdev, port1,
1847 USB_PORT_FEAT_C_ENABLE);
1848 }
1849
1850 return status;
1851}
1852
1817#ifdef CONFIG_USB_SUSPEND 1853#ifdef CONFIG_USB_SUSPEND
1818 1854
1819/* 1855/*
@@ -1943,7 +1979,8 @@ static int finish_port_resume(struct usb_device *udev)
1943 * resumed. 1979 * resumed.
1944 */ 1980 */
1945 if (udev->reset_resume) 1981 if (udev->reset_resume)
1946 status = usb_reset_device(udev); 1982 retry_reset_resume:
1983 status = usb_reset_and_verify_device(udev);
1947 1984
1948 /* 10.5.4.5 says be sure devices in the tree are still there. 1985 /* 10.5.4.5 says be sure devices in the tree are still there.
1949 * For now let's assume the device didn't go crazy on resume, 1986 * For now let's assume the device didn't go crazy on resume,
@@ -1954,6 +1991,13 @@ static int finish_port_resume(struct usb_device *udev)
1954 status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus); 1991 status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus);
1955 if (status >= 0) 1992 if (status >= 0)
1956 status = (status > 0 ? 0 : -ENODEV); 1993 status = (status > 0 ? 0 : -ENODEV);
1994
1995 /* If a normal resume failed, try doing a reset-resume */
1996 if (status && !udev->reset_resume && udev->persist_enabled) {
1997 dev_dbg(&udev->dev, "retry with reset-resume\n");
1998 udev->reset_resume = 1;
1999 goto retry_reset_resume;
2000 }
1957 } 2001 }
1958 2002
1959 if (status) { 2003 if (status) {
@@ -2002,7 +2046,7 @@ static int finish_port_resume(struct usb_device *udev)
2002 * to it will be lost. Using the USB_PERSIST facility, the device can be 2046 * to it will be lost. Using the USB_PERSIST facility, the device can be
2003 * made to appear as if it had not disconnected. 2047 * made to appear as if it had not disconnected.
2004 * 2048 *
2005 * This facility can be dangerous. Although usb_reset_device() makes 2049 * This facility can be dangerous. Although usb_reset_and_verify_device() makes
2006 * every effort to insure that the same device is present after the 2050 * every effort to insure that the same device is present after the
2007 * reset as before, it cannot provide a 100% guarantee. Furthermore it's 2051 * reset as before, it cannot provide a 100% guarantee. Furthermore it's
2008 * quite possible for a device to remain unaltered but its media to be 2052 * quite possible for a device to remain unaltered but its media to be
@@ -2018,7 +2062,6 @@ int usb_port_resume(struct usb_device *udev)
2018 int port1 = udev->portnum; 2062 int port1 = udev->portnum;
2019 int status; 2063 int status;
2020 u16 portchange, portstatus; 2064 u16 portchange, portstatus;
2021 unsigned mask_flags, want_flags;
2022 2065
2023 /* Skip the initial Clear-Suspend step for a remote wakeup */ 2066 /* Skip the initial Clear-Suspend step for a remote wakeup */
2024 status = hub_port_status(hub, port1, &portstatus, &portchange); 2067 status = hub_port_status(hub, port1, &portstatus, &portchange);
@@ -2047,35 +2090,23 @@ int usb_port_resume(struct usb_device *udev)
2047 */ 2090 */
2048 status = hub_port_status(hub, port1, &portstatus, &portchange); 2091 status = hub_port_status(hub, port1, &portstatus, &portchange);
2049 2092
2050 SuspendCleared: 2093 /* TRSMRCY = 10 msec */
2051 if (udev->reset_resume) 2094 msleep(10);
2052 want_flags = USB_PORT_STAT_POWER 2095 }
2053 | USB_PORT_STAT_CONNECTION;
2054 else
2055 want_flags = USB_PORT_STAT_POWER
2056 | USB_PORT_STAT_CONNECTION
2057 | USB_PORT_STAT_ENABLE;
2058 mask_flags = want_flags | USB_PORT_STAT_SUSPEND;
2059 2096
2060 if (status < 0 || (portstatus & mask_flags) != want_flags) { 2097 SuspendCleared:
2061 dev_dbg(hub->intfdev, 2098 if (status == 0) {
2062 "port %d status %04x.%04x after resume, %d\n", 2099 if (portchange & USB_PORT_STAT_C_SUSPEND)
2063 port1, portchange, portstatus, status); 2100 clear_port_feature(hub->hdev, port1,
2064 if (status >= 0) 2101 USB_PORT_FEAT_C_SUSPEND);
2065 status = -ENODEV;
2066 } else {
2067 if (portchange & USB_PORT_STAT_C_SUSPEND)
2068 clear_port_feature(hub->hdev, port1,
2069 USB_PORT_FEAT_C_SUSPEND);
2070 /* TRSMRCY = 10 msec */
2071 msleep(10);
2072 }
2073 } 2102 }
2074 2103
2075 clear_bit(port1, hub->busy_bits); 2104 clear_bit(port1, hub->busy_bits);
2076 if (!hub->hdev->parent && !hub->busy_bits[0]) 2105 if (!hub->hdev->parent && !hub->busy_bits[0])
2077 usb_enable_root_hub_irq(hub->hdev->bus); 2106 usb_enable_root_hub_irq(hub->hdev->bus);
2078 2107
2108 status = check_port_resume_type(udev,
2109 hub, port1, status, portchange, portstatus);
2079 if (status == 0) 2110 if (status == 0)
2080 status = finish_port_resume(udev); 2111 status = finish_port_resume(udev);
2081 if (status < 0) { 2112 if (status < 0) {
@@ -2085,17 +2116,16 @@ int usb_port_resume(struct usb_device *udev)
2085 return status; 2116 return status;
2086} 2117}
2087 2118
2119/* caller has locked udev */
2088static int remote_wakeup(struct usb_device *udev) 2120static int remote_wakeup(struct usb_device *udev)
2089{ 2121{
2090 int status = 0; 2122 int status = 0;
2091 2123
2092 usb_lock_device(udev);
2093 if (udev->state == USB_STATE_SUSPENDED) { 2124 if (udev->state == USB_STATE_SUSPENDED) {
2094 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); 2125 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-");
2095 usb_mark_last_busy(udev); 2126 usb_mark_last_busy(udev);
2096 status = usb_external_resume_device(udev); 2127 status = usb_external_resume_device(udev);
2097 } 2128 }
2098 usb_unlock_device(udev);
2099 return status; 2129 return status;
2100} 2130}
2101 2131
@@ -2108,14 +2138,25 @@ int usb_port_suspend(struct usb_device *udev)
2108 return 0; 2138 return 0;
2109} 2139}
2110 2140
2141/* However we may need to do a reset-resume */
2142
2111int usb_port_resume(struct usb_device *udev) 2143int usb_port_resume(struct usb_device *udev)
2112{ 2144{
2113 int status = 0; 2145 struct usb_hub *hub = hdev_to_hub(udev->parent);
2146 int port1 = udev->portnum;
2147 int status;
2148 u16 portchange, portstatus;
2114 2149
2115 /* However we may need to do a reset-resume */ 2150 status = hub_port_status(hub, port1, &portstatus, &portchange);
2116 if (udev->reset_resume) { 2151 status = check_port_resume_type(udev,
2152 hub, port1, status, portchange, portstatus);
2153
2154 if (status) {
2155 dev_dbg(&udev->dev, "can't resume, status %d\n", status);
2156 hub_port_logical_disconnect(hub, port1);
2157 } else if (udev->reset_resume) {
2117 dev_dbg(&udev->dev, "reset-resume\n"); 2158 dev_dbg(&udev->dev, "reset-resume\n");
2118 status = usb_reset_device(udev); 2159 status = usb_reset_and_verify_device(udev);
2119 } 2160 }
2120 return status; 2161 return status;
2121} 2162}
@@ -2149,7 +2190,7 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
2149 dev_dbg(&intf->dev, "%s\n", __func__); 2190 dev_dbg(&intf->dev, "%s\n", __func__);
2150 2191
2151 /* stop khubd and related activity */ 2192 /* stop khubd and related activity */
2152 hub_quiesce(hub); 2193 hub_quiesce(hub, HUB_SUSPEND);
2153 return 0; 2194 return 0;
2154} 2195}
2155 2196
@@ -2158,7 +2199,7 @@ static int hub_resume(struct usb_interface *intf)
2158 struct usb_hub *hub = usb_get_intfdata(intf); 2199 struct usb_hub *hub = usb_get_intfdata(intf);
2159 2200
2160 dev_dbg(&intf->dev, "%s\n", __func__); 2201 dev_dbg(&intf->dev, "%s\n", __func__);
2161 hub_restart(hub, HUB_RESUME); 2202 hub_activate(hub, HUB_RESUME);
2162 return 0; 2203 return 0;
2163} 2204}
2164 2205
@@ -2167,8 +2208,7 @@ static int hub_reset_resume(struct usb_interface *intf)
2167 struct usb_hub *hub = usb_get_intfdata(intf); 2208 struct usb_hub *hub = usb_get_intfdata(intf);
2168 2209
2169 dev_dbg(&intf->dev, "%s\n", __func__); 2210 dev_dbg(&intf->dev, "%s\n", __func__);
2170 hub_power_on(hub); 2211 hub_activate(hub, HUB_RESET_RESUME);
2171 hub_restart(hub, HUB_RESET_RESUME);
2172 return 0; 2212 return 0;
2173} 2213}
2174 2214
@@ -2218,11 +2258,6 @@ static inline int remote_wakeup(struct usb_device *udev)
2218 * every 25ms for transient disconnects. When the port status has been 2258 * every 25ms for transient disconnects. When the port status has been
2219 * unchanged for 100ms it returns the port status. 2259 * unchanged for 100ms it returns the port status.
2220 */ 2260 */
2221
2222#define HUB_DEBOUNCE_TIMEOUT 1500
2223#define HUB_DEBOUNCE_STEP 25
2224#define HUB_DEBOUNCE_STABLE 100
2225
2226static int hub_port_debounce(struct usb_hub *hub, int port1) 2261static int hub_port_debounce(struct usb_hub *hub, int port1)
2227{ 2262{
2228 int ret; 2263 int ret;
@@ -2302,7 +2337,7 @@ static int hub_set_address(struct usb_device *udev, int devnum)
2302 * Returns device in USB_STATE_ADDRESS, except on error. 2337 * Returns device in USB_STATE_ADDRESS, except on error.
2303 * 2338 *
2304 * If this is called for an already-existing device (as part of 2339 * If this is called for an already-existing device (as part of
2305 * usb_reset_device), the caller must own the device lock. For a 2340 * usb_reset_and_verify_device), the caller must own the device lock. For a
2306 * newly detected device that is not accessible through any global 2341 * newly detected device that is not accessible through any global
2307 * pointers, it's not necessary to lock the device. 2342 * pointers, it's not necessary to lock the device.
2308 */ 2343 */
@@ -2619,7 +2654,7 @@ hub_power_remaining (struct usb_hub *hub)
2619 * This routine is called when: 2654 * This routine is called when:
2620 * a port connection-change occurs; 2655 * a port connection-change occurs;
2621 * a port enable-change occurs (often caused by EMI); 2656 * a port enable-change occurs (often caused by EMI);
2622 * usb_reset_device() encounters changed descriptors (as from 2657 * usb_reset_and_verify_device() encounters changed descriptors (as from
2623 * a firmware download) 2658 * a firmware download)
2624 * caller already locked the hub 2659 * caller already locked the hub
2625 */ 2660 */
@@ -2629,9 +2664,11 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2629 struct usb_device *hdev = hub->hdev; 2664 struct usb_device *hdev = hub->hdev;
2630 struct device *hub_dev = hub->intfdev; 2665 struct device *hub_dev = hub->intfdev;
2631 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); 2666 struct usb_hcd *hcd = bus_to_hcd(hdev->bus);
2632 u16 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); 2667 unsigned wHubCharacteristics =
2668 le16_to_cpu(hub->descriptor->wHubCharacteristics);
2669 struct usb_device *udev;
2633 int status, i; 2670 int status, i;
2634 2671
2635 dev_dbg (hub_dev, 2672 dev_dbg (hub_dev,
2636 "port %d, status %04x, change %04x, %s\n", 2673 "port %d, status %04x, change %04x, %s\n",
2637 port1, portstatus, portchange, portspeed (portstatus)); 2674 port1, portstatus, portchange, portspeed (portstatus));
@@ -2640,30 +2677,73 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2640 set_port_led(hub, port1, HUB_LED_AUTO); 2677 set_port_led(hub, port1, HUB_LED_AUTO);
2641 hub->indicator[port1-1] = INDICATOR_AUTO; 2678 hub->indicator[port1-1] = INDICATOR_AUTO;
2642 } 2679 }
2643
2644 /* Disconnect any existing devices under this port */
2645 if (hdev->children[port1-1])
2646 usb_disconnect(&hdev->children[port1-1]);
2647 clear_bit(port1, hub->change_bits);
2648 2680
2649#ifdef CONFIG_USB_OTG 2681#ifdef CONFIG_USB_OTG
2650 /* during HNP, don't repeat the debounce */ 2682 /* during HNP, don't repeat the debounce */
2651 if (hdev->bus->is_b_host) 2683 if (hdev->bus->is_b_host)
2652 portchange &= ~USB_PORT_STAT_C_CONNECTION; 2684 portchange &= ~(USB_PORT_STAT_C_CONNECTION |
2685 USB_PORT_STAT_C_ENABLE);
2653#endif 2686#endif
2654 2687
2655 if (portchange & USB_PORT_STAT_C_CONNECTION) { 2688 /* Try to use the debounce delay for protection against
2689 * port-enable changes caused, for example, by EMI.
2690 */
2691 if (portchange & (USB_PORT_STAT_C_CONNECTION |
2692 USB_PORT_STAT_C_ENABLE)) {
2656 status = hub_port_debounce(hub, port1); 2693 status = hub_port_debounce(hub, port1);
2657 if (status < 0) { 2694 if (status < 0) {
2658 if (printk_ratelimit()) 2695 if (printk_ratelimit())
2659 dev_err (hub_dev, "connect-debounce failed, " 2696 dev_err (hub_dev, "connect-debounce failed, "
2660 "port %d disabled\n", port1); 2697 "port %d disabled\n", port1);
2661 goto done; 2698 portstatus &= ~USB_PORT_STAT_CONNECTION;
2699 } else {
2700 portstatus = status;
2701 }
2702 }
2703
2704 /* Try to resuscitate an existing device */
2705 udev = hdev->children[port1-1];
2706 if ((portstatus & USB_PORT_STAT_CONNECTION) && udev &&
2707 udev->state != USB_STATE_NOTATTACHED) {
2708
2709 usb_lock_device(udev);
2710 if (portstatus & USB_PORT_STAT_ENABLE) {
2711 status = 0; /* Nothing to do */
2712 } else if (!udev->persist_enabled) {
2713 status = -ENODEV; /* Mustn't resuscitate */
2714
2715#ifdef CONFIG_USB_SUSPEND
2716 } else if (udev->state == USB_STATE_SUSPENDED) {
2717 /* For a suspended device, treat this as a
2718 * remote wakeup event.
2719 */
2720 if (udev->do_remote_wakeup)
2721 status = remote_wakeup(udev);
2722
2723 /* Otherwise leave it be; devices can't tell the
2724 * difference between suspended and disabled.
2725 */
2726 else
2727 status = 0;
2728#endif
2729
2730 } else {
2731 status = usb_reset_device(udev);
2732 }
2733 usb_unlock_device(udev);
2734
2735 if (status == 0) {
2736 clear_bit(port1, hub->change_bits);
2737 return;
2662 } 2738 }
2663 portstatus = status;
2664 } 2739 }
2665 2740
2666 /* Return now if nothing is connected */ 2741 /* Disconnect any existing devices under this port */
2742 if (udev)
2743 usb_disconnect(&hdev->children[port1-1]);
2744 clear_bit(port1, hub->change_bits);
2745
2746 /* Return now if debouncing failed or nothing is connected */
2667 if (!(portstatus & USB_PORT_STAT_CONNECTION)) { 2747 if (!(portstatus & USB_PORT_STAT_CONNECTION)) {
2668 2748
2669 /* maybe switch power back on (e.g. root hub was reset) */ 2749 /* maybe switch power back on (e.g. root hub was reset) */
@@ -2677,7 +2757,6 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2677 } 2757 }
2678 2758
2679 for (i = 0; i < SET_CONFIG_TRIES; i++) { 2759 for (i = 0; i < SET_CONFIG_TRIES; i++) {
2680 struct usb_device *udev;
2681 2760
2682 /* reallocate for each attempt, since references 2761 /* reallocate for each attempt, since references
2683 * to the previous one can escape in various ways 2762 * to the previous one can escape in various ways
@@ -2858,7 +2937,7 @@ static void hub_events(void)
2858 /* If the hub has died, clean up after it */ 2937 /* If the hub has died, clean up after it */
2859 if (hdev->state == USB_STATE_NOTATTACHED) { 2938 if (hdev->state == USB_STATE_NOTATTACHED) {
2860 hub->error = -ENODEV; 2939 hub->error = -ENODEV;
2861 hub_stop(hub); 2940 hub_quiesce(hub, HUB_DISCONNECT);
2862 goto loop; 2941 goto loop;
2863 } 2942 }
2864 2943
@@ -2877,7 +2956,7 @@ static void hub_events(void)
2877 dev_dbg (hub_dev, "resetting for error %d\n", 2956 dev_dbg (hub_dev, "resetting for error %d\n",
2878 hub->error); 2957 hub->error);
2879 2958
2880 ret = usb_reset_composite_device(hdev, intf); 2959 ret = usb_reset_device(hdev);
2881 if (ret) { 2960 if (ret) {
2882 dev_dbg (hub_dev, 2961 dev_dbg (hub_dev,
2883 "error resetting hub: %d\n", ret); 2962 "error resetting hub: %d\n", ret);
@@ -2894,7 +2973,7 @@ static void hub_events(void)
2894 continue; 2973 continue;
2895 connect_change = test_bit(i, hub->change_bits); 2974 connect_change = test_bit(i, hub->change_bits);
2896 if (!test_and_clear_bit(i, hub->event_bits) && 2975 if (!test_and_clear_bit(i, hub->event_bits) &&
2897 !connect_change && !hub->activating) 2976 !connect_change)
2898 continue; 2977 continue;
2899 2978
2900 ret = hub_port_status(hub, i, 2979 ret = hub_port_status(hub, i,
@@ -2902,11 +2981,6 @@ static void hub_events(void)
2902 if (ret < 0) 2981 if (ret < 0)
2903 continue; 2982 continue;
2904 2983
2905 if (hub->activating && !hdev->children[i-1] &&
2906 (portstatus &
2907 USB_PORT_STAT_CONNECTION))
2908 connect_change = 1;
2909
2910 if (portchange & USB_PORT_STAT_C_CONNECTION) { 2984 if (portchange & USB_PORT_STAT_C_CONNECTION) {
2911 clear_port_feature(hdev, i, 2985 clear_port_feature(hdev, i,
2912 USB_PORT_FEAT_C_CONNECTION); 2986 USB_PORT_FEAT_C_CONNECTION);
@@ -2941,11 +3015,16 @@ static void hub_events(void)
2941 } 3015 }
2942 3016
2943 if (portchange & USB_PORT_STAT_C_SUSPEND) { 3017 if (portchange & USB_PORT_STAT_C_SUSPEND) {
3018 struct usb_device *udev;
3019
2944 clear_port_feature(hdev, i, 3020 clear_port_feature(hdev, i,
2945 USB_PORT_FEAT_C_SUSPEND); 3021 USB_PORT_FEAT_C_SUSPEND);
2946 if (hdev->children[i-1]) { 3022 udev = hdev->children[i-1];
3023 if (udev) {
3024 usb_lock_device(udev);
2947 ret = remote_wakeup(hdev-> 3025 ret = remote_wakeup(hdev->
2948 children[i-1]); 3026 children[i-1]);
3027 usb_unlock_device(udev);
2949 if (ret < 0) 3028 if (ret < 0)
2950 connect_change = 1; 3029 connect_change = 1;
2951 } else { 3030 } else {
@@ -3002,8 +3081,6 @@ static void hub_events(void)
3002 } 3081 }
3003 } 3082 }
3004 3083
3005 hub->activating = 0;
3006
3007 /* If this is a root hub, tell the HCD it's okay to 3084 /* If this is a root hub, tell the HCD it's okay to
3008 * re-enable port-change interrupts now. */ 3085 * re-enable port-change interrupts now. */
3009 if (!hdev->parent && !hub->busy_bits[0]) 3086 if (!hdev->parent && !hub->busy_bits[0])
@@ -3172,12 +3249,12 @@ static int descriptors_changed(struct usb_device *udev,
3172} 3249}
3173 3250
3174/** 3251/**
3175 * usb_reset_device - perform a USB port reset to reinitialize a device 3252 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
3176 * @udev: device to reset (not in SUSPENDED or NOTATTACHED state) 3253 * @udev: device to reset (not in SUSPENDED or NOTATTACHED state)
3177 * 3254 *
3178 * WARNING - don't use this routine to reset a composite device 3255 * WARNING - don't use this routine to reset a composite device
3179 * (one with multiple interfaces owned by separate drivers)! 3256 * (one with multiple interfaces owned by separate drivers)!
3180 * Use usb_reset_composite_device() instead. 3257 * Use usb_reset_device() instead.
3181 * 3258 *
3182 * Do a port reset, reassign the device's address, and establish its 3259 * Do a port reset, reassign the device's address, and establish its
3183 * former operating configuration. If the reset fails, or the device's 3260 * former operating configuration. If the reset fails, or the device's
@@ -3201,7 +3278,7 @@ static int descriptors_changed(struct usb_device *udev,
3201 * holding the device lock because these tasks should always call 3278 * holding the device lock because these tasks should always call
3202 * usb_autopm_resume_device(), thereby preventing any unwanted autoresume. 3279 * usb_autopm_resume_device(), thereby preventing any unwanted autoresume.
3203 */ 3280 */
3204int usb_reset_device(struct usb_device *udev) 3281static int usb_reset_and_verify_device(struct usb_device *udev)
3205{ 3282{
3206 struct usb_device *parent_hdev = udev->parent; 3283 struct usb_device *parent_hdev = udev->parent;
3207 struct usb_hub *parent_hub; 3284 struct usb_hub *parent_hub;
@@ -3289,26 +3366,28 @@ re_enumerate:
3289 hub_port_logical_disconnect(parent_hub, port1); 3366 hub_port_logical_disconnect(parent_hub, port1);
3290 return -ENODEV; 3367 return -ENODEV;
3291} 3368}
3292EXPORT_SYMBOL_GPL(usb_reset_device);
3293 3369
3294/** 3370/**
3295 * usb_reset_composite_device - warn interface drivers and perform a USB port reset 3371 * usb_reset_device - warn interface drivers and perform a USB port reset
3296 * @udev: device to reset (not in SUSPENDED or NOTATTACHED state) 3372 * @udev: device to reset (not in SUSPENDED or NOTATTACHED state)
3297 * @iface: interface bound to the driver making the request (optional)
3298 * 3373 *
3299 * Warns all drivers bound to registered interfaces (using their pre_reset 3374 * Warns all drivers bound to registered interfaces (using their pre_reset
3300 * method), performs the port reset, and then lets the drivers know that 3375 * method), performs the port reset, and then lets the drivers know that
3301 * the reset is over (using their post_reset method). 3376 * the reset is over (using their post_reset method).
3302 * 3377 *
3303 * Return value is the same as for usb_reset_device(). 3378 * Return value is the same as for usb_reset_and_verify_device().
3304 * 3379 *
3305 * The caller must own the device lock. For example, it's safe to use 3380 * The caller must own the device lock. For example, it's safe to use
3306 * this from a driver probe() routine after downloading new firmware. 3381 * this from a driver probe() routine after downloading new firmware.
3307 * For calls that might not occur during probe(), drivers should lock 3382 * For calls that might not occur during probe(), drivers should lock
3308 * the device using usb_lock_device_for_reset(). 3383 * the device using usb_lock_device_for_reset().
3384 *
3385 * If an interface is currently being probed or disconnected, we assume
3386 * its driver knows how to handle resets. For all other interfaces,
3387 * if the driver doesn't have pre_reset and post_reset methods then
3388 * we attempt to unbind it and rebind afterward.
3309 */ 3389 */
3310int usb_reset_composite_device(struct usb_device *udev, 3390int usb_reset_device(struct usb_device *udev)
3311 struct usb_interface *iface)
3312{ 3391{
3313 int ret; 3392 int ret;
3314 int i; 3393 int i;
@@ -3324,40 +3403,47 @@ int usb_reset_composite_device(struct usb_device *udev,
3324 /* Prevent autosuspend during the reset */ 3403 /* Prevent autosuspend during the reset */
3325 usb_autoresume_device(udev); 3404 usb_autoresume_device(udev);
3326 3405
3327 if (iface && iface->condition != USB_INTERFACE_BINDING)
3328 iface = NULL;
3329
3330 if (config) { 3406 if (config) {
3331 for (i = 0; i < config->desc.bNumInterfaces; ++i) { 3407 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
3332 struct usb_interface *cintf = config->interface[i]; 3408 struct usb_interface *cintf = config->interface[i];
3333 struct usb_driver *drv; 3409 struct usb_driver *drv;
3410 int unbind = 0;
3334 3411
3335 if (cintf->dev.driver) { 3412 if (cintf->dev.driver) {
3336 drv = to_usb_driver(cintf->dev.driver); 3413 drv = to_usb_driver(cintf->dev.driver);
3337 if (drv->pre_reset) 3414 if (drv->pre_reset && drv->post_reset)
3338 (drv->pre_reset)(cintf); 3415 unbind = (drv->pre_reset)(cintf);
3339 /* FIXME: Unbind if pre_reset returns an error or isn't defined */ 3416 else if (cintf->condition ==
3417 USB_INTERFACE_BOUND)
3418 unbind = 1;
3419 if (unbind)
3420 usb_forced_unbind_intf(cintf);
3340 } 3421 }
3341 } 3422 }
3342 } 3423 }
3343 3424
3344 ret = usb_reset_device(udev); 3425 ret = usb_reset_and_verify_device(udev);
3345 3426
3346 if (config) { 3427 if (config) {
3347 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { 3428 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) {
3348 struct usb_interface *cintf = config->interface[i]; 3429 struct usb_interface *cintf = config->interface[i];
3349 struct usb_driver *drv; 3430 struct usb_driver *drv;
3431 int rebind = cintf->needs_binding;
3350 3432
3351 if (cintf->dev.driver) { 3433 if (!rebind && cintf->dev.driver) {
3352 drv = to_usb_driver(cintf->dev.driver); 3434 drv = to_usb_driver(cintf->dev.driver);
3353 if (drv->post_reset) 3435 if (drv->post_reset)
3354 (drv->post_reset)(cintf); 3436 rebind = (drv->post_reset)(cintf);
3355 /* FIXME: Unbind if post_reset returns an error or isn't defined */ 3437 else if (cintf->condition ==
3438 USB_INTERFACE_BOUND)
3439 rebind = 1;
3356 } 3440 }
3441 if (rebind)
3442 usb_rebind_intf(cintf);
3357 } 3443 }
3358 } 3444 }
3359 3445
3360 usb_autosuspend_device(udev); 3446 usb_autosuspend_device(udev);
3361 return ret; 3447 return ret;
3362} 3448}
3363EXPORT_SYMBOL_GPL(usb_reset_composite_device); 3449EXPORT_SYMBOL_GPL(usb_reset_device);
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index 1d253dd4ea81..db410e92c80d 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -712,25 +712,11 @@ static void usbfs_add_device(struct usb_device *dev)
712 712
713static void usbfs_remove_device(struct usb_device *dev) 713static void usbfs_remove_device(struct usb_device *dev)
714{ 714{
715 struct dev_state *ds;
716 struct siginfo sinfo;
717
718 if (dev->usbfs_dentry) { 715 if (dev->usbfs_dentry) {
719 fs_remove_file (dev->usbfs_dentry); 716 fs_remove_file (dev->usbfs_dentry);
720 dev->usbfs_dentry = NULL; 717 dev->usbfs_dentry = NULL;
721 } 718 }
722 while (!list_empty(&dev->filelist)) { 719 usb_fs_classdev_common_remove(dev);
723 ds = list_entry(dev->filelist.next, struct dev_state, list);
724 wake_up_all(&ds->wait);
725 list_del_init(&ds->list);
726 if (ds->discsignr) {
727 sinfo.si_signo = ds->discsignr;
728 sinfo.si_errno = EPIPE;
729 sinfo.si_code = SI_ASYNCIO;
730 sinfo.si_addr = ds->disccontext;
731 kill_pid_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid, ds->secid);
732 }
733 }
734} 720}
735 721
736static int usbfs_notify(struct notifier_block *self, unsigned long action, void *dev) 722static int usbfs_notify(struct notifier_block *self, unsigned long action, void *dev)
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index fe47d145255a..2fcc06eb5e60 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -400,7 +400,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
400 if (usb_pipein(pipe)) 400 if (usb_pipein(pipe))
401 urb_flags |= URB_SHORT_NOT_OK; 401 urb_flags |= URB_SHORT_NOT_OK;
402 402
403 for (i = 0; i < io->entries; i++) { 403 for_each_sg(sg, sg, io->entries, i) {
404 unsigned len; 404 unsigned len;
405 405
406 io->urbs[i] = usb_alloc_urb(0, mem_flags); 406 io->urbs[i] = usb_alloc_urb(0, mem_flags);
@@ -434,17 +434,17 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
434 * to prevent stale pointers and to help spot bugs. 434 * to prevent stale pointers and to help spot bugs.
435 */ 435 */
436 if (dma) { 436 if (dma) {
437 io->urbs[i]->transfer_dma = sg_dma_address(sg + i); 437 io->urbs[i]->transfer_dma = sg_dma_address(sg);
438 len = sg_dma_len(sg + i); 438 len = sg_dma_len(sg);
439#if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU) 439#if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU)
440 io->urbs[i]->transfer_buffer = NULL; 440 io->urbs[i]->transfer_buffer = NULL;
441#else 441#else
442 io->urbs[i]->transfer_buffer = sg_virt(&sg[i]); 442 io->urbs[i]->transfer_buffer = sg_virt(sg);
443#endif 443#endif
444 } else { 444 } else {
445 /* hc may use _only_ transfer_buffer */ 445 /* hc may use _only_ transfer_buffer */
446 io->urbs[i]->transfer_buffer = sg_virt(&sg[i]); 446 io->urbs[i]->transfer_buffer = sg_virt(sg);
447 len = sg[i].length; 447 len = sg->length;
448 } 448 }
449 449
450 if (length) { 450 if (length) {
@@ -1090,7 +1090,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1090 if (!device_is_registered(&interface->dev)) 1090 if (!device_is_registered(&interface->dev))
1091 continue; 1091 continue;
1092 dev_dbg(&dev->dev, "unregistering interface %s\n", 1092 dev_dbg(&dev->dev, "unregistering interface %s\n",
1093 interface->dev.bus_id); 1093 dev_name(&interface->dev));
1094 device_del(&interface->dev); 1094 device_del(&interface->dev);
1095 usb_remove_sysfs_intf_files(interface); 1095 usb_remove_sysfs_intf_files(interface);
1096 } 1096 }
@@ -1476,7 +1476,7 @@ static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
1476 * 1476 *
1477 * This call is synchronous. The calling context must be able to sleep, 1477 * This call is synchronous. The calling context must be able to sleep,
1478 * must own the device lock, and must not hold the driver model's USB 1478 * must own the device lock, and must not hold the driver model's USB
1479 * bus mutex; usb device driver probe() methods cannot use this routine. 1479 * bus mutex; usb interface driver probe() methods cannot use this routine.
1480 * 1480 *
1481 * Returns zero on success, or else the status code returned by the 1481 * Returns zero on success, or else the status code returned by the
1482 * underlying call that failed. On successful completion, each interface 1482 * underlying call that failed. On successful completion, each interface
@@ -1611,7 +1611,7 @@ free_interfaces:
1611 intf->dev.dma_mask = dev->dev.dma_mask; 1611 intf->dev.dma_mask = dev->dev.dma_mask;
1612 device_initialize(&intf->dev); 1612 device_initialize(&intf->dev);
1613 mark_quiesced(intf); 1613 mark_quiesced(intf);
1614 sprintf(&intf->dev.bus_id[0], "%d-%s:%d.%d", 1614 dev_set_name(&intf->dev, "%d-%s:%d.%d",
1615 dev->bus->busnum, dev->devpath, 1615 dev->bus->busnum, dev->devpath,
1616 configuration, alt->desc.bInterfaceNumber); 1616 configuration, alt->desc.bInterfaceNumber);
1617 } 1617 }
@@ -1631,12 +1631,12 @@ free_interfaces:
1631 1631
1632 dev_dbg(&dev->dev, 1632 dev_dbg(&dev->dev,
1633 "adding %s (config #%d, interface %d)\n", 1633 "adding %s (config #%d, interface %d)\n",
1634 intf->dev.bus_id, configuration, 1634 dev_name(&intf->dev), configuration,
1635 intf->cur_altsetting->desc.bInterfaceNumber); 1635 intf->cur_altsetting->desc.bInterfaceNumber);
1636 ret = device_add(&intf->dev); 1636 ret = device_add(&intf->dev);
1637 if (ret != 0) { 1637 if (ret != 0) {
1638 dev_err(&dev->dev, "device_add(%s) --> %d\n", 1638 dev_err(&dev->dev, "device_add(%s) --> %d\n",
1639 intf->dev.bus_id, ret); 1639 dev_name(&intf->dev), ret);
1640 continue; 1640 continue;
1641 } 1641 }
1642 usb_create_sysfs_intf_files(intf); 1642 usb_create_sysfs_intf_files(intf);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 325774375837..84fcaa6a21ec 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -308,7 +308,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
308 * by location for diagnostics, tools, driver model, etc. The 308 * by location for diagnostics, tools, driver model, etc. The
309 * string is a path along hub ports, from the root. Each device's 309 * string is a path along hub ports, from the root. Each device's
310 * dev->devpath will be stable until USB is re-cabled, and hubs 310 * dev->devpath will be stable until USB is re-cabled, and hubs
311 * are often labeled with these port numbers. The bus_id isn't 311 * are often labeled with these port numbers. The name isn't
312 * as stable: bus->busnum changes easily from modprobe order, 312 * as stable: bus->busnum changes easily from modprobe order,
313 * cardbus or pci hotplugging, and so on. 313 * cardbus or pci hotplugging, and so on.
314 */ 314 */
@@ -316,7 +316,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
316 dev->devpath[0] = '0'; 316 dev->devpath[0] = '0';
317 317
318 dev->dev.parent = bus->controller; 318 dev->dev.parent = bus->controller;
319 sprintf(&dev->dev.bus_id[0], "usb%d", bus->busnum); 319 dev_set_name(&dev->dev, "usb%d", bus->busnum);
320 root_hub = 1; 320 root_hub = 1;
321 } else { 321 } else {
322 /* match any labeling on the hubs; it's one-based */ 322 /* match any labeling on the hubs; it's one-based */
@@ -328,8 +328,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
328 "%s.%d", parent->devpath, port1); 328 "%s.%d", parent->devpath, port1);
329 329
330 dev->dev.parent = &parent->dev; 330 dev->dev.parent = &parent->dev;
331 sprintf(&dev->dev.bus_id[0], "%d-%s", 331 dev_set_name(&dev->dev, "%d-%s", bus->busnum, dev->devpath);
332 bus->busnum, dev->devpath);
333 332
334 /* hub driver sets up TT records */ 333 /* hub driver sets up TT records */
335 } 334 }
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 1a8bc21c335e..d9a6e16dbf84 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -29,6 +29,8 @@ extern int usb_choose_configuration(struct usb_device *udev);
29extern void usb_kick_khubd(struct usb_device *dev); 29extern void usb_kick_khubd(struct usb_device *dev);
30extern int usb_match_device(struct usb_device *dev, 30extern int usb_match_device(struct usb_device *dev,
31 const struct usb_device_id *id); 31 const struct usb_device_id *id);
32extern void usb_forced_unbind_intf(struct usb_interface *intf);
33extern void usb_rebind_intf(struct usb_interface *intf);
32 34
33extern int usb_hub_init(void); 35extern int usb_hub_init(void);
34extern void usb_hub_cleanup(void); 36extern void usb_hub_cleanup(void);
@@ -140,26 +142,11 @@ extern struct usb_driver usbfs_driver;
140extern const struct file_operations usbfs_devices_fops; 142extern const struct file_operations usbfs_devices_fops;
141extern const struct file_operations usbdev_file_operations; 143extern const struct file_operations usbdev_file_operations;
142extern void usbfs_conn_disc_event(void); 144extern void usbfs_conn_disc_event(void);
145extern void usb_fs_classdev_common_remove(struct usb_device *udev);
143 146
144extern int usb_devio_init(void); 147extern int usb_devio_init(void);
145extern void usb_devio_cleanup(void); 148extern void usb_devio_cleanup(void);
146 149
147struct dev_state {
148 struct list_head list; /* state list */
149 struct usb_device *dev;
150 struct file *file;
151 spinlock_t lock; /* protects the async urb lists */
152 struct list_head async_pending;
153 struct list_head async_completed;
154 wait_queue_head_t wait; /* wake up if a request completed */
155 unsigned int discsignr;
156 struct pid *disc_pid;
157 uid_t disc_uid, disc_euid;
158 void __user *disccontext;
159 unsigned long ifclaimed;
160 u32 secid;
161};
162
163/* internal notify stuff */ 150/* internal notify stuff */
164extern void usb_notify_add_device(struct usb_device *udev); 151extern void usb_notify_add_device(struct usb_device *udev);
165extern void usb_notify_remove_device(struct usb_device *udev); 152extern void usb_notify_remove_device(struct usb_device *udev);
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index d6bab0d5f453..c6a8c6b1116a 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -586,6 +586,20 @@ config USB_G_PRINTER
586 For more information, see Documentation/usb/gadget_printer.txt 586 For more information, see Documentation/usb/gadget_printer.txt
587 which includes sample code for accessing the device file. 587 which includes sample code for accessing the device file.
588 588
589config USB_CDC_COMPOSITE
590 tristate "CDC Composite Device (Ethernet and ACM)"
591 depends on NET
592 help
593 This driver provides two functions in one configuration:
594 a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link.
595
596 This driver requires four bulk and two interrupt endpoints,
597 plus the ability to handle altsettings. Not all peripheral
598 controllers are that capable.
599
600 Say "y" to link the driver statically, or "m" to build a
601 dynamically linked module.
602
589# put drivers that need isochronous transfer support (for audio 603# put drivers that need isochronous transfer support (for audio
590# or video class gadget drivers), or specific hardware, here. 604# or video class gadget drivers), or specific hardware, here.
591 605
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index e258afd25faf..fcb5cb9094d9 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -22,18 +22,22 @@ obj-$(CONFIG_USB_M66592) += m66592-udc.o
22# 22#
23# USB gadget drivers 23# USB gadget drivers
24# 24#
25g_zero-objs := zero.o usbstring.o config.o epautoconf.o 25C_UTILS = composite.o usbstring.o config.o epautoconf.o
26g_ether-objs := ether.o usbstring.o config.o epautoconf.o 26
27g_serial-objs := serial.o usbstring.o config.o epautoconf.o 27g_zero-objs := zero.o f_sourcesink.o f_loopback.o $(C_UTILS)
28g_ether-objs := ether.o u_ether.o f_subset.o f_ecm.o $(C_UTILS)
29g_serial-objs := serial.o u_serial.o f_acm.o f_serial.o $(C_UTILS)
28g_midi-objs := gmidi.o usbstring.o config.o epautoconf.o 30g_midi-objs := gmidi.o usbstring.o config.o epautoconf.o
29gadgetfs-objs := inode.o 31gadgetfs-objs := inode.o
30g_file_storage-objs := file_storage.o usbstring.o config.o \ 32g_file_storage-objs := file_storage.o usbstring.o config.o \
31 epautoconf.o 33 epautoconf.o
32g_printer-objs := printer.o usbstring.o config.o \ 34g_printer-objs := printer.o usbstring.o config.o \
33 epautoconf.o 35 epautoconf.o
36g_cdc-objs := cdc2.o u_ether.o f_ecm.o \
37 u_serial.o f_acm.o $(C_UTILS)
34 38
35ifeq ($(CONFIG_USB_ETH_RNDIS),y) 39ifeq ($(CONFIG_USB_ETH_RNDIS),y)
36 g_ether-objs += rndis.o 40 g_ether-objs += f_rndis.o rndis.o
37endif 41endif
38 42
39obj-$(CONFIG_USB_ZERO) += g_zero.o 43obj-$(CONFIG_USB_ZERO) += g_zero.o
@@ -43,4 +47,5 @@ obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o
43obj-$(CONFIG_USB_G_SERIAL) += g_serial.o 47obj-$(CONFIG_USB_G_SERIAL) += g_serial.o
44obj-$(CONFIG_USB_G_PRINTER) += g_printer.o 48obj-$(CONFIG_USB_G_PRINTER) += g_printer.o
45obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o 49obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o
50obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o
46 51
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index f261d2a9a5f0..1500e1b3c302 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -3342,7 +3342,7 @@ static int udc_probe(struct udc *dev)
3342 spin_lock_init(&dev->lock); 3342 spin_lock_init(&dev->lock);
3343 dev->gadget.ops = &udc_ops; 3343 dev->gadget.ops = &udc_ops;
3344 3344
3345 strcpy(dev->gadget.dev.bus_id, "gadget"); 3345 dev_set_name(&dev->gadget.dev, "gadget");
3346 dev->gadget.dev.release = gadget_release; 3346 dev->gadget.dev.release = gadget_release;
3347 dev->gadget.name = name; 3347 dev->gadget.name = name;
3348 dev->gadget.name = name; 3348 dev->gadget.name = name;
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index b6b2a0a5ba37..e2d8a5d86c40 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1687,6 +1687,19 @@ static int __init at91udc_probe(struct platform_device *pdev)
1687 udc->board.pullup_active_low); 1687 udc->board.pullup_active_low);
1688 } 1688 }
1689 1689
1690 /* newer chips have more FIFO memory than rm9200 */
1691 if (cpu_is_at91sam9260()) {
1692 udc->ep[0].maxpacket = 64;
1693 udc->ep[3].maxpacket = 64;
1694 udc->ep[4].maxpacket = 512;
1695 udc->ep[5].maxpacket = 512;
1696 } else if (cpu_is_at91sam9261()) {
1697 udc->ep[3].maxpacket = 64;
1698 } else if (cpu_is_at91sam9263()) {
1699 udc->ep[0].maxpacket = 64;
1700 udc->ep[3].maxpacket = 64;
1701 }
1702
1690 udc->udp_baseaddr = ioremap(res->start, res->end - res->start + 1); 1703 udc->udp_baseaddr = ioremap(res->start, res->end - res->start + 1);
1691 if (!udc->udp_baseaddr) { 1704 if (!udc->udp_baseaddr) {
1692 retval = -ENOMEM; 1705 retval = -ENOMEM;
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
new file mode 100644
index 000000000000..d490d0289507
--- /dev/null
+++ b/drivers/usb/gadget/cdc2.c
@@ -0,0 +1,246 @@
1/*
2 * cdc2.c -- CDC Composite driver, with ECM and ACM support
3 *
4 * Copyright (C) 2008 David Brownell
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/kernel.h>
23#include <linux/utsname.h>
24
25#include "u_ether.h"
26#include "u_serial.h"
27
28
29#define DRIVER_DESC "CDC Composite Gadget"
30#define DRIVER_VERSION "King Kamehameha Day 2008"
31
32/*-------------------------------------------------------------------------*/
33
34/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
35 * Instead: allocate your own, using normal USB-IF procedures.
36 */
37
38/* Thanks to NetChip Technologies for donating this product ID.
39 * It's for devices with only this composite CDC configuration.
40 */
41#define CDC_VENDOR_NUM 0x0525 /* NetChip */
42#define CDC_PRODUCT_NUM 0xa4aa /* CDC Composite: ECM + ACM */
43
44/*-------------------------------------------------------------------------*/
45
46static struct usb_device_descriptor device_desc = {
47 .bLength = sizeof device_desc,
48 .bDescriptorType = USB_DT_DEVICE,
49
50 .bcdUSB = __constant_cpu_to_le16(0x0200),
51
52 .bDeviceClass = USB_CLASS_COMM,
53 .bDeviceSubClass = 0,
54 .bDeviceProtocol = 0,
55 /* .bMaxPacketSize0 = f(hardware) */
56
57 /* Vendor and product id can be overridden by module parameters. */
58 .idVendor = __constant_cpu_to_le16(CDC_VENDOR_NUM),
59 .idProduct = __constant_cpu_to_le16(CDC_PRODUCT_NUM),
60 /* .bcdDevice = f(hardware) */
61 /* .iManufacturer = DYNAMIC */
62 /* .iProduct = DYNAMIC */
63 /* NO SERIAL NUMBER */
64 .bNumConfigurations = 1,
65};
66
67static struct usb_otg_descriptor otg_descriptor = {
68 .bLength = sizeof otg_descriptor,
69 .bDescriptorType = USB_DT_OTG,
70
71 /* REVISIT SRP-only hardware is possible, although
72 * it would not be called "OTG" ...
73 */
74 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
75};
76
77static const struct usb_descriptor_header *otg_desc[] = {
78 (struct usb_descriptor_header *) &otg_descriptor,
79 NULL,
80};
81
82
83/* string IDs are assigned dynamically */
84
85#define STRING_MANUFACTURER_IDX 0
86#define STRING_PRODUCT_IDX 1
87
88static char manufacturer[50];
89
90static struct usb_string strings_dev[] = {
91 [STRING_MANUFACTURER_IDX].s = manufacturer,
92 [STRING_PRODUCT_IDX].s = DRIVER_DESC,
93 { } /* end of list */
94};
95
96static struct usb_gadget_strings stringtab_dev = {
97 .language = 0x0409, /* en-us */
98 .strings = strings_dev,
99};
100
101static struct usb_gadget_strings *dev_strings[] = {
102 &stringtab_dev,
103 NULL,
104};
105
106static u8 hostaddr[ETH_ALEN];
107
108/*-------------------------------------------------------------------------*/
109
110/*
111 * We _always_ have both CDC ECM and CDC ACM functions.
112 */
113static int __init cdc_do_config(struct usb_configuration *c)
114{
115 int status;
116
117 if (gadget_is_otg(c->cdev->gadget)) {
118 c->descriptors = otg_desc;
119 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
120 }
121
122 status = ecm_bind_config(c, hostaddr);
123 if (status < 0)
124 return status;
125
126 status = acm_bind_config(c, 0);
127 if (status < 0)
128 return status;
129
130 return 0;
131}
132
133static struct usb_configuration cdc_config_driver = {
134 .label = "CDC Composite (ECM + ACM)",
135 .bind = cdc_do_config,
136 .bConfigurationValue = 1,
137 /* .iConfiguration = DYNAMIC */
138 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
139 .bMaxPower = 1, /* 2 mA, minimal */
140};
141
142/*-------------------------------------------------------------------------*/
143
144static int __init cdc_bind(struct usb_composite_dev *cdev)
145{
146 int gcnum;
147 struct usb_gadget *gadget = cdev->gadget;
148 int status;
149
150 if (!can_support_ecm(cdev->gadget)) {
151 ERROR(cdev, "controller '%s' not usable\n", gadget->name);
152 return -EINVAL;
153 }
154
155 /* set up network link layer */
156 status = gether_setup(cdev->gadget, hostaddr);
157 if (status < 0)
158 return status;
159
160 /* set up serial link layer */
161 status = gserial_setup(cdev->gadget, 1);
162 if (status < 0)
163 goto fail0;
164
165 gcnum = usb_gadget_controller_number(gadget);
166 if (gcnum >= 0)
167 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
168 else {
169 /* We assume that can_support_ecm() tells the truth;
170 * but if the controller isn't recognized at all then
171 * that assumption is a bit more likely to be wrong.
172 */
173 WARN(cdev, "controller '%s' not recognized; trying %s\n",
174 gadget->name,
175 cdc_config_driver.label);
176 device_desc.bcdDevice =
177 __constant_cpu_to_le16(0x0300 | 0x0099);
178 }
179
180
181 /* Allocate string descriptor numbers ... note that string
182 * contents can be overridden by the composite_dev glue.
183 */
184
185 /* device descriptor strings: manufacturer, product */
186 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
187 init_utsname()->sysname, init_utsname()->release,
188 gadget->name);
189 status = usb_string_id(cdev);
190 if (status < 0)
191 goto fail1;
192 strings_dev[STRING_MANUFACTURER_IDX].id = status;
193 device_desc.iManufacturer = status;
194
195 status = usb_string_id(cdev);
196 if (status < 0)
197 goto fail1;
198 strings_dev[STRING_PRODUCT_IDX].id = status;
199 device_desc.iProduct = status;
200
201 /* register our configuration */
202 status = usb_add_config(cdev, &cdc_config_driver);
203 if (status < 0)
204 goto fail1;
205
206 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC);
207
208 return 0;
209
210fail1:
211 gserial_cleanup();
212fail0:
213 gether_cleanup();
214 return status;
215}
216
217static int __exit cdc_unbind(struct usb_composite_dev *cdev)
218{
219 gserial_cleanup();
220 gether_cleanup();
221 return 0;
222}
223
224static struct usb_composite_driver cdc_driver = {
225 .name = "g_cdc",
226 .dev = &device_desc,
227 .strings = dev_strings,
228 .bind = cdc_bind,
229 .unbind = __exit_p(cdc_unbind),
230};
231
232MODULE_DESCRIPTION(DRIVER_DESC);
233MODULE_AUTHOR("David Brownell");
234MODULE_LICENSE("GPL");
235
236static int __init init(void)
237{
238 return usb_composite_register(&cdc_driver);
239}
240module_init(init);
241
242static void __exit cleanup(void)
243{
244 usb_composite_unregister(&cdc_driver);
245}
246module_exit(cleanup);
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
new file mode 100644
index 000000000000..85c876c1f150
--- /dev/null
+++ b/drivers/usb/gadget/composite.c
@@ -0,0 +1,1041 @@
1/*
2 * composite.c - infrastructure for Composite USB Gadgets
3 *
4 * Copyright (C) 2006-2008 David Brownell
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/* #define VERBOSE_DEBUG */
22
23#include <linux/kallsyms.h>
24#include <linux/kernel.h>
25#include <linux/slab.h>
26#include <linux/device.h>
27
28#include <linux/usb/composite.h>
29
30
31/*
32 * The code in this file is utility code, used to build a gadget driver
33 * from one or more "function" drivers, one or more "configuration"
34 * objects, and a "usb_composite_driver" by gluing them together along
35 * with the relevant device-wide data.
36 */
37
38/* big enough to hold our biggest descriptor */
39#define USB_BUFSIZ 512
40
41static struct usb_composite_driver *composite;
42
43/* Some systems will need runtime overrides for the product identifers
44 * published in the device descriptor, either numbers or strings or both.
45 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters).
46 */
47
48static ushort idVendor;
49module_param(idVendor, ushort, 0);
50MODULE_PARM_DESC(idVendor, "USB Vendor ID");
51
52static ushort idProduct;
53module_param(idProduct, ushort, 0);
54MODULE_PARM_DESC(idProduct, "USB Product ID");
55
56static ushort bcdDevice;
57module_param(bcdDevice, ushort, 0);
58MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
59
60static char *iManufacturer;
61module_param(iManufacturer, charp, 0);
62MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
63
64static char *iProduct;
65module_param(iProduct, charp, 0);
66MODULE_PARM_DESC(iProduct, "USB Product string");
67
68static char *iSerialNumber;
69module_param(iSerialNumber, charp, 0);
70MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
71
72/*-------------------------------------------------------------------------*/
73
74/**
75 * usb_add_function() - add a function to a configuration
76 * @config: the configuration
77 * @function: the function being added
78 * Context: single threaded during gadget setup
79 *
80 * After initialization, each configuration must have one or more
81 * functions added to it. Adding a function involves calling its @bind()
82 * method to allocate resources such as interface and string identifiers
83 * and endpoints.
84 *
85 * This function returns the value of the function's bind(), which is
86 * zero for success else a negative errno value.
87 */
88int __init usb_add_function(struct usb_configuration *config,
89 struct usb_function *function)
90{
91 int value = -EINVAL;
92
93 DBG(config->cdev, "adding '%s'/%p to config '%s'/%p\n",
94 function->name, function,
95 config->label, config);
96
97 if (!function->set_alt || !function->disable)
98 goto done;
99
100 function->config = config;
101 list_add_tail(&function->list, &config->functions);
102
103 /* REVISIT *require* function->bind? */
104 if (function->bind) {
105 value = function->bind(config, function);
106 if (value < 0) {
107 list_del(&function->list);
108 function->config = NULL;
109 }
110 } else
111 value = 0;
112
113 /* We allow configurations that don't work at both speeds.
114 * If we run into a lowspeed Linux system, treat it the same
115 * as full speed ... it's the function drivers that will need
116 * to avoid bulk and ISO transfers.
117 */
118 if (!config->fullspeed && function->descriptors)
119 config->fullspeed = true;
120 if (!config->highspeed && function->hs_descriptors)
121 config->highspeed = true;
122
123done:
124 if (value)
125 DBG(config->cdev, "adding '%s'/%p --> %d\n",
126 function->name, function, value);
127 return value;
128}
129
130/**
131 * usb_interface_id() - allocate an unused interface ID
132 * @config: configuration associated with the interface
133 * @function: function handling the interface
134 * Context: single threaded during gadget setup
135 *
136 * usb_interface_id() is called from usb_function.bind() callbacks to
137 * allocate new interface IDs. The function driver will then store that
138 * ID in interface, association, CDC union, and other descriptors. It
139 * will also handle any control requests targetted at that interface,
140 * particularly changing its altsetting via set_alt(). There may
141 * also be class-specific or vendor-specific requests to handle.
142 *
143 * All interface identifier should be allocated using this routine, to
144 * ensure that for example different functions don't wrongly assign
145 * different meanings to the same identifier. Note that since interface
146 * identifers are configuration-specific, functions used in more than
147 * one configuration (or more than once in a given configuration) need
148 * multiple versions of the relevant descriptors.
149 *
150 * Returns the interface ID which was allocated; or -ENODEV if no
151 * more interface IDs can be allocated.
152 */
153int __init usb_interface_id(struct usb_configuration *config,
154 struct usb_function *function)
155{
156 unsigned id = config->next_interface_id;
157
158 if (id < MAX_CONFIG_INTERFACES) {
159 config->interface[id] = function;
160 config->next_interface_id = id + 1;
161 return id;
162 }
163 return -ENODEV;
164}
165
166static int config_buf(struct usb_configuration *config,
167 enum usb_device_speed speed, void *buf, u8 type)
168{
169 struct usb_config_descriptor *c = buf;
170 void *next = buf + USB_DT_CONFIG_SIZE;
171 int len = USB_BUFSIZ - USB_DT_CONFIG_SIZE;
172 struct usb_function *f;
173 int status;
174
175 /* write the config descriptor */
176 c = buf;
177 c->bLength = USB_DT_CONFIG_SIZE;
178 c->bDescriptorType = type;
179 /* wTotalLength is written later */
180 c->bNumInterfaces = config->next_interface_id;
181 c->bConfigurationValue = config->bConfigurationValue;
182 c->iConfiguration = config->iConfiguration;
183 c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes;
184 c->bMaxPower = config->bMaxPower;
185
186 /* There may be e.g. OTG descriptors */
187 if (config->descriptors) {
188 status = usb_descriptor_fillbuf(next, len,
189 config->descriptors);
190 if (status < 0)
191 return status;
192 len -= status;
193 next += status;
194 }
195
196 /* add each function's descriptors */
197 list_for_each_entry(f, &config->functions, list) {
198 struct usb_descriptor_header **descriptors;
199
200 if (speed == USB_SPEED_HIGH)
201 descriptors = f->hs_descriptors;
202 else
203 descriptors = f->descriptors;
204 if (!descriptors)
205 continue;
206 status = usb_descriptor_fillbuf(next, len,
207 (const struct usb_descriptor_header **) descriptors);
208 if (status < 0)
209 return status;
210 len -= status;
211 next += status;
212 }
213
214 len = next - buf;
215 c->wTotalLength = cpu_to_le16(len);
216 return len;
217}
218
219static int config_desc(struct usb_composite_dev *cdev, unsigned w_value)
220{
221 struct usb_gadget *gadget = cdev->gadget;
222 struct usb_configuration *c;
223 u8 type = w_value >> 8;
224 enum usb_device_speed speed = USB_SPEED_UNKNOWN;
225
226 if (gadget_is_dualspeed(gadget)) {
227 int hs = 0;
228
229 if (gadget->speed == USB_SPEED_HIGH)
230 hs = 1;
231 if (type == USB_DT_OTHER_SPEED_CONFIG)
232 hs = !hs;
233 if (hs)
234 speed = USB_SPEED_HIGH;
235
236 }
237
238 /* This is a lookup by config *INDEX* */
239 w_value &= 0xff;
240 list_for_each_entry(c, &cdev->configs, list) {
241 /* ignore configs that won't work at this speed */
242 if (speed == USB_SPEED_HIGH) {
243 if (!c->highspeed)
244 continue;
245 } else {
246 if (!c->fullspeed)
247 continue;
248 }
249 if (w_value == 0)
250 return config_buf(c, speed, cdev->req->buf, type);
251 w_value--;
252 }
253 return -EINVAL;
254}
255
256static int count_configs(struct usb_composite_dev *cdev, unsigned type)
257{
258 struct usb_gadget *gadget = cdev->gadget;
259 struct usb_configuration *c;
260 unsigned count = 0;
261 int hs = 0;
262
263 if (gadget_is_dualspeed(gadget)) {
264 if (gadget->speed == USB_SPEED_HIGH)
265 hs = 1;
266 if (type == USB_DT_DEVICE_QUALIFIER)
267 hs = !hs;
268 }
269 list_for_each_entry(c, &cdev->configs, list) {
270 /* ignore configs that won't work at this speed */
271 if (hs) {
272 if (!c->highspeed)
273 continue;
274 } else {
275 if (!c->fullspeed)
276 continue;
277 }
278 count++;
279 }
280 return count;
281}
282
283static void device_qual(struct usb_composite_dev *cdev)
284{
285 struct usb_qualifier_descriptor *qual = cdev->req->buf;
286
287 qual->bLength = sizeof(*qual);
288 qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER;
289 /* POLICY: same bcdUSB and device type info at both speeds */
290 qual->bcdUSB = cdev->desc.bcdUSB;
291 qual->bDeviceClass = cdev->desc.bDeviceClass;
292 qual->bDeviceSubClass = cdev->desc.bDeviceSubClass;
293 qual->bDeviceProtocol = cdev->desc.bDeviceProtocol;
294 /* ASSUME same EP0 fifo size at both speeds */
295 qual->bMaxPacketSize0 = cdev->desc.bMaxPacketSize0;
296 qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER);
297 qual->bRESERVED = 0;
298}
299
300/*-------------------------------------------------------------------------*/
301
302static void reset_config(struct usb_composite_dev *cdev)
303{
304 struct usb_function *f;
305
306 DBG(cdev, "reset config\n");
307
308 list_for_each_entry(f, &cdev->config->functions, list) {
309 if (f->disable)
310 f->disable(f);
311 }
312 cdev->config = NULL;
313}
314
315static int set_config(struct usb_composite_dev *cdev,
316 const struct usb_ctrlrequest *ctrl, unsigned number)
317{
318 struct usb_gadget *gadget = cdev->gadget;
319 struct usb_configuration *c = NULL;
320 int result = -EINVAL;
321 unsigned power = gadget_is_otg(gadget) ? 8 : 100;
322 int tmp;
323
324 if (cdev->config)
325 reset_config(cdev);
326
327 if (number) {
328 list_for_each_entry(c, &cdev->configs, list) {
329 if (c->bConfigurationValue == number) {
330 result = 0;
331 break;
332 }
333 }
334 if (result < 0)
335 goto done;
336 } else
337 result = 0;
338
339 INFO(cdev, "%s speed config #%d: %s\n",
340 ({ char *speed;
341 switch (gadget->speed) {
342 case USB_SPEED_LOW: speed = "low"; break;
343 case USB_SPEED_FULL: speed = "full"; break;
344 case USB_SPEED_HIGH: speed = "high"; break;
345 default: speed = "?"; break;
346 } ; speed; }), number, c ? c->label : "unconfigured");
347
348 if (!c)
349 goto done;
350
351 cdev->config = c;
352
353 /* Initialize all interfaces by setting them to altsetting zero. */
354 for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) {
355 struct usb_function *f = c->interface[tmp];
356
357 if (!f)
358 break;
359
360 result = f->set_alt(f, tmp, 0);
361 if (result < 0) {
362 DBG(cdev, "interface %d (%s/%p) alt 0 --> %d\n",
363 tmp, f->name, f, result);
364
365 reset_config(cdev);
366 goto done;
367 }
368 }
369
370 /* when we return, be sure our power usage is valid */
371 power = 2 * c->bMaxPower;
372done:
373 usb_gadget_vbus_draw(gadget, power);
374 return result;
375}
376
377/**
378 * usb_add_config() - add a configuration to a device.
379 * @cdev: wraps the USB gadget
380 * @config: the configuration, with bConfigurationValue assigned
381 * Context: single threaded during gadget setup
382 *
383 * One of the main tasks of a composite driver's bind() routine is to
384 * add each of the configurations it supports, using this routine.
385 *
386 * This function returns the value of the configuration's bind(), which
387 * is zero for success else a negative errno value. Binding configurations
388 * assigns global resources including string IDs, and per-configuration
389 * resources such as interface IDs and endpoints.
390 */
391int __init usb_add_config(struct usb_composite_dev *cdev,
392 struct usb_configuration *config)
393{
394 int status = -EINVAL;
395 struct usb_configuration *c;
396
397 DBG(cdev, "adding config #%u '%s'/%p\n",
398 config->bConfigurationValue,
399 config->label, config);
400
401 if (!config->bConfigurationValue || !config->bind)
402 goto done;
403
404 /* Prevent duplicate configuration identifiers */
405 list_for_each_entry(c, &cdev->configs, list) {
406 if (c->bConfigurationValue == config->bConfigurationValue) {
407 status = -EBUSY;
408 goto done;
409 }
410 }
411
412 config->cdev = cdev;
413 list_add_tail(&config->list, &cdev->configs);
414
415 INIT_LIST_HEAD(&config->functions);
416 config->next_interface_id = 0;
417
418 status = config->bind(config);
419 if (status < 0) {
420 list_del(&config->list);
421 config->cdev = NULL;
422 } else {
423 unsigned i;
424
425 DBG(cdev, "cfg %d/%p speeds:%s%s\n",
426 config->bConfigurationValue, config,
427 config->highspeed ? " high" : "",
428 config->fullspeed
429 ? (gadget_is_dualspeed(cdev->gadget)
430 ? " full"
431 : " full/low")
432 : "");
433
434 for (i = 0; i < MAX_CONFIG_INTERFACES; i++) {
435 struct usb_function *f = config->interface[i];
436
437 if (!f)
438 continue;
439 DBG(cdev, " interface %d = %s/%p\n",
440 i, f->name, f);
441 }
442 }
443
444 /* set_alt(), or next config->bind(), sets up
445 * ep->driver_data as needed.
446 */
447 usb_ep_autoconfig_reset(cdev->gadget);
448
449done:
450 if (status)
451 DBG(cdev, "added config '%s'/%u --> %d\n", config->label,
452 config->bConfigurationValue, status);
453 return status;
454}
455
456/*-------------------------------------------------------------------------*/
457
458/* We support strings in multiple languages ... string descriptor zero
459 * says which languages are supported. The typical case will be that
460 * only one language (probably English) is used, with I18N handled on
461 * the host side.
462 */
463
464static void collect_langs(struct usb_gadget_strings **sp, __le16 *buf)
465{
466 const struct usb_gadget_strings *s;
467 u16 language;
468 __le16 *tmp;
469
470 while (*sp) {
471 s = *sp;
472 language = cpu_to_le16(s->language);
473 for (tmp = buf; *tmp && tmp < &buf[126]; tmp++) {
474 if (*tmp == language)
475 goto repeat;
476 }
477 *tmp++ = language;
478repeat:
479 sp++;
480 }
481}
482
483static int lookup_string(
484 struct usb_gadget_strings **sp,
485 void *buf,
486 u16 language,
487 int id
488)
489{
490 struct usb_gadget_strings *s;
491 int value;
492
493 while (*sp) {
494 s = *sp++;
495 if (s->language != language)
496 continue;
497 value = usb_gadget_get_string(s, id, buf);
498 if (value > 0)
499 return value;
500 }
501 return -EINVAL;
502}
503
504static int get_string(struct usb_composite_dev *cdev,
505 void *buf, u16 language, int id)
506{
507 struct usb_configuration *c;
508 struct usb_function *f;
509 int len;
510
511 /* Yes, not only is USB's I18N support probably more than most
512 * folk will ever care about ... also, it's all supported here.
513 * (Except for UTF8 support for Unicode's "Astral Planes".)
514 */
515
516 /* 0 == report all available language codes */
517 if (id == 0) {
518 struct usb_string_descriptor *s = buf;
519 struct usb_gadget_strings **sp;
520
521 memset(s, 0, 256);
522 s->bDescriptorType = USB_DT_STRING;
523
524 sp = composite->strings;
525 if (sp)
526 collect_langs(sp, s->wData);
527
528 list_for_each_entry(c, &cdev->configs, list) {
529 sp = c->strings;
530 if (sp)
531 collect_langs(sp, s->wData);
532
533 list_for_each_entry(f, &c->functions, list) {
534 sp = f->strings;
535 if (sp)
536 collect_langs(sp, s->wData);
537 }
538 }
539
540 for (len = 0; s->wData[len] && len <= 126; len++)
541 continue;
542 if (!len)
543 return -EINVAL;
544
545 s->bLength = 2 * (len + 1);
546 return s->bLength;
547 }
548
549 /* Otherwise, look up and return a specified string. String IDs
550 * are device-scoped, so we look up each string table we're told
551 * about. These lookups are infrequent; simpler-is-better here.
552 */
553 if (composite->strings) {
554 len = lookup_string(composite->strings, buf, language, id);
555 if (len > 0)
556 return len;
557 }
558 list_for_each_entry(c, &cdev->configs, list) {
559 if (c->strings) {
560 len = lookup_string(c->strings, buf, language, id);
561 if (len > 0)
562 return len;
563 }
564 list_for_each_entry(f, &c->functions, list) {
565 if (!f->strings)
566 continue;
567 len = lookup_string(f->strings, buf, language, id);
568 if (len > 0)
569 return len;
570 }
571 }
572 return -EINVAL;
573}
574
575/**
576 * usb_string_id() - allocate an unused string ID
577 * @cdev: the device whose string descriptor IDs are being allocated
578 * Context: single threaded during gadget setup
579 *
580 * @usb_string_id() is called from bind() callbacks to allocate
581 * string IDs. Drivers for functions, configurations, or gadgets will
582 * then store that ID in the appropriate descriptors and string table.
583 *
584 * All string identifier should be allocated using this routine, to
585 * ensure that for example different functions don't wrongly assign
586 * different meanings to the same identifier.
587 */
588int __init usb_string_id(struct usb_composite_dev *cdev)
589{
590 if (cdev->next_string_id < 254) {
591 /* string id 0 is reserved */
592 cdev->next_string_id++;
593 return cdev->next_string_id;
594 }
595 return -ENODEV;
596}
597
598/*-------------------------------------------------------------------------*/
599
600static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req)
601{
602 if (req->status || req->actual != req->length)
603 DBG((struct usb_composite_dev *) ep->driver_data,
604 "setup complete --> %d, %d/%d\n",
605 req->status, req->actual, req->length);
606}
607
608/*
609 * The setup() callback implements all the ep0 functionality that's
610 * not handled lower down, in hardware or the hardware driver(like
611 * device and endpoint feature flags, and their status). It's all
612 * housekeeping for the gadget function we're implementing. Most of
613 * the work is in config and function specific setup.
614 */
615static int
616composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
617{
618 struct usb_composite_dev *cdev = get_gadget_data(gadget);
619 struct usb_request *req = cdev->req;
620 int value = -EOPNOTSUPP;
621 u16 w_index = le16_to_cpu(ctrl->wIndex);
622 u16 w_value = le16_to_cpu(ctrl->wValue);
623 u16 w_length = le16_to_cpu(ctrl->wLength);
624 struct usb_function *f = NULL;
625
626 /* partial re-init of the response message; the function or the
627 * gadget might need to intercept e.g. a control-OUT completion
628 * when we delegate to it.
629 */
630 req->zero = 0;
631 req->complete = composite_setup_complete;
632 req->length = USB_BUFSIZ;
633 gadget->ep0->driver_data = cdev;
634
635 switch (ctrl->bRequest) {
636
637 /* we handle all standard USB descriptors */
638 case USB_REQ_GET_DESCRIPTOR:
639 if (ctrl->bRequestType != USB_DIR_IN)
640 goto unknown;
641 switch (w_value >> 8) {
642
643 case USB_DT_DEVICE:
644 cdev->desc.bNumConfigurations =
645 count_configs(cdev, USB_DT_DEVICE);
646 value = min(w_length, (u16) sizeof cdev->desc);
647 memcpy(req->buf, &cdev->desc, value);
648 break;
649 case USB_DT_DEVICE_QUALIFIER:
650 if (!gadget_is_dualspeed(gadget))
651 break;
652 device_qual(cdev);
653 value = min_t(int, w_length,
654 sizeof(struct usb_qualifier_descriptor));
655 break;
656 case USB_DT_OTHER_SPEED_CONFIG:
657 if (!gadget_is_dualspeed(gadget))
658 break;
659 /* FALLTHROUGH */
660 case USB_DT_CONFIG:
661 value = config_desc(cdev, w_value);
662 if (value >= 0)
663 value = min(w_length, (u16) value);
664 break;
665 case USB_DT_STRING:
666 value = get_string(cdev, req->buf,
667 w_index, w_value & 0xff);
668 if (value >= 0)
669 value = min(w_length, (u16) value);
670 break;
671 }
672 break;
673
674 /* any number of configs can work */
675 case USB_REQ_SET_CONFIGURATION:
676 if (ctrl->bRequestType != 0)
677 goto unknown;
678 if (gadget_is_otg(gadget)) {
679 if (gadget->a_hnp_support)
680 DBG(cdev, "HNP available\n");
681 else if (gadget->a_alt_hnp_support)
682 DBG(cdev, "HNP on another port\n");
683 else
684 VDBG(cdev, "HNP inactive\n");
685 }
686 spin_lock(&cdev->lock);
687 value = set_config(cdev, ctrl, w_value);
688 spin_unlock(&cdev->lock);
689 break;
690 case USB_REQ_GET_CONFIGURATION:
691 if (ctrl->bRequestType != USB_DIR_IN)
692 goto unknown;
693 if (cdev->config)
694 *(u8 *)req->buf = cdev->config->bConfigurationValue;
695 else
696 *(u8 *)req->buf = 0;
697 value = min(w_length, (u16) 1);
698 break;
699
700 /* function drivers must handle get/set altsetting; if there's
701 * no get() method, we know only altsetting zero works.
702 */
703 case USB_REQ_SET_INTERFACE:
704 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
705 goto unknown;
706 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
707 break;
708 f = cdev->config->interface[w_index];
709 if (!f)
710 break;
711 if (w_value && !f->get_alt)
712 break;
713 value = f->set_alt(f, w_index, w_value);
714 break;
715 case USB_REQ_GET_INTERFACE:
716 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
717 goto unknown;
718 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
719 break;
720 f = cdev->config->interface[w_index];
721 if (!f)
722 break;
723 /* lots of interfaces only need altsetting zero... */
724 value = f->get_alt ? f->get_alt(f, w_index) : 0;
725 if (value < 0)
726 break;
727 *((u8 *)req->buf) = value;
728 value = min(w_length, (u16) 1);
729 break;
730 default:
731unknown:
732 VDBG(cdev,
733 "non-core control req%02x.%02x v%04x i%04x l%d\n",
734 ctrl->bRequestType, ctrl->bRequest,
735 w_value, w_index, w_length);
736
737 /* functions always handle their interfaces ... punt other
738 * recipients (endpoint, other, WUSB, ...) to the current
739 * configuration code.
740 *
741 * REVISIT it could make sense to let the composite device
742 * take such requests too, if that's ever needed: to work
743 * in config 0, etc.
744 */
745 if ((ctrl->bRequestType & USB_RECIP_MASK)
746 == USB_RECIP_INTERFACE) {
747 f = cdev->config->interface[w_index];
748 if (f && f->setup)
749 value = f->setup(f, ctrl);
750 else
751 f = NULL;
752 }
753 if (value < 0 && !f) {
754 struct usb_configuration *c;
755
756 c = cdev->config;
757 if (c && c->setup)
758 value = c->setup(c, ctrl);
759 }
760
761 goto done;
762 }
763
764 /* respond with data transfer before status phase? */
765 if (value >= 0) {
766 req->length = value;
767 req->zero = value < w_length;
768 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
769 if (value < 0) {
770 DBG(cdev, "ep_queue --> %d\n", value);
771 req->status = 0;
772 composite_setup_complete(gadget->ep0, req);
773 }
774 }
775
776done:
777 /* device either stalls (value < 0) or reports success */
778 return value;
779}
780
781static void composite_disconnect(struct usb_gadget *gadget)
782{
783 struct usb_composite_dev *cdev = get_gadget_data(gadget);
784 unsigned long flags;
785
786 /* REVISIT: should we have config and device level
787 * disconnect callbacks?
788 */
789 spin_lock_irqsave(&cdev->lock, flags);
790 if (cdev->config)
791 reset_config(cdev);
792 spin_unlock_irqrestore(&cdev->lock, flags);
793}
794
795/*-------------------------------------------------------------------------*/
796
797static void /* __init_or_exit */
798composite_unbind(struct usb_gadget *gadget)
799{
800 struct usb_composite_dev *cdev = get_gadget_data(gadget);
801
802 /* composite_disconnect() must already have been called
803 * by the underlying peripheral controller driver!
804 * so there's no i/o concurrency that could affect the
805 * state protected by cdev->lock.
806 */
807 WARN_ON(cdev->config);
808
809 while (!list_empty(&cdev->configs)) {
810 struct usb_configuration *c;
811
812 c = list_first_entry(&cdev->configs,
813 struct usb_configuration, list);
814 while (!list_empty(&c->functions)) {
815 struct usb_function *f;
816
817 f = list_first_entry(&c->functions,
818 struct usb_function, list);
819 list_del(&f->list);
820 if (f->unbind) {
821 DBG(cdev, "unbind function '%s'/%p\n",
822 f->name, f);
823 f->unbind(c, f);
824 /* may free memory for "f" */
825 }
826 }
827 list_del(&c->list);
828 if (c->unbind) {
829 DBG(cdev, "unbind config '%s'/%p\n", c->label, c);
830 c->unbind(c);
831 /* may free memory for "c" */
832 }
833 }
834 if (composite->unbind)
835 composite->unbind(cdev);
836
837 if (cdev->req) {
838 kfree(cdev->req->buf);
839 usb_ep_free_request(gadget->ep0, cdev->req);
840 }
841 kfree(cdev);
842 set_gadget_data(gadget, NULL);
843 composite = NULL;
844}
845
846static void __init
847string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s)
848{
849 struct usb_string *str = tab->strings;
850
851 for (str = tab->strings; str->s; str++) {
852 if (str->id == id) {
853 str->s = s;
854 return;
855 }
856 }
857}
858
859static void __init
860string_override(struct usb_gadget_strings **tab, u8 id, const char *s)
861{
862 while (*tab) {
863 string_override_one(*tab, id, s);
864 tab++;
865 }
866}
867
868static int __init composite_bind(struct usb_gadget *gadget)
869{
870 struct usb_composite_dev *cdev;
871 int status = -ENOMEM;
872
873 cdev = kzalloc(sizeof *cdev, GFP_KERNEL);
874 if (!cdev)
875 return status;
876
877 spin_lock_init(&cdev->lock);
878 cdev->gadget = gadget;
879 set_gadget_data(gadget, cdev);
880 INIT_LIST_HEAD(&cdev->configs);
881
882 /* preallocate control response and buffer */
883 cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
884 if (!cdev->req)
885 goto fail;
886 cdev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
887 if (!cdev->req->buf)
888 goto fail;
889 cdev->req->complete = composite_setup_complete;
890 gadget->ep0->driver_data = cdev;
891
892 cdev->bufsiz = USB_BUFSIZ;
893 cdev->driver = composite;
894
895 usb_gadget_set_selfpowered(gadget);
896
897 /* interface and string IDs start at zero via kzalloc.
898 * we force endpoints to start unassigned; few controller
899 * drivers will zero ep->driver_data.
900 */
901 usb_ep_autoconfig_reset(cdev->gadget);
902
903 /* composite gadget needs to assign strings for whole device (like
904 * serial number), register function drivers, potentially update
905 * power state and consumption, etc
906 */
907 status = composite->bind(cdev);
908 if (status < 0)
909 goto fail;
910
911 cdev->desc = *composite->dev;
912 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
913
914 /* standardized runtime overrides for device ID data */
915 if (idVendor)
916 cdev->desc.idVendor = cpu_to_le16(idVendor);
917 if (idProduct)
918 cdev->desc.idProduct = cpu_to_le16(idProduct);
919 if (bcdDevice)
920 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
921
922 /* strings can't be assigned before bind() allocates the
923 * releavnt identifiers
924 */
925 if (cdev->desc.iManufacturer && iManufacturer)
926 string_override(composite->strings,
927 cdev->desc.iManufacturer, iManufacturer);
928 if (cdev->desc.iProduct && iProduct)
929 string_override(composite->strings,
930 cdev->desc.iProduct, iProduct);
931 if (cdev->desc.iSerialNumber && iSerialNumber)
932 string_override(composite->strings,
933 cdev->desc.iSerialNumber, iSerialNumber);
934
935 INFO(cdev, "%s ready\n", composite->name);
936 return 0;
937
938fail:
939 composite_unbind(gadget);
940 return status;
941}
942
943/*-------------------------------------------------------------------------*/
944
945static void
946composite_suspend(struct usb_gadget *gadget)
947{
948 struct usb_composite_dev *cdev = get_gadget_data(gadget);
949 struct usb_function *f;
950
951 /* REVISIT: should we have config and device level
952 * suspend/resume callbacks?
953 */
954 DBG(cdev, "suspend\n");
955 if (cdev->config) {
956 list_for_each_entry(f, &cdev->config->functions, list) {
957 if (f->suspend)
958 f->suspend(f);
959 }
960 }
961}
962
963static void
964composite_resume(struct usb_gadget *gadget)
965{
966 struct usb_composite_dev *cdev = get_gadget_data(gadget);
967 struct usb_function *f;
968
969 /* REVISIT: should we have config and device level
970 * suspend/resume callbacks?
971 */
972 DBG(cdev, "resume\n");
973 if (cdev->config) {
974 list_for_each_entry(f, &cdev->config->functions, list) {
975 if (f->resume)
976 f->resume(f);
977 }
978 }
979}
980
981/*-------------------------------------------------------------------------*/
982
983static struct usb_gadget_driver composite_driver = {
984 .speed = USB_SPEED_HIGH,
985
986 .bind = composite_bind,
987 .unbind = __exit_p(composite_unbind),
988
989 .setup = composite_setup,
990 .disconnect = composite_disconnect,
991
992 .suspend = composite_suspend,
993 .resume = composite_resume,
994
995 .driver = {
996 .owner = THIS_MODULE,
997 },
998};
999
1000/**
1001 * usb_composite_register() - register a composite driver
1002 * @driver: the driver to register
1003 * Context: single threaded during gadget setup
1004 *
1005 * This function is used to register drivers using the composite driver
1006 * framework. The return value is zero, or a negative errno value.
1007 * Those values normally come from the driver's @bind method, which does
1008 * all the work of setting up the driver to match the hardware.
1009 *
1010 * On successful return, the gadget is ready to respond to requests from
1011 * the host, unless one of its components invokes usb_gadget_disconnect()
1012 * while it was binding. That would usually be done in order to wait for
1013 * some userspace participation.
1014 */
1015int __init usb_composite_register(struct usb_composite_driver *driver)
1016{
1017 if (!driver || !driver->dev || !driver->bind || composite)
1018 return -EINVAL;
1019
1020 if (!driver->name)
1021 driver->name = "composite";
1022 composite_driver.function = (char *) driver->name;
1023 composite_driver.driver.name = driver->name;
1024 composite = driver;
1025
1026 return usb_gadget_register_driver(&composite_driver);
1027}
1028
1029/**
1030 * usb_composite_unregister() - unregister a composite driver
1031 * @driver: the driver to unregister
1032 *
1033 * This function is used to unregister drivers using the composite
1034 * driver framework.
1035 */
1036void __exit usb_composite_unregister(struct usb_composite_driver *driver)
1037{
1038 if (composite != driver)
1039 return;
1040 usb_gadget_unregister_driver(&composite_driver);
1041}
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
index a4e54b2743f0..1ca1c326392a 100644
--- a/drivers/usb/gadget/config.c
+++ b/drivers/usb/gadget/config.c
@@ -96,7 +96,7 @@ int usb_gadget_config_buf(
96 /* config descriptor first */ 96 /* config descriptor first */
97 if (length < USB_DT_CONFIG_SIZE || !desc) 97 if (length < USB_DT_CONFIG_SIZE || !desc)
98 return -EINVAL; 98 return -EINVAL;
99 *cp = *config; 99 *cp = *config;
100 100
101 /* then interface/endpoint/class/vendor/... */ 101 /* then interface/endpoint/class/vendor/... */
102 len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf, 102 len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
@@ -115,3 +115,77 @@ int usb_gadget_config_buf(
115 return len; 115 return len;
116} 116}
117 117
118/**
119 * usb_copy_descriptors - copy a vector of USB descriptors
120 * @src: null-terminated vector to copy
121 * Context: initialization code, which may sleep
122 *
123 * This makes a copy of a vector of USB descriptors. Its primary use
124 * is to support usb_function objects which can have multiple copies,
125 * each needing different descriptors. Functions may have static
126 * tables of descriptors, which are used as templates and customized
127 * with identifiers (for interfaces, strings, endpoints, and more)
128 * as needed by a given function instance.
129 */
130struct usb_descriptor_header **__init
131usb_copy_descriptors(struct usb_descriptor_header **src)
132{
133 struct usb_descriptor_header **tmp;
134 unsigned bytes;
135 unsigned n_desc;
136 void *mem;
137 struct usb_descriptor_header **ret;
138
139 /* count descriptors and their sizes; then add vector size */
140 for (bytes = 0, n_desc = 0, tmp = src; *tmp; tmp++, n_desc++)
141 bytes += (*tmp)->bLength;
142 bytes += (n_desc + 1) * sizeof(*tmp);
143
144 mem = kmalloc(bytes, GFP_KERNEL);
145 if (!mem)
146 return NULL;
147
148 /* fill in pointers starting at "tmp",
149 * to descriptors copied starting at "mem";
150 * and return "ret"
151 */
152 tmp = mem;
153 ret = mem;
154 mem += (n_desc + 1) * sizeof(*tmp);
155 while (*src) {
156 memcpy(mem, *src, (*src)->bLength);
157 *tmp = mem;
158 tmp++;
159 mem += (*src)->bLength;
160 src++;
161 }
162 *tmp = NULL;
163
164 return ret;
165}
166
167/**
168 * usb_find_endpoint - find a copy of an endpoint descriptor
169 * @src: original vector of descriptors
170 * @copy: copy of @src
171 * @ep: endpoint descriptor found in @src
172 *
173 * This returns the copy of the @match descriptor made for @copy. Its
174 * intended use is to help remembering the endpoint descriptor to use
175 * when enabling a given endpoint.
176 */
177struct usb_endpoint_descriptor *__init
178usb_find_endpoint(
179 struct usb_descriptor_header **src,
180 struct usb_descriptor_header **copy,
181 struct usb_endpoint_descriptor *match
182)
183{
184 while (*src) {
185 if (*src == (void *) match)
186 return (void *)*copy;
187 src++;
188 copy++;
189 }
190 return NULL;
191}
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 42036192a03c..21d1406af9ee 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -862,7 +862,7 @@ static int dummy_udc_probe (struct platform_device *pdev)
862 /* maybe claim OTG support, though we won't complete HNP */ 862 /* maybe claim OTG support, though we won't complete HNP */
863 dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0); 863 dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0);
864 864
865 strcpy (dum->gadget.dev.bus_id, "gadget"); 865 dev_set_name(&dum->gadget.dev, "gadget");
866 dum->gadget.dev.parent = &pdev->dev; 866 dum->gadget.dev.parent = &pdev->dev;
867 dum->gadget.dev.release = dummy_gadget_release; 867 dum->gadget.dev.release = dummy_gadget_release;
868 rc = device_register (&dum->gadget.dev); 868 rc = device_register (&dum->gadget.dev);
@@ -1865,7 +1865,7 @@ static int dummy_hcd_probe(struct platform_device *pdev)
1865 1865
1866 dev_info(&pdev->dev, "%s, driver " DRIVER_VERSION "\n", driver_desc); 1866 dev_info(&pdev->dev, "%s, driver " DRIVER_VERSION "\n", driver_desc);
1867 1867
1868 hcd = usb_create_hcd(&dummy_hcd, &pdev->dev, pdev->dev.bus_id); 1868 hcd = usb_create_hcd(&dummy_hcd, &pdev->dev, dev_name(&pdev->dev));
1869 if (!hcd) 1869 if (!hcd)
1870 return -ENOMEM; 1870 return -ENOMEM;
1871 the_controller = hcd_to_dummy (hcd); 1871 the_controller = hcd_to_dummy (hcd);
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 8bdad221fa91..9462e30192d8 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -159,6 +159,7 @@ ep_matches (
159 /* MATCH!! */ 159 /* MATCH!! */
160 160
161 /* report address */ 161 /* report address */
162 desc->bEndpointAddress &= USB_DIR_IN;
162 if (isdigit (ep->name [2])) { 163 if (isdigit (ep->name [2])) {
163 u8 num = simple_strtol (&ep->name [2], NULL, 10); 164 u8 num = simple_strtol (&ep->name [2], NULL, 10);
164 desc->bEndpointAddress |= num; 165 desc->bEndpointAddress |= num;
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 4ce3950b997f..d7aaaa29b1e1 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -1,8 +1,9 @@
1/* 1/*
2 * ether.c -- Ethernet gadget driver, with CDC and non-CDC options 2 * ether.c -- Ethernet gadget driver, with CDC and non-CDC options
3 * 3 *
4 * Copyright (C) 2003-2005 David Brownell 4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger 5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -23,18 +24,9 @@
23 24
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/utsname.h> 26#include <linux/utsname.h>
26#include <linux/device.h>
27#include <linux/ctype.h>
28#include <linux/etherdevice.h>
29#include <linux/ethtool.h>
30 27
31#include <linux/usb/ch9.h> 28#include "u_ether.h"
32#include <linux/usb/cdc.h>
33#include <linux/usb/gadget.h>
34 29
35#include "gadget_chips.h"
36
37/*-------------------------------------------------------------------------*/
38 30
39/* 31/*
40 * Ethernet gadget driver -- with CDC and non-CDC options 32 * Ethernet gadget driver -- with CDC and non-CDC options
@@ -46,7 +38,11 @@
46 * this USB-IF standard as its open-systems interoperability solution; 38 * this USB-IF standard as its open-systems interoperability solution;
47 * most host side USB stacks (except from Microsoft) support it. 39 * most host side USB stacks (except from Microsoft) support it.
48 * 40 *
49 * There's some hardware that can't talk CDC. We make that hardware 41 * This is sometimes called "CDC ECM" (Ethernet Control Model) to support
42 * TLA-soup. "CDC ACM" (Abstract Control Model) is for modems, and a new
43 * "CDC EEM" (Ethernet Emulation Model) is starting to spread.
44 *
45 * There's some hardware that can't talk CDC ECM. We make that hardware
50 * implement a "minimalist" vendor-agnostic CDC core: same framing, but 46 * implement a "minimalist" vendor-agnostic CDC core: same framing, but
51 * link-level setup only requires activating the configuration. Only the 47 * link-level setup only requires activating the configuration. Only the
52 * endpoint descriptors, and product/vendor IDs, are relevant; no control 48 * endpoint descriptors, and product/vendor IDs, are relevant; no control
@@ -64,70 +60,40 @@
64 * A third option is also in use. Rather than CDC Ethernet, or something 60 * A third option is also in use. Rather than CDC Ethernet, or something
65 * simpler, Microsoft pushes their own approach: RNDIS. The published 61 * simpler, Microsoft pushes their own approach: RNDIS. The published
66 * RNDIS specs are ambiguous and appear to be incomplete, and are also 62 * RNDIS specs are ambiguous and appear to be incomplete, and are also
67 * needlessly complex. 63 * needlessly complex. They borrow more from CDC ACM than CDC ECM.
68 */ 64 */
69 65
70#define DRIVER_DESC "Ethernet Gadget" 66#define DRIVER_DESC "Ethernet Gadget"
71#define DRIVER_VERSION "May Day 2005" 67#define DRIVER_VERSION "Memorial Day 2008"
72
73static const char shortname [] = "ether";
74static const char driver_desc [] = DRIVER_DESC;
75
76#define RX_EXTRA 20 /* guard against rx overflows */
77
78#include "rndis.h"
79 68
80#ifndef CONFIG_USB_ETH_RNDIS 69#ifdef CONFIG_USB_ETH_RNDIS
81#define rndis_uninit(x) do{}while(0) 70#define PREFIX "RNDIS/"
82#define rndis_deregister(c) do{}while(0) 71#else
83#define rndis_exit() do{}while(0) 72#define PREFIX ""
84#endif 73#endif
85 74
86/* CDC and RNDIS support the same host-chosen outgoing packet filters. */ 75/*
87#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \ 76 * This driver aims for interoperability by using CDC ECM unless
88 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \ 77 *
89 |USB_CDC_PACKET_TYPE_PROMISCUOUS \ 78 * can_support_ecm()
90 |USB_CDC_PACKET_TYPE_DIRECTED) 79 *
91 80 * returns false, in which case it supports the CDC Subset. By default,
92 81 * that returns true; most hardware has no problems with CDC ECM, that's
93/*-------------------------------------------------------------------------*/ 82 * a good default. Previous versions of this driver had no default; this
94 83 * version changes that, removing overhead for new controller support.
95struct eth_dev {
96 spinlock_t lock;
97 struct usb_gadget *gadget;
98 struct usb_request *req; /* for control responses */
99 struct usb_request *stat_req; /* for cdc & rndis status */
100
101 u8 config;
102 struct usb_ep *in_ep, *out_ep, *status_ep;
103 const struct usb_endpoint_descriptor
104 *in, *out, *status;
105
106 spinlock_t req_lock;
107 struct list_head tx_reqs, rx_reqs;
108
109 struct net_device *net;
110 struct net_device_stats stats;
111 atomic_t tx_qlen;
112
113 struct work_struct work;
114 unsigned zlp:1;
115 unsigned cdc:1;
116 unsigned rndis:1;
117 unsigned suspended:1;
118 u16 cdc_filter;
119 unsigned long todo;
120#define WORK_RX_MEMORY 0
121 int rndis_config;
122 u8 host_mac [ETH_ALEN];
123};
124
125/* This version autoconfigures as much as possible at run-time.
126 * 84 *
127 * It also ASSUMES a self-powered device, without remote wakeup, 85 * IF YOUR HARDWARE CAN'T SUPPORT CDC ECM, UPDATE THAT ROUTINE!
128 * although remote wakeup support would make sense.
129 */ 86 */
130 87
88static inline bool has_rndis(void)
89{
90#ifdef CONFIG_USB_ETH_RNDIS
91 return true;
92#else
93 return false;
94#endif
95}
96
131/*-------------------------------------------------------------------------*/ 97/*-------------------------------------------------------------------------*/
132 98
133/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! 99/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
@@ -137,8 +103,8 @@ struct eth_dev {
137/* Thanks to NetChip Technologies for donating this product ID. 103/* Thanks to NetChip Technologies for donating this product ID.
138 * It's for devices with only CDC Ethernet configurations. 104 * It's for devices with only CDC Ethernet configurations.
139 */ 105 */
140#define CDC_VENDOR_NUM 0x0525 /* NetChip */ 106#define CDC_VENDOR_NUM 0x0525 /* NetChip */
141#define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ 107#define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */
142 108
143/* For hardware that can't talk CDC, we use the same vendor ID that 109/* For hardware that can't talk CDC, we use the same vendor ID that
144 * ARM Linux has used for ethernet-over-usb, both with sa1100 and 110 * ARM Linux has used for ethernet-over-usb, both with sa1100 and
@@ -162,274 +128,9 @@ struct eth_dev {
162#define RNDIS_VENDOR_NUM 0x0525 /* NetChip */ 128#define RNDIS_VENDOR_NUM 0x0525 /* NetChip */
163#define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */ 129#define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */
164 130
165
166/* Some systems will want different product identifers published in the
167 * device descriptor, either numbers or strings or both. These string
168 * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
169 */
170
171static ushort idVendor;
172module_param(idVendor, ushort, S_IRUGO);
173MODULE_PARM_DESC(idVendor, "USB Vendor ID");
174
175static ushort idProduct;
176module_param(idProduct, ushort, S_IRUGO);
177MODULE_PARM_DESC(idProduct, "USB Product ID");
178
179static ushort bcdDevice;
180module_param(bcdDevice, ushort, S_IRUGO);
181MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
182
183static char *iManufacturer;
184module_param(iManufacturer, charp, S_IRUGO);
185MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
186
187static char *iProduct;
188module_param(iProduct, charp, S_IRUGO);
189MODULE_PARM_DESC(iProduct, "USB Product string");
190
191static char *iSerialNumber;
192module_param(iSerialNumber, charp, S_IRUGO);
193MODULE_PARM_DESC(iSerialNumber, "SerialNumber");
194
195/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
196static char *dev_addr;
197module_param(dev_addr, charp, S_IRUGO);
198MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
199
200/* this address is invisible to ifconfig */
201static char *host_addr;
202module_param(host_addr, charp, S_IRUGO);
203MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
204
205
206/*-------------------------------------------------------------------------*/
207
208/* Include CDC support if we could run on CDC-capable hardware. */
209
210#ifdef CONFIG_USB_GADGET_NET2280
211#define DEV_CONFIG_CDC
212#endif
213
214#ifdef CONFIG_USB_GADGET_DUMMY_HCD
215#define DEV_CONFIG_CDC
216#endif
217
218#ifdef CONFIG_USB_GADGET_GOKU
219#define DEV_CONFIG_CDC
220#endif
221
222#ifdef CONFIG_USB_GADGET_LH7A40X
223#define DEV_CONFIG_CDC
224#endif
225
226#ifdef CONFIG_USB_GADGET_MQ11XX
227#define DEV_CONFIG_CDC
228#endif
229
230#ifdef CONFIG_USB_GADGET_OMAP
231#define DEV_CONFIG_CDC
232#endif
233
234#ifdef CONFIG_USB_GADGET_N9604
235#define DEV_CONFIG_CDC
236#endif
237
238#ifdef CONFIG_USB_GADGET_S3C2410
239#define DEV_CONFIG_CDC
240#endif
241
242#ifdef CONFIG_USB_GADGET_AT91
243#define DEV_CONFIG_CDC
244#endif
245
246#ifdef CONFIG_USB_GADGET_MUSBHSFC
247#define DEV_CONFIG_CDC
248#endif
249
250#ifdef CONFIG_USB_GADGET_MUSB_HDRC
251#define DEV_CONFIG_CDC
252#endif
253
254#ifdef CONFIG_USB_GADGET_ATMEL_USBA
255#define DEV_CONFIG_CDC
256#endif
257
258#ifdef CONFIG_USB_GADGET_FSL_USB2
259#define DEV_CONFIG_CDC
260#endif
261
262/* For CDC-incapable hardware, choose the simple cdc subset.
263 * Anything that talks bulk (without notable bugs) can do this.
264 */
265#ifdef CONFIG_USB_GADGET_PXA25X
266#define DEV_CONFIG_SUBSET
267#endif
268
269#ifdef CONFIG_USB_GADGET_PXA27X
270#define DEV_CONFIG_SUBSET
271#endif
272
273#ifdef CONFIG_USB_GADGET_SUPERH
274#define DEV_CONFIG_SUBSET
275#endif
276
277#ifdef CONFIG_USB_GADGET_SA1100
278/* use non-CDC for backwards compatibility */
279#define DEV_CONFIG_SUBSET
280#endif
281
282#ifdef CONFIG_USB_GADGET_M66592
283#define DEV_CONFIG_CDC
284#endif
285
286#ifdef CONFIG_USB_GADGET_AMD5536UDC
287#define DEV_CONFIG_CDC
288#endif
289
290
291/*-------------------------------------------------------------------------*/
292
293/* "main" config is either CDC, or its simple subset */
294static inline int is_cdc(struct eth_dev *dev)
295{
296#if !defined(DEV_CONFIG_SUBSET)
297 return 1; /* only cdc possible */
298#elif !defined (DEV_CONFIG_CDC)
299 return 0; /* only subset possible */
300#else
301 return dev->cdc; /* depends on what hardware we found */
302#endif
303}
304
305/* "secondary" RNDIS config may sometimes be activated */
306static inline int rndis_active(struct eth_dev *dev)
307{
308#ifdef CONFIG_USB_ETH_RNDIS
309 return dev->rndis;
310#else
311 return 0;
312#endif
313}
314
315#define subset_active(dev) (!is_cdc(dev) && !rndis_active(dev))
316#define cdc_active(dev) ( is_cdc(dev) && !rndis_active(dev))
317
318
319
320#define DEFAULT_QLEN 2 /* double buffering by default */
321
322/* peak bulk transfer bits-per-second */
323#define HS_BPS (13 * 512 * 8 * 1000 * 8)
324#define FS_BPS (19 * 64 * 1 * 1000 * 8)
325
326#ifdef CONFIG_USB_GADGET_DUALSPEED
327#define DEVSPEED USB_SPEED_HIGH
328
329static unsigned qmult = 5;
330module_param (qmult, uint, S_IRUGO|S_IWUSR);
331
332
333/* for dual-speed hardware, use deeper queues at highspeed */
334#define qlen(gadget) \
335 (DEFAULT_QLEN*((gadget->speed == USB_SPEED_HIGH) ? qmult : 1))
336
337static inline int BITRATE(struct usb_gadget *g)
338{
339 return (g->speed == USB_SPEED_HIGH) ? HS_BPS : FS_BPS;
340}
341
342#else /* full speed (low speed doesn't do bulk) */
343
344#define qmult 1
345
346#define DEVSPEED USB_SPEED_FULL
347
348#define qlen(gadget) DEFAULT_QLEN
349
350static inline int BITRATE(struct usb_gadget *g)
351{
352 return FS_BPS;
353}
354#endif
355
356
357/*-------------------------------------------------------------------------*/
358
359#define xprintk(d,level,fmt,args...) \
360 printk(level "%s: " fmt , (d)->net->name , ## args)
361
362#ifdef DEBUG
363#undef DEBUG
364#define DEBUG(dev,fmt,args...) \
365 xprintk(dev , KERN_DEBUG , fmt , ## args)
366#else
367#define DEBUG(dev,fmt,args...) \
368 do { } while (0)
369#endif /* DEBUG */
370
371#ifdef VERBOSE_DEBUG
372#define VDEBUG DEBUG
373#else
374#define VDEBUG(dev,fmt,args...) \
375 do { } while (0)
376#endif /* DEBUG */
377
378#define ERROR(dev,fmt,args...) \
379 xprintk(dev , KERN_ERR , fmt , ## args)
380#define WARN(dev,fmt,args...) \
381 xprintk(dev , KERN_WARNING , fmt , ## args)
382#define INFO(dev,fmt,args...) \
383 xprintk(dev , KERN_INFO , fmt , ## args)
384
385/*-------------------------------------------------------------------------*/ 131/*-------------------------------------------------------------------------*/
386 132
387/* USB DRIVER HOOKUP (to the hardware driver, below us), mostly 133static struct usb_device_descriptor device_desc = {
388 * ep0 implementation: descriptors, config management, setup().
389 * also optional class-specific notification interrupt transfer.
390 */
391
392/*
393 * DESCRIPTORS ... most are static, but strings and (full) configuration
394 * descriptors are built on demand. For now we do either full CDC, or
395 * our simple subset, with RNDIS as an optional second configuration.
396 *
397 * RNDIS includes some CDC ACM descriptors ... like CDC Ethernet. But
398 * the class descriptors match a modem (they're ignored; it's really just
399 * Ethernet functionality), they don't need the NOP altsetting, and the
400 * status transfer endpoint isn't optional.
401 */
402
403#define STRING_MANUFACTURER 1
404#define STRING_PRODUCT 2
405#define STRING_ETHADDR 3
406#define STRING_DATA 4
407#define STRING_CONTROL 5
408#define STRING_RNDIS_CONTROL 6
409#define STRING_CDC 7
410#define STRING_SUBSET 8
411#define STRING_RNDIS 9
412#define STRING_SERIALNUMBER 10
413
414/* holds our biggest descriptor (or RNDIS response) */
415#define USB_BUFSIZ 256
416
417/*
418 * This device advertises one configuration, eth_config, unless RNDIS
419 * is enabled (rndis_config) on hardware supporting at least two configs.
420 *
421 * NOTE: Controllers like superh_udc should probably be able to use
422 * an RNDIS-only configuration.
423 *
424 * FIXME define some higher-powered configurations to make it easier
425 * to recharge batteries ...
426 */
427
428#define DEV_CONFIG_VALUE 1 /* cdc or subset */
429#define DEV_RNDIS_CONFIG_VALUE 2 /* rndis; optional */
430
431static struct usb_device_descriptor
432device_desc = {
433 .bLength = sizeof device_desc, 134 .bLength = sizeof device_desc,
434 .bDescriptorType = USB_DT_DEVICE, 135 .bDescriptorType = USB_DT_DEVICE,
435 136
@@ -438,2220 +139,234 @@ device_desc = {
438 .bDeviceClass = USB_CLASS_COMM, 139 .bDeviceClass = USB_CLASS_COMM,
439 .bDeviceSubClass = 0, 140 .bDeviceSubClass = 0,
440 .bDeviceProtocol = 0, 141 .bDeviceProtocol = 0,
142 /* .bMaxPacketSize0 = f(hardware) */
441 143
144 /* Vendor and product id defaults change according to what configs
145 * we support. (As does bNumConfigurations.) These values can
146 * also be overridden by module parameters.
147 */
442 .idVendor = __constant_cpu_to_le16 (CDC_VENDOR_NUM), 148 .idVendor = __constant_cpu_to_le16 (CDC_VENDOR_NUM),
443 .idProduct = __constant_cpu_to_le16 (CDC_PRODUCT_NUM), 149 .idProduct = __constant_cpu_to_le16 (CDC_PRODUCT_NUM),
444 .iManufacturer = STRING_MANUFACTURER, 150 /* .bcdDevice = f(hardware) */
445 .iProduct = STRING_PRODUCT, 151 /* .iManufacturer = DYNAMIC */
152 /* .iProduct = DYNAMIC */
153 /* NO SERIAL NUMBER */
446 .bNumConfigurations = 1, 154 .bNumConfigurations = 1,
447}; 155};
448 156
449static struct usb_otg_descriptor 157static struct usb_otg_descriptor otg_descriptor = {
450otg_descriptor = {
451 .bLength = sizeof otg_descriptor, 158 .bLength = sizeof otg_descriptor,
452 .bDescriptorType = USB_DT_OTG, 159 .bDescriptorType = USB_DT_OTG,
453 160
454 .bmAttributes = USB_OTG_SRP, 161 /* REVISIT SRP-only hardware is possible, although
455}; 162 * it would not be called "OTG" ...
456 163 */
457static struct usb_config_descriptor 164 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
458eth_config = {
459 .bLength = sizeof eth_config,
460 .bDescriptorType = USB_DT_CONFIG,
461
462 /* compute wTotalLength on the fly */
463 .bNumInterfaces = 2,
464 .bConfigurationValue = DEV_CONFIG_VALUE,
465 .iConfiguration = STRING_CDC,
466 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
467 .bMaxPower = 50,
468};
469
470#ifdef CONFIG_USB_ETH_RNDIS
471static struct usb_config_descriptor
472rndis_config = {
473 .bLength = sizeof rndis_config,
474 .bDescriptorType = USB_DT_CONFIG,
475
476 /* compute wTotalLength on the fly */
477 .bNumInterfaces = 2,
478 .bConfigurationValue = DEV_RNDIS_CONFIG_VALUE,
479 .iConfiguration = STRING_RNDIS,
480 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
481 .bMaxPower = 50,
482};
483#endif
484
485/*
486 * Compared to the simple CDC subset, the full CDC Ethernet model adds
487 * three class descriptors, two interface descriptors, optional status
488 * endpoint. Both have a "data" interface and two bulk endpoints.
489 * There are also differences in how control requests are handled.
490 *
491 * RNDIS shares a lot with CDC-Ethernet, since it's a variant of the
492 * CDC-ACM (modem) spec. Unfortunately MSFT's RNDIS driver is buggy; it
493 * may hang or oops. Since bugfixes (or accurate specs, letting Linux
494 * work around those bugs) are unlikely to ever come from MSFT, you may
495 * wish to avoid using RNDIS.
496 *
497 * MCCI offers an alternative to RNDIS if you need to connect to Windows
498 * but have hardware that can't support CDC Ethernet. We add descriptors
499 * to present the CDC Subset as a (nonconformant) CDC MDLM variant called
500 * "SAFE". That borrows from both CDC Ethernet and CDC MDLM. You can
501 * get those drivers from MCCI, or bundled with various products.
502 */
503
504#ifdef DEV_CONFIG_CDC
505static struct usb_interface_descriptor
506control_intf = {
507 .bLength = sizeof control_intf,
508 .bDescriptorType = USB_DT_INTERFACE,
509
510 .bInterfaceNumber = 0,
511 /* status endpoint is optional; this may be patched later */
512 .bNumEndpoints = 1,
513 .bInterfaceClass = USB_CLASS_COMM,
514 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET,
515 .bInterfaceProtocol = USB_CDC_PROTO_NONE,
516 .iInterface = STRING_CONTROL,
517};
518#endif
519
520#ifdef CONFIG_USB_ETH_RNDIS
521static const struct usb_interface_descriptor
522rndis_control_intf = {
523 .bLength = sizeof rndis_control_intf,
524 .bDescriptorType = USB_DT_INTERFACE,
525
526 .bInterfaceNumber = 0,
527 .bNumEndpoints = 1,
528 .bInterfaceClass = USB_CLASS_COMM,
529 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
530 .bInterfaceProtocol = USB_CDC_ACM_PROTO_VENDOR,
531 .iInterface = STRING_RNDIS_CONTROL,
532};
533#endif
534
535static const struct usb_cdc_header_desc header_desc = {
536 .bLength = sizeof header_desc,
537 .bDescriptorType = USB_DT_CS_INTERFACE,
538 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
539
540 .bcdCDC = __constant_cpu_to_le16 (0x0110),
541};
542
543#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
544
545static const struct usb_cdc_union_desc union_desc = {
546 .bLength = sizeof union_desc,
547 .bDescriptorType = USB_DT_CS_INTERFACE,
548 .bDescriptorSubType = USB_CDC_UNION_TYPE,
549
550 .bMasterInterface0 = 0, /* index of control interface */
551 .bSlaveInterface0 = 1, /* index of DATA interface */
552};
553
554#endif /* CDC || RNDIS */
555
556#ifdef CONFIG_USB_ETH_RNDIS
557
558static const struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = {
559 .bLength = sizeof call_mgmt_descriptor,
560 .bDescriptorType = USB_DT_CS_INTERFACE,
561 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
562
563 .bmCapabilities = 0x00,
564 .bDataInterface = 0x01,
565};
566
567static const struct usb_cdc_acm_descriptor acm_descriptor = {
568 .bLength = sizeof acm_descriptor,
569 .bDescriptorType = USB_DT_CS_INTERFACE,
570 .bDescriptorSubType = USB_CDC_ACM_TYPE,
571
572 .bmCapabilities = 0x00,
573};
574
575#endif
576
577#ifndef DEV_CONFIG_CDC
578
579/* "SAFE" loosely follows CDC WMC MDLM, violating the spec in various
580 * ways: data endpoints live in the control interface, there's no data
581 * interface, and it's not used to talk to a cell phone radio.
582 */
583
584static const struct usb_cdc_mdlm_desc mdlm_desc = {
585 .bLength = sizeof mdlm_desc,
586 .bDescriptorType = USB_DT_CS_INTERFACE,
587 .bDescriptorSubType = USB_CDC_MDLM_TYPE,
588
589 .bcdVersion = __constant_cpu_to_le16(0x0100),
590 .bGUID = {
591 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
592 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
593 },
594};
595
596/* since "usb_cdc_mdlm_detail_desc" is a variable length structure, we
597 * can't really use its struct. All we do here is say that we're using
598 * the submode of "SAFE" which directly matches the CDC Subset.
599 */
600static const u8 mdlm_detail_desc[] = {
601 6,
602 USB_DT_CS_INTERFACE,
603 USB_CDC_MDLM_DETAIL_TYPE,
604
605 0, /* "SAFE" */
606 0, /* network control capabilities (none) */
607 0, /* network data capabilities ("raw" encapsulation) */
608};
609
610#endif
611
612static const struct usb_cdc_ether_desc ether_desc = {
613 .bLength = sizeof ether_desc,
614 .bDescriptorType = USB_DT_CS_INTERFACE,
615 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
616
617 /* this descriptor actually adds value, surprise! */
618 .iMACAddress = STRING_ETHADDR,
619 .bmEthernetStatistics = __constant_cpu_to_le32 (0), /* no statistics */
620 .wMaxSegmentSize = __constant_cpu_to_le16 (ETH_FRAME_LEN),
621 .wNumberMCFilters = __constant_cpu_to_le16 (0),
622 .bNumberPowerFilters = 0,
623};
624
625
626#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
627
628/* include the status endpoint if we can, even where it's optional.
629 * use wMaxPacketSize big enough to fit CDC_NOTIFY_SPEED_CHANGE in one
630 * packet, to simplify cancellation; and a big transfer interval, to
631 * waste less bandwidth.
632 *
633 * some drivers (like Linux 2.4 cdc-ether!) "need" it to exist even
634 * if they ignore the connect/disconnect notifications that real aether
635 * can provide. more advanced cdc configurations might want to support
636 * encapsulated commands (vendor-specific, using control-OUT).
637 *
638 * RNDIS requires the status endpoint, since it uses that encapsulation
639 * mechanism for its funky RPC scheme.
640 */
641
642#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */
643#define STATUS_BYTECOUNT 16 /* 8 byte header + data */
644
645static struct usb_endpoint_descriptor
646fs_status_desc = {
647 .bLength = USB_DT_ENDPOINT_SIZE,
648 .bDescriptorType = USB_DT_ENDPOINT,
649
650 .bEndpointAddress = USB_DIR_IN,
651 .bmAttributes = USB_ENDPOINT_XFER_INT,
652 .wMaxPacketSize = __constant_cpu_to_le16 (STATUS_BYTECOUNT),
653 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
654};
655#endif
656
657#ifdef DEV_CONFIG_CDC
658
659/* the default data interface has no endpoints ... */
660
661static const struct usb_interface_descriptor
662data_nop_intf = {
663 .bLength = sizeof data_nop_intf,
664 .bDescriptorType = USB_DT_INTERFACE,
665
666 .bInterfaceNumber = 1,
667 .bAlternateSetting = 0,
668 .bNumEndpoints = 0,
669 .bInterfaceClass = USB_CLASS_CDC_DATA,
670 .bInterfaceSubClass = 0,
671 .bInterfaceProtocol = 0,
672};
673
674/* ... but the "real" data interface has two bulk endpoints */
675
676static const struct usb_interface_descriptor
677data_intf = {
678 .bLength = sizeof data_intf,
679 .bDescriptorType = USB_DT_INTERFACE,
680
681 .bInterfaceNumber = 1,
682 .bAlternateSetting = 1,
683 .bNumEndpoints = 2,
684 .bInterfaceClass = USB_CLASS_CDC_DATA,
685 .bInterfaceSubClass = 0,
686 .bInterfaceProtocol = 0,
687 .iInterface = STRING_DATA,
688};
689
690#endif
691
692#ifdef CONFIG_USB_ETH_RNDIS
693
694/* RNDIS doesn't activate by changing to the "real" altsetting */
695
696static const struct usb_interface_descriptor
697rndis_data_intf = {
698 .bLength = sizeof rndis_data_intf,
699 .bDescriptorType = USB_DT_INTERFACE,
700
701 .bInterfaceNumber = 1,
702 .bAlternateSetting = 0,
703 .bNumEndpoints = 2,
704 .bInterfaceClass = USB_CLASS_CDC_DATA,
705 .bInterfaceSubClass = 0,
706 .bInterfaceProtocol = 0,
707 .iInterface = STRING_DATA,
708};
709
710#endif
711
712#ifdef DEV_CONFIG_SUBSET
713
714/*
715 * "Simple" CDC-subset option is a simple vendor-neutral model that most
716 * full speed controllers can handle: one interface, two bulk endpoints.
717 *
718 * To assist host side drivers, we fancy it up a bit, and add descriptors
719 * so some host side drivers will understand it as a "SAFE" variant.
720 */
721
722static const struct usb_interface_descriptor
723subset_data_intf = {
724 .bLength = sizeof subset_data_intf,
725 .bDescriptorType = USB_DT_INTERFACE,
726
727 .bInterfaceNumber = 0,
728 .bAlternateSetting = 0,
729 .bNumEndpoints = 2,
730 .bInterfaceClass = USB_CLASS_COMM,
731 .bInterfaceSubClass = USB_CDC_SUBCLASS_MDLM,
732 .bInterfaceProtocol = 0,
733 .iInterface = STRING_DATA,
734};
735
736#endif /* SUBSET */
737
738
739static struct usb_endpoint_descriptor
740fs_source_desc = {
741 .bLength = USB_DT_ENDPOINT_SIZE,
742 .bDescriptorType = USB_DT_ENDPOINT,
743
744 .bEndpointAddress = USB_DIR_IN,
745 .bmAttributes = USB_ENDPOINT_XFER_BULK,
746};
747
748static struct usb_endpoint_descriptor
749fs_sink_desc = {
750 .bLength = USB_DT_ENDPOINT_SIZE,
751 .bDescriptorType = USB_DT_ENDPOINT,
752
753 .bEndpointAddress = USB_DIR_OUT,
754 .bmAttributes = USB_ENDPOINT_XFER_BULK,
755}; 165};
756 166
757static const struct usb_descriptor_header *fs_eth_function [11] = { 167static const struct usb_descriptor_header *otg_desc[] = {
758 (struct usb_descriptor_header *) &otg_descriptor, 168 (struct usb_descriptor_header *) &otg_descriptor,
759#ifdef DEV_CONFIG_CDC
760 /* "cdc" mode descriptors */
761 (struct usb_descriptor_header *) &control_intf,
762 (struct usb_descriptor_header *) &header_desc,
763 (struct usb_descriptor_header *) &union_desc,
764 (struct usb_descriptor_header *) &ether_desc,
765 /* NOTE: status endpoint may need to be removed */
766 (struct usb_descriptor_header *) &fs_status_desc,
767 /* data interface, with altsetting */
768 (struct usb_descriptor_header *) &data_nop_intf,
769 (struct usb_descriptor_header *) &data_intf,
770 (struct usb_descriptor_header *) &fs_source_desc,
771 (struct usb_descriptor_header *) &fs_sink_desc,
772 NULL, 169 NULL,
773#endif /* DEV_CONFIG_CDC */
774}; 170};
775 171
776static inline void __init fs_subset_descriptors(void)
777{
778#ifdef DEV_CONFIG_SUBSET
779 /* behavior is "CDC Subset"; extra descriptors say "SAFE" */
780 fs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf;
781 fs_eth_function[2] = (struct usb_descriptor_header *) &header_desc;
782 fs_eth_function[3] = (struct usb_descriptor_header *) &mdlm_desc;
783 fs_eth_function[4] = (struct usb_descriptor_header *) &mdlm_detail_desc;
784 fs_eth_function[5] = (struct usb_descriptor_header *) &ether_desc;
785 fs_eth_function[6] = (struct usb_descriptor_header *) &fs_source_desc;
786 fs_eth_function[7] = (struct usb_descriptor_header *) &fs_sink_desc;
787 fs_eth_function[8] = NULL;
788#else
789 fs_eth_function[1] = NULL;
790#endif
791}
792 172
793#ifdef CONFIG_USB_ETH_RNDIS 173/* string IDs are assigned dynamically */
794static const struct usb_descriptor_header *fs_rndis_function [] = {
795 (struct usb_descriptor_header *) &otg_descriptor,
796 /* control interface matches ACM, not Ethernet */
797 (struct usb_descriptor_header *) &rndis_control_intf,
798 (struct usb_descriptor_header *) &header_desc,
799 (struct usb_descriptor_header *) &call_mgmt_descriptor,
800 (struct usb_descriptor_header *) &acm_descriptor,
801 (struct usb_descriptor_header *) &union_desc,
802 (struct usb_descriptor_header *) &fs_status_desc,
803 /* data interface has no altsetting */
804 (struct usb_descriptor_header *) &rndis_data_intf,
805 (struct usb_descriptor_header *) &fs_source_desc,
806 (struct usb_descriptor_header *) &fs_sink_desc,
807 NULL,
808};
809#endif
810
811/*
812 * usb 2.0 devices need to expose both high speed and full speed
813 * descriptors, unless they only run at full speed.
814 */
815
816#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
817static struct usb_endpoint_descriptor
818hs_status_desc = {
819 .bLength = USB_DT_ENDPOINT_SIZE,
820 .bDescriptorType = USB_DT_ENDPOINT,
821
822 .bmAttributes = USB_ENDPOINT_XFER_INT,
823 .wMaxPacketSize = __constant_cpu_to_le16 (STATUS_BYTECOUNT),
824 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
825};
826#endif /* DEV_CONFIG_CDC */
827
828static struct usb_endpoint_descriptor
829hs_source_desc = {
830 .bLength = USB_DT_ENDPOINT_SIZE,
831 .bDescriptorType = USB_DT_ENDPOINT,
832
833 .bmAttributes = USB_ENDPOINT_XFER_BULK,
834 .wMaxPacketSize = __constant_cpu_to_le16 (512),
835};
836
837static struct usb_endpoint_descriptor
838hs_sink_desc = {
839 .bLength = USB_DT_ENDPOINT_SIZE,
840 .bDescriptorType = USB_DT_ENDPOINT,
841
842 .bmAttributes = USB_ENDPOINT_XFER_BULK,
843 .wMaxPacketSize = __constant_cpu_to_le16 (512),
844};
845 174
846static struct usb_qualifier_descriptor 175#define STRING_MANUFACTURER_IDX 0
847dev_qualifier = { 176#define STRING_PRODUCT_IDX 1
848 .bLength = sizeof dev_qualifier,
849 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
850 177
851 .bcdUSB = __constant_cpu_to_le16 (0x0200), 178static char manufacturer[50];
852 .bDeviceClass = USB_CLASS_COMM,
853 179
854 .bNumConfigurations = 1, 180static struct usb_string strings_dev[] = {
181 [STRING_MANUFACTURER_IDX].s = manufacturer,
182 [STRING_PRODUCT_IDX].s = PREFIX DRIVER_DESC,
183 { } /* end of list */
855}; 184};
856 185
857static const struct usb_descriptor_header *hs_eth_function [11] = { 186static struct usb_gadget_strings stringtab_dev = {
858 (struct usb_descriptor_header *) &otg_descriptor, 187 .language = 0x0409, /* en-us */
859#ifdef DEV_CONFIG_CDC 188 .strings = strings_dev,
860 /* "cdc" mode descriptors */
861 (struct usb_descriptor_header *) &control_intf,
862 (struct usb_descriptor_header *) &header_desc,
863 (struct usb_descriptor_header *) &union_desc,
864 (struct usb_descriptor_header *) &ether_desc,
865 /* NOTE: status endpoint may need to be removed */
866 (struct usb_descriptor_header *) &hs_status_desc,
867 /* data interface, with altsetting */
868 (struct usb_descriptor_header *) &data_nop_intf,
869 (struct usb_descriptor_header *) &data_intf,
870 (struct usb_descriptor_header *) &hs_source_desc,
871 (struct usb_descriptor_header *) &hs_sink_desc,
872 NULL,
873#endif /* DEV_CONFIG_CDC */
874}; 189};
875 190
876static inline void __init hs_subset_descriptors(void) 191static struct usb_gadget_strings *dev_strings[] = {
877{ 192 &stringtab_dev,
878#ifdef DEV_CONFIG_SUBSET
879 /* behavior is "CDC Subset"; extra descriptors say "SAFE" */
880 hs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf;
881 hs_eth_function[2] = (struct usb_descriptor_header *) &header_desc;
882 hs_eth_function[3] = (struct usb_descriptor_header *) &mdlm_desc;
883 hs_eth_function[4] = (struct usb_descriptor_header *) &mdlm_detail_desc;
884 hs_eth_function[5] = (struct usb_descriptor_header *) &ether_desc;
885 hs_eth_function[6] = (struct usb_descriptor_header *) &hs_source_desc;
886 hs_eth_function[7] = (struct usb_descriptor_header *) &hs_sink_desc;
887 hs_eth_function[8] = NULL;
888#else
889 hs_eth_function[1] = NULL;
890#endif
891}
892
893#ifdef CONFIG_USB_ETH_RNDIS
894static const struct usb_descriptor_header *hs_rndis_function [] = {
895 (struct usb_descriptor_header *) &otg_descriptor,
896 /* control interface matches ACM, not Ethernet */
897 (struct usb_descriptor_header *) &rndis_control_intf,
898 (struct usb_descriptor_header *) &header_desc,
899 (struct usb_descriptor_header *) &call_mgmt_descriptor,
900 (struct usb_descriptor_header *) &acm_descriptor,
901 (struct usb_descriptor_header *) &union_desc,
902 (struct usb_descriptor_header *) &hs_status_desc,
903 /* data interface has no altsetting */
904 (struct usb_descriptor_header *) &rndis_data_intf,
905 (struct usb_descriptor_header *) &hs_source_desc,
906 (struct usb_descriptor_header *) &hs_sink_desc,
907 NULL, 193 NULL,
908}; 194};
909#endif
910
911
912/* maxpacket and other transfer characteristics vary by speed. */
913static inline struct usb_endpoint_descriptor *
914ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
915 struct usb_endpoint_descriptor *fs)
916{
917 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
918 return hs;
919 return fs;
920}
921 195
196static u8 hostaddr[ETH_ALEN];
922 197
923/*-------------------------------------------------------------------------*/ 198/*-------------------------------------------------------------------------*/
924 199
925/* descriptors that are built on-demand */
926
927static char manufacturer [50];
928static char product_desc [40] = DRIVER_DESC;
929static char serial_number [20];
930
931/* address that the host will use ... usually assigned at random */
932static char ethaddr [2 * ETH_ALEN + 1];
933
934/* static strings, in UTF-8 */
935static struct usb_string strings [] = {
936 { STRING_MANUFACTURER, manufacturer, },
937 { STRING_PRODUCT, product_desc, },
938 { STRING_SERIALNUMBER, serial_number, },
939 { STRING_DATA, "Ethernet Data", },
940 { STRING_ETHADDR, ethaddr, },
941#ifdef DEV_CONFIG_CDC
942 { STRING_CDC, "CDC Ethernet", },
943 { STRING_CONTROL, "CDC Communications Control", },
944#endif
945#ifdef DEV_CONFIG_SUBSET
946 { STRING_SUBSET, "CDC Ethernet Subset", },
947#endif
948#ifdef CONFIG_USB_ETH_RNDIS
949 { STRING_RNDIS, "RNDIS", },
950 { STRING_RNDIS_CONTROL, "RNDIS Communications Control", },
951#endif
952 { } /* end of list */
953};
954
955static struct usb_gadget_strings stringtab = {
956 .language = 0x0409, /* en-us */
957 .strings = strings,
958};
959
960/* 200/*
961 * one config, two interfaces: control, data. 201 * We may not have an RNDIS configuration, but if we do it needs to be
962 * complications: class descriptors, and an altsetting. 202 * the first one present. That's to make Microsoft's drivers happy,
963 */ 203 * and to follow DOCSIS 1.0 (cable modem standard).
964static int
965config_buf(struct usb_gadget *g, u8 *buf, u8 type, unsigned index, int is_otg)
966{
967 int len;
968 const struct usb_config_descriptor *config;
969 const struct usb_descriptor_header **function;
970 int hs = 0;
971
972 if (gadget_is_dualspeed(g)) {
973 hs = (g->speed == USB_SPEED_HIGH);
974 if (type == USB_DT_OTHER_SPEED_CONFIG)
975 hs = !hs;
976 }
977#define which_fn(t) (hs ? hs_ ## t ## _function : fs_ ## t ## _function)
978
979 if (index >= device_desc.bNumConfigurations)
980 return -EINVAL;
981
982#ifdef CONFIG_USB_ETH_RNDIS
983 /* list the RNDIS config first, to make Microsoft's drivers
984 * happy. DOCSIS 1.0 needs this too.
985 */
986 if (device_desc.bNumConfigurations == 2 && index == 0) {
987 config = &rndis_config;
988 function = which_fn (rndis);
989 } else
990#endif
991 {
992 config = &eth_config;
993 function = which_fn (eth);
994 }
995
996 /* for now, don't advertise srp-only devices */
997 if (!is_otg)
998 function++;
999
1000 len = usb_gadget_config_buf (config, buf, USB_BUFSIZ, function);
1001 if (len < 0)
1002 return len;
1003 ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
1004 return len;
1005}
1006
1007/*-------------------------------------------------------------------------*/
1008
1009static void eth_start (struct eth_dev *dev, gfp_t gfp_flags);
1010static int alloc_requests (struct eth_dev *dev, unsigned n, gfp_t gfp_flags);
1011
1012static int
1013set_ether_config (struct eth_dev *dev, gfp_t gfp_flags)
1014{
1015 int result = 0;
1016 struct usb_gadget *gadget = dev->gadget;
1017
1018#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
1019 /* status endpoint used for RNDIS and (optionally) CDC */
1020 if (!subset_active(dev) && dev->status_ep) {
1021 dev->status = ep_desc (gadget, &hs_status_desc,
1022 &fs_status_desc);
1023 dev->status_ep->driver_data = dev;
1024
1025 result = usb_ep_enable (dev->status_ep, dev->status);
1026 if (result != 0) {
1027 DEBUG (dev, "enable %s --> %d\n",
1028 dev->status_ep->name, result);
1029 goto done;
1030 }
1031 }
1032#endif
1033
1034 dev->in = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
1035 dev->in_ep->driver_data = dev;
1036
1037 dev->out = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
1038 dev->out_ep->driver_data = dev;
1039
1040 /* With CDC, the host isn't allowed to use these two data
1041 * endpoints in the default altsetting for the interface.
1042 * so we don't activate them yet. Reset from SET_INTERFACE.
1043 *
1044 * Strictly speaking RNDIS should work the same: activation is
1045 * a side effect of setting a packet filter. Deactivation is
1046 * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG.
1047 */
1048 if (!cdc_active(dev)) {
1049 result = usb_ep_enable (dev->in_ep, dev->in);
1050 if (result != 0) {
1051 DEBUG(dev, "enable %s --> %d\n",
1052 dev->in_ep->name, result);
1053 goto done;
1054 }
1055
1056 result = usb_ep_enable (dev->out_ep, dev->out);
1057 if (result != 0) {
1058 DEBUG (dev, "enable %s --> %d\n",
1059 dev->out_ep->name, result);
1060 goto done;
1061 }
1062 }
1063
1064done:
1065 if (result == 0)
1066 result = alloc_requests (dev, qlen (gadget), gfp_flags);
1067
1068 /* on error, disable any endpoints */
1069 if (result < 0) {
1070 if (!subset_active(dev) && dev->status_ep)
1071 (void) usb_ep_disable (dev->status_ep);
1072 dev->status = NULL;
1073 (void) usb_ep_disable (dev->in_ep);
1074 (void) usb_ep_disable (dev->out_ep);
1075 dev->in = NULL;
1076 dev->out = NULL;
1077 }
1078
1079 /* activate non-CDC configs right away
1080 * this isn't strictly according to the RNDIS spec
1081 */
1082 else if (!cdc_active (dev)) {
1083 netif_carrier_on (dev->net);
1084 if (netif_running (dev->net)) {
1085 spin_unlock (&dev->lock);
1086 eth_start (dev, GFP_ATOMIC);
1087 spin_lock (&dev->lock);
1088 }
1089 }
1090
1091 if (result == 0)
1092 DEBUG (dev, "qlen %d\n", qlen (gadget));
1093
1094 /* caller is responsible for cleanup on error */
1095 return result;
1096}
1097
1098static void eth_reset_config (struct eth_dev *dev)
1099{
1100 struct usb_request *req;
1101
1102 if (dev->config == 0)
1103 return;
1104
1105 DEBUG (dev, "%s\n", __func__);
1106
1107 netif_stop_queue (dev->net);
1108 netif_carrier_off (dev->net);
1109 rndis_uninit(dev->rndis_config);
1110
1111 /* disable endpoints, forcing (synchronous) completion of
1112 * pending i/o. then free the requests.
1113 */
1114 if (dev->in) {
1115 usb_ep_disable (dev->in_ep);
1116 spin_lock(&dev->req_lock);
1117 while (likely (!list_empty (&dev->tx_reqs))) {
1118 req = container_of (dev->tx_reqs.next,
1119 struct usb_request, list);
1120 list_del (&req->list);
1121
1122 spin_unlock(&dev->req_lock);
1123 usb_ep_free_request (dev->in_ep, req);
1124 spin_lock(&dev->req_lock);
1125 }
1126 spin_unlock(&dev->req_lock);
1127 }
1128 if (dev->out) {
1129 usb_ep_disable (dev->out_ep);
1130 spin_lock(&dev->req_lock);
1131 while (likely (!list_empty (&dev->rx_reqs))) {
1132 req = container_of (dev->rx_reqs.next,
1133 struct usb_request, list);
1134 list_del (&req->list);
1135
1136 spin_unlock(&dev->req_lock);
1137 usb_ep_free_request (dev->out_ep, req);
1138 spin_lock(&dev->req_lock);
1139 }
1140 spin_unlock(&dev->req_lock);
1141 }
1142
1143 if (dev->status) {
1144 usb_ep_disable (dev->status_ep);
1145 }
1146 dev->rndis = 0;
1147 dev->cdc_filter = 0;
1148 dev->config = 0;
1149}
1150
1151/* change our operational config. must agree with the code
1152 * that returns config descriptors, and altsetting code.
1153 */ 204 */
1154static int 205static int __init rndis_do_config(struct usb_configuration *c)
1155eth_set_config (struct eth_dev *dev, unsigned number, gfp_t gfp_flags)
1156{ 206{
1157 int result = 0; 207 /* FIXME alloc iConfiguration string, set it in c->strings */
1158 struct usb_gadget *gadget = dev->gadget;
1159
1160 if (gadget_is_sa1100 (gadget)
1161 && dev->config
1162 && atomic_read (&dev->tx_qlen) != 0) {
1163 /* tx fifo is full, but we can't clear it...*/
1164 INFO (dev, "can't change configurations\n");
1165 return -ESPIPE;
1166 }
1167 eth_reset_config (dev);
1168
1169 switch (number) {
1170 case DEV_CONFIG_VALUE:
1171 result = set_ether_config (dev, gfp_flags);
1172 break;
1173#ifdef CONFIG_USB_ETH_RNDIS
1174 case DEV_RNDIS_CONFIG_VALUE:
1175 dev->rndis = 1;
1176 result = set_ether_config (dev, gfp_flags);
1177 break;
1178#endif
1179 default:
1180 result = -EINVAL;
1181 /* FALL THROUGH */
1182 case 0:
1183 break;
1184 }
1185
1186 if (result) {
1187 if (number)
1188 eth_reset_config (dev);
1189 usb_gadget_vbus_draw(dev->gadget,
1190 gadget_is_otg(dev->gadget) ? 8 : 100);
1191 } else {
1192 char *speed;
1193 unsigned power;
1194
1195 power = 2 * eth_config.bMaxPower;
1196 usb_gadget_vbus_draw(dev->gadget, power);
1197 208
1198 switch (gadget->speed) { 209 if (gadget_is_otg(c->cdev->gadget)) {
1199 case USB_SPEED_FULL: speed = "full"; break; 210 c->descriptors = otg_desc;
1200#ifdef CONFIG_USB_GADGET_DUALSPEED 211 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1201 case USB_SPEED_HIGH: speed = "high"; break;
1202#endif
1203 default: speed = "?"; break;
1204 }
1205
1206 dev->config = number;
1207 INFO (dev, "%s speed config #%d: %d mA, %s, using %s\n",
1208 speed, number, power, driver_desc,
1209 rndis_active(dev)
1210 ? "RNDIS"
1211 : (cdc_active(dev)
1212 ? "CDC Ethernet"
1213 : "CDC Ethernet Subset"));
1214 } 212 }
1215 return result;
1216}
1217
1218/*-------------------------------------------------------------------------*/
1219
1220#ifdef DEV_CONFIG_CDC
1221 213
1222/* The interrupt endpoint is used in CDC networking models (Ethernet, ATM) 214 return rndis_bind_config(c, hostaddr);
1223 * only to notify the host about link status changes (which we support) or
1224 * report completion of some encapsulated command (as used in RNDIS). Since
1225 * we want this CDC Ethernet code to be vendor-neutral, we don't use that
1226 * command mechanism; and only one status request is ever queued.
1227 */
1228
1229static void eth_status_complete (struct usb_ep *ep, struct usb_request *req)
1230{
1231 struct usb_cdc_notification *event = req->buf;
1232 int value = req->status;
1233 struct eth_dev *dev = ep->driver_data;
1234
1235 /* issue the second notification if host reads the first */
1236 if (event->bNotificationType == USB_CDC_NOTIFY_NETWORK_CONNECTION
1237 && value == 0) {
1238 __le32 *data = req->buf + sizeof *event;
1239
1240 event->bmRequestType = 0xA1;
1241 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE;
1242 event->wValue = __constant_cpu_to_le16 (0);
1243 event->wIndex = __constant_cpu_to_le16 (1);
1244 event->wLength = __constant_cpu_to_le16 (8);
1245
1246 /* SPEED_CHANGE data is up/down speeds in bits/sec */
1247 data [0] = data [1] = cpu_to_le32 (BITRATE (dev->gadget));
1248
1249 req->length = STATUS_BYTECOUNT;
1250 value = usb_ep_queue (ep, req, GFP_ATOMIC);
1251 DEBUG (dev, "send SPEED_CHANGE --> %d\n", value);
1252 if (value == 0)
1253 return;
1254 } else if (value != -ECONNRESET)
1255 DEBUG (dev, "event %02x --> %d\n",
1256 event->bNotificationType, value);
1257 req->context = NULL;
1258} 215}
1259 216
1260static void issue_start_status (struct eth_dev *dev) 217static struct usb_configuration rndis_config_driver = {
1261{ 218 .label = "RNDIS",
1262 struct usb_request *req = dev->stat_req; 219 .bind = rndis_do_config,
1263 struct usb_cdc_notification *event; 220 .bConfigurationValue = 2,
1264 int value; 221 /* .iConfiguration = DYNAMIC */
1265 222 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
1266 DEBUG (dev, "%s, flush old status first\n", __func__); 223 .bMaxPower = 1, /* 2 mA, minimal */
1267 224};
1268 /* flush old status
1269 *
1270 * FIXME ugly idiom, maybe we'd be better with just
1271 * a "cancel the whole queue" primitive since any
1272 * unlink-one primitive has way too many error modes.
1273 * here, we "know" toggle is already clear...
1274 *
1275 * FIXME iff req->context != null just dequeue it
1276 */
1277 usb_ep_disable (dev->status_ep);
1278 usb_ep_enable (dev->status_ep, dev->status);
1279
1280 /* 3.8.1 says to issue first NETWORK_CONNECTION, then
1281 * a SPEED_CHANGE. could be useful in some configs.
1282 */
1283 event = req->buf;
1284 event->bmRequestType = 0xA1;
1285 event->bNotificationType = USB_CDC_NOTIFY_NETWORK_CONNECTION;
1286 event->wValue = __constant_cpu_to_le16 (1); /* connected */
1287 event->wIndex = __constant_cpu_to_le16 (1);
1288 event->wLength = 0;
1289
1290 req->length = sizeof *event;
1291 req->complete = eth_status_complete;
1292 req->context = dev;
1293
1294 value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC);
1295 if (value < 0)
1296 DEBUG (dev, "status buf queue --> %d\n", value);
1297}
1298
1299#endif
1300 225
1301/*-------------------------------------------------------------------------*/ 226/*-------------------------------------------------------------------------*/
1302 227
1303static void eth_setup_complete (struct usb_ep *ep, struct usb_request *req)
1304{
1305 if (req->status || req->actual != req->length)
1306 DEBUG ((struct eth_dev *) ep->driver_data,
1307 "setup complete --> %d, %d/%d\n",
1308 req->status, req->actual, req->length);
1309}
1310
1311#ifdef CONFIG_USB_ETH_RNDIS
1312
1313static void rndis_response_complete (struct usb_ep *ep, struct usb_request *req)
1314{
1315 if (req->status || req->actual != req->length)
1316 DEBUG ((struct eth_dev *) ep->driver_data,
1317 "rndis response complete --> %d, %d/%d\n",
1318 req->status, req->actual, req->length);
1319
1320 /* done sending after USB_CDC_GET_ENCAPSULATED_RESPONSE */
1321}
1322
1323static void rndis_command_complete (struct usb_ep *ep, struct usb_request *req)
1324{
1325 struct eth_dev *dev = ep->driver_data;
1326 int status;
1327
1328 /* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
1329 spin_lock(&dev->lock);
1330 status = rndis_msg_parser (dev->rndis_config, (u8 *) req->buf);
1331 if (status < 0)
1332 ERROR(dev, "%s: rndis parse error %d\n", __func__, status);
1333 spin_unlock(&dev->lock);
1334}
1335
1336#endif /* RNDIS */
1337
1338/* 228/*
1339 * The setup() callback implements all the ep0 functionality that's not 229 * We _always_ have an ECM or CDC Subset configuration.
1340 * handled lower down. CDC has a number of less-common features:
1341 *
1342 * - two interfaces: control, and ethernet data
1343 * - Ethernet data interface has two altsettings: default, and active
1344 * - class-specific descriptors for the control interface
1345 * - class-specific control requests
1346 */ 230 */
1347static int 231static int __init eth_do_config(struct usb_configuration *c)
1348eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1349{ 232{
1350 struct eth_dev *dev = get_gadget_data (gadget); 233 /* FIXME alloc iConfiguration string, set it in c->strings */
1351 struct usb_request *req = dev->req;
1352 int value = -EOPNOTSUPP;
1353 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1354 u16 wValue = le16_to_cpu(ctrl->wValue);
1355 u16 wLength = le16_to_cpu(ctrl->wLength);
1356
1357 /* descriptors just go into the pre-allocated ep0 buffer,
1358 * while config change events may enable network traffic.
1359 */
1360 req->complete = eth_setup_complete;
1361 switch (ctrl->bRequest) {
1362
1363 case USB_REQ_GET_DESCRIPTOR:
1364 if (ctrl->bRequestType != USB_DIR_IN)
1365 break;
1366 switch (wValue >> 8) {
1367
1368 case USB_DT_DEVICE:
1369 value = min (wLength, (u16) sizeof device_desc);
1370 memcpy (req->buf, &device_desc, value);
1371 break;
1372 case USB_DT_DEVICE_QUALIFIER:
1373 if (!gadget_is_dualspeed(gadget))
1374 break;
1375 value = min (wLength, (u16) sizeof dev_qualifier);
1376 memcpy (req->buf, &dev_qualifier, value);
1377 break;
1378
1379 case USB_DT_OTHER_SPEED_CONFIG:
1380 if (!gadget_is_dualspeed(gadget))
1381 break;
1382 // FALLTHROUGH
1383 case USB_DT_CONFIG:
1384 value = config_buf(gadget, req->buf,
1385 wValue >> 8,
1386 wValue & 0xff,
1387 gadget_is_otg(gadget));
1388 if (value >= 0)
1389 value = min (wLength, (u16) value);
1390 break;
1391
1392 case USB_DT_STRING:
1393 value = usb_gadget_get_string (&stringtab,
1394 wValue & 0xff, req->buf);
1395 if (value >= 0)
1396 value = min (wLength, (u16) value);
1397 break;
1398 }
1399 break;
1400
1401 case USB_REQ_SET_CONFIGURATION:
1402 if (ctrl->bRequestType != 0)
1403 break;
1404 if (gadget->a_hnp_support)
1405 DEBUG (dev, "HNP available\n");
1406 else if (gadget->a_alt_hnp_support)
1407 DEBUG (dev, "HNP needs a different root port\n");
1408 spin_lock (&dev->lock);
1409 value = eth_set_config (dev, wValue, GFP_ATOMIC);
1410 spin_unlock (&dev->lock);
1411 break;
1412 case USB_REQ_GET_CONFIGURATION:
1413 if (ctrl->bRequestType != USB_DIR_IN)
1414 break;
1415 *(u8 *)req->buf = dev->config;
1416 value = min (wLength, (u16) 1);
1417 break;
1418
1419 case USB_REQ_SET_INTERFACE:
1420 if (ctrl->bRequestType != USB_RECIP_INTERFACE
1421 || !dev->config
1422 || wIndex > 1)
1423 break;
1424 if (!cdc_active(dev) && wIndex != 0)
1425 break;
1426 spin_lock (&dev->lock);
1427
1428 /* PXA hardware partially handles SET_INTERFACE;
1429 * we need to kluge around that interference.
1430 */
1431 if (gadget_is_pxa (gadget)) {
1432 value = eth_set_config (dev, DEV_CONFIG_VALUE,
1433 GFP_ATOMIC);
1434 goto done_set_intf;
1435 }
1436
1437#ifdef DEV_CONFIG_CDC
1438 switch (wIndex) {
1439 case 0: /* control/master intf */
1440 if (wValue != 0)
1441 break;
1442 if (dev->status) {
1443 usb_ep_disable (dev->status_ep);
1444 usb_ep_enable (dev->status_ep, dev->status);
1445 }
1446 value = 0;
1447 break;
1448 case 1: /* data intf */
1449 if (wValue > 1)
1450 break;
1451 usb_ep_disable (dev->in_ep);
1452 usb_ep_disable (dev->out_ep);
1453
1454 /* CDC requires the data transfers not be done from
1455 * the default interface setting ... also, setting
1456 * the non-default interface resets filters etc.
1457 */
1458 if (wValue == 1) {
1459 if (!cdc_active (dev))
1460 break;
1461 usb_ep_enable (dev->in_ep, dev->in);
1462 usb_ep_enable (dev->out_ep, dev->out);
1463 dev->cdc_filter = DEFAULT_FILTER;
1464 netif_carrier_on (dev->net);
1465 if (dev->status)
1466 issue_start_status (dev);
1467 if (netif_running (dev->net)) {
1468 spin_unlock (&dev->lock);
1469 eth_start (dev, GFP_ATOMIC);
1470 spin_lock (&dev->lock);
1471 }
1472 } else {
1473 netif_stop_queue (dev->net);
1474 netif_carrier_off (dev->net);
1475 }
1476 value = 0;
1477 break;
1478 }
1479#else
1480 /* FIXME this is wrong, as is the assumption that
1481 * all non-PXA hardware talks real CDC ...
1482 */
1483 dev_warn (&gadget->dev, "set_interface ignored!\n");
1484#endif /* DEV_CONFIG_CDC */
1485
1486done_set_intf:
1487 spin_unlock (&dev->lock);
1488 break;
1489 case USB_REQ_GET_INTERFACE:
1490 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)
1491 || !dev->config
1492 || wIndex > 1)
1493 break;
1494 if (!(cdc_active(dev) || rndis_active(dev)) && wIndex != 0)
1495 break;
1496
1497 /* for CDC, iff carrier is on, data interface is active. */
1498 if (rndis_active(dev) || wIndex != 1)
1499 *(u8 *)req->buf = 0;
1500 else
1501 *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0;
1502 value = min (wLength, (u16) 1);
1503 break;
1504
1505#ifdef DEV_CONFIG_CDC
1506 case USB_CDC_SET_ETHERNET_PACKET_FILTER:
1507 /* see 6.2.30: no data, wIndex = interface,
1508 * wValue = packet filter bitmap
1509 */
1510 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1511 || !cdc_active(dev)
1512 || wLength != 0
1513 || wIndex > 1)
1514 break;
1515 DEBUG (dev, "packet filter %02x\n", wValue);
1516 dev->cdc_filter = wValue;
1517 value = 0;
1518 break;
1519
1520 /* and potentially:
1521 * case USB_CDC_SET_ETHERNET_MULTICAST_FILTERS:
1522 * case USB_CDC_SET_ETHERNET_PM_PATTERN_FILTER:
1523 * case USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER:
1524 * case USB_CDC_GET_ETHERNET_STATISTIC:
1525 */
1526
1527#endif /* DEV_CONFIG_CDC */
1528 234
1529#ifdef CONFIG_USB_ETH_RNDIS 235 if (gadget_is_otg(c->cdev->gadget)) {
1530 /* RNDIS uses the CDC command encapsulation mechanism to implement 236 c->descriptors = otg_desc;
1531 * an RPC scheme, with much getting/setting of attributes by OID. 237 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1532 */
1533 case USB_CDC_SEND_ENCAPSULATED_COMMAND:
1534 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1535 || !rndis_active(dev)
1536 || wLength > USB_BUFSIZ
1537 || wValue
1538 || rndis_control_intf.bInterfaceNumber
1539 != wIndex)
1540 break;
1541 /* read the request, then process it */
1542 value = wLength;
1543 req->complete = rndis_command_complete;
1544 /* later, rndis_control_ack () sends a notification */
1545 break;
1546
1547 case USB_CDC_GET_ENCAPSULATED_RESPONSE:
1548 if ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1549 == ctrl->bRequestType
1550 && rndis_active(dev)
1551 // && wLength >= 0x0400
1552 && !wValue
1553 && rndis_control_intf.bInterfaceNumber
1554 == wIndex) {
1555 u8 *buf;
1556 u32 n;
1557
1558 /* return the result */
1559 buf = rndis_get_next_response(dev->rndis_config, &n);
1560 if (buf) {
1561 memcpy(req->buf, buf, n);
1562 req->complete = rndis_response_complete;
1563 rndis_free_response(dev->rndis_config, buf);
1564 value = n;
1565 }
1566 /* else stalls ... spec says to avoid that */
1567 }
1568 break;
1569#endif /* RNDIS */
1570
1571 default:
1572 VDEBUG (dev,
1573 "unknown control req%02x.%02x v%04x i%04x l%d\n",
1574 ctrl->bRequestType, ctrl->bRequest,
1575 wValue, wIndex, wLength);
1576 } 238 }
1577 239
1578 /* respond with data transfer before status phase? */ 240 if (can_support_ecm(c->cdev->gadget))
1579 if (value >= 0) { 241 return ecm_bind_config(c, hostaddr);
1580 req->length = value;
1581 req->zero = value < wLength
1582 && (value % gadget->ep0->maxpacket) == 0;
1583 value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
1584 if (value < 0) {
1585 DEBUG (dev, "ep_queue --> %d\n", value);
1586 req->status = 0;
1587 eth_setup_complete (gadget->ep0, req);
1588 }
1589 }
1590
1591 /* host either stalls (value < 0) or reports success */
1592 return value;
1593}
1594
1595static void
1596eth_disconnect (struct usb_gadget *gadget)
1597{
1598 struct eth_dev *dev = get_gadget_data (gadget);
1599 unsigned long flags;
1600
1601 spin_lock_irqsave (&dev->lock, flags);
1602 netif_stop_queue (dev->net);
1603 netif_carrier_off (dev->net);
1604 eth_reset_config (dev);
1605 spin_unlock_irqrestore (&dev->lock, flags);
1606
1607 /* FIXME RNDIS should enter RNDIS_UNINITIALIZED */
1608
1609 /* next we may get setup() calls to enumerate new connections;
1610 * or an unbind() during shutdown (including removing module).
1611 */
1612}
1613
1614/*-------------------------------------------------------------------------*/
1615
1616/* NETWORK DRIVER HOOKUP (to the layer above this driver) */
1617
1618static int eth_change_mtu (struct net_device *net, int new_mtu)
1619{
1620 struct eth_dev *dev = netdev_priv(net);
1621
1622 if (dev->rndis)
1623 return -EBUSY;
1624
1625 if (new_mtu <= ETH_HLEN || new_mtu > ETH_FRAME_LEN)
1626 return -ERANGE;
1627 /* no zero-length packet read wanted after mtu-sized packets */
1628 if (((new_mtu + sizeof (struct ethhdr)) % dev->in_ep->maxpacket) == 0)
1629 return -EDOM;
1630 net->mtu = new_mtu;
1631 return 0;
1632}
1633
1634static struct net_device_stats *eth_get_stats (struct net_device *net)
1635{
1636 return &((struct eth_dev *)netdev_priv(net))->stats;
1637}
1638
1639static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
1640{
1641 struct eth_dev *dev = netdev_priv(net);
1642 strlcpy(p->driver, shortname, sizeof p->driver);
1643 strlcpy(p->version, DRIVER_VERSION, sizeof p->version);
1644 strlcpy(p->fw_version, dev->gadget->name, sizeof p->fw_version);
1645 strlcpy (p->bus_info, dev->gadget->dev.bus_id, sizeof p->bus_info);
1646}
1647
1648static u32 eth_get_link(struct net_device *net)
1649{
1650 struct eth_dev *dev = netdev_priv(net);
1651 return dev->gadget->speed != USB_SPEED_UNKNOWN;
1652}
1653
1654static struct ethtool_ops ops = {
1655 .get_drvinfo = eth_get_drvinfo,
1656 .get_link = eth_get_link
1657};
1658
1659static void defer_kevent (struct eth_dev *dev, int flag)
1660{
1661 if (test_and_set_bit (flag, &dev->todo))
1662 return;
1663 if (!schedule_work (&dev->work))
1664 ERROR (dev, "kevent %d may have been dropped\n", flag);
1665 else 242 else
1666 DEBUG (dev, "kevent %d scheduled\n", flag); 243 return geth_bind_config(c, hostaddr);
1667}
1668
1669static void rx_complete (struct usb_ep *ep, struct usb_request *req);
1670
1671static int
1672rx_submit (struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
1673{
1674 struct sk_buff *skb;
1675 int retval = -ENOMEM;
1676 size_t size;
1677
1678 /* Padding up to RX_EXTRA handles minor disagreements with host.
1679 * Normally we use the USB "terminate on short read" convention;
1680 * so allow up to (N*maxpacket), since that memory is normally
1681 * already allocated. Some hardware doesn't deal well with short
1682 * reads (e.g. DMA must be N*maxpacket), so for now don't trim a
1683 * byte off the end (to force hardware errors on overflow).
1684 *
1685 * RNDIS uses internal framing, and explicitly allows senders to
1686 * pad to end-of-packet. That's potentially nice for speed,
1687 * but means receivers can't recover synch on their own.
1688 */
1689 size = (sizeof (struct ethhdr) + dev->net->mtu + RX_EXTRA);
1690 size += dev->out_ep->maxpacket - 1;
1691 if (rndis_active(dev))
1692 size += sizeof (struct rndis_packet_msg_type);
1693 size -= size % dev->out_ep->maxpacket;
1694
1695 skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags);
1696 if (skb == NULL) {
1697 DEBUG (dev, "no rx skb\n");
1698 goto enomem;
1699 }
1700
1701 /* Some platforms perform better when IP packets are aligned,
1702 * but on at least one, checksumming fails otherwise. Note:
1703 * RNDIS headers involve variable numbers of LE32 values.
1704 */
1705 skb_reserve(skb, NET_IP_ALIGN);
1706
1707 req->buf = skb->data;
1708 req->length = size;
1709 req->complete = rx_complete;
1710 req->context = skb;
1711
1712 retval = usb_ep_queue (dev->out_ep, req, gfp_flags);
1713 if (retval == -ENOMEM)
1714enomem:
1715 defer_kevent (dev, WORK_RX_MEMORY);
1716 if (retval) {
1717 DEBUG (dev, "rx submit --> %d\n", retval);
1718 if (skb)
1719 dev_kfree_skb_any(skb);
1720 spin_lock(&dev->req_lock);
1721 list_add (&req->list, &dev->rx_reqs);
1722 spin_unlock(&dev->req_lock);
1723 }
1724 return retval;
1725}
1726
1727static void rx_complete (struct usb_ep *ep, struct usb_request *req)
1728{
1729 struct sk_buff *skb = req->context;
1730 struct eth_dev *dev = ep->driver_data;
1731 int status = req->status;
1732
1733 switch (status) {
1734
1735 /* normal completion */
1736 case 0:
1737 skb_put (skb, req->actual);
1738 /* we know MaxPacketsPerTransfer == 1 here */
1739 if (rndis_active(dev))
1740 status = rndis_rm_hdr (skb);
1741 if (status < 0
1742 || ETH_HLEN > skb->len
1743 || skb->len > ETH_FRAME_LEN) {
1744 dev->stats.rx_errors++;
1745 dev->stats.rx_length_errors++;
1746 DEBUG (dev, "rx length %d\n", skb->len);
1747 break;
1748 }
1749
1750 skb->protocol = eth_type_trans (skb, dev->net);
1751 dev->stats.rx_packets++;
1752 dev->stats.rx_bytes += skb->len;
1753
1754 /* no buffer copies needed, unless hardware can't
1755 * use skb buffers.
1756 */
1757 status = netif_rx (skb);
1758 skb = NULL;
1759 break;
1760
1761 /* software-driven interface shutdown */
1762 case -ECONNRESET: // unlink
1763 case -ESHUTDOWN: // disconnect etc
1764 VDEBUG (dev, "rx shutdown, code %d\n", status);
1765 goto quiesce;
1766
1767 /* for hardware automagic (such as pxa) */
1768 case -ECONNABORTED: // endpoint reset
1769 DEBUG (dev, "rx %s reset\n", ep->name);
1770 defer_kevent (dev, WORK_RX_MEMORY);
1771quiesce:
1772 dev_kfree_skb_any (skb);
1773 goto clean;
1774
1775 /* data overrun */
1776 case -EOVERFLOW:
1777 dev->stats.rx_over_errors++;
1778 // FALLTHROUGH
1779
1780 default:
1781 dev->stats.rx_errors++;
1782 DEBUG (dev, "rx status %d\n", status);
1783 break;
1784 }
1785
1786 if (skb)
1787 dev_kfree_skb_any (skb);
1788 if (!netif_running (dev->net)) {
1789clean:
1790 spin_lock(&dev->req_lock);
1791 list_add (&req->list, &dev->rx_reqs);
1792 spin_unlock(&dev->req_lock);
1793 req = NULL;
1794 }
1795 if (req)
1796 rx_submit (dev, req, GFP_ATOMIC);
1797}
1798
1799static int prealloc (struct list_head *list, struct usb_ep *ep,
1800 unsigned n, gfp_t gfp_flags)
1801{
1802 unsigned i;
1803 struct usb_request *req;
1804
1805 if (!n)
1806 return -ENOMEM;
1807
1808 /* queue/recycle up to N requests */
1809 i = n;
1810 list_for_each_entry (req, list, list) {
1811 if (i-- == 0)
1812 goto extra;
1813 }
1814 while (i--) {
1815 req = usb_ep_alloc_request (ep, gfp_flags);
1816 if (!req)
1817 return list_empty (list) ? -ENOMEM : 0;
1818 list_add (&req->list, list);
1819 }
1820 return 0;
1821
1822extra:
1823 /* free extras */
1824 for (;;) {
1825 struct list_head *next;
1826
1827 next = req->list.next;
1828 list_del (&req->list);
1829 usb_ep_free_request (ep, req);
1830
1831 if (next == list)
1832 break;
1833
1834 req = container_of (next, struct usb_request, list);
1835 }
1836 return 0;
1837}
1838
1839static int alloc_requests (struct eth_dev *dev, unsigned n, gfp_t gfp_flags)
1840{
1841 int status;
1842
1843 spin_lock(&dev->req_lock);
1844 status = prealloc (&dev->tx_reqs, dev->in_ep, n, gfp_flags);
1845 if (status < 0)
1846 goto fail;
1847 status = prealloc (&dev->rx_reqs, dev->out_ep, n, gfp_flags);
1848 if (status < 0)
1849 goto fail;
1850 goto done;
1851fail:
1852 DEBUG (dev, "can't alloc requests\n");
1853done:
1854 spin_unlock(&dev->req_lock);
1855 return status;
1856}
1857
1858static void rx_fill (struct eth_dev *dev, gfp_t gfp_flags)
1859{
1860 struct usb_request *req;
1861 unsigned long flags;
1862
1863 /* fill unused rxq slots with some skb */
1864 spin_lock_irqsave(&dev->req_lock, flags);
1865 while (!list_empty (&dev->rx_reqs)) {
1866 req = container_of (dev->rx_reqs.next,
1867 struct usb_request, list);
1868 list_del_init (&req->list);
1869 spin_unlock_irqrestore(&dev->req_lock, flags);
1870
1871 if (rx_submit (dev, req, gfp_flags) < 0) {
1872 defer_kevent (dev, WORK_RX_MEMORY);
1873 return;
1874 }
1875
1876 spin_lock_irqsave(&dev->req_lock, flags);
1877 }
1878 spin_unlock_irqrestore(&dev->req_lock, flags);
1879}
1880
1881static void eth_work (struct work_struct *work)
1882{
1883 struct eth_dev *dev = container_of(work, struct eth_dev, work);
1884
1885 if (test_and_clear_bit (WORK_RX_MEMORY, &dev->todo)) {
1886 if (netif_running (dev->net))
1887 rx_fill (dev, GFP_KERNEL);
1888 }
1889
1890 if (dev->todo)
1891 DEBUG (dev, "work done, flags = 0x%lx\n", dev->todo);
1892}
1893
1894static void tx_complete (struct usb_ep *ep, struct usb_request *req)
1895{
1896 struct sk_buff *skb = req->context;
1897 struct eth_dev *dev = ep->driver_data;
1898
1899 switch (req->status) {
1900 default:
1901 dev->stats.tx_errors++;
1902 VDEBUG (dev, "tx err %d\n", req->status);
1903 /* FALLTHROUGH */
1904 case -ECONNRESET: // unlink
1905 case -ESHUTDOWN: // disconnect etc
1906 break;
1907 case 0:
1908 dev->stats.tx_bytes += skb->len;
1909 }
1910 dev->stats.tx_packets++;
1911
1912 spin_lock(&dev->req_lock);
1913 list_add (&req->list, &dev->tx_reqs);
1914 spin_unlock(&dev->req_lock);
1915 dev_kfree_skb_any (skb);
1916
1917 atomic_dec (&dev->tx_qlen);
1918 if (netif_carrier_ok (dev->net))
1919 netif_wake_queue (dev->net);
1920}
1921
1922static inline int eth_is_promisc (struct eth_dev *dev)
1923{
1924 /* no filters for the CDC subset; always promisc */
1925 if (subset_active (dev))
1926 return 1;
1927 return dev->cdc_filter & USB_CDC_PACKET_TYPE_PROMISCUOUS;
1928}
1929
1930static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1931{
1932 struct eth_dev *dev = netdev_priv(net);
1933 int length = skb->len;
1934 int retval;
1935 struct usb_request *req = NULL;
1936 unsigned long flags;
1937
1938 /* apply outgoing CDC or RNDIS filters */
1939 if (!eth_is_promisc (dev)) {
1940 u8 *dest = skb->data;
1941
1942 if (is_multicast_ether_addr(dest)) {
1943 u16 type;
1944
1945 /* ignores USB_CDC_PACKET_TYPE_MULTICAST and host
1946 * SET_ETHERNET_MULTICAST_FILTERS requests
1947 */
1948 if (is_broadcast_ether_addr(dest))
1949 type = USB_CDC_PACKET_TYPE_BROADCAST;
1950 else
1951 type = USB_CDC_PACKET_TYPE_ALL_MULTICAST;
1952 if (!(dev->cdc_filter & type)) {
1953 dev_kfree_skb_any (skb);
1954 return 0;
1955 }
1956 }
1957 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */
1958 }
1959
1960 spin_lock_irqsave(&dev->req_lock, flags);
1961 /*
1962 * this freelist can be empty if an interrupt triggered disconnect()
1963 * and reconfigured the gadget (shutting down this queue) after the
1964 * network stack decided to xmit but before we got the spinlock.
1965 */
1966 if (list_empty(&dev->tx_reqs)) {
1967 spin_unlock_irqrestore(&dev->req_lock, flags);
1968 return 1;
1969 }
1970
1971 req = container_of (dev->tx_reqs.next, struct usb_request, list);
1972 list_del (&req->list);
1973
1974 /* temporarily stop TX queue when the freelist empties */
1975 if (list_empty (&dev->tx_reqs))
1976 netif_stop_queue (net);
1977 spin_unlock_irqrestore(&dev->req_lock, flags);
1978
1979 /* no buffer copies needed, unless the network stack did it
1980 * or the hardware can't use skb buffers.
1981 * or there's not enough space for any RNDIS headers we need
1982 */
1983 if (rndis_active(dev)) {
1984 struct sk_buff *skb_rndis;
1985
1986 skb_rndis = skb_realloc_headroom (skb,
1987 sizeof (struct rndis_packet_msg_type));
1988 if (!skb_rndis)
1989 goto drop;
1990
1991 dev_kfree_skb_any (skb);
1992 skb = skb_rndis;
1993 rndis_add_hdr (skb);
1994 length = skb->len;
1995 }
1996 req->buf = skb->data;
1997 req->context = skb;
1998 req->complete = tx_complete;
1999
2000 /* use zlp framing on tx for strict CDC-Ether conformance,
2001 * though any robust network rx path ignores extra padding.
2002 * and some hardware doesn't like to write zlps.
2003 */
2004 req->zero = 1;
2005 if (!dev->zlp && (length % dev->in_ep->maxpacket) == 0)
2006 length++;
2007
2008 req->length = length;
2009
2010 /* throttle highspeed IRQ rate back slightly */
2011 if (gadget_is_dualspeed(dev->gadget))
2012 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH)
2013 ? ((atomic_read(&dev->tx_qlen) % qmult) != 0)
2014 : 0;
2015
2016 retval = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC);
2017 switch (retval) {
2018 default:
2019 DEBUG (dev, "tx queue err %d\n", retval);
2020 break;
2021 case 0:
2022 net->trans_start = jiffies;
2023 atomic_inc (&dev->tx_qlen);
2024 }
2025
2026 if (retval) {
2027drop:
2028 dev->stats.tx_dropped++;
2029 dev_kfree_skb_any (skb);
2030 spin_lock_irqsave(&dev->req_lock, flags);
2031 if (list_empty (&dev->tx_reqs))
2032 netif_start_queue (net);
2033 list_add (&req->list, &dev->tx_reqs);
2034 spin_unlock_irqrestore(&dev->req_lock, flags);
2035 }
2036 return 0;
2037}
2038
2039/*-------------------------------------------------------------------------*/
2040
2041#ifdef CONFIG_USB_ETH_RNDIS
2042
2043/* The interrupt endpoint is used in RNDIS to notify the host when messages
2044 * other than data packets are available ... notably the REMOTE_NDIS_*_CMPLT
2045 * messages, but also REMOTE_NDIS_INDICATE_STATUS_MSG and potentially even
2046 * REMOTE_NDIS_KEEPALIVE_MSG.
2047 *
2048 * The RNDIS control queue is processed by GET_ENCAPSULATED_RESPONSE, and
2049 * normally just one notification will be queued.
2050 */
2051
2052static struct usb_request *eth_req_alloc (struct usb_ep *, unsigned, gfp_t);
2053static void eth_req_free (struct usb_ep *ep, struct usb_request *req);
2054
2055static void
2056rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req)
2057{
2058 struct eth_dev *dev = ep->driver_data;
2059
2060 if (req->status || req->actual != req->length)
2061 DEBUG (dev,
2062 "rndis control ack complete --> %d, %d/%d\n",
2063 req->status, req->actual, req->length);
2064 req->context = NULL;
2065
2066 if (req != dev->stat_req)
2067 eth_req_free(ep, req);
2068}
2069
2070static int rndis_control_ack (struct net_device *net)
2071{
2072 struct eth_dev *dev = netdev_priv(net);
2073 int length;
2074 struct usb_request *resp = dev->stat_req;
2075
2076 /* in case RNDIS calls this after disconnect */
2077 if (!dev->status) {
2078 DEBUG (dev, "status ENODEV\n");
2079 return -ENODEV;
2080 }
2081
2082 /* in case queue length > 1 */
2083 if (resp->context) {
2084 resp = eth_req_alloc (dev->status_ep, 8, GFP_ATOMIC);
2085 if (!resp)
2086 return -ENOMEM;
2087 }
2088
2089 /* Send RNDIS RESPONSE_AVAILABLE notification;
2090 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE should work too
2091 */
2092 resp->length = 8;
2093 resp->complete = rndis_control_ack_complete;
2094 resp->context = dev;
2095
2096 *((__le32 *) resp->buf) = __constant_cpu_to_le32 (1);
2097 *((__le32 *) resp->buf + 1) = __constant_cpu_to_le32 (0);
2098
2099 length = usb_ep_queue (dev->status_ep, resp, GFP_ATOMIC);
2100 if (length < 0) {
2101 resp->status = 0;
2102 rndis_control_ack_complete (dev->status_ep, resp);
2103 }
2104
2105 return 0;
2106}
2107
2108#else
2109
2110#define rndis_control_ack NULL
2111
2112#endif /* RNDIS */
2113
2114static void eth_start (struct eth_dev *dev, gfp_t gfp_flags)
2115{
2116 DEBUG (dev, "%s\n", __func__);
2117
2118 /* fill the rx queue */
2119 rx_fill (dev, gfp_flags);
2120
2121 /* and open the tx floodgates */
2122 atomic_set (&dev->tx_qlen, 0);
2123 netif_wake_queue (dev->net);
2124 if (rndis_active(dev)) {
2125 rndis_set_param_medium (dev->rndis_config,
2126 NDIS_MEDIUM_802_3,
2127 BITRATE(dev->gadget)/100);
2128 (void) rndis_signal_connect (dev->rndis_config);
2129 }
2130}
2131
2132static int eth_open (struct net_device *net)
2133{
2134 struct eth_dev *dev = netdev_priv(net);
2135
2136 DEBUG (dev, "%s\n", __func__);
2137 if (netif_carrier_ok (dev->net))
2138 eth_start (dev, GFP_KERNEL);
2139 return 0;
2140} 244}
2141 245
2142static int eth_stop (struct net_device *net) 246static struct usb_configuration eth_config_driver = {
2143{ 247 /* .label = f(hardware) */
2144 struct eth_dev *dev = netdev_priv(net); 248 .bind = eth_do_config,
2145 249 .bConfigurationValue = 1,
2146 VDEBUG (dev, "%s\n", __func__); 250 /* .iConfiguration = DYNAMIC */
2147 netif_stop_queue (net); 251 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
2148 252 .bMaxPower = 1, /* 2 mA, minimal */
2149 DEBUG (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld\n", 253};
2150 dev->stats.rx_packets, dev->stats.tx_packets,
2151 dev->stats.rx_errors, dev->stats.tx_errors
2152 );
2153
2154 /* ensure there are no more active requests */
2155 if (dev->config) {
2156 usb_ep_disable (dev->in_ep);
2157 usb_ep_disable (dev->out_ep);
2158 if (netif_carrier_ok (dev->net)) {
2159 DEBUG (dev, "host still using in/out endpoints\n");
2160 // FIXME idiom may leave toggle wrong here
2161 usb_ep_enable (dev->in_ep, dev->in);
2162 usb_ep_enable (dev->out_ep, dev->out);
2163 }
2164 if (dev->status_ep) {
2165 usb_ep_disable (dev->status_ep);
2166 usb_ep_enable (dev->status_ep, dev->status);
2167 }
2168 }
2169
2170 if (rndis_active(dev)) {
2171 rndis_set_param_medium(dev->rndis_config, NDIS_MEDIUM_802_3, 0);
2172 (void) rndis_signal_disconnect (dev->rndis_config);
2173 }
2174
2175 return 0;
2176}
2177 254
2178/*-------------------------------------------------------------------------*/ 255/*-------------------------------------------------------------------------*/
2179 256
2180static struct usb_request * 257static int __init eth_bind(struct usb_composite_dev *cdev)
2181eth_req_alloc (struct usb_ep *ep, unsigned size, gfp_t gfp_flags)
2182{ 258{
2183 struct usb_request *req; 259 int gcnum;
2184 260 struct usb_gadget *gadget = cdev->gadget;
2185 req = usb_ep_alloc_request (ep, gfp_flags); 261 int status;
2186 if (!req)
2187 return NULL;
2188
2189 req->buf = kmalloc (size, gfp_flags);
2190 if (!req->buf) {
2191 usb_ep_free_request (ep, req);
2192 req = NULL;
2193 }
2194 return req;
2195}
2196
2197static void
2198eth_req_free (struct usb_ep *ep, struct usb_request *req)
2199{
2200 kfree (req->buf);
2201 usb_ep_free_request (ep, req);
2202}
2203
2204
2205static void /* __init_or_exit */
2206eth_unbind (struct usb_gadget *gadget)
2207{
2208 struct eth_dev *dev = get_gadget_data (gadget);
2209
2210 DEBUG (dev, "unbind\n");
2211 rndis_deregister (dev->rndis_config);
2212 rndis_exit ();
2213
2214 /* we've already been disconnected ... no i/o is active */
2215 if (dev->req) {
2216 eth_req_free (gadget->ep0, dev->req);
2217 dev->req = NULL;
2218 }
2219 if (dev->stat_req) {
2220 eth_req_free (dev->status_ep, dev->stat_req);
2221 dev->stat_req = NULL;
2222 }
2223
2224 unregister_netdev (dev->net);
2225 free_netdev(dev->net);
2226
2227 /* assuming we used keventd, it must quiesce too */
2228 flush_scheduled_work ();
2229 set_gadget_data (gadget, NULL);
2230}
2231
2232static u8 __init nibble (unsigned char c)
2233{
2234 if (likely (isdigit (c)))
2235 return c - '0';
2236 c = toupper (c);
2237 if (likely (isxdigit (c)))
2238 return 10 + c - 'A';
2239 return 0;
2240}
2241 262
2242static int __init get_ether_addr(const char *str, u8 *dev_addr) 263 /* set up network link layer */
2243{ 264 status = gether_setup(cdev->gadget, hostaddr);
2244 if (str) { 265 if (status < 0)
2245 unsigned i; 266 return status;
2246 267
2247 for (i = 0; i < 6; i++) { 268 /* set up main config label and device descriptor */
2248 unsigned char num; 269 if (can_support_ecm(cdev->gadget)) {
270 /* ECM */
271 eth_config_driver.label = "CDC Ethernet (ECM)";
272 } else {
273 /* CDC Subset */
274 eth_config_driver.label = "CDC Subset/SAFE";
2249 275
2250 if((*str == '.') || (*str == ':')) 276 device_desc.idVendor = cpu_to_le16(SIMPLE_VENDOR_NUM),
2251 str++; 277 device_desc.idProduct = cpu_to_le16(SIMPLE_PRODUCT_NUM),
2252 num = nibble(*str++) << 4; 278 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
2253 num |= (nibble(*str++));
2254 dev_addr [i] = num;
2255 }
2256 if (is_valid_ether_addr (dev_addr))
2257 return 0;
2258 } 279 }
2259 random_ether_addr(dev_addr);
2260 return 1;
2261}
2262
2263static int __init
2264eth_bind (struct usb_gadget *gadget)
2265{
2266 struct eth_dev *dev;
2267 struct net_device *net;
2268 u8 cdc = 1, zlp = 1, rndis = 1;
2269 struct usb_ep *in_ep, *out_ep, *status_ep = NULL;
2270 int status = -ENOMEM;
2271 int gcnum;
2272
2273 /* these flags are only ever cleared; compiler take note */
2274#ifndef DEV_CONFIG_CDC
2275 cdc = 0;
2276#endif
2277#ifndef CONFIG_USB_ETH_RNDIS
2278 rndis = 0;
2279#endif
2280 280
2281 /* Because most host side USB stacks handle CDC Ethernet, that 281 if (has_rndis()) {
2282 * standard protocol is _strongly_ preferred for interop purposes. 282 /* RNDIS plus ECM-or-Subset */
2283 * (By everyone except Microsoft.) 283 device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM),
2284 */ 284 device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM),
2285 if (gadget_is_pxa (gadget)) { 285 device_desc.bNumConfigurations = 2;
2286 /* pxa doesn't support altsettings */
2287 cdc = 0;
2288 } else if (gadget_is_musbhdrc(gadget)) {
2289 /* reduce tx dma overhead by avoiding special cases */
2290 zlp = 0;
2291 } else if (gadget_is_sh(gadget)) {
2292 /* sh doesn't support multiple interfaces or configs */
2293 cdc = 0;
2294 rndis = 0;
2295 } else if (gadget_is_sa1100 (gadget)) {
2296 /* hardware can't write zlps */
2297 zlp = 0;
2298 /* sa1100 CAN do CDC, without status endpoint ... we use
2299 * non-CDC to be compatible with ARM Linux-2.4 "usb-eth".
2300 */
2301 cdc = 0;
2302 } 286 }
2303 287
2304 gcnum = usb_gadget_controller_number (gadget); 288 gcnum = usb_gadget_controller_number(gadget);
2305 if (gcnum >= 0) 289 if (gcnum >= 0)
2306 device_desc.bcdDevice = cpu_to_le16 (0x0200 + gcnum); 290 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
2307 else { 291 else {
2308 /* can't assume CDC works. don't want to default to 292 /* We assume that can_support_ecm() tells the truth;
2309 * anything less functional on CDC-capable hardware, 293 * but if the controller isn't recognized at all then
2310 * so we fail in this case. 294 * that assumption is a bit more likely to be wrong.
2311 */ 295 */
2312 dev_err (&gadget->dev, 296 WARN(cdev, "controller '%s' not recognized; trying %s\n",
2313 "controller '%s' not recognized\n", 297 gadget->name,
2314 gadget->name); 298 eth_config_driver.label);
2315 return -ENODEV; 299 device_desc.bcdDevice =
2316 } 300 __constant_cpu_to_le16(0x0300 | 0x0099);
2317 snprintf (manufacturer, sizeof manufacturer, "%s %s/%s",
2318 init_utsname()->sysname, init_utsname()->release,
2319 gadget->name);
2320
2321 /* If there's an RNDIS configuration, that's what Windows wants to
2322 * be using ... so use these product IDs here and in the "linux.inf"
2323 * needed to install MSFT drivers. Current Linux kernels will use
2324 * the second configuration if it's CDC Ethernet, and need some help
2325 * to choose the right configuration otherwise.
2326 */
2327 if (rndis) {
2328 device_desc.idVendor =
2329 __constant_cpu_to_le16(RNDIS_VENDOR_NUM);
2330 device_desc.idProduct =
2331 __constant_cpu_to_le16(RNDIS_PRODUCT_NUM);
2332 snprintf (product_desc, sizeof product_desc,
2333 "RNDIS/%s", driver_desc);
2334
2335 /* CDC subset ... recognized by Linux since 2.4.10, but Windows
2336 * drivers aren't widely available. (That may be improved by
2337 * supporting one submode of the "SAFE" variant of MDLM.)
2338 */
2339 } else if (!cdc) {
2340 device_desc.idVendor =
2341 __constant_cpu_to_le16(SIMPLE_VENDOR_NUM);
2342 device_desc.idProduct =
2343 __constant_cpu_to_le16(SIMPLE_PRODUCT_NUM);
2344 }
2345
2346 /* support optional vendor/distro customization */
2347 if (idVendor) {
2348 if (!idProduct) {
2349 dev_err (&gadget->dev, "idVendor needs idProduct!\n");
2350 return -ENODEV;
2351 }
2352 device_desc.idVendor = cpu_to_le16(idVendor);
2353 device_desc.idProduct = cpu_to_le16(idProduct);
2354 if (bcdDevice)
2355 device_desc.bcdDevice = cpu_to_le16(bcdDevice);
2356 }
2357 if (iManufacturer)
2358 strlcpy (manufacturer, iManufacturer, sizeof manufacturer);
2359 if (iProduct)
2360 strlcpy (product_desc, iProduct, sizeof product_desc);
2361 if (iSerialNumber) {
2362 device_desc.iSerialNumber = STRING_SERIALNUMBER,
2363 strlcpy(serial_number, iSerialNumber, sizeof serial_number);
2364 }
2365
2366 /* all we really need is bulk IN/OUT */
2367 usb_ep_autoconfig_reset (gadget);
2368 in_ep = usb_ep_autoconfig (gadget, &fs_source_desc);
2369 if (!in_ep) {
2370autoconf_fail:
2371 dev_err (&gadget->dev,
2372 "can't autoconfigure on %s\n",
2373 gadget->name);
2374 return -ENODEV;
2375 }
2376 in_ep->driver_data = in_ep; /* claim */
2377
2378 out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc);
2379 if (!out_ep)
2380 goto autoconf_fail;
2381 out_ep->driver_data = out_ep; /* claim */
2382
2383#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2384 /* CDC Ethernet control interface doesn't require a status endpoint.
2385 * Since some hosts expect one, try to allocate one anyway.
2386 */
2387 if (cdc || rndis) {
2388 status_ep = usb_ep_autoconfig (gadget, &fs_status_desc);
2389 if (status_ep) {
2390 status_ep->driver_data = status_ep; /* claim */
2391 } else if (rndis) {
2392 dev_err (&gadget->dev,
2393 "can't run RNDIS on %s\n",
2394 gadget->name);
2395 return -ENODEV;
2396#ifdef DEV_CONFIG_CDC
2397 /* pxa25x only does CDC subset; often used with RNDIS */
2398 } else if (cdc) {
2399 control_intf.bNumEndpoints = 0;
2400 /* FIXME remove endpoint from descriptor list */
2401#endif
2402 }
2403 }
2404#endif
2405
2406 /* one config: cdc, else minimal subset */
2407 if (!cdc) {
2408 eth_config.bNumInterfaces = 1;
2409 eth_config.iConfiguration = STRING_SUBSET;
2410
2411 /* use functions to set these up, in case we're built to work
2412 * with multiple controllers and must override CDC Ethernet.
2413 */
2414 fs_subset_descriptors();
2415 hs_subset_descriptors();
2416 }
2417
2418 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
2419 usb_gadget_set_selfpowered (gadget);
2420
2421 /* For now RNDIS is always a second config */
2422 if (rndis)
2423 device_desc.bNumConfigurations = 2;
2424
2425 if (gadget_is_dualspeed(gadget)) {
2426 if (rndis)
2427 dev_qualifier.bNumConfigurations = 2;
2428 else if (!cdc)
2429 dev_qualifier.bDeviceClass = USB_CLASS_VENDOR_SPEC;
2430
2431 /* assumes ep0 uses the same value for both speeds ... */
2432 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
2433
2434 /* and that all endpoints are dual-speed */
2435 hs_source_desc.bEndpointAddress =
2436 fs_source_desc.bEndpointAddress;
2437 hs_sink_desc.bEndpointAddress =
2438 fs_sink_desc.bEndpointAddress;
2439#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2440 if (status_ep)
2441 hs_status_desc.bEndpointAddress =
2442 fs_status_desc.bEndpointAddress;
2443#endif
2444 } 301 }
2445 302
2446 if (gadget_is_otg(gadget)) {
2447 otg_descriptor.bmAttributes |= USB_OTG_HNP,
2448 eth_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
2449 eth_config.bMaxPower = 4;
2450#ifdef CONFIG_USB_ETH_RNDIS
2451 rndis_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
2452 rndis_config.bMaxPower = 4;
2453#endif
2454 }
2455
2456 net = alloc_etherdev (sizeof *dev);
2457 if (!net)
2458 return status;
2459 dev = netdev_priv(net);
2460 spin_lock_init (&dev->lock);
2461 spin_lock_init (&dev->req_lock);
2462 INIT_WORK (&dev->work, eth_work);
2463 INIT_LIST_HEAD (&dev->tx_reqs);
2464 INIT_LIST_HEAD (&dev->rx_reqs);
2465
2466 /* network device setup */
2467 dev->net = net;
2468 strcpy (net->name, "usb%d");
2469 dev->cdc = cdc;
2470 dev->zlp = zlp;
2471 303
2472 dev->in_ep = in_ep; 304 /* Allocate string descriptor numbers ... note that string
2473 dev->out_ep = out_ep; 305 * contents can be overridden by the composite_dev glue.
2474 dev->status_ep = status_ep;
2475
2476 /* Module params for these addresses should come from ID proms.
2477 * The host side address is used with CDC and RNDIS, and commonly
2478 * ends up in a persistent config database. It's not clear if
2479 * host side code for the SAFE thing cares -- its original BLAN
2480 * thing didn't, Sharp never assigned those addresses on Zaurii.
2481 */ 306 */
2482 if (get_ether_addr(dev_addr, net->dev_addr))
2483 dev_warn(&gadget->dev,
2484 "using random %s ethernet address\n", "self");
2485 if (get_ether_addr(host_addr, dev->host_mac))
2486 dev_warn(&gadget->dev,
2487 "using random %s ethernet address\n", "host");
2488 snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X",
2489 dev->host_mac [0], dev->host_mac [1],
2490 dev->host_mac [2], dev->host_mac [3],
2491 dev->host_mac [4], dev->host_mac [5]);
2492
2493 if (rndis) {
2494 status = rndis_init();
2495 if (status < 0) {
2496 dev_err (&gadget->dev, "can't init RNDIS, %d\n",
2497 status);
2498 goto fail;
2499 }
2500 }
2501 307
2502 net->change_mtu = eth_change_mtu; 308 /* device descriptor strings: manufacturer, product */
2503 net->get_stats = eth_get_stats; 309 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
2504 net->hard_start_xmit = eth_start_xmit; 310 init_utsname()->sysname, init_utsname()->release,
2505 net->open = eth_open; 311 gadget->name);
2506 net->stop = eth_stop; 312 status = usb_string_id(cdev);
2507 // watchdog_timeo, tx_timeout ... 313 if (status < 0)
2508 // set_multicast_list 314 goto fail;
2509 SET_ETHTOOL_OPS(net, &ops); 315 strings_dev[STRING_MANUFACTURER_IDX].id = status;
316 device_desc.iManufacturer = status;
2510 317
2511 /* preallocate control message data and buffer */ 318 status = usb_string_id(cdev);
2512 dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ, GFP_KERNEL); 319 if (status < 0)
2513 if (!dev->req)
2514 goto fail; 320 goto fail;
2515 dev->req->complete = eth_setup_complete; 321 strings_dev[STRING_PRODUCT_IDX].id = status;
322 device_desc.iProduct = status;
2516 323
2517 /* ... and maybe likewise for status transfer */ 324 /* register our configuration(s); RNDIS first, if it's used */
2518#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 325 if (has_rndis()) {
2519 if (dev->status_ep) { 326 status = usb_add_config(cdev, &rndis_config_driver);
2520 dev->stat_req = eth_req_alloc (dev->status_ep, 327 if (status < 0)
2521 STATUS_BYTECOUNT, GFP_KERNEL);
2522 if (!dev->stat_req) {
2523 eth_req_free (gadget->ep0, dev->req);
2524 goto fail; 328 goto fail;
2525 }
2526 dev->stat_req->context = NULL;
2527 } 329 }
2528#endif
2529
2530 /* finish hookup to lower layer ... */
2531 dev->gadget = gadget;
2532 set_gadget_data (gadget, dev);
2533 gadget->ep0->driver_data = dev;
2534 330
2535 /* two kinds of host-initiated state changes: 331 status = usb_add_config(cdev, &eth_config_driver);
2536 * - iff DATA transfer is active, carrier is "on"
2537 * - tx queueing enabled if open *and* carrier is "on"
2538 */
2539 netif_stop_queue (dev->net);
2540 netif_carrier_off (dev->net);
2541
2542 SET_NETDEV_DEV (dev->net, &gadget->dev);
2543 status = register_netdev (dev->net);
2544 if (status < 0) 332 if (status < 0)
2545 goto fail1; 333 goto fail;
2546
2547 INFO (dev, "%s, version: " DRIVER_VERSION "\n", driver_desc);
2548 INFO (dev, "using %s, OUT %s IN %s%s%s\n", gadget->name,
2549 out_ep->name, in_ep->name,
2550 status_ep ? " STATUS " : "",
2551 status_ep ? status_ep->name : ""
2552 );
2553 INFO (dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
2554 net->dev_addr [0], net->dev_addr [1],
2555 net->dev_addr [2], net->dev_addr [3],
2556 net->dev_addr [4], net->dev_addr [5]);
2557
2558 if (cdc || rndis)
2559 INFO (dev, "HOST MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
2560 dev->host_mac [0], dev->host_mac [1],
2561 dev->host_mac [2], dev->host_mac [3],
2562 dev->host_mac [4], dev->host_mac [5]);
2563
2564 if (rndis) {
2565 u32 vendorID = 0;
2566
2567 /* FIXME RNDIS vendor id == "vendor NIC code" == ? */
2568
2569 dev->rndis_config = rndis_register (rndis_control_ack);
2570 if (dev->rndis_config < 0) {
2571fail0:
2572 unregister_netdev (dev->net);
2573 status = -ENODEV;
2574 goto fail;
2575 }
2576 334
2577 /* these set up a lot of the OIDs that RNDIS needs */ 335 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC);
2578 rndis_set_host_mac (dev->rndis_config, dev->host_mac);
2579 if (rndis_set_param_dev (dev->rndis_config, dev->net,
2580 &dev->stats, &dev->cdc_filter))
2581 goto fail0;
2582 if (rndis_set_param_vendor(dev->rndis_config, vendorID,
2583 manufacturer))
2584 goto fail0;
2585 if (rndis_set_param_medium(dev->rndis_config,
2586 NDIS_MEDIUM_802_3, 0))
2587 goto fail0;
2588 INFO (dev, "RNDIS ready\n");
2589 }
2590 336
2591 return status; 337 return 0;
2592 338
2593fail1:
2594 dev_dbg(&gadget->dev, "register_netdev failed, %d\n", status);
2595fail: 339fail:
2596 eth_unbind (gadget); 340 gether_cleanup();
2597 return status; 341 return status;
2598} 342}
2599 343
2600/*-------------------------------------------------------------------------*/ 344static int __exit eth_unbind(struct usb_composite_dev *cdev)
2601
2602static void
2603eth_suspend (struct usb_gadget *gadget)
2604{
2605 struct eth_dev *dev = get_gadget_data (gadget);
2606
2607 DEBUG (dev, "suspend\n");
2608 dev->suspended = 1;
2609}
2610
2611static void
2612eth_resume (struct usb_gadget *gadget)
2613{ 345{
2614 struct eth_dev *dev = get_gadget_data (gadget); 346 gether_cleanup();
2615 347 return 0;
2616 DEBUG (dev, "resume\n");
2617 dev->suspended = 0;
2618} 348}
2619 349
2620/*-------------------------------------------------------------------------*/ 350static struct usb_composite_driver eth_driver = {
2621 351 .name = "g_ether",
2622static struct usb_gadget_driver eth_driver = { 352 .dev = &device_desc,
2623 .speed = DEVSPEED, 353 .strings = dev_strings,
2624
2625 .function = (char *) driver_desc,
2626 .bind = eth_bind, 354 .bind = eth_bind,
2627 .unbind = eth_unbind, 355 .unbind = __exit_p(eth_unbind),
2628
2629 .setup = eth_setup,
2630 .disconnect = eth_disconnect,
2631
2632 .suspend = eth_suspend,
2633 .resume = eth_resume,
2634
2635 .driver = {
2636 .name = (char *) shortname,
2637 .owner = THIS_MODULE,
2638 },
2639}; 356};
2640 357
2641MODULE_DESCRIPTION (DRIVER_DESC); 358MODULE_DESCRIPTION(PREFIX DRIVER_DESC);
2642MODULE_AUTHOR ("David Brownell, Benedikt Spanger"); 359MODULE_AUTHOR("David Brownell, Benedikt Spanger");
2643MODULE_LICENSE ("GPL"); 360MODULE_LICENSE("GPL");
2644 361
2645 362static int __init init(void)
2646static int __init init (void)
2647{ 363{
2648 return usb_gadget_register_driver (&eth_driver); 364 return usb_composite_register(&eth_driver);
2649} 365}
2650module_init (init); 366module_init(init);
2651 367
2652static void __exit cleanup (void) 368static void __exit cleanup(void)
2653{ 369{
2654 usb_gadget_unregister_driver (&eth_driver); 370 usb_composite_unregister(&eth_driver);
2655} 371}
2656module_exit (cleanup); 372module_exit(cleanup);
2657
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
new file mode 100644
index 000000000000..d8faccf27895
--- /dev/null
+++ b/drivers/usb/gadget/f_acm.c
@@ -0,0 +1,589 @@
1/*
2 * f_acm.c -- USB CDC serial (ACM) function driver
3 *
4 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
5 * Copyright (C) 2008 by David Brownell
6 * Copyright (C) 2008 by Nokia Corporation
7 *
8 * This software is distributed under the terms of the GNU General
9 * Public License ("GPL") as published by the Free Software Foundation,
10 * either version 2 of that License or (at your option) any later version.
11 */
12
13/* #define VERBOSE_DEBUG */
14
15#include <linux/kernel.h>
16#include <linux/device.h>
17
18#include "u_serial.h"
19#include "gadget_chips.h"
20
21
22/*
23 * This CDC ACM function support just wraps control functions and
24 * notifications around the generic serial-over-usb code.
25 *
26 * Because CDC ACM is standardized by the USB-IF, many host operating
27 * systems have drivers for it. Accordingly, ACM is the preferred
28 * interop solution for serial-port type connections. The control
29 * models are often not necessary, and in any case don't do much in
30 * this bare-bones implementation.
31 *
32 * Note that even MS-Windows has some support for ACM. However, that
33 * support is somewhat broken because when you use ACM in a composite
34 * device, having multiple interfaces confuses the poor OS. It doesn't
35 * seem to understand CDC Union descriptors. The new "association"
36 * descriptors (roughly equivalent to CDC Unions) may sometimes help.
37 */
38
39struct acm_ep_descs {
40 struct usb_endpoint_descriptor *in;
41 struct usb_endpoint_descriptor *out;
42 struct usb_endpoint_descriptor *notify;
43};
44
45struct f_acm {
46 struct gserial port;
47 u8 ctrl_id, data_id;
48 u8 port_num;
49
50 struct usb_descriptor_header **fs_function;
51 struct acm_ep_descs fs;
52 struct usb_descriptor_header **hs_function;
53 struct acm_ep_descs hs;
54
55 struct usb_ep *notify;
56 struct usb_endpoint_descriptor *notify_desc;
57
58 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
59 u16 port_handshake_bits;
60#define RS232_RTS (1 << 1) /* unused with full duplex */
61#define RS232_DTR (1 << 0) /* host is ready for data r/w */
62};
63
64static inline struct f_acm *func_to_acm(struct usb_function *f)
65{
66 return container_of(f, struct f_acm, port.func);
67}
68
69/*-------------------------------------------------------------------------*/
70
71/* notification endpoint uses smallish and infrequent fixed-size messages */
72
73#define GS_LOG2_NOTIFY_INTERVAL 5 /* 1 << 5 == 32 msec */
74#define GS_NOTIFY_MAXPACKET 8
75
76/* interface and class descriptors: */
77
78static struct usb_interface_descriptor acm_control_interface_desc __initdata = {
79 .bLength = USB_DT_INTERFACE_SIZE,
80 .bDescriptorType = USB_DT_INTERFACE,
81 /* .bInterfaceNumber = DYNAMIC */
82 .bNumEndpoints = 1,
83 .bInterfaceClass = USB_CLASS_COMM,
84 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
85 .bInterfaceProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
86 /* .iInterface = DYNAMIC */
87};
88
89static struct usb_interface_descriptor acm_data_interface_desc __initdata = {
90 .bLength = USB_DT_INTERFACE_SIZE,
91 .bDescriptorType = USB_DT_INTERFACE,
92 /* .bInterfaceNumber = DYNAMIC */
93 .bNumEndpoints = 2,
94 .bInterfaceClass = USB_CLASS_CDC_DATA,
95 .bInterfaceSubClass = 0,
96 .bInterfaceProtocol = 0,
97 /* .iInterface = DYNAMIC */
98};
99
100static struct usb_cdc_header_desc acm_header_desc __initdata = {
101 .bLength = sizeof(acm_header_desc),
102 .bDescriptorType = USB_DT_CS_INTERFACE,
103 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
104 .bcdCDC = __constant_cpu_to_le16(0x0110),
105};
106
107static struct usb_cdc_call_mgmt_descriptor
108acm_call_mgmt_descriptor __initdata = {
109 .bLength = sizeof(acm_call_mgmt_descriptor),
110 .bDescriptorType = USB_DT_CS_INTERFACE,
111 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
112 .bmCapabilities = 0,
113 /* .bDataInterface = DYNAMIC */
114};
115
116static struct usb_cdc_acm_descriptor acm_descriptor __initdata = {
117 .bLength = sizeof(acm_descriptor),
118 .bDescriptorType = USB_DT_CS_INTERFACE,
119 .bDescriptorSubType = USB_CDC_ACM_TYPE,
120 .bmCapabilities = (1 << 1),
121};
122
123static struct usb_cdc_union_desc acm_union_desc __initdata = {
124 .bLength = sizeof(acm_union_desc),
125 .bDescriptorType = USB_DT_CS_INTERFACE,
126 .bDescriptorSubType = USB_CDC_UNION_TYPE,
127 /* .bMasterInterface0 = DYNAMIC */
128 /* .bSlaveInterface0 = DYNAMIC */
129};
130
131/* full speed support: */
132
133static struct usb_endpoint_descriptor acm_fs_notify_desc __initdata = {
134 .bLength = USB_DT_ENDPOINT_SIZE,
135 .bDescriptorType = USB_DT_ENDPOINT,
136 .bEndpointAddress = USB_DIR_IN,
137 .bmAttributes = USB_ENDPOINT_XFER_INT,
138 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET),
139 .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL,
140};
141
142static struct usb_endpoint_descriptor acm_fs_in_desc __initdata = {
143 .bLength = USB_DT_ENDPOINT_SIZE,
144 .bDescriptorType = USB_DT_ENDPOINT,
145 .bEndpointAddress = USB_DIR_IN,
146 .bmAttributes = USB_ENDPOINT_XFER_BULK,
147};
148
149static struct usb_endpoint_descriptor acm_fs_out_desc __initdata = {
150 .bLength = USB_DT_ENDPOINT_SIZE,
151 .bDescriptorType = USB_DT_ENDPOINT,
152 .bEndpointAddress = USB_DIR_OUT,
153 .bmAttributes = USB_ENDPOINT_XFER_BULK,
154};
155
156static struct usb_descriptor_header *acm_fs_function[] __initdata = {
157 (struct usb_descriptor_header *) &acm_control_interface_desc,
158 (struct usb_descriptor_header *) &acm_header_desc,
159 (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
160 (struct usb_descriptor_header *) &acm_descriptor,
161 (struct usb_descriptor_header *) &acm_union_desc,
162 (struct usb_descriptor_header *) &acm_fs_notify_desc,
163 (struct usb_descriptor_header *) &acm_data_interface_desc,
164 (struct usb_descriptor_header *) &acm_fs_in_desc,
165 (struct usb_descriptor_header *) &acm_fs_out_desc,
166 NULL,
167};
168
169/* high speed support: */
170
171static struct usb_endpoint_descriptor acm_hs_notify_desc __initdata = {
172 .bLength = USB_DT_ENDPOINT_SIZE,
173 .bDescriptorType = USB_DT_ENDPOINT,
174 .bEndpointAddress = USB_DIR_IN,
175 .bmAttributes = USB_ENDPOINT_XFER_INT,
176 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET),
177 .bInterval = GS_LOG2_NOTIFY_INTERVAL+4,
178};
179
180static struct usb_endpoint_descriptor acm_hs_in_desc __initdata = {
181 .bLength = USB_DT_ENDPOINT_SIZE,
182 .bDescriptorType = USB_DT_ENDPOINT,
183 .bmAttributes = USB_ENDPOINT_XFER_BULK,
184 .wMaxPacketSize = __constant_cpu_to_le16(512),
185};
186
187static struct usb_endpoint_descriptor acm_hs_out_desc __initdata = {
188 .bLength = USB_DT_ENDPOINT_SIZE,
189 .bDescriptorType = USB_DT_ENDPOINT,
190 .bmAttributes = USB_ENDPOINT_XFER_BULK,
191 .wMaxPacketSize = __constant_cpu_to_le16(512),
192};
193
194static struct usb_descriptor_header *acm_hs_function[] __initdata = {
195 (struct usb_descriptor_header *) &acm_control_interface_desc,
196 (struct usb_descriptor_header *) &acm_header_desc,
197 (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
198 (struct usb_descriptor_header *) &acm_descriptor,
199 (struct usb_descriptor_header *) &acm_union_desc,
200 (struct usb_descriptor_header *) &acm_hs_notify_desc,
201 (struct usb_descriptor_header *) &acm_data_interface_desc,
202 (struct usb_descriptor_header *) &acm_hs_in_desc,
203 (struct usb_descriptor_header *) &acm_hs_out_desc,
204 NULL,
205};
206
207/* string descriptors: */
208
209#define ACM_CTRL_IDX 0
210#define ACM_DATA_IDX 1
211
212/* static strings, in UTF-8 */
213static struct usb_string acm_string_defs[] = {
214 [ACM_CTRL_IDX].s = "CDC Abstract Control Model (ACM)",
215 [ACM_DATA_IDX].s = "CDC ACM Data",
216 { /* ZEROES END LIST */ },
217};
218
219static struct usb_gadget_strings acm_string_table = {
220 .language = 0x0409, /* en-us */
221 .strings = acm_string_defs,
222};
223
224static struct usb_gadget_strings *acm_strings[] = {
225 &acm_string_table,
226 NULL,
227};
228
229/*-------------------------------------------------------------------------*/
230
231/* ACM control ... data handling is delegated to tty library code.
232 * The main task of this function is to activate and deactivate
233 * that code based on device state; track parameters like line
234 * speed, handshake state, and so on; and issue notifications.
235 */
236
237static void acm_complete_set_line_coding(struct usb_ep *ep,
238 struct usb_request *req)
239{
240 struct f_acm *acm = ep->driver_data;
241 struct usb_composite_dev *cdev = acm->port.func.config->cdev;
242
243 if (req->status != 0) {
244 DBG(cdev, "acm ttyGS%d completion, err %d\n",
245 acm->port_num, req->status);
246 return;
247 }
248
249 /* normal completion */
250 if (req->actual != sizeof(acm->port_line_coding)) {
251 DBG(cdev, "acm ttyGS%d short resp, len %d\n",
252 acm->port_num, req->actual);
253 usb_ep_set_halt(ep);
254 } else {
255 struct usb_cdc_line_coding *value = req->buf;
256
257 /* REVISIT: we currently just remember this data.
258 * If we change that, (a) validate it first, then
259 * (b) update whatever hardware needs updating,
260 * (c) worry about locking. This is information on
261 * the order of 9600-8-N-1 ... most of which means
262 * nothing unless we control a real RS232 line.
263 */
264 acm->port_line_coding = *value;
265 }
266}
267
268static int acm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
269{
270 struct f_acm *acm = func_to_acm(f);
271 struct usb_composite_dev *cdev = f->config->cdev;
272 struct usb_request *req = cdev->req;
273 int value = -EOPNOTSUPP;
274 u16 w_index = le16_to_cpu(ctrl->wIndex);
275 u16 w_value = le16_to_cpu(ctrl->wValue);
276 u16 w_length = le16_to_cpu(ctrl->wLength);
277
278 /* composite driver infrastructure handles everything except
279 * CDC class messages; interface activation uses set_alt().
280 */
281 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
282
283 /* SET_LINE_CODING ... just read and save what the host sends */
284 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
285 | USB_CDC_REQ_SET_LINE_CODING:
286 if (w_length != sizeof(struct usb_cdc_line_coding)
287 || w_index != acm->ctrl_id)
288 goto invalid;
289
290 value = w_length;
291 cdev->gadget->ep0->driver_data = acm;
292 req->complete = acm_complete_set_line_coding;
293 break;
294
295 /* GET_LINE_CODING ... return what host sent, or initial value */
296 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
297 | USB_CDC_REQ_GET_LINE_CODING:
298 if (w_index != acm->ctrl_id)
299 goto invalid;
300
301 value = min_t(unsigned, w_length,
302 sizeof(struct usb_cdc_line_coding));
303 memcpy(req->buf, &acm->port_line_coding, value);
304 break;
305
306 /* SET_CONTROL_LINE_STATE ... save what the host sent */
307 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
308 | USB_CDC_REQ_SET_CONTROL_LINE_STATE:
309 if (w_index != acm->ctrl_id)
310 goto invalid;
311
312 value = 0;
313
314 /* FIXME we should not allow data to flow until the
315 * host sets the RS232_DTR bit; and when it clears
316 * that bit, we should return to that no-flow state.
317 */
318 acm->port_handshake_bits = w_value;
319 break;
320
321 default:
322invalid:
323 VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
324 ctrl->bRequestType, ctrl->bRequest,
325 w_value, w_index, w_length);
326 }
327
328 /* respond with data transfer or status phase? */
329 if (value >= 0) {
330 DBG(cdev, "acm ttyGS%d req%02x.%02x v%04x i%04x l%d\n",
331 acm->port_num, ctrl->bRequestType, ctrl->bRequest,
332 w_value, w_index, w_length);
333 req->zero = 0;
334 req->length = value;
335 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
336 if (value < 0)
337 ERROR(cdev, "acm response on ttyGS%d, err %d\n",
338 acm->port_num, value);
339 }
340
341 /* device either stalls (value < 0) or reports success */
342 return value;
343}
344
345static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
346{
347 struct f_acm *acm = func_to_acm(f);
348 struct usb_composite_dev *cdev = f->config->cdev;
349
350 /* we know alt == 0, so this is an activation or a reset */
351
352 if (intf == acm->ctrl_id) {
353 /* REVISIT this may need more work when we start to
354 * send notifications ...
355 */
356 if (acm->notify->driver_data) {
357 VDBG(cdev, "reset acm control interface %d\n", intf);
358 usb_ep_disable(acm->notify);
359 } else {
360 VDBG(cdev, "init acm ctrl interface %d\n", intf);
361 acm->notify_desc = ep_choose(cdev->gadget,
362 acm->hs.notify,
363 acm->fs.notify);
364 }
365 usb_ep_enable(acm->notify, acm->notify_desc);
366 acm->notify->driver_data = acm;
367
368 } else if (intf == acm->data_id) {
369 if (acm->port.in->driver_data) {
370 DBG(cdev, "reset acm ttyGS%d\n", acm->port_num);
371 gserial_disconnect(&acm->port);
372 } else {
373 DBG(cdev, "activate acm ttyGS%d\n", acm->port_num);
374 acm->port.in_desc = ep_choose(cdev->gadget,
375 acm->hs.in, acm->fs.in);
376 acm->port.out_desc = ep_choose(cdev->gadget,
377 acm->hs.out, acm->fs.out);
378 }
379 gserial_connect(&acm->port, acm->port_num);
380
381 } else
382 return -EINVAL;
383
384 return 0;
385}
386
387static void acm_disable(struct usb_function *f)
388{
389 struct f_acm *acm = func_to_acm(f);
390 struct usb_composite_dev *cdev = f->config->cdev;
391
392 DBG(cdev, "acm ttyGS%d deactivated\n", acm->port_num);
393 gserial_disconnect(&acm->port);
394 usb_ep_disable(acm->notify);
395 acm->notify->driver_data = NULL;
396}
397
398/*-------------------------------------------------------------------------*/
399
400/* ACM function driver setup/binding */
401static int __init
402acm_bind(struct usb_configuration *c, struct usb_function *f)
403{
404 struct usb_composite_dev *cdev = c->cdev;
405 struct f_acm *acm = func_to_acm(f);
406 int status;
407 struct usb_ep *ep;
408
409 /* allocate instance-specific interface IDs, and patch descriptors */
410 status = usb_interface_id(c, f);
411 if (status < 0)
412 goto fail;
413 acm->ctrl_id = status;
414
415 acm_control_interface_desc.bInterfaceNumber = status;
416 acm_union_desc .bMasterInterface0 = status;
417
418 status = usb_interface_id(c, f);
419 if (status < 0)
420 goto fail;
421 acm->data_id = status;
422
423 acm_data_interface_desc.bInterfaceNumber = status;
424 acm_union_desc.bSlaveInterface0 = status;
425 acm_call_mgmt_descriptor.bDataInterface = status;
426
427 status = -ENODEV;
428
429 /* allocate instance-specific endpoints */
430 ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_in_desc);
431 if (!ep)
432 goto fail;
433 acm->port.in = ep;
434 ep->driver_data = cdev; /* claim */
435
436 ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_out_desc);
437 if (!ep)
438 goto fail;
439 acm->port.out = ep;
440 ep->driver_data = cdev; /* claim */
441
442 ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_notify_desc);
443 if (!ep)
444 goto fail;
445 acm->notify = ep;
446 ep->driver_data = cdev; /* claim */
447
448 /* copy descriptors, and track endpoint copies */
449 f->descriptors = usb_copy_descriptors(acm_fs_function);
450
451 acm->fs.in = usb_find_endpoint(acm_fs_function,
452 f->descriptors, &acm_fs_in_desc);
453 acm->fs.out = usb_find_endpoint(acm_fs_function,
454 f->descriptors, &acm_fs_out_desc);
455 acm->fs.notify = usb_find_endpoint(acm_fs_function,
456 f->descriptors, &acm_fs_notify_desc);
457
458 /* support all relevant hardware speeds... we expect that when
459 * hardware is dual speed, all bulk-capable endpoints work at
460 * both speeds
461 */
462 if (gadget_is_dualspeed(c->cdev->gadget)) {
463 acm_hs_in_desc.bEndpointAddress =
464 acm_fs_in_desc.bEndpointAddress;
465 acm_hs_out_desc.bEndpointAddress =
466 acm_fs_out_desc.bEndpointAddress;
467 acm_hs_notify_desc.bEndpointAddress =
468 acm_fs_notify_desc.bEndpointAddress;
469
470 /* copy descriptors, and track endpoint copies */
471 f->hs_descriptors = usb_copy_descriptors(acm_hs_function);
472
473 acm->hs.in = usb_find_endpoint(acm_hs_function,
474 f->hs_descriptors, &acm_hs_in_desc);
475 acm->hs.out = usb_find_endpoint(acm_hs_function,
476 f->hs_descriptors, &acm_hs_out_desc);
477 acm->hs.notify = usb_find_endpoint(acm_hs_function,
478 f->hs_descriptors, &acm_hs_notify_desc);
479 }
480
481 /* FIXME provide a callback for triggering notifications */
482
483 DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n",
484 acm->port_num,
485 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
486 acm->port.in->name, acm->port.out->name,
487 acm->notify->name);
488 return 0;
489
490fail:
491 /* we might as well release our claims on endpoints */
492 if (acm->notify)
493 acm->notify->driver_data = NULL;
494 if (acm->port.out)
495 acm->port.out->driver_data = NULL;
496 if (acm->port.in)
497 acm->port.in->driver_data = NULL;
498
499 ERROR(cdev, "%s/%p: can't bind, err %d\n", f->name, f, status);
500
501 return status;
502}
503
504static void
505acm_unbind(struct usb_configuration *c, struct usb_function *f)
506{
507 if (gadget_is_dualspeed(c->cdev->gadget))
508 usb_free_descriptors(f->hs_descriptors);
509 usb_free_descriptors(f->descriptors);
510 kfree(func_to_acm(f));
511}
512
513/* Some controllers can't support CDC ACM ... */
514static inline bool can_support_cdc(struct usb_configuration *c)
515{
516 /* SH3 doesn't support multiple interfaces */
517 if (gadget_is_sh(c->cdev->gadget))
518 return false;
519
520 /* sa1100 doesn't have a third interrupt endpoint */
521 if (gadget_is_sa1100(c->cdev->gadget))
522 return false;
523
524 /* everything else is *probably* fine ... */
525 return true;
526}
527
528/**
529 * acm_bind_config - add a CDC ACM function to a configuration
530 * @c: the configuration to support the CDC ACM instance
531 * @port_num: /dev/ttyGS* port this interface will use
532 * Context: single threaded during gadget setup
533 *
534 * Returns zero on success, else negative errno.
535 *
536 * Caller must have called @gserial_setup() with enough ports to
537 * handle all the ones it binds. Caller is also responsible
538 * for calling @gserial_cleanup() before module unload.
539 */
540int __init acm_bind_config(struct usb_configuration *c, u8 port_num)
541{
542 struct f_acm *acm;
543 int status;
544
545 if (!can_support_cdc(c))
546 return -EINVAL;
547
548 /* REVISIT might want instance-specific strings to help
549 * distinguish instances ...
550 */
551
552 /* maybe allocate device-global string IDs, and patch descriptors */
553 if (acm_string_defs[ACM_CTRL_IDX].id == 0) {
554 status = usb_string_id(c->cdev);
555 if (status < 0)
556 return status;
557 acm_string_defs[ACM_CTRL_IDX].id = status;
558
559 acm_control_interface_desc.iInterface = status;
560
561 status = usb_string_id(c->cdev);
562 if (status < 0)
563 return status;
564 acm_string_defs[ACM_DATA_IDX].id = status;
565
566 acm_data_interface_desc.iInterface = status;
567 }
568
569 /* allocate and initialize one new instance */
570 acm = kzalloc(sizeof *acm, GFP_KERNEL);
571 if (!acm)
572 return -ENOMEM;
573
574 acm->port_num = port_num;
575
576 acm->port.func.name = "acm";
577 acm->port.func.strings = acm_strings;
578 /* descriptors are per-instance copies */
579 acm->port.func.bind = acm_bind;
580 acm->port.func.unbind = acm_unbind;
581 acm->port.func.set_alt = acm_set_alt;
582 acm->port.func.setup = acm_setup;
583 acm->port.func.disable = acm_disable;
584
585 status = usb_add_function(c, &acm->port.func);
586 if (status)
587 kfree(acm);
588 return status;
589}
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
new file mode 100644
index 000000000000..0822e9d7693a
--- /dev/null
+++ b/drivers/usb/gadget/f_ecm.c
@@ -0,0 +1,833 @@
1/*
2 * f_ecm.c -- USB CDC Ethernet (ECM) link function driver
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/* #define VERBOSE_DEBUG */
23
24#include <linux/kernel.h>
25#include <linux/device.h>
26#include <linux/etherdevice.h>
27
28#include "u_ether.h"
29
30
31/*
32 * This function is a "CDC Ethernet Networking Control Model" (CDC ECM)
33 * Ethernet link. The data transfer model is simple (packets sent and
34 * received over bulk endpoints using normal short packet termination),
35 * and the control model exposes various data and optional notifications.
36 *
37 * ECM is well standardized and (except for Microsoft) supported by most
38 * operating systems with USB host support. It's the preferred interop
39 * solution for Ethernet over USB, at least for firmware based solutions.
40 * (Hardware solutions tend to be more minimalist.) A newer and simpler
41 * "Ethernet Emulation Model" (CDC EEM) hasn't yet caught on.
42 *
43 * Note that ECM requires the use of "alternate settings" for its data
44 * interface. This means that the set_alt() method has real work to do,
45 * and also means that a get_alt() method is required.
46 */
47
48struct ecm_ep_descs {
49 struct usb_endpoint_descriptor *in;
50 struct usb_endpoint_descriptor *out;
51 struct usb_endpoint_descriptor *notify;
52};
53
54enum ecm_notify_state {
55 ECM_NOTIFY_NONE, /* don't notify */
56 ECM_NOTIFY_CONNECT, /* issue CONNECT next */
57 ECM_NOTIFY_SPEED, /* issue SPEED_CHANGE next */
58};
59
60struct f_ecm {
61 struct gether port;
62 u8 ctrl_id, data_id;
63
64 char ethaddr[14];
65
66 struct usb_descriptor_header **fs_function;
67 struct ecm_ep_descs fs;
68 struct usb_descriptor_header **hs_function;
69 struct ecm_ep_descs hs;
70
71 struct usb_ep *notify;
72 struct usb_endpoint_descriptor *notify_desc;
73 struct usb_request *notify_req;
74 u8 notify_state;
75 bool is_open;
76
77 /* FIXME is_open needs some irq-ish locking
78 * ... possibly the same as port.ioport
79 */
80};
81
82static inline struct f_ecm *func_to_ecm(struct usb_function *f)
83{
84 return container_of(f, struct f_ecm, port.func);
85}
86
87/* peak (theoretical) bulk transfer rate in bits-per-second */
88static inline unsigned bitrate(struct usb_gadget *g)
89{
90 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
91 return 13 * 512 * 8 * 1000 * 8;
92 else
93 return 19 * 64 * 1 * 1000 * 8;
94}
95
96/*-------------------------------------------------------------------------*/
97
98/*
99 * Include the status endpoint if we can, even though it's optional.
100 *
101 * Use wMaxPacketSize big enough to fit CDC_NOTIFY_SPEED_CHANGE in one
102 * packet, to simplify cancellation; and a big transfer interval, to
103 * waste less bandwidth.
104 *
105 * Some drivers (like Linux 2.4 cdc-ether!) "need" it to exist even
106 * if they ignore the connect/disconnect notifications that real aether
107 * can provide. More advanced cdc configurations might want to support
108 * encapsulated commands (vendor-specific, using control-OUT).
109 */
110
111#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */
112#define STATUS_BYTECOUNT 16 /* 8 byte header + data */
113
114
115/* interface descriptor: */
116
117static struct usb_interface_descriptor ecm_control_intf __initdata = {
118 .bLength = sizeof ecm_control_intf,
119 .bDescriptorType = USB_DT_INTERFACE,
120
121 /* .bInterfaceNumber = DYNAMIC */
122 /* status endpoint is optional; this could be patched later */
123 .bNumEndpoints = 1,
124 .bInterfaceClass = USB_CLASS_COMM,
125 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET,
126 .bInterfaceProtocol = USB_CDC_PROTO_NONE,
127 /* .iInterface = DYNAMIC */
128};
129
130static struct usb_cdc_header_desc header_desc __initdata = {
131 .bLength = sizeof header_desc,
132 .bDescriptorType = USB_DT_CS_INTERFACE,
133 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
134
135 .bcdCDC = __constant_cpu_to_le16(0x0110),
136};
137
138static struct usb_cdc_union_desc ecm_union_desc __initdata = {
139 .bLength = sizeof(ecm_union_desc),
140 .bDescriptorType = USB_DT_CS_INTERFACE,
141 .bDescriptorSubType = USB_CDC_UNION_TYPE,
142 /* .bMasterInterface0 = DYNAMIC */
143 /* .bSlaveInterface0 = DYNAMIC */
144};
145
146static struct usb_cdc_ether_desc ether_desc __initdata = {
147 .bLength = sizeof ether_desc,
148 .bDescriptorType = USB_DT_CS_INTERFACE,
149 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
150
151 /* this descriptor actually adds value, surprise! */
152 /* .iMACAddress = DYNAMIC */
153 .bmEthernetStatistics = __constant_cpu_to_le32(0), /* no statistics */
154 .wMaxSegmentSize = __constant_cpu_to_le16(ETH_FRAME_LEN),
155 .wNumberMCFilters = __constant_cpu_to_le16(0),
156 .bNumberPowerFilters = 0,
157};
158
159/* the default data interface has no endpoints ... */
160
161static struct usb_interface_descriptor ecm_data_nop_intf __initdata = {
162 .bLength = sizeof ecm_data_nop_intf,
163 .bDescriptorType = USB_DT_INTERFACE,
164
165 .bInterfaceNumber = 1,
166 .bAlternateSetting = 0,
167 .bNumEndpoints = 0,
168 .bInterfaceClass = USB_CLASS_CDC_DATA,
169 .bInterfaceSubClass = 0,
170 .bInterfaceProtocol = 0,
171 /* .iInterface = DYNAMIC */
172};
173
174/* ... but the "real" data interface has two bulk endpoints */
175
176static struct usb_interface_descriptor ecm_data_intf __initdata = {
177 .bLength = sizeof ecm_data_intf,
178 .bDescriptorType = USB_DT_INTERFACE,
179
180 .bInterfaceNumber = 1,
181 .bAlternateSetting = 1,
182 .bNumEndpoints = 2,
183 .bInterfaceClass = USB_CLASS_CDC_DATA,
184 .bInterfaceSubClass = 0,
185 .bInterfaceProtocol = 0,
186 /* .iInterface = DYNAMIC */
187};
188
189/* full speed support: */
190
191static struct usb_endpoint_descriptor fs_notify_desc __initdata = {
192 .bLength = USB_DT_ENDPOINT_SIZE,
193 .bDescriptorType = USB_DT_ENDPOINT,
194
195 .bEndpointAddress = USB_DIR_IN,
196 .bmAttributes = USB_ENDPOINT_XFER_INT,
197 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT),
198 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
199};
200
201static struct usb_endpoint_descriptor fs_in_desc __initdata = {
202 .bLength = USB_DT_ENDPOINT_SIZE,
203 .bDescriptorType = USB_DT_ENDPOINT,
204
205 .bEndpointAddress = USB_DIR_IN,
206 .bmAttributes = USB_ENDPOINT_XFER_BULK,
207};
208
209static struct usb_endpoint_descriptor fs_out_desc __initdata = {
210 .bLength = USB_DT_ENDPOINT_SIZE,
211 .bDescriptorType = USB_DT_ENDPOINT,
212
213 .bEndpointAddress = USB_DIR_OUT,
214 .bmAttributes = USB_ENDPOINT_XFER_BULK,
215};
216
217static struct usb_descriptor_header *eth_fs_function[] __initdata = {
218 /* CDC ECM control descriptors */
219 (struct usb_descriptor_header *) &ecm_control_intf,
220 (struct usb_descriptor_header *) &header_desc,
221 (struct usb_descriptor_header *) &ecm_union_desc,
222 (struct usb_descriptor_header *) &ether_desc,
223 /* NOTE: status endpoint might need to be removed */
224 (struct usb_descriptor_header *) &fs_notify_desc,
225 /* data interface, altsettings 0 and 1 */
226 (struct usb_descriptor_header *) &ecm_data_nop_intf,
227 (struct usb_descriptor_header *) &ecm_data_intf,
228 (struct usb_descriptor_header *) &fs_in_desc,
229 (struct usb_descriptor_header *) &fs_out_desc,
230 NULL,
231};
232
233/* high speed support: */
234
235static struct usb_endpoint_descriptor hs_notify_desc __initdata = {
236 .bLength = USB_DT_ENDPOINT_SIZE,
237 .bDescriptorType = USB_DT_ENDPOINT,
238
239 .bEndpointAddress = USB_DIR_IN,
240 .bmAttributes = USB_ENDPOINT_XFER_INT,
241 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT),
242 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
243};
244static struct usb_endpoint_descriptor hs_in_desc __initdata = {
245 .bLength = USB_DT_ENDPOINT_SIZE,
246 .bDescriptorType = USB_DT_ENDPOINT,
247
248 .bEndpointAddress = USB_DIR_IN,
249 .bmAttributes = USB_ENDPOINT_XFER_BULK,
250 .wMaxPacketSize = __constant_cpu_to_le16(512),
251};
252
253static struct usb_endpoint_descriptor hs_out_desc __initdata = {
254 .bLength = USB_DT_ENDPOINT_SIZE,
255 .bDescriptorType = USB_DT_ENDPOINT,
256
257 .bEndpointAddress = USB_DIR_OUT,
258 .bmAttributes = USB_ENDPOINT_XFER_BULK,
259 .wMaxPacketSize = __constant_cpu_to_le16(512),
260};
261
262static struct usb_descriptor_header *eth_hs_function[] __initdata = {
263 /* CDC ECM control descriptors */
264 (struct usb_descriptor_header *) &ecm_control_intf,
265 (struct usb_descriptor_header *) &header_desc,
266 (struct usb_descriptor_header *) &ecm_union_desc,
267 (struct usb_descriptor_header *) &ether_desc,
268 /* NOTE: status endpoint might need to be removed */
269 (struct usb_descriptor_header *) &hs_notify_desc,
270 /* data interface, altsettings 0 and 1 */
271 (struct usb_descriptor_header *) &ecm_data_nop_intf,
272 (struct usb_descriptor_header *) &ecm_data_intf,
273 (struct usb_descriptor_header *) &hs_in_desc,
274 (struct usb_descriptor_header *) &hs_out_desc,
275 NULL,
276};
277
278/* string descriptors: */
279
280static struct usb_string ecm_string_defs[] = {
281 [0].s = "CDC Ethernet Control Model (ECM)",
282 [1].s = NULL /* DYNAMIC */,
283 [2].s = "CDC Ethernet Data",
284 { } /* end of list */
285};
286
287static struct usb_gadget_strings ecm_string_table = {
288 .language = 0x0409, /* en-us */
289 .strings = ecm_string_defs,
290};
291
292static struct usb_gadget_strings *ecm_strings[] = {
293 &ecm_string_table,
294 NULL,
295};
296
297/*-------------------------------------------------------------------------*/
298
299static void ecm_do_notify(struct f_ecm *ecm)
300{
301 struct usb_request *req = ecm->notify_req;
302 struct usb_cdc_notification *event;
303 struct usb_composite_dev *cdev = ecm->port.func.config->cdev;
304 __le32 *data;
305 int status;
306
307 /* notification already in flight? */
308 if (!req)
309 return;
310
311 event = req->buf;
312 switch (ecm->notify_state) {
313 case ECM_NOTIFY_NONE:
314 return;
315
316 case ECM_NOTIFY_CONNECT:
317 event->bNotificationType = USB_CDC_NOTIFY_NETWORK_CONNECTION;
318 if (ecm->is_open)
319 event->wValue = cpu_to_le16(1);
320 else
321 event->wValue = cpu_to_le16(0);
322 event->wLength = 0;
323 req->length = sizeof *event;
324
325 DBG(cdev, "notify connect %s\n",
326 ecm->is_open ? "true" : "false");
327 ecm->notify_state = ECM_NOTIFY_SPEED;
328 break;
329
330 case ECM_NOTIFY_SPEED:
331 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE;
332 event->wValue = cpu_to_le16(0);
333 event->wLength = cpu_to_le16(8);
334 req->length = STATUS_BYTECOUNT;
335
336 /* SPEED_CHANGE data is up/down speeds in bits/sec */
337 data = req->buf + sizeof *event;
338 data[0] = cpu_to_le32(bitrate(cdev->gadget));
339 data[1] = data[0];
340
341 DBG(cdev, "notify speed %d\n", bitrate(cdev->gadget));
342 ecm->notify_state = ECM_NOTIFY_NONE;
343 break;
344 }
345 event->bmRequestType = 0xA1;
346 event->wIndex = cpu_to_le16(ecm->ctrl_id);
347
348 ecm->notify_req = NULL;
349 status = usb_ep_queue(ecm->notify, req, GFP_ATOMIC);
350 if (status < 0) {
351 ecm->notify_req = req;
352 DBG(cdev, "notify --> %d\n", status);
353 }
354}
355
356static void ecm_notify(struct f_ecm *ecm)
357{
358 /* NOTE on most versions of Linux, host side cdc-ethernet
359 * won't listen for notifications until its netdevice opens.
360 * The first notification then sits in the FIFO for a long
361 * time, and the second one is queued.
362 */
363 ecm->notify_state = ECM_NOTIFY_CONNECT;
364 ecm_do_notify(ecm);
365}
366
367static void ecm_notify_complete(struct usb_ep *ep, struct usb_request *req)
368{
369 struct f_ecm *ecm = req->context;
370 struct usb_composite_dev *cdev = ecm->port.func.config->cdev;
371 struct usb_cdc_notification *event = req->buf;
372
373 switch (req->status) {
374 case 0:
375 /* no fault */
376 break;
377 case -ECONNRESET:
378 case -ESHUTDOWN:
379 ecm->notify_state = ECM_NOTIFY_NONE;
380 break;
381 default:
382 DBG(cdev, "event %02x --> %d\n",
383 event->bNotificationType, req->status);
384 break;
385 }
386 ecm->notify_req = req;
387 ecm_do_notify(ecm);
388}
389
390static int ecm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
391{
392 struct f_ecm *ecm = func_to_ecm(f);
393 struct usb_composite_dev *cdev = f->config->cdev;
394 struct usb_request *req = cdev->req;
395 int value = -EOPNOTSUPP;
396 u16 w_index = le16_to_cpu(ctrl->wIndex);
397 u16 w_value = le16_to_cpu(ctrl->wValue);
398 u16 w_length = le16_to_cpu(ctrl->wLength);
399
400 /* composite driver infrastructure handles everything except
401 * CDC class messages; interface activation uses set_alt().
402 */
403 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
404 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
405 | USB_CDC_SET_ETHERNET_PACKET_FILTER:
406 /* see 6.2.30: no data, wIndex = interface,
407 * wValue = packet filter bitmap
408 */
409 if (w_length != 0 || w_index != ecm->ctrl_id)
410 goto invalid;
411 DBG(cdev, "packet filter %02x\n", w_value);
412 /* REVISIT locking of cdc_filter. This assumes the UDC
413 * driver won't have a concurrent packet TX irq running on
414 * another CPU; or that if it does, this write is atomic...
415 */
416 ecm->port.cdc_filter = w_value;
417 value = 0;
418 break;
419
420 /* and optionally:
421 * case USB_CDC_SEND_ENCAPSULATED_COMMAND:
422 * case USB_CDC_GET_ENCAPSULATED_RESPONSE:
423 * case USB_CDC_SET_ETHERNET_MULTICAST_FILTERS:
424 * case USB_CDC_SET_ETHERNET_PM_PATTERN_FILTER:
425 * case USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER:
426 * case USB_CDC_GET_ETHERNET_STATISTIC:
427 */
428
429 default:
430invalid:
431 DBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
432 ctrl->bRequestType, ctrl->bRequest,
433 w_value, w_index, w_length);
434 }
435
436 /* respond with data transfer or status phase? */
437 if (value >= 0) {
438 DBG(cdev, "ecm req%02x.%02x v%04x i%04x l%d\n",
439 ctrl->bRequestType, ctrl->bRequest,
440 w_value, w_index, w_length);
441 req->zero = 0;
442 req->length = value;
443 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
444 if (value < 0)
445 ERROR(cdev, "ecm req %02x.%02x response err %d\n",
446 ctrl->bRequestType, ctrl->bRequest,
447 value);
448 }
449
450 /* device either stalls (value < 0) or reports success */
451 return value;
452}
453
454
455static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
456{
457 struct f_ecm *ecm = func_to_ecm(f);
458 struct usb_composite_dev *cdev = f->config->cdev;
459
460 /* Control interface has only altsetting 0 */
461 if (intf == ecm->ctrl_id) {
462 if (alt != 0)
463 goto fail;
464
465 if (ecm->notify->driver_data) {
466 VDBG(cdev, "reset ecm control %d\n", intf);
467 usb_ep_disable(ecm->notify);
468 } else {
469 VDBG(cdev, "init ecm ctrl %d\n", intf);
470 ecm->notify_desc = ep_choose(cdev->gadget,
471 ecm->hs.notify,
472 ecm->fs.notify);
473 }
474 usb_ep_enable(ecm->notify, ecm->notify_desc);
475 ecm->notify->driver_data = ecm;
476
477 /* Data interface has two altsettings, 0 and 1 */
478 } else if (intf == ecm->data_id) {
479 if (alt > 1)
480 goto fail;
481
482 if (ecm->port.in_ep->driver_data) {
483 DBG(cdev, "reset ecm\n");
484 gether_disconnect(&ecm->port);
485 }
486
487 if (!ecm->port.in) {
488 DBG(cdev, "init ecm\n");
489 ecm->port.in = ep_choose(cdev->gadget,
490 ecm->hs.in, ecm->fs.in);
491 ecm->port.out = ep_choose(cdev->gadget,
492 ecm->hs.out, ecm->fs.out);
493 }
494
495 /* CDC Ethernet only sends data in non-default altsettings.
496 * Changing altsettings resets filters, statistics, etc.
497 */
498 if (alt == 1) {
499 struct net_device *net;
500
501 /* Enable zlps by default for ECM conformance;
502 * override for musb_hdrc (avoids txdma ovhead)
503 * and sa1100 (can't).
504 */
505 ecm->port.is_zlp_ok = !(
506 gadget_is_sa1100(cdev->gadget)
507 || gadget_is_musbhdrc(cdev->gadget)
508 );
509 ecm->port.cdc_filter = DEFAULT_FILTER;
510 DBG(cdev, "activate ecm\n");
511 net = gether_connect(&ecm->port);
512 if (IS_ERR(net))
513 return PTR_ERR(net);
514 }
515
516 /* NOTE this can be a minor disagreement with the ECM spec,
517 * which says speed notifications will "always" follow
518 * connection notifications. But we allow one connect to
519 * follow another (if the first is in flight), and instead
520 * just guarantee that a speed notification is always sent.
521 */
522 ecm_notify(ecm);
523 } else
524 goto fail;
525
526 return 0;
527fail:
528 return -EINVAL;
529}
530
531/* Because the data interface supports multiple altsettings,
532 * this ECM function *MUST* implement a get_alt() method.
533 */
534static int ecm_get_alt(struct usb_function *f, unsigned intf)
535{
536 struct f_ecm *ecm = func_to_ecm(f);
537
538 if (intf == ecm->ctrl_id)
539 return 0;
540 return ecm->port.in_ep->driver_data ? 1 : 0;
541}
542
543static void ecm_disable(struct usb_function *f)
544{
545 struct f_ecm *ecm = func_to_ecm(f);
546 struct usb_composite_dev *cdev = f->config->cdev;
547
548 DBG(cdev, "ecm deactivated\n");
549
550 if (ecm->port.in_ep->driver_data)
551 gether_disconnect(&ecm->port);
552
553 if (ecm->notify->driver_data) {
554 usb_ep_disable(ecm->notify);
555 ecm->notify->driver_data = NULL;
556 ecm->notify_desc = NULL;
557 }
558}
559
560/*-------------------------------------------------------------------------*/
561
562/*
563 * Callbacks let us notify the host about connect/disconnect when the
564 * net device is opened or closed.
565 *
566 * For testing, note that link states on this side include both opened
567 * and closed variants of:
568 *
569 * - disconnected/unconfigured
570 * - configured but inactive (data alt 0)
571 * - configured and active (data alt 1)
572 *
573 * Each needs to be tested with unplug, rmmod, SET_CONFIGURATION, and
574 * SET_INTERFACE (altsetting). Remember also that "configured" doesn't
575 * imply the host is actually polling the notification endpoint, and
576 * likewise that "active" doesn't imply it's actually using the data
577 * endpoints for traffic.
578 */
579
580static void ecm_open(struct gether *geth)
581{
582 struct f_ecm *ecm = func_to_ecm(&geth->func);
583
584 DBG(ecm->port.func.config->cdev, "%s\n", __func__);
585
586 ecm->is_open = true;
587 ecm_notify(ecm);
588}
589
590static void ecm_close(struct gether *geth)
591{
592 struct f_ecm *ecm = func_to_ecm(&geth->func);
593
594 DBG(ecm->port.func.config->cdev, "%s\n", __func__);
595
596 ecm->is_open = false;
597 ecm_notify(ecm);
598}
599
600/*-------------------------------------------------------------------------*/
601
602/* ethernet function driver setup/binding */
603
604static int __init
605ecm_bind(struct usb_configuration *c, struct usb_function *f)
606{
607 struct usb_composite_dev *cdev = c->cdev;
608 struct f_ecm *ecm = func_to_ecm(f);
609 int status;
610 struct usb_ep *ep;
611
612 /* allocate instance-specific interface IDs */
613 status = usb_interface_id(c, f);
614 if (status < 0)
615 goto fail;
616 ecm->ctrl_id = status;
617
618 ecm_control_intf.bInterfaceNumber = status;
619 ecm_union_desc.bMasterInterface0 = status;
620
621 status = usb_interface_id(c, f);
622 if (status < 0)
623 goto fail;
624 ecm->data_id = status;
625
626 ecm_data_nop_intf.bInterfaceNumber = status;
627 ecm_data_intf.bInterfaceNumber = status;
628 ecm_union_desc.bSlaveInterface0 = status;
629
630 status = -ENODEV;
631
632 /* allocate instance-specific endpoints */
633 ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc);
634 if (!ep)
635 goto fail;
636 ecm->port.in_ep = ep;
637 ep->driver_data = cdev; /* claim */
638
639 ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc);
640 if (!ep)
641 goto fail;
642 ecm->port.out_ep = ep;
643 ep->driver_data = cdev; /* claim */
644
645 /* NOTE: a status/notification endpoint is *OPTIONAL* but we
646 * don't treat it that way. It's simpler, and some newer CDC
647 * profiles (wireless handsets) no longer treat it as optional.
648 */
649 ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc);
650 if (!ep)
651 goto fail;
652 ecm->notify = ep;
653 ep->driver_data = cdev; /* claim */
654
655 status = -ENOMEM;
656
657 /* allocate notification request and buffer */
658 ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
659 if (!ecm->notify_req)
660 goto fail;
661 ecm->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL);
662 if (!ecm->notify_req->buf)
663 goto fail;
664 ecm->notify_req->context = ecm;
665 ecm->notify_req->complete = ecm_notify_complete;
666
667 /* copy descriptors, and track endpoint copies */
668 f->descriptors = usb_copy_descriptors(eth_fs_function);
669 if (!f->descriptors)
670 goto fail;
671
672 ecm->fs.in = usb_find_endpoint(eth_fs_function,
673 f->descriptors, &fs_in_desc);
674 ecm->fs.out = usb_find_endpoint(eth_fs_function,
675 f->descriptors, &fs_out_desc);
676 ecm->fs.notify = usb_find_endpoint(eth_fs_function,
677 f->descriptors, &fs_notify_desc);
678
679 /* support all relevant hardware speeds... we expect that when
680 * hardware is dual speed, all bulk-capable endpoints work at
681 * both speeds
682 */
683 if (gadget_is_dualspeed(c->cdev->gadget)) {
684 hs_in_desc.bEndpointAddress =
685 fs_in_desc.bEndpointAddress;
686 hs_out_desc.bEndpointAddress =
687 fs_out_desc.bEndpointAddress;
688 hs_notify_desc.bEndpointAddress =
689 fs_notify_desc.bEndpointAddress;
690
691 /* copy descriptors, and track endpoint copies */
692 f->hs_descriptors = usb_copy_descriptors(eth_hs_function);
693 if (!f->hs_descriptors)
694 goto fail;
695
696 ecm->hs.in = usb_find_endpoint(eth_hs_function,
697 f->hs_descriptors, &hs_in_desc);
698 ecm->hs.out = usb_find_endpoint(eth_hs_function,
699 f->hs_descriptors, &hs_out_desc);
700 ecm->hs.notify = usb_find_endpoint(eth_hs_function,
701 f->hs_descriptors, &hs_notify_desc);
702 }
703
704 /* NOTE: all that is done without knowing or caring about
705 * the network link ... which is unavailable to this code
706 * until we're activated via set_alt().
707 */
708
709 ecm->port.open = ecm_open;
710 ecm->port.close = ecm_close;
711
712 DBG(cdev, "CDC Ethernet: %s speed IN/%s OUT/%s NOTIFY/%s\n",
713 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
714 ecm->port.in_ep->name, ecm->port.out_ep->name,
715 ecm->notify->name);
716 return 0;
717
718fail:
719 if (f->descriptors)
720 usb_free_descriptors(f->descriptors);
721
722 if (ecm->notify_req) {
723 kfree(ecm->notify_req->buf);
724 usb_ep_free_request(ecm->notify, ecm->notify_req);
725 }
726
727 /* we might as well release our claims on endpoints */
728 if (ecm->notify)
729 ecm->notify->driver_data = NULL;
730 if (ecm->port.out)
731 ecm->port.out_ep->driver_data = NULL;
732 if (ecm->port.in)
733 ecm->port.in_ep->driver_data = NULL;
734
735 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
736
737 return status;
738}
739
740static void
741ecm_unbind(struct usb_configuration *c, struct usb_function *f)
742{
743 struct f_ecm *ecm = func_to_ecm(f);
744
745 DBG(c->cdev, "ecm unbind\n");
746
747 if (gadget_is_dualspeed(c->cdev->gadget))
748 usb_free_descriptors(f->hs_descriptors);
749 usb_free_descriptors(f->descriptors);
750
751 kfree(ecm->notify_req->buf);
752 usb_ep_free_request(ecm->notify, ecm->notify_req);
753
754 ecm_string_defs[1].s = NULL;
755 kfree(ecm);
756}
757
758/**
759 * ecm_bind_config - add CDC Ethernet network link to a configuration
760 * @c: the configuration to support the network link
761 * @ethaddr: a buffer in which the ethernet address of the host side
762 * side of the link was recorded
763 * Context: single threaded during gadget setup
764 *
765 * Returns zero on success, else negative errno.
766 *
767 * Caller must have called @gether_setup(). Caller is also responsible
768 * for calling @gether_cleanup() before module unload.
769 */
770int __init ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
771{
772 struct f_ecm *ecm;
773 int status;
774
775 if (!can_support_ecm(c->cdev->gadget) || !ethaddr)
776 return -EINVAL;
777
778 /* maybe allocate device-global string IDs */
779 if (ecm_string_defs[0].id == 0) {
780
781 /* control interface label */
782 status = usb_string_id(c->cdev);
783 if (status < 0)
784 return status;
785 ecm_string_defs[0].id = status;
786 ecm_control_intf.iInterface = status;
787
788 /* data interface label */
789 status = usb_string_id(c->cdev);
790 if (status < 0)
791 return status;
792 ecm_string_defs[2].id = status;
793 ecm_data_intf.iInterface = status;
794
795 /* MAC address */
796 status = usb_string_id(c->cdev);
797 if (status < 0)
798 return status;
799 ecm_string_defs[1].id = status;
800 ether_desc.iMACAddress = status;
801 }
802
803 /* allocate and initialize one new instance */
804 ecm = kzalloc(sizeof *ecm, GFP_KERNEL);
805 if (!ecm)
806 return -ENOMEM;
807
808 /* export host's Ethernet address in CDC format */
809 snprintf(ecm->ethaddr, sizeof ecm->ethaddr,
810 "%02X%02X%02X%02X%02X%02X",
811 ethaddr[0], ethaddr[1], ethaddr[2],
812 ethaddr[3], ethaddr[4], ethaddr[5]);
813 ecm_string_defs[1].s = ecm->ethaddr;
814
815 ecm->port.cdc_filter = DEFAULT_FILTER;
816
817 ecm->port.func.name = "cdc_ethernet";
818 ecm->port.func.strings = ecm_strings;
819 /* descriptors are per-instance copies */
820 ecm->port.func.bind = ecm_bind;
821 ecm->port.func.unbind = ecm_unbind;
822 ecm->port.func.set_alt = ecm_set_alt;
823 ecm->port.func.get_alt = ecm_get_alt;
824 ecm->port.func.setup = ecm_setup;
825 ecm->port.func.disable = ecm_disable;
826
827 status = usb_add_function(c, &ecm->port.func);
828 if (status) {
829 ecm_string_defs[1].s = NULL;
830 kfree(ecm);
831 }
832 return status;
833}
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
new file mode 100644
index 000000000000..eda4cde72c82
--- /dev/null
+++ b/drivers/usb/gadget/f_loopback.c
@@ -0,0 +1,381 @@
1/*
2 * f_loopback.c - USB peripheral loopback configuration driver
3 *
4 * Copyright (C) 2003-2008 David Brownell
5 * Copyright (C) 2008 by Nokia Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/* #define VERBOSE_DEBUG */
23
24#include <linux/kernel.h>
25#include <linux/utsname.h>
26#include <linux/device.h>
27
28#include "g_zero.h"
29#include "gadget_chips.h"
30
31
32/*
33 * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals,
34 *
35 * This takes messages of various sizes written OUT to a device, and loops
36 * them back so they can be read IN from it. It has been used by certain
37 * test applications. It supports limited testing of data queueing logic.
38 *
39 *
40 * This is currently packaged as a configuration driver, which can't be
41 * combined with other functions to make composite devices. However, it
42 * can be combined with other independent configurations.
43 */
44struct f_loopback {
45 struct usb_function function;
46
47 struct usb_ep *in_ep;
48 struct usb_ep *out_ep;
49};
50
51static inline struct f_loopback *func_to_loop(struct usb_function *f)
52{
53 return container_of(f, struct f_loopback, function);
54}
55
56static unsigned qlen = 32;
57module_param(qlen, uint, 0);
58MODULE_PARM_DESC(qlenn, "depth of loopback queue");
59
60/*-------------------------------------------------------------------------*/
61
62static struct usb_interface_descriptor loopback_intf = {
63 .bLength = sizeof loopback_intf,
64 .bDescriptorType = USB_DT_INTERFACE,
65
66 .bNumEndpoints = 2,
67 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
68 /* .iInterface = DYNAMIC */
69};
70
71/* full speed support: */
72
73static struct usb_endpoint_descriptor fs_source_desc = {
74 .bLength = USB_DT_ENDPOINT_SIZE,
75 .bDescriptorType = USB_DT_ENDPOINT,
76
77 .bEndpointAddress = USB_DIR_IN,
78 .bmAttributes = USB_ENDPOINT_XFER_BULK,
79};
80
81static struct usb_endpoint_descriptor fs_sink_desc = {
82 .bLength = USB_DT_ENDPOINT_SIZE,
83 .bDescriptorType = USB_DT_ENDPOINT,
84
85 .bEndpointAddress = USB_DIR_OUT,
86 .bmAttributes = USB_ENDPOINT_XFER_BULK,
87};
88
89static struct usb_descriptor_header *fs_loopback_descs[] = {
90 (struct usb_descriptor_header *) &loopback_intf,
91 (struct usb_descriptor_header *) &fs_sink_desc,
92 (struct usb_descriptor_header *) &fs_source_desc,
93 NULL,
94};
95
96/* high speed support: */
97
98static struct usb_endpoint_descriptor hs_source_desc = {
99 .bLength = USB_DT_ENDPOINT_SIZE,
100 .bDescriptorType = USB_DT_ENDPOINT,
101
102 .bmAttributes = USB_ENDPOINT_XFER_BULK,
103 .wMaxPacketSize = __constant_cpu_to_le16(512),
104};
105
106static struct usb_endpoint_descriptor hs_sink_desc = {
107 .bLength = USB_DT_ENDPOINT_SIZE,
108 .bDescriptorType = USB_DT_ENDPOINT,
109
110 .bmAttributes = USB_ENDPOINT_XFER_BULK,
111 .wMaxPacketSize = __constant_cpu_to_le16(512),
112};
113
114static struct usb_descriptor_header *hs_loopback_descs[] = {
115 (struct usb_descriptor_header *) &loopback_intf,
116 (struct usb_descriptor_header *) &hs_source_desc,
117 (struct usb_descriptor_header *) &hs_sink_desc,
118 NULL,
119};
120
121/* function-specific strings: */
122
123static struct usb_string strings_loopback[] = {
124 [0].s = "loop input to output",
125 { } /* end of list */
126};
127
128static struct usb_gadget_strings stringtab_loop = {
129 .language = 0x0409, /* en-us */
130 .strings = strings_loopback,
131};
132
133static struct usb_gadget_strings *loopback_strings[] = {
134 &stringtab_loop,
135 NULL,
136};
137
138/*-------------------------------------------------------------------------*/
139
140static int __init
141loopback_bind(struct usb_configuration *c, struct usb_function *f)
142{
143 struct usb_composite_dev *cdev = c->cdev;
144 struct f_loopback *loop = func_to_loop(f);
145 int id;
146
147 /* allocate interface ID(s) */
148 id = usb_interface_id(c, f);
149 if (id < 0)
150 return id;
151 loopback_intf.bInterfaceNumber = id;
152
153 /* allocate endpoints */
154
155 loop->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc);
156 if (!loop->in_ep) {
157autoconf_fail:
158 ERROR(cdev, "%s: can't autoconfigure on %s\n",
159 f->name, cdev->gadget->name);
160 return -ENODEV;
161 }
162 loop->in_ep->driver_data = cdev; /* claim */
163
164 loop->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_sink_desc);
165 if (!loop->out_ep)
166 goto autoconf_fail;
167 loop->out_ep->driver_data = cdev; /* claim */
168
169 /* support high speed hardware */
170 if (gadget_is_dualspeed(c->cdev->gadget)) {
171 hs_source_desc.bEndpointAddress =
172 fs_source_desc.bEndpointAddress;
173 hs_sink_desc.bEndpointAddress =
174 fs_sink_desc.bEndpointAddress;
175 f->hs_descriptors = hs_loopback_descs;
176 }
177
178 DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n",
179 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
180 f->name, loop->in_ep->name, loop->out_ep->name);
181 return 0;
182}
183
184static void
185loopback_unbind(struct usb_configuration *c, struct usb_function *f)
186{
187 kfree(func_to_loop(f));
188}
189
190static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
191{
192 struct f_loopback *loop = ep->driver_data;
193 struct usb_composite_dev *cdev = loop->function.config->cdev;
194 int status = req->status;
195
196 switch (status) {
197
198 case 0: /* normal completion? */
199 if (ep == loop->out_ep) {
200 /* loop this OUT packet back IN to the host */
201 req->zero = (req->actual < req->length);
202 req->length = req->actual;
203 status = usb_ep_queue(loop->in_ep, req, GFP_ATOMIC);
204 if (status == 0)
205 return;
206
207 /* "should never get here" */
208 ERROR(cdev, "can't loop %s to %s: %d\n",
209 ep->name, loop->in_ep->name,
210 status);
211 }
212
213 /* queue the buffer for some later OUT packet */
214 req->length = buflen;
215 status = usb_ep_queue(loop->out_ep, req, GFP_ATOMIC);
216 if (status == 0)
217 return;
218
219 /* "should never get here" */
220 /* FALLTHROUGH */
221
222 default:
223 ERROR(cdev, "%s loop complete --> %d, %d/%d\n", ep->name,
224 status, req->actual, req->length);
225 /* FALLTHROUGH */
226
227 /* NOTE: since this driver doesn't maintain an explicit record
228 * of requests it submitted (just maintains qlen count), we
229 * rely on the hardware driver to clean up on disconnect or
230 * endpoint disable.
231 */
232 case -ECONNABORTED: /* hardware forced ep reset */
233 case -ECONNRESET: /* request dequeued */
234 case -ESHUTDOWN: /* disconnect from host */
235 free_ep_req(ep, req);
236 return;
237 }
238}
239
240static void disable_loopback(struct f_loopback *loop)
241{
242 struct usb_composite_dev *cdev;
243
244 cdev = loop->function.config->cdev;
245 disable_endpoints(cdev, loop->in_ep, loop->out_ep);
246 VDBG(cdev, "%s disabled\n", loop->function.name);
247}
248
249static int
250enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop)
251{
252 int result = 0;
253 const struct usb_endpoint_descriptor *src, *sink;
254 struct usb_ep *ep;
255 struct usb_request *req;
256 unsigned i;
257
258 src = ep_choose(cdev->gadget, &hs_source_desc, &fs_source_desc);
259 sink = ep_choose(cdev->gadget, &hs_sink_desc, &fs_sink_desc);
260
261 /* one endpoint writes data back IN to the host */
262 ep = loop->in_ep;
263 result = usb_ep_enable(ep, src);
264 if (result < 0)
265 return result;
266 ep->driver_data = loop;
267
268 /* one endpoint just reads OUT packets */
269 ep = loop->out_ep;
270 result = usb_ep_enable(ep, sink);
271 if (result < 0) {
272fail0:
273 ep = loop->in_ep;
274 usb_ep_disable(ep);
275 ep->driver_data = NULL;
276 return result;
277 }
278 ep->driver_data = loop;
279
280 /* allocate a bunch of read buffers and queue them all at once.
281 * we buffer at most 'qlen' transfers; fewer if any need more
282 * than 'buflen' bytes each.
283 */
284 for (i = 0; i < qlen && result == 0; i++) {
285 req = alloc_ep_req(ep);
286 if (req) {
287 req->complete = loopback_complete;
288 result = usb_ep_queue(ep, req, GFP_ATOMIC);
289 if (result)
290 ERROR(cdev, "%s queue req --> %d\n",
291 ep->name, result);
292 } else {
293 usb_ep_disable(ep);
294 ep->driver_data = NULL;
295 result = -ENOMEM;
296 goto fail0;
297 }
298 }
299
300 DBG(cdev, "%s enabled\n", loop->function.name);
301 return result;
302}
303
304static int loopback_set_alt(struct usb_function *f,
305 unsigned intf, unsigned alt)
306{
307 struct f_loopback *loop = func_to_loop(f);
308 struct usb_composite_dev *cdev = f->config->cdev;
309
310 /* we know alt is zero */
311 if (loop->in_ep->driver_data)
312 disable_loopback(loop);
313 return enable_loopback(cdev, loop);
314}
315
316static void loopback_disable(struct usb_function *f)
317{
318 struct f_loopback *loop = func_to_loop(f);
319
320 disable_loopback(loop);
321}
322
323/*-------------------------------------------------------------------------*/
324
325static int __init loopback_bind_config(struct usb_configuration *c)
326{
327 struct f_loopback *loop;
328 int status;
329
330 loop = kzalloc(sizeof *loop, GFP_KERNEL);
331 if (!loop)
332 return -ENOMEM;
333
334 loop->function.name = "loopback";
335 loop->function.descriptors = fs_loopback_descs;
336 loop->function.bind = loopback_bind;
337 loop->function.unbind = loopback_unbind;
338 loop->function.set_alt = loopback_set_alt;
339 loop->function.disable = loopback_disable;
340
341 status = usb_add_function(c, &loop->function);
342 if (status)
343 kfree(loop);
344 return status;
345}
346
347static struct usb_configuration loopback_driver = {
348 .label = "loopback",
349 .strings = loopback_strings,
350 .bind = loopback_bind_config,
351 .bConfigurationValue = 2,
352 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
353 .bMaxPower = 1, /* 2 mA, minimal */
354 /* .iConfiguration = DYNAMIC */
355};
356
357/**
358 * loopback_add - add a loopback testing configuration to a device
359 * @cdev: the device to support the loopback configuration
360 */
361int __init loopback_add(struct usb_composite_dev *cdev)
362{
363 int id;
364
365 /* allocate string ID(s) */
366 id = usb_string_id(cdev);
367 if (id < 0)
368 return id;
369 strings_loopback[0].id = id;
370
371 loopback_intf.iInterface = id;
372 loopback_driver.iConfiguration = id;
373
374 /* support OTG systems */
375 if (gadget_is_otg(cdev->gadget)) {
376 loopback_driver.descriptors = otg_desc;
377 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
378 }
379
380 return usb_add_config(cdev, &loopback_driver);
381}
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
new file mode 100644
index 000000000000..61652f0f13fd
--- /dev/null
+++ b/drivers/usb/gadget/f_rndis.c
@@ -0,0 +1,827 @@
1/*
2 * f_rndis.c -- RNDIS link function driver
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23/* #define VERBOSE_DEBUG */
24
25#include <linux/kernel.h>
26#include <linux/device.h>
27#include <linux/etherdevice.h>
28
29#include <asm/atomic.h>
30
31#include "u_ether.h"
32#include "rndis.h"
33
34
35/*
36 * This function is an RNDIS Ethernet port -- a Microsoft protocol that's
37 * been promoted instead of the standard CDC Ethernet. The published RNDIS
38 * spec is ambiguous, incomplete, and needlessly complex. Variants such as
39 * ActiveSync have even worse status in terms of specification.
40 *
41 * In short: it's a protocol controlled by (and for) Microsoft, not for an
42 * Open ecosystem or markets. Linux supports it *only* because Microsoft
43 * doesn't support the CDC Ethernet standard.
44 *
45 * The RNDIS data transfer model is complex, with multiple Ethernet packets
46 * per USB message, and out of band data. The control model is built around
47 * what's essentially an "RNDIS RPC" protocol. It's all wrapped in a CDC ACM
48 * (modem, not Ethernet) veneer, with those ACM descriptors being entirely
49 * useless (they're ignored). RNDIS expects to be the only function in its
50 * configuration, so it's no real help if you need composite devices; and
51 * it expects to be the first configuration too.
52 *
53 * There is a single technical advantage of RNDIS over CDC Ethernet, if you
54 * discount the fluff that its RPC can be made to deliver: it doesn't need
55 * a NOP altsetting for the data interface. That lets it work on some of the
56 * "so smart it's stupid" hardware which takes over configuration changes
57 * from the software, and adds restrictions like "no altsettings".
58 *
59 * Unfortunately MSFT's RNDIS drivers are buggy. They hang or oops, and
60 * have all sorts of contrary-to-specification oddities that can prevent
61 * them from working sanely. Since bugfixes (or accurate specs, letting
62 * Linux work around those bugs) are unlikely to ever come from MSFT, you
63 * may want to avoid using RNDIS on purely operational grounds.
64 *
65 * Omissions from the RNDIS 1.0 specification include:
66 *
67 * - Power management ... references data that's scattered around lots
68 * of other documentation, which is incorrect/incomplete there too.
69 *
70 * - There are various undocumented protocol requirements, like the need
71 * to send garbage in some control-OUT messages.
72 *
73 * - MS-Windows drivers sometimes emit undocumented requests.
74 */
75
76struct rndis_ep_descs {
77 struct usb_endpoint_descriptor *in;
78 struct usb_endpoint_descriptor *out;
79 struct usb_endpoint_descriptor *notify;
80};
81
82struct f_rndis {
83 struct gether port;
84 u8 ctrl_id, data_id;
85 u8 ethaddr[ETH_ALEN];
86 int config;
87
88 struct usb_descriptor_header **fs_function;
89 struct rndis_ep_descs fs;
90 struct usb_descriptor_header **hs_function;
91 struct rndis_ep_descs hs;
92
93 struct usb_ep *notify;
94 struct usb_endpoint_descriptor *notify_desc;
95 struct usb_request *notify_req;
96 atomic_t notify_count;
97};
98
99static inline struct f_rndis *func_to_rndis(struct usb_function *f)
100{
101 return container_of(f, struct f_rndis, port.func);
102}
103
104/* peak (theoretical) bulk transfer rate in bits-per-second */
105static unsigned int bitrate(struct usb_gadget *g)
106{
107 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
108 return 13 * 512 * 8 * 1000 * 8;
109 else
110 return 19 * 64 * 1 * 1000 * 8;
111}
112
113/*-------------------------------------------------------------------------*/
114
115/*
116 */
117
118#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */
119#define STATUS_BYTECOUNT 8 /* 8 bytes data */
120
121
122/* interface descriptor: */
123
124static struct usb_interface_descriptor rndis_control_intf __initdata = {
125 .bLength = sizeof rndis_control_intf,
126 .bDescriptorType = USB_DT_INTERFACE,
127
128 /* .bInterfaceNumber = DYNAMIC */
129 /* status endpoint is optional; this could be patched later */
130 .bNumEndpoints = 1,
131 .bInterfaceClass = USB_CLASS_COMM,
132 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
133 .bInterfaceProtocol = USB_CDC_ACM_PROTO_VENDOR,
134 /* .iInterface = DYNAMIC */
135};
136
137static struct usb_cdc_header_desc header_desc __initdata = {
138 .bLength = sizeof header_desc,
139 .bDescriptorType = USB_DT_CS_INTERFACE,
140 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
141
142 .bcdCDC = __constant_cpu_to_le16(0x0110),
143};
144
145static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor __initdata = {
146 .bLength = sizeof call_mgmt_descriptor,
147 .bDescriptorType = USB_DT_CS_INTERFACE,
148 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
149
150 .bmCapabilities = 0x00,
151 .bDataInterface = 0x01,
152};
153
154static struct usb_cdc_acm_descriptor acm_descriptor __initdata = {
155 .bLength = sizeof acm_descriptor,
156 .bDescriptorType = USB_DT_CS_INTERFACE,
157 .bDescriptorSubType = USB_CDC_ACM_TYPE,
158
159 .bmCapabilities = 0x00,
160};
161
162static struct usb_cdc_union_desc rndis_union_desc __initdata = {
163 .bLength = sizeof(rndis_union_desc),
164 .bDescriptorType = USB_DT_CS_INTERFACE,
165 .bDescriptorSubType = USB_CDC_UNION_TYPE,
166 /* .bMasterInterface0 = DYNAMIC */
167 /* .bSlaveInterface0 = DYNAMIC */
168};
169
170/* the data interface has two bulk endpoints */
171
172static struct usb_interface_descriptor rndis_data_intf __initdata = {
173 .bLength = sizeof rndis_data_intf,
174 .bDescriptorType = USB_DT_INTERFACE,
175
176 /* .bInterfaceNumber = DYNAMIC */
177 .bAlternateSetting = 1,
178 .bNumEndpoints = 2,
179 .bInterfaceClass = USB_CLASS_CDC_DATA,
180 .bInterfaceSubClass = 0,
181 .bInterfaceProtocol = 0,
182 /* .iInterface = DYNAMIC */
183};
184
185/* full speed support: */
186
187static struct usb_endpoint_descriptor fs_notify_desc __initdata = {
188 .bLength = USB_DT_ENDPOINT_SIZE,
189 .bDescriptorType = USB_DT_ENDPOINT,
190
191 .bEndpointAddress = USB_DIR_IN,
192 .bmAttributes = USB_ENDPOINT_XFER_INT,
193 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT),
194 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
195};
196
197static struct usb_endpoint_descriptor fs_in_desc __initdata = {
198 .bLength = USB_DT_ENDPOINT_SIZE,
199 .bDescriptorType = USB_DT_ENDPOINT,
200
201 .bEndpointAddress = USB_DIR_IN,
202 .bmAttributes = USB_ENDPOINT_XFER_BULK,
203};
204
205static struct usb_endpoint_descriptor fs_out_desc __initdata = {
206 .bLength = USB_DT_ENDPOINT_SIZE,
207 .bDescriptorType = USB_DT_ENDPOINT,
208
209 .bEndpointAddress = USB_DIR_OUT,
210 .bmAttributes = USB_ENDPOINT_XFER_BULK,
211};
212
213static struct usb_descriptor_header *eth_fs_function[] __initdata = {
214 /* control interface matches ACM, not Ethernet */
215 (struct usb_descriptor_header *) &rndis_control_intf,
216 (struct usb_descriptor_header *) &header_desc,
217 (struct usb_descriptor_header *) &call_mgmt_descriptor,
218 (struct usb_descriptor_header *) &acm_descriptor,
219 (struct usb_descriptor_header *) &rndis_union_desc,
220 (struct usb_descriptor_header *) &fs_notify_desc,
221 /* data interface has no altsetting */
222 (struct usb_descriptor_header *) &rndis_data_intf,
223 (struct usb_descriptor_header *) &fs_in_desc,
224 (struct usb_descriptor_header *) &fs_out_desc,
225 NULL,
226};
227
228/* high speed support: */
229
230static struct usb_endpoint_descriptor hs_notify_desc __initdata = {
231 .bLength = USB_DT_ENDPOINT_SIZE,
232 .bDescriptorType = USB_DT_ENDPOINT,
233
234 .bEndpointAddress = USB_DIR_IN,
235 .bmAttributes = USB_ENDPOINT_XFER_INT,
236 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT),
237 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
238};
239static struct usb_endpoint_descriptor hs_in_desc __initdata = {
240 .bLength = USB_DT_ENDPOINT_SIZE,
241 .bDescriptorType = USB_DT_ENDPOINT,
242
243 .bEndpointAddress = USB_DIR_IN,
244 .bmAttributes = USB_ENDPOINT_XFER_BULK,
245 .wMaxPacketSize = __constant_cpu_to_le16(512),
246};
247
248static struct usb_endpoint_descriptor hs_out_desc __initdata = {
249 .bLength = USB_DT_ENDPOINT_SIZE,
250 .bDescriptorType = USB_DT_ENDPOINT,
251
252 .bEndpointAddress = USB_DIR_OUT,
253 .bmAttributes = USB_ENDPOINT_XFER_BULK,
254 .wMaxPacketSize = __constant_cpu_to_le16(512),
255};
256
257static struct usb_descriptor_header *eth_hs_function[] __initdata = {
258 /* control interface matches ACM, not Ethernet */
259 (struct usb_descriptor_header *) &rndis_control_intf,
260 (struct usb_descriptor_header *) &header_desc,
261 (struct usb_descriptor_header *) &call_mgmt_descriptor,
262 (struct usb_descriptor_header *) &acm_descriptor,
263 (struct usb_descriptor_header *) &rndis_union_desc,
264 (struct usb_descriptor_header *) &hs_notify_desc,
265 /* data interface has no altsetting */
266 (struct usb_descriptor_header *) &rndis_data_intf,
267 (struct usb_descriptor_header *) &hs_in_desc,
268 (struct usb_descriptor_header *) &hs_out_desc,
269 NULL,
270};
271
272/* string descriptors: */
273
274static struct usb_string rndis_string_defs[] = {
275 [0].s = "RNDIS Communications Control",
276 [1].s = "RNDIS Ethernet Data",
277 { } /* end of list */
278};
279
280static struct usb_gadget_strings rndis_string_table = {
281 .language = 0x0409, /* en-us */
282 .strings = rndis_string_defs,
283};
284
285static struct usb_gadget_strings *rndis_strings[] = {
286 &rndis_string_table,
287 NULL,
288};
289
290/*-------------------------------------------------------------------------*/
291
292static struct sk_buff *rndis_add_header(struct sk_buff *skb)
293{
294 skb = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type));
295 if (skb)
296 rndis_add_hdr(skb);
297 return skb;
298}
299
300static void rndis_response_available(void *_rndis)
301{
302 struct f_rndis *rndis = _rndis;
303 struct usb_request *req = rndis->notify_req;
304 struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
305 __le32 *data = req->buf;
306 int status;
307
308 if (atomic_inc_return(&rndis->notify_count))
309 return;
310
311 /* Send RNDIS RESPONSE_AVAILABLE notification; a
312 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE "should" work too
313 *
314 * This is the only notification defined by RNDIS.
315 */
316 data[0] = cpu_to_le32(1);
317 data[1] = cpu_to_le32(0);
318
319 status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
320 if (status) {
321 atomic_dec(&rndis->notify_count);
322 DBG(cdev, "notify/0 --> %d\n", status);
323 }
324}
325
326static void rndis_response_complete(struct usb_ep *ep, struct usb_request *req)
327{
328 struct f_rndis *rndis = req->context;
329 struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
330 int status = req->status;
331
332 /* after TX:
333 * - USB_CDC_GET_ENCAPSULATED_RESPONSE (ep0/control)
334 * - RNDIS_RESPONSE_AVAILABLE (status/irq)
335 */
336 switch (status) {
337 case -ECONNRESET:
338 case -ESHUTDOWN:
339 /* connection gone */
340 atomic_set(&rndis->notify_count, 0);
341 break;
342 default:
343 DBG(cdev, "RNDIS %s response error %d, %d/%d\n",
344 ep->name, status,
345 req->actual, req->length);
346 /* FALLTHROUGH */
347 case 0:
348 if (ep != rndis->notify)
349 break;
350
351 /* handle multiple pending RNDIS_RESPONSE_AVAILABLE
352 * notifications by resending until we're done
353 */
354 if (atomic_dec_and_test(&rndis->notify_count))
355 break;
356 status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
357 if (status) {
358 atomic_dec(&rndis->notify_count);
359 DBG(cdev, "notify/1 --> %d\n", status);
360 }
361 break;
362 }
363}
364
365static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req)
366{
367 struct f_rndis *rndis = req->context;
368 struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
369 int status;
370
371 /* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
372// spin_lock(&dev->lock);
373 status = rndis_msg_parser(rndis->config, (u8 *) req->buf);
374 if (status < 0)
375 ERROR(cdev, "RNDIS command error %d, %d/%d\n",
376 status, req->actual, req->length);
377// spin_unlock(&dev->lock);
378}
379
380static int
381rndis_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
382{
383 struct f_rndis *rndis = func_to_rndis(f);
384 struct usb_composite_dev *cdev = f->config->cdev;
385 struct usb_request *req = cdev->req;
386 int value = -EOPNOTSUPP;
387 u16 w_index = le16_to_cpu(ctrl->wIndex);
388 u16 w_value = le16_to_cpu(ctrl->wValue);
389 u16 w_length = le16_to_cpu(ctrl->wLength);
390
391 /* composite driver infrastructure handles everything except
392 * CDC class messages; interface activation uses set_alt().
393 */
394 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
395
396 /* RNDIS uses the CDC command encapsulation mechanism to implement
397 * an RPC scheme, with much getting/setting of attributes by OID.
398 */
399 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
400 | USB_CDC_SEND_ENCAPSULATED_COMMAND:
401 if (w_length > req->length || w_value
402 || w_index != rndis->ctrl_id)
403 goto invalid;
404 /* read the request; process it later */
405 value = w_length;
406 req->complete = rndis_command_complete;
407 req->context = rndis;
408 /* later, rndis_response_available() sends a notification */
409 break;
410
411 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
412 | USB_CDC_GET_ENCAPSULATED_RESPONSE:
413 if (w_value || w_index != rndis->ctrl_id)
414 goto invalid;
415 else {
416 u8 *buf;
417 u32 n;
418
419 /* return the result */
420 buf = rndis_get_next_response(rndis->config, &n);
421 if (buf) {
422 memcpy(req->buf, buf, n);
423 req->complete = rndis_response_complete;
424 rndis_free_response(rndis->config, buf);
425 value = n;
426 }
427 /* else stalls ... spec says to avoid that */
428 }
429 break;
430
431 default:
432invalid:
433 VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
434 ctrl->bRequestType, ctrl->bRequest,
435 w_value, w_index, w_length);
436 }
437
438 /* respond with data transfer or status phase? */
439 if (value >= 0) {
440 DBG(cdev, "rndis req%02x.%02x v%04x i%04x l%d\n",
441 ctrl->bRequestType, ctrl->bRequest,
442 w_value, w_index, w_length);
443 req->zero = 0;
444 req->length = value;
445 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
446 if (value < 0)
447 ERROR(cdev, "rndis response on err %d\n", value);
448 }
449
450 /* device either stalls (value < 0) or reports success */
451 return value;
452}
453
454
455static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
456{
457 struct f_rndis *rndis = func_to_rndis(f);
458 struct usb_composite_dev *cdev = f->config->cdev;
459
460 /* we know alt == 0 */
461
462 if (intf == rndis->ctrl_id) {
463 if (rndis->notify->driver_data) {
464 VDBG(cdev, "reset rndis control %d\n", intf);
465 usb_ep_disable(rndis->notify);
466 } else {
467 VDBG(cdev, "init rndis ctrl %d\n", intf);
468 rndis->notify_desc = ep_choose(cdev->gadget,
469 rndis->hs.notify,
470 rndis->fs.notify);
471 }
472 usb_ep_enable(rndis->notify, rndis->notify_desc);
473 rndis->notify->driver_data = rndis;
474
475 } else if (intf == rndis->data_id) {
476 struct net_device *net;
477
478 if (rndis->port.in_ep->driver_data) {
479 DBG(cdev, "reset rndis\n");
480 gether_disconnect(&rndis->port);
481 } else {
482 DBG(cdev, "init rndis\n");
483 rndis->port.in = ep_choose(cdev->gadget,
484 rndis->hs.in, rndis->fs.in);
485 rndis->port.out = ep_choose(cdev->gadget,
486 rndis->hs.out, rndis->fs.out);
487 }
488
489 /* Avoid ZLPs; they can be troublesome. */
490 rndis->port.is_zlp_ok = false;
491
492 /* RNDIS should be in the "RNDIS uninitialized" state,
493 * either never activated or after rndis_uninit().
494 *
495 * We don't want data to flow here until a nonzero packet
496 * filter is set, at which point it enters "RNDIS data
497 * initialized" state ... but we do want the endpoints
498 * to be activated. It's a strange little state.
499 *
500 * REVISIT the RNDIS gadget code has done this wrong for a
501 * very long time. We need another call to the link layer
502 * code -- gether_updown(...bool) maybe -- to do it right.
503 */
504 rndis->port.cdc_filter = 0;
505
506 DBG(cdev, "RNDIS RX/TX early activation ... \n");
507 net = gether_connect(&rndis->port);
508 if (IS_ERR(net))
509 return PTR_ERR(net);
510
511 rndis_set_param_dev(rndis->config, net,
512 &rndis->port.cdc_filter);
513 } else
514 goto fail;
515
516 return 0;
517fail:
518 return -EINVAL;
519}
520
521static void rndis_disable(struct usb_function *f)
522{
523 struct f_rndis *rndis = func_to_rndis(f);
524 struct usb_composite_dev *cdev = f->config->cdev;
525
526 if (!rndis->notify->driver_data)
527 return;
528
529 DBG(cdev, "rndis deactivated\n");
530
531 rndis_uninit(rndis->config);
532 gether_disconnect(&rndis->port);
533
534 usb_ep_disable(rndis->notify);
535 rndis->notify->driver_data = NULL;
536}
537
538/*-------------------------------------------------------------------------*/
539
540/*
541 * This isn't quite the same mechanism as CDC Ethernet, since the
542 * notification scheme passes less data, but the same set of link
543 * states must be tested. A key difference is that altsettings are
544 * not used to tell whether the link should send packets or not.
545 */
546
547static void rndis_open(struct gether *geth)
548{
549 struct f_rndis *rndis = func_to_rndis(&geth->func);
550 struct usb_composite_dev *cdev = geth->func.config->cdev;
551
552 DBG(cdev, "%s\n", __func__);
553
554 rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3,
555 bitrate(cdev->gadget) / 100);
556 rndis_signal_connect(rndis->config);
557}
558
559static void rndis_close(struct gether *geth)
560{
561 struct f_rndis *rndis = func_to_rndis(&geth->func);
562
563 DBG(geth->func.config->cdev, "%s\n", __func__);
564
565 rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3, 0);
566 rndis_signal_disconnect(rndis->config);
567}
568
569/*-------------------------------------------------------------------------*/
570
571/* ethernet function driver setup/binding */
572
573static int __init
574rndis_bind(struct usb_configuration *c, struct usb_function *f)
575{
576 struct usb_composite_dev *cdev = c->cdev;
577 struct f_rndis *rndis = func_to_rndis(f);
578 int status;
579 struct usb_ep *ep;
580
581 /* allocate instance-specific interface IDs */
582 status = usb_interface_id(c, f);
583 if (status < 0)
584 goto fail;
585 rndis->ctrl_id = status;
586
587 rndis_control_intf.bInterfaceNumber = status;
588 rndis_union_desc.bMasterInterface0 = status;
589
590 status = usb_interface_id(c, f);
591 if (status < 0)
592 goto fail;
593 rndis->data_id = status;
594
595 rndis_data_intf.bInterfaceNumber = status;
596 rndis_union_desc.bSlaveInterface0 = status;
597
598 status = -ENODEV;
599
600 /* allocate instance-specific endpoints */
601 ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc);
602 if (!ep)
603 goto fail;
604 rndis->port.in_ep = ep;
605 ep->driver_data = cdev; /* claim */
606
607 ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc);
608 if (!ep)
609 goto fail;
610 rndis->port.out_ep = ep;
611 ep->driver_data = cdev; /* claim */
612
613 /* NOTE: a status/notification endpoint is, strictly speaking,
614 * optional. We don't treat it that way though! It's simpler,
615 * and some newer profiles don't treat it as optional.
616 */
617 ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc);
618 if (!ep)
619 goto fail;
620 rndis->notify = ep;
621 ep->driver_data = cdev; /* claim */
622
623 status = -ENOMEM;
624
625 /* allocate notification request and buffer */
626 rndis->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
627 if (!rndis->notify_req)
628 goto fail;
629 rndis->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL);
630 if (!rndis->notify_req->buf)
631 goto fail;
632 rndis->notify_req->length = STATUS_BYTECOUNT;
633 rndis->notify_req->context = rndis;
634 rndis->notify_req->complete = rndis_response_complete;
635
636 /* copy descriptors, and track endpoint copies */
637 f->descriptors = usb_copy_descriptors(eth_fs_function);
638 if (!f->descriptors)
639 goto fail;
640
641 rndis->fs.in = usb_find_endpoint(eth_fs_function,
642 f->descriptors, &fs_in_desc);
643 rndis->fs.out = usb_find_endpoint(eth_fs_function,
644 f->descriptors, &fs_out_desc);
645 rndis->fs.notify = usb_find_endpoint(eth_fs_function,
646 f->descriptors, &fs_notify_desc);
647
648 /* support all relevant hardware speeds... we expect that when
649 * hardware is dual speed, all bulk-capable endpoints work at
650 * both speeds
651 */
652 if (gadget_is_dualspeed(c->cdev->gadget)) {
653 hs_in_desc.bEndpointAddress =
654 fs_in_desc.bEndpointAddress;
655 hs_out_desc.bEndpointAddress =
656 fs_out_desc.bEndpointAddress;
657
658 /* copy descriptors, and track endpoint copies */
659 f->hs_descriptors = usb_copy_descriptors(eth_hs_function);
660
661 if (!f->hs_descriptors)
662 goto fail;
663
664 rndis->hs.in = usb_find_endpoint(eth_hs_function,
665 f->hs_descriptors, &hs_in_desc);
666 rndis->hs.out = usb_find_endpoint(eth_hs_function,
667 f->hs_descriptors, &hs_out_desc);
668 }
669
670 rndis->port.open = rndis_open;
671 rndis->port.close = rndis_close;
672
673 status = rndis_register(rndis_response_available, rndis);
674 if (status < 0)
675 goto fail;
676 rndis->config = status;
677
678 rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3, 0);
679 rndis_set_host_mac(rndis->config, rndis->ethaddr);
680
681#if 0
682// FIXME
683 if (rndis_set_param_vendor(rndis->config, vendorID,
684 manufacturer))
685 goto fail0;
686#endif
687
688 /* NOTE: all that is done without knowing or caring about
689 * the network link ... which is unavailable to this code
690 * until we're activated via set_alt().
691 */
692
693 DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n",
694 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
695 rndis->port.in_ep->name, rndis->port.out_ep->name,
696 rndis->notify->name);
697 return 0;
698
699fail:
700 if (gadget_is_dualspeed(c->cdev->gadget) && f->hs_descriptors)
701 usb_free_descriptors(f->hs_descriptors);
702 if (f->descriptors)
703 usb_free_descriptors(f->descriptors);
704
705 if (rndis->notify_req) {
706 kfree(rndis->notify_req->buf);
707 usb_ep_free_request(rndis->notify, rndis->notify_req);
708 }
709
710 /* we might as well release our claims on endpoints */
711 if (rndis->notify)
712 rndis->notify->driver_data = NULL;
713 if (rndis->port.out)
714 rndis->port.out_ep->driver_data = NULL;
715 if (rndis->port.in)
716 rndis->port.in_ep->driver_data = NULL;
717
718 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
719
720 return status;
721}
722
723static void
724rndis_unbind(struct usb_configuration *c, struct usb_function *f)
725{
726 struct f_rndis *rndis = func_to_rndis(f);
727
728 rndis_deregister(rndis->config);
729 rndis_exit();
730
731 if (gadget_is_dualspeed(c->cdev->gadget))
732 usb_free_descriptors(f->hs_descriptors);
733 usb_free_descriptors(f->descriptors);
734
735 kfree(rndis->notify_req->buf);
736 usb_ep_free_request(rndis->notify, rndis->notify_req);
737
738 kfree(rndis);
739}
740
741/* Some controllers can't support RNDIS ... */
742static inline bool can_support_rndis(struct usb_configuration *c)
743{
744 /* only two endpoints on sa1100 */
745 if (gadget_is_sa1100(c->cdev->gadget))
746 return false;
747
748 /* everything else is *presumably* fine */
749 return true;
750}
751
752/**
753 * rndis_bind_config - add RNDIS network link to a configuration
754 * @c: the configuration to support the network link
755 * @ethaddr: a buffer in which the ethernet address of the host side
756 * side of the link was recorded
757 * Context: single threaded during gadget setup
758 *
759 * Returns zero on success, else negative errno.
760 *
761 * Caller must have called @gether_setup(). Caller is also responsible
762 * for calling @gether_cleanup() before module unload.
763 */
764int __init rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
765{
766 struct f_rndis *rndis;
767 int status;
768
769 if (!can_support_rndis(c) || !ethaddr)
770 return -EINVAL;
771
772 /* maybe allocate device-global string IDs */
773 if (rndis_string_defs[0].id == 0) {
774
775 /* ... and setup RNDIS itself */
776 status = rndis_init();
777 if (status < 0)
778 return status;
779
780 /* control interface label */
781 status = usb_string_id(c->cdev);
782 if (status < 0)
783 return status;
784 rndis_string_defs[0].id = status;
785 rndis_control_intf.iInterface = status;
786
787 /* data interface label */
788 status = usb_string_id(c->cdev);
789 if (status < 0)
790 return status;
791 rndis_string_defs[1].id = status;
792 rndis_data_intf.iInterface = status;
793 }
794
795 /* allocate and initialize one new instance */
796 status = -ENOMEM;
797 rndis = kzalloc(sizeof *rndis, GFP_KERNEL);
798 if (!rndis)
799 goto fail;
800
801 memcpy(rndis->ethaddr, ethaddr, ETH_ALEN);
802
803 /* RNDIS activates when the host changes this filter */
804 rndis->port.cdc_filter = 0;
805
806 /* RNDIS has special (and complex) framing */
807 rndis->port.header_len = sizeof(struct rndis_packet_msg_type);
808 rndis->port.wrap = rndis_add_header;
809 rndis->port.unwrap = rndis_rm_hdr;
810
811 rndis->port.func.name = "rndis";
812 rndis->port.func.strings = rndis_strings;
813 /* descriptors are per-instance copies */
814 rndis->port.func.bind = rndis_bind;
815 rndis->port.func.unbind = rndis_unbind;
816 rndis->port.func.set_alt = rndis_set_alt;
817 rndis->port.func.setup = rndis_setup;
818 rndis->port.func.disable = rndis_disable;
819
820 status = usb_add_function(c, &rndis->port.func);
821 if (status) {
822 kfree(rndis);
823fail:
824 rndis_exit();
825 }
826 return status;
827}
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
new file mode 100644
index 000000000000..1b6bde9aaed5
--- /dev/null
+++ b/drivers/usb/gadget/f_serial.c
@@ -0,0 +1,296 @@
1/*
2 * f_serial.c - generic USB serial function driver
3 *
4 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
5 * Copyright (C) 2008 by David Brownell
6 * Copyright (C) 2008 by Nokia Corporation
7 *
8 * This software is distributed under the terms of the GNU General
9 * Public License ("GPL") as published by the Free Software Foundation,
10 * either version 2 of that License or (at your option) any later version.
11 */
12
13#include <linux/kernel.h>
14#include <linux/device.h>
15
16#include "u_serial.h"
17#include "gadget_chips.h"
18
19
20/*
21 * This function packages a simple "generic serial" port with no real
22 * control mechanisms, just raw data transfer over two bulk endpoints.
23 *
24 * Because it's not standardized, this isn't as interoperable as the
25 * CDC ACM driver. However, for many purposes it's just as functional
26 * if you can arrange appropriate host side drivers.
27 */
28
29struct gser_descs {
30 struct usb_endpoint_descriptor *in;
31 struct usb_endpoint_descriptor *out;
32};
33
34struct f_gser {
35 struct gserial port;
36 u8 data_id;
37 u8 port_num;
38
39 struct usb_descriptor_header **fs_function;
40 struct gser_descs fs;
41 struct usb_descriptor_header **hs_function;
42 struct gser_descs hs;
43};
44
45static inline struct f_gser *func_to_gser(struct usb_function *f)
46{
47 return container_of(f, struct f_gser, port.func);
48}
49
50/*-------------------------------------------------------------------------*/
51
52/* interface descriptor: */
53
54static struct usb_interface_descriptor gser_interface_desc __initdata = {
55 .bLength = USB_DT_INTERFACE_SIZE,
56 .bDescriptorType = USB_DT_INTERFACE,
57 /* .bInterfaceNumber = DYNAMIC */
58 .bNumEndpoints = 2,
59 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
60 .bInterfaceSubClass = 0,
61 .bInterfaceProtocol = 0,
62 /* .iInterface = DYNAMIC */
63};
64
65/* full speed support: */
66
67static struct usb_endpoint_descriptor gser_fs_in_desc __initdata = {
68 .bLength = USB_DT_ENDPOINT_SIZE,
69 .bDescriptorType = USB_DT_ENDPOINT,
70 .bEndpointAddress = USB_DIR_IN,
71 .bmAttributes = USB_ENDPOINT_XFER_BULK,
72};
73
74static struct usb_endpoint_descriptor gser_fs_out_desc __initdata = {
75 .bLength = USB_DT_ENDPOINT_SIZE,
76 .bDescriptorType = USB_DT_ENDPOINT,
77 .bEndpointAddress = USB_DIR_OUT,
78 .bmAttributes = USB_ENDPOINT_XFER_BULK,
79};
80
81static struct usb_descriptor_header *gser_fs_function[] __initdata = {
82 (struct usb_descriptor_header *) &gser_interface_desc,
83 (struct usb_descriptor_header *) &gser_fs_in_desc,
84 (struct usb_descriptor_header *) &gser_fs_out_desc,
85 NULL,
86};
87
88/* high speed support: */
89
90static struct usb_endpoint_descriptor gser_hs_in_desc __initdata = {
91 .bLength = USB_DT_ENDPOINT_SIZE,
92 .bDescriptorType = USB_DT_ENDPOINT,
93 .bmAttributes = USB_ENDPOINT_XFER_BULK,
94 .wMaxPacketSize = __constant_cpu_to_le16(512),
95};
96
97static struct usb_endpoint_descriptor gser_hs_out_desc __initdata = {
98 .bLength = USB_DT_ENDPOINT_SIZE,
99 .bDescriptorType = USB_DT_ENDPOINT,
100 .bmAttributes = USB_ENDPOINT_XFER_BULK,
101 .wMaxPacketSize = __constant_cpu_to_le16(512),
102};
103
104static struct usb_descriptor_header *gser_hs_function[] __initdata = {
105 (struct usb_descriptor_header *) &gser_interface_desc,
106 (struct usb_descriptor_header *) &gser_hs_in_desc,
107 (struct usb_descriptor_header *) &gser_hs_out_desc,
108 NULL,
109};
110
111/* string descriptors: */
112
113static struct usb_string gser_string_defs[] = {
114 [0].s = "Generic Serial",
115 { } /* end of list */
116};
117
118static struct usb_gadget_strings gser_string_table = {
119 .language = 0x0409, /* en-us */
120 .strings = gser_string_defs,
121};
122
123static struct usb_gadget_strings *gser_strings[] = {
124 &gser_string_table,
125 NULL,
126};
127
128/*-------------------------------------------------------------------------*/
129
130static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
131{
132 struct f_gser *gser = func_to_gser(f);
133 struct usb_composite_dev *cdev = f->config->cdev;
134
135 /* we know alt == 0, so this is an activation or a reset */
136
137 if (gser->port.in->driver_data) {
138 DBG(cdev, "reset generic ttyGS%d\n", gser->port_num);
139 gserial_disconnect(&gser->port);
140 } else {
141 DBG(cdev, "activate generic ttyGS%d\n", gser->port_num);
142 gser->port.in_desc = ep_choose(cdev->gadget,
143 gser->hs.in, gser->fs.in);
144 gser->port.out_desc = ep_choose(cdev->gadget,
145 gser->hs.out, gser->fs.out);
146 }
147 gserial_connect(&gser->port, gser->port_num);
148 return 0;
149}
150
151static void gser_disable(struct usb_function *f)
152{
153 struct f_gser *gser = func_to_gser(f);
154 struct usb_composite_dev *cdev = f->config->cdev;
155
156 DBG(cdev, "generic ttyGS%d deactivated\n", gser->port_num);
157 gserial_disconnect(&gser->port);
158}
159
160/*-------------------------------------------------------------------------*/
161
162/* serial function driver setup/binding */
163
164static int __init
165gser_bind(struct usb_configuration *c, struct usb_function *f)
166{
167 struct usb_composite_dev *cdev = c->cdev;
168 struct f_gser *gser = func_to_gser(f);
169 int status;
170 struct usb_ep *ep;
171
172 /* allocate instance-specific interface IDs */
173 status = usb_interface_id(c, f);
174 if (status < 0)
175 goto fail;
176 gser->data_id = status;
177 gser_interface_desc.bInterfaceNumber = status;
178
179 status = -ENODEV;
180
181 /* allocate instance-specific endpoints */
182 ep = usb_ep_autoconfig(cdev->gadget, &gser_fs_in_desc);
183 if (!ep)
184 goto fail;
185 gser->port.in = ep;
186 ep->driver_data = cdev; /* claim */
187
188 ep = usb_ep_autoconfig(cdev->gadget, &gser_fs_out_desc);
189 if (!ep)
190 goto fail;
191 gser->port.out = ep;
192 ep->driver_data = cdev; /* claim */
193
194 /* copy descriptors, and track endpoint copies */
195 f->descriptors = usb_copy_descriptors(gser_fs_function);
196
197 gser->fs.in = usb_find_endpoint(gser_fs_function,
198 f->descriptors, &gser_fs_in_desc);
199 gser->fs.out = usb_find_endpoint(gser_fs_function,
200 f->descriptors, &gser_fs_out_desc);
201
202
203 /* support all relevant hardware speeds... we expect that when
204 * hardware is dual speed, all bulk-capable endpoints work at
205 * both speeds
206 */
207 if (gadget_is_dualspeed(c->cdev->gadget)) {
208 gser_hs_in_desc.bEndpointAddress =
209 gser_fs_in_desc.bEndpointAddress;
210 gser_hs_out_desc.bEndpointAddress =
211 gser_fs_out_desc.bEndpointAddress;
212
213 /* copy descriptors, and track endpoint copies */
214 f->hs_descriptors = usb_copy_descriptors(gser_hs_function);
215
216 gser->hs.in = usb_find_endpoint(gser_hs_function,
217 f->hs_descriptors, &gser_hs_in_desc);
218 gser->hs.out = usb_find_endpoint(gser_hs_function,
219 f->hs_descriptors, &gser_hs_out_desc);
220 }
221
222 DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n",
223 gser->port_num,
224 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
225 gser->port.in->name, gser->port.out->name);
226 return 0;
227
228fail:
229 /* we might as well release our claims on endpoints */
230 if (gser->port.out)
231 gser->port.out->driver_data = NULL;
232 if (gser->port.in)
233 gser->port.in->driver_data = NULL;
234
235 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
236
237 return status;
238}
239
240static void
241gser_unbind(struct usb_configuration *c, struct usb_function *f)
242{
243 if (gadget_is_dualspeed(c->cdev->gadget))
244 usb_free_descriptors(f->hs_descriptors);
245 usb_free_descriptors(f->descriptors);
246 kfree(func_to_gser(f));
247}
248
249/**
250 * gser_bind_config - add a generic serial function to a configuration
251 * @c: the configuration to support the serial instance
252 * @port_num: /dev/ttyGS* port this interface will use
253 * Context: single threaded during gadget setup
254 *
255 * Returns zero on success, else negative errno.
256 *
257 * Caller must have called @gserial_setup() with enough ports to
258 * handle all the ones it binds. Caller is also responsible
259 * for calling @gserial_cleanup() before module unload.
260 */
261int __init gser_bind_config(struct usb_configuration *c, u8 port_num)
262{
263 struct f_gser *gser;
264 int status;
265
266 /* REVISIT might want instance-specific strings to help
267 * distinguish instances ...
268 */
269
270 /* maybe allocate device-global string ID */
271 if (gser_string_defs[0].id == 0) {
272 status = usb_string_id(c->cdev);
273 if (status < 0)
274 return status;
275 gser_string_defs[0].id = status;
276 }
277
278 /* allocate and initialize one new instance */
279 gser = kzalloc(sizeof *gser, GFP_KERNEL);
280 if (!gser)
281 return -ENOMEM;
282
283 gser->port_num = port_num;
284
285 gser->port.func.name = "gser";
286 gser->port.func.strings = gser_strings;
287 gser->port.func.bind = gser_bind;
288 gser->port.func.unbind = gser_unbind;
289 gser->port.func.set_alt = gser_set_alt;
290 gser->port.func.disable = gser_disable;
291
292 status = usb_add_function(c, &gser->port.func);
293 if (status)
294 kfree(gser);
295 return status;
296}
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
new file mode 100644
index 000000000000..f18c3a14d72a
--- /dev/null
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -0,0 +1,587 @@
1/*
2 * f_sourcesink.c - USB peripheral source/sink configuration driver
3 *
4 * Copyright (C) 2003-2008 David Brownell
5 * Copyright (C) 2008 by Nokia Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/* #define VERBOSE_DEBUG */
23
24#include <linux/kernel.h>
25#include <linux/utsname.h>
26#include <linux/device.h>
27
28#include "g_zero.h"
29#include "gadget_chips.h"
30
31
32/*
33 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral
34 * controller drivers.
35 *
36 * This just sinks bulk packets OUT to the peripheral and sources them IN
37 * to the host, optionally with specific data patterns for integrity tests.
38 * As such it supports basic functionality and load tests.
39 *
40 * In terms of control messaging, this supports all the standard requests
41 * plus two that support control-OUT tests. If the optional "autoresume"
42 * mode is enabled, it provides good functional coverage for the "USBCV"
43 * test harness from USB-IF.
44 *
45 * Note that because this doesn't queue more than one request at a time,
46 * some other function must be used to test queueing logic. The network
47 * link (g_ether) is the best overall option for that, since its TX and RX
48 * queues are relatively independent, will receive a range of packet sizes,
49 * and can often be made to run out completely. Those issues are important
50 * when stress testing peripheral controller drivers.
51 *
52 *
53 * This is currently packaged as a configuration driver, which can't be
54 * combined with other functions to make composite devices. However, it
55 * can be combined with other independent configurations.
56 */
57struct f_sourcesink {
58 struct usb_function function;
59
60 struct usb_ep *in_ep;
61 struct usb_ep *out_ep;
62 struct timer_list resume;
63};
64
65static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
66{
67 return container_of(f, struct f_sourcesink, function);
68}
69
70static unsigned autoresume;
71module_param(autoresume, uint, 0);
72MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup");
73
74static unsigned pattern;
75module_param(pattern, uint, 0);
76MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63 ");
77
78/*-------------------------------------------------------------------------*/
79
80static struct usb_interface_descriptor source_sink_intf = {
81 .bLength = sizeof source_sink_intf,
82 .bDescriptorType = USB_DT_INTERFACE,
83
84 .bNumEndpoints = 2,
85 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
86 /* .iInterface = DYNAMIC */
87};
88
89/* full speed support: */
90
91static struct usb_endpoint_descriptor fs_source_desc = {
92 .bLength = USB_DT_ENDPOINT_SIZE,
93 .bDescriptorType = USB_DT_ENDPOINT,
94
95 .bEndpointAddress = USB_DIR_IN,
96 .bmAttributes = USB_ENDPOINT_XFER_BULK,
97};
98
99static struct usb_endpoint_descriptor fs_sink_desc = {
100 .bLength = USB_DT_ENDPOINT_SIZE,
101 .bDescriptorType = USB_DT_ENDPOINT,
102
103 .bEndpointAddress = USB_DIR_OUT,
104 .bmAttributes = USB_ENDPOINT_XFER_BULK,
105};
106
107static struct usb_descriptor_header *fs_source_sink_descs[] = {
108 (struct usb_descriptor_header *) &source_sink_intf,
109 (struct usb_descriptor_header *) &fs_sink_desc,
110 (struct usb_descriptor_header *) &fs_source_desc,
111 NULL,
112};
113
114/* high speed support: */
115
116static struct usb_endpoint_descriptor hs_source_desc = {
117 .bLength = USB_DT_ENDPOINT_SIZE,
118 .bDescriptorType = USB_DT_ENDPOINT,
119
120 .bmAttributes = USB_ENDPOINT_XFER_BULK,
121 .wMaxPacketSize = __constant_cpu_to_le16(512),
122};
123
124static struct usb_endpoint_descriptor hs_sink_desc = {
125 .bLength = USB_DT_ENDPOINT_SIZE,
126 .bDescriptorType = USB_DT_ENDPOINT,
127
128 .bmAttributes = USB_ENDPOINT_XFER_BULK,
129 .wMaxPacketSize = __constant_cpu_to_le16(512),
130};
131
132static struct usb_descriptor_header *hs_source_sink_descs[] = {
133 (struct usb_descriptor_header *) &source_sink_intf,
134 (struct usb_descriptor_header *) &hs_source_desc,
135 (struct usb_descriptor_header *) &hs_sink_desc,
136 NULL,
137};
138
139/* function-specific strings: */
140
141static struct usb_string strings_sourcesink[] = {
142 [0].s = "source and sink data",
143 { } /* end of list */
144};
145
146static struct usb_gadget_strings stringtab_sourcesink = {
147 .language = 0x0409, /* en-us */
148 .strings = strings_sourcesink,
149};
150
151static struct usb_gadget_strings *sourcesink_strings[] = {
152 &stringtab_sourcesink,
153 NULL,
154};
155
156/*-------------------------------------------------------------------------*/
157
158static void sourcesink_autoresume(unsigned long _c)
159{
160 struct usb_composite_dev *cdev = (void *)_c;
161 struct usb_gadget *g = cdev->gadget;
162
163 /* Normally the host would be woken up for something
164 * more significant than just a timer firing; likely
165 * because of some direct user request.
166 */
167 if (g->speed != USB_SPEED_UNKNOWN) {
168 int status = usb_gadget_wakeup(g);
169 DBG(cdev, "%s --> %d\n", __func__, status);
170 }
171}
172
173static int __init
174sourcesink_bind(struct usb_configuration *c, struct usb_function *f)
175{
176 struct usb_composite_dev *cdev = c->cdev;
177 struct f_sourcesink *ss = func_to_ss(f);
178 int id;
179
180 /* allocate interface ID(s) */
181 id = usb_interface_id(c, f);
182 if (id < 0)
183 return id;
184 source_sink_intf.bInterfaceNumber = id;
185
186 /* allocate endpoints */
187 ss->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc);
188 if (!ss->in_ep) {
189autoconf_fail:
190 ERROR(cdev, "%s: can't autoconfigure on %s\n",
191 f->name, cdev->gadget->name);
192 return -ENODEV;
193 }
194 ss->in_ep->driver_data = cdev; /* claim */
195
196 ss->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_sink_desc);
197 if (!ss->out_ep)
198 goto autoconf_fail;
199 ss->out_ep->driver_data = cdev; /* claim */
200
201 setup_timer(&ss->resume, sourcesink_autoresume,
202 (unsigned long) c->cdev);
203
204 /* support high speed hardware */
205 if (gadget_is_dualspeed(c->cdev->gadget)) {
206 hs_source_desc.bEndpointAddress =
207 fs_source_desc.bEndpointAddress;
208 hs_sink_desc.bEndpointAddress =
209 fs_sink_desc.bEndpointAddress;
210 f->hs_descriptors = hs_source_sink_descs;
211 }
212
213 DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n",
214 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
215 f->name, ss->in_ep->name, ss->out_ep->name);
216 return 0;
217}
218
219static void
220sourcesink_unbind(struct usb_configuration *c, struct usb_function *f)
221{
222 kfree(func_to_ss(f));
223}
224
225/* optionally require specific source/sink data patterns */
226static int check_read_data(struct f_sourcesink *ss, struct usb_request *req)
227{
228 unsigned i;
229 u8 *buf = req->buf;
230 struct usb_composite_dev *cdev = ss->function.config->cdev;
231
232 for (i = 0; i < req->actual; i++, buf++) {
233 switch (pattern) {
234
235 /* all-zeroes has no synchronization issues */
236 case 0:
237 if (*buf == 0)
238 continue;
239 break;
240
241 /* "mod63" stays in sync with short-terminated transfers,
242 * OR otherwise when host and gadget agree on how large
243 * each usb transfer request should be. Resync is done
244 * with set_interface or set_config. (We *WANT* it to
245 * get quickly out of sync if controllers or their drivers
246 * stutter for any reason, including buffer duplcation...)
247 */
248 case 1:
249 if (*buf == (u8)(i % 63))
250 continue;
251 break;
252 }
253 ERROR(cdev, "bad OUT byte, buf[%d] = %d\n", i, *buf);
254 usb_ep_set_halt(ss->out_ep);
255 return -EINVAL;
256 }
257 return 0;
258}
259
260static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
261{
262 unsigned i;
263 u8 *buf = req->buf;
264
265 switch (pattern) {
266 case 0:
267 memset(req->buf, 0, req->length);
268 break;
269 case 1:
270 for (i = 0; i < req->length; i++)
271 *buf++ = (u8) (i % 63);
272 break;
273 }
274}
275
276static void source_sink_complete(struct usb_ep *ep, struct usb_request *req)
277{
278 struct f_sourcesink *ss = ep->driver_data;
279 struct usb_composite_dev *cdev = ss->function.config->cdev;
280 int status = req->status;
281
282 switch (status) {
283
284 case 0: /* normal completion? */
285 if (ep == ss->out_ep) {
286 check_read_data(ss, req);
287 memset(req->buf, 0x55, req->length);
288 } else
289 reinit_write_data(ep, req);
290 break;
291
292 /* this endpoint is normally active while we're configured */
293 case -ECONNABORTED: /* hardware forced ep reset */
294 case -ECONNRESET: /* request dequeued */
295 case -ESHUTDOWN: /* disconnect from host */
296 VDBG(cdev, "%s gone (%d), %d/%d\n", ep->name, status,
297 req->actual, req->length);
298 if (ep == ss->out_ep)
299 check_read_data(ss, req);
300 free_ep_req(ep, req);
301 return;
302
303 case -EOVERFLOW: /* buffer overrun on read means that
304 * we didn't provide a big enough
305 * buffer.
306 */
307 default:
308#if 1
309 DBG(cdev, "%s complete --> %d, %d/%d\n", ep->name,
310 status, req->actual, req->length);
311#endif
312 case -EREMOTEIO: /* short read */
313 break;
314 }
315
316 status = usb_ep_queue(ep, req, GFP_ATOMIC);
317 if (status) {
318 ERROR(cdev, "kill %s: resubmit %d bytes --> %d\n",
319 ep->name, req->length, status);
320 usb_ep_set_halt(ep);
321 /* FIXME recover later ... somehow */
322 }
323}
324
325static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in)
326{
327 struct usb_ep *ep;
328 struct usb_request *req;
329 int status;
330
331 ep = is_in ? ss->in_ep : ss->out_ep;
332 req = alloc_ep_req(ep);
333 if (!req)
334 return -ENOMEM;
335
336 req->complete = source_sink_complete;
337 if (is_in)
338 reinit_write_data(ep, req);
339 else
340 memset(req->buf, 0x55, req->length);
341
342 status = usb_ep_queue(ep, req, GFP_ATOMIC);
343 if (status) {
344 struct usb_composite_dev *cdev;
345
346 cdev = ss->function.config->cdev;
347 ERROR(cdev, "start %s %s --> %d\n",
348 is_in ? "IN" : "OUT",
349 ep->name, status);
350 free_ep_req(ep, req);
351 }
352
353 return status;
354}
355
356static void disable_source_sink(struct f_sourcesink *ss)
357{
358 struct usb_composite_dev *cdev;
359
360 cdev = ss->function.config->cdev;
361 disable_endpoints(cdev, ss->in_ep, ss->out_ep);
362 del_timer(&ss->resume);
363 VDBG(cdev, "%s disabled\n", ss->function.name);
364}
365
366static int
367enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss)
368{
369 int result = 0;
370 const struct usb_endpoint_descriptor *src, *sink;
371 struct usb_ep *ep;
372
373 src = ep_choose(cdev->gadget, &hs_source_desc, &fs_source_desc);
374 sink = ep_choose(cdev->gadget, &hs_sink_desc, &fs_sink_desc);
375
376 /* one endpoint writes (sources) zeroes IN (to the host) */
377 ep = ss->in_ep;
378 result = usb_ep_enable(ep, src);
379 if (result < 0)
380 return result;
381 ep->driver_data = ss;
382
383 result = source_sink_start_ep(ss, true);
384 if (result < 0) {
385fail:
386 ep = ss->in_ep;
387 usb_ep_disable(ep);
388 ep->driver_data = NULL;
389 return result;
390 }
391
392 /* one endpoint reads (sinks) anything OUT (from the host) */
393 ep = ss->out_ep;
394 result = usb_ep_enable(ep, sink);
395 if (result < 0)
396 goto fail;
397 ep->driver_data = ss;
398
399 result = source_sink_start_ep(ss, false);
400 if (result < 0) {
401 usb_ep_disable(ep);
402 ep->driver_data = NULL;
403 goto fail;
404 }
405
406 DBG(cdev, "%s enabled\n", ss->function.name);
407 return result;
408}
409
410static int sourcesink_set_alt(struct usb_function *f,
411 unsigned intf, unsigned alt)
412{
413 struct f_sourcesink *ss = func_to_ss(f);
414 struct usb_composite_dev *cdev = f->config->cdev;
415
416 /* we know alt is zero */
417 if (ss->in_ep->driver_data)
418 disable_source_sink(ss);
419 return enable_source_sink(cdev, ss);
420}
421
422static void sourcesink_disable(struct usb_function *f)
423{
424 struct f_sourcesink *ss = func_to_ss(f);
425
426 disable_source_sink(ss);
427}
428
429static void sourcesink_suspend(struct usb_function *f)
430{
431 struct f_sourcesink *ss = func_to_ss(f);
432 struct usb_composite_dev *cdev = f->config->cdev;
433
434 if (cdev->gadget->speed == USB_SPEED_UNKNOWN)
435 return;
436
437 if (autoresume) {
438 mod_timer(&ss->resume, jiffies + (HZ * autoresume));
439 DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume);
440 } else
441 DBG(cdev, "%s\n", __func__);
442}
443
444static void sourcesink_resume(struct usb_function *f)
445{
446 struct f_sourcesink *ss = func_to_ss(f);
447 struct usb_composite_dev *cdev = f->config->cdev;
448
449 DBG(cdev, "%s\n", __func__);
450 del_timer(&ss->resume);
451}
452
453/*-------------------------------------------------------------------------*/
454
455static int __init sourcesink_bind_config(struct usb_configuration *c)
456{
457 struct f_sourcesink *ss;
458 int status;
459
460 ss = kzalloc(sizeof *ss, GFP_KERNEL);
461 if (!ss)
462 return -ENOMEM;
463
464 ss->function.name = "source/sink";
465 ss->function.descriptors = fs_source_sink_descs;
466 ss->function.bind = sourcesink_bind;
467 ss->function.unbind = sourcesink_unbind;
468 ss->function.set_alt = sourcesink_set_alt;
469 ss->function.disable = sourcesink_disable;
470 ss->function.suspend = sourcesink_suspend;
471 ss->function.resume = sourcesink_resume;
472
473 status = usb_add_function(c, &ss->function);
474 if (status)
475 kfree(ss);
476 return status;
477}
478
479static int sourcesink_setup(struct usb_configuration *c,
480 const struct usb_ctrlrequest *ctrl)
481{
482 struct usb_request *req = c->cdev->req;
483 int value = -EOPNOTSUPP;
484 u16 w_index = le16_to_cpu(ctrl->wIndex);
485 u16 w_value = le16_to_cpu(ctrl->wValue);
486 u16 w_length = le16_to_cpu(ctrl->wLength);
487
488 /* composite driver infrastructure handles everything except
489 * the two control test requests.
490 */
491 switch (ctrl->bRequest) {
492
493 /*
494 * These are the same vendor-specific requests supported by
495 * Intel's USB 2.0 compliance test devices. We exceed that
496 * device spec by allowing multiple-packet requests.
497 *
498 * NOTE: the Control-OUT data stays in req->buf ... better
499 * would be copying it into a scratch buffer, so that other
500 * requests may safely intervene.
501 */
502 case 0x5b: /* control WRITE test -- fill the buffer */
503 if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
504 goto unknown;
505 if (w_value || w_index)
506 break;
507 /* just read that many bytes into the buffer */
508 if (w_length > req->length)
509 break;
510 value = w_length;
511 break;
512 case 0x5c: /* control READ test -- return the buffer */
513 if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
514 goto unknown;
515 if (w_value || w_index)
516 break;
517 /* expect those bytes are still in the buffer; send back */
518 if (w_length > req->length)
519 break;
520 value = w_length;
521 break;
522
523 default:
524unknown:
525 VDBG(c->cdev,
526 "unknown control req%02x.%02x v%04x i%04x l%d\n",
527 ctrl->bRequestType, ctrl->bRequest,
528 w_value, w_index, w_length);
529 }
530
531 /* respond with data transfer or status phase? */
532 if (value >= 0) {
533 VDBG(c->cdev, "source/sink req%02x.%02x v%04x i%04x l%d\n",
534 ctrl->bRequestType, ctrl->bRequest,
535 w_value, w_index, w_length);
536 req->zero = 0;
537 req->length = value;
538 value = usb_ep_queue(c->cdev->gadget->ep0, req, GFP_ATOMIC);
539 if (value < 0)
540 ERROR(c->cdev, "source/sinkc response, err %d\n",
541 value);
542 }
543
544 /* device either stalls (value < 0) or reports success */
545 return value;
546}
547
548static struct usb_configuration sourcesink_driver = {
549 .label = "source/sink",
550 .strings = sourcesink_strings,
551 .bind = sourcesink_bind_config,
552 .setup = sourcesink_setup,
553 .bConfigurationValue = 3,
554 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
555 .bMaxPower = 1, /* 2 mA, minimal */
556 /* .iConfiguration = DYNAMIC */
557};
558
559/**
560 * sourcesink_add - add a source/sink testing configuration to a device
561 * @cdev: the device to support the configuration
562 */
563int __init sourcesink_add(struct usb_composite_dev *cdev)
564{
565 int id;
566
567 /* allocate string ID(s) */
568 id = usb_string_id(cdev);
569 if (id < 0)
570 return id;
571 strings_sourcesink[0].id = id;
572
573 source_sink_intf.iInterface = id;
574 sourcesink_driver.iConfiguration = id;
575
576 /* support autoresume for remote wakeup testing */
577 if (autoresume)
578 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
579
580 /* support OTG systems */
581 if (gadget_is_otg(cdev->gadget)) {
582 sourcesink_driver.descriptors = otg_desc;
583 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
584 }
585
586 return usb_add_config(cdev, &sourcesink_driver);
587}
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
new file mode 100644
index 000000000000..afeab9a0523f
--- /dev/null
+++ b/drivers/usb/gadget/f_subset.c
@@ -0,0 +1,423 @@
1/*
2 * f_subset.c -- "CDC Subset" Ethernet link function driver
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/kernel.h>
23#include <linux/device.h>
24#include <linux/etherdevice.h>
25
26#include "u_ether.h"
27
28
29/*
30 * This function packages a simple "CDC Subset" Ethernet port with no real
31 * control mechanisms; just raw data transfer over two bulk endpoints.
32 * The data transfer model is exactly that of CDC Ethernet, which is
33 * why we call it the "CDC Subset".
34 *
35 * Because it's not standardized, this has some interoperability issues.
36 * They mostly relate to driver binding, since the data transfer model is
37 * so simple (CDC Ethernet). The original versions of this protocol used
38 * specific product/vendor IDs: byteswapped IDs for Digital Equipment's
39 * SA-1100 "Itsy" board, which could run Linux 2.4 kernels and supported
40 * daughtercards with USB peripheral connectors. (It was used more often
41 * with other boards, using the Itsy identifiers.) Linux hosts recognized
42 * this with CONFIG_USB_ARMLINUX; these devices have only one configuration
43 * and one interface.
44 *
45 * At some point, MCCI defined a (nonconformant) CDC MDLM variant called
46 * "SAFE", which happens to have a mode which is identical to the "CDC
47 * Subset" in terms of data transfer and lack of control model. This was
48 * adopted by later Sharp Zaurus models, and by some other software which
49 * Linux hosts recognize with CONFIG_USB_NET_ZAURUS.
50 *
51 * Because Microsoft's RNDIS drivers are far from robust, we added a few
52 * descriptors to the CDC Subset code, making this code look like a SAFE
53 * implementation. This lets you use MCCI's host side MS-Windows drivers
54 * if you get fed up with RNDIS. It also makes it easier for composite
55 * drivers to work, since they can use class based binding instead of
56 * caring about specific product and vendor IDs.
57 */
58
59struct geth_descs {
60 struct usb_endpoint_descriptor *in;
61 struct usb_endpoint_descriptor *out;
62};
63
64struct f_gether {
65 struct gether port;
66
67 char ethaddr[14];
68
69 struct usb_descriptor_header **fs_function;
70 struct geth_descs fs;
71 struct usb_descriptor_header **hs_function;
72 struct geth_descs hs;
73};
74
75static inline struct f_gether *func_to_geth(struct usb_function *f)
76{
77 return container_of(f, struct f_gether, port.func);
78}
79
80/*-------------------------------------------------------------------------*/
81
82/*
83 * "Simple" CDC-subset option is a simple vendor-neutral model that most
84 * full speed controllers can handle: one interface, two bulk endpoints.
85 * To assist host side drivers, we fancy it up a bit, and add descriptors so
86 * some host side drivers will understand it as a "SAFE" variant.
87 *
88 * "SAFE" loosely follows CDC WMC MDLM, violating the spec in various ways.
89 * Data endpoints live in the control interface, there's no data interface.
90 * And it's not used to talk to a cell phone radio.
91 */
92
93/* interface descriptor: */
94
95static struct usb_interface_descriptor subset_data_intf __initdata = {
96 .bLength = sizeof subset_data_intf,
97 .bDescriptorType = USB_DT_INTERFACE,
98
99 /* .bInterfaceNumber = DYNAMIC */
100 .bAlternateSetting = 0,
101 .bNumEndpoints = 2,
102 .bInterfaceClass = USB_CLASS_COMM,
103 .bInterfaceSubClass = USB_CDC_SUBCLASS_MDLM,
104 .bInterfaceProtocol = 0,
105 /* .iInterface = DYNAMIC */
106};
107
108static struct usb_cdc_header_desc header_desc __initdata = {
109 .bLength = sizeof header_desc,
110 .bDescriptorType = USB_DT_CS_INTERFACE,
111 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
112
113 .bcdCDC = __constant_cpu_to_le16(0x0110),
114};
115
116static struct usb_cdc_mdlm_desc mdlm_desc __initdata = {
117 .bLength = sizeof mdlm_desc,
118 .bDescriptorType = USB_DT_CS_INTERFACE,
119 .bDescriptorSubType = USB_CDC_MDLM_TYPE,
120
121 .bcdVersion = __constant_cpu_to_le16(0x0100),
122 .bGUID = {
123 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
124 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
125 },
126};
127
128/* since "usb_cdc_mdlm_detail_desc" is a variable length structure, we
129 * can't really use its struct. All we do here is say that we're using
130 * the submode of "SAFE" which directly matches the CDC Subset.
131 */
132static u8 mdlm_detail_desc[] __initdata = {
133 6,
134 USB_DT_CS_INTERFACE,
135 USB_CDC_MDLM_DETAIL_TYPE,
136
137 0, /* "SAFE" */
138 0, /* network control capabilities (none) */
139 0, /* network data capabilities ("raw" encapsulation) */
140};
141
142static struct usb_cdc_ether_desc ether_desc __initdata = {
143 .bLength = sizeof ether_desc,
144 .bDescriptorType = USB_DT_CS_INTERFACE,
145 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
146
147 /* this descriptor actually adds value, surprise! */
148 /* .iMACAddress = DYNAMIC */
149 .bmEthernetStatistics = __constant_cpu_to_le32(0), /* no statistics */
150 .wMaxSegmentSize = __constant_cpu_to_le16(ETH_FRAME_LEN),
151 .wNumberMCFilters = __constant_cpu_to_le16(0),
152 .bNumberPowerFilters = 0,
153};
154
155/* full speed support: */
156
157static struct usb_endpoint_descriptor fs_in_desc __initdata = {
158 .bLength = USB_DT_ENDPOINT_SIZE,
159 .bDescriptorType = USB_DT_ENDPOINT,
160
161 .bEndpointAddress = USB_DIR_IN,
162 .bmAttributes = USB_ENDPOINT_XFER_BULK,
163};
164
165static struct usb_endpoint_descriptor fs_out_desc __initdata = {
166 .bLength = USB_DT_ENDPOINT_SIZE,
167 .bDescriptorType = USB_DT_ENDPOINT,
168
169 .bEndpointAddress = USB_DIR_OUT,
170 .bmAttributes = USB_ENDPOINT_XFER_BULK,
171};
172
173static struct usb_descriptor_header *fs_eth_function[] __initdata = {
174 (struct usb_descriptor_header *) &subset_data_intf,
175 (struct usb_descriptor_header *) &header_desc,
176 (struct usb_descriptor_header *) &mdlm_desc,
177 (struct usb_descriptor_header *) &mdlm_detail_desc,
178 (struct usb_descriptor_header *) &ether_desc,
179 (struct usb_descriptor_header *) &fs_in_desc,
180 (struct usb_descriptor_header *) &fs_out_desc,
181 NULL,
182};
183
184/* high speed support: */
185
186static struct usb_endpoint_descriptor hs_in_desc __initdata = {
187 .bLength = USB_DT_ENDPOINT_SIZE,
188 .bDescriptorType = USB_DT_ENDPOINT,
189
190 .bmAttributes = USB_ENDPOINT_XFER_BULK,
191 .wMaxPacketSize = __constant_cpu_to_le16(512),
192};
193
194static struct usb_endpoint_descriptor hs_out_desc __initdata = {
195 .bLength = USB_DT_ENDPOINT_SIZE,
196 .bDescriptorType = USB_DT_ENDPOINT,
197
198 .bmAttributes = USB_ENDPOINT_XFER_BULK,
199 .wMaxPacketSize = __constant_cpu_to_le16(512),
200};
201
202static struct usb_descriptor_header *hs_eth_function[] __initdata = {
203 (struct usb_descriptor_header *) &subset_data_intf,
204 (struct usb_descriptor_header *) &header_desc,
205 (struct usb_descriptor_header *) &mdlm_desc,
206 (struct usb_descriptor_header *) &mdlm_detail_desc,
207 (struct usb_descriptor_header *) &ether_desc,
208 (struct usb_descriptor_header *) &hs_in_desc,
209 (struct usb_descriptor_header *) &hs_out_desc,
210 NULL,
211};
212
213/* string descriptors: */
214
215static struct usb_string geth_string_defs[] = {
216 [0].s = "CDC Ethernet Subset/SAFE",
217 [1].s = NULL /* DYNAMIC */,
218 { } /* end of list */
219};
220
221static struct usb_gadget_strings geth_string_table = {
222 .language = 0x0409, /* en-us */
223 .strings = geth_string_defs,
224};
225
226static struct usb_gadget_strings *geth_strings[] = {
227 &geth_string_table,
228 NULL,
229};
230
231/*-------------------------------------------------------------------------*/
232
233static int geth_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
234{
235 struct f_gether *geth = func_to_geth(f);
236 struct usb_composite_dev *cdev = f->config->cdev;
237 struct net_device *net;
238
239 /* we know alt == 0, so this is an activation or a reset */
240
241 if (geth->port.in_ep->driver_data) {
242 DBG(cdev, "reset cdc subset\n");
243 gether_disconnect(&geth->port);
244 }
245
246 DBG(cdev, "init + activate cdc subset\n");
247 geth->port.in = ep_choose(cdev->gadget,
248 geth->hs.in, geth->fs.in);
249 geth->port.out = ep_choose(cdev->gadget,
250 geth->hs.out, geth->fs.out);
251
252 net = gether_connect(&geth->port);
253 return IS_ERR(net) ? PTR_ERR(net) : 0;
254}
255
256static void geth_disable(struct usb_function *f)
257{
258 struct f_gether *geth = func_to_geth(f);
259 struct usb_composite_dev *cdev = f->config->cdev;
260
261 DBG(cdev, "net deactivated\n");
262 gether_disconnect(&geth->port);
263}
264
265/*-------------------------------------------------------------------------*/
266
267/* serial function driver setup/binding */
268
269static int __init
270geth_bind(struct usb_configuration *c, struct usb_function *f)
271{
272 struct usb_composite_dev *cdev = c->cdev;
273 struct f_gether *geth = func_to_geth(f);
274 int status;
275 struct usb_ep *ep;
276
277 /* allocate instance-specific interface IDs */
278 status = usb_interface_id(c, f);
279 if (status < 0)
280 goto fail;
281 subset_data_intf.bInterfaceNumber = status;
282
283 status = -ENODEV;
284
285 /* allocate instance-specific endpoints */
286 ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc);
287 if (!ep)
288 goto fail;
289 geth->port.in_ep = ep;
290 ep->driver_data = cdev; /* claim */
291
292 ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc);
293 if (!ep)
294 goto fail;
295 geth->port.out_ep = ep;
296 ep->driver_data = cdev; /* claim */
297
298 /* copy descriptors, and track endpoint copies */
299 f->descriptors = usb_copy_descriptors(fs_eth_function);
300
301 geth->fs.in = usb_find_endpoint(fs_eth_function,
302 f->descriptors, &fs_in_desc);
303 geth->fs.out = usb_find_endpoint(fs_eth_function,
304 f->descriptors, &fs_out_desc);
305
306
307 /* support all relevant hardware speeds... we expect that when
308 * hardware is dual speed, all bulk-capable endpoints work at
309 * both speeds
310 */
311 if (gadget_is_dualspeed(c->cdev->gadget)) {
312 hs_in_desc.bEndpointAddress =
313 fs_in_desc.bEndpointAddress;
314 hs_out_desc.bEndpointAddress =
315 fs_out_desc.bEndpointAddress;
316
317 /* copy descriptors, and track endpoint copies */
318 f->hs_descriptors = usb_copy_descriptors(hs_eth_function);
319
320 geth->hs.in = usb_find_endpoint(hs_eth_function,
321 f->hs_descriptors, &hs_in_desc);
322 geth->hs.out = usb_find_endpoint(hs_eth_function,
323 f->hs_descriptors, &hs_out_desc);
324 }
325
326 /* NOTE: all that is done without knowing or caring about
327 * the network link ... which is unavailable to this code
328 * until we're activated via set_alt().
329 */
330
331 DBG(cdev, "CDC Subset: %s speed IN/%s OUT/%s\n",
332 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
333 geth->port.in_ep->name, geth->port.out_ep->name);
334 return 0;
335
336fail:
337 /* we might as well release our claims on endpoints */
338 if (geth->port.out)
339 geth->port.out_ep->driver_data = NULL;
340 if (geth->port.in)
341 geth->port.in_ep->driver_data = NULL;
342
343 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
344
345 return status;
346}
347
348static void
349geth_unbind(struct usb_configuration *c, struct usb_function *f)
350{
351 if (gadget_is_dualspeed(c->cdev->gadget))
352 usb_free_descriptors(f->hs_descriptors);
353 usb_free_descriptors(f->descriptors);
354 geth_string_defs[1].s = NULL;
355 kfree(func_to_geth(f));
356}
357
358/**
359 * geth_bind_config - add CDC Subset network link to a configuration
360 * @c: the configuration to support the network link
361 * @ethaddr: a buffer in which the ethernet address of the host side
362 * side of the link was recorded
363 * Context: single threaded during gadget setup
364 *
365 * Returns zero on success, else negative errno.
366 *
367 * Caller must have called @gether_setup(). Caller is also responsible
368 * for calling @gether_cleanup() before module unload.
369 */
370int __init geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
371{
372 struct f_gether *geth;
373 int status;
374
375 if (!ethaddr)
376 return -EINVAL;
377
378 /* maybe allocate device-global string IDs */
379 if (geth_string_defs[0].id == 0) {
380
381 /* interface label */
382 status = usb_string_id(c->cdev);
383 if (status < 0)
384 return status;
385 geth_string_defs[0].id = status;
386 subset_data_intf.iInterface = status;
387
388 /* MAC address */
389 status = usb_string_id(c->cdev);
390 if (status < 0)
391 return status;
392 geth_string_defs[1].id = status;
393 ether_desc.iMACAddress = status;
394 }
395
396 /* allocate and initialize one new instance */
397 geth = kzalloc(sizeof *geth, GFP_KERNEL);
398 if (!geth)
399 return -ENOMEM;
400
401 /* export host's Ethernet address in CDC format */
402 snprintf(geth->ethaddr, sizeof geth->ethaddr,
403 "%02X%02X%02X%02X%02X%02X",
404 ethaddr[0], ethaddr[1], ethaddr[2],
405 ethaddr[3], ethaddr[4], ethaddr[5]);
406 geth_string_defs[1].s = geth->ethaddr;
407
408 geth->port.cdc_filter = DEFAULT_FILTER;
409
410 geth->port.func.name = "cdc_subset";
411 geth->port.func.strings = geth_strings;
412 geth->port.func.bind = geth_bind;
413 geth->port.func.unbind = geth_unbind;
414 geth->port.func.set_alt = geth_set_alt;
415 geth->port.func.disable = geth_disable;
416
417 status = usb_add_function(c, &geth->port.func);
418 if (status) {
419 geth_string_defs[1].s = NULL;
420 kfree(geth);
421 }
422 return status;
423}
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 47bb9f09a1aa..15c24edbb61a 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -3867,8 +3867,8 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3867 curlun->dev.parent = &gadget->dev; 3867 curlun->dev.parent = &gadget->dev;
3868 curlun->dev.driver = &fsg_driver.driver; 3868 curlun->dev.driver = &fsg_driver.driver;
3869 dev_set_drvdata(&curlun->dev, fsg); 3869 dev_set_drvdata(&curlun->dev, fsg);
3870 snprintf(curlun->dev.bus_id, BUS_ID_SIZE, 3870 dev_set_name(&curlun->dev,"%s-lun%d",
3871 "%s-lun%d", gadget->dev.bus_id, i); 3871 dev_name(&gadget->dev), i);
3872 3872
3873 if ((rc = device_register(&curlun->dev)) != 0) { 3873 if ((rc = device_register(&curlun->dev)) != 0) {
3874 INFO(fsg, "failed to register LUN%d: %d\n", i, rc); 3874 INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index 18687543d7fa..1695382f30fe 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -2331,7 +2331,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2331 udc_controller->gadget.name = driver_name; 2331 udc_controller->gadget.name = driver_name;
2332 2332
2333 /* Setup gadget.dev and register with kernel */ 2333 /* Setup gadget.dev and register with kernel */
2334 strcpy(udc_controller->gadget.dev.bus_id, "gadget"); 2334 dev_set_name(&udc_controller->gadget.dev, "gadget");
2335 udc_controller->gadget.dev.release = fsl_udc_release; 2335 udc_controller->gadget.dev.release = fsl_udc_release;
2336 udc_controller->gadget.dev.parent = &pdev->dev; 2336 udc_controller->gadget.dev.parent = &pdev->dev;
2337 ret = device_register(&udc_controller->gadget.dev); 2337 ret = device_register(&udc_controller->gadget.dev);
diff --git a/drivers/usb/gadget/g_zero.h b/drivers/usb/gadget/g_zero.h
new file mode 100644
index 000000000000..dd2f16ad5a88
--- /dev/null
+++ b/drivers/usb/gadget/g_zero.h
@@ -0,0 +1,25 @@
1/*
2 * This header declares the utility functions used by "Gadget Zero", plus
3 * interfaces to its two single-configuration function drivers.
4 */
5
6#ifndef __G_ZERO_H
7#define __G_ZERO_H
8
9#include <linux/usb/composite.h>
10
11/* global state */
12extern unsigned buflen;
13extern const struct usb_descriptor_header *otg_desc[];
14
15/* common utilities */
16struct usb_request *alloc_ep_req(struct usb_ep *ep);
17void free_ep_req(struct usb_ep *ep, struct usb_request *req);
18void disable_endpoints(struct usb_composite_dev *cdev,
19 struct usb_ep *in, struct usb_ep *out);
20
21/* configuration-specific linkup */
22int sourcesink_add(struct usb_composite_dev *cdev);
23int loopback_add(struct usb_composite_dev *cdev);
24
25#endif /* __G_ZERO_H */
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index ca5149ea7312..5246e8fef2b2 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -214,3 +214,26 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
214 return 0x21; 214 return 0x21;
215 return -ENOENT; 215 return -ENOENT;
216} 216}
217
218
219/**
220 * gadget_supports_altsettings - return true if altsettings work
221 * @gadget: the gadget in question
222 */
223static inline bool gadget_supports_altsettings(struct usb_gadget *gadget)
224{
225 /* PXA 21x/25x/26x has no altsettings at all */
226 if (gadget_is_pxa(gadget))
227 return false;
228
229 /* PXA 27x and 3xx have *broken* altsetting support */
230 if (gadget_is_pxa27x(gadget))
231 return false;
232
233 /* SH3 hardware just doesn't do altsettings */
234 if (gadget_is_sh(gadget))
235 return false;
236
237 /* Everything else is *presumably* fine ... */
238 return true;
239}
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index be6613afedbf..48f1c63b7013 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1790,7 +1790,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1790 dev->gadget.ops = &goku_ops; 1790 dev->gadget.ops = &goku_ops;
1791 1791
1792 /* the "gadget" abstracts/virtualizes the controller */ 1792 /* the "gadget" abstracts/virtualizes the controller */
1793 strcpy(dev->gadget.dev.bus_id, "gadget"); 1793 dev_set_name(&dev->gadget.dev, "gadget");
1794 dev->gadget.dev.parent = &pdev->dev; 1794 dev->gadget.dev.parent = &pdev->dev;
1795 dev->gadget.dev.dma_mask = pdev->dev.dma_mask; 1795 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
1796 dev->gadget.dev.release = gadget_release; 1796 dev->gadget.dev.release = gadget_release;
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index f132a9219e11..04692d59fc1c 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -32,6 +32,7 @@
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/poll.h> 34#include <linux/poll.h>
35#include <linux/smp_lock.h>
35 36
36#include <linux/device.h> 37#include <linux/device.h>
37#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
@@ -483,8 +484,7 @@ ep_release (struct inode *inode, struct file *fd)
483 return 0; 484 return 0;
484} 485}
485 486
486static int ep_ioctl (struct inode *inode, struct file *fd, 487static long ep_ioctl(struct file *fd, unsigned code, unsigned long value)
487 unsigned code, unsigned long value)
488{ 488{
489 struct ep_data *data = fd->private_data; 489 struct ep_data *data = fd->private_data;
490 int status; 490 int status;
@@ -740,7 +740,7 @@ static const struct file_operations ep_io_operations = {
740 740
741 .read = ep_read, 741 .read = ep_read,
742 .write = ep_write, 742 .write = ep_write,
743 .ioctl = ep_ioctl, 743 .unlocked_ioctl = ep_ioctl,
744 .release = ep_release, 744 .release = ep_release,
745 745
746 .aio_read = ep_aio_read, 746 .aio_read = ep_aio_read,
@@ -1294,15 +1294,18 @@ out:
1294 return mask; 1294 return mask;
1295} 1295}
1296 1296
1297static int dev_ioctl (struct inode *inode, struct file *fd, 1297static long dev_ioctl (struct file *fd, unsigned code, unsigned long value)
1298 unsigned code, unsigned long value)
1299{ 1298{
1300 struct dev_data *dev = fd->private_data; 1299 struct dev_data *dev = fd->private_data;
1301 struct usb_gadget *gadget = dev->gadget; 1300 struct usb_gadget *gadget = dev->gadget;
1301 long ret = -ENOTTY;
1302 1302
1303 if (gadget->ops->ioctl) 1303 if (gadget->ops->ioctl) {
1304 return gadget->ops->ioctl (gadget, code, value); 1304 lock_kernel();
1305 return -ENOTTY; 1305 ret = gadget->ops->ioctl (gadget, code, value);
1306 unlock_kernel();
1307 }
1308 return ret;
1306} 1309}
1307 1310
1308/* used after device configuration */ 1311/* used after device configuration */
@@ -1314,7 +1317,7 @@ static const struct file_operations ep0_io_operations = {
1314 .write = ep0_write, 1317 .write = ep0_write,
1315 .fasync = ep0_fasync, 1318 .fasync = ep0_fasync,
1316 .poll = ep0_poll, 1319 .poll = ep0_poll,
1317 .ioctl = dev_ioctl, 1320 .unlocked_ioctl = dev_ioctl,
1318 .release = dev_release, 1321 .release = dev_release,
1319}; 1322};
1320 1323
@@ -1964,7 +1967,7 @@ static const struct file_operations dev_init_operations = {
1964 .open = dev_open, 1967 .open = dev_open,
1965 .write = dev_config, 1968 .write = dev_config,
1966 .fasync = ep0_fasync, 1969 .fasync = ep0_fasync,
1967 .ioctl = dev_ioctl, 1970 .unlocked_ioctl = dev_ioctl,
1968 .release = dev_release, 1971 .release = dev_release,
1969}; 1972};
1970 1973
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index 825abd2621b3..c6e7df04c69a 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -1970,7 +1970,7 @@ static const struct usb_gadget_ops lh7a40x_udc_ops = {
1970 1970
1971static void nop_release(struct device *dev) 1971static void nop_release(struct device *dev)
1972{ 1972{
1973 DEBUG("%s %s\n", __func__, dev->bus_id); 1973 DEBUG("%s %s\n", __func__, dev_name(dev));
1974} 1974}
1975 1975
1976static struct lh7a40x_udc memory = { 1976static struct lh7a40x_udc memory = {
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index ee6b35fa870f..8da7535c0c70 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -1593,7 +1593,7 @@ static int __init m66592_probe(struct platform_device *pdev)
1593 1593
1594 m66592->gadget.ops = &m66592_gadget_ops; 1594 m66592->gadget.ops = &m66592_gadget_ops;
1595 device_initialize(&m66592->gadget.dev); 1595 device_initialize(&m66592->gadget.dev);
1596 strcpy(m66592->gadget.dev.bus_id, "gadget"); 1596 dev_set_name(&m66592->gadget, "gadget");
1597 m66592->gadget.is_dualspeed = 1; 1597 m66592->gadget.is_dualspeed = 1;
1598 m66592->gadget.dev.parent = &pdev->dev; 1598 m66592->gadget.dev.parent = &pdev->dev;
1599 m66592->gadget.dev.dma_mask = pdev->dev.dma_mask; 1599 m66592->gadget.dev.dma_mask = pdev->dev.dma_mask;
diff --git a/drivers/usb/gadget/ndis.h b/drivers/usb/gadget/ndis.h
index 09e3ee4eeae1..df886cec5ef4 100644
--- a/drivers/usb/gadget/ndis.h
+++ b/drivers/usb/gadget/ndis.h
@@ -1,11 +1,11 @@
1/* 1/*
2 * ndis.h 2 * ndis.h
3 * 3 *
4 * ntddndis.h modified by Benedikt Spranger <b.spranger@pengutronix.de> 4 * ntddndis.h modified by Benedikt Spranger <b.spranger@pengutronix.de>
5 * 5 *
6 * Thanks to the cygwin development team, 6 * Thanks to the cygwin development team,
7 * espacially to Casper S. Hornstrup <chorns@users.sourceforge.net> 7 * espacially to Casper S. Hornstrup <chorns@users.sourceforge.net>
8 * 8 *
9 * THIS SOFTWARE IS NOT COPYRIGHTED 9 * THIS SOFTWARE IS NOT COPYRIGHTED
10 * 10 *
11 * This source code is offered for use in the public domain. You may 11 * This source code is offered for use in the public domain. You may
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index e01862300169..b67ab677af72 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -2768,7 +2768,7 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2768 dev->gadget.is_dualspeed = 1; 2768 dev->gadget.is_dualspeed = 1;
2769 2769
2770 /* the "gadget" abstracts/virtualizes the controller */ 2770 /* the "gadget" abstracts/virtualizes the controller */
2771 strcpy (dev->gadget.dev.bus_id, "gadget"); 2771 dev_set_name(&dev->gadget.dev, "gadget");
2772 dev->gadget.dev.parent = &pdev->dev; 2772 dev->gadget.dev.parent = &pdev->dev;
2773 dev->gadget.dev.dma_mask = pdev->dev.dma_mask; 2773 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
2774 dev->gadget.dev.release = gadget_release; 2774 dev->gadget.dev.release = gadget_release;
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 03a7f49d207d..4b79a8509e84 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -2686,7 +2686,7 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
2686 udc->gadget.name = driver_name; 2686 udc->gadget.name = driver_name;
2687 2687
2688 device_initialize(&udc->gadget.dev); 2688 device_initialize(&udc->gadget.dev);
2689 strcpy (udc->gadget.dev.bus_id, "gadget"); 2689 dev_set_name(&udc->gadget.dev, "gadget");
2690 udc->gadget.dev.release = omap_udc_release; 2690 udc->gadget.dev.release = omap_udc_release;
2691 udc->gadget.dev.parent = &odev->dev; 2691 udc->gadget.dev.parent = &odev->dev;
2692 if (use_dma) 2692 if (use_dma)
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index ec8f2eb041ca..49cd9e145a9b 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -828,9 +828,8 @@ printer_poll(struct file *fd, poll_table *wait)
828 return status; 828 return status;
829} 829}
830 830
831static int 831static long
832printer_ioctl(struct inode *inode, struct file *fd, unsigned int code, 832printer_ioctl(struct file *fd, unsigned int code, unsigned long arg)
833 unsigned long arg)
834{ 833{
835 struct printer_dev *dev = fd->private_data; 834 struct printer_dev *dev = fd->private_data;
836 unsigned long flags; 835 unsigned long flags;
@@ -869,7 +868,7 @@ static struct file_operations printer_io_operations = {
869 .write = printer_write, 868 .write = printer_write,
870 .fsync = printer_fsync, 869 .fsync = printer_fsync,
871 .poll = printer_poll, 870 .poll = printer_poll,
872 .ioctl = printer_ioctl, 871 .unlocked_ioctl = printer_ioctl,
873 .release = printer_close 872 .release = printer_close
874}; 873};
875 874
@@ -1361,8 +1360,8 @@ printer_bind(struct usb_gadget *gadget)
1361 1360
1362 1361
1363 /* Setup the sysfs files for the printer gadget. */ 1362 /* Setup the sysfs files for the printer gadget. */
1364 dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno, 1363 dev->pdev = device_create_drvdata(usb_gadget_class, NULL,
1365 "g_printer"); 1364 g_printer_devno, NULL, "g_printer");
1366 if (IS_ERR(dev->pdev)) { 1365 if (IS_ERR(dev->pdev)) {
1367 ERROR(dev, "Failed to create device: g_printer\n"); 1366 ERROR(dev, "Failed to create device: g_printer\n");
1368 goto fail; 1367 goto fail;
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index 031dceb93023..fbd6289977c8 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -1818,7 +1818,7 @@ pxa25x_udc_irq(int irq, void *_dev)
1818 1818
1819static void nop_release (struct device *dev) 1819static void nop_release (struct device *dev)
1820{ 1820{
1821 DMSG("%s %s\n", __func__, dev->bus_id); 1821 DMSG("%s %s\n", __func__, dev_name(dev));
1822} 1822}
1823 1823
1824/* this uses load-time allocation and initialization (instead of 1824/* this uses load-time allocation and initialization (instead of
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 9c0e82ec5c43..9d447d8cfc0c 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -1575,7 +1575,6 @@ static void udc_enable(struct pxa_udc *udc)
1575{ 1575{
1576 udc_writel(udc, UDCICR0, 0); 1576 udc_writel(udc, UDCICR0, 0);
1577 udc_writel(udc, UDCICR1, 0); 1577 udc_writel(udc, UDCICR1, 0);
1578 udc_writel(udc, UP2OCR, UP2OCR_HXOE);
1579 udc_clear_mask_UDCCR(udc, UDCCR_UDE); 1578 udc_clear_mask_UDCCR(udc, UDCCR_UDE);
1580 1579
1581 clk_enable(udc->clk); 1580 clk_enable(udc->clk);
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index d0677f5d3cd5..7228e8562236 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -1,8 +1,6 @@
1/* 1/*
2 * RNDIS MSG parser 2 * RNDIS MSG parser
3 * 3 *
4 * Version: $Id: rndis.c,v 1.19 2004/03/25 21:33:46 robert Exp $
5 *
6 * Authors: Benedikt Spranger, Pengutronix 4 * Authors: Benedikt Spranger, Pengutronix
7 * Robert Schwebel, Pengutronix 5 * Robert Schwebel, Pengutronix
8 * 6 *
@@ -30,6 +28,7 @@
30#include <linux/init.h> 28#include <linux/init.h>
31#include <linux/list.h> 29#include <linux/list.h>
32#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
31#include <linux/seq_file.h>
33#include <linux/netdevice.h> 32#include <linux/netdevice.h>
34 33
35#include <asm/io.h> 34#include <asm/io.h>
@@ -38,9 +37,7 @@
38#include <asm/unaligned.h> 37#include <asm/unaligned.h>
39 38
40 39
41#undef RNDIS_PM 40#undef VERBOSE_DEBUG
42#undef RNDIS_WAKEUP
43#undef VERBOSE
44 41
45#include "rndis.h" 42#include "rndis.h"
46 43
@@ -96,9 +93,6 @@ static const u32 oid_supported_list [] =
96 OID_GEN_MAXIMUM_TOTAL_SIZE, 93 OID_GEN_MAXIMUM_TOTAL_SIZE,
97 OID_GEN_MEDIA_CONNECT_STATUS, 94 OID_GEN_MEDIA_CONNECT_STATUS,
98 OID_GEN_PHYSICAL_MEDIUM, 95 OID_GEN_PHYSICAL_MEDIUM,
99#if 0
100 OID_GEN_RNDIS_CONFIG_PARAMETER,
101#endif
102 96
103 /* the statistical stuff */ 97 /* the statistical stuff */
104 OID_GEN_XMIT_OK, 98 OID_GEN_XMIT_OK,
@@ -146,7 +140,14 @@ static const u32 oid_supported_list [] =
146#endif /* RNDIS_OPTIONAL_STATS */ 140#endif /* RNDIS_OPTIONAL_STATS */
147 141
148#ifdef RNDIS_PM 142#ifdef RNDIS_PM
149 /* PM and wakeup are mandatory for USB: */ 143 /* PM and wakeup are "mandatory" for USB, but the RNDIS specs
144 * don't say what they mean ... and the NDIS specs are often
145 * confusing and/or ambiguous in this context. (That is, more
146 * so than their specs for the other OIDs.)
147 *
148 * FIXME someone who knows what these should do, please
149 * implement them!
150 */
150 151
151 /* power management */ 152 /* power management */
152 OID_PNP_CAPABILITIES, 153 OID_PNP_CAPABILITIES,
@@ -173,6 +174,8 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
173 __le32 *outbuf; 174 __le32 *outbuf;
174 int i, count; 175 int i, count;
175 rndis_query_cmplt_type *resp; 176 rndis_query_cmplt_type *resp;
177 struct net_device *net;
178 struct net_device_stats *stats;
176 179
177 if (!r) return -ENOMEM; 180 if (!r) return -ENOMEM;
178 resp = (rndis_query_cmplt_type *) r->buf; 181 resp = (rndis_query_cmplt_type *) r->buf;
@@ -194,6 +197,12 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
194 outbuf = (__le32 *) &resp[1]; 197 outbuf = (__le32 *) &resp[1];
195 resp->InformationBufferOffset = __constant_cpu_to_le32 (16); 198 resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
196 199
200 net = rndis_per_dev_params[configNr].dev;
201 if (net->get_stats)
202 stats = net->get_stats(net);
203 else
204 stats = NULL;
205
197 switch (OID) { 206 switch (OID) {
198 207
199 /* general oids (table 4-1) */ 208 /* general oids (table 4-1) */
@@ -350,11 +359,9 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
350 case OID_GEN_XMIT_OK: 359 case OID_GEN_XMIT_OK:
351 if (rndis_debug > 1) 360 if (rndis_debug > 1)
352 DBG("%s: OID_GEN_XMIT_OK\n", __func__); 361 DBG("%s: OID_GEN_XMIT_OK\n", __func__);
353 if (rndis_per_dev_params [configNr].stats) { 362 if (stats) {
354 *outbuf = cpu_to_le32 ( 363 *outbuf = cpu_to_le32(stats->tx_packets
355 rndis_per_dev_params [configNr].stats->tx_packets - 364 - stats->tx_errors - stats->tx_dropped);
356 rndis_per_dev_params [configNr].stats->tx_errors -
357 rndis_per_dev_params [configNr].stats->tx_dropped);
358 retval = 0; 365 retval = 0;
359 } 366 }
360 break; 367 break;
@@ -363,11 +370,9 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
363 case OID_GEN_RCV_OK: 370 case OID_GEN_RCV_OK:
364 if (rndis_debug > 1) 371 if (rndis_debug > 1)
365 DBG("%s: OID_GEN_RCV_OK\n", __func__); 372 DBG("%s: OID_GEN_RCV_OK\n", __func__);
366 if (rndis_per_dev_params [configNr].stats) { 373 if (stats) {
367 *outbuf = cpu_to_le32 ( 374 *outbuf = cpu_to_le32(stats->rx_packets
368 rndis_per_dev_params [configNr].stats->rx_packets - 375 - stats->rx_errors - stats->rx_dropped);
369 rndis_per_dev_params [configNr].stats->rx_errors -
370 rndis_per_dev_params [configNr].stats->rx_dropped);
371 retval = 0; 376 retval = 0;
372 } 377 }
373 break; 378 break;
@@ -376,9 +381,8 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
376 case OID_GEN_XMIT_ERROR: 381 case OID_GEN_XMIT_ERROR:
377 if (rndis_debug > 1) 382 if (rndis_debug > 1)
378 DBG("%s: OID_GEN_XMIT_ERROR\n", __func__); 383 DBG("%s: OID_GEN_XMIT_ERROR\n", __func__);
379 if (rndis_per_dev_params [configNr].stats) { 384 if (stats) {
380 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 385 *outbuf = cpu_to_le32(stats->tx_errors);
381 .stats->tx_errors);
382 retval = 0; 386 retval = 0;
383 } 387 }
384 break; 388 break;
@@ -387,9 +391,8 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
387 case OID_GEN_RCV_ERROR: 391 case OID_GEN_RCV_ERROR:
388 if (rndis_debug > 1) 392 if (rndis_debug > 1)
389 DBG("%s: OID_GEN_RCV_ERROR\n", __func__); 393 DBG("%s: OID_GEN_RCV_ERROR\n", __func__);
390 if (rndis_per_dev_params [configNr].stats) { 394 if (stats) {
391 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 395 *outbuf = cpu_to_le32(stats->rx_errors);
392 .stats->rx_errors);
393 retval = 0; 396 retval = 0;
394 } 397 }
395 break; 398 break;
@@ -397,150 +400,12 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
397 /* mandatory */ 400 /* mandatory */
398 case OID_GEN_RCV_NO_BUFFER: 401 case OID_GEN_RCV_NO_BUFFER:
399 DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __func__); 402 DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __func__);
400 if (rndis_per_dev_params [configNr].stats) { 403 if (stats) {
401 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 404 *outbuf = cpu_to_le32(stats->rx_dropped);
402 .stats->rx_dropped);
403 retval = 0;
404 }
405 break;
406
407#ifdef RNDIS_OPTIONAL_STATS
408 case OID_GEN_DIRECTED_BYTES_XMIT:
409 DBG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __func__);
410 /*
411 * Aunt Tilly's size of shoes
412 * minus antarctica count of penguins
413 * divided by weight of Alpha Centauri
414 */
415 if (rndis_per_dev_params [configNr].stats) {
416 *outbuf = cpu_to_le32 (
417 (rndis_per_dev_params [configNr]
418 .stats->tx_packets -
419 rndis_per_dev_params [configNr]
420 .stats->tx_errors -
421 rndis_per_dev_params [configNr]
422 .stats->tx_dropped)
423 * 123);
424 retval = 0;
425 }
426 break;
427
428 case OID_GEN_DIRECTED_FRAMES_XMIT:
429 DBG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __func__);
430 /* dito */
431 if (rndis_per_dev_params [configNr].stats) {
432 *outbuf = cpu_to_le32 (
433 (rndis_per_dev_params [configNr]
434 .stats->tx_packets -
435 rndis_per_dev_params [configNr]
436 .stats->tx_errors -
437 rndis_per_dev_params [configNr]
438 .stats->tx_dropped)
439 / 123);
440 retval = 0;
441 }
442 break;
443
444 case OID_GEN_MULTICAST_BYTES_XMIT:
445 DBG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __func__);
446 if (rndis_per_dev_params [configNr].stats) {
447 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
448 .stats->multicast*1234);
449 retval = 0;
450 }
451 break;
452
453 case OID_GEN_MULTICAST_FRAMES_XMIT:
454 DBG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __func__);
455 if (rndis_per_dev_params [configNr].stats) {
456 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
457 .stats->multicast);
458 retval = 0;
459 }
460 break;
461
462 case OID_GEN_BROADCAST_BYTES_XMIT:
463 DBG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __func__);
464 if (rndis_per_dev_params [configNr].stats) {
465 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
466 .stats->tx_packets/42*255);
467 retval = 0;
468 }
469 break;
470
471 case OID_GEN_BROADCAST_FRAMES_XMIT:
472 DBG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __func__);
473 if (rndis_per_dev_params [configNr].stats) {
474 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
475 .stats->tx_packets/42);
476 retval = 0;
477 }
478 break;
479
480 case OID_GEN_DIRECTED_BYTES_RCV:
481 DBG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __func__);
482 *outbuf = __constant_cpu_to_le32 (0);
483 retval = 0;
484 break;
485
486 case OID_GEN_DIRECTED_FRAMES_RCV:
487 DBG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __func__);
488 *outbuf = __constant_cpu_to_le32 (0);
489 retval = 0;
490 break;
491
492 case OID_GEN_MULTICAST_BYTES_RCV:
493 DBG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __func__);
494 if (rndis_per_dev_params [configNr].stats) {
495 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
496 .stats->multicast * 1111);
497 retval = 0;
498 }
499 break;
500
501 case OID_GEN_MULTICAST_FRAMES_RCV:
502 DBG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __func__);
503 if (rndis_per_dev_params [configNr].stats) {
504 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
505 .stats->multicast);
506 retval = 0;
507 }
508 break;
509
510 case OID_GEN_BROADCAST_BYTES_RCV:
511 DBG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __func__);
512 if (rndis_per_dev_params [configNr].stats) {
513 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
514 .stats->rx_packets/42*255);
515 retval = 0;
516 }
517 break;
518
519 case OID_GEN_BROADCAST_FRAMES_RCV:
520 DBG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __func__);
521 if (rndis_per_dev_params [configNr].stats) {
522 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
523 .stats->rx_packets/42);
524 retval = 0; 405 retval = 0;
525 } 406 }
526 break; 407 break;
527 408
528 case OID_GEN_RCV_CRC_ERROR:
529 DBG("%s: OID_GEN_RCV_CRC_ERROR\n", __func__);
530 if (rndis_per_dev_params [configNr].stats) {
531 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
532 .stats->rx_crc_errors);
533 retval = 0;
534 }
535 break;
536
537 case OID_GEN_TRANSMIT_QUEUE_LENGTH:
538 DBG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __func__);
539 *outbuf = __constant_cpu_to_le32 (0);
540 retval = 0;
541 break;
542#endif /* RNDIS_OPTIONAL_STATS */
543
544 /* ieee802.3 OIDs (table 4-3) */ 409 /* ieee802.3 OIDs (table 4-3) */
545 410
546 /* mandatory */ 411 /* mandatory */
@@ -592,9 +457,8 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
592 /* mandatory */ 457 /* mandatory */
593 case OID_802_3_RCV_ERROR_ALIGNMENT: 458 case OID_802_3_RCV_ERROR_ALIGNMENT:
594 DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__); 459 DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
595 if (rndis_per_dev_params [configNr].stats) { 460 if (stats) {
596 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 461 *outbuf = cpu_to_le32(stats->rx_frame_errors);
597 .stats->rx_frame_errors);
598 retval = 0; 462 retval = 0;
599 } 463 }
600 break; 464 break;
@@ -613,64 +477,6 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
613 retval = 0; 477 retval = 0;
614 break; 478 break;
615 479
616#ifdef RNDIS_OPTIONAL_STATS
617 case OID_802_3_XMIT_DEFERRED:
618 DBG("%s: OID_802_3_XMIT_DEFERRED\n", __func__);
619 /* TODO */
620 break;
621
622 case OID_802_3_XMIT_MAX_COLLISIONS:
623 DBG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __func__);
624 /* TODO */
625 break;
626
627 case OID_802_3_RCV_OVERRUN:
628 DBG("%s: OID_802_3_RCV_OVERRUN\n", __func__);
629 /* TODO */
630 break;
631
632 case OID_802_3_XMIT_UNDERRUN:
633 DBG("%s: OID_802_3_XMIT_UNDERRUN\n", __func__);
634 /* TODO */
635 break;
636
637 case OID_802_3_XMIT_HEARTBEAT_FAILURE:
638 DBG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __func__);
639 /* TODO */
640 break;
641
642 case OID_802_3_XMIT_TIMES_CRS_LOST:
643 DBG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __func__);
644 /* TODO */
645 break;
646
647 case OID_802_3_XMIT_LATE_COLLISIONS:
648 DBG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __func__);
649 /* TODO */
650 break;
651#endif /* RNDIS_OPTIONAL_STATS */
652
653#ifdef RNDIS_PM
654 /* power management OIDs (table 4-5) */
655 case OID_PNP_CAPABILITIES:
656 DBG("%s: OID_PNP_CAPABILITIES\n", __func__);
657
658 /* for now, no wakeup capabilities */
659 length = sizeof (struct NDIS_PNP_CAPABILITIES);
660 memset(outbuf, 0, length);
661 retval = 0;
662 break;
663 case OID_PNP_QUERY_POWER:
664 DBG("%s: OID_PNP_QUERY_POWER D%d\n", __func__,
665 get_unaligned_le32(buf) - 1);
666 /* only suspend is a real power state, and
667 * it can't be entered by OID_PNP_SET_POWER...
668 */
669 length = 0;
670 retval = 0;
671 break;
672#endif
673
674 default: 480 default:
675 pr_warning("%s: query unknown OID 0x%08X\n", 481 pr_warning("%s: query unknown OID 0x%08X\n",
676 __func__, OID); 482 __func__, OID);
@@ -726,9 +532,6 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
726 * what makes the packet flow start and stop, like 532 * what makes the packet flow start and stop, like
727 * activating the CDC Ethernet altsetting. 533 * activating the CDC Ethernet altsetting.
728 */ 534 */
729#ifdef RNDIS_PM
730update_linkstate:
731#endif
732 retval = 0; 535 retval = 0;
733 if (*params->filter) { 536 if (*params->filter) {
734 params->state = RNDIS_DATA_INITIALIZED; 537 params->state = RNDIS_DATA_INITIALIZED;
@@ -747,49 +550,6 @@ update_linkstate:
747 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__); 550 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__);
748 retval = 0; 551 retval = 0;
749 break; 552 break;
750#if 0
751 case OID_GEN_RNDIS_CONFIG_PARAMETER:
752 {
753 struct rndis_config_parameter *param;
754 param = (struct rndis_config_parameter *) buf;
755 DBG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n",
756 __func__,
757 min(cpu_to_le32(param->ParameterNameLength),80),
758 buf + param->ParameterNameOffset);
759 retval = 0;
760 }
761 break;
762#endif
763
764#ifdef RNDIS_PM
765 case OID_PNP_SET_POWER:
766 /* The only real power state is USB suspend, and RNDIS requests
767 * can't enter it; this one isn't really about power. After
768 * resuming, Windows forces a reset, and then SET_POWER D0.
769 * FIXME ... then things go batty; Windows wedges itself.
770 */
771 i = get_unaligned_le32(buf);
772 DBG("%s: OID_PNP_SET_POWER D%d\n", __func__, i - 1);
773 switch (i) {
774 case NdisDeviceStateD0:
775 *params->filter = params->saved_filter;
776 goto update_linkstate;
777 case NdisDeviceStateD3:
778 case NdisDeviceStateD2:
779 case NdisDeviceStateD1:
780 params->saved_filter = *params->filter;
781 retval = 0;
782 break;
783 }
784 break;
785
786#ifdef RNDIS_WAKEUP
787 // no wakeup support advertised, so wakeup OIDs always fail:
788 // - OID_PNP_ENABLE_WAKE_UP
789 // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN
790#endif
791
792#endif /* RNDIS_PM */
793 553
794 default: 554 default:
795 pr_warning("%s: set unknown OID 0x%08X, size %d\n", 555 pr_warning("%s: set unknown OID 0x%08X, size %d\n",
@@ -807,8 +567,10 @@ static int rndis_init_response (int configNr, rndis_init_msg_type *buf)
807{ 567{
808 rndis_init_cmplt_type *resp; 568 rndis_init_cmplt_type *resp;
809 rndis_resp_t *r; 569 rndis_resp_t *r;
570 struct rndis_params *params = rndis_per_dev_params + configNr;
810 571
811 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; 572 if (!params->dev)
573 return -ENOTSUPP;
812 574
813 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type)); 575 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type));
814 if (!r) 576 if (!r)
@@ -826,7 +588,7 @@ static int rndis_init_response (int configNr, rndis_init_msg_type *buf)
826 resp->Medium = __constant_cpu_to_le32 (RNDIS_MEDIUM_802_3); 588 resp->Medium = __constant_cpu_to_le32 (RNDIS_MEDIUM_802_3);
827 resp->MaxPacketsPerTransfer = __constant_cpu_to_le32 (1); 589 resp->MaxPacketsPerTransfer = __constant_cpu_to_le32 (1);
828 resp->MaxTransferSize = cpu_to_le32 ( 590 resp->MaxTransferSize = cpu_to_le32 (
829 rndis_per_dev_params [configNr].dev->mtu 591 params->dev->mtu
830 + sizeof (struct ethhdr) 592 + sizeof (struct ethhdr)
831 + sizeof (struct rndis_packet_msg_type) 593 + sizeof (struct rndis_packet_msg_type)
832 + 22); 594 + 22);
@@ -834,10 +596,7 @@ static int rndis_init_response (int configNr, rndis_init_msg_type *buf)
834 resp->AFListOffset = __constant_cpu_to_le32 (0); 596 resp->AFListOffset = __constant_cpu_to_le32 (0);
835 resp->AFListSize = __constant_cpu_to_le32 (0); 597 resp->AFListSize = __constant_cpu_to_le32 (0);
836 598
837 if (rndis_per_dev_params [configNr].ack) 599 params->resp_avail(params->v);
838 rndis_per_dev_params [configNr].ack (
839 rndis_per_dev_params [configNr].dev);
840
841 return 0; 600 return 0;
842} 601}
843 602
@@ -845,9 +604,11 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
845{ 604{
846 rndis_query_cmplt_type *resp; 605 rndis_query_cmplt_type *resp;
847 rndis_resp_t *r; 606 rndis_resp_t *r;
607 struct rndis_params *params = rndis_per_dev_params + configNr;
848 608
849 // DBG("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); 609 // DBG("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID));
850 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; 610 if (!params->dev)
611 return -ENOTSUPP;
851 612
852 /* 613 /*
853 * we need more memory: 614 * we need more memory:
@@ -878,9 +639,7 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
878 } else 639 } else
879 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); 640 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
880 641
881 if (rndis_per_dev_params [configNr].ack) 642 params->resp_avail(params->v);
882 rndis_per_dev_params [configNr].ack (
883 rndis_per_dev_params [configNr].dev);
884 return 0; 643 return 0;
885} 644}
886 645
@@ -889,6 +648,7 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
889 u32 BufLength, BufOffset; 648 u32 BufLength, BufOffset;
890 rndis_set_cmplt_type *resp; 649 rndis_set_cmplt_type *resp;
891 rndis_resp_t *r; 650 rndis_resp_t *r;
651 struct rndis_params *params = rndis_per_dev_params + configNr;
892 652
893 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type)); 653 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type));
894 if (!r) 654 if (!r)
@@ -898,7 +658,7 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
898 BufLength = le32_to_cpu (buf->InformationBufferLength); 658 BufLength = le32_to_cpu (buf->InformationBufferLength);
899 BufOffset = le32_to_cpu (buf->InformationBufferOffset); 659 BufOffset = le32_to_cpu (buf->InformationBufferOffset);
900 660
901#ifdef VERBOSE 661#ifdef VERBOSE_DEBUG
902 DBG("%s: Length: %d\n", __func__, BufLength); 662 DBG("%s: Length: %d\n", __func__, BufLength);
903 DBG("%s: Offset: %d\n", __func__, BufOffset); 663 DBG("%s: Offset: %d\n", __func__, BufOffset);
904 DBG("%s: InfoBuffer: ", __func__); 664 DBG("%s: InfoBuffer: ", __func__);
@@ -919,10 +679,7 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
919 else 679 else
920 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); 680 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
921 681
922 if (rndis_per_dev_params [configNr].ack) 682 params->resp_avail(params->v);
923 rndis_per_dev_params [configNr].ack (
924 rndis_per_dev_params [configNr].dev);
925
926 return 0; 683 return 0;
927} 684}
928 685
@@ -930,6 +687,7 @@ static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf)
930{ 687{
931 rndis_reset_cmplt_type *resp; 688 rndis_reset_cmplt_type *resp;
932 rndis_resp_t *r; 689 rndis_resp_t *r;
690 struct rndis_params *params = rndis_per_dev_params + configNr;
933 691
934 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type)); 692 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type));
935 if (!r) 693 if (!r)
@@ -942,10 +700,7 @@ static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf)
942 /* resent information */ 700 /* resent information */
943 resp->AddressingReset = __constant_cpu_to_le32 (1); 701 resp->AddressingReset = __constant_cpu_to_le32 (1);
944 702
945 if (rndis_per_dev_params [configNr].ack) 703 params->resp_avail(params->v);
946 rndis_per_dev_params [configNr].ack (
947 rndis_per_dev_params [configNr].dev);
948
949 return 0; 704 return 0;
950} 705}
951 706
@@ -954,6 +709,7 @@ static int rndis_keepalive_response (int configNr,
954{ 709{
955 rndis_keepalive_cmplt_type *resp; 710 rndis_keepalive_cmplt_type *resp;
956 rndis_resp_t *r; 711 rndis_resp_t *r;
712 struct rndis_params *params = rndis_per_dev_params + configNr;
957 713
958 /* host "should" check only in RNDIS_DATA_INITIALIZED state */ 714 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
959 715
@@ -968,10 +724,7 @@ static int rndis_keepalive_response (int configNr,
968 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 724 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
969 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); 725 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
970 726
971 if (rndis_per_dev_params [configNr].ack) 727 params->resp_avail(params->v);
972 rndis_per_dev_params [configNr].ack (
973 rndis_per_dev_params [configNr].dev);
974
975 return 0; 728 return 0;
976} 729}
977 730
@@ -983,8 +736,9 @@ static int rndis_indicate_status_msg (int configNr, u32 status)
983{ 736{
984 rndis_indicate_status_msg_type *resp; 737 rndis_indicate_status_msg_type *resp;
985 rndis_resp_t *r; 738 rndis_resp_t *r;
739 struct rndis_params *params = rndis_per_dev_params + configNr;
986 740
987 if (rndis_per_dev_params [configNr].state == RNDIS_UNINITIALIZED) 741 if (params->state == RNDIS_UNINITIALIZED)
988 return -ENOTSUPP; 742 return -ENOTSUPP;
989 743
990 r = rndis_add_response (configNr, 744 r = rndis_add_response (configNr,
@@ -1000,9 +754,7 @@ static int rndis_indicate_status_msg (int configNr, u32 status)
1000 resp->StatusBufferLength = __constant_cpu_to_le32 (0); 754 resp->StatusBufferLength = __constant_cpu_to_le32 (0);
1001 resp->StatusBufferOffset = __constant_cpu_to_le32 (0); 755 resp->StatusBufferOffset = __constant_cpu_to_le32 (0);
1002 756
1003 if (rndis_per_dev_params [configNr].ack) 757 params->resp_avail(params->v);
1004 rndis_per_dev_params [configNr].ack (
1005 rndis_per_dev_params [configNr].dev);
1006 return 0; 758 return 0;
1007} 759}
1008 760
@@ -1029,7 +781,6 @@ void rndis_uninit (int configNr)
1029 781
1030 if (configNr >= RNDIS_MAX_CONFIGS) 782 if (configNr >= RNDIS_MAX_CONFIGS)
1031 return; 783 return;
1032 rndis_per_dev_params [configNr].used = 0;
1033 rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED; 784 rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED;
1034 785
1035 /* drain the response queue */ 786 /* drain the response queue */
@@ -1142,21 +893,25 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1142 return -ENOTSUPP; 893 return -ENOTSUPP;
1143} 894}
1144 895
1145int rndis_register (int (* rndis_control_ack) (struct net_device *)) 896int rndis_register(void (*resp_avail)(void *v), void *v)
1146{ 897{
1147 u8 i; 898 u8 i;
1148 899
900 if (!resp_avail)
901 return -EINVAL;
902
1149 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { 903 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1150 if (!rndis_per_dev_params [i].used) { 904 if (!rndis_per_dev_params [i].used) {
1151 rndis_per_dev_params [i].used = 1; 905 rndis_per_dev_params [i].used = 1;
1152 rndis_per_dev_params [i].ack = rndis_control_ack; 906 rndis_per_dev_params [i].resp_avail = resp_avail;
907 rndis_per_dev_params [i].v = v;
1153 DBG("%s: configNr = %d\n", __func__, i); 908 DBG("%s: configNr = %d\n", __func__, i);
1154 return i; 909 return i;
1155 } 910 }
1156 } 911 }
1157 DBG("failed\n"); 912 DBG("failed\n");
1158 913
1159 return -1; 914 return -ENODEV;
1160} 915}
1161 916
1162void rndis_deregister (int configNr) 917void rndis_deregister (int configNr)
@@ -1169,16 +924,14 @@ void rndis_deregister (int configNr)
1169 return; 924 return;
1170} 925}
1171 926
1172int rndis_set_param_dev (u8 configNr, struct net_device *dev, 927int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter)
1173 struct net_device_stats *stats,
1174 u16 *cdc_filter)
1175{ 928{
1176 DBG("%s:\n", __func__ ); 929 DBG("%s:\n", __func__ );
1177 if (!dev || !stats) return -1; 930 if (!dev)
931 return -EINVAL;
1178 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 932 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1179 933
1180 rndis_per_dev_params [configNr].dev = dev; 934 rndis_per_dev_params [configNr].dev = dev;
1181 rndis_per_dev_params [configNr].stats = stats;
1182 rndis_per_dev_params [configNr].filter = cdc_filter; 935 rndis_per_dev_params [configNr].filter = cdc_filter;
1183 936
1184 return 0; 937 return 0;
@@ -1296,14 +1049,11 @@ int rndis_rm_hdr(struct sk_buff *skb)
1296 1049
1297#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1050#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1298 1051
1299static int rndis_proc_read (char *page, char **start, off_t off, int count, int *eof, 1052static int rndis_proc_show(struct seq_file *m, void *v)
1300 void *data)
1301{ 1053{
1302 char *out = page; 1054 rndis_params *param = m->private;
1303 int len;
1304 rndis_params *param = (rndis_params *) data;
1305 1055
1306 out += snprintf (out, count, 1056 seq_printf(m,
1307 "Config Nr. %d\n" 1057 "Config Nr. %d\n"
1308 "used : %s\n" 1058 "used : %s\n"
1309 "state : %s\n" 1059 "state : %s\n"
@@ -1326,25 +1076,13 @@ static int rndis_proc_read (char *page, char **start, off_t off, int count, int
1326 (param->media_state) ? 0 : param->speed*100, 1076 (param->media_state) ? 0 : param->speed*100,
1327 (param->media_state) ? "disconnected" : "connected", 1077 (param->media_state) ? "disconnected" : "connected",
1328 param->vendorID, param->vendorDescr); 1078 param->vendorID, param->vendorDescr);
1329 1079 return 0;
1330 len = out - page;
1331 len -= off;
1332
1333 if (len < count) {
1334 *eof = 1;
1335 if (len <= 0)
1336 return 0;
1337 } else
1338 len = count;
1339
1340 *start = page + off;
1341 return len;
1342} 1080}
1343 1081
1344static int rndis_proc_write (struct file *file, const char __user *buffer, 1082static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
1345 unsigned long count, void *data) 1083 size_t count, loff_t *ppos)
1346{ 1084{
1347 rndis_params *p = data; 1085 rndis_params *p = PDE(file->f_path.dentry->d_inode)->data;
1348 u32 speed = 0; 1086 u32 speed = 0;
1349 int i, fl_speed = 0; 1087 int i, fl_speed = 0;
1350 1088
@@ -1386,6 +1124,20 @@ static int rndis_proc_write (struct file *file, const char __user *buffer,
1386 return count; 1124 return count;
1387} 1125}
1388 1126
1127static int rndis_proc_open(struct inode *inode, struct file *file)
1128{
1129 return single_open(file, rndis_proc_show, PDE(inode)->data);
1130}
1131
1132static const struct file_operations rndis_proc_fops = {
1133 .owner = THIS_MODULE,
1134 .open = rndis_proc_open,
1135 .read = seq_read,
1136 .llseek = seq_lseek,
1137 .release = single_release,
1138 .write = rndis_proc_write,
1139};
1140
1389#define NAME_TEMPLATE "driver/rndis-%03d" 1141#define NAME_TEMPLATE "driver/rndis-%03d"
1390 1142
1391static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS]; 1143static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
@@ -1403,7 +1155,9 @@ int __init rndis_init (void)
1403 1155
1404 sprintf (name, NAME_TEMPLATE, i); 1156 sprintf (name, NAME_TEMPLATE, i);
1405 if (!(rndis_connect_state [i] 1157 if (!(rndis_connect_state [i]
1406 = create_proc_entry (name, 0660, NULL))) 1158 = proc_create_data(name, 0660, NULL,
1159 &rndis_proc_fops,
1160 (void *)(rndis_per_dev_params + i))))
1407 { 1161 {
1408 DBG("%s :remove entries", __func__); 1162 DBG("%s :remove entries", __func__);
1409 while (i) { 1163 while (i) {
@@ -1413,11 +1167,6 @@ int __init rndis_init (void)
1413 DBG("\n"); 1167 DBG("\n");
1414 return -EIO; 1168 return -EIO;
1415 } 1169 }
1416
1417 rndis_connect_state [i]->write_proc = rndis_proc_write;
1418 rndis_connect_state [i]->read_proc = rndis_proc_read;
1419 rndis_connect_state [i]->data = (void *)
1420 (rndis_per_dev_params + i);
1421#endif 1170#endif
1422 rndis_per_dev_params [i].confignr = i; 1171 rndis_per_dev_params [i].confignr = i;
1423 rndis_per_dev_params [i].used = 0; 1172 rndis_per_dev_params [i].used = 0;
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h
index 397b149f3ca7..aac61dfe0f03 100644
--- a/drivers/usb/gadget/rndis.h
+++ b/drivers/usb/gadget/rndis.h
@@ -1,8 +1,6 @@
1/* 1/*
2 * RNDIS Definitions for Remote NDIS 2 * RNDIS Definitions for Remote NDIS
3 * 3 *
4 * Version: $Id: rndis.h,v 1.15 2004/03/25 21:33:46 robert Exp $
5 *
6 * Authors: Benedikt Spranger, Pengutronix 4 * Authors: Benedikt Spranger, Pengutronix
7 * Robert Schwebel, Pengutronix 5 * Robert Schwebel, Pengutronix
8 * 6 *
@@ -235,20 +233,19 @@ typedef struct rndis_params
235 const u8 *host_mac; 233 const u8 *host_mac;
236 u16 *filter; 234 u16 *filter;
237 struct net_device *dev; 235 struct net_device *dev;
238 struct net_device_stats *stats;
239 236
240 u32 vendorID; 237 u32 vendorID;
241 const char *vendorDescr; 238 const char *vendorDescr;
242 int (*ack) (struct net_device *); 239 void (*resp_avail)(void *v);
240 void *v;
243 struct list_head resp_queue; 241 struct list_head resp_queue;
244} rndis_params; 242} rndis_params;
245 243
246/* RNDIS Message parser and other useless functions */ 244/* RNDIS Message parser and other useless functions */
247int rndis_msg_parser (u8 configNr, u8 *buf); 245int rndis_msg_parser (u8 configNr, u8 *buf);
248int rndis_register (int (*rndis_control_ack) (struct net_device *)); 246int rndis_register(void (*resp_avail)(void *v), void *v);
249void rndis_deregister (int configNr); 247void rndis_deregister (int configNr);
250int rndis_set_param_dev (u8 configNr, struct net_device *dev, 248int rndis_set_param_dev (u8 configNr, struct net_device *dev,
251 struct net_device_stats *stats,
252 u16 *cdc_filter); 249 u16 *cdc_filter);
253int rndis_set_param_vendor (u8 configNr, u32 vendorID, 250int rndis_set_param_vendor (u8 configNr, u32 vendorID,
254 const char *vendorDescr); 251 const char *vendorDescr);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index fa019fa73334..b3699afff002 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -1,15 +1,9 @@
1/* 1/*
2 * g_serial.c -- USB gadget serial driver 2 * serial.c -- USB gadget serial driver
3 * 3 *
4 * Copyright 2003 (C) Al Borchers (alborchers@steinerpoint.com) 4 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
5 * 5 * Copyright (C) 2008 by David Brownell
6 * This code is based in part on the Gadget Zero driver, which 6 * Copyright (C) 2008 by Nokia Corporation
7 * is Copyright (C) 2003 by David Brownell, all rights reserved.
8 *
9 * This code also borrows from usbserial.c, which is
10 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
11 * Copyright (C) 2000 Peter Berger (pberger@brimson.com)
12 * Copyright (C) 2000 Al Borchers (alborchers@steinerpoint.com)
13 * 7 *
14 * This software is distributed under the terms of the GNU General 8 * This software is distributed under the terms of the GNU General
15 * Public License ("GPL") as published by the Free Software Foundation, 9 * Public License ("GPL") as published by the Free Software Foundation,
@@ -22,2254 +16,237 @@
22#include <linux/tty.h> 16#include <linux/tty.h>
23#include <linux/tty_flip.h> 17#include <linux/tty_flip.h>
24 18
25#include <linux/usb/ch9.h> 19#include "u_serial.h"
26#include <linux/usb/cdc.h>
27#include <linux/usb/gadget.h>
28
29#include "gadget_chips.h" 20#include "gadget_chips.h"
30 21
31 22
32/* Defines */ 23/* Defines */
33 24
34#define GS_VERSION_STR "v2.2" 25#define GS_VERSION_STR "v2.4"
35#define GS_VERSION_NUM 0x2200 26#define GS_VERSION_NUM 0x2400
36 27
37#define GS_LONG_NAME "Gadget Serial" 28#define GS_LONG_NAME "Gadget Serial"
38#define GS_SHORT_NAME "g_serial" 29#define GS_VERSION_NAME GS_LONG_NAME " " GS_VERSION_STR
39
40#define GS_MAJOR 127
41#define GS_MINOR_START 0
42
43/* REVISIT only one port is supported for now;
44 * see gs_{send,recv}_packet() ... no multiplexing,
45 * and no support for multiple ACM devices.
46 */
47#define GS_NUM_PORTS 1
48
49#define GS_NUM_CONFIGS 1
50#define GS_NO_CONFIG_ID 0
51#define GS_BULK_CONFIG_ID 1
52#define GS_ACM_CONFIG_ID 2
53
54#define GS_MAX_NUM_INTERFACES 2
55#define GS_BULK_INTERFACE_ID 0
56#define GS_CONTROL_INTERFACE_ID 0
57#define GS_DATA_INTERFACE_ID 1
58
59#define GS_MAX_DESC_LEN 256
60
61#define GS_DEFAULT_READ_Q_SIZE 32
62#define GS_DEFAULT_WRITE_Q_SIZE 32
63
64#define GS_DEFAULT_WRITE_BUF_SIZE 8192
65#define GS_TMP_BUF_SIZE 8192
66
67#define GS_CLOSE_TIMEOUT 15
68
69#define GS_DEFAULT_USE_ACM 0
70
71/* 9600-8-N-1 ... matches init_termios.c_cflag and defaults
72 * expected by "usbser.sys" on MS-Windows.
73 */
74#define GS_DEFAULT_DTE_RATE 9600
75#define GS_DEFAULT_DATA_BITS 8
76#define GS_DEFAULT_PARITY USB_CDC_NO_PARITY
77#define GS_DEFAULT_CHAR_FORMAT USB_CDC_1_STOP_BITS
78
79/* maxpacket and other transfer characteristics vary by speed. */
80static inline struct usb_endpoint_descriptor *
81choose_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
82 struct usb_endpoint_descriptor *fs)
83{
84 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
85 return hs;
86 return fs;
87}
88
89
90/* debug settings */
91#ifdef DEBUG
92static int debug = 1;
93#else
94#define debug 0
95#endif
96
97#define gs_debug(format, arg...) \
98 do { if (debug) pr_debug(format, ## arg); } while (0)
99#define gs_debug_level(level, format, arg...) \
100 do { if (debug >= level) pr_debug(format, ## arg); } while (0)
101 30
31/*-------------------------------------------------------------------------*/
102 32
103/* Thanks to NetChip Technologies for donating this product ID. 33/* Thanks to NetChip Technologies for donating this product ID.
104 * 34*
105 * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! 35* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
106 * Instead: allocate your own, using normal USB-IF procedures. 36* Instead: allocate your own, using normal USB-IF procedures.
107 */ 37*/
108#define GS_VENDOR_ID 0x0525 /* NetChip */ 38#define GS_VENDOR_ID 0x0525 /* NetChip */
109#define GS_PRODUCT_ID 0xa4a6 /* Linux-USB Serial Gadget */ 39#define GS_PRODUCT_ID 0xa4a6 /* Linux-USB Serial Gadget */
110#define GS_CDC_PRODUCT_ID 0xa4a7 /* ... as CDC-ACM */ 40#define GS_CDC_PRODUCT_ID 0xa4a7 /* ... as CDC-ACM */
111 41
112#define GS_LOG2_NOTIFY_INTERVAL 5 /* 1 << 5 == 32 msec */ 42/* string IDs are assigned dynamically */
113#define GS_NOTIFY_MAXPACKET 8
114 43
44#define STRING_MANUFACTURER_IDX 0
45#define STRING_PRODUCT_IDX 1
46#define STRING_DESCRIPTION_IDX 2
115 47
116/* circular buffer */ 48static char manufacturer[50];
117struct gs_buf {
118 unsigned int buf_size;
119 char *buf_buf;
120 char *buf_get;
121 char *buf_put;
122};
123 49
124/* the port structure holds info for each port, one for each minor number */ 50static struct usb_string strings_dev[] = {
125struct gs_port { 51 [STRING_MANUFACTURER_IDX].s = manufacturer,
126 struct gs_dev *port_dev; /* pointer to device struct */ 52 [STRING_PRODUCT_IDX].s = GS_VERSION_NAME,
127 struct tty_struct *port_tty; /* pointer to tty struct */ 53 [STRING_DESCRIPTION_IDX].s = NULL /* updated; f(use_acm) */,
128 spinlock_t port_lock; 54 { } /* end of list */
129 int port_num;
130 int port_open_count;
131 int port_in_use; /* open/close in progress */
132 wait_queue_head_t port_write_wait;/* waiting to write */
133 struct gs_buf *port_write_buf;
134 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
135 u16 port_handshake_bits;
136#define RS232_RTS (1 << 1)
137#define RS232_DTE (1 << 0)
138}; 55};
139 56
140/* the device structure holds info for the USB device */ 57static struct usb_gadget_strings stringtab_dev = {
141struct gs_dev { 58 .language = 0x0409, /* en-us */
142 struct usb_gadget *dev_gadget; /* gadget device pointer */ 59 .strings = strings_dev,
143 spinlock_t dev_lock; /* lock for set/reset config */
144 int dev_config; /* configuration number */
145 struct usb_ep *dev_notify_ep; /* address of notify endpoint */
146 struct usb_ep *dev_in_ep; /* address of in endpoint */
147 struct usb_ep *dev_out_ep; /* address of out endpoint */
148 struct usb_endpoint_descriptor /* descriptor of notify ep */
149 *dev_notify_ep_desc;
150 struct usb_endpoint_descriptor /* descriptor of in endpoint */
151 *dev_in_ep_desc;
152 struct usb_endpoint_descriptor /* descriptor of out endpoint */
153 *dev_out_ep_desc;
154 struct usb_request *dev_ctrl_req; /* control request */
155 struct list_head dev_req_list; /* list of write requests */
156 int dev_sched_port; /* round robin port scheduled */
157 struct gs_port *dev_port[GS_NUM_PORTS]; /* the ports */
158}; 60};
159 61
160 62static struct usb_gadget_strings *dev_strings[] = {
161/* Functions */ 63 &stringtab_dev,
162 64 NULL,
163/* tty driver internals */
164static int gs_send(struct gs_dev *dev);
165static int gs_send_packet(struct gs_dev *dev, char *packet,
166 unsigned int size);
167static int gs_recv_packet(struct gs_dev *dev, char *packet,
168 unsigned int size);
169static void gs_read_complete(struct usb_ep *ep, struct usb_request *req);
170static void gs_write_complete(struct usb_ep *ep, struct usb_request *req);
171
172/* gadget driver internals */
173static int gs_set_config(struct gs_dev *dev, unsigned config);
174static void gs_reset_config(struct gs_dev *dev);
175static int gs_build_config_buf(u8 *buf, struct usb_gadget *g,
176 u8 type, unsigned int index, int is_otg);
177
178static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
179 gfp_t kmalloc_flags);
180static void gs_free_req(struct usb_ep *ep, struct usb_request *req);
181
182static int gs_alloc_ports(struct gs_dev *dev, gfp_t kmalloc_flags);
183static void gs_free_ports(struct gs_dev *dev);
184
185/* circular buffer */
186static struct gs_buf *gs_buf_alloc(unsigned int size, gfp_t kmalloc_flags);
187static void gs_buf_free(struct gs_buf *gb);
188static void gs_buf_clear(struct gs_buf *gb);
189static unsigned int gs_buf_data_avail(struct gs_buf *gb);
190static unsigned int gs_buf_space_avail(struct gs_buf *gb);
191static unsigned int gs_buf_put(struct gs_buf *gb, const char *buf,
192 unsigned int count);
193static unsigned int gs_buf_get(struct gs_buf *gb, char *buf,
194 unsigned int count);
195
196
197/* Globals */
198
199static struct gs_dev *gs_device;
200
201static struct mutex gs_open_close_lock[GS_NUM_PORTS];
202
203
204/*-------------------------------------------------------------------------*/
205
206/* USB descriptors */
207
208#define GS_MANUFACTURER_STR_ID 1
209#define GS_PRODUCT_STR_ID 2
210#define GS_SERIAL_STR_ID 3
211#define GS_BULK_CONFIG_STR_ID 4
212#define GS_ACM_CONFIG_STR_ID 5
213#define GS_CONTROL_STR_ID 6
214#define GS_DATA_STR_ID 7
215
216/* static strings, in UTF-8 */
217static char manufacturer[50];
218static struct usb_string gs_strings[] = {
219 { GS_MANUFACTURER_STR_ID, manufacturer },
220 { GS_PRODUCT_STR_ID, GS_LONG_NAME },
221 { GS_BULK_CONFIG_STR_ID, "Gadget Serial Bulk" },
222 { GS_ACM_CONFIG_STR_ID, "Gadget Serial CDC ACM" },
223 { GS_CONTROL_STR_ID, "Gadget Serial Control" },
224 { GS_DATA_STR_ID, "Gadget Serial Data" },
225 { } /* end of list */
226};
227
228static struct usb_gadget_strings gs_string_table = {
229 .language = 0x0409, /* en-us */
230 .strings = gs_strings,
231}; 65};
232 66
233static struct usb_device_descriptor gs_device_desc = { 67static struct usb_device_descriptor device_desc = {
234 .bLength = USB_DT_DEVICE_SIZE, 68 .bLength = USB_DT_DEVICE_SIZE,
235 .bDescriptorType = USB_DT_DEVICE, 69 .bDescriptorType = USB_DT_DEVICE,
236 .bcdUSB = __constant_cpu_to_le16(0x0200), 70 .bcdUSB = __constant_cpu_to_le16(0x0200),
71 /* .bDeviceClass = f(use_acm) */
237 .bDeviceSubClass = 0, 72 .bDeviceSubClass = 0,
238 .bDeviceProtocol = 0, 73 .bDeviceProtocol = 0,
74 /* .bMaxPacketSize0 = f(hardware) */
239 .idVendor = __constant_cpu_to_le16(GS_VENDOR_ID), 75 .idVendor = __constant_cpu_to_le16(GS_VENDOR_ID),
240 .idProduct = __constant_cpu_to_le16(GS_PRODUCT_ID), 76 /* .idProduct = f(use_acm) */
241 .iManufacturer = GS_MANUFACTURER_STR_ID, 77 /* .bcdDevice = f(hardware) */
242 .iProduct = GS_PRODUCT_STR_ID, 78 /* .iManufacturer = DYNAMIC */
243 .bNumConfigurations = GS_NUM_CONFIGS, 79 /* .iProduct = DYNAMIC */
80 .bNumConfigurations = 1,
244}; 81};
245 82
246static struct usb_otg_descriptor gs_otg_descriptor = { 83static struct usb_otg_descriptor otg_descriptor = {
247 .bLength = sizeof(gs_otg_descriptor), 84 .bLength = sizeof otg_descriptor,
248 .bDescriptorType = USB_DT_OTG, 85 .bDescriptorType = USB_DT_OTG,
249 .bmAttributes = USB_OTG_SRP,
250};
251
252static struct usb_config_descriptor gs_bulk_config_desc = {
253 .bLength = USB_DT_CONFIG_SIZE,
254 .bDescriptorType = USB_DT_CONFIG,
255 /* .wTotalLength computed dynamically */
256 .bNumInterfaces = 1,
257 .bConfigurationValue = GS_BULK_CONFIG_ID,
258 .iConfiguration = GS_BULK_CONFIG_STR_ID,
259 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
260 .bMaxPower = 1,
261};
262
263static struct usb_config_descriptor gs_acm_config_desc = {
264 .bLength = USB_DT_CONFIG_SIZE,
265 .bDescriptorType = USB_DT_CONFIG,
266 /* .wTotalLength computed dynamically */
267 .bNumInterfaces = 2,
268 .bConfigurationValue = GS_ACM_CONFIG_ID,
269 .iConfiguration = GS_ACM_CONFIG_STR_ID,
270 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
271 .bMaxPower = 1,
272};
273
274static const struct usb_interface_descriptor gs_bulk_interface_desc = {
275 .bLength = USB_DT_INTERFACE_SIZE,
276 .bDescriptorType = USB_DT_INTERFACE,
277 .bInterfaceNumber = GS_BULK_INTERFACE_ID,
278 .bNumEndpoints = 2,
279 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
280 .bInterfaceSubClass = 0,
281 .bInterfaceProtocol = 0,
282 .iInterface = GS_DATA_STR_ID,
283};
284
285static const struct usb_interface_descriptor gs_control_interface_desc = {
286 .bLength = USB_DT_INTERFACE_SIZE,
287 .bDescriptorType = USB_DT_INTERFACE,
288 .bInterfaceNumber = GS_CONTROL_INTERFACE_ID,
289 .bNumEndpoints = 1,
290 .bInterfaceClass = USB_CLASS_COMM,
291 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
292 .bInterfaceProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
293 .iInterface = GS_CONTROL_STR_ID,
294};
295
296static const struct usb_interface_descriptor gs_data_interface_desc = {
297 .bLength = USB_DT_INTERFACE_SIZE,
298 .bDescriptorType = USB_DT_INTERFACE,
299 .bInterfaceNumber = GS_DATA_INTERFACE_ID,
300 .bNumEndpoints = 2,
301 .bInterfaceClass = USB_CLASS_CDC_DATA,
302 .bInterfaceSubClass = 0,
303 .bInterfaceProtocol = 0,
304 .iInterface = GS_DATA_STR_ID,
305};
306
307static const struct usb_cdc_header_desc gs_header_desc = {
308 .bLength = sizeof(gs_header_desc),
309 .bDescriptorType = USB_DT_CS_INTERFACE,
310 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
311 .bcdCDC = __constant_cpu_to_le16(0x0110),
312};
313
314static const struct usb_cdc_call_mgmt_descriptor gs_call_mgmt_descriptor = {
315 .bLength = sizeof(gs_call_mgmt_descriptor),
316 .bDescriptorType = USB_DT_CS_INTERFACE,
317 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
318 .bmCapabilities = 0,
319 .bDataInterface = 1, /* index of data interface */
320};
321
322static struct usb_cdc_acm_descriptor gs_acm_descriptor = {
323 .bLength = sizeof(gs_acm_descriptor),
324 .bDescriptorType = USB_DT_CS_INTERFACE,
325 .bDescriptorSubType = USB_CDC_ACM_TYPE,
326 .bmCapabilities = (1 << 1),
327};
328
329static const struct usb_cdc_union_desc gs_union_desc = {
330 .bLength = sizeof(gs_union_desc),
331 .bDescriptorType = USB_DT_CS_INTERFACE,
332 .bDescriptorSubType = USB_CDC_UNION_TYPE,
333 .bMasterInterface0 = 0, /* index of control interface */
334 .bSlaveInterface0 = 1, /* index of data interface */
335};
336
337static struct usb_endpoint_descriptor gs_fullspeed_notify_desc = {
338 .bLength = USB_DT_ENDPOINT_SIZE,
339 .bDescriptorType = USB_DT_ENDPOINT,
340 .bEndpointAddress = USB_DIR_IN,
341 .bmAttributes = USB_ENDPOINT_XFER_INT,
342 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET),
343 .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL,
344};
345
346static struct usb_endpoint_descriptor gs_fullspeed_in_desc = {
347 .bLength = USB_DT_ENDPOINT_SIZE,
348 .bDescriptorType = USB_DT_ENDPOINT,
349 .bEndpointAddress = USB_DIR_IN,
350 .bmAttributes = USB_ENDPOINT_XFER_BULK,
351};
352
353static struct usb_endpoint_descriptor gs_fullspeed_out_desc = {
354 .bLength = USB_DT_ENDPOINT_SIZE,
355 .bDescriptorType = USB_DT_ENDPOINT,
356 .bEndpointAddress = USB_DIR_OUT,
357 .bmAttributes = USB_ENDPOINT_XFER_BULK,
358};
359
360static const struct usb_descriptor_header *gs_bulk_fullspeed_function[] = {
361 (struct usb_descriptor_header *) &gs_otg_descriptor,
362 (struct usb_descriptor_header *) &gs_bulk_interface_desc,
363 (struct usb_descriptor_header *) &gs_fullspeed_in_desc,
364 (struct usb_descriptor_header *) &gs_fullspeed_out_desc,
365 NULL,
366};
367
368static const struct usb_descriptor_header *gs_acm_fullspeed_function[] = {
369 (struct usb_descriptor_header *) &gs_otg_descriptor,
370 (struct usb_descriptor_header *) &gs_control_interface_desc,
371 (struct usb_descriptor_header *) &gs_header_desc,
372 (struct usb_descriptor_header *) &gs_call_mgmt_descriptor,
373 (struct usb_descriptor_header *) &gs_acm_descriptor,
374 (struct usb_descriptor_header *) &gs_union_desc,
375 (struct usb_descriptor_header *) &gs_fullspeed_notify_desc,
376 (struct usb_descriptor_header *) &gs_data_interface_desc,
377 (struct usb_descriptor_header *) &gs_fullspeed_in_desc,
378 (struct usb_descriptor_header *) &gs_fullspeed_out_desc,
379 NULL,
380};
381 86
382static struct usb_endpoint_descriptor gs_highspeed_notify_desc = { 87 /* REVISIT SRP-only hardware is possible, although
383 .bLength = USB_DT_ENDPOINT_SIZE, 88 * it would not be called "OTG" ...
384 .bDescriptorType = USB_DT_ENDPOINT, 89 */
385 .bEndpointAddress = USB_DIR_IN, 90 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
386 .bmAttributes = USB_ENDPOINT_XFER_INT,
387 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET),
388 .bInterval = GS_LOG2_NOTIFY_INTERVAL+4,
389};
390
391static struct usb_endpoint_descriptor gs_highspeed_in_desc = {
392 .bLength = USB_DT_ENDPOINT_SIZE,
393 .bDescriptorType = USB_DT_ENDPOINT,
394 .bmAttributes = USB_ENDPOINT_XFER_BULK,
395 .wMaxPacketSize = __constant_cpu_to_le16(512),
396};
397
398static struct usb_endpoint_descriptor gs_highspeed_out_desc = {
399 .bLength = USB_DT_ENDPOINT_SIZE,
400 .bDescriptorType = USB_DT_ENDPOINT,
401 .bmAttributes = USB_ENDPOINT_XFER_BULK,
402 .wMaxPacketSize = __constant_cpu_to_le16(512),
403};
404
405static struct usb_qualifier_descriptor gs_qualifier_desc = {
406 .bLength = sizeof(struct usb_qualifier_descriptor),
407 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
408 .bcdUSB = __constant_cpu_to_le16 (0x0200),
409 /* assumes ep0 uses the same value for both speeds ... */
410 .bNumConfigurations = GS_NUM_CONFIGS,
411};
412
413static const struct usb_descriptor_header *gs_bulk_highspeed_function[] = {
414 (struct usb_descriptor_header *) &gs_otg_descriptor,
415 (struct usb_descriptor_header *) &gs_bulk_interface_desc,
416 (struct usb_descriptor_header *) &gs_highspeed_in_desc,
417 (struct usb_descriptor_header *) &gs_highspeed_out_desc,
418 NULL,
419}; 91};
420 92
421static const struct usb_descriptor_header *gs_acm_highspeed_function[] = { 93static const struct usb_descriptor_header *otg_desc[] = {
422 (struct usb_descriptor_header *) &gs_otg_descriptor, 94 (struct usb_descriptor_header *) &otg_descriptor,
423 (struct usb_descriptor_header *) &gs_control_interface_desc,
424 (struct usb_descriptor_header *) &gs_header_desc,
425 (struct usb_descriptor_header *) &gs_call_mgmt_descriptor,
426 (struct usb_descriptor_header *) &gs_acm_descriptor,
427 (struct usb_descriptor_header *) &gs_union_desc,
428 (struct usb_descriptor_header *) &gs_highspeed_notify_desc,
429 (struct usb_descriptor_header *) &gs_data_interface_desc,
430 (struct usb_descriptor_header *) &gs_highspeed_in_desc,
431 (struct usb_descriptor_header *) &gs_highspeed_out_desc,
432 NULL, 95 NULL,
433}; 96};
434 97
435
436/*-------------------------------------------------------------------------*/ 98/*-------------------------------------------------------------------------*/
437 99
438/* Module */ 100/* Module */
439MODULE_DESCRIPTION(GS_LONG_NAME); 101MODULE_DESCRIPTION(GS_VERSION_NAME);
440MODULE_AUTHOR("Al Borchers"); 102MODULE_AUTHOR("Al Borchers");
103MODULE_AUTHOR("David Brownell");
441MODULE_LICENSE("GPL"); 104MODULE_LICENSE("GPL");
442 105
443#ifdef DEBUG 106static int use_acm = true;
444module_param(debug, int, S_IRUGO|S_IWUSR); 107module_param(use_acm, bool, 0);
445MODULE_PARM_DESC(debug, "Enable debugging, 0=off, 1=on"); 108MODULE_PARM_DESC(use_acm, "Use CDC ACM, default=yes");
446#endif
447
448static unsigned int read_q_size = GS_DEFAULT_READ_Q_SIZE;
449module_param(read_q_size, uint, S_IRUGO);
450MODULE_PARM_DESC(read_q_size, "Read request queue size, default=32");
451
452static unsigned int write_q_size = GS_DEFAULT_WRITE_Q_SIZE;
453module_param(write_q_size, uint, S_IRUGO);
454MODULE_PARM_DESC(write_q_size, "Write request queue size, default=32");
455 109
456static unsigned int write_buf_size = GS_DEFAULT_WRITE_BUF_SIZE; 110static unsigned n_ports = 1;
457module_param(write_buf_size, uint, S_IRUGO); 111module_param(n_ports, uint, 0);
458MODULE_PARM_DESC(write_buf_size, "Write buffer size, default=8192"); 112MODULE_PARM_DESC(n_ports, "number of ports to create, default=1");
459
460static unsigned int use_acm = GS_DEFAULT_USE_ACM;
461module_param(use_acm, uint, S_IRUGO);
462MODULE_PARM_DESC(use_acm, "Use CDC ACM, 0=no, 1=yes, default=no");
463 113
464/*-------------------------------------------------------------------------*/ 114/*-------------------------------------------------------------------------*/
465 115
466/* TTY Driver */ 116static int __init serial_bind_config(struct usb_configuration *c)
467
468/*
469 * gs_open
470 */
471static int gs_open(struct tty_struct *tty, struct file *file)
472{
473 int port_num;
474 unsigned long flags;
475 struct gs_port *port;
476 struct gs_dev *dev;
477 struct gs_buf *buf;
478 struct mutex *mtx;
479 int ret;
480
481 port_num = tty->index;
482
483 gs_debug("gs_open: (%d,%p,%p)\n", port_num, tty, file);
484
485 if (port_num < 0 || port_num >= GS_NUM_PORTS) {
486 pr_err("gs_open: (%d,%p,%p) invalid port number\n",
487 port_num, tty, file);
488 return -ENODEV;
489 }
490
491 dev = gs_device;
492
493 if (dev == NULL) {
494 pr_err("gs_open: (%d,%p,%p) NULL device pointer\n",
495 port_num, tty, file);
496 return -ENODEV;
497 }
498
499 mtx = &gs_open_close_lock[port_num];
500 if (mutex_lock_interruptible(mtx)) {
501 pr_err("gs_open: (%d,%p,%p) interrupted waiting for mutex\n",
502 port_num, tty, file);
503 return -ERESTARTSYS;
504 }
505
506 spin_lock_irqsave(&dev->dev_lock, flags);
507
508 if (dev->dev_config == GS_NO_CONFIG_ID) {
509 pr_err("gs_open: (%d,%p,%p) device is not connected\n",
510 port_num, tty, file);
511 ret = -ENODEV;
512 goto exit_unlock_dev;
513 }
514
515 port = dev->dev_port[port_num];
516
517 if (port == NULL) {
518 pr_err("gs_open: (%d,%p,%p) NULL port pointer\n",
519 port_num, tty, file);
520 ret = -ENODEV;
521 goto exit_unlock_dev;
522 }
523
524 spin_lock(&port->port_lock);
525 spin_unlock(&dev->dev_lock);
526
527 if (port->port_dev == NULL) {
528 pr_err("gs_open: (%d,%p,%p) port disconnected (1)\n",
529 port_num, tty, file);
530 ret = -EIO;
531 goto exit_unlock_port;
532 }
533
534 if (port->port_open_count > 0) {
535 ++port->port_open_count;
536 gs_debug("gs_open: (%d,%p,%p) already open\n",
537 port_num, tty, file);
538 ret = 0;
539 goto exit_unlock_port;
540 }
541
542 tty->driver_data = NULL;
543
544 /* mark port as in use, we can drop port lock and sleep if necessary */
545 port->port_in_use = 1;
546
547 /* allocate write buffer on first open */
548 if (port->port_write_buf == NULL) {
549 spin_unlock_irqrestore(&port->port_lock, flags);
550 buf = gs_buf_alloc(write_buf_size, GFP_KERNEL);
551 spin_lock_irqsave(&port->port_lock, flags);
552
553 /* might have been disconnected while asleep, check */
554 if (port->port_dev == NULL) {
555 pr_err("gs_open: (%d,%p,%p) port disconnected (2)\n",
556 port_num, tty, file);
557 port->port_in_use = 0;
558 ret = -EIO;
559 goto exit_unlock_port;
560 }
561
562 if ((port->port_write_buf=buf) == NULL) {
563 pr_err("gs_open: (%d,%p,%p) cannot allocate "
564 "port write buffer\n",
565 port_num, tty, file);
566 port->port_in_use = 0;
567 ret = -ENOMEM;
568 goto exit_unlock_port;
569 }
570
571 }
572
573 /* wait for carrier detect (not implemented) */
574
575 /* might have been disconnected while asleep, check */
576 if (port->port_dev == NULL) {
577 pr_err("gs_open: (%d,%p,%p) port disconnected (3)\n",
578 port_num, tty, file);
579 port->port_in_use = 0;
580 ret = -EIO;
581 goto exit_unlock_port;
582 }
583
584 tty->driver_data = port;
585 port->port_tty = tty;
586 port->port_open_count = 1;
587 port->port_in_use = 0;
588
589 gs_debug("gs_open: (%d,%p,%p) completed\n", port_num, tty, file);
590
591 ret = 0;
592
593exit_unlock_port:
594 spin_unlock_irqrestore(&port->port_lock, flags);
595 mutex_unlock(mtx);
596 return ret;
597
598exit_unlock_dev:
599 spin_unlock_irqrestore(&dev->dev_lock, flags);
600 mutex_unlock(mtx);
601 return ret;
602
603}
604
605/*
606 * gs_close
607 */
608
609static int gs_write_finished_event_safely(struct gs_port *p)
610{
611 int cond;
612
613 spin_lock_irq(&(p)->port_lock);
614 cond = !(p)->port_dev || !gs_buf_data_avail((p)->port_write_buf);
615 spin_unlock_irq(&(p)->port_lock);
616 return cond;
617}
618
619static void gs_close(struct tty_struct *tty, struct file *file)
620{
621 struct gs_port *port = tty->driver_data;
622 struct mutex *mtx;
623
624 if (port == NULL) {
625 pr_err("gs_close: NULL port pointer\n");
626 return;
627 }
628
629 gs_debug("gs_close: (%d,%p,%p)\n", port->port_num, tty, file);
630
631 mtx = &gs_open_close_lock[port->port_num];
632 mutex_lock(mtx);
633
634 spin_lock_irq(&port->port_lock);
635
636 if (port->port_open_count == 0) {
637 pr_err("gs_close: (%d,%p,%p) port is already closed\n",
638 port->port_num, tty, file);
639 goto exit;
640 }
641
642 if (port->port_open_count > 1) {
643 --port->port_open_count;
644 goto exit;
645 }
646
647 /* free disconnected port on final close */
648 if (port->port_dev == NULL) {
649 kfree(port);
650 goto exit;
651 }
652
653 /* mark port as closed but in use, we can drop port lock */
654 /* and sleep if necessary */
655 port->port_in_use = 1;
656 port->port_open_count = 0;
657
658 /* wait for write buffer to drain, or */
659 /* at most GS_CLOSE_TIMEOUT seconds */
660 if (gs_buf_data_avail(port->port_write_buf) > 0) {
661 spin_unlock_irq(&port->port_lock);
662 wait_event_interruptible_timeout(port->port_write_wait,
663 gs_write_finished_event_safely(port),
664 GS_CLOSE_TIMEOUT * HZ);
665 spin_lock_irq(&port->port_lock);
666 }
667
668 /* free disconnected port on final close */
669 /* (might have happened during the above sleep) */
670 if (port->port_dev == NULL) {
671 kfree(port);
672 goto exit;
673 }
674
675 gs_buf_clear(port->port_write_buf);
676
677 tty->driver_data = NULL;
678 port->port_tty = NULL;
679 port->port_in_use = 0;
680
681 gs_debug("gs_close: (%d,%p,%p) completed\n",
682 port->port_num, tty, file);
683
684exit:
685 spin_unlock_irq(&port->port_lock);
686 mutex_unlock(mtx);
687}
688
689/*
690 * gs_write
691 */
692static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count)
693{ 117{
694 unsigned long flags; 118 unsigned i;
695 struct gs_port *port = tty->driver_data; 119 int status = 0;
696 int ret;
697
698 if (port == NULL) {
699 pr_err("gs_write: NULL port pointer\n");
700 return -EIO;
701 }
702
703 gs_debug("gs_write: (%d,%p) writing %d bytes\n", port->port_num, tty,
704 count);
705
706 if (count == 0)
707 return 0;
708
709 spin_lock_irqsave(&port->port_lock, flags);
710
711 if (port->port_dev == NULL) {
712 pr_err("gs_write: (%d,%p) port is not connected\n",
713 port->port_num, tty);
714 ret = -EIO;
715 goto exit;
716 }
717
718 if (port->port_open_count == 0) {
719 pr_err("gs_write: (%d,%p) port is closed\n",
720 port->port_num, tty);
721 ret = -EBADF;
722 goto exit;
723 }
724
725 count = gs_buf_put(port->port_write_buf, buf, count);
726
727 spin_unlock_irqrestore(&port->port_lock, flags);
728
729 gs_send(gs_device);
730
731 gs_debug("gs_write: (%d,%p) wrote %d bytes\n", port->port_num, tty,
732 count);
733 120
734 return count; 121 for (i = 0; i < n_ports && status == 0; i++) {
735 122 if (use_acm)
736exit: 123 status = acm_bind_config(c, i);
737 spin_unlock_irqrestore(&port->port_lock, flags); 124 else
738 return ret; 125 status = gser_bind_config(c, i);
739}
740
741/*
742 * gs_put_char
743 */
744static int gs_put_char(struct tty_struct *tty, unsigned char ch)
745{
746 unsigned long flags;
747 struct gs_port *port = tty->driver_data;
748 int ret = 0;
749
750 if (port == NULL) {
751 pr_err("gs_put_char: NULL port pointer\n");
752 return 0;
753 }
754
755 gs_debug("gs_put_char: (%d,%p) char=0x%x, called from %p\n",
756 port->port_num, tty, ch, __builtin_return_address(0));
757
758 spin_lock_irqsave(&port->port_lock, flags);
759
760 if (port->port_dev == NULL) {
761 pr_err("gs_put_char: (%d,%p) port is not connected\n",
762 port->port_num, tty);
763 goto exit;
764 }
765
766 if (port->port_open_count == 0) {
767 pr_err("gs_put_char: (%d,%p) port is closed\n",
768 port->port_num, tty);
769 goto exit;
770 }
771
772 ret = gs_buf_put(port->port_write_buf, &ch, 1);
773
774exit:
775 spin_unlock_irqrestore(&port->port_lock, flags);
776 return ret;
777}
778
779/*
780 * gs_flush_chars
781 */
782static void gs_flush_chars(struct tty_struct *tty)
783{
784 unsigned long flags;
785 struct gs_port *port = tty->driver_data;
786
787 if (port == NULL) {
788 pr_err("gs_flush_chars: NULL port pointer\n");
789 return;
790 }
791
792 gs_debug("gs_flush_chars: (%d,%p)\n", port->port_num, tty);
793
794 spin_lock_irqsave(&port->port_lock, flags);
795
796 if (port->port_dev == NULL) {
797 pr_err("gs_flush_chars: (%d,%p) port is not connected\n",
798 port->port_num, tty);
799 goto exit;
800 }
801
802 if (port->port_open_count == 0) {
803 pr_err("gs_flush_chars: (%d,%p) port is closed\n",
804 port->port_num, tty);
805 goto exit;
806 }
807
808 spin_unlock_irqrestore(&port->port_lock, flags);
809
810 gs_send(gs_device);
811
812 return;
813
814exit:
815 spin_unlock_irqrestore(&port->port_lock, flags);
816}
817
818/*
819 * gs_write_room
820 */
821static int gs_write_room(struct tty_struct *tty)
822{
823
824 int room = 0;
825 unsigned long flags;
826 struct gs_port *port = tty->driver_data;
827
828
829 if (port == NULL)
830 return 0;
831
832 spin_lock_irqsave(&port->port_lock, flags);
833
834 if (port->port_dev != NULL && port->port_open_count > 0
835 && port->port_write_buf != NULL)
836 room = gs_buf_space_avail(port->port_write_buf);
837
838 spin_unlock_irqrestore(&port->port_lock, flags);
839
840 gs_debug("gs_write_room: (%d,%p) room=%d\n",
841 port->port_num, tty, room);
842
843 return room;
844}
845
846/*
847 * gs_chars_in_buffer
848 */
849static int gs_chars_in_buffer(struct tty_struct *tty)
850{
851 int chars = 0;
852 unsigned long flags;
853 struct gs_port *port = tty->driver_data;
854
855 if (port == NULL)
856 return 0;
857
858 spin_lock_irqsave(&port->port_lock, flags);
859
860 if (port->port_dev != NULL && port->port_open_count > 0
861 && port->port_write_buf != NULL)
862 chars = gs_buf_data_avail(port->port_write_buf);
863
864 spin_unlock_irqrestore(&port->port_lock, flags);
865
866 gs_debug("gs_chars_in_buffer: (%d,%p) chars=%d\n",
867 port->port_num, tty, chars);
868
869 return chars;
870}
871
872/*
873 * gs_throttle
874 */
875static void gs_throttle(struct tty_struct *tty)
876{
877}
878
879/*
880 * gs_unthrottle
881 */
882static void gs_unthrottle(struct tty_struct *tty)
883{
884}
885
886/*
887 * gs_break
888 */
889static void gs_break(struct tty_struct *tty, int break_state)
890{
891}
892
893/*
894 * gs_ioctl
895 */
896static int gs_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
897{
898 struct gs_port *port = tty->driver_data;
899
900 if (port == NULL) {
901 pr_err("gs_ioctl: NULL port pointer\n");
902 return -EIO;
903 } 126 }
904 127 return status;
905 gs_debug("gs_ioctl: (%d,%p,%p) cmd=0x%4.4x, arg=%lu\n",
906 port->port_num, tty, file, cmd, arg);
907
908 /* handle ioctls */
909
910 /* could not handle ioctl */
911 return -ENOIOCTLCMD;
912}
913
914/*
915 * gs_set_termios
916 */
917static void gs_set_termios(struct tty_struct *tty, struct ktermios *old)
918{
919} 128}
920 129
921static const struct tty_operations gs_tty_ops = { 130static struct usb_configuration serial_config_driver = {
922 .open = gs_open, 131 /* .label = f(use_acm) */
923 .close = gs_close, 132 .bind = serial_bind_config,
924 .write = gs_write, 133 /* .bConfigurationValue = f(use_acm) */
925 .put_char = gs_put_char, 134 /* .iConfiguration = DYNAMIC */
926 .flush_chars = gs_flush_chars, 135 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
927 .write_room = gs_write_room, 136 .bMaxPower = 1, /* 2 mA, minimal */
928 .ioctl = gs_ioctl,
929 .set_termios = gs_set_termios,
930 .throttle = gs_throttle,
931 .unthrottle = gs_unthrottle,
932 .break_ctl = gs_break,
933 .chars_in_buffer = gs_chars_in_buffer,
934}; 137};
935 138
936/*-------------------------------------------------------------------------*/ 139static int __init gs_bind(struct usb_composite_dev *cdev)
937
938/*
939* gs_send
940*
941* This function finds available write requests, calls
942* gs_send_packet to fill these packets with data, and
943* continues until either there are no more write requests
944* available or no more data to send. This function is
945* run whenever data arrives or write requests are available.
946*/
947static int gs_send(struct gs_dev *dev)
948{
949 int ret,len;
950 unsigned long flags;
951 struct usb_ep *ep;
952 struct usb_request *req;
953
954 if (dev == NULL) {
955 pr_err("gs_send: NULL device pointer\n");
956 return -ENODEV;
957 }
958
959 spin_lock_irqsave(&dev->dev_lock, flags);
960
961 ep = dev->dev_in_ep;
962
963 while(!list_empty(&dev->dev_req_list)) {
964
965 req = list_entry(dev->dev_req_list.next,
966 struct usb_request, list);
967
968 len = gs_send_packet(dev, req->buf, ep->maxpacket);
969
970 if (len > 0) {
971 gs_debug_level(3, "gs_send: len=%d, 0x%2.2x "
972 "0x%2.2x 0x%2.2x ...\n", len,
973 *((unsigned char *)req->buf),
974 *((unsigned char *)req->buf+1),
975 *((unsigned char *)req->buf+2));
976 list_del(&req->list);
977 req->length = len;
978 spin_unlock_irqrestore(&dev->dev_lock, flags);
979 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
980 pr_err(
981 "gs_send: cannot queue read request, ret=%d\n",
982 ret);
983 spin_lock_irqsave(&dev->dev_lock, flags);
984 break;
985 }
986 spin_lock_irqsave(&dev->dev_lock, flags);
987 } else {
988 break;
989 }
990
991 }
992
993 spin_unlock_irqrestore(&dev->dev_lock, flags);
994
995 return 0;
996}
997
998/*
999 * gs_send_packet
1000 *
1001 * If there is data to send, a packet is built in the given
1002 * buffer and the size is returned. If there is no data to
1003 * send, 0 is returned. If there is any error a negative
1004 * error number is returned.
1005 *
1006 * Called during USB completion routine, on interrupt time.
1007 *
1008 * We assume that disconnect will not happen until all completion
1009 * routines have completed, so we can assume that the dev_port
1010 * array does not change during the lifetime of this function.
1011 */
1012static int gs_send_packet(struct gs_dev *dev, char *packet, unsigned int size)
1013{
1014 unsigned int len;
1015 struct gs_port *port;
1016
1017 /* TEMPORARY -- only port 0 is supported right now */
1018 port = dev->dev_port[0];
1019
1020 if (port == NULL) {
1021 pr_err("gs_send_packet: port=%d, NULL port pointer\n", 0);
1022 return -EIO;
1023 }
1024
1025 spin_lock(&port->port_lock);
1026
1027 len = gs_buf_data_avail(port->port_write_buf);
1028 if (len < size)
1029 size = len;
1030
1031 if (size == 0)
1032 goto exit;
1033
1034 size = gs_buf_get(port->port_write_buf, packet, size);
1035
1036 if (port->port_tty)
1037 wake_up_interruptible(&port->port_tty->write_wait);
1038
1039exit:
1040 spin_unlock(&port->port_lock);
1041 return size;
1042}
1043
1044/*
1045 * gs_recv_packet
1046 *
1047 * Called for each USB packet received. Reads the packet
1048 * header and stuffs the data in the appropriate tty buffer.
1049 * Returns 0 if successful, or a negative error number.
1050 *
1051 * Called during USB completion routine, on interrupt time.
1052 *
1053 * We assume that disconnect will not happen until all completion
1054 * routines have completed, so we can assume that the dev_port
1055 * array does not change during the lifetime of this function.
1056 */
1057static int gs_recv_packet(struct gs_dev *dev, char *packet, unsigned int size)
1058{
1059 unsigned int len;
1060 struct gs_port *port;
1061 int ret;
1062 struct tty_struct *tty;
1063
1064 /* TEMPORARY -- only port 0 is supported right now */
1065 port = dev->dev_port[0];
1066
1067 if (port == NULL) {
1068 pr_err("gs_recv_packet: port=%d, NULL port pointer\n",
1069 port->port_num);
1070 return -EIO;
1071 }
1072
1073 spin_lock(&port->port_lock);
1074
1075 if (port->port_open_count == 0) {
1076 pr_err("gs_recv_packet: port=%d, port is closed\n",
1077 port->port_num);
1078 ret = -EIO;
1079 goto exit;
1080 }
1081
1082
1083 tty = port->port_tty;
1084
1085 if (tty == NULL) {
1086 pr_err("gs_recv_packet: port=%d, NULL tty pointer\n",
1087 port->port_num);
1088 ret = -EIO;
1089 goto exit;
1090 }
1091
1092 if (port->port_tty->magic != TTY_MAGIC) {
1093 pr_err("gs_recv_packet: port=%d, bad tty magic\n",
1094 port->port_num);
1095 ret = -EIO;
1096 goto exit;
1097 }
1098
1099 len = tty_buffer_request_room(tty, size);
1100 if (len > 0) {
1101 tty_insert_flip_string(tty, packet, len);
1102 tty_flip_buffer_push(port->port_tty);
1103 wake_up_interruptible(&port->port_tty->read_wait);
1104 }
1105 ret = 0;
1106exit:
1107 spin_unlock(&port->port_lock);
1108 return ret;
1109}
1110
1111/*
1112* gs_read_complete
1113*/
1114static void gs_read_complete(struct usb_ep *ep, struct usb_request *req)
1115{ 140{
1116 int ret; 141 int gcnum;
1117 struct gs_dev *dev = ep->driver_data; 142 struct usb_gadget *gadget = cdev->gadget;
1118 143 int status;
1119 if (dev == NULL) {
1120 pr_err("gs_read_complete: NULL device pointer\n");
1121 return;
1122 }
1123 144
1124 switch(req->status) { 145 status = gserial_setup(cdev->gadget, n_ports);
1125 case 0: 146 if (status < 0)
1126 /* normal completion */ 147 return status;
1127 gs_recv_packet(dev, req->buf, req->actual);
1128requeue:
1129 req->length = ep->maxpacket;
1130 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
1131 pr_err(
1132 "gs_read_complete: cannot queue read request, ret=%d\n",
1133 ret);
1134 }
1135 break;
1136
1137 case -ESHUTDOWN:
1138 /* disconnect */
1139 gs_debug("gs_read_complete: shutdown\n");
1140 gs_free_req(ep, req);
1141 break;
1142
1143 default:
1144 /* unexpected */
1145 pr_err(
1146 "gs_read_complete: unexpected status error, status=%d\n",
1147 req->status);
1148 goto requeue;
1149 break;
1150 }
1151}
1152
1153/*
1154* gs_write_complete
1155*/
1156static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
1157{
1158 struct gs_dev *dev = ep->driver_data;
1159
1160 if (dev == NULL) {
1161 pr_err("gs_write_complete: NULL device pointer\n");
1162 return;
1163 }
1164 148
1165 switch(req->status) { 149 /* Allocate string descriptor numbers ... note that string
1166 case 0: 150 * contents can be overridden by the composite_dev glue.
1167 /* normal completion */ 151 */
1168requeue:
1169 spin_lock(&dev->dev_lock);
1170 list_add(&req->list, &dev->dev_req_list);
1171 spin_unlock(&dev->dev_lock);
1172
1173 gs_send(dev);
1174
1175 break;
1176
1177 case -ESHUTDOWN:
1178 /* disconnect */
1179 gs_debug("gs_write_complete: shutdown\n");
1180 gs_free_req(ep, req);
1181 break;
1182
1183 default:
1184 pr_err(
1185 "gs_write_complete: unexpected status error, status=%d\n",
1186 req->status);
1187 goto requeue;
1188 break;
1189 }
1190}
1191 152
1192/*-------------------------------------------------------------------------*/ 153 /* device description: manufacturer, product */
154 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
155 init_utsname()->sysname, init_utsname()->release,
156 gadget->name);
157 status = usb_string_id(cdev);
158 if (status < 0)
159 goto fail;
160 strings_dev[STRING_MANUFACTURER_IDX].id = status;
1193 161
1194/* Gadget Driver */ 162 device_desc.iManufacturer = status;
1195 163
1196/* 164 status = usb_string_id(cdev);
1197 * gs_unbind 165 if (status < 0)
1198 * 166 goto fail;
1199 * Called on module unload. Frees the control request and device 167 strings_dev[STRING_PRODUCT_IDX].id = status;
1200 * structure.
1201 */
1202static void /* __init_or_exit */ gs_unbind(struct usb_gadget *gadget)
1203{
1204 struct gs_dev *dev = get_gadget_data(gadget);
1205 168
1206 gs_device = NULL; 169 device_desc.iProduct = status;
1207 170
1208 /* read/write requests already freed, only control request remains */ 171 /* config description */
1209 if (dev != NULL) { 172 status = usb_string_id(cdev);
1210 if (dev->dev_ctrl_req != NULL) { 173 if (status < 0)
1211 gs_free_req(gadget->ep0, dev->dev_ctrl_req); 174 goto fail;
1212 dev->dev_ctrl_req = NULL; 175 strings_dev[STRING_DESCRIPTION_IDX].id = status;
1213 }
1214 gs_reset_config(dev);
1215 gs_free_ports(dev);
1216 kfree(dev);
1217 set_gadget_data(gadget, NULL);
1218 }
1219 176
1220 pr_info("gs_unbind: %s %s unbound\n", GS_LONG_NAME, 177 serial_config_driver.iConfiguration = status;
1221 GS_VERSION_STR);
1222}
1223
1224/*
1225 * gs_bind
1226 *
1227 * Called on module load. Allocates and initializes the device
1228 * structure and a control request.
1229 */
1230static int __init gs_bind(struct usb_gadget *gadget)
1231{
1232 int ret;
1233 struct usb_ep *ep;
1234 struct gs_dev *dev;
1235 int gcnum;
1236
1237 /* Some controllers can't support CDC ACM:
1238 * - sh doesn't support multiple interfaces or configs;
1239 * - sa1100 doesn't have a third interrupt endpoint
1240 */
1241 if (gadget_is_sh(gadget) || gadget_is_sa1100(gadget))
1242 use_acm = 0;
1243 178
179 /* set up other descriptors */
1244 gcnum = usb_gadget_controller_number(gadget); 180 gcnum = usb_gadget_controller_number(gadget);
1245 if (gcnum >= 0) 181 if (gcnum >= 0)
1246 gs_device_desc.bcdDevice = 182 device_desc.bcdDevice = cpu_to_le16(GS_VERSION_NUM | gcnum);
1247 cpu_to_le16(GS_VERSION_NUM | gcnum);
1248 else { 183 else {
184 /* this is so simple (for now, no altsettings) that it
185 * SHOULD NOT have problems with bulk-capable hardware.
186 * so warn about unrcognized controllers -- don't panic.
187 *
188 * things like configuration and altsetting numbering
189 * can need hardware-specific attention though.
190 */
1249 pr_warning("gs_bind: controller '%s' not recognized\n", 191 pr_warning("gs_bind: controller '%s' not recognized\n",
1250 gadget->name); 192 gadget->name);
1251 /* unrecognized, but safe unless bulk is REALLY quirky */ 193 device_desc.bcdDevice =
1252 gs_device_desc.bcdDevice = 194 __constant_cpu_to_le16(GS_VERSION_NUM | 0x0099);
1253 __constant_cpu_to_le16(GS_VERSION_NUM|0x0099);
1254 }
1255
1256 dev = kzalloc(sizeof(struct gs_dev), GFP_KERNEL);
1257 if (dev == NULL)
1258 return -ENOMEM;
1259
1260 usb_ep_autoconfig_reset(gadget);
1261
1262 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_in_desc);
1263 if (!ep)
1264 goto autoconf_fail;
1265 dev->dev_in_ep = ep;
1266 ep->driver_data = dev; /* claim the endpoint */
1267
1268 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_out_desc);
1269 if (!ep)
1270 goto autoconf_fail;
1271 dev->dev_out_ep = ep;
1272 ep->driver_data = dev; /* claim the endpoint */
1273
1274 if (use_acm) {
1275 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_notify_desc);
1276 if (!ep) {
1277 pr_err("gs_bind: cannot run ACM on %s\n", gadget->name);
1278 goto autoconf_fail;
1279 }
1280 gs_device_desc.idProduct = __constant_cpu_to_le16(
1281 GS_CDC_PRODUCT_ID),
1282 dev->dev_notify_ep = ep;
1283 ep->driver_data = dev; /* claim the endpoint */
1284 }
1285
1286 gs_device_desc.bDeviceClass = use_acm
1287 ? USB_CLASS_COMM : USB_CLASS_VENDOR_SPEC;
1288 gs_device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1289
1290 if (gadget_is_dualspeed(gadget)) {
1291 gs_qualifier_desc.bDeviceClass = use_acm
1292 ? USB_CLASS_COMM : USB_CLASS_VENDOR_SPEC;
1293 /* assume ep0 uses the same packet size for both speeds */
1294 gs_qualifier_desc.bMaxPacketSize0 =
1295 gs_device_desc.bMaxPacketSize0;
1296 /* assume endpoints are dual-speed */
1297 gs_highspeed_notify_desc.bEndpointAddress =
1298 gs_fullspeed_notify_desc.bEndpointAddress;
1299 gs_highspeed_in_desc.bEndpointAddress =
1300 gs_fullspeed_in_desc.bEndpointAddress;
1301 gs_highspeed_out_desc.bEndpointAddress =
1302 gs_fullspeed_out_desc.bEndpointAddress;
1303 }
1304
1305 usb_gadget_set_selfpowered(gadget);
1306
1307 if (gadget_is_otg(gadget)) {
1308 gs_otg_descriptor.bmAttributes |= USB_OTG_HNP,
1309 gs_bulk_config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1310 gs_acm_config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1311 } 195 }
1312 196
1313 gs_device = dev; 197 if (gadget_is_otg(cdev->gadget)) {
1314 198 serial_config_driver.descriptors = otg_desc;
1315 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s", 199 serial_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1316 init_utsname()->sysname, init_utsname()->release,
1317 gadget->name);
1318
1319 dev->dev_gadget = gadget;
1320 spin_lock_init(&dev->dev_lock);
1321 INIT_LIST_HEAD(&dev->dev_req_list);
1322 set_gadget_data(gadget, dev);
1323
1324 if ((ret=gs_alloc_ports(dev, GFP_KERNEL)) != 0) {
1325 pr_err("gs_bind: cannot allocate ports\n");
1326 gs_unbind(gadget);
1327 return ret;
1328 } 200 }
1329 201
1330 /* preallocate control response and buffer */ 202 /* register our configuration */
1331 dev->dev_ctrl_req = gs_alloc_req(gadget->ep0, GS_MAX_DESC_LEN, 203 status = usb_add_config(cdev, &serial_config_driver);
1332 GFP_KERNEL); 204 if (status < 0)
1333 if (dev->dev_ctrl_req == NULL) { 205 goto fail;
1334 gs_unbind(gadget);
1335 return -ENOMEM;
1336 }
1337 gadget->ep0->driver_data = dev;
1338 206
1339 pr_info("gs_bind: %s %s bound\n", 207 INFO(cdev, "%s\n", GS_VERSION_NAME);
1340 GS_LONG_NAME, GS_VERSION_STR);
1341 208
1342 return 0; 209 return 0;
1343 210
1344autoconf_fail: 211fail:
1345 kfree(dev); 212 gserial_cleanup();
1346 pr_err("gs_bind: cannot autoconfigure on %s\n", gadget->name); 213 return status;
1347 return -ENODEV;
1348}
1349
1350static int gs_setup_standard(struct usb_gadget *gadget,
1351 const struct usb_ctrlrequest *ctrl)
1352{
1353 int ret = -EOPNOTSUPP;
1354 struct gs_dev *dev = get_gadget_data(gadget);
1355 struct usb_request *req = dev->dev_ctrl_req;
1356 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1357 u16 wValue = le16_to_cpu(ctrl->wValue);
1358 u16 wLength = le16_to_cpu(ctrl->wLength);
1359
1360 switch (ctrl->bRequest) {
1361 case USB_REQ_GET_DESCRIPTOR:
1362 if (ctrl->bRequestType != USB_DIR_IN)
1363 break;
1364
1365 switch (wValue >> 8) {
1366 case USB_DT_DEVICE:
1367 ret = min(wLength,
1368 (u16)sizeof(struct usb_device_descriptor));
1369 memcpy(req->buf, &gs_device_desc, ret);
1370 break;
1371
1372 case USB_DT_DEVICE_QUALIFIER:
1373 if (!gadget_is_dualspeed(gadget))
1374 break;
1375 ret = min(wLength,
1376 (u16)sizeof(struct usb_qualifier_descriptor));
1377 memcpy(req->buf, &gs_qualifier_desc, ret);
1378 break;
1379
1380 case USB_DT_OTHER_SPEED_CONFIG:
1381 if (!gadget_is_dualspeed(gadget))
1382 break;
1383 /* fall through */
1384 case USB_DT_CONFIG:
1385 ret = gs_build_config_buf(req->buf, gadget,
1386 wValue >> 8, wValue & 0xff,
1387 gadget_is_otg(gadget));
1388 if (ret >= 0)
1389 ret = min(wLength, (u16)ret);
1390 break;
1391
1392 case USB_DT_STRING:
1393 /* wIndex == language code. */
1394 ret = usb_gadget_get_string(&gs_string_table,
1395 wValue & 0xff, req->buf);
1396 if (ret >= 0)
1397 ret = min(wLength, (u16)ret);
1398 break;
1399 }
1400 break;
1401
1402 case USB_REQ_SET_CONFIGURATION:
1403 if (ctrl->bRequestType != 0)
1404 break;
1405 spin_lock(&dev->dev_lock);
1406 ret = gs_set_config(dev, wValue);
1407 spin_unlock(&dev->dev_lock);
1408 break;
1409
1410 case USB_REQ_GET_CONFIGURATION:
1411 if (ctrl->bRequestType != USB_DIR_IN)
1412 break;
1413 *(u8 *)req->buf = dev->dev_config;
1414 ret = min(wLength, (u16)1);
1415 break;
1416
1417 case USB_REQ_SET_INTERFACE:
1418 if (ctrl->bRequestType != USB_RECIP_INTERFACE
1419 || !dev->dev_config
1420 || wIndex >= GS_MAX_NUM_INTERFACES)
1421 break;
1422 if (dev->dev_config == GS_BULK_CONFIG_ID
1423 && wIndex != GS_BULK_INTERFACE_ID)
1424 break;
1425 /* no alternate interface settings */
1426 if (wValue != 0)
1427 break;
1428 spin_lock(&dev->dev_lock);
1429 /* PXA hardware partially handles SET_INTERFACE;
1430 * we need to kluge around that interference. */
1431 if (gadget_is_pxa(gadget)) {
1432 ret = gs_set_config(dev, use_acm ?
1433 GS_ACM_CONFIG_ID : GS_BULK_CONFIG_ID);
1434 goto set_interface_done;
1435 }
1436 if (dev->dev_config != GS_BULK_CONFIG_ID
1437 && wIndex == GS_CONTROL_INTERFACE_ID) {
1438 if (dev->dev_notify_ep) {
1439 usb_ep_disable(dev->dev_notify_ep);
1440 usb_ep_enable(dev->dev_notify_ep, dev->dev_notify_ep_desc);
1441 }
1442 } else {
1443 usb_ep_disable(dev->dev_in_ep);
1444 usb_ep_disable(dev->dev_out_ep);
1445 usb_ep_enable(dev->dev_in_ep, dev->dev_in_ep_desc);
1446 usb_ep_enable(dev->dev_out_ep, dev->dev_out_ep_desc);
1447 }
1448 ret = 0;
1449set_interface_done:
1450 spin_unlock(&dev->dev_lock);
1451 break;
1452
1453 case USB_REQ_GET_INTERFACE:
1454 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)
1455 || dev->dev_config == GS_NO_CONFIG_ID)
1456 break;
1457 if (wIndex >= GS_MAX_NUM_INTERFACES
1458 || (dev->dev_config == GS_BULK_CONFIG_ID
1459 && wIndex != GS_BULK_INTERFACE_ID)) {
1460 ret = -EDOM;
1461 break;
1462 }
1463 /* no alternate interface settings */
1464 *(u8 *)req->buf = 0;
1465 ret = min(wLength, (u16)1);
1466 break;
1467
1468 default:
1469 pr_err("gs_setup: unknown standard request, type=%02x, "
1470 "request=%02x, value=%04x, index=%04x, length=%d\n",
1471 ctrl->bRequestType, ctrl->bRequest,
1472 wValue, wIndex, wLength);
1473 break;
1474 }
1475
1476 return ret;
1477} 214}
1478 215
1479static void gs_setup_complete_set_line_coding(struct usb_ep *ep, 216static struct usb_composite_driver gserial_driver = {
1480 struct usb_request *req) 217 .name = "g_serial",
1481{ 218 .dev = &device_desc,
1482 struct gs_dev *dev = ep->driver_data; 219 .strings = dev_strings,
1483 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */ 220 .bind = gs_bind,
1484
1485 switch (req->status) {
1486 case 0:
1487 /* normal completion */
1488 if (req->actual != sizeof(port->port_line_coding))
1489 usb_ep_set_halt(ep);
1490 else if (port) {
1491 struct usb_cdc_line_coding *value = req->buf;
1492
1493 /* REVISIT: we currently just remember this data.
1494 * If we change that, (a) validate it first, then
1495 * (b) update whatever hardware needs updating.
1496 */
1497 spin_lock(&port->port_lock);
1498 port->port_line_coding = *value;
1499 spin_unlock(&port->port_lock);
1500 }
1501 break;
1502
1503 case -ESHUTDOWN:
1504 /* disconnect */
1505 gs_free_req(ep, req);
1506 break;
1507
1508 default:
1509 /* unexpected */
1510 break;
1511 }
1512 return;
1513}
1514
1515static int gs_setup_class(struct usb_gadget *gadget,
1516 const struct usb_ctrlrequest *ctrl)
1517{
1518 int ret = -EOPNOTSUPP;
1519 struct gs_dev *dev = get_gadget_data(gadget);
1520 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */
1521 struct usb_request *req = dev->dev_ctrl_req;
1522 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1523 u16 wValue = le16_to_cpu(ctrl->wValue);
1524 u16 wLength = le16_to_cpu(ctrl->wLength);
1525
1526 switch (ctrl->bRequest) {
1527 case USB_CDC_REQ_SET_LINE_CODING:
1528 if (wLength != sizeof(struct usb_cdc_line_coding))
1529 break;
1530 ret = wLength;
1531 req->complete = gs_setup_complete_set_line_coding;
1532 break;
1533
1534 case USB_CDC_REQ_GET_LINE_CODING:
1535 ret = min_t(int, wLength, sizeof(struct usb_cdc_line_coding));
1536 if (port) {
1537 spin_lock(&port->port_lock);
1538 memcpy(req->buf, &port->port_line_coding, ret);
1539 spin_unlock(&port->port_lock);
1540 }
1541 break;
1542
1543 case USB_CDC_REQ_SET_CONTROL_LINE_STATE:
1544 if (wLength != 0)
1545 break;
1546 ret = 0;
1547 if (port) {
1548 /* REVISIT: we currently just remember this data.
1549 * If we change that, update whatever hardware needs
1550 * updating.
1551 */
1552 spin_lock(&port->port_lock);
1553 port->port_handshake_bits = wValue;
1554 spin_unlock(&port->port_lock);
1555 }
1556 break;
1557
1558 default:
1559 /* NOTE: strictly speaking, we should accept AT-commands
1560 * using SEND_ENCPSULATED_COMMAND/GET_ENCAPSULATED_RESPONSE.
1561 * But our call management descriptor says we don't handle
1562 * call management, so we should be able to get by without
1563 * handling those "required" commands (except by stalling).
1564 */
1565 pr_err("gs_setup: unknown class request, "
1566 "type=%02x, request=%02x, value=%04x, "
1567 "index=%04x, length=%d\n",
1568 ctrl->bRequestType, ctrl->bRequest,
1569 wValue, wIndex, wLength);
1570 break;
1571 }
1572
1573 return ret;
1574}
1575
1576/*
1577 * gs_setup_complete
1578 */
1579static void gs_setup_complete(struct usb_ep *ep, struct usb_request *req)
1580{
1581 if (req->status || req->actual != req->length) {
1582 pr_err("gs_setup_complete: status error, status=%d, "
1583 "actual=%d, length=%d\n",
1584 req->status, req->actual, req->length);
1585 }
1586}
1587
1588/*
1589 * gs_setup
1590 *
1591 * Implements all the control endpoint functionality that's not
1592 * handled in hardware or the hardware driver.
1593 *
1594 * Returns the size of the data sent to the host, or a negative
1595 * error number.
1596 */
1597static int gs_setup(struct usb_gadget *gadget,
1598 const struct usb_ctrlrequest *ctrl)
1599{
1600 int ret = -EOPNOTSUPP;
1601 struct gs_dev *dev = get_gadget_data(gadget);
1602 struct usb_request *req = dev->dev_ctrl_req;
1603 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1604 u16 wValue = le16_to_cpu(ctrl->wValue);
1605 u16 wLength = le16_to_cpu(ctrl->wLength);
1606
1607 req->complete = gs_setup_complete;
1608
1609 switch (ctrl->bRequestType & USB_TYPE_MASK) {
1610 case USB_TYPE_STANDARD:
1611 ret = gs_setup_standard(gadget, ctrl);
1612 break;
1613
1614 case USB_TYPE_CLASS:
1615 ret = gs_setup_class(gadget, ctrl);
1616 break;
1617
1618 default:
1619 pr_err("gs_setup: unknown request, type=%02x, request=%02x, "
1620 "value=%04x, index=%04x, length=%d\n",
1621 ctrl->bRequestType, ctrl->bRequest,
1622 wValue, wIndex, wLength);
1623 break;
1624 }
1625
1626 /* respond with data transfer before status phase? */
1627 if (ret >= 0) {
1628 req->length = ret;
1629 req->zero = ret < wLength
1630 && (ret % gadget->ep0->maxpacket) == 0;
1631 ret = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
1632 if (ret < 0) {
1633 pr_err("gs_setup: cannot queue response, ret=%d\n",
1634 ret);
1635 req->status = 0;
1636 gs_setup_complete(gadget->ep0, req);
1637 }
1638 }
1639
1640 /* device either stalls (ret < 0) or reports success */
1641 return ret;
1642}
1643
1644/*
1645 * gs_disconnect
1646 *
1647 * Called when the device is disconnected. Frees the closed
1648 * ports and disconnects open ports. Open ports will be freed
1649 * on close. Then reallocates the ports for the next connection.
1650 */
1651static void gs_disconnect(struct usb_gadget *gadget)
1652{
1653 unsigned long flags;
1654 struct gs_dev *dev = get_gadget_data(gadget);
1655
1656 spin_lock_irqsave(&dev->dev_lock, flags);
1657
1658 gs_reset_config(dev);
1659
1660 /* free closed ports and disconnect open ports */
1661 /* (open ports will be freed when closed) */
1662 gs_free_ports(dev);
1663
1664 /* re-allocate ports for the next connection */
1665 if (gs_alloc_ports(dev, GFP_ATOMIC) != 0)
1666 pr_err("gs_disconnect: cannot re-allocate ports\n");
1667
1668 spin_unlock_irqrestore(&dev->dev_lock, flags);
1669
1670 pr_info("gs_disconnect: %s disconnected\n", GS_LONG_NAME);
1671}
1672
1673static struct usb_gadget_driver gs_gadget_driver = {
1674#ifdef CONFIG_USB_GADGET_DUALSPEED
1675 .speed = USB_SPEED_HIGH,
1676#else
1677 .speed = USB_SPEED_FULL,
1678#endif /* CONFIG_USB_GADGET_DUALSPEED */
1679 .function = GS_LONG_NAME,
1680 .bind = gs_bind,
1681 .unbind = gs_unbind,
1682 .setup = gs_setup,
1683 .disconnect = gs_disconnect,
1684 .driver = {
1685 .name = GS_SHORT_NAME,
1686 .owner = THIS_MODULE,
1687 },
1688}; 221};
1689 222
1690/* 223static int __init init(void)
1691 * gs_set_config
1692 *
1693 * Configures the device by enabling device specific
1694 * optimizations, setting up the endpoints, allocating
1695 * read and write requests and queuing read requests.
1696 *
1697 * The device lock must be held when calling this function.
1698 */
1699static int gs_set_config(struct gs_dev *dev, unsigned config)
1700{ 224{
1701 int i; 225 /* We *could* export two configs; that'd be much cleaner...
1702 int ret = 0; 226 * but neither of these product IDs was defined that way.
1703 struct usb_gadget *gadget = dev->dev_gadget;
1704 struct usb_ep *ep;
1705 struct usb_endpoint_descriptor *out, *in, *notify;
1706 struct usb_request *req;
1707
1708 if (dev == NULL) {
1709 pr_err("gs_set_config: NULL device pointer\n");
1710 return 0;
1711 }
1712
1713 if (config == dev->dev_config)
1714 return 0;
1715
1716 gs_reset_config(dev);
1717
1718 switch (config) {
1719 case GS_NO_CONFIG_ID:
1720 return 0;
1721 case GS_BULK_CONFIG_ID:
1722 if (use_acm)
1723 return -EINVAL;
1724 break;
1725 case GS_ACM_CONFIG_ID:
1726 if (!use_acm)
1727 return -EINVAL;
1728 break;
1729 default:
1730 return -EINVAL;
1731 }
1732
1733 in = choose_ep_desc(gadget,
1734 &gs_highspeed_in_desc,
1735 &gs_fullspeed_in_desc);
1736 out = choose_ep_desc(gadget,
1737 &gs_highspeed_out_desc,
1738 &gs_fullspeed_out_desc);
1739 notify = dev->dev_notify_ep
1740 ? choose_ep_desc(gadget,
1741 &gs_highspeed_notify_desc,
1742 &gs_fullspeed_notify_desc)
1743 : NULL;
1744
1745 ret = usb_ep_enable(dev->dev_in_ep, in);
1746 if (ret == 0) {
1747 dev->dev_in_ep_desc = in;
1748 } else {
1749 pr_debug("%s: cannot enable %s %s, ret=%d\n",
1750 __func__, "IN", dev->dev_in_ep->name, ret);
1751 return ret;
1752 }
1753
1754 ret = usb_ep_enable(dev->dev_out_ep, out);
1755 if (ret == 0) {
1756 dev->dev_out_ep_desc = out;
1757 } else {
1758 pr_debug("%s: cannot enable %s %s, ret=%d\n",
1759 __func__, "OUT", dev->dev_out_ep->name, ret);
1760fail0:
1761 usb_ep_disable(dev->dev_in_ep);
1762 return ret;
1763 }
1764
1765 if (notify) {
1766 ret = usb_ep_enable(dev->dev_notify_ep, notify);
1767 if (ret == 0) {
1768 dev->dev_notify_ep_desc = notify;
1769 } else {
1770 pr_debug("%s: cannot enable %s %s, ret=%d\n",
1771 __func__, "NOTIFY",
1772 dev->dev_notify_ep->name, ret);
1773 usb_ep_disable(dev->dev_out_ep);
1774 goto fail0;
1775 }
1776 }
1777
1778 dev->dev_config = config;
1779
1780 /* allocate and queue read requests */
1781 ep = dev->dev_out_ep;
1782 for (i=0; i<read_q_size && ret == 0; i++) {
1783 if ((req=gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC))) {
1784 req->complete = gs_read_complete;
1785 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
1786 pr_err("gs_set_config: cannot queue read "
1787 "request, ret=%d\n", ret);
1788 }
1789 } else {
1790 pr_err("gs_set_config: cannot allocate "
1791 "read requests\n");
1792 ret = -ENOMEM;
1793 goto exit_reset_config;
1794 }
1795 }
1796
1797 /* allocate write requests, and put on free list */
1798 ep = dev->dev_in_ep;
1799 for (i=0; i<write_q_size; i++) {
1800 req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC);
1801 if (req) {
1802 req->complete = gs_write_complete;
1803 list_add(&req->list, &dev->dev_req_list);
1804 } else {
1805 pr_err("gs_set_config: cannot allocate "
1806 "write requests\n");
1807 ret = -ENOMEM;
1808 goto exit_reset_config;
1809 }
1810 }
1811
1812 /* REVISIT the ACM mode should be able to actually *issue* some
1813 * notifications, for at least serial state change events if
1814 * not also for network connection; say so in bmCapabilities.
1815 */ 227 */
1816
1817 pr_info("gs_set_config: %s configured, %s speed %s config\n",
1818 GS_LONG_NAME,
1819 gadget->speed == USB_SPEED_HIGH ? "high" : "full",
1820 config == GS_BULK_CONFIG_ID ? "BULK" : "CDC-ACM");
1821
1822 return 0;
1823
1824exit_reset_config:
1825 gs_reset_config(dev);
1826 return ret;
1827}
1828
1829/*
1830 * gs_reset_config
1831 *
1832 * Mark the device as not configured, disable all endpoints,
1833 * which forces completion of pending I/O and frees queued
1834 * requests, and free the remaining write requests on the
1835 * free list.
1836 *
1837 * The device lock must be held when calling this function.
1838 */
1839static void gs_reset_config(struct gs_dev *dev)
1840{
1841 struct usb_request *req;
1842
1843 if (dev == NULL) {
1844 pr_err("gs_reset_config: NULL device pointer\n");
1845 return;
1846 }
1847
1848 if (dev->dev_config == GS_NO_CONFIG_ID)
1849 return;
1850
1851 dev->dev_config = GS_NO_CONFIG_ID;
1852
1853 /* free write requests on the free list */
1854 while(!list_empty(&dev->dev_req_list)) {
1855 req = list_entry(dev->dev_req_list.next,
1856 struct usb_request, list);
1857 list_del(&req->list);
1858 gs_free_req(dev->dev_in_ep, req);
1859 }
1860
1861 /* disable endpoints, forcing completion of pending i/o; */
1862 /* completion handlers free their requests in this case */
1863 if (dev->dev_notify_ep)
1864 usb_ep_disable(dev->dev_notify_ep);
1865 usb_ep_disable(dev->dev_in_ep);
1866 usb_ep_disable(dev->dev_out_ep);
1867}
1868
1869/*
1870 * gs_build_config_buf
1871 *
1872 * Builds the config descriptors in the given buffer and returns the
1873 * length, or a negative error number.
1874 */
1875static int gs_build_config_buf(u8 *buf, struct usb_gadget *g,
1876 u8 type, unsigned int index, int is_otg)
1877{
1878 int len;
1879 int high_speed = 0;
1880 const struct usb_config_descriptor *config_desc;
1881 const struct usb_descriptor_header **function;
1882
1883 if (index >= gs_device_desc.bNumConfigurations)
1884 return -EINVAL;
1885
1886 /* other speed switches high and full speed */
1887 if (gadget_is_dualspeed(g)) {
1888 high_speed = (g->speed == USB_SPEED_HIGH);
1889 if (type == USB_DT_OTHER_SPEED_CONFIG)
1890 high_speed = !high_speed;
1891 }
1892
1893 if (use_acm) { 228 if (use_acm) {
1894 config_desc = &gs_acm_config_desc; 229 serial_config_driver.label = "CDC ACM config";
1895 function = high_speed 230 serial_config_driver.bConfigurationValue = 2;
1896 ? gs_acm_highspeed_function 231 device_desc.bDeviceClass = USB_CLASS_COMM;
1897 : gs_acm_fullspeed_function; 232 device_desc.idProduct =
233 __constant_cpu_to_le16(GS_CDC_PRODUCT_ID);
1898 } else { 234 } else {
1899 config_desc = &gs_bulk_config_desc; 235 serial_config_driver.label = "Generic Serial config";
1900 function = high_speed 236 serial_config_driver.bConfigurationValue = 1;
1901 ? gs_bulk_highspeed_function 237 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
1902 : gs_bulk_fullspeed_function; 238 device_desc.idProduct =
1903 } 239 __constant_cpu_to_le16(GS_PRODUCT_ID);
1904
1905 /* for now, don't advertise srp-only devices */
1906 if (!is_otg)
1907 function++;
1908
1909 len = usb_gadget_config_buf(config_desc, buf, GS_MAX_DESC_LEN, function);
1910 if (len < 0)
1911 return len;
1912
1913 ((struct usb_config_descriptor *)buf)->bDescriptorType = type;
1914
1915 return len;
1916}
1917
1918/*
1919 * gs_alloc_req
1920 *
1921 * Allocate a usb_request and its buffer. Returns a pointer to the
1922 * usb_request or NULL if there is an error.
1923 */
1924static struct usb_request *
1925gs_alloc_req(struct usb_ep *ep, unsigned int len, gfp_t kmalloc_flags)
1926{
1927 struct usb_request *req;
1928
1929 if (ep == NULL)
1930 return NULL;
1931
1932 req = usb_ep_alloc_request(ep, kmalloc_flags);
1933
1934 if (req != NULL) {
1935 req->length = len;
1936 req->buf = kmalloc(len, kmalloc_flags);
1937 if (req->buf == NULL) {
1938 usb_ep_free_request(ep, req);
1939 return NULL;
1940 }
1941 } 240 }
241 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label;
1942 242
1943 return req; 243 return usb_composite_register(&gserial_driver);
1944} 244}
245module_init(init);
1945 246
1946/* 247static void __exit cleanup(void)
1947 * gs_free_req
1948 *
1949 * Free a usb_request and its buffer.
1950 */
1951static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
1952{ 248{
1953 if (ep != NULL && req != NULL) { 249 usb_composite_unregister(&gserial_driver);
1954 kfree(req->buf); 250 gserial_cleanup();
1955 usb_ep_free_request(ep, req);
1956 }
1957}
1958
1959/*
1960 * gs_alloc_ports
1961 *
1962 * Allocate all ports and set the gs_dev struct to point to them.
1963 * Return 0 if successful, or a negative error number.
1964 *
1965 * The device lock is normally held when calling this function.
1966 */
1967static int gs_alloc_ports(struct gs_dev *dev, gfp_t kmalloc_flags)
1968{
1969 int i;
1970 struct gs_port *port;
1971
1972 if (dev == NULL)
1973 return -EIO;
1974
1975 for (i=0; i<GS_NUM_PORTS; i++) {
1976 if ((port=kzalloc(sizeof(struct gs_port), kmalloc_flags)) == NULL)
1977 return -ENOMEM;
1978
1979 port->port_dev = dev;
1980 port->port_num = i;
1981 port->port_line_coding.dwDTERate = cpu_to_le32(GS_DEFAULT_DTE_RATE);
1982 port->port_line_coding.bCharFormat = GS_DEFAULT_CHAR_FORMAT;
1983 port->port_line_coding.bParityType = GS_DEFAULT_PARITY;
1984 port->port_line_coding.bDataBits = GS_DEFAULT_DATA_BITS;
1985 spin_lock_init(&port->port_lock);
1986 init_waitqueue_head(&port->port_write_wait);
1987
1988 dev->dev_port[i] = port;
1989 }
1990
1991 return 0;
1992}
1993
1994/*
1995 * gs_free_ports
1996 *
1997 * Free all closed ports. Open ports are disconnected by
1998 * freeing their write buffers, setting their device pointers
1999 * and the pointers to them in the device to NULL. These
2000 * ports will be freed when closed.
2001 *
2002 * The device lock is normally held when calling this function.
2003 */
2004static void gs_free_ports(struct gs_dev *dev)
2005{
2006 int i;
2007 unsigned long flags;
2008 struct gs_port *port;
2009
2010 if (dev == NULL)
2011 return;
2012
2013 for (i=0; i<GS_NUM_PORTS; i++) {
2014 if ((port=dev->dev_port[i]) != NULL) {
2015 dev->dev_port[i] = NULL;
2016
2017 spin_lock_irqsave(&port->port_lock, flags);
2018
2019 if (port->port_write_buf != NULL) {
2020 gs_buf_free(port->port_write_buf);
2021 port->port_write_buf = NULL;
2022 }
2023
2024 if (port->port_open_count > 0 || port->port_in_use) {
2025 port->port_dev = NULL;
2026 wake_up_interruptible(&port->port_write_wait);
2027 if (port->port_tty) {
2028 tty_hangup(port->port_tty);
2029 }
2030 spin_unlock_irqrestore(&port->port_lock, flags);
2031 } else {
2032 spin_unlock_irqrestore(&port->port_lock, flags);
2033 kfree(port);
2034 }
2035
2036 }
2037 }
2038}
2039
2040/*-------------------------------------------------------------------------*/
2041
2042/* Circular Buffer */
2043
2044/*
2045 * gs_buf_alloc
2046 *
2047 * Allocate a circular buffer and all associated memory.
2048 */
2049static struct gs_buf *gs_buf_alloc(unsigned int size, gfp_t kmalloc_flags)
2050{
2051 struct gs_buf *gb;
2052
2053 if (size == 0)
2054 return NULL;
2055
2056 gb = kmalloc(sizeof(struct gs_buf), kmalloc_flags);
2057 if (gb == NULL)
2058 return NULL;
2059
2060 gb->buf_buf = kmalloc(size, kmalloc_flags);
2061 if (gb->buf_buf == NULL) {
2062 kfree(gb);
2063 return NULL;
2064 }
2065
2066 gb->buf_size = size;
2067 gb->buf_get = gb->buf_put = gb->buf_buf;
2068
2069 return gb;
2070}
2071
2072/*
2073 * gs_buf_free
2074 *
2075 * Free the buffer and all associated memory.
2076 */
2077static void gs_buf_free(struct gs_buf *gb)
2078{
2079 if (gb) {
2080 kfree(gb->buf_buf);
2081 kfree(gb);
2082 }
2083}
2084
2085/*
2086 * gs_buf_clear
2087 *
2088 * Clear out all data in the circular buffer.
2089 */
2090static void gs_buf_clear(struct gs_buf *gb)
2091{
2092 if (gb != NULL)
2093 gb->buf_get = gb->buf_put;
2094 /* equivalent to a get of all data available */
2095}
2096
2097/*
2098 * gs_buf_data_avail
2099 *
2100 * Return the number of bytes of data available in the circular
2101 * buffer.
2102 */
2103static unsigned int gs_buf_data_avail(struct gs_buf *gb)
2104{
2105 if (gb != NULL)
2106 return (gb->buf_size + gb->buf_put - gb->buf_get) % gb->buf_size;
2107 else
2108 return 0;
2109}
2110
2111/*
2112 * gs_buf_space_avail
2113 *
2114 * Return the number of bytes of space available in the circular
2115 * buffer.
2116 */
2117static unsigned int gs_buf_space_avail(struct gs_buf *gb)
2118{
2119 if (gb != NULL)
2120 return (gb->buf_size + gb->buf_get - gb->buf_put - 1) % gb->buf_size;
2121 else
2122 return 0;
2123}
2124
2125/*
2126 * gs_buf_put
2127 *
2128 * Copy data data from a user buffer and put it into the circular buffer.
2129 * Restrict to the amount of space available.
2130 *
2131 * Return the number of bytes copied.
2132 */
2133static unsigned int
2134gs_buf_put(struct gs_buf *gb, const char *buf, unsigned int count)
2135{
2136 unsigned int len;
2137
2138 if (gb == NULL)
2139 return 0;
2140
2141 len = gs_buf_space_avail(gb);
2142 if (count > len)
2143 count = len;
2144
2145 if (count == 0)
2146 return 0;
2147
2148 len = gb->buf_buf + gb->buf_size - gb->buf_put;
2149 if (count > len) {
2150 memcpy(gb->buf_put, buf, len);
2151 memcpy(gb->buf_buf, buf+len, count - len);
2152 gb->buf_put = gb->buf_buf + count - len;
2153 } else {
2154 memcpy(gb->buf_put, buf, count);
2155 if (count < len)
2156 gb->buf_put += count;
2157 else /* count == len */
2158 gb->buf_put = gb->buf_buf;
2159 }
2160
2161 return count;
2162}
2163
2164/*
2165 * gs_buf_get
2166 *
2167 * Get data from the circular buffer and copy to the given buffer.
2168 * Restrict to the amount of data available.
2169 *
2170 * Return the number of bytes copied.
2171 */
2172static unsigned int
2173gs_buf_get(struct gs_buf *gb, char *buf, unsigned int count)
2174{
2175 unsigned int len;
2176
2177 if (gb == NULL)
2178 return 0;
2179
2180 len = gs_buf_data_avail(gb);
2181 if (count > len)
2182 count = len;
2183
2184 if (count == 0)
2185 return 0;
2186
2187 len = gb->buf_buf + gb->buf_size - gb->buf_get;
2188 if (count > len) {
2189 memcpy(buf, gb->buf_get, len);
2190 memcpy(buf+len, gb->buf_buf, count - len);
2191 gb->buf_get = gb->buf_buf + count - len;
2192 } else {
2193 memcpy(buf, gb->buf_get, count);
2194 if (count < len)
2195 gb->buf_get += count;
2196 else /* count == len */
2197 gb->buf_get = gb->buf_buf;
2198 }
2199
2200 return count;
2201}
2202
2203/*-------------------------------------------------------------------------*/
2204
2205static struct tty_driver *gs_tty_driver;
2206
2207/*
2208 * gs_module_init
2209 *
2210 * Register as a USB gadget driver and a tty driver.
2211 */
2212static int __init gs_module_init(void)
2213{
2214 int i;
2215 int retval;
2216
2217 retval = usb_gadget_register_driver(&gs_gadget_driver);
2218 if (retval) {
2219 pr_err("gs_module_init: cannot register gadget driver, "
2220 "ret=%d\n", retval);
2221 return retval;
2222 }
2223
2224 gs_tty_driver = alloc_tty_driver(GS_NUM_PORTS);
2225 if (!gs_tty_driver)
2226 return -ENOMEM;
2227 gs_tty_driver->owner = THIS_MODULE;
2228 gs_tty_driver->driver_name = GS_SHORT_NAME;
2229 gs_tty_driver->name = "ttygs";
2230 gs_tty_driver->major = GS_MAJOR;
2231 gs_tty_driver->minor_start = GS_MINOR_START;
2232 gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
2233 gs_tty_driver->subtype = SERIAL_TYPE_NORMAL;
2234 gs_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
2235 gs_tty_driver->init_termios = tty_std_termios;
2236 /* must match GS_DEFAULT_DTE_RATE and friends */
2237 gs_tty_driver->init_termios.c_cflag =
2238 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2239 gs_tty_driver->init_termios.c_ispeed = GS_DEFAULT_DTE_RATE;
2240 gs_tty_driver->init_termios.c_ospeed = GS_DEFAULT_DTE_RATE;
2241 tty_set_operations(gs_tty_driver, &gs_tty_ops);
2242
2243 for (i = 0; i < GS_NUM_PORTS; i++)
2244 mutex_init(&gs_open_close_lock[i]);
2245
2246 retval = tty_register_driver(gs_tty_driver);
2247 if (retval) {
2248 usb_gadget_unregister_driver(&gs_gadget_driver);
2249 put_tty_driver(gs_tty_driver);
2250 pr_err("gs_module_init: cannot register tty driver, "
2251 "ret=%d\n", retval);
2252 return retval;
2253 }
2254
2255 pr_info("gs_module_init: %s %s loaded\n",
2256 GS_LONG_NAME, GS_VERSION_STR);
2257 return 0;
2258}
2259module_init(gs_module_init);
2260
2261/*
2262 * gs_module_exit
2263 *
2264 * Unregister as a tty driver and a USB gadget driver.
2265 */
2266static void __exit gs_module_exit(void)
2267{
2268 tty_unregister_driver(gs_tty_driver);
2269 put_tty_driver(gs_tty_driver);
2270 usb_gadget_unregister_driver(&gs_gadget_driver);
2271
2272 pr_info("gs_module_exit: %s %s unloaded\n",
2273 GS_LONG_NAME, GS_VERSION_STR);
2274} 251}
2275module_exit(gs_module_exit); 252module_exit(cleanup);
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
new file mode 100644
index 000000000000..5458f43a8668
--- /dev/null
+++ b/drivers/usb/gadget/u_ether.c
@@ -0,0 +1,967 @@
1/*
2 * u_ether.c -- Ethernet-over-USB link layer utilities for Gadget stack
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23/* #define VERBOSE_DEBUG */
24
25#include <linux/kernel.h>
26#include <linux/utsname.h>
27#include <linux/device.h>
28#include <linux/ctype.h>
29#include <linux/etherdevice.h>
30#include <linux/ethtool.h>
31
32#include "u_ether.h"
33
34
35/*
36 * This component encapsulates the Ethernet link glue needed to provide
37 * one (!) network link through the USB gadget stack, normally "usb0".
38 *
39 * The control and data models are handled by the function driver which
40 * connects to this code; such as CDC Ethernet, "CDC Subset", or RNDIS.
41 * That includes all descriptor and endpoint management.
42 *
43 * Link level addressing is handled by this component using module
44 * parameters; if no such parameters are provided, random link level
45 * addresses are used. Each end of the link uses one address. The
46 * host end address is exported in various ways, and is often recorded
47 * in configuration databases.
48 *
49 * The driver which assembles each configuration using such a link is
50 * responsible for ensuring that each configuration includes at most one
51 * instance of is network link. (The network layer provides ways for
52 * this single "physical" link to be used by multiple virtual links.)
53 */
54
55#define DRIVER_VERSION "29-May-2008"
56
57struct eth_dev {
58 /* lock is held while accessing port_usb
59 * or updating its backlink port_usb->ioport
60 */
61 spinlock_t lock;
62 struct gether *port_usb;
63
64 struct net_device *net;
65 struct usb_gadget *gadget;
66
67 spinlock_t req_lock; /* guard {rx,tx}_reqs */
68 struct list_head tx_reqs, rx_reqs;
69 atomic_t tx_qlen;
70
71 unsigned header_len;
72 struct sk_buff *(*wrap)(struct sk_buff *skb);
73 int (*unwrap)(struct sk_buff *skb);
74
75 struct work_struct work;
76
77 unsigned long todo;
78#define WORK_RX_MEMORY 0
79
80 bool zlp;
81 u8 host_mac[ETH_ALEN];
82};
83
84/*-------------------------------------------------------------------------*/
85
86#define RX_EXTRA 20 /* bytes guarding against rx overflows */
87
88#define DEFAULT_QLEN 2 /* double buffering by default */
89
90
91#ifdef CONFIG_USB_GADGET_DUALSPEED
92
93static unsigned qmult = 5;
94module_param(qmult, uint, S_IRUGO|S_IWUSR);
95MODULE_PARM_DESC(qmult, "queue length multiplier at high speed");
96
97#else /* full speed (low speed doesn't do bulk) */
98#define qmult 1
99#endif
100
101/* for dual-speed hardware, use deeper queues at highspeed */
102static inline int qlen(struct usb_gadget *gadget)
103{
104 if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH)
105 return qmult * DEFAULT_QLEN;
106 else
107 return DEFAULT_QLEN;
108}
109
110/*-------------------------------------------------------------------------*/
111
112/* REVISIT there must be a better way than having two sets
113 * of debug calls ...
114 */
115
116#undef DBG
117#undef VDBG
118#undef ERROR
119#undef WARN
120#undef INFO
121
122#define xprintk(d, level, fmt, args...) \
123 printk(level "%s: " fmt , (d)->net->name , ## args)
124
125#ifdef DEBUG
126#undef DEBUG
127#define DBG(dev, fmt, args...) \
128 xprintk(dev , KERN_DEBUG , fmt , ## args)
129#else
130#define DBG(dev, fmt, args...) \
131 do { } while (0)
132#endif /* DEBUG */
133
134#ifdef VERBOSE_DEBUG
135#define VDBG DBG
136#else
137#define VDBG(dev, fmt, args...) \
138 do { } while (0)
139#endif /* DEBUG */
140
141#define ERROR(dev, fmt, args...) \
142 xprintk(dev , KERN_ERR , fmt , ## args)
143#define WARN(dev, fmt, args...) \
144 xprintk(dev , KERN_WARNING , fmt , ## args)
145#define INFO(dev, fmt, args...) \
146 xprintk(dev , KERN_INFO , fmt , ## args)
147
148/*-------------------------------------------------------------------------*/
149
150/* NETWORK DRIVER HOOKUP (to the layer above this driver) */
151
152static int eth_change_mtu(struct net_device *net, int new_mtu)
153{
154 struct eth_dev *dev = netdev_priv(net);
155 unsigned long flags;
156 int status = 0;
157
158 /* don't change MTU on "live" link (peer won't know) */
159 spin_lock_irqsave(&dev->lock, flags);
160 if (dev->port_usb)
161 status = -EBUSY;
162 else if (new_mtu <= ETH_HLEN || new_mtu > ETH_FRAME_LEN)
163 status = -ERANGE;
164 else
165 net->mtu = new_mtu;
166 spin_unlock_irqrestore(&dev->lock, flags);
167
168 return status;
169}
170
171static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
172{
173 struct eth_dev *dev = netdev_priv(net);
174
175 strlcpy(p->driver, "g_ether", sizeof p->driver);
176 strlcpy(p->version, DRIVER_VERSION, sizeof p->version);
177 strlcpy(p->fw_version, dev->gadget->name, sizeof p->fw_version);
178 strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof p->bus_info);
179}
180
181static u32 eth_get_link(struct net_device *net)
182{
183 struct eth_dev *dev = netdev_priv(net);
184 return dev->gadget->speed != USB_SPEED_UNKNOWN;
185}
186
187/* REVISIT can also support:
188 * - WOL (by tracking suspends and issuing remote wakeup)
189 * - msglevel (implies updated messaging)
190 * - ... probably more ethtool ops
191 */
192
193static struct ethtool_ops ops = {
194 .get_drvinfo = eth_get_drvinfo,
195 .get_link = eth_get_link
196};
197
198static void defer_kevent(struct eth_dev *dev, int flag)
199{
200 if (test_and_set_bit(flag, &dev->todo))
201 return;
202 if (!schedule_work(&dev->work))
203 ERROR(dev, "kevent %d may have been dropped\n", flag);
204 else
205 DBG(dev, "kevent %d scheduled\n", flag);
206}
207
208static void rx_complete(struct usb_ep *ep, struct usb_request *req);
209
210static int
211rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
212{
213 struct sk_buff *skb;
214 int retval = -ENOMEM;
215 size_t size = 0;
216 struct usb_ep *out;
217 unsigned long flags;
218
219 spin_lock_irqsave(&dev->lock, flags);
220 if (dev->port_usb)
221 out = dev->port_usb->out_ep;
222 else
223 out = NULL;
224 spin_unlock_irqrestore(&dev->lock, flags);
225
226 if (!out)
227 return -ENOTCONN;
228
229
230 /* Padding up to RX_EXTRA handles minor disagreements with host.
231 * Normally we use the USB "terminate on short read" convention;
232 * so allow up to (N*maxpacket), since that memory is normally
233 * already allocated. Some hardware doesn't deal well with short
234 * reads (e.g. DMA must be N*maxpacket), so for now don't trim a
235 * byte off the end (to force hardware errors on overflow).
236 *
237 * RNDIS uses internal framing, and explicitly allows senders to
238 * pad to end-of-packet. That's potentially nice for speed, but
239 * means receivers can't recover lost synch on their own (because
240 * new packets don't only start after a short RX).
241 */
242 size += sizeof(struct ethhdr) + dev->net->mtu + RX_EXTRA;
243 size += dev->port_usb->header_len;
244 size += out->maxpacket - 1;
245 size -= size % out->maxpacket;
246
247 skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags);
248 if (skb == NULL) {
249 DBG(dev, "no rx skb\n");
250 goto enomem;
251 }
252
253 /* Some platforms perform better when IP packets are aligned,
254 * but on at least one, checksumming fails otherwise. Note:
255 * RNDIS headers involve variable numbers of LE32 values.
256 */
257 skb_reserve(skb, NET_IP_ALIGN);
258
259 req->buf = skb->data;
260 req->length = size;
261 req->complete = rx_complete;
262 req->context = skb;
263
264 retval = usb_ep_queue(out, req, gfp_flags);
265 if (retval == -ENOMEM)
266enomem:
267 defer_kevent(dev, WORK_RX_MEMORY);
268 if (retval) {
269 DBG(dev, "rx submit --> %d\n", retval);
270 if (skb)
271 dev_kfree_skb_any(skb);
272 spin_lock_irqsave(&dev->req_lock, flags);
273 list_add(&req->list, &dev->rx_reqs);
274 spin_unlock_irqrestore(&dev->req_lock, flags);
275 }
276 return retval;
277}
278
279static void rx_complete(struct usb_ep *ep, struct usb_request *req)
280{
281 struct sk_buff *skb = req->context;
282 struct eth_dev *dev = ep->driver_data;
283 int status = req->status;
284
285 switch (status) {
286
287 /* normal completion */
288 case 0:
289 skb_put(skb, req->actual);
290 if (dev->unwrap)
291 status = dev->unwrap(skb);
292 if (status < 0
293 || ETH_HLEN > skb->len
294 || skb->len > ETH_FRAME_LEN) {
295 dev->net->stats.rx_errors++;
296 dev->net->stats.rx_length_errors++;
297 DBG(dev, "rx length %d\n", skb->len);
298 break;
299 }
300
301 skb->protocol = eth_type_trans(skb, dev->net);
302 dev->net->stats.rx_packets++;
303 dev->net->stats.rx_bytes += skb->len;
304
305 /* no buffer copies needed, unless hardware can't
306 * use skb buffers.
307 */
308 status = netif_rx(skb);
309 skb = NULL;
310 break;
311
312 /* software-driven interface shutdown */
313 case -ECONNRESET: /* unlink */
314 case -ESHUTDOWN: /* disconnect etc */
315 VDBG(dev, "rx shutdown, code %d\n", status);
316 goto quiesce;
317
318 /* for hardware automagic (such as pxa) */
319 case -ECONNABORTED: /* endpoint reset */
320 DBG(dev, "rx %s reset\n", ep->name);
321 defer_kevent(dev, WORK_RX_MEMORY);
322quiesce:
323 dev_kfree_skb_any(skb);
324 goto clean;
325
326 /* data overrun */
327 case -EOVERFLOW:
328 dev->net->stats.rx_over_errors++;
329 /* FALLTHROUGH */
330
331 default:
332 dev->net->stats.rx_errors++;
333 DBG(dev, "rx status %d\n", status);
334 break;
335 }
336
337 if (skb)
338 dev_kfree_skb_any(skb);
339 if (!netif_running(dev->net)) {
340clean:
341 spin_lock(&dev->req_lock);
342 list_add(&req->list, &dev->rx_reqs);
343 spin_unlock(&dev->req_lock);
344 req = NULL;
345 }
346 if (req)
347 rx_submit(dev, req, GFP_ATOMIC);
348}
349
350static int prealloc(struct list_head *list, struct usb_ep *ep, unsigned n)
351{
352 unsigned i;
353 struct usb_request *req;
354
355 if (!n)
356 return -ENOMEM;
357
358 /* queue/recycle up to N requests */
359 i = n;
360 list_for_each_entry(req, list, list) {
361 if (i-- == 0)
362 goto extra;
363 }
364 while (i--) {
365 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
366 if (!req)
367 return list_empty(list) ? -ENOMEM : 0;
368 list_add(&req->list, list);
369 }
370 return 0;
371
372extra:
373 /* free extras */
374 for (;;) {
375 struct list_head *next;
376
377 next = req->list.next;
378 list_del(&req->list);
379 usb_ep_free_request(ep, req);
380
381 if (next == list)
382 break;
383
384 req = container_of(next, struct usb_request, list);
385 }
386 return 0;
387}
388
389static int alloc_requests(struct eth_dev *dev, struct gether *link, unsigned n)
390{
391 int status;
392
393 spin_lock(&dev->req_lock);
394 status = prealloc(&dev->tx_reqs, link->in_ep, n);
395 if (status < 0)
396 goto fail;
397 status = prealloc(&dev->rx_reqs, link->out_ep, n);
398 if (status < 0)
399 goto fail;
400 goto done;
401fail:
402 DBG(dev, "can't alloc requests\n");
403done:
404 spin_unlock(&dev->req_lock);
405 return status;
406}
407
408static void rx_fill(struct eth_dev *dev, gfp_t gfp_flags)
409{
410 struct usb_request *req;
411 unsigned long flags;
412
413 /* fill unused rxq slots with some skb */
414 spin_lock_irqsave(&dev->req_lock, flags);
415 while (!list_empty(&dev->rx_reqs)) {
416 req = container_of(dev->rx_reqs.next,
417 struct usb_request, list);
418 list_del_init(&req->list);
419 spin_unlock_irqrestore(&dev->req_lock, flags);
420
421 if (rx_submit(dev, req, gfp_flags) < 0) {
422 defer_kevent(dev, WORK_RX_MEMORY);
423 return;
424 }
425
426 spin_lock_irqsave(&dev->req_lock, flags);
427 }
428 spin_unlock_irqrestore(&dev->req_lock, flags);
429}
430
431static void eth_work(struct work_struct *work)
432{
433 struct eth_dev *dev = container_of(work, struct eth_dev, work);
434
435 if (test_and_clear_bit(WORK_RX_MEMORY, &dev->todo)) {
436 if (netif_running(dev->net))
437 rx_fill(dev, GFP_KERNEL);
438 }
439
440 if (dev->todo)
441 DBG(dev, "work done, flags = 0x%lx\n", dev->todo);
442}
443
444static void tx_complete(struct usb_ep *ep, struct usb_request *req)
445{
446 struct sk_buff *skb = req->context;
447 struct eth_dev *dev = ep->driver_data;
448
449 switch (req->status) {
450 default:
451 dev->net->stats.tx_errors++;
452 VDBG(dev, "tx err %d\n", req->status);
453 /* FALLTHROUGH */
454 case -ECONNRESET: /* unlink */
455 case -ESHUTDOWN: /* disconnect etc */
456 break;
457 case 0:
458 dev->net->stats.tx_bytes += skb->len;
459 }
460 dev->net->stats.tx_packets++;
461
462 spin_lock(&dev->req_lock);
463 list_add(&req->list, &dev->tx_reqs);
464 spin_unlock(&dev->req_lock);
465 dev_kfree_skb_any(skb);
466
467 atomic_dec(&dev->tx_qlen);
468 if (netif_carrier_ok(dev->net))
469 netif_wake_queue(dev->net);
470}
471
472static inline int is_promisc(u16 cdc_filter)
473{
474 return cdc_filter & USB_CDC_PACKET_TYPE_PROMISCUOUS;
475}
476
477static int eth_start_xmit(struct sk_buff *skb, struct net_device *net)
478{
479 struct eth_dev *dev = netdev_priv(net);
480 int length = skb->len;
481 int retval;
482 struct usb_request *req = NULL;
483 unsigned long flags;
484 struct usb_ep *in;
485 u16 cdc_filter;
486
487 spin_lock_irqsave(&dev->lock, flags);
488 if (dev->port_usb) {
489 in = dev->port_usb->in_ep;
490 cdc_filter = dev->port_usb->cdc_filter;
491 } else {
492 in = NULL;
493 cdc_filter = 0;
494 }
495 spin_unlock_irqrestore(&dev->lock, flags);
496
497 if (!in) {
498 dev_kfree_skb_any(skb);
499 return 0;
500 }
501
502 /* apply outgoing CDC or RNDIS filters */
503 if (!is_promisc(cdc_filter)) {
504 u8 *dest = skb->data;
505
506 if (is_multicast_ether_addr(dest)) {
507 u16 type;
508
509 /* ignores USB_CDC_PACKET_TYPE_MULTICAST and host
510 * SET_ETHERNET_MULTICAST_FILTERS requests
511 */
512 if (is_broadcast_ether_addr(dest))
513 type = USB_CDC_PACKET_TYPE_BROADCAST;
514 else
515 type = USB_CDC_PACKET_TYPE_ALL_MULTICAST;
516 if (!(cdc_filter & type)) {
517 dev_kfree_skb_any(skb);
518 return 0;
519 }
520 }
521 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */
522 }
523
524 spin_lock_irqsave(&dev->req_lock, flags);
525 /*
526 * this freelist can be empty if an interrupt triggered disconnect()
527 * and reconfigured the gadget (shutting down this queue) after the
528 * network stack decided to xmit but before we got the spinlock.
529 */
530 if (list_empty(&dev->tx_reqs)) {
531 spin_unlock_irqrestore(&dev->req_lock, flags);
532 return 1;
533 }
534
535 req = container_of(dev->tx_reqs.next, struct usb_request, list);
536 list_del(&req->list);
537
538 /* temporarily stop TX queue when the freelist empties */
539 if (list_empty(&dev->tx_reqs))
540 netif_stop_queue(net);
541 spin_unlock_irqrestore(&dev->req_lock, flags);
542
543 /* no buffer copies needed, unless the network stack did it
544 * or the hardware can't use skb buffers.
545 * or there's not enough space for extra headers we need
546 */
547 if (dev->wrap) {
548 struct sk_buff *skb_new;
549
550 skb_new = dev->wrap(skb);
551 if (!skb_new)
552 goto drop;
553
554 dev_kfree_skb_any(skb);
555 skb = skb_new;
556 length = skb->len;
557 }
558 req->buf = skb->data;
559 req->context = skb;
560 req->complete = tx_complete;
561
562 /* use zlp framing on tx for strict CDC-Ether conformance,
563 * though any robust network rx path ignores extra padding.
564 * and some hardware doesn't like to write zlps.
565 */
566 req->zero = 1;
567 if (!dev->zlp && (length % in->maxpacket) == 0)
568 length++;
569
570 req->length = length;
571
572 /* throttle highspeed IRQ rate back slightly */
573 if (gadget_is_dualspeed(dev->gadget))
574 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH)
575 ? ((atomic_read(&dev->tx_qlen) % qmult) != 0)
576 : 0;
577
578 retval = usb_ep_queue(in, req, GFP_ATOMIC);
579 switch (retval) {
580 default:
581 DBG(dev, "tx queue err %d\n", retval);
582 break;
583 case 0:
584 net->trans_start = jiffies;
585 atomic_inc(&dev->tx_qlen);
586 }
587
588 if (retval) {
589drop:
590 dev->net->stats.tx_dropped++;
591 dev_kfree_skb_any(skb);
592 spin_lock_irqsave(&dev->req_lock, flags);
593 if (list_empty(&dev->tx_reqs))
594 netif_start_queue(net);
595 list_add(&req->list, &dev->tx_reqs);
596 spin_unlock_irqrestore(&dev->req_lock, flags);
597 }
598 return 0;
599}
600
601/*-------------------------------------------------------------------------*/
602
603static void eth_start(struct eth_dev *dev, gfp_t gfp_flags)
604{
605 DBG(dev, "%s\n", __func__);
606
607 /* fill the rx queue */
608 rx_fill(dev, gfp_flags);
609
610 /* and open the tx floodgates */
611 atomic_set(&dev->tx_qlen, 0);
612 netif_wake_queue(dev->net);
613}
614
615static int eth_open(struct net_device *net)
616{
617 struct eth_dev *dev = netdev_priv(net);
618 struct gether *link;
619
620 DBG(dev, "%s\n", __func__);
621 if (netif_carrier_ok(dev->net))
622 eth_start(dev, GFP_KERNEL);
623
624 spin_lock_irq(&dev->lock);
625 link = dev->port_usb;
626 if (link && link->open)
627 link->open(link);
628 spin_unlock_irq(&dev->lock);
629
630 return 0;
631}
632
633static int eth_stop(struct net_device *net)
634{
635 struct eth_dev *dev = netdev_priv(net);
636 unsigned long flags;
637
638 VDBG(dev, "%s\n", __func__);
639 netif_stop_queue(net);
640
641 DBG(dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld\n",
642 dev->net->stats.rx_packets, dev->net->stats.tx_packets,
643 dev->net->stats.rx_errors, dev->net->stats.tx_errors
644 );
645
646 /* ensure there are no more active requests */
647 spin_lock_irqsave(&dev->lock, flags);
648 if (dev->port_usb) {
649 struct gether *link = dev->port_usb;
650
651 if (link->close)
652 link->close(link);
653
654 /* NOTE: we have no abort-queue primitive we could use
655 * to cancel all pending I/O. Instead, we disable then
656 * reenable the endpoints ... this idiom may leave toggle
657 * wrong, but that's a self-correcting error.
658 *
659 * REVISIT: we *COULD* just let the transfers complete at
660 * their own pace; the network stack can handle old packets.
661 * For the moment we leave this here, since it works.
662 */
663 usb_ep_disable(link->in_ep);
664 usb_ep_disable(link->out_ep);
665 if (netif_carrier_ok(net)) {
666 DBG(dev, "host still using in/out endpoints\n");
667 usb_ep_enable(link->in_ep, link->in);
668 usb_ep_enable(link->out_ep, link->out);
669 }
670 }
671 spin_unlock_irqrestore(&dev->lock, flags);
672
673 return 0;
674}
675
676/*-------------------------------------------------------------------------*/
677
678/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
679static char *dev_addr;
680module_param(dev_addr, charp, S_IRUGO);
681MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
682
683/* this address is invisible to ifconfig */
684static char *host_addr;
685module_param(host_addr, charp, S_IRUGO);
686MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
687
688
689static u8 __init nibble(unsigned char c)
690{
691 if (isdigit(c))
692 return c - '0';
693 c = toupper(c);
694 if (isxdigit(c))
695 return 10 + c - 'A';
696 return 0;
697}
698
699static int __init get_ether_addr(const char *str, u8 *dev_addr)
700{
701 if (str) {
702 unsigned i;
703
704 for (i = 0; i < 6; i++) {
705 unsigned char num;
706
707 if ((*str == '.') || (*str == ':'))
708 str++;
709 num = nibble(*str++) << 4;
710 num |= (nibble(*str++));
711 dev_addr [i] = num;
712 }
713 if (is_valid_ether_addr(dev_addr))
714 return 0;
715 }
716 random_ether_addr(dev_addr);
717 return 1;
718}
719
720static struct eth_dev *the_dev;
721
722
723/**
724 * gether_setup - initialize one ethernet-over-usb link
725 * @g: gadget to associated with these links
726 * @ethaddr: NULL, or a buffer in which the ethernet address of the
727 * host side of the link is recorded
728 * Context: may sleep
729 *
730 * This sets up the single network link that may be exported by a
731 * gadget driver using this framework. The link layer addresses are
732 * set up using module parameters.
733 *
734 * Returns negative errno, or zero on success
735 */
736int __init gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
737{
738 struct eth_dev *dev;
739 struct net_device *net;
740 int status;
741
742 if (the_dev)
743 return -EBUSY;
744
745 net = alloc_etherdev(sizeof *dev);
746 if (!net)
747 return -ENOMEM;
748
749 dev = netdev_priv(net);
750 spin_lock_init(&dev->lock);
751 spin_lock_init(&dev->req_lock);
752 INIT_WORK(&dev->work, eth_work);
753 INIT_LIST_HEAD(&dev->tx_reqs);
754 INIT_LIST_HEAD(&dev->rx_reqs);
755
756 /* network device setup */
757 dev->net = net;
758 strcpy(net->name, "usb%d");
759
760 if (get_ether_addr(dev_addr, net->dev_addr))
761 dev_warn(&g->dev,
762 "using random %s ethernet address\n", "self");
763 if (get_ether_addr(host_addr, dev->host_mac))
764 dev_warn(&g->dev,
765 "using random %s ethernet address\n", "host");
766
767 if (ethaddr)
768 memcpy(ethaddr, dev->host_mac, ETH_ALEN);
769
770 net->change_mtu = eth_change_mtu;
771 net->hard_start_xmit = eth_start_xmit;
772 net->open = eth_open;
773 net->stop = eth_stop;
774 /* watchdog_timeo, tx_timeout ... */
775 /* set_multicast_list */
776 SET_ETHTOOL_OPS(net, &ops);
777
778 /* two kinds of host-initiated state changes:
779 * - iff DATA transfer is active, carrier is "on"
780 * - tx queueing enabled if open *and* carrier is "on"
781 */
782 netif_stop_queue(net);
783 netif_carrier_off(net);
784
785 dev->gadget = g;
786 SET_NETDEV_DEV(net, &g->dev);
787
788 status = register_netdev(net);
789 if (status < 0) {
790 dev_dbg(&g->dev, "register_netdev failed, %d\n", status);
791 free_netdev(net);
792 } else {
793 DECLARE_MAC_BUF(tmp);
794
795 INFO(dev, "MAC %s\n", print_mac(tmp, net->dev_addr));
796 INFO(dev, "HOST MAC %s\n", print_mac(tmp, dev->host_mac));
797
798 the_dev = dev;
799 }
800
801 return status;
802}
803
804/**
805 * gether_cleanup - remove Ethernet-over-USB device
806 * Context: may sleep
807 *
808 * This is called to free all resources allocated by @gether_setup().
809 */
810void gether_cleanup(void)
811{
812 if (!the_dev)
813 return;
814
815 unregister_netdev(the_dev->net);
816 free_netdev(the_dev->net);
817
818 /* assuming we used keventd, it must quiesce too */
819 flush_scheduled_work();
820
821 the_dev = NULL;
822}
823
824
825/**
826 * gether_connect - notify network layer that USB link is active
827 * @link: the USB link, set up with endpoints, descriptors matching
828 * current device speed, and any framing wrapper(s) set up.
829 * Context: irqs blocked
830 *
831 * This is called to activate endpoints and let the network layer know
832 * the connection is active ("carrier detect"). It may cause the I/O
833 * queues to open and start letting network packets flow, but will in
834 * any case activate the endpoints so that they respond properly to the
835 * USB host.
836 *
837 * Verify net_device pointer returned using IS_ERR(). If it doesn't
838 * indicate some error code (negative errno), ep->driver_data values
839 * have been overwritten.
840 */
841struct net_device *gether_connect(struct gether *link)
842{
843 struct eth_dev *dev = the_dev;
844 int result = 0;
845
846 if (!dev)
847 return ERR_PTR(-EINVAL);
848
849 link->in_ep->driver_data = dev;
850 result = usb_ep_enable(link->in_ep, link->in);
851 if (result != 0) {
852 DBG(dev, "enable %s --> %d\n",
853 link->in_ep->name, result);
854 goto fail0;
855 }
856
857 link->out_ep->driver_data = dev;
858 result = usb_ep_enable(link->out_ep, link->out);
859 if (result != 0) {
860 DBG(dev, "enable %s --> %d\n",
861 link->out_ep->name, result);
862 goto fail1;
863 }
864
865 if (result == 0)
866 result = alloc_requests(dev, link, qlen(dev->gadget));
867
868 if (result == 0) {
869 dev->zlp = link->is_zlp_ok;
870 DBG(dev, "qlen %d\n", qlen(dev->gadget));
871
872 dev->header_len = link->header_len;
873 dev->unwrap = link->unwrap;
874 dev->wrap = link->wrap;
875
876 spin_lock(&dev->lock);
877 dev->port_usb = link;
878 link->ioport = dev;
879 spin_unlock(&dev->lock);
880
881 netif_carrier_on(dev->net);
882 if (netif_running(dev->net))
883 eth_start(dev, GFP_ATOMIC);
884
885 /* on error, disable any endpoints */
886 } else {
887 (void) usb_ep_disable(link->out_ep);
888fail1:
889 (void) usb_ep_disable(link->in_ep);
890 }
891fail0:
892 /* caller is responsible for cleanup on error */
893 if (result < 0)
894 return ERR_PTR(result);
895 return dev->net;
896}
897
898/**
899 * gether_disconnect - notify network layer that USB link is inactive
900 * @link: the USB link, on which gether_connect() was called
901 * Context: irqs blocked
902 *
903 * This is called to deactivate endpoints and let the network layer know
904 * the connection went inactive ("no carrier").
905 *
906 * On return, the state is as if gether_connect() had never been called.
907 * The endpoints are inactive, and accordingly without active USB I/O.
908 * Pointers to endpoint descriptors and endpoint private data are nulled.
909 */
910void gether_disconnect(struct gether *link)
911{
912 struct eth_dev *dev = link->ioport;
913 struct usb_request *req;
914
915 WARN_ON(!dev);
916 if (!dev)
917 return;
918
919 DBG(dev, "%s\n", __func__);
920
921 netif_stop_queue(dev->net);
922 netif_carrier_off(dev->net);
923
924 /* disable endpoints, forcing (synchronous) completion
925 * of all pending i/o. then free the request objects
926 * and forget about the endpoints.
927 */
928 usb_ep_disable(link->in_ep);
929 spin_lock(&dev->req_lock);
930 while (!list_empty(&dev->tx_reqs)) {
931 req = container_of(dev->tx_reqs.next,
932 struct usb_request, list);
933 list_del(&req->list);
934
935 spin_unlock(&dev->req_lock);
936 usb_ep_free_request(link->in_ep, req);
937 spin_lock(&dev->req_lock);
938 }
939 spin_unlock(&dev->req_lock);
940 link->in_ep->driver_data = NULL;
941 link->in = NULL;
942
943 usb_ep_disable(link->out_ep);
944 spin_lock(&dev->req_lock);
945 while (!list_empty(&dev->rx_reqs)) {
946 req = container_of(dev->rx_reqs.next,
947 struct usb_request, list);
948 list_del(&req->list);
949
950 spin_unlock(&dev->req_lock);
951 usb_ep_free_request(link->out_ep, req);
952 spin_lock(&dev->req_lock);
953 }
954 spin_unlock(&dev->req_lock);
955 link->out_ep->driver_data = NULL;
956 link->out = NULL;
957
958 /* finish forgetting about this USB link episode */
959 dev->header_len = 0;
960 dev->unwrap = NULL;
961 dev->wrap = NULL;
962
963 spin_lock(&dev->lock);
964 dev->port_usb = NULL;
965 link->ioport = NULL;
966 spin_unlock(&dev->lock);
967}
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h
new file mode 100644
index 000000000000..0d1f7ae3b071
--- /dev/null
+++ b/drivers/usb/gadget/u_ether.h
@@ -0,0 +1,127 @@
1/*
2 * u_ether.h -- interface to USB gadget "ethernet link" utilities
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef __U_ETHER_H
24#define __U_ETHER_H
25
26#include <linux/err.h>
27#include <linux/if_ether.h>
28#include <linux/usb/composite.h>
29#include <linux/usb/cdc.h>
30
31#include "gadget_chips.h"
32
33
34/*
35 * This represents the USB side of an "ethernet" link, managed by a USB
36 * function which provides control and (maybe) framing. Two functions
37 * in different configurations could share the same ethernet link/netdev,
38 * using different host interaction models.
39 *
40 * There is a current limitation that only one instance of this link may
41 * be present in any given configuration. When that's a problem, network
42 * layer facilities can be used to package multiple logical links on this
43 * single "physical" one.
44 */
45struct gether {
46 struct usb_function func;
47
48 /* updated by gether_{connect,disconnect} */
49 struct eth_dev *ioport;
50
51 /* endpoints handle full and/or high speeds */
52 struct usb_ep *in_ep;
53 struct usb_ep *out_ep;
54
55 /* descriptors match device speed at gether_connect() time */
56 struct usb_endpoint_descriptor *in;
57 struct usb_endpoint_descriptor *out;
58
59 bool is_zlp_ok;
60
61 u16 cdc_filter;
62
63 /* hooks for added framing, as needed for RNDIS and EEM.
64 * we currently don't support multiple frames per SKB.
65 */
66 u32 header_len;
67 struct sk_buff *(*wrap)(struct sk_buff *skb);
68 int (*unwrap)(struct sk_buff *skb);
69
70 /* called on network open/close */
71 void (*open)(struct gether *);
72 void (*close)(struct gether *);
73};
74
75#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
76 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
77 |USB_CDC_PACKET_TYPE_PROMISCUOUS \
78 |USB_CDC_PACKET_TYPE_DIRECTED)
79
80
81/* netdev setup/teardown as directed by the gadget driver */
82int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]);
83void gether_cleanup(void);
84
85/* connect/disconnect is handled by individual functions */
86struct net_device *gether_connect(struct gether *);
87void gether_disconnect(struct gether *);
88
89/* Some controllers can't support CDC Ethernet (ECM) ... */
90static inline bool can_support_ecm(struct usb_gadget *gadget)
91{
92 if (!gadget_supports_altsettings(gadget))
93 return false;
94
95 /* SA1100 can do ECM, *without* status endpoint ... but we'll
96 * only use it in non-ECM mode for backwards compatibility
97 * (and since we currently require a status endpoint)
98 */
99 if (gadget_is_sa1100(gadget))
100 return false;
101
102 /* Everything else is *presumably* fine ... but this is a bit
103 * chancy, so be **CERTAIN** there are no hardware issues with
104 * your controller. Add it above if it can't handle CDC.
105 */
106 return true;
107}
108
109/* each configuration may bind one instance of an ethernet link */
110int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
111int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
112
113#ifdef CONFIG_USB_ETH_RNDIS
114
115int rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
116
117#else
118
119static inline int
120rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
121{
122 return 0;
123}
124
125#endif
126
127#endif /* __U_ETHER_H */
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
new file mode 100644
index 000000000000..abf9505d3a75
--- /dev/null
+++ b/drivers/usb/gadget/u_serial.c
@@ -0,0 +1,1246 @@
1/*
2 * u_serial.c - utilities for USB gadget "serial port"/TTY support
3 *
4 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
5 * Copyright (C) 2008 David Brownell
6 * Copyright (C) 2008 by Nokia Corporation
7 *
8 * This code also borrows from usbserial.c, which is
9 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
10 * Copyright (C) 2000 Peter Berger (pberger@brimson.com)
11 * Copyright (C) 2000 Al Borchers (alborchers@steinerpoint.com)
12 *
13 * This software is distributed under the terms of the GNU General
14 * Public License ("GPL") as published by the Free Software Foundation,
15 * either version 2 of that License or (at your option) any later version.
16 */
17
18/* #define VERBOSE_DEBUG */
19
20#include <linux/kernel.h>
21#include <linux/interrupt.h>
22#include <linux/device.h>
23#include <linux/delay.h>
24#include <linux/tty.h>
25#include <linux/tty_flip.h>
26
27#include "u_serial.h"
28
29
30/*
31 * This component encapsulates the TTY layer glue needed to provide basic
32 * "serial port" functionality through the USB gadget stack. Each such
33 * port is exposed through a /dev/ttyGS* node.
34 *
35 * After initialization (gserial_setup), these TTY port devices stay
36 * available until they are removed (gserial_cleanup). Each one may be
37 * connected to a USB function (gserial_connect), or disconnected (with
38 * gserial_disconnect) when the USB host issues a config change event.
39 * Data can only flow when the port is connected to the host.
40 *
41 * A given TTY port can be made available in multiple configurations.
42 * For example, each one might expose a ttyGS0 node which provides a
43 * login application. In one case that might use CDC ACM interface 0,
44 * while another configuration might use interface 3 for that. The
45 * work to handle that (including descriptor management) is not part
46 * of this component.
47 *
48 * Configurations may expose more than one TTY port. For example, if
49 * ttyGS0 provides login service, then ttyGS1 might provide dialer access
50 * for a telephone or fax link. And ttyGS2 might be something that just
51 * needs a simple byte stream interface for some messaging protocol that
52 * is managed in userspace ... OBEX, PTP, and MTP have been mentioned.
53 */
54
55/*
56 * gserial is the lifecycle interface, used by USB functions
57 * gs_port is the I/O nexus, used by the tty driver
58 * tty_struct links to the tty/filesystem framework
59 *
60 * gserial <---> gs_port ... links will be null when the USB link is
61 * inactive; managed by gserial_{connect,disconnect}().
62 * gserial->ioport == usb_ep->driver_data ... gs_port
63 * gs_port->port_usb ... gserial
64 *
65 * gs_port <---> tty_struct ... links will be null when the TTY file
66 * isn't opened; managed by gs_open()/gs_close()
67 * gserial->port_tty ... tty_struct
68 * tty_struct->driver_data ... gserial
69 */
70
71/* RX and TX queues can buffer QUEUE_SIZE packets before they hit the
72 * next layer of buffering. For TX that's a circular buffer; for RX
73 * consider it a NOP. A third layer is provided by the TTY code.
74 */
75#define QUEUE_SIZE 16
76#define WRITE_BUF_SIZE 8192 /* TX only */
77
78/* circular buffer */
79struct gs_buf {
80 unsigned buf_size;
81 char *buf_buf;
82 char *buf_get;
83 char *buf_put;
84};
85
86/*
87 * The port structure holds info for each port, one for each minor number
88 * (and thus for each /dev/ node).
89 */
90struct gs_port {
91 spinlock_t port_lock; /* guard port_* access */
92
93 struct gserial *port_usb;
94 struct tty_struct *port_tty;
95
96 unsigned open_count;
97 bool openclose; /* open/close in progress */
98 u8 port_num;
99
100 wait_queue_head_t close_wait; /* wait for last close */
101
102 struct list_head read_pool;
103 struct tasklet_struct push;
104
105 struct list_head write_pool;
106 struct gs_buf port_write_buf;
107 wait_queue_head_t drain_wait; /* wait while writes drain */
108
109 /* REVISIT this state ... */
110 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
111};
112
113/* increase N_PORTS if you need more */
114#define N_PORTS 4
115static struct portmaster {
116 struct mutex lock; /* protect open/close */
117 struct gs_port *port;
118} ports[N_PORTS];
119static unsigned n_ports;
120
121#define GS_CLOSE_TIMEOUT 15 /* seconds */
122
123
124
125#ifdef VERBOSE_DEBUG
126#define pr_vdebug(fmt, arg...) \
127 pr_debug(fmt, ##arg)
128#else
129#define pr_vdebug(fmt, arg...) \
130 ({ if (0) pr_debug(fmt, ##arg); })
131#endif
132
133/*-------------------------------------------------------------------------*/
134
135/* Circular Buffer */
136
137/*
138 * gs_buf_alloc
139 *
140 * Allocate a circular buffer and all associated memory.
141 */
142static int gs_buf_alloc(struct gs_buf *gb, unsigned size)
143{
144 gb->buf_buf = kmalloc(size, GFP_KERNEL);
145 if (gb->buf_buf == NULL)
146 return -ENOMEM;
147
148 gb->buf_size = size;
149 gb->buf_put = gb->buf_buf;
150 gb->buf_get = gb->buf_buf;
151
152 return 0;
153}
154
155/*
156 * gs_buf_free
157 *
158 * Free the buffer and all associated memory.
159 */
160static void gs_buf_free(struct gs_buf *gb)
161{
162 kfree(gb->buf_buf);
163 gb->buf_buf = NULL;
164}
165
166/*
167 * gs_buf_clear
168 *
169 * Clear out all data in the circular buffer.
170 */
171static void gs_buf_clear(struct gs_buf *gb)
172{
173 gb->buf_get = gb->buf_put;
174 /* equivalent to a get of all data available */
175}
176
177/*
178 * gs_buf_data_avail
179 *
180 * Return the number of bytes of data available in the circular
181 * buffer.
182 */
183static unsigned gs_buf_data_avail(struct gs_buf *gb)
184{
185 return (gb->buf_size + gb->buf_put - gb->buf_get) % gb->buf_size;
186}
187
188/*
189 * gs_buf_space_avail
190 *
191 * Return the number of bytes of space available in the circular
192 * buffer.
193 */
194static unsigned gs_buf_space_avail(struct gs_buf *gb)
195{
196 return (gb->buf_size + gb->buf_get - gb->buf_put - 1) % gb->buf_size;
197}
198
199/*
200 * gs_buf_put
201 *
202 * Copy data data from a user buffer and put it into the circular buffer.
203 * Restrict to the amount of space available.
204 *
205 * Return the number of bytes copied.
206 */
207static unsigned
208gs_buf_put(struct gs_buf *gb, const char *buf, unsigned count)
209{
210 unsigned len;
211
212 len = gs_buf_space_avail(gb);
213 if (count > len)
214 count = len;
215
216 if (count == 0)
217 return 0;
218
219 len = gb->buf_buf + gb->buf_size - gb->buf_put;
220 if (count > len) {
221 memcpy(gb->buf_put, buf, len);
222 memcpy(gb->buf_buf, buf+len, count - len);
223 gb->buf_put = gb->buf_buf + count - len;
224 } else {
225 memcpy(gb->buf_put, buf, count);
226 if (count < len)
227 gb->buf_put += count;
228 else /* count == len */
229 gb->buf_put = gb->buf_buf;
230 }
231
232 return count;
233}
234
235/*
236 * gs_buf_get
237 *
238 * Get data from the circular buffer and copy to the given buffer.
239 * Restrict to the amount of data available.
240 *
241 * Return the number of bytes copied.
242 */
243static unsigned
244gs_buf_get(struct gs_buf *gb, char *buf, unsigned count)
245{
246 unsigned len;
247
248 len = gs_buf_data_avail(gb);
249 if (count > len)
250 count = len;
251
252 if (count == 0)
253 return 0;
254
255 len = gb->buf_buf + gb->buf_size - gb->buf_get;
256 if (count > len) {
257 memcpy(buf, gb->buf_get, len);
258 memcpy(buf+len, gb->buf_buf, count - len);
259 gb->buf_get = gb->buf_buf + count - len;
260 } else {
261 memcpy(buf, gb->buf_get, count);
262 if (count < len)
263 gb->buf_get += count;
264 else /* count == len */
265 gb->buf_get = gb->buf_buf;
266 }
267
268 return count;
269}
270
271/*-------------------------------------------------------------------------*/
272
273/* I/O glue between TTY (upper) and USB function (lower) driver layers */
274
275/*
276 * gs_alloc_req
277 *
278 * Allocate a usb_request and its buffer. Returns a pointer to the
279 * usb_request or NULL if there is an error.
280 */
281static struct usb_request *
282gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t kmalloc_flags)
283{
284 struct usb_request *req;
285
286 req = usb_ep_alloc_request(ep, kmalloc_flags);
287
288 if (req != NULL) {
289 req->length = len;
290 req->buf = kmalloc(len, kmalloc_flags);
291 if (req->buf == NULL) {
292 usb_ep_free_request(ep, req);
293 return NULL;
294 }
295 }
296
297 return req;
298}
299
300/*
301 * gs_free_req
302 *
303 * Free a usb_request and its buffer.
304 */
305static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
306{
307 kfree(req->buf);
308 usb_ep_free_request(ep, req);
309}
310
311/*
312 * gs_send_packet
313 *
314 * If there is data to send, a packet is built in the given
315 * buffer and the size is returned. If there is no data to
316 * send, 0 is returned.
317 *
318 * Called with port_lock held.
319 */
320static unsigned
321gs_send_packet(struct gs_port *port, char *packet, unsigned size)
322{
323 unsigned len;
324
325 len = gs_buf_data_avail(&port->port_write_buf);
326 if (len < size)
327 size = len;
328 if (size != 0)
329 size = gs_buf_get(&port->port_write_buf, packet, size);
330 return size;
331}
332
333/*
334 * gs_start_tx
335 *
336 * This function finds available write requests, calls
337 * gs_send_packet to fill these packets with data, and
338 * continues until either there are no more write requests
339 * available or no more data to send. This function is
340 * run whenever data arrives or write requests are available.
341 *
342 * Context: caller owns port_lock; port_usb is non-null.
343 */
344static int gs_start_tx(struct gs_port *port)
345/*
346__releases(&port->port_lock)
347__acquires(&port->port_lock)
348*/
349{
350 struct list_head *pool = &port->write_pool;
351 struct usb_ep *in = port->port_usb->in;
352 int status = 0;
353 bool do_tty_wake = false;
354
355 while (!list_empty(pool)) {
356 struct usb_request *req;
357 int len;
358
359 req = list_entry(pool->next, struct usb_request, list);
360 len = gs_send_packet(port, req->buf, in->maxpacket);
361 if (len == 0) {
362 wake_up_interruptible(&port->drain_wait);
363 break;
364 }
365 do_tty_wake = true;
366
367 req->length = len;
368 list_del(&req->list);
369
370#ifdef VERBOSE_DEBUG
371 pr_debug("%s: %s, len=%d, 0x%02x 0x%02x 0x%02x ...\n",
372 __func__, in->name, len, *((u8 *)req->buf),
373 *((u8 *)req->buf+1), *((u8 *)req->buf+2));
374#endif
375
376 /* Drop lock while we call out of driver; completions
377 * could be issued while we do so. Disconnection may
378 * happen too; maybe immediately before we queue this!
379 *
380 * NOTE that we may keep sending data for a while after
381 * the TTY closed (dev->ioport->port_tty is NULL).
382 */
383 spin_unlock(&port->port_lock);
384 status = usb_ep_queue(in, req, GFP_ATOMIC);
385 spin_lock(&port->port_lock);
386
387 if (status) {
388 pr_debug("%s: %s %s err %d\n",
389 __func__, "queue", in->name, status);
390 list_add(&req->list, pool);
391 break;
392 }
393
394 /* abort immediately after disconnect */
395 if (!port->port_usb)
396 break;
397 }
398
399 if (do_tty_wake && port->port_tty)
400 tty_wakeup(port->port_tty);
401 return status;
402}
403
404static void gs_rx_push(unsigned long _port)
405{
406 struct gs_port *port = (void *)_port;
407 struct tty_struct *tty = port->port_tty;
408
409 /* With low_latency, tty_flip_buffer_push() doesn't put its
410 * real work through a workqueue, so the ldisc has a better
411 * chance to keep up with peak USB data rates.
412 */
413 if (tty) {
414 tty_flip_buffer_push(tty);
415 wake_up_interruptible(&tty->read_wait);
416 }
417}
418
419/*
420 * gs_recv_packet
421 *
422 * Called for each USB packet received. Reads the packet
423 * header and stuffs the data in the appropriate tty buffer.
424 * Returns 0 if successful, or a negative error number.
425 *
426 * Called during USB completion routine, on interrupt time.
427 * With port_lock.
428 */
429static int gs_recv_packet(struct gs_port *port, char *packet, unsigned size)
430{
431 unsigned len;
432 struct tty_struct *tty;
433
434 /* I/O completions can continue for a while after close(), until the
435 * request queue empties. Just discard any data we receive, until
436 * something reopens this TTY ... as if there were no HW flow control.
437 */
438 tty = port->port_tty;
439 if (tty == NULL) {
440 pr_vdebug("%s: ttyGS%d, after close\n",
441 __func__, port->port_num);
442 return -EIO;
443 }
444
445 len = tty_insert_flip_string(tty, packet, size);
446 if (len > 0)
447 tasklet_schedule(&port->push);
448 if (len < size)
449 pr_debug("%s: ttyGS%d, drop %d bytes\n",
450 __func__, port->port_num, size - len);
451 return 0;
452}
453
454/*
455 * Context: caller owns port_lock, and port_usb is set
456 */
457static unsigned gs_start_rx(struct gs_port *port)
458/*
459__releases(&port->port_lock)
460__acquires(&port->port_lock)
461*/
462{
463 struct list_head *pool = &port->read_pool;
464 struct usb_ep *out = port->port_usb->out;
465 unsigned started = 0;
466
467 while (!list_empty(pool)) {
468 struct usb_request *req;
469 int status;
470 struct tty_struct *tty;
471
472 /* no more rx if closed or throttled */
473 tty = port->port_tty;
474 if (!tty || test_bit(TTY_THROTTLED, &tty->flags))
475 break;
476
477 req = list_entry(pool->next, struct usb_request, list);
478 list_del(&req->list);
479 req->length = out->maxpacket;
480
481 /* drop lock while we call out; the controller driver
482 * may need to call us back (e.g. for disconnect)
483 */
484 spin_unlock(&port->port_lock);
485 status = usb_ep_queue(out, req, GFP_ATOMIC);
486 spin_lock(&port->port_lock);
487
488 if (status) {
489 pr_debug("%s: %s %s err %d\n",
490 __func__, "queue", out->name, status);
491 list_add(&req->list, pool);
492 break;
493 }
494 started++;
495
496 /* abort immediately after disconnect */
497 if (!port->port_usb)
498 break;
499 }
500 return started;
501}
502
503static void gs_read_complete(struct usb_ep *ep, struct usb_request *req)
504{
505 int status;
506 struct gs_port *port = ep->driver_data;
507
508 spin_lock(&port->port_lock);
509 list_add(&req->list, &port->read_pool);
510
511 switch (req->status) {
512 case 0:
513 /* normal completion */
514 status = gs_recv_packet(port, req->buf, req->actual);
515 if (status && status != -EIO)
516 pr_debug("%s: %s %s err %d\n",
517 __func__, "recv", ep->name, status);
518 gs_start_rx(port);
519 break;
520
521 case -ESHUTDOWN:
522 /* disconnect */
523 pr_vdebug("%s: %s shutdown\n", __func__, ep->name);
524 break;
525
526 default:
527 /* presumably a transient fault */
528 pr_warning("%s: unexpected %s status %d\n",
529 __func__, ep->name, req->status);
530 gs_start_rx(port);
531 break;
532 }
533 spin_unlock(&port->port_lock);
534}
535
536static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
537{
538 struct gs_port *port = ep->driver_data;
539
540 spin_lock(&port->port_lock);
541 list_add(&req->list, &port->write_pool);
542
543 switch (req->status) {
544 default:
545 /* presumably a transient fault */
546 pr_warning("%s: unexpected %s status %d\n",
547 __func__, ep->name, req->status);
548 /* FALL THROUGH */
549 case 0:
550 /* normal completion */
551 gs_start_tx(port);
552 break;
553
554 case -ESHUTDOWN:
555 /* disconnect */
556 pr_vdebug("%s: %s shutdown\n", __func__, ep->name);
557 break;
558 }
559
560 spin_unlock(&port->port_lock);
561}
562
563static void gs_free_requests(struct usb_ep *ep, struct list_head *head)
564{
565 struct usb_request *req;
566
567 while (!list_empty(head)) {
568 req = list_entry(head->next, struct usb_request, list);
569 list_del(&req->list);
570 gs_free_req(ep, req);
571 }
572}
573
574static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head,
575 void (*fn)(struct usb_ep *, struct usb_request *))
576{
577 int i;
578 struct usb_request *req;
579
580 /* Pre-allocate up to QUEUE_SIZE transfers, but if we can't
581 * do quite that many this time, don't fail ... we just won't
582 * be as speedy as we might otherwise be.
583 */
584 for (i = 0; i < QUEUE_SIZE; i++) {
585 req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC);
586 if (!req)
587 return list_empty(head) ? -ENOMEM : 0;
588 req->complete = fn;
589 list_add_tail(&req->list, head);
590 }
591 return 0;
592}
593
594/**
595 * gs_start_io - start USB I/O streams
596 * @dev: encapsulates endpoints to use
597 * Context: holding port_lock; port_tty and port_usb are non-null
598 *
599 * We only start I/O when something is connected to both sides of
600 * this port. If nothing is listening on the host side, we may
601 * be pointlessly filling up our TX buffers and FIFO.
602 */
603static int gs_start_io(struct gs_port *port)
604{
605 struct list_head *head = &port->read_pool;
606 struct usb_ep *ep = port->port_usb->out;
607 int status;
608 unsigned started;
609
610 /* Allocate RX and TX I/O buffers. We can't easily do this much
611 * earlier (with GFP_KERNEL) because the requests are coupled to
612 * endpoints, as are the packet sizes we'll be using. Different
613 * configurations may use different endpoints with a given port;
614 * and high speed vs full speed changes packet sizes too.
615 */
616 status = gs_alloc_requests(ep, head, gs_read_complete);
617 if (status)
618 return status;
619
620 status = gs_alloc_requests(port->port_usb->in, &port->write_pool,
621 gs_write_complete);
622 if (status) {
623 gs_free_requests(ep, head);
624 return status;
625 }
626
627 /* queue read requests */
628 started = gs_start_rx(port);
629
630 /* unblock any pending writes into our circular buffer */
631 if (started) {
632 tty_wakeup(port->port_tty);
633 } else {
634 gs_free_requests(ep, head);
635 gs_free_requests(port->port_usb->in, &port->write_pool);
636 }
637
638 return started ? 0 : status;
639}
640
641/*-------------------------------------------------------------------------*/
642
643/* TTY Driver */
644
645/*
646 * gs_open sets up the link between a gs_port and its associated TTY.
647 * That link is broken *only* by TTY close(), and all driver methods
648 * know that.
649 */
650static int gs_open(struct tty_struct *tty, struct file *file)
651{
652 int port_num = tty->index;
653 struct gs_port *port;
654 int status;
655
656 if (port_num < 0 || port_num >= n_ports)
657 return -ENXIO;
658
659 do {
660 mutex_lock(&ports[port_num].lock);
661 port = ports[port_num].port;
662 if (!port)
663 status = -ENODEV;
664 else {
665 spin_lock_irq(&port->port_lock);
666
667 /* already open? Great. */
668 if (port->open_count) {
669 status = 0;
670 port->open_count++;
671
672 /* currently opening/closing? wait ... */
673 } else if (port->openclose) {
674 status = -EBUSY;
675
676 /* ... else we do the work */
677 } else {
678 status = -EAGAIN;
679 port->openclose = true;
680 }
681 spin_unlock_irq(&port->port_lock);
682 }
683 mutex_unlock(&ports[port_num].lock);
684
685 switch (status) {
686 default:
687 /* fully handled */
688 return status;
689 case -EAGAIN:
690 /* must do the work */
691 break;
692 case -EBUSY:
693 /* wait for EAGAIN task to finish */
694 msleep(1);
695 /* REVISIT could have a waitchannel here, if
696 * concurrent open performance is important
697 */
698 break;
699 }
700 } while (status != -EAGAIN);
701
702 /* Do the "real open" */
703 spin_lock_irq(&port->port_lock);
704
705 /* allocate circular buffer on first open */
706 if (port->port_write_buf.buf_buf == NULL) {
707
708 spin_unlock_irq(&port->port_lock);
709 status = gs_buf_alloc(&port->port_write_buf, WRITE_BUF_SIZE);
710 spin_lock_irq(&port->port_lock);
711
712 if (status) {
713 pr_debug("gs_open: ttyGS%d (%p,%p) no buffer\n",
714 port->port_num, tty, file);
715 port->openclose = false;
716 goto exit_unlock_port;
717 }
718 }
719
720 /* REVISIT if REMOVED (ports[].port NULL), abort the open
721 * to let rmmod work faster (but this way isn't wrong).
722 */
723
724 /* REVISIT maybe wait for "carrier detect" */
725
726 tty->driver_data = port;
727 port->port_tty = tty;
728
729 port->open_count = 1;
730 port->openclose = false;
731
732 /* low_latency means ldiscs work in tasklet context, without
733 * needing a workqueue schedule ... easier to keep up.
734 */
735 tty->low_latency = 1;
736
737 /* if connected, start the I/O stream */
738 if (port->port_usb) {
739 pr_debug("gs_open: start ttyGS%d\n", port->port_num);
740 gs_start_io(port);
741
742 /* REVISIT for ACM, issue "network connected" event */
743 }
744
745 pr_debug("gs_open: ttyGS%d (%p,%p)\n", port->port_num, tty, file);
746
747 status = 0;
748
749exit_unlock_port:
750 spin_unlock_irq(&port->port_lock);
751 return status;
752}
753
754static int gs_writes_finished(struct gs_port *p)
755{
756 int cond;
757
758 /* return true on disconnect or empty buffer */
759 spin_lock_irq(&p->port_lock);
760 cond = (p->port_usb == NULL) || !gs_buf_data_avail(&p->port_write_buf);
761 spin_unlock_irq(&p->port_lock);
762
763 return cond;
764}
765
766static void gs_close(struct tty_struct *tty, struct file *file)
767{
768 struct gs_port *port = tty->driver_data;
769
770 spin_lock_irq(&port->port_lock);
771
772 if (port->open_count != 1) {
773 if (port->open_count == 0)
774 WARN_ON(1);
775 else
776 --port->open_count;
777 goto exit;
778 }
779
780 pr_debug("gs_close: ttyGS%d (%p,%p) ...\n", port->port_num, tty, file);
781
782 /* mark port as closing but in use; we can drop port lock
783 * and sleep if necessary
784 */
785 port->openclose = true;
786 port->open_count = 0;
787
788 if (port->port_usb)
789 /* REVISIT for ACM, issue "network disconnected" event */;
790
791 /* wait for circular write buffer to drain, disconnect, or at
792 * most GS_CLOSE_TIMEOUT seconds; then discard the rest
793 */
794 if (gs_buf_data_avail(&port->port_write_buf) > 0
795 && port->port_usb) {
796 spin_unlock_irq(&port->port_lock);
797 wait_event_interruptible_timeout(port->drain_wait,
798 gs_writes_finished(port),
799 GS_CLOSE_TIMEOUT * HZ);
800 spin_lock_irq(&port->port_lock);
801 }
802
803 /* Iff we're disconnected, there can be no I/O in flight so it's
804 * ok to free the circular buffer; else just scrub it. And don't
805 * let the push tasklet fire again until we're re-opened.
806 */
807 if (port->port_usb == NULL)
808 gs_buf_free(&port->port_write_buf);
809 else
810 gs_buf_clear(&port->port_write_buf);
811
812 tasklet_kill(&port->push);
813
814 tty->driver_data = NULL;
815 port->port_tty = NULL;
816
817 port->openclose = false;
818
819 pr_debug("gs_close: ttyGS%d (%p,%p) done!\n",
820 port->port_num, tty, file);
821
822 wake_up_interruptible(&port->close_wait);
823exit:
824 spin_unlock_irq(&port->port_lock);
825}
826
827static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count)
828{
829 struct gs_port *port = tty->driver_data;
830 unsigned long flags;
831 int status;
832
833 pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n",
834 port->port_num, tty, count);
835
836 spin_lock_irqsave(&port->port_lock, flags);
837 if (count)
838 count = gs_buf_put(&port->port_write_buf, buf, count);
839 /* treat count == 0 as flush_chars() */
840 if (port->port_usb)
841 status = gs_start_tx(port);
842 spin_unlock_irqrestore(&port->port_lock, flags);
843
844 return count;
845}
846
847static int gs_put_char(struct tty_struct *tty, unsigned char ch)
848{
849 struct gs_port *port = tty->driver_data;
850 unsigned long flags;
851 int status;
852
853 pr_vdebug("gs_put_char: (%d,%p) char=0x%x, called from %p\n",
854 port->port_num, tty, ch, __builtin_return_address(0));
855
856 spin_lock_irqsave(&port->port_lock, flags);
857 status = gs_buf_put(&port->port_write_buf, &ch, 1);
858 spin_unlock_irqrestore(&port->port_lock, flags);
859
860 return status;
861}
862
863static void gs_flush_chars(struct tty_struct *tty)
864{
865 struct gs_port *port = tty->driver_data;
866 unsigned long flags;
867
868 pr_vdebug("gs_flush_chars: (%d,%p)\n", port->port_num, tty);
869
870 spin_lock_irqsave(&port->port_lock, flags);
871 if (port->port_usb)
872 gs_start_tx(port);
873 spin_unlock_irqrestore(&port->port_lock, flags);
874}
875
876static int gs_write_room(struct tty_struct *tty)
877{
878 struct gs_port *port = tty->driver_data;
879 unsigned long flags;
880 int room = 0;
881
882 spin_lock_irqsave(&port->port_lock, flags);
883 if (port->port_usb)
884 room = gs_buf_space_avail(&port->port_write_buf);
885 spin_unlock_irqrestore(&port->port_lock, flags);
886
887 pr_vdebug("gs_write_room: (%d,%p) room=%d\n",
888 port->port_num, tty, room);
889
890 return room;
891}
892
893static int gs_chars_in_buffer(struct tty_struct *tty)
894{
895 struct gs_port *port = tty->driver_data;
896 unsigned long flags;
897 int chars = 0;
898
899 spin_lock_irqsave(&port->port_lock, flags);
900 chars = gs_buf_data_avail(&port->port_write_buf);
901 spin_unlock_irqrestore(&port->port_lock, flags);
902
903 pr_vdebug("gs_chars_in_buffer: (%d,%p) chars=%d\n",
904 port->port_num, tty, chars);
905
906 return chars;
907}
908
909/* undo side effects of setting TTY_THROTTLED */
910static void gs_unthrottle(struct tty_struct *tty)
911{
912 struct gs_port *port = tty->driver_data;
913 unsigned long flags;
914 unsigned started = 0;
915
916 spin_lock_irqsave(&port->port_lock, flags);
917 if (port->port_usb)
918 started = gs_start_rx(port);
919 spin_unlock_irqrestore(&port->port_lock, flags);
920
921 pr_vdebug("gs_unthrottle: ttyGS%d, %d packets\n",
922 port->port_num, started);
923}
924
925static const struct tty_operations gs_tty_ops = {
926 .open = gs_open,
927 .close = gs_close,
928 .write = gs_write,
929 .put_char = gs_put_char,
930 .flush_chars = gs_flush_chars,
931 .write_room = gs_write_room,
932 .chars_in_buffer = gs_chars_in_buffer,
933 .unthrottle = gs_unthrottle,
934};
935
936/*-------------------------------------------------------------------------*/
937
938static struct tty_driver *gs_tty_driver;
939
940static int __init
941gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
942{
943 struct gs_port *port;
944
945 port = kzalloc(sizeof(struct gs_port), GFP_KERNEL);
946 if (port == NULL)
947 return -ENOMEM;
948
949 spin_lock_init(&port->port_lock);
950 init_waitqueue_head(&port->close_wait);
951 init_waitqueue_head(&port->drain_wait);
952
953 tasklet_init(&port->push, gs_rx_push, (unsigned long) port);
954
955 INIT_LIST_HEAD(&port->read_pool);
956 INIT_LIST_HEAD(&port->write_pool);
957
958 port->port_num = port_num;
959 port->port_line_coding = *coding;
960
961 ports[port_num].port = port;
962
963 return 0;
964}
965
966/**
967 * gserial_setup - initialize TTY driver for one or more ports
968 * @g: gadget to associate with these ports
969 * @count: how many ports to support
970 * Context: may sleep
971 *
972 * The TTY stack needs to know in advance how many devices it should
973 * plan to manage. Use this call to set up the ports you will be
974 * exporting through USB. Later, connect them to functions based
975 * on what configuration is activated by the USB host; and disconnect
976 * them as appropriate.
977 *
978 * An example would be a two-configuration device in which both
979 * configurations expose port 0, but through different functions.
980 * One configuration could even expose port 1 while the other
981 * one doesn't.
982 *
983 * Returns negative errno or zero.
984 */
985int __init gserial_setup(struct usb_gadget *g, unsigned count)
986{
987 unsigned i;
988 struct usb_cdc_line_coding coding;
989 int status;
990
991 if (count == 0 || count > N_PORTS)
992 return -EINVAL;
993
994 gs_tty_driver = alloc_tty_driver(count);
995 if (!gs_tty_driver)
996 return -ENOMEM;
997
998 gs_tty_driver->owner = THIS_MODULE;
999 gs_tty_driver->driver_name = "g_serial";
1000 gs_tty_driver->name = "ttyGS";
1001 /* uses dynamically assigned dev_t values */
1002
1003 gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
1004 gs_tty_driver->subtype = SERIAL_TYPE_NORMAL;
1005 gs_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1006 gs_tty_driver->init_termios = tty_std_termios;
1007
1008 /* 9600-8-N-1 ... matches defaults expected by "usbser.sys" on
1009 * MS-Windows. Otherwise, most of these flags shouldn't affect
1010 * anything unless we were to actually hook up to a serial line.
1011 */
1012 gs_tty_driver->init_termios.c_cflag =
1013 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1014 gs_tty_driver->init_termios.c_ispeed = 9600;
1015 gs_tty_driver->init_termios.c_ospeed = 9600;
1016
1017 coding.dwDTERate = __constant_cpu_to_le32(9600);
1018 coding.bCharFormat = 8;
1019 coding.bParityType = USB_CDC_NO_PARITY;
1020 coding.bDataBits = USB_CDC_1_STOP_BITS;
1021
1022 tty_set_operations(gs_tty_driver, &gs_tty_ops);
1023
1024 /* make devices be openable */
1025 for (i = 0; i < count; i++) {
1026 mutex_init(&ports[i].lock);
1027 status = gs_port_alloc(i, &coding);
1028 if (status) {
1029 count = i;
1030 goto fail;
1031 }
1032 }
1033 n_ports = count;
1034
1035 /* export the driver ... */
1036 status = tty_register_driver(gs_tty_driver);
1037 if (status) {
1038 put_tty_driver(gs_tty_driver);
1039 pr_err("%s: cannot register, err %d\n",
1040 __func__, status);
1041 goto fail;
1042 }
1043
1044 /* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */
1045 for (i = 0; i < count; i++) {
1046 struct device *tty_dev;
1047
1048 tty_dev = tty_register_device(gs_tty_driver, i, &g->dev);
1049 if (IS_ERR(tty_dev))
1050 pr_warning("%s: no classdev for port %d, err %ld\n",
1051 __func__, i, PTR_ERR(tty_dev));
1052 }
1053
1054 pr_debug("%s: registered %d ttyGS* device%s\n", __func__,
1055 count, (count == 1) ? "" : "s");
1056
1057 return status;
1058fail:
1059 while (count--)
1060 kfree(ports[count].port);
1061 put_tty_driver(gs_tty_driver);
1062 gs_tty_driver = NULL;
1063 return status;
1064}
1065
1066static int gs_closed(struct gs_port *port)
1067{
1068 int cond;
1069
1070 spin_lock_irq(&port->port_lock);
1071 cond = (port->open_count == 0) && !port->openclose;
1072 spin_unlock_irq(&port->port_lock);
1073 return cond;
1074}
1075
1076/**
1077 * gserial_cleanup - remove TTY-over-USB driver and devices
1078 * Context: may sleep
1079 *
1080 * This is called to free all resources allocated by @gserial_setup().
1081 * Accordingly, it may need to wait until some open /dev/ files have
1082 * closed.
1083 *
1084 * The caller must have issued @gserial_disconnect() for any ports
1085 * that had previously been connected, so that there is never any
1086 * I/O pending when it's called.
1087 */
1088void gserial_cleanup(void)
1089{
1090 unsigned i;
1091 struct gs_port *port;
1092
1093 if (!gs_tty_driver)
1094 return;
1095
1096 /* start sysfs and /dev/ttyGS* node removal */
1097 for (i = 0; i < n_ports; i++)
1098 tty_unregister_device(gs_tty_driver, i);
1099
1100 for (i = 0; i < n_ports; i++) {
1101 /* prevent new opens */
1102 mutex_lock(&ports[i].lock);
1103 port = ports[i].port;
1104 ports[i].port = NULL;
1105 mutex_unlock(&ports[i].lock);
1106
1107 /* wait for old opens to finish */
1108 wait_event(port->close_wait, gs_closed(port));
1109
1110 WARN_ON(port->port_usb != NULL);
1111
1112 kfree(port);
1113 }
1114 n_ports = 0;
1115
1116 tty_unregister_driver(gs_tty_driver);
1117 gs_tty_driver = NULL;
1118
1119 pr_debug("%s: cleaned up ttyGS* support\n", __func__);
1120}
1121
1122/**
1123 * gserial_connect - notify TTY I/O glue that USB link is active
1124 * @gser: the function, set up with endpoints and descriptors
1125 * @port_num: which port is active
1126 * Context: any (usually from irq)
1127 *
1128 * This is called activate endpoints and let the TTY layer know that
1129 * the connection is active ... not unlike "carrier detect". It won't
1130 * necessarily start I/O queues; unless the TTY is held open by any
1131 * task, there would be no point. However, the endpoints will be
1132 * activated so the USB host can perform I/O, subject to basic USB
1133 * hardware flow control.
1134 *
1135 * Caller needs to have set up the endpoints and USB function in @dev
1136 * before calling this, as well as the appropriate (speed-specific)
1137 * endpoint descriptors, and also have set up the TTY driver by calling
1138 * @gserial_setup().
1139 *
1140 * Returns negative errno or zero.
1141 * On success, ep->driver_data will be overwritten.
1142 */
1143int gserial_connect(struct gserial *gser, u8 port_num)
1144{
1145 struct gs_port *port;
1146 unsigned long flags;
1147 int status;
1148
1149 if (!gs_tty_driver || port_num >= n_ports)
1150 return -ENXIO;
1151
1152 /* we "know" gserial_cleanup() hasn't been called */
1153 port = ports[port_num].port;
1154
1155 /* activate the endpoints */
1156 status = usb_ep_enable(gser->in, gser->in_desc);
1157 if (status < 0)
1158 return status;
1159 gser->in->driver_data = port;
1160
1161 status = usb_ep_enable(gser->out, gser->out_desc);
1162 if (status < 0)
1163 goto fail_out;
1164 gser->out->driver_data = port;
1165
1166 /* then tell the tty glue that I/O can work */
1167 spin_lock_irqsave(&port->port_lock, flags);
1168 gser->ioport = port;
1169 port->port_usb = gser;
1170
1171 /* REVISIT unclear how best to handle this state...
1172 * we don't really couple it with the Linux TTY.
1173 */
1174 gser->port_line_coding = port->port_line_coding;
1175
1176 /* REVISIT if waiting on "carrier detect", signal. */
1177
1178 /* REVISIT for ACM, issue "network connection" status notification:
1179 * connected if open_count, else disconnected.
1180 */
1181
1182 /* if it's already open, start I/O */
1183 if (port->open_count) {
1184 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
1185 gs_start_io(port);
1186 }
1187
1188 spin_unlock_irqrestore(&port->port_lock, flags);
1189
1190 return status;
1191
1192fail_out:
1193 usb_ep_disable(gser->in);
1194 gser->in->driver_data = NULL;
1195 return status;
1196}
1197
1198/**
1199 * gserial_disconnect - notify TTY I/O glue that USB link is inactive
1200 * @gser: the function, on which gserial_connect() was called
1201 * Context: any (usually from irq)
1202 *
1203 * This is called to deactivate endpoints and let the TTY layer know
1204 * that the connection went inactive ... not unlike "hangup".
1205 *
1206 * On return, the state is as if gserial_connect() had never been called;
1207 * there is no active USB I/O on these endpoints.
1208 */
1209void gserial_disconnect(struct gserial *gser)
1210{
1211 struct gs_port *port = gser->ioport;
1212 unsigned long flags;
1213
1214 if (!port)
1215 return;
1216
1217 /* tell the TTY glue not to do I/O here any more */
1218 spin_lock_irqsave(&port->port_lock, flags);
1219
1220 /* REVISIT as above: how best to track this? */
1221 port->port_line_coding = gser->port_line_coding;
1222
1223 port->port_usb = NULL;
1224 gser->ioport = NULL;
1225 if (port->open_count > 0 || port->openclose) {
1226 wake_up_interruptible(&port->drain_wait);
1227 if (port->port_tty)
1228 tty_hangup(port->port_tty);
1229 }
1230 spin_unlock_irqrestore(&port->port_lock, flags);
1231
1232 /* disable endpoints, aborting down any active I/O */
1233 usb_ep_disable(gser->out);
1234 gser->out->driver_data = NULL;
1235
1236 usb_ep_disable(gser->in);
1237 gser->in->driver_data = NULL;
1238
1239 /* finally, free any unused/unusable I/O buffers */
1240 spin_lock_irqsave(&port->port_lock, flags);
1241 if (port->open_count == 0 && !port->openclose)
1242 gs_buf_free(&port->port_write_buf);
1243 gs_free_requests(gser->out, &port->read_pool);
1244 gs_free_requests(gser->in, &port->write_pool);
1245 spin_unlock_irqrestore(&port->port_lock, flags);
1246}
diff --git a/drivers/usb/gadget/u_serial.h b/drivers/usb/gadget/u_serial.h
new file mode 100644
index 000000000000..7b561138f90e
--- /dev/null
+++ b/drivers/usb/gadget/u_serial.h
@@ -0,0 +1,58 @@
1/*
2 * u_serial.h - interface to USB gadget "serial port"/TTY utilities
3 *
4 * Copyright (C) 2008 David Brownell
5 * Copyright (C) 2008 by Nokia Corporation
6 *
7 * This software is distributed under the terms of the GNU General
8 * Public License ("GPL") as published by the Free Software Foundation,
9 * either version 2 of that License or (at your option) any later version.
10 */
11
12#ifndef __U_SERIAL_H
13#define __U_SERIAL_H
14
15#include <linux/usb/composite.h>
16#include <linux/usb/cdc.h>
17
18/*
19 * One non-multiplexed "serial" I/O port ... there can be several of these
20 * on any given USB peripheral device, if it provides enough endpoints.
21 *
22 * The "u_serial" utility component exists to do one thing: manage TTY
23 * style I/O using the USB peripheral endpoints listed here, including
24 * hookups to sysfs and /dev for each logical "tty" device.
25 *
26 * REVISIT need TTY --> USB event flow too, so ACM can report open/close
27 * as carrier detect events. Model after ECM. There's more ACM state too.
28 *
29 * REVISIT someday, allow multiplexing several TTYs over these endpoints.
30 */
31struct gserial {
32 struct usb_function func;
33
34 /* port is managed by gserial_{connect,disconnect} */
35 struct gs_port *ioport;
36
37 struct usb_ep *in;
38 struct usb_ep *out;
39 struct usb_endpoint_descriptor *in_desc;
40 struct usb_endpoint_descriptor *out_desc;
41
42 /* REVISIT avoid this CDC-ACM support harder ... */
43 struct usb_cdc_line_coding port_line_coding; /* 9600-8-N-1 etc */
44};
45
46/* port setup/teardown is handled by gadget driver */
47int gserial_setup(struct usb_gadget *g, unsigned n_ports);
48void gserial_cleanup(void);
49
50/* connect/disconnect is handled by individual functions */
51int gserial_connect(struct gserial *, u8 port_num);
52void gserial_disconnect(struct gserial *);
53
54/* functions are bound to configurations by a config or gadget driver */
55int acm_bind_config(struct usb_configuration *c, u8 port_num);
56int gser_bind_config(struct usb_configuration *c, u8 port_num);
57
58#endif /* __U_SERIAL_H */
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index fce4924dbbe8..aa0bd4f126a1 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * zero.c -- Gadget Zero, for USB development 2 * zero.c -- Gadget Zero, for USB development
3 * 3 *
4 * Copyright (C) 2003-2007 David Brownell 4 * Copyright (C) 2003-2008 David Brownell
5 * All rights reserved. 5 * Copyright (C) 2008 by Nokia Corporation
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -30,12 +30,7 @@
30 * 30 *
31 * It supports two similar configurations. One sinks whatever the usb host 31 * It supports two similar configurations. One sinks whatever the usb host
32 * writes, and in return sources zeroes. The other loops whatever the host 32 * writes, and in return sources zeroes. The other loops whatever the host
33 * writes back, so the host can read it. Module options include: 33 * writes back, so the host can read it.
34 *
35 * buflen=N default N=4096, buffer size used
36 * qlen=N default N=32, how many buffers in the loopback queue
37 * loopdefault default false, list loopback config first
38 * autoresume=N default N=0, seconds before triggering remote wakeup
39 * 34 *
40 * Many drivers will only have one configuration, letting them be much 35 * Many drivers will only have one configuration, letting them be much
41 * simpler if they also don't support high speed operation (like this 36 * simpler if they also don't support high speed operation (like this
@@ -47,94 +42,35 @@
47 * work with low capability USB controllers without four bulk endpoints. 42 * work with low capability USB controllers without four bulk endpoints.
48 */ 43 */
49 44
45/*
46 * driver assumes self-powered hardware, and
47 * has no way for users to trigger remote wakeup.
48 */
49
50/* #define VERBOSE_DEBUG */ 50/* #define VERBOSE_DEBUG */
51 51
52#include <linux/kernel.h> 52#include <linux/kernel.h>
53#include <linux/utsname.h> 53#include <linux/utsname.h>
54#include <linux/device.h> 54#include <linux/device.h>
55 55
56#include <linux/usb/ch9.h> 56#include "g_zero.h"
57#include <linux/usb/gadget.h>
58
59#include "gadget_chips.h" 57#include "gadget_chips.h"
60 58
61 59
62/*-------------------------------------------------------------------------*/ 60/*-------------------------------------------------------------------------*/
63 61
64#define DRIVER_VERSION "Earth Day 2008" 62#define DRIVER_VERSION "Cinco de Mayo 2008"
65 63
66static const char shortname[] = "zero";
67static const char longname[] = "Gadget Zero"; 64static const char longname[] = "Gadget Zero";
68 65
69static const char source_sink[] = "source and sink data"; 66unsigned buflen = 4096;
70static const char loopback[] = "loop input to output"; 67module_param(buflen, uint, 0);
71
72/*-------------------------------------------------------------------------*/
73
74/*
75 * driver assumes self-powered hardware, and
76 * has no way for users to trigger remote wakeup.
77 *
78 * this version autoconfigures as much as possible,
79 * which is reasonable for most "bulk-only" drivers.
80 */
81static const char *EP_IN_NAME; /* source */
82static const char *EP_OUT_NAME; /* sink */
83
84/*-------------------------------------------------------------------------*/
85
86/* big enough to hold our biggest descriptor */
87#define USB_BUFSIZ 256
88
89struct zero_dev {
90 spinlock_t lock;
91 struct usb_gadget *gadget;
92 struct usb_request *req; /* for control responses */
93
94 /* when configured, we have one of two configs:
95 * - source data (in to host) and sink it (out from host)
96 * - or loop it back (out from host back in to host)
97 */
98 u8 config;
99 struct usb_ep *in_ep, *out_ep;
100
101 /* autoresume timer */
102 struct timer_list resume;
103};
104
105#define DBG(d, fmt, args...) \
106 dev_dbg(&(d)->gadget->dev , fmt , ## args)
107#define VDBG(d, fmt, args...) \
108 dev_vdbg(&(d)->gadget->dev , fmt , ## args)
109#define ERROR(d, fmt, args...) \
110 dev_err(&(d)->gadget->dev , fmt , ## args)
111#define WARN(d, fmt, args...) \
112 dev_warn(&(d)->gadget->dev , fmt , ## args)
113#define INFO(d, fmt, args...) \
114 dev_info(&(d)->gadget->dev , fmt , ## args)
115
116/*-------------------------------------------------------------------------*/
117
118static unsigned buflen = 4096;
119static unsigned qlen = 32;
120static unsigned pattern = 0;
121
122module_param(buflen, uint, S_IRUGO);
123module_param(qlen, uint, S_IRUGO);
124module_param(pattern, uint, S_IRUGO|S_IWUSR);
125
126/*
127 * if it's nonzero, autoresume says how many seconds to wait
128 * before trying to wake up the host after suspend.
129 */
130static unsigned autoresume = 0;
131module_param(autoresume, uint, 0);
132 68
133/* 69/*
134 * Normally the "loopback" configuration is second (index 1) so 70 * Normally the "loopback" configuration is second (index 1) so
135 * it's not the default. Here's where to change that order, to 71 * it's not the default. Here's where to change that order, to
136 * work better with hosts where config changes are problematic. 72 * work better with hosts where config changes are problematic or
137 * Or controllers (like superh) that only support one config. 73 * controllers (like original superh) that only support one config.
138 */ 74 */
139static int loopdefault = 0; 75static int loopdefault = 0;
140module_param(loopdefault, bool, S_IRUGO|S_IWUSR); 76module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
@@ -156,24 +92,6 @@ module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
156 92
157/*-------------------------------------------------------------------------*/ 93/*-------------------------------------------------------------------------*/
158 94
159/*
160 * DESCRIPTORS ... most are static, but strings and (full)
161 * configuration descriptors are built on demand.
162 */
163
164#define STRING_MANUFACTURER 25
165#define STRING_PRODUCT 42
166#define STRING_SERIAL 101
167#define STRING_SOURCE_SINK 250
168#define STRING_LOOPBACK 251
169
170/*
171 * This device advertises two configurations; these numbers work
172 * on a pxa250 as well as more flexible hardware.
173 */
174#define CONFIG_SOURCE_SINK 3
175#define CONFIG_LOOPBACK 2
176
177static struct usb_device_descriptor device_desc = { 95static struct usb_device_descriptor device_desc = {
178 .bLength = sizeof device_desc, 96 .bLength = sizeof device_desc,
179 .bDescriptorType = USB_DT_DEVICE, 97 .bDescriptorType = USB_DT_DEVICE,
@@ -183,248 +101,64 @@ static struct usb_device_descriptor device_desc = {
183 101
184 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM), 102 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM),
185 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM), 103 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM),
186 .iManufacturer = STRING_MANUFACTURER,
187 .iProduct = STRING_PRODUCT,
188 .iSerialNumber = STRING_SERIAL,
189 .bNumConfigurations = 2, 104 .bNumConfigurations = 2,
190}; 105};
191 106
192static struct usb_config_descriptor source_sink_config = { 107#ifdef CONFIG_USB_OTG
193 .bLength = sizeof source_sink_config,
194 .bDescriptorType = USB_DT_CONFIG,
195
196 /* compute wTotalLength on the fly */
197 .bNumInterfaces = 1,
198 .bConfigurationValue = CONFIG_SOURCE_SINK,
199 .iConfiguration = STRING_SOURCE_SINK,
200 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
201 .bMaxPower = 1, /* self-powered */
202};
203
204static struct usb_config_descriptor loopback_config = {
205 .bLength = sizeof loopback_config,
206 .bDescriptorType = USB_DT_CONFIG,
207
208 /* compute wTotalLength on the fly */
209 .bNumInterfaces = 1,
210 .bConfigurationValue = CONFIG_LOOPBACK,
211 .iConfiguration = STRING_LOOPBACK,
212 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
213 .bMaxPower = 1, /* self-powered */
214};
215
216static struct usb_otg_descriptor otg_descriptor = { 108static struct usb_otg_descriptor otg_descriptor = {
217 .bLength = sizeof otg_descriptor, 109 .bLength = sizeof otg_descriptor,
218 .bDescriptorType = USB_DT_OTG, 110 .bDescriptorType = USB_DT_OTG,
219 111
220 .bmAttributes = USB_OTG_SRP, 112 /* REVISIT SRP-only hardware is possible, although
221}; 113 * it would not be called "OTG" ...
222 114 */
223/* one interface in each configuration */ 115 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
224
225static const struct usb_interface_descriptor source_sink_intf = {
226 .bLength = sizeof source_sink_intf,
227 .bDescriptorType = USB_DT_INTERFACE,
228
229 .bNumEndpoints = 2,
230 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
231 .iInterface = STRING_SOURCE_SINK,
232};
233
234static const struct usb_interface_descriptor loopback_intf = {
235 .bLength = sizeof loopback_intf,
236 .bDescriptorType = USB_DT_INTERFACE,
237
238 .bNumEndpoints = 2,
239 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
240 .iInterface = STRING_LOOPBACK,
241};
242
243/* two full speed bulk endpoints; their use is config-dependent */
244
245static struct usb_endpoint_descriptor fs_source_desc = {
246 .bLength = USB_DT_ENDPOINT_SIZE,
247 .bDescriptorType = USB_DT_ENDPOINT,
248
249 .bEndpointAddress = USB_DIR_IN,
250 .bmAttributes = USB_ENDPOINT_XFER_BULK,
251};
252
253static struct usb_endpoint_descriptor fs_sink_desc = {
254 .bLength = USB_DT_ENDPOINT_SIZE,
255 .bDescriptorType = USB_DT_ENDPOINT,
256
257 .bEndpointAddress = USB_DIR_OUT,
258 .bmAttributes = USB_ENDPOINT_XFER_BULK,
259};
260
261static const struct usb_descriptor_header *fs_source_sink_function[] = {
262 (struct usb_descriptor_header *) &otg_descriptor,
263 (struct usb_descriptor_header *) &source_sink_intf,
264 (struct usb_descriptor_header *) &fs_sink_desc,
265 (struct usb_descriptor_header *) &fs_source_desc,
266 NULL,
267};
268
269static const struct usb_descriptor_header *fs_loopback_function[] = {
270 (struct usb_descriptor_header *) &otg_descriptor,
271 (struct usb_descriptor_header *) &loopback_intf,
272 (struct usb_descriptor_header *) &fs_sink_desc,
273 (struct usb_descriptor_header *) &fs_source_desc,
274 NULL,
275};
276
277/*
278 * usb 2.0 devices need to expose both high speed and full speed
279 * descriptors, unless they only run at full speed.
280 *
281 * that means alternate endpoint descriptors (bigger packets)
282 * and a "device qualifier" ... plus more construction options
283 * for the config descriptor.
284 */
285
286static struct usb_endpoint_descriptor hs_source_desc = {
287 .bLength = USB_DT_ENDPOINT_SIZE,
288 .bDescriptorType = USB_DT_ENDPOINT,
289
290 .bmAttributes = USB_ENDPOINT_XFER_BULK,
291 .wMaxPacketSize = __constant_cpu_to_le16(512),
292};
293
294static struct usb_endpoint_descriptor hs_sink_desc = {
295 .bLength = USB_DT_ENDPOINT_SIZE,
296 .bDescriptorType = USB_DT_ENDPOINT,
297
298 .bmAttributes = USB_ENDPOINT_XFER_BULK,
299 .wMaxPacketSize = __constant_cpu_to_le16(512),
300};
301
302static struct usb_qualifier_descriptor dev_qualifier = {
303 .bLength = sizeof dev_qualifier,
304 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
305
306 .bcdUSB = __constant_cpu_to_le16(0x0200),
307 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
308
309 .bNumConfigurations = 2,
310}; 116};
311 117
312static const struct usb_descriptor_header *hs_source_sink_function[] = { 118const struct usb_descriptor_header *otg_desc[] = {
313 (struct usb_descriptor_header *) &otg_descriptor, 119 (struct usb_descriptor_header *) &otg_descriptor,
314 (struct usb_descriptor_header *) &source_sink_intf,
315 (struct usb_descriptor_header *) &hs_source_desc,
316 (struct usb_descriptor_header *) &hs_sink_desc,
317 NULL, 120 NULL,
318}; 121};
122#endif
319 123
320static const struct usb_descriptor_header *hs_loopback_function[] = { 124/* string IDs are assigned dynamically */
321 (struct usb_descriptor_header *) &otg_descriptor,
322 (struct usb_descriptor_header *) &loopback_intf,
323 (struct usb_descriptor_header *) &hs_source_desc,
324 (struct usb_descriptor_header *) &hs_sink_desc,
325 NULL,
326};
327 125
328/* maxpacket and other transfer characteristics vary by speed. */ 126#define STRING_MANUFACTURER_IDX 0
329static inline struct usb_endpoint_descriptor * 127#define STRING_PRODUCT_IDX 1
330ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs, 128#define STRING_SERIAL_IDX 2
331 struct usb_endpoint_descriptor *fs)
332{
333 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
334 return hs;
335 return fs;
336}
337 129
338static char manufacturer[50]; 130static char manufacturer[50];
339 131
340/* default serial number takes at least two packets */ 132/* default serial number takes at least two packets */
341static char serial[] = "0123456789.0123456789.0123456789"; 133static char serial[] = "0123456789.0123456789.0123456789";
342 134
343 135static struct usb_string strings_dev[] = {
344/* static strings, in UTF-8 */ 136 [STRING_MANUFACTURER_IDX].s = manufacturer,
345static struct usb_string strings[] = { 137 [STRING_PRODUCT_IDX].s = longname,
346 { STRING_MANUFACTURER, manufacturer, }, 138 [STRING_SERIAL_IDX].s = serial,
347 { STRING_PRODUCT, longname, },
348 { STRING_SERIAL, serial, },
349 { STRING_LOOPBACK, loopback, },
350 { STRING_SOURCE_SINK, source_sink, },
351 { } /* end of list */ 139 { } /* end of list */
352}; 140};
353 141
354static struct usb_gadget_strings stringtab = { 142static struct usb_gadget_strings stringtab_dev = {
355 .language = 0x0409, /* en-us */ 143 .language = 0x0409, /* en-us */
356 .strings = strings, 144 .strings = strings_dev,
357}; 145};
358 146
359/* 147static struct usb_gadget_strings *dev_strings[] = {
360 * config descriptors are also handcrafted. these must agree with code 148 &stringtab_dev,
361 * that sets configurations, and with code managing interfaces and their 149 NULL,
362 * altsettings. other complexity may come from: 150};
363 *
364 * - high speed support, including "other speed config" rules
365 * - multiple configurations
366 * - interfaces with alternate settings
367 * - embedded class or vendor-specific descriptors
368 *
369 * this handles high speed, and has a second config that could as easily
370 * have been an alternate interface setting (on most hardware).
371 *
372 * NOTE: to demonstrate (and test) more USB capabilities, this driver
373 * should include an altsetting to test interrupt transfers, including
374 * high bandwidth modes at high speed. (Maybe work like Intel's test
375 * device?)
376 */
377static int config_buf(struct usb_gadget *gadget,
378 u8 *buf, u8 type, unsigned index)
379{
380 int is_source_sink;
381 int len;
382 const struct usb_descriptor_header **function;
383 int hs = 0;
384
385 /* two configurations will always be index 0 and index 1 */
386 if (index > 1)
387 return -EINVAL;
388 is_source_sink = loopdefault ? (index == 1) : (index == 0);
389
390 if (gadget_is_dualspeed(gadget)) {
391 hs = (gadget->speed == USB_SPEED_HIGH);
392 if (type == USB_DT_OTHER_SPEED_CONFIG)
393 hs = !hs;
394 }
395 if (hs)
396 function = is_source_sink
397 ? hs_source_sink_function
398 : hs_loopback_function;
399 else
400 function = is_source_sink
401 ? fs_source_sink_function
402 : fs_loopback_function;
403
404 /* for now, don't advertise srp-only devices */
405 if (!gadget_is_otg(gadget))
406 function++;
407
408 len = usb_gadget_config_buf(is_source_sink
409 ? &source_sink_config
410 : &loopback_config,
411 buf, USB_BUFSIZ, function);
412 if (len < 0)
413 return len;
414 ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
415 return len;
416}
417 151
418/*-------------------------------------------------------------------------*/ 152/*-------------------------------------------------------------------------*/
419 153
420static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) 154struct usb_request *alloc_ep_req(struct usb_ep *ep)
421{ 155{
422 struct usb_request *req; 156 struct usb_request *req;
423 157
424 req = usb_ep_alloc_request(ep, GFP_ATOMIC); 158 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
425 if (req) { 159 if (req) {
426 req->length = length; 160 req->length = buflen;
427 req->buf = kmalloc(length, GFP_ATOMIC); 161 req->buf = kmalloc(buflen, GFP_ATOMIC);
428 if (!req->buf) { 162 if (!req->buf) {
429 usb_ep_free_request(ep, req); 163 usb_ep_free_request(ep, req);
430 req = NULL; 164 req = NULL;
@@ -433,681 +167,73 @@ static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
433 return req; 167 return req;
434} 168}
435 169
436static void free_ep_req(struct usb_ep *ep, struct usb_request *req) 170void free_ep_req(struct usb_ep *ep, struct usb_request *req)
437{ 171{
438 kfree(req->buf); 172 kfree(req->buf);
439 usb_ep_free_request(ep, req); 173 usb_ep_free_request(ep, req);
440} 174}
441 175
442/*-------------------------------------------------------------------------*/ 176static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
443
444/*
445 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripherals,
446 * this just sinks bulk packets OUT to the peripheral and sources them IN
447 * to the host, optionally with specific data patterns.
448 *
449 * In terms of control messaging, this supports all the standard requests
450 * plus two that support control-OUT tests.
451 *
452 * Note that because this doesn't queue more than one request at a time,
453 * some other function must be used to test queueing logic. The network
454 * link (g_ether) is probably the best option for that.
455 */
456
457/* optionally require specific source/sink data patterns */
458
459static int
460check_read_data(
461 struct zero_dev *dev,
462 struct usb_ep *ep,
463 struct usb_request *req
464)
465{ 177{
466 unsigned i; 178 int value;
467 u8 *buf = req->buf; 179
468 180 if (ep->driver_data) {
469 for (i = 0; i < req->actual; i++, buf++) { 181 value = usb_ep_disable(ep);
470 switch (pattern) { 182 if (value < 0)
471 /* all-zeroes has no synchronization issues */ 183 DBG(cdev, "disable %s --> %d\n",
472 case 0: 184 ep->name, value);
473 if (*buf == 0) 185 ep->driver_data = NULL;
474 continue;
475 break;
476 /* mod63 stays in sync with short-terminated transfers,
477 * or otherwise when host and gadget agree on how large
478 * each usb transfer request should be. resync is done
479 * with set_interface or set_config.
480 */
481 case 1:
482 if (*buf == (u8)(i % 63))
483 continue;
484 break;
485 }
486 ERROR(dev, "bad OUT byte, buf[%d] = %d\n", i, *buf);
487 usb_ep_set_halt(ep);
488 return -EINVAL;
489 } 186 }
490 return 0;
491} 187}
492 188
493static void reinit_write_data(struct usb_ep *ep, struct usb_request *req) 189void disable_endpoints(struct usb_composite_dev *cdev,
190 struct usb_ep *in, struct usb_ep *out)
494{ 191{
495 unsigned i; 192 disable_ep(cdev, in);
496 u8 *buf = req->buf; 193 disable_ep(cdev, out);
497
498 switch (pattern) {
499 case 0:
500 memset(req->buf, 0, req->length);
501 break;
502 case 1:
503 for (i = 0; i < req->length; i++)
504 *buf++ = (u8) (i % 63);
505 break;
506 }
507}
508
509/* if there is only one request in the queue, there'll always be an
510 * irq delay between end of one request and start of the next.
511 * that prevents using hardware dma queues.
512 */
513static void source_sink_complete(struct usb_ep *ep, struct usb_request *req)
514{
515 struct zero_dev *dev = ep->driver_data;
516 int status = req->status;
517
518 switch (status) {
519
520 case 0: /* normal completion? */
521 if (ep == dev->out_ep) {
522 check_read_data(dev, ep, req);
523 memset(req->buf, 0x55, req->length);
524 } else
525 reinit_write_data(ep, req);
526 break;
527
528 /* this endpoint is normally active while we're configured */
529 case -ECONNABORTED: /* hardware forced ep reset */
530 case -ECONNRESET: /* request dequeued */
531 case -ESHUTDOWN: /* disconnect from host */
532 VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status,
533 req->actual, req->length);
534 if (ep == dev->out_ep)
535 check_read_data(dev, ep, req);
536 free_ep_req(ep, req);
537 return;
538
539 case -EOVERFLOW: /* buffer overrun on read means that
540 * we didn't provide a big enough
541 * buffer.
542 */
543 default:
544#if 1
545 DBG(dev, "%s complete --> %d, %d/%d\n", ep->name,
546 status, req->actual, req->length);
547#endif
548 case -EREMOTEIO: /* short read */
549 break;
550 }
551
552 status = usb_ep_queue(ep, req, GFP_ATOMIC);
553 if (status) {
554 ERROR(dev, "kill %s: resubmit %d bytes --> %d\n",
555 ep->name, req->length, status);
556 usb_ep_set_halt(ep);
557 /* FIXME recover later ... somehow */
558 }
559}
560
561static struct usb_request *source_sink_start_ep(struct usb_ep *ep)
562{
563 struct usb_request *req;
564 int status;
565
566 req = alloc_ep_req(ep, buflen);
567 if (!req)
568 return NULL;
569
570 memset(req->buf, 0, req->length);
571 req->complete = source_sink_complete;
572
573 if (strcmp(ep->name, EP_IN_NAME) == 0)
574 reinit_write_data(ep, req);
575 else
576 memset(req->buf, 0x55, req->length);
577
578 status = usb_ep_queue(ep, req, GFP_ATOMIC);
579 if (status) {
580 struct zero_dev *dev = ep->driver_data;
581
582 ERROR(dev, "start %s --> %d\n", ep->name, status);
583 free_ep_req(ep, req);
584 req = NULL;
585 }
586
587 return req;
588}
589
590static int set_source_sink_config(struct zero_dev *dev)
591{
592 int result = 0;
593 struct usb_ep *ep;
594 struct usb_gadget *gadget = dev->gadget;
595
596 gadget_for_each_ep(ep, gadget) {
597 const struct usb_endpoint_descriptor *d;
598
599 /* one endpoint writes (sources) zeroes in (to the host) */
600 if (strcmp(ep->name, EP_IN_NAME) == 0) {
601 d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
602 result = usb_ep_enable(ep, d);
603 if (result == 0) {
604 ep->driver_data = dev;
605 if (source_sink_start_ep(ep) != NULL) {
606 dev->in_ep = ep;
607 continue;
608 }
609 usb_ep_disable(ep);
610 result = -EIO;
611 }
612
613 /* one endpoint reads (sinks) anything out (from the host) */
614 } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
615 d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
616 result = usb_ep_enable(ep, d);
617 if (result == 0) {
618 ep->driver_data = dev;
619 if (source_sink_start_ep(ep) != NULL) {
620 dev->out_ep = ep;
621 continue;
622 }
623 usb_ep_disable(ep);
624 result = -EIO;
625 }
626
627 /* ignore any other endpoints */
628 } else
629 continue;
630
631 /* stop on error */
632 ERROR(dev, "can't start %s, result %d\n", ep->name, result);
633 break;
634 }
635 if (result == 0)
636 DBG(dev, "buflen %d\n", buflen);
637
638 /* caller is responsible for cleanup on error */
639 return result;
640}
641
642/*-------------------------------------------------------------------------*/
643
644static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
645{
646 struct zero_dev *dev = ep->driver_data;
647 int status = req->status;
648
649 switch (status) {
650
651 case 0: /* normal completion? */
652 if (ep == dev->out_ep) {
653 /* loop this OUT packet back IN to the host */
654 req->zero = (req->actual < req->length);
655 req->length = req->actual;
656 status = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC);
657 if (status == 0)
658 return;
659
660 /* "should never get here" */
661 ERROR(dev, "can't loop %s to %s: %d\n",
662 ep->name, dev->in_ep->name,
663 status);
664 }
665
666 /* queue the buffer for some later OUT packet */
667 req->length = buflen;
668 status = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
669 if (status == 0)
670 return;
671
672 /* "should never get here" */
673 /* FALLTHROUGH */
674
675 default:
676 ERROR(dev, "%s loop complete --> %d, %d/%d\n", ep->name,
677 status, req->actual, req->length);
678 /* FALLTHROUGH */
679
680 /* NOTE: since this driver doesn't maintain an explicit record
681 * of requests it submitted (just maintains qlen count), we
682 * rely on the hardware driver to clean up on disconnect or
683 * endpoint disable.
684 */
685 case -ECONNABORTED: /* hardware forced ep reset */
686 case -ECONNRESET: /* request dequeued */
687 case -ESHUTDOWN: /* disconnect from host */
688 free_ep_req(ep, req);
689 return;
690 }
691}
692
693static int set_loopback_config(struct zero_dev *dev)
694{
695 int result = 0;
696 struct usb_ep *ep;
697 struct usb_gadget *gadget = dev->gadget;
698
699 gadget_for_each_ep(ep, gadget) {
700 const struct usb_endpoint_descriptor *d;
701
702 /* one endpoint writes data back IN to the host */
703 if (strcmp(ep->name, EP_IN_NAME) == 0) {
704 d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
705 result = usb_ep_enable(ep, d);
706 if (result == 0) {
707 ep->driver_data = dev;
708 dev->in_ep = ep;
709 continue;
710 }
711
712 /* one endpoint just reads OUT packets */
713 } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
714 d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
715 result = usb_ep_enable(ep, d);
716 if (result == 0) {
717 ep->driver_data = dev;
718 dev->out_ep = ep;
719 continue;
720 }
721
722 /* ignore any other endpoints */
723 } else
724 continue;
725
726 /* stop on error */
727 ERROR(dev, "can't enable %s, result %d\n", ep->name, result);
728 break;
729 }
730
731 /* allocate a bunch of read buffers and queue them all at once.
732 * we buffer at most 'qlen' transfers; fewer if any need more
733 * than 'buflen' bytes each.
734 */
735 if (result == 0) {
736 struct usb_request *req;
737 unsigned i;
738
739 ep = dev->out_ep;
740 for (i = 0; i < qlen && result == 0; i++) {
741 req = alloc_ep_req(ep, buflen);
742 if (req) {
743 req->complete = loopback_complete;
744 result = usb_ep_queue(ep, req, GFP_ATOMIC);
745 if (result)
746 DBG(dev, "%s queue req --> %d\n",
747 ep->name, result);
748 } else
749 result = -ENOMEM;
750 }
751 }
752 if (result == 0)
753 DBG(dev, "qlen %d, buflen %d\n", qlen, buflen);
754
755 /* caller is responsible for cleanup on error */
756 return result;
757}
758
759/*-------------------------------------------------------------------------*/
760
761static void zero_reset_config(struct zero_dev *dev)
762{
763 if (dev->config == 0)
764 return;
765
766 DBG(dev, "reset config\n");
767
768 /* just disable endpoints, forcing completion of pending i/o.
769 * all our completion handlers free their requests in this case.
770 */
771 if (dev->in_ep) {
772 usb_ep_disable(dev->in_ep);
773 dev->in_ep = NULL;
774 }
775 if (dev->out_ep) {
776 usb_ep_disable(dev->out_ep);
777 dev->out_ep = NULL;
778 }
779 dev->config = 0;
780 del_timer(&dev->resume);
781}
782
783/* change our operational config. this code must agree with the code
784 * that returns config descriptors, and altsetting code.
785 *
786 * it's also responsible for power management interactions. some
787 * configurations might not work with our current power sources.
788 *
789 * note that some device controller hardware will constrain what this
790 * code can do, perhaps by disallowing more than one configuration or
791 * by limiting configuration choices (like the pxa2xx).
792 */
793static int zero_set_config(struct zero_dev *dev, unsigned number)
794{
795 int result = 0;
796 struct usb_gadget *gadget = dev->gadget;
797
798 if (number == dev->config)
799 return 0;
800
801 if (gadget_is_sa1100(gadget) && dev->config) {
802 /* tx fifo is full, but we can't clear it...*/
803 ERROR(dev, "can't change configurations\n");
804 return -ESPIPE;
805 }
806 zero_reset_config(dev);
807
808 switch (number) {
809 case CONFIG_SOURCE_SINK:
810 result = set_source_sink_config(dev);
811 break;
812 case CONFIG_LOOPBACK:
813 result = set_loopback_config(dev);
814 break;
815 default:
816 result = -EINVAL;
817 /* FALL THROUGH */
818 case 0:
819 return result;
820 }
821
822 if (!result && (!dev->in_ep || !dev->out_ep))
823 result = -ENODEV;
824 if (result)
825 zero_reset_config(dev);
826 else {
827 char *speed;
828
829 switch (gadget->speed) {
830 case USB_SPEED_LOW: speed = "low"; break;
831 case USB_SPEED_FULL: speed = "full"; break;
832 case USB_SPEED_HIGH: speed = "high"; break;
833 default: speed = "?"; break;
834 }
835
836 dev->config = number;
837 INFO(dev, "%s speed config #%d: %s\n", speed, number,
838 (number == CONFIG_SOURCE_SINK)
839 ? source_sink : loopback);
840 }
841 return result;
842}
843
844/*-------------------------------------------------------------------------*/
845
846static void zero_setup_complete(struct usb_ep *ep, struct usb_request *req)
847{
848 if (req->status || req->actual != req->length)
849 DBG((struct zero_dev *) ep->driver_data,
850 "setup complete --> %d, %d/%d\n",
851 req->status, req->actual, req->length);
852}
853
854/*
855 * The setup() callback implements all the ep0 functionality that's
856 * not handled lower down, in hardware or the hardware driver (like
857 * device and endpoint feature flags, and their status). It's all
858 * housekeeping for the gadget function we're implementing. Most of
859 * the work is in config-specific setup.
860 */
861static int
862zero_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
863{
864 struct zero_dev *dev = get_gadget_data(gadget);
865 struct usb_request *req = dev->req;
866 int value = -EOPNOTSUPP;
867 u16 w_index = le16_to_cpu(ctrl->wIndex);
868 u16 w_value = le16_to_cpu(ctrl->wValue);
869 u16 w_length = le16_to_cpu(ctrl->wLength);
870
871 /* usually this stores reply data in the pre-allocated ep0 buffer,
872 * but config change events will reconfigure hardware.
873 */
874 req->zero = 0;
875 switch (ctrl->bRequest) {
876
877 case USB_REQ_GET_DESCRIPTOR:
878 if (ctrl->bRequestType != USB_DIR_IN)
879 goto unknown;
880 switch (w_value >> 8) {
881
882 case USB_DT_DEVICE:
883 value = min(w_length, (u16) sizeof device_desc);
884 memcpy(req->buf, &device_desc, value);
885 break;
886 case USB_DT_DEVICE_QUALIFIER:
887 if (!gadget_is_dualspeed(gadget))
888 break;
889 value = min(w_length, (u16) sizeof dev_qualifier);
890 memcpy(req->buf, &dev_qualifier, value);
891 break;
892
893 case USB_DT_OTHER_SPEED_CONFIG:
894 if (!gadget_is_dualspeed(gadget))
895 break;
896 // FALLTHROUGH
897 case USB_DT_CONFIG:
898 value = config_buf(gadget, req->buf,
899 w_value >> 8,
900 w_value & 0xff);
901 if (value >= 0)
902 value = min(w_length, (u16) value);
903 break;
904
905 case USB_DT_STRING:
906 /* wIndex == language code.
907 * this driver only handles one language, you can
908 * add string tables for other languages, using
909 * any UTF-8 characters
910 */
911 value = usb_gadget_get_string(&stringtab,
912 w_value & 0xff, req->buf);
913 if (value >= 0)
914 value = min(w_length, (u16) value);
915 break;
916 }
917 break;
918
919 /* currently two configs, two speeds */
920 case USB_REQ_SET_CONFIGURATION:
921 if (ctrl->bRequestType != 0)
922 goto unknown;
923 if (gadget->a_hnp_support)
924 DBG(dev, "HNP available\n");
925 else if (gadget->a_alt_hnp_support)
926 DBG(dev, "HNP needs a different root port\n");
927 else
928 VDBG(dev, "HNP inactive\n");
929 spin_lock(&dev->lock);
930 value = zero_set_config(dev, w_value);
931 spin_unlock(&dev->lock);
932 break;
933 case USB_REQ_GET_CONFIGURATION:
934 if (ctrl->bRequestType != USB_DIR_IN)
935 goto unknown;
936 *(u8 *)req->buf = dev->config;
937 value = min(w_length, (u16) 1);
938 break;
939
940 /* until we add altsetting support, or other interfaces,
941 * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
942 * and already killed pending endpoint I/O.
943 */
944 case USB_REQ_SET_INTERFACE:
945 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
946 goto unknown;
947 spin_lock(&dev->lock);
948 if (dev->config && w_index == 0 && w_value == 0) {
949 u8 config = dev->config;
950
951 /* resets interface configuration, forgets about
952 * previous transaction state (queued bufs, etc)
953 * and re-inits endpoint state (toggle etc)
954 * no response queued, just zero status == success.
955 * if we had more than one interface we couldn't
956 * use this "reset the config" shortcut.
957 */
958 zero_reset_config(dev);
959 zero_set_config(dev, config);
960 value = 0;
961 }
962 spin_unlock(&dev->lock);
963 break;
964 case USB_REQ_GET_INTERFACE:
965 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
966 goto unknown;
967 if (!dev->config)
968 break;
969 if (w_index != 0) {
970 value = -EDOM;
971 break;
972 }
973 *(u8 *)req->buf = 0;
974 value = min(w_length, (u16) 1);
975 break;
976
977 /*
978 * These are the same vendor-specific requests supported by
979 * Intel's USB 2.0 compliance test devices. We exceed that
980 * device spec by allowing multiple-packet requests.
981 */
982 case 0x5b: /* control WRITE test -- fill the buffer */
983 if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
984 goto unknown;
985 if (w_value || w_index)
986 break;
987 /* just read that many bytes into the buffer */
988 if (w_length > USB_BUFSIZ)
989 break;
990 value = w_length;
991 break;
992 case 0x5c: /* control READ test -- return the buffer */
993 if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
994 goto unknown;
995 if (w_value || w_index)
996 break;
997 /* expect those bytes are still in the buffer; send back */
998 if (w_length > USB_BUFSIZ
999 || w_length != req->length)
1000 break;
1001 value = w_length;
1002 break;
1003
1004 default:
1005unknown:
1006 VDBG(dev,
1007 "unknown control req%02x.%02x v%04x i%04x l%d\n",
1008 ctrl->bRequestType, ctrl->bRequest,
1009 w_value, w_index, w_length);
1010 }
1011
1012 /* respond with data transfer before status phase? */
1013 if (value >= 0) {
1014 req->length = value;
1015 req->zero = value < w_length;
1016 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
1017 if (value < 0) {
1018 DBG(dev, "ep_queue --> %d\n", value);
1019 req->status = 0;
1020 zero_setup_complete(gadget->ep0, req);
1021 }
1022 }
1023
1024 /* device either stalls (value < 0) or reports success */
1025 return value;
1026}
1027
1028static void zero_disconnect(struct usb_gadget *gadget)
1029{
1030 struct zero_dev *dev = get_gadget_data(gadget);
1031 unsigned long flags;
1032
1033 spin_lock_irqsave(&dev->lock, flags);
1034 zero_reset_config(dev);
1035
1036 /* a more significant application might have some non-usb
1037 * activities to quiesce here, saving resources like power
1038 * or pushing the notification up a network stack.
1039 */
1040 spin_unlock_irqrestore(&dev->lock, flags);
1041
1042 /* next we may get setup() calls to enumerate new connections;
1043 * or an unbind() during shutdown (including removing module).
1044 */
1045}
1046
1047static void zero_autoresume(unsigned long _dev)
1048{
1049 struct zero_dev *dev = (struct zero_dev *) _dev;
1050 int status;
1051
1052 /* normally the host would be woken up for something
1053 * more significant than just a timer firing...
1054 */
1055 if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
1056 status = usb_gadget_wakeup(dev->gadget);
1057 DBG(dev, "wakeup --> %d\n", status);
1058 }
1059} 194}
1060 195
1061/*-------------------------------------------------------------------------*/ 196/*-------------------------------------------------------------------------*/
1062 197
1063static void zero_unbind(struct usb_gadget *gadget) 198static int __init zero_bind(struct usb_composite_dev *cdev)
1064{ 199{
1065 struct zero_dev *dev = get_gadget_data(gadget);
1066
1067 DBG(dev, "unbind\n");
1068
1069 /* we've already been disconnected ... no i/o is active */
1070 if (dev->req) {
1071 dev->req->length = USB_BUFSIZ;
1072 free_ep_req(gadget->ep0, dev->req);
1073 }
1074 del_timer_sync(&dev->resume);
1075 kfree(dev);
1076 set_gadget_data(gadget, NULL);
1077}
1078
1079static int __init zero_bind(struct usb_gadget *gadget)
1080{
1081 struct zero_dev *dev;
1082 struct usb_ep *ep;
1083 int gcnum; 200 int gcnum;
201 struct usb_gadget *gadget = cdev->gadget;
202 int id;
1084 203
1085 /* FIXME this can't yet work right with SH ... it has only 204 /* Allocate string descriptor numbers ... note that string
1086 * one configuration, numbered one. 205 * contents can be overridden by the composite_dev glue.
1087 */ 206 */
1088 if (gadget_is_sh(gadget)) 207 id = usb_string_id(cdev);
1089 return -ENODEV; 208 if (id < 0)
1090 209 return id;
1091 /* Bulk-only drivers like this one SHOULD be able to 210 strings_dev[STRING_MANUFACTURER_IDX].id = id;
1092 * autoconfigure on any sane usb controller driver, 211 device_desc.iManufacturer = id;
1093 * but there may also be important quirks to address. 212
213 id = usb_string_id(cdev);
214 if (id < 0)
215 return id;
216 strings_dev[STRING_PRODUCT_IDX].id = id;
217 device_desc.iProduct = id;
218
219 id = usb_string_id(cdev);
220 if (id < 0)
221 return id;
222 strings_dev[STRING_SERIAL_IDX].id = id;
223 device_desc.iSerialNumber = id;
224
225 /* Register primary, then secondary configuration. Note that
226 * SH3 only allows one config...
1094 */ 227 */
1095 usb_ep_autoconfig_reset(gadget); 228 if (loopdefault) {
1096 ep = usb_ep_autoconfig(gadget, &fs_source_desc); 229 loopback_add(cdev);
1097 if (!ep) { 230 if (!gadget_is_sh(gadget))
1098autoconf_fail: 231 sourcesink_add(cdev);
1099 pr_err("%s: can't autoconfigure on %s\n", 232 } else {
1100 shortname, gadget->name); 233 sourcesink_add(cdev);
1101 return -ENODEV; 234 if (!gadget_is_sh(gadget))
235 loopback_add(cdev);
1102 } 236 }
1103 EP_IN_NAME = ep->name;
1104 ep->driver_data = ep; /* claim */
1105
1106 ep = usb_ep_autoconfig(gadget, &fs_sink_desc);
1107 if (!ep)
1108 goto autoconf_fail;
1109 EP_OUT_NAME = ep->name;
1110 ep->driver_data = ep; /* claim */
1111 237
1112 gcnum = usb_gadget_controller_number(gadget); 238 gcnum = usb_gadget_controller_number(gadget);
1113 if (gcnum >= 0) 239 if (gcnum >= 0)
@@ -1115,144 +241,44 @@ autoconf_fail:
1115 else { 241 else {
1116 /* gadget zero is so simple (for now, no altsettings) that 242 /* gadget zero is so simple (for now, no altsettings) that
1117 * it SHOULD NOT have problems with bulk-capable hardware. 243 * it SHOULD NOT have problems with bulk-capable hardware.
1118 * so warn about unrcognized controllers, don't panic. 244 * so just warn about unrcognized controllers -- don't panic.
1119 * 245 *
1120 * things like configuration and altsetting numbering 246 * things like configuration and altsetting numbering
1121 * can need hardware-specific attention though. 247 * can need hardware-specific attention though.
1122 */ 248 */
1123 pr_warning("%s: controller '%s' not recognized\n", 249 pr_warning("%s: controller '%s' not recognized\n",
1124 shortname, gadget->name); 250 longname, gadget->name);
1125 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); 251 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
1126 } 252 }
1127 253
1128 254
1129 /* ok, we made sense of the hardware ... */ 255 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname);
1130 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1131 if (!dev)
1132 return -ENOMEM;
1133 spin_lock_init(&dev->lock);
1134 dev->gadget = gadget;
1135 set_gadget_data(gadget, dev);
1136
1137 init_timer(&dev->resume);
1138 dev->resume.function = zero_autoresume;
1139 dev->resume.data = (unsigned long) dev;
1140
1141 /* preallocate control response and buffer */
1142 dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
1143 if (!dev->req)
1144 goto enomem;
1145 dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
1146 if (!dev->req->buf)
1147 goto enomem;
1148
1149 dev->req->complete = zero_setup_complete;
1150
1151 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1152
1153 if (gadget_is_dualspeed(gadget)) {
1154 /* assume ep0 uses the same value for both speeds ... */
1155 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
1156
1157 /* and that all endpoints are dual-speed */
1158 hs_source_desc.bEndpointAddress =
1159 fs_source_desc.bEndpointAddress;
1160 hs_sink_desc.bEndpointAddress =
1161 fs_sink_desc.bEndpointAddress;
1162 }
1163
1164 if (gadget_is_otg(gadget)) {
1165 otg_descriptor.bmAttributes |= USB_OTG_HNP,
1166 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1167 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1168 }
1169
1170 usb_gadget_set_selfpowered(gadget);
1171
1172 if (autoresume) {
1173 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1174 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1175 }
1176
1177 gadget->ep0->driver_data = dev;
1178
1179 INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname);
1180 INFO(dev, "using %s, OUT %s IN %s\n", gadget->name,
1181 EP_OUT_NAME, EP_IN_NAME);
1182 256
1183 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", 257 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
1184 init_utsname()->sysname, init_utsname()->release, 258 init_utsname()->sysname, init_utsname()->release,
1185 gadget->name); 259 gadget->name);
1186 260
1187 return 0; 261 return 0;
1188
1189enomem:
1190 zero_unbind(gadget);
1191 return -ENOMEM;
1192} 262}
1193 263
1194/*-------------------------------------------------------------------------*/ 264static struct usb_composite_driver zero_driver = {
1195 265 .name = "zero",
1196static void zero_suspend(struct usb_gadget *gadget) 266 .dev = &device_desc,
1197{ 267 .strings = dev_strings,
1198 struct zero_dev *dev = get_gadget_data(gadget);
1199
1200 if (gadget->speed == USB_SPEED_UNKNOWN)
1201 return;
1202
1203 if (autoresume) {
1204 mod_timer(&dev->resume, jiffies + (HZ * autoresume));
1205 DBG(dev, "suspend, wakeup in %d seconds\n", autoresume);
1206 } else
1207 DBG(dev, "suspend\n");
1208}
1209
1210static void zero_resume(struct usb_gadget *gadget)
1211{
1212 struct zero_dev *dev = get_gadget_data(gadget);
1213
1214 DBG(dev, "resume\n");
1215 del_timer(&dev->resume);
1216}
1217
1218
1219/*-------------------------------------------------------------------------*/
1220
1221static struct usb_gadget_driver zero_driver = {
1222#ifdef CONFIG_USB_GADGET_DUALSPEED
1223 .speed = USB_SPEED_HIGH,
1224#else
1225 .speed = USB_SPEED_FULL,
1226#endif
1227 .function = (char *) longname,
1228 .bind = zero_bind, 268 .bind = zero_bind,
1229 .unbind = __exit_p(zero_unbind),
1230
1231 .setup = zero_setup,
1232 .disconnect = zero_disconnect,
1233
1234 .suspend = zero_suspend,
1235 .resume = zero_resume,
1236
1237 .driver = {
1238 .name = (char *) shortname,
1239 .owner = THIS_MODULE,
1240 },
1241}; 269};
1242 270
1243MODULE_AUTHOR("David Brownell"); 271MODULE_AUTHOR("David Brownell");
1244MODULE_LICENSE("GPL"); 272MODULE_LICENSE("GPL");
1245 273
1246
1247static int __init init(void) 274static int __init init(void)
1248{ 275{
1249 return usb_gadget_register_driver(&zero_driver); 276 return usb_composite_register(&zero_driver);
1250} 277}
1251module_init(init); 278module_init(init);
1252 279
1253static void __exit cleanup(void) 280static void __exit cleanup(void)
1254{ 281{
1255 usb_gadget_unregister_driver(&zero_driver); 282 usb_composite_unregister(&zero_driver);
1256} 283}
1257module_exit(cleanup); 284module_exit(cleanup);
1258
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index 08a4335401a9..bf69f4739107 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -19,263 +19,304 @@
19#define USB_MCFG_RDCOMB (1<<30) 19#define USB_MCFG_RDCOMB (1<<30)
20#define USB_MCFG_SSDEN (1<<23) 20#define USB_MCFG_SSDEN (1<<23)
21#define USB_MCFG_PHYPLLEN (1<<19) 21#define USB_MCFG_PHYPLLEN (1<<19)
22#define USB_MCFG_UCECLKEN (1<<18)
22#define USB_MCFG_EHCCLKEN (1<<17) 23#define USB_MCFG_EHCCLKEN (1<<17)
24#ifdef CONFIG_DMA_COHERENT
23#define USB_MCFG_UCAM (1<<7) 25#define USB_MCFG_UCAM (1<<7)
26#else
27#define USB_MCFG_UCAM (0)
28#endif
24#define USB_MCFG_EBMEN (1<<3) 29#define USB_MCFG_EBMEN (1<<3)
25#define USB_MCFG_EMEMEN (1<<2) 30#define USB_MCFG_EMEMEN (1<<2)
26 31
27#define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN) 32#define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN)
33#define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
34 USBH_ENABLE_CE | USB_MCFG_SSDEN | \
35 USB_MCFG_UCAM | USB_MCFG_EBMEN | \
36 USB_MCFG_EMEMEN)
28 37
29#ifdef CONFIG_DMA_COHERENT
30#define USBH_ENABLE_INIT (USBH_ENABLE_CE \
31 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
32 | USB_MCFG_SSDEN | USB_MCFG_UCAM \
33 | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
34#else
35#define USBH_ENABLE_INIT (USBH_ENABLE_CE \
36 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
37 | USB_MCFG_SSDEN \
38 | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
39#endif
40#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN) 38#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
41 39
42extern int usb_disabled(void); 40extern int usb_disabled(void);
43 41
44/*-------------------------------------------------------------------------*/ 42static void au1xxx_start_ehc(void)
45
46static void au1xxx_start_ehc(struct platform_device *dev)
47{ 43{
48 pr_debug(__FILE__ ": starting Au1xxx EHCI USB Controller\n"); 44 /* enable clock to EHCI block and HS PHY PLL*/
49 45 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
50 /* write HW defaults again in case Yamon cleared them */ 46 au_sync();
51 if (au_readl(USB_HOST_CONFIG) == 0) {
52 au_writel(0x00d02000, USB_HOST_CONFIG);
53 au_readl(USB_HOST_CONFIG);
54 udelay(1000);
55 }
56 /* enable host controller */
57 au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
58 au_readl(USB_HOST_CONFIG);
59 udelay(1000);
60 au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG),
61 USB_HOST_CONFIG);
62 au_readl(USB_HOST_CONFIG);
63 udelay(1000); 47 udelay(1000);
64 48
65 pr_debug(__FILE__ ": Clock to USB host has been enabled\n"); 49 /* enable EHCI mmio */
50 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
51 au_sync();
52 udelay(1000);
66} 53}
67 54
68static void au1xxx_stop_ehc(struct platform_device *dev) 55static void au1xxx_stop_ehc(void)
69{ 56{
70 pr_debug(__FILE__ ": stopping Au1xxx EHCI USB Controller\n"); 57 unsigned long c;
71 58
72 /* Disable mem */ 59 /* Disable mem */
73 au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG); 60 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
61 au_sync();
74 udelay(1000); 62 udelay(1000);
75 /* Disable clock */ 63
76 au_writel(~USB_MCFG_EHCCLKEN & au_readl(USB_HOST_CONFIG), 64 /* Disable EHC clock. If the HS PHY is unused disable it too. */
77 USB_HOST_CONFIG); 65 c = au_readl(USB_HOST_CONFIG) & ~USB_MCFG_EHCCLKEN;
78 au_readl(USB_HOST_CONFIG); 66 if (!(c & USB_MCFG_UCECLKEN)) /* UDC disabled? */
67 c &= ~USB_MCFG_PHYPLLEN; /* yes: disable HS PHY PLL */
68 au_writel(c, USB_HOST_CONFIG);
69 au_sync();
79} 70}
80 71
81/*-------------------------------------------------------------------------*/ 72static const struct hc_driver ehci_au1xxx_hc_driver = {
73 .description = hcd_name,
74 .product_desc = "Au1xxx EHCI",
75 .hcd_priv_size = sizeof(struct ehci_hcd),
76
77 /*
78 * generic hardware linkage
79 */
80 .irq = ehci_irq,
81 .flags = HCD_MEMORY | HCD_USB2,
82
83 /*
84 * basic lifecycle operations
85 *
86 * FIXME -- ehci_init() doesn't do enough here.
87 * See ehci-ppc-soc for a complete implementation.
88 */
89 .reset = ehci_init,
90 .start = ehci_run,
91 .stop = ehci_stop,
92 .shutdown = ehci_shutdown,
82 93
83/* configure so an HC device and id are always provided */ 94 /*
84/* always called with process context; sleeping is OK */ 95 * managing i/o requests and associated device resources
96 */
97 .urb_enqueue = ehci_urb_enqueue,
98 .urb_dequeue = ehci_urb_dequeue,
99 .endpoint_disable = ehci_endpoint_disable,
85 100
86/** 101 /*
87 * usb_ehci_au1xxx_probe - initialize Au1xxx-based HCDs 102 * scheduling support
88 * Context: !in_interrupt() 103 */
89 * 104 .get_frame_number = ehci_get_frame,
90 * Allocates basic resources for this USB host controller, and 105
91 * then invokes the start() method for the HCD associated with it 106 /*
92 * through the hotplug entry's driver_data. 107 * root hub support
93 * 108 */
94 */ 109 .hub_status_data = ehci_hub_status_data,
95int usb_ehci_au1xxx_probe(const struct hc_driver *driver, 110 .hub_control = ehci_hub_control,
96 struct usb_hcd **hcd_out, struct platform_device *dev) 111 .bus_suspend = ehci_bus_suspend,
112 .bus_resume = ehci_bus_resume,
113 .relinquish_port = ehci_relinquish_port,
114 .port_handed_over = ehci_port_handed_over,
115};
116
117static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
97{ 118{
98 int retval;
99 struct usb_hcd *hcd; 119 struct usb_hcd *hcd;
100 struct ehci_hcd *ehci; 120 struct ehci_hcd *ehci;
121 int ret;
101 122
102#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT) 123 if (usb_disabled())
124 return -ENODEV;
103 125
126#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
104 /* Au1200 AB USB does not support coherent memory */ 127 /* Au1200 AB USB does not support coherent memory */
105 if (!(read_c0_prid() & 0xff)) { 128 if (!(read_c0_prid() & 0xff)) {
106 pr_info("%s: this is chip revision AB!\n", dev->name); 129 printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
107 pr_info("%s: update your board or re-configure the kernel\n", 130 printk(KERN_INFO "%s: update your board or re-configure"
108 dev->name); 131 " the kernel\n", pdev->name);
109 return -ENODEV; 132 return -ENODEV;
110 } 133 }
111#endif 134#endif
112 135
113 au1xxx_start_ehc(dev); 136 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
114
115 if (dev->resource[1].flags != IORESOURCE_IRQ) {
116 pr_debug("resource[1] is not IORESOURCE_IRQ"); 137 pr_debug("resource[1] is not IORESOURCE_IRQ");
117 retval = -ENOMEM; 138 return -ENOMEM;
118 } 139 }
119 hcd = usb_create_hcd(driver, &dev->dev, "Au1xxx"); 140 hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
120 if (!hcd) 141 if (!hcd)
121 return -ENOMEM; 142 return -ENOMEM;
122 hcd->rsrc_start = dev->resource[0].start; 143
123 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1; 144 hcd->rsrc_start = pdev->resource[0].start;
145 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
124 146
125 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 147 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
126 pr_debug("request_mem_region failed"); 148 pr_debug("request_mem_region failed");
127 retval = -EBUSY; 149 ret = -EBUSY;
128 goto err1; 150 goto err1;
129 } 151 }
130 152
131 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 153 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
132 if (!hcd->regs) { 154 if (!hcd->regs) {
133 pr_debug("ioremap failed"); 155 pr_debug("ioremap failed");
134 retval = -ENOMEM; 156 ret = -ENOMEM;
135 goto err2; 157 goto err2;
136 } 158 }
137 159
160 au1xxx_start_ehc();
161
138 ehci = hcd_to_ehci(hcd); 162 ehci = hcd_to_ehci(hcd);
139 ehci->caps = hcd->regs; 163 ehci->caps = hcd->regs;
140 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase)); 164 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
141 /* cache this readonly data; minimize chip reads */ 165 /* cache this readonly data; minimize chip reads */
142 ehci->hcs_params = readl(&ehci->caps->hcs_params); 166 ehci->hcs_params = readl(&ehci->caps->hcs_params);
143 167
144 /* ehci_hcd_init(hcd_to_ehci(hcd)); */ 168 ret = usb_add_hcd(hcd, pdev->resource[1].start,
145 169 IRQF_DISABLED | IRQF_SHARED);
146 retval = 170 if (ret == 0) {
147 usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED | IRQF_SHARED); 171 platform_set_drvdata(pdev, hcd);
148 if (retval == 0) 172 return ret;
149 return retval; 173 }
150 174
151 au1xxx_stop_ehc(dev); 175 au1xxx_stop_ehc();
152 iounmap(hcd->regs); 176 iounmap(hcd->regs);
153err2: 177err2:
154 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 178 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
155err1: 179err1:
156 usb_put_hcd(hcd); 180 usb_put_hcd(hcd);
157 return retval; 181 return ret;
158} 182}
159 183
160/* may be called without controller electrically present */ 184static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
161/* may be called with controller, bus, and devices active */
162
163/**
164 * usb_ehci_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
165 * @dev: USB Host Controller being removed
166 * Context: !in_interrupt()
167 *
168 * Reverses the effect of usb_ehci_hcd_au1xxx_probe(), first invoking
169 * the HCD's stop() method. It is always called from a thread
170 * context, normally "rmmod", "apmd", or something similar.
171 *
172 */
173void usb_ehci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
174{ 185{
186 struct usb_hcd *hcd = platform_get_drvdata(pdev);
187
175 usb_remove_hcd(hcd); 188 usb_remove_hcd(hcd);
176 iounmap(hcd->regs); 189 iounmap(hcd->regs);
177 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 190 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
178 usb_put_hcd(hcd); 191 usb_put_hcd(hcd);
179 au1xxx_stop_ehc(dev); 192 au1xxx_stop_ehc();
193 platform_set_drvdata(pdev, NULL);
194
195 return 0;
180} 196}
181 197
182/*-------------------------------------------------------------------------*/ 198#ifdef CONFIG_PM
199static int ehci_hcd_au1xxx_drv_suspend(struct platform_device *pdev,
200 pm_message_t message)
201{
202 struct usb_hcd *hcd = platform_get_drvdata(pdev);
203 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
204 unsigned long flags;
205 int rc;
183 206
184static const struct hc_driver ehci_au1xxx_hc_driver = { 207 return 0;
185 .description = hcd_name, 208 rc = 0;
186 .product_desc = "Au1xxx EHCI",
187 .hcd_priv_size = sizeof(struct ehci_hcd),
188 209
189 /* 210 if (time_before(jiffies, ehci->next_statechange))
190 * generic hardware linkage 211 msleep(10);
191 */
192 .irq = ehci_irq,
193 .flags = HCD_MEMORY | HCD_USB2,
194 212
195 /* 213 /* Root hub was already suspended. Disable irq emission and
196 * basic lifecycle operations 214 * mark HW unaccessible, bail out if RH has been resumed. Use
215 * the spinlock to properly synchronize with possible pending
216 * RH suspend or resume activity.
197 * 217 *
198 * FIXME -- ehci_init() doesn't do enough here. 218 * This is still racy as hcd->state is manipulated outside of
199 * See ehci-ppc-soc for a complete implementation. 219 * any locks =P But that will be a different fix.
200 */
201 .reset = ehci_init,
202 .start = ehci_run,
203 .stop = ehci_stop,
204 .shutdown = ehci_shutdown,
205
206 /*
207 * managing i/o requests and associated device resources
208 */ 220 */
209 .urb_enqueue = ehci_urb_enqueue, 221 spin_lock_irqsave(&ehci->lock, flags);
210 .urb_dequeue = ehci_urb_dequeue, 222 if (hcd->state != HC_STATE_SUSPENDED) {
211 .endpoint_disable = ehci_endpoint_disable, 223 rc = -EINVAL;
224 goto bail;
225 }
226 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
227 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
212 228
213 /* 229 /* make sure snapshot being resumed re-enumerates everything */
214 * scheduling support 230 if (message.event == PM_EVENT_PRETHAW) {
215 */ 231 ehci_halt(ehci);
216 .get_frame_number = ehci_get_frame, 232 ehci_reset(ehci);
233 }
217 234
218 /* 235 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
219 * root hub support
220 */
221 .hub_status_data = ehci_hub_status_data,
222 .hub_control = ehci_hub_control,
223 .bus_suspend = ehci_bus_suspend,
224 .bus_resume = ehci_bus_resume,
225 .relinquish_port = ehci_relinquish_port,
226 .port_handed_over = ehci_port_handed_over,
227};
228 236
229/*-------------------------------------------------------------------------*/ 237 au1xxx_stop_ehc();
230 238
231static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev) 239bail:
232{ 240 spin_unlock_irqrestore(&ehci->lock, flags);
233 struct usb_hcd *hcd = NULL;
234 int ret;
235 241
236 pr_debug("In ehci_hcd_au1xxx_drv_probe\n"); 242 // could save FLADJ in case of Vaux power loss
243 // ... we'd only use it to handle clock skew
237 244
238 if (usb_disabled()) 245 return rc;
239 return -ENODEV;
240
241 /* FIXME we only want one one probe() not two */
242 ret = usb_ehci_au1xxx_probe(&ehci_au1xxx_hc_driver, &hcd, pdev);
243 return ret;
244} 246}
245 247
246static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev) 248
249static int ehci_hcd_au1xxx_drv_resume(struct platform_device *pdev)
247{ 250{
248 struct usb_hcd *hcd = platform_get_drvdata(pdev); 251 struct usb_hcd *hcd = platform_get_drvdata(pdev);
252 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
249 253
250 /* FIXME we only want one one remove() not two */ 254 au1xxx_start_ehc();
251 usb_ehci_au1xxx_remove(hcd, pdev);
252 return 0;
253}
254 255
255 /*TBD*/ 256 // maybe restore FLADJ
256/*static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
257{
258 struct platform_device *pdev = to_platform_device(dev);
259 struct usb_hcd *hcd = dev_get_drvdata(dev);
260 257
261 return 0; 258 if (time_before(jiffies, ehci->next_statechange))
262} 259 msleep(100);
263static int ehci_hcd_au1xxx_drv_resume(struct device *dev) 260
264{ 261 /* Mark hardware accessible again as we are out of D3 state by now */
265 struct platform_device *pdev = to_platform_device(dev); 262 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
266 struct usb_hcd *hcd = dev_get_drvdata(dev); 263
264 /* If CF is still set, we maintained PCI Vaux power.
265 * Just undo the effect of ehci_pci_suspend().
266 */
267 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
268 int mask = INTR_MASK;
269
270 if (!hcd->self.root_hub->do_remote_wakeup)
271 mask &= ~STS_PCD;
272 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
273 ehci_readl(ehci, &ehci->regs->intr_enable);
274 return 0;
275 }
276
277 ehci_dbg(ehci, "lost power, restarting\n");
278 usb_root_hub_lost_power(hcd->self.root_hub);
279
280 /* Else reset, to cope with power loss or flush-to-storage
281 * style "resume" having let BIOS kick in during reboot.
282 */
283 (void) ehci_halt(ehci);
284 (void) ehci_reset(ehci);
285
286 /* emptying the schedule aborts any urbs */
287 spin_lock_irq(&ehci->lock);
288 if (ehci->reclaim)
289 end_unlink_async(ehci);
290 ehci_work(ehci);
291 spin_unlock_irq(&ehci->lock);
292
293 ehci_writel(ehci, ehci->command, &ehci->regs->command);
294 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
295 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
296
297 /* here we "know" root ports should always stay powered */
298 ehci_port_power(ehci, 1);
299
300 hcd->state = HC_STATE_SUSPENDED;
267 301
268 return 0; 302 return 0;
269} 303}
270*/ 304
271MODULE_ALIAS("platform:au1xxx-ehci"); 305#else
306#define ehci_hcd_au1xxx_drv_suspend NULL
307#define ehci_hcd_au1xxx_drv_resume NULL
308#endif
309
272static struct platform_driver ehci_hcd_au1xxx_driver = { 310static struct platform_driver ehci_hcd_au1xxx_driver = {
273 .probe = ehci_hcd_au1xxx_drv_probe, 311 .probe = ehci_hcd_au1xxx_drv_probe,
274 .remove = ehci_hcd_au1xxx_drv_remove, 312 .remove = ehci_hcd_au1xxx_drv_remove,
275 .shutdown = usb_hcd_platform_shutdown, 313 .shutdown = usb_hcd_platform_shutdown,
276 /*.suspend = ehci_hcd_au1xxx_drv_suspend, */ 314 .suspend = ehci_hcd_au1xxx_drv_suspend,
277 /*.resume = ehci_hcd_au1xxx_drv_resume, */ 315 .resume = ehci_hcd_au1xxx_drv_resume,
278 .driver = { 316 .driver = {
279 .name = "au1xxx-ehci", 317 .name = "au1xxx-ehci",
318 .owner = THIS_MODULE,
280 } 319 }
281}; 320};
321
322MODULE_ALIAS("platform:au1xxx-ehci");
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 0f82fdcaef09..b0f8ed5a7fb9 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -676,7 +676,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
676 "%s\n" 676 "%s\n"
677 "SUSPENDED (no register access)\n", 677 "SUSPENDED (no register access)\n",
678 hcd->self.controller->bus->name, 678 hcd->self.controller->bus->name,
679 hcd->self.controller->bus_id, 679 dev_name(hcd->self.controller),
680 hcd->product_desc); 680 hcd->product_desc);
681 goto done; 681 goto done;
682 } 682 }
@@ -688,7 +688,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
688 "%s\n" 688 "%s\n"
689 "EHCI %x.%02x, hcd state %d\n", 689 "EHCI %x.%02x, hcd state %d\n",
690 hcd->self.controller->bus->name, 690 hcd->self.controller->bus->name,
691 hcd->self.controller->bus_id, 691 dev_name(hcd->self.controller),
692 hcd->product_desc, 692 hcd->product_desc,
693 i >> 8, i & 0x0ff, hcd->state); 693 i >> 8, i & 0x0ff, hcd->state);
694 size -= temp; 694 size -= temp;
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 7370d6187c64..01c3da34f678 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -56,7 +56,7 @@ int usb_hcd_fsl_probe(const struct hc_driver *driver,
56 pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data; 56 pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data;
57 if (!pdata) { 57 if (!pdata) {
58 dev_err(&pdev->dev, 58 dev_err(&pdev->dev,
59 "No platform data for %s.\n", pdev->dev.bus_id); 59 "No platform data for %s.\n", dev_name(&pdev->dev));
60 return -ENODEV; 60 return -ENODEV;
61 } 61 }
62 62
@@ -69,7 +69,7 @@ int usb_hcd_fsl_probe(const struct hc_driver *driver,
69 (pdata->operating_mode == FSL_USB2_DR_OTG))) { 69 (pdata->operating_mode == FSL_USB2_DR_OTG))) {
70 dev_err(&pdev->dev, 70 dev_err(&pdev->dev,
71 "Non Host Mode configured for %s. Wrong driver linked.\n", 71 "Non Host Mode configured for %s. Wrong driver linked.\n",
72 pdev->dev.bus_id); 72 dev_name(&pdev->dev));
73 return -ENODEV; 73 return -ENODEV;
74 } 74 }
75 75
@@ -77,12 +77,12 @@ int usb_hcd_fsl_probe(const struct hc_driver *driver,
77 if (!res) { 77 if (!res) {
78 dev_err(&pdev->dev, 78 dev_err(&pdev->dev,
79 "Found HC with no IRQ. Check %s setup!\n", 79 "Found HC with no IRQ. Check %s setup!\n",
80 pdev->dev.bus_id); 80 dev_name(&pdev->dev));
81 return -ENODEV; 81 return -ENODEV;
82 } 82 }
83 irq = res->start; 83 irq = res->start;
84 84
85 hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id); 85 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
86 if (!hcd) { 86 if (!hcd) {
87 retval = -ENOMEM; 87 retval = -ENOMEM;
88 goto err1; 88 goto err1;
@@ -92,7 +92,7 @@ int usb_hcd_fsl_probe(const struct hc_driver *driver,
92 if (!res) { 92 if (!res) {
93 dev_err(&pdev->dev, 93 dev_err(&pdev->dev,
94 "Found HC with no register addr. Check %s setup!\n", 94 "Found HC with no register addr. Check %s setup!\n",
95 pdev->dev.bus_id); 95 dev_name(&pdev->dev));
96 retval = -ENODEV; 96 retval = -ENODEV;
97 goto err2; 97 goto err2;
98 } 98 }
@@ -132,7 +132,7 @@ int usb_hcd_fsl_probe(const struct hc_driver *driver,
132 err2: 132 err2:
133 usb_put_hcd(hcd); 133 usb_put_hcd(hcd);
134 err1: 134 err1:
135 dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval); 135 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
136 return retval; 136 return retval;
137} 137}
138 138
@@ -230,8 +230,13 @@ static void mpc83xx_usb_setup(struct usb_hcd *hcd)
230 230
231 /* put controller in host mode. */ 231 /* put controller in host mode. */
232 ehci_writel(ehci, 0x00000003, non_ehci + FSL_SOC_USB_USBMODE); 232 ehci_writel(ehci, 0x00000003, non_ehci + FSL_SOC_USB_USBMODE);
233#ifdef CONFIG_PPC_85xx
234 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x00000008);
235 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000080);
236#else
233 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c); 237 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
234 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040); 238 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
239#endif
235 out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001); 240 out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
236} 241}
237 242
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 369a8a5ea7bb..d9d53f289caf 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -84,7 +84,7 @@ static const char hcd_name [] = "ehci_hcd";
84#define EHCI_IAA_MSECS 10 /* arbitrary */ 84#define EHCI_IAA_MSECS 10 /* arbitrary */
85#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ 85#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
86#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */ 86#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */
87#define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */ 87#define EHCI_SHRINK_FRAMES 5 /* async qh unlink delay */
88 88
89/* Initial IRQ latency: faster than hw default */ 89/* Initial IRQ latency: faster than hw default */
90static int log2_irq_thresh = 0; // 0 to 6 90static int log2_irq_thresh = 0; // 0 to 6
diff --git a/drivers/usb/host/ehci-ixp4xx.c b/drivers/usb/host/ehci-ixp4xx.c
index 9d042f220097..f9575c409124 100644
--- a/drivers/usb/host/ehci-ixp4xx.c
+++ b/drivers/usb/host/ehci-ixp4xx.c
@@ -77,12 +77,12 @@ static int ixp4xx_ehci_probe(struct platform_device *pdev)
77 if (!res) { 77 if (!res) {
78 dev_err(&pdev->dev, 78 dev_err(&pdev->dev,
79 "Found HC with no IRQ. Check %s setup!\n", 79 "Found HC with no IRQ. Check %s setup!\n",
80 pdev->dev.bus_id); 80 dev_name(&pdev->dev));
81 return -ENODEV; 81 return -ENODEV;
82 } 82 }
83 irq = res->start; 83 irq = res->start;
84 84
85 hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id); 85 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
86 if (!hcd) { 86 if (!hcd) {
87 retval = -ENOMEM; 87 retval = -ENOMEM;
88 goto fail_create_hcd; 88 goto fail_create_hcd;
@@ -92,7 +92,7 @@ static int ixp4xx_ehci_probe(struct platform_device *pdev)
92 if (!res) { 92 if (!res) {
93 dev_err(&pdev->dev, 93 dev_err(&pdev->dev,
94 "Found HC with no register addr. Check %s setup!\n", 94 "Found HC with no register addr. Check %s setup!\n",
95 pdev->dev.bus_id); 95 dev_name(&pdev->dev));
96 retval = -ENODEV; 96 retval = -ENODEV;
97 goto fail_request_resource; 97 goto fail_request_resource;
98 } 98 }
@@ -126,7 +126,7 @@ fail_ioremap:
126fail_request_resource: 126fail_request_resource:
127 usb_put_hcd(hcd); 127 usb_put_hcd(hcd);
128fail_create_hcd: 128fail_create_hcd:
129 dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval); 129 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
130 return retval; 130 return retval;
131} 131}
132 132
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index ab625f0ba1d9..5fbdc14e63b3 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -204,7 +204,7 @@ static int __init ehci_orion_drv_probe(struct platform_device *pdev)
204 if (irq <= 0) { 204 if (irq <= 0) {
205 dev_err(&pdev->dev, 205 dev_err(&pdev->dev,
206 "Found HC with no IRQ. Check %s setup!\n", 206 "Found HC with no IRQ. Check %s setup!\n",
207 pdev->dev.bus_id); 207 dev_name(&pdev->dev));
208 err = -ENODEV; 208 err = -ENODEV;
209 goto err1; 209 goto err1;
210 } 210 }
@@ -213,7 +213,7 @@ static int __init ehci_orion_drv_probe(struct platform_device *pdev)
213 if (!res) { 213 if (!res) {
214 dev_err(&pdev->dev, 214 dev_err(&pdev->dev,
215 "Found HC with no register addr. Check %s setup!\n", 215 "Found HC with no register addr. Check %s setup!\n",
216 pdev->dev.bus_id); 216 dev_name(&pdev->dev));
217 err = -ENODEV; 217 err = -ENODEV;
218 goto err1; 218 goto err1;
219 } 219 }
@@ -233,7 +233,7 @@ static int __init ehci_orion_drv_probe(struct platform_device *pdev)
233 } 233 }
234 234
235 hcd = usb_create_hcd(&ehci_orion_hc_driver, 235 hcd = usb_create_hcd(&ehci_orion_hc_driver,
236 &pdev->dev, pdev->dev.bus_id); 236 &pdev->dev, dev_name(&pdev->dev));
237 if (!hcd) { 237 if (!hcd) {
238 err = -ENOMEM; 238 err = -ENOMEM;
239 goto err3; 239 goto err3;
@@ -276,7 +276,7 @@ err2:
276 release_mem_region(res->start, res->end - res->start + 1); 276 release_mem_region(res->start, res->end - res->start + 1);
277err1: 277err1:
278 dev_err(&pdev->dev, "init %s fail, %d\n", 278 dev_err(&pdev->dev, "init %s fail, %d\n",
279 pdev->dev.bus_id, err); 279 dev_name(&pdev->dev), err);
280 280
281 return err; 281 return err;
282} 282}
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index 37e6abeb794c..0eba894bcb01 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -128,7 +128,7 @@ static int ps3_ehci_probe(struct ps3_system_bus_device *dev)
128 128
129 dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */ 129 dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */
130 130
131 hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev->core.bus_id); 131 hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev_name(&dev->core));
132 132
133 if (!hcd) { 133 if (!hcd) {
134 dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__, 134 dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index b85b54160cda..2622b6596d7c 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -1116,8 +1116,7 @@ static void scan_async (struct ehci_hcd *ehci)
1116 struct ehci_qh *qh; 1116 struct ehci_qh *qh;
1117 enum ehci_timer_action action = TIMER_IO_WATCHDOG; 1117 enum ehci_timer_action action = TIMER_IO_WATCHDOG;
1118 1118
1119 if (!++(ehci->stamp)) 1119 ehci->stamp = ehci_readl(ehci, &ehci->regs->frame_index);
1120 ehci->stamp++;
1121 timer_action_done (ehci, TIMER_ASYNC_SHRINK); 1120 timer_action_done (ehci, TIMER_ASYNC_SHRINK);
1122rescan: 1121rescan:
1123 qh = ehci->async->qh_next.qh; 1122 qh = ehci->async->qh_next.qh;
@@ -1142,18 +1141,20 @@ rescan:
1142 } 1141 }
1143 } 1142 }
1144 1143
1145 /* unlink idle entries, reducing HC PCI usage as well 1144 /* unlink idle entries, reducing DMA usage as well
1146 * as HCD schedule-scanning costs. delay for any qh 1145 * as HCD schedule-scanning costs. delay for any qh
1147 * we just scanned, there's a not-unusual case that it 1146 * we just scanned, there's a not-unusual case that it
1148 * doesn't stay idle for long. 1147 * doesn't stay idle for long.
1149 * (plus, avoids some kind of re-activation race.) 1148 * (plus, avoids some kind of re-activation race.)
1150 */ 1149 */
1151 if (list_empty (&qh->qtd_list)) { 1150 if (list_empty(&qh->qtd_list)
1152 if (qh->stamp == ehci->stamp) 1151 && qh->qh_state == QH_STATE_LINKED) {
1152 if (!ehci->reclaim
1153 && ((ehci->stamp - qh->stamp) & 0x1fff)
1154 >= (EHCI_SHRINK_FRAMES * 8))
1155 start_unlink_async(ehci, qh);
1156 else
1153 action = TIMER_ASYNC_SHRINK; 1157 action = TIMER_ASYNC_SHRINK;
1154 else if (!ehci->reclaim
1155 && qh->qh_state == QH_STATE_LINKED)
1156 start_unlink_async (ehci, qh);
1157 } 1158 }
1158 1159
1159 qh = qh->qh_next.qh; 1160 qh = qh->qh_next.qh;
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 90245fd8bac4..5799298364fb 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -198,7 +198,10 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
198 break; 198 break;
199 // case TIMER_ASYNC_SHRINK: 199 // case TIMER_ASYNC_SHRINK:
200 default: 200 default:
201 t = EHCI_SHRINK_JIFFIES; 201 /* add a jiffie since we synch against the
202 * 8 KHz uframe counter.
203 */
204 t = DIV_ROUND_UP(EHCI_SHRINK_FRAMES * HZ, 1000) + 1;
202 break; 205 break;
203 } 206 }
204 mod_timer(&ehci->watchdog, t + jiffies); 207 mod_timer(&ehci->watchdog, t + jiffies);
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 20b9a0d07420..31178e10cbbe 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -94,6 +94,10 @@ static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len)
94 u16 w; 94 u16 w;
95 int quot = len % 4; 95 int quot = len % 4;
96 96
97 /* buffer is already in 'usb data order', which is LE. */
98 /* When reading buffer as u16, we have to take care byte order */
99 /* doesn't get mixed up */
100
97 if ((unsigned long)dp2 & 1) { 101 if ((unsigned long)dp2 & 1) {
98 /* not aligned */ 102 /* not aligned */
99 for (; len > 1; len -= 2) { 103 for (; len > 1; len -= 2) {
@@ -105,8 +109,11 @@ static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len)
105 isp116x_write_data16(isp116x, (u16) * dp); 109 isp116x_write_data16(isp116x, (u16) * dp);
106 } else { 110 } else {
107 /* aligned */ 111 /* aligned */
108 for (; len > 1; len -= 2) 112 for (; len > 1; len -= 2) {
109 isp116x_raw_write_data16(isp116x, *dp2++); 113 /* Keep byte order ! */
114 isp116x_raw_write_data16(isp116x, cpu_to_le16(*dp2++));
115 }
116
110 if (len) 117 if (len)
111 isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2)); 118 isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2));
112 } 119 }
@@ -124,6 +131,10 @@ static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len)
124 u16 w; 131 u16 w;
125 int quot = len % 4; 132 int quot = len % 4;
126 133
134 /* buffer is already in 'usb data order', which is LE. */
135 /* When reading buffer as u16, we have to take care byte order */
136 /* doesn't get mixed up */
137
127 if ((unsigned long)dp2 & 1) { 138 if ((unsigned long)dp2 & 1) {
128 /* not aligned */ 139 /* not aligned */
129 for (; len > 1; len -= 2) { 140 for (; len > 1; len -= 2) {
@@ -131,12 +142,16 @@ static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len)
131 *dp++ = w & 0xff; 142 *dp++ = w & 0xff;
132 *dp++ = (w >> 8) & 0xff; 143 *dp++ = (w >> 8) & 0xff;
133 } 144 }
145
134 if (len) 146 if (len)
135 *dp = 0xff & isp116x_read_data16(isp116x); 147 *dp = 0xff & isp116x_read_data16(isp116x);
136 } else { 148 } else {
137 /* aligned */ 149 /* aligned */
138 for (; len > 1; len -= 2) 150 for (; len > 1; len -= 2) {
139 *dp2++ = isp116x_raw_read_data16(isp116x); 151 /* Keep byte order! */
152 *dp2++ = le16_to_cpu(isp116x_raw_read_data16(isp116x));
153 }
154
140 if (len) 155 if (len)
141 *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x); 156 *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x);
142 } 157 }
@@ -1592,7 +1607,7 @@ static int __devinit isp116x_probe(struct platform_device *pdev)
1592 } 1607 }
1593 1608
1594 /* allocate and initialize hcd */ 1609 /* allocate and initialize hcd */
1595 hcd = usb_create_hcd(&isp116x_hc_driver, &pdev->dev, pdev->dev.bus_id); 1610 hcd = usb_create_hcd(&isp116x_hc_driver, &pdev->dev, dev_name(&pdev->dev));
1596 if (!hcd) { 1611 if (!hcd) {
1597 ret = -ENOMEM; 1612 ret = -ENOMEM;
1598 goto err5; 1613 goto err5;
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index 65aa5ecf569a..c858f2adb929 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -38,6 +38,7 @@ struct isp1760_hcd {
38 unsigned i_thresh; 38 unsigned i_thresh;
39 unsigned long reset_done; 39 unsigned long reset_done;
40 unsigned long next_statechange; 40 unsigned long next_statechange;
41 unsigned int devflags;
41}; 42};
42 43
43static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd) 44static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd)
@@ -378,9 +379,31 @@ static int isp1760_hc_setup(struct usb_hcd *hcd)
378{ 379{
379 struct isp1760_hcd *priv = hcd_to_priv(hcd); 380 struct isp1760_hcd *priv = hcd_to_priv(hcd);
380 int result; 381 int result;
381 u32 scratch; 382 u32 scratch, hwmode;
383
384 /* Setup HW Mode Control: This assumes a level active-low interrupt */
385 hwmode = HW_DATA_BUS_32BIT;
386
387 if (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16)
388 hwmode &= ~HW_DATA_BUS_32BIT;
389 if (priv->devflags & ISP1760_FLAG_ANALOG_OC)
390 hwmode |= HW_ANA_DIGI_OC;
391 if (priv->devflags & ISP1760_FLAG_DACK_POL_HIGH)
392 hwmode |= HW_DACK_POL_HIGH;
393 if (priv->devflags & ISP1760_FLAG_DREQ_POL_HIGH)
394 hwmode |= HW_DREQ_POL_HIGH;
395
396 /*
397 * We have to set this first in case we're in 16-bit mode.
398 * Write it twice to ensure correct upper bits if switching
399 * to 16-bit mode.
400 */
401 isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL);
402 isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL);
382 403
383 isp1760_writel(0xdeadbabe, hcd->regs + HC_SCRATCH_REG); 404 isp1760_writel(0xdeadbabe, hcd->regs + HC_SCRATCH_REG);
405 /* Change bus pattern */
406 scratch = isp1760_readl(hcd->regs + HC_CHIP_ID_REG);
384 scratch = isp1760_readl(hcd->regs + HC_SCRATCH_REG); 407 scratch = isp1760_readl(hcd->regs + HC_SCRATCH_REG);
385 if (scratch != 0xdeadbabe) { 408 if (scratch != 0xdeadbabe) {
386 printk(KERN_ERR "ISP1760: Scratch test failed.\n"); 409 printk(KERN_ERR "ISP1760: Scratch test failed.\n");
@@ -403,17 +426,29 @@ static int isp1760_hc_setup(struct usb_hcd *hcd)
403 426
404 /* Step 11 passed */ 427 /* Step 11 passed */
405 428
406 isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_REG); 429 isp1760_info(priv, "bus width: %d, oc: %s\n",
407 isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_ENABLE); 430 (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) ?
431 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ?
432 "analog" : "digital");
408 433
409 /* ATL reset */ 434 /* ATL reset */
410 scratch = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); 435 isp1760_writel(hwmode | ALL_ATX_RESET, hcd->regs + HC_HW_MODE_CTRL);
411 isp1760_writel(scratch | ALL_ATX_RESET, hcd->regs + HC_HW_MODE_CTRL);
412 mdelay(10); 436 mdelay(10);
413 isp1760_writel(scratch, hcd->regs + HC_HW_MODE_CTRL); 437 isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL);
414 438
415 isp1760_writel(PORT1_POWER | PORT1_INIT2, hcd->regs + HC_PORT1_CTRL); 439 isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_REG);
416 mdelay(10); 440 isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_ENABLE);
441
442 /*
443 * PORT 1 Control register of the ISP1760 is the OTG control
444 * register on ISP1761.
445 */
446 if (!(priv->devflags & ISP1760_FLAG_ISP1761) &&
447 !(priv->devflags & ISP1760_FLAG_PORT1_DIS)) {
448 isp1760_writel(PORT1_POWER | PORT1_INIT2,
449 hcd->regs + HC_PORT1_CTRL);
450 mdelay(10);
451 }
417 452
418 priv->hcs_params = isp1760_readl(hcd->regs + HC_HCSPARAMS); 453 priv->hcs_params = isp1760_readl(hcd->regs + HC_HCSPARAMS);
419 454
@@ -453,8 +488,7 @@ static int isp1760_run(struct usb_hcd *hcd)
453 hcd->state = HC_STATE_RUNNING; 488 hcd->state = HC_STATE_RUNNING;
454 isp1760_enable_interrupts(hcd); 489 isp1760_enable_interrupts(hcd);
455 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); 490 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL);
456 temp |= FINAL_HW_CONFIG; 491 isp1760_writel(temp | HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL);
457 isp1760_writel(temp, hcd->regs + HC_HW_MODE_CTRL);
458 492
459 command = isp1760_readl(hcd->regs + HC_USBCMD); 493 command = isp1760_readl(hcd->regs + HC_USBCMD);
460 command &= ~(CMD_LRESET|CMD_RESET); 494 command &= ~(CMD_LRESET|CMD_RESET);
@@ -782,8 +816,8 @@ static void enqueue_one_int_qtd(u32 int_regs, u32 payload,
782 qtd->status |= slot << 16; 816 qtd->status |= slot << 16;
783} 817}
784 818
785void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, 819static void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
786 struct isp1760_qtd *qtd) 820 struct isp1760_qtd *qtd)
787{ 821{
788 struct isp1760_hcd *priv = hcd_to_priv(hcd); 822 struct isp1760_hcd *priv = hcd_to_priv(hcd);
789 u32 skip_map, or_map; 823 u32 skip_map, or_map;
@@ -816,8 +850,8 @@ void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
816 isp1760_writel(buffstatus, hcd->regs + HC_BUFFER_STATUS_REG); 850 isp1760_writel(buffstatus, hcd->regs + HC_BUFFER_STATUS_REG);
817} 851}
818 852
819void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, 853static void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
820 struct isp1760_qtd *qtd) 854 struct isp1760_qtd *qtd)
821{ 855{
822 struct isp1760_hcd *priv = hcd_to_priv(hcd); 856 struct isp1760_hcd *priv = hcd_to_priv(hcd);
823 u32 skip_map, or_map; 857 u32 skip_map, or_map;
@@ -1592,7 +1626,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1592 struct inter_packet_info *ints; 1626 struct inter_packet_info *ints;
1593 u32 i; 1627 u32 i;
1594 u32 reg_base, or_reg, skip_reg; 1628 u32 reg_base, or_reg, skip_reg;
1595 int flags; 1629 unsigned long flags;
1596 struct ptd ptd; 1630 struct ptd ptd;
1597 1631
1598 switch (usb_pipetype(urb->pipe)) { 1632 switch (usb_pipetype(urb->pipe)) {
@@ -2061,7 +2095,7 @@ static void isp1760_endpoint_disable(struct usb_hcd *usb_hcd,
2061 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); 2095 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd);
2062 struct isp1760_qh *qh; 2096 struct isp1760_qh *qh;
2063 struct isp1760_qtd *qtd; 2097 struct isp1760_qtd *qtd;
2064 u32 flags; 2098 unsigned long flags;
2065 2099
2066 spin_lock_irqsave(&priv->lock, flags); 2100 spin_lock_irqsave(&priv->lock, flags);
2067 qh = ep->hcpriv; 2101 qh = ep->hcpriv;
@@ -2112,6 +2146,7 @@ static int isp1760_get_frame(struct usb_hcd *hcd)
2112static void isp1760_stop(struct usb_hcd *hcd) 2146static void isp1760_stop(struct usb_hcd *hcd)
2113{ 2147{
2114 struct isp1760_hcd *priv = hcd_to_priv(hcd); 2148 struct isp1760_hcd *priv = hcd_to_priv(hcd);
2149 u32 temp;
2115 2150
2116 isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1, 2151 isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1,
2117 NULL, 0); 2152 NULL, 0);
@@ -2120,7 +2155,8 @@ static void isp1760_stop(struct usb_hcd *hcd)
2120 spin_lock_irq(&priv->lock); 2155 spin_lock_irq(&priv->lock);
2121 ehci_reset(priv); 2156 ehci_reset(priv);
2122 /* Disable IRQ */ 2157 /* Disable IRQ */
2123 isp1760_writel(HW_DATA_BUS_32BIT, hcd->regs + HC_HW_MODE_CTRL); 2158 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL);
2159 isp1760_writel(temp &= ~HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL);
2124 spin_unlock_irq(&priv->lock); 2160 spin_unlock_irq(&priv->lock);
2125 2161
2126 isp1760_writel(0, hcd->regs + HC_CONFIGFLAG); 2162 isp1760_writel(0, hcd->regs + HC_CONFIGFLAG);
@@ -2128,10 +2164,11 @@ static void isp1760_stop(struct usb_hcd *hcd)
2128 2164
2129static void isp1760_shutdown(struct usb_hcd *hcd) 2165static void isp1760_shutdown(struct usb_hcd *hcd)
2130{ 2166{
2131 u32 command; 2167 u32 command, temp;
2132 2168
2133 isp1760_stop(hcd); 2169 isp1760_stop(hcd);
2134 isp1760_writel(HW_DATA_BUS_32BIT, hcd->regs + HC_HW_MODE_CTRL); 2170 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL);
2171 isp1760_writel(temp &= ~HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL);
2135 2172
2136 command = isp1760_readl(hcd->regs + HC_USBCMD); 2173 command = isp1760_readl(hcd->regs + HC_USBCMD);
2137 command &= ~CMD_RUN; 2174 command &= ~CMD_RUN;
@@ -2183,7 +2220,8 @@ void deinit_kmem_cache(void)
2183} 2220}
2184 2221
2185struct usb_hcd *isp1760_register(u64 res_start, u64 res_len, int irq, 2222struct usb_hcd *isp1760_register(u64 res_start, u64 res_len, int irq,
2186 u64 irqflags, struct device *dev, const char *busname) 2223 u64 irqflags, struct device *dev, const char *busname,
2224 unsigned int devflags)
2187{ 2225{
2188 struct usb_hcd *hcd; 2226 struct usb_hcd *hcd;
2189 struct isp1760_hcd *priv; 2227 struct isp1760_hcd *priv;
@@ -2195,11 +2233,12 @@ struct usb_hcd *isp1760_register(u64 res_start, u64 res_len, int irq,
2195 /* prevent usb-core allocating DMA pages */ 2233 /* prevent usb-core allocating DMA pages */
2196 dev->dma_mask = NULL; 2234 dev->dma_mask = NULL;
2197 2235
2198 hcd = usb_create_hcd(&isp1760_hc_driver, dev, dev->bus_id); 2236 hcd = usb_create_hcd(&isp1760_hc_driver, dev, dev_name(dev));
2199 if (!hcd) 2237 if (!hcd)
2200 return ERR_PTR(-ENOMEM); 2238 return ERR_PTR(-ENOMEM);
2201 2239
2202 priv = hcd_to_priv(hcd); 2240 priv = hcd_to_priv(hcd);
2241 priv->devflags = devflags;
2203 init_memory(priv); 2242 init_memory(priv);
2204 hcd->regs = ioremap(res_start, res_len); 2243 hcd->regs = ioremap(res_start, res_len);
2205 if (!hcd->regs) { 2244 if (!hcd->regs) {
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h
index 3d86d0f6b147..6473dd86993c 100644
--- a/drivers/usb/host/isp1760-hcd.h
+++ b/drivers/usb/host/isp1760-hcd.h
@@ -3,7 +3,8 @@
3 3
4/* exports for if */ 4/* exports for if */
5struct usb_hcd *isp1760_register(u64 res_start, u64 res_len, int irq, 5struct usb_hcd *isp1760_register(u64 res_start, u64 res_len, int irq,
6 u64 irqflags, struct device *dev, const char *busname); 6 u64 irqflags, struct device *dev, const char *busname,
7 unsigned int devflags);
7int init_kmem_once(void); 8int init_kmem_once(void);
8void deinit_kmem_cache(void); 9void deinit_kmem_cache(void);
9 10
@@ -31,6 +32,7 @@ void deinit_kmem_cache(void);
31/* Configuration Register */ 32/* Configuration Register */
32#define HC_HW_MODE_CTRL 0x300 33#define HC_HW_MODE_CTRL 0x300
33#define ALL_ATX_RESET (1 << 31) 34#define ALL_ATX_RESET (1 << 31)
35#define HW_ANA_DIGI_OC (1 << 15)
34#define HW_DATA_BUS_32BIT (1 << 8) 36#define HW_DATA_BUS_32BIT (1 << 8)
35#define HW_DACK_POL_HIGH (1 << 6) 37#define HW_DACK_POL_HIGH (1 << 6)
36#define HW_DREQ_POL_HIGH (1 << 5) 38#define HW_DREQ_POL_HIGH (1 << 5)
@@ -56,13 +58,14 @@ void deinit_kmem_cache(void);
56#define PORT1_POWER (3 << 3) 58#define PORT1_POWER (3 << 3)
57#define PORT1_INIT1 (1 << 7) 59#define PORT1_INIT1 (1 << 7)
58#define PORT1_INIT2 (1 << 23) 60#define PORT1_INIT2 (1 << 23)
61#define HW_OTG_CTRL_SET 0x374
62#define HW_OTG_CTRL_CLR 0x376
59 63
60/* Interrupt Register */ 64/* Interrupt Register */
61#define HC_INTERRUPT_REG 0x310 65#define HC_INTERRUPT_REG 0x310
62 66
63#define HC_INTERRUPT_ENABLE 0x314 67#define HC_INTERRUPT_ENABLE 0x314
64#define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT | HC_EOT_INT) 68#define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT | HC_EOT_INT)
65#define FINAL_HW_CONFIG (HW_GLOBAL_INTR_EN | HW_DATA_BUS_32BIT)
66 69
67#define HC_ISO_INT (1 << 9) 70#define HC_ISO_INT (1 << 9)
68#define HC_ATL_INT (1 << 8) 71#define HC_ATL_INT (1 << 8)
@@ -122,6 +125,19 @@ typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh,
122#define isp1760_err(priv, fmt, args...) \ 125#define isp1760_err(priv, fmt, args...) \
123 dev_err(priv_to_hcd(priv)->self.controller, fmt, ##args) 126 dev_err(priv_to_hcd(priv)->self.controller, fmt, ##args)
124 127
128/*
129 * Device flags that can vary from board to board. All of these
130 * indicate the most "atypical" case, so that a devflags of 0 is
131 * a sane default configuration.
132 */
133#define ISP1760_FLAG_PORT1_DIS 0x00000001 /* Port 1 disabled */
134#define ISP1760_FLAG_BUS_WIDTH_16 0x00000002 /* 16-bit data bus width */
135#define ISP1760_FLAG_OTG_EN 0x00000004 /* Port 1 supports OTG */
136#define ISP1760_FLAG_ANALOG_OC 0x00000008 /* Analog overcurrent */
137#define ISP1760_FLAG_DACK_POL_HIGH 0x00000010 /* DACK active high */
138#define ISP1760_FLAG_DREQ_POL_HIGH 0x00000020 /* DREQ active high */
139#define ISP1760_FLAG_ISP1761 0x00000040 /* Chip is ISP1761 */
140
125/* chip memory management */ 141/* chip memory management */
126struct memory_chunk { 142struct memory_chunk {
127 unsigned int start; 143 unsigned int start;
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index c9db3fe98726..051ef7b6bdc6 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -35,13 +35,15 @@ static int of_isp1760_probe(struct of_device *dev,
35 int virq; 35 int virq;
36 u64 res_len; 36 u64 res_len;
37 int ret; 37 int ret;
38 const unsigned int *prop;
39 unsigned int devflags = 0;
38 40
39 ret = of_address_to_resource(dp, 0, &memory); 41 ret = of_address_to_resource(dp, 0, &memory);
40 if (ret) 42 if (ret)
41 return -ENXIO; 43 return -ENXIO;
42 44
43 res = request_mem_region(memory.start, memory.end - memory.start + 1, 45 res = request_mem_region(memory.start, memory.end - memory.start + 1,
44 dev->dev.bus_id); 46 dev_name(&dev->dev));
45 if (!res) 47 if (!res)
46 return -EBUSY; 48 return -EBUSY;
47 49
@@ -55,8 +57,32 @@ static int of_isp1760_probe(struct of_device *dev,
55 virq = irq_create_of_mapping(oirq.controller, oirq.specifier, 57 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
56 oirq.size); 58 oirq.size);
57 59
60 if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
61 devflags |= ISP1760_FLAG_ISP1761;
62
63 if (of_get_property(dp, "port1-disable", NULL) != NULL)
64 devflags |= ISP1760_FLAG_PORT1_DIS;
65
66 /* Some systems wire up only 16 of the 32 data lines */
67 prop = of_get_property(dp, "bus-width", NULL);
68 if (prop && *prop == 16)
69 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
70
71 if (of_get_property(dp, "port1-otg", NULL) != NULL)
72 devflags |= ISP1760_FLAG_OTG_EN;
73
74 if (of_get_property(dp, "analog-oc", NULL) != NULL)
75 devflags |= ISP1760_FLAG_ANALOG_OC;
76
77 if (of_get_property(dp, "dack-polarity", NULL) != NULL)
78 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
79
80 if (of_get_property(dp, "dreq-polarity", NULL) != NULL)
81 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
82
58 hcd = isp1760_register(memory.start, res_len, virq, 83 hcd = isp1760_register(memory.start, res_len, virq,
59 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev->dev.bus_id); 84 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev),
85 devflags);
60 if (IS_ERR(hcd)) { 86 if (IS_ERR(hcd)) {
61 ret = PTR_ERR(hcd); 87 ret = PTR_ERR(hcd);
62 goto release_reg; 88 goto release_reg;
@@ -87,6 +113,9 @@ static struct of_device_id of_isp1760_match[] = {
87 { 113 {
88 .compatible = "nxp,usb-isp1760", 114 .compatible = "nxp,usb-isp1760",
89 }, 115 },
116 {
117 .compatible = "nxp,usb-isp1761",
118 },
90 { }, 119 { },
91}; 120};
92MODULE_DEVICE_TABLE(of, of_isp1760_match); 121MODULE_DEVICE_TABLE(of, of_isp1760_match);
@@ -116,6 +145,7 @@ static int __devinit isp1761_pci_probe(struct pci_dev *dev,
116 int length; 145 int length;
117 int status = 1; 146 int status = 1;
118 struct usb_hcd *hcd; 147 struct usb_hcd *hcd;
148 unsigned int devflags = 0;
119 149
120 if (usb_disabled()) 150 if (usb_disabled())
121 return -ENODEV; 151 return -ENODEV;
@@ -200,7 +230,8 @@ static int __devinit isp1761_pci_probe(struct pci_dev *dev,
200 230
201 dev->dev.dma_mask = NULL; 231 dev->dev.dma_mask = NULL;
202 hcd = isp1760_register(pci_mem_phy0, length, dev->irq, 232 hcd = isp1760_register(pci_mem_phy0, length, dev->irq,
203 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev->dev.bus_id); 233 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev),
234 devflags);
204 pci_set_drvdata(dev, hcd); 235 pci_set_drvdata(dev, hcd);
205 if (!hcd) 236 if (!hcd)
206 return 0; 237 return 0;
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index e534f9de0f05..a5d8e550d897 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -91,7 +91,7 @@ static void at91_stop_hc(struct platform_device *pdev)
91 91
92/*-------------------------------------------------------------------------*/ 92/*-------------------------------------------------------------------------*/
93 93
94static int usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *); 94static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
95 95
96/* configure so an HC device and id are always provided */ 96/* configure so an HC device and id are always provided */
97/* always called with process context; sleeping is OK */ 97/* always called with process context; sleeping is OK */
@@ -184,13 +184,14 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
184 * context, "rmmod" or something similar. 184 * context, "rmmod" or something similar.
185 * 185 *
186 */ 186 */
187static int usb_hcd_at91_remove(struct usb_hcd *hcd, 187static void usb_hcd_at91_remove(struct usb_hcd *hcd,
188 struct platform_device *pdev) 188 struct platform_device *pdev)
189{ 189{
190 usb_remove_hcd(hcd); 190 usb_remove_hcd(hcd);
191 at91_stop_hc(pdev); 191 at91_stop_hc(pdev);
192 iounmap(hcd->regs); 192 iounmap(hcd->regs);
193 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 193 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
194 usb_put_hcd(hcd);
194 195
195 if (cpu_is_at91sam9261()) 196 if (cpu_is_at91sam9261())
196 clk_put(hclk); 197 clk_put(hclk);
@@ -199,7 +200,6 @@ static int usb_hcd_at91_remove(struct usb_hcd *hcd,
199 fclk = iclk = hclk = NULL; 200 fclk = iclk = hclk = NULL;
200 201
201 dev_set_drvdata(&pdev->dev, NULL); 202 dev_set_drvdata(&pdev->dev, NULL);
202 return 0;
203} 203}
204 204
205/*-------------------------------------------------------------------------*/ 205/*-------------------------------------------------------------------------*/
@@ -309,7 +309,8 @@ static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
309 } 309 }
310 310
311 device_init_wakeup(&pdev->dev, 0); 311 device_init_wakeup(&pdev->dev, 0);
312 return usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev); 312 usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
313 return 0;
313} 314}
314 315
315#ifdef CONFIG_PM 316#ifdef CONFIG_PM
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 68c17f5ea8ea..c0948008fe3d 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -34,7 +34,8 @@
34#ifdef __LITTLE_ENDIAN 34#ifdef __LITTLE_ENDIAN
35#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C) 35#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
36#elif __BIG_ENDIAN 36#elif __BIG_ENDIAN
37#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | USBH_ENABLE_BE) 37#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | \
38 USBH_ENABLE_BE)
38#else 39#else
39#error not byte order defined 40#error not byte order defined
40#endif 41#endif
@@ -46,213 +47,87 @@
46#define USB_MCFG_RDCOMB (1<<30) 47#define USB_MCFG_RDCOMB (1<<30)
47#define USB_MCFG_SSDEN (1<<23) 48#define USB_MCFG_SSDEN (1<<23)
48#define USB_MCFG_OHCCLKEN (1<<16) 49#define USB_MCFG_OHCCLKEN (1<<16)
50#ifdef CONFIG_DMA_COHERENT
49#define USB_MCFG_UCAM (1<<7) 51#define USB_MCFG_UCAM (1<<7)
52#else
53#define USB_MCFG_UCAM (0)
54#endif
50#define USB_MCFG_OBMEN (1<<1) 55#define USB_MCFG_OBMEN (1<<1)
51#define USB_MCFG_OMEMEN (1<<0) 56#define USB_MCFG_OMEMEN (1<<0)
52 57
53#define USBH_ENABLE_CE USB_MCFG_OHCCLKEN 58#define USBH_ENABLE_CE USB_MCFG_OHCCLKEN
54#ifdef CONFIG_DMA_COHERENT 59
55#define USBH_ENABLE_INIT (USB_MCFG_OHCCLKEN \ 60#define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
56 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \ 61 USBH_ENABLE_CE | USB_MCFG_SSDEN | \
57 | USB_MCFG_SSDEN | USB_MCFG_UCAM \ 62 USB_MCFG_UCAM | \
58 | USB_MCFG_OBMEN | USB_MCFG_OMEMEN) 63 USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
59#else 64
60#define USBH_ENABLE_INIT (USB_MCFG_OHCCLKEN \
61 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
62 | USB_MCFG_SSDEN \
63 | USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
64#endif
65#define USBH_DISABLE (USB_MCFG_OBMEN | USB_MCFG_OMEMEN) 65#define USBH_DISABLE (USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
66 66
67#endif /* Au1200 */ 67#endif /* Au1200 */
68 68
69extern int usb_disabled(void); 69extern int usb_disabled(void);
70 70
71/*-------------------------------------------------------------------------*/ 71static void au1xxx_start_ohc(void)
72
73static void au1xxx_start_ohc(struct platform_device *dev)
74{ 72{
75 printk(KERN_DEBUG __FILE__
76 ": starting Au1xxx OHCI USB Controller\n");
77
78 /* enable host controller */ 73 /* enable host controller */
79
80#ifndef CONFIG_SOC_AU1200 74#ifndef CONFIG_SOC_AU1200
81
82 au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG); 75 au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
76 au_sync();
83 udelay(1000); 77 udelay(1000);
84 au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG);
85 udelay(1000);
86
87#else /* Au1200 */
88 78
89 /* write HW defaults again in case Yamon cleared them */ 79 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
90 if (au_readl(USB_HOST_CONFIG) == 0) { 80 au_sync();
91 au_writel(0x00d02000, USB_HOST_CONFIG);
92 au_readl(USB_HOST_CONFIG);
93 udelay(1000);
94 }
95 au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
96 au_readl(USB_HOST_CONFIG);
97 udelay(1000); 81 udelay(1000);
98 au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
99 au_readl(USB_HOST_CONFIG);
100 udelay(1000);
101
102#endif /* Au1200 */
103 82
104#ifndef CONFIG_SOC_AU1200
105 /* wait for reset complete (read register twice; see au1500 errata) */ 83 /* wait for reset complete (read register twice; see au1500 errata) */
106 while (au_readl(USB_HOST_CONFIG), 84 while (au_readl(USB_HOST_CONFIG),
107 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD)) 85 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
108#endif
109 udelay(1000); 86 udelay(1000);
110 87
111 printk(KERN_DEBUG __FILE__
112 ": Clock to USB host has been enabled \n");
113}
114
115static void au1xxx_stop_ohc(struct platform_device *dev)
116{
117 printk(KERN_DEBUG __FILE__
118 ": stopping Au1xxx OHCI USB Controller\n");
119
120#ifndef CONFIG_SOC_AU1200
121
122 /* Disable clock */
123 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
124
125#else /* Au1200 */ 88#else /* Au1200 */
126 89 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
127 /* Disable mem */ 90 au_sync();
128 au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
129 udelay(1000); 91 udelay(1000);
130 /* Disable clock */ 92
131 au_writel(~USBH_ENABLE_CE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG); 93 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
132 au_readl(USB_HOST_CONFIG); 94 au_sync();
95 udelay(2000);
133#endif /* Au1200 */ 96#endif /* Au1200 */
134} 97}
135 98
136 99static void au1xxx_stop_ohc(void)
137/*-------------------------------------------------------------------------*/
138
139/* configure so an HC device and id are always provided */
140/* always called with process context; sleeping is OK */
141
142
143/**
144 * usb_ohci_au1xxx_probe - initialize Au1xxx-based HCDs
145 * Context: !in_interrupt()
146 *
147 * Allocates basic resources for this USB host controller, and
148 * then invokes the start() method for the HCD associated with it
149 * through the hotplug entry's driver_data.
150 *
151 */
152static int usb_ohci_au1xxx_probe(const struct hc_driver *driver,
153 struct platform_device *dev)
154{ 100{
155 int retval; 101#ifdef CONFIG_SOC_AU1200
156 struct usb_hcd *hcd; 102 /* Disable mem */
157 103 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
158#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT) 104 au_sync();
159 /* Au1200 AB USB does not support coherent memory */ 105 udelay(1000);
160 if (!(read_c0_prid() & 0xff)) {
161 pr_info("%s: this is chip revision AB !!\n",
162 dev->name);
163 pr_info("%s: update your board or re-configure the kernel\n",
164 dev->name);
165 return -ENODEV;
166 }
167#endif 106#endif
168 107 /* Disable clock */
169 if (dev->resource[1].flags != IORESOURCE_IRQ) { 108 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
170 pr_debug("resource[1] is not IORESOURCE_IRQ\n"); 109 au_sync();
171 return -ENOMEM;
172 }
173
174 hcd = usb_create_hcd(driver, &dev->dev, "au1xxx");
175 if (!hcd)
176 return -ENOMEM;
177 hcd->rsrc_start = dev->resource[0].start;
178 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
179
180 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
181 pr_debug("request_mem_region failed\n");
182 retval = -EBUSY;
183 goto err1;
184 }
185
186 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
187 if (!hcd->regs) {
188 pr_debug("ioremap failed\n");
189 retval = -ENOMEM;
190 goto err2;
191 }
192
193 au1xxx_start_ohc(dev);
194 ohci_hcd_init(hcd_to_ohci(hcd));
195
196 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED | IRQF_SHARED);
197 if (retval == 0)
198 return retval;
199
200 au1xxx_stop_ohc(dev);
201 iounmap(hcd->regs);
202 err2:
203 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
204 err1:
205 usb_put_hcd(hcd);
206 return retval;
207}
208
209
210/* may be called without controller electrically present */
211/* may be called with controller, bus, and devices active */
212
213/**
214 * usb_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
215 * @dev: USB Host Controller being removed
216 * Context: !in_interrupt()
217 *
218 * Reverses the effect of usb_hcd_au1xxx_probe(), first invoking
219 * the HCD's stop() method. It is always called from a thread
220 * context, normally "rmmod", "apmd", or something similar.
221 *
222 */
223static void usb_ohci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
224{
225 usb_remove_hcd(hcd);
226 au1xxx_stop_ohc(dev);
227 iounmap(hcd->regs);
228 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
229 usb_put_hcd(hcd);
230} 110}
231 111
232/*-------------------------------------------------------------------------*/ 112static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd)
233
234static int __devinit
235ohci_au1xxx_start (struct usb_hcd *hcd)
236{ 113{
237 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 114 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
238 int ret; 115 int ret;
239 116
240 ohci_dbg (ohci, "ohci_au1xxx_start, ohci:%p", ohci); 117 ohci_dbg(ohci, "ohci_au1xxx_start, ohci:%p", ohci);
241 118
242 if ((ret = ohci_init (ohci)) < 0) 119 if ((ret = ohci_init(ohci)) < 0)
243 return ret; 120 return ret;
244 121
245 if ((ret = ohci_run (ohci)) < 0) { 122 if ((ret = ohci_run(ohci)) < 0) {
246 err ("can't start %s", hcd->self.bus_name); 123 err ("can't start %s", hcd->self.bus_name);
247 ohci_stop (hcd); 124 ohci_stop(hcd);
248 return ret; 125 return ret;
249 } 126 }
250 127
251 return 0; 128 return 0;
252} 129}
253 130
254/*-------------------------------------------------------------------------*/
255
256static const struct hc_driver ohci_au1xxx_hc_driver = { 131static const struct hc_driver ohci_au1xxx_hc_driver = {
257 .description = hcd_name, 132 .description = hcd_name,
258 .product_desc = "Au1xxx OHCI", 133 .product_desc = "Au1xxx OHCI",
@@ -296,18 +171,66 @@ static const struct hc_driver ohci_au1xxx_hc_driver = {
296 .start_port_reset = ohci_start_port_reset, 171 .start_port_reset = ohci_start_port_reset,
297}; 172};
298 173
299/*-------------------------------------------------------------------------*/
300
301static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev) 174static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
302{ 175{
303 int ret; 176 int ret;
304 177 struct usb_hcd *hcd;
305 pr_debug ("In ohci_hcd_au1xxx_drv_probe");
306 178
307 if (usb_disabled()) 179 if (usb_disabled())
308 return -ENODEV; 180 return -ENODEV;
309 181
310 ret = usb_ohci_au1xxx_probe(&ohci_au1xxx_hc_driver, pdev); 182#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
183 /* Au1200 AB USB does not support coherent memory */
184 if (!(read_c0_prid() & 0xff)) {
185 printk(KERN_INFO "%s: this is chip revision AB !!\n",
186 pdev->name);
187 printk(KERN_INFO "%s: update your board or re-configure "
188 "the kernel\n", pdev->name);
189 return -ENODEV;
190 }
191#endif
192
193 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
194 pr_debug("resource[1] is not IORESOURCE_IRQ\n");
195 return -ENOMEM;
196 }
197
198 hcd = usb_create_hcd(&ohci_au1xxx_hc_driver, &pdev->dev, "au1xxx");
199 if (!hcd)
200 return -ENOMEM;
201
202 hcd->rsrc_start = pdev->resource[0].start;
203 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
204
205 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
206 pr_debug("request_mem_region failed\n");
207 ret = -EBUSY;
208 goto err1;
209 }
210
211 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
212 if (!hcd->regs) {
213 pr_debug("ioremap failed\n");
214 ret = -ENOMEM;
215 goto err2;
216 }
217
218 au1xxx_start_ohc();
219 ohci_hcd_init(hcd_to_ohci(hcd));
220
221 ret = usb_add_hcd(hcd, pdev->resource[1].start,
222 IRQF_DISABLED | IRQF_SHARED);
223 if (ret == 0) {
224 platform_set_drvdata(pdev, hcd);
225 return ret;
226 }
227
228 au1xxx_stop_ohc();
229 iounmap(hcd->regs);
230err2:
231 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
232err1:
233 usb_put_hcd(hcd);
311 return ret; 234 return ret;
312} 235}
313 236
@@ -315,30 +238,78 @@ static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
315{ 238{
316 struct usb_hcd *hcd = platform_get_drvdata(pdev); 239 struct usb_hcd *hcd = platform_get_drvdata(pdev);
317 240
318 usb_ohci_au1xxx_remove(hcd, pdev); 241 usb_remove_hcd(hcd);
242 au1xxx_stop_ohc();
243 iounmap(hcd->regs);
244 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
245 usb_put_hcd(hcd);
246 platform_set_drvdata(pdev, NULL);
247
319 return 0; 248 return 0;
320} 249}
321 /*TBD*/ 250
322/*static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *dev) 251#ifdef CONFIG_PM
252static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *pdev,
253 pm_message_t message)
323{ 254{
324 struct usb_hcd *hcd = platform_get_drvdata(dev); 255 struct usb_hcd *hcd = platform_get_drvdata(pdev);
256 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
257 unsigned long flags;
258 int rc;
259
260 rc = 0;
261
262 /* Root hub was already suspended. Disable irq emission and
263 * mark HW unaccessible, bail out if RH has been resumed. Use
264 * the spinlock to properly synchronize with possible pending
265 * RH suspend or resume activity.
266 *
267 * This is still racy as hcd->state is manipulated outside of
268 * any locks =P But that will be a different fix.
269 */
270 spin_lock_irqsave(&ohci->lock, flags);
271 if (hcd->state != HC_STATE_SUSPENDED) {
272 rc = -EINVAL;
273 goto bail;
274 }
275 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
276 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
325 277
326 return 0; 278 /* make sure snapshot being resumed re-enumerates everything */
279 if (message.event == PM_EVENT_PRETHAW)
280 ohci_usb_reset(ohci);
281
282 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
283
284 au1xxx_stop_ohc();
285bail:
286 spin_unlock_irqrestore(&ohci->lock, flags);
287
288 return rc;
327} 289}
328static int ohci_hcd_au1xxx_drv_resume(struct platform_device *dev) 290
291static int ohci_hcd_au1xxx_drv_resume(struct platform_device *pdev)
329{ 292{
330 struct usb_hcd *hcd = platform_get_drvdata(dev); 293 struct usb_hcd *hcd = platform_get_drvdata(pdev);
294
295 au1xxx_start_ohc();
296
297 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
298 ohci_finish_controller_resume(hcd);
331 299
332 return 0; 300 return 0;
333} 301}
334*/ 302#else
303#define ohci_hcd_au1xxx_drv_suspend NULL
304#define ohci_hcd_au1xxx_drv_resume NULL
305#endif
335 306
336static struct platform_driver ohci_hcd_au1xxx_driver = { 307static struct platform_driver ohci_hcd_au1xxx_driver = {
337 .probe = ohci_hcd_au1xxx_drv_probe, 308 .probe = ohci_hcd_au1xxx_drv_probe,
338 .remove = ohci_hcd_au1xxx_drv_remove, 309 .remove = ohci_hcd_au1xxx_drv_remove,
339 .shutdown = usb_hcd_platform_shutdown, 310 .shutdown = usb_hcd_platform_shutdown,
340 /*.suspend = ohci_hcd_au1xxx_drv_suspend, */ 311 .suspend = ohci_hcd_au1xxx_drv_suspend,
341 /*.resume = ohci_hcd_au1xxx_drv_resume, */ 312 .resume = ohci_hcd_au1xxx_drv_resume,
342 .driver = { 313 .driver = {
343 .name = "au1xxx-ohci", 314 .name = "au1xxx-ohci",
344 .owner = THIS_MODULE, 315 .owner = THIS_MODULE,
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index e06bfaebec54..7cef1d2f7ccc 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -651,7 +651,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
651 "%s\n" 651 "%s\n"
652 "%s version " DRIVER_VERSION "\n", 652 "%s version " DRIVER_VERSION "\n",
653 hcd->self.controller->bus->name, 653 hcd->self.controller->bus->name,
654 hcd->self.controller->bus_id, 654 dev_name(hcd->self.controller),
655 hcd->product_desc, 655 hcd->product_desc,
656 hcd_name); 656 hcd_name);
657 657
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index a8160d65f32b..26bc47941d01 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -974,7 +974,7 @@ MODULE_LICENSE ("GPL");
974#define PCI_DRIVER ohci_pci_driver 974#define PCI_DRIVER ohci_pci_driver
975#endif 975#endif
976 976
977#ifdef CONFIG_SA1111 977#if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
978#include "ohci-sa1111.c" 978#include "ohci-sa1111.c"
979#define SA1111_DRIVER ohci_hcd_sa1111_driver 979#define SA1111_DRIVER ohci_hcd_sa1111_driver
980#endif 980#endif
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index a19a4f80a6e1..6e5e5f81ac90 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -329,7 +329,7 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver,
329 } 329 }
330 330
331 331
332 hcd = usb_create_hcd (driver, &pdev->dev, pdev->dev.bus_id); 332 hcd = usb_create_hcd (driver, &pdev->dev, dev_name(&pdev->dev));
333 if (!hcd) { 333 if (!hcd) {
334 retval = -ENOMEM; 334 retval = -ENOMEM;
335 goto err0; 335 goto err0;
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
index 28b458f20cc3..6ad8f2fc57b9 100644
--- a/drivers/usb/host/ohci-pnx4008.c
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -109,8 +109,6 @@ static struct clk *usb_clk;
109 109
110static int isp1301_probe(struct i2c_adapter *adap); 110static int isp1301_probe(struct i2c_adapter *adap);
111static int isp1301_detach(struct i2c_client *client); 111static int isp1301_detach(struct i2c_client *client);
112static int isp1301_command(struct i2c_client *client, unsigned int cmd,
113 void *arg);
114 112
115static const unsigned short normal_i2c[] = 113static const unsigned short normal_i2c[] =
116 { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END }; 114 { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END };
@@ -123,30 +121,37 @@ static struct i2c_client_address_data addr_data = {
123}; 121};
124 122
125struct i2c_driver isp1301_driver = { 123struct i2c_driver isp1301_driver = {
126 .class = I2C_CLASS_HWMON, 124 .driver = {
125 .name = "isp1301_pnx",
126 },
127 .attach_adapter = isp1301_probe, 127 .attach_adapter = isp1301_probe,
128 .detach_client = isp1301_detach, 128 .detach_client = isp1301_detach,
129 .command = isp1301_command
130}; 129};
131 130
132static int isp1301_attach(struct i2c_adapter *adap, int addr, int kind) 131static int isp1301_attach(struct i2c_adapter *adap, int addr, int kind)
133{ 132{
134 struct i2c_client *c; 133 struct i2c_client *c;
134 int err;
135 135
136 c = kzalloc(sizeof(*c), GFP_KERNEL); 136 c = kzalloc(sizeof(*c), GFP_KERNEL);
137
138 if (!c) 137 if (!c)
139 return -ENOMEM; 138 return -ENOMEM;
140 139
141 strcpy(c->name, "isp1301"); 140 strlcpy(c->name, "isp1301_pnx", I2C_NAME_SIZE);
142 c->flags = 0; 141 c->flags = 0;
143 c->addr = addr; 142 c->addr = addr;
144 c->adapter = adap; 143 c->adapter = adap;
145 c->driver = &isp1301_driver; 144 c->driver = &isp1301_driver;
146 145
146 err = i2c_attach_client(c);
147 if (err) {
148 kfree(c);
149 return err;
150 }
151
147 isp1301_i2c_client = c; 152 isp1301_i2c_client = c;
148 153
149 return i2c_attach_client(c); 154 return 0;
150} 155}
151 156
152static int isp1301_probe(struct i2c_adapter *adap) 157static int isp1301_probe(struct i2c_adapter *adap)
@@ -161,13 +166,6 @@ static int isp1301_detach(struct i2c_client *client)
161 return 0; 166 return 0;
162} 167}
163 168
164/* No commands defined */
165static int isp1301_command(struct i2c_client *client, unsigned int cmd,
166 void *arg)
167{
168 return 0;
169}
170
171static void i2c_write(u8 buf, u8 subaddr) 169static void i2c_write(u8 buf, u8 subaddr)
172{ 170{
173 char tmpbuf[2]; 171 char tmpbuf[2];
@@ -389,7 +387,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
389 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) != 387 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) !=
390 USB_CLOCK_MASK) ; 388 USB_CLOCK_MASK) ;
391 389
392 hcd = usb_create_hcd (driver, &pdev->dev, pdev->dev.bus_id); 390 hcd = usb_create_hcd (driver, &pdev->dev, dev_name(&pdev->dev));
393 if (!hcd) { 391 if (!hcd) {
394 err("Failed to allocate HC buffer"); 392 err("Failed to allocate HC buffer");
395 ret = -ENOMEM; 393 ret = -ENOMEM;
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index a67252791223..91e6e101a4cc 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -14,8 +14,8 @@
14 */ 14 */
15 15
16#include <linux/signal.h> 16#include <linux/signal.h>
17#include <linux/of_platform.h>
17 18
18#include <asm/of_platform.h>
19#include <asm/prom.h> 19#include <asm/prom.h>
20 20
21 21
diff --git a/drivers/usb/host/ohci-ps3.c b/drivers/usb/host/ohci-ps3.c
index c1935ae537f8..55c95647f008 100644
--- a/drivers/usb/host/ohci-ps3.c
+++ b/drivers/usb/host/ohci-ps3.c
@@ -129,7 +129,7 @@ static int ps3_ohci_probe(struct ps3_system_bus_device *dev)
129 129
130 dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */ 130 dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */
131 131
132 hcd = usb_create_hcd(&ps3_ohci_hc_driver, &dev->core, dev->core.bus_id); 132 hcd = usb_create_hcd(&ps3_ohci_hc_driver, &dev->core, dev_name(&dev->core));
133 133
134 if (!hcd) { 134 if (!hcd) {
135 dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__, 135 dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index 9b547407c934..6a9b4c557953 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -159,9 +159,6 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
159{ 159{
160 int branch; 160 int branch;
161 161
162 if (ohci_to_hcd(ohci)->state == HC_STATE_QUIESCING)
163 return -EAGAIN;
164
165 ed->state = ED_OPER; 162 ed->state = ED_OPER;
166 ed->ed_prev = NULL; 163 ed->ed_prev = NULL;
167 ed->ed_next = NULL; 164 ed->ed_next = NULL;
diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c
index e610698c6b60..21b164e4abeb 100644
--- a/drivers/usb/host/ohci-sm501.c
+++ b/drivers/usb/host/ohci-sm501.c
@@ -143,7 +143,7 @@ static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev)
143 goto err2; 143 goto err2;
144 } 144 }
145 145
146 hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id); 146 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
147 if (!hcd) { 147 if (!hcd) {
148 retval = -ENOMEM; 148 retval = -ENOMEM;
149 goto err2; 149 goto err2;
diff --git a/drivers/usb/host/ohci-ssb.c b/drivers/usb/host/ohci-ssb.c
index 7275186db315..3660c83d80af 100644
--- a/drivers/usb/host/ohci-ssb.c
+++ b/drivers/usb/host/ohci-ssb.c
@@ -113,7 +113,7 @@ static int ssb_ohci_attach(struct ssb_device *dev)
113 ssb_device_enable(dev, flags); 113 ssb_device_enable(dev, flags);
114 114
115 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev, 115 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
116 dev->dev->bus_id); 116 dev_name(dev->dev));
117 if (!hcd) 117 if (!hcd)
118 goto err_dev_disable; 118 goto err_dev_disable;
119 ohcidev = hcd_to_ssb_ohci(hcd); 119 ohcidev = hcd_to_ssb_ohci(hcd);
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 16667342b3c3..d5f02dddb120 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -312,9 +312,9 @@ static void put_child_connect_map(struct r8a66597 *r8a66597, int address)
312static void set_pipe_reg_addr(struct r8a66597_pipe *pipe, u8 dma_ch) 312static void set_pipe_reg_addr(struct r8a66597_pipe *pipe, u8 dma_ch)
313{ 313{
314 u16 pipenum = pipe->info.pipenum; 314 u16 pipenum = pipe->info.pipenum;
315 unsigned long fifoaddr[] = {D0FIFO, D1FIFO, CFIFO}; 315 const unsigned long fifoaddr[] = {D0FIFO, D1FIFO, CFIFO};
316 unsigned long fifosel[] = {D0FIFOSEL, D1FIFOSEL, CFIFOSEL}; 316 const unsigned long fifosel[] = {D0FIFOSEL, D1FIFOSEL, CFIFOSEL};
317 unsigned long fifoctr[] = {D0FIFOCTR, D1FIFOCTR, CFIFOCTR}; 317 const unsigned long fifoctr[] = {D0FIFOCTR, D1FIFOCTR, CFIFOCTR};
318 318
319 if (dma_ch > R8A66597_PIPE_NO_DMA) /* dma fifo not use? */ 319 if (dma_ch > R8A66597_PIPE_NO_DMA) /* dma fifo not use? */
320 dma_ch = R8A66597_PIPE_NO_DMA; 320 dma_ch = R8A66597_PIPE_NO_DMA;
@@ -863,6 +863,32 @@ static void disable_r8a66597_pipe_all(struct r8a66597 *r8a66597,
863 dev->dma_map = 0; 863 dev->dma_map = 0;
864} 864}
865 865
866static u16 get_interval(struct urb *urb, __u8 interval)
867{
868 u16 time = 1;
869 int i;
870
871 if (urb->dev->speed == USB_SPEED_HIGH) {
872 if (interval > IITV)
873 time = IITV;
874 else
875 time = interval ? interval - 1 : 0;
876 } else {
877 if (interval > 128) {
878 time = IITV;
879 } else {
880 /* calculate the nearest value for PIPEPERI */
881 for (i = 0; i < 7; i++) {
882 if ((1 << i) < interval &&
883 (1 << (i + 1) > interval))
884 time = 1 << i;
885 }
886 }
887 }
888
889 return time;
890}
891
866static unsigned long get_timer_interval(struct urb *urb, __u8 interval) 892static unsigned long get_timer_interval(struct urb *urb, __u8 interval)
867{ 893{
868 __u8 i; 894 __u8 i;
@@ -901,10 +927,7 @@ static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb,
901 info.interval = 0; 927 info.interval = 0;
902 info.timer_interval = 0; 928 info.timer_interval = 0;
903 } else { 929 } else {
904 if (ep->bInterval > IITV) 930 info.interval = get_interval(urb, ep->bInterval);
905 info.interval = IITV;
906 else
907 info.interval = ep->bInterval ? ep->bInterval - 1 : 0;
908 info.timer_interval = get_timer_interval(urb, ep->bInterval); 931 info.timer_interval = get_timer_interval(urb, ep->bInterval);
909 } 932 }
910 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 933 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
@@ -2244,6 +2267,7 @@ static int __init r8a66597_probe(struct platform_device *pdev)
2244 struct r8a66597 *r8a66597; 2267 struct r8a66597 *r8a66597;
2245 int ret = 0; 2268 int ret = 0;
2246 int i; 2269 int i;
2270 unsigned long irq_trigger;
2247 2271
2248 if (pdev->dev.dma_mask) { 2272 if (pdev->dev.dma_mask) {
2249 ret = -EINVAL; 2273 ret = -EINVAL;
@@ -2302,7 +2326,11 @@ static int __init r8a66597_probe(struct platform_device *pdev)
2302 INIT_LIST_HEAD(&r8a66597->child_device); 2326 INIT_LIST_HEAD(&r8a66597->child_device);
2303 2327
2304 hcd->rsrc_start = res->start; 2328 hcd->rsrc_start = res->start;
2305 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); 2329 if (irq_sense == INTL)
2330 irq_trigger = IRQF_TRIGGER_LOW;
2331 else
2332 irq_trigger = IRQF_TRIGGER_FALLING;
2333 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | irq_trigger);
2306 if (ret != 0) { 2334 if (ret != 0) {
2307 err("Failed to add hcd"); 2335 err("Failed to add hcd");
2308 goto clean_up; 2336 goto clean_up;
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 426575247b23..340d72da554a 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1674,7 +1674,7 @@ sl811h_probe(struct platform_device *dev)
1674 } 1674 }
1675 1675
1676 /* allocate and initialize hcd */ 1676 /* allocate and initialize hcd */
1677 hcd = usb_create_hcd(&sl811h_hc_driver, &dev->dev, dev->dev.bus_id); 1677 hcd = usb_create_hcd(&sl811h_hc_driver, &dev->dev, dev_name(&dev->dev));
1678 if (!hcd) { 1678 if (!hcd) {
1679 retval = -ENOMEM; 1679 retval = -ENOMEM;
1680 goto err5; 1680 goto err5;
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 9b6323f768b2..20ad3c48fcb2 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -3124,7 +3124,7 @@ static int __devinit u132_probe(struct platform_device *pdev)
3124 if (pdev->dev.dma_mask) 3124 if (pdev->dev.dma_mask)
3125 return -EINVAL; 3125 return -EINVAL;
3126 3126
3127 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id); 3127 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, dev_name(&pdev->dev));
3128 if (!hcd) { 3128 if (!hcd) {
3129 printk(KERN_ERR "failed to create the usb hcd struct for U132\n" 3129 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3130 ); 3130 );
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 8e4427aebb14..885b585360b9 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -12,7 +12,7 @@
12 * (C) Copyright 2004 Alan Stern, stern@rowland.harvard.edu 12 * (C) Copyright 2004 Alan Stern, stern@rowland.harvard.edu
13 */ 13 */
14 14
15static __u8 root_hub_hub_des[] = 15static const __u8 root_hub_hub_des[] =
16{ 16{
17 0x09, /* __u8 bLength; */ 17 0x09, /* __u8 bLength; */
18 0x29, /* __u8 bDescriptorType; Hub-descriptor */ 18 0x29, /* __u8 bDescriptorType; Hub-descriptor */
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
index 093938697426..d2f61d5510e7 100644
--- a/drivers/usb/misc/auerswald.c
+++ b/drivers/usb/misc/auerswald.c
@@ -1421,7 +1421,8 @@ ofail: mutex_unlock(&cp->mutex);
1421 1421
1422 1422
1423/* IOCTL functions */ 1423/* IOCTL functions */
1424static int auerchar_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 1424static long auerchar_ioctl(struct file *file, unsigned int cmd,
1425 unsigned long arg)
1425{ 1426{
1426 pauerchar_t ccp = (pauerchar_t) file->private_data; 1427 pauerchar_t ccp = (pauerchar_t) file->private_data;
1427 int ret = 0; 1428 int ret = 0;
@@ -1452,7 +1453,7 @@ static int auerchar_ioctl (struct inode *inode, struct file *file, unsigned int
1452 mutex_unlock(&ccp->mutex); 1453 mutex_unlock(&ccp->mutex);
1453 return -ENODEV; 1454 return -ENODEV;
1454 } 1455 }
1455 1456 lock_kernel();
1456 switch (cmd) { 1457 switch (cmd) {
1457 1458
1458 /* return != 0 if Transmitt channel ready to send */ 1459 /* return != 0 if Transmitt channel ready to send */
@@ -1547,9 +1548,10 @@ static int auerchar_ioctl (struct inode *inode, struct file *file, unsigned int
1547 1548
1548 default: 1549 default:
1549 dbg ("IOCTL_AU_UNKNOWN"); 1550 dbg ("IOCTL_AU_UNKNOWN");
1550 ret = -ENOIOCTLCMD; 1551 ret = -ENOTTY;
1551 break; 1552 break;
1552 } 1553 }
1554 unlock_kernel();
1553 /* release the mutexes */ 1555 /* release the mutexes */
1554 mutex_unlock(&cp->mutex); 1556 mutex_unlock(&cp->mutex);
1555 mutex_unlock(&ccp->mutex); 1557 mutex_unlock(&ccp->mutex);
@@ -1860,7 +1862,7 @@ static const struct file_operations auerswald_fops =
1860 .llseek = no_llseek, 1862 .llseek = no_llseek,
1861 .read = auerchar_read, 1863 .read = auerchar_read,
1862 .write = auerchar_write, 1864 .write = auerchar_write,
1863 .ioctl = auerchar_ioctl, 1865 .unlocked_ioctl = auerchar_ioctl,
1864 .open = auerchar_open, 1866 .open = auerchar_open,
1865 .release = auerchar_release, 1867 .release = auerchar_release,
1866}; 1868};
diff --git a/drivers/usb/misc/emi62.c b/drivers/usb/misc/emi62.c
index 20886c21e739..5d859ded5bbf 100644
--- a/drivers/usb/misc/emi62.c
+++ b/drivers/usb/misc/emi62.c
@@ -6,8 +6,6 @@
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, as published by 7 * it under the terms of the GNU General Public License, as published by
8 * the Free Software Foundation, version 2. 8 * the Free Software Foundation, version 2.
9 *
10 * $Id: emi62.c,v 1.15 2002/04/23 06:13:59 tapio Exp $
11 */ 9 */
12#include <linux/kernel.h> 10#include <linux/kernel.h>
13#include <linux/errno.h> 11#include <linux/errno.h>
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index ec88b3bfee46..97c280971532 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -656,29 +656,6 @@ static int ftdi_elan_release(struct inode *inode, struct file *file)
656} 656}
657 657
658 658
659#define FTDI_ELAN_IOC_MAGIC 0xA1
660#define FTDI_ELAN_IOCDEBUG _IOC(_IOC_WRITE, FTDI_ELAN_IOC_MAGIC, 1, 132)
661static int ftdi_elan_ioctl(struct inode *inode, struct file *file,
662 unsigned int cmd, unsigned long arg)
663{
664 switch (cmd) {
665 case FTDI_ELAN_IOCDEBUG:{
666 char line[132];
667 int size = strncpy_from_user(line,
668 (const char __user *)arg, sizeof(line));
669 if (size < 0) {
670 return -EINVAL;
671 } else {
672 printk(KERN_ERR "TODO: ioctl %s\n", line);
673 return 0;
674 }
675 }
676 default:
677 return -EFAULT;
678 }
679}
680
681
682/* 659/*
683* 660*
684* blocking bulk reads are used to get data from the device 661* blocking bulk reads are used to get data from the device
@@ -1222,7 +1199,6 @@ error_1:
1222static const struct file_operations ftdi_elan_fops = { 1199static const struct file_operations ftdi_elan_fops = {
1223 .owner = THIS_MODULE, 1200 .owner = THIS_MODULE,
1224 .llseek = no_llseek, 1201 .llseek = no_llseek,
1225 .ioctl = ftdi_elan_ioctl,
1226 .read = ftdi_elan_read, 1202 .read = ftdi_elan_read,
1227 .write = ftdi_elan_write, 1203 .write = ftdi_elan_write,
1228 .open = ftdi_elan_open, 1204 .open = ftdi_elan_open,
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 1cb54a28347f..e6ca9979e3ae 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -474,8 +474,8 @@ exit:
474/** 474/**
475 * iowarrior_ioctl 475 * iowarrior_ioctl
476 */ 476 */
477static int iowarrior_ioctl(struct inode *inode, struct file *file, 477static long iowarrior_ioctl(struct file *file, unsigned int cmd,
478 unsigned int cmd, unsigned long arg) 478 unsigned long arg)
479{ 479{
480 struct iowarrior *dev = NULL; 480 struct iowarrior *dev = NULL;
481 __u8 *buffer; 481 __u8 *buffer;
@@ -493,6 +493,7 @@ static int iowarrior_ioctl(struct inode *inode, struct file *file,
493 return -ENOMEM; 493 return -ENOMEM;
494 494
495 /* lock this object */ 495 /* lock this object */
496 lock_kernel();
496 mutex_lock(&dev->mutex); 497 mutex_lock(&dev->mutex);
497 498
498 /* verify that the device wasn't unplugged */ 499 /* verify that the device wasn't unplugged */
@@ -584,6 +585,7 @@ static int iowarrior_ioctl(struct inode *inode, struct file *file,
584error_out: 585error_out:
585 /* unlock the device */ 586 /* unlock the device */
586 mutex_unlock(&dev->mutex); 587 mutex_unlock(&dev->mutex);
588 unlock_kernel();
587 kfree(buffer); 589 kfree(buffer);
588 return retval; 590 return retval;
589} 591}
@@ -719,7 +721,7 @@ static const struct file_operations iowarrior_fops = {
719 .owner = THIS_MODULE, 721 .owner = THIS_MODULE,
720 .write = iowarrior_write, 722 .write = iowarrior_write,
721 .read = iowarrior_read, 723 .read = iowarrior_read,
722 .ioctl = iowarrior_ioctl, 724 .unlocked_ioctl = iowarrior_ioctl,
723 .open = iowarrior_open, 725 .open = iowarrior_open,
724 .release = iowarrior_release, 726 .release = iowarrior_release,
725 .poll = iowarrior_poll, 727 .poll = iowarrior_poll,
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
index 330c18e390b8..248a12aacef6 100644
--- a/drivers/usb/misc/rio500.c
+++ b/drivers/usb/misc/rio500.c
@@ -104,9 +104,7 @@ static int close_rio(struct inode *inode, struct file *file)
104 return 0; 104 return 0;
105} 105}
106 106
107static int 107static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
108ioctl_rio(struct inode *inode, struct file *file, unsigned int cmd,
109 unsigned long arg)
110{ 108{
111 struct RioCommand rio_cmd; 109 struct RioCommand rio_cmd;
112 struct rio_usb_data *rio = &rio_instance; 110 struct rio_usb_data *rio = &rio_instance;
@@ -116,6 +114,7 @@ ioctl_rio(struct inode *inode, struct file *file, unsigned int cmd,
116 int retries; 114 int retries;
117 int retval=0; 115 int retval=0;
118 116
117 lock_kernel();
119 mutex_lock(&(rio->lock)); 118 mutex_lock(&(rio->lock));
120 /* Sanity check to make sure rio is connected, powered, etc */ 119 /* Sanity check to make sure rio is connected, powered, etc */
121 if (rio->present == 0 || rio->rio_dev == NULL) { 120 if (rio->present == 0 || rio->rio_dev == NULL) {
@@ -254,6 +253,7 @@ ioctl_rio(struct inode *inode, struct file *file, unsigned int cmd,
254 253
255err_out: 254err_out:
256 mutex_unlock(&(rio->lock)); 255 mutex_unlock(&(rio->lock));
256 unlock_kernel();
257 return retval; 257 return retval;
258} 258}
259 259
@@ -433,7 +433,7 @@ file_operations usb_rio_fops = {
433 .owner = THIS_MODULE, 433 .owner = THIS_MODULE,
434 .read = read_rio, 434 .read = read_rio,
435 .write = write_rio, 435 .write = write_rio,
436 .ioctl = ioctl_rio, 436 .unlocked_ioctl = ioctl_rio,
437 .open = open_rio, 437 .open = open_rio,
438 .release = close_rio, 438 .release = close_rio,
439}; 439};
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 33182f4c2267..fbace41a7cba 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -2982,9 +2982,8 @@ sisusb_handle_command(struct sisusb_usb_data *sisusb, struct sisusb_command *y,
2982 return retval; 2982 return retval;
2983} 2983}
2984 2984
2985static int 2985static long
2986sisusb_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 2986sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2987 unsigned long arg)
2988{ 2987{
2989 struct sisusb_usb_data *sisusb; 2988 struct sisusb_usb_data *sisusb;
2990 struct sisusb_info x; 2989 struct sisusb_info x;
@@ -2995,6 +2994,7 @@ sisusb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
2995 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2994 if (!(sisusb = (struct sisusb_usb_data *)file->private_data))
2996 return -ENODEV; 2995 return -ENODEV;
2997 2996
2997 lock_kernel();
2998 mutex_lock(&sisusb->lock); 2998 mutex_lock(&sisusb->lock);
2999 2999
3000 /* Sanity check */ 3000 /* Sanity check */
@@ -3053,6 +3053,7 @@ sisusb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
3053 3053
3054err_out: 3054err_out:
3055 mutex_unlock(&sisusb->lock); 3055 mutex_unlock(&sisusb->lock);
3056 unlock_kernel();
3056 return retval; 3057 return retval;
3057} 3058}
3058 3059
@@ -3066,9 +3067,7 @@ sisusb_compat_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
3066 case SISUSB_GET_CONFIG_SIZE: 3067 case SISUSB_GET_CONFIG_SIZE:
3067 case SISUSB_GET_CONFIG: 3068 case SISUSB_GET_CONFIG:
3068 case SISUSB_COMMAND: 3069 case SISUSB_COMMAND:
3069 lock_kernel(); 3070 retval = sisusb_ioctl(f, cmd, arg);
3070 retval = sisusb_ioctl(f->f_path.dentry->d_inode, f, cmd, arg);
3071 unlock_kernel();
3072 return retval; 3071 return retval;
3073 3072
3074 default: 3073 default:
@@ -3087,7 +3086,7 @@ static const struct file_operations usb_sisusb_fops = {
3087#ifdef SISUSB_NEW_CONFIG_COMPAT 3086#ifdef SISUSB_NEW_CONFIG_COMPAT
3088 .compat_ioctl = sisusb_compat_ioctl, 3087 .compat_ioctl = sisusb_compat_ioctl,
3089#endif 3088#endif
3090 .ioctl = sisusb_ioctl 3089 .unlocked_ioctl = sisusb_ioctl
3091}; 3090};
3092 3091
3093static struct usb_class_driver usb_sisusb_class = { 3092static struct usb_class_driver usb_sisusb_class = {
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index 7f7021ee4189..2db4228fbb01 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -146,7 +146,7 @@ static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, l
146 return retval; 146 return retval;
147} 147}
148 148
149static int lcd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 149static long lcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
150{ 150{
151 struct usb_lcd *dev; 151 struct usb_lcd *dev;
152 u16 bcdDevice; 152 u16 bcdDevice;
@@ -158,12 +158,14 @@ static int lcd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
158 158
159 switch (cmd) { 159 switch (cmd) {
160 case IOCTL_GET_HARD_VERSION: 160 case IOCTL_GET_HARD_VERSION:
161 lock_kernel();
161 bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice); 162 bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice);
162 sprintf(buf,"%1d%1d.%1d%1d", 163 sprintf(buf,"%1d%1d.%1d%1d",
163 (bcdDevice & 0xF000)>>12, 164 (bcdDevice & 0xF000)>>12,
164 (bcdDevice & 0xF00)>>8, 165 (bcdDevice & 0xF00)>>8,
165 (bcdDevice & 0xF0)>>4, 166 (bcdDevice & 0xF0)>>4,
166 (bcdDevice & 0xF)); 167 (bcdDevice & 0xF));
168 unlock_kernel();
167 if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0) 169 if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0)
168 return -EFAULT; 170 return -EFAULT;
169 break; 171 break;
@@ -272,7 +274,7 @@ static const struct file_operations lcd_fops = {
272 .read = lcd_read, 274 .read = lcd_read,
273 .write = lcd_write, 275 .write = lcd_write,
274 .open = lcd_open, 276 .open = lcd_open,
275 .ioctl = lcd_ioctl, 277 .unlocked_ioctl = lcd_ioctl,
276 .release = lcd_release, 278 .release = lcd_release,
277}; 279};
278 280
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 293a46247c3b..6566fc0a3228 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -1162,8 +1162,9 @@ int mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus)
1162 if (minor >= MON_BIN_MAX_MINOR) 1162 if (minor >= MON_BIN_MAX_MINOR)
1163 return 0; 1163 return 0;
1164 1164
1165 dev = device_create(mon_bin_class, ubus? ubus->controller: NULL, 1165 dev = device_create_drvdata(mon_bin_class, ubus? ubus->controller: NULL,
1166 MKDEV(MAJOR(mon_bin_dev0), minor), "usbmon%d", minor); 1166 MKDEV(MAJOR(mon_bin_dev0), minor), NULL,
1167 "usbmon%d", minor);
1167 if (IS_ERR(dev)) 1168 if (IS_ERR(dev))
1168 return 0; 1169 return 0;
1169 1170
diff --git a/drivers/usb/mon/mon_stat.c b/drivers/usb/mon/mon_stat.c
index c7a595cd648a..ac8b0d5ce7f8 100644
--- a/drivers/usb/mon/mon_stat.c
+++ b/drivers/usb/mon/mon_stat.c
@@ -9,6 +9,7 @@
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/usb.h> 11#include <linux/usb.h>
12#include <linux/fs.h>
12#include <asm/uaccess.h> 13#include <asm/uaccess.h>
13 14
14#include "usb_mon.h" 15#include "usb_mon.h"
@@ -42,19 +43,8 @@ static ssize_t mon_stat_read(struct file *file, char __user *buf,
42 size_t nbytes, loff_t *ppos) 43 size_t nbytes, loff_t *ppos)
43{ 44{
44 struct snap *sp = file->private_data; 45 struct snap *sp = file->private_data;
45 loff_t pos = *ppos;
46 int cnt;
47 46
48 if (pos < 0 || pos >= sp->slen) 47 return simple_read_from_buffer(buf, nbytes, ppos, sp->str, sp->slen);
49 return 0;
50 if (nbytes == 0)
51 return 0;
52 if ((cnt = sp->slen - pos) > nbytes)
53 cnt = nbytes;
54 if (copy_to_user(buf, sp->str + pos, cnt))
55 return -EFAULT;
56 *ppos = pos + cnt;
57 return cnt;
58} 48}
59 49
60static int mon_stat_release(struct inode *inode, struct file *file) 50static int mon_stat_release(struct inode *inode, struct file *file)
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 9a7681b55266..8878c1767fc8 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -64,14 +64,6 @@ config USB_SERIAL_AIRCABLE
64 To compile this driver as a module, choose M here: the module 64 To compile this driver as a module, choose M here: the module
65 will be called aircable. 65 will be called aircable.
66 66
67config USB_SERIAL_AIRPRIME
68 tristate "USB AirPrime CDMA Wireless Driver"
69 help
70 Say Y here if you want to use a AirPrime CDMA Wireless PC card.
71
72 To compile this driver as a module, choose M here: the
73 module will be called airprime.
74
75config USB_SERIAL_ARK3116 67config USB_SERIAL_ARK3116
76 tristate "USB ARK Micro 3116 USB Serial Driver" 68 tristate "USB ARK Micro 3116 USB Serial Driver"
77 help 69 help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 17a762ab6769..6047f818adfe 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -12,7 +12,6 @@ usbserial-obj-$(CONFIG_USB_EZUSB) += ezusb.o
12usbserial-objs := usb-serial.o generic.o bus.o $(usbserial-obj-y) 12usbserial-objs := usb-serial.o generic.o bus.o $(usbserial-obj-y)
13 13
14obj-$(CONFIG_USB_SERIAL_AIRCABLE) += aircable.o 14obj-$(CONFIG_USB_SERIAL_AIRCABLE) += aircable.o
15obj-$(CONFIG_USB_SERIAL_AIRPRIME) += airprime.o
16obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o 15obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o
17obj-$(CONFIG_USB_SERIAL_BELKIN) += belkin_sa.o 16obj-$(CONFIG_USB_SERIAL_BELKIN) += belkin_sa.o
18obj-$(CONFIG_USB_SERIAL_CH341) += ch341.o 17obj-$(CONFIG_USB_SERIAL_CH341) += ch341.o
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index db6f97a93c02..79ea98c66fa8 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -272,7 +272,7 @@ static void aircable_read(struct work_struct *work)
272 * 64 bytes, to ensure I do not get throttled. 272 * 64 bytes, to ensure I do not get throttled.
273 * Ask USB mailing list for better aproach. 273 * Ask USB mailing list for better aproach.
274 */ 274 */
275 tty = port->tty; 275 tty = port->port.tty;
276 276
277 if (!tty) { 277 if (!tty) {
278 schedule_work(&priv->rx_work); 278 schedule_work(&priv->rx_work);
@@ -378,13 +378,14 @@ static void aircable_shutdown(struct usb_serial *serial)
378 } 378 }
379} 379}
380 380
381static int aircable_write_room(struct usb_serial_port *port) 381static int aircable_write_room(struct tty_struct *tty)
382{ 382{
383 struct usb_serial_port *port = tty->driver_data;
383 struct aircable_private *priv = usb_get_serial_port_data(port); 384 struct aircable_private *priv = usb_get_serial_port_data(port);
384 return serial_buf_data_avail(priv->tx_buf); 385 return serial_buf_data_avail(priv->tx_buf);
385} 386}
386 387
387static int aircable_write(struct usb_serial_port *port, 388static int aircable_write(struct tty_struct *tty, struct usb_serial_port *port,
388 const unsigned char *source, int count) 389 const unsigned char *source, int count)
389{ 390{
390 struct aircable_private *priv = usb_get_serial_port_data(port); 391 struct aircable_private *priv = usb_get_serial_port_data(port);
@@ -466,7 +467,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
466 467
467 if (status) { 468 if (status) {
468 dbg("%s - urb status = %d", __func__, status); 469 dbg("%s - urb status = %d", __func__, status);
469 if (!port->open_count) { 470 if (!port->port.count) {
470 dbg("%s - port is closed, exiting.", __func__); 471 dbg("%s - port is closed, exiting.", __func__);
471 return; 472 return;
472 } 473 }
@@ -494,7 +495,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
494 usb_serial_debug_data(debug, &port->dev, __func__, 495 usb_serial_debug_data(debug, &port->dev, __func__,
495 urb->actual_length, urb->transfer_buffer); 496 urb->actual_length, urb->transfer_buffer);
496 497
497 tty = port->tty; 498 tty = port->port.tty;
498 if (tty && urb->actual_length) { 499 if (tty && urb->actual_length) {
499 if (urb->actual_length <= 2) { 500 if (urb->actual_length <= 2) {
500 /* This is an incomplete package */ 501 /* This is an incomplete package */
@@ -528,7 +529,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
528 } 529 }
529 530
530 /* Schedule the next read _if_ we are still open */ 531 /* Schedule the next read _if_ we are still open */
531 if (port->open_count) { 532 if (port->port.count) {
532 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 533 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
533 usb_rcvbulkpipe(port->serial->dev, 534 usb_rcvbulkpipe(port->serial->dev,
534 port->bulk_in_endpointAddress), 535 port->bulk_in_endpointAddress),
@@ -547,8 +548,9 @@ static void aircable_read_bulk_callback(struct urb *urb)
547} 548}
548 549
549/* Based on ftdi_sio.c throttle */ 550/* Based on ftdi_sio.c throttle */
550static void aircable_throttle(struct usb_serial_port *port) 551static void aircable_throttle(struct tty_struct *tty)
551{ 552{
553 struct usb_serial_port *port = tty->driver_data;
552 struct aircable_private *priv = usb_get_serial_port_data(port); 554 struct aircable_private *priv = usb_get_serial_port_data(port);
553 unsigned long flags; 555 unsigned long flags;
554 556
@@ -560,8 +562,9 @@ static void aircable_throttle(struct usb_serial_port *port)
560} 562}
561 563
562/* Based on ftdi_sio.c unthrottle */ 564/* Based on ftdi_sio.c unthrottle */
563static void aircable_unthrottle(struct usb_serial_port *port) 565static void aircable_unthrottle(struct tty_struct *tty)
564{ 566{
567 struct usb_serial_port *port = tty->driver_data;
565 struct aircable_private *priv = usb_get_serial_port_data(port); 568 struct aircable_private *priv = usb_get_serial_port_data(port);
566 int actually_throttled; 569 int actually_throttled;
567 unsigned long flags; 570 unsigned long flags;
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 0798c14ce787..b3f1d1e82468 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -60,7 +60,7 @@ static int airprime_send_setup(struct usb_serial_port *port)
60 60
61 priv = usb_get_serial_port_data(port); 61 priv = usb_get_serial_port_data(port);
62 62
63 if (port->tty) { 63 if (port->port.tty) {
64 int val = 0; 64 int val = 0;
65 if (priv->dtr_state) 65 if (priv->dtr_state)
66 val |= 0x01; 66 val |= 0x01;
@@ -94,7 +94,7 @@ static void airprime_read_bulk_callback(struct urb *urb)
94 usb_serial_debug_data(debug, &port->dev, __func__, 94 usb_serial_debug_data(debug, &port->dev, __func__,
95 urb->actual_length, data); 95 urb->actual_length, data);
96 96
97 tty = port->tty; 97 tty = port->port.tty;
98 if (tty && urb->actual_length) { 98 if (tty && urb->actual_length) {
99 tty_insert_flip_string(tty, data, urb->actual_length); 99 tty_insert_flip_string(tty, data, urb->actual_length);
100 tty_flip_buffer_push(tty); 100 tty_flip_buffer_push(tty);
@@ -130,7 +130,8 @@ static void airprime_write_bulk_callback(struct urb *urb)
130 usb_serial_port_softint(port); 130 usb_serial_port_softint(port);
131} 131}
132 132
133static int airprime_open(struct usb_serial_port *port, struct file *filp) 133static int airprime_open(struct tty_struct *tty, struct usb_serial_port *port,
134 struct file *filp)
134{ 135{
135 struct airprime_private *priv = usb_get_serial_port_data(port); 136 struct airprime_private *priv = usb_get_serial_port_data(port);
136 struct usb_serial *serial = port->serial; 137 struct usb_serial *serial = port->serial;
@@ -211,7 +212,8 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
211 return result; 212 return result;
212} 213}
213 214
214static void airprime_close(struct usb_serial_port *port, struct file *filp) 215static void airprime_close(struct tty_struct *tty,
216 struct usb_serial_port *port, struct file *filp)
215{ 217{
216 struct airprime_private *priv = usb_get_serial_port_data(port); 218 struct airprime_private *priv = usb_get_serial_port_data(port);
217 int i; 219 int i;
@@ -237,7 +239,7 @@ static void airprime_close(struct usb_serial_port *port, struct file *filp)
237 usb_set_serial_port_data(port, NULL); 239 usb_set_serial_port_data(port, NULL);
238} 240}
239 241
240static int airprime_write(struct usb_serial_port *port, 242static int airprime_write(struct tty_struct *tty, struct usb_serial_port *port,
241 const unsigned char *buf, int count) 243 const unsigned char *buf, int count)
242{ 244{
243 struct airprime_private *priv = usb_get_serial_port_data(port); 245 struct airprime_private *priv = usb_get_serial_port_data(port);
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 77895c8f8f31..aec61880f36c 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -158,12 +158,13 @@ cleanup:
158 return -ENOMEM; 158 return -ENOMEM;
159} 159}
160 160
161static void ark3116_set_termios(struct usb_serial_port *port, 161static void ark3116_set_termios(struct tty_struct *tty,
162 struct usb_serial_port *port,
162 struct ktermios *old_termios) 163 struct ktermios *old_termios)
163{ 164{
164 struct usb_serial *serial = port->serial; 165 struct usb_serial *serial = port->serial;
165 struct ark3116_private *priv = usb_get_serial_port_data(port); 166 struct ark3116_private *priv = usb_get_serial_port_data(port);
166 struct ktermios *termios = port->tty->termios; 167 struct ktermios *termios = tty->termios;
167 unsigned int cflag = termios->c_cflag; 168 unsigned int cflag = termios->c_cflag;
168 unsigned long flags; 169 unsigned long flags;
169 int baud; 170 int baud;
@@ -177,8 +178,8 @@ static void ark3116_set_termios(struct usb_serial_port *port,
177 178
178 spin_lock_irqsave(&priv->lock, flags); 179 spin_lock_irqsave(&priv->lock, flags);
179 if (!priv->termios_initialized) { 180 if (!priv->termios_initialized) {
180 *(port->tty->termios) = tty_std_termios; 181 *termios = tty_std_termios;
181 port->tty->termios->c_cflag = B9600 | CS8 182 termios->c_cflag = B9600 | CS8
182 | CREAD | HUPCL | CLOCAL; 183 | CREAD | HUPCL | CLOCAL;
183 termios->c_ispeed = 9600; 184 termios->c_ispeed = 9600;
184 termios->c_ospeed = 9600; 185 termios->c_ospeed = 9600;
@@ -192,7 +193,7 @@ static void ark3116_set_termios(struct usb_serial_port *port,
192 buf = kmalloc(1, GFP_KERNEL); 193 buf = kmalloc(1, GFP_KERNEL);
193 if (!buf) { 194 if (!buf) {
194 dbg("error kmalloc"); 195 dbg("error kmalloc");
195 *port->tty->termios = *old_termios; 196 *termios = *old_termios;
196 return; 197 return;
197 } 198 }
198 199
@@ -243,7 +244,7 @@ static void ark3116_set_termios(struct usb_serial_port *port,
243 } 244 }
244 245
245 /* set baudrate */ 246 /* set baudrate */
246 baud = tty_get_baud_rate(port->tty); 247 baud = tty_get_baud_rate(tty);
247 248
248 switch (baud) { 249 switch (baud) {
249 case 75: 250 case 75:
@@ -262,11 +263,11 @@ static void ark3116_set_termios(struct usb_serial_port *port,
262 case 230400: 263 case 230400:
263 case 460800: 264 case 460800:
264 /* Report the resulting rate back to the caller */ 265 /* Report the resulting rate back to the caller */
265 tty_encode_baud_rate(port->tty, baud, baud); 266 tty_encode_baud_rate(tty, baud, baud);
266 break; 267 break;
267 /* set 9600 as default (if given baudrate is invalid for example) */ 268 /* set 9600 as default (if given baudrate is invalid for example) */
268 default: 269 default:
269 tty_encode_baud_rate(port->tty, 9600, 9600); 270 tty_encode_baud_rate(tty, 9600, 9600);
270 case 0: 271 case 0:
271 baud = 9600; 272 baud = 9600;
272 } 273 }
@@ -317,7 +318,8 @@ static void ark3116_set_termios(struct usb_serial_port *port,
317 return; 318 return;
318} 319}
319 320
320static int ark3116_open(struct usb_serial_port *port, struct file *filp) 321static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port,
322 struct file *filp)
321{ 323{
322 struct ktermios tmp_termios; 324 struct ktermios tmp_termios;
323 struct usb_serial *serial = port->serial; 325 struct usb_serial *serial = port->serial;
@@ -332,7 +334,7 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp)
332 return -ENOMEM; 334 return -ENOMEM;
333 } 335 }
334 336
335 result = usb_serial_generic_open(port, filp); 337 result = usb_serial_generic_open(tty, port, filp);
336 if (result) 338 if (result)
337 goto err_out; 339 goto err_out;
338 340
@@ -362,8 +364,8 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp)
362 ARK3116_RCV(serial, 124, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf); 364 ARK3116_RCV(serial, 124, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf);
363 365
364 /* initialise termios */ 366 /* initialise termios */
365 if (port->tty) 367 if (tty)
366 ark3116_set_termios(port, &tmp_termios); 368 ark3116_set_termios(tty, port, &tmp_termios);
367 369
368err_out: 370err_out:
369 kfree(buf); 371 kfree(buf);
@@ -371,9 +373,10 @@ err_out:
371 return result; 373 return result;
372} 374}
373 375
374static int ark3116_ioctl(struct usb_serial_port *port, struct file *file, 376static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
375 unsigned int cmd, unsigned long arg) 377 unsigned int cmd, unsigned long arg)
376{ 378{
379 struct usb_serial_port *port = tty->driver_data;
377 struct serial_struct serstruct; 380 struct serial_struct serstruct;
378 void __user *user_arg = (void __user *)arg; 381 void __user *user_arg = (void __user *)arg;
379 382
@@ -403,8 +406,9 @@ static int ark3116_ioctl(struct usb_serial_port *port, struct file *file,
403 return -ENOIOCTLCMD; 406 return -ENOIOCTLCMD;
404} 407}
405 408
406static int ark3116_tiocmget(struct usb_serial_port *port, struct file *file) 409static int ark3116_tiocmget(struct tty_struct *tty, struct file *file)
407{ 410{
411 struct usb_serial_port *port = tty->driver_data;
408 struct usb_serial *serial = port->serial; 412 struct usb_serial *serial = port->serial;
409 char *buf; 413 char *buf;
410 char temp; 414 char temp;
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 0a322fc53d6e..2ebe06c3405a 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -7,13 +7,14 @@
7 * This program is largely derived from work by the linux-usb group 7 * This program is largely derived from work by the linux-usb group
8 * and associated source files. Please see the usb/serial files for 8 * and associated source files. Please see the usb/serial files for
9 * individual credits and copyrights. 9 * individual credits and copyrights.
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
15 * 15 *
16 * See Documentation/usb/usb-serial.txt for more information on using this driver 16 * See Documentation/usb/usb-serial.txt for more information on using this
17 * driver
17 * 18 *
18 * TODO: 19 * TODO:
19 * -- Add true modem contol line query capability. Currently we track the 20 * -- Add true modem contol line query capability. Currently we track the
@@ -28,7 +29,8 @@
28 * compressed all the differnent device entries into 1. 29 * compressed all the differnent device entries into 1.
29 * 30 *
30 * 30-May-2001 gkh 31 * 30-May-2001 gkh
31 * switched from using spinlock to a semaphore, which fixes lots of problems. 32 * switched from using spinlock to a semaphore, which fixes lots of
33 * problems.
32 * 34 *
33 * 08-Apr-2001 gb 35 * 08-Apr-2001 gb
34 * - Identify version on module load. 36 * - Identify version on module load.
@@ -41,7 +43,7 @@
41 * - Added support for the old Belkin and Peracom devices. 43 * - Added support for the old Belkin and Peracom devices.
42 * - Made the port able to be opened multiple times. 44 * - Made the port able to be opened multiple times.
43 * - Added some defaults incase the line settings are things these devices 45 * - Added some defaults incase the line settings are things these devices
44 * can't support. 46 * can't support.
45 * 47 *
46 * 18-Oct-2000 William Greathouse 48 * 18-Oct-2000 William Greathouse
47 * Released into the wild (linux-usb-devel) 49 * Released into the wild (linux-usb-devel)
@@ -72,7 +74,7 @@
72#include <linux/tty_flip.h> 74#include <linux/tty_flip.h>
73#include <linux/module.h> 75#include <linux/module.h>
74#include <linux/spinlock.h> 76#include <linux/spinlock.h>
75#include <asm/uaccess.h> 77#include <linux/uaccess.h>
76#include <linux/usb.h> 78#include <linux/usb.h>
77#include <linux/usb/serial.h> 79#include <linux/usb/serial.h>
78#include "belkin_sa.h" 80#include "belkin_sa.h"
@@ -87,16 +89,19 @@ static int debug;
87#define DRIVER_DESC "USB Belkin Serial converter driver" 89#define DRIVER_DESC "USB Belkin Serial converter driver"
88 90
89/* function prototypes for a Belkin USB Serial Adapter F5U103 */ 91/* function prototypes for a Belkin USB Serial Adapter F5U103 */
90static int belkin_sa_startup (struct usb_serial *serial); 92static int belkin_sa_startup(struct usb_serial *serial);
91static void belkin_sa_shutdown (struct usb_serial *serial); 93static void belkin_sa_shutdown(struct usb_serial *serial);
92static int belkin_sa_open (struct usb_serial_port *port, struct file *filp); 94static int belkin_sa_open(struct tty_struct *tty,
93static void belkin_sa_close (struct usb_serial_port *port, struct file *filp); 95 struct usb_serial_port *port, struct file *filp);
94static void belkin_sa_read_int_callback (struct urb *urb); 96static void belkin_sa_close(struct tty_struct *tty,
95static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios * old); 97 struct usb_serial_port *port, struct file *filp);
96static int belkin_sa_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 98static void belkin_sa_read_int_callback(struct urb *urb);
97static void belkin_sa_break_ctl (struct usb_serial_port *port, int break_state ); 99static void belkin_sa_set_termios(struct tty_struct *tty,
98static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file); 100 struct usb_serial_port *port, struct ktermios * old);
99static int belkin_sa_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); 101static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state);
102static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file);
103static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file,
104 unsigned int set, unsigned int clear);
100 105
101 106
102static struct usb_device_id id_table_combined [] = { 107static struct usb_device_id id_table_combined [] = {
@@ -106,10 +111,10 @@ static struct usb_device_id id_table_combined [] = {
106 { USB_DEVICE(GOHUBS_VID, GOHUBS_PID) }, 111 { USB_DEVICE(GOHUBS_VID, GOHUBS_PID) },
107 { USB_DEVICE(GOHUBS_VID, HANDYLINK_PID) }, 112 { USB_DEVICE(GOHUBS_VID, HANDYLINK_PID) },
108 { USB_DEVICE(BELKIN_DOCKSTATION_VID, BELKIN_DOCKSTATION_PID) }, 113 { USB_DEVICE(BELKIN_DOCKSTATION_VID, BELKIN_DOCKSTATION_PID) },
109 { } /* Terminating entry */ 114 { } /* Terminating entry */
110}; 115};
111 116
112MODULE_DEVICE_TABLE (usb, id_table_combined); 117MODULE_DEVICE_TABLE(usb, id_table_combined);
113 118
114static struct usb_driver belkin_driver = { 119static struct usb_driver belkin_driver = {
115 .name = "belkin", 120 .name = "belkin",
@@ -131,8 +136,8 @@ static struct usb_serial_driver belkin_device = {
131 .num_ports = 1, 136 .num_ports = 1,
132 .open = belkin_sa_open, 137 .open = belkin_sa_open,
133 .close = belkin_sa_close, 138 .close = belkin_sa_close,
134 .read_int_callback = belkin_sa_read_int_callback, /* How we get the status info */ 139 .read_int_callback = belkin_sa_read_int_callback,
135 .ioctl = belkin_sa_ioctl, 140 /* How we get the status info */
136 .set_termios = belkin_sa_set_termios, 141 .set_termios = belkin_sa_set_termios,
137 .break_ctl = belkin_sa_break_ctl, 142 .break_ctl = belkin_sa_break_ctl,
138 .tiocmget = belkin_sa_tiocmget, 143 .tiocmget = belkin_sa_tiocmget,
@@ -160,12 +165,12 @@ struct belkin_sa_private {
160#define WDR_TIMEOUT 5000 /* default urb timeout */ 165#define WDR_TIMEOUT 5000 /* default urb timeout */
161 166
162/* assumes that struct usb_serial *serial is available */ 167/* assumes that struct usb_serial *serial is available */
163#define BSA_USB_CMD(c,v) usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), \ 168#define BSA_USB_CMD(c, v) usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), \
164 (c), BELKIN_SA_SET_REQUEST_TYPE, \ 169 (c), BELKIN_SA_SET_REQUEST_TYPE, \
165 (v), 0, NULL, 0, WDR_TIMEOUT) 170 (v), 0, NULL, 0, WDR_TIMEOUT)
166 171
167/* do some startup allocations not currently performed by usb_serial_probe() */ 172/* do some startup allocations not currently performed by usb_serial_probe() */
168static int belkin_sa_startup (struct usb_serial *serial) 173static int belkin_sa_startup(struct usb_serial *serial)
169{ 174{
170 struct usb_device *dev = serial->dev; 175 struct usb_device *dev = serial->dev;
171 struct belkin_sa_private *priv; 176 struct belkin_sa_private *priv;
@@ -173,32 +178,35 @@ static int belkin_sa_startup (struct usb_serial *serial)
173 /* allocate the private data structure */ 178 /* allocate the private data structure */
174 priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL); 179 priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL);
175 if (!priv) 180 if (!priv)
176 return (-1); /* error */ 181 return -1; /* error */
177 /* set initial values for control structures */ 182 /* set initial values for control structures */
178 spin_lock_init(&priv->lock); 183 spin_lock_init(&priv->lock);
179 priv->control_state = 0; 184 priv->control_state = 0;
180 priv->last_lsr = 0; 185 priv->last_lsr = 0;
181 priv->last_msr = 0; 186 priv->last_msr = 0;
182 /* see comments at top of file */ 187 /* see comments at top of file */
183 priv->bad_flow_control = (le16_to_cpu(dev->descriptor.bcdDevice) <= 0x0206) ? 1 : 0; 188 priv->bad_flow_control =
184 info("bcdDevice: %04x, bfc: %d", le16_to_cpu(dev->descriptor.bcdDevice), priv->bad_flow_control); 189 (le16_to_cpu(dev->descriptor.bcdDevice) <= 0x0206) ? 1 : 0;
190 info("bcdDevice: %04x, bfc: %d",
191 le16_to_cpu(dev->descriptor.bcdDevice),
192 priv->bad_flow_control);
185 193
186 init_waitqueue_head(&serial->port[0]->write_wait); 194 init_waitqueue_head(&serial->port[0]->write_wait);
187 usb_set_serial_port_data(serial->port[0], priv); 195 usb_set_serial_port_data(serial->port[0], priv);
188 196
189 return (0); 197 return 0;
190} 198}
191 199
192 200
193static void belkin_sa_shutdown (struct usb_serial *serial) 201static void belkin_sa_shutdown(struct usb_serial *serial)
194{ 202{
195 struct belkin_sa_private *priv; 203 struct belkin_sa_private *priv;
196 int i; 204 int i;
197 205
198 dbg ("%s", __func__); 206 dbg("%s", __func__);
199 207
200 /* stop reads and writes on all ports */ 208 /* stop reads and writes on all ports */
201 for (i=0; i < serial->num_ports; ++i) { 209 for (i = 0; i < serial->num_ports; ++i) {
202 /* My special items, the standard routines free my urbs */ 210 /* My special items, the standard routines free my urbs */
203 priv = usb_get_serial_port_data(serial->port[i]); 211 priv = usb_get_serial_port_data(serial->port[i]);
204 kfree(priv); 212 kfree(priv);
@@ -206,7 +214,8 @@ static void belkin_sa_shutdown (struct usb_serial *serial)
206} 214}
207 215
208 216
209static int belkin_sa_open (struct usb_serial_port *port, struct file *filp) 217static int belkin_sa_open(struct tty_struct *tty,
218 struct usb_serial_port *port, struct file *filp)
210{ 219{
211 int retval = 0; 220 int retval = 0;
212 221
@@ -235,7 +244,8 @@ exit:
235} /* belkin_sa_open */ 244} /* belkin_sa_open */
236 245
237 246
238static void belkin_sa_close (struct usb_serial_port *port, struct file *filp) 247static void belkin_sa_close(struct tty_struct *tty,
248 struct usb_serial_port *port, struct file *filp)
239{ 249{
240 dbg("%s port %d", __func__, port->number); 250 dbg("%s port %d", __func__, port->number);
241 251
@@ -246,7 +256,7 @@ static void belkin_sa_close (struct usb_serial_port *port, struct file *filp)
246} /* belkin_sa_close */ 256} /* belkin_sa_close */
247 257
248 258
249static void belkin_sa_read_int_callback (struct urb *urb) 259static void belkin_sa_read_int_callback(struct urb *urb)
250{ 260{
251 struct usb_serial_port *port = urb->context; 261 struct usb_serial_port *port = urb->context;
252 struct belkin_sa_private *priv; 262 struct belkin_sa_private *priv;
@@ -272,7 +282,8 @@ static void belkin_sa_read_int_callback (struct urb *urb)
272 goto exit; 282 goto exit;
273 } 283 }
274 284
275 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 285 usb_serial_debug_data(debug, &port->dev, __func__,
286 urb->actual_length, data);
276 287
277 /* Handle known interrupt data */ 288 /* Handle known interrupt data */
278 /* ignore data[0] and data[1] */ 289 /* ignore data[0] and data[1] */
@@ -280,7 +291,7 @@ static void belkin_sa_read_int_callback (struct urb *urb)
280 priv = usb_get_serial_port_data(port); 291 priv = usb_get_serial_port_data(port);
281 spin_lock_irqsave(&priv->lock, flags); 292 spin_lock_irqsave(&priv->lock, flags);
282 priv->last_msr = data[BELKIN_SA_MSR_INDEX]; 293 priv->last_msr = data[BELKIN_SA_MSR_INDEX];
283 294
284 /* Record Control Line states */ 295 /* Record Control Line states */
285 if (priv->last_msr & BELKIN_SA_MSR_DSR) 296 if (priv->last_msr & BELKIN_SA_MSR_DSR)
286 priv->control_state |= TIOCM_DSR; 297 priv->control_state |= TIOCM_DSR;
@@ -311,7 +322,7 @@ static void belkin_sa_read_int_callback (struct urb *urb)
311 * to look in to this before committing any code. 322 * to look in to this before committing any code.
312 */ 323 */
313 if (priv->last_lsr & BELKIN_SA_LSR_ERR) { 324 if (priv->last_lsr & BELKIN_SA_LSR_ERR) {
314 tty = port->tty; 325 tty = port->port.tty;
315 /* Overrun Error */ 326 /* Overrun Error */
316 if (priv->last_lsr & BELKIN_SA_LSR_OE) { 327 if (priv->last_lsr & BELKIN_SA_LSR_OE) {
317 } 328 }
@@ -328,13 +339,14 @@ static void belkin_sa_read_int_callback (struct urb *urb)
328#endif 339#endif
329 spin_unlock_irqrestore(&priv->lock, flags); 340 spin_unlock_irqrestore(&priv->lock, flags);
330exit: 341exit:
331 retval = usb_submit_urb (urb, GFP_ATOMIC); 342 retval = usb_submit_urb(urb, GFP_ATOMIC);
332 if (retval) 343 if (retval)
333 err ("%s - usb_submit_urb failed with result %d", 344 err("%s - usb_submit_urb failed with result %d",
334 __func__, retval); 345 __func__, retval);
335} 346}
336 347
337static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 348static void belkin_sa_set_termios(struct tty_struct *tty,
349 struct usb_serial_port *port, struct ktermios *old_termios)
338{ 350{
339 struct usb_serial *serial = port->serial; 351 struct usb_serial *serial = port->serial;
340 struct belkin_sa_private *priv = usb_get_serial_port_data(port); 352 struct belkin_sa_private *priv = usb_get_serial_port_data(port);
@@ -347,8 +359,8 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
347 unsigned long control_state; 359 unsigned long control_state;
348 int bad_flow_control; 360 int bad_flow_control;
349 speed_t baud; 361 speed_t baud;
350 struct ktermios *termios = port->tty->termios; 362 struct ktermios *termios = tty->termios;
351 363
352 iflag = termios->c_iflag; 364 iflag = termios->c_iflag;
353 cflag = termios->c_cflag; 365 cflag = termios->c_cflag;
354 366
@@ -359,25 +371,26 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
359 control_state = priv->control_state; 371 control_state = priv->control_state;
360 bad_flow_control = priv->bad_flow_control; 372 bad_flow_control = priv->bad_flow_control;
361 spin_unlock_irqrestore(&priv->lock, flags); 373 spin_unlock_irqrestore(&priv->lock, flags);
362 374
363 old_iflag = old_termios->c_iflag; 375 old_iflag = old_termios->c_iflag;
364 old_cflag = old_termios->c_cflag; 376 old_cflag = old_termios->c_cflag;
365 377
366 /* Set the baud rate */ 378 /* Set the baud rate */
367 if ((cflag & CBAUD) != (old_cflag & CBAUD)) { 379 if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
368 /* reassert DTR and (maybe) RTS on transition from B0 */ 380 /* reassert DTR and (maybe) RTS on transition from B0 */
369 if( (old_cflag&CBAUD) == B0 ) { 381 if ((old_cflag & CBAUD) == B0) {
370 control_state |= (TIOCM_DTR|TIOCM_RTS); 382 control_state |= (TIOCM_DTR|TIOCM_RTS);
371 if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 1) < 0) 383 if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 1) < 0)
372 err("Set DTR error"); 384 err("Set DTR error");
373 /* don't set RTS if using hardware flow control */ 385 /* don't set RTS if using hardware flow control */
374 if (!(old_cflag & CRTSCTS)) 386 if (!(old_cflag & CRTSCTS))
375 if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 1) < 0) 387 if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST
388 , 1) < 0)
376 err("Set RTS error"); 389 err("Set RTS error");
377 } 390 }
378 } 391 }
379 392
380 baud = tty_get_baud_rate(port->tty); 393 baud = tty_get_baud_rate(tty);
381 if (baud) { 394 if (baud) {
382 urb_value = BELKIN_SA_BAUD(baud); 395 urb_value = BELKIN_SA_BAUD(baud);
383 /* Clip to maximum speed */ 396 /* Clip to maximum speed */
@@ -387,12 +400,13 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
387 baud = BELKIN_SA_BAUD(urb_value); 400 baud = BELKIN_SA_BAUD(urb_value);
388 401
389 /* Report the actual baud rate back to the caller */ 402 /* Report the actual baud rate back to the caller */
390 tty_encode_baud_rate(port->tty, baud, baud); 403 tty_encode_baud_rate(tty, baud, baud);
391 if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0) 404 if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0)
392 err("Set baudrate error"); 405 err("Set baudrate error");
393 } else { 406 } else {
394 /* Disable flow control */ 407 /* Disable flow control */
395 if (BSA_USB_CMD(BELKIN_SA_SET_FLOW_CTRL_REQUEST, BELKIN_SA_FLOW_NONE) < 0) 408 if (BSA_USB_CMD(BELKIN_SA_SET_FLOW_CTRL_REQUEST,
409 BELKIN_SA_FLOW_NONE) < 0)
396 err("Disable flowcontrol error"); 410 err("Disable flowcontrol error");
397 /* Drop RTS and DTR */ 411 /* Drop RTS and DTR */
398 control_state &= ~(TIOCM_DTR | TIOCM_RTS); 412 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
@@ -403,9 +417,10 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
403 } 417 }
404 418
405 /* set the parity */ 419 /* set the parity */
406 if( (cflag&(PARENB|PARODD)) != (old_cflag&(PARENB|PARODD)) ) { 420 if ((cflag ^ old_cflag) & (PARENB | PARODD)) {
407 if (cflag & PARENB) 421 if (cflag & PARENB)
408 urb_value = (cflag & PARODD) ? BELKIN_SA_PARITY_ODD : BELKIN_SA_PARITY_EVEN; 422 urb_value = (cflag & PARODD) ? BELKIN_SA_PARITY_ODD
423 : BELKIN_SA_PARITY_EVEN;
409 else 424 else
410 urb_value = BELKIN_SA_PARITY_NONE; 425 urb_value = BELKIN_SA_PARITY_NONE;
411 if (BSA_USB_CMD(BELKIN_SA_SET_PARITY_REQUEST, urb_value) < 0) 426 if (BSA_USB_CMD(BELKIN_SA_SET_PARITY_REQUEST, urb_value) < 0)
@@ -413,31 +428,40 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
413 } 428 }
414 429
415 /* set the number of data bits */ 430 /* set the number of data bits */
416 if( (cflag&CSIZE) != (old_cflag&CSIZE) ) { 431 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
417 switch (cflag & CSIZE) { 432 switch (cflag & CSIZE) {
418 case CS5: urb_value = BELKIN_SA_DATA_BITS(5); break; 433 case CS5:
419 case CS6: urb_value = BELKIN_SA_DATA_BITS(6); break; 434 urb_value = BELKIN_SA_DATA_BITS(5);
420 case CS7: urb_value = BELKIN_SA_DATA_BITS(7); break; 435 break;
421 case CS8: urb_value = BELKIN_SA_DATA_BITS(8); break; 436 case CS6:
422 default: dbg("CSIZE was not CS5-CS8, using default of 8"); 437 urb_value = BELKIN_SA_DATA_BITS(6);
423 urb_value = BELKIN_SA_DATA_BITS(8); 438 break;
424 break; 439 case CS7:
440 urb_value = BELKIN_SA_DATA_BITS(7);
441 break;
442 case CS8:
443 urb_value = BELKIN_SA_DATA_BITS(8);
444 break;
445 default: dbg("CSIZE was not CS5-CS8, using default of 8");
446 urb_value = BELKIN_SA_DATA_BITS(8);
447 break;
425 } 448 }
426 if (BSA_USB_CMD(BELKIN_SA_SET_DATA_BITS_REQUEST, urb_value) < 0) 449 if (BSA_USB_CMD(BELKIN_SA_SET_DATA_BITS_REQUEST, urb_value) < 0)
427 err("Set data bits error"); 450 err("Set data bits error");
428 } 451 }
429 452
430 /* set the number of stop bits */ 453 /* set the number of stop bits */
431 if( (cflag&CSTOPB) != (old_cflag&CSTOPB) ) { 454 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) {
432 urb_value = (cflag & CSTOPB) ? BELKIN_SA_STOP_BITS(2) : BELKIN_SA_STOP_BITS(1); 455 urb_value = (cflag & CSTOPB) ? BELKIN_SA_STOP_BITS(2)
433 if (BSA_USB_CMD(BELKIN_SA_SET_STOP_BITS_REQUEST, urb_value) < 0) 456 : BELKIN_SA_STOP_BITS(1);
457 if (BSA_USB_CMD(BELKIN_SA_SET_STOP_BITS_REQUEST,
458 urb_value) < 0)
434 err("Set stop bits error"); 459 err("Set stop bits error");
435 } 460 }
436 461
437 /* Set flow control */ 462 /* Set flow control */
438 if( (iflag&IXOFF) != (old_iflag&IXOFF) 463 if (((iflag ^ old_iflag) & (IXOFF | IXON)) ||
439 || (iflag&IXON) != (old_iflag&IXON) 464 ((cflag ^ old_cflag) & CRTSCTS)) {
440 || (cflag&CRTSCTS) != (old_cflag&CRTSCTS) ) {
441 urb_value = 0; 465 urb_value = 0;
442 if ((iflag & IXOFF) || (iflag & IXON)) 466 if ((iflag & IXOFF) || (iflag & IXON))
443 urb_value |= (BELKIN_SA_FLOW_OXON | BELKIN_SA_FLOW_IXON); 467 urb_value |= (BELKIN_SA_FLOW_OXON | BELKIN_SA_FLOW_IXON);
@@ -463,8 +487,9 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
463} /* belkin_sa_set_termios */ 487} /* belkin_sa_set_termios */
464 488
465 489
466static void belkin_sa_break_ctl( struct usb_serial_port *port, int break_state ) 490static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state)
467{ 491{
492 struct usb_serial_port *port = tty->driver_data;
468 struct usb_serial *serial = port->serial; 493 struct usb_serial *serial = port->serial;
469 494
470 if (BSA_USB_CMD(BELKIN_SA_SET_BREAK_REQUEST, break_state ? 1 : 0) < 0) 495 if (BSA_USB_CMD(BELKIN_SA_SET_BREAK_REQUEST, break_state ? 1 : 0) < 0)
@@ -472,12 +497,13 @@ static void belkin_sa_break_ctl( struct usb_serial_port *port, int break_state )
472} 497}
473 498
474 499
475static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file) 500static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file)
476{ 501{
502 struct usb_serial_port *port = tty->driver_data;
477 struct belkin_sa_private *priv = usb_get_serial_port_data(port); 503 struct belkin_sa_private *priv = usb_get_serial_port_data(port);
478 unsigned long control_state; 504 unsigned long control_state;
479 unsigned long flags; 505 unsigned long flags;
480 506
481 dbg("%s", __func__); 507 dbg("%s", __func__);
482 508
483 spin_lock_irqsave(&priv->lock, flags); 509 spin_lock_irqsave(&priv->lock, flags);
@@ -488,9 +514,10 @@ static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file)
488} 514}
489 515
490 516
491static int belkin_sa_tiocmset (struct usb_serial_port *port, struct file *file, 517static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file,
492 unsigned int set, unsigned int clear) 518 unsigned int set, unsigned int clear)
493{ 519{
520 struct usb_serial_port *port = tty->driver_data;
494 struct usb_serial *serial = port->serial; 521 struct usb_serial *serial = port->serial;
495 struct belkin_sa_private *priv = usb_get_serial_port_data(port); 522 struct belkin_sa_private *priv = usb_get_serial_port_data(port);
496 unsigned long control_state; 523 unsigned long control_state;
@@ -498,7 +525,7 @@ static int belkin_sa_tiocmset (struct usb_serial_port *port, struct file *file,
498 int retval; 525 int retval;
499 int rts = 0; 526 int rts = 0;
500 int dtr = 0; 527 int dtr = 0;
501 528
502 dbg("%s", __func__); 529 dbg("%s", __func__);
503 530
504 spin_lock_irqsave(&priv->lock, flags); 531 spin_lock_irqsave(&priv->lock, flags);
@@ -540,29 +567,7 @@ exit:
540} 567}
541 568
542 569
543static int belkin_sa_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 570static int __init belkin_sa_init(void)
544{
545 switch (cmd) {
546 case TIOCMIWAIT:
547 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
548 /* TODO */
549 return( 0 );
550
551 case TIOCGICOUNT:
552 /* return count of modemline transitions */
553 /* TODO */
554 return 0;
555
556 default:
557 dbg("belkin_sa_ioctl arg not supported - 0x%04x",cmd);
558 return(-ENOIOCTLCMD);
559 break;
560 }
561 return 0;
562} /* belkin_sa_ioctl */
563
564
565static int __init belkin_sa_init (void)
566{ 571{
567 int retval; 572 int retval;
568 retval = usb_serial_register(&belkin_device); 573 retval = usb_serial_register(&belkin_device);
@@ -582,17 +587,17 @@ failed_usb_serial_register:
582 587
583static void __exit belkin_sa_exit (void) 588static void __exit belkin_sa_exit (void)
584{ 589{
585 usb_deregister (&belkin_driver); 590 usb_deregister(&belkin_driver);
586 usb_serial_deregister (&belkin_device); 591 usb_serial_deregister(&belkin_device);
587} 592}
588 593
589 594
590module_init (belkin_sa_init); 595module_init(belkin_sa_init);
591module_exit (belkin_sa_exit); 596module_exit(belkin_sa_exit);
592 597
593MODULE_AUTHOR( DRIVER_AUTHOR ); 598MODULE_AUTHOR(DRIVER_AUTHOR);
594MODULE_DESCRIPTION( DRIVER_DESC ); 599MODULE_DESCRIPTION(DRIVER_DESC);
595MODULE_VERSION( DRIVER_VERSION ); 600MODULE_VERSION(DRIVER_VERSION);
596MODULE_LICENSE("GPL"); 601MODULE_LICENSE("GPL");
597 602
598module_param(debug, bool, S_IRUGO | S_IWUSR); 603module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/belkin_sa.h b/drivers/usb/serial/belkin_sa.h
index 9116b92f4622..c66a6730d38c 100644
--- a/drivers/usb/serial/belkin_sa.h
+++ b/drivers/usb/serial/belkin_sa.h
@@ -7,13 +7,14 @@
7 * This program is largely derived from work by the linux-usb group 7 * This program is largely derived from work by the linux-usb group
8 * and associated source files. Please see the usb/serial files for 8 * and associated source files. Please see the usb/serial files for
9 * individual credits and copyrights. 9 * individual credits and copyrights.
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
15 * 15 *
16 * See Documentation/usb/usb-serial.txt for more information on using this driver 16 * See Documentation/usb/usb-serial.txt for more information on using this
17 * driver
17 * 18 *
18 * 12-Mar-2001 gkh 19 * 12-Mar-2001 gkh
19 * Added GoHubs GO-COM232 device id. 20 * Added GoHubs GO-COM232 device id.
@@ -27,7 +28,7 @@
27 * adapter, so pardon any stupid mistakes. All of the information 28 * adapter, so pardon any stupid mistakes. All of the information
28 * I am using to write this driver was acquired by using a modified 29 * I am using to write this driver was acquired by using a modified
29 * UsbSnoop on Windows2000. 30 * UsbSnoop on Windows2000.
30 * 31 *
31 */ 32 */
32 33
33#ifndef __LINUX_USB_SERIAL_BSA_H 34#ifndef __LINUX_USB_SERIAL_BSA_H
@@ -96,20 +97,20 @@
96 97
97/* 98/*
98 * It seems that the interrupt pipe is closely modelled after the 99 * It seems that the interrupt pipe is closely modelled after the
99 * 16550 register layout. This is probably because the adapter can 100 * 16550 register layout. This is probably because the adapter can
100 * be used in a "DOS" environment to simulate a standard hardware port. 101 * be used in a "DOS" environment to simulate a standard hardware port.
101 */ 102 */
102#define BELKIN_SA_LSR_INDEX 2 /* Line Status Register */ 103#define BELKIN_SA_LSR_INDEX 2 /* Line Status Register */
103#define BELKIN_SA_LSR_RDR 0x01 /* receive data ready */ 104#define BELKIN_SA_LSR_RDR 0x01 /* receive data ready */
104#define BELKIN_SA_LSR_OE 0x02 /* overrun error */ 105#define BELKIN_SA_LSR_OE 0x02 /* overrun error */
105#define BELKIN_SA_LSR_PE 0x04 /* parity error */ 106#define BELKIN_SA_LSR_PE 0x04 /* parity error */
106#define BELKIN_SA_LSR_FE 0x08 /* framing error */ 107#define BELKIN_SA_LSR_FE 0x08 /* framing error */
107#define BELKIN_SA_LSR_BI 0x10 /* break indicator */ 108#define BELKIN_SA_LSR_BI 0x10 /* break indicator */
108#define BELKIN_SA_LSR_THE 0x20 /* transmit holding register empty */ 109#define BELKIN_SA_LSR_THE 0x20 /* tx holding register empty */
109#define BELKIN_SA_LSR_TE 0x40 /* transmit register empty */ 110#define BELKIN_SA_LSR_TE 0x40 /* transmit register empty */
110#define BELKIN_SA_LSR_ERR 0x80 /* OE | PE | FE | BI */ 111#define BELKIN_SA_LSR_ERR 0x80 /* OE | PE | FE | BI */
111 112
112#define BELKIN_SA_MSR_INDEX 3 /* Modem Status Register */ 113#define BELKIN_SA_MSR_INDEX 3 /* Modem Status Register */
113#define BELKIN_SA_MSR_DCTS 0x01 /* Delta CTS */ 114#define BELKIN_SA_MSR_DCTS 0x01 /* Delta CTS */
114#define BELKIN_SA_MSR_DDSR 0x02 /* Delta DSR */ 115#define BELKIN_SA_MSR_DDSR 0x02 /* Delta DSR */
115#define BELKIN_SA_MSR_DRI 0x04 /* Delta RI */ 116#define BELKIN_SA_MSR_DRI 0x04 /* Delta RI */
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
index 0b14aea8ebd5..83bbb5bca2ef 100644
--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -15,7 +15,8 @@
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/usb/serial.h> 16#include <linux/usb/serial.h>
17 17
18static int usb_serial_device_match (struct device *dev, struct device_driver *drv) 18static int usb_serial_device_match(struct device *dev,
19 struct device_driver *drv)
19{ 20{
20 struct usb_serial_driver *driver; 21 struct usb_serial_driver *driver;
21 const struct usb_serial_port *port; 22 const struct usb_serial_port *port;
@@ -46,7 +47,7 @@ static ssize_t show_port_number(struct device *dev,
46 47
47static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL); 48static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL);
48 49
49static int usb_serial_device_probe (struct device *dev) 50static int usb_serial_device_probe(struct device *dev)
50{ 51{
51 struct usb_serial_driver *driver; 52 struct usb_serial_driver *driver;
52 struct usb_serial_port *port; 53 struct usb_serial_port *port;
@@ -66,7 +67,7 @@ static int usb_serial_device_probe (struct device *dev)
66 retval = -EIO; 67 retval = -EIO;
67 goto exit; 68 goto exit;
68 } 69 }
69 retval = driver->port_probe (port); 70 retval = driver->port_probe(port);
70 module_put(driver->driver.owner); 71 module_put(driver->driver.owner);
71 if (retval) 72 if (retval)
72 goto exit; 73 goto exit;
@@ -77,8 +78,8 @@ static int usb_serial_device_probe (struct device *dev)
77 goto exit; 78 goto exit;
78 79
79 minor = port->number; 80 minor = port->number;
80 tty_register_device (usb_serial_tty_driver, minor, dev); 81 tty_register_device(usb_serial_tty_driver, minor, dev);
81 dev_info(&port->serial->dev->dev, 82 dev_info(&port->serial->dev->dev,
82 "%s converter now attached to ttyUSB%d\n", 83 "%s converter now attached to ttyUSB%d\n",
83 driver->description, minor); 84 driver->description, minor);
84 85
@@ -86,7 +87,7 @@ exit:
86 return retval; 87 return retval;
87} 88}
88 89
89static int usb_serial_device_remove (struct device *dev) 90static int usb_serial_device_remove(struct device *dev)
90{ 91{
91 struct usb_serial_driver *driver; 92 struct usb_serial_driver *driver;
92 struct usb_serial_port *port; 93 struct usb_serial_port *port;
@@ -94,9 +95,8 @@ static int usb_serial_device_remove (struct device *dev)
94 int minor; 95 int minor;
95 96
96 port = to_usb_serial_port(dev); 97 port = to_usb_serial_port(dev);
97 if (!port) { 98 if (!port)
98 return -ENODEV; 99 return -ENODEV;
99 }
100 100
101 device_remove_file(&port->dev, &dev_attr_port_number); 101 device_remove_file(&port->dev, &dev_attr_port_number);
102 102
@@ -107,12 +107,12 @@ static int usb_serial_device_remove (struct device *dev)
107 retval = -EIO; 107 retval = -EIO;
108 goto exit; 108 goto exit;
109 } 109 }
110 retval = driver->port_remove (port); 110 retval = driver->port_remove(port);
111 module_put(driver->driver.owner); 111 module_put(driver->driver.owner);
112 } 112 }
113exit: 113exit:
114 minor = port->number; 114 minor = port->number;
115 tty_unregister_device (usb_serial_tty_driver, minor); 115 tty_unregister_device(usb_serial_tty_driver, minor);
116 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", 116 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
117 driver->description, minor); 117 driver->description, minor);
118 118
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 1f7c86bd8297..f61e3ca64305 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -232,7 +232,8 @@ error: kfree(priv);
232} 232}
233 233
234/* open this device, set default parameters */ 234/* open this device, set default parameters */
235static int ch341_open(struct usb_serial_port *port, struct file *filp) 235static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port,
236 struct file *filp)
236{ 237{
237 struct usb_serial *serial = port->serial; 238 struct usb_serial *serial = port->serial;
238 struct ch341_private *priv = usb_get_serial_port_data(serial->port[0]); 239 struct ch341_private *priv = usb_get_serial_port_data(serial->port[0]);
@@ -256,7 +257,7 @@ static int ch341_open(struct usb_serial_port *port, struct file *filp)
256 if (r) 257 if (r)
257 goto out; 258 goto out;
258 259
259 r = usb_serial_generic_open(port, filp); 260 r = usb_serial_generic_open(tty, port, filp);
260 261
261out: return r; 262out: return r;
262} 263}
@@ -264,11 +265,10 @@ out: return r;
264/* Old_termios contains the original termios settings and 265/* Old_termios contains the original termios settings and
265 * tty->termios contains the new setting to be used. 266 * tty->termios contains the new setting to be used.
266 */ 267 */
267static void ch341_set_termios(struct usb_serial_port *port, 268static void ch341_set_termios(struct tty_struct *tty,
268 struct ktermios *old_termios) 269 struct usb_serial_port *port, struct ktermios *old_termios)
269{ 270{
270 struct ch341_private *priv = usb_get_serial_port_data(port); 271 struct ch341_private *priv = usb_get_serial_port_data(port);
271 struct tty_struct *tty = port->tty;
272 unsigned baud_rate; 272 unsigned baud_rate;
273 273
274 dbg("ch341_set_termios()"); 274 dbg("ch341_set_termios()");
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index 201184c3fb87..7b74238ad1c7 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -6,7 +6,7 @@
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation. 8 * 2 as published by the Free Software Foundation.
9 * 9 *
10 * Thanks to Randy Dunlap for the original version of this code. 10 * Thanks to Randy Dunlap for the original version of this code.
11 * 11 *
12 */ 12 */
@@ -67,7 +67,7 @@ static int usb_console_setup(struct console *co, char *options)
67 struct tty_struct *tty = NULL; 67 struct tty_struct *tty = NULL;
68 struct ktermios *termios = NULL, dummy; 68 struct ktermios *termios = NULL, dummy;
69 69
70 dbg ("%s", __func__); 70 dbg("%s", __func__);
71 71
72 if (options) { 72 if (options) {
73 baud = simple_strtoul(options, NULL, 10); 73 baud = simple_strtoul(options, NULL, 10);
@@ -81,55 +81,27 @@ static int usb_console_setup(struct console *co, char *options)
81 if (*s) 81 if (*s)
82 doflow = (*s++ == 'r'); 82 doflow = (*s++ == 'r');
83 } 83 }
84
85 /* Sane default */
86 if (baud == 0)
87 baud = 9600;
84 88
85 /* build a cflag setting */
86 switch (baud) {
87 case 1200:
88 cflag |= B1200;
89 break;
90 case 2400:
91 cflag |= B2400;
92 break;
93 case 4800:
94 cflag |= B4800;
95 break;
96 case 19200:
97 cflag |= B19200;
98 break;
99 case 38400:
100 cflag |= B38400;
101 break;
102 case 57600:
103 cflag |= B57600;
104 break;
105 case 115200:
106 cflag |= B115200;
107 break;
108 case 9600:
109 default:
110 cflag |= B9600;
111 /*
112 * Set this to a sane value to prevent a divide error
113 */
114 baud = 9600;
115 break;
116 }
117 switch (bits) { 89 switch (bits) {
118 case 7: 90 case 7:
119 cflag |= CS7; 91 cflag |= CS7;
120 break; 92 break;
121 default: 93 default:
122 case 8: 94 case 8:
123 cflag |= CS8; 95 cflag |= CS8;
124 break; 96 break;
125 } 97 }
126 switch (parity) { 98 switch (parity) {
127 case 'o': case 'O': 99 case 'o': case 'O':
128 cflag |= PARODD; 100 cflag |= PARODD;
129 break; 101 break;
130 case 'e': case 'E': 102 case 'e': case 'E':
131 cflag |= PARENB; 103 cflag |= PARENB;
132 break; 104 break;
133 } 105 }
134 co->cflag = cflag; 106 co->cflag = cflag;
135 107
@@ -140,17 +112,17 @@ static int usb_console_setup(struct console *co, char *options)
140 serial = usb_serial_get_by_index(co->index); 112 serial = usb_serial_get_by_index(co->index);
141 if (serial == NULL) { 113 if (serial == NULL) {
142 /* no device is connected yet, sorry :( */ 114 /* no device is connected yet, sorry :( */
143 err ("No USB device connected to ttyUSB%i", co->index); 115 err("No USB device connected to ttyUSB%i", co->index);
144 return -ENODEV; 116 return -ENODEV;
145 } 117 }
146 118
147 port = serial->port[0]; 119 port = serial->port[0];
148 port->tty = NULL; 120 port->port.tty = NULL;
149 121
150 info->port = port; 122 info->port = port;
151 123
152 ++port->open_count; 124 ++port->port.count;
153 if (port->open_count == 1) { 125 if (port->port.count == 1) {
154 if (serial->type->set_termios) { 126 if (serial->type->set_termios) {
155 /* 127 /*
156 * allocate a fake tty so the driver can initialize 128 * allocate a fake tty so the driver can initialize
@@ -171,15 +143,15 @@ static int usb_console_setup(struct console *co, char *options)
171 } 143 }
172 memset(&dummy, 0, sizeof(struct ktermios)); 144 memset(&dummy, 0, sizeof(struct ktermios));
173 tty->termios = termios; 145 tty->termios = termios;
174 port->tty = tty; 146 port->port.tty = tty;
175 } 147 }
176 148
177 /* only call the device specific open if this 149 /* only call the device specific open if this
178 * is the first time the port is opened */ 150 * is the first time the port is opened */
179 if (serial->type->open) 151 if (serial->type->open)
180 retval = serial->type->open(port, NULL); 152 retval = serial->type->open(NULL, port, NULL);
181 else 153 else
182 retval = usb_serial_generic_open(port, NULL); 154 retval = usb_serial_generic_open(NULL, port, NULL);
183 155
184 if (retval) { 156 if (retval) {
185 err("could not open USB console port"); 157 err("could not open USB console port");
@@ -188,9 +160,10 @@ static int usb_console_setup(struct console *co, char *options)
188 160
189 if (serial->type->set_termios) { 161 if (serial->type->set_termios) {
190 termios->c_cflag = cflag; 162 termios->c_cflag = cflag;
191 serial->type->set_termios(port, &dummy); 163 tty_termios_encode_baud_rate(termios, baud, baud);
164 serial->type->set_termios(NULL, port, &dummy);
192 165
193 port->tty = NULL; 166 port->port.tty = NULL;
194 kfree(termios); 167 kfree(termios);
195 kfree(tty); 168 kfree(tty);
196 } 169 }
@@ -203,15 +176,16 @@ out:
203 return retval; 176 return retval;
204free_termios: 177free_termios:
205 kfree(termios); 178 kfree(termios);
206 port->tty = NULL; 179 port->port.tty = NULL;
207free_tty: 180free_tty:
208 kfree(tty); 181 kfree(tty);
209reset_open_count: 182reset_open_count:
210 port->open_count = 0; 183 port->port.count = 0;
211goto out; 184goto out;
212} 185}
213 186
214static void usb_console_write(struct console *co, const char *buf, unsigned count) 187static void usb_console_write(struct console *co,
188 const char *buf, unsigned count)
215{ 189{
216 static struct usbcons_info *info = &usbcons_info; 190 static struct usbcons_info *info = &usbcons_info;
217 struct usb_serial_port *port = info->port; 191 struct usb_serial_port *port = info->port;
@@ -227,8 +201,8 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
227 201
228 dbg("%s - port %d, %d byte(s)", __func__, port->number, count); 202 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
229 203
230 if (!port->open_count) { 204 if (!port->port.count) {
231 dbg ("%s - port not opened", __func__); 205 dbg("%s - port not opened", __func__);
232 return; 206 return;
233 } 207 }
234 208
@@ -236,26 +210,29 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
236 unsigned int i; 210 unsigned int i;
237 unsigned int lf; 211 unsigned int lf;
238 /* search for LF so we can insert CR if necessary */ 212 /* search for LF so we can insert CR if necessary */
239 for (i=0, lf=0 ; i < count ; i++) { 213 for (i = 0, lf = 0 ; i < count ; i++) {
240 if (*(buf + i) == 10) { 214 if (*(buf + i) == 10) {
241 lf = 1; 215 lf = 1;
242 i++; 216 i++;
243 break; 217 break;
244 } 218 }
245 } 219 }
246 /* pass on to the driver specific version of this function if it is available */ 220 /* pass on to the driver specific version of this function if
221 it is available */
247 if (serial->type->write) 222 if (serial->type->write)
248 retval = serial->type->write(port, buf, i); 223 retval = serial->type->write(NULL, port, buf, i);
249 else 224 else
250 retval = usb_serial_generic_write(port, buf, i); 225 retval = usb_serial_generic_write(NULL, port, buf, i);
251 dbg("%s - return value : %d", __func__, retval); 226 dbg("%s - return value : %d", __func__, retval);
252 if (lf) { 227 if (lf) {
253 /* append CR after LF */ 228 /* append CR after LF */
254 unsigned char cr = 13; 229 unsigned char cr = 13;
255 if (serial->type->write) 230 if (serial->type->write)
256 retval = serial->type->write(port, &cr, 1); 231 retval = serial->type->write(NULL,
232 port, &cr, 1);
257 else 233 else
258 retval = usb_serial_generic_write(port, &cr, 1); 234 retval = usb_serial_generic_write(NULL,
235 port, &cr, 1);
259 dbg("%s - return value : %d", __func__, retval); 236 dbg("%s - return value : %d", __func__, retval);
260 } 237 }
261 buf += i; 238 buf += i;
@@ -273,18 +250,19 @@ static struct console usbcons = {
273 250
274void usb_serial_console_disconnect(struct usb_serial *serial) 251void usb_serial_console_disconnect(struct usb_serial *serial)
275{ 252{
276 if (serial && serial->port && serial->port[0] && serial->port[0] == usbcons_info.port) { 253 if (serial && serial->port && serial->port[0]
254 && serial->port[0] == usbcons_info.port) {
277 usb_serial_console_exit(); 255 usb_serial_console_exit();
278 usb_serial_put(serial); 256 usb_serial_put(serial);
279 } 257 }
280} 258}
281 259
282void usb_serial_console_init (int serial_debug, int minor) 260void usb_serial_console_init(int serial_debug, int minor)
283{ 261{
284 debug = serial_debug; 262 debug = serial_debug;
285 263
286 if (minor == 0) { 264 if (minor == 0) {
287 /* 265 /*
288 * Call register_console() if this is the first device plugged 266 * Call register_console() if this is the first device plugged
289 * in. If we call it earlier, then the callback to 267 * in. If we call it earlier, then the callback to
290 * console_setup() will fail, as there is not a device seen by 268 * console_setup() will fail, as there is not a device seen by
@@ -293,21 +271,21 @@ void usb_serial_console_init (int serial_debug, int minor)
293 /* 271 /*
294 * Register console. 272 * Register console.
295 * NOTES: 273 * NOTES:
296 * console_setup() is called (back) immediately (from register_console). 274 * console_setup() is called (back) immediately (from
297 * console_write() is called immediately from register_console iff 275 * register_console). console_write() is called immediately
298 * CON_PRINTBUFFER is set in flags. 276 * from register_console iff CON_PRINTBUFFER is set in flags.
299 */ 277 */
300 dbg ("registering the USB serial console."); 278 dbg("registering the USB serial console.");
301 register_console(&usbcons); 279 register_console(&usbcons);
302 } 280 }
303} 281}
304 282
305void usb_serial_console_exit (void) 283void usb_serial_console_exit(void)
306{ 284{
307 if (usbcons_info.port) { 285 if (usbcons_info.port) {
308 unregister_console(&usbcons); 286 unregister_console(&usbcons);
309 if (usbcons_info.port->open_count) 287 if (usbcons_info.port->port.count)
310 usbcons_info.port->open_count--; 288 usbcons_info.port->port.count--;
311 usbcons_info.port = NULL; 289 usbcons_info.port = NULL;
312 } 290 }
313} 291}
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index f5b57b196c5a..442cba69cce5 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -25,7 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <asm/uaccess.h> 28#include <linux/uaccess.h>
29#include <linux/usb/serial.h> 29#include <linux/usb/serial.h>
30 30
31/* 31/*
@@ -37,17 +37,20 @@
37/* 37/*
38 * Function Prototypes 38 * Function Prototypes
39 */ 39 */
40static int cp2101_open(struct usb_serial_port*, struct file*); 40static int cp2101_open(struct tty_struct *, struct usb_serial_port *,
41static void cp2101_cleanup(struct usb_serial_port*); 41 struct file *);
42static void cp2101_close(struct usb_serial_port*, struct file*); 42static void cp2101_cleanup(struct usb_serial_port *);
43static void cp2101_get_termios(struct usb_serial_port*); 43static void cp2101_close(struct tty_struct *, struct usb_serial_port *,
44static void cp2101_set_termios(struct usb_serial_port*, struct ktermios*); 44 struct file*);
45static int cp2101_tiocmget (struct usb_serial_port *, struct file *); 45static void cp2101_get_termios(struct tty_struct *);
46static int cp2101_tiocmset (struct usb_serial_port *, struct file *, 46static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *,
47 struct ktermios*);
48static int cp2101_tiocmget(struct tty_struct *, struct file *);
49static int cp2101_tiocmset(struct tty_struct *, struct file *,
47 unsigned int, unsigned int); 50 unsigned int, unsigned int);
48static void cp2101_break_ctl(struct usb_serial_port*, int); 51static void cp2101_break_ctl(struct tty_struct *, int);
49static int cp2101_startup (struct usb_serial *); 52static int cp2101_startup(struct usb_serial *);
50static void cp2101_shutdown(struct usb_serial*); 53static void cp2101_shutdown(struct usb_serial *);
51 54
52 55
53static int debug; 56static int debug;
@@ -93,7 +96,7 @@ static struct usb_device_id id_table [] = {
93 { } /* Terminating Entry */ 96 { } /* Terminating Entry */
94}; 97};
95 98
96MODULE_DEVICE_TABLE (usb, id_table); 99MODULE_DEVICE_TABLE(usb, id_table);
97 100
98static struct usb_driver cp2101_driver = { 101static struct usb_driver cp2101_driver = {
99 .name = "cp2101", 102 .name = "cp2101",
@@ -182,7 +185,7 @@ static struct usb_serial_driver cp2101_device = {
182 * 'data' is a pointer to a pre-allocated array of integers large 185 * 'data' is a pointer to a pre-allocated array of integers large
183 * enough to hold 'size' bytes (with 4 bytes to each integer) 186 * enough to hold 'size' bytes (with 4 bytes to each integer)
184 */ 187 */
185static int cp2101_get_config(struct usb_serial_port* port, u8 request, 188static int cp2101_get_config(struct usb_serial_port *port, u8 request,
186 unsigned int *data, int size) 189 unsigned int *data, int size)
187{ 190{
188 struct usb_serial *serial = port->serial; 191 struct usb_serial *serial = port->serial;
@@ -202,12 +205,12 @@ static int cp2101_get_config(struct usb_serial_port* port, u8 request,
202 request++; 205 request++;
203 206
204 /* Issue the request, attempting to read 'size' bytes */ 207 /* Issue the request, attempting to read 'size' bytes */
205 result = usb_control_msg (serial->dev,usb_rcvctrlpipe (serial->dev, 0), 208 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
206 request, REQTYPE_DEVICE_TO_HOST, 0x0000, 209 request, REQTYPE_DEVICE_TO_HOST, 0x0000,
207 0, buf, size, 300); 210 0, buf, size, 300);
208 211
209 /* Convert data into an array of integers */ 212 /* Convert data into an array of integers */
210 for (i=0; i<length; i++) 213 for (i = 0; i < length; i++)
211 data[i] = le32_to_cpu(buf[i]); 214 data[i] = le32_to_cpu(buf[i]);
212 215
213 kfree(buf); 216 kfree(buf);
@@ -228,7 +231,7 @@ static int cp2101_get_config(struct usb_serial_port* port, u8 request,
228 * Values less than 16 bits wide are sent directly 231 * Values less than 16 bits wide are sent directly
229 * 'size' is specified in bytes. 232 * 'size' is specified in bytes.
230 */ 233 */
231static int cp2101_set_config(struct usb_serial_port* port, u8 request, 234static int cp2101_set_config(struct usb_serial_port *port, u8 request,
232 unsigned int *data, int size) 235 unsigned int *data, int size)
233{ 236{
234 struct usb_serial *serial = port->serial; 237 struct usb_serial *serial = port->serial;
@@ -250,12 +253,12 @@ static int cp2101_set_config(struct usb_serial_port* port, u8 request,
250 buf[i] = cpu_to_le32(data[i]); 253 buf[i] = cpu_to_le32(data[i]);
251 254
252 if (size > 2) { 255 if (size > 2) {
253 result = usb_control_msg (serial->dev, 256 result = usb_control_msg(serial->dev,
254 usb_sndctrlpipe(serial->dev, 0), 257 usb_sndctrlpipe(serial->dev, 0),
255 request, REQTYPE_HOST_TO_DEVICE, 0x0000, 258 request, REQTYPE_HOST_TO_DEVICE, 0x0000,
256 0, buf, size, 300); 259 0, buf, size, 300);
257 } else { 260 } else {
258 result = usb_control_msg (serial->dev, 261 result = usb_control_msg(serial->dev,
259 usb_sndctrlpipe(serial->dev, 0), 262 usb_sndctrlpipe(serial->dev, 0),
260 request, REQTYPE_HOST_TO_DEVICE, data[0], 263 request, REQTYPE_HOST_TO_DEVICE, data[0],
261 0, NULL, 0, 300); 264 0, NULL, 0, 300);
@@ -271,7 +274,7 @@ static int cp2101_set_config(struct usb_serial_port* port, u8 request,
271 } 274 }
272 275
273 /* Single data value */ 276 /* Single data value */
274 result = usb_control_msg (serial->dev, 277 result = usb_control_msg(serial->dev,
275 usb_sndctrlpipe(serial->dev, 0), 278 usb_sndctrlpipe(serial->dev, 0),
276 request, REQTYPE_HOST_TO_DEVICE, data[0], 279 request, REQTYPE_HOST_TO_DEVICE, data[0],
277 0, NULL, 0, 300); 280 0, NULL, 0, 300);
@@ -283,13 +286,14 @@ static int cp2101_set_config(struct usb_serial_port* port, u8 request,
283 * Convenience function for calling cp2101_set_config on single data values 286 * Convenience function for calling cp2101_set_config on single data values
284 * without requiring an integer pointer 287 * without requiring an integer pointer
285 */ 288 */
286static inline int cp2101_set_config_single(struct usb_serial_port* port, 289static inline int cp2101_set_config_single(struct usb_serial_port *port,
287 u8 request, unsigned int data) 290 u8 request, unsigned int data)
288{ 291{
289 return cp2101_set_config(port, request, &data, 2); 292 return cp2101_set_config(port, request, &data, 2);
290} 293}
291 294
292static int cp2101_open (struct usb_serial_port *port, struct file *filp) 295static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port,
296 struct file *filp)
293{ 297{
294 struct usb_serial *serial = port->serial; 298 struct usb_serial *serial = port->serial;
295 int result; 299 int result;
@@ -303,7 +307,7 @@ static int cp2101_open (struct usb_serial_port *port, struct file *filp)
303 } 307 }
304 308
305 /* Start reading from the device */ 309 /* Start reading from the device */
306 usb_fill_bulk_urb (port->read_urb, serial->dev, 310 usb_fill_bulk_urb(port->read_urb, serial->dev,
307 usb_rcvbulkpipe(serial->dev, 311 usb_rcvbulkpipe(serial->dev,
308 port->bulk_in_endpointAddress), 312 port->bulk_in_endpointAddress),
309 port->read_urb->transfer_buffer, 313 port->read_urb->transfer_buffer,
@@ -318,15 +322,15 @@ static int cp2101_open (struct usb_serial_port *port, struct file *filp)
318 } 322 }
319 323
320 /* Configure the termios structure */ 324 /* Configure the termios structure */
321 cp2101_get_termios(port); 325 cp2101_get_termios(tty);
322 326
323 /* Set the DTR and RTS pins low */ 327 /* Set the DTR and RTS pins low */
324 cp2101_tiocmset(port, NULL, TIOCM_DTR | TIOCM_RTS, 0); 328 cp2101_tiocmset(tty, NULL, TIOCM_DTR | TIOCM_RTS, 0);
325 329
326 return 0; 330 return 0;
327} 331}
328 332
329static void cp2101_cleanup (struct usb_serial_port *port) 333static void cp2101_cleanup(struct usb_serial_port *port)
330{ 334{
331 struct usb_serial *serial = port->serial; 335 struct usb_serial *serial = port->serial;
332 336
@@ -341,7 +345,8 @@ static void cp2101_cleanup (struct usb_serial_port *port)
341 } 345 }
342} 346}
343 347
344static void cp2101_close (struct usb_serial_port *port, struct file * filp) 348static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port,
349 struct file *filp)
345{ 350{
346 dbg("%s - port %d", __func__, port->number); 351 dbg("%s - port %d", __func__, port->number);
347 352
@@ -362,19 +367,15 @@ static void cp2101_close (struct usb_serial_port *port, struct file * filp)
362 * from the device, corrects any unsupported values, and configures the 367 * from the device, corrects any unsupported values, and configures the
363 * termios structure to reflect the state of the device 368 * termios structure to reflect the state of the device
364 */ 369 */
365static void cp2101_get_termios (struct usb_serial_port *port) 370static void cp2101_get_termios (struct tty_struct *tty)
366{ 371{
372 struct usb_serial_port *port = tty->driver_data;
367 unsigned int cflag, modem_ctl[4]; 373 unsigned int cflag, modem_ctl[4];
368 int baud; 374 unsigned int baud;
369 int bits; 375 unsigned int bits;
370 376
371 dbg("%s - port %d", __func__, port->number); 377 dbg("%s - port %d", __func__, port->number);
372 378
373 if (!port->tty || !port->tty->termios) {
374 dbg("%s - no tty structures", __func__);
375 return;
376 }
377
378 cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2); 379 cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2);
379 /* Convert to baudrate */ 380 /* Convert to baudrate */
380 if (baud) 381 if (baud)
@@ -382,104 +383,102 @@ static void cp2101_get_termios (struct usb_serial_port *port)
382 383
383 dbg("%s - baud rate = %d", __func__, baud); 384 dbg("%s - baud rate = %d", __func__, baud);
384 385
385 tty_encode_baud_rate(port->tty, baud, baud); 386 tty_encode_baud_rate(tty, baud, baud);
386 cflag = port->tty->termios->c_cflag; 387 cflag = tty->termios->c_cflag;
387 388
388 cp2101_get_config(port, CP2101_BITS, &bits, 2); 389 cp2101_get_config(port, CP2101_BITS, &bits, 2);
389 cflag &= ~CSIZE; 390 cflag &= ~CSIZE;
390 switch(bits & BITS_DATA_MASK) { 391 switch (bits & BITS_DATA_MASK) {
391 case BITS_DATA_5: 392 case BITS_DATA_5:
392 dbg("%s - data bits = 5", __func__); 393 dbg("%s - data bits = 5", __func__);
393 cflag |= CS5; 394 cflag |= CS5;
394 break; 395 break;
395 case BITS_DATA_6: 396 case BITS_DATA_6:
396 dbg("%s - data bits = 6", __func__); 397 dbg("%s - data bits = 6", __func__);
397 cflag |= CS6; 398 cflag |= CS6;
398 break; 399 break;
399 case BITS_DATA_7: 400 case BITS_DATA_7:
400 dbg("%s - data bits = 7", __func__); 401 dbg("%s - data bits = 7", __func__);
401 cflag |= CS7; 402 cflag |= CS7;
402 break; 403 break;
403 case BITS_DATA_8: 404 case BITS_DATA_8:
404 dbg("%s - data bits = 8", __func__); 405 dbg("%s - data bits = 8", __func__);
405 cflag |= CS8; 406 cflag |= CS8;
406 break; 407 break;
407 case BITS_DATA_9: 408 case BITS_DATA_9:
408 dbg("%s - data bits = 9 (not supported, " 409 dbg("%s - data bits = 9 (not supported, using 8 data bits)",
409 "using 8 data bits)", __func__); 410 __func__);
410 cflag |= CS8; 411 cflag |= CS8;
411 bits &= ~BITS_DATA_MASK; 412 bits &= ~BITS_DATA_MASK;
412 bits |= BITS_DATA_8; 413 bits |= BITS_DATA_8;
413 cp2101_set_config(port, CP2101_BITS, &bits, 2); 414 cp2101_set_config(port, CP2101_BITS, &bits, 2);
414 break; 415 break;
415 default: 416 default:
416 dbg("%s - Unknown number of data bits, " 417 dbg("%s - Unknown number of data bits, using 8", __func__);
417 "using 8", __func__); 418 cflag |= CS8;
418 cflag |= CS8; 419 bits &= ~BITS_DATA_MASK;
419 bits &= ~BITS_DATA_MASK; 420 bits |= BITS_DATA_8;
420 bits |= BITS_DATA_8; 421 cp2101_set_config(port, CP2101_BITS, &bits, 2);
421 cp2101_set_config(port, CP2101_BITS, &bits, 2); 422 break;
422 break;
423 } 423 }
424 424
425 switch(bits & BITS_PARITY_MASK) { 425 switch (bits & BITS_PARITY_MASK) {
426 case BITS_PARITY_NONE: 426 case BITS_PARITY_NONE:
427 dbg("%s - parity = NONE", __func__); 427 dbg("%s - parity = NONE", __func__);
428 cflag &= ~PARENB; 428 cflag &= ~PARENB;
429 break; 429 break;
430 case BITS_PARITY_ODD: 430 case BITS_PARITY_ODD:
431 dbg("%s - parity = ODD", __func__); 431 dbg("%s - parity = ODD", __func__);
432 cflag |= (PARENB|PARODD); 432 cflag |= (PARENB|PARODD);
433 break; 433 break;
434 case BITS_PARITY_EVEN: 434 case BITS_PARITY_EVEN:
435 dbg("%s - parity = EVEN", __func__); 435 dbg("%s - parity = EVEN", __func__);
436 cflag &= ~PARODD; 436 cflag &= ~PARODD;
437 cflag |= PARENB; 437 cflag |= PARENB;
438 break; 438 break;
439 case BITS_PARITY_MARK: 439 case BITS_PARITY_MARK:
440 dbg("%s - parity = MARK (not supported, " 440 dbg("%s - parity = MARK (not supported, disabling parity)",
441 "disabling parity)", __func__); 441 __func__);
442 cflag &= ~PARENB; 442 cflag &= ~PARENB;
443 bits &= ~BITS_PARITY_MASK; 443 bits &= ~BITS_PARITY_MASK;
444 cp2101_set_config(port, CP2101_BITS, &bits, 2); 444 cp2101_set_config(port, CP2101_BITS, &bits, 2);
445 break; 445 break;
446 case BITS_PARITY_SPACE: 446 case BITS_PARITY_SPACE:
447 dbg("%s - parity = SPACE (not supported, " 447 dbg("%s - parity = SPACE (not supported, disabling parity)",
448 "disabling parity)", __func__); 448 __func__);
449 cflag &= ~PARENB; 449 cflag &= ~PARENB;
450 bits &= ~BITS_PARITY_MASK; 450 bits &= ~BITS_PARITY_MASK;
451 cp2101_set_config(port, CP2101_BITS, &bits, 2); 451 cp2101_set_config(port, CP2101_BITS, &bits, 2);
452 break; 452 break;
453 default: 453 default:
454 dbg("%s - Unknown parity mode, " 454 dbg("%s - Unknown parity mode, disabling parity", __func__);
455 "disabling parity", __func__); 455 cflag &= ~PARENB;
456 cflag &= ~PARENB; 456 bits &= ~BITS_PARITY_MASK;
457 bits &= ~BITS_PARITY_MASK; 457 cp2101_set_config(port, CP2101_BITS, &bits, 2);
458 cp2101_set_config(port, CP2101_BITS, &bits, 2); 458 break;
459 break;
460 } 459 }
461 460
462 cflag &= ~CSTOPB; 461 cflag &= ~CSTOPB;
463 switch(bits & BITS_STOP_MASK) { 462 switch (bits & BITS_STOP_MASK) {
464 case BITS_STOP_1: 463 case BITS_STOP_1:
465 dbg("%s - stop bits = 1", __func__); 464 dbg("%s - stop bits = 1", __func__);
466 break; 465 break;
467 case BITS_STOP_1_5: 466 case BITS_STOP_1_5:
468 dbg("%s - stop bits = 1.5 (not supported, " 467 dbg("%s - stop bits = 1.5 (not supported, using 1 stop bit)",
469 "using 1 stop bit)", __func__); 468 __func__);
470 bits &= ~BITS_STOP_MASK; 469 bits &= ~BITS_STOP_MASK;
471 cp2101_set_config(port, CP2101_BITS, &bits, 2); 470 cp2101_set_config(port, CP2101_BITS, &bits, 2);
472 break; 471 break;
473 case BITS_STOP_2: 472 case BITS_STOP_2:
474 dbg("%s - stop bits = 2", __func__); 473 dbg("%s - stop bits = 2", __func__);
475 cflag |= CSTOPB; 474 cflag |= CSTOPB;
476 break; 475 break;
477 default: 476 default:
478 dbg("%s - Unknown number of stop bits, " 477 dbg("%s - Unknown number of stop bits, using 1 stop bit",
479 "using 1 stop bit", __func__); 478 __func__);
480 bits &= ~BITS_STOP_MASK; 479 bits &= ~BITS_STOP_MASK;
481 cp2101_set_config(port, CP2101_BITS, &bits, 2); 480 cp2101_set_config(port, CP2101_BITS, &bits, 2);
482 break; 481 break;
483 } 482 }
484 483
485 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); 484 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16);
@@ -491,55 +490,53 @@ static void cp2101_get_termios (struct usb_serial_port *port)
491 cflag &= ~CRTSCTS; 490 cflag &= ~CRTSCTS;
492 } 491 }
493 492
494 port->tty->termios->c_cflag = cflag; 493 tty->termios->c_cflag = cflag;
495} 494}
496 495
497static void cp2101_set_termios (struct usb_serial_port *port, 496static void cp2101_set_termios(struct tty_struct *tty,
498 struct ktermios *old_termios) 497 struct usb_serial_port *port, struct ktermios *old_termios)
499{ 498{
500 unsigned int cflag, old_cflag; 499 unsigned int cflag, old_cflag;
501 int baud=0, bits; 500 unsigned int baud = 0, bits;
502 unsigned int modem_ctl[4]; 501 unsigned int modem_ctl[4];
503 502
504 dbg("%s - port %d", __func__, port->number); 503 dbg("%s - port %d", __func__, port->number);
505 504
506 if (!port->tty || !port->tty->termios) { 505 if (!tty)
507 dbg("%s - no tty structures", __func__);
508 return; 506 return;
509 }
510 port->tty->termios->c_cflag &= ~CMSPAR;
511 507
512 cflag = port->tty->termios->c_cflag; 508 tty->termios->c_cflag &= ~CMSPAR;
509 cflag = tty->termios->c_cflag;
513 old_cflag = old_termios->c_cflag; 510 old_cflag = old_termios->c_cflag;
514 baud = tty_get_baud_rate(port->tty); 511 baud = tty_get_baud_rate(tty);
515 512
516 /* If the baud rate is to be updated*/ 513 /* If the baud rate is to be updated*/
517 if (baud != tty_termios_baud_rate(old_termios)) { 514 if (baud != tty_termios_baud_rate(old_termios)) {
518 switch (baud) { 515 switch (baud) {
519 case 0: 516 case 0:
520 case 600: 517 case 600:
521 case 1200: 518 case 1200:
522 case 1800: 519 case 1800:
523 case 2400: 520 case 2400:
524 case 4800: 521 case 4800:
525 case 7200: 522 case 7200:
526 case 9600: 523 case 9600:
527 case 14400: 524 case 14400:
528 case 19200: 525 case 19200:
529 case 28800: 526 case 28800:
530 case 38400: 527 case 38400:
531 case 55854: 528 case 55854:
532 case 57600: 529 case 57600:
533 case 115200: 530 case 115200:
534 case 127117: 531 case 127117:
535 case 230400: 532 case 230400:
536 case 460800: 533 case 460800:
537 case 921600: 534 case 921600:
538 case 3686400: 535 case 3686400:
539 break; 536 break;
540 default: 537 default:
541 baud = 9600; 538 baud = 9600;
542 break; 539 break;
543 } 540 }
544 541
545 if (baud) { 542 if (baud) {
@@ -554,35 +551,35 @@ static void cp2101_set_termios (struct usb_serial_port *port,
554 } 551 }
555 } 552 }
556 /* Report back the resulting baud rate */ 553 /* Report back the resulting baud rate */
557 tty_encode_baud_rate(port->tty, baud, baud); 554 tty_encode_baud_rate(tty, baud, baud);
558 555
559 /* If the number of data bits is to be updated */ 556 /* If the number of data bits is to be updated */
560 if ((cflag & CSIZE) != (old_cflag & CSIZE)) { 557 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
561 cp2101_get_config(port, CP2101_BITS, &bits, 2); 558 cp2101_get_config(port, CP2101_BITS, &bits, 2);
562 bits &= ~BITS_DATA_MASK; 559 bits &= ~BITS_DATA_MASK;
563 switch (cflag & CSIZE) { 560 switch (cflag & CSIZE) {
564 case CS5: 561 case CS5:
565 bits |= BITS_DATA_5; 562 bits |= BITS_DATA_5;
566 dbg("%s - data bits = 5", __func__); 563 dbg("%s - data bits = 5", __func__);
567 break; 564 break;
568 case CS6: 565 case CS6:
569 bits |= BITS_DATA_6; 566 bits |= BITS_DATA_6;
570 dbg("%s - data bits = 6", __func__); 567 dbg("%s - data bits = 6", __func__);
571 break; 568 break;
572 case CS7: 569 case CS7:
573 bits |= BITS_DATA_7; 570 bits |= BITS_DATA_7;
574 dbg("%s - data bits = 7", __func__); 571 dbg("%s - data bits = 7", __func__);
575 break; 572 break;
576 case CS8: 573 case CS8:
577 bits |= BITS_DATA_8; 574 bits |= BITS_DATA_8;
578 dbg("%s - data bits = 8", __func__); 575 dbg("%s - data bits = 8", __func__);
579 break; 576 break;
580 /*case CS9: 577 /*case CS9:
581 bits |= BITS_DATA_9; 578 bits |= BITS_DATA_9;
582 dbg("%s - data bits = 9", __func__); 579 dbg("%s - data bits = 9", __func__);
583 break;*/ 580 break;*/
584 default: 581 default:
585 dev_err(&port->dev, "cp2101 driver does not " 582 dev_err(&port->dev, "cp2101 driver does not "
586 "support the number of bits requested," 583 "support the number of bits requested,"
587 " using 8 bit mode\n"); 584 " using 8 bit mode\n");
588 bits |= BITS_DATA_8; 585 bits |= BITS_DATA_8;
@@ -651,10 +648,11 @@ static void cp2101_set_termios (struct usb_serial_port *port,
651 648
652} 649}
653 650
654static int cp2101_tiocmset (struct usb_serial_port *port, struct file *file, 651static int cp2101_tiocmset (struct tty_struct *tty, struct file *file,
655 unsigned int set, unsigned int clear) 652 unsigned int set, unsigned int clear)
656{ 653{
657 int control = 0; 654 struct usb_serial_port *port = tty->driver_data;
655 unsigned int control = 0;
658 656
659 dbg("%s - port %d", __func__, port->number); 657 dbg("%s - port %d", __func__, port->number);
660 658
@@ -681,9 +679,11 @@ static int cp2101_tiocmset (struct usb_serial_port *port, struct file *file,
681 679
682} 680}
683 681
684static int cp2101_tiocmget (struct usb_serial_port *port, struct file *file) 682static int cp2101_tiocmget (struct tty_struct *tty, struct file *file)
685{ 683{
686 int control, result; 684 struct usb_serial_port *port = tty->driver_data;
685 unsigned int control;
686 int result;
687 687
688 dbg("%s - port %d", __func__, port->number); 688 dbg("%s - port %d", __func__, port->number);
689 689
@@ -701,9 +701,10 @@ static int cp2101_tiocmget (struct usb_serial_port *port, struct file *file)
701 return result; 701 return result;
702} 702}
703 703
704static void cp2101_break_ctl (struct usb_serial_port *port, int break_state) 704static void cp2101_break_ctl (struct tty_struct *tty, int break_state)
705{ 705{
706 int state; 706 struct usb_serial_port *port = tty->driver_data;
707 unsigned int state;
707 708
708 dbg("%s - port %d", __func__, port->number); 709 dbg("%s - port %d", __func__, port->number);
709 if (break_state == 0) 710 if (break_state == 0)
@@ -711,30 +712,29 @@ static void cp2101_break_ctl (struct usb_serial_port *port, int break_state)
711 else 712 else
712 state = BREAK_ON; 713 state = BREAK_ON;
713 dbg("%s - turning break %s", __func__, 714 dbg("%s - turning break %s", __func__,
714 state==BREAK_OFF ? "off" : "on"); 715 state == BREAK_OFF ? "off" : "on");
715 cp2101_set_config(port, CP2101_BREAK, &state, 2); 716 cp2101_set_config(port, CP2101_BREAK, &state, 2);
716} 717}
717 718
718static int cp2101_startup (struct usb_serial *serial) 719static int cp2101_startup(struct usb_serial *serial)
719{ 720{
720 /* CP2101 buffers behave strangely unless device is reset */ 721 /* CP2101 buffers behave strangely unless device is reset */
721 usb_reset_device(serial->dev); 722 usb_reset_device(serial->dev);
722 return 0; 723 return 0;
723} 724}
724 725
725static void cp2101_shutdown (struct usb_serial *serial) 726static void cp2101_shutdown(struct usb_serial *serial)
726{ 727{
727 int i; 728 int i;
728 729
729 dbg("%s", __func__); 730 dbg("%s", __func__);
730 731
731 /* Stop reads and writes on all ports */ 732 /* Stop reads and writes on all ports */
732 for (i=0; i < serial->num_ports; ++i) { 733 for (i = 0; i < serial->num_ports; ++i)
733 cp2101_cleanup(serial->port[i]); 734 cp2101_cleanup(serial->port[i]);
734 }
735} 735}
736 736
737static int __init cp2101_init (void) 737static int __init cp2101_init(void)
738{ 738{
739 int retval; 739 int retval;
740 740
@@ -754,10 +754,10 @@ static int __init cp2101_init (void)
754 return 0; 754 return 0;
755} 755}
756 756
757static void __exit cp2101_exit (void) 757static void __exit cp2101_exit(void)
758{ 758{
759 usb_deregister (&cp2101_driver); 759 usb_deregister(&cp2101_driver);
760 usb_serial_deregister (&cp2101_device); 760 usb_serial_deregister(&cp2101_device);
761} 761}
762 762
763module_init(cp2101_init); 763module_init(cp2101_init);
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index c164e2cf2752..b4d72351cb96 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -37,7 +37,7 @@
37#include <linux/tty_flip.h> 37#include <linux/tty_flip.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <asm/uaccess.h> 40#include <linux/uaccess.h>
41#include <linux/usb.h> 41#include <linux/usb.h>
42#include <linux/usb/serial.h> 42#include <linux/usb/serial.h>
43 43
@@ -57,22 +57,25 @@ static int debug;
57#define CYBERJACK_PRODUCT_ID 0x0100 57#define CYBERJACK_PRODUCT_ID 0x0100
58 58
59/* Function prototypes */ 59/* Function prototypes */
60static int cyberjack_startup (struct usb_serial *serial); 60static int cyberjack_startup(struct usb_serial *serial);
61static void cyberjack_shutdown (struct usb_serial *serial); 61static void cyberjack_shutdown(struct usb_serial *serial);
62static int cyberjack_open (struct usb_serial_port *port, struct file *filp); 62static int cyberjack_open(struct tty_struct *tty,
63static void cyberjack_close (struct usb_serial_port *port, struct file *filp); 63 struct usb_serial_port *port, struct file *filp);
64static int cyberjack_write (struct usb_serial_port *port, const unsigned char *buf, int count); 64static void cyberjack_close(struct tty_struct *tty,
65static int cyberjack_write_room( struct usb_serial_port *port ); 65 struct usb_serial_port *port, struct file *filp);
66static void cyberjack_read_int_callback (struct urb *urb); 66static int cyberjack_write(struct tty_struct *tty,
67static void cyberjack_read_bulk_callback (struct urb *urb); 67 struct usb_serial_port *port, const unsigned char *buf, int count);
68static void cyberjack_write_bulk_callback (struct urb *urb); 68static int cyberjack_write_room(struct tty_struct *tty);
69static void cyberjack_read_int_callback(struct urb *urb);
70static void cyberjack_read_bulk_callback(struct urb *urb);
71static void cyberjack_write_bulk_callback(struct urb *urb);
69 72
70static struct usb_device_id id_table [] = { 73static struct usb_device_id id_table [] = {
71 { USB_DEVICE(CYBERJACK_VENDOR_ID, CYBERJACK_PRODUCT_ID) }, 74 { USB_DEVICE(CYBERJACK_VENDOR_ID, CYBERJACK_PRODUCT_ID) },
72 { } /* Terminating entry */ 75 { } /* Terminating entry */
73}; 76};
74 77
75MODULE_DEVICE_TABLE (usb, id_table); 78MODULE_DEVICE_TABLE(usb, id_table);
76 79
77static struct usb_driver cyberjack_driver = { 80static struct usb_driver cyberjack_driver = {
78 .name = "cyberjack", 81 .name = "cyberjack",
@@ -111,7 +114,7 @@ struct cyberjack_private {
111}; 114};
112 115
113/* do some startup allocations not currently performed by usb_serial_probe() */ 116/* do some startup allocations not currently performed by usb_serial_probe() */
114static int cyberjack_startup (struct usb_serial *serial) 117static int cyberjack_startup(struct usb_serial *serial)
115{ 118{
116 struct cyberjack_private *priv; 119 struct cyberjack_private *priv;
117 int i; 120 int i;
@@ -135,20 +138,20 @@ static int cyberjack_startup (struct usb_serial *serial)
135 for (i = 0; i < serial->num_ports; ++i) { 138 for (i = 0; i < serial->num_ports; ++i) {
136 int result; 139 int result;
137 serial->port[i]->interrupt_in_urb->dev = serial->dev; 140 serial->port[i]->interrupt_in_urb->dev = serial->dev;
138 result = usb_submit_urb(serial->port[i]->interrupt_in_urb, 141 result = usb_submit_urb(serial->port[i]->interrupt_in_urb,
139 GFP_KERNEL); 142 GFP_KERNEL);
140 if (result) 143 if (result)
141 err(" usb_submit_urb(read int) failed"); 144 err(" usb_submit_urb(read int) failed");
142 dbg("%s - usb_submit_urb(int urb)", __func__); 145 dbg("%s - usb_submit_urb(int urb)", __func__);
143 } 146 }
144 147
145 return( 0 ); 148 return 0;
146} 149}
147 150
148static void cyberjack_shutdown (struct usb_serial *serial) 151static void cyberjack_shutdown(struct usb_serial *serial)
149{ 152{
150 int i; 153 int i;
151 154
152 dbg("%s", __func__); 155 dbg("%s", __func__);
153 156
154 for (i = 0; i < serial->num_ports; ++i) { 157 for (i = 0; i < serial->num_ports; ++i) {
@@ -158,8 +161,9 @@ static void cyberjack_shutdown (struct usb_serial *serial)
158 usb_set_serial_port_data(serial->port[i], NULL); 161 usb_set_serial_port_data(serial->port[i], NULL);
159 } 162 }
160} 163}
161 164
162static int cyberjack_open (struct usb_serial_port *port, struct file *filp) 165static int cyberjack_open(struct tty_struct *tty,
166 struct usb_serial_port *port, struct file *filp)
163{ 167{
164 struct cyberjack_private *priv; 168 struct cyberjack_private *priv;
165 unsigned long flags; 169 unsigned long flags;
@@ -167,14 +171,15 @@ static int cyberjack_open (struct usb_serial_port *port, struct file *filp)
167 171
168 dbg("%s - port %d", __func__, port->number); 172 dbg("%s - port %d", __func__, port->number);
169 173
170 dbg("%s - usb_clear_halt", __func__ ); 174 dbg("%s - usb_clear_halt", __func__);
171 usb_clear_halt(port->serial->dev, port->write_urb->pipe); 175 usb_clear_halt(port->serial->dev, port->write_urb->pipe);
172 176
173 /* force low_latency on so that our tty_push actually forces 177 /* force low_latency on so that our tty_push actually forces
174 * the data through, otherwise it is scheduled, and with high 178 * the data through, otherwise it is scheduled, and with high
175 * data rates (like with OHCI) data can get lost. 179 * data rates (like with OHCI) data can get lost.
176 */ 180 */
177 port->tty->low_latency = 1; 181 if (tty)
182 tty->low_latency = 1;
178 183
179 priv = usb_get_serial_port_data(port); 184 priv = usb_get_serial_port_data(port);
180 spin_lock_irqsave(&priv->lock, flags); 185 spin_lock_irqsave(&priv->lock, flags);
@@ -186,7 +191,8 @@ static int cyberjack_open (struct usb_serial_port *port, struct file *filp)
186 return result; 191 return result;
187} 192}
188 193
189static void cyberjack_close (struct usb_serial_port *port, struct file *filp) 194static void cyberjack_close(struct tty_struct *tty,
195 struct usb_serial_port *port, struct file *filp)
190{ 196{
191 dbg("%s - port %d", __func__, port->number); 197 dbg("%s - port %d", __func__, port->number);
192 198
@@ -197,7 +203,8 @@ static void cyberjack_close (struct usb_serial_port *port, struct file *filp)
197 } 203 }
198} 204}
199 205
200static int cyberjack_write (struct usb_serial_port *port, const unsigned char *buf, int count) 206static int cyberjack_write(struct tty_struct *tty,
207 struct usb_serial_port *port, const unsigned char *buf, int count)
201{ 208{
202 struct usb_serial *serial = port->serial; 209 struct usb_serial *serial = port->serial;
203 struct cyberjack_private *priv = usb_get_serial_port_data(port); 210 struct cyberjack_private *priv = usb_get_serial_port_data(port);
@@ -223,7 +230,7 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
223 230
224 spin_lock_irqsave(&priv->lock, flags); 231 spin_lock_irqsave(&priv->lock, flags);
225 232
226 if( (count+priv->wrfilled) > sizeof(priv->wrbuf) ) { 233 if (count+priv->wrfilled > sizeof(priv->wrbuf)) {
227 /* To much data for buffer. Reset buffer. */ 234 /* To much data for buffer. Reset buffer. */
228 priv->wrfilled = 0; 235 priv->wrfilled = 0;
229 port->write_urb_busy = 0; 236 port->write_urb_busy = 0;
@@ -232,42 +239,43 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
232 } 239 }
233 240
234 /* Copy data */ 241 /* Copy data */
235 memcpy (priv->wrbuf+priv->wrfilled, buf, count); 242 memcpy(priv->wrbuf + priv->wrfilled, buf, count);
236 243
237 usb_serial_debug_data(debug, &port->dev, __func__, count, 244 usb_serial_debug_data(debug, &port->dev, __func__, count,
238 priv->wrbuf+priv->wrfilled); 245 priv->wrbuf + priv->wrfilled);
239 priv->wrfilled += count; 246 priv->wrfilled += count;
240 247
241 if( priv->wrfilled >= 3 ) { 248 if (priv->wrfilled >= 3) {
242 wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; 249 wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
243 dbg("%s - expected data: %d", __func__, wrexpected); 250 dbg("%s - expected data: %d", __func__, wrexpected);
244 } else { 251 } else
245 wrexpected = sizeof(priv->wrbuf); 252 wrexpected = sizeof(priv->wrbuf);
246 }
247 253
248 if( priv->wrfilled >= wrexpected ) { 254 if (priv->wrfilled >= wrexpected) {
249 /* We have enough data to begin transmission */ 255 /* We have enough data to begin transmission */
250 int length; 256 int length;
251 257
252 dbg("%s - transmitting data (frame 1)", __func__); 258 dbg("%s - transmitting data (frame 1)", __func__);
253 length = (wrexpected > port->bulk_out_size) ? port->bulk_out_size : wrexpected; 259 length = (wrexpected > port->bulk_out_size) ?
260 port->bulk_out_size : wrexpected;
254 261
255 memcpy (port->write_urb->transfer_buffer, priv->wrbuf, length ); 262 memcpy(port->write_urb->transfer_buffer, priv->wrbuf, length);
256 priv->wrsent=length; 263 priv->wrsent = length;
257 264
258 /* set up our urb */ 265 /* set up our urb */
259 usb_fill_bulk_urb(port->write_urb, serial->dev, 266 usb_fill_bulk_urb(port->write_urb, serial->dev,
260 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress), 267 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
261 port->write_urb->transfer_buffer, length, 268 port->write_urb->transfer_buffer, length,
262 ((serial->type->write_bulk_callback) ? 269 ((serial->type->write_bulk_callback) ?
263 serial->type->write_bulk_callback : 270 serial->type->write_bulk_callback :
264 cyberjack_write_bulk_callback), 271 cyberjack_write_bulk_callback),
265 port); 272 port);
266 273
267 /* send the data out the bulk port */ 274 /* send the data out the bulk port */
268 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 275 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
269 if (result) { 276 if (result) {
270 err("%s - failed submitting write urb, error %d", __func__, result); 277 err("%s - failed submitting write urb, error %d",
278 __func__, result);
271 /* Throw away data. No better idea what to do with it. */ 279 /* Throw away data. No better idea what to do with it. */
272 priv->wrfilled = 0; 280 priv->wrfilled = 0;
273 priv->wrsent = 0; 281 priv->wrsent = 0;
@@ -276,12 +284,12 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
276 return 0; 284 return 0;
277 } 285 }
278 286
279 dbg("%s - priv->wrsent=%d", __func__,priv->wrsent); 287 dbg("%s - priv->wrsent=%d", __func__, priv->wrsent);
280 dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled); 288 dbg("%s - priv->wrfilled=%d", __func__, priv->wrfilled);
281 289
282 if( priv->wrsent>=priv->wrfilled ) { 290 if (priv->wrsent >= priv->wrfilled) {
283 dbg("%s - buffer cleaned", __func__); 291 dbg("%s - buffer cleaned", __func__);
284 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); 292 memset(priv->wrbuf, 0, sizeof(priv->wrbuf));
285 priv->wrfilled = 0; 293 priv->wrfilled = 0;
286 priv->wrsent = 0; 294 priv->wrsent = 0;
287 } 295 }
@@ -289,16 +297,16 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
289 297
290 spin_unlock_irqrestore(&priv->lock, flags); 298 spin_unlock_irqrestore(&priv->lock, flags);
291 299
292 return (count); 300 return count;
293} 301}
294 302
295static int cyberjack_write_room( struct usb_serial_port *port ) 303static int cyberjack_write_room(struct tty_struct *tty)
296{ 304{
297 /* FIXME: .... */ 305 /* FIXME: .... */
298 return CYBERJACK_LOCAL_BUF_SIZE; 306 return CYBERJACK_LOCAL_BUF_SIZE;
299} 307}
300 308
301static void cyberjack_read_int_callback( struct urb *urb ) 309static void cyberjack_read_int_callback(struct urb *urb)
302{ 310{
303 struct usb_serial_port *port = urb->context; 311 struct usb_serial_port *port = urb->context;
304 struct cyberjack_private *priv = usb_get_serial_port_data(port); 312 struct cyberjack_private *priv = usb_get_serial_port_data(port);
@@ -312,10 +320,11 @@ static void cyberjack_read_int_callback( struct urb *urb )
312 if (status) 320 if (status)
313 return; 321 return;
314 322
315 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 323 usb_serial_debug_data(debug, &port->dev, __func__,
324 urb->actual_length, data);
316 325
317 /* React only to interrupts signaling a bulk_in transfer */ 326 /* React only to interrupts signaling a bulk_in transfer */
318 if( (urb->actual_length == 4) && (data[0] == 0x01) ) { 327 if (urb->actual_length == 4 && data[0] == 0x01) {
319 short old_rdtodo; 328 short old_rdtodo;
320 329
321 /* This is a announcement of coming bulk_ins. */ 330 /* This is a announcement of coming bulk_ins. */
@@ -325,8 +334,8 @@ static void cyberjack_read_int_callback( struct urb *urb )
325 334
326 old_rdtodo = priv->rdtodo; 335 old_rdtodo = priv->rdtodo;
327 336
328 if( (old_rdtodo+size)<(old_rdtodo) ) { 337 if (old_rdtodo + size < old_rdtodo) {
329 dbg( "To many bulk_in urbs to do." ); 338 dbg("To many bulk_in urbs to do.");
330 spin_unlock(&priv->lock); 339 spin_unlock(&priv->lock);
331 goto resubmit; 340 goto resubmit;
332 } 341 }
@@ -338,10 +347,10 @@ static void cyberjack_read_int_callback( struct urb *urb )
338 347
339 spin_unlock(&priv->lock); 348 spin_unlock(&priv->lock);
340 349
341 if( !old_rdtodo ) { 350 if (!old_rdtodo) {
342 port->read_urb->dev = port->serial->dev; 351 port->read_urb->dev = port->serial->dev;
343 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 352 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
344 if( result ) 353 if (result)
345 err("%s - failed resubmitting read urb, error %d", __func__, result); 354 err("%s - failed resubmitting read urb, error %d", __func__, result);
346 dbg("%s - usb_submit_urb(read urb)", __func__); 355 dbg("%s - usb_submit_urb(read urb)", __func__);
347 } 356 }
@@ -355,7 +364,7 @@ resubmit:
355 dbg("%s - usb_submit_urb(int urb)", __func__); 364 dbg("%s - usb_submit_urb(int urb)", __func__);
356} 365}
357 366
358static void cyberjack_read_bulk_callback (struct urb *urb) 367static void cyberjack_read_bulk_callback(struct urb *urb)
359{ 368{
360 struct usb_serial_port *port = urb->context; 369 struct usb_serial_port *port = urb->context;
361 struct cyberjack_private *priv = usb_get_serial_port_data(port); 370 struct cyberjack_private *priv = usb_get_serial_port_data(port);
@@ -367,14 +376,15 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
367 376
368 dbg("%s - port %d", __func__, port->number); 377 dbg("%s - port %d", __func__, port->number);
369 378
370 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 379 usb_serial_debug_data(debug, &port->dev, __func__,
380 urb->actual_length, data);
371 if (status) { 381 if (status) {
372 dbg("%s - nonzero read bulk status received: %d", 382 dbg("%s - nonzero read bulk status received: %d",
373 __func__, status); 383 __func__, status);
374 return; 384 return;
375 } 385 }
376 386
377 tty = port->tty; 387 tty = port->port.tty;
378 if (!tty) { 388 if (!tty) {
379 dbg("%s - ignoring since device not open\n", __func__); 389 dbg("%s - ignoring since device not open\n", __func__);
380 return; 390 return;
@@ -382,15 +392,16 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
382 if (urb->actual_length) { 392 if (urb->actual_length) {
383 tty_buffer_request_room(tty, urb->actual_length); 393 tty_buffer_request_room(tty, urb->actual_length);
384 tty_insert_flip_string(tty, data, urb->actual_length); 394 tty_insert_flip_string(tty, data, urb->actual_length);
385 tty_flip_buffer_push(tty); 395 tty_flip_buffer_push(tty);
386 } 396 }
387 397
388 spin_lock(&priv->lock); 398 spin_lock(&priv->lock);
389 399
390 /* Reduce urbs to do by one. */ 400 /* Reduce urbs to do by one. */
391 priv->rdtodo-=urb->actual_length; 401 priv->rdtodo -= urb->actual_length;
392 /* Just to be sure */ 402 /* Just to be sure */
393 if ( priv->rdtodo<0 ) priv->rdtodo = 0; 403 if (priv->rdtodo < 0)
404 priv->rdtodo = 0;
394 todo = priv->rdtodo; 405 todo = priv->rdtodo;
395 406
396 spin_unlock(&priv->lock); 407 spin_unlock(&priv->lock);
@@ -398,16 +409,17 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
398 dbg("%s - rdtodo: %d", __func__, todo); 409 dbg("%s - rdtodo: %d", __func__, todo);
399 410
400 /* Continue to read if we have still urbs to do. */ 411 /* Continue to read if we have still urbs to do. */
401 if( todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/ ) { 412 if (todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/) {
402 port->read_urb->dev = port->serial->dev; 413 port->read_urb->dev = port->serial->dev;
403 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 414 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
404 if (result) 415 if (result)
405 err("%s - failed resubmitting read urb, error %d", __func__, result); 416 err("%s - failed resubmitting read urb, error %d",
417 __func__, result);
406 dbg("%s - usb_submit_urb(read urb)", __func__); 418 dbg("%s - usb_submit_urb(read urb)", __func__);
407 } 419 }
408} 420}
409 421
410static void cyberjack_write_bulk_callback (struct urb *urb) 422static void cyberjack_write_bulk_callback(struct urb *urb)
411{ 423{
412 struct usb_serial_port *port = urb->context; 424 struct usb_serial_port *port = urb->context;
413 struct cyberjack_private *priv = usb_get_serial_port_data(port); 425 struct cyberjack_private *priv = usb_get_serial_port_data(port);
@@ -425,7 +437,7 @@ static void cyberjack_write_bulk_callback (struct urb *urb)
425 spin_lock(&priv->lock); 437 spin_lock(&priv->lock);
426 438
427 /* only do something if we have more data to send */ 439 /* only do something if we have more data to send */
428 if( priv->wrfilled ) { 440 if (priv->wrfilled) {
429 int length, blksize, result; 441 int length, blksize, result;
430 442
431 dbg("%s - transmitting data (frame n)", __func__); 443 dbg("%s - transmitting data (frame n)", __func__);
@@ -433,37 +445,39 @@ static void cyberjack_write_bulk_callback (struct urb *urb)
433 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ? 445 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ?
434 port->bulk_out_size : (priv->wrfilled - priv->wrsent); 446 port->bulk_out_size : (priv->wrfilled - priv->wrsent);
435 447
436 memcpy (port->write_urb->transfer_buffer, priv->wrbuf + priv->wrsent, 448 memcpy(port->write_urb->transfer_buffer,
437 length ); 449 priv->wrbuf + priv->wrsent, length);
438 priv->wrsent+=length; 450 priv->wrsent += length;
439 451
440 /* set up our urb */ 452 /* set up our urb */
441 usb_fill_bulk_urb(port->write_urb, port->serial->dev, 453 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
442 usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), 454 usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress),
443 port->write_urb->transfer_buffer, length, 455 port->write_urb->transfer_buffer, length,
444 ((port->serial->type->write_bulk_callback) ? 456 ((port->serial->type->write_bulk_callback) ?
445 port->serial->type->write_bulk_callback : 457 port->serial->type->write_bulk_callback :
446 cyberjack_write_bulk_callback), 458 cyberjack_write_bulk_callback),
447 port); 459 port);
448 460
449 /* send the data out the bulk port */ 461 /* send the data out the bulk port */
450 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 462 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
451 if (result) { 463 if (result) {
452 err("%s - failed submitting write urb, error %d", __func__, result); 464 err("%s - failed submitting write urb, error %d",
465 __func__, result);
453 /* Throw away data. No better idea what to do with it. */ 466 /* Throw away data. No better idea what to do with it. */
454 priv->wrfilled = 0; 467 priv->wrfilled = 0;
455 priv->wrsent = 0; 468 priv->wrsent = 0;
456 goto exit; 469 goto exit;
457 } 470 }
458 471
459 dbg("%s - priv->wrsent=%d", __func__,priv->wrsent); 472 dbg("%s - priv->wrsent=%d", __func__, priv->wrsent);
460 dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled); 473 dbg("%s - priv->wrfilled=%d", __func__, priv->wrfilled);
461 474
462 blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; 475 blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
463 476
464 if( (priv->wrsent>=priv->wrfilled) || (priv->wrsent>=blksize) ) { 477 if (priv->wrsent >= priv->wrfilled ||
478 priv->wrsent >= blksize) {
465 dbg("%s - buffer cleaned", __func__); 479 dbg("%s - buffer cleaned", __func__);
466 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); 480 memset(priv->wrbuf, 0, sizeof(priv->wrbuf));
467 priv->wrfilled = 0; 481 priv->wrfilled = 0;
468 priv->wrsent = 0; 482 priv->wrsent = 0;
469 } 483 }
@@ -474,14 +488,14 @@ exit:
474 usb_serial_port_softint(port); 488 usb_serial_port_softint(port);
475} 489}
476 490
477static int __init cyberjack_init (void) 491static int __init cyberjack_init(void)
478{ 492{
479 int retval; 493 int retval;
480 retval = usb_serial_register(&cyberjack_device); 494 retval = usb_serial_register(&cyberjack_device);
481 if (retval) 495 if (retval)
482 goto failed_usb_serial_register; 496 goto failed_usb_serial_register;
483 retval = usb_register(&cyberjack_driver); 497 retval = usb_register(&cyberjack_driver);
484 if (retval) 498 if (retval)
485 goto failed_usb_register; 499 goto failed_usb_register;
486 500
487 info(DRIVER_VERSION " " DRIVER_AUTHOR); 501 info(DRIVER_VERSION " " DRIVER_AUTHOR);
@@ -494,18 +508,18 @@ failed_usb_serial_register:
494 return retval; 508 return retval;
495} 509}
496 510
497static void __exit cyberjack_exit (void) 511static void __exit cyberjack_exit(void)
498{ 512{
499 usb_deregister (&cyberjack_driver); 513 usb_deregister(&cyberjack_driver);
500 usb_serial_deregister (&cyberjack_device); 514 usb_serial_deregister(&cyberjack_device);
501} 515}
502 516
503module_init(cyberjack_init); 517module_init(cyberjack_init);
504module_exit(cyberjack_exit); 518module_exit(cyberjack_exit);
505 519
506MODULE_AUTHOR( DRIVER_AUTHOR ); 520MODULE_AUTHOR(DRIVER_AUTHOR);
507MODULE_DESCRIPTION( DRIVER_DESC ); 521MODULE_DESCRIPTION(DRIVER_DESC);
508MODULE_VERSION( DRIVER_VERSION ); 522MODULE_VERSION(DRIVER_VERSION);
509MODULE_LICENSE("GPL"); 523MODULE_LICENSE("GPL");
510 524
511module_param(debug, bool, S_IRUGO | S_IWUSR); 525module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 0230d3c0888a..22837a3f2f89 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -2,7 +2,7 @@
2 * USB Cypress M8 driver 2 * USB Cypress M8 driver
3 * 3 *
4 * Copyright (C) 2004 4 * Copyright (C) 2004
5 * Lonnie Mendez (dignome@gmail.com) 5 * Lonnie Mendez (dignome@gmail.com)
6 * Copyright (C) 2003,2004 6 * Copyright (C) 2003,2004
7 * Neil Whelchel (koyama@firstlight.net) 7 * Neil Whelchel (koyama@firstlight.net)
8 * 8 *
@@ -11,19 +11,21 @@
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version. 12 * (at your option) any later version.
13 * 13 *
14 * See Documentation/usb/usb-serial.txt for more information on using this driver 14 * See Documentation/usb/usb-serial.txt for more information on using this
15 * driver
15 * 16 *
16 * See http://geocities.com/i0xox0i for information on this driver and the 17 * See http://geocities.com/i0xox0i for information on this driver and the
17 * earthmate usb device. 18 * earthmate usb device.
18 * 19 *
19 * Lonnie Mendez <dignome@gmail.com> 20 * Lonnie Mendez <dignome@gmail.com>
20 * 4-29-2005 21 * 4-29-2005
21 * Fixed problem where setting or retreiving the serial config would fail with 22 * Fixed problem where setting or retreiving the serial config would fail
22 * EPIPE. Removed CRTS toggling so the driver behaves more like other usbserial 23 * with EPIPE. Removed CRTS toggling so the driver behaves more like
23 * adapters. Issued new interval of 1ms instead of the default 10ms. As a 24 * other usbserial adapters. Issued new interval of 1ms instead of the
24 * result, transfer speed has been substantially increased. From avg. 850bps to 25 * default 10ms. As a result, transfer speed has been substantially
25 * avg. 3300bps. initial termios has also been modified. Cleaned up code and 26 * increased from avg. 850bps to avg. 3300bps. initial termios has also
26 * formatting issues so it is more readable. Replaced the C++ style comments. 27 * been modified. Cleaned up code and formatting issues so it is more
28 * readable. Replaced the C++ style comments.
27 * 29 *
28 * Lonnie Mendez <dignome@gmail.com> 30 * Lonnie Mendez <dignome@gmail.com>
29 * 12-15-2004 31 * 12-15-2004
@@ -42,10 +44,11 @@
42 * 44 *
43 */ 45 */
44 46
45/* Thanks to Neil Whelchel for writing the first cypress m8 implementation for linux. */ 47/* Thanks to Neil Whelchel for writing the first cypress m8 implementation
48 for linux. */
46/* Thanks to cypress for providing references for the hid reports. */ 49/* Thanks to cypress for providing references for the hid reports. */
47/* Thanks to Jiang Zhang for providing links and for general help. */ 50/* Thanks to Jiang Zhang for providing links and for general help. */
48/* Code originates and was built up from ftdi_sio, belkin, pl2303 and others. */ 51/* Code originates and was built up from ftdi_sio, belkin, pl2303 and others.*/
49 52
50 53
51#include <linux/kernel.h> 54#include <linux/kernel.h>
@@ -62,7 +65,7 @@
62#include <linux/usb/serial.h> 65#include <linux/usb/serial.h>
63#include <linux/serial.h> 66#include <linux/serial.h>
64#include <linux/delay.h> 67#include <linux/delay.h>
65#include <asm/uaccess.h> 68#include <linux/uaccess.h>
66 69
67#include "cypress_m8.h" 70#include "cypress_m8.h"
68 71
@@ -112,7 +115,7 @@ static struct usb_device_id id_table_combined [] = {
112 { } /* Terminating entry */ 115 { } /* Terminating entry */
113}; 116};
114 117
115MODULE_DEVICE_TABLE (usb, id_table_combined); 118MODULE_DEVICE_TABLE(usb, id_table_combined);
116 119
117static struct usb_driver cypress_driver = { 120static struct usb_driver cypress_driver = {
118 .name = "cypress", 121 .name = "cypress",
@@ -146,11 +149,13 @@ struct cypress_private {
146 __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */ 149 __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */
147 enum packet_format pkt_fmt; /* format to use for packet send / receive */ 150 enum packet_format pkt_fmt; /* format to use for packet send / receive */
148 int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */ 151 int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */
149 int baud_rate; /* stores current baud rate in integer form */ 152 int baud_rate; /* stores current baud rate in
153 integer form */
150 int isthrottled; /* if throttled, discard reads */ 154 int isthrottled; /* if throttled, discard reads */
151 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */ 155 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */
152 char prev_status, diff_status; /* used for TIOCMIWAIT */ 156 char prev_status, diff_status; /* used for TIOCMIWAIT */
153 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */ 157 /* we pass a pointer to this as the arguement sent to
158 cypress_set_termios old_termios */
154 struct ktermios tmp_termios; /* stores the old termios settings */ 159 struct ktermios tmp_termios; /* stores the old termios settings */
155}; 160};
156 161
@@ -163,33 +168,41 @@ struct cypress_buf {
163}; 168};
164 169
165/* function prototypes for the Cypress USB to serial device */ 170/* function prototypes for the Cypress USB to serial device */
166static int cypress_earthmate_startup (struct usb_serial *serial); 171static int cypress_earthmate_startup(struct usb_serial *serial);
167static int cypress_hidcom_startup (struct usb_serial *serial); 172static int cypress_hidcom_startup(struct usb_serial *serial);
168static int cypress_ca42v2_startup (struct usb_serial *serial); 173static int cypress_ca42v2_startup(struct usb_serial *serial);
169static void cypress_shutdown (struct usb_serial *serial); 174static void cypress_shutdown(struct usb_serial *serial);
170static int cypress_open (struct usb_serial_port *port, struct file *filp); 175static int cypress_open(struct tty_struct *tty,
171static void cypress_close (struct usb_serial_port *port, struct file *filp); 176 struct usb_serial_port *port, struct file *filp);
172static int cypress_write (struct usb_serial_port *port, const unsigned char *buf, int count); 177static void cypress_close(struct tty_struct *tty,
173static void cypress_send (struct usb_serial_port *port); 178 struct usb_serial_port *port, struct file *filp);
174static int cypress_write_room (struct usb_serial_port *port); 179static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
175static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 180 const unsigned char *buf, int count);
176static void cypress_set_termios (struct usb_serial_port *port, struct ktermios * old); 181static void cypress_send(struct usb_serial_port *port);
177static int cypress_tiocmget (struct usb_serial_port *port, struct file *file); 182static int cypress_write_room(struct tty_struct *tty);
178static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); 183static int cypress_ioctl(struct tty_struct *tty, struct file *file,
179static int cypress_chars_in_buffer (struct usb_serial_port *port); 184 unsigned int cmd, unsigned long arg);
180static void cypress_throttle (struct usb_serial_port *port); 185static void cypress_set_termios(struct tty_struct *tty,
181static void cypress_unthrottle (struct usb_serial_port *port); 186 struct usb_serial_port *port, struct ktermios *old);
182static void cypress_set_dead (struct usb_serial_port *port); 187static int cypress_tiocmget(struct tty_struct *tty, struct file *file);
183static void cypress_read_int_callback (struct urb *urb); 188static int cypress_tiocmset(struct tty_struct *tty, struct file *file,
184static void cypress_write_int_callback (struct urb *urb); 189 unsigned int set, unsigned int clear);
190static int cypress_chars_in_buffer(struct tty_struct *tty);
191static void cypress_throttle(struct tty_struct *tty);
192static void cypress_unthrottle(struct tty_struct *tty);
193static void cypress_set_dead(struct usb_serial_port *port);
194static void cypress_read_int_callback(struct urb *urb);
195static void cypress_write_int_callback(struct urb *urb);
185/* write buffer functions */ 196/* write buffer functions */
186static struct cypress_buf *cypress_buf_alloc(unsigned int size); 197static struct cypress_buf *cypress_buf_alloc(unsigned int size);
187static void cypress_buf_free(struct cypress_buf *cb); 198static void cypress_buf_free(struct cypress_buf *cb);
188static void cypress_buf_clear(struct cypress_buf *cb); 199static void cypress_buf_clear(struct cypress_buf *cb);
189static unsigned int cypress_buf_data_avail(struct cypress_buf *cb); 200static unsigned int cypress_buf_data_avail(struct cypress_buf *cb);
190static unsigned int cypress_buf_space_avail(struct cypress_buf *cb); 201static unsigned int cypress_buf_space_avail(struct cypress_buf *cb);
191static unsigned int cypress_buf_put(struct cypress_buf *cb, const char *buf, unsigned int count); 202static unsigned int cypress_buf_put(struct cypress_buf *cb,
192static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf, unsigned int count); 203 const char *buf, unsigned int count);
204static unsigned int cypress_buf_get(struct cypress_buf *cb,
205 char *buf, unsigned int count);
193 206
194 207
195static struct usb_serial_driver cypress_earthmate_device = { 208static struct usb_serial_driver cypress_earthmate_device = {
@@ -247,7 +260,7 @@ static struct usb_serial_driver cypress_hidcom_device = {
247static struct usb_serial_driver cypress_ca42v2_device = { 260static struct usb_serial_driver cypress_ca42v2_device = {
248 .driver = { 261 .driver = {
249 .owner = THIS_MODULE, 262 .owner = THIS_MODULE,
250 .name = "nokiaca42v2", 263 .name = "nokiaca42v2",
251 }, 264 },
252 .description = "Nokia CA-42 V2 Adapter", 265 .description = "Nokia CA-42 V2 Adapter",
253 .usb_driver = &cypress_driver, 266 .usb_driver = &cypress_driver,
@@ -322,8 +335,10 @@ static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate)
322 335
323 336
324/* This function can either set or retrieve the current serial line settings */ 337/* This function can either set or retrieve the current serial line settings */
325static int cypress_serial_control (struct usb_serial_port *port, speed_t baud_rate, int data_bits, int stop_bits, 338static int cypress_serial_control(struct tty_struct *tty,
326 int parity_enable, int parity_type, int reset, int cypress_request_type) 339 struct usb_serial_port *port, speed_t baud_rate, int data_bits,
340 int stop_bits, int parity_enable, int parity_type, int reset,
341 int cypress_request_type)
327{ 342{
328 int new_baudrate = 0, retval = 0, tries = 0; 343 int new_baudrate = 0, retval = 0, tries = 0;
329 struct cypress_private *priv; 344 struct cypress_private *priv;
@@ -331,111 +346,114 @@ static int cypress_serial_control (struct usb_serial_port *port, speed_t baud_ra
331 unsigned long flags; 346 unsigned long flags;
332 347
333 dbg("%s", __func__); 348 dbg("%s", __func__);
334 349
335 priv = usb_get_serial_port_data(port); 350 priv = usb_get_serial_port_data(port);
336 351
337 if (!priv->comm_is_ok) 352 if (!priv->comm_is_ok)
338 return -ENODEV; 353 return -ENODEV;
339 354
340 switch(cypress_request_type) { 355 switch (cypress_request_type) {
341 case CYPRESS_SET_CONFIG: 356 case CYPRESS_SET_CONFIG:
357 new_baudrate = priv->baud_rate;
358 /* 0 means 'Hang up' so doesn't change the true bit rate */
359 if (baud_rate == 0)
342 new_baudrate = priv->baud_rate; 360 new_baudrate = priv->baud_rate;
343 /* 0 means 'Hang up' so doesn't change the true bit rate */ 361 /* Change of speed ? */
344 if (baud_rate == 0) 362 else if (baud_rate != priv->baud_rate) {
345 new_baudrate = priv->baud_rate; 363 dbg("%s - baud rate is changing", __func__);
346 /* Change of speed ? */ 364 retval = analyze_baud_rate(port, baud_rate);
347 else if (baud_rate != priv->baud_rate) { 365 if (retval >= 0) {
348 dbg("%s - baud rate is changing", __func__); 366 new_baudrate = retval;
349 retval = analyze_baud_rate(port, baud_rate); 367 dbg("%s - New baud rate set to %d",
350 if (retval >= 0) { 368 __func__, new_baudrate);
351 new_baudrate = retval;
352 dbg("%s - New baud rate set to %d",
353 __func__, new_baudrate);
354 }
355 }
356 dbg("%s - baud rate is being sent as %d", __func__, new_baudrate);
357
358 memset(feature_buffer, 0, sizeof(feature_buffer));
359 /* fill the feature_buffer with new configuration */
360 *((u_int32_t *)feature_buffer) = new_baudrate;
361
362 feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */
363 /* 1 bit gap */
364 feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */
365 feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */
366 feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */
367 /* 1 bit gap */
368 feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
369
370 dbg("%s - device is being sent this feature report:", __func__);
371 dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__, feature_buffer[0], feature_buffer[1],
372 feature_buffer[2], feature_buffer[3], feature_buffer[4]);
373
374 do {
375 retval = usb_control_msg(port->serial->dev,
376 usb_sndctrlpipe(port->serial->dev, 0),
377 HID_REQ_SET_REPORT,
378 USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
379 0x0300, 0, feature_buffer,
380 sizeof(feature_buffer), 500);
381
382 if (tries++ >= 3)
383 break;
384
385 } while (retval != sizeof(feature_buffer) &&
386 retval != -ENODEV);
387
388 if (retval != sizeof(feature_buffer)) {
389 err("%s - failed sending serial line settings - %d", __func__, retval);
390 cypress_set_dead(port);
391 } else {
392 spin_lock_irqsave(&priv->lock, flags);
393 priv->baud_rate = new_baudrate;
394 priv->current_config = feature_buffer[4];
395 spin_unlock_irqrestore(&priv->lock, flags);
396 /* If we asked for a speed change encode it */
397 if (baud_rate)
398 tty_encode_baud_rate(port->tty,
399 new_baudrate, new_baudrate);
400 }
401 break;
402 case CYPRESS_GET_CONFIG:
403 if (priv->get_cfg_unsafe) {
404 /* Not implemented for this device,
405 and if we try to do it we're likely
406 to crash the hardware. */
407 return -ENOTTY;
408 }
409 dbg("%s - retreiving serial line settings", __func__);
410 /* set initial values in feature buffer */
411 memset(feature_buffer, 0, sizeof(feature_buffer));
412
413 do {
414 retval = usb_control_msg(port->serial->dev,
415 usb_rcvctrlpipe(port->serial->dev, 0),
416 HID_REQ_GET_REPORT,
417 USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
418 0x0300, 0, feature_buffer,
419 sizeof(feature_buffer), 500);
420
421 if (tries++ >= 3)
422 break;
423
424 } while (retval != sizeof(feature_buffer) &&
425 retval != -ENODEV);
426
427 if (retval != sizeof(feature_buffer)) {
428 err("%s - failed to retrieve serial line settings - %d", __func__, retval);
429 cypress_set_dead(port);
430 return retval;
431 } else {
432 spin_lock_irqsave(&priv->lock, flags);
433
434 /* store the config in one byte, and later use bit masks to check values */
435 priv->current_config = feature_buffer[4];
436 priv->baud_rate = *((u_int32_t *)feature_buffer);
437 spin_unlock_irqrestore(&priv->lock, flags);
438 } 369 }
370 }
371 dbg("%s - baud rate is being sent as %d",
372 __func__, new_baudrate);
373
374 memset(feature_buffer, 0, sizeof(feature_buffer));
375 /* fill the feature_buffer with new configuration */
376 *((u_int32_t *)feature_buffer) = new_baudrate;
377 feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */
378 /* 1 bit gap */
379 feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */
380 feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */
381 feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */
382 /* 1 bit gap */
383 feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
384
385 dbg("%s - device is being sent this feature report:",
386 __func__);
387 dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__,
388 feature_buffer[0], feature_buffer[1],
389 feature_buffer[2], feature_buffer[3],
390 feature_buffer[4]);
391
392 do {
393 retval = usb_control_msg(port->serial->dev,
394 usb_sndctrlpipe(port->serial->dev, 0),
395 HID_REQ_SET_REPORT,
396 USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
397 0x0300, 0, feature_buffer,
398 sizeof(feature_buffer), 500);
399
400 if (tries++ >= 3)
401 break;
402
403 } while (retval != sizeof(feature_buffer) &&
404 retval != -ENODEV);
405
406 if (retval != sizeof(feature_buffer)) {
407 err("%s - failed sending serial line settings - %d",
408 __func__, retval);
409 cypress_set_dead(port);
410 } else {
411 spin_lock_irqsave(&priv->lock, flags);
412 priv->baud_rate = new_baudrate;
413 priv->current_config = feature_buffer[4];
414 spin_unlock_irqrestore(&priv->lock, flags);
415 /* If we asked for a speed change encode it */
416 if (baud_rate)
417 tty_encode_baud_rate(tty,
418 new_baudrate, new_baudrate);
419 }
420 break;
421 case CYPRESS_GET_CONFIG:
422 if (priv->get_cfg_unsafe) {
423 /* Not implemented for this device,
424 and if we try to do it we're likely
425 to crash the hardware. */
426 return -ENOTTY;
427 }
428 dbg("%s - retreiving serial line settings", __func__);
429 /* set initial values in feature buffer */
430 memset(feature_buffer, 0, sizeof(feature_buffer));
431
432 do {
433 retval = usb_control_msg(port->serial->dev,
434 usb_rcvctrlpipe(port->serial->dev, 0),
435 HID_REQ_GET_REPORT,
436 USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
437 0x0300, 0, feature_buffer,
438 sizeof(feature_buffer), 500);
439
440 if (tries++ >= 3)
441 break;
442 } while (retval != sizeof(feature_buffer)
443 && retval != -ENODEV);
444
445 if (retval != sizeof(feature_buffer)) {
446 err("%s - failed to retrieve serial line settings - %d", __func__, retval);
447 cypress_set_dead(port);
448 return retval;
449 } else {
450 spin_lock_irqsave(&priv->lock, flags);
451 /* store the config in one byte, and later
452 use bit masks to check values */
453 priv->current_config = feature_buffer[4];
454 priv->baud_rate = *((u_int32_t *)feature_buffer);
455 spin_unlock_irqrestore(&priv->lock, flags);
456 }
439 } 457 }
440 spin_lock_irqsave(&priv->lock, flags); 458 spin_lock_irqsave(&priv->lock, flags);
441 ++priv->cmd_count; 459 ++priv->cmd_count;
@@ -468,14 +486,14 @@ static void cypress_set_dead(struct usb_serial_port *port)
468 *****************************************************************************/ 486 *****************************************************************************/
469 487
470 488
471static int generic_startup (struct usb_serial *serial) 489static int generic_startup(struct usb_serial *serial)
472{ 490{
473 struct cypress_private *priv; 491 struct cypress_private *priv;
474 struct usb_serial_port *port = serial->port[0]; 492 struct usb_serial_port *port = serial->port[0];
475 493
476 dbg("%s - port %d", __func__, port->number); 494 dbg("%s - port %d", __func__, port->number);
477 495
478 priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL); 496 priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL);
479 if (!priv) 497 if (!priv)
480 return -ENOMEM; 498 return -ENOMEM;
481 499
@@ -487,9 +505,9 @@ static int generic_startup (struct usb_serial *serial)
487 return -ENOMEM; 505 return -ENOMEM;
488 } 506 }
489 init_waitqueue_head(&priv->delta_msr_wait); 507 init_waitqueue_head(&priv->delta_msr_wait);
490 508
491 usb_reset_configuration (serial->dev); 509 usb_reset_configuration(serial->dev);
492 510
493 priv->cmd_ctrl = 0; 511 priv->cmd_ctrl = 0;
494 priv->line_control = 0; 512 priv->line_control = 0;
495 priv->termios_initialized = 0; 513 priv->termios_initialized = 0;
@@ -500,30 +518,30 @@ static int generic_startup (struct usb_serial *serial)
500 small. Otherwise we can use the slightly more compact 518 small. Otherwise we can use the slightly more compact
501 format. This is in accordance with the cypress_m8 serial 519 format. This is in accordance with the cypress_m8 serial
502 converter app note. */ 520 converter app note. */
503 if (port->interrupt_out_size > 9) { 521 if (port->interrupt_out_size > 9)
504 priv->pkt_fmt = packet_format_1; 522 priv->pkt_fmt = packet_format_1;
505 } else { 523 else
506 priv->pkt_fmt = packet_format_2; 524 priv->pkt_fmt = packet_format_2;
507 } 525
508 if (interval > 0) { 526 if (interval > 0) {
509 priv->write_urb_interval = interval; 527 priv->write_urb_interval = interval;
510 priv->read_urb_interval = interval; 528 priv->read_urb_interval = interval;
511 dbg("%s - port %d read & write intervals forced to %d", 529 dbg("%s - port %d read & write intervals forced to %d",
512 __func__,port->number,interval); 530 __func__, port->number, interval);
513 } else { 531 } else {
514 priv->write_urb_interval = port->interrupt_out_urb->interval; 532 priv->write_urb_interval = port->interrupt_out_urb->interval;
515 priv->read_urb_interval = port->interrupt_in_urb->interval; 533 priv->read_urb_interval = port->interrupt_in_urb->interval;
516 dbg("%s - port %d intervals: read=%d write=%d", 534 dbg("%s - port %d intervals: read=%d write=%d",
517 __func__,port->number, 535 __func__, port->number,
518 priv->read_urb_interval,priv->write_urb_interval); 536 priv->read_urb_interval, priv->write_urb_interval);
519 } 537 }
520 usb_set_serial_port_data(port, priv); 538 usb_set_serial_port_data(port, priv);
521 539
522 return 0; 540 return 0;
523} 541}
524 542
525 543
526static int cypress_earthmate_startup (struct usb_serial *serial) 544static int cypress_earthmate_startup(struct usb_serial *serial)
527{ 545{
528 struct cypress_private *priv; 546 struct cypress_private *priv;
529 struct usb_serial_port *port = serial->port[0]; 547 struct usb_serial_port *port = serial->port[0];
@@ -541,7 +559,8 @@ static int cypress_earthmate_startup (struct usb_serial *serial)
541 /* All Earthmate devices use the separated-count packet 559 /* All Earthmate devices use the separated-count packet
542 format! Idiotic. */ 560 format! Idiotic. */
543 priv->pkt_fmt = packet_format_1; 561 priv->pkt_fmt = packet_format_1;
544 if (serial->dev->descriptor.idProduct != cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) { 562 if (serial->dev->descriptor.idProduct !=
563 cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) {
545 /* The old original USB Earthmate seemed able to 564 /* The old original USB Earthmate seemed able to
546 handle GET_CONFIG requests; everything they've 565 handle GET_CONFIG requests; everything they've
547 produced since that time crashes if this command is 566 produced since that time crashes if this command is
@@ -555,7 +574,7 @@ static int cypress_earthmate_startup (struct usb_serial *serial)
555} /* cypress_earthmate_startup */ 574} /* cypress_earthmate_startup */
556 575
557 576
558static int cypress_hidcom_startup (struct usb_serial *serial) 577static int cypress_hidcom_startup(struct usb_serial *serial)
559{ 578{
560 struct cypress_private *priv; 579 struct cypress_private *priv;
561 580
@@ -569,12 +588,12 @@ static int cypress_hidcom_startup (struct usb_serial *serial)
569 588
570 priv = usb_get_serial_port_data(serial->port[0]); 589 priv = usb_get_serial_port_data(serial->port[0]);
571 priv->chiptype = CT_CYPHIDCOM; 590 priv->chiptype = CT_CYPHIDCOM;
572 591
573 return 0; 592 return 0;
574} /* cypress_hidcom_startup */ 593} /* cypress_hidcom_startup */
575 594
576 595
577static int cypress_ca42v2_startup (struct usb_serial *serial) 596static int cypress_ca42v2_startup(struct usb_serial *serial)
578{ 597{
579 struct cypress_private *priv; 598 struct cypress_private *priv;
580 599
@@ -593,11 +612,11 @@ static int cypress_ca42v2_startup (struct usb_serial *serial)
593} /* cypress_ca42v2_startup */ 612} /* cypress_ca42v2_startup */
594 613
595 614
596static void cypress_shutdown (struct usb_serial *serial) 615static void cypress_shutdown(struct usb_serial *serial)
597{ 616{
598 struct cypress_private *priv; 617 struct cypress_private *priv;
599 618
600 dbg ("%s - port %d", __func__, serial->port[0]->number); 619 dbg("%s - port %d", __func__, serial->port[0]->number);
601 620
602 /* all open ports are closed at this point */ 621 /* all open ports are closed at this point */
603 622
@@ -611,7 +630,8 @@ static void cypress_shutdown (struct usb_serial *serial)
611} 630}
612 631
613 632
614static int cypress_open (struct usb_serial_port *port, struct file *filp) 633static int cypress_open(struct tty_struct *tty,
634 struct usb_serial_port *port, struct file *filp)
615{ 635{
616 struct cypress_private *priv = usb_get_serial_port_data(port); 636 struct cypress_private *priv = usb_get_serial_port_data(port);
617 struct usb_serial *serial = port->serial; 637 struct usb_serial *serial = port->serial;
@@ -636,37 +656,44 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp)
636 spin_unlock_irqrestore(&priv->lock, flags); 656 spin_unlock_irqrestore(&priv->lock, flags);
637 657
638 /* setting to zero could cause data loss */ 658 /* setting to zero could cause data loss */
639 port->tty->low_latency = 1; 659 if (tty)
660 tty->low_latency = 1;
640 661
641 /* raise both lines and set termios */ 662 /* raise both lines and set termios */
642 spin_lock_irqsave(&priv->lock, flags); 663 spin_lock_irqsave(&priv->lock, flags);
643 priv->line_control = CONTROL_DTR | CONTROL_RTS; 664 priv->line_control = CONTROL_DTR | CONTROL_RTS;
644 priv->cmd_ctrl = 1; 665 priv->cmd_ctrl = 1;
645 spin_unlock_irqrestore(&priv->lock, flags); 666 spin_unlock_irqrestore(&priv->lock, flags);
646 result = cypress_write(port, NULL, 0); 667 result = cypress_write(tty, port, NULL, 0);
647 668
648 if (result) { 669 if (result) {
649 dev_err(&port->dev, "%s - failed setting the control lines - error %d\n", __func__, result); 670 dev_err(&port->dev,
671 "%s - failed setting the control lines - error %d\n",
672 __func__, result);
650 return result; 673 return result;
651 } else 674 } else
652 dbg("%s - success setting the control lines", __func__); 675 dbg("%s - success setting the control lines", __func__);
653 676
654 cypress_set_termios(port, &priv->tmp_termios); 677 if (tty)
678 cypress_set_termios(tty, port, &priv->tmp_termios);
655 679
656 /* setup the port and start reading from the device */ 680 /* setup the port and start reading from the device */
657 if(!port->interrupt_in_urb){ 681 if (!port->interrupt_in_urb) {
658 err("%s - interrupt_in_urb is empty!", __func__); 682 err("%s - interrupt_in_urb is empty!", __func__);
659 return(-1); 683 return -1;
660 } 684 }
661 685
662 usb_fill_int_urb(port->interrupt_in_urb, serial->dev, 686 usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
663 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), 687 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress),
664 port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length, 688 port->interrupt_in_urb->transfer_buffer,
689 port->interrupt_in_urb->transfer_buffer_length,
665 cypress_read_int_callback, port, priv->read_urb_interval); 690 cypress_read_int_callback, port, priv->read_urb_interval);
666 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 691 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
667 692
668 if (result){ 693 if (result) {
669 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 694 dev_err(&port->dev,
695 "%s - failed submitting read urb, error %d\n",
696 __func__, result);
670 cypress_set_dead(port); 697 cypress_set_dead(port);
671 } 698 }
672 699
@@ -674,7 +701,8 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp)
674} /* cypress_open */ 701} /* cypress_open */
675 702
676 703
677static void cypress_close(struct usb_serial_port *port, struct file * filp) 704static void cypress_close(struct tty_struct *tty,
705 struct usb_serial_port *port, struct file *filp)
678{ 706{
679 struct cypress_private *priv = usb_get_serial_port_data(port); 707 struct cypress_private *priv = usb_get_serial_port_data(port);
680 unsigned int c_cflag; 708 unsigned int c_cflag;
@@ -688,7 +716,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
688 spin_lock_irq(&priv->lock); 716 spin_lock_irq(&priv->lock);
689 timeout = CYPRESS_CLOSING_WAIT; 717 timeout = CYPRESS_CLOSING_WAIT;
690 init_waitqueue_entry(&wait, current); 718 init_waitqueue_entry(&wait, current);
691 add_wait_queue(&port->tty->write_wait, &wait); 719 add_wait_queue(&tty->write_wait, &wait);
692 for (;;) { 720 for (;;) {
693 set_current_state(TASK_INTERRUPTIBLE); 721 set_current_state(TASK_INTERRUPTIBLE);
694 if (cypress_buf_data_avail(priv->buf) == 0 722 if (cypress_buf_data_avail(priv->buf) == 0
@@ -701,7 +729,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
701 spin_lock_irq(&priv->lock); 729 spin_lock_irq(&priv->lock);
702 } 730 }
703 set_current_state(TASK_RUNNING); 731 set_current_state(TASK_RUNNING);
704 remove_wait_queue(&port->tty->write_wait, &wait); 732 remove_wait_queue(&tty->write_wait, &wait);
705 /* clear out any remaining data in the buffer */ 733 /* clear out any remaining data in the buffer */
706 cypress_buf_clear(priv->buf); 734 cypress_buf_clear(priv->buf);
707 spin_unlock_irq(&priv->lock); 735 spin_unlock_irq(&priv->lock);
@@ -713,19 +741,21 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
713 return; 741 return;
714 } 742 }
715 /* wait for characters to drain from device */ 743 /* wait for characters to drain from device */
716 bps = tty_get_baud_rate(port->tty); 744 if (tty) {
717 if (bps > 1200) 745 bps = tty_get_baud_rate(tty);
718 timeout = max((HZ*2560)/bps,HZ/10); 746 if (bps > 1200)
719 else 747 timeout = max((HZ * 2560) / bps, HZ / 10);
720 timeout = 2*HZ; 748 else
721 schedule_timeout_interruptible(timeout); 749 timeout = 2 * HZ;
750 schedule_timeout_interruptible(timeout);
751 }
722 752
723 dbg("%s - stopping urbs", __func__); 753 dbg("%s - stopping urbs", __func__);
724 usb_kill_urb (port->interrupt_in_urb); 754 usb_kill_urb(port->interrupt_in_urb);
725 usb_kill_urb (port->interrupt_out_urb); 755 usb_kill_urb(port->interrupt_out_urb);
726 756
727 if (port->tty) { 757 if (tty) {
728 c_cflag = port->tty->termios->c_cflag; 758 c_cflag = tty->termios->c_cflag;
729 if (c_cflag & HUPCL) { 759 if (c_cflag & HUPCL) {
730 /* drop dtr and rts */ 760 /* drop dtr and rts */
731 priv = usb_get_serial_port_data(port); 761 priv = usb_get_serial_port_data(port);
@@ -733,22 +763,23 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
733 priv->line_control = 0; 763 priv->line_control = 0;
734 priv->cmd_ctrl = 1; 764 priv->cmd_ctrl = 1;
735 spin_unlock_irq(&priv->lock); 765 spin_unlock_irq(&priv->lock);
736 cypress_write(port, NULL, 0); 766 cypress_write(tty, port, NULL, 0);
737 } 767 }
738 } 768 }
739 769
740 if (stats) 770 if (stats)
741 dev_info (&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", 771 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
742 priv->bytes_in, priv->bytes_out, priv->cmd_count); 772 priv->bytes_in, priv->bytes_out, priv->cmd_count);
743 mutex_unlock(&port->serial->disc_mutex); 773 mutex_unlock(&port->serial->disc_mutex);
744} /* cypress_close */ 774} /* cypress_close */
745 775
746 776
747static int cypress_write(struct usb_serial_port *port, const unsigned char *buf, int count) 777static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
778 const unsigned char *buf, int count)
748{ 779{
749 struct cypress_private *priv = usb_get_serial_port_data(port); 780 struct cypress_private *priv = usb_get_serial_port_data(port);
750 unsigned long flags; 781 unsigned long flags;
751 782
752 dbg("%s - port %d, %d bytes", __func__, port->number, count); 783 dbg("%s - port %d, %d bytes", __func__, port->number, count);
753 784
754 /* line control commands, which need to be executed immediately, 785 /* line control commands, which need to be executed immediately,
@@ -758,10 +789,10 @@ static int cypress_write(struct usb_serial_port *port, const unsigned char *buf,
758 count = 0; 789 count = 0;
759 goto finish; 790 goto finish;
760 } 791 }
761 792
762 if (!count) 793 if (!count)
763 return count; 794 return count;
764 795
765 spin_lock_irqsave(&priv->lock, flags); 796 spin_lock_irqsave(&priv->lock, flags);
766 count = cypress_buf_put(priv->buf, buf, count); 797 count = cypress_buf_put(priv->buf, buf, count);
767 spin_unlock_irqrestore(&priv->lock, flags); 798 spin_unlock_irqrestore(&priv->lock, flags);
@@ -778,13 +809,14 @@ static void cypress_send(struct usb_serial_port *port)
778 int count = 0, result, offset, actual_size; 809 int count = 0, result, offset, actual_size;
779 struct cypress_private *priv = usb_get_serial_port_data(port); 810 struct cypress_private *priv = usb_get_serial_port_data(port);
780 unsigned long flags; 811 unsigned long flags;
781 812
782 if (!priv->comm_is_ok) 813 if (!priv->comm_is_ok)
783 return; 814 return;
784 815
785 dbg("%s - port %d", __func__, port->number); 816 dbg("%s - port %d", __func__, port->number);
786 dbg("%s - interrupt out size is %d", __func__, port->interrupt_out_size); 817 dbg("%s - interrupt out size is %d", __func__,
787 818 port->interrupt_out_size);
819
788 spin_lock_irqsave(&priv->lock, flags); 820 spin_lock_irqsave(&priv->lock, flags);
789 if (priv->write_urb_in_use) { 821 if (priv->write_urb_in_use) {
790 dbg("%s - can't write, urb in use", __func__); 822 dbg("%s - can't write, urb in use", __func__);
@@ -794,7 +826,8 @@ static void cypress_send(struct usb_serial_port *port)
794 spin_unlock_irqrestore(&priv->lock, flags); 826 spin_unlock_irqrestore(&priv->lock, flags);
795 827
796 /* clear buffer */ 828 /* clear buffer */
797 memset(port->interrupt_out_urb->transfer_buffer, 0, port->interrupt_out_size); 829 memset(port->interrupt_out_urb->transfer_buffer, 0,
830 port->interrupt_out_size);
798 831
799 spin_lock_irqsave(&priv->lock, flags); 832 spin_lock_irqsave(&priv->lock, flags);
800 switch (priv->pkt_fmt) { 833 switch (priv->pkt_fmt) {
@@ -825,9 +858,8 @@ static void cypress_send(struct usb_serial_port *port)
825 count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset], 858 count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset],
826 port->interrupt_out_size-offset); 859 port->interrupt_out_size-offset);
827 860
828 if (count == 0) { 861 if (count == 0)
829 return; 862 return;
830 }
831 863
832 switch (priv->pkt_fmt) { 864 switch (priv->pkt_fmt) {
833 default: 865 default:
@@ -851,26 +883,29 @@ send:
851 actual_size = count + 883 actual_size = count +
852 (priv->pkt_fmt == packet_format_1 ? 2 : 1); 884 (priv->pkt_fmt == packet_format_1 ? 2 : 1);
853 885
854 usb_serial_debug_data(debug, &port->dev, __func__, port->interrupt_out_size, 886 usb_serial_debug_data(debug, &port->dev, __func__,
855 port->interrupt_out_urb->transfer_buffer); 887 port->interrupt_out_size,
888 port->interrupt_out_urb->transfer_buffer);
856 889
857 usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev, 890 usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev,
858 usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress), 891 usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress),
859 port->interrupt_out_buffer, port->interrupt_out_size, 892 port->interrupt_out_buffer, port->interrupt_out_size,
860 cypress_write_int_callback, port, priv->write_urb_interval); 893 cypress_write_int_callback, port, priv->write_urb_interval);
861 result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC); 894 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
862 if (result) { 895 if (result) {
863 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, 896 dev_err(&port->dev,
864 result); 897 "%s - failed submitting write urb, error %d\n",
898 __func__, result);
865 priv->write_urb_in_use = 0; 899 priv->write_urb_in_use = 0;
866 cypress_set_dead(port); 900 cypress_set_dead(port);
867 } 901 }
868 902
869 spin_lock_irqsave(&priv->lock, flags); 903 spin_lock_irqsave(&priv->lock, flags);
870 if (priv->cmd_ctrl) { 904 if (priv->cmd_ctrl)
871 priv->cmd_ctrl = 0; 905 priv->cmd_ctrl = 0;
872 } 906
873 priv->bytes_out += count; /* do not count the line control and size bytes */ 907 /* do not count the line control and size bytes */
908 priv->bytes_out += count;
874 spin_unlock_irqrestore(&priv->lock, flags); 909 spin_unlock_irqrestore(&priv->lock, flags);
875 910
876 usb_serial_port_softint(port); 911 usb_serial_port_softint(port);
@@ -878,8 +913,9 @@ send:
878 913
879 914
880/* returns how much space is available in the soft buffer */ 915/* returns how much space is available in the soft buffer */
881static int cypress_write_room(struct usb_serial_port *port) 916static int cypress_write_room(struct tty_struct *tty)
882{ 917{
918 struct usb_serial_port *port = tty->driver_data;
883 struct cypress_private *priv = usb_get_serial_port_data(port); 919 struct cypress_private *priv = usb_get_serial_port_data(port);
884 int room = 0; 920 int room = 0;
885 unsigned long flags; 921 unsigned long flags;
@@ -895,13 +931,14 @@ static int cypress_write_room(struct usb_serial_port *port)
895} 931}
896 932
897 933
898static int cypress_tiocmget (struct usb_serial_port *port, struct file *file) 934static int cypress_tiocmget(struct tty_struct *tty, struct file *file)
899{ 935{
936 struct usb_serial_port *port = tty->driver_data;
900 struct cypress_private *priv = usb_get_serial_port_data(port); 937 struct cypress_private *priv = usb_get_serial_port_data(port);
901 __u8 status, control; 938 __u8 status, control;
902 unsigned int result = 0; 939 unsigned int result = 0;
903 unsigned long flags; 940 unsigned long flags;
904 941
905 dbg("%s - port %d", __func__, port->number); 942 dbg("%s - port %d", __func__, port->number);
906 943
907 spin_lock_irqsave(&priv->lock, flags); 944 spin_lock_irqsave(&priv->lock, flags);
@@ -922,12 +959,13 @@ static int cypress_tiocmget (struct usb_serial_port *port, struct file *file)
922} 959}
923 960
924 961
925static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, 962static int cypress_tiocmset(struct tty_struct *tty, struct file *file,
926 unsigned int set, unsigned int clear) 963 unsigned int set, unsigned int clear)
927{ 964{
965 struct usb_serial_port *port = tty->driver_data;
928 struct cypress_private *priv = usb_get_serial_port_data(port); 966 struct cypress_private *priv = usb_get_serial_port_data(port);
929 unsigned long flags; 967 unsigned long flags;
930 968
931 dbg("%s - port %d", __func__, port->number); 969 dbg("%s - port %d", __func__, port->number);
932 970
933 spin_lock_irqsave(&priv->lock, flags); 971 spin_lock_irqsave(&priv->lock, flags);
@@ -942,63 +980,60 @@ static int cypress_tiocmset (struct usb_serial_port *port, struct file *file,
942 priv->cmd_ctrl = 1; 980 priv->cmd_ctrl = 1;
943 spin_unlock_irqrestore(&priv->lock, flags); 981 spin_unlock_irqrestore(&priv->lock, flags);
944 982
945 return cypress_write(port, NULL, 0); 983 return cypress_write(tty, port, NULL, 0);
946} 984}
947 985
948 986
949static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 987static int cypress_ioctl(struct tty_struct *tty, struct file *file,
988 unsigned int cmd, unsigned long arg)
950{ 989{
990 struct usb_serial_port *port = tty->driver_data;
951 struct cypress_private *priv = usb_get_serial_port_data(port); 991 struct cypress_private *priv = usb_get_serial_port_data(port);
952 992
953 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); 993 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
954 994
955 switch (cmd) { 995 switch (cmd) {
956 /* This code comes from drivers/char/serial.c and ftdi_sio.c */ 996 /* This code comes from drivers/char/serial.c and ftdi_sio.c */
957 case TIOCMIWAIT: 997 case TIOCMIWAIT:
958 while (priv != NULL) { 998 while (priv != NULL) {
959 interruptible_sleep_on(&priv->delta_msr_wait); 999 interruptible_sleep_on(&priv->delta_msr_wait);
960 /* see if a signal did it */ 1000 /* see if a signal did it */
961 if (signal_pending(current)) 1001 if (signal_pending(current))
962 return -ERESTARTSYS; 1002 return -ERESTARTSYS;
963 else { 1003 else {
964 char diff = priv->diff_status; 1004 char diff = priv->diff_status;
965 1005 if (diff == 0)
966 if (diff == 0) { 1006 return -EIO; /* no change => error */
967 return -EIO; /* no change => error */ 1007
968 } 1008 /* consume all events */
969 1009 priv->diff_status = 0;
970 /* consume all events */ 1010
971 priv->diff_status = 0; 1011 /* return 0 if caller wanted to know about
972 1012 these bits */
973 /* return 0 if caller wanted to know about these bits */ 1013 if (((arg & TIOCM_RNG) && (diff & UART_RI)) ||
974 if ( ((arg & TIOCM_RNG) && (diff & UART_RI)) || 1014 ((arg & TIOCM_DSR) && (diff & UART_DSR)) ||
975 ((arg & TIOCM_DSR) && (diff & UART_DSR)) || 1015 ((arg & TIOCM_CD) && (diff & UART_CD)) ||
976 ((arg & TIOCM_CD) && (diff & UART_CD)) || 1016 ((arg & TIOCM_CTS) && (diff & UART_CTS)))
977 ((arg & TIOCM_CTS) && (diff & UART_CTS)) ) { 1017 return 0;
978 return 0; 1018 /* otherwise caller can't care less about what
979 } 1019 * happened, and so we continue to wait for
980 /* otherwise caller can't care less about what happened, 1020 * more events.
981 * and so we continue to wait for more events. 1021 */
982 */
983 }
984 } 1022 }
985 return 0; 1023 }
986 break; 1024 return 0;
987 default: 1025 default:
988 break; 1026 break;
989 } 1027 }
990
991 dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __func__, cmd); 1028 dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __func__, cmd);
992
993 return -ENOIOCTLCMD; 1029 return -ENOIOCTLCMD;
994} /* cypress_ioctl */ 1030} /* cypress_ioctl */
995 1031
996 1032
997static void cypress_set_termios (struct usb_serial_port *port, 1033static void cypress_set_termios(struct tty_struct *tty,
998 struct ktermios *old_termios) 1034 struct usb_serial_port *port, struct ktermios *old_termios)
999{ 1035{
1000 struct cypress_private *priv = usb_get_serial_port_data(port); 1036 struct cypress_private *priv = usb_get_serial_port_data(port);
1001 struct tty_struct *tty;
1002 int data_bits, stop_bits, parity_type, parity_enable; 1037 int data_bits, stop_bits, parity_type, parity_enable;
1003 unsigned cflag, iflag; 1038 unsigned cflag, iflag;
1004 unsigned long flags; 1039 unsigned long flags;
@@ -1007,8 +1042,6 @@ static void cypress_set_termios (struct usb_serial_port *port,
1007 1042
1008 dbg("%s - port %d", __func__, port->number); 1043 dbg("%s - port %d", __func__, port->number);
1009 1044
1010 tty = port->tty;
1011
1012 spin_lock_irqsave(&priv->lock, flags); 1045 spin_lock_irqsave(&priv->lock, flags);
1013 if (!priv->termios_initialized) { 1046 if (!priv->termios_initialized) {
1014 if (priv->chiptype == CT_EARTHMATE) { 1047 if (priv->chiptype == CT_EARTHMATE) {
@@ -1060,28 +1093,24 @@ static void cypress_set_termios (struct usb_serial_port *port,
1060 } else 1093 } else
1061 parity_enable = parity_type = 0; 1094 parity_enable = parity_type = 0;
1062 1095
1063 if (cflag & CSIZE) { 1096 switch (cflag & CSIZE) {
1064 switch (cflag & CSIZE) { 1097 case CS5:
1065 case CS5: 1098 data_bits = 0;
1066 data_bits = 0; 1099 break;
1067 break; 1100 case CS6:
1068 case CS6: 1101 data_bits = 1;
1069 data_bits = 1; 1102 break;
1070 break; 1103 case CS7:
1071 case CS7: 1104 data_bits = 2;
1072 data_bits = 2; 1105 break;
1073 break; 1106 case CS8:
1074 case CS8:
1075 data_bits = 3;
1076 break;
1077 default:
1078 err("%s - CSIZE was set, but not CS5-CS8",
1079 __func__);
1080 data_bits = 3;
1081 }
1082 } else
1083 data_bits = 3; 1107 data_bits = 3;
1084 1108 break;
1109 default:
1110 err("%s - CSIZE was set, but not CS5-CS8",
1111 __func__);
1112 data_bits = 3;
1113 }
1085 spin_lock_irqsave(&priv->lock, flags); 1114 spin_lock_irqsave(&priv->lock, flags);
1086 oldlines = priv->line_control; 1115 oldlines = priv->line_control;
1087 if ((cflag & CBAUD) == B0) { 1116 if ((cflag & CBAUD) == B0) {
@@ -1096,19 +1125,21 @@ static void cypress_set_termios (struct usb_serial_port *port,
1096 "%d data_bits (+5)", __func__, stop_bits, 1125 "%d data_bits (+5)", __func__, stop_bits,
1097 parity_enable, parity_type, data_bits); 1126 parity_enable, parity_type, data_bits);
1098 1127
1099 cypress_serial_control(port, tty_get_baud_rate(tty), data_bits, stop_bits, 1128 cypress_serial_control(tty, port, tty_get_baud_rate(tty),
1100 parity_enable, parity_type, 0, CYPRESS_SET_CONFIG); 1129 data_bits, stop_bits,
1130 parity_enable, parity_type,
1131 0, CYPRESS_SET_CONFIG);
1101 1132
1102 /* we perform a CYPRESS_GET_CONFIG so that the current settings are 1133 /* we perform a CYPRESS_GET_CONFIG so that the current settings are
1103 * filled into the private structure this should confirm that all is 1134 * filled into the private structure this should confirm that all is
1104 * working if it returns what we just set */ 1135 * working if it returns what we just set */
1105 cypress_serial_control(port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG); 1136 cypress_serial_control(tty, port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG);
1106 1137
1107 /* Here we can define custom tty settings for devices; the main tty 1138 /* Here we can define custom tty settings for devices; the main tty
1108 * termios flag base comes from empeg.c */ 1139 * termios flag base comes from empeg.c */
1109 1140
1110 spin_lock_irqsave(&priv->lock, flags); 1141 spin_lock_irqsave(&priv->lock, flags);
1111 if ( (priv->chiptype == CT_EARTHMATE) && (priv->baud_rate == 4800) ) { 1142 if (priv->chiptype == CT_EARTHMATE && priv->baud_rate == 4800) {
1112 dbg("Using custom termios settings for a baud rate of " 1143 dbg("Using custom termios settings for a baud rate of "
1113 "4800bps."); 1144 "4800bps.");
1114 /* define custom termios settings for NMEA protocol */ 1145 /* define custom termios settings for NMEA protocol */
@@ -1142,20 +1173,21 @@ static void cypress_set_termios (struct usb_serial_port *port,
1142 /* if necessary, set lines */ 1173 /* if necessary, set lines */
1143 if (linechange) { 1174 if (linechange) {
1144 priv->cmd_ctrl = 1; 1175 priv->cmd_ctrl = 1;
1145 cypress_write(port, NULL, 0); 1176 cypress_write(tty, port, NULL, 0);
1146 } 1177 }
1147} /* cypress_set_termios */ 1178} /* cypress_set_termios */
1148 1179
1149 1180
1150/* returns amount of data still left in soft buffer */ 1181/* returns amount of data still left in soft buffer */
1151static int cypress_chars_in_buffer(struct usb_serial_port *port) 1182static int cypress_chars_in_buffer(struct tty_struct *tty)
1152{ 1183{
1184 struct usb_serial_port *port = tty->driver_data;
1153 struct cypress_private *priv = usb_get_serial_port_data(port); 1185 struct cypress_private *priv = usb_get_serial_port_data(port);
1154 int chars = 0; 1186 int chars = 0;
1155 unsigned long flags; 1187 unsigned long flags;
1156 1188
1157 dbg("%s - port %d", __func__, port->number); 1189 dbg("%s - port %d", __func__, port->number);
1158 1190
1159 spin_lock_irqsave(&priv->lock, flags); 1191 spin_lock_irqsave(&priv->lock, flags);
1160 chars = cypress_buf_data_avail(priv->buf); 1192 chars = cypress_buf_data_avail(priv->buf);
1161 spin_unlock_irqrestore(&priv->lock, flags); 1193 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1165,8 +1197,9 @@ static int cypress_chars_in_buffer(struct usb_serial_port *port)
1165} 1197}
1166 1198
1167 1199
1168static void cypress_throttle (struct usb_serial_port *port) 1200static void cypress_throttle(struct tty_struct *tty)
1169{ 1201{
1202 struct usb_serial_port *port = tty->driver_data;
1170 struct cypress_private *priv = usb_get_serial_port_data(port); 1203 struct cypress_private *priv = usb_get_serial_port_data(port);
1171 unsigned long flags; 1204 unsigned long flags;
1172 1205
@@ -1178,8 +1211,9 @@ static void cypress_throttle (struct usb_serial_port *port)
1178} 1211}
1179 1212
1180 1213
1181static void cypress_unthrottle (struct usb_serial_port *port) 1214static void cypress_unthrottle(struct tty_struct *tty)
1182{ 1215{
1216 struct usb_serial_port *port = tty->driver_data;
1183 struct cypress_private *priv = usb_get_serial_port_data(port); 1217 struct cypress_private *priv = usb_get_serial_port_data(port);
1184 int actually_throttled, result; 1218 int actually_throttled, result;
1185 unsigned long flags; 1219 unsigned long flags;
@@ -1232,12 +1266,13 @@ static void cypress_read_int_callback(struct urb *urb)
1232 /* precursor to disconnect so just go away */ 1266 /* precursor to disconnect so just go away */
1233 return; 1267 return;
1234 case -EPIPE: 1268 case -EPIPE:
1235 usb_clear_halt(port->serial->dev,0x81); 1269 usb_clear_halt(port->serial->dev, 0x81);
1236 break; 1270 break;
1237 default: 1271 default:
1238 /* something ugly is going on... */ 1272 /* something ugly is going on... */
1239 dev_err(&urb->dev->dev,"%s - unexpected nonzero read status received: %d\n", 1273 dev_err(&urb->dev->dev,
1240 __func__, status); 1274 "%s - unexpected nonzero read status received: %d\n",
1275 __func__, status);
1241 cypress_set_dead(port); 1276 cypress_set_dead(port);
1242 return; 1277 return;
1243 } 1278 }
@@ -1251,7 +1286,7 @@ static void cypress_read_int_callback(struct urb *urb)
1251 } 1286 }
1252 spin_unlock_irqrestore(&priv->lock, flags); 1287 spin_unlock_irqrestore(&priv->lock, flags);
1253 1288
1254 tty = port->tty; 1289 tty = port->port.tty;
1255 if (!tty) { 1290 if (!tty) {
1256 dbg("%s - bad tty pointer - exiting", __func__); 1291 dbg("%s - bad tty pointer - exiting", __func__);
1257 return; 1292 return;
@@ -1285,8 +1320,8 @@ static void cypress_read_int_callback(struct urb *urb)
1285 goto continue_read; 1320 goto continue_read;
1286 } 1321 }
1287 1322
1288 usb_serial_debug_data (debug, &port->dev, __func__, 1323 usb_serial_debug_data(debug, &port->dev, __func__,
1289 urb->actual_length, data); 1324 urb->actual_length, data);
1290 1325
1291 spin_lock_irqsave(&priv->lock, flags); 1326 spin_lock_irqsave(&priv->lock, flags);
1292 /* check to see if status has changed */ 1327 /* check to see if status has changed */
@@ -1327,7 +1362,7 @@ static void cypress_read_int_callback(struct urb *urb)
1327 data[i]); 1362 data[i]);
1328 tty_insert_flip_char(tty, data[i], tty_flag); 1363 tty_insert_flip_char(tty, data[i], tty_flag);
1329 } 1364 }
1330 tty_flip_buffer_push(port->tty); 1365 tty_flip_buffer_push(port->port.tty);
1331 } 1366 }
1332 1367
1333 spin_lock_irqsave(&priv->lock, flags); 1368 spin_lock_irqsave(&priv->lock, flags);
@@ -1339,13 +1374,14 @@ continue_read:
1339 1374
1340 /* Continue trying to always read... unless the port has closed. */ 1375 /* Continue trying to always read... unless the port has closed. */
1341 1376
1342 if (port->open_count > 0 && priv->comm_is_ok) { 1377 if (port->port.count > 0 && priv->comm_is_ok) {
1343 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, 1378 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
1344 usb_rcvintpipe(port->serial->dev, 1379 usb_rcvintpipe(port->serial->dev,
1345 port->interrupt_in_endpointAddress), 1380 port->interrupt_in_endpointAddress),
1346 port->interrupt_in_urb->transfer_buffer, 1381 port->interrupt_in_urb->transfer_buffer,
1347 port->interrupt_in_urb->transfer_buffer_length, 1382 port->interrupt_in_urb->transfer_buffer_length,
1348 cypress_read_int_callback, port, priv->read_urb_interval); 1383 cypress_read_int_callback, port,
1384 priv->read_urb_interval);
1349 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1385 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1350 if (result) { 1386 if (result) {
1351 dev_err(&urb->dev->dev, "%s - failed resubmitting " 1387 dev_err(&urb->dev->dev, "%s - failed resubmitting "
@@ -1369,42 +1405,43 @@ static void cypress_write_int_callback(struct urb *urb)
1369 dbg("%s - port %d", __func__, port->number); 1405 dbg("%s - port %d", __func__, port->number);
1370 1406
1371 switch (status) { 1407 switch (status) {
1372 case 0: 1408 case 0:
1373 /* success */ 1409 /* success */
1410 break;
1411 case -ECONNRESET:
1412 case -ENOENT:
1413 case -ESHUTDOWN:
1414 /* this urb is terminated, clean up */
1415 dbg("%s - urb shutting down with status: %d",
1416 __func__, status);
1417 priv->write_urb_in_use = 0;
1418 return;
1419 case -EPIPE: /* no break needed; clear halt and resubmit */
1420 if (!priv->comm_is_ok)
1374 break; 1421 break;
1375 case -ECONNRESET: 1422 usb_clear_halt(port->serial->dev, 0x02);
1376 case -ENOENT: 1423 /* error in the urb, so we have to resubmit it */
1377 case -ESHUTDOWN: 1424 dbg("%s - nonzero write bulk status received: %d",
1378 /* this urb is terminated, clean up */ 1425 __func__, status);
1379 dbg("%s - urb shutting down with status: %d", 1426 port->interrupt_out_urb->transfer_buffer_length = 1;
1380 __func__, status); 1427 port->interrupt_out_urb->dev = port->serial->dev;
1381 priv->write_urb_in_use = 0; 1428 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
1429 if (!result)
1382 return; 1430 return;
1383 case -EPIPE: /* no break needed; clear halt and resubmit */ 1431 dev_err(&urb->dev->dev,
1384 if (!priv->comm_is_ok) 1432 "%s - failed resubmitting write urb, error %d\n",
1385 break; 1433 __func__, result);
1386 usb_clear_halt(port->serial->dev, 0x02); 1434 cypress_set_dead(port);
1387 /* error in the urb, so we have to resubmit it */ 1435 break;
1388 dbg("%s - nonzero write bulk status received: %d", 1436 default:
1389 __func__, status); 1437 dev_err(&urb->dev->dev,
1390 port->interrupt_out_urb->transfer_buffer_length = 1; 1438 "%s - unexpected nonzero write status received: %d\n",
1391 port->interrupt_out_urb->dev = port->serial->dev; 1439 __func__, status);
1392 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); 1440 cypress_set_dead(port);
1393 if (!result) 1441 break;
1394 return;
1395 dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n",
1396 __func__, result);
1397 cypress_set_dead(port);
1398 break;
1399 default:
1400 dev_err(&urb->dev->dev,"%s - unexpected nonzero write status received: %d\n",
1401 __func__, status);
1402 cypress_set_dead(port);
1403 break;
1404 } 1442 }
1405
1406 priv->write_urb_in_use = 0; 1443 priv->write_urb_in_use = 0;
1407 1444
1408 /* send any buffered data */ 1445 /* send any buffered data */
1409 cypress_send(port); 1446 cypress_send(port);
1410} 1447}
@@ -1486,7 +1523,8 @@ static void cypress_buf_clear(struct cypress_buf *cb)
1486static unsigned int cypress_buf_data_avail(struct cypress_buf *cb) 1523static unsigned int cypress_buf_data_avail(struct cypress_buf *cb)
1487{ 1524{
1488 if (cb != NULL) 1525 if (cb != NULL)
1489 return ((cb->buf_size + cb->buf_put - cb->buf_get) % cb->buf_size); 1526 return (cb->buf_size + cb->buf_put - cb->buf_get)
1527 % cb->buf_size;
1490 else 1528 else
1491 return 0; 1529 return 0;
1492} 1530}
@@ -1502,7 +1540,8 @@ static unsigned int cypress_buf_data_avail(struct cypress_buf *cb)
1502static unsigned int cypress_buf_space_avail(struct cypress_buf *cb) 1540static unsigned int cypress_buf_space_avail(struct cypress_buf *cb)
1503{ 1541{
1504 if (cb != NULL) 1542 if (cb != NULL)
1505 return ((cb->buf_size + cb->buf_get - cb->buf_put - 1) % cb->buf_size); 1543 return (cb->buf_size + cb->buf_get - cb->buf_put - 1)
1544 % cb->buf_size;
1506 else 1545 else
1507 return 0; 1546 return 0;
1508} 1547}
@@ -1602,9 +1641,9 @@ static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf,
1602static int __init cypress_init(void) 1641static int __init cypress_init(void)
1603{ 1642{
1604 int retval; 1643 int retval;
1605 1644
1606 dbg("%s", __func__); 1645 dbg("%s", __func__);
1607 1646
1608 retval = usb_serial_register(&cypress_earthmate_device); 1647 retval = usb_serial_register(&cypress_earthmate_device);
1609 if (retval) 1648 if (retval)
1610 goto failed_em_register; 1649 goto failed_em_register;
@@ -1632,23 +1671,23 @@ failed_em_register:
1632} 1671}
1633 1672
1634 1673
1635static void __exit cypress_exit (void) 1674static void __exit cypress_exit(void)
1636{ 1675{
1637 dbg("%s", __func__); 1676 dbg("%s", __func__);
1638 1677
1639 usb_deregister (&cypress_driver); 1678 usb_deregister(&cypress_driver);
1640 usb_serial_deregister (&cypress_earthmate_device); 1679 usb_serial_deregister(&cypress_earthmate_device);
1641 usb_serial_deregister (&cypress_hidcom_device); 1680 usb_serial_deregister(&cypress_hidcom_device);
1642 usb_serial_deregister (&cypress_ca42v2_device); 1681 usb_serial_deregister(&cypress_ca42v2_device);
1643} 1682}
1644 1683
1645 1684
1646module_init(cypress_init); 1685module_init(cypress_init);
1647module_exit(cypress_exit); 1686module_exit(cypress_exit);
1648 1687
1649MODULE_AUTHOR( DRIVER_AUTHOR ); 1688MODULE_AUTHOR(DRIVER_AUTHOR);
1650MODULE_DESCRIPTION( DRIVER_DESC ); 1689MODULE_DESCRIPTION(DRIVER_DESC);
1651MODULE_VERSION( DRIVER_VERSION ); 1690MODULE_VERSION(DRIVER_VERSION);
1652MODULE_LICENSE("GPL"); 1691MODULE_LICENSE("GPL");
1653 1692
1654module_param(debug, bool, S_IRUGO | S_IWUSR); 1693module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/cypress_m8.h b/drivers/usb/serial/cypress_m8.h
index 0388065bb794..e772b01ac3ac 100644
--- a/drivers/usb/serial/cypress_m8.h
+++ b/drivers/usb/serial/cypress_m8.h
@@ -54,7 +54,7 @@
54#define UART_DSR 0x20 /* data set ready - flow control - device to host */ 54#define UART_DSR 0x20 /* data set ready - flow control - device to host */
55#define CONTROL_RTS 0x10 /* request to send - flow control - host to device */ 55#define CONTROL_RTS 0x10 /* request to send - flow control - host to device */
56#define UART_CTS 0x10 /* clear to send - flow control - device to host */ 56#define UART_CTS 0x10 /* clear to send - flow control - device to host */
57#define UART_RI 0x10 /* ring indicator - modem - device to host */ 57#define UART_RI 0x10 /* ring indicator - modem - device to host */
58#define UART_CD 0x40 /* carrier detect - modem - device to host */ 58#define UART_CD 0x40 /* carrier detect - modem - device to host */
59#define CYP_ERROR 0x08 /* received from input report - device to host */ 59#define CYP_ERROR 0x08 /* received from input report - device to host */
60/* Note - the below has nothing to to with the "feature report" reset */ 60/* Note - the below has nothing to to with the "feature report" reset */
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 04a56f300ea6..240aad1acaab 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -15,7 +15,7 @@
15* Al Borchers (borchers@steinerpoint.com) 15* Al Borchers (borchers@steinerpoint.com)
16* 16*
17* (12/03/2001) gkh 17* (12/03/2001) gkh
18* switched to using port->open_count instead of private version. 18* switched to using port->port.count instead of private version.
19* Removed port->active 19* Removed port->active
20* 20*
21* (04/08/2001) gb 21* (04/08/2001) gb
@@ -229,8 +229,6 @@
229* in case a wake up is lost. 229* in case a wake up is lost.
230* - Following Documentation/DocBook/kernel-locking.pdf no spin locks 230* - Following Documentation/DocBook/kernel-locking.pdf no spin locks
231* are held when calling copy_to/from_user or printk. 231* are held when calling copy_to/from_user or printk.
232*
233* $Id: digi_acceleport.c,v 1.80.1.2 2000/11/02 05:45:08 root Exp $
234*/ 232*/
235 233
236#include <linux/kernel.h> 234#include <linux/kernel.h>
@@ -243,7 +241,7 @@
243#include <linux/module.h> 241#include <linux/module.h>
244#include <linux/spinlock.h> 242#include <linux/spinlock.h>
245#include <linux/workqueue.h> 243#include <linux/workqueue.h>
246#include <asm/uaccess.h> 244#include <linux/uaccess.h>
247#include <linux/usb.h> 245#include <linux/usb.h>
248#include <linux/wait.h> 246#include <linux/wait.h>
249#include <linux/usb/serial.h> 247#include <linux/usb/serial.h>
@@ -443,22 +441,23 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
443 unsigned int modem_signals, int interruptible); 441 unsigned int modem_signals, int interruptible);
444static int digi_transmit_idle(struct usb_serial_port *port, 442static int digi_transmit_idle(struct usb_serial_port *port,
445 unsigned long timeout); 443 unsigned long timeout);
446static void digi_rx_throttle (struct usb_serial_port *port); 444static void digi_rx_throttle(struct tty_struct *tty);
447static void digi_rx_unthrottle (struct usb_serial_port *port); 445static void digi_rx_unthrottle(struct tty_struct *tty);
448static void digi_set_termios(struct usb_serial_port *port, 446static void digi_set_termios(struct tty_struct *tty,
449 struct ktermios *old_termios); 447 struct usb_serial_port *port, struct ktermios *old_termios);
450static void digi_break_ctl(struct usb_serial_port *port, int break_state); 448static void digi_break_ctl(struct tty_struct *tty, int break_state);
451static int digi_ioctl(struct usb_serial_port *port, struct file *file, 449static int digi_tiocmget(struct tty_struct *tty, struct file *file);
452 unsigned int cmd, unsigned long arg); 450static int digi_tiocmset(struct tty_struct *tty, struct file *file,
453static int digi_tiocmget(struct usb_serial_port *port, struct file *file);
454static int digi_tiocmset(struct usb_serial_port *port, struct file *file,
455 unsigned int set, unsigned int clear); 451 unsigned int set, unsigned int clear);
456static int digi_write(struct usb_serial_port *port, const unsigned char *buf, int count); 452static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
453 const unsigned char *buf, int count);
457static void digi_write_bulk_callback(struct urb *urb); 454static void digi_write_bulk_callback(struct urb *urb);
458static int digi_write_room(struct usb_serial_port *port); 455static int digi_write_room(struct tty_struct *tty);
459static int digi_chars_in_buffer(struct usb_serial_port *port); 456static int digi_chars_in_buffer(struct tty_struct *tty);
460static int digi_open(struct usb_serial_port *port, struct file *filp); 457static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
461static void digi_close(struct usb_serial_port *port, struct file *filp); 458 struct file *filp);
459static void digi_close(struct tty_struct *tty, struct usb_serial_port *port,
460 struct file *filp);
462static int digi_startup_device(struct usb_serial *serial); 461static int digi_startup_device(struct usb_serial *serial);
463static int digi_startup(struct usb_serial *serial); 462static int digi_startup(struct usb_serial *serial);
464static void digi_shutdown(struct usb_serial *serial); 463static void digi_shutdown(struct usb_serial *serial);
@@ -487,7 +486,7 @@ static struct usb_device_id id_table_4 [] = {
487 { } /* Terminating entry */ 486 { } /* Terminating entry */
488}; 487};
489 488
490MODULE_DEVICE_TABLE (usb, id_table_combined); 489MODULE_DEVICE_TABLE(usb, id_table_combined);
491 490
492static struct usb_driver digi_driver = { 491static struct usb_driver digi_driver = {
493 .name = "digi_acceleport", 492 .name = "digi_acceleport",
@@ -518,7 +517,6 @@ static struct usb_serial_driver digi_acceleport_2_device = {
518 .chars_in_buffer = digi_chars_in_buffer, 517 .chars_in_buffer = digi_chars_in_buffer,
519 .throttle = digi_rx_throttle, 518 .throttle = digi_rx_throttle,
520 .unthrottle = digi_rx_unthrottle, 519 .unthrottle = digi_rx_unthrottle,
521 .ioctl = digi_ioctl,
522 .set_termios = digi_set_termios, 520 .set_termios = digi_set_termios,
523 .break_ctl = digi_break_ctl, 521 .break_ctl = digi_break_ctl,
524 .tiocmget = digi_tiocmget, 522 .tiocmget = digi_tiocmget,
@@ -545,7 +543,6 @@ static struct usb_serial_driver digi_acceleport_4_device = {
545 .chars_in_buffer = digi_chars_in_buffer, 543 .chars_in_buffer = digi_chars_in_buffer,
546 .throttle = digi_rx_throttle, 544 .throttle = digi_rx_throttle,
547 .unthrottle = digi_rx_unthrottle, 545 .unthrottle = digi_rx_unthrottle,
548 .ioctl = digi_ioctl,
549 .set_termios = digi_set_termios, 546 .set_termios = digi_set_termios,
550 .break_ctl = digi_break_ctl, 547 .break_ctl = digi_break_ctl,
551 .tiocmget = digi_tiocmget, 548 .tiocmget = digi_tiocmget,
@@ -558,21 +555,22 @@ static struct usb_serial_driver digi_acceleport_4_device = {
558/* Functions */ 555/* Functions */
559 556
560/* 557/*
561* Cond Wait Interruptible Timeout Irqrestore 558 * Cond Wait Interruptible Timeout Irqrestore
562* 559 *
563* Do spin_unlock_irqrestore and interruptible_sleep_on_timeout 560 * Do spin_unlock_irqrestore and interruptible_sleep_on_timeout
564* so that wake ups are not lost if they occur between the unlock 561 * so that wake ups are not lost if they occur between the unlock
565* and the sleep. In other words, spin_unlock_irqrestore and 562 * and the sleep. In other words, spin_unlock_irqrestore and
566* interruptible_sleep_on_timeout are "atomic" with respect to 563 * interruptible_sleep_on_timeout are "atomic" with respect to
567* wake ups. This is used to implement condition variables. 564 * wake ups. This is used to implement condition variables.
568* 565 *
569* interruptible_sleep_on_timeout is deprecated and has been replaced 566 * interruptible_sleep_on_timeout is deprecated and has been replaced
570* with the equivalent code. 567 * with the equivalent code.
571*/ 568 */
572 569
573static long cond_wait_interruptible_timeout_irqrestore( 570static long cond_wait_interruptible_timeout_irqrestore(
574 wait_queue_head_t *q, long timeout, 571 wait_queue_head_t *q, long timeout,
575 spinlock_t *lock, unsigned long flags) 572 spinlock_t *lock, unsigned long flags)
573__releases(lock)
576{ 574{
577 DEFINE_WAIT(wait); 575 DEFINE_WAIT(wait);
578 576
@@ -586,15 +584,16 @@ static long cond_wait_interruptible_timeout_irqrestore(
586 584
587 585
588/* 586/*
589* Digi Wakeup Write 587 * Digi Wakeup Write
590* 588 *
591* Wake up port, line discipline, and tty processes sleeping 589 * Wake up port, line discipline, and tty processes sleeping
592* on writes. 590 * on writes.
593*/ 591 */
594 592
595static void digi_wakeup_write_lock(struct work_struct *work) 593static void digi_wakeup_write_lock(struct work_struct *work)
596{ 594{
597 struct digi_port *priv = container_of(work, struct digi_port, dp_wakeup_work); 595 struct digi_port *priv =
596 container_of(work, struct digi_port, dp_wakeup_work);
598 struct usb_serial_port *port = priv->dp_port; 597 struct usb_serial_port *port = priv->dp_port;
599 unsigned long flags; 598 unsigned long flags;
600 599
@@ -605,20 +604,20 @@ static void digi_wakeup_write_lock(struct work_struct *work)
605 604
606static void digi_wakeup_write(struct usb_serial_port *port) 605static void digi_wakeup_write(struct usb_serial_port *port)
607{ 606{
608 tty_wakeup(port->tty); 607 tty_wakeup(port->port.tty);
609} 608}
610 609
611 610
612/* 611/*
613* Digi Write OOB Command 612 * Digi Write OOB Command
614* 613 *
615* Write commands on the out of band port. Commands are 4 614 * Write commands on the out of band port. Commands are 4
616* bytes each, multiple commands can be sent at once, and 615 * bytes each, multiple commands can be sent at once, and
617* no command will be split across USB packets. Returns 0 616 * no command will be split across USB packets. Returns 0
618* if successful, -EINTR if interrupted while sleeping and 617 * if successful, -EINTR if interrupted while sleeping and
619* the interruptible flag is true, or a negative error 618 * the interruptible flag is true, or a negative error
620* returned by usb_submit_urb. 619 * returned by usb_submit_urb.
621*/ 620 */
622 621
623static int digi_write_oob_command(struct usb_serial_port *port, 622static int digi_write_oob_command(struct usb_serial_port *port,
624 unsigned char *buf, int count, int interruptible) 623 unsigned char *buf, int count, int interruptible)
@@ -633,8 +632,8 @@ static int digi_write_oob_command(struct usb_serial_port *port,
633 dbg("digi_write_oob_command: TOP: port=%d, count=%d", oob_priv->dp_port_num, count); 632 dbg("digi_write_oob_command: TOP: port=%d, count=%d", oob_priv->dp_port_num, count);
634 633
635 spin_lock_irqsave(&oob_priv->dp_port_lock, flags); 634 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
636 while(count > 0) { 635 while (count > 0) {
637 while(oob_port->write_urb->status == -EINPROGRESS 636 while (oob_port->write_urb->status == -EINPROGRESS
638 || oob_priv->dp_write_urb_in_use) { 637 || oob_priv->dp_write_urb_in_use) {
639 cond_wait_interruptible_timeout_irqrestore( 638 cond_wait_interruptible_timeout_irqrestore(
640 &oob_port->write_wait, DIGI_RETRY_TIMEOUT, 639 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
@@ -651,7 +650,8 @@ static int digi_write_oob_command(struct usb_serial_port *port,
651 memcpy(oob_port->write_urb->transfer_buffer, buf, len); 650 memcpy(oob_port->write_urb->transfer_buffer, buf, len);
652 oob_port->write_urb->transfer_buffer_length = len; 651 oob_port->write_urb->transfer_buffer_length = len;
653 oob_port->write_urb->dev = port->serial->dev; 652 oob_port->write_urb->dev = port->serial->dev;
654 if ((ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC)) == 0) { 653 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
654 if (ret == 0) {
655 oob_priv->dp_write_urb_in_use = 1; 655 oob_priv->dp_write_urb_in_use = 1;
656 count -= len; 656 count -= len;
657 buf += len; 657 buf += len;
@@ -666,16 +666,16 @@ static int digi_write_oob_command(struct usb_serial_port *port,
666 666
667 667
668/* 668/*
669* Digi Write In Band Command 669 * Digi Write In Band Command
670* 670 *
671* Write commands on the given port. Commands are 4 671 * Write commands on the given port. Commands are 4
672* bytes each, multiple commands can be sent at once, and 672 * bytes each, multiple commands can be sent at once, and
673* no command will be split across USB packets. If timeout 673 * no command will be split across USB packets. If timeout
674* is non-zero, write in band command will return after 674 * is non-zero, write in band command will return after
675* waiting unsuccessfully for the URB status to clear for 675 * waiting unsuccessfully for the URB status to clear for
676* timeout ticks. Returns 0 if successful, or a negative 676 * timeout ticks. Returns 0 if successful, or a negative
677* error returned by digi_write. 677 * error returned by digi_write.
678*/ 678 */
679 679
680static int digi_write_inb_command(struct usb_serial_port *port, 680static int digi_write_inb_command(struct usb_serial_port *port,
681 unsigned char *buf, int count, unsigned long timeout) 681 unsigned char *buf, int count, unsigned long timeout)
@@ -695,9 +695,10 @@ static int digi_write_inb_command(struct usb_serial_port *port,
695 timeout = ULONG_MAX; 695 timeout = ULONG_MAX;
696 696
697 spin_lock_irqsave(&priv->dp_port_lock, flags); 697 spin_lock_irqsave(&priv->dp_port_lock, flags);
698 while(count > 0 && ret == 0) { 698 while (count > 0 && ret == 0) {
699 while((port->write_urb->status == -EINPROGRESS 699 while ((port->write_urb->status == -EINPROGRESS
700 || priv->dp_write_urb_in_use) && time_before(jiffies, timeout)) { 700 || priv->dp_write_urb_in_use)
701 && time_before(jiffies, timeout)) {
701 cond_wait_interruptible_timeout_irqrestore( 702 cond_wait_interruptible_timeout_irqrestore(
702 &port->write_wait, DIGI_RETRY_TIMEOUT, 703 &port->write_wait, DIGI_RETRY_TIMEOUT,
703 &priv->dp_port_lock, flags); 704 &priv->dp_port_lock, flags);
@@ -728,7 +729,8 @@ static int digi_write_inb_command(struct usb_serial_port *port,
728 } 729 }
729 port->write_urb->dev = port->serial->dev; 730 port->write_urb->dev = port->serial->dev;
730 731
731 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) { 732 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
733 if (ret == 0) {
732 priv->dp_write_urb_in_use = 1; 734 priv->dp_write_urb_in_use = 1;
733 priv->dp_out_buf_len = 0; 735 priv->dp_out_buf_len = 0;
734 count -= len; 736 count -= len;
@@ -746,14 +748,14 @@ static int digi_write_inb_command(struct usb_serial_port *port,
746 748
747 749
748/* 750/*
749* Digi Set Modem Signals 751 * Digi Set Modem Signals
750* 752 *
751* Sets or clears DTR and RTS on the port, according to the 753 * Sets or clears DTR and RTS on the port, according to the
752* modem_signals argument. Use TIOCM_DTR and TIOCM_RTS flags 754 * modem_signals argument. Use TIOCM_DTR and TIOCM_RTS flags
753* for the modem_signals argument. Returns 0 if successful, 755 * for the modem_signals argument. Returns 0 if successful,
754* -EINTR if interrupted while sleeping, or a non-zero error 756 * -EINTR if interrupted while sleeping, or a non-zero error
755* returned by usb_submit_urb. 757 * returned by usb_submit_urb.
756*/ 758 */
757 759
758static int digi_set_modem_signals(struct usb_serial_port *port, 760static int digi_set_modem_signals(struct usb_serial_port *port,
759 unsigned int modem_signals, int interruptible) 761 unsigned int modem_signals, int interruptible)
@@ -761,7 +763,7 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
761 763
762 int ret; 764 int ret;
763 struct digi_port *port_priv = usb_get_serial_port_data(port); 765 struct digi_port *port_priv = usb_get_serial_port_data(port);
764 struct usb_serial_port *oob_port = (struct usb_serial_port *)((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port; 766 struct usb_serial_port *oob_port = (struct usb_serial_port *) ((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port;
765 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port); 767 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port);
766 unsigned char *data = oob_port->write_urb->transfer_buffer; 768 unsigned char *data = oob_port->write_urb->transfer_buffer;
767 unsigned long flags = 0; 769 unsigned long flags = 0;
@@ -773,7 +775,8 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
773 spin_lock_irqsave(&oob_priv->dp_port_lock, flags); 775 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
774 spin_lock(&port_priv->dp_port_lock); 776 spin_lock(&port_priv->dp_port_lock);
775 777
776 while(oob_port->write_urb->status == -EINPROGRESS || oob_priv->dp_write_urb_in_use) { 778 while (oob_port->write_urb->status == -EINPROGRESS ||
779 oob_priv->dp_write_urb_in_use) {
777 spin_unlock(&port_priv->dp_port_lock); 780 spin_unlock(&port_priv->dp_port_lock);
778 cond_wait_interruptible_timeout_irqrestore( 781 cond_wait_interruptible_timeout_irqrestore(
779 &oob_port->write_wait, DIGI_RETRY_TIMEOUT, 782 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
@@ -785,17 +788,20 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
785 } 788 }
786 data[0] = DIGI_CMD_SET_DTR_SIGNAL; 789 data[0] = DIGI_CMD_SET_DTR_SIGNAL;
787 data[1] = port_priv->dp_port_num; 790 data[1] = port_priv->dp_port_num;
788 data[2] = (modem_signals&TIOCM_DTR) ? DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE; 791 data[2] = (modem_signals & TIOCM_DTR) ?
792 DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE;
789 data[3] = 0; 793 data[3] = 0;
790 data[4] = DIGI_CMD_SET_RTS_SIGNAL; 794 data[4] = DIGI_CMD_SET_RTS_SIGNAL;
791 data[5] = port_priv->dp_port_num; 795 data[5] = port_priv->dp_port_num;
792 data[6] = (modem_signals&TIOCM_RTS) ? DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE; 796 data[6] = (modem_signals & TIOCM_RTS) ?
797 DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE;
793 data[7] = 0; 798 data[7] = 0;
794 799
795 oob_port->write_urb->transfer_buffer_length = 8; 800 oob_port->write_urb->transfer_buffer_length = 8;
796 oob_port->write_urb->dev = port->serial->dev; 801 oob_port->write_urb->dev = port->serial->dev;
797 802
798 if ((ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC)) == 0) { 803 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
804 if (ret == 0) {
799 oob_priv->dp_write_urb_in_use = 1; 805 oob_priv->dp_write_urb_in_use = 1;
800 port_priv->dp_modem_signals = 806 port_priv->dp_modem_signals =
801 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS)) 807 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS))
@@ -809,16 +815,16 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
809} 815}
810 816
811/* 817/*
812* Digi Transmit Idle 818 * Digi Transmit Idle
813* 819 *
814* Digi transmit idle waits, up to timeout ticks, for the transmitter 820 * Digi transmit idle waits, up to timeout ticks, for the transmitter
815* to go idle. It returns 0 if successful or a negative error. 821 * to go idle. It returns 0 if successful or a negative error.
816* 822 *
817* There are race conditions here if more than one process is calling 823 * There are race conditions here if more than one process is calling
818* digi_transmit_idle on the same port at the same time. However, this 824 * digi_transmit_idle on the same port at the same time. However, this
819* is only called from close, and only one process can be in close on a 825 * is only called from close, and only one process can be in close on a
820* port at a time, so its ok. 826 * port at a time, so its ok.
821*/ 827 */
822 828
823static int digi_transmit_idle(struct usb_serial_port *port, 829static int digi_transmit_idle(struct usb_serial_port *port,
824 unsigned long timeout) 830 unsigned long timeout)
@@ -837,12 +843,13 @@ static int digi_transmit_idle(struct usb_serial_port *port,
837 843
838 timeout += jiffies; 844 timeout += jiffies;
839 845
840 if ((ret = digi_write_inb_command(port, buf, 2, timeout - jiffies)) != 0) 846 ret = digi_write_inb_command(port, buf, 2, timeout - jiffies);
847 if (ret != 0)
841 return ret; 848 return ret;
842 849
843 spin_lock_irqsave(&priv->dp_port_lock, flags); 850 spin_lock_irqsave(&priv->dp_port_lock, flags);
844 851
845 while(time_before(jiffies, timeout) && !priv->dp_transmit_idle) { 852 while (time_before(jiffies, timeout) && !priv->dp_transmit_idle) {
846 cond_wait_interruptible_timeout_irqrestore( 853 cond_wait_interruptible_timeout_irqrestore(
847 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT, 854 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT,
848 &priv->dp_port_lock, flags); 855 &priv->dp_port_lock, flags);
@@ -857,9 +864,10 @@ static int digi_transmit_idle(struct usb_serial_port *port,
857} 864}
858 865
859 866
860static void digi_rx_throttle(struct usb_serial_port *port) 867static void digi_rx_throttle(struct tty_struct *tty)
861{ 868{
862 unsigned long flags; 869 unsigned long flags;
870 struct usb_serial_port *port = tty->driver_data;
863 struct digi_port *priv = usb_get_serial_port_data(port); 871 struct digi_port *priv = usb_get_serial_port_data(port);
864 872
865 873
@@ -873,10 +881,11 @@ static void digi_rx_throttle(struct usb_serial_port *port)
873} 881}
874 882
875 883
876static void digi_rx_unthrottle(struct usb_serial_port *port) 884static void digi_rx_unthrottle(struct tty_struct *tty)
877{ 885{
878 int ret = 0; 886 int ret = 0;
879 unsigned long flags; 887 unsigned long flags;
888 struct usb_serial_port *port = tty->driver_data;
880 struct digi_port *priv = usb_get_serial_port_data(port); 889 struct digi_port *priv = usb_get_serial_port_data(port);
881 890
882 dbg("digi_rx_unthrottle: TOP: port=%d", priv->dp_port_num); 891 dbg("digi_rx_unthrottle: TOP: port=%d", priv->dp_port_num);
@@ -901,26 +910,25 @@ static void digi_rx_unthrottle(struct usb_serial_port *port)
901} 910}
902 911
903 912
904static void digi_set_termios(struct usb_serial_port *port, 913static void digi_set_termios(struct tty_struct *tty,
905 struct ktermios *old_termios) 914 struct usb_serial_port *port, struct ktermios *old_termios)
906{ 915{
907
908 struct digi_port *priv = usb_get_serial_port_data(port); 916 struct digi_port *priv = usb_get_serial_port_data(port);
909 struct tty_struct *tty = port->tty;
910 unsigned int iflag = tty->termios->c_iflag; 917 unsigned int iflag = tty->termios->c_iflag;
911 unsigned int cflag = tty->termios->c_cflag; 918 unsigned int cflag = tty->termios->c_cflag;
912 unsigned int old_iflag = old_termios->c_iflag; 919 unsigned int old_iflag = old_termios->c_iflag;
913 unsigned int old_cflag = old_termios->c_cflag; 920 unsigned int old_cflag = old_termios->c_cflag;
914 unsigned char buf[32]; 921 unsigned char buf[32];
915 unsigned int modem_signals; 922 unsigned int modem_signals;
916 int arg,ret; 923 int arg, ret;
917 int i = 0; 924 int i = 0;
918 speed_t baud; 925 speed_t baud;
919 926
920 dbg("digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, old_cflag=0x%x", priv->dp_port_num, iflag, old_iflag, cflag, old_cflag); 927 dbg("digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, old_cflag=0x%x", priv->dp_port_num, iflag, old_iflag, cflag, old_cflag);
921 928
922 /* set baud rate */ 929 /* set baud rate */
923 if ((baud = tty_get_baud_rate(tty)) != tty_termios_baud_rate(old_termios)) { 930 baud = tty_get_baud_rate(tty);
931 if (baud != tty_termios_baud_rate(old_termios)) {
924 arg = -1; 932 arg = -1;
925 933
926 /* reassert DTR and (maybe) RTS on transition from B0 */ 934 /* reassert DTR and (maybe) RTS on transition from B0 */
@@ -934,30 +942,30 @@ static void digi_set_termios(struct usb_serial_port *port,
934 digi_set_modem_signals(port, modem_signals, 1); 942 digi_set_modem_signals(port, modem_signals, 1);
935 } 943 }
936 switch (baud) { 944 switch (baud) {
937 /* drop DTR and RTS on transition to B0 */ 945 /* drop DTR and RTS on transition to B0 */
938 case 0: digi_set_modem_signals(port, 0, 1); break; 946 case 0: digi_set_modem_signals(port, 0, 1); break;
939 case 50: arg = DIGI_BAUD_50; break; 947 case 50: arg = DIGI_BAUD_50; break;
940 case 75: arg = DIGI_BAUD_75; break; 948 case 75: arg = DIGI_BAUD_75; break;
941 case 110: arg = DIGI_BAUD_110; break; 949 case 110: arg = DIGI_BAUD_110; break;
942 case 150: arg = DIGI_BAUD_150; break; 950 case 150: arg = DIGI_BAUD_150; break;
943 case 200: arg = DIGI_BAUD_200; break; 951 case 200: arg = DIGI_BAUD_200; break;
944 case 300: arg = DIGI_BAUD_300; break; 952 case 300: arg = DIGI_BAUD_300; break;
945 case 600: arg = DIGI_BAUD_600; break; 953 case 600: arg = DIGI_BAUD_600; break;
946 case 1200: arg = DIGI_BAUD_1200; break; 954 case 1200: arg = DIGI_BAUD_1200; break;
947 case 1800: arg = DIGI_BAUD_1800; break; 955 case 1800: arg = DIGI_BAUD_1800; break;
948 case 2400: arg = DIGI_BAUD_2400; break; 956 case 2400: arg = DIGI_BAUD_2400; break;
949 case 4800: arg = DIGI_BAUD_4800; break; 957 case 4800: arg = DIGI_BAUD_4800; break;
950 case 9600: arg = DIGI_BAUD_9600; break; 958 case 9600: arg = DIGI_BAUD_9600; break;
951 case 19200: arg = DIGI_BAUD_19200; break; 959 case 19200: arg = DIGI_BAUD_19200; break;
952 case 38400: arg = DIGI_BAUD_38400; break; 960 case 38400: arg = DIGI_BAUD_38400; break;
953 case 57600: arg = DIGI_BAUD_57600; break; 961 case 57600: arg = DIGI_BAUD_57600; break;
954 case 115200: arg = DIGI_BAUD_115200; break; 962 case 115200: arg = DIGI_BAUD_115200; break;
955 case 230400: arg = DIGI_BAUD_230400; break; 963 case 230400: arg = DIGI_BAUD_230400; break;
956 case 460800: arg = DIGI_BAUD_460800; break; 964 case 460800: arg = DIGI_BAUD_460800; break;
957 default: 965 default:
958 arg = DIGI_BAUD_9600; 966 arg = DIGI_BAUD_9600;
959 baud = 9600; 967 baud = 9600;
960 break; 968 break;
961 } 969 }
962 if (arg != -1) { 970 if (arg != -1) {
963 buf[i++] = DIGI_CMD_SET_BAUD_RATE; 971 buf[i++] = DIGI_CMD_SET_BAUD_RATE;
@@ -1083,14 +1091,16 @@ static void digi_set_termios(struct usb_serial_port *port,
1083 buf[i++] = arg; 1091 buf[i++] = arg;
1084 buf[i++] = 0; 1092 buf[i++] = 0;
1085 } 1093 }
1086 if ((ret = digi_write_oob_command(port, buf, i, 1)) != 0) 1094 ret = digi_write_oob_command(port, buf, i, 1);
1095 if (ret != 0)
1087 dbg("digi_set_termios: write oob failed, ret=%d", ret); 1096 dbg("digi_set_termios: write oob failed, ret=%d", ret);
1088 tty_encode_baud_rate(tty, baud, baud); 1097 tty_encode_baud_rate(tty, baud, baud);
1089} 1098}
1090 1099
1091 1100
1092static void digi_break_ctl(struct usb_serial_port *port, int break_state) 1101static void digi_break_ctl(struct tty_struct *tty, int break_state)
1093{ 1102{
1103 struct usb_serial_port *port = tty->driver_data;
1094 unsigned char buf[4]; 1104 unsigned char buf[4];
1095 1105
1096 buf[0] = DIGI_CMD_BREAK_CONTROL; 1106 buf[0] = DIGI_CMD_BREAK_CONTROL;
@@ -1101,8 +1111,9 @@ static void digi_break_ctl(struct usb_serial_port *port, int break_state)
1101} 1111}
1102 1112
1103 1113
1104static int digi_tiocmget(struct usb_serial_port *port, struct file *file) 1114static int digi_tiocmget(struct tty_struct *tty, struct file *file)
1105{ 1115{
1116 struct usb_serial_port *port = tty->driver_data;
1106 struct digi_port *priv = usb_get_serial_port_data(port); 1117 struct digi_port *priv = usb_get_serial_port_data(port);
1107 unsigned int val; 1118 unsigned int val;
1108 unsigned long flags; 1119 unsigned long flags;
@@ -1116,9 +1127,10 @@ static int digi_tiocmget(struct usb_serial_port *port, struct file *file)
1116} 1127}
1117 1128
1118 1129
1119static int digi_tiocmset(struct usb_serial_port *port, struct file *file, 1130static int digi_tiocmset(struct tty_struct *tty, struct file *file,
1120 unsigned int set, unsigned int clear) 1131 unsigned int set, unsigned int clear)
1121{ 1132{
1133 struct usb_serial_port *port = tty->driver_data;
1122 struct digi_port *priv = usb_get_serial_port_data(port); 1134 struct digi_port *priv = usb_get_serial_port_data(port);
1123 unsigned int val; 1135 unsigned int val;
1124 unsigned long flags; 1136 unsigned long flags;
@@ -1132,30 +1144,11 @@ static int digi_tiocmset(struct usb_serial_port *port, struct file *file,
1132} 1144}
1133 1145
1134 1146
1135static int digi_ioctl(struct usb_serial_port *port, struct file *file, 1147static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
1136 unsigned int cmd, unsigned long arg) 1148 const unsigned char *buf, int count)
1137{
1138 struct digi_port *priv = usb_get_serial_port_data(port);
1139 dbg("digi_ioctl: TOP: port=%d, cmd=0x%x", priv->dp_port_num, cmd);
1140
1141 switch (cmd) {
1142 case TIOCMIWAIT:
1143 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
1144 /* TODO */
1145 return 0;
1146 case TIOCGICOUNT:
1147 /* return count of modemline transitions */
1148 /* TODO */
1149 return 0;
1150 }
1151 return -ENOIOCTLCMD;
1152
1153}
1154
1155static int digi_write(struct usb_serial_port *port, const unsigned char *buf, int count)
1156{ 1149{
1157 1150
1158 int ret,data_len,new_len; 1151 int ret, data_len, new_len;
1159 struct digi_port *priv = usb_get_serial_port_data(port); 1152 struct digi_port *priv = usb_get_serial_port_data(port);
1160 unsigned char *data = port->write_urb->transfer_buffer; 1153 unsigned char *data = port->write_urb->transfer_buffer;
1161 unsigned long flags = 0; 1154 unsigned long flags = 0;
@@ -1173,7 +1166,8 @@ static int digi_write(struct usb_serial_port *port, const unsigned char *buf, in
1173 spin_lock_irqsave(&priv->dp_port_lock, flags); 1166 spin_lock_irqsave(&priv->dp_port_lock, flags);
1174 1167
1175 /* wait for urb status clear to submit another urb */ 1168 /* wait for urb status clear to submit another urb */
1176 if (port->write_urb->status == -EINPROGRESS || priv->dp_write_urb_in_use) { 1169 if (port->write_urb->status == -EINPROGRESS ||
1170 priv->dp_write_urb_in_use) {
1177 /* buffer data if count is 1 (probably put_char) if possible */ 1171 /* buffer data if count is 1 (probably put_char) if possible */
1178 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) { 1172 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) {
1179 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf; 1173 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf;
@@ -1208,7 +1202,8 @@ static int digi_write(struct usb_serial_port *port, const unsigned char *buf, in
1208 /* copy in new data */ 1202 /* copy in new data */
1209 memcpy(data, buf, new_len); 1203 memcpy(data, buf, new_len);
1210 1204
1211 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) { 1205 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1206 if (ret == 0) {
1212 priv->dp_write_urb_in_use = 1; 1207 priv->dp_write_urb_in_use = 1;
1213 ret = new_len; 1208 ret = new_len;
1214 priv->dp_out_buf_len = 0; 1209 priv->dp_out_buf_len = 0;
@@ -1222,7 +1217,7 @@ static int digi_write(struct usb_serial_port *port, const unsigned char *buf, in
1222 dbg("digi_write: returning %d", ret); 1217 dbg("digi_write: returning %d", ret);
1223 return ret; 1218 return ret;
1224 1219
1225} 1220}
1226 1221
1227static void digi_write_bulk_callback(struct urb *urb) 1222static void digi_write_bulk_callback(struct urb *urb)
1228{ 1223{
@@ -1237,13 +1232,13 @@ static void digi_write_bulk_callback(struct urb *urb)
1237 dbg("digi_write_bulk_callback: TOP, urb->status=%d", status); 1232 dbg("digi_write_bulk_callback: TOP, urb->status=%d", status);
1238 1233
1239 /* port and serial sanity check */ 1234 /* port and serial sanity check */
1240 if (port == NULL || (priv=usb_get_serial_port_data(port)) == NULL) { 1235 if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) {
1241 err("%s: port or port->private is NULL, status=%d", 1236 err("%s: port or port->private is NULL, status=%d",
1242 __func__, status); 1237 __func__, status);
1243 return; 1238 return;
1244 } 1239 }
1245 serial = port->serial; 1240 serial = port->serial;
1246 if (serial == NULL || (serial_priv=usb_get_serial_data(serial)) == NULL) { 1241 if (serial == NULL || (serial_priv = usb_get_serial_data(serial)) == NULL) {
1247 err("%s: serial or serial->private is NULL, status=%d", 1242 err("%s: serial or serial->private is NULL, status=%d",
1248 __func__, status); 1243 __func__, status);
1249 return; 1244 return;
@@ -1262,17 +1257,19 @@ static void digi_write_bulk_callback(struct urb *urb)
1262 /* try to send any buffered data on this port, if it is open */ 1257 /* try to send any buffered data on this port, if it is open */
1263 spin_lock(&priv->dp_port_lock); 1258 spin_lock(&priv->dp_port_lock);
1264 priv->dp_write_urb_in_use = 0; 1259 priv->dp_write_urb_in_use = 0;
1265 if (port->open_count && port->write_urb->status != -EINPROGRESS 1260 if (port->port.count && port->write_urb->status != -EINPROGRESS
1266 && priv->dp_out_buf_len > 0) { 1261 && priv->dp_out_buf_len > 0) {
1267 *((unsigned char *)(port->write_urb->transfer_buffer)) 1262 *((unsigned char *)(port->write_urb->transfer_buffer))
1268 = (unsigned char)DIGI_CMD_SEND_DATA; 1263 = (unsigned char)DIGI_CMD_SEND_DATA;
1269 *((unsigned char *)(port->write_urb->transfer_buffer)+1) 1264 *((unsigned char *)(port->write_urb->transfer_buffer) + 1)
1270 = (unsigned char)priv->dp_out_buf_len; 1265 = (unsigned char)priv->dp_out_buf_len;
1271 port->write_urb->transfer_buffer_length = priv->dp_out_buf_len+2; 1266 port->write_urb->transfer_buffer_length =
1267 priv->dp_out_buf_len + 2;
1272 port->write_urb->dev = serial->dev; 1268 port->write_urb->dev = serial->dev;
1273 memcpy(port->write_urb->transfer_buffer+2, priv->dp_out_buf, 1269 memcpy(port->write_urb->transfer_buffer + 2, priv->dp_out_buf,
1274 priv->dp_out_buf_len); 1270 priv->dp_out_buf_len);
1275 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) { 1271 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1272 if (ret == 0) {
1276 priv->dp_write_urb_in_use = 1; 1273 priv->dp_write_urb_in_use = 1;
1277 priv->dp_out_buf_len = 0; 1274 priv->dp_out_buf_len = 0;
1278 } 1275 }
@@ -1289,16 +1286,17 @@ static void digi_write_bulk_callback(struct urb *urb)
1289 __func__, ret, priv->dp_port_num); 1286 __func__, ret, priv->dp_port_num);
1290} 1287}
1291 1288
1292static int digi_write_room(struct usb_serial_port *port) 1289static int digi_write_room(struct tty_struct *tty)
1293{ 1290{
1294 1291 struct usb_serial_port *port = tty->driver_data;
1295 int room;
1296 struct digi_port *priv = usb_get_serial_port_data(port); 1292 struct digi_port *priv = usb_get_serial_port_data(port);
1293 int room;
1297 unsigned long flags = 0; 1294 unsigned long flags = 0;
1298 1295
1299 spin_lock_irqsave(&priv->dp_port_lock, flags); 1296 spin_lock_irqsave(&priv->dp_port_lock, flags);
1300 1297
1301 if (port->write_urb->status == -EINPROGRESS || priv->dp_write_urb_in_use) 1298 if (port->write_urb->status == -EINPROGRESS ||
1299 priv->dp_write_urb_in_use)
1302 room = 0; 1300 room = 0;
1303 else 1301 else
1304 room = port->bulk_out_size - 2 - priv->dp_out_buf_len; 1302 room = port->bulk_out_size - 2 - priv->dp_out_buf_len;
@@ -1309,12 +1307,11 @@ static int digi_write_room(struct usb_serial_port *port)
1309 1307
1310} 1308}
1311 1309
1312static int digi_chars_in_buffer(struct usb_serial_port *port) 1310static int digi_chars_in_buffer(struct tty_struct *tty)
1313{ 1311{
1314 1312 struct usb_serial_port *port = tty->driver_data;
1315 struct digi_port *priv = usb_get_serial_port_data(port); 1313 struct digi_port *priv = usb_get_serial_port_data(port);
1316 1314
1317
1318 if (port->write_urb->status == -EINPROGRESS 1315 if (port->write_urb->status == -EINPROGRESS
1319 || priv->dp_write_urb_in_use) { 1316 || priv->dp_write_urb_in_use) {
1320 dbg("digi_chars_in_buffer: port=%d, chars=%d", 1317 dbg("digi_chars_in_buffer: port=%d, chars=%d",
@@ -1330,7 +1327,8 @@ static int digi_chars_in_buffer(struct usb_serial_port *port)
1330} 1327}
1331 1328
1332 1329
1333static int digi_open(struct usb_serial_port *port, struct file *filp) 1330static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
1331 struct file *filp)
1334{ 1332{
1335 int ret; 1333 int ret;
1336 unsigned char buf[32]; 1334 unsigned char buf[32];
@@ -1339,7 +1337,7 @@ static int digi_open(struct usb_serial_port *port, struct file *filp)
1339 unsigned long flags = 0; 1337 unsigned long flags = 0;
1340 1338
1341 dbg("digi_open: TOP: port=%d, open_count=%d", 1339 dbg("digi_open: TOP: port=%d, open_count=%d",
1342 priv->dp_port_num, port->open_count); 1340 priv->dp_port_num, port->port.count);
1343 1341
1344 /* be sure the device is started up */ 1342 /* be sure the device is started up */
1345 if (digi_startup_device(port->serial) != 0) 1343 if (digi_startup_device(port->serial) != 0)
@@ -1354,7 +1352,7 @@ static int digi_open(struct usb_serial_port *port, struct file *filp)
1354 } 1352 }
1355 1353
1356 /* wait for a close in progress to finish */ 1354 /* wait for a close in progress to finish */
1357 while(priv->dp_in_close) { 1355 while (priv->dp_in_close) {
1358 cond_wait_interruptible_timeout_irqrestore( 1356 cond_wait_interruptible_timeout_irqrestore(
1359 &priv->dp_close_wait, DIGI_RETRY_TIMEOUT, 1357 &priv->dp_close_wait, DIGI_RETRY_TIMEOUT,
1360 &priv->dp_port_lock, flags); 1358 &priv->dp_port_lock, flags);
@@ -1364,7 +1362,7 @@ static int digi_open(struct usb_serial_port *port, struct file *filp)
1364 } 1362 }
1365 1363
1366 spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1364 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1367 1365
1368 /* read modem signals automatically whenever they change */ 1366 /* read modem signals automatically whenever they change */
1369 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS; 1367 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS;
1370 buf[1] = priv->dp_port_num; 1368 buf[1] = priv->dp_port_num;
@@ -1377,13 +1375,16 @@ static int digi_open(struct usb_serial_port *port, struct file *filp)
1377 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX; 1375 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1378 buf[7] = 0; 1376 buf[7] = 0;
1379 1377
1380 if ((ret = digi_write_oob_command(port, buf, 8, 1)) != 0) 1378 ret = digi_write_oob_command(port, buf, 8, 1);
1379 if (ret != 0)
1381 dbg("digi_open: write oob failed, ret=%d", ret); 1380 dbg("digi_open: write oob failed, ret=%d", ret);
1382 1381
1383 /* set termios settings */ 1382 /* set termios settings */
1384 not_termios.c_cflag = ~port->tty->termios->c_cflag; 1383 if (tty) {
1385 not_termios.c_iflag = ~port->tty->termios->c_iflag; 1384 not_termios.c_cflag = ~tty->termios->c_cflag;
1386 digi_set_termios(port, &not_termios); 1385 not_termios.c_iflag = ~tty->termios->c_iflag;
1386 digi_set_termios(tty, port, &not_termios);
1387 }
1387 1388
1388 /* set DTR and RTS */ 1389 /* set DTR and RTS */
1389 digi_set_modem_signals(port, TIOCM_DTR|TIOCM_RTS, 1); 1390 digi_set_modem_signals(port, TIOCM_DTR|TIOCM_RTS, 1);
@@ -1392,16 +1393,16 @@ static int digi_open(struct usb_serial_port *port, struct file *filp)
1392} 1393}
1393 1394
1394 1395
1395static void digi_close(struct usb_serial_port *port, struct file *filp) 1396static void digi_close(struct tty_struct *tty, struct usb_serial_port *port,
1397 struct file *filp)
1396{ 1398{
1397 DEFINE_WAIT(wait); 1399 DEFINE_WAIT(wait);
1398 int ret; 1400 int ret;
1399 unsigned char buf[32]; 1401 unsigned char buf[32];
1400 struct tty_struct *tty = port->tty;
1401 struct digi_port *priv = usb_get_serial_port_data(port); 1402 struct digi_port *priv = usb_get_serial_port_data(port);
1402 1403
1403 dbg("digi_close: TOP: port=%d, open_count=%d", 1404 dbg("digi_close: TOP: port=%d, open_count=%d",
1404 priv->dp_port_num, port->open_count); 1405 priv->dp_port_num, port->port.count);
1405 1406
1406 mutex_lock(&port->serial->disc_mutex); 1407 mutex_lock(&port->serial->disc_mutex);
1407 /* if disconnected, just clear flags */ 1408 /* if disconnected, just clear flags */
@@ -1426,9 +1427,8 @@ static void digi_close(struct usb_serial_port *port, struct file *filp)
1426 1427
1427 if (port->serial->dev) { 1428 if (port->serial->dev) {
1428 /* wait for transmit idle */ 1429 /* wait for transmit idle */
1429 if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) { 1430 if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0)
1430 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT); 1431 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1431 }
1432 /* drop DTR and RTS */ 1432 /* drop DTR and RTS */
1433 digi_set_modem_signals(port, 0, 0); 1433 digi_set_modem_signals(port, 0, 0);
1434 1434
@@ -1462,11 +1462,13 @@ static void digi_close(struct usb_serial_port *port, struct file *filp)
1462 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX; 1462 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1463 buf[19] = 0; 1463 buf[19] = 0;
1464 1464
1465 if ((ret = digi_write_oob_command(port, buf, 20, 0)) != 0) 1465 ret = digi_write_oob_command(port, buf, 20, 0);
1466 if (ret != 0)
1466 dbg("digi_close: write oob failed, ret=%d", ret); 1467 dbg("digi_close: write oob failed, ret=%d", ret);
1467 1468
1468 /* wait for final commands on oob port to complete */ 1469 /* wait for final commands on oob port to complete */
1469 prepare_to_wait(&priv->dp_flush_wait, &wait, TASK_INTERRUPTIBLE); 1470 prepare_to_wait(&priv->dp_flush_wait, &wait,
1471 TASK_INTERRUPTIBLE);
1470 schedule_timeout(DIGI_CLOSE_TIMEOUT); 1472 schedule_timeout(DIGI_CLOSE_TIMEOUT);
1471 finish_wait(&priv->dp_flush_wait, &wait); 1473 finish_wait(&priv->dp_flush_wait, &wait);
1472 1474
@@ -1486,15 +1488,15 @@ exit:
1486 1488
1487 1489
1488/* 1490/*
1489* Digi Startup Device 1491 * Digi Startup Device
1490* 1492 *
1491* Starts reads on all ports. Must be called AFTER startup, with 1493 * Starts reads on all ports. Must be called AFTER startup, with
1492* urbs initialized. Returns 0 if successful, non-zero error otherwise. 1494 * urbs initialized. Returns 0 if successful, non-zero error otherwise.
1493*/ 1495 */
1494 1496
1495static int digi_startup_device(struct usb_serial *serial) 1497static int digi_startup_device(struct usb_serial *serial)
1496{ 1498{
1497 int i,ret = 0; 1499 int i, ret = 0;
1498 struct digi_serial *serial_priv = usb_get_serial_data(serial); 1500 struct digi_serial *serial_priv = usb_get_serial_data(serial);
1499 struct usb_serial_port *port; 1501 struct usb_serial_port *port;
1500 1502
@@ -1512,7 +1514,8 @@ static int digi_startup_device(struct usb_serial *serial)
1512 for (i = 0; i < serial->type->num_ports + 1; i++) { 1514 for (i = 0; i < serial->type->num_ports + 1; i++) {
1513 port = serial->port[i]; 1515 port = serial->port[i];
1514 port->write_urb->dev = port->serial->dev; 1516 port->write_urb->dev = port->serial->dev;
1515 if ((ret = usb_submit_urb(port->read_urb, GFP_KERNEL)) != 0) { 1517 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
1518 if (ret != 0) {
1516 err("%s: usb_submit_urb failed, ret=%d, port=%d", 1519 err("%s: usb_submit_urb failed, ret=%d, port=%d",
1517 __func__, ret, i); 1520 __func__, ret, i);
1518 break; 1521 break;
@@ -1533,7 +1536,7 @@ static int digi_startup(struct usb_serial *serial)
1533 1536
1534 /* allocate the private data structures for all ports */ 1537 /* allocate the private data structures for all ports */
1535 /* number of regular ports + 1 for the out-of-band port */ 1538 /* number of regular ports + 1 for the out-of-band port */
1536 for(i = 0; i < serial->type->num_ports + 1; i++) { 1539 for (i = 0; i < serial->type->num_ports + 1; i++) {
1537 /* allocate port private structure */ 1540 /* allocate port private structure */
1538 priv = kmalloc(sizeof(struct digi_port), GFP_KERNEL); 1541 priv = kmalloc(sizeof(struct digi_port), GFP_KERNEL);
1539 if (priv == NULL) { 1542 if (priv == NULL) {
@@ -1596,7 +1599,7 @@ static void digi_shutdown(struct usb_serial *serial)
1596 1599
1597 /* free the private data structures for all ports */ 1600 /* free the private data structures for all ports */
1598 /* number of regular ports + 1 for the out-of-band port */ 1601 /* number of regular ports + 1 for the out-of-band port */
1599 for(i = 0; i < serial->type->num_ports + 1; i++) 1602 for (i = 0; i < serial->type->num_ports + 1; i++)
1600 kfree(usb_get_serial_port_data(serial->port[i])); 1603 kfree(usb_get_serial_port_data(serial->port[i]));
1601 kfree(usb_get_serial_data(serial)); 1604 kfree(usb_get_serial_data(serial));
1602} 1605}
@@ -1619,7 +1622,7 @@ static void digi_read_bulk_callback(struct urb *urb)
1619 return; 1622 return;
1620 } 1623 }
1621 if (port->serial == NULL || 1624 if (port->serial == NULL ||
1622 (serial_priv=usb_get_serial_data(port->serial)) == NULL) { 1625 (serial_priv = usb_get_serial_data(port->serial)) == NULL) {
1623 err("%s: serial is bad or serial->private is NULL, status=%d", 1626 err("%s: serial is bad or serial->private is NULL, status=%d",
1624 __func__, status); 1627 __func__, status);
1625 return; 1628 return;
@@ -1643,45 +1646,46 @@ static void digi_read_bulk_callback(struct urb *urb)
1643 1646
1644 /* continue read */ 1647 /* continue read */
1645 urb->dev = port->serial->dev; 1648 urb->dev = port->serial->dev;
1646 if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 1649 ret = usb_submit_urb(urb, GFP_ATOMIC);
1650 if (ret != 0) {
1647 err("%s: failed resubmitting urb, ret=%d, port=%d", 1651 err("%s: failed resubmitting urb, ret=%d, port=%d",
1648 __func__, ret, priv->dp_port_num); 1652 __func__, ret, priv->dp_port_num);
1649 } 1653 }
1650 1654
1651} 1655}
1652 1656
1653/* 1657/*
1654* Digi Read INB Callback 1658 * Digi Read INB Callback
1655* 1659 *
1656* Digi Read INB Callback handles reads on the in band ports, sending 1660 * Digi Read INB Callback handles reads on the in band ports, sending
1657* the data on to the tty subsystem. When called we know port and 1661 * the data on to the tty subsystem. When called we know port and
1658* port->private are not NULL and port->serial has been validated. 1662 * port->private are not NULL and port->serial has been validated.
1659* It returns 0 if successful, 1 if successful but the port is 1663 * It returns 0 if successful, 1 if successful but the port is
1660* throttled, and -1 if the sanity checks failed. 1664 * throttled, and -1 if the sanity checks failed.
1661*/ 1665 */
1662 1666
1663static int digi_read_inb_callback(struct urb *urb) 1667static int digi_read_inb_callback(struct urb *urb)
1664{ 1668{
1665 1669
1666 struct usb_serial_port *port = urb->context; 1670 struct usb_serial_port *port = urb->context;
1667 struct tty_struct *tty = port->tty; 1671 struct tty_struct *tty = port->port.tty;
1668 struct digi_port *priv = usb_get_serial_port_data(port); 1672 struct digi_port *priv = usb_get_serial_port_data(port);
1669 int opcode = ((unsigned char *)urb->transfer_buffer)[0]; 1673 int opcode = ((unsigned char *)urb->transfer_buffer)[0];
1670 int len = ((unsigned char *)urb->transfer_buffer)[1]; 1674 int len = ((unsigned char *)urb->transfer_buffer)[1];
1671 int port_status = ((unsigned char *)urb->transfer_buffer)[2]; 1675 int port_status = ((unsigned char *)urb->transfer_buffer)[2];
1672 unsigned char *data = ((unsigned char *)urb->transfer_buffer)+3; 1676 unsigned char *data = ((unsigned char *)urb->transfer_buffer) + 3;
1673 int flag,throttled; 1677 int flag, throttled;
1674 int i; 1678 int i;
1675 int status = urb->status; 1679 int status = urb->status;
1676 1680
1677 /* do not process callbacks on closed ports */ 1681 /* do not process callbacks on closed ports */
1678 /* but do continue the read chain */ 1682 /* but do continue the read chain */
1679 if (port->open_count == 0) 1683 if (port->port.count == 0)
1680 return 0; 1684 return 0;
1681 1685
1682 /* short/multiple packet check */ 1686 /* short/multiple packet check */
1683 if (urb->actual_length != len + 2) { 1687 if (urb->actual_length != len + 2) {
1684 err("%s: INCOMPLETE OR MULTIPLE PACKET, urb->status=%d, " 1688 err("%s: INCOMPLETE OR MULTIPLE PACKET, urb->status=%d, "
1685 "port=%d, opcode=%d, len=%d, actual_length=%d, " 1689 "port=%d, opcode=%d, len=%d, actual_length=%d, "
1686 "status=%d", __func__, status, priv->dp_port_num, 1690 "status=%d", __func__, status, priv->dp_port_num,
1687 opcode, len, urb->actual_length, port_status); 1691 opcode, len, urb->actual_length, port_status);
@@ -1723,8 +1727,9 @@ static int digi_read_inb_callback(struct urb *urb)
1723 if (flag == TTY_NORMAL) 1727 if (flag == TTY_NORMAL)
1724 tty_insert_flip_string(tty, data, len); 1728 tty_insert_flip_string(tty, data, len);
1725 else { 1729 else {
1726 for(i = 0; i < len; i++) 1730 for (i = 0; i < len; i++)
1727 tty_insert_flip_char(tty, data[i], flag); 1731 tty_insert_flip_char(tty,
1732 data[i], flag);
1728 } 1733 }
1729 tty_flip_buffer_push(tty); 1734 tty_flip_buffer_push(tty);
1730 } 1735 }
@@ -1736,19 +1741,19 @@ static int digi_read_inb_callback(struct urb *urb)
1736 else if (opcode != DIGI_CMD_RECEIVE_DATA) 1741 else if (opcode != DIGI_CMD_RECEIVE_DATA)
1737 dbg("%s: unknown opcode: %d", __func__, opcode); 1742 dbg("%s: unknown opcode: %d", __func__, opcode);
1738 1743
1739 return(throttled ? 1 : 0); 1744 return throttled ? 1 : 0;
1740 1745
1741} 1746}
1742 1747
1743 1748
1744/* 1749/*
1745* Digi Read OOB Callback 1750 * Digi Read OOB Callback
1746* 1751 *
1747* Digi Read OOB Callback handles reads on the out of band port. 1752 * Digi Read OOB Callback handles reads on the out of band port.
1748* When called we know port and port->private are not NULL and 1753 * When called we know port and port->private are not NULL and
1749* the port->serial is valid. It returns 0 if successful, and 1754 * the port->serial is valid. It returns 0 if successful, and
1750* -1 if the sanity checks failed. 1755 * -1 if the sanity checks failed.
1751*/ 1756 */
1752 1757
1753static int digi_read_oob_callback(struct urb *urb) 1758static int digi_read_oob_callback(struct urb *urb)
1754{ 1759{
@@ -1758,12 +1763,13 @@ static int digi_read_oob_callback(struct urb *urb)
1758 struct digi_port *priv = usb_get_serial_port_data(port); 1763 struct digi_port *priv = usb_get_serial_port_data(port);
1759 int opcode, line, status, val; 1764 int opcode, line, status, val;
1760 int i; 1765 int i;
1766 unsigned int rts;
1761 1767
1762 dbg("digi_read_oob_callback: port=%d, len=%d", 1768 dbg("digi_read_oob_callback: port=%d, len=%d",
1763 priv->dp_port_num, urb->actual_length); 1769 priv->dp_port_num, urb->actual_length);
1764 1770
1765 /* handle each oob command */ 1771 /* handle each oob command */
1766 for(i = 0; i < urb->actual_length - 3;) { 1772 for (i = 0; i < urb->actual_length - 3;) {
1767 opcode = ((unsigned char *)urb->transfer_buffer)[i++]; 1773 opcode = ((unsigned char *)urb->transfer_buffer)[i++];
1768 line = ((unsigned char *)urb->transfer_buffer)[i++]; 1774 line = ((unsigned char *)urb->transfer_buffer)[i++];
1769 status = ((unsigned char *)urb->transfer_buffer)[i++]; 1775 status = ((unsigned char *)urb->transfer_buffer)[i++];
@@ -1777,27 +1783,29 @@ static int digi_read_oob_callback(struct urb *urb)
1777 1783
1778 port = serial->port[line]; 1784 port = serial->port[line];
1779 1785
1780 if ((priv=usb_get_serial_port_data(port)) == NULL) 1786 priv = usb_get_serial_port_data(port);
1787 if (priv == NULL)
1781 return -1; 1788 return -1;
1782 1789
1790 rts = 0;
1791 if (port->port.count)
1792 rts = port->port.tty->termios->c_cflag & CRTSCTS;
1793
1783 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) { 1794 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
1784 spin_lock(&priv->dp_port_lock); 1795 spin_lock(&priv->dp_port_lock);
1785 /* convert from digi flags to termiox flags */ 1796 /* convert from digi flags to termiox flags */
1786 if (val & DIGI_READ_INPUT_SIGNALS_CTS) { 1797 if (val & DIGI_READ_INPUT_SIGNALS_CTS) {
1787 priv->dp_modem_signals |= TIOCM_CTS; 1798 priv->dp_modem_signals |= TIOCM_CTS;
1788 /* port must be open to use tty struct */ 1799 /* port must be open to use tty struct */
1789 if (port->open_count 1800 if (rts) {
1790 && port->tty->termios->c_cflag & CRTSCTS) { 1801 port->port.tty->hw_stopped = 0;
1791 port->tty->hw_stopped = 0;
1792 digi_wakeup_write(port); 1802 digi_wakeup_write(port);
1793 } 1803 }
1794 } else { 1804 } else {
1795 priv->dp_modem_signals &= ~TIOCM_CTS; 1805 priv->dp_modem_signals &= ~TIOCM_CTS;
1796 /* port must be open to use tty struct */ 1806 /* port must be open to use tty struct */
1797 if (port->open_count 1807 if (rts)
1798 && port->tty->termios->c_cflag & CRTSCTS) { 1808 port->port.tty->hw_stopped = 1;
1799 port->tty->hw_stopped = 1;
1800 }
1801 } 1809 }
1802 if (val & DIGI_READ_INPUT_SIGNALS_DSR) 1810 if (val & DIGI_READ_INPUT_SIGNALS_DSR)
1803 priv->dp_modem_signals |= TIOCM_DSR; 1811 priv->dp_modem_signals |= TIOCM_DSR;
@@ -1834,7 +1842,7 @@ static int __init digi_init(void)
1834 if (retval) 1842 if (retval)
1835 goto failed_acceleport_2_device; 1843 goto failed_acceleport_2_device;
1836 retval = usb_serial_register(&digi_acceleport_4_device); 1844 retval = usb_serial_register(&digi_acceleport_4_device);
1837 if (retval) 1845 if (retval)
1838 goto failed_acceleport_4_device; 1846 goto failed_acceleport_4_device;
1839 retval = usb_register(&digi_driver); 1847 retval = usb_register(&digi_driver);
1840 if (retval) 1848 if (retval)
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index c5ec309a3cb1..a6ab5b58d9ca 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -11,36 +11,39 @@
11 * it under the terms of the GNU General Public License, as published by 11 * it under the terms of the GNU General Public License, as published by
12 * the Free Software Foundation, version 2. 12 * the Free Software Foundation, version 2.
13 * 13 *
14 * See Documentation/usb/usb-serial.txt for more information on using this driver 14 * See Documentation/usb/usb-serial.txt for more information on using this
15 * 15 * driver
16 *
16 * (07/16/2001) gb 17 * (07/16/2001) gb
17 * remove unused code in empeg_close() (thanks to Oliver Neukum for pointing this 18 * remove unused code in empeg_close() (thanks to Oliver Neukum for
18 * out) and rewrote empeg_set_termios(). 19 * pointing this out) and rewrote empeg_set_termios().
19 * 20 *
20 * (05/30/2001) gkh 21 * (05/30/2001) gkh
21 * switched from using spinlock to a semaphore, which fixes lots of problems. 22 * switched from using spinlock to a semaphore, which fixes lots of
23 * problems.
22 * 24 *
23 * (04/08/2001) gb 25 * (04/08/2001) gb
24 * Identify version on module load. 26 * Identify version on module load.
25 * 27 *
26 * (01/22/2001) gb 28 * (01/22/2001) gb
27 * Added write_room() and chars_in_buffer() support. 29 * Added write_room() and chars_in_buffer() support.
28 * 30 *
29 * (12/21/2000) gb 31 * (12/21/2000) gb
30 * Moved termio stuff inside the port->active check. 32 * Moved termio stuff inside the port->active check.
31 * Moved MOD_DEC_USE_COUNT to end of empeg_close(). 33 * Moved MOD_DEC_USE_COUNT to end of empeg_close().
32 * 34 *
33 * (12/03/2000) gb 35 * (12/03/2000) gb
34 * Added port->tty->ldisc.set_termios(port->tty, NULL) to empeg_open() 36 * Added port->port.tty->ldisc.set_termios(port->port.tty, NULL) to
35 * This notifies the tty driver that the termios have changed. 37 * empeg_open(). This notifies the tty driver that the termios have
36 * 38 * changed.
39 *
37 * (11/13/2000) gb 40 * (11/13/2000) gb
38 * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to empeg_open() 41 * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to
39 * (It only needs to be set once - Doh!) 42 * empeg_open() (It only needs to be set once - Doh!)
40 * 43 *
41 * (11/11/2000) gb 44 * (11/11/2000) gb
42 * Updated to work with id_table structure. 45 * Updated to work with id_table structure.
43 * 46 *
44 * (11/04/2000) gb 47 * (11/04/2000) gb
45 * Forked this from visor.c, and hacked it up to work with an 48 * Forked this from visor.c, and hacked it up to work with an
46 * Empeg ltd. empeg-car player. Constructive criticism welcomed. 49 * Empeg ltd. empeg-car player. Constructive criticism welcomed.
@@ -48,7 +51,7 @@
48 * use of his code, and for his guidance, advice and patience. :) 51 * use of his code, and for his guidance, advice and patience. :)
49 * A 'Thank You' is in order for John Ripley of Empeg ltd for his 52 * A 'Thank You' is in order for John Ripley of Empeg ltd for his
50 * advice, and patience too. 53 * advice, and patience too.
51 * 54 *
52 */ 55 */
53 56
54#include <linux/kernel.h> 57#include <linux/kernel.h>
@@ -60,7 +63,7 @@
60#include <linux/tty_flip.h> 63#include <linux/tty_flip.h>
61#include <linux/module.h> 64#include <linux/module.h>
62#include <linux/spinlock.h> 65#include <linux/spinlock.h>
63#include <asm/uaccess.h> 66#include <linux/uaccess.h>
64#include <linux/usb.h> 67#include <linux/usb.h>
65#include <linux/usb/serial.h> 68#include <linux/usb/serial.h>
66 69
@@ -77,31 +80,30 @@ static int debug;
77#define EMPEG_PRODUCT_ID 0x0001 80#define EMPEG_PRODUCT_ID 0x0001
78 81
79/* function prototypes for an empeg-car player */ 82/* function prototypes for an empeg-car player */
80static int empeg_open (struct usb_serial_port *port, struct file *filp); 83static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
81static void empeg_close (struct usb_serial_port *port, struct file *filp); 84 struct file *filp);
82static int empeg_write (struct usb_serial_port *port, 85static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port,
83 const unsigned char *buf, 86 struct file *filp);
84 int count); 87static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
85static int empeg_write_room (struct usb_serial_port *port); 88 const unsigned char *buf,
86static int empeg_chars_in_buffer (struct usb_serial_port *port); 89 int count);
87static void empeg_throttle (struct usb_serial_port *port); 90static int empeg_write_room(struct tty_struct *tty);
88static void empeg_unthrottle (struct usb_serial_port *port); 91static int empeg_chars_in_buffer(struct tty_struct *tty);
89static int empeg_startup (struct usb_serial *serial); 92static void empeg_throttle(struct tty_struct *tty);
90static void empeg_shutdown (struct usb_serial *serial); 93static void empeg_unthrottle(struct tty_struct *tty);
91static int empeg_ioctl (struct usb_serial_port *port, 94static int empeg_startup(struct usb_serial *serial);
92 struct file * file, 95static void empeg_shutdown(struct usb_serial *serial);
93 unsigned int cmd, 96static void empeg_set_termios(struct tty_struct *tty,
94 unsigned long arg); 97 struct usb_serial_port *port, struct ktermios *old_termios);
95static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *old_termios); 98static void empeg_write_bulk_callback(struct urb *urb);
96static void empeg_write_bulk_callback (struct urb *urb); 99static void empeg_read_bulk_callback(struct urb *urb);
97static void empeg_read_bulk_callback (struct urb *urb);
98 100
99static struct usb_device_id id_table [] = { 101static struct usb_device_id id_table [] = {
100 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) }, 102 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) },
101 { } /* Terminating entry */ 103 { } /* Terminating entry */
102}; 104};
103 105
104MODULE_DEVICE_TABLE (usb, id_table); 106MODULE_DEVICE_TABLE(usb, id_table);
105 107
106static struct usb_driver empeg_driver = { 108static struct usb_driver empeg_driver = {
107 .name = "empeg", 109 .name = "empeg",
@@ -125,7 +127,6 @@ static struct usb_serial_driver empeg_device = {
125 .unthrottle = empeg_unthrottle, 127 .unthrottle = empeg_unthrottle,
126 .attach = empeg_startup, 128 .attach = empeg_startup,
127 .shutdown = empeg_shutdown, 129 .shutdown = empeg_shutdown,
128 .ioctl = empeg_ioctl,
129 .set_termios = empeg_set_termios, 130 .set_termios = empeg_set_termios,
130 .write = empeg_write, 131 .write = empeg_write,
131 .write_room = empeg_write_room, 132 .write_room = empeg_write_room,
@@ -145,7 +146,8 @@ static int bytes_out;
145/****************************************************************************** 146/******************************************************************************
146 * Empeg specific driver functions 147 * Empeg specific driver functions
147 ******************************************************************************/ 148 ******************************************************************************/
148static int empeg_open (struct usb_serial_port *port, struct file *filp) 149static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
150 struct file *filp)
149{ 151{
150 struct usb_serial *serial = port->serial; 152 struct usb_serial *serial = port->serial;
151 int result = 0; 153 int result = 0;
@@ -153,7 +155,7 @@ static int empeg_open (struct usb_serial_port *port, struct file *filp)
153 dbg("%s - port %d", __func__, port->number); 155 dbg("%s - port %d", __func__, port->number);
154 156
155 /* Force default termio settings */ 157 /* Force default termio settings */
156 empeg_set_termios (port, NULL) ; 158 empeg_set_termios(tty, port, NULL) ;
157 159
158 bytes_in = 0; 160 bytes_in = 0;
159 bytes_out = 0; 161 bytes_out = 0;
@@ -161,7 +163,7 @@ static int empeg_open (struct usb_serial_port *port, struct file *filp)
161 /* Start reading from the device */ 163 /* Start reading from the device */
162 usb_fill_bulk_urb( 164 usb_fill_bulk_urb(
163 port->read_urb, 165 port->read_urb,
164 serial->dev, 166 serial->dev,
165 usb_rcvbulkpipe(serial->dev, 167 usb_rcvbulkpipe(serial->dev,
166 port->bulk_in_endpointAddress), 168 port->bulk_in_endpointAddress),
167 port->read_urb->transfer_buffer, 169 port->read_urb->transfer_buffer,
@@ -172,13 +174,16 @@ static int empeg_open (struct usb_serial_port *port, struct file *filp)
172 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 174 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
173 175
174 if (result) 176 if (result)
175 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 177 dev_err(&port->dev,
178 "%s - failed submitting read urb, error %d\n",
179 __func__, result);
176 180
177 return result; 181 return result;
178} 182}
179 183
180 184
181static void empeg_close (struct usb_serial_port *port, struct file * filp) 185static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port,
186 struct file *filp)
182{ 187{
183 dbg("%s - port %d", __func__, port->number); 188 dbg("%s - port %d", __func__, port->number);
184 189
@@ -189,7 +194,8 @@ static void empeg_close (struct usb_serial_port *port, struct file * filp)
189} 194}
190 195
191 196
192static int empeg_write (struct usb_serial_port *port, const unsigned char *buf, int count) 197static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
198 const unsigned char *buf, int count)
193{ 199{
194 struct usb_serial *serial = port->serial; 200 struct usb_serial *serial = port->serial;
195 struct urb *urb; 201 struct urb *urb;
@@ -203,11 +209,10 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
203 dbg("%s - port %d", __func__, port->number); 209 dbg("%s - port %d", __func__, port->number);
204 210
205 while (count > 0) { 211 while (count > 0) {
206
207 /* try to find a free urb in our list of them */ 212 /* try to find a free urb in our list of them */
208 urb = NULL; 213 urb = NULL;
209 214
210 spin_lock_irqsave (&write_urb_pool_lock, flags); 215 spin_lock_irqsave(&write_urb_pool_lock, flags);
211 216
212 for (i = 0; i < NUM_URBS; ++i) { 217 for (i = 0; i < NUM_URBS; ++i) {
213 if (write_urb_pool[i]->status != -EINPROGRESS) { 218 if (write_urb_pool[i]->status != -EINPROGRESS) {
@@ -216,7 +221,7 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
216 } 221 }
217 } 222 }
218 223
219 spin_unlock_irqrestore (&write_urb_pool_lock, flags); 224 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
220 225
221 if (urb == NULL) { 226 if (urb == NULL) {
222 dbg("%s - no more free urbs", __func__); 227 dbg("%s - no more free urbs", __func__);
@@ -224,25 +229,27 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
224 } 229 }
225 230
226 if (urb->transfer_buffer == NULL) { 231 if (urb->transfer_buffer == NULL) {
227 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); 232 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
228 if (urb->transfer_buffer == NULL) { 233 if (urb->transfer_buffer == NULL) {
229 dev_err(&port->dev, "%s no more kernel memory...\n", __func__); 234 dev_err(&port->dev,
235 "%s no more kernel memory...\n",
236 __func__);
230 goto exit; 237 goto exit;
231 } 238 }
232 } 239 }
233 240
234 transfer_size = min (count, URB_TRANSFER_BUFFER_SIZE); 241 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
235 242
236 memcpy (urb->transfer_buffer, current_position, transfer_size); 243 memcpy(urb->transfer_buffer, current_position, transfer_size);
237 244
238 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer); 245 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer);
239 246
240 /* build up our urb */ 247 /* build up our urb */
241 usb_fill_bulk_urb ( 248 usb_fill_bulk_urb(
242 urb, 249 urb,
243 serial->dev, 250 serial->dev,
244 usb_sndbulkpipe(serial->dev, 251 usb_sndbulkpipe(serial->dev,
245 port->bulk_out_endpointAddress), 252 port->bulk_out_endpointAddress),
246 urb->transfer_buffer, 253 urb->transfer_buffer,
247 transfer_size, 254 transfer_size,
248 empeg_write_bulk_callback, 255 empeg_write_bulk_callback,
@@ -262,66 +269,57 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
262 bytes_out += transfer_size; 269 bytes_out += transfer_size;
263 270
264 } 271 }
265
266exit: 272exit:
267 return bytes_sent; 273 return bytes_sent;
268 274}
269}
270 275
271 276
272static int empeg_write_room (struct usb_serial_port *port) 277static int empeg_write_room(struct tty_struct *tty)
273{ 278{
279 struct usb_serial_port *port = tty->driver_data;
274 unsigned long flags; 280 unsigned long flags;
275 int i; 281 int i;
276 int room = 0; 282 int room = 0;
277 283
278 dbg("%s - port %d", __func__, port->number); 284 dbg("%s - port %d", __func__, port->number);
279 285
280 spin_lock_irqsave (&write_urb_pool_lock, flags); 286 spin_lock_irqsave(&write_urb_pool_lock, flags);
281
282 /* tally up the number of bytes available */ 287 /* tally up the number of bytes available */
283 for (i = 0; i < NUM_URBS; ++i) { 288 for (i = 0; i < NUM_URBS; ++i) {
284 if (write_urb_pool[i]->status != -EINPROGRESS) { 289 if (write_urb_pool[i]->status != -EINPROGRESS)
285 room += URB_TRANSFER_BUFFER_SIZE; 290 room += URB_TRANSFER_BUFFER_SIZE;
286 } 291 }
287 } 292 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
288
289 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
290
291 dbg("%s - returns %d", __func__, room); 293 dbg("%s - returns %d", __func__, room);
292 294 return room;
293 return (room);
294 295
295} 296}
296 297
297 298
298static int empeg_chars_in_buffer (struct usb_serial_port *port) 299static int empeg_chars_in_buffer(struct tty_struct *tty)
299{ 300{
301 struct usb_serial_port *port = tty->driver_data;
300 unsigned long flags; 302 unsigned long flags;
301 int i; 303 int i;
302 int chars = 0; 304 int chars = 0;
303 305
304 dbg("%s - port %d", __func__, port->number); 306 dbg("%s - port %d", __func__, port->number);
305 307
306 spin_lock_irqsave (&write_urb_pool_lock, flags); 308 spin_lock_irqsave(&write_urb_pool_lock, flags);
307 309
308 /* tally up the number of bytes waiting */ 310 /* tally up the number of bytes waiting */
309 for (i = 0; i < NUM_URBS; ++i) { 311 for (i = 0; i < NUM_URBS; ++i) {
310 if (write_urb_pool[i]->status == -EINPROGRESS) { 312 if (write_urb_pool[i]->status == -EINPROGRESS)
311 chars += URB_TRANSFER_BUFFER_SIZE; 313 chars += URB_TRANSFER_BUFFER_SIZE;
312 }
313 } 314 }
314 315
315 spin_unlock_irqrestore (&write_urb_pool_lock, flags); 316 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
316
317 dbg("%s - returns %d", __func__, chars); 317 dbg("%s - returns %d", __func__, chars);
318 318 return chars;
319 return (chars);
320
321} 319}
322 320
323 321
324static void empeg_write_bulk_callback (struct urb *urb) 322static void empeg_write_bulk_callback(struct urb *urb)
325{ 323{
326 struct usb_serial_port *port = urb->context; 324 struct usb_serial_port *port = urb->context;
327 int status = urb->status; 325 int status = urb->status;
@@ -338,7 +336,7 @@ static void empeg_write_bulk_callback (struct urb *urb)
338} 336}
339 337
340 338
341static void empeg_read_bulk_callback (struct urb *urb) 339static void empeg_read_bulk_callback(struct urb *urb)
342{ 340{
343 struct usb_serial_port *port = urb->context; 341 struct usb_serial_port *port = urb->context;
344 struct tty_struct *tty; 342 struct tty_struct *tty;
@@ -354,9 +352,9 @@ static void empeg_read_bulk_callback (struct urb *urb)
354 return; 352 return;
355 } 353 }
356 354
357 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 355 usb_serial_debug_data(debug, &port->dev, __func__,
358 356 urb->actual_length, data);
359 tty = port->tty; 357 tty = port->port.tty;
360 358
361 if (urb->actual_length) { 359 if (urb->actual_length) {
362 tty_buffer_request_room(tty, urb->actual_length); 360 tty_buffer_request_room(tty, urb->actual_length);
@@ -368,7 +366,7 @@ static void empeg_read_bulk_callback (struct urb *urb)
368 /* Continue trying to always read */ 366 /* Continue trying to always read */
369 usb_fill_bulk_urb( 367 usb_fill_bulk_urb(
370 port->read_urb, 368 port->read_urb,
371 port->serial->dev, 369 port->serial->dev,
372 usb_rcvbulkpipe(port->serial->dev, 370 usb_rcvbulkpipe(port->serial->dev,
373 port->bulk_in_endpointAddress), 371 port->bulk_in_endpointAddress),
374 port->read_urb->transfer_buffer, 372 port->read_urb->transfer_buffer,
@@ -379,38 +377,39 @@ static void empeg_read_bulk_callback (struct urb *urb)
379 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 377 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
380 378
381 if (result) 379 if (result)
382 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 380 dev_err(&urb->dev->dev,
381 "%s - failed resubmitting read urb, error %d\n",
382 __func__, result);
383 383
384 return; 384 return;
385 385
386} 386}
387 387
388 388
389static void empeg_throttle (struct usb_serial_port *port) 389static void empeg_throttle(struct tty_struct *tty)
390{ 390{
391 struct usb_serial_port *port = tty->driver_data;
391 dbg("%s - port %d", __func__, port->number); 392 dbg("%s - port %d", __func__, port->number);
392 usb_kill_urb(port->read_urb); 393 usb_kill_urb(port->read_urb);
393} 394}
394 395
395 396
396static void empeg_unthrottle (struct usb_serial_port *port) 397static void empeg_unthrottle(struct tty_struct *tty)
397{ 398{
399 struct usb_serial_port *port = tty->driver_data;
398 int result; 400 int result;
399
400 dbg("%s - port %d", __func__, port->number); 401 dbg("%s - port %d", __func__, port->number);
401 402
402 port->read_urb->dev = port->serial->dev; 403 port->read_urb->dev = port->serial->dev;
403
404 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 404 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
405
406 if (result) 405 if (result)
407 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 406 dev_err(&port->dev,
408 407 "%s - failed submitting read urb, error %d\n",
409 return; 408 __func__, result);
410} 409}
411 410
412 411
413static int empeg_startup (struct usb_serial *serial) 412static int empeg_startup(struct usb_serial *serial)
414{ 413{
415 int r; 414 int r;
416 415
@@ -422,7 +421,7 @@ static int empeg_startup (struct usb_serial *serial)
422 return -ENODEV; 421 return -ENODEV;
423 } 422 }
424 dbg("%s - reset config", __func__); 423 dbg("%s - reset config", __func__);
425 r = usb_reset_configuration (serial->dev); 424 r = usb_reset_configuration(serial->dev);
426 425
427 /* continue on with initialization */ 426 /* continue on with initialization */
428 return r; 427 return r;
@@ -430,34 +429,27 @@ static int empeg_startup (struct usb_serial *serial)
430} 429}
431 430
432 431
433static void empeg_shutdown (struct usb_serial *serial) 432static void empeg_shutdown(struct usb_serial *serial)
434{ 433{
435 dbg ("%s", __func__); 434 dbg("%s", __func__);
436}
437
438
439static int empeg_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
440{
441 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
442
443 return -ENOIOCTLCMD;
444} 435}
445 436
446 437
447static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 438static void empeg_set_termios(struct tty_struct *tty,
439 struct usb_serial_port *port, struct ktermios *old_termios)
448{ 440{
449 struct ktermios *termios = port->tty->termios; 441 struct ktermios *termios = tty->termios;
450 dbg("%s - port %d", __func__, port->number); 442 dbg("%s - port %d", __func__, port->number);
451 443
452 /* 444 /*
453 * The empeg-car player wants these particular tty settings. 445 * The empeg-car player wants these particular tty settings.
454 * You could, for example, change the baud rate, however the 446 * You could, for example, change the baud rate, however the
455 * player only supports 115200 (currently), so there is really 447 * player only supports 115200 (currently), so there is really
456 * no point in support for changes to the tty settings. 448 * no point in support for changes to the tty settings.
457 * (at least for now) 449 * (at least for now)
458 * 450 *
459 * The default requirements for this device are: 451 * The default requirements for this device are:
460 */ 452 */
461 termios->c_iflag 453 termios->c_iflag
462 &= ~(IGNBRK /* disable ignore break */ 454 &= ~(IGNBRK /* disable ignore break */
463 | BRKINT /* disable break causes interrupt */ 455 | BRKINT /* disable break causes interrupt */
@@ -491,18 +483,18 @@ static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *ol
491 * this is bad as it opens up the possibility of dropping bytes 483 * this is bad as it opens up the possibility of dropping bytes
492 * on the floor. We don't want to drop bytes on the floor. :) 484 * on the floor. We don't want to drop bytes on the floor. :)
493 */ 485 */
494 port->tty->low_latency = 1; 486 tty->low_latency = 1;
495 tty_encode_baud_rate(port->tty, 115200, 115200); 487 tty_encode_baud_rate(tty, 115200, 115200);
496} 488}
497 489
498 490
499static int __init empeg_init (void) 491static int __init empeg_init(void)
500{ 492{
501 struct urb *urb; 493 struct urb *urb;
502 int i, retval; 494 int i, retval;
503 495
504 /* create our write urb pool and transfer buffers */ 496 /* create our write urb pool and transfer buffers */
505 spin_lock_init (&write_urb_pool_lock); 497 spin_lock_init(&write_urb_pool_lock);
506 for (i = 0; i < NUM_URBS; ++i) { 498 for (i = 0; i < NUM_URBS; ++i) {
507 urb = usb_alloc_urb(0, GFP_KERNEL); 499 urb = usb_alloc_urb(0, GFP_KERNEL);
508 write_urb_pool[i] = urb; 500 write_urb_pool[i] = urb;
@@ -511,9 +503,10 @@ static int __init empeg_init (void)
511 continue; 503 continue;
512 } 504 }
513 505
514 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 506 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
507 GFP_KERNEL);
515 if (!urb->transfer_buffer) { 508 if (!urb->transfer_buffer) {
516 err("%s - out of memory for urb buffers.", 509 err("%s - out of memory for urb buffers.",
517 __func__); 510 __func__);
518 continue; 511 continue;
519 } 512 }
@@ -542,36 +535,36 @@ failed_usb_serial_register:
542} 535}
543 536
544 537
545static void __exit empeg_exit (void) 538static void __exit empeg_exit(void)
546{ 539{
547 int i; 540 int i;
548 unsigned long flags; 541 unsigned long flags;
549 542
550 usb_deregister(&empeg_driver); 543 usb_deregister(&empeg_driver);
551 usb_serial_deregister (&empeg_device); 544 usb_serial_deregister(&empeg_device);
552 545
553 spin_lock_irqsave (&write_urb_pool_lock, flags); 546 spin_lock_irqsave(&write_urb_pool_lock, flags);
554 547
555 for (i = 0; i < NUM_URBS; ++i) { 548 for (i = 0; i < NUM_URBS; ++i) {
556 if (write_urb_pool[i]) { 549 if (write_urb_pool[i]) {
557 /* FIXME - uncomment the following usb_kill_urb call when 550 /* FIXME - uncomment the following usb_kill_urb call
558 * the host controllers get fixed to set urb->dev = NULL after 551 * when the host controllers get fixed to set urb->dev
559 * the urb is finished. Otherwise this call oopses. */ 552 * = NULL after the urb is finished. Otherwise this
553 * call oopses. */
560 /* usb_kill_urb(write_urb_pool[i]); */ 554 /* usb_kill_urb(write_urb_pool[i]); */
561 kfree(write_urb_pool[i]->transfer_buffer); 555 kfree(write_urb_pool[i]->transfer_buffer);
562 usb_free_urb (write_urb_pool[i]); 556 usb_free_urb(write_urb_pool[i]);
563 } 557 }
564 } 558 }
565 559 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
566 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
567} 560}
568 561
569 562
570module_init(empeg_init); 563module_init(empeg_init);
571module_exit(empeg_exit); 564module_exit(empeg_exit);
572 565
573MODULE_AUTHOR( DRIVER_AUTHOR ); 566MODULE_AUTHOR(DRIVER_AUTHOR);
574MODULE_DESCRIPTION( DRIVER_DESC ); 567MODULE_DESCRIPTION(DRIVER_DESC);
575MODULE_LICENSE("GPL"); 568MODULE_LICENSE("GPL");
576 569
577module_param(debug, bool, S_IRUGO | S_IWUSR); 570module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/ezusb.c b/drivers/usb/serial/ezusb.c
index cc4fbd9d60be..711e84f6ed82 100644
--- a/drivers/usb/serial/ezusb.c
+++ b/drivers/usb/serial/ezusb.c
@@ -20,7 +20,8 @@
20/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */ 20/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */
21#define CPUCS_REG 0x7F92 21#define CPUCS_REG 0x7F92
22 22
23int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *data, int length, __u8 bRequest) 23int ezusb_writememory(struct usb_serial *serial, int address,
24 unsigned char *data, int length, __u8 request)
24{ 25{
25 int result; 26 int result;
26 unsigned char *transfer_buffer; 27 unsigned char *transfer_buffer;
@@ -33,26 +34,27 @@ int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *da
33 34
34 transfer_buffer = kmemdup(data, length, GFP_KERNEL); 35 transfer_buffer = kmemdup(data, length, GFP_KERNEL);
35 if (!transfer_buffer) { 36 if (!transfer_buffer) {
36 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, length); 37 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n",
38 __func__, length);
37 return -ENOMEM; 39 return -ENOMEM;
38 } 40 }
39 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), bRequest, 0x40, address, 0, transfer_buffer, length, 3000); 41 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
40 kfree (transfer_buffer); 42 request, 0x40, address, 0, transfer_buffer, length, 3000);
43 kfree(transfer_buffer);
41 return result; 44 return result;
42} 45}
46EXPORT_SYMBOL_GPL(ezusb_writememory);
43 47
44int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit) 48int ezusb_set_reset(struct usb_serial *serial, unsigned char reset_bit)
45{ 49{
46 int response; 50 int response;
47 51
48 /* dbg("%s - %d", __func__, reset_bit); */ 52 /* dbg("%s - %d", __func__, reset_bit); */
49 response = ezusb_writememory (serial, CPUCS_REG, &reset_bit, 1, 0xa0); 53 response = ezusb_writememory(serial, CPUCS_REG, &reset_bit, 1, 0xa0);
50 if (response < 0) 54 if (response < 0)
51 dev_err(&serial->dev->dev, "%s- %d failed\n", __func__, reset_bit); 55 dev_err(&serial->dev->dev, "%s- %d failed\n",
56 __func__, reset_bit);
52 return response; 57 return response;
53} 58}
54
55
56EXPORT_SYMBOL_GPL(ezusb_writememory);
57EXPORT_SYMBOL_GPL(ezusb_set_reset); 59EXPORT_SYMBOL_GPL(ezusb_set_reset);
58 60
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 0ff4a3971e45..838717250145 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -12,7 +12,8 @@
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver 15 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver
16 * 17 *
17 * See http://ftdi-usb-sio.sourceforge.net for upto date testing info 18 * See http://ftdi-usb-sio.sourceforge.net for upto date testing info
18 * and extra documentation 19 * and extra documentation
@@ -25,7 +26,8 @@
25/* Bill Ryder - bryder@sgi.com - wrote the FTDI_SIO implementation */ 26/* Bill Ryder - bryder@sgi.com - wrote the FTDI_SIO implementation */
26/* Thanx to FTDI for so kindly providing details of the protocol required */ 27/* Thanx to FTDI for so kindly providing details of the protocol required */
27/* to talk to the device */ 28/* to talk to the device */
28/* Thanx to gkh and the rest of the usb dev group for all code I have assimilated :-) */ 29/* Thanx to gkh and the rest of the usb dev group for all code I have
30 assimilated :-) */
29 31
30#include <linux/kernel.h> 32#include <linux/kernel.h>
31#include <linux/errno.h> 33#include <linux/errno.h>
@@ -36,7 +38,7 @@
36#include <linux/tty_flip.h> 38#include <linux/tty_flip.h>
37#include <linux/module.h> 39#include <linux/module.h>
38#include <linux/spinlock.h> 40#include <linux/spinlock.h>
39#include <asm/uaccess.h> 41#include <linux/uaccess.h>
40#include <linux/usb.h> 42#include <linux/usb.h>
41#include <linux/serial.h> 43#include <linux/serial.h>
42#include <linux/usb/serial.h> 44#include <linux/usb/serial.h>
@@ -55,17 +57,22 @@ static __u16 product;
55 57
56struct ftdi_private { 58struct ftdi_private {
57 ftdi_chip_type_t chip_type; 59 ftdi_chip_type_t chip_type;
58 /* type of the device, either SIO or FT8U232AM */ 60 /* type of device, either SIO or FT8U232AM */
59 int baud_base; /* baud base clock for divisor setting */ 61 int baud_base; /* baud base clock for divisor setting */
60 int custom_divisor; /* custom_divisor kludge, this is for baud_base (different from what goes to the chip!) */ 62 int custom_divisor; /* custom_divisor kludge, this is for
63 baud_base (different from what goes to the
64 chip!) */
61 __u16 last_set_data_urb_value ; 65 __u16 last_set_data_urb_value ;
62 /* the last data state set - needed for doing a break */ 66 /* the last data state set - needed for doing
63 int write_offset; /* This is the offset in the usb data block to write the serial data - 67 * a break
64 * it is different between devices 68 */
69 int write_offset; /* This is the offset in the usb data block to
70 * write the serial data - it varies between
71 * devices
65 */ 72 */
66 int flags; /* some ASYNC_xxxx flags are supported */ 73 int flags; /* some ASYNC_xxxx flags are supported */
67 unsigned long last_dtr_rts; /* saved modem control outputs */ 74 unsigned long last_dtr_rts; /* saved modem control outputs */
68 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */ 75 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
69 char prev_status, diff_status; /* Used for TIOCMIWAIT */ 76 char prev_status, diff_status; /* Used for TIOCMIWAIT */
70 __u8 rx_flags; /* receive state flags (throttling) */ 77 __u8 rx_flags; /* receive state flags (throttling) */
71 spinlock_t rx_lock; /* spinlock for receive state */ 78 spinlock_t rx_lock; /* spinlock for receive state */
@@ -76,8 +83,10 @@ struct ftdi_private {
76 83
77 __u16 interface; /* FT2232C port interface (0 for FT232/245) */ 84 __u16 interface; /* FT2232C port interface (0 for FT232/245) */
78 85
79 speed_t force_baud; /* if non-zero, force the baud rate to this value */ 86 speed_t force_baud; /* if non-zero, force the baud rate to
80 int force_rtscts; /* if non-zero, force RTS-CTS to always be enabled */ 87 this value */
88 int force_rtscts; /* if non-zero, force RTS-CTS to always
89 be enabled */
81 90
82 spinlock_t tx_lock; /* spinlock for transmit state */ 91 spinlock_t tx_lock; /* spinlock for transmit state */
83 unsigned long tx_bytes; 92 unsigned long tx_bytes;
@@ -88,13 +97,14 @@ struct ftdi_private {
88/* struct ftdi_sio_quirk is used by devices requiring special attention. */ 97/* struct ftdi_sio_quirk is used by devices requiring special attention. */
89struct ftdi_sio_quirk { 98struct ftdi_sio_quirk {
90 int (*probe)(struct usb_serial *); 99 int (*probe)(struct usb_serial *);
91 void (*port_probe)(struct ftdi_private *); /* Special settings for probed ports. */ 100 /* Special settings for probed ports. */
101 void (*port_probe)(struct ftdi_private *);
92}; 102};
93 103
94static int ftdi_jtag_probe (struct usb_serial *serial); 104static int ftdi_jtag_probe(struct usb_serial *serial);
95static int ftdi_mtxorb_hack_setup (struct usb_serial *serial); 105static int ftdi_mtxorb_hack_setup(struct usb_serial *serial);
96static void ftdi_USB_UIRT_setup (struct ftdi_private *priv); 106static void ftdi_USB_UIRT_setup(struct ftdi_private *priv);
97static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv); 107static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
98 108
99static struct ftdi_sio_quirk ftdi_jtag_quirk = { 109static struct ftdi_sio_quirk ftdi_jtag_quirk = {
100 .probe = ftdi_jtag_probe, 110 .probe = ftdi_jtag_probe,
@@ -174,270 +184,270 @@ static struct usb_device_id id_table_combined [] = {
174 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_4_PID) }, 184 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_4_PID) },
175 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) }, 185 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) },
176 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) }, 186 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) },
177 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0100_PID) }, 187 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0100_PID) },
178 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0101_PID) }, 188 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0101_PID) },
179 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0102_PID) }, 189 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0102_PID) },
180 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0103_PID) }, 190 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0103_PID) },
181 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0104_PID) }, 191 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0104_PID) },
182 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0105_PID) }, 192 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0105_PID) },
183 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0106_PID) }, 193 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0106_PID) },
184 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0107_PID) }, 194 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0107_PID) },
185 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0108_PID) }, 195 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0108_PID) },
186 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0109_PID) }, 196 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0109_PID) },
187 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010A_PID) }, 197 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010A_PID) },
188 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010B_PID) }, 198 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010B_PID) },
189 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010C_PID) }, 199 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010C_PID) },
190 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010D_PID) }, 200 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010D_PID) },
191 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010E_PID) }, 201 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010E_PID) },
192 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010F_PID) }, 202 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010F_PID) },
193 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0110_PID) }, 203 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0110_PID) },
194 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0111_PID) }, 204 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0111_PID) },
195 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0112_PID) }, 205 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0112_PID) },
196 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0113_PID) }, 206 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0113_PID) },
197 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0114_PID) }, 207 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0114_PID) },
198 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0115_PID) }, 208 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0115_PID) },
199 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0116_PID) }, 209 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0116_PID) },
200 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0117_PID) }, 210 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0117_PID) },
201 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0118_PID) }, 211 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0118_PID) },
202 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0119_PID) }, 212 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0119_PID) },
203 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011A_PID) }, 213 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011A_PID) },
204 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011B_PID) }, 214 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011B_PID) },
205 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011C_PID) }, 215 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011C_PID) },
206 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011D_PID) }, 216 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011D_PID) },
207 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011E_PID) }, 217 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011E_PID) },
208 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011F_PID) }, 218 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011F_PID) },
209 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0120_PID) }, 219 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0120_PID) },
210 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0121_PID) }, 220 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0121_PID) },
211 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0122_PID) }, 221 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0122_PID) },
212 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0123_PID) }, 222 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0123_PID) },
213 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0124_PID) }, 223 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0124_PID) },
214 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0125_PID) }, 224 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0125_PID) },
215 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0126_PID) }, 225 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0126_PID) },
216 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0127_PID), 226 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0127_PID),
217 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 227 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
218 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0128_PID) }, 228 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0128_PID) },
219 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0129_PID) }, 229 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0129_PID) },
220 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012A_PID) }, 230 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012A_PID) },
221 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012B_PID) }, 231 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012B_PID) },
222 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012C_PID), 232 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012C_PID),
223 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 233 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
224 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012D_PID) }, 234 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012D_PID) },
225 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012E_PID) }, 235 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012E_PID) },
226 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012F_PID) }, 236 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012F_PID) },
227 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0130_PID) }, 237 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0130_PID) },
228 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0131_PID) }, 238 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0131_PID) },
229 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0132_PID) }, 239 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0132_PID) },
230 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0133_PID) }, 240 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0133_PID) },
231 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0134_PID) }, 241 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0134_PID) },
232 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0135_PID) }, 242 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0135_PID) },
233 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0136_PID) }, 243 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0136_PID) },
234 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0137_PID) }, 244 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0137_PID) },
235 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0138_PID) }, 245 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0138_PID) },
236 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0139_PID) }, 246 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0139_PID) },
237 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013A_PID) }, 247 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013A_PID) },
238 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013B_PID) }, 248 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013B_PID) },
239 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013C_PID) }, 249 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013C_PID) },
240 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013D_PID) }, 250 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013D_PID) },
241 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013E_PID) }, 251 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013E_PID) },
242 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013F_PID) }, 252 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013F_PID) },
243 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0140_PID) }, 253 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0140_PID) },
244 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0141_PID) }, 254 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0141_PID) },
245 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0142_PID) }, 255 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0142_PID) },
246 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0143_PID) }, 256 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0143_PID) },
247 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0144_PID) }, 257 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0144_PID) },
248 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0145_PID) }, 258 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0145_PID) },
249 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0146_PID) }, 259 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0146_PID) },
250 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0147_PID) }, 260 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0147_PID) },
251 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0148_PID) }, 261 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0148_PID) },
252 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0149_PID) }, 262 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0149_PID) },
253 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014A_PID) }, 263 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014A_PID) },
254 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014B_PID) }, 264 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014B_PID) },
255 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014C_PID) }, 265 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014C_PID) },
256 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014D_PID) }, 266 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014D_PID) },
257 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014E_PID) }, 267 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014E_PID) },
258 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014F_PID) }, 268 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014F_PID) },
259 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0150_PID) }, 269 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0150_PID) },
260 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0151_PID) }, 270 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0151_PID) },
261 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0152_PID) }, 271 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0152_PID) },
262 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0153_PID), 272 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0153_PID),
263 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 273 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
264 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0154_PID), 274 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0154_PID),
265 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 275 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
266 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0155_PID), 276 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0155_PID),
267 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 277 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
268 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0156_PID), 278 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0156_PID),
269 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 279 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
270 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0157_PID), 280 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0157_PID),
271 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 281 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
272 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0158_PID), 282 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0158_PID),
273 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk }, 283 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
274 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0159_PID) }, 284 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0159_PID) },
275 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015A_PID) }, 285 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015A_PID) },
276 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015B_PID) }, 286 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015B_PID) },
277 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015C_PID) }, 287 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015C_PID) },
278 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015D_PID) }, 288 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015D_PID) },
279 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015E_PID) }, 289 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015E_PID) },
280 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015F_PID) }, 290 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015F_PID) },
281 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0160_PID) }, 291 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0160_PID) },
282 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0161_PID) }, 292 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0161_PID) },
283 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0162_PID) }, 293 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0162_PID) },
284 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0163_PID) }, 294 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0163_PID) },
285 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0164_PID) }, 295 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0164_PID) },
286 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0165_PID) }, 296 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0165_PID) },
287 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0166_PID) }, 297 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0166_PID) },
288 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0167_PID) }, 298 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0167_PID) },
289 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0168_PID) }, 299 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0168_PID) },
290 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0169_PID) }, 300 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0169_PID) },
291 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016A_PID) }, 301 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016A_PID) },
292 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016B_PID) }, 302 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016B_PID) },
293 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016C_PID) }, 303 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016C_PID) },
294 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016D_PID) }, 304 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016D_PID) },
295 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016E_PID) }, 305 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016E_PID) },
296 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016F_PID) }, 306 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016F_PID) },
297 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0170_PID) }, 307 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0170_PID) },
298 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0171_PID) }, 308 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0171_PID) },
299 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0172_PID) }, 309 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0172_PID) },
300 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0173_PID) }, 310 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0173_PID) },
301 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0174_PID) }, 311 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0174_PID) },
302 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0175_PID) }, 312 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0175_PID) },
303 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0176_PID) }, 313 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0176_PID) },
304 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0177_PID) }, 314 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0177_PID) },
305 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0178_PID) }, 315 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0178_PID) },
306 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0179_PID) }, 316 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0179_PID) },
307 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017A_PID) }, 317 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017A_PID) },
308 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017B_PID) }, 318 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017B_PID) },
309 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017C_PID) }, 319 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017C_PID) },
310 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017D_PID) }, 320 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017D_PID) },
311 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017E_PID) }, 321 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017E_PID) },
312 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017F_PID) }, 322 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017F_PID) },
313 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0180_PID) }, 323 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0180_PID) },
314 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0181_PID) }, 324 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0181_PID) },
315 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0182_PID) }, 325 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0182_PID) },
316 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0183_PID) }, 326 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0183_PID) },
317 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0184_PID) }, 327 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0184_PID) },
318 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0185_PID) }, 328 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0185_PID) },
319 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0186_PID) }, 329 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0186_PID) },
320 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0187_PID) }, 330 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0187_PID) },
321 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0188_PID) }, 331 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0188_PID) },
322 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0189_PID) }, 332 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0189_PID) },
323 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018A_PID) }, 333 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018A_PID) },
324 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018B_PID) }, 334 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018B_PID) },
325 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018C_PID) }, 335 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018C_PID) },
326 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018D_PID) }, 336 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018D_PID) },
327 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018E_PID) }, 337 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018E_PID) },
328 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018F_PID) }, 338 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018F_PID) },
329 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0190_PID) }, 339 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0190_PID) },
330 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0191_PID) }, 340 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0191_PID) },
331 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0192_PID) }, 341 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0192_PID) },
332 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0193_PID) }, 342 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0193_PID) },
333 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0194_PID) }, 343 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0194_PID) },
334 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0195_PID) }, 344 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0195_PID) },
335 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0196_PID) }, 345 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0196_PID) },
336 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0197_PID) }, 346 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0197_PID) },
337 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0198_PID) }, 347 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0198_PID) },
338 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0199_PID) }, 348 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0199_PID) },
339 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019A_PID) }, 349 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019A_PID) },
340 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019B_PID) }, 350 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019B_PID) },
341 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019C_PID) }, 351 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019C_PID) },
342 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019D_PID) }, 352 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019D_PID) },
343 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019E_PID) }, 353 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019E_PID) },
344 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019F_PID) }, 354 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019F_PID) },
345 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A0_PID) }, 355 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A0_PID) },
346 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A1_PID) }, 356 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A1_PID) },
347 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A2_PID) }, 357 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A2_PID) },
348 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A3_PID) }, 358 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A3_PID) },
349 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A4_PID) }, 359 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A4_PID) },
350 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A5_PID) }, 360 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A5_PID) },
351 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A6_PID) }, 361 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A6_PID) },
352 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A7_PID) }, 362 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A7_PID) },
353 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A8_PID) }, 363 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A8_PID) },
354 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A9_PID) }, 364 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A9_PID) },
355 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AA_PID) }, 365 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AA_PID) },
356 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AB_PID) }, 366 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AB_PID) },
357 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AC_PID) }, 367 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AC_PID) },
358 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AD_PID) }, 368 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AD_PID) },
359 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AE_PID) }, 369 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AE_PID) },
360 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AF_PID) }, 370 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AF_PID) },
361 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B0_PID) }, 371 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B0_PID) },
362 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B1_PID) }, 372 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B1_PID) },
363 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B2_PID) }, 373 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B2_PID) },
364 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B3_PID) }, 374 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B3_PID) },
365 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B4_PID) }, 375 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B4_PID) },
366 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B5_PID) }, 376 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B5_PID) },
367 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B6_PID) }, 377 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B6_PID) },
368 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B7_PID) }, 378 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B7_PID) },
369 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B8_PID) }, 379 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B8_PID) },
370 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B9_PID) }, 380 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B9_PID) },
371 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BA_PID) }, 381 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BA_PID) },
372 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BB_PID) }, 382 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BB_PID) },
373 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BC_PID) }, 383 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BC_PID) },
374 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BD_PID) }, 384 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BD_PID) },
375 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BE_PID) }, 385 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BE_PID) },
376 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BF_PID) }, 386 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BF_PID) },
377 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C0_PID) }, 387 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C0_PID) },
378 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C1_PID) }, 388 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C1_PID) },
379 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C2_PID) }, 389 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C2_PID) },
380 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C3_PID) }, 390 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C3_PID) },
381 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C4_PID) }, 391 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C4_PID) },
382 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C5_PID) }, 392 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C5_PID) },
383 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C6_PID) }, 393 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C6_PID) },
384 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C7_PID) }, 394 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C7_PID) },
385 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C8_PID) }, 395 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C8_PID) },
386 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C9_PID) }, 396 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C9_PID) },
387 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CA_PID) }, 397 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CA_PID) },
388 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CB_PID) }, 398 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CB_PID) },
389 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CC_PID) }, 399 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CC_PID) },
390 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CD_PID) }, 400 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CD_PID) },
391 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CE_PID) }, 401 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CE_PID) },
392 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CF_PID) }, 402 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CF_PID) },
393 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D0_PID) }, 403 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D0_PID) },
394 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D1_PID) }, 404 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D1_PID) },
395 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D2_PID) }, 405 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D2_PID) },
396 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D3_PID) }, 406 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D3_PID) },
397 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D4_PID) }, 407 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D4_PID) },
398 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D5_PID) }, 408 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D5_PID) },
399 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D6_PID) }, 409 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D6_PID) },
400 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D7_PID) }, 410 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D7_PID) },
401 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D8_PID) }, 411 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D8_PID) },
402 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D9_PID) }, 412 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D9_PID) },
403 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DA_PID) }, 413 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DA_PID) },
404 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DB_PID) }, 414 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DB_PID) },
405 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DC_PID) }, 415 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DC_PID) },
406 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DD_PID) }, 416 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DD_PID) },
407 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DE_PID) }, 417 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DE_PID) },
408 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DF_PID) }, 418 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DF_PID) },
409 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E0_PID) }, 419 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E0_PID) },
410 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E1_PID) }, 420 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E1_PID) },
411 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E2_PID) }, 421 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E2_PID) },
412 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E3_PID) }, 422 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E3_PID) },
413 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E4_PID) }, 423 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E4_PID) },
414 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E5_PID) }, 424 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E5_PID) },
415 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E6_PID) }, 425 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E6_PID) },
416 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E7_PID) }, 426 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E7_PID) },
417 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E8_PID) }, 427 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E8_PID) },
418 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E9_PID) }, 428 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E9_PID) },
419 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EA_PID) }, 429 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EA_PID) },
420 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EB_PID) }, 430 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EB_PID) },
421 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EC_PID) }, 431 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EC_PID) },
422 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01ED_PID) }, 432 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01ED_PID) },
423 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EE_PID) }, 433 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EE_PID) },
424 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EF_PID) }, 434 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EF_PID) },
425 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F0_PID) }, 435 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F0_PID) },
426 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F1_PID) }, 436 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F1_PID) },
427 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F2_PID) }, 437 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F2_PID) },
428 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F3_PID) }, 438 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F3_PID) },
429 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F4_PID) }, 439 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F4_PID) },
430 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F5_PID) }, 440 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F5_PID) },
431 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F6_PID) }, 441 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F6_PID) },
432 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F7_PID) }, 442 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F7_PID) },
433 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F8_PID) }, 443 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F8_PID) },
434 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F9_PID) }, 444 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F9_PID) },
435 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FA_PID) }, 445 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FA_PID) },
436 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FB_PID) }, 446 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FB_PID) },
437 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FC_PID) }, 447 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FC_PID) },
438 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FD_PID) }, 448 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FD_PID) },
439 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FE_PID) }, 449 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FE_PID) },
440 { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FF_PID) }, 450 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FF_PID) },
441 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) }, 451 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) },
442 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) }, 452 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) },
443 { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) }, 453 { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) },
@@ -642,7 +652,7 @@ static struct usb_device_id id_table_combined [] = {
642 { } /* Terminating entry */ 652 { } /* Terminating entry */
643}; 653};
644 654
645MODULE_DEVICE_TABLE (usb, id_table_combined); 655MODULE_DEVICE_TABLE(usb, id_table_combined);
646 656
647static struct usb_driver ftdi_driver = { 657static struct usb_driver ftdi_driver = {
648 .name = "ftdi_sio", 658 .name = "ftdi_sio",
@@ -678,30 +688,37 @@ static const char *ftdi_chip_name[] = {
678 | ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP) 688 | ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP)
679 689
680/* function prototypes for a FTDI serial converter */ 690/* function prototypes for a FTDI serial converter */
681static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id); 691static int ftdi_sio_probe(struct usb_serial *serial,
682static void ftdi_shutdown (struct usb_serial *serial); 692 const struct usb_device_id *id);
683static int ftdi_sio_port_probe (struct usb_serial_port *port); 693static void ftdi_shutdown(struct usb_serial *serial);
684static int ftdi_sio_port_remove (struct usb_serial_port *port); 694static int ftdi_sio_port_probe(struct usb_serial_port *port);
685static int ftdi_open (struct usb_serial_port *port, struct file *filp); 695static int ftdi_sio_port_remove(struct usb_serial_port *port);
686static void ftdi_close (struct usb_serial_port *port, struct file *filp); 696static int ftdi_open(struct tty_struct *tty,
687static int ftdi_write (struct usb_serial_port *port, const unsigned char *buf, int count); 697 struct usb_serial_port *port, struct file *filp);
688static int ftdi_write_room (struct usb_serial_port *port); 698static void ftdi_close(struct tty_struct *tty,
689static int ftdi_chars_in_buffer (struct usb_serial_port *port); 699 struct usb_serial_port *port, struct file *filp);
690static void ftdi_write_bulk_callback (struct urb *urb); 700static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
691static void ftdi_read_bulk_callback (struct urb *urb); 701 const unsigned char *buf, int count);
692static void ftdi_process_read (struct work_struct *work); 702static int ftdi_write_room(struct tty_struct *tty);
693static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios * old); 703static int ftdi_chars_in_buffer(struct tty_struct *tty);
694static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file); 704static void ftdi_write_bulk_callback(struct urb *urb);
695static int ftdi_tiocmset (struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear); 705static void ftdi_read_bulk_callback(struct urb *urb);
696static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 706static void ftdi_process_read(struct work_struct *work);
697static void ftdi_break_ctl (struct usb_serial_port *port, int break_state ); 707static void ftdi_set_termios(struct tty_struct *tty,
698static void ftdi_throttle (struct usb_serial_port *port); 708 struct usb_serial_port *port, struct ktermios *old);
699static void ftdi_unthrottle (struct usb_serial_port *port); 709static int ftdi_tiocmget(struct tty_struct *tty, struct file *file);
700 710static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
701static unsigned short int ftdi_232am_baud_base_to_divisor (int baud, int base); 711 unsigned int set, unsigned int clear);
702static unsigned short int ftdi_232am_baud_to_divisor (int baud); 712static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
703static __u32 ftdi_232bm_baud_base_to_divisor (int baud, int base); 713 unsigned int cmd, unsigned long arg);
704static __u32 ftdi_232bm_baud_to_divisor (int baud); 714static void ftdi_break_ctl(struct tty_struct *tty, int break_state);
715static void ftdi_throttle(struct tty_struct *tty);
716static void ftdi_unthrottle(struct tty_struct *tty);
717
718static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base);
719static unsigned short int ftdi_232am_baud_to_divisor(int baud);
720static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base);
721static __u32 ftdi_232bm_baud_to_divisor(int baud);
705 722
706static struct usb_serial_driver ftdi_sio_device = { 723static struct usb_serial_driver ftdi_sio_device = {
707 .driver = { 724 .driver = {
@@ -752,44 +769,54 @@ static struct usb_serial_driver ftdi_sio_device = {
752static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base) 769static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base)
753{ 770{
754 unsigned short int divisor; 771 unsigned short int divisor;
755 int divisor3 = base / 2 / baud; // divisor shifted 3 bits to the left 772 /* divisor shifted 3 bits to the left */
756 if ((divisor3 & 0x7) == 7) divisor3 ++; // round x.7/8 up to x+1 773 int divisor3 = base / 2 / baud;
774 if ((divisor3 & 0x7) == 7)
775 divisor3++; /* round x.7/8 up to x+1 */
757 divisor = divisor3 >> 3; 776 divisor = divisor3 >> 3;
758 divisor3 &= 0x7; 777 divisor3 &= 0x7;
759 if (divisor3 == 1) divisor |= 0xc000; else // 0.125 778 if (divisor3 == 1)
760 if (divisor3 >= 4) divisor |= 0x4000; else // 0.5 779 divisor |= 0xc000;
761 if (divisor3 != 0) divisor |= 0x8000; // 0.25 780 else if (divisor3 >= 4)
762 if (divisor == 1) divisor = 0; /* special case for maximum baud rate */ 781 divisor |= 0x4000;
782 else if (divisor3 != 0)
783 divisor |= 0x8000;
784 else if (divisor == 1)
785 divisor = 0; /* special case for maximum baud rate */
763 return divisor; 786 return divisor;
764} 787}
765 788
766static unsigned short int ftdi_232am_baud_to_divisor(int baud) 789static unsigned short int ftdi_232am_baud_to_divisor(int baud)
767{ 790{
768 return(ftdi_232am_baud_base_to_divisor(baud, 48000000)); 791 return ftdi_232am_baud_base_to_divisor(baud, 48000000);
769} 792}
770 793
771static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base) 794static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base)
772{ 795{
773 static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 }; 796 static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
774 __u32 divisor; 797 __u32 divisor;
775 int divisor3 = base / 2 / baud; // divisor shifted 3 bits to the left 798 /* divisor shifted 3 bits to the left */
799 int divisor3 = base / 2 / baud;
776 divisor = divisor3 >> 3; 800 divisor = divisor3 >> 3;
777 divisor |= (__u32)divfrac[divisor3 & 0x7] << 14; 801 divisor |= (__u32)divfrac[divisor3 & 0x7] << 14;
778 /* Deal with special cases for highest baud rates. */ 802 /* Deal with special cases for highest baud rates. */
779 if (divisor == 1) divisor = 0; else // 1.0 803 if (divisor == 1)
780 if (divisor == 0x4001) divisor = 1; // 1.5 804 divisor = 0;
805 else if (divisor == 0x4001)
806 divisor = 1;
781 return divisor; 807 return divisor;
782} 808}
783 809
784static __u32 ftdi_232bm_baud_to_divisor(int baud) 810static __u32 ftdi_232bm_baud_to_divisor(int baud)
785{ 811{
786 return(ftdi_232bm_baud_base_to_divisor(baud, 48000000)); 812 return ftdi_232bm_baud_base_to_divisor(baud, 48000000);
787} 813}
788 814
789#define set_mctrl(port, set) update_mctrl((port), (set), 0) 815#define set_mctrl(port, set) update_mctrl((port), (set), 0)
790#define clear_mctrl(port, clear) update_mctrl((port), 0, (clear)) 816#define clear_mctrl(port, clear) update_mctrl((port), 0, (clear))
791 817
792static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned int clear) 818static int update_mctrl(struct usb_serial_port *port, unsigned int set,
819 unsigned int clear)
793{ 820{
794 struct ftdi_private *priv = usb_get_serial_port_data(port); 821 struct ftdi_private *priv = usb_get_serial_port_data(port);
795 char *buf; 822 char *buf;
@@ -843,42 +870,8 @@ static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned
843} 870}
844 871
845 872
846static __u32 get_ftdi_divisor(struct usb_serial_port * port); 873static __u32 get_ftdi_divisor(struct tty_struct *tty,
847 874 struct usb_serial_port *port)
848
849static int change_speed(struct usb_serial_port *port)
850{
851 struct ftdi_private *priv = usb_get_serial_port_data(port);
852 char *buf;
853 __u16 urb_value;
854 __u16 urb_index;
855 __u32 urb_index_value;
856 int rv;
857
858 buf = kmalloc(1, GFP_NOIO);
859 if (!buf)
860 return -ENOMEM;
861
862 urb_index_value = get_ftdi_divisor(port);
863 urb_value = (__u16)urb_index_value;
864 urb_index = (__u16)(urb_index_value >> 16);
865 if (priv->interface) { /* FT2232C */
866 urb_index = (__u16)((urb_index << 8) | priv->interface);
867 }
868
869 rv = usb_control_msg(port->serial->dev,
870 usb_sndctrlpipe(port->serial->dev, 0),
871 FTDI_SIO_SET_BAUDRATE_REQUEST,
872 FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,
873 urb_value, urb_index,
874 buf, 0, WDR_SHORT_TIMEOUT);
875
876 kfree(buf);
877 return rv;
878}
879
880
881static __u32 get_ftdi_divisor(struct usb_serial_port * port)
882{ /* get_ftdi_divisor */ 875{ /* get_ftdi_divisor */
883 struct ftdi_private *priv = usb_get_serial_port_data(port); 876 struct ftdi_private *priv = usb_get_serial_port_data(port);
884 __u32 div_value = 0; 877 __u32 div_value = 0;
@@ -886,48 +879,56 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
886 int baud; 879 int baud;
887 880
888 /* 881 /*
889 * The logic involved in setting the baudrate can be cleanly split in 3 steps. 882 * The logic involved in setting the baudrate can be cleanly split into
890 * Obtaining the actual baud rate is a little tricky since unix traditionally 883 * 3 steps.
891 * somehow ignored the possibility to set non-standard baud rates.
892 * 1. Standard baud rates are set in tty->termios->c_cflag 884 * 1. Standard baud rates are set in tty->termios->c_cflag
893 * 2. If these are not enough, you can set any speed using alt_speed as follows: 885 * 2. If these are not enough, you can set any speed using alt_speed as
886 * follows:
894 * - set tty->termios->c_cflag speed to B38400 887 * - set tty->termios->c_cflag speed to B38400
895 * - set your real speed in tty->alt_speed; it gets ignored when 888 * - set your real speed in tty->alt_speed; it gets ignored when
896 * alt_speed==0, (or) 889 * alt_speed==0, (or)
897 * - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows: 890 * - call TIOCSSERIAL ioctl with (struct serial_struct) set as
898 * flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP], this just 891 * follows:
899 * sets alt_speed to (HI: 57600, VHI: 115200, SHI: 230400, WARP: 460800) 892 * flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP],
893 * this just sets alt_speed to (HI: 57600, VHI: 115200,
894 * SHI: 230400, WARP: 460800)
900 * ** Steps 1, 2 are done courtesy of tty_get_baud_rate 895 * ** Steps 1, 2 are done courtesy of tty_get_baud_rate
901 * 3. You can also set baud rate by setting custom divisor as follows 896 * 3. You can also set baud rate by setting custom divisor as follows
902 * - set tty->termios->c_cflag speed to B38400 897 * - set tty->termios->c_cflag speed to B38400
903 * - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows: 898 * - call TIOCSSERIAL ioctl with (struct serial_struct) set as
899 * follows:
904 * o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST 900 * o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST
905 * o custom_divisor set to baud_base / your_new_baudrate 901 * o custom_divisor set to baud_base / your_new_baudrate
906 * ** Step 3 is done courtesy of code borrowed from serial.c - I should really 902 * ** Step 3 is done courtesy of code borrowed from serial.c
907 * spend some time and separate+move this common code to serial.c, it is 903 * I should really spend some time and separate + move this common
908 * replicated in nearly every serial driver you see. 904 * code to serial.c, it is replicated in nearly every serial driver
905 * you see.
909 */ 906 */
910 907
911 /* 1. Get the baud rate from the tty settings, this observes alt_speed hack */ 908 /* 1. Get the baud rate from the tty settings, this observes
909 alt_speed hack */
912 910
913 baud = tty_get_baud_rate(port->tty); 911 baud = tty_get_baud_rate(tty);
914 dbg("%s - tty_get_baud_rate reports speed %d", __func__, baud); 912 dbg("%s - tty_get_baud_rate reports speed %d", __func__, baud);
915 913
916 /* 2. Observe async-compatible custom_divisor hack, update baudrate if needed */ 914 /* 2. Observe async-compatible custom_divisor hack, update baudrate
915 if needed */
917 916
918 if (baud == 38400 && 917 if (baud == 38400 &&
919 ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) && 918 ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
920 (priv->custom_divisor)) { 919 (priv->custom_divisor)) {
921 baud = priv->baud_base / priv->custom_divisor; 920 baud = priv->baud_base / priv->custom_divisor;
922 dbg("%s - custom divisor %d sets baud rate to %d", __func__, priv->custom_divisor, baud); 921 dbg("%s - custom divisor %d sets baud rate to %d",
922 __func__, priv->custom_divisor, baud);
923 } 923 }
924 924
925 /* 3. Convert baudrate to device-specific divisor */ 925 /* 3. Convert baudrate to device-specific divisor */
926 926
927 if (!baud) baud = 9600; 927 if (!baud)
928 switch(priv->chip_type) { 928 baud = 9600;
929 switch (priv->chip_type) {
929 case SIO: /* SIO chip */ 930 case SIO: /* SIO chip */
930 switch(baud) { 931 switch (baud) {
931 case 300: div_value = ftdi_sio_b300; break; 932 case 300: div_value = ftdi_sio_b300; break;
932 case 600: div_value = ftdi_sio_b600; break; 933 case 600: div_value = ftdi_sio_b600; break;
933 case 1200: div_value = ftdi_sio_b1200; break; 934 case 1200: div_value = ftdi_sio_b1200; break;
@@ -940,7 +941,8 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
940 case 115200: div_value = ftdi_sio_b115200; break; 941 case 115200: div_value = ftdi_sio_b115200; break;
941 } /* baud */ 942 } /* baud */
942 if (div_value == 0) { 943 if (div_value == 0) {
943 dbg("%s - Baudrate (%d) requested is not supported", __func__, baud); 944 dbg("%s - Baudrate (%d) requested is not supported",
945 __func__, baud);
944 div_value = ftdi_sio_b9600; 946 div_value = ftdi_sio_b9600;
945 baud = 9600; 947 baud = 9600;
946 div_okay = 0; 948 div_okay = 0;
@@ -950,7 +952,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
950 if (baud <= 3000000) { 952 if (baud <= 3000000) {
951 div_value = ftdi_232am_baud_to_divisor(baud); 953 div_value = ftdi_232am_baud_to_divisor(baud);
952 } else { 954 } else {
953 dbg("%s - Baud rate too high!", __func__); 955 dbg("%s - Baud rate too high!", __func__);
954 baud = 9600; 956 baud = 9600;
955 div_value = ftdi_232am_baud_to_divisor(9600); 957 div_value = ftdi_232am_baud_to_divisor(9600);
956 div_okay = 0; 958 div_okay = 0;
@@ -962,7 +964,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
962 if (baud <= 3000000) { 964 if (baud <= 3000000) {
963 div_value = ftdi_232bm_baud_to_divisor(baud); 965 div_value = ftdi_232bm_baud_to_divisor(baud);
964 } else { 966 } else {
965 dbg("%s - Baud rate too high!", __func__); 967 dbg("%s - Baud rate too high!", __func__);
966 div_value = ftdi_232bm_baud_to_divisor(9600); 968 div_value = ftdi_232bm_baud_to_divisor(9600);
967 div_okay = 0; 969 div_okay = 0;
968 baud = 9600; 970 baud = 9600;
@@ -976,12 +978,45 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
976 ftdi_chip_name[priv->chip_type]); 978 ftdi_chip_name[priv->chip_type]);
977 } 979 }
978 980
979 tty_encode_baud_rate(port->tty, baud, baud); 981 tty_encode_baud_rate(tty, baud, baud);
980 return(div_value); 982 return div_value;
983}
984
985static int change_speed(struct tty_struct *tty, struct usb_serial_port *port)
986{
987 struct ftdi_private *priv = usb_get_serial_port_data(port);
988 char *buf;
989 __u16 urb_value;
990 __u16 urb_index;
991 __u32 urb_index_value;
992 int rv;
993
994 buf = kmalloc(1, GFP_NOIO);
995 if (!buf)
996 return -ENOMEM;
997
998 urb_index_value = get_ftdi_divisor(tty, port);
999 urb_value = (__u16)urb_index_value;
1000 urb_index = (__u16)(urb_index_value >> 16);
1001 if (priv->interface) { /* FT2232C */
1002 urb_index = (__u16)((urb_index << 8) | priv->interface);
1003 }
1004
1005 rv = usb_control_msg(port->serial->dev,
1006 usb_sndctrlpipe(port->serial->dev, 0),
1007 FTDI_SIO_SET_BAUDRATE_REQUEST,
1008 FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,
1009 urb_value, urb_index,
1010 buf, 0, WDR_SHORT_TIMEOUT);
1011
1012 kfree(buf);
1013 return rv;
981} 1014}
982 1015
983 1016
984static int get_serial_info(struct usb_serial_port * port, struct serial_struct __user * retinfo) 1017
1018static int get_serial_info(struct usb_serial_port *port,
1019 struct serial_struct __user *retinfo)
985{ 1020{
986 struct ftdi_private *priv = usb_get_serial_port_data(port); 1021 struct ftdi_private *priv = usb_get_serial_port_data(port);
987 struct serial_struct tmp; 1022 struct serial_struct tmp;
@@ -998,7 +1033,8 @@ static int get_serial_info(struct usb_serial_port * port, struct serial_struct _
998} /* get_serial_info */ 1033} /* get_serial_info */
999 1034
1000 1035
1001static int set_serial_info(struct usb_serial_port * port, struct serial_struct __user * newinfo) 1036static int set_serial_info(struct tty_struct *tty,
1037 struct usb_serial_port *port, struct serial_struct __user *newinfo)
1002{ /* set_serial_info */ 1038{ /* set_serial_info */
1003 struct ftdi_private *priv = usb_get_serial_port_data(port); 1039 struct ftdi_private *priv = usb_get_serial_port_data(port);
1004 struct serial_struct new_serial; 1040 struct serial_struct new_serial;
@@ -1006,7 +1042,7 @@ static int set_serial_info(struct usb_serial_port * port, struct serial_struct _
1006 1042
1007 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) 1043 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
1008 return -EFAULT; 1044 return -EFAULT;
1009 old_priv = * priv; 1045 old_priv = *priv;
1010 1046
1011 /* Do error checking and permission checking */ 1047 /* Do error checking and permission checking */
1012 1048
@@ -1027,33 +1063,32 @@ static int set_serial_info(struct usb_serial_port * port, struct serial_struct _
1027 /* Make the changes - these are privileged changes! */ 1063 /* Make the changes - these are privileged changes! */
1028 1064
1029 priv->flags = ((priv->flags & ~ASYNC_FLAGS) | 1065 priv->flags = ((priv->flags & ~ASYNC_FLAGS) |
1030 (new_serial.flags & ASYNC_FLAGS)); 1066 (new_serial.flags & ASYNC_FLAGS));
1031 priv->custom_divisor = new_serial.custom_divisor; 1067 priv->custom_divisor = new_serial.custom_divisor;
1032 1068
1033 port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1069 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1034 1070
1035check_and_exit: 1071check_and_exit:
1036 if ((old_priv.flags & ASYNC_SPD_MASK) != 1072 if ((old_priv.flags & ASYNC_SPD_MASK) !=
1037 (priv->flags & ASYNC_SPD_MASK)) { 1073 (priv->flags & ASYNC_SPD_MASK)) {
1038 if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 1074 if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1039 port->tty->alt_speed = 57600; 1075 tty->alt_speed = 57600;
1040 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 1076 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1041 port->tty->alt_speed = 115200; 1077 tty->alt_speed = 115200;
1042 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 1078 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
1043 port->tty->alt_speed = 230400; 1079 tty->alt_speed = 230400;
1044 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 1080 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
1045 port->tty->alt_speed = 460800; 1081 tty->alt_speed = 460800;
1046 else 1082 else
1047 port->tty->alt_speed = 0; 1083 tty->alt_speed = 0;
1048 } 1084 }
1049 if (((old_priv.flags & ASYNC_SPD_MASK) != 1085 if (((old_priv.flags & ASYNC_SPD_MASK) !=
1050 (priv->flags & ASYNC_SPD_MASK)) || 1086 (priv->flags & ASYNC_SPD_MASK)) ||
1051 (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) && 1087 (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
1052 (old_priv.custom_divisor != priv->custom_divisor))) { 1088 (old_priv.custom_divisor != priv->custom_divisor))) {
1053 change_speed(port); 1089 change_speed(tty, port);
1054 } 1090 }
1055 1091 return 0;
1056 return (0);
1057 1092
1058} /* set_serial_info */ 1093} /* set_serial_info */
1059 1094
@@ -1082,11 +1117,10 @@ static void ftdi_determine_type(struct usb_serial_port *port)
1082 priv->chip_type = FT2232C; 1117 priv->chip_type = FT2232C;
1083 /* Determine interface code. */ 1118 /* Determine interface code. */
1084 inter = serial->interface->altsetting->desc.bInterfaceNumber; 1119 inter = serial->interface->altsetting->desc.bInterfaceNumber;
1085 if (inter == 0) { 1120 if (inter == 0)
1086 priv->interface = PIT_SIOA; 1121 priv->interface = PIT_SIOA;
1087 } else { 1122 else
1088 priv->interface = PIT_SIOB; 1123 priv->interface = PIT_SIOB;
1089 }
1090 /* BM-type devices have a bug where bcdDevice gets set 1124 /* BM-type devices have a bug where bcdDevice gets set
1091 * to 0x200 when iSerialNumber is 0. */ 1125 * to 0x200 when iSerialNumber is 0. */
1092 if (version < 0x500) { 1126 if (version < 0x500) {
@@ -1120,7 +1154,8 @@ static void ftdi_determine_type(struct usb_serial_port *port)
1120 * *************************************************************************** 1154 * ***************************************************************************
1121 */ 1155 */
1122 1156
1123static ssize_t show_latency_timer(struct device *dev, struct device_attribute *attr, char *buf) 1157static ssize_t show_latency_timer(struct device *dev,
1158 struct device_attribute *attr, char *buf)
1124{ 1159{
1125 struct usb_serial_port *port = to_usb_serial_port(dev); 1160 struct usb_serial_port *port = to_usb_serial_port(dev);
1126 struct ftdi_private *priv = usb_get_serial_port_data(port); 1161 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1129,14 +1164,14 @@ static ssize_t show_latency_timer(struct device *dev, struct device_attribute *a
1129 int rv = 0; 1164 int rv = 0;
1130 1165
1131 1166
1132 dbg("%s",__func__); 1167 dbg("%s", __func__);
1133 1168
1134 rv = usb_control_msg(udev, 1169 rv = usb_control_msg(udev,
1135 usb_rcvctrlpipe(udev, 0), 1170 usb_rcvctrlpipe(udev, 0),
1136 FTDI_SIO_GET_LATENCY_TIMER_REQUEST, 1171 FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
1137 FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, 1172 FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
1138 0, priv->interface, 1173 0, priv->interface,
1139 (char*) &latency, 1, WDR_TIMEOUT); 1174 (char *) &latency, 1, WDR_TIMEOUT);
1140 1175
1141 if (rv < 0) { 1176 if (rv < 0) {
1142 dev_err(dev, "Unable to read latency timer: %i\n", rv); 1177 dev_err(dev, "Unable to read latency timer: %i\n", rv);
@@ -1146,8 +1181,9 @@ static ssize_t show_latency_timer(struct device *dev, struct device_attribute *a
1146} 1181}
1147 1182
1148/* Write a new value of the latency timer, in units of milliseconds. */ 1183/* Write a new value of the latency timer, in units of milliseconds. */
1149static ssize_t store_latency_timer(struct device *dev, struct device_attribute *attr, const char *valbuf, 1184static ssize_t store_latency_timer(struct device *dev,
1150 size_t count) 1185 struct device_attribute *attr, const char *valbuf,
1186 size_t count)
1151{ 1187{
1152 struct usb_serial_port *port = to_usb_serial_port(dev); 1188 struct usb_serial_port *port = to_usb_serial_port(dev);
1153 struct ftdi_private *priv = usb_get_serial_port_data(port); 1189 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1175,8 +1211,8 @@ static ssize_t store_latency_timer(struct device *dev, struct device_attribute *
1175 1211
1176/* Write an event character directly to the FTDI register. The ASCII 1212/* Write an event character directly to the FTDI register. The ASCII
1177 value is in the low 8 bits, with the enable bit in the 9th bit. */ 1213 value is in the low 8 bits, with the enable bit in the 9th bit. */
1178static ssize_t store_event_char(struct device *dev, struct device_attribute *attr, const char *valbuf, 1214static ssize_t store_event_char(struct device *dev,
1179 size_t count) 1215 struct device_attribute *attr, const char *valbuf, size_t count)
1180{ 1216{
1181 struct usb_serial_port *port = to_usb_serial_port(dev); 1217 struct usb_serial_port *port = to_usb_serial_port(dev);
1182 struct ftdi_private *priv = usb_get_serial_port_data(port); 1218 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1202,7 +1238,8 @@ static ssize_t store_event_char(struct device *dev, struct device_attribute *att
1202 return count; 1238 return count;
1203} 1239}
1204 1240
1205static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer); 1241static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer,
1242 store_latency_timer);
1206static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char); 1243static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char);
1207 1244
1208static int create_sysfs_attrs(struct usb_serial_port *port) 1245static int create_sysfs_attrs(struct usb_serial_port *port)
@@ -1210,7 +1247,7 @@ static int create_sysfs_attrs(struct usb_serial_port *port)
1210 struct ftdi_private *priv = usb_get_serial_port_data(port); 1247 struct ftdi_private *priv = usb_get_serial_port_data(port);
1211 int retval = 0; 1248 int retval = 0;
1212 1249
1213 dbg("%s",__func__); 1250 dbg("%s", __func__);
1214 1251
1215 /* XXX I've no idea if the original SIO supports the event_char 1252 /* XXX I've no idea if the original SIO supports the event_char
1216 * sysfs parameter, so I'm playing it safe. */ 1253 * sysfs parameter, so I'm playing it safe. */
@@ -1232,7 +1269,7 @@ static void remove_sysfs_attrs(struct usb_serial_port *port)
1232{ 1269{
1233 struct ftdi_private *priv = usb_get_serial_port_data(port); 1270 struct ftdi_private *priv = usb_get_serial_port_data(port);
1234 1271
1235 dbg("%s",__func__); 1272 dbg("%s", __func__);
1236 1273
1237 /* XXX see create_sysfs_attrs */ 1274 /* XXX see create_sysfs_attrs */
1238 if (priv->chip_type != SIO) { 1275 if (priv->chip_type != SIO) {
@@ -1253,9 +1290,11 @@ static void remove_sysfs_attrs(struct usb_serial_port *port)
1253 */ 1290 */
1254 1291
1255/* Probe function to check for special devices */ 1292/* Probe function to check for special devices */
1256static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id) 1293static int ftdi_sio_probe(struct usb_serial *serial,
1294 const struct usb_device_id *id)
1257{ 1295{
1258 struct ftdi_sio_quirk *quirk = (struct ftdi_sio_quirk *)id->driver_info; 1296 struct ftdi_sio_quirk *quirk =
1297 (struct ftdi_sio_quirk *)id->driver_info;
1259 1298
1260 if (quirk && quirk->probe) { 1299 if (quirk && quirk->probe) {
1261 int ret = quirk->probe(serial); 1300 int ret = quirk->probe(serial);
@@ -1274,17 +1313,18 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1274 struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial); 1313 struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial);
1275 1314
1276 1315
1277 dbg("%s",__func__); 1316 dbg("%s", __func__);
1278 1317
1279 priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); 1318 priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL);
1280 if (!priv){ 1319 if (!priv) {
1281 err("%s- kmalloc(%Zd) failed.", __func__, sizeof(struct ftdi_private)); 1320 err("%s- kmalloc(%Zd) failed.", __func__,
1321 sizeof(struct ftdi_private));
1282 return -ENOMEM; 1322 return -ENOMEM;
1283 } 1323 }
1284 1324
1285 spin_lock_init(&priv->rx_lock); 1325 spin_lock_init(&priv->rx_lock);
1286 spin_lock_init(&priv->tx_lock); 1326 spin_lock_init(&priv->tx_lock);
1287 init_waitqueue_head(&priv->delta_msr_wait); 1327 init_waitqueue_head(&priv->delta_msr_wait);
1288 /* This will push the characters through immediately rather 1328 /* This will push the characters through immediately rather
1289 than queue a task to deliver them */ 1329 than queue a task to deliver them */
1290 priv->flags = ASYNC_LOW_LATENCY; 1330 priv->flags = ASYNC_LOW_LATENCY;
@@ -1294,9 +1334,9 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1294 1334
1295 /* Increase the size of read buffers */ 1335 /* Increase the size of read buffers */
1296 kfree(port->bulk_in_buffer); 1336 kfree(port->bulk_in_buffer);
1297 port->bulk_in_buffer = kmalloc (BUFSZ, GFP_KERNEL); 1337 port->bulk_in_buffer = kmalloc(BUFSZ, GFP_KERNEL);
1298 if (!port->bulk_in_buffer) { 1338 if (!port->bulk_in_buffer) {
1299 kfree (priv); 1339 kfree(priv);
1300 return -ENOMEM; 1340 return -ENOMEM;
1301 } 1341 }
1302 if (port->read_urb) { 1342 if (port->read_urb) {
@@ -1309,7 +1349,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1309 1349
1310 /* Free port's existing write urb and transfer buffer. */ 1350 /* Free port's existing write urb and transfer buffer. */
1311 if (port->write_urb) { 1351 if (port->write_urb) {
1312 usb_free_urb (port->write_urb); 1352 usb_free_urb(port->write_urb);
1313 port->write_urb = NULL; 1353 port->write_urb = NULL;
1314 } 1354 }
1315 kfree(port->bulk_out_buffer); 1355 kfree(port->bulk_out_buffer);
@@ -1317,7 +1357,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1317 1357
1318 usb_set_serial_port_data(port, priv); 1358 usb_set_serial_port_data(port, priv);
1319 1359
1320 ftdi_determine_type (port); 1360 ftdi_determine_type(port);
1321 create_sysfs_attrs(port); 1361 create_sysfs_attrs(port);
1322 return 0; 1362 return 0;
1323} 1363}
@@ -1325,9 +1365,9 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1325/* Setup for the USB-UIRT device, which requires hardwired 1365/* Setup for the USB-UIRT device, which requires hardwired
1326 * baudrate (38400 gets mapped to 312500) */ 1366 * baudrate (38400 gets mapped to 312500) */
1327/* Called from usbserial:serial_probe */ 1367/* Called from usbserial:serial_probe */
1328static void ftdi_USB_UIRT_setup (struct ftdi_private *priv) 1368static void ftdi_USB_UIRT_setup(struct ftdi_private *priv)
1329{ 1369{
1330 dbg("%s",__func__); 1370 dbg("%s", __func__);
1331 1371
1332 priv->flags |= ASYNC_SPD_CUST; 1372 priv->flags |= ASYNC_SPD_CUST;
1333 priv->custom_divisor = 77; 1373 priv->custom_divisor = 77;
@@ -1336,9 +1376,10 @@ static void ftdi_USB_UIRT_setup (struct ftdi_private *priv)
1336 1376
1337/* Setup for the HE-TIRA1 device, which requires hardwired 1377/* Setup for the HE-TIRA1 device, which requires hardwired
1338 * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */ 1378 * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */
1339static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv) 1379
1380static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv)
1340{ 1381{
1341 dbg("%s",__func__); 1382 dbg("%s", __func__);
1342 1383
1343 priv->flags |= ASYNC_SPD_CUST; 1384 priv->flags |= ASYNC_SPD_CUST;
1344 priv->custom_divisor = 240; 1385 priv->custom_divisor = 240;
@@ -1356,7 +1397,7 @@ static int ftdi_jtag_probe(struct usb_serial *serial)
1356 struct usb_device *udev = serial->dev; 1397 struct usb_device *udev = serial->dev;
1357 struct usb_interface *interface = serial->interface; 1398 struct usb_interface *interface = serial->interface;
1358 1399
1359 dbg("%s",__func__); 1400 dbg("%s", __func__);
1360 1401
1361 if (interface == udev->actconfig->interface[0]) { 1402 if (interface == udev->actconfig->interface[0]) {
1362 info("Ignoring serial port reserved for JTAG"); 1403 info("Ignoring serial port reserved for JTAG");
@@ -1390,7 +1431,7 @@ static int ftdi_mtxorb_hack_setup(struct usb_serial *serial)
1390 * calls __serial_close for each open of the port 1431 * calls __serial_close for each open of the port
1391 * shutdown is called then (ie ftdi_shutdown) 1432 * shutdown is called then (ie ftdi_shutdown)
1392 */ 1433 */
1393static void ftdi_shutdown (struct usb_serial *serial) 1434static void ftdi_shutdown(struct usb_serial *serial)
1394{ 1435{
1395 dbg("%s", __func__); 1436 dbg("%s", __func__);
1396} 1437}
@@ -1404,7 +1445,7 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
1404 remove_sysfs_attrs(port); 1445 remove_sysfs_attrs(port);
1405 1446
1406 /* all open ports are closed at this point 1447 /* all open ports are closed at this point
1407 * (by usbserial.c:__serial_close, which calls ftdi_close) 1448 * (by usbserial.c:__serial_close, which calls ftdi_close)
1408 */ 1449 */
1409 1450
1410 if (priv) { 1451 if (priv) {
@@ -1415,7 +1456,8 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
1415 return 0; 1456 return 0;
1416} 1457}
1417 1458
1418static int ftdi_open (struct usb_serial_port *port, struct file *filp) 1459static int ftdi_open(struct tty_struct *tty,
1460 struct usb_serial_port *port, struct file *filp)
1419{ /* ftdi_open */ 1461{ /* ftdi_open */
1420 struct usb_device *dev = port->serial->dev; 1462 struct usb_device *dev = port->serial->dev;
1421 struct ftdi_private *priv = usb_get_serial_port_data(port); 1463 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1433,8 +1475,8 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1433 priv->rx_bytes = 0; 1475 priv->rx_bytes = 0;
1434 spin_unlock_irqrestore(&priv->rx_lock, flags); 1476 spin_unlock_irqrestore(&priv->rx_lock, flags);
1435 1477
1436 if (port->tty) 1478 if (tty)
1437 port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1479 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1438 1480
1439 /* No error checking for this (will get errors later anyway) */ 1481 /* No error checking for this (will get errors later anyway) */
1440 /* See ftdi_sio.h for description of what is reset */ 1482 /* See ftdi_sio.h for description of what is reset */
@@ -1448,8 +1490,8 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1448 This is same behaviour as serial.c/rs_open() - Kuba */ 1490 This is same behaviour as serial.c/rs_open() - Kuba */
1449 1491
1450 /* ftdi_set_termios will send usb control messages */ 1492 /* ftdi_set_termios will send usb control messages */
1451 if (port->tty) 1493 if (tty)
1452 ftdi_set_termios(port, port->tty->termios); 1494 ftdi_set_termios(tty, port, tty->termios);
1453 1495
1454 /* FIXME: Flow control might be enabled, so it should be checked - 1496 /* FIXME: Flow control might be enabled, so it should be checked -
1455 we have no control of defaults! */ 1497 we have no control of defaults! */
@@ -1464,12 +1506,14 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1464 /* Start reading from the device */ 1506 /* Start reading from the device */
1465 priv->rx_processed = 0; 1507 priv->rx_processed = 0;
1466 usb_fill_bulk_urb(port->read_urb, dev, 1508 usb_fill_bulk_urb(port->read_urb, dev,
1467 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress), 1509 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
1468 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 1510 port->read_urb->transfer_buffer,
1469 ftdi_read_bulk_callback, port); 1511 port->read_urb->transfer_buffer_length,
1512 ftdi_read_bulk_callback, port);
1470 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 1513 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
1471 if (result) 1514 if (result)
1472 err("%s - failed submitting read urb, error %d", __func__, result); 1515 err("%s - failed submitting read urb, error %d",
1516 __func__, result);
1473 1517
1474 1518
1475 return result; 1519 return result;
@@ -1485,16 +1529,17 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1485 * 1529 *
1486 */ 1530 */
1487 1531
1488static void ftdi_close (struct usb_serial_port *port, struct file *filp) 1532static void ftdi_close(struct tty_struct *tty,
1533 struct usb_serial_port *port, struct file *filp)
1489{ /* ftdi_close */ 1534{ /* ftdi_close */
1490 unsigned int c_cflag = port->tty->termios->c_cflag; 1535 unsigned int c_cflag = tty->termios->c_cflag;
1491 struct ftdi_private *priv = usb_get_serial_port_data(port); 1536 struct ftdi_private *priv = usb_get_serial_port_data(port);
1492 char buf[1]; 1537 char buf[1];
1493 1538
1494 dbg("%s", __func__); 1539 dbg("%s", __func__);
1495 1540
1496 mutex_lock(&port->serial->disc_mutex); 1541 mutex_lock(&port->serial->disc_mutex);
1497 if (c_cflag & HUPCL && !port->serial->disconnected){ 1542 if (c_cflag & HUPCL && !port->serial->disconnected) {
1498 /* Disable flow control */ 1543 /* Disable flow control */
1499 if (usb_control_msg(port->serial->dev, 1544 if (usb_control_msg(port->serial->dev,
1500 usb_sndctrlpipe(port->serial->dev, 0), 1545 usb_sndctrlpipe(port->serial->dev, 0),
@@ -1527,7 +1572,7 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
1527 * 1572 *
1528 * The new devices do not require this byte 1573 * The new devices do not require this byte
1529 */ 1574 */
1530static int ftdi_write (struct usb_serial_port *port, 1575static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
1531 const unsigned char *buf, int count) 1576 const unsigned char *buf, int count)
1532{ /* ftdi_write */ 1577{ /* ftdi_write */
1533 struct ftdi_private *priv = usb_get_serial_port_data(port); 1578 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1554,7 +1599,7 @@ static int ftdi_write (struct usb_serial_port *port,
1554 spin_unlock_irqrestore(&priv->tx_lock, flags); 1599 spin_unlock_irqrestore(&priv->tx_lock, flags);
1555 1600
1556 data_offset = priv->write_offset; 1601 data_offset = priv->write_offset;
1557 dbg("data_offset set to %d",data_offset); 1602 dbg("data_offset set to %d", data_offset);
1558 1603
1559 /* Determine total transfer size */ 1604 /* Determine total transfer size */
1560 transfer_size = count; 1605 transfer_size = count;
@@ -1565,7 +1610,7 @@ static int ftdi_write (struct usb_serial_port *port,
1565 (PKTSZ - data_offset))); 1610 (PKTSZ - data_offset)));
1566 } 1611 }
1567 1612
1568 buffer = kmalloc (transfer_size, GFP_ATOMIC); 1613 buffer = kmalloc(transfer_size, GFP_ATOMIC);
1569 if (!buffer) { 1614 if (!buffer) {
1570 err("%s ran out of kernel memory for urb ...", __func__); 1615 err("%s ran out of kernel memory for urb ...", __func__);
1571 count = -ENOMEM; 1616 count = -ENOMEM;
@@ -1581,20 +1626,20 @@ static int ftdi_write (struct usb_serial_port *port,
1581 1626
1582 /* Copy data */ 1627 /* Copy data */
1583 if (data_offset > 0) { 1628 if (data_offset > 0) {
1584 /* Original sio requires control byte at start of each packet. */ 1629 /* Original sio requires control byte at start of
1630 each packet. */
1585 int user_pktsz = PKTSZ - data_offset; 1631 int user_pktsz = PKTSZ - data_offset;
1586 int todo = count; 1632 int todo = count;
1587 unsigned char *first_byte = buffer; 1633 unsigned char *first_byte = buffer;
1588 const unsigned char *current_position = buf; 1634 const unsigned char *current_position = buf;
1589 1635
1590 while (todo > 0) { 1636 while (todo > 0) {
1591 if (user_pktsz > todo) { 1637 if (user_pktsz > todo)
1592 user_pktsz = todo; 1638 user_pktsz = todo;
1593 }
1594 /* Write the control byte at the front of the packet*/ 1639 /* Write the control byte at the front of the packet*/
1595 *first_byte = 1 | ((user_pktsz) << 2); 1640 *first_byte = 1 | ((user_pktsz) << 2);
1596 /* Copy data for packet */ 1641 /* Copy data for packet */
1597 memcpy (first_byte + data_offset, 1642 memcpy(first_byte + data_offset,
1598 current_position, user_pktsz); 1643 current_position, user_pktsz);
1599 first_byte += user_pktsz + data_offset; 1644 first_byte += user_pktsz + data_offset;
1600 current_position += user_pktsz; 1645 current_position += user_pktsz;
@@ -1603,20 +1648,23 @@ static int ftdi_write (struct usb_serial_port *port,
1603 } else { 1648 } else {
1604 /* No control byte required. */ 1649 /* No control byte required. */
1605 /* Copy in the data to send */ 1650 /* Copy in the data to send */
1606 memcpy (buffer, buf, count); 1651 memcpy(buffer, buf, count);
1607 } 1652 }
1608 1653
1609 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, buffer); 1654 usb_serial_debug_data(debug, &port->dev, __func__,
1655 transfer_size, buffer);
1610 1656
1611 /* fill the buffer and send it */ 1657 /* fill the buffer and send it */
1612 usb_fill_bulk_urb(urb, port->serial->dev, 1658 usb_fill_bulk_urb(urb, port->serial->dev,
1613 usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), 1659 usb_sndbulkpipe(port->serial->dev,
1614 buffer, transfer_size, 1660 port->bulk_out_endpointAddress),
1615 ftdi_write_bulk_callback, port); 1661 buffer, transfer_size,
1662 ftdi_write_bulk_callback, port);
1616 1663
1617 status = usb_submit_urb(urb, GFP_ATOMIC); 1664 status = usb_submit_urb(urb, GFP_ATOMIC);
1618 if (status) { 1665 if (status) {
1619 err("%s - failed submitting write urb, error %d", __func__, status); 1666 err("%s - failed submitting write urb, error %d",
1667 __func__, status);
1620 count = status; 1668 count = status;
1621 goto error; 1669 goto error;
1622 } else { 1670 } else {
@@ -1635,7 +1683,7 @@ static int ftdi_write (struct usb_serial_port *port,
1635error: 1683error:
1636 usb_free_urb(urb); 1684 usb_free_urb(urb);
1637error_no_urb: 1685error_no_urb:
1638 kfree (buffer); 1686 kfree(buffer);
1639error_no_buffer: 1687error_no_buffer:
1640 spin_lock_irqsave(&priv->tx_lock, flags); 1688 spin_lock_irqsave(&priv->tx_lock, flags);
1641 priv->tx_outstanding_urbs--; 1689 priv->tx_outstanding_urbs--;
@@ -1646,7 +1694,7 @@ error_no_buffer:
1646 1694
1647/* This function may get called when the device is closed */ 1695/* This function may get called when the device is closed */
1648 1696
1649static void ftdi_write_bulk_callback (struct urb *urb) 1697static void ftdi_write_bulk_callback(struct urb *urb)
1650{ 1698{
1651 unsigned long flags; 1699 unsigned long flags;
1652 struct usb_serial_port *port = urb->context; 1700 struct usb_serial_port *port = urb->context;
@@ -1656,7 +1704,7 @@ static void ftdi_write_bulk_callback (struct urb *urb)
1656 int status = urb->status; 1704 int status = urb->status;
1657 1705
1658 /* free up the transfer buffer, as usb_free_urb() does not do this */ 1706 /* free up the transfer buffer, as usb_free_urb() does not do this */
1659 kfree (urb->transfer_buffer); 1707 kfree(urb->transfer_buffer);
1660 1708
1661 dbg("%s - port %d", __func__, port->number); 1709 dbg("%s - port %d", __func__, port->number);
1662 1710
@@ -1686,8 +1734,9 @@ static void ftdi_write_bulk_callback (struct urb *urb)
1686} /* ftdi_write_bulk_callback */ 1734} /* ftdi_write_bulk_callback */
1687 1735
1688 1736
1689static int ftdi_write_room( struct usb_serial_port *port ) 1737static int ftdi_write_room(struct tty_struct *tty)
1690{ 1738{
1739 struct usb_serial_port *port = tty->driver_data;
1691 struct ftdi_private *priv = usb_get_serial_port_data(port); 1740 struct ftdi_private *priv = usb_get_serial_port_data(port);
1692 int room; 1741 int room;
1693 unsigned long flags; 1742 unsigned long flags;
@@ -1707,11 +1756,11 @@ static int ftdi_write_room( struct usb_serial_port *port )
1707 } 1756 }
1708 spin_unlock_irqrestore(&priv->tx_lock, flags); 1757 spin_unlock_irqrestore(&priv->tx_lock, flags);
1709 return room; 1758 return room;
1710} /* ftdi_write_room */ 1759}
1711
1712 1760
1713static int ftdi_chars_in_buffer (struct usb_serial_port *port) 1761static int ftdi_chars_in_buffer(struct tty_struct *tty)
1714{ /* ftdi_chars_in_buffer */ 1762{
1763 struct usb_serial_port *port = tty->driver_data;
1715 struct ftdi_private *priv = usb_get_serial_port_data(port); 1764 struct ftdi_private *priv = usb_get_serial_port_data(port);
1716 int buffered; 1765 int buffered;
1717 unsigned long flags; 1766 unsigned long flags;
@@ -1726,12 +1775,10 @@ static int ftdi_chars_in_buffer (struct usb_serial_port *port)
1726 buffered = 0; 1775 buffered = 0;
1727 } 1776 }
1728 return buffered; 1777 return buffered;
1729} /* ftdi_chars_in_buffer */ 1778}
1730
1731
1732 1779
1733static void ftdi_read_bulk_callback (struct urb *urb) 1780static void ftdi_read_bulk_callback(struct urb *urb)
1734{ /* ftdi_read_bulk_callback */ 1781{
1735 struct usb_serial_port *port = urb->context; 1782 struct usb_serial_port *port = urb->context;
1736 struct tty_struct *tty; 1783 struct tty_struct *tty;
1737 struct ftdi_private *priv; 1784 struct ftdi_private *priv;
@@ -1740,19 +1787,21 @@ static void ftdi_read_bulk_callback (struct urb *urb)
1740 int status = urb->status; 1787 int status = urb->status;
1741 1788
1742 if (urb->number_of_packets > 0) { 1789 if (urb->number_of_packets > 0) {
1743 err("%s transfer_buffer_length %d actual_length %d number of packets %d",__func__, 1790 err("%s transfer_buffer_length %d actual_length %d number of packets %d",
1744 urb->transfer_buffer_length, urb->actual_length, urb->number_of_packets ); 1791 __func__,
1745 err("%s transfer_flags %x ", __func__,urb->transfer_flags ); 1792 urb->transfer_buffer_length,
1793 urb->actual_length, urb->number_of_packets);
1794 err("%s transfer_flags %x ", __func__, urb->transfer_flags);
1746 } 1795 }
1747 1796
1748 dbg("%s - port %d", __func__, port->number); 1797 dbg("%s - port %d", __func__, port->number);
1749 1798
1750 if (port->open_count <= 0) 1799 if (port->port.count <= 0)
1751 return; 1800 return;
1752 1801
1753 tty = port->tty; 1802 tty = port->port.tty;
1754 if (!tty) { 1803 if (!tty) {
1755 dbg("%s - bad tty pointer - exiting",__func__); 1804 dbg("%s - bad tty pointer - exiting", __func__);
1756 return; 1805 return;
1757 } 1806 }
1758 1807
@@ -1762,14 +1811,13 @@ static void ftdi_read_bulk_callback (struct urb *urb)
1762 return; 1811 return;
1763 } 1812 }
1764 1813
1765 if (urb != port->read_urb) { 1814 if (urb != port->read_urb)
1766 err("%s - Not my urb!", __func__); 1815 err("%s - Not my urb!", __func__);
1767 }
1768 1816
1769 if (status) { 1817 if (status) {
1770 /* This will happen at close every time so it is a dbg not an err */ 1818 /* This will happen at close every time so it is a dbg not an
1771 dbg("(this is ok on close) nonzero read bulk status received: " 1819 err */
1772 "%d", status); 1820 dbg("(this is ok on close) nonzero read bulk status received: %d", status);
1773 return; 1821 return;
1774 } 1822 }
1775 1823
@@ -1785,7 +1833,7 @@ static void ftdi_read_bulk_callback (struct urb *urb)
1785} /* ftdi_read_bulk_callback */ 1833} /* ftdi_read_bulk_callback */
1786 1834
1787 1835
1788static void ftdi_process_read (struct work_struct *work) 1836static void ftdi_process_read(struct work_struct *work)
1789{ /* ftdi_process_read */ 1837{ /* ftdi_process_read */
1790 struct ftdi_private *priv = 1838 struct ftdi_private *priv =
1791 container_of(work, struct ftdi_private, rx_work.work); 1839 container_of(work, struct ftdi_private, rx_work.work);
@@ -1803,12 +1851,12 @@ static void ftdi_process_read (struct work_struct *work)
1803 1851
1804 dbg("%s - port %d", __func__, port->number); 1852 dbg("%s - port %d", __func__, port->number);
1805 1853
1806 if (port->open_count <= 0) 1854 if (port->port.count <= 0)
1807 return; 1855 return;
1808 1856
1809 tty = port->tty; 1857 tty = port->port.tty;
1810 if (!tty) { 1858 if (!tty) {
1811 dbg("%s - bad tty pointer - exiting",__func__); 1859 dbg("%s - bad tty pointer - exiting", __func__);
1812 return; 1860 return;
1813 } 1861 }
1814 1862
@@ -1832,11 +1880,11 @@ static void ftdi_process_read (struct work_struct *work)
1832 urb->actual_length - priv->rx_processed); 1880 urb->actual_length - priv->rx_processed);
1833 } else { 1881 } else {
1834 /* The first two bytes of every read packet are status */ 1882 /* The first two bytes of every read packet are status */
1835 if (urb->actual_length > 2) { 1883 if (urb->actual_length > 2)
1836 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 1884 usb_serial_debug_data(debug, &port->dev, __func__,
1837 } else { 1885 urb->actual_length, data);
1838 dbg("Status only: %03oo %03oo",data[0],data[1]); 1886 else
1839 } 1887 dbg("Status only: %03oo %03oo", data[0], data[1]);
1840 } 1888 }
1841 1889
1842 1890
@@ -1846,16 +1894,19 @@ static void ftdi_process_read (struct work_struct *work)
1846 /* if CD is dropped and the line is not CLOCAL then we should hangup */ 1894 /* if CD is dropped and the line is not CLOCAL then we should hangup */
1847 1895
1848 need_flip = 0; 1896 need_flip = 0;
1849 for (packet_offset = priv->rx_processed; packet_offset < urb->actual_length; packet_offset += PKTSZ) { 1897 for (packet_offset = priv->rx_processed;
1898 packet_offset < urb->actual_length; packet_offset += PKTSZ) {
1850 int length; 1899 int length;
1851 1900
1852 /* Compare new line status to the old one, signal if different */ 1901 /* Compare new line status to the old one, signal if different/
1853 /* N.B. packet may be processed more than once, but differences 1902 N.B. packet may be processed more than once, but differences
1854 * are only processed once. */ 1903 are only processed once. */
1855 if (priv != NULL) { 1904 if (priv != NULL) {
1856 char new_status = data[packet_offset+0] & FTDI_STATUS_B0_MASK; 1905 char new_status = data[packet_offset + 0] &
1906 FTDI_STATUS_B0_MASK;
1857 if (new_status != priv->prev_status) { 1907 if (new_status != priv->prev_status) {
1858 priv->diff_status |= new_status ^ priv->prev_status; 1908 priv->diff_status |=
1909 new_status ^ priv->prev_status;
1859 wake_up_interruptible(&priv->delta_msr_wait); 1910 wake_up_interruptible(&priv->delta_msr_wait);
1860 priv->prev_status = new_status; 1911 priv->prev_status = new_status;
1861 } 1912 }
@@ -1872,30 +1923,31 @@ static void ftdi_process_read (struct work_struct *work)
1872 break; 1923 break;
1873 } 1924 }
1874 if (tty_buffer_request_room(tty, length) < length) { 1925 if (tty_buffer_request_room(tty, length) < length) {
1875 /* break out & wait for throttling/unthrottling to happen */ 1926 /* break out & wait for throttling/unthrottling to
1927 happen */
1876 dbg("%s - receive room low", __func__); 1928 dbg("%s - receive room low", __func__);
1877 break; 1929 break;
1878 } 1930 }
1879 1931
1880 /* Handle errors and break */ 1932 /* Handle errors and break */
1881 error_flag = TTY_NORMAL; 1933 error_flag = TTY_NORMAL;
1882 /* Although the device uses a bitmask and hence can have multiple */ 1934 /* Although the device uses a bitmask and hence can have
1883 /* errors on a packet - the order here sets the priority the */ 1935 multiple errors on a packet - the order here sets the
1884 /* error is returned to the tty layer */ 1936 priority the error is returned to the tty layer */
1885 1937
1886 if ( data[packet_offset+1] & FTDI_RS_OE ) { 1938 if (data[packet_offset+1] & FTDI_RS_OE) {
1887 error_flag = TTY_OVERRUN; 1939 error_flag = TTY_OVERRUN;
1888 dbg("OVERRRUN error"); 1940 dbg("OVERRRUN error");
1889 } 1941 }
1890 if ( data[packet_offset+1] & FTDI_RS_BI ) { 1942 if (data[packet_offset+1] & FTDI_RS_BI) {
1891 error_flag = TTY_BREAK; 1943 error_flag = TTY_BREAK;
1892 dbg("BREAK received"); 1944 dbg("BREAK received");
1893 } 1945 }
1894 if ( data[packet_offset+1] & FTDI_RS_PE ) { 1946 if (data[packet_offset+1] & FTDI_RS_PE) {
1895 error_flag = TTY_PARITY; 1947 error_flag = TTY_PARITY;
1896 dbg("PARITY error"); 1948 dbg("PARITY error");
1897 } 1949 }
1898 if ( data[packet_offset+1] & FTDI_RS_FE ) { 1950 if (data[packet_offset+1] & FTDI_RS_FE) {
1899 error_flag = TTY_FRAME; 1951 error_flag = TTY_FRAME;
1900 dbg("FRAMING error"); 1952 dbg("FRAMING error");
1901 } 1953 }
@@ -1904,7 +1956,8 @@ static void ftdi_process_read (struct work_struct *work)
1904 /* Note that the error flag is duplicated for 1956 /* Note that the error flag is duplicated for
1905 every character received since we don't know 1957 every character received since we don't know
1906 which character it applied to */ 1958 which character it applied to */
1907 tty_insert_flip_char(tty, data[packet_offset+i], error_flag); 1959 tty_insert_flip_char(tty,
1960 data[packet_offset + i], error_flag);
1908 } 1961 }
1909 need_flip = 1; 1962 need_flip = 1;
1910 } 1963 }
@@ -1912,19 +1965,19 @@ static void ftdi_process_read (struct work_struct *work)
1912#ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW 1965#ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW
1913 /* if a parity error is detected you get status packets forever 1966 /* if a parity error is detected you get status packets forever
1914 until a character is sent without a parity error. 1967 until a character is sent without a parity error.
1915 This doesn't work well since the application receives a never 1968 This doesn't work well since the application receives a
1916 ending stream of bad data - even though new data hasn't been sent. 1969 never ending stream of bad data - even though new data
1917 Therefore I (bill) have taken this out. 1970 hasn't been sent. Therefore I (bill) have taken this out.
1918 However - this might make sense for framing errors and so on 1971 However - this might make sense for framing errors and so on
1919 so I am leaving the code in for now. 1972 so I am leaving the code in for now.
1920 */ 1973 */
1921 else { 1974 else {
1922 if (error_flag != TTY_NORMAL){ 1975 if (error_flag != TTY_NORMAL) {
1923 dbg("error_flag is not normal"); 1976 dbg("error_flag is not normal");
1924 /* In this case it is just status - if that is an error send a bad character */ 1977 /* In this case it is just status - if that is
1925 if(tty->flip.count >= TTY_FLIPBUF_SIZE) { 1978 an error send a bad character */
1979 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
1926 tty_flip_buffer_push(tty); 1980 tty_flip_buffer_push(tty);
1927 }
1928 tty_insert_flip_char(tty, 0xff, error_flag); 1981 tty_insert_flip_char(tty, 0xff, error_flag);
1929 need_flip = 1; 1982 need_flip = 1;
1930 } 1983 }
@@ -1933,9 +1986,8 @@ static void ftdi_process_read (struct work_struct *work)
1933 } /* "for(packet_offset=0..." */ 1986 } /* "for(packet_offset=0..." */
1934 1987
1935 /* Low latency */ 1988 /* Low latency */
1936 if (need_flip) { 1989 if (need_flip)
1937 tty_flip_buffer_push(tty); 1990 tty_flip_buffer_push(tty);
1938 }
1939 1991
1940 if (packet_offset < urb->actual_length) { 1992 if (packet_offset < urb->actual_length) {
1941 /* not completely processed - record progress */ 1993 /* not completely processed - record progress */
@@ -1954,12 +2006,11 @@ static void ftdi_process_read (struct work_struct *work)
1954 } 2006 }
1955 spin_unlock_irqrestore(&priv->rx_lock, flags); 2007 spin_unlock_irqrestore(&priv->rx_lock, flags);
1956 /* if the port is closed stop trying to read */ 2008 /* if the port is closed stop trying to read */
1957 if (port->open_count > 0){ 2009 if (port->port.count > 0)
1958 /* delay processing of remainder */ 2010 /* delay processing of remainder */
1959 schedule_delayed_work(&priv->rx_work, 1); 2011 schedule_delayed_work(&priv->rx_work, 1);
1960 } else { 2012 else
1961 dbg("%s - port is closed", __func__); 2013 dbg("%s - port is closed", __func__);
1962 }
1963 return; 2014 return;
1964 } 2015 }
1965 2016
@@ -1967,24 +2018,26 @@ static void ftdi_process_read (struct work_struct *work)
1967 priv->rx_processed = 0; 2018 priv->rx_processed = 0;
1968 2019
1969 /* if the port is closed stop trying to read */ 2020 /* if the port is closed stop trying to read */
1970 if (port->open_count > 0){ 2021 if (port->port.count > 0) {
1971 /* Continue trying to always read */ 2022 /* Continue trying to always read */
1972 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 2023 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
1973 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), 2024 usb_rcvbulkpipe(port->serial->dev,
1974 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 2025 port->bulk_in_endpointAddress),
1975 ftdi_read_bulk_callback, port); 2026 port->read_urb->transfer_buffer,
2027 port->read_urb->transfer_buffer_length,
2028 ftdi_read_bulk_callback, port);
1976 2029
1977 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 2030 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1978 if (result) 2031 if (result)
1979 err("%s - failed resubmitting read urb, error %d", __func__, result); 2032 err("%s - failed resubmitting read urb, error %d",
2033 __func__, result);
1980 } 2034 }
1981
1982 return;
1983} /* ftdi_process_read */ 2035} /* ftdi_process_read */
1984 2036
1985 2037
1986static void ftdi_break_ctl( struct usb_serial_port *port, int break_state ) 2038static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
1987{ 2039{
2040 struct usb_serial_port *port = tty->driver_data;
1988 struct ftdi_private *priv = usb_get_serial_port_data(port); 2041 struct ftdi_private *priv = usb_get_serial_port_data(port);
1989 __u16 urb_value = 0; 2042 __u16 urb_value = 0;
1990 char buf[1]; 2043 char buf[1];
@@ -1993,22 +2046,23 @@ static void ftdi_break_ctl( struct usb_serial_port *port, int break_state )
1993 /* see drivers/char/tty_io.c to see it used */ 2046 /* see drivers/char/tty_io.c to see it used */
1994 /* last_set_data_urb_value NEVER has the break bit set in it */ 2047 /* last_set_data_urb_value NEVER has the break bit set in it */
1995 2048
1996 if (break_state) { 2049 if (break_state)
1997 urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK; 2050 urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK;
1998 } else { 2051 else
1999 urb_value = priv->last_set_data_urb_value; 2052 urb_value = priv->last_set_data_urb_value;
2000 }
2001 2053
2002 2054 if (usb_control_msg(port->serial->dev,
2003 if (usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0), 2055 usb_sndctrlpipe(port->serial->dev, 0),
2004 FTDI_SIO_SET_DATA_REQUEST, 2056 FTDI_SIO_SET_DATA_REQUEST,
2005 FTDI_SIO_SET_DATA_REQUEST_TYPE, 2057 FTDI_SIO_SET_DATA_REQUEST_TYPE,
2006 urb_value , priv->interface, 2058 urb_value , priv->interface,
2007 buf, 0, WDR_TIMEOUT) < 0) { 2059 buf, 0, WDR_TIMEOUT) < 0) {
2008 err("%s FAILED to enable/disable break state (state was %d)", __func__,break_state); 2060 err("%s FAILED to enable/disable break state (state was %d)",
2061 __func__, break_state);
2009 } 2062 }
2010 2063
2011 dbg("%s break state is %d - urb is %d", __func__,break_state, urb_value); 2064 dbg("%s break state is %d - urb is %d", __func__,
2065 break_state, urb_value);
2012 2066
2013} 2067}
2014 2068
@@ -2018,26 +2072,28 @@ static void ftdi_break_ctl( struct usb_serial_port *port, int break_state )
2018 * WARNING: set_termios calls this with old_termios in kernel space 2072 * WARNING: set_termios calls this with old_termios in kernel space
2019 */ 2073 */
2020 2074
2021static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 2075static void ftdi_set_termios(struct tty_struct *tty,
2076 struct usb_serial_port *port, struct ktermios *old_termios)
2022{ /* ftdi_termios */ 2077{ /* ftdi_termios */
2023 struct usb_device *dev = port->serial->dev; 2078 struct usb_device *dev = port->serial->dev;
2024 struct ftdi_private *priv = usb_get_serial_port_data(port); 2079 struct ftdi_private *priv = usb_get_serial_port_data(port);
2025 struct ktermios *termios = port->tty->termios; 2080 struct ktermios *termios = tty->termios;
2026 unsigned int cflag = termios->c_cflag; 2081 unsigned int cflag = termios->c_cflag;
2027 __u16 urb_value; /* will hold the new flags */ 2082 __u16 urb_value; /* will hold the new flags */
2028 char buf[1]; /* Perhaps I should dynamically alloc this? */ 2083 char buf[1]; /* Perhaps I should dynamically alloc this? */
2029 2084
2030 // Added for xon/xoff support 2085 /* Added for xon/xoff support */
2031 unsigned int iflag = termios->c_iflag; 2086 unsigned int iflag = termios->c_iflag;
2032 unsigned char vstop; 2087 unsigned char vstop;
2033 unsigned char vstart; 2088 unsigned char vstart;
2034 2089
2035 dbg("%s", __func__); 2090 dbg("%s", __func__);
2036 2091
2037 /* Force baud rate if this device requires it, unless it is set to B0. */ 2092 /* Force baud rate if this device requires it, unless it is set to
2093 B0. */
2038 if (priv->force_baud && ((termios->c_cflag & CBAUD) != B0)) { 2094 if (priv->force_baud && ((termios->c_cflag & CBAUD) != B0)) {
2039 dbg("%s: forcing baud rate for this device", __func__); 2095 dbg("%s: forcing baud rate for this device", __func__);
2040 tty_encode_baud_rate(port->tty, priv->force_baud, 2096 tty_encode_baud_rate(tty, priv->force_baud,
2041 priv->force_baud); 2097 priv->force_baud);
2042 } 2098 }
2043 2099
@@ -2053,8 +2109,8 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2053 not - so just do the change regardless - should be able to 2109 not - so just do the change regardless - should be able to
2054 compare old_termios and tty->termios */ 2110 compare old_termios and tty->termios */
2055 /* NOTE These routines can get interrupted by 2111 /* NOTE These routines can get interrupted by
2056 ftdi_sio_read_bulk_callback - need to examine what this 2112 ftdi_sio_read_bulk_callback - need to examine what this means -
2057 means - don't see any problems yet */ 2113 don't see any problems yet */
2058 2114
2059 /* Set number of data bits, parity, stop bits */ 2115 /* Set number of data bits, parity, stop bits */
2060 2116
@@ -2078,8 +2134,8 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2078 } 2134 }
2079 } 2135 }
2080 2136
2081 /* This is needed by the break command since it uses the same command - but is 2137 /* This is needed by the break command since it uses the same command
2082 * or'ed with this value */ 2138 - but is or'ed with this value */
2083 priv->last_set_data_urb_value = urb_value; 2139 priv->last_set_data_urb_value = urb_value;
2084 2140
2085 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 2141 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
@@ -2091,7 +2147,7 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2091 } 2147 }
2092 2148
2093 /* Now do the baudrate */ 2149 /* Now do the baudrate */
2094 if ((cflag & CBAUD) == B0 ) { 2150 if ((cflag & CBAUD) == B0) {
2095 /* Disable flow control */ 2151 /* Disable flow control */
2096 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 2152 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
2097 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 2153 FTDI_SIO_SET_FLOW_CTRL_REQUEST,
@@ -2104,13 +2160,11 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2104 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 2160 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
2105 } else { 2161 } else {
2106 /* set the baudrate determined before */ 2162 /* set the baudrate determined before */
2107 if (change_speed(port)) { 2163 if (change_speed(tty, port))
2108 err("%s urb failed to set baudrate", __func__); 2164 err("%s urb failed to set baudrate", __func__);
2109 }
2110 /* Ensure RTS and DTR are raised when baudrate changed from 0 */ 2165 /* Ensure RTS and DTR are raised when baudrate changed from 0 */
2111 if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) { 2166 if (!old_termios || (old_termios->c_cflag & CBAUD) == B0)
2112 set_mctrl(port, TIOCM_DTR | TIOCM_RTS); 2167 set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
2113 }
2114 } 2168 }
2115 2169
2116 /* Set flow control */ 2170 /* Set flow control */
@@ -2130,18 +2184,22 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2130 /* 2184 /*
2131 * Xon/Xoff code 2185 * Xon/Xoff code
2132 * 2186 *
2133 * Check the IXOFF status in the iflag component of the termios structure 2187 * Check the IXOFF status in the iflag component of the
2134 * if IXOFF is not set, the pre-xon/xoff code is executed. 2188 * termios structure. If IXOFF is not set, the pre-xon/xoff
2135 */ 2189 * code is executed.
2190 */
2136 if (iflag & IXOFF) { 2191 if (iflag & IXOFF) {
2137 dbg("%s request to enable xonxoff iflag=%04x",__func__,iflag); 2192 dbg("%s request to enable xonxoff iflag=%04x",
2138 // Try to enable the XON/XOFF on the ftdi_sio 2193 __func__, iflag);
2139 // Set the vstart and vstop -- could have been done up above where 2194 /* Try to enable the XON/XOFF on the ftdi_sio
2140 // a lot of other dereferencing is done but that would be very 2195 * Set the vstart and vstop -- could have been done up
2141 // inefficient as vstart and vstop are not always needed 2196 * above where a lot of other dereferencing is done but
2197 * that would be very inefficient as vstart and vstop
2198 * are not always needed.
2199 */
2142 vstart = termios->c_cc[VSTART]; 2200 vstart = termios->c_cc[VSTART];
2143 vstop = termios->c_cc[VSTOP]; 2201 vstop = termios->c_cc[VSTOP];
2144 urb_value=(vstop << 8) | (vstart); 2202 urb_value = (vstop << 8) | (vstart);
2145 2203
2146 if (usb_control_msg(dev, 2204 if (usb_control_msg(dev,
2147 usb_sndctrlpipe(dev, 0), 2205 usb_sndctrlpipe(dev, 0),
@@ -2153,8 +2211,9 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2153 err("urb failed to set to xon/xoff flow control"); 2211 err("urb failed to set to xon/xoff flow control");
2154 } 2212 }
2155 } else { 2213 } else {
2156 /* else clause to only run if cfag ! CRTSCTS and iflag ! XOFF */ 2214 /* else clause to only run if cflag ! CRTSCTS and iflag
2157 /* CHECKME Assuming XON/XOFF handled by tty stack - not by device */ 2215 * ! XOFF. CHECKME Assuming XON/XOFF handled by tty
2216 * stack - not by device */
2158 dbg("%s Turning off hardware flow control", __func__); 2217 dbg("%s Turning off hardware flow control", __func__);
2159 if (usb_control_msg(dev, 2218 if (usb_control_msg(dev,
2160 usb_sndctrlpipe(dev, 0), 2219 usb_sndctrlpipe(dev, 0),
@@ -2168,11 +2227,11 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
2168 2227
2169 } 2228 }
2170 return; 2229 return;
2171} /* ftdi_termios */ 2230}
2172
2173 2231
2174static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file) 2232static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
2175{ 2233{
2234 struct usb_serial_port *port = tty->driver_data;
2176 struct ftdi_private *priv = usb_get_serial_port_data(port); 2235 struct ftdi_private *priv = usb_get_serial_port_data(port);
2177 unsigned char buf[2]; 2236 unsigned char buf[2];
2178 int ret; 2237 int ret;
@@ -2181,32 +2240,35 @@ static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file)
2181 switch (priv->chip_type) { 2240 switch (priv->chip_type) {
2182 case SIO: 2241 case SIO:
2183 /* Request the status from the device */ 2242 /* Request the status from the device */
2184 if ((ret = usb_control_msg(port->serial->dev, 2243 ret = usb_control_msg(port->serial->dev,
2185 usb_rcvctrlpipe(port->serial->dev, 0), 2244 usb_rcvctrlpipe(port->serial->dev, 0),
2186 FTDI_SIO_GET_MODEM_STATUS_REQUEST, 2245 FTDI_SIO_GET_MODEM_STATUS_REQUEST,
2187 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 2246 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2188 0, 0, 2247 0, 0,
2189 buf, 1, WDR_TIMEOUT)) < 0 ) { 2248 buf, 1, WDR_TIMEOUT);
2249 if (ret < 0) {
2190 err("%s Could not get modem status of device - err: %d", __func__, 2250 err("%s Could not get modem status of device - err: %d", __func__,
2191 ret); 2251 ret);
2192 return(ret); 2252 return ret;
2193 } 2253 }
2194 break; 2254 break;
2195 case FT8U232AM: 2255 case FT8U232AM:
2196 case FT232BM: 2256 case FT232BM:
2197 case FT2232C: 2257 case FT2232C:
2198 case FT232RL: 2258 case FT232RL:
2199 /* the 8U232AM returns a two byte value (the sio is a 1 byte value) - in the same 2259 /* the 8U232AM returns a two byte value (the sio is a 1 byte
2200 format as the data returned from the in point */ 2260 value) - in the same format as the data returned from the in
2201 if ((ret = usb_control_msg(port->serial->dev, 2261 point */
2202 usb_rcvctrlpipe(port->serial->dev, 0), 2262 ret = usb_control_msg(port->serial->dev,
2203 FTDI_SIO_GET_MODEM_STATUS_REQUEST, 2263 usb_rcvctrlpipe(port->serial->dev, 0),
2204 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 2264 FTDI_SIO_GET_MODEM_STATUS_REQUEST,
2205 0, priv->interface, 2265 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2206 buf, 2, WDR_TIMEOUT)) < 0 ) { 2266 0, priv->interface,
2267 buf, 2, WDR_TIMEOUT);
2268 if (ret < 0) {
2207 err("%s Could not get modem status of device - err: %d", __func__, 2269 err("%s Could not get modem status of device - err: %d", __func__,
2208 ret); 2270 ret);
2209 return(ret); 2271 return ret;
2210 } 2272 }
2211 break; 2273 break;
2212 default: 2274 default:
@@ -2221,15 +2283,19 @@ static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file)
2221 priv->last_dtr_rts; 2283 priv->last_dtr_rts;
2222} 2284}
2223 2285
2224static int ftdi_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear) 2286static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
2287 unsigned int set, unsigned int clear)
2225{ 2288{
2289 struct usb_serial_port *port = tty->driver_data;
2226 dbg("%s TIOCMSET", __func__); 2290 dbg("%s TIOCMSET", __func__);
2227 return update_mctrl(port, set, clear); 2291 return update_mctrl(port, set, clear);
2228} 2292}
2229 2293
2230 2294
2231static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 2295static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
2296 unsigned int cmd, unsigned long arg)
2232{ 2297{
2298 struct usb_serial_port *port = tty->driver_data;
2233 struct ftdi_private *priv = usb_get_serial_port_data(port); 2299 struct ftdi_private *priv = usb_get_serial_port_data(port);
2234 2300
2235 dbg("%s cmd 0x%04x", __func__, cmd); 2301 dbg("%s cmd 0x%04x", __func__, cmd);
@@ -2238,10 +2304,12 @@ static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigne
2238 switch (cmd) { 2304 switch (cmd) {
2239 2305
2240 case TIOCGSERIAL: /* gets serial port data */ 2306 case TIOCGSERIAL: /* gets serial port data */
2241 return get_serial_info(port, (struct serial_struct __user *) arg); 2307 return get_serial_info(port,
2308 (struct serial_struct __user *) arg);
2242 2309
2243 case TIOCSSERIAL: /* sets serial port data */ 2310 case TIOCSSERIAL: /* sets serial port data */
2244 return set_serial_info(port, (struct serial_struct __user *) arg); 2311 return set_serial_info(tty, port,
2312 (struct serial_struct __user *) arg);
2245 2313
2246 /* 2314 /*
2247 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 2315 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
@@ -2260,45 +2328,41 @@ static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigne
2260 else { 2328 else {
2261 char diff = priv->diff_status; 2329 char diff = priv->diff_status;
2262 2330
2263 if (diff == 0) { 2331 if (diff == 0)
2264 return -EIO; /* no change => error */ 2332 return -EIO; /* no change => error */
2265 }
2266 2333
2267 /* Consume all events */ 2334 /* Consume all events */
2268 priv->diff_status = 0; 2335 priv->diff_status = 0;
2269 2336
2270 /* Return 0 if caller wanted to know about these bits */ 2337 /* Return 0 if caller wanted to know about
2271 if ( ((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) || 2338 these bits */
2272 ((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) || 2339 if (((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) ||
2273 ((arg & TIOCM_CD) && (diff & FTDI_RS0_RLSD)) || 2340 ((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) ||
2274 ((arg & TIOCM_CTS) && (diff & FTDI_RS0_CTS)) ) { 2341 ((arg & TIOCM_CD) && (diff & FTDI_RS0_RLSD)) ||
2342 ((arg & TIOCM_CTS) && (diff & FTDI_RS0_CTS))) {
2275 return 0; 2343 return 0;
2276 } 2344 }
2277 /* 2345 /*
2278 * Otherwise caller can't care less about what happened, 2346 * Otherwise caller can't care less about what
2279 * and so we continue to wait for more events. 2347 * happened,and so we continue to wait for more
2348 * events.
2280 */ 2349 */
2281 } 2350 }
2282 } 2351 }
2283 return(0); 2352 return 0;
2284 break;
2285 default: 2353 default:
2286 break; 2354 break;
2287
2288 } 2355 }
2289 2356 /* This is not necessarily an error - turns out the higher layers
2290 2357 * will do some ioctls themselves (see comment above)
2291 /* This is not necessarily an error - turns out the higher layers will do
2292 * some ioctls itself (see comment above)
2293 */ 2358 */
2294 dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __func__, cmd); 2359 dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __func__, cmd);
2360 return -ENOIOCTLCMD;
2361}
2295 2362
2296 return(-ENOIOCTLCMD); 2363static void ftdi_throttle(struct tty_struct *tty)
2297} /* ftdi_ioctl */
2298
2299
2300static void ftdi_throttle (struct usb_serial_port *port)
2301{ 2364{
2365 struct usb_serial_port *port = tty->driver_data;
2302 struct ftdi_private *priv = usb_get_serial_port_data(port); 2366 struct ftdi_private *priv = usb_get_serial_port_data(port);
2303 unsigned long flags; 2367 unsigned long flags;
2304 2368
@@ -2310,8 +2374,9 @@ static void ftdi_throttle (struct usb_serial_port *port)
2310} 2374}
2311 2375
2312 2376
2313static void ftdi_unthrottle (struct usb_serial_port *port) 2377static void ftdi_unthrottle(struct tty_struct *tty)
2314{ 2378{
2379 struct usb_serial_port *port = tty->driver_data;
2315 struct ftdi_private *priv = usb_get_serial_port_data(port); 2380 struct ftdi_private *priv = usb_get_serial_port_data(port);
2316 int actually_throttled; 2381 int actually_throttled;
2317 unsigned long flags; 2382 unsigned long flags;
@@ -2327,7 +2392,7 @@ static void ftdi_unthrottle (struct usb_serial_port *port)
2327 schedule_delayed_work(&priv->rx_work, 0); 2392 schedule_delayed_work(&priv->rx_work, 0);
2328} 2393}
2329 2394
2330static int __init ftdi_init (void) 2395static int __init ftdi_init(void)
2331{ 2396{
2332 int retval; 2397 int retval;
2333 2398
@@ -2357,13 +2422,13 @@ failed_sio_register:
2357} 2422}
2358 2423
2359 2424
2360static void __exit ftdi_exit (void) 2425static void __exit ftdi_exit(void)
2361{ 2426{
2362 2427
2363 dbg("%s", __func__); 2428 dbg("%s", __func__);
2364 2429
2365 usb_deregister (&ftdi_driver); 2430 usb_deregister(&ftdi_driver);
2366 usb_serial_deregister (&ftdi_sio_device); 2431 usb_serial_deregister(&ftdi_sio_device);
2367 2432
2368} 2433}
2369 2434
@@ -2371,8 +2436,8 @@ static void __exit ftdi_exit (void)
2371module_init(ftdi_init); 2436module_init(ftdi_init);
2372module_exit(ftdi_exit); 2437module_exit(ftdi_exit);
2373 2438
2374MODULE_AUTHOR( DRIVER_AUTHOR ); 2439MODULE_AUTHOR(DRIVER_AUTHOR);
2375MODULE_DESCRIPTION( DRIVER_DESC ); 2440MODULE_DESCRIPTION(DRIVER_DESC);
2376MODULE_LICENSE("GPL"); 2441MODULE_LICENSE("GPL");
2377 2442
2378module_param(debug, bool, S_IRUGO | S_IWUSR); 2443module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 8302eca893ea..a577ea44dcf9 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -1,20 +1,20 @@
1/* 1/*
2 * Definitions for the FTDI USB Single Port Serial Converter - 2 * Definitions for the FTDI USB Single Port Serial Converter -
3 * known as FTDI_SIO (Serial Input/Output application of the chipset) 3 * known as FTDI_SIO (Serial Input/Output application of the chipset)
4 * 4 *
5 * The example I have is known as the USC-1000 which is available from 5 * The example I have is known as the USC-1000 which is available from
6 * http://www.dse.co.nz - cat no XH4214 It looks similar to this: 6 * http://www.dse.co.nz - cat no XH4214 It looks similar to this:
7 * http://www.dansdata.com/usbser.htm but I can't be sure There are other 7 * http://www.dansdata.com/usbser.htm but I can't be sure There are other
8 * USC-1000s which don't look like my device though so beware! 8 * USC-1000s which don't look like my device though so beware!
9 * 9 *
10 * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side, 10 * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side,
11 * USB on the other. 11 * USB on the other.
12 * 12 *
13 * Thanx to FTDI (http://www.ftdi.co.uk) for so kindly providing details 13 * Thanx to FTDI (http://www.ftdi.co.uk) for so kindly providing details
14 * of the protocol required to talk to the device and ongoing assistence 14 * of the protocol required to talk to the device and ongoing assistence
15 * during development. 15 * during development.
16 * 16 *
17 * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the 17 * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the
18 * FTDI_SIO implementation. 18 * FTDI_SIO implementation.
19 * 19 *
20 * Philipp Gühring - pg@futureware.at - added the Device ID of the USB relais 20 * Philipp Gühring - pg@futureware.at - added the Device ID of the USB relais
@@ -472,7 +472,7 @@
472/* 472/*
473 * DSS-20 Sync Station for Sony Ericsson P800 473 * DSS-20 Sync Station for Sony Ericsson P800
474 */ 474 */
475#define FTDI_DSS20_PID 0xFC82 475#define FTDI_DSS20_PID 0xFC82
476 476
477/* 477/*
478 * Home Electronics (www.home-electro.com) USB gadgets 478 * Home Electronics (www.home-electro.com) USB gadgets
@@ -884,7 +884,7 @@
884/* 884/*
885 * BmRequestType: 0100 0000B 885 * BmRequestType: 0100 0000B
886 * bRequest: FTDI_SIO_RESET 886 * bRequest: FTDI_SIO_RESET
887 * wValue: Control Value 887 * wValue: Control Value
888 * 0 = Reset SIO 888 * 0 = Reset SIO
889 * 1 = Purge RX buffer 889 * 1 = Purge RX buffer
890 * 2 = Purge TX buffer 890 * 2 = Purge TX buffer
@@ -952,7 +952,7 @@
952 * 101 - add .625 to divisor 952 * 101 - add .625 to divisor
953 * 110 - add .750 to divisor 953 * 110 - add .750 to divisor
954 * 111 - add .875 to divisor 954 * 111 - add .875 to divisor
955 * Bits 15 to 0 of the 17-bit divisor are placed in the urb value. Bit 16 is 955 * Bits 15 to 0 of the 17-bit divisor are placed in the urb value. Bit 16 is
956 * placed in bit 0 of the urb index. 956 * placed in bit 0 of the urb index.
957 * 957 *
958 * Note that there are a couple of special cases to support the highest baud 958 * Note that there are a couple of special cases to support the highest baud
@@ -971,8 +971,8 @@ typedef enum {
971} ftdi_chip_type_t; 971} ftdi_chip_type_t;
972 972
973typedef enum { 973typedef enum {
974 ftdi_sio_b300 = 0, 974 ftdi_sio_b300 = 0,
975 ftdi_sio_b600 = 1, 975 ftdi_sio_b600 = 1,
976 ftdi_sio_b1200 = 2, 976 ftdi_sio_b1200 = 2,
977 ftdi_sio_b2400 = 3, 977 ftdi_sio_b2400 = 3,
978 ftdi_sio_b4800 = 4, 978 ftdi_sio_b4800 = 4,
@@ -981,7 +981,7 @@ typedef enum {
981 ftdi_sio_b38400 = 7, 981 ftdi_sio_b38400 = 7,
982 ftdi_sio_b57600 = 8, 982 ftdi_sio_b57600 = 8,
983 ftdi_sio_b115200 = 9 983 ftdi_sio_b115200 = 9
984} FTDI_SIO_baudrate_t ; 984} FTDI_SIO_baudrate_t;
985 985
986/* 986/*
987 * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor values 987 * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor values
@@ -990,19 +990,19 @@ typedef enum {
990 990
991#define FTDI_SIO_SET_DATA_REQUEST FTDI_SIO_SET_DATA 991#define FTDI_SIO_SET_DATA_REQUEST FTDI_SIO_SET_DATA
992#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40 992#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40
993#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8 ) 993#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8)
994#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8 ) 994#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8)
995#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8 ) 995#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8)
996#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8 ) 996#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8)
997#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8 ) 997#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8)
998#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11 ) 998#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11)
999#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11 ) 999#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11)
1000#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11 ) 1000#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11)
1001#define FTDI_SIO_SET_BREAK (0x1 << 14) 1001#define FTDI_SIO_SET_BREAK (0x1 << 14)
1002/* FTDI_SIO_SET_DATA */ 1002/* FTDI_SIO_SET_DATA */
1003 1003
1004/* 1004/*
1005 * BmRequestType: 0100 0000B 1005 * BmRequestType: 0100 0000B
1006 * bRequest: FTDI_SIO_SET_DATA 1006 * bRequest: FTDI_SIO_SET_DATA
1007 * wValue: Data characteristics (see below) 1007 * wValue: Data characteristics (see below)
1008 * wIndex: Port 1008 * wIndex: Port
@@ -1035,7 +1035,7 @@ typedef enum {
1035#define FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE 0x40 1035#define FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE 0x40
1036#define FTDI_SIO_SET_MODEM_CTRL_REQUEST FTDI_SIO_MODEM_CTRL 1036#define FTDI_SIO_SET_MODEM_CTRL_REQUEST FTDI_SIO_MODEM_CTRL
1037 1037
1038/* 1038/*
1039 * BmRequestType: 0100 0000B 1039 * BmRequestType: 0100 0000B
1040 * bRequest: FTDI_SIO_MODEM_CTRL 1040 * bRequest: FTDI_SIO_MODEM_CTRL
1041 * wValue: ControlValue (see below) 1041 * wValue: ControlValue (see below)
@@ -1049,11 +1049,11 @@ typedef enum {
1049 */ 1049 */
1050 1050
1051#define FTDI_SIO_SET_DTR_MASK 0x1 1051#define FTDI_SIO_SET_DTR_MASK 0x1
1052#define FTDI_SIO_SET_DTR_HIGH ( 1 | ( FTDI_SIO_SET_DTR_MASK << 8)) 1052#define FTDI_SIO_SET_DTR_HIGH (1 | (FTDI_SIO_SET_DTR_MASK << 8))
1053#define FTDI_SIO_SET_DTR_LOW ( 0 | ( FTDI_SIO_SET_DTR_MASK << 8)) 1053#define FTDI_SIO_SET_DTR_LOW (0 | (FTDI_SIO_SET_DTR_MASK << 8))
1054#define FTDI_SIO_SET_RTS_MASK 0x2 1054#define FTDI_SIO_SET_RTS_MASK 0x2
1055#define FTDI_SIO_SET_RTS_HIGH ( 2 | ( FTDI_SIO_SET_RTS_MASK << 8 )) 1055#define FTDI_SIO_SET_RTS_HIGH (2 | (FTDI_SIO_SET_RTS_MASK << 8))
1056#define FTDI_SIO_SET_RTS_LOW ( 0 | ( FTDI_SIO_SET_RTS_MASK << 8 )) 1056#define FTDI_SIO_SET_RTS_LOW (0 | (FTDI_SIO_SET_RTS_MASK << 8))
1057 1057
1058/* 1058/*
1059 * ControlValue 1059 * ControlValue
@@ -1076,7 +1076,7 @@ typedef enum {
1076/* FTDI_SIO_SET_FLOW_CTRL */ 1076/* FTDI_SIO_SET_FLOW_CTRL */
1077#define FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE 0x40 1077#define FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE 0x40
1078#define FTDI_SIO_SET_FLOW_CTRL_REQUEST FTDI_SIO_SET_FLOW_CTRL 1078#define FTDI_SIO_SET_FLOW_CTRL_REQUEST FTDI_SIO_SET_FLOW_CTRL
1079#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0 1079#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0
1080#define FTDI_SIO_RTS_CTS_HS (0x1 << 8) 1080#define FTDI_SIO_RTS_CTS_HS (0x1 << 8)
1081#define FTDI_SIO_DTR_DSR_HS (0x2 << 8) 1081#define FTDI_SIO_DTR_DSR_HS (0x2 << 8)
1082#define FTDI_SIO_XON_XOFF_HS (0x4 << 8) 1082#define FTDI_SIO_XON_XOFF_HS (0x4 << 8)
@@ -1085,7 +1085,7 @@ typedef enum {
1085 * bRequest: FTDI_SIO_SET_FLOW_CTRL 1085 * bRequest: FTDI_SIO_SET_FLOW_CTRL
1086 * wValue: Xoff/Xon 1086 * wValue: Xoff/Xon
1087 * wIndex: Protocol/Port - hIndex is protocl / lIndex is port 1087 * wIndex: Protocol/Port - hIndex is protocl / lIndex is port
1088 * wLength: 0 1088 * wLength: 0
1089 * Data: None 1089 * Data: None
1090 * 1090 *
1091 * hIndex protocol is: 1091 * hIndex protocol is:
@@ -1101,10 +1101,10 @@ typedef enum {
1101 * 1101 *
1102 * A value of zero in the hIndex field disables handshaking 1102 * A value of zero in the hIndex field disables handshaking
1103 * 1103 *
1104 * If Xon/Xoff handshaking is specified, the hValue field should contain the XOFF character 1104 * If Xon/Xoff handshaking is specified, the hValue field should contain the XOFF character
1105 * and the lValue field contains the XON character. 1105 * and the lValue field contains the XON character.
1106 */ 1106 */
1107 1107
1108/* 1108/*
1109 * FTDI_SIO_GET_LATENCY_TIMER 1109 * FTDI_SIO_GET_LATENCY_TIMER
1110 * 1110 *
@@ -1118,7 +1118,7 @@ typedef enum {
1118#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST FTDI_SIO_GET_LATENCY_TIMER 1118#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST FTDI_SIO_GET_LATENCY_TIMER
1119#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE 0xC0 1119#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE 0xC0
1120 1120
1121/* 1121/*
1122 * BmRequestType: 1100 0000b 1122 * BmRequestType: 1100 0000b
1123 * bRequest: FTDI_SIO_GET_LATENCY_TIMER 1123 * bRequest: FTDI_SIO_GET_LATENCY_TIMER
1124 * wValue: 0 1124 * wValue: 0
@@ -1127,7 +1127,7 @@ typedef enum {
1127 * Data: latency (on return) 1127 * Data: latency (on return)
1128 */ 1128 */
1129 1129
1130/* 1130/*
1131 * FTDI_SIO_SET_LATENCY_TIMER 1131 * FTDI_SIO_SET_LATENCY_TIMER
1132 * 1132 *
1133 * Set the timeout interval. The FTDI collects data from the slave 1133 * Set the timeout interval. The FTDI collects data from the slave
@@ -1140,7 +1140,7 @@ typedef enum {
1140#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST FTDI_SIO_SET_LATENCY_TIMER 1140#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST FTDI_SIO_SET_LATENCY_TIMER
1141#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE 0x40 1141#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE 0x40
1142 1142
1143/* 1143/*
1144 * BmRequestType: 0100 0000b 1144 * BmRequestType: 0100 0000b
1145 * bRequest: FTDI_SIO_SET_LATENCY_TIMER 1145 * bRequest: FTDI_SIO_SET_LATENCY_TIMER
1146 * wValue: Latency (milliseconds) 1146 * wValue: Latency (milliseconds)
@@ -1155,7 +1155,7 @@ typedef enum {
1155 */ 1155 */
1156 1156
1157/* 1157/*
1158 * FTDI_SIO_SET_EVENT_CHAR 1158 * FTDI_SIO_SET_EVENT_CHAR
1159 * 1159 *
1160 * Set the special event character for the specified communications port. 1160 * Set the special event character for the specified communications port.
1161 * If the device sees this character it will immediately return the 1161 * If the device sees this character it will immediately return the
@@ -1168,7 +1168,7 @@ typedef enum {
1168#define FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE 0x40 1168#define FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE 0x40
1169 1169
1170 1170
1171/* 1171/*
1172 * BmRequestType: 0100 0000b 1172 * BmRequestType: 0100 0000b
1173 * bRequest: FTDI_SIO_SET_EVENT_CHAR 1173 * bRequest: FTDI_SIO_SET_EVENT_CHAR
1174 * wValue: EventChar 1174 * wValue: EventChar
@@ -1184,12 +1184,12 @@ typedef enum {
1184 * B9..15 Reserved 1184 * B9..15 Reserved
1185 * 1185 *
1186 */ 1186 */
1187 1187
1188/* FTDI_SIO_SET_ERROR_CHAR */ 1188/* FTDI_SIO_SET_ERROR_CHAR */
1189 1189
1190/* Set the parity error replacement character for the specified communications port */ 1190/* Set the parity error replacement character for the specified communications port */
1191 1191
1192/* 1192/*
1193 * BmRequestType: 0100 0000b 1193 * BmRequestType: 0100 0000b
1194 * bRequest: FTDI_SIO_SET_EVENT_CHAR 1194 * bRequest: FTDI_SIO_SET_EVENT_CHAR
1195 * wValue: Error Char 1195 * wValue: Error Char
@@ -1215,15 +1215,15 @@ typedef enum {
1215#define FTDI_SIO_DSR_MASK 0x20 1215#define FTDI_SIO_DSR_MASK 0x20
1216#define FTDI_SIO_RI_MASK 0x40 1216#define FTDI_SIO_RI_MASK 0x40
1217#define FTDI_SIO_RLSD_MASK 0x80 1217#define FTDI_SIO_RLSD_MASK 0x80
1218/* 1218/*
1219 * BmRequestType: 1100 0000b 1219 * BmRequestType: 1100 0000b
1220 * bRequest: FTDI_SIO_GET_MODEM_STATUS 1220 * bRequest: FTDI_SIO_GET_MODEM_STATUS
1221 * wValue: zero 1221 * wValue: zero
1222 * wIndex: Port 1222 * wIndex: Port
1223 * wLength: 1 1223 * wLength: 1
1224 * Data: Status 1224 * Data: Status
1225 * 1225 *
1226 * One byte of data is returned 1226 * One byte of data is returned
1227 * B0..3 0 1227 * B0..3 0
1228 * B4 CTS 1228 * B4 CTS
1229 * 0 = inactive 1229 * 0 = inactive
@@ -1236,15 +1236,15 @@ typedef enum {
1236 * 1 = active 1236 * 1 = active
1237 * B7 Receive Line Signal Detect (RLSD) 1237 * B7 Receive Line Signal Detect (RLSD)
1238 * 0 = inactive 1238 * 0 = inactive
1239 * 1 = active 1239 * 1 = active
1240 */ 1240 */
1241 1241
1242 1242
1243 1243
1244/* Descriptors returned by the device 1244/* Descriptors returned by the device
1245 * 1245 *
1246 * Device Descriptor 1246 * Device Descriptor
1247 * 1247 *
1248 * Offset Field Size Value Description 1248 * Offset Field Size Value Description
1249 * 0 bLength 1 0x12 Size of descriptor in bytes 1249 * 0 bLength 1 0x12 Size of descriptor in bytes
1250 * 1 bDescriptorType 1 0x01 DEVICE Descriptor Type 1250 * 1 bDescriptorType 1 0x01 DEVICE Descriptor Type
@@ -1260,9 +1260,9 @@ typedef enum {
1260 * 15 iProduct 1 0x02 Index of prod string desc 1260 * 15 iProduct 1 0x02 Index of prod string desc
1261 * 16 iSerialNumber 1 0x02 Index of serial nmr string desc 1261 * 16 iSerialNumber 1 0x02 Index of serial nmr string desc
1262 * 17 bNumConfigurations 1 0x01 Number of possible configurations 1262 * 17 bNumConfigurations 1 0x01 Number of possible configurations
1263 * 1263 *
1264 * Configuration Descriptor 1264 * Configuration Descriptor
1265 * 1265 *
1266 * Offset Field Size Value 1266 * Offset Field Size Value
1267 * 0 bLength 1 0x09 Size of descriptor in bytes 1267 * 0 bLength 1 0x09 Size of descriptor in bytes
1268 * 1 bDescriptorType 1 0x02 CONFIGURATION Descriptor Type 1268 * 1 bDescriptorType 1 0x02 CONFIGURATION Descriptor Type
@@ -1272,9 +1272,9 @@ typedef enum {
1272 * 6 iConfiguration 1 0x02 Index of config string descriptor 1272 * 6 iConfiguration 1 0x02 Index of config string descriptor
1273 * 7 bmAttributes 1 0x20 Config characteristics Remote Wakeup 1273 * 7 bmAttributes 1 0x20 Config characteristics Remote Wakeup
1274 * 8 MaxPower 1 0x1E Max power consumption 1274 * 8 MaxPower 1 0x1E Max power consumption
1275 * 1275 *
1276 * Interface Descriptor 1276 * Interface Descriptor
1277 * 1277 *
1278 * Offset Field Size Value 1278 * Offset Field Size Value
1279 * 0 bLength 1 0x09 Size of descriptor in bytes 1279 * 0 bLength 1 0x09 Size of descriptor in bytes
1280 * 1 bDescriptorType 1 0x04 INTERFACE Descriptor Type 1280 * 1 bDescriptorType 1 0x04 INTERFACE Descriptor Type
@@ -1285,9 +1285,9 @@ typedef enum {
1285 * 6 bInterfaceSubClass 1 0xFF Subclass Code 1285 * 6 bInterfaceSubClass 1 0xFF Subclass Code
1286 * 7 bInterfaceProtocol 1 0xFF Protocol Code 1286 * 7 bInterfaceProtocol 1 0xFF Protocol Code
1287 * 8 iInterface 1 0x02 Index of interface string description 1287 * 8 iInterface 1 0x02 Index of interface string description
1288 * 1288 *
1289 * IN Endpoint Descriptor 1289 * IN Endpoint Descriptor
1290 * 1290 *
1291 * Offset Field Size Value 1291 * Offset Field Size Value
1292 * 0 bLength 1 0x07 Size of descriptor in bytes 1292 * 0 bLength 1 0x07 Size of descriptor in bytes
1293 * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type 1293 * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type
@@ -1295,9 +1295,9 @@ typedef enum {
1295 * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk 1295 * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk
1296 * 4 bNumEndpoints 2 0x0040 maximum packet size 1296 * 4 bNumEndpoints 2 0x0040 maximum packet size
1297 * 5 bInterval 1 0x00 Interval for polling endpoint 1297 * 5 bInterval 1 0x00 Interval for polling endpoint
1298 * 1298 *
1299 * OUT Endpoint Descriptor 1299 * OUT Endpoint Descriptor
1300 * 1300 *
1301 * Offset Field Size Value 1301 * Offset Field Size Value
1302 * 0 bLength 1 0x07 Size of descriptor in bytes 1302 * 0 bLength 1 0x07 Size of descriptor in bytes
1303 * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type 1303 * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type
@@ -1305,17 +1305,17 @@ typedef enum {
1305 * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk 1305 * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk
1306 * 4 bNumEndpoints 2 0x0040 maximum packet size 1306 * 4 bNumEndpoints 2 0x0040 maximum packet size
1307 * 5 bInterval 1 0x00 Interval for polling endpoint 1307 * 5 bInterval 1 0x00 Interval for polling endpoint
1308 * 1308 *
1309 * DATA FORMAT 1309 * DATA FORMAT
1310 * 1310 *
1311 * IN Endpoint 1311 * IN Endpoint
1312 * 1312 *
1313 * The device reserves the first two bytes of data on this endpoint to contain the current 1313 * The device reserves the first two bytes of data on this endpoint to contain the current
1314 * values of the modem and line status registers. In the absence of data, the device 1314 * values of the modem and line status registers. In the absence of data, the device
1315 * generates a message consisting of these two status bytes every 40 ms 1315 * generates a message consisting of these two status bytes every 40 ms
1316 * 1316 *
1317 * Byte 0: Modem Status 1317 * Byte 0: Modem Status
1318 * 1318 *
1319 * Offset Description 1319 * Offset Description
1320 * B0 Reserved - must be 1 1320 * B0 Reserved - must be 1
1321 * B1 Reserved - must be 0 1321 * B1 Reserved - must be 0
@@ -1325,9 +1325,9 @@ typedef enum {
1325 * B5 Data Set Ready (DSR) 1325 * B5 Data Set Ready (DSR)
1326 * B6 Ring Indicator (RI) 1326 * B6 Ring Indicator (RI)
1327 * B7 Receive Line Signal Detect (RLSD) 1327 * B7 Receive Line Signal Detect (RLSD)
1328 * 1328 *
1329 * Byte 1: Line Status 1329 * Byte 1: Line Status
1330 * 1330 *
1331 * Offset Description 1331 * Offset Description
1332 * B0 Data Ready (DR) 1332 * B0 Data Ready (DR)
1333 * B1 Overrun Error (OE) 1333 * B1 Overrun Error (OE)
@@ -1337,7 +1337,7 @@ typedef enum {
1337 * B5 Transmitter Holding Register (THRE) 1337 * B5 Transmitter Holding Register (THRE)
1338 * B6 Transmitter Empty (TEMT) 1338 * B6 Transmitter Empty (TEMT)
1339 * B7 Error in RCVR FIFO 1339 * B7 Error in RCVR FIFO
1340 * 1340 *
1341 */ 1341 */
1342#define FTDI_RS0_CTS (1 << 4) 1342#define FTDI_RS0_CTS (1 << 4)
1343#define FTDI_RS0_DSR (1 << 5) 1343#define FTDI_RS0_DSR (1 << 5)
@@ -1355,17 +1355,17 @@ typedef enum {
1355 1355
1356/* 1356/*
1357 * OUT Endpoint 1357 * OUT Endpoint
1358 * 1358 *
1359 * This device reserves the first bytes of data on this endpoint contain the length 1359 * This device reserves the first bytes of data on this endpoint contain the length
1360 * and port identifier of the message. For the FTDI USB Serial converter the port 1360 * and port identifier of the message. For the FTDI USB Serial converter the port
1361 * identifier is always 1. 1361 * identifier is always 1.
1362 * 1362 *
1363 * Byte 0: Line Status 1363 * Byte 0: Line Status
1364 * 1364 *
1365 * Offset Description 1365 * Offset Description
1366 * B0 Reserved - must be 1 1366 * B0 Reserved - must be 1
1367 * B1 Reserved - must be 0 1367 * B1 Reserved - must be 0
1368 * B2..7 Length of message - (not including Byte 0) 1368 * B2..7 Length of message - (not including Byte 0)
1369 * 1369 *
1370 */ 1370 */
1371 1371
diff --git a/drivers/usb/serial/funsoft.c b/drivers/usb/serial/funsoft.c
index e8ba2cb5995d..d30f736d2cc5 100644
--- a/drivers/usb/serial/funsoft.c
+++ b/drivers/usb/serial/funsoft.c
@@ -14,7 +14,7 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/usb/serial.h> 16#include <linux/usb/serial.h>
17#include <asm/uaccess.h> 17#include <linux/uaccess.h>
18 18
19static int debug; 19static int debug;
20 20
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 8ce5a56a48e3..2e663f1afd5e 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -33,7 +33,7 @@
33#include <linux/tty_flip.h> 33#include <linux/tty_flip.h>
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <asm/uaccess.h> 36#include <linux/uaccess.h>
37#include <asm/atomic.h> 37#include <asm/atomic.h>
38#include <linux/usb.h> 38#include <linux/usb.h>
39#include <linux/usb/serial.h> 39#include <linux/usb/serial.h>
@@ -44,7 +44,7 @@
44static int initial_mode = 1; 44static int initial_mode = 1;
45 45
46/* debug flag */ 46/* debug flag */
47static int debug = 0; 47static int debug;
48 48
49#define GARMIN_VENDOR_ID 0x091E 49#define GARMIN_VENDOR_ID 0x091E
50 50
@@ -56,7 +56,7 @@ static int debug = 0;
56#define VERSION_MINOR 31 56#define VERSION_MINOR 31
57 57
58#define _STR(s) #s 58#define _STR(s) #s
59#define _DRIVER_VERSION(a,b) "v" _STR(a) "." _STR(b) 59#define _DRIVER_VERSION(a, b) "v" _STR(a) "." _STR(b)
60#define DRIVER_VERSION _DRIVER_VERSION(VERSION_MAJOR, VERSION_MINOR) 60#define DRIVER_VERSION _DRIVER_VERSION(VERSION_MAJOR, VERSION_MINOR)
61#define DRIVER_AUTHOR "hermann kneissel" 61#define DRIVER_AUTHOR "hermann kneissel"
62#define DRIVER_DESC "garmin gps driver" 62#define DRIVER_DESC "garmin gps driver"
@@ -65,37 +65,37 @@ static int debug = 0;
65#define EINVPKT 1000 /* invalid packet structure */ 65#define EINVPKT 1000 /* invalid packet structure */
66 66
67 67
68// size of the header of a packet using the usb protocol 68/* size of the header of a packet using the usb protocol */
69#define GARMIN_PKTHDR_LENGTH 12 69#define GARMIN_PKTHDR_LENGTH 12
70 70
71// max. possible size of a packet using the serial protocol 71/* max. possible size of a packet using the serial protocol */
72#define MAX_SERIAL_PKT_SIZ (3+255+3) 72#define MAX_SERIAL_PKT_SIZ (3 + 255 + 3)
73 73
74// max. possible size of a packet with worst case stuffing 74/* max. possible size of a packet with worst case stuffing */
75#define MAX_SERIAL_PKT_SIZ_STUFFED MAX_SERIAL_PKT_SIZ+256 75#define MAX_SERIAL_PKT_SIZ_STUFFED (MAX_SERIAL_PKT_SIZ + 256)
76 76
77// size of a buffer able to hold a complete (no stuffing) packet 77/* size of a buffer able to hold a complete (no stuffing) packet
78// (the document protocol does not contain packets with a larger 78 * (the document protocol does not contain packets with a larger
79// size, but in theory a packet may be 64k+12 bytes - if in 79 * size, but in theory a packet may be 64k+12 bytes - if in
80// later protocol versions larger packet sizes occur, this value 80 * later protocol versions larger packet sizes occur, this value
81// should be increased accordingly, so the input buffer is always 81 * should be increased accordingly, so the input buffer is always
82// large enough the store a complete packet inclusive header) 82 * large enough the store a complete packet inclusive header) */
83#define GPS_IN_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ) 83#define GPS_IN_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ)
84 84
85// size of a buffer able to hold a complete (incl. stuffing) packet 85/* size of a buffer able to hold a complete (incl. stuffing) packet */
86#define GPS_OUT_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ_STUFFED) 86#define GPS_OUT_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ_STUFFED)
87 87
88// where to place the packet id of a serial packet, so we can 88/* where to place the packet id of a serial packet, so we can
89// prepend the usb-packet header without the need to move the 89 * prepend the usb-packet header without the need to move the
90// packets data 90 * packets data */
91#define GSP_INITIAL_OFFSET (GARMIN_PKTHDR_LENGTH-2) 91#define GSP_INITIAL_OFFSET (GARMIN_PKTHDR_LENGTH-2)
92 92
93// max. size of incoming private packets (header+1 param) 93/* max. size of incoming private packets (header+1 param) */
94#define PRIVPKTSIZ (GARMIN_PKTHDR_LENGTH+4) 94#define PRIVPKTSIZ (GARMIN_PKTHDR_LENGTH+4)
95 95
96#define GARMIN_LAYERID_TRANSPORT 0 96#define GARMIN_LAYERID_TRANSPORT 0
97#define GARMIN_LAYERID_APPL 20 97#define GARMIN_LAYERID_APPL 20
98// our own layer-id to use for some control mechanisms 98/* our own layer-id to use for some control mechanisms */
99#define GARMIN_LAYERID_PRIVATE 0x01106E4B 99#define GARMIN_LAYERID_PRIVATE 0x01106E4B
100 100
101#define GARMIN_PKTID_PVT_DATA 51 101#define GARMIN_PKTID_PVT_DATA 51
@@ -103,7 +103,7 @@ static int debug = 0;
103 103
104#define CMND_ABORT_TRANSFER 0 104#define CMND_ABORT_TRANSFER 0
105 105
106// packet ids used in private layer 106/* packet ids used in private layer */
107#define PRIV_PKTID_SET_DEBUG 1 107#define PRIV_PKTID_SET_DEBUG 1
108#define PRIV_PKTID_SET_MODE 2 108#define PRIV_PKTID_SET_MODE 2
109#define PRIV_PKTID_INFO_REQ 3 109#define PRIV_PKTID_INFO_REQ 3
@@ -121,7 +121,8 @@ static int debug = 0;
121struct garmin_packet { 121struct garmin_packet {
122 struct list_head list; 122 struct list_head list;
123 int seq; 123 int seq;
124 int size; // the real size of the data array, always > 0 124 /* the real size of the data array, always > 0 */
125 int size;
125 __u8 data[1]; 126 __u8 data[1];
126}; 127};
127 128
@@ -164,7 +165,7 @@ struct garmin_data {
164#define MODE_NATIVE 0 165#define MODE_NATIVE 0
165#define MODE_GARMIN_SERIAL 1 166#define MODE_GARMIN_SERIAL 1
166 167
167// Flags used in garmin_data.flags: 168/* Flags used in garmin_data.flags: */
168#define FLAGS_SESSION_REPLY_MASK 0x00C0 169#define FLAGS_SESSION_REPLY_MASK 0x00C0
169#define FLAGS_SESSION_REPLY1_SEEN 0x0080 170#define FLAGS_SESSION_REPLY1_SEEN 0x0080
170#define FLAGS_SESSION_REPLY2_SEEN 0x0040 171#define FLAGS_SESSION_REPLY2_SEEN 0x0040
@@ -185,7 +186,7 @@ struct garmin_data {
185 186
186 187
187/* function prototypes */ 188/* function prototypes */
188static void gsp_next_packet(struct garmin_data * garmin_data_p); 189static void gsp_next_packet(struct garmin_data *garmin_data_p);
189static int garmin_write_bulk(struct usb_serial_port *port, 190static int garmin_write_bulk(struct usb_serial_port *port,
190 const unsigned char *buf, int count, 191 const unsigned char *buf, int count,
191 int dismiss_ack); 192 int dismiss_ack);
@@ -217,12 +218,13 @@ static unsigned char const PRIVATE_REQ[]
217 218
218 219
219static struct usb_device_id id_table [] = { 220static struct usb_device_id id_table [] = {
220 /* the same device id seems to be used by all usb enabled gps devices */ 221 /* the same device id seems to be used by all
221 { USB_DEVICE(GARMIN_VENDOR_ID, 3 ) }, 222 usb enabled GPS devices */
223 { USB_DEVICE(GARMIN_VENDOR_ID, 3) },
222 { } /* Terminating entry */ 224 { } /* Terminating entry */
223}; 225};
224 226
225MODULE_DEVICE_TABLE (usb, id_table); 227MODULE_DEVICE_TABLE(usb, id_table);
226 228
227static struct usb_driver garmin_driver = { 229static struct usb_driver garmin_driver = {
228 .name = "garmin_gps", 230 .name = "garmin_gps",
@@ -233,9 +235,10 @@ static struct usb_driver garmin_driver = {
233}; 235};
234 236
235 237
236static inline int noResponseFromAppLayer(struct garmin_data * garmin_data_p) 238static inline int noResponseFromAppLayer(struct garmin_data *garmin_data_p)
237{ 239{
238 return atomic_read(&garmin_data_p->req_count) == atomic_read(&garmin_data_p->resp_count); 240 return atomic_read(&garmin_data_p->req_count) ==
241 atomic_read(&garmin_data_p->resp_count);
239} 242}
240 243
241 244
@@ -261,10 +264,10 @@ static inline int getDataLength(const __u8 *usbPacket)
261 */ 264 */
262static inline int isAbortTrfCmnd(const unsigned char *buf) 265static inline int isAbortTrfCmnd(const unsigned char *buf)
263{ 266{
264 if (0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ, 267 if (0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ,
265 sizeof(GARMIN_STOP_TRANSFER_REQ)) || 268 sizeof(GARMIN_STOP_TRANSFER_REQ)) ||
266 0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2, 269 0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2,
267 sizeof(GARMIN_STOP_TRANSFER_REQ_V2))) 270 sizeof(GARMIN_STOP_TRANSFER_REQ_V2)))
268 return 1; 271 return 1;
269 else 272 else
270 return 0; 273 return 0;
@@ -275,11 +278,11 @@ static inline int isAbortTrfCmnd(const unsigned char *buf)
275static void send_to_tty(struct usb_serial_port *port, 278static void send_to_tty(struct usb_serial_port *port,
276 char *data, unsigned int actual_length) 279 char *data, unsigned int actual_length)
277{ 280{
278 struct tty_struct *tty = port->tty; 281 struct tty_struct *tty = port->port.tty;
279 282
280 if (tty && actual_length) { 283 if (tty && actual_length) {
281 284
282 usb_serial_debug_data(debug, &port->dev, 285 usb_serial_debug_data(debug, &port->dev,
283 __func__, actual_length, data); 286 __func__, actual_length, data);
284 287
285 tty_buffer_request_room(tty, actual_length); 288 tty_buffer_request_room(tty, actual_length);
@@ -296,7 +299,7 @@ static void send_to_tty(struct usb_serial_port *port,
296/* 299/*
297 * queue a received (usb-)packet for later processing 300 * queue a received (usb-)packet for later processing
298 */ 301 */
299static int pkt_add(struct garmin_data * garmin_data_p, 302static int pkt_add(struct garmin_data *garmin_data_p,
300 unsigned char *data, unsigned int data_length) 303 unsigned char *data, unsigned int data_length)
301{ 304{
302 int state = 0; 305 int state = 0;
@@ -307,7 +310,7 @@ static int pkt_add(struct garmin_data * garmin_data_p,
307 /* process only packets containg data ... */ 310 /* process only packets containg data ... */
308 if (data_length) { 311 if (data_length) {
309 pkt = kmalloc(sizeof(struct garmin_packet)+data_length, 312 pkt = kmalloc(sizeof(struct garmin_packet)+data_length,
310 GFP_ATOMIC); 313 GFP_ATOMIC);
311 if (pkt == NULL) { 314 if (pkt == NULL) {
312 dev_err(&garmin_data_p->port->dev, "out of memory\n"); 315 dev_err(&garmin_data_p->port->dev, "out of memory\n");
313 return 0; 316 return 0;
@@ -325,16 +328,15 @@ static int pkt_add(struct garmin_data * garmin_data_p,
325 328
326 /* in serial mode, if someone is waiting for data from 329 /* in serial mode, if someone is waiting for data from
327 the device, iconvert and send the next packet to tty. */ 330 the device, iconvert and send the next packet to tty. */
328 if (result && (state == STATE_GSP_WAIT_DATA)) { 331 if (result && (state == STATE_GSP_WAIT_DATA))
329 gsp_next_packet(garmin_data_p); 332 gsp_next_packet(garmin_data_p);
330 }
331 } 333 }
332 return result; 334 return result;
333} 335}
334 336
335 337
336/* get the next pending packet */ 338/* get the next pending packet */
337static struct garmin_packet *pkt_pop(struct garmin_data * garmin_data_p) 339static struct garmin_packet *pkt_pop(struct garmin_data *garmin_data_p)
338{ 340{
339 unsigned long flags; 341 unsigned long flags;
340 struct garmin_packet *result = NULL; 342 struct garmin_packet *result = NULL;
@@ -350,7 +352,7 @@ static struct garmin_packet *pkt_pop(struct garmin_data * garmin_data_p)
350 352
351 353
352/* free up all queued data */ 354/* free up all queued data */
353static void pkt_clear(struct garmin_data * garmin_data_p) 355static void pkt_clear(struct garmin_data *garmin_data_p)
354{ 356{
355 unsigned long flags; 357 unsigned long flags;
356 struct garmin_packet *result = NULL; 358 struct garmin_packet *result = NULL;
@@ -372,7 +374,7 @@ static void pkt_clear(struct garmin_data * garmin_data_p)
372 ******************************************************************************/ 374 ******************************************************************************/
373 375
374/* send an ack packet back to the tty */ 376/* send an ack packet back to the tty */
375static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id) 377static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id)
376{ 378{
377 __u8 pkt[10]; 379 __u8 pkt[10];
378 __u8 cksum = 0; 380 __u8 cksum = 0;
@@ -391,9 +393,8 @@ static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id)
391 *ptr++ = pkt_id; 393 *ptr++ = pkt_id;
392 cksum += pkt_id; 394 cksum += pkt_id;
393 395
394 if (pkt_id == DLE) { 396 if (pkt_id == DLE)
395 *ptr++ = DLE; 397 *ptr++ = DLE;
396 }
397 398
398 *ptr++ = 0; 399 *ptr++ = 0;
399 *ptr++ = 0xFF & (-cksum); 400 *ptr++ = 0xFF & (-cksum);
@@ -415,12 +416,12 @@ static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id)
415 * at GSP_INITIAL_OFFSET. 416 * at GSP_INITIAL_OFFSET.
416 * 417 *
417 * count - number of bytes in the input buffer including space reserved for 418 * count - number of bytes in the input buffer including space reserved for
418 * the usb header: GSP_INITIAL_OFFSET + number of bytes in packet 419 * the usb header: GSP_INITIAL_OFFSET + number of bytes in packet
419 * (including pkt-id, data-length a. cksum) 420 * (including pkt-id, data-length a. cksum)
420 */ 421 */
421static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) 422static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count)
422{ 423{
423 const __u8* recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; 424 const __u8 *recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET;
424 __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; 425 __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer;
425 426
426 int cksum = 0; 427 int cksum = 0;
@@ -440,8 +441,8 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
440 cksum += *recpkt++; 441 cksum += *recpkt++;
441 cksum += *recpkt++; 442 cksum += *recpkt++;
442 443
443 // sanity check, remove after test ... 444 /* sanity check, remove after test ... */
444 if ((__u8*)&(usbdata[3]) != recpkt) { 445 if ((__u8 *)&(usbdata[3]) != recpkt) {
445 dbg("%s - ptr mismatch %p - %p", 446 dbg("%s - ptr mismatch %p - %p",
446 __func__, &(usbdata[4]), recpkt); 447 __func__, &(usbdata[4]), recpkt);
447 return -EINVPKT; 448 return -EINVPKT;
@@ -462,7 +463,7 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
462 usbdata[1] = __cpu_to_le32(pktid); 463 usbdata[1] = __cpu_to_le32(pktid);
463 usbdata[2] = __cpu_to_le32(size); 464 usbdata[2] = __cpu_to_le32(size);
464 465
465 garmin_write_bulk (garmin_data_p->port, garmin_data_p->inbuffer, 466 garmin_write_bulk(garmin_data_p->port, garmin_data_p->inbuffer,
466 GARMIN_PKTHDR_LENGTH+size, 0); 467 GARMIN_PKTHDR_LENGTH+size, 0);
467 468
468 /* if this was an abort-transfer command, flush all 469 /* if this was an abort-transfer command, flush all
@@ -495,7 +496,7 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
495 * if the input is an abort command, drop all queued data. 496 * if the input is an abort command, drop all queued data.
496 */ 497 */
497 498
498static int gsp_receive(struct garmin_data * garmin_data_p, 499static int gsp_receive(struct garmin_data *garmin_data_p,
499 const unsigned char *buf, int count) 500 const unsigned char *buf, int count)
500{ 501{
501 unsigned long flags; 502 unsigned long flags;
@@ -504,10 +505,11 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
504 int i = 0; 505 int i = 0;
505 __u8 *dest; 506 __u8 *dest;
506 int size; 507 int size;
507 // dleSeen: set if last byte read was a DLE 508 /* dleSeen: set if last byte read was a DLE */
508 int dleSeen; 509 int dleSeen;
509 // skip: if set, skip incoming data until possible start of 510 /* skip: if set, skip incoming data until possible start of
510 // new packet 511 * new packet
512 */
511 int skip; 513 int skip;
512 __u8 data; 514 __u8 data;
513 515
@@ -521,14 +523,13 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
521 dbg("%s - dle=%d skip=%d size=%d count=%d", 523 dbg("%s - dle=%d skip=%d size=%d count=%d",
522 __func__, dleSeen, skip, size, count); 524 __func__, dleSeen, skip, size, count);
523 525
524 if (size == 0) { 526 if (size == 0)
525 size = GSP_INITIAL_OFFSET; 527 size = GSP_INITIAL_OFFSET;
526 }
527 528
528 while (offs < count) { 529 while (offs < count) {
529 530
530 data = *(buf+offs); 531 data = *(buf+offs);
531 offs ++; 532 offs++;
532 533
533 if (data == DLE) { 534 if (data == DLE) {
534 if (skip) { /* start of a new pkt */ 535 if (skip) { /* start of a new pkt */
@@ -554,9 +555,8 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
554 ack_or_nak_seen = NAK; 555 ack_or_nak_seen = NAK;
555 dbg("NAK packet complete."); 556 dbg("NAK packet complete.");
556 } else { 557 } else {
557 dbg("packet complete " 558 dbg("packet complete - id=0x%X.",
558 "- id=0x%X.", 559 0xFF & data);
559 0xFF & data);
560 gsp_rec_packet(garmin_data_p, size); 560 gsp_rec_packet(garmin_data_p, size);
561 } 561 }
562 562
@@ -589,7 +589,7 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
589 589
590 garmin_data_p->insize = size; 590 garmin_data_p->insize = size;
591 591
592 // copy flags back to structure 592 /* copy flags back to structure */
593 if (skip) 593 if (skip)
594 garmin_data_p->flags |= FLAGS_GSP_SKIP; 594 garmin_data_p->flags |= FLAGS_GSP_SKIP;
595 else 595 else
@@ -600,16 +600,13 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
600 else 600 else
601 garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN; 601 garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN;
602 602
603 if (ack_or_nak_seen) { 603 if (ack_or_nak_seen)
604 garmin_data_p->state = STATE_GSP_WAIT_DATA; 604 garmin_data_p->state = STATE_GSP_WAIT_DATA;
605 }
606 605
607 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 606 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
608 607
609 if (ack_or_nak_seen) { 608 if (ack_or_nak_seen)
610 gsp_next_packet(garmin_data_p); 609 gsp_next_packet(garmin_data_p);
611 }
612
613 return count; 610 return count;
614} 611}
615 612
@@ -623,7 +620,7 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
623 * 620 *
624 * return <0 on error, 0 if packet is incomplete or > 0 if packet was sent 621 * return <0 on error, 0 if packet is incomplete or > 0 if packet was sent
625 */ 622 */
626static int gsp_send(struct garmin_data * garmin_data_p, 623static int gsp_send(struct garmin_data *garmin_data_p,
627 const unsigned char *buf, int count) 624 const unsigned char *buf, int count)
628{ 625{
629 const unsigned char *src; 626 const unsigned char *src;
@@ -631,11 +628,11 @@ static int gsp_send(struct garmin_data * garmin_data_p,
631 int pktid = 0; 628 int pktid = 0;
632 int datalen = 0; 629 int datalen = 0;
633 int cksum = 0; 630 int cksum = 0;
634 int i=0; 631 int i = 0;
635 int k; 632 int k;
636 633
637 dbg("%s - state %d - %d bytes.", __func__, 634 dbg("%s - state %d - %d bytes.", __func__,
638 garmin_data_p->state, count); 635 garmin_data_p->state, count);
639 636
640 k = garmin_data_p->outsize; 637 k = garmin_data_p->outsize;
641 if ((k+count) > GPS_OUT_BUFSIZ) { 638 if ((k+count) > GPS_OUT_BUFSIZ) {
@@ -650,7 +647,7 @@ static int gsp_send(struct garmin_data * garmin_data_p,
650 647
651 if (k >= GARMIN_PKTHDR_LENGTH) { 648 if (k >= GARMIN_PKTHDR_LENGTH) {
652 pktid = getPacketId(garmin_data_p->outbuffer); 649 pktid = getPacketId(garmin_data_p->outbuffer);
653 datalen= getDataLength(garmin_data_p->outbuffer); 650 datalen = getDataLength(garmin_data_p->outbuffer);
654 i = GARMIN_PKTHDR_LENGTH + datalen; 651 i = GARMIN_PKTHDR_LENGTH + datalen;
655 if (k < i) 652 if (k < i)
656 return 0; 653 return 0;
@@ -658,19 +655,18 @@ static int gsp_send(struct garmin_data * garmin_data_p,
658 return 0; 655 return 0;
659 } 656 }
660 657
661 dbg("%s - %d bytes in buffer, %d bytes in pkt.", __func__, 658 dbg("%s - %d bytes in buffer, %d bytes in pkt.", __func__, k, i);
662 k, i);
663 659
664 /* garmin_data_p->outbuffer now contains a complete packet */ 660 /* garmin_data_p->outbuffer now contains a complete packet */
665 661
666 usb_serial_debug_data(debug, &garmin_data_p->port->dev, 662 usb_serial_debug_data(debug, &garmin_data_p->port->dev,
667 __func__, k, garmin_data_p->outbuffer); 663 __func__, k, garmin_data_p->outbuffer);
668 664
669 garmin_data_p->outsize = 0; 665 garmin_data_p->outsize = 0;
670 666
671 if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) { 667 if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) {
672 dbg("not an application packet (%d)", 668 dbg("not an application packet (%d)",
673 getLayerId(garmin_data_p->outbuffer)); 669 getLayerId(garmin_data_p->outbuffer));
674 return -1; 670 return -1;
675 } 671 }
676 672
@@ -688,14 +684,14 @@ static int gsp_send(struct garmin_data * garmin_data_p,
688 684
689 k = 0; 685 k = 0;
690 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; 686 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH;
691 for (i=0; i<datalen; i++) { 687 for (i = 0; i < datalen; i++) {
692 if (*src++ == DLE) 688 if (*src++ == DLE)
693 k++; 689 k++;
694 } 690 }
695 691
696 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; 692 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH;
697 if (k > (GARMIN_PKTHDR_LENGTH-2)) { 693 if (k > (GARMIN_PKTHDR_LENGTH-2)) {
698 /* can't add stuffing DLEs in place, move data to end 694 /* can't add stuffing DLEs in place, move data to end
699 of buffer ... */ 695 of buffer ... */
700 dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen; 696 dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen;
701 memcpy(dst, src, datalen); 697 memcpy(dst, src, datalen);
@@ -712,14 +708,14 @@ static int gsp_send(struct garmin_data * garmin_data_p,
712 if (datalen == DLE) 708 if (datalen == DLE)
713 *dst++ = DLE; 709 *dst++ = DLE;
714 710
715 for (i=0; i<datalen; i++) { 711 for (i = 0; i < datalen; i++) {
716 __u8 c = *src++; 712 __u8 c = *src++;
717 *dst++ = c; 713 *dst++ = c;
718 cksum += c; 714 cksum += c;
719 if (c == DLE) 715 if (c == DLE)
720 *dst++ = DLE; 716 *dst++ = DLE;
721 } 717 }
722 718
723 cksum = 0xFF & -cksum; 719 cksum = 0xFF & -cksum;
724 *dst++ = cksum; 720 *dst++ = cksum;
725 if (cksum == DLE) 721 if (cksum == DLE)
@@ -744,7 +740,7 @@ static int gsp_send(struct garmin_data * garmin_data_p,
744/* 740/*
745 * Process the next pending data packet - if there is one 741 * Process the next pending data packet - if there is one
746 */ 742 */
747static void gsp_next_packet(struct garmin_data * garmin_data_p) 743static void gsp_next_packet(struct garmin_data *garmin_data_p)
748{ 744{
749 struct garmin_packet *pkt = NULL; 745 struct garmin_packet *pkt = NULL;
750 746
@@ -774,17 +770,17 @@ static void gsp_next_packet(struct garmin_data * garmin_data_p)
774 * buf contains the data read, it may span more than one packet 770 * buf contains the data read, it may span more than one packet
775 * or even incomplete packets 771 * or even incomplete packets
776 */ 772 */
777static int nat_receive(struct garmin_data * garmin_data_p, 773static int nat_receive(struct garmin_data *garmin_data_p,
778 const unsigned char *buf, int count) 774 const unsigned char *buf, int count)
779{ 775{
780 unsigned long flags; 776 unsigned long flags;
781 __u8 * dest; 777 __u8 *dest;
782 int offs = 0; 778 int offs = 0;
783 int result = count; 779 int result = count;
784 int len; 780 int len;
785 781
786 while (offs < count) { 782 while (offs < count) {
787 // if buffer contains header, copy rest of data 783 /* if buffer contains header, copy rest of data */
788 if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) 784 if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH)
789 len = GARMIN_PKTHDR_LENGTH 785 len = GARMIN_PKTHDR_LENGTH
790 +getDataLength(garmin_data_p->inbuffer); 786 +getDataLength(garmin_data_p->inbuffer);
@@ -792,9 +788,9 @@ static int nat_receive(struct garmin_data * garmin_data_p,
792 len = GARMIN_PKTHDR_LENGTH; 788 len = GARMIN_PKTHDR_LENGTH;
793 789
794 if (len >= GPS_IN_BUFSIZ) { 790 if (len >= GPS_IN_BUFSIZ) {
795 /* seem to be an invalid packet, ignore rest of input */ 791 /* seems to be an invalid packet, ignore rest
796 dbg("%s - packet size too large: %d", 792 of input */
797 __func__, len); 793 dbg("%s - packet size too large: %d", __func__, len);
798 garmin_data_p->insize = 0; 794 garmin_data_p->insize = 0;
799 count = 0; 795 count = 0;
800 result = -EINVPKT; 796 result = -EINVPKT;
@@ -804,7 +800,7 @@ static int nat_receive(struct garmin_data * garmin_data_p,
804 len = (count-offs); 800 len = (count-offs);
805 if (len > 0) { 801 if (len > 0) {
806 dest = garmin_data_p->inbuffer 802 dest = garmin_data_p->inbuffer
807 +garmin_data_p->insize; 803 + garmin_data_p->insize;
808 memcpy(dest, buf+offs, len); 804 memcpy(dest, buf+offs, len);
809 garmin_data_p->insize += len; 805 garmin_data_p->insize += len;
810 offs += len; 806 offs += len;
@@ -816,17 +812,19 @@ static int nat_receive(struct garmin_data * garmin_data_p,
816 len = GARMIN_PKTHDR_LENGTH+ 812 len = GARMIN_PKTHDR_LENGTH+
817 getDataLength(garmin_data_p->inbuffer); 813 getDataLength(garmin_data_p->inbuffer);
818 if (garmin_data_p->insize >= len) { 814 if (garmin_data_p->insize >= len) {
819 garmin_write_bulk (garmin_data_p->port, 815 garmin_write_bulk(garmin_data_p->port,
820 garmin_data_p->inbuffer, 816 garmin_data_p->inbuffer,
821 len, 0); 817 len, 0);
822 garmin_data_p->insize = 0; 818 garmin_data_p->insize = 0;
823 819
824 /* if this was an abort-transfer command, 820 /* if this was an abort-transfer command,
825 flush all queued data. */ 821 flush all queued data. */
826 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { 822 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) {
827 spin_lock_irqsave(&garmin_data_p->lock, flags); 823 spin_lock_irqsave(&garmin_data_p->lock,
824 flags);
828 garmin_data_p->flags |= FLAGS_DROP_DATA; 825 garmin_data_p->flags |= FLAGS_DROP_DATA;
829 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 826 spin_unlock_irqrestore(
827 &garmin_data_p->lock, flags);
830 pkt_clear(garmin_data_p); 828 pkt_clear(garmin_data_p);
831 } 829 }
832 } 830 }
@@ -842,7 +840,7 @@ static int nat_receive(struct garmin_data * garmin_data_p,
842 840
843static void priv_status_resp(struct usb_serial_port *port) 841static void priv_status_resp(struct usb_serial_port *port)
844{ 842{
845 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 843 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
846 __le32 *pkt = (__le32 *)garmin_data_p->privpkt; 844 __le32 *pkt = (__le32 *)garmin_data_p->privpkt;
847 845
848 pkt[0] = __cpu_to_le32(GARMIN_LAYERID_PRIVATE); 846 pkt[0] = __cpu_to_le32(GARMIN_LAYERID_PRIVATE);
@@ -852,7 +850,7 @@ static void priv_status_resp(struct usb_serial_port *port)
852 pkt[4] = __cpu_to_le32(garmin_data_p->mode); 850 pkt[4] = __cpu_to_le32(garmin_data_p->mode);
853 pkt[5] = __cpu_to_le32(garmin_data_p->serial_num); 851 pkt[5] = __cpu_to_le32(garmin_data_p->serial_num);
854 852
855 send_to_tty(port, (__u8*)pkt, 6*4); 853 send_to_tty(port, (__u8 *)pkt, 6 * 4);
856} 854}
857 855
858 856
@@ -864,7 +862,7 @@ static int process_resetdev_request(struct usb_serial_port *port)
864{ 862{
865 unsigned long flags; 863 unsigned long flags;
866 int status; 864 int status;
867 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 865 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
868 866
869 spin_lock_irqsave(&garmin_data_p->lock, flags); 867 spin_lock_irqsave(&garmin_data_p->lock, flags);
870 garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED); 868 garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED);
@@ -872,8 +870,8 @@ static int process_resetdev_request(struct usb_serial_port *port)
872 garmin_data_p->serial_num = 0; 870 garmin_data_p->serial_num = 0;
873 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 871 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
874 872
875 usb_kill_urb (port->interrupt_in_urb); 873 usb_kill_urb(port->interrupt_in_urb);
876 dbg("%s - usb_reset_device", __func__ ); 874 dbg("%s - usb_reset_device", __func__);
877 status = usb_reset_device(port->serial->dev); 875 status = usb_reset_device(port->serial->dev);
878 if (status) 876 if (status)
879 dbg("%s - usb_reset_device failed: %d", 877 dbg("%s - usb_reset_device failed: %d",
@@ -886,7 +884,7 @@ static int process_resetdev_request(struct usb_serial_port *port)
886/* 884/*
887 * clear all cached data 885 * clear all cached data
888 */ 886 */
889static int garmin_clear(struct garmin_data * garmin_data_p) 887static int garmin_clear(struct garmin_data *garmin_data_p)
890{ 888{
891 unsigned long flags; 889 unsigned long flags;
892 int status = 0; 890 int status = 0;
@@ -896,8 +894,7 @@ static int garmin_clear(struct garmin_data * garmin_data_p)
896 if (port != NULL && atomic_read(&garmin_data_p->resp_count)) { 894 if (port != NULL && atomic_read(&garmin_data_p->resp_count)) {
897 /* send a terminate command */ 895 /* send a terminate command */
898 status = garmin_write_bulk(port, GARMIN_STOP_TRANSFER_REQ, 896 status = garmin_write_bulk(port, GARMIN_STOP_TRANSFER_REQ,
899 sizeof(GARMIN_STOP_TRANSFER_REQ), 897 sizeof(GARMIN_STOP_TRANSFER_REQ), 1);
900 1);
901 } 898 }
902 899
903 /* flush all queued data */ 900 /* flush all queued data */
@@ -920,28 +917,26 @@ static int garmin_init_session(struct usb_serial_port *port)
920{ 917{
921 unsigned long flags; 918 unsigned long flags;
922 struct usb_serial *serial = port->serial; 919 struct usb_serial *serial = port->serial;
923 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 920 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
924 int status = 0; 921 int status = 0;
925 922
926 if (status == 0) { 923 if (status == 0) {
927 usb_kill_urb (port->interrupt_in_urb); 924 usb_kill_urb(port->interrupt_in_urb);
928 925
929 dbg("%s - adding interrupt input", __func__); 926 dbg("%s - adding interrupt input", __func__);
930 port->interrupt_in_urb->dev = serial->dev; 927 port->interrupt_in_urb->dev = serial->dev;
931 status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 928 status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
932 if (status) 929 if (status)
933 dev_err(&serial->dev->dev, 930 dev_err(&serial->dev->dev,
934 "%s - failed submitting interrupt urb," 931 "%s - failed submitting interrupt urb, error %d\n",
935 " error %d\n", 932 __func__, status);
936 __func__, status);
937 } 933 }
938 934
939 if (status == 0) { 935 if (status == 0) {
940 dbg("%s - starting session ...", __func__); 936 dbg("%s - starting session ...", __func__);
941 garmin_data_p->state = STATE_ACTIVE; 937 garmin_data_p->state = STATE_ACTIVE;
942 status = garmin_write_bulk(port, GARMIN_START_SESSION_REQ, 938 status = garmin_write_bulk(port, GARMIN_START_SESSION_REQ,
943 sizeof(GARMIN_START_SESSION_REQ), 939 sizeof(GARMIN_START_SESSION_REQ), 0);
944 0);
945 940
946 if (status >= 0) { 941 if (status >= 0) {
947 942
@@ -951,14 +946,14 @@ static int garmin_init_session(struct usb_serial_port *port)
951 946
952 /* not needed, but the win32 driver does it too ... */ 947 /* not needed, but the win32 driver does it too ... */
953 status = garmin_write_bulk(port, 948 status = garmin_write_bulk(port,
954 GARMIN_START_SESSION_REQ2, 949 GARMIN_START_SESSION_REQ2,
955 sizeof(GARMIN_START_SESSION_REQ2), 950 sizeof(GARMIN_START_SESSION_REQ2), 0);
956 0);
957 if (status >= 0) { 951 if (status >= 0) {
958 status = 0; 952 status = 0;
959 spin_lock_irqsave(&garmin_data_p->lock, flags); 953 spin_lock_irqsave(&garmin_data_p->lock, flags);
960 garmin_data_p->ignorePkts++; 954 garmin_data_p->ignorePkts++;
961 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 955 spin_unlock_irqrestore(&garmin_data_p->lock,
956 flags);
962 } 957 }
963 } 958 }
964 } 959 }
@@ -970,11 +965,12 @@ static int garmin_init_session(struct usb_serial_port *port)
970 965
971 966
972 967
973static int garmin_open (struct usb_serial_port *port, struct file *filp) 968static int garmin_open(struct tty_struct *tty,
969 struct usb_serial_port *port, struct file *filp)
974{ 970{
975 unsigned long flags; 971 unsigned long flags;
976 int status = 0; 972 int status = 0;
977 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 973 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
978 974
979 dbg("%s - port %d", __func__, port->number); 975 dbg("%s - port %d", __func__, port->number);
980 976
@@ -983,8 +979,8 @@ static int garmin_open (struct usb_serial_port *port, struct file *filp)
983 * through, otherwise it is scheduled, and with high data rates (like 979 * through, otherwise it is scheduled, and with high data rates (like
984 * with OHCI) data can get lost. 980 * with OHCI) data can get lost.
985 */ 981 */
986 if (port->tty) 982 if (tty)
987 port->tty->low_latency = 1; 983 tty->low_latency = 1;
988 984
989 spin_lock_irqsave(&garmin_data_p->lock, flags); 985 spin_lock_irqsave(&garmin_data_p->lock, flags);
990 garmin_data_p->mode = initial_mode; 986 garmin_data_p->mode = initial_mode;
@@ -995,23 +991,22 @@ static int garmin_open (struct usb_serial_port *port, struct file *filp)
995 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 991 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
996 992
997 /* shutdown any bulk reads that might be going on */ 993 /* shutdown any bulk reads that might be going on */
998 usb_kill_urb (port->write_urb); 994 usb_kill_urb(port->write_urb);
999 usb_kill_urb (port->read_urb); 995 usb_kill_urb(port->read_urb);
1000 996
1001 if (garmin_data_p->state == STATE_RESET) { 997 if (garmin_data_p->state == STATE_RESET)
1002 status = garmin_init_session(port); 998 status = garmin_init_session(port);
1003 }
1004 999
1005 garmin_data_p->state = STATE_ACTIVE; 1000 garmin_data_p->state = STATE_ACTIVE;
1006
1007 return status; 1001 return status;
1008} 1002}
1009 1003
1010 1004
1011static void garmin_close (struct usb_serial_port *port, struct file * filp) 1005static void garmin_close(struct tty_struct *tty,
1006 struct usb_serial_port *port, struct file *filp)
1012{ 1007{
1013 struct usb_serial *serial = port->serial; 1008 struct usb_serial *serial = port->serial;
1014 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1009 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1015 1010
1016 dbg("%s - port %d - mode=%d state=%d flags=0x%X", __func__, 1011 dbg("%s - port %d - mode=%d state=%d flags=0x%X", __func__,
1017 port->number, garmin_data_p->mode, 1012 port->number, garmin_data_p->mode,
@@ -1025,8 +1020,8 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp)
1025 garmin_clear(garmin_data_p); 1020 garmin_clear(garmin_data_p);
1026 1021
1027 /* shutdown our urbs */ 1022 /* shutdown our urbs */
1028 usb_kill_urb (port->read_urb); 1023 usb_kill_urb(port->read_urb);
1029 usb_kill_urb (port->write_urb); 1024 usb_kill_urb(port->write_urb);
1030 1025
1031 if (!port->serial->disconnected) { 1026 if (!port->serial->disconnected) {
1032 if (noResponseFromAppLayer(garmin_data_p) || 1027 if (noResponseFromAppLayer(garmin_data_p) ||
@@ -1042,21 +1037,22 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp)
1042 mutex_unlock(&port->serial->disc_mutex); 1037 mutex_unlock(&port->serial->disc_mutex);
1043} 1038}
1044 1039
1045 1040static void garmin_write_bulk_callback(struct urb *urb)
1046static void garmin_write_bulk_callback (struct urb *urb)
1047{ 1041{
1048 unsigned long flags; 1042 unsigned long flags;
1049 struct usb_serial_port *port = urb->context; 1043 struct usb_serial_port *port = urb->context;
1050 int status = urb->status; 1044 int status = urb->status;
1051 1045
1052 if (port) { 1046 if (port) {
1053 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1047 struct garmin_data *garmin_data_p =
1048 usb_get_serial_port_data(port);
1054 1049
1055 dbg("%s - port %d", __func__, port->number); 1050 dbg("%s - port %d", __func__, port->number);
1056 1051
1057 if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer) 1052 if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer)
1058 && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) { 1053 && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) {
1059 gsp_send_ack(garmin_data_p, ((__u8 *)urb->transfer_buffer)[4]); 1054 gsp_send_ack(garmin_data_p,
1055 ((__u8 *)urb->transfer_buffer)[4]);
1060 } 1056 }
1061 1057
1062 if (status) { 1058 if (status) {
@@ -1070,20 +1066,21 @@ static void garmin_write_bulk_callback (struct urb *urb)
1070 usb_serial_port_softint(port); 1066 usb_serial_port_softint(port);
1071 } 1067 }
1072 1068
1073 /* Ignore errors that resulted from garmin_write_bulk with dismiss_ack=1 */ 1069 /* Ignore errors that resulted from garmin_write_bulk with
1070 dismiss_ack = 1 */
1074 1071
1075 /* free up the transfer buffer, as usb_free_urb() does not do this */ 1072 /* free up the transfer buffer, as usb_free_urb() does not do this */
1076 kfree (urb->transfer_buffer); 1073 kfree(urb->transfer_buffer);
1077} 1074}
1078 1075
1079 1076
1080static int garmin_write_bulk (struct usb_serial_port *port, 1077static int garmin_write_bulk(struct usb_serial_port *port,
1081 const unsigned char *buf, int count, 1078 const unsigned char *buf, int count,
1082 int dismiss_ack) 1079 int dismiss_ack)
1083{ 1080{
1084 unsigned long flags; 1081 unsigned long flags;
1085 struct usb_serial *serial = port->serial; 1082 struct usb_serial *serial = port->serial;
1086 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1083 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1087 struct urb *urb; 1084 struct urb *urb;
1088 unsigned char *buffer; 1085 unsigned char *buffer;
1089 int status; 1086 int status;
@@ -1095,7 +1092,7 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1095 garmin_data_p->flags &= ~FLAGS_DROP_DATA; 1092 garmin_data_p->flags &= ~FLAGS_DROP_DATA;
1096 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1093 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1097 1094
1098 buffer = kmalloc (count, GFP_ATOMIC); 1095 buffer = kmalloc(count, GFP_ATOMIC);
1099 if (!buffer) { 1096 if (!buffer) {
1100 dev_err(&port->dev, "out of memory\n"); 1097 dev_err(&port->dev, "out of memory\n");
1101 return -ENOMEM; 1098 return -ENOMEM;
@@ -1104,17 +1101,17 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1104 urb = usb_alloc_urb(0, GFP_ATOMIC); 1101 urb = usb_alloc_urb(0, GFP_ATOMIC);
1105 if (!urb) { 1102 if (!urb) {
1106 dev_err(&port->dev, "no more free urbs\n"); 1103 dev_err(&port->dev, "no more free urbs\n");
1107 kfree (buffer); 1104 kfree(buffer);
1108 return -ENOMEM; 1105 return -ENOMEM;
1109 } 1106 }
1110 1107
1111 memcpy (buffer, buf, count); 1108 memcpy(buffer, buf, count);
1112 1109
1113 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); 1110 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
1114 1111
1115 usb_fill_bulk_urb (urb, serial->dev, 1112 usb_fill_bulk_urb(urb, serial->dev,
1116 usb_sndbulkpipe (serial->dev, 1113 usb_sndbulkpipe(serial->dev,
1117 port->bulk_out_endpointAddress), 1114 port->bulk_out_endpointAddress),
1118 buffer, count, 1115 buffer, count,
1119 garmin_write_bulk_callback, 1116 garmin_write_bulk_callback,
1120 dismiss_ack ? NULL : port); 1117 dismiss_ack ? NULL : port);
@@ -1132,33 +1129,29 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1132 status = usb_submit_urb(urb, GFP_ATOMIC); 1129 status = usb_submit_urb(urb, GFP_ATOMIC);
1133 if (status) { 1130 if (status) {
1134 dev_err(&port->dev, 1131 dev_err(&port->dev,
1135 "%s - usb_submit_urb(write bulk) " 1132 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
1136 "failed with status = %d\n",
1137 __func__, status); 1133 __func__, status);
1138 count = status; 1134 count = status;
1139 } 1135 }
1140 1136
1141 /* we are done with this urb, so let the host driver 1137 /* we are done with this urb, so let the host driver
1142 * really free it when it is finished with it */ 1138 * really free it when it is finished with it */
1143 usb_free_urb (urb); 1139 usb_free_urb(urb);
1144 1140
1145 return count; 1141 return count;
1146} 1142}
1147 1143
1148 1144static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port,
1149 1145 const unsigned char *buf, int count)
1150static int garmin_write (struct usb_serial_port *port,
1151 const unsigned char *buf, int count)
1152{ 1146{
1153 int pktid, pktsiz, len; 1147 int pktid, pktsiz, len;
1154 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1148 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1155 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; 1149 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt;
1156 1150
1157 usb_serial_debug_data(debug, &port->dev, __func__, count, buf); 1151 usb_serial_debug_data(debug, &port->dev, __func__, count, buf);
1158 1152
1159 /* check for our private packets */ 1153 /* check for our private packets */
1160 if (count >= GARMIN_PKTHDR_LENGTH) { 1154 if (count >= GARMIN_PKTHDR_LENGTH) {
1161
1162 len = PRIVPKTSIZ; 1155 len = PRIVPKTSIZ;
1163 if (count < len) 1156 if (count < len)
1164 len = count; 1157 len = count;
@@ -1169,15 +1162,16 @@ static int garmin_write (struct usb_serial_port *port,
1169 pktid = getPacketId(garmin_data_p->privpkt); 1162 pktid = getPacketId(garmin_data_p->privpkt);
1170 1163
1171 if (count == (GARMIN_PKTHDR_LENGTH+pktsiz) 1164 if (count == (GARMIN_PKTHDR_LENGTH+pktsiz)
1172 && GARMIN_LAYERID_PRIVATE == getLayerId(garmin_data_p->privpkt)) { 1165 && GARMIN_LAYERID_PRIVATE ==
1166 getLayerId(garmin_data_p->privpkt)) {
1173 1167
1174 dbg("%s - processing private request %d", 1168 dbg("%s - processing private request %d",
1175 __func__, pktid); 1169 __func__, pktid);
1176 1170
1177 // drop all unfinished transfers 1171 /* drop all unfinished transfers */
1178 garmin_clear(garmin_data_p); 1172 garmin_clear(garmin_data_p);
1179 1173
1180 switch(pktid) { 1174 switch (pktid) {
1181 1175
1182 case PRIV_PKTID_SET_DEBUG: 1176 case PRIV_PKTID_SET_DEBUG:
1183 if (pktsiz != 4) 1177 if (pktsiz != 4)
@@ -1226,44 +1220,31 @@ static int garmin_write (struct usb_serial_port *port,
1226} 1220}
1227 1221
1228 1222
1229static int garmin_write_room (struct usb_serial_port *port) 1223static int garmin_write_room(struct tty_struct *tty)
1230{ 1224{
1225 struct usb_serial_port *port = tty->driver_data;
1231 /* 1226 /*
1232 * Report back the bytes currently available in the output buffer. 1227 * Report back the bytes currently available in the output buffer.
1233 */ 1228 */
1234 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1229 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1235 return GPS_OUT_BUFSIZ-garmin_data_p->outsize; 1230 return GPS_OUT_BUFSIZ-garmin_data_p->outsize;
1236} 1231}
1237 1232
1238 1233
1239static int garmin_chars_in_buffer (struct usb_serial_port *port) 1234static void garmin_read_process(struct garmin_data *garmin_data_p,
1240{
1241 /*
1242 * Report back the number of bytes currently in our input buffer.
1243 * Will this lock up the driver - the buffer contains an incomplete
1244 * package which will not be written to the device until it
1245 * has been completed ?
1246 */
1247 //struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1248 //return garmin_data_p->insize;
1249 return 0;
1250}
1251
1252
1253static void garmin_read_process(struct garmin_data * garmin_data_p,
1254 unsigned char *data, unsigned data_length) 1235 unsigned char *data, unsigned data_length)
1255{ 1236{
1256 if (garmin_data_p->flags & FLAGS_DROP_DATA) { 1237 if (garmin_data_p->flags & FLAGS_DROP_DATA) {
1257 /* abort-transfer cmd is actice */ 1238 /* abort-transfer cmd is actice */
1258 dbg("%s - pkt dropped", __func__); 1239 dbg("%s - pkt dropped", __func__);
1259 } else if (garmin_data_p->state != STATE_DISCONNECTED && 1240 } else if (garmin_data_p->state != STATE_DISCONNECTED &&
1260 garmin_data_p->state != STATE_RESET ) { 1241 garmin_data_p->state != STATE_RESET) {
1261 1242
1262 /* remember any appl.layer packets, so we know 1243 /* remember any appl.layer packets, so we know
1263 if a reset is required or not when closing 1244 if a reset is required or not when closing
1264 the device */ 1245 the device */
1265 if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY, 1246 if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY,
1266 sizeof(GARMIN_APP_LAYER_REPLY))) { 1247 sizeof(GARMIN_APP_LAYER_REPLY))) {
1267 atomic_inc(&garmin_data_p->resp_count); 1248 atomic_inc(&garmin_data_p->resp_count);
1268 } 1249 }
1269 1250
@@ -1273,9 +1254,8 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
1273 if (garmin_data_p->flags & FLAGS_QUEUING) { 1254 if (garmin_data_p->flags & FLAGS_QUEUING) {
1274 pkt_add(garmin_data_p, data, data_length); 1255 pkt_add(garmin_data_p, data, data_length);
1275 } else if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { 1256 } else if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1276 if (getLayerId(data) == GARMIN_LAYERID_APPL) { 1257 if (getLayerId(data) == GARMIN_LAYERID_APPL)
1277 pkt_add(garmin_data_p, data, data_length); 1258 pkt_add(garmin_data_p, data, data_length);
1278 }
1279 } else { 1259 } else {
1280 send_to_tty(garmin_data_p->port, data, data_length); 1260 send_to_tty(garmin_data_p->port, data, data_length);
1281 } 1261 }
@@ -1283,12 +1263,12 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
1283} 1263}
1284 1264
1285 1265
1286static void garmin_read_bulk_callback (struct urb *urb) 1266static void garmin_read_bulk_callback(struct urb *urb)
1287{ 1267{
1288 unsigned long flags; 1268 unsigned long flags;
1289 struct usb_serial_port *port = urb->context; 1269 struct usb_serial_port *port = urb->context;
1290 struct usb_serial *serial = port->serial; 1270 struct usb_serial *serial = port->serial;
1291 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1271 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1292 unsigned char *data = urb->transfer_buffer; 1272 unsigned char *data = urb->transfer_buffer;
1293 int status = urb->status; 1273 int status = urb->status;
1294 int retval; 1274 int retval;
@@ -1306,7 +1286,7 @@ static void garmin_read_bulk_callback (struct urb *urb)
1306 return; 1286 return;
1307 } 1287 }
1308 1288
1309 usb_serial_debug_data(debug, &port->dev, 1289 usb_serial_debug_data(debug, &port->dev,
1310 __func__, urb->actual_length, data); 1290 __func__, urb->actual_length, data);
1311 1291
1312 garmin_read_process(garmin_data_p, data, urb->actual_length); 1292 garmin_read_process(garmin_data_p, data, urb->actual_length);
@@ -1340,13 +1320,13 @@ static void garmin_read_bulk_callback (struct urb *urb)
1340} 1320}
1341 1321
1342 1322
1343static void garmin_read_int_callback (struct urb *urb) 1323static void garmin_read_int_callback(struct urb *urb)
1344{ 1324{
1345 unsigned long flags; 1325 unsigned long flags;
1346 int retval; 1326 int retval;
1347 struct usb_serial_port *port = urb->context; 1327 struct usb_serial_port *port = urb->context;
1348 struct usb_serial *serial = port->serial; 1328 struct usb_serial *serial = port->serial;
1349 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1329 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1350 unsigned char *data = urb->transfer_buffer; 1330 unsigned char *data = urb->transfer_buffer;
1351 int status = urb->status; 1331 int status = urb->status;
1352 1332
@@ -1372,30 +1352,31 @@ static void garmin_read_int_callback (struct urb *urb)
1372 1352
1373 if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) && 1353 if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) &&
1374 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY, 1354 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY,
1375 sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) { 1355 sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) {
1376 1356
1377 dbg("%s - bulk data available.", __func__); 1357 dbg("%s - bulk data available.", __func__);
1378 1358
1379 if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { 1359 if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) {
1380 1360
1381 /* bulk data available */ 1361 /* bulk data available */
1382 usb_fill_bulk_urb (port->read_urb, serial->dev, 1362 usb_fill_bulk_urb(port->read_urb, serial->dev,
1383 usb_rcvbulkpipe (serial->dev, 1363 usb_rcvbulkpipe(serial->dev,
1384 port->bulk_in_endpointAddress), 1364 port->bulk_in_endpointAddress),
1385 port->read_urb->transfer_buffer, 1365 port->read_urb->transfer_buffer,
1386 port->read_urb->transfer_buffer_length, 1366 port->read_urb->transfer_buffer_length,
1387 garmin_read_bulk_callback, port); 1367 garmin_read_bulk_callback, port);
1388 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC); 1368 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1389 if (retval) { 1369 if (retval) {
1390 dev_err(&port->dev, 1370 dev_err(&port->dev,
1391 "%s - failed submitting read urb, error %d\n", 1371 "%s - failed submitting read urb, error %d\n",
1392 __func__, retval); 1372 __func__, retval);
1393 } else { 1373 } else {
1394 spin_lock_irqsave(&garmin_data_p->lock, flags); 1374 spin_lock_irqsave(&garmin_data_p->lock, flags);
1395 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE; 1375 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE;
1396 /* do not send this packet to the user */ 1376 /* do not send this packet to the user */
1397 garmin_data_p->ignorePkts = 1; 1377 garmin_data_p->ignorePkts = 1;
1398 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1378 spin_unlock_irqrestore(&garmin_data_p->lock,
1379 flags);
1399 } 1380 }
1400 } else { 1381 } else {
1401 /* bulk-in transfer still active */ 1382 /* bulk-in transfer still active */
@@ -1406,15 +1387,15 @@ static void garmin_read_int_callback (struct urb *urb)
1406 1387
1407 } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY)) 1388 } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY))
1408 && 0 == memcmp(data, GARMIN_START_SESSION_REPLY, 1389 && 0 == memcmp(data, GARMIN_START_SESSION_REPLY,
1409 sizeof(GARMIN_START_SESSION_REPLY))) { 1390 sizeof(GARMIN_START_SESSION_REPLY))) {
1410 1391
1411 spin_lock_irqsave(&garmin_data_p->lock, flags); 1392 spin_lock_irqsave(&garmin_data_p->lock, flags);
1412 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN; 1393 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN;
1413 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1394 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1414 1395
1415 /* save the serial number */ 1396 /* save the serial number */
1416 garmin_data_p->serial_num 1397 garmin_data_p->serial_num = __le32_to_cpup(
1417 = __le32_to_cpup((__le32*)(data+GARMIN_PKTHDR_LENGTH)); 1398 (__le32 *)(data+GARMIN_PKTHDR_LENGTH));
1418 1399
1419 dbg("%s - start-of-session reply seen - serial %u.", 1400 dbg("%s - start-of-session reply seen - serial %u.",
1420 __func__, garmin_data_p->serial_num); 1401 __func__, garmin_data_p->serial_num);
@@ -1433,7 +1414,7 @@ static void garmin_read_int_callback (struct urb *urb)
1433 } 1414 }
1434 1415
1435 port->interrupt_in_urb->dev = port->serial->dev; 1416 port->interrupt_in_urb->dev = port->serial->dev;
1436 retval = usb_submit_urb (urb, GFP_ATOMIC); 1417 retval = usb_submit_urb(urb, GFP_ATOMIC);
1437 if (retval) 1418 if (retval)
1438 dev_err(&urb->dev->dev, 1419 dev_err(&urb->dev->dev,
1439 "%s - Error %d submitting interrupt urb\n", 1420 "%s - Error %d submitting interrupt urb\n",
@@ -1446,7 +1427,7 @@ static void garmin_read_int_callback (struct urb *urb)
1446 * and then sets a timer to call itself again until all queued data 1427 * and then sets a timer to call itself again until all queued data
1447 * is sent. 1428 * is sent.
1448 */ 1429 */
1449static int garmin_flush_queue(struct garmin_data * garmin_data_p) 1430static int garmin_flush_queue(struct garmin_data *garmin_data_p)
1450{ 1431{
1451 unsigned long flags; 1432 unsigned long flags;
1452 struct garmin_packet *pkt; 1433 struct garmin_packet *pkt;
@@ -1468,10 +1449,11 @@ static int garmin_flush_queue(struct garmin_data * garmin_data_p)
1468} 1449}
1469 1450
1470 1451
1471static void garmin_throttle (struct usb_serial_port *port) 1452static void garmin_throttle(struct tty_struct *tty)
1472{ 1453{
1454 struct usb_serial_port *port = tty->driver_data;
1455 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1473 unsigned long flags; 1456 unsigned long flags;
1474 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1475 1457
1476 dbg("%s - port %d", __func__, port->number); 1458 dbg("%s - port %d", __func__, port->number);
1477 /* set flag, data received will be put into a queue 1459 /* set flag, data received will be put into a queue
@@ -1482,10 +1464,11 @@ static void garmin_throttle (struct usb_serial_port *port)
1482} 1464}
1483 1465
1484 1466
1485static void garmin_unthrottle (struct usb_serial_port *port) 1467static void garmin_unthrottle(struct tty_struct *tty)
1486{ 1468{
1469 struct usb_serial_port *port = tty->driver_data;
1470 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1487 unsigned long flags; 1471 unsigned long flags;
1488 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1489 int status; 1472 int status;
1490 1473
1491 dbg("%s - port %d", __func__, port->number); 1474 dbg("%s - port %d", __func__, port->number);
@@ -1507,8 +1490,6 @@ static void garmin_unthrottle (struct usb_serial_port *port)
1507 } 1490 }
1508} 1491}
1509 1492
1510
1511
1512/* 1493/*
1513 * The timer is currently only used to send queued packets to 1494 * The timer is currently only used to send queued packets to
1514 * the tty in cases where the protocol provides no own handshaking 1495 * the tty in cases where the protocol provides no own handshaking
@@ -1526,11 +1507,11 @@ static void timeout_handler(unsigned long data)
1526 1507
1527 1508
1528 1509
1529static int garmin_attach (struct usb_serial *serial) 1510static int garmin_attach(struct usb_serial *serial)
1530{ 1511{
1531 int status = 0; 1512 int status = 0;
1532 struct usb_serial_port *port = serial->port[0]; 1513 struct usb_serial_port *port = serial->port[0];
1533 struct garmin_data * garmin_data_p = NULL; 1514 struct garmin_data *garmin_data_p = NULL;
1534 1515
1535 dbg("%s", __func__); 1516 dbg("%s", __func__);
1536 1517
@@ -1542,7 +1523,7 @@ static int garmin_attach (struct usb_serial *serial)
1542 init_timer(&garmin_data_p->timer); 1523 init_timer(&garmin_data_p->timer);
1543 spin_lock_init(&garmin_data_p->lock); 1524 spin_lock_init(&garmin_data_p->lock);
1544 INIT_LIST_HEAD(&garmin_data_p->pktlist); 1525 INIT_LIST_HEAD(&garmin_data_p->pktlist);
1545 //garmin_data_p->timer.expires = jiffies + session_timeout; 1526 /* garmin_data_p->timer.expires = jiffies + session_timeout; */
1546 garmin_data_p->timer.data = (unsigned long)garmin_data_p; 1527 garmin_data_p->timer.data = (unsigned long)garmin_data_p;
1547 garmin_data_p->timer.function = timeout_handler; 1528 garmin_data_p->timer.function = timeout_handler;
1548 garmin_data_p->port = port; 1529 garmin_data_p->port = port;
@@ -1556,16 +1537,16 @@ static int garmin_attach (struct usb_serial *serial)
1556} 1537}
1557 1538
1558 1539
1559static void garmin_shutdown (struct usb_serial *serial) 1540static void garmin_shutdown(struct usb_serial *serial)
1560{ 1541{
1561 struct usb_serial_port *port = serial->port[0]; 1542 struct usb_serial_port *port = serial->port[0];
1562 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1543 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1563 1544
1564 dbg("%s", __func__); 1545 dbg("%s", __func__);
1565 1546
1566 usb_kill_urb (port->interrupt_in_urb); 1547 usb_kill_urb(port->interrupt_in_urb);
1567 del_timer_sync(&garmin_data_p->timer); 1548 del_timer_sync(&garmin_data_p->timer);
1568 kfree (garmin_data_p); 1549 kfree(garmin_data_p);
1569 usb_set_serial_port_data(port, NULL); 1550 usb_set_serial_port_data(port, NULL);
1570} 1551}
1571 1552
@@ -1588,7 +1569,6 @@ static struct usb_serial_driver garmin_device = {
1588 .shutdown = garmin_shutdown, 1569 .shutdown = garmin_shutdown,
1589 .write = garmin_write, 1570 .write = garmin_write,
1590 .write_room = garmin_write_room, 1571 .write_room = garmin_write_room,
1591 .chars_in_buffer = garmin_chars_in_buffer,
1592 .write_bulk_callback = garmin_write_bulk_callback, 1572 .write_bulk_callback = garmin_write_bulk_callback,
1593 .read_bulk_callback = garmin_read_bulk_callback, 1573 .read_bulk_callback = garmin_read_bulk_callback,
1594 .read_int_callback = garmin_read_int_callback, 1574 .read_int_callback = garmin_read_int_callback,
@@ -1596,7 +1576,7 @@ static struct usb_serial_driver garmin_device = {
1596 1576
1597 1577
1598 1578
1599static int __init garmin_init (void) 1579static int __init garmin_init(void)
1600{ 1580{
1601 int retval; 1581 int retval;
1602 1582
@@ -1616,10 +1596,10 @@ failed_garmin_register:
1616} 1596}
1617 1597
1618 1598
1619static void __exit garmin_exit (void) 1599static void __exit garmin_exit(void)
1620{ 1600{
1621 usb_deregister (&garmin_driver); 1601 usb_deregister(&garmin_driver);
1622 usb_serial_deregister (&garmin_device); 1602 usb_serial_deregister(&garmin_device);
1623} 1603}
1624 1604
1625 1605
@@ -1628,8 +1608,8 @@ static void __exit garmin_exit (void)
1628module_init(garmin_init); 1608module_init(garmin_init);
1629module_exit(garmin_exit); 1609module_exit(garmin_exit);
1630 1610
1631MODULE_AUTHOR( DRIVER_AUTHOR ); 1611MODULE_AUTHOR(DRIVER_AUTHOR);
1632MODULE_DESCRIPTION( DRIVER_DESC ); 1612MODULE_DESCRIPTION(DRIVER_DESC);
1633MODULE_LICENSE("GPL"); 1613MODULE_LICENSE("GPL");
1634 1614
1635module_param(debug, bool, S_IWUSR | S_IRUGO); 1615module_param(debug, bool, S_IWUSR | S_IRUGO);
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 537f12a027c2..fe84c88ec20c 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -18,7 +18,7 @@
18#include <linux/moduleparam.h> 18#include <linux/moduleparam.h>
19#include <linux/usb.h> 19#include <linux/usb.h>
20#include <linux/usb/serial.h> 20#include <linux/usb/serial.h>
21#include <asm/uaccess.h> 21#include <linux/uaccess.h>
22 22
23 23
24static int debug; 24static int debug;
@@ -81,7 +81,7 @@ static int generic_probe(struct usb_interface *interface,
81} 81}
82#endif 82#endif
83 83
84int usb_serial_generic_register (int _debug) 84int usb_serial_generic_register(int _debug)
85{ 85{
86 int retval = 0; 86 int retval = 0;
87 87
@@ -89,10 +89,11 @@ int usb_serial_generic_register (int _debug)
89#ifdef CONFIG_USB_SERIAL_GENERIC 89#ifdef CONFIG_USB_SERIAL_GENERIC
90 generic_device_ids[0].idVendor = vendor; 90 generic_device_ids[0].idVendor = vendor;
91 generic_device_ids[0].idProduct = product; 91 generic_device_ids[0].idProduct = product;
92 generic_device_ids[0].match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; 92 generic_device_ids[0].match_flags =
93 USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT;
93 94
94 /* register our generic driver with ourselves */ 95 /* register our generic driver with ourselves */
95 retval = usb_serial_register (&usb_serial_generic_device); 96 retval = usb_serial_register(&usb_serial_generic_device);
96 if (retval) 97 if (retval)
97 goto exit; 98 goto exit;
98 retval = usb_register(&generic_driver); 99 retval = usb_register(&generic_driver);
@@ -103,16 +104,17 @@ exit:
103 return retval; 104 return retval;
104} 105}
105 106
106void usb_serial_generic_deregister (void) 107void usb_serial_generic_deregister(void)
107{ 108{
108#ifdef CONFIG_USB_SERIAL_GENERIC 109#ifdef CONFIG_USB_SERIAL_GENERIC
109 /* remove our generic driver */ 110 /* remove our generic driver */
110 usb_deregister(&generic_driver); 111 usb_deregister(&generic_driver);
111 usb_serial_deregister (&usb_serial_generic_device); 112 usb_serial_deregister(&usb_serial_generic_device);
112#endif 113#endif
113} 114}
114 115
115int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp) 116int usb_serial_generic_open(struct tty_struct *tty,
117 struct usb_serial_port *port, struct file *filp)
116{ 118{
117 struct usb_serial *serial = port->serial; 119 struct usb_serial *serial = port->serial;
118 int result = 0; 120 int result = 0;
@@ -120,11 +122,11 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
120 122
121 dbg("%s - port %d", __func__, port->number); 123 dbg("%s - port %d", __func__, port->number);
122 124
123 /* force low_latency on so that our tty_push actually forces the data through, 125 /* force low_latency on so that our tty_push actually forces the data
124 otherwise it is scheduled, and with high data rates (like with OHCI) data 126 through, otherwise it is scheduled, and with high data rates (like
125 can get lost. */ 127 with OHCI) data can get lost. */
126 if (port->tty) 128 if (tty)
127 port->tty->low_latency = 1; 129 tty->low_latency = 1;
128 130
129 /* clear the throttle flags */ 131 /* clear the throttle flags */
130 spin_lock_irqsave(&port->lock, flags); 132 spin_lock_irqsave(&port->lock, flags);
@@ -135,8 +137,9 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
135 /* if we have a bulk endpoint, start reading from it */ 137 /* if we have a bulk endpoint, start reading from it */
136 if (serial->num_bulk_in) { 138 if (serial->num_bulk_in) {
137 /* Start reading from the device */ 139 /* Start reading from the device */
138 usb_fill_bulk_urb (port->read_urb, serial->dev, 140 usb_fill_bulk_urb(port->read_urb, serial->dev,
139 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), 141 usb_rcvbulkpipe(serial->dev,
142 port->bulk_in_endpointAddress),
140 port->read_urb->transfer_buffer, 143 port->read_urb->transfer_buffer,
141 port->read_urb->transfer_buffer_length, 144 port->read_urb->transfer_buffer_length,
142 ((serial->type->read_bulk_callback) ? 145 ((serial->type->read_bulk_callback) ?
@@ -145,14 +148,16 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
145 port); 148 port);
146 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 149 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
147 if (result) 150 if (result)
148 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 151 dev_err(&port->dev,
152 "%s - failed resubmitting read urb, error %d\n",
153 __func__, result);
149 } 154 }
150 155
151 return result; 156 return result;
152} 157}
153EXPORT_SYMBOL_GPL(usb_serial_generic_open); 158EXPORT_SYMBOL_GPL(usb_serial_generic_open);
154 159
155static void generic_cleanup (struct usb_serial_port *port) 160static void generic_cleanup(struct usb_serial_port *port)
156{ 161{
157 struct usb_serial *serial = port->serial; 162 struct usb_serial *serial = port->serial;
158 163
@@ -182,7 +187,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)
182#endif 187#endif
183 for (i = 0; i < serial->num_ports; i++) { 188 for (i = 0; i < serial->num_ports; i++) {
184 port = serial->port[i]; 189 port = serial->port[i];
185 if (port->open_count && port->read_urb) { 190 if (port->port.count && port->read_urb) {
186 r = usb_submit_urb(port->read_urb, GFP_NOIO); 191 r = usb_submit_urb(port->read_urb, GFP_NOIO);
187 if (r < 0) 192 if (r < 0)
188 c++; 193 c++;
@@ -192,13 +197,15 @@ int usb_serial_generic_resume(struct usb_serial *serial)
192 return c ? -EIO : 0; 197 return c ? -EIO : 0;
193} 198}
194 199
195void usb_serial_generic_close (struct usb_serial_port *port, struct file * filp) 200void usb_serial_generic_close(struct tty_struct *tty,
201 struct usb_serial_port *port, struct file *filp)
196{ 202{
197 dbg("%s - port %d", __func__, port->number); 203 dbg("%s - port %d", __func__, port->number);
198 generic_cleanup (port); 204 generic_cleanup(port);
199} 205}
200 206
201int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *buf, int count) 207int usb_serial_generic_write(struct tty_struct *tty,
208 struct usb_serial_port *port, const unsigned char *buf, int count)
202{ 209{
203 struct usb_serial *serial = port->serial; 210 struct usb_serial *serial = port->serial;
204 int result; 211 int result;
@@ -208,7 +215,7 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
208 215
209 if (count == 0) { 216 if (count == 0) {
210 dbg("%s - write request of 0 bytes", __func__); 217 dbg("%s - write request of 0 bytes", __func__);
211 return (0); 218 return 0;
212 } 219 }
213 220
214 /* only do something if we have a bulk out endpoint */ 221 /* only do something if we have a bulk out endpoint */
@@ -223,27 +230,32 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
223 port->write_urb_busy = 1; 230 port->write_urb_busy = 1;
224 spin_unlock_irqrestore(&port->lock, flags); 231 spin_unlock_irqrestore(&port->lock, flags);
225 232
226 count = (count > port->bulk_out_size) ? port->bulk_out_size : count; 233 count = (count > port->bulk_out_size) ?
234 port->bulk_out_size : count;
227 235
228 memcpy (port->write_urb->transfer_buffer, buf, count); 236 memcpy(port->write_urb->transfer_buffer, buf, count);
229 data = port->write_urb->transfer_buffer; 237 data = port->write_urb->transfer_buffer;
230 usb_serial_debug_data(debug, &port->dev, __func__, count, data); 238 usb_serial_debug_data(debug, &port->dev, __func__, count, data);
231 239
232 /* set up our urb */ 240 /* set up our urb */
233 usb_fill_bulk_urb (port->write_urb, serial->dev, 241 usb_fill_bulk_urb(port->write_urb, serial->dev,
234 usb_sndbulkpipe (serial->dev, 242 usb_sndbulkpipe(serial->dev,
235 port->bulk_out_endpointAddress), 243 port->bulk_out_endpointAddress),
236 port->write_urb->transfer_buffer, count, 244 port->write_urb->transfer_buffer, count,
237 ((serial->type->write_bulk_callback) ? 245 ((serial->type->write_bulk_callback) ?
238 serial->type->write_bulk_callback : 246 serial->type->write_bulk_callback :
239 usb_serial_generic_write_bulk_callback), port); 247 usb_serial_generic_write_bulk_callback),
248 port);
240 249
241 /* send the data out the bulk port */ 250 /* send the data out the bulk port */
242 port->write_urb_busy = 1; 251 port->write_urb_busy = 1;
243 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 252 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
244 if (result) { 253 if (result) {
245 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); 254 dev_err(&port->dev,
246 /* don't have to grab the lock here, as we will retry if != 0 */ 255 "%s - failed submitting write urb, error %d\n",
256 __func__, result);
257 /* don't have to grab the lock here, as we will
258 retry if != 0 */
247 port->write_urb_busy = 0; 259 port->write_urb_busy = 0;
248 } else 260 } else
249 result = count; 261 result = count;
@@ -255,8 +267,9 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
255 return 0; 267 return 0;
256} 268}
257 269
258int usb_serial_generic_write_room (struct usb_serial_port *port) 270int usb_serial_generic_write_room(struct tty_struct *tty)
259{ 271{
272 struct usb_serial_port *port = tty->driver_data;
260 struct usb_serial *serial = port->serial; 273 struct usb_serial *serial = port->serial;
261 int room = 0; 274 int room = 0;
262 275
@@ -272,8 +285,9 @@ int usb_serial_generic_write_room (struct usb_serial_port *port)
272 return room; 285 return room;
273} 286}
274 287
275int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port) 288int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
276{ 289{
290 struct usb_serial_port *port = tty->driver_data;
277 struct usb_serial *serial = port->serial; 291 struct usb_serial *serial = port->serial;
278 int chars = 0; 292 int chars = 0;
279 293
@@ -286,7 +300,7 @@ int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port)
286 } 300 }
287 301
288 dbg("%s - returns %d", __func__, chars); 302 dbg("%s - returns %d", __func__, chars);
289 return (chars); 303 return chars;
290} 304}
291 305
292 306
@@ -297,24 +311,26 @@ static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags)
297 int result; 311 int result;
298 312
299 /* Continue reading from device */ 313 /* Continue reading from device */
300 usb_fill_bulk_urb (urb, serial->dev, 314 usb_fill_bulk_urb(urb, serial->dev,
301 usb_rcvbulkpipe (serial->dev, 315 usb_rcvbulkpipe(serial->dev,
302 port->bulk_in_endpointAddress), 316 port->bulk_in_endpointAddress),
303 urb->transfer_buffer, 317 urb->transfer_buffer,
304 urb->transfer_buffer_length, 318 urb->transfer_buffer_length,
305 ((serial->type->read_bulk_callback) ? 319 ((serial->type->read_bulk_callback) ?
306 serial->type->read_bulk_callback : 320 serial->type->read_bulk_callback :
307 usb_serial_generic_read_bulk_callback), port); 321 usb_serial_generic_read_bulk_callback), port);
308 result = usb_submit_urb(urb, mem_flags); 322 result = usb_submit_urb(urb, mem_flags);
309 if (result) 323 if (result)
310 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 324 dev_err(&port->dev,
325 "%s - failed resubmitting read urb, error %d\n",
326 __func__, result);
311} 327}
312 328
313/* Push data to tty layer and resubmit the bulk read URB */ 329/* Push data to tty layer and resubmit the bulk read URB */
314static void flush_and_resubmit_read_urb (struct usb_serial_port *port) 330static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
315{ 331{
316 struct urb *urb = port->read_urb; 332 struct urb *urb = port->read_urb;
317 struct tty_struct *tty = port->tty; 333 struct tty_struct *tty = port->port.tty;
318 int room; 334 int room;
319 335
320 /* Push data to tty */ 336 /* Push data to tty */
@@ -329,7 +345,7 @@ static void flush_and_resubmit_read_urb (struct usb_serial_port *port)
329 resubmit_read_urb(port, GFP_ATOMIC); 345 resubmit_read_urb(port, GFP_ATOMIC);
330} 346}
331 347
332void usb_serial_generic_read_bulk_callback (struct urb *urb) 348void usb_serial_generic_read_bulk_callback(struct urb *urb)
333{ 349{
334 struct usb_serial_port *port = urb->context; 350 struct usb_serial_port *port = urb->context;
335 unsigned char *data = urb->transfer_buffer; 351 unsigned char *data = urb->transfer_buffer;
@@ -344,20 +360,21 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb)
344 return; 360 return;
345 } 361 }
346 362
347 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 363 usb_serial_debug_data(debug, &port->dev, __func__,
364 urb->actual_length, data);
348 365
349 /* Throttle the device if requested by tty */ 366 /* Throttle the device if requested by tty */
350 spin_lock_irqsave(&port->lock, flags); 367 spin_lock_irqsave(&port->lock, flags);
351 if (!(port->throttled = port->throttle_req)) { 368 port->throttled = port->throttle_req;
369 if (!port->throttled) {
352 spin_unlock_irqrestore(&port->lock, flags); 370 spin_unlock_irqrestore(&port->lock, flags);
353 flush_and_resubmit_read_urb(port); 371 flush_and_resubmit_read_urb(port);
354 } else { 372 } else
355 spin_unlock_irqrestore(&port->lock, flags); 373 spin_unlock_irqrestore(&port->lock, flags);
356 }
357} 374}
358EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); 375EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
359 376
360void usb_serial_generic_write_bulk_callback (struct urb *urb) 377void usb_serial_generic_write_bulk_callback(struct urb *urb)
361{ 378{
362 struct usb_serial_port *port = urb->context; 379 struct usb_serial_port *port = urb->context;
363 int status = urb->status; 380 int status = urb->status;
@@ -374,8 +391,9 @@ void usb_serial_generic_write_bulk_callback (struct urb *urb)
374} 391}
375EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); 392EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
376 393
377void usb_serial_generic_throttle (struct usb_serial_port *port) 394void usb_serial_generic_throttle(struct tty_struct *tty)
378{ 395{
396 struct usb_serial_port *port = tty->driver_data;
379 unsigned long flags; 397 unsigned long flags;
380 398
381 dbg("%s - port %d", __func__, port->number); 399 dbg("%s - port %d", __func__, port->number);
@@ -387,8 +405,9 @@ void usb_serial_generic_throttle (struct usb_serial_port *port)
387 spin_unlock_irqrestore(&port->lock, flags); 405 spin_unlock_irqrestore(&port->lock, flags);
388} 406}
389 407
390void usb_serial_generic_unthrottle (struct usb_serial_port *port) 408void usb_serial_generic_unthrottle(struct tty_struct *tty)
391{ 409{
410 struct usb_serial_port *port = tty->driver_data;
392 int was_throttled; 411 int was_throttled;
393 unsigned long flags; 412 unsigned long flags;
394 413
@@ -406,15 +425,14 @@ void usb_serial_generic_unthrottle (struct usb_serial_port *port)
406 } 425 }
407} 426}
408 427
409void usb_serial_generic_shutdown (struct usb_serial *serial) 428void usb_serial_generic_shutdown(struct usb_serial *serial)
410{ 429{
411 int i; 430 int i;
412 431
413 dbg("%s", __func__); 432 dbg("%s", __func__);
414 433
415 /* stop reads and writes on all ports */ 434 /* stop reads and writes on all ports */
416 for (i=0; i < serial->num_ports; ++i) { 435 for (i = 0; i < serial->num_ports; ++i)
417 generic_cleanup(serial->port[i]); 436 generic_cleanup(serial->port[i]);
418 }
419} 437}
420 438
diff --git a/drivers/usb/serial/hp4x.c b/drivers/usb/serial/hp4x.c
index 75b88b356ebc..ab905869e959 100644
--- a/drivers/usb/serial/hp4x.c
+++ b/drivers/usb/serial/hp4x.c
@@ -9,7 +9,8 @@
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 10 * (at your option) any later version.
11 * 11 *
12 * See Documentation/usb/usb-serial.txt for more information on using this driver 12 * See Documentation/usb/usb-serial.txt for more information on using this
13 * driver
13 */ 14 */
14 15
15#include <linux/kernel.h> 16#include <linux/kernel.h>
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 2fd449bcfa35..bfa508ddb0fe 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -44,7 +44,7 @@
44#include <linux/wait.h> 44#include <linux/wait.h>
45#include <linux/firmware.h> 45#include <linux/firmware.h>
46#include <linux/ihex.h> 46#include <linux/ihex.h>
47#include <asm/uaccess.h> 47#include <linux/uaccess.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/usb/serial.h> 49#include <linux/usb/serial.h>
50#include "io_edgeport.h" 50#include "io_edgeport.h"
@@ -66,16 +66,16 @@
66 66
67/* receive port state */ 67/* receive port state */
68enum RXSTATE { 68enum RXSTATE {
69 EXPECT_HDR1 = 0, /* Expect header byte 1 */ 69 EXPECT_HDR1 = 0, /* Expect header byte 1 */
70 EXPECT_HDR2 = 1, /* Expect header byte 2 */ 70 EXPECT_HDR2 = 1, /* Expect header byte 2 */
71 EXPECT_DATA = 2, /* Expect 'RxBytesRemaining' data */ 71 EXPECT_DATA = 2, /* Expect 'RxBytesRemaining' data */
72 EXPECT_HDR3 = 3, /* Expect header byte 3 (for status hdrs only) */ 72 EXPECT_HDR3 = 3, /* Expect header byte 3 (for status hdrs only) */
73}; 73};
74 74
75 75
76/* Transmit Fifo 76/* Transmit Fifo
77 * This Transmit queue is an extension of the edgeport Rx buffer. 77 * This Transmit queue is an extension of the edgeport Rx buffer.
78 * The maximum amount of data buffered in both the edgeport 78 * The maximum amount of data buffered in both the edgeport
79 * Rx buffer (maxTxCredits) and this buffer will never exceed maxTxCredits. 79 * Rx buffer (maxTxCredits) and this buffer will never exceed maxTxCredits.
80 */ 80 */
81struct TxFifo { 81struct TxFifo {
@@ -132,12 +132,12 @@ struct edgeport_serial {
132 int is_epic; /* flag if EPiC device or not */ 132 int is_epic; /* flag if EPiC device or not */
133 133
134 __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */ 134 __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */
135 unsigned char * interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */ 135 unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */
136 struct urb * interrupt_read_urb; /* our interrupt urb */ 136 struct urb *interrupt_read_urb; /* our interrupt urb */
137 137
138 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */ 138 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
139 unsigned char * bulk_in_buffer; /* the buffer we use for the bulk in endpoint */ 139 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
140 struct urb * read_urb; /* our bulk read urb */ 140 struct urb *read_urb; /* our bulk read urb */
141 bool read_in_progress; 141 bool read_in_progress;
142 spinlock_t es_lock; 142 spinlock_t es_lock;
143 143
@@ -162,16 +162,17 @@ struct divisor_table_entry {
162 __u16 Divisor; 162 __u16 Divisor;
163}; 163};
164 164
165// 165/*
166// Define table of divisors for Rev A EdgePort/4 hardware 166 * Define table of divisors for Rev A EdgePort/4 hardware
167// These assume a 3.6864MHz crystal, the standard /16, and 167 * These assume a 3.6864MHz crystal, the standard /16, and
168// MCR.7 = 0. 168 * MCR.7 = 0.
169// 169 */
170
170static const struct divisor_table_entry divisor_table[] = { 171static const struct divisor_table_entry divisor_table[] = {
171 { 50, 4608}, 172 { 50, 4608},
172 { 75, 3072}, 173 { 75, 3072},
173 { 110, 2095}, /* 2094.545455 => 230450 => .0217 % over */ 174 { 110, 2095}, /* 2094.545455 => 230450 => .0217 % over */
174 { 134, 1713}, /* 1713.011152 => 230398.5 => .00065% under */ 175 { 134, 1713}, /* 1713.011152 => 230398.5 => .00065% under */
175 { 150, 1536}, 176 { 150, 1536},
176 { 300, 768}, 177 { 300, 768},
177 { 600, 384}, 178 { 600, 384},
@@ -194,64 +195,86 @@ static int debug;
194 195
195static int low_latency = 1; /* tty low latency flag, on by default */ 196static int low_latency = 1; /* tty low latency flag, on by default */
196 197
197static atomic_t CmdUrbs; /* Number of outstanding Command Write Urbs */ 198static atomic_t CmdUrbs; /* Number of outstanding Command Write Urbs */
198 199
199 200
200/* local function prototypes */ 201/* local function prototypes */
201 202
202/* function prototypes for all URB callbacks */ 203/* function prototypes for all URB callbacks */
203static void edge_interrupt_callback (struct urb *urb); 204static void edge_interrupt_callback(struct urb *urb);
204static void edge_bulk_in_callback (struct urb *urb); 205static void edge_bulk_in_callback(struct urb *urb);
205static void edge_bulk_out_data_callback (struct urb *urb); 206static void edge_bulk_out_data_callback(struct urb *urb);
206static void edge_bulk_out_cmd_callback (struct urb *urb); 207static void edge_bulk_out_cmd_callback(struct urb *urb);
207 208
208/* function prototypes for the usbserial callbacks */ 209/* function prototypes for the usbserial callbacks */
209static int edge_open (struct usb_serial_port *port, struct file *filp); 210static int edge_open(struct tty_struct *tty, struct usb_serial_port *port,
210static void edge_close (struct usb_serial_port *port, struct file *filp); 211 struct file *filp);
211static int edge_write (struct usb_serial_port *port, const unsigned char *buf, int count); 212static void edge_close(struct tty_struct *tty, struct usb_serial_port *port,
212static int edge_write_room (struct usb_serial_port *port); 213 struct file *filp);
213static int edge_chars_in_buffer (struct usb_serial_port *port); 214static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
214static void edge_throttle (struct usb_serial_port *port); 215 const unsigned char *buf, int count);
215static void edge_unthrottle (struct usb_serial_port *port); 216static int edge_write_room(struct tty_struct *tty);
216static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios); 217static int edge_chars_in_buffer(struct tty_struct *tty);
217static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg); 218static void edge_throttle(struct tty_struct *tty);
218static void edge_break (struct usb_serial_port *port, int break_state); 219static void edge_unthrottle(struct tty_struct *tty);
219static int edge_tiocmget (struct usb_serial_port *port, struct file *file); 220static void edge_set_termios(struct tty_struct *tty,
220static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); 221 struct usb_serial_port *port,
221static int edge_startup (struct usb_serial *serial); 222 struct ktermios *old_termios);
222static void edge_shutdown (struct usb_serial *serial); 223static int edge_ioctl(struct tty_struct *tty, struct file *file,
223 224 unsigned int cmd, unsigned long arg);
225static void edge_break(struct tty_struct *tty, int break_state);
226static int edge_tiocmget(struct tty_struct *tty, struct file *file);
227static int edge_tiocmset(struct tty_struct *tty, struct file *file,
228 unsigned int set, unsigned int clear);
229static int edge_startup(struct usb_serial *serial);
230static void edge_shutdown(struct usb_serial *serial);
224 231
225#include "io_tables.h" /* all of the devices that this driver supports */ 232#include "io_tables.h" /* all of the devices that this driver supports */
226 233
227/* function prototypes for all of our local functions */ 234/* function prototypes for all of our local functions */
228static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned char *buffer, __u16 bufferLength); 235
229static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2, __u8 byte3); 236static void process_rcvd_data(struct edgeport_serial *edge_serial,
230static void edge_tty_recv (struct device *dev, struct tty_struct *tty, unsigned char *data, int length); 237 unsigned char *buffer, __u16 bufferLength);
231static void handle_new_msr (struct edgeport_port *edge_port, __u8 newMsr); 238static void process_rcvd_status(struct edgeport_serial *edge_serial,
232static void handle_new_lsr (struct edgeport_port *edge_port, __u8 lsrData, __u8 lsr, __u8 data); 239 __u8 byte2, __u8 byte3);
233static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u8 param); 240static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
234static int calc_baud_rate_divisor (int baud_rate, int *divisor); 241 unsigned char *data, int length);
235static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRate); 242static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr);
236static void change_port_settings (struct edgeport_port *edge_port, struct ktermios *old_termios); 243static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData,
237static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 regNum, __u8 regValue); 244 __u8 lsr, __u8 data);
238static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer, int writeLength); 245static int send_iosp_ext_cmd(struct edgeport_port *edge_port, __u8 command,
239static void send_more_port_data (struct edgeport_serial *edge_serial, struct edgeport_port *edge_port); 246 __u8 param);
240 247static int calc_baud_rate_divisor(int baud_rate, int *divisor);
241static int sram_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data); 248static int send_cmd_write_baud_rate(struct edgeport_port *edge_port,
242static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data); 249 int baudRate);
243static int rom_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data); 250static void change_port_settings(struct tty_struct *tty,
244static void get_manufacturing_desc (struct edgeport_serial *edge_serial); 251 struct edgeport_port *edge_port,
245static void get_boot_desc (struct edgeport_serial *edge_serial); 252 struct ktermios *old_termios);
246static void load_application_firmware (struct edgeport_serial *edge_serial); 253static int send_cmd_write_uart_register(struct edgeport_port *edge_port,
247 254 __u8 regNum, __u8 regValue);
248static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unicode_size); 255static int write_cmd_usb(struct edgeport_port *edge_port,
249 256 unsigned char *buffer, int writeLength);
250 257static void send_more_port_data(struct edgeport_serial *edge_serial,
251// ************************************************************************ 258 struct edgeport_port *edge_port);
252// ************************************************************************ 259
253// ************************************************************************ 260static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
254// ************************************************************************ 261 __u16 length, const __u8 *data);
262static int rom_read(struct usb_serial *serial, __u16 extAddr, __u16 addr,
263 __u16 length, __u8 *data);
264static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
265 __u16 length, const __u8 *data);
266static void get_manufacturing_desc(struct edgeport_serial *edge_serial);
267static void get_boot_desc(struct edgeport_serial *edge_serial);
268static void load_application_firmware(struct edgeport_serial *edge_serial);
269
270static void unicode_to_ascii(char *string, int buflen,
271 __le16 *unicode, int unicode_size);
272
273
274/* ************************************************************************ */
275/* ************************************************************************ */
276/* ************************************************************************ */
277/* ************************************************************************ */
255 278
256/************************************************************************ 279/************************************************************************
257 * * 280 * *
@@ -261,7 +284,7 @@ static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unic
261 * embedded in this driver * 284 * embedded in this driver *
262 * * 285 * *
263 ************************************************************************/ 286 ************************************************************************/
264static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial) 287static void update_edgeport_E2PROM(struct edgeport_serial *edge_serial)
265{ 288{
266 __u32 BootCurVer; 289 __u32 BootCurVer;
267 __u32 BootNewVer; 290 __u32 BootNewVer;
@@ -275,16 +298,14 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial)
275 int response; 298 int response;
276 299
277 switch (edge_serial->product_info.iDownloadFile) { 300 switch (edge_serial->product_info.iDownloadFile) {
278 case EDGE_DOWNLOAD_FILE_I930: 301 case EDGE_DOWNLOAD_FILE_I930:
279 fw_name = "edgeport/boot.fw"; 302 fw_name = "edgeport/boot.fw";
280 break; 303 break;
281 304 case EDGE_DOWNLOAD_FILE_80251:
282 case EDGE_DOWNLOAD_FILE_80251: 305 fw_name = "edgeport/boot2.fw";
283 fw_name = "edgeport/boot2.fw"; 306 break;
284 break; 307 default:
285 308 return;
286 default:
287 return;
288 } 309 }
289 310
290 response = request_ihex_firmware(&fw, fw_name, 311 response = request_ihex_firmware(&fw, fw_name,
@@ -300,7 +321,7 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial)
300 BootMinorVersion = rec->data[1]; 321 BootMinorVersion = rec->data[1];
301 BootBuildNumber = (rec->data[2] << 8) | rec->data[3]; 322 BootBuildNumber = (rec->data[2] << 8) | rec->data[3];
302 323
303 // Check Boot Image Version 324 /* Check Boot Image Version */
304 BootCurVer = (edge_serial->boot_descriptor.MajorVersion << 24) + 325 BootCurVer = (edge_serial->boot_descriptor.MajorVersion << 24) +
305 (edge_serial->boot_descriptor.MinorVersion << 16) + 326 (edge_serial->boot_descriptor.MinorVersion << 16) +
306 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber); 327 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber);
@@ -352,29 +373,29 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial)
352 * Get string descriptor from device * 373 * Get string descriptor from device *
353 * * 374 * *
354 ************************************************************************/ 375 ************************************************************************/
355static int get_string (struct usb_device *dev, int Id, char *string, int buflen) 376static int get_string(struct usb_device *dev, int Id, char *string, int buflen)
356{ 377{
357 struct usb_string_descriptor StringDesc; 378 struct usb_string_descriptor StringDesc;
358 struct usb_string_descriptor *pStringDesc; 379 struct usb_string_descriptor *pStringDesc;
359 380
360 dbg("%s - USB String ID = %d", __func__, Id ); 381 dbg("%s - USB String ID = %d", __func__, Id);
361 382
362 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) { 383 if (!usb_get_descriptor(dev, USB_DT_STRING, Id,
384 &StringDesc, sizeof(StringDesc)))
363 return 0; 385 return 0;
364 }
365 386
366 pStringDesc = kmalloc (StringDesc.bLength, GFP_KERNEL); 387 pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL);
367 388 if (!pStringDesc)
368 if (!pStringDesc) {
369 return 0; 389 return 0;
370 }
371 390
372 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc, StringDesc.bLength )) { 391 if (!usb_get_descriptor(dev, USB_DT_STRING, Id,
392 pStringDesc, StringDesc.bLength)) {
373 kfree(pStringDesc); 393 kfree(pStringDesc);
374 return 0; 394 return 0;
375 } 395 }
376 396
377 unicode_to_ascii(string, buflen, pStringDesc->wData, pStringDesc->bLength/2); 397 unicode_to_ascii(string, buflen,
398 pStringDesc->wData, pStringDesc->bLength/2);
378 399
379 kfree(pStringDesc); 400 kfree(pStringDesc);
380 dbg("%s - USB String %s", __func__, string); 401 dbg("%s - USB String %s", __func__, string);
@@ -388,24 +409,24 @@ static int get_string (struct usb_device *dev, int Id, char *string, int buflen)
388 * Get string descriptor from device 409 * Get string descriptor from device
389 * 410 *
390 ************************************************************************/ 411 ************************************************************************/
391static int get_string_desc (struct usb_device *dev, int Id, struct usb_string_descriptor **pRetDesc) 412static int get_string_desc(struct usb_device *dev, int Id,
413 struct usb_string_descriptor **pRetDesc)
392{ 414{
393 struct usb_string_descriptor StringDesc; 415 struct usb_string_descriptor StringDesc;
394 struct usb_string_descriptor *pStringDesc; 416 struct usb_string_descriptor *pStringDesc;
395 417
396 dbg("%s - USB String ID = %d", __func__, Id ); 418 dbg("%s - USB String ID = %d", __func__, Id);
397 419
398 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) { 420 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc,
421 sizeof(StringDesc)))
399 return 0; 422 return 0;
400 }
401 423
402 pStringDesc = kmalloc (StringDesc.bLength, GFP_KERNEL); 424 pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL);
403 425 if (!pStringDesc)
404 if (!pStringDesc) {
405 return -1; 426 return -1;
406 }
407 427
408 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc, StringDesc.bLength )) { 428 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc,
429 StringDesc.bLength)) {
409 kfree(pStringDesc); 430 kfree(pStringDesc);
410 return -1; 431 return -1;
411 } 432 }
@@ -417,25 +438,30 @@ static int get_string_desc (struct usb_device *dev, int Id, struct usb_string_de
417 438
418static void dump_product_info(struct edgeport_product_info *product_info) 439static void dump_product_info(struct edgeport_product_info *product_info)
419{ 440{
420 // Dump Product Info structure 441 /* Dump Product Info structure */
421 dbg("**Product Information:"); 442 dbg("**Product Information:");
422 dbg(" ProductId %x", product_info->ProductId ); 443 dbg(" ProductId %x", product_info->ProductId);
423 dbg(" NumPorts %d", product_info->NumPorts ); 444 dbg(" NumPorts %d", product_info->NumPorts);
424 dbg(" ProdInfoVer %d", product_info->ProdInfoVer ); 445 dbg(" ProdInfoVer %d", product_info->ProdInfoVer);
425 dbg(" IsServer %d", product_info->IsServer); 446 dbg(" IsServer %d", product_info->IsServer);
426 dbg(" IsRS232 %d", product_info->IsRS232 ); 447 dbg(" IsRS232 %d", product_info->IsRS232);
427 dbg(" IsRS422 %d", product_info->IsRS422 ); 448 dbg(" IsRS422 %d", product_info->IsRS422);
428 dbg(" IsRS485 %d", product_info->IsRS485 ); 449 dbg(" IsRS485 %d", product_info->IsRS485);
429 dbg(" RomSize %d", product_info->RomSize ); 450 dbg(" RomSize %d", product_info->RomSize);
430 dbg(" RamSize %d", product_info->RamSize ); 451 dbg(" RamSize %d", product_info->RamSize);
431 dbg(" CpuRev %x", product_info->CpuRev ); 452 dbg(" CpuRev %x", product_info->CpuRev);
432 dbg(" BoardRev %x", product_info->BoardRev); 453 dbg(" BoardRev %x", product_info->BoardRev);
433 dbg(" BootMajorVersion %d.%d.%d", product_info->BootMajorVersion, 454 dbg(" BootMajorVersion %d.%d.%d", product_info->BootMajorVersion,
434 product_info->BootMinorVersion, 455 product_info->BootMinorVersion,
435 le16_to_cpu(product_info->BootBuildNumber)); 456 le16_to_cpu(product_info->BootBuildNumber));
436 dbg(" ManufactureDescDate %d/%d/%d", product_info->ManufactureDescDate[0], 457 dbg(" FirmwareMajorVersion %d.%d.%d",
437 product_info->ManufactureDescDate[1], 458 product_info->FirmwareMajorVersion,
438 product_info->ManufactureDescDate[2]+1900); 459 product_info->FirmwareMinorVersion,
460 le16_to_cpu(product_info->FirmwareBuildNumber));
461 dbg(" ManufactureDescDate %d/%d/%d",
462 product_info->ManufactureDescDate[0],
463 product_info->ManufactureDescDate[1],
464 product_info->ManufactureDescDate[2]+1900);
439 dbg(" iDownloadFile 0x%x", product_info->iDownloadFile); 465 dbg(" iDownloadFile 0x%x", product_info->iDownloadFile);
440 dbg(" EpicVer %d", product_info->EpicVer); 466 dbg(" EpicVer %d", product_info->EpicVer);
441} 467}
@@ -444,55 +470,60 @@ static void get_product_info(struct edgeport_serial *edge_serial)
444{ 470{
445 struct edgeport_product_info *product_info = &edge_serial->product_info; 471 struct edgeport_product_info *product_info = &edge_serial->product_info;
446 472
447 memset (product_info, 0, sizeof(struct edgeport_product_info)); 473 memset(product_info, 0, sizeof(struct edgeport_product_info));
448 474
449 product_info->ProductId = (__u16)(le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ~ION_DEVICE_ID_80251_NETCHIP); 475 product_info->ProductId = (__u16)(le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ~ION_DEVICE_ID_80251_NETCHIP);
450 product_info->NumPorts = edge_serial->manuf_descriptor.NumPorts; 476 product_info->NumPorts = edge_serial->manuf_descriptor.NumPorts;
451 product_info->ProdInfoVer = 0; 477 product_info->ProdInfoVer = 0;
452 478
453 product_info->RomSize = edge_serial->manuf_descriptor.RomSize; 479 product_info->RomSize = edge_serial->manuf_descriptor.RomSize;
454 product_info->RamSize = edge_serial->manuf_descriptor.RamSize; 480 product_info->RamSize = edge_serial->manuf_descriptor.RamSize;
455 product_info->CpuRev = edge_serial->manuf_descriptor.CpuRev; 481 product_info->CpuRev = edge_serial->manuf_descriptor.CpuRev;
456 product_info->BoardRev = edge_serial->manuf_descriptor.BoardRev; 482 product_info->BoardRev = edge_serial->manuf_descriptor.BoardRev;
457 483
458 product_info->BootMajorVersion = edge_serial->boot_descriptor.MajorVersion; 484 product_info->BootMajorVersion =
459 product_info->BootMinorVersion = edge_serial->boot_descriptor.MinorVersion; 485 edge_serial->boot_descriptor.MajorVersion;
460 product_info->BootBuildNumber = edge_serial->boot_descriptor.BuildNumber; 486 product_info->BootMinorVersion =
461 487 edge_serial->boot_descriptor.MinorVersion;
462 memcpy(product_info->ManufactureDescDate, edge_serial->manuf_descriptor.DescDate, sizeof(edge_serial->manuf_descriptor.DescDate)); 488 product_info->BootBuildNumber =
463 489 edge_serial->boot_descriptor.BuildNumber;
464 // check if this is 2nd generation hardware 490
465 if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ION_DEVICE_ID_80251_NETCHIP) { 491 memcpy(product_info->ManufactureDescDate,
466 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251; 492 edge_serial->manuf_descriptor.DescDate,
467 } else { 493 sizeof(edge_serial->manuf_descriptor.DescDate));
468 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930; 494
469 } 495 /* check if this is 2nd generation hardware */
470 496 if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct)
471 // Determine Product type and set appropriate flags 497 & ION_DEVICE_ID_80251_NETCHIP)
498 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251;
499 else
500 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930;
501
502 /* Determine Product type and set appropriate flags */
472 switch (DEVICE_ID_FROM_USB_PRODUCT_ID(product_info->ProductId)) { 503 switch (DEVICE_ID_FROM_USB_PRODUCT_ID(product_info->ProductId)) {
473 case ION_DEVICE_ID_EDGEPORT_COMPATIBLE: 504 case ION_DEVICE_ID_EDGEPORT_COMPATIBLE:
474 case ION_DEVICE_ID_EDGEPORT_4T: 505 case ION_DEVICE_ID_EDGEPORT_4T:
475 case ION_DEVICE_ID_EDGEPORT_4: 506 case ION_DEVICE_ID_EDGEPORT_4:
476 case ION_DEVICE_ID_EDGEPORT_2: 507 case ION_DEVICE_ID_EDGEPORT_2:
477 case ION_DEVICE_ID_EDGEPORT_8_DUAL_CPU: 508 case ION_DEVICE_ID_EDGEPORT_8_DUAL_CPU:
478 case ION_DEVICE_ID_EDGEPORT_8: 509 case ION_DEVICE_ID_EDGEPORT_8:
479 case ION_DEVICE_ID_EDGEPORT_421: 510 case ION_DEVICE_ID_EDGEPORT_421:
480 case ION_DEVICE_ID_EDGEPORT_21: 511 case ION_DEVICE_ID_EDGEPORT_21:
481 case ION_DEVICE_ID_EDGEPORT_2_DIN: 512 case ION_DEVICE_ID_EDGEPORT_2_DIN:
482 case ION_DEVICE_ID_EDGEPORT_4_DIN: 513 case ION_DEVICE_ID_EDGEPORT_4_DIN:
483 case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU: 514 case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU:
484 product_info->IsRS232 = 1; 515 product_info->IsRS232 = 1;
485 break; 516 break;
486 517
487 case ION_DEVICE_ID_EDGEPORT_2I: // Edgeport/2 RS422/RS485 518 case ION_DEVICE_ID_EDGEPORT_2I: /* Edgeport/2 RS422/RS485 */
488 product_info->IsRS422 = 1; 519 product_info->IsRS422 = 1;
489 product_info->IsRS485 = 1; 520 product_info->IsRS485 = 1;
490 break; 521 break;
491 522
492 case ION_DEVICE_ID_EDGEPORT_8I: // Edgeport/4 RS422 523 case ION_DEVICE_ID_EDGEPORT_8I: /* Edgeport/4 RS422 */
493 case ION_DEVICE_ID_EDGEPORT_4I: // Edgeport/4 RS422 524 case ION_DEVICE_ID_EDGEPORT_4I: /* Edgeport/4 RS422 */
494 product_info->IsRS422 = 1; 525 product_info->IsRS422 = 1;
495 break; 526 break;
496 } 527 }
497 528
498 dump_product_info(product_info); 529 dump_product_info(product_info);
@@ -520,32 +551,32 @@ static int get_epic_descriptor(struct edgeport_serial *ep)
520 ep->is_epic = 1; 551 ep->is_epic = 1;
521 memset(product_info, 0, sizeof(struct edgeport_product_info)); 552 memset(product_info, 0, sizeof(struct edgeport_product_info));
522 553
523 product_info->NumPorts = epic->NumPorts; 554 product_info->NumPorts = epic->NumPorts;
524 product_info->ProdInfoVer = 0; 555 product_info->ProdInfoVer = 0;
525 product_info->FirmwareMajorVersion = epic->MajorVersion; 556 product_info->FirmwareMajorVersion = epic->MajorVersion;
526 product_info->FirmwareMinorVersion = epic->MinorVersion; 557 product_info->FirmwareMinorVersion = epic->MinorVersion;
527 product_info->FirmwareBuildNumber = epic->BuildNumber; 558 product_info->FirmwareBuildNumber = epic->BuildNumber;
528 product_info->iDownloadFile = epic->iDownloadFile; 559 product_info->iDownloadFile = epic->iDownloadFile;
529 product_info->EpicVer = epic->EpicVer; 560 product_info->EpicVer = epic->EpicVer;
530 product_info->Epic = epic->Supports; 561 product_info->Epic = epic->Supports;
531 product_info->ProductId = ION_DEVICE_ID_EDGEPORT_COMPATIBLE; 562 product_info->ProductId = ION_DEVICE_ID_EDGEPORT_COMPATIBLE;
532 dump_product_info(product_info); 563 dump_product_info(product_info);
533 564
534 bits = &ep->epic_descriptor.Supports; 565 bits = &ep->epic_descriptor.Supports;
535 dbg("**EPIC descriptor:"); 566 dbg("**EPIC descriptor:");
536 dbg(" VendEnableSuspend: %s", bits->VendEnableSuspend ? "TRUE": "FALSE"); 567 dbg(" VendEnableSuspend: %s", bits->VendEnableSuspend ? "TRUE": "FALSE");
537 dbg(" IOSPOpen : %s", bits->IOSPOpen ? "TRUE": "FALSE" ); 568 dbg(" IOSPOpen : %s", bits->IOSPOpen ? "TRUE": "FALSE");
538 dbg(" IOSPClose : %s", bits->IOSPClose ? "TRUE": "FALSE" ); 569 dbg(" IOSPClose : %s", bits->IOSPClose ? "TRUE": "FALSE");
539 dbg(" IOSPChase : %s", bits->IOSPChase ? "TRUE": "FALSE" ); 570 dbg(" IOSPChase : %s", bits->IOSPChase ? "TRUE": "FALSE");
540 dbg(" IOSPSetRxFlow : %s", bits->IOSPSetRxFlow ? "TRUE": "FALSE" ); 571 dbg(" IOSPSetRxFlow : %s", bits->IOSPSetRxFlow ? "TRUE": "FALSE");
541 dbg(" IOSPSetTxFlow : %s", bits->IOSPSetTxFlow ? "TRUE": "FALSE" ); 572 dbg(" IOSPSetTxFlow : %s", bits->IOSPSetTxFlow ? "TRUE": "FALSE");
542 dbg(" IOSPSetXChar : %s", bits->IOSPSetXChar ? "TRUE": "FALSE" ); 573 dbg(" IOSPSetXChar : %s", bits->IOSPSetXChar ? "TRUE": "FALSE");
543 dbg(" IOSPRxCheck : %s", bits->IOSPRxCheck ? "TRUE": "FALSE" ); 574 dbg(" IOSPRxCheck : %s", bits->IOSPRxCheck ? "TRUE": "FALSE");
544 dbg(" IOSPSetClrBreak : %s", bits->IOSPSetClrBreak ? "TRUE": "FALSE" ); 575 dbg(" IOSPSetClrBreak : %s", bits->IOSPSetClrBreak ? "TRUE": "FALSE");
545 dbg(" IOSPWriteMCR : %s", bits->IOSPWriteMCR ? "TRUE": "FALSE" ); 576 dbg(" IOSPWriteMCR : %s", bits->IOSPWriteMCR ? "TRUE": "FALSE");
546 dbg(" IOSPWriteLCR : %s", bits->IOSPWriteLCR ? "TRUE": "FALSE" ); 577 dbg(" IOSPWriteLCR : %s", bits->IOSPWriteLCR ? "TRUE": "FALSE");
547 dbg(" IOSPSetBaudRate : %s", bits->IOSPSetBaudRate ? "TRUE": "FALSE" ); 578 dbg(" IOSPSetBaudRate : %s", bits->IOSPSetBaudRate ? "TRUE": "FALSE");
548 dbg(" TrueEdgeport : %s", bits->TrueEdgeport ? "TRUE": "FALSE" ); 579 dbg(" TrueEdgeport : %s", bits->TrueEdgeport ? "TRUE": "FALSE");
549 } 580 }
550 581
551 return result; 582 return result;
@@ -561,10 +592,10 @@ static int get_epic_descriptor(struct edgeport_serial *ep)
561 592
562/***************************************************************************** 593/*****************************************************************************
563 * edge_interrupt_callback 594 * edge_interrupt_callback
564 * this is the callback function for when we have received data on the 595 * this is the callback function for when we have received data on the
565 * interrupt endpoint. 596 * interrupt endpoint.
566 *****************************************************************************/ 597 *****************************************************************************/
567static void edge_interrupt_callback (struct urb *urb) 598static void edge_interrupt_callback(struct urb *urb)
568{ 599{
569 struct edgeport_serial *edge_serial = urb->context; 600 struct edgeport_serial *edge_serial = urb->context;
570 struct edgeport_port *edge_port; 601 struct edgeport_port *edge_port;
@@ -589,17 +620,17 @@ static void edge_interrupt_callback (struct urb *urb)
589 case -ESHUTDOWN: 620 case -ESHUTDOWN:
590 /* this urb is terminated, clean up */ 621 /* this urb is terminated, clean up */
591 dbg("%s - urb shutting down with status: %d", 622 dbg("%s - urb shutting down with status: %d",
592 __func__, status); 623 __func__, status);
593 return; 624 return;
594 default: 625 default:
595 dbg("%s - nonzero urb status received: %d", 626 dbg("%s - nonzero urb status received: %d", __func__, status);
596 __func__, status);
597 goto exit; 627 goto exit;
598 } 628 }
599 629
600 // process this interrupt-read even if there are no ports open 630 /* process this interrupt-read even if there are no ports open */
601 if (length) { 631 if (length) {
602 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, length, data); 632 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev,
633 __func__, length, data);
603 634
604 if (length > 1) { 635 if (length > 1) {
605 bytes_avail = data[0] | (data[1] << 8); 636 bytes_avail = data[0] | (data[1] << 8);
@@ -613,7 +644,8 @@ static void edge_interrupt_callback (struct urb *urb)
613 dbg("%s - posting a read", __func__); 644 dbg("%s - posting a read", __func__);
614 edge_serial->read_in_progress = true; 645 edge_serial->read_in_progress = true;
615 646
616 /* we have pending bytes on the bulk in pipe, send a request */ 647 /* we have pending bytes on the
648 bulk in pipe, send a request */
617 edge_serial->read_urb->dev = edge_serial->serial->dev; 649 edge_serial->read_urb->dev = edge_serial->serial->dev;
618 result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); 650 result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC);
619 if (result) { 651 if (result) {
@@ -627,7 +659,8 @@ static void edge_interrupt_callback (struct urb *urb)
627 /* grab the txcredits for the ports if available */ 659 /* grab the txcredits for the ports if available */
628 position = 2; 660 position = 2;
629 portNumber = 0; 661 portNumber = 0;
630 while ((position < length) && (portNumber < edge_serial->serial->num_ports)) { 662 while ((position < length) &&
663 (portNumber < edge_serial->serial->num_ports)) {
631 txCredits = data[position] | (data[position+1] << 8); 664 txCredits = data[position] | (data[position+1] << 8);
632 if (txCredits) { 665 if (txCredits) {
633 port = edge_serial->serial->port[portNumber]; 666 port = edge_serial->serial->port[portNumber];
@@ -636,14 +669,19 @@ static void edge_interrupt_callback (struct urb *urb)
636 spin_lock(&edge_port->ep_lock); 669 spin_lock(&edge_port->ep_lock);
637 edge_port->txCredits += txCredits; 670 edge_port->txCredits += txCredits;
638 spin_unlock(&edge_port->ep_lock); 671 spin_unlock(&edge_port->ep_lock);
639 dbg("%s - txcredits for port%d = %d", __func__, portNumber, edge_port->txCredits); 672 dbg("%s - txcredits for port%d = %d",
640 673 __func__, portNumber,
641 /* tell the tty driver that something has changed */ 674 edge_port->txCredits);
642 if (edge_port->port->tty) 675
643 tty_wakeup(edge_port->port->tty); 676 /* tell the tty driver that something
644 677 has changed */
645 // Since we have more credit, check if more data can be sent 678 if (edge_port->port->port.tty)
646 send_more_port_data(edge_serial, edge_port); 679 tty_wakeup(edge_port->port->port.tty);
680
681 /* Since we have more credit, check
682 if more data can be sent */
683 send_more_port_data(edge_serial,
684 edge_port);
647 } 685 }
648 } 686 }
649 position += 2; 687 position += 2;
@@ -652,19 +690,20 @@ static void edge_interrupt_callback (struct urb *urb)
652 } 690 }
653 691
654exit: 692exit:
655 result = usb_submit_urb (urb, GFP_ATOMIC); 693 result = usb_submit_urb(urb, GFP_ATOMIC);
656 if (result) { 694 if (result)
657 dev_err(&urb->dev->dev, "%s - Error %d submitting control urb\n", __func__, result); 695 dev_err(&urb->dev->dev,
658 } 696 "%s - Error %d submitting control urb\n",
697 __func__, result);
659} 698}
660 699
661 700
662/***************************************************************************** 701/*****************************************************************************
663 * edge_bulk_in_callback 702 * edge_bulk_in_callback
664 * this is the callback function for when we have received data on the 703 * this is the callback function for when we have received data on the
665 * bulk in endpoint. 704 * bulk in endpoint.
666 *****************************************************************************/ 705 *****************************************************************************/
667static void edge_bulk_in_callback (struct urb *urb) 706static void edge_bulk_in_callback(struct urb *urb)
668{ 707{
669 struct edgeport_serial *edge_serial = urb->context; 708 struct edgeport_serial *edge_serial = urb->context;
670 unsigned char *data = urb->transfer_buffer; 709 unsigned char *data = urb->transfer_buffer;
@@ -689,16 +728,18 @@ static void edge_bulk_in_callback (struct urb *urb)
689 728
690 raw_data_length = urb->actual_length; 729 raw_data_length = urb->actual_length;
691 730
692 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, raw_data_length, data); 731 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev,
732 __func__, raw_data_length, data);
693 733
694 spin_lock(&edge_serial->es_lock); 734 spin_lock(&edge_serial->es_lock);
695 735
696 /* decrement our rxBytes available by the number that we just got */ 736 /* decrement our rxBytes available by the number that we just got */
697 edge_serial->rxBytesAvail -= raw_data_length; 737 edge_serial->rxBytesAvail -= raw_data_length;
698 738
699 dbg("%s - Received = %d, rxBytesAvail %d", __func__, raw_data_length, edge_serial->rxBytesAvail); 739 dbg("%s - Received = %d, rxBytesAvail %d", __func__,
740 raw_data_length, edge_serial->rxBytesAvail);
700 741
701 process_rcvd_data (edge_serial, data, urb->actual_length); 742 process_rcvd_data(edge_serial, data, urb->actual_length);
702 743
703 /* check to see if there's any more data for us to read */ 744 /* check to see if there's any more data for us to read */
704 if (edge_serial->rxBytesAvail > 0) { 745 if (edge_serial->rxBytesAvail > 0) {
@@ -721,10 +762,10 @@ static void edge_bulk_in_callback (struct urb *urb)
721 762
722/***************************************************************************** 763/*****************************************************************************
723 * edge_bulk_out_data_callback 764 * edge_bulk_out_data_callback
724 * this is the callback function for when we have finished sending serial data 765 * this is the callback function for when we have finished sending
725 * on the bulk out endpoint. 766 * serial data on the bulk out endpoint.
726 *****************************************************************************/ 767 *****************************************************************************/
727static void edge_bulk_out_data_callback (struct urb *urb) 768static void edge_bulk_out_data_callback(struct urb *urb)
728{ 769{
729 struct edgeport_port *edge_port = urb->context; 770 struct edgeport_port *edge_port = urb->context;
730 struct tty_struct *tty; 771 struct tty_struct *tty;
@@ -737,27 +778,29 @@ static void edge_bulk_out_data_callback (struct urb *urb)
737 __func__, status); 778 __func__, status);
738 } 779 }
739 780
740 tty = edge_port->port->tty; 781 tty = edge_port->port->port.tty;
741 782
742 if (tty && edge_port->open) { 783 if (tty && edge_port->open) {
743 /* let the tty driver wakeup if it has a special write_wakeup function */ 784 /* let the tty driver wakeup if it has a special
785 write_wakeup function */
744 tty_wakeup(tty); 786 tty_wakeup(tty);
745 } 787 }
746 788
747 // Release the Write URB 789 /* Release the Write URB */
748 edge_port->write_in_progress = false; 790 edge_port->write_in_progress = false;
749 791
750 // Check if more data needs to be sent 792 /* Check if more data needs to be sent */
751 send_more_port_data((struct edgeport_serial *)(usb_get_serial_data(edge_port->port->serial)), edge_port); 793 send_more_port_data((struct edgeport_serial *)
794 (usb_get_serial_data(edge_port->port->serial)), edge_port);
752} 795}
753 796
754 797
755/***************************************************************************** 798/*****************************************************************************
756 * BulkOutCmdCallback 799 * BulkOutCmdCallback
757 * this is the callback function for when we have finished sending a command 800 * this is the callback function for when we have finished sending a
758 * on the bulk out endpoint. 801 * command on the bulk out endpoint.
759 *****************************************************************************/ 802 *****************************************************************************/
760static void edge_bulk_out_cmd_callback (struct urb *urb) 803static void edge_bulk_out_cmd_callback(struct urb *urb)
761{ 804{
762 struct edgeport_port *edge_port = urb->context; 805 struct edgeport_port *edge_port = urb->context;
763 struct tty_struct *tty; 806 struct tty_struct *tty;
@@ -766,22 +809,24 @@ static void edge_bulk_out_cmd_callback (struct urb *urb)
766 dbg("%s", __func__); 809 dbg("%s", __func__);
767 810
768 atomic_dec(&CmdUrbs); 811 atomic_dec(&CmdUrbs);
769 dbg("%s - FREE URB %p (outstanding %d)", __func__, urb, atomic_read(&CmdUrbs)); 812 dbg("%s - FREE URB %p (outstanding %d)", __func__,
813 urb, atomic_read(&CmdUrbs));
770 814
771 815
772 /* clean up the transfer buffer */ 816 /* clean up the transfer buffer */
773 kfree(urb->transfer_buffer); 817 kfree(urb->transfer_buffer);
774 818
775 /* Free the command urb */ 819 /* Free the command urb */
776 usb_free_urb (urb); 820 usb_free_urb(urb);
777 821
778 if (status) { 822 if (status) {
779 dbg("%s - nonzero write bulk status received: %d", __func__, status); 823 dbg("%s - nonzero write bulk status received: %d",
824 __func__, status);
780 return; 825 return;
781 } 826 }
782 827
783 /* Get pointer to tty */ 828 /* Get pointer to tty */
784 tty = edge_port->port->tty; 829 tty = edge_port->port->port.tty;
785 830
786 /* tell the tty driver that something has changed */ 831 /* tell the tty driver that something has changed */
787 if (tty && edge_port->open) 832 if (tty && edge_port->open)
@@ -803,7 +848,8 @@ static void edge_bulk_out_cmd_callback (struct urb *urb)
803 * If successful, we return 0 848 * If successful, we return 0
804 * Otherwise we return a negative error number. 849 * Otherwise we return a negative error number.
805 *****************************************************************************/ 850 *****************************************************************************/
806static int edge_open (struct usb_serial_port *port, struct file * filp) 851static int edge_open(struct tty_struct *tty,
852 struct usb_serial_port *port, struct file *filp)
807{ 853{
808 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 854 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
809 struct usb_serial *serial; 855 struct usb_serial *serial;
@@ -815,55 +861,62 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
815 if (edge_port == NULL) 861 if (edge_port == NULL)
816 return -ENODEV; 862 return -ENODEV;
817 863
818 if (port->tty) 864 if (tty)
819 port->tty->low_latency = low_latency; 865 tty->low_latency = low_latency;
820 866
821 /* see if we've set up our endpoint info yet (can't set it up in edge_startup 867 /* see if we've set up our endpoint info yet (can't set it up
822 as the structures were not set up at that time.) */ 868 in edge_startup as the structures were not set up at that time.) */
823 serial = port->serial; 869 serial = port->serial;
824 edge_serial = usb_get_serial_data(serial); 870 edge_serial = usb_get_serial_data(serial);
825 if (edge_serial == NULL) { 871 if (edge_serial == NULL)
826 return -ENODEV; 872 return -ENODEV;
827 }
828 if (edge_serial->interrupt_in_buffer == NULL) { 873 if (edge_serial->interrupt_in_buffer == NULL) {
829 struct usb_serial_port *port0 = serial->port[0]; 874 struct usb_serial_port *port0 = serial->port[0];
830 875
831 /* not set up yet, so do it now */ 876 /* not set up yet, so do it now */
832 edge_serial->interrupt_in_buffer = port0->interrupt_in_buffer; 877 edge_serial->interrupt_in_buffer =
833 edge_serial->interrupt_in_endpoint = port0->interrupt_in_endpointAddress; 878 port0->interrupt_in_buffer;
879 edge_serial->interrupt_in_endpoint =
880 port0->interrupt_in_endpointAddress;
834 edge_serial->interrupt_read_urb = port0->interrupt_in_urb; 881 edge_serial->interrupt_read_urb = port0->interrupt_in_urb;
835 edge_serial->bulk_in_buffer = port0->bulk_in_buffer; 882 edge_serial->bulk_in_buffer = port0->bulk_in_buffer;
836 edge_serial->bulk_in_endpoint = port0->bulk_in_endpointAddress; 883 edge_serial->bulk_in_endpoint =
884 port0->bulk_in_endpointAddress;
837 edge_serial->read_urb = port0->read_urb; 885 edge_serial->read_urb = port0->read_urb;
838 edge_serial->bulk_out_endpoint = port0->bulk_out_endpointAddress; 886 edge_serial->bulk_out_endpoint =
839 887 port0->bulk_out_endpointAddress;
888
840 /* set up our interrupt urb */ 889 /* set up our interrupt urb */
841 usb_fill_int_urb(edge_serial->interrupt_read_urb, 890 usb_fill_int_urb(edge_serial->interrupt_read_urb,
842 serial->dev, 891 serial->dev,
843 usb_rcvintpipe(serial->dev, 892 usb_rcvintpipe(serial->dev,
844 port0->interrupt_in_endpointAddress), 893 port0->interrupt_in_endpointAddress),
845 port0->interrupt_in_buffer, 894 port0->interrupt_in_buffer,
846 edge_serial->interrupt_read_urb->transfer_buffer_length, 895 edge_serial->interrupt_read_urb->transfer_buffer_length,
847 edge_interrupt_callback, edge_serial, 896 edge_interrupt_callback, edge_serial,
848 edge_serial->interrupt_read_urb->interval); 897 edge_serial->interrupt_read_urb->interval);
849 898
850 /* set up our bulk in urb */ 899 /* set up our bulk in urb */
851 usb_fill_bulk_urb(edge_serial->read_urb, serial->dev, 900 usb_fill_bulk_urb(edge_serial->read_urb, serial->dev,
852 usb_rcvbulkpipe(serial->dev, 901 usb_rcvbulkpipe(serial->dev,
853 port0->bulk_in_endpointAddress), 902 port0->bulk_in_endpointAddress),
854 port0->bulk_in_buffer, 903 port0->bulk_in_buffer,
855 edge_serial->read_urb->transfer_buffer_length, 904 edge_serial->read_urb->transfer_buffer_length,
856 edge_bulk_in_callback, edge_serial); 905 edge_bulk_in_callback, edge_serial);
857 edge_serial->read_in_progress = false; 906 edge_serial->read_in_progress = false;
858 907
859 /* start interrupt read for this edgeport 908 /* start interrupt read for this edgeport
860 * this interrupt will continue as long as the edgeport is connected */ 909 * this interrupt will continue as long
861 response = usb_submit_urb (edge_serial->interrupt_read_urb, GFP_KERNEL); 910 * as the edgeport is connected */
911 response = usb_submit_urb(edge_serial->interrupt_read_urb,
912 GFP_KERNEL);
862 if (response) { 913 if (response) {
863 dev_err(&port->dev, "%s - Error %d submitting control urb\n", __func__, response); 914 dev_err(&port->dev,
915 "%s - Error %d submitting control urb\n",
916 __func__, response);
864 } 917 }
865 } 918 }
866 919
867 /* initialize our wait queues */ 920 /* initialize our wait queues */
868 init_waitqueue_head(&edge_port->wait_open); 921 init_waitqueue_head(&edge_port->wait_open);
869 init_waitqueue_head(&edge_port->wait_chase); 922 init_waitqueue_head(&edge_port->wait_chase);
@@ -871,26 +924,29 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
871 init_waitqueue_head(&edge_port->wait_command); 924 init_waitqueue_head(&edge_port->wait_command);
872 925
873 /* initialize our icount structure */ 926 /* initialize our icount structure */
874 memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount)); 927 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
875 928
876 /* initialize our port settings */ 929 /* initialize our port settings */
877 edge_port->txCredits = 0; /* Can't send any data yet */ 930 edge_port->txCredits = 0; /* Can't send any data yet */
878 edge_port->shadowMCR = MCR_MASTER_IE; /* Must always set this bit to enable ints! */ 931 /* Must always set this bit to enable ints! */
932 edge_port->shadowMCR = MCR_MASTER_IE;
879 edge_port->chaseResponsePending = false; 933 edge_port->chaseResponsePending = false;
880 934
881 /* send a open port command */ 935 /* send a open port command */
882 edge_port->openPending = true; 936 edge_port->openPending = true;
883 edge_port->open = false; 937 edge_port->open = false;
884 response = send_iosp_ext_cmd (edge_port, IOSP_CMD_OPEN_PORT, 0); 938 response = send_iosp_ext_cmd(edge_port, IOSP_CMD_OPEN_PORT, 0);
885 939
886 if (response < 0) { 940 if (response < 0) {
887 dev_err(&port->dev, "%s - error sending open port command\n", __func__); 941 dev_err(&port->dev, "%s - error sending open port command\n",
942 __func__);
888 edge_port->openPending = false; 943 edge_port->openPending = false;
889 return -ENODEV; 944 return -ENODEV;
890 } 945 }
891 946
892 /* now wait for the port to be completely opened */ 947 /* now wait for the port to be completely opened */
893 wait_event_timeout(edge_port->wait_open, !edge_port->openPending, OPEN_TIMEOUT); 948 wait_event_timeout(edge_port->wait_open, !edge_port->openPending,
949 OPEN_TIMEOUT);
894 950
895 if (!edge_port->open) { 951 if (!edge_port->open) {
896 /* open timed out */ 952 /* open timed out */
@@ -904,25 +960,26 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
904 edge_port->txfifo.tail = 0; 960 edge_port->txfifo.tail = 0;
905 edge_port->txfifo.count = 0; 961 edge_port->txfifo.count = 0;
906 edge_port->txfifo.size = edge_port->maxTxCredits; 962 edge_port->txfifo.size = edge_port->maxTxCredits;
907 edge_port->txfifo.fifo = kmalloc (edge_port->maxTxCredits, GFP_KERNEL); 963 edge_port->txfifo.fifo = kmalloc(edge_port->maxTxCredits, GFP_KERNEL);
908 964
909 if (!edge_port->txfifo.fifo) { 965 if (!edge_port->txfifo.fifo) {
910 dbg("%s - no memory", __func__); 966 dbg("%s - no memory", __func__);
911 edge_close (port, filp); 967 edge_close(tty, port, filp);
912 return -ENOMEM; 968 return -ENOMEM;
913 } 969 }
914 970
915 /* Allocate a URB for the write */ 971 /* Allocate a URB for the write */
916 edge_port->write_urb = usb_alloc_urb (0, GFP_KERNEL); 972 edge_port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
917 edge_port->write_in_progress = false; 973 edge_port->write_in_progress = false;
918 974
919 if (!edge_port->write_urb) { 975 if (!edge_port->write_urb) {
920 dbg("%s - no memory", __func__); 976 dbg("%s - no memory", __func__);
921 edge_close (port, filp); 977 edge_close(tty, port, filp);
922 return -ENOMEM; 978 return -ENOMEM;
923 } 979 }
924 980
925 dbg("%s(%d) - Initialize TX fifo to %d bytes", __func__, port->number, edge_port->maxTxCredits); 981 dbg("%s(%d) - Initialize TX fifo to %d bytes",
982 __func__, port->number, edge_port->maxTxCredits);
926 983
927 dbg("%s exited", __func__); 984 dbg("%s exited", __func__);
928 985
@@ -948,27 +1005,28 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
948 int loop = 10; 1005 int loop = 10;
949 1006
950 while (1) { 1007 while (1) {
951 // Save Last credits 1008 /* Save Last credits */
952 lastCredits = edge_port->txCredits; 1009 lastCredits = edge_port->txCredits;
953 1010
954 // Did we get our Chase response 1011 /* Did we get our Chase response */
955 if (!edge_port->chaseResponsePending) { 1012 if (!edge_port->chaseResponsePending) {
956 dbg("%s - Got Chase Response", __func__); 1013 dbg("%s - Got Chase Response", __func__);
957 1014
958 // did we get all of our credit back? 1015 /* did we get all of our credit back? */
959 if (edge_port->txCredits == edge_port->maxTxCredits ) { 1016 if (edge_port->txCredits == edge_port->maxTxCredits) {
960 dbg("%s - Got all credits", __func__); 1017 dbg("%s - Got all credits", __func__);
961 return; 1018 return;
962 } 1019 }
963 } 1020 }
964 1021
965 // Block the thread for a while 1022 /* Block the thread for a while */
966 prepare_to_wait(&edge_port->wait_chase, &wait, TASK_UNINTERRUPTIBLE); 1023 prepare_to_wait(&edge_port->wait_chase, &wait,
1024 TASK_UNINTERRUPTIBLE);
967 schedule_timeout(timeout); 1025 schedule_timeout(timeout);
968 finish_wait(&edge_port->wait_chase, &wait); 1026 finish_wait(&edge_port->wait_chase, &wait);
969 1027
970 if (lastCredits == edge_port->txCredits) { 1028 if (lastCredits == edge_port->txCredits) {
971 // No activity.. count down. 1029 /* No activity.. count down. */
972 loop--; 1030 loop--;
973 if (loop == 0) { 1031 if (loop == 0) {
974 edge_port->chaseResponsePending = false; 1032 edge_port->chaseResponsePending = false;
@@ -976,8 +1034,9 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
976 return; 1034 return;
977 } 1035 }
978 } else { 1036 } else {
979 // Reset timeout value back to 10 seconds 1037 /* Reset timeout value back to 10 seconds */
980 dbg("%s - Last %d, Current %d", __func__, lastCredits, edge_port->txCredits); 1038 dbg("%s - Last %d, Current %d", __func__,
1039 lastCredits, edge_port->txCredits);
981 loop = 10; 1040 loop = 10;
982 } 1041 }
983 } 1042 }
@@ -994,7 +1053,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
994 * 3. A timeout of 3 seconds without activity has expired 1053 * 3. A timeout of 3 seconds without activity has expired
995 * 1054 *
996 ************************************************************************/ 1055 ************************************************************************/
997static void block_until_tx_empty (struct edgeport_port *edge_port) 1056static void block_until_tx_empty(struct edgeport_port *edge_port)
998{ 1057{
999 DEFINE_WAIT(wait); 1058 DEFINE_WAIT(wait);
1000 struct TxFifo *fifo = &edge_port->txfifo; 1059 struct TxFifo *fifo = &edge_port->txfifo;
@@ -1003,31 +1062,32 @@ static void block_until_tx_empty (struct edgeport_port *edge_port)
1003 int loop = 30; 1062 int loop = 30;
1004 1063
1005 while (1) { 1064 while (1) {
1006 // Save Last count 1065 /* Save Last count */
1007 lastCount = fifo->count; 1066 lastCount = fifo->count;
1008 1067
1009 // Is the Edgeport Buffer empty? 1068 /* Is the Edgeport Buffer empty? */
1010 if (lastCount == 0) { 1069 if (lastCount == 0) {
1011 dbg("%s - TX Buffer Empty", __func__); 1070 dbg("%s - TX Buffer Empty", __func__);
1012 return; 1071 return;
1013 } 1072 }
1014 1073
1015 // Block the thread for a while 1074 /* Block the thread for a while */
1016 prepare_to_wait (&edge_port->wait_chase, &wait, TASK_UNINTERRUPTIBLE); 1075 prepare_to_wait(&edge_port->wait_chase, &wait,
1076 TASK_UNINTERRUPTIBLE);
1017 schedule_timeout(timeout); 1077 schedule_timeout(timeout);
1018 finish_wait(&edge_port->wait_chase, &wait); 1078 finish_wait(&edge_port->wait_chase, &wait);
1019 1079
1020 dbg("%s wait", __func__); 1080 dbg("%s wait", __func__);
1021 1081
1022 if (lastCount == fifo->count) { 1082 if (lastCount == fifo->count) {
1023 // No activity.. count down. 1083 /* No activity.. count down. */
1024 loop--; 1084 loop--;
1025 if (loop == 0) { 1085 if (loop == 0) {
1026 dbg("%s - TIMEOUT", __func__); 1086 dbg("%s - TIMEOUT", __func__);
1027 return; 1087 return;
1028 } 1088 }
1029 } else { 1089 } else {
1030 // Reset timeout value back to seconds 1090 /* Reset timeout value back to seconds */
1031 loop = 30; 1091 loop = 30;
1032 } 1092 }
1033 } 1093 }
@@ -1038,20 +1098,21 @@ static void block_until_tx_empty (struct edgeport_port *edge_port)
1038 * edge_close 1098 * edge_close
1039 * this function is called by the tty driver when a port is closed 1099 * this function is called by the tty driver when a port is closed
1040 *****************************************************************************/ 1100 *****************************************************************************/
1041static void edge_close (struct usb_serial_port *port, struct file * filp) 1101static void edge_close(struct tty_struct *tty,
1102 struct usb_serial_port *port, struct file *filp)
1042{ 1103{
1043 struct edgeport_serial *edge_serial; 1104 struct edgeport_serial *edge_serial;
1044 struct edgeport_port *edge_port; 1105 struct edgeport_port *edge_port;
1045 int status; 1106 int status;
1046 1107
1047 dbg("%s - port %d", __func__, port->number); 1108 dbg("%s - port %d", __func__, port->number);
1048 1109
1049 edge_serial = usb_get_serial_data(port->serial); 1110 edge_serial = usb_get_serial_data(port->serial);
1050 edge_port = usb_get_serial_port_data(port); 1111 edge_port = usb_get_serial_port_data(port);
1051 if ((edge_serial == NULL) || (edge_port == NULL)) 1112 if (edge_serial == NULL || edge_port == NULL)
1052 return; 1113 return;
1053 1114
1054 // block until tx is empty 1115 /* block until tx is empty */
1055 block_until_tx_empty(edge_port); 1116 block_until_tx_empty(edge_port);
1056 1117
1057 edge_port->closePending = true; 1118 edge_port->closePending = true;
@@ -1063,13 +1124,12 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1063 edge_port->chaseResponsePending = true; 1124 edge_port->chaseResponsePending = true;
1064 1125
1065 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__); 1126 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__);
1066 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); 1127 status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0);
1067 if (status == 0) { 1128 if (status == 0)
1068 // block until chase finished 1129 /* block until chase finished */
1069 block_until_chase_response(edge_port); 1130 block_until_chase_response(edge_port);
1070 } else { 1131 else
1071 edge_port->chaseResponsePending = false; 1132 edge_port->chaseResponsePending = false;
1072 }
1073 } 1133 }
1074 1134
1075 if ((!edge_serial->is_epic) || 1135 if ((!edge_serial->is_epic) ||
@@ -1077,10 +1137,10 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1077 (edge_serial->epic_descriptor.Supports.IOSPClose))) { 1137 (edge_serial->epic_descriptor.Supports.IOSPClose))) {
1078 /* close the port */ 1138 /* close the port */
1079 dbg("%s - Sending IOSP_CMD_CLOSE_PORT", __func__); 1139 dbg("%s - Sending IOSP_CMD_CLOSE_PORT", __func__);
1080 send_iosp_ext_cmd (edge_port, IOSP_CMD_CLOSE_PORT, 0); 1140 send_iosp_ext_cmd(edge_port, IOSP_CMD_CLOSE_PORT, 0);
1081 } 1141 }
1082 1142
1083 //port->close = true; 1143 /* port->close = true; */
1084 edge_port->closePending = false; 1144 edge_port->closePending = false;
1085 edge_port->open = false; 1145 edge_port->open = false;
1086 edge_port->openPending = false; 1146 edge_port->openPending = false;
@@ -1088,7 +1148,8 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1088 usb_kill_urb(edge_port->write_urb); 1148 usb_kill_urb(edge_port->write_urb);
1089 1149
1090 if (edge_port->write_urb) { 1150 if (edge_port->write_urb) {
1091 /* if this urb had a transfer buffer already (old transfer) free it */ 1151 /* if this urb had a transfer buffer already
1152 (old transfer) free it */
1092 kfree(edge_port->write_urb->transfer_buffer); 1153 kfree(edge_port->write_urb->transfer_buffer);
1093 usb_free_urb(edge_port->write_urb); 1154 usb_free_urb(edge_port->write_urb);
1094 edge_port->write_urb = NULL; 1155 edge_port->write_urb = NULL;
@@ -1097,16 +1158,17 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1097 edge_port->txfifo.fifo = NULL; 1158 edge_port->txfifo.fifo = NULL;
1098 1159
1099 dbg("%s exited", __func__); 1160 dbg("%s exited", __func__);
1100} 1161}
1101 1162
1102/***************************************************************************** 1163/*****************************************************************************
1103 * SerialWrite 1164 * SerialWrite
1104 * this function is called by the tty driver when data should be written to 1165 * this function is called by the tty driver when data should be written
1105 * the port. 1166 * to the port.
1106 * If successful, we return the number of bytes written, otherwise we return 1167 * If successful, we return the number of bytes written, otherwise we
1107 * a negative error number. 1168 * return a negative error number.
1108 *****************************************************************************/ 1169 *****************************************************************************/
1109static int edge_write (struct usb_serial_port *port, const unsigned char *data, int count) 1170static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
1171 const unsigned char *data, int count)
1110{ 1172{
1111 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1173 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1112 struct TxFifo *fifo; 1174 struct TxFifo *fifo;
@@ -1121,66 +1183,76 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
1121 if (edge_port == NULL) 1183 if (edge_port == NULL)
1122 return -ENODEV; 1184 return -ENODEV;
1123 1185
1124 // get a pointer to the Tx fifo 1186 /* get a pointer to the Tx fifo */
1125 fifo = &edge_port->txfifo; 1187 fifo = &edge_port->txfifo;
1126 1188
1127 spin_lock_irqsave(&edge_port->ep_lock, flags); 1189 spin_lock_irqsave(&edge_port->ep_lock, flags);
1128 1190
1129 // calculate number of bytes to put in fifo 1191 /* calculate number of bytes to put in fifo */
1130 copySize = min ((unsigned int)count, (edge_port->txCredits - fifo->count)); 1192 copySize = min((unsigned int)count,
1193 (edge_port->txCredits - fifo->count));
1131 1194
1132 dbg("%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes", __func__, 1195 dbg("%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes",
1133 port->number, count, edge_port->txCredits - fifo->count, copySize); 1196 __func__, port->number, count,
1197 edge_port->txCredits - fifo->count, copySize);
1134 1198
1135 /* catch writes of 0 bytes which the tty driver likes to give us, and when txCredits is empty */ 1199 /* catch writes of 0 bytes which the tty driver likes to give us,
1200 and when txCredits is empty */
1136 if (copySize == 0) { 1201 if (copySize == 0) {
1137 dbg("%s - copySize = Zero", __func__); 1202 dbg("%s - copySize = Zero", __func__);
1138 goto finish_write; 1203 goto finish_write;
1139 } 1204 }
1140 1205
1141 // queue the data 1206 /* queue the data
1142 // since we can never overflow the buffer we do not have to check for full condition 1207 * since we can never overflow the buffer we do not have to check for a
1143 1208 * full condition
1144 // the copy is done is two parts -- first fill to the end of the buffer 1209 *
1145 // then copy the reset from the start of the buffer 1210 * the copy is done is two parts -- first fill to the end of the buffer
1146 1211 * then copy the reset from the start of the buffer
1212 */
1147 bytesleft = fifo->size - fifo->head; 1213 bytesleft = fifo->size - fifo->head;
1148 firsthalf = min (bytesleft, copySize); 1214 firsthalf = min(bytesleft, copySize);
1149 dbg("%s - copy %d bytes of %d into fifo ", __func__, firsthalf, bytesleft); 1215 dbg("%s - copy %d bytes of %d into fifo ", __func__,
1216 firsthalf, bytesleft);
1150 1217
1151 /* now copy our data */ 1218 /* now copy our data */
1152 memcpy(&fifo->fifo[fifo->head], data, firsthalf); 1219 memcpy(&fifo->fifo[fifo->head], data, firsthalf);
1153 usb_serial_debug_data(debug, &port->dev, __func__, firsthalf, &fifo->fifo[fifo->head]); 1220 usb_serial_debug_data(debug, &port->dev, __func__,
1221 firsthalf, &fifo->fifo[fifo->head]);
1154 1222
1155 // update the index and size 1223 /* update the index and size */
1156 fifo->head += firsthalf; 1224 fifo->head += firsthalf;
1157 fifo->count += firsthalf; 1225 fifo->count += firsthalf;
1158 1226
1159 // wrap the index 1227 /* wrap the index */
1160 if (fifo->head == fifo->size) { 1228 if (fifo->head == fifo->size)
1161 fifo->head = 0; 1229 fifo->head = 0;
1162 }
1163 1230
1164 secondhalf = copySize-firsthalf; 1231 secondhalf = copySize-firsthalf;
1165 1232
1166 if (secondhalf) { 1233 if (secondhalf) {
1167 dbg("%s - copy rest of data %d", __func__, secondhalf); 1234 dbg("%s - copy rest of data %d", __func__, secondhalf);
1168 memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf); 1235 memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf);
1169 usb_serial_debug_data(debug, &port->dev, __func__, secondhalf, &fifo->fifo[fifo->head]); 1236 usb_serial_debug_data(debug, &port->dev, __func__,
1170 // update the index and size 1237 secondhalf, &fifo->fifo[fifo->head]);
1238 /* update the index and size */
1171 fifo->count += secondhalf; 1239 fifo->count += secondhalf;
1172 fifo->head += secondhalf; 1240 fifo->head += secondhalf;
1173 // No need to check for wrap since we can not get to end of fifo in this part 1241 /* No need to check for wrap since we can not get to end of
1242 * the fifo in this part
1243 */
1174 } 1244 }
1175 1245
1176finish_write: 1246finish_write:
1177 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1247 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1178 1248
1179 send_more_port_data((struct edgeport_serial *)usb_get_serial_data(port->serial), edge_port); 1249 send_more_port_data((struct edgeport_serial *)
1250 usb_get_serial_data(port->serial), edge_port);
1180 1251
1181 dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __func__, copySize, edge_port->txCredits, fifo->count); 1252 dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __func__,
1253 copySize, edge_port->txCredits, fifo->count);
1182 1254
1183 return copySize; 1255 return copySize;
1184} 1256}
1185 1257
1186 1258
@@ -1197,7 +1269,8 @@ finish_write:
1197 * can transmit more. 1269 * can transmit more.
1198 * 1270 *
1199 ************************************************************************/ 1271 ************************************************************************/
1200static void send_more_port_data(struct edgeport_serial *edge_serial, struct edgeport_port *edge_port) 1272static void send_more_port_data(struct edgeport_serial *edge_serial,
1273 struct edgeport_port *edge_port)
1201{ 1274{
1202 struct TxFifo *fifo = &edge_port->txfifo; 1275 struct TxFifo *fifo = &edge_port->txfifo;
1203 struct urb *urb; 1276 struct urb *urb;
@@ -1216,67 +1289,78 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
1216 if (edge_port->write_in_progress || 1289 if (edge_port->write_in_progress ||
1217 !edge_port->open || 1290 !edge_port->open ||
1218 (fifo->count == 0)) { 1291 (fifo->count == 0)) {
1219 dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d", __func__, edge_port->port->number, fifo->count, edge_port->write_in_progress); 1292 dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d",
1293 __func__, edge_port->port->number,
1294 fifo->count, edge_port->write_in_progress);
1220 goto exit_send; 1295 goto exit_send;
1221 } 1296 }
1222 1297
1223 // since the amount of data in the fifo will always fit into the 1298 /* since the amount of data in the fifo will always fit into the
1224 // edgeport buffer we do not need to check the write length 1299 * edgeport buffer we do not need to check the write length
1225 1300 *
1226 // Do we have enough credits for this port to make it worthwhile 1301 * Do we have enough credits for this port to make it worthwhile
1227 // to bother queueing a write. If it's too small, say a few bytes, 1302 * to bother queueing a write. If it's too small, say a few bytes,
1228 // it's better to wait for more credits so we can do a larger 1303 * it's better to wait for more credits so we can do a larger write.
1229 // write. 1304 */
1230 if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits,EDGE_FW_BULK_MAX_PACKET_SIZE)) { 1305 if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits, EDGE_FW_BULK_MAX_PACKET_SIZE)) {
1231 dbg("%s(%d) Not enough credit - fifo %d TxCredit %d", __func__, edge_port->port->number, fifo->count, edge_port->txCredits ); 1306 dbg("%s(%d) Not enough credit - fifo %d TxCredit %d",
1307 __func__, edge_port->port->number, fifo->count,
1308 edge_port->txCredits);
1232 goto exit_send; 1309 goto exit_send;
1233 } 1310 }
1234 1311
1235 // lock this write 1312 /* lock this write */
1236 edge_port->write_in_progress = true; 1313 edge_port->write_in_progress = true;
1237 1314
1238 // get a pointer to the write_urb 1315 /* get a pointer to the write_urb */
1239 urb = edge_port->write_urb; 1316 urb = edge_port->write_urb;
1240 1317
1241 /* make sure transfer buffer is freed */ 1318 /* make sure transfer buffer is freed */
1242 kfree(urb->transfer_buffer); 1319 kfree(urb->transfer_buffer);
1243 urb->transfer_buffer = NULL; 1320 urb->transfer_buffer = NULL;
1244 1321
1245 /* build the data header for the buffer and port that we are about to send out */ 1322 /* build the data header for the buffer and port that we are about
1323 to send out */
1246 count = fifo->count; 1324 count = fifo->count;
1247 buffer = kmalloc (count+2, GFP_ATOMIC); 1325 buffer = kmalloc(count+2, GFP_ATOMIC);
1248 if (buffer == NULL) { 1326 if (buffer == NULL) {
1249 dev_err(&edge_port->port->dev, "%s - no more kernel memory...\n", __func__); 1327 dev_err(&edge_port->port->dev,
1328 "%s - no more kernel memory...\n", __func__);
1250 edge_port->write_in_progress = false; 1329 edge_port->write_in_progress = false;
1251 goto exit_send; 1330 goto exit_send;
1252 } 1331 }
1253 buffer[0] = IOSP_BUILD_DATA_HDR1 (edge_port->port->number - edge_port->port->serial->minor, count); 1332 buffer[0] = IOSP_BUILD_DATA_HDR1(edge_port->port->number
1254 buffer[1] = IOSP_BUILD_DATA_HDR2 (edge_port->port->number - edge_port->port->serial->minor, count); 1333 - edge_port->port->serial->minor, count);
1334 buffer[1] = IOSP_BUILD_DATA_HDR2(edge_port->port->number
1335 - edge_port->port->serial->minor, count);
1255 1336
1256 /* now copy our data */ 1337 /* now copy our data */
1257 bytesleft = fifo->size - fifo->tail; 1338 bytesleft = fifo->size - fifo->tail;
1258 firsthalf = min (bytesleft, count); 1339 firsthalf = min(bytesleft, count);
1259 memcpy(&buffer[2], &fifo->fifo[fifo->tail], firsthalf); 1340 memcpy(&buffer[2], &fifo->fifo[fifo->tail], firsthalf);
1260 fifo->tail += firsthalf; 1341 fifo->tail += firsthalf;
1261 fifo->count -= firsthalf; 1342 fifo->count -= firsthalf;
1262 if (fifo->tail == fifo->size) { 1343 if (fifo->tail == fifo->size)
1263 fifo->tail = 0; 1344 fifo->tail = 0;
1264 }
1265 1345
1266 secondhalf = count-firsthalf; 1346 secondhalf = count-firsthalf;
1267 if (secondhalf) { 1347 if (secondhalf) {
1268 memcpy(&buffer[2+firsthalf], &fifo->fifo[fifo->tail], secondhalf); 1348 memcpy(&buffer[2+firsthalf], &fifo->fifo[fifo->tail],
1349 secondhalf);
1269 fifo->tail += secondhalf; 1350 fifo->tail += secondhalf;
1270 fifo->count -= secondhalf; 1351 fifo->count -= secondhalf;
1271 } 1352 }
1272 1353
1273 if (count) 1354 if (count)
1274 usb_serial_debug_data(debug, &edge_port->port->dev, __func__, count, &buffer[2]); 1355 usb_serial_debug_data(debug, &edge_port->port->dev,
1356 __func__, count, &buffer[2]);
1275 1357
1276 /* fill up the urb with all of our data and submit it */ 1358 /* fill up the urb with all of our data and submit it */
1277 usb_fill_bulk_urb (urb, edge_serial->serial->dev, 1359 usb_fill_bulk_urb(urb, edge_serial->serial->dev,
1278 usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint), 1360 usb_sndbulkpipe(edge_serial->serial->dev,
1279 buffer, count+2, edge_bulk_out_data_callback, edge_port); 1361 edge_serial->bulk_out_endpoint),
1362 buffer, count+2,
1363 edge_bulk_out_data_callback, edge_port);
1280 1364
1281 /* decrement the number of credits we have by the number we just sent */ 1365 /* decrement the number of credits we have by the number we just sent */
1282 edge_port->txCredits -= count; 1366 edge_port->txCredits -= count;
@@ -1286,14 +1370,17 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
1286 status = usb_submit_urb(urb, GFP_ATOMIC); 1370 status = usb_submit_urb(urb, GFP_ATOMIC);
1287 if (status) { 1371 if (status) {
1288 /* something went wrong */ 1372 /* something went wrong */
1289 dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n", __func__, status); 1373 dev_err(&edge_port->port->dev,
1374 "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n",
1375 __func__, status);
1290 edge_port->write_in_progress = false; 1376 edge_port->write_in_progress = false;
1291 1377
1292 /* revert the credits as something bad happened. */ 1378 /* revert the credits as something bad happened. */
1293 edge_port->txCredits += count; 1379 edge_port->txCredits += count;
1294 edge_port->icount.tx -= count; 1380 edge_port->icount.tx -= count;
1295 } 1381 }
1296 dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d", __func__, count, edge_port->txCredits, fifo->count); 1382 dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d",
1383 __func__, count, edge_port->txCredits, fifo->count);
1297 1384
1298exit_send: 1385exit_send:
1299 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1386 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
@@ -1302,14 +1389,14 @@ exit_send:
1302 1389
1303/***************************************************************************** 1390/*****************************************************************************
1304 * edge_write_room 1391 * edge_write_room
1305 * this function is called by the tty driver when it wants to know how many 1392 * this function is called by the tty driver when it wants to know how
1306 * bytes of data we can accept for a specific port. 1393 * many bytes of data we can accept for a specific port. If successful,
1307 * If successful, we return the amount of room that we have for this port 1394 * we return the amount of room that we have for this port (the txCredits)
1308 * (the txCredits), 1395 * otherwise we return a negative error number.
1309 * Otherwise we return a negative error number.
1310 *****************************************************************************/ 1396 *****************************************************************************/
1311static int edge_write_room (struct usb_serial_port *port) 1397static int edge_write_room(struct tty_struct *tty)
1312{ 1398{
1399 struct usb_serial_port *port = tty->driver_data;
1313 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1400 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1314 int room; 1401 int room;
1315 unsigned long flags; 1402 unsigned long flags;
@@ -1317,18 +1404,18 @@ static int edge_write_room (struct usb_serial_port *port)
1317 dbg("%s", __func__); 1404 dbg("%s", __func__);
1318 1405
1319 if (edge_port == NULL) 1406 if (edge_port == NULL)
1320 return -ENODEV; 1407 return 0;
1321 if (edge_port->closePending) 1408 if (edge_port->closePending)
1322 return -ENODEV; 1409 return 0;
1323 1410
1324 dbg("%s - port %d", __func__, port->number); 1411 dbg("%s - port %d", __func__, port->number);
1325 1412
1326 if (!edge_port->open) { 1413 if (!edge_port->open) {
1327 dbg("%s - port not opened", __func__); 1414 dbg("%s - port not opened", __func__);
1328 return -EINVAL; 1415 return 0;
1329 } 1416 }
1330 1417
1331 // total of both buffers is still txCredit 1418 /* total of both buffers is still txCredit */
1332 spin_lock_irqsave(&edge_port->ep_lock, flags); 1419 spin_lock_irqsave(&edge_port->ep_lock, flags);
1333 room = edge_port->txCredits - edge_port->txfifo.count; 1420 room = edge_port->txCredits - edge_port->txfifo.count;
1334 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1421 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
@@ -1340,15 +1427,16 @@ static int edge_write_room (struct usb_serial_port *port)
1340 1427
1341/***************************************************************************** 1428/*****************************************************************************
1342 * edge_chars_in_buffer 1429 * edge_chars_in_buffer
1343 * this function is called by the tty driver when it wants to know how many 1430 * this function is called by the tty driver when it wants to know how
1344 * bytes of data we currently have outstanding in the port (data that has 1431 * many bytes of data we currently have outstanding in the port (data that
1345 * been written, but hasn't made it out the port yet) 1432 * has been written, but hasn't made it out the port yet)
1346 * If successful, we return the number of bytes left to be written in the 1433 * If successful, we return the number of bytes left to be written in the
1347 * system, 1434 * system,
1348 * Otherwise we return a negative error number. 1435 * Otherwise we return a negative error number.
1349 *****************************************************************************/ 1436 *****************************************************************************/
1350static int edge_chars_in_buffer (struct usb_serial_port *port) 1437static int edge_chars_in_buffer(struct tty_struct *tty)
1351{ 1438{
1439 struct usb_serial_port *port = tty->driver_data;
1352 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1440 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1353 int num_chars; 1441 int num_chars;
1354 unsigned long flags; 1442 unsigned long flags;
@@ -1356,20 +1444,22 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
1356 dbg("%s", __func__); 1444 dbg("%s", __func__);
1357 1445
1358 if (edge_port == NULL) 1446 if (edge_port == NULL)
1359 return -ENODEV; 1447 return 0;
1360 if (edge_port->closePending) 1448 if (edge_port->closePending)
1361 return -ENODEV; 1449 return 0;
1362 1450
1363 if (!edge_port->open) { 1451 if (!edge_port->open) {
1364 dbg("%s - port not opened", __func__); 1452 dbg("%s - port not opened", __func__);
1365 return -EINVAL; 1453 return 0;
1366 } 1454 }
1367 1455
1368 spin_lock_irqsave(&edge_port->ep_lock, flags); 1456 spin_lock_irqsave(&edge_port->ep_lock, flags);
1369 num_chars = edge_port->maxTxCredits - edge_port->txCredits + edge_port->txfifo.count; 1457 num_chars = edge_port->maxTxCredits - edge_port->txCredits +
1458 edge_port->txfifo.count;
1370 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1459 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1371 if (num_chars) { 1460 if (num_chars) {
1372 dbg("%s(port %d) - returns %d", __func__, port->number, num_chars); 1461 dbg("%s(port %d) - returns %d", __func__,
1462 port->number, num_chars);
1373 } 1463 }
1374 1464
1375 return num_chars; 1465 return num_chars;
@@ -1381,10 +1471,10 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
1381 * this function is called by the tty driver when it wants to stop the data 1471 * this function is called by the tty driver when it wants to stop the data
1382 * being read from the port. 1472 * being read from the port.
1383 *****************************************************************************/ 1473 *****************************************************************************/
1384static void edge_throttle (struct usb_serial_port *port) 1474static void edge_throttle(struct tty_struct *tty)
1385{ 1475{
1476 struct usb_serial_port *port = tty->driver_data;
1386 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1477 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1387 struct tty_struct *tty;
1388 int status; 1478 int status;
1389 1479
1390 dbg("%s - port %d", __func__, port->number); 1480 dbg("%s - port %d", __func__, port->number);
@@ -1397,28 +1487,21 @@ static void edge_throttle (struct usb_serial_port *port)
1397 return; 1487 return;
1398 } 1488 }
1399 1489
1400 tty = port->tty;
1401 if (!tty) {
1402 dbg ("%s - no tty available", __func__);
1403 return;
1404 }
1405
1406 /* if we are implementing XON/XOFF, send the stop character */ 1490 /* if we are implementing XON/XOFF, send the stop character */
1407 if (I_IXOFF(tty)) { 1491 if (I_IXOFF(tty)) {
1408 unsigned char stop_char = STOP_CHAR(tty); 1492 unsigned char stop_char = STOP_CHAR(tty);
1409 status = edge_write (port, &stop_char, 1); 1493 status = edge_write(tty, port, &stop_char, 1);
1410 if (status <= 0) { 1494 if (status <= 0)
1411 return; 1495 return;
1412 }
1413 } 1496 }
1414 1497
1415 /* if we are implementing RTS/CTS, toggle that line */ 1498 /* if we are implementing RTS/CTS, toggle that line */
1416 if (tty->termios->c_cflag & CRTSCTS) { 1499 if (tty->termios->c_cflag & CRTSCTS) {
1417 edge_port->shadowMCR &= ~MCR_RTS; 1500 edge_port->shadowMCR &= ~MCR_RTS;
1418 status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); 1501 status = send_cmd_write_uart_register(edge_port, MCR,
1419 if (status != 0) { 1502 edge_port->shadowMCR);
1503 if (status != 0)
1420 return; 1504 return;
1421 }
1422 } 1505 }
1423 1506
1424 return; 1507 return;
@@ -1427,13 +1510,13 @@ static void edge_throttle (struct usb_serial_port *port)
1427 1510
1428/***************************************************************************** 1511/*****************************************************************************
1429 * edge_unthrottle 1512 * edge_unthrottle
1430 * this function is called by the tty driver when it wants to resume the data 1513 * this function is called by the tty driver when it wants to resume the
1431 * being read from the port (called after SerialThrottle is called) 1514 * data being read from the port (called after SerialThrottle is called)
1432 *****************************************************************************/ 1515 *****************************************************************************/
1433static void edge_unthrottle (struct usb_serial_port *port) 1516static void edge_unthrottle(struct tty_struct *tty)
1434{ 1517{
1518 struct usb_serial_port *port = tty->driver_data;
1435 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1519 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1436 struct tty_struct *tty;
1437 int status; 1520 int status;
1438 1521
1439 dbg("%s - port %d", __func__, port->number); 1522 dbg("%s - port %d", __func__, port->number);
@@ -1446,43 +1529,31 @@ static void edge_unthrottle (struct usb_serial_port *port)
1446 return; 1529 return;
1447 } 1530 }
1448 1531
1449 tty = port->tty;
1450 if (!tty) {
1451 dbg ("%s - no tty available", __func__);
1452 return;
1453 }
1454
1455 /* if we are implementing XON/XOFF, send the start character */ 1532 /* if we are implementing XON/XOFF, send the start character */
1456 if (I_IXOFF(tty)) { 1533 if (I_IXOFF(tty)) {
1457 unsigned char start_char = START_CHAR(tty); 1534 unsigned char start_char = START_CHAR(tty);
1458 status = edge_write (port, &start_char, 1); 1535 status = edge_write(tty, port, &start_char, 1);
1459 if (status <= 0) { 1536 if (status <= 0)
1460 return; 1537 return;
1461 }
1462 } 1538 }
1463
1464 /* if we are implementing RTS/CTS, toggle that line */ 1539 /* if we are implementing RTS/CTS, toggle that line */
1465 if (tty->termios->c_cflag & CRTSCTS) { 1540 if (tty->termios->c_cflag & CRTSCTS) {
1466 edge_port->shadowMCR |= MCR_RTS; 1541 edge_port->shadowMCR |= MCR_RTS;
1467 status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); 1542 send_cmd_write_uart_register(edge_port, MCR,
1468 if (status != 0) { 1543 edge_port->shadowMCR);
1469 return;
1470 }
1471 } 1544 }
1472
1473 return;
1474} 1545}
1475 1546
1476 1547
1477/***************************************************************************** 1548/*****************************************************************************
1478 * SerialSetTermios 1549 * SerialSetTermios
1479 * this function is called by the tty driver when it wants to change the termios structure 1550 * this function is called by the tty driver when it wants to change
1551 * the termios structure
1480 *****************************************************************************/ 1552 *****************************************************************************/
1481static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 1553static void edge_set_termios(struct tty_struct *tty,
1554 struct usb_serial_port *port, struct ktermios *old_termios)
1482{ 1555{
1483 /* FIXME: This function appears unused ?? */
1484 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1556 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1485 struct tty_struct *tty = port->tty;
1486 unsigned int cflag; 1557 unsigned int cflag;
1487 1558
1488 cflag = tty->termios->c_cflag; 1559 cflag = tty->termios->c_cflag;
@@ -1502,9 +1573,7 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old
1502 } 1573 }
1503 1574
1504 /* change the port settings to the new ones specified */ 1575 /* change the port settings to the new ones specified */
1505 change_port_settings (edge_port, old_termios); 1576 change_port_settings(tty, edge_port, old_termios);
1506
1507 return;
1508} 1577}
1509 1578
1510 1579
@@ -1516,9 +1585,10 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old
1516 * release the bus after transmitting. This must be done when 1585 * release the bus after transmitting. This must be done when
1517 * the transmit shift register is empty, not be done when the 1586 * the transmit shift register is empty, not be done when the
1518 * transmit holding register is empty. This functionality 1587 * transmit holding register is empty. This functionality
1519 * allows an RS485 driver to be written in user space. 1588 * allows an RS485 driver to be written in user space.
1520 *****************************************************************************/ 1589 *****************************************************************************/
1521static int get_lsr_info(struct edgeport_port *edge_port, unsigned int __user *value) 1590static int get_lsr_info(struct edgeport_port *edge_port,
1591 unsigned int __user *value)
1522{ 1592{
1523 unsigned int result = 0; 1593 unsigned int result = 0;
1524 unsigned long flags; 1594 unsigned long flags;
@@ -1536,25 +1606,10 @@ static int get_lsr_info(struct edgeport_port *edge_port, unsigned int __user *va
1536 return 0; 1606 return 0;
1537} 1607}
1538 1608
1539static int get_number_bytes_avail(struct edgeport_port *edge_port, unsigned int __user *value) 1609static int edge_tiocmset(struct tty_struct *tty, struct file *file,
1540{ 1610 unsigned int set, unsigned int clear)
1541 unsigned int result = 0;
1542 struct tty_struct *tty = edge_port->port->tty;
1543
1544 if (!tty)
1545 return -ENOIOCTLCMD;
1546
1547 result = tty->read_cnt;
1548
1549 dbg("%s(%d) = %d", __func__, edge_port->port->number, result);
1550 if (copy_to_user(value, &result, sizeof(int)))
1551 return -EFAULT;
1552 //return 0;
1553 return -ENOIOCTLCMD;
1554}
1555
1556static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear)
1557{ 1611{
1612 struct usb_serial_port *port = tty->driver_data;
1558 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1613 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1559 unsigned int mcr; 1614 unsigned int mcr;
1560 1615
@@ -1582,8 +1637,9 @@ static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsig
1582 return 0; 1637 return 0;
1583} 1638}
1584 1639
1585static int edge_tiocmget(struct usb_serial_port *port, struct file *file) 1640static int edge_tiocmget(struct tty_struct *tty, struct file *file)
1586{ 1641{
1642 struct usb_serial_port *port = tty->driver_data;
1587 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1643 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1588 unsigned int result = 0; 1644 unsigned int result = 0;
1589 unsigned int msr; 1645 unsigned int msr;
@@ -1606,7 +1662,8 @@ static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
1606 return result; 1662 return result;
1607} 1663}
1608 1664
1609static int get_serial_info(struct edgeport_port *edge_port, struct serial_struct __user *retinfo) 1665static int get_serial_info(struct edgeport_port *edge_port,
1666 struct serial_struct __user *retinfo)
1610{ 1667{
1611 struct serial_struct tmp; 1668 struct serial_struct tmp;
1612 1669
@@ -1624,9 +1681,6 @@ static int get_serial_info(struct edgeport_port *edge_port, struct serial_struct
1624 tmp.baud_base = 9600; 1681 tmp.baud_base = 9600;
1625 tmp.close_delay = 5*HZ; 1682 tmp.close_delay = 5*HZ;
1626 tmp.closing_wait = 30*HZ; 1683 tmp.closing_wait = 30*HZ;
1627// tmp.custom_divisor = state->custom_divisor;
1628// tmp.hub6 = state->hub6;
1629// tmp.io_type = state->io_type;
1630 1684
1631 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 1685 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1632 return -EFAULT; 1686 return -EFAULT;
@@ -1639,8 +1693,10 @@ static int get_serial_info(struct edgeport_port *edge_port, struct serial_struct
1639 * SerialIoctl 1693 * SerialIoctl
1640 * this function handles any ioctl calls to the driver 1694 * this function handles any ioctl calls to the driver
1641 *****************************************************************************/ 1695 *****************************************************************************/
1642static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg) 1696static int edge_ioctl(struct tty_struct *tty, struct file *file,
1697 unsigned int cmd, unsigned long arg)
1643{ 1698{
1699 struct usb_serial_port *port = tty->driver_data;
1644 DEFINE_WAIT(wait); 1700 DEFINE_WAIT(wait);
1645 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1701 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1646 struct async_icount cnow; 1702 struct async_icount cnow;
@@ -1650,71 +1706,61 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
1650 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 1706 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1651 1707
1652 switch (cmd) { 1708 switch (cmd) {
1653 // return number of bytes available 1709 case TIOCSERGETLSR:
1654 case TIOCINQ: 1710 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1655 dbg("%s (%d) TIOCINQ", __func__, port->number); 1711 return get_lsr_info(edge_port, (unsigned int __user *) arg);
1656 return get_number_bytes_avail(edge_port, (unsigned int __user *) arg); 1712
1657 break; 1713 case TIOCGSERIAL:
1658 1714 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
1659 case TIOCSERGETLSR: 1715 return get_serial_info(edge_port, (struct serial_struct __user *) arg);
1660 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); 1716
1661 return get_lsr_info(edge_port, (unsigned int __user *) arg); 1717 case TIOCMIWAIT:
1662 return 0; 1718 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1663 1719 cprev = edge_port->icount;
1664 case TIOCGSERIAL: 1720 while (1) {
1665 dbg("%s (%d) TIOCGSERIAL", __func__, port->number); 1721 prepare_to_wait(&edge_port->delta_msr_wait,
1666 return get_serial_info(edge_port, (struct serial_struct __user *) arg); 1722 &wait, TASK_INTERRUPTIBLE);
1667 1723 schedule();
1668 case TIOCSSERIAL: 1724 finish_wait(&edge_port->delta_msr_wait, &wait);
1669 dbg("%s (%d) TIOCSSERIAL", __func__, port->number); 1725 /* see if a signal did it */
1670 break; 1726 if (signal_pending(current))
1671 1727 return -ERESTARTSYS;
1672 case TIOCMIWAIT: 1728 cnow = edge_port->icount;
1673 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 1729 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1674 cprev = edge_port->icount; 1730 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1675 while (1) { 1731 return -EIO; /* no change => error */
1676 prepare_to_wait(&edge_port->delta_msr_wait, &wait, TASK_INTERRUPTIBLE); 1732 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1677 schedule(); 1733 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1678 finish_wait(&edge_port->delta_msr_wait, &wait); 1734 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1679 /* see if a signal did it */ 1735 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1680 if (signal_pending(current)) 1736 return 0;
1681 return -ERESTARTSYS;
1682 cnow = edge_port->icount;
1683 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1684 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1685 return -EIO; /* no change => error */
1686 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1687 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1688 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1689 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
1690 return 0;
1691 }
1692 cprev = cnow;
1693 } 1737 }
1694 /* NOTREACHED */ 1738 cprev = cnow;
1695 break; 1739 }
1740 /* NOTREACHED */
1741 break;
1696 1742
1697 case TIOCGICOUNT: 1743 case TIOCGICOUNT:
1698 cnow = edge_port->icount; 1744 cnow = edge_port->icount;
1699 memset(&icount, 0, sizeof(icount)); 1745 memset(&icount, 0, sizeof(icount));
1700 icount.cts = cnow.cts; 1746 icount.cts = cnow.cts;
1701 icount.dsr = cnow.dsr; 1747 icount.dsr = cnow.dsr;
1702 icount.rng = cnow.rng; 1748 icount.rng = cnow.rng;
1703 icount.dcd = cnow.dcd; 1749 icount.dcd = cnow.dcd;
1704 icount.rx = cnow.rx; 1750 icount.rx = cnow.rx;
1705 icount.tx = cnow.tx; 1751 icount.tx = cnow.tx;
1706 icount.frame = cnow.frame; 1752 icount.frame = cnow.frame;
1707 icount.overrun = cnow.overrun; 1753 icount.overrun = cnow.overrun;
1708 icount.parity = cnow.parity; 1754 icount.parity = cnow.parity;
1709 icount.brk = cnow.brk; 1755 icount.brk = cnow.brk;
1710 icount.buf_overrun = cnow.buf_overrun; 1756 icount.buf_overrun = cnow.buf_overrun;
1711 1757
1712 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, port->number, icount.rx, icount.tx ); 1758 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d",
1713 if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) 1759 __func__, port->number, icount.rx, icount.tx);
1714 return -EFAULT; 1760 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1715 return 0; 1761 return -EFAULT;
1762 return 0;
1716 } 1763 }
1717
1718 return -ENOIOCTLCMD; 1764 return -ENOIOCTLCMD;
1719} 1765}
1720 1766
@@ -1723,8 +1769,9 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
1723 * SerialBreak 1769 * SerialBreak
1724 * this function sends a break to the port 1770 * this function sends a break to the port
1725 *****************************************************************************/ 1771 *****************************************************************************/
1726static void edge_break (struct usb_serial_port *port, int break_state) 1772static void edge_break(struct tty_struct *tty, int break_state)
1727{ 1773{
1774 struct usb_serial_port *port = tty->driver_data;
1728 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1775 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1729 struct edgeport_serial *edge_serial = usb_get_serial_data(port->serial); 1776 struct edgeport_serial *edge_serial = usb_get_serial_data(port->serial);
1730 int status; 1777 int status;
@@ -1736,9 +1783,9 @@ static void edge_break (struct usb_serial_port *port, int break_state)
1736 edge_port->chaseResponsePending = true; 1783 edge_port->chaseResponsePending = true;
1737 1784
1738 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__); 1785 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__);
1739 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); 1786 status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0);
1740 if (status == 0) { 1787 if (status == 0) {
1741 // block until chase finished 1788 /* block until chase finished */
1742 block_until_chase_response(edge_port); 1789 block_until_chase_response(edge_port);
1743 } else { 1790 } else {
1744 edge_port->chaseResponsePending = false; 1791 edge_port->chaseResponsePending = false;
@@ -1750,14 +1797,16 @@ static void edge_break (struct usb_serial_port *port, int break_state)
1750 (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) { 1797 (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) {
1751 if (break_state == -1) { 1798 if (break_state == -1) {
1752 dbg("%s - Sending IOSP_CMD_SET_BREAK", __func__); 1799 dbg("%s - Sending IOSP_CMD_SET_BREAK", __func__);
1753 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_SET_BREAK, 0); 1800 status = send_iosp_ext_cmd(edge_port,
1801 IOSP_CMD_SET_BREAK, 0);
1754 } else { 1802 } else {
1755 dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __func__); 1803 dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __func__);
1756 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CLEAR_BREAK, 0); 1804 status = send_iosp_ext_cmd(edge_port,
1757 } 1805 IOSP_CMD_CLEAR_BREAK, 0);
1758 if (status) {
1759 dbg("%s - error sending break set/clear command.", __func__);
1760 } 1806 }
1807 if (status)
1808 dbg("%s - error sending break set/clear command.",
1809 __func__);
1761 } 1810 }
1762 1811
1763 return; 1812 return;
@@ -1768,7 +1817,8 @@ static void edge_break (struct usb_serial_port *port, int break_state)
1768 * process_rcvd_data 1817 * process_rcvd_data
1769 * this function handles the data received on the bulk in pipe. 1818 * this function handles the data received on the bulk in pipe.
1770 *****************************************************************************/ 1819 *****************************************************************************/
1771static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned char * buffer, __u16 bufferLength) 1820static void process_rcvd_data(struct edgeport_serial *edge_serial,
1821 unsigned char *buffer, __u16 bufferLength)
1772{ 1822{
1773 struct usb_serial_port *port; 1823 struct usb_serial_port *port;
1774 struct edgeport_port *edge_port; 1824 struct edgeport_port *edge_port;
@@ -1789,105 +1839,123 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
1789 lastBufferLength = bufferLength; 1839 lastBufferLength = bufferLength;
1790 1840
1791 switch (edge_serial->rxState) { 1841 switch (edge_serial->rxState) {
1792 case EXPECT_HDR1: 1842 case EXPECT_HDR1:
1793 edge_serial->rxHeader1 = *buffer; 1843 edge_serial->rxHeader1 = *buffer;
1794 ++buffer; 1844 ++buffer;
1795 --bufferLength; 1845 --bufferLength;
1796 1846
1797 if (bufferLength == 0) { 1847 if (bufferLength == 0) {
1798 edge_serial->rxState = EXPECT_HDR2; 1848 edge_serial->rxState = EXPECT_HDR2;
1849 break;
1850 }
1851 /* otherwise, drop on through */
1852 case EXPECT_HDR2:
1853 edge_serial->rxHeader2 = *buffer;
1854 ++buffer;
1855 --bufferLength;
1856
1857 dbg("%s - Hdr1=%02X Hdr2=%02X", __func__,
1858 edge_serial->rxHeader1, edge_serial->rxHeader2);
1859 /* Process depending on whether this header is
1860 * data or status */
1861
1862 if (IS_CMD_STAT_HDR(edge_serial->rxHeader1)) {
1863 /* Decode this status header and go to
1864 * EXPECT_HDR1 (if we can process the status
1865 * with only 2 bytes), or go to EXPECT_HDR3 to
1866 * get the third byte. */
1867 edge_serial->rxPort =
1868 IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
1869 edge_serial->rxStatusCode =
1870 IOSP_GET_STATUS_CODE(
1871 edge_serial->rxHeader1);
1872
1873 if (!IOSP_STATUS_IS_2BYTE(
1874 edge_serial->rxStatusCode)) {
1875 /* This status needs additional bytes.
1876 * Save what we have and then wait for
1877 * more data.
1878 */
1879 edge_serial->rxStatusParam
1880 = edge_serial->rxHeader2;
1881 edge_serial->rxState = EXPECT_HDR3;
1799 break; 1882 break;
1800 } 1883 }
1801 /* otherwise, drop on through */ 1884 /* We have all the header bytes, process the
1802 1885 status now */
1803 case EXPECT_HDR2: 1886 process_rcvd_status(edge_serial,
1804 edge_serial->rxHeader2 = *buffer; 1887 edge_serial->rxHeader2, 0);
1805 ++buffer; 1888 edge_serial->rxState = EXPECT_HDR1;
1806 --bufferLength; 1889 break;
1807 1890 } else {
1808 dbg("%s - Hdr1=%02X Hdr2=%02X", __func__, edge_serial->rxHeader1, edge_serial->rxHeader2); 1891 edge_serial->rxPort =
1809 1892 IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
1810 // Process depending on whether this header is 1893 edge_serial->rxBytesRemaining =
1811 // data or status 1894 IOSP_GET_HDR_DATA_LEN(
1812 1895 edge_serial->rxHeader1,
1813 if (IS_CMD_STAT_HDR(edge_serial->rxHeader1)) { 1896 edge_serial->rxHeader2);
1814 // Decode this status header and goto EXPECT_HDR1 (if we 1897 dbg("%s - Data for Port %u Len %u",
1815 // can process the status with only 2 bytes), or goto 1898 __func__,
1816 // EXPECT_HDR3 to get the third byte. 1899 edge_serial->rxPort,
1817 1900 edge_serial->rxBytesRemaining);
1818 edge_serial->rxPort = IOSP_GET_HDR_PORT(edge_serial->rxHeader1); 1901
1819 edge_serial->rxStatusCode = IOSP_GET_STATUS_CODE(edge_serial->rxHeader1); 1902 /* ASSERT(DevExt->RxPort < DevExt->NumPorts);
1820 1903 * ASSERT(DevExt->RxBytesRemaining <
1821 if (!IOSP_STATUS_IS_2BYTE(edge_serial->rxStatusCode)) { 1904 * IOSP_MAX_DATA_LENGTH);
1822 // This status needs additional bytes. Save what we have 1905 */
1823 // and then wait for more data.
1824 edge_serial->rxStatusParam = edge_serial->rxHeader2;
1825
1826 edge_serial->rxState = EXPECT_HDR3;
1827 break;
1828 }
1829 1906
1830 // We have all the header bytes, process the status now 1907 if (bufferLength == 0) {
1831 process_rcvd_status (edge_serial, edge_serial->rxHeader2, 0); 1908 edge_serial->rxState = EXPECT_DATA;
1832 edge_serial->rxState = EXPECT_HDR1;
1833 break; 1909 break;
1834 } else {
1835 edge_serial->rxPort = IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
1836 edge_serial->rxBytesRemaining = IOSP_GET_HDR_DATA_LEN(edge_serial->rxHeader1, edge_serial->rxHeader2);
1837
1838 dbg("%s - Data for Port %u Len %u", __func__, edge_serial->rxPort, edge_serial->rxBytesRemaining);
1839
1840 //ASSERT( DevExt->RxPort < DevExt->NumPorts );
1841 //ASSERT( DevExt->RxBytesRemaining < IOSP_MAX_DATA_LENGTH );
1842
1843 if (bufferLength == 0 ) {
1844 edge_serial->rxState = EXPECT_DATA;
1845 break;
1846 }
1847 // Else, drop through
1848 } 1910 }
1911 /* Else, drop through */
1912 }
1913 case EXPECT_DATA: /* Expect data */
1914 if (bufferLength < edge_serial->rxBytesRemaining) {
1915 rxLen = bufferLength;
1916 /* Expect data to start next buffer */
1917 edge_serial->rxState = EXPECT_DATA;
1918 } else {
1919 /* BufLen >= RxBytesRemaining */
1920 rxLen = edge_serial->rxBytesRemaining;
1921 /* Start another header next time */
1922 edge_serial->rxState = EXPECT_HDR1;
1923 }
1849 1924
1850 case EXPECT_DATA: // Expect data 1925 bufferLength -= rxLen;
1851 1926 edge_serial->rxBytesRemaining -= rxLen;
1852 if (bufferLength < edge_serial->rxBytesRemaining) {
1853 rxLen = bufferLength;
1854 edge_serial->rxState = EXPECT_DATA; // Expect data to start next buffer
1855 } else {
1856 // BufLen >= RxBytesRemaining
1857 rxLen = edge_serial->rxBytesRemaining;
1858 edge_serial->rxState = EXPECT_HDR1; // Start another header next time
1859 }
1860 1927
1861 bufferLength -= rxLen; 1928 /* spit this data back into the tty driver if this
1862 edge_serial->rxBytesRemaining -= rxLen; 1929 port is open */
1863 1930 if (rxLen) {
1864 /* spit this data back into the tty driver if this port is open */ 1931 port = edge_serial->serial->port[
1865 if (rxLen) { 1932 edge_serial->rxPort];
1866 port = edge_serial->serial->port[edge_serial->rxPort]; 1933 edge_port = usb_get_serial_port_data(port);
1867 edge_port = usb_get_serial_port_data(port); 1934 if (edge_port->open) {
1868 if (edge_port->open) { 1935 tty = edge_port->port->port.tty;
1869 tty = edge_port->port->tty; 1936 if (tty) {
1870 if (tty) { 1937 dbg("%s - Sending %d bytes to TTY for port %d",
1871 dbg("%s - Sending %d bytes to TTY for port %d", __func__, rxLen, edge_serial->rxPort); 1938 __func__, rxLen, edge_serial->rxPort);
1872 edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen); 1939 edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen);
1873 }
1874 edge_port->icount.rx += rxLen;
1875 } 1940 }
1876 buffer += rxLen; 1941 edge_port->icount.rx += rxLen;
1877 } 1942 }
1943 buffer += rxLen;
1944 }
1945 break;
1878 1946
1879 break; 1947 case EXPECT_HDR3: /* Expect 3rd byte of status header */
1880 1948 edge_serial->rxHeader3 = *buffer;
1881 case EXPECT_HDR3: // Expect 3rd byte of status header 1949 ++buffer;
1882 edge_serial->rxHeader3 = *buffer; 1950 --bufferLength;
1883 ++buffer; 1951
1884 --bufferLength; 1952 /* We have all the header bytes, process the
1885 1953 status now */
1886 // We have all the header bytes, process the status now 1954 process_rcvd_status(edge_serial,
1887 process_rcvd_status (edge_serial, edge_serial->rxStatusParam, edge_serial->rxHeader3); 1955 edge_serial->rxStatusParam,
1888 edge_serial->rxState = EXPECT_HDR1; 1956 edge_serial->rxHeader3);
1889 break; 1957 edge_serial->rxState = EXPECT_HDR1;
1890 1958 break;
1891 } 1959 }
1892 } 1960 }
1893} 1961}
@@ -1895,9 +1963,11 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
1895 1963
1896/***************************************************************************** 1964/*****************************************************************************
1897 * process_rcvd_status 1965 * process_rcvd_status
1898 * this function handles the any status messages received on the bulk in pipe. 1966 * this function handles the any status messages received on the
1967 * bulk in pipe.
1899 *****************************************************************************/ 1968 *****************************************************************************/
1900static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2, __u8 byte3) 1969static void process_rcvd_status(struct edgeport_serial *edge_serial,
1970 __u8 byte2, __u8 byte3)
1901{ 1971{
1902 struct usb_serial_port *port; 1972 struct usb_serial_port *port;
1903 struct edgeport_port *edge_port; 1973 struct edgeport_port *edge_port;
@@ -1907,7 +1977,9 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1907 port = edge_serial->serial->port[edge_serial->rxPort]; 1977 port = edge_serial->serial->port[edge_serial->rxPort];
1908 edge_port = usb_get_serial_port_data(port); 1978 edge_port = usb_get_serial_port_data(port);
1909 if (edge_port == NULL) { 1979 if (edge_port == NULL) {
1910 dev_err(&edge_serial->serial->dev->dev, "%s - edge_port == NULL for port %d\n", __func__, edge_serial->rxPort); 1980 dev_err(&edge_serial->serial->dev->dev,
1981 "%s - edge_port == NULL for port %d\n",
1982 __func__, edge_serial->rxPort);
1911 return; 1983 return;
1912 } 1984 }
1913 1985
@@ -1915,22 +1987,28 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1915 1987
1916 if (code == IOSP_EXT_STATUS) { 1988 if (code == IOSP_EXT_STATUS) {
1917 switch (byte2) { 1989 switch (byte2) {
1918 case IOSP_EXT_STATUS_CHASE_RSP: 1990 case IOSP_EXT_STATUS_CHASE_RSP:
1919 // we want to do EXT status regardless of port open/closed 1991 /* we want to do EXT status regardless of port
1920 dbg("%s - Port %u EXT CHASE_RSP Data = %02x", __func__, edge_serial->rxPort, byte3 ); 1992 * open/closed */
1921 // Currently, the only EXT_STATUS is Chase, so process here instead of one more call 1993 dbg("%s - Port %u EXT CHASE_RSP Data = %02x",
1922 // to one more subroutine. If/when more EXT_STATUS, there'll be more work to do. 1994 __func__, edge_serial->rxPort, byte3);
1923 // Also, we currently clear flag and close the port regardless of content of above's Byte3. 1995 /* Currently, the only EXT_STATUS is Chase, so process
1924 // We could choose to do something else when Byte3 says Timeout on Chase from Edgeport, 1996 * here instead of one more call to one more subroutine
1925 // like wait longer in block_until_chase_response, but for now we don't. 1997 * If/when more EXT_STATUS, there'll be more work to do
1926 edge_port->chaseResponsePending = false; 1998 * Also, we currently clear flag and close the port
1927 wake_up (&edge_port->wait_chase); 1999 * regardless of content of above's Byte3.
1928 return; 2000 * We could choose to do something else when Byte3 says
2001 * Timeout on Chase from Edgeport, like wait longer in
2002 * block_until_chase_response, but for now we don't.
2003 */
2004 edge_port->chaseResponsePending = false;
2005 wake_up(&edge_port->wait_chase);
2006 return;
1929 2007
1930 case IOSP_EXT_STATUS_RX_CHECK_RSP: 2008 case IOSP_EXT_STATUS_RX_CHECK_RSP:
1931 dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __func__, edge_serial->rxPort, byte3 ); 2009 dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __func__, edge_serial->rxPort, byte3);
1932 //Port->RxCheckRsp = true; 2010 /* Port->RxCheckRsp = true; */
1933 return; 2011 return;
1934 } 2012 }
1935 } 2013 }
1936 2014
@@ -1938,11 +2016,14 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1938 edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3); 2016 edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3);
1939 edge_port->maxTxCredits = edge_port->txCredits; 2017 edge_port->maxTxCredits = edge_port->txCredits;
1940 dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits); 2018 dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits);
1941 handle_new_msr (edge_port, byte2); 2019 handle_new_msr(edge_port, byte2);
1942 2020
1943 /* send the current line settings to the port so we are in sync with any further termios calls */ 2021 /* send the current line settings to the port so we are
1944 if (edge_port->port->tty) 2022 in sync with any further termios calls */
1945 change_port_settings (edge_port, edge_port->port->tty->termios); 2023 /* FIXME: locking on tty */
2024 if (edge_port->port->port.tty)
2025 change_port_settings(edge_port->port->port.tty,
2026 edge_port, edge_port->port->port.tty->termios);
1946 2027
1947 /* we have completed the open */ 2028 /* we have completed the open */
1948 edge_port->openPending = false; 2029 edge_port->openPending = false;
@@ -1951,45 +2032,49 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1951 return; 2032 return;
1952 } 2033 }
1953 2034
1954 // If port is closed, silently discard all rcvd status. We can 2035 /* If port is closed, silently discard all rcvd status. We can
1955 // have cases where buffered status is received AFTER the close 2036 * have cases where buffered status is received AFTER the close
1956 // port command is sent to the Edgeport. 2037 * port command is sent to the Edgeport.
1957 if (!edge_port->open || edge_port->closePending) { 2038 */
2039 if (!edge_port->open || edge_port->closePending)
1958 return; 2040 return;
1959 }
1960 2041
1961 switch (code) { 2042 switch (code) {
1962 // Not currently sent by Edgeport 2043 /* Not currently sent by Edgeport */
1963 case IOSP_STATUS_LSR: 2044 case IOSP_STATUS_LSR:
1964 dbg("%s - Port %u LSR Status = %02x", __func__, edge_serial->rxPort, byte2); 2045 dbg("%s - Port %u LSR Status = %02x",
1965 handle_new_lsr(edge_port, false, byte2, 0); 2046 __func__, edge_serial->rxPort, byte2);
1966 break; 2047 handle_new_lsr(edge_port, false, byte2, 0);
2048 break;
1967 2049
1968 case IOSP_STATUS_LSR_DATA: 2050 case IOSP_STATUS_LSR_DATA:
1969 dbg("%s - Port %u LSR Status = %02x, Data = %02x", __func__, edge_serial->rxPort, byte2, byte3); 2051 dbg("%s - Port %u LSR Status = %02x, Data = %02x",
1970 // byte2 is LSR Register 2052 __func__, edge_serial->rxPort, byte2, byte3);
1971 // byte3 is broken data byte 2053 /* byte2 is LSR Register */
1972 handle_new_lsr(edge_port, true, byte2, byte3); 2054 /* byte3 is broken data byte */
1973 break; 2055 handle_new_lsr(edge_port, true, byte2, byte3);
1974 // 2056 break;
1975 // case IOSP_EXT_4_STATUS: 2057 /*
1976 // dbg("%s - Port %u LSR Status = %02x Data = %02x", __func__, edge_serial->rxPort, byte2, byte3); 2058 * case IOSP_EXT_4_STATUS:
1977 // break; 2059 * dbg("%s - Port %u LSR Status = %02x Data = %02x",
1978 // 2060 * __func__, edge_serial->rxPort, byte2, byte3);
1979 case IOSP_STATUS_MSR: 2061 * break;
1980 dbg("%s - Port %u MSR Status = %02x", __func__, edge_serial->rxPort, byte2); 2062 */
1981 2063 case IOSP_STATUS_MSR:
1982 // Process this new modem status and generate appropriate 2064 dbg("%s - Port %u MSR Status = %02x",
1983 // events, etc, based on the new status. This routine 2065 __func__, edge_serial->rxPort, byte2);
1984 // also saves the MSR in Port->ShadowMsr. 2066 /*
1985 handle_new_msr(edge_port, byte2); 2067 * Process this new modem status and generate appropriate
1986 break; 2068 * events, etc, based on the new status. This routine
2069 * also saves the MSR in Port->ShadowMsr.
2070 */
2071 handle_new_msr(edge_port, byte2);
2072 break;
1987 2073
1988 default: 2074 default:
1989 dbg("%s - Unrecognized IOSP status code %u\n", __func__, code); 2075 dbg("%s - Unrecognized IOSP status code %u\n", __func__, code);
1990 break; 2076 break;
1991 } 2077 }
1992
1993 return; 2078 return;
1994} 2079}
1995 2080
@@ -1998,7 +2083,8 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1998 * edge_tty_recv 2083 * edge_tty_recv
1999 * this function passes data on to the tty flip buffer 2084 * this function passes data on to the tty flip buffer
2000 *****************************************************************************/ 2085 *****************************************************************************/
2001static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length) 2086static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
2087 unsigned char *data, int length)
2002{ 2088{
2003 int cnt; 2089 int cnt;
2004 2090
@@ -2007,7 +2093,7 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned c
2007 if (cnt < length) { 2093 if (cnt < length) {
2008 dev_err(dev, "%s - dropping data, %d bytes lost\n", 2094 dev_err(dev, "%s - dropping data, %d bytes lost\n",
2009 __func__, length - cnt); 2095 __func__, length - cnt);
2010 if(cnt == 0) 2096 if (cnt == 0)
2011 break; 2097 break;
2012 } 2098 }
2013 tty_insert_flip_string(tty, data, cnt); 2099 tty_insert_flip_string(tty, data, cnt);
@@ -2029,22 +2115,19 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2029 2115
2030 dbg("%s %02x", __func__, newMsr); 2116 dbg("%s %02x", __func__, newMsr);
2031 2117
2032 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { 2118 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
2119 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
2033 icount = &edge_port->icount; 2120 icount = &edge_port->icount;
2034 2121
2035 /* update input line counters */ 2122 /* update input line counters */
2036 if (newMsr & EDGEPORT_MSR_DELTA_CTS) { 2123 if (newMsr & EDGEPORT_MSR_DELTA_CTS)
2037 icount->cts++; 2124 icount->cts++;
2038 } 2125 if (newMsr & EDGEPORT_MSR_DELTA_DSR)
2039 if (newMsr & EDGEPORT_MSR_DELTA_DSR) {
2040 icount->dsr++; 2126 icount->dsr++;
2041 } 2127 if (newMsr & EDGEPORT_MSR_DELTA_CD)
2042 if (newMsr & EDGEPORT_MSR_DELTA_CD) {
2043 icount->dcd++; 2128 icount->dcd++;
2044 } 2129 if (newMsr & EDGEPORT_MSR_DELTA_RI)
2045 if (newMsr & EDGEPORT_MSR_DELTA_RI) {
2046 icount->rng++; 2130 icount->rng++;
2047 }
2048 wake_up_interruptible(&edge_port->delta_msr_wait); 2131 wake_up_interruptible(&edge_port->delta_msr_wait);
2049 } 2132 }
2050 2133
@@ -2059,42 +2142,41 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2059 * handle_new_lsr 2142 * handle_new_lsr
2060 * this function handles any change to the lsr register for a port. 2143 * this function handles any change to the lsr register for a port.
2061 *****************************************************************************/ 2144 *****************************************************************************/
2062static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, __u8 lsr, __u8 data) 2145static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData,
2146 __u8 lsr, __u8 data)
2063{ 2147{
2064 __u8 newLsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)); 2148 __u8 newLsr = (__u8) (lsr & (__u8)
2065 struct async_icount *icount; 2149 (LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK));
2150 struct async_icount *icount;
2066 2151
2067 dbg("%s - %02x", __func__, newLsr); 2152 dbg("%s - %02x", __func__, newLsr);
2068 2153
2069 edge_port->shadowLSR = lsr; 2154 edge_port->shadowLSR = lsr;
2070 2155
2071 if (newLsr & LSR_BREAK) { 2156 if (newLsr & LSR_BREAK) {
2072 // 2157 /*
2073 // Parity and Framing errors only count if they 2158 * Parity and Framing errors only count if they
2074 // occur exclusive of a break being 2159 * occur exclusive of a break being
2075 // received. 2160 * received.
2076 // 2161 */
2077 newLsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); 2162 newLsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
2078 } 2163 }
2079 2164
2080 /* Place LSR data byte into Rx buffer */ 2165 /* Place LSR data byte into Rx buffer */
2081 if (lsrData && edge_port->port->tty) 2166 if (lsrData && edge_port->port->port.tty)
2082 edge_tty_recv(&edge_port->port->dev, edge_port->port->tty, &data, 1); 2167 edge_tty_recv(&edge_port->port->dev,
2168 edge_port->port->port.tty, &data, 1);
2083 2169
2084 /* update input line counters */ 2170 /* update input line counters */
2085 icount = &edge_port->icount; 2171 icount = &edge_port->icount;
2086 if (newLsr & LSR_BREAK) { 2172 if (newLsr & LSR_BREAK)
2087 icount->brk++; 2173 icount->brk++;
2088 } 2174 if (newLsr & LSR_OVER_ERR)
2089 if (newLsr & LSR_OVER_ERR) {
2090 icount->overrun++; 2175 icount->overrun++;
2091 } 2176 if (newLsr & LSR_PAR_ERR)
2092 if (newLsr & LSR_PAR_ERR) {
2093 icount->parity++; 2177 icount->parity++;
2094 } 2178 if (newLsr & LSR_FRM_ERR)
2095 if (newLsr & LSR_FRM_ERR) {
2096 icount->frame++; 2179 icount->frame++;
2097 }
2098 2180
2099 return; 2181 return;
2100} 2182}
@@ -2102,12 +2184,13 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, __u8 l
2102 2184
2103/**************************************************************************** 2185/****************************************************************************
2104 * sram_write 2186 * sram_write
2105 * writes a number of bytes to the Edgeport device's sram starting at the 2187 * writes a number of bytes to the Edgeport device's sram starting at the
2106 * given address. 2188 * given address.
2107 * If successful returns the number of bytes written, otherwise it returns 2189 * If successful returns the number of bytes written, otherwise it returns
2108 * a negative error number of the problem. 2190 * a negative error number of the problem.
2109 ****************************************************************************/ 2191 ****************************************************************************/
2110static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data) 2192static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
2193 __u16 length, const __u8 *data)
2111{ 2194{
2112 int result; 2195 int result;
2113 __u16 current_length; 2196 __u16 current_length;
@@ -2115,32 +2198,37 @@ static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u1
2115 2198
2116 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); 2199 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length);
2117 2200
2118 transfer_buffer = kmalloc (64, GFP_KERNEL); 2201 transfer_buffer = kmalloc(64, GFP_KERNEL);
2119 if (!transfer_buffer) { 2202 if (!transfer_buffer) {
2120 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64); 2203 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n",
2204 __func__, 64);
2121 return -ENOMEM; 2205 return -ENOMEM;
2122 } 2206 }
2123 2207
2124 /* need to split these writes up into 64 byte chunks */ 2208 /* need to split these writes up into 64 byte chunks */
2125 result = 0; 2209 result = 0;
2126 while (length > 0) { 2210 while (length > 0) {
2127 if (length > 64) { 2211 if (length > 64)
2128 current_length = 64; 2212 current_length = 64;
2129 } else { 2213 else
2130 current_length = length; 2214 current_length = length;
2131 } 2215
2132// dbg("%s - writing %x, %x, %d", __func__, extAddr, addr, current_length); 2216/* dbg("%s - writing %x, %x, %d", __func__,
2133 memcpy (transfer_buffer, data, current_length); 2217 extAddr, addr, current_length); */
2134 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), USB_REQUEST_ION_WRITE_RAM, 2218 memcpy(transfer_buffer, data, current_length);
2135 0x40, addr, extAddr, transfer_buffer, current_length, 300); 2219 result = usb_control_msg(serial->dev,
2220 usb_sndctrlpipe(serial->dev, 0),
2221 USB_REQUEST_ION_WRITE_RAM,
2222 0x40, addr, extAddr, transfer_buffer,
2223 current_length, 300);
2136 if (result < 0) 2224 if (result < 0)
2137 break; 2225 break;
2138 length -= current_length; 2226 length -= current_length;
2139 addr += current_length; 2227 addr += current_length;
2140 data += current_length; 2228 data += current_length;
2141 } 2229 }
2142 2230
2143 kfree (transfer_buffer); 2231 kfree(transfer_buffer);
2144 return result; 2232 return result;
2145} 2233}
2146 2234
@@ -2152,40 +2240,45 @@ static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u1
2152 * If successful returns the number of bytes written, otherwise it returns 2240 * If successful returns the number of bytes written, otherwise it returns
2153 * a negative error number of the problem. 2241 * a negative error number of the problem.
2154 ****************************************************************************/ 2242 ****************************************************************************/
2155static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data) 2243static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
2244 __u16 length, const __u8 *data)
2156{ 2245{
2157 int result; 2246 int result;
2158 __u16 current_length; 2247 __u16 current_length;
2159 unsigned char *transfer_buffer; 2248 unsigned char *transfer_buffer;
2160 2249
2161// dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); 2250/* dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); */
2162 2251
2163 transfer_buffer = kmalloc (64, GFP_KERNEL); 2252 transfer_buffer = kmalloc(64, GFP_KERNEL);
2164 if (!transfer_buffer) { 2253 if (!transfer_buffer) {
2165 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64); 2254 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n",
2255 __func__, 64);
2166 return -ENOMEM; 2256 return -ENOMEM;
2167 } 2257 }
2168 2258
2169 /* need to split these writes up into 64 byte chunks */ 2259 /* need to split these writes up into 64 byte chunks */
2170 result = 0; 2260 result = 0;
2171 while (length > 0) { 2261 while (length > 0) {
2172 if (length > 64) { 2262 if (length > 64)
2173 current_length = 64; 2263 current_length = 64;
2174 } else { 2264 else
2175 current_length = length; 2265 current_length = length;
2176 } 2266/* dbg("%s - writing %x, %x, %d", __func__,
2177// dbg("%s - writing %x, %x, %d", __func__, extAddr, addr, current_length); 2267 extAddr, addr, current_length); */
2178 memcpy (transfer_buffer, data, current_length); 2268 memcpy(transfer_buffer, data, current_length);
2179 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), USB_REQUEST_ION_WRITE_ROM, 2269 result = usb_control_msg(serial->dev,
2180 0x40, addr, extAddr, transfer_buffer, current_length, 300); 2270 usb_sndctrlpipe(serial->dev, 0),
2271 USB_REQUEST_ION_WRITE_ROM, 0x40,
2272 addr, extAddr,
2273 transfer_buffer, current_length, 300);
2181 if (result < 0) 2274 if (result < 0)
2182 break; 2275 break;
2183 length -= current_length; 2276 length -= current_length;
2184 addr += current_length; 2277 addr += current_length;
2185 data += current_length; 2278 data += current_length;
2186 } 2279 }
2187 2280
2188 kfree (transfer_buffer); 2281 kfree(transfer_buffer);
2189 return result; 2282 return result;
2190} 2283}
2191 2284
@@ -2197,7 +2290,8 @@ static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16
2197 * If successful returns the number of bytes read, otherwise it returns 2290 * If successful returns the number of bytes read, otherwise it returns
2198 * a negative error number of the problem. 2291 * a negative error number of the problem.
2199 ****************************************************************************/ 2292 ****************************************************************************/
2200static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data) 2293static int rom_read(struct usb_serial *serial, __u16 extAddr,
2294 __u16 addr, __u16 length, __u8 *data)
2201{ 2295{
2202 int result; 2296 int result;
2203 __u16 current_length; 2297 __u16 current_length;
@@ -2205,32 +2299,36 @@ static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16
2205 2299
2206 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); 2300 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length);
2207 2301
2208 transfer_buffer = kmalloc (64, GFP_KERNEL); 2302 transfer_buffer = kmalloc(64, GFP_KERNEL);
2209 if (!transfer_buffer) { 2303 if (!transfer_buffer) {
2210 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64); 2304 dev_err(&serial->dev->dev,
2305 "%s - kmalloc(%d) failed.\n", __func__, 64);
2211 return -ENOMEM; 2306 return -ENOMEM;
2212 } 2307 }
2213 2308
2214 /* need to split these reads up into 64 byte chunks */ 2309 /* need to split these reads up into 64 byte chunks */
2215 result = 0; 2310 result = 0;
2216 while (length > 0) { 2311 while (length > 0) {
2217 if (length > 64) { 2312 if (length > 64)
2218 current_length = 64; 2313 current_length = 64;
2219 } else { 2314 else
2220 current_length = length; 2315 current_length = length;
2221 } 2316/* dbg("%s - %x, %x, %d", __func__,
2222// dbg("%s - %x, %x, %d", __func__, extAddr, addr, current_length); 2317 extAddr, addr, current_length); */
2223 result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), USB_REQUEST_ION_READ_ROM, 2318 result = usb_control_msg(serial->dev,
2224 0xC0, addr, extAddr, transfer_buffer, current_length, 300); 2319 usb_rcvctrlpipe(serial->dev, 0),
2320 USB_REQUEST_ION_READ_ROM,
2321 0xC0, addr, extAddr, transfer_buffer,
2322 current_length, 300);
2225 if (result < 0) 2323 if (result < 0)
2226 break; 2324 break;
2227 memcpy (data, transfer_buffer, current_length); 2325 memcpy(data, transfer_buffer, current_length);
2228 length -= current_length; 2326 length -= current_length;
2229 addr += current_length; 2327 addr += current_length;
2230 data += current_length; 2328 data += current_length;
2231 } 2329 }
2232 2330
2233 kfree (transfer_buffer); 2331 kfree(transfer_buffer);
2234 return result; 2332 return result;
2235} 2333}
2236 2334
@@ -2239,7 +2337,8 @@ static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16
2239 * send_iosp_ext_cmd 2337 * send_iosp_ext_cmd
2240 * Is used to send a IOSP message to the Edgeport device 2338 * Is used to send a IOSP message to the Edgeport device
2241 ****************************************************************************/ 2339 ****************************************************************************/
2242static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u8 param) 2340static int send_iosp_ext_cmd(struct edgeport_port *edge_port,
2341 __u8 command, __u8 param)
2243{ 2342{
2244 unsigned char *buffer; 2343 unsigned char *buffer;
2245 unsigned char *currentCommand; 2344 unsigned char *currentCommand;
@@ -2248,19 +2347,20 @@ static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u
2248 2347
2249 dbg("%s - %d, %d", __func__, command, param); 2348 dbg("%s - %d, %d", __func__, command, param);
2250 2349
2251 buffer = kmalloc (10, GFP_ATOMIC); 2350 buffer = kmalloc(10, GFP_ATOMIC);
2252 if (!buffer) { 2351 if (!buffer) {
2253 dev_err(&edge_port->port->dev, "%s - kmalloc(%d) failed.\n", __func__, 10); 2352 dev_err(&edge_port->port->dev,
2353 "%s - kmalloc(%d) failed.\n", __func__, 10);
2254 return -ENOMEM; 2354 return -ENOMEM;
2255 } 2355 }
2256 2356
2257 currentCommand = buffer; 2357 currentCommand = buffer;
2258 2358
2259 MAKE_CMD_EXT_CMD (&currentCommand, &length, 2359 MAKE_CMD_EXT_CMD(&currentCommand, &length,
2260 edge_port->port->number - edge_port->port->serial->minor, 2360 edge_port->port->number - edge_port->port->serial->minor,
2261 command, param); 2361 command, param);
2262 2362
2263 status = write_cmd_usb (edge_port, buffer, length); 2363 status = write_cmd_usb(edge_port, buffer, length);
2264 if (status) { 2364 if (status) {
2265 /* something bad happened, let's free up the memory */ 2365 /* something bad happened, let's free up the memory */
2266 kfree(buffer); 2366 kfree(buffer);
@@ -2274,43 +2374,50 @@ static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u
2274 * write_cmd_usb 2374 * write_cmd_usb
2275 * this function writes the given buffer out to the bulk write endpoint. 2375 * this function writes the given buffer out to the bulk write endpoint.
2276 *****************************************************************************/ 2376 *****************************************************************************/
2277static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer, int length) 2377static int write_cmd_usb(struct edgeport_port *edge_port,
2378 unsigned char *buffer, int length)
2278{ 2379{
2279 struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); 2380 struct edgeport_serial *edge_serial =
2381 usb_get_serial_data(edge_port->port->serial);
2280 int status = 0; 2382 int status = 0;
2281 struct urb *urb; 2383 struct urb *urb;
2282 int timeout; 2384 int timeout;
2283 2385
2284 usb_serial_debug_data(debug, &edge_port->port->dev, __func__, length, buffer); 2386 usb_serial_debug_data(debug, &edge_port->port->dev,
2387 __func__, length, buffer);
2285 2388
2286 /* Allocate our next urb */ 2389 /* Allocate our next urb */
2287 urb = usb_alloc_urb (0, GFP_ATOMIC); 2390 urb = usb_alloc_urb(0, GFP_ATOMIC);
2288 if (!urb) 2391 if (!urb)
2289 return -ENOMEM; 2392 return -ENOMEM;
2290 2393
2291 atomic_inc(&CmdUrbs); 2394 atomic_inc(&CmdUrbs);
2292 dbg("%s - ALLOCATE URB %p (outstanding %d)", __func__, urb, atomic_read(&CmdUrbs)); 2395 dbg("%s - ALLOCATE URB %p (outstanding %d)",
2396 __func__, urb, atomic_read(&CmdUrbs));
2293 2397
2294 usb_fill_bulk_urb (urb, edge_serial->serial->dev, 2398 usb_fill_bulk_urb(urb, edge_serial->serial->dev,
2295 usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint), 2399 usb_sndbulkpipe(edge_serial->serial->dev,
2296 buffer, length, edge_bulk_out_cmd_callback, edge_port); 2400 edge_serial->bulk_out_endpoint),
2401 buffer, length, edge_bulk_out_cmd_callback, edge_port);
2297 2402
2298 edge_port->commandPending = true; 2403 edge_port->commandPending = true;
2299 status = usb_submit_urb(urb, GFP_ATOMIC); 2404 status = usb_submit_urb(urb, GFP_ATOMIC);
2300 2405
2301 if (status) { 2406 if (status) {
2302 /* something went wrong */ 2407 /* something went wrong */
2303 dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write command) failed, status = %d\n", __func__, status); 2408 dev_err(&edge_port->port->dev,
2409 "%s - usb_submit_urb(write command) failed, status = %d\n",
2410 __func__, status);
2304 usb_kill_urb(urb); 2411 usb_kill_urb(urb);
2305 usb_free_urb(urb); 2412 usb_free_urb(urb);
2306 atomic_dec(&CmdUrbs); 2413 atomic_dec(&CmdUrbs);
2307 return status; 2414 return status;
2308 } 2415 }
2309 2416
2310 // wait for command to finish 2417 /* wait for command to finish */
2311 timeout = COMMAND_TIMEOUT; 2418 timeout = COMMAND_TIMEOUT;
2312#if 0 2419#if 0
2313 wait_event (&edge_port->wait_command, !edge_port->commandPending); 2420 wait_event(&edge_port->wait_command, !edge_port->commandPending);
2314 2421
2315 if (edge_port->commandPending) { 2422 if (edge_port->commandPending) {
2316 /* command timed out */ 2423 /* command timed out */
@@ -2327,15 +2434,18 @@ static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer
2327 * this function sends the proper command to change the baud rate of the 2434 * this function sends the proper command to change the baud rate of the
2328 * specified port. 2435 * specified port.
2329 *****************************************************************************/ 2436 *****************************************************************************/
2330static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRate) 2437static int send_cmd_write_baud_rate(struct edgeport_port *edge_port,
2438 int baudRate)
2331{ 2439{
2332 struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); 2440 struct edgeport_serial *edge_serial =
2441 usb_get_serial_data(edge_port->port->serial);
2333 unsigned char *cmdBuffer; 2442 unsigned char *cmdBuffer;
2334 unsigned char *currCmd; 2443 unsigned char *currCmd;
2335 int cmdLen = 0; 2444 int cmdLen = 0;
2336 int divisor; 2445 int divisor;
2337 int status; 2446 int status;
2338 unsigned char number = edge_port->port->number - edge_port->port->serial->minor; 2447 unsigned char number =
2448 edge_port->port->number - edge_port->port->serial->minor;
2339 2449
2340 if (edge_serial->is_epic && 2450 if (edge_serial->is_epic &&
2341 !edge_serial->epic_descriptor.Supports.IOSPSetBaudRate) { 2451 !edge_serial->epic_descriptor.Supports.IOSPSetBaudRate) {
@@ -2344,36 +2454,40 @@ static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRa
2344 return 0; 2454 return 0;
2345 } 2455 }
2346 2456
2347 dbg("%s - port = %d, baud = %d", __func__, edge_port->port->number, baudRate); 2457 dbg("%s - port = %d, baud = %d", __func__,
2458 edge_port->port->number, baudRate);
2348 2459
2349 status = calc_baud_rate_divisor (baudRate, &divisor); 2460 status = calc_baud_rate_divisor(baudRate, &divisor);
2350 if (status) { 2461 if (status) {
2351 dev_err(&edge_port->port->dev, "%s - bad baud rate\n", __func__); 2462 dev_err(&edge_port->port->dev, "%s - bad baud rate\n",
2463 __func__);
2352 return status; 2464 return status;
2353 } 2465 }
2354 2466
2355 // Alloc memory for the string of commands. 2467 /* Alloc memory for the string of commands. */
2356 cmdBuffer = kmalloc (0x100, GFP_ATOMIC); 2468 cmdBuffer = kmalloc(0x100, GFP_ATOMIC);
2357 if (!cmdBuffer) { 2469 if (!cmdBuffer) {
2358 dev_err(&edge_port->port->dev, "%s - kmalloc(%d) failed.\n", __func__, 0x100); 2470 dev_err(&edge_port->port->dev,
2471 "%s - kmalloc(%d) failed.\n", __func__, 0x100);
2359 return -ENOMEM; 2472 return -ENOMEM;
2360 } 2473 }
2361 currCmd = cmdBuffer; 2474 currCmd = cmdBuffer;
2362 2475
2363 // Enable access to divisor latch 2476 /* Enable access to divisor latch */
2364 MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, LCR, LCR_DL_ENABLE ); 2477 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR, LCR_DL_ENABLE);
2365 2478
2366 // Write the divisor itself 2479 /* Write the divisor itself */
2367 MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, DLL, LOW8 (divisor) ); 2480 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, DLL, LOW8(divisor));
2368 MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, DLM, HIGH8(divisor) ); 2481 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, DLM, HIGH8(divisor));
2369 2482
2370 // Restore original value to disable access to divisor latch 2483 /* Restore original value to disable access to divisor latch */
2371 MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, LCR, edge_port->shadowLCR); 2484 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR,
2485 edge_port->shadowLCR);
2372 2486
2373 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen ); 2487 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen);
2374 if (status) { 2488 if (status) {
2375 /* something bad happened, let's free up the memory */ 2489 /* something bad happened, let's free up the memory */
2376 kfree (cmdBuffer); 2490 kfree(cmdBuffer);
2377 } 2491 }
2378 2492
2379 return status; 2493 return status;
@@ -2385,7 +2499,7 @@ static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRa
2385 * this function calculates the proper baud rate divisor for the specified 2499 * this function calculates the proper baud rate divisor for the specified
2386 * baud rate. 2500 * baud rate.
2387 *****************************************************************************/ 2501 *****************************************************************************/
2388static int calc_baud_rate_divisor (int baudrate, int *divisor) 2502static int calc_baud_rate_divisor(int baudrate, int *divisor)
2389{ 2503{
2390 int i; 2504 int i;
2391 __u16 custom; 2505 __u16 custom;
@@ -2394,17 +2508,17 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor)
2394 dbg("%s - %d", __func__, baudrate); 2508 dbg("%s - %d", __func__, baudrate);
2395 2509
2396 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) { 2510 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) {
2397 if ( divisor_table[i].BaudRate == baudrate ) { 2511 if (divisor_table[i].BaudRate == baudrate) {
2398 *divisor = divisor_table[i].Divisor; 2512 *divisor = divisor_table[i].Divisor;
2399 return 0; 2513 return 0;
2400 } 2514 }
2401 } 2515 }
2402 2516
2403 // We have tried all of the standard baud rates 2517 /* We have tried all of the standard baud rates
2404 // lets try to calculate the divisor for this baud rate 2518 * lets try to calculate the divisor for this baud rate
2405 // Make sure the baud rate is reasonable 2519 * Make sure the baud rate is reasonable */
2406 if (baudrate > 50 && baudrate < 230400) { 2520 if (baudrate > 50 && baudrate < 230400) {
2407 // get divisor 2521 /* get divisor */
2408 custom = (__u16)((230400L + baudrate/2) / baudrate); 2522 custom = (__u16)((230400L + baudrate/2) / baudrate);
2409 2523
2410 *divisor = custom; 2524 *divisor = custom;
@@ -2419,17 +2533,20 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor)
2419 2533
2420/***************************************************************************** 2534/*****************************************************************************
2421 * send_cmd_write_uart_register 2535 * send_cmd_write_uart_register
2422 * this function builds up a uart register message and sends to to the device. 2536 * this function builds up a uart register message and sends to to the device.
2423 *****************************************************************************/ 2537 *****************************************************************************/
2424static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 regNum, __u8 regValue) 2538static int send_cmd_write_uart_register(struct edgeport_port *edge_port,
2539 __u8 regNum, __u8 regValue)
2425{ 2540{
2426 struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); 2541 struct edgeport_serial *edge_serial =
2542 usb_get_serial_data(edge_port->port->serial);
2427 unsigned char *cmdBuffer; 2543 unsigned char *cmdBuffer;
2428 unsigned char *currCmd; 2544 unsigned char *currCmd;
2429 unsigned long cmdLen = 0; 2545 unsigned long cmdLen = 0;
2430 int status; 2546 int status;
2431 2547
2432 dbg("%s - write to %s register 0x%02x", (regNum == MCR) ? "MCR" : "LCR", __func__, regValue); 2548 dbg("%s - write to %s register 0x%02x",
2549 (regNum == MCR) ? "MCR" : "LCR", __func__, regValue);
2433 2550
2434 if (edge_serial->is_epic && 2551 if (edge_serial->is_epic &&
2435 !edge_serial->epic_descriptor.Supports.IOSPWriteMCR && 2552 !edge_serial->epic_descriptor.Supports.IOSPWriteMCR &&
@@ -2441,27 +2558,26 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r
2441 if (edge_serial->is_epic && 2558 if (edge_serial->is_epic &&
2442 !edge_serial->epic_descriptor.Supports.IOSPWriteLCR && 2559 !edge_serial->epic_descriptor.Supports.IOSPWriteLCR &&
2443 regNum == LCR) { 2560 regNum == LCR) {
2444 dbg ("SendCmdWriteUartReg - Not writing to LCR Register"); 2561 dbg("SendCmdWriteUartReg - Not writing to LCR Register");
2445 return 0; 2562 return 0;
2446 } 2563 }
2447 2564
2448 // Alloc memory for the string of commands. 2565 /* Alloc memory for the string of commands. */
2449 cmdBuffer = kmalloc (0x10, GFP_ATOMIC); 2566 cmdBuffer = kmalloc(0x10, GFP_ATOMIC);
2450 if (cmdBuffer == NULL ) { 2567 if (cmdBuffer == NULL)
2451 return -ENOMEM; 2568 return -ENOMEM;
2452 }
2453 2569
2454 currCmd = cmdBuffer; 2570 currCmd = cmdBuffer;
2455 2571
2456 // Build a cmd in the buffer to write the given register 2572 /* Build a cmd in the buffer to write the given register */
2457 MAKE_CMD_WRITE_REG (&currCmd, &cmdLen, 2573 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen,
2458 edge_port->port->number - edge_port->port->serial->minor, 2574 edge_port->port->number - edge_port->port->serial->minor,
2459 regNum, regValue); 2575 regNum, regValue);
2460 2576
2461 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen); 2577 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen);
2462 if (status) { 2578 if (status) {
2463 /* something bad happened, let's free up the memory */ 2579 /* something bad happened, let's free up the memory */
2464 kfree (cmdBuffer); 2580 kfree(cmdBuffer);
2465 } 2581 }
2466 2582
2467 return status; 2583 return status;
@@ -2470,16 +2586,15 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r
2470 2586
2471/***************************************************************************** 2587/*****************************************************************************
2472 * change_port_settings 2588 * change_port_settings
2473 * This routine is called to set the UART on the device to match the specified 2589 * This routine is called to set the UART on the device to match the
2474 * new settings. 2590 * specified new settings.
2475 *****************************************************************************/ 2591 *****************************************************************************/
2476#ifndef CMSPAR 2592
2477#define CMSPAR 0 2593static void change_port_settings(struct tty_struct *tty,
2478#endif 2594 struct edgeport_port *edge_port, struct ktermios *old_termios)
2479static void change_port_settings (struct edgeport_port *edge_port, struct ktermios *old_termios)
2480{ 2595{
2481 struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); 2596 struct edgeport_serial *edge_serial =
2482 struct tty_struct *tty; 2597 usb_get_serial_data(edge_port->port->serial);
2483 int baud; 2598 int baud;
2484 unsigned cflag; 2599 unsigned cflag;
2485 __u8 mask = 0xff; 2600 __u8 mask = 0xff;
@@ -2498,21 +2613,26 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2498 return; 2613 return;
2499 } 2614 }
2500 2615
2501 tty = edge_port->port->tty;
2502 if ((!tty) ||
2503 (!tty->termios)) {
2504 dbg("%s - no tty structures", __func__);
2505 return;
2506 }
2507
2508 cflag = tty->termios->c_cflag; 2616 cflag = tty->termios->c_cflag;
2509 2617
2510 switch (cflag & CSIZE) { 2618 switch (cflag & CSIZE) {
2511 case CS5: lData = LCR_BITS_5; mask = 0x1f; dbg("%s - data bits = 5", __func__); break; 2619 case CS5:
2512 case CS6: lData = LCR_BITS_6; mask = 0x3f; dbg("%s - data bits = 6", __func__); break; 2620 lData = LCR_BITS_5; mask = 0x1f;
2513 case CS7: lData = LCR_BITS_7; mask = 0x7f; dbg("%s - data bits = 7", __func__); break; 2621 dbg("%s - data bits = 5", __func__);
2514 default: 2622 break;
2515 case CS8: lData = LCR_BITS_8; dbg("%s - data bits = 8", __func__); break; 2623 case CS6:
2624 lData = LCR_BITS_6; mask = 0x3f;
2625 dbg("%s - data bits = 6", __func__);
2626 break;
2627 case CS7:
2628 lData = LCR_BITS_7; mask = 0x7f;
2629 dbg("%s - data bits = 7", __func__);
2630 break;
2631 default:
2632 case CS8:
2633 lData = LCR_BITS_8;
2634 dbg("%s - data bits = 8", __func__);
2635 break;
2516 } 2636 }
2517 2637
2518 lParity = LCR_PAR_NONE; 2638 lParity = LCR_PAR_NONE;
@@ -2554,7 +2674,8 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2554 dbg("%s - RTS/CTS is disabled", __func__); 2674 dbg("%s - RTS/CTS is disabled", __func__);
2555 } 2675 }
2556 2676
2557 /* if we are implementing XON/XOFF, set the start and stop character in the device */ 2677 /* if we are implementing XON/XOFF, set the start and stop character
2678 in the device */
2558 if (I_IXOFF(tty) || I_IXON(tty)) { 2679 if (I_IXOFF(tty) || I_IXON(tty)) {
2559 unsigned char stop_char = STOP_CHAR(tty); 2680 unsigned char stop_char = STOP_CHAR(tty);
2560 unsigned char start_char = START_CHAR(tty); 2681 unsigned char start_char = START_CHAR(tty);
@@ -2562,14 +2683,17 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2562 if ((!edge_serial->is_epic) || 2683 if ((!edge_serial->is_epic) ||
2563 ((edge_serial->is_epic) && 2684 ((edge_serial->is_epic) &&
2564 (edge_serial->epic_descriptor.Supports.IOSPSetXChar))) { 2685 (edge_serial->epic_descriptor.Supports.IOSPSetXChar))) {
2565 send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_XON_CHAR, start_char); 2686 send_iosp_ext_cmd(edge_port,
2566 send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_XOFF_CHAR, stop_char); 2687 IOSP_CMD_SET_XON_CHAR, start_char);
2688 send_iosp_ext_cmd(edge_port,
2689 IOSP_CMD_SET_XOFF_CHAR, stop_char);
2567 } 2690 }
2568 2691
2569 /* if we are implementing INBOUND XON/XOFF */ 2692 /* if we are implementing INBOUND XON/XOFF */
2570 if (I_IXOFF(tty)) { 2693 if (I_IXOFF(tty)) {
2571 rxFlow |= IOSP_RX_FLOW_XON_XOFF; 2694 rxFlow |= IOSP_RX_FLOW_XON_XOFF;
2572 dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", __func__, start_char, stop_char); 2695 dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2696 __func__, start_char, stop_char);
2573 } else { 2697 } else {
2574 dbg("%s - INBOUND XON/XOFF is disabled", __func__); 2698 dbg("%s - INBOUND XON/XOFF is disabled", __func__);
2575 } 2699 }
@@ -2577,7 +2701,8 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2577 /* if we are implementing OUTBOUND XON/XOFF */ 2701 /* if we are implementing OUTBOUND XON/XOFF */
2578 if (I_IXON(tty)) { 2702 if (I_IXON(tty)) {
2579 txFlow |= IOSP_TX_FLOW_XON_XOFF; 2703 txFlow |= IOSP_TX_FLOW_XON_XOFF;
2580 dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", __func__, start_char, stop_char); 2704 dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2705 __func__, start_char, stop_char);
2581 } else { 2706 } else {
2582 dbg("%s - OUTBOUND XON/XOFF is disabled", __func__); 2707 dbg("%s - OUTBOUND XON/XOFF is disabled", __func__);
2583 } 2708 }
@@ -2600,20 +2725,20 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2600 edge_port->validDataMask = mask; 2725 edge_port->validDataMask = mask;
2601 2726
2602 /* Send the updated LCR value to the EdgePort */ 2727 /* Send the updated LCR value to the EdgePort */
2603 status = send_cmd_write_uart_register(edge_port, LCR, edge_port->shadowLCR); 2728 status = send_cmd_write_uart_register(edge_port, LCR,
2604 if (status != 0) { 2729 edge_port->shadowLCR);
2730 if (status != 0)
2605 return; 2731 return;
2606 }
2607 2732
2608 /* set up the MCR register and send it to the EdgePort */ 2733 /* set up the MCR register and send it to the EdgePort */
2609 edge_port->shadowMCR = MCR_MASTER_IE; 2734 edge_port->shadowMCR = MCR_MASTER_IE;
2610 if (cflag & CBAUD) { 2735 if (cflag & CBAUD)
2611 edge_port->shadowMCR |= (MCR_DTR | MCR_RTS); 2736 edge_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2612 } 2737
2613 status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); 2738 status = send_cmd_write_uart_register(edge_port, MCR,
2614 if (status != 0) { 2739 edge_port->shadowMCR);
2740 if (status != 0)
2615 return; 2741 return;
2616 }
2617 2742
2618 /* Determine divisor based on baud rate */ 2743 /* Determine divisor based on baud rate */
2619 baud = tty_get_baud_rate(tty); 2744 baud = tty_get_baud_rate(tty);
@@ -2623,7 +2748,7 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2623 } 2748 }
2624 2749
2625 dbg("%s - baud rate = %d", __func__, baud); 2750 dbg("%s - baud rate = %d", __func__, baud);
2626 status = send_cmd_write_baud_rate (edge_port, baud); 2751 status = send_cmd_write_baud_rate(edge_port, baud);
2627 if (status == -1) { 2752 if (status == -1) {
2628 /* Speed change was not possible - put back the old speed */ 2753 /* Speed change was not possible - put back the old speed */
2629 baud = tty_termios_baud_rate(old_termios); 2754 baud = tty_termios_baud_rate(old_termios);
@@ -2640,7 +2765,8 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2640 * ASCII range, but it's only for debugging... 2765 * ASCII range, but it's only for debugging...
2641 * NOTE: expects the unicode in LE format 2766 * NOTE: expects the unicode in LE format
2642 ****************************************************************************/ 2767 ****************************************************************************/
2643static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unicode_size) 2768static void unicode_to_ascii(char *string, int buflen,
2769 __le16 *unicode, int unicode_size)
2644{ 2770{
2645 int i; 2771 int i;
2646 2772
@@ -2659,75 +2785,99 @@ static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unic
2659 2785
2660/**************************************************************************** 2786/****************************************************************************
2661 * get_manufacturing_desc 2787 * get_manufacturing_desc
2662 * reads in the manufacturing descriptor and stores it into the serial 2788 * reads in the manufacturing descriptor and stores it into the serial
2663 * structure. 2789 * structure.
2664 ****************************************************************************/ 2790 ****************************************************************************/
2665static void get_manufacturing_desc (struct edgeport_serial *edge_serial) 2791static void get_manufacturing_desc(struct edgeport_serial *edge_serial)
2666{ 2792{
2667 int response; 2793 int response;
2668 2794
2669 dbg("getting manufacturer descriptor"); 2795 dbg("getting manufacturer descriptor");
2670 2796
2671 response = rom_read (edge_serial->serial, (EDGE_MANUF_DESC_ADDR & 0xffff0000) >> 16, 2797 response = rom_read(edge_serial->serial,
2672 (__u16)(EDGE_MANUF_DESC_ADDR & 0x0000ffff), EDGE_MANUF_DESC_LEN, 2798 (EDGE_MANUF_DESC_ADDR & 0xffff0000) >> 16,
2673 (__u8 *)(&edge_serial->manuf_descriptor)); 2799 (__u16)(EDGE_MANUF_DESC_ADDR & 0x0000ffff),
2800 EDGE_MANUF_DESC_LEN,
2801 (__u8 *)(&edge_serial->manuf_descriptor));
2674 2802
2675 if (response < 1) { 2803 if (response < 1)
2676 dev_err(&edge_serial->serial->dev->dev, "error in getting manufacturer descriptor\n"); 2804 dev_err(&edge_serial->serial->dev->dev,
2677 } else { 2805 "error in getting manufacturer descriptor\n");
2806 else {
2678 char string[30]; 2807 char string[30];
2679 dbg("**Manufacturer Descriptor"); 2808 dbg("**Manufacturer Descriptor");
2680 dbg(" RomSize: %dK", edge_serial->manuf_descriptor.RomSize); 2809 dbg(" RomSize: %dK",
2681 dbg(" RamSize: %dK", edge_serial->manuf_descriptor.RamSize); 2810 edge_serial->manuf_descriptor.RomSize);
2682 dbg(" CpuRev: %d", edge_serial->manuf_descriptor.CpuRev); 2811 dbg(" RamSize: %dK",
2683 dbg(" BoardRev: %d", edge_serial->manuf_descriptor.BoardRev); 2812 edge_serial->manuf_descriptor.RamSize);
2684 dbg(" NumPorts: %d", edge_serial->manuf_descriptor.NumPorts); 2813 dbg(" CpuRev: %d",
2685 dbg(" DescDate: %d/%d/%d", edge_serial->manuf_descriptor.DescDate[0], edge_serial->manuf_descriptor.DescDate[1], edge_serial->manuf_descriptor.DescDate[2]+1900); 2814 edge_serial->manuf_descriptor.CpuRev);
2815 dbg(" BoardRev: %d",
2816 edge_serial->manuf_descriptor.BoardRev);
2817 dbg(" NumPorts: %d",
2818 edge_serial->manuf_descriptor.NumPorts);
2819 dbg(" DescDate: %d/%d/%d",
2820 edge_serial->manuf_descriptor.DescDate[0],
2821 edge_serial->manuf_descriptor.DescDate[1],
2822 edge_serial->manuf_descriptor.DescDate[2]+1900);
2686 unicode_to_ascii(string, sizeof(string), 2823 unicode_to_ascii(string, sizeof(string),
2687 edge_serial->manuf_descriptor.SerialNumber, 2824 edge_serial->manuf_descriptor.SerialNumber,
2688 edge_serial->manuf_descriptor.SerNumLength/2); 2825 edge_serial->manuf_descriptor.SerNumLength/2);
2689 dbg(" SerialNumber: %s", string); 2826 dbg(" SerialNumber: %s", string);
2690 unicode_to_ascii(string, sizeof(string), 2827 unicode_to_ascii(string, sizeof(string),
2691 edge_serial->manuf_descriptor.AssemblyNumber, 2828 edge_serial->manuf_descriptor.AssemblyNumber,
2692 edge_serial->manuf_descriptor.AssemblyNumLength/2); 2829 edge_serial->manuf_descriptor.AssemblyNumLength/2);
2693 dbg(" AssemblyNumber: %s", string); 2830 dbg(" AssemblyNumber: %s", string);
2694 unicode_to_ascii(string, sizeof(string), 2831 unicode_to_ascii(string, sizeof(string),
2695 edge_serial->manuf_descriptor.OemAssyNumber, 2832 edge_serial->manuf_descriptor.OemAssyNumber,
2696 edge_serial->manuf_descriptor.OemAssyNumLength/2); 2833 edge_serial->manuf_descriptor.OemAssyNumLength/2);
2697 dbg(" OemAssyNumber: %s", string); 2834 dbg(" OemAssyNumber: %s", string);
2698 dbg(" UartType: %d", edge_serial->manuf_descriptor.UartType); 2835 dbg(" UartType: %d",
2699 dbg(" IonPid: %d", edge_serial->manuf_descriptor.IonPid); 2836 edge_serial->manuf_descriptor.UartType);
2700 dbg(" IonConfig: %d", edge_serial->manuf_descriptor.IonConfig); 2837 dbg(" IonPid: %d",
2838 edge_serial->manuf_descriptor.IonPid);
2839 dbg(" IonConfig: %d",
2840 edge_serial->manuf_descriptor.IonConfig);
2701 } 2841 }
2702} 2842}
2703 2843
2704 2844
2705/**************************************************************************** 2845/****************************************************************************
2706 * get_boot_desc 2846 * get_boot_desc
2707 * reads in the bootloader descriptor and stores it into the serial 2847 * reads in the bootloader descriptor and stores it into the serial
2708 * structure. 2848 * structure.
2709 ****************************************************************************/ 2849 ****************************************************************************/
2710static void get_boot_desc (struct edgeport_serial *edge_serial) 2850static void get_boot_desc(struct edgeport_serial *edge_serial)
2711{ 2851{
2712 int response; 2852 int response;
2713 2853
2714 dbg("getting boot descriptor"); 2854 dbg("getting boot descriptor");
2715 2855
2716 response = rom_read (edge_serial->serial, (EDGE_BOOT_DESC_ADDR & 0xffff0000) >> 16, 2856 response = rom_read(edge_serial->serial,
2717 (__u16)(EDGE_BOOT_DESC_ADDR & 0x0000ffff), EDGE_BOOT_DESC_LEN, 2857 (EDGE_BOOT_DESC_ADDR & 0xffff0000) >> 16,
2718 (__u8 *)(&edge_serial->boot_descriptor)); 2858 (__u16)(EDGE_BOOT_DESC_ADDR & 0x0000ffff),
2859 EDGE_BOOT_DESC_LEN,
2860 (__u8 *)(&edge_serial->boot_descriptor));
2719 2861
2720 if (response < 1) { 2862 if (response < 1)
2721 dev_err(&edge_serial->serial->dev->dev, "error in getting boot descriptor\n"); 2863 dev_err(&edge_serial->serial->dev->dev,
2722 } else { 2864 "error in getting boot descriptor\n");
2865 else {
2723 dbg("**Boot Descriptor:"); 2866 dbg("**Boot Descriptor:");
2724 dbg(" BootCodeLength: %d", le16_to_cpu(edge_serial->boot_descriptor.BootCodeLength)); 2867 dbg(" BootCodeLength: %d",
2725 dbg(" MajorVersion: %d", edge_serial->boot_descriptor.MajorVersion); 2868 le16_to_cpu(edge_serial->boot_descriptor.BootCodeLength));
2726 dbg(" MinorVersion: %d", edge_serial->boot_descriptor.MinorVersion); 2869 dbg(" MajorVersion: %d",
2727 dbg(" BuildNumber: %d", le16_to_cpu(edge_serial->boot_descriptor.BuildNumber)); 2870 edge_serial->boot_descriptor.MajorVersion);
2728 dbg(" Capabilities: 0x%x", le16_to_cpu(edge_serial->boot_descriptor.Capabilities)); 2871 dbg(" MinorVersion: %d",
2729 dbg(" UConfig0: %d", edge_serial->boot_descriptor.UConfig0); 2872 edge_serial->boot_descriptor.MinorVersion);
2730 dbg(" UConfig1: %d", edge_serial->boot_descriptor.UConfig1); 2873 dbg(" BuildNumber: %d",
2874 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber));
2875 dbg(" Capabilities: 0x%x",
2876 le16_to_cpu(edge_serial->boot_descriptor.Capabilities));
2877 dbg(" UConfig0: %d",
2878 edge_serial->boot_descriptor.UConfig0);
2879 dbg(" UConfig1: %d",
2880 edge_serial->boot_descriptor.UConfig1);
2731 } 2881 }
2732} 2882}
2733 2883
@@ -2736,7 +2886,7 @@ static void get_boot_desc (struct edgeport_serial *edge_serial)
2736 * load_application_firmware 2886 * load_application_firmware
2737 * This is called to load the application firmware to the device 2887 * This is called to load the application firmware to the device
2738 ****************************************************************************/ 2888 ****************************************************************************/
2739static void load_application_firmware (struct edgeport_serial *edge_serial) 2889static void load_application_firmware(struct edgeport_serial *edge_serial)
2740{ 2890{
2741 const struct ihex_binrec *rec; 2891 const struct ihex_binrec *rec;
2742 const struct firmware *fw; 2892 const struct firmware *fw;
@@ -2813,7 +2963,7 @@ static void load_application_firmware (struct edgeport_serial *edge_serial)
2813/**************************************************************************** 2963/****************************************************************************
2814 * edge_startup 2964 * edge_startup
2815 ****************************************************************************/ 2965 ****************************************************************************/
2816static int edge_startup (struct usb_serial *serial) 2966static int edge_startup(struct usb_serial *serial)
2817{ 2967{
2818 struct edgeport_serial *edge_serial; 2968 struct edgeport_serial *edge_serial;
2819 struct edgeport_port *edge_port; 2969 struct edgeport_port *edge_port;
@@ -2855,10 +3005,10 @@ static int edge_startup (struct usb_serial *serial)
2855 sizeof(struct edge_compatibility_bits)); 3005 sizeof(struct edge_compatibility_bits));
2856 3006
2857 /* get the manufacturing descriptor for this device */ 3007 /* get the manufacturing descriptor for this device */
2858 get_manufacturing_desc (edge_serial); 3008 get_manufacturing_desc(edge_serial);
2859 3009
2860 /* get the boot descriptor */ 3010 /* get the boot descriptor */
2861 get_boot_desc (edge_serial); 3011 get_boot_desc(edge_serial);
2862 3012
2863 get_product_info(edge_serial); 3013 get_product_info(edge_serial);
2864 } 3014 }
@@ -2879,41 +3029,43 @@ static int edge_startup (struct usb_serial *serial)
2879 /* If not an EPiC device */ 3029 /* If not an EPiC device */
2880 if (!edge_serial->is_epic) { 3030 if (!edge_serial->is_epic) {
2881 /* now load the application firmware into this device */ 3031 /* now load the application firmware into this device */
2882 load_application_firmware (edge_serial); 3032 load_application_firmware(edge_serial);
2883 3033
2884 dbg("%s - time 2 %ld", __func__, jiffies); 3034 dbg("%s - time 2 %ld", __func__, jiffies);
2885 3035
2886 /* Check current Edgeport EEPROM and update if necessary */ 3036 /* Check current Edgeport EEPROM and update if necessary */
2887 update_edgeport_E2PROM (edge_serial); 3037 update_edgeport_E2PROM(edge_serial);
2888 3038
2889 dbg("%s - time 3 %ld", __func__, jiffies); 3039 dbg("%s - time 3 %ld", __func__, jiffies);
2890 3040
2891 /* set the configuration to use #1 */ 3041 /* set the configuration to use #1 */
2892// dbg("set_configuration 1"); 3042/* dbg("set_configuration 1"); */
2893// usb_set_configuration (dev, 1); 3043/* usb_set_configuration (dev, 1); */
2894 } 3044 }
2895 dbg(" FirmwareMajorVersion %d.%d.%d", 3045 dbg(" FirmwareMajorVersion %d.%d.%d",
2896 edge_serial->product_info.FirmwareMajorVersion, 3046 edge_serial->product_info.FirmwareMajorVersion,
2897 edge_serial->product_info.FirmwareMinorVersion, 3047 edge_serial->product_info.FirmwareMinorVersion,
2898 le16_to_cpu(edge_serial->product_info.FirmwareBuildNumber)); 3048 le16_to_cpu(edge_serial->product_info.FirmwareBuildNumber));
2899 3049
2900 /* we set up the pointers to the endpoints in the edge_open function, 3050 /* we set up the pointers to the endpoints in the edge_open function,
2901 * as the structures aren't created yet. */ 3051 * as the structures aren't created yet. */
2902 3052
2903 /* set up our port private structures */ 3053 /* set up our port private structures */
2904 for (i = 0; i < serial->num_ports; ++i) { 3054 for (i = 0; i < serial->num_ports; ++i) {
2905 edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL); 3055 edge_port = kmalloc(sizeof(struct edgeport_port), GFP_KERNEL);
2906 if (edge_port == NULL) { 3056 if (edge_port == NULL) {
2907 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); 3057 dev_err(&serial->dev->dev, "%s - Out of memory\n",
3058 __func__);
2908 for (j = 0; j < i; ++j) { 3059 for (j = 0; j < i; ++j) {
2909 kfree (usb_get_serial_port_data(serial->port[j])); 3060 kfree(usb_get_serial_port_data(serial->port[j]));
2910 usb_set_serial_port_data(serial->port[j], NULL); 3061 usb_set_serial_port_data(serial->port[j],
3062 NULL);
2911 } 3063 }
2912 usb_set_serial_data(serial, NULL); 3064 usb_set_serial_data(serial, NULL);
2913 kfree(edge_serial); 3065 kfree(edge_serial);
2914 return -ENOMEM; 3066 return -ENOMEM;
2915 } 3067 }
2916 memset (edge_port, 0, sizeof(struct edgeport_port)); 3068 memset(edge_port, 0, sizeof(struct edgeport_port));
2917 spin_lock_init(&edge_port->ep_lock); 3069 spin_lock_init(&edge_port->ep_lock);
2918 edge_port->port = serial->port[i]; 3070 edge_port->port = serial->port[i];
2919 usb_set_serial_port_data(serial->port[i], edge_port); 3071 usb_set_serial_port_data(serial->port[i], edge_port);
@@ -2922,14 +3074,16 @@ static int edge_startup (struct usb_serial *serial)
2922 response = 0; 3074 response = 0;
2923 3075
2924 if (edge_serial->is_epic) { 3076 if (edge_serial->is_epic) {
2925 /* EPIC thing, set up our interrupt polling now and our read urb, so 3077 /* EPIC thing, set up our interrupt polling now and our read
2926 * that the device knows it really is connected. */ 3078 * urb, so that the device knows it really is connected. */
2927 interrupt_in_found = bulk_in_found = bulk_out_found = false; 3079 interrupt_in_found = bulk_in_found = bulk_out_found = false;
2928 for (i = 0; i < serial->interface->altsetting[0].desc.bNumEndpoints; ++i) { 3080 for (i = 0; i < serial->interface->altsetting[0]
3081 .desc.bNumEndpoints; ++i) {
2929 struct usb_endpoint_descriptor *endpoint; 3082 struct usb_endpoint_descriptor *endpoint;
2930 int buffer_size; 3083 int buffer_size;
2931 3084
2932 endpoint = &serial->interface->altsetting[0].endpoint[i].desc; 3085 endpoint = &serial->interface->altsetting[0].
3086 endpoint[i].desc;
2933 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 3087 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
2934 if (!interrupt_in_found && 3088 if (!interrupt_in_found &&
2935 (usb_endpoint_is_int_in(endpoint))) { 3089 (usb_endpoint_is_int_in(endpoint))) {
@@ -2937,58 +3091,67 @@ static int edge_startup (struct usb_serial *serial)
2937 dbg("found interrupt in"); 3091 dbg("found interrupt in");
2938 3092
2939 /* not set up yet, so do it now */ 3093 /* not set up yet, so do it now */
2940 edge_serial->interrupt_read_urb = usb_alloc_urb(0, GFP_KERNEL); 3094 edge_serial->interrupt_read_urb =
3095 usb_alloc_urb(0, GFP_KERNEL);
2941 if (!edge_serial->interrupt_read_urb) { 3096 if (!edge_serial->interrupt_read_urb) {
2942 err("out of memory"); 3097 err("out of memory");
2943 return -ENOMEM; 3098 return -ENOMEM;
2944 } 3099 }
2945 edge_serial->interrupt_in_buffer = kmalloc(buffer_size, GFP_KERNEL); 3100 edge_serial->interrupt_in_buffer =
3101 kmalloc(buffer_size, GFP_KERNEL);
2946 if (!edge_serial->interrupt_in_buffer) { 3102 if (!edge_serial->interrupt_in_buffer) {
2947 err("out of memory"); 3103 err("out of memory");
2948 usb_free_urb(edge_serial->interrupt_read_urb); 3104 usb_free_urb(edge_serial->interrupt_read_urb);
2949 return -ENOMEM; 3105 return -ENOMEM;
2950 } 3106 }
2951 edge_serial->interrupt_in_endpoint = endpoint->bEndpointAddress; 3107 edge_serial->interrupt_in_endpoint =
3108 endpoint->bEndpointAddress;
2952 3109
2953 /* set up our interrupt urb */ 3110 /* set up our interrupt urb */
2954 usb_fill_int_urb(edge_serial->interrupt_read_urb, 3111 usb_fill_int_urb(
2955 dev, 3112 edge_serial->interrupt_read_urb,
2956 usb_rcvintpipe(dev, endpoint->bEndpointAddress), 3113 dev,
2957 edge_serial->interrupt_in_buffer, 3114 usb_rcvintpipe(dev,
2958 buffer_size, 3115 endpoint->bEndpointAddress),
2959 edge_interrupt_callback, 3116 edge_serial->interrupt_in_buffer,
2960 edge_serial, 3117 buffer_size,
2961 endpoint->bInterval); 3118 edge_interrupt_callback,
3119 edge_serial,
3120 endpoint->bInterval);
2962 3121
2963 interrupt_in_found = true; 3122 interrupt_in_found = true;
2964 } 3123 }
2965 3124
2966 if (!bulk_in_found && 3125 if (!bulk_in_found &&
2967 (usb_endpoint_is_bulk_in(endpoint))) { 3126 (usb_endpoint_is_bulk_in(endpoint))) {
2968 /* we found a bulk in endpoint */ 3127 /* we found a bulk in endpoint */
2969 dbg("found bulk in"); 3128 dbg("found bulk in");
2970 3129
2971 /* not set up yet, so do it now */ 3130 /* not set up yet, so do it now */
2972 edge_serial->read_urb = usb_alloc_urb(0, GFP_KERNEL); 3131 edge_serial->read_urb =
3132 usb_alloc_urb(0, GFP_KERNEL);
2973 if (!edge_serial->read_urb) { 3133 if (!edge_serial->read_urb) {
2974 err("out of memory"); 3134 err("out of memory");
2975 return -ENOMEM; 3135 return -ENOMEM;
2976 } 3136 }
2977 edge_serial->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); 3137 edge_serial->bulk_in_buffer =
3138 kmalloc(buffer_size, GFP_KERNEL);
2978 if (!edge_serial->bulk_in_buffer) { 3139 if (!edge_serial->bulk_in_buffer) {
2979 err ("out of memory"); 3140 err("out of memory");
2980 usb_free_urb(edge_serial->read_urb); 3141 usb_free_urb(edge_serial->read_urb);
2981 return -ENOMEM; 3142 return -ENOMEM;
2982 } 3143 }
2983 edge_serial->bulk_in_endpoint = endpoint->bEndpointAddress; 3144 edge_serial->bulk_in_endpoint =
3145 endpoint->bEndpointAddress;
2984 3146
2985 /* set up our bulk in urb */ 3147 /* set up our bulk in urb */
2986 usb_fill_bulk_urb(edge_serial->read_urb, dev, 3148 usb_fill_bulk_urb(edge_serial->read_urb, dev,
2987 usb_rcvbulkpipe(dev, endpoint->bEndpointAddress), 3149 usb_rcvbulkpipe(dev,
2988 edge_serial->bulk_in_buffer, 3150 endpoint->bEndpointAddress),
2989 le16_to_cpu(endpoint->wMaxPacketSize), 3151 edge_serial->bulk_in_buffer,
2990 edge_bulk_in_callback, 3152 le16_to_cpu(endpoint->wMaxPacketSize),
2991 edge_serial); 3153 edge_bulk_in_callback,
3154 edge_serial);
2992 bulk_in_found = true; 3155 bulk_in_found = true;
2993 } 3156 }
2994 3157
@@ -2996,21 +3159,24 @@ static int edge_startup (struct usb_serial *serial)
2996 (usb_endpoint_is_bulk_out(endpoint))) { 3159 (usb_endpoint_is_bulk_out(endpoint))) {
2997 /* we found a bulk out endpoint */ 3160 /* we found a bulk out endpoint */
2998 dbg("found bulk out"); 3161 dbg("found bulk out");
2999 edge_serial->bulk_out_endpoint = endpoint->bEndpointAddress; 3162 edge_serial->bulk_out_endpoint =
3163 endpoint->bEndpointAddress;
3000 bulk_out_found = true; 3164 bulk_out_found = true;
3001 } 3165 }
3002 } 3166 }
3003 3167
3004 if (!interrupt_in_found || !bulk_in_found || !bulk_out_found) { 3168 if (!interrupt_in_found || !bulk_in_found || !bulk_out_found) {
3005 err ("Error - the proper endpoints were not found!"); 3169 err("Error - the proper endpoints were not found!");
3006 return -ENODEV; 3170 return -ENODEV;
3007 } 3171 }
3008 3172
3009 /* start interrupt read for this edgeport this interrupt will 3173 /* start interrupt read for this edgeport this interrupt will
3010 * continue as long as the edgeport is connected */ 3174 * continue as long as the edgeport is connected */
3011 response = usb_submit_urb(edge_serial->interrupt_read_urb, GFP_KERNEL); 3175 response = usb_submit_urb(edge_serial->interrupt_read_urb,
3176 GFP_KERNEL);
3012 if (response) 3177 if (response)
3013 err("%s - Error %d submitting control urb", __func__, response); 3178 err("%s - Error %d submitting control urb",
3179 __func__, response);
3014 } 3180 }
3015 return response; 3181 return response;
3016} 3182}
@@ -3020,7 +3186,7 @@ static int edge_startup (struct usb_serial *serial)
3020 * edge_shutdown 3186 * edge_shutdown
3021 * This function is called whenever the device is removed from the usb bus. 3187 * This function is called whenever the device is removed from the usb bus.
3022 ****************************************************************************/ 3188 ****************************************************************************/
3023static void edge_shutdown (struct usb_serial *serial) 3189static void edge_shutdown(struct usb_serial *serial)
3024{ 3190{
3025 struct edgeport_serial *edge_serial = usb_get_serial_data(serial); 3191 struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
3026 int i; 3192 int i;
@@ -3028,8 +3194,8 @@ static void edge_shutdown (struct usb_serial *serial)
3028 dbg("%s", __func__); 3194 dbg("%s", __func__);
3029 3195
3030 /* stop reads and writes on all ports */ 3196 /* stop reads and writes on all ports */
3031 for (i=0; i < serial->num_ports; ++i) { 3197 for (i = 0; i < serial->num_ports; ++i) {
3032 kfree (usb_get_serial_port_data(serial->port[i])); 3198 kfree(usb_get_serial_port_data(serial->port[i]));
3033 usb_set_serial_port_data(serial->port[i], NULL); 3199 usb_set_serial_port_data(serial->port[i], NULL);
3034 } 3200 }
3035 /* free up our endpoint stuff */ 3201 /* free up our endpoint stuff */
@@ -3069,7 +3235,7 @@ static int __init edgeport_init(void)
3069 if (retval) 3235 if (retval)
3070 goto failed_epic_device_register; 3236 goto failed_epic_device_register;
3071 retval = usb_register(&io_driver); 3237 retval = usb_register(&io_driver);
3072 if (retval) 3238 if (retval)
3073 goto failed_usb_register; 3239 goto failed_usb_register;
3074 atomic_set(&CmdUrbs, 0); 3240 atomic_set(&CmdUrbs, 0);
3075 info(DRIVER_DESC " " DRIVER_VERSION); 3241 info(DRIVER_DESC " " DRIVER_VERSION);
@@ -3094,19 +3260,19 @@ failed_2port_device_register:
3094 ****************************************************************************/ 3260 ****************************************************************************/
3095static void __exit edgeport_exit (void) 3261static void __exit edgeport_exit (void)
3096{ 3262{
3097 usb_deregister (&io_driver); 3263 usb_deregister(&io_driver);
3098 usb_serial_deregister (&edgeport_2port_device); 3264 usb_serial_deregister(&edgeport_2port_device);
3099 usb_serial_deregister (&edgeport_4port_device); 3265 usb_serial_deregister(&edgeport_4port_device);
3100 usb_serial_deregister (&edgeport_8port_device); 3266 usb_serial_deregister(&edgeport_8port_device);
3101 usb_serial_deregister (&epic_device); 3267 usb_serial_deregister(&epic_device);
3102} 3268}
3103 3269
3104module_init(edgeport_init); 3270module_init(edgeport_init);
3105module_exit(edgeport_exit); 3271module_exit(edgeport_exit);
3106 3272
3107/* Module information */ 3273/* Module information */
3108MODULE_AUTHOR( DRIVER_AUTHOR ); 3274MODULE_AUTHOR(DRIVER_AUTHOR);
3109MODULE_DESCRIPTION( DRIVER_DESC ); 3275MODULE_DESCRIPTION(DRIVER_DESC);
3110MODULE_LICENSE("GPL"); 3276MODULE_LICENSE("GPL");
3111MODULE_FIRMWARE("edgeport/boot.fw"); 3277MODULE_FIRMWARE("edgeport/boot.fw");
3112MODULE_FIRMWARE("edgeport/boot2.fw"); 3278MODULE_FIRMWARE("edgeport/boot2.fw");
diff --git a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
index 2ec85893f27a..7eb9d67b81b6 100644
--- a/drivers/usb/serial/io_tables.h
+++ b/drivers/usb/serial/io_tables.h
@@ -8,7 +8,7 @@
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 10 * (at your option) any later version.
11 * 11 *
12 */ 12 */
13 13
14#ifndef IO_TABLES_H 14#ifndef IO_TABLES_H
@@ -90,10 +90,10 @@ static struct usb_device_id id_table_combined [] = {
90 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A758) }, 90 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A758) },
91 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A794) }, 91 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A794) },
92 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A225) }, 92 { USB_DEVICE(USB_VENDOR_ID_AXIOHM, AXIOHM_DEVICE_ID_EPIC_A225) },
93 { } /* Terminating entry */ 93 { } /* Terminating entry */
94}; 94};
95 95
96MODULE_DEVICE_TABLE (usb, id_table_combined); 96MODULE_DEVICE_TABLE(usb, id_table_combined);
97 97
98static struct usb_driver io_driver = { 98static struct usb_driver io_driver = {
99 .name = "io_edgeport", 99 .name = "io_edgeport",
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 61daea3f7b2d..cb4c54316cf5 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -18,8 +18,8 @@
18 * 18 *
19 * Version history: 19 * Version history:
20 * 20 *
21 * July 11, 2002 Removed 4 port device structure since all TI UMP 21 * July 11, 2002 Removed 4 port device structure since all TI UMP
22 * chips have only 2 ports 22 * chips have only 2 ports
23 * David Iacovelli (davidi@ionetworks.com) 23 * David Iacovelli (davidi@ionetworks.com)
24 * 24 *
25 */ 25 */
@@ -38,7 +38,7 @@
38#include <linux/serial.h> 38#include <linux/serial.h>
39#include <linux/ioctl.h> 39#include <linux/ioctl.h>
40#include <linux/firmware.h> 40#include <linux/firmware.h>
41#include <asm/uaccess.h> 41#include <linux/uaccess.h>
42#include <linux/usb.h> 42#include <linux/usb.h>
43#include <linux/usb/serial.h> 43#include <linux/usb/serial.h>
44 44
@@ -57,18 +57,19 @@
57 57
58 58
59struct edgeport_uart_buf_desc { 59struct edgeport_uart_buf_desc {
60 __u32 count; // Number of bytes currently in buffer 60 __u32 count; /* Number of bytes currently in buffer */
61}; 61};
62 62
63/* different hardware types */ 63/* different hardware types */
64#define HARDWARE_TYPE_930 0 64#define HARDWARE_TYPE_930 0
65#define HARDWARE_TYPE_TIUMP 1 65#define HARDWARE_TYPE_TIUMP 1
66 66
67// IOCTL_PRIVATE_TI_GET_MODE Definitions 67/* IOCTL_PRIVATE_TI_GET_MODE Definitions */
68#define TI_MODE_CONFIGURING 0 // Device has not entered start device 68#define TI_MODE_CONFIGURING 0 /* Device has not entered start device */
69#define TI_MODE_BOOT 1 // Staying in boot mode 69#define TI_MODE_BOOT 1 /* Staying in boot mode */
70#define TI_MODE_DOWNLOAD 2 // Made it to download mode 70#define TI_MODE_DOWNLOAD 2 /* Made it to download mode */
71#define TI_MODE_TRANSITIONING 3 // Currently in boot mode but transitioning to download mode 71#define TI_MODE_TRANSITIONING 3 /* Currently in boot mode but
72 transitioning to download mode */
72 73
73/* read urb state */ 74/* read urb state */
74#define EDGE_READ_URB_RUNNING 0 75#define EDGE_READ_URB_RUNNING 0
@@ -82,10 +83,9 @@ struct edgeport_uart_buf_desc {
82 83
83 84
84/* Product information read from the Edgeport */ 85/* Product information read from the Edgeport */
85struct product_info 86struct product_info {
86{ 87 int TiMode; /* Current TI Mode */
87 int TiMode; // Current TI Mode 88 __u8 hardware_type; /* Type of hardware */
88 __u8 hardware_type; // Type of hardware
89} __attribute__((packed)); 89} __attribute__((packed));
90 90
91/* circular buffer */ 91/* circular buffer */
@@ -116,7 +116,7 @@ struct edgeport_port {
116 happen */ 116 happen */
117 struct edgeport_serial *edge_serial; 117 struct edgeport_serial *edge_serial;
118 struct usb_serial_port *port; 118 struct usb_serial_port *port;
119 __u8 bUartMode; /* Port type, 0: RS232, etc. */ 119 __u8 bUartMode; /* Port type, 0: RS232, etc. */
120 spinlock_t ep_lock; 120 spinlock_t ep_lock;
121 int ep_read_urb_state; 121 int ep_read_urb_state;
122 int ep_write_urb_in_use; 122 int ep_write_urb_in_use;
@@ -125,8 +125,9 @@ struct edgeport_port {
125 125
126struct edgeport_serial { 126struct edgeport_serial {
127 struct product_info product_info; 127 struct product_info product_info;
128 u8 TI_I2C_Type; // Type of I2C in UMP 128 u8 TI_I2C_Type; /* Type of I2C in UMP */
129 u8 TiReadI2C; // Set to TRUE if we have read the I2c in Boot Mode 129 u8 TiReadI2C; /* Set to TRUE if we have read the
130 I2c in Boot Mode */
130 struct mutex es_lock; 131 struct mutex es_lock;
131 int num_ports_open; 132 int num_ports_open;
132 struct usb_serial *serial; 133 struct usb_serial *serial;
@@ -214,7 +215,7 @@ static struct usb_device_id id_table_combined [] = {
214 { } 215 { }
215}; 216};
216 217
217MODULE_DEVICE_TABLE (usb, id_table_combined); 218MODULE_DEVICE_TABLE(usb, id_table_combined);
218 219
219static struct usb_driver io_driver = { 220static struct usb_driver io_driver = {
220 .name = "io_ti", 221 .name = "io_ti",
@@ -231,20 +232,20 @@ static unsigned short OperationalBuildNumber;
231 232
232static int debug; 233static int debug;
233 234
234static int TIStayInBootMode = 0;
235static int low_latency = EDGE_LOW_LATENCY; 235static int low_latency = EDGE_LOW_LATENCY;
236static int closing_wait = EDGE_CLOSING_WAIT; 236static int closing_wait = EDGE_CLOSING_WAIT;
237static int ignore_cpu_rev = 0; 237static int ignore_cpu_rev;
238static int default_uart_mode = 0; /* RS232 */ 238static int default_uart_mode; /* RS232 */
239
240 239
241static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length); 240static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
241 unsigned char *data, int length);
242 242
243static void stop_read(struct edgeport_port *edge_port); 243static void stop_read(struct edgeport_port *edge_port);
244static int restart_read(struct edgeport_port *edge_port); 244static int restart_read(struct edgeport_port *edge_port);
245 245
246static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios); 246static void edge_set_termios(struct tty_struct *tty,
247static void edge_send(struct usb_serial_port *port); 247 struct usb_serial_port *port, struct ktermios *old_termios);
248static void edge_send(struct tty_struct *tty);
248 249
249/* sysfs attributes */ 250/* sysfs attributes */
250static int edge_create_sysfs_attrs(struct usb_serial_port *port); 251static int edge_create_sysfs_attrs(struct usb_serial_port *port);
@@ -262,87 +263,57 @@ static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
262 unsigned int count); 263 unsigned int count);
263 264
264 265
265static int TIReadVendorRequestSync (struct usb_device *dev, 266static int ti_vread_sync(struct usb_device *dev, __u8 request,
266 __u8 request, 267 __u16 value, __u16 index, u8 *data, int size)
267 __u16 value,
268 __u16 index,
269 u8 *data,
270 int size)
271{ 268{
272 int status; 269 int status;
273 270
274 status = usb_control_msg (dev, 271 status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
275 usb_rcvctrlpipe(dev, 0), 272 (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN),
276 request, 273 value, index, data, size, 1000);
277 (USB_TYPE_VENDOR |
278 USB_RECIP_DEVICE |
279 USB_DIR_IN),
280 value,
281 index,
282 data,
283 size,
284 1000);
285 if (status < 0) 274 if (status < 0)
286 return status; 275 return status;
287 if (status != size) { 276 if (status != size) {
288 dbg ("%s - wanted to write %d, but only wrote %d", 277 dbg("%s - wanted to write %d, but only wrote %d",
289 __func__, size, status); 278 __func__, size, status);
290 return -ECOMM; 279 return -ECOMM;
291 } 280 }
292 return 0; 281 return 0;
293} 282}
294 283
295static int TISendVendorRequestSync (struct usb_device *dev, 284static int ti_vsend_sync(struct usb_device *dev, __u8 request,
296 __u8 request, 285 __u16 value, __u16 index, u8 *data, int size)
297 __u16 value,
298 __u16 index,
299 u8 *data,
300 int size)
301{ 286{
302 int status; 287 int status;
303 288
304 status = usb_control_msg (dev, 289 status = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
305 usb_sndctrlpipe(dev, 0), 290 (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
306 request, 291 value, index, data, size, 1000);
307 (USB_TYPE_VENDOR |
308 USB_RECIP_DEVICE |
309 USB_DIR_OUT),
310 value,
311 index,
312 data,
313 size,
314 1000);
315 if (status < 0) 292 if (status < 0)
316 return status; 293 return status;
317 if (status != size) { 294 if (status != size) {
318 dbg ("%s - wanted to write %d, but only wrote %d", 295 dbg("%s - wanted to write %d, but only wrote %d",
319 __func__, size, status); 296 __func__, size, status);
320 return -ECOMM; 297 return -ECOMM;
321 } 298 }
322 return 0; 299 return 0;
323} 300}
324 301
325static int TIWriteCommandSync (struct usb_device *dev, __u8 command, 302static int send_cmd(struct usb_device *dev, __u8 command,
326 __u8 moduleid, __u16 value, u8 *data, 303 __u8 moduleid, __u16 value, u8 *data,
327 int size) 304 int size)
328{ 305{
329 return TISendVendorRequestSync (dev, 306 return ti_vsend_sync(dev, command, value, moduleid, data, size);
330 command, // Request
331 value, // wValue
332 moduleid, // wIndex
333 data, // TransferBuffer
334 size); // TransferBufferLength
335
336} 307}
337 308
338/* clear tx/rx buffers and fifo in TI UMP */ 309/* clear tx/rx buffers and fifo in TI UMP */
339static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask) 310static int purge_port(struct usb_serial_port *port, __u16 mask)
340{ 311{
341 int port_number = port->number - port->serial->minor; 312 int port_number = port->number - port->serial->minor;
342 313
343 dbg ("%s - port %d, mask %x", __func__, port_number, mask); 314 dbg("%s - port %d, mask %x", __func__, port_number, mask);
344 315
345 return TIWriteCommandSync (port->serial->dev, 316 return send_cmd(port->serial->dev,
346 UMPC_PURGE_PORT, 317 UMPC_PURGE_PORT,
347 (__u8)(UMPM_UART1_PORT + port_number), 318 (__u8)(UMPM_UART1_PORT + port_number),
348 mask, 319 mask,
@@ -351,92 +322,87 @@ static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask)
351} 322}
352 323
353/** 324/**
354 * TIReadDownloadMemory - Read edgeport memory from TI chip 325 * read_download_mem - Read edgeport memory from TI chip
355 * @dev: usb device pointer 326 * @dev: usb device pointer
356 * @start_address: Device CPU address at which to read 327 * @start_address: Device CPU address at which to read
357 * @length: Length of above data 328 * @length: Length of above data
358 * @address_type: Can read both XDATA and I2C 329 * @address_type: Can read both XDATA and I2C
359 * @buffer: pointer to input data buffer 330 * @buffer: pointer to input data buffer
360 */ 331 */
361static int TIReadDownloadMemory(struct usb_device *dev, int start_address, 332static int read_download_mem(struct usb_device *dev, int start_address,
362 int length, __u8 address_type, __u8 *buffer) 333 int length, __u8 address_type, __u8 *buffer)
363{ 334{
364 int status = 0; 335 int status = 0;
365 __u8 read_length; 336 __u8 read_length;
366 __be16 be_start_address; 337 __be16 be_start_address;
367 338
368 dbg ("%s - @ %x for %d", __func__, start_address, length); 339 dbg("%s - @ %x for %d", __func__, start_address, length);
369 340
370 /* Read in blocks of 64 bytes 341 /* Read in blocks of 64 bytes
371 * (TI firmware can't handle more than 64 byte reads) 342 * (TI firmware can't handle more than 64 byte reads)
372 */ 343 */
373 while (length) { 344 while (length) {
374 if (length > 64) 345 if (length > 64)
375 read_length= 64; 346 read_length = 64;
376 else 347 else
377 read_length = (__u8)length; 348 read_length = (__u8)length;
378 349
379 if (read_length > 1) { 350 if (read_length > 1) {
380 dbg ("%s - @ %x for %d", __func__, 351 dbg("%s - @ %x for %d", __func__,
381 start_address, read_length); 352 start_address, read_length);
382 } 353 }
383 be_start_address = cpu_to_be16 (start_address); 354 be_start_address = cpu_to_be16(start_address);
384 status = TIReadVendorRequestSync (dev, 355 status = ti_vread_sync(dev, UMPC_MEMORY_READ,
385 UMPC_MEMORY_READ, // Request 356 (__u16)address_type,
386 (__u16)address_type, // wValue (Address type) 357 (__force __u16)be_start_address,
387 (__force __u16)be_start_address, // wIndex (Address to read) 358 buffer, read_length);
388 buffer, // TransferBuffer
389 read_length); // TransferBufferLength
390 359
391 if (status) { 360 if (status) {
392 dbg ("%s - ERROR %x", __func__, status); 361 dbg("%s - ERROR %x", __func__, status);
393 return status; 362 return status;
394 } 363 }
395 364
396 if (read_length > 1) { 365 if (read_length > 1)
397 usb_serial_debug_data(debug, &dev->dev, __func__, 366 usb_serial_debug_data(debug, &dev->dev, __func__,
398 read_length, buffer); 367 read_length, buffer);
399 }
400 368
401 /* Update pointers/length */ 369 /* Update pointers/length */
402 start_address += read_length; 370 start_address += read_length;
403 buffer += read_length; 371 buffer += read_length;
404 length -= read_length; 372 length -= read_length;
405 } 373 }
406 374
407 return status; 375 return status;
408} 376}
409 377
410static int TIReadRam (struct usb_device *dev, int start_address, int length, __u8 *buffer) 378static int read_ram(struct usb_device *dev, int start_address,
379 int length, __u8 *buffer)
411{ 380{
412 return TIReadDownloadMemory (dev, 381 return read_download_mem(dev, start_address, length,
413 start_address, 382 DTK_ADDR_SPACE_XDATA, buffer);
414 length,
415 DTK_ADDR_SPACE_XDATA,
416 buffer);
417} 383}
418 384
419/* Read edgeport memory to a given block */ 385/* Read edgeport memory to a given block */
420static int TIReadBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 * buffer) 386static int read_boot_mem(struct edgeport_serial *serial,
387 int start_address, int length, __u8 *buffer)
421{ 388{
422 int status = 0; 389 int status = 0;
423 int i; 390 int i;
424 391
425 for (i=0; i< length; i++) { 392 for (i = 0; i < length; i++) {
426 status = TIReadVendorRequestSync (serial->serial->dev, 393 status = ti_vread_sync(serial->serial->dev,
427 UMPC_MEMORY_READ, // Request 394 UMPC_MEMORY_READ, serial->TI_I2C_Type,
428 serial->TI_I2C_Type, // wValue (Address type) 395 (__u16)(start_address+i), &buffer[i], 0x01);
429 (__u16)(start_address+i), // wIndex
430 &buffer[i], // TransferBuffer
431 0x01); // TransferBufferLength
432 if (status) { 396 if (status) {
433 dbg ("%s - ERROR %x", __func__, status); 397 dbg("%s - ERROR %x", __func__, status);
434 return status; 398 return status;
435 } 399 }
436 } 400 }
437 401
438 dbg ("%s - start_address = %x, length = %d", __func__, start_address, length); 402 dbg("%s - start_address = %x, length = %d",
439 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, length, buffer); 403 __func__, start_address, length);
404 usb_serial_debug_data(debug, &serial->serial->dev->dev,
405 __func__, length, buffer);
440 406
441 serial->TiReadI2C = 1; 407 serial->TiReadI2C = 1;
442 408
@@ -444,7 +410,8 @@ static int TIReadBootMemory (struct edgeport_serial *serial, int start_address,
444} 410}
445 411
446/* Write given block to TI EPROM memory */ 412/* Write given block to TI EPROM memory */
447static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer) 413static int write_boot_mem(struct edgeport_serial *serial,
414 int start_address, int length, __u8 *buffer)
448{ 415{
449 int status = 0; 416 int status = 0;
450 int i; 417 int i;
@@ -452,57 +419,58 @@ static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address,
452 419
453 /* Must do a read before write */ 420 /* Must do a read before write */
454 if (!serial->TiReadI2C) { 421 if (!serial->TiReadI2C) {
455 status = TIReadBootMemory(serial, 0, 1, &temp); 422 status = read_boot_mem(serial, 0, 1, &temp);
456 if (status) 423 if (status)
457 return status; 424 return status;
458 } 425 }
459 426
460 for (i=0; i < length; ++i) { 427 for (i = 0; i < length; ++i) {
461 status = TISendVendorRequestSync (serial->serial->dev, 428 status = ti_vsend_sync(serial->serial->dev,
462 UMPC_MEMORY_WRITE, // Request 429 UMPC_MEMORY_WRITE, buffer[i],
463 buffer[i], // wValue 430 (__u16)(i + start_address), NULL, 0);
464 (__u16)(i+start_address), // wIndex
465 NULL, // TransferBuffer
466 0); // TransferBufferLength
467 if (status) 431 if (status)
468 return status; 432 return status;
469 } 433 }
470 434
471 dbg ("%s - start_sddr = %x, length = %d", __func__, start_address, length); 435 dbg("%s - start_sddr = %x, length = %d",
472 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, length, buffer); 436 __func__, start_address, length);
437 usb_serial_debug_data(debug, &serial->serial->dev->dev,
438 __func__, length, buffer);
473 439
474 return status; 440 return status;
475} 441}
476 442
477 443
478/* Write edgeport I2C memory to TI chip */ 444/* Write edgeport I2C memory to TI chip */
479static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address, int length, __u8 address_type, __u8 *buffer) 445static int write_i2c_mem(struct edgeport_serial *serial,
446 int start_address, int length, __u8 address_type, __u8 *buffer)
480{ 447{
481 int status = 0; 448 int status = 0;
482 int write_length; 449 int write_length;
483 __be16 be_start_address; 450 __be16 be_start_address;
484 451
485 /* We can only send a maximum of 1 aligned byte page at a time */ 452 /* We can only send a maximum of 1 aligned byte page at a time */
486 453
487 /* calulate the number of bytes left in the first page */ 454 /* calulate the number of bytes left in the first page */
488 write_length = EPROM_PAGE_SIZE - (start_address & (EPROM_PAGE_SIZE - 1)); 455 write_length = EPROM_PAGE_SIZE -
456 (start_address & (EPROM_PAGE_SIZE - 1));
489 457
490 if (write_length > length) 458 if (write_length > length)
491 write_length = length; 459 write_length = length;
492 460
493 dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __func__, start_address, write_length); 461 dbg("%s - BytesInFirstPage Addr = %x, length = %d",
494 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, write_length, buffer); 462 __func__, start_address, write_length);
463 usb_serial_debug_data(debug, &serial->serial->dev->dev,
464 __func__, write_length, buffer);
495 465
496 /* Write first page */ 466 /* Write first page */
497 be_start_address = cpu_to_be16 (start_address); 467 be_start_address = cpu_to_be16(start_address);
498 status = TISendVendorRequestSync (serial->serial->dev, 468 status = ti_vsend_sync(serial->serial->dev,
499 UMPC_MEMORY_WRITE, // Request 469 UMPC_MEMORY_WRITE, (__u16)address_type,
500 (__u16)address_type, // wValue 470 (__force __u16)be_start_address,
501 (__force __u16)be_start_address, // wIndex 471 buffer, write_length);
502 buffer, // TransferBuffer
503 write_length);
504 if (status) { 472 if (status) {
505 dbg ("%s - ERROR %d", __func__, status); 473 dbg("%s - ERROR %d", __func__, status);
506 return status; 474 return status;
507 } 475 }
508 476
@@ -510,29 +478,31 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
510 start_address += write_length; 478 start_address += write_length;
511 buffer += write_length; 479 buffer += write_length;
512 480
513 /* We should be aligned now -- can write max page size bytes at a time */ 481 /* We should be aligned now -- can write
482 max page size bytes at a time */
514 while (length) { 483 while (length) {
515 if (length > EPROM_PAGE_SIZE) 484 if (length > EPROM_PAGE_SIZE)
516 write_length = EPROM_PAGE_SIZE; 485 write_length = EPROM_PAGE_SIZE;
517 else 486 else
518 write_length = length; 487 write_length = length;
519 488
520 dbg ("%s - Page Write Addr = %x, length = %d", __func__, start_address, write_length); 489 dbg("%s - Page Write Addr = %x, length = %d",
521 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, write_length, buffer); 490 __func__, start_address, write_length);
491 usb_serial_debug_data(debug, &serial->serial->dev->dev,
492 __func__, write_length, buffer);
522 493
523 /* Write next page */ 494 /* Write next page */
524 be_start_address = cpu_to_be16 (start_address); 495 be_start_address = cpu_to_be16(start_address);
525 status = TISendVendorRequestSync (serial->serial->dev, 496 status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
526 UMPC_MEMORY_WRITE, // Request 497 (__u16)address_type,
527 (__u16)address_type, // wValue 498 (__force __u16)be_start_address,
528 (__force __u16)be_start_address, // wIndex 499 buffer, write_length);
529 buffer, // TransferBuffer
530 write_length); // TransferBufferLength
531 if (status) { 500 if (status) {
532 dev_err (&serial->serial->dev->dev, "%s - ERROR %d\n", __func__, status); 501 dev_err(&serial->serial->dev->dev, "%s - ERROR %d\n",
502 __func__, status);
533 return status; 503 return status;
534 } 504 }
535 505
536 length -= write_length; 506 length -= write_length;
537 start_address += write_length; 507 start_address += write_length;
538 buffer += write_length; 508 buffer += write_length;
@@ -541,25 +511,25 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
541} 511}
542 512
543/* Examine the UMP DMA registers and LSR 513/* Examine the UMP DMA registers and LSR
544 * 514 *
545 * Check the MSBit of the X and Y DMA byte count registers. 515 * Check the MSBit of the X and Y DMA byte count registers.
546 * A zero in this bit indicates that the TX DMA buffers are empty 516 * A zero in this bit indicates that the TX DMA buffers are empty
547 * then check the TX Empty bit in the UART. 517 * then check the TX Empty bit in the UART.
548 */ 518 */
549static int TIIsTxActive (struct edgeport_port *port) 519static int tx_active(struct edgeport_port *port)
550{ 520{
551 int status; 521 int status;
552 struct out_endpoint_desc_block *oedb; 522 struct out_endpoint_desc_block *oedb;
553 __u8 *lsr; 523 __u8 *lsr;
554 int bytes_left = 0; 524 int bytes_left = 0;
555 525
556 oedb = kmalloc (sizeof (* oedb), GFP_KERNEL); 526 oedb = kmalloc(sizeof(*oedb), GFP_KERNEL);
557 if (!oedb) { 527 if (!oedb) {
558 dev_err (&port->port->dev, "%s - out of memory\n", __func__); 528 dev_err(&port->port->dev, "%s - out of memory\n", __func__);
559 return -ENOMEM; 529 return -ENOMEM;
560 } 530 }
561 531
562 lsr = kmalloc (1, GFP_KERNEL); /* Sigh, that's right, just one byte, 532 lsr = kmalloc(1, GFP_KERNEL); /* Sigh, that's right, just one byte,
563 as not all platforms can do DMA 533 as not all platforms can do DMA
564 from stack */ 534 from stack */
565 if (!lsr) { 535 if (!lsr) {
@@ -567,51 +537,47 @@ static int TIIsTxActive (struct edgeport_port *port)
567 return -ENOMEM; 537 return -ENOMEM;
568 } 538 }
569 /* Read the DMA Count Registers */ 539 /* Read the DMA Count Registers */
570 status = TIReadRam (port->port->serial->dev, 540 status = read_ram(port->port->serial->dev, port->dma_address,
571 port->dma_address, 541 sizeof(*oedb), (void *)oedb);
572 sizeof( *oedb),
573 (void *)oedb);
574
575 if (status) 542 if (status)
576 goto exit_is_tx_active; 543 goto exit_is_tx_active;
577 544
578 dbg ("%s - XByteCount 0x%X", __func__, oedb->XByteCount); 545 dbg("%s - XByteCount 0x%X", __func__, oedb->XByteCount);
579 546
580 /* and the LSR */ 547 /* and the LSR */
581 status = TIReadRam (port->port->serial->dev, 548 status = read_ram(port->port->serial->dev,
582 port->uart_base + UMPMEM_OFFS_UART_LSR, 549 port->uart_base + UMPMEM_OFFS_UART_LSR, 1, lsr);
583 1,
584 lsr);
585 550
586 if (status) 551 if (status)
587 goto exit_is_tx_active; 552 goto exit_is_tx_active;
588 dbg ("%s - LSR = 0x%X", __func__, *lsr); 553 dbg("%s - LSR = 0x%X", __func__, *lsr);
589 554
590 /* If either buffer has data or we are transmitting then return TRUE */ 555 /* If either buffer has data or we are transmitting then return TRUE */
591 if ((oedb->XByteCount & 0x80 ) != 0 ) 556 if ((oedb->XByteCount & 0x80) != 0)
592 bytes_left += 64; 557 bytes_left += 64;
593 558
594 if ((*lsr & UMP_UART_LSR_TX_MASK ) == 0 ) 559 if ((*lsr & UMP_UART_LSR_TX_MASK) == 0)
595 bytes_left += 1; 560 bytes_left += 1;
596 561
597 /* We return Not Active if we get any kind of error */ 562 /* We return Not Active if we get any kind of error */
598exit_is_tx_active: 563exit_is_tx_active:
599 dbg ("%s - return %d", __func__, bytes_left ); 564 dbg("%s - return %d", __func__, bytes_left);
600 565
601 kfree(lsr); 566 kfree(lsr);
602 kfree(oedb); 567 kfree(oedb);
603 return bytes_left; 568 return bytes_left;
604} 569}
605 570
606static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int flush) 571static void chase_port(struct edgeport_port *port, unsigned long timeout,
572 int flush)
607{ 573{
608 int baud_rate; 574 int baud_rate;
609 struct tty_struct *tty = port->port->tty; 575 struct tty_struct *tty = port->port->port.tty;
610 wait_queue_t wait; 576 wait_queue_t wait;
611 unsigned long flags; 577 unsigned long flags;
612 578
613 if (!timeout) 579 if (!timeout)
614 timeout = (HZ*EDGE_CLOSING_WAIT)/100; 580 timeout = (HZ * EDGE_CLOSING_WAIT)/100;
615 581
616 /* wait for data to drain from the buffer */ 582 /* wait for data to drain from the buffer */
617 spin_lock_irqsave(&port->ep_lock, flags); 583 spin_lock_irqsave(&port->ep_lock, flags);
@@ -621,7 +587,8 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
621 set_current_state(TASK_INTERRUPTIBLE); 587 set_current_state(TASK_INTERRUPTIBLE);
622 if (edge_buf_data_avail(port->ep_out_buf) == 0 588 if (edge_buf_data_avail(port->ep_out_buf) == 0
623 || timeout == 0 || signal_pending(current) 589 || timeout == 0 || signal_pending(current)
624 || !usb_get_intfdata(port->port->serial->interface)) /* disconnect */ 590 || !usb_get_intfdata(port->port->serial->interface))
591 /* disconnect */
625 break; 592 break;
626 spin_unlock_irqrestore(&port->ep_lock, flags); 593 spin_unlock_irqrestore(&port->ep_lock, flags);
627 timeout = schedule_timeout(timeout); 594 timeout = schedule_timeout(timeout);
@@ -636,8 +603,9 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
636 /* wait for data to drain from the device */ 603 /* wait for data to drain from the device */
637 timeout += jiffies; 604 timeout += jiffies;
638 while ((long)(jiffies - timeout) < 0 && !signal_pending(current) 605 while ((long)(jiffies - timeout) < 0 && !signal_pending(current)
639 && usb_get_intfdata(port->port->serial->interface)) { /* not disconnected */ 606 && usb_get_intfdata(port->port->serial->interface)) {
640 if (!TIIsTxActive(port)) 607 /* not disconnected */
608 if (!tx_active(port))
641 break; 609 break;
642 msleep(10); 610 msleep(10);
643 } 611 }
@@ -647,72 +615,72 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
647 return; 615 return;
648 616
649 /* wait one more character time, based on baud rate */ 617 /* wait one more character time, based on baud rate */
650 /* (TIIsTxActive doesn't seem to wait for the last byte) */ 618 /* (tx_active doesn't seem to wait for the last byte) */
651 if ((baud_rate=port->baud_rate) == 0) 619 baud_rate = port->baud_rate;
620 if (baud_rate == 0)
652 baud_rate = 50; 621 baud_rate = 50;
653 msleep(max(1, DIV_ROUND_UP(10000, baud_rate))); 622 msleep(max(1, DIV_ROUND_UP(10000, baud_rate)));
654} 623}
655 624
656static int TIChooseConfiguration (struct usb_device *dev) 625static int choose_config(struct usb_device *dev)
657{ 626{
658 // There may be multiple configurations on this device, in which case 627 /*
659 // we would need to read and parse all of them to find out which one 628 * There may be multiple configurations on this device, in which case
660 // we want. However, we just support one config at this point, 629 * we would need to read and parse all of them to find out which one
661 // configuration # 1, which is Config Descriptor 0. 630 * we want. However, we just support one config at this point,
631 * configuration # 1, which is Config Descriptor 0.
632 */
662 633
663 dbg ("%s - Number of Interfaces = %d", __func__, dev->config->desc.bNumInterfaces); 634 dbg("%s - Number of Interfaces = %d",
664 dbg ("%s - MAX Power = %d", __func__, dev->config->desc.bMaxPower*2); 635 __func__, dev->config->desc.bNumInterfaces);
636 dbg("%s - MAX Power = %d",
637 __func__, dev->config->desc.bMaxPower * 2);
665 638
666 if (dev->config->desc.bNumInterfaces != 1) { 639 if (dev->config->desc.bNumInterfaces != 1) {
667 dev_err (&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __func__); 640 dev_err(&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n",
641 __func__);
668 return -ENODEV; 642 return -ENODEV;
669 } 643 }
670 644
671 return 0; 645 return 0;
672} 646}
673 647
674static int TIReadRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer) 648static int read_rom(struct edgeport_serial *serial,
649 int start_address, int length, __u8 *buffer)
675{ 650{
676 int status; 651 int status;
677 652
678 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) { 653 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
679 status = TIReadDownloadMemory (serial->serial->dev, 654 status = read_download_mem(serial->serial->dev,
680 start_address, 655 start_address,
681 length, 656 length,
682 serial->TI_I2C_Type, 657 serial->TI_I2C_Type,
683 buffer); 658 buffer);
684 } else { 659 } else {
685 status = TIReadBootMemory (serial, 660 status = read_boot_mem(serial, start_address, length,
686 start_address, 661 buffer);
687 length,
688 buffer);
689 } 662 }
690
691 return status; 663 return status;
692} 664}
693 665
694static int TIWriteRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer) 666static int write_rom(struct edgeport_serial *serial, int start_address,
667 int length, __u8 *buffer)
695{ 668{
696 if (serial->product_info.TiMode == TI_MODE_BOOT) 669 if (serial->product_info.TiMode == TI_MODE_BOOT)
697 return TIWriteBootMemory (serial, 670 return write_boot_mem(serial, start_address, length,
698 start_address, 671 buffer);
699 length,
700 buffer);
701 672
702 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) 673 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
703 return TIWriteDownloadI2C (serial, 674 return write_i2c_mem(serial, start_address, length,
704 start_address, 675 serial->TI_I2C_Type, buffer);
705 length,
706 serial->TI_I2C_Type,
707 buffer);
708
709 return -EINVAL; 676 return -EINVAL;
710} 677}
711 678
712 679
713 680
714/* Read a descriptor header from I2C based on type */ 681/* Read a descriptor header from I2C based on type */
715static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type, struct ti_i2c_desc *rom_desc) 682static int get_descriptor_addr(struct edgeport_serial *serial,
683 int desc_type, struct ti_i2c_desc *rom_desc)
716{ 684{
717 int start_address; 685 int start_address;
718 int status; 686 int status;
@@ -720,41 +688,42 @@ static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type
720 /* Search for requested descriptor in I2C */ 688 /* Search for requested descriptor in I2C */
721 start_address = 2; 689 start_address = 2;
722 do { 690 do {
723 status = TIReadRom (serial, 691 status = read_rom(serial,
724 start_address, 692 start_address,
725 sizeof(struct ti_i2c_desc), 693 sizeof(struct ti_i2c_desc),
726 (__u8 *)rom_desc ); 694 (__u8 *)rom_desc);
727 if (status) 695 if (status)
728 return 0; 696 return 0;
729 697
730 if (rom_desc->Type == desc_type) 698 if (rom_desc->Type == desc_type)
731 return start_address; 699 return start_address;
732 700
733 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size; 701 start_address = start_address + sizeof(struct ti_i2c_desc)
702 + rom_desc->Size;
734 703
735 } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type); 704 } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
736 705
737 return 0; 706 return 0;
738} 707}
739 708
740/* Validate descriptor checksum */ 709/* Validate descriptor checksum */
741static int ValidChecksum(struct ti_i2c_desc *rom_desc, __u8 *buffer) 710static int valid_csum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
742{ 711{
743 __u16 i; 712 __u16 i;
744 __u8 cs = 0; 713 __u8 cs = 0;
745 714
746 for (i=0; i < rom_desc->Size; i++) { 715 for (i = 0; i < rom_desc->Size; i++)
747 cs = (__u8)(cs + buffer[i]); 716 cs = (__u8)(cs + buffer[i]);
748 } 717
749 if (cs != rom_desc->CheckSum) { 718 if (cs != rom_desc->CheckSum) {
750 dbg ("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs); 719 dbg("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs);
751 return -EINVAL; 720 return -EINVAL;
752 } 721 }
753 return 0; 722 return 0;
754} 723}
755 724
756/* Make sure that the I2C image is good */ 725/* Make sure that the I2C image is good */
757static int TiValidateI2cImage (struct edgeport_serial *serial) 726static int check_i2c_image(struct edgeport_serial *serial)
758{ 727{
759 struct device *dev = &serial->serial->dev->dev; 728 struct device *dev = &serial->serial->dev->dev;
760 int status = 0; 729 int status = 0;
@@ -763,120 +732,124 @@ static int TiValidateI2cImage (struct edgeport_serial *serial)
763 __u8 *buffer; 732 __u8 *buffer;
764 __u16 ttype; 733 __u16 ttype;
765 734
766 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); 735 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
767 if (!rom_desc) { 736 if (!rom_desc) {
768 dev_err (dev, "%s - out of memory\n", __func__); 737 dev_err(dev, "%s - out of memory\n", __func__);
769 return -ENOMEM; 738 return -ENOMEM;
770 } 739 }
771 buffer = kmalloc (TI_MAX_I2C_SIZE, GFP_KERNEL); 740 buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL);
772 if (!buffer) { 741 if (!buffer) {
773 dev_err (dev, "%s - out of memory when allocating buffer\n", __func__); 742 dev_err(dev, "%s - out of memory when allocating buffer\n",
774 kfree (rom_desc); 743 __func__);
744 kfree(rom_desc);
775 return -ENOMEM; 745 return -ENOMEM;
776 } 746 }
777 747
778 // Read the first byte (Signature0) must be 0x52 or 0x10 748 /* Read the first byte (Signature0) must be 0x52 or 0x10 */
779 status = TIReadRom (serial, 0, 1, buffer); 749 status = read_rom(serial, 0, 1, buffer);
780 if (status) 750 if (status)
781 goto ExitTiValidateI2cImage; 751 goto out;
782 752
783 if (*buffer != UMP5152 && *buffer != UMP3410) { 753 if (*buffer != UMP5152 && *buffer != UMP3410) {
784 dev_err (dev, "%s - invalid buffer signature\n", __func__); 754 dev_err(dev, "%s - invalid buffer signature\n", __func__);
785 status = -ENODEV; 755 status = -ENODEV;
786 goto ExitTiValidateI2cImage; 756 goto out;
787 } 757 }
788 758
789 do { 759 do {
790 // Validate the I2C 760 /* Validate the I2C */
791 status = TIReadRom (serial, 761 status = read_rom(serial,
792 start_address, 762 start_address,
793 sizeof(struct ti_i2c_desc), 763 sizeof(struct ti_i2c_desc),
794 (__u8 *)rom_desc); 764 (__u8 *)rom_desc);
795 if (status) 765 if (status)
796 break; 766 break;
797 767
798 if ((start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size) > TI_MAX_I2C_SIZE) { 768 if ((start_address + sizeof(struct ti_i2c_desc) +
769 rom_desc->Size) > TI_MAX_I2C_SIZE) {
799 status = -ENODEV; 770 status = -ENODEV;
800 dbg ("%s - structure too big, erroring out.", __func__); 771 dbg("%s - structure too big, erroring out.", __func__);
801 break; 772 break;
802 } 773 }
803 774
804 dbg ("%s Type = 0x%x", __func__, rom_desc->Type); 775 dbg("%s Type = 0x%x", __func__, rom_desc->Type);
805 776
806 // Skip type 2 record 777 /* Skip type 2 record */
807 ttype = rom_desc->Type & 0x0f; 778 ttype = rom_desc->Type & 0x0f;
808 if ( ttype != I2C_DESC_TYPE_FIRMWARE_BASIC 779 if (ttype != I2C_DESC_TYPE_FIRMWARE_BASIC
809 && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO ) { 780 && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO) {
810 // Read the descriptor data 781 /* Read the descriptor data */
811 status = TIReadRom(serial, 782 status = read_rom(serial, start_address +
812 start_address+sizeof(struct ti_i2c_desc), 783 sizeof(struct ti_i2c_desc),
813 rom_desc->Size, 784 rom_desc->Size, buffer);
814 buffer);
815 if (status) 785 if (status)
816 break; 786 break;
817 787
818 status = ValidChecksum(rom_desc, buffer); 788 status = valid_csum(rom_desc, buffer);
819 if (status) 789 if (status)
820 break; 790 break;
821 } 791 }
822 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size; 792 start_address = start_address + sizeof(struct ti_i2c_desc) +
793 rom_desc->Size;
823 794
824 } while ((rom_desc->Type != I2C_DESC_TYPE_ION) && (start_address < TI_MAX_I2C_SIZE)); 795 } while ((rom_desc->Type != I2C_DESC_TYPE_ION) &&
796 (start_address < TI_MAX_I2C_SIZE));
825 797
826 if ((rom_desc->Type != I2C_DESC_TYPE_ION) || (start_address > TI_MAX_I2C_SIZE)) 798 if ((rom_desc->Type != I2C_DESC_TYPE_ION) ||
799 (start_address > TI_MAX_I2C_SIZE))
827 status = -ENODEV; 800 status = -ENODEV;
828 801
829ExitTiValidateI2cImage: 802out:
830 kfree (buffer); 803 kfree(buffer);
831 kfree (rom_desc); 804 kfree(rom_desc);
832 return status; 805 return status;
833} 806}
834 807
835static int TIReadManufDescriptor (struct edgeport_serial *serial, __u8 *buffer) 808static int get_manuf_info(struct edgeport_serial *serial, __u8 *buffer)
836{ 809{
837 int status; 810 int status;
838 int start_address; 811 int start_address;
839 struct ti_i2c_desc *rom_desc; 812 struct ti_i2c_desc *rom_desc;
840 struct edge_ti_manuf_descriptor *desc; 813 struct edge_ti_manuf_descriptor *desc;
841 814
842 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); 815 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
843 if (!rom_desc) { 816 if (!rom_desc) {
844 dev_err (&serial->serial->dev->dev, "%s - out of memory\n", __func__); 817 dev_err(&serial->serial->dev->dev, "%s - out of memory\n",
818 __func__);
845 return -ENOMEM; 819 return -ENOMEM;
846 } 820 }
847 start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_ION, rom_desc); 821 start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
822 rom_desc);
848 823
849 if (!start_address) { 824 if (!start_address) {
850 dbg ("%s - Edge Descriptor not found in I2C", __func__); 825 dbg("%s - Edge Descriptor not found in I2C", __func__);
851 status = -ENODEV; 826 status = -ENODEV;
852 goto exit; 827 goto exit;
853 } 828 }
854 829
855 // Read the descriptor data 830 /* Read the descriptor data */
856 status = TIReadRom (serial, 831 status = read_rom(serial, start_address+sizeof(struct ti_i2c_desc),
857 start_address+sizeof(struct ti_i2c_desc), 832 rom_desc->Size, buffer);
858 rom_desc->Size,
859 buffer);
860 if (status) 833 if (status)
861 goto exit; 834 goto exit;
862 835
863 status = ValidChecksum(rom_desc, buffer); 836 status = valid_csum(rom_desc, buffer);
864 837
865 desc = (struct edge_ti_manuf_descriptor *)buffer; 838 desc = (struct edge_ti_manuf_descriptor *)buffer;
866 dbg ( "%s - IonConfig 0x%x", __func__, desc->IonConfig ); 839 dbg("%s - IonConfig 0x%x", __func__, desc->IonConfig);
867 dbg ( "%s - Version %d", __func__, desc->Version ); 840 dbg("%s - Version %d", __func__, desc->Version);
868 dbg ( "%s - Cpu/Board 0x%x", __func__, desc->CpuRev_BoardRev ); 841 dbg("%s - Cpu/Board 0x%x", __func__, desc->CpuRev_BoardRev);
869 dbg ( "%s - NumPorts %d", __func__, desc->NumPorts ); 842 dbg("%s - NumPorts %d", __func__, desc->NumPorts);
870 dbg ( "%s - NumVirtualPorts %d", __func__, desc->NumVirtualPorts ); 843 dbg("%s - NumVirtualPorts %d", __func__, desc->NumVirtualPorts);
871 dbg ( "%s - TotalPorts %d", __func__, desc->TotalPorts ); 844 dbg("%s - TotalPorts %d", __func__, desc->TotalPorts);
872 845
873exit: 846exit:
874 kfree (rom_desc); 847 kfree(rom_desc);
875 return status; 848 return status;
876} 849}
877 850
878/* Build firmware header used for firmware update */ 851/* Build firmware header used for firmware update */
879static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev) 852static int build_i2c_fw_hdr(__u8 *header, struct device *dev)
880{ 853{
881 __u8 *buffer; 854 __u8 *buffer;
882 int buffer_size; 855 int buffer_size;
@@ -889,24 +862,28 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
889 const struct firmware *fw; 862 const struct firmware *fw;
890 const char *fw_name = "edgeport/down3.bin"; 863 const char *fw_name = "edgeport/down3.bin";
891 864
892 // In order to update the I2C firmware we must change the type 2 record to type 0xF2. 865 /* In order to update the I2C firmware we must change the type 2 record
893 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver 866 * to type 0xF2. This will force the UMP to come up in Boot Mode.
894 // will download the latest firmware (padded to 15.5k) into the UMP ram. 867 * Then while in boot mode, the driver will download the latest
895 // And finally when the device comes back up in download mode the driver will cause 868 * firmware (padded to 15.5k) into the UMP ram. And finally when the
896 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update 869 * device comes back up in download mode the driver will cause the new
897 // the record type from 0xf2 to 0x02. 870 * firmware to be copied from the UMP Ram to I2C and the firmware will
898 871 * update the record type from 0xf2 to 0x02.
899 // Allocate a 15.5k buffer + 2 bytes for version number (Firmware Record) 872 */
900 buffer_size = (((1024 * 16) - 512 )+ sizeof(struct ti_i2c_firmware_rec)); 873
901 874 /* Allocate a 15.5k buffer + 2 bytes for version number
902 buffer = kmalloc (buffer_size, GFP_KERNEL); 875 * (Firmware Record) */
876 buffer_size = (((1024 * 16) - 512 ) +
877 sizeof(struct ti_i2c_firmware_rec));
878
879 buffer = kmalloc(buffer_size, GFP_KERNEL);
903 if (!buffer) { 880 if (!buffer) {
904 dev_err (dev, "%s - out of memory\n", __func__); 881 dev_err(dev, "%s - out of memory\n", __func__);
905 return -ENOMEM; 882 return -ENOMEM;
906 } 883 }
907 884
908 // Set entire image of 0xffs 885 // Set entire image of 0xffs
909 memset (buffer, 0xff, buffer_size); 886 memset(buffer, 0xff, buffer_size);
910 887
911 err = request_firmware(&fw, fw_name, dev); 888 err = request_firmware(&fw, fw_name, dev);
912 if (err) { 889 if (err) {
@@ -921,16 +898,16 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
921 OperationalMinorVersion = fw->data[1]; 898 OperationalMinorVersion = fw->data[1];
922 OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8); 899 OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8);
923 900
924 // Copy version number into firmware record 901 /* Copy version number into firmware record */
925 firmware_rec = (struct ti_i2c_firmware_rec *)buffer; 902 firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
926 903
927 firmware_rec->Ver_Major = OperationalMajorVersion; 904 firmware_rec->Ver_Major = OperationalMajorVersion;
928 firmware_rec->Ver_Minor = OperationalMinorVersion; 905 firmware_rec->Ver_Minor = OperationalMinorVersion;
929 906
930 // Pointer to fw_down memory image 907 /* Pointer to fw_down memory image */
931 img_header = (struct ti_i2c_image_header *)&fw->data[4]; 908 img_header = (struct ti_i2c_image_header *)&fw->data[4];
932 909
933 memcpy (buffer + sizeof(struct ti_i2c_firmware_rec), 910 memcpy(buffer + sizeof(struct ti_i2c_firmware_rec),
934 &fw->data[4 + sizeof(struct ti_i2c_image_header)], 911 &fw->data[4 + sizeof(struct ti_i2c_image_header)],
935 le16_to_cpu(img_header->Length)); 912 le16_to_cpu(img_header->Length));
936 913
@@ -940,12 +917,12 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
940 cs = (__u8)(cs + buffer[i]); 917 cs = (__u8)(cs + buffer[i]);
941 } 918 }
942 919
943 kfree (buffer); 920 kfree(buffer);
944 921
945 // Build new header 922 /* Build new header */
946 i2c_header = (struct ti_i2c_desc *)header; 923 i2c_header = (struct ti_i2c_desc *)header;
947 firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data; 924 firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
948 925
949 i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK; 926 i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK;
950 i2c_header->Size = (__u16)buffer_size; 927 i2c_header->Size = (__u16)buffer_size;
951 i2c_header->CheckSum = cs; 928 i2c_header->CheckSum = cs;
@@ -956,103 +933,100 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
956} 933}
957 934
958/* Try to figure out what type of I2c we have */ 935/* Try to figure out what type of I2c we have */
959static int TIGetI2cTypeInBootMode (struct edgeport_serial *serial) 936static int i2c_type_bootmode(struct edgeport_serial *serial)
960{ 937{
961 int status; 938 int status;
962 __u8 data; 939 __u8 data;
963 940
964 // Try to read type 2 941 /* Try to read type 2 */
965 status = TIReadVendorRequestSync (serial->serial->dev, 942 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
966 UMPC_MEMORY_READ, // Request 943 DTK_ADDR_SPACE_I2C_TYPE_II, 0, &data, 0x01);
967 DTK_ADDR_SPACE_I2C_TYPE_II, // wValue (Address type)
968 0, // wIndex
969 &data, // TransferBuffer
970 0x01); // TransferBufferLength
971 if (status) 944 if (status)
972 dbg ("%s - read 2 status error = %d", __func__, status); 945 dbg("%s - read 2 status error = %d", __func__, status);
973 else 946 else
974 dbg ("%s - read 2 data = 0x%x", __func__, data); 947 dbg("%s - read 2 data = 0x%x", __func__, data);
975 if ((!status) && (data == UMP5152 || data == UMP3410)) { 948 if ((!status) && (data == UMP5152 || data == UMP3410)) {
976 dbg ("%s - ROM_TYPE_II", __func__); 949 dbg("%s - ROM_TYPE_II", __func__);
977 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 950 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
978 return 0; 951 return 0;
979 } 952 }
980 953
981 // Try to read type 3 954 /* Try to read type 3 */
982 status = TIReadVendorRequestSync (serial->serial->dev, 955 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
983 UMPC_MEMORY_READ, // Request 956 DTK_ADDR_SPACE_I2C_TYPE_III, 0, &data, 0x01);
984 DTK_ADDR_SPACE_I2C_TYPE_III, // wValue (Address type)
985 0, // wIndex
986 &data, // TransferBuffer
987 0x01); // TransferBufferLength
988 if (status) 957 if (status)
989 dbg ("%s - read 3 status error = %d", __func__, status); 958 dbg("%s - read 3 status error = %d", __func__, status);
990 else 959 else
991 dbg ("%s - read 2 data = 0x%x", __func__, data); 960 dbg("%s - read 2 data = 0x%x", __func__, data);
992 if ((!status) && (data == UMP5152 || data == UMP3410)) { 961 if ((!status) && (data == UMP5152 || data == UMP3410)) {
993 dbg ("%s - ROM_TYPE_III", __func__); 962 dbg("%s - ROM_TYPE_III", __func__);
994 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III; 963 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
995 return 0; 964 return 0;
996 } 965 }
997 966
998 dbg ("%s - Unknown", __func__); 967 dbg("%s - Unknown", __func__);
999 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 968 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1000 return -ENODEV; 969 return -ENODEV;
1001} 970}
1002 971
1003static int TISendBulkTransferSync (struct usb_serial *serial, void *buffer, int length, int *num_sent) 972static int bulk_xfer(struct usb_serial *serial, void *buffer,
973 int length, int *num_sent)
1004{ 974{
1005 int status; 975 int status;
1006 976
1007 status = usb_bulk_msg (serial->dev, 977 status = usb_bulk_msg(serial->dev,
1008 usb_sndbulkpipe(serial->dev, 978 usb_sndbulkpipe(serial->dev,
1009 serial->port[0]->bulk_out_endpointAddress), 979 serial->port[0]->bulk_out_endpointAddress),
1010 buffer, 980 buffer, length, num_sent, 1000);
1011 length,
1012 num_sent,
1013 1000);
1014 return status; 981 return status;
1015} 982}
1016 983
1017/* Download given firmware image to the device (IN BOOT MODE) */ 984/* Download given firmware image to the device (IN BOOT MODE) */
1018static int TIDownloadCodeImage (struct edgeport_serial *serial, __u8 *image, int image_length) 985static int download_code(struct edgeport_serial *serial, __u8 *image,
986 int image_length)
1019{ 987{
1020 int status = 0; 988 int status = 0;
1021 int pos; 989 int pos;
1022 int transfer; 990 int transfer;
1023 int done; 991 int done;
1024 992
1025 // Transfer firmware image 993 /* Transfer firmware image */
1026 for (pos = 0; pos < image_length; ) { 994 for (pos = 0; pos < image_length; ) {
1027 // Read the next buffer from file 995 /* Read the next buffer from file */
1028 transfer = image_length - pos; 996 transfer = image_length - pos;
1029 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE) 997 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
1030 transfer = EDGE_FW_BULK_MAX_PACKET_SIZE; 998 transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
1031 999
1032 // Transfer data 1000 /* Transfer data */
1033 status = TISendBulkTransferSync (serial->serial, &image[pos], transfer, &done); 1001 status = bulk_xfer(serial->serial, &image[pos],
1002 transfer, &done);
1034 if (status) 1003 if (status)
1035 break; 1004 break;
1036 // Advance buffer pointer 1005 /* Advance buffer pointer */
1037 pos += done; 1006 pos += done;
1038 } 1007 }
1039 1008
1040 return status; 1009 return status;
1041} 1010}
1042 1011
1043// FIXME!!! 1012/* FIXME!!! */
1044static int TIConfigureBootDevice (struct usb_device *dev) 1013static int config_boot_dev(struct usb_device *dev)
1045{ 1014{
1046 return 0; 1015 return 0;
1047} 1016}
1048 1017
1018static int ti_cpu_rev(struct edge_ti_manuf_descriptor *desc)
1019{
1020 return TI_GET_CPU_REVISION(desc->CpuRev_BoardRev);
1021}
1022
1049/** 1023/**
1050 * DownloadTIFirmware - Download run-time operating firmware to the TI5052 1024 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
1051 * 1025 *
1052 * This routine downloads the main operating code into the TI5052, using the 1026 * This routine downloads the main operating code into the TI5052, using the
1053 * boot code already burned into E2PROM or ROM. 1027 * boot code already burned into E2PROM or ROM.
1054 */ 1028 */
1055static int TIDownloadFirmware (struct edgeport_serial *serial) 1029static int download_fw(struct edgeport_serial *serial)
1056{ 1030{
1057 struct device *dev = &serial->serial->dev->dev; 1031 struct device *dev = &serial->serial->dev->dev;
1058 int status = 0; 1032 int status = 0;
@@ -1071,22 +1045,25 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1071 /* Default to type 2 i2c */ 1045 /* Default to type 2 i2c */
1072 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 1046 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1073 1047
1074 status = TIChooseConfiguration (serial->serial->dev); 1048 status = choose_config(serial->serial->dev);
1075 if (status) 1049 if (status)
1076 return status; 1050 return status;
1077 1051
1078 interface = &serial->serial->interface->cur_altsetting->desc; 1052 interface = &serial->serial->interface->cur_altsetting->desc;
1079 if (!interface) { 1053 if (!interface) {
1080 dev_err (dev, "%s - no interface set, error!\n", __func__); 1054 dev_err(dev, "%s - no interface set, error!\n", __func__);
1081 return -ENODEV; 1055 return -ENODEV;
1082 } 1056 }
1083 1057
1084 // Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING 1058 /*
1085 // if we have more than one endpoint we are definitely in download mode 1059 * Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
1060 * if we have more than one endpoint we are definitely in download
1061 * mode
1062 */
1086 if (interface->bNumEndpoints > 1) 1063 if (interface->bNumEndpoints > 1)
1087 serial->product_info.TiMode = TI_MODE_DOWNLOAD; 1064 serial->product_info.TiMode = TI_MODE_DOWNLOAD;
1088 else 1065 else
1089 // Otherwise we will remain in configuring mode 1066 /* Otherwise we will remain in configuring mode */
1090 serial->product_info.TiMode = TI_MODE_CONFIGURING; 1067 serial->product_info.TiMode = TI_MODE_CONFIGURING;
1091 1068
1092 /********************************************************************/ 1069 /********************************************************************/
@@ -1097,256 +1074,273 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1097 1074
1098 dbg("%s - RUNNING IN DOWNLOAD MODE", __func__); 1075 dbg("%s - RUNNING IN DOWNLOAD MODE", __func__);
1099 1076
1100 status = TiValidateI2cImage (serial); 1077 status = check_i2c_image(serial);
1101 if (status) { 1078 if (status) {
1102 dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__); 1079 dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__);
1103 return status; 1080 return status;
1104 } 1081 }
1105 1082
1106 /* Validate Hardware version number 1083 /* Validate Hardware version number
1107 * Read Manufacturing Descriptor from TI Based Edgeport 1084 * Read Manufacturing Descriptor from TI Based Edgeport
1108 */ 1085 */
1109 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL); 1086 ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
1110 if (!ti_manuf_desc) { 1087 if (!ti_manuf_desc) {
1111 dev_err (dev, "%s - out of memory.\n", __func__); 1088 dev_err(dev, "%s - out of memory.\n", __func__);
1112 return -ENOMEM; 1089 return -ENOMEM;
1113 } 1090 }
1114 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc); 1091 status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
1115 if (status) { 1092 if (status) {
1116 kfree (ti_manuf_desc); 1093 kfree(ti_manuf_desc);
1117 return status; 1094 return status;
1118 } 1095 }
1119 1096
1120 // Check version number of ION descriptor 1097 /* Check version number of ION descriptor */
1121 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) { 1098 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
1122 dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __func__, 1099 dbg("%s - Wrong CPU Rev %d (Must be 2)",
1123 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev)); 1100 __func__, ti_cpu_rev(ti_manuf_desc));
1124 kfree (ti_manuf_desc); 1101 kfree(ti_manuf_desc);
1125 return -EINVAL; 1102 return -EINVAL;
1126 } 1103 }
1127 1104
1128 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); 1105 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
1129 if (!rom_desc) { 1106 if (!rom_desc) {
1130 dev_err (dev, "%s - out of memory.\n", __func__); 1107 dev_err(dev, "%s - out of memory.\n", __func__);
1131 kfree (ti_manuf_desc); 1108 kfree(ti_manuf_desc);
1132 return -ENOMEM; 1109 return -ENOMEM;
1133 } 1110 }
1134 1111
1135 // Search for type 2 record (firmware record) 1112 /* Search for type 2 record (firmware record) */
1136 if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc)) != 0) { 1113 start_address = get_descriptor_addr(serial,
1114 I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
1115 if (start_address != 0) {
1137 struct ti_i2c_firmware_rec *firmware_version; 1116 struct ti_i2c_firmware_rec *firmware_version;
1138 __u8 record; 1117 __u8 record;
1139 1118
1140 dbg ("%s - Found Type FIRMWARE (Type 2) record", __func__); 1119 dbg("%s - Found Type FIRMWARE (Type 2) record",
1120 __func__);
1141 1121
1142 firmware_version = kmalloc (sizeof (*firmware_version), GFP_KERNEL); 1122 firmware_version = kmalloc(sizeof(*firmware_version),
1123 GFP_KERNEL);
1143 if (!firmware_version) { 1124 if (!firmware_version) {
1144 dev_err (dev, "%s - out of memory.\n", __func__); 1125 dev_err(dev, "%s - out of memory.\n", __func__);
1145 kfree (rom_desc); 1126 kfree(rom_desc);
1146 kfree (ti_manuf_desc); 1127 kfree(ti_manuf_desc);
1147 return -ENOMEM; 1128 return -ENOMEM;
1148 } 1129 }
1149 1130
1150 // Validate version number 1131 /* Validate version number
1151 // Read the descriptor data 1132 * Read the descriptor data
1152 status = TIReadRom (serial, 1133 */
1153 start_address+sizeof(struct ti_i2c_desc), 1134 status = read_rom(serial, start_address +
1135 sizeof(struct ti_i2c_desc),
1154 sizeof(struct ti_i2c_firmware_rec), 1136 sizeof(struct ti_i2c_firmware_rec),
1155 (__u8 *)firmware_version); 1137 (__u8 *)firmware_version);
1156 if (status) { 1138 if (status) {
1157 kfree (firmware_version); 1139 kfree(firmware_version);
1158 kfree (rom_desc); 1140 kfree(rom_desc);
1159 kfree (ti_manuf_desc); 1141 kfree(ti_manuf_desc);
1160 return status; 1142 return status;
1161 } 1143 }
1162 1144
1163 // Check version number of download with current version in I2c 1145 /* Check version number of download with current
1164 download_cur_ver = (firmware_version->Ver_Major << 8) + 1146 version in I2c */
1147 download_cur_ver = (firmware_version->Ver_Major << 8) +
1165 (firmware_version->Ver_Minor); 1148 (firmware_version->Ver_Minor);
1166 download_new_ver = (OperationalMajorVersion << 8) + 1149 download_new_ver = (OperationalMajorVersion << 8) +
1167 (OperationalMinorVersion); 1150 (OperationalMinorVersion);
1168 1151
1169 dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d", 1152 dbg("%s - >> FW Versions Device %d.%d Driver %d.%d",
1170 __func__, 1153 __func__,
1171 firmware_version->Ver_Major, 1154 firmware_version->Ver_Major,
1172 firmware_version->Ver_Minor, 1155 firmware_version->Ver_Minor,
1173 OperationalMajorVersion, 1156 OperationalMajorVersion,
1174 OperationalMinorVersion); 1157 OperationalMinorVersion);
1175 1158
1176 // Check if we have an old version in the I2C and update if necessary 1159 /* Check if we have an old version in the I2C and
1160 update if necessary */
1177 if (download_cur_ver != download_new_ver) { 1161 if (download_cur_ver != download_new_ver) {
1178 dbg ("%s - Update I2C Download from %d.%d to %d.%d", 1162 dbg("%s - Update I2C dld from %d.%d to %d.%d",
1179 __func__, 1163 __func__,
1180 firmware_version->Ver_Major, 1164 firmware_version->Ver_Major,
1181 firmware_version->Ver_Minor, 1165 firmware_version->Ver_Minor,
1182 OperationalMajorVersion, 1166 OperationalMajorVersion,
1183 OperationalMinorVersion); 1167 OperationalMinorVersion);
1184 1168
1185 // In order to update the I2C firmware we must change the type 2 record to type 0xF2. 1169 /* In order to update the I2C firmware we must
1186 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver 1170 * change the type 2 record to type 0xF2. This
1187 // will download the latest firmware (padded to 15.5k) into the UMP ram. 1171 * will force the UMP to come up in Boot Mode.
1188 // And finally when the device comes back up in download mode the driver will cause 1172 * Then while in boot mode, the driver will
1189 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update 1173 * download the latest firmware (padded to
1190 // the record type from 0xf2 to 0x02. 1174 * 15.5k) into the UMP ram. Finally when the
1191 1175 * device comes back up in download mode the
1176 * driver will cause the new firmware to be
1177 * copied from the UMP Ram to I2C and the
1178 * firmware will update the record type from
1179 * 0xf2 to 0x02.
1180 */
1192 record = I2C_DESC_TYPE_FIRMWARE_BLANK; 1181 record = I2C_DESC_TYPE_FIRMWARE_BLANK;
1193 1182
1194 // Change the I2C Firmware record type to 0xf2 to trigger an update 1183 /* Change the I2C Firmware record type to
1195 status = TIWriteRom (serial, 1184 0xf2 to trigger an update */
1196 start_address, 1185 status = write_rom(serial, start_address,
1197 sizeof(record), 1186 sizeof(record), &record);
1198 &record);
1199 if (status) { 1187 if (status) {
1200 kfree (firmware_version); 1188 kfree(firmware_version);
1201 kfree (rom_desc); 1189 kfree(rom_desc);
1202 kfree (ti_manuf_desc); 1190 kfree(ti_manuf_desc);
1203 return status; 1191 return status;
1204 } 1192 }
1205 1193
1206 // verify the write -- must do this in order for write to 1194 /* verify the write -- must do this in order
1207 // complete before we do the hardware reset 1195 * for write to complete before we do the
1208 status = TIReadRom (serial, 1196 * hardware reset
1197 */
1198 status = read_rom(serial,
1209 start_address, 1199 start_address,
1210 sizeof(record), 1200 sizeof(record),
1211 &record); 1201 &record);
1212
1213 if (status) { 1202 if (status) {
1214 kfree (firmware_version); 1203 kfree(firmware_version);
1215 kfree (rom_desc); 1204 kfree(rom_desc);
1216 kfree (ti_manuf_desc); 1205 kfree(ti_manuf_desc);
1217 return status; 1206 return status;
1218 } 1207 }
1219 1208
1220 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) { 1209 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
1221 dev_err (dev, "%s - error resetting device\n", __func__); 1210 dev_err(dev,
1222 kfree (firmware_version); 1211 "%s - error resetting device\n",
1223 kfree (rom_desc); 1212 __func__);
1224 kfree (ti_manuf_desc); 1213 kfree(firmware_version);
1214 kfree(rom_desc);
1215 kfree(ti_manuf_desc);
1225 return -ENODEV; 1216 return -ENODEV;
1226 } 1217 }
1227 1218
1228 dbg ("%s - HARDWARE RESET", __func__); 1219 dbg("%s - HARDWARE RESET", __func__);
1229 1220
1230 // Reset UMP -- Back to BOOT MODE 1221 /* Reset UMP -- Back to BOOT MODE */
1231 status = TISendVendorRequestSync (serial->serial->dev, 1222 status = ti_vsend_sync(serial->serial->dev,
1232 UMPC_HARDWARE_RESET, // Request 1223 UMPC_HARDWARE_RESET,
1233 0, // wValue 1224 0, 0, NULL, 0);
1234 0, // wIndex
1235 NULL, // TransferBuffer
1236 0); // TransferBufferLength
1237 1225
1238 dbg ( "%s - HARDWARE RESET return %d", __func__, status); 1226 dbg("%s - HARDWARE RESET return %d",
1227 __func__, status);
1239 1228
1240 /* return an error on purpose. */ 1229 /* return an error on purpose. */
1241 kfree (firmware_version); 1230 kfree(firmware_version);
1242 kfree (rom_desc); 1231 kfree(rom_desc);
1243 kfree (ti_manuf_desc); 1232 kfree(ti_manuf_desc);
1244 return -ENODEV; 1233 return -ENODEV;
1245 } 1234 }
1246 kfree (firmware_version); 1235 kfree(firmware_version);
1247 } 1236 }
1248 // Search for type 0xF2 record (firmware blank record) 1237 /* Search for type 0xF2 record (firmware blank record) */
1249 else if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) { 1238 else if ((start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
1250 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + sizeof(struct ti_i2c_firmware_rec)) 1239#define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \
1240 sizeof(struct ti_i2c_firmware_rec))
1251 __u8 *header; 1241 __u8 *header;
1252 __u8 *vheader; 1242 __u8 *vheader;
1253 1243
1254 header = kmalloc (HEADER_SIZE, GFP_KERNEL); 1244 header = kmalloc(HEADER_SIZE, GFP_KERNEL);
1255 if (!header) { 1245 if (!header) {
1256 dev_err (dev, "%s - out of memory.\n", __func__); 1246 dev_err(dev, "%s - out of memory.\n", __func__);
1257 kfree (rom_desc); 1247 kfree(rom_desc);
1258 kfree (ti_manuf_desc); 1248 kfree(ti_manuf_desc);
1259 return -ENOMEM; 1249 return -ENOMEM;
1260 } 1250 }
1261 1251
1262 vheader = kmalloc (HEADER_SIZE, GFP_KERNEL); 1252 vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
1263 if (!vheader) { 1253 if (!vheader) {
1264 dev_err (dev, "%s - out of memory.\n", __func__); 1254 dev_err(dev, "%s - out of memory.\n", __func__);
1265 kfree (header); 1255 kfree(header);
1266 kfree (rom_desc); 1256 kfree(rom_desc);
1267 kfree (ti_manuf_desc); 1257 kfree(ti_manuf_desc);
1268 return -ENOMEM; 1258 return -ENOMEM;
1269 } 1259 }
1270 1260
1271 dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __func__); 1261 dbg("%s - Found Type BLANK FIRMWARE (Type F2) record",
1272 1262 __func__);
1273 // In order to update the I2C firmware we must change the type 2 record to type 0xF2. 1263
1274 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver 1264 /*
1275 // will download the latest firmware (padded to 15.5k) into the UMP ram. 1265 * In order to update the I2C firmware we must change
1276 // And finally when the device comes back up in download mode the driver will cause 1266 * the type 2 record to type 0xF2. This will force the
1277 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update 1267 * UMP to come up in Boot Mode. Then while in boot
1278 // the record type from 0xf2 to 0x02. 1268 * mode, the driver will download the latest firmware
1279 status = BuildI2CFirmwareHeader(header, dev); 1269 * (padded to 15.5k) into the UMP ram. Finally when the
1270 * device comes back up in download mode the driver
1271 * will cause the new firmware to be copied from the
1272 * UMP Ram to I2C and the firmware will update the
1273 * record type from 0xf2 to 0x02.
1274 */
1275 status = build_i2c_fw_hdr(header, dev);
1280 if (status) { 1276 if (status) {
1281 kfree (vheader); 1277 kfree(vheader);
1282 kfree (header); 1278 kfree(header);
1283 kfree (rom_desc); 1279 kfree(rom_desc);
1284 kfree (ti_manuf_desc); 1280 kfree(ti_manuf_desc);
1285 return status; 1281 return status;
1286 } 1282 }
1287 1283
1288 // Update I2C with type 0xf2 record with correct size and checksum 1284 /* Update I2C with type 0xf2 record with correct
1289 status = TIWriteRom (serial, 1285 size and checksum */
1286 status = write_rom(serial,
1290 start_address, 1287 start_address,
1291 HEADER_SIZE, 1288 HEADER_SIZE,
1292 header); 1289 header);
1293 if (status) { 1290 if (status) {
1294 kfree (vheader); 1291 kfree(vheader);
1295 kfree (header); 1292 kfree(header);
1296 kfree (rom_desc); 1293 kfree(rom_desc);
1297 kfree (ti_manuf_desc); 1294 kfree(ti_manuf_desc);
1298 return status; 1295 return status;
1299 } 1296 }
1300 1297
1301 // verify the write -- must do this in order for write to 1298 /* verify the write -- must do this in order for
1302 // complete before we do the hardware reset 1299 write to complete before we do the hardware reset */
1303 status = TIReadRom (serial, 1300 status = read_rom(serial, start_address,
1304 start_address, 1301 HEADER_SIZE, vheader);
1305 HEADER_SIZE,
1306 vheader);
1307 1302
1308 if (status) { 1303 if (status) {
1309 dbg ("%s - can't read header back", __func__); 1304 dbg("%s - can't read header back", __func__);
1310 kfree (vheader); 1305 kfree(vheader);
1311 kfree (header); 1306 kfree(header);
1312 kfree (rom_desc); 1307 kfree(rom_desc);
1313 kfree (ti_manuf_desc); 1308 kfree(ti_manuf_desc);
1314 return status; 1309 return status;
1315 } 1310 }
1316 if (memcmp(vheader, header, HEADER_SIZE)) { 1311 if (memcmp(vheader, header, HEADER_SIZE)) {
1317 dbg ("%s - write download record failed", __func__); 1312 dbg("%s - write download record failed",
1318 kfree (vheader); 1313 __func__);
1319 kfree (header); 1314 kfree(vheader);
1320 kfree (rom_desc); 1315 kfree(header);
1321 kfree (ti_manuf_desc); 1316 kfree(rom_desc);
1317 kfree(ti_manuf_desc);
1322 return status; 1318 return status;
1323 } 1319 }
1324 1320
1325 kfree (vheader); 1321 kfree(vheader);
1326 kfree (header); 1322 kfree(header);
1327 1323
1328 dbg ("%s - Start firmware update", __func__); 1324 dbg("%s - Start firmware update", __func__);
1329 1325
1330 // Tell firmware to copy download image into I2C 1326 /* Tell firmware to copy download image into I2C */
1331 status = TISendVendorRequestSync (serial->serial->dev, 1327 status = ti_vsend_sync(serial->serial->dev,
1332 UMPC_COPY_DNLD_TO_I2C, // Request 1328 UMPC_COPY_DNLD_TO_I2C, 0, 0, NULL, 0);
1333 0, // wValue
1334 0, // wIndex
1335 NULL, // TransferBuffer
1336 0); // TransferBufferLength
1337 1329
1338 dbg ("%s - Update complete 0x%x", __func__, status); 1330 dbg("%s - Update complete 0x%x", __func__, status);
1339 if (status) { 1331 if (status) {
1340 dev_err (dev, "%s - UMPC_COPY_DNLD_TO_I2C failed\n", __func__); 1332 dev_err(dev,
1341 kfree (rom_desc); 1333 "%s - UMPC_COPY_DNLD_TO_I2C failed\n",
1342 kfree (ti_manuf_desc); 1334 __func__);
1335 kfree(rom_desc);
1336 kfree(ti_manuf_desc);
1343 return status; 1337 return status;
1344 } 1338 }
1345 } 1339 }
1346 1340
1347 // The device is running the download code 1341 // The device is running the download code
1348 kfree (rom_desc); 1342 kfree(rom_desc);
1349 kfree (ti_manuf_desc); 1343 kfree(ti_manuf_desc);
1350 return 0; 1344 return 0;
1351 } 1345 }
1352 1346
@@ -1355,32 +1349,26 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1355 /********************************************************************/ 1349 /********************************************************************/
1356 dbg("%s - RUNNING IN BOOT MODE", __func__); 1350 dbg("%s - RUNNING IN BOOT MODE", __func__);
1357 1351
1358 // Configure the TI device so we can use the BULK pipes for download 1352 /* Configure the TI device so we can use the BULK pipes for download */
1359 status = TIConfigureBootDevice (serial->serial->dev); 1353 status = config_boot_dev(serial->serial->dev);
1360 if (status) 1354 if (status)
1361 return status; 1355 return status;
1362 1356
1363 if (le16_to_cpu(serial->serial->dev->descriptor.idVendor) != USB_VENDOR_ID_ION) { 1357 if (le16_to_cpu(serial->serial->dev->descriptor.idVendor)
1364 dbg ("%s - VID = 0x%x", __func__, 1358 != USB_VENDOR_ID_ION) {
1359 dbg("%s - VID = 0x%x", __func__,
1365 le16_to_cpu(serial->serial->dev->descriptor.idVendor)); 1360 le16_to_cpu(serial->serial->dev->descriptor.idVendor));
1366 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 1361 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1367 goto StayInBootMode; 1362 goto stayinbootmode;
1368 } 1363 }
1369 1364
1370 // We have an ION device (I2c Must be programmed) 1365 /* We have an ION device (I2c Must be programmed)
1371 // Determine I2C image type 1366 Determine I2C image type */
1372 if (TIGetI2cTypeInBootMode(serial)) { 1367 if (i2c_type_bootmode(serial))
1373 goto StayInBootMode; 1368 goto stayinbootmode;
1374 }
1375 1369
1376 // Registry variable set? 1370 /* Check for ION Vendor ID and that the I2C is valid */
1377 if (TIStayInBootMode) { 1371 if (!check_i2c_image(serial)) {
1378 dbg ("%s - TIStayInBootMode", __func__);
1379 goto StayInBootMode;
1380 }
1381
1382 // Check for ION Vendor ID and that the I2C is valid
1383 if (!TiValidateI2cImage(serial)) {
1384 struct ti_i2c_image_header *header; 1372 struct ti_i2c_image_header *header;
1385 int i; 1373 int i;
1386 __u8 cs = 0; 1374 __u8 cs = 0;
@@ -1393,49 +1381,52 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1393 /* Validate Hardware version number 1381 /* Validate Hardware version number
1394 * Read Manufacturing Descriptor from TI Based Edgeport 1382 * Read Manufacturing Descriptor from TI Based Edgeport
1395 */ 1383 */
1396 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL); 1384 ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
1397 if (!ti_manuf_desc) { 1385 if (!ti_manuf_desc) {
1398 dev_err (dev, "%s - out of memory.\n", __func__); 1386 dev_err(dev, "%s - out of memory.\n", __func__);
1399 return -ENOMEM; 1387 return -ENOMEM;
1400 } 1388 }
1401 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc); 1389 status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
1402 if (status) { 1390 if (status) {
1403 kfree (ti_manuf_desc); 1391 kfree(ti_manuf_desc);
1404 goto StayInBootMode; 1392 goto stayinbootmode;
1405 } 1393 }
1406 1394
1407 // Check for version 2 1395 /* Check for version 2 */
1408 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) { 1396 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
1409 dbg ("%s - Wrong CPU Rev %d (Must be 2)", __func__, 1397 dbg("%s - Wrong CPU Rev %d (Must be 2)",
1410 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev)); 1398 __func__, ti_cpu_rev(ti_manuf_desc));
1411 kfree (ti_manuf_desc); 1399 kfree(ti_manuf_desc);
1412 goto StayInBootMode; 1400 goto stayinbootmode;
1413 } 1401 }
1414 1402
1415 kfree (ti_manuf_desc); 1403 kfree(ti_manuf_desc);
1416 1404
1417 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1418 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1419 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1420 // And finally when the device comes back up in download mode the driver will cause
1421 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1422 // the record type from 0xf2 to 0x02.
1423
1424 /* 1405 /*
1406 * In order to update the I2C firmware we must change the type
1407 * 2 record to type 0xF2. This will force the UMP to come up
1408 * in Boot Mode. Then while in boot mode, the driver will
1409 * download the latest firmware (padded to 15.5k) into the
1410 * UMP ram. Finally when the device comes back up in download
1411 * mode the driver will cause the new firmware to be copied
1412 * from the UMP Ram to I2C and the firmware will update the
1413 * record type from 0xf2 to 0x02.
1414 *
1425 * Do we really have to copy the whole firmware image, 1415 * Do we really have to copy the whole firmware image,
1426 * or could we do this in place! 1416 * or could we do this in place!
1427 */ 1417 */
1428 1418
1429 // Allocate a 15.5k buffer + 3 byte header 1419 /* Allocate a 15.5k buffer + 3 byte header */
1430 buffer_size = (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header)); 1420 buffer_size = (((1024 * 16) - 512) +
1431 buffer = kmalloc (buffer_size, GFP_KERNEL); 1421 sizeof(struct ti_i2c_image_header));
1422 buffer = kmalloc(buffer_size, GFP_KERNEL);
1432 if (!buffer) { 1423 if (!buffer) {
1433 dev_err (dev, "%s - out of memory\n", __func__); 1424 dev_err(dev, "%s - out of memory\n", __func__);
1434 return -ENOMEM; 1425 return -ENOMEM;
1435 } 1426 }
1436 1427
1437 // Initialize the buffer to 0xff (pad the buffer) 1428 /* Initialize the buffer to 0xff (pad the buffer) */
1438 memset (buffer, 0xff, buffer_size); 1429 memset(buffer, 0xff, buffer_size);
1439 1430
1440 err = request_firmware(&fw, fw_name, dev); 1431 err = request_firmware(&fw, fw_name, dev);
1441 if (err) { 1432 if (err) {
@@ -1447,38 +1438,43 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1447 memcpy(buffer, &fw->data[4], fw->size - 4); 1438 memcpy(buffer, &fw->data[4], fw->size - 4);
1448 release_firmware(fw); 1439 release_firmware(fw);
1449 1440
1450 for(i = sizeof(struct ti_i2c_image_header); i < buffer_size; i++) { 1441 for (i = sizeof(struct ti_i2c_image_header);
1442 i < buffer_size; i++) {
1451 cs = (__u8)(cs + buffer[i]); 1443 cs = (__u8)(cs + buffer[i]);
1452 } 1444 }
1453 1445
1454 header = (struct ti_i2c_image_header *)buffer; 1446 header = (struct ti_i2c_image_header *)buffer;
1455 1447
1456 // update length and checksum after padding 1448 /* update length and checksum after padding */
1457 header->Length = cpu_to_le16((__u16)(buffer_size - sizeof(struct ti_i2c_image_header))); 1449 header->Length = cpu_to_le16((__u16)(buffer_size -
1450 sizeof(struct ti_i2c_image_header)));
1458 header->CheckSum = cs; 1451 header->CheckSum = cs;
1459 1452
1460 // Download the operational code 1453 /* Download the operational code */
1461 dbg ("%s - Downloading operational code image (TI UMP)", __func__); 1454 dbg("%s - Downloading operational code image (TI UMP)",
1462 status = TIDownloadCodeImage (serial, buffer, buffer_size); 1455 __func__);
1456 status = download_code(serial, buffer, buffer_size);
1463 1457
1464 kfree (buffer); 1458 kfree(buffer);
1465 1459
1466 if (status) { 1460 if (status) {
1467 dbg ("%s - Error downloading operational code image", __func__); 1461 dbg("%s - Error downloading operational code image",
1462 __func__);
1468 return status; 1463 return status;
1469 } 1464 }
1470 1465
1471 // Device will reboot 1466 /* Device will reboot */
1472 serial->product_info.TiMode = TI_MODE_TRANSITIONING; 1467 serial->product_info.TiMode = TI_MODE_TRANSITIONING;
1473 1468
1474 dbg ("%s - Download successful -- Device rebooting...", __func__); 1469 dbg("%s - Download successful -- Device rebooting...",
1470 __func__);
1475 1471
1476 /* return an error on purpose */ 1472 /* return an error on purpose */
1477 return -ENODEV; 1473 return -ENODEV;
1478 } 1474 }
1479 1475
1480StayInBootMode: 1476stayinbootmode:
1481 // Eprom is invalid or blank stay in boot mode 1477 /* Eprom is invalid or blank stay in boot mode */
1482 dbg("%s - STAYING IN BOOT MODE", __func__); 1478 dbg("%s - STAYING IN BOOT MODE", __func__);
1483 serial->product_info.TiMode = TI_MODE_BOOT; 1479 serial->product_info.TiMode = TI_MODE_BOOT;
1484 1480
@@ -1486,156 +1482,33 @@ StayInBootMode:
1486} 1482}
1487 1483
1488 1484
1489static int TISetDtr (struct edgeport_port *port) 1485static int ti_do_config(struct edgeport_port *port, int feature, int on)
1490{
1491 int port_number = port->port->number - port->port->serial->minor;
1492
1493 dbg ("%s", __func__);
1494 port->shadow_mcr |= MCR_DTR;
1495
1496 return TIWriteCommandSync (port->port->serial->dev,
1497 UMPC_SET_CLR_DTR,
1498 (__u8)(UMPM_UART1_PORT + port_number),
1499 1, /* set */
1500 NULL,
1501 0);
1502}
1503
1504static int TIClearDtr (struct edgeport_port *port)
1505{
1506 int port_number = port->port->number - port->port->serial->minor;
1507
1508 dbg ("%s", __func__);
1509 port->shadow_mcr &= ~MCR_DTR;
1510
1511 return TIWriteCommandSync (port->port->serial->dev,
1512 UMPC_SET_CLR_DTR,
1513 (__u8)(UMPM_UART1_PORT + port_number),
1514 0, /* clear */
1515 NULL,
1516 0);
1517}
1518
1519static int TISetRts (struct edgeport_port *port)
1520{
1521 int port_number = port->port->number - port->port->serial->minor;
1522
1523 dbg ("%s", __func__);
1524 port->shadow_mcr |= MCR_RTS;
1525
1526 return TIWriteCommandSync (port->port->serial->dev,
1527 UMPC_SET_CLR_RTS,
1528 (__u8)(UMPM_UART1_PORT + port_number),
1529 1, /* set */
1530 NULL,
1531 0);
1532}
1533
1534static int TIClearRts (struct edgeport_port *port)
1535{
1536 int port_number = port->port->number - port->port->serial->minor;
1537
1538 dbg ("%s", __func__);
1539 port->shadow_mcr &= ~MCR_RTS;
1540
1541 return TIWriteCommandSync (port->port->serial->dev,
1542 UMPC_SET_CLR_RTS,
1543 (__u8)(UMPM_UART1_PORT + port_number),
1544 0, /* clear */
1545 NULL,
1546 0);
1547}
1548
1549static int TISetLoopBack (struct edgeport_port *port)
1550{
1551 int port_number = port->port->number - port->port->serial->minor;
1552
1553 dbg ("%s", __func__);
1554
1555 return TIWriteCommandSync (port->port->serial->dev,
1556 UMPC_SET_CLR_LOOPBACK,
1557 (__u8)(UMPM_UART1_PORT + port_number),
1558 1, /* set */
1559 NULL,
1560 0);
1561}
1562
1563static int TIClearLoopBack (struct edgeport_port *port)
1564{
1565 int port_number = port->port->number - port->port->serial->minor;
1566
1567 dbg ("%s", __func__);
1568
1569 return TIWriteCommandSync (port->port->serial->dev,
1570 UMPC_SET_CLR_LOOPBACK,
1571 (__u8)(UMPM_UART1_PORT + port_number),
1572 0, /* clear */
1573 NULL,
1574 0);
1575}
1576
1577static int TISetBreak (struct edgeport_port *port)
1578{ 1486{
1579 int port_number = port->port->number - port->port->serial->minor; 1487 int port_number = port->port->number - port->port->serial->minor;
1580 1488 on = !!on; /* 1 or 0 not bitmask */
1581 dbg ("%s", __func__); 1489 return send_cmd(port->port->serial->dev,
1582 1490 feature, (__u8)(UMPM_UART1_PORT + port_number),
1583 return TIWriteCommandSync (port->port->serial->dev, 1491 on, NULL, 0);
1584 UMPC_SET_CLR_BREAK,
1585 (__u8)(UMPM_UART1_PORT + port_number),
1586 1, /* set */
1587 NULL,
1588 0);
1589} 1492}
1590 1493
1591static int TIClearBreak (struct edgeport_port *port)
1592{
1593 int port_number = port->port->number - port->port->serial->minor;
1594
1595 dbg ("%s", __func__);
1596 1494
1597 return TIWriteCommandSync (port->port->serial->dev, 1495static int restore_mcr(struct edgeport_port *port, __u8 mcr)
1598 UMPC_SET_CLR_BREAK,
1599 (__u8)(UMPM_UART1_PORT + port_number),
1600 0, /* clear */
1601 NULL,
1602 0);
1603}
1604
1605static int TIRestoreMCR (struct edgeport_port *port, __u8 mcr)
1606{ 1496{
1607 int status = 0; 1497 int status = 0;
1608 1498
1609 dbg ("%s - %x", __func__, mcr); 1499 dbg("%s - %x", __func__, mcr);
1610
1611 if (mcr & MCR_DTR)
1612 status = TISetDtr (port);
1613 else
1614 status = TIClearDtr (port);
1615 1500
1501 status = ti_do_config(port, UMPC_SET_CLR_DTR, mcr & MCR_DTR);
1616 if (status) 1502 if (status)
1617 return status; 1503 return status;
1618 1504 status = ti_do_config(port, UMPC_SET_CLR_RTS, mcr & MCR_RTS);
1619 if (mcr & MCR_RTS)
1620 status = TISetRts (port);
1621 else
1622 status = TIClearRts (port);
1623
1624 if (status) 1505 if (status)
1625 return status; 1506 return status;
1626 1507 return ti_do_config(port, UMPC_SET_CLR_LOOPBACK, mcr & MCR_LOOPBACK);
1627 if (mcr & MCR_LOOPBACK)
1628 status = TISetLoopBack (port);
1629 else
1630 status = TIClearLoopBack (port);
1631
1632 return status;
1633} 1508}
1634 1509
1635
1636
1637/* Convert TI LSR to standard UART flags */ 1510/* Convert TI LSR to standard UART flags */
1638static __u8 MapLineStatus (__u8 ti_lsr) 1511static __u8 map_line_status(__u8 ti_lsr)
1639{ 1512{
1640 __u8 lsr = 0; 1513 __u8 lsr = 0;
1641 1514
@@ -1647,22 +1520,23 @@ static __u8 MapLineStatus (__u8 ti_lsr)
1647 MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */ 1520 MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
1648 MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */ 1521 MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
1649 MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */ 1522 MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
1650 MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* receive data available */ 1523 MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* rx data available */
1651 MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* transmit holding register empty */ 1524 MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* tx hold reg empty */
1652 1525
1653#undef MAP_FLAG 1526#undef MAP_FLAG
1654 1527
1655 return lsr; 1528 return lsr;
1656} 1529}
1657 1530
1658static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr) 1531static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1659{ 1532{
1660 struct async_icount *icount; 1533 struct async_icount *icount;
1661 struct tty_struct *tty; 1534 struct tty_struct *tty;
1662 1535
1663 dbg ("%s - %02x", __func__, msr); 1536 dbg("%s - %02x", __func__, msr);
1664 1537
1665 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { 1538 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
1539 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
1666 icount = &edge_port->icount; 1540 icount = &edge_port->icount;
1667 1541
1668 /* update input line counters */ 1542 /* update input line counters */
@@ -1674,13 +1548,13 @@ static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
1674 icount->dcd++; 1548 icount->dcd++;
1675 if (msr & EDGEPORT_MSR_DELTA_RI) 1549 if (msr & EDGEPORT_MSR_DELTA_RI)
1676 icount->rng++; 1550 icount->rng++;
1677 wake_up_interruptible (&edge_port->delta_msr_wait); 1551 wake_up_interruptible(&edge_port->delta_msr_wait);
1678 } 1552 }
1679 1553
1680 /* Save the new modem status */ 1554 /* Save the new modem status */
1681 edge_port->shadow_msr = msr & 0xf0; 1555 edge_port->shadow_msr = msr & 0xf0;
1682 1556
1683 tty = edge_port->port->tty; 1557 tty = edge_port->port->port.tty;
1684 /* handle CTS flow control */ 1558 /* handle CTS flow control */
1685 if (tty && C_CRTSCTS(tty)) { 1559 if (tty && C_CRTSCTS(tty)) {
1686 if (msr & EDGEPORT_MSR_CTS) { 1560 if (msr & EDGEPORT_MSR_CTS) {
@@ -1694,26 +1568,27 @@ static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
1694 return; 1568 return;
1695} 1569}
1696 1570
1697static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8 lsr, __u8 data) 1571static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
1572 __u8 lsr, __u8 data)
1698{ 1573{
1699 struct async_icount *icount; 1574 struct async_icount *icount;
1700 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)); 1575 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR |
1576 LSR_FRM_ERR | LSR_BREAK));
1701 1577
1702 dbg ("%s - %02x", __func__, new_lsr); 1578 dbg("%s - %02x", __func__, new_lsr);
1703 1579
1704 edge_port->shadow_lsr = lsr; 1580 edge_port->shadow_lsr = lsr;
1705 1581
1706 if (new_lsr & LSR_BREAK) { 1582 if (new_lsr & LSR_BREAK)
1707 /* 1583 /*
1708 * Parity and Framing errors only count if they 1584 * Parity and Framing errors only count if they
1709 * occur exclusive of a break being received. 1585 * occur exclusive of a break being received.
1710 */ 1586 */
1711 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); 1587 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
1712 }
1713 1588
1714 /* Place LSR data byte into Rx buffer */ 1589 /* Place LSR data byte into Rx buffer */
1715 if (lsr_data && edge_port->port->tty) 1590 if (lsr_data && edge_port->port->port.tty)
1716 edge_tty_recv(&edge_port->port->dev, edge_port->port->tty, &data, 1); 1591 edge_tty_recv(&edge_port->port->dev, edge_port->port->port.tty, &data, 1);
1717 1592
1718 /* update input line counters */ 1593 /* update input line counters */
1719 icount = &edge_port->icount; 1594 icount = &edge_port->icount;
@@ -1728,7 +1603,7 @@ static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8
1728} 1603}
1729 1604
1730 1605
1731static void edge_interrupt_callback (struct urb *urb) 1606static void edge_interrupt_callback(struct urb *urb)
1732{ 1607{
1733 struct edgeport_serial *edge_serial = urb->context; 1608 struct edgeport_serial *edge_serial = urb->context;
1734 struct usb_serial_port *port; 1609 struct usb_serial_port *port;
@@ -1762,66 +1637,71 @@ static void edge_interrupt_callback (struct urb *urb)
1762 } 1637 }
1763 1638
1764 if (!length) { 1639 if (!length) {
1765 dbg ("%s - no data in urb", __func__); 1640 dbg("%s - no data in urb", __func__);
1766 goto exit; 1641 goto exit;
1767 } 1642 }
1768 1643
1769 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, length, data); 1644 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev,
1770 1645 __func__, length, data);
1646
1771 if (length != 2) { 1647 if (length != 2) {
1772 dbg ("%s - expecting packet of size 2, got %d", __func__, length); 1648 dbg("%s - expecting packet of size 2, got %d",
1649 __func__, length);
1773 goto exit; 1650 goto exit;
1774 } 1651 }
1775 1652
1776 port_number = TIUMP_GET_PORT_FROM_CODE (data[0]); 1653 port_number = TIUMP_GET_PORT_FROM_CODE(data[0]);
1777 function = TIUMP_GET_FUNC_FROM_CODE (data[0]); 1654 function = TIUMP_GET_FUNC_FROM_CODE(data[0]);
1778 dbg ("%s - port_number %d, function %d, info 0x%x", 1655 dbg("%s - port_number %d, function %d, info 0x%x",
1779 __func__, port_number, function, data[1]); 1656 __func__, port_number, function, data[1]);
1780 port = edge_serial->serial->port[port_number]; 1657 port = edge_serial->serial->port[port_number];
1781 edge_port = usb_get_serial_port_data(port); 1658 edge_port = usb_get_serial_port_data(port);
1782 if (!edge_port) { 1659 if (!edge_port) {
1783 dbg ("%s - edge_port not found", __func__); 1660 dbg("%s - edge_port not found", __func__);
1784 return; 1661 return;
1785 } 1662 }
1786 switch (function) { 1663 switch (function) {
1787 case TIUMP_INTERRUPT_CODE_LSR: 1664 case TIUMP_INTERRUPT_CODE_LSR:
1788 lsr = MapLineStatus(data[1]); 1665 lsr = map_line_status(data[1]);
1789 if (lsr & UMP_UART_LSR_DATA_MASK) { 1666 if (lsr & UMP_UART_LSR_DATA_MASK) {
1790 /* Save the LSR event for bulk read completion routine */ 1667 /* Save the LSR event for bulk read
1791 dbg ("%s - LSR Event Port %u LSR Status = %02x", 1668 completion routine */
1669 dbg("%s - LSR Event Port %u LSR Status = %02x",
1792 __func__, port_number, lsr); 1670 __func__, port_number, lsr);
1793 edge_port->lsr_event = 1; 1671 edge_port->lsr_event = 1;
1794 edge_port->lsr_mask = lsr; 1672 edge_port->lsr_mask = lsr;
1795 } else { 1673 } else {
1796 dbg ("%s - ===== Port %d LSR Status = %02x ======", 1674 dbg("%s - ===== Port %d LSR Status = %02x ======",
1797 __func__, port_number, lsr); 1675 __func__, port_number, lsr);
1798 handle_new_lsr (edge_port, 0, lsr, 0); 1676 handle_new_lsr(edge_port, 0, lsr, 0);
1799 } 1677 }
1800 break; 1678 break;
1801 1679
1802 case TIUMP_INTERRUPT_CODE_MSR: // MSR 1680 case TIUMP_INTERRUPT_CODE_MSR: /* MSR */
1803 /* Copy MSR from UMP */ 1681 /* Copy MSR from UMP */
1804 msr = data[1]; 1682 msr = data[1];
1805 dbg ("%s - ===== Port %u MSR Status = %02x ======\n", 1683 dbg("%s - ===== Port %u MSR Status = %02x ======\n",
1806 __func__, port_number, msr); 1684 __func__, port_number, msr);
1807 handle_new_msr (edge_port, msr); 1685 handle_new_msr(edge_port, msr);
1808 break; 1686 break;
1809 1687
1810 default: 1688 default:
1811 dev_err (&urb->dev->dev, "%s - Unknown Interrupt code from UMP %x\n", 1689 dev_err(&urb->dev->dev,
1812 __func__, data[1]); 1690 "%s - Unknown Interrupt code from UMP %x\n",
1691 __func__, data[1]);
1813 break; 1692 break;
1814 1693
1815 } 1694 }
1816 1695
1817exit: 1696exit:
1818 retval = usb_submit_urb (urb, GFP_ATOMIC); 1697 retval = usb_submit_urb(urb, GFP_ATOMIC);
1819 if (retval) 1698 if (retval)
1820 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", 1699 dev_err(&urb->dev->dev,
1700 "%s - usb_submit_urb failed with result %d\n",
1821 __func__, retval); 1701 __func__, retval);
1822} 1702}
1823 1703
1824static void edge_bulk_in_callback (struct urb *urb) 1704static void edge_bulk_in_callback(struct urb *urb)
1825{ 1705{
1826 struct edgeport_port *edge_port = urb->context; 1706 struct edgeport_port *edge_port = urb->context;
1827 unsigned char *data = urb->transfer_buffer; 1707 unsigned char *data = urb->transfer_buffer;
@@ -1844,15 +1724,16 @@ static void edge_bulk_in_callback (struct urb *urb)
1844 __func__, status); 1724 __func__, status);
1845 return; 1725 return;
1846 default: 1726 default:
1847 dev_err (&urb->dev->dev,"%s - nonzero read bulk status received: %d\n", 1727 dev_err(&urb->dev->dev,
1848 __func__, status); 1728 "%s - nonzero read bulk status received: %d\n",
1729 __func__, status);
1849 } 1730 }
1850 1731
1851 if (status == -EPIPE) 1732 if (status == -EPIPE)
1852 goto exit; 1733 goto exit;
1853 1734
1854 if (status) { 1735 if (status) {
1855 dev_err(&urb->dev->dev,"%s - stopping read!\n", __func__); 1736 dev_err(&urb->dev->dev, "%s - stopping read!\n", __func__);
1856 return; 1737 return;
1857 } 1738 }
1858 1739
@@ -1860,23 +1741,24 @@ static void edge_bulk_in_callback (struct urb *urb)
1860 1741
1861 if (edge_port->lsr_event) { 1742 if (edge_port->lsr_event) {
1862 edge_port->lsr_event = 0; 1743 edge_port->lsr_event = 0;
1863 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======", 1744 dbg("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1864 __func__, port_number, edge_port->lsr_mask, *data); 1745 __func__, port_number, edge_port->lsr_mask, *data);
1865 handle_new_lsr (edge_port, 1, edge_port->lsr_mask, *data); 1746 handle_new_lsr(edge_port, 1, edge_port->lsr_mask, *data);
1866 /* Adjust buffer length/pointer */ 1747 /* Adjust buffer length/pointer */
1867 --urb->actual_length; 1748 --urb->actual_length;
1868 ++data; 1749 ++data;
1869 } 1750 }
1870 1751
1871 tty = edge_port->port->tty; 1752 tty = edge_port->port->port.tty;
1872 if (tty && urb->actual_length) { 1753 if (tty && urb->actual_length) {
1873 usb_serial_debug_data(debug, &edge_port->port->dev, __func__, urb->actual_length, data); 1754 usb_serial_debug_data(debug, &edge_port->port->dev,
1874 1755 __func__, urb->actual_length, data);
1875 if (edge_port->close_pending) { 1756 if (edge_port->close_pending)
1876 dbg ("%s - close is pending, dropping data on the floor.", __func__); 1757 dbg("%s - close pending, dropping data on the floor",
1877 } else { 1758 __func__);
1878 edge_tty_recv(&edge_port->port->dev, tty, data, urb->actual_length); 1759 else
1879 } 1760 edge_tty_recv(&edge_port->port->dev, tty, data,
1761 urb->actual_length);
1880 edge_port->icount.rx += urb->actual_length; 1762 edge_port->icount.rx += urb->actual_length;
1881 } 1763 }
1882 1764
@@ -1891,37 +1773,31 @@ exit:
1891 } 1773 }
1892 spin_unlock(&edge_port->ep_lock); 1774 spin_unlock(&edge_port->ep_lock);
1893 if (retval) 1775 if (retval)
1894 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", 1776 dev_err(&urb->dev->dev,
1777 "%s - usb_submit_urb failed with result %d\n",
1895 __func__, retval); 1778 __func__, retval);
1896} 1779}
1897 1780
1898static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length) 1781static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
1782 unsigned char *data, int length)
1899{ 1783{
1900 int cnt; 1784 int queued;
1901
1902 do {
1903 cnt = tty_buffer_request_room(tty, length);
1904 if (cnt < length) {
1905 dev_err(dev, "%s - dropping data, %d bytes lost\n",
1906 __func__, length - cnt);
1907 if(cnt == 0)
1908 break;
1909 }
1910 tty_insert_flip_string(tty, data, cnt);
1911 data += cnt;
1912 length -= cnt;
1913 } while (length > 0);
1914 1785
1786 tty_buffer_request_room(tty, length);
1787 queued = tty_insert_flip_string(tty, data, length);
1788 if (queued < length)
1789 dev_err(dev, "%s - dropping data, %d bytes lost\n",
1790 __func__, length - queued);
1915 tty_flip_buffer_push(tty); 1791 tty_flip_buffer_push(tty);
1916} 1792}
1917 1793
1918static void edge_bulk_out_callback (struct urb *urb) 1794static void edge_bulk_out_callback(struct urb *urb)
1919{ 1795{
1920 struct usb_serial_port *port = urb->context; 1796 struct usb_serial_port *port = urb->context;
1921 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1797 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1922 int status = urb->status; 1798 int status = urb->status;
1923 1799
1924 dbg ("%s - port %d", __func__, port->number); 1800 dbg("%s - port %d", __func__, port->number);
1925 1801
1926 edge_port->ep_write_urb_in_use = 0; 1802 edge_port->ep_write_urb_in_use = 0;
1927 1803
@@ -1942,10 +1818,11 @@ static void edge_bulk_out_callback (struct urb *urb)
1942 } 1818 }
1943 1819
1944 /* send any buffered data */ 1820 /* send any buffered data */
1945 edge_send(port); 1821 edge_send(port->port.tty);
1946} 1822}
1947 1823
1948static int edge_open (struct usb_serial_port *port, struct file * filp) 1824static int edge_open(struct tty_struct *tty,
1825 struct usb_serial_port *port, struct file *filp)
1949{ 1826{
1950 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1827 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1951 struct edgeport_serial *edge_serial; 1828 struct edgeport_serial *edge_serial;
@@ -1961,122 +1838,125 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
1961 if (edge_port == NULL) 1838 if (edge_port == NULL)
1962 return -ENODEV; 1839 return -ENODEV;
1963 1840
1964 port->tty->low_latency = low_latency; 1841 if (tty)
1842 tty->low_latency = low_latency;
1965 1843
1966 port_number = port->number - port->serial->minor; 1844 port_number = port->number - port->serial->minor;
1967 switch (port_number) { 1845 switch (port_number) {
1968 case 0: 1846 case 0:
1969 edge_port->uart_base = UMPMEM_BASE_UART1; 1847 edge_port->uart_base = UMPMEM_BASE_UART1;
1970 edge_port->dma_address = UMPD_OEDB1_ADDRESS; 1848 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
1971 break; 1849 break;
1972 case 1: 1850 case 1:
1973 edge_port->uart_base = UMPMEM_BASE_UART2; 1851 edge_port->uart_base = UMPMEM_BASE_UART2;
1974 edge_port->dma_address = UMPD_OEDB2_ADDRESS; 1852 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
1975 break; 1853 break;
1976 default: 1854 default:
1977 dev_err (&port->dev, "Unknown port number!!!\n"); 1855 dev_err(&port->dev, "Unknown port number!!!\n");
1978 return -ENODEV; 1856 return -ENODEV;
1979 } 1857 }
1980 1858
1981 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x", 1859 dbg("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1982 __func__, port_number, edge_port->uart_base, edge_port->dma_address); 1860 __func__, port_number, edge_port->uart_base,
1861 edge_port->dma_address);
1983 1862
1984 dev = port->serial->dev; 1863 dev = port->serial->dev;
1985 1864
1986 memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount)); 1865 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1987 init_waitqueue_head (&edge_port->delta_msr_wait); 1866 init_waitqueue_head(&edge_port->delta_msr_wait);
1988 1867
1989 /* turn off loopback */ 1868 /* turn off loopback */
1990 status = TIClearLoopBack (edge_port); 1869 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
1991 if (status) { 1870 if (status) {
1992 dev_err(&port->dev,"%s - cannot send clear loopback command, %d\n", 1871 dev_err(&port->dev,
1872 "%s - cannot send clear loopback command, %d\n",
1993 __func__, status); 1873 __func__, status);
1994 return status; 1874 return status;
1995 } 1875 }
1996 1876
1997 /* set up the port settings */ 1877 /* set up the port settings */
1998 edge_set_termios (port, port->tty->termios); 1878 if (tty)
1879 edge_set_termios(tty, port, port->port.tty->termios);
1999 1880
2000 /* open up the port */ 1881 /* open up the port */
2001 1882
2002 /* milliseconds to timeout for DMA transfer */ 1883 /* milliseconds to timeout for DMA transfer */
2003 transaction_timeout = 2; 1884 transaction_timeout = 2;
2004 1885
2005 edge_port->ump_read_timeout = max (20, ((transaction_timeout * 3) / 2) ); 1886 edge_port->ump_read_timeout =
1887 max(20, ((transaction_timeout * 3) / 2));
2006 1888
2007 // milliseconds to timeout for DMA transfer 1889 /* milliseconds to timeout for DMA transfer */
2008 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS | 1890 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
2009 UMP_PIPE_TRANS_TIMEOUT_ENA | 1891 UMP_PIPE_TRANS_TIMEOUT_ENA |
2010 (transaction_timeout << 2)); 1892 (transaction_timeout << 2));
2011 1893
2012 dbg ("%s - Sending UMPC_OPEN_PORT", __func__); 1894 dbg("%s - Sending UMPC_OPEN_PORT", __func__);
2013 1895
2014 /* Tell TI to open and start the port */ 1896 /* Tell TI to open and start the port */
2015 status = TIWriteCommandSync (dev, 1897 status = send_cmd(dev, UMPC_OPEN_PORT,
2016 UMPC_OPEN_PORT, 1898 (u8)(UMPM_UART1_PORT + port_number), open_settings, NULL, 0);
2017 (u8)(UMPM_UART1_PORT + port_number),
2018 open_settings,
2019 NULL,
2020 0);
2021 if (status) { 1899 if (status) {
2022 dev_err(&port->dev,"%s - cannot send open command, %d\n", __func__, status); 1900 dev_err(&port->dev, "%s - cannot send open command, %d\n",
1901 __func__, status);
2023 return status; 1902 return status;
2024 } 1903 }
2025 1904
2026 /* Start the DMA? */ 1905 /* Start the DMA? */
2027 status = TIWriteCommandSync (dev, 1906 status = send_cmd(dev, UMPC_START_PORT,
2028 UMPC_START_PORT, 1907 (u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
2029 (u8)(UMPM_UART1_PORT + port_number),
2030 0,
2031 NULL,
2032 0);
2033 if (status) { 1908 if (status) {
2034 dev_err(&port->dev,"%s - cannot send start DMA command, %d\n", __func__, status); 1909 dev_err(&port->dev, "%s - cannot send start DMA command, %d\n",
1910 __func__, status);
2035 return status; 1911 return status;
2036 } 1912 }
2037 1913
2038 /* Clear TX and RX buffers in UMP */ 1914 /* Clear TX and RX buffers in UMP */
2039 status = TIPurgeDataSync (port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN); 1915 status = purge_port(port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
2040 if (status) { 1916 if (status) {
2041 dev_err(&port->dev,"%s - cannot send clear buffers command, %d\n", __func__, status); 1917 dev_err(&port->dev,
1918 "%s - cannot send clear buffers command, %d\n",
1919 __func__, status);
2042 return status; 1920 return status;
2043 } 1921 }
2044 1922
2045 /* Read Initial MSR */ 1923 /* Read Initial MSR */
2046 status = TIReadVendorRequestSync (dev, 1924 status = ti_vread_sync(dev, UMPC_READ_MSR, 0,
2047 UMPC_READ_MSR, // Request 1925 (__u16)(UMPM_UART1_PORT + port_number),
2048 0, // wValue 1926 &edge_port->shadow_msr, 1);
2049 (__u16)(UMPM_UART1_PORT + port_number), // wIndex (Address)
2050 &edge_port->shadow_msr, // TransferBuffer
2051 1); // TransferBufferLength
2052 if (status) { 1927 if (status) {
2053 dev_err(&port->dev,"%s - cannot send read MSR command, %d\n", __func__, status); 1928 dev_err(&port->dev, "%s - cannot send read MSR command, %d\n",
1929 __func__, status);
2054 return status; 1930 return status;
2055 } 1931 }
2056 1932
2057 dbg ("ShadowMSR 0x%X", edge_port->shadow_msr); 1933 dbg("ShadowMSR 0x%X", edge_port->shadow_msr);
2058 1934
2059 /* Set Initial MCR */ 1935 /* Set Initial MCR */
2060 edge_port->shadow_mcr = MCR_RTS | MCR_DTR; 1936 edge_port->shadow_mcr = MCR_RTS | MCR_DTR;
2061 dbg ("ShadowMCR 0x%X", edge_port->shadow_mcr); 1937 dbg("ShadowMCR 0x%X", edge_port->shadow_mcr);
2062 1938
2063 edge_serial = edge_port->edge_serial; 1939 edge_serial = edge_port->edge_serial;
2064 if (mutex_lock_interruptible(&edge_serial->es_lock)) 1940 if (mutex_lock_interruptible(&edge_serial->es_lock))
2065 return -ERESTARTSYS; 1941 return -ERESTARTSYS;
2066 if (edge_serial->num_ports_open == 0) { 1942 if (edge_serial->num_ports_open == 0) {
2067 /* we are the first port to be opened, let's post the interrupt urb */ 1943 /* we are the first port to open, post the interrupt urb */
2068 urb = edge_serial->serial->port[0]->interrupt_in_urb; 1944 urb = edge_serial->serial->port[0]->interrupt_in_urb;
2069 if (!urb) { 1945 if (!urb) {
2070 dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __func__); 1946 dev_err(&port->dev,
1947 "%s - no interrupt urb present, exiting\n",
1948 __func__);
2071 status = -EINVAL; 1949 status = -EINVAL;
2072 goto release_es_lock; 1950 goto release_es_lock;
2073 } 1951 }
2074 urb->complete = edge_interrupt_callback; 1952 urb->complete = edge_interrupt_callback;
2075 urb->context = edge_serial; 1953 urb->context = edge_serial;
2076 urb->dev = dev; 1954 urb->dev = dev;
2077 status = usb_submit_urb (urb, GFP_KERNEL); 1955 status = usb_submit_urb(urb, GFP_KERNEL);
2078 if (status) { 1956 if (status) {
2079 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __func__, status); 1957 dev_err(&port->dev,
1958 "%s - usb_submit_urb failed with value %d\n",
1959 __func__, status);
2080 goto release_es_lock; 1960 goto release_es_lock;
2081 } 1961 }
2082 } 1962 }
@@ -2085,13 +1965,14 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2085 * reset the data toggle on the bulk endpoints to work around bug in 1965 * reset the data toggle on the bulk endpoints to work around bug in
2086 * host controllers where things get out of sync some times 1966 * host controllers where things get out of sync some times
2087 */ 1967 */
2088 usb_clear_halt (dev, port->write_urb->pipe); 1968 usb_clear_halt(dev, port->write_urb->pipe);
2089 usb_clear_halt (dev, port->read_urb->pipe); 1969 usb_clear_halt(dev, port->read_urb->pipe);
2090 1970
2091 /* start up our bulk read urb */ 1971 /* start up our bulk read urb */
2092 urb = port->read_urb; 1972 urb = port->read_urb;
2093 if (!urb) { 1973 if (!urb) {
2094 dev_err (&port->dev, "%s - no read urb present, exiting\n", __func__); 1974 dev_err(&port->dev, "%s - no read urb present, exiting\n",
1975 __func__);
2095 status = -EINVAL; 1976 status = -EINVAL;
2096 goto unlink_int_urb; 1977 goto unlink_int_urb;
2097 } 1978 }
@@ -2099,9 +1980,11 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2099 urb->complete = edge_bulk_in_callback; 1980 urb->complete = edge_bulk_in_callback;
2100 urb->context = edge_port; 1981 urb->context = edge_port;
2101 urb->dev = dev; 1982 urb->dev = dev;
2102 status = usb_submit_urb (urb, GFP_KERNEL); 1983 status = usb_submit_urb(urb, GFP_KERNEL);
2103 if (status) { 1984 if (status) {
2104 dev_err (&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __func__, status); 1985 dev_err(&port->dev,
1986 "%s - read bulk usb_submit_urb failed with value %d\n",
1987 __func__, status);
2105 goto unlink_int_urb; 1988 goto unlink_int_urb;
2106 } 1989 }
2107 1990
@@ -2119,7 +2002,8 @@ release_es_lock:
2119 return status; 2002 return status;
2120} 2003}
2121 2004
2122static void edge_close (struct usb_serial_port *port, struct file *filp) 2005static void edge_close(struct tty_struct *tty,
2006 struct usb_serial_port *port, struct file *filp)
2123{ 2007{
2124 struct edgeport_serial *edge_serial; 2008 struct edgeport_serial *edge_serial;
2125 struct edgeport_port *edge_port; 2009 struct edgeport_port *edge_port;
@@ -2127,18 +2011,18 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
2127 int status; 2011 int status;
2128 2012
2129 dbg("%s - port %d", __func__, port->number); 2013 dbg("%s - port %d", __func__, port->number);
2130 2014
2131 edge_serial = usb_get_serial_data(port->serial); 2015 edge_serial = usb_get_serial_data(port->serial);
2132 edge_port = usb_get_serial_port_data(port); 2016 edge_port = usb_get_serial_port_data(port);
2133 if ((edge_serial == NULL) || (edge_port == NULL)) 2017 if (edge_serial == NULL || edge_port == NULL)
2134 return; 2018 return;
2135 2019
2136 /* The bulkreadcompletion routine will check 2020 /* The bulkreadcompletion routine will check
2137 * this flag and dump add read data */ 2021 * this flag and dump add read data */
2138 edge_port->close_pending = 1; 2022 edge_port->close_pending = 1;
2139 2023
2140 /* chase the port close and flush */ 2024 /* chase the port close and flush */
2141 TIChasePort (edge_port, (HZ*closing_wait)/100, 1); 2025 chase_port(edge_port, (HZ * closing_wait) / 100, 1);
2142 2026
2143 usb_kill_urb(port->read_urb); 2027 usb_kill_urb(port->read_urb);
2144 usb_kill_urb(port->write_urb); 2028 usb_kill_urb(port->write_urb);
@@ -2148,7 +2032,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
2148 * send a close port command to it */ 2032 * send a close port command to it */
2149 dbg("%s - send umpc_close_port", __func__); 2033 dbg("%s - send umpc_close_port", __func__);
2150 port_number = port->number - port->serial->minor; 2034 port_number = port->number - port->serial->minor;
2151 status = TIWriteCommandSync (port->serial->dev, 2035 status = send_cmd(port->serial->dev,
2152 UMPC_CLOSE_PORT, 2036 UMPC_CLOSE_PORT,
2153 (__u8)(UMPM_UART1_PORT + port_number), 2037 (__u8)(UMPM_UART1_PORT + port_number),
2154 0, 2038 0,
@@ -2167,7 +2051,8 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
2167 dbg("%s - exited", __func__); 2051 dbg("%s - exited", __func__);
2168} 2052}
2169 2053
2170static int edge_write (struct usb_serial_port *port, const unsigned char *data, int count) 2054static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
2055 const unsigned char *data, int count)
2171{ 2056{
2172 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2057 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2173 unsigned long flags; 2058 unsigned long flags;
@@ -2188,16 +2073,16 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
2188 count = edge_buf_put(edge_port->ep_out_buf, data, count); 2073 count = edge_buf_put(edge_port->ep_out_buf, data, count);
2189 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2074 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2190 2075
2191 edge_send(port); 2076 edge_send(tty);
2192 2077
2193 return count; 2078 return count;
2194} 2079}
2195 2080
2196static void edge_send(struct usb_serial_port *port) 2081static void edge_send(struct tty_struct *tty)
2197{ 2082{
2083 struct usb_serial_port *port = tty->driver_data;
2198 int count, result; 2084 int count, result;
2199 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2085 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2200 struct tty_struct *tty = port->tty;
2201 unsigned long flags; 2086 unsigned long flags;
2202 2087
2203 2088
@@ -2223,11 +2108,12 @@ static void edge_send(struct usb_serial_port *port)
2223 2108
2224 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2109 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2225 2110
2226 usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer); 2111 usb_serial_debug_data(debug, &port->dev, __func__, count,
2112 port->write_urb->transfer_buffer);
2227 2113
2228 /* set up our urb */ 2114 /* set up our urb */
2229 usb_fill_bulk_urb (port->write_urb, port->serial->dev, 2115 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
2230 usb_sndbulkpipe (port->serial->dev, 2116 usb_sndbulkpipe(port->serial->dev,
2231 port->bulk_out_endpointAddress), 2117 port->bulk_out_endpointAddress),
2232 port->write_urb->transfer_buffer, count, 2118 port->write_urb->transfer_buffer, count,
2233 edge_bulk_out_callback, 2119 edge_bulk_out_callback,
@@ -2236,23 +2122,23 @@ static void edge_send(struct usb_serial_port *port)
2236 /* send the data out the bulk port */ 2122 /* send the data out the bulk port */
2237 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 2123 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
2238 if (result) { 2124 if (result) {
2239 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); 2125 dev_err(&port->dev,
2126 "%s - failed submitting write urb, error %d\n",
2127 __func__, result);
2240 edge_port->ep_write_urb_in_use = 0; 2128 edge_port->ep_write_urb_in_use = 0;
2241 // TODO: reschedule edge_send 2129 /* TODO: reschedule edge_send */
2242 } else { 2130 } else
2243 edge_port->icount.tx += count; 2131 edge_port->icount.tx += count;
2244 }
2245 2132
2246 /* wakeup any process waiting for writes to complete */ 2133 /* wakeup any process waiting for writes to complete */
2247 /* there is now more room in the buffer for new writes */ 2134 /* there is now more room in the buffer for new writes */
2248 if (tty) { 2135 if (tty)
2249 /* let the tty driver wakeup if it has a special write_wakeup function */
2250 tty_wakeup(tty); 2136 tty_wakeup(tty);
2251 }
2252} 2137}
2253 2138
2254static int edge_write_room (struct usb_serial_port *port) 2139static int edge_write_room(struct tty_struct *tty)
2255{ 2140{
2141 struct usb_serial_port *port = tty->driver_data;
2256 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2142 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2257 int room = 0; 2143 int room = 0;
2258 unsigned long flags; 2144 unsigned long flags;
@@ -2260,9 +2146,9 @@ static int edge_write_room (struct usb_serial_port *port)
2260 dbg("%s - port %d", __func__, port->number); 2146 dbg("%s - port %d", __func__, port->number);
2261 2147
2262 if (edge_port == NULL) 2148 if (edge_port == NULL)
2263 return -ENODEV; 2149 return 0;
2264 if (edge_port->close_pending == 1) 2150 if (edge_port->close_pending == 1)
2265 return -ENODEV; 2151 return 0;
2266 2152
2267 spin_lock_irqsave(&edge_port->ep_lock, flags); 2153 spin_lock_irqsave(&edge_port->ep_lock, flags);
2268 room = edge_buf_space_avail(edge_port->ep_out_buf); 2154 room = edge_buf_space_avail(edge_port->ep_out_buf);
@@ -2272,8 +2158,9 @@ static int edge_write_room (struct usb_serial_port *port)
2272 return room; 2158 return room;
2273} 2159}
2274 2160
2275static int edge_chars_in_buffer (struct usb_serial_port *port) 2161static int edge_chars_in_buffer(struct tty_struct *tty)
2276{ 2162{
2163 struct usb_serial_port *port = tty->driver_data;
2277 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2164 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2278 int chars = 0; 2165 int chars = 0;
2279 unsigned long flags; 2166 unsigned long flags;
@@ -2281,22 +2168,22 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
2281 dbg("%s - port %d", __func__, port->number); 2168 dbg("%s - port %d", __func__, port->number);
2282 2169
2283 if (edge_port == NULL) 2170 if (edge_port == NULL)
2284 return -ENODEV; 2171 return 0;
2285 if (edge_port->close_pending == 1) 2172 if (edge_port->close_pending == 1)
2286 return -ENODEV; 2173 return 0;
2287 2174
2288 spin_lock_irqsave(&edge_port->ep_lock, flags); 2175 spin_lock_irqsave(&edge_port->ep_lock, flags);
2289 chars = edge_buf_data_avail(edge_port->ep_out_buf); 2176 chars = edge_buf_data_avail(edge_port->ep_out_buf);
2290 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2177 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2291 2178
2292 dbg ("%s - returns %d", __func__, chars); 2179 dbg("%s - returns %d", __func__, chars);
2293 return chars; 2180 return chars;
2294} 2181}
2295 2182
2296static void edge_throttle (struct usb_serial_port *port) 2183static void edge_throttle(struct tty_struct *tty)
2297{ 2184{
2185 struct usb_serial_port *port = tty->driver_data;
2298 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2186 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2299 struct tty_struct *tty;
2300 int status; 2187 int status;
2301 2188
2302 dbg("%s - port %d", __func__, port->number); 2189 dbg("%s - port %d", __func__, port->number);
@@ -2304,16 +2191,10 @@ static void edge_throttle (struct usb_serial_port *port)
2304 if (edge_port == NULL) 2191 if (edge_port == NULL)
2305 return; 2192 return;
2306 2193
2307 tty = port->tty;
2308 if (!tty) {
2309 dbg ("%s - no tty available", __func__);
2310 return;
2311 }
2312
2313 /* if we are implementing XON/XOFF, send the stop character */ 2194 /* if we are implementing XON/XOFF, send the stop character */
2314 if (I_IXOFF(tty)) { 2195 if (I_IXOFF(tty)) {
2315 unsigned char stop_char = STOP_CHAR(tty); 2196 unsigned char stop_char = STOP_CHAR(tty);
2316 status = edge_write (port, &stop_char, 1); 2197 status = edge_write(tty, port, &stop_char, 1);
2317 if (status <= 0) { 2198 if (status <= 0) {
2318 dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status); 2199 dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status);
2319 } 2200 }
@@ -2326,10 +2207,10 @@ static void edge_throttle (struct usb_serial_port *port)
2326 2207
2327} 2208}
2328 2209
2329static void edge_unthrottle (struct usb_serial_port *port) 2210static void edge_unthrottle(struct tty_struct *tty)
2330{ 2211{
2212 struct usb_serial_port *port = tty->driver_data;
2331 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2213 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2332 struct tty_struct *tty;
2333 int status; 2214 int status;
2334 2215
2335 dbg("%s - port %d", __func__, port->number); 2216 dbg("%s - port %d", __func__, port->number);
@@ -2337,27 +2218,22 @@ static void edge_unthrottle (struct usb_serial_port *port)
2337 if (edge_port == NULL) 2218 if (edge_port == NULL)
2338 return; 2219 return;
2339 2220
2340 tty = port->tty;
2341 if (!tty) {
2342 dbg ("%s - no tty available", __func__);
2343 return;
2344 }
2345
2346 /* if we are implementing XON/XOFF, send the start character */ 2221 /* if we are implementing XON/XOFF, send the start character */
2347 if (I_IXOFF(tty)) { 2222 if (I_IXOFF(tty)) {
2348 unsigned char start_char = START_CHAR(tty); 2223 unsigned char start_char = START_CHAR(tty);
2349 status = edge_write (port, &start_char, 1); 2224 status = edge_write(tty, port, &start_char, 1);
2350 if (status <= 0) { 2225 if (status <= 0) {
2351 dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status); 2226 dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status);
2352 } 2227 }
2353 } 2228 }
2354
2355 /* if we are implementing RTS/CTS, restart reads */ 2229 /* if we are implementing RTS/CTS, restart reads */
2356 /* are the Edgeport will assert the RTS line */ 2230 /* are the Edgeport will assert the RTS line */
2357 if (C_CRTSCTS(tty)) { 2231 if (C_CRTSCTS(tty)) {
2358 status = restart_read(edge_port); 2232 status = restart_read(edge_port);
2359 if (status) 2233 if (status)
2360 dev_err(&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __func__, status); 2234 dev_err(&port->dev,
2235 "%s - read bulk usb_submit_urb failed: %d\n",
2236 __func__, status);
2361 } 2237 }
2362 2238
2363} 2239}
@@ -2398,22 +2274,23 @@ static int restart_read(struct edgeport_port *edge_port)
2398 return status; 2274 return status;
2399} 2275}
2400 2276
2401static void change_port_settings (struct edgeport_port *edge_port, struct ktermios *old_termios) 2277static void change_port_settings(struct tty_struct *tty,
2278 struct edgeport_port *edge_port, struct ktermios *old_termios)
2402{ 2279{
2403 struct ump_uart_config *config; 2280 struct ump_uart_config *config;
2404 struct tty_struct *tty;
2405 int baud; 2281 int baud;
2406 unsigned cflag; 2282 unsigned cflag;
2407 int status; 2283 int status;
2408 int port_number = edge_port->port->number - edge_port->port->serial->minor; 2284 int port_number = edge_port->port->number -
2285 edge_port->port->serial->minor;
2409 2286
2410 dbg("%s - port %d", __func__, edge_port->port->number); 2287 dbg("%s - port %d", __func__, edge_port->port->number);
2411 2288
2412 tty = edge_port->port->tty;
2413
2414 config = kmalloc (sizeof (*config), GFP_KERNEL); 2289 config = kmalloc (sizeof (*config), GFP_KERNEL);
2415 if (!config) { 2290 if (!config) {
2416 dev_err (&edge_port->port->dev, "%s - out of memory\n", __func__); 2291 *tty->termios = *old_termios;
2292 dev_err(&edge_port->port->dev, "%s - out of memory\n",
2293 __func__);
2417 return; 2294 return;
2418 } 2295 }
2419 2296
@@ -2427,22 +2304,22 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2427 config->bUartMode = (__u8)(edge_port->bUartMode); 2304 config->bUartMode = (__u8)(edge_port->bUartMode);
2428 2305
2429 switch (cflag & CSIZE) { 2306 switch (cflag & CSIZE) {
2430 case CS5: 2307 case CS5:
2431 config->bDataBits = UMP_UART_CHAR5BITS; 2308 config->bDataBits = UMP_UART_CHAR5BITS;
2432 dbg ("%s - data bits = 5", __func__); 2309 dbg("%s - data bits = 5", __func__);
2433 break; 2310 break;
2434 case CS6: 2311 case CS6:
2435 config->bDataBits = UMP_UART_CHAR6BITS; 2312 config->bDataBits = UMP_UART_CHAR6BITS;
2436 dbg ("%s - data bits = 6", __func__); 2313 dbg("%s - data bits = 6", __func__);
2437 break; 2314 break;
2438 case CS7: 2315 case CS7:
2439 config->bDataBits = UMP_UART_CHAR7BITS; 2316 config->bDataBits = UMP_UART_CHAR7BITS;
2440 dbg ("%s - data bits = 7", __func__); 2317 dbg("%s - data bits = 7", __func__);
2441 break; 2318 break;
2442 default: 2319 default:
2443 case CS8: 2320 case CS8:
2444 config->bDataBits = UMP_UART_CHAR8BITS; 2321 config->bDataBits = UMP_UART_CHAR8BITS;
2445 dbg ("%s - data bits = 8", __func__); 2322 dbg("%s - data bits = 8", __func__);
2446 break; 2323 break;
2447 } 2324 }
2448 2325
@@ -2457,7 +2334,7 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2457 dbg("%s - parity = even", __func__); 2334 dbg("%s - parity = even", __func__);
2458 } 2335 }
2459 } else { 2336 } else {
2460 config->bParity = UMP_UART_NOPARITY; 2337 config->bParity = UMP_UART_NOPARITY;
2461 dbg("%s - parity = none", __func__); 2338 dbg("%s - parity = none", __func__);
2462 } 2339 }
2463 2340
@@ -2480,29 +2357,26 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2480 restart_read(edge_port); 2357 restart_read(edge_port);
2481 } 2358 }
2482 2359
2483 /* if we are implementing XON/XOFF, set the start and stop character in the device */ 2360 /* if we are implementing XON/XOFF, set the start and stop
2484 if (I_IXOFF(tty) || I_IXON(tty)) { 2361 character in the device */
2485 config->cXon = START_CHAR(tty); 2362 config->cXon = START_CHAR(tty);
2486 config->cXoff = STOP_CHAR(tty); 2363 config->cXoff = STOP_CHAR(tty);
2487 2364
2488 /* if we are implementing INBOUND XON/XOFF */ 2365 /* if we are implementing INBOUND XON/XOFF */
2489 if (I_IXOFF(tty)) { 2366 if (I_IXOFF(tty)) {
2490 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X; 2367 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
2491 dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", 2368 dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2492 __func__, config->cXon, config->cXoff); 2369 __func__, config->cXon, config->cXoff);
2493 } else { 2370 } else
2494 dbg ("%s - INBOUND XON/XOFF is disabled", __func__); 2371 dbg("%s - INBOUND XON/XOFF is disabled", __func__);
2495 }
2496 2372
2497 /* if we are implementing OUTBOUND XON/XOFF */ 2373 /* if we are implementing OUTBOUND XON/XOFF */
2498 if (I_IXON(tty)) { 2374 if (I_IXON(tty)) {
2499 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X; 2375 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
2500 dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", 2376 dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2501 __func__, config->cXon, config->cXoff); 2377 __func__, config->cXon, config->cXoff);
2502 } else { 2378 } else
2503 dbg ("%s - OUTBOUND XON/XOFF is disabled", __func__); 2379 dbg("%s - OUTBOUND XON/XOFF is disabled", __func__);
2504 }
2505 }
2506 2380
2507 tty->termios->c_cflag &= ~CMSPAR; 2381 tty->termios->c_cflag &= ~CMSPAR;
2508 2382
@@ -2519,41 +2393,36 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2519 2393
2520 /* FIXME: Recompute actual baud from divisor here */ 2394 /* FIXME: Recompute actual baud from divisor here */
2521 2395
2522 dbg ("%s - baud rate = %d, wBaudRate = %d", __func__, baud, config->wBaudRate); 2396 dbg("%s - baud rate = %d, wBaudRate = %d", __func__, baud,
2397 config->wBaudRate);
2523 2398
2524 dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate)); 2399 dbg("wBaudRate: %d", (int)(461550L / config->wBaudRate));
2525 dbg ("wFlags: 0x%x", config->wFlags); 2400 dbg("wFlags: 0x%x", config->wFlags);
2526 dbg ("bDataBits: %d", config->bDataBits); 2401 dbg("bDataBits: %d", config->bDataBits);
2527 dbg ("bParity: %d", config->bParity); 2402 dbg("bParity: %d", config->bParity);
2528 dbg ("bStopBits: %d", config->bStopBits); 2403 dbg("bStopBits: %d", config->bStopBits);
2529 dbg ("cXon: %d", config->cXon); 2404 dbg("cXon: %d", config->cXon);
2530 dbg ("cXoff: %d", config->cXoff); 2405 dbg("cXoff: %d", config->cXoff);
2531 dbg ("bUartMode: %d", config->bUartMode); 2406 dbg("bUartMode: %d", config->bUartMode);
2532 2407
2533 /* move the word values into big endian mode */ 2408 /* move the word values into big endian mode */
2534 cpu_to_be16s (&config->wFlags); 2409 cpu_to_be16s(&config->wFlags);
2535 cpu_to_be16s (&config->wBaudRate); 2410 cpu_to_be16s(&config->wBaudRate);
2536 2411
2537 status = TIWriteCommandSync (edge_port->port->serial->dev, 2412 status = send_cmd(edge_port->port->serial->dev, UMPC_SET_CONFIG,
2538 UMPC_SET_CONFIG,
2539 (__u8)(UMPM_UART1_PORT + port_number), 2413 (__u8)(UMPM_UART1_PORT + port_number),
2540 0, 2414 0, (__u8 *)config, sizeof(*config));
2541 (__u8 *)config, 2415 if (status)
2542 sizeof(*config)); 2416 dbg("%s - error %d when trying to write config to device",
2543 if (status) {
2544 dbg ("%s - error %d when trying to write config to device",
2545 __func__, status); 2417 __func__, status);
2546 } 2418 kfree(config);
2547
2548 kfree (config);
2549
2550 return; 2419 return;
2551} 2420}
2552 2421
2553static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 2422static void edge_set_termios(struct tty_struct *tty,
2423 struct usb_serial_port *port, struct ktermios *old_termios)
2554{ 2424{
2555 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2425 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2556 struct tty_struct *tty = port->tty;
2557 unsigned int cflag; 2426 unsigned int cflag;
2558 2427
2559 cflag = tty->termios->c_cflag; 2428 cflag = tty->termios->c_cflag;
@@ -2562,20 +2431,19 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old
2562 tty->termios->c_cflag, tty->termios->c_iflag); 2431 tty->termios->c_cflag, tty->termios->c_iflag);
2563 dbg("%s - old clfag %08x old iflag %08x", __func__, 2432 dbg("%s - old clfag %08x old iflag %08x", __func__,
2564 old_termios->c_cflag, old_termios->c_iflag); 2433 old_termios->c_cflag, old_termios->c_iflag);
2565
2566 dbg("%s - port %d", __func__, port->number); 2434 dbg("%s - port %d", __func__, port->number);
2567 2435
2568 if (edge_port == NULL) 2436 if (edge_port == NULL)
2569 return; 2437 return;
2570
2571 /* change the port settings to the new ones specified */ 2438 /* change the port settings to the new ones specified */
2572 change_port_settings (edge_port, old_termios); 2439 change_port_settings(tty, edge_port, old_termios);
2573
2574 return; 2440 return;
2575} 2441}
2576 2442
2577static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear) 2443static int edge_tiocmset(struct tty_struct *tty, struct file *file,
2444 unsigned int set, unsigned int clear)
2578{ 2445{
2446 struct usb_serial_port *port = tty->driver_data;
2579 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2447 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2580 unsigned int mcr; 2448 unsigned int mcr;
2581 unsigned long flags; 2449 unsigned long flags;
@@ -2601,13 +2469,13 @@ static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsig
2601 edge_port->shadow_mcr = mcr; 2469 edge_port->shadow_mcr = mcr;
2602 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2470 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2603 2471
2604 TIRestoreMCR (edge_port, mcr); 2472 restore_mcr(edge_port, mcr);
2605
2606 return 0; 2473 return 0;
2607} 2474}
2608 2475
2609static int edge_tiocmget(struct usb_serial_port *port, struct file *file) 2476static int edge_tiocmget(struct tty_struct *tty, struct file *file)
2610{ 2477{
2478 struct usb_serial_port *port = tty->driver_data;
2611 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2479 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2612 unsigned int result = 0; 2480 unsigned int result = 0;
2613 unsigned int msr; 2481 unsigned int msr;
@@ -2634,7 +2502,8 @@ static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
2634 return result; 2502 return result;
2635} 2503}
2636 2504
2637static int get_serial_info (struct edgeport_port *edge_port, struct serial_struct __user *retinfo) 2505static int get_serial_info(struct edgeport_port *edge_port,
2506 struct serial_struct __user *retinfo)
2638{ 2507{
2639 struct serial_struct tmp; 2508 struct serial_struct tmp;
2640 2509
@@ -2652,18 +2521,16 @@ static int get_serial_info (struct edgeport_port *edge_port, struct serial_struc
2652 tmp.baud_base = 9600; 2521 tmp.baud_base = 9600;
2653 tmp.close_delay = 5*HZ; 2522 tmp.close_delay = 5*HZ;
2654 tmp.closing_wait = closing_wait; 2523 tmp.closing_wait = closing_wait;
2655// tmp.custom_divisor = state->custom_divisor;
2656// tmp.hub6 = state->hub6;
2657// tmp.io_type = state->io_type;
2658
2659 2524
2660 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 2525 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2661 return -EFAULT; 2526 return -EFAULT;
2662 return 0; 2527 return 0;
2663} 2528}
2664 2529
2665static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg) 2530static int edge_ioctl(struct tty_struct *tty, struct file *file,
2531 unsigned int cmd, unsigned long arg)
2666{ 2532{
2533 struct usb_serial_port *port = tty->driver_data;
2667 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2534 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2668 struct async_icount cnow; 2535 struct async_icount cnow;
2669 struct async_icount cprev; 2536 struct async_icount cprev;
@@ -2671,81 +2538,64 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
2671 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 2538 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
2672 2539
2673 switch (cmd) { 2540 switch (cmd) {
2674 case TIOCINQ: 2541 case TIOCGSERIAL:
2675 dbg("%s - (%d) TIOCINQ", __func__, port->number); 2542 dbg("%s - (%d) TIOCGSERIAL", __func__, port->number);
2676// return get_number_bytes_avail(edge_port, (unsigned int *) arg); 2543 return get_serial_info(edge_port,
2677 break; 2544 (struct serial_struct __user *) arg);
2678 2545 case TIOCMIWAIT:
2679 case TIOCSERGETLSR: 2546 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number);
2680 dbg("%s - (%d) TIOCSERGETLSR", __func__, port->number); 2547 cprev = edge_port->icount;
2681// return get_lsr_info(edge_port, (unsigned int *) arg); 2548 while (1) {
2682 break; 2549 interruptible_sleep_on(&edge_port->delta_msr_wait);
2683 2550 /* see if a signal did it */
2684 case TIOCGSERIAL: 2551 if (signal_pending(current))
2685 dbg("%s - (%d) TIOCGSERIAL", __func__, port->number); 2552 return -ERESTARTSYS;
2686 return get_serial_info(edge_port, (struct serial_struct __user *) arg); 2553 cnow = edge_port->icount;
2687 break; 2554 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2688 2555 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2689 case TIOCSSERIAL: 2556 return -EIO; /* no change => error */
2690 dbg("%s - (%d) TIOCSSERIAL", __func__, port->number); 2557 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2691 break; 2558 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2692 2559 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2693 case TIOCMIWAIT: 2560 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2694 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number); 2561 return 0;
2695 cprev = edge_port->icount;
2696 while (1) {
2697 interruptible_sleep_on(&edge_port->delta_msr_wait);
2698 /* see if a signal did it */
2699 if (signal_pending(current))
2700 return -ERESTARTSYS;
2701 cnow = edge_port->icount;
2702 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2703 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2704 return -EIO; /* no change => error */
2705 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2706 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2707 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2708 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2709 return 0;
2710 }
2711 cprev = cnow;
2712 } 2562 }
2713 /* not reached */ 2563 cprev = cnow;
2714 break; 2564 }
2715 2565 /* not reached */
2716 case TIOCGICOUNT: 2566 break;
2717 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, 2567 case TIOCGICOUNT:
2718 port->number, edge_port->icount.rx, edge_port->icount.tx); 2568 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2719 if (copy_to_user((void __user *)arg, &edge_port->icount, sizeof(edge_port->icount))) 2569 port->number, edge_port->icount.rx, edge_port->icount.tx);
2720 return -EFAULT; 2570 if (copy_to_user((void __user *)arg, &edge_port->icount,
2721 return 0; 2571 sizeof(edge_port->icount)))
2572 return -EFAULT;
2573 return 0;
2722 } 2574 }
2723
2724 return -ENOIOCTLCMD; 2575 return -ENOIOCTLCMD;
2725} 2576}
2726 2577
2727static void edge_break (struct usb_serial_port *port, int break_state) 2578static void edge_break(struct tty_struct *tty, int break_state)
2728{ 2579{
2580 struct usb_serial_port *port = tty->driver_data;
2729 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2581 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2730 int status; 2582 int status;
2583 int bv = 0; /* Off */
2731 2584
2732 dbg ("%s - state = %d", __func__, break_state); 2585 dbg("%s - state = %d", __func__, break_state);
2733 2586
2734 /* chase the port close */ 2587 /* chase the port close */
2735 TIChasePort (edge_port, 0, 0); 2588 chase_port(edge_port, 0, 0);
2736 2589
2737 if (break_state == -1) { 2590 if (break_state == -1)
2738 status = TISetBreak (edge_port); 2591 bv = 1; /* On */
2739 } else { 2592 status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv);
2740 status = TIClearBreak (edge_port); 2593 if (status)
2741 } 2594 dbg("%s - error %d sending break set/clear command.",
2742 if (status) {
2743 dbg ("%s - error %d sending break set/clear command.",
2744 __func__, status); 2595 __func__, status);
2745 }
2746} 2596}
2747 2597
2748static int edge_startup (struct usb_serial *serial) 2598static int edge_startup(struct usb_serial *serial)
2749{ 2599{
2750 struct edgeport_serial *edge_serial; 2600 struct edgeport_serial *edge_serial;
2751 struct edgeport_port *edge_port; 2601 struct edgeport_port *edge_port;
@@ -2765,9 +2615,9 @@ static int edge_startup (struct usb_serial *serial)
2765 edge_serial->serial = serial; 2615 edge_serial->serial = serial;
2766 usb_set_serial_data(serial, edge_serial); 2616 usb_set_serial_data(serial, edge_serial);
2767 2617
2768 status = TIDownloadFirmware (edge_serial); 2618 status = download_fw(edge_serial);
2769 if (status) { 2619 if (status) {
2770 kfree (edge_serial); 2620 kfree(edge_serial);
2771 return status; 2621 return status;
2772 } 2622 }
2773 2623
@@ -2775,13 +2625,15 @@ static int edge_startup (struct usb_serial *serial)
2775 for (i = 0; i < serial->num_ports; ++i) { 2625 for (i = 0; i < serial->num_ports; ++i) {
2776 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL); 2626 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
2777 if (edge_port == NULL) { 2627 if (edge_port == NULL) {
2778 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); 2628 dev_err(&serial->dev->dev, "%s - Out of memory\n",
2629 __func__);
2779 goto cleanup; 2630 goto cleanup;
2780 } 2631 }
2781 spin_lock_init(&edge_port->ep_lock); 2632 spin_lock_init(&edge_port->ep_lock);
2782 edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE); 2633 edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE);
2783 if (edge_port->ep_out_buf == NULL) { 2634 if (edge_port->ep_out_buf == NULL) {
2784 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); 2635 dev_err(&serial->dev->dev, "%s - Out of memory\n",
2636 __func__);
2785 kfree(edge_port); 2637 kfree(edge_port);
2786 goto cleanup; 2638 goto cleanup;
2787 } 2639 }
@@ -2790,27 +2642,27 @@ static int edge_startup (struct usb_serial *serial)
2790 usb_set_serial_port_data(serial->port[i], edge_port); 2642 usb_set_serial_port_data(serial->port[i], edge_port);
2791 edge_port->bUartMode = default_uart_mode; 2643 edge_port->bUartMode = default_uart_mode;
2792 } 2644 }
2793 2645
2794 return 0; 2646 return 0;
2795 2647
2796cleanup: 2648cleanup:
2797 for (--i; i>=0; --i) { 2649 for (--i; i >= 0; --i) {
2798 edge_port = usb_get_serial_port_data(serial->port[i]); 2650 edge_port = usb_get_serial_port_data(serial->port[i]);
2799 edge_buf_free(edge_port->ep_out_buf); 2651 edge_buf_free(edge_port->ep_out_buf);
2800 kfree(edge_port); 2652 kfree(edge_port);
2801 usb_set_serial_port_data(serial->port[i], NULL); 2653 usb_set_serial_port_data(serial->port[i], NULL);
2802 } 2654 }
2803 kfree (edge_serial); 2655 kfree(edge_serial);
2804 usb_set_serial_data(serial, NULL); 2656 usb_set_serial_data(serial, NULL);
2805 return -ENOMEM; 2657 return -ENOMEM;
2806} 2658}
2807 2659
2808static void edge_shutdown (struct usb_serial *serial) 2660static void edge_shutdown(struct usb_serial *serial)
2809{ 2661{
2810 int i; 2662 int i;
2811 struct edgeport_port *edge_port; 2663 struct edgeport_port *edge_port;
2812 2664
2813 dbg ("%s", __func__); 2665 dbg("%s", __func__);
2814 2666
2815 for (i = 0; i < serial->num_ports; ++i) { 2667 for (i = 0; i < serial->num_ports; ++i) {
2816 edge_port = usb_get_serial_port_data(serial->port[i]); 2668 edge_port = usb_get_serial_port_data(serial->port[i]);
@@ -2852,7 +2704,8 @@ static ssize_t store_uart_mode(struct device *dev,
2852 return count; 2704 return count;
2853} 2705}
2854 2706
2855static DEVICE_ATTR(uart_mode, S_IWUSR | S_IRUGO, show_uart_mode, store_uart_mode); 2707static DEVICE_ATTR(uart_mode, S_IWUSR | S_IRUGO, show_uart_mode,
2708 store_uart_mode);
2856 2709
2857static int edge_create_sysfs_attrs(struct usb_serial_port *port) 2710static int edge_create_sysfs_attrs(struct usb_serial_port *port)
2858{ 2711{
@@ -2922,9 +2775,9 @@ static void edge_buf_free(struct edge_buf *eb)
2922 2775
2923static void edge_buf_clear(struct edge_buf *eb) 2776static void edge_buf_clear(struct edge_buf *eb)
2924{ 2777{
2925 if (eb != NULL) 2778 if (eb != NULL)
2926 eb->buf_get = eb->buf_put; 2779 eb->buf_get = eb->buf_put;
2927 /* equivalent to a get of all data available */ 2780 /* equivalent to a get of all data available */
2928} 2781}
2929 2782
2930 2783
@@ -2937,10 +2790,9 @@ static void edge_buf_clear(struct edge_buf *eb)
2937 2790
2938static unsigned int edge_buf_data_avail(struct edge_buf *eb) 2791static unsigned int edge_buf_data_avail(struct edge_buf *eb)
2939{ 2792{
2940 if (eb != NULL) 2793 if (eb == NULL)
2941 return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size);
2942 else
2943 return 0; 2794 return 0;
2795 return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size);
2944} 2796}
2945 2797
2946 2798
@@ -2953,10 +2805,9 @@ static unsigned int edge_buf_data_avail(struct edge_buf *eb)
2953 2805
2954static unsigned int edge_buf_space_avail(struct edge_buf *eb) 2806static unsigned int edge_buf_space_avail(struct edge_buf *eb)
2955{ 2807{
2956 if (eb != NULL) 2808 if (eb == NULL)
2957 return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size);
2958 else
2959 return 0; 2809 return 0;
2810 return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size);
2960} 2811}
2961 2812
2962 2813
@@ -3113,7 +2964,7 @@ static int __init edgeport_init(void)
3113 if (retval) 2964 if (retval)
3114 goto failed_2port_device_register; 2965 goto failed_2port_device_register;
3115 retval = usb_register(&io_driver); 2966 retval = usb_register(&io_driver);
3116 if (retval) 2967 if (retval)
3117 goto failed_usb_register; 2968 goto failed_usb_register;
3118 info(DRIVER_DESC " " DRIVER_VERSION); 2969 info(DRIVER_DESC " " DRIVER_VERSION);
3119 return 0; 2970 return 0;
@@ -3125,11 +2976,11 @@ failed_1port_device_register:
3125 return retval; 2976 return retval;
3126} 2977}
3127 2978
3128static void __exit edgeport_exit (void) 2979static void __exit edgeport_exit(void)
3129{ 2980{
3130 usb_deregister (&io_driver); 2981 usb_deregister(&io_driver);
3131 usb_serial_deregister (&edgeport_1port_device); 2982 usb_serial_deregister(&edgeport_1port_device);
3132 usb_serial_deregister (&edgeport_2port_device); 2983 usb_serial_deregister(&edgeport_2port_device);
3133} 2984}
3134 2985
3135module_init(edgeport_init); 2986module_init(edgeport_init);
@@ -3151,8 +3002,8 @@ module_param(closing_wait, int, S_IRUGO | S_IWUSR);
3151MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs"); 3002MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs");
3152 3003
3153module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR); 3004module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR);
3154MODULE_PARM_DESC(ignore_cpu_rev, "Ignore the cpu revision when connecting to a device"); 3005MODULE_PARM_DESC(ignore_cpu_rev,
3006 "Ignore the cpu revision when connecting to a device");
3155 3007
3156module_param(default_uart_mode, int, S_IRUGO | S_IWUSR); 3008module_param(default_uart_mode, int, S_IRUGO | S_IWUSR);
3157MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ..."); 3009MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ...");
3158
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index d9fb3768a2d7..832a5a4f3cb3 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -53,7 +53,7 @@
53#include <linux/tty_flip.h> 53#include <linux/tty_flip.h>
54#include <linux/module.h> 54#include <linux/module.h>
55#include <linux/spinlock.h> 55#include <linux/spinlock.h>
56#include <asm/uaccess.h> 56#include <linux/uaccess.h>
57#include <linux/usb.h> 57#include <linux/usb.h>
58#include <linux/usb/serial.h> 58#include <linux/usb/serial.h>
59#include "ipaq.h" 59#include "ipaq.h"
@@ -74,19 +74,21 @@ static int connect_retries = KP_RETRIES;
74static int initial_wait; 74static int initial_wait;
75 75
76/* Function prototypes for an ipaq */ 76/* Function prototypes for an ipaq */
77static int ipaq_open (struct usb_serial_port *port, struct file *filp); 77static int ipaq_open(struct tty_struct *tty,
78static void ipaq_close (struct usb_serial_port *port, struct file *filp); 78 struct usb_serial_port *port, struct file *filp);
79static int ipaq_startup (struct usb_serial *serial); 79static void ipaq_close(struct tty_struct *tty,
80static void ipaq_shutdown (struct usb_serial *serial); 80 struct usb_serial_port *port, struct file *filp);
81static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf, 81static int ipaq_startup(struct usb_serial *serial);
82 int count); 82static void ipaq_shutdown(struct usb_serial *serial);
83static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *buf, 83static int ipaq_write(struct tty_struct *tty, struct usb_serial_port *port,
84 int count); 84 const unsigned char *buf, int count);
85static int ipaq_write_bulk(struct usb_serial_port *port,
86 const unsigned char *buf, int count);
85static void ipaq_write_gather(struct usb_serial_port *port); 87static void ipaq_write_gather(struct usb_serial_port *port);
86static void ipaq_read_bulk_callback (struct urb *urb); 88static void ipaq_read_bulk_callback(struct urb *urb);
87static void ipaq_write_bulk_callback(struct urb *urb); 89static void ipaq_write_bulk_callback(struct urb *urb);
88static int ipaq_write_room(struct usb_serial_port *port); 90static int ipaq_write_room(struct tty_struct *tty);
89static int ipaq_chars_in_buffer(struct usb_serial_port *port); 91static int ipaq_chars_in_buffer(struct tty_struct *tty);
90static void ipaq_destroy_lists(struct usb_serial_port *port); 92static void ipaq_destroy_lists(struct usb_serial_port *port);
91 93
92 94
@@ -550,7 +552,7 @@ static struct usb_device_id ipaq_id_table [] = {
550 { } /* Terminating entry */ 552 { } /* Terminating entry */
551}; 553};
552 554
553MODULE_DEVICE_TABLE (usb, ipaq_id_table); 555MODULE_DEVICE_TABLE(usb, ipaq_id_table);
554 556
555static struct usb_driver ipaq_driver = { 557static struct usb_driver ipaq_driver = {
556 .name = "ipaq", 558 .name = "ipaq",
@@ -591,7 +593,8 @@ static spinlock_t write_list_lock;
591static int bytes_in; 593static int bytes_in;
592static int bytes_out; 594static int bytes_out;
593 595
594static int ipaq_open(struct usb_serial_port *port, struct file *filp) 596static int ipaq_open(struct tty_struct *tty,
597 struct usb_serial_port *port, struct file *filp)
595{ 598{
596 struct usb_serial *serial = port->serial; 599 struct usb_serial *serial = port->serial;
597 struct ipaq_private *priv; 600 struct ipaq_private *priv;
@@ -617,9 +620,9 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
617 620
618 for (i = 0; i < URBDATA_QUEUE_MAX / PACKET_SIZE; i++) { 621 for (i = 0; i < URBDATA_QUEUE_MAX / PACKET_SIZE; i++) {
619 pkt = kmalloc(sizeof(struct ipaq_packet), GFP_KERNEL); 622 pkt = kmalloc(sizeof(struct ipaq_packet), GFP_KERNEL);
620 if (pkt == NULL) { 623 if (pkt == NULL)
621 goto enomem; 624 goto enomem;
622 } 625
623 pkt->data = kmalloc(PACKET_SIZE, GFP_KERNEL); 626 pkt->data = kmalloc(PACKET_SIZE, GFP_KERNEL);
624 if (pkt->data == NULL) { 627 if (pkt->data == NULL) {
625 kfree(pkt); 628 kfree(pkt);
@@ -637,21 +640,24 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
637 * discipline instead of queueing. 640 * discipline instead of queueing.
638 */ 641 */
639 642
640 port->tty->low_latency = 1; 643 if (tty) {
641 port->tty->raw = 1; 644 tty->low_latency = 1;
642 port->tty->real_raw = 1; 645 /* FIXME: These two are bogus */
643 646 tty->raw = 1;
647 tty->real_raw = 1;
648 }
644 /* 649 /*
645 * Lose the small buffers usbserial provides. Make larger ones. 650 * Lose the small buffers usbserial provides. Make larger ones.
646 */ 651 */
647 652
648 kfree(port->bulk_in_buffer); 653 kfree(port->bulk_in_buffer);
649 kfree(port->bulk_out_buffer);
650 port->bulk_in_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL); 654 port->bulk_in_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL);
651 if (port->bulk_in_buffer == NULL) { 655 if (port->bulk_in_buffer == NULL) {
652 port->bulk_out_buffer = NULL; /* prevent double free */ 656 port->bulk_out_buffer = NULL; /* prevent double free */
653 goto enomem; 657 goto enomem;
654 } 658 }
659
660 kfree(port->bulk_out_buffer);
655 port->bulk_out_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL); 661 port->bulk_out_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL);
656 if (port->bulk_out_buffer == NULL) { 662 if (port->bulk_out_buffer == NULL) {
657 kfree(port->bulk_in_buffer); 663 kfree(port->bulk_in_buffer);
@@ -661,8 +667,9 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
661 port->read_urb->transfer_buffer = port->bulk_in_buffer; 667 port->read_urb->transfer_buffer = port->bulk_in_buffer;
662 port->write_urb->transfer_buffer = port->bulk_out_buffer; 668 port->write_urb->transfer_buffer = port->bulk_out_buffer;
663 port->read_urb->transfer_buffer_length = URBDATA_SIZE; 669 port->read_urb->transfer_buffer_length = URBDATA_SIZE;
664 port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE; 670 port->bulk_out_size = port->write_urb->transfer_buffer_length
665 671 = URBDATA_SIZE;
672
666 msleep(1000*initial_wait); 673 msleep(1000*initial_wait);
667 674
668 /* 675 /*
@@ -691,13 +698,15 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
691 698
692 /* Start reading from the device */ 699 /* Start reading from the device */
693 usb_fill_bulk_urb(port->read_urb, serial->dev, 700 usb_fill_bulk_urb(port->read_urb, serial->dev,
694 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), 701 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
695 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 702 port->read_urb->transfer_buffer,
696 ipaq_read_bulk_callback, port); 703 port->read_urb->transfer_buffer_length,
704 ipaq_read_bulk_callback, port);
697 705
698 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 706 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
699 if (result) { 707 if (result) {
700 err("%s - failed submitting read urb, error %d", __func__, result); 708 err("%s - failed submitting read urb, error %d",
709 __func__, result);
701 goto error; 710 goto error;
702 } 711 }
703 712
@@ -713,12 +722,13 @@ error:
713} 722}
714 723
715 724
716static void ipaq_close(struct usb_serial_port *port, struct file *filp) 725static void ipaq_close(struct tty_struct *tty,
726 struct usb_serial_port *port, struct file *filp)
717{ 727{
718 struct ipaq_private *priv = usb_get_serial_port_data(port); 728 struct ipaq_private *priv = usb_get_serial_port_data(port);
719 729
720 dbg("%s - port %d", __func__, port->number); 730 dbg("%s - port %d", __func__, port->number);
721 731
722 /* 732 /*
723 * shut down bulk read and write 733 * shut down bulk read and write
724 */ 734 */
@@ -728,7 +738,8 @@ static void ipaq_close(struct usb_serial_port *port, struct file *filp)
728 kfree(priv); 738 kfree(priv);
729 usb_set_serial_port_data(port, NULL); 739 usb_set_serial_port_data(port, NULL);
730 740
731 /* Uncomment the following line if you want to see some statistics in your syslog */ 741 /* Uncomment the following line if you want to see some statistics
742 * in your syslog */
732 /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */ 743 /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */
733} 744}
734 745
@@ -748,9 +759,10 @@ static void ipaq_read_bulk_callback(struct urb *urb)
748 return; 759 return;
749 } 760 }
750 761
751 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 762 usb_serial_debug_data(debug, &port->dev, __func__,
763 urb->actual_length, data);
752 764
753 tty = port->tty; 765 tty = port->port.tty;
754 if (tty && urb->actual_length) { 766 if (tty && urb->actual_length) {
755 tty_buffer_request_room(tty, urb->actual_length); 767 tty_buffer_request_room(tty, urb->actual_length);
756 tty_insert_flip_string(tty, data, urb->actual_length); 768 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -759,18 +771,20 @@ static void ipaq_read_bulk_callback(struct urb *urb)
759 } 771 }
760 772
761 /* Continue trying to always read */ 773 /* Continue trying to always read */
762 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 774 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
763 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), 775 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress),
764 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 776 port->read_urb->transfer_buffer,
765 ipaq_read_bulk_callback, port); 777 port->read_urb->transfer_buffer_length,
778 ipaq_read_bulk_callback, port);
766 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 779 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
767 if (result) 780 if (result)
768 err("%s - failed resubmitting read urb, error %d", __func__, result); 781 err("%s - failed resubmitting read urb, error %d",
782 __func__, result);
769 return; 783 return;
770} 784}
771 785
772static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf, 786static int ipaq_write(struct tty_struct *tty, struct usb_serial_port *port,
773 int count) 787 const unsigned char *buf, int count)
774{ 788{
775 const unsigned char *current_position = buf; 789 const unsigned char *current_position = buf;
776 int bytes_sent = 0; 790 int bytes_sent = 0;
@@ -780,9 +794,8 @@ static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf,
780 794
781 while (count > 0) { 795 while (count > 0) {
782 transfer_size = min(count, PACKET_SIZE); 796 transfer_size = min(count, PACKET_SIZE);
783 if (ipaq_write_bulk(port, current_position, transfer_size)) { 797 if (ipaq_write_bulk(port, current_position, transfer_size))
784 break; 798 break;
785 }
786 current_position += transfer_size; 799 current_position += transfer_size;
787 bytes_sent += transfer_size; 800 bytes_sent += transfer_size;
788 count -= transfer_size; 801 count -= transfer_size;
@@ -790,10 +803,10 @@ static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf,
790 } 803 }
791 804
792 return bytes_sent; 805 return bytes_sent;
793} 806}
794 807
795static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *buf, 808static int ipaq_write_bulk(struct usb_serial_port *port,
796 int count) 809 const unsigned char *buf, int count)
797{ 810{
798 struct ipaq_private *priv = usb_get_serial_port_data(port); 811 struct ipaq_private *priv = usb_get_serial_port_data(port);
799 struct ipaq_packet *pkt = NULL; 812 struct ipaq_packet *pkt = NULL;
@@ -830,9 +843,9 @@ static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *bu
830 ipaq_write_gather(port); 843 ipaq_write_gather(port);
831 spin_unlock_irqrestore(&write_list_lock, flags); 844 spin_unlock_irqrestore(&write_list_lock, flags);
832 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 845 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
833 if (result) { 846 if (result)
834 err("%s - failed submitting write urb, error %d", __func__, result); 847 err("%s - failed submitting write urb, error %d",
835 } 848 __func__, result);
836 } else { 849 } else {
837 spin_unlock_irqrestore(&write_list_lock, flags); 850 spin_unlock_irqrestore(&write_list_lock, flags);
838 } 851 }
@@ -859,16 +872,15 @@ static void ipaq_write_gather(struct usb_serial_port *port)
859 list_move(&pkt->list, &priv->freelist); 872 list_move(&pkt->list, &priv->freelist);
860 priv->free_len += PACKET_SIZE; 873 priv->free_len += PACKET_SIZE;
861 } 874 }
862 if (room == 0) { 875 if (room == 0)
863 break; 876 break;
864 }
865 } 877 }
866 878
867 count = URBDATA_SIZE - room; 879 count = URBDATA_SIZE - room;
868 usb_fill_bulk_urb(port->write_urb, serial->dev, 880 usb_fill_bulk_urb(port->write_urb, serial->dev,
869 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress), 881 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
870 port->write_urb->transfer_buffer, count, ipaq_write_bulk_callback, 882 port->write_urb->transfer_buffer, count,
871 port); 883 ipaq_write_bulk_callback, port);
872 return; 884 return;
873} 885}
874 886
@@ -893,9 +905,9 @@ static void ipaq_write_bulk_callback(struct urb *urb)
893 ipaq_write_gather(port); 905 ipaq_write_gather(port);
894 spin_unlock_irqrestore(&write_list_lock, flags); 906 spin_unlock_irqrestore(&write_list_lock, flags);
895 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 907 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
896 if (result) { 908 if (result)
897 err("%s - failed submitting write urb, error %d", __func__, result); 909 err("%s - failed submitting write urb, error %d",
898 } 910 __func__, result);
899 } else { 911 } else {
900 priv->active = 0; 912 priv->active = 0;
901 spin_unlock_irqrestore(&write_list_lock, flags); 913 spin_unlock_irqrestore(&write_list_lock, flags);
@@ -904,16 +916,18 @@ static void ipaq_write_bulk_callback(struct urb *urb)
904 usb_serial_port_softint(port); 916 usb_serial_port_softint(port);
905} 917}
906 918
907static int ipaq_write_room(struct usb_serial_port *port) 919static int ipaq_write_room(struct tty_struct *tty)
908{ 920{
921 struct usb_serial_port *port = tty->driver_data;
909 struct ipaq_private *priv = usb_get_serial_port_data(port); 922 struct ipaq_private *priv = usb_get_serial_port_data(port);
910 923
911 dbg("%s - freelen %d", __func__, priv->free_len); 924 dbg("%s - freelen %d", __func__, priv->free_len);
912 return priv->free_len; 925 return priv->free_len;
913} 926}
914 927
915static int ipaq_chars_in_buffer(struct usb_serial_port *port) 928static int ipaq_chars_in_buffer(struct tty_struct *tty)
916{ 929{
930 struct usb_serial_port *port = tty->driver_data;
917 struct ipaq_private *priv = usb_get_serial_port_data(port); 931 struct ipaq_private *priv = usb_get_serial_port_data(port);
918 932
919 dbg("%s - queuelen %d", __func__, priv->queue_len); 933 dbg("%s - queuelen %d", __func__, priv->queue_len);
@@ -944,7 +958,7 @@ static int ipaq_startup(struct usb_serial *serial)
944 serial->dev->actconfig->desc.bConfigurationValue); 958 serial->dev->actconfig->desc.bConfigurationValue);
945 return -ENODEV; 959 return -ENODEV;
946 } 960 }
947 return usb_reset_configuration (serial->dev); 961 return usb_reset_configuration(serial->dev);
948} 962}
949 963
950static void ipaq_shutdown(struct usb_serial *serial) 964static void ipaq_shutdown(struct usb_serial *serial)
@@ -957,7 +971,7 @@ static int __init ipaq_init(void)
957 int retval; 971 int retval;
958 spin_lock_init(&write_list_lock); 972 spin_lock_init(&write_list_lock);
959 retval = usb_serial_register(&ipaq_device); 973 retval = usb_serial_register(&ipaq_device);
960 if (retval) 974 if (retval)
961 goto failed_usb_serial_register; 975 goto failed_usb_serial_register;
962 info(DRIVER_DESC " " DRIVER_VERSION); 976 info(DRIVER_DESC " " DRIVER_VERSION);
963 if (vendor) { 977 if (vendor) {
@@ -967,7 +981,7 @@ static int __init ipaq_init(void)
967 retval = usb_register(&ipaq_driver); 981 retval = usb_register(&ipaq_driver);
968 if (retval) 982 if (retval)
969 goto failed_usb_register; 983 goto failed_usb_register;
970 984
971 return 0; 985 return 0;
972failed_usb_register: 986failed_usb_register:
973 usb_serial_deregister(&ipaq_device); 987 usb_serial_deregister(&ipaq_device);
@@ -986,8 +1000,8 @@ static void __exit ipaq_exit(void)
986module_init(ipaq_init); 1000module_init(ipaq_init);
987module_exit(ipaq_exit); 1001module_exit(ipaq_exit);
988 1002
989MODULE_AUTHOR( DRIVER_AUTHOR ); 1003MODULE_AUTHOR(DRIVER_AUTHOR);
990MODULE_DESCRIPTION( DRIVER_DESC ); 1004MODULE_DESCRIPTION(DRIVER_DESC);
991MODULE_LICENSE("GPL"); 1005MODULE_LICENSE("GPL");
992 1006
993module_param(debug, bool, S_IRUGO | S_IWUSR); 1007module_param(debug, bool, S_IRUGO | S_IWUSR);
@@ -1000,7 +1014,9 @@ module_param(product, ushort, 0);
1000MODULE_PARM_DESC(product, "User specified USB idProduct"); 1014MODULE_PARM_DESC(product, "User specified USB idProduct");
1001 1015
1002module_param(connect_retries, int, S_IRUGO|S_IWUSR); 1016module_param(connect_retries, int, S_IRUGO|S_IWUSR);
1003MODULE_PARM_DESC(connect_retries, "Maximum number of connect retries (one second each)"); 1017MODULE_PARM_DESC(connect_retries,
1018 "Maximum number of connect retries (one second each)");
1004 1019
1005module_param(initial_wait, int, S_IRUGO|S_IWUSR); 1020module_param(initial_wait, int, S_IRUGO|S_IWUSR);
1006MODULE_PARM_DESC(initial_wait, "Time to wait before attempting a connection (in seconds)"); 1021MODULE_PARM_DESC(initial_wait,
1022 "Time to wait before attempting a connection (in seconds)");
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index bc85ca5c1c37..a842025b9b57 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -10,27 +10,27 @@
10 * (at your option) any later version. 10 * (at your option) any later version.
11 * 11 *
12 * All information about the device was acquired using SnoopyPro 12 * All information about the device was acquired using SnoopyPro
13 * on MSFT's O/S, and examing the MSFT drivers' debug output 13 * on MSFT's O/S, and examing the MSFT drivers' debug output
14 * (insanely left _on_ in the enduser version) 14 * (insanely left _on_ in the enduser version)
15 * 15 *
16 * It was written out of frustration with the IPWireless USB modem 16 * It was written out of frustration with the IPWireless USB modem
17 * supplied by Axity3G/Sentech South Africa not supporting 17 * supplied by Axity3G/Sentech South Africa not supporting
18 * Linux whatsoever. 18 * Linux whatsoever.
19 * 19 *
20 * Nobody provided any proprietary information that was not already 20 * Nobody provided any proprietary information that was not already
21 * available for this device. 21 * available for this device.
22 * 22 *
23 * The modem adheres to the "3GPP TS 27.007 AT command set for 3G 23 * The modem adheres to the "3GPP TS 27.007 AT command set for 3G
24 * User Equipment (UE)" standard, available from 24 * User Equipment (UE)" standard, available from
25 * http://www.3gpp.org/ftp/Specs/html-info/27007.htm 25 * http://www.3gpp.org/ftp/Specs/html-info/27007.htm
26 * 26 *
27 * The code was only tested the IPWireless handheld modem distributed 27 * The code was only tested the IPWireless handheld modem distributed
28 * in South Africa by Sentech. 28 * in South Africa by Sentech.
29 * 29 *
30 * It may work for Woosh Inc in .nz too, as it appears they use the 30 * It may work for Woosh Inc in .nz too, as it appears they use the
31 * same kit. 31 * same kit.
32 * 32 *
33 * There is still some work to be done in terms of handling 33 * There is still some work to be done in terms of handling
34 * DCD, DTR, RTS, CTS which are currently faked. 34 * DCD, DTR, RTS, CTS which are currently faked.
35 * It's good enough for PPP at this point. It's based off all kinds of 35 * It's good enough for PPP at this point. It's based off all kinds of
36 * code found in usb/serial and usb/class 36 * code found in usb/serial and usb/class
@@ -47,7 +47,7 @@
47#include <linux/spinlock.h> 47#include <linux/spinlock.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/usb/serial.h> 49#include <linux/usb/serial.h>
50#include <asm/uaccess.h> 50#include <linux/uaccess.h>
51 51
52/* 52/*
53 * Version Information 53 * Version Information
@@ -64,7 +64,7 @@
64 64
65/* Message sizes */ 65/* Message sizes */
66#define EVENT_BUFFER_SIZE 0xFF 66#define EVENT_BUFFER_SIZE 0xFF
67#define CHAR2INT16(c1,c0) (((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff)) 67#define CHAR2INT16(c1, c0) (((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff))
68#define NUM_BULK_URBS 24 68#define NUM_BULK_URBS 24
69#define NUM_CONTROL_URBS 16 69#define NUM_CONTROL_URBS 16
70 70
@@ -94,33 +94,34 @@ enum {
94 94
95/* data bits */ 95/* data bits */
96#define ipw_dtb_7 0x700 96#define ipw_dtb_7 0x700
97#define ipw_dtb_8 0x810 // ok so the define is misleading, I know, but forces 8,n,1 97#define ipw_dtb_8 0x810 /* ok so the define is misleading, I know, but forces 8,n,1 */
98 // I mean, is there a point to any other setting these days? :) 98 /* I mean, is there a point to any other setting these days? :) */
99 99
100/* usb control request types : */ 100/* usb control request types : */
101#define IPW_SIO_RXCTL 0x00 // control bulk rx channel transmissions, value=1/0 (on/off) 101#define IPW_SIO_RXCTL 0x00 /* control bulk rx channel transmissions, value=1/0 (on/off) */
102#define IPW_SIO_SET_BAUD 0x01 // set baud, value=requested ipw_sio_bxxxx 102#define IPW_SIO_SET_BAUD 0x01 /* set baud, value=requested ipw_sio_bxxxx */
103#define IPW_SIO_SET_LINE 0x03 // set databits, parity. value=ipw_dtb_x 103#define IPW_SIO_SET_LINE 0x03 /* set databits, parity. value=ipw_dtb_x */
104#define IPW_SIO_SET_PIN 0x03 // set/clear dtr/rts value=ipw_pin_xxx 104#define IPW_SIO_SET_PIN 0x03 /* set/clear dtr/rts value=ipw_pin_xxx */
105#define IPW_SIO_POLL 0x08 // get serial port status byte, call with value=0 105#define IPW_SIO_POLL 0x08 /* get serial port status byte, call with value=0 */
106#define IPW_SIO_INIT 0x11 // initializes ? value=0 (appears as first thing todo on open) 106#define IPW_SIO_INIT 0x11 /* initializes ? value=0 (appears as first thing todo on open) */
107#define IPW_SIO_PURGE 0x12 // purge all transmissions?, call with value=numchar_to_purge 107#define IPW_SIO_PURGE 0x12 /* purge all transmissions?, call with value=numchar_to_purge */
108#define IPW_SIO_HANDFLOW 0x13 // set xon/xoff limits value=0, and a buffer of 0x10 bytes 108#define IPW_SIO_HANDFLOW 0x13 /* set xon/xoff limits value=0, and a buffer of 0x10 bytes */
109#define IPW_SIO_SETCHARS 0x13 // set the flowcontrol special chars, value=0, buf=6 bytes, 109#define IPW_SIO_SETCHARS 0x13 /* set the flowcontrol special chars, value=0, buf=6 bytes, */
110 // last 2 bytes contain flowcontrol chars e.g. 00 00 00 00 11 13 110 /* last 2 bytes contain flowcontrol chars e.g. 00 00 00 00 11 13 */
111 111
112/* values used for request IPW_SIO_SET_PIN */ 112/* values used for request IPW_SIO_SET_PIN */
113#define IPW_PIN_SETDTR 0x101 113#define IPW_PIN_SETDTR 0x101
114#define IPW_PIN_SETRTS 0x202 114#define IPW_PIN_SETRTS 0x202
115#define IPW_PIN_CLRDTR 0x100 115#define IPW_PIN_CLRDTR 0x100
116#define IPW_PIN_CLRRTS 0x200 // unconfirmed 116#define IPW_PIN_CLRRTS 0x200 /* unconfirmed */
117 117
118/* values used for request IPW_SIO_RXCTL */ 118/* values used for request IPW_SIO_RXCTL */
119#define IPW_RXBULK_ON 1 119#define IPW_RXBULK_ON 1
120#define IPW_RXBULK_OFF 0 120#define IPW_RXBULK_OFF 0
121 121
122/* various 16 byte hardcoded transferbuffers used by flow control */ 122/* various 16 byte hardcoded transferbuffers used by flow control */
123#define IPW_BYTES_FLOWINIT { 0x01, 0, 0, 0, 0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 123#define IPW_BYTES_FLOWINIT { 0x01, 0, 0, 0, 0x40, 0, 0, 0, \
124 0, 0, 0, 0, 0, 0, 0, 0 }
124 125
125/* Interpretation of modem status lines */ 126/* Interpretation of modem status lines */
126/* These need sorting out by individually connecting pins and checking 127/* These need sorting out by individually connecting pins and checking
@@ -132,17 +133,6 @@ enum {
132#define IPW_CTS ((1<<5) | (1<<4)) 133#define IPW_CTS ((1<<5) | (1<<4))
133 134
134#define IPW_WANTS_TO_SEND 0x30 135#define IPW_WANTS_TO_SEND 0x30
135//#define IPW_DTR /* Data Terminal Ready */
136//#define IPW_CTS /* Clear To Send */
137//#define IPW_CD /* Carrier Detect */
138//#define IPW_DSR /* Data Set Ready */
139//#define IPW_RxD /* Receive pin */
140
141//#define IPW_LE
142//#define IPW_RTS
143//#define IPW_ST
144//#define IPW_SR
145//#define IPW_RI /* Ring Indicator */
146 136
147static struct usb_device_id usb_ipw_ids[] = { 137static struct usb_device_id usb_ipw_ids[] = {
148 { USB_DEVICE(IPW_VID, IPW_PID) }, 138 { USB_DEVICE(IPW_VID, IPW_PID) },
@@ -177,9 +167,10 @@ static void ipw_read_bulk_callback(struct urb *urb)
177 return; 167 return;
178 } 168 }
179 169
180 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 170 usb_serial_debug_data(debug, &port->dev, __func__,
171 urb->actual_length, data);
181 172
182 tty = port->tty; 173 tty = port->port.tty;
183 if (tty && urb->actual_length) { 174 if (tty && urb->actual_length) {
184 tty_buffer_request_room(tty, urb->actual_length); 175 tty_buffer_request_room(tty, urb->actual_length);
185 tty_insert_flip_string(tty, data, urb->actual_length); 176 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -187,19 +178,22 @@ static void ipw_read_bulk_callback(struct urb *urb)
187 } 178 }
188 179
189 /* Continue trying to always read */ 180 /* Continue trying to always read */
190 usb_fill_bulk_urb (port->read_urb, port->serial->dev, 181 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
191 usb_rcvbulkpipe(port->serial->dev, 182 usb_rcvbulkpipe(port->serial->dev,
192 port->bulk_in_endpointAddress), 183 port->bulk_in_endpointAddress),
193 port->read_urb->transfer_buffer, 184 port->read_urb->transfer_buffer,
194 port->read_urb->transfer_buffer_length, 185 port->read_urb->transfer_buffer_length,
195 ipw_read_bulk_callback, port); 186 ipw_read_bulk_callback, port);
196 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 187 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
197 if (result) 188 if (result)
198 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 189 dev_err(&port->dev,
190 "%s - failed resubmitting read urb, error %d\n",
191 __func__, result);
199 return; 192 return;
200} 193}
201 194
202static int ipw_open(struct usb_serial_port *port, struct file *filp) 195static int ipw_open(struct tty_struct *tty,
196 struct usb_serial_port *port, struct file *filp)
203{ 197{
204 struct usb_device *dev = port->serial->dev; 198 struct usb_device *dev = port->serial->dev;
205 u8 buf_flow_static[16] = IPW_BYTES_FLOWINIT; 199 u8 buf_flow_static[16] = IPW_BYTES_FLOWINIT;
@@ -212,29 +206,33 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
212 if (!buf_flow_init) 206 if (!buf_flow_init)
213 return -ENOMEM; 207 return -ENOMEM;
214 208
215 if (port->tty) 209 if (tty)
216 port->tty->low_latency = 1; 210 tty->low_latency = 1;
217 211
218 /* --1: Tell the modem to initialize (we think) From sniffs this is always the 212 /* --1: Tell the modem to initialize (we think) From sniffs this is
219 * first thing that gets sent to the modem during opening of the device */ 213 * always the first thing that gets sent to the modem during
220 dbg("%s: Sending SIO_INIT (we guess)",__func__); 214 * opening of the device */
221 result = usb_control_msg(dev, usb_sndctrlpipe(dev,0), 215 dbg("%s: Sending SIO_INIT (we guess)", __func__);
222 IPW_SIO_INIT, 216 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
223 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 217 IPW_SIO_INIT,
224 0, 218 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
225 0, /* index */ 219 0,
226 NULL, 220 0, /* index */
227 0, 221 NULL,
228 100000); 222 0,
223 100000);
229 if (result < 0) 224 if (result < 0)
230 dev_err(&port->dev, "Init of modem failed (error = %d)\n", result); 225 dev_err(&port->dev,
226 "Init of modem failed (error = %d)\n", result);
231 227
232 /* reset the bulk pipes */ 228 /* reset the bulk pipes */
233 usb_clear_halt(dev, usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress)); 229 usb_clear_halt(dev,
234 usb_clear_halt(dev, usb_sndbulkpipe(dev, port->bulk_out_endpointAddress)); 230 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress));
231 usb_clear_halt(dev,
232 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress));
235 233
236 /*--2: Start reading from the device */ 234 /*--2: Start reading from the device */
237 dbg("%s: setting up bulk read callback",__func__); 235 dbg("%s: setting up bulk read callback", __func__);
238 usb_fill_bulk_urb(port->read_urb, dev, 236 usb_fill_bulk_urb(port->read_urb, dev,
239 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress), 237 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
240 port->bulk_in_buffer, 238 port->bulk_in_buffer,
@@ -242,66 +240,72 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
242 ipw_read_bulk_callback, port); 240 ipw_read_bulk_callback, port);
243 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 241 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
244 if (result < 0) 242 if (result < 0)
245 dbg("%s - usb_submit_urb(read bulk) failed with status %d", __func__, result); 243 dbg("%s - usb_submit_urb(read bulk) failed with status %d",
244 __func__, result);
246 245
247 /*--3: Tell the modem to open the floodgates on the rx bulk channel */ 246 /*--3: Tell the modem to open the floodgates on the rx bulk channel */
248 dbg("%s:asking modem for RxRead (RXBULK_ON)",__func__); 247 dbg("%s:asking modem for RxRead (RXBULK_ON)", __func__);
249 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 248 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
250 IPW_SIO_RXCTL, 249 IPW_SIO_RXCTL,
251 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 250 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
252 IPW_RXBULK_ON, 251 IPW_RXBULK_ON,
253 0, /* index */ 252 0, /* index */
254 NULL, 253 NULL,
255 0, 254 0,
256 100000); 255 100000);
257 if (result < 0) 256 if (result < 0)
258 dev_err(&port->dev, "Enabling bulk RxRead failed (error = %d)\n", result); 257 dev_err(&port->dev,
258 "Enabling bulk RxRead failed (error = %d)\n", result);
259 259
260 /*--4: setup the initial flowcontrol */ 260 /*--4: setup the initial flowcontrol */
261 dbg("%s:setting init flowcontrol (%s)",__func__,buf_flow_init); 261 dbg("%s:setting init flowcontrol (%s)", __func__, buf_flow_init);
262 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 262 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
263 IPW_SIO_HANDFLOW, 263 IPW_SIO_HANDFLOW,
264 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 264 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
265 0, 265 0,
266 0, 266 0,
267 buf_flow_init, 267 buf_flow_init,
268 0x10, 268 0x10,
269 200000); 269 200000);
270 if (result < 0) 270 if (result < 0)
271 dev_err(&port->dev, "initial flowcontrol failed (error = %d)\n", result); 271 dev_err(&port->dev,
272 "initial flowcontrol failed (error = %d)\n", result);
272 273
273 274
274 /*--5: raise the dtr */ 275 /*--5: raise the dtr */
275 dbg("%s:raising dtr",__func__); 276 dbg("%s:raising dtr", __func__);
276 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 277 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
277 IPW_SIO_SET_PIN, 278 IPW_SIO_SET_PIN,
278 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 279 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
279 IPW_PIN_SETDTR, 280 IPW_PIN_SETDTR,
280 0, 281 0,
281 NULL, 282 NULL,
282 0, 283 0,
283 200000); 284 200000);
284 if (result < 0) 285 if (result < 0)
285 dev_err(&port->dev, "setting dtr failed (error = %d)\n", result); 286 dev_err(&port->dev,
287 "setting dtr failed (error = %d)\n", result);
286 288
287 /*--6: raise the rts */ 289 /*--6: raise the rts */
288 dbg("%s:raising rts",__func__); 290 dbg("%s:raising rts", __func__);
289 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 291 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
290 IPW_SIO_SET_PIN, 292 IPW_SIO_SET_PIN,
291 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 293 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
292 IPW_PIN_SETRTS, 294 IPW_PIN_SETRTS,
293 0, 295 0,
294 NULL, 296 NULL,
295 0, 297 0,
296 200000); 298 200000);
297 if (result < 0) 299 if (result < 0)
298 dev_err(&port->dev, "setting dtr failed (error = %d)\n", result); 300 dev_err(&port->dev,
299 301 "setting dtr failed (error = %d)\n", result);
302
300 kfree(buf_flow_init); 303 kfree(buf_flow_init);
301 return 0; 304 return 0;
302} 305}
303 306
304static void ipw_close(struct usb_serial_port *port, struct file * filp) 307static void ipw_close(struct tty_struct *tty,
308 struct usb_serial_port *port, struct file *filp)
305{ 309{
306 struct usb_device *dev = port->serial->dev; 310 struct usb_device *dev = port->serial->dev;
307 int result; 311 int result;
@@ -312,56 +316,62 @@ static void ipw_close(struct usb_serial_port *port, struct file * filp)
312 } 316 }
313 317
314 /*--1: drop the dtr */ 318 /*--1: drop the dtr */
315 dbg("%s:dropping dtr",__func__); 319 dbg("%s:dropping dtr", __func__);
316 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 320 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
317 IPW_SIO_SET_PIN, 321 IPW_SIO_SET_PIN,
318 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 322 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
319 IPW_PIN_CLRDTR, 323 IPW_PIN_CLRDTR,
320 0, 324 0,
321 NULL, 325 NULL,
322 0, 326 0,
323 200000); 327 200000);
324 if (result < 0) 328 if (result < 0)
325 dev_err(&port->dev, "dropping dtr failed (error = %d)\n", result); 329 dev_err(&port->dev, "dropping dtr failed (error = %d)\n",
330 result);
326 331
327 /*--2: drop the rts */ 332 /*--2: drop the rts */
328 dbg("%s:dropping rts",__func__); 333 dbg("%s:dropping rts", __func__);
329 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 334 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
330 IPW_SIO_SET_PIN, USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 335 IPW_SIO_SET_PIN, USB_TYPE_VENDOR |
331 IPW_PIN_CLRRTS, 336 USB_RECIP_INTERFACE | USB_DIR_OUT,
332 0, 337 IPW_PIN_CLRRTS,
333 NULL, 338 0,
334 0, 339 NULL,
335 200000); 340 0,
341 200000);
336 if (result < 0) 342 if (result < 0)
337 dev_err(&port->dev, "dropping rts failed (error = %d)\n", result); 343 dev_err(&port->dev,
344 "dropping rts failed (error = %d)\n", result);
338 345
339 346
340 /*--3: purge */ 347 /*--3: purge */
341 dbg("%s:sending purge",__func__); 348 dbg("%s:sending purge", __func__);
342 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 349 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
343 IPW_SIO_PURGE, USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 350 IPW_SIO_PURGE, USB_TYPE_VENDOR |
344 0x03, 351 USB_RECIP_INTERFACE | USB_DIR_OUT,
345 0, 352 0x03,
346 NULL, 353 0,
347 0, 354 NULL,
348 200000); 355 0,
356 200000);
349 if (result < 0) 357 if (result < 0)
350 dev_err(&port->dev, "purge failed (error = %d)\n", result); 358 dev_err(&port->dev, "purge failed (error = %d)\n", result);
351 359
352 360
353 /* send RXBULK_off (tell modem to stop transmitting bulk data on rx chan) */ 361 /* send RXBULK_off (tell modem to stop transmitting bulk data on
362 rx chan) */
354 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 363 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
355 IPW_SIO_RXCTL, 364 IPW_SIO_RXCTL,
356 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 365 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
357 IPW_RXBULK_OFF, 366 IPW_RXBULK_OFF,
358 0, /* index */ 367 0, /* index */
359 NULL, 368 NULL,
360 0, 369 0,
361 100000); 370 100000);
362 371
363 if (result < 0) 372 if (result < 0)
364 dev_err(&port->dev, "Disabling bulk RxRead failed (error = %d)\n", result); 373 dev_err(&port->dev,
374 "Disabling bulk RxRead failed (error = %d)\n", result);
365 375
366 /* shutdown any in-flight urbs that we know about */ 376 /* shutdown any in-flight urbs that we know about */
367 usb_kill_urb(port->read_urb); 377 usb_kill_urb(port->read_urb);
@@ -384,13 +394,14 @@ static void ipw_write_bulk_callback(struct urb *urb)
384 usb_serial_port_softint(port); 394 usb_serial_port_softint(port);
385} 395}
386 396
387static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int count) 397static int ipw_write(struct tty_struct *tty, struct usb_serial_port *port,
398 const unsigned char *buf, int count)
388{ 399{
389 struct usb_device *dev = port->serial->dev; 400 struct usb_device *dev = port->serial->dev;
390 int ret; 401 int ret;
391 402
392 dbg("%s: TOP: count=%d, in_interrupt=%ld", __func__, 403 dbg("%s: TOP: count=%d, in_interrupt=%ld", __func__,
393 count, in_interrupt() ); 404 count, in_interrupt());
394 405
395 if (count == 0) { 406 if (count == 0) {
396 dbg("%s - write request of 0 bytes", __func__); 407 dbg("%s - write request of 0 bytes", __func__);
@@ -421,13 +432,14 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
421 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC); 432 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
422 if (ret != 0) { 433 if (ret != 0) {
423 port->write_urb_busy = 0; 434 port->write_urb_busy = 0;
424 dbg("%s - usb_submit_urb(write bulk) failed with error = %d", __func__, ret); 435 dbg("%s - usb_submit_urb(write bulk) failed with error = %d",
436 __func__, ret);
425 return ret; 437 return ret;
426 } 438 }
427 439
428 dbg("%s returning %d", __func__, count); 440 dbg("%s returning %d", __func__, count);
429 return count; 441 return count;
430} 442}
431 443
432static int ipw_probe(struct usb_serial_port *port) 444static int ipw_probe(struct usb_serial_port *port)
433{ 445{
@@ -486,8 +498,8 @@ module_init(usb_ipw_init);
486module_exit(usb_ipw_exit); 498module_exit(usb_ipw_exit);
487 499
488/* Module information */ 500/* Module information */
489MODULE_AUTHOR( DRIVER_AUTHOR ); 501MODULE_AUTHOR(DRIVER_AUTHOR);
490MODULE_DESCRIPTION( DRIVER_DESC ); 502MODULE_DESCRIPTION(DRIVER_DESC);
491MODULE_LICENSE("GPL"); 503MODULE_LICENSE("GPL");
492 504
493module_param(debug, bool, S_IRUGO | S_IWUSR); 505module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 004d57385a75..e59155c6607d 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -19,7 +19,12 @@
19 * was written by Roman Weissgaerber <weissg@vienna.at>, Dag Brattli 19 * was written by Roman Weissgaerber <weissg@vienna.at>, Dag Brattli
20 * <dag@brattli.net>, and Jean Tourrilhes <jt@hpl.hp.com> 20 * <dag@brattli.net>, and Jean Tourrilhes <jt@hpl.hp.com>
21 * 21 *
22 * See Documentation/usb/usb-serial.txt for more information on using this driver 22 * See Documentation/usb/usb-serial.txt for more information on using this
23 * driver
24 *
25 * 2008_Jun_02 Felipe Balbi <me@felipebalbi.com>
26 * Introduced common header to be used also in USB Gadget Framework.
27 * Still needs some other style fixes.
23 * 28 *
24 * 2007_Jun_21 Alan Cox <alan@redhat.com> 29 * 2007_Jun_21 Alan Cox <alan@redhat.com>
25 * Minimal cleanups for some of the driver problens and tty layer abuse. 30 * Minimal cleanups for some of the driver problens and tty layer abuse.
@@ -59,9 +64,10 @@
59#include <linux/tty_flip.h> 64#include <linux/tty_flip.h>
60#include <linux/module.h> 65#include <linux/module.h>
61#include <linux/spinlock.h> 66#include <linux/spinlock.h>
62#include <asm/uaccess.h> 67#include <linux/uaccess.h>
63#include <linux/usb.h> 68#include <linux/usb.h>
64#include <linux/usb/serial.h> 69#include <linux/usb/serial.h>
70#include <linux/usb/irda.h>
65 71
66/* 72/*
67 * Version Information 73 * Version Information
@@ -70,100 +76,77 @@
70#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>" 76#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>"
71#define DRIVER_DESC "USB IR Dongle driver" 77#define DRIVER_DESC "USB IR Dongle driver"
72 78
73/* USB IrDA class spec information */
74#define USB_CLASS_IRDA 0x02
75#define USB_DT_IRDA 0x21
76#define IU_REQ_GET_CLASS_DESC 0x06
77#define SPEED_2400 0x01
78#define SPEED_9600 0x02
79#define SPEED_19200 0x03
80#define SPEED_38400 0x04
81#define SPEED_57600 0x05
82#define SPEED_115200 0x06
83#define SPEED_576000 0x07
84#define SPEED_1152000 0x08
85#define SPEED_4000000 0x09
86
87struct irda_class_desc {
88 u8 bLength;
89 u8 bDescriptorType;
90 u16 bcdSpecRevision;
91 u8 bmDataSize;
92 u8 bmWindowSize;
93 u8 bmMinTurnaroundTime;
94 u16 wBaudRate;
95 u8 bmAdditionalBOFs;
96 u8 bIrdaRateSniff;
97 u8 bMaxUnicastList;
98} __attribute__ ((packed));
99
100static int debug; 79static int debug;
101 80
102/* if overridden by the user, then use their value for the size of the read and 81/* if overridden by the user, then use their value for the size of the read and
103 * write urbs */ 82 * write urbs */
104static int buffer_size; 83static int buffer_size;
84
105/* if overridden by the user, then use the specified number of XBOFs */ 85/* if overridden by the user, then use the specified number of XBOFs */
106static int xbof = -1; 86static int xbof = -1;
107 87
108static int ir_startup (struct usb_serial *serial); 88static int ir_startup (struct usb_serial *serial);
109static int ir_open (struct usb_serial_port *port, struct file *filep); 89static int ir_open(struct tty_struct *tty, struct usb_serial_port *port,
110static void ir_close (struct usb_serial_port *port, struct file *filep); 90 struct file *filep);
111static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int count); 91static void ir_close(struct tty_struct *tty, struct usb_serial_port *port,
92 struct file *filep);
93static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
94 const unsigned char *buf, int count);
112static void ir_write_bulk_callback (struct urb *urb); 95static void ir_write_bulk_callback (struct urb *urb);
113static void ir_read_bulk_callback (struct urb *urb); 96static void ir_read_bulk_callback (struct urb *urb);
114static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_termios); 97static void ir_set_termios(struct tty_struct *tty,
98 struct usb_serial_port *port, struct ktermios *old_termios);
115 99
116/* Not that this lot means you can only have one per system */ 100/* Not that this lot means you can only have one per system */
117static u8 ir_baud = 0; 101static u8 ir_baud;
118static u8 ir_xbof = 0; 102static u8 ir_xbof;
119static u8 ir_add_bof = 0; 103static u8 ir_add_bof;
120 104
121static struct usb_device_id id_table [] = { 105static struct usb_device_id ir_id_table[] = {
122 { USB_DEVICE(0x050f, 0x0180) }, /* KC Technology, KC-180 */ 106 { USB_DEVICE(0x050f, 0x0180) }, /* KC Technology, KC-180 */
123 { USB_DEVICE(0x08e9, 0x0100) }, /* XTNDAccess */ 107 { USB_DEVICE(0x08e9, 0x0100) }, /* XTNDAccess */
124 { USB_DEVICE(0x09c4, 0x0011) }, /* ACTiSys ACT-IR2000U */ 108 { USB_DEVICE(0x09c4, 0x0011) }, /* ACTiSys ACT-IR2000U */
125 { USB_INTERFACE_INFO (USB_CLASS_APP_SPEC, USB_CLASS_IRDA, 0) }, 109 { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC, USB_SUBCLASS_IRDA, 0) },
126 { } /* Terminating entry */ 110 { } /* Terminating entry */
127}; 111};
128 112
129MODULE_DEVICE_TABLE (usb, id_table); 113MODULE_DEVICE_TABLE(usb, ir_id_table);
130 114
131static struct usb_driver ir_driver = { 115static struct usb_driver ir_driver = {
132 .name = "ir-usb", 116 .name = "ir-usb",
133 .probe = usb_serial_probe, 117 .probe = usb_serial_probe,
134 .disconnect = usb_serial_disconnect, 118 .disconnect = usb_serial_disconnect,
135 .id_table = id_table, 119 .id_table = ir_id_table,
136 .no_dynamic_id = 1, 120 .no_dynamic_id = 1,
137}; 121};
138 122
139
140static struct usb_serial_driver ir_device = { 123static struct usb_serial_driver ir_device = {
141 .driver = { 124 .driver = {
142 .owner = THIS_MODULE, 125 .owner = THIS_MODULE,
143 .name = "ir-usb", 126 .name = "ir-usb",
144 }, 127 },
145 .description = "IR Dongle", 128 .description = "IR Dongle",
146 .usb_driver = &ir_driver, 129 .usb_driver = &ir_driver,
147 .id_table = id_table, 130 .id_table = ir_id_table,
148 .num_ports = 1, 131 .num_ports = 1,
149 .set_termios = ir_set_termios, 132 .set_termios = ir_set_termios,
150 .attach = ir_startup, 133 .attach = ir_startup,
151 .open = ir_open, 134 .open = ir_open,
152 .close = ir_close, 135 .close = ir_close,
153 .write = ir_write, 136 .write = ir_write,
154 .write_bulk_callback = ir_write_bulk_callback, 137 .write_bulk_callback = ir_write_bulk_callback,
155 .read_bulk_callback = ir_read_bulk_callback, 138 .read_bulk_callback = ir_read_bulk_callback,
156}; 139};
157 140
158static inline void irda_usb_dump_class_desc(struct irda_class_desc *desc) 141static inline void irda_usb_dump_class_desc(struct usb_irda_cs_descriptor *desc)
159{ 142{
160 dbg("bLength=%x", desc->bLength); 143 dbg("bLength=%x", desc->bLength);
161 dbg("bDescriptorType=%x", desc->bDescriptorType); 144 dbg("bDescriptorType=%x", desc->bDescriptorType);
162 dbg("bcdSpecRevision=%x", desc->bcdSpecRevision); 145 dbg("bcdSpecRevision=%x", __le16_to_cpu(desc->bcdSpecRevision));
163 dbg("bmDataSize=%x", desc->bmDataSize); 146 dbg("bmDataSize=%x", desc->bmDataSize);
164 dbg("bmWindowSize=%x", desc->bmWindowSize); 147 dbg("bmWindowSize=%x", desc->bmWindowSize);
165 dbg("bmMinTurnaroundTime=%d", desc->bmMinTurnaroundTime); 148 dbg("bmMinTurnaroundTime=%d", desc->bmMinTurnaroundTime);
166 dbg("wBaudRate=%x", desc->wBaudRate); 149 dbg("wBaudRate=%x", __le16_to_cpu(desc->wBaudRate));
167 dbg("bmAdditionalBOFs=%x", desc->bmAdditionalBOFs); 150 dbg("bmAdditionalBOFs=%x", desc->bmAdditionalBOFs);
168 dbg("bIrdaRateSniff=%x", desc->bIrdaRateSniff); 151 dbg("bIrdaRateSniff=%x", desc->bIrdaRateSniff);
169 dbg("bMaxUnicastList=%x", desc->bMaxUnicastList); 152 dbg("bMaxUnicastList=%x", desc->bMaxUnicastList);
@@ -181,35 +164,37 @@ static inline void irda_usb_dump_class_desc(struct irda_class_desc *desc)
181 * 164 *
182 * Based on the same function in drivers/net/irda/irda-usb.c 165 * Based on the same function in drivers/net/irda/irda-usb.c
183 */ 166 */
184static struct irda_class_desc *irda_usb_find_class_desc(struct usb_device *dev, unsigned int ifnum) 167static struct usb_irda_cs_descriptor *
168irda_usb_find_class_desc(struct usb_device *dev, unsigned int ifnum)
185{ 169{
186 struct irda_class_desc *desc; 170 struct usb_irda_cs_descriptor *desc;
187 int ret; 171 int ret;
188 172
189 desc = kzalloc(sizeof (struct irda_class_desc), GFP_KERNEL); 173 desc = kzalloc(sizeof(*desc), GFP_KERNEL);
190 if (desc == NULL) 174 if (!desc)
191 return NULL; 175 return NULL;
192 176
193 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev,0), 177 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
194 IU_REQ_GET_CLASS_DESC, 178 USB_REQ_CS_IRDA_GET_CLASS_DESC,
195 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 179 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
196 0, ifnum, desc, sizeof(*desc), 1000); 180 0, ifnum, desc, sizeof(*desc), 1000);
197 181
198 dbg("%s - ret=%d", __func__, ret); 182 dbg("%s - ret=%d", __func__, ret);
199 if (ret < sizeof(*desc)) { 183 if (ret < sizeof(*desc)) {
200 dbg("%s - class descriptor read %s (%d)", 184 dbg("%s - class descriptor read %s (%d)",
201 __func__, 185 __func__,
202 (ret<0) ? "failed" : "too short", 186 (ret < 0) ? "failed" : "too short",
203 ret); 187 ret);
204 goto error; 188 goto error;
205 } 189 }
206 if (desc->bDescriptorType != USB_DT_IRDA) { 190 if (desc->bDescriptorType != USB_DT_CS_IRDA) {
207 dbg("%s - bad class descriptor type", __func__); 191 dbg("%s - bad class descriptor type", __func__);
208 goto error; 192 goto error;
209 } 193 }
210 194
211 irda_usb_dump_class_desc(desc); 195 irda_usb_dump_class_desc(desc);
212 return desc; 196 return desc;
197
213error: 198error:
214 kfree(desc); 199 kfree(desc);
215 return NULL; 200 return NULL;
@@ -219,64 +204,101 @@ error:
219static u8 ir_xbof_change(u8 xbof) 204static u8 ir_xbof_change(u8 xbof)
220{ 205{
221 u8 result; 206 u8 result;
207
222 /* reference irda-usb.c */ 208 /* reference irda-usb.c */
223 switch(xbof) { 209 switch (xbof) {
224 case 48: result = 0x10; break; 210 case 48:
225 case 28: 211 result = 0x10;
226 case 24: result = 0x20; break; 212 break;
227 default: 213 case 28:
228 case 12: result = 0x30; break; 214 case 24:
229 case 5: 215 result = 0x20;
230 case 6: result = 0x40; break; 216 break;
231 case 3: result = 0x50; break; 217 default:
232 case 2: result = 0x60; break; 218 case 12:
233 case 1: result = 0x70; break; 219 result = 0x30;
234 case 0: result = 0x80; break; 220 break;
221 case 5:
222 case 6:
223 result = 0x40;
224 break;
225 case 3:
226 result = 0x50;
227 break;
228 case 2:
229 result = 0x60;
230 break;
231 case 1:
232 result = 0x70;
233 break;
234 case 0:
235 result = 0x80;
236 break;
235 } 237 }
238
236 return(result); 239 return(result);
237} 240}
238 241
239 242
240static int ir_startup (struct usb_serial *serial) 243static int ir_startup(struct usb_serial *serial)
241{ 244{
242 struct irda_class_desc *irda_desc; 245 struct usb_irda_cs_descriptor *irda_desc;
243 246
244 irda_desc = irda_usb_find_class_desc (serial->dev, 0); 247 irda_desc = irda_usb_find_class_desc(serial->dev, 0);
245 if (irda_desc == NULL) { 248 if (!irda_desc) {
246 dev_err (&serial->dev->dev, "IRDA class descriptor not found, device not bound\n"); 249 dev_err(&serial->dev->dev,
250 "IRDA class descriptor not found, device not bound\n");
247 return -ENODEV; 251 return -ENODEV;
248 } 252 }
249 253
250 dbg ("%s - Baud rates supported:%s%s%s%s%s%s%s%s%s", 254 dbg("%s - Baud rates supported:%s%s%s%s%s%s%s%s%s",
251 __func__, 255 __func__,
252 (irda_desc->wBaudRate & 0x0001) ? " 2400" : "", 256 (irda_desc->wBaudRate & USB_IRDA_BR_2400) ? " 2400" : "",
253 (irda_desc->wBaudRate & 0x0002) ? " 9600" : "", 257 (irda_desc->wBaudRate & USB_IRDA_BR_9600) ? " 9600" : "",
254 (irda_desc->wBaudRate & 0x0004) ? " 19200" : "", 258 (irda_desc->wBaudRate & USB_IRDA_BR_19200) ? " 19200" : "",
255 (irda_desc->wBaudRate & 0x0008) ? " 38400" : "", 259 (irda_desc->wBaudRate & USB_IRDA_BR_38400) ? " 38400" : "",
256 (irda_desc->wBaudRate & 0x0010) ? " 57600" : "", 260 (irda_desc->wBaudRate & USB_IRDA_BR_57600) ? " 57600" : "",
257 (irda_desc->wBaudRate & 0x0020) ? " 115200" : "", 261 (irda_desc->wBaudRate & USB_IRDA_BR_115200) ? " 115200" : "",
258 (irda_desc->wBaudRate & 0x0040) ? " 576000" : "", 262 (irda_desc->wBaudRate & USB_IRDA_BR_576000) ? " 576000" : "",
259 (irda_desc->wBaudRate & 0x0080) ? " 1152000" : "", 263 (irda_desc->wBaudRate & USB_IRDA_BR_1152000) ? " 1152000" : "",
260 (irda_desc->wBaudRate & 0x0100) ? " 4000000" : ""); 264 (irda_desc->wBaudRate & USB_IRDA_BR_4000000) ? " 4000000" : "");
261 265
262 switch( irda_desc->bmAdditionalBOFs ) { 266 switch (irda_desc->bmAdditionalBOFs) {
263 case 0x01: ir_add_bof = 48; break; 267 case USB_IRDA_AB_48:
264 case 0x02: ir_add_bof = 24; break; 268 ir_add_bof = 48;
265 case 0x04: ir_add_bof = 12; break; 269 break;
266 case 0x08: ir_add_bof = 6; break; 270 case USB_IRDA_AB_24:
267 case 0x10: ir_add_bof = 3; break; 271 ir_add_bof = 24;
268 case 0x20: ir_add_bof = 2; break; 272 break;
269 case 0x40: ir_add_bof = 1; break; 273 case USB_IRDA_AB_12:
270 case 0x80: ir_add_bof = 0; break; 274 ir_add_bof = 12;
271 default:; 275 break;
276 case USB_IRDA_AB_6:
277 ir_add_bof = 6;
278 break;
279 case USB_IRDA_AB_3:
280 ir_add_bof = 3;
281 break;
282 case USB_IRDA_AB_2:
283 ir_add_bof = 2;
284 break;
285 case USB_IRDA_AB_1:
286 ir_add_bof = 1;
287 break;
288 case USB_IRDA_AB_0:
289 ir_add_bof = 0;
290 break;
291 default:
292 break;
272 } 293 }
273 294
274 kfree (irda_desc); 295 kfree(irda_desc);
275 296
276 return 0; 297 return 0;
277} 298}
278 299
279static int ir_open (struct usb_serial_port *port, struct file *filp) 300static int ir_open(struct tty_struct *tty,
301 struct usb_serial_port *port, struct file *filp)
280{ 302{
281 char *buffer; 303 char *buffer;
282 int result = 0; 304 int result = 0;
@@ -285,51 +307,56 @@ static int ir_open (struct usb_serial_port *port, struct file *filp)
285 307
286 if (buffer_size) { 308 if (buffer_size) {
287 /* override the default buffer sizes */ 309 /* override the default buffer sizes */
288 buffer = kmalloc (buffer_size, GFP_KERNEL); 310 buffer = kmalloc(buffer_size, GFP_KERNEL);
289 if (!buffer) { 311 if (!buffer) {
290 dev_err (&port->dev, "%s - out of memory.\n", __func__); 312 dev_err(&port->dev, "%s - out of memory.\n", __func__);
291 return -ENOMEM; 313 return -ENOMEM;
292 } 314 }
293 kfree (port->read_urb->transfer_buffer); 315 kfree(port->read_urb->transfer_buffer);
294 port->read_urb->transfer_buffer = buffer; 316 port->read_urb->transfer_buffer = buffer;
295 port->read_urb->transfer_buffer_length = buffer_size; 317 port->read_urb->transfer_buffer_length = buffer_size;
296 318
297 buffer = kmalloc (buffer_size, GFP_KERNEL); 319 buffer = kmalloc(buffer_size, GFP_KERNEL);
298 if (!buffer) { 320 if (!buffer) {
299 dev_err (&port->dev, "%s - out of memory.\n", __func__); 321 dev_err(&port->dev, "%s - out of memory.\n", __func__);
300 return -ENOMEM; 322 return -ENOMEM;
301 } 323 }
302 kfree (port->write_urb->transfer_buffer); 324 kfree(port->write_urb->transfer_buffer);
303 port->write_urb->transfer_buffer = buffer; 325 port->write_urb->transfer_buffer = buffer;
304 port->write_urb->transfer_buffer_length = buffer_size; 326 port->write_urb->transfer_buffer_length = buffer_size;
305 port->bulk_out_size = buffer_size; 327 port->bulk_out_size = buffer_size;
306 } 328 }
307 329
308 /* Start reading from the device */ 330 /* Start reading from the device */
309 usb_fill_bulk_urb ( 331 usb_fill_bulk_urb(
310 port->read_urb, 332 port->read_urb,
311 port->serial->dev, 333 port->serial->dev,
312 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), 334 usb_rcvbulkpipe(port->serial->dev,
335 port->bulk_in_endpointAddress),
313 port->read_urb->transfer_buffer, 336 port->read_urb->transfer_buffer,
314 port->read_urb->transfer_buffer_length, 337 port->read_urb->transfer_buffer_length,
315 ir_read_bulk_callback, 338 ir_read_bulk_callback,
316 port); 339 port);
317 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 340 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
318 if (result) 341 if (result)
319 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 342 dev_err(&port->dev,
343 "%s - failed submitting read urb, error %d\n",
344 __func__, result);
320 345
321 return result; 346 return result;
322} 347}
323 348
324static void ir_close (struct usb_serial_port *port, struct file * filp) 349static void ir_close(struct tty_struct *tty,
350 struct usb_serial_port *port, struct file * filp)
325{ 351{
326 dbg("%s - port %d", __func__, port->number); 352 dbg("%s - port %d", __func__, port->number);
327 353
328 /* shutdown our bulk read */ 354 /* shutdown our bulk read */
329 usb_kill_urb(port->read_urb); 355 usb_kill_urb(port->read_urb);
330} 356}
331 357
332static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int count) 358static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
359 const unsigned char *buf, int count)
333{ 360{
334 unsigned char *transfer_buffer; 361 unsigned char *transfer_buffer;
335 int result; 362 int result;
@@ -337,11 +364,6 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
337 364
338 dbg("%s - port = %d, count = %d", __func__, port->number, count); 365 dbg("%s - port = %d, count = %d", __func__, port->number, count);
339 366
340 if (!port->tty) {
341 dev_err (&port->dev, "%s - no tty???\n", __func__);
342 return 0;
343 }
344
345 if (count == 0) 367 if (count == 0)
346 return 0; 368 return 0;
347 369
@@ -359,7 +381,7 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
359 381
360 /* 382 /*
361 * The first byte of the packet we send to the device contains an 383 * The first byte of the packet we send to the device contains an
362 * inband header which indicates an additional number of BOFs and 384 * inbound header which indicates an additional number of BOFs and
363 * a baud rate change. 385 * a baud rate change.
364 * 386 *
365 * See section 5.4.2.2 of the USB IrDA spec. 387 * See section 5.4.2.2 of the USB IrDA spec.
@@ -367,9 +389,9 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
367 *transfer_buffer = ir_xbof | ir_baud; 389 *transfer_buffer = ir_xbof | ir_baud;
368 ++transfer_buffer; 390 ++transfer_buffer;
369 391
370 memcpy (transfer_buffer, buf, transfer_size); 392 memcpy(transfer_buffer, buf, transfer_size);
371 393
372 usb_fill_bulk_urb ( 394 usb_fill_bulk_urb(
373 port->write_urb, 395 port->write_urb,
374 port->serial->dev, 396 port->serial->dev,
375 usb_sndbulkpipe(port->serial->dev, 397 usb_sndbulkpipe(port->serial->dev,
@@ -381,17 +403,19 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
381 403
382 port->write_urb->transfer_flags = URB_ZERO_PACKET; 404 port->write_urb->transfer_flags = URB_ZERO_PACKET;
383 405
384 result = usb_submit_urb (port->write_urb, GFP_ATOMIC); 406 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
385 if (result) { 407 if (result) {
386 port->write_urb_busy = 0; 408 port->write_urb_busy = 0;
387 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); 409 dev_err(&port->dev,
410 "%s - failed submitting write urb, error %d\n",
411 __func__, result);
388 } else 412 } else
389 result = transfer_size; 413 result = transfer_size;
390 414
391 return result; 415 return result;
392} 416}
393 417
394static void ir_write_bulk_callback (struct urb *urb) 418static void ir_write_bulk_callback(struct urb *urb)
395{ 419{
396 struct usb_serial_port *port = urb->context; 420 struct usb_serial_port *port = urb->context;
397 int status = urb->status; 421 int status = urb->status;
@@ -405,7 +429,7 @@ static void ir_write_bulk_callback (struct urb *urb)
405 return; 429 return;
406 } 430 }
407 431
408 usb_serial_debug_data ( 432 usb_serial_debug_data(
409 debug, 433 debug,
410 &port->dev, 434 &port->dev,
411 __func__, 435 __func__,
@@ -415,7 +439,7 @@ static void ir_write_bulk_callback (struct urb *urb)
415 usb_serial_port_softint(port); 439 usb_serial_port_softint(port);
416} 440}
417 441
418static void ir_read_bulk_callback (struct urb *urb) 442static void ir_read_bulk_callback(struct urb *urb)
419{ 443{
420 struct usb_serial_port *port = urb->context; 444 struct usb_serial_port *port = urb->context;
421 struct tty_struct *tty; 445 struct tty_struct *tty;
@@ -425,74 +449,61 @@ static void ir_read_bulk_callback (struct urb *urb)
425 449
426 dbg("%s - port %d", __func__, port->number); 450 dbg("%s - port %d", __func__, port->number);
427 451
428 if (!port->open_count) { 452 if (!port->port.count) {
429 dbg("%s - port closed.", __func__); 453 dbg("%s - port closed.", __func__);
430 return; 454 return;
431 } 455 }
432 456
433 switch (status) { 457 switch (status) {
434 case 0: /* Successful */ 458 case 0: /* Successful */
435 459 /*
436 /* 460 * The first byte of the packet we get from the device
437 * The first byte of the packet we get from the device 461 * contains a busy indicator and baud rate change.
438 * contains a busy indicator and baud rate change. 462 * See section 5.4.1.2 of the USB IrDA spec.
439 * See section 5.4.1.2 of the USB IrDA spec. 463 */
440 */ 464 if ((*data & 0x0f) > 0)
441 if ((*data & 0x0f) > 0) 465 ir_baud = *data & 0x0f;
442 ir_baud = *data & 0x0f; 466 usb_serial_debug_data(debug, &port->dev, __func__,
443 467 urb->actual_length, data);
444 usb_serial_debug_data ( 468 tty = port->port.tty;
445 debug, 469 if (tty_buffer_request_room(tty, urb->actual_length - 1)) {
446 &port->dev, 470 tty_insert_flip_string(tty, data+1, urb->actual_length - 1);
447 __func__, 471 tty_flip_buffer_push(tty);
448 urb->actual_length, 472 }
449 data);
450
451 tty = port->tty;
452
453 if (tty_buffer_request_room(tty, urb->actual_length - 1)) {
454 tty_insert_flip_string(tty, data+1, urb->actual_length - 1);
455 tty_flip_buffer_push(tty);
456 }
457
458 /*
459 * No break here.
460 * We want to resubmit the urb so we can read
461 * again.
462 */
463 473
464 case -EPROTO: /* taking inspiration from pl2303.c */ 474 /*
475 * No break here.
476 * We want to resubmit the urb so we can read
477 * again.
478 */
465 479
480 case -EPROTO: /* taking inspiration from pl2303.c */
466 /* Continue trying to always read */ 481 /* Continue trying to always read */
467 usb_fill_bulk_urb ( 482 usb_fill_bulk_urb(
468 port->read_urb, 483 port->read_urb,
469 port->serial->dev, 484 port->serial->dev,
470 usb_rcvbulkpipe(port->serial->dev, 485 usb_rcvbulkpipe(port->serial->dev,
471 port->bulk_in_endpointAddress), 486 port->bulk_in_endpointAddress),
472 port->read_urb->transfer_buffer, 487 port->read_urb->transfer_buffer,
473 port->read_urb->transfer_buffer_length, 488 port->read_urb->transfer_buffer_length,
474 ir_read_bulk_callback, 489 ir_read_bulk_callback,
475 port); 490 port);
476 491
477 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 492 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
478 if (result) 493 if (result)
479 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", 494 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n",
480 __func__, result); 495 __func__, result);
481
482 break ;
483
484 default:
485 dbg("%s - nonzero read bulk status received: %d",
486 __func__,
487 status);
488 break ; 496 break ;
489 497 default:
498 dbg("%s - nonzero read bulk status received: %d",
499 __func__, status);
500 break ;
490 } 501 }
491
492 return; 502 return;
493} 503}
494 504
495static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 505static void ir_set_termios(struct tty_struct *tty,
506 struct usb_serial_port *port, struct ktermios *old_termios)
496{ 507{
497 unsigned char *transfer_buffer; 508 unsigned char *transfer_buffer;
498 int result; 509 int result;
@@ -501,7 +512,7 @@ static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_t
501 512
502 dbg("%s - port %d", __func__, port->number); 513 dbg("%s - port %d", __func__, port->number);
503 514
504 baud = tty_get_baud_rate(port->tty); 515 baud = tty_get_baud_rate(tty);
505 516
506 /* 517 /*
507 * FIXME, we should compare the baud request against the 518 * FIXME, we should compare the baud request against the
@@ -510,19 +521,36 @@ static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_t
510 */ 521 */
511 522
512 switch (baud) { 523 switch (baud) {
513 case 2400: ir_baud = SPEED_2400; break; 524 case 2400:
514 case 9600: ir_baud = SPEED_9600; break; 525 ir_baud = USB_IRDA_BR_2400;
515 case 19200: ir_baud = SPEED_19200; break; 526 break;
516 case 38400: ir_baud = SPEED_38400; break; 527 case 9600:
517 case 57600: ir_baud = SPEED_57600; break; 528 ir_baud = USB_IRDA_BR_9600;
518 case 115200: ir_baud = SPEED_115200; break; 529 break;
519 case 576000: ir_baud = SPEED_576000; break; 530 case 19200:
520 case 1152000: ir_baud = SPEED_1152000; break; 531 ir_baud = USB_IRDA_BR_19200;
521 case 4000000: ir_baud = SPEED_4000000; break; 532 break;
522 break; 533 case 38400:
523 default: 534 ir_baud = USB_IRDA_BR_38400;
524 ir_baud = SPEED_9600; 535 break;
525 baud = 9600; 536 case 57600:
537 ir_baud = USB_IRDA_BR_57600;
538 break;
539 case 115200:
540 ir_baud = USB_IRDA_BR_115200;
541 break;
542 case 576000:
543 ir_baud = USB_IRDA_BR_576000;
544 break;
545 case 1152000:
546 ir_baud = USB_IRDA_BR_1152000;
547 break;
548 case 4000000:
549 ir_baud = USB_IRDA_BR_4000000;
550 break;
551 default:
552 ir_baud = USB_IRDA_BR_9600;
553 baud = 9600;
526 } 554 }
527 555
528 if (xbof == -1) 556 if (xbof == -1)
@@ -538,10 +566,11 @@ static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_t
538 transfer_buffer = port->write_urb->transfer_buffer; 566 transfer_buffer = port->write_urb->transfer_buffer;
539 *transfer_buffer = ir_xbof | ir_baud; 567 *transfer_buffer = ir_xbof | ir_baud;
540 568
541 usb_fill_bulk_urb ( 569 usb_fill_bulk_urb(
542 port->write_urb, 570 port->write_urb,
543 port->serial->dev, 571 port->serial->dev,
544 usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), 572 usb_sndbulkpipe(port->serial->dev,
573 port->bulk_out_endpointAddress),
545 port->write_urb->transfer_buffer, 574 port->write_urb->transfer_buffer,
546 1, 575 1,
547 ir_write_bulk_callback, 576 ir_write_bulk_callback,
@@ -549,38 +578,44 @@ static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_t
549 578
550 port->write_urb->transfer_flags = URB_ZERO_PACKET; 579 port->write_urb->transfer_flags = URB_ZERO_PACKET;
551 580
552 result = usb_submit_urb (port->write_urb, GFP_KERNEL); 581 result = usb_submit_urb(port->write_urb, GFP_KERNEL);
553 if (result) 582 if (result)
554 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); 583 dev_err(&port->dev,
584 "%s - failed submitting write urb, error %d\n",
585 __func__, result);
555 586
556 /* Only speed changes are supported */ 587 /* Only speed changes are supported */
557 tty_termios_copy_hw(port->tty->termios, old_termios); 588 tty_termios_copy_hw(tty->termios, old_termios);
558 tty_encode_baud_rate(port->tty, baud, baud); 589 tty_encode_baud_rate(tty, baud, baud);
559} 590}
560 591
561 592static int __init ir_init(void)
562static int __init ir_init (void)
563{ 593{
564 int retval; 594 int retval;
595
565 retval = usb_serial_register(&ir_device); 596 retval = usb_serial_register(&ir_device);
566 if (retval) 597 if (retval)
567 goto failed_usb_serial_register; 598 goto failed_usb_serial_register;
599
568 retval = usb_register(&ir_driver); 600 retval = usb_register(&ir_driver);
569 if (retval) 601 if (retval)
570 goto failed_usb_register; 602 goto failed_usb_register;
603
571 info(DRIVER_DESC " " DRIVER_VERSION); 604 info(DRIVER_DESC " " DRIVER_VERSION);
605
572 return 0; 606 return 0;
607
573failed_usb_register: 608failed_usb_register:
574 usb_serial_deregister(&ir_device); 609 usb_serial_deregister(&ir_device);
610
575failed_usb_serial_register: 611failed_usb_serial_register:
576 return retval; 612 return retval;
577} 613}
578 614
579 615static void __exit ir_exit(void)
580static void __exit ir_exit (void)
581{ 616{
582 usb_deregister (&ir_driver); 617 usb_deregister(&ir_driver);
583 usb_serial_deregister (&ir_device); 618 usb_serial_deregister(&ir_device);
584} 619}
585 620
586 621
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index a01e987c7d32..ddff37fa6339 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -144,9 +144,10 @@ static void iuu_shutdown(struct usb_serial *serial)
144 } 144 }
145} 145}
146 146
147static int iuu_tiocmset(struct usb_serial_port *port, struct file *file, 147static int iuu_tiocmset(struct tty_struct *tty, struct file *file,
148 unsigned int set, unsigned int clear) 148 unsigned int set, unsigned int clear)
149{ 149{
150 struct usb_serial_port *port = tty->driver_data;
150 struct iuu_private *priv = usb_get_serial_port_data(port); 151 struct iuu_private *priv = usb_get_serial_port_data(port);
151 unsigned long flags; 152 unsigned long flags;
152 153
@@ -171,8 +172,9 @@ static int iuu_tiocmset(struct usb_serial_port *port, struct file *file,
171 * When no card , the reader respond with TIOCM_CD 172 * When no card , the reader respond with TIOCM_CD
172 * This is known as CD autodetect mechanism 173 * This is known as CD autodetect mechanism
173 */ 174 */
174static int iuu_tiocmget(struct usb_serial_port *port, struct file *file) 175static int iuu_tiocmget(struct tty_struct *tty, struct file *file)
175{ 176{
177 struct usb_serial_port *port = tty->driver_data;
176 struct iuu_private *priv = usb_get_serial_port_data(port); 178 struct iuu_private *priv = usb_get_serial_port_data(port);
177 unsigned long flags; 179 unsigned long flags;
178 int rc; 180 int rc;
@@ -316,11 +318,10 @@ static int bulk_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
316 port->bulk_out_endpointAddress), buf, 318 port->bulk_out_endpointAddress), buf,
317 count, &actual, HZ * 1); 319 count, &actual, HZ * 1);
318 320
319 if (status != IUU_OPERATION_OK) { 321 if (status != IUU_OPERATION_OK)
320 dbg("%s - error = %2x", __func__, status); 322 dbg("%s - error = %2x", __func__, status);
321 } else { 323 else
322 dbg("%s - write OK !", __func__); 324 dbg("%s - write OK !", __func__);
323 }
324 return status; 325 return status;
325} 326}
326 327
@@ -340,12 +341,10 @@ static int read_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
340 port->bulk_in_endpointAddress), buf, 341 port->bulk_in_endpointAddress), buf,
341 count, &actual, HZ * 1); 342 count, &actual, HZ * 1);
342 343
343 if (status != IUU_OPERATION_OK) { 344 if (status != IUU_OPERATION_OK)
344 dbg("%s - error = %2x", __func__, status); 345 dbg("%s - error = %2x", __func__, status);
345 } else { 346 else
346 dbg("%s - read OK !", __func__); 347 dbg("%s - read OK !", __func__);
347 }
348
349 return status; 348 return status;
350} 349}
351 350
@@ -630,7 +629,7 @@ static void read_buf_callback(struct urb *urb)
630 } 629 }
631 630
632 dbg("%s - %i chars to write", __func__, urb->actual_length); 631 dbg("%s - %i chars to write", __func__, urb->actual_length);
633 tty = port->tty; 632 tty = port->port.tty;
634 if (data == NULL) 633 if (data == NULL)
635 dbg("%s - data is NULL !!!", __func__); 634 dbg("%s - data is NULL !!!", __func__);
636 if (tty && urb->actual_length && data) { 635 if (tty && urb->actual_length && data) {
@@ -752,11 +751,10 @@ static void iuu_uart_read_callback(struct urb *urb)
752 /* if nothing to write call again rxcmd */ 751 /* if nothing to write call again rxcmd */
753 dbg("%s - rxcmd recall", __func__); 752 dbg("%s - rxcmd recall", __func__);
754 iuu_led_activity_off(urb); 753 iuu_led_activity_off(urb);
755 return;
756} 754}
757 755
758static int iuu_uart_write(struct usb_serial_port *port, const u8 *buf, 756static int iuu_uart_write(struct tty_struct *tty, struct usb_serial_port *port,
759 int count) 757 const u8 *buf, int count)
760{ 758{
761 struct iuu_private *priv = usb_get_serial_port_data(port); 759 struct iuu_private *priv = usb_get_serial_port_data(port);
762 unsigned long flags; 760 unsigned long flags;
@@ -769,14 +767,14 @@ static int iuu_uart_write(struct usb_serial_port *port, const u8 *buf,
769 if (priv->writelen > 0) { 767 if (priv->writelen > 0) {
770 /* buffer already filled but not commited */ 768 /* buffer already filled but not commited */
771 spin_unlock_irqrestore(&priv->lock, flags); 769 spin_unlock_irqrestore(&priv->lock, flags);
772 return (0); 770 return 0;
773 } 771 }
774 /* fill the buffer */ 772 /* fill the buffer */
775 memcpy(priv->writebuf, buf, count); 773 memcpy(priv->writebuf, buf, count);
776 priv->writelen = count; 774 priv->writelen = count;
777 spin_unlock_irqrestore(&priv->lock, flags); 775 spin_unlock_irqrestore(&priv->lock, flags);
778 776
779 return (count); 777 return count;
780} 778}
781 779
782static void read_rxcmd_callback(struct urb *urb) 780static void read_rxcmd_callback(struct urb *urb)
@@ -948,7 +946,8 @@ static int set_control_lines(struct usb_device *dev, u8 value)
948 return 0; 946 return 0;
949} 947}
950 948
951static void iuu_close(struct usb_serial_port *port, struct file *filp) 949static void iuu_close(struct tty_struct *tty,
950 struct usb_serial_port *port, struct file *filp)
952{ 951{
953 /* iuu_led (port,255,0,0,0); */ 952 /* iuu_led (port,255,0,0,0); */
954 struct usb_serial *serial; 953 struct usb_serial *serial;
@@ -964,8 +963,8 @@ static void iuu_close(struct usb_serial_port *port, struct file *filp)
964 963
965 iuu_uart_off(port); 964 iuu_uart_off(port);
966 if (serial->dev) { 965 if (serial->dev) {
967 if (port->tty) { 966 if (tty) {
968 c_cflag = port->tty->termios->c_cflag; 967 c_cflag = tty->termios->c_cflag;
969 if (c_cflag & HUPCL) { 968 if (c_cflag & HUPCL) {
970 /* drop DTR and RTS */ 969 /* drop DTR and RTS */
971 priv = usb_get_serial_port_data(port); 970 priv = usb_get_serial_port_data(port);
@@ -989,7 +988,8 @@ static void iuu_close(struct usb_serial_port *port, struct file *filp)
989 } 988 }
990} 989}
991 990
992static int iuu_open(struct usb_serial_port *port, struct file *filp) 991static int iuu_open(struct tty_struct *tty,
992 struct usb_serial_port *port, struct file *filp)
993{ 993{
994 struct usb_serial *serial = port->serial; 994 struct usb_serial *serial = port->serial;
995 u8 *buf; 995 u8 *buf;
@@ -1036,15 +1036,17 @@ static int iuu_open(struct usb_serial_port *port, struct file *filp)
1036 1036
1037 /* set the termios structure */ 1037 /* set the termios structure */
1038 spin_lock_irqsave(&priv->lock, flags); 1038 spin_lock_irqsave(&priv->lock, flags);
1039 if (!priv->termios_initialized) { 1039 if (tty && !priv->termios_initialized) {
1040 *(port->tty->termios) = tty_std_termios; 1040 *(tty->termios) = tty_std_termios;
1041 port->tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600 1041 tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600
1042 | TIOCM_CTS | CSTOPB | PARENB; 1042 | TIOCM_CTS | CSTOPB | PARENB;
1043 port->tty->termios->c_lflag = 0; 1043 tty->termios->c_ispeed = 9600;
1044 port->tty->termios->c_oflag = 0; 1044 tty->termios->c_ospeed = 9600;
1045 port->tty->termios->c_iflag = 0; 1045 tty->termios->c_lflag = 0;
1046 tty->termios->c_oflag = 0;
1047 tty->termios->c_iflag = 0;
1046 priv->termios_initialized = 1; 1048 priv->termios_initialized = 1;
1047 port->tty->low_latency = 1; 1049 tty->low_latency = 1;
1048 priv->poll = 0; 1050 priv->poll = 0;
1049 } 1051 }
1050 spin_unlock_irqrestore(&priv->lock, flags); 1052 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1148,7 +1150,7 @@ static int iuu_open(struct usb_serial_port *port, struct file *filp)
1148 if (result) { 1150 if (result) {
1149 dev_err(&port->dev, "%s - failed submitting read urb," 1151 dev_err(&port->dev, "%s - failed submitting read urb,"
1150 " error %d\n", __func__, result); 1152 " error %d\n", __func__, result);
1151 iuu_close(port, NULL); 1153 iuu_close(tty, port, NULL);
1152 return -EPROTO; 1154 return -EPROTO;
1153 } else { 1155 } else {
1154 dbg("%s - rxcmd OK", __func__); 1156 dbg("%s - rxcmd OK", __func__);
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 11e439b90eac..704716f6f6d3 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -1,29 +1,29 @@
1/* 1/*
2 Keyspan USB to Serial Converter driver 2 Keyspan USB to Serial Converter driver
3 3
4 (C) Copyright (C) 2000-2001 Hugh Blemings <hugh@blemings.org> 4 (C) Copyright (C) 2000-2001 Hugh Blemings <hugh@blemings.org>
5 (C) Copyright (C) 2002 Greg Kroah-Hartman <greg@kroah.com> 5 (C) Copyright (C) 2002 Greg Kroah-Hartman <greg@kroah.com>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 See http://misc.nu/hugh/keyspan.html for more information. 12 See http://misc.nu/hugh/keyspan.html for more information.
13 13
14 Code in this driver inspired by and in a number of places taken 14 Code in this driver inspired by and in a number of places taken
15 from Brian Warner's original Keyspan-PDA driver. 15 from Brian Warner's original Keyspan-PDA driver.
16 16
17 This driver has been put together with the support of Innosys, Inc. 17 This driver has been put together with the support of Innosys, Inc.
18 and Keyspan, Inc the manufacturers of the Keyspan USB-serial products. 18 and Keyspan, Inc the manufacturers of the Keyspan USB-serial products.
19 Thanks Guys :) 19 Thanks Guys :)
20 20
21 Thanks to Paulus for miscellaneous tidy ups, some largish chunks 21 Thanks to Paulus for miscellaneous tidy ups, some largish chunks
22 of much nicer and/or completely new code and (perhaps most uniquely) 22 of much nicer and/or completely new code and (perhaps most uniquely)
23 having the patience to sit down and explain why and where he'd changed 23 having the patience to sit down and explain why and where he'd changed
24 stuff. 24 stuff.
25 25
26 Tip 'o the hat to IBM (and previously Linuxcare :) for supporting 26 Tip 'o the hat to IBM (and previously Linuxcare :) for supporting
27 staff in their work on open source projects. 27 staff in their work on open source projects.
28 28
29 Change History 29 Change History
@@ -70,21 +70,21 @@
70 70
71 Thu May 31 11:56:42 PDT 2001 gkh 71 Thu May 31 11:56:42 PDT 2001 gkh
72 switched from using spinlock to a semaphore 72 switched from using spinlock to a semaphore
73 73
74 (04/08/2001) gb 74 (04/08/2001) gb
75 Identify version on module load. 75 Identify version on module load.
76 76
77 (11/01/2000) Adam J. Richter 77 (11/01/2000) Adam J. Richter
78 usb_device_id table support. 78 usb_device_id table support.
79 79
80 Tue Oct 10 23:15:33 EST 2000 Hugh 80 Tue Oct 10 23:15:33 EST 2000 Hugh
81 Merged Paul's changes with my USA-49W mods. Work in progress 81 Merged Paul's changes with my USA-49W mods. Work in progress
82 still... 82 still...
83 83
84 Wed Jul 19 14:00:42 EST 2000 gkh 84 Wed Jul 19 14:00:42 EST 2000 gkh
85 Added module_init and module_exit functions to handle the fact that 85 Added module_init and module_exit functions to handle the fact that
86 this driver is a loadable module now. 86 this driver is a loadable module now.
87 87
88 Tue Jul 18 16:14:52 EST 2000 Hugh 88 Tue Jul 18 16:14:52 EST 2000 Hugh
89 Basic character input/output for USA-19 now mostly works, 89 Basic character input/output for USA-19 now mostly works,
90 fixed at 9600 baud for the moment. 90 fixed at 9600 baud for the moment.
@@ -107,7 +107,7 @@
107#include <linux/spinlock.h> 107#include <linux/spinlock.h>
108#include <linux/firmware.h> 108#include <linux/firmware.h>
109#include <linux/ihex.h> 109#include <linux/ihex.h>
110#include <asm/uaccess.h> 110#include <linux/uaccess.h>
111#include <linux/usb.h> 111#include <linux/usb.h>
112#include <linux/usb/serial.h> 112#include <linux/usb/serial.h>
113#include "keyspan.h" 113#include "keyspan.h"
@@ -132,15 +132,15 @@ struct keyspan_serial_private {
132 struct urb *instat_urb; 132 struct urb *instat_urb;
133 char instat_buf[INSTAT_BUFLEN]; 133 char instat_buf[INSTAT_BUFLEN];
134 134
135 /* added to support 49wg, where data from all 4 ports comes in on 1 EP */ 135 /* added to support 49wg, where data from all 4 ports comes in
136 /* and high-speed supported */ 136 on 1 EP and high-speed supported */
137 struct urb *indat_urb; 137 struct urb *indat_urb;
138 char indat_buf[INDAT49W_BUFLEN]; 138 char indat_buf[INDAT49W_BUFLEN];
139 139
140 /* XXX this one probably will need a lock */ 140 /* XXX this one probably will need a lock */
141 struct urb *glocont_urb; 141 struct urb *glocont_urb;
142 char glocont_buf[GLOCONT_BUFLEN]; 142 char glocont_buf[GLOCONT_BUFLEN];
143 char ctrl_buf[8]; // for EP0 control message 143 char ctrl_buf[8]; /* for EP0 control message */
144}; 144};
145 145
146struct keyspan_port_private { 146struct keyspan_port_private {
@@ -186,19 +186,19 @@ struct keyspan_port_private {
186 int resend_cont; /* need to resend control packet */ 186 int resend_cont; /* need to resend control packet */
187}; 187};
188 188
189
190/* Include Keyspan message headers. All current Keyspan Adapters 189/* Include Keyspan message headers. All current Keyspan Adapters
191 make use of one of five message formats which are referred 190 make use of one of five message formats which are referred
192 to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and within this driver. */ 191 to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and
192 within this driver. */
193#include "keyspan_usa26msg.h" 193#include "keyspan_usa26msg.h"
194#include "keyspan_usa28msg.h" 194#include "keyspan_usa28msg.h"
195#include "keyspan_usa49msg.h" 195#include "keyspan_usa49msg.h"
196#include "keyspan_usa90msg.h" 196#include "keyspan_usa90msg.h"
197#include "keyspan_usa67msg.h" 197#include "keyspan_usa67msg.h"
198 198
199 199
200/* Functions used by new usb-serial code. */ 200/* Functions used by new usb-serial code. */
201static int __init keyspan_init (void) 201static int __init keyspan_init(void)
202{ 202{
203 int retval; 203 int retval;
204 retval = usb_serial_register(&keyspan_pre_device); 204 retval = usb_serial_register(&keyspan_pre_device);
@@ -214,7 +214,7 @@ static int __init keyspan_init (void)
214 if (retval) 214 if (retval)
215 goto failed_4port_device_register; 215 goto failed_4port_device_register;
216 retval = usb_register(&keyspan_driver); 216 retval = usb_register(&keyspan_driver);
217 if (retval) 217 if (retval)
218 goto failed_usb_register; 218 goto failed_usb_register;
219 219
220 info(DRIVER_VERSION ":" DRIVER_DESC); 220 info(DRIVER_VERSION ":" DRIVER_DESC);
@@ -232,35 +232,24 @@ failed_pre_device_register:
232 return retval; 232 return retval;
233} 233}
234 234
235static void __exit keyspan_exit (void) 235static void __exit keyspan_exit(void)
236{ 236{
237 usb_deregister (&keyspan_driver); 237 usb_deregister(&keyspan_driver);
238 usb_serial_deregister (&keyspan_pre_device); 238 usb_serial_deregister(&keyspan_pre_device);
239 usb_serial_deregister (&keyspan_1port_device); 239 usb_serial_deregister(&keyspan_1port_device);
240 usb_serial_deregister (&keyspan_2port_device); 240 usb_serial_deregister(&keyspan_2port_device);
241 usb_serial_deregister (&keyspan_4port_device); 241 usb_serial_deregister(&keyspan_4port_device);
242} 242}
243 243
244module_init(keyspan_init); 244module_init(keyspan_init);
245module_exit(keyspan_exit); 245module_exit(keyspan_exit);
246 246
247static void keyspan_rx_throttle (struct usb_serial_port *port) 247static void keyspan_break_ctl(struct tty_struct *tty, int break_state)
248{
249 dbg("%s - port %d", __func__, port->number);
250}
251
252
253static void keyspan_rx_unthrottle (struct usb_serial_port *port)
254{
255 dbg("%s - port %d", __func__, port->number);
256}
257
258
259static void keyspan_break_ctl (struct usb_serial_port *port, int break_state)
260{ 248{
249 struct usb_serial_port *port = tty->driver_data;
261 struct keyspan_port_private *p_priv; 250 struct keyspan_port_private *p_priv;
262 251
263 dbg("%s", __func__); 252 dbg("%s", __func__);
264 253
265 p_priv = usb_get_serial_port_data(port); 254 p_priv = usb_get_serial_port_data(port);
266 255
@@ -273,14 +262,13 @@ static void keyspan_break_ctl (struct usb_serial_port *port, int break_state)
273} 262}
274 263
275 264
276static void keyspan_set_termios (struct usb_serial_port *port, 265static void keyspan_set_termios(struct tty_struct *tty,
277 struct ktermios *old_termios) 266 struct usb_serial_port *port, struct ktermios *old_termios)
278{ 267{
279 int baud_rate, device_port; 268 int baud_rate, device_port;
280 struct keyspan_port_private *p_priv; 269 struct keyspan_port_private *p_priv;
281 const struct keyspan_device_details *d_details; 270 const struct keyspan_device_details *d_details;
282 unsigned int cflag; 271 unsigned int cflag;
283 struct tty_struct *tty = port->tty;
284 272
285 dbg("%s", __func__); 273 dbg("%s", __func__);
286 274
@@ -292,7 +280,7 @@ static void keyspan_set_termios (struct usb_serial_port *port,
292 /* Baud rate calculation takes baud rate as an integer 280 /* Baud rate calculation takes baud rate as an integer
293 so other rates can be generated if desired. */ 281 so other rates can be generated if desired. */
294 baud_rate = tty_get_baud_rate(tty); 282 baud_rate = tty_get_baud_rate(tty);
295 /* If no match or invalid, don't change */ 283 /* If no match or invalid, don't change */
296 if (d_details->calculate_baud_rate(baud_rate, d_details->baudclk, 284 if (d_details->calculate_baud_rate(baud_rate, d_details->baudclk,
297 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) { 285 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
298 /* FIXME - more to do here to ensure rate changes cleanly */ 286 /* FIXME - more to do here to ensure rate changes cleanly */
@@ -312,35 +300,32 @@ static void keyspan_set_termios (struct usb_serial_port *port,
312 keyspan_send_setup(port, 0); 300 keyspan_send_setup(port, 0);
313} 301}
314 302
315static int keyspan_tiocmget(struct usb_serial_port *port, struct file *file) 303static int keyspan_tiocmget(struct tty_struct *tty, struct file *file)
316{ 304{
305 struct usb_serial_port *port = tty->driver_data;
306 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
317 unsigned int value; 307 unsigned int value;
318 struct keyspan_port_private *p_priv;
319 308
320 p_priv = usb_get_serial_port_data(port);
321
322 value = ((p_priv->rts_state) ? TIOCM_RTS : 0) | 309 value = ((p_priv->rts_state) ? TIOCM_RTS : 0) |
323 ((p_priv->dtr_state) ? TIOCM_DTR : 0) | 310 ((p_priv->dtr_state) ? TIOCM_DTR : 0) |
324 ((p_priv->cts_state) ? TIOCM_CTS : 0) | 311 ((p_priv->cts_state) ? TIOCM_CTS : 0) |
325 ((p_priv->dsr_state) ? TIOCM_DSR : 0) | 312 ((p_priv->dsr_state) ? TIOCM_DSR : 0) |
326 ((p_priv->dcd_state) ? TIOCM_CAR : 0) | 313 ((p_priv->dcd_state) ? TIOCM_CAR : 0) |
327 ((p_priv->ri_state) ? TIOCM_RNG : 0); 314 ((p_priv->ri_state) ? TIOCM_RNG : 0);
328 315
329 return value; 316 return value;
330} 317}
331 318
332static int keyspan_tiocmset(struct usb_serial_port *port, struct file *file, 319static int keyspan_tiocmset(struct tty_struct *tty, struct file *file,
333 unsigned int set, unsigned int clear) 320 unsigned int set, unsigned int clear)
334{ 321{
335 struct keyspan_port_private *p_priv; 322 struct usb_serial_port *port = tty->driver_data;
323 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
336 324
337 p_priv = usb_get_serial_port_data(port);
338
339 if (set & TIOCM_RTS) 325 if (set & TIOCM_RTS)
340 p_priv->rts_state = 1; 326 p_priv->rts_state = 1;
341 if (set & TIOCM_DTR) 327 if (set & TIOCM_DTR)
342 p_priv->dtr_state = 1; 328 p_priv->dtr_state = 1;
343
344 if (clear & TIOCM_RTS) 329 if (clear & TIOCM_RTS)
345 p_priv->rts_state = 0; 330 p_priv->rts_state = 0;
346 if (clear & TIOCM_DTR) 331 if (clear & TIOCM_DTR)
@@ -349,35 +334,29 @@ static int keyspan_tiocmset(struct usb_serial_port *port, struct file *file,
349 return 0; 334 return 0;
350} 335}
351 336
352static int keyspan_ioctl(struct usb_serial_port *port, struct file *file, 337/* Write function is similar for the four protocols used
353 unsigned int cmd, unsigned long arg) 338 with only a minor change for usa90 (usa19hs) required */
354{ 339static int keyspan_write(struct tty_struct *tty,
355 return -ENOIOCTLCMD; 340 struct usb_serial_port *port, const unsigned char *buf, int count)
356}
357
358 /* Write function is similar for the four protocols used
359 with only a minor change for usa90 (usa19hs) required */
360static int keyspan_write(struct usb_serial_port *port,
361 const unsigned char *buf, int count)
362{ 341{
363 struct keyspan_port_private *p_priv; 342 struct keyspan_port_private *p_priv;
364 const struct keyspan_device_details *d_details; 343 const struct keyspan_device_details *d_details;
365 int flip; 344 int flip;
366 int left, todo; 345 int left, todo;
367 struct urb *this_urb; 346 struct urb *this_urb;
368 int err, maxDataLen, dataOffset; 347 int err, maxDataLen, dataOffset;
369 348
370 p_priv = usb_get_serial_port_data(port); 349 p_priv = usb_get_serial_port_data(port);
371 d_details = p_priv->device_details; 350 d_details = p_priv->device_details;
372 351
373 if (d_details->msg_format == msg_usa90) { 352 if (d_details->msg_format == msg_usa90) {
374 maxDataLen = 64; 353 maxDataLen = 64;
375 dataOffset = 0; 354 dataOffset = 0;
376 } else { 355 } else {
377 maxDataLen = 63; 356 maxDataLen = 63;
378 dataOffset = 1; 357 dataOffset = 1;
379 } 358 }
380 359
381 dbg("%s - for port %d (%d chars), flip=%d", 360 dbg("%s - for port %d (%d chars), flip=%d",
382 __func__, port->number, count, p_priv->out_flip); 361 __func__, port->number, count, p_priv->out_flip);
383 362
@@ -387,37 +366,40 @@ static int keyspan_write(struct usb_serial_port *port,
387 todo = maxDataLen; 366 todo = maxDataLen;
388 367
389 flip = p_priv->out_flip; 368 flip = p_priv->out_flip;
390 369
391 /* Check we have a valid urb/endpoint before we use it... */ 370 /* Check we have a valid urb/endpoint before we use it... */
392 if ((this_urb = p_priv->out_urbs[flip]) == NULL) { 371 this_urb = p_priv->out_urbs[flip];
372 if (this_urb == NULL) {
393 /* no bulk out, so return 0 bytes written */ 373 /* no bulk out, so return 0 bytes written */
394 dbg("%s - no output urb :(", __func__); 374 dbg("%s - no output urb :(", __func__);
395 return count; 375 return count;
396 } 376 }
397 377
398 dbg("%s - endpoint %d flip %d", __func__, usb_pipeendpoint(this_urb->pipe), flip); 378 dbg("%s - endpoint %d flip %d",
379 __func__, usb_pipeendpoint(this_urb->pipe), flip);
399 380
400 if (this_urb->status == -EINPROGRESS) { 381 if (this_urb->status == -EINPROGRESS) {
401 if (time_before(jiffies, p_priv->tx_start_time[flip] + 10 * HZ)) 382 if (time_before(jiffies,
383 p_priv->tx_start_time[flip] + 10 * HZ))
402 break; 384 break;
403 usb_unlink_urb(this_urb); 385 usb_unlink_urb(this_urb);
404 break; 386 break;
405 } 387 }
406 388
407 /* First byte in buffer is "last flag" (except for usa19hx) - unused so 389 /* First byte in buffer is "last flag" (except for usa19hx)
408 for now so set to zero */ 390 - unused so for now so set to zero */
409 ((char *)this_urb->transfer_buffer)[0] = 0; 391 ((char *)this_urb->transfer_buffer)[0] = 0;
410 392
411 memcpy (this_urb->transfer_buffer + dataOffset, buf, todo); 393 memcpy(this_urb->transfer_buffer + dataOffset, buf, todo);
412 buf += todo; 394 buf += todo;
413 395
414 /* send the data out the bulk port */ 396 /* send the data out the bulk port */
415 this_urb->transfer_buffer_length = todo + dataOffset; 397 this_urb->transfer_buffer_length = todo + dataOffset;
416 398
417 this_urb->dev = port->serial->dev; 399 this_urb->dev = port->serial->dev;
418 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 400 err = usb_submit_urb(this_urb, GFP_ATOMIC);
401 if (err != 0)
419 dbg("usb_submit_urb(write bulk) failed (%d)", err); 402 dbg("usb_submit_urb(write bulk) failed (%d)", err);
420 }
421 p_priv->tx_start_time[flip] = jiffies; 403 p_priv->tx_start_time[flip] = jiffies;
422 404
423 /* Flip for next time if usa26 or usa28 interface 405 /* Flip for next time if usa26 or usa28 interface
@@ -437,7 +419,7 @@ static void usa26_indat_callback(struct urb *urb)
437 unsigned char *data = urb->transfer_buffer; 419 unsigned char *data = urb->transfer_buffer;
438 int status = urb->status; 420 int status = urb->status;
439 421
440 dbg ("%s", __func__); 422 dbg("%s", __func__);
441 423
442 endpoint = usb_pipeendpoint(urb->pipe); 424 endpoint = usb_pipeendpoint(urb->pipe);
443 425
@@ -448,17 +430,18 @@ static void usa26_indat_callback(struct urb *urb)
448 } 430 }
449 431
450 port = urb->context; 432 port = urb->context;
451 tty = port->tty; 433 tty = port->port.tty;
452 if (tty && urb->actual_length) { 434 if (tty && urb->actual_length) {
453 /* 0x80 bit is error flag */ 435 /* 0x80 bit is error flag */
454 if ((data[0] & 0x80) == 0) { 436 if ((data[0] & 0x80) == 0) {
455 /* no errors on individual bytes, only possible overrun err*/ 437 /* no errors on individual bytes, only
438 possible overrun err */
456 if (data[0] & RXERROR_OVERRUN) 439 if (data[0] & RXERROR_OVERRUN)
457 err = TTY_OVERRUN; 440 err = TTY_OVERRUN;
458 else err = 0; 441 else
459 for (i = 1; i < urb->actual_length ; ++i) { 442 err = 0;
443 for (i = 1; i < urb->actual_length ; ++i)
460 tty_insert_flip_char(tty, data[i], err); 444 tty_insert_flip_char(tty, data[i], err);
461 }
462 } else { 445 } else {
463 /* some bytes had errors, every byte has status */ 446 /* some bytes had errors, every byte has status */
464 dbg("%s - RX error!!!!", __func__); 447 dbg("%s - RX error!!!!", __func__);
@@ -476,17 +459,19 @@ static void usa26_indat_callback(struct urb *urb)
476 } 459 }
477 tty_flip_buffer_push(tty); 460 tty_flip_buffer_push(tty);
478 } 461 }
479 462
480 /* Resubmit urb so we continue receiving */ 463 /* Resubmit urb so we continue receiving */
481 urb->dev = port->serial->dev; 464 urb->dev = port->serial->dev;
482 if (port->open_count) 465 if (port->port.count) {
483 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 466 err = usb_submit_urb(urb, GFP_ATOMIC);
484 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 467 if (err != 0)
485 } 468 dbg("%s - resubmit read urb failed. (%d)",
469 __func__, err);
470 }
486 return; 471 return;
487} 472}
488 473
489 /* Outdat handling is common for all devices */ 474/* Outdat handling is common for all devices */
490static void usa2x_outdat_callback(struct urb *urb) 475static void usa2x_outdat_callback(struct urb *urb)
491{ 476{
492 struct usb_serial_port *port; 477 struct usb_serial_port *port;
@@ -494,16 +479,16 @@ static void usa2x_outdat_callback(struct urb *urb)
494 479
495 port = urb->context; 480 port = urb->context;
496 p_priv = usb_get_serial_port_data(port); 481 p_priv = usb_get_serial_port_data(port);
497 dbg ("%s - urb %d", __func__, urb == p_priv->out_urbs[1]); 482 dbg("%s - urb %d", __func__, urb == p_priv->out_urbs[1]);
498 483
499 if (port->open_count) 484 if (port->port.count)
500 usb_serial_port_softint(port); 485 usb_serial_port_softint(port);
501} 486}
502 487
503static void usa26_inack_callback(struct urb *urb) 488static void usa26_inack_callback(struct urb *urb)
504{ 489{
505 dbg ("%s", __func__); 490 dbg("%s", __func__);
506 491
507} 492}
508 493
509static void usa26_outcont_callback(struct urb *urb) 494static void usa26_outcont_callback(struct urb *urb)
@@ -515,8 +500,9 @@ static void usa26_outcont_callback(struct urb *urb)
515 p_priv = usb_get_serial_port_data(port); 500 p_priv = usb_get_serial_port_data(port);
516 501
517 if (p_priv->resend_cont) { 502 if (p_priv->resend_cont) {
518 dbg ("%s - sending setup", __func__); 503 dbg("%s - sending setup", __func__);
519 keyspan_usa26_send_setup(port->serial, port, p_priv->resend_cont - 1); 504 keyspan_usa26_send_setup(port->serial, port,
505 p_priv->resend_cont - 1);
520 } 506 }
521} 507}
522 508
@@ -552,14 +538,14 @@ static void usa26_instat_callback(struct urb *urb)
552 /* Now do something useful with the data */ 538 /* Now do something useful with the data */
553 539
554 540
555 /* Check port number from message and retrieve private data */ 541 /* Check port number from message and retrieve private data */
556 if (msg->port >= serial->num_ports) { 542 if (msg->port >= serial->num_ports) {
557 dbg ("%s - Unexpected port number %d", __func__, msg->port); 543 dbg("%s - Unexpected port number %d", __func__, msg->port);
558 goto exit; 544 goto exit;
559 } 545 }
560 port = serial->port[msg->port]; 546 port = serial->port[msg->port];
561 p_priv = usb_get_serial_port_data(port); 547 p_priv = usb_get_serial_port_data(port);
562 548
563 /* Update handshaking pin state information */ 549 /* Update handshaking pin state information */
564 old_dcd_state = p_priv->dcd_state; 550 old_dcd_state = p_priv->dcd_state;
565 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0); 551 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
@@ -567,39 +553,38 @@ static void usa26_instat_callback(struct urb *urb)
567 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0); 553 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
568 p_priv->ri_state = ((msg->ri) ? 1 : 0); 554 p_priv->ri_state = ((msg->ri) ? 1 : 0);
569 555
570 if (port->tty && !C_CLOCAL(port->tty) 556 if (port->port.tty && !C_CLOCAL(port->port.tty)
571 && old_dcd_state != p_priv->dcd_state) { 557 && old_dcd_state != p_priv->dcd_state) {
572 if (old_dcd_state) 558 if (old_dcd_state)
573 tty_hangup(port->tty); 559 tty_hangup(port->port.tty);
574 /* else */ 560 /* else */
575 /* wake_up_interruptible(&p_priv->open_wait); */ 561 /* wake_up_interruptible(&p_priv->open_wait); */
576 } 562 }
577 563
578 /* Resubmit urb so we continue receiving */ 564 /* Resubmit urb so we continue receiving */
579 urb->dev = serial->dev; 565 urb->dev = serial->dev;
580 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 566 err = usb_submit_urb(urb, GFP_ATOMIC);
567 if (err != 0)
581 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 568 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
582 }
583exit: ; 569exit: ;
584} 570}
585 571
586static void usa26_glocont_callback(struct urb *urb) 572static void usa26_glocont_callback(struct urb *urb)
587{ 573{
588 dbg ("%s", __func__); 574 dbg("%s", __func__);
589
590} 575}
591 576
592 577
593static void usa28_indat_callback(struct urb *urb) 578static void usa28_indat_callback(struct urb *urb)
594{ 579{
595 int i, err; 580 int err;
596 struct usb_serial_port *port; 581 struct usb_serial_port *port;
597 struct tty_struct *tty; 582 struct tty_struct *tty;
598 unsigned char *data; 583 unsigned char *data;
599 struct keyspan_port_private *p_priv; 584 struct keyspan_port_private *p_priv;
600 int status = urb->status; 585 int status = urb->status;
601 586
602 dbg ("%s", __func__); 587 dbg("%s", __func__);
603 588
604 port = urb->context; 589 port = urb->context;
605 p_priv = usb_get_serial_port_data(port); 590 p_priv = usb_get_serial_port_data(port);
@@ -619,20 +604,20 @@ static void usa28_indat_callback(struct urb *urb)
619 p_priv = usb_get_serial_port_data(port); 604 p_priv = usb_get_serial_port_data(port);
620 data = urb->transfer_buffer; 605 data = urb->transfer_buffer;
621 606
622 tty = port->tty; 607 tty = port->port.tty;
623 if (urb->actual_length) { 608 if (urb->actual_length) {
624 for (i = 0; i < urb->actual_length ; ++i) { 609 tty_insert_flip_string(tty, data, urb->actual_length);
625 tty_insert_flip_char(tty, data[i], 0);
626 }
627 tty_flip_buffer_push(tty); 610 tty_flip_buffer_push(tty);
628 } 611 }
629 612
630 /* Resubmit urb so we continue receiving */ 613 /* Resubmit urb so we continue receiving */
631 urb->dev = port->serial->dev; 614 urb->dev = port->serial->dev;
632 if (port->open_count) 615 if (port->port.count) {
633 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 616 err = usb_submit_urb(urb, GFP_ATOMIC);
634 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 617 if (err != 0)
635 } 618 dbg("%s - resubmit read urb failed. (%d)",
619 __func__, err);
620 }
636 p_priv->in_flip ^= 1; 621 p_priv->in_flip ^= 1;
637 622
638 urb = p_priv->in_urbs[p_priv->in_flip]; 623 urb = p_priv->in_urbs[p_priv->in_flip];
@@ -641,7 +626,7 @@ static void usa28_indat_callback(struct urb *urb)
641 626
642static void usa28_inack_callback(struct urb *urb) 627static void usa28_inack_callback(struct urb *urb)
643{ 628{
644 dbg ("%s", __func__); 629 dbg("%s", __func__);
645} 630}
646 631
647static void usa28_outcont_callback(struct urb *urb) 632static void usa28_outcont_callback(struct urb *urb)
@@ -653,8 +638,9 @@ static void usa28_outcont_callback(struct urb *urb)
653 p_priv = usb_get_serial_port_data(port); 638 p_priv = usb_get_serial_port_data(port);
654 639
655 if (p_priv->resend_cont) { 640 if (p_priv->resend_cont) {
656 dbg ("%s - sending setup", __func__); 641 dbg("%s - sending setup", __func__);
657 keyspan_usa28_send_setup(port->serial, port, p_priv->resend_cont - 1); 642 keyspan_usa28_send_setup(port->serial, port,
643 p_priv->resend_cont - 1);
658 } 644 }
659} 645}
660 646
@@ -684,19 +670,18 @@ static void usa28_instat_callback(struct urb *urb)
684 /*dbg("%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__ 670 /*dbg("%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__
685 data[0], data[1], data[2], data[3], data[4], data[5], 671 data[0], data[1], data[2], data[3], data[4], data[5],
686 data[6], data[7], data[8], data[9], data[10], data[11]);*/ 672 data[6], data[7], data[8], data[9], data[10], data[11]);*/
687
688 /* Now do something useful with the data */
689 msg = (struct keyspan_usa28_portStatusMessage *)data;
690 673
674 /* Now do something useful with the data */
675 msg = (struct keyspan_usa28_portStatusMessage *)data;
691 676
692 /* Check port number from message and retrieve private data */ 677 /* Check port number from message and retrieve private data */
693 if (msg->port >= serial->num_ports) { 678 if (msg->port >= serial->num_ports) {
694 dbg ("%s - Unexpected port number %d", __func__, msg->port); 679 dbg("%s - Unexpected port number %d", __func__, msg->port);
695 goto exit; 680 goto exit;
696 } 681 }
697 port = serial->port[msg->port]; 682 port = serial->port[msg->port];
698 p_priv = usb_get_serial_port_data(port); 683 p_priv = usb_get_serial_port_data(port);
699 684
700 /* Update handshaking pin state information */ 685 /* Update handshaking pin state information */
701 old_dcd_state = p_priv->dcd_state; 686 old_dcd_state = p_priv->dcd_state;
702 p_priv->cts_state = ((msg->cts) ? 1 : 0); 687 p_priv->cts_state = ((msg->cts) ? 1 : 0);
@@ -704,25 +689,25 @@ static void usa28_instat_callback(struct urb *urb)
704 p_priv->dcd_state = ((msg->dcd) ? 1 : 0); 689 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
705 p_priv->ri_state = ((msg->ri) ? 1 : 0); 690 p_priv->ri_state = ((msg->ri) ? 1 : 0);
706 691
707 if (port->tty && !C_CLOCAL(port->tty) 692 if (port->port.tty && !C_CLOCAL(port->port.tty)
708 && old_dcd_state != p_priv->dcd_state) { 693 && old_dcd_state != p_priv->dcd_state) {
709 if (old_dcd_state) 694 if (old_dcd_state)
710 tty_hangup(port->tty); 695 tty_hangup(port->port.tty);
711 /* else */ 696 /* else */
712 /* wake_up_interruptible(&p_priv->open_wait); */ 697 /* wake_up_interruptible(&p_priv->open_wait); */
713 } 698 }
714 699
715 /* Resubmit urb so we continue receiving */ 700 /* Resubmit urb so we continue receiving */
716 urb->dev = serial->dev; 701 urb->dev = serial->dev;
717 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 702 err = usb_submit_urb(urb, GFP_ATOMIC);
703 if (err != 0)
718 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 704 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
719 }
720exit: ; 705exit: ;
721} 706}
722 707
723static void usa28_glocont_callback(struct urb *urb) 708static void usa28_glocont_callback(struct urb *urb)
724{ 709{
725 dbg ("%s", __func__); 710 dbg("%s", __func__);
726} 711}
727 712
728 713
@@ -733,7 +718,7 @@ static void usa49_glocont_callback(struct urb *urb)
733 struct keyspan_port_private *p_priv; 718 struct keyspan_port_private *p_priv;
734 int i; 719 int i;
735 720
736 dbg ("%s", __func__); 721 dbg("%s", __func__);
737 722
738 serial = urb->context; 723 serial = urb->context;
739 for (i = 0; i < serial->num_ports; ++i) { 724 for (i = 0; i < serial->num_ports; ++i) {
@@ -741,8 +726,9 @@ static void usa49_glocont_callback(struct urb *urb)
741 p_priv = usb_get_serial_port_data(port); 726 p_priv = usb_get_serial_port_data(port);
742 727
743 if (p_priv->resend_cont) { 728 if (p_priv->resend_cont) {
744 dbg ("%s - sending setup", __func__); 729 dbg("%s - sending setup", __func__);
745 keyspan_usa49_send_setup(serial, port, p_priv->resend_cont - 1); 730 keyspan_usa49_send_setup(serial, port,
731 p_priv->resend_cont - 1);
746 break; 732 break;
747 } 733 }
748 } 734 }
@@ -761,7 +747,7 @@ static void usa49_instat_callback(struct urb *urb)
761 int old_dcd_state; 747 int old_dcd_state;
762 int status = urb->status; 748 int status = urb->status;
763 749
764 dbg ("%s", __func__); 750 dbg("%s", __func__);
765 751
766 serial = urb->context; 752 serial = urb->context;
767 753
@@ -770,7 +756,8 @@ static void usa49_instat_callback(struct urb *urb)
770 return; 756 return;
771 } 757 }
772 758
773 if (urb->actual_length != sizeof(struct keyspan_usa49_portStatusMessage)) { 759 if (urb->actual_length !=
760 sizeof(struct keyspan_usa49_portStatusMessage)) {
774 dbg("%s - bad length %d", __func__, urb->actual_length); 761 dbg("%s - bad length %d", __func__, urb->actual_length);
775 goto exit; 762 goto exit;
776 } 763 }
@@ -778,18 +765,19 @@ static void usa49_instat_callback(struct urb *urb)
778 /*dbg(" %x %x %x %x %x %x %x %x %x %x %x", __func__, 765 /*dbg(" %x %x %x %x %x %x %x %x %x %x %x", __func__,
779 data[0], data[1], data[2], data[3], data[4], data[5], 766 data[0], data[1], data[2], data[3], data[4], data[5],
780 data[6], data[7], data[8], data[9], data[10]);*/ 767 data[6], data[7], data[8], data[9], data[10]);*/
781 768
782 /* Now do something useful with the data */ 769 /* Now do something useful with the data */
783 msg = (struct keyspan_usa49_portStatusMessage *)data; 770 msg = (struct keyspan_usa49_portStatusMessage *)data;
784 771
785 /* Check port number from message and retrieve private data */ 772 /* Check port number from message and retrieve private data */
786 if (msg->portNumber >= serial->num_ports) { 773 if (msg->portNumber >= serial->num_ports) {
787 dbg ("%s - Unexpected port number %d", __func__, msg->portNumber); 774 dbg("%s - Unexpected port number %d",
775 __func__, msg->portNumber);
788 goto exit; 776 goto exit;
789 } 777 }
790 port = serial->port[msg->portNumber]; 778 port = serial->port[msg->portNumber];
791 p_priv = usb_get_serial_port_data(port); 779 p_priv = usb_get_serial_port_data(port);
792 780
793 /* Update handshaking pin state information */ 781 /* Update handshaking pin state information */
794 old_dcd_state = p_priv->dcd_state; 782 old_dcd_state = p_priv->dcd_state;
795 p_priv->cts_state = ((msg->cts) ? 1 : 0); 783 p_priv->cts_state = ((msg->cts) ? 1 : 0);
@@ -797,26 +785,26 @@ static void usa49_instat_callback(struct urb *urb)
797 p_priv->dcd_state = ((msg->dcd) ? 1 : 0); 785 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
798 p_priv->ri_state = ((msg->ri) ? 1 : 0); 786 p_priv->ri_state = ((msg->ri) ? 1 : 0);
799 787
800 if (port->tty && !C_CLOCAL(port->tty) 788 if (port->port.tty && !C_CLOCAL(port->port.tty)
801 && old_dcd_state != p_priv->dcd_state) { 789 && old_dcd_state != p_priv->dcd_state) {
802 if (old_dcd_state) 790 if (old_dcd_state)
803 tty_hangup(port->tty); 791 tty_hangup(port->port.tty);
804 /* else */ 792 /* else */
805 /* wake_up_interruptible(&p_priv->open_wait); */ 793 /* wake_up_interruptible(&p_priv->open_wait); */
806 } 794 }
807 795
808 /* Resubmit urb so we continue receiving */ 796 /* Resubmit urb so we continue receiving */
809 urb->dev = serial->dev; 797 urb->dev = serial->dev;
810 798
811 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 799 err = usb_submit_urb(urb, GFP_ATOMIC);
800 if (err != 0)
812 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 801 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
813 }
814exit: ; 802exit: ;
815} 803}
816 804
817static void usa49_inack_callback(struct urb *urb) 805static void usa49_inack_callback(struct urb *urb)
818{ 806{
819 dbg ("%s", __func__); 807 dbg("%s", __func__);
820} 808}
821 809
822static void usa49_indat_callback(struct urb *urb) 810static void usa49_indat_callback(struct urb *urb)
@@ -828,7 +816,7 @@ static void usa49_indat_callback(struct urb *urb)
828 unsigned char *data = urb->transfer_buffer; 816 unsigned char *data = urb->transfer_buffer;
829 int status = urb->status; 817 int status = urb->status;
830 818
831 dbg ("%s", __func__); 819 dbg("%s", __func__);
832 820
833 endpoint = usb_pipeendpoint(urb->pipe); 821 endpoint = usb_pipeendpoint(urb->pipe);
834 822
@@ -839,14 +827,13 @@ static void usa49_indat_callback(struct urb *urb)
839 } 827 }
840 828
841 port = urb->context; 829 port = urb->context;
842 tty = port->tty; 830 tty = port->port.tty;
843 if (tty && urb->actual_length) { 831 if (tty && urb->actual_length) {
844 /* 0x80 bit is error flag */ 832 /* 0x80 bit is error flag */
845 if ((data[0] & 0x80) == 0) { 833 if ((data[0] & 0x80) == 0) {
846 /* no error on any byte */ 834 /* no error on any byte */
847 for (i = 1; i < urb->actual_length ; ++i) { 835 tty_insert_flip_string(tty, data + 1,
848 tty_insert_flip_char(tty, data[i], 0); 836 urb->actual_length - 1);
849 }
850 } else { 837 } else {
851 /* some bytes had errors, every byte has status */ 838 /* some bytes had errors, every byte has status */
852 for (i = 0; i + 1 < urb->actual_length; i += 2) { 839 for (i = 0; i + 1 < urb->actual_length; i += 2) {
@@ -863,13 +850,15 @@ static void usa49_indat_callback(struct urb *urb)
863 } 850 }
864 tty_flip_buffer_push(tty); 851 tty_flip_buffer_push(tty);
865 } 852 }
866 853
867 /* Resubmit urb so we continue receiving */ 854 /* Resubmit urb so we continue receiving */
868 urb->dev = port->serial->dev; 855 urb->dev = port->serial->dev;
869 if (port->open_count) 856 if (port->port.count) {
870 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 857 err = usb_submit_urb(urb, GFP_ATOMIC);
871 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 858 if (err != 0)
872 } 859 dbg("%s - resubmit read urb failed. (%d)",
860 __func__, err);
861 }
873} 862}
874 863
875static void usa49wg_indat_callback(struct urb *urb) 864static void usa49wg_indat_callback(struct urb *urb)
@@ -881,7 +870,7 @@ static void usa49wg_indat_callback(struct urb *urb)
881 unsigned char *data = urb->transfer_buffer; 870 unsigned char *data = urb->transfer_buffer;
882 int status = urb->status; 871 int status = urb->status;
883 872
884 dbg ("%s", __func__); 873 dbg("%s", __func__);
885 874
886 serial = urb->context; 875 serial = urb->context;
887 876
@@ -899,12 +888,12 @@ static void usa49wg_indat_callback(struct urb *urb)
899 888
900 /* Check port number from message*/ 889 /* Check port number from message*/
901 if (data[i] >= serial->num_ports) { 890 if (data[i] >= serial->num_ports) {
902 dbg ("%s - Unexpected port number %d", 891 dbg("%s - Unexpected port number %d",
903 __func__, data[i]); 892 __func__, data[i]);
904 return; 893 return;
905 } 894 }
906 port = serial->port[data[i++]]; 895 port = serial->port[data[i++]];
907 tty = port->tty; 896 tty = port->port.tty;
908 len = data[i++]; 897 len = data[i++];
909 898
910 /* 0x80 bit is error flag */ 899 /* 0x80 bit is error flag */
@@ -912,7 +901,7 @@ static void usa49wg_indat_callback(struct urb *urb)
912 /* no error on any byte */ 901 /* no error on any byte */
913 i++; 902 i++;
914 for (x = 1; x < len ; ++x) 903 for (x = 1; x < len ; ++x)
915 if (port->open_count) 904 if (port->port.count)
916 tty_insert_flip_char(tty, 905 tty_insert_flip_char(tty,
917 data[i++], 0); 906 data[i++], 0);
918 else 907 else
@@ -930,13 +919,13 @@ static void usa49wg_indat_callback(struct urb *urb)
930 if (stat & RXERROR_PARITY) 919 if (stat & RXERROR_PARITY)
931 flag |= TTY_PARITY; 920 flag |= TTY_PARITY;
932 /* XXX should handle break (0x10) */ 921 /* XXX should handle break (0x10) */
933 if (port->open_count) 922 if (port->port.count)
934 tty_insert_flip_char(tty, 923 tty_insert_flip_char(tty,
935 data[i+1], flag); 924 data[i+1], flag);
936 i += 2; 925 i += 2;
937 } 926 }
938 } 927 }
939 if (port->open_count) 928 if (port->port.count)
940 tty_flip_buffer_push(tty); 929 tty_flip_buffer_push(tty);
941 } 930 }
942 } 931 }
@@ -952,7 +941,7 @@ static void usa49wg_indat_callback(struct urb *urb)
952/* not used, usa-49 doesn't have per-port control endpoints */ 941/* not used, usa-49 doesn't have per-port control endpoints */
953static void usa49_outcont_callback(struct urb *urb) 942static void usa49_outcont_callback(struct urb *urb)
954{ 943{
955 dbg ("%s", __func__); 944 dbg("%s", __func__);
956} 945}
957 946
958static void usa90_indat_callback(struct urb *urb) 947static void usa90_indat_callback(struct urb *urb)
@@ -965,7 +954,7 @@ static void usa90_indat_callback(struct urb *urb)
965 unsigned char *data = urb->transfer_buffer; 954 unsigned char *data = urb->transfer_buffer;
966 int status = urb->status; 955 int status = urb->status;
967 956
968 dbg ("%s", __func__); 957 dbg("%s", __func__);
969 958
970 endpoint = usb_pipeendpoint(urb->pipe); 959 endpoint = usb_pipeendpoint(urb->pipe);
971 960
@@ -978,29 +967,26 @@ static void usa90_indat_callback(struct urb *urb)
978 port = urb->context; 967 port = urb->context;
979 p_priv = usb_get_serial_port_data(port); 968 p_priv = usb_get_serial_port_data(port);
980 969
981 tty = port->tty; 970 tty = port->port.tty;
982 if (urb->actual_length) { 971 if (urb->actual_length) {
983
984 /* if current mode is DMA, looks like usa28 format 972 /* if current mode is DMA, looks like usa28 format
985 otherwise looks like usa26 data format */ 973 otherwise looks like usa26 data format */
986 974
987 if (p_priv->baud > 57600) { 975 if (p_priv->baud > 57600)
988 for (i = 0; i < urb->actual_length ; ++i) 976 tty_insert_flip_string(tty, data, urb->actual_length);
989 tty_insert_flip_char(tty, data[i], 0);
990 }
991 else { 977 else {
992
993 /* 0x80 bit is error flag */ 978 /* 0x80 bit is error flag */
994 if ((data[0] & 0x80) == 0) { 979 if ((data[0] & 0x80) == 0) {
995 /* no errors on individual bytes, only possible overrun err*/ 980 /* no errors on individual bytes, only
981 possible overrun err*/
996 if (data[0] & RXERROR_OVERRUN) 982 if (data[0] & RXERROR_OVERRUN)
997 err = TTY_OVERRUN; 983 err = TTY_OVERRUN;
998 else err = 0; 984 else
999 for (i = 1; i < urb->actual_length ; ++i) 985 err = 0;
1000 tty_insert_flip_char(tty, data[i], err); 986 for (i = 1; i < urb->actual_length ; ++i)
1001 987 tty_insert_flip_char(tty, data[i],
1002 } 988 err);
1003 else { 989 } else {
1004 /* some bytes had errors, every byte has status */ 990 /* some bytes had errors, every byte has status */
1005 dbg("%s - RX error!!!!", __func__); 991 dbg("%s - RX error!!!!", __func__);
1006 for (i = 0; i + 1 < urb->actual_length; i += 2) { 992 for (i = 0; i + 1 < urb->actual_length; i += 2) {
@@ -1012,19 +998,22 @@ static void usa90_indat_callback(struct urb *urb)
1012 if (stat & RXERROR_PARITY) 998 if (stat & RXERROR_PARITY)
1013 flag |= TTY_PARITY; 999 flag |= TTY_PARITY;
1014 /* XXX should handle break (0x10) */ 1000 /* XXX should handle break (0x10) */
1015 tty_insert_flip_char(tty, data[i+1], flag); 1001 tty_insert_flip_char(tty, data[i+1],
1002 flag);
1016 } 1003 }
1017 } 1004 }
1018 } 1005 }
1019 tty_flip_buffer_push(tty); 1006 tty_flip_buffer_push(tty);
1020 } 1007 }
1021 1008
1022 /* Resubmit urb so we continue receiving */ 1009 /* Resubmit urb so we continue receiving */
1023 urb->dev = port->serial->dev; 1010 urb->dev = port->serial->dev;
1024 if (port->open_count) 1011 if (port->port.count) {
1025 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 1012 err = usb_submit_urb(urb, GFP_ATOMIC);
1026 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 1013 if (err != 0)
1027 } 1014 dbg("%s - resubmit read urb failed. (%d)",
1015 __func__, err);
1016 }
1028 return; 1017 return;
1029} 1018}
1030 1019
@@ -1056,7 +1045,7 @@ static void usa90_instat_callback(struct urb *urb)
1056 1045
1057 port = serial->port[0]; 1046 port = serial->port[0];
1058 p_priv = usb_get_serial_port_data(port); 1047 p_priv = usb_get_serial_port_data(port);
1059 1048
1060 /* Update handshaking pin state information */ 1049 /* Update handshaking pin state information */
1061 old_dcd_state = p_priv->dcd_state; 1050 old_dcd_state = p_priv->dcd_state;
1062 p_priv->cts_state = ((msg->cts) ? 1 : 0); 1051 p_priv->cts_state = ((msg->cts) ? 1 : 0);
@@ -1064,19 +1053,19 @@ static void usa90_instat_callback(struct urb *urb)
1064 p_priv->dcd_state = ((msg->dcd) ? 1 : 0); 1053 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
1065 p_priv->ri_state = ((msg->ri) ? 1 : 0); 1054 p_priv->ri_state = ((msg->ri) ? 1 : 0);
1066 1055
1067 if (port->tty && !C_CLOCAL(port->tty) 1056 if (port->port.tty && !C_CLOCAL(port->port.tty)
1068 && old_dcd_state != p_priv->dcd_state) { 1057 && old_dcd_state != p_priv->dcd_state) {
1069 if (old_dcd_state) 1058 if (old_dcd_state)
1070 tty_hangup(port->tty); 1059 tty_hangup(port->port.tty);
1071 /* else */ 1060 /* else */
1072 /* wake_up_interruptible(&p_priv->open_wait); */ 1061 /* wake_up_interruptible(&p_priv->open_wait); */
1073 } 1062 }
1074 1063
1075 /* Resubmit urb so we continue receiving */ 1064 /* Resubmit urb so we continue receiving */
1076 urb->dev = serial->dev; 1065 urb->dev = serial->dev;
1077 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 1066 err = usb_submit_urb(urb, GFP_ATOMIC);
1067 if (err != 0)
1078 dbg("%s - resubmit read urb failed. (%d)", __func__, err); 1068 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
1079 }
1080exit: 1069exit:
1081 ; 1070 ;
1082} 1071}
@@ -1090,8 +1079,9 @@ static void usa90_outcont_callback(struct urb *urb)
1090 p_priv = usb_get_serial_port_data(port); 1079 p_priv = usb_get_serial_port_data(port);
1091 1080
1092 if (p_priv->resend_cont) { 1081 if (p_priv->resend_cont) {
1093 dbg ("%s - sending setup", __func__); 1082 dbg("%s - sending setup", __func__);
1094 keyspan_usa90_send_setup(port->serial, port, p_priv->resend_cont - 1); 1083 keyspan_usa90_send_setup(port->serial, port,
1084 p_priv->resend_cont - 1);
1095 } 1085 }
1096} 1086}
1097 1087
@@ -1107,7 +1097,7 @@ static void usa67_instat_callback(struct urb *urb)
1107 int old_dcd_state; 1097 int old_dcd_state;
1108 int status = urb->status; 1098 int status = urb->status;
1109 1099
1110 dbg ("%s", __func__); 1100 dbg("%s", __func__);
1111 1101
1112 serial = urb->context; 1102 serial = urb->context;
1113 1103
@@ -1116,7 +1106,8 @@ static void usa67_instat_callback(struct urb *urb)
1116 return; 1106 return;
1117 } 1107 }
1118 1108
1119 if (urb->actual_length != sizeof(struct keyspan_usa67_portStatusMessage)) { 1109 if (urb->actual_length !=
1110 sizeof(struct keyspan_usa67_portStatusMessage)) {
1120 dbg("%s - bad length %d", __func__, urb->actual_length); 1111 dbg("%s - bad length %d", __func__, urb->actual_length);
1121 return; 1112 return;
1122 } 1113 }
@@ -1127,7 +1118,7 @@ static void usa67_instat_callback(struct urb *urb)
1127 1118
1128 /* Check port number from message and retrieve private data */ 1119 /* Check port number from message and retrieve private data */
1129 if (msg->port >= serial->num_ports) { 1120 if (msg->port >= serial->num_ports) {
1130 dbg ("%s - Unexpected port number %d", __func__, msg->port); 1121 dbg("%s - Unexpected port number %d", __func__, msg->port);
1131 return; 1122 return;
1132 } 1123 }
1133 1124
@@ -1139,10 +1130,10 @@ static void usa67_instat_callback(struct urb *urb)
1139 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0); 1130 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
1140 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0); 1131 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
1141 1132
1142 if (port->tty && !C_CLOCAL(port->tty) 1133 if (port->port.tty && !C_CLOCAL(port->port.tty)
1143 && old_dcd_state != p_priv->dcd_state) { 1134 && old_dcd_state != p_priv->dcd_state) {
1144 if (old_dcd_state) 1135 if (old_dcd_state)
1145 tty_hangup(port->tty); 1136 tty_hangup(port->port.tty);
1146 /* else */ 1137 /* else */
1147 /* wake_up_interruptible(&p_priv->open_wait); */ 1138 /* wake_up_interruptible(&p_priv->open_wait); */
1148 } 1139 }
@@ -1161,7 +1152,7 @@ static void usa67_glocont_callback(struct urb *urb)
1161 struct keyspan_port_private *p_priv; 1152 struct keyspan_port_private *p_priv;
1162 int i; 1153 int i;
1163 1154
1164 dbg ("%s", __func__); 1155 dbg("%s", __func__);
1165 1156
1166 serial = urb->context; 1157 serial = urb->context;
1167 for (i = 0; i < serial->num_ports; ++i) { 1158 for (i = 0; i < serial->num_ports; ++i) {
@@ -1169,7 +1160,7 @@ static void usa67_glocont_callback(struct urb *urb)
1169 p_priv = usb_get_serial_port_data(port); 1160 p_priv = usb_get_serial_port_data(port);
1170 1161
1171 if (p_priv->resend_cont) { 1162 if (p_priv->resend_cont) {
1172 dbg ("%s - sending setup", __func__); 1163 dbg("%s - sending setup", __func__);
1173 keyspan_usa67_send_setup(serial, port, 1164 keyspan_usa67_send_setup(serial, port,
1174 p_priv->resend_cont - 1); 1165 p_priv->resend_cont - 1);
1175 break; 1166 break;
@@ -1177,8 +1168,9 @@ static void usa67_glocont_callback(struct urb *urb)
1177 } 1168 }
1178} 1169}
1179 1170
1180static int keyspan_write_room (struct usb_serial_port *port) 1171static int keyspan_write_room(struct tty_struct *tty)
1181{ 1172{
1173 struct usb_serial_port *port = tty->driver_data;
1182 struct keyspan_port_private *p_priv; 1174 struct keyspan_port_private *p_priv;
1183 const struct keyspan_device_details *d_details; 1175 const struct keyspan_device_details *d_details;
1184 int flip; 1176 int flip;
@@ -1191,32 +1183,30 @@ static int keyspan_write_room (struct usb_serial_port *port)
1191 1183
1192 /* FIXME: locking */ 1184 /* FIXME: locking */
1193 if (d_details->msg_format == msg_usa90) 1185 if (d_details->msg_format == msg_usa90)
1194 data_len = 64; 1186 data_len = 64;
1195 else 1187 else
1196 data_len = 63; 1188 data_len = 63;
1197 1189
1198 flip = p_priv->out_flip; 1190 flip = p_priv->out_flip;
1199 1191
1200 /* Check both endpoints to see if any are available. */ 1192 /* Check both endpoints to see if any are available. */
1201 if ((this_urb = p_priv->out_urbs[flip]) != NULL) { 1193 this_urb = p_priv->out_urbs[flip];
1194 if (this_urb != NULL) {
1202 if (this_urb->status != -EINPROGRESS) 1195 if (this_urb->status != -EINPROGRESS)
1203 return (data_len); 1196 return data_len;
1204 flip = (flip + 1) & d_details->outdat_endp_flip; 1197 flip = (flip + 1) & d_details->outdat_endp_flip;
1205 if ((this_urb = p_priv->out_urbs[flip]) != NULL) 1198 this_urb = p_priv->out_urbs[flip];
1199 if (this_urb != NULL) {
1206 if (this_urb->status != -EINPROGRESS) 1200 if (this_urb->status != -EINPROGRESS)
1207 return (data_len); 1201 return data_len;
1202 }
1208 } 1203 }
1209 return 0; 1204 return 0;
1210} 1205}
1211 1206
1212 1207
1213static int keyspan_chars_in_buffer (struct usb_serial_port *port) 1208static int keyspan_open(struct tty_struct *tty,
1214{ 1209 struct usb_serial_port *port, struct file *filp)
1215 return 0;
1216}
1217
1218
1219static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1220{ 1210{
1221 struct keyspan_port_private *p_priv; 1211 struct keyspan_port_private *p_priv;
1222 struct keyspan_serial_private *s_priv; 1212 struct keyspan_serial_private *s_priv;
@@ -1225,7 +1215,7 @@ static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1225 int i, err; 1215 int i, err;
1226 int baud_rate, device_port; 1216 int baud_rate, device_port;
1227 struct urb *urb; 1217 struct urb *urb;
1228 unsigned int cflag; 1218 unsigned int cflag = 0;
1229 1219
1230 s_priv = usb_get_serial_data(serial); 1220 s_priv = usb_get_serial_data(serial);
1231 p_priv = usb_get_serial_port_data(port); 1221 p_priv = usb_get_serial_port_data(port);
@@ -1247,50 +1237,53 @@ static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1247 1237
1248 /* Reset low level data toggle and start reading from endpoints */ 1238 /* Reset low level data toggle and start reading from endpoints */
1249 for (i = 0; i < 2; i++) { 1239 for (i = 0; i < 2; i++) {
1250 if ((urb = p_priv->in_urbs[i]) == NULL) 1240 urb = p_priv->in_urbs[i];
1241 if (urb == NULL)
1251 continue; 1242 continue;
1252 urb->dev = serial->dev; 1243 urb->dev = serial->dev;
1253 1244
1254 /* make sure endpoint data toggle is synchronized with the device */ 1245 /* make sure endpoint data toggle is synchronized
1255 1246 with the device */
1256 usb_clear_halt(urb->dev, urb->pipe); 1247 usb_clear_halt(urb->dev, urb->pipe);
1257 1248 err = usb_submit_urb(urb, GFP_KERNEL);
1258 if ((err = usb_submit_urb(urb, GFP_KERNEL)) != 0) { 1249 if (err != 0)
1259 dbg("%s - submit urb %d failed (%d)", __func__, i, err); 1250 dbg("%s - submit urb %d failed (%d)",
1260 } 1251 __func__, i, err);
1261 } 1252 }
1262 1253
1263 /* Reset low level data toggle on out endpoints */ 1254 /* Reset low level data toggle on out endpoints */
1264 for (i = 0; i < 2; i++) { 1255 for (i = 0; i < 2; i++) {
1265 if ((urb = p_priv->out_urbs[i]) == NULL) 1256 urb = p_priv->out_urbs[i];
1257 if (urb == NULL)
1266 continue; 1258 continue;
1267 urb->dev = serial->dev; 1259 urb->dev = serial->dev;
1268 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */ 1260 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1261 usb_pipeout(urb->pipe), 0); */
1269 } 1262 }
1270 1263
1271 /* get the terminal config for the setup message now so we don't 1264 /* get the terminal config for the setup message now so we don't
1272 * need to send 2 of them */ 1265 * need to send 2 of them */
1273 1266
1274 cflag = port->tty->termios->c_cflag;
1275 device_port = port->number - port->serial->minor; 1267 device_port = port->number - port->serial->minor;
1276 1268 if (tty) {
1277 /* Baud rate calculation takes baud rate as an integer 1269 cflag = tty->termios->c_cflag;
1278 so other rates can be generated if desired. */ 1270 /* Baud rate calculation takes baud rate as an integer
1279 baud_rate = tty_get_baud_rate(port->tty); 1271 so other rates can be generated if desired. */
1280 /* If no match or invalid, leave as default */ 1272 baud_rate = tty_get_baud_rate(tty);
1281 if (baud_rate >= 0 1273 /* If no match or invalid, leave as default */
1282 && d_details->calculate_baud_rate(baud_rate, d_details->baudclk, 1274 if (baud_rate >= 0
1283 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) { 1275 && d_details->calculate_baud_rate(baud_rate, d_details->baudclk,
1284 p_priv->baud = baud_rate; 1276 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1277 p_priv->baud = baud_rate;
1278 }
1285 } 1279 }
1286
1287 /* set CTS/RTS handshake etc. */ 1280 /* set CTS/RTS handshake etc. */
1288 p_priv->cflag = cflag; 1281 p_priv->cflag = cflag;
1289 p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none; 1282 p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none;
1290 1283
1291 keyspan_send_setup(port, 1); 1284 keyspan_send_setup(port, 1);
1292 //mdelay(100); 1285 /* mdelay(100); */
1293 //keyspan_set_termios(port, NULL); 1286 /* keyspan_set_termios(port, NULL); */
1294 1287
1295 return 0; 1288 return 0;
1296} 1289}
@@ -1301,7 +1294,8 @@ static inline void stop_urb(struct urb *urb)
1301 usb_kill_urb(urb); 1294 usb_kill_urb(urb);
1302} 1295}
1303 1296
1304static void keyspan_close(struct usb_serial_port *port, struct file *filp) 1297static void keyspan_close(struct tty_struct *tty,
1298 struct usb_serial_port *port, struct file *filp)
1305{ 1299{
1306 int i; 1300 int i;
1307 struct usb_serial *serial = port->serial; 1301 struct usb_serial *serial = port->serial;
@@ -1311,15 +1305,15 @@ static void keyspan_close(struct usb_serial_port *port, struct file *filp)
1311 dbg("%s", __func__); 1305 dbg("%s", __func__);
1312 s_priv = usb_get_serial_data(serial); 1306 s_priv = usb_get_serial_data(serial);
1313 p_priv = usb_get_serial_port_data(port); 1307 p_priv = usb_get_serial_port_data(port);
1314 1308
1315 p_priv->rts_state = 0; 1309 p_priv->rts_state = 0;
1316 p_priv->dtr_state = 0; 1310 p_priv->dtr_state = 0;
1317 1311
1318 if (serial->dev) { 1312 if (serial->dev) {
1319 keyspan_send_setup(port, 2); 1313 keyspan_send_setup(port, 2);
1320 /* pilot-xfer seems to work best with this delay */ 1314 /* pilot-xfer seems to work best with this delay */
1321 mdelay(100); 1315 mdelay(100);
1322 // keyspan_set_termios(port, NULL); 1316 /* keyspan_set_termios(port, NULL); */
1323 } 1317 }
1324 1318
1325 /*while (p_priv->outcont_urb->status == -EINPROGRESS) { 1319 /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
@@ -1338,11 +1332,11 @@ static void keyspan_close(struct usb_serial_port *port, struct file *filp)
1338 stop_urb(p_priv->out_urbs[i]); 1332 stop_urb(p_priv->out_urbs[i]);
1339 } 1333 }
1340 } 1334 }
1341 port->tty = NULL; 1335 port->port.tty = NULL;
1342} 1336}
1343 1337
1344 /* download the firmware to a pre-renumeration device */ 1338/* download the firmware to a pre-renumeration device */
1345static int keyspan_fake_startup (struct usb_serial *serial) 1339static int keyspan_fake_startup(struct usb_serial *serial)
1346{ 1340{
1347 int response; 1341 int response;
1348 const struct ihex_binrec *record; 1342 const struct ihex_binrec *record;
@@ -1352,10 +1346,11 @@ static int keyspan_fake_startup (struct usb_serial *serial)
1352 dbg("Keyspan startup version %04x product %04x", 1346 dbg("Keyspan startup version %04x product %04x",
1353 le16_to_cpu(serial->dev->descriptor.bcdDevice), 1347 le16_to_cpu(serial->dev->descriptor.bcdDevice),
1354 le16_to_cpu(serial->dev->descriptor.idProduct)); 1348 le16_to_cpu(serial->dev->descriptor.idProduct));
1355 1349
1356 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000) != 0x8000) { 1350 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
1351 != 0x8000) {
1357 dbg("Firmware already loaded. Quitting."); 1352 dbg("Firmware already loaded. Quitting.");
1358 return(1); 1353 return 1;
1359 } 1354 }
1360 1355
1361 /* Select firmware image on the basis of idProduct */ 1356 /* Select firmware image on the basis of idProduct */
@@ -1379,11 +1374,11 @@ static int keyspan_fake_startup (struct usb_serial *serial)
1379 case keyspan_usa19_pre_product_id: 1374 case keyspan_usa19_pre_product_id:
1380 fw_name = "keyspan/usa19.fw"; 1375 fw_name = "keyspan/usa19.fw";
1381 break; 1376 break;
1382 1377
1383 case keyspan_usa19qi_pre_product_id: 1378 case keyspan_usa19qi_pre_product_id:
1384 fw_name = "keyspan/usa19qi.fw"; 1379 fw_name = "keyspan/usa19qi.fw";
1385 break; 1380 break;
1386 1381
1387 case keyspan_mpr_pre_product_id: 1382 case keyspan_mpr_pre_product_id:
1388 fw_name = "keyspan/mpr.fw"; 1383 fw_name = "keyspan/mpr.fw";
1389 break; 1384 break;
@@ -1391,15 +1386,15 @@ static int keyspan_fake_startup (struct usb_serial *serial)
1391 case keyspan_usa19qw_pre_product_id: 1386 case keyspan_usa19qw_pre_product_id:
1392 fw_name = "keyspan/usa19qw.fw"; 1387 fw_name = "keyspan/usa19qw.fw";
1393 break; 1388 break;
1394 1389
1395 case keyspan_usa18x_pre_product_id: 1390 case keyspan_usa18x_pre_product_id:
1396 fw_name = "keyspan/usa18x.fw"; 1391 fw_name = "keyspan/usa18x.fw";
1397 break; 1392 break;
1398 1393
1399 case keyspan_usa19w_pre_product_id: 1394 case keyspan_usa19w_pre_product_id:
1400 fw_name = "keyspan/usa19w.fw"; 1395 fw_name = "keyspan/usa19w.fw";
1401 break; 1396 break;
1402 1397
1403 case keyspan_usa49w_pre_product_id: 1398 case keyspan_usa49w_pre_product_id:
1404 fw_name = "keyspan/usa49w.fw"; 1399 fw_name = "keyspan/usa49w.fw";
1405 break; 1400 break;
@@ -1431,8 +1426,7 @@ static int keyspan_fake_startup (struct usb_serial *serial)
1431 (unsigned char *)record->data, 1426 (unsigned char *)record->data,
1432 be16_to_cpu(record->len), 0xa0); 1427 be16_to_cpu(record->len), 0xa0);
1433 if (response < 0) { 1428 if (response < 0) {
1434 dev_err(&serial->dev->dev, "ezusb_writememory failed for Keyspan" 1429 dev_err(&serial->dev->dev, "ezusb_writememory failed for Keyspan firmware (%d %04X %p %d)\n",
1435 "firmware (%d %04X %p %d)\n",
1436 response, be32_to_cpu(record->addr), 1430 response, be32_to_cpu(record->addr),
1437 record->data, be16_to_cpu(record->len)); 1431 record->data, be16_to_cpu(record->len));
1438 break; 1432 break;
@@ -1445,7 +1439,7 @@ static int keyspan_fake_startup (struct usb_serial *serial)
1445 response = ezusb_set_reset(serial, 0); 1439 response = ezusb_set_reset(serial, 0);
1446 1440
1447 /* we don't want this device to have a driver assigned to it. */ 1441 /* we don't want this device to have a driver assigned to it. */
1448 return (1); 1442 return 1;
1449} 1443}
1450 1444
1451/* Helper functions used by keyspan_setup_urbs */ 1445/* Helper functions used by keyspan_setup_urbs */
@@ -1467,7 +1461,7 @@ static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *se
1467 return NULL; 1461 return NULL;
1468} 1462}
1469 1463
1470static struct urb *keyspan_setup_urb (struct usb_serial *serial, int endpoint, 1464static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1471 int dir, void *ctx, char *buf, int len, 1465 int dir, void *ctx, char *buf, int len,
1472 void (*callback)(struct urb *)) 1466 void (*callback)(struct urb *))
1473{ 1467{
@@ -1478,10 +1472,10 @@ static struct urb *keyspan_setup_urb (struct usb_serial *serial, int endpoint,
1478 if (endpoint == -1) 1472 if (endpoint == -1)
1479 return NULL; /* endpoint not needed */ 1473 return NULL; /* endpoint not needed */
1480 1474
1481 dbg ("%s - alloc for endpoint %d.", __func__, endpoint); 1475 dbg("%s - alloc for endpoint %d.", __func__, endpoint);
1482 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ 1476 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1483 if (urb == NULL) { 1477 if (urb == NULL) {
1484 dbg ("%s - alloc for endpoint %d failed.", __func__, endpoint); 1478 dbg("%s - alloc for endpoint %d failed.", __func__, endpoint);
1485 return NULL; 1479 return NULL;
1486 } 1480 }
1487 1481
@@ -1554,7 +1548,7 @@ static struct callbacks {
1554 }, { 1548 }, {
1555 /* msg_usa90 callbacks */ 1549 /* msg_usa90 callbacks */
1556 .instat_callback = usa90_instat_callback, 1550 .instat_callback = usa90_instat_callback,
1557 .glocont_callback = usa28_glocont_callback, 1551 .glocont_callback = usa28_glocont_callback,
1558 .indat_callback = usa90_indat_callback, 1552 .indat_callback = usa90_indat_callback,
1559 .outdat_callback = usa2x_outdat_callback, 1553 .outdat_callback = usa2x_outdat_callback,
1560 .inack_callback = usa28_inack_callback, 1554 .inack_callback = usa28_inack_callback,
@@ -1582,16 +1576,16 @@ static void keyspan_setup_urbs(struct usb_serial *serial)
1582 struct callbacks *cback; 1576 struct callbacks *cback;
1583 int endp; 1577 int endp;
1584 1578
1585 dbg ("%s", __func__); 1579 dbg("%s", __func__);
1586 1580
1587 s_priv = usb_get_serial_data(serial); 1581 s_priv = usb_get_serial_data(serial);
1588 d_details = s_priv->device_details; 1582 d_details = s_priv->device_details;
1589 1583
1590 /* Setup values for the various callback routines */ 1584 /* Setup values for the various callback routines */
1591 cback = &keyspan_callbacks[d_details->msg_format]; 1585 cback = &keyspan_callbacks[d_details->msg_format];
1592 1586
1593 /* Allocate and set up urbs for each one that is in use, 1587 /* Allocate and set up urbs for each one that is in use,
1594 starting with instat endpoints */ 1588 starting with instat endpoints */
1595 s_priv->instat_urb = keyspan_setup_urb 1589 s_priv->instat_urb = keyspan_setup_urb
1596 (serial, d_details->instat_endpoint, USB_DIR_IN, 1590 (serial, d_details->instat_endpoint, USB_DIR_IN,
1597 serial, s_priv->instat_buf, INSTAT_BUFLEN, 1591 serial, s_priv->instat_buf, INSTAT_BUFLEN,
@@ -1607,8 +1601,8 @@ static void keyspan_setup_urbs(struct usb_serial *serial)
1607 serial, s_priv->glocont_buf, GLOCONT_BUFLEN, 1601 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1608 cback->glocont_callback); 1602 cback->glocont_callback);
1609 1603
1610 /* Setup endpoints for each port specific thing */ 1604 /* Setup endpoints for each port specific thing */
1611 for (i = 0; i < d_details->num_ports; i ++) { 1605 for (i = 0; i < d_details->num_ports; i++) {
1612 port = serial->port[i]; 1606 port = serial->port[i];
1613 p_priv = usb_get_serial_port_data(port); 1607 p_priv = usb_get_serial_port_data(port);
1614 1608
@@ -1644,8 +1638,7 @@ static void keyspan_setup_urbs(struct usb_serial *serial)
1644 (serial, d_details->outcont_endpoints[i], USB_DIR_OUT, 1638 (serial, d_details->outcont_endpoints[i], USB_DIR_OUT,
1645 port, p_priv->outcont_buffer, 64, 1639 port, p_priv->outcont_buffer, 64,
1646 cback->outcont_callback); 1640 cback->outcont_callback);
1647 } 1641 }
1648
1649} 1642}
1650 1643
1651/* usa19 function doesn't require prescaler */ 1644/* usa19 function doesn't require prescaler */
@@ -1653,46 +1646,39 @@ static int keyspan_usa19_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1653 u8 *rate_low, u8 *prescaler, int portnum) 1646 u8 *rate_low, u8 *prescaler, int portnum)
1654{ 1647{
1655 u32 b16, /* baud rate times 16 (actual rate used internally) */ 1648 u32 b16, /* baud rate times 16 (actual rate used internally) */
1656 div, /* divisor */ 1649 div, /* divisor */
1657 cnt; /* inverse of divisor (programmed into 8051) */ 1650 cnt; /* inverse of divisor (programmed into 8051) */
1658
1659 dbg ("%s - %d.", __func__, baud_rate);
1660
1661 /* prevent divide by zero... */
1662 if( (b16 = (baud_rate * 16L)) == 0) {
1663 return (KEYSPAN_INVALID_BAUD_RATE);
1664 }
1665 1651
1666 /* Any "standard" rate over 57k6 is marginal on the USA-19 1652 dbg("%s - %d.", __func__, baud_rate);
1667 as we run out of divisor resolution. */ 1653
1668 if (baud_rate > 57600) { 1654 /* prevent divide by zero... */
1669 return (KEYSPAN_INVALID_BAUD_RATE); 1655 b16 = baud_rate * 16L;
1670 } 1656 if (b16 == 0)
1671 1657 return KEYSPAN_INVALID_BAUD_RATE;
1672 /* calculate the divisor and the counter (its inverse) */ 1658 /* Any "standard" rate over 57k6 is marginal on the USA-19
1673 if( (div = (baudclk / b16)) == 0) { 1659 as we run out of divisor resolution. */
1674 return (KEYSPAN_INVALID_BAUD_RATE); 1660 if (baud_rate > 57600)
1675 } 1661 return KEYSPAN_INVALID_BAUD_RATE;
1676 else { 1662
1663 /* calculate the divisor and the counter (its inverse) */
1664 div = baudclk / b16;
1665 if (div == 0)
1666 return KEYSPAN_INVALID_BAUD_RATE;
1667 else
1677 cnt = 0 - div; 1668 cnt = 0 - div;
1678 }
1679 1669
1680 if(div > 0xffff) { 1670 if (div > 0xffff)
1681 return (KEYSPAN_INVALID_BAUD_RATE); 1671 return KEYSPAN_INVALID_BAUD_RATE;
1682 }
1683 1672
1684 /* return the counter values if non-null */ 1673 /* return the counter values if non-null */
1685 if (rate_low) { 1674 if (rate_low)
1686 *rate_low = (u8) (cnt & 0xff); 1675 *rate_low = (u8) (cnt & 0xff);
1687 } 1676 if (rate_hi)
1688 if (rate_hi) {
1689 *rate_hi = (u8) ((cnt >> 8) & 0xff); 1677 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1690 } 1678 if (rate_low && rate_hi)
1691 if (rate_low && rate_hi) { 1679 dbg("%s - %d %02x %02x.",
1692 dbg ("%s - %d %02x %02x.", __func__, baud_rate, *rate_hi, *rate_low); 1680 __func__, baud_rate, *rate_hi, *rate_low);
1693 } 1681 return KEYSPAN_BAUD_RATE_OK;
1694
1695 return (KEYSPAN_BAUD_RATE_OK);
1696} 1682}
1697 1683
1698/* usa19hs function doesn't require prescaler */ 1684/* usa19hs function doesn't require prescaler */
@@ -1700,34 +1686,35 @@ static int keyspan_usa19hs_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1700 u8 *rate_low, u8 *prescaler, int portnum) 1686 u8 *rate_low, u8 *prescaler, int portnum)
1701{ 1687{
1702 u32 b16, /* baud rate times 16 (actual rate used internally) */ 1688 u32 b16, /* baud rate times 16 (actual rate used internally) */
1703 div; /* divisor */ 1689 div; /* divisor */
1704
1705 dbg ("%s - %d.", __func__, baud_rate);
1706 1690
1707 /* prevent divide by zero... */ 1691 dbg("%s - %d.", __func__, baud_rate);
1708 if( (b16 = (baud_rate * 16L)) == 0)
1709 return (KEYSPAN_INVALID_BAUD_RATE);
1710
1711 1692
1693 /* prevent divide by zero... */
1694 b16 = baud_rate * 16L;
1695 if (b16 == 0)
1696 return KEYSPAN_INVALID_BAUD_RATE;
1712 1697
1713 /* calculate the divisor */ 1698 /* calculate the divisor */
1714 if( (div = (baudclk / b16)) == 0) 1699 div = baudclk / b16;
1715 return (KEYSPAN_INVALID_BAUD_RATE); 1700 if (div == 0)
1701 return KEYSPAN_INVALID_BAUD_RATE;
1716 1702
1717 if(div > 0xffff) 1703 if (div > 0xffff)
1718 return (KEYSPAN_INVALID_BAUD_RATE); 1704 return KEYSPAN_INVALID_BAUD_RATE;
1719 1705
1720 /* return the counter values if non-null */ 1706 /* return the counter values if non-null */
1721 if (rate_low) 1707 if (rate_low)
1722 *rate_low = (u8) (div & 0xff); 1708 *rate_low = (u8) (div & 0xff);
1723 1709
1724 if (rate_hi) 1710 if (rate_hi)
1725 *rate_hi = (u8) ((div >> 8) & 0xff); 1711 *rate_hi = (u8) ((div >> 8) & 0xff);
1726 1712
1727 if (rate_low && rate_hi) 1713 if (rate_low && rate_hi)
1728 dbg ("%s - %d %02x %02x.", __func__, baud_rate, *rate_hi, *rate_low); 1714 dbg("%s - %d %02x %02x.",
1729 1715 __func__, baud_rate, *rate_hi, *rate_low);
1730 return (KEYSPAN_BAUD_RATE_OK); 1716
1717 return KEYSPAN_BAUD_RATE_OK;
1731} 1718}
1732 1719
1733static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi, 1720static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
@@ -1735,64 +1722,61 @@ static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1735{ 1722{
1736 u32 b16, /* baud rate times 16 (actual rate used internally) */ 1723 u32 b16, /* baud rate times 16 (actual rate used internally) */
1737 clk, /* clock with 13/8 prescaler */ 1724 clk, /* clock with 13/8 prescaler */
1738 div, /* divisor using 13/8 prescaler */ 1725 div, /* divisor using 13/8 prescaler */
1739 res, /* resulting baud rate using 13/8 prescaler */ 1726 res, /* resulting baud rate using 13/8 prescaler */
1740 diff, /* error using 13/8 prescaler */ 1727 diff, /* error using 13/8 prescaler */
1741 smallest_diff; 1728 smallest_diff;
1742 u8 best_prescaler; 1729 u8 best_prescaler;
1743 int i; 1730 int i;
1744 1731
1745 dbg ("%s - %d.", __func__, baud_rate); 1732 dbg("%s - %d.", __func__, baud_rate);
1746 1733
1747 /* prevent divide by zero */ 1734 /* prevent divide by zero */
1748 if( (b16 = baud_rate * 16L) == 0) { 1735 b16 = baud_rate * 16L;
1749 return (KEYSPAN_INVALID_BAUD_RATE); 1736 if (b16 == 0)
1750 } 1737 return KEYSPAN_INVALID_BAUD_RATE;
1751 1738
1752 /* Calculate prescaler by trying them all and looking 1739 /* Calculate prescaler by trying them all and looking
1753 for best fit */ 1740 for best fit */
1754 1741
1755 /* start with largest possible difference */ 1742 /* start with largest possible difference */
1756 smallest_diff = 0xffffffff; 1743 smallest_diff = 0xffffffff;
1757 1744
1758 /* 0 is an invalid prescaler, used as a flag */ 1745 /* 0 is an invalid prescaler, used as a flag */
1759 best_prescaler = 0; 1746 best_prescaler = 0;
1760 1747
1761 for(i = 8; i <= 0xff; ++i) { 1748 for (i = 8; i <= 0xff; ++i) {
1762 clk = (baudclk * 8) / (u32) i; 1749 clk = (baudclk * 8) / (u32) i;
1763 1750
1764 if( (div = clk / b16) == 0) { 1751 div = clk / b16;
1752 if (div == 0)
1765 continue; 1753 continue;
1766 }
1767 1754
1768 res = clk / div; 1755 res = clk / div;
1769 diff= (res > b16) ? (res-b16) : (b16-res); 1756 diff = (res > b16) ? (res-b16) : (b16-res);
1770 1757
1771 if(diff < smallest_diff) { 1758 if (diff < smallest_diff) {
1772 best_prescaler = i; 1759 best_prescaler = i;
1773 smallest_diff = diff; 1760 smallest_diff = diff;
1774 } 1761 }
1775 } 1762 }
1776 1763
1777 if(best_prescaler == 0) { 1764 if (best_prescaler == 0)
1778 return (KEYSPAN_INVALID_BAUD_RATE); 1765 return KEYSPAN_INVALID_BAUD_RATE;
1779 }
1780 1766
1781 clk = (baudclk * 8) / (u32) best_prescaler; 1767 clk = (baudclk * 8) / (u32) best_prescaler;
1782 div = clk / b16; 1768 div = clk / b16;
1783 1769
1784 /* return the divisor and prescaler if non-null */ 1770 /* return the divisor and prescaler if non-null */
1785 if (rate_low) { 1771 if (rate_low)
1786 *rate_low = (u8) (div & 0xff); 1772 *rate_low = (u8) (div & 0xff);
1787 } 1773 if (rate_hi)
1788 if (rate_hi) {
1789 *rate_hi = (u8) ((div >> 8) & 0xff); 1774 *rate_hi = (u8) ((div >> 8) & 0xff);
1790 }
1791 if (prescaler) { 1775 if (prescaler) {
1792 *prescaler = best_prescaler; 1776 *prescaler = best_prescaler;
1793 /* dbg("%s - %d %d", __func__, *prescaler, div); */ 1777 /* dbg("%s - %d %d", __func__, *prescaler, div); */
1794 } 1778 }
1795 return (KEYSPAN_BAUD_RATE_OK); 1779 return KEYSPAN_BAUD_RATE_OK;
1796} 1780}
1797 1781
1798 /* USA-28 supports different maximum baud rates on each port */ 1782 /* USA-28 supports different maximum baud rates on each port */
@@ -1800,57 +1784,51 @@ static int keyspan_usa28_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1800 u8 *rate_low, u8 *prescaler, int portnum) 1784 u8 *rate_low, u8 *prescaler, int portnum)
1801{ 1785{
1802 u32 b16, /* baud rate times 16 (actual rate used internally) */ 1786 u32 b16, /* baud rate times 16 (actual rate used internally) */
1803 div, /* divisor */ 1787 div, /* divisor */
1804 cnt; /* inverse of divisor (programmed into 8051) */ 1788 cnt; /* inverse of divisor (programmed into 8051) */
1805 1789
1806 dbg ("%s - %d.", __func__, baud_rate); 1790 dbg("%s - %d.", __func__, baud_rate);
1807 1791
1808 /* prevent divide by zero */ 1792 /* prevent divide by zero */
1809 if ((b16 = baud_rate * 16L) == 0) 1793 b16 = baud_rate * 16L;
1810 return (KEYSPAN_INVALID_BAUD_RATE); 1794 if (b16 == 0)
1811 1795 return KEYSPAN_INVALID_BAUD_RATE;
1812 /* calculate the divisor and the counter (its inverse) */ 1796
1813 if ((div = (KEYSPAN_USA28_BAUDCLK / b16)) == 0) { 1797 /* calculate the divisor and the counter (its inverse) */
1814 return (KEYSPAN_INVALID_BAUD_RATE); 1798 div = KEYSPAN_USA28_BAUDCLK / b16;
1815 } 1799 if (div == 0)
1816 else { 1800 return KEYSPAN_INVALID_BAUD_RATE;
1801 else
1817 cnt = 0 - div; 1802 cnt = 0 - div;
1818 }
1819 1803
1820 /* check for out of range, based on portnum, 1804 /* check for out of range, based on portnum,
1821 and return result */ 1805 and return result */
1822 if(portnum == 0) { 1806 if (portnum == 0) {
1823 if(div > 0xffff) 1807 if (div > 0xffff)
1824 return (KEYSPAN_INVALID_BAUD_RATE); 1808 return KEYSPAN_INVALID_BAUD_RATE;
1825 } 1809 } else {
1826 else { 1810 if (portnum == 1) {
1827 if(portnum == 1) { 1811 if (div > 0xff)
1828 if(div > 0xff) { 1812 return KEYSPAN_INVALID_BAUD_RATE;
1829 return (KEYSPAN_INVALID_BAUD_RATE); 1813 } else
1830 } 1814 return KEYSPAN_INVALID_BAUD_RATE;
1831 }
1832 else {
1833 return (KEYSPAN_INVALID_BAUD_RATE);
1834 }
1835 } 1815 }
1836 1816
1837 /* return the counter values if not NULL 1817 /* return the counter values if not NULL
1838 (port 1 will ignore retHi) */ 1818 (port 1 will ignore retHi) */
1839 if (rate_low) { 1819 if (rate_low)
1840 *rate_low = (u8) (cnt & 0xff); 1820 *rate_low = (u8) (cnt & 0xff);
1841 } 1821 if (rate_hi)
1842 if (rate_hi) {
1843 *rate_hi = (u8) ((cnt >> 8) & 0xff); 1822 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1844 } 1823 dbg("%s - %d OK.", __func__, baud_rate);
1845 dbg ("%s - %d OK.", __func__, baud_rate); 1824 return KEYSPAN_BAUD_RATE_OK;
1846 return (KEYSPAN_BAUD_RATE_OK);
1847} 1825}
1848 1826
1849static int keyspan_usa26_send_setup(struct usb_serial *serial, 1827static int keyspan_usa26_send_setup(struct usb_serial *serial,
1850 struct usb_serial_port *port, 1828 struct usb_serial_port *port,
1851 int reset_port) 1829 int reset_port)
1852{ 1830{
1853 struct keyspan_usa26_portControlMessage msg; 1831 struct keyspan_usa26_portControlMessage msg;
1854 struct keyspan_serial_private *s_priv; 1832 struct keyspan_serial_private *s_priv;
1855 struct keyspan_port_private *p_priv; 1833 struct keyspan_port_private *p_priv;
1856 const struct keyspan_device_details *d_details; 1834 const struct keyspan_device_details *d_details;
@@ -1858,7 +1836,7 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1858 struct urb *this_urb; 1836 struct urb *this_urb;
1859 int device_port, err; 1837 int device_port, err;
1860 1838
1861 dbg ("%s reset=%d", __func__, reset_port); 1839 dbg("%s reset=%d", __func__, reset_port);
1862 1840
1863 s_priv = usb_get_serial_data(serial); 1841 s_priv = usb_get_serial_data(serial);
1864 p_priv = usb_get_serial_port_data(port); 1842 p_priv = usb_get_serial_port_data(port);
@@ -1881,22 +1859,22 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1881 if ((reset_port + 1) > p_priv->resend_cont) 1859 if ((reset_port + 1) > p_priv->resend_cont)
1882 p_priv->resend_cont = reset_port + 1; 1860 p_priv->resend_cont = reset_port + 1;
1883 if (this_urb->status == -EINPROGRESS) { 1861 if (this_urb->status == -EINPROGRESS) {
1884 /* dbg ("%s - already writing", __func__); */ 1862 /* dbg("%s - already writing", __func__); */
1885 mdelay(5); 1863 mdelay(5);
1886 return(-1); 1864 return -1;
1887 } 1865 }
1888 1866
1889 memset(&msg, 0, sizeof (struct keyspan_usa26_portControlMessage)); 1867 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1890 1868
1891 /* Only set baud rate if it's changed */ 1869 /* Only set baud rate if it's changed */
1892 if (p_priv->old_baud != p_priv->baud) { 1870 if (p_priv->old_baud != p_priv->baud) {
1893 p_priv->old_baud = p_priv->baud; 1871 p_priv->old_baud = p_priv->baud;
1894 msg.setClocking = 0xff; 1872 msg.setClocking = 0xff;
1895 if (d_details->calculate_baud_rate 1873 if (d_details->calculate_baud_rate
1896 (p_priv->baud, d_details->baudclk, &msg.baudHi, 1874 (p_priv->baud, d_details->baudclk, &msg.baudHi,
1897 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 1875 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1898 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__, 1876 dbg("%s - Invalid baud rate %d requested, using 9600.",
1899 p_priv->baud); 1877 __func__, p_priv->baud);
1900 msg.baudLo = 0; 1878 msg.baudLo = 0;
1901 msg.baudHi = 125; /* Values for 9600 baud */ 1879 msg.baudHi = 125; /* Values for 9600 baud */
1902 msg.prescaler = 10; 1880 msg.prescaler = 10;
@@ -1922,7 +1900,7 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1922 if (p_priv->cflag & PARENB) { 1900 if (p_priv->cflag & PARENB) {
1923 /* note USA_PARITY_NONE == 0 */ 1901 /* note USA_PARITY_NONE == 0 */
1924 msg.lcr |= (p_priv->cflag & PARODD)? 1902 msg.lcr |= (p_priv->cflag & PARODD)?
1925 USA_PARITY_ODD: USA_PARITY_EVEN; 1903 USA_PARITY_ODD : USA_PARITY_EVEN;
1926 } 1904 }
1927 msg.setLcr = 0xff; 1905 msg.setLcr = 0xff;
1928 1906
@@ -1963,7 +1941,7 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1963 1941
1964 /* Sending intermediate configs */ 1942 /* Sending intermediate configs */
1965 else { 1943 else {
1966 msg._txOn = (! p_priv->break_on); 1944 msg._txOn = (!p_priv->break_on);
1967 msg._txOff = 0; 1945 msg._txOff = 0;
1968 msg.txFlush = 0; 1946 msg.txFlush = 0;
1969 msg.txBreak = (p_priv->break_on); 1947 msg.txBreak = (p_priv->break_on);
@@ -1975,23 +1953,23 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1975 msg.resetDataToggle = 0x0; 1953 msg.resetDataToggle = 0x0;
1976 } 1954 }
1977 1955
1978 /* Do handshaking outputs */ 1956 /* Do handshaking outputs */
1979 msg.setTxTriState_setRts = 0xff; 1957 msg.setTxTriState_setRts = 0xff;
1980 msg.txTriState_rts = p_priv->rts_state; 1958 msg.txTriState_rts = p_priv->rts_state;
1981 1959
1982 msg.setHskoa_setDtr = 0xff; 1960 msg.setHskoa_setDtr = 0xff;
1983 msg.hskoa_dtr = p_priv->dtr_state; 1961 msg.hskoa_dtr = p_priv->dtr_state;
1984 1962
1985 p_priv->resend_cont = 0; 1963 p_priv->resend_cont = 0;
1986 memcpy (this_urb->transfer_buffer, &msg, sizeof(msg)); 1964 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1987 1965
1988 /* send the data out the device on control endpoint */ 1966 /* send the data out the device on control endpoint */
1989 this_urb->transfer_buffer_length = sizeof(msg); 1967 this_urb->transfer_buffer_length = sizeof(msg);
1990 1968
1991 this_urb->dev = serial->dev; 1969 this_urb->dev = serial->dev;
1992 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 1970 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1971 if (err != 0)
1993 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err); 1972 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
1994 }
1995#if 0 1973#if 0
1996 else { 1974 else {
1997 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__ 1975 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__
@@ -2007,14 +1985,14 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2007 struct usb_serial_port *port, 1985 struct usb_serial_port *port,
2008 int reset_port) 1986 int reset_port)
2009{ 1987{
2010 struct keyspan_usa28_portControlMessage msg; 1988 struct keyspan_usa28_portControlMessage msg;
2011 struct keyspan_serial_private *s_priv; 1989 struct keyspan_serial_private *s_priv;
2012 struct keyspan_port_private *p_priv; 1990 struct keyspan_port_private *p_priv;
2013 const struct keyspan_device_details *d_details; 1991 const struct keyspan_device_details *d_details;
2014 struct urb *this_urb; 1992 struct urb *this_urb;
2015 int device_port, err; 1993 int device_port, err;
2016 1994
2017 dbg ("%s", __func__); 1995 dbg("%s", __func__);
2018 1996
2019 s_priv = usb_get_serial_data(serial); 1997 s_priv = usb_get_serial_data(serial);
2020 p_priv = usb_get_serial_port_data(port); 1998 p_priv = usb_get_serial_port_data(port);
@@ -2022,7 +2000,8 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2022 device_port = port->number - port->serial->minor; 2000 device_port = port->number - port->serial->minor;
2023 2001
2024 /* only do something if we have a bulk out endpoint */ 2002 /* only do something if we have a bulk out endpoint */
2025 if ((this_urb = p_priv->outcont_urb) == NULL) { 2003 this_urb = p_priv->outcont_urb;
2004 if (this_urb == NULL) {
2026 dbg("%s - oops no urb.", __func__); 2005 dbg("%s - oops no urb.", __func__);
2027 return -1; 2006 return -1;
2028 } 2007 }
@@ -2032,17 +2011,18 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2032 if ((reset_port + 1) > p_priv->resend_cont) 2011 if ((reset_port + 1) > p_priv->resend_cont)
2033 p_priv->resend_cont = reset_port + 1; 2012 p_priv->resend_cont = reset_port + 1;
2034 if (this_urb->status == -EINPROGRESS) { 2013 if (this_urb->status == -EINPROGRESS) {
2035 dbg ("%s already writing", __func__); 2014 dbg("%s already writing", __func__);
2036 mdelay(5); 2015 mdelay(5);
2037 return(-1); 2016 return -1;
2038 } 2017 }
2039 2018
2040 memset(&msg, 0, sizeof (struct keyspan_usa28_portControlMessage)); 2019 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
2041 2020
2042 msg.setBaudRate = 1; 2021 msg.setBaudRate = 1;
2043 if (d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk, 2022 if (d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk,
2044 &msg.baudHi, &msg.baudLo, NULL, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 2023 &msg.baudHi, &msg.baudLo, NULL, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2045 dbg("%s - Invalid baud rate requested %d.", __func__, p_priv->baud); 2024 dbg("%s - Invalid baud rate requested %d.",
2025 __func__, p_priv->baud);
2046 msg.baudLo = 0xff; 2026 msg.baudLo = 0xff;
2047 msg.baudHi = 0xb2; /* Values for 9600 baud */ 2027 msg.baudHi = 0xb2; /* Values for 9600 baud */
2048 } 2028 }
@@ -2053,7 +2033,7 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2053 msg.ctsFlowControl = (p_priv->flow_control == flow_cts); 2033 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2054 msg.xonFlowControl = 0; 2034 msg.xonFlowControl = 0;
2055 2035
2056 /* Do handshaking outputs, DTR is inverted relative to RTS */ 2036 /* Do handshaking outputs, DTR is inverted relative to RTS */
2057 msg.rts = p_priv->rts_state; 2037 msg.rts = p_priv->rts_state;
2058 msg.dtr = p_priv->dtr_state; 2038 msg.dtr = p_priv->dtr_state;
2059 2039
@@ -2095,7 +2075,7 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2095 } 2075 }
2096 /* Sending intermediate configs */ 2076 /* Sending intermediate configs */
2097 else { 2077 else {
2098 msg._txOn = (! p_priv->break_on); 2078 msg._txOn = (!p_priv->break_on);
2099 msg._txOff = 0; 2079 msg._txOff = 0;
2100 msg.txFlush = 0; 2080 msg.txFlush = 0;
2101 msg.txForceXoff = 0; 2081 msg.txForceXoff = 0;
@@ -2109,15 +2089,15 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2109 } 2089 }
2110 2090
2111 p_priv->resend_cont = 0; 2091 p_priv->resend_cont = 0;
2112 memcpy (this_urb->transfer_buffer, &msg, sizeof(msg)); 2092 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2113 2093
2114 /* send the data out the device on control endpoint */ 2094 /* send the data out the device on control endpoint */
2115 this_urb->transfer_buffer_length = sizeof(msg); 2095 this_urb->transfer_buffer_length = sizeof(msg);
2116 2096
2117 this_urb->dev = serial->dev; 2097 this_urb->dev = serial->dev;
2118 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 2098 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2099 if (err != 0)
2119 dbg("%s - usb_submit_urb(setup) failed", __func__); 2100 dbg("%s - usb_submit_urb(setup) failed", __func__);
2120 }
2121#if 0 2101#if 0
2122 else { 2102 else {
2123 dbg("%s - usb_submit_urb(setup) OK %d bytes", __func__, 2103 dbg("%s - usb_submit_urb(setup) OK %d bytes", __func__,
@@ -2140,7 +2120,7 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2140 struct urb *this_urb; 2120 struct urb *this_urb;
2141 int err, device_port; 2121 int err, device_port;
2142 2122
2143 dbg ("%s", __func__); 2123 dbg("%s", __func__);
2144 2124
2145 s_priv = usb_get_serial_data(serial); 2125 s_priv = usb_get_serial_data(serial);
2146 p_priv = usb_get_serial_port_data(port); 2126 p_priv = usb_get_serial_port_data(port);
@@ -2151,7 +2131,9 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2151 /* Work out which port within the device is being setup */ 2131 /* Work out which port within the device is being setup */
2152 device_port = port->number - port->serial->minor; 2132 device_port = port->number - port->serial->minor;
2153 2133
2154 dbg("%s - endpoint %d port %d (%d)",__func__, usb_pipeendpoint(this_urb->pipe), port->number, device_port); 2134 dbg("%s - endpoint %d port %d (%d)",
2135 __func__, usb_pipeendpoint(this_urb->pipe),
2136 port->number, device_port);
2155 2137
2156 /* Make sure we have an urb then send the message */ 2138 /* Make sure we have an urb then send the message */
2157 if (this_urb == NULL) { 2139 if (this_urb == NULL) {
@@ -2165,30 +2147,30 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2165 p_priv->resend_cont = reset_port + 1; 2147 p_priv->resend_cont = reset_port + 1;
2166 2148
2167 if (this_urb->status == -EINPROGRESS) { 2149 if (this_urb->status == -EINPROGRESS) {
2168 /* dbg ("%s - already writing", __func__); */ 2150 /* dbg("%s - already writing", __func__); */
2169 mdelay(5); 2151 mdelay(5);
2170 return(-1); 2152 return -1;
2171 } 2153 }
2172 2154
2173 memset(&msg, 0, sizeof (struct keyspan_usa49_portControlMessage)); 2155 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
2174 2156
2175 /*msg.portNumber = port->number;*/ 2157 /*msg.portNumber = port->number;*/
2176 msg.portNumber = device_port; 2158 msg.portNumber = device_port;
2177 2159
2178 /* Only set baud rate if it's changed */ 2160 /* Only set baud rate if it's changed */
2179 if (p_priv->old_baud != p_priv->baud) { 2161 if (p_priv->old_baud != p_priv->baud) {
2180 p_priv->old_baud = p_priv->baud; 2162 p_priv->old_baud = p_priv->baud;
2181 msg.setClocking = 0xff; 2163 msg.setClocking = 0xff;
2182 if (d_details->calculate_baud_rate 2164 if (d_details->calculate_baud_rate
2183 (p_priv->baud, d_details->baudclk, &msg.baudHi, 2165 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2184 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 2166 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2185 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__, 2167 dbg("%s - Invalid baud rate %d requested, using 9600.",
2186 p_priv->baud); 2168 __func__, p_priv->baud);
2187 msg.baudLo = 0; 2169 msg.baudLo = 0;
2188 msg.baudHi = 125; /* Values for 9600 baud */ 2170 msg.baudHi = 125; /* Values for 9600 baud */
2189 msg.prescaler = 10; 2171 msg.prescaler = 10;
2190 } 2172 }
2191 //msg.setPrescaler = 0xff; 2173 /* msg.setPrescaler = 0xff; */
2192 } 2174 }
2193 2175
2194 msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1; 2176 msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1;
@@ -2209,19 +2191,19 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2209 if (p_priv->cflag & PARENB) { 2191 if (p_priv->cflag & PARENB) {
2210 /* note USA_PARITY_NONE == 0 */ 2192 /* note USA_PARITY_NONE == 0 */
2211 msg.lcr |= (p_priv->cflag & PARODD)? 2193 msg.lcr |= (p_priv->cflag & PARODD)?
2212 USA_PARITY_ODD: USA_PARITY_EVEN; 2194 USA_PARITY_ODD : USA_PARITY_EVEN;
2213 } 2195 }
2214 msg.setLcr = 0xff; 2196 msg.setLcr = 0xff;
2215 2197
2216 msg.ctsFlowControl = (p_priv->flow_control == flow_cts); 2198 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2217 msg.xonFlowControl = 0; 2199 msg.xonFlowControl = 0;
2218 msg.setFlowControl = 0xff; 2200 msg.setFlowControl = 0xff;
2219 2201
2220 msg.forwardingLength = 16; 2202 msg.forwardingLength = 16;
2221 msg.xonChar = 17; 2203 msg.xonChar = 17;
2222 msg.xoffChar = 19; 2204 msg.xoffChar = 19;
2223 2205
2224 /* Opening port */ 2206 /* Opening port */
2225 if (reset_port == 1) { 2207 if (reset_port == 1) {
2226 msg._txOn = 1; 2208 msg._txOn = 1;
2227 msg._txOff = 0; 2209 msg._txOff = 0;
@@ -2253,7 +2235,7 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2253 } 2235 }
2254 /* Sending intermediate configs */ 2236 /* Sending intermediate configs */
2255 else { 2237 else {
2256 msg._txOn = (! p_priv->break_on); 2238 msg._txOn = (!p_priv->break_on);
2257 msg._txOff = 0; 2239 msg._txOff = 0;
2258 msg.txFlush = 0; 2240 msg.txFlush = 0;
2259 msg.txBreak = (p_priv->break_on); 2241 msg.txBreak = (p_priv->break_on);
@@ -2267,16 +2249,17 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2267 msg.disablePort = 0; 2249 msg.disablePort = 0;
2268 } 2250 }
2269 2251
2270 /* Do handshaking outputs */ 2252 /* Do handshaking outputs */
2271 msg.setRts = 0xff; 2253 msg.setRts = 0xff;
2272 msg.rts = p_priv->rts_state; 2254 msg.rts = p_priv->rts_state;
2273 2255
2274 msg.setDtr = 0xff; 2256 msg.setDtr = 0xff;
2275 msg.dtr = p_priv->dtr_state; 2257 msg.dtr = p_priv->dtr_state;
2276 2258
2277 p_priv->resend_cont = 0; 2259 p_priv->resend_cont = 0;
2278 2260
2279 /* if the device is a 49wg, we send control message on usb control EP 0 */ 2261 /* if the device is a 49wg, we send control message on usb
2262 control EP 0 */
2280 2263
2281 if (d_details->product_id == keyspan_usa49wg_product_id) { 2264 if (d_details->product_id == keyspan_usa49wg_product_id) {
2282 dr = (void *)(s_priv->ctrl_buf); 2265 dr = (void *)(s_priv->ctrl_buf);
@@ -2286,23 +2269,24 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2286 dr->wIndex = 0; 2269 dr->wIndex = 0;
2287 dr->wLength = cpu_to_le16(sizeof(msg)); 2270 dr->wLength = cpu_to_le16(sizeof(msg));
2288 2271
2289 memcpy (s_priv->glocont_buf, &msg, sizeof(msg)); 2272 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
2290 2273
2291 usb_fill_control_urb(this_urb, serial->dev, usb_sndctrlpipe(serial->dev, 0), 2274 usb_fill_control_urb(this_urb, serial->dev,
2292 (unsigned char *)dr, s_priv->glocont_buf, sizeof(msg), 2275 usb_sndctrlpipe(serial->dev, 0),
2293 usa49_glocont_callback, serial); 2276 (unsigned char *)dr, s_priv->glocont_buf,
2277 sizeof(msg), usa49_glocont_callback, serial);
2294 2278
2295 } else { 2279 } else {
2296 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg)); 2280 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2297 2281
2298 /* send the data out the device on control endpoint */ 2282 /* send the data out the device on control endpoint */
2299 this_urb->transfer_buffer_length = sizeof(msg); 2283 this_urb->transfer_buffer_length = sizeof(msg);
2300 2284
2301 this_urb->dev = serial->dev; 2285 this_urb->dev = serial->dev;
2302 } 2286 }
2303 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 2287 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2288 if (err != 0)
2304 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err); 2289 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
2305 }
2306#if 0 2290#if 0
2307 else { 2291 else {
2308 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__, 2292 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__,
@@ -2318,7 +2302,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2318 struct usb_serial_port *port, 2302 struct usb_serial_port *port,
2319 int reset_port) 2303 int reset_port)
2320{ 2304{
2321 struct keyspan_usa90_portControlMessage msg; 2305 struct keyspan_usa90_portControlMessage msg;
2322 struct keyspan_serial_private *s_priv; 2306 struct keyspan_serial_private *s_priv;
2323 struct keyspan_port_private *p_priv; 2307 struct keyspan_port_private *p_priv;
2324 const struct keyspan_device_details *d_details; 2308 const struct keyspan_device_details *d_details;
@@ -2326,14 +2310,15 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2326 int err; 2310 int err;
2327 u8 prescaler; 2311 u8 prescaler;
2328 2312
2329 dbg ("%s", __func__); 2313 dbg("%s", __func__);
2330 2314
2331 s_priv = usb_get_serial_data(serial); 2315 s_priv = usb_get_serial_data(serial);
2332 p_priv = usb_get_serial_port_data(port); 2316 p_priv = usb_get_serial_port_data(port);
2333 d_details = s_priv->device_details; 2317 d_details = s_priv->device_details;
2334 2318
2335 /* only do something if we have a bulk out endpoint */ 2319 /* only do something if we have a bulk out endpoint */
2336 if ((this_urb = p_priv->outcont_urb) == NULL) { 2320 this_urb = p_priv->outcont_urb;
2321 if (this_urb == NULL) {
2337 dbg("%s - oops no urb.", __func__); 2322 dbg("%s - oops no urb.", __func__);
2338 return -1; 2323 return -1;
2339 } 2324 }
@@ -2343,24 +2328,24 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2343 if ((reset_port + 1) > p_priv->resend_cont) 2328 if ((reset_port + 1) > p_priv->resend_cont)
2344 p_priv->resend_cont = reset_port + 1; 2329 p_priv->resend_cont = reset_port + 1;
2345 if (this_urb->status == -EINPROGRESS) { 2330 if (this_urb->status == -EINPROGRESS) {
2346 dbg ("%s already writing", __func__); 2331 dbg("%s already writing", __func__);
2347 mdelay(5); 2332 mdelay(5);
2348 return(-1); 2333 return -1;
2349 } 2334 }
2350 2335
2351 memset(&msg, 0, sizeof (struct keyspan_usa90_portControlMessage)); 2336 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2352 2337
2353 /* Only set baud rate if it's changed */ 2338 /* Only set baud rate if it's changed */
2354 if (p_priv->old_baud != p_priv->baud) { 2339 if (p_priv->old_baud != p_priv->baud) {
2355 p_priv->old_baud = p_priv->baud; 2340 p_priv->old_baud = p_priv->baud;
2356 msg.setClocking = 0x01; 2341 msg.setClocking = 0x01;
2357 if (d_details->calculate_baud_rate 2342 if (d_details->calculate_baud_rate
2358 (p_priv->baud, d_details->baudclk, &msg.baudHi, 2343 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2359 &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE ) { 2344 &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2360 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__, 2345 dbg("%s - Invalid baud rate %d requested, using 9600.",
2361 p_priv->baud); 2346 __func__, p_priv->baud);
2362 p_priv->baud = 9600; 2347 p_priv->baud = 9600;
2363 d_details->calculate_baud_rate (p_priv->baud, d_details->baudclk, 2348 d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk,
2364 &msg.baudHi, &msg.baudLo, &prescaler, 0); 2349 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2365 } 2350 }
2366 msg.setRxMode = 1; 2351 msg.setRxMode = 1;
@@ -2368,13 +2353,10 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2368 } 2353 }
2369 2354
2370 /* modes must always be correctly specified */ 2355 /* modes must always be correctly specified */
2371 if (p_priv->baud > 57600) 2356 if (p_priv->baud > 57600) {
2372 {
2373 msg.rxMode = RXMODE_DMA; 2357 msg.rxMode = RXMODE_DMA;
2374 msg.txMode = TXMODE_DMA; 2358 msg.txMode = TXMODE_DMA;
2375 } 2359 } else {
2376 else
2377 {
2378 msg.rxMode = RXMODE_BYHAND; 2360 msg.rxMode = RXMODE_BYHAND;
2379 msg.txMode = TXMODE_BYHAND; 2361 msg.txMode = TXMODE_BYHAND;
2380 } 2362 }
@@ -2397,7 +2379,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2397 if (p_priv->cflag & PARENB) { 2379 if (p_priv->cflag & PARENB) {
2398 /* note USA_PARITY_NONE == 0 */ 2380 /* note USA_PARITY_NONE == 0 */
2399 msg.lcr |= (p_priv->cflag & PARODD)? 2381 msg.lcr |= (p_priv->cflag & PARODD)?
2400 USA_PARITY_ODD: USA_PARITY_EVEN; 2382 USA_PARITY_ODD : USA_PARITY_EVEN;
2401 } 2383 }
2402 if (p_priv->old_cflag != p_priv->cflag) { 2384 if (p_priv->old_cflag != p_priv->cflag) {
2403 p_priv->old_cflag = p_priv->cflag; 2385 p_priv->old_cflag = p_priv->cflag;
@@ -2408,47 +2390,46 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2408 msg.txFlowControl = TXFLOW_CTS; 2390 msg.txFlowControl = TXFLOW_CTS;
2409 msg.setTxFlowControl = 0x01; 2391 msg.setTxFlowControl = 0x01;
2410 msg.setRxFlowControl = 0x01; 2392 msg.setRxFlowControl = 0x01;
2411 2393
2412 msg.rxForwardingLength = 16; 2394 msg.rxForwardingLength = 16;
2413 msg.rxForwardingTimeout = 16; 2395 msg.rxForwardingTimeout = 16;
2414 msg.txAckSetting = 0; 2396 msg.txAckSetting = 0;
2415 msg.xonChar = 17; 2397 msg.xonChar = 17;
2416 msg.xoffChar = 19; 2398 msg.xoffChar = 19;
2417 2399
2418 /* Opening port */ 2400 /* Opening port */
2419 if (reset_port == 1) { 2401 if (reset_port == 1) {
2420 msg.portEnabled = 1; 2402 msg.portEnabled = 1;
2421 msg.rxFlush = 1; 2403 msg.rxFlush = 1;
2422 msg.txBreak = (p_priv->break_on); 2404 msg.txBreak = (p_priv->break_on);
2423 } 2405 }
2424 /* Closing port */ 2406 /* Closing port */
2425 else if (reset_port == 2) { 2407 else if (reset_port == 2)
2426 msg.portEnabled = 0; 2408 msg.portEnabled = 0;
2427 }
2428 /* Sending intermediate configs */ 2409 /* Sending intermediate configs */
2429 else { 2410 else {
2430 if (port->open_count) 2411 if (port->port.count)
2431 msg.portEnabled = 1; 2412 msg.portEnabled = 1;
2432 msg.txBreak = (p_priv->break_on); 2413 msg.txBreak = (p_priv->break_on);
2433 } 2414 }
2434 2415
2435 /* Do handshaking outputs */ 2416 /* Do handshaking outputs */
2436 msg.setRts = 0x01; 2417 msg.setRts = 0x01;
2437 msg.rts = p_priv->rts_state; 2418 msg.rts = p_priv->rts_state;
2438 2419
2439 msg.setDtr = 0x01; 2420 msg.setDtr = 0x01;
2440 msg.dtr = p_priv->dtr_state; 2421 msg.dtr = p_priv->dtr_state;
2441 2422
2442 p_priv->resend_cont = 0; 2423 p_priv->resend_cont = 0;
2443 memcpy (this_urb->transfer_buffer, &msg, sizeof(msg)); 2424 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2444 2425
2445 /* send the data out the device on control endpoint */ 2426 /* send the data out the device on control endpoint */
2446 this_urb->transfer_buffer_length = sizeof(msg); 2427 this_urb->transfer_buffer_length = sizeof(msg);
2447 2428
2448 this_urb->dev = serial->dev; 2429 this_urb->dev = serial->dev;
2449 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 2430 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2431 if (err != 0)
2450 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err); 2432 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
2451 }
2452 return 0; 2433 return 0;
2453} 2434}
2454 2435
@@ -2463,7 +2444,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2463 struct urb *this_urb; 2444 struct urb *this_urb;
2464 int err, device_port; 2445 int err, device_port;
2465 2446
2466 dbg ("%s", __func__); 2447 dbg("%s", __func__);
2467 2448
2468 s_priv = usb_get_serial_data(serial); 2449 s_priv = usb_get_serial_data(serial);
2469 p_priv = usb_get_serial_port_data(port); 2450 p_priv = usb_get_serial_port_data(port);
@@ -2486,9 +2467,9 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2486 if ((reset_port + 1) > p_priv->resend_cont) 2467 if ((reset_port + 1) > p_priv->resend_cont)
2487 p_priv->resend_cont = reset_port + 1; 2468 p_priv->resend_cont = reset_port + 1;
2488 if (this_urb->status == -EINPROGRESS) { 2469 if (this_urb->status == -EINPROGRESS) {
2489 /* dbg ("%s - already writing", __func__); */ 2470 /* dbg("%s - already writing", __func__); */
2490 mdelay(5); 2471 mdelay(5);
2491 return(-1); 2472 return -1;
2492 } 2473 }
2493 2474
2494 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage)); 2475 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
@@ -2501,9 +2482,9 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2501 msg.setClocking = 0xff; 2482 msg.setClocking = 0xff;
2502 if (d_details->calculate_baud_rate 2483 if (d_details->calculate_baud_rate
2503 (p_priv->baud, d_details->baudclk, &msg.baudHi, 2484 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2504 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 2485 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2505 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__, 2486 dbg("%s - Invalid baud rate %d requested, using 9600.",
2506 p_priv->baud); 2487 __func__, p_priv->baud);
2507 msg.baudLo = 0; 2488 msg.baudLo = 0;
2508 msg.baudHi = 125; /* Values for 9600 baud */ 2489 msg.baudHi = 125; /* Values for 9600 baud */
2509 msg.prescaler = 10; 2490 msg.prescaler = 10;
@@ -2529,7 +2510,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2529 if (p_priv->cflag & PARENB) { 2510 if (p_priv->cflag & PARENB) {
2530 /* note USA_PARITY_NONE == 0 */ 2511 /* note USA_PARITY_NONE == 0 */
2531 msg.lcr |= (p_priv->cflag & PARODD)? 2512 msg.lcr |= (p_priv->cflag & PARODD)?
2532 USA_PARITY_ODD: USA_PARITY_EVEN; 2513 USA_PARITY_ODD : USA_PARITY_EVEN;
2533 } 2514 }
2534 msg.setLcr = 0xff; 2515 msg.setLcr = 0xff;
2535 2516
@@ -2566,7 +2547,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2566 msg.resetDataToggle = 0; 2547 msg.resetDataToggle = 0;
2567 } else { 2548 } else {
2568 /* Sending intermediate configs */ 2549 /* Sending intermediate configs */
2569 msg._txOn = (! p_priv->break_on); 2550 msg._txOn = (!p_priv->break_on);
2570 msg._txOff = 0; 2551 msg._txOff = 0;
2571 msg.txFlush = 0; 2552 msg.txFlush = 0;
2572 msg.txBreak = (p_priv->break_on); 2553 msg.txBreak = (p_priv->break_on);
@@ -2606,7 +2587,7 @@ static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2606 struct keyspan_serial_private *s_priv; 2587 struct keyspan_serial_private *s_priv;
2607 const struct keyspan_device_details *d_details; 2588 const struct keyspan_device_details *d_details;
2608 2589
2609 dbg ("%s", __func__); 2590 dbg("%s", __func__);
2610 2591
2611 s_priv = usb_get_serial_data(serial); 2592 s_priv = usb_get_serial_data(serial);
2612 d_details = s_priv->device_details; 2593 d_details = s_priv->device_details;
@@ -2633,7 +2614,7 @@ static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2633 2614
2634/* Gets called by the "real" driver (ie once firmware is loaded 2615/* Gets called by the "real" driver (ie once firmware is loaded
2635 and renumeration has taken place. */ 2616 and renumeration has taken place. */
2636static int keyspan_startup (struct usb_serial *serial) 2617static int keyspan_startup(struct usb_serial *serial)
2637{ 2618{
2638 int i, err; 2619 int i, err;
2639 struct usb_serial_port *port; 2620 struct usb_serial_port *port;
@@ -2644,17 +2625,20 @@ static int keyspan_startup (struct usb_serial *serial)
2644 dbg("%s", __func__); 2625 dbg("%s", __func__);
2645 2626
2646 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i) 2627 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2647 if (d_details->product_id == le16_to_cpu(serial->dev->descriptor.idProduct)) 2628 if (d_details->product_id ==
2629 le16_to_cpu(serial->dev->descriptor.idProduct))
2648 break; 2630 break;
2649 if (d_details == NULL) { 2631 if (d_details == NULL) {
2650 dev_err(&serial->dev->dev, "%s - unknown product id %x\n", __func__, le16_to_cpu(serial->dev->descriptor.idProduct)); 2632 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2633 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2651 return 1; 2634 return 1;
2652 } 2635 }
2653 2636
2654 /* Setup private data for serial driver */ 2637 /* Setup private data for serial driver */
2655 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL); 2638 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2656 if (!s_priv) { 2639 if (!s_priv) {
2657 dbg("%s - kmalloc for keyspan_serial_private failed.", __func__); 2640 dbg("%s - kmalloc for keyspan_serial_private failed.",
2641 __func__);
2658 return -ENOMEM; 2642 return -ENOMEM;
2659 } 2643 }
2660 2644
@@ -2664,10 +2648,11 @@ static int keyspan_startup (struct usb_serial *serial)
2664 /* Now setup per port private data */ 2648 /* Now setup per port private data */
2665 for (i = 0; i < serial->num_ports; i++) { 2649 for (i = 0; i < serial->num_ports; i++) {
2666 port = serial->port[i]; 2650 port = serial->port[i];
2667 p_priv = kzalloc(sizeof(struct keyspan_port_private), GFP_KERNEL); 2651 p_priv = kzalloc(sizeof(struct keyspan_port_private),
2652 GFP_KERNEL);
2668 if (!p_priv) { 2653 if (!p_priv) {
2669 dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __func__, i); 2654 dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __func__, i);
2670 return (1); 2655 return 1;
2671 } 2656 }
2672 p_priv->device_details = d_details; 2657 p_priv->device_details = d_details;
2673 usb_set_serial_port_data(port, p_priv); 2658 usb_set_serial_port_data(port, p_priv);
@@ -2689,11 +2674,11 @@ static int keyspan_startup (struct usb_serial *serial)
2689 dbg("%s - submit indat urb failed %d", __func__, 2674 dbg("%s - submit indat urb failed %d", __func__,
2690 err); 2675 err);
2691 } 2676 }
2692 2677
2693 return 0; 2678 return 0;
2694} 2679}
2695 2680
2696static void keyspan_shutdown (struct usb_serial *serial) 2681static void keyspan_shutdown(struct usb_serial *serial)
2697{ 2682{
2698 int i, j; 2683 int i, j;
2699 struct usb_serial_port *port; 2684 struct usb_serial_port *port;
@@ -2745,8 +2730,8 @@ static void keyspan_shutdown (struct usb_serial *serial)
2745 } 2730 }
2746} 2731}
2747 2732
2748MODULE_AUTHOR( DRIVER_AUTHOR ); 2733MODULE_AUTHOR(DRIVER_AUTHOR);
2749MODULE_DESCRIPTION( DRIVER_DESC ); 2734MODULE_DESCRIPTION(DRIVER_DESC);
2750MODULE_LICENSE("GPL"); 2735MODULE_LICENSE("GPL");
2751 2736
2752MODULE_FIRMWARE("keyspan/usa28.fw"); 2737MODULE_FIRMWARE("keyspan/usa28.fw");
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h
index b52fb657a244..38b4582e0734 100644
--- a/drivers/usb/serial/keyspan.h
+++ b/drivers/usb/serial/keyspan.h
@@ -35,17 +35,18 @@
35 35
36 36
37/* Function prototypes for Keyspan serial converter */ 37/* Function prototypes for Keyspan serial converter */
38static int keyspan_open (struct usb_serial_port *port, 38static int keyspan_open (struct tty_struct *tty,
39 struct usb_serial_port *port,
39 struct file *filp); 40 struct file *filp);
40static void keyspan_close (struct usb_serial_port *port, 41static void keyspan_close (struct tty_struct *tty,
42 struct usb_serial_port *port,
41 struct file *filp); 43 struct file *filp);
42static int keyspan_startup (struct usb_serial *serial); 44static int keyspan_startup (struct usb_serial *serial);
43static void keyspan_shutdown (struct usb_serial *serial); 45static void keyspan_shutdown (struct usb_serial *serial);
44static void keyspan_rx_throttle (struct usb_serial_port *port); 46static int keyspan_write_room (struct tty_struct *tty);
45static void keyspan_rx_unthrottle (struct usb_serial_port *port);
46static int keyspan_write_room (struct usb_serial_port *port);
47 47
48static int keyspan_write (struct usb_serial_port *port, 48static int keyspan_write (struct tty_struct *tty,
49 struct usb_serial_port *port,
49 const unsigned char *buf, 50 const unsigned char *buf,
50 int count); 51 int count);
51 52
@@ -53,18 +54,14 @@ static void keyspan_send_setup (struct usb_serial_port *port,
53 int reset_port); 54 int reset_port);
54 55
55 56
56static int keyspan_chars_in_buffer (struct usb_serial_port *port); 57static void keyspan_set_termios (struct tty_struct *tty,
57static int keyspan_ioctl (struct usb_serial_port *port, 58 struct usb_serial_port *port,
58 struct file *file,
59 unsigned int cmd,
60 unsigned long arg);
61static void keyspan_set_termios (struct usb_serial_port *port,
62 struct ktermios *old); 59 struct ktermios *old);
63static void keyspan_break_ctl (struct usb_serial_port *port, 60static void keyspan_break_ctl (struct tty_struct *tty,
64 int break_state); 61 int break_state);
65static int keyspan_tiocmget (struct usb_serial_port *port, 62static int keyspan_tiocmget (struct tty_struct *tty,
66 struct file *file); 63 struct file *file);
67static int keyspan_tiocmset (struct usb_serial_port *port, 64static int keyspan_tiocmset (struct tty_struct *tty,
68 struct file *file, unsigned int set, 65 struct file *file, unsigned int set,
69 unsigned int clear); 66 unsigned int clear);
70static int keyspan_fake_startup (struct usb_serial *serial); 67static int keyspan_fake_startup (struct usb_serial *serial);
@@ -138,7 +135,8 @@ static int keyspan_usa67_send_setup (struct usb_serial *serial,
138 135
139/* Product IDs post-renumeration. Note that the 28x and 28xb 136/* Product IDs post-renumeration. Note that the 28x and 28xb
140 have the same id's post-renumeration but behave identically 137 have the same id's post-renumeration but behave identically
141 so it's not an issue. */ 138 so it's not an issue. As such, the 28xb is not listed in any
139 of the device tables. */
142#define keyspan_usa18x_product_id 0x0112 140#define keyspan_usa18x_product_id 0x0112
143#define keyspan_usa19_product_id 0x0107 141#define keyspan_usa19_product_id 0x0107
144#define keyspan_usa19qi_product_id 0x010c 142#define keyspan_usa19qi_product_id 0x010c
@@ -482,7 +480,6 @@ static struct usb_device_id keyspan_ids_combined[] = {
482 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_product_id) }, 480 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_product_id) },
483 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_product_id) }, 481 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_product_id) },
484 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_product_id) }, 482 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_product_id) },
485 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xb_product_id) },
486 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xg_product_id) }, 483 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xg_product_id) },
487 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_product_id)}, 484 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_product_id)},
488 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_product_id)}, 485 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_product_id)},
@@ -532,7 +529,6 @@ static struct usb_device_id keyspan_2port_ids[] = {
532 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_product_id) }, 529 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_product_id) },
533 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_product_id) }, 530 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_product_id) },
534 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_product_id) }, 531 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_product_id) },
535 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xb_product_id) },
536 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xg_product_id) }, 532 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xg_product_id) },
537 { } /* Terminating entry */ 533 { } /* Terminating entry */
538}; 534};
@@ -568,10 +564,6 @@ static struct usb_serial_driver keyspan_1port_device = {
568 .close = keyspan_close, 564 .close = keyspan_close,
569 .write = keyspan_write, 565 .write = keyspan_write,
570 .write_room = keyspan_write_room, 566 .write_room = keyspan_write_room,
571 .chars_in_buffer = keyspan_chars_in_buffer,
572 .throttle = keyspan_rx_throttle,
573 .unthrottle = keyspan_rx_unthrottle,
574 .ioctl = keyspan_ioctl,
575 .set_termios = keyspan_set_termios, 567 .set_termios = keyspan_set_termios,
576 .break_ctl = keyspan_break_ctl, 568 .break_ctl = keyspan_break_ctl,
577 .tiocmget = keyspan_tiocmget, 569 .tiocmget = keyspan_tiocmget,
@@ -592,10 +584,6 @@ static struct usb_serial_driver keyspan_2port_device = {
592 .close = keyspan_close, 584 .close = keyspan_close,
593 .write = keyspan_write, 585 .write = keyspan_write,
594 .write_room = keyspan_write_room, 586 .write_room = keyspan_write_room,
595 .chars_in_buffer = keyspan_chars_in_buffer,
596 .throttle = keyspan_rx_throttle,
597 .unthrottle = keyspan_rx_unthrottle,
598 .ioctl = keyspan_ioctl,
599 .set_termios = keyspan_set_termios, 587 .set_termios = keyspan_set_termios,
600 .break_ctl = keyspan_break_ctl, 588 .break_ctl = keyspan_break_ctl,
601 .tiocmget = keyspan_tiocmget, 589 .tiocmget = keyspan_tiocmget,
@@ -616,10 +604,6 @@ static struct usb_serial_driver keyspan_4port_device = {
616 .close = keyspan_close, 604 .close = keyspan_close,
617 .write = keyspan_write, 605 .write = keyspan_write,
618 .write_room = keyspan_write_room, 606 .write_room = keyspan_write_room,
619 .chars_in_buffer = keyspan_chars_in_buffer,
620 .throttle = keyspan_rx_throttle,
621 .unthrottle = keyspan_rx_unthrottle,
622 .ioctl = keyspan_ioctl,
623 .set_termios = keyspan_set_termios, 607 .set_termios = keyspan_set_termios,
624 .break_ctl = keyspan_break_ctl, 608 .break_ctl = keyspan_break_ctl,
625 .tiocmget = keyspan_tiocmget, 609 .tiocmget = keyspan_tiocmget,
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 644a1eaaa376..040040a267d9 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -10,8 +10,9 @@
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * See Documentation/usb/usb-serial.txt for more information on using this driver 13 * See Documentation/usb/usb-serial.txt for more information on using this
14 * 14 * driver
15 *
15 * (09/07/2001) gkh 16 * (09/07/2001) gkh
16 * cleaned up the Xircom support. Added ids for Entregra device which is 17 * cleaned up the Xircom support. Added ids for Entregra device which is
17 * the same as the Xircom device. Enabled the code to be compiled for 18 * the same as the Xircom device. Enabled the code to be compiled for
@@ -21,23 +22,24 @@
21 * support for Xircom PGSDB9 22 * support for Xircom PGSDB9
22 * 23 *
23 * (05/31/2001) gkh 24 * (05/31/2001) gkh
24 * switched from using spinlock to a semaphore, which fixes lots of problems. 25 * switched from using spinlock to a semaphore, which fixes lots of
26 * problems.
25 * 27 *
26 * (04/08/2001) gb 28 * (04/08/2001) gb
27 * Identify version on module load. 29 * Identify version on module load.
28 * 30 *
29 * (11/01/2000) Adam J. Richter 31 * (11/01/2000) Adam J. Richter
30 * usb_device_id table support 32 * usb_device_id table support
31 * 33 *
32 * (10/05/2000) gkh 34 * (10/05/2000) gkh
33 * Fixed bug with urb->dev not being set properly, now that the usb 35 * Fixed bug with urb->dev not being set properly, now that the usb
34 * core needs it. 36 * core needs it.
35 * 37 *
36 * (08/28/2000) gkh 38 * (08/28/2000) gkh
37 * Added locks for SMP safeness. 39 * Added locks for SMP safeness.
38 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more 40 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
39 * than once. 41 * than once.
40 * 42 *
41 * (07/20/2000) borchers 43 * (07/20/2000) borchers
42 * - keyspan_pda_write no longer sleeps if it is called on interrupt time; 44 * - keyspan_pda_write no longer sleeps if it is called on interrupt time;
43 * PPP and the line discipline with stty echo on can call write on 45 * PPP and the line discipline with stty echo on can call write on
@@ -55,14 +57,14 @@
55 * than done directly from the callback to avoid the race in write_chan 57 * than done directly from the callback to avoid the race in write_chan
56 * - keyspan_pda_chars_in_buffer also indicates its buffer is full if the 58 * - keyspan_pda_chars_in_buffer also indicates its buffer is full if the
57 * urb status is -EINPROGRESS, meaning it cannot write at the moment 59 * urb status is -EINPROGRESS, meaning it cannot write at the moment
58 * 60 *
59 * (07/19/2000) gkh 61 * (07/19/2000) gkh
60 * Added module_init and module_exit functions to handle the fact that this 62 * Added module_init and module_exit functions to handle the fact that this
61 * driver is a loadable module now. 63 * driver is a loadable module now.
62 * 64 *
63 * (03/26/2000) gkh 65 * (03/26/2000) gkh
64 * Split driver up into device specific pieces. 66 * Split driver up into device specific pieces.
65 * 67 *
66 */ 68 */
67 69
68 70
@@ -78,7 +80,7 @@
78#include <linux/workqueue.h> 80#include <linux/workqueue.h>
79#include <linux/firmware.h> 81#include <linux/firmware.h>
80#include <linux/ihex.h> 82#include <linux/ihex.h>
81#include <asm/uaccess.h> 83#include <linux/uaccess.h>
82#include <linux/usb.h> 84#include <linux/usb.h>
83#include <linux/usb/serial.h> 85#include <linux/usb/serial.h>
84 86
@@ -135,7 +137,7 @@ static struct usb_device_id id_table_combined [] = {
135 { } /* Terminating entry */ 137 { } /* Terminating entry */
136}; 138};
137 139
138MODULE_DEVICE_TABLE (usb, id_table_combined); 140MODULE_DEVICE_TABLE(usb, id_table_combined);
139 141
140static struct usb_driver keyspan_pda_driver = { 142static struct usb_driver keyspan_pda_driver = {
141 .name = "keyspan_pda", 143 .name = "keyspan_pda",
@@ -159,9 +161,9 @@ static struct usb_device_id id_table_fake [] = {
159 161
160#ifdef XIRCOM 162#ifdef XIRCOM
161static struct usb_device_id id_table_fake_xircom [] = { 163static struct usb_device_id id_table_fake_xircom [] = {
162 { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) }, 164 { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
163 { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) }, 165 { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) },
164 { } 166 { }
165}; 167};
166#endif 168#endif
167 169
@@ -171,7 +173,7 @@ static void keyspan_pda_wakeup_write(struct work_struct *work)
171 container_of(work, struct keyspan_pda_private, wakeup_work); 173 container_of(work, struct keyspan_pda_private, wakeup_work);
172 struct usb_serial_port *port = priv->port; 174 struct usb_serial_port *port = priv->port;
173 175
174 tty_wakeup(port->tty); 176 tty_wakeup(port->port.tty);
175} 177}
176 178
177static void keyspan_pda_request_unthrottle(struct work_struct *work) 179static void keyspan_pda_request_unthrottle(struct work_struct *work)
@@ -184,7 +186,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
184 dbg(" request_unthrottle"); 186 dbg(" request_unthrottle");
185 /* ask the device to tell us when the tx buffer becomes 187 /* ask the device to tell us when the tx buffer becomes
186 sufficiently empty */ 188 sufficiently empty */
187 result = usb_control_msg(serial->dev, 189 result = usb_control_msg(serial->dev,
188 usb_sndctrlpipe(serial->dev, 0), 190 usb_sndctrlpipe(serial->dev, 0),
189 7, /* request_unthrottle */ 191 7, /* request_unthrottle */
190 USB_TYPE_VENDOR | USB_RECIP_INTERFACE 192 USB_TYPE_VENDOR | USB_RECIP_INTERFACE
@@ -195,17 +197,16 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
195 0, 197 0,
196 2000); 198 2000);
197 if (result < 0) 199 if (result < 0)
198 dbg("%s - error %d from usb_control_msg", 200 dbg("%s - error %d from usb_control_msg",
199 __func__, result); 201 __func__, result);
200} 202}
201 203
202 204
203static void keyspan_pda_rx_interrupt (struct urb *urb) 205static void keyspan_pda_rx_interrupt(struct urb *urb)
204{ 206{
205 struct usb_serial_port *port = urb->context; 207 struct usb_serial_port *port = urb->context;
206 struct tty_struct *tty = port->tty; 208 struct tty_struct *tty = port->port.tty;
207 unsigned char *data = urb->transfer_buffer; 209 unsigned char *data = urb->transfer_buffer;
208 int i;
209 int retval; 210 int retval;
210 int status = urb->status; 211 int status = urb->status;
211 struct keyspan_pda_private *priv; 212 struct keyspan_pda_private *priv;
@@ -228,14 +229,13 @@ static void keyspan_pda_rx_interrupt (struct urb *urb)
228 goto exit; 229 goto exit;
229 } 230 }
230 231
231 /* see if the message is data or a status interrupt */ 232 /* see if the message is data or a status interrupt */
232 switch (data[0]) { 233 switch (data[0]) {
233 case 0: 234 case 0:
234 /* rest of message is rx data */ 235 /* rest of message is rx data */
235 if (urb->actual_length) { 236 if (urb->actual_length) {
236 for (i = 1; i < urb->actual_length ; ++i) { 237 tty_insert_flip_string(tty, data + 1,
237 tty_insert_flip_char(tty, data[i], 0); 238 urb->actual_length - 1);
238 }
239 tty_flip_buffer_push(tty); 239 tty_flip_buffer_push(tty);
240 } 240 }
241 break; 241 break;
@@ -259,14 +259,14 @@ static void keyspan_pda_rx_interrupt (struct urb *urb)
259 } 259 }
260 260
261exit: 261exit:
262 retval = usb_submit_urb (urb, GFP_ATOMIC); 262 retval = usb_submit_urb(urb, GFP_ATOMIC);
263 if (retval) 263 if (retval)
264 err ("%s - usb_submit_urb failed with result %d", 264 err("%s - usb_submit_urb failed with result %d",
265 __func__, retval); 265 __func__, retval);
266} 266}
267 267
268 268
269static void keyspan_pda_rx_throttle (struct usb_serial_port *port) 269static void keyspan_pda_rx_throttle(struct tty_struct *tty)
270{ 270{
271 /* stop receiving characters. We just turn off the URB request, and 271 /* stop receiving characters. We just turn off the URB request, and
272 let chars pile up in the device. If we're doing hardware 272 let chars pile up in the device. If we're doing hardware
@@ -274,14 +274,15 @@ static void keyspan_pda_rx_throttle (struct usb_serial_port *port)
274 fills up. If we're doing XON/XOFF, this would be a good time to 274 fills up. If we're doing XON/XOFF, this would be a good time to
275 send an XOFF, although it might make sense to foist that off 275 send an XOFF, although it might make sense to foist that off
276 upon the device too. */ 276 upon the device too. */
277 277 struct usb_serial_port *port = tty->driver_data;
278 dbg("keyspan_pda_rx_throttle port %d", port->number); 278 dbg("keyspan_pda_rx_throttle port %d", port->number);
279 usb_kill_urb(port->interrupt_in_urb); 279 usb_kill_urb(port->interrupt_in_urb);
280} 280}
281 281
282 282
283static void keyspan_pda_rx_unthrottle (struct usb_serial_port *port) 283static void keyspan_pda_rx_unthrottle(struct tty_struct *tty)
284{ 284{
285 struct usb_serial_port *port = tty->driver_data;
285 /* just restart the receive interrupt URB */ 286 /* just restart the receive interrupt URB */
286 dbg("keyspan_pda_rx_unthrottle port %d", port->number); 287 dbg("keyspan_pda_rx_unthrottle port %d", port->number);
287 port->interrupt_in_urb->dev = port->serial->dev; 288 port->interrupt_in_urb->dev = port->serial->dev;
@@ -291,32 +292,52 @@ static void keyspan_pda_rx_unthrottle (struct usb_serial_port *port)
291} 292}
292 293
293 294
294static speed_t keyspan_pda_setbaud (struct usb_serial *serial, speed_t baud) 295static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud)
295{ 296{
296 int rc; 297 int rc;
297 int bindex; 298 int bindex;
298 299
299 switch(baud) { 300 switch (baud) {
300 case 110: bindex = 0; break; 301 case 110:
301 case 300: bindex = 1; break; 302 bindex = 0;
302 case 1200: bindex = 2; break; 303 break;
303 case 2400: bindex = 3; break; 304 case 300:
304 case 4800: bindex = 4; break; 305 bindex = 1;
305 case 9600: bindex = 5; break; 306 break;
306 case 19200: bindex = 6; break; 307 case 1200:
307 case 38400: bindex = 7; break; 308 bindex = 2;
308 case 57600: bindex = 8; break; 309 break;
309 case 115200: bindex = 9; break; 310 case 2400:
310 default: 311 bindex = 3;
311 bindex = 5; /* Default to 9600 */ 312 break;
312 baud = 9600; 313 case 4800:
314 bindex = 4;
315 break;
316 case 9600:
317 bindex = 5;
318 break;
319 case 19200:
320 bindex = 6;
321 break;
322 case 38400:
323 bindex = 7;
324 break;
325 case 57600:
326 bindex = 8;
327 break;
328 case 115200:
329 bindex = 9;
330 break;
331 default:
332 bindex = 5; /* Default to 9600 */
333 baud = 9600;
313 } 334 }
314 335
315 /* rather than figure out how to sleep while waiting for this 336 /* rather than figure out how to sleep while waiting for this
316 to complete, I just use the "legacy" API. */ 337 to complete, I just use the "legacy" API. */
317 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 338 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
318 0, /* set baud */ 339 0, /* set baud */
319 USB_TYPE_VENDOR 340 USB_TYPE_VENDOR
320 | USB_RECIP_INTERFACE 341 | USB_RECIP_INTERFACE
321 | USB_DIR_OUT, /* type */ 342 | USB_DIR_OUT, /* type */
322 bindex, /* value */ 343 bindex, /* value */
@@ -330,8 +351,9 @@ static speed_t keyspan_pda_setbaud (struct usb_serial *serial, speed_t baud)
330} 351}
331 352
332 353
333static void keyspan_pda_break_ctl (struct usb_serial_port *port, int break_state) 354static void keyspan_pda_break_ctl(struct tty_struct *tty, int break_state)
334{ 355{
356 struct usb_serial_port *port = tty->driver_data;
335 struct usb_serial *serial = port->serial; 357 struct usb_serial *serial = port->serial;
336 int value; 358 int value;
337 int result; 359 int result;
@@ -341,11 +363,11 @@ static void keyspan_pda_break_ctl (struct usb_serial_port *port, int break_state
341 else 363 else
342 value = 0; /* clear break */ 364 value = 0; /* clear break */
343 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 365 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
344 4, /* set break */ 366 4, /* set break */
345 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 367 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
346 value, 0, NULL, 0, 2000); 368 value, 0, NULL, 0, 2000);
347 if (result < 0) 369 if (result < 0)
348 dbg("%s - error %d from usb_control_msg", 370 dbg("%s - error %d from usb_control_msg",
349 __func__, result); 371 __func__, result);
350 /* there is something funky about this.. the TCSBRK that 'cu' performs 372 /* there is something funky about this.. the TCSBRK that 'cu' performs
351 ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4 373 ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4
@@ -354,8 +376,8 @@ static void keyspan_pda_break_ctl (struct usb_serial_port *port, int break_state
354} 376}
355 377
356 378
357static void keyspan_pda_set_termios (struct usb_serial_port *port, 379static void keyspan_pda_set_termios(struct tty_struct *tty,
358 struct ktermios *old_termios) 380 struct usb_serial_port *port, struct ktermios *old_termios)
359{ 381{
360 struct usb_serial *serial = port->serial; 382 struct usb_serial *serial = port->serial;
361 speed_t speed; 383 speed_t speed;
@@ -380,7 +402,7 @@ static void keyspan_pda_set_termios (struct usb_serial_port *port,
380 402
381 For now, just do baud. */ 403 For now, just do baud. */
382 404
383 speed = tty_get_baud_rate(port->tty); 405 speed = tty_get_baud_rate(tty);
384 speed = keyspan_pda_setbaud(serial, speed); 406 speed = keyspan_pda_setbaud(serial, speed);
385 407
386 if (speed == 0) { 408 if (speed == 0) {
@@ -390,8 +412,8 @@ static void keyspan_pda_set_termios (struct usb_serial_port *port,
390 } 412 }
391 /* Only speed can change so copy the old h/w parameters 413 /* Only speed can change so copy the old h/w parameters
392 then encode the new speed */ 414 then encode the new speed */
393 tty_termios_copy_hw(port->tty->termios, old_termios); 415 tty_termios_copy_hw(tty->termios, old_termios);
394 tty_encode_baud_rate(port->tty, speed, speed); 416 tty_encode_baud_rate(tty, speed, speed);
395} 417}
396 418
397 419
@@ -408,7 +430,7 @@ static int keyspan_pda_get_modem_info(struct usb_serial *serial,
408 3, /* get pins */ 430 3, /* get pins */
409 USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_IN, 431 USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_IN,
410 0, 0, &data, 1, 2000); 432 0, 0, &data, 1, 2000);
411 if (rc > 0) 433 if (rc >= 0)
412 *value = data; 434 *value = data;
413 return rc; 435 return rc;
414} 436}
@@ -425,8 +447,9 @@ static int keyspan_pda_set_modem_info(struct usb_serial *serial,
425 return rc; 447 return rc;
426} 448}
427 449
428static int keyspan_pda_tiocmget(struct usb_serial_port *port, struct file *file) 450static int keyspan_pda_tiocmget(struct tty_struct *tty, struct file *file)
429{ 451{
452 struct usb_serial_port *port = tty->driver_data;
430 struct usb_serial *serial = port->serial; 453 struct usb_serial *serial = port->serial;
431 int rc; 454 int rc;
432 unsigned char status; 455 unsigned char status;
@@ -445,9 +468,10 @@ static int keyspan_pda_tiocmget(struct usb_serial_port *port, struct file *file)
445 return value; 468 return value;
446} 469}
447 470
448static int keyspan_pda_tiocmset(struct usb_serial_port *port, struct file *file, 471static int keyspan_pda_tiocmset(struct tty_struct *tty, struct file *file,
449 unsigned int set, unsigned int clear) 472 unsigned int set, unsigned int clear)
450{ 473{
474 struct usb_serial_port *port = tty->driver_data;
451 struct usb_serial *serial = port->serial; 475 struct usb_serial *serial = port->serial;
452 int rc; 476 int rc;
453 unsigned char status; 477 unsigned char status;
@@ -469,23 +493,8 @@ static int keyspan_pda_tiocmset(struct usb_serial_port *port, struct file *file,
469 return rc; 493 return rc;
470} 494}
471 495
472static int keyspan_pda_ioctl(struct usb_serial_port *port, struct file *file, 496static int keyspan_pda_write(struct tty_struct *tty,
473 unsigned int cmd, unsigned long arg) 497 struct usb_serial_port *port, const unsigned char *buf, int count)
474{
475 switch (cmd) {
476 case TIOCMIWAIT:
477 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
478 /* TODO */
479 case TIOCGICOUNT:
480 /* return count of modemline transitions */
481 return 0; /* TODO */
482 }
483
484 return -ENOIOCTLCMD;
485}
486
487static int keyspan_pda_write(struct usb_serial_port *port,
488 const unsigned char *buf, int count)
489{ 498{
490 struct usb_serial *serial = port->serial; 499 struct usb_serial *serial = port->serial;
491 int request_unthrottle = 0; 500 int request_unthrottle = 0;
@@ -501,10 +510,10 @@ static int keyspan_pda_write(struct usb_serial_port *port,
501 select() or poll() too) until we receive that unthrottle interrupt. 510 select() or poll() too) until we receive that unthrottle interrupt.
502 Block if we can't write anything at all, otherwise write as much as 511 Block if we can't write anything at all, otherwise write as much as
503 we can. */ 512 we can. */
504 dbg("keyspan_pda_write(%d)",count); 513 dbg("keyspan_pda_write(%d)", count);
505 if (count == 0) { 514 if (count == 0) {
506 dbg(" write request of 0 bytes"); 515 dbg(" write request of 0 bytes");
507 return (0); 516 return 0;
508 } 517 }
509 518
510 /* we might block because of: 519 /* we might block because of:
@@ -531,7 +540,7 @@ static int keyspan_pda_write(struct usb_serial_port *port,
531 scheduler time, since usb_control_msg() sleeps. */ 540 scheduler time, since usb_control_msg() sleeps. */
532 if (count > priv->tx_room && !in_interrupt()) { 541 if (count > priv->tx_room && !in_interrupt()) {
533 unsigned char room; 542 unsigned char room;
534 rc = usb_control_msg(serial->dev, 543 rc = usb_control_msg(serial->dev,
535 usb_rcvctrlpipe(serial->dev, 0), 544 usb_rcvctrlpipe(serial->dev, 0),
536 6, /* write_room */ 545 6, /* write_room */
537 USB_TYPE_VENDOR | USB_RECIP_INTERFACE 546 USB_TYPE_VENDOR | USB_RECIP_INTERFACE
@@ -562,7 +571,7 @@ static int keyspan_pda_write(struct usb_serial_port *port,
562 571
563 if (count) { 572 if (count) {
564 /* now transfer data */ 573 /* now transfer data */
565 memcpy (port->write_urb->transfer_buffer, buf, count); 574 memcpy(port->write_urb->transfer_buffer, buf, count);
566 /* send the data out the bulk port */ 575 /* send the data out the bulk port */
567 port->write_urb->transfer_buffer_length = count; 576 port->write_urb->transfer_buffer_length = count;
568 577
@@ -574,8 +583,7 @@ static int keyspan_pda_write(struct usb_serial_port *port,
574 dbg(" usb_submit_urb(write bulk) failed"); 583 dbg(" usb_submit_urb(write bulk) failed");
575 goto exit; 584 goto exit;
576 } 585 }
577 } 586 } else {
578 else {
579 /* There wasn't any room left, so we are throttled until 587 /* There wasn't any room left, so we are throttled until
580 the buffer empties a bit */ 588 the buffer empties a bit */
581 request_unthrottle = 1; 589 request_unthrottle = 1;
@@ -594,7 +602,7 @@ exit:
594} 602}
595 603
596 604
597static void keyspan_pda_write_bulk_callback (struct urb *urb) 605static void keyspan_pda_write_bulk_callback(struct urb *urb)
598{ 606{
599 struct usb_serial_port *port = urb->context; 607 struct usb_serial_port *port = urb->context;
600 struct keyspan_pda_private *priv; 608 struct keyspan_pda_private *priv;
@@ -607,22 +615,21 @@ static void keyspan_pda_write_bulk_callback (struct urb *urb)
607} 615}
608 616
609 617
610static int keyspan_pda_write_room (struct usb_serial_port *port) 618static int keyspan_pda_write_room(struct tty_struct *tty)
611{ 619{
620 struct usb_serial_port *port = tty->driver_data;
612 struct keyspan_pda_private *priv; 621 struct keyspan_pda_private *priv;
613
614 priv = usb_get_serial_port_data(port); 622 priv = usb_get_serial_port_data(port);
615
616 /* used by n_tty.c for processing of tabs and such. Giving it our 623 /* used by n_tty.c for processing of tabs and such. Giving it our
617 conservative guess is probably good enough, but needs testing by 624 conservative guess is probably good enough, but needs testing by
618 running a console through the device. */ 625 running a console through the device. */
619 626 return priv->tx_room;
620 return (priv->tx_room);
621} 627}
622 628
623 629
624static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port) 630static int keyspan_pda_chars_in_buffer(struct tty_struct *tty)
625{ 631{
632 struct usb_serial_port *port = tty->driver_data;
626 struct keyspan_pda_private *priv; 633 struct keyspan_pda_private *priv;
627 unsigned long flags; 634 unsigned long flags;
628 int ret = 0; 635 int ret = 0;
@@ -640,7 +647,8 @@ static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port)
640} 647}
641 648
642 649
643static int keyspan_pda_open (struct usb_serial_port *port, struct file *filp) 650static int keyspan_pda_open(struct tty_struct *tty,
651 struct usb_serial_port *port, struct file *filp)
644{ 652{
645 struct usb_serial *serial = port->serial; 653 struct usb_serial *serial = port->serial;
646 unsigned char room; 654 unsigned char room;
@@ -672,8 +680,8 @@ static int keyspan_pda_open (struct usb_serial_port *port, struct file *filp)
672 680
673 /* the normal serial device seems to always turn on DTR and RTS here, 681 /* the normal serial device seems to always turn on DTR and RTS here,
674 so do the same */ 682 so do the same */
675 if (port->tty->termios->c_cflag & CBAUD) 683 if (tty && (tty->termios->c_cflag & CBAUD))
676 keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2) ); 684 keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2));
677 else 685 else
678 keyspan_pda_set_modem_info(serial, 0); 686 keyspan_pda_set_modem_info(serial, 0);
679 687
@@ -690,13 +698,15 @@ error:
690} 698}
691 699
692 700
693static void keyspan_pda_close(struct usb_serial_port *port, struct file *filp) 701static void keyspan_pda_close(struct tty_struct *tty,
702 struct usb_serial_port *port, struct file *filp)
694{ 703{
695 struct usb_serial *serial = port->serial; 704 struct usb_serial *serial = port->serial;
696 705
697 if (serial->dev) { 706 if (serial->dev) {
698 /* the normal serial device seems to always shut off DTR and RTS now */ 707 /* the normal serial device seems to always shut
699 if (port->tty->termios->c_cflag & HUPCL) 708 off DTR and RTS now */
709 if (tty->termios->c_cflag & HUPCL)
700 keyspan_pda_set_modem_info(serial, 0); 710 keyspan_pda_set_modem_info(serial, 0);
701 711
702 /* shutdown our bulk reads and writes */ 712 /* shutdown our bulk reads and writes */
@@ -707,7 +717,7 @@ static void keyspan_pda_close(struct usb_serial_port *port, struct file *filp)
707 717
708 718
709/* download the firmware to a "fake" device (pre-renumeration) */ 719/* download the firmware to a "fake" device (pre-renumeration) */
710static int keyspan_pda_fake_startup (struct usb_serial *serial) 720static int keyspan_pda_fake_startup(struct usb_serial *serial)
711{ 721{
712 int response; 722 int response;
713 const char *fw_name; 723 const char *fw_name;
@@ -756,10 +766,10 @@ static int keyspan_pda_fake_startup (struct usb_serial *serial)
756 response = ezusb_set_reset(serial, 0); 766 response = ezusb_set_reset(serial, 0);
757 767
758 /* we want this device to fail to have a driver assigned to it. */ 768 /* we want this device to fail to have a driver assigned to it. */
759 return (1); 769 return 1;
760} 770}
761 771
762static int keyspan_pda_startup (struct usb_serial *serial) 772static int keyspan_pda_startup(struct usb_serial *serial)
763{ 773{
764 774
765 struct keyspan_pda_private *priv; 775 struct keyspan_pda_private *priv;
@@ -769,20 +779,20 @@ static int keyspan_pda_startup (struct usb_serial *serial)
769 779
770 priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL); 780 priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL);
771 if (!priv) 781 if (!priv)
772 return (1); /* error */ 782 return 1; /* error */
773 usb_set_serial_port_data(serial->port[0], priv); 783 usb_set_serial_port_data(serial->port[0], priv);
774 init_waitqueue_head(&serial->port[0]->write_wait); 784 init_waitqueue_head(&serial->port[0]->write_wait);
775 INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write); 785 INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write);
776 INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle); 786 INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle);
777 priv->serial = serial; 787 priv->serial = serial;
778 priv->port = serial->port[0]; 788 priv->port = serial->port[0];
779 return (0); 789 return 0;
780} 790}
781 791
782static void keyspan_pda_shutdown (struct usb_serial *serial) 792static void keyspan_pda_shutdown(struct usb_serial *serial)
783{ 793{
784 dbg("%s", __func__); 794 dbg("%s", __func__);
785 795
786 kfree(usb_get_serial_port_data(serial->port[0])); 796 kfree(usb_get_serial_port_data(serial->port[0]));
787} 797}
788 798
@@ -832,7 +842,6 @@ static struct usb_serial_driver keyspan_pda_device = {
832 .chars_in_buffer = keyspan_pda_chars_in_buffer, 842 .chars_in_buffer = keyspan_pda_chars_in_buffer,
833 .throttle = keyspan_pda_rx_throttle, 843 .throttle = keyspan_pda_rx_throttle,
834 .unthrottle = keyspan_pda_rx_unthrottle, 844 .unthrottle = keyspan_pda_rx_unthrottle,
835 .ioctl = keyspan_pda_ioctl,
836 .set_termios = keyspan_pda_set_termios, 845 .set_termios = keyspan_pda_set_termios,
837 .break_ctl = keyspan_pda_break_ctl, 846 .break_ctl = keyspan_pda_break_ctl,
838 .tiocmget = keyspan_pda_tiocmget, 847 .tiocmget = keyspan_pda_tiocmget,
@@ -842,7 +851,7 @@ static struct usb_serial_driver keyspan_pda_device = {
842}; 851};
843 852
844 853
845static int __init keyspan_pda_init (void) 854static int __init keyspan_pda_init(void)
846{ 855{
847 int retval; 856 int retval;
848 retval = usb_serial_register(&keyspan_pda_device); 857 retval = usb_serial_register(&keyspan_pda_device);
@@ -863,7 +872,7 @@ static int __init keyspan_pda_init (void)
863 goto failed_usb_register; 872 goto failed_usb_register;
864 info(DRIVER_DESC " " DRIVER_VERSION); 873 info(DRIVER_DESC " " DRIVER_VERSION);
865 return 0; 874 return 0;
866failed_usb_register: 875failed_usb_register:
867#ifdef XIRCOM 876#ifdef XIRCOM
868 usb_serial_deregister(&xircom_pgs_fake_device); 877 usb_serial_deregister(&xircom_pgs_fake_device);
869failed_xircom_register: 878failed_xircom_register:
@@ -880,15 +889,15 @@ failed_pda_register:
880} 889}
881 890
882 891
883static void __exit keyspan_pda_exit (void) 892static void __exit keyspan_pda_exit(void)
884{ 893{
885 usb_deregister (&keyspan_pda_driver); 894 usb_deregister(&keyspan_pda_driver);
886 usb_serial_deregister (&keyspan_pda_device); 895 usb_serial_deregister(&keyspan_pda_device);
887#ifdef KEYSPAN 896#ifdef KEYSPAN
888 usb_serial_deregister (&keyspan_pda_fake_device); 897 usb_serial_deregister(&keyspan_pda_fake_device);
889#endif 898#endif
890#ifdef XIRCOM 899#ifdef XIRCOM
891 usb_serial_deregister (&xircom_pgs_fake_device); 900 usb_serial_deregister(&xircom_pgs_fake_device);
892#endif 901#endif
893} 902}
894 903
@@ -896,8 +905,8 @@ static void __exit keyspan_pda_exit (void)
896module_init(keyspan_pda_init); 905module_init(keyspan_pda_init);
897module_exit(keyspan_pda_exit); 906module_exit(keyspan_pda_exit);
898 907
899MODULE_AUTHOR( DRIVER_AUTHOR ); 908MODULE_AUTHOR(DRIVER_AUTHOR);
900MODULE_DESCRIPTION( DRIVER_DESC ); 909MODULE_DESCRIPTION(DRIVER_DESC);
901MODULE_LICENSE("GPL"); 910MODULE_LICENSE("GPL");
902 911
903module_param(debug, bool, S_IRUGO | S_IWUSR); 912module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index f328948d74e3..b84dddc71124 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -15,12 +15,12 @@
15 * Neither Palm, nor their contractor (MCCI) or their supplier (KLSI) provided 15 * Neither Palm, nor their contractor (MCCI) or their supplier (KLSI) provided
16 * information that was not already available. 16 * information that was not already available.
17 * 17 *
18 * It seems that KLSI bought some silicon-design information from ScanLogic, 18 * It seems that KLSI bought some silicon-design information from ScanLogic,
19 * whose SL11R processor is at the core of the KL5KUSB chipset from KLSI. 19 * whose SL11R processor is at the core of the KL5KUSB chipset from KLSI.
20 * KLSI has firmware available for their devices; it is probable that the 20 * KLSI has firmware available for their devices; it is probable that the
21 * firmware differs from that used by KLSI in their products. If you have an 21 * firmware differs from that used by KLSI in their products. If you have an
22 * original KLSI device and can provide some information on it, I would be 22 * original KLSI device and can provide some information on it, I would be
23 * most interested in adding support for it here. If you have any information 23 * most interested in adding support for it here. If you have any information
24 * on the protocol used (or find errors in my reverse-engineered stuff), please 24 * on the protocol used (or find errors in my reverse-engineered stuff), please
25 * let me know. 25 * let me know.
26 * 26 *
@@ -40,7 +40,7 @@
40 * 0.2 - TIOCMGET works, so autopilot(1) can be used! 40 * 0.2 - TIOCMGET works, so autopilot(1) can be used!
41 * 0.1 - can be used to to pilot-xfer -p /dev/ttyUSB0 -l 41 * 0.1 - can be used to to pilot-xfer -p /dev/ttyUSB0 -l
42 * 42 *
43 * The driver skeleton is mainly based on mct_u232.c and various other 43 * The driver skeleton is mainly based on mct_u232.c and various other
44 * pieces of code shamelessly copied from the drivers/usb/serial/ directory. 44 * pieces of code shamelessly copied from the drivers/usb/serial/ directory.
45 */ 45 */
46 46
@@ -53,7 +53,7 @@
53#include <linux/tty_driver.h> 53#include <linux/tty_driver.h>
54#include <linux/tty_flip.h> 54#include <linux/tty_flip.h>
55#include <linux/module.h> 55#include <linux/module.h>
56#include <asm/uaccess.h> 56#include <linux/uaccess.h>
57#include <asm/unaligned.h> 57#include <asm/unaligned.h>
58#include <linux/usb.h> 58#include <linux/usb.h>
59#include <linux/usb/serial.h> 59#include <linux/usb/serial.h>
@@ -72,33 +72,25 @@ static int debug;
72/* 72/*
73 * Function prototypes 73 * Function prototypes
74 */ 74 */
75static int klsi_105_startup (struct usb_serial *serial); 75static int klsi_105_startup(struct usb_serial *serial);
76static void klsi_105_shutdown (struct usb_serial *serial); 76static void klsi_105_shutdown(struct usb_serial *serial);
77static int klsi_105_open (struct usb_serial_port *port, 77static int klsi_105_open(struct tty_struct *tty,
78 struct file *filp); 78 struct usb_serial_port *port, struct file *filp);
79static void klsi_105_close (struct usb_serial_port *port, 79static void klsi_105_close(struct tty_struct *tty,
80 struct file *filp); 80 struct usb_serial_port *port, struct file *filp);
81static int klsi_105_write (struct usb_serial_port *port, 81static int klsi_105_write(struct tty_struct *tty,
82 const unsigned char *buf, 82 struct usb_serial_port *port, const unsigned char *buf, int count);
83 int count); 83static void klsi_105_write_bulk_callback(struct urb *urb);
84static void klsi_105_write_bulk_callback (struct urb *urb); 84static int klsi_105_chars_in_buffer(struct tty_struct *tty);
85static int klsi_105_chars_in_buffer (struct usb_serial_port *port); 85static int klsi_105_write_room(struct tty_struct *tty);
86static int klsi_105_write_room (struct usb_serial_port *port); 86static void klsi_105_read_bulk_callback(struct urb *urb);
87 87static void klsi_105_set_termios(struct tty_struct *tty,
88static void klsi_105_read_bulk_callback (struct urb *urb); 88 struct usb_serial_port *port, struct ktermios *old);
89static void klsi_105_set_termios (struct usb_serial_port *port, 89static void klsi_105_throttle(struct tty_struct *tty);
90 struct ktermios *old); 90static void klsi_105_unthrottle(struct tty_struct *tty);
91static void klsi_105_throttle (struct usb_serial_port *port); 91static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file);
92static void klsi_105_unthrottle (struct usb_serial_port *port); 92static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
93/* 93 unsigned int set, unsigned int clear);
94static void klsi_105_break_ctl (struct usb_serial_port *port,
95 int break_state );
96 */
97static int klsi_105_tiocmget (struct usb_serial_port *port,
98 struct file *file);
99static int klsi_105_tiocmset (struct usb_serial_port *port,
100 struct file *file, unsigned int set,
101 unsigned int clear);
102 94
103/* 95/*
104 * All of the device info needed for the KLSI converters. 96 * All of the device info needed for the KLSI converters.
@@ -109,7 +101,7 @@ static struct usb_device_id id_table [] = {
109 { } /* Terminating entry */ 101 { } /* Terminating entry */
110}; 102};
111 103
112MODULE_DEVICE_TABLE (usb, id_table); 104MODULE_DEVICE_TABLE(usb, id_table);
113 105
114static struct usb_driver kl5kusb105d_driver = { 106static struct usb_driver kl5kusb105d_driver = {
115 .name = "kl5kusb105d", 107 .name = "kl5kusb105d",
@@ -134,7 +126,7 @@ static struct usb_serial_driver kl5kusb105d_device = {
134 .write_bulk_callback = klsi_105_write_bulk_callback, 126 .write_bulk_callback = klsi_105_write_bulk_callback,
135 .chars_in_buffer = klsi_105_chars_in_buffer, 127 .chars_in_buffer = klsi_105_chars_in_buffer,
136 .write_room = klsi_105_write_room, 128 .write_room = klsi_105_write_room,
137 .read_bulk_callback =klsi_105_read_bulk_callback, 129 .read_bulk_callback = klsi_105_read_bulk_callback,
138 .set_termios = klsi_105_set_termios, 130 .set_termios = klsi_105_set_termios,
139 /*.break_ctl = klsi_105_break_ctl,*/ 131 /*.break_ctl = klsi_105_break_ctl,*/
140 .tiocmget = klsi_105_tiocmget, 132 .tiocmget = klsi_105_tiocmget,
@@ -161,7 +153,7 @@ struct klsi_105_private {
161 struct ktermios termios; 153 struct ktermios termios;
162 unsigned long line_state; /* modem line settings */ 154 unsigned long line_state; /* modem line settings */
163 /* write pool */ 155 /* write pool */
164 struct urb * write_urb_pool[NUM_URBS]; 156 struct urb *write_urb_pool[NUM_URBS];
165 spinlock_t lock; 157 spinlock_t lock;
166 unsigned long bytes_in; 158 unsigned long bytes_in;
167 unsigned long bytes_out; 159 unsigned long bytes_out;
@@ -180,15 +172,15 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port,
180{ 172{
181 int rc; 173 int rc;
182 174
183 rc = usb_control_msg(port->serial->dev, 175 rc = usb_control_msg(port->serial->dev,
184 usb_sndctrlpipe(port->serial->dev, 0), 176 usb_sndctrlpipe(port->serial->dev, 0),
185 KL5KUSB105A_SIO_SET_DATA, 177 KL5KUSB105A_SIO_SET_DATA,
186 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE, 178 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
187 0, /* value */ 179 0, /* value */
188 0, /* index */ 180 0, /* index */
189 settings, 181 settings,
190 sizeof(struct klsi_105_port_settings), 182 sizeof(struct klsi_105_port_settings),
191 KLSI_TIMEOUT); 183 KLSI_TIMEOUT);
192 if (rc < 0) 184 if (rc < 0)
193 err("Change port settings failed (error = %d)", rc); 185 err("Change port settings failed (error = %d)", rc);
194 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d", 186 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d",
@@ -196,7 +188,7 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port,
196 settings->pktlen, 188 settings->pktlen,
197 settings->baudrate, settings->databits, 189 settings->baudrate, settings->databits,
198 settings->unknown1, settings->unknown2); 190 settings->unknown1, settings->unknown2);
199 return rc; 191 return rc;
200} /* klsi_105_chg_port_settings */ 192} /* klsi_105_chg_port_settings */
201 193
202/* translate a 16-bit status value from the device to linux's TIO bits */ 194/* translate a 16-bit status value from the device to linux's TIO bits */
@@ -210,9 +202,9 @@ static unsigned long klsi_105_status2linestate(const __u16 status)
210 202
211 return res; 203 return res;
212} 204}
213/* 205/*
214 * Read line control via vendor command and return result through 206 * Read line control via vendor command and return result through
215 * *line_state_p 207 * *line_state_p
216 */ 208 */
217/* It seems that the status buffer has always only 2 bytes length */ 209/* It seems that the status buffer has always only 2 bytes length */
218#define KLSI_STATUSBUF_LEN 2 210#define KLSI_STATUSBUF_LEN 2
@@ -220,14 +212,14 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
220 unsigned long *line_state_p) 212 unsigned long *line_state_p)
221{ 213{
222 int rc; 214 int rc;
223 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1}; 215 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1, -1};
224 __u16 status; 216 __u16 status;
225 217
226 info("%s - sending SIO Poll request", __func__); 218 info("%s - sending SIO Poll request", __func__);
227 rc = usb_control_msg(port->serial->dev, 219 rc = usb_control_msg(port->serial->dev,
228 usb_rcvctrlpipe(port->serial->dev, 0), 220 usb_rcvctrlpipe(port->serial->dev, 0),
229 KL5KUSB105A_SIO_POLL, 221 KL5KUSB105A_SIO_POLL,
230 USB_TYPE_VENDOR | USB_DIR_IN, 222 USB_TYPE_VENDOR | USB_DIR_IN,
231 0, /* value */ 223 0, /* value */
232 0, /* index */ 224 0, /* index */
233 status_buf, KLSI_STATUSBUF_LEN, 225 status_buf, KLSI_STATUSBUF_LEN,
@@ -236,15 +228,14 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
236 if (rc < 0) 228 if (rc < 0)
237 err("Reading line status failed (error = %d)", rc); 229 err("Reading line status failed (error = %d)", rc);
238 else { 230 else {
239 status = le16_to_cpu(get_unaligned((__le16 *)status_buf)); 231 status = get_unaligned_le16(status_buf);
240 232
241 info("%s - read status %x %x", __func__, 233 info("%s - read status %x %x", __func__,
242 status_buf[0], status_buf[1]); 234 status_buf[0], status_buf[1]);
243 235
244 *line_state_p = klsi_105_status2linestate(status); 236 *line_state_p = klsi_105_status2linestate(status);
245 } 237 }
246 238 return rc;
247 return rc;
248} 239}
249 240
250 241
@@ -252,7 +243,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
252 * Driver's tty interface functions 243 * Driver's tty interface functions
253 */ 244 */
254 245
255static int klsi_105_startup (struct usb_serial *serial) 246static int klsi_105_startup(struct usb_serial *serial)
256{ 247{
257 struct klsi_105_private *priv; 248 struct klsi_105_private *priv;
258 int i, j; 249 int i, j;
@@ -262,7 +253,7 @@ static int klsi_105_startup (struct usb_serial *serial)
262 */ 253 */
263 254
264 /* allocate the private data structure */ 255 /* allocate the private data structure */
265 for (i=0; i<serial->num_ports; i++) { 256 for (i = 0; i < serial->num_ports; i++) {
266 priv = kmalloc(sizeof(struct klsi_105_private), 257 priv = kmalloc(sizeof(struct klsi_105_private),
267 GFP_KERNEL); 258 GFP_KERNEL);
268 if (!priv) { 259 if (!priv) {
@@ -283,9 +274,9 @@ static int klsi_105_startup (struct usb_serial *serial)
283 priv->bytes_out = 0; 274 priv->bytes_out = 0;
284 usb_set_serial_port_data(serial->port[i], priv); 275 usb_set_serial_port_data(serial->port[i], priv);
285 276
286 spin_lock_init (&priv->lock); 277 spin_lock_init(&priv->lock);
287 for (j=0; j<NUM_URBS; j++) { 278 for (j = 0; j < NUM_URBS; j++) {
288 struct urb* urb = usb_alloc_urb(0, GFP_KERNEL); 279 struct urb *urb = usb_alloc_urb(0, GFP_KERNEL);
289 280
290 priv->write_urb_pool[j] = urb; 281 priv->write_urb_pool[j] = urb;
291 if (urb == NULL) { 282 if (urb == NULL) {
@@ -293,10 +284,11 @@ static int klsi_105_startup (struct usb_serial *serial)
293 goto err_cleanup; 284 goto err_cleanup;
294 } 285 }
295 286
296 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, 287 urb->transfer_buffer =
297 GFP_KERNEL); 288 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
298 if (!urb->transfer_buffer) { 289 if (!urb->transfer_buffer) {
299 err("%s - out of memory for urb buffers.", __func__); 290 err("%s - out of memory for urb buffers.",
291 __func__);
300 goto err_cleanup; 292 goto err_cleanup;
301 } 293 }
302 } 294 }
@@ -304,13 +296,13 @@ static int klsi_105_startup (struct usb_serial *serial)
304 /* priv->termios is left uninitalized until port opening */ 296 /* priv->termios is left uninitalized until port opening */
305 init_waitqueue_head(&serial->port[i]->write_wait); 297 init_waitqueue_head(&serial->port[i]->write_wait);
306 } 298 }
307 299
308 return 0; 300 return 0;
309 301
310err_cleanup: 302err_cleanup:
311 for (; i >= 0; i--) { 303 for (; i >= 0; i--) {
312 priv = usb_get_serial_port_data(serial->port[i]); 304 priv = usb_get_serial_port_data(serial->port[i]);
313 for (j=0; j < NUM_URBS; j++) { 305 for (j = 0; j < NUM_URBS; j++) {
314 if (priv->write_urb_pool[j]) { 306 if (priv->write_urb_pool[j]) {
315 kfree(priv->write_urb_pool[j]->transfer_buffer); 307 kfree(priv->write_urb_pool[j]->transfer_buffer);
316 usb_free_urb(priv->write_urb_pool[j]); 308 usb_free_urb(priv->write_urb_pool[j]);
@@ -322,22 +314,23 @@ err_cleanup:
322} /* klsi_105_startup */ 314} /* klsi_105_startup */
323 315
324 316
325static void klsi_105_shutdown (struct usb_serial *serial) 317static void klsi_105_shutdown(struct usb_serial *serial)
326{ 318{
327 int i; 319 int i;
328 320
329 dbg("%s", __func__); 321 dbg("%s", __func__);
330 322
331 /* stop reads and writes on all ports */ 323 /* stop reads and writes on all ports */
332 for (i=0; i < serial->num_ports; ++i) { 324 for (i = 0; i < serial->num_ports; ++i) {
333 struct klsi_105_private *priv = usb_get_serial_port_data(serial->port[i]); 325 struct klsi_105_private *priv =
326 usb_get_serial_port_data(serial->port[i]);
334 unsigned long flags; 327 unsigned long flags;
335 328
336 if (priv) { 329 if (priv) {
337 /* kill our write urb pool */ 330 /* kill our write urb pool */
338 int j; 331 int j;
339 struct urb **write_urbs = priv->write_urb_pool; 332 struct urb **write_urbs = priv->write_urb_pool;
340 spin_lock_irqsave(&priv->lock,flags); 333 spin_lock_irqsave(&priv->lock, flags);
341 334
342 for (j = 0; j < NUM_URBS; j++) { 335 for (j = 0; j < NUM_URBS; j++) {
343 if (write_urbs[j]) { 336 if (write_urbs[j]) {
@@ -349,19 +342,18 @@ static void klsi_105_shutdown (struct usb_serial *serial)
349 * oopses. */ 342 * oopses. */
350 /* usb_kill_urb(write_urbs[j]); */ 343 /* usb_kill_urb(write_urbs[j]); */
351 kfree(write_urbs[j]->transfer_buffer); 344 kfree(write_urbs[j]->transfer_buffer);
352 usb_free_urb (write_urbs[j]); 345 usb_free_urb(write_urbs[j]);
353 } 346 }
354 } 347 }
355 348 spin_unlock_irqrestore(&priv->lock, flags);
356 spin_unlock_irqrestore (&priv->lock, flags);
357
358 kfree(priv); 349 kfree(priv);
359 usb_set_serial_port_data(serial->port[i], NULL); 350 usb_set_serial_port_data(serial->port[i], NULL);
360 } 351 }
361 } 352 }
362} /* klsi_105_shutdown */ 353} /* klsi_105_shutdown */
363 354
364static int klsi_105_open (struct usb_serial_port *port, struct file *filp) 355static int klsi_105_open(struct tty_struct *tty,
356 struct usb_serial_port *port, struct file *filp)
365{ 357{
366 struct klsi_105_private *priv = usb_get_serial_port_data(port); 358 struct klsi_105_private *priv = usb_get_serial_port_data(port);
367 int retval = 0; 359 int retval = 0;
@@ -375,11 +367,11 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
375 367
376 /* force low_latency on so that our tty_push actually forces 368 /* force low_latency on so that our tty_push actually forces
377 * the data through 369 * the data through
378 * port->tty->low_latency = 1; */ 370 * tty->low_latency = 1; */
379 371
380 /* Do a defined restart: 372 /* Do a defined restart:
381 * Set up sane default baud rate and send the 'READ_ON' 373 * Set up sane default baud rate and send the 'READ_ON'
382 * vendor command. 374 * vendor command.
383 * FIXME: set modem line control (how?) 375 * FIXME: set modem line control (how?)
384 * Then read the modem line control and store values in 376 * Then read the modem line control and store values in
385 * priv->line_state. 377 * priv->line_state.
@@ -390,24 +382,24 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
390 cfg.unknown1 = 0; 382 cfg.unknown1 = 0;
391 cfg.unknown2 = 1; 383 cfg.unknown2 = 1;
392 klsi_105_chg_port_settings(port, &cfg); 384 klsi_105_chg_port_settings(port, &cfg);
393 385
394 /* set up termios structure */ 386 /* set up termios structure */
395 spin_lock_irqsave (&priv->lock, flags); 387 spin_lock_irqsave(&priv->lock, flags);
396 priv->termios.c_iflag = port->tty->termios->c_iflag; 388 priv->termios.c_iflag = tty->termios->c_iflag;
397 priv->termios.c_oflag = port->tty->termios->c_oflag; 389 priv->termios.c_oflag = tty->termios->c_oflag;
398 priv->termios.c_cflag = port->tty->termios->c_cflag; 390 priv->termios.c_cflag = tty->termios->c_cflag;
399 priv->termios.c_lflag = port->tty->termios->c_lflag; 391 priv->termios.c_lflag = tty->termios->c_lflag;
400 for (i=0; i<NCCS; i++) 392 for (i = 0; i < NCCS; i++)
401 priv->termios.c_cc[i] = port->tty->termios->c_cc[i]; 393 priv->termios.c_cc[i] = tty->termios->c_cc[i];
402 priv->cfg.pktlen = cfg.pktlen; 394 priv->cfg.pktlen = cfg.pktlen;
403 priv->cfg.baudrate = cfg.baudrate; 395 priv->cfg.baudrate = cfg.baudrate;
404 priv->cfg.databits = cfg.databits; 396 priv->cfg.databits = cfg.databits;
405 priv->cfg.unknown1 = cfg.unknown1; 397 priv->cfg.unknown1 = cfg.unknown1;
406 priv->cfg.unknown2 = cfg.unknown2; 398 priv->cfg.unknown2 = cfg.unknown2;
407 spin_unlock_irqrestore (&priv->lock, flags); 399 spin_unlock_irqrestore(&priv->lock, flags);
408 400
409 /* READ_ON and urb submission */ 401 /* READ_ON and urb submission */
410 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 402 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
411 usb_rcvbulkpipe(port->serial->dev, 403 usb_rcvbulkpipe(port->serial->dev,
412 port->bulk_in_endpointAddress), 404 port->bulk_in_endpointAddress),
413 port->read_urb->transfer_buffer, 405 port->read_urb->transfer_buffer,
@@ -423,7 +415,7 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
423 } 415 }
424 416
425 rc = usb_control_msg(port->serial->dev, 417 rc = usb_control_msg(port->serial->dev,
426 usb_sndctrlpipe(port->serial->dev,0), 418 usb_sndctrlpipe(port->serial->dev, 0),
427 KL5KUSB105A_SIO_CONFIGURE, 419 KL5KUSB105A_SIO_CONFIGURE,
428 USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE, 420 USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE,
429 KL5KUSB105A_SIO_CONFIGURE_READ_ON, 421 KL5KUSB105A_SIO_CONFIGURE_READ_ON,
@@ -434,14 +426,14 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
434 if (rc < 0) { 426 if (rc < 0) {
435 err("Enabling read failed (error = %d)", rc); 427 err("Enabling read failed (error = %d)", rc);
436 retval = rc; 428 retval = rc;
437 } else 429 } else
438 dbg("%s - enabled reading", __func__); 430 dbg("%s - enabled reading", __func__);
439 431
440 rc = klsi_105_get_line_state(port, &line_state); 432 rc = klsi_105_get_line_state(port, &line_state);
441 if (rc >= 0) { 433 if (rc >= 0) {
442 spin_lock_irqsave (&priv->lock, flags); 434 spin_lock_irqsave(&priv->lock, flags);
443 priv->line_state = line_state; 435 priv->line_state = line_state;
444 spin_unlock_irqrestore (&priv->lock, flags); 436 spin_unlock_irqrestore(&priv->lock, flags);
445 dbg("%s - read line state 0x%lx", __func__, line_state); 437 dbg("%s - read line state 0x%lx", __func__, line_state);
446 retval = 0; 438 retval = 0;
447 } else 439 } else
@@ -452,7 +444,8 @@ exit:
452} /* klsi_105_open */ 444} /* klsi_105_open */
453 445
454 446
455static void klsi_105_close (struct usb_serial_port *port, struct file *filp) 447static void klsi_105_close(struct tty_struct *tty,
448 struct usb_serial_port *port, struct file *filp)
456{ 449{
457 struct klsi_105_private *priv = usb_get_serial_port_data(port); 450 struct klsi_105_private *priv = usb_get_serial_port_data(port);
458 int rc; 451 int rc;
@@ -462,14 +455,14 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
462 mutex_lock(&port->serial->disc_mutex); 455 mutex_lock(&port->serial->disc_mutex);
463 if (!port->serial->disconnected) { 456 if (!port->serial->disconnected) {
464 /* send READ_OFF */ 457 /* send READ_OFF */
465 rc = usb_control_msg (port->serial->dev, 458 rc = usb_control_msg(port->serial->dev,
466 usb_sndctrlpipe(port->serial->dev, 0), 459 usb_sndctrlpipe(port->serial->dev, 0),
467 KL5KUSB105A_SIO_CONFIGURE, 460 KL5KUSB105A_SIO_CONFIGURE,
468 USB_TYPE_VENDOR | USB_DIR_OUT, 461 USB_TYPE_VENDOR | USB_DIR_OUT,
469 KL5KUSB105A_SIO_CONFIGURE_READ_OFF, 462 KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
470 0, /* index */ 463 0, /* index */
471 NULL, 0, 464 NULL, 0,
472 KLSI_TIMEOUT); 465 KLSI_TIMEOUT);
473 if (rc < 0) 466 if (rc < 0)
474 err("Disabling read failed (error = %d)", rc); 467 err("Disabling read failed (error = %d)", rc);
475 } 468 }
@@ -482,23 +475,24 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
482 /* FIXME */ 475 /* FIXME */
483 /* wgg - do I need this? I think so. */ 476 /* wgg - do I need this? I think so. */
484 usb_kill_urb(port->interrupt_in_urb); 477 usb_kill_urb(port->interrupt_in_urb);
485 info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out); 478 info("kl5kusb105 port stats: %ld bytes in, %ld bytes out",
479 priv->bytes_in, priv->bytes_out);
486} /* klsi_105_close */ 480} /* klsi_105_close */
487 481
488 482
489/* We need to write a complete 64-byte data block and encode the 483/* We need to write a complete 64-byte data block and encode the
490 * number actually sent in the first double-byte, LSB-order. That 484 * number actually sent in the first double-byte, LSB-order. That
491 * leaves at most 62 bytes of payload. 485 * leaves at most 62 bytes of payload.
492 */ 486 */
493#define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */ 487#define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
494 488
495 489
496static int klsi_105_write (struct usb_serial_port *port, 490static int klsi_105_write(struct tty_struct *tty,
497 const unsigned char *buf, int count) 491 struct usb_serial_port *port, const unsigned char *buf, int count)
498{ 492{
499 struct klsi_105_private *priv = usb_get_serial_port_data(port); 493 struct klsi_105_private *priv = usb_get_serial_port_data(port);
500 int result, size; 494 int result, size;
501 int bytes_sent=0; 495 int bytes_sent = 0;
502 496
503 dbg("%s - port %d", __func__, port->number); 497 dbg("%s - port %d", __func__, port->number);
504 498
@@ -507,34 +501,37 @@ static int klsi_105_write (struct usb_serial_port *port,
507 struct urb *urb = NULL; 501 struct urb *urb = NULL;
508 unsigned long flags; 502 unsigned long flags;
509 int i; 503 int i;
510 /* since the pool is per-port we might not need the spin lock !? */ 504 /* since the pool is per-port we might not need
511 spin_lock_irqsave (&priv->lock, flags); 505 the spin lock !? */
512 for (i=0; i<NUM_URBS; i++) { 506 spin_lock_irqsave(&priv->lock, flags);
507 for (i = 0; i < NUM_URBS; i++) {
513 if (priv->write_urb_pool[i]->status != -EINPROGRESS) { 508 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
514 urb = priv->write_urb_pool[i]; 509 urb = priv->write_urb_pool[i];
515 dbg("%s - using pool URB %d", __func__, i); 510 dbg("%s - using pool URB %d", __func__, i);
516 break; 511 break;
517 } 512 }
518 } 513 }
519 spin_unlock_irqrestore (&priv->lock, flags); 514 spin_unlock_irqrestore(&priv->lock, flags);
520 515
521 if (urb==NULL) { 516 if (urb == NULL) {
522 dbg("%s - no more free urbs", __func__); 517 dbg("%s - no more free urbs", __func__);
523 goto exit; 518 goto exit;
524 } 519 }
525 520
526 if (urb->transfer_buffer == NULL) { 521 if (urb->transfer_buffer == NULL) {
527 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); 522 urb->transfer_buffer =
523 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
528 if (urb->transfer_buffer == NULL) { 524 if (urb->transfer_buffer == NULL) {
529 err("%s - no more kernel memory...", __func__); 525 err("%s - no more kernel memory...", __func__);
530 goto exit; 526 goto exit;
531 } 527 }
532 } 528 }
533 529
534 size = min (count, port->bulk_out_size - KLSI_105_DATA_OFFSET); 530 size = min(count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
535 size = min (size, URB_TRANSFER_BUFFER_SIZE - KLSI_105_DATA_OFFSET); 531 size = min(size, URB_TRANSFER_BUFFER_SIZE -
532 KLSI_105_DATA_OFFSET);
536 533
537 memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size); 534 memcpy(urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size);
538 535
539 /* write payload size into transfer buffer */ 536 /* write payload size into transfer buffer */
540 ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF); 537 ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF);
@@ -552,7 +549,8 @@ static int klsi_105_write (struct usb_serial_port *port,
552 /* send the data out the bulk port */ 549 /* send the data out the bulk port */
553 result = usb_submit_urb(urb, GFP_ATOMIC); 550 result = usb_submit_urb(urb, GFP_ATOMIC);
554 if (result) { 551 if (result) {
555 err("%s - failed submitting write urb, error %d", __func__, result); 552 err("%s - failed submitting write urb, error %d",
553 __func__, result);
556 goto exit; 554 goto exit;
557 } 555 }
558 buf += size; 556 buf += size;
@@ -561,12 +559,12 @@ static int klsi_105_write (struct usb_serial_port *port,
561 } 559 }
562exit: 560exit:
563 /* lockless, but it's for debug info only... */ 561 /* lockless, but it's for debug info only... */
564 priv->bytes_out+=bytes_sent; 562 priv->bytes_out += bytes_sent;
565 563
566 return bytes_sent; /* that's how much we wrote */ 564 return bytes_sent; /* that's how much we wrote */
567} /* klsi_105_write */ 565} /* klsi_105_write */
568 566
569static void klsi_105_write_bulk_callback ( struct urb *urb) 567static void klsi_105_write_bulk_callback(struct urb *urb)
570{ 568{
571 struct usb_serial_port *port = urb->context; 569 struct usb_serial_port *port = urb->context;
572 int status = urb->status; 570 int status = urb->status;
@@ -584,50 +582,50 @@ static void klsi_105_write_bulk_callback ( struct urb *urb)
584 582
585 583
586/* return number of characters currently in the writing process */ 584/* return number of characters currently in the writing process */
587static int klsi_105_chars_in_buffer (struct usb_serial_port *port) 585static int klsi_105_chars_in_buffer(struct tty_struct *tty)
588{ 586{
587 struct usb_serial_port *port = tty->driver_data;
589 int chars = 0; 588 int chars = 0;
590 int i; 589 int i;
591 unsigned long flags; 590 unsigned long flags;
592 struct klsi_105_private *priv = usb_get_serial_port_data(port); 591 struct klsi_105_private *priv = usb_get_serial_port_data(port);
593 592
594 spin_lock_irqsave (&priv->lock, flags); 593 spin_lock_irqsave(&priv->lock, flags);
595 594
596 for (i = 0; i < NUM_URBS; ++i) { 595 for (i = 0; i < NUM_URBS; ++i) {
597 if (priv->write_urb_pool[i]->status == -EINPROGRESS) { 596 if (priv->write_urb_pool[i]->status == -EINPROGRESS)
598 chars += URB_TRANSFER_BUFFER_SIZE; 597 chars += URB_TRANSFER_BUFFER_SIZE;
599 }
600 } 598 }
601 599
602 spin_unlock_irqrestore (&priv->lock, flags); 600 spin_unlock_irqrestore(&priv->lock, flags);
603 601
604 dbg("%s - returns %d", __func__, chars); 602 dbg("%s - returns %d", __func__, chars);
605 return (chars); 603 return chars;
606} 604}
607 605
608static int klsi_105_write_room (struct usb_serial_port *port) 606static int klsi_105_write_room(struct tty_struct *tty)
609{ 607{
608 struct usb_serial_port *port = tty->driver_data;
610 unsigned long flags; 609 unsigned long flags;
611 int i; 610 int i;
612 int room = 0; 611 int room = 0;
613 struct klsi_105_private *priv = usb_get_serial_port_data(port); 612 struct klsi_105_private *priv = usb_get_serial_port_data(port);
614 613
615 spin_lock_irqsave (&priv->lock, flags); 614 spin_lock_irqsave(&priv->lock, flags);
616 for (i = 0; i < NUM_URBS; ++i) { 615 for (i = 0; i < NUM_URBS; ++i) {
617 if (priv->write_urb_pool[i]->status != -EINPROGRESS) { 616 if (priv->write_urb_pool[i]->status != -EINPROGRESS)
618 room += URB_TRANSFER_BUFFER_SIZE; 617 room += URB_TRANSFER_BUFFER_SIZE;
619 }
620 } 618 }
621 619
622 spin_unlock_irqrestore (&priv->lock, flags); 620 spin_unlock_irqrestore(&priv->lock, flags);
623 621
624 dbg("%s - returns %d", __func__, room); 622 dbg("%s - returns %d", __func__, room);
625 return (room); 623 return room;
626} 624}
627 625
628 626
629 627
630static void klsi_105_read_bulk_callback (struct urb *urb) 628static void klsi_105_read_bulk_callback(struct urb *urb)
631{ 629{
632 struct usb_serial_port *port = urb->context; 630 struct usb_serial_port *port = urb->context;
633 struct klsi_105_private *priv = usb_get_serial_port_data(port); 631 struct klsi_105_private *priv = usb_get_serial_port_data(port);
@@ -660,13 +658,13 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
660 } else { 658 } else {
661 int bytes_sent = ((__u8 *) data)[0] + 659 int bytes_sent = ((__u8 *) data)[0] +
662 ((unsigned int) ((__u8 *) data)[1] << 8); 660 ((unsigned int) ((__u8 *) data)[1] << 8);
663 tty = port->tty; 661 tty = port->port.tty;
664 /* we should immediately resubmit the URB, before attempting 662 /* we should immediately resubmit the URB, before attempting
665 * to pass the data on to the tty layer. But that needs locking 663 * to pass the data on to the tty layer. But that needs locking
666 * against re-entry an then mixed-up data because of 664 * against re-entry an then mixed-up data because of
667 * intermixed tty_flip_buffer_push()s 665 * intermixed tty_flip_buffer_push()s
668 * FIXME 666 * FIXME
669 */ 667 */
670 usb_serial_debug_data(debug, &port->dev, __func__, 668 usb_serial_debug_data(debug, &port->dev, __func__,
671 urb->actual_length, data); 669 urb->actual_length, data);
672 670
@@ -686,7 +684,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
686 priv->bytes_in += bytes_sent; 684 priv->bytes_in += bytes_sent;
687 } 685 }
688 /* Continue trying to always read */ 686 /* Continue trying to always read */
689 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 687 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
690 usb_rcvbulkpipe(port->serial->dev, 688 usb_rcvbulkpipe(port->serial->dev,
691 port->bulk_in_endpointAddress), 689 port->bulk_in_endpointAddress),
692 port->read_urb->transfer_buffer, 690 port->read_urb->transfer_buffer,
@@ -695,15 +693,16 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
695 port); 693 port);
696 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC); 694 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC);
697 if (rc) 695 if (rc)
698 err("%s - failed resubmitting read urb, error %d", __func__, rc); 696 err("%s - failed resubmitting read urb, error %d",
697 __func__, rc);
699} /* klsi_105_read_bulk_callback */ 698} /* klsi_105_read_bulk_callback */
700 699
701 700
702static void klsi_105_set_termios (struct usb_serial_port *port, 701static void klsi_105_set_termios(struct tty_struct *tty,
703 struct ktermios *old_termios) 702 struct usb_serial_port *port,
703 struct ktermios *old_termios)
704{ 704{
705 struct klsi_105_private *priv = usb_get_serial_port_data(port); 705 struct klsi_105_private *priv = usb_get_serial_port_data(port);
706 struct tty_struct *tty = port->tty;
707 unsigned int iflag = tty->termios->c_iflag; 706 unsigned int iflag = tty->termios->c_iflag;
708 unsigned int old_iflag = old_termios->c_iflag; 707 unsigned int old_iflag = old_termios->c_iflag;
709 unsigned int cflag = tty->termios->c_cflag; 708 unsigned int cflag = tty->termios->c_cflag;
@@ -711,65 +710,63 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
711 struct klsi_105_port_settings cfg; 710 struct klsi_105_port_settings cfg;
712 unsigned long flags; 711 unsigned long flags;
713 speed_t baud; 712 speed_t baud;
714 713
715 /* lock while we are modifying the settings */ 714 /* lock while we are modifying the settings */
716 spin_lock_irqsave (&priv->lock, flags); 715 spin_lock_irqsave(&priv->lock, flags);
717 716
718 /* 717 /*
719 * Update baud rate 718 * Update baud rate
720 */ 719 */
721 baud = tty_get_baud_rate(tty); 720 baud = tty_get_baud_rate(tty);
722 721
723 if( (cflag & CBAUD) != (old_cflag & CBAUD) ) { 722 if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
724 /* reassert DTR and (maybe) RTS on transition from B0 */ 723 /* reassert DTR and (maybe) RTS on transition from B0 */
725 if( (old_cflag & CBAUD) == B0 ) { 724 if ((old_cflag & CBAUD) == B0) {
726 dbg("%s: baud was B0", __func__); 725 dbg("%s: baud was B0", __func__);
727#if 0 726#if 0
728 priv->control_state |= TIOCM_DTR; 727 priv->control_state |= TIOCM_DTR;
729 /* don't set RTS if using hardware flow control */ 728 /* don't set RTS if using hardware flow control */
730 if (!(old_cflag & CRTSCTS)) { 729 if (!(old_cflag & CRTSCTS))
731 priv->control_state |= TIOCM_RTS; 730 priv->control_state |= TIOCM_RTS;
732 }
733 mct_u232_set_modem_ctrl(serial, priv->control_state); 731 mct_u232_set_modem_ctrl(serial, priv->control_state);
734#endif 732#endif
735 } 733 }
736 } 734 }
737 switch(baud) { 735 switch (baud) {
738 case 0: /* handled below */ 736 case 0: /* handled below */
739 break; 737 break;
740 case 1200: 738 case 1200:
741 priv->cfg.baudrate = kl5kusb105a_sio_b1200; 739 priv->cfg.baudrate = kl5kusb105a_sio_b1200;
742 break; 740 break;
743 case 2400: 741 case 2400:
744 priv->cfg.baudrate = kl5kusb105a_sio_b2400; 742 priv->cfg.baudrate = kl5kusb105a_sio_b2400;
745 break; 743 break;
746 case 4800: 744 case 4800:
747 priv->cfg.baudrate = kl5kusb105a_sio_b4800; 745 priv->cfg.baudrate = kl5kusb105a_sio_b4800;
748 break; 746 break;
749 case 9600: 747 case 9600:
750 priv->cfg.baudrate = kl5kusb105a_sio_b9600; 748 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
751 break; 749 break;
752 case 19200: 750 case 19200:
753 priv->cfg.baudrate = kl5kusb105a_sio_b19200; 751 priv->cfg.baudrate = kl5kusb105a_sio_b19200;
754 break; 752 break;
755 case 38400: 753 case 38400:
756 priv->cfg.baudrate = kl5kusb105a_sio_b38400; 754 priv->cfg.baudrate = kl5kusb105a_sio_b38400;
757 break; 755 break;
758 case 57600: 756 case 57600:
759 priv->cfg.baudrate = kl5kusb105a_sio_b57600; 757 priv->cfg.baudrate = kl5kusb105a_sio_b57600;
760 break; 758 break;
761 case 115200: 759 case 115200:
762 priv->cfg.baudrate = kl5kusb105a_sio_b115200; 760 priv->cfg.baudrate = kl5kusb105a_sio_b115200;
763 break; 761 break;
764 default: 762 default:
765 dbg("KLSI USB->Serial converter:" 763 dbg("KLSI USB->Serial converter:"
766 " unsupported baudrate request, using default" 764 " unsupported baudrate request, using default of 9600");
767 " of 9600");
768 priv->cfg.baudrate = kl5kusb105a_sio_b9600; 765 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
769 baud = 9600; 766 baud = 9600;
770 break; 767 break;
771 } 768 }
772 if ((cflag & CBAUD) == B0 ) { 769 if ((cflag & CBAUD) == B0) {
773 dbg("%s: baud is B0", __func__); 770 dbg("%s: baud is B0", __func__);
774 /* Drop RTS and DTR */ 771 /* Drop RTS and DTR */
775 /* maybe this should be simulated by sending read 772 /* maybe this should be simulated by sending read
@@ -778,7 +775,7 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
778 ; 775 ;
779#if 0 776#if 0
780 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); 777 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
781 mct_u232_set_modem_ctrl(serial, priv->control_state); 778 mct_u232_set_modem_ctrl(serial, priv->control_state);
782#endif 779#endif
783 } 780 }
784 tty_encode_baud_rate(tty, baud, baud); 781 tty_encode_baud_rate(tty, baud, baud);
@@ -788,11 +785,11 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
788 switch (cflag & CSIZE) { 785 switch (cflag & CSIZE) {
789 case CS5: 786 case CS5:
790 dbg("%s - 5 bits/byte not supported", __func__); 787 dbg("%s - 5 bits/byte not supported", __func__);
791 spin_unlock_irqrestore (&priv->lock, flags); 788 spin_unlock_irqrestore(&priv->lock, flags);
792 return ; 789 return ;
793 case CS6: 790 case CS6:
794 dbg("%s - 6 bits/byte not supported", __func__); 791 dbg("%s - 6 bits/byte not supported", __func__);
795 spin_unlock_irqrestore (&priv->lock, flags); 792 spin_unlock_irqrestore(&priv->lock, flags);
796 return ; 793 return ;
797 case CS7: 794 case CS7:
798 priv->cfg.databits = kl5kusb105a_dtb_7; 795 priv->cfg.databits = kl5kusb105a_dtb_7;
@@ -811,8 +808,7 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
811 * Update line control register (LCR) 808 * Update line control register (LCR)
812 */ 809 */
813 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD)) 810 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
814 || (cflag & CSTOPB) != (old_cflag & CSTOPB) ) { 811 || (cflag & CSTOPB) != (old_cflag & CSTOPB)) {
815
816 /* Not currently supported */ 812 /* Not currently supported */
817 tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB); 813 tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB);
818#if 0 814#if 0
@@ -833,20 +829,18 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
833#endif 829#endif
834 ; 830 ;
835 } 831 }
836
837 /* 832 /*
838 * Set flow control: well, I do not really now how to handle DTR/RTS. 833 * Set flow control: well, I do not really now how to handle DTR/RTS.
839 * Just do what we have seen with SniffUSB on Win98. 834 * Just do what we have seen with SniffUSB on Win98.
840 */ 835 */
841 if( (iflag & IXOFF) != (old_iflag & IXOFF) 836 if ((iflag & IXOFF) != (old_iflag & IXOFF)
842 || (iflag & IXON) != (old_iflag & IXON) 837 || (iflag & IXON) != (old_iflag & IXON)
843 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) { 838 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
844
845 /* Not currently supported */ 839 /* Not currently supported */
846 tty->termios->c_cflag &= ~CRTSCTS; 840 tty->termios->c_cflag &= ~CRTSCTS;
847 /* Drop DTR/RTS if no flow control otherwise assert */ 841 /* Drop DTR/RTS if no flow control otherwise assert */
848#if 0 842#if 0
849 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) ) 843 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
850 priv->control_state |= TIOCM_DTR | TIOCM_RTS; 844 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
851 else 845 else
852 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); 846 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
@@ -854,19 +848,21 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
854#endif 848#endif
855 ; 849 ;
856 } 850 }
857 memcpy (&cfg, &priv->cfg, sizeof(cfg)); 851 memcpy(&cfg, &priv->cfg, sizeof(cfg));
858 spin_unlock_irqrestore (&priv->lock, flags); 852 spin_unlock_irqrestore(&priv->lock, flags);
859 853
860 /* now commit changes to device */ 854 /* now commit changes to device */
861 klsi_105_chg_port_settings(port, &cfg); 855 klsi_105_chg_port_settings(port, &cfg);
862} /* klsi_105_set_termios */ 856} /* klsi_105_set_termios */
863 857
864 858
865#if 0 859#if 0
866static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state ) 860static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
867{ 861{
862 struct usb_serial_port *port = tty->driver_data;
868 struct usb_serial *serial = port->serial; 863 struct usb_serial *serial = port->serial;
869 struct mct_u232_private *priv = (struct mct_u232_private *)port->private; 864 struct mct_u232_private *priv =
865 (struct mct_u232_private *)port->private;
870 unsigned char lcr = priv->last_lcr; 866 unsigned char lcr = priv->last_lcr;
871 867
872 dbg("%sstate=%d", __func__, break_state); 868 dbg("%sstate=%d", __func__, break_state);
@@ -878,8 +874,9 @@ static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
878} /* mct_u232_break_ctl */ 874} /* mct_u232_break_ctl */
879#endif 875#endif
880 876
881static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file) 877static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file)
882{ 878{
879 struct usb_serial_port *port = tty->driver_data;
883 struct klsi_105_private *priv = usb_get_serial_port_data(port); 880 struct klsi_105_private *priv = usb_get_serial_port_data(port);
884 unsigned long flags; 881 unsigned long flags;
885 int rc; 882 int rc;
@@ -893,18 +890,18 @@ static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file)
893 return rc; 890 return rc;
894 } 891 }
895 892
896 spin_lock_irqsave (&priv->lock, flags); 893 spin_lock_irqsave(&priv->lock, flags);
897 priv->line_state = line_state; 894 priv->line_state = line_state;
898 spin_unlock_irqrestore (&priv->lock, flags); 895 spin_unlock_irqrestore(&priv->lock, flags);
899 dbg("%s - read line state 0x%lx", __func__, line_state); 896 dbg("%s - read line state 0x%lx", __func__, line_state);
900 return (int)line_state; 897 return (int)line_state;
901} 898}
902 899
903static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file, 900static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
904 unsigned int set, unsigned int clear) 901 unsigned int set, unsigned int clear)
905{ 902{
906 int retval = -EINVAL; 903 int retval = -EINVAL;
907 904
908 dbg("%s", __func__); 905 dbg("%s", __func__);
909 906
910/* if this ever gets implemented, it should be done something like this: 907/* if this ever gets implemented, it should be done something like this:
@@ -929,14 +926,16 @@ static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file,
929 return retval; 926 return retval;
930} 927}
931 928
932static void klsi_105_throttle (struct usb_serial_port *port) 929static void klsi_105_throttle(struct tty_struct *tty)
933{ 930{
931 struct usb_serial_port *port = tty->driver_data;
934 dbg("%s - port %d", __func__, port->number); 932 dbg("%s - port %d", __func__, port->number);
935 usb_kill_urb(port->read_urb); 933 usb_kill_urb(port->read_urb);
936} 934}
937 935
938static void klsi_105_unthrottle (struct usb_serial_port *port) 936static void klsi_105_unthrottle(struct tty_struct *tty)
939{ 937{
938 struct usb_serial_port *port = tty->driver_data;
940 int result; 939 int result;
941 940
942 dbg("%s - port %d", __func__, port->number); 941 dbg("%s - port %d", __func__, port->number);
@@ -950,7 +949,7 @@ static void klsi_105_unthrottle (struct usb_serial_port *port)
950 949
951 950
952 951
953static int __init klsi_105_init (void) 952static int __init klsi_105_init(void)
954{ 953{
955 int retval; 954 int retval;
956 retval = usb_serial_register(&kl5kusb105d_device); 955 retval = usb_serial_register(&kl5kusb105d_device);
@@ -969,19 +968,19 @@ failed_usb_serial_register:
969} 968}
970 969
971 970
972static void __exit klsi_105_exit (void) 971static void __exit klsi_105_exit(void)
973{ 972{
974 usb_deregister (&kl5kusb105d_driver); 973 usb_deregister(&kl5kusb105d_driver);
975 usb_serial_deregister (&kl5kusb105d_device); 974 usb_serial_deregister(&kl5kusb105d_device);
976} 975}
977 976
978 977
979module_init (klsi_105_init); 978module_init(klsi_105_init);
980module_exit (klsi_105_exit); 979module_exit(klsi_105_exit);
981 980
982MODULE_AUTHOR( DRIVER_AUTHOR ); 981MODULE_AUTHOR(DRIVER_AUTHOR);
983MODULE_DESCRIPTION( DRIVER_DESC ); 982MODULE_DESCRIPTION(DRIVER_DESC);
984MODULE_LICENSE("GPL"); 983MODULE_LICENSE("GPL");
985 984
986 985
987module_param(debug, bool, S_IRUGO | S_IWUSR); 986module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 693f00da7c03..deba28ec77e8 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * KOBIL USB Smart Card Terminal Driver 2 * KOBIL USB Smart Card Terminal Driver
3 * 3 *
4 * Copyright (C) 2002 KOBIL Systems GmbH 4 * Copyright (C) 2002 KOBIL Systems GmbH
5 * Author: Thomas Wahrenbruch 5 * Author: Thomas Wahrenbruch
6 * 6 *
7 * Contact: linuxusb@kobil.de 7 * Contact: linuxusb@kobil.de
@@ -20,7 +20,7 @@
20 * 20 *
21 * Supported readers: USB TWIN, KAAN Standard Plus and SecOVID Reader Plus 21 * Supported readers: USB TWIN, KAAN Standard Plus and SecOVID Reader Plus
22 * (Adapter K), B1 Professional and KAAN Professional (Adapter B) 22 * (Adapter K), B1 Professional and KAAN Professional (Adapter B)
23 * 23 *
24 * (21/05/2004) tw 24 * (21/05/2004) tw
25 * Fix bug with P'n'P readers 25 * Fix bug with P'n'P readers
26 * 26 *
@@ -44,7 +44,7 @@
44#include <linux/tty_flip.h> 44#include <linux/tty_flip.h>
45#include <linux/module.h> 45#include <linux/module.h>
46#include <linux/spinlock.h> 46#include <linux/spinlock.h>
47#include <asm/uaccess.h> 47#include <linux/uaccess.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/usb/serial.h> 49#include <linux/usb/serial.h>
50#include <linux/ioctl.h> 50#include <linux/ioctl.h>
@@ -68,21 +68,24 @@ static int debug;
68 68
69 69
70/* Function prototypes */ 70/* Function prototypes */
71static int kobil_startup (struct usb_serial *serial); 71static int kobil_startup(struct usb_serial *serial);
72static void kobil_shutdown (struct usb_serial *serial); 72static void kobil_shutdown(struct usb_serial *serial);
73static int kobil_open (struct usb_serial_port *port, struct file *filp); 73static int kobil_open(struct tty_struct *tty,
74static void kobil_close (struct usb_serial_port *port, struct file *filp); 74 struct usb_serial_port *port, struct file *filp);
75static int kobil_write (struct usb_serial_port *port, 75static void kobil_close(struct tty_struct *tty, struct usb_serial_port *port,
76 struct file *filp);
77static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
76 const unsigned char *buf, int count); 78 const unsigned char *buf, int count);
77static int kobil_write_room(struct usb_serial_port *port); 79static int kobil_write_room(struct tty_struct *tty);
78static int kobil_ioctl(struct usb_serial_port *port, struct file *file, 80static int kobil_ioctl(struct tty_struct *tty, struct file *file,
79 unsigned int cmd, unsigned long arg); 81 unsigned int cmd, unsigned long arg);
80static int kobil_tiocmget(struct usb_serial_port *port, struct file *file); 82static int kobil_tiocmget(struct tty_struct *tty, struct file *file);
81static int kobil_tiocmset(struct usb_serial_port *port, struct file *file, 83static int kobil_tiocmset(struct tty_struct *tty, struct file *file,
82 unsigned int set, unsigned int clear); 84 unsigned int set, unsigned int clear);
83static void kobil_read_int_callback( struct urb *urb ); 85static void kobil_read_int_callback(struct urb *urb);
84static void kobil_write_callback( struct urb *purb ); 86static void kobil_write_callback(struct urb *purb);
85static void kobil_set_termios(struct usb_serial_port *port, struct ktermios *old); 87static void kobil_set_termios(struct tty_struct *tty,
88 struct usb_serial_port *port, struct ktermios *old);
86 89
87 90
88static struct usb_device_id id_table [] = { 91static struct usb_device_id id_table [] = {
@@ -94,7 +97,7 @@ static struct usb_device_id id_table [] = {
94}; 97};
95 98
96 99
97MODULE_DEVICE_TABLE (usb, id_table); 100MODULE_DEVICE_TABLE(usb, id_table);
98 101
99static struct usb_driver kobil_driver = { 102static struct usb_driver kobil_driver = {
100 .name = "kobil", 103 .name = "kobil",
@@ -131,14 +134,14 @@ static struct usb_serial_driver kobil_device = {
131struct kobil_private { 134struct kobil_private {
132 int write_int_endpoint_address; 135 int write_int_endpoint_address;
133 int read_int_endpoint_address; 136 int read_int_endpoint_address;
134 unsigned char buf[KOBIL_BUF_LENGTH]; // buffer for the APDU to send 137 unsigned char buf[KOBIL_BUF_LENGTH]; /* buffer for the APDU to send */
135 int filled; // index of the last char in buf 138 int filled; /* index of the last char in buf */
136 int cur_pos; // index of the next char to send in buf 139 int cur_pos; /* index of the next char to send in buf */
137 __u16 device_type; 140 __u16 device_type;
138}; 141};
139 142
140 143
141static int kobil_startup (struct usb_serial *serial) 144static int kobil_startup(struct usb_serial *serial)
142{ 145{
143 int i; 146 int i;
144 struct kobil_private *priv; 147 struct kobil_private *priv;
@@ -149,20 +152,20 @@ static int kobil_startup (struct usb_serial *serial)
149 struct usb_host_endpoint *endpoint; 152 struct usb_host_endpoint *endpoint;
150 153
151 priv = kmalloc(sizeof(struct kobil_private), GFP_KERNEL); 154 priv = kmalloc(sizeof(struct kobil_private), GFP_KERNEL);
152 if (!priv){ 155 if (!priv)
153 return -ENOMEM; 156 return -ENOMEM;
154 }
155 157
156 priv->filled = 0; 158 priv->filled = 0;
157 priv->cur_pos = 0; 159 priv->cur_pos = 0;
158 priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct); 160 priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct);
159 161
160 switch (priv->device_type){ 162 switch (priv->device_type) {
161 case KOBIL_ADAPTER_B_PRODUCT_ID: 163 case KOBIL_ADAPTER_B_PRODUCT_ID:
162 printk(KERN_DEBUG "KOBIL B1 PRO / KAAN PRO detected\n"); 164 printk(KERN_DEBUG "KOBIL B1 PRO / KAAN PRO detected\n");
163 break; 165 break;
164 case KOBIL_ADAPTER_K_PRODUCT_ID: 166 case KOBIL_ADAPTER_K_PRODUCT_ID:
165 printk(KERN_DEBUG "KOBIL KAAN Standard Plus / SecOVID Reader Plus detected\n"); 167 printk(KERN_DEBUG
168 "KOBIL KAAN Standard Plus / SecOVID Reader Plus detected\n");
166 break; 169 break;
167 case KOBIL_USBTWIN_PRODUCT_ID: 170 case KOBIL_USBTWIN_PRODUCT_ID:
168 printk(KERN_DEBUG "KOBIL USBTWIN detected\n"); 171 printk(KERN_DEBUG "KOBIL USBTWIN detected\n");
@@ -173,44 +176,48 @@ static int kobil_startup (struct usb_serial *serial)
173 } 176 }
174 usb_set_serial_port_data(serial->port[0], priv); 177 usb_set_serial_port_data(serial->port[0], priv);
175 178
176 // search for the necessary endpoints 179 /* search for the necessary endpoints */
177 pdev = serial->dev; 180 pdev = serial->dev;
178 actconfig = pdev->actconfig; 181 actconfig = pdev->actconfig;
179 interface = actconfig->interface[0]; 182 interface = actconfig->interface[0];
180 altsetting = interface->cur_altsetting; 183 altsetting = interface->cur_altsetting;
181 endpoint = altsetting->endpoint; 184 endpoint = altsetting->endpoint;
182 185
183 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { 186 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) {
184 endpoint = &altsetting->endpoint[i]; 187 endpoint = &altsetting->endpoint[i];
185 if (usb_endpoint_is_int_out(&endpoint->desc)) { 188 if (usb_endpoint_is_int_out(&endpoint->desc)) {
186 dbg("%s Found interrupt out endpoint. Address: %d", __func__, endpoint->desc.bEndpointAddress); 189 dbg("%s Found interrupt out endpoint. Address: %d",
187 priv->write_int_endpoint_address = endpoint->desc.bEndpointAddress; 190 __func__, endpoint->desc.bEndpointAddress);
188 } 191 priv->write_int_endpoint_address =
192 endpoint->desc.bEndpointAddress;
193 }
189 if (usb_endpoint_is_int_in(&endpoint->desc)) { 194 if (usb_endpoint_is_int_in(&endpoint->desc)) {
190 dbg("%s Found interrupt in endpoint. Address: %d", __func__, endpoint->desc.bEndpointAddress); 195 dbg("%s Found interrupt in endpoint. Address: %d",
191 priv->read_int_endpoint_address = endpoint->desc.bEndpointAddress; 196 __func__, endpoint->desc.bEndpointAddress);
192 } 197 priv->read_int_endpoint_address =
198 endpoint->desc.bEndpointAddress;
199 }
193 } 200 }
194 return 0; 201 return 0;
195} 202}
196 203
197 204
198static void kobil_shutdown (struct usb_serial *serial) 205static void kobil_shutdown(struct usb_serial *serial)
199{ 206{
200 int i; 207 int i;
201 dbg("%s - port %d", __func__, serial->port[0]->number); 208 dbg("%s - port %d", __func__, serial->port[0]->number);
202 209
203 for (i=0; i < serial->num_ports; ++i) { 210 for (i = 0; i < serial->num_ports; ++i) {
204 while (serial->port[i]->open_count > 0) { 211 while (serial->port[i]->port.count > 0)
205 kobil_close (serial->port[i], NULL); 212 kobil_close(NULL, serial->port[i], NULL);
206 }
207 kfree(usb_get_serial_port_data(serial->port[i])); 213 kfree(usb_get_serial_port_data(serial->port[i]));
208 usb_set_serial_port_data(serial->port[i], NULL); 214 usb_set_serial_port_data(serial->port[i], NULL);
209 } 215 }
210} 216}
211 217
212 218
213static int kobil_open (struct usb_serial_port *port, struct file *filp) 219static int kobil_open(struct tty_struct *tty,
220 struct usb_serial_port *port, struct file *filp)
214{ 221{
215 int result = 0; 222 int result = 0;
216 struct kobil_private *priv; 223 struct kobil_private *priv;
@@ -221,7 +228,7 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
221 dbg("%s - port %d", __func__, port->number); 228 dbg("%s - port %d", __func__, port->number);
222 priv = usb_get_serial_port_data(port); 229 priv = usb_get_serial_port_data(port);
223 230
224 // someone sets the dev to 0 if the close method has been called 231 /* someone sets the dev to 0 if the close method has been called */
225 port->interrupt_in_urb->dev = port->serial->dev; 232 port->interrupt_in_urb->dev = port->serial->dev;
226 233
227 234
@@ -229,100 +236,115 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
229 * the data through, otherwise it is scheduled, and with high 236 * the data through, otherwise it is scheduled, and with high
230 * data rates (like with OHCI) data can get lost. 237 * data rates (like with OHCI) data can get lost.
231 */ 238 */
232 port->tty->low_latency = 1; 239 if (tty) {
233 240 tty->low_latency = 1;
234 // without this, every push_tty_char is echoed :-( 241
235 port->tty->termios->c_lflag = 0; 242 /* Default to echo off and other sane device settings */
236 port->tty->termios->c_lflag &= ~(ISIG | ICANON | ECHO | IEXTEN | XCASE); 243 tty->termios->c_lflag = 0;
237 port->tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF; 244 tty->termios->c_lflag &= ~(ISIG | ICANON | ECHO | IEXTEN |
238 port->tty->termios->c_oflag &= ~ONLCR; // do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) 245 XCASE);
239 246 tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF;
240 // allocate memory for transfer buffer 247 /* do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) */
248 tty->termios->c_oflag &= ~ONLCR;
249 }
250 /* allocate memory for transfer buffer */
241 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); 251 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
242 if (! transfer_buffer) { 252 if (!transfer_buffer)
243 return -ENOMEM; 253 return -ENOMEM;
244 } 254
245 255 /* allocate write_urb */
246 // allocate write_urb 256 if (!port->write_urb) {
247 if (!port->write_urb) { 257 dbg("%s - port %d Allocating port->write_urb",
248 dbg("%s - port %d Allocating port->write_urb", __func__, port->number); 258 __func__, port->number);
249 port->write_urb = usb_alloc_urb(0, GFP_KERNEL); 259 port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
250 if (!port->write_urb) { 260 if (!port->write_urb) {
251 dbg("%s - port %d usb_alloc_urb failed", __func__, port->number); 261 dbg("%s - port %d usb_alloc_urb failed",
262 __func__, port->number);
252 kfree(transfer_buffer); 263 kfree(transfer_buffer);
253 return -ENOMEM; 264 return -ENOMEM;
254 } 265 }
255 } 266 }
256 267
257 // allocate memory for write_urb transfer buffer 268 /* allocate memory for write_urb transfer buffer */
258 port->write_urb->transfer_buffer = kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL); 269 port->write_urb->transfer_buffer =
259 if (! port->write_urb->transfer_buffer) { 270 kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL);
271 if (!port->write_urb->transfer_buffer) {
260 kfree(transfer_buffer); 272 kfree(transfer_buffer);
261 usb_free_urb(port->write_urb); 273 usb_free_urb(port->write_urb);
262 port->write_urb = NULL; 274 port->write_urb = NULL;
263 return -ENOMEM; 275 return -ENOMEM;
264 } 276 }
265 277
266 // get hardware version 278 /* get hardware version */
267 result = usb_control_msg( port->serial->dev, 279 result = usb_control_msg(port->serial->dev,
268 usb_rcvctrlpipe(port->serial->dev, 0 ), 280 usb_rcvctrlpipe(port->serial->dev, 0),
269 SUSBCRequest_GetMisc, 281 SUSBCRequest_GetMisc,
270 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN, 282 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN,
271 SUSBCR_MSC_GetHWVersion, 283 SUSBCR_MSC_GetHWVersion,
272 0, 284 0,
273 transfer_buffer, 285 transfer_buffer,
274 transfer_buffer_length, 286 transfer_buffer_length,
275 KOBIL_TIMEOUT 287 KOBIL_TIMEOUT
288 );
289 dbg("%s - port %d Send get_HW_version URB returns: %i",
290 __func__, port->number, result);
291 dbg("Harware version: %i.%i.%i",
292 transfer_buffer[0], transfer_buffer[1], transfer_buffer[2]);
293
294 /* get firmware version */
295 result = usb_control_msg(port->serial->dev,
296 usb_rcvctrlpipe(port->serial->dev, 0),
297 SUSBCRequest_GetMisc,
298 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN,
299 SUSBCR_MSC_GetFWVersion,
300 0,
301 transfer_buffer,
302 transfer_buffer_length,
303 KOBIL_TIMEOUT
304 );
305 dbg("%s - port %d Send get_FW_version URB returns: %i",
306 __func__, port->number, result);
307 dbg("Firmware version: %i.%i.%i",
308 transfer_buffer[0], transfer_buffer[1], transfer_buffer[2]);
309
310 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
311 priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
312 /* Setting Baudrate, Parity and Stopbits */
313 result = usb_control_msg(port->serial->dev,
314 usb_rcvctrlpipe(port->serial->dev, 0),
315 SUSBCRequest_SetBaudRateParityAndStopBits,
316 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
317 SUSBCR_SBR_9600 | SUSBCR_SPASB_EvenParity |
318 SUSBCR_SPASB_1StopBit,
319 0,
320 transfer_buffer,
321 0,
322 KOBIL_TIMEOUT
276 ); 323 );
277 dbg("%s - port %d Send get_HW_version URB returns: %i", __func__, port->number, result); 324 dbg("%s - port %d Send set_baudrate URB returns: %i",
278 dbg("Harware version: %i.%i.%i", transfer_buffer[0], transfer_buffer[1], transfer_buffer[2] ); 325 __func__, port->number, result);
279 326
280 // get firmware version 327 /* reset all queues */
281 result = usb_control_msg( port->serial->dev, 328 result = usb_control_msg(port->serial->dev,
282 usb_rcvctrlpipe(port->serial->dev, 0 ), 329 usb_rcvctrlpipe(port->serial->dev, 0),
283 SUSBCRequest_GetMisc, 330 SUSBCRequest_Misc,
284 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN, 331 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
285 SUSBCR_MSC_GetFWVersion, 332 SUSBCR_MSC_ResetAllQueues,
286 0, 333 0,
287 transfer_buffer, 334 transfer_buffer,
288 transfer_buffer_length, 335 0,
289 KOBIL_TIMEOUT 336 KOBIL_TIMEOUT
290 ); 337 );
291 dbg("%s - port %d Send get_FW_version URB returns: %i", __func__, port->number, result); 338 dbg("%s - port %d Send reset_all_queues URB returns: %i",
292 dbg("Firmware version: %i.%i.%i", transfer_buffer[0], transfer_buffer[1], transfer_buffer[2] ); 339 __func__, port->number, result);
293
294 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
295 // Setting Baudrate, Parity and Stopbits
296 result = usb_control_msg( port->serial->dev,
297 usb_rcvctrlpipe(port->serial->dev, 0 ),
298 SUSBCRequest_SetBaudRateParityAndStopBits,
299 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
300 SUSBCR_SBR_9600 | SUSBCR_SPASB_EvenParity | SUSBCR_SPASB_1StopBit,
301 0,
302 transfer_buffer,
303 0,
304 KOBIL_TIMEOUT
305 );
306 dbg("%s - port %d Send set_baudrate URB returns: %i", __func__, port->number, result);
307
308 // reset all queues
309 result = usb_control_msg( port->serial->dev,
310 usb_rcvctrlpipe(port->serial->dev, 0 ),
311 SUSBCRequest_Misc,
312 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
313 SUSBCR_MSC_ResetAllQueues,
314 0,
315 transfer_buffer,
316 0,
317 KOBIL_TIMEOUT
318 );
319 dbg("%s - port %d Send reset_all_queues URB returns: %i", __func__, port->number, result);
320 } 340 }
321 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || 341 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID ||
342 priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
322 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) { 343 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
323 // start reading (Adapter B 'cause PNP string) 344 /* start reading (Adapter B 'cause PNP string) */
324 result = usb_submit_urb( port->interrupt_in_urb, GFP_ATOMIC ); 345 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
325 dbg("%s - port %d Send read URB returns: %i", __func__, port->number, result); 346 dbg("%s - port %d Send read URB returns: %i",
347 __func__, port->number, result);
326 } 348 }
327 349
328 kfree(transfer_buffer); 350 kfree(transfer_buffer);
@@ -330,13 +352,14 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
330} 352}
331 353
332 354
333static void kobil_close (struct usb_serial_port *port, struct file *filp) 355static void kobil_close(struct tty_struct *tty,
356 struct usb_serial_port *port, struct file *filp)
334{ 357{
335 dbg("%s - port %d", __func__, port->number); 358 dbg("%s - port %d", __func__, port->number);
336 359
337 if (port->write_urb) { 360 if (port->write_urb) {
338 usb_kill_urb(port->write_urb); 361 usb_kill_urb(port->write_urb);
339 usb_free_urb( port->write_urb ); 362 usb_free_urb(port->write_urb);
340 port->write_urb = NULL; 363 port->write_urb = NULL;
341 } 364 }
342 usb_kill_urb(port->interrupt_in_urb); 365 usb_kill_urb(port->interrupt_in_urb);
@@ -350,7 +373,7 @@ static void kobil_read_int_callback(struct urb *urb)
350 struct tty_struct *tty; 373 struct tty_struct *tty;
351 unsigned char *data = urb->transfer_buffer; 374 unsigned char *data = urb->transfer_buffer;
352 int status = urb->status; 375 int status = urb->status;
353// char *dbg_data; 376/* char *dbg_data; */
354 377
355 dbg("%s - port %d", __func__, port->number); 378 dbg("%s - port %d", __func__, port->number);
356 379
@@ -360,51 +383,53 @@ static void kobil_read_int_callback(struct urb *urb)
360 return; 383 return;
361 } 384 }
362 385
363 tty = port->tty; 386 tty = port->port.tty;
364 if (urb->actual_length) { 387 if (urb->actual_length) {
365 388
366 // BEGIN DEBUG 389 /* BEGIN DEBUG */
367 /* 390 /*
368 dbg_data = kzalloc((3 * purb->actual_length + 10) * sizeof(char), GFP_KERNEL); 391 dbg_data = kzalloc((3 * purb->actual_length + 10)
392 * sizeof(char), GFP_KERNEL);
369 if (! dbg_data) { 393 if (! dbg_data) {
370 return; 394 return;
371 } 395 }
372 for (i = 0; i < purb->actual_length; i++) { 396 for (i = 0; i < purb->actual_length; i++) {
373 sprintf(dbg_data +3*i, "%02X ", data[i]); 397 sprintf(dbg_data +3*i, "%02X ", data[i]);
374 } 398 }
375 dbg(" <-- %s", dbg_data ); 399 dbg(" <-- %s", dbg_data);
376 kfree(dbg_data); 400 kfree(dbg_data);
377 */ 401 */
378 // END DEBUG 402 /* END DEBUG */
379 403
380 tty_buffer_request_room(tty, urb->actual_length); 404 tty_buffer_request_room(tty, urb->actual_length);
381 tty_insert_flip_string(tty, data, urb->actual_length); 405 tty_insert_flip_string(tty, data, urb->actual_length);
382 tty_flip_buffer_push(tty); 406 tty_flip_buffer_push(tty);
383 } 407 }
384 408 /* someone sets the dev to 0 if the close method has been called */
385 // someone sets the dev to 0 if the close method has been called
386 port->interrupt_in_urb->dev = port->serial->dev; 409 port->interrupt_in_urb->dev = port->serial->dev;
387 410
388 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 411 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
389 dbg("%s - port %d Send read URB returns: %i", __func__, port->number, result); 412 dbg("%s - port %d Send read URB returns: %i",
413 __func__, port->number, result);
390} 414}
391 415
392 416
393static void kobil_write_callback( struct urb *purb ) 417static void kobil_write_callback(struct urb *purb)
394{ 418{
395} 419}
396 420
397 421
398static int kobil_write (struct usb_serial_port *port, 422static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
399 const unsigned char *buf, int count) 423 const unsigned char *buf, int count)
400{ 424{
401 int length = 0; 425 int length = 0;
402 int result = 0; 426 int result = 0;
403 int todo = 0; 427 int todo = 0;
404 struct kobil_private * priv; 428 struct kobil_private *priv;
405 429
406 if (count == 0) { 430 if (count == 0) {
407 dbg("%s - port %d write request of 0 bytes", __func__, port->number); 431 dbg("%s - port %d write request of 0 bytes",
432 __func__, port->number);
408 return 0; 433 return 0;
409 } 434 }
410 435
@@ -415,106 +440,113 @@ static int kobil_write (struct usb_serial_port *port,
415 return -ENOMEM; 440 return -ENOMEM;
416 } 441 }
417 442
418 // Copy data to buffer 443 /* Copy data to buffer */
419 memcpy (priv->buf + priv->filled, buf, count); 444 memcpy(priv->buf + priv->filled, buf, count);
420 445 usb_serial_debug_data(debug, &port->dev, __func__, count,
421 usb_serial_debug_data(debug, &port->dev, __func__, count, priv->buf + priv->filled); 446 priv->buf + priv->filled);
422
423 priv->filled = priv->filled + count; 447 priv->filled = priv->filled + count;
424 448
425 449 /* only send complete block. TWIN, KAAN SIM and adapter K
426 // only send complete block. TWIN, KAAN SIM and adapter K use the same protocol. 450 use the same protocol. */
427 if ( ((priv->device_type != KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 2) && (priv->filled >= (priv->buf[1] + 3))) || 451 if (((priv->device_type != KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 2) && (priv->filled >= (priv->buf[1] + 3))) ||
428 ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4))) ) { 452 ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4)))) {
429 453 /* stop reading (except TWIN and KAAN SIM) */
430 // stop reading (except TWIN and KAAN SIM) 454 if ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID)
431 if ( (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) ) 455 || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID))
432 usb_kill_urb(port->interrupt_in_urb); 456 usb_kill_urb(port->interrupt_in_urb);
433 457
434 todo = priv->filled - priv->cur_pos; 458 todo = priv->filled - priv->cur_pos;
435 459
436 while(todo > 0) { 460 while (todo > 0) {
437 // max 8 byte in one urb (endpoint size) 461 /* max 8 byte in one urb (endpoint size) */
438 length = (todo < 8) ? todo : 8; 462 length = (todo < 8) ? todo : 8;
439 // copy data to transfer buffer 463 /* copy data to transfer buffer */
440 memcpy(port->write_urb->transfer_buffer, priv->buf + priv->cur_pos, length ); 464 memcpy(port->write_urb->transfer_buffer,
441 usb_fill_int_urb( port->write_urb, 465 priv->buf + priv->cur_pos, length);
442 port->serial->dev, 466 usb_fill_int_urb(port->write_urb,
443 usb_sndintpipe(port->serial->dev, priv->write_int_endpoint_address), 467 port->serial->dev,
444 port->write_urb->transfer_buffer, 468 usb_sndintpipe(port->serial->dev,
445 length, 469 priv->write_int_endpoint_address),
446 kobil_write_callback, 470 port->write_urb->transfer_buffer,
447 port, 471 length,
448 8 472 kobil_write_callback,
449 ); 473 port,
474 8
475 );
450 476
451 priv->cur_pos = priv->cur_pos + length; 477 priv->cur_pos = priv->cur_pos + length;
452 result = usb_submit_urb( port->write_urb, GFP_NOIO ); 478 result = usb_submit_urb(port->write_urb, GFP_NOIO);
453 dbg("%s - port %d Send write URB returns: %i", __func__, port->number, result); 479 dbg("%s - port %d Send write URB returns: %i",
480 __func__, port->number, result);
454 todo = priv->filled - priv->cur_pos; 481 todo = priv->filled - priv->cur_pos;
455 482
456 if (todo > 0) { 483 if (todo > 0)
457 msleep(24); 484 msleep(24);
458 } 485 }
459 486
460 } // end while
461
462 priv->filled = 0; 487 priv->filled = 0;
463 priv->cur_pos = 0; 488 priv->cur_pos = 0;
464 489
465 // someone sets the dev to 0 if the close method has been called 490 /* someone sets the dev to 0 if the close method
491 has been called */
466 port->interrupt_in_urb->dev = port->serial->dev; 492 port->interrupt_in_urb->dev = port->serial->dev;
467 493
468 // start reading (except TWIN and KAAN SIM) 494 /* start reading (except TWIN and KAAN SIM) */
469 if ( (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) ) { 495 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
470 // someone sets the dev to 0 if the close method has been called 496 priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
497 /* someone sets the dev to 0 if the close method has
498 been called */
471 port->interrupt_in_urb->dev = port->serial->dev; 499 port->interrupt_in_urb->dev = port->serial->dev;
472 500
473 result = usb_submit_urb( port->interrupt_in_urb, GFP_NOIO ); 501 result = usb_submit_urb(port->interrupt_in_urb,
474 dbg("%s - port %d Send read URB returns: %i", __func__, port->number, result); 502 GFP_NOIO);
503 dbg("%s - port %d Send read URB returns: %i",
504 __func__, port->number, result);
475 } 505 }
476 } 506 }
477 return count; 507 return count;
478} 508}
479 509
480 510
481static int kobil_write_room (struct usb_serial_port *port) 511static int kobil_write_room(struct tty_struct *tty)
482{ 512{
483 //dbg("%s - port %d", __func__, port->number); 513 /* dbg("%s - port %d", __func__, port->number); */
514 /* FIXME */
484 return 8; 515 return 8;
485} 516}
486 517
487 518
488static int kobil_tiocmget(struct usb_serial_port *port, struct file *file) 519static int kobil_tiocmget(struct tty_struct *tty, struct file *file)
489{ 520{
490 struct kobil_private * priv; 521 struct usb_serial_port *port = tty->driver_data;
522 struct kobil_private *priv;
491 int result; 523 int result;
492 unsigned char *transfer_buffer; 524 unsigned char *transfer_buffer;
493 int transfer_buffer_length = 8; 525 int transfer_buffer_length = 8;
494 526
495 priv = usb_get_serial_port_data(port); 527 priv = usb_get_serial_port_data(port);
496 if ((priv->device_type == KOBIL_USBTWIN_PRODUCT_ID) || (priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)) { 528 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID
497 // This device doesn't support ioctl calls 529 || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
530 /* This device doesn't support ioctl calls */
498 return -EINVAL; 531 return -EINVAL;
499 } 532 }
500 533
501 // allocate memory for transfer buffer 534 /* allocate memory for transfer buffer */
502 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); 535 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
503 if (!transfer_buffer) { 536 if (!transfer_buffer)
504 return -ENOMEM; 537 return -ENOMEM;
505 }
506 538
507 result = usb_control_msg( port->serial->dev, 539 result = usb_control_msg(port->serial->dev,
508 usb_rcvctrlpipe(port->serial->dev, 0 ), 540 usb_rcvctrlpipe(port->serial->dev, 0),
509 SUSBCRequest_GetStatusLineState, 541 SUSBCRequest_GetStatusLineState,
510 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN, 542 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN,
511 0, 543 0,
512 0, 544 0,
513 transfer_buffer, 545 transfer_buffer,
514 transfer_buffer_length, 546 transfer_buffer_length,
515 KOBIL_TIMEOUT); 547 KOBIL_TIMEOUT);
516 548
517 dbg("%s - port %d Send get_status_line_state URB returns: %i. Statusline: %02x", 549 dbg("%s - port %d Send get_status_line_state URB returns: %i. Statusline: %02x",
518 __func__, port->number, result, transfer_buffer[0]); 550 __func__, port->number, result, transfer_buffer[0]);
519 551
520 result = 0; 552 result = 0;
@@ -524,10 +556,11 @@ static int kobil_tiocmget(struct usb_serial_port *port, struct file *file)
524 return result; 556 return result;
525} 557}
526 558
527static int kobil_tiocmset(struct usb_serial_port *port, struct file *file, 559static int kobil_tiocmset(struct tty_struct *tty, struct file *file,
528 unsigned int set, unsigned int clear) 560 unsigned int set, unsigned int clear)
529{ 561{
530 struct kobil_private * priv; 562 struct usb_serial_port *port = tty->driver_data;
563 struct kobil_private *priv;
531 int result; 564 int result;
532 int dtr = 0; 565 int dtr = 0;
533 int rts = 0; 566 int rts = 0;
@@ -536,16 +569,16 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
536 569
537 /* FIXME: locking ? */ 570 /* FIXME: locking ? */
538 priv = usb_get_serial_port_data(port); 571 priv = usb_get_serial_port_data(port);
539 if ((priv->device_type == KOBIL_USBTWIN_PRODUCT_ID) || (priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)) { 572 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID
540 // This device doesn't support ioctl calls 573 || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
574 /* This device doesn't support ioctl calls */
541 return -EINVAL; 575 return -EINVAL;
542 } 576 }
543 577
544 // allocate memory for transfer buffer 578 /* allocate memory for transfer buffer */
545 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); 579 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
546 if (! transfer_buffer) { 580 if (!transfer_buffer)
547 return -ENOMEM; 581 return -ENOMEM;
548 }
549 582
550 if (set & TIOCM_RTS) 583 if (set & TIOCM_RTS)
551 rts = 1; 584 rts = 1;
@@ -558,66 +591,77 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
558 591
559 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) { 592 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) {
560 if (dtr != 0) 593 if (dtr != 0)
561 dbg("%s - port %d Setting DTR", __func__, port->number); 594 dbg("%s - port %d Setting DTR",
595 __func__, port->number);
562 else 596 else
563 dbg("%s - port %d Clearing DTR", __func__, port->number); 597 dbg("%s - port %d Clearing DTR",
564 result = usb_control_msg( port->serial->dev, 598 __func__, port->number);
565 usb_rcvctrlpipe(port->serial->dev, 0 ), 599 result = usb_control_msg(port->serial->dev,
566 SUSBCRequest_SetStatusLinesOrQueues, 600 usb_rcvctrlpipe(port->serial->dev, 0),
567 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, 601 SUSBCRequest_SetStatusLinesOrQueues,
568 ((dtr != 0) ? SUSBCR_SSL_SETDTR : SUSBCR_SSL_CLRDTR), 602 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
569 0, 603 ((dtr != 0) ? SUSBCR_SSL_SETDTR : SUSBCR_SSL_CLRDTR),
570 transfer_buffer, 604 0,
571 0, 605 transfer_buffer,
572 KOBIL_TIMEOUT); 606 0,
607 KOBIL_TIMEOUT);
573 } else { 608 } else {
574 if (rts != 0) 609 if (rts != 0)
575 dbg("%s - port %d Setting RTS", __func__, port->number); 610 dbg("%s - port %d Setting RTS",
611 __func__, port->number);
576 else 612 else
577 dbg("%s - port %d Clearing RTS", __func__, port->number); 613 dbg("%s - port %d Clearing RTS",
578 result = usb_control_msg( port->serial->dev, 614 __func__, port->number);
579 usb_rcvctrlpipe(port->serial->dev, 0 ), 615 result = usb_control_msg(port->serial->dev,
580 SUSBCRequest_SetStatusLinesOrQueues, 616 usb_rcvctrlpipe(port->serial->dev, 0),
581 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, 617 SUSBCRequest_SetStatusLinesOrQueues,
582 ((rts != 0) ? SUSBCR_SSL_SETRTS : SUSBCR_SSL_CLRRTS), 618 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
583 0, 619 ((rts != 0) ? SUSBCR_SSL_SETRTS : SUSBCR_SSL_CLRRTS),
584 transfer_buffer, 620 0,
585 0, 621 transfer_buffer,
586 KOBIL_TIMEOUT); 622 0,
623 KOBIL_TIMEOUT);
587 } 624 }
588 dbg("%s - port %d Send set_status_line URB returns: %i", __func__, port->number, result); 625 dbg("%s - port %d Send set_status_line URB returns: %i",
626 __func__, port->number, result);
589 kfree(transfer_buffer); 627 kfree(transfer_buffer);
590 return (result < 0) ? result : 0; 628 return (result < 0) ? result : 0;
591} 629}
592 630
593static void kobil_set_termios(struct usb_serial_port *port, struct ktermios *old) 631static void kobil_set_termios(struct tty_struct *tty,
632 struct usb_serial_port *port, struct ktermios *old)
594{ 633{
595 struct kobil_private * priv; 634 struct kobil_private *priv;
596 int result; 635 int result;
597 unsigned short urb_val = 0; 636 unsigned short urb_val = 0;
598 int c_cflag = port->tty->termios->c_cflag; 637 int c_cflag = tty->termios->c_cflag;
599 speed_t speed; 638 speed_t speed;
600 void * settings; 639 void *settings;
601 640
602 priv = usb_get_serial_port_data(port); 641 priv = usb_get_serial_port_data(port);
603 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) 642 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID ||
604 // This device doesn't support ioctl calls 643 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
644 /* This device doesn't support ioctl calls */
645 *tty->termios = *old;
605 return; 646 return;
647 }
606 648
607 switch (speed = tty_get_baud_rate(port->tty)) { 649 speed = tty_get_baud_rate(tty);
608 case 1200: 650 switch (speed) {
609 urb_val = SUSBCR_SBR_1200; 651 case 1200:
610 break; 652 urb_val = SUSBCR_SBR_1200;
611 default: 653 break;
612 speed = 9600; 654 default:
613 case 9600: 655 speed = 9600;
614 urb_val = SUSBCR_SBR_9600; 656 case 9600:
615 break; 657 urb_val = SUSBCR_SBR_9600;
658 break;
616 } 659 }
617 urb_val |= (c_cflag & CSTOPB) ? SUSBCR_SPASB_2StopBits : SUSBCR_SPASB_1StopBit; 660 urb_val |= (c_cflag & CSTOPB) ? SUSBCR_SPASB_2StopBits :
661 SUSBCR_SPASB_1StopBit;
618 662
619 settings = kzalloc(50, GFP_KERNEL); 663 settings = kzalloc(50, GFP_KERNEL);
620 if (! settings) 664 if (!settings)
621 return; 665 return;
622 666
623 sprintf(settings, "%d ", speed); 667 sprintf(settings, "%d ", speed);
@@ -634,66 +678,69 @@ static void kobil_set_termios(struct usb_serial_port *port, struct ktermios *old
634 urb_val |= SUSBCR_SPASB_NoParity; 678 urb_val |= SUSBCR_SPASB_NoParity;
635 strcat(settings, "No Parity"); 679 strcat(settings, "No Parity");
636 } 680 }
637 port->tty->termios->c_cflag &= ~CMSPAR; 681 tty->termios->c_cflag &= ~CMSPAR;
638 tty_encode_baud_rate(port->tty, speed, speed); 682 tty_encode_baud_rate(tty, speed, speed);
639 683
640 result = usb_control_msg( port->serial->dev, 684 result = usb_control_msg(port->serial->dev,
641 usb_rcvctrlpipe(port->serial->dev, 0 ), 685 usb_rcvctrlpipe(port->serial->dev, 0),
642 SUSBCRequest_SetBaudRateParityAndStopBits, 686 SUSBCRequest_SetBaudRateParityAndStopBits,
643 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, 687 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
644 urb_val, 688 urb_val,
645 0, 689 0,
646 settings, 690 settings,
647 0, 691 0,
648 KOBIL_TIMEOUT 692 KOBIL_TIMEOUT
649 ); 693 );
650 kfree(settings); 694 kfree(settings);
651} 695}
652 696
653static int kobil_ioctl(struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 697static int kobil_ioctl(struct tty_struct *tty, struct file *file,
698 unsigned int cmd, unsigned long arg)
654{ 699{
655 struct kobil_private * priv = usb_get_serial_port_data(port); 700 struct usb_serial_port *port = tty->driver_data;
701 struct kobil_private *priv = usb_get_serial_port_data(port);
656 unsigned char *transfer_buffer; 702 unsigned char *transfer_buffer;
657 int transfer_buffer_length = 8; 703 int transfer_buffer_length = 8;
658 int result; 704 int result;
659 705
660 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) 706 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID ||
661 // This device doesn't support ioctl calls 707 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)
662 return 0; 708 /* This device doesn't support ioctl calls */
709 return -ENOIOCTLCMD;
663 710
664 switch (cmd) { 711 switch (cmd) {
665 case TCFLSH: // 0x540B 712 case TCFLSH:
666 transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL); 713 transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL);
667 if (! transfer_buffer) 714 if (!transfer_buffer)
668 return -ENOBUFS; 715 return -ENOBUFS;
669 716
670 result = usb_control_msg( port->serial->dev, 717 result = usb_control_msg(port->serial->dev,
671 usb_rcvctrlpipe(port->serial->dev, 0 ), 718 usb_rcvctrlpipe(port->serial->dev, 0),
672 SUSBCRequest_Misc, 719 SUSBCRequest_Misc,
673 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, 720 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
674 SUSBCR_MSC_ResetAllQueues, 721 SUSBCR_MSC_ResetAllQueues,
675 0, 722 0,
676 NULL,//transfer_buffer, 723 NULL, /* transfer_buffer, */
677 0, 724 0,
678 KOBIL_TIMEOUT 725 KOBIL_TIMEOUT
679 ); 726 );
680 727
681 dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __func__, port->number, result); 728 dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __func__, port->number, result);
682 kfree(transfer_buffer); 729 kfree(transfer_buffer);
683 return (result < 0) ? -EFAULT : 0; 730 return (result < 0) ? -EIO: 0;
684 default: 731 default:
685 return -ENOIOCTLCMD; 732 return -ENOIOCTLCMD;
686 } 733 }
687} 734}
688 735
689static int __init kobil_init (void) 736static int __init kobil_init(void)
690{ 737{
691 int retval; 738 int retval;
692 retval = usb_serial_register(&kobil_device); 739 retval = usb_serial_register(&kobil_device);
693 if (retval) 740 if (retval)
694 goto failed_usb_serial_register; 741 goto failed_usb_serial_register;
695 retval = usb_register(&kobil_driver); 742 retval = usb_register(&kobil_driver);
696 if (retval) 743 if (retval)
697 goto failed_usb_register; 744 goto failed_usb_register;
698 745
699 info(DRIVER_VERSION " " DRIVER_AUTHOR); 746 info(DRIVER_VERSION " " DRIVER_AUTHOR);
@@ -707,18 +754,18 @@ failed_usb_serial_register:
707} 754}
708 755
709 756
710static void __exit kobil_exit (void) 757static void __exit kobil_exit(void)
711{ 758{
712 usb_deregister (&kobil_driver); 759 usb_deregister(&kobil_driver);
713 usb_serial_deregister (&kobil_device); 760 usb_serial_deregister(&kobil_device);
714} 761}
715 762
716module_init(kobil_init); 763module_init(kobil_init);
717module_exit(kobil_exit); 764module_exit(kobil_exit);
718 765
719MODULE_AUTHOR( DRIVER_AUTHOR ); 766MODULE_AUTHOR(DRIVER_AUTHOR);
720MODULE_DESCRIPTION( DRIVER_DESC ); 767MODULE_DESCRIPTION(DRIVER_DESC);
721MODULE_LICENSE( "GPL" ); 768MODULE_LICENSE("GPL");
722 769
723module_param(debug, bool, S_IRUGO | S_IWUSR); 770module_param(debug, bool, S_IRUGO | S_IWUSR);
724MODULE_PARM_DESC(debug, "Debug enabled or not"); 771MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 5fc2cef30e39..0ded8bd6ec85 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -33,10 +33,11 @@
33 * - Fixed an endianess problem with the baudrate selection for PowerPC. 33 * - Fixed an endianess problem with the baudrate selection for PowerPC.
34 * 34 *
35 * 06-Dec-2001 Martin Hamilton <martinh@gnu.org> 35 * 06-Dec-2001 Martin Hamilton <martinh@gnu.org>
36 * Added support for the Belkin F5U109 DB9 adaptor 36 * - Added support for the Belkin F5U109 DB9 adaptor
37 * 37 *
38 * 30-May-2001 Greg Kroah-Hartman 38 * 30-May-2001 Greg Kroah-Hartman
39 * switched from using spinlock to a semaphore, which fixes lots of problems. 39 * - switched from using spinlock to a semaphore, which fixes lots of
40 * problems.
40 * 41 *
41 * 04-May-2001 Stelian Pop 42 * 04-May-2001 Stelian Pop
42 * - Set the maximum bulk output size for Sitecom U232-P25 model to 16 bytes 43 * - Set the maximum bulk output size for Sitecom U232-P25 model to 16 bytes
@@ -49,7 +50,7 @@
49 * 08-Apr-2001 gb 50 * 08-Apr-2001 gb
50 * - Identify version on module load. 51 * - Identify version on module load.
51 * 52 *
52 * 06-Jan-2001 Cornel Ciocirlan 53 * 06-Jan-2001 Cornel Ciocirlan
53 * - Added support for Sitecom U232-P25 model (Product Id 0x0230) 54 * - Added support for Sitecom U232-P25 model (Product Id 0x0230)
54 * - Added support for D-Link DU-H3SP USB BAY (Product Id 0x0200) 55 * - Added support for D-Link DU-H3SP USB BAY (Product Id 0x0200)
55 * 56 *
@@ -59,8 +60,8 @@
59 * (lots of things will change if/when the usb-serial core changes to 60 * (lots of things will change if/when the usb-serial core changes to
60 * handle these issues. 61 * handle these issues.
61 * 62 *
62 * 27-Nov-2000 Wolfgang Grandegger 63 * 27-Nov-2000 Wolfgang Grandegge
63 * A version for kernel 2.4.0-test10 released to the Linux community 64 * A version for kernel 2.4.0-test10 released to the Linux community
64 * (via linux-usb-devel). 65 * (via linux-usb-devel).
65 */ 66 */
66 67
@@ -73,7 +74,7 @@
73#include <linux/tty_flip.h> 74#include <linux/tty_flip.h>
74#include <linux/module.h> 75#include <linux/module.h>
75#include <linux/spinlock.h> 76#include <linux/spinlock.h>
76#include <asm/uaccess.h> 77#include <linux/uaccess.h>
77#include <linux/usb.h> 78#include <linux/usb.h>
78#include <linux/usb/serial.h> 79#include <linux/usb/serial.h>
79#include "mct_u232.h" 80#include "mct_u232.h"
@@ -90,28 +91,21 @@ static int debug;
90/* 91/*
91 * Function prototypes 92 * Function prototypes
92 */ 93 */
93static int mct_u232_startup (struct usb_serial *serial); 94static int mct_u232_startup(struct usb_serial *serial);
94static void mct_u232_shutdown (struct usb_serial *serial); 95static void mct_u232_shutdown(struct usb_serial *serial);
95static int mct_u232_open (struct usb_serial_port *port, 96static int mct_u232_open(struct tty_struct *tty,
96 struct file *filp); 97 struct usb_serial_port *port, struct file *filp);
97static void mct_u232_close (struct usb_serial_port *port, 98static void mct_u232_close(struct tty_struct *tty,
98 struct file *filp); 99 struct usb_serial_port *port, struct file *filp);
99static void mct_u232_read_int_callback (struct urb *urb); 100static void mct_u232_read_int_callback(struct urb *urb);
100static void mct_u232_set_termios (struct usb_serial_port *port, 101static void mct_u232_set_termios(struct tty_struct *tty,
101 struct ktermios * old); 102 struct usb_serial_port *port, struct ktermios *old);
102static int mct_u232_ioctl (struct usb_serial_port *port, 103static void mct_u232_break_ctl(struct tty_struct *tty, int break_state);
103 struct file * file, 104static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file);
104 unsigned int cmd, 105static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
105 unsigned long arg); 106 unsigned int set, unsigned int clear);
106static void mct_u232_break_ctl (struct usb_serial_port *port, 107static void mct_u232_throttle(struct tty_struct *tty);
107 int break_state ); 108static void mct_u232_unthrottle(struct tty_struct *tty);
108static int mct_u232_tiocmget (struct usb_serial_port *port,
109 struct file *file);
110static int mct_u232_tiocmset (struct usb_serial_port *port,
111 struct file *file, unsigned int set,
112 unsigned int clear);
113static void mct_u232_throttle (struct usb_serial_port *port);
114static void mct_u232_unthrottle (struct usb_serial_port *port);
115 109
116 110
117/* 111/*
@@ -125,7 +119,7 @@ static struct usb_device_id id_table_combined [] = {
125 { } /* Terminating entry */ 119 { } /* Terminating entry */
126}; 120};
127 121
128MODULE_DEVICE_TABLE (usb, id_table_combined); 122MODULE_DEVICE_TABLE(usb, id_table_combined);
129 123
130static struct usb_driver mct_u232_driver = { 124static struct usb_driver mct_u232_driver = {
131 .name = "mct_u232", 125 .name = "mct_u232",
@@ -149,7 +143,6 @@ static struct usb_serial_driver mct_u232_device = {
149 .throttle = mct_u232_throttle, 143 .throttle = mct_u232_throttle,
150 .unthrottle = mct_u232_unthrottle, 144 .unthrottle = mct_u232_unthrottle,
151 .read_int_callback = mct_u232_read_int_callback, 145 .read_int_callback = mct_u232_read_int_callback,
152 .ioctl = mct_u232_ioctl,
153 .set_termios = mct_u232_set_termios, 146 .set_termios = mct_u232_set_termios,
154 .break_ctl = mct_u232_break_ctl, 147 .break_ctl = mct_u232_break_ctl,
155 .tiocmget = mct_u232_tiocmget, 148 .tiocmget = mct_u232_tiocmget,
@@ -180,23 +173,34 @@ struct mct_u232_private {
180 * Later day 2.6.0-test kernels have new baud rates like B230400 which 173 * Later day 2.6.0-test kernels have new baud rates like B230400 which
181 * we do not know how to support. We ignore them for the moment. 174 * we do not know how to support. We ignore them for the moment.
182 */ 175 */
183static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value, speed_t *result) 176static int mct_u232_calculate_baud_rate(struct usb_serial *serial,
177 speed_t value, speed_t *result)
184{ 178{
185 *result = value; 179 *result = value;
186 180
187 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID 181 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID
188 || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) { 182 || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) {
189 switch (value) { 183 switch (value) {
190 case 300: return 0x01; 184 case 300:
191 case 600: return 0x02; /* this one not tested */ 185 return 0x01;
192 case 1200: return 0x03; 186 case 600:
193 case 2400: return 0x04; 187 return 0x02; /* this one not tested */
194 case 4800: return 0x06; 188 case 1200:
195 case 9600: return 0x08; 189 return 0x03;
196 case 19200: return 0x09; 190 case 2400:
197 case 38400: return 0x0a; 191 return 0x04;
198 case 57600: return 0x0b; 192 case 4800:
199 case 115200: return 0x0c; 193 return 0x06;
194 case 9600:
195 return 0x08;
196 case 19200:
197 return 0x09;
198 case 38400:
199 return 0x0a;
200 case 57600:
201 return 0x0b;
202 case 115200:
203 return 0x0c;
200 default: 204 default:
201 *result = 9600; 205 *result = 9600;
202 return 0x08; 206 return 0x08;
@@ -224,26 +228,27 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
224 } 228 }
225} 229}
226 230
227static int mct_u232_set_baud_rate(struct usb_serial *serial, struct usb_serial_port *port, 231static int mct_u232_set_baud_rate(struct tty_struct *tty,
228 speed_t value) 232 struct usb_serial *serial, struct usb_serial_port *port, speed_t value)
229{ 233{
230 __le32 divisor; 234 __le32 divisor;
231 int rc; 235 int rc;
232 unsigned char zero_byte = 0; 236 unsigned char zero_byte = 0;
233 unsigned char cts_enable_byte = 0; 237 unsigned char cts_enable_byte = 0;
234 speed_t speed; 238 speed_t speed;
235 239
236 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value, &speed)); 240 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value,
237 241 &speed));
238 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 242
239 MCT_U232_SET_BAUD_RATE_REQUEST, 243 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
240 MCT_U232_SET_REQUEST_TYPE, 244 MCT_U232_SET_BAUD_RATE_REQUEST,
241 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE, 245 MCT_U232_SET_REQUEST_TYPE,
242 WDR_TIMEOUT); 246 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE,
247 WDR_TIMEOUT);
243 if (rc < 0) /*FIXME: What value speed results */ 248 if (rc < 0) /*FIXME: What value speed results */
244 err("Set BAUD RATE %d failed (error = %d)", value, rc); 249 err("Set BAUD RATE %d failed (error = %d)", value, rc);
245 else 250 else
246 tty_encode_baud_rate(port->tty, speed, speed); 251 tty_encode_baud_rate(tty, speed, speed);
247 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor); 252 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor);
248 253
249 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which 254 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
@@ -258,55 +263,55 @@ static int mct_u232_set_baud_rate(struct usb_serial *serial, struct usb_serial_p
258 whether data will be transmitted to a device which is not asserting 263 whether data will be transmitted to a device which is not asserting
259 the 'CTS' signal. If the second message's data byte is zero, data 264 the 'CTS' signal. If the second message's data byte is zero, data
260 will be transmitted even if 'CTS' is not asserted (i.e. no hardware 265 will be transmitted even if 'CTS' is not asserted (i.e. no hardware
261 flow control). if the second message's data byte is nonzero (a value 266 flow control). if the second message's data byte is nonzero (a
262 of 1 is used by this driver), data will not be transmitted to a device 267 value of 1 is used by this driver), data will not be transmitted to
263 which is not asserting 'CTS'. 268 a device which is not asserting 'CTS'.
264 */ 269 */
265 270
266 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 271 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
267 MCT_U232_SET_UNKNOWN1_REQUEST, 272 MCT_U232_SET_UNKNOWN1_REQUEST,
268 MCT_U232_SET_REQUEST_TYPE, 273 MCT_U232_SET_REQUEST_TYPE,
269 0, 0, &zero_byte, MCT_U232_SET_UNKNOWN1_SIZE, 274 0, 0, &zero_byte, MCT_U232_SET_UNKNOWN1_SIZE,
270 WDR_TIMEOUT); 275 WDR_TIMEOUT);
271 if (rc < 0) 276 if (rc < 0)
272 err("Sending USB device request code %d failed (error = %d)", 277 err("Sending USB device request code %d failed (error = %d)",
273 MCT_U232_SET_UNKNOWN1_REQUEST, rc); 278 MCT_U232_SET_UNKNOWN1_REQUEST, rc);
274 279
275 if (port && C_CRTSCTS(port->tty)) { 280 if (port && C_CRTSCTS(tty))
276 cts_enable_byte = 1; 281 cts_enable_byte = 1;
277 }
278 282
279 dbg("set_baud_rate: send second control message, data = %02X", cts_enable_byte); 283 dbg("set_baud_rate: send second control message, data = %02X",
284 cts_enable_byte);
280 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 285 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
281 MCT_U232_SET_CTS_REQUEST, 286 MCT_U232_SET_CTS_REQUEST,
282 MCT_U232_SET_REQUEST_TYPE, 287 MCT_U232_SET_REQUEST_TYPE,
283 0, 0, &cts_enable_byte, MCT_U232_SET_CTS_SIZE, 288 0, 0, &cts_enable_byte, MCT_U232_SET_CTS_SIZE,
284 WDR_TIMEOUT); 289 WDR_TIMEOUT);
285 if (rc < 0) 290 if (rc < 0)
286 err("Sending USB device request code %d failed (error = %d)", 291 err("Sending USB device request code %d failed (error = %d)",
287 MCT_U232_SET_CTS_REQUEST, rc); 292 MCT_U232_SET_CTS_REQUEST, rc);
288 293
289 return rc; 294 return rc;
290} /* mct_u232_set_baud_rate */ 295} /* mct_u232_set_baud_rate */
291 296
292static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr) 297static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr)
293{ 298{
294 int rc; 299 int rc;
295 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 300 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
296 MCT_U232_SET_LINE_CTRL_REQUEST, 301 MCT_U232_SET_LINE_CTRL_REQUEST,
297 MCT_U232_SET_REQUEST_TYPE, 302 MCT_U232_SET_REQUEST_TYPE,
298 0, 0, &lcr, MCT_U232_SET_LINE_CTRL_SIZE, 303 0, 0, &lcr, MCT_U232_SET_LINE_CTRL_SIZE,
299 WDR_TIMEOUT); 304 WDR_TIMEOUT);
300 if (rc < 0) 305 if (rc < 0)
301 err("Set LINE CTRL 0x%x failed (error = %d)", lcr, rc); 306 err("Set LINE CTRL 0x%x failed (error = %d)", lcr, rc);
302 dbg("set_line_ctrl: 0x%x", lcr); 307 dbg("set_line_ctrl: 0x%x", lcr);
303 return rc; 308 return rc;
304} /* mct_u232_set_line_ctrl */ 309} /* mct_u232_set_line_ctrl */
305 310
306static int mct_u232_set_modem_ctrl(struct usb_serial *serial, 311static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
307 unsigned int control_state) 312 unsigned int control_state)
308{ 313{
309 int rc; 314 int rc;
310 unsigned char mcr = MCT_U232_MCR_NONE; 315 unsigned char mcr = MCT_U232_MCR_NONE;
311 316
312 if (control_state & TIOCM_DTR) 317 if (control_state & TIOCM_DTR)
@@ -314,37 +319,39 @@ static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
314 if (control_state & TIOCM_RTS) 319 if (control_state & TIOCM_RTS)
315 mcr |= MCT_U232_MCR_RTS; 320 mcr |= MCT_U232_MCR_RTS;
316 321
317 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 322 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
318 MCT_U232_SET_MODEM_CTRL_REQUEST, 323 MCT_U232_SET_MODEM_CTRL_REQUEST,
319 MCT_U232_SET_REQUEST_TYPE, 324 MCT_U232_SET_REQUEST_TYPE,
320 0, 0, &mcr, MCT_U232_SET_MODEM_CTRL_SIZE, 325 0, 0, &mcr, MCT_U232_SET_MODEM_CTRL_SIZE,
321 WDR_TIMEOUT); 326 WDR_TIMEOUT);
322 if (rc < 0) 327 if (rc < 0)
323 err("Set MODEM CTRL 0x%x failed (error = %d)", mcr, rc); 328 err("Set MODEM CTRL 0x%x failed (error = %d)", mcr, rc);
324 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr); 329 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr);
325 330
326 return rc; 331 return rc;
327} /* mct_u232_set_modem_ctrl */ 332} /* mct_u232_set_modem_ctrl */
328 333
329static int mct_u232_get_modem_stat(struct usb_serial *serial, unsigned char *msr) 334static int mct_u232_get_modem_stat(struct usb_serial *serial,
335 unsigned char *msr)
330{ 336{
331 int rc; 337 int rc;
332 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 338 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
333 MCT_U232_GET_MODEM_STAT_REQUEST, 339 MCT_U232_GET_MODEM_STAT_REQUEST,
334 MCT_U232_GET_REQUEST_TYPE, 340 MCT_U232_GET_REQUEST_TYPE,
335 0, 0, msr, MCT_U232_GET_MODEM_STAT_SIZE, 341 0, 0, msr, MCT_U232_GET_MODEM_STAT_SIZE,
336 WDR_TIMEOUT); 342 WDR_TIMEOUT);
337 if (rc < 0) { 343 if (rc < 0) {
338 err("Get MODEM STATus failed (error = %d)", rc); 344 err("Get MODEM STATus failed (error = %d)", rc);
339 *msr = 0; 345 *msr = 0;
340 } 346 }
341 dbg("get_modem_stat: 0x%x", *msr); 347 dbg("get_modem_stat: 0x%x", *msr);
342 return rc; 348 return rc;
343} /* mct_u232_get_modem_stat */ 349} /* mct_u232_get_modem_stat */
344 350
345static void mct_u232_msr_to_state(unsigned int *control_state, unsigned char msr) 351static void mct_u232_msr_to_state(unsigned int *control_state,
352 unsigned char msr)
346{ 353{
347 /* Translate Control Line states */ 354 /* Translate Control Line states */
348 if (msr & MCT_U232_MSR_DSR) 355 if (msr & MCT_U232_MSR_DSR)
349 *control_state |= TIOCM_DSR; 356 *control_state |= TIOCM_DSR;
350 else 357 else
@@ -361,14 +368,14 @@ static void mct_u232_msr_to_state(unsigned int *control_state, unsigned char msr
361 *control_state |= TIOCM_CD; 368 *control_state |= TIOCM_CD;
362 else 369 else
363 *control_state &= ~TIOCM_CD; 370 *control_state &= ~TIOCM_CD;
364 dbg("msr_to_state: msr=0x%x ==> state=0x%x", msr, *control_state); 371 dbg("msr_to_state: msr=0x%x ==> state=0x%x", msr, *control_state);
365} /* mct_u232_msr_to_state */ 372} /* mct_u232_msr_to_state */
366 373
367/* 374/*
368 * Driver's tty interface functions 375 * Driver's tty interface functions
369 */ 376 */
370 377
371static int mct_u232_startup (struct usb_serial *serial) 378static int mct_u232_startup(struct usb_serial *serial)
372{ 379{
373 struct mct_u232_private *priv; 380 struct mct_u232_private *priv;
374 struct usb_serial_port *port, *rport; 381 struct usb_serial_port *port, *rport;
@@ -390,18 +397,18 @@ static int mct_u232_startup (struct usb_serial *serial)
390 rport->interrupt_in_urb = NULL; 397 rport->interrupt_in_urb = NULL;
391 port->read_urb->context = port; 398 port->read_urb->context = port;
392 399
393 return (0); 400 return 0;
394} /* mct_u232_startup */ 401} /* mct_u232_startup */
395 402
396 403
397static void mct_u232_shutdown (struct usb_serial *serial) 404static void mct_u232_shutdown(struct usb_serial *serial)
398{ 405{
399 struct mct_u232_private *priv; 406 struct mct_u232_private *priv;
400 int i; 407 int i;
401 408
402 dbg("%s", __func__); 409 dbg("%s", __func__);
403 410
404 for (i=0; i < serial->num_ports; ++i) { 411 for (i = 0; i < serial->num_ports; ++i) {
405 /* My special items, the standard routines free my urbs */ 412 /* My special items, the standard routines free my urbs */
406 priv = usb_get_serial_port_data(serial->port[i]); 413 priv = usb_get_serial_port_data(serial->port[i]);
407 if (priv) { 414 if (priv) {
@@ -411,7 +418,8 @@ static void mct_u232_shutdown (struct usb_serial *serial)
411 } 418 }
412} /* mct_u232_shutdown */ 419} /* mct_u232_shutdown */
413 420
414static int mct_u232_open (struct usb_serial_port *port, struct file *filp) 421static int mct_u232_open(struct tty_struct *tty,
422 struct usb_serial_port *port, struct file *filp)
415{ 423{
416 struct usb_serial *serial = port->serial; 424 struct usb_serial *serial = port->serial;
417 struct mct_u232_private *priv = usb_get_serial_port_data(port); 425 struct mct_u232_private *priv = usb_get_serial_port_data(port);
@@ -428,21 +436,22 @@ static int mct_u232_open (struct usb_serial_port *port, struct file *filp)
428 * it seems to be able to accept only 16 bytes (and that's what 436 * it seems to be able to accept only 16 bytes (and that's what
429 * SniffUSB says too...) 437 * SniffUSB says too...)
430 */ 438 */
431 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID) 439 if (le16_to_cpu(serial->dev->descriptor.idProduct)
440 == MCT_U232_SITECOM_PID)
432 port->bulk_out_size = 16; 441 port->bulk_out_size = 16;
433 442
434 /* Do a defined restart: the normal serial device seems to 443 /* Do a defined restart: the normal serial device seems to
435 * always turn on DTR and RTS here, so do the same. I'm not 444 * always turn on DTR and RTS here, so do the same. I'm not
436 * sure if this is really necessary. But it should not harm 445 * sure if this is really necessary. But it should not harm
437 * either. 446 * either.
438 */ 447 */
439 spin_lock_irqsave(&priv->lock, flags); 448 spin_lock_irqsave(&priv->lock, flags);
440 if (port->tty->termios->c_cflag & CBAUD) 449 if (tty && (tty->termios->c_cflag & CBAUD))
441 priv->control_state = TIOCM_DTR | TIOCM_RTS; 450 priv->control_state = TIOCM_DTR | TIOCM_RTS;
442 else 451 else
443 priv->control_state = 0; 452 priv->control_state = 0;
444 453
445 priv->last_lcr = (MCT_U232_DATA_BITS_8 | 454 priv->last_lcr = (MCT_U232_DATA_BITS_8 |
446 MCT_U232_PARITY_NONE | 455 MCT_U232_PARITY_NONE |
447 MCT_U232_STOP_BITS_1); 456 MCT_U232_STOP_BITS_1);
448 control_state = priv->control_state; 457 control_state = priv->control_state;
@@ -481,15 +490,16 @@ error:
481} /* mct_u232_open */ 490} /* mct_u232_open */
482 491
483 492
484static void mct_u232_close (struct usb_serial_port *port, struct file *filp) 493static void mct_u232_close(struct tty_struct *tty,
494 struct usb_serial_port *port, struct file *filp)
485{ 495{
486 unsigned int c_cflag; 496 unsigned int c_cflag;
487 unsigned int control_state; 497 unsigned int control_state;
488 struct mct_u232_private *priv = usb_get_serial_port_data(port); 498 struct mct_u232_private *priv = usb_get_serial_port_data(port);
489 dbg("%s port %d", __func__, port->number); 499 dbg("%s port %d", __func__, port->number);
490 500
491 if (port->tty) { 501 if (tty) {
492 c_cflag = port->tty->termios->c_cflag; 502 c_cflag = tty->termios->c_cflag;
493 mutex_lock(&port->serial->disc_mutex); 503 mutex_lock(&port->serial->disc_mutex);
494 if (c_cflag & HUPCL && !port->serial->disconnected) { 504 if (c_cflag & HUPCL && !port->serial->disconnected) {
495 /* drop DTR and RTS */ 505 /* drop DTR and RTS */
@@ -512,7 +522,7 @@ static void mct_u232_close (struct usb_serial_port *port, struct file *filp)
512} /* mct_u232_close */ 522} /* mct_u232_close */
513 523
514 524
515static void mct_u232_read_int_callback (struct urb *urb) 525static void mct_u232_read_int_callback(struct urb *urb)
516{ 526{
517 struct usb_serial_port *port = urb->context; 527 struct usb_serial_port *port = urb->context;
518 struct mct_u232_private *priv = usb_get_serial_port_data(port); 528 struct mct_u232_private *priv = usb_get_serial_port_data(port);
@@ -545,36 +555,34 @@ static void mct_u232_read_int_callback (struct urb *urb)
545 return; 555 return;
546 } 556 }
547 557
548 dbg("%s - port %d", __func__, port->number); 558 dbg("%s - port %d", __func__, port->number);
549 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 559 usb_serial_debug_data(debug, &port->dev, __func__,
560 urb->actual_length, data);
550 561
551 /* 562 /*
552 * Work-a-round: handle the 'usual' bulk-in pipe here 563 * Work-a-round: handle the 'usual' bulk-in pipe here
553 */ 564 */
554 if (urb->transfer_buffer_length > 2) { 565 if (urb->transfer_buffer_length > 2) {
555 int i; 566 tty = port->port.tty;
556 tty = port->tty;
557 if (urb->actual_length) { 567 if (urb->actual_length) {
558 for (i = 0; i < urb->actual_length ; ++i) { 568 tty_insert_flip_string(tty, data, urb->actual_length);
559 tty_insert_flip_char(tty, data[i], 0);
560 }
561 tty_flip_buffer_push(tty); 569 tty_flip_buffer_push(tty);
562 } 570 }
563 goto exit; 571 goto exit;
564 } 572 }
565 573
566 /* 574 /*
567 * The interrupt-in pipe signals exceptional conditions (modem line 575 * The interrupt-in pipe signals exceptional conditions (modem line
568 * signal changes and errors). data[0] holds MSR, data[1] holds LSR. 576 * signal changes and errors). data[0] holds MSR, data[1] holds LSR.
569 */ 577 */
570 spin_lock_irqsave(&priv->lock, flags); 578 spin_lock_irqsave(&priv->lock, flags);
571 priv->last_msr = data[MCT_U232_MSR_INDEX]; 579 priv->last_msr = data[MCT_U232_MSR_INDEX];
572 580
573 /* Record Control Line states */ 581 /* Record Control Line states */
574 mct_u232_msr_to_state(&priv->control_state, priv->last_msr); 582 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
575 583
576#if 0 584#if 0
577 /* Not yet handled. See belin_sa.c for further information */ 585 /* Not yet handled. See belkin_sa.c for further information */
578 /* Now to report any errors */ 586 /* Now to report any errors */
579 priv->last_lsr = data[MCT_U232_LSR_INDEX]; 587 priv->last_lsr = data[MCT_U232_LSR_INDEX];
580 /* 588 /*
@@ -583,7 +591,7 @@ static void mct_u232_read_int_callback (struct urb *urb)
583 * to look in to this before committing any code. 591 * to look in to this before committing any code.
584 */ 592 */
585 if (priv->last_lsr & MCT_U232_LSR_ERR) { 593 if (priv->last_lsr & MCT_U232_LSR_ERR) {
586 tty = port->tty; 594 tty = port->port.tty;
587 /* Overrun Error */ 595 /* Overrun Error */
588 if (priv->last_lsr & MCT_U232_LSR_OE) { 596 if (priv->last_lsr & MCT_U232_LSR_OE) {
589 } 597 }
@@ -600,18 +608,19 @@ static void mct_u232_read_int_callback (struct urb *urb)
600#endif 608#endif
601 spin_unlock_irqrestore(&priv->lock, flags); 609 spin_unlock_irqrestore(&priv->lock, flags);
602exit: 610exit:
603 retval = usb_submit_urb (urb, GFP_ATOMIC); 611 retval = usb_submit_urb(urb, GFP_ATOMIC);
604 if (retval) 612 if (retval)
605 err ("%s - usb_submit_urb failed with result %d", 613 err("%s - usb_submit_urb failed with result %d",
606 __func__, retval); 614 __func__, retval);
607} /* mct_u232_read_int_callback */ 615} /* mct_u232_read_int_callback */
608 616
609static void mct_u232_set_termios (struct usb_serial_port *port, 617static void mct_u232_set_termios(struct tty_struct *tty,
610 struct ktermios *old_termios) 618 struct usb_serial_port *port,
619 struct ktermios *old_termios)
611{ 620{
612 struct usb_serial *serial = port->serial; 621 struct usb_serial *serial = port->serial;
613 struct mct_u232_private *priv = usb_get_serial_port_data(port); 622 struct mct_u232_private *priv = usb_get_serial_port_data(port);
614 struct ktermios *termios = port->tty->termios; 623 struct ktermios *termios = tty->termios;
615 unsigned int cflag = termios->c_cflag; 624 unsigned int cflag = termios->c_cflag;
616 unsigned int old_cflag = old_termios->c_cflag; 625 unsigned int old_cflag = old_termios->c_cflag;
617 unsigned long flags; 626 unsigned long flags;
@@ -631,20 +640,20 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
631 * Premature optimization is the root of all evil. 640 * Premature optimization is the root of all evil.
632 */ 641 */
633 642
634 /* reassert DTR and RTS on transition from B0 */ 643 /* reassert DTR and RTS on transition from B0 */
635 if ((old_cflag & CBAUD) == B0) { 644 if ((old_cflag & CBAUD) == B0) {
636 dbg("%s: baud was B0", __func__); 645 dbg("%s: baud was B0", __func__);
637 control_state |= TIOCM_DTR | TIOCM_RTS; 646 control_state |= TIOCM_DTR | TIOCM_RTS;
638 mct_u232_set_modem_ctrl(serial, control_state); 647 mct_u232_set_modem_ctrl(serial, control_state);
639 } 648 }
640 649
641 mct_u232_set_baud_rate(serial, port, tty_get_baud_rate(port->tty)); 650 mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty));
642 651
643 if ((cflag & CBAUD) == B0 ) { 652 if ((cflag & CBAUD) == B0) {
644 dbg("%s: baud is B0", __func__); 653 dbg("%s: baud is B0", __func__);
645 /* Drop RTS and DTR */ 654 /* Drop RTS and DTR */
646 control_state &= ~(TIOCM_DTR | TIOCM_RTS); 655 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
647 mct_u232_set_modem_ctrl(serial, control_state); 656 mct_u232_set_modem_ctrl(serial, control_state);
648 } 657 }
649 658
650 /* 659 /*
@@ -689,8 +698,9 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
689 spin_unlock_irqrestore(&priv->lock, flags); 698 spin_unlock_irqrestore(&priv->lock, flags);
690} /* mct_u232_set_termios */ 699} /* mct_u232_set_termios */
691 700
692static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state ) 701static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
693{ 702{
703 struct usb_serial_port *port = tty->driver_data;
694 struct usb_serial *serial = port->serial; 704 struct usb_serial *serial = port->serial;
695 struct mct_u232_private *priv = usb_get_serial_port_data(port); 705 struct mct_u232_private *priv = usb_get_serial_port_data(port);
696 unsigned char lcr; 706 unsigned char lcr;
@@ -709,12 +719,13 @@ static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
709} /* mct_u232_break_ctl */ 719} /* mct_u232_break_ctl */
710 720
711 721
712static int mct_u232_tiocmget (struct usb_serial_port *port, struct file *file) 722static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file)
713{ 723{
724 struct usb_serial_port *port = tty->driver_data;
714 struct mct_u232_private *priv = usb_get_serial_port_data(port); 725 struct mct_u232_private *priv = usb_get_serial_port_data(port);
715 unsigned int control_state; 726 unsigned int control_state;
716 unsigned long flags; 727 unsigned long flags;
717 728
718 dbg("%s", __func__); 729 dbg("%s", __func__);
719 730
720 spin_lock_irqsave(&priv->lock, flags); 731 spin_lock_irqsave(&priv->lock, flags);
@@ -724,14 +735,15 @@ static int mct_u232_tiocmget (struct usb_serial_port *port, struct file *file)
724 return control_state; 735 return control_state;
725} 736}
726 737
727static int mct_u232_tiocmset (struct usb_serial_port *port, struct file *file, 738static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
728 unsigned int set, unsigned int clear) 739 unsigned int set, unsigned int clear)
729{ 740{
741 struct usb_serial_port *port = tty->driver_data;
730 struct usb_serial *serial = port->serial; 742 struct usb_serial *serial = port->serial;
731 struct mct_u232_private *priv = usb_get_serial_port_data(port); 743 struct mct_u232_private *priv = usb_get_serial_port_data(port);
732 unsigned int control_state; 744 unsigned int control_state;
733 unsigned long flags; 745 unsigned long flags;
734 746
735 dbg("%s", __func__); 747 dbg("%s", __func__);
736 748
737 spin_lock_irqsave(&priv->lock, flags); 749 spin_lock_irqsave(&priv->lock, flags);
@@ -751,77 +763,50 @@ static int mct_u232_tiocmset (struct usb_serial_port *port, struct file *file,
751 return mct_u232_set_modem_ctrl(serial, control_state); 763 return mct_u232_set_modem_ctrl(serial, control_state);
752} 764}
753 765
754static int mct_u232_ioctl (struct usb_serial_port *port, struct file * file, 766static void mct_u232_throttle(struct tty_struct *tty)
755 unsigned int cmd, unsigned long arg)
756{
757 dbg("%scmd=0x%x", __func__, cmd);
758
759 /* Based on code from acm.c and others */
760 switch (cmd) {
761 case TIOCMIWAIT:
762 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
763 /* TODO */
764 return( 0 );
765
766 case TIOCGICOUNT:
767 /* return count of modemline transitions */
768 /* TODO */
769 return 0;
770
771 default:
772 dbg("%s: arg not supported - 0x%04x", __func__,cmd);
773 return(-ENOIOCTLCMD);
774 break;
775 }
776 return 0;
777} /* mct_u232_ioctl */
778
779static void mct_u232_throttle (struct usb_serial_port *port)
780{ 767{
768 struct usb_serial_port *port = tty->driver_data;
781 struct mct_u232_private *priv = usb_get_serial_port_data(port); 769 struct mct_u232_private *priv = usb_get_serial_port_data(port);
782 unsigned long flags; 770 unsigned long flags;
783 unsigned int control_state; 771 unsigned int control_state;
784 struct tty_struct *tty;
785 772
786 tty = port->tty;
787 dbg("%s - port %d", __func__, port->number); 773 dbg("%s - port %d", __func__, port->number);
788 774
789 spin_lock_irqsave(&priv->lock, flags); 775 spin_lock_irqsave(&priv->lock, flags);
790 priv->rx_flags |= THROTTLED; 776 priv->rx_flags |= THROTTLED;
791 if (C_CRTSCTS(tty)) { 777 if (C_CRTSCTS(tty)) {
792 priv->control_state &= ~TIOCM_RTS; 778 priv->control_state &= ~TIOCM_RTS;
793 control_state = priv->control_state; 779 control_state = priv->control_state;
794 spin_unlock_irqrestore(&priv->lock, flags); 780 spin_unlock_irqrestore(&priv->lock, flags);
795 (void) mct_u232_set_modem_ctrl(port->serial, control_state); 781 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
796 } else { 782 } else {
797 spin_unlock_irqrestore(&priv->lock, flags); 783 spin_unlock_irqrestore(&priv->lock, flags);
798 } 784 }
799} 785}
800 786
801 787
802static void mct_u232_unthrottle (struct usb_serial_port *port) 788static void mct_u232_unthrottle(struct tty_struct *tty)
803{ 789{
790 struct usb_serial_port *port = tty->driver_data;
804 struct mct_u232_private *priv = usb_get_serial_port_data(port); 791 struct mct_u232_private *priv = usb_get_serial_port_data(port);
805 unsigned long flags; 792 unsigned long flags;
806 unsigned int control_state; 793 unsigned int control_state;
807 struct tty_struct *tty;
808 794
809 dbg("%s - port %d", __func__, port->number); 795 dbg("%s - port %d", __func__, port->number);
810 796
811 tty = port->tty;
812 spin_lock_irqsave(&priv->lock, flags); 797 spin_lock_irqsave(&priv->lock, flags);
813 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) { 798 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) {
814 priv->rx_flags &= ~THROTTLED; 799 priv->rx_flags &= ~THROTTLED;
815 priv->control_state |= TIOCM_RTS; 800 priv->control_state |= TIOCM_RTS;
816 control_state = priv->control_state; 801 control_state = priv->control_state;
817 spin_unlock_irqrestore(&priv->lock, flags); 802 spin_unlock_irqrestore(&priv->lock, flags);
818 (void) mct_u232_set_modem_ctrl(port->serial, control_state); 803 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
819 } else { 804 } else {
820 spin_unlock_irqrestore(&priv->lock, flags); 805 spin_unlock_irqrestore(&priv->lock, flags);
821 } 806 }
822} 807}
823 808
824static int __init mct_u232_init (void) 809static int __init mct_u232_init(void)
825{ 810{
826 int retval; 811 int retval;
827 retval = usb_serial_register(&mct_u232_device); 812 retval = usb_serial_register(&mct_u232_device);
@@ -839,18 +824,17 @@ failed_usb_serial_register:
839} 824}
840 825
841 826
842static void __exit mct_u232_exit (void) 827static void __exit mct_u232_exit(void)
843{ 828{
844 usb_deregister (&mct_u232_driver); 829 usb_deregister(&mct_u232_driver);
845 usb_serial_deregister (&mct_u232_device); 830 usb_serial_deregister(&mct_u232_device);
846} 831}
847 832
848 833module_init(mct_u232_init);
849module_init (mct_u232_init);
850module_exit(mct_u232_exit); 834module_exit(mct_u232_exit);
851 835
852MODULE_AUTHOR( DRIVER_AUTHOR ); 836MODULE_AUTHOR(DRIVER_AUTHOR);
853MODULE_DESCRIPTION( DRIVER_DESC ); 837MODULE_DESCRIPTION(DRIVER_DESC);
854MODULE_LICENSE("GPL"); 838MODULE_LICENSE("GPL");
855 839
856module_param(debug, bool, S_IRUGO | S_IWUSR); 840module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 50f1fe263338..7c4917d77c0a 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -33,7 +33,7 @@
33#include <linux/serial_reg.h> 33#include <linux/serial_reg.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb/serial.h> 35#include <linux/usb/serial.h>
36#include <asm/uaccess.h> 36#include <linux/uaccess.h>
37 37
38 38
39/* 39/*
@@ -64,8 +64,7 @@
64#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */ 64#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
65 65
66/* This structure holds all of the local port information */ 66/* This structure holds all of the local port information */
67struct moschip_port 67struct moschip_port {
68{
69 __u8 shadowLCR; /* last LCR value received */ 68 __u8 shadowLCR; /* last LCR value received */
70 __u8 shadowMCR; /* last MCR value received */ 69 __u8 shadowMCR; /* last MCR value received */
71 __u8 shadowMSR; /* last MSR value received */ 70 __u8 shadowMSR; /* last MSR value received */
@@ -76,8 +75,7 @@ struct moschip_port
76}; 75};
77 76
78/* This structure holds all of the individual serial device information */ 77/* This structure holds all of the individual serial device information */
79struct moschip_serial 78struct moschip_serial {
80{
81 int interrupt_started; 79 int interrupt_started;
82}; 80};
83 81
@@ -88,7 +86,7 @@ static int debug;
88#define MOSCHIP_DEVICE_ID_7715 0x7715 86#define MOSCHIP_DEVICE_ID_7715 0x7715
89 87
90static struct usb_device_id moschip_port_id_table [] = { 88static struct usb_device_id moschip_port_id_table [] = {
91 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP,MOSCHIP_DEVICE_ID_7720) }, 89 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7720) },
92 { } /* terminating entry */ 90 { } /* terminating entry */
93}; 91};
94MODULE_DEVICE_TABLE(usb, moschip_port_id_table); 92MODULE_DEVICE_TABLE(usb, moschip_port_id_table);
@@ -108,7 +106,7 @@ static void mos7720_interrupt_callback(struct urb *urb)
108 __u8 sp1; 106 __u8 sp1;
109 __u8 sp2; 107 __u8 sp2;
110 108
111 dbg("%s"," : Entering\n"); 109 dbg("%s", " : Entering\n");
112 110
113 switch (status) { 111 switch (status) {
114 case 0: 112 case 0:
@@ -208,7 +206,7 @@ static void mos7720_bulk_in_callback(struct urb *urb)
208 206
209 mos7720_port = urb->context; 207 mos7720_port = urb->context;
210 if (!mos7720_port) { 208 if (!mos7720_port) {
211 dbg("%s","NULL mos7720_port pointer \n"); 209 dbg("%s", "NULL mos7720_port pointer \n");
212 return ; 210 return ;
213 } 211 }
214 212
@@ -218,7 +216,7 @@ static void mos7720_bulk_in_callback(struct urb *urb)
218 216
219 data = urb->transfer_buffer; 217 data = urb->transfer_buffer;
220 218
221 tty = port->tty; 219 tty = port->port.tty;
222 if (tty && urb->actual_length) { 220 if (tty && urb->actual_length) {
223 tty_buffer_request_room(tty, urb->actual_length); 221 tty_buffer_request_room(tty, urb->actual_length);
224 tty_insert_flip_string(tty, data, urb->actual_length); 222 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -264,7 +262,7 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
264 262
265 dbg("Entering ........."); 263 dbg("Entering .........");
266 264
267 tty = mos7720_port->port->tty; 265 tty = mos7720_port->port->port.tty;
268 266
269 if (tty && mos7720_port->open) 267 if (tty && mos7720_port->open)
270 tty_wakeup(tty); 268 tty_wakeup(tty);
@@ -284,17 +282,16 @@ static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
284 __u16 size = 0x0000; 282 __u16 size = 0x0000;
285 283
286 if (value < MOS_MAX_PORT) { 284 if (value < MOS_MAX_PORT) {
287 if (product == MOSCHIP_DEVICE_ID_7715) { 285 if (product == MOSCHIP_DEVICE_ID_7715)
288 value = value*0x100+0x100; 286 value = value*0x100+0x100;
289 } else { 287 else
290 value = value*0x100+0x200; 288 value = value*0x100+0x200;
291 }
292 } else { 289 } else {
293 value = 0x0000; 290 value = 0x0000;
294 if ((product == MOSCHIP_DEVICE_ID_7715) && 291 if ((product == MOSCHIP_DEVICE_ID_7715) &&
295 (index != 0x08)) { 292 (index != 0x08)) {
296 dbg("serial->product== MOSCHIP_DEVICE_ID_7715"); 293 dbg("serial->product== MOSCHIP_DEVICE_ID_7715");
297 //index = 0x01 ; 294 /* index = 0x01 ; */
298 } 295 }
299 } 296 }
300 297
@@ -308,19 +305,20 @@ static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
308 request = (__u8)MOS_READ; 305 request = (__u8)MOS_READ;
309 requesttype = (__u8)0xC0; 306 requesttype = (__u8)0xC0;
310 size = 0x01; 307 size = 0x01;
311 pipe = usb_rcvctrlpipe(serial->dev,0); 308 pipe = usb_rcvctrlpipe(serial->dev, 0);
312 } 309 }
313 310
314 status = usb_control_msg(serial->dev, pipe, request, requesttype, 311 status = usb_control_msg(serial->dev, pipe, request, requesttype,
315 value, index, data, size, MOS_WDR_TIMEOUT); 312 value, index, data, size, MOS_WDR_TIMEOUT);
316 313
317 if (status < 0) 314 if (status < 0)
318 dbg("Command Write failed Value %x index %x\n",value,index); 315 dbg("Command Write failed Value %x index %x\n", value, index);
319 316
320 return status; 317 return status;
321} 318}
322 319
323static int mos7720_open(struct usb_serial_port *port, struct file * filp) 320static int mos7720_open(struct tty_struct *tty,
321 struct usb_serial_port *port, struct file *filp)
324{ 322{
325 struct usb_serial *serial; 323 struct usb_serial *serial;
326 struct usb_serial_port *port0; 324 struct usb_serial_port *port0;
@@ -351,7 +349,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
351 349
352 /* Initialising the write urb pool */ 350 /* Initialising the write urb pool */
353 for (j = 0; j < NUM_URBS; ++j) { 351 for (j = 0; j < NUM_URBS; ++j) {
354 urb = usb_alloc_urb(0,GFP_KERNEL); 352 urb = usb_alloc_urb(0, GFP_KERNEL);
355 mos7720_port->write_urb_pool[j] = urb; 353 mos7720_port->write_urb_pool[j] = urb;
356 354
357 if (urb == NULL) { 355 if (urb == NULL) {
@@ -385,7 +383,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
385 */ 383 */
386 port_number = port->number - port->serial->minor; 384 port_number = port->number - port->serial->minor;
387 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data); 385 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data);
388 dbg("SS::%p LSR:%x\n",mos7720_port, data); 386 dbg("SS::%p LSR:%x\n", mos7720_port, data);
389 387
390 dbg("Check:Sending Command .........."); 388 dbg("Check:Sending Command ..........");
391 389
@@ -402,10 +400,10 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
402 data = 0xCF; 400 data = 0xCF;
403 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data); 401 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
404 data = 0x03; 402 data = 0x03;
405 mos7720_port->shadowLCR = data; 403 mos7720_port->shadowLCR = data;
406 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 404 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
407 data = 0x0b; 405 data = 0x0b;
408 mos7720_port->shadowMCR = data; 406 mos7720_port->shadowMCR = data;
409 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 407 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
410 data = 0x0b; 408 data = 0x0b;
411 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 409 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
@@ -420,7 +418,8 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
420 data = 0x03; 418 data = 0x03;
421 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data); 419 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
422 data = 0x00; 420 data = 0x00;
423 send_mos_cmd(port->serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data); 421 send_mos_cmd(port->serial, MOS_WRITE, MOS_MAX_PORT,
422 port_number + 1, &data);
424*/ 423*/
425 data = 0x00; 424 data = 0x00;
426 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data); 425 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
@@ -429,28 +428,26 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
429 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 428 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
430 429
431 data = 0x83; 430 data = 0x83;
432 mos7720_port->shadowLCR = data; 431 mos7720_port->shadowLCR = data;
433 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 432 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
434 data = 0x0c; 433 data = 0x0c;
435 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data); 434 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
436 data = 0x00; 435 data = 0x00;
437 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 436 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
438 data = 0x03; 437 data = 0x03;
439 mos7720_port->shadowLCR = data; 438 mos7720_port->shadowLCR = data;
440 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 439 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
441 data = 0x0c; 440 data = 0x0c;
442 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 441 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
443 data = 0x0c; 442 data = 0x0c;
444 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 443 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
445 444
446//Matrix
447
448 /* force low_latency on so that our tty_push actually forces * 445 /* force low_latency on so that our tty_push actually forces *
449 * the data through,otherwise it is scheduled, and with * 446 * the data through,otherwise it is scheduled, and with *
450 * high data rates (like with OHCI) data can get lost. */ 447 * high data rates (like with OHCI) data can get lost. */
451 448
452 if (port->tty) 449 if (tty)
453 port->tty->low_latency = 1; 450 tty->low_latency = 1;
454 451
455 /* see if we've set up our endpoint info yet * 452 /* see if we've set up our endpoint info yet *
456 * (can't set it up in mos7720_startup as the * 453 * (can't set it up in mos7720_startup as the *
@@ -465,15 +462,15 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
465 462
466 /* set up our interrupt urb */ 463 /* set up our interrupt urb */
467 usb_fill_int_urb(port0->interrupt_in_urb, serial->dev, 464 usb_fill_int_urb(port0->interrupt_in_urb, serial->dev,
468 usb_rcvintpipe(serial->dev, 465 usb_rcvintpipe(serial->dev,
469 port->interrupt_in_endpointAddress), 466 port->interrupt_in_endpointAddress),
470 port0->interrupt_in_buffer, 467 port0->interrupt_in_buffer,
471 port0->interrupt_in_urb->transfer_buffer_length, 468 port0->interrupt_in_urb->transfer_buffer_length,
472 mos7720_interrupt_callback, mos7720_port, 469 mos7720_interrupt_callback, mos7720_port,
473 port0->interrupt_in_urb->interval); 470 port0->interrupt_in_urb->interval);
474 471
475 /* start interrupt read for this mos7720 this interrupt * 472 /* start interrupt read for this mos7720 this interrupt *
476 * will continue as long as the mos7720 is connected */ 473 * will continue as long as the mos7720 is connected */
477 dbg("Submit URB over !!!"); 474 dbg("Submit URB over !!!");
478 response = usb_submit_urb(port0->interrupt_in_urb, GFP_KERNEL); 475 response = usb_submit_urb(port0->interrupt_in_urb, GFP_KERNEL);
479 if (response) 476 if (response)
@@ -485,14 +482,14 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
485 /* set up our bulk in urb */ 482 /* set up our bulk in urb */
486 usb_fill_bulk_urb(port->read_urb, serial->dev, 483 usb_fill_bulk_urb(port->read_urb, serial->dev,
487 usb_rcvbulkpipe(serial->dev, 484 usb_rcvbulkpipe(serial->dev,
488 port->bulk_in_endpointAddress), 485 port->bulk_in_endpointAddress),
489 port->bulk_in_buffer, 486 port->bulk_in_buffer,
490 port->read_urb->transfer_buffer_length, 487 port->read_urb->transfer_buffer_length,
491 mos7720_bulk_in_callback, mos7720_port); 488 mos7720_bulk_in_callback, mos7720_port);
492 response = usb_submit_urb(port->read_urb, GFP_KERNEL); 489 response = usb_submit_urb(port->read_urb, GFP_KERNEL);
493 if (response) 490 if (response)
494 dev_err(&port->dev, 491 dev_err(&port->dev, "%s - Error %d submitting read urb\n",
495 "%s - Error %d submitting read urb\n", __func__, response); 492 __func__, response);
496 493
497 /* initialize our icount structure */ 494 /* initialize our icount structure */
498 memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount)); 495 memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount));
@@ -515,8 +512,9 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
515 * system, 512 * system,
516 * Otherwise we return a negative error number. 513 * Otherwise we return a negative error number.
517 */ 514 */
518static int mos7720_chars_in_buffer(struct usb_serial_port *port) 515static int mos7720_chars_in_buffer(struct tty_struct *tty)
519{ 516{
517 struct usb_serial_port *port = tty->driver_data;
520 int i; 518 int i;
521 int chars = 0; 519 int chars = 0;
522 struct moschip_port *mos7720_port; 520 struct moschip_port *mos7720_port;
@@ -530,14 +528,16 @@ static int mos7720_chars_in_buffer(struct usb_serial_port *port)
530 } 528 }
531 529
532 for (i = 0; i < NUM_URBS; ++i) { 530 for (i = 0; i < NUM_URBS; ++i) {
533 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status == -EINPROGRESS) 531 if (mos7720_port->write_urb_pool[i] &&
532 mos7720_port->write_urb_pool[i]->status == -EINPROGRESS)
534 chars += URB_TRANSFER_BUFFER_SIZE; 533 chars += URB_TRANSFER_BUFFER_SIZE;
535 } 534 }
536 dbg("%s - returns %d", __func__, chars); 535 dbg("%s - returns %d", __func__, chars);
537 return chars; 536 return chars;
538} 537}
539 538
540static void mos7720_close(struct usb_serial_port *port, struct file *filp) 539static void mos7720_close(struct tty_struct *tty,
540 struct usb_serial_port *port, struct file *filp)
541{ 541{
542 struct usb_serial *serial; 542 struct usb_serial *serial;
543 struct moschip_port *mos7720_port; 543 struct moschip_port *mos7720_port;
@@ -575,12 +575,12 @@ static void mos7720_close(struct usb_serial_port *port, struct file *filp)
575 * been disconnected */ 575 * been disconnected */
576 if (!serial->disconnected) { 576 if (!serial->disconnected) {
577 data = 0x00; 577 data = 0x00;
578 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, 578 send_mos_cmd(serial, MOS_WRITE,
579 0x04, &data); 579 port->number - port->serial->minor, 0x04, &data);
580 580
581 data = 0x00; 581 data = 0x00;
582 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, 582 send_mos_cmd(serial, MOS_WRITE,
583 0x01, &data); 583 port->number - port->serial->minor, 0x01, &data);
584 } 584 }
585 mutex_unlock(&serial->disc_mutex); 585 mutex_unlock(&serial->disc_mutex);
586 mos7720_port->open = 0; 586 mos7720_port->open = 0;
@@ -588,9 +588,10 @@ static void mos7720_close(struct usb_serial_port *port, struct file *filp)
588 dbg("Leaving %s", __func__); 588 dbg("Leaving %s", __func__);
589} 589}
590 590
591static void mos7720_break(struct usb_serial_port *port, int break_state) 591static void mos7720_break(struct tty_struct *tty, int break_state)
592{ 592{
593 unsigned char data; 593 struct usb_serial_port *port = tty->driver_data;
594 unsigned char data;
594 struct usb_serial *serial; 595 struct usb_serial *serial;
595 struct moschip_port *mos7720_port; 596 struct moschip_port *mos7720_port;
596 597
@@ -621,8 +622,9 @@ static void mos7720_break(struct usb_serial_port *port, int break_state)
621 * If successful, we return the amount of room that we have for this port 622 * If successful, we return the amount of room that we have for this port
622 * Otherwise we return a negative error number. 623 * Otherwise we return a negative error number.
623 */ 624 */
624static int mos7720_write_room(struct usb_serial_port *port) 625static int mos7720_write_room(struct tty_struct *tty)
625{ 626{
627 struct usb_serial_port *port = tty->driver_data;
626 struct moschip_port *mos7720_port; 628 struct moschip_port *mos7720_port;
627 int room = 0; 629 int room = 0;
628 int i; 630 int i;
@@ -637,7 +639,8 @@ static int mos7720_write_room(struct usb_serial_port *port)
637 639
638 /* FIXME: Locking */ 640 /* FIXME: Locking */
639 for (i = 0; i < NUM_URBS; ++i) { 641 for (i = 0; i < NUM_URBS; ++i) {
640 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) 642 if (mos7720_port->write_urb_pool[i] &&
643 mos7720_port->write_urb_pool[i]->status != -EINPROGRESS)
641 room += URB_TRANSFER_BUFFER_SIZE; 644 room += URB_TRANSFER_BUFFER_SIZE;
642 } 645 }
643 646
@@ -645,8 +648,8 @@ static int mos7720_write_room(struct usb_serial_port *port)
645 return room; 648 return room;
646} 649}
647 650
648static int mos7720_write(struct usb_serial_port *port, 651static int mos7720_write(struct tty_struct *tty, struct usb_serial_port *port,
649 const unsigned char *data, int count) 652 const unsigned char *data, int count)
650{ 653{
651 int status; 654 int status;
652 int i; 655 int i;
@@ -672,9 +675,10 @@ static int mos7720_write(struct usb_serial_port *port,
672 urb = NULL; 675 urb = NULL;
673 676
674 for (i = 0; i < NUM_URBS; ++i) { 677 for (i = 0; i < NUM_URBS; ++i) {
675 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) { 678 if (mos7720_port->write_urb_pool[i] &&
679 mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) {
676 urb = mos7720_port->write_urb_pool[i]; 680 urb = mos7720_port->write_urb_pool[i];
677 dbg("URB:%d",i); 681 dbg("URB:%d", i);
678 break; 682 break;
679 } 683 }
680 } 684 }
@@ -692,7 +696,7 @@ static int mos7720_write(struct usb_serial_port *port,
692 goto exit; 696 goto exit;
693 } 697 }
694 } 698 }
695 transfer_size = min (count, URB_TRANSFER_BUFFER_SIZE); 699 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
696 700
697 memcpy(urb->transfer_buffer, current_position, transfer_size); 701 memcpy(urb->transfer_buffer, current_position, transfer_size);
698 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, 702 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size,
@@ -701,12 +705,12 @@ static int mos7720_write(struct usb_serial_port *port,
701 /* fill urb with data and submit */ 705 /* fill urb with data and submit */
702 usb_fill_bulk_urb(urb, serial->dev, 706 usb_fill_bulk_urb(urb, serial->dev,
703 usb_sndbulkpipe(serial->dev, 707 usb_sndbulkpipe(serial->dev,
704 port->bulk_out_endpointAddress), 708 port->bulk_out_endpointAddress),
705 urb->transfer_buffer, transfer_size, 709 urb->transfer_buffer, transfer_size,
706 mos7720_bulk_out_data_callback, mos7720_port); 710 mos7720_bulk_out_data_callback, mos7720_port);
707 711
708 /* send it down the pipe */ 712 /* send it down the pipe */
709 status = usb_submit_urb(urb,GFP_ATOMIC); 713 status = usb_submit_urb(urb, GFP_ATOMIC);
710 if (status) { 714 if (status) {
711 err("%s - usb_submit_urb(write bulk) failed with status = %d", 715 err("%s - usb_submit_urb(write bulk) failed with status = %d",
712 __func__, status); 716 __func__, status);
@@ -719,10 +723,10 @@ exit:
719 return bytes_sent; 723 return bytes_sent;
720} 724}
721 725
722static void mos7720_throttle(struct usb_serial_port *port) 726static void mos7720_throttle(struct tty_struct *tty)
723{ 727{
728 struct usb_serial_port *port = tty->driver_data;
724 struct moschip_port *mos7720_port; 729 struct moschip_port *mos7720_port;
725 struct tty_struct *tty;
726 int status; 730 int status;
727 731
728 dbg("%s- port %d\n", __func__, port->number); 732 dbg("%s- port %d\n", __func__, port->number);
@@ -739,16 +743,10 @@ static void mos7720_throttle(struct usb_serial_port *port)
739 743
740 dbg("%s: Entering ..........", __func__); 744 dbg("%s: Entering ..........", __func__);
741 745
742 tty = port->tty;
743 if (!tty) {
744 dbg("%s - no tty available", __func__);
745 return;
746 }
747
748 /* if we are implementing XON/XOFF, send the stop character */ 746 /* if we are implementing XON/XOFF, send the stop character */
749 if (I_IXOFF(tty)) { 747 if (I_IXOFF(tty)) {
750 unsigned char stop_char = STOP_CHAR(tty); 748 unsigned char stop_char = STOP_CHAR(tty);
751 status = mos7720_write(port, &stop_char, 1); 749 status = mos7720_write(tty, port, &stop_char, 1);
752 if (status <= 0) 750 if (status <= 0)
753 return; 751 return;
754 } 752 }
@@ -764,11 +762,11 @@ static void mos7720_throttle(struct usb_serial_port *port)
764 } 762 }
765} 763}
766 764
767static void mos7720_unthrottle(struct usb_serial_port *port) 765static void mos7720_unthrottle(struct tty_struct *tty)
768{ 766{
769 struct tty_struct *tty; 767 struct usb_serial_port *port = tty->driver_data;
770 int status;
771 struct moschip_port *mos7720_port = usb_get_serial_port_data(port); 768 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
769 int status;
772 770
773 if (mos7720_port == NULL) 771 if (mos7720_port == NULL)
774 return; 772 return;
@@ -780,16 +778,10 @@ static void mos7720_unthrottle(struct usb_serial_port *port)
780 778
781 dbg("%s: Entering ..........", __func__); 779 dbg("%s: Entering ..........", __func__);
782 780
783 tty = port->tty;
784 if (!tty) {
785 dbg("%s - no tty available", __func__);
786 return;
787 }
788
789 /* if we are implementing XON/XOFF, send the start character */ 781 /* if we are implementing XON/XOFF, send the start character */
790 if (I_IXOFF(tty)) { 782 if (I_IXOFF(tty)) {
791 unsigned char start_char = START_CHAR(tty); 783 unsigned char start_char = START_CHAR(tty);
792 status = mos7720_write(port, &start_char, 1); 784 status = mos7720_write(tty, port, &start_char, 1);
793 if (status <= 0) 785 if (status <= 0)
794 return; 786 return;
795 } 787 }
@@ -819,9 +811,9 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
819 port = mos7720_port->port; 811 port = mos7720_port->port;
820 serial = port->serial; 812 serial = port->serial;
821 813
822 /*********************************************** 814 /***********************************************
823 * Init Sequence for higher rates 815 * Init Sequence for higher rates
824 ***********************************************/ 816 ***********************************************/
825 dbg("Sending Setting Commands .........."); 817 dbg("Sending Setting Commands ..........");
826 port_number = port->number - port->serial->minor; 818 port_number = port->number - port->serial->minor;
827 819
@@ -832,7 +824,7 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
832 data = 0x0CF; 824 data = 0x0CF;
833 send_mos_cmd(serial, MOS_WRITE, port->number, 0x02, &data); 825 send_mos_cmd(serial, MOS_WRITE, port->number, 0x02, &data);
834 data = 0x00b; 826 data = 0x00b;
835 mos7720_port->shadowMCR = data; 827 mos7720_port->shadowMCR = data;
836 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 828 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
837 data = 0x00b; 829 data = 0x00b;
838 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 830 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
@@ -843,12 +835,12 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
843 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 835 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
844 836
845 837
846 /*********************************************** 838 /***********************************************
847 * Set for higher rates * 839 * Set for higher rates *
848 ***********************************************/ 840 ***********************************************/
849 841
850 data = baud * 0x10; 842 data = baud * 0x10;
851 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1,&data); 843 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
852 844
853 data = 0x003; 845 data = 0x003;
854 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data); 846 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
@@ -856,34 +848,33 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
856 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 848 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
857 849
858 data = 0x02b; 850 data = 0x02b;
859 mos7720_port->shadowMCR = data; 851 mos7720_port->shadowMCR = data;
860 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 852 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
861 data = 0x02b; 853 data = 0x02b;
862 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 854 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
863 855
864 /*********************************************** 856 /***********************************************
865 * Set DLL/DLM 857 * Set DLL/DLM
866 ***********************************************/ 858 ***********************************************/
867 859
868 data = mos7720_port->shadowLCR | UART_LCR_DLAB; 860 data = mos7720_port->shadowLCR | UART_LCR_DLAB;
869 mos7720_port->shadowLCR = data; 861 mos7720_port->shadowLCR = data;
870 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 862 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
871 863
872 data = 0x001; /* DLL */ 864 data = 0x001; /* DLL */
873 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data); 865 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
874 data = 0x000; /* DLM */ 866 data = 0x000; /* DLM */
875 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 867 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
876 868
877 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB; 869 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
878 mos7720_port->shadowLCR = data; 870 mos7720_port->shadowLCR = data;
879 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 871 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
880 872
881 return 0; 873 return 0;
882} 874}
883 875
884/* baud rate information */ 876/* baud rate information */
885struct divisor_table_entry 877struct divisor_table_entry {
886{
887 __u32 baudrate; 878 __u32 baudrate;
888 __u16 divisor; 879 __u16 divisor;
889}; 880};
@@ -932,8 +923,8 @@ static int calc_baud_rate_divisor(int baudrate, int *divisor)
932 } 923 }
933 } 924 }
934 925
935 /* After trying for all the standard baud rates * 926 /* After trying for all the standard baud rates *
936 * Try calculating the divisor for this baud rate */ 927 * Try calculating the divisor for this baud rate */
937 if (baudrate > 75 && baudrate < 230400) { 928 if (baudrate > 75 && baudrate < 230400) {
938 /* get the divisor */ 929 /* get the divisor */
939 custom = (__u16)(230400L / baudrate); 930 custom = (__u16)(230400L / baudrate);
@@ -945,7 +936,7 @@ static int calc_baud_rate_divisor(int baudrate, int *divisor)
945 custom++; 936 custom++;
946 *divisor = custom; 937 *divisor = custom;
947 938
948 dbg("Baud %d = %d",baudrate, custom); 939 dbg("Baud %d = %d", baudrate, custom);
949 return 0; 940 return 0;
950 } 941 }
951 942
@@ -979,29 +970,29 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
979 number = port->number - port->serial->minor; 970 number = port->number - port->serial->minor;
980 dbg("%s - port = %d, baud = %d", __func__, port->number, baudrate); 971 dbg("%s - port = %d, baud = %d", __func__, port->number, baudrate);
981 972
982 /* Calculate the Divisor */ 973 /* Calculate the Divisor */
983 status = calc_baud_rate_divisor(baudrate, &divisor); 974 status = calc_baud_rate_divisor(baudrate, &divisor);
984 if (status) { 975 if (status) {
985 err("%s - bad baud rate", __func__); 976 err("%s - bad baud rate", __func__);
986 return status; 977 return status;
987 } 978 }
988 979
989 /* Enable access to divisor latch */ 980 /* Enable access to divisor latch */
990 data = mos7720_port->shadowLCR | UART_LCR_DLAB; 981 data = mos7720_port->shadowLCR | UART_LCR_DLAB;
991 mos7720_port->shadowLCR = data; 982 mos7720_port->shadowLCR = data;
992 send_mos_cmd(serial, MOS_WRITE, number, UART_LCR, &data); 983 send_mos_cmd(serial, MOS_WRITE, number, UART_LCR, &data);
993 984
994 /* Write the divisor */ 985 /* Write the divisor */
995 data = ((unsigned char)(divisor & 0xff)); 986 data = ((unsigned char)(divisor & 0xff));
996 send_mos_cmd(serial, MOS_WRITE, number, 0x00, &data); 987 send_mos_cmd(serial, MOS_WRITE, number, 0x00, &data);
997 988
998 data = ((unsigned char)((divisor & 0xff00) >> 8)); 989 data = ((unsigned char)((divisor & 0xff00) >> 8));
999 send_mos_cmd(serial, MOS_WRITE, number, 0x01, &data); 990 send_mos_cmd(serial, MOS_WRITE, number, 0x01, &data);
1000 991
1001 /* Disable access to divisor latch */ 992 /* Disable access to divisor latch */
1002 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB; 993 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
1003 mos7720_port->shadowLCR = data; 994 mos7720_port->shadowLCR = data;
1004 send_mos_cmd(serial, MOS_WRITE, number, 0x03, &data); 995 send_mos_cmd(serial, MOS_WRITE, number, 0x03, &data);
1005 996
1006 return status; 997 return status;
1007} 998}
@@ -1011,12 +1002,12 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1011 * This routine is called to set the UART on the device to match 1002 * This routine is called to set the UART on the device to match
1012 * the specified new settings. 1003 * the specified new settings.
1013 */ 1004 */
1014static void change_port_settings(struct moschip_port *mos7720_port, 1005static void change_port_settings(struct tty_struct *tty,
1006 struct moschip_port *mos7720_port,
1015 struct ktermios *old_termios) 1007 struct ktermios *old_termios)
1016{ 1008{
1017 struct usb_serial_port *port; 1009 struct usb_serial_port *port;
1018 struct usb_serial *serial; 1010 struct usb_serial *serial;
1019 struct tty_struct *tty;
1020 int baud; 1011 int baud;
1021 unsigned cflag; 1012 unsigned cflag;
1022 unsigned iflag; 1013 unsigned iflag;
@@ -1042,8 +1033,6 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1042 return; 1033 return;
1043 } 1034 }
1044 1035
1045 tty = mos7720_port->port->tty;
1046
1047 dbg("%s: Entering ..........", __func__); 1036 dbg("%s: Entering ..........", __func__);
1048 1037
1049 lData = UART_LCR_WLEN8; 1038 lData = UART_LCR_WLEN8;
@@ -1106,29 +1095,31 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1106#define LCR_PAR_MASK 0x38 /* Mask for parity field */ 1095#define LCR_PAR_MASK 0x38 /* Mask for parity field */
1107 1096
1108 /* Update the LCR with the correct value */ 1097 /* Update the LCR with the correct value */
1109 mos7720_port->shadowLCR &= ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); 1098 mos7720_port->shadowLCR &=
1099 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1110 mos7720_port->shadowLCR |= (lData | lParity | lStop); 1100 mos7720_port->shadowLCR |= (lData | lParity | lStop);
1111 1101
1112 1102
1113 /* Disable Interrupts */ 1103 /* Disable Interrupts */
1114 data = 0x00; 1104 data = 0x00;
1115 send_mos_cmd(serial,MOS_WRITE,port->number - port->serial->minor, UART_IER, &data); 1105 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
1106 UART_IER, &data);
1116 1107
1117 data = 0x00; 1108 data = 0x00;
1118 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data); 1109 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1119 1110
1120 data = 0xcf; 1111 data = 0xcf;
1121 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data); 1112 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1122 1113
1123 /* Send the updated LCR value to the mos7720 */ 1114 /* Send the updated LCR value to the mos7720 */
1124 data = mos7720_port->shadowLCR; 1115 data = mos7720_port->shadowLCR;
1125 send_mos_cmd(serial, MOS_WRITE, port_number, UART_LCR, &data); 1116 send_mos_cmd(serial, MOS_WRITE, port_number, UART_LCR, &data);
1126 1117
1127 data = 0x00b; 1118 data = 0x00b;
1128 mos7720_port->shadowMCR = data; 1119 mos7720_port->shadowMCR = data;
1129 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 1120 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1130 data = 0x00b; 1121 data = 0x00b;
1131 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data); 1122 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1132 1123
1133 /* set up the MCR register and send it to the mos7720 */ 1124 /* set up the MCR register and send it to the mos7720 */
1134 mos7720_port->shadowMCR = UART_MCR_OUT2; 1125 mos7720_port->shadowMCR = UART_MCR_OUT2;
@@ -1137,9 +1128,8 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1137 1128
1138 if (cflag & CRTSCTS) { 1129 if (cflag & CRTSCTS) {
1139 mos7720_port->shadowMCR |= (UART_MCR_XONANY); 1130 mos7720_port->shadowMCR |= (UART_MCR_XONANY);
1140 1131 /* To set hardware flow control to the specified *
1141 /* To set hardware flow control to the specified * 1132 * serial port, in SP1/2_CONTROL_REG */
1142 * serial port, in SP1/2_CONTROL_REG */
1143 if (port->number) { 1133 if (port->number) {
1144 data = 0x001; 1134 data = 0x001;
1145 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 1135 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT,
@@ -1198,14 +1188,13 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1198 * this function is called by the tty driver when it wants to change the 1188 * this function is called by the tty driver when it wants to change the
1199 * termios structure. 1189 * termios structure.
1200 */ 1190 */
1201static void mos7720_set_termios(struct usb_serial_port *port, 1191static void mos7720_set_termios(struct tty_struct *tty,
1202 struct ktermios *old_termios) 1192 struct usb_serial_port *port, struct ktermios *old_termios)
1203{ 1193{
1204 int status; 1194 int status;
1205 unsigned int cflag; 1195 unsigned int cflag;
1206 struct usb_serial *serial; 1196 struct usb_serial *serial;
1207 struct moschip_port *mos7720_port; 1197 struct moschip_port *mos7720_port;
1208 struct tty_struct *tty;
1209 1198
1210 serial = port->serial; 1199 serial = port->serial;
1211 1200
@@ -1214,15 +1203,12 @@ static void mos7720_set_termios(struct usb_serial_port *port,
1214 if (mos7720_port == NULL) 1203 if (mos7720_port == NULL)
1215 return; 1204 return;
1216 1205
1217 tty = port->tty;
1218
1219
1220 if (!mos7720_port->open) { 1206 if (!mos7720_port->open) {
1221 dbg("%s - port not opened", __func__); 1207 dbg("%s - port not opened", __func__);
1222 return; 1208 return;
1223 } 1209 }
1224 1210
1225 dbg("%s\n","setting termios - ASPIRE"); 1211 dbg("%s\n", "setting termios - ASPIRE");
1226 1212
1227 cflag = tty->termios->c_cflag; 1213 cflag = tty->termios->c_cflag;
1228 1214
@@ -1237,14 +1223,14 @@ static void mos7720_set_termios(struct usb_serial_port *port,
1237 dbg("%s - port %d", __func__, port->number); 1223 dbg("%s - port %d", __func__, port->number);
1238 1224
1239 /* change the port settings to the new ones specified */ 1225 /* change the port settings to the new ones specified */
1240 change_port_settings(mos7720_port, old_termios); 1226 change_port_settings(tty, mos7720_port, old_termios);
1241 1227
1242 if(!port->read_urb) { 1228 if (!port->read_urb) {
1243 dbg("%s","URB KILLED !!!!!\n"); 1229 dbg("%s", "URB KILLED !!!!!\n");
1244 return; 1230 return;
1245 } 1231 }
1246 1232
1247 if(port->read_urb->status != -EINPROGRESS) { 1233 if (port->read_urb->status != -EINPROGRESS) {
1248 port->read_urb->dev = serial->dev; 1234 port->read_urb->dev = serial->dev;
1249 status = usb_submit_urb(port->read_urb, GFP_ATOMIC); 1235 status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1250 if (status) 1236 if (status)
@@ -1264,13 +1250,13 @@ static void mos7720_set_termios(struct usb_serial_port *port,
1264 * transmit holding register is empty. This functionality 1250 * transmit holding register is empty. This functionality
1265 * allows an RS485 driver to be written in user space. 1251 * allows an RS485 driver to be written in user space.
1266 */ 1252 */
1267static int get_lsr_info(struct moschip_port *mos7720_port, 1253static int get_lsr_info(struct tty_struct *tty,
1268 unsigned int __user *value) 1254 struct moschip_port *mos7720_port, unsigned int __user *value)
1269{ 1255{
1270 int count; 1256 int count;
1271 unsigned int result = 0; 1257 unsigned int result = 0;
1272 1258
1273 count = mos7720_chars_in_buffer(mos7720_port->port); 1259 count = mos7720_chars_in_buffer(tty);
1274 if (count == 0) { 1260 if (count == 0) {
1275 dbg("%s -- Empty", __func__); 1261 dbg("%s -- Empty", __func__);
1276 result = TIOCSER_TEMT; 1262 result = TIOCSER_TEMT;
@@ -1290,7 +1276,7 @@ static int get_number_bytes_avail(struct moschip_port *mos7720_port,
1290 unsigned int __user *value) 1276 unsigned int __user *value)
1291{ 1277{
1292 unsigned int result = 0; 1278 unsigned int result = 0;
1293 struct tty_struct *tty = mos7720_port->port->tty; 1279 struct tty_struct *tty = mos7720_port->port->port.tty;
1294 1280
1295 if (!tty) 1281 if (!tty)
1296 return -ENOIOCTLCMD; 1282 return -ENOIOCTLCMD;
@@ -1316,7 +1302,7 @@ static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1316 if (mos7720_port == NULL) 1302 if (mos7720_port == NULL)
1317 return -1; 1303 return -1;
1318 1304
1319 port = (struct usb_serial_port*)mos7720_port->port; 1305 port = (struct usb_serial_port *)mos7720_port->port;
1320 mcr = mos7720_port->shadowMCR; 1306 mcr = mos7720_port->shadowMCR;
1321 1307
1322 if (copy_from_user(&arg, value, sizeof(int))) 1308 if (copy_from_user(&arg, value, sizeof(int)))
@@ -1397,7 +1383,7 @@ static int get_serial_info(struct moschip_port *mos7720_port,
1397 tmp.port = mos7720_port->port->number; 1383 tmp.port = mos7720_port->port->number;
1398 tmp.irq = 0; 1384 tmp.irq = 0;
1399 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; 1385 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1400 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; 1386 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1401 tmp.baud_base = 9600; 1387 tmp.baud_base = 9600;
1402 tmp.close_delay = 5*HZ; 1388 tmp.close_delay = 5*HZ;
1403 tmp.closing_wait = 30*HZ; 1389 tmp.closing_wait = 30*HZ;
@@ -1407,9 +1393,10 @@ static int get_serial_info(struct moschip_port *mos7720_port,
1407 return 0; 1393 return 0;
1408} 1394}
1409 1395
1410static int mos7720_ioctl(struct usb_serial_port *port, struct file *file, 1396static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
1411 unsigned int cmd, unsigned long arg) 1397 unsigned int cmd, unsigned long arg)
1412{ 1398{
1399 struct usb_serial_port *port = tty->driver_data;
1413 struct moschip_port *mos7720_port; 1400 struct moschip_port *mos7720_port;
1414 struct async_icount cnow; 1401 struct async_icount cnow;
1415 struct async_icount cprev; 1402 struct async_icount cprev;
@@ -1431,14 +1418,16 @@ static int mos7720_ioctl(struct usb_serial_port *port, struct file *file,
1431 1418
1432 case TIOCSERGETLSR: 1419 case TIOCSERGETLSR:
1433 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); 1420 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1434 return get_lsr_info(mos7720_port, (unsigned int __user *)arg); 1421 return get_lsr_info(tty, mos7720_port,
1422 (unsigned int __user *)arg);
1435 return 0; 1423 return 0;
1436 1424
1425 /* FIXME: These should be using the mode methods */
1437 case TIOCMBIS: 1426 case TIOCMBIS:
1438 case TIOCMBIC: 1427 case TIOCMBIC:
1439 case TIOCMSET: 1428 case TIOCMSET:
1440 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __func__, 1429 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET",
1441 port->number); 1430 __func__, port->number);
1442 return set_modem_info(mos7720_port, cmd, 1431 return set_modem_info(mos7720_port, cmd,
1443 (unsigned int __user *)arg); 1432 (unsigned int __user *)arg);
1444 1433
@@ -1452,10 +1441,6 @@ static int mos7720_ioctl(struct usb_serial_port *port, struct file *file,
1452 return get_serial_info(mos7720_port, 1441 return get_serial_info(mos7720_port,
1453 (struct serial_struct __user *)arg); 1442 (struct serial_struct __user *)arg);
1454 1443
1455 case TIOCSSERIAL:
1456 dbg("%s (%d) TIOCSSERIAL", __func__, port->number);
1457 break;
1458
1459 case TIOCMIWAIT: 1444 case TIOCMIWAIT:
1460 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 1445 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1461 cprev = mos7720_port->icount; 1446 cprev = mos7720_port->icount;
@@ -1469,7 +1454,7 @@ static int mos7720_ioctl(struct usb_serial_port *port, struct file *file,
1469 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || 1454 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1470 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || 1455 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1471 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || 1456 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1472 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) { 1457 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1473 return 0; 1458 return 0;
1474 } 1459 }
1475 cprev = cnow; 1460 cprev = cnow;
@@ -1492,7 +1477,7 @@ static int mos7720_ioctl(struct usb_serial_port *port, struct file *file,
1492 icount.buf_overrun = cnow.buf_overrun; 1477 icount.buf_overrun = cnow.buf_overrun;
1493 1478
1494 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, 1479 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
1495 port->number, icount.rx, icount.tx ); 1480 port->number, icount.rx, icount.tx);
1496 if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) 1481 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1497 return -EFAULT; 1482 return -EFAULT;
1498 return 0; 1483 return 0;
@@ -1543,7 +1528,8 @@ static int mos7720_startup(struct usb_serial *serial)
1543 /* Initialize all port interrupt end point to port 0 int 1528 /* Initialize all port interrupt end point to port 0 int
1544 * endpoint. Our device has only one interrupt endpoint 1529 * endpoint. Our device has only one interrupt endpoint
1545 * comman to all ports */ 1530 * comman to all ports */
1546 serial->port[i]->interrupt_in_endpointAddress = serial->port[0]->interrupt_in_endpointAddress; 1531 serial->port[i]->interrupt_in_endpointAddress =
1532 serial->port[0]->interrupt_in_endpointAddress;
1547 1533
1548 mos7720_port->port = serial->port[i]; 1534 mos7720_port->port = serial->port[i];
1549 usb_set_serial_port_data(serial->port[i], mos7720_port); 1535 usb_set_serial_port_data(serial->port[i], mos7720_port);
@@ -1555,13 +1541,15 @@ static int mos7720_startup(struct usb_serial *serial)
1555 1541
1556 /* setting configuration feature to one */ 1542 /* setting configuration feature to one */
1557 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 1543 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1558 (__u8)0x03, 0x00,0x01,0x00, NULL, 0x00, 5*HZ); 1544 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5*HZ);
1559 1545
1560 send_mos_cmd(serial,MOS_READ,0x00, UART_LSR, &data); // LSR For Port 1 1546 /* LSR For Port 1 */
1561 dbg("LSR:%x",data); 1547 send_mos_cmd(serial, MOS_READ, 0x00, UART_LSR, &data);
1548 dbg("LSR:%x", data);
1562 1549
1563 send_mos_cmd(serial,MOS_READ,0x01, UART_LSR, &data); // LSR For Port 2 1550 /* LSR For Port 2 */
1564 dbg("LSR:%x",data); 1551 send_mos_cmd(serial, MOS_READ, 0x01, UART_LSR, &data);
1552 dbg("LSR:%x", data);
1565 1553
1566 return 0; 1554 return 0;
1567} 1555}
@@ -1571,7 +1559,7 @@ static void mos7720_shutdown(struct usb_serial *serial)
1571 int i; 1559 int i;
1572 1560
1573 /* free private structure allocated for serial port */ 1561 /* free private structure allocated for serial port */
1574 for (i=0; i < serial->num_ports; ++i) { 1562 for (i = 0; i < serial->num_ports; ++i) {
1575 kfree(usb_get_serial_port_data(serial->port[i])); 1563 kfree(usb_get_serial_port_data(serial->port[i]));
1576 usb_set_serial_port_data(serial->port[i], NULL); 1564 usb_set_serial_port_data(serial->port[i], NULL);
1577 } 1565 }
@@ -1651,8 +1639,8 @@ module_init(moschip7720_init);
1651module_exit(moschip7720_exit); 1639module_exit(moschip7720_exit);
1652 1640
1653/* Module information */ 1641/* Module information */
1654MODULE_AUTHOR( DRIVER_AUTHOR ); 1642MODULE_AUTHOR(DRIVER_AUTHOR);
1655MODULE_DESCRIPTION( DRIVER_DESC ); 1643MODULE_DESCRIPTION(DRIVER_DESC);
1656MODULE_LICENSE("GPL"); 1644MODULE_LICENSE("GPL");
1657 1645
1658module_param(debug, bool, S_IRUGO | S_IWUSR); 1646module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 78f2f6db494d..09d82062b973 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -33,7 +33,7 @@
33#include <linux/serial.h> 33#include <linux/serial.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb/serial.h> 35#include <linux/usb/serial.h>
36#include <asm/uaccess.h> 36#include <linux/uaccess.h>
37 37
38/* 38/*
39 * Version Information 39 * Version Information
@@ -82,8 +82,8 @@
82 * Defines used for sending commands to port 82 * Defines used for sending commands to port
83 */ 83 */
84 84
85#define WAIT_FOR_EVER (HZ * 0 ) /* timeout urb is wait for ever */ 85#define WAIT_FOR_EVER (HZ * 0) /* timeout urb is wait for ever */
86#define MOS_WDR_TIMEOUT (HZ * 5 ) /* default urb timeout */ 86#define MOS_WDR_TIMEOUT (HZ * 5) /* default urb timeout */
87 87
88#define MOS_PORT1 0x0200 88#define MOS_PORT1 0x0200
89#define MOS_PORT2 0x0300 89#define MOS_PORT2 0x0300
@@ -102,8 +102,8 @@
102 102
103#define MAX_NAME_LEN 64 103#define MAX_NAME_LEN 64
104 104
105#define ZLP_REG1 0x3A //Zero_Flag_Reg1 58 105#define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */
106#define ZLP_REG5 0x3E //Zero_Flag_Reg5 62 106#define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */
107 107
108/* For higher baud Rates use TIOCEXBAUD */ 108/* For higher baud Rates use TIOCEXBAUD */
109#define TIOCEXBAUD 0x5462 109#define TIOCEXBAUD 0x5462
@@ -142,7 +142,7 @@
142#define MOS_MSR_DELTA_RI 0x40 142#define MOS_MSR_DELTA_RI 0x40
143#define MOS_MSR_DELTA_CD 0x80 143#define MOS_MSR_DELTA_CD 0x80
144 144
145// Serial Port register Address 145/* Serial Port register Address */
146#define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01)) 146#define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01))
147#define FIFO_CONTROL_REGISTER ((__u16)(0x02)) 147#define FIFO_CONTROL_REGISTER ((__u16)(0x02))
148#define LINE_CONTROL_REGISTER ((__u16)(0x03)) 148#define LINE_CONTROL_REGISTER ((__u16)(0x03))
@@ -201,11 +201,11 @@ struct moschip_port {
201 struct async_icount icount; 201 struct async_icount icount;
202 struct usb_serial_port *port; /* loop back to the owner of this object */ 202 struct usb_serial_port *port; /* loop back to the owner of this object */
203 203
204 /*Offsets */ 204 /* Offsets */
205 __u8 SpRegOffset; 205 __u8 SpRegOffset;
206 __u8 ControlRegOffset; 206 __u8 ControlRegOffset;
207 __u8 DcrRegOffset; 207 __u8 DcrRegOffset;
208 //for processing control URBS in interrupt context 208 /* for processing control URBS in interrupt context */
209 struct urb *control_urb; 209 struct urb *control_urb;
210 struct usb_ctrlrequest *dr; 210 struct usb_ctrlrequest *dr;
211 char *ctrl_buf; 211 char *ctrl_buf;
@@ -244,7 +244,7 @@ static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg,
244 */ 244 */
245 245
246static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg, 246static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
247 __u16 * val) 247 __u16 *val)
248{ 248{
249 struct usb_device *dev = port->serial->dev; 249 struct usb_device *dev = port->serial->dev;
250 int ret = 0; 250 int ret = 0;
@@ -269,16 +269,15 @@ static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
269 269
270 struct usb_device *dev = port->serial->dev; 270 struct usb_device *dev = port->serial->dev;
271 val = val & 0x00ff; 271 val = val & 0x00ff;
272 // For the UART control registers, the application number need to be Or'ed 272 /* For the UART control registers, the application number need
273 to be Or'ed */
273 if (port->serial->num_ports == 4) { 274 if (port->serial->num_ports == 4) {
274 val |= 275 val |= (((__u16) port->number -
275 (((__u16) port->number - (__u16) (port->serial->minor)) + 276 (__u16) (port->serial->minor)) + 1) << 8;
276 1) << 8;
277 dbg("mos7840_set_uart_reg application number is %x\n", val); 277 dbg("mos7840_set_uart_reg application number is %x\n", val);
278 } else { 278 } else {
279 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { 279 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
280 val |= 280 val |= (((__u16) port->number -
281 (((__u16) port->number -
282 (__u16) (port->serial->minor)) + 1) << 8; 281 (__u16) (port->serial->minor)) + 1) << 8;
283 dbg("mos7840_set_uart_reg application number is %x\n", 282 dbg("mos7840_set_uart_reg application number is %x\n",
284 val); 283 val);
@@ -302,14 +301,15 @@ static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
302 * by passing usb_rcvctrlpipe function as parameter. 301 * by passing usb_rcvctrlpipe function as parameter.
303 */ 302 */
304static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg, 303static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
305 __u16 * val) 304 __u16 *val)
306{ 305{
307 struct usb_device *dev = port->serial->dev; 306 struct usb_device *dev = port->serial->dev;
308 int ret = 0; 307 int ret = 0;
309 __u16 Wval; 308 __u16 Wval;
310 309
311 //dbg("application number is %4x \n",(((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); 310 /* dbg("application number is %4x \n",
312 /*Wval is same as application number */ 311 (((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); */
312 /* Wval is same as application number */
313 if (port->serial->num_ports == 4) { 313 if (port->serial->num_ports == 4) {
314 Wval = 314 Wval =
315 (((__u16) port->number - (__u16) (port->serial->minor)) + 315 (((__u16) port->number - (__u16) (port->serial->minor)) +
@@ -317,14 +317,12 @@ static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
317 dbg("mos7840_get_uart_reg application number is %x\n", Wval); 317 dbg("mos7840_get_uart_reg application number is %x\n", Wval);
318 } else { 318 } else {
319 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { 319 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
320 Wval = 320 Wval = (((__u16) port->number -
321 (((__u16) port->number -
322 (__u16) (port->serial->minor)) + 1) << 8; 321 (__u16) (port->serial->minor)) + 1) << 8;
323 dbg("mos7840_get_uart_reg application number is %x\n", 322 dbg("mos7840_get_uart_reg application number is %x\n",
324 Wval); 323 Wval);
325 } else { 324 } else {
326 Wval = 325 Wval = (((__u16) port->number -
327 (((__u16) port->number -
328 (__u16) (port->serial->minor)) + 2) << 8; 326 (__u16) (port->serial->minor)) + 2) << 8;
329 dbg("mos7840_get_uart_reg application number is %x\n", 327 dbg("mos7840_get_uart_reg application number is %x\n",
330 Wval); 328 Wval);
@@ -406,11 +404,11 @@ static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
406 dbg("%s - %02x", __func__, new_lsr); 404 dbg("%s - %02x", __func__, new_lsr);
407 405
408 if (new_lsr & SERIAL_LSR_BI) { 406 if (new_lsr & SERIAL_LSR_BI) {
409 // 407 /*
410 // Parity and Framing errors only count if they 408 * Parity and Framing errors only count if they
411 // occur exclusive of a break being 409 * occur exclusive of a break being
412 // received. 410 * received.
413 // 411 */
414 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI); 412 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
415 } 413 }
416 414
@@ -492,7 +490,7 @@ exit:
492} 490}
493 491
494static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, 492static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
495 __u16 * val) 493 __u16 *val)
496{ 494{
497 struct usb_device *dev = mcs->port->serial->dev; 495 struct usb_device *dev = mcs->port->serial->dev;
498 struct usb_ctrlrequest *dr = mcs->dr; 496 struct usb_ctrlrequest *dr = mcs->dr;
@@ -501,7 +499,7 @@ static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
501 499
502 dr->bRequestType = MCS_RD_RTYPE; 500 dr->bRequestType = MCS_RD_RTYPE;
503 dr->bRequest = MCS_RDREQ; 501 dr->bRequest = MCS_RDREQ;
504 dr->wValue = cpu_to_le16(Wval); //0; 502 dr->wValue = cpu_to_le16(Wval); /* 0 */
505 dr->wIndex = cpu_to_le16(reg); 503 dr->wIndex = cpu_to_le16(reg);
506 dr->wLength = cpu_to_le16(2); 504 dr->wLength = cpu_to_le16(2);
507 505
@@ -607,7 +605,8 @@ static void mos7840_interrupt_callback(struct urb *urb)
607 } 605 }
608 } 606 }
609 } 607 }
610 if (!(rv < 0)) /* the completion handler for the control urb will resubmit */ 608 if (!(rv < 0))
609 /* the completion handler for the control urb will resubmit */
611 return; 610 return;
612exit: 611exit:
613 result = usb_submit_urb(urb, GFP_ATOMIC); 612 result = usb_submit_urb(urb, GFP_ATOMIC);
@@ -656,8 +655,8 @@ static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port,
656 if (!port || 655 if (!port ||
657 mos7840_port_paranoia_check(port, function) || 656 mos7840_port_paranoia_check(port, function) ||
658 mos7840_serial_paranoia_check(port->serial, function)) { 657 mos7840_serial_paranoia_check(port->serial, function)) {
659 /* then say that we don't have a valid usb_serial thing, which will 658 /* then say that we don't have a valid usb_serial thing,
660 * end up genrating -ENODEV return values */ 659 * which will end up genrating -ENODEV return values */
661 return NULL; 660 return NULL;
662 } 661 }
663 662
@@ -710,7 +709,7 @@ static void mos7840_bulk_in_callback(struct urb *urb)
710 dbg("%s", "Entering ........... \n"); 709 dbg("%s", "Entering ........... \n");
711 710
712 if (urb->actual_length) { 711 if (urb->actual_length) {
713 tty = mos7840_port->port->tty; 712 tty = mos7840_port->port->port.tty;
714 if (tty) { 713 if (tty) {
715 tty_buffer_request_room(tty, urb->actual_length); 714 tty_buffer_request_room(tty, urb->actual_length);
716 tty_insert_flip_string(tty, data, urb->actual_length); 715 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -741,8 +740,8 @@ static void mos7840_bulk_in_callback(struct urb *urb)
741 740
742/***************************************************************************** 741/*****************************************************************************
743 * mos7840_bulk_out_data_callback 742 * mos7840_bulk_out_data_callback
744 * this is the callback function for when we have finished sending serial data 743 * this is the callback function for when we have finished sending
745 * on the bulk out endpoint. 744 * serial data on the bulk out endpoint.
746 *****************************************************************************/ 745 *****************************************************************************/
747 746
748static void mos7840_bulk_out_data_callback(struct urb *urb) 747static void mos7840_bulk_out_data_callback(struct urb *urb)
@@ -774,7 +773,7 @@ static void mos7840_bulk_out_data_callback(struct urb *urb)
774 773
775 dbg("%s \n", "Entering ........."); 774 dbg("%s \n", "Entering .........");
776 775
777 tty = mos7840_port->port->tty; 776 tty = mos7840_port->port->port.tty;
778 777
779 if (tty && mos7840_port->open) 778 if (tty && mos7840_port->open)
780 tty_wakeup(tty); 779 tty_wakeup(tty);
@@ -804,7 +803,8 @@ static int mos7840_serial_probe(struct usb_serial *serial,
804 * Otherwise we return a negative error number. 803 * Otherwise we return a negative error number.
805 *****************************************************************************/ 804 *****************************************************************************/
806 805
807static int mos7840_open(struct usb_serial_port *port, struct file *filp) 806static int mos7840_open(struct tty_struct *tty,
807 struct usb_serial_port *port, struct file *filp)
808{ 808{
809 int response; 809 int response;
810 int j; 810 int j;
@@ -847,7 +847,8 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
847 continue; 847 continue;
848 } 848 }
849 849
850 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 850 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
851 GFP_KERNEL);
851 if (!urb->transfer_buffer) { 852 if (!urb->transfer_buffer) {
852 usb_free_urb(urb); 853 usb_free_urb(urb);
853 mos7840_port->write_urb_pool[j] = NULL; 854 mos7840_port->write_urb_pool[j] = NULL;
@@ -868,9 +869,8 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
868 * 0x08 : SP1/2 Control Reg 869 * 0x08 : SP1/2 Control Reg
869 *****************************************************************************/ 870 *****************************************************************************/
870 871
871//NEED to check the following Block 872 /* NEED to check the following Block */
872 873
873 status = 0;
874 Data = 0x0; 874 Data = 0x0;
875 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 875 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
876 if (status < 0) { 876 if (status < 0) {
@@ -890,36 +890,35 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
890 dbg("writing Spreg failed\n"); 890 dbg("writing Spreg failed\n");
891 return -1; 891 return -1;
892 } 892 }
893//End of block to be checked 893 /* End of block to be checked */
894 894
895 status = 0;
896 Data = 0x0; 895 Data = 0x0;
897 status = 896 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
898 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data); 897 &Data);
899 if (status < 0) { 898 if (status < 0) {
900 dbg("Reading Controlreg failed\n"); 899 dbg("Reading Controlreg failed\n");
901 return -1; 900 return -1;
902 } 901 }
903 Data |= 0x08; //Driver done bit 902 Data |= 0x08; /* Driver done bit */
904 Data |= 0x20; //rx_disable 903 Data |= 0x20; /* rx_disable */
905 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data); 904 status = mos7840_set_reg_sync(port,
905 mos7840_port->ControlRegOffset, Data);
906 if (status < 0) { 906 if (status < 0) {
907 dbg("writing Controlreg failed\n"); 907 dbg("writing Controlreg failed\n");
908 return -1; 908 return -1;
909 } 909 }
910 //do register settings here 910 /* do register settings here */
911 // Set all regs to the device default values. 911 /* Set all regs to the device default values. */
912 //////////////////////////////////// 912 /***********************************
913 // First Disable all interrupts. 913 * First Disable all interrupts.
914 //////////////////////////////////// 914 ***********************************/
915
916 Data = 0x00; 915 Data = 0x00;
917 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 916 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
918 if (status < 0) { 917 if (status < 0) {
919 dbg("disableing interrupts failed\n"); 918 dbg("disableing interrupts failed\n");
920 return -1; 919 return -1;
921 } 920 }
922 // Set FIFO_CONTROL_REGISTER to the default value 921 /* Set FIFO_CONTROL_REGISTER to the default value */
923 Data = 0x00; 922 Data = 0x00;
924 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 923 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
925 if (status < 0) { 924 if (status < 0) {
@@ -946,90 +945,73 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
946 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 945 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
947 mos7840_port->shadowLCR = Data; 946 mos7840_port->shadowLCR = Data;
948 947
949 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 948 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
950 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 949 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
951 950
952 Data = 0x0c; 951 Data = 0x0c;
953 status = 0;
954 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); 952 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
955 953
956 Data = 0x0; 954 Data = 0x0;
957 status = 0;
958 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); 955 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
959 956
960 Data = 0x00; 957 Data = 0x00;
961 status = 0;
962 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 958 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
963 959
964 Data = Data & ~SERIAL_LCR_DLAB; 960 Data = Data & ~SERIAL_LCR_DLAB;
965 status = 0;
966 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 961 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
967 mos7840_port->shadowLCR = Data; 962 mos7840_port->shadowLCR = Data;
968 963
969 //clearing Bulkin and Bulkout Fifo 964 /* clearing Bulkin and Bulkout Fifo */
970 Data = 0x0; 965 Data = 0x0;
971 status = 0;
972 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 966 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
973 967
974 Data = Data | 0x0c; 968 Data = Data | 0x0c;
975 status = 0;
976 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 969 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
977 970
978 Data = Data & ~0x0c; 971 Data = Data & ~0x0c;
979 status = 0;
980 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 972 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
981 //Finally enable all interrupts 973 /* Finally enable all interrupts */
982 Data = 0x0;
983 Data = 0x0c; 974 Data = 0x0c;
984 status = 0;
985 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 975 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
986 976
987 //clearing rx_disable 977 /* clearing rx_disable */
988 Data = 0x0; 978 Data = 0x0;
989 status = 0; 979 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
990 status = 980 &Data);
991 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
992 Data = Data & ~0x20; 981 Data = Data & ~0x20;
993 status = 0; 982 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
994 status = 983 Data);
995 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
996 984
997 // rx_negate 985 /* rx_negate */
998 Data = 0x0; 986 Data = 0x0;
999 status = 0; 987 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1000 status = 988 &Data);
1001 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
1002 Data = Data | 0x10; 989 Data = Data | 0x10;
1003 status = 0; 990 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1004 status = 991 Data);
1005 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
1006 992
1007 /* force low_latency on so that our tty_push actually forces * 993 /* force low_latency on so that our tty_push actually forces *
1008 * the data through,otherwise it is scheduled, and with * 994 * the data through,otherwise it is scheduled, and with *
1009 * high data rates (like with OHCI) data can get lost. */ 995 * high data rates (like with OHCI) data can get lost. */
996 if (tty)
997 tty->low_latency = 1;
1010 998
1011 if (port->tty) 999 /* Check to see if we've set up our endpoint info yet *
1012 port->tty->low_latency = 1; 1000 * (can't set it up in mos7840_startup as the structures *
1013/* Check to see if we've set up our endpoint info yet * 1001 * were not set up at that time.) */
1014 * (can't set it up in mos7840_startup as the structures *
1015 * were not set up at that time.) */
1016 if (port0->open_ports == 1) { 1002 if (port0->open_ports == 1) {
1017 if (serial->port[0]->interrupt_in_buffer == NULL) { 1003 if (serial->port[0]->interrupt_in_buffer == NULL) {
1018
1019 /* set up interrupt urb */ 1004 /* set up interrupt urb */
1020
1021 usb_fill_int_urb(serial->port[0]->interrupt_in_urb, 1005 usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
1022 serial->dev, 1006 serial->dev,
1023 usb_rcvintpipe(serial->dev, 1007 usb_rcvintpipe(serial->dev,
1024 serial->port[0]-> 1008 serial->port[0]->interrupt_in_endpointAddress),
1025 interrupt_in_endpointAddress), 1009 serial->port[0]->interrupt_in_buffer,
1026 serial->port[0]->interrupt_in_buffer, 1010 serial->port[0]->interrupt_in_urb->
1027 serial->port[0]->interrupt_in_urb-> 1011 transfer_buffer_length,
1028 transfer_buffer_length, 1012 mos7840_interrupt_callback,
1029 mos7840_interrupt_callback, 1013 serial,
1030 serial, 1014 serial->port[0]->interrupt_in_urb->interval);
1031 serial->port[0]->interrupt_in_urb->
1032 interval);
1033 1015
1034 /* start interrupt read for mos7840 * 1016 /* start interrupt read for mos7840 *
1035 * will continue as long as mos7840 is connected */ 1017 * will continue as long as mos7840 is connected */
@@ -1084,14 +1066,16 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
1084 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount)); 1066 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1085 1067
1086 /* initialize our port settings */ 1068 /* initialize our port settings */
1087 mos7840_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */ 1069 /* Must set to enable ints! */
1070 mos7840_port->shadowMCR = MCR_MASTER_IE;
1088 /* send a open port command */ 1071 /* send a open port command */
1089 mos7840_port->open = 1; 1072 mos7840_port->open = 1;
1090 //mos7840_change_port_settings(mos7840_port,old_termios); 1073 /* mos7840_change_port_settings(mos7840_port,old_termios); */
1091 mos7840_port->icount.tx = 0; 1074 mos7840_port->icount.tx = 0;
1092 mos7840_port->icount.rx = 0; 1075 mos7840_port->icount.rx = 0;
1093 1076
1094 dbg("\n\nusb_serial serial:%p mos7840_port:%p\n usb_serial_port port:%p\n\n", serial, mos7840_port, port); 1077 dbg("\n\nusb_serial serial:%p mos7840_port:%p\n usb_serial_port port:%p\n\n",
1078 serial, mos7840_port, port);
1095 1079
1096 return 0; 1080 return 0;
1097 1081
@@ -1104,11 +1088,12 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
1104 * been written, but hasn't made it out the port yet) 1088 * been written, but hasn't made it out the port yet)
1105 * If successful, we return the number of bytes left to be written in the 1089 * If successful, we return the number of bytes left to be written in the
1106 * system, 1090 * system,
1107 * Otherwise we return a negative error number. 1091 * Otherwise we return zero.
1108 *****************************************************************************/ 1092 *****************************************************************************/
1109 1093
1110static int mos7840_chars_in_buffer(struct usb_serial_port *port) 1094static int mos7840_chars_in_buffer(struct tty_struct *tty)
1111{ 1095{
1096 struct usb_serial_port *port = tty->driver_data;
1112 int i; 1097 int i;
1113 int chars = 0; 1098 int chars = 0;
1114 unsigned long flags; 1099 unsigned long flags;
@@ -1118,22 +1103,20 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port)
1118 1103
1119 if (mos7840_port_paranoia_check(port, __func__)) { 1104 if (mos7840_port_paranoia_check(port, __func__)) {
1120 dbg("%s", "Invalid port \n"); 1105 dbg("%s", "Invalid port \n");
1121 return -1; 1106 return 0;
1122 } 1107 }
1123 1108
1124 mos7840_port = mos7840_get_port_private(port); 1109 mos7840_port = mos7840_get_port_private(port);
1125 if (mos7840_port == NULL) { 1110 if (mos7840_port == NULL) {
1126 dbg("%s \n", "mos7840_break:leaving ..........."); 1111 dbg("%s \n", "mos7840_break:leaving ...........");
1127 return -1; 1112 return 0;
1128 } 1113 }
1129 1114
1130 spin_lock_irqsave(&mos7840_port->pool_lock,flags); 1115 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
1131 for (i = 0; i < NUM_URBS; ++i) { 1116 for (i = 0; i < NUM_URBS; ++i)
1132 if (mos7840_port->busy[i]) { 1117 if (mos7840_port->busy[i])
1133 chars += URB_TRANSFER_BUFFER_SIZE; 1118 chars += URB_TRANSFER_BUFFER_SIZE;
1134 } 1119 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
1135 }
1136 spin_unlock_irqrestore(&mos7840_port->pool_lock,flags);
1137 dbg("%s - returns %d", __func__, chars); 1120 dbg("%s - returns %d", __func__, chars);
1138 return chars; 1121 return chars;
1139 1122
@@ -1149,7 +1132,8 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port)
1149 * 3. A timeout of 3 seconds without activity has expired 1132 * 3. A timeout of 3 seconds without activity has expired
1150 * 1133 *
1151 ************************************************************************/ 1134 ************************************************************************/
1152static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port) 1135static void mos7840_block_until_tx_empty(struct tty_struct *tty,
1136 struct moschip_port *mos7840_port)
1153{ 1137{
1154 int timeout = HZ / 10; 1138 int timeout = HZ / 10;
1155 int wait = 30; 1139 int wait = 30;
@@ -1157,12 +1141,11 @@ static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
1157 1141
1158 while (1) { 1142 while (1) {
1159 1143
1160 count = mos7840_chars_in_buffer(mos7840_port->port); 1144 count = mos7840_chars_in_buffer(tty);
1161 1145
1162 /* Check for Buffer status */ 1146 /* Check for Buffer status */
1163 if (count <= 0) { 1147 if (count <= 0)
1164 return; 1148 return;
1165 }
1166 1149
1167 /* Block the thread for a while */ 1150 /* Block the thread for a while */
1168 interruptible_sleep_on_timeout(&mos7840_port->wait_chase, 1151 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
@@ -1185,7 +1168,8 @@ static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
1185 * this function is called by the tty driver when a port is closed 1168 * this function is called by the tty driver when a port is closed
1186 *****************************************************************************/ 1169 *****************************************************************************/
1187 1170
1188static void mos7840_close(struct usb_serial_port *port, struct file *filp) 1171static void mos7840_close(struct tty_struct *tty,
1172 struct usb_serial_port *port, struct file *filp)
1189{ 1173{
1190 struct usb_serial *serial; 1174 struct usb_serial *serial;
1191 struct moschip_port *mos7840_port; 1175 struct moschip_port *mos7840_port;
@@ -1226,32 +1210,28 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1226 } 1210 }
1227 } 1211 }
1228 1212
1229 if (serial->dev) { 1213 if (serial->dev)
1230 /* flush and block until tx is empty */ 1214 /* flush and block until tx is empty */
1231 mos7840_block_until_tx_empty(mos7840_port); 1215 mos7840_block_until_tx_empty(tty, mos7840_port);
1232 }
1233 1216
1234 /* While closing port, shutdown all bulk read, write * 1217 /* While closing port, shutdown all bulk read, write *
1235 * and interrupt read if they exists */ 1218 * and interrupt read if they exists */
1236 if (serial->dev) { 1219 if (serial->dev) {
1237
1238 if (mos7840_port->write_urb) { 1220 if (mos7840_port->write_urb) {
1239 dbg("%s", "Shutdown bulk write\n"); 1221 dbg("%s", "Shutdown bulk write\n");
1240 usb_kill_urb(mos7840_port->write_urb); 1222 usb_kill_urb(mos7840_port->write_urb);
1241 } 1223 }
1242
1243 if (mos7840_port->read_urb) { 1224 if (mos7840_port->read_urb) {
1244 dbg("%s", "Shutdown bulk read\n"); 1225 dbg("%s", "Shutdown bulk read\n");
1245 usb_kill_urb(mos7840_port->read_urb); 1226 usb_kill_urb(mos7840_port->read_urb);
1246 } 1227 }
1247 if ((&mos7840_port->control_urb)) { 1228 if ((&mos7840_port->control_urb)) {
1248 dbg("%s", "Shutdown control read\n"); 1229 dbg("%s", "Shutdown control read\n");
1249 // usb_kill_urb (mos7840_port->control_urb); 1230 /*/ usb_kill_urb (mos7840_port->control_urb); */
1250
1251 } 1231 }
1252 } 1232 }
1253// if(mos7840_port->ctrl_buf != NULL) 1233/* if(mos7840_port->ctrl_buf != NULL) */
1254// kfree(mos7840_port->ctrl_buf); 1234/* kfree(mos7840_port->ctrl_buf); */
1255 port0->open_ports--; 1235 port0->open_ports--;
1256 dbg("mos7840_num_open_ports in close%d:in port%d\n", 1236 dbg("mos7840_num_open_ports in close%d:in port%d\n",
1257 port0->open_ports, port->number); 1237 port0->open_ports, port->number);
@@ -1264,10 +1244,8 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1264 1244
1265 if (mos7840_port->write_urb) { 1245 if (mos7840_port->write_urb) {
1266 /* if this urb had a transfer buffer already (old tx) free it */ 1246 /* if this urb had a transfer buffer already (old tx) free it */
1267 1247 if (mos7840_port->write_urb->transfer_buffer != NULL)
1268 if (mos7840_port->write_urb->transfer_buffer != NULL) {
1269 kfree(mos7840_port->write_urb->transfer_buffer); 1248 kfree(mos7840_port->write_urb->transfer_buffer);
1270 }
1271 usb_free_urb(mos7840_port->write_urb); 1249 usb_free_urb(mos7840_port->write_urb);
1272 } 1250 }
1273 1251
@@ -1293,20 +1271,19 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1293 * 1271 *
1294 ************************************************************************/ 1272 ************************************************************************/
1295 1273
1296static void mos7840_block_until_chase_response(struct moschip_port 1274static void mos7840_block_until_chase_response(struct tty_struct *tty,
1297 *mos7840_port) 1275 struct moschip_port *mos7840_port)
1298{ 1276{
1299 int timeout = 1 * HZ; 1277 int timeout = 1 * HZ;
1300 int wait = 10; 1278 int wait = 10;
1301 int count; 1279 int count;
1302 1280
1303 while (1) { 1281 while (1) {
1304 count = mos7840_chars_in_buffer(mos7840_port->port); 1282 count = mos7840_chars_in_buffer(tty);
1305 1283
1306 /* Check for Buffer status */ 1284 /* Check for Buffer status */
1307 if (count <= 0) { 1285 if (count <= 0)
1308 return; 1286 return;
1309 }
1310 1287
1311 /* Block the thread for a while */ 1288 /* Block the thread for a while */
1312 interruptible_sleep_on_timeout(&mos7840_port->wait_chase, 1289 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
@@ -1328,8 +1305,9 @@ static void mos7840_block_until_chase_response(struct moschip_port
1328 * mos7840_break 1305 * mos7840_break
1329 * this function sends a break to the port 1306 * this function sends a break to the port
1330 *****************************************************************************/ 1307 *****************************************************************************/
1331static void mos7840_break(struct usb_serial_port *port, int break_state) 1308static void mos7840_break(struct tty_struct *tty, int break_state)
1332{ 1309{
1310 struct usb_serial_port *port = tty->driver_data;
1333 unsigned char data; 1311 unsigned char data;
1334 struct usb_serial *serial; 1312 struct usb_serial *serial;
1335 struct moschip_port *mos7840_port; 1313 struct moschip_port *mos7840_port;
@@ -1350,21 +1328,17 @@ static void mos7840_break(struct usb_serial_port *port, int break_state)
1350 1328
1351 mos7840_port = mos7840_get_port_private(port); 1329 mos7840_port = mos7840_get_port_private(port);
1352 1330
1353 if (mos7840_port == NULL) { 1331 if (mos7840_port == NULL)
1354 return; 1332 return;
1355 }
1356
1357 if (serial->dev) {
1358 1333
1334 if (serial->dev)
1359 /* flush and block until tx is empty */ 1335 /* flush and block until tx is empty */
1360 mos7840_block_until_chase_response(mos7840_port); 1336 mos7840_block_until_chase_response(tty, mos7840_port);
1361 }
1362 1337
1363 if (break_state == -1) { 1338 if (break_state == -1)
1364 data = mos7840_port->shadowLCR | LCR_SET_BREAK; 1339 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
1365 } else { 1340 else
1366 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK; 1341 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK;
1367 }
1368 1342
1369 mos7840_port->shadowLCR = data; 1343 mos7840_port->shadowLCR = data;
1370 dbg("mcs7840_break mos7840_port->shadowLCR is %x\n", 1344 dbg("mcs7840_break mos7840_port->shadowLCR is %x\n",
@@ -1383,8 +1357,9 @@ static void mos7840_break(struct usb_serial_port *port, int break_state)
1383 * Otherwise we return a negative error number. 1357 * Otherwise we return a negative error number.
1384 *****************************************************************************/ 1358 *****************************************************************************/
1385 1359
1386static int mos7840_write_room(struct usb_serial_port *port) 1360static int mos7840_write_room(struct tty_struct *tty)
1387{ 1361{
1362 struct usb_serial_port *port = tty->driver_data;
1388 int i; 1363 int i;
1389 int room = 0; 1364 int room = 0;
1390 unsigned long flags; 1365 unsigned long flags;
@@ -1406,9 +1381,8 @@ static int mos7840_write_room(struct usb_serial_port *port)
1406 1381
1407 spin_lock_irqsave(&mos7840_port->pool_lock, flags); 1382 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
1408 for (i = 0; i < NUM_URBS; ++i) { 1383 for (i = 0; i < NUM_URBS; ++i) {
1409 if (!mos7840_port->busy[i]) { 1384 if (!mos7840_port->busy[i])
1410 room += URB_TRANSFER_BUFFER_SIZE; 1385 room += URB_TRANSFER_BUFFER_SIZE;
1411 }
1412 } 1386 }
1413 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 1387 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
1414 1388
@@ -1426,7 +1400,7 @@ static int mos7840_write_room(struct usb_serial_port *port)
1426 * return a negative error number. 1400 * return a negative error number.
1427 *****************************************************************************/ 1401 *****************************************************************************/
1428 1402
1429static int mos7840_write(struct usb_serial_port *port, 1403static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
1430 const unsigned char *data, int count) 1404 const unsigned char *data, int count)
1431{ 1405{
1432 int status; 1406 int status;
@@ -1438,45 +1412,41 @@ static int mos7840_write(struct usb_serial_port *port,
1438 struct moschip_port *mos7840_port; 1412 struct moschip_port *mos7840_port;
1439 struct usb_serial *serial; 1413 struct usb_serial *serial;
1440 struct urb *urb; 1414 struct urb *urb;
1441 //__u16 Data; 1415 /* __u16 Data; */
1442 const unsigned char *current_position = data; 1416 const unsigned char *current_position = data;
1443 unsigned char *data1; 1417 unsigned char *data1;
1444 dbg("%s \n", "entering ..........."); 1418 dbg("%s \n", "entering ...........");
1445 //dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",mos7840_port->shadowLCR); 1419 /* dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1420 mos7840_port->shadowLCR); */
1446 1421
1447#ifdef NOTMOS7840 1422#ifdef NOTMOS7840
1448 Data = 0x00; 1423 Data = 0x00;
1449 status = 0;
1450 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 1424 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1451 mos7840_port->shadowLCR = Data; 1425 mos7840_port->shadowLCR = Data;
1452 dbg("mos7840_write: LINE_CONTROL_REGISTER is %x\n", Data); 1426 dbg("mos7840_write: LINE_CONTROL_REGISTER is %x\n", Data);
1453 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n", 1427 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1454 mos7840_port->shadowLCR); 1428 mos7840_port->shadowLCR);
1455 1429
1456 //Data = 0x03; 1430 /* Data = 0x03; */
1457 //status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); 1431 /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */
1458 //mos7840_port->shadowLCR=Data;//Need to add later 1432 /* mos7840_port->shadowLCR=Data;//Need to add later */
1459 1433
1460 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 1434 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
1461 status = 0;
1462 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1435 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1463 1436
1464 //Data = 0x0c; 1437 /* Data = 0x0c; */
1465 //status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); 1438 /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */
1466 Data = 0x00; 1439 Data = 0x00;
1467 status = 0;
1468 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data); 1440 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data);
1469 dbg("mos7840_write:DLL value is %x\n", Data); 1441 dbg("mos7840_write:DLL value is %x\n", Data);
1470 1442
1471 Data = 0x0; 1443 Data = 0x0;
1472 status = 0;
1473 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data); 1444 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data);
1474 dbg("mos7840_write:DLM value is %x\n", Data); 1445 dbg("mos7840_write:DLM value is %x\n", Data);
1475 1446
1476 Data = Data & ~SERIAL_LCR_DLAB; 1447 Data = Data & ~SERIAL_LCR_DLAB;
1477 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n", 1448 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1478 mos7840_port->shadowLCR); 1449 mos7840_port->shadowLCR);
1479 status = 0;
1480 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1450 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1481#endif 1451#endif
1482 1452
@@ -1555,8 +1525,7 @@ static int mos7840_write(struct usb_serial_port *port,
1555 mos7840_port->icount.tx += transfer_size; 1525 mos7840_port->icount.tx += transfer_size;
1556 smp_wmb(); 1526 smp_wmb();
1557 dbg("mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx); 1527 dbg("mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx);
1558 exit: 1528exit:
1559
1560 return bytes_sent; 1529 return bytes_sent;
1561 1530
1562} 1531}
@@ -1567,10 +1536,10 @@ static int mos7840_write(struct usb_serial_port *port,
1567 * being read from the port. 1536 * being read from the port.
1568 *****************************************************************************/ 1537 *****************************************************************************/
1569 1538
1570static void mos7840_throttle(struct usb_serial_port *port) 1539static void mos7840_throttle(struct tty_struct *tty)
1571{ 1540{
1541 struct usb_serial_port *port = tty->driver_data;
1572 struct moschip_port *mos7840_port; 1542 struct moschip_port *mos7840_port;
1573 struct tty_struct *tty;
1574 int status; 1543 int status;
1575 1544
1576 if (mos7840_port_paranoia_check(port, __func__)) { 1545 if (mos7840_port_paranoia_check(port, __func__)) {
@@ -1592,32 +1561,20 @@ static void mos7840_throttle(struct usb_serial_port *port)
1592 1561
1593 dbg("%s", "Entering .......... \n"); 1562 dbg("%s", "Entering .......... \n");
1594 1563
1595 tty = port->tty;
1596 if (!tty) {
1597 dbg("%s - no tty available", __func__);
1598 return;
1599 }
1600
1601 /* if we are implementing XON/XOFF, send the stop character */ 1564 /* if we are implementing XON/XOFF, send the stop character */
1602 if (I_IXOFF(tty)) { 1565 if (I_IXOFF(tty)) {
1603 unsigned char stop_char = STOP_CHAR(tty); 1566 unsigned char stop_char = STOP_CHAR(tty);
1604 status = mos7840_write(port, &stop_char, 1); 1567 status = mos7840_write(tty, port, &stop_char, 1);
1605 if (status <= 0) { 1568 if (status <= 0)
1606 return; 1569 return;
1607 }
1608 } 1570 }
1609
1610 /* if we are implementing RTS/CTS, toggle that line */ 1571 /* if we are implementing RTS/CTS, toggle that line */
1611 if (tty->termios->c_cflag & CRTSCTS) { 1572 if (tty->termios->c_cflag & CRTSCTS) {
1612 mos7840_port->shadowMCR &= ~MCR_RTS; 1573 mos7840_port->shadowMCR &= ~MCR_RTS;
1613 status = 0; 1574 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1614 status =
1615 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1616 mos7840_port->shadowMCR); 1575 mos7840_port->shadowMCR);
1617 1576 if (status < 0)
1618 if (status < 0) {
1619 return; 1577 return;
1620 }
1621 } 1578 }
1622 1579
1623 return; 1580 return;
@@ -1625,12 +1582,13 @@ static void mos7840_throttle(struct usb_serial_port *port)
1625 1582
1626/***************************************************************************** 1583/*****************************************************************************
1627 * mos7840_unthrottle 1584 * mos7840_unthrottle
1628 * this function is called by the tty driver when it wants to resume the data 1585 * this function is called by the tty driver when it wants to resume
1629 * being read from the port (called after SerialThrottle is called) 1586 * the data being read from the port (called after mos7840_throttle is
1587 * called)
1630 *****************************************************************************/ 1588 *****************************************************************************/
1631static void mos7840_unthrottle(struct usb_serial_port *port) 1589static void mos7840_unthrottle(struct tty_struct *tty)
1632{ 1590{
1633 struct tty_struct *tty; 1591 struct usb_serial_port *port = tty->driver_data;
1634 int status; 1592 int status;
1635 struct moschip_port *mos7840_port = mos7840_get_port_private(port); 1593 struct moschip_port *mos7840_port = mos7840_get_port_private(port);
1636 1594
@@ -1649,43 +1607,32 @@ static void mos7840_unthrottle(struct usb_serial_port *port)
1649 1607
1650 dbg("%s", "Entering .......... \n"); 1608 dbg("%s", "Entering .......... \n");
1651 1609
1652 tty = port->tty;
1653 if (!tty) {
1654 dbg("%s - no tty available", __func__);
1655 return;
1656 }
1657
1658 /* if we are implementing XON/XOFF, send the start character */ 1610 /* if we are implementing XON/XOFF, send the start character */
1659 if (I_IXOFF(tty)) { 1611 if (I_IXOFF(tty)) {
1660 unsigned char start_char = START_CHAR(tty); 1612 unsigned char start_char = START_CHAR(tty);
1661 status = mos7840_write(port, &start_char, 1); 1613 status = mos7840_write(tty, port, &start_char, 1);
1662 if (status <= 0) { 1614 if (status <= 0)
1663 return; 1615 return;
1664 }
1665 } 1616 }
1666 1617
1667 /* if we are implementing RTS/CTS, toggle that line */ 1618 /* if we are implementing RTS/CTS, toggle that line */
1668 if (tty->termios->c_cflag & CRTSCTS) { 1619 if (tty->termios->c_cflag & CRTSCTS) {
1669 mos7840_port->shadowMCR |= MCR_RTS; 1620 mos7840_port->shadowMCR |= MCR_RTS;
1670 status = 0; 1621 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1671 status =
1672 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1673 mos7840_port->shadowMCR); 1622 mos7840_port->shadowMCR);
1674 if (status < 0) { 1623 if (status < 0)
1675 return; 1624 return;
1676 }
1677 } 1625 }
1678
1679 return;
1680} 1626}
1681 1627
1682static int mos7840_tiocmget(struct usb_serial_port *port, struct file *file) 1628static int mos7840_tiocmget(struct tty_struct *tty, struct file *file)
1683{ 1629{
1630 struct usb_serial_port *port = tty->driver_data;
1684 struct moschip_port *mos7840_port; 1631 struct moschip_port *mos7840_port;
1685 unsigned int result; 1632 unsigned int result;
1686 __u16 msr; 1633 __u16 msr;
1687 __u16 mcr; 1634 __u16 mcr;
1688 int status = 0; 1635 int status;
1689 mos7840_port = mos7840_get_port_private(port); 1636 mos7840_port = mos7840_get_port_private(port);
1690 1637
1691 dbg("%s - port %d", __func__, port->number); 1638 dbg("%s - port %d", __func__, port->number);
@@ -1708,9 +1655,10 @@ static int mos7840_tiocmget(struct usb_serial_port *port, struct file *file)
1708 return result; 1655 return result;
1709} 1656}
1710 1657
1711static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file, 1658static int mos7840_tiocmset(struct tty_struct *tty, struct file *file,
1712 unsigned int set, unsigned int clear) 1659 unsigned int set, unsigned int clear)
1713{ 1660{
1661 struct usb_serial_port *port = tty->driver_data;
1714 struct moschip_port *mos7840_port; 1662 struct moschip_port *mos7840_port;
1715 unsigned int mcr; 1663 unsigned int mcr;
1716 int status; 1664 int status;
@@ -1755,7 +1703,7 @@ static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file,
1755 * baud rate. 1703 * baud rate.
1756 *****************************************************************************/ 1704 *****************************************************************************/
1757static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor, 1705static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
1758 __u16 * clk_sel_val) 1706 __u16 *clk_sel_val)
1759{ 1707{
1760 1708
1761 dbg("%s - %d", __func__, baudRate); 1709 dbg("%s - %d", __func__, baudRate);
@@ -1807,9 +1755,8 @@ static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
1807 /* Check for round off */ 1755 /* Check for round off */
1808 round1 = (__u16) (2304000L / baudrate); 1756 round1 = (__u16) (2304000L / baudrate);
1809 round = (__u16) (round1 - (custom * 10)); 1757 round = (__u16) (round1 - (custom * 10));
1810 if (round > 4) { 1758 if (round > 4)
1811 custom++; 1759 custom++;
1812 }
1813 *divisor = custom; 1760 *divisor = custom;
1814 1761
1815 dbg(" Baud %d = %d\n", baudrate, custom); 1762 dbg(" Baud %d = %d\n", baudrate, custom);
@@ -1857,16 +1804,15 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1857 1804
1858 dbg("%s - port = %d, baud = %d", __func__, 1805 dbg("%s - port = %d, baud = %d", __func__,
1859 mos7840_port->port->number, baudRate); 1806 mos7840_port->port->number, baudRate);
1860 //reset clk_uart_sel in spregOffset 1807 /* reset clk_uart_sel in spregOffset */
1861 if (baudRate > 115200) { 1808 if (baudRate > 115200) {
1862#ifdef HW_flow_control 1809#ifdef HW_flow_control
1863 //NOTE: need to see the pther register to modify 1810 /* NOTE: need to see the pther register to modify */
1864 //setting h/w flow control bit to 1; 1811 /* setting h/w flow control bit to 1 */
1865 status = 0;
1866 Data = 0x2b; 1812 Data = 0x2b;
1867 mos7840_port->shadowMCR = Data; 1813 mos7840_port->shadowMCR = Data;
1868 status = 1814 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1869 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 1815 Data);
1870 if (status < 0) { 1816 if (status < 0) {
1871 dbg("Writing spreg failed in set_serial_baud\n"); 1817 dbg("Writing spreg failed in set_serial_baud\n");
1872 return -1; 1818 return -1;
@@ -1875,12 +1821,11 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1875 1821
1876 } else { 1822 } else {
1877#ifdef HW_flow_control 1823#ifdef HW_flow_control
1878 //setting h/w flow control bit to 0; 1824 / *setting h/w flow control bit to 0 */
1879 status = 0;
1880 Data = 0xb; 1825 Data = 0xb;
1881 mos7840_port->shadowMCR = Data; 1826 mos7840_port->shadowMCR = Data;
1882 status = 1827 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1883 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 1828 Data);
1884 if (status < 0) { 1829 if (status < 0) {
1885 dbg("Writing spreg failed in set_serial_baud\n"); 1830 dbg("Writing spreg failed in set_serial_baud\n");
1886 return -1; 1831 return -1;
@@ -1889,25 +1834,20 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1889 1834
1890 } 1835 }
1891 1836
1892 if (1) //baudRate <= 115200) 1837 if (1) { /* baudRate <= 115200) */
1893 {
1894 clk_sel_val = 0x0; 1838 clk_sel_val = 0x0;
1895 Data = 0x0; 1839 Data = 0x0;
1896 status = 0; 1840 status = mos7840_calc_baud_rate_divisor(baudRate, &divisor,
1897 status =
1898 mos7840_calc_baud_rate_divisor(baudRate, &divisor,
1899 &clk_sel_val); 1841 &clk_sel_val);
1900 status = 1842 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset,
1901 mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, 1843 &Data);
1902 &Data);
1903 if (status < 0) { 1844 if (status < 0) {
1904 dbg("reading spreg failed in set_serial_baud\n"); 1845 dbg("reading spreg failed in set_serial_baud\n");
1905 return -1; 1846 return -1;
1906 } 1847 }
1907 Data = (Data & 0x8f) | clk_sel_val; 1848 Data = (Data & 0x8f) | clk_sel_val;
1908 status = 0; 1849 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset,
1909 status = 1850 Data);
1910 mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
1911 if (status < 0) { 1851 if (status < 0) {
1912 dbg("Writing spreg failed in set_serial_baud\n"); 1852 dbg("Writing spreg failed in set_serial_baud\n");
1913 return -1; 1853 return -1;
@@ -1939,7 +1879,6 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1939 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1879 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1940 1880
1941 } 1881 }
1942
1943 return status; 1882 return status;
1944} 1883}
1945 1884
@@ -1949,10 +1888,9 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1949 * the specified new settings. 1888 * the specified new settings.
1950 *****************************************************************************/ 1889 *****************************************************************************/
1951 1890
1952static void mos7840_change_port_settings(struct moschip_port *mos7840_port, 1891static void mos7840_change_port_settings(struct tty_struct *tty,
1953 struct ktermios *old_termios) 1892 struct moschip_port *mos7840_port, struct ktermios *old_termios)
1954{ 1893{
1955 struct tty_struct *tty;
1956 int baud; 1894 int baud;
1957 unsigned cflag; 1895 unsigned cflag;
1958 unsigned iflag; 1896 unsigned iflag;
@@ -1988,8 +1926,6 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
1988 return; 1926 return;
1989 } 1927 }
1990 1928
1991 tty = mos7840_port->port->tty;
1992
1993 dbg("%s", "Entering .......... \n"); 1929 dbg("%s", "Entering .......... \n");
1994 1930
1995 lData = LCR_BITS_8; 1931 lData = LCR_BITS_8;
@@ -2033,9 +1969,8 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2033 dbg("%s - parity = none", __func__); 1969 dbg("%s - parity = none", __func__);
2034 } 1970 }
2035 1971
2036 if (cflag & CMSPAR) { 1972 if (cflag & CMSPAR)
2037 lParity = lParity | 0x20; 1973 lParity = lParity | 0x20;
2038 }
2039 1974
2040 /* Change the Stop bit */ 1975 /* Change the Stop bit */
2041 if (cflag & CSTOPB) { 1976 if (cflag & CSTOPB) {
@@ -2077,16 +2012,13 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2077 /* set up the MCR register and send it to the mos7840 */ 2012 /* set up the MCR register and send it to the mos7840 */
2078 2013
2079 mos7840_port->shadowMCR = MCR_MASTER_IE; 2014 mos7840_port->shadowMCR = MCR_MASTER_IE;
2080 if (cflag & CBAUD) { 2015 if (cflag & CBAUD)
2081 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS); 2016 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2082 }
2083 2017
2084 if (cflag & CRTSCTS) { 2018 if (cflag & CRTSCTS)
2085 mos7840_port->shadowMCR |= (MCR_XON_ANY); 2019 mos7840_port->shadowMCR |= (MCR_XON_ANY);
2086 2020 else
2087 } else {
2088 mos7840_port->shadowMCR &= ~(MCR_XON_ANY); 2021 mos7840_port->shadowMCR &= ~(MCR_XON_ANY);
2089 }
2090 2022
2091 Data = mos7840_port->shadowMCR; 2023 Data = mos7840_port->shadowMCR;
2092 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 2024 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
@@ -2131,14 +2063,14 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2131 * the termios structure 2063 * the termios structure
2132 *****************************************************************************/ 2064 *****************************************************************************/
2133 2065
2134static void mos7840_set_termios(struct usb_serial_port *port, 2066static void mos7840_set_termios(struct tty_struct *tty,
2067 struct usb_serial_port *port,
2135 struct ktermios *old_termios) 2068 struct ktermios *old_termios)
2136{ 2069{
2137 int status; 2070 int status;
2138 unsigned int cflag; 2071 unsigned int cflag;
2139 struct usb_serial *serial; 2072 struct usb_serial *serial;
2140 struct moschip_port *mos7840_port; 2073 struct moschip_port *mos7840_port;
2141 struct tty_struct *tty;
2142 dbg("mos7840_set_termios: START\n"); 2074 dbg("mos7840_set_termios: START\n");
2143 if (mos7840_port_paranoia_check(port, __func__)) { 2075 if (mos7840_port_paranoia_check(port, __func__)) {
2144 dbg("%s", "Invalid port \n"); 2076 dbg("%s", "Invalid port \n");
@@ -2157,8 +2089,6 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2157 if (mos7840_port == NULL) 2089 if (mos7840_port == NULL)
2158 return; 2090 return;
2159 2091
2160 tty = port->tty;
2161
2162 if (!mos7840_port->open) { 2092 if (!mos7840_port->open) {
2163 dbg("%s - port not opened", __func__); 2093 dbg("%s - port not opened", __func__);
2164 return; 2094 return;
@@ -2176,7 +2106,7 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2176 2106
2177 /* change the port settings to the new ones specified */ 2107 /* change the port settings to the new ones specified */
2178 2108
2179 mos7840_change_port_settings(mos7840_port, old_termios); 2109 mos7840_change_port_settings(tty, mos7840_port, old_termios);
2180 2110
2181 if (!mos7840_port->read_urb) { 2111 if (!mos7840_port->read_urb) {
2182 dbg("%s", "URB KILLED !!!!!\n"); 2112 dbg("%s", "URB KILLED !!!!!\n");
@@ -2205,13 +2135,13 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2205 * allows an RS485 driver to be written in user space. 2135 * allows an RS485 driver to be written in user space.
2206 *****************************************************************************/ 2136 *****************************************************************************/
2207 2137
2208static int mos7840_get_lsr_info(struct moschip_port *mos7840_port, 2138static int mos7840_get_lsr_info(struct tty_struct *tty,
2209 unsigned int __user *value) 2139 unsigned int __user *value)
2210{ 2140{
2211 int count; 2141 int count;
2212 unsigned int result = 0; 2142 unsigned int result = 0;
2213 2143
2214 count = mos7840_chars_in_buffer(mos7840_port->port); 2144 count = mos7840_chars_in_buffer(tty);
2215 if (count == 0) { 2145 if (count == 0) {
2216 dbg("%s -- Empty", __func__); 2146 dbg("%s -- Empty", __func__);
2217 result = TIOCSER_TEMT; 2147 result = TIOCSER_TEMT;
@@ -2227,6 +2157,8 @@ static int mos7840_get_lsr_info(struct moschip_port *mos7840_port,
2227 * function to set modem info 2157 * function to set modem info
2228 *****************************************************************************/ 2158 *****************************************************************************/
2229 2159
2160/* FIXME: Should be using the model control hooks */
2161
2230static int mos7840_set_modem_info(struct moschip_port *mos7840_port, 2162static int mos7840_set_modem_info(struct moschip_port *mos7840_port,
2231 unsigned int cmd, unsigned int __user *value) 2163 unsigned int cmd, unsigned int __user *value)
2232{ 2164{
@@ -2282,7 +2214,6 @@ static int mos7840_set_modem_info(struct moschip_port *mos7840_port,
2282 mos7840_port->shadowMCR = mcr; 2214 mos7840_port->shadowMCR = mcr;
2283 2215
2284 Data = mos7840_port->shadowMCR; 2216 Data = mos7840_port->shadowMCR;
2285 status = 0;
2286 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 2217 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2287 if (status < 0) { 2218 if (status < 0) {
2288 dbg("setting MODEM_CONTROL_REGISTER Failed\n"); 2219 dbg("setting MODEM_CONTROL_REGISTER Failed\n");
@@ -2303,10 +2234,8 @@ static int mos7840_get_modem_info(struct moschip_port *mos7840_port,
2303 unsigned int result = 0; 2234 unsigned int result = 0;
2304 __u16 msr; 2235 __u16 msr;
2305 unsigned int mcr = mos7840_port->shadowMCR; 2236 unsigned int mcr = mos7840_port->shadowMCR;
2306 int status = 0; 2237 mos7840_get_uart_reg(mos7840_port->port,
2307 status = 2238 MODEM_STATUS_REGISTER, &msr);
2308 mos7840_get_uart_reg(mos7840_port->port, MODEM_STATUS_REGISTER,
2309 &msr);
2310 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */ 2239 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
2311 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */ 2240 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
2312 |((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */ 2241 |((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
@@ -2359,12 +2288,12 @@ static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
2359 * this function handles any ioctl calls to the driver 2288 * this function handles any ioctl calls to the driver
2360 *****************************************************************************/ 2289 *****************************************************************************/
2361 2290
2362static int mos7840_ioctl(struct usb_serial_port *port, struct file *file, 2291static int mos7840_ioctl(struct tty_struct *tty, struct file *file,
2363 unsigned int cmd, unsigned long arg) 2292 unsigned int cmd, unsigned long arg)
2364{ 2293{
2294 struct usb_serial_port *port = tty->driver_data;
2365 void __user *argp = (void __user *)arg; 2295 void __user *argp = (void __user *)arg;
2366 struct moschip_port *mos7840_port; 2296 struct moschip_port *mos7840_port;
2367 struct tty_struct *tty;
2368 2297
2369 struct async_icount cnow; 2298 struct async_icount cnow;
2370 struct async_icount cprev; 2299 struct async_icount cprev;
@@ -2381,8 +2310,6 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2381 if (mos7840_port == NULL) 2310 if (mos7840_port == NULL)
2382 return -1; 2311 return -1;
2383 2312
2384 tty = mos7840_port->port->tty;
2385
2386 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 2313 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
2387 2314
2388 switch (cmd) { 2315 switch (cmd) {
@@ -2390,9 +2317,10 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2390 2317
2391 case TIOCSERGETLSR: 2318 case TIOCSERGETLSR:
2392 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); 2319 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
2393 return mos7840_get_lsr_info(mos7840_port, argp); 2320 return mos7840_get_lsr_info(tty, argp);
2394 return 0; 2321 return 0;
2395 2322
2323 /* FIXME: use the modem hooks and remove this */
2396 case TIOCMBIS: 2324 case TIOCMBIS:
2397 case TIOCMBIC: 2325 case TIOCMBIC:
2398 case TIOCMSET: 2326 case TIOCMSET:
@@ -2418,7 +2346,7 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2418 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 2346 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
2419 cprev = mos7840_port->icount; 2347 cprev = mos7840_port->icount;
2420 while (1) { 2348 while (1) {
2421 //interruptible_sleep_on(&mos7840_port->delta_msr_wait); 2349 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
2422 mos7840_port->delta_msr_cond = 0; 2350 mos7840_port->delta_msr_cond = 0;
2423 wait_event_interruptible(mos7840_port->delta_msr_wait, 2351 wait_event_interruptible(mos7840_port->delta_msr_wait,
2424 (mos7840_port-> 2352 (mos7840_port->
@@ -2463,13 +2391,9 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2463 if (copy_to_user(argp, &icount, sizeof(icount))) 2391 if (copy_to_user(argp, &icount, sizeof(icount)))
2464 return -EFAULT; 2392 return -EFAULT;
2465 return 0; 2393 return 0;
2466
2467 case TIOCEXBAUD:
2468 return 0;
2469 default: 2394 default:
2470 break; 2395 break;
2471 } 2396 }
2472
2473 return -ENOIOCTLCMD; 2397 return -ENOIOCTLCMD;
2474} 2398}
2475 2399
@@ -2527,8 +2451,9 @@ static int mos7840_startup(struct usb_serial *serial)
2527 goto error; 2451 goto error;
2528 } 2452 }
2529 2453
2530 /* Initialize all port interrupt end point to port 0 int endpoint * 2454 /* Initialize all port interrupt end point to port 0 int
2531 * Our device has only one interrupt end point comman to all port */ 2455 * endpoint. Our device has only one interrupt end point
2456 * common to all port */
2532 2457
2533 mos7840_port->port = serial->port[i]; 2458 mos7840_port->port = serial->port[i];
2534 mos7840_set_port_private(serial->port[i], mos7840_port); 2459 mos7840_set_port_private(serial->port[i], mos7840_port);
@@ -2564,27 +2489,23 @@ static int mos7840_startup(struct usb_serial *serial)
2564 mos7840_port->DcrRegOffset = 0x1c; 2489 mos7840_port->DcrRegOffset = 0x1c;
2565 } 2490 }
2566 mos7840_dump_serial_port(mos7840_port); 2491 mos7840_dump_serial_port(mos7840_port);
2567
2568 mos7840_set_port_private(serial->port[i], mos7840_port); 2492 mos7840_set_port_private(serial->port[i], mos7840_port);
2569 2493
2570 //enable rx_disable bit in control register 2494 /* enable rx_disable bit in control register */
2571 2495 status = mos7840_get_reg_sync(serial->port[i],
2572 status = 2496 mos7840_port->ControlRegOffset, &Data);
2573 mos7840_get_reg_sync(serial->port[i],
2574 mos7840_port->ControlRegOffset, &Data);
2575 if (status < 0) { 2497 if (status < 0) {
2576 dbg("Reading ControlReg failed status-0x%x\n", status); 2498 dbg("Reading ControlReg failed status-0x%x\n", status);
2577 break; 2499 break;
2578 } else 2500 } else
2579 dbg("ControlReg Reading success val is %x, status%d\n", 2501 dbg("ControlReg Reading success val is %x, status%d\n",
2580 Data, status); 2502 Data, status);
2581 Data |= 0x08; //setting driver done bit 2503 Data |= 0x08; /* setting driver done bit */
2582 Data |= 0x04; //sp1_bit to have cts change reflect in modem status reg 2504 Data |= 0x04; /* sp1_bit to have cts change reflect in
2505 modem status reg */
2583 2506
2584 //Data |= 0x20; //rx_disable bit 2507 /* Data |= 0x20; //rx_disable bit */
2585 status = 0; 2508 status = mos7840_set_reg_sync(serial->port[i],
2586 status =
2587 mos7840_set_reg_sync(serial->port[i],
2588 mos7840_port->ControlRegOffset, Data); 2509 mos7840_port->ControlRegOffset, Data);
2589 if (status < 0) { 2510 if (status < 0) {
2590 dbg("Writing ControlReg failed(rx_disable) status-0x%x\n", status); 2511 dbg("Writing ControlReg failed(rx_disable) status-0x%x\n", status);
@@ -2593,13 +2514,11 @@ static int mos7840_startup(struct usb_serial *serial)
2593 dbg("ControlReg Writing success(rx_disable) status%d\n", 2514 dbg("ControlReg Writing success(rx_disable) status%d\n",
2594 status); 2515 status);
2595 2516
2596 //Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 and 0x24 in DCR3 2517 /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2518 and 0x24 in DCR3 */
2597 Data = 0x01; 2519 Data = 0x01;
2598 status = 0; 2520 status = mos7840_set_reg_sync(serial->port[i],
2599 status = 2521 (__u16) (mos7840_port->DcrRegOffset + 0), Data);
2600 mos7840_set_reg_sync(serial->port[i],
2601 (__u16) (mos7840_port->DcrRegOffset +
2602 0), Data);
2603 if (status < 0) { 2522 if (status < 0) {
2604 dbg("Writing DCR0 failed status-0x%x\n", status); 2523 dbg("Writing DCR0 failed status-0x%x\n", status);
2605 break; 2524 break;
@@ -2607,11 +2526,8 @@ static int mos7840_startup(struct usb_serial *serial)
2607 dbg("DCR0 Writing success status%d\n", status); 2526 dbg("DCR0 Writing success status%d\n", status);
2608 2527
2609 Data = 0x05; 2528 Data = 0x05;
2610 status = 0; 2529 status = mos7840_set_reg_sync(serial->port[i],
2611 status = 2530 (__u16) (mos7840_port->DcrRegOffset + 1), Data);
2612 mos7840_set_reg_sync(serial->port[i],
2613 (__u16) (mos7840_port->DcrRegOffset +
2614 1), Data);
2615 if (status < 0) { 2531 if (status < 0) {
2616 dbg("Writing DCR1 failed status-0x%x\n", status); 2532 dbg("Writing DCR1 failed status-0x%x\n", status);
2617 break; 2533 break;
@@ -2619,22 +2535,17 @@ static int mos7840_startup(struct usb_serial *serial)
2619 dbg("DCR1 Writing success status%d\n", status); 2535 dbg("DCR1 Writing success status%d\n", status);
2620 2536
2621 Data = 0x24; 2537 Data = 0x24;
2622 status = 0; 2538 status = mos7840_set_reg_sync(serial->port[i],
2623 status = 2539 (__u16) (mos7840_port->DcrRegOffset + 2), Data);
2624 mos7840_set_reg_sync(serial->port[i],
2625 (__u16) (mos7840_port->DcrRegOffset +
2626 2), Data);
2627 if (status < 0) { 2540 if (status < 0) {
2628 dbg("Writing DCR2 failed status-0x%x\n", status); 2541 dbg("Writing DCR2 failed status-0x%x\n", status);
2629 break; 2542 break;
2630 } else 2543 } else
2631 dbg("DCR2 Writing success status%d\n", status); 2544 dbg("DCR2 Writing success status%d\n", status);
2632 2545
2633 // write values in clkstart0x0 and clkmulti 0x20 2546 /* write values in clkstart0x0 and clkmulti 0x20 */
2634 Data = 0x0; 2547 Data = 0x0;
2635 status = 0; 2548 status = mos7840_set_reg_sync(serial->port[i],
2636 status =
2637 mos7840_set_reg_sync(serial->port[i],
2638 CLK_START_VALUE_REGISTER, Data); 2549 CLK_START_VALUE_REGISTER, Data);
2639 if (status < 0) { 2550 if (status < 0) {
2640 dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status); 2551 dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status);
@@ -2643,9 +2554,8 @@ static int mos7840_startup(struct usb_serial *serial)
2643 dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status); 2554 dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status);
2644 2555
2645 Data = 0x20; 2556 Data = 0x20;
2646 status = 2557 status = mos7840_set_reg_sync(serial->port[i],
2647 mos7840_set_reg_sync(serial->port[i], CLK_MULTI_REGISTER, 2558 CLK_MULTI_REGISTER, Data);
2648 Data);
2649 if (status < 0) { 2559 if (status < 0) {
2650 dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n", 2560 dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n",
2651 status); 2561 status);
@@ -2654,11 +2564,10 @@ static int mos7840_startup(struct usb_serial *serial)
2654 dbg("CLK_MULTI_REGISTER Writing success status%d\n", 2564 dbg("CLK_MULTI_REGISTER Writing success status%d\n",
2655 status); 2565 status);
2656 2566
2657 //write value 0x0 to scratchpad register 2567 /* write value 0x0 to scratchpad register */
2658 Data = 0x00; 2568 Data = 0x00;
2659 status = 2569 status = mos7840_set_uart_reg(serial->port[i],
2660 mos7840_set_uart_reg(serial->port[i], SCRATCH_PAD_REGISTER, 2570 SCRATCH_PAD_REGISTER, Data);
2661 Data);
2662 if (status < 0) { 2571 if (status < 0) {
2663 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", 2572 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n",
2664 status); 2573 status);
@@ -2667,21 +2576,17 @@ static int mos7840_startup(struct usb_serial *serial)
2667 dbg("SCRATCH_PAD_REGISTER Writing success status%d\n", 2576 dbg("SCRATCH_PAD_REGISTER Writing success status%d\n",
2668 status); 2577 status);
2669 2578
2670 //Zero Length flag register 2579 /* Zero Length flag register */
2671 if ((mos7840_port->port_num != 1) 2580 if ((mos7840_port->port_num != 1)
2672 && (serial->num_ports == 2)) { 2581 && (serial->num_ports == 2)) {
2673 2582
2674 Data = 0xff; 2583 Data = 0xff;
2675 status = 0;
2676 status = mos7840_set_reg_sync(serial->port[i], 2584 status = mos7840_set_reg_sync(serial->port[i],
2677 (__u16) (ZLP_REG1 + 2585 (__u16) (ZLP_REG1 +
2678 ((__u16) 2586 ((__u16)mos7840_port->port_num)), Data);
2679 mos7840_port->
2680 port_num)),
2681 Data);
2682 dbg("ZLIP offset%x\n", 2587 dbg("ZLIP offset%x\n",
2683 (__u16) (ZLP_REG1 + 2588 (__u16) (ZLP_REG1 +
2684 ((__u16) mos7840_port->port_num))); 2589 ((__u16) mos7840_port->port_num)));
2685 if (status < 0) { 2590 if (status < 0) {
2686 dbg("Writing ZLP_REG%d failed status-0x%x\n", 2591 dbg("Writing ZLP_REG%d failed status-0x%x\n",
2687 i + 2, status); 2592 i + 2, status);
@@ -2691,13 +2596,9 @@ static int mos7840_startup(struct usb_serial *serial)
2691 i + 2, status); 2596 i + 2, status);
2692 } else { 2597 } else {
2693 Data = 0xff; 2598 Data = 0xff;
2694 status = 0;
2695 status = mos7840_set_reg_sync(serial->port[i], 2599 status = mos7840_set_reg_sync(serial->port[i],
2696 (__u16) (ZLP_REG1 + 2600 (__u16) (ZLP_REG1 +
2697 ((__u16) 2601 ((__u16)mos7840_port->port_num) - 0x1), Data);
2698 mos7840_port->
2699 port_num) -
2700 0x1), Data);
2701 dbg("ZLIP offset%x\n", 2602 dbg("ZLIP offset%x\n",
2702 (__u16) (ZLP_REG1 + 2603 (__u16) (ZLP_REG1 +
2703 ((__u16) mos7840_port->port_num) - 0x1)); 2604 ((__u16) mos7840_port->port_num) - 0x1));
@@ -2712,14 +2613,16 @@ static int mos7840_startup(struct usb_serial *serial)
2712 } 2613 }
2713 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); 2614 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL);
2714 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); 2615 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2715 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); 2616 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest),
2716 if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || !mos7840_port->dr) { 2617 GFP_KERNEL);
2618 if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf ||
2619 !mos7840_port->dr) {
2717 status = -ENOMEM; 2620 status = -ENOMEM;
2718 goto error; 2621 goto error;
2719 } 2622 }
2720 } 2623 }
2721 2624
2722 //Zero Length flag enable 2625 /* Zero Length flag enable */
2723 Data = 0x0f; 2626 Data = 0x0f;
2724 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); 2627 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2725 if (status < 0) { 2628 if (status < 0) {
@@ -2762,7 +2665,7 @@ static void mos7840_shutdown(struct usb_serial *serial)
2762 return; 2665 return;
2763 } 2666 }
2764 2667
2765 /* check for the ports to be closed,close the ports and disconnect */ 2668 /* check for the ports to be closed,close the ports and disconnect */
2766 2669
2767 /* free private structure allocated for serial port * 2670 /* free private structure allocated for serial port *
2768 * stop reads and writes on all ports */ 2671 * stop reads and writes on all ports */
@@ -2843,20 +2746,12 @@ static int __init moschip7840_init(void)
2843 2746
2844 /* Register with the usb */ 2747 /* Register with the usb */
2845 retval = usb_register(&io_driver); 2748 retval = usb_register(&io_driver);
2846
2847 if (retval)
2848 goto failed_usb_register;
2849
2850 if (retval == 0) { 2749 if (retval == 0) {
2851 dbg("%s\n", "Leaving..."); 2750 dbg("%s\n", "Leaving...");
2852 return 0; 2751 return 0;
2853 } 2752 }
2854
2855 failed_usb_register:
2856 usb_serial_deregister(&moschip7840_4port_device); 2753 usb_serial_deregister(&moschip7840_4port_device);
2857 2754failed_port_device_register:
2858 failed_port_device_register:
2859
2860 return retval; 2755 return retval;
2861} 2756}
2862 2757
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c
index 43c8894353bf..d6736531a0fa 100644
--- a/drivers/usb/serial/navman.c
+++ b/drivers/usb/serial/navman.c
@@ -64,7 +64,7 @@ static void navman_read_int_callback(struct urb *urb)
64 usb_serial_debug_data(debug, &port->dev, __func__, 64 usb_serial_debug_data(debug, &port->dev, __func__,
65 urb->actual_length, data); 65 urb->actual_length, data);
66 66
67 tty = port->tty; 67 tty = port->port.tty;
68 if (tty && urb->actual_length) { 68 if (tty && urb->actual_length) {
69 tty_buffer_request_room(tty, urb->actual_length); 69 tty_buffer_request_room(tty, urb->actual_length);
70 tty_insert_flip_string(tty, data, urb->actual_length); 70 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -79,7 +79,8 @@ exit:
79 __func__, result); 79 __func__, result);
80} 80}
81 81
82static int navman_open(struct usb_serial_port *port, struct file *filp) 82static int navman_open(struct tty_struct *tty,
83 struct usb_serial_port *port, struct file *filp)
83{ 84{
84 int result = 0; 85 int result = 0;
85 86
@@ -96,14 +97,15 @@ static int navman_open(struct usb_serial_port *port, struct file *filp)
96 return result; 97 return result;
97} 98}
98 99
99static void navman_close(struct usb_serial_port *port, struct file *filp) 100static void navman_close(struct tty_struct *tty,
101 struct usb_serial_port *port, struct file *filp)
100{ 102{
101 dbg("%s - port %d", __func__, port->number); 103 dbg("%s - port %d", __func__, port->number);
102 104
103 usb_kill_urb(port->interrupt_in_urb); 105 usb_kill_urb(port->interrupt_in_urb);
104} 106}
105 107
106static int navman_write(struct usb_serial_port *port, 108static int navman_write(struct tty_struct *tty, struct usb_serial_port *port,
107 const unsigned char *buf, int count) 109 const unsigned char *buf, int count)
108{ 110{
109 dbg("%s - port %d", __func__, port->number); 111 dbg("%s - port %d", __func__, port->number);
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index 7b7422f49478..ae8e227f3db2 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -5,26 +5,28 @@
5 * modify it under the terms of the GNU General Public License version 5 * modify it under the terms of the GNU General Public License version
6 * 2 as published by the Free Software Foundation. 6 * 2 as published by the Free Software Foundation.
7 * 7 *
8 * See Documentation/usb/usb-serial.txt for more information on using this driver 8 * See Documentation/usb/usb-serial.txt for more information on using this
9 * driver
9 * 10 *
10 * Please report both successes and troubles to the author at omninet@kroah.com 11 * Please report both successes and troubles to the author at omninet@kroah.com
11 * 12 *
12 * (05/30/2001) gkh 13 * (05/30/2001) gkh
13 * switched from using spinlock to a semaphore, which fixes lots of problems. 14 * switched from using spinlock to a semaphore, which fixes lots of
15 * problems.
14 * 16 *
15 * (04/08/2001) gb 17 * (04/08/2001) gb
16 * Identify version on module load. 18 * Identify version on module load.
17 * 19 *
18 * (11/01/2000) Adam J. Richter 20 * (11/01/2000) Adam J. Richter
19 * usb_device_id table support 21 * usb_device_id table support
20 * 22 *
21 * (10/05/2000) gkh 23 * (10/05/2000) gkh
22 * Fixed bug with urb->dev not being set properly, now that the usb 24 * Fixed bug with urb->dev not being set properly, now that the usb
23 * core needs it. 25 * core needs it.
24 * 26 *
25 * (08/28/2000) gkh 27 * (08/28/2000) gkh
26 * Added locks for SMP safeness. 28 * Added locks for SMP safeness.
27 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more 29 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
28 * than once. 30 * than once.
29 * Fixed potential race in omninet_write_bulk_callback 31 * Fixed potential race in omninet_write_bulk_callback
30 * 32 *
@@ -43,7 +45,7 @@
43#include <linux/tty_flip.h> 45#include <linux/tty_flip.h>
44#include <linux/module.h> 46#include <linux/module.h>
45#include <linux/spinlock.h> 47#include <linux/spinlock.h>
46#include <asm/uaccess.h> 48#include <linux/uaccess.h>
47#include <linux/usb.h> 49#include <linux/usb.h>
48#include <linux/usb/serial.h> 50#include <linux/usb/serial.h>
49 51
@@ -58,25 +60,29 @@ static int debug;
58 60
59#define ZYXEL_VENDOR_ID 0x0586 61#define ZYXEL_VENDOR_ID 0x0586
60#define ZYXEL_OMNINET_ID 0x1000 62#define ZYXEL_OMNINET_ID 0x1000
61#define BT_IGNITIONPRO_ID 0x2000 /* This one seems to be a re-branded ZyXEL device */ 63/* This one seems to be a re-branded ZyXEL device */
64#define BT_IGNITIONPRO_ID 0x2000
62 65
63/* function prototypes */ 66/* function prototypes */
64static int omninet_open (struct usb_serial_port *port, struct file *filp); 67static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port,
65static void omninet_close (struct usb_serial_port *port, struct file *filp); 68 struct file *filp);
66static void omninet_read_bulk_callback (struct urb *urb); 69static void omninet_close(struct tty_struct *tty, struct usb_serial_port *port,
67static void omninet_write_bulk_callback (struct urb *urb); 70 struct file *filp);
68static int omninet_write (struct usb_serial_port *port, const unsigned char *buf, int count); 71static void omninet_read_bulk_callback(struct urb *urb);
69static int omninet_write_room (struct usb_serial_port *port); 72static void omninet_write_bulk_callback(struct urb *urb);
70static void omninet_shutdown (struct usb_serial *serial); 73static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
71static int omninet_attach (struct usb_serial *serial); 74 const unsigned char *buf, int count);
72 75static int omninet_write_room(struct tty_struct *tty);
73static struct usb_device_id id_table [] = { 76static void omninet_shutdown(struct usb_serial *serial);
77static int omninet_attach(struct usb_serial *serial);
78
79static struct usb_device_id id_table[] = {
74 { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) }, 80 { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) },
75 { USB_DEVICE(ZYXEL_VENDOR_ID, BT_IGNITIONPRO_ID) }, 81 { USB_DEVICE(ZYXEL_VENDOR_ID, BT_IGNITIONPRO_ID) },
76 { } /* Terminating entry */ 82 { } /* Terminating entry */
77}; 83};
78 84
79MODULE_DEVICE_TABLE (usb, id_table); 85MODULE_DEVICE_TABLE(usb, id_table);
80 86
81static struct usb_driver omninet_driver = { 87static struct usb_driver omninet_driver = {
82 .name = "omninet", 88 .name = "omninet",
@@ -130,34 +136,34 @@ static struct usb_serial_driver zyxel_omninet_device = {
130 * 136 *
131 */ 137 */
132 138
133struct omninet_header 139struct omninet_header {
134{
135 __u8 oh_seq; 140 __u8 oh_seq;
136 __u8 oh_len; 141 __u8 oh_len;
137 __u8 oh_xxx; 142 __u8 oh_xxx;
138 __u8 oh_pad; 143 __u8 oh_pad;
139}; 144};
140 145
141struct omninet_data 146struct omninet_data {
142{ 147 __u8 od_outseq; /* Sequence number for bulk_out URBs */
143 __u8 od_outseq; // Sequence number for bulk_out URBs
144}; 148};
145 149
146static int omninet_attach (struct usb_serial *serial) 150static int omninet_attach(struct usb_serial *serial)
147{ 151{
148 struct omninet_data *od; 152 struct omninet_data *od;
149 struct usb_serial_port *port = serial->port[0]; 153 struct usb_serial_port *port = serial->port[0];
150 154
151 od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL ); 155 od = kmalloc(sizeof(struct omninet_data), GFP_KERNEL);
152 if( !od ) { 156 if (!od) {
153 err("%s- kmalloc(%Zd) failed.", __func__, sizeof(struct omninet_data)); 157 err("%s- kmalloc(%Zd) failed.",
158 __func__, sizeof(struct omninet_data));
154 return -ENOMEM; 159 return -ENOMEM;
155 } 160 }
156 usb_set_serial_port_data(port, od); 161 usb_set_serial_port_data(port, od);
157 return 0; 162 return 0;
158} 163}
159 164
160static int omninet_open (struct usb_serial_port *port, struct file *filp) 165static int omninet_open(struct tty_struct *tty,
166 struct usb_serial_port *port, struct file *filp)
161{ 167{
162 struct usb_serial *serial = port->serial; 168 struct usb_serial *serial = port->serial;
163 struct usb_serial_port *wport; 169 struct usb_serial_port *wport;
@@ -166,22 +172,24 @@ static int omninet_open (struct usb_serial_port *port, struct file *filp)
166 dbg("%s - port %d", __func__, port->number); 172 dbg("%s - port %d", __func__, port->number);
167 173
168 wport = serial->port[1]; 174 wport = serial->port[1];
169 wport->tty = port->tty; 175 wport->port.tty = tty; /* FIXME */
170 176
171 /* Start reading from the device */ 177 /* Start reading from the device */
172 usb_fill_bulk_urb(port->read_urb, serial->dev, 178 usb_fill_bulk_urb(port->read_urb, serial->dev,
173 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), 179 usb_rcvbulkpipe(serial->dev,
174 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 180 port->bulk_in_endpointAddress),
175 omninet_read_bulk_callback, port); 181 port->read_urb->transfer_buffer,
182 port->read_urb->transfer_buffer_length,
183 omninet_read_bulk_callback, port);
176 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 184 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
177 if (result) { 185 if (result)
178 err("%s - failed submitting read urb, error %d", __func__, result); 186 err("%s - failed submitting read urb, error %d",
179 } 187 __func__, result);
180
181 return result; 188 return result;
182} 189}
183 190
184static void omninet_close (struct usb_serial_port *port, struct file * filp) 191static void omninet_close(struct tty_struct *tty,
192 struct usb_serial_port *port, struct file *filp)
185{ 193{
186 dbg("%s - port %d", __func__, port->number); 194 dbg("%s - port %d", __func__, port->number);
187 usb_kill_urb(port->read_urb); 195 usb_kill_urb(port->read_urb);
@@ -192,14 +200,14 @@ static void omninet_close (struct usb_serial_port *port, struct file * filp)
192#define OMNINET_HEADERLEN sizeof(struct omninet_header) 200#define OMNINET_HEADERLEN sizeof(struct omninet_header)
193#define OMNINET_BULKOUTSIZE (64 - OMNINET_HEADERLEN) 201#define OMNINET_BULKOUTSIZE (64 - OMNINET_HEADERLEN)
194 202
195static void omninet_read_bulk_callback (struct urb *urb) 203static void omninet_read_bulk_callback(struct urb *urb)
196{ 204{
197 struct usb_serial_port *port = urb->context; 205 struct usb_serial_port *port = urb->context;
198 unsigned char *data = urb->transfer_buffer; 206 unsigned char *data = urb->transfer_buffer;
199 struct omninet_header *header = (struct omninet_header *) &data[0]; 207 struct omninet_header *header = (struct omninet_header *) &data[0];
200 int status = urb->status; 208 int status = urb->status;
201 int i;
202 int result; 209 int result;
210 int i;
203 211
204 dbg("%s - port %d", __func__, port->number); 212 dbg("%s - port %d", __func__, port->number);
205 213
@@ -209,42 +217,46 @@ static void omninet_read_bulk_callback (struct urb *urb)
209 return; 217 return;
210 } 218 }
211 219
212 if ((debug) && (header->oh_xxx != 0x30)) { 220 if (debug && header->oh_xxx != 0x30) {
213 if (urb->actual_length) { 221 if (urb->actual_length) {
214 printk (KERN_DEBUG __FILE__ ": omninet_read %d: ", header->oh_len); 222 printk(KERN_DEBUG __FILE__
215 for (i = 0; i < (header->oh_len + OMNINET_HEADERLEN); i++) { 223 ": omninet_read %d: ", header->oh_len);
216 printk ("%.2x ", data[i]); 224 for (i = 0; i < (header->oh_len +
217 } 225 OMNINET_HEADERLEN); i++)
218 printk ("\n"); 226 printk("%.2x ", data[i]);
227 printk("\n");
219 } 228 }
220 } 229 }
221 230
222 if (urb->actual_length && header->oh_len) { 231 if (urb->actual_length && header->oh_len) {
223 for (i = 0; i < header->oh_len; i++) { 232 tty_insert_flip_string(port->port.tty,
224 tty_insert_flip_char(port->tty, data[OMNINET_DATAOFFSET + i], 0); 233 data + OMNINET_DATAOFFSET, header->oh_len);
225 } 234 tty_flip_buffer_push(port->port.tty);
226 tty_flip_buffer_push(port->tty);
227 } 235 }
228 236
229 /* Continue trying to always read */ 237 /* Continue trying to always read */
230 usb_fill_bulk_urb(urb, port->serial->dev, 238 usb_fill_bulk_urb(urb, port->serial->dev,
231 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), 239 usb_rcvbulkpipe(port->serial->dev,
232 urb->transfer_buffer, urb->transfer_buffer_length, 240 port->bulk_in_endpointAddress),
233 omninet_read_bulk_callback, port); 241 urb->transfer_buffer, urb->transfer_buffer_length,
242 omninet_read_bulk_callback, port);
234 result = usb_submit_urb(urb, GFP_ATOMIC); 243 result = usb_submit_urb(urb, GFP_ATOMIC);
235 if (result) 244 if (result)
236 err("%s - failed resubmitting read urb, error %d", __func__, result); 245 err("%s - failed resubmitting read urb, error %d",
246 __func__, result);
237 247
238 return; 248 return;
239} 249}
240 250
241static int omninet_write (struct usb_serial_port *port, const unsigned char *buf, int count) 251static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
252 const unsigned char *buf, int count)
242{ 253{
243 struct usb_serial *serial = port->serial; 254 struct usb_serial *serial = port->serial;
244 struct usb_serial_port *wport = serial->port[1]; 255 struct usb_serial_port *wport = serial->port[1];
245 256
246 struct omninet_data *od = usb_get_serial_port_data(port); 257 struct omninet_data *od = usb_get_serial_port_data(port);
247 struct omninet_header *header = (struct omninet_header *) wport->write_urb->transfer_buffer; 258 struct omninet_header *header = (struct omninet_header *)
259 wport->write_urb->transfer_buffer;
248 260
249 int result; 261 int result;
250 262
@@ -252,7 +264,7 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
252 264
253 if (count == 0) { 265 if (count == 0) {
254 dbg("%s - write request of 0 bytes", __func__); 266 dbg("%s - write request of 0 bytes", __func__);
255 return (0); 267 return 0;
256 } 268 }
257 269
258 spin_lock_bh(&wport->lock); 270 spin_lock_bh(&wport->lock);
@@ -266,9 +278,11 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
266 278
267 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count; 279 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count;
268 280
269 memcpy (wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET, buf, count); 281 memcpy(wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET,
282 buf, count);
270 283
271 usb_serial_debug_data(debug, &port->dev, __func__, count, wport->write_urb->transfer_buffer); 284 usb_serial_debug_data(debug, &port->dev, __func__, count,
285 wport->write_urb->transfer_buffer);
272 286
273 header->oh_seq = od->od_outseq++; 287 header->oh_seq = od->od_outseq++;
274 header->oh_len = count; 288 header->oh_len = count;
@@ -282,7 +296,8 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
282 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC); 296 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC);
283 if (result) { 297 if (result) {
284 wport->write_urb_busy = 0; 298 wport->write_urb_busy = 0;
285 err("%s - failed submitting write urb, error %d", __func__, result); 299 err("%s - failed submitting write urb, error %d",
300 __func__, result);
286 } else 301 } else
287 result = count; 302 result = count;
288 303
@@ -290,8 +305,9 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
290} 305}
291 306
292 307
293static int omninet_write_room (struct usb_serial_port *port) 308static int omninet_write_room(struct tty_struct *tty)
294{ 309{
310 struct usb_serial_port *port = tty->driver_data;
295 struct usb_serial *serial = port->serial; 311 struct usb_serial *serial = port->serial;
296 struct usb_serial_port *wport = serial->port[1]; 312 struct usb_serial_port *wport = serial->port[1];
297 313
@@ -303,12 +319,13 @@ static int omninet_write_room (struct usb_serial_port *port)
303 319
304 dbg("%s - returns %d", __func__, room); 320 dbg("%s - returns %d", __func__, room);
305 321
306 return (room); 322 return room;
307} 323}
308 324
309static void omninet_write_bulk_callback (struct urb *urb) 325static void omninet_write_bulk_callback(struct urb *urb)
310{ 326{
311/* struct omninet_header *header = (struct omninet_header *) urb->transfer_buffer; */ 327/* struct omninet_header *header = (struct omninet_header *)
328 urb->transfer_buffer; */
312 struct usb_serial_port *port = urb->context; 329 struct usb_serial_port *port = urb->context;
313 int status = urb->status; 330 int status = urb->status;
314 331
@@ -325,18 +342,18 @@ static void omninet_write_bulk_callback (struct urb *urb)
325} 342}
326 343
327 344
328static void omninet_shutdown (struct usb_serial *serial) 345static void omninet_shutdown(struct usb_serial *serial)
329{ 346{
330 struct usb_serial_port *wport = serial->port[1]; 347 struct usb_serial_port *wport = serial->port[1];
331 struct usb_serial_port *port = serial->port[0]; 348 struct usb_serial_port *port = serial->port[0];
332 dbg ("%s", __func__); 349 dbg("%s", __func__);
333 350
334 usb_kill_urb(wport->write_urb); 351 usb_kill_urb(wport->write_urb);
335 kfree(usb_get_serial_port_data(port)); 352 kfree(usb_get_serial_port_data(port));
336} 353}
337 354
338 355
339static int __init omninet_init (void) 356static int __init omninet_init(void)
340{ 357{
341 int retval; 358 int retval;
342 retval = usb_serial_register(&zyxel_omninet_device); 359 retval = usb_serial_register(&zyxel_omninet_device);
@@ -354,18 +371,18 @@ failed_usb_serial_register:
354} 371}
355 372
356 373
357static void __exit omninet_exit (void) 374static void __exit omninet_exit(void)
358{ 375{
359 usb_deregister (&omninet_driver); 376 usb_deregister(&omninet_driver);
360 usb_serial_deregister (&zyxel_omninet_device); 377 usb_serial_deregister(&zyxel_omninet_device);
361} 378}
362 379
363 380
364module_init(omninet_init); 381module_init(omninet_init);
365module_exit(omninet_exit); 382module_exit(omninet_exit);
366 383
367MODULE_AUTHOR( DRIVER_AUTHOR ); 384MODULE_AUTHOR(DRIVER_AUTHOR);
368MODULE_DESCRIPTION( DRIVER_DESC ); 385MODULE_DESCRIPTION(DRIVER_DESC);
369MODULE_LICENSE("GPL"); 386MODULE_LICENSE("GPL");
370 387
371module_param(debug, bool, S_IRUGO | S_IWUSR); 388module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index a73420dd052a..e4eca95f2b0f 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -43,29 +43,25 @@
43#include <linux/usb/serial.h> 43#include <linux/usb/serial.h>
44 44
45/* Function prototypes */ 45/* Function prototypes */
46static int option_open(struct usb_serial_port *port, struct file *filp); 46static int option_open(struct tty_struct *tty, struct usb_serial_port *port,
47static void option_close(struct usb_serial_port *port, struct file *filp); 47 struct file *filp);
48static void option_close(struct tty_struct *tty, struct usb_serial_port *port,
49 struct file *filp);
48static int option_startup(struct usb_serial *serial); 50static int option_startup(struct usb_serial *serial);
49static void option_shutdown(struct usb_serial *serial); 51static void option_shutdown(struct usb_serial *serial);
50static void option_rx_throttle(struct usb_serial_port *port); 52static int option_write_room(struct tty_struct *tty);
51static void option_rx_unthrottle(struct usb_serial_port *port);
52static int option_write_room(struct usb_serial_port *port);
53 53
54static void option_instat_callback(struct urb *urb); 54static void option_instat_callback(struct urb *urb);
55 55
56static int option_write(struct usb_serial_port *port, 56static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
57 const unsigned char *buf, int count); 57 const unsigned char *buf, int count);
58 58static int option_chars_in_buffer(struct tty_struct *tty);
59static int option_chars_in_buffer(struct usb_serial_port *port); 59static void option_set_termios(struct tty_struct *tty,
60static int option_ioctl(struct usb_serial_port *port, struct file *file, 60 struct usb_serial_port *port, struct ktermios *old);
61 unsigned int cmd, unsigned long arg); 61static int option_tiocmget(struct tty_struct *tty, struct file *file);
62static void option_set_termios(struct usb_serial_port *port, 62static int option_tiocmset(struct tty_struct *tty, struct file *file,
63 struct ktermios *old);
64static void option_break_ctl(struct usb_serial_port *port, int break_state);
65static int option_tiocmget(struct usb_serial_port *port, struct file *file);
66static int option_tiocmset(struct usb_serial_port *port, struct file *file,
67 unsigned int set, unsigned int clear); 63 unsigned int set, unsigned int clear);
68static int option_send_setup(struct usb_serial_port *port); 64static int option_send_setup(struct tty_struct *tty, struct usb_serial_port *port);
69 65
70/* Vendor and product IDs */ 66/* Vendor and product IDs */
71#define OPTION_VENDOR_ID 0x0AF0 67#define OPTION_VENDOR_ID 0x0AF0
@@ -173,6 +169,7 @@ static int option_send_setup(struct usb_serial_port *port);
173#define DELL_VENDOR_ID 0x413C 169#define DELL_VENDOR_ID 0x413C
174 170
175#define KYOCERA_VENDOR_ID 0x0c88 171#define KYOCERA_VENDOR_ID 0x0c88
172#define KYOCERA_PRODUCT_KPC650 0x17da
176#define KYOCERA_PRODUCT_KPC680 0x180a 173#define KYOCERA_PRODUCT_KPC680 0x180a
177 174
178#define ANYDATA_VENDOR_ID 0x16d5 175#define ANYDATA_VENDOR_ID 0x16d5
@@ -305,6 +302,7 @@ static struct usb_device_id option_ids[] = {
305 { USB_DEVICE(ONDA_VENDOR_ID, ONDA_PRODUCT_ET502HS) }, 302 { USB_DEVICE(ONDA_VENDOR_ID, ONDA_PRODUCT_ET502HS) },
306 { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_C100_1) }, 303 { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_C100_1) },
307 { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_C100_2) }, 304 { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_C100_2) },
305 { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_PRODUCT_KPC650) },
308 { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_PRODUCT_KPC680) }, 306 { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_PRODUCT_KPC680) },
309 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6000)}, /* ZTE AC8700 */ 307 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6000)}, /* ZTE AC8700 */
310 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */ 308 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */
@@ -340,11 +338,7 @@ static struct usb_serial_driver option_1port_device = {
340 .write = option_write, 338 .write = option_write,
341 .write_room = option_write_room, 339 .write_room = option_write_room,
342 .chars_in_buffer = option_chars_in_buffer, 340 .chars_in_buffer = option_chars_in_buffer,
343 .throttle = option_rx_throttle,
344 .unthrottle = option_rx_unthrottle,
345 .ioctl = option_ioctl,
346 .set_termios = option_set_termios, 341 .set_termios = option_set_termios,
347 .break_ctl = option_break_ctl,
348 .tiocmget = option_tiocmget, 342 .tiocmget = option_tiocmget,
349 .tiocmset = option_tiocmset, 343 .tiocmset = option_tiocmset,
350 .attach = option_startup, 344 .attach = option_startup,
@@ -401,47 +395,32 @@ static int __init option_init(void)
401 return 0; 395 return 0;
402 396
403failed_driver_register: 397failed_driver_register:
404 usb_serial_deregister (&option_1port_device); 398 usb_serial_deregister(&option_1port_device);
405failed_1port_device_register: 399failed_1port_device_register:
406 return retval; 400 return retval;
407} 401}
408 402
409static void __exit option_exit(void) 403static void __exit option_exit(void)
410{ 404{
411 usb_deregister (&option_driver); 405 usb_deregister(&option_driver);
412 usb_serial_deregister (&option_1port_device); 406 usb_serial_deregister(&option_1port_device);
413} 407}
414 408
415module_init(option_init); 409module_init(option_init);
416module_exit(option_exit); 410module_exit(option_exit);
417 411
418static void option_rx_throttle(struct usb_serial_port *port) 412static void option_set_termios(struct tty_struct *tty,
419{ 413 struct usb_serial_port *port, struct ktermios *old_termios)
420 dbg("%s", __func__);
421}
422
423static void option_rx_unthrottle(struct usb_serial_port *port)
424{
425 dbg("%s", __func__);
426}
427
428static void option_break_ctl(struct usb_serial_port *port, int break_state)
429{
430 /* Unfortunately, I don't know how to send a break */
431 dbg("%s", __func__);
432}
433
434static void option_set_termios(struct usb_serial_port *port,
435 struct ktermios *old_termios)
436{ 414{
437 dbg("%s", __func__); 415 dbg("%s", __func__);
438 /* Doesn't support option setting */ 416 /* Doesn't support option setting */
439 tty_termios_copy_hw(port->tty->termios, old_termios); 417 tty_termios_copy_hw(tty->termios, old_termios);
440 option_send_setup(port); 418 option_send_setup(tty, port);
441} 419}
442 420
443static int option_tiocmget(struct usb_serial_port *port, struct file *file) 421static int option_tiocmget(struct tty_struct *tty, struct file *file)
444{ 422{
423 struct usb_serial_port *port = tty->driver_data;
445 unsigned int value; 424 unsigned int value;
446 struct option_port_private *portdata; 425 struct option_port_private *portdata;
447 426
@@ -457,9 +436,10 @@ static int option_tiocmget(struct usb_serial_port *port, struct file *file)
457 return value; 436 return value;
458} 437}
459 438
460static int option_tiocmset(struct usb_serial_port *port, struct file *file, 439static int option_tiocmset(struct tty_struct *tty, struct file *file,
461 unsigned int set, unsigned int clear) 440 unsigned int set, unsigned int clear)
462{ 441{
442 struct usb_serial_port *port = tty->driver_data;
463 struct option_port_private *portdata; 443 struct option_port_private *portdata;
464 444
465 portdata = usb_get_serial_port_data(port); 445 portdata = usb_get_serial_port_data(port);
@@ -474,17 +454,11 @@ static int option_tiocmset(struct usb_serial_port *port, struct file *file,
474 portdata->rts_state = 0; 454 portdata->rts_state = 0;
475 if (clear & TIOCM_DTR) 455 if (clear & TIOCM_DTR)
476 portdata->dtr_state = 0; 456 portdata->dtr_state = 0;
477 return option_send_setup(port); 457 return option_send_setup(tty, port);
478}
479
480static int option_ioctl(struct usb_serial_port *port, struct file *file,
481 unsigned int cmd, unsigned long arg)
482{
483 return -ENOIOCTLCMD;
484} 458}
485 459
486/* Write */ 460/* Write */
487static int option_write(struct usb_serial_port *port, 461static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
488 const unsigned char *buf, int count) 462 const unsigned char *buf, int count)
489{ 463{
490 struct option_port_private *portdata; 464 struct option_port_private *portdata;
@@ -499,7 +473,7 @@ static int option_write(struct usb_serial_port *port,
499 473
500 i = 0; 474 i = 0;
501 left = count; 475 left = count;
502 for (i=0; left > 0 && i < N_OUT_URB; i++) { 476 for (i = 0; left > 0 && i < N_OUT_URB; i++) {
503 todo = left; 477 todo = left;
504 if (todo > OUT_BUFLEN) 478 if (todo > OUT_BUFLEN)
505 todo = OUT_BUFLEN; 479 todo = OUT_BUFLEN;
@@ -520,7 +494,7 @@ static int option_write(struct usb_serial_port *port,
520 usb_pipeendpoint(this_urb->pipe), i); 494 usb_pipeendpoint(this_urb->pipe), i);
521 495
522 /* send the data */ 496 /* send the data */
523 memcpy (this_urb->transfer_buffer, buf, todo); 497 memcpy(this_urb->transfer_buffer, buf, todo);
524 this_urb->transfer_buffer_length = todo; 498 this_urb->transfer_buffer_length = todo;
525 499
526 this_urb->dev = port->serial->dev; 500 this_urb->dev = port->serial->dev;
@@ -560,7 +534,7 @@ static void option_indat_callback(struct urb *urb)
560 dbg("%s: nonzero status: %d on endpoint %02x.", 534 dbg("%s: nonzero status: %d on endpoint %02x.",
561 __func__, status, endpoint); 535 __func__, status, endpoint);
562 } else { 536 } else {
563 tty = port->tty; 537 tty = port->port.tty;
564 if (urb->actual_length) { 538 if (urb->actual_length) {
565 tty_buffer_request_room(tty, urb->actual_length); 539 tty_buffer_request_room(tty, urb->actual_length);
566 tty_insert_flip_string(tty, data, urb->actual_length); 540 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -570,7 +544,7 @@ static void option_indat_callback(struct urb *urb)
570 } 544 }
571 545
572 /* Resubmit urb so we continue receiving */ 546 /* Resubmit urb so we continue receiving */
573 if (port->open_count && status != -ESHUTDOWN) { 547 if (port->port.count && status != -ESHUTDOWN) {
574 err = usb_submit_urb(urb, GFP_ATOMIC); 548 err = usb_submit_urb(urb, GFP_ATOMIC);
575 if (err) 549 if (err)
576 printk(KERN_ERR "%s: resubmit read urb failed. " 550 printk(KERN_ERR "%s: resubmit read urb failed. "
@@ -611,7 +585,7 @@ static void option_instat_callback(struct urb *urb)
611 struct usb_serial *serial = port->serial; 585 struct usb_serial *serial = port->serial;
612 586
613 dbg("%s", __func__); 587 dbg("%s", __func__);
614 dbg("%s: urb %p port %p has data %p", __func__,urb,port,portdata); 588 dbg("%s: urb %p port %p has data %p", __func__, urb, port, portdata);
615 589
616 if (status == 0) { 590 if (status == 0) {
617 struct usb_ctrlrequest *req_pkt = 591 struct usb_ctrlrequest *req_pkt =
@@ -636,12 +610,12 @@ static void option_instat_callback(struct urb *urb)
636 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); 610 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
637 portdata->ri_state = ((signals & 0x08) ? 1 : 0); 611 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
638 612
639 if (port->tty && !C_CLOCAL(port->tty) && 613 if (port->port.tty && !C_CLOCAL(port->port.tty) &&
640 old_dcd_state && !portdata->dcd_state) 614 old_dcd_state && !portdata->dcd_state)
641 tty_hangup(port->tty); 615 tty_hangup(port->port.tty);
642 } else { 616 } else {
643 dbg("%s: type %x req %x", __func__, 617 dbg("%s: type %x req %x", __func__,
644 req_pkt->bRequestType,req_pkt->bRequest); 618 req_pkt->bRequestType, req_pkt->bRequest);
645 } 619 }
646 } else 620 } else
647 dbg("%s: error %d", __func__, status); 621 dbg("%s: error %d", __func__, status);
@@ -656,8 +630,9 @@ static void option_instat_callback(struct urb *urb)
656 } 630 }
657} 631}
658 632
659static int option_write_room(struct usb_serial_port *port) 633static int option_write_room(struct tty_struct *tty)
660{ 634{
635 struct usb_serial_port *port = tty->driver_data;
661 struct option_port_private *portdata; 636 struct option_port_private *portdata;
662 int i; 637 int i;
663 int data_len = 0; 638 int data_len = 0;
@@ -666,7 +641,7 @@ static int option_write_room(struct usb_serial_port *port)
666 portdata = usb_get_serial_port_data(port); 641 portdata = usb_get_serial_port_data(port);
667 642
668 643
669 for (i=0; i < N_OUT_URB; i++) { 644 for (i = 0; i < N_OUT_URB; i++) {
670 this_urb = portdata->out_urbs[i]; 645 this_urb = portdata->out_urbs[i];
671 if (this_urb && !test_bit(i, &portdata->out_busy)) 646 if (this_urb && !test_bit(i, &portdata->out_busy))
672 data_len += OUT_BUFLEN; 647 data_len += OUT_BUFLEN;
@@ -676,8 +651,9 @@ static int option_write_room(struct usb_serial_port *port)
676 return data_len; 651 return data_len;
677} 652}
678 653
679static int option_chars_in_buffer(struct usb_serial_port *port) 654static int option_chars_in_buffer(struct tty_struct *tty)
680{ 655{
656 struct usb_serial_port *port = tty->driver_data;
681 struct option_port_private *portdata; 657 struct option_port_private *portdata;
682 int i; 658 int i;
683 int data_len = 0; 659 int data_len = 0;
@@ -685,7 +661,7 @@ static int option_chars_in_buffer(struct usb_serial_port *port)
685 661
686 portdata = usb_get_serial_port_data(port); 662 portdata = usb_get_serial_port_data(port);
687 663
688 for (i=0; i < N_OUT_URB; i++) { 664 for (i = 0; i < N_OUT_URB; i++) {
689 this_urb = portdata->out_urbs[i]; 665 this_urb = portdata->out_urbs[i];
690 /* FIXME: This locking is insufficient as this_urb may 666 /* FIXME: This locking is insufficient as this_urb may
691 go unused during the test */ 667 go unused during the test */
@@ -696,7 +672,8 @@ static int option_chars_in_buffer(struct usb_serial_port *port)
696 return data_len; 672 return data_len;
697} 673}
698 674
699static int option_open(struct usb_serial_port *port, struct file *filp) 675static int option_open(struct tty_struct *tty,
676 struct usb_serial_port *port, struct file *filp)
700{ 677{
701 struct option_port_private *portdata; 678 struct option_port_private *portdata;
702 struct usb_serial *serial = port->serial; 679 struct usb_serial *serial = port->serial;
@@ -714,7 +691,7 @@ static int option_open(struct usb_serial_port *port, struct file *filp)
714 /* Reset low level data toggle and start reading from endpoints */ 691 /* Reset low level data toggle and start reading from endpoints */
715 for (i = 0; i < N_IN_URB; i++) { 692 for (i = 0; i < N_IN_URB; i++) {
716 urb = portdata->in_urbs[i]; 693 urb = portdata->in_urbs[i];
717 if (! urb) 694 if (!urb)
718 continue; 695 continue;
719 if (urb->dev != serial->dev) { 696 if (urb->dev != serial->dev) {
720 dbg("%s: dev %p != %p", __func__, 697 dbg("%s: dev %p != %p", __func__,
@@ -739,21 +716,23 @@ static int option_open(struct usb_serial_port *port, struct file *filp)
739 /* Reset low level data toggle on out endpoints */ 716 /* Reset low level data toggle on out endpoints */
740 for (i = 0; i < N_OUT_URB; i++) { 717 for (i = 0; i < N_OUT_URB; i++) {
741 urb = portdata->out_urbs[i]; 718 urb = portdata->out_urbs[i];
742 if (! urb) 719 if (!urb)
743 continue; 720 continue;
744 urb->dev = serial->dev; 721 urb->dev = serial->dev;
745 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), 722 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
746 usb_pipeout(urb->pipe), 0); */ 723 usb_pipeout(urb->pipe), 0); */
747 } 724 }
748 725
749 port->tty->low_latency = 1; 726 if (tty)
727 tty->low_latency = 1;
750 728
751 option_send_setup(port); 729 option_send_setup(tty, port);
752 730
753 return (0); 731 return 0;
754} 732}
755 733
756static void option_close(struct usb_serial_port *port, struct file *filp) 734static void option_close(struct tty_struct *tty,
735 struct usb_serial_port *port, struct file *filp)
757{ 736{
758 int i; 737 int i;
759 struct usb_serial *serial = port->serial; 738 struct usb_serial *serial = port->serial;
@@ -768,7 +747,7 @@ static void option_close(struct usb_serial_port *port, struct file *filp)
768 if (serial->dev) { 747 if (serial->dev) {
769 mutex_lock(&serial->disc_mutex); 748 mutex_lock(&serial->disc_mutex);
770 if (!serial->disconnected) 749 if (!serial->disconnected)
771 option_send_setup(port); 750 option_send_setup(tty, port);
772 mutex_unlock(&serial->disc_mutex); 751 mutex_unlock(&serial->disc_mutex);
773 752
774 /* Stop reading/writing urbs */ 753 /* Stop reading/writing urbs */
@@ -777,7 +756,7 @@ static void option_close(struct usb_serial_port *port, struct file *filp)
777 for (i = 0; i < N_OUT_URB; i++) 756 for (i = 0; i < N_OUT_URB; i++)
778 usb_kill_urb(portdata->out_urbs[i]); 757 usb_kill_urb(portdata->out_urbs[i]);
779 } 758 }
780 port->tty = NULL; 759 port->port.tty = NULL; /* FIXME */
781} 760}
782 761
783/* Helper functions used by option_setup_urbs */ 762/* Helper functions used by option_setup_urbs */
@@ -807,7 +786,7 @@ static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
807/* Setup urbs */ 786/* Setup urbs */
808static void option_setup_urbs(struct usb_serial *serial) 787static void option_setup_urbs(struct usb_serial *serial)
809{ 788{
810 int i,j; 789 int i, j;
811 struct usb_serial_port *port; 790 struct usb_serial_port *port;
812 struct option_port_private *portdata; 791 struct option_port_private *portdata;
813 792
@@ -817,18 +796,22 @@ static void option_setup_urbs(struct usb_serial *serial)
817 port = serial->port[i]; 796 port = serial->port[i];
818 portdata = usb_get_serial_port_data(port); 797 portdata = usb_get_serial_port_data(port);
819 798
820 /* Do indat endpoints first */ 799 /* Do indat endpoints first */
821 for (j = 0; j < N_IN_URB; ++j) { 800 for (j = 0; j < N_IN_URB; ++j) {
822 portdata->in_urbs[j] = option_setup_urb (serial, 801 portdata->in_urbs[j] = option_setup_urb(serial,
823 port->bulk_in_endpointAddress, USB_DIR_IN, port, 802 port->bulk_in_endpointAddress,
824 portdata->in_buffer[j], IN_BUFLEN, option_indat_callback); 803 USB_DIR_IN, port,
804 portdata->in_buffer[j],
805 IN_BUFLEN, option_indat_callback);
825 } 806 }
826 807
827 /* outdat endpoints */ 808 /* outdat endpoints */
828 for (j = 0; j < N_OUT_URB; ++j) { 809 for (j = 0; j < N_OUT_URB; ++j) {
829 portdata->out_urbs[j] = option_setup_urb (serial, 810 portdata->out_urbs[j] = option_setup_urb(serial,
830 port->bulk_out_endpointAddress, USB_DIR_OUT, port, 811 port->bulk_out_endpointAddress,
831 portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback); 812 USB_DIR_OUT, port,
813 portdata->out_buffer[j],
814 OUT_BUFLEN, option_outdat_callback);
832 } 815 }
833 } 816 }
834} 817}
@@ -839,7 +822,8 @@ static void option_setup_urbs(struct usb_serial *serial)
839 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN 822 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN
840 * CDC. 823 * CDC.
841*/ 824*/
842static int option_send_setup(struct usb_serial_port *port) 825static int option_send_setup(struct tty_struct *tty,
826 struct usb_serial_port *port)
843{ 827{
844 struct usb_serial *serial = port->serial; 828 struct usb_serial *serial = port->serial;
845 struct option_port_private *portdata; 829 struct option_port_private *portdata;
@@ -848,7 +832,7 @@ static int option_send_setup(struct usb_serial_port *port)
848 832
849 portdata = usb_get_serial_port_data(port); 833 portdata = usb_get_serial_port_data(port);
850 834
851 if (port->tty) { 835 if (tty) {
852 int val = 0; 836 int val = 0;
853 if (portdata->dtr_state) 837 if (portdata->dtr_state)
854 val |= 0x01; 838 val |= 0x01;
@@ -856,10 +840,9 @@ static int option_send_setup(struct usb_serial_port *port)
856 val |= 0x02; 840 val |= 0x02;
857 841
858 return usb_control_msg(serial->dev, 842 return usb_control_msg(serial->dev,
859 usb_rcvctrlpipe(serial->dev, 0), 843 usb_rcvctrlpipe(serial->dev, 0),
860 0x22,0x21,val,ifNum,NULL,0,USB_CTRL_SET_TIMEOUT); 844 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT);
861 } 845 }
862
863 return 0; 846 return 0;
864} 847}
865 848
@@ -879,7 +862,7 @@ static int option_startup(struct usb_serial *serial)
879 if (!portdata) { 862 if (!portdata) {
880 dbg("%s: kmalloc for option_port_private (%d) failed!.", 863 dbg("%s: kmalloc for option_port_private (%d) failed!.",
881 __func__, i); 864 __func__, i);
882 return (1); 865 return 1;
883 } 866 }
884 867
885 for (j = 0; j < N_IN_URB; j++) { 868 for (j = 0; j < N_IN_URB; j++) {
@@ -898,17 +881,15 @@ static int option_startup(struct usb_serial *serial)
898 881
899 usb_set_serial_port_data(port, portdata); 882 usb_set_serial_port_data(port, portdata);
900 883
901 if (! port->interrupt_in_urb) 884 if (!port->interrupt_in_urb)
902 continue; 885 continue;
903 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 886 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
904 if (err) 887 if (err)
905 dbg("%s: submit irq_in urb failed %d", 888 dbg("%s: submit irq_in urb failed %d",
906 __func__, err); 889 __func__, err);
907 } 890 }
908
909 option_setup_urbs(serial); 891 option_setup_urbs(serial);
910 892 return 0;
911 return (0);
912 893
913bail_out_error2: 894bail_out_error2:
914 for (j = 0; j < N_OUT_URB; j++) 895 for (j = 0; j < N_OUT_URB; j++)
@@ -947,7 +928,8 @@ static void option_shutdown(struct usb_serial *serial)
947 for (j = 0; j < N_IN_URB; j++) { 928 for (j = 0; j < N_IN_URB; j++) {
948 if (portdata->in_urbs[j]) { 929 if (portdata->in_urbs[j]) {
949 usb_free_urb(portdata->in_urbs[j]); 930 usb_free_urb(portdata->in_urbs[j]);
950 free_page((unsigned long)portdata->in_buffer[j]); 931 free_page((unsigned long)
932 portdata->in_buffer[j]);
951 portdata->in_urbs[j] = NULL; 933 portdata->in_urbs[j] = NULL;
952 } 934 }
953 } 935 }
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index a9625c180dc3..81db5715ee25 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -25,7 +25,8 @@
25 * it under the terms of the GNU General Public License as published by 25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License. 26 * the Free Software Foundation; either version 2 of the License.
27 * 27 *
28 * See Documentation/usb/usb-serial.txt for more information on using this driver 28 * See Documentation/usb/usb-serial.txt for more information on using this
29 * driver
29 * 30 *
30 * TODO: 31 * TODO:
31 * - implement correct flushing for ioctls and oti6858_close() 32 * - implement correct flushing for ioctls and oti6858_close()
@@ -49,7 +50,7 @@
49#include <linux/spinlock.h> 50#include <linux/spinlock.h>
50#include <linux/usb.h> 51#include <linux/usb.h>
51#include <linux/usb/serial.h> 52#include <linux/usb/serial.h>
52#include <asm/uaccess.h> 53#include <linux/uaccess.h>
53#include "oti6858.h" 54#include "oti6858.h"
54 55
55#define OTI6858_DESCRIPTION \ 56#define OTI6858_DESCRIPTION \
@@ -135,27 +136,28 @@ struct oti6858_control_pkt {
135 136
136#define OTI6858_CTRL_PKT_SIZE sizeof(struct oti6858_control_pkt) 137#define OTI6858_CTRL_PKT_SIZE sizeof(struct oti6858_control_pkt)
137#define OTI6858_CTRL_EQUALS_PENDING(a, priv) \ 138#define OTI6858_CTRL_EQUALS_PENDING(a, priv) \
138 ( ((a)->divisor == (priv)->pending_setup.divisor) \ 139 (((a)->divisor == (priv)->pending_setup.divisor) \
139 && ((a)->control == (priv)->pending_setup.control) \ 140 && ((a)->control == (priv)->pending_setup.control) \
140 && ((a)->frame_fmt == (priv)->pending_setup.frame_fmt) ) 141 && ((a)->frame_fmt == (priv)->pending_setup.frame_fmt))
141 142
142/* function prototypes */ 143/* function prototypes */
143static int oti6858_open(struct usb_serial_port *port, struct file *filp); 144static int oti6858_open(struct tty_struct *tty,
144static void oti6858_close(struct usb_serial_port *port, struct file *filp); 145 struct usb_serial_port *port, struct file *filp);
145static void oti6858_set_termios(struct usb_serial_port *port, 146static void oti6858_close(struct tty_struct *tty,
146 struct ktermios *old); 147 struct usb_serial_port *port, struct file *filp);
147static int oti6858_ioctl(struct usb_serial_port *port, struct file *file, 148static void oti6858_set_termios(struct tty_struct *tty,
149 struct usb_serial_port *port, struct ktermios *old);
150static int oti6858_ioctl(struct tty_struct *tty, struct file *file,
148 unsigned int cmd, unsigned long arg); 151 unsigned int cmd, unsigned long arg);
149static void oti6858_read_int_callback(struct urb *urb); 152static void oti6858_read_int_callback(struct urb *urb);
150static void oti6858_read_bulk_callback(struct urb *urb); 153static void oti6858_read_bulk_callback(struct urb *urb);
151static void oti6858_write_bulk_callback(struct urb *urb); 154static void oti6858_write_bulk_callback(struct urb *urb);
152static int oti6858_write(struct usb_serial_port *port, 155static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
153 const unsigned char *buf, int count); 156 const unsigned char *buf, int count);
154static int oti6858_write_room(struct usb_serial_port *port); 157static int oti6858_write_room(struct tty_struct *tty);
155static void oti6858_break_ctl(struct usb_serial_port *port, int break_state); 158static int oti6858_chars_in_buffer(struct tty_struct *tty);
156static int oti6858_chars_in_buffer(struct usb_serial_port *port); 159static int oti6858_tiocmget(struct tty_struct *tty, struct file *file);
157static int oti6858_tiocmget(struct usb_serial_port *port, struct file *file); 160static int oti6858_tiocmset(struct tty_struct *tty, struct file *file,
158static int oti6858_tiocmset(struct usb_serial_port *port, struct file *file,
159 unsigned int set, unsigned int clear); 161 unsigned int set, unsigned int clear);
160static int oti6858_startup(struct usb_serial *serial); 162static int oti6858_startup(struct usb_serial *serial);
161static void oti6858_shutdown(struct usb_serial *serial); 163static void oti6858_shutdown(struct usb_serial *serial);
@@ -184,7 +186,6 @@ static struct usb_serial_driver oti6858_device = {
184 .close = oti6858_close, 186 .close = oti6858_close,
185 .write = oti6858_write, 187 .write = oti6858_write,
186 .ioctl = oti6858_ioctl, 188 .ioctl = oti6858_ioctl,
187 .break_ctl = oti6858_break_ctl,
188 .set_termios = oti6858_set_termios, 189 .set_termios = oti6858_set_termios,
189 .tiocmget = oti6858_tiocmget, 190 .tiocmget = oti6858_tiocmget,
190 .tiocmset = oti6858_tiocmset, 191 .tiocmset = oti6858_tiocmset,
@@ -220,7 +221,7 @@ struct oti6858_private {
220 struct delayed_work delayed_setup_work; 221 struct delayed_work delayed_setup_work;
221 222
222 wait_queue_head_t intr_wait; 223 wait_queue_head_t intr_wait;
223 struct usb_serial_port *port; /* USB port with which associated */ 224 struct usb_serial_port *port; /* USB port with which associated */
224}; 225};
225 226
226#undef dbg 227#undef dbg
@@ -229,7 +230,8 @@ struct oti6858_private {
229 230
230static void setup_line(struct work_struct *work) 231static void setup_line(struct work_struct *work)
231{ 232{
232 struct oti6858_private *priv = container_of(work, struct oti6858_private, delayed_setup_work.work); 233 struct oti6858_private *priv = container_of(work,
234 struct oti6858_private, delayed_setup_work.work);
233 struct usb_serial_port *port = priv->port; 235 struct usb_serial_port *port = priv->port;
234 struct oti6858_control_pkt *new_setup; 236 struct oti6858_control_pkt *new_setup;
235 unsigned long flags; 237 unsigned long flags;
@@ -237,10 +239,12 @@ static void setup_line(struct work_struct *work)
237 239
238 dbg("%s(port = %d)", __func__, port->number); 240 dbg("%s(port = %d)", __func__, port->number);
239 241
240 if ((new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL)) == NULL) { 242 new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL);
243 if (new_setup == NULL) {
241 dev_err(&port->dev, "%s(): out of memory!\n", __func__); 244 dev_err(&port->dev, "%s(): out of memory!\n", __func__);
242 /* we will try again */ 245 /* we will try again */
243 schedule_delayed_work(&priv->delayed_setup_work, msecs_to_jiffies(2)); 246 schedule_delayed_work(&priv->delayed_setup_work,
247 msecs_to_jiffies(2));
244 return; 248 return;
245 } 249 }
246 250
@@ -256,7 +260,8 @@ static void setup_line(struct work_struct *work)
256 dev_err(&port->dev, "%s(): error reading status\n", __func__); 260 dev_err(&port->dev, "%s(): error reading status\n", __func__);
257 kfree(new_setup); 261 kfree(new_setup);
258 /* we will try again */ 262 /* we will try again */
259 schedule_delayed_work(&priv->delayed_setup_work, msecs_to_jiffies(2)); 263 schedule_delayed_work(&priv->delayed_setup_work,
264 msecs_to_jiffies(2));
260 return; 265 return;
261 } 266 }
262 267
@@ -297,7 +302,8 @@ static void setup_line(struct work_struct *work)
297 302
298void send_data(struct work_struct *work) 303void send_data(struct work_struct *work)
299{ 304{
300 struct oti6858_private *priv = container_of(work, struct oti6858_private, delayed_write_work.work); 305 struct oti6858_private *priv = container_of(work,
306 struct oti6858_private, delayed_write_work.work);
301 struct usb_serial_port *port = priv->port; 307 struct usb_serial_port *port = priv->port;
302 int count = 0, result; 308 int count = 0, result;
303 unsigned long flags; 309 unsigned long flags;
@@ -308,7 +314,8 @@ void send_data(struct work_struct *work)
308 spin_lock_irqsave(&priv->lock, flags); 314 spin_lock_irqsave(&priv->lock, flags);
309 if (priv->flags.write_urb_in_use) { 315 if (priv->flags.write_urb_in_use) {
310 spin_unlock_irqrestore(&priv->lock, flags); 316 spin_unlock_irqrestore(&priv->lock, flags);
311 schedule_delayed_work(&priv->delayed_write_work, msecs_to_jiffies(2)); 317 schedule_delayed_work(&priv->delayed_write_work,
318 msecs_to_jiffies(2));
312 return; 319 return;
313 } 320 }
314 priv->flags.write_urb_in_use = 1; 321 priv->flags.write_urb_in_use = 1;
@@ -359,8 +366,8 @@ void send_data(struct work_struct *work)
359 366
360static int oti6858_startup(struct usb_serial *serial) 367static int oti6858_startup(struct usb_serial *serial)
361{ 368{
362 struct usb_serial_port *port = serial->port[0]; 369 struct usb_serial_port *port = serial->port[0];
363 struct oti6858_private *priv; 370 struct oti6858_private *priv;
364 int i; 371 int i;
365 372
366 for (i = 0; i < serial->num_ports; ++i) { 373 for (i = 0; i < serial->num_ports; ++i) {
@@ -375,8 +382,8 @@ static int oti6858_startup(struct usb_serial *serial)
375 382
376 spin_lock_init(&priv->lock); 383 spin_lock_init(&priv->lock);
377 init_waitqueue_head(&priv->intr_wait); 384 init_waitqueue_head(&priv->intr_wait);
378// INIT_WORK(&priv->setup_work, setup_line, serial->port[i]); 385/* INIT_WORK(&priv->setup_work, setup_line, serial->port[i]); */
379// INIT_WORK(&priv->write_work, send_data, serial->port[i]); 386/* INIT_WORK(&priv->write_work, send_data, serial->port[i]); */
380 priv->port = port; 387 priv->port = port;
381 INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line); 388 INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line);
382 INIT_DELAYED_WORK(&priv->delayed_write_work, send_data); 389 INIT_DELAYED_WORK(&priv->delayed_write_work, send_data);
@@ -395,7 +402,7 @@ static int oti6858_startup(struct usb_serial *serial)
395 return -ENOMEM; 402 return -ENOMEM;
396} 403}
397 404
398static int oti6858_write(struct usb_serial_port *port, 405static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
399 const unsigned char *buf, int count) 406 const unsigned char *buf, int count)
400{ 407{
401 struct oti6858_private *priv = usb_get_serial_port_data(port); 408 struct oti6858_private *priv = usb_get_serial_port_data(port);
@@ -413,8 +420,9 @@ static int oti6858_write(struct usb_serial_port *port,
413 return count; 420 return count;
414} 421}
415 422
416static int oti6858_write_room(struct usb_serial_port *port) 423static int oti6858_write_room(struct tty_struct *tty)
417{ 424{
425 struct usb_serial_port *port = tty->driver_data;
418 struct oti6858_private *priv = usb_get_serial_port_data(port); 426 struct oti6858_private *priv = usb_get_serial_port_data(port);
419 int room = 0; 427 int room = 0;
420 unsigned long flags; 428 unsigned long flags;
@@ -428,8 +436,9 @@ static int oti6858_write_room(struct usb_serial_port *port)
428 return room; 436 return room;
429} 437}
430 438
431static int oti6858_chars_in_buffer(struct usb_serial_port *port) 439static int oti6858_chars_in_buffer(struct tty_struct *tty)
432{ 440{
441 struct usb_serial_port *port = tty->driver_data;
433 struct oti6858_private *priv = usb_get_serial_port_data(port); 442 struct oti6858_private *priv = usb_get_serial_port_data(port);
434 int chars = 0; 443 int chars = 0;
435 unsigned long flags; 444 unsigned long flags;
@@ -443,8 +452,8 @@ static int oti6858_chars_in_buffer(struct usb_serial_port *port)
443 return chars; 452 return chars;
444} 453}
445 454
446static void oti6858_set_termios(struct usb_serial_port *port, 455static void oti6858_set_termios(struct tty_struct *tty,
447 struct ktermios *old_termios) 456 struct usb_serial_port *port, struct ktermios *old_termios)
448{ 457{
449 struct oti6858_private *priv = usb_get_serial_port_data(port); 458 struct oti6858_private *priv = usb_get_serial_port_data(port);
450 unsigned long flags; 459 unsigned long flags;
@@ -455,22 +464,22 @@ static void oti6858_set_termios(struct usb_serial_port *port,
455 464
456 dbg("%s(port = %d)", __func__, port->number); 465 dbg("%s(port = %d)", __func__, port->number);
457 466
458 if (!port->tty || !port->tty->termios) { 467 if (!tty) {
459 dbg("%s(): no tty structures", __func__); 468 dbg("%s(): no tty structures", __func__);
460 return; 469 return;
461 } 470 }
462 471
463 spin_lock_irqsave(&priv->lock, flags); 472 spin_lock_irqsave(&priv->lock, flags);
464 if (!priv->flags.termios_initialized) { 473 if (!priv->flags.termios_initialized) {
465 *(port->tty->termios) = tty_std_termios; 474 *(tty->termios) = tty_std_termios;
466 port->tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL; 475 tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL;
476 tty->termios->c_ispeed = 38400;
477 tty->termios->c_ospeed = 38400;
467 priv->flags.termios_initialized = 1; 478 priv->flags.termios_initialized = 1;
468 port->tty->termios->c_ispeed = 38400;
469 port->tty->termios->c_ospeed = 38400;
470 } 479 }
471 spin_unlock_irqrestore(&priv->lock, flags); 480 spin_unlock_irqrestore(&priv->lock, flags);
472 481
473 cflag = port->tty->termios->c_cflag; 482 cflag = tty->termios->c_cflag;
474 483
475 spin_lock_irqsave(&priv->lock, flags); 484 spin_lock_irqsave(&priv->lock, flags);
476 divisor = priv->pending_setup.divisor; 485 divisor = priv->pending_setup.divisor;
@@ -480,19 +489,19 @@ static void oti6858_set_termios(struct usb_serial_port *port,
480 489
481 frame_fmt &= ~FMT_DATA_BITS_MASK; 490 frame_fmt &= ~FMT_DATA_BITS_MASK;
482 switch (cflag & CSIZE) { 491 switch (cflag & CSIZE) {
483 case CS5: 492 case CS5:
484 frame_fmt |= FMT_DATA_BITS_5; 493 frame_fmt |= FMT_DATA_BITS_5;
485 break; 494 break;
486 case CS6: 495 case CS6:
487 frame_fmt |= FMT_DATA_BITS_6; 496 frame_fmt |= FMT_DATA_BITS_6;
488 break; 497 break;
489 case CS7: 498 case CS7:
490 frame_fmt |= FMT_DATA_BITS_7; 499 frame_fmt |= FMT_DATA_BITS_7;
491 break; 500 break;
492 default: 501 default:
493 case CS8: 502 case CS8:
494 frame_fmt |= FMT_DATA_BITS_8; 503 frame_fmt |= FMT_DATA_BITS_8;
495 break; 504 break;
496 } 505 }
497 506
498 /* manufacturer claims that this device can work with baud rates 507 /* manufacturer claims that this device can work with baud rates
@@ -500,7 +509,7 @@ static void oti6858_set_termios(struct usb_serial_port *port,
500 * guarantee that any other baud rate will work (especially 509 * guarantee that any other baud rate will work (especially
501 * the higher ones) 510 * the higher ones)
502 */ 511 */
503 br = tty_get_baud_rate(port->tty); 512 br = tty_get_baud_rate(tty);
504 if (br == 0) { 513 if (br == 0) {
505 divisor = 0; 514 divisor = 0;
506 } else { 515 } else {
@@ -511,23 +520,21 @@ static void oti6858_set_termios(struct usb_serial_port *port,
511 new_divisor = (96000000 + 8 * br) / (16 * br); 520 new_divisor = (96000000 + 8 * br) / (16 * br);
512 real_br = 96000000 / (16 * new_divisor); 521 real_br = 96000000 / (16 * new_divisor);
513 divisor = cpu_to_le16(new_divisor); 522 divisor = cpu_to_le16(new_divisor);
514 tty_encode_baud_rate(port->tty, real_br, real_br); 523 tty_encode_baud_rate(tty, real_br, real_br);
515 } 524 }
516 525
517 frame_fmt &= ~FMT_STOP_BITS_MASK; 526 frame_fmt &= ~FMT_STOP_BITS_MASK;
518 if ((cflag & CSTOPB) != 0) { 527 if ((cflag & CSTOPB) != 0)
519 frame_fmt |= FMT_STOP_BITS_2; 528 frame_fmt |= FMT_STOP_BITS_2;
520 } else { 529 else
521 frame_fmt |= FMT_STOP_BITS_1; 530 frame_fmt |= FMT_STOP_BITS_1;
522 }
523 531
524 frame_fmt &= ~FMT_PARITY_MASK; 532 frame_fmt &= ~FMT_PARITY_MASK;
525 if ((cflag & PARENB) != 0) { 533 if ((cflag & PARENB) != 0) {
526 if ((cflag & PARODD) != 0) { 534 if ((cflag & PARODD) != 0)
527 frame_fmt |= FMT_PARITY_ODD; 535 frame_fmt |= FMT_PARITY_ODD;
528 } else { 536 else
529 frame_fmt |= FMT_PARITY_EVEN; 537 frame_fmt |= FMT_PARITY_EVEN;
530 }
531 } else { 538 } else {
532 frame_fmt |= FMT_PARITY_NONE; 539 frame_fmt |= FMT_PARITY_NONE;
533 } 540 }
@@ -564,7 +571,8 @@ static void oti6858_set_termios(struct usb_serial_port *port,
564 spin_unlock_irqrestore(&priv->lock, flags); 571 spin_unlock_irqrestore(&priv->lock, flags);
565} 572}
566 573
567static int oti6858_open(struct usb_serial_port *port, struct file *filp) 574static int oti6858_open(struct tty_struct *tty,
575 struct usb_serial_port *port, struct file *filp)
568{ 576{
569 struct oti6858_private *priv = usb_get_serial_port_data(port); 577 struct oti6858_private *priv = usb_get_serial_port_data(port);
570 struct ktermios tmp_termios; 578 struct ktermios tmp_termios;
@@ -578,10 +586,11 @@ static int oti6858_open(struct usb_serial_port *port, struct file *filp)
578 usb_clear_halt(serial->dev, port->write_urb->pipe); 586 usb_clear_halt(serial->dev, port->write_urb->pipe);
579 usb_clear_halt(serial->dev, port->read_urb->pipe); 587 usb_clear_halt(serial->dev, port->read_urb->pipe);
580 588
581 if (port->open_count != 1) 589 if (port->port.count != 1)
582 return 0; 590 return 0;
583 591
584 if ((buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL)) == NULL) { 592 buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL);
593 if (buf == NULL) {
585 dev_err(&port->dev, "%s(): out of memory!\n", __func__); 594 dev_err(&port->dev, "%s(): out of memory!\n", __func__);
586 return -ENOMEM; 595 return -ENOMEM;
587 } 596 }
@@ -617,18 +626,19 @@ static int oti6858_open(struct usb_serial_port *port, struct file *filp)
617 if (result != 0) { 626 if (result != 0) {
618 dev_err(&port->dev, "%s(): usb_submit_urb() failed" 627 dev_err(&port->dev, "%s(): usb_submit_urb() failed"
619 " with error %d\n", __func__, result); 628 " with error %d\n", __func__, result);
620 oti6858_close(port, NULL); 629 oti6858_close(tty, port, NULL);
621 return -EPROTO; 630 return -EPROTO;
622 } 631 }
623 632
624 /* setup termios */ 633 /* setup termios */
625 if (port->tty) 634 if (tty)
626 oti6858_set_termios(port, &tmp_termios); 635 oti6858_set_termios(tty, port, &tmp_termios);
627 636
628 return 0; 637 return 0;
629} 638}
630 639
631static void oti6858_close(struct usb_serial_port *port, struct file *filp) 640static void oti6858_close(struct tty_struct *tty,
641 struct usb_serial_port *port, struct file *filp)
632{ 642{
633 struct oti6858_private *priv = usb_get_serial_port_data(port); 643 struct oti6858_private *priv = usb_get_serial_port_data(port);
634 unsigned long flags; 644 unsigned long flags;
@@ -641,7 +651,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
641 spin_lock_irqsave(&priv->lock, flags); 651 spin_lock_irqsave(&priv->lock, flags);
642 timeout = 30 * HZ; /* PL2303_CLOSING_WAIT */ 652 timeout = 30 * HZ; /* PL2303_CLOSING_WAIT */
643 init_waitqueue_entry(&wait, current); 653 init_waitqueue_entry(&wait, current);
644 add_wait_queue(&port->tty->write_wait, &wait); 654 add_wait_queue(&tty->write_wait, &wait);
645 dbg("%s(): entering wait loop", __func__); 655 dbg("%s(): entering wait loop", __func__);
646 for (;;) { 656 for (;;) {
647 set_current_state(TASK_INTERRUPTIBLE); 657 set_current_state(TASK_INTERRUPTIBLE);
@@ -654,7 +664,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
654 spin_lock_irqsave(&priv->lock, flags); 664 spin_lock_irqsave(&priv->lock, flags);
655 } 665 }
656 set_current_state(TASK_RUNNING); 666 set_current_state(TASK_RUNNING);
657 remove_wait_queue(&port->tty->write_wait, &wait); 667 remove_wait_queue(&tty->write_wait, &wait);
658 dbg("%s(): after wait loop", __func__); 668 dbg("%s(): after wait loop", __func__);
659 669
660 /* clear out any remaining data in the buffer */ 670 /* clear out any remaining data in the buffer */
@@ -669,7 +679,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
669 /* data is in the buffer to compute a delay */ 679 /* data is in the buffer to compute a delay */
670 /* that is not unnecessarily long) */ 680 /* that is not unnecessarily long) */
671 /* FIXME 681 /* FIXME
672 bps = tty_get_baud_rate(port->tty); 682 bps = tty_get_baud_rate(tty);
673 if (bps > 1200) 683 if (bps > 1200)
674 timeout = max((HZ*2560)/bps,HZ/10); 684 timeout = max((HZ*2560)/bps,HZ/10);
675 else 685 else
@@ -690,7 +700,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
690 usb_kill_urb(port->interrupt_in_urb); 700 usb_kill_urb(port->interrupt_in_urb);
691 701
692 /* 702 /*
693 if (port->tty && (port->tty->termios->c_cflag) & HUPCL) { 703 if (tty && (tty->termios->c_cflag) & HUPCL) {
694 // drop DTR and RTS 704 // drop DTR and RTS
695 spin_lock_irqsave(&priv->lock, flags); 705 spin_lock_irqsave(&priv->lock, flags);
696 priv->pending_setup.control &= ~CONTROL_MASK; 706 priv->pending_setup.control &= ~CONTROL_MASK;
@@ -699,9 +709,10 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
699 */ 709 */
700} 710}
701 711
702static int oti6858_tiocmset(struct usb_serial_port *port, struct file *file, 712static int oti6858_tiocmset(struct tty_struct *tty, struct file *file,
703 unsigned int set, unsigned int clear) 713 unsigned int set, unsigned int clear)
704{ 714{
715 struct usb_serial_port *port = tty->driver_data;
705 struct oti6858_private *priv = usb_get_serial_port_data(port); 716 struct oti6858_private *priv = usb_get_serial_port_data(port);
706 unsigned long flags; 717 unsigned long flags;
707 u8 control; 718 u8 control;
@@ -724,16 +735,16 @@ static int oti6858_tiocmset(struct usb_serial_port *port, struct file *file,
724 if ((clear & TIOCM_DTR) != 0) 735 if ((clear & TIOCM_DTR) != 0)
725 control &= ~CONTROL_DTR_HIGH; 736 control &= ~CONTROL_DTR_HIGH;
726 737
727 if (control != priv->pending_setup.control) { 738 if (control != priv->pending_setup.control)
728 priv->pending_setup.control = control; 739 priv->pending_setup.control = control;
729 }
730 spin_unlock_irqrestore(&priv->lock, flags);
731 740
741 spin_unlock_irqrestore(&priv->lock, flags);
732 return 0; 742 return 0;
733} 743}
734 744
735static int oti6858_tiocmget(struct usb_serial_port *port, struct file *file) 745static int oti6858_tiocmget(struct tty_struct *tty, struct file *file)
736{ 746{
747 struct usb_serial_port *port = tty->driver_data;
737 struct oti6858_private *priv = usb_get_serial_port_data(port); 748 struct oti6858_private *priv = usb_get_serial_port_data(port);
738 unsigned long flags; 749 unsigned long flags;
739 unsigned pin_state; 750 unsigned pin_state;
@@ -779,7 +790,8 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
779 spin_unlock_irqrestore(&priv->lock, flags); 790 spin_unlock_irqrestore(&priv->lock, flags);
780 791
781 while (1) { 792 while (1) {
782 wait_event_interruptible(priv->intr_wait, priv->status.pin_state != prev); 793 wait_event_interruptible(priv->intr_wait,
794 priv->status.pin_state != prev);
783 if (signal_pending(current)) 795 if (signal_pending(current))
784 return -ERESTARTSYS; 796 return -ERESTARTSYS;
785 797
@@ -789,12 +801,11 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
789 801
790 changed = prev ^ status; 802 changed = prev ^ status;
791 /* FIXME: check if this is correct (active high/low) */ 803 /* FIXME: check if this is correct (active high/low) */
792 if ( ((arg & TIOCM_RNG) && (changed & PIN_RI)) || 804 if (((arg & TIOCM_RNG) && (changed & PIN_RI)) ||
793 ((arg & TIOCM_DSR) && (changed & PIN_DSR)) || 805 ((arg & TIOCM_DSR) && (changed & PIN_DSR)) ||
794 ((arg & TIOCM_CD) && (changed & PIN_DCD)) || 806 ((arg & TIOCM_CD) && (changed & PIN_DCD)) ||
795 ((arg & TIOCM_CTS) && (changed & PIN_CTS))) { 807 ((arg & TIOCM_CTS) && (changed & PIN_CTS)))
796 return 0; 808 return 0;
797 }
798 prev = status; 809 prev = status;
799 } 810 }
800 811
@@ -802,56 +813,25 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
802 return 0; 813 return 0;
803} 814}
804 815
805static int oti6858_ioctl(struct usb_serial_port *port, struct file *file, 816static int oti6858_ioctl(struct tty_struct *tty, struct file *file,
806 unsigned int cmd, unsigned long arg) 817 unsigned int cmd, unsigned long arg)
807{ 818{
808 void __user *user_arg = (void __user *) arg; 819 struct usb_serial_port *port = tty->driver_data;
809 unsigned int x;
810 820
811 dbg("%s(port = %d, cmd = 0x%04x, arg = 0x%08lx)", 821 dbg("%s(port = %d, cmd = 0x%04x, arg = 0x%08lx)",
812 __func__, port->number, cmd, arg); 822 __func__, port->number, cmd, arg);
813 823
814 switch (cmd) { 824 switch (cmd) {
815 case TIOCMBIS: 825 case TIOCMIWAIT:
816 if (copy_from_user(&x, user_arg, sizeof(x))) 826 dbg("%s(): TIOCMIWAIT", __func__);
817 return -EFAULT; 827 return wait_modem_info(port, arg);
818 return oti6858_tiocmset(port, NULL, x, 0); 828 default:
819 829 dbg("%s(): 0x%04x not supported", __func__, cmd);
820 case TIOCMBIC: 830 break;
821 if (copy_from_user(&x, user_arg, sizeof(x)))
822 return -EFAULT;
823 return oti6858_tiocmset(port, NULL, 0, x);
824
825 case TIOCMIWAIT:
826 dbg("%s(): TIOCMIWAIT", __func__);
827 return wait_modem_info(port, arg);
828
829 default:
830 dbg("%s(): 0x%04x not supported", __func__, cmd);
831 break;
832 } 831 }
833
834 return -ENOIOCTLCMD; 832 return -ENOIOCTLCMD;
835} 833}
836 834
837static void oti6858_break_ctl(struct usb_serial_port *port, int break_state)
838{
839 int state;
840
841 dbg("%s(port = %d)", __func__, port->number);
842
843 state = (break_state == 0) ? 0 : 1;
844 dbg("%s(): turning break %s", __func__, state ? "on" : "off");
845
846 /* FIXME */
847/*
848 result = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
849 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
850 0, NULL, 0, 100);
851 if (result != 0)
852 dbg("%s(): error sending break", __func__);
853 */
854}
855 835
856static void oti6858_shutdown(struct usb_serial *serial) 836static void oti6858_shutdown(struct usb_serial *serial)
857{ 837{
@@ -964,7 +944,7 @@ static void oti6858_read_int_callback(struct urb *urb)
964 spin_lock_irqsave(&priv->lock, flags); 944 spin_lock_irqsave(&priv->lock, flags);
965 if (priv->flags.write_urb_in_use == 0 945 if (priv->flags.write_urb_in_use == 0
966 && oti6858_buf_data_avail(priv->buf) != 0) { 946 && oti6858_buf_data_avail(priv->buf) != 0) {
967 schedule_delayed_work(&priv->delayed_write_work,0); 947 schedule_delayed_work(&priv->delayed_write_work, 0);
968 resubmit = 0; 948 resubmit = 0;
969 } 949 }
970 spin_unlock_irqrestore(&priv->lock, flags); 950 spin_unlock_irqrestore(&priv->lock, flags);
@@ -973,7 +953,7 @@ static void oti6858_read_int_callback(struct urb *urb)
973 if (resubmit) { 953 if (resubmit) {
974 int result; 954 int result;
975 955
976// dbg("%s(): submitting interrupt urb", __func__); 956/* dbg("%s(): submitting interrupt urb", __func__); */
977 urb->dev = port->serial->dev; 957 urb->dev = port->serial->dev;
978 result = usb_submit_urb(urb, GFP_ATOMIC); 958 result = usb_submit_urb(urb, GFP_ATOMIC);
979 if (result != 0) { 959 if (result != 0) {
@@ -1002,14 +982,16 @@ static void oti6858_read_bulk_callback(struct urb *urb)
1002 spin_unlock_irqrestore(&priv->lock, flags); 982 spin_unlock_irqrestore(&priv->lock, flags);
1003 983
1004 if (status != 0) { 984 if (status != 0) {
1005 if (!port->open_count) { 985 if (!port->port.count) {
1006 dbg("%s(): port is closed, exiting", __func__); 986 dbg("%s(): port is closed, exiting", __func__);
1007 return; 987 return;
1008 } 988 }
1009 /* 989 /*
1010 if (status == -EPROTO) { 990 if (status == -EPROTO) {
1011 // PL2303 mysteriously fails with -EPROTO reschedule the read 991 * PL2303 mysteriously fails with -EPROTO reschedule
1012 dbg("%s - caught -EPROTO, resubmitting the urb", __func__); 992 the read *
993 dbg("%s - caught -EPROTO, resubmitting the urb",
994 __func__);
1013 result = usb_submit_urb(urb, GFP_ATOMIC); 995 result = usb_submit_urb(urb, GFP_ATOMIC);
1014 if (result) 996 if (result)
1015 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 997 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
@@ -1020,14 +1002,14 @@ static void oti6858_read_bulk_callback(struct urb *urb)
1020 return; 1002 return;
1021 } 1003 }
1022 1004
1023 tty = port->tty; 1005 tty = port->port.tty;
1024 if (tty != NULL && urb->actual_length > 0) { 1006 if (tty != NULL && urb->actual_length > 0) {
1025 tty_insert_flip_string(tty, data, urb->actual_length); 1007 tty_insert_flip_string(tty, data, urb->actual_length);
1026 tty_flip_buffer_push(tty); 1008 tty_flip_buffer_push(tty);
1027 } 1009 }
1028 1010
1029 // schedule the interrupt urb if we are still open */ 1011 /* schedule the interrupt urb if we are still open */
1030 if (port->open_count != 0) { 1012 if (port->port.count != 0) {
1031 port->interrupt_in_urb->dev = port->serial->dev; 1013 port->interrupt_in_urb->dev = port->serial->dev;
1032 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1014 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1033 if (result != 0) { 1015 if (result != 0) {
@@ -1078,7 +1060,7 @@ static void oti6858_write_bulk_callback(struct urb *urb)
1078 1060
1079 priv->flags.write_urb_in_use = 0; 1061 priv->flags.write_urb_in_use = 0;
1080 1062
1081 // schedule the interrupt urb if we are still open */ 1063 /* schedule the interrupt urb if we are still open */
1082 port->interrupt_in_urb->dev = port->serial->dev; 1064 port->interrupt_in_urb->dev = port->serial->dev;
1083 dbg("%s(): submitting interrupt urb", __func__); 1065 dbg("%s(): submitting interrupt urb", __func__);
1084 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1066 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
@@ -1153,7 +1135,7 @@ static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb)
1153{ 1135{
1154 if (pb == NULL) 1136 if (pb == NULL)
1155 return 0; 1137 return 0;
1156 return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); 1138 return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size;
1157} 1139}
1158 1140
1159/* 1141/*
@@ -1166,7 +1148,7 @@ static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb)
1166{ 1148{
1167 if (pb == NULL) 1149 if (pb == NULL)
1168 return 0; 1150 return 0;
1169 return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); 1151 return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size;
1170} 1152}
1171 1153
1172/* 1154/*
@@ -1253,13 +1235,12 @@ static int __init oti6858_init(void)
1253{ 1235{
1254 int retval; 1236 int retval;
1255 1237
1256 if ((retval = usb_serial_register(&oti6858_device)) == 0) { 1238 retval = usb_serial_register(&oti6858_device);
1257 if ((retval = usb_register(&oti6858_driver)) != 0) 1239 if (retval == 0) {
1240 retval = usb_register(&oti6858_driver);
1241 if (retval)
1258 usb_serial_deregister(&oti6858_device); 1242 usb_serial_deregister(&oti6858_device);
1259 else
1260 return 0;
1261 } 1243 }
1262
1263 return retval; 1244 return retval;
1264} 1245}
1265 1246
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 2a0dd1b50dc4..2c9c446ad625 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -10,7 +10,8 @@
10 * modify it under the terms of the GNU General Public License version 10 * modify it under the terms of the GNU General Public License version
11 * 2 as published by the Free Software Foundation. 11 * 2 as published by the Free Software Foundation.
12 * 12 *
13 * See Documentation/usb/usb-serial.txt for more information on using this driver 13 * See Documentation/usb/usb-serial.txt for more information on using this
14 * driver
14 * 15 *
15 */ 16 */
16 17
@@ -25,7 +26,7 @@
25#include <linux/module.h> 26#include <linux/module.h>
26#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
27#include <linux/spinlock.h> 28#include <linux/spinlock.h>
28#include <asm/uaccess.h> 29#include <linux/uaccess.h>
29#include <linux/usb.h> 30#include <linux/usb.h>
30#include <linux/usb/serial.h> 31#include <linux/usb/serial.h>
31#include "pl2303.h" 32#include "pl2303.h"
@@ -116,7 +117,7 @@ static struct usb_driver pl2303_driver = {
116#define CONTROL_RTS 0x02 117#define CONTROL_RTS 0x02
117 118
118#define BREAK_REQUEST_TYPE 0x21 119#define BREAK_REQUEST_TYPE 0x21
119#define BREAK_REQUEST 0x23 120#define BREAK_REQUEST 0x23
120#define BREAK_ON 0xffff 121#define BREAK_ON 0xffff
121#define BREAK_OFF 0x0000 122#define BREAK_OFF 0x0000
122 123
@@ -222,7 +223,7 @@ static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb)
222 if (pb == NULL) 223 if (pb == NULL)
223 return 0; 224 return 0;
224 225
225 return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); 226 return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size;
226} 227}
227 228
228/* 229/*
@@ -236,7 +237,7 @@ static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb)
236 if (pb == NULL) 237 if (pb == NULL)
237 return 0; 238 return 0;
238 239
239 return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); 240 return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size;
240} 241}
241 242
242/* 243/*
@@ -395,7 +396,7 @@ static int pl2303_startup(struct usb_serial *serial)
395 396
396cleanup: 397cleanup:
397 kfree(buf); 398 kfree(buf);
398 for (--i; i>=0; --i) { 399 for (--i; i >= 0; --i) {
399 priv = usb_get_serial_port_data(serial->port[i]); 400 priv = usb_get_serial_port_data(serial->port[i]);
400 pl2303_buf_free(priv->buf); 401 pl2303_buf_free(priv->buf);
401 kfree(priv); 402 kfree(priv);
@@ -407,7 +408,7 @@ cleanup:
407static int set_control_lines(struct usb_device *dev, u8 value) 408static int set_control_lines(struct usb_device *dev, u8 value)
408{ 409{
409 int retval; 410 int retval;
410 411
411 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 412 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
412 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, 413 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
413 value, 0, NULL, 0, 100); 414 value, 0, NULL, 0, 100);
@@ -452,14 +453,14 @@ static void pl2303_send(struct usb_serial_port *port)
452 dev_err(&port->dev, "%s - failed submitting write urb," 453 dev_err(&port->dev, "%s - failed submitting write urb,"
453 " error %d\n", __func__, result); 454 " error %d\n", __func__, result);
454 priv->write_urb_in_use = 0; 455 priv->write_urb_in_use = 0;
455 // TODO: reschedule pl2303_send 456 /* TODO: reschedule pl2303_send */
456 } 457 }
457 458
458 usb_serial_port_softint(port); 459 usb_serial_port_softint(port);
459} 460}
460 461
461static int pl2303_write(struct usb_serial_port *port, const unsigned char *buf, 462static int pl2303_write(struct tty_struct *tty, struct usb_serial_port *port,
462 int count) 463 const unsigned char *buf, int count)
463{ 464{
464 struct pl2303_private *priv = usb_get_serial_port_data(port); 465 struct pl2303_private *priv = usb_get_serial_port_data(port);
465 unsigned long flags; 466 unsigned long flags;
@@ -478,8 +479,9 @@ static int pl2303_write(struct usb_serial_port *port, const unsigned char *buf,
478 return count; 479 return count;
479} 480}
480 481
481static int pl2303_write_room(struct usb_serial_port *port) 482static int pl2303_write_room(struct tty_struct *tty)
482{ 483{
484 struct usb_serial_port *port = tty->driver_data;
483 struct pl2303_private *priv = usb_get_serial_port_data(port); 485 struct pl2303_private *priv = usb_get_serial_port_data(port);
484 int room = 0; 486 int room = 0;
485 unsigned long flags; 487 unsigned long flags;
@@ -494,8 +496,9 @@ static int pl2303_write_room(struct usb_serial_port *port)
494 return room; 496 return room;
495} 497}
496 498
497static int pl2303_chars_in_buffer(struct usb_serial_port *port) 499static int pl2303_chars_in_buffer(struct tty_struct *tty)
498{ 500{
501 struct usb_serial_port *port = tty->driver_data;
499 struct pl2303_private *priv = usb_get_serial_port_data(port); 502 struct pl2303_private *priv = usb_get_serial_port_data(port);
500 int chars = 0; 503 int chars = 0;
501 unsigned long flags; 504 unsigned long flags;
@@ -510,8 +513,8 @@ static int pl2303_chars_in_buffer(struct usb_serial_port *port)
510 return chars; 513 return chars;
511} 514}
512 515
513static void pl2303_set_termios(struct usb_serial_port *port, 516static void pl2303_set_termios(struct tty_struct *tty,
514 struct ktermios *old_termios) 517 struct usb_serial_port *port, struct ktermios *old_termios)
515{ 518{
516 struct usb_serial *serial = port->serial; 519 struct usb_serial *serial = port->serial;
517 struct pl2303_private *priv = usb_get_serial_port_data(port); 520 struct pl2303_private *priv = usb_get_serial_port_data(port);
@@ -526,11 +529,10 @@ static void pl2303_set_termios(struct usb_serial_port *port,
526 529
527 spin_lock_irqsave(&priv->lock, flags); 530 spin_lock_irqsave(&priv->lock, flags);
528 if (!priv->termios_initialized) { 531 if (!priv->termios_initialized) {
529 *(port->tty->termios) = tty_std_termios; 532 *(tty->termios) = tty_std_termios;
530 port->tty->termios->c_cflag = B9600 | CS8 | CREAD | 533 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
531 HUPCL | CLOCAL; 534 tty->termios->c_ispeed = 9600;
532 port->tty->termios->c_ispeed = 9600; 535 tty->termios->c_ospeed = 9600;
533 port->tty->termios->c_ospeed = 9600;
534 priv->termios_initialized = 1; 536 priv->termios_initialized = 1;
535 } 537 }
536 spin_unlock_irqrestore(&priv->lock, flags); 538 spin_unlock_irqrestore(&priv->lock, flags);
@@ -539,16 +541,16 @@ static void pl2303_set_termios(struct usb_serial_port *port,
539 serial settings even to the same values as before. Thus 541 serial settings even to the same values as before. Thus
540 we actually need to filter in this specific case */ 542 we actually need to filter in this specific case */
541 543
542 if (!tty_termios_hw_change(port->tty->termios, old_termios)) 544 if (!tty_termios_hw_change(tty->termios, old_termios))
543 return; 545 return;
544 546
545 cflag = port->tty->termios->c_cflag; 547 cflag = tty->termios->c_cflag;
546 548
547 buf = kzalloc(7, GFP_KERNEL); 549 buf = kzalloc(7, GFP_KERNEL);
548 if (!buf) { 550 if (!buf) {
549 dev_err(&port->dev, "%s - out of memory.\n", __func__); 551 dev_err(&port->dev, "%s - out of memory.\n", __func__);
550 /* Report back no change occurred */ 552 /* Report back no change occurred */
551 *port->tty->termios = *old_termios; 553 *tty->termios = *old_termios;
552 return; 554 return;
553 } 555 }
554 556
@@ -560,16 +562,24 @@ static void pl2303_set_termios(struct usb_serial_port *port,
560 562
561 if (cflag & CSIZE) { 563 if (cflag & CSIZE) {
562 switch (cflag & CSIZE) { 564 switch (cflag & CSIZE) {
563 case CS5: buf[6] = 5; break; 565 case CS5:
564 case CS6: buf[6] = 6; break; 566 buf[6] = 5;
565 case CS7: buf[6] = 7; break; 567 break;
566 default: 568 case CS6:
567 case CS8: buf[6] = 8; break; 569 buf[6] = 6;
570 break;
571 case CS7:
572 buf[6] = 7;
573 break;
574 default:
575 case CS8:
576 buf[6] = 8;
577 break;
568 } 578 }
569 dbg("%s - data bits = %d", __func__, buf[6]); 579 dbg("%s - data bits = %d", __func__, buf[6]);
570 } 580 }
571 581
572 baud = tty_get_baud_rate(port->tty);; 582 baud = tty_get_baud_rate(tty);
573 dbg("%s - baud = %d", __func__, baud); 583 dbg("%s - baud = %d", __func__, baud);
574 if (baud) { 584 if (baud) {
575 buf[0] = baud & 0xff; 585 buf[0] = baud & 0xff;
@@ -646,12 +656,13 @@ static void pl2303_set_termios(struct usb_serial_port *port,
646 656
647 /* FIXME: Need to read back resulting baud rate */ 657 /* FIXME: Need to read back resulting baud rate */
648 if (baud) 658 if (baud)
649 tty_encode_baud_rate(port->tty, baud, baud); 659 tty_encode_baud_rate(tty, baud, baud);
650 660
651 kfree(buf); 661 kfree(buf);
652} 662}
653 663
654static void pl2303_close(struct usb_serial_port *port, struct file *filp) 664static void pl2303_close(struct tty_struct *tty,
665 struct usb_serial_port *port, struct file *filp)
655{ 666{
656 struct pl2303_private *priv = usb_get_serial_port_data(port); 667 struct pl2303_private *priv = usb_get_serial_port_data(port);
657 unsigned long flags; 668 unsigned long flags;
@@ -666,7 +677,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
666 spin_lock_irqsave(&priv->lock, flags); 677 spin_lock_irqsave(&priv->lock, flags);
667 timeout = PL2303_CLOSING_WAIT; 678 timeout = PL2303_CLOSING_WAIT;
668 init_waitqueue_entry(&wait, current); 679 init_waitqueue_entry(&wait, current);
669 add_wait_queue(&port->tty->write_wait, &wait); 680 add_wait_queue(&tty->write_wait, &wait);
670 for (;;) { 681 for (;;) {
671 set_current_state(TASK_INTERRUPTIBLE); 682 set_current_state(TASK_INTERRUPTIBLE);
672 if (pl2303_buf_data_avail(priv->buf) == 0 || 683 if (pl2303_buf_data_avail(priv->buf) == 0 ||
@@ -678,7 +689,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
678 spin_lock_irqsave(&priv->lock, flags); 689 spin_lock_irqsave(&priv->lock, flags);
679 } 690 }
680 set_current_state(TASK_RUNNING); 691 set_current_state(TASK_RUNNING);
681 remove_wait_queue(&port->tty->write_wait, &wait); 692 remove_wait_queue(&tty->write_wait, &wait);
682 /* clear out any remaining data in the buffer */ 693 /* clear out any remaining data in the buffer */
683 pl2303_buf_clear(priv->buf); 694 pl2303_buf_clear(priv->buf);
684 spin_unlock_irqrestore(&priv->lock, flags); 695 spin_unlock_irqrestore(&priv->lock, flags);
@@ -690,9 +701,9 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
690 /* for lower rates we should really know how much */ 701 /* for lower rates we should really know how much */
691 /* data is in the buffer to compute a delay */ 702 /* data is in the buffer to compute a delay */
692 /* that is not unnecessarily long) */ 703 /* that is not unnecessarily long) */
693 bps = tty_get_baud_rate(port->tty); 704 bps = tty_get_baud_rate(tty);
694 if (bps > 1200) 705 if (bps > 1200)
695 timeout = max((HZ*2560)/bps,HZ/10); 706 timeout = max((HZ*2560)/bps, HZ/10);
696 else 707 else
697 timeout = 2*HZ; 708 timeout = 2*HZ;
698 schedule_timeout_interruptible(timeout); 709 schedule_timeout_interruptible(timeout);
@@ -703,8 +714,8 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
703 usb_kill_urb(port->read_urb); 714 usb_kill_urb(port->read_urb);
704 usb_kill_urb(port->interrupt_in_urb); 715 usb_kill_urb(port->interrupt_in_urb);
705 716
706 if (port->tty) { 717 if (tty) {
707 c_cflag = port->tty->termios->c_cflag; 718 c_cflag = tty->termios->c_cflag;
708 if (c_cflag & HUPCL) { 719 if (c_cflag & HUPCL) {
709 /* drop DTR and RTS */ 720 /* drop DTR and RTS */
710 spin_lock_irqsave(&priv->lock, flags); 721 spin_lock_irqsave(&priv->lock, flags);
@@ -715,7 +726,8 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
715 } 726 }
716} 727}
717 728
718static int pl2303_open(struct usb_serial_port *port, struct file *filp) 729static int pl2303_open(struct tty_struct *tty,
730 struct usb_serial_port *port, struct file *filp)
719{ 731{
720 struct ktermios tmp_termios; 732 struct ktermios tmp_termios;
721 struct usb_serial *serial = port->serial; 733 struct usb_serial *serial = port->serial;
@@ -734,11 +746,10 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
734 } 746 }
735 747
736 /* Setup termios */ 748 /* Setup termios */
737 if (port->tty) { 749 if (tty)
738 pl2303_set_termios(port, &tmp_termios); 750 pl2303_set_termios(tty, port, &tmp_termios);
739 }
740 751
741 //FIXME: need to assert RTS and DTR if CRTSCTS off 752 /* FIXME: need to assert RTS and DTR if CRTSCTS off */
742 753
743 dbg("%s - submitting read urb", __func__); 754 dbg("%s - submitting read urb", __func__);
744 port->read_urb->dev = serial->dev; 755 port->read_urb->dev = serial->dev;
@@ -746,7 +757,7 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
746 if (result) { 757 if (result) {
747 dev_err(&port->dev, "%s - failed submitting read urb," 758 dev_err(&port->dev, "%s - failed submitting read urb,"
748 " error %d\n", __func__, result); 759 " error %d\n", __func__, result);
749 pl2303_close(port, NULL); 760 pl2303_close(tty, port, NULL);
750 return -EPROTO; 761 return -EPROTO;
751 } 762 }
752 763
@@ -756,15 +767,16 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
756 if (result) { 767 if (result) {
757 dev_err(&port->dev, "%s - failed submitting interrupt urb," 768 dev_err(&port->dev, "%s - failed submitting interrupt urb,"
758 " error %d\n", __func__, result); 769 " error %d\n", __func__, result);
759 pl2303_close(port, NULL); 770 pl2303_close(tty, port, NULL);
760 return -EPROTO; 771 return -EPROTO;
761 } 772 }
762 return 0; 773 return 0;
763} 774}
764 775
765static int pl2303_tiocmset(struct usb_serial_port *port, struct file *file, 776static int pl2303_tiocmset(struct tty_struct *tty, struct file *file,
766 unsigned int set, unsigned int clear) 777 unsigned int set, unsigned int clear)
767{ 778{
779 struct usb_serial_port *port = tty->driver_data;
768 struct pl2303_private *priv = usb_get_serial_port_data(port); 780 struct pl2303_private *priv = usb_get_serial_port_data(port);
769 unsigned long flags; 781 unsigned long flags;
770 u8 control; 782 u8 control;
@@ -787,8 +799,9 @@ static int pl2303_tiocmset(struct usb_serial_port *port, struct file *file,
787 return set_control_lines(port->serial->dev, control); 799 return set_control_lines(port->serial->dev, control);
788} 800}
789 801
790static int pl2303_tiocmget(struct usb_serial_port *port, struct file *file) 802static int pl2303_tiocmget(struct tty_struct *tty, struct file *file)
791{ 803{
804 struct usb_serial_port *port = tty->driver_data;
792 struct pl2303_private *priv = usb_get_serial_port_data(port); 805 struct pl2303_private *priv = usb_get_serial_port_data(port);
793 unsigned long flags; 806 unsigned long flags;
794 unsigned int mcr; 807 unsigned int mcr;
@@ -839,12 +852,12 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
839 status = priv->line_status; 852 status = priv->line_status;
840 spin_unlock_irqrestore(&priv->lock, flags); 853 spin_unlock_irqrestore(&priv->lock, flags);
841 854
842 changed=prevstatus^status; 855 changed = prevstatus ^ status;
843 856
844 if (((arg & TIOCM_RNG) && (changed & UART_RING)) || 857 if (((arg & TIOCM_RNG) && (changed & UART_RING)) ||
845 ((arg & TIOCM_DSR) && (changed & UART_DSR)) || 858 ((arg & TIOCM_DSR) && (changed & UART_DSR)) ||
846 ((arg & TIOCM_CD) && (changed & UART_DCD)) || 859 ((arg & TIOCM_CD) && (changed & UART_DCD)) ||
847 ((arg & TIOCM_CTS) && (changed & UART_CTS)) ) { 860 ((arg & TIOCM_CTS) && (changed & UART_CTS))) {
848 return 0; 861 return 0;
849 } 862 }
850 prevstatus = status; 863 prevstatus = status;
@@ -853,26 +866,26 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
853 return 0; 866 return 0;
854} 867}
855 868
856static int pl2303_ioctl(struct usb_serial_port *port, struct file *file, 869static int pl2303_ioctl(struct tty_struct *tty, struct file *file,
857 unsigned int cmd, unsigned long arg) 870 unsigned int cmd, unsigned long arg)
858{ 871{
872 struct usb_serial_port *port = tty->driver_data;
859 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd); 873 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd);
860 874
861 switch (cmd) { 875 switch (cmd) {
862 case TIOCMIWAIT: 876 case TIOCMIWAIT:
863 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 877 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
864 return wait_modem_info(port, arg); 878 return wait_modem_info(port, arg);
865 879 default:
866 default: 880 dbg("%s not supported = 0x%04x", __func__, cmd);
867 dbg("%s not supported = 0x%04x", __func__, cmd); 881 break;
868 break;
869 } 882 }
870
871 return -ENOIOCTLCMD; 883 return -ENOIOCTLCMD;
872} 884}
873 885
874static void pl2303_break_ctl(struct usb_serial_port *port, int break_state) 886static void pl2303_break_ctl(struct tty_struct *tty, int break_state)
875{ 887{
888 struct usb_serial_port *port = tty->driver_data;
876 struct usb_serial *serial = port->serial; 889 struct usb_serial *serial = port->serial;
877 u16 state; 890 u16 state;
878 int result; 891 int result;
@@ -883,7 +896,8 @@ static void pl2303_break_ctl(struct usb_serial_port *port, int break_state)
883 state = BREAK_OFF; 896 state = BREAK_OFF;
884 else 897 else
885 state = BREAK_ON; 898 state = BREAK_ON;
886 dbg("%s - turning break %s", __func__, state==BREAK_OFF ? "off" : "on"); 899 dbg("%s - turning break %s", __func__,
900 state == BREAK_OFF ? "off" : "on");
887 901
888 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 902 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
889 BREAK_REQUEST, BREAK_REQUEST_TYPE, state, 903 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
@@ -937,7 +951,7 @@ static void pl2303_update_line_status(struct usb_serial_port *port,
937 if (actual_length < length) 951 if (actual_length < length)
938 return; 952 return;
939 953
940 /* Save off the uart status for others to look at */ 954 /* Save off the uart status for others to look at */
941 spin_lock_irqsave(&priv->lock, flags); 955 spin_lock_irqsave(&priv->lock, flags);
942 priv->line_status = data[status_idx]; 956 priv->line_status = data[status_idx];
943 spin_unlock_irqrestore(&priv->lock, flags); 957 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1001,7 +1015,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1001 1015
1002 if (status) { 1016 if (status) {
1003 dbg("%s - urb status = %d", __func__, status); 1017 dbg("%s - urb status = %d", __func__, status);
1004 if (!port->open_count) { 1018 if (!port->port.count) {
1005 dbg("%s - port is closed, exiting.", __func__); 1019 dbg("%s - port is closed, exiting.", __func__);
1006 return; 1020 return;
1007 } 1021 }
@@ -1036,7 +1050,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1036 1050
1037 /* break takes precedence over parity, */ 1051 /* break takes precedence over parity, */
1038 /* which takes precedence over framing errors */ 1052 /* which takes precedence over framing errors */
1039 if (line_status & UART_BREAK_ERROR ) 1053 if (line_status & UART_BREAK_ERROR)
1040 tty_flag = TTY_BREAK; 1054 tty_flag = TTY_BREAK;
1041 else if (line_status & UART_PARITY_ERROR) 1055 else if (line_status & UART_PARITY_ERROR)
1042 tty_flag = TTY_PARITY; 1056 tty_flag = TTY_PARITY;
@@ -1044,7 +1058,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1044 tty_flag = TTY_FRAME; 1058 tty_flag = TTY_FRAME;
1045 dbg("%s - tty_flag = %d", __func__, tty_flag); 1059 dbg("%s - tty_flag = %d", __func__, tty_flag);
1046 1060
1047 tty = port->tty; 1061 tty = port->port.tty;
1048 if (tty && urb->actual_length) { 1062 if (tty && urb->actual_length) {
1049 tty_buffer_request_room(tty, urb->actual_length + 1); 1063 tty_buffer_request_room(tty, urb->actual_length + 1);
1050 /* overrun is special, not associated with a char */ 1064 /* overrun is special, not associated with a char */
@@ -1056,7 +1070,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1056 } 1070 }
1057 1071
1058 /* Schedule the next read _if_ we are still open */ 1072 /* Schedule the next read _if_ we are still open */
1059 if (port->open_count) { 1073 if (port->port.count) {
1060 urb->dev = port->serial->dev; 1074 urb->dev = port->serial->dev;
1061 result = usb_submit_urb(urb, GFP_ATOMIC); 1075 result = usb_submit_urb(urb, GFP_ATOMIC);
1062 if (result) 1076 if (result)
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 94bddf06ea4f..def52d07a4ea 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -13,24 +13,25 @@
13 * Stuart Lynne <sl@lineo.com>, Tom Rushworth <tbr@lineo.com> 13 * Stuart Lynne <sl@lineo.com>, Tom Rushworth <tbr@lineo.com>
14 */ 14 */
15 15
16/* 16/*
17 * The encapsultaion is designed to overcome difficulties with some USB hardware. 17 * The encapsultaion is designed to overcome difficulties with some USB
18 * hardware.
18 * 19 *
19 * While the USB protocol has a CRC over the data while in transit, i.e. while 20 * While the USB protocol has a CRC over the data while in transit, i.e. while
20 * being carried over the bus, there is no end to end protection. If the hardware 21 * being carried over the bus, there is no end to end protection. If the
21 * has any problems getting the data into or out of the USB transmit and receive 22 * hardware has any problems getting the data into or out of the USB transmit
22 * FIFO's then data can be lost. 23 * and receive FIFO's then data can be lost.
23 * 24 *
24 * This protocol adds a two byte trailer to each USB packet to specify the number 25 * This protocol adds a two byte trailer to each USB packet to specify the
25 * of bytes of valid data and a 10 bit CRC that will allow the receiver to verify 26 * number of bytes of valid data and a 10 bit CRC that will allow the receiver
26 * that the entire USB packet was received without error. 27 * to verify that the entire USB packet was received without error.
27 * 28 *
28 * Because in this case the sender and receiver are the class and function drivers 29 * Because in this case the sender and receiver are the class and function
29 * there is now end to end protection. 30 * drivers there is now end to end protection.
30 * 31 *
31 * There is an additional option that can be used to force all transmitted packets 32 * There is an additional option that can be used to force all transmitted
32 * to be padded to the maximum packet size. This provides a work around for some 33 * packets to be padded to the maximum packet size. This provides a work
33 * devices which have problems with small USB packets. 34 * around for some devices which have problems with small USB packets.
34 * 35 *
35 * Assuming a packetsize of N: 36 * Assuming a packetsize of N:
36 * 37 *
@@ -44,11 +45,12 @@
44 * | Data Length | 10 bit CRC | 45 * | Data Length | 10 bit CRC |
45 * + 7 . 6 . 5 . 4 . 3 . 2 . 1 . 0 | 7 . 6 . 5 . 4 . 3 . 2 . 1 . 0 + 46 * + 7 . 6 . 5 . 4 . 3 . 2 . 1 . 0 | 7 . 6 . 5 . 4 . 3 . 2 . 1 . 0 +
46 * 47 *
47 * The 10 bit CRC is computed across the sent data, followed by the trailer with 48 * The 10 bit CRC is computed across the sent data, followed by the trailer
48 * the length set and the CRC set to zero. The CRC is then OR'd into the trailer. 49 * with the length set and the CRC set to zero. The CRC is then OR'd into
50 * the trailer.
49 * 51 *
50 * When received a 10 bit CRC is computed over the entire frame including the trailer 52 * When received a 10 bit CRC is computed over the entire frame including
51 * and should be equal to zero. 53 * the trailer and should be equal to zero.
52 * 54 *
53 * Two module parameters are used to control the encapsulation, if both are 55 * Two module parameters are used to control the encapsulation, if both are
54 * turned of the module works as a simple serial device with NO 56 * turned of the module works as a simple serial device with NO
@@ -69,7 +71,7 @@
69#include <linux/tty_flip.h> 71#include <linux/tty_flip.h>
70#include <linux/module.h> 72#include <linux/module.h>
71#include <linux/spinlock.h> 73#include <linux/spinlock.h>
72#include <asm/uaccess.h> 74#include <linux/uaccess.h>
73#include <linux/usb.h> 75#include <linux/usb.h>
74#include <linux/usb/serial.h> 76#include <linux/usb/serial.h>
75 77
@@ -86,12 +88,12 @@ static int padded = CONFIG_USB_SERIAL_SAFE_PADDED;
86#define DRIVER_AUTHOR "sl@lineo.com, tbr@lineo.com" 88#define DRIVER_AUTHOR "sl@lineo.com, tbr@lineo.com"
87#define DRIVER_DESC "USB Safe Encapsulated Serial" 89#define DRIVER_DESC "USB Safe Encapsulated Serial"
88 90
89MODULE_AUTHOR (DRIVER_AUTHOR); 91MODULE_AUTHOR(DRIVER_AUTHOR);
90MODULE_DESCRIPTION (DRIVER_DESC); 92MODULE_DESCRIPTION(DRIVER_DESC);
91MODULE_LICENSE("GPL"); 93MODULE_LICENSE("GPL");
92 94
93static __u16 vendor; // no default 95static __u16 vendor; /* no default */
94static __u16 product; // no default 96static __u16 product; /* no default */
95module_param(vendor, ushort, 0); 97module_param(vendor, ushort, 0);
96MODULE_PARM_DESC(vendor, "User specified USB idVendor (required)"); 98MODULE_PARM_DESC(vendor, "User specified USB idVendor (required)");
97module_param(product, ushort, 0); 99module_param(product, ushort, 0);
@@ -122,30 +124,31 @@ MODULE_PARM_DESC(padded, "Pad to full wMaxPacketSize On/Off");
122#define LINEO_SAFESERIAL_CRC_PADDED 0x02 124#define LINEO_SAFESERIAL_CRC_PADDED 0x02
123 125
124 126
125#define MY_USB_DEVICE(vend,prod,dc,ic,isc) \ 127#define MY_USB_DEVICE(vend, prod, dc, ic, isc) \
126 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS | \ 128 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
127 USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS, \ 129 USB_DEVICE_ID_MATCH_DEV_CLASS | \
128 .idVendor = (vend), \ 130 USB_DEVICE_ID_MATCH_INT_CLASS | \
129 .idProduct = (prod),\ 131 USB_DEVICE_ID_MATCH_INT_SUBCLASS, \
130 .bDeviceClass = (dc),\ 132 .idVendor = (vend), \
131 .bInterfaceClass = (ic), \ 133 .idProduct = (prod),\
132 .bInterfaceSubClass = (isc), 134 .bDeviceClass = (dc),\
135 .bInterfaceClass = (ic), \
136 .bInterfaceSubClass = (isc),
133 137
134static struct usb_device_id id_table[] = { 138static struct usb_device_id id_table[] = {
135 {MY_USB_DEVICE (0x49f, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Itsy 139 {MY_USB_DEVICE(0x49f, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Itsy */
136 {MY_USB_DEVICE (0x3f0, 0x2101, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Calypso 140 {MY_USB_DEVICE(0x3f0, 0x2101, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Calypso */
137 {MY_USB_DEVICE (0x4dd, 0x8001, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Iris 141 {MY_USB_DEVICE(0x4dd, 0x8001, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Iris */
138 {MY_USB_DEVICE (0x4dd, 0x8002, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Collie 142 {MY_USB_DEVICE(0x4dd, 0x8002, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Collie */
139 {MY_USB_DEVICE (0x4dd, 0x8003, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Collie 143 {MY_USB_DEVICE(0x4dd, 0x8003, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Collie */
140 {MY_USB_DEVICE (0x4dd, 0x8004, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Collie 144 {MY_USB_DEVICE(0x4dd, 0x8004, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Collie */
141 {MY_USB_DEVICE (0x5f9, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, // Sharp tmp 145 {MY_USB_DEVICE(0x5f9, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Sharp tmp */
142 // extra null entry for module 146 /* extra null entry for module vendor/produc parameters */
143 // vendor/produc parameters 147 {MY_USB_DEVICE(0, 0, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)},
144 {MY_USB_DEVICE (0, 0, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, 148 {} /* terminating entry */
145 {} // terminating entry
146}; 149};
147 150
148MODULE_DEVICE_TABLE (usb, id_table); 151MODULE_DEVICE_TABLE(usb, id_table);
149 152
150static struct usb_driver safe_driver = { 153static struct usb_driver safe_driver = {
151 .name = "safe_serial", 154 .name = "safe_serial",
@@ -156,29 +159,45 @@ static struct usb_driver safe_driver = {
156}; 159};
157 160
158static const __u16 crc10_table[256] = { 161static const __u16 crc10_table[256] = {
159 0x000, 0x233, 0x255, 0x066, 0x299, 0x0aa, 0x0cc, 0x2ff, 0x301, 0x132, 0x154, 0x367, 0x198, 0x3ab, 0x3cd, 0x1fe, 162 0x000, 0x233, 0x255, 0x066, 0x299, 0x0aa, 0x0cc, 0x2ff,
160 0x031, 0x202, 0x264, 0x057, 0x2a8, 0x09b, 0x0fd, 0x2ce, 0x330, 0x103, 0x165, 0x356, 0x1a9, 0x39a, 0x3fc, 0x1cf, 163 0x301, 0x132, 0x154, 0x367, 0x198, 0x3ab, 0x3cd, 0x1fe,
161 0x062, 0x251, 0x237, 0x004, 0x2fb, 0x0c8, 0x0ae, 0x29d, 0x363, 0x150, 0x136, 0x305, 0x1fa, 0x3c9, 0x3af, 0x19c, 164 0x031, 0x202, 0x264, 0x057, 0x2a8, 0x09b, 0x0fd, 0x2ce,
162 0x053, 0x260, 0x206, 0x035, 0x2ca, 0x0f9, 0x09f, 0x2ac, 0x352, 0x161, 0x107, 0x334, 0x1cb, 0x3f8, 0x39e, 0x1ad, 165 0x330, 0x103, 0x165, 0x356, 0x1a9, 0x39a, 0x3fc, 0x1cf,
163 0x0c4, 0x2f7, 0x291, 0x0a2, 0x25d, 0x06e, 0x008, 0x23b, 0x3c5, 0x1f6, 0x190, 0x3a3, 0x15c, 0x36f, 0x309, 0x13a, 166 0x062, 0x251, 0x237, 0x004, 0x2fb, 0x0c8, 0x0ae, 0x29d,
164 0x0f5, 0x2c6, 0x2a0, 0x093, 0x26c, 0x05f, 0x039, 0x20a, 0x3f4, 0x1c7, 0x1a1, 0x392, 0x16d, 0x35e, 0x338, 0x10b, 167 0x363, 0x150, 0x136, 0x305, 0x1fa, 0x3c9, 0x3af, 0x19c,
165 0x0a6, 0x295, 0x2f3, 0x0c0, 0x23f, 0x00c, 0x06a, 0x259, 0x3a7, 0x194, 0x1f2, 0x3c1, 0x13e, 0x30d, 0x36b, 0x158, 168 0x053, 0x260, 0x206, 0x035, 0x2ca, 0x0f9, 0x09f, 0x2ac,
166 0x097, 0x2a4, 0x2c2, 0x0f1, 0x20e, 0x03d, 0x05b, 0x268, 0x396, 0x1a5, 0x1c3, 0x3f0, 0x10f, 0x33c, 0x35a, 0x169, 169 0x352, 0x161, 0x107, 0x334, 0x1cb, 0x3f8, 0x39e, 0x1ad,
167 0x188, 0x3bb, 0x3dd, 0x1ee, 0x311, 0x122, 0x144, 0x377, 0x289, 0x0ba, 0x0dc, 0x2ef, 0x010, 0x223, 0x245, 0x076, 170 0x0c4, 0x2f7, 0x291, 0x0a2, 0x25d, 0x06e, 0x008, 0x23b,
168 0x1b9, 0x38a, 0x3ec, 0x1df, 0x320, 0x113, 0x175, 0x346, 0x2b8, 0x08b, 0x0ed, 0x2de, 0x021, 0x212, 0x274, 0x047, 171 0x3c5, 0x1f6, 0x190, 0x3a3, 0x15c, 0x36f, 0x309, 0x13a,
169 0x1ea, 0x3d9, 0x3bf, 0x18c, 0x373, 0x140, 0x126, 0x315, 0x2eb, 0x0d8, 0x0be, 0x28d, 0x072, 0x241, 0x227, 0x014, 172 0x0f5, 0x2c6, 0x2a0, 0x093, 0x26c, 0x05f, 0x039, 0x20a,
170 0x1db, 0x3e8, 0x38e, 0x1bd, 0x342, 0x171, 0x117, 0x324, 0x2da, 0x0e9, 0x08f, 0x2bc, 0x043, 0x270, 0x216, 0x025, 173 0x3f4, 0x1c7, 0x1a1, 0x392, 0x16d, 0x35e, 0x338, 0x10b,
171 0x14c, 0x37f, 0x319, 0x12a, 0x3d5, 0x1e6, 0x180, 0x3b3, 0x24d, 0x07e, 0x018, 0x22b, 0x0d4, 0x2e7, 0x281, 0x0b2, 174 0x0a6, 0x295, 0x2f3, 0x0c0, 0x23f, 0x00c, 0x06a, 0x259,
172 0x17d, 0x34e, 0x328, 0x11b, 0x3e4, 0x1d7, 0x1b1, 0x382, 0x27c, 0x04f, 0x029, 0x21a, 0x0e5, 0x2d6, 0x2b0, 0x083, 175 0x3a7, 0x194, 0x1f2, 0x3c1, 0x13e, 0x30d, 0x36b, 0x158,
173 0x12e, 0x31d, 0x37b, 0x148, 0x3b7, 0x184, 0x1e2, 0x3d1, 0x22f, 0x01c, 0x07a, 0x249, 0x0b6, 0x285, 0x2e3, 0x0d0, 176 0x097, 0x2a4, 0x2c2, 0x0f1, 0x20e, 0x03d, 0x05b, 0x268,
174 0x11f, 0x32c, 0x34a, 0x179, 0x386, 0x1b5, 0x1d3, 0x3e0, 0x21e, 0x02d, 0x04b, 0x278, 0x087, 0x2b4, 0x2d2, 0x0e1, 177 0x396, 0x1a5, 0x1c3, 0x3f0, 0x10f, 0x33c, 0x35a, 0x169,
178 0x188, 0x3bb, 0x3dd, 0x1ee, 0x311, 0x122, 0x144, 0x377,
179 0x289, 0x0ba, 0x0dc, 0x2ef, 0x010, 0x223, 0x245, 0x076,
180 0x1b9, 0x38a, 0x3ec, 0x1df, 0x320, 0x113, 0x175, 0x346,
181 0x2b8, 0x08b, 0x0ed, 0x2de, 0x021, 0x212, 0x274, 0x047,
182 0x1ea, 0x3d9, 0x3bf, 0x18c, 0x373, 0x140, 0x126, 0x315,
183 0x2eb, 0x0d8, 0x0be, 0x28d, 0x072, 0x241, 0x227, 0x014,
184 0x1db, 0x3e8, 0x38e, 0x1bd, 0x342, 0x171, 0x117, 0x324,
185 0x2da, 0x0e9, 0x08f, 0x2bc, 0x043, 0x270, 0x216, 0x025,
186 0x14c, 0x37f, 0x319, 0x12a, 0x3d5, 0x1e6, 0x180, 0x3b3,
187 0x24d, 0x07e, 0x018, 0x22b, 0x0d4, 0x2e7, 0x281, 0x0b2,
188 0x17d, 0x34e, 0x328, 0x11b, 0x3e4, 0x1d7, 0x1b1, 0x382,
189 0x27c, 0x04f, 0x029, 0x21a, 0x0e5, 0x2d6, 0x2b0, 0x083,
190 0x12e, 0x31d, 0x37b, 0x148, 0x3b7, 0x184, 0x1e2, 0x3d1,
191 0x22f, 0x01c, 0x07a, 0x249, 0x0b6, 0x285, 0x2e3, 0x0d0,
192 0x11f, 0x32c, 0x34a, 0x179, 0x386, 0x1b5, 0x1d3, 0x3e0,
193 0x21e, 0x02d, 0x04b, 0x278, 0x087, 0x2b4, 0x2d2, 0x0e1,
175}; 194};
176 195
177#define CRC10_INITFCS 0x000 // Initial FCS value 196#define CRC10_INITFCS 0x000 /* Initial FCS value */
178#define CRC10_GOODFCS 0x000 // Good final FCS value 197#define CRC10_GOODFCS 0x000 /* Good final FCS value */
179#define CRC10_FCS(fcs, c) ( (((fcs) << 8) & 0x3ff) ^ crc10_table[((fcs) >> 2) & 0xff] ^ (c)) 198#define CRC10_FCS(fcs, c) ((((fcs) << 8) & 0x3ff) ^ crc10_table[((fcs) >> 2) & 0xff] ^ (c))
180 199
181/** 200/**
182 * fcs_compute10 - memcpy and calculate 10 bit CRC across buffer 201 * fcs_compute10 - memcpy and calculate 10 bit CRC across buffer
183 * @sp: pointer to buffer 202 * @sp: pointer to buffer
184 * @len: number of bytes 203 * @len: number of bytes
@@ -187,13 +206,13 @@ static const __u16 crc10_table[256] = {
187 * Perform a memcpy and calculate fcs using ppp 10bit CRC algorithm. Return 206 * Perform a memcpy and calculate fcs using ppp 10bit CRC algorithm. Return
188 * new 10 bit FCS. 207 * new 10 bit FCS.
189 */ 208 */
190static __u16 __inline__ fcs_compute10 (unsigned char *sp, int len, __u16 fcs) 209static __u16 __inline__ fcs_compute10(unsigned char *sp, int len, __u16 fcs)
191{ 210{
192 for (; len-- > 0; fcs = CRC10_FCS (fcs, *sp++)); 211 for (; len-- > 0; fcs = CRC10_FCS(fcs, *sp++));
193 return fcs; 212 return fcs;
194} 213}
195 214
196static void safe_read_bulk_callback (struct urb *urb) 215static void safe_read_bulk_callback(struct urb *urb)
197{ 216{
198 struct usb_serial_port *port = urb->context; 217 struct usb_serial_port *port = urb->context;
199 unsigned char *data = urb->transfer_buffer; 218 unsigned char *data = urb->transfer_buffer;
@@ -201,7 +220,7 @@ static void safe_read_bulk_callback (struct urb *urb)
201 int result; 220 int result;
202 int status = urb->status; 221 int status = urb->status;
203 222
204 dbg ("%s", __func__); 223 dbg("%s", __func__);
205 224
206 if (status) { 225 if (status) {
207 dbg("%s - nonzero read bulk status received: %d", 226 dbg("%s - nonzero read bulk status received: %d",
@@ -209,76 +228,82 @@ static void safe_read_bulk_callback (struct urb *urb)
209 return; 228 return;
210 } 229 }
211 230
212 dbg ("safe_read_bulk_callback length: %d", port->read_urb->actual_length); 231 dbg("safe_read_bulk_callback length: %d",
232 port->read_urb->actual_length);
213#ifdef ECHO_RCV 233#ifdef ECHO_RCV
214 { 234 {
215 int i; 235 int i;
216 unsigned char *cp = port->read_urb->transfer_buffer; 236 unsigned char *cp = port->read_urb->transfer_buffer;
217 for (i = 0; i < port->read_urb->actual_length; i++) { 237 for (i = 0; i < port->read_urb->actual_length; i++) {
218 if ((i % 32) == 0) { 238 if ((i % 32) == 0)
219 printk ("\nru[%02x] ", i); 239 printk("\nru[%02x] ", i);
220 } 240 printk("%02x ", *cp++);
221 printk ("%02x ", *cp++);
222 } 241 }
223 printk ("\n"); 242 printk("\n");
224 } 243 }
225#endif 244#endif
226 if (safe) { 245 if (safe) {
227 __u16 fcs; 246 __u16 fcs;
228 if (!(fcs = fcs_compute10 (data, length, CRC10_INITFCS))) { 247 fcs = fcs_compute10(data, length, CRC10_INITFCS);
248 if (!fcs) {
229 int actual_length = data[length - 2] >> 2; 249 int actual_length = data[length - 2] >> 2;
230 if (actual_length <= (length - 2)) { 250 if (actual_length <= (length - 2)) {
231 info ("%s - actual: %d", __func__, actual_length); 251 info("%s - actual: %d", __func__,
232 tty_insert_flip_string(port->tty, data, actual_length); 252 actual_length);
233 tty_flip_buffer_push (port->tty); 253 tty_insert_flip_string(port->port.tty,
254 data, actual_length);
255 tty_flip_buffer_push(port->port.tty);
234 } else { 256 } else {
235 err ("%s - inconsistent lengths %d:%d", __func__, 257 err("%s - inconsistent lengths %d:%d",
236 actual_length, length); 258 __func__, actual_length, length);
237 } 259 }
238 } else { 260 } else {
239 err ("%s - bad CRC %x", __func__, fcs); 261 err("%s - bad CRC %x", __func__, fcs);
240 } 262 }
241 } else { 263 } else {
242 tty_insert_flip_string(port->tty, data, length); 264 tty_insert_flip_string(port->port.tty, data, length);
243 tty_flip_buffer_push (port->tty); 265 tty_flip_buffer_push(port->port.tty);
244 } 266 }
245 267
246 /* Continue trying to always read */ 268 /* Continue trying to always read */
247 usb_fill_bulk_urb (urb, port->serial->dev, 269 usb_fill_bulk_urb(urb, port->serial->dev,
248 usb_rcvbulkpipe (port->serial->dev, port->bulk_in_endpointAddress), 270 usb_rcvbulkpipe(port->serial->dev,
249 urb->transfer_buffer, urb->transfer_buffer_length, 271 port->bulk_in_endpointAddress),
250 safe_read_bulk_callback, port); 272 urb->transfer_buffer, urb->transfer_buffer_length,
251 273 safe_read_bulk_callback, port);
252 if ((result = usb_submit_urb (urb, GFP_ATOMIC))) { 274
253 err ("%s - failed resubmitting read urb, error %d", __func__, result); 275 result = usb_submit_urb(urb, GFP_ATOMIC);
276 if (result)
277 err("%s - failed resubmitting read urb, error %d",
278 __func__, result);
254 /* FIXME: Need a mechanism to retry later if this happens */ 279 /* FIXME: Need a mechanism to retry later if this happens */
255 }
256} 280}
257 281
258static int safe_write (struct usb_serial_port *port, const unsigned char *buf, int count) 282static int safe_write(struct tty_struct *tty, struct usb_serial_port *port,
283 const unsigned char *buf, int count)
259{ 284{
260 unsigned char *data; 285 unsigned char *data;
261 int result; 286 int result;
262 int i; 287 int i;
263 int packet_length; 288 int packet_length;
264 289
265 dbg ("safe_write port: %p %d urb: %p count: %d", port, port->number, port->write_urb, 290 dbg("safe_write port: %p %d urb: %p count: %d",
266 count); 291 port, port->number, port->write_urb, count);
267 292
268 if (!port->write_urb) { 293 if (!port->write_urb) {
269 dbg ("%s - write urb NULL", __func__); 294 dbg("%s - write urb NULL", __func__);
270 return 0; 295 return 0;
271 } 296 }
272 297
273 dbg ("safe_write write_urb: %d transfer_buffer_length", 298 dbg("safe_write write_urb: %d transfer_buffer_length",
274 port->write_urb->transfer_buffer_length); 299 port->write_urb->transfer_buffer_length);
275 300
276 if (!port->write_urb->transfer_buffer_length) { 301 if (!port->write_urb->transfer_buffer_length) {
277 dbg ("%s - write urb transfer_buffer_length zero", __func__); 302 dbg("%s - write urb transfer_buffer_length zero", __func__);
278 return 0; 303 return 0;
279 } 304 }
280 if (count == 0) { 305 if (count == 0) {
281 dbg ("%s - write request of 0 bytes", __func__); 306 dbg("%s - write request of 0 bytes", __func__);
282 return 0; 307 return 0;
283 } 308 }
284 spin_lock_bh(&port->lock); 309 spin_lock_bh(&port->lock);
@@ -290,85 +315,85 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
290 port->write_urb_busy = 1; 315 port->write_urb_busy = 1;
291 spin_unlock_bh(&port->lock); 316 spin_unlock_bh(&port->lock);
292 317
293 packet_length = port->bulk_out_size; // get max packetsize 318 packet_length = port->bulk_out_size; /* get max packetsize */
294 319
295 i = packet_length - (safe ? 2 : 0); // get bytes to send 320 i = packet_length - (safe ? 2 : 0); /* get bytes to send */
296 count = (count > i) ? i : count; 321 count = (count > i) ? i : count;
297 322
298 323
299 // get the data into the transfer buffer 324 /* get the data into the transfer buffer */
300 data = port->write_urb->transfer_buffer; 325 data = port->write_urb->transfer_buffer;
301 memset (data, '0', packet_length); 326 memset(data, '0', packet_length);
302 327
303 memcpy (data, buf, count); 328 memcpy(data, buf, count);
304 329
305 if (safe) { 330 if (safe) {
306 __u16 fcs; 331 __u16 fcs;
307 332
308 // pad if necessary 333 /* pad if necessary */
309 if (!padded) { 334 if (!padded)
310 packet_length = count + 2; 335 packet_length = count + 2;
311 } 336 /* set count */
312 // set count
313 data[packet_length - 2] = count << 2; 337 data[packet_length - 2] = count << 2;
314 data[packet_length - 1] = 0; 338 data[packet_length - 1] = 0;
315 339
316 // compute fcs and insert into trailer 340 /* compute fcs and insert into trailer */
317 fcs = fcs_compute10 (data, packet_length, CRC10_INITFCS); 341 fcs = fcs_compute10(data, packet_length, CRC10_INITFCS);
318 data[packet_length - 2] |= fcs >> 8; 342 data[packet_length - 2] |= fcs >> 8;
319 data[packet_length - 1] |= fcs & 0xff; 343 data[packet_length - 1] |= fcs & 0xff;
320 344
321 // set length to send 345 /* set length to send */
322 port->write_urb->transfer_buffer_length = packet_length; 346 port->write_urb->transfer_buffer_length = packet_length;
323 } else { 347 } else {
324 port->write_urb->transfer_buffer_length = count; 348 port->write_urb->transfer_buffer_length = count;
325 } 349 }
326 350
327 usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer); 351 usb_serial_debug_data(debug, &port->dev, __func__, count,
352 port->write_urb->transfer_buffer);
328#ifdef ECHO_TX 353#ifdef ECHO_TX
329 { 354 {
330 int i; 355 int i;
331 unsigned char *cp = port->write_urb->transfer_buffer; 356 unsigned char *cp = port->write_urb->transfer_buffer;
332 for (i = 0; i < port->write_urb->transfer_buffer_length; i++) { 357 for (i = 0; i < port->write_urb->transfer_buffer_length; i++) {
333 if ((i % 32) == 0) { 358 if ((i % 32) == 0)
334 printk ("\nsu[%02x] ", i); 359 printk("\nsu[%02x] ", i);
335 } 360 printk("%02x ", *cp++);
336 printk ("%02x ", *cp++);
337 } 361 }
338 printk ("\n"); 362 printk("\n");
339 } 363 }
340#endif 364#endif
341 port->write_urb->dev = port->serial->dev; 365 port->write_urb->dev = port->serial->dev;
342 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) { 366 result = usb_submit_urb(port->write_urb, GFP_KERNEL);
367 if (result) {
343 port->write_urb_busy = 0; 368 port->write_urb_busy = 0;
344 err ("%s - failed submitting write urb, error %d", __func__, result); 369 err("%s - failed submitting write urb, error %d",
370 __func__, result);
345 return 0; 371 return 0;
346 } 372 }
347 dbg ("%s urb: %p submitted", __func__, port->write_urb); 373 dbg("%s urb: %p submitted", __func__, port->write_urb);
348 374
349 return (count); 375 return count;
350} 376}
351 377
352static int safe_write_room (struct usb_serial_port *port) 378static int safe_write_room(struct tty_struct *tty)
353{ 379{
380 struct usb_serial_port *port = tty->driver_data;
354 int room = 0; /* Default: no room */ 381 int room = 0; /* Default: no room */
355 unsigned long flags; 382 unsigned long flags;
356 383
357 dbg ("%s", __func__); 384 dbg("%s", __func__);
358 385
359 spin_lock_irqsave(&port->lock, flags); 386 spin_lock_irqsave(&port->lock, flags);
360 if (port->write_urb_busy) 387 if (port->write_urb_busy)
361 room = port->bulk_out_size - (safe ? 2 : 0); 388 room = port->bulk_out_size - (safe ? 2 : 0);
362 spin_unlock_irqrestore(&port->lock, flags); 389 spin_unlock_irqrestore(&port->lock, flags);
363 390
364 if (room) { 391 if (room)
365 dbg ("safe_write_room returns %d", room); 392 dbg("safe_write_room returns %d", room);
366 }
367
368 return room; 393 return room;
369} 394}
370 395
371static int safe_startup (struct usb_serial *serial) 396static int safe_startup(struct usb_serial *serial)
372{ 397{
373 switch (serial->interface->cur_altsetting->desc.bInterfaceProtocol) { 398 switch (serial->interface->cur_altsetting->desc.bInterfaceProtocol) {
374 case LINEO_SAFESERIAL_CRC: 399 case LINEO_SAFESERIAL_CRC:
@@ -396,17 +421,18 @@ static struct usb_serial_driver safe_device = {
396 .attach = safe_startup, 421 .attach = safe_startup,
397}; 422};
398 423
399static int __init safe_init (void) 424static int __init safe_init(void)
400{ 425{
401 int i, retval; 426 int i, retval;
402 427
403 info (DRIVER_VERSION " " DRIVER_AUTHOR); 428 info(DRIVER_VERSION " " DRIVER_AUTHOR);
404 info (DRIVER_DESC); 429 info(DRIVER_DESC);
405 info ("vendor: %x product: %x safe: %d padded: %d\n", vendor, product, safe, padded); 430 info("vendor: %x product: %x safe: %d padded: %d\n",
431 vendor, product, safe, padded);
406 432
407 // if we have vendor / product parameters patch them into id list 433 /* if we have vendor / product parameters patch them into id list */
408 if (vendor || product) { 434 if (vendor || product) {
409 info ("vendor: %x product: %x\n", vendor, product); 435 info("vendor: %x product: %x\n", vendor, product);
410 436
411 for (i = 0; i < ARRAY_SIZE(id_table); i++) { 437 for (i = 0; i < ARRAY_SIZE(id_table); i++) {
412 if (!id_table[i].idVendor && !id_table[i].idProduct) { 438 if (!id_table[i].idVendor && !id_table[i].idProduct) {
@@ -431,11 +457,11 @@ failed_usb_serial_register:
431 return retval; 457 return retval;
432} 458}
433 459
434static void __exit safe_exit (void) 460static void __exit safe_exit(void)
435{ 461{
436 usb_deregister (&safe_driver); 462 usb_deregister(&safe_driver);
437 usb_serial_deregister (&safe_device); 463 usb_serial_deregister(&safe_device);
438} 464}
439 465
440module_init (safe_init); 466module_init(safe_init);
441module_exit (safe_exit); 467module_exit(safe_exit);
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 29074c1ba22b..2f6f1523ec56 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -250,7 +250,8 @@ struct sierra_port_private {
250 int ri_state; 250 int ri_state;
251}; 251};
252 252
253static int sierra_send_setup(struct usb_serial_port *port) 253static int sierra_send_setup(struct tty_struct *tty,
254 struct usb_serial_port *port)
254{ 255{
255 struct usb_serial *serial = port->serial; 256 struct usb_serial *serial = port->serial;
256 struct sierra_port_private *portdata; 257 struct sierra_port_private *portdata;
@@ -260,7 +261,7 @@ static int sierra_send_setup(struct usb_serial_port *port)
260 261
261 portdata = usb_get_serial_port_data(port); 262 portdata = usb_get_serial_port_data(port);
262 263
263 if (port->tty) { 264 if (tty) {
264 int val = 0; 265 int val = 0;
265 if (portdata->dtr_state) 266 if (portdata->dtr_state)
266 val |= 0x01; 267 val |= 0x01;
@@ -284,32 +285,17 @@ static int sierra_send_setup(struct usb_serial_port *port)
284 return 0; 285 return 0;
285} 286}
286 287
287static void sierra_rx_throttle(struct usb_serial_port *port) 288static void sierra_set_termios(struct tty_struct *tty,
289 struct usb_serial_port *port, struct ktermios *old_termios)
288{ 290{
289 dbg("%s", __func__); 291 dbg("%s", __func__);
292 tty_termios_copy_hw(tty->termios, old_termios);
293 sierra_send_setup(tty, port);
290} 294}
291 295
292static void sierra_rx_unthrottle(struct usb_serial_port *port) 296static int sierra_tiocmget(struct tty_struct *tty, struct file *file)
293{
294 dbg("%s", __func__);
295}
296
297static void sierra_break_ctl(struct usb_serial_port *port, int break_state)
298{
299 /* Unfortunately, I don't know how to send a break */
300 dbg("%s", __func__);
301}
302
303static void sierra_set_termios(struct usb_serial_port *port,
304 struct ktermios *old_termios)
305{
306 dbg("%s", __func__);
307 tty_termios_copy_hw(port->tty->termios, old_termios);
308 sierra_send_setup(port);
309}
310
311static int sierra_tiocmget(struct usb_serial_port *port, struct file *file)
312{ 297{
298 struct usb_serial_port *port = tty->driver_data;
313 unsigned int value; 299 unsigned int value;
314 struct sierra_port_private *portdata; 300 struct sierra_port_private *portdata;
315 301
@@ -325,9 +311,10 @@ static int sierra_tiocmget(struct usb_serial_port *port, struct file *file)
325 return value; 311 return value;
326} 312}
327 313
328static int sierra_tiocmset(struct usb_serial_port *port, struct file *file, 314static int sierra_tiocmset(struct tty_struct *tty, struct file *file,
329 unsigned int set, unsigned int clear) 315 unsigned int set, unsigned int clear)
330{ 316{
317 struct usb_serial_port *port = tty->driver_data;
331 struct sierra_port_private *portdata; 318 struct sierra_port_private *portdata;
332 319
333 portdata = usb_get_serial_port_data(port); 320 portdata = usb_get_serial_port_data(port);
@@ -341,13 +328,7 @@ static int sierra_tiocmset(struct usb_serial_port *port, struct file *file,
341 portdata->rts_state = 0; 328 portdata->rts_state = 0;
342 if (clear & TIOCM_DTR) 329 if (clear & TIOCM_DTR)
343 portdata->dtr_state = 0; 330 portdata->dtr_state = 0;
344 return sierra_send_setup(port); 331 return sierra_send_setup(tty, port);
345}
346
347static int sierra_ioctl(struct usb_serial_port *port, struct file *file,
348 unsigned int cmd, unsigned long arg)
349{
350 return -ENOIOCTLCMD;
351} 332}
352 333
353static void sierra_outdat_callback(struct urb *urb) 334static void sierra_outdat_callback(struct urb *urb)
@@ -374,8 +355,8 @@ static void sierra_outdat_callback(struct urb *urb)
374} 355}
375 356
376/* Write */ 357/* Write */
377static int sierra_write(struct usb_serial_port *port, 358static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
378 const unsigned char *buf, int count) 359 const unsigned char *buf, int count)
379{ 360{
380 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 361 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
381 struct usb_serial *serial = port->serial; 362 struct usb_serial *serial = port->serial;
@@ -463,7 +444,7 @@ static void sierra_indat_callback(struct urb *urb)
463 dbg("%s: nonzero status: %d on endpoint %02x.", 444 dbg("%s: nonzero status: %d on endpoint %02x.",
464 __func__, status, endpoint); 445 __func__, status, endpoint);
465 } else { 446 } else {
466 tty = port->tty; 447 tty = port->port.tty;
467 if (urb->actual_length) { 448 if (urb->actual_length) {
468 tty_buffer_request_room(tty, urb->actual_length); 449 tty_buffer_request_room(tty, urb->actual_length);
469 tty_insert_flip_string(tty, data, urb->actual_length); 450 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -473,7 +454,7 @@ static void sierra_indat_callback(struct urb *urb)
473 } 454 }
474 455
475 /* Resubmit urb so we continue receiving */ 456 /* Resubmit urb so we continue receiving */
476 if (port->open_count && status != -ESHUTDOWN) { 457 if (port->port.count && status != -ESHUTDOWN) {
477 err = usb_submit_urb(urb, GFP_ATOMIC); 458 err = usb_submit_urb(urb, GFP_ATOMIC);
478 if (err) 459 if (err)
479 dev_err(&port->dev, "resubmit read urb failed." 460 dev_err(&port->dev, "resubmit read urb failed."
@@ -517,9 +498,9 @@ static void sierra_instat_callback(struct urb *urb)
517 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); 498 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
518 portdata->ri_state = ((signals & 0x08) ? 1 : 0); 499 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
519 500
520 if (port->tty && !C_CLOCAL(port->tty) && 501 if (port->port.tty && !C_CLOCAL(port->port.tty) &&
521 old_dcd_state && !portdata->dcd_state) 502 old_dcd_state && !portdata->dcd_state)
522 tty_hangup(port->tty); 503 tty_hangup(port->port.tty);
523 } else { 504 } else {
524 dbg("%s: type %x req %x", __func__, 505 dbg("%s: type %x req %x", __func__,
525 req_pkt->bRequestType, req_pkt->bRequest); 506 req_pkt->bRequestType, req_pkt->bRequest);
@@ -537,8 +518,9 @@ static void sierra_instat_callback(struct urb *urb)
537 } 518 }
538} 519}
539 520
540static int sierra_write_room(struct usb_serial_port *port) 521static int sierra_write_room(struct tty_struct *tty)
541{ 522{
523 struct usb_serial_port *port = tty->driver_data;
542 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 524 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
543 unsigned long flags; 525 unsigned long flags;
544 526
@@ -557,22 +539,8 @@ static int sierra_write_room(struct usb_serial_port *port)
557 return 2048; 539 return 2048;
558} 540}
559 541
560static int sierra_chars_in_buffer(struct usb_serial_port *port) 542static int sierra_open(struct tty_struct *tty,
561{ 543 struct usb_serial_port *port, struct file *filp)
562 dbg("%s - port %d", __func__, port->number);
563
564 /*
565 * We can't really account for how much data we
566 * have sent out, but hasn't made it through to the
567 * device as we can't see the backend here, so just
568 * tell the tty layer that everything is flushed.
569 *
570 * FIXME: should walk the outstanding urbs info
571 */
572 return 0;
573}
574
575static int sierra_open(struct usb_serial_port *port, struct file *filp)
576{ 544{
577 struct sierra_port_private *portdata; 545 struct sierra_port_private *portdata;
578 struct usb_serial *serial = port->serial; 546 struct usb_serial *serial = port->serial;
@@ -612,9 +580,10 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp)
612 } 580 }
613 } 581 }
614 582
615 port->tty->low_latency = 1; 583 if (tty)
584 tty->low_latency = 1;
616 585
617 sierra_send_setup(port); 586 sierra_send_setup(tty, port);
618 587
619 /* start up the interrupt endpoint if we have one */ 588 /* start up the interrupt endpoint if we have one */
620 if (port->interrupt_in_urb) { 589 if (port->interrupt_in_urb) {
@@ -626,7 +595,8 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp)
626 return 0; 595 return 0;
627} 596}
628 597
629static void sierra_close(struct usb_serial_port *port, struct file *filp) 598static void sierra_close(struct tty_struct *tty,
599 struct usb_serial_port *port, struct file *filp)
630{ 600{
631 int i; 601 int i;
632 struct usb_serial *serial = port->serial; 602 struct usb_serial *serial = port->serial;
@@ -641,7 +611,7 @@ static void sierra_close(struct usb_serial_port *port, struct file *filp)
641 if (serial->dev) { 611 if (serial->dev) {
642 mutex_lock(&serial->disc_mutex); 612 mutex_lock(&serial->disc_mutex);
643 if (!serial->disconnected) 613 if (!serial->disconnected)
644 sierra_send_setup(port); 614 sierra_send_setup(tty, port);
645 mutex_unlock(&serial->disc_mutex); 615 mutex_unlock(&serial->disc_mutex);
646 616
647 /* Stop reading/writing urbs */ 617 /* Stop reading/writing urbs */
@@ -651,7 +621,7 @@ static void sierra_close(struct usb_serial_port *port, struct file *filp)
651 621
652 usb_kill_urb(port->interrupt_in_urb); 622 usb_kill_urb(port->interrupt_in_urb);
653 623
654 port->tty = NULL; 624 port->port.tty = NULL; /* FIXME */
655} 625}
656 626
657static int sierra_startup(struct usb_serial *serial) 627static int sierra_startup(struct usb_serial *serial)
@@ -754,12 +724,7 @@ static struct usb_serial_driver sierra_device = {
754 .close = sierra_close, 724 .close = sierra_close,
755 .write = sierra_write, 725 .write = sierra_write,
756 .write_room = sierra_write_room, 726 .write_room = sierra_write_room,
757 .chars_in_buffer = sierra_chars_in_buffer,
758 .throttle = sierra_rx_throttle,
759 .unthrottle = sierra_rx_unthrottle,
760 .ioctl = sierra_ioctl,
761 .set_termios = sierra_set_termios, 727 .set_termios = sierra_set_termios,
762 .break_ctl = sierra_break_ctl,
763 .tiocmget = sierra_tiocmget, 728 .tiocmget = sierra_tiocmget,
764 .tiocmset = sierra_tiocmset, 729 .tiocmset = sierra_tiocmset,
765 .attach = sierra_startup, 730 .attach = sierra_startup,
@@ -792,7 +757,7 @@ failed_device_register:
792 757
793static void __exit sierra_exit(void) 758static void __exit sierra_exit(void)
794{ 759{
795 usb_deregister (&sierra_driver); 760 usb_deregister(&sierra_driver);
796 usb_serial_deregister(&sierra_device); 761 usb_serial_deregister(&sierra_device);
797} 762}
798 763
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 55b2570b8b8b..283cf6b36b2c 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -208,7 +208,7 @@ static inline unsigned int ringbuf_avail_data(struct ringbuf *pb)
208{ 208{
209 if (pb == NULL) 209 if (pb == NULL)
210 return 0; 210 return 0;
211 return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); 211 return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size;
212} 212}
213 213
214/* get the number of space in the pipo */ 214/* get the number of space in the pipo */
@@ -216,7 +216,7 @@ static inline unsigned int ringbuf_avail_space(struct ringbuf *pb)
216{ 216{
217 if (pb == NULL) 217 if (pb == NULL)
218 return 0; 218 return 0;
219 return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); 219 return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size;
220} 220}
221 221
222/* put count data into pipo */ 222/* put count data into pipo */
@@ -448,7 +448,8 @@ static void spcp8x5_set_workMode(struct usb_device *dev, u16 value,
448 448
449/* close the serial port. We should wait for data sending to device 1st and 449/* close the serial port. We should wait for data sending to device 1st and
450 * then kill all urb. */ 450 * then kill all urb. */
451static void spcp8x5_close(struct usb_serial_port *port, struct file *filp) 451static void spcp8x5_close(struct tty_struct *tty,
452 struct usb_serial_port *port, struct file *filp)
452{ 453{
453 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 454 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
454 unsigned long flags; 455 unsigned long flags;
@@ -464,7 +465,7 @@ static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
464 spin_lock_irqsave(&priv->lock, flags); 465 spin_lock_irqsave(&priv->lock, flags);
465 timeout = SPCP8x5_CLOSING_WAIT; 466 timeout = SPCP8x5_CLOSING_WAIT;
466 init_waitqueue_entry(&wait, current); 467 init_waitqueue_entry(&wait, current);
467 add_wait_queue(&port->tty->write_wait, &wait); 468 add_wait_queue(&tty->write_wait, &wait);
468 for (;;) { 469 for (;;) {
469 set_current_state(TASK_INTERRUPTIBLE); 470 set_current_state(TASK_INTERRUPTIBLE);
470 if (ringbuf_avail_data(priv->buf) == 0 || 471 if (ringbuf_avail_data(priv->buf) == 0 ||
@@ -475,7 +476,7 @@ static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
475 spin_lock_irqsave(&priv->lock, flags); 476 spin_lock_irqsave(&priv->lock, flags);
476 } 477 }
477 set_current_state(TASK_RUNNING); 478 set_current_state(TASK_RUNNING);
478 remove_wait_queue(&port->tty->write_wait, &wait); 479 remove_wait_queue(&tty->write_wait, &wait);
479 480
480 /* clear out any remaining data in the buffer */ 481 /* clear out any remaining data in the buffer */
481 clear_ringbuf(priv->buf); 482 clear_ringbuf(priv->buf);
@@ -486,7 +487,7 @@ static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
486 * flow control for data rates of 1200 bps or more, for lower rates we 487 * flow control for data rates of 1200 bps or more, for lower rates we
487 * should really know how much data is in the buffer to compute a delay 488 * should really know how much data is in the buffer to compute a delay
488 * that is not unnecessarily long) */ 489 * that is not unnecessarily long) */
489 bps = tty_get_baud_rate(port->tty); 490 bps = tty_get_baud_rate(tty);
490 if (bps > 1200) 491 if (bps > 1200)
491 timeout = max((HZ*2560) / bps, HZ/10); 492 timeout = max((HZ*2560) / bps, HZ/10);
492 else 493 else
@@ -495,8 +496,8 @@ static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
495 schedule_timeout(timeout); 496 schedule_timeout(timeout);
496 497
497 /* clear control lines */ 498 /* clear control lines */
498 if (port->tty) { 499 if (tty) {
499 c_cflag = port->tty->termios->c_cflag; 500 c_cflag = tty->termios->c_cflag;
500 if (c_cflag & HUPCL) { 501 if (c_cflag & HUPCL) {
501 spin_lock_irqsave(&priv->lock, flags); 502 spin_lock_irqsave(&priv->lock, flags);
502 priv->line_control = 0; 503 priv->line_control = 0;
@@ -518,14 +519,14 @@ static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
518} 519}
519 520
520/* set the serial param for transfer. we should check if we really need to 521/* set the serial param for transfer. we should check if we really need to
521 * transfer. then if be set flow contorl we should do this too. */ 522 * transfer. if we set flow control we should do this too. */
522static void spcp8x5_set_termios(struct usb_serial_port *port, 523static void spcp8x5_set_termios(struct tty_struct *tty,
523 struct ktermios *old_termios) 524 struct usb_serial_port *port, struct ktermios *old_termios)
524{ 525{
525 struct usb_serial *serial = port->serial; 526 struct usb_serial *serial = port->serial;
526 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 527 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
527 unsigned long flags; 528 unsigned long flags;
528 unsigned int cflag = port->tty->termios->c_cflag; 529 unsigned int cflag = tty->termios->c_cflag;
529 unsigned int old_cflag = old_termios->c_cflag; 530 unsigned int old_cflag = old_termios->c_cflag;
530 unsigned short uartdata; 531 unsigned short uartdata;
531 unsigned char buf[2] = {0, 0}; 532 unsigned char buf[2] = {0, 0};
@@ -533,21 +534,19 @@ static void spcp8x5_set_termios(struct usb_serial_port *port,
533 int i; 534 int i;
534 u8 control; 535 u8 control;
535 536
536 if ((!port->tty) || (!port->tty->termios))
537 return;
538
539 /* for the 1st time call this function */ 537 /* for the 1st time call this function */
540 spin_lock_irqsave(&priv->lock, flags); 538 spin_lock_irqsave(&priv->lock, flags);
541 if (!priv->termios_initialized) { 539 if (!priv->termios_initialized) {
542 *(port->tty->termios) = tty_std_termios; 540 *(tty->termios) = tty_std_termios;
543 port->tty->termios->c_cflag = B115200 | CS8 | CREAD | 541 tty->termios->c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL;
544 HUPCL | CLOCAL; 542 tty->termios->c_ispeed = 115200;
543 tty->termios->c_ospeed = 115200;
545 priv->termios_initialized = 1; 544 priv->termios_initialized = 1;
546 } 545 }
547 spin_unlock_irqrestore(&priv->lock, flags); 546 spin_unlock_irqrestore(&priv->lock, flags);
548 547
549 /* check that they really want us to change something */ 548 /* check that they really want us to change something */
550 if (!tty_termios_hw_change(port->tty->termios, old_termios)) 549 if (!tty_termios_hw_change(tty->termios, old_termios))
551 return; 550 return;
552 551
553 /* set DTR/RTS active */ 552 /* set DTR/RTS active */
@@ -567,7 +566,7 @@ static void spcp8x5_set_termios(struct usb_serial_port *port,
567 } 566 }
568 567
569 /* Set Baud Rate */ 568 /* Set Baud Rate */
570 baud = tty_get_baud_rate(port->tty);; 569 baud = tty_get_baud_rate(tty);;
571 switch (baud) { 570 switch (baud) {
572 case 300: buf[0] = 0x00; break; 571 case 300: buf[0] = 0x00; break;
573 case 600: buf[0] = 0x01; break; 572 case 600: buf[0] = 0x01; break;
@@ -643,7 +642,8 @@ static void spcp8x5_set_termios(struct usb_serial_port *port,
643 642
644/* open the serial port. do some usb system call. set termios and get the line 643/* open the serial port. do some usb system call. set termios and get the line
645 * status of the device. then submit the read urb */ 644 * status of the device. then submit the read urb */
646static int spcp8x5_open(struct usb_serial_port *port, struct file *filp) 645static int spcp8x5_open(struct tty_struct *tty,
646 struct usb_serial_port *port, struct file *filp)
647{ 647{
648 struct ktermios tmp_termios; 648 struct ktermios tmp_termios;
649 struct usb_serial *serial = port->serial; 649 struct usb_serial *serial = port->serial;
@@ -665,7 +665,7 @@ static int spcp8x5_open(struct usb_serial_port *port, struct file *filp)
665 return ret; 665 return ret;
666 666
667 spin_lock_irqsave(&priv->lock, flags); 667 spin_lock_irqsave(&priv->lock, flags);
668 if (port->tty->termios->c_cflag & CBAUD) 668 if (tty && (tty->termios->c_cflag & CBAUD))
669 priv->line_control = MCR_DTR | MCR_RTS; 669 priv->line_control = MCR_DTR | MCR_RTS;
670 else 670 else
671 priv->line_control = 0; 671 priv->line_control = 0;
@@ -674,8 +674,8 @@ static int spcp8x5_open(struct usb_serial_port *port, struct file *filp)
674 spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type); 674 spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type);
675 675
676 /* Setup termios */ 676 /* Setup termios */
677 if (port->tty) 677 if (tty)
678 spcp8x5_set_termios(port, &tmp_termios); 678 spcp8x5_set_termios(tty, port, &tmp_termios);
679 679
680 spcp8x5_get_msr(serial->dev, &status, priv->type); 680 spcp8x5_get_msr(serial->dev, &status, priv->type);
681 681
@@ -690,7 +690,7 @@ static int spcp8x5_open(struct usb_serial_port *port, struct file *filp)
690 port->read_urb->dev = serial->dev; 690 port->read_urb->dev = serial->dev;
691 ret = usb_submit_urb(port->read_urb, GFP_KERNEL); 691 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
692 if (ret) { 692 if (ret) {
693 spcp8x5_close(port, NULL); 693 spcp8x5_close(tty, port, NULL);
694 return -EPROTO; 694 return -EPROTO;
695 } 695 }
696 return 0; 696 return 0;
@@ -717,7 +717,7 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
717 717
718 /* check the urb status */ 718 /* check the urb status */
719 if (urb->status) { 719 if (urb->status) {
720 if (!port->open_count) 720 if (!port->port.count)
721 return; 721 return;
722 if (urb->status == -EPROTO) { 722 if (urb->status == -EPROTO) {
723 /* spcp8x5 mysteriously fails with -EPROTO */ 723 /* spcp8x5 mysteriously fails with -EPROTO */
@@ -755,7 +755,7 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
755 tty_flag = TTY_FRAME; 755 tty_flag = TTY_FRAME;
756 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag); 756 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
757 757
758 tty = port->tty; 758 tty = port->port.tty;
759 if (tty && urb->actual_length) { 759 if (tty && urb->actual_length) {
760 tty_buffer_request_room(tty, urb->actual_length + 1); 760 tty_buffer_request_room(tty, urb->actual_length + 1);
761 /* overrun is special, not associated with a char */ 761 /* overrun is special, not associated with a char */
@@ -767,7 +767,7 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
767 } 767 }
768 768
769 /* Schedule the next read _if_ we are still open */ 769 /* Schedule the next read _if_ we are still open */
770 if (port->open_count) { 770 if (port->port.count) {
771 urb->dev = port->serial->dev; 771 urb->dev = port->serial->dev;
772 result = usb_submit_urb(urb , GFP_ATOMIC); 772 result = usb_submit_urb(urb , GFP_ATOMIC);
773 if (result) 773 if (result)
@@ -866,7 +866,7 @@ static void spcp8x5_write_bulk_callback(struct urb *urb)
866} 866}
867 867
868/* write data to ring buffer. and then start the write transfer */ 868/* write data to ring buffer. and then start the write transfer */
869static int spcp8x5_write(struct usb_serial_port *port, 869static int spcp8x5_write(struct tty_struct *tty, struct usb_serial_port *port,
870 const unsigned char *buf, int count) 870 const unsigned char *buf, int count)
871{ 871{
872 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 872 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
@@ -925,9 +925,10 @@ static int spcp8x5_wait_modem_info(struct usb_serial_port *port,
925 return 0; 925 return 0;
926} 926}
927 927
928static int spcp8x5_ioctl(struct usb_serial_port *port, struct file *file, 928static int spcp8x5_ioctl(struct tty_struct *tty, struct file *file,
929 unsigned int cmd, unsigned long arg) 929 unsigned int cmd, unsigned long arg)
930{ 930{
931 struct usb_serial_port *port = tty->driver_data;
931 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd); 932 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd);
932 933
933 switch (cmd) { 934 switch (cmd) {
@@ -943,9 +944,10 @@ static int spcp8x5_ioctl(struct usb_serial_port *port, struct file *file,
943 return -ENOIOCTLCMD; 944 return -ENOIOCTLCMD;
944} 945}
945 946
946static int spcp8x5_tiocmset(struct usb_serial_port *port, struct file *file, 947static int spcp8x5_tiocmset(struct tty_struct *tty, struct file *file,
947 unsigned int set, unsigned int clear) 948 unsigned int set, unsigned int clear)
948{ 949{
950 struct usb_serial_port *port = tty->driver_data;
949 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 951 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
950 unsigned long flags; 952 unsigned long flags;
951 u8 control; 953 u8 control;
@@ -965,8 +967,9 @@ static int spcp8x5_tiocmset(struct usb_serial_port *port, struct file *file,
965 return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); 967 return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type);
966} 968}
967 969
968static int spcp8x5_tiocmget(struct usb_serial_port *port, struct file *file) 970static int spcp8x5_tiocmget(struct tty_struct *tty, struct file *file)
969{ 971{
972 struct usb_serial_port *port = tty->driver_data;
970 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 973 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
971 unsigned long flags; 974 unsigned long flags;
972 unsigned int mcr; 975 unsigned int mcr;
@@ -989,8 +992,9 @@ static int spcp8x5_tiocmget(struct usb_serial_port *port, struct file *file)
989} 992}
990 993
991/* get the avail space room in ring buffer */ 994/* get the avail space room in ring buffer */
992static int spcp8x5_write_room(struct usb_serial_port *port) 995static int spcp8x5_write_room(struct tty_struct *tty)
993{ 996{
997 struct usb_serial_port *port = tty->driver_data;
994 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 998 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
995 int room = 0; 999 int room = 0;
996 unsigned long flags; 1000 unsigned long flags;
@@ -1003,8 +1007,9 @@ static int spcp8x5_write_room(struct usb_serial_port *port)
1003} 1007}
1004 1008
1005/* get the number of avail data in write ring buffer */ 1009/* get the number of avail data in write ring buffer */
1006static int spcp8x5_chars_in_buffer(struct usb_serial_port *port) 1010static int spcp8x5_chars_in_buffer(struct tty_struct *tty)
1007{ 1011{
1012 struct usb_serial_port *port = tty->driver_data;
1008 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 1013 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
1009 int chars = 0; 1014 int chars = 0;
1010 unsigned long flags; 1015 unsigned long flags;
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index a26a629dfc4f..e39c779e4160 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -16,7 +16,7 @@
16 * For questions or problems with this driver, contact Texas Instruments 16 * For questions or problems with this driver, contact Texas Instruments
17 * technical support, or Al Borchers <alborchers@steinerpoint.com>, or 17 * technical support, or Al Borchers <alborchers@steinerpoint.com>, or
18 * Peter Berger <pberger@brimson.com>. 18 * Peter Berger <pberger@brimson.com>.
19 * 19 *
20 * This driver needs this hotplug script in /etc/hotplug/usb/ti_usb_3410_5052 20 * This driver needs this hotplug script in /etc/hotplug/usb/ti_usb_3410_5052
21 * or in /etc/hotplug.d/usb/ti_usb_3410_5052.hotplug to set the device 21 * or in /etc/hotplug.d/usb/ti_usb_3410_5052.hotplug to set the device
22 * configuration. 22 * configuration.
@@ -70,6 +70,7 @@
70 70
71#include <linux/kernel.h> 71#include <linux/kernel.h>
72#include <linux/errno.h> 72#include <linux/errno.h>
73#include <linux/firmware.h>
73#include <linux/init.h> 74#include <linux/init.h>
74#include <linux/slab.h> 75#include <linux/slab.h>
75#include <linux/tty.h> 76#include <linux/tty.h>
@@ -81,7 +82,7 @@
81#include <linux/serial.h> 82#include <linux/serial.h>
82#include <linux/circ_buf.h> 83#include <linux/circ_buf.h>
83#include <linux/mutex.h> 84#include <linux/mutex.h>
84#include <asm/uaccess.h> 85#include <linux/uaccess.h>
85#include <linux/usb.h> 86#include <linux/usb.h>
86#include <linux/usb/serial.h> 87#include <linux/usb/serial.h>
87#include <linux/firmware.h> 88#include <linux/firmware.h>
@@ -149,21 +150,24 @@ struct ti_device {
149 150
150static int ti_startup(struct usb_serial *serial); 151static int ti_startup(struct usb_serial *serial);
151static void ti_shutdown(struct usb_serial *serial); 152static void ti_shutdown(struct usb_serial *serial);
152static int ti_open(struct usb_serial_port *port, struct file *file); 153static int ti_open(struct tty_struct *tty, struct usb_serial_port *port,
153static void ti_close(struct usb_serial_port *port, struct file *file); 154 struct file *file);
154static int ti_write(struct usb_serial_port *port, const unsigned char *data, 155static void ti_close(struct tty_struct *tty, struct usb_serial_port *port,
155 int count); 156 struct file *file);
156static int ti_write_room(struct usb_serial_port *port); 157static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
157static int ti_chars_in_buffer(struct usb_serial_port *port); 158 const unsigned char *data, int count);
158static void ti_throttle(struct usb_serial_port *port); 159static int ti_write_room(struct tty_struct *tty);
159static void ti_unthrottle(struct usb_serial_port *port); 160static int ti_chars_in_buffer(struct tty_struct *tty);
160static int ti_ioctl(struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg); 161static void ti_throttle(struct tty_struct *tty);
161static void ti_set_termios(struct usb_serial_port *port, 162static void ti_unthrottle(struct tty_struct *tty);
162 struct ktermios *old_termios); 163static int ti_ioctl(struct tty_struct *tty, struct file *file,
163static int ti_tiocmget(struct usb_serial_port *port, struct file *file); 164 unsigned int cmd, unsigned long arg);
164static int ti_tiocmset(struct usb_serial_port *port, struct file *file, 165static void ti_set_termios(struct tty_struct *tty,
165 unsigned int set, unsigned int clear); 166 struct usb_serial_port *port, struct ktermios *old_termios);
166static void ti_break(struct usb_serial_port *port, int break_state); 167static int ti_tiocmget(struct tty_struct *tty, struct file *file);
168static int ti_tiocmset(struct tty_struct *tty, struct file *file,
169 unsigned int set, unsigned int clear);
170static void ti_break(struct tty_struct *tty, int break_state);
167static void ti_interrupt_callback(struct urb *urb); 171static void ti_interrupt_callback(struct urb *urb);
168static void ti_bulk_in_callback(struct urb *urb); 172static void ti_bulk_in_callback(struct urb *urb);
169static void ti_bulk_out_callback(struct urb *urb); 173static void ti_bulk_out_callback(struct urb *urb);
@@ -192,8 +196,7 @@ static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
192static int ti_write_byte(struct ti_device *tdev, unsigned long addr, 196static int ti_write_byte(struct ti_device *tdev, unsigned long addr,
193 __u8 mask, __u8 byte); 197 __u8 mask, __u8 byte);
194 198
195static int ti_download_firmware(struct ti_device *tdev, char *fw_name); 199static int ti_download_firmware(struct ti_device *tdev, int type);
196
197 200
198/* circular buffer */ 201/* circular buffer */
199static struct circ_buf *ti_buf_alloc(void); 202static struct circ_buf *ti_buf_alloc(void);
@@ -325,19 +328,25 @@ module_param(debug, bool, S_IRUGO | S_IWUSR);
325MODULE_PARM_DESC(debug, "Enable debugging, 0=no, 1=yes"); 328MODULE_PARM_DESC(debug, "Enable debugging, 0=no, 1=yes");
326 329
327module_param(low_latency, bool, S_IRUGO | S_IWUSR); 330module_param(low_latency, bool, S_IRUGO | S_IWUSR);
328MODULE_PARM_DESC(low_latency, "TTY low_latency flag, 0=off, 1=on, default is off"); 331MODULE_PARM_DESC(low_latency,
332 "TTY low_latency flag, 0=off, 1=on, default is off");
329 333
330module_param(closing_wait, int, S_IRUGO | S_IWUSR); 334module_param(closing_wait, int, S_IRUGO | S_IWUSR);
331MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain in close, in .01 secs, default is 4000"); 335MODULE_PARM_DESC(closing_wait,
336 "Maximum wait for data to drain in close, in .01 secs, default is 4000");
332 337
333module_param_array(vendor_3410, ushort, &vendor_3410_count, S_IRUGO); 338module_param_array(vendor_3410, ushort, &vendor_3410_count, S_IRUGO);
334MODULE_PARM_DESC(vendor_3410, "Vendor ids for 3410 based devices, 1-5 short integers"); 339MODULE_PARM_DESC(vendor_3410,
340 "Vendor ids for 3410 based devices, 1-5 short integers");
335module_param_array(product_3410, ushort, &product_3410_count, S_IRUGO); 341module_param_array(product_3410, ushort, &product_3410_count, S_IRUGO);
336MODULE_PARM_DESC(product_3410, "Product ids for 3410 based devices, 1-5 short integers"); 342MODULE_PARM_DESC(product_3410,
343 "Product ids for 3410 based devices, 1-5 short integers");
337module_param_array(vendor_5052, ushort, &vendor_5052_count, S_IRUGO); 344module_param_array(vendor_5052, ushort, &vendor_5052_count, S_IRUGO);
338MODULE_PARM_DESC(vendor_5052, "Vendor ids for 5052 based devices, 1-5 short integers"); 345MODULE_PARM_DESC(vendor_5052,
346 "Vendor ids for 5052 based devices, 1-5 short integers");
339module_param_array(product_5052, ushort, &product_5052_count, S_IRUGO); 347module_param_array(product_5052, ushort, &product_5052_count, S_IRUGO);
340MODULE_PARM_DESC(product_5052, "Product ids for 5052 based devices, 1-5 short integers"); 348MODULE_PARM_DESC(product_5052,
349 "Product ids for 5052 based devices, 1-5 short integers");
341 350
342MODULE_DEVICE_TABLE(usb, ti_id_table_combined); 351MODULE_DEVICE_TABLE(usb, ti_id_table_combined);
343 352
@@ -346,18 +355,18 @@ MODULE_DEVICE_TABLE(usb, ti_id_table_combined);
346 355
347static int __init ti_init(void) 356static int __init ti_init(void)
348{ 357{
349 int i,j; 358 int i, j;
350 int ret; 359 int ret;
351 360
352 /* insert extra vendor and product ids */ 361 /* insert extra vendor and product ids */
353 j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1; 362 j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1;
354 for (i=0; i<min(vendor_3410_count,product_3410_count); i++,j++) { 363 for (i = 0; i < min(vendor_3410_count, product_3410_count); i++, j++) {
355 ti_id_table_3410[j].idVendor = vendor_3410[i]; 364 ti_id_table_3410[j].idVendor = vendor_3410[i];
356 ti_id_table_3410[j].idProduct = product_3410[i]; 365 ti_id_table_3410[j].idProduct = product_3410[i];
357 ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; 366 ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
358 } 367 }
359 j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1; 368 j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1;
360 for (i=0; i<min(vendor_5052_count,product_5052_count); i++,j++) { 369 for (i = 0; i < min(vendor_5052_count, product_5052_count); i++, j++) {
361 ti_id_table_5052[j].idVendor = vendor_5052[i]; 370 ti_id_table_5052[j].idVendor = vendor_5052[i];
362 ti_id_table_5052[j].idProduct = product_5052[i]; 371 ti_id_table_5052[j].idProduct = product_5052[i];
363 ti_id_table_5052[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; 372 ti_id_table_5052[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
@@ -426,15 +435,15 @@ static int ti_startup(struct usb_serial *serial)
426 /* determine device type */ 435 /* determine device type */
427 if (usb_match_id(serial->interface, ti_id_table_3410)) 436 if (usb_match_id(serial->interface, ti_id_table_3410))
428 tdev->td_is_3410 = 1; 437 tdev->td_is_3410 = 1;
429 dbg("%s - device type is %s", __func__, tdev->td_is_3410 ? "3410" : "5052"); 438 dbg("%s - device type is %s", __func__,
439 tdev->td_is_3410 ? "3410" : "5052");
430 440
431 /* if we have only 1 configuration, download firmware */ 441 /* if we have only 1 configuration, download firmware */
432 if (dev->descriptor.bNumConfigurations == 1) { 442 if (dev->descriptor.bNumConfigurations == 1) {
433
434 if (tdev->td_is_3410) 443 if (tdev->td_is_3410)
435 status = ti_download_firmware(tdev, "ti_3410.fw"); 444 status = ti_download_firmware(tdev, 3410);
436 else 445 else
437 status = ti_download_firmware(tdev, "ti_5052.fw"); 446 status = ti_download_firmware(tdev, 5052);
438 if (status) 447 if (status)
439 goto free_tdev; 448 goto free_tdev;
440 449
@@ -446,7 +455,7 @@ static int ti_startup(struct usb_serial *serial)
446 455
447 status = -ENODEV; 456 status = -ENODEV;
448 goto free_tdev; 457 goto free_tdev;
449 } 458 }
450 459
451 /* the second configuration must be set (in sysfs by hotplug script) */ 460 /* the second configuration must be set (in sysfs by hotplug script) */
452 if (dev->actconfig->desc.bConfigurationValue == TI_BOOT_CONFIG) { 461 if (dev->actconfig->desc.bConfigurationValue == TI_BOOT_CONFIG) {
@@ -463,7 +472,8 @@ static int ti_startup(struct usb_serial *serial)
463 goto free_tports; 472 goto free_tports;
464 } 473 }
465 spin_lock_init(&tport->tp_lock); 474 spin_lock_init(&tport->tp_lock);
466 tport->tp_uart_base_addr = (i == 0 ? TI_UART1_BASE_ADDR : TI_UART2_BASE_ADDR); 475 tport->tp_uart_base_addr = (i == 0 ?
476 TI_UART1_BASE_ADDR : TI_UART2_BASE_ADDR);
467 tport->tp_flags = low_latency ? ASYNC_LOW_LATENCY : 0; 477 tport->tp_flags = low_latency ? ASYNC_LOW_LATENCY : 0;
468 tport->tp_closing_wait = closing_wait; 478 tport->tp_closing_wait = closing_wait;
469 init_waitqueue_head(&tport->tp_msr_wait); 479 init_waitqueue_head(&tport->tp_msr_wait);
@@ -480,11 +490,11 @@ static int ti_startup(struct usb_serial *serial)
480 usb_set_serial_port_data(serial->port[i], tport); 490 usb_set_serial_port_data(serial->port[i], tport);
481 tport->tp_uart_mode = 0; /* default is RS232 */ 491 tport->tp_uart_mode = 0; /* default is RS232 */
482 } 492 }
483 493
484 return 0; 494 return 0;
485 495
486free_tports: 496free_tports:
487 for (--i; i>=0; --i) { 497 for (--i; i >= 0; --i) {
488 tport = usb_get_serial_port_data(serial->port[i]); 498 tport = usb_get_serial_port_data(serial->port[i]);
489 ti_buf_free(tport->tp_write_buf); 499 ti_buf_free(tport->tp_write_buf);
490 kfree(tport); 500 kfree(tport);
@@ -505,7 +515,7 @@ static void ti_shutdown(struct usb_serial *serial)
505 515
506 dbg("%s", __func__); 516 dbg("%s", __func__);
507 517
508 for (i=0; i < serial->num_ports; ++i) { 518 for (i = 0; i < serial->num_ports; ++i) {
509 tport = usb_get_serial_port_data(serial->port[i]); 519 tport = usb_get_serial_port_data(serial->port[i]);
510 if (tport) { 520 if (tport) {
511 ti_buf_free(tport->tp_write_buf); 521 ti_buf_free(tport->tp_write_buf);
@@ -519,7 +529,8 @@ static void ti_shutdown(struct usb_serial *serial)
519} 529}
520 530
521 531
522static int ti_open(struct usb_serial_port *port, struct file *file) 532static int ti_open(struct tty_struct *tty,
533 struct usb_serial_port *port, struct file *file)
523{ 534{
524 struct ti_port *tport = usb_get_serial_port_data(port); 535 struct ti_port *tport = usb_get_serial_port_data(port);
525 struct ti_device *tdev; 536 struct ti_device *tdev;
@@ -527,8 +538,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
527 struct urb *urb; 538 struct urb *urb;
528 int port_number; 539 int port_number;
529 int status; 540 int status;
530 __u16 open_settings = (__u8)(TI_PIPE_MODE_CONTINOUS | 541 __u16 open_settings = (__u8)(TI_PIPE_MODE_CONTINOUS |
531 TI_PIPE_TIMEOUT_ENABLE | 542 TI_PIPE_TIMEOUT_ENABLE |
532 (TI_TRANSFER_TIMEOUT << 2)); 543 (TI_TRANSFER_TIMEOUT << 2));
533 544
534 dbg("%s - port %d", __func__, port->number); 545 dbg("%s - port %d", __func__, port->number);
@@ -543,9 +554,9 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
543 if (mutex_lock_interruptible(&tdev->td_open_close_lock)) 554 if (mutex_lock_interruptible(&tdev->td_open_close_lock))
544 return -ERESTARTSYS; 555 return -ERESTARTSYS;
545 556
546 if (port->tty) 557 if (tty)
547 port->tty->low_latency = 558 tty->low_latency =
548 (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0; 559 (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0;
549 560
550 port_number = port->number - port->serial->minor; 561 port_number = port->number - port->serial->minor;
551 562
@@ -559,7 +570,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
559 dbg("%s - start interrupt in urb", __func__); 570 dbg("%s - start interrupt in urb", __func__);
560 urb = tdev->td_serial->port[0]->interrupt_in_urb; 571 urb = tdev->td_serial->port[0]->interrupt_in_urb;
561 if (!urb) { 572 if (!urb) {
562 dev_err(&port->dev, "%s - no interrupt urb\n", __func__); 573 dev_err(&port->dev, "%s - no interrupt urb\n",
574 __func__);
563 status = -EINVAL; 575 status = -EINVAL;
564 goto release_lock; 576 goto release_lock;
565 } 577 }
@@ -568,18 +580,22 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
568 urb->dev = dev; 580 urb->dev = dev;
569 status = usb_submit_urb(urb, GFP_KERNEL); 581 status = usb_submit_urb(urb, GFP_KERNEL);
570 if (status) { 582 if (status) {
571 dev_err(&port->dev, "%s - submit interrupt urb failed, %d\n", __func__, status); 583 dev_err(&port->dev,
584 "%s - submit interrupt urb failed, %d\n",
585 __func__, status);
572 goto release_lock; 586 goto release_lock;
573 } 587 }
574 } 588 }
575 589
576 ti_set_termios(port, port->tty->termios); 590 if (tty)
591 ti_set_termios(tty, port, tty->termios);
577 592
578 dbg("%s - sending TI_OPEN_PORT", __func__); 593 dbg("%s - sending TI_OPEN_PORT", __func__);
579 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 594 status = ti_command_out_sync(tdev, TI_OPEN_PORT,
580 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 595 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
581 if (status) { 596 if (status) {
582 dev_err(&port->dev, "%s - cannot send open command, %d\n", __func__, status); 597 dev_err(&port->dev, "%s - cannot send open command, %d\n",
598 __func__, status);
583 goto unlink_int_urb; 599 goto unlink_int_urb;
584 } 600 }
585 601
@@ -587,7 +603,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
587 status = ti_command_out_sync(tdev, TI_START_PORT, 603 status = ti_command_out_sync(tdev, TI_START_PORT,
588 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 604 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
589 if (status) { 605 if (status) {
590 dev_err(&port->dev, "%s - cannot send start command, %d\n", __func__, status); 606 dev_err(&port->dev, "%s - cannot send start command, %d\n",
607 __func__, status);
591 goto unlink_int_urb; 608 goto unlink_int_urb;
592 } 609 }
593 610
@@ -595,13 +612,15 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
595 status = ti_command_out_sync(tdev, TI_PURGE_PORT, 612 status = ti_command_out_sync(tdev, TI_PURGE_PORT,
596 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0); 613 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0);
597 if (status) { 614 if (status) {
598 dev_err(&port->dev, "%s - cannot clear input buffers, %d\n", __func__, status); 615 dev_err(&port->dev, "%s - cannot clear input buffers, %d\n",
616 __func__, status);
599 goto unlink_int_urb; 617 goto unlink_int_urb;
600 } 618 }
601 status = ti_command_out_sync(tdev, TI_PURGE_PORT, 619 status = ti_command_out_sync(tdev, TI_PURGE_PORT,
602 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0); 620 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0);
603 if (status) { 621 if (status) {
604 dev_err(&port->dev, "%s - cannot clear output buffers, %d\n", __func__, status); 622 dev_err(&port->dev, "%s - cannot clear output buffers, %d\n",
623 __func__, status);
605 goto unlink_int_urb; 624 goto unlink_int_urb;
606 } 625 }
607 626
@@ -610,13 +629,15 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
610 usb_clear_halt(dev, port->write_urb->pipe); 629 usb_clear_halt(dev, port->write_urb->pipe);
611 usb_clear_halt(dev, port->read_urb->pipe); 630 usb_clear_halt(dev, port->read_urb->pipe);
612 631
613 ti_set_termios(port, port->tty->termios); 632 if (tty)
633 ti_set_termios(tty, port, tty->termios);
614 634
615 dbg("%s - sending TI_OPEN_PORT (2)", __func__); 635 dbg("%s - sending TI_OPEN_PORT (2)", __func__);
616 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 636 status = ti_command_out_sync(tdev, TI_OPEN_PORT,
617 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 637 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
618 if (status) { 638 if (status) {
619 dev_err(&port->dev, "%s - cannot send open command (2), %d\n", __func__, status); 639 dev_err(&port->dev, "%s - cannot send open command (2), %d\n",
640 __func__, status);
620 goto unlink_int_urb; 641 goto unlink_int_urb;
621 } 642 }
622 643
@@ -624,7 +645,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
624 status = ti_command_out_sync(tdev, TI_START_PORT, 645 status = ti_command_out_sync(tdev, TI_START_PORT,
625 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 646 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
626 if (status) { 647 if (status) {
627 dev_err(&port->dev, "%s - cannot send start command (2), %d\n", __func__, status); 648 dev_err(&port->dev, "%s - cannot send start command (2), %d\n",
649 __func__, status);
628 goto unlink_int_urb; 650 goto unlink_int_urb;
629 } 651 }
630 652
@@ -642,7 +664,8 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
642 urb->dev = dev; 664 urb->dev = dev;
643 status = usb_submit_urb(urb, GFP_KERNEL); 665 status = usb_submit_urb(urb, GFP_KERNEL);
644 if (status) { 666 if (status) {
645 dev_err(&port->dev, "%s - submit read urb failed, %d\n", __func__, status); 667 dev_err(&port->dev, "%s - submit read urb failed, %d\n",
668 __func__, status);
646 goto unlink_int_urb; 669 goto unlink_int_urb;
647 } 670 }
648 671
@@ -661,7 +684,8 @@ release_lock:
661} 684}
662 685
663 686
664static void ti_close(struct usb_serial_port *port, struct file *file) 687static void ti_close(struct tty_struct *tty, struct usb_serial_port *port,
688 struct file *file)
665{ 689{
666 struct ti_device *tdev; 690 struct ti_device *tdev;
667 struct ti_port *tport; 691 struct ti_port *tport;
@@ -670,7 +694,7 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
670 int do_unlock; 694 int do_unlock;
671 695
672 dbg("%s - port %d", __func__, port->number); 696 dbg("%s - port %d", __func__, port->number);
673 697
674 tdev = usb_get_serial_data(port->serial); 698 tdev = usb_get_serial_data(port->serial);
675 tport = usb_get_serial_port_data(port); 699 tport = usb_get_serial_port_data(port);
676 if (tdev == NULL || tport == NULL) 700 if (tdev == NULL || tport == NULL)
@@ -690,7 +714,9 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
690 status = ti_command_out_sync(tdev, TI_CLOSE_PORT, 714 status = ti_command_out_sync(tdev, TI_CLOSE_PORT,
691 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 715 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
692 if (status) 716 if (status)
693 dev_err(&port->dev, "%s - cannot send close port command, %d\n" , __func__, status); 717 dev_err(&port->dev,
718 "%s - cannot send close port command, %d\n"
719 , __func__, status);
694 720
695 /* if mutex_lock is interrupted, continue anyway */ 721 /* if mutex_lock is interrupted, continue anyway */
696 do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock); 722 do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock);
@@ -707,8 +733,8 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
707} 733}
708 734
709 735
710static int ti_write(struct usb_serial_port *port, const unsigned char *data, 736static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
711 int count) 737 const unsigned char *data, int count)
712{ 738{
713 struct ti_port *tport = usb_get_serial_port_data(port); 739 struct ti_port *tport = usb_get_serial_port_data(port);
714 unsigned long flags; 740 unsigned long flags;
@@ -733,8 +759,9 @@ static int ti_write(struct usb_serial_port *port, const unsigned char *data,
733} 759}
734 760
735 761
736static int ti_write_room(struct usb_serial_port *port) 762static int ti_write_room(struct tty_struct *tty)
737{ 763{
764 struct usb_serial_port *port = tty->driver_data;
738 struct ti_port *tport = usb_get_serial_port_data(port); 765 struct ti_port *tport = usb_get_serial_port_data(port);
739 int room = 0; 766 int room = 0;
740 unsigned long flags; 767 unsigned long flags;
@@ -743,7 +770,7 @@ static int ti_write_room(struct usb_serial_port *port)
743 770
744 if (tport == NULL) 771 if (tport == NULL)
745 return -ENODEV; 772 return -ENODEV;
746 773
747 spin_lock_irqsave(&tport->tp_lock, flags); 774 spin_lock_irqsave(&tport->tp_lock, flags);
748 room = ti_buf_space_avail(tport->tp_write_buf); 775 room = ti_buf_space_avail(tport->tp_write_buf);
749 spin_unlock_irqrestore(&tport->tp_lock, flags); 776 spin_unlock_irqrestore(&tport->tp_lock, flags);
@@ -753,8 +780,9 @@ static int ti_write_room(struct usb_serial_port *port)
753} 780}
754 781
755 782
756static int ti_chars_in_buffer(struct usb_serial_port *port) 783static int ti_chars_in_buffer(struct tty_struct *tty)
757{ 784{
785 struct usb_serial_port *port = tty->driver_data;
758 struct ti_port *tport = usb_get_serial_port_data(port); 786 struct ti_port *tport = usb_get_serial_port_data(port);
759 int chars = 0; 787 int chars = 0;
760 unsigned long flags; 788 unsigned long flags;
@@ -773,32 +801,26 @@ static int ti_chars_in_buffer(struct usb_serial_port *port)
773} 801}
774 802
775 803
776static void ti_throttle(struct usb_serial_port *port) 804static void ti_throttle(struct tty_struct *tty)
777{ 805{
806 struct usb_serial_port *port = tty->driver_data;
778 struct ti_port *tport = usb_get_serial_port_data(port); 807 struct ti_port *tport = usb_get_serial_port_data(port);
779 struct tty_struct *tty;
780 808
781 dbg("%s - port %d", __func__, port->number); 809 dbg("%s - port %d", __func__, port->number);
782 810
783 if (tport == NULL) 811 if (tport == NULL)
784 return; 812 return;
785 813
786 tty = port->tty;
787 if (!tty) {
788 dbg("%s - no tty", __func__);
789 return;
790 }
791
792 if (I_IXOFF(tty) || C_CRTSCTS(tty)) 814 if (I_IXOFF(tty) || C_CRTSCTS(tty))
793 ti_stop_read(tport, tty); 815 ti_stop_read(tport, tty);
794 816
795} 817}
796 818
797 819
798static void ti_unthrottle(struct usb_serial_port *port) 820static void ti_unthrottle(struct tty_struct *tty)
799{ 821{
822 struct usb_serial_port *port = tty->driver_data;
800 struct ti_port *tport = usb_get_serial_port_data(port); 823 struct ti_port *tport = usb_get_serial_port_data(port);
801 struct tty_struct *tty;
802 int status; 824 int status;
803 825
804 dbg("%s - port %d", __func__, port->number); 826 dbg("%s - port %d", __func__, port->number);
@@ -806,23 +828,19 @@ static void ti_unthrottle(struct usb_serial_port *port)
806 if (tport == NULL) 828 if (tport == NULL)
807 return; 829 return;
808 830
809 tty = port->tty;
810 if (!tty) {
811 dbg("%s - no tty", __func__);
812 return;
813 }
814
815 if (I_IXOFF(tty) || C_CRTSCTS(tty)) { 831 if (I_IXOFF(tty) || C_CRTSCTS(tty)) {
816 status = ti_restart_read(tport, tty); 832 status = ti_restart_read(tport, tty);
817 if (status) 833 if (status)
818 dev_err(&port->dev, "%s - cannot restart read, %d\n", __func__, status); 834 dev_err(&port->dev, "%s - cannot restart read, %d\n",
835 __func__, status);
819 } 836 }
820} 837}
821 838
822 839
823static int ti_ioctl(struct usb_serial_port *port, struct file *file, 840static int ti_ioctl(struct tty_struct *tty, struct file *file,
824 unsigned int cmd, unsigned long arg) 841 unsigned int cmd, unsigned long arg)
825{ 842{
843 struct usb_serial_port *port = tty->driver_data;
826 struct ti_port *tport = usb_get_serial_port_data(port); 844 struct ti_port *tport = usb_get_serial_port_data(port);
827 struct async_icount cnow; 845 struct async_icount cnow;
828 struct async_icount cprev; 846 struct async_icount cprev;
@@ -833,55 +851,52 @@ static int ti_ioctl(struct usb_serial_port *port, struct file *file,
833 return -ENODEV; 851 return -ENODEV;
834 852
835 switch (cmd) { 853 switch (cmd) {
836 case TIOCGSERIAL: 854 case TIOCGSERIAL:
837 dbg("%s - (%d) TIOCGSERIAL", __func__, port->number); 855 dbg("%s - (%d) TIOCGSERIAL", __func__, port->number);
838 return ti_get_serial_info(tport, (struct serial_struct __user *)arg); 856 return ti_get_serial_info(tport,
839 break; 857 (struct serial_struct __user *)arg);
840 858 case TIOCSSERIAL:
841 case TIOCSSERIAL: 859 dbg("%s - (%d) TIOCSSERIAL", __func__, port->number);
842 dbg("%s - (%d) TIOCSSERIAL", __func__, port->number); 860 return ti_set_serial_info(tport,
843 return ti_set_serial_info(tport, (struct serial_struct __user *)arg); 861 (struct serial_struct __user *)arg);
844 break; 862 case TIOCMIWAIT:
845 863 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number);
846 case TIOCMIWAIT: 864 cprev = tport->tp_icount;
847 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number); 865 while (1) {
848 cprev = tport->tp_icount; 866 interruptible_sleep_on(&tport->tp_msr_wait);
849 while (1) { 867 if (signal_pending(current))
850 interruptible_sleep_on(&tport->tp_msr_wait); 868 return -ERESTARTSYS;
851 if (signal_pending(current)) 869 cnow = tport->tp_icount;
852 return -ERESTARTSYS; 870 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
853 cnow = tport->tp_icount; 871 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
854 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 872 return -EIO; /* no change => error */
855 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) 873 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
856 return -EIO; /* no change => error */ 874 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
857 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || 875 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
858 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || 876 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)))
859 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || 877 return 0;
860 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) { 878 cprev = cnow;
861 return 0; 879 }
862 } 880 break;
863 cprev = cnow; 881 case TIOCGICOUNT:
864 } 882 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d",
865 break; 883 __func__, port->number,
866 884 tport->tp_icount.rx, tport->tp_icount.tx);
867 case TIOCGICOUNT: 885 if (copy_to_user((void __user *)arg, &tport->tp_icount,
868 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, port->number, tport->tp_icount.rx, tport->tp_icount.tx); 886 sizeof(tport->tp_icount)))
869 if (copy_to_user((void __user *)arg, &tport->tp_icount, sizeof(tport->tp_icount))) 887 return -EFAULT;
870 return -EFAULT; 888 return 0;
871 return 0;
872 } 889 }
873
874 return -ENOIOCTLCMD; 890 return -ENOIOCTLCMD;
875} 891}
876 892
877 893
878static void ti_set_termios(struct usb_serial_port *port, 894static void ti_set_termios(struct tty_struct *tty,
879 struct ktermios *old_termios) 895 struct usb_serial_port *port, struct ktermios *old_termios)
880{ 896{
881 struct ti_port *tport = usb_get_serial_port_data(port); 897 struct ti_port *tport = usb_get_serial_port_data(port);
882 struct tty_struct *tty = port->tty;
883 struct ti_uart_config *config; 898 struct ti_uart_config *config;
884 tcflag_t cflag,iflag; 899 tcflag_t cflag, iflag;
885 int baud; 900 int baud;
886 int status; 901 int status;
887 int port_number = port->number - port->serial->minor; 902 int port_number = port->number - port->serial->minor;
@@ -893,7 +908,8 @@ static void ti_set_termios(struct usb_serial_port *port,
893 iflag = tty->termios->c_iflag; 908 iflag = tty->termios->c_iflag;
894 909
895 dbg("%s - cflag %08x, iflag %08x", __func__, cflag, iflag); 910 dbg("%s - cflag %08x, iflag %08x", __func__, cflag, iflag);
896 dbg("%s - old clfag %08x, old iflag %08x", __func__, old_termios->c_cflag, old_termios->c_iflag); 911 dbg("%s - old clfag %08x, old iflag %08x", __func__,
912 old_termios->c_cflag, old_termios->c_iflag);
897 913
898 if (tport == NULL) 914 if (tport == NULL)
899 return; 915 return;
@@ -912,19 +928,19 @@ static void ti_set_termios(struct usb_serial_port *port,
912 config->bUartMode = (__u8)(tport->tp_uart_mode); 928 config->bUartMode = (__u8)(tport->tp_uart_mode);
913 929
914 switch (cflag & CSIZE) { 930 switch (cflag & CSIZE) {
915 case CS5: 931 case CS5:
916 config->bDataBits = TI_UART_5_DATA_BITS; 932 config->bDataBits = TI_UART_5_DATA_BITS;
917 break; 933 break;
918 case CS6: 934 case CS6:
919 config->bDataBits = TI_UART_6_DATA_BITS; 935 config->bDataBits = TI_UART_6_DATA_BITS;
920 break; 936 break;
921 case CS7: 937 case CS7:
922 config->bDataBits = TI_UART_7_DATA_BITS; 938 config->bDataBits = TI_UART_7_DATA_BITS;
923 break; 939 break;
924 default: 940 default:
925 case CS8: 941 case CS8:
926 config->bDataBits = TI_UART_8_DATA_BITS; 942 config->bDataBits = TI_UART_8_DATA_BITS;
927 break; 943 break;
928 } 944 }
929 945
930 /* CMSPAR isn't supported by this driver */ 946 /* CMSPAR isn't supported by this driver */
@@ -940,7 +956,7 @@ static void ti_set_termios(struct usb_serial_port *port,
940 } 956 }
941 } else { 957 } else {
942 config->wFlags &= ~TI_UART_ENABLE_PARITY_CHECKING; 958 config->wFlags &= ~TI_UART_ENABLE_PARITY_CHECKING;
943 config->bParity = TI_UART_NO_PARITY; 959 config->bParity = TI_UART_NO_PARITY;
944 } 960 }
945 961
946 if (cflag & CSTOPB) 962 if (cflag & CSTOPB)
@@ -993,7 +1009,8 @@ static void ti_set_termios(struct usb_serial_port *port,
993 (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config, 1009 (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config,
994 sizeof(*config)); 1010 sizeof(*config));
995 if (status) 1011 if (status)
996 dev_err(&port->dev, "%s - cannot set config on port %d, %d\n", __func__, port_number, status); 1012 dev_err(&port->dev, "%s - cannot set config on port %d, %d\n",
1013 __func__, port_number, status);
997 1014
998 /* SET_CONFIG asserts RTS and DTR, reset them correctly */ 1015 /* SET_CONFIG asserts RTS and DTR, reset them correctly */
999 mcr = tport->tp_shadow_mcr; 1016 mcr = tport->tp_shadow_mcr;
@@ -1002,14 +1019,17 @@ static void ti_set_termios(struct usb_serial_port *port,
1002 mcr &= ~(TI_MCR_DTR | TI_MCR_RTS); 1019 mcr &= ~(TI_MCR_DTR | TI_MCR_RTS);
1003 status = ti_set_mcr(tport, mcr); 1020 status = ti_set_mcr(tport, mcr);
1004 if (status) 1021 if (status)
1005 dev_err(&port->dev, "%s - cannot set modem control on port %d, %d\n", __func__, port_number, status); 1022 dev_err(&port->dev,
1023 "%s - cannot set modem control on port %d, %d\n",
1024 __func__, port_number, status);
1006 1025
1007 kfree(config); 1026 kfree(config);
1008} 1027}
1009 1028
1010 1029
1011static int ti_tiocmget(struct usb_serial_port *port, struct file *file) 1030static int ti_tiocmget(struct tty_struct *tty, struct file *file)
1012{ 1031{
1032 struct usb_serial_port *port = tty->driver_data;
1013 struct ti_port *tport = usb_get_serial_port_data(port); 1033 struct ti_port *tport = usb_get_serial_port_data(port);
1014 unsigned int result; 1034 unsigned int result;
1015 unsigned int msr; 1035 unsigned int msr;
@@ -1040,9 +1060,10 @@ static int ti_tiocmget(struct usb_serial_port *port, struct file *file)
1040} 1060}
1041 1061
1042 1062
1043static int ti_tiocmset(struct usb_serial_port *port, struct file *file, 1063static int ti_tiocmset(struct tty_struct *tty, struct file *file,
1044 unsigned int set, unsigned int clear) 1064 unsigned int set, unsigned int clear)
1045{ 1065{
1066 struct usb_serial_port *port = tty->driver_data;
1046 struct ti_port *tport = usb_get_serial_port_data(port); 1067 struct ti_port *tport = usb_get_serial_port_data(port);
1047 unsigned int mcr; 1068 unsigned int mcr;
1048 unsigned long flags; 1069 unsigned long flags;
@@ -1074,8 +1095,9 @@ static int ti_tiocmset(struct usb_serial_port *port, struct file *file,
1074} 1095}
1075 1096
1076 1097
1077static void ti_break(struct usb_serial_port *port, int break_state) 1098static void ti_break(struct tty_struct *tty, int break_state)
1078{ 1099{
1100 struct usb_serial_port *port = tty->driver_data;
1079 struct ti_port *tport = usb_get_serial_port_data(port); 1101 struct ti_port *tport = usb_get_serial_port_data(port);
1080 int status; 1102 int status;
1081 1103
@@ -1141,10 +1163,12 @@ static void ti_interrupt_callback(struct urb *urb)
1141 port_number = TI_GET_PORT_FROM_CODE(data[0]); 1163 port_number = TI_GET_PORT_FROM_CODE(data[0]);
1142 function = TI_GET_FUNC_FROM_CODE(data[0]); 1164 function = TI_GET_FUNC_FROM_CODE(data[0]);
1143 1165
1144 dbg("%s - port_number %d, function %d, data 0x%02X", __func__, port_number, function, data[1]); 1166 dbg("%s - port_number %d, function %d, data 0x%02X",
1167 __func__, port_number, function, data[1]);
1145 1168
1146 if (port_number >= serial->num_ports) { 1169 if (port_number >= serial->num_ports) {
1147 dev_err(dev, "%s - bad port number, %d\n", __func__, port_number); 1170 dev_err(dev, "%s - bad port number, %d\n",
1171 __func__, port_number);
1148 goto exit; 1172 goto exit;
1149 } 1173 }
1150 1174
@@ -1156,7 +1180,8 @@ static void ti_interrupt_callback(struct urb *urb)
1156 1180
1157 switch (function) { 1181 switch (function) {
1158 case TI_CODE_DATA_ERROR: 1182 case TI_CODE_DATA_ERROR:
1159 dev_err(dev, "%s - DATA ERROR, port %d, data 0x%02X\n", __func__, port_number, data[1]); 1183 dev_err(dev, "%s - DATA ERROR, port %d, data 0x%02X\n",
1184 __func__, port_number, data[1]);
1160 break; 1185 break;
1161 1186
1162 case TI_CODE_MODEM_STATUS: 1187 case TI_CODE_MODEM_STATUS:
@@ -1166,7 +1191,8 @@ static void ti_interrupt_callback(struct urb *urb)
1166 break; 1191 break;
1167 1192
1168 default: 1193 default:
1169 dev_err(dev, "%s - unknown interrupt code, 0x%02X\n", __func__, data[1]); 1194 dev_err(dev, "%s - unknown interrupt code, 0x%02X\n",
1195 __func__, data[1]);
1170 break; 1196 break;
1171 } 1197 }
1172 1198
@@ -1200,7 +1226,7 @@ static void ti_bulk_in_callback(struct urb *urb)
1200 return; 1226 return;
1201 default: 1227 default:
1202 dev_err(dev, "%s - nonzero urb status, %d\n", 1228 dev_err(dev, "%s - nonzero urb status, %d\n",
1203 __func__, status ); 1229 __func__, status);
1204 tport->tp_tdev->td_urb_error = 1; 1230 tport->tp_tdev->td_urb_error = 1;
1205 wake_up_interruptible(&tport->tp_write_wait); 1231 wake_up_interruptible(&tport->tp_write_wait);
1206 } 1232 }
@@ -1213,15 +1239,16 @@ static void ti_bulk_in_callback(struct urb *urb)
1213 return; 1239 return;
1214 } 1240 }
1215 1241
1216 if (port->tty && urb->actual_length) { 1242 if (port->port.tty && urb->actual_length) {
1217 usb_serial_debug_data(debug, dev, __func__, 1243 usb_serial_debug_data(debug, dev, __func__,
1218 urb->actual_length, urb->transfer_buffer); 1244 urb->actual_length, urb->transfer_buffer);
1219 1245
1220 if (!tport->tp_is_open) 1246 if (!tport->tp_is_open)
1221 dbg("%s - port closed, dropping data", __func__); 1247 dbg("%s - port closed, dropping data", __func__);
1222 else 1248 else
1223 ti_recv(&urb->dev->dev, port->tty, urb->transfer_buffer, 1249 ti_recv(&urb->dev->dev, port->port.tty,
1224 urb->actual_length); 1250 urb->transfer_buffer,
1251 urb->actual_length);
1225 1252
1226 spin_lock(&tport->tp_lock); 1253 spin_lock(&tport->tp_lock);
1227 tport->tp_icount.rx += urb->actual_length; 1254 tport->tp_icount.rx += urb->actual_length;
@@ -1285,8 +1312,9 @@ static void ti_recv(struct device *dev, struct tty_struct *tty,
1285 do { 1312 do {
1286 cnt = tty_buffer_request_room(tty, length); 1313 cnt = tty_buffer_request_room(tty, length);
1287 if (cnt < length) { 1314 if (cnt < length) {
1288 dev_err(dev, "%s - dropping data, %d bytes lost\n", __func__, length - cnt); 1315 dev_err(dev, "%s - dropping data, %d bytes lost\n",
1289 if(cnt == 0) 1316 __func__, length - cnt);
1317 if (cnt == 0)
1290 break; 1318 break;
1291 } 1319 }
1292 tty_insert_flip_string(tty, data, cnt); 1320 tty_insert_flip_string(tty, data, cnt);
@@ -1302,7 +1330,7 @@ static void ti_send(struct ti_port *tport)
1302{ 1330{
1303 int count, result; 1331 int count, result;
1304 struct usb_serial_port *port = tport->tp_port; 1332 struct usb_serial_port *port = tport->tp_port;
1305 struct tty_struct *tty = port->tty; 1333 struct tty_struct *tty = port->port.tty; /* FIXME */
1306 unsigned long flags; 1334 unsigned long flags;
1307 1335
1308 1336
@@ -1328,7 +1356,8 @@ static void ti_send(struct ti_port *tport)
1328 1356
1329 spin_unlock_irqrestore(&tport->tp_lock, flags); 1357 spin_unlock_irqrestore(&tport->tp_lock, flags);
1330 1358
1331 usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer); 1359 usb_serial_debug_data(debug, &port->dev, __func__, count,
1360 port->write_urb->transfer_buffer);
1332 1361
1333 usb_fill_bulk_urb(port->write_urb, port->serial->dev, 1362 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
1334 usb_sndbulkpipe(port->serial->dev, 1363 usb_sndbulkpipe(port->serial->dev,
@@ -1338,8 +1367,9 @@ static void ti_send(struct ti_port *tport)
1338 1367
1339 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 1368 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1340 if (result) { 1369 if (result) {
1341 dev_err(&port->dev, "%s - submit write urb failed, %d\n", __func__, result); 1370 dev_err(&port->dev, "%s - submit write urb failed, %d\n",
1342 tport->tp_write_urb_in_use = 0; 1371 __func__, result);
1372 tport->tp_write_urb_in_use = 0;
1343 /* TODO: reschedule ti_send */ 1373 /* TODO: reschedule ti_send */
1344 } else { 1374 } else {
1345 spin_lock_irqsave(&tport->tp_lock, flags); 1375 spin_lock_irqsave(&tport->tp_lock, flags);
@@ -1374,7 +1404,7 @@ static int ti_set_mcr(struct ti_port *tport, unsigned int mcr)
1374 1404
1375static int ti_get_lsr(struct ti_port *tport) 1405static int ti_get_lsr(struct ti_port *tport)
1376{ 1406{
1377 int size,status; 1407 int size, status;
1378 struct ti_device *tdev = tport->tp_tdev; 1408 struct ti_device *tdev = tport->tp_tdev;
1379 struct usb_serial_port *port = tport->tp_port; 1409 struct usb_serial_port *port = tport->tp_port;
1380 int port_number = port->number - port->serial->minor; 1410 int port_number = port->number - port->serial->minor;
@@ -1392,7 +1422,9 @@ static int ti_get_lsr(struct ti_port *tport)
1392 status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS, 1422 status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS,
1393 (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size); 1423 (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size);
1394 if (status) { 1424 if (status) {
1395 dev_err(&port->dev, "%s - get port status command failed, %d\n", __func__, status); 1425 dev_err(&port->dev,
1426 "%s - get port status command failed, %d\n",
1427 __func__, status);
1396 goto free_data; 1428 goto free_data;
1397 } 1429 }
1398 1430
@@ -1442,8 +1474,9 @@ static int ti_set_serial_info(struct ti_port *tport,
1442 return -EFAULT; 1474 return -EFAULT;
1443 1475
1444 tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS; 1476 tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS;
1445 if (port->tty) 1477 /* FIXME */
1446 port->tty->low_latency = 1478 if (port->port.tty)
1479 port->port.tty->low_latency =
1447 (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1480 (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1448 tport->tp_closing_wait = new_serial.closing_wait; 1481 tport->tp_closing_wait = new_serial.closing_wait;
1449 1482
@@ -1477,7 +1510,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1477 tport->tp_msr = msr & TI_MSR_MASK; 1510 tport->tp_msr = msr & TI_MSR_MASK;
1478 1511
1479 /* handle CTS flow control */ 1512 /* handle CTS flow control */
1480 tty = tport->tp_port->tty; 1513 tty = tport->tp_port->port.tty;
1481 if (tty && C_CRTSCTS(tty)) { 1514 if (tty && C_CRTSCTS(tty)) {
1482 if (msr & TI_MSR_CTS) { 1515 if (msr & TI_MSR_CTS) {
1483 tty->hw_stopped = 0; 1516 tty->hw_stopped = 0;
@@ -1627,7 +1660,8 @@ static int ti_write_byte(struct ti_device *tdev, unsigned long addr,
1627 struct ti_write_data_bytes *data; 1660 struct ti_write_data_bytes *data;
1628 struct device *dev = &tdev->td_serial->dev->dev; 1661 struct device *dev = &tdev->td_serial->dev->dev;
1629 1662
1630 dbg("%s - addr 0x%08lX, mask 0x%02X, byte 0x%02X", __func__, addr, mask, byte); 1663 dbg("%s - addr 0x%08lX, mask 0x%02X, byte 0x%02X",
1664 __func__, addr, mask, byte);
1631 1665
1632 size = sizeof(struct ti_write_data_bytes) + 2; 1666 size = sizeof(struct ti_write_data_bytes) + 2;
1633 data = kmalloc(size, GFP_KERNEL); 1667 data = kmalloc(size, GFP_KERNEL);
@@ -1655,67 +1689,68 @@ static int ti_write_byte(struct ti_device *tdev, unsigned long addr,
1655 return status; 1689 return status;
1656} 1690}
1657 1691
1658 1692static int ti_do_download(struct usb_device *dev, int pipe,
1659static int ti_download_firmware(struct ti_device *tdev, 1693 u8 *buffer, int size)
1660 char *fw_name)
1661{ 1694{
1662 const struct firmware *fw;
1663 int status = 0;
1664 int buffer_size;
1665 int pos; 1695 int pos;
1666 int len; 1696 u8 cs = 0;
1667 int done; 1697 int done;
1668 __u8 cs = 0;
1669 __u8 *buffer;
1670 struct usb_device *dev = tdev->td_serial->dev;
1671 struct ti_firmware_header *header; 1698 struct ti_firmware_header *header;
1672 unsigned int pipe = usb_sndbulkpipe(dev, 1699 int status;
1673 tdev->td_serial->port[0]->bulk_out_endpointAddress); 1700 int len;
1674
1675 buffer_size = TI_FIRMWARE_BUF_SIZE + sizeof(struct ti_firmware_header);
1676
1677 if (request_firmware(&fw, fw_name, &dev->dev)) {
1678 dev_err(&dev->dev, "%s - failed to load firmware \"%s\"\n",
1679 __func__, fw_name);
1680 return -ENOENT;
1681 }
1682 if (fw->size > buffer_size) {
1683 dev_err(&dev->dev, "%s - firmware \"%s\" is too large\n",
1684 __func__, fw_name);
1685 release_firmware(fw);
1686 return -EINVAL;
1687 }
1688
1689 buffer = kmalloc(buffer_size, GFP_KERNEL);
1690 if (!buffer) {
1691 dev_err(&dev->dev, "%s - out of memory\n", __func__);
1692 release_firmware(fw);
1693 return -ENOMEM;
1694 }
1695
1696 memcpy(buffer, fw->data, fw->size);
1697 memset(buffer+fw->size, 0xff, buffer_size-fw->size);
1698 1701
1699 for(pos = sizeof(struct ti_firmware_header); pos < buffer_size; pos++) 1702 for (pos = sizeof(struct ti_firmware_header); pos < size; pos++)
1700 cs = (__u8)(cs + buffer[pos]); 1703 cs = (__u8)(cs + buffer[pos]);
1701 1704
1702 header = (struct ti_firmware_header *)buffer; 1705 header = (struct ti_firmware_header *)buffer;
1703 header->wLength = cpu_to_le16((__u16)(buffer_size - sizeof(struct ti_firmware_header))); 1706 header->wLength = cpu_to_le16((__u16)(size
1707 - sizeof(struct ti_firmware_header)));
1704 header->bCheckSum = cs; 1708 header->bCheckSum = cs;
1705 1709
1706 dbg("%s - downloading firmware", __func__); 1710 dbg("%s - downloading firmware", __func__);
1707 for (pos = 0; pos < buffer_size; pos += done) { 1711 for (pos = 0; pos < size; pos += done) {
1708 len = min(buffer_size - pos, TI_DOWNLOAD_MAX_PACKET_SIZE); 1712 len = min(size - pos, TI_DOWNLOAD_MAX_PACKET_SIZE);
1709 status = usb_bulk_msg(dev, pipe, buffer+pos, len, &done, 1000); 1713 status = usb_bulk_msg(dev, pipe, buffer + pos, len,
1714 &done, 1000);
1710 if (status) 1715 if (status)
1711 break; 1716 break;
1712 } 1717 }
1718 return status;
1719}
1713 1720
1714 kfree(buffer); 1721static int ti_download_firmware(struct ti_device *tdev, int type)
1715 release_firmware(fw); 1722{
1723 int status = -ENOMEM;
1724 int buffer_size;
1725 __u8 *buffer;
1726 struct usb_device *dev = tdev->td_serial->dev;
1727 unsigned int pipe = usb_sndbulkpipe(dev,
1728 tdev->td_serial->port[0]->bulk_out_endpointAddress);
1729 const struct firmware *fw_p;
1730 char buf[32];
1731 sprintf(buf, "ti_usb-%d.bin", type);
1716 1732
1733 if (request_firmware(&fw_p, buf, &dev->dev)) {
1734 dev_err(&dev->dev, "%s - firmware not found\n", __func__);
1735 return -ENOENT;
1736 }
1737 if (fw_p->size > TI_FIRMWARE_BUF_SIZE) {
1738 dev_err(&dev->dev, "%s - firmware too large\n", __func__);
1739 return -ENOENT;
1740 }
1741
1742 buffer_size = TI_FIRMWARE_BUF_SIZE + sizeof(struct ti_firmware_header);
1743 buffer = kmalloc(buffer_size, GFP_KERNEL);
1744 if (buffer) {
1745 memcpy(buffer, fw_p->data, fw_p->size);
1746 memset(buffer + fw_p->size, 0xff, buffer_size - fw_p->size);
1747 ti_do_download(dev, pipe, buffer, fw_p->size);
1748 kfree(buffer);
1749 }
1750 release_firmware(fw_p);
1717 if (status) { 1751 if (status) {
1718 dev_err(&dev->dev, "%s - error downloading firmware, %d\n", __func__, status); 1752 dev_err(&dev->dev, "%s - error downloading firmware, %d\n",
1753 __func__, status);
1719 return status; 1754 return status;
1720 } 1755 }
1721 1756
@@ -1787,7 +1822,7 @@ static void ti_buf_clear(struct circ_buf *cb)
1787 1822
1788static int ti_buf_data_avail(struct circ_buf *cb) 1823static int ti_buf_data_avail(struct circ_buf *cb)
1789{ 1824{
1790 return CIRC_CNT(cb->head,cb->tail,TI_WRITE_BUF_SIZE); 1825 return CIRC_CNT(cb->head, cb->tail, TI_WRITE_BUF_SIZE);
1791} 1826}
1792 1827
1793 1828
@@ -1800,7 +1835,7 @@ static int ti_buf_data_avail(struct circ_buf *cb)
1800 1835
1801static int ti_buf_space_avail(struct circ_buf *cb) 1836static int ti_buf_space_avail(struct circ_buf *cb)
1802{ 1837{
1803 return CIRC_SPACE(cb->head,cb->tail,TI_WRITE_BUF_SIZE); 1838 return CIRC_SPACE(cb->head, cb->tail, TI_WRITE_BUF_SIZE);
1804} 1839}
1805 1840
1806 1841
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 0cb0d77dc429..8c2d531eedea 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -12,7 +12,8 @@
12 * This driver was originally based on the ACM driver by Armin Fuerst (which was 12 * This driver was originally based on the ACM driver by Armin Fuerst (which was
13 * based on a driver by Brad Keryan) 13 * based on a driver by Brad Keryan)
14 * 14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver 15 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver
16 * 17 *
17 */ 18 */
18 19
@@ -28,7 +29,7 @@
28#include <linux/spinlock.h> 29#include <linux/spinlock.h>
29#include <linux/mutex.h> 30#include <linux/mutex.h>
30#include <linux/list.h> 31#include <linux/list.h>
31#include <asm/uaccess.h> 32#include <linux/uaccess.h>
32#include <linux/usb.h> 33#include <linux/usb.h>
33#include <linux/usb/serial.h> 34#include <linux/usb/serial.h>
34#include "pl2303.h" 35#include "pl2303.h"
@@ -59,7 +60,8 @@ static struct usb_driver usb_serial_driver = {
59*/ 60*/
60 61
61static int debug; 62static int debug;
62static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */ 63/* initially all NULL */
64static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
63static DEFINE_MUTEX(table_lock); 65static DEFINE_MUTEX(table_lock);
64static LIST_HEAD(usb_serial_driver_list); 66static LIST_HEAD(usb_serial_driver_list);
65 67
@@ -76,7 +78,8 @@ struct usb_serial *usb_serial_get_by_index(unsigned index)
76 return serial; 78 return serial;
77} 79}
78 80
79static struct usb_serial *get_free_serial (struct usb_serial *serial, int num_ports, unsigned int *minor) 81static struct usb_serial *get_free_serial(struct usb_serial *serial,
82 int num_ports, unsigned int *minor)
80{ 83{
81 unsigned int i, j; 84 unsigned int i, j;
82 int good_spot; 85 int good_spot;
@@ -122,9 +125,8 @@ static void return_serial(struct usb_serial *serial)
122 if (serial == NULL) 125 if (serial == NULL)
123 return; 126 return;
124 127
125 for (i = 0; i < serial->num_ports; ++i) { 128 for (i = 0; i < serial->num_ports; ++i)
126 serial_table[serial->minor + i] = NULL; 129 serial_table[serial->minor + i] = NULL;
127 }
128} 130}
129 131
130static void destroy_serial(struct kref *kref) 132static void destroy_serial(struct kref *kref)
@@ -143,7 +145,7 @@ static void destroy_serial(struct kref *kref)
143 return_serial(serial); 145 return_serial(serial);
144 146
145 for (i = 0; i < serial->num_ports; ++i) 147 for (i = 0; i < serial->num_ports; ++i)
146 serial->port[i]->open_count = 0; 148 serial->port[i]->port.count = 0;
147 149
148 /* the ports are cleaned up and released in port_release() */ 150 /* the ports are cleaned up and released in port_release() */
149 for (i = 0; i < serial->num_ports; ++i) 151 for (i = 0; i < serial->num_ports; ++i)
@@ -156,7 +158,8 @@ static void destroy_serial(struct kref *kref)
156 * not get cleaned up in port_release() as it was never registered with 158 * not get cleaned up in port_release() as it was never registered with
157 * the driver core */ 159 * the driver core */
158 if (serial->num_ports < serial->num_port_pointers) { 160 if (serial->num_ports < serial->num_port_pointers) {
159 for (i = serial->num_ports; i < serial->num_port_pointers; ++i) { 161 for (i = serial->num_ports;
162 i < serial->num_port_pointers; ++i) {
160 port = serial->port[i]; 163 port = serial->port[i];
161 if (!port) 164 if (!port)
162 continue; 165 continue;
@@ -167,7 +170,7 @@ static void destroy_serial(struct kref *kref)
167 usb_put_dev(serial->dev); 170 usb_put_dev(serial->dev);
168 171
169 /* free up any memory that we allocated */ 172 /* free up any memory that we allocated */
170 kfree (serial); 173 kfree(serial);
171} 174}
172 175
173void usb_serial_put(struct usb_serial *serial) 176void usb_serial_put(struct usb_serial *serial)
@@ -180,13 +183,13 @@ void usb_serial_put(struct usb_serial *serial)
180/***************************************************************************** 183/*****************************************************************************
181 * Driver tty interface functions 184 * Driver tty interface functions
182 *****************************************************************************/ 185 *****************************************************************************/
183static int serial_open (struct tty_struct *tty, struct file * filp) 186static int serial_open (struct tty_struct *tty, struct file *filp)
184{ 187{
185 struct usb_serial *serial; 188 struct usb_serial *serial;
186 struct usb_serial_port *port; 189 struct usb_serial_port *port;
187 unsigned int portNumber; 190 unsigned int portNumber;
188 int retval; 191 int retval;
189 192
190 dbg("%s", __func__); 193 dbg("%s", __func__);
191 194
192 /* get the serial object associated with this tty pointer */ 195 /* get the serial object associated with this tty pointer */
@@ -207,15 +210,15 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
207 retval = -ERESTARTSYS; 210 retval = -ERESTARTSYS;
208 goto bailout_kref_put; 211 goto bailout_kref_put;
209 } 212 }
210 213
211 ++port->open_count; 214 ++port->port.count;
212 215
213 /* set up our port structure making the tty driver 216 /* set up our port structure making the tty driver
214 * remember our port object, and us it */ 217 * remember our port object, and us it */
215 tty->driver_data = port; 218 tty->driver_data = port;
216 port->tty = tty; 219 port->port.tty = tty;
217 220
218 if (port->open_count == 1) { 221 if (port->port.count == 1) {
219 222
220 /* lock this module before we call it 223 /* lock this module before we call it
221 * this may fail, which means we must bail out, 224 * this may fail, which means we must bail out,
@@ -228,9 +231,9 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
228 retval = usb_autopm_get_interface(serial->interface); 231 retval = usb_autopm_get_interface(serial->interface);
229 if (retval) 232 if (retval)
230 goto bailout_module_put; 233 goto bailout_module_put;
231 /* only call the device specific open if this 234 /* only call the device specific open if this
232 * is the first time the port is opened */ 235 * is the first time the port is opened */
233 retval = serial->type->open(port, filp); 236 retval = serial->type->open(tty, port, filp);
234 if (retval) 237 if (retval)
235 goto bailout_interface_put; 238 goto bailout_interface_put;
236 } 239 }
@@ -243,16 +246,16 @@ bailout_interface_put:
243bailout_module_put: 246bailout_module_put:
244 module_put(serial->type->driver.owner); 247 module_put(serial->type->driver.owner);
245bailout_mutex_unlock: 248bailout_mutex_unlock:
246 port->open_count = 0; 249 port->port.count = 0;
247 tty->driver_data = NULL; 250 tty->driver_data = NULL;
248 port->tty = NULL; 251 port->port.tty = NULL;
249 mutex_unlock(&port->mutex); 252 mutex_unlock(&port->mutex);
250bailout_kref_put: 253bailout_kref_put:
251 usb_serial_put(serial); 254 usb_serial_put(serial);
252 return retval; 255 return retval;
253} 256}
254 257
255static void serial_close(struct tty_struct *tty, struct file * filp) 258static void serial_close(struct tty_struct *tty, struct file *filp)
256{ 259{
257 struct usb_serial_port *port = tty->driver_data; 260 struct usb_serial_port *port = tty->driver_data;
258 261
@@ -263,27 +266,30 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
263 266
264 mutex_lock(&port->mutex); 267 mutex_lock(&port->mutex);
265 268
266 if (port->open_count == 0) { 269 if (port->port.count == 0) {
267 mutex_unlock(&port->mutex); 270 mutex_unlock(&port->mutex);
268 return; 271 return;
269 } 272 }
270 273
271 --port->open_count; 274 --port->port.count;
272 if (port->open_count == 0) 275 if (port->port.count == 0)
273 /* only call the device specific close if this 276 /* only call the device specific close if this
274 * port is being closed by the last owner */ 277 * port is being closed by the last owner */
275 port->serial->type->close(port, filp); 278 port->serial->type->close(tty, port, filp);
276 279
277 if (port->open_count == (port->console? 1 : 0)) { 280 if (port->port.count == (port->console? 1 : 0)) {
278 if (port->tty) { 281 if (port->port.tty) {
279 if (port->tty->driver_data) 282 if (port->port.tty->driver_data)
280 port->tty->driver_data = NULL; 283 port->port.tty->driver_data = NULL;
281 port->tty = NULL; 284 port->port.tty = NULL;
282 } 285 }
283 } 286 }
284 287
285 if (port->open_count == 0) { 288 if (port->port.count == 0) {
286 usb_autopm_put_interface(port->serial->interface); 289 mutex_lock(&port->serial->disc_mutex);
290 if (!port->serial->disconnected)
291 usb_autopm_put_interface(port->serial->interface);
292 mutex_unlock(&port->serial->disc_mutex);
287 module_put(port->serial->type->driver.owner); 293 module_put(port->serial->type->driver.owner);
288 } 294 }
289 295
@@ -291,7 +297,8 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
291 usb_serial_put(port->serial); 297 usb_serial_put(port->serial);
292} 298}
293 299
294static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count) 300static int serial_write(struct tty_struct *tty, const unsigned char *buf,
301 int count)
295{ 302{
296 struct usb_serial_port *port = tty->driver_data; 303 struct usb_serial_port *port = tty->driver_data;
297 int retval = -ENODEV; 304 int retval = -ENODEV;
@@ -301,107 +308,112 @@ static int serial_write (struct tty_struct * tty, const unsigned char *buf, int
301 308
302 dbg("%s - port %d, %d byte(s)", __func__, port->number, count); 309 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
303 310
304 /* open_count is managed under the mutex lock for the tty so cannot 311 /* count is managed under the mutex lock for the tty so cannot
305 drop to zero until after the last close completes */ 312 drop to zero until after the last close completes */
306 WARN_ON(!port->open_count); 313 WARN_ON(!port->port.count);
307 314
308 /* pass on to the driver specific version of this function */ 315 /* pass on to the driver specific version of this function */
309 retval = port->serial->type->write(port, buf, count); 316 retval = port->serial->type->write(tty, port, buf, count);
310 317
311exit: 318exit:
312 return retval; 319 return retval;
313} 320}
314 321
315static int serial_write_room (struct tty_struct *tty) 322static int serial_write_room(struct tty_struct *tty)
316{ 323{
317 struct usb_serial_port *port = tty->driver_data; 324 struct usb_serial_port *port = tty->driver_data;
318 dbg("%s - port %d", __func__, port->number); 325 dbg("%s - port %d", __func__, port->number);
319 WARN_ON(!port->open_count); 326 WARN_ON(!port->port.count);
320 /* pass on to the driver specific version of this function */ 327 /* pass on to the driver specific version of this function */
321 return port->serial->type->write_room(port); 328 return port->serial->type->write_room(tty);
322} 329}
323 330
324static int serial_chars_in_buffer (struct tty_struct *tty) 331static int serial_chars_in_buffer(struct tty_struct *tty)
325{ 332{
326 struct usb_serial_port *port = tty->driver_data; 333 struct usb_serial_port *port = tty->driver_data;
327 dbg("%s = port %d", __func__, port->number); 334 dbg("%s = port %d", __func__, port->number);
328 335
329 WARN_ON(!port->open_count); 336 WARN_ON(!port->port.count);
330 /* pass on to the driver specific version of this function */ 337 /* pass on to the driver specific version of this function */
331 return port->serial->type->chars_in_buffer(port); 338 return port->serial->type->chars_in_buffer(tty);
332} 339}
333 340
334static void serial_throttle (struct tty_struct * tty) 341static void serial_throttle(struct tty_struct *tty)
335{ 342{
336 struct usb_serial_port *port = tty->driver_data; 343 struct usb_serial_port *port = tty->driver_data;
337 dbg("%s - port %d", __func__, port->number); 344 dbg("%s - port %d", __func__, port->number);
338 345
339 WARN_ON(!port->open_count); 346 WARN_ON(!port->port.count);
340 /* pass on to the driver specific version of this function */ 347 /* pass on to the driver specific version of this function */
341 if (port->serial->type->throttle) 348 if (port->serial->type->throttle)
342 port->serial->type->throttle(port); 349 port->serial->type->throttle(tty);
343} 350}
344 351
345static void serial_unthrottle (struct tty_struct * tty) 352static void serial_unthrottle(struct tty_struct *tty)
346{ 353{
347 struct usb_serial_port *port = tty->driver_data; 354 struct usb_serial_port *port = tty->driver_data;
348 dbg("%s - port %d", __func__, port->number); 355 dbg("%s - port %d", __func__, port->number);
349 356
350 WARN_ON(!port->open_count); 357 WARN_ON(!port->port.count);
351 /* pass on to the driver specific version of this function */ 358 /* pass on to the driver specific version of this function */
352 if (port->serial->type->unthrottle) 359 if (port->serial->type->unthrottle)
353 port->serial->type->unthrottle(port); 360 port->serial->type->unthrottle(tty);
354} 361}
355 362
356static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) 363static int serial_ioctl(struct tty_struct *tty, struct file *file,
364 unsigned int cmd, unsigned long arg)
357{ 365{
358 struct usb_serial_port *port = tty->driver_data; 366 struct usb_serial_port *port = tty->driver_data;
359 int retval = -ENODEV; 367 int retval = -ENODEV;
360 368
361 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); 369 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
362 370
363 WARN_ON(!port->open_count); 371 WARN_ON(!port->port.count);
364 372
365 /* pass on to the driver specific version of this function if it is available */ 373 /* pass on to the driver specific version of this function
374 if it is available */
366 if (port->serial->type->ioctl) { 375 if (port->serial->type->ioctl) {
367 lock_kernel(); 376 lock_kernel();
368 retval = port->serial->type->ioctl(port, file, cmd, arg); 377 retval = port->serial->type->ioctl(tty, file, cmd, arg);
369 unlock_kernel(); 378 unlock_kernel();
370 } 379 } else
371 else
372 retval = -ENOIOCTLCMD; 380 retval = -ENOIOCTLCMD;
373 return retval; 381 return retval;
374} 382}
375 383
376static void serial_set_termios (struct tty_struct *tty, struct ktermios * old) 384static void serial_set_termios(struct tty_struct *tty, struct ktermios *old)
377{ 385{
378 struct usb_serial_port *port = tty->driver_data; 386 struct usb_serial_port *port = tty->driver_data;
379 dbg("%s - port %d", __func__, port->number); 387 dbg("%s - port %d", __func__, port->number);
380 388
381 WARN_ON(!port->open_count); 389 WARN_ON(!port->port.count);
382 /* pass on to the driver specific version of this function if it is available */ 390 /* pass on to the driver specific version of this function
391 if it is available */
383 if (port->serial->type->set_termios) 392 if (port->serial->type->set_termios)
384 port->serial->type->set_termios(port, old); 393 port->serial->type->set_termios(tty, port, old);
385 else 394 else
386 tty_termios_copy_hw(tty->termios, old); 395 tty_termios_copy_hw(tty->termios, old);
387} 396}
388 397
389static void serial_break (struct tty_struct *tty, int break_state) 398static int serial_break(struct tty_struct *tty, int break_state)
390{ 399{
391 struct usb_serial_port *port = tty->driver_data; 400 struct usb_serial_port *port = tty->driver_data;
392 401
393 dbg("%s - port %d", __func__, port->number); 402 dbg("%s - port %d", __func__, port->number);
394 403
395 WARN_ON(!port->open_count); 404 WARN_ON(!port->port.count);
396 /* pass on to the driver specific version of this function if it is available */ 405 /* pass on to the driver specific version of this function
406 if it is available */
397 if (port->serial->type->break_ctl) { 407 if (port->serial->type->break_ctl) {
398 lock_kernel(); 408 lock_kernel();
399 port->serial->type->break_ctl(port, break_state); 409 port->serial->type->break_ctl(tty, break_state);
400 unlock_kernel(); 410 unlock_kernel();
401 } 411 }
412 return 0;
402} 413}
403 414
404static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data) 415static int serial_read_proc(char *page, char **start, off_t off, int count,
416 int *eof, void *data)
405{ 417{
406 struct usb_serial *serial; 418 struct usb_serial *serial;
407 int length = 0; 419 int length = 0;
@@ -410,26 +422,29 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
410 char tmp[40]; 422 char tmp[40];
411 423
412 dbg("%s", __func__); 424 dbg("%s", __func__);
413 length += sprintf (page, "usbserinfo:1.0 driver:2.0\n"); 425 length += sprintf(page, "usbserinfo:1.0 driver:2.0\n");
414 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) { 426 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
415 serial = usb_serial_get_by_index(i); 427 serial = usb_serial_get_by_index(i);
416 if (serial == NULL) 428 if (serial == NULL)
417 continue; 429 continue;
418 430
419 length += sprintf (page+length, "%d:", i); 431 length += sprintf(page+length, "%d:", i);
420 if (serial->type->driver.owner) 432 if (serial->type->driver.owner)
421 length += sprintf (page+length, " module:%s", module_name(serial->type->driver.owner)); 433 length += sprintf(page+length, " module:%s",
422 length += sprintf (page+length, " name:\"%s\"", serial->type->description); 434 module_name(serial->type->driver.owner));
423 length += sprintf (page+length, " vendor:%04x product:%04x", 435 length += sprintf(page+length, " name:\"%s\"",
424 le16_to_cpu(serial->dev->descriptor.idVendor), 436 serial->type->description);
425 le16_to_cpu(serial->dev->descriptor.idProduct)); 437 length += sprintf(page+length, " vendor:%04x product:%04x",
426 length += sprintf (page+length, " num_ports:%d", serial->num_ports); 438 le16_to_cpu(serial->dev->descriptor.idVendor),
427 length += sprintf (page+length, " port:%d", i - serial->minor + 1); 439 le16_to_cpu(serial->dev->descriptor.idProduct));
428 440 length += sprintf(page+length, " num_ports:%d",
441 serial->num_ports);
442 length += sprintf(page+length, " port:%d",
443 i - serial->minor + 1);
429 usb_make_path(serial->dev, tmp, sizeof(tmp)); 444 usb_make_path(serial->dev, tmp, sizeof(tmp));
430 length += sprintf (page+length, " path:%s", tmp); 445 length += sprintf(page+length, " path:%s", tmp);
431 446
432 length += sprintf (page+length, "\n"); 447 length += sprintf(page+length, "\n");
433 if ((length + begin) > (off + count)) { 448 if ((length + begin) > (off + count)) {
434 usb_serial_put(serial); 449 usb_serial_put(serial);
435 goto done; 450 goto done;
@@ -445,31 +460,31 @@ done:
445 if (off >= (length + begin)) 460 if (off >= (length + begin))
446 return 0; 461 return 0;
447 *start = page + (off-begin); 462 *start = page + (off-begin);
448 return ((count < begin+length-off) ? count : begin+length-off); 463 return (count < begin+length-off) ? count : begin+length-off;
449} 464}
450 465
451static int serial_tiocmget (struct tty_struct *tty, struct file *file) 466static int serial_tiocmget(struct tty_struct *tty, struct file *file)
452{ 467{
453 struct usb_serial_port *port = tty->driver_data; 468 struct usb_serial_port *port = tty->driver_data;
454 469
455 dbg("%s - port %d", __func__, port->number); 470 dbg("%s - port %d", __func__, port->number);
456 471
457 WARN_ON(!port->open_count); 472 WARN_ON(!port->port.count);
458 if (port->serial->type->tiocmget) 473 if (port->serial->type->tiocmget)
459 return port->serial->type->tiocmget(port, file); 474 return port->serial->type->tiocmget(tty, file);
460 return -EINVAL; 475 return -EINVAL;
461} 476}
462 477
463static int serial_tiocmset (struct tty_struct *tty, struct file *file, 478static int serial_tiocmset(struct tty_struct *tty, struct file *file,
464 unsigned int set, unsigned int clear) 479 unsigned int set, unsigned int clear)
465{ 480{
466 struct usb_serial_port *port = tty->driver_data; 481 struct usb_serial_port *port = tty->driver_data;
467 482
468 dbg("%s - port %d", __func__, port->number); 483 dbg("%s - port %d", __func__, port->number);
469 484
470 WARN_ON(!port->open_count); 485 WARN_ON(!port->port.count);
471 if (port->serial->type->tiocmset) 486 if (port->serial->type->tiocmset)
472 return port->serial->type->tiocmset(port, file, set, clear); 487 return port->serial->type->tiocmset(tty, file, set, clear);
473 return -EINVAL; 488 return -EINVAL;
474} 489}
475 490
@@ -482,6 +497,7 @@ void usb_serial_port_softint(struct usb_serial_port *port)
482{ 497{
483 schedule_work(&port->work); 498 schedule_work(&port->work);
484} 499}
500EXPORT_SYMBOL_GPL(usb_serial_port_softint);
485 501
486static void usb_serial_port_work(struct work_struct *work) 502static void usb_serial_port_work(struct work_struct *work)
487{ 503{
@@ -490,11 +506,11 @@ static void usb_serial_port_work(struct work_struct *work)
490 struct tty_struct *tty; 506 struct tty_struct *tty;
491 507
492 dbg("%s - port %d", __func__, port->number); 508 dbg("%s - port %d", __func__, port->number);
493 509
494 if (!port) 510 if (!port)
495 return; 511 return;
496 512
497 tty = port->tty; 513 tty = port->port.tty;
498 if (!tty) 514 if (!tty)
499 return; 515 return;
500 516
@@ -505,7 +521,7 @@ static void port_release(struct device *dev)
505{ 521{
506 struct usb_serial_port *port = to_usb_serial_port(dev); 522 struct usb_serial_port *port = to_usb_serial_port(dev);
507 523
508 dbg ("%s - %s", __func__, dev->bus_id); 524 dbg ("%s - %s", __func__, dev_name(dev));
509 port_free(port); 525 port_free(port);
510} 526}
511 527
@@ -543,9 +559,9 @@ static void port_free(struct usb_serial_port *port)
543 kfree(port); 559 kfree(port);
544} 560}
545 561
546static struct usb_serial * create_serial (struct usb_device *dev, 562static struct usb_serial *create_serial(struct usb_device *dev,
547 struct usb_interface *interface, 563 struct usb_interface *interface,
548 struct usb_serial_driver *driver) 564 struct usb_serial_driver *driver)
549{ 565{
550 struct usb_serial *serial; 566 struct usb_serial *serial;
551 567
@@ -564,7 +580,7 @@ static struct usb_serial * create_serial (struct usb_device *dev,
564} 580}
565 581
566static const struct usb_device_id *match_dynamic_id(struct usb_interface *intf, 582static const struct usb_device_id *match_dynamic_id(struct usb_interface *intf,
567 struct usb_serial_driver *drv) 583 struct usb_serial_driver *drv)
568{ 584{
569 struct usb_dynid *dynid; 585 struct usb_dynid *dynid;
570 586
@@ -596,7 +612,8 @@ exit:
596 return id; 612 return id;
597} 613}
598 614
599static struct usb_serial_driver *search_serial_device(struct usb_interface *iface) 615static struct usb_serial_driver *search_serial_device(
616 struct usb_interface *iface)
600{ 617{
601 const struct usb_device_id *id; 618 const struct usb_device_id *id;
602 struct usb_serial_driver *drv; 619 struct usb_serial_driver *drv;
@@ -614,7 +631,7 @@ static struct usb_serial_driver *search_serial_device(struct usb_interface *ifac
614int usb_serial_probe(struct usb_interface *interface, 631int usb_serial_probe(struct usb_interface *interface,
615 const struct usb_device_id *id) 632 const struct usb_device_id *id)
616{ 633{
617 struct usb_device *dev = interface_to_usbdev (interface); 634 struct usb_device *dev = interface_to_usbdev(interface);
618 struct usb_serial *serial = NULL; 635 struct usb_serial *serial = NULL;
619 struct usb_serial_port *port; 636 struct usb_serial_port *port;
620 struct usb_host_interface *iface_desc; 637 struct usb_host_interface *iface_desc;
@@ -625,7 +642,7 @@ int usb_serial_probe(struct usb_interface *interface,
625 struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS]; 642 struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS];
626 struct usb_serial_driver *type = NULL; 643 struct usb_serial_driver *type = NULL;
627 int retval; 644 int retval;
628 int minor; 645 unsigned int minor;
629 int buffer_size; 646 int buffer_size;
630 int i; 647 int i;
631 int num_interrupt_in = 0; 648 int num_interrupt_in = 0;
@@ -643,7 +660,7 @@ int usb_serial_probe(struct usb_interface *interface,
643 return -ENODEV; 660 return -ENODEV;
644 } 661 }
645 662
646 serial = create_serial (dev, interface, type); 663 serial = create_serial(dev, interface, type);
647 if (!serial) { 664 if (!serial) {
648 unlock_kernel(); 665 unlock_kernel();
649 dev_err(&interface->dev, "%s - out of memory\n", __func__); 666 dev_err(&interface->dev, "%s - out of memory\n", __func__);
@@ -656,8 +673,9 @@ int usb_serial_probe(struct usb_interface *interface,
656 673
657 if (!try_module_get(type->driver.owner)) { 674 if (!try_module_get(type->driver.owner)) {
658 unlock_kernel(); 675 unlock_kernel();
659 dev_err(&interface->dev, "module get failed, exiting\n"); 676 dev_err(&interface->dev,
660 kfree (serial); 677 "module get failed, exiting\n");
678 kfree(serial);
661 return -EIO; 679 return -EIO;
662 } 680 }
663 681
@@ -667,8 +685,8 @@ int usb_serial_probe(struct usb_interface *interface,
667 685
668 if (retval) { 686 if (retval) {
669 unlock_kernel(); 687 unlock_kernel();
670 dbg ("sub driver rejected device"); 688 dbg("sub driver rejected device");
671 kfree (serial); 689 kfree(serial);
672 return retval; 690 return retval;
673 } 691 }
674 } 692 }
@@ -709,7 +727,7 @@ int usb_serial_probe(struct usb_interface *interface,
709 } 727 }
710 728
711#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE) 729#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)
712 /* BEGIN HORRIBLE HACK FOR PL2303 */ 730 /* BEGIN HORRIBLE HACK FOR PL2303 */
713 /* this is needed due to the looney way its endpoints are set up */ 731 /* this is needed due to the looney way its endpoints are set up */
714 if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) && 732 if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) &&
715 (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) || 733 (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) ||
@@ -738,7 +756,7 @@ int usb_serial_probe(struct usb_interface *interface,
738 if (num_bulk_in == 0 || num_bulk_out == 0) { 756 if (num_bulk_in == 0 || num_bulk_out == 0) {
739 unlock_kernel(); 757 unlock_kernel();
740 dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n"); 758 dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n");
741 kfree (serial); 759 kfree(serial);
742 return -ENODEV; 760 return -ENODEV;
743 } 761 }
744 } 762 }
@@ -750,8 +768,9 @@ int usb_serial_probe(struct usb_interface *interface,
750 num_ports = num_bulk_out; 768 num_ports = num_bulk_out;
751 if (num_ports == 0) { 769 if (num_ports == 0) {
752 unlock_kernel(); 770 unlock_kernel();
753 dev_err(&interface->dev, "Generic device with no bulk out, not allowed.\n"); 771 dev_err(&interface->dev,
754 kfree (serial); 772 "Generic device with no bulk out, not allowed.\n");
773 kfree(serial);
755 return -EIO; 774 return -EIO;
756 } 775 }
757 } 776 }
@@ -761,11 +780,12 @@ int usb_serial_probe(struct usb_interface *interface,
761 if (type->calc_num_ports) { 780 if (type->calc_num_ports) {
762 if (!try_module_get(type->driver.owner)) { 781 if (!try_module_get(type->driver.owner)) {
763 unlock_kernel(); 782 unlock_kernel();
764 dev_err(&interface->dev, "module get failed, exiting\n"); 783 dev_err(&interface->dev,
765 kfree (serial); 784 "module get failed, exiting\n");
785 kfree(serial);
766 return -EIO; 786 return -EIO;
767 } 787 }
768 num_ports = type->calc_num_ports (serial); 788 num_ports = type->calc_num_ports(serial);
769 module_put(type->driver.owner); 789 module_put(type->driver.owner);
770 } 790 }
771 if (!num_ports) 791 if (!num_ports)
@@ -783,7 +803,8 @@ int usb_serial_probe(struct usb_interface *interface,
783 type->description); 803 type->description);
784 804
785 /* create our ports, we need as many as the max endpoints */ 805 /* create our ports, we need as many as the max endpoints */
786 /* we don't use num_ports here cauz some devices have more endpoint pairs than ports */ 806 /* we don't use num_ports here because some devices have more
807 endpoint pairs than ports */
787 max_endpoints = max(num_bulk_in, num_bulk_out); 808 max_endpoints = max(num_bulk_in, num_bulk_out);
788 max_endpoints = max(max_endpoints, num_interrupt_in); 809 max_endpoints = max(max_endpoints, num_interrupt_in);
789 max_endpoints = max(max_endpoints, num_interrupt_out); 810 max_endpoints = max(max_endpoints, num_interrupt_out);
@@ -791,7 +812,8 @@ int usb_serial_probe(struct usb_interface *interface,
791 serial->num_port_pointers = max_endpoints; 812 serial->num_port_pointers = max_endpoints;
792 unlock_kernel(); 813 unlock_kernel();
793 814
794 dbg("%s - setting up %d port structures for this device", __func__, max_endpoints); 815 dbg("%s - setting up %d port structures for this device",
816 __func__, max_endpoints);
795 for (i = 0; i < max_endpoints; ++i) { 817 for (i = 0; i < max_endpoints; ++i) {
796 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL); 818 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL);
797 if (!port) 819 if (!port)
@@ -807,7 +829,7 @@ int usb_serial_probe(struct usb_interface *interface,
807 for (i = 0; i < num_bulk_in; ++i) { 829 for (i = 0; i < num_bulk_in; ++i) {
808 endpoint = bulk_in_endpoint[i]; 830 endpoint = bulk_in_endpoint[i];
809 port = serial->port[i]; 831 port = serial->port[i];
810 port->read_urb = usb_alloc_urb (0, GFP_KERNEL); 832 port->read_urb = usb_alloc_urb(0, GFP_KERNEL);
811 if (!port->read_urb) { 833 if (!port->read_urb) {
812 dev_err(&interface->dev, "No free urbs available\n"); 834 dev_err(&interface->dev, "No free urbs available\n");
813 goto probe_error; 835 goto probe_error;
@@ -815,17 +837,17 @@ int usb_serial_probe(struct usb_interface *interface,
815 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 837 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
816 port->bulk_in_size = buffer_size; 838 port->bulk_in_size = buffer_size;
817 port->bulk_in_endpointAddress = endpoint->bEndpointAddress; 839 port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
818 port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL); 840 port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
819 if (!port->bulk_in_buffer) { 841 if (!port->bulk_in_buffer) {
820 dev_err(&interface->dev, "Couldn't allocate bulk_in_buffer\n"); 842 dev_err(&interface->dev,
843 "Couldn't allocate bulk_in_buffer\n");
821 goto probe_error; 844 goto probe_error;
822 } 845 }
823 usb_fill_bulk_urb (port->read_urb, dev, 846 usb_fill_bulk_urb(port->read_urb, dev,
824 usb_rcvbulkpipe (dev, 847 usb_rcvbulkpipe(dev,
825 endpoint->bEndpointAddress), 848 endpoint->bEndpointAddress),
826 port->bulk_in_buffer, buffer_size, 849 port->bulk_in_buffer, buffer_size,
827 serial->type->read_bulk_callback, 850 serial->type->read_bulk_callback, port);
828 port);
829 } 851 }
830 852
831 for (i = 0; i < num_bulk_out; ++i) { 853 for (i = 0; i < num_bulk_out; ++i) {
@@ -839,17 +861,17 @@ int usb_serial_probe(struct usb_interface *interface,
839 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 861 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
840 port->bulk_out_size = buffer_size; 862 port->bulk_out_size = buffer_size;
841 port->bulk_out_endpointAddress = endpoint->bEndpointAddress; 863 port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
842 port->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL); 864 port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
843 if (!port->bulk_out_buffer) { 865 if (!port->bulk_out_buffer) {
844 dev_err(&interface->dev, "Couldn't allocate bulk_out_buffer\n"); 866 dev_err(&interface->dev,
867 "Couldn't allocate bulk_out_buffer\n");
845 goto probe_error; 868 goto probe_error;
846 } 869 }
847 usb_fill_bulk_urb (port->write_urb, dev, 870 usb_fill_bulk_urb(port->write_urb, dev,
848 usb_sndbulkpipe (dev, 871 usb_sndbulkpipe(dev,
849 endpoint->bEndpointAddress), 872 endpoint->bEndpointAddress),
850 port->bulk_out_buffer, buffer_size, 873 port->bulk_out_buffer, buffer_size,
851 serial->type->write_bulk_callback, 874 serial->type->write_bulk_callback, port);
852 port);
853 } 875 }
854 876
855 if (serial->type->read_int_callback) { 877 if (serial->type->read_int_callback) {
@@ -858,73 +880,82 @@ int usb_serial_probe(struct usb_interface *interface,
858 port = serial->port[i]; 880 port = serial->port[i];
859 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 881 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
860 if (!port->interrupt_in_urb) { 882 if (!port->interrupt_in_urb) {
861 dev_err(&interface->dev, "No free urbs available\n"); 883 dev_err(&interface->dev,
884 "No free urbs available\n");
862 goto probe_error; 885 goto probe_error;
863 } 886 }
864 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 887 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
865 port->interrupt_in_endpointAddress = endpoint->bEndpointAddress; 888 port->interrupt_in_endpointAddress =
866 port->interrupt_in_buffer = kmalloc (buffer_size, GFP_KERNEL); 889 endpoint->bEndpointAddress;
890 port->interrupt_in_buffer = kmalloc(buffer_size,
891 GFP_KERNEL);
867 if (!port->interrupt_in_buffer) { 892 if (!port->interrupt_in_buffer) {
868 dev_err(&interface->dev, "Couldn't allocate interrupt_in_buffer\n"); 893 dev_err(&interface->dev,
894 "Couldn't allocate interrupt_in_buffer\n");
869 goto probe_error; 895 goto probe_error;
870 } 896 }
871 usb_fill_int_urb (port->interrupt_in_urb, dev, 897 usb_fill_int_urb(port->interrupt_in_urb, dev,
872 usb_rcvintpipe (dev, 898 usb_rcvintpipe(dev,
873 endpoint->bEndpointAddress), 899 endpoint->bEndpointAddress),
874 port->interrupt_in_buffer, buffer_size, 900 port->interrupt_in_buffer, buffer_size,
875 serial->type->read_int_callback, port, 901 serial->type->read_int_callback, port,
876 endpoint->bInterval); 902 endpoint->bInterval);
877 } 903 }
878 } else if (num_interrupt_in) { 904 } else if (num_interrupt_in) {
879 dbg("the device claims to support interrupt in transfers, but read_int_callback is not defined"); 905 dbg("the device claims to support interrupt in transfers, but read_int_callback is not defined");
880 } 906 }
881 907
882 if (serial->type->write_int_callback) { 908 if (serial->type->write_int_callback) {
883 for (i = 0; i < num_interrupt_out; ++i) { 909 for (i = 0; i < num_interrupt_out; ++i) {
884 endpoint = interrupt_out_endpoint[i]; 910 endpoint = interrupt_out_endpoint[i];
885 port = serial->port[i]; 911 port = serial->port[i];
886 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 912 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
887 if (!port->interrupt_out_urb) { 913 if (!port->interrupt_out_urb) {
888 dev_err(&interface->dev, "No free urbs available\n"); 914 dev_err(&interface->dev,
915 "No free urbs available\n");
889 goto probe_error; 916 goto probe_error;
890 } 917 }
891 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 918 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
892 port->interrupt_out_size = buffer_size; 919 port->interrupt_out_size = buffer_size;
893 port->interrupt_out_endpointAddress = endpoint->bEndpointAddress; 920 port->interrupt_out_endpointAddress =
894 port->interrupt_out_buffer = kmalloc (buffer_size, GFP_KERNEL); 921 endpoint->bEndpointAddress;
922 port->interrupt_out_buffer = kmalloc(buffer_size,
923 GFP_KERNEL);
895 if (!port->interrupt_out_buffer) { 924 if (!port->interrupt_out_buffer) {
896 dev_err(&interface->dev, "Couldn't allocate interrupt_out_buffer\n"); 925 dev_err(&interface->dev,
926 "Couldn't allocate interrupt_out_buffer\n");
897 goto probe_error; 927 goto probe_error;
898 } 928 }
899 usb_fill_int_urb (port->interrupt_out_urb, dev, 929 usb_fill_int_urb(port->interrupt_out_urb, dev,
900 usb_sndintpipe (dev, 930 usb_sndintpipe(dev,
901 endpoint->bEndpointAddress), 931 endpoint->bEndpointAddress),
902 port->interrupt_out_buffer, buffer_size, 932 port->interrupt_out_buffer, buffer_size,
903 serial->type->write_int_callback, port, 933 serial->type->write_int_callback, port,
904 endpoint->bInterval); 934 endpoint->bInterval);
905 } 935 }
906 } else if (num_interrupt_out) { 936 } else if (num_interrupt_out) {
907 dbg("the device claims to support interrupt out transfers, but write_int_callback is not defined"); 937 dbg("the device claims to support interrupt out transfers, but write_int_callback is not defined");
908 } 938 }
909 939
910 /* if this device type has an attach function, call it */ 940 /* if this device type has an attach function, call it */
911 if (type->attach) { 941 if (type->attach) {
912 if (!try_module_get(type->driver.owner)) { 942 if (!try_module_get(type->driver.owner)) {
913 dev_err(&interface->dev, "module get failed, exiting\n"); 943 dev_err(&interface->dev,
944 "module get failed, exiting\n");
914 goto probe_error; 945 goto probe_error;
915 } 946 }
916 retval = type->attach (serial); 947 retval = type->attach(serial);
917 module_put(type->driver.owner); 948 module_put(type->driver.owner);
918 if (retval < 0) 949 if (retval < 0)
919 goto probe_error; 950 goto probe_error;
920 if (retval > 0) { 951 if (retval > 0) {
921 /* quietly accept this device, but don't bind to a serial port 952 /* quietly accept this device, but don't bind to a
922 * as it's about to disappear */ 953 serial port as it's about to disappear */
923 goto exit; 954 goto exit;
924 } 955 }
925 } 956 }
926 957
927 if (get_free_serial (serial, num_ports, &minor) == NULL) { 958 if (get_free_serial(serial, num_ports, &minor) == NULL) {
928 dev_err(&interface->dev, "No more free serial devices\n"); 959 dev_err(&interface->dev, "No more free serial devices\n");
929 goto probe_error; 960 goto probe_error;
930 } 961 }
@@ -938,19 +969,19 @@ int usb_serial_probe(struct usb_interface *interface,
938 port->dev.bus = &usb_serial_bus_type; 969 port->dev.bus = &usb_serial_bus_type;
939 port->dev.release = &port_release; 970 port->dev.release = &port_release;
940 971
941 snprintf (&port->dev.bus_id[0], sizeof(port->dev.bus_id), "ttyUSB%d", port->number); 972 dev_set_name(&port->dev, "ttyUSB%d", port->number);
942 dbg ("%s - registering %s", __func__, port->dev.bus_id); 973 dbg ("%s - registering %s", __func__, dev_name(&port->dev));
943 retval = device_register(&port->dev); 974 retval = device_register(&port->dev);
944 if (retval) 975 if (retval)
945 dev_err(&port->dev, "Error registering port device, " 976 dev_err(&port->dev, "Error registering port device, "
946 "continuing\n"); 977 "continuing\n");
947 } 978 }
948 979
949 usb_serial_console_init (debug, minor); 980 usb_serial_console_init(debug, minor);
950 981
951exit: 982exit:
952 /* success */ 983 /* success */
953 usb_set_intfdata (interface, serial); 984 usb_set_intfdata(interface, serial);
954 return 0; 985 return 0;
955 986
956probe_error: 987probe_error:
@@ -986,29 +1017,30 @@ probe_error:
986 /* free up any memory that we allocated */ 1017 /* free up any memory that we allocated */
987 for (i = 0; i < serial->num_port_pointers; ++i) 1018 for (i = 0; i < serial->num_port_pointers; ++i)
988 kfree(serial->port[i]); 1019 kfree(serial->port[i]);
989 kfree (serial); 1020 kfree(serial);
990 return -EIO; 1021 return -EIO;
991} 1022}
1023EXPORT_SYMBOL_GPL(usb_serial_probe);
992 1024
993void usb_serial_disconnect(struct usb_interface *interface) 1025void usb_serial_disconnect(struct usb_interface *interface)
994{ 1026{
995 int i; 1027 int i;
996 struct usb_serial *serial = usb_get_intfdata (interface); 1028 struct usb_serial *serial = usb_get_intfdata(interface);
997 struct device *dev = &interface->dev; 1029 struct device *dev = &interface->dev;
998 struct usb_serial_port *port; 1030 struct usb_serial_port *port;
999 1031
1000 usb_serial_console_disconnect(serial); 1032 usb_serial_console_disconnect(serial);
1001 dbg ("%s", __func__); 1033 dbg("%s", __func__);
1002 1034
1003 mutex_lock(&serial->disc_mutex); 1035 mutex_lock(&serial->disc_mutex);
1004 usb_set_intfdata (interface, NULL); 1036 usb_set_intfdata(interface, NULL);
1005 /* must set a flag, to signal subdrivers */ 1037 /* must set a flag, to signal subdrivers */
1006 serial->disconnected = 1; 1038 serial->disconnected = 1;
1007 for (i = 0; i < serial->num_ports; ++i) { 1039 for (i = 0; i < serial->num_ports; ++i) {
1008 port = serial->port[i]; 1040 port = serial->port[i];
1009 if (port) { 1041 if (port) {
1010 if (port->tty) 1042 if (port->port.tty)
1011 tty_hangup(port->tty); 1043 tty_hangup(port->port.tty);
1012 kill_traffic(port); 1044 kill_traffic(port);
1013 } 1045 }
1014 } 1046 }
@@ -1018,6 +1050,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
1018 usb_serial_put(serial); 1050 usb_serial_put(serial);
1019 dev_info(dev, "device disconnected\n"); 1051 dev_info(dev, "device disconnected\n");
1020} 1052}
1053EXPORT_SYMBOL_GPL(usb_serial_disconnect);
1021 1054
1022int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) 1055int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1023{ 1056{
@@ -1076,9 +1109,8 @@ static int __init usb_serial_init(void)
1076 return -ENOMEM; 1109 return -ENOMEM;
1077 1110
1078 /* Initialize our global data */ 1111 /* Initialize our global data */
1079 for (i = 0; i < SERIAL_TTY_MINORS; ++i) { 1112 for (i = 0; i < SERIAL_TTY_MINORS; ++i)
1080 serial_table[i] = NULL; 1113 serial_table[i] = NULL;
1081 }
1082 1114
1083 result = bus_register(&usb_serial_bus_type); 1115 result = bus_register(&usb_serial_bus_type);
1084 if (result) { 1116 if (result) {
@@ -1093,9 +1125,11 @@ static int __init usb_serial_init(void)
1093 usb_serial_tty_driver->minor_start = 0; 1125 usb_serial_tty_driver->minor_start = 0;
1094 usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; 1126 usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
1095 usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL; 1127 usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL;
1096 usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 1128 usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW |
1129 TTY_DRIVER_DYNAMIC_DEV;
1097 usb_serial_tty_driver->init_termios = tty_std_termios; 1130 usb_serial_tty_driver->init_termios = tty_std_termios;
1098 usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1131 usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD
1132 | HUPCL | CLOCAL;
1099 usb_serial_tty_driver->init_termios.c_ispeed = 9600; 1133 usb_serial_tty_driver->init_termios.c_ispeed = 9600;
1100 usb_serial_tty_driver->init_termios.c_ospeed = 9600; 1134 usb_serial_tty_driver->init_termios.c_ospeed = 9600;
1101 tty_set_operations(usb_serial_tty_driver, &serial_ops); 1135 tty_set_operations(usb_serial_tty_driver, &serial_ops);
@@ -1133,7 +1167,7 @@ exit_reg_driver:
1133 bus_unregister(&usb_serial_bus_type); 1167 bus_unregister(&usb_serial_bus_type);
1134 1168
1135exit_bus: 1169exit_bus:
1136 err ("%s - returning with error %d", __func__, result); 1170 err("%s - returning with error %d", __func__, result);
1137 put_tty_driver(usb_serial_tty_driver); 1171 put_tty_driver(usb_serial_tty_driver);
1138 return result; 1172 return result;
1139} 1173}
@@ -1160,7 +1194,7 @@ module_exit(usb_serial_exit);
1160 if (!type->function) { \ 1194 if (!type->function) { \
1161 type->function = usb_serial_generic_##function; \ 1195 type->function = usb_serial_generic_##function; \
1162 dbg("Had to override the " #function \ 1196 dbg("Had to override the " #function \
1163 " usb serial operation with the generic one.");\ 1197 " usb serial operation with the generic one.");\
1164 } \ 1198 } \
1165 } while (0) 1199 } while (0)
1166 1200
@@ -1177,8 +1211,9 @@ static void fixup_generic(struct usb_serial_driver *device)
1177 set_to_generic_if_null(device, resume); 1211 set_to_generic_if_null(device, resume);
1178} 1212}
1179 1213
1180int usb_serial_register(struct usb_serial_driver *driver) /* must be called with BKL held */ 1214int usb_serial_register(struct usb_serial_driver *driver)
1181{ 1215{
1216 /* must be called with BKL held */
1182 int retval; 1217 int retval;
1183 1218
1184 fixup_generic(driver); 1219 fixup_generic(driver);
@@ -1191,37 +1226,30 @@ int usb_serial_register(struct usb_serial_driver *driver) /* must be called with
1191 1226
1192 retval = usb_serial_bus_register(driver); 1227 retval = usb_serial_bus_register(driver);
1193 if (retval) { 1228 if (retval) {
1194 err("problem %d when registering driver %s", retval, driver->description); 1229 err("problem %d when registering driver %s",
1230 retval, driver->description);
1195 list_del(&driver->driver_list); 1231 list_del(&driver->driver_list);
1196 } 1232 } else
1197 else 1233 info("USB Serial support registered for %s",
1198 info("USB Serial support registered for %s", driver->description); 1234 driver->description);
1199 1235
1200 return retval; 1236 return retval;
1201} 1237}
1238EXPORT_SYMBOL_GPL(usb_serial_register);
1202 1239
1203 1240
1204void usb_serial_deregister(struct usb_serial_driver *device) /* must be called with BKL held */ 1241void usb_serial_deregister(struct usb_serial_driver *device)
1205{ 1242{
1243 /* must be called with BKL held */
1206 info("USB Serial deregistering driver %s", device->description); 1244 info("USB Serial deregistering driver %s", device->description);
1207 list_del(&device->driver_list); 1245 list_del(&device->driver_list);
1208 usb_serial_bus_deregister(device); 1246 usb_serial_bus_deregister(device);
1209} 1247}
1210
1211
1212
1213/* If the usb-serial core is built into the core, the usb-serial drivers
1214 need these symbols to load properly as modules. */
1215EXPORT_SYMBOL_GPL(usb_serial_register);
1216EXPORT_SYMBOL_GPL(usb_serial_deregister); 1248EXPORT_SYMBOL_GPL(usb_serial_deregister);
1217EXPORT_SYMBOL_GPL(usb_serial_probe);
1218EXPORT_SYMBOL_GPL(usb_serial_disconnect);
1219EXPORT_SYMBOL_GPL(usb_serial_port_softint);
1220
1221 1249
1222/* Module information */ 1250/* Module information */
1223MODULE_AUTHOR( DRIVER_AUTHOR ); 1251MODULE_AUTHOR(DRIVER_AUTHOR);
1224MODULE_DESCRIPTION( DRIVER_DESC ); 1252MODULE_DESCRIPTION(DRIVER_DESC);
1225MODULE_LICENSE("GPL"); 1253MODULE_LICENSE("GPL");
1226 1254
1227module_param(debug, bool, S_IRUGO | S_IWUSR); 1255module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/usb_debug.c b/drivers/usb/serial/usb_debug.c
index f9fc926b56d8..fc5d9952b03b 100644
--- a/drivers/usb/serial/usb_debug.c
+++ b/drivers/usb/serial/usb_debug.c
@@ -15,6 +15,8 @@
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/usb/serial.h> 16#include <linux/usb/serial.h>
17 17
18#define USB_DEBUG_MAX_PACKET_SIZE 8
19
18static struct usb_device_id id_table [] = { 20static struct usb_device_id id_table [] = {
19 { USB_DEVICE(0x0525, 0x127a) }, 21 { USB_DEVICE(0x0525, 0x127a) },
20 { }, 22 { },
@@ -29,6 +31,13 @@ static struct usb_driver debug_driver = {
29 .no_dynamic_id = 1, 31 .no_dynamic_id = 1,
30}; 32};
31 33
34int usb_debug_open(struct tty_struct *tty, struct usb_serial_port *port,
35 struct file *filp)
36{
37 port->bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE;
38 return usb_serial_generic_open(tty, port, filp);
39}
40
32static struct usb_serial_driver debug_device = { 41static struct usb_serial_driver debug_device = {
33 .driver = { 42 .driver = {
34 .owner = THIS_MODULE, 43 .owner = THIS_MODULE,
@@ -36,6 +45,7 @@ static struct usb_serial_driver debug_device = {
36 }, 45 },
37 .id_table = id_table, 46 .id_table = id_table,
38 .num_ports = 1, 47 .num_ports = 1,
48 .open = usb_debug_open,
39}; 49};
40 50
41static int __init debug_init(void) 51static int __init debug_init(void)
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 5fc20122145f..cf8924f9a2cc 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -9,7 +9,8 @@
9 * modify it under the terms of the GNU General Public License version 9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation. 10 * 2 as published by the Free Software Foundation.
11 * 11 *
12 * See Documentation/usb/usb-serial.txt for more information on using this driver 12 * See Documentation/usb/usb-serial.txt for more information on using this
13 * driver
13 * 14 *
14 */ 15 */
15 16
@@ -23,7 +24,7 @@
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
25#include <linux/spinlock.h> 26#include <linux/spinlock.h>
26#include <asm/uaccess.h> 27#include <linux/uaccess.h>
27#include <linux/usb.h> 28#include <linux/usb.h>
28#include <linux/usb/serial.h> 29#include <linux/usb/serial.h>
29#include "visor.h" 30#include "visor.h"
@@ -35,25 +36,29 @@
35#define DRIVER_DESC "USB HandSpring Visor / Palm OS driver" 36#define DRIVER_DESC "USB HandSpring Visor / Palm OS driver"
36 37
37/* function prototypes for a handspring visor */ 38/* function prototypes for a handspring visor */
38static int visor_open (struct usb_serial_port *port, struct file *filp); 39static int visor_open(struct tty_struct *tty, struct usb_serial_port *port,
39static void visor_close (struct usb_serial_port *port, struct file *filp); 40 struct file *filp);
40static int visor_write (struct usb_serial_port *port, const unsigned char *buf, int count); 41static void visor_close(struct tty_struct *tty, struct usb_serial_port *port,
41static int visor_write_room (struct usb_serial_port *port); 42 struct file *filp);
42static int visor_chars_in_buffer (struct usb_serial_port *port); 43static int visor_write(struct tty_struct *tty, struct usb_serial_port *port,
43static void visor_throttle (struct usb_serial_port *port); 44 const unsigned char *buf, int count);
44static void visor_unthrottle (struct usb_serial_port *port); 45static int visor_write_room(struct tty_struct *tty);
45static int visor_probe (struct usb_serial *serial, const struct usb_device_id *id); 46static void visor_throttle(struct tty_struct *tty);
47static void visor_unthrottle(struct tty_struct *tty);
48static int visor_probe(struct usb_serial *serial,
49 const struct usb_device_id *id);
46static int visor_calc_num_ports(struct usb_serial *serial); 50static int visor_calc_num_ports(struct usb_serial *serial);
47static void visor_shutdown (struct usb_serial *serial); 51static void visor_shutdown(struct usb_serial *serial);
48static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 52static void visor_write_bulk_callback(struct urb *urb);
49static void visor_write_bulk_callback (struct urb *urb); 53static void visor_read_bulk_callback(struct urb *urb);
50static void visor_read_bulk_callback (struct urb *urb); 54static void visor_read_int_callback(struct urb *urb);
51static void visor_read_int_callback (struct urb *urb); 55static int clie_3_5_startup(struct usb_serial *serial);
52static int clie_3_5_startup (struct usb_serial *serial); 56static int treo_attach(struct usb_serial *serial);
53static int treo_attach (struct usb_serial *serial); 57static int clie_5_attach(struct usb_serial *serial);
54static int clie_5_attach (struct usb_serial *serial); 58static int palm_os_3_probe(struct usb_serial *serial,
55static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_id *id); 59 const struct usb_device_id *id);
56static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_id *id); 60static int palm_os_4_probe(struct usb_serial *serial,
61 const struct usb_device_id *id);
57 62
58/* Parameters that may be passed into the module. */ 63/* Parameters that may be passed into the module. */
59static int debug; 64static int debug;
@@ -105,13 +110,13 @@ static struct usb_device_id id_table [] = {
105 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 110 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
106 { USB_DEVICE(ACER_VENDOR_ID, ACER_S10_ID), 111 { USB_DEVICE(ACER_VENDOR_ID, ACER_S10_ID),
107 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 112 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
108 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID), 113 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID),
109 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 114 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
110 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID), 115 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID),
111 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 116 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
112 { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID), 117 { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID),
113 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 118 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
114 { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID), 119 { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID),
115 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 120 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
116 { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID), 121 { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID),
117 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 122 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
@@ -170,7 +175,7 @@ static struct usb_device_id id_table_combined [] = {
170 { } /* Terminating entry */ 175 { } /* Terminating entry */
171}; 176};
172 177
173MODULE_DEVICE_TABLE (usb, id_table_combined); 178MODULE_DEVICE_TABLE(usb, id_table_combined);
174 179
175static struct usb_driver visor_driver = { 180static struct usb_driver visor_driver = {
176 .name = "visor", 181 .name = "visor",
@@ -180,7 +185,8 @@ static struct usb_driver visor_driver = {
180 .no_dynamic_id = 1, 185 .no_dynamic_id = 1,
181}; 186};
182 187
183/* All of the device info needed for the Handspring Visor, and Palm 4.0 devices */ 188/* All of the device info needed for the Handspring Visor,
189 and Palm 4.0 devices */
184static struct usb_serial_driver handspring_device = { 190static struct usb_serial_driver handspring_device = {
185 .driver = { 191 .driver = {
186 .owner = THIS_MODULE, 192 .owner = THIS_MODULE,
@@ -198,10 +204,8 @@ static struct usb_serial_driver handspring_device = {
198 .probe = visor_probe, 204 .probe = visor_probe,
199 .calc_num_ports = visor_calc_num_ports, 205 .calc_num_ports = visor_calc_num_ports,
200 .shutdown = visor_shutdown, 206 .shutdown = visor_shutdown,
201 .ioctl = visor_ioctl,
202 .write = visor_write, 207 .write = visor_write,
203 .write_room = visor_write_room, 208 .write_room = visor_write_room,
204 .chars_in_buffer = visor_chars_in_buffer,
205 .write_bulk_callback = visor_write_bulk_callback, 209 .write_bulk_callback = visor_write_bulk_callback,
206 .read_bulk_callback = visor_read_bulk_callback, 210 .read_bulk_callback = visor_read_bulk_callback,
207 .read_int_callback = visor_read_int_callback, 211 .read_int_callback = visor_read_int_callback,
@@ -225,10 +229,8 @@ static struct usb_serial_driver clie_5_device = {
225 .probe = visor_probe, 229 .probe = visor_probe,
226 .calc_num_ports = visor_calc_num_ports, 230 .calc_num_ports = visor_calc_num_ports,
227 .shutdown = visor_shutdown, 231 .shutdown = visor_shutdown,
228 .ioctl = visor_ioctl,
229 .write = visor_write, 232 .write = visor_write,
230 .write_room = visor_write_room, 233 .write_room = visor_write_room,
231 .chars_in_buffer = visor_chars_in_buffer,
232 .write_bulk_callback = visor_write_bulk_callback, 234 .write_bulk_callback = visor_write_bulk_callback,
233 .read_bulk_callback = visor_read_bulk_callback, 235 .read_bulk_callback = visor_read_bulk_callback,
234 .read_int_callback = visor_read_int_callback, 236 .read_int_callback = visor_read_int_callback,
@@ -249,10 +251,8 @@ static struct usb_serial_driver clie_3_5_device = {
249 .throttle = visor_throttle, 251 .throttle = visor_throttle,
250 .unthrottle = visor_unthrottle, 252 .unthrottle = visor_unthrottle,
251 .attach = clie_3_5_startup, 253 .attach = clie_3_5_startup,
252 .ioctl = visor_ioctl,
253 .write = visor_write, 254 .write = visor_write,
254 .write_room = visor_write_room, 255 .write_room = visor_write_room,
255 .chars_in_buffer = visor_chars_in_buffer,
256 .write_bulk_callback = visor_write_bulk_callback, 256 .write_bulk_callback = visor_write_bulk_callback,
257 .read_bulk_callback = visor_read_bulk_callback, 257 .read_bulk_callback = visor_read_bulk_callback,
258}; 258};
@@ -274,7 +274,8 @@ static int stats;
274/****************************************************************************** 274/******************************************************************************
275 * Handspring Visor specific driver functions 275 * Handspring Visor specific driver functions
276 ******************************************************************************/ 276 ******************************************************************************/
277static int visor_open (struct usb_serial_port *port, struct file *filp) 277static int visor_open(struct tty_struct *tty, struct usb_serial_port *port,
278 struct file *filp)
278{ 279{
279 struct usb_serial *serial = port->serial; 280 struct usb_serial *serial = port->serial;
280 struct visor_private *priv = usb_get_serial_port_data(port); 281 struct visor_private *priv = usb_get_serial_port_data(port);
@@ -300,42 +301,45 @@ static int visor_open (struct usb_serial_port *port, struct file *filp)
300 * through, otherwise it is scheduled, and with high data rates (like 301 * through, otherwise it is scheduled, and with high data rates (like
301 * with OHCI) data can get lost. 302 * with OHCI) data can get lost.
302 */ 303 */
303 if (port->tty) 304 if (tty)
304 port->tty->low_latency = 1; 305 tty->low_latency = 1;
305 306
306 /* Start reading from the device */ 307 /* Start reading from the device */
307 usb_fill_bulk_urb (port->read_urb, serial->dev, 308 usb_fill_bulk_urb(port->read_urb, serial->dev,
308 usb_rcvbulkpipe (serial->dev, 309 usb_rcvbulkpipe(serial->dev,
309 port->bulk_in_endpointAddress), 310 port->bulk_in_endpointAddress),
310 port->read_urb->transfer_buffer, 311 port->read_urb->transfer_buffer,
311 port->read_urb->transfer_buffer_length, 312 port->read_urb->transfer_buffer_length,
312 visor_read_bulk_callback, port); 313 visor_read_bulk_callback, port);
313 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 314 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
314 if (result) { 315 if (result) {
315 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", 316 dev_err(&port->dev,
316 __func__, result); 317 "%s - failed submitting read urb, error %d\n",
318 __func__, result);
317 goto exit; 319 goto exit;
318 } 320 }
319 321
320 if (port->interrupt_in_urb) { 322 if (port->interrupt_in_urb) {
321 dbg("%s - adding interrupt input for treo", __func__); 323 dbg("%s - adding interrupt input for treo", __func__);
322 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 324 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
323 if (result) 325 if (result)
324 dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n", 326 dev_err(&port->dev,
325 __func__, result); 327 "%s - failed submitting interrupt urb, error %d\n",
328 __func__, result);
326 } 329 }
327exit: 330exit:
328 return result; 331 return result;
329} 332}
330 333
331 334
332static void visor_close (struct usb_serial_port *port, struct file * filp) 335static void visor_close(struct tty_struct *tty,
336 struct usb_serial_port *port, struct file *filp)
333{ 337{
334 struct visor_private *priv = usb_get_serial_port_data(port); 338 struct visor_private *priv = usb_get_serial_port_data(port);
335 unsigned char *transfer_buffer; 339 unsigned char *transfer_buffer;
336 340
337 dbg("%s - port %d", __func__, port->number); 341 dbg("%s - port %d", __func__, port->number);
338 342
339 /* shutdown our urbs */ 343 /* shutdown our urbs */
340 usb_kill_urb(port->read_urb); 344 usb_kill_urb(port->read_urb);
341 usb_kill_urb(port->interrupt_in_urb); 345 usb_kill_urb(port->interrupt_in_urb);
@@ -343,14 +347,14 @@ static void visor_close (struct usb_serial_port *port, struct file * filp)
343 mutex_lock(&port->serial->disc_mutex); 347 mutex_lock(&port->serial->disc_mutex);
344 if (!port->serial->disconnected) { 348 if (!port->serial->disconnected) {
345 /* Try to send shutdown message, unless the device is gone */ 349 /* Try to send shutdown message, unless the device is gone */
346 transfer_buffer = kmalloc (0x12, GFP_KERNEL); 350 transfer_buffer = kmalloc(0x12, GFP_KERNEL);
347 if (transfer_buffer) { 351 if (transfer_buffer) {
348 usb_control_msg (port->serial->dev, 352 usb_control_msg(port->serial->dev,
349 usb_rcvctrlpipe(port->serial->dev, 0), 353 usb_rcvctrlpipe(port->serial->dev, 0),
350 VISOR_CLOSE_NOTIFICATION, 0xc2, 354 VISOR_CLOSE_NOTIFICATION, 0xc2,
351 0x0000, 0x0000, 355 0x0000, 0x0000,
352 transfer_buffer, 0x12, 300); 356 transfer_buffer, 0x12, 300);
353 kfree (transfer_buffer); 357 kfree(transfer_buffer);
354 } 358 }
355 } 359 }
356 mutex_unlock(&port->serial->disc_mutex); 360 mutex_unlock(&port->serial->disc_mutex);
@@ -361,7 +365,8 @@ static void visor_close (struct usb_serial_port *port, struct file * filp)
361} 365}
362 366
363 367
364static int visor_write (struct usb_serial_port *port, const unsigned char *buf, int count) 368static int visor_write(struct tty_struct *tty, struct usb_serial_port *port,
369 const unsigned char *buf, int count)
365{ 370{
366 struct visor_private *priv = usb_get_serial_port_data(port); 371 struct visor_private *priv = usb_get_serial_port_data(port);
367 struct usb_serial *serial = port->serial; 372 struct usb_serial *serial = port->serial;
@@ -381,7 +386,7 @@ static int visor_write (struct usb_serial_port *port, const unsigned char *buf,
381 priv->outstanding_urbs++; 386 priv->outstanding_urbs++;
382 spin_unlock_irqrestore(&priv->lock, flags); 387 spin_unlock_irqrestore(&priv->lock, flags);
383 388
384 buffer = kmalloc (count, GFP_ATOMIC); 389 buffer = kmalloc(count, GFP_ATOMIC);
385 if (!buffer) { 390 if (!buffer) {
386 dev_err(&port->dev, "out of memory\n"); 391 dev_err(&port->dev, "out of memory\n");
387 count = -ENOMEM; 392 count = -ENOMEM;
@@ -395,21 +400,22 @@ static int visor_write (struct usb_serial_port *port, const unsigned char *buf,
395 goto error_no_urb; 400 goto error_no_urb;
396 } 401 }
397 402
398 memcpy (buffer, buf, count); 403 memcpy(buffer, buf, count);
399 404
400 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); 405 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
401 406
402 usb_fill_bulk_urb (urb, serial->dev, 407 usb_fill_bulk_urb(urb, serial->dev,
403 usb_sndbulkpipe (serial->dev, 408 usb_sndbulkpipe(serial->dev,
404 port->bulk_out_endpointAddress), 409 port->bulk_out_endpointAddress),
405 buffer, count, 410 buffer, count,
406 visor_write_bulk_callback, port); 411 visor_write_bulk_callback, port);
407 412
408 /* send it down the pipe */ 413 /* send it down the pipe */
409 status = usb_submit_urb(urb, GFP_ATOMIC); 414 status = usb_submit_urb(urb, GFP_ATOMIC);
410 if (status) { 415 if (status) {
411 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", 416 dev_err(&port->dev,
412 __func__, status); 417 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
418 __func__, status);
413 count = status; 419 count = status;
414 goto error; 420 goto error;
415 } else { 421 } else {
@@ -435,8 +441,9 @@ error_no_buffer:
435} 441}
436 442
437 443
438static int visor_write_room (struct usb_serial_port *port) 444static int visor_write_room(struct tty_struct *tty)
439{ 445{
446 struct usb_serial_port *port = tty->driver_data;
440 struct visor_private *priv = usb_get_serial_port_data(port); 447 struct visor_private *priv = usb_get_serial_port_data(port);
441 unsigned long flags; 448 unsigned long flags;
442 449
@@ -460,23 +467,7 @@ static int visor_write_room (struct usb_serial_port *port)
460} 467}
461 468
462 469
463static int visor_chars_in_buffer (struct usb_serial_port *port) 470static void visor_write_bulk_callback(struct urb *urb)
464{
465 dbg("%s - port %d", __func__, port->number);
466
467 /*
468 * We can't really account for how much data we
469 * have sent out, but hasn't made it through to the
470 * device, so just tell the tty layer that everything
471 * is flushed.
472 *
473 * FIXME: Should walk outstanding_urbs
474 */
475 return 0;
476}
477
478
479static void visor_write_bulk_callback (struct urb *urb)
480{ 471{
481 struct usb_serial_port *port = urb->context; 472 struct usb_serial_port *port = urb->context;
482 struct visor_private *priv = usb_get_serial_port_data(port); 473 struct visor_private *priv = usb_get_serial_port_data(port);
@@ -484,7 +475,7 @@ static void visor_write_bulk_callback (struct urb *urb)
484 unsigned long flags; 475 unsigned long flags;
485 476
486 /* free up the transfer buffer, as usb_free_urb() does not do this */ 477 /* free up the transfer buffer, as usb_free_urb() does not do this */
487 kfree (urb->transfer_buffer); 478 kfree(urb->transfer_buffer);
488 479
489 dbg("%s - port %d", __func__, port->number); 480 dbg("%s - port %d", __func__, port->number);
490 481
@@ -500,7 +491,7 @@ static void visor_write_bulk_callback (struct urb *urb)
500} 491}
501 492
502 493
503static void visor_read_bulk_callback (struct urb *urb) 494static void visor_read_bulk_callback(struct urb *urb)
504{ 495{
505 struct usb_serial_port *port = urb->context; 496 struct usb_serial_port *port = urb->context;
506 struct visor_private *priv = usb_get_serial_port_data(port); 497 struct visor_private *priv = usb_get_serial_port_data(port);
@@ -518,11 +509,13 @@ static void visor_read_bulk_callback (struct urb *urb)
518 return; 509 return;
519 } 510 }
520 511
521 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 512 usb_serial_debug_data(debug, &port->dev, __func__,
513 urb->actual_length, data);
522 514
523 tty = port->tty; 515 tty = port->port.tty;
524 if (tty && urb->actual_length) { 516 if (tty && urb->actual_length) {
525 available_room = tty_buffer_request_room(tty, urb->actual_length); 517 available_room = tty_buffer_request_room(tty,
518 urb->actual_length);
526 if (available_room) { 519 if (available_room) {
527 tty_insert_flip_string(tty, data, available_room); 520 tty_insert_flip_string(tty, data, available_room);
528 tty_flip_buffer_push(tty); 521 tty_flip_buffer_push(tty);
@@ -536,22 +529,23 @@ static void visor_read_bulk_callback (struct urb *urb)
536 529
537 /* Continue trying to always read if we should */ 530 /* Continue trying to always read if we should */
538 if (!priv->throttled) { 531 if (!priv->throttled) {
539 usb_fill_bulk_urb (port->read_urb, port->serial->dev, 532 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
540 usb_rcvbulkpipe(port->serial->dev, 533 usb_rcvbulkpipe(port->serial->dev,
541 port->bulk_in_endpointAddress), 534 port->bulk_in_endpointAddress),
542 port->read_urb->transfer_buffer, 535 port->read_urb->transfer_buffer,
543 port->read_urb->transfer_buffer_length, 536 port->read_urb->transfer_buffer_length,
544 visor_read_bulk_callback, port); 537 visor_read_bulk_callback, port);
545 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 538 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
546 if (result) 539 if (result)
547 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 540 dev_err(&port->dev,
548 } else { 541 "%s - failed resubmitting read urb, error %d\n",
542 __func__, result);
543 } else
549 priv->actually_throttled = 1; 544 priv->actually_throttled = 1;
550 }
551 spin_unlock(&priv->lock); 545 spin_unlock(&priv->lock);
552} 546}
553 547
554static void visor_read_int_callback (struct urb *urb) 548static void visor_read_int_callback(struct urb *urb)
555{ 549{
556 struct usb_serial_port *port = urb->context; 550 struct usb_serial_port *port = urb->context;
557 int status = urb->status; 551 int status = urb->status;
@@ -585,14 +579,16 @@ static void visor_read_int_callback (struct urb *urb)
585 urb->actual_length, urb->transfer_buffer); 579 urb->actual_length, urb->transfer_buffer);
586 580
587exit: 581exit:
588 result = usb_submit_urb (urb, GFP_ATOMIC); 582 result = usb_submit_urb(urb, GFP_ATOMIC);
589 if (result) 583 if (result)
590 dev_err(&urb->dev->dev, "%s - Error %d submitting interrupt urb\n", 584 dev_err(&urb->dev->dev,
591 __func__, result); 585 "%s - Error %d submitting interrupt urb\n",
586 __func__, result);
592} 587}
593 588
594static void visor_throttle (struct usb_serial_port *port) 589static void visor_throttle(struct tty_struct *tty)
595{ 590{
591 struct usb_serial_port *port = tty->driver_data;
596 struct visor_private *priv = usb_get_serial_port_data(port); 592 struct visor_private *priv = usb_get_serial_port_data(port);
597 unsigned long flags; 593 unsigned long flags;
598 594
@@ -603,8 +599,9 @@ static void visor_throttle (struct usb_serial_port *port)
603} 599}
604 600
605 601
606static void visor_unthrottle (struct usb_serial_port *port) 602static void visor_unthrottle(struct tty_struct *tty)
607{ 603{
604 struct usb_serial_port *port = tty->driver_data;
608 struct visor_private *priv = usb_get_serial_port_data(port); 605 struct visor_private *priv = usb_get_serial_port_data(port);
609 unsigned long flags; 606 unsigned long flags;
610 int result; 607 int result;
@@ -618,10 +615,13 @@ static void visor_unthrottle (struct usb_serial_port *port)
618 port->read_urb->dev = port->serial->dev; 615 port->read_urb->dev = port->serial->dev;
619 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 616 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
620 if (result) 617 if (result)
621 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 618 dev_err(&port->dev,
619 "%s - failed submitting read urb, error %d\n",
620 __func__, result);
622} 621}
623 622
624static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_id *id) 623static int palm_os_3_probe(struct usb_serial *serial,
624 const struct usb_device_id *id)
625{ 625{
626 struct device *dev = &serial->dev->dev; 626 struct device *dev = &serial->dev->dev;
627 struct visor_connection_info *connection_info; 627 struct visor_connection_info *connection_info;
@@ -633,7 +633,7 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
633 633
634 dbg("%s", __func__); 634 dbg("%s", __func__);
635 635
636 transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL); 636 transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL);
637 if (!transfer_buffer) { 637 if (!transfer_buffer) {
638 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__, 638 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__,
639 sizeof(*connection_info)); 639 sizeof(*connection_info));
@@ -641,7 +641,7 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
641 } 641 }
642 642
643 /* send a get connection info request */ 643 /* send a get connection info request */
644 retval = usb_control_msg (serial->dev, 644 retval = usb_control_msg(serial->dev,
645 usb_rcvctrlpipe(serial->dev, 0), 645 usb_rcvctrlpipe(serial->dev, 0),
646 VISOR_GET_CONNECTION_INFORMATION, 646 VISOR_GET_CONNECTION_INFORMATION,
647 0xc2, 0x0000, 0x0000, transfer_buffer, 647 0xc2, 0x0000, 0x0000, transfer_buffer,
@@ -653,29 +653,31 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
653 } 653 }
654 654
655 if (retval == sizeof(*connection_info)) { 655 if (retval == sizeof(*connection_info)) {
656 connection_info = (struct visor_connection_info *)transfer_buffer; 656 connection_info = (struct visor_connection_info *)
657 transfer_buffer;
657 658
658 num_ports = le16_to_cpu(connection_info->num_ports); 659 num_ports = le16_to_cpu(connection_info->num_ports);
659 for (i = 0; i < num_ports; ++i) { 660 for (i = 0; i < num_ports; ++i) {
660 switch (connection_info->connections[i].port_function_id) { 661 switch (
661 case VISOR_FUNCTION_GENERIC: 662 connection_info->connections[i].port_function_id) {
662 string = "Generic"; 663 case VISOR_FUNCTION_GENERIC:
663 break; 664 string = "Generic";
664 case VISOR_FUNCTION_DEBUGGER: 665 break;
665 string = "Debugger"; 666 case VISOR_FUNCTION_DEBUGGER:
666 break; 667 string = "Debugger";
667 case VISOR_FUNCTION_HOTSYNC: 668 break;
668 string = "HotSync"; 669 case VISOR_FUNCTION_HOTSYNC:
669 break; 670 string = "HotSync";
670 case VISOR_FUNCTION_CONSOLE: 671 break;
671 string = "Console"; 672 case VISOR_FUNCTION_CONSOLE:
672 break; 673 string = "Console";
673 case VISOR_FUNCTION_REMOTE_FILE_SYS: 674 break;
674 string = "Remote File System"; 675 case VISOR_FUNCTION_REMOTE_FILE_SYS:
675 break; 676 string = "Remote File System";
676 default: 677 break;
677 string = "unknown"; 678 default:
678 break; 679 string = "unknown";
680 break;
679 } 681 }
680 dev_info(dev, "%s: port %d, is for %s use\n", 682 dev_info(dev, "%s: port %d, is for %s use\n",
681 serial->type->description, 683 serial->type->description,
@@ -686,11 +688,11 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
686 * Handle devices that report invalid stuff here. 688 * Handle devices that report invalid stuff here.
687 */ 689 */
688 if (num_ports == 0 || num_ports > 2) { 690 if (num_ports == 0 || num_ports > 2) {
689 dev_warn (dev, "%s: No valid connect info available\n", 691 dev_warn(dev, "%s: No valid connect info available\n",
690 serial->type->description); 692 serial->type->description);
691 num_ports = 2; 693 num_ports = 2;
692 } 694 }
693 695
694 dev_info(dev, "%s: Number of ports: %d\n", serial->type->description, 696 dev_info(dev, "%s: Number of ports: %d\n", serial->type->description,
695 num_ports); 697 num_ports);
696 698
@@ -700,8 +702,9 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
700 */ 702 */
701 usb_set_serial_data(serial, (void *)(long)num_ports); 703 usb_set_serial_data(serial, (void *)(long)num_ports);
702 704
703 /* ask for the number of bytes available, but ignore the response as it is broken */ 705 /* ask for the number of bytes available, but ignore the
704 retval = usb_control_msg (serial->dev, 706 response as it is broken */
707 retval = usb_control_msg(serial->dev,
705 usb_rcvctrlpipe(serial->dev, 0), 708 usb_rcvctrlpipe(serial->dev, 0),
706 VISOR_REQUEST_BYTES_AVAILABLE, 709 VISOR_REQUEST_BYTES_AVAILABLE,
707 0xc2, 0x0000, 0x0005, transfer_buffer, 710 0xc2, 0x0000, 0x0005, transfer_buffer,
@@ -712,12 +715,13 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
712 retval = 0; 715 retval = 0;
713 716
714exit: 717exit:
715 kfree (transfer_buffer); 718 kfree(transfer_buffer);
716 719
717 return retval; 720 return retval;
718} 721}
719 722
720static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_id *id) 723static int palm_os_4_probe(struct usb_serial *serial,
724 const struct usb_device_id *id)
721{ 725{
722 struct device *dev = &serial->dev->dev; 726 struct device *dev = &serial->dev->dev;
723 struct palm_ext_connection_info *connection_info; 727 struct palm_ext_connection_info *connection_info;
@@ -726,18 +730,18 @@ static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_i
726 730
727 dbg("%s", __func__); 731 dbg("%s", __func__);
728 732
729 transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL); 733 transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL);
730 if (!transfer_buffer) { 734 if (!transfer_buffer) {
731 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__, 735 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__,
732 sizeof(*connection_info)); 736 sizeof(*connection_info));
733 return -ENOMEM; 737 return -ENOMEM;
734 } 738 }
735 739
736 retval = usb_control_msg (serial->dev, 740 retval = usb_control_msg(serial->dev,
737 usb_rcvctrlpipe(serial->dev, 0), 741 usb_rcvctrlpipe(serial->dev, 0),
738 PALM_GET_EXT_CONNECTION_INFORMATION, 742 PALM_GET_EXT_CONNECTION_INFORMATION,
739 0xc2, 0x0000, 0x0000, transfer_buffer, 743 0xc2, 0x0000, 0x0000, transfer_buffer,
740 sizeof (*connection_info), 300); 744 sizeof(*connection_info), 300);
741 if (retval < 0) 745 if (retval < 0)
742 dev_err(dev, "%s - error %d getting connection info\n", 746 dev_err(dev, "%s - error %d getting connection info\n",
743 __func__, retval); 747 __func__, retval);
@@ -745,15 +749,17 @@ static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_i
745 usb_serial_debug_data(debug, &serial->dev->dev, __func__, 749 usb_serial_debug_data(debug, &serial->dev->dev, __func__,
746 retval, transfer_buffer); 750 retval, transfer_buffer);
747 751
748 kfree (transfer_buffer); 752 kfree(transfer_buffer);
749 return 0; 753 return 0;
750} 754}
751 755
752 756
753static int visor_probe (struct usb_serial *serial, const struct usb_device_id *id) 757static int visor_probe(struct usb_serial *serial,
758 const struct usb_device_id *id)
754{ 759{
755 int retval = 0; 760 int retval = 0;
756 int (*startup) (struct usb_serial *serial, const struct usb_device_id *id); 761 int (*startup)(struct usb_serial *serial,
762 const struct usb_device_id *id);
757 763
758 dbg("%s", __func__); 764 dbg("%s", __func__);
759 765
@@ -771,7 +777,7 @@ static int visor_probe (struct usb_serial *serial, const struct usb_device_id *i
771 return retval; 777 return retval;
772} 778}
773 779
774static int visor_calc_num_ports (struct usb_serial *serial) 780static int visor_calc_num_ports(struct usb_serial *serial)
775{ 781{
776 int num_ports = (int)(long)(usb_get_serial_data(serial)); 782 int num_ports = (int)(long)(usb_get_serial_data(serial));
777 783
@@ -788,7 +794,7 @@ static int generic_startup(struct usb_serial *serial)
788 int i; 794 int i;
789 795
790 for (i = 0; i < serial->num_ports; ++i) { 796 for (i = 0; i < serial->num_ports; ++i) {
791 priv = kzalloc (sizeof(*priv), GFP_KERNEL); 797 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
792 if (!priv) { 798 if (!priv) {
793 while (i-- != 0) { 799 while (i-- != 0) {
794 priv = usb_get_serial_port_data(ports[i]); 800 priv = usb_get_serial_port_data(ports[i]);
@@ -803,7 +809,7 @@ static int generic_startup(struct usb_serial *serial)
803 return 0; 809 return 0;
804} 810}
805 811
806static int clie_3_5_startup (struct usb_serial *serial) 812static int clie_3_5_startup(struct usb_serial *serial)
807{ 813{
808 struct device *dev = &serial->dev->dev; 814 struct device *dev = &serial->dev->dev;
809 int result; 815 int result;
@@ -816,62 +822,72 @@ static int clie_3_5_startup (struct usb_serial *serial)
816 */ 822 */
817 823
818 /* get the config number */ 824 /* get the config number */
819 result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), 825 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
820 USB_REQ_GET_CONFIGURATION, USB_DIR_IN, 826 USB_REQ_GET_CONFIGURATION, USB_DIR_IN,
821 0, 0, &data, 1, 3000); 827 0, 0, &data, 1, 3000);
822 if (result < 0) { 828 if (result < 0) {
823 dev_err(dev, "%s: get config number failed: %d\n", __func__, result); 829 dev_err(dev, "%s: get config number failed: %d\n",
830 __func__, result);
824 return result; 831 return result;
825 } 832 }
826 if (result != 1) { 833 if (result != 1) {
827 dev_err(dev, "%s: get config number bad return length: %d\n", __func__, result); 834 dev_err(dev, "%s: get config number bad return length: %d\n",
835 __func__, result);
828 return -EIO; 836 return -EIO;
829 } 837 }
830 838
831 /* get the interface number */ 839 /* get the interface number */
832 result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), 840 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
833 USB_REQ_GET_INTERFACE, 841 USB_REQ_GET_INTERFACE,
834 USB_DIR_IN | USB_RECIP_INTERFACE, 842 USB_DIR_IN | USB_RECIP_INTERFACE,
835 0, 0, &data, 1, 3000); 843 0, 0, &data, 1, 3000);
836 if (result < 0) { 844 if (result < 0) {
837 dev_err(dev, "%s: get interface number failed: %d\n", __func__, result); 845 dev_err(dev, "%s: get interface number failed: %d\n",
846 __func__, result);
838 return result; 847 return result;
839 } 848 }
840 if (result != 1) { 849 if (result != 1) {
841 dev_err(dev, "%s: get interface number bad return length: %d\n", __func__, result); 850 dev_err(dev,
851 "%s: get interface number bad return length: %d\n",
852 __func__, result);
842 return -EIO; 853 return -EIO;
843 } 854 }
844 855
845 return generic_startup(serial); 856 return generic_startup(serial);
846} 857}
847 858
848static int treo_attach (struct usb_serial *serial) 859static int treo_attach(struct usb_serial *serial)
849{ 860{
850 struct usb_serial_port *swap_port; 861 struct usb_serial_port *swap_port;
851 862
852 /* Only do this endpoint hack for the Handspring devices with 863 /* Only do this endpoint hack for the Handspring devices with
853 * interrupt in endpoints, which for now are the Treo devices. */ 864 * interrupt in endpoints, which for now are the Treo devices. */
854 if (!((le16_to_cpu(serial->dev->descriptor.idVendor) == HANDSPRING_VENDOR_ID) || 865 if (!((le16_to_cpu(serial->dev->descriptor.idVendor)
855 (le16_to_cpu(serial->dev->descriptor.idVendor) == KYOCERA_VENDOR_ID)) || 866 == HANDSPRING_VENDOR_ID) ||
856 (serial->num_interrupt_in == 0)) 867 (le16_to_cpu(serial->dev->descriptor.idVendor)
868 == KYOCERA_VENDOR_ID)) ||
869 (serial->num_interrupt_in == 0))
857 goto generic_startup; 870 goto generic_startup;
858 871
859 dbg("%s", __func__); 872 dbg("%s", __func__);
860 873
861 /* 874 /*
862 * It appears that Treos and Kyoceras want to use the 875 * It appears that Treos and Kyoceras want to use the
863 * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint, 876 * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint,
864 * so let's swap the 1st and 2nd bulk in and interrupt endpoints. 877 * so let's swap the 1st and 2nd bulk in and interrupt endpoints.
865 * Note that swapping the bulk out endpoints would break lots of 878 * Note that swapping the bulk out endpoints would break lots of
866 * apps that want to communicate on the second port. 879 * apps that want to communicate on the second port.
867 */ 880 */
868#define COPY_PORT(dest, src) \ 881#define COPY_PORT(dest, src) \
869 dest->read_urb = src->read_urb; \ 882 do { \
870 dest->bulk_in_endpointAddress = src->bulk_in_endpointAddress; \ 883 dest->read_urb = src->read_urb; \
871 dest->bulk_in_buffer = src->bulk_in_buffer; \ 884 dest->bulk_in_endpointAddress = src->bulk_in_endpointAddress;\
872 dest->interrupt_in_urb = src->interrupt_in_urb; \ 885 dest->bulk_in_buffer = src->bulk_in_buffer; \
873 dest->interrupt_in_endpointAddress = src->interrupt_in_endpointAddress; \ 886 dest->interrupt_in_urb = src->interrupt_in_urb; \
874 dest->interrupt_in_buffer = src->interrupt_in_buffer; 887 dest->interrupt_in_endpointAddress = \
888 src->interrupt_in_endpointAddress;\
889 dest->interrupt_in_buffer = src->interrupt_in_buffer; \
890 } while (0);
875 891
876 swap_port = kmalloc(sizeof(*swap_port), GFP_KERNEL); 892 swap_port = kmalloc(sizeof(*swap_port), GFP_KERNEL);
877 if (!swap_port) 893 if (!swap_port)
@@ -885,28 +901,30 @@ generic_startup:
885 return generic_startup(serial); 901 return generic_startup(serial);
886} 902}
887 903
888static int clie_5_attach (struct usb_serial *serial) 904static int clie_5_attach(struct usb_serial *serial)
889{ 905{
890 dbg("%s", __func__); 906 dbg("%s", __func__);
891 907
892 /* TH55 registers 2 ports. 908 /* TH55 registers 2 ports.
893 Communication in from the UX50/TH55 uses bulk_in_endpointAddress from port 0 909 Communication in from the UX50/TH55 uses bulk_in_endpointAddress
894 Communication out to the UX50/TH55 uses bulk_out_endpointAddress from port 1 910 from port 0. Communication out to the UX50/TH55 uses
895 911 bulk_out_endpointAddress from port 1
912
896 Lets do a quick and dirty mapping 913 Lets do a quick and dirty mapping
897 */ 914 */
898 915
899 /* some sanity check */ 916 /* some sanity check */
900 if (serial->num_ports < 2) 917 if (serial->num_ports < 2)
901 return -1; 918 return -1;
902 919
903 /* port 0 now uses the modified endpoint Address */ 920 /* port 0 now uses the modified endpoint Address */
904 serial->port[0]->bulk_out_endpointAddress = serial->port[1]->bulk_out_endpointAddress; 921 serial->port[0]->bulk_out_endpointAddress =
922 serial->port[1]->bulk_out_endpointAddress;
905 923
906 return generic_startup(serial); 924 return generic_startup(serial);
907} 925}
908 926
909static void visor_shutdown (struct usb_serial *serial) 927static void visor_shutdown(struct usb_serial *serial)
910{ 928{
911 struct visor_private *priv; 929 struct visor_private *priv;
912 int i; 930 int i;
@@ -922,37 +940,35 @@ static void visor_shutdown (struct usb_serial *serial)
922 } 940 }
923} 941}
924 942
925static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 943static int __init visor_init(void)
926{
927 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
928
929 return -ENOIOCTLCMD;
930}
931
932static int __init visor_init (void)
933{ 944{
934 int i, retval; 945 int i, retval;
935 /* Only if parameters were passed to us */ 946 /* Only if parameters were passed to us */
936 if ((vendor>0) && (product>0)) { 947 if (vendor > 0 && product > 0) {
937 struct usb_device_id usb_dev_temp[]= 948 struct usb_device_id usb_dev_temp[] = {
938 {{USB_DEVICE(vendor, product), 949 {
939 .driver_info = (kernel_ulong_t)&palm_os_4_probe }}; 950 USB_DEVICE(vendor, product),
951 .driver_info =
952 (kernel_ulong_t) &palm_os_4_probe
953 }
954 };
940 955
941 /* Find the last entry in id_table */ 956 /* Find the last entry in id_table */
942 for (i=0; ; i++) { 957 for (i = 0;; i++) {
943 if (id_table[i].idVendor==0) { 958 if (id_table[i].idVendor == 0) {
944 id_table[i] = usb_dev_temp[0]; 959 id_table[i] = usb_dev_temp[0];
945 break; 960 break;
946 } 961 }
947 } 962 }
948 /* Find the last entry in id_table_combined */ 963 /* Find the last entry in id_table_combined */
949 for (i=0; ; i++) { 964 for (i = 0;; i++) {
950 if (id_table_combined[i].idVendor==0) { 965 if (id_table_combined[i].idVendor == 0) {
951 id_table_combined[i] = usb_dev_temp[0]; 966 id_table_combined[i] = usb_dev_temp[0];
952 break; 967 break;
953 } 968 }
954 } 969 }
955 info("Untested USB device specified at time of module insertion"); 970 info(
971 "Untested USB device specified at time of module insertion");
956 info("Warning: This is not guaranteed to work"); 972 info("Warning: This is not guaranteed to work");
957 info("Using a newer kernel is preferred to this method"); 973 info("Using a newer kernel is preferred to this method");
958 info("Adding Palm OS protocol 4.x support for unknown device: 0x%x/0x%x", 974 info("Adding Palm OS protocol 4.x support for unknown device: 0x%x/0x%x",
@@ -968,7 +984,7 @@ static int __init visor_init (void)
968 if (retval) 984 if (retval)
969 goto failed_clie_5_register; 985 goto failed_clie_5_register;
970 retval = usb_register(&visor_driver); 986 retval = usb_register(&visor_driver);
971 if (retval) 987 if (retval)
972 goto failed_usb_register; 988 goto failed_usb_register;
973 info(DRIVER_DESC); 989 info(DRIVER_DESC);
974 990
@@ -986,18 +1002,18 @@ failed_handspring_register:
986 1002
987static void __exit visor_exit (void) 1003static void __exit visor_exit (void)
988{ 1004{
989 usb_deregister (&visor_driver); 1005 usb_deregister(&visor_driver);
990 usb_serial_deregister (&handspring_device); 1006 usb_serial_deregister(&handspring_device);
991 usb_serial_deregister (&clie_3_5_device); 1007 usb_serial_deregister(&clie_3_5_device);
992 usb_serial_deregister (&clie_5_device); 1008 usb_serial_deregister(&clie_5_device);
993} 1009}
994 1010
995 1011
996module_init(visor_init); 1012module_init(visor_init);
997module_exit(visor_exit); 1013module_exit(visor_exit);
998 1014
999MODULE_AUTHOR( DRIVER_AUTHOR ); 1015MODULE_AUTHOR(DRIVER_AUTHOR);
1000MODULE_DESCRIPTION( DRIVER_DESC ); 1016MODULE_DESCRIPTION(DRIVER_DESC);
1001MODULE_LICENSE("GPL"); 1017MODULE_LICENSE("GPL");
1002 1018
1003module_param(debug, bool, S_IRUGO | S_IWUSR); 1019module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 665aa77a917b..3a9d14384a43 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -12,29 +12,31 @@
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver 15 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver
16 * 17 *
17 * (10/09/2002) Stuart MacDonald (stuartm@connecttech.com) 18 * (10/09/2002) Stuart MacDonald (stuartm@connecttech.com)
18 * Upgrade to full working driver 19 * Upgrade to full working driver
19 * 20 *
20 * (05/30/2001) gkh 21 * (05/30/2001) gkh
21 * switched from using spinlock to a semaphore, which fixes lots of problems. 22 * switched from using spinlock to a semaphore, which fixes lots of
23 * problems.
22 * 24 *
23 * (04/08/2001) gb 25 * (04/08/2001) gb
24 * Identify version on module load. 26 * Identify version on module load.
25 * 27 *
26 * 2001_Mar_19 gkh 28 * 2001_Mar_19 gkh
27 * Fixed MOD_INC and MOD_DEC logic, the ability to open a port more 29 * Fixed MOD_INC and MOD_DEC logic, the ability to open a port more
28 * than once, and the got the proper usb_device_id table entries so 30 * than once, and the got the proper usb_device_id table entries so
29 * the driver works again. 31 * the driver works again.
30 * 32 *
31 * (11/01/2000) Adam J. Richter 33 * (11/01/2000) Adam J. Richter
32 * usb_device_id table support 34 * usb_device_id table support
33 * 35 *
34 * (10/05/2000) gkh 36 * (10/05/2000) gkh
35 * Fixed bug with urb->dev not being set properly, now that the usb 37 * Fixed bug with urb->dev not being set properly, now that the usb
36 * core needs it. 38 * core needs it.
37 * 39 *
38 * (10/03/2000) smd 40 * (10/03/2000) smd
39 * firmware is improved to guard against crap sent to device 41 * firmware is improved to guard against crap sent to device
40 * firmware now replies CMD_FAILURE on bad things 42 * firmware now replies CMD_FAILURE on bad things
@@ -52,9 +54,9 @@
52 * Fixed bug with port->minor that was found by Al Borchers 54 * Fixed bug with port->minor that was found by Al Borchers
53 * 55 *
54 * (07/04/2000) gkh 56 * (07/04/2000) gkh
55 * Added support for port settings. Baud rate can now be changed. Line signals 57 * Added support for port settings. Baud rate can now be changed. Line
56 * are not transferred to and from the tty layer yet, but things seem to be 58 * signals are not transferred to and from the tty layer yet, but things
57 * working well now. 59 * seem to be working well now.
58 * 60 *
59 * (05/04/2000) gkh 61 * (05/04/2000) gkh
60 * First cut at open and close commands. Data can flow through the ports at 62 * First cut at open and close commands. Data can flow through the ports at
@@ -62,7 +64,7 @@
62 * 64 *
63 * (03/26/2000) gkh 65 * (03/26/2000) gkh
64 * Split driver up into device specific pieces. 66 * Split driver up into device specific pieces.
65 * 67 *
66 */ 68 */
67 69
68#include <linux/kernel.h> 70#include <linux/kernel.h>
@@ -75,7 +77,7 @@
75#include <linux/module.h> 77#include <linux/module.h>
76#include <linux/spinlock.h> 78#include <linux/spinlock.h>
77#include <linux/mutex.h> 79#include <linux/mutex.h>
78#include <asm/uaccess.h> 80#include <linux/uaccess.h>
79#include <asm/termbits.h> 81#include <asm/termbits.h>
80#include <linux/usb.h> 82#include <linux/usb.h>
81#include <linux/serial_reg.h> 83#include <linux/serial_reg.h>
@@ -125,7 +127,7 @@ static struct usb_device_id id_table_combined [] = {
125 { } /* Terminating entry */ 127 { } /* Terminating entry */
126}; 128};
127 129
128MODULE_DEVICE_TABLE (usb, id_table_combined); 130MODULE_DEVICE_TABLE(usb, id_table_combined);
129 131
130static struct usb_driver whiteheat_driver = { 132static struct usb_driver whiteheat_driver = {
131 .name = "whiteheat", 133 .name = "whiteheat",
@@ -136,26 +138,34 @@ static struct usb_driver whiteheat_driver = {
136}; 138};
137 139
138/* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */ 140/* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
139static int whiteheat_firmware_download (struct usb_serial *serial, const struct usb_device_id *id); 141static int whiteheat_firmware_download(struct usb_serial *serial,
140static int whiteheat_firmware_attach (struct usb_serial *serial); 142 const struct usb_device_id *id);
143static int whiteheat_firmware_attach(struct usb_serial *serial);
141 144
142/* function prototypes for the Connect Tech WhiteHEAT serial converter */ 145/* function prototypes for the Connect Tech WhiteHEAT serial converter */
143static int whiteheat_attach (struct usb_serial *serial); 146static int whiteheat_attach(struct usb_serial *serial);
144static void whiteheat_shutdown (struct usb_serial *serial); 147static void whiteheat_shutdown(struct usb_serial *serial);
145static int whiteheat_open (struct usb_serial_port *port, struct file *filp); 148static int whiteheat_open(struct tty_struct *tty,
146static void whiteheat_close (struct usb_serial_port *port, struct file *filp); 149 struct usb_serial_port *port, struct file *filp);
147static int whiteheat_write (struct usb_serial_port *port, const unsigned char *buf, int count); 150static void whiteheat_close(struct tty_struct *tty,
148static int whiteheat_write_room (struct usb_serial_port *port); 151 struct usb_serial_port *port, struct file *filp);
149static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 152static int whiteheat_write(struct tty_struct *tty,
150static void whiteheat_set_termios (struct usb_serial_port *port, struct ktermios * old); 153 struct usb_serial_port *port,
151static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file); 154 const unsigned char *buf, int count);
152static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); 155static int whiteheat_write_room(struct tty_struct *tty);
153static void whiteheat_break_ctl (struct usb_serial_port *port, int break_state); 156static int whiteheat_ioctl(struct tty_struct *tty, struct file *file,
154static int whiteheat_chars_in_buffer (struct usb_serial_port *port); 157 unsigned int cmd, unsigned long arg);
155static void whiteheat_throttle (struct usb_serial_port *port); 158static void whiteheat_set_termios(struct tty_struct *tty,
156static void whiteheat_unthrottle (struct usb_serial_port *port); 159 struct usb_serial_port *port, struct ktermios *old);
157static void whiteheat_read_callback (struct urb *urb); 160static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file);
158static void whiteheat_write_callback (struct urb *urb); 161static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file,
162 unsigned int set, unsigned int clear);
163static void whiteheat_break_ctl(struct tty_struct *tty, int break_state);
164static int whiteheat_chars_in_buffer(struct tty_struct *tty);
165static void whiteheat_throttle(struct tty_struct *tty);
166static void whiteheat_unthrottle(struct tty_struct *tty);
167static void whiteheat_read_callback(struct urb *urb);
168static void whiteheat_write_callback(struct urb *urb);
159 169
160static struct usb_serial_driver whiteheat_fake_device = { 170static struct usb_serial_driver whiteheat_fake_device = {
161 .driver = { 171 .driver = {
@@ -202,7 +212,9 @@ struct whiteheat_command_private {
202 struct mutex mutex; 212 struct mutex mutex;
203 __u8 port_running; 213 __u8 port_running;
204 __u8 command_finished; 214 __u8 command_finished;
205 wait_queue_head_t wait_command; /* for handling sleeping while waiting for a command to finish */ 215 wait_queue_head_t wait_command; /* for handling sleeping whilst
216 waiting for a command to
217 finish */
206 __u8 result_buffer[64]; 218 __u8 result_buffer[64];
207}; 219};
208 220
@@ -239,14 +251,16 @@ static void command_port_write_callback(struct urb *urb);
239static void command_port_read_callback(struct urb *urb); 251static void command_port_read_callback(struct urb *urb);
240 252
241static int start_port_read(struct usb_serial_port *port); 253static int start_port_read(struct usb_serial_port *port);
242static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb, struct list_head *head); 254static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb,
255 struct list_head *head);
243static struct list_head *list_first(struct list_head *head); 256static struct list_head *list_first(struct list_head *head);
244static void rx_data_softint(struct work_struct *work); 257static void rx_data_softint(struct work_struct *work);
245 258
246static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *data, __u8 datasize); 259static int firm_send_command(struct usb_serial_port *port, __u8 command,
260 __u8 *data, __u8 datasize);
247static int firm_open(struct usb_serial_port *port); 261static int firm_open(struct usb_serial_port *port);
248static int firm_close(struct usb_serial_port *port); 262static int firm_close(struct usb_serial_port *port);
249static int firm_setup_port(struct usb_serial_port *port); 263static int firm_setup_port(struct tty_struct *tty);
250static int firm_set_rts(struct usb_serial_port *port, __u8 onoff); 264static int firm_set_rts(struct usb_serial_port *port, __u8 onoff);
251static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff); 265static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff);
252static int firm_set_break(struct usb_serial_port *port, __u8 onoff); 266static int firm_set_break(struct usb_serial_port *port, __u8 onoff);
@@ -278,7 +292,8 @@ static int firm_report_tx_done(struct usb_serial_port *port);
278 - device renumerated itself and comes up as new device id with all 292 - device renumerated itself and comes up as new device id with all
279 firmware download completed. 293 firmware download completed.
280*/ 294*/
281static int whiteheat_firmware_download (struct usb_serial *serial, const struct usb_device_id *id) 295static int whiteheat_firmware_download(struct usb_serial *serial,
296 const struct usb_device_id *id)
282{ 297{
283 int response, ret = -ENOENT; 298 int response, ret = -ENOENT;
284 const struct firmware *loader_fw = NULL, *firmware_fw = NULL; 299 const struct firmware *loader_fw = NULL, *firmware_fw = NULL;
@@ -313,7 +328,7 @@ static int whiteheat_firmware_download (struct usb_serial *serial, const struct
313 record = ihex_next_binrec(record); 328 record = ihex_next_binrec(record);
314 } 329 }
315 330
316 response = ezusb_set_reset (serial, 0); 331 response = ezusb_set_reset(serial, 0);
317 332
318 record = (const struct ihex_binrec *)firmware_fw->data; 333 record = (const struct ihex_binrec *)firmware_fw->data;
319 while (record && be32_to_cpu(record->addr) < 0x1b40) 334 while (record && be32_to_cpu(record->addr) < 0x1b40)
@@ -330,8 +345,8 @@ static int whiteheat_firmware_download (struct usb_serial *serial, const struct
330 } 345 }
331 ++record; 346 ++record;
332 } 347 }
333 348
334 response = ezusb_set_reset (serial, 1); 349 response = ezusb_set_reset(serial, 1);
335 350
336 record = (const struct ihex_binrec *)firmware_fw->data; 351 record = (const struct ihex_binrec *)firmware_fw->data;
337 while (record && be32_to_cpu(record->addr) < 0x1b40) { 352 while (record && be32_to_cpu(record->addr) < 0x1b40) {
@@ -355,7 +370,7 @@ static int whiteheat_firmware_download (struct usb_serial *serial, const struct
355} 370}
356 371
357 372
358static int whiteheat_firmware_attach (struct usb_serial *serial) 373static int whiteheat_firmware_attach(struct usb_serial *serial)
359{ 374{
360 /* We want this device to fail to have a driver assigned to it */ 375 /* We want this device to fail to have a driver assigned to it */
361 return 1; 376 return 1;
@@ -365,7 +380,7 @@ static int whiteheat_firmware_attach (struct usb_serial *serial)
365/***************************************************************************** 380/*****************************************************************************
366 * Connect Tech's White Heat serial driver functions 381 * Connect Tech's White Heat serial driver functions
367 *****************************************************************************/ 382 *****************************************************************************/
368static int whiteheat_attach (struct usb_serial *serial) 383static int whiteheat_attach(struct usb_serial *serial)
369{ 384{
370 struct usb_serial_port *command_port; 385 struct usb_serial_port *command_port;
371 struct whiteheat_command_private *command_info; 386 struct whiteheat_command_private *command_info;
@@ -386,43 +401,52 @@ static int whiteheat_attach (struct usb_serial *serial)
386 401
387 command_port = serial->port[COMMAND_PORT]; 402 command_port = serial->port[COMMAND_PORT];
388 403
389 pipe = usb_sndbulkpipe (serial->dev, command_port->bulk_out_endpointAddress); 404 pipe = usb_sndbulkpipe(serial->dev,
405 command_port->bulk_out_endpointAddress);
390 command = kmalloc(2, GFP_KERNEL); 406 command = kmalloc(2, GFP_KERNEL);
391 if (!command) 407 if (!command)
392 goto no_command_buffer; 408 goto no_command_buffer;
393 command[0] = WHITEHEAT_GET_HW_INFO; 409 command[0] = WHITEHEAT_GET_HW_INFO;
394 command[1] = 0; 410 command[1] = 0;
395 411
396 result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL); 412 result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
397 if (!result) 413 if (!result)
398 goto no_result_buffer; 414 goto no_result_buffer;
399 /* 415 /*
400 * When the module is reloaded the firmware is still there and 416 * When the module is reloaded the firmware is still there and
401 * the endpoints are still in the usb core unchanged. This is the 417 * the endpoints are still in the usb core unchanged. This is the
402 * unlinking bug in disguise. Same for the call below. 418 * unlinking bug in disguise. Same for the call below.
403 */ 419 */
404 usb_clear_halt(serial->dev, pipe); 420 usb_clear_halt(serial->dev, pipe);
405 ret = usb_bulk_msg (serial->dev, pipe, command, 2, &alen, COMMAND_TIMEOUT_MS); 421 ret = usb_bulk_msg(serial->dev, pipe, command, 2,
422 &alen, COMMAND_TIMEOUT_MS);
406 if (ret) { 423 if (ret) {
407 err("%s: Couldn't send command [%d]", serial->type->description, ret); 424 err("%s: Couldn't send command [%d]",
425 serial->type->description, ret);
408 goto no_firmware; 426 goto no_firmware;
409 } else if (alen != 2) { 427 } else if (alen != 2) {
410 err("%s: Send command incomplete [%d]", serial->type->description, alen); 428 err("%s: Send command incomplete [%d]",
429 serial->type->description, alen);
411 goto no_firmware; 430 goto no_firmware;
412 } 431 }
413 432
414 pipe = usb_rcvbulkpipe (serial->dev, command_port->bulk_in_endpointAddress); 433 pipe = usb_rcvbulkpipe(serial->dev,
434 command_port->bulk_in_endpointAddress);
415 /* See the comment on the usb_clear_halt() above */ 435 /* See the comment on the usb_clear_halt() above */
416 usb_clear_halt(serial->dev, pipe); 436 usb_clear_halt(serial->dev, pipe);
417 ret = usb_bulk_msg (serial->dev, pipe, result, sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS); 437 ret = usb_bulk_msg(serial->dev, pipe, result,
438 sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
418 if (ret) { 439 if (ret) {
419 err("%s: Couldn't get results [%d]", serial->type->description, ret); 440 err("%s: Couldn't get results [%d]",
441 serial->type->description, ret);
420 goto no_firmware; 442 goto no_firmware;
421 } else if (alen != sizeof(*hw_info) + 1) { 443 } else if (alen != sizeof(*hw_info) + 1) {
422 err("%s: Get results incomplete [%d]", serial->type->description, alen); 444 err("%s: Get results incomplete [%d]",
445 serial->type->description, alen);
423 goto no_firmware; 446 goto no_firmware;
424 } else if (result[0] != command[0]) { 447 } else if (result[0] != command[0]) {
425 err("%s: Command failed [%d]", serial->type->description, result[0]); 448 err("%s: Command failed [%d]",
449 serial->type->description, result[0]);
426 goto no_firmware; 450 goto no_firmware;
427 } 451 }
428 452
@@ -436,7 +460,8 @@ static int whiteheat_attach (struct usb_serial *serial)
436 460
437 info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL); 461 info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL);
438 if (info == NULL) { 462 if (info == NULL) {
439 err("%s: Out of memory for port structures\n", serial->type->description); 463 err("%s: Out of memory for port structures\n",
464 serial->type->description);
440 goto no_private; 465 goto no_private;
441 } 466 }
442 467
@@ -506,9 +531,11 @@ static int whiteheat_attach (struct usb_serial *serial)
506 usb_set_serial_port_data(port, info); 531 usb_set_serial_port_data(port, info);
507 } 532 }
508 533
509 command_info = kmalloc(sizeof(struct whiteheat_command_private), GFP_KERNEL); 534 command_info = kmalloc(sizeof(struct whiteheat_command_private),
535 GFP_KERNEL);
510 if (command_info == NULL) { 536 if (command_info == NULL) {
511 err("%s: Out of memory for port structures\n", serial->type->description); 537 err("%s: Out of memory for port structures\n",
538 serial->type->description);
512 goto no_command_private; 539 goto no_command_private;
513 } 540 }
514 541
@@ -525,9 +552,12 @@ static int whiteheat_attach (struct usb_serial *serial)
525 552
526no_firmware: 553no_firmware:
527 /* Firmware likely not running */ 554 /* Firmware likely not running */
528 err("%s: Unable to retrieve firmware version, try replugging\n", serial->type->description); 555 err("%s: Unable to retrieve firmware version, try replugging\n",
529 err("%s: If the firmware is not running (status led not blinking)\n", serial->type->description); 556 serial->type->description);
530 err("%s: please contact support@connecttech.com\n", serial->type->description); 557 err("%s: If the firmware is not running (status led not blinking)\n",
558 serial->type->description);
559 err("%s: please contact support@connecttech.com\n",
560 serial->type->description);
531 kfree(result); 561 kfree(result);
532 return -ENODEV; 562 return -ENODEV;
533 563
@@ -570,7 +600,7 @@ no_command_buffer:
570} 600}
571 601
572 602
573static void whiteheat_shutdown (struct usb_serial *serial) 603static void whiteheat_shutdown(struct usb_serial *serial)
574{ 604{
575 struct usb_serial_port *command_port; 605 struct usb_serial_port *command_port;
576 struct usb_serial_port *port; 606 struct usb_serial_port *port;
@@ -585,7 +615,7 @@ static void whiteheat_shutdown (struct usb_serial *serial)
585 615
586 /* free up our private data for our command port */ 616 /* free up our private data for our command port */
587 command_port = serial->port[COMMAND_PORT]; 617 command_port = serial->port[COMMAND_PORT];
588 kfree (usb_get_serial_port_data(command_port)); 618 kfree(usb_get_serial_port_data(command_port));
589 619
590 for (i = 0; i < serial->num_ports; i++) { 620 for (i = 0; i < serial->num_ports; i++) {
591 port = serial->port[i]; 621 port = serial->port[i];
@@ -612,11 +642,10 @@ static void whiteheat_shutdown (struct usb_serial *serial)
612 return; 642 return;
613} 643}
614 644
615 645static int whiteheat_open(struct tty_struct *tty,
616static int whiteheat_open (struct usb_serial_port *port, struct file *filp) 646 struct usb_serial_port *port, struct file *filp)
617{ 647{
618 int retval = 0; 648 int retval = 0;
619 struct ktermios old_term;
620 649
621 dbg("%s - port %d", __func__, port->number); 650 dbg("%s - port %d", __func__, port->number);
622 651
@@ -624,7 +653,8 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
624 if (retval) 653 if (retval)
625 goto exit; 654 goto exit;
626 655
627 port->tty->low_latency = 1; 656 if (tty)
657 tty->low_latency = 1;
628 658
629 /* send an open port command */ 659 /* send an open port command */
630 retval = firm_open(port); 660 retval = firm_open(port);
@@ -640,9 +670,8 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
640 goto exit; 670 goto exit;
641 } 671 }
642 672
643 old_term.c_cflag = ~port->tty->termios->c_cflag; 673 if (tty)
644 old_term.c_iflag = ~port->tty->termios->c_iflag; 674 firm_setup_port(tty);
645 whiteheat_set_termios(port, &old_term);
646 675
647 /* Work around HCD bugs */ 676 /* Work around HCD bugs */
648 usb_clear_halt(port->serial->dev, port->read_urb->pipe); 677 usb_clear_halt(port->serial->dev, port->read_urb->pipe);
@@ -651,7 +680,8 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
651 /* Start reading from the device */ 680 /* Start reading from the device */
652 retval = start_port_read(port); 681 retval = start_port_read(port);
653 if (retval) { 682 if (retval) {
654 err("%s - failed submitting read urb, error %d", __func__, retval); 683 err("%s - failed submitting read urb, error %d",
684 __func__, retval);
655 firm_close(port); 685 firm_close(port);
656 stop_command_port(port->serial); 686 stop_command_port(port->serial);
657 goto exit; 687 goto exit;
@@ -663,7 +693,8 @@ exit:
663} 693}
664 694
665 695
666static void whiteheat_close(struct usb_serial_port *port, struct file * filp) 696static void whiteheat_close(struct tty_struct *tty,
697 struct usb_serial_port *port, struct file *filp)
667{ 698{
668 struct whiteheat_private *info = usb_get_serial_port_data(port); 699 struct whiteheat_private *info = usb_get_serial_port_data(port);
669 struct whiteheat_urb_wrap *wrap; 700 struct whiteheat_urb_wrap *wrap;
@@ -681,7 +712,7 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
681 } 712 }
682 mutex_unlock(&port->serial->disc_mutex); 713 mutex_unlock(&port->serial->disc_mutex);
683 714
684 port->tty->closing = 1; 715 tty->closing = 1;
685 716
686/* 717/*
687 * Not currently in use; tty_wait_until_sent() calls 718 * Not currently in use; tty_wait_until_sent() calls
@@ -689,12 +720,12 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
689 * acquisition. This should be fixed at some point. Greg's been 720 * acquisition. This should be fixed at some point. Greg's been
690 * notified. 721 * notified.
691 if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) { 722 if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) {
692 tty_wait_until_sent(port->tty, CLOSING_DELAY); 723 tty_wait_until_sent(tty, CLOSING_DELAY);
693 } 724 }
694*/ 725*/
695 726
696 tty_driver_flush_buffer(port->tty); 727 tty_driver_flush_buffer(tty);
697 tty_ldisc_flush(port->tty); 728 tty_ldisc_flush(tty);
698 729
699 firm_report_tx_done(port); 730 firm_report_tx_done(port);
700 731
@@ -728,11 +759,12 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
728 759
729 stop_command_port(port->serial); 760 stop_command_port(port->serial);
730 761
731 port->tty->closing = 0; 762 tty->closing = 0;
732} 763}
733 764
734 765
735static int whiteheat_write(struct usb_serial_port *port, const unsigned char *buf, int count) 766static int whiteheat_write(struct tty_struct *tty,
767 struct usb_serial_port *port, const unsigned char *buf, int count)
736{ 768{
737 struct usb_serial *serial = port->serial; 769 struct usb_serial *serial = port->serial;
738 struct whiteheat_private *info = usb_get_serial_port_data(port); 770 struct whiteheat_private *info = usb_get_serial_port_data(port);
@@ -763,16 +795,19 @@ static int whiteheat_write(struct usb_serial_port *port, const unsigned char *bu
763 795
764 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); 796 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
765 urb = wrap->urb; 797 urb = wrap->urb;
766 bytes = (count > port->bulk_out_size) ? port->bulk_out_size : count; 798 bytes = (count > port->bulk_out_size) ?
767 memcpy (urb->transfer_buffer, buf + sent, bytes); 799 port->bulk_out_size : count;
800 memcpy(urb->transfer_buffer, buf + sent, bytes);
768 801
769 usb_serial_debug_data(debug, &port->dev, __func__, bytes, urb->transfer_buffer); 802 usb_serial_debug_data(debug, &port->dev,
803 __func__, bytes, urb->transfer_buffer);
770 804
771 urb->dev = serial->dev; 805 urb->dev = serial->dev;
772 urb->transfer_buffer_length = bytes; 806 urb->transfer_buffer_length = bytes;
773 result = usb_submit_urb(urb, GFP_ATOMIC); 807 result = usb_submit_urb(urb, GFP_ATOMIC);
774 if (result) { 808 if (result) {
775 err("%s - failed submitting write urb, error %d", __func__, result); 809 err("%s - failed submitting write urb, error %d",
810 __func__, result);
776 sent = result; 811 sent = result;
777 spin_lock_irqsave(&info->lock, flags); 812 spin_lock_irqsave(&info->lock, flags);
778 list_add(tmp, &info->tx_urbs_free); 813 list_add(tmp, &info->tx_urbs_free);
@@ -790,16 +825,16 @@ static int whiteheat_write(struct usb_serial_port *port, const unsigned char *bu
790 return sent; 825 return sent;
791} 826}
792 827
793 828static int whiteheat_write_room(struct tty_struct *tty)
794static int whiteheat_write_room(struct usb_serial_port *port)
795{ 829{
830 struct usb_serial_port *port = tty->driver_data;
796 struct whiteheat_private *info = usb_get_serial_port_data(port); 831 struct whiteheat_private *info = usb_get_serial_port_data(port);
797 struct list_head *tmp; 832 struct list_head *tmp;
798 int room = 0; 833 int room = 0;
799 unsigned long flags; 834 unsigned long flags;
800 835
801 dbg("%s - port %d", __func__, port->number); 836 dbg("%s - port %d", __func__, port->number);
802 837
803 spin_lock_irqsave(&info->lock, flags); 838 spin_lock_irqsave(&info->lock, flags);
804 list_for_each(tmp, &info->tx_urbs_free) 839 list_for_each(tmp, &info->tx_urbs_free)
805 room++; 840 room++;
@@ -810,9 +845,9 @@ static int whiteheat_write_room(struct usb_serial_port *port)
810 return (room); 845 return (room);
811} 846}
812 847
813 848static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file)
814static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file)
815{ 849{
850 struct usb_serial_port *port = tty->driver_data;
816 struct whiteheat_private *info = usb_get_serial_port_data(port); 851 struct whiteheat_private *info = usb_get_serial_port_data(port);
817 unsigned int modem_signals = 0; 852 unsigned int modem_signals = 0;
818 853
@@ -827,10 +862,10 @@ static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file)
827 return modem_signals; 862 return modem_signals;
828} 863}
829 864
830 865static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file,
831static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file,
832 unsigned int set, unsigned int clear) 866 unsigned int set, unsigned int clear)
833{ 867{
868 struct usb_serial_port *port = tty->driver_data;
834 struct whiteheat_private *info = usb_get_serial_port_data(port); 869 struct whiteheat_private *info = usb_get_serial_port_data(port);
835 870
836 dbg("%s - port %d", __func__, port->number); 871 dbg("%s - port %d", __func__, port->number);
@@ -851,65 +886,55 @@ static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file,
851} 886}
852 887
853 888
854static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 889static int whiteheat_ioctl(struct tty_struct *tty, struct file *file,
890 unsigned int cmd, unsigned long arg)
855{ 891{
892 struct usb_serial_port *port = tty->driver_data;
856 struct serial_struct serstruct; 893 struct serial_struct serstruct;
857 void __user *user_arg = (void __user *)arg; 894 void __user *user_arg = (void __user *)arg;
858 895
859 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); 896 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
860 897
861 switch (cmd) { 898 switch (cmd) {
862 case TIOCGSERIAL: 899 case TIOCGSERIAL:
863 memset(&serstruct, 0, sizeof(serstruct)); 900 memset(&serstruct, 0, sizeof(serstruct));
864 serstruct.type = PORT_16654; 901 serstruct.type = PORT_16654;
865 serstruct.line = port->serial->minor; 902 serstruct.line = port->serial->minor;
866 serstruct.port = port->number; 903 serstruct.port = port->number;
867 serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; 904 serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
868 serstruct.xmit_fifo_size = port->bulk_out_size; 905 serstruct.xmit_fifo_size = port->bulk_out_size;
869 serstruct.custom_divisor = 0; 906 serstruct.custom_divisor = 0;
870 serstruct.baud_base = 460800; 907 serstruct.baud_base = 460800;
871 serstruct.close_delay = CLOSING_DELAY; 908 serstruct.close_delay = CLOSING_DELAY;
872 serstruct.closing_wait = CLOSING_DELAY; 909 serstruct.closing_wait = CLOSING_DELAY;
873 910
874 if (copy_to_user(user_arg, &serstruct, sizeof(serstruct))) 911 if (copy_to_user(user_arg, &serstruct, sizeof(serstruct)))
875 return -EFAULT; 912 return -EFAULT;
876 913 break;
877 break; 914 default:
878 915 break;
879 case TIOCSSERIAL:
880 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct)))
881 return -EFAULT;
882
883 /*
884 * For now this is ignored. dip sets the ASYNC_[V]HI flags
885 * but this isn't used by us at all. Maybe someone somewhere
886 * will need the custom_divisor setting.
887 */
888
889 break;
890
891 default:
892 break;
893 } 916 }
894 917
895 return -ENOIOCTLCMD; 918 return -ENOIOCTLCMD;
896} 919}
897 920
898 921
899static void whiteheat_set_termios(struct usb_serial_port *port, struct ktermios *old_termios) 922static void whiteheat_set_termios(struct tty_struct *tty,
923 struct usb_serial_port *port, struct ktermios *old_termios)
900{ 924{
901 dbg("%s -port %d", __func__, port->number); 925 firm_setup_port(tty);
902 firm_setup_port(port);
903} 926}
904 927
905 928static void whiteheat_break_ctl(struct tty_struct *tty, int break_state)
906static void whiteheat_break_ctl(struct usb_serial_port *port, int break_state) { 929{
930 struct usb_serial_port *port = tty->driver_data;
907 firm_set_break(port, break_state); 931 firm_set_break(port, break_state);
908} 932}
909 933
910 934
911static int whiteheat_chars_in_buffer(struct usb_serial_port *port) 935static int whiteheat_chars_in_buffer(struct tty_struct *tty)
912{ 936{
937 struct usb_serial_port *port = tty->driver_data;
913 struct whiteheat_private *info = usb_get_serial_port_data(port); 938 struct whiteheat_private *info = usb_get_serial_port_data(port);
914 struct list_head *tmp; 939 struct list_head *tmp;
915 struct whiteheat_urb_wrap *wrap; 940 struct whiteheat_urb_wrap *wrap;
@@ -925,13 +950,14 @@ static int whiteheat_chars_in_buffer(struct usb_serial_port *port)
925 } 950 }
926 spin_unlock_irqrestore(&info->lock, flags); 951 spin_unlock_irqrestore(&info->lock, flags);
927 952
928 dbg ("%s - returns %d", __func__, chars); 953 dbg("%s - returns %d", __func__, chars);
929 return chars; 954 return chars;
930} 955}
931 956
932 957
933static void whiteheat_throttle (struct usb_serial_port *port) 958static void whiteheat_throttle(struct tty_struct *tty)
934{ 959{
960 struct usb_serial_port *port = tty->driver_data;
935 struct whiteheat_private *info = usb_get_serial_port_data(port); 961 struct whiteheat_private *info = usb_get_serial_port_data(port);
936 unsigned long flags; 962 unsigned long flags;
937 963
@@ -945,8 +971,9 @@ static void whiteheat_throttle (struct usb_serial_port *port)
945} 971}
946 972
947 973
948static void whiteheat_unthrottle (struct usb_serial_port *port) 974static void whiteheat_unthrottle(struct tty_struct *tty)
949{ 975{
976 struct usb_serial_port *port = tty->driver_data;
950 struct whiteheat_private *info = usb_get_serial_port_data(port); 977 struct whiteheat_private *info = usb_get_serial_port_data(port);
951 int actually_throttled; 978 int actually_throttled;
952 unsigned long flags; 979 unsigned long flags;
@@ -993,7 +1020,7 @@ static void command_port_read_callback(struct urb *urb)
993 1020
994 command_info = usb_get_serial_port_data(command_port); 1021 command_info = usb_get_serial_port_data(command_port);
995 if (!command_info) { 1022 if (!command_info) {
996 dbg ("%s - command_info is NULL, exiting.", __func__); 1023 dbg("%s - command_info is NULL, exiting.", __func__);
997 return; 1024 return;
998 } 1025 }
999 if (status) { 1026 if (status) {
@@ -1004,7 +1031,8 @@ static void command_port_read_callback(struct urb *urb)
1004 return; 1031 return;
1005 } 1032 }
1006 1033
1007 usb_serial_debug_data(debug, &command_port->dev, __func__, urb->actual_length, data); 1034 usb_serial_debug_data(debug, &command_port->dev,
1035 __func__, urb->actual_length, data);
1008 1036
1009 if (data[0] == WHITEHEAT_CMD_COMPLETE) { 1037 if (data[0] == WHITEHEAT_CMD_COMPLETE) {
1010 command_info->command_finished = WHITEHEAT_CMD_COMPLETE; 1038 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
@@ -1013,21 +1041,23 @@ static void command_port_read_callback(struct urb *urb)
1013 command_info->command_finished = WHITEHEAT_CMD_FAILURE; 1041 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
1014 wake_up(&command_info->wait_command); 1042 wake_up(&command_info->wait_command);
1015 } else if (data[0] == WHITEHEAT_EVENT) { 1043 } else if (data[0] == WHITEHEAT_EVENT) {
1016 /* These are unsolicited reports from the firmware, hence no waiting command to wakeup */ 1044 /* These are unsolicited reports from the firmware, hence no
1045 waiting command to wakeup */
1017 dbg("%s - event received", __func__); 1046 dbg("%s - event received", __func__);
1018 } else if (data[0] == WHITEHEAT_GET_DTR_RTS) { 1047 } else if (data[0] == WHITEHEAT_GET_DTR_RTS) {
1019 memcpy(command_info->result_buffer, &data[1], urb->actual_length - 1); 1048 memcpy(command_info->result_buffer, &data[1],
1049 urb->actual_length - 1);
1020 command_info->command_finished = WHITEHEAT_CMD_COMPLETE; 1050 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
1021 wake_up(&command_info->wait_command); 1051 wake_up(&command_info->wait_command);
1022 } else { 1052 } else
1023 dbg("%s - bad reply from firmware", __func__); 1053 dbg("%s - bad reply from firmware", __func__);
1024 } 1054
1025
1026 /* Continue trying to always read */ 1055 /* Continue trying to always read */
1027 command_port->read_urb->dev = command_port->serial->dev; 1056 command_port->read_urb->dev = command_port->serial->dev;
1028 result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC); 1057 result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC);
1029 if (result) 1058 if (result)
1030 dbg("%s - failed resubmitting read urb, error %d", __func__, result); 1059 dbg("%s - failed resubmitting read urb, error %d",
1060 __func__, result);
1031} 1061}
1032 1062
1033 1063
@@ -1060,7 +1090,8 @@ static void whiteheat_read_callback(struct urb *urb)
1060 return; 1090 return;
1061 } 1091 }
1062 1092
1063 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 1093 usb_serial_debug_data(debug, &port->dev,
1094 __func__, urb->actual_length, data);
1064 1095
1065 spin_lock(&info->lock); 1096 spin_lock(&info->lock);
1066 list_add_tail(&wrap->list, &info->rx_urb_q); 1097 list_add_tail(&wrap->list, &info->rx_urb_q);
@@ -1107,7 +1138,8 @@ static void whiteheat_write_callback(struct urb *urb)
1107/***************************************************************************** 1138/*****************************************************************************
1108 * Connect Tech's White Heat firmware interface 1139 * Connect Tech's White Heat firmware interface
1109 *****************************************************************************/ 1140 *****************************************************************************/
1110static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *data, __u8 datasize) 1141static int firm_send_command(struct usb_serial_port *port, __u8 command,
1142 __u8 *data, __u8 datasize)
1111{ 1143{
1112 struct usb_serial_port *command_port; 1144 struct usb_serial_port *command_port;
1113 struct whiteheat_command_private *command_info; 1145 struct whiteheat_command_private *command_info;
@@ -1122,13 +1154,13 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *d
1122 command_info = usb_get_serial_port_data(command_port); 1154 command_info = usb_get_serial_port_data(command_port);
1123 mutex_lock(&command_info->mutex); 1155 mutex_lock(&command_info->mutex);
1124 command_info->command_finished = false; 1156 command_info->command_finished = false;
1125 1157
1126 transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer; 1158 transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer;
1127 transfer_buffer[0] = command; 1159 transfer_buffer[0] = command;
1128 memcpy (&transfer_buffer[1], data, datasize); 1160 memcpy(&transfer_buffer[1], data, datasize);
1129 command_port->write_urb->transfer_buffer_length = datasize + 1; 1161 command_port->write_urb->transfer_buffer_length = datasize + 1;
1130 command_port->write_urb->dev = port->serial->dev; 1162 command_port->write_urb->dev = port->serial->dev;
1131 retval = usb_submit_urb (command_port->write_urb, GFP_NOIO); 1163 retval = usb_submit_urb(command_port->write_urb, GFP_NOIO);
1132 if (retval) { 1164 if (retval) {
1133 dbg("%s - submit urb failed", __func__); 1165 dbg("%s - submit urb failed", __func__);
1134 goto exit; 1166 goto exit;
@@ -1155,51 +1187,57 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *d
1155 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) { 1187 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
1156 dbg("%s - command completed.", __func__); 1188 dbg("%s - command completed.", __func__);
1157 switch (command) { 1189 switch (command) {
1158 case WHITEHEAT_GET_DTR_RTS: 1190 case WHITEHEAT_GET_DTR_RTS:
1159 info = usb_get_serial_port_data(port); 1191 info = usb_get_serial_port_data(port);
1160 memcpy(&info->mcr, command_info->result_buffer, sizeof(struct whiteheat_dr_info)); 1192 memcpy(&info->mcr, command_info->result_buffer,
1193 sizeof(struct whiteheat_dr_info));
1161 break; 1194 break;
1162 } 1195 }
1163 } 1196 }
1164
1165exit: 1197exit:
1166 mutex_unlock(&command_info->mutex); 1198 mutex_unlock(&command_info->mutex);
1167 return retval; 1199 return retval;
1168} 1200}
1169 1201
1170 1202
1171static int firm_open(struct usb_serial_port *port) { 1203static int firm_open(struct usb_serial_port *port)
1204{
1172 struct whiteheat_simple open_command; 1205 struct whiteheat_simple open_command;
1173 1206
1174 open_command.port = port->number - port->serial->minor + 1; 1207 open_command.port = port->number - port->serial->minor + 1;
1175 return firm_send_command(port, WHITEHEAT_OPEN, (__u8 *)&open_command, sizeof(open_command)); 1208 return firm_send_command(port, WHITEHEAT_OPEN,
1209 (__u8 *)&open_command, sizeof(open_command));
1176} 1210}
1177 1211
1178 1212
1179static int firm_close(struct usb_serial_port *port) { 1213static int firm_close(struct usb_serial_port *port)
1214{
1180 struct whiteheat_simple close_command; 1215 struct whiteheat_simple close_command;
1181 1216
1182 close_command.port = port->number - port->serial->minor + 1; 1217 close_command.port = port->number - port->serial->minor + 1;
1183 return firm_send_command(port, WHITEHEAT_CLOSE, (__u8 *)&close_command, sizeof(close_command)); 1218 return firm_send_command(port, WHITEHEAT_CLOSE,
1219 (__u8 *)&close_command, sizeof(close_command));
1184} 1220}
1185 1221
1186 1222
1187static int firm_setup_port(struct usb_serial_port *port) { 1223static int firm_setup_port(struct tty_struct *tty)
1224{
1225 struct usb_serial_port *port = tty->driver_data;
1188 struct whiteheat_port_settings port_settings; 1226 struct whiteheat_port_settings port_settings;
1189 unsigned int cflag = port->tty->termios->c_cflag; 1227 unsigned int cflag = tty->termios->c_cflag;
1190 1228
1191 port_settings.port = port->number + 1; 1229 port_settings.port = port->number + 1;
1192 1230
1193 /* get the byte size */ 1231 /* get the byte size */
1194 switch (cflag & CSIZE) { 1232 switch (cflag & CSIZE) {
1195 case CS5: port_settings.bits = 5; break; 1233 case CS5: port_settings.bits = 5; break;
1196 case CS6: port_settings.bits = 6; break; 1234 case CS6: port_settings.bits = 6; break;
1197 case CS7: port_settings.bits = 7; break; 1235 case CS7: port_settings.bits = 7; break;
1198 default: 1236 default:
1199 case CS8: port_settings.bits = 8; break; 1237 case CS8: port_settings.bits = 8; break;
1200 } 1238 }
1201 dbg("%s - data bits = %d", __func__, port_settings.bits); 1239 dbg("%s - data bits = %d", __func__, port_settings.bits);
1202 1240
1203 /* determine the parity */ 1241 /* determine the parity */
1204 if (cflag & PARENB) 1242 if (cflag & PARENB)
1205 if (cflag & CMSPAR) 1243 if (cflag & CMSPAR)
@@ -1225,7 +1263,8 @@ static int firm_setup_port(struct usb_serial_port *port) {
1225 1263
1226 /* figure out the flow control settings */ 1264 /* figure out the flow control settings */
1227 if (cflag & CRTSCTS) 1265 if (cflag & CRTSCTS)
1228 port_settings.hflow = (WHITEHEAT_HFLOW_CTS | WHITEHEAT_HFLOW_RTS); 1266 port_settings.hflow = (WHITEHEAT_HFLOW_CTS |
1267 WHITEHEAT_HFLOW_RTS);
1229 else 1268 else
1230 port_settings.hflow = WHITEHEAT_HFLOW_NONE; 1269 port_settings.hflow = WHITEHEAT_HFLOW_NONE;
1231 dbg("%s - hardware flow control = %s %s %s %s", __func__, 1270 dbg("%s - hardware flow control = %s %s %s %s", __func__,
@@ -1233,81 +1272,95 @@ static int firm_setup_port(struct usb_serial_port *port) {
1233 (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "", 1272 (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "",
1234 (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "", 1273 (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "",
1235 (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : ""); 1274 (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : "");
1236 1275
1237 /* determine software flow control */ 1276 /* determine software flow control */
1238 if (I_IXOFF(port->tty)) 1277 if (I_IXOFF(tty))
1239 port_settings.sflow = WHITEHEAT_SFLOW_RXTX; 1278 port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
1240 else 1279 else
1241 port_settings.sflow = WHITEHEAT_SFLOW_NONE; 1280 port_settings.sflow = WHITEHEAT_SFLOW_NONE;
1242 dbg("%s - software flow control = %c", __func__, port_settings.sflow); 1281 dbg("%s - software flow control = %c", __func__, port_settings.sflow);
1243 1282
1244 port_settings.xon = START_CHAR(port->tty); 1283 port_settings.xon = START_CHAR(tty);
1245 port_settings.xoff = STOP_CHAR(port->tty); 1284 port_settings.xoff = STOP_CHAR(tty);
1246 dbg("%s - XON = %2x, XOFF = %2x", __func__, port_settings.xon, port_settings.xoff); 1285 dbg("%s - XON = %2x, XOFF = %2x",
1286 __func__, port_settings.xon, port_settings.xoff);
1247 1287
1248 /* get the baud rate wanted */ 1288 /* get the baud rate wanted */
1249 port_settings.baud = tty_get_baud_rate(port->tty); 1289 port_settings.baud = tty_get_baud_rate(tty);
1250 dbg("%s - baud rate = %d", __func__, port_settings.baud); 1290 dbg("%s - baud rate = %d", __func__, port_settings.baud);
1251 1291
1252 /* fixme: should set validated settings */ 1292 /* fixme: should set validated settings */
1253 tty_encode_baud_rate(port->tty, port_settings.baud, port_settings.baud); 1293 tty_encode_baud_rate(tty, port_settings.baud, port_settings.baud);
1254 /* handle any settings that aren't specified in the tty structure */ 1294 /* handle any settings that aren't specified in the tty structure */
1255 port_settings.lloop = 0; 1295 port_settings.lloop = 0;
1256 1296
1257 /* now send the message to the device */ 1297 /* now send the message to the device */
1258 return firm_send_command(port, WHITEHEAT_SETUP_PORT, (__u8 *)&port_settings, sizeof(port_settings)); 1298 return firm_send_command(port, WHITEHEAT_SETUP_PORT,
1299 (__u8 *)&port_settings, sizeof(port_settings));
1259} 1300}
1260 1301
1261 1302
1262static int firm_set_rts(struct usb_serial_port *port, __u8 onoff) { 1303static int firm_set_rts(struct usb_serial_port *port, __u8 onoff)
1304{
1263 struct whiteheat_set_rdb rts_command; 1305 struct whiteheat_set_rdb rts_command;
1264 1306
1265 rts_command.port = port->number - port->serial->minor + 1; 1307 rts_command.port = port->number - port->serial->minor + 1;
1266 rts_command.state = onoff; 1308 rts_command.state = onoff;
1267 return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&rts_command, sizeof(rts_command)); 1309 return firm_send_command(port, WHITEHEAT_SET_RTS,
1310 (__u8 *)&rts_command, sizeof(rts_command));
1268} 1311}
1269 1312
1270 1313
1271static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff) { 1314static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff)
1315{
1272 struct whiteheat_set_rdb dtr_command; 1316 struct whiteheat_set_rdb dtr_command;
1273 1317
1274 dtr_command.port = port->number - port->serial->minor + 1; 1318 dtr_command.port = port->number - port->serial->minor + 1;
1275 dtr_command.state = onoff; 1319 dtr_command.state = onoff;
1276 return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&dtr_command, sizeof(dtr_command)); 1320 return firm_send_command(port, WHITEHEAT_SET_DTR,
1321 (__u8 *)&dtr_command, sizeof(dtr_command));
1277} 1322}
1278 1323
1279 1324
1280static int firm_set_break(struct usb_serial_port *port, __u8 onoff) { 1325static int firm_set_break(struct usb_serial_port *port, __u8 onoff)
1326{
1281 struct whiteheat_set_rdb break_command; 1327 struct whiteheat_set_rdb break_command;
1282 1328
1283 break_command.port = port->number - port->serial->minor + 1; 1329 break_command.port = port->number - port->serial->minor + 1;
1284 break_command.state = onoff; 1330 break_command.state = onoff;
1285 return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&break_command, sizeof(break_command)); 1331 return firm_send_command(port, WHITEHEAT_SET_BREAK,
1332 (__u8 *)&break_command, sizeof(break_command));
1286} 1333}
1287 1334
1288 1335
1289static int firm_purge(struct usb_serial_port *port, __u8 rxtx) { 1336static int firm_purge(struct usb_serial_port *port, __u8 rxtx)
1337{
1290 struct whiteheat_purge purge_command; 1338 struct whiteheat_purge purge_command;
1291 1339
1292 purge_command.port = port->number - port->serial->minor + 1; 1340 purge_command.port = port->number - port->serial->minor + 1;
1293 purge_command.what = rxtx; 1341 purge_command.what = rxtx;
1294 return firm_send_command(port, WHITEHEAT_PURGE, (__u8 *)&purge_command, sizeof(purge_command)); 1342 return firm_send_command(port, WHITEHEAT_PURGE,
1343 (__u8 *)&purge_command, sizeof(purge_command));
1295} 1344}
1296 1345
1297 1346
1298static int firm_get_dtr_rts(struct usb_serial_port *port) { 1347static int firm_get_dtr_rts(struct usb_serial_port *port)
1348{
1299 struct whiteheat_simple get_dr_command; 1349 struct whiteheat_simple get_dr_command;
1300 1350
1301 get_dr_command.port = port->number - port->serial->minor + 1; 1351 get_dr_command.port = port->number - port->serial->minor + 1;
1302 return firm_send_command(port, WHITEHEAT_GET_DTR_RTS, (__u8 *)&get_dr_command, sizeof(get_dr_command)); 1352 return firm_send_command(port, WHITEHEAT_GET_DTR_RTS,
1353 (__u8 *)&get_dr_command, sizeof(get_dr_command));
1303} 1354}
1304 1355
1305 1356
1306static int firm_report_tx_done(struct usb_serial_port *port) { 1357static int firm_report_tx_done(struct usb_serial_port *port)
1358{
1307 struct whiteheat_simple close_command; 1359 struct whiteheat_simple close_command;
1308 1360
1309 close_command.port = port->number - port->serial->minor + 1; 1361 close_command.port = port->number - port->serial->minor + 1;
1310 return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE, (__u8 *)&close_command, sizeof(close_command)); 1362 return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE,
1363 (__u8 *)&close_command, sizeof(close_command));
1311} 1364}
1312 1365
1313 1366
@@ -1319,7 +1372,7 @@ static int start_command_port(struct usb_serial *serial)
1319 struct usb_serial_port *command_port; 1372 struct usb_serial_port *command_port;
1320 struct whiteheat_command_private *command_info; 1373 struct whiteheat_command_private *command_info;
1321 int retval = 0; 1374 int retval = 0;
1322 1375
1323 command_port = serial->port[COMMAND_PORT]; 1376 command_port = serial->port[COMMAND_PORT];
1324 command_info = usb_get_serial_port_data(command_port); 1377 command_info = usb_get_serial_port_data(command_port);
1325 mutex_lock(&command_info->mutex); 1378 mutex_lock(&command_info->mutex);
@@ -1330,7 +1383,8 @@ static int start_command_port(struct usb_serial *serial)
1330 command_port->read_urb->dev = serial->dev; 1383 command_port->read_urb->dev = serial->dev;
1331 retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL); 1384 retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
1332 if (retval) { 1385 if (retval) {
1333 err("%s - failed submitting read urb, error %d", __func__, retval); 1386 err("%s - failed submitting read urb, error %d",
1387 __func__, retval);
1334 goto exit; 1388 goto exit;
1335 } 1389 }
1336 } 1390 }
@@ -1400,7 +1454,8 @@ static int start_port_read(struct usb_serial_port *port)
1400} 1454}
1401 1455
1402 1456
1403static struct whiteheat_urb_wrap *urb_to_wrap(struct urb* urb, struct list_head *head) 1457static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb,
1458 struct list_head *head)
1404{ 1459{
1405 struct whiteheat_urb_wrap *wrap; 1460 struct whiteheat_urb_wrap *wrap;
1406 struct list_head *tmp; 1461 struct list_head *tmp;
@@ -1426,7 +1481,7 @@ static void rx_data_softint(struct work_struct *work)
1426 struct whiteheat_private *info = 1481 struct whiteheat_private *info =
1427 container_of(work, struct whiteheat_private, rx_work); 1482 container_of(work, struct whiteheat_private, rx_work);
1428 struct usb_serial_port *port = info->port; 1483 struct usb_serial_port *port = info->port;
1429 struct tty_struct *tty = port->tty; 1484 struct tty_struct *tty = port->port.tty;
1430 struct whiteheat_urb_wrap *wrap; 1485 struct whiteheat_urb_wrap *wrap;
1431 struct urb *urb; 1486 struct urb *urb;
1432 unsigned long flags; 1487 unsigned long flags;
@@ -1449,7 +1504,8 @@ static void rx_data_softint(struct work_struct *work)
1449 urb = wrap->urb; 1504 urb = wrap->urb;
1450 1505
1451 if (tty && urb->actual_length) { 1506 if (tty && urb->actual_length) {
1452 int len = tty_buffer_request_room(tty, urb->actual_length); 1507 int len = tty_buffer_request_room(tty,
1508 urb->actual_length);
1453 /* This stuff can go away now I suspect */ 1509 /* This stuff can go away now I suspect */
1454 if (unlikely(len < urb->actual_length)) { 1510 if (unlikely(len < urb->actual_length)) {
1455 spin_lock_irqsave(&info->lock, flags); 1511 spin_lock_irqsave(&info->lock, flags);
@@ -1466,7 +1522,8 @@ static void rx_data_softint(struct work_struct *work)
1466 urb->dev = port->serial->dev; 1522 urb->dev = port->serial->dev;
1467 result = usb_submit_urb(urb, GFP_ATOMIC); 1523 result = usb_submit_urb(urb, GFP_ATOMIC);
1468 if (result) { 1524 if (result) {
1469 err("%s - failed resubmitting read urb, error %d", __func__, result); 1525 err("%s - failed resubmitting read urb, error %d",
1526 __func__, result);
1470 spin_lock_irqsave(&info->lock, flags); 1527 spin_lock_irqsave(&info->lock, flags);
1471 list_add(tmp, &info->rx_urbs_free); 1528 list_add(tmp, &info->rx_urbs_free);
1472 continue; 1529 continue;
@@ -1485,7 +1542,7 @@ static void rx_data_softint(struct work_struct *work)
1485/***************************************************************************** 1542/*****************************************************************************
1486 * Connect Tech's White Heat module functions 1543 * Connect Tech's White Heat module functions
1487 *****************************************************************************/ 1544 *****************************************************************************/
1488static int __init whiteheat_init (void) 1545static int __init whiteheat_init(void)
1489{ 1546{
1490 int retval; 1547 int retval;
1491 retval = usb_serial_register(&whiteheat_fake_device); 1548 retval = usb_serial_register(&whiteheat_fake_device);
@@ -1508,19 +1565,19 @@ failed_fake_register:
1508} 1565}
1509 1566
1510 1567
1511static void __exit whiteheat_exit (void) 1568static void __exit whiteheat_exit(void)
1512{ 1569{
1513 usb_deregister (&whiteheat_driver); 1570 usb_deregister(&whiteheat_driver);
1514 usb_serial_deregister (&whiteheat_fake_device); 1571 usb_serial_deregister(&whiteheat_fake_device);
1515 usb_serial_deregister (&whiteheat_device); 1572 usb_serial_deregister(&whiteheat_device);
1516} 1573}
1517 1574
1518 1575
1519module_init(whiteheat_init); 1576module_init(whiteheat_init);
1520module_exit(whiteheat_exit); 1577module_exit(whiteheat_exit);
1521 1578
1522MODULE_AUTHOR( DRIVER_AUTHOR ); 1579MODULE_AUTHOR(DRIVER_AUTHOR);
1523MODULE_DESCRIPTION( DRIVER_DESC ); 1580MODULE_DESCRIPTION(DRIVER_DESC);
1524MODULE_LICENSE("GPL"); 1581MODULE_LICENSE("GPL");
1525 1582
1526MODULE_FIRMWARE("whiteheat.fw"); 1583MODULE_FIRMWARE("whiteheat.fw");
diff --git a/drivers/usb/serial/whiteheat.h b/drivers/usb/serial/whiteheat.h
index f16079705664..38065df4d2d8 100644
--- a/drivers/usb/serial/whiteheat.h
+++ b/drivers/usb/serial/whiteheat.h
@@ -2,7 +2,7 @@
2 * USB ConnectTech WhiteHEAT driver 2 * USB ConnectTech WhiteHEAT driver
3 * 3 *
4 * Copyright (C) 2002 4 * Copyright (C) 2002
5 * Connect Tech Inc. 5 * Connect Tech Inc.
6 * 6 *
7 * Copyright (C) 1999, 2000 7 * Copyright (C) 1999, 2000
8 * Greg Kroah-Hartman (greg@kroah.com) 8 * Greg Kroah-Hartman (greg@kroah.com)
@@ -12,7 +12,8 @@
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver 15 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver
16 * 17 *
17 */ 18 */
18 19
@@ -30,13 +31,16 @@
30#define WHITEHEAT_DUMP 7 /* dump memory */ 31#define WHITEHEAT_DUMP 7 /* dump memory */
31#define WHITEHEAT_STATUS 8 /* get status */ 32#define WHITEHEAT_STATUS 8 /* get status */
32#define WHITEHEAT_PURGE 9 /* clear the UART fifos */ 33#define WHITEHEAT_PURGE 9 /* clear the UART fifos */
33#define WHITEHEAT_GET_DTR_RTS 10 /* get the state of DTR and RTS for a port */ 34#define WHITEHEAT_GET_DTR_RTS 10 /* get the state of DTR and RTS
34#define WHITEHEAT_GET_HW_INFO 11 /* get EEPROM info and hardware ID */ 35 for a port */
36#define WHITEHEAT_GET_HW_INFO 11 /* get EEPROM info and
37 hardware ID */
35#define WHITEHEAT_REPORT_TX_DONE 12 /* get the next TX done */ 38#define WHITEHEAT_REPORT_TX_DONE 12 /* get the next TX done */
36#define WHITEHEAT_EVENT 13 /* unsolicited status events */ 39#define WHITEHEAT_EVENT 13 /* unsolicited status events */
37#define WHITEHEAT_ECHO 14 /* send data to the indicated IN endpoint */ 40#define WHITEHEAT_ECHO 14 /* send data to the indicated
38#define WHITEHEAT_DO_TEST 15 /* perform the specified test */ 41 IN endpoint */
39#define WHITEHEAT_CMD_COMPLETE 16 /* reply for certain commands */ 42#define WHITEHEAT_DO_TEST 15 /* perform specified test */
43#define WHITEHEAT_CMD_COMPLETE 16 /* reply for some commands */
40#define WHITEHEAT_CMD_FAILURE 17 /* reply for failed commands */ 44#define WHITEHEAT_CMD_FAILURE 17 /* reply for failed commands */
41 45
42 46
@@ -67,20 +71,28 @@ struct whiteheat_simple {
67#define WHITEHEAT_PAR_MARK '1' /* mark (force 1) parity */ 71#define WHITEHEAT_PAR_MARK '1' /* mark (force 1) parity */
68 72
69#define WHITEHEAT_SFLOW_NONE 'n' /* no software flow control */ 73#define WHITEHEAT_SFLOW_NONE 'n' /* no software flow control */
70#define WHITEHEAT_SFLOW_RX 'r' /* XOFF/ON is sent when RX fills/empties */ 74#define WHITEHEAT_SFLOW_RX 'r' /* XOFF/ON is sent when RX
71#define WHITEHEAT_SFLOW_TX 't' /* when received XOFF/ON will stop/start TX */ 75 fills/empties */
76#define WHITEHEAT_SFLOW_TX 't' /* when received XOFF/ON will
77 stop/start TX */
72#define WHITEHEAT_SFLOW_RXTX 'b' /* both SFLOW_RX and SFLOW_TX */ 78#define WHITEHEAT_SFLOW_RXTX 'b' /* both SFLOW_RX and SFLOW_TX */
73 79
74#define WHITEHEAT_HFLOW_NONE 0x00 /* no hardware flow control */ 80#define WHITEHEAT_HFLOW_NONE 0x00 /* no hardware flow control */
75#define WHITEHEAT_HFLOW_RTS_TOGGLE 0x01 /* RTS is on during transmit, off otherwise */ 81#define WHITEHEAT_HFLOW_RTS_TOGGLE 0x01 /* RTS is on during transmit,
76#define WHITEHEAT_HFLOW_DTR 0x02 /* DTR is off/on when RX fills/empties */ 82 off otherwise */
77#define WHITEHEAT_HFLOW_CTS 0x08 /* when received CTS off/on will stop/start TX */ 83#define WHITEHEAT_HFLOW_DTR 0x02 /* DTR is off/on when RX
78#define WHITEHEAT_HFLOW_DSR 0x10 /* when received DSR off/on will stop/start TX */ 84 fills/empties */
79#define WHITEHEAT_HFLOW_RTS 0x80 /* RTS is off/on when RX fills/empties */ 85#define WHITEHEAT_HFLOW_CTS 0x08 /* when received CTS off/on
86 will stop/start TX */
87#define WHITEHEAT_HFLOW_DSR 0x10 /* when received DSR off/on
88 will stop/start TX */
89#define WHITEHEAT_HFLOW_RTS 0x80 /* RTS is off/on when RX
90 fills/empties */
80 91
81struct whiteheat_port_settings { 92struct whiteheat_port_settings {
82 __u8 port; /* port number (1 to N) */ 93 __u8 port; /* port number (1 to N) */
83 __u32 baud; /* any value 7 - 460800, firmware calculates best fit; arrives little endian */ 94 __u32 baud; /* any value 7 - 460800, firmware calculates
95 best fit; arrives little endian */
84 __u8 bits; /* 5, 6, 7, or 8 */ 96 __u8 bits; /* 5, 6, 7, or 8 */
85 __u8 stop; /* 1 or 2, default 1 (2 = 1.5 if bits = 5) */ 97 __u8 stop; /* 1 or 2, default 1 (2 = 1.5 if bits = 5) */
86 __u8 parity; /* see WHITEHEAT_PAR_* above */ 98 __u8 parity; /* see WHITEHEAT_PAR_* above */
@@ -167,12 +179,14 @@ struct whiteheat_echo {
167 */ 179 */
168#define WHITEHEAT_TEST_UART_RW 0x01 /* read/write uart registers */ 180#define WHITEHEAT_TEST_UART_RW 0x01 /* read/write uart registers */
169#define WHITEHEAT_TEST_UART_INTR 0x02 /* uart interrupt */ 181#define WHITEHEAT_TEST_UART_INTR 0x02 /* uart interrupt */
170#define WHITEHEAT_TEST_SETUP_CONT 0x03 /* setup for PORT_CONT/PORT_DISCONT */ 182#define WHITEHEAT_TEST_SETUP_CONT 0x03 /* setup for
183 PORT_CONT/PORT_DISCONT */
171#define WHITEHEAT_TEST_PORT_CONT 0x04 /* port connect */ 184#define WHITEHEAT_TEST_PORT_CONT 0x04 /* port connect */
172#define WHITEHEAT_TEST_PORT_DISCONT 0x05 /* port disconnect */ 185#define WHITEHEAT_TEST_PORT_DISCONT 0x05 /* port disconnect */
173#define WHITEHEAT_TEST_UART_CLK_START 0x06 /* uart clock test start */ 186#define WHITEHEAT_TEST_UART_CLK_START 0x06 /* uart clock test start */
174#define WHITEHEAT_TEST_UART_CLK_STOP 0x07 /* uart clock test stop */ 187#define WHITEHEAT_TEST_UART_CLK_STOP 0x07 /* uart clock test stop */
175#define WHITEHEAT_TEST_MODEM_FT 0x08 /* modem signals, requires a loopback cable/connector */ 188#define WHITEHEAT_TEST_MODEM_FT 0x08 /* modem signals, requires a
189 loopback cable/connector */
176#define WHITEHEAT_TEST_ERASE_EEPROM 0x09 /* erase eeprom */ 190#define WHITEHEAT_TEST_ERASE_EEPROM 0x09 /* erase eeprom */
177#define WHITEHEAT_TEST_READ_EEPROM 0x0a /* read eeprom */ 191#define WHITEHEAT_TEST_READ_EEPROM 0x0a /* read eeprom */
178#define WHITEHEAT_TEST_PROGRAM_EEPROM 0x0b /* program eeprom */ 192#define WHITEHEAT_TEST_PROGRAM_EEPROM 0x0b /* program eeprom */
@@ -198,19 +212,27 @@ struct whiteheat_test {
198#define WHITEHEAT_EVENT_CONNECT 0x08 /* connect field is valid */ 212#define WHITEHEAT_EVENT_CONNECT 0x08 /* connect field is valid */
199 213
200#define WHITEHEAT_FLOW_NONE 0x00 /* no flow control active */ 214#define WHITEHEAT_FLOW_NONE 0x00 /* no flow control active */
201#define WHITEHEAT_FLOW_HARD_OUT 0x01 /* TX is stopped by CTS (waiting for CTS to go on) */ 215#define WHITEHEAT_FLOW_HARD_OUT 0x01 /* TX is stopped by CTS
202#define WHITEHEAT_FLOW_HARD_IN 0x02 /* remote TX is stopped by RTS */ 216 (waiting for CTS to go on) */
203#define WHITEHEAT_FLOW_SOFT_OUT 0x04 /* TX is stopped by XOFF received (waiting for XON) */ 217#define WHITEHEAT_FLOW_HARD_IN 0x02 /* remote TX is stopped
204#define WHITEHEAT_FLOW_SOFT_IN 0x08 /* remote TX is stopped by XOFF transmitted */ 218 by RTS */
219#define WHITEHEAT_FLOW_SOFT_OUT 0x04 /* TX is stopped by XOFF
220 received (waiting for XON) */
221#define WHITEHEAT_FLOW_SOFT_IN 0x08 /* remote TX is stopped by XOFF
222 transmitted */
205#define WHITEHEAT_FLOW_TX_DONE 0x80 /* TX has completed */ 223#define WHITEHEAT_FLOW_TX_DONE 0x80 /* TX has completed */
206 224
207struct whiteheat_status_info { 225struct whiteheat_status_info {
208 __u8 port; /* port number (1 to N) */ 226 __u8 port; /* port number (1 to N) */
209 __u8 event; /* indicates what the current event is, see WHITEHEAT_EVENT_* above */ 227 __u8 event; /* indicates what the current event is,
210 __u8 modem; /* modem signal status (copy of uart's MSR register) */ 228 see WHITEHEAT_EVENT_* above */
229 __u8 modem; /* modem signal status (copy of uart's
230 MSR register) */
211 __u8 error; /* line status (copy of uart's LSR register) */ 231 __u8 error; /* line status (copy of uart's LSR register) */
212 __u8 flow; /* flow control state, see WHITEHEAT_FLOW_* above */ 232 __u8 flow; /* flow control state, see WHITEHEAT_FLOW_*
213 __u8 connect; /* 0 means not connected, non-zero means connected */ 233 above */
234 __u8 connect; /* 0 means not connected, non-zero means
235 connected */
214}; 236};
215 237
216 238
@@ -256,7 +278,8 @@ struct whiteheat_hw_info {
256struct whiteheat_event_info { 278struct whiteheat_event_info {
257 __u8 port; /* port number (1 to N) */ 279 __u8 port; /* port number (1 to N) */
258 __u8 event; /* see whiteheat_status_info.event */ 280 __u8 event; /* see whiteheat_status_info.event */
259 __u8 info; /* see whiteheat_status_info.modem, .error, .flow, .connect */ 281 __u8 info; /* see whiteheat_status_info.modem, .error,
282 .flow, .connect */
260}; 283};
261 284
262 285
@@ -269,7 +292,8 @@ struct whiteheat_event_info {
269 292
270struct whiteheat_test_info { 293struct whiteheat_test_info {
271 __u8 port; /* port number (1 to N) */ 294 __u8 port; /* port number (1 to N) */
272 __u8 test; /* indicates which test this is a response for, see WHITEHEAT_DO_TEST above */ 295 __u8 test; /* indicates which test this is a response for,
296 see WHITEHEAT_DO_TEST above */
273 __u8 status; /* see WHITEHEAT_TEST_* above */ 297 __u8 status; /* see WHITEHEAT_TEST_* above */
274 __u8 results[32]; /* test-dependent results */ 298 __u8 results[32]; /* test-dependent results */
275}; 299};
diff --git a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c
index 579e9f52053a..17f1ae232919 100644
--- a/drivers/usb/storage/datafab.c
+++ b/drivers/usb/storage/datafab.c
@@ -1,7 +1,5 @@
1/* Driver for Datafab USB Compact Flash reader 1/* Driver for Datafab USB Compact Flash reader
2 * 2 *
3 * $Id: datafab.c,v 1.7 2002/02/25 00:40:13 mdharm Exp $
4 *
5 * datafab driver v0.1: 3 * datafab driver v0.1:
6 * 4 *
7 * First release 5 * First release
diff --git a/drivers/usb/storage/debug.c b/drivers/usb/storage/debug.c
index 01e430654a13..a2b5526c9fa0 100644
--- a/drivers/usb/storage/debug.c
+++ b/drivers/usb/storage/debug.c
@@ -1,8 +1,6 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * Debugging Functions Source Code File 2 * Debugging Functions Source Code File
3 * 3 *
4 * $Id: debug.c,v 1.9 2002/04/22 03:39:43 mdharm Exp $
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 5 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 * 6 *
diff --git a/drivers/usb/storage/debug.h b/drivers/usb/storage/debug.h
index 77e244a8c376..dbb985d52423 100644
--- a/drivers/usb/storage/debug.h
+++ b/drivers/usb/storage/debug.h
@@ -1,8 +1,6 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * Debugging Functions Header File 2 * Debugging Functions Header File
3 * 3 *
4 * $Id: debug.h,v 1.6 2001/01/12 23:51:04 mdharm Exp $
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 5 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 * 6 *
diff --git a/drivers/usb/storage/dpcm.c b/drivers/usb/storage/dpcm.c
index 9a410b5a6e5b..939923471af4 100644
--- a/drivers/usb/storage/dpcm.c
+++ b/drivers/usb/storage/dpcm.c
@@ -1,7 +1,5 @@
1/* Driver for Microtech DPCM-USB CompactFlash/SmartMedia reader 1/* Driver for Microtech DPCM-USB CompactFlash/SmartMedia reader
2 * 2 *
3 * $Id: dpcm.c,v 1.4 2001/06/11 02:54:25 mdharm Exp $
4 *
5 * DPCM driver v0.1: 3 * DPCM driver v0.1:
6 * 4 *
7 * First release 5 * First release
diff --git a/drivers/usb/storage/dpcm.h b/drivers/usb/storage/dpcm.h
index 81b464cfcc1e..e7b7b0f120d7 100644
--- a/drivers/usb/storage/dpcm.h
+++ b/drivers/usb/storage/dpcm.h
@@ -1,7 +1,5 @@
1/* Driver for Microtech DPCM-USB CompactFlash/SmartMedia reader 1/* Driver for Microtech DPCM-USB CompactFlash/SmartMedia reader
2 * 2 *
3 * $Id: dpcm.h,v 1.2 2000/08/25 00:13:51 mdharm Exp $
4 *
5 * DPCM driver v0.1: 3 * DPCM driver v0.1:
6 * 4 *
7 * First release 5 * First release
diff --git a/drivers/usb/storage/freecom.c b/drivers/usb/storage/freecom.c
index f5a4e8d6a3b1..7a4d45677227 100644
--- a/drivers/usb/storage/freecom.c
+++ b/drivers/usb/storage/freecom.c
@@ -1,7 +1,5 @@
1/* Driver for Freecom USB/IDE adaptor 1/* Driver for Freecom USB/IDE adaptor
2 * 2 *
3 * $Id: freecom.c,v 1.22 2002/04/22 03:39:43 mdharm Exp $
4 *
5 * Freecom v0.1: 3 * Freecom v0.1:
6 * 4 *
7 * First release 5 * First release
diff --git a/drivers/usb/storage/freecom.h b/drivers/usb/storage/freecom.h
index 1b012d62d0a8..20d0fe6ba0c8 100644
--- a/drivers/usb/storage/freecom.h
+++ b/drivers/usb/storage/freecom.h
@@ -1,7 +1,5 @@
1/* Driver for Freecom USB/IDE adaptor 1/* Driver for Freecom USB/IDE adaptor
2 * 2 *
3 * $Id: freecom.h,v 1.4 2000/08/29 14:49:15 dlbrown Exp $
4 *
5 * Freecom v0.1: 3 * Freecom v0.1:
6 * 4 *
7 * First release 5 * First release
diff --git a/drivers/usb/storage/initializers.c b/drivers/usb/storage/initializers.c
index 187dd1e01093..4995bb595aef 100644
--- a/drivers/usb/storage/initializers.c
+++ b/drivers/usb/storage/initializers.c
@@ -1,7 +1,5 @@
1/* Special Initializers for certain USB Mass Storage devices 1/* Special Initializers for certain USB Mass Storage devices
2 * 2 *
3 * $Id: initializers.c,v 1.2 2000/09/06 22:35:57 mdharm Exp $
4 *
5 * Current development and maintenance by: 3 * Current development and maintenance by:
6 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 4 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
7 * 5 *
diff --git a/drivers/usb/storage/initializers.h b/drivers/usb/storage/initializers.h
index ad3ffd4236c2..529327fbb06b 100644
--- a/drivers/usb/storage/initializers.h
+++ b/drivers/usb/storage/initializers.h
@@ -1,7 +1,5 @@
1/* Header file for Special Initializers for certain USB Mass Storage devices 1/* Header file for Special Initializers for certain USB Mass Storage devices
2 * 2 *
3 * $Id: initializers.h,v 1.1 2000/08/29 23:07:02 mdharm Exp $
4 *
5 * Current development and maintenance by: 3 * Current development and maintenance by:
6 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 4 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
7 * 5 *
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index 3addcd8f827b..383abf2516a5 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -1,7 +1,5 @@
1/* Transport & Protocol Driver for In-System Design, Inc. ISD200 ASIC 1/* Transport & Protocol Driver for In-System Design, Inc. ISD200 ASIC
2 * 2 *
3 * $Id: isd200.c,v 1.16 2002/04/22 03:39:43 mdharm Exp $
4 *
5 * Current development and maintenance: 3 * Current development and maintenance:
6 * (C) 2001-2002 Björn Stenberg (bjorn@haxx.se) 4 * (C) 2001-2002 Björn Stenberg (bjorn@haxx.se)
7 * 5 *
@@ -586,7 +584,7 @@ static void isd200_invoke_transport( struct us_data *us,
586 /* if the command gets aborted by the higher layers, we need to 584 /* if the command gets aborted by the higher layers, we need to
587 * short-circuit all other processing 585 * short-circuit all other processing
588 */ 586 */
589 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 587 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
590 US_DEBUGP("-- command was aborted\n"); 588 US_DEBUGP("-- command was aborted\n");
591 goto Handle_Abort; 589 goto Handle_Abort;
592 } 590 }
@@ -633,7 +631,7 @@ static void isd200_invoke_transport( struct us_data *us,
633 631
634 if (need_auto_sense) { 632 if (need_auto_sense) {
635 result = isd200_read_regs(us); 633 result = isd200_read_regs(us);
636 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 634 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
637 US_DEBUGP("-- auto-sense aborted\n"); 635 US_DEBUGP("-- auto-sense aborted\n");
638 goto Handle_Abort; 636 goto Handle_Abort;
639 } 637 }
@@ -663,7 +661,7 @@ static void isd200_invoke_transport( struct us_data *us,
663 srb->result = DID_ABORT << 16; 661 srb->result = DID_ABORT << 16;
664 662
665 /* permit the reset transfer to take place */ 663 /* permit the reset transfer to take place */
666 clear_bit(US_FLIDX_ABORTING, &us->flags); 664 clear_bit(US_FLIDX_ABORTING, &us->dflags);
667 /* Need reset here */ 665 /* Need reset here */
668} 666}
669 667
diff --git a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c
index 61097cbb1585..df67f13c9e73 100644
--- a/drivers/usb/storage/jumpshot.c
+++ b/drivers/usb/storage/jumpshot.c
@@ -1,7 +1,5 @@
1/* Driver for Lexar "Jumpshot" Compact Flash reader 1/* Driver for Lexar "Jumpshot" Compact Flash reader
2 * 2 *
3 * $Id: jumpshot.c,v 1.7 2002/02/25 00:40:13 mdharm Exp $
4 *
5 * jumpshot driver v0.1: 3 * jumpshot driver v0.1:
6 * 4 *
7 * First release 5 * First release
diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c
index b9b8ede61fb3..3b3357e20ea7 100644
--- a/drivers/usb/storage/protocol.c
+++ b/drivers/usb/storage/protocol.c
@@ -1,7 +1,5 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * 2 *
3 * $Id: protocol.c,v 1.14 2002/04/22 03:39:43 mdharm Exp $
4 *
5 * Current development and maintenance by: 3 * Current development and maintenance by:
6 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 4 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
7 * 5 *
diff --git a/drivers/usb/storage/protocol.h b/drivers/usb/storage/protocol.h
index 8737a36891ca..487056ffb516 100644
--- a/drivers/usb/storage/protocol.h
+++ b/drivers/usb/storage/protocol.h
@@ -1,8 +1,6 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * Protocol Functions Header File 2 * Protocol Functions Header File
3 * 3 *
4 * $Id: protocol.h,v 1.4 2001/02/13 07:10:03 mdharm Exp $
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 5 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 * 6 *
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 3fcde9f0fa5f..09779f6a8179 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -1,8 +1,6 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * SCSI layer glue code 2 * SCSI layer glue code
3 * 3 *
4 * $Id: scsiglue.c,v 1.26 2002/04/22 03:39:43 mdharm Exp $
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 5 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 * 6 *
@@ -73,7 +71,6 @@ static const char* host_info(struct Scsi_Host *host)
73static int slave_alloc (struct scsi_device *sdev) 71static int slave_alloc (struct scsi_device *sdev)
74{ 72{
75 struct us_data *us = host_to_us(sdev->host); 73 struct us_data *us = host_to_us(sdev->host);
76 struct usb_host_endpoint *bulk_in_ep;
77 74
78 /* 75 /*
79 * Set the INQUIRY transfer length to 36. We don't use any of 76 * Set the INQUIRY transfer length to 36. We don't use any of
@@ -82,16 +79,22 @@ static int slave_alloc (struct scsi_device *sdev)
82 */ 79 */
83 sdev->inquiry_len = 36; 80 sdev->inquiry_len = 36;
84 81
85 /* Scatter-gather buffers (all but the last) must have a length 82 /* USB has unusual DMA-alignment requirements: Although the
86 * divisible by the bulk maxpacket size. Otherwise a data packet 83 * starting address of each scatter-gather element doesn't matter,
87 * would end up being short, causing a premature end to the data 84 * the length of each element except the last must be divisible
88 * transfer. We'll use the maxpacket value of the bulk-IN pipe 85 * by the Bulk maxpacket value. There's currently no way to
89 * to set the SCSI device queue's DMA alignment mask. 86 * express this by block-layer constraints, so we'll cop out
87 * and simply require addresses to be aligned at 512-byte
88 * boundaries. This is okay since most block I/O involves
89 * hardware sectors that are multiples of 512 bytes in length,
90 * and since host controllers up through USB 2.0 have maxpacket
91 * values no larger than 512.
92 *
93 * But it doesn't suffice for Wireless USB, where Bulk maxpacket
94 * values can be as large as 2048. To make that work properly
95 * will require changes to the block layer.
90 */ 96 */
91 bulk_in_ep = us->pusb_dev->ep_in[usb_pipeendpoint(us->recv_bulk_pipe)]; 97 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
92 blk_queue_update_dma_alignment(sdev->request_queue,
93 le16_to_cpu(bulk_in_ep->desc.wMaxPacketSize) - 1);
94 /* wMaxPacketSize must be a power of 2 */
95 98
96 /* 99 /*
97 * The UFI spec treates the Peripheral Qualifier bits in an 100 * The UFI spec treates the Peripheral Qualifier bits in an
@@ -116,10 +119,10 @@ static int slave_configure(struct scsi_device *sdev)
116 * while others have trouble with more than 64K. At this time we 119 * while others have trouble with more than 64K. At this time we
117 * are limiting both to 32K (64 sectores). 120 * are limiting both to 32K (64 sectores).
118 */ 121 */
119 if (us->flags & (US_FL_MAX_SECTORS_64 | US_FL_MAX_SECTORS_MIN)) { 122 if (us->fflags & (US_FL_MAX_SECTORS_64 | US_FL_MAX_SECTORS_MIN)) {
120 unsigned int max_sectors = 64; 123 unsigned int max_sectors = 64;
121 124
122 if (us->flags & US_FL_MAX_SECTORS_MIN) 125 if (us->fflags & US_FL_MAX_SECTORS_MIN)
123 max_sectors = PAGE_CACHE_SIZE >> 9; 126 max_sectors = PAGE_CACHE_SIZE >> 9;
124 if (sdev->request_queue->max_sectors > max_sectors) 127 if (sdev->request_queue->max_sectors > max_sectors)
125 blk_queue_max_sectors(sdev->request_queue, 128 blk_queue_max_sectors(sdev->request_queue,
@@ -148,7 +151,7 @@ static int slave_configure(struct scsi_device *sdev)
148 * majority of devices work fine, but a few still can't 151 * majority of devices work fine, but a few still can't
149 * handle it. The sd driver will simply assume those 152 * handle it. The sd driver will simply assume those
150 * devices are write-enabled. */ 153 * devices are write-enabled. */
151 if (us->flags & US_FL_NO_WP_DETECT) 154 if (us->fflags & US_FL_NO_WP_DETECT)
152 sdev->skip_ms_page_3f = 1; 155 sdev->skip_ms_page_3f = 1;
153 156
154 /* A number of devices have problems with MODE SENSE for 157 /* A number of devices have problems with MODE SENSE for
@@ -158,13 +161,13 @@ static int slave_configure(struct scsi_device *sdev)
158 /* Some disks return the total number of blocks in response 161 /* Some disks return the total number of blocks in response
159 * to READ CAPACITY rather than the highest block number. 162 * to READ CAPACITY rather than the highest block number.
160 * If this device makes that mistake, tell the sd driver. */ 163 * If this device makes that mistake, tell the sd driver. */
161 if (us->flags & US_FL_FIX_CAPACITY) 164 if (us->fflags & US_FL_FIX_CAPACITY)
162 sdev->fix_capacity = 1; 165 sdev->fix_capacity = 1;
163 166
164 /* A few disks have two indistinguishable version, one of 167 /* A few disks have two indistinguishable version, one of
165 * which reports the correct capacity and the other does not. 168 * which reports the correct capacity and the other does not.
166 * The sd driver has to guess which is the case. */ 169 * The sd driver has to guess which is the case. */
167 if (us->flags & US_FL_CAPACITY_HEURISTICS) 170 if (us->fflags & US_FL_CAPACITY_HEURISTICS)
168 sdev->guess_capacity = 1; 171 sdev->guess_capacity = 1;
169 172
170 /* Some devices report a SCSI revision level above 2 but are 173 /* Some devices report a SCSI revision level above 2 but are
@@ -213,7 +216,7 @@ static int slave_configure(struct scsi_device *sdev)
213 216
214 /* Some devices choke when they receive a PREVENT-ALLOW MEDIUM 217 /* Some devices choke when they receive a PREVENT-ALLOW MEDIUM
215 * REMOVAL command, so suppress those commands. */ 218 * REMOVAL command, so suppress those commands. */
216 if (us->flags & US_FL_NOT_LOCKABLE) 219 if (us->fflags & US_FL_NOT_LOCKABLE)
217 sdev->lockable = 0; 220 sdev->lockable = 0;
218 221
219 /* this is to satisfy the compiler, tho I don't think the 222 /* this is to satisfy the compiler, tho I don't think the
@@ -238,7 +241,7 @@ static int queuecommand(struct scsi_cmnd *srb,
238 } 241 }
239 242
240 /* fail the command if we are disconnecting */ 243 /* fail the command if we are disconnecting */
241 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 244 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
242 US_DEBUGP("Fail command during disconnect\n"); 245 US_DEBUGP("Fail command during disconnect\n");
243 srb->result = DID_NO_CONNECT << 16; 246 srb->result = DID_NO_CONNECT << 16;
244 done(srb); 247 done(srb);
@@ -248,7 +251,7 @@ static int queuecommand(struct scsi_cmnd *srb,
248 /* enqueue the command and wake up the control thread */ 251 /* enqueue the command and wake up the control thread */
249 srb->scsi_done = done; 252 srb->scsi_done = done;
250 us->srb = srb; 253 us->srb = srb;
251 up(&(us->sema)); 254 complete(&us->cmnd_ready);
252 255
253 return 0; 256 return 0;
254} 257}
@@ -280,9 +283,9 @@ static int command_abort(struct scsi_cmnd *srb)
280 * with the reset). Note that we must retain the host lock while 283 * with the reset). Note that we must retain the host lock while
281 * calling usb_stor_stop_transport(); otherwise it might interfere 284 * calling usb_stor_stop_transport(); otherwise it might interfere
282 * with an auto-reset that begins as soon as we release the lock. */ 285 * with an auto-reset that begins as soon as we release the lock. */
283 set_bit(US_FLIDX_TIMED_OUT, &us->flags); 286 set_bit(US_FLIDX_TIMED_OUT, &us->dflags);
284 if (!test_bit(US_FLIDX_RESETTING, &us->flags)) { 287 if (!test_bit(US_FLIDX_RESETTING, &us->dflags)) {
285 set_bit(US_FLIDX_ABORTING, &us->flags); 288 set_bit(US_FLIDX_ABORTING, &us->dflags);
286 usb_stor_stop_transport(us); 289 usb_stor_stop_transport(us);
287 } 290 }
288 scsi_unlock(us_to_host(us)); 291 scsi_unlock(us_to_host(us));
@@ -329,7 +332,7 @@ void usb_stor_report_device_reset(struct us_data *us)
329 struct Scsi_Host *host = us_to_host(us); 332 struct Scsi_Host *host = us_to_host(us);
330 333
331 scsi_report_device_reset(host, 0, 0); 334 scsi_report_device_reset(host, 0, 0);
332 if (us->flags & US_FL_SCM_MULT_TARG) { 335 if (us->fflags & US_FL_SCM_MULT_TARG) {
333 for (i = 1; i < host->max_id; ++i) 336 for (i = 1; i < host->max_id; ++i)
334 scsi_report_device_reset(host, 0, i); 337 scsi_report_device_reset(host, 0, i);
335 } 338 }
@@ -400,7 +403,7 @@ static int proc_info (struct Scsi_Host *host, char *buffer,
400 pos += sprintf(pos, " Quirks:"); 403 pos += sprintf(pos, " Quirks:");
401 404
402#define US_FLAG(name, value) \ 405#define US_FLAG(name, value) \
403 if (us->flags & value) pos += sprintf(pos, " " #name); 406 if (us->fflags & value) pos += sprintf(pos, " " #name);
404US_DO_ALL_FLAGS 407US_DO_ALL_FLAGS
405#undef US_FLAG 408#undef US_FLAG
406 409
diff --git a/drivers/usb/storage/scsiglue.h b/drivers/usb/storage/scsiglue.h
index 737e4fa6045f..ffa1cca93d2c 100644
--- a/drivers/usb/storage/scsiglue.h
+++ b/drivers/usb/storage/scsiglue.h
@@ -1,8 +1,6 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * SCSI Connecting Glue Header File 2 * SCSI Connecting Glue Header File
3 * 3 *
4 * $Id: scsiglue.h,v 1.4 2000/08/25 00:13:51 mdharm Exp $
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 5 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 * 6 *
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c
index 8972b17da843..c5a54b872c24 100644
--- a/drivers/usb/storage/sddr09.c
+++ b/drivers/usb/storage/sddr09.c
@@ -1,6 +1,5 @@
1/* Driver for SanDisk SDDR-09 SmartMedia reader 1/* Driver for SanDisk SDDR-09 SmartMedia reader
2 * 2 *
3 * $Id: sddr09.c,v 1.24 2002/04/22 03:39:43 mdharm Exp $
4 * (c) 2000, 2001 Robert Baruch (autophile@starband.net) 3 * (c) 2000, 2001 Robert Baruch (autophile@starband.net)
5 * (c) 2002 Andries Brouwer (aeb@cwi.nl) 4 * (c) 2002 Andries Brouwer (aeb@cwi.nl)
6 * Developed with the assistance of: 5 * Developed with the assistance of:
diff --git a/drivers/usb/storage/sddr09.h b/drivers/usb/storage/sddr09.h
index c03089a9ec38..e50033ad7b19 100644
--- a/drivers/usb/storage/sddr09.h
+++ b/drivers/usb/storage/sddr09.h
@@ -1,8 +1,6 @@
1/* Driver for SanDisk SDDR-09 SmartMedia reader 1/* Driver for SanDisk SDDR-09 SmartMedia reader
2 * Header File 2 * Header File
3 * 3 *
4 * $Id: sddr09.h,v 1.5 2000/08/25 00:13:51 mdharm Exp $
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 2000 Robert Baruch (autophile@dol.net) 5 * (c) 2000 Robert Baruch (autophile@dol.net)
8 * (c) 2002 Andries Brouwer (aeb@cwi.nl) 6 * (c) 2002 Andries Brouwer (aeb@cwi.nl)
diff --git a/drivers/usb/storage/sddr55.c b/drivers/usb/storage/sddr55.c
index 6d14327c921d..0d8df7577899 100644
--- a/drivers/usb/storage/sddr55.c
+++ b/drivers/usb/storage/sddr55.c
@@ -1,7 +1,5 @@
1/* Driver for SanDisk SDDR-55 SmartMedia reader 1/* Driver for SanDisk SDDR-55 SmartMedia reader
2 * 2 *
3 * $Id:$
4 *
5 * SDDR55 driver v0.1: 3 * SDDR55 driver v0.1:
6 * 4 *
7 * First release 5 * First release
diff --git a/drivers/usb/storage/sddr55.h b/drivers/usb/storage/sddr55.h
index d6bd32f6c9f3..a815a0470c84 100644
--- a/drivers/usb/storage/sddr55.h
+++ b/drivers/usb/storage/sddr55.h
@@ -1,8 +1,6 @@
1/* Driver for SanDisk SDDR-55 SmartMedia reader 1/* Driver for SanDisk SDDR-55 SmartMedia reader
2 * Header File 2 * Header File
3 * 3 *
4 * $Id:$
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 2002 Simon Munton 5 * (c) 2002 Simon Munton
8 * 6 *
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index 570c1250f6f3..ae6d64810d2a 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -1,7 +1,5 @@
1/* Driver for SCM Microsystems (a.k.a. Shuttle) USB-ATAPI cable 1/* Driver for SCM Microsystems (a.k.a. Shuttle) USB-ATAPI cable
2 * 2 *
3 * $Id: shuttle_usbat.c,v 1.17 2002/04/22 03:39:43 mdharm Exp $
4 *
5 * Current development and maintenance by: 3 * Current development and maintenance by:
6 * (c) 2000, 2001 Robert Baruch (autophile@starband.net) 4 * (c) 2000, 2001 Robert Baruch (autophile@starband.net)
7 * (c) 2004, 2005 Daniel Drake <dsd@gentoo.org> 5 * (c) 2004, 2005 Daniel Drake <dsd@gentoo.org>
diff --git a/drivers/usb/storage/shuttle_usbat.h b/drivers/usb/storage/shuttle_usbat.h
index 3ddf143a1dec..d8bfc43e9044 100644
--- a/drivers/usb/storage/shuttle_usbat.h
+++ b/drivers/usb/storage/shuttle_usbat.h
@@ -1,8 +1,6 @@
1/* Driver for SCM Microsystems USB-ATAPI cable 1/* Driver for SCM Microsystems USB-ATAPI cable
2 * Header File 2 * Header File
3 * 3 *
4 * $Id: shuttle_usbat.h,v 1.5 2000/09/17 14:44:52 groovyjava Exp $
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 2000 Robert Baruch (autophile@dol.net) 5 * (c) 2000 Robert Baruch (autophile@dol.net)
8 * (c) 2004, 2005 Daniel Drake <dsd@gentoo.org> 6 * (c) 2004, 2005 Daniel Drake <dsd@gentoo.org>
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 6610d2dd1e7f..fcbbfdb7b2b0 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -1,7 +1,5 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * 2 *
3 * $Id: transport.c,v 1.47 2002/04/22 03:39:43 mdharm Exp $
4 *
5 * Current development and maintenance by: 3 * Current development and maintenance by:
6 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 4 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
7 * 5 *
@@ -75,14 +73,14 @@
75 * by a separate code path.) 73 * by a separate code path.)
76 * 74 *
77 * The abort function (usb_storage_command_abort() in scsiglue.c) first 75 * The abort function (usb_storage_command_abort() in scsiglue.c) first
78 * sets the machine state and the ABORTING bit in us->flags to prevent 76 * sets the machine state and the ABORTING bit in us->dflags to prevent
79 * new URBs from being submitted. It then calls usb_stor_stop_transport() 77 * new URBs from being submitted. It then calls usb_stor_stop_transport()
80 * below, which atomically tests-and-clears the URB_ACTIVE bit in us->flags 78 * below, which atomically tests-and-clears the URB_ACTIVE bit in us->dflags
81 * to see if the current_urb needs to be stopped. Likewise, the SG_ACTIVE 79 * to see if the current_urb needs to be stopped. Likewise, the SG_ACTIVE
82 * bit is tested to see if the current_sg scatter-gather request needs to be 80 * bit is tested to see if the current_sg scatter-gather request needs to be
83 * stopped. The timeout callback routine does much the same thing. 81 * stopped. The timeout callback routine does much the same thing.
84 * 82 *
85 * When a disconnect occurs, the DISCONNECTING bit in us->flags is set to 83 * When a disconnect occurs, the DISCONNECTING bit in us->dflags is set to
86 * prevent new URBs from being submitted, and usb_stor_stop_transport() is 84 * prevent new URBs from being submitted, and usb_stor_stop_transport() is
87 * called to stop any ongoing requests. 85 * called to stop any ongoing requests.
88 * 86 *
@@ -127,8 +125,8 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
127 long timeleft; 125 long timeleft;
128 int status; 126 int status;
129 127
130 /* don't submit URBs during abort/disconnect processing */ 128 /* don't submit URBs during abort processing */
131 if (us->flags & ABORTING_OR_DISCONNECTING) 129 if (test_bit(US_FLIDX_ABORTING, &us->dflags))
132 return -EIO; 130 return -EIO;
133 131
134 /* set up data structures for the wakeup system */ 132 /* set up data structures for the wakeup system */
@@ -159,13 +157,13 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
159 157
160 /* since the URB has been submitted successfully, it's now okay 158 /* since the URB has been submitted successfully, it's now okay
161 * to cancel it */ 159 * to cancel it */
162 set_bit(US_FLIDX_URB_ACTIVE, &us->flags); 160 set_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
163 161
164 /* did an abort/disconnect occur during the submission? */ 162 /* did an abort occur during the submission? */
165 if (us->flags & ABORTING_OR_DISCONNECTING) { 163 if (test_bit(US_FLIDX_ABORTING, &us->dflags)) {
166 164
167 /* cancel the URB, if it hasn't been cancelled already */ 165 /* cancel the URB, if it hasn't been cancelled already */
168 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->flags)) { 166 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
169 US_DEBUGP("-- cancelling URB\n"); 167 US_DEBUGP("-- cancelling URB\n");
170 usb_unlink_urb(us->current_urb); 168 usb_unlink_urb(us->current_urb);
171 } 169 }
@@ -175,7 +173,7 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
175 timeleft = wait_for_completion_interruptible_timeout( 173 timeleft = wait_for_completion_interruptible_timeout(
176 &urb_done, timeout ? : MAX_SCHEDULE_TIMEOUT); 174 &urb_done, timeout ? : MAX_SCHEDULE_TIMEOUT);
177 175
178 clear_bit(US_FLIDX_URB_ACTIVE, &us->flags); 176 clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
179 177
180 if (timeleft <= 0) { 178 if (timeleft <= 0) {
181 US_DEBUGP("%s -- cancelling URB\n", 179 US_DEBUGP("%s -- cancelling URB\n",
@@ -419,8 +417,8 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
419{ 417{
420 int result; 418 int result;
421 419
422 /* don't submit s-g requests during abort/disconnect processing */ 420 /* don't submit s-g requests during abort processing */
423 if (us->flags & ABORTING_OR_DISCONNECTING) 421 if (test_bit(US_FLIDX_ABORTING, &us->dflags))
424 return USB_STOR_XFER_ERROR; 422 return USB_STOR_XFER_ERROR;
425 423
426 /* initialize the scatter-gather request block */ 424 /* initialize the scatter-gather request block */
@@ -435,13 +433,13 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
435 433
436 /* since the block has been initialized successfully, it's now 434 /* since the block has been initialized successfully, it's now
437 * okay to cancel it */ 435 * okay to cancel it */
438 set_bit(US_FLIDX_SG_ACTIVE, &us->flags); 436 set_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
439 437
440 /* did an abort/disconnect occur during the submission? */ 438 /* did an abort occur during the submission? */
441 if (us->flags & ABORTING_OR_DISCONNECTING) { 439 if (test_bit(US_FLIDX_ABORTING, &us->dflags)) {
442 440
443 /* cancel the request, if it hasn't been cancelled already */ 441 /* cancel the request, if it hasn't been cancelled already */
444 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->flags)) { 442 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
445 US_DEBUGP("-- cancelling sg request\n"); 443 US_DEBUGP("-- cancelling sg request\n");
446 usb_sg_cancel(&us->current_sg); 444 usb_sg_cancel(&us->current_sg);
447 } 445 }
@@ -449,7 +447,7 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
449 447
450 /* wait for the completion of the transfer */ 448 /* wait for the completion of the transfer */
451 usb_sg_wait(&us->current_sg); 449 usb_sg_wait(&us->current_sg);
452 clear_bit(US_FLIDX_SG_ACTIVE, &us->flags); 450 clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
453 451
454 result = us->current_sg.status; 452 result = us->current_sg.status;
455 if (act_len) 453 if (act_len)
@@ -530,7 +528,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
530 /* if the command gets aborted by the higher layers, we need to 528 /* if the command gets aborted by the higher layers, we need to
531 * short-circuit all other processing 529 * short-circuit all other processing
532 */ 530 */
533 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 531 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
534 US_DEBUGP("-- command was aborted\n"); 532 US_DEBUGP("-- command was aborted\n");
535 srb->result = DID_ABORT << 16; 533 srb->result = DID_ABORT << 16;
536 goto Handle_Errors; 534 goto Handle_Errors;
@@ -616,7 +614,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
616 /* let's clean up right away */ 614 /* let's clean up right away */
617 scsi_eh_restore_cmnd(srb, &ses); 615 scsi_eh_restore_cmnd(srb, &ses);
618 616
619 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 617 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
620 US_DEBUGP("-- auto-sense aborted\n"); 618 US_DEBUGP("-- auto-sense aborted\n");
621 srb->result = DID_ABORT << 16; 619 srb->result = DID_ABORT << 16;
622 goto Handle_Errors; 620 goto Handle_Errors;
@@ -629,7 +627,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
629 * auto-sense is perfectly valid 627 * auto-sense is perfectly valid
630 */ 628 */
631 srb->result = DID_ERROR << 16; 629 srb->result = DID_ERROR << 16;
632 if (!(us->flags & US_FL_SCM_MULT_TARG)) 630 if (!(us->fflags & US_FL_SCM_MULT_TARG))
633 goto Handle_Errors; 631 goto Handle_Errors;
634 return; 632 return;
635 } 633 }
@@ -679,8 +677,8 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
679 /* Set the RESETTING bit, and clear the ABORTING bit so that 677 /* Set the RESETTING bit, and clear the ABORTING bit so that
680 * the reset may proceed. */ 678 * the reset may proceed. */
681 scsi_lock(us_to_host(us)); 679 scsi_lock(us_to_host(us));
682 set_bit(US_FLIDX_RESETTING, &us->flags); 680 set_bit(US_FLIDX_RESETTING, &us->dflags);
683 clear_bit(US_FLIDX_ABORTING, &us->flags); 681 clear_bit(US_FLIDX_ABORTING, &us->dflags);
684 scsi_unlock(us_to_host(us)); 682 scsi_unlock(us_to_host(us));
685 683
686 /* We must release the device lock because the pre_reset routine 684 /* We must release the device lock because the pre_reset routine
@@ -695,7 +693,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
695 scsi_unlock(us_to_host(us)); 693 scsi_unlock(us_to_host(us));
696 us->transport_reset(us); 694 us->transport_reset(us);
697 } 695 }
698 clear_bit(US_FLIDX_RESETTING, &us->flags); 696 clear_bit(US_FLIDX_RESETTING, &us->dflags);
699} 697}
700 698
701/* Stop the current URB transfer */ 699/* Stop the current URB transfer */
@@ -707,13 +705,13 @@ void usb_stor_stop_transport(struct us_data *us)
707 * let's wake it up. The test_and_clear_bit() call 705 * let's wake it up. The test_and_clear_bit() call
708 * guarantees that if a URB has just been submitted, 706 * guarantees that if a URB has just been submitted,
709 * it won't be cancelled more than once. */ 707 * it won't be cancelled more than once. */
710 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->flags)) { 708 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
711 US_DEBUGP("-- cancelling URB\n"); 709 US_DEBUGP("-- cancelling URB\n");
712 usb_unlink_urb(us->current_urb); 710 usb_unlink_urb(us->current_urb);
713 } 711 }
714 712
715 /* If we are waiting for a scatter-gather operation, cancel it. */ 713 /* If we are waiting for a scatter-gather operation, cancel it. */
716 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->flags)) { 714 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
717 US_DEBUGP("-- cancelling sg request\n"); 715 US_DEBUGP("-- cancelling sg request\n");
718 usb_sg_cancel(&us->current_sg); 716 usb_sg_cancel(&us->current_sg);
719 } 717 }
@@ -914,7 +912,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
914 unsigned int cbwlen = US_BULK_CB_WRAP_LEN; 912 unsigned int cbwlen = US_BULK_CB_WRAP_LEN;
915 913
916 /* Take care of BULK32 devices; set extra byte to 0 */ 914 /* Take care of BULK32 devices; set extra byte to 0 */
917 if ( unlikely(us->flags & US_FL_BULK32)) { 915 if (unlikely(us->fflags & US_FL_BULK32)) {
918 cbwlen = 32; 916 cbwlen = 32;
919 us->iobuf[31] = 0; 917 us->iobuf[31] = 0;
920 } 918 }
@@ -925,7 +923,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
925 bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ? 1 << 7 : 0; 923 bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ? 1 << 7 : 0;
926 bcb->Tag = ++us->tag; 924 bcb->Tag = ++us->tag;
927 bcb->Lun = srb->device->lun; 925 bcb->Lun = srb->device->lun;
928 if (us->flags & US_FL_SCM_MULT_TARG) 926 if (us->fflags & US_FL_SCM_MULT_TARG)
929 bcb->Lun |= srb->device->id << 4; 927 bcb->Lun |= srb->device->id << 4;
930 bcb->Length = srb->cmd_len; 928 bcb->Length = srb->cmd_len;
931 929
@@ -951,7 +949,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
951 /* Some USB-IDE converter chips need a 100us delay between the 949 /* Some USB-IDE converter chips need a 100us delay between the
952 * command phase and the data phase. Some devices need a little 950 * command phase and the data phase. Some devices need a little
953 * more than that, probably because of clock rate inaccuracies. */ 951 * more than that, probably because of clock rate inaccuracies. */
954 if (unlikely(us->flags & US_FL_GO_SLOW)) 952 if (unlikely(us->fflags & US_FL_GO_SLOW))
955 udelay(125); 953 udelay(125);
956 954
957 if (transfer_length) { 955 if (transfer_length) {
@@ -1010,7 +1008,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1010 US_DEBUGP("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n", 1008 US_DEBUGP("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n",
1011 le32_to_cpu(bcs->Signature), bcs->Tag, 1009 le32_to_cpu(bcs->Signature), bcs->Tag,
1012 residue, bcs->Status); 1010 residue, bcs->Status);
1013 if (!(bcs->Tag == us->tag || (us->flags & US_FL_BULK_IGNORE_TAG)) || 1011 if (!(bcs->Tag == us->tag || (us->fflags & US_FL_BULK_IGNORE_TAG)) ||
1014 bcs->Status > US_BULK_STAT_PHASE) { 1012 bcs->Status > US_BULK_STAT_PHASE) {
1015 US_DEBUGP("Bulk logical error\n"); 1013 US_DEBUGP("Bulk logical error\n");
1016 return USB_STOR_TRANSPORT_ERROR; 1014 return USB_STOR_TRANSPORT_ERROR;
@@ -1035,7 +1033,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1035 /* try to compute the actual residue, based on how much data 1033 /* try to compute the actual residue, based on how much data
1036 * was really transferred and what the device tells us */ 1034 * was really transferred and what the device tells us */
1037 if (residue) { 1035 if (residue) {
1038 if (!(us->flags & US_FL_IGNORE_RESIDUE)) { 1036 if (!(us->fflags & US_FL_IGNORE_RESIDUE)) {
1039 residue = min(residue, transfer_length); 1037 residue = min(residue, transfer_length);
1040 scsi_set_resid(srb, max(scsi_get_resid(srb), 1038 scsi_set_resid(srb, max(scsi_get_resid(srb),
1041 (int) residue)); 1039 (int) residue));
@@ -1090,7 +1088,7 @@ static int usb_stor_reset_common(struct us_data *us,
1090 int result; 1088 int result;
1091 int result2; 1089 int result2;
1092 1090
1093 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1091 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1094 US_DEBUGP("No reset during disconnect\n"); 1092 US_DEBUGP("No reset during disconnect\n");
1095 return -EIO; 1093 return -EIO;
1096 } 1094 }
@@ -1103,12 +1101,12 @@ static int usb_stor_reset_common(struct us_data *us,
1103 return result; 1101 return result;
1104 } 1102 }
1105 1103
1106 /* Give the device some time to recover from the reset, 1104 /* Give the device some time to recover from the reset,
1107 * but don't delay disconnect processing. */ 1105 * but don't delay disconnect processing. */
1108 wait_event_interruptible_timeout(us->delay_wait, 1106 wait_event_interruptible_timeout(us->delay_wait,
1109 test_bit(US_FLIDX_DISCONNECTING, &us->flags), 1107 test_bit(US_FLIDX_DISCONNECTING, &us->dflags),
1110 HZ*6); 1108 HZ*6);
1111 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1109 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1112 US_DEBUGP("Reset interrupted by disconnect\n"); 1110 US_DEBUGP("Reset interrupted by disconnect\n");
1113 return -EIO; 1111 return -EIO;
1114 } 1112 }
@@ -1170,13 +1168,12 @@ int usb_stor_port_reset(struct us_data *us)
1170 US_DEBUGP("unable to lock device for reset: %d\n", result); 1168 US_DEBUGP("unable to lock device for reset: %d\n", result);
1171 else { 1169 else {
1172 /* Were we disconnected while waiting for the lock? */ 1170 /* Were we disconnected while waiting for the lock? */
1173 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1171 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1174 result = -EIO; 1172 result = -EIO;
1175 US_DEBUGP("No reset during disconnect\n"); 1173 US_DEBUGP("No reset during disconnect\n");
1176 } else { 1174 } else {
1177 result = usb_reset_composite_device( 1175 result = usb_reset_device(us->pusb_dev);
1178 us->pusb_dev, us->pusb_intf); 1176 US_DEBUGP("usb_reset_device returns %d\n",
1179 US_DEBUGP("usb_reset_composite_device returns %d\n",
1180 result); 1177 result);
1181 } 1178 }
1182 if (rc_lock) 1179 if (rc_lock)
diff --git a/drivers/usb/storage/transport.h b/drivers/usb/storage/transport.h
index ada7c2f43f84..e70b88182f0e 100644
--- a/drivers/usb/storage/transport.h
+++ b/drivers/usb/storage/transport.h
@@ -1,8 +1,6 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * Transport Functions Header File 2 * Transport Functions Header File
3 * 3 *
4 * $Id: transport.h,v 1.18 2002/04/21 02:57:59 mdharm Exp $
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 5 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 * 6 *
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 39a7c11795c4..7ae69f55aa96 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1,8 +1,6 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * Unusual Devices File 2 * Unusual Devices File
3 * 3 *
4 * $Id: unusual_devs.h,v 1.32 2002/02/25 02:41:24 mdharm Exp $
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 2000-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 5 * (c) 2000-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 * 6 *
@@ -1234,6 +1232,17 @@ UNUSUAL_DEV( 0x0851, 0x1543, 0x0200, 0x0200,
1234 US_SC_DEVICE, US_PR_DEVICE, NULL, 1232 US_SC_DEVICE, US_PR_DEVICE, NULL,
1235 US_FL_NOT_LOCKABLE), 1233 US_FL_NOT_LOCKABLE),
1236 1234
1235/* Andrew Lunn <andrew@lunn.ch>
1236 * PanDigital Digital Picture Frame. Does not like ALLOW_MEDIUM_REMOVAL
1237 * on LUN 4.
1238 * Note: Vend:Prod clash with "Ltd Maxell WS30 Slim Digital Camera"
1239*/
1240UNUSUAL_DEV( 0x0851, 0x1543, 0x0200, 0x0200,
1241 "PanDigital",
1242 "Photo Frame",
1243 US_SC_DEVICE, US_PR_DEVICE, NULL,
1244 US_FL_NOT_LOCKABLE),
1245
1237/* Submitted by Jan De Luyck <lkml@kcore.org> */ 1246/* Submitted by Jan De Luyck <lkml@kcore.org> */
1238UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000, 1247UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000,
1239 "CITIZEN", 1248 "CITIZEN",
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index e268aacb773a..bfea851be985 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -1,7 +1,5 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * 2 *
3 * $Id: usb.c,v 1.75 2002/04/22 03:39:43 mdharm Exp $
4 *
5 * Current development and maintenance by: 3 * Current development and maintenance by:
6 * (c) 1999-2003 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 4 * (c) 1999-2003 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
7 * 5 *
@@ -312,26 +310,27 @@ static int usb_stor_control_thread(void * __us)
312 310
313 for(;;) { 311 for(;;) {
314 US_DEBUGP("*** thread sleeping.\n"); 312 US_DEBUGP("*** thread sleeping.\n");
315 if(down_interruptible(&us->sema)) 313 if (wait_for_completion_interruptible(&us->cmnd_ready))
316 break; 314 break;
317 315
318 US_DEBUGP("*** thread awakened.\n"); 316 US_DEBUGP("*** thread awakened.\n");
319 317
320 /* lock the device pointers */ 318 /* lock the device pointers */
321 mutex_lock(&(us->dev_mutex)); 319 mutex_lock(&(us->dev_mutex));
322 320
323 /* if the device has disconnected, we are free to exit */ 321 /* lock access to the state */
324 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 322 scsi_lock(host);
325 US_DEBUGP("-- exiting\n"); 323
324 /* When we are called with no command pending, we're done */
325 if (us->srb == NULL) {
326 scsi_unlock(host);
326 mutex_unlock(&us->dev_mutex); 327 mutex_unlock(&us->dev_mutex);
328 US_DEBUGP("-- exiting\n");
327 break; 329 break;
328 } 330 }
329 331
330 /* lock access to the state */
331 scsi_lock(host);
332
333 /* has the command timed out *already* ? */ 332 /* has the command timed out *already* ? */
334 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 333 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
335 us->srb->result = DID_ABORT << 16; 334 us->srb->result = DID_ABORT << 16;
336 goto SkipForAbort; 335 goto SkipForAbort;
337 } 336 }
@@ -350,7 +349,7 @@ static int usb_stor_control_thread(void * __us)
350 * the maximum known LUN 349 * the maximum known LUN
351 */ 350 */
352 else if (us->srb->device->id && 351 else if (us->srb->device->id &&
353 !(us->flags & US_FL_SCM_MULT_TARG)) { 352 !(us->fflags & US_FL_SCM_MULT_TARG)) {
354 US_DEBUGP("Bad target number (%d:%d)\n", 353 US_DEBUGP("Bad target number (%d:%d)\n",
355 us->srb->device->id, us->srb->device->lun); 354 us->srb->device->id, us->srb->device->lun);
356 us->srb->result = DID_BAD_TARGET << 16; 355 us->srb->result = DID_BAD_TARGET << 16;
@@ -365,7 +364,7 @@ static int usb_stor_control_thread(void * __us)
365 /* Handle those devices which need us to fake 364 /* Handle those devices which need us to fake
366 * their inquiry data */ 365 * their inquiry data */
367 else if ((us->srb->cmnd[0] == INQUIRY) && 366 else if ((us->srb->cmnd[0] == INQUIRY) &&
368 (us->flags & US_FL_FIX_INQUIRY)) { 367 (us->fflags & US_FL_FIX_INQUIRY)) {
369 unsigned char data_ptr[36] = { 368 unsigned char data_ptr[36] = {
370 0x00, 0x80, 0x02, 0x02, 369 0x00, 0x80, 0x02, 0x02,
371 0x1F, 0x00, 0x00, 0x00}; 370 0x1F, 0x00, 0x00, 0x00};
@@ -384,12 +383,8 @@ static int usb_stor_control_thread(void * __us)
384 /* lock access to the state */ 383 /* lock access to the state */
385 scsi_lock(host); 384 scsi_lock(host);
386 385
387 /* did the command already complete because of a disconnect? */
388 if (!us->srb)
389 ; /* nothing to do */
390
391 /* indicate that the command is done */ 386 /* indicate that the command is done */
392 else if (us->srb->result != DID_ABORT << 16) { 387 if (us->srb->result != DID_ABORT << 16) {
393 US_DEBUGP("scsi cmd done, result=0x%x\n", 388 US_DEBUGP("scsi cmd done, result=0x%x\n",
394 us->srb->result); 389 us->srb->result);
395 us->srb->scsi_done(us->srb); 390 us->srb->scsi_done(us->srb);
@@ -403,12 +398,12 @@ SkipForAbort:
403 * the TIMED_OUT flag, not srb->result == DID_ABORT, because 398 * the TIMED_OUT flag, not srb->result == DID_ABORT, because
404 * the timeout might have occurred after the command had 399 * the timeout might have occurred after the command had
405 * already completed with a different result code. */ 400 * already completed with a different result code. */
406 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 401 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
407 complete(&(us->notify)); 402 complete(&(us->notify));
408 403
409 /* Allow USB transfers to resume */ 404 /* Allow USB transfers to resume */
410 clear_bit(US_FLIDX_ABORTING, &us->flags); 405 clear_bit(US_FLIDX_ABORTING, &us->dflags);
411 clear_bit(US_FLIDX_TIMED_OUT, &us->flags); 406 clear_bit(US_FLIDX_TIMED_OUT, &us->dflags);
412 } 407 }
413 408
414 /* finished working on this command */ 409 /* finished working on this command */
@@ -500,9 +495,9 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id)
500 us->protocol = (unusual_dev->useTransport == US_PR_DEVICE) ? 495 us->protocol = (unusual_dev->useTransport == US_PR_DEVICE) ?
501 idesc->bInterfaceProtocol : 496 idesc->bInterfaceProtocol :
502 unusual_dev->useTransport; 497 unusual_dev->useTransport;
503 us->flags = USB_US_ORIG_FLAGS(id->driver_info); 498 us->fflags = USB_US_ORIG_FLAGS(id->driver_info);
504 499
505 if (us->flags & US_FL_IGNORE_DEVICE) { 500 if (us->fflags & US_FL_IGNORE_DEVICE) {
506 printk(KERN_INFO USB_STORAGE "device ignored\n"); 501 printk(KERN_INFO USB_STORAGE "device ignored\n");
507 return -ENODEV; 502 return -ENODEV;
508 } 503 }
@@ -512,7 +507,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id)
512 * disable it if we're in full-speed 507 * disable it if we're in full-speed
513 */ 508 */
514 if (dev->speed != USB_SPEED_HIGH) 509 if (dev->speed != USB_SPEED_HIGH)
515 us->flags &= ~US_FL_GO_SLOW; 510 us->fflags &= ~US_FL_GO_SLOW;
516 511
517 /* Log a message if a non-generic unusual_dev entry contains an 512 /* Log a message if a non-generic unusual_dev entry contains an
518 * unnecessary subclass or protocol override. This may stimulate 513 * unnecessary subclass or protocol override. This may stimulate
@@ -533,7 +528,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id)
533 if (unusual_dev->useTransport != US_PR_DEVICE && 528 if (unusual_dev->useTransport != US_PR_DEVICE &&
534 us->protocol == idesc->bInterfaceProtocol) 529 us->protocol == idesc->bInterfaceProtocol)
535 msg += 2; 530 msg += 2;
536 if (msg >= 0 && !(us->flags & US_FL_NEED_OVERRIDE)) 531 if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE))
537 printk(KERN_NOTICE USB_STORAGE "This device " 532 printk(KERN_NOTICE USB_STORAGE "This device "
538 "(%04x,%04x,%04x S %02x P %02x)" 533 "(%04x,%04x,%04x S %02x P %02x)"
539 " has %s in unusual_devs.h (kernel" 534 " has %s in unusual_devs.h (kernel"
@@ -663,7 +658,7 @@ static int get_transport(struct us_data *us)
663 US_DEBUGP("Transport: %s\n", us->transport_name); 658 US_DEBUGP("Transport: %s\n", us->transport_name);
664 659
665 /* fix for single-lun devices */ 660 /* fix for single-lun devices */
666 if (us->flags & US_FL_SINGLE_LUN) 661 if (us->fflags & US_FL_SINGLE_LUN)
667 us->max_lun = 0; 662 us->max_lun = 0;
668 return 0; 663 return 0;
669} 664}
@@ -820,12 +815,11 @@ static void usb_stor_release_resources(struct us_data *us)
820 US_DEBUGP("-- %s\n", __func__); 815 US_DEBUGP("-- %s\n", __func__);
821 816
822 /* Tell the control thread to exit. The SCSI host must 817 /* Tell the control thread to exit. The SCSI host must
823 * already have been removed so it won't try to queue 818 * already have been removed and the DISCONNECTING flag set
824 * any more commands. 819 * so that we won't accept any more commands.
825 */ 820 */
826 US_DEBUGP("-- sending exit command to thread\n"); 821 US_DEBUGP("-- sending exit command to thread\n");
827 set_bit(US_FLIDX_DISCONNECTING, &us->flags); 822 complete(&us->cmnd_ready);
828 up(&us->sema);
829 if (us->ctl_thread) 823 if (us->ctl_thread)
830 kthread_stop(us->ctl_thread); 824 kthread_stop(us->ctl_thread);
831 825
@@ -859,39 +853,36 @@ static void dissociate_dev(struct us_data *us)
859 usb_set_intfdata(us->pusb_intf, NULL); 853 usb_set_intfdata(us->pusb_intf, NULL);
860} 854}
861 855
862/* First stage of disconnect processing: stop all commands and remove 856/* First stage of disconnect processing: stop SCSI scanning,
863 * the host */ 857 * remove the host, and stop accepting new commands
858 */
864static void quiesce_and_remove_host(struct us_data *us) 859static void quiesce_and_remove_host(struct us_data *us)
865{ 860{
866 struct Scsi_Host *host = us_to_host(us); 861 struct Scsi_Host *host = us_to_host(us);
867 862
868 /* Prevent new USB transfers, stop the current command, and 863 /* If the device is really gone, cut short reset delays */
869 * interrupt a SCSI-scan or device-reset delay */ 864 if (us->pusb_dev->state == USB_STATE_NOTATTACHED)
870 scsi_lock(host); 865 set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
871 set_bit(US_FLIDX_DISCONNECTING, &us->flags);
872 scsi_unlock(host);
873 usb_stor_stop_transport(us);
874 wake_up(&us->delay_wait);
875 866
876 /* queuecommand won't accept any new commands and the control 867 /* Prevent SCSI-scanning (if it hasn't started yet)
877 * thread won't execute a previously-queued command. If there 868 * and wait for the SCSI-scanning thread to stop.
878 * is such a command pending, complete it with an error. */ 869 */
879 mutex_lock(&us->dev_mutex); 870 set_bit(US_FLIDX_DONT_SCAN, &us->dflags);
880 if (us->srb) { 871 wake_up(&us->delay_wait);
881 us->srb->result = DID_NO_CONNECT << 16; 872 wait_for_completion(&us->scanning_done);
882 scsi_lock(host);
883 us->srb->scsi_done(us->srb);
884 us->srb = NULL;
885 complete(&us->notify); /* in case of an abort */
886 scsi_unlock(host);
887 }
888 mutex_unlock(&us->dev_mutex);
889 873
890 /* Now we own no commands so it's safe to remove the SCSI host */ 874 /* Removing the host will perform an orderly shutdown: caches
875 * synchronized, disks spun down, etc.
876 */
891 scsi_remove_host(host); 877 scsi_remove_host(host);
892 878
893 /* Wait for the SCSI-scanning thread to stop */ 879 /* Prevent any new commands from being accepted and cut short
894 wait_for_completion(&us->scanning_done); 880 * reset delays.
881 */
882 scsi_lock(host);
883 set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
884 scsi_unlock(host);
885 wake_up(&us->delay_wait);
895} 886}
896 887
897/* Second stage of disconnect processing: deallocate all resources */ 888/* Second stage of disconnect processing: deallocate all resources */
@@ -919,16 +910,16 @@ static int usb_stor_scan_thread(void * __us)
919 printk(KERN_DEBUG "usb-storage: waiting for device " 910 printk(KERN_DEBUG "usb-storage: waiting for device "
920 "to settle before scanning\n"); 911 "to settle before scanning\n");
921 wait_event_freezable_timeout(us->delay_wait, 912 wait_event_freezable_timeout(us->delay_wait,
922 test_bit(US_FLIDX_DISCONNECTING, &us->flags), 913 test_bit(US_FLIDX_DONT_SCAN, &us->dflags),
923 delay_use * HZ); 914 delay_use * HZ);
924 } 915 }
925 916
926 /* If the device is still connected, perform the scanning */ 917 /* If the device is still connected, perform the scanning */
927 if (!test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 918 if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags)) {
928 919
929 /* For bulk-only devices, determine the max LUN value */ 920 /* For bulk-only devices, determine the max LUN value */
930 if (us->protocol == US_PR_BULK && 921 if (us->protocol == US_PR_BULK &&
931 !(us->flags & US_FL_SINGLE_LUN)) { 922 !(us->fflags & US_FL_SINGLE_LUN)) {
932 mutex_lock(&us->dev_mutex); 923 mutex_lock(&us->dev_mutex);
933 us->max_lun = usb_stor_Bulk_max_lun(us); 924 us->max_lun = usb_stor_Bulk_max_lun(us);
934 mutex_unlock(&us->dev_mutex); 925 mutex_unlock(&us->dev_mutex);
@@ -975,7 +966,7 @@ static int storage_probe(struct usb_interface *intf,
975 us = host_to_us(host); 966 us = host_to_us(host);
976 memset(us, 0, sizeof(struct us_data)); 967 memset(us, 0, sizeof(struct us_data));
977 mutex_init(&(us->dev_mutex)); 968 mutex_init(&(us->dev_mutex));
978 init_MUTEX_LOCKED(&(us->sema)); 969 init_completion(&us->cmnd_ready);
979 init_completion(&(us->notify)); 970 init_completion(&(us->notify));
980 init_waitqueue_head(&us->delay_wait); 971 init_waitqueue_head(&us->delay_wait);
981 init_completion(&us->scanning_done); 972 init_completion(&us->scanning_done);
@@ -1023,6 +1014,7 @@ static int storage_probe(struct usb_interface *intf,
1023 if (IS_ERR(th)) { 1014 if (IS_ERR(th)) {
1024 printk(KERN_WARNING USB_STORAGE 1015 printk(KERN_WARNING USB_STORAGE
1025 "Unable to start the device-scanning thread\n"); 1016 "Unable to start the device-scanning thread\n");
1017 complete(&us->scanning_done);
1026 quiesce_and_remove_host(us); 1018 quiesce_and_remove_host(us);
1027 result = PTR_ERR(th); 1019 result = PTR_ERR(th);
1028 goto BadDevice; 1020 goto BadDevice;
@@ -1065,6 +1057,7 @@ static struct usb_driver usb_storage_driver = {
1065 .pre_reset = storage_pre_reset, 1057 .pre_reset = storage_pre_reset,
1066 .post_reset = storage_post_reset, 1058 .post_reset = storage_post_reset,
1067 .id_table = storage_usb_ids, 1059 .id_table = storage_usb_ids,
1060 .soft_unbind = 1,
1068}; 1061};
1069 1062
1070static int __init usb_stor_init(void) 1063static int __init usb_stor_init(void)
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 8d87503e2560..a4ad73bd832d 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -1,8 +1,6 @@
1/* Driver for USB Mass Storage compliant devices 1/* Driver for USB Mass Storage compliant devices
2 * Main Header File 2 * Main Header File
3 * 3 *
4 * $Id: usb.h,v 1.21 2002/04/21 02:57:59 mdharm Exp $
5 *
6 * Current development and maintenance by: 4 * Current development and maintenance by:
7 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 5 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 * 6 *
@@ -67,16 +65,14 @@ struct us_unusual_dev {
67}; 65};
68 66
69 67
70/* Dynamic flag definitions: used in set_bit() etc. */ 68/* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
71#define US_FLIDX_URB_ACTIVE 18 /* 0x00040000 current_urb is in use */ 69#define US_FLIDX_URB_ACTIVE 0 /* current_urb is in use */
72#define US_FLIDX_SG_ACTIVE 19 /* 0x00080000 current_sg is in use */ 70#define US_FLIDX_SG_ACTIVE 1 /* current_sg is in use */
73#define US_FLIDX_ABORTING 20 /* 0x00100000 abort is in progress */ 71#define US_FLIDX_ABORTING 2 /* abort is in progress */
74#define US_FLIDX_DISCONNECTING 21 /* 0x00200000 disconnect in progress */ 72#define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */
75#define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \ 73#define US_FLIDX_RESETTING 4 /* device reset in progress */
76 (1UL << US_FLIDX_DISCONNECTING)) 74#define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
77#define US_FLIDX_RESETTING 22 /* 0x00400000 device reset in progress */ 75#define US_FLIDX_DONT_SCAN 6 /* don't scan (disconnect) */
78#define US_FLIDX_TIMED_OUT 23 /* 0x00800000 SCSI midlayer timed out */
79
80 76
81#define USB_STOR_STRING_LEN 32 77#define USB_STOR_STRING_LEN 32
82 78
@@ -109,7 +105,8 @@ struct us_data {
109 struct usb_device *pusb_dev; /* this usb_device */ 105 struct usb_device *pusb_dev; /* this usb_device */
110 struct usb_interface *pusb_intf; /* this interface */ 106 struct usb_interface *pusb_intf; /* this interface */
111 struct us_unusual_dev *unusual_dev; /* device-filter entry */ 107 struct us_unusual_dev *unusual_dev; /* device-filter entry */
112 unsigned long flags; /* from filter initially */ 108 unsigned long fflags; /* fixed flags from filter */
109 unsigned long dflags; /* dynamic atomic bitflags */
113 unsigned int send_bulk_pipe; /* cached pipe values */ 110 unsigned int send_bulk_pipe; /* cached pipe values */
114 unsigned int recv_bulk_pipe; 111 unsigned int recv_bulk_pipe;
115 unsigned int send_ctrl_pipe; 112 unsigned int send_ctrl_pipe;
@@ -147,7 +144,7 @@ struct us_data {
147 struct task_struct *ctl_thread; /* the control thread */ 144 struct task_struct *ctl_thread; /* the control thread */
148 145
149 /* mutual exclusion and synchronization structures */ 146 /* mutual exclusion and synchronization structures */
150 struct semaphore sema; /* to sleep thread on */ 147 struct completion cmnd_ready; /* to sleep thread on */
151 struct completion notify; /* thread begin/end */ 148 struct completion notify; /* thread begin/end */
152 wait_queue_head_t delay_wait; /* wait during scan, reset */ 149 wait_queue_head_t delay_wait; /* wait during scan, reset */
153 struct completion scanning_done; /* wait for scan thread */ 150 struct completion scanning_done; /* wait for scan thread */
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 24ee96c4e9e9..07b6addbb3c1 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -1872,7 +1872,7 @@ static int __devinit aty128_init(struct pci_dev *pdev, const struct pci_device_i
1872 struct fb_info *info = pci_get_drvdata(pdev); 1872 struct fb_info *info = pci_get_drvdata(pdev);
1873 struct aty128fb_par *par = info->par; 1873 struct aty128fb_par *par = info->par;
1874 struct fb_var_screeninfo var; 1874 struct fb_var_screeninfo var;
1875 char video_card[DEVICE_NAME_SIZE]; 1875 char video_card[50];
1876 u8 chip_rev; 1876 u8 chip_rev;
1877 u32 dac; 1877 u32 dac;
1878 1878
diff --git a/drivers/video/aty/radeonfb.h b/drivers/video/aty/radeonfb.h
index c347e38cd0b0..ccbfffd12805 100644
--- a/drivers/video/aty/radeonfb.h
+++ b/drivers/video/aty/radeonfb.h
@@ -289,7 +289,7 @@ struct radeonfb_info {
289 struct radeon_regs state; 289 struct radeon_regs state;
290 struct radeon_regs init_state; 290 struct radeon_regs init_state;
291 291
292 char name[DEVICE_NAME_SIZE]; 292 char name[50];
293 293
294 unsigned long mmio_base_phys; 294 unsigned long mmio_base_phys;
295 unsigned long fb_base_phys; 295 unsigned long fb_base_phys;
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 97aff8db10bf..4be3b46c069b 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -3586,7 +3586,8 @@ static int __init fb_console_init(void)
3586 3586
3587 acquire_console_sem(); 3587 acquire_console_sem();
3588 fb_register_client(&fbcon_event_notifier); 3588 fb_register_client(&fbcon_event_notifier);
3589 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), "fbcon"); 3589 fbcon_device = device_create_drvdata(fb_class, NULL, MKDEV(0, 0),
3590 NULL, "fbcon");
3590 3591
3591 if (IS_ERR(fbcon_device)) { 3592 if (IS_ERR(fbcon_device)) {
3592 printk(KERN_WARNING "Unable to create device " 3593 printk(KERN_WARNING "Unable to create device "
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 33ebdb198daf..1cd5071e5362 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -1439,8 +1439,9 @@ register_framebuffer(struct fb_info *fb_info)
1439 break; 1439 break;
1440 fb_info->node = i; 1440 fb_info->node = i;
1441 1441
1442 fb_info->dev = device_create(fb_class, fb_info->device, 1442 fb_info->dev = device_create_drvdata(fb_class, fb_info->device,
1443 MKDEV(FB_MAJOR, i), "fb%d", i); 1443 MKDEV(FB_MAJOR, i), NULL,
1444 "fb%d", i);
1444 if (IS_ERR(fb_info->dev)) { 1445 if (IS_ERR(fb_info->dev)) {
1445 /* Not fatal */ 1446 /* Not fatal */
1446 printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n", i, PTR_ERR(fb_info->dev)); 1447 printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n", i, PTR_ERR(fb_info->dev));
diff --git a/drivers/video/offb.c b/drivers/video/offb.c
index d7b3dcc0dc43..e1d9eeb1aeaf 100644
--- a/drivers/video/offb.c
+++ b/drivers/video/offb.c
@@ -47,6 +47,7 @@ enum {
47 cmap_M3B, /* ATI Rage Mobility M3 Head B */ 47 cmap_M3B, /* ATI Rage Mobility M3 Head B */
48 cmap_radeon, /* ATI Radeon */ 48 cmap_radeon, /* ATI Radeon */
49 cmap_gxt2000, /* IBM GXT2000 */ 49 cmap_gxt2000, /* IBM GXT2000 */
50 cmap_avivo, /* ATI R5xx */
50}; 51};
51 52
52struct offb_par { 53struct offb_par {
@@ -58,26 +59,36 @@ struct offb_par {
58 59
59struct offb_par default_par; 60struct offb_par default_par;
60 61
61 /*
62 * Interface used by the world
63 */
64
65static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
66 u_int transp, struct fb_info *info);
67static int offb_blank(int blank, struct fb_info *info);
68
69#ifdef CONFIG_PPC32 62#ifdef CONFIG_PPC32
70extern boot_infos_t *boot_infos; 63extern boot_infos_t *boot_infos;
71#endif 64#endif
72 65
73static struct fb_ops offb_ops = { 66/* Definitions used by the Avivo palette hack */
74 .owner = THIS_MODULE, 67#define AVIVO_DC_LUT_RW_SELECT 0x6480
75 .fb_setcolreg = offb_setcolreg, 68#define AVIVO_DC_LUT_RW_MODE 0x6484
76 .fb_blank = offb_blank, 69#define AVIVO_DC_LUT_RW_INDEX 0x6488
77 .fb_fillrect = cfb_fillrect, 70#define AVIVO_DC_LUT_SEQ_COLOR 0x648c
78 .fb_copyarea = cfb_copyarea, 71#define AVIVO_DC_LUT_PWL_DATA 0x6490
79 .fb_imageblit = cfb_imageblit, 72#define AVIVO_DC_LUT_30_COLOR 0x6494
80}; 73#define AVIVO_DC_LUT_READ_PIPE_SELECT 0x6498
74#define AVIVO_DC_LUT_WRITE_EN_MASK 0x649c
75#define AVIVO_DC_LUT_AUTOFILL 0x64a0
76
77#define AVIVO_DC_LUTA_CONTROL 0x64c0
78#define AVIVO_DC_LUTA_BLACK_OFFSET_BLUE 0x64c4
79#define AVIVO_DC_LUTA_BLACK_OFFSET_GREEN 0x64c8
80#define AVIVO_DC_LUTA_BLACK_OFFSET_RED 0x64cc
81#define AVIVO_DC_LUTA_WHITE_OFFSET_BLUE 0x64d0
82#define AVIVO_DC_LUTA_WHITE_OFFSET_GREEN 0x64d4
83#define AVIVO_DC_LUTA_WHITE_OFFSET_RED 0x64d8
84
85#define AVIVO_DC_LUTB_CONTROL 0x6cc0
86#define AVIVO_DC_LUTB_BLACK_OFFSET_BLUE 0x6cc4
87#define AVIVO_DC_LUTB_BLACK_OFFSET_GREEN 0x6cc8
88#define AVIVO_DC_LUTB_BLACK_OFFSET_RED 0x6ccc
89#define AVIVO_DC_LUTB_WHITE_OFFSET_BLUE 0x6cd0
90#define AVIVO_DC_LUTB_WHITE_OFFSET_GREEN 0x6cd4
91#define AVIVO_DC_LUTB_WHITE_OFFSET_RED 0x6cd8
81 92
82 /* 93 /*
83 * Set a single color register. The values supplied are already 94 * Set a single color register. The values supplied are already
@@ -160,6 +171,17 @@ static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
160 out_le32(((unsigned __iomem *) par->cmap_adr) + regno, 171 out_le32(((unsigned __iomem *) par->cmap_adr) + regno,
161 (red << 16 | green << 8 | blue)); 172 (red << 16 | green << 8 | blue));
162 break; 173 break;
174 case cmap_avivo:
175 /* Write to both LUTs for now */
176 writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
177 writeb(regno, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
178 writel(((red) << 22) | ((green) << 12) | ((blue) << 2),
179 par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
180 writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
181 writeb(regno, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
182 writel(((red) << 22) | ((green) << 12) | ((blue) << 2),
183 par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
184 break;
163 } 185 }
164 186
165 return 0; 187 return 0;
@@ -216,12 +238,59 @@ static int offb_blank(int blank, struct fb_info *info)
216 out_le32(((unsigned __iomem *) par->cmap_adr) + i, 238 out_le32(((unsigned __iomem *) par->cmap_adr) + i,
217 0); 239 0);
218 break; 240 break;
241 case cmap_avivo:
242 writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
243 writeb(i, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
244 writel(0, par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
245 writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
246 writeb(i, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
247 writel(0, par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
248 break;
219 } 249 }
220 } else 250 } else
221 fb_set_cmap(&info->cmap, info); 251 fb_set_cmap(&info->cmap, info);
222 return 0; 252 return 0;
223} 253}
224 254
255static int offb_set_par(struct fb_info *info)
256{
257 struct offb_par *par = (struct offb_par *) info->par;
258
259 /* On avivo, initialize palette control */
260 if (par->cmap_type == cmap_avivo) {
261 writel(0, par->cmap_adr + AVIVO_DC_LUTA_CONTROL);
262 writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_BLUE);
263 writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_GREEN);
264 writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_RED);
265 writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_BLUE);
266 writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_GREEN);
267 writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_RED);
268 writel(0, par->cmap_adr + AVIVO_DC_LUTB_CONTROL);
269 writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_BLUE);
270 writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_GREEN);
271 writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_RED);
272 writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_BLUE);
273 writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_GREEN);
274 writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_RED);
275 writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
276 writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_MODE);
277 writel(0x0000003f, par->cmap_adr + AVIVO_DC_LUT_WRITE_EN_MASK);
278 writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
279 writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_MODE);
280 writel(0x0000003f, par->cmap_adr + AVIVO_DC_LUT_WRITE_EN_MASK);
281 }
282 return 0;
283}
284
285static struct fb_ops offb_ops = {
286 .owner = THIS_MODULE,
287 .fb_setcolreg = offb_setcolreg,
288 .fb_set_par = offb_set_par,
289 .fb_blank = offb_blank,
290 .fb_fillrect = cfb_fillrect,
291 .fb_copyarea = cfb_copyarea,
292 .fb_imageblit = cfb_imageblit,
293};
225 294
226static void __iomem *offb_map_reg(struct device_node *np, int index, 295static void __iomem *offb_map_reg(struct device_node *np, int index,
227 unsigned long offset, unsigned long size) 296 unsigned long offset, unsigned long size)
@@ -245,6 +314,59 @@ static void __iomem *offb_map_reg(struct device_node *np, int index,
245 return ioremap(taddr + offset, size); 314 return ioremap(taddr + offset, size);
246} 315}
247 316
317static void offb_init_palette_hacks(struct fb_info *info, struct device_node *dp,
318 const char *name, unsigned long address)
319{
320 struct offb_par *par = (struct offb_par *) info->par;
321
322 if (dp && !strncmp(name, "ATY,Rage128", 11)) {
323 par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
324 if (par->cmap_adr)
325 par->cmap_type = cmap_r128;
326 } else if (dp && (!strncmp(name, "ATY,RageM3pA", 12)
327 || !strncmp(name, "ATY,RageM3p12A", 14))) {
328 par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
329 if (par->cmap_adr)
330 par->cmap_type = cmap_M3A;
331 } else if (dp && !strncmp(name, "ATY,RageM3pB", 12)) {
332 par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
333 if (par->cmap_adr)
334 par->cmap_type = cmap_M3B;
335 } else if (dp && !strncmp(name, "ATY,Rage6", 9)) {
336 par->cmap_adr = offb_map_reg(dp, 1, 0, 0x1fff);
337 if (par->cmap_adr)
338 par->cmap_type = cmap_radeon;
339 } else if (!strncmp(name, "ATY,", 4)) {
340 unsigned long base = address & 0xff000000UL;
341 par->cmap_adr =
342 ioremap(base + 0x7ff000, 0x1000) + 0xcc0;
343 par->cmap_data = par->cmap_adr + 1;
344 par->cmap_type = cmap_m64;
345 } else if (dp && (of_device_is_compatible(dp, "pci1014,b7") ||
346 of_device_is_compatible(dp, "pci1014,21c"))) {
347 par->cmap_adr = offb_map_reg(dp, 0, 0x6000, 0x1000);
348 if (par->cmap_adr)
349 par->cmap_type = cmap_gxt2000;
350 } else if (dp && !strncmp(name, "vga,Display-", 12)) {
351 /* Look for AVIVO initialized by SLOF */
352 struct device_node *pciparent = of_get_parent(dp);
353 const u32 *vid, *did;
354 vid = of_get_property(pciparent, "vendor-id", NULL);
355 did = of_get_property(pciparent, "device-id", NULL);
356 /* This will match most R5xx */
357 if (vid && did && *vid == 0x1002 &&
358 ((*did >= 0x7100 && *did < 0x7800) ||
359 (*did >= 0x9400))) {
360 par->cmap_adr = offb_map_reg(pciparent, 2, 0, 0x10000);
361 if (par->cmap_adr)
362 par->cmap_type = cmap_avivo;
363 }
364 of_node_put(pciparent);
365 }
366 info->fix.visual = (par->cmap_type != cmap_unknown) ?
367 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR;
368}
369
248static void __init offb_init_fb(const char *name, const char *full_name, 370static void __init offb_init_fb(const char *name, const char *full_name,
249 int width, int height, int depth, 371 int width, int height, int depth,
250 int pitch, unsigned long address, 372 int pitch, unsigned long address,
@@ -283,6 +405,7 @@ static void __init offb_init_fb(const char *name, const char *full_name,
283 405
284 fix = &info->fix; 406 fix = &info->fix;
285 var = &info->var; 407 var = &info->var;
408 info->par = par;
286 409
287 strcpy(fix->id, "OFfb "); 410 strcpy(fix->id, "OFfb ");
288 strncat(fix->id, name, sizeof(fix->id) - sizeof("OFfb ")); 411 strncat(fix->id, name, sizeof(fix->id) - sizeof("OFfb "));
@@ -298,39 +421,9 @@ static void __init offb_init_fb(const char *name, const char *full_name,
298 fix->type_aux = 0; 421 fix->type_aux = 0;
299 422
300 par->cmap_type = cmap_unknown; 423 par->cmap_type = cmap_unknown;
301 if (depth == 8) { 424 if (depth == 8)
302 if (dp && !strncmp(name, "ATY,Rage128", 11)) { 425 offb_init_palette_hacks(info, dp, name, address);
303 par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff); 426 else
304 if (par->cmap_adr)
305 par->cmap_type = cmap_r128;
306 } else if (dp && (!strncmp(name, "ATY,RageM3pA", 12)
307 || !strncmp(name, "ATY,RageM3p12A", 14))) {
308 par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
309 if (par->cmap_adr)
310 par->cmap_type = cmap_M3A;
311 } else if (dp && !strncmp(name, "ATY,RageM3pB", 12)) {
312 par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
313 if (par->cmap_adr)
314 par->cmap_type = cmap_M3B;
315 } else if (dp && !strncmp(name, "ATY,Rage6", 9)) {
316 par->cmap_adr = offb_map_reg(dp, 1, 0, 0x1fff);
317 if (par->cmap_adr)
318 par->cmap_type = cmap_radeon;
319 } else if (!strncmp(name, "ATY,", 4)) {
320 unsigned long base = address & 0xff000000UL;
321 par->cmap_adr =
322 ioremap(base + 0x7ff000, 0x1000) + 0xcc0;
323 par->cmap_data = par->cmap_adr + 1;
324 par->cmap_type = cmap_m64;
325 } else if (dp && (of_device_is_compatible(dp, "pci1014,b7") ||
326 of_device_is_compatible(dp, "pci1014,21c"))) {
327 par->cmap_adr = offb_map_reg(dp, 0, 0x6000, 0x1000);
328 if (par->cmap_adr)
329 par->cmap_type = cmap_gxt2000;
330 }
331 fix->visual = (par->cmap_type != cmap_unknown) ?
332 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR;
333 } else
334 fix->visual = FB_VISUAL_TRUECOLOR; 427 fix->visual = FB_VISUAL_TRUECOLOR;
335 428
336 var->xoffset = var->yoffset = 0; 429 var->xoffset = var->yoffset = 0;
@@ -395,7 +488,6 @@ static void __init offb_init_fb(const char *name, const char *full_name,
395 488
396 info->fbops = &offb_ops; 489 info->fbops = &offb_ops;
397 info->screen_base = ioremap(address, fix->smem_len); 490 info->screen_base = ioremap(address, fix->smem_len);
398 info->par = par;
399 info->pseudo_palette = (void *) (info + 1); 491 info->pseudo_palette = (void *) (info + 1);
400 info->flags = FBINFO_DEFAULT | foreign_endian; 492 info->flags = FBINFO_DEFAULT | foreign_endian;
401 493
diff --git a/drivers/video/ps3fb.c b/drivers/video/ps3fb.c
index dc3af1c78c56..4b5d80771904 100644
--- a/drivers/video/ps3fb.c
+++ b/drivers/video/ps3fb.c
@@ -1297,6 +1297,7 @@ static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
1297 1297
1298static struct ps3_system_bus_driver ps3fb_driver = { 1298static struct ps3_system_bus_driver ps3fb_driver = {
1299 .match_id = PS3_MATCH_ID_GRAPHICS, 1299 .match_id = PS3_MATCH_ID_GRAPHICS,
1300 .match_sub_id = PS3_MATCH_SUB_ID_FB,
1300 .core.name = DEVICE_NAME, 1301 .core.name = DEVICE_NAME,
1301 .core.owner = THIS_MODULE, 1302 .core.owner = THIS_MODULE,
1302 .probe = ps3fb_probe, 1303 .probe = ps3fb_probe,
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 591bc29b55f5..d4427cb86979 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -610,6 +610,7 @@ static ssize_t show_target_kb(struct sys_device *dev, char *buf)
610} 610}
611 611
612static ssize_t store_target_kb(struct sys_device *dev, 612static ssize_t store_target_kb(struct sys_device *dev,
613 struct sysdev_attribute *attr,
613 const char *buf, 614 const char *buf,
614 size_t count) 615 size_t count)
615{ 616{
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index d48ff5f370f4..639d2d8b5710 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -204,6 +204,7 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
204 NEW_AUX_ENT(AT_GID, tsk->gid); 204 NEW_AUX_ENT(AT_GID, tsk->gid);
205 NEW_AUX_ENT(AT_EGID, tsk->egid); 205 NEW_AUX_ENT(AT_EGID, tsk->egid);
206 NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm)); 206 NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm));
207 NEW_AUX_ENT(AT_EXECFN, bprm->exec);
207 if (k_platform) { 208 if (k_platform) {
208 NEW_AUX_ENT(AT_PLATFORM, 209 NEW_AUX_ENT(AT_PLATFORM,
209 (elf_addr_t)(unsigned long)u_platform); 210 (elf_addr_t)(unsigned long)u_platform);
diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c
index e3eb3556622b..40c36f7352a6 100644
--- a/fs/coda/psdev.c
+++ b/fs/coda/psdev.c
@@ -362,8 +362,9 @@ static int init_coda_psdev(void)
362 goto out_chrdev; 362 goto out_chrdev;
363 } 363 }
364 for (i = 0; i < MAX_CODADEVS; i++) 364 for (i = 0; i < MAX_CODADEVS; i++)
365 device_create(coda_psdev_class, NULL, 365 device_create_drvdata(coda_psdev_class, NULL,
366 MKDEV(CODA_PSDEV_MAJOR,i), "cfs%d", i); 366 MKDEV(CODA_PSDEV_MAJOR, i),
367 NULL, "cfs%d", i);
367 coda_sysctl_init(); 368 coda_sysctl_init();
368 goto out; 369 goto out;
369 370
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index e9602d85c11d..08e28c9bb416 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -309,6 +309,31 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
309} 309}
310EXPORT_SYMBOL_GPL(debugfs_create_symlink); 310EXPORT_SYMBOL_GPL(debugfs_create_symlink);
311 311
312static void __debugfs_remove(struct dentry *dentry, struct dentry *parent)
313{
314 int ret = 0;
315
316 if (debugfs_positive(dentry)) {
317 if (dentry->d_inode) {
318 dget(dentry);
319 switch (dentry->d_inode->i_mode & S_IFMT) {
320 case S_IFDIR:
321 ret = simple_rmdir(parent->d_inode, dentry);
322 break;
323 case S_IFLNK:
324 kfree(dentry->d_inode->i_private);
325 /* fall through */
326 default:
327 simple_unlink(parent->d_inode, dentry);
328 break;
329 }
330 if (!ret)
331 d_delete(dentry);
332 dput(dentry);
333 }
334 }
335}
336
312/** 337/**
313 * debugfs_remove - removes a file or directory from the debugfs filesystem 338 * debugfs_remove - removes a file or directory from the debugfs filesystem
314 * @dentry: a pointer to a the dentry of the file or directory to be 339 * @dentry: a pointer to a the dentry of the file or directory to be
@@ -325,7 +350,6 @@ EXPORT_SYMBOL_GPL(debugfs_create_symlink);
325void debugfs_remove(struct dentry *dentry) 350void debugfs_remove(struct dentry *dentry)
326{ 351{
327 struct dentry *parent; 352 struct dentry *parent;
328 int ret = 0;
329 353
330 if (!dentry) 354 if (!dentry)
331 return; 355 return;
@@ -335,29 +359,83 @@ void debugfs_remove(struct dentry *dentry)
335 return; 359 return;
336 360
337 mutex_lock(&parent->d_inode->i_mutex); 361 mutex_lock(&parent->d_inode->i_mutex);
338 if (debugfs_positive(dentry)) { 362 __debugfs_remove(dentry, parent);
339 if (dentry->d_inode) { 363 mutex_unlock(&parent->d_inode->i_mutex);
340 dget(dentry); 364 simple_release_fs(&debugfs_mount, &debugfs_mount_count);
341 switch (dentry->d_inode->i_mode & S_IFMT) { 365}
342 case S_IFDIR: 366EXPORT_SYMBOL_GPL(debugfs_remove);
343 ret = simple_rmdir(parent->d_inode, dentry); 367
344 break; 368/**
345 case S_IFLNK: 369 * debugfs_remove_recursive - recursively removes a directory
346 kfree(dentry->d_inode->i_private); 370 * @dentry: a pointer to a the dentry of the directory to be removed.
347 /* fall through */ 371 *
348 default: 372 * This function recursively removes a directory tree in debugfs that
349 simple_unlink(parent->d_inode, dentry); 373 * was previously created with a call to another debugfs function
374 * (like debugfs_create_file() or variants thereof.)
375 *
376 * This function is required to be called in order for the file to be
377 * removed, no automatic cleanup of files will happen when a module is
378 * removed, you are responsible here.
379 */
380void debugfs_remove_recursive(struct dentry *dentry)
381{
382 struct dentry *child;
383 struct dentry *parent;
384
385 if (!dentry)
386 return;
387
388 parent = dentry->d_parent;
389 if (!parent || !parent->d_inode)
390 return;
391
392 parent = dentry;
393 mutex_lock(&parent->d_inode->i_mutex);
394
395 while (1) {
396 /*
397 * When all dentries under "parent" has been removed,
398 * walk up the tree until we reach our starting point.
399 */
400 if (list_empty(&parent->d_subdirs)) {
401 mutex_unlock(&parent->d_inode->i_mutex);
402 if (parent == dentry)
350 break; 403 break;
351 } 404 parent = parent->d_parent;
352 if (!ret) 405 mutex_lock(&parent->d_inode->i_mutex);
353 d_delete(dentry); 406 }
354 dput(dentry); 407 child = list_entry(parent->d_subdirs.next, struct dentry,
408 d_u.d_child);
409
410 /*
411 * If "child" isn't empty, walk down the tree and
412 * remove all its descendants first.
413 */
414 if (!list_empty(&child->d_subdirs)) {
415 mutex_unlock(&parent->d_inode->i_mutex);
416 parent = child;
417 mutex_lock(&parent->d_inode->i_mutex);
418 continue;
355 } 419 }
420 __debugfs_remove(child, parent);
421 if (parent->d_subdirs.next == &child->d_u.d_child) {
422 /*
423 * Avoid infinite loop if we fail to remove
424 * one dentry.
425 */
426 mutex_unlock(&parent->d_inode->i_mutex);
427 break;
428 }
429 simple_release_fs(&debugfs_mount, &debugfs_mount_count);
356 } 430 }
431
432 parent = dentry->d_parent;
433 mutex_lock(&parent->d_inode->i_mutex);
434 __debugfs_remove(dentry, parent);
357 mutex_unlock(&parent->d_inode->i_mutex); 435 mutex_unlock(&parent->d_inode->i_mutex);
358 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 436 simple_release_fs(&debugfs_mount, &debugfs_mount_count);
359} 437}
360EXPORT_SYMBOL_GPL(debugfs_remove); 438EXPORT_SYMBOL_GPL(debugfs_remove_recursive);
361 439
362/** 440/**
363 * debugfs_rename - rename a file/directory in the debugfs filesystem 441 * debugfs_rename - rename a file/directory in the debugfs filesystem
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 6149e4b58c88..efef715135d3 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -401,7 +401,7 @@ void register_disk(struct gendisk *disk)
401 disk->dev.parent = disk->driverfs_dev; 401 disk->dev.parent = disk->driverfs_dev;
402 disk->dev.devt = MKDEV(disk->major, disk->first_minor); 402 disk->dev.devt = MKDEV(disk->major, disk->first_minor);
403 403
404 strlcpy(disk->dev.bus_id, disk->disk_name, KOBJ_NAME_LEN); 404 strlcpy(disk->dev.bus_id, disk->disk_name, BUS_ID_SIZE);
405 /* ewww... some of these buggers have / in the name... */ 405 /* ewww... some of these buggers have / in the name... */
406 s = strchr(disk->dev.bus_id, '/'); 406 s = strchr(disk->dev.bus_id, '/');
407 if (s) 407 if (s)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 164bd9f9ede3..7546a918f790 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -636,7 +636,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
636 struct pagemapread pm; 636 struct pagemapread pm;
637 int pagecount; 637 int pagecount;
638 int ret = -ESRCH; 638 int ret = -ESRCH;
639 struct mm_walk pagemap_walk; 639 struct mm_walk pagemap_walk = {};
640 unsigned long src; 640 unsigned long src;
641 unsigned long svpfn; 641 unsigned long svpfn;
642 unsigned long start_vaddr; 642 unsigned long start_vaddr;
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 8c0e4b92574f..c1a7efb310bf 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -398,7 +398,7 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
398} 398}
399 399
400/** 400/**
401 * sysfs_add_one - add sysfs_dirent to parent 401 * __sysfs_add_one - add sysfs_dirent to parent without warning
402 * @acxt: addrm context to use 402 * @acxt: addrm context to use
403 * @sd: sysfs_dirent to be added 403 * @sd: sysfs_dirent to be added
404 * 404 *
@@ -417,7 +417,7 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
417 * 0 on success, -EEXIST if entry with the given name already 417 * 0 on success, -EEXIST if entry with the given name already
418 * exists. 418 * exists.
419 */ 419 */
420int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) 420int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
421{ 421{
422 if (sysfs_find_dirent(acxt->parent_sd, sd->s_name)) 422 if (sysfs_find_dirent(acxt->parent_sd, sd->s_name))
423 return -EEXIST; 423 return -EEXIST;
@@ -435,6 +435,39 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
435} 435}
436 436
437/** 437/**
438 * sysfs_add_one - add sysfs_dirent to parent
439 * @acxt: addrm context to use
440 * @sd: sysfs_dirent to be added
441 *
442 * Get @acxt->parent_sd and set sd->s_parent to it and increment
443 * nlink of parent inode if @sd is a directory and link into the
444 * children list of the parent.
445 *
446 * This function should be called between calls to
447 * sysfs_addrm_start() and sysfs_addrm_finish() and should be
448 * passed the same @acxt as passed to sysfs_addrm_start().
449 *
450 * LOCKING:
451 * Determined by sysfs_addrm_start().
452 *
453 * RETURNS:
454 * 0 on success, -EEXIST if entry with the given name already
455 * exists.
456 */
457int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
458{
459 int ret;
460
461 ret = __sysfs_add_one(acxt, sd);
462 if (ret == -EEXIST) {
463 printk(KERN_WARNING "sysfs: duplicate filename '%s' "
464 "can not be created\n", sd->s_name);
465 WARN_ON(1);
466 }
467 return ret;
468}
469
470/**
438 * sysfs_remove_one - remove sysfs_dirent from parent 471 * sysfs_remove_one - remove sysfs_dirent from parent
439 * @acxt: addrm context to use 472 * @acxt: addrm context to use
440 * @sd: sysfs_dirent to be removed 473 * @sd: sysfs_dirent to be removed
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index e7735f643cd1..3f07893ff896 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -14,6 +14,7 @@
14#include <linux/kobject.h> 14#include <linux/kobject.h>
15#include <linux/kallsyms.h> 15#include <linux/kallsyms.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/fsnotify.h>
17#include <linux/namei.h> 18#include <linux/namei.h>
18#include <linux/poll.h> 19#include <linux/poll.h>
19#include <linux/list.h> 20#include <linux/list.h>
@@ -585,9 +586,11 @@ int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode)
585 586
586 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO); 587 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
587 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; 588 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
588 rc = notify_change(victim, &newattrs); 589 newattrs.ia_ctime = current_fs_time(inode->i_sb);
590 rc = sysfs_setattr(victim, &newattrs);
589 591
590 if (rc == 0) { 592 if (rc == 0) {
593 fsnotify_change(victim, newattrs.ia_valid);
591 mutex_lock(&sysfs_mutex); 594 mutex_lock(&sysfs_mutex);
592 victim_sd->s_mode = newattrs.ia_mode; 595 victim_sd->s_mode = newattrs.ia_mode;
593 mutex_unlock(&sysfs_mutex); 596 mutex_unlock(&sysfs_mutex);
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 817f5966edca..a3ba217fbe74 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -19,13 +19,8 @@
19 19
20#include "sysfs.h" 20#include "sysfs.h"
21 21
22/** 22static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
23 * sysfs_create_link - create symlink between two objects. 23 const char *name, int warn)
24 * @kobj: object whose directory we're creating the link in.
25 * @target: object we're pointing to.
26 * @name: name of the symlink.
27 */
28int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name)
29{ 24{
30 struct sysfs_dirent *parent_sd = NULL; 25 struct sysfs_dirent *parent_sd = NULL;
31 struct sysfs_dirent *target_sd = NULL; 26 struct sysfs_dirent *target_sd = NULL;
@@ -65,7 +60,10 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
65 target_sd = NULL; /* reference is now owned by the symlink */ 60 target_sd = NULL; /* reference is now owned by the symlink */
66 61
67 sysfs_addrm_start(&acxt, parent_sd); 62 sysfs_addrm_start(&acxt, parent_sd);
68 error = sysfs_add_one(&acxt, sd); 63 if (warn)
64 error = sysfs_add_one(&acxt, sd);
65 else
66 error = __sysfs_add_one(&acxt, sd);
69 sysfs_addrm_finish(&acxt); 67 sysfs_addrm_finish(&acxt);
70 68
71 if (error) 69 if (error)
@@ -80,6 +78,33 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
80} 78}
81 79
82/** 80/**
81 * sysfs_create_link - create symlink between two objects.
82 * @kobj: object whose directory we're creating the link in.
83 * @target: object we're pointing to.
84 * @name: name of the symlink.
85 */
86int sysfs_create_link(struct kobject *kobj, struct kobject *target,
87 const char *name)
88{
89 return sysfs_do_create_link(kobj, target, name, 1);
90}
91
92/**
93 * sysfs_create_link_nowarn - create symlink between two objects.
94 * @kobj: object whose directory we're creating the link in.
95 * @target: object we're pointing to.
96 * @name: name of the symlink.
97 *
98 * This function does the same as sysf_create_link(), but it
99 * doesn't warn if the link already exists.
100 */
101int sysfs_create_link_nowarn(struct kobject *kobj, struct kobject *target,
102 const char *name)
103{
104 return sysfs_do_create_link(kobj, target, name, 0);
105}
106
107/**
83 * sysfs_remove_link - remove symlink in object's directory. 108 * sysfs_remove_link - remove symlink in object's directory.
84 * @kobj: object we're acting for. 109 * @kobj: object we're acting for.
85 * @name: name of the symlink to remove. 110 * @name: name of the symlink to remove.
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index ce4e15f8aaeb..a5db496f71c7 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -107,6 +107,7 @@ struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
107void sysfs_put_active_two(struct sysfs_dirent *sd); 107void sysfs_put_active_two(struct sysfs_dirent *sd);
108void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt, 108void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
109 struct sysfs_dirent *parent_sd); 109 struct sysfs_dirent *parent_sd);
110int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
110int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); 111int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
111void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); 112void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
112void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); 113void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
diff --git a/include/asm-ia64/Kbuild b/include/asm-ia64/Kbuild
index eb24a3f47caa..ccbe8ae47a61 100644
--- a/include/asm-ia64/Kbuild
+++ b/include/asm-ia64/Kbuild
@@ -5,12 +5,12 @@ header-y += fpu.h
5header-y += fpswa.h 5header-y += fpswa.h
6header-y += ia64regs.h 6header-y += ia64regs.h
7header-y += intel_intrin.h 7header-y += intel_intrin.h
8header-y += intrinsics.h
9header-y += perfmon_default_smpl.h 8header-y += perfmon_default_smpl.h
10header-y += ptrace_offsets.h 9header-y += ptrace_offsets.h
11header-y += rse.h 10header-y += rse.h
12header-y += ucontext.h 11header-y += ucontext.h
13 12
14unifdef-y += gcc_intrin.h 13unifdef-y += gcc_intrin.h
14unifdef-y += intrinsics.h
15unifdef-y += perfmon.h 15unifdef-y += perfmon.h
16unifdef-y += ustack.h 16unifdef-y += ustack.h
diff --git a/include/asm-ia64/gcc_intrin.h b/include/asm-ia64/gcc_intrin.h
index 2fe292c275fe..0f5b55921758 100644
--- a/include/asm-ia64/gcc_intrin.h
+++ b/include/asm-ia64/gcc_intrin.h
@@ -32,7 +32,7 @@ extern void ia64_bad_param_for_getreg (void);
32register unsigned long ia64_r13 asm ("r13") __used; 32register unsigned long ia64_r13 asm ("r13") __used;
33#endif 33#endif
34 34
35#define ia64_setreg(regnum, val) \ 35#define ia64_native_setreg(regnum, val) \
36({ \ 36({ \
37 switch (regnum) { \ 37 switch (regnum) { \
38 case _IA64_REG_PSR_L: \ 38 case _IA64_REG_PSR_L: \
@@ -61,7 +61,7 @@ register unsigned long ia64_r13 asm ("r13") __used;
61 } \ 61 } \
62}) 62})
63 63
64#define ia64_getreg(regnum) \ 64#define ia64_native_getreg(regnum) \
65({ \ 65({ \
66 __u64 ia64_intri_res; \ 66 __u64 ia64_intri_res; \
67 \ 67 \
@@ -385,7 +385,7 @@ register unsigned long ia64_r13 asm ("r13") __used;
385 385
386#define ia64_invala() asm volatile ("invala" ::: "memory") 386#define ia64_invala() asm volatile ("invala" ::: "memory")
387 387
388#define ia64_thash(addr) \ 388#define ia64_native_thash(addr) \
389({ \ 389({ \
390 __u64 ia64_intri_res; \ 390 __u64 ia64_intri_res; \
391 asm volatile ("thash %0=%1" : "=r"(ia64_intri_res) : "r" (addr)); \ 391 asm volatile ("thash %0=%1" : "=r"(ia64_intri_res) : "r" (addr)); \
@@ -438,10 +438,10 @@ register unsigned long ia64_r13 asm ("r13") __used;
438#define ia64_set_pmd(index, val) \ 438#define ia64_set_pmd(index, val) \
439 asm volatile ("mov pmd[%0]=%1" :: "r"(index), "r"(val) : "memory") 439 asm volatile ("mov pmd[%0]=%1" :: "r"(index), "r"(val) : "memory")
440 440
441#define ia64_set_rr(index, val) \ 441#define ia64_native_set_rr(index, val) \
442 asm volatile ("mov rr[%0]=%1" :: "r"(index), "r"(val) : "memory"); 442 asm volatile ("mov rr[%0]=%1" :: "r"(index), "r"(val) : "memory");
443 443
444#define ia64_get_cpuid(index) \ 444#define ia64_native_get_cpuid(index) \
445({ \ 445({ \
446 __u64 ia64_intri_res; \ 446 __u64 ia64_intri_res; \
447 asm volatile ("mov %0=cpuid[%r1]" : "=r"(ia64_intri_res) : "rO"(index)); \ 447 asm volatile ("mov %0=cpuid[%r1]" : "=r"(ia64_intri_res) : "rO"(index)); \
@@ -477,33 +477,33 @@ register unsigned long ia64_r13 asm ("r13") __used;
477}) 477})
478 478
479 479
480#define ia64_get_pmd(index) \ 480#define ia64_native_get_pmd(index) \
481({ \ 481({ \
482 __u64 ia64_intri_res; \ 482 __u64 ia64_intri_res; \
483 asm volatile ("mov %0=pmd[%1]" : "=r"(ia64_intri_res) : "r"(index)); \ 483 asm volatile ("mov %0=pmd[%1]" : "=r"(ia64_intri_res) : "r"(index)); \
484 ia64_intri_res; \ 484 ia64_intri_res; \
485}) 485})
486 486
487#define ia64_get_rr(index) \ 487#define ia64_native_get_rr(index) \
488({ \ 488({ \
489 __u64 ia64_intri_res; \ 489 __u64 ia64_intri_res; \
490 asm volatile ("mov %0=rr[%1]" : "=r"(ia64_intri_res) : "r" (index)); \ 490 asm volatile ("mov %0=rr[%1]" : "=r"(ia64_intri_res) : "r" (index)); \
491 ia64_intri_res; \ 491 ia64_intri_res; \
492}) 492})
493 493
494#define ia64_fc(addr) asm volatile ("fc %0" :: "r"(addr) : "memory") 494#define ia64_native_fc(addr) asm volatile ("fc %0" :: "r"(addr) : "memory")
495 495
496 496
497#define ia64_sync_i() asm volatile (";; sync.i" ::: "memory") 497#define ia64_sync_i() asm volatile (";; sync.i" ::: "memory")
498 498
499#define ia64_ssm(mask) asm volatile ("ssm %0":: "i"((mask)) : "memory") 499#define ia64_native_ssm(mask) asm volatile ("ssm %0":: "i"((mask)) : "memory")
500#define ia64_rsm(mask) asm volatile ("rsm %0":: "i"((mask)) : "memory") 500#define ia64_native_rsm(mask) asm volatile ("rsm %0":: "i"((mask)) : "memory")
501#define ia64_sum(mask) asm volatile ("sum %0":: "i"((mask)) : "memory") 501#define ia64_sum(mask) asm volatile ("sum %0":: "i"((mask)) : "memory")
502#define ia64_rum(mask) asm volatile ("rum %0":: "i"((mask)) : "memory") 502#define ia64_rum(mask) asm volatile ("rum %0":: "i"((mask)) : "memory")
503 503
504#define ia64_ptce(addr) asm volatile ("ptc.e %0" :: "r"(addr)) 504#define ia64_ptce(addr) asm volatile ("ptc.e %0" :: "r"(addr))
505 505
506#define ia64_ptcga(addr, size) \ 506#define ia64_native_ptcga(addr, size) \
507do { \ 507do { \
508 asm volatile ("ptc.ga %0,%1" :: "r"(addr), "r"(size) : "memory"); \ 508 asm volatile ("ptc.ga %0,%1" :: "r"(addr), "r"(size) : "memory"); \
509 ia64_dv_serialize_data(); \ 509 ia64_dv_serialize_data(); \
@@ -608,7 +608,7 @@ do { \
608 } \ 608 } \
609}) 609})
610 610
611#define ia64_intrin_local_irq_restore(x) \ 611#define ia64_native_intrin_local_irq_restore(x) \
612do { \ 612do { \
613 asm volatile (";; cmp.ne p6,p7=%0,r0;;" \ 613 asm volatile (";; cmp.ne p6,p7=%0,r0;;" \
614 "(p6) ssm psr.i;" \ 614 "(p6) ssm psr.i;" \
diff --git a/include/asm-ia64/hw_irq.h b/include/asm-ia64/hw_irq.h
index 76366dc9c1a0..5c99cbcb8a0d 100644
--- a/include/asm-ia64/hw_irq.h
+++ b/include/asm-ia64/hw_irq.h
@@ -15,7 +15,11 @@
15#include <asm/ptrace.h> 15#include <asm/ptrace.h>
16#include <asm/smp.h> 16#include <asm/smp.h>
17 17
18#ifndef CONFIG_PARAVIRT
18typedef u8 ia64_vector; 19typedef u8 ia64_vector;
20#else
21typedef u16 ia64_vector;
22#endif
19 23
20/* 24/*
21 * 0 special 25 * 0 special
@@ -104,13 +108,24 @@ DECLARE_PER_CPU(int[IA64_NUM_VECTORS], vector_irq);
104 108
105extern struct hw_interrupt_type irq_type_ia64_lsapic; /* CPU-internal interrupt controller */ 109extern struct hw_interrupt_type irq_type_ia64_lsapic; /* CPU-internal interrupt controller */
106 110
111#ifdef CONFIG_PARAVIRT_GUEST
112#include <asm/paravirt.h>
113#else
114#define ia64_register_ipi ia64_native_register_ipi
115#define assign_irq_vector ia64_native_assign_irq_vector
116#define free_irq_vector ia64_native_free_irq_vector
117#define register_percpu_irq ia64_native_register_percpu_irq
118#define ia64_resend_irq ia64_native_resend_irq
119#endif
120
121extern void ia64_native_register_ipi(void);
107extern int bind_irq_vector(int irq, int vector, cpumask_t domain); 122extern int bind_irq_vector(int irq, int vector, cpumask_t domain);
108extern int assign_irq_vector (int irq); /* allocate a free vector */ 123extern int ia64_native_assign_irq_vector (int irq); /* allocate a free vector */
109extern void free_irq_vector (int vector); 124extern void ia64_native_free_irq_vector (int vector);
110extern int reserve_irq_vector (int vector); 125extern int reserve_irq_vector (int vector);
111extern void __setup_vector_irq(int cpu); 126extern void __setup_vector_irq(int cpu);
112extern void ia64_send_ipi (int cpu, int vector, int delivery_mode, int redirect); 127extern void ia64_send_ipi (int cpu, int vector, int delivery_mode, int redirect);
113extern void register_percpu_irq (ia64_vector vec, struct irqaction *action); 128extern void ia64_native_register_percpu_irq (ia64_vector vec, struct irqaction *action);
114extern int check_irq_used (int irq); 129extern int check_irq_used (int irq);
115extern void destroy_and_reserve_irq (unsigned int irq); 130extern void destroy_and_reserve_irq (unsigned int irq);
116 131
@@ -122,7 +137,7 @@ static inline int irq_prepare_move(int irq, int cpu) { return 0; }
122static inline void irq_complete_move(unsigned int irq) {} 137static inline void irq_complete_move(unsigned int irq) {}
123#endif 138#endif
124 139
125static inline void ia64_resend_irq(unsigned int vector) 140static inline void ia64_native_resend_irq(unsigned int vector)
126{ 141{
127 platform_send_ipi(smp_processor_id(), vector, IA64_IPI_DM_INT, 0); 142 platform_send_ipi(smp_processor_id(), vector, IA64_IPI_DM_INT, 0);
128} 143}
diff --git a/include/asm-ia64/intel_intrin.h b/include/asm-ia64/intel_intrin.h
index a520d103d808..53cec577558a 100644
--- a/include/asm-ia64/intel_intrin.h
+++ b/include/asm-ia64/intel_intrin.h
@@ -16,8 +16,8 @@
16 * intrinsic 16 * intrinsic
17 */ 17 */
18 18
19#define ia64_getreg __getReg 19#define ia64_native_getreg __getReg
20#define ia64_setreg __setReg 20#define ia64_native_setreg __setReg
21 21
22#define ia64_hint __hint 22#define ia64_hint __hint
23#define ia64_hint_pause __hint_pause 23#define ia64_hint_pause __hint_pause
@@ -39,10 +39,10 @@
39#define ia64_invala_fr __invala_fr 39#define ia64_invala_fr __invala_fr
40#define ia64_nop __nop 40#define ia64_nop __nop
41#define ia64_sum __sum 41#define ia64_sum __sum
42#define ia64_ssm __ssm 42#define ia64_native_ssm __ssm
43#define ia64_rum __rum 43#define ia64_rum __rum
44#define ia64_rsm __rsm 44#define ia64_native_rsm __rsm
45#define ia64_fc __fc 45#define ia64_native_fc __fc
46 46
47#define ia64_ldfs __ldfs 47#define ia64_ldfs __ldfs
48#define ia64_ldfd __ldfd 48#define ia64_ldfd __ldfd
@@ -88,16 +88,17 @@
88 __setIndReg(_IA64_REG_INDR_PMC, index, val) 88 __setIndReg(_IA64_REG_INDR_PMC, index, val)
89#define ia64_set_pmd(index, val) \ 89#define ia64_set_pmd(index, val) \
90 __setIndReg(_IA64_REG_INDR_PMD, index, val) 90 __setIndReg(_IA64_REG_INDR_PMD, index, val)
91#define ia64_set_rr(index, val) \ 91#define ia64_native_set_rr(index, val) \
92 __setIndReg(_IA64_REG_INDR_RR, index, val) 92 __setIndReg(_IA64_REG_INDR_RR, index, val)
93 93
94#define ia64_get_cpuid(index) __getIndReg(_IA64_REG_INDR_CPUID, index) 94#define ia64_native_get_cpuid(index) \
95#define __ia64_get_dbr(index) __getIndReg(_IA64_REG_INDR_DBR, index) 95 __getIndReg(_IA64_REG_INDR_CPUID, index)
96#define ia64_get_ibr(index) __getIndReg(_IA64_REG_INDR_IBR, index) 96#define __ia64_get_dbr(index) __getIndReg(_IA64_REG_INDR_DBR, index)
97#define ia64_get_pkr(index) __getIndReg(_IA64_REG_INDR_PKR, index) 97#define ia64_get_ibr(index) __getIndReg(_IA64_REG_INDR_IBR, index)
98#define ia64_get_pmc(index) __getIndReg(_IA64_REG_INDR_PMC, index) 98#define ia64_get_pkr(index) __getIndReg(_IA64_REG_INDR_PKR, index)
99#define ia64_get_pmd(index) __getIndReg(_IA64_REG_INDR_PMD, index) 99#define ia64_get_pmc(index) __getIndReg(_IA64_REG_INDR_PMC, index)
100#define ia64_get_rr(index) __getIndReg(_IA64_REG_INDR_RR, index) 100#define ia64_native_get_pmd(index) __getIndReg(_IA64_REG_INDR_PMD, index)
101#define ia64_native_get_rr(index) __getIndReg(_IA64_REG_INDR_RR, index)
101 102
102#define ia64_srlz_d __dsrlz 103#define ia64_srlz_d __dsrlz
103#define ia64_srlz_i __isrlz 104#define ia64_srlz_i __isrlz
@@ -119,16 +120,16 @@
119#define ia64_ld8_acq __ld8_acq 120#define ia64_ld8_acq __ld8_acq
120 121
121#define ia64_sync_i __synci 122#define ia64_sync_i __synci
122#define ia64_thash __thash 123#define ia64_native_thash __thash
123#define ia64_ttag __ttag 124#define ia64_native_ttag __ttag
124#define ia64_itcd __itcd 125#define ia64_itcd __itcd
125#define ia64_itci __itci 126#define ia64_itci __itci
126#define ia64_itrd __itrd 127#define ia64_itrd __itrd
127#define ia64_itri __itri 128#define ia64_itri __itri
128#define ia64_ptce __ptce 129#define ia64_ptce __ptce
129#define ia64_ptcl __ptcl 130#define ia64_ptcl __ptcl
130#define ia64_ptcg __ptcg 131#define ia64_native_ptcg __ptcg
131#define ia64_ptcga __ptcga 132#define ia64_native_ptcga __ptcga
132#define ia64_ptri __ptri 133#define ia64_ptri __ptri
133#define ia64_ptrd __ptrd 134#define ia64_ptrd __ptrd
134#define ia64_dep_mi _m64_dep_mi 135#define ia64_dep_mi _m64_dep_mi
@@ -145,13 +146,13 @@
145#define ia64_lfetch_fault __lfetch_fault 146#define ia64_lfetch_fault __lfetch_fault
146#define ia64_lfetch_fault_excl __lfetch_fault_excl 147#define ia64_lfetch_fault_excl __lfetch_fault_excl
147 148
148#define ia64_intrin_local_irq_restore(x) \ 149#define ia64_native_intrin_local_irq_restore(x) \
149do { \ 150do { \
150 if ((x) != 0) { \ 151 if ((x) != 0) { \
151 ia64_ssm(IA64_PSR_I); \ 152 ia64_native_ssm(IA64_PSR_I); \
152 ia64_srlz_d(); \ 153 ia64_srlz_d(); \
153 } else { \ 154 } else { \
154 ia64_rsm(IA64_PSR_I); \ 155 ia64_native_rsm(IA64_PSR_I); \
155 } \ 156 } \
156} while (0) 157} while (0)
157 158
diff --git a/include/asm-ia64/intrinsics.h b/include/asm-ia64/intrinsics.h
index f1135b5b94c3..47d686dba1eb 100644
--- a/include/asm-ia64/intrinsics.h
+++ b/include/asm-ia64/intrinsics.h
@@ -18,6 +18,17 @@
18# include <asm/gcc_intrin.h> 18# include <asm/gcc_intrin.h>
19#endif 19#endif
20 20
21#define ia64_native_get_psr_i() (ia64_native_getreg(_IA64_REG_PSR) & IA64_PSR_I)
22
23#define ia64_native_set_rr0_to_rr4(val0, val1, val2, val3, val4) \
24do { \
25 ia64_native_set_rr(0x0000000000000000UL, (val0)); \
26 ia64_native_set_rr(0x2000000000000000UL, (val1)); \
27 ia64_native_set_rr(0x4000000000000000UL, (val2)); \
28 ia64_native_set_rr(0x6000000000000000UL, (val3)); \
29 ia64_native_set_rr(0x8000000000000000UL, (val4)); \
30} while (0)
31
21/* 32/*
22 * Force an unresolved reference if someone tries to use 33 * Force an unresolved reference if someone tries to use
23 * ia64_fetch_and_add() with a bad value. 34 * ia64_fetch_and_add() with a bad value.
@@ -183,4 +194,48 @@ extern long ia64_cmpxchg_called_with_bad_pointer (void);
183#endif /* !CONFIG_IA64_DEBUG_CMPXCHG */ 194#endif /* !CONFIG_IA64_DEBUG_CMPXCHG */
184 195
185#endif 196#endif
197
198#ifdef __KERNEL__
199#include <asm/paravirt_privop.h>
200#endif
201
202#ifndef __ASSEMBLY__
203#if defined(CONFIG_PARAVIRT) && defined(__KERNEL__)
204#define IA64_INTRINSIC_API(name) pv_cpu_ops.name
205#define IA64_INTRINSIC_MACRO(name) paravirt_ ## name
206#else
207#define IA64_INTRINSIC_API(name) ia64_native_ ## name
208#define IA64_INTRINSIC_MACRO(name) ia64_native_ ## name
209#endif
210
211/************************************************/
212/* Instructions paravirtualized for correctness */
213/************************************************/
214/* fc, thash, get_cpuid, get_pmd, get_eflags, set_eflags */
215/* Note that "ttag" and "cover" are also privilege-sensitive; "ttag"
216 * is not currently used (though it may be in a long-format VHPT system!)
217 */
218#define ia64_fc IA64_INTRINSIC_API(fc)
219#define ia64_thash IA64_INTRINSIC_API(thash)
220#define ia64_get_cpuid IA64_INTRINSIC_API(get_cpuid)
221#define ia64_get_pmd IA64_INTRINSIC_API(get_pmd)
222
223
224/************************************************/
225/* Instructions paravirtualized for performance */
226/************************************************/
227#define ia64_ssm IA64_INTRINSIC_MACRO(ssm)
228#define ia64_rsm IA64_INTRINSIC_MACRO(rsm)
229#define ia64_getreg IA64_INTRINSIC_API(getreg)
230#define ia64_setreg IA64_INTRINSIC_API(setreg)
231#define ia64_set_rr IA64_INTRINSIC_API(set_rr)
232#define ia64_get_rr IA64_INTRINSIC_API(get_rr)
233#define ia64_ptcga IA64_INTRINSIC_API(ptcga)
234#define ia64_get_psr_i IA64_INTRINSIC_API(get_psr_i)
235#define ia64_intrin_local_irq_restore \
236 IA64_INTRINSIC_API(intrin_local_irq_restore)
237#define ia64_set_rr0_to_rr4 IA64_INTRINSIC_API(set_rr0_to_rr4)
238
239#endif /* !__ASSEMBLY__ */
240
186#endif /* _ASM_IA64_INTRINSICS_H */ 241#endif /* _ASM_IA64_INTRINSICS_H */
diff --git a/include/asm-ia64/iosapic.h b/include/asm-ia64/iosapic.h
index a3a4288daae8..b9c102e15f22 100644
--- a/include/asm-ia64/iosapic.h
+++ b/include/asm-ia64/iosapic.h
@@ -55,13 +55,27 @@
55 55
56#define NR_IOSAPICS 256 56#define NR_IOSAPICS 256
57 57
58static inline unsigned int __iosapic_read(char __iomem *iosapic, unsigned int reg) 58#ifdef CONFIG_PARAVIRT_GUEST
59#include <asm/paravirt.h>
60#else
61#define iosapic_pcat_compat_init ia64_native_iosapic_pcat_compat_init
62#define __iosapic_read __ia64_native_iosapic_read
63#define __iosapic_write __ia64_native_iosapic_write
64#define iosapic_get_irq_chip ia64_native_iosapic_get_irq_chip
65#endif
66
67extern void __init ia64_native_iosapic_pcat_compat_init(void);
68extern struct irq_chip *ia64_native_iosapic_get_irq_chip(unsigned long trigger);
69
70static inline unsigned int
71__ia64_native_iosapic_read(char __iomem *iosapic, unsigned int reg)
59{ 72{
60 writel(reg, iosapic + IOSAPIC_REG_SELECT); 73 writel(reg, iosapic + IOSAPIC_REG_SELECT);
61 return readl(iosapic + IOSAPIC_WINDOW); 74 return readl(iosapic + IOSAPIC_WINDOW);
62} 75}
63 76
64static inline void __iosapic_write(char __iomem *iosapic, unsigned int reg, u32 val) 77static inline void
78__ia64_native_iosapic_write(char __iomem *iosapic, unsigned int reg, u32 val)
65{ 79{
66 writel(reg, iosapic + IOSAPIC_REG_SELECT); 80 writel(reg, iosapic + IOSAPIC_REG_SELECT);
67 writel(val, iosapic + IOSAPIC_WINDOW); 81 writel(val, iosapic + IOSAPIC_WINDOW);
diff --git a/include/asm-ia64/irq.h b/include/asm-ia64/irq.h
index a66d26827cbb..3627116fb0e2 100644
--- a/include/asm-ia64/irq.h
+++ b/include/asm-ia64/irq.h
@@ -13,14 +13,7 @@
13 13
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/cpumask.h> 15#include <linux/cpumask.h>
16 16#include <asm-ia64/nr-irqs.h>
17#define NR_VECTORS 256
18
19#if (NR_VECTORS + 32 * NR_CPUS) < 1024
20#define NR_IRQS (NR_VECTORS + 32 * NR_CPUS)
21#else
22#define NR_IRQS 1024
23#endif
24 17
25static __inline__ int 18static __inline__ int
26irq_canonicalize (int irq) 19irq_canonicalize (int irq)
diff --git a/include/asm-ia64/mmu_context.h b/include/asm-ia64/mmu_context.h
index cef2400983fa..040bc87db930 100644
--- a/include/asm-ia64/mmu_context.h
+++ b/include/asm-ia64/mmu_context.h
@@ -152,11 +152,7 @@ reload_context (nv_mm_context_t context)
152# endif 152# endif
153#endif 153#endif
154 154
155 ia64_set_rr(0x0000000000000000UL, rr0); 155 ia64_set_rr0_to_rr4(rr0, rr1, rr2, rr3, rr4);
156 ia64_set_rr(0x2000000000000000UL, rr1);
157 ia64_set_rr(0x4000000000000000UL, rr2);
158 ia64_set_rr(0x6000000000000000UL, rr3);
159 ia64_set_rr(0x8000000000000000UL, rr4);
160 ia64_srlz_i(); /* srlz.i implies srlz.d */ 156 ia64_srlz_i(); /* srlz.i implies srlz.d */
161} 157}
162 158
diff --git a/include/asm-ia64/native/inst.h b/include/asm-ia64/native/inst.h
new file mode 100644
index 000000000000..c953a2ca4fce
--- /dev/null
+++ b/include/asm-ia64/native/inst.h
@@ -0,0 +1,175 @@
1/******************************************************************************
2 * include/asm-ia64/native/inst.h
3 *
4 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#define DO_SAVE_MIN IA64_NATIVE_DO_SAVE_MIN
24
25#define __paravirt_switch_to ia64_native_switch_to
26#define __paravirt_leave_syscall ia64_native_leave_syscall
27#define __paravirt_work_processed_syscall ia64_native_work_processed_syscall
28#define __paravirt_leave_kernel ia64_native_leave_kernel
29#define __paravirt_pending_syscall_end ia64_work_pending_syscall_end
30#define __paravirt_work_processed_syscall_target \
31 ia64_work_processed_syscall
32
33#ifdef CONFIG_PARAVIRT_GUEST_ASM_CLOBBER_CHECK
34# define PARAVIRT_POISON 0xdeadbeefbaadf00d
35# define CLOBBER(clob) \
36 ;; \
37 movl clob = PARAVIRT_POISON; \
38 ;;
39#else
40# define CLOBBER(clob) /* nothing */
41#endif
42
43#define MOV_FROM_IFA(reg) \
44 mov reg = cr.ifa
45
46#define MOV_FROM_ITIR(reg) \
47 mov reg = cr.itir
48
49#define MOV_FROM_ISR(reg) \
50 mov reg = cr.isr
51
52#define MOV_FROM_IHA(reg) \
53 mov reg = cr.iha
54
55#define MOV_FROM_IPSR(pred, reg) \
56(pred) mov reg = cr.ipsr
57
58#define MOV_FROM_IIM(reg) \
59 mov reg = cr.iim
60
61#define MOV_FROM_IIP(reg) \
62 mov reg = cr.iip
63
64#define MOV_FROM_IVR(reg, clob) \
65 mov reg = cr.ivr \
66 CLOBBER(clob)
67
68#define MOV_FROM_PSR(pred, reg, clob) \
69(pred) mov reg = psr \
70 CLOBBER(clob)
71
72#define MOV_TO_IFA(reg, clob) \
73 mov cr.ifa = reg \
74 CLOBBER(clob)
75
76#define MOV_TO_ITIR(pred, reg, clob) \
77(pred) mov cr.itir = reg \
78 CLOBBER(clob)
79
80#define MOV_TO_IHA(pred, reg, clob) \
81(pred) mov cr.iha = reg \
82 CLOBBER(clob)
83
84#define MOV_TO_IPSR(pred, reg, clob) \
85(pred) mov cr.ipsr = reg \
86 CLOBBER(clob)
87
88#define MOV_TO_IFS(pred, reg, clob) \
89(pred) mov cr.ifs = reg \
90 CLOBBER(clob)
91
92#define MOV_TO_IIP(reg, clob) \
93 mov cr.iip = reg \
94 CLOBBER(clob)
95
96#define MOV_TO_KR(kr, reg, clob0, clob1) \
97 mov IA64_KR(kr) = reg \
98 CLOBBER(clob0) \
99 CLOBBER(clob1)
100
101#define ITC_I(pred, reg, clob) \
102(pred) itc.i reg \
103 CLOBBER(clob)
104
105#define ITC_D(pred, reg, clob) \
106(pred) itc.d reg \
107 CLOBBER(clob)
108
109#define ITC_I_AND_D(pred_i, pred_d, reg, clob) \
110(pred_i) itc.i reg; \
111(pred_d) itc.d reg \
112 CLOBBER(clob)
113
114#define THASH(pred, reg0, reg1, clob) \
115(pred) thash reg0 = reg1 \
116 CLOBBER(clob)
117
118#define SSM_PSR_IC_AND_DEFAULT_BITS_AND_SRLZ_I(clob0, clob1) \
119 ssm psr.ic | PSR_DEFAULT_BITS \
120 CLOBBER(clob0) \
121 CLOBBER(clob1) \
122 ;; \
123 srlz.i /* guarantee that interruption collectin is on */ \
124 ;;
125
126#define SSM_PSR_IC_AND_SRLZ_D(clob0, clob1) \
127 ssm psr.ic \
128 CLOBBER(clob0) \
129 CLOBBER(clob1) \
130 ;; \
131 srlz.d
132
133#define RSM_PSR_IC(clob) \
134 rsm psr.ic \
135 CLOBBER(clob)
136
137#define SSM_PSR_I(pred, pred_clob, clob) \
138(pred) ssm psr.i \
139 CLOBBER(clob)
140
141#define RSM_PSR_I(pred, clob0, clob1) \
142(pred) rsm psr.i \
143 CLOBBER(clob0) \
144 CLOBBER(clob1)
145
146#define RSM_PSR_I_IC(clob0, clob1, clob2) \
147 rsm psr.i | psr.ic \
148 CLOBBER(clob0) \
149 CLOBBER(clob1) \
150 CLOBBER(clob2)
151
152#define RSM_PSR_DT \
153 rsm psr.dt
154
155#define SSM_PSR_DT_AND_SRLZ_I \
156 ssm psr.dt \
157 ;; \
158 srlz.i
159
160#define BSW_0(clob0, clob1, clob2) \
161 bsw.0 \
162 CLOBBER(clob0) \
163 CLOBBER(clob1) \
164 CLOBBER(clob2)
165
166#define BSW_1(clob0, clob1) \
167 bsw.1 \
168 CLOBBER(clob0) \
169 CLOBBER(clob1)
170
171#define COVER \
172 cover
173
174#define RFI \
175 rfi
diff --git a/include/asm-ia64/native/irq.h b/include/asm-ia64/native/irq.h
new file mode 100644
index 000000000000..efe9ff74a3c4
--- /dev/null
+++ b/include/asm-ia64/native/irq.h
@@ -0,0 +1,35 @@
1/******************************************************************************
2 * include/asm-ia64/native/irq.h
3 *
4 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * moved from linux/include/asm-ia64/irq.h.
22 */
23
24#ifndef _ASM_IA64_NATIVE_IRQ_H
25#define _ASM_IA64_NATIVE_IRQ_H
26
27#define NR_VECTORS 256
28
29#if (NR_VECTORS + 32 * NR_CPUS) < 1024
30#define IA64_NATIVE_NR_IRQS (NR_VECTORS + 32 * NR_CPUS)
31#else
32#define IA64_NATIVE_NR_IRQS 1024
33#endif
34
35#endif /* _ASM_IA64_NATIVE_IRQ_H */
diff --git a/include/asm-ia64/paravirt.h b/include/asm-ia64/paravirt.h
new file mode 100644
index 000000000000..1b4df129f579
--- /dev/null
+++ b/include/asm-ia64/paravirt.h
@@ -0,0 +1,255 @@
1/******************************************************************************
2 * include/asm-ia64/paravirt.h
3 *
4 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23
24#ifndef __ASM_PARAVIRT_H
25#define __ASM_PARAVIRT_H
26
27#ifdef CONFIG_PARAVIRT_GUEST
28
29#define PARAVIRT_HYPERVISOR_TYPE_DEFAULT 0
30#define PARAVIRT_HYPERVISOR_TYPE_XEN 1
31
32#ifndef __ASSEMBLY__
33
34#include <asm/hw_irq.h>
35#include <asm/meminit.h>
36
37/******************************************************************************
38 * general info
39 */
40struct pv_info {
41 unsigned int kernel_rpl;
42 int paravirt_enabled;
43 const char *name;
44};
45
46extern struct pv_info pv_info;
47
48static inline int paravirt_enabled(void)
49{
50 return pv_info.paravirt_enabled;
51}
52
53static inline unsigned int get_kernel_rpl(void)
54{
55 return pv_info.kernel_rpl;
56}
57
58/******************************************************************************
59 * initialization hooks.
60 */
61struct rsvd_region;
62
63struct pv_init_ops {
64 void (*banner)(void);
65
66 int (*reserve_memory)(struct rsvd_region *region);
67
68 void (*arch_setup_early)(void);
69 void (*arch_setup_console)(char **cmdline_p);
70 int (*arch_setup_nomca)(void);
71
72 void (*post_smp_prepare_boot_cpu)(void);
73};
74
75extern struct pv_init_ops pv_init_ops;
76
77static inline void paravirt_banner(void)
78{
79 if (pv_init_ops.banner)
80 pv_init_ops.banner();
81}
82
83static inline int paravirt_reserve_memory(struct rsvd_region *region)
84{
85 if (pv_init_ops.reserve_memory)
86 return pv_init_ops.reserve_memory(region);
87 return 0;
88}
89
90static inline void paravirt_arch_setup_early(void)
91{
92 if (pv_init_ops.arch_setup_early)
93 pv_init_ops.arch_setup_early();
94}
95
96static inline void paravirt_arch_setup_console(char **cmdline_p)
97{
98 if (pv_init_ops.arch_setup_console)
99 pv_init_ops.arch_setup_console(cmdline_p);
100}
101
102static inline int paravirt_arch_setup_nomca(void)
103{
104 if (pv_init_ops.arch_setup_nomca)
105 return pv_init_ops.arch_setup_nomca();
106 return 0;
107}
108
109static inline void paravirt_post_smp_prepare_boot_cpu(void)
110{
111 if (pv_init_ops.post_smp_prepare_boot_cpu)
112 pv_init_ops.post_smp_prepare_boot_cpu();
113}
114
115/******************************************************************************
116 * replacement of iosapic operations.
117 */
118
119struct pv_iosapic_ops {
120 void (*pcat_compat_init)(void);
121
122 struct irq_chip *(*get_irq_chip)(unsigned long trigger);
123
124 unsigned int (*__read)(char __iomem *iosapic, unsigned int reg);
125 void (*__write)(char __iomem *iosapic, unsigned int reg, u32 val);
126};
127
128extern struct pv_iosapic_ops pv_iosapic_ops;
129
130static inline void
131iosapic_pcat_compat_init(void)
132{
133 if (pv_iosapic_ops.pcat_compat_init)
134 pv_iosapic_ops.pcat_compat_init();
135}
136
137static inline struct irq_chip*
138iosapic_get_irq_chip(unsigned long trigger)
139{
140 return pv_iosapic_ops.get_irq_chip(trigger);
141}
142
143static inline unsigned int
144__iosapic_read(char __iomem *iosapic, unsigned int reg)
145{
146 return pv_iosapic_ops.__read(iosapic, reg);
147}
148
149static inline void
150__iosapic_write(char __iomem *iosapic, unsigned int reg, u32 val)
151{
152 return pv_iosapic_ops.__write(iosapic, reg, val);
153}
154
155/******************************************************************************
156 * replacement of irq operations.
157 */
158
159struct pv_irq_ops {
160 void (*register_ipi)(void);
161
162 int (*assign_irq_vector)(int irq);
163 void (*free_irq_vector)(int vector);
164
165 void (*register_percpu_irq)(ia64_vector vec,
166 struct irqaction *action);
167
168 void (*resend_irq)(unsigned int vector);
169};
170
171extern struct pv_irq_ops pv_irq_ops;
172
173static inline void
174ia64_register_ipi(void)
175{
176 pv_irq_ops.register_ipi();
177}
178
179static inline int
180assign_irq_vector(int irq)
181{
182 return pv_irq_ops.assign_irq_vector(irq);
183}
184
185static inline void
186free_irq_vector(int vector)
187{
188 return pv_irq_ops.free_irq_vector(vector);
189}
190
191static inline void
192register_percpu_irq(ia64_vector vec, struct irqaction *action)
193{
194 pv_irq_ops.register_percpu_irq(vec, action);
195}
196
197static inline void
198ia64_resend_irq(unsigned int vector)
199{
200 pv_irq_ops.resend_irq(vector);
201}
202
203/******************************************************************************
204 * replacement of time operations.
205 */
206
207extern struct itc_jitter_data_t itc_jitter_data;
208extern volatile int time_keeper_id;
209
210struct pv_time_ops {
211 void (*init_missing_ticks_accounting)(int cpu);
212 int (*do_steal_accounting)(unsigned long *new_itm);
213
214 void (*clocksource_resume)(void);
215};
216
217extern struct pv_time_ops pv_time_ops;
218
219static inline void
220paravirt_init_missing_ticks_accounting(int cpu)
221{
222 if (pv_time_ops.init_missing_ticks_accounting)
223 pv_time_ops.init_missing_ticks_accounting(cpu);
224}
225
226static inline int
227paravirt_do_steal_accounting(unsigned long *new_itm)
228{
229 return pv_time_ops.do_steal_accounting(new_itm);
230}
231
232#endif /* !__ASSEMBLY__ */
233
234#else
235/* fallback for native case */
236
237#ifndef __ASSEMBLY__
238
239#define paravirt_banner() do { } while (0)
240#define paravirt_reserve_memory(region) 0
241
242#define paravirt_arch_setup_early() do { } while (0)
243#define paravirt_arch_setup_console(cmdline_p) do { } while (0)
244#define paravirt_arch_setup_nomca() 0
245#define paravirt_post_smp_prepare_boot_cpu() do { } while (0)
246
247#define paravirt_init_missing_ticks_accounting(cpu) do { } while (0)
248#define paravirt_do_steal_accounting(new_itm) 0
249
250#endif /* __ASSEMBLY__ */
251
252
253#endif /* CONFIG_PARAVIRT_GUEST */
254
255#endif /* __ASM_PARAVIRT_H */
diff --git a/include/asm-ia64/paravirt_privop.h b/include/asm-ia64/paravirt_privop.h
new file mode 100644
index 000000000000..52482e6940ac
--- /dev/null
+++ b/include/asm-ia64/paravirt_privop.h
@@ -0,0 +1,114 @@
1/******************************************************************************
2 * include/asm-ia64/paravirt_privops.h
3 *
4 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#ifndef _ASM_IA64_PARAVIRT_PRIVOP_H
24#define _ASM_IA64_PARAVIRT_PRIVOP_H
25
26#ifdef CONFIG_PARAVIRT
27
28#ifndef __ASSEMBLY__
29
30#include <linux/types.h>
31#include <asm/kregs.h> /* for IA64_PSR_I */
32
33/******************************************************************************
34 * replacement of intrinsics operations.
35 */
36
37struct pv_cpu_ops {
38 void (*fc)(unsigned long addr);
39 unsigned long (*thash)(unsigned long addr);
40 unsigned long (*get_cpuid)(int index);
41 unsigned long (*get_pmd)(int index);
42 unsigned long (*getreg)(int reg);
43 void (*setreg)(int reg, unsigned long val);
44 void (*ptcga)(unsigned long addr, unsigned long size);
45 unsigned long (*get_rr)(unsigned long index);
46 void (*set_rr)(unsigned long index, unsigned long val);
47 void (*set_rr0_to_rr4)(unsigned long val0, unsigned long val1,
48 unsigned long val2, unsigned long val3,
49 unsigned long val4);
50 void (*ssm_i)(void);
51 void (*rsm_i)(void);
52 unsigned long (*get_psr_i)(void);
53 void (*intrin_local_irq_restore)(unsigned long flags);
54};
55
56extern struct pv_cpu_ops pv_cpu_ops;
57
58extern void ia64_native_setreg_func(int regnum, unsigned long val);
59extern unsigned long ia64_native_getreg_func(int regnum);
60
61/************************************************/
62/* Instructions paravirtualized for performance */
63/************************************************/
64
65/* mask for ia64_native_ssm/rsm() must be constant.("i" constraing).
66 * static inline function doesn't satisfy it. */
67#define paravirt_ssm(mask) \
68 do { \
69 if ((mask) == IA64_PSR_I) \
70 pv_cpu_ops.ssm_i(); \
71 else \
72 ia64_native_ssm(mask); \
73 } while (0)
74
75#define paravirt_rsm(mask) \
76 do { \
77 if ((mask) == IA64_PSR_I) \
78 pv_cpu_ops.rsm_i(); \
79 else \
80 ia64_native_rsm(mask); \
81 } while (0)
82
83/******************************************************************************
84 * replacement of hand written assembly codes.
85 */
86struct pv_cpu_asm_switch {
87 unsigned long switch_to;
88 unsigned long leave_syscall;
89 unsigned long work_processed_syscall;
90 unsigned long leave_kernel;
91};
92void paravirt_cpu_asm_init(const struct pv_cpu_asm_switch *cpu_asm_switch);
93
94#endif /* __ASSEMBLY__ */
95
96#define IA64_PARAVIRT_ASM_FUNC(name) paravirt_ ## name
97
98#else
99
100/* fallback for native case */
101#define IA64_PARAVIRT_ASM_FUNC(name) ia64_native_ ## name
102
103#endif /* CONFIG_PARAVIRT */
104
105/* these routines utilize privilege-sensitive or performance-sensitive
106 * privileged instructions so the code must be replaced with
107 * paravirtualized versions */
108#define ia64_switch_to IA64_PARAVIRT_ASM_FUNC(switch_to)
109#define ia64_leave_syscall IA64_PARAVIRT_ASM_FUNC(leave_syscall)
110#define ia64_work_processed_syscall \
111 IA64_PARAVIRT_ASM_FUNC(work_processed_syscall)
112#define ia64_leave_kernel IA64_PARAVIRT_ASM_FUNC(leave_kernel)
113
114#endif /* _ASM_IA64_PARAVIRT_PRIVOP_H */
diff --git a/include/asm-ia64/smp.h b/include/asm-ia64/smp.h
index 27731e032ee9..12d96e0cd513 100644
--- a/include/asm-ia64/smp.h
+++ b/include/asm-ia64/smp.h
@@ -15,6 +15,7 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/cpumask.h> 16#include <linux/cpumask.h>
17#include <linux/bitops.h> 17#include <linux/bitops.h>
18#include <linux/irqreturn.h>
18 19
19#include <asm/io.h> 20#include <asm/io.h>
20#include <asm/param.h> 21#include <asm/param.h>
@@ -120,6 +121,7 @@ extern void __init smp_build_cpu_map(void);
120extern void __init init_smp_config (void); 121extern void __init init_smp_config (void);
121extern void smp_do_timer (struct pt_regs *regs); 122extern void smp_do_timer (struct pt_regs *regs);
122 123
124extern irqreturn_t handle_IPI(int irq, void *dev_id);
123extern void smp_send_reschedule (int cpu); 125extern void smp_send_reschedule (int cpu);
124extern void identify_siblings (struct cpuinfo_ia64 *); 126extern void identify_siblings (struct cpuinfo_ia64 *);
125extern int is_multithreading_enabled(void); 127extern int is_multithreading_enabled(void);
diff --git a/include/asm-ia64/system.h b/include/asm-ia64/system.h
index 26e250bfb912..927a381c20ca 100644
--- a/include/asm-ia64/system.h
+++ b/include/asm-ia64/system.h
@@ -26,6 +26,7 @@
26 */ 26 */
27#define KERNEL_START (GATE_ADDR+__IA64_UL_CONST(0x100000000)) 27#define KERNEL_START (GATE_ADDR+__IA64_UL_CONST(0x100000000))
28#define PERCPU_ADDR (-PERCPU_PAGE_SIZE) 28#define PERCPU_ADDR (-PERCPU_PAGE_SIZE)
29#define LOAD_OFFSET (KERNEL_START - KERNEL_TR_PAGE_SIZE)
29 30
30#ifndef __ASSEMBLY__ 31#ifndef __ASSEMBLY__
31 32
@@ -122,10 +123,16 @@ extern struct ia64_boot_param {
122 * write a floating-point register right before reading the PSR 123 * write a floating-point register right before reading the PSR
123 * and that writes to PSR.mfl 124 * and that writes to PSR.mfl
124 */ 125 */
126#ifdef CONFIG_PARAVIRT
127#define __local_save_flags() ia64_get_psr_i()
128#else
129#define __local_save_flags() ia64_getreg(_IA64_REG_PSR)
130#endif
131
125#define __local_irq_save(x) \ 132#define __local_irq_save(x) \
126do { \ 133do { \
127 ia64_stop(); \ 134 ia64_stop(); \
128 (x) = ia64_getreg(_IA64_REG_PSR); \ 135 (x) = __local_save_flags(); \
129 ia64_stop(); \ 136 ia64_stop(); \
130 ia64_rsm(IA64_PSR_I); \ 137 ia64_rsm(IA64_PSR_I); \
131} while (0) 138} while (0)
@@ -173,7 +180,7 @@ do { \
173#endif /* !CONFIG_IA64_DEBUG_IRQ */ 180#endif /* !CONFIG_IA64_DEBUG_IRQ */
174 181
175#define local_irq_enable() ({ ia64_stop(); ia64_ssm(IA64_PSR_I); ia64_srlz_d(); }) 182#define local_irq_enable() ({ ia64_stop(); ia64_ssm(IA64_PSR_I); ia64_srlz_d(); })
176#define local_save_flags(flags) ({ ia64_stop(); (flags) = ia64_getreg(_IA64_REG_PSR); }) 183#define local_save_flags(flags) ({ ia64_stop(); (flags) = __local_save_flags(); })
177 184
178#define irqs_disabled() \ 185#define irqs_disabled() \
179({ \ 186({ \
diff --git a/include/asm-ia64/uv/uv_mmrs.h b/include/asm-ia64/uv/uv_mmrs.h
index 1cc1dbb0182f..c149ef085437 100644
--- a/include/asm-ia64/uv/uv_mmrs.h
+++ b/include/asm-ia64/uv/uv_mmrs.h
@@ -11,11 +11,284 @@
11#ifndef __ASM_IA64_UV_MMRS__ 11#ifndef __ASM_IA64_UV_MMRS__
12#define __ASM_IA64_UV_MMRS__ 12#define __ASM_IA64_UV_MMRS__
13 13
14/* 14#define UV_MMR_ENABLE (1UL << 63)
15 * AUTO GENERATED - Do not edit 15
16 */ 16/* ========================================================================= */
17/* UVH_BAU_DATA_CONFIG */
18/* ========================================================================= */
19#define UVH_BAU_DATA_CONFIG 0x61680UL
20#define UVH_BAU_DATA_CONFIG_32 0x0438
21
22#define UVH_BAU_DATA_CONFIG_VECTOR_SHFT 0
23#define UVH_BAU_DATA_CONFIG_VECTOR_MASK 0x00000000000000ffUL
24#define UVH_BAU_DATA_CONFIG_DM_SHFT 8
25#define UVH_BAU_DATA_CONFIG_DM_MASK 0x0000000000000700UL
26#define UVH_BAU_DATA_CONFIG_DESTMODE_SHFT 11
27#define UVH_BAU_DATA_CONFIG_DESTMODE_MASK 0x0000000000000800UL
28#define UVH_BAU_DATA_CONFIG_STATUS_SHFT 12
29#define UVH_BAU_DATA_CONFIG_STATUS_MASK 0x0000000000001000UL
30#define UVH_BAU_DATA_CONFIG_P_SHFT 13
31#define UVH_BAU_DATA_CONFIG_P_MASK 0x0000000000002000UL
32#define UVH_BAU_DATA_CONFIG_T_SHFT 15
33#define UVH_BAU_DATA_CONFIG_T_MASK 0x0000000000008000UL
34#define UVH_BAU_DATA_CONFIG_M_SHFT 16
35#define UVH_BAU_DATA_CONFIG_M_MASK 0x0000000000010000UL
36#define UVH_BAU_DATA_CONFIG_APIC_ID_SHFT 32
37#define UVH_BAU_DATA_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
38
39union uvh_bau_data_config_u {
40 unsigned long v;
41 struct uvh_bau_data_config_s {
42 unsigned long vector_ : 8; /* RW */
43 unsigned long dm : 3; /* RW */
44 unsigned long destmode : 1; /* RW */
45 unsigned long status : 1; /* RO */
46 unsigned long p : 1; /* RO */
47 unsigned long rsvd_14 : 1; /* */
48 unsigned long t : 1; /* RO */
49 unsigned long m : 1; /* RW */
50 unsigned long rsvd_17_31: 15; /* */
51 unsigned long apic_id : 32; /* RW */
52 } s;
53};
54
55/* ========================================================================= */
56/* UVH_EVENT_OCCURRED0 */
57/* ========================================================================= */
58#define UVH_EVENT_OCCURRED0 0x70000UL
59#define UVH_EVENT_OCCURRED0_32 0x005e8
60
61#define UVH_EVENT_OCCURRED0_LB_HCERR_SHFT 0
62#define UVH_EVENT_OCCURRED0_LB_HCERR_MASK 0x0000000000000001UL
63#define UVH_EVENT_OCCURRED0_GR0_HCERR_SHFT 1
64#define UVH_EVENT_OCCURRED0_GR0_HCERR_MASK 0x0000000000000002UL
65#define UVH_EVENT_OCCURRED0_GR1_HCERR_SHFT 2
66#define UVH_EVENT_OCCURRED0_GR1_HCERR_MASK 0x0000000000000004UL
67#define UVH_EVENT_OCCURRED0_LH_HCERR_SHFT 3
68#define UVH_EVENT_OCCURRED0_LH_HCERR_MASK 0x0000000000000008UL
69#define UVH_EVENT_OCCURRED0_RH_HCERR_SHFT 4
70#define UVH_EVENT_OCCURRED0_RH_HCERR_MASK 0x0000000000000010UL
71#define UVH_EVENT_OCCURRED0_XN_HCERR_SHFT 5
72#define UVH_EVENT_OCCURRED0_XN_HCERR_MASK 0x0000000000000020UL
73#define UVH_EVENT_OCCURRED0_SI_HCERR_SHFT 6
74#define UVH_EVENT_OCCURRED0_SI_HCERR_MASK 0x0000000000000040UL
75#define UVH_EVENT_OCCURRED0_LB_AOERR0_SHFT 7
76#define UVH_EVENT_OCCURRED0_LB_AOERR0_MASK 0x0000000000000080UL
77#define UVH_EVENT_OCCURRED0_GR0_AOERR0_SHFT 8
78#define UVH_EVENT_OCCURRED0_GR0_AOERR0_MASK 0x0000000000000100UL
79#define UVH_EVENT_OCCURRED0_GR1_AOERR0_SHFT 9
80#define UVH_EVENT_OCCURRED0_GR1_AOERR0_MASK 0x0000000000000200UL
81#define UVH_EVENT_OCCURRED0_LH_AOERR0_SHFT 10
82#define UVH_EVENT_OCCURRED0_LH_AOERR0_MASK 0x0000000000000400UL
83#define UVH_EVENT_OCCURRED0_RH_AOERR0_SHFT 11
84#define UVH_EVENT_OCCURRED0_RH_AOERR0_MASK 0x0000000000000800UL
85#define UVH_EVENT_OCCURRED0_XN_AOERR0_SHFT 12
86#define UVH_EVENT_OCCURRED0_XN_AOERR0_MASK 0x0000000000001000UL
87#define UVH_EVENT_OCCURRED0_SI_AOERR0_SHFT 13
88#define UVH_EVENT_OCCURRED0_SI_AOERR0_MASK 0x0000000000002000UL
89#define UVH_EVENT_OCCURRED0_LB_AOERR1_SHFT 14
90#define UVH_EVENT_OCCURRED0_LB_AOERR1_MASK 0x0000000000004000UL
91#define UVH_EVENT_OCCURRED0_GR0_AOERR1_SHFT 15
92#define UVH_EVENT_OCCURRED0_GR0_AOERR1_MASK 0x0000000000008000UL
93#define UVH_EVENT_OCCURRED0_GR1_AOERR1_SHFT 16
94#define UVH_EVENT_OCCURRED0_GR1_AOERR1_MASK 0x0000000000010000UL
95#define UVH_EVENT_OCCURRED0_LH_AOERR1_SHFT 17
96#define UVH_EVENT_OCCURRED0_LH_AOERR1_MASK 0x0000000000020000UL
97#define UVH_EVENT_OCCURRED0_RH_AOERR1_SHFT 18
98#define UVH_EVENT_OCCURRED0_RH_AOERR1_MASK 0x0000000000040000UL
99#define UVH_EVENT_OCCURRED0_XN_AOERR1_SHFT 19
100#define UVH_EVENT_OCCURRED0_XN_AOERR1_MASK 0x0000000000080000UL
101#define UVH_EVENT_OCCURRED0_SI_AOERR1_SHFT 20
102#define UVH_EVENT_OCCURRED0_SI_AOERR1_MASK 0x0000000000100000UL
103#define UVH_EVENT_OCCURRED0_RH_VPI_INT_SHFT 21
104#define UVH_EVENT_OCCURRED0_RH_VPI_INT_MASK 0x0000000000200000UL
105#define UVH_EVENT_OCCURRED0_SYSTEM_SHUTDOWN_INT_SHFT 22
106#define UVH_EVENT_OCCURRED0_SYSTEM_SHUTDOWN_INT_MASK 0x0000000000400000UL
107#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_0_SHFT 23
108#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_0_MASK 0x0000000000800000UL
109#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_1_SHFT 24
110#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_1_MASK 0x0000000001000000UL
111#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_2_SHFT 25
112#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_2_MASK 0x0000000002000000UL
113#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_3_SHFT 26
114#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_3_MASK 0x0000000004000000UL
115#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_4_SHFT 27
116#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_4_MASK 0x0000000008000000UL
117#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_5_SHFT 28
118#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_5_MASK 0x0000000010000000UL
119#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_6_SHFT 29
120#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_6_MASK 0x0000000020000000UL
121#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_7_SHFT 30
122#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_7_MASK 0x0000000040000000UL
123#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_8_SHFT 31
124#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_8_MASK 0x0000000080000000UL
125#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_9_SHFT 32
126#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_9_MASK 0x0000000100000000UL
127#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_10_SHFT 33
128#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_10_MASK 0x0000000200000000UL
129#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_11_SHFT 34
130#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_11_MASK 0x0000000400000000UL
131#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_12_SHFT 35
132#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_12_MASK 0x0000000800000000UL
133#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_13_SHFT 36
134#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_13_MASK 0x0000001000000000UL
135#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_14_SHFT 37
136#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_14_MASK 0x0000002000000000UL
137#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_15_SHFT 38
138#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_15_MASK 0x0000004000000000UL
139#define UVH_EVENT_OCCURRED0_L1_NMI_INT_SHFT 39
140#define UVH_EVENT_OCCURRED0_L1_NMI_INT_MASK 0x0000008000000000UL
141#define UVH_EVENT_OCCURRED0_STOP_CLOCK_SHFT 40
142#define UVH_EVENT_OCCURRED0_STOP_CLOCK_MASK 0x0000010000000000UL
143#define UVH_EVENT_OCCURRED0_ASIC_TO_L1_SHFT 41
144#define UVH_EVENT_OCCURRED0_ASIC_TO_L1_MASK 0x0000020000000000UL
145#define UVH_EVENT_OCCURRED0_L1_TO_ASIC_SHFT 42
146#define UVH_EVENT_OCCURRED0_L1_TO_ASIC_MASK 0x0000040000000000UL
147#define UVH_EVENT_OCCURRED0_LTC_INT_SHFT 43
148#define UVH_EVENT_OCCURRED0_LTC_INT_MASK 0x0000080000000000UL
149#define UVH_EVENT_OCCURRED0_LA_SEQ_TRIGGER_SHFT 44
150#define UVH_EVENT_OCCURRED0_LA_SEQ_TRIGGER_MASK 0x0000100000000000UL
151#define UVH_EVENT_OCCURRED0_IPI_INT_SHFT 45
152#define UVH_EVENT_OCCURRED0_IPI_INT_MASK 0x0000200000000000UL
153#define UVH_EVENT_OCCURRED0_EXTIO_INT0_SHFT 46
154#define UVH_EVENT_OCCURRED0_EXTIO_INT0_MASK 0x0000400000000000UL
155#define UVH_EVENT_OCCURRED0_EXTIO_INT1_SHFT 47
156#define UVH_EVENT_OCCURRED0_EXTIO_INT1_MASK 0x0000800000000000UL
157#define UVH_EVENT_OCCURRED0_EXTIO_INT2_SHFT 48
158#define UVH_EVENT_OCCURRED0_EXTIO_INT2_MASK 0x0001000000000000UL
159#define UVH_EVENT_OCCURRED0_EXTIO_INT3_SHFT 49
160#define UVH_EVENT_OCCURRED0_EXTIO_INT3_MASK 0x0002000000000000UL
161#define UVH_EVENT_OCCURRED0_PROFILE_INT_SHFT 50
162#define UVH_EVENT_OCCURRED0_PROFILE_INT_MASK 0x0004000000000000UL
163#define UVH_EVENT_OCCURRED0_RTC0_SHFT 51
164#define UVH_EVENT_OCCURRED0_RTC0_MASK 0x0008000000000000UL
165#define UVH_EVENT_OCCURRED0_RTC1_SHFT 52
166#define UVH_EVENT_OCCURRED0_RTC1_MASK 0x0010000000000000UL
167#define UVH_EVENT_OCCURRED0_RTC2_SHFT 53
168#define UVH_EVENT_OCCURRED0_RTC2_MASK 0x0020000000000000UL
169#define UVH_EVENT_OCCURRED0_RTC3_SHFT 54
170#define UVH_EVENT_OCCURRED0_RTC3_MASK 0x0040000000000000UL
171#define UVH_EVENT_OCCURRED0_BAU_DATA_SHFT 55
172#define UVH_EVENT_OCCURRED0_BAU_DATA_MASK 0x0080000000000000UL
173#define UVH_EVENT_OCCURRED0_POWER_MANAGEMENT_REQ_SHFT 56
174#define UVH_EVENT_OCCURRED0_POWER_MANAGEMENT_REQ_MASK 0x0100000000000000UL
175union uvh_event_occurred0_u {
176 unsigned long v;
177 struct uvh_event_occurred0_s {
178 unsigned long lb_hcerr : 1; /* RW, W1C */
179 unsigned long gr0_hcerr : 1; /* RW, W1C */
180 unsigned long gr1_hcerr : 1; /* RW, W1C */
181 unsigned long lh_hcerr : 1; /* RW, W1C */
182 unsigned long rh_hcerr : 1; /* RW, W1C */
183 unsigned long xn_hcerr : 1; /* RW, W1C */
184 unsigned long si_hcerr : 1; /* RW, W1C */
185 unsigned long lb_aoerr0 : 1; /* RW, W1C */
186 unsigned long gr0_aoerr0 : 1; /* RW, W1C */
187 unsigned long gr1_aoerr0 : 1; /* RW, W1C */
188 unsigned long lh_aoerr0 : 1; /* RW, W1C */
189 unsigned long rh_aoerr0 : 1; /* RW, W1C */
190 unsigned long xn_aoerr0 : 1; /* RW, W1C */
191 unsigned long si_aoerr0 : 1; /* RW, W1C */
192 unsigned long lb_aoerr1 : 1; /* RW, W1C */
193 unsigned long gr0_aoerr1 : 1; /* RW, W1C */
194 unsigned long gr1_aoerr1 : 1; /* RW, W1C */
195 unsigned long lh_aoerr1 : 1; /* RW, W1C */
196 unsigned long rh_aoerr1 : 1; /* RW, W1C */
197 unsigned long xn_aoerr1 : 1; /* RW, W1C */
198 unsigned long si_aoerr1 : 1; /* RW, W1C */
199 unsigned long rh_vpi_int : 1; /* RW, W1C */
200 unsigned long system_shutdown_int : 1; /* RW, W1C */
201 unsigned long lb_irq_int_0 : 1; /* RW, W1C */
202 unsigned long lb_irq_int_1 : 1; /* RW, W1C */
203 unsigned long lb_irq_int_2 : 1; /* RW, W1C */
204 unsigned long lb_irq_int_3 : 1; /* RW, W1C */
205 unsigned long lb_irq_int_4 : 1; /* RW, W1C */
206 unsigned long lb_irq_int_5 : 1; /* RW, W1C */
207 unsigned long lb_irq_int_6 : 1; /* RW, W1C */
208 unsigned long lb_irq_int_7 : 1; /* RW, W1C */
209 unsigned long lb_irq_int_8 : 1; /* RW, W1C */
210 unsigned long lb_irq_int_9 : 1; /* RW, W1C */
211 unsigned long lb_irq_int_10 : 1; /* RW, W1C */
212 unsigned long lb_irq_int_11 : 1; /* RW, W1C */
213 unsigned long lb_irq_int_12 : 1; /* RW, W1C */
214 unsigned long lb_irq_int_13 : 1; /* RW, W1C */
215 unsigned long lb_irq_int_14 : 1; /* RW, W1C */
216 unsigned long lb_irq_int_15 : 1; /* RW, W1C */
217 unsigned long l1_nmi_int : 1; /* RW, W1C */
218 unsigned long stop_clock : 1; /* RW, W1C */
219 unsigned long asic_to_l1 : 1; /* RW, W1C */
220 unsigned long l1_to_asic : 1; /* RW, W1C */
221 unsigned long ltc_int : 1; /* RW, W1C */
222 unsigned long la_seq_trigger : 1; /* RW, W1C */
223 unsigned long ipi_int : 1; /* RW, W1C */
224 unsigned long extio_int0 : 1; /* RW, W1C */
225 unsigned long extio_int1 : 1; /* RW, W1C */
226 unsigned long extio_int2 : 1; /* RW, W1C */
227 unsigned long extio_int3 : 1; /* RW, W1C */
228 unsigned long profile_int : 1; /* RW, W1C */
229 unsigned long rtc0 : 1; /* RW, W1C */
230 unsigned long rtc1 : 1; /* RW, W1C */
231 unsigned long rtc2 : 1; /* RW, W1C */
232 unsigned long rtc3 : 1; /* RW, W1C */
233 unsigned long bau_data : 1; /* RW, W1C */
234 unsigned long power_management_req : 1; /* RW, W1C */
235 unsigned long rsvd_57_63 : 7; /* */
236 } s;
237};
238
239/* ========================================================================= */
240/* UVH_EVENT_OCCURRED0_ALIAS */
241/* ========================================================================= */
242#define UVH_EVENT_OCCURRED0_ALIAS 0x0000000000070008UL
243#define UVH_EVENT_OCCURRED0_ALIAS_32 0x005f0
244
245/* ========================================================================= */
246/* UVH_INT_CMPB */
247/* ========================================================================= */
248#define UVH_INT_CMPB 0x22080UL
249
250#define UVH_INT_CMPB_REAL_TIME_CMPB_SHFT 0
251#define UVH_INT_CMPB_REAL_TIME_CMPB_MASK 0x00ffffffffffffffUL
252
253union uvh_int_cmpb_u {
254 unsigned long v;
255 struct uvh_int_cmpb_s {
256 unsigned long real_time_cmpb : 56; /* RW */
257 unsigned long rsvd_56_63 : 8; /* */
258 } s;
259};
260
261/* ========================================================================= */
262/* UVH_INT_CMPC */
263/* ========================================================================= */
264#define UVH_INT_CMPC 0x22100UL
265
266#define UVH_INT_CMPC_REAL_TIME_CMPC_SHFT 0
267#define UVH_INT_CMPC_REAL_TIME_CMPC_MASK 0x00ffffffffffffffUL
268
269union uvh_int_cmpc_u {
270 unsigned long v;
271 struct uvh_int_cmpc_s {
272 unsigned long real_time_cmpc : 56; /* RW */
273 unsigned long rsvd_56_63 : 8; /* */
274 } s;
275};
17 276
18 #define UV_MMR_ENABLE (1UL << 63) 277/* ========================================================================= */
278/* UVH_INT_CMPD */
279/* ========================================================================= */
280#define UVH_INT_CMPD 0x22180UL
281
282#define UVH_INT_CMPD_REAL_TIME_CMPD_SHFT 0
283#define UVH_INT_CMPD_REAL_TIME_CMPD_MASK 0x00ffffffffffffffUL
284
285union uvh_int_cmpd_u {
286 unsigned long v;
287 struct uvh_int_cmpd_s {
288 unsigned long real_time_cmpd : 56; /* RW */
289 unsigned long rsvd_56_63 : 8; /* */
290 } s;
291};
19 292
20/* ========================================================================= */ 293/* ========================================================================= */
21/* UVH_NODE_ID */ 294/* UVH_NODE_ID */
@@ -111,8 +384,8 @@ union uvh_rh_gam_alias210_redirect_config_2_mmr_u {
111 384
112#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT 28 385#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT 28
113#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_MASK 0x00003ffff0000000UL 386#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_MASK 0x00003ffff0000000UL
114#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_GR4_SHFT 46 387#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_GR4_SHFT 48
115#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_GR4_MASK 0x0000400000000000UL 388#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_GR4_MASK 0x0001000000000000UL
116#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_N_GRU_SHFT 52 389#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_N_GRU_SHFT 52
117#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_N_GRU_MASK 0x00f0000000000000UL 390#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_N_GRU_MASK 0x00f0000000000000UL
118#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_ENABLE_SHFT 63 391#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_ENABLE_SHFT 63
@@ -123,8 +396,9 @@ union uvh_rh_gam_gru_overlay_config_mmr_u {
123 struct uvh_rh_gam_gru_overlay_config_mmr_s { 396 struct uvh_rh_gam_gru_overlay_config_mmr_s {
124 unsigned long rsvd_0_27: 28; /* */ 397 unsigned long rsvd_0_27: 28; /* */
125 unsigned long base : 18; /* RW */ 398 unsigned long base : 18; /* RW */
399 unsigned long rsvd_46_47: 2; /* */
126 unsigned long gr4 : 1; /* RW */ 400 unsigned long gr4 : 1; /* RW */
127 unsigned long rsvd_47_51: 5; /* */ 401 unsigned long rsvd_49_51: 3; /* */
128 unsigned long n_gru : 4; /* RW */ 402 unsigned long n_gru : 4; /* RW */
129 unsigned long rsvd_56_62: 7; /* */ 403 unsigned long rsvd_56_62: 7; /* */
130 unsigned long enable : 1; /* RW */ 404 unsigned long enable : 1; /* RW */
@@ -157,7 +431,7 @@ union uvh_rh_gam_mmr_overlay_config_mmr_u {
157/* ========================================================================= */ 431/* ========================================================================= */
158/* UVH_RTC */ 432/* UVH_RTC */
159/* ========================================================================= */ 433/* ========================================================================= */
160#define UVH_RTC 0x28000UL 434#define UVH_RTC 0x340000UL
161 435
162#define UVH_RTC_REAL_TIME_CLOCK_SHFT 0 436#define UVH_RTC_REAL_TIME_CLOCK_SHFT 0
163#define UVH_RTC_REAL_TIME_CLOCK_MASK 0x00ffffffffffffffUL 437#define UVH_RTC_REAL_TIME_CLOCK_MASK 0x00ffffffffffffffUL
@@ -171,6 +445,139 @@ union uvh_rtc_u {
171}; 445};
172 446
173/* ========================================================================= */ 447/* ========================================================================= */
448/* UVH_RTC1_INT_CONFIG */
449/* ========================================================================= */
450#define UVH_RTC1_INT_CONFIG 0x615c0UL
451
452#define UVH_RTC1_INT_CONFIG_VECTOR_SHFT 0
453#define UVH_RTC1_INT_CONFIG_VECTOR_MASK 0x00000000000000ffUL
454#define UVH_RTC1_INT_CONFIG_DM_SHFT 8
455#define UVH_RTC1_INT_CONFIG_DM_MASK 0x0000000000000700UL
456#define UVH_RTC1_INT_CONFIG_DESTMODE_SHFT 11
457#define UVH_RTC1_INT_CONFIG_DESTMODE_MASK 0x0000000000000800UL
458#define UVH_RTC1_INT_CONFIG_STATUS_SHFT 12
459#define UVH_RTC1_INT_CONFIG_STATUS_MASK 0x0000000000001000UL
460#define UVH_RTC1_INT_CONFIG_P_SHFT 13
461#define UVH_RTC1_INT_CONFIG_P_MASK 0x0000000000002000UL
462#define UVH_RTC1_INT_CONFIG_T_SHFT 15
463#define UVH_RTC1_INT_CONFIG_T_MASK 0x0000000000008000UL
464#define UVH_RTC1_INT_CONFIG_M_SHFT 16
465#define UVH_RTC1_INT_CONFIG_M_MASK 0x0000000000010000UL
466#define UVH_RTC1_INT_CONFIG_APIC_ID_SHFT 32
467#define UVH_RTC1_INT_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
468
469union uvh_rtc1_int_config_u {
470 unsigned long v;
471 struct uvh_rtc1_int_config_s {
472 unsigned long vector_ : 8; /* RW */
473 unsigned long dm : 3; /* RW */
474 unsigned long destmode : 1; /* RW */
475 unsigned long status : 1; /* RO */
476 unsigned long p : 1; /* RO */
477 unsigned long rsvd_14 : 1; /* */
478 unsigned long t : 1; /* RO */
479 unsigned long m : 1; /* RW */
480 unsigned long rsvd_17_31: 15; /* */
481 unsigned long apic_id : 32; /* RW */
482 } s;
483};
484
485/* ========================================================================= */
486/* UVH_RTC2_INT_CONFIG */
487/* ========================================================================= */
488#define UVH_RTC2_INT_CONFIG 0x61600UL
489
490#define UVH_RTC2_INT_CONFIG_VECTOR_SHFT 0
491#define UVH_RTC2_INT_CONFIG_VECTOR_MASK 0x00000000000000ffUL
492#define UVH_RTC2_INT_CONFIG_DM_SHFT 8
493#define UVH_RTC2_INT_CONFIG_DM_MASK 0x0000000000000700UL
494#define UVH_RTC2_INT_CONFIG_DESTMODE_SHFT 11
495#define UVH_RTC2_INT_CONFIG_DESTMODE_MASK 0x0000000000000800UL
496#define UVH_RTC2_INT_CONFIG_STATUS_SHFT 12
497#define UVH_RTC2_INT_CONFIG_STATUS_MASK 0x0000000000001000UL
498#define UVH_RTC2_INT_CONFIG_P_SHFT 13
499#define UVH_RTC2_INT_CONFIG_P_MASK 0x0000000000002000UL
500#define UVH_RTC2_INT_CONFIG_T_SHFT 15
501#define UVH_RTC2_INT_CONFIG_T_MASK 0x0000000000008000UL
502#define UVH_RTC2_INT_CONFIG_M_SHFT 16
503#define UVH_RTC2_INT_CONFIG_M_MASK 0x0000000000010000UL
504#define UVH_RTC2_INT_CONFIG_APIC_ID_SHFT 32
505#define UVH_RTC2_INT_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
506
507union uvh_rtc2_int_config_u {
508 unsigned long v;
509 struct uvh_rtc2_int_config_s {
510 unsigned long vector_ : 8; /* RW */
511 unsigned long dm : 3; /* RW */
512 unsigned long destmode : 1; /* RW */
513 unsigned long status : 1; /* RO */
514 unsigned long p : 1; /* RO */
515 unsigned long rsvd_14 : 1; /* */
516 unsigned long t : 1; /* RO */
517 unsigned long m : 1; /* RW */
518 unsigned long rsvd_17_31: 15; /* */
519 unsigned long apic_id : 32; /* RW */
520 } s;
521};
522
523/* ========================================================================= */
524/* UVH_RTC3_INT_CONFIG */
525/* ========================================================================= */
526#define UVH_RTC3_INT_CONFIG 0x61640UL
527
528#define UVH_RTC3_INT_CONFIG_VECTOR_SHFT 0
529#define UVH_RTC3_INT_CONFIG_VECTOR_MASK 0x00000000000000ffUL
530#define UVH_RTC3_INT_CONFIG_DM_SHFT 8
531#define UVH_RTC3_INT_CONFIG_DM_MASK 0x0000000000000700UL
532#define UVH_RTC3_INT_CONFIG_DESTMODE_SHFT 11
533#define UVH_RTC3_INT_CONFIG_DESTMODE_MASK 0x0000000000000800UL
534#define UVH_RTC3_INT_CONFIG_STATUS_SHFT 12
535#define UVH_RTC3_INT_CONFIG_STATUS_MASK 0x0000000000001000UL
536#define UVH_RTC3_INT_CONFIG_P_SHFT 13
537#define UVH_RTC3_INT_CONFIG_P_MASK 0x0000000000002000UL
538#define UVH_RTC3_INT_CONFIG_T_SHFT 15
539#define UVH_RTC3_INT_CONFIG_T_MASK 0x0000000000008000UL
540#define UVH_RTC3_INT_CONFIG_M_SHFT 16
541#define UVH_RTC3_INT_CONFIG_M_MASK 0x0000000000010000UL
542#define UVH_RTC3_INT_CONFIG_APIC_ID_SHFT 32
543#define UVH_RTC3_INT_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
544
545union uvh_rtc3_int_config_u {
546 unsigned long v;
547 struct uvh_rtc3_int_config_s {
548 unsigned long vector_ : 8; /* RW */
549 unsigned long dm : 3; /* RW */
550 unsigned long destmode : 1; /* RW */
551 unsigned long status : 1; /* RO */
552 unsigned long p : 1; /* RO */
553 unsigned long rsvd_14 : 1; /* */
554 unsigned long t : 1; /* RO */
555 unsigned long m : 1; /* RW */
556 unsigned long rsvd_17_31: 15; /* */
557 unsigned long apic_id : 32; /* RW */
558 } s;
559};
560
561/* ========================================================================= */
562/* UVH_RTC_INC_RATIO */
563/* ========================================================================= */
564#define UVH_RTC_INC_RATIO 0x350000UL
565
566#define UVH_RTC_INC_RATIO_FRACTION_SHFT 0
567#define UVH_RTC_INC_RATIO_FRACTION_MASK 0x00000000000fffffUL
568#define UVH_RTC_INC_RATIO_RATIO_SHFT 20
569#define UVH_RTC_INC_RATIO_RATIO_MASK 0x0000000000700000UL
570
571union uvh_rtc_inc_ratio_u {
572 unsigned long v;
573 struct uvh_rtc_inc_ratio_s {
574 unsigned long fraction : 20; /* RW */
575 unsigned long ratio : 3; /* RW */
576 unsigned long rsvd_23_63: 41; /* */
577 } s;
578};
579
580/* ========================================================================= */
174/* UVH_SI_ADDR_MAP_CONFIG */ 581/* UVH_SI_ADDR_MAP_CONFIG */
175/* ========================================================================= */ 582/* ========================================================================= */
176#define UVH_SI_ADDR_MAP_CONFIG 0xc80000UL 583#define UVH_SI_ADDR_MAP_CONFIG 0xc80000UL
diff --git a/include/asm-powerpc/asm-compat.h b/include/asm-powerpc/asm-compat.h
index 8ec2e1da68bf..8f0fe7971949 100644
--- a/include/asm-powerpc/asm-compat.h
+++ b/include/asm-powerpc/asm-compat.h
@@ -22,6 +22,7 @@
22#define PPC_STL stringify_in_c(std) 22#define PPC_STL stringify_in_c(std)
23#define PPC_LCMPI stringify_in_c(cmpdi) 23#define PPC_LCMPI stringify_in_c(cmpdi)
24#define PPC_LONG stringify_in_c(.llong) 24#define PPC_LONG stringify_in_c(.llong)
25#define PPC_LONG_ALIGN stringify_in_c(.balign 8)
25#define PPC_TLNEI stringify_in_c(tdnei) 26#define PPC_TLNEI stringify_in_c(tdnei)
26#define PPC_LLARX stringify_in_c(ldarx) 27#define PPC_LLARX stringify_in_c(ldarx)
27#define PPC_STLCX stringify_in_c(stdcx.) 28#define PPC_STLCX stringify_in_c(stdcx.)
@@ -43,6 +44,7 @@
43#define PPC_STL stringify_in_c(stw) 44#define PPC_STL stringify_in_c(stw)
44#define PPC_LCMPI stringify_in_c(cmpwi) 45#define PPC_LCMPI stringify_in_c(cmpwi)
45#define PPC_LONG stringify_in_c(.long) 46#define PPC_LONG stringify_in_c(.long)
47#define PPC_LONG_ALIGN stringify_in_c(.balign 4)
46#define PPC_TLNEI stringify_in_c(twnei) 48#define PPC_TLNEI stringify_in_c(twnei)
47#define PPC_LLARX stringify_in_c(lwarx) 49#define PPC_LLARX stringify_in_c(lwarx)
48#define PPC_STLCX stringify_in_c(stwcx.) 50#define PPC_STLCX stringify_in_c(stwcx.)
diff --git a/include/asm-powerpc/machdep.h b/include/asm-powerpc/machdep.h
index 989922621e35..1233d735fd28 100644
--- a/include/asm-powerpc/machdep.h
+++ b/include/asm-powerpc/machdep.h
@@ -80,7 +80,8 @@ struct machdep_calls {
80 long index, 80 long index,
81 long npages, 81 long npages,
82 unsigned long uaddr, 82 unsigned long uaddr,
83 enum dma_data_direction direction); 83 enum dma_data_direction direction,
84 struct dma_attrs *attrs);
84 void (*tce_free)(struct iommu_table *tbl, 85 void (*tce_free)(struct iommu_table *tbl,
85 long index, 86 long index,
86 long npages); 87 long npages);
diff --git a/include/asm-powerpc/pgtable-ppc32.h b/include/asm-powerpc/pgtable-ppc32.h
index 73015f0139de..3a96d001cb75 100644
--- a/include/asm-powerpc/pgtable-ppc32.h
+++ b/include/asm-powerpc/pgtable-ppc32.h
@@ -295,10 +295,10 @@ extern int icache_44x_need_flush;
295#define _PAGE_PRESENT 0x00001 /* S: PTE contains a translation */ 295#define _PAGE_PRESENT 0x00001 /* S: PTE contains a translation */
296#define _PAGE_USER 0x00002 /* S: User page (maps to UR) */ 296#define _PAGE_USER 0x00002 /* S: User page (maps to UR) */
297#define _PAGE_FILE 0x00002 /* S: when !present: nonlinear file mapping */ 297#define _PAGE_FILE 0x00002 /* S: when !present: nonlinear file mapping */
298#define _PAGE_ACCESSED 0x00004 /* S: Page referenced */ 298#define _PAGE_RW 0x00004 /* S: Write permission (SW) */
299#define _PAGE_HWWRITE 0x00008 /* H: Dirty & RW, set in exception */ 299#define _PAGE_DIRTY 0x00008 /* S: Page dirty */
300#define _PAGE_RW 0x00010 /* S: Write permission */ 300#define _PAGE_HWEXEC 0x00010 /* H: SX permission */
301#define _PAGE_HWEXEC 0x00020 /* H: UX permission */ 301#define _PAGE_ACCESSED 0x00020 /* S: Page referenced */
302 302
303#define _PAGE_ENDIAN 0x00040 /* H: E bit */ 303#define _PAGE_ENDIAN 0x00040 /* H: E bit */
304#define _PAGE_GUARDED 0x00080 /* H: G bit */ 304#define _PAGE_GUARDED 0x00080 /* H: G bit */
@@ -307,21 +307,14 @@ extern int icache_44x_need_flush;
307#define _PAGE_WRITETHRU 0x00400 /* H: W bit */ 307#define _PAGE_WRITETHRU 0x00400 /* H: W bit */
308 308
309#ifdef CONFIG_PTE_64BIT 309#ifdef CONFIG_PTE_64BIT
310#define _PAGE_DIRTY 0x08000 /* S: Page dirty */
311
312/* ERPN in a PTE never gets cleared, ignore it */ 310/* ERPN in a PTE never gets cleared, ignore it */
313#define _PTE_NONE_MASK 0xffffffffffff0000ULL 311#define _PTE_NONE_MASK 0xffffffffffff0000ULL
314#else
315#define _PAGE_DIRTY 0x00800 /* S: Page dirty */
316#endif 312#endif
317 313
318#define _PMD_PRESENT 0 314#define _PMD_PRESENT 0
319#define _PMD_PRESENT_MASK (PAGE_MASK) 315#define _PMD_PRESENT_MASK (PAGE_MASK)
320#define _PMD_BAD (~PAGE_MASK) 316#define _PMD_BAD (~PAGE_MASK)
321 317
322/* Until my rework is finished, FSL BookE still needs atomic PTE updates */
323#define PTE_ATOMIC_UPDATES 1
324
325#elif defined(CONFIG_8xx) 318#elif defined(CONFIG_8xx)
326/* Definitions for 8xx embedded chips. */ 319/* Definitions for 8xx embedded chips. */
327#define _PAGE_PRESENT 0x0001 /* Page is valid */ 320#define _PAGE_PRESENT 0x0001 /* Page is valid */
diff --git a/include/asm-powerpc/pmi.h b/include/asm-powerpc/pmi.h
index e1dc090748df..b4e91fbf5081 100644
--- a/include/asm-powerpc/pmi.h
+++ b/include/asm-powerpc/pmi.h
@@ -30,6 +30,7 @@
30#ifdef __KERNEL__ 30#ifdef __KERNEL__
31 31
32#define PMI_TYPE_FREQ_CHANGE 0x01 32#define PMI_TYPE_FREQ_CHANGE 0x01
33#define PMI_TYPE_POWER_BUTTON 0x02
33#define PMI_READ_TYPE 0 34#define PMI_READ_TYPE 0
34#define PMI_READ_DATA0 1 35#define PMI_READ_DATA0 1
35#define PMI_READ_DATA1 2 36#define PMI_READ_DATA1 2
diff --git a/include/asm-powerpc/ps3.h b/include/asm-powerpc/ps3.h
index 81ffe3b3c1ce..f9e34c493cbb 100644
--- a/include/asm-powerpc/ps3.h
+++ b/include/asm-powerpc/ps3.h
@@ -337,12 +337,18 @@ enum ps3_system_bus_device_type {
337 PS3_DEVICE_TYPE_LPM, 337 PS3_DEVICE_TYPE_LPM,
338}; 338};
339 339
340enum ps3_match_sub_id {
341 /* for PS3_MATCH_ID_GRAPHICS */
342 PS3_MATCH_SUB_ID_FB = 1,
343};
344
340/** 345/**
341 * struct ps3_system_bus_device - a device on the system bus 346 * struct ps3_system_bus_device - a device on the system bus
342 */ 347 */
343 348
344struct ps3_system_bus_device { 349struct ps3_system_bus_device {
345 enum ps3_match_id match_id; 350 enum ps3_match_id match_id;
351 enum ps3_match_sub_id match_sub_id;
346 enum ps3_system_bus_device_type dev_type; 352 enum ps3_system_bus_device_type dev_type;
347 353
348 u64 bus_id; /* SB */ 354 u64 bus_id; /* SB */
@@ -371,6 +377,7 @@ int ps3_close_hv_device(struct ps3_system_bus_device *dev);
371 377
372struct ps3_system_bus_driver { 378struct ps3_system_bus_driver {
373 enum ps3_match_id match_id; 379 enum ps3_match_id match_id;
380 enum ps3_match_sub_id match_sub_id;
374 struct device_driver core; 381 struct device_driver core;
375 int (*probe)(struct ps3_system_bus_device *); 382 int (*probe)(struct ps3_system_bus_device *);
376 int (*remove)(struct ps3_system_bus_device *); 383 int (*remove)(struct ps3_system_bus_device *);
diff --git a/include/asm-powerpc/reg.h b/include/asm-powerpc/reg.h
index bbccadfee0d6..c6d1ab650778 100644
--- a/include/asm-powerpc/reg.h
+++ b/include/asm-powerpc/reg.h
@@ -155,10 +155,12 @@
155#define CTRL_RUNLATCH 0x1 155#define CTRL_RUNLATCH 0x1
156#define SPRN_DABR 0x3F5 /* Data Address Breakpoint Register */ 156#define SPRN_DABR 0x3F5 /* Data Address Breakpoint Register */
157#define DABR_TRANSLATION (1UL << 2) 157#define DABR_TRANSLATION (1UL << 2)
158#define SPRN_DABR2 0x13D /* e300 */
158#define SPRN_DABRX 0x3F7 /* Data Address Breakpoint Register Extension */ 159#define SPRN_DABRX 0x3F7 /* Data Address Breakpoint Register Extension */
159#define DABRX_USER (1UL << 0) 160#define DABRX_USER (1UL << 0)
160#define DABRX_KERNEL (1UL << 1) 161#define DABRX_KERNEL (1UL << 1)
161#define SPRN_DAR 0x013 /* Data Address Register */ 162#define SPRN_DAR 0x013 /* Data Address Register */
163#define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
162#define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */ 164#define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
163#define DSISR_NOHPTE 0x40000000 /* no translation found */ 165#define DSISR_NOHPTE 0x40000000 /* no translation found */
164#define DSISR_PROTFAULT 0x08000000 /* protection fault */ 166#define DSISR_PROTFAULT 0x08000000 /* protection fault */
@@ -264,6 +266,8 @@
264#define HID1_PS (1<<16) /* 750FX PLL selection */ 266#define HID1_PS (1<<16) /* 750FX PLL selection */
265#define SPRN_HID2 0x3F8 /* Hardware Implementation Register 2 */ 267#define SPRN_HID2 0x3F8 /* Hardware Implementation Register 2 */
266#define SPRN_IABR 0x3F2 /* Instruction Address Breakpoint Register */ 268#define SPRN_IABR 0x3F2 /* Instruction Address Breakpoint Register */
269#define SPRN_IABR2 0x3FA /* 83xx */
270#define SPRN_IBCR 0x135 /* 83xx Insn Breakpoint Control Reg */
267#define SPRN_HID4 0x3F4 /* 970 HID4 */ 271#define SPRN_HID4 0x3F4 /* 970 HID4 */
268#define SPRN_HID5 0x3F6 /* 970 HID5 */ 272#define SPRN_HID5 0x3F6 /* 970 HID5 */
269#define SPRN_HID6 0x3F9 /* BE HID 6 */ 273#define SPRN_HID6 0x3F9 /* BE HID 6 */
diff --git a/include/asm-powerpc/uaccess.h b/include/asm-powerpc/uaccess.h
index 1a0736f8803f..bd0fb8495154 100644
--- a/include/asm-powerpc/uaccess.h
+++ b/include/asm-powerpc/uaccess.h
@@ -6,6 +6,7 @@
6 6
7#include <linux/sched.h> 7#include <linux/sched.h>
8#include <linux/errno.h> 8#include <linux/errno.h>
9#include <asm/asm-compat.h>
9#include <asm/processor.h> 10#include <asm/processor.h>
10#include <asm/page.h> 11#include <asm/page.h>
11 12
@@ -141,12 +142,11 @@ extern long __put_user_bad(void);
141 " b 2b\n" \ 142 " b 2b\n" \
142 ".previous\n" \ 143 ".previous\n" \
143 ".section __ex_table,\"a\"\n" \ 144 ".section __ex_table,\"a\"\n" \
144 " .balign %5\n" \ 145 PPC_LONG_ALIGN "\n" \
145 PPC_LONG "1b,3b\n" \ 146 PPC_LONG "1b,3b\n" \
146 ".previous" \ 147 ".previous" \
147 : "=r" (err) \ 148 : "=r" (err) \
148 : "r" (x), "b" (addr), "i" (-EFAULT), "0" (err),\ 149 : "r" (x), "b" (addr), "i" (-EFAULT), "0" (err))
149 "i"(sizeof(unsigned long)))
150 150
151#ifdef __powerpc64__ 151#ifdef __powerpc64__
152#define __put_user_asm2(x, ptr, retval) \ 152#define __put_user_asm2(x, ptr, retval) \
@@ -162,13 +162,12 @@ extern long __put_user_bad(void);
162 " b 3b\n" \ 162 " b 3b\n" \
163 ".previous\n" \ 163 ".previous\n" \
164 ".section __ex_table,\"a\"\n" \ 164 ".section __ex_table,\"a\"\n" \
165 " .balign %5\n" \ 165 PPC_LONG_ALIGN "\n" \
166 PPC_LONG "1b,4b\n" \ 166 PPC_LONG "1b,4b\n" \
167 PPC_LONG "2b,4b\n" \ 167 PPC_LONG "2b,4b\n" \
168 ".previous" \ 168 ".previous" \
169 : "=r" (err) \ 169 : "=r" (err) \
170 : "r" (x), "b" (addr), "i" (-EFAULT), "0" (err),\ 170 : "r" (x), "b" (addr), "i" (-EFAULT), "0" (err))
171 "i"(sizeof(unsigned long)))
172#endif /* __powerpc64__ */ 171#endif /* __powerpc64__ */
173 172
174#define __put_user_size(x, ptr, size, retval) \ 173#define __put_user_size(x, ptr, size, retval) \
@@ -226,12 +225,11 @@ extern long __get_user_bad(void);
226 " b 2b\n" \ 225 " b 2b\n" \
227 ".previous\n" \ 226 ".previous\n" \
228 ".section __ex_table,\"a\"\n" \ 227 ".section __ex_table,\"a\"\n" \
229 " .balign %5\n" \ 228 PPC_LONG_ALIGN "\n" \
230 PPC_LONG "1b,3b\n" \ 229 PPC_LONG "1b,3b\n" \
231 ".previous" \ 230 ".previous" \
232 : "=r" (err), "=r" (x) \ 231 : "=r" (err), "=r" (x) \
233 : "b" (addr), "i" (-EFAULT), "0" (err), \ 232 : "b" (addr), "i" (-EFAULT), "0" (err))
234 "i"(sizeof(unsigned long)))
235 233
236#ifdef __powerpc64__ 234#ifdef __powerpc64__
237#define __get_user_asm2(x, addr, err) \ 235#define __get_user_asm2(x, addr, err) \
@@ -249,13 +247,12 @@ extern long __get_user_bad(void);
249 " b 3b\n" \ 247 " b 3b\n" \
250 ".previous\n" \ 248 ".previous\n" \
251 ".section __ex_table,\"a\"\n" \ 249 ".section __ex_table,\"a\"\n" \
252 " .balign %5\n" \ 250 PPC_LONG_ALIGN "\n" \
253 PPC_LONG "1b,4b\n" \ 251 PPC_LONG "1b,4b\n" \
254 PPC_LONG "2b,4b\n" \ 252 PPC_LONG "2b,4b\n" \
255 ".previous" \ 253 ".previous" \
256 : "=r" (err), "=&r" (x) \ 254 : "=r" (err), "=&r" (x) \
257 : "b" (addr), "i" (-EFAULT), "0" (err), \ 255 : "b" (addr), "i" (-EFAULT), "0" (err))
258 "i"(sizeof(unsigned long)))
259#endif /* __powerpc64__ */ 256#endif /* __powerpc64__ */
260 257
261#define __get_user_size(x, ptr, size, retval) \ 258#define __get_user_size(x, ptr, size, retval) \
diff --git a/include/asm-powerpc/ucc_fast.h b/include/asm-powerpc/ucc_fast.h
index f529f70b1d82..fce16abe7ee1 100644
--- a/include/asm-powerpc/ucc_fast.h
+++ b/include/asm-powerpc/ucc_fast.h
@@ -156,11 +156,11 @@ struct ucc_fast_info {
156 156
157struct ucc_fast_private { 157struct ucc_fast_private {
158 struct ucc_fast_info *uf_info; 158 struct ucc_fast_info *uf_info;
159 struct ucc_fast *uf_regs; /* a pointer to memory map of UCC regs. */ 159 struct ucc_fast __iomem *uf_regs; /* a pointer to the UCC regs. */
160 u32 *p_ucce; /* a pointer to the event register in memory. */ 160 u32 __iomem *p_ucce; /* a pointer to the event register in memory. */
161 u32 *p_uccm; /* a pointer to the mask register in memory. */ 161 u32 __iomem *p_uccm; /* a pointer to the mask register in memory. */
162#ifdef CONFIG_UGETH_TX_ON_DEMAND 162#ifdef CONFIG_UGETH_TX_ON_DEMAND
163 u16 *p_utodr; /* pointer to the transmit on demand register */ 163 u16 __iomem *p_utodr; /* pointer to the transmit on demand register */
164#endif 164#endif
165 int enabled_tx; /* Whether channel is enabled for Tx (ENT) */ 165 int enabled_tx; /* Whether channel is enabled for Tx (ENT) */
166 int enabled_rx; /* Whether channel is enabled for Rx (ENR) */ 166 int enabled_rx; /* Whether channel is enabled for Rx (ENR) */
diff --git a/include/asm-sparc/Kbuild b/include/asm-sparc/Kbuild
index 671223718f0a..6cdaf9d33b38 100644
--- a/include/asm-sparc/Kbuild
+++ b/include/asm-sparc/Kbuild
@@ -1,14 +1 @@
1include include/asm-generic/Kbuild.asm # dummy file to avoid breaking make headers_install
2
3header-y += apc.h
4header-y += asi.h
5header-y += bpp.h
6header-y += jsflash.h
7header-y += openpromio.h
8header-y += reg.h
9header-y += traps.h
10header-y += vfc_ioctls.h
11
12unifdef-y += fbio.h
13unifdef-y += perfctr.h
14unifdef-y += psr.h
diff --git a/include/asm-sparc/agp.h b/include/asm-sparc/agp.h
new file mode 100644
index 000000000000..c2456870b05c
--- /dev/null
+++ b/include/asm-sparc/agp.h
@@ -0,0 +1,20 @@
1#ifndef AGP_H
2#define AGP_H 1
3
4/* dummy for now */
5
6#define map_page_into_agp(page)
7#define unmap_page_from_agp(page)
8#define flush_agp_cache() mb()
9
10/* Convert a physical address to an address suitable for the GART. */
11#define phys_to_gart(x) (x)
12#define gart_to_phys(x) (x)
13
14/* GATT allocation. Returns/accepts GATT kernel virtual address. */
15#define alloc_gatt_pages(order) \
16 ((char *)__get_free_pages(GFP_KERNEL, (order)))
17#define free_gatt_pages(table, order) \
18 free_pages((unsigned long)(table), (order))
19
20#endif
diff --git a/include/asm-sparc/apb.h b/include/asm-sparc/apb.h
new file mode 100644
index 000000000000..8f3b57db810f
--- /dev/null
+++ b/include/asm-sparc/apb.h
@@ -0,0 +1,36 @@
1/*
2 * apb.h: Advanced PCI Bridge Configuration Registers and Bits
3 *
4 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
5 */
6
7#ifndef _SPARC64_APB_H
8#define _SPARC64_APB_H
9
10#define APB_TICK_REGISTER 0xb0
11#define APB_INT_ACK 0xb8
12#define APB_PRIMARY_MASTER_RETRY_LIMIT 0xc0
13#define APB_DMA_ASFR 0xc8
14#define APB_DMA_AFAR 0xd0
15#define APB_PIO_TARGET_RETRY_LIMIT 0xd8
16#define APB_PIO_TARGET_LATENCY_TIMER 0xd9
17#define APB_DMA_TARGET_RETRY_LIMIT 0xda
18#define APB_DMA_TARGET_LATENCY_TIMER 0xdb
19#define APB_SECONDARY_MASTER_RETRY_LIMIT 0xdc
20#define APB_SECONDARY_CONTROL 0xdd
21#define APB_IO_ADDRESS_MAP 0xde
22#define APB_MEM_ADDRESS_MAP 0xdf
23
24#define APB_PCI_CONTROL_LOW 0xe0
25# define APB_PCI_CTL_LOW_ARB_PARK (1 << 21)
26# define APB_PCI_CTL_LOW_ERRINT_EN (1 << 8)
27
28#define APB_PCI_CONTROL_HIGH 0xe4
29# define APB_PCI_CTL_HIGH_SERR (1 << 2)
30# define APB_PCI_CTL_HIGH_ARBITER_EN (1 << 0)
31
32#define APB_PIO_ASFR 0xe8
33#define APB_PIO_AFAR 0xf0
34#define APB_DIAG_REGISTER 0xf8
35
36#endif /* !(_SPARC64_APB_H) */
diff --git a/include/asm-sparc/asi.h b/include/asm-sparc/asi.h
index 158f9b00d43f..74703c5ef985 100644
--- a/include/asm-sparc/asi.h
+++ b/include/asm-sparc/asi.h
@@ -3,7 +3,7 @@
3 3
4/* asi.h: Address Space Identifier values for the sparc. 4/* asi.h: Address Space Identifier values for the sparc.
5 * 5 *
6 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 6 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
7 * 7 *
8 * Pioneer work for sun4m: Paul Hatchman (paul@sfe.com.au) 8 * Pioneer work for sun4m: Paul Hatchman (paul@sfe.com.au)
9 * Joint edition for sun4c+sun4m: Pete A. Zaitcev <zaitcev@ipmce.su> 9 * Joint edition for sun4c+sun4m: Pete A. Zaitcev <zaitcev@ipmce.su>
@@ -108,4 +108,155 @@
108 108
109#define ASI_M_ACTION 0x4c /* Breakpoint Action Register (GNU/Viking) */ 109#define ASI_M_ACTION 0x4c /* Breakpoint Action Register (GNU/Viking) */
110 110
111/* V9 Architecture mandary ASIs. */
112#define ASI_N 0x04 /* Nucleus */
113#define ASI_NL 0x0c /* Nucleus, little endian */
114#define ASI_AIUP 0x10 /* Primary, user */
115#define ASI_AIUS 0x11 /* Secondary, user */
116#define ASI_AIUPL 0x18 /* Primary, user, little endian */
117#define ASI_AIUSL 0x19 /* Secondary, user, little endian */
118#define ASI_P 0x80 /* Primary, implicit */
119#define ASI_S 0x81 /* Secondary, implicit */
120#define ASI_PNF 0x82 /* Primary, no fault */
121#define ASI_SNF 0x83 /* Secondary, no fault */
122#define ASI_PL 0x88 /* Primary, implicit, l-endian */
123#define ASI_SL 0x89 /* Secondary, implicit, l-endian */
124#define ASI_PNFL 0x8a /* Primary, no fault, l-endian */
125#define ASI_SNFL 0x8b /* Secondary, no fault, l-endian */
126
127/* SpitFire and later extended ASIs. The "(III)" marker designates
128 * UltraSparc-III and later specific ASIs. The "(CMT)" marker designates
129 * Chip Multi Threading specific ASIs. "(NG)" designates Niagara specific
130 * ASIs, "(4V)" designates SUN4V specific ASIs.
131 */
132#define ASI_PHYS_USE_EC 0x14 /* PADDR, E-cachable */
133#define ASI_PHYS_BYPASS_EC_E 0x15 /* PADDR, E-bit */
134#define ASI_BLK_AIUP_4V 0x16 /* (4V) Prim, user, block ld/st */
135#define ASI_BLK_AIUS_4V 0x17 /* (4V) Sec, user, block ld/st */
136#define ASI_PHYS_USE_EC_L 0x1c /* PADDR, E-cachable, little endian*/
137#define ASI_PHYS_BYPASS_EC_E_L 0x1d /* PADDR, E-bit, little endian */
138#define ASI_BLK_AIUP_L_4V 0x1e /* (4V) Prim, user, block, l-endian*/
139#define ASI_BLK_AIUS_L_4V 0x1f /* (4V) Sec, user, block, l-endian */
140#define ASI_SCRATCHPAD 0x20 /* (4V) Scratch Pad Registers */
141#define ASI_MMU 0x21 /* (4V) MMU Context Registers */
142#define ASI_BLK_INIT_QUAD_LDD_AIUS 0x23 /* (NG) init-store, twin load,
143 * secondary, user
144 */
145#define ASI_NUCLEUS_QUAD_LDD 0x24 /* Cachable, qword load */
146#define ASI_QUEUE 0x25 /* (4V) Interrupt Queue Registers */
147#define ASI_QUAD_LDD_PHYS_4V 0x26 /* (4V) Physical, qword load */
148#define ASI_NUCLEUS_QUAD_LDD_L 0x2c /* Cachable, qword load, l-endian */
149#define ASI_QUAD_LDD_PHYS_L_4V 0x2e /* (4V) Phys, qword load, l-endian */
150#define ASI_PCACHE_DATA_STATUS 0x30 /* (III) PCache data stat RAM diag */
151#define ASI_PCACHE_DATA 0x31 /* (III) PCache data RAM diag */
152#define ASI_PCACHE_TAG 0x32 /* (III) PCache tag RAM diag */
153#define ASI_PCACHE_SNOOP_TAG 0x33 /* (III) PCache snoop tag RAM diag */
154#define ASI_QUAD_LDD_PHYS 0x34 /* (III+) PADDR, qword load */
155#define ASI_WCACHE_VALID_BITS 0x38 /* (III) WCache Valid Bits diag */
156#define ASI_WCACHE_DATA 0x39 /* (III) WCache data RAM diag */
157#define ASI_WCACHE_TAG 0x3a /* (III) WCache tag RAM diag */
158#define ASI_WCACHE_SNOOP_TAG 0x3b /* (III) WCache snoop tag RAM diag */
159#define ASI_QUAD_LDD_PHYS_L 0x3c /* (III+) PADDR, qw-load, l-endian */
160#define ASI_SRAM_FAST_INIT 0x40 /* (III+) Fast SRAM init */
161#define ASI_CORE_AVAILABLE 0x41 /* (CMT) LP Available */
162#define ASI_CORE_ENABLE_STAT 0x41 /* (CMT) LP Enable Status */
163#define ASI_CORE_ENABLE 0x41 /* (CMT) LP Enable RW */
164#define ASI_XIR_STEERING 0x41 /* (CMT) XIR Steering RW */
165#define ASI_CORE_RUNNING_RW 0x41 /* (CMT) LP Running RW */
166#define ASI_CORE_RUNNING_W1S 0x41 /* (CMT) LP Running Write-One Set */
167#define ASI_CORE_RUNNING_W1C 0x41 /* (CMT) LP Running Write-One Clr */
168#define ASI_CORE_RUNNING_STAT 0x41 /* (CMT) LP Running Status */
169#define ASI_CMT_ERROR_STEERING 0x41 /* (CMT) Error Steering RW */
170#define ASI_DCACHE_INVALIDATE 0x42 /* (III) DCache Invalidate diag */
171#define ASI_DCACHE_UTAG 0x43 /* (III) DCache uTag diag */
172#define ASI_DCACHE_SNOOP_TAG 0x44 /* (III) DCache snoop tag RAM diag */
173#define ASI_LSU_CONTROL 0x45 /* Load-store control unit */
174#define ASI_DCU_CONTROL_REG 0x45 /* (III) DCache Unit Control reg */
175#define ASI_DCACHE_DATA 0x46 /* DCache data-ram diag access */
176#define ASI_DCACHE_TAG 0x47 /* Dcache tag/valid ram diag access*/
177#define ASI_INTR_DISPATCH_STAT 0x48 /* IRQ vector dispatch status */
178#define ASI_INTR_RECEIVE 0x49 /* IRQ vector receive status */
179#define ASI_UPA_CONFIG 0x4a /* UPA config space */
180#define ASI_JBUS_CONFIG 0x4a /* (IIIi) JBUS Config Register */
181#define ASI_SAFARI_CONFIG 0x4a /* (III) Safari Config Register */
182#define ASI_SAFARI_ADDRESS 0x4a /* (III) Safari Address Register */
183#define ASI_ESTATE_ERROR_EN 0x4b /* E-cache error enable space */
184#define ASI_AFSR 0x4c /* Async fault status register */
185#define ASI_AFAR 0x4d /* Async fault address register */
186#define ASI_EC_TAG_DATA 0x4e /* E-cache tag/valid ram diag acc */
187#define ASI_IMMU 0x50 /* Insn-MMU main register space */
188#define ASI_IMMU_TSB_8KB_PTR 0x51 /* Insn-MMU 8KB TSB pointer reg */
189#define ASI_IMMU_TSB_64KB_PTR 0x52 /* Insn-MMU 64KB TSB pointer reg */
190#define ASI_ITLB_DATA_IN 0x54 /* Insn-MMU TLB data in reg */
191#define ASI_ITLB_DATA_ACCESS 0x55 /* Insn-MMU TLB data access reg */
192#define ASI_ITLB_TAG_READ 0x56 /* Insn-MMU TLB tag read reg */
193#define ASI_IMMU_DEMAP 0x57 /* Insn-MMU TLB demap */
194#define ASI_DMMU 0x58 /* Data-MMU main register space */
195#define ASI_DMMU_TSB_8KB_PTR 0x59 /* Data-MMU 8KB TSB pointer reg */
196#define ASI_DMMU_TSB_64KB_PTR 0x5a /* Data-MMU 16KB TSB pointer reg */
197#define ASI_DMMU_TSB_DIRECT_PTR 0x5b /* Data-MMU TSB direct pointer reg */
198#define ASI_DTLB_DATA_IN 0x5c /* Data-MMU TLB data in reg */
199#define ASI_DTLB_DATA_ACCESS 0x5d /* Data-MMU TLB data access reg */
200#define ASI_DTLB_TAG_READ 0x5e /* Data-MMU TLB tag read reg */
201#define ASI_DMMU_DEMAP 0x5f /* Data-MMU TLB demap */
202#define ASI_IIU_INST_TRAP 0x60 /* (III) Instruction Breakpoint */
203#define ASI_INTR_ID 0x63 /* (CMT) Interrupt ID register */
204#define ASI_CORE_ID 0x63 /* (CMT) LP ID register */
205#define ASI_CESR_ID 0x63 /* (CMT) CESR ID register */
206#define ASI_IC_INSTR 0x66 /* Insn cache instrucion ram diag */
207#define ASI_IC_TAG 0x67 /* Insn cache tag/valid ram diag */
208#define ASI_IC_STAG 0x68 /* (III) Insn cache snoop tag ram */
209#define ASI_IC_PRE_DECODE 0x6e /* Insn cache pre-decode ram diag */
210#define ASI_IC_NEXT_FIELD 0x6f /* Insn cache next-field ram diag */
211#define ASI_BRPRED_ARRAY 0x6f /* (III) Branch Prediction RAM diag*/
212#define ASI_BLK_AIUP 0x70 /* Primary, user, block load/store */
213#define ASI_BLK_AIUS 0x71 /* Secondary, user, block ld/st */
214#define ASI_MCU_CTRL_REG 0x72 /* (III) Memory controller regs */
215#define ASI_EC_DATA 0x74 /* (III) E-cache data staging reg */
216#define ASI_EC_CTRL 0x75 /* (III) E-cache control reg */
217#define ASI_EC_W 0x76 /* E-cache diag write access */
218#define ASI_UDB_ERROR_W 0x77 /* External UDB error regs W */
219#define ASI_UDB_CONTROL_W 0x77 /* External UDB control regs W */
220#define ASI_INTR_W 0x77 /* IRQ vector dispatch write */
221#define ASI_INTR_DATAN_W 0x77 /* (III) Out irq vector data reg N */
222#define ASI_INTR_DISPATCH_W 0x77 /* (III) Interrupt vector dispatch */
223#define ASI_BLK_AIUPL 0x78 /* Primary, user, little, blk ld/st*/
224#define ASI_BLK_AIUSL 0x79 /* Secondary, user, little, blk ld/st*/
225#define ASI_EC_R 0x7e /* E-cache diag read access */
226#define ASI_UDBH_ERROR_R 0x7f /* External UDB error regs rd hi */
227#define ASI_UDBL_ERROR_R 0x7f /* External UDB error regs rd low */
228#define ASI_UDBH_CONTROL_R 0x7f /* External UDB control regs rd hi */
229#define ASI_UDBL_CONTROL_R 0x7f /* External UDB control regs rd low*/
230#define ASI_INTR_R 0x7f /* IRQ vector dispatch read */
231#define ASI_INTR_DATAN_R 0x7f /* (III) In irq vector data reg N */
232#define ASI_PST8_P 0xc0 /* Primary, 8 8-bit, partial */
233#define ASI_PST8_S 0xc1 /* Secondary, 8 8-bit, partial */
234#define ASI_PST16_P 0xc2 /* Primary, 4 16-bit, partial */
235#define ASI_PST16_S 0xc3 /* Secondary, 4 16-bit, partial */
236#define ASI_PST32_P 0xc4 /* Primary, 2 32-bit, partial */
237#define ASI_PST32_S 0xc5 /* Secondary, 2 32-bit, partial */
238#define ASI_PST8_PL 0xc8 /* Primary, 8 8-bit, partial, L */
239#define ASI_PST8_SL 0xc9 /* Secondary, 8 8-bit, partial, L */
240#define ASI_PST16_PL 0xca /* Primary, 4 16-bit, partial, L */
241#define ASI_PST16_SL 0xcb /* Secondary, 4 16-bit, partial, L */
242#define ASI_PST32_PL 0xcc /* Primary, 2 32-bit, partial, L */
243#define ASI_PST32_SL 0xcd /* Secondary, 2 32-bit, partial, L */
244#define ASI_FL8_P 0xd0 /* Primary, 1 8-bit, fpu ld/st */
245#define ASI_FL8_S 0xd1 /* Secondary, 1 8-bit, fpu ld/st */
246#define ASI_FL16_P 0xd2 /* Primary, 1 16-bit, fpu ld/st */
247#define ASI_FL16_S 0xd3 /* Secondary, 1 16-bit, fpu ld/st */
248#define ASI_FL8_PL 0xd8 /* Primary, 1 8-bit, fpu ld/st, L */
249#define ASI_FL8_SL 0xd9 /* Secondary, 1 8-bit, fpu ld/st, L*/
250#define ASI_FL16_PL 0xda /* Primary, 1 16-bit, fpu ld/st, L */
251#define ASI_FL16_SL 0xdb /* Secondary, 1 16-bit, fpu ld/st,L*/
252#define ASI_BLK_COMMIT_P 0xe0 /* Primary, blk store commit */
253#define ASI_BLK_COMMIT_S 0xe1 /* Secondary, blk store commit */
254#define ASI_BLK_INIT_QUAD_LDD_P 0xe2 /* (NG) init-store, twin load,
255 * primary, implicit
256 */
257#define ASI_BLK_P 0xf0 /* Primary, blk ld/st */
258#define ASI_BLK_S 0xf1 /* Secondary, blk ld/st */
259#define ASI_BLK_PL 0xf8 /* Primary, blk ld/st, little */
260#define ASI_BLK_SL 0xf9 /* Secondary, blk ld/st, little */
261
111#endif /* _SPARC_ASI_H */ 262#endif /* _SPARC_ASI_H */
diff --git a/include/asm-sparc/atomic.h b/include/asm-sparc/atomic.h
index 5c944b5a8040..66d8166ec1d7 100644
--- a/include/asm-sparc/atomic.h
+++ b/include/asm-sparc/atomic.h
@@ -1,165 +1,8 @@
1/* atomic.h: These still suck, but the I-cache hit rate is higher. 1#ifndef ___ASM_SPARC_ATOMIC_H
2 * 2#define ___ASM_SPARC_ATOMIC_H
3 * Copyright (C) 1996 David S. Miller (davem@davemloft.net) 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com.au) 4#include <asm-sparc/atomic_64.h>
5 * Copyright (C) 2007 Kyle McMartin (kyle@parisc-linux.org)
6 *
7 * Additions by Keith M Wesolowski (wesolows@foobazco.org) based
8 * on asm-parisc/atomic.h Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>.
9 */
10
11#ifndef __ARCH_SPARC_ATOMIC__
12#define __ARCH_SPARC_ATOMIC__
13
14#include <linux/types.h>
15
16typedef struct { volatile int counter; } atomic_t;
17
18#ifdef __KERNEL__
19
20#define ATOMIC_INIT(i) { (i) }
21
22extern int __atomic_add_return(int, atomic_t *);
23extern int atomic_cmpxchg(atomic_t *, int, int);
24#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
25extern int atomic_add_unless(atomic_t *, int, int);
26extern void atomic_set(atomic_t *, int);
27
28#define atomic_read(v) ((v)->counter)
29
30#define atomic_add(i, v) ((void)__atomic_add_return( (int)(i), (v)))
31#define atomic_sub(i, v) ((void)__atomic_add_return(-(int)(i), (v)))
32#define atomic_inc(v) ((void)__atomic_add_return( 1, (v)))
33#define atomic_dec(v) ((void)__atomic_add_return( -1, (v)))
34
35#define atomic_add_return(i, v) (__atomic_add_return( (int)(i), (v)))
36#define atomic_sub_return(i, v) (__atomic_add_return(-(int)(i), (v)))
37#define atomic_inc_return(v) (__atomic_add_return( 1, (v)))
38#define atomic_dec_return(v) (__atomic_add_return( -1, (v)))
39
40#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
41
42/*
43 * atomic_inc_and_test - increment and test
44 * @v: pointer of type atomic_t
45 *
46 * Atomically increments @v by 1
47 * and returns true if the result is zero, or false for all
48 * other cases.
49 */
50#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
51
52#define atomic_dec_and_test(v) (atomic_dec_return(v) == 0)
53#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
54
55#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
56
57/* This is the old 24-bit implementation. It's still used internally
58 * by some sparc-specific code, notably the semaphore implementation.
59 */
60typedef struct { volatile int counter; } atomic24_t;
61
62#ifndef CONFIG_SMP
63
64#define ATOMIC24_INIT(i) { (i) }
65#define atomic24_read(v) ((v)->counter)
66#define atomic24_set(v, i) (((v)->counter) = i)
67
68#else 5#else
69/* We do the bulk of the actual work out of line in two common 6#include <asm-sparc/atomic_32.h>
70 * routines in assembler, see arch/sparc/lib/atomic.S for the 7#endif
71 * "fun" details.
72 *
73 * For SMP the trick is you embed the spin lock byte within
74 * the word, use the low byte so signedness is easily retained
75 * via a quick arithmetic shift. It looks like this:
76 *
77 * ----------------------------------------
78 * | signed 24-bit counter value | lock | atomic_t
79 * ----------------------------------------
80 * 31 8 7 0
81 */
82
83#define ATOMIC24_INIT(i) { ((i) << 8) }
84
85static inline int atomic24_read(const atomic24_t *v)
86{
87 int ret = v->counter;
88
89 while(ret & 0xff)
90 ret = v->counter;
91
92 return ret >> 8;
93}
94
95#define atomic24_set(v, i) (((v)->counter) = ((i) << 8))
96#endif 8#endif
97
98static inline int __atomic24_add(int i, atomic24_t *v)
99{
100 register volatile int *ptr asm("g1");
101 register int increment asm("g2");
102 register int tmp1 asm("g3");
103 register int tmp2 asm("g4");
104 register int tmp3 asm("g7");
105
106 ptr = &v->counter;
107 increment = i;
108
109 __asm__ __volatile__(
110 "mov %%o7, %%g4\n\t"
111 "call ___atomic24_add\n\t"
112 " add %%o7, 8, %%o7\n"
113 : "=&r" (increment), "=r" (tmp1), "=r" (tmp2), "=r" (tmp3)
114 : "0" (increment), "r" (ptr)
115 : "memory", "cc");
116
117 return increment;
118}
119
120static inline int __atomic24_sub(int i, atomic24_t *v)
121{
122 register volatile int *ptr asm("g1");
123 register int increment asm("g2");
124 register int tmp1 asm("g3");
125 register int tmp2 asm("g4");
126 register int tmp3 asm("g7");
127
128 ptr = &v->counter;
129 increment = i;
130
131 __asm__ __volatile__(
132 "mov %%o7, %%g4\n\t"
133 "call ___atomic24_sub\n\t"
134 " add %%o7, 8, %%o7\n"
135 : "=&r" (increment), "=r" (tmp1), "=r" (tmp2), "=r" (tmp3)
136 : "0" (increment), "r" (ptr)
137 : "memory", "cc");
138
139 return increment;
140}
141
142#define atomic24_add(i, v) ((void)__atomic24_add((i), (v)))
143#define atomic24_sub(i, v) ((void)__atomic24_sub((i), (v)))
144
145#define atomic24_dec_return(v) __atomic24_sub(1, (v))
146#define atomic24_inc_return(v) __atomic24_add(1, (v))
147
148#define atomic24_sub_and_test(i, v) (__atomic24_sub((i), (v)) == 0)
149#define atomic24_dec_and_test(v) (__atomic24_sub(1, (v)) == 0)
150
151#define atomic24_inc(v) ((void)__atomic24_add(1, (v)))
152#define atomic24_dec(v) ((void)__atomic24_sub(1, (v)))
153
154#define atomic24_add_negative(i, v) (__atomic24_add((i), (v)) < 0)
155
156/* Atomic operations are already serializing */
157#define smp_mb__before_atomic_dec() barrier()
158#define smp_mb__after_atomic_dec() barrier()
159#define smp_mb__before_atomic_inc() barrier()
160#define smp_mb__after_atomic_inc() barrier()
161
162#endif /* !(__KERNEL__) */
163
164#include <asm-generic/atomic.h>
165#endif /* !(__ARCH_SPARC_ATOMIC__) */
diff --git a/include/asm-sparc/atomic_32.h b/include/asm-sparc/atomic_32.h
new file mode 100644
index 000000000000..5c944b5a8040
--- /dev/null
+++ b/include/asm-sparc/atomic_32.h
@@ -0,0 +1,165 @@
1/* atomic.h: These still suck, but the I-cache hit rate is higher.
2 *
3 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com.au)
5 * Copyright (C) 2007 Kyle McMartin (kyle@parisc-linux.org)
6 *
7 * Additions by Keith M Wesolowski (wesolows@foobazco.org) based
8 * on asm-parisc/atomic.h Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>.
9 */
10
11#ifndef __ARCH_SPARC_ATOMIC__
12#define __ARCH_SPARC_ATOMIC__
13
14#include <linux/types.h>
15
16typedef struct { volatile int counter; } atomic_t;
17
18#ifdef __KERNEL__
19
20#define ATOMIC_INIT(i) { (i) }
21
22extern int __atomic_add_return(int, atomic_t *);
23extern int atomic_cmpxchg(atomic_t *, int, int);
24#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
25extern int atomic_add_unless(atomic_t *, int, int);
26extern void atomic_set(atomic_t *, int);
27
28#define atomic_read(v) ((v)->counter)
29
30#define atomic_add(i, v) ((void)__atomic_add_return( (int)(i), (v)))
31#define atomic_sub(i, v) ((void)__atomic_add_return(-(int)(i), (v)))
32#define atomic_inc(v) ((void)__atomic_add_return( 1, (v)))
33#define atomic_dec(v) ((void)__atomic_add_return( -1, (v)))
34
35#define atomic_add_return(i, v) (__atomic_add_return( (int)(i), (v)))
36#define atomic_sub_return(i, v) (__atomic_add_return(-(int)(i), (v)))
37#define atomic_inc_return(v) (__atomic_add_return( 1, (v)))
38#define atomic_dec_return(v) (__atomic_add_return( -1, (v)))
39
40#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
41
42/*
43 * atomic_inc_and_test - increment and test
44 * @v: pointer of type atomic_t
45 *
46 * Atomically increments @v by 1
47 * and returns true if the result is zero, or false for all
48 * other cases.
49 */
50#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
51
52#define atomic_dec_and_test(v) (atomic_dec_return(v) == 0)
53#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
54
55#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
56
57/* This is the old 24-bit implementation. It's still used internally
58 * by some sparc-specific code, notably the semaphore implementation.
59 */
60typedef struct { volatile int counter; } atomic24_t;
61
62#ifndef CONFIG_SMP
63
64#define ATOMIC24_INIT(i) { (i) }
65#define atomic24_read(v) ((v)->counter)
66#define atomic24_set(v, i) (((v)->counter) = i)
67
68#else
69/* We do the bulk of the actual work out of line in two common
70 * routines in assembler, see arch/sparc/lib/atomic.S for the
71 * "fun" details.
72 *
73 * For SMP the trick is you embed the spin lock byte within
74 * the word, use the low byte so signedness is easily retained
75 * via a quick arithmetic shift. It looks like this:
76 *
77 * ----------------------------------------
78 * | signed 24-bit counter value | lock | atomic_t
79 * ----------------------------------------
80 * 31 8 7 0
81 */
82
83#define ATOMIC24_INIT(i) { ((i) << 8) }
84
85static inline int atomic24_read(const atomic24_t *v)
86{
87 int ret = v->counter;
88
89 while(ret & 0xff)
90 ret = v->counter;
91
92 return ret >> 8;
93}
94
95#define atomic24_set(v, i) (((v)->counter) = ((i) << 8))
96#endif
97
98static inline int __atomic24_add(int i, atomic24_t *v)
99{
100 register volatile int *ptr asm("g1");
101 register int increment asm("g2");
102 register int tmp1 asm("g3");
103 register int tmp2 asm("g4");
104 register int tmp3 asm("g7");
105
106 ptr = &v->counter;
107 increment = i;
108
109 __asm__ __volatile__(
110 "mov %%o7, %%g4\n\t"
111 "call ___atomic24_add\n\t"
112 " add %%o7, 8, %%o7\n"
113 : "=&r" (increment), "=r" (tmp1), "=r" (tmp2), "=r" (tmp3)
114 : "0" (increment), "r" (ptr)
115 : "memory", "cc");
116
117 return increment;
118}
119
120static inline int __atomic24_sub(int i, atomic24_t *v)
121{
122 register volatile int *ptr asm("g1");
123 register int increment asm("g2");
124 register int tmp1 asm("g3");
125 register int tmp2 asm("g4");
126 register int tmp3 asm("g7");
127
128 ptr = &v->counter;
129 increment = i;
130
131 __asm__ __volatile__(
132 "mov %%o7, %%g4\n\t"
133 "call ___atomic24_sub\n\t"
134 " add %%o7, 8, %%o7\n"
135 : "=&r" (increment), "=r" (tmp1), "=r" (tmp2), "=r" (tmp3)
136 : "0" (increment), "r" (ptr)
137 : "memory", "cc");
138
139 return increment;
140}
141
142#define atomic24_add(i, v) ((void)__atomic24_add((i), (v)))
143#define atomic24_sub(i, v) ((void)__atomic24_sub((i), (v)))
144
145#define atomic24_dec_return(v) __atomic24_sub(1, (v))
146#define atomic24_inc_return(v) __atomic24_add(1, (v))
147
148#define atomic24_sub_and_test(i, v) (__atomic24_sub((i), (v)) == 0)
149#define atomic24_dec_and_test(v) (__atomic24_sub(1, (v)) == 0)
150
151#define atomic24_inc(v) ((void)__atomic24_add(1, (v)))
152#define atomic24_dec(v) ((void)__atomic24_sub(1, (v)))
153
154#define atomic24_add_negative(i, v) (__atomic24_add((i), (v)) < 0)
155
156/* Atomic operations are already serializing */
157#define smp_mb__before_atomic_dec() barrier()
158#define smp_mb__after_atomic_dec() barrier()
159#define smp_mb__before_atomic_inc() barrier()
160#define smp_mb__after_atomic_inc() barrier()
161
162#endif /* !(__KERNEL__) */
163
164#include <asm-generic/atomic.h>
165#endif /* !(__ARCH_SPARC_ATOMIC__) */
diff --git a/include/asm-sparc/atomic_64.h b/include/asm-sparc/atomic_64.h
new file mode 100644
index 000000000000..2c71ec4a3b18
--- /dev/null
+++ b/include/asm-sparc/atomic_64.h
@@ -0,0 +1,128 @@
1/* atomic.h: Thankfully the V9 is at least reasonable for this
2 * stuff.
3 *
4 * Copyright (C) 1996, 1997, 2000 David S. Miller (davem@redhat.com)
5 */
6
7#ifndef __ARCH_SPARC64_ATOMIC__
8#define __ARCH_SPARC64_ATOMIC__
9
10#include <linux/types.h>
11#include <asm/system.h>
12
13typedef struct { volatile int counter; } atomic_t;
14typedef struct { volatile __s64 counter; } atomic64_t;
15
16#define ATOMIC_INIT(i) { (i) }
17#define ATOMIC64_INIT(i) { (i) }
18
19#define atomic_read(v) ((v)->counter)
20#define atomic64_read(v) ((v)->counter)
21
22#define atomic_set(v, i) (((v)->counter) = i)
23#define atomic64_set(v, i) (((v)->counter) = i)
24
25extern void atomic_add(int, atomic_t *);
26extern void atomic64_add(int, atomic64_t *);
27extern void atomic_sub(int, atomic_t *);
28extern void atomic64_sub(int, atomic64_t *);
29
30extern int atomic_add_ret(int, atomic_t *);
31extern int atomic64_add_ret(int, atomic64_t *);
32extern int atomic_sub_ret(int, atomic_t *);
33extern int atomic64_sub_ret(int, atomic64_t *);
34
35#define atomic_dec_return(v) atomic_sub_ret(1, v)
36#define atomic64_dec_return(v) atomic64_sub_ret(1, v)
37
38#define atomic_inc_return(v) atomic_add_ret(1, v)
39#define atomic64_inc_return(v) atomic64_add_ret(1, v)
40
41#define atomic_sub_return(i, v) atomic_sub_ret(i, v)
42#define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
43
44#define atomic_add_return(i, v) atomic_add_ret(i, v)
45#define atomic64_add_return(i, v) atomic64_add_ret(i, v)
46
47/*
48 * atomic_inc_and_test - increment and test
49 * @v: pointer of type atomic_t
50 *
51 * Atomically increments @v by 1
52 * and returns true if the result is zero, or false for all
53 * other cases.
54 */
55#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
56#define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
57
58#define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
59#define atomic64_sub_and_test(i, v) (atomic64_sub_ret(i, v) == 0)
60
61#define atomic_dec_and_test(v) (atomic_sub_ret(1, v) == 0)
62#define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
63
64#define atomic_inc(v) atomic_add(1, v)
65#define atomic64_inc(v) atomic64_add(1, v)
66
67#define atomic_dec(v) atomic_sub(1, v)
68#define atomic64_dec(v) atomic64_sub(1, v)
69
70#define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
71#define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
72
73#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
74#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
75
76static inline int atomic_add_unless(atomic_t *v, int a, int u)
77{
78 int c, old;
79 c = atomic_read(v);
80 for (;;) {
81 if (unlikely(c == (u)))
82 break;
83 old = atomic_cmpxchg((v), c, c + (a));
84 if (likely(old == c))
85 break;
86 c = old;
87 }
88 return c != (u);
89}
90
91#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
92
93#define atomic64_cmpxchg(v, o, n) \
94 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
95#define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
96
97static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
98{
99 long c, old;
100 c = atomic64_read(v);
101 for (;;) {
102 if (unlikely(c == (u)))
103 break;
104 old = atomic64_cmpxchg((v), c, c + (a));
105 if (likely(old == c))
106 break;
107 c = old;
108 }
109 return c != (u);
110}
111
112#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
113
114/* Atomic operations are already serializing */
115#ifdef CONFIG_SMP
116#define smp_mb__before_atomic_dec() membar_storeload_loadload();
117#define smp_mb__after_atomic_dec() membar_storeload_storestore();
118#define smp_mb__before_atomic_inc() membar_storeload_loadload();
119#define smp_mb__after_atomic_inc() membar_storeload_storestore();
120#else
121#define smp_mb__before_atomic_dec() barrier()
122#define smp_mb__after_atomic_dec() barrier()
123#define smp_mb__before_atomic_inc() barrier()
124#define smp_mb__after_atomic_inc() barrier()
125#endif
126
127#include <asm-generic/atomic.h>
128#endif /* !(__ARCH_SPARC64_ATOMIC__) */
diff --git a/include/asm-sparc/auxio.h b/include/asm-sparc/auxio.h
index e552b8d68450..24c6f3c0f577 100644
--- a/include/asm-sparc/auxio.h
+++ b/include/asm-sparc/auxio.h
@@ -1,89 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_AUXIO_H
2 * auxio.h: Definitions and code for the Auxiliary I/O register. 2#define ___ASM_SPARC_AUXIO_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 4#include <asm-sparc/auxio_64.h>
5 */ 5#else
6#ifndef _SPARC_AUXIO_H 6#include <asm-sparc/auxio_32.h>
7#define _SPARC_AUXIO_H 7#endif
8 8#endif
9#include <asm/system.h>
10#include <asm/vaddrs.h>
11
12/* This register is an unsigned char in IO space. It does two things.
13 * First, it is used to control the front panel LED light on machines
14 * that have it (good for testing entry points to trap handlers and irq's)
15 * Secondly, it controls various floppy drive parameters.
16 */
17#define AUXIO_ORMEIN 0xf0 /* All writes must set these bits. */
18#define AUXIO_ORMEIN4M 0xc0 /* sun4m - All writes must set these bits. */
19#define AUXIO_FLPY_DENS 0x20 /* Floppy density, high if set. Read only. */
20#define AUXIO_FLPY_DCHG 0x10 /* A disk change occurred. Read only. */
21#define AUXIO_EDGE_ON 0x10 /* sun4m - On means Jumper block is in. */
22#define AUXIO_FLPY_DSEL 0x08 /* Drive select/start-motor. Write only. */
23#define AUXIO_LINK_TEST 0x08 /* sun4m - On means TPE Carrier detect. */
24
25/* Set the following to one, then zero, after doing a pseudo DMA transfer. */
26#define AUXIO_FLPY_TCNT 0x04 /* Floppy terminal count. Write only. */
27
28/* Set the following to zero to eject the floppy. */
29#define AUXIO_FLPY_EJCT 0x02 /* Eject floppy disk. Write only. */
30#define AUXIO_LED 0x01 /* On if set, off if unset. Read/Write */
31
32#ifndef __ASSEMBLY__
33
34/*
35 * NOTE: these routines are implementation dependent--
36 * understand the hardware you are querying!
37 */
38extern void set_auxio(unsigned char bits_on, unsigned char bits_off);
39extern unsigned char get_auxio(void); /* .../asm-sparc/floppy.h */
40
41/*
42 * The following routines are provided for driver-compatibility
43 * with sparc64 (primarily sunlance.c)
44 */
45
46#define AUXIO_LTE_ON 1
47#define AUXIO_LTE_OFF 0
48
49/* auxio_set_lte - Set Link Test Enable (TPE Link Detect)
50 *
51 * on - AUXIO_LTE_ON or AUXIO_LTE_OFF
52 */
53#define auxio_set_lte(on) \
54do { \
55 if(on) { \
56 set_auxio(AUXIO_LINK_TEST, 0); \
57 } else { \
58 set_auxio(0, AUXIO_LINK_TEST); \
59 } \
60} while (0)
61
62#define AUXIO_LED_ON 1
63#define AUXIO_LED_OFF 0
64
65/* auxio_set_led - Set system front panel LED
66 *
67 * on - AUXIO_LED_ON or AUXIO_LED_OFF
68 */
69#define auxio_set_led(on) \
70do { \
71 if(on) { \
72 set_auxio(AUXIO_LED, 0); \
73 } else { \
74 set_auxio(0, AUXIO_LED); \
75 } \
76} while (0)
77
78#endif /* !(__ASSEMBLY__) */
79
80
81/* AUXIO2 (Power Off Control) */
82extern __volatile__ unsigned char * auxio_power_register;
83
84#define AUXIO_POWER_DETECT_FAILURE 32
85#define AUXIO_POWER_CLEAR_FAILURE 2
86#define AUXIO_POWER_OFF 1
87
88
89#endif /* !(_SPARC_AUXIO_H) */
diff --git a/include/asm-sparc/auxio_32.h b/include/asm-sparc/auxio_32.h
new file mode 100644
index 000000000000..4db8f23db20f
--- /dev/null
+++ b/include/asm-sparc/auxio_32.h
@@ -0,0 +1,89 @@
1/*
2 * auxio.h: Definitions and code for the Auxiliary I/O register.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 */
6#ifndef _SPARC_AUXIO_H
7#define _SPARC_AUXIO_H
8
9#include <asm/system.h>
10#include <asm/vaddrs.h>
11
12/* This register is an unsigned char in IO space. It does two things.
13 * First, it is used to control the front panel LED light on machines
14 * that have it (good for testing entry points to trap handlers and irq's)
15 * Secondly, it controls various floppy drive parameters.
16 */
17#define AUXIO_ORMEIN 0xf0 /* All writes must set these bits. */
18#define AUXIO_ORMEIN4M 0xc0 /* sun4m - All writes must set these bits. */
19#define AUXIO_FLPY_DENS 0x20 /* Floppy density, high if set. Read only. */
20#define AUXIO_FLPY_DCHG 0x10 /* A disk change occurred. Read only. */
21#define AUXIO_EDGE_ON 0x10 /* sun4m - On means Jumper block is in. */
22#define AUXIO_FLPY_DSEL 0x08 /* Drive select/start-motor. Write only. */
23#define AUXIO_LINK_TEST 0x08 /* sun4m - On means TPE Carrier detect. */
24
25/* Set the following to one, then zero, after doing a pseudo DMA transfer. */
26#define AUXIO_FLPY_TCNT 0x04 /* Floppy terminal count. Write only. */
27
28/* Set the following to zero to eject the floppy. */
29#define AUXIO_FLPY_EJCT 0x02 /* Eject floppy disk. Write only. */
30#define AUXIO_LED 0x01 /* On if set, off if unset. Read/Write */
31
32#ifndef __ASSEMBLY__
33
34/*
35 * NOTE: these routines are implementation dependent--
36 * understand the hardware you are querying!
37 */
38extern void set_auxio(unsigned char bits_on, unsigned char bits_off);
39extern unsigned char get_auxio(void); /* .../asm-sparc/floppy.h */
40
41/*
42 * The following routines are provided for driver-compatibility
43 * with sparc64 (primarily sunlance.c)
44 */
45
46#define AUXIO_LTE_ON 1
47#define AUXIO_LTE_OFF 0
48
49/* auxio_set_lte - Set Link Test Enable (TPE Link Detect)
50 *
51 * on - AUXIO_LTE_ON or AUXIO_LTE_OFF
52 */
53#define auxio_set_lte(on) \
54do { \
55 if(on) { \
56 set_auxio(AUXIO_LINK_TEST, 0); \
57 } else { \
58 set_auxio(0, AUXIO_LINK_TEST); \
59 } \
60} while (0)
61
62#define AUXIO_LED_ON 1
63#define AUXIO_LED_OFF 0
64
65/* auxio_set_led - Set system front panel LED
66 *
67 * on - AUXIO_LED_ON or AUXIO_LED_OFF
68 */
69#define auxio_set_led(on) \
70do { \
71 if(on) { \
72 set_auxio(AUXIO_LED, 0); \
73 } else { \
74 set_auxio(0, AUXIO_LED); \
75 } \
76} while (0)
77
78#endif /* !(__ASSEMBLY__) */
79
80
81/* AUXIO2 (Power Off Control) */
82extern __volatile__ unsigned char * auxio_power_register;
83
84#define AUXIO_POWER_DETECT_FAILURE 32
85#define AUXIO_POWER_CLEAR_FAILURE 2
86#define AUXIO_POWER_OFF 1
87
88
89#endif /* !(_SPARC_AUXIO_H) */
diff --git a/include/asm-sparc/auxio_64.h b/include/asm-sparc/auxio_64.h
new file mode 100644
index 000000000000..f61cd1e3e395
--- /dev/null
+++ b/include/asm-sparc/auxio_64.h
@@ -0,0 +1,100 @@
1/*
2 * auxio.h: Definitions and code for the Auxiliary I/O registers.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 *
6 * Refactoring for unified NCR/PCIO support 2002 Eric Brower (ebrower@usa.net)
7 */
8#ifndef _SPARC64_AUXIO_H
9#define _SPARC64_AUXIO_H
10
11/* AUXIO implementations:
12 * sbus-based NCR89C105 "Slavio"
13 * LED/Floppy (AUX1) register
14 * Power (AUX2) register
15 *
16 * ebus-based auxio on PCIO
17 * LED Auxio Register
18 * Power Auxio Register
19 *
20 * Register definitions from NCR _NCR89C105 Chip Specification_
21 *
22 * SLAVIO AUX1 @ 0x1900000
23 * -------------------------------------------------
24 * | (R) | (R) | D | (R) | E | M | T | L |
25 * -------------------------------------------------
26 * (R) - bit 7:6,4 are reserved and should be masked in s/w
27 * D - Floppy Density Sense (1=high density) R/O
28 * E - Link Test Enable, directly reflected on AT&T 7213 LTE pin
29 * M - Monitor/Mouse Mux, directly reflected on MON_MSE_MUX pin
30 * T - Terminal Count: sends TC pulse to 82077 floppy controller
31 * L - System LED on front panel (0=off, 1=on)
32 */
33#define AUXIO_AUX1_MASK 0xc0 /* Mask bits */
34#define AUXIO_AUX1_FDENS 0x20 /* Floppy Density Sense */
35#define AUXIO_AUX1_LTE 0x08 /* Link Test Enable */
36#define AUXIO_AUX1_MMUX 0x04 /* Monitor/Mouse Mux */
37#define AUXIO_AUX1_FTCNT 0x02 /* Terminal Count, */
38#define AUXIO_AUX1_LED 0x01 /* System LED */
39
40/* SLAVIO AUX2 @ 0x1910000
41 * -------------------------------------------------
42 * | (R) | (R) | D | (R) | (R) | (R) | C | F |
43 * -------------------------------------------------
44 * (R) - bits 7:6,4:2 are reserved and should be masked in s/w
45 * D - Power Failure Detect (1=power fail)
46 * C - Clear Power Failure Detect Int (1=clear)
47 * F - Power Off (1=power off)
48 */
49#define AUXIO_AUX2_MASK 0xdc /* Mask Bits */
50#define AUXIO_AUX2_PFAILDET 0x20 /* Power Fail Detect */
51#define AUXIO_AUX2_PFAILCLR 0x02 /* Clear Pwr Fail Det Intr */
52#define AUXIO_AUX2_PWR_OFF 0x01 /* Power Off */
53
54/* Register definitions from Sun Microsystems _PCIO_ p/n 802-7837
55 *
56 * PCIO LED Auxio @ 0x726000
57 * -------------------------------------------------
58 * | 31:1 Unused | LED |
59 * -------------------------------------------------
60 * Bits 31:1 unused
61 * LED - System LED on front panel (0=off, 1=on)
62 */
63#define AUXIO_PCIO_LED 0x01 /* System LED */
64
65/* PCIO Power Auxio @ 0x724000
66 * -------------------------------------------------
67 * | 31:2 Unused | CPO | SPO |
68 * -------------------------------------------------
69 * Bits 31:2 unused
70 * CPO - Courtesy Power Off (1=off)
71 * SPO - System Power Off (1=off)
72 */
73#define AUXIO_PCIO_CPWR_OFF 0x02 /* Courtesy Power Off */
74#define AUXIO_PCIO_SPWR_OFF 0x01 /* System Power Off */
75
76#ifndef __ASSEMBLY__
77
78extern void __iomem *auxio_register;
79
80#define AUXIO_LTE_ON 1
81#define AUXIO_LTE_OFF 0
82
83/* auxio_set_lte - Set Link Test Enable (TPE Link Detect)
84 *
85 * on - AUXIO_LTE_ON or AUXIO_LTE_OFF
86 */
87extern void auxio_set_lte(int on);
88
89#define AUXIO_LED_ON 1
90#define AUXIO_LED_OFF 0
91
92/* auxio_set_led - Set system front panel LED
93 *
94 * on - AUXIO_LED_ON or AUXIO_LED_OFF
95 */
96extern void auxio_set_led(int on);
97
98#endif /* ifndef __ASSEMBLY__ */
99
100#endif /* !(_SPARC64_AUXIO_H) */
diff --git a/include/asm-sparc/backoff.h b/include/asm-sparc/backoff.h
new file mode 100644
index 000000000000..fa1fdf67e350
--- /dev/null
+++ b/include/asm-sparc/backoff.h
@@ -0,0 +1,31 @@
1#ifndef _SPARC64_BACKOFF_H
2#define _SPARC64_BACKOFF_H
3
4#define BACKOFF_LIMIT (4 * 1024)
5
6#ifdef CONFIG_SMP
7
8#define BACKOFF_SETUP(reg) \
9 mov 1, reg
10
11#define BACKOFF_SPIN(reg, tmp, label) \
12 mov reg, tmp; \
1388: brnz,pt tmp, 88b; \
14 sub tmp, 1, tmp; \
15 set BACKOFF_LIMIT, tmp; \
16 cmp reg, tmp; \
17 bg,pn %xcc, label; \
18 nop; \
19 ba,pt %xcc, label; \
20 sllx reg, 1, reg;
21
22#else
23
24#define BACKOFF_SETUP(reg)
25#define BACKOFF_SPIN(reg, tmp, label) \
26 ba,pt %xcc, label; \
27 nop;
28
29#endif
30
31#endif /* _SPARC64_BACKOFF_H */
diff --git a/include/asm-sparc/bbc.h b/include/asm-sparc/bbc.h
new file mode 100644
index 000000000000..423a85800aae
--- /dev/null
+++ b/include/asm-sparc/bbc.h
@@ -0,0 +1,225 @@
1/*
2 * bbc.h: Defines for BootBus Controller found on UltraSPARC-III
3 * systems.
4 *
5 * Copyright (C) 2000 David S. Miller (davem@redhat.com)
6 */
7
8#ifndef _SPARC64_BBC_H
9#define _SPARC64_BBC_H
10
11/* Register sizes are indicated by "B" (Byte, 1-byte),
12 * "H" (Half-word, 2 bytes), "W" (Word, 4 bytes) or
13 * "Q" (Quad, 8 bytes) inside brackets.
14 */
15
16#define BBC_AID 0x00 /* [B] Agent ID */
17#define BBC_DEVP 0x01 /* [B] Device Present */
18#define BBC_ARB 0x02 /* [B] Arbitration */
19#define BBC_QUIESCE 0x03 /* [B] Quiesce */
20#define BBC_WDACTION 0x04 /* [B] Watchdog Action */
21#define BBC_SPG 0x06 /* [B] Soft POR Gen */
22#define BBC_SXG 0x07 /* [B] Soft XIR Gen */
23#define BBC_PSRC 0x08 /* [W] POR Source */
24#define BBC_XSRC 0x0c /* [B] XIR Source */
25#define BBC_CSC 0x0d /* [B] Clock Synthesizers Control*/
26#define BBC_ES_CTRL 0x0e /* [H] Energy Star Control */
27#define BBC_ES_ACT 0x10 /* [W] E* Assert Change Time */
28#define BBC_ES_DACT 0x14 /* [B] E* De-Assert Change Time */
29#define BBC_ES_DABT 0x15 /* [B] E* De-Assert Bypass Time */
30#define BBC_ES_ABT 0x16 /* [H] E* Assert Bypass Time */
31#define BBC_ES_PST 0x18 /* [W] E* PLL Settle Time */
32#define BBC_ES_FSL 0x1c /* [W] E* Frequency Switch Latency*/
33#define BBC_EBUST 0x20 /* [Q] EBUS Timing */
34#define BBC_JTAG_CMD 0x28 /* [W] JTAG+ Command */
35#define BBC_JTAG_CTRL 0x2c /* [B] JTAG+ Control */
36#define BBC_I2C_SEL 0x2d /* [B] I2C Selection */
37#define BBC_I2C_0_S1 0x2e /* [B] I2C ctrlr-0 reg S1 */
38#define BBC_I2C_0_S0 0x2f /* [B] I2C ctrlr-0 regs S0,S0',S2,S3*/
39#define BBC_I2C_1_S1 0x30 /* [B] I2C ctrlr-1 reg S1 */
40#define BBC_I2C_1_S0 0x31 /* [B] I2C ctrlr-1 regs S0,S0',S2,S3*/
41#define BBC_KBD_BEEP 0x32 /* [B] Keyboard Beep */
42#define BBC_KBD_BCNT 0x34 /* [W] Keyboard Beep Counter */
43
44#define BBC_REGS_SIZE 0x40
45
46/* There is a 2K scratch ram area at offset 0x80000 but I doubt
47 * we will use it for anything.
48 */
49
50/* Agent ID register. This register shows the Safari Agent ID
51 * for the processors. The value returned depends upon which
52 * cpu is reading the register.
53 */
54#define BBC_AID_ID 0x07 /* Safari ID */
55#define BBC_AID_RESV 0xf8 /* Reserved */
56
57/* Device Present register. One can determine which cpus are actually
58 * present in the machine by interrogating this register.
59 */
60#define BBC_DEVP_CPU0 0x01 /* Processor 0 present */
61#define BBC_DEVP_CPU1 0x02 /* Processor 1 present */
62#define BBC_DEVP_CPU2 0x04 /* Processor 2 present */
63#define BBC_DEVP_CPU3 0x08 /* Processor 3 present */
64#define BBC_DEVP_RESV 0xf0 /* Reserved */
65
66/* Arbitration register. This register is used to block access to
67 * the BBC from a particular cpu.
68 */
69#define BBC_ARB_CPU0 0x01 /* Enable cpu 0 BBC arbitratrion */
70#define BBC_ARB_CPU1 0x02 /* Enable cpu 1 BBC arbitratrion */
71#define BBC_ARB_CPU2 0x04 /* Enable cpu 2 BBC arbitratrion */
72#define BBC_ARB_CPU3 0x08 /* Enable cpu 3 BBC arbitratrion */
73#define BBC_ARB_RESV 0xf0 /* Reserved */
74
75/* Quiesce register. Bus and BBC segments for cpus can be disabled
76 * with this register, ie. for hot plugging.
77 */
78#define BBC_QUIESCE_S02 0x01 /* Quiesce Safari segment for cpu 0 and 2 */
79#define BBC_QUIESCE_S13 0x02 /* Quiesce Safari segment for cpu 1 and 3 */
80#define BBC_QUIESCE_B02 0x04 /* Quiesce BBC segment for cpu 0 and 2 */
81#define BBC_QUIESCE_B13 0x08 /* Quiesce BBC segment for cpu 1 and 3 */
82#define BBC_QUIESCE_FD0 0x10 /* Disable Fatal_Error[0] reporting */
83#define BBC_QUIESCE_FD1 0x20 /* Disable Fatal_Error[1] reporting */
84#define BBC_QUIESCE_FD2 0x40 /* Disable Fatal_Error[2] reporting */
85#define BBC_QUIESCE_FD3 0x80 /* Disable Fatal_Error[3] reporting */
86
87/* Watchdog Action register. When the watchdog device timer expires
88 * a line is enabled to the BBC. The action BBC takes when this line
89 * is asserted can be controlled by this regiser.
90 */
91#define BBC_WDACTION_RST 0x01 /* When set, watchdog causes system reset.
92 * When clear, BBC ignores watchdog signal.
93 */
94#define BBC_WDACTION_RESV 0xfe /* Reserved */
95
96/* Soft_POR_GEN register. The POR (Power On Reset) signal may be asserted
97 * for specific processors or all processors via this register.
98 */
99#define BBC_SPG_CPU0 0x01 /* Assert POR for processor 0 */
100#define BBC_SPG_CPU1 0x02 /* Assert POR for processor 1 */
101#define BBC_SPG_CPU2 0x04 /* Assert POR for processor 2 */
102#define BBC_SPG_CPU3 0x08 /* Assert POR for processor 3 */
103#define BBC_SPG_CPUALL 0x10 /* Reset all processors and reset
104 * the entire system.
105 */
106#define BBC_SPG_RESV 0xe0 /* Reserved */
107
108/* Soft_XIR_GEN register. The XIR (eXternally Initiated Reset) signal
109 * may be asserted to specific processors via this register.
110 */
111#define BBC_SXG_CPU0 0x01 /* Assert XIR for processor 0 */
112#define BBC_SXG_CPU1 0x02 /* Assert XIR for processor 1 */
113#define BBC_SXG_CPU2 0x04 /* Assert XIR for processor 2 */
114#define BBC_SXG_CPU3 0x08 /* Assert XIR for processor 3 */
115#define BBC_SXG_RESV 0xf0 /* Reserved */
116
117/* POR Source register. One may identify the cause of the most recent
118 * reset by reading this register.
119 */
120#define BBC_PSRC_SPG0 0x0001 /* CPU 0 reset via BBC_SPG register */
121#define BBC_PSRC_SPG1 0x0002 /* CPU 1 reset via BBC_SPG register */
122#define BBC_PSRC_SPG2 0x0004 /* CPU 2 reset via BBC_SPG register */
123#define BBC_PSRC_SPG3 0x0008 /* CPU 3 reset via BBC_SPG register */
124#define BBC_PSRC_SPGSYS 0x0010 /* System reset via BBC_SPG register */
125#define BBC_PSRC_JTAG 0x0020 /* System reset via JTAG+ */
126#define BBC_PSRC_BUTTON 0x0040 /* System reset via push-button dongle */
127#define BBC_PSRC_PWRUP 0x0080 /* System reset via power-up */
128#define BBC_PSRC_FE0 0x0100 /* CPU 0 reported Fatal_Error */
129#define BBC_PSRC_FE1 0x0200 /* CPU 1 reported Fatal_Error */
130#define BBC_PSRC_FE2 0x0400 /* CPU 2 reported Fatal_Error */
131#define BBC_PSRC_FE3 0x0800 /* CPU 3 reported Fatal_Error */
132#define BBC_PSRC_FE4 0x1000 /* Schizo reported Fatal_Error */
133#define BBC_PSRC_FE5 0x2000 /* Safari device 5 reported Fatal_Error */
134#define BBC_PSRC_FE6 0x4000 /* CPMS reported Fatal_Error */
135#define BBC_PSRC_SYNTH 0x8000 /* System reset when on-board clock synthesizers
136 * were updated.
137 */
138#define BBC_PSRC_WDT 0x10000 /* System reset via Super I/O watchdog */
139#define BBC_PSRC_RSC 0x20000 /* System reset via RSC remote monitoring
140 * device
141 */
142
143/* XIR Source register. The source of an XIR event sent to a processor may
144 * be determined via this register.
145 */
146#define BBC_XSRC_SXG0 0x01 /* CPU 0 received XIR via Soft_XIR_GEN reg */
147#define BBC_XSRC_SXG1 0x02 /* CPU 1 received XIR via Soft_XIR_GEN reg */
148#define BBC_XSRC_SXG2 0x04 /* CPU 2 received XIR via Soft_XIR_GEN reg */
149#define BBC_XSRC_SXG3 0x08 /* CPU 3 received XIR via Soft_XIR_GEN reg */
150#define BBC_XSRC_JTAG 0x10 /* All CPUs received XIR via JTAG+ */
151#define BBC_XSRC_W_OR_B 0x20 /* All CPUs received XIR either because:
152 * a) Super I/O watchdog fired, or
153 * b) XIR push button was activated
154 */
155#define BBC_XSRC_RESV 0xc0 /* Reserved */
156
157/* Clock Synthesizers Control register. This register provides the big-bang
158 * programming interface to the two clock synthesizers of the machine.
159 */
160#define BBC_CSC_SLOAD 0x01 /* Directly connected to S_LOAD pins */
161#define BBC_CSC_SDATA 0x02 /* Directly connected to S_DATA pins */
162#define BBC_CSC_SCLOCK 0x04 /* Directly connected to S_CLOCK pins */
163#define BBC_CSC_RESV 0x78 /* Reserved */
164#define BBC_CSC_RST 0x80 /* Generate system reset when S_LOAD==1 */
165
166/* Energy Star Control register. This register is used to generate the
167 * clock frequency change trigger to the main system devices (Schizo and
168 * the processors). The transition occurs when bits in this register
169 * go from 0 to 1, only one bit must be set at once else no action
170 * occurs. Basically the sequence of events is:
171 * a) Choose new frequency: full, 1/2 or 1/32
172 * b) Program this desired frequency into the cpus and Schizo.
173 * c) Set the same value in this register.
174 * d) 16 system clocks later, clear this register.
175 */
176#define BBC_ES_CTRL_1_1 0x01 /* Full frequency */
177#define BBC_ES_CTRL_1_2 0x02 /* 1/2 frequency */
178#define BBC_ES_CTRL_1_32 0x20 /* 1/32 frequency */
179#define BBC_ES_RESV 0xdc /* Reserved */
180
181/* Energy Star Assert Change Time register. This determines the number
182 * of BBC clock cycles (which is half the system frequency) between
183 * the detection of FREEZE_ACK being asserted and the assertion of
184 * the CLK_CHANGE_L[2:0] signals.
185 */
186#define BBC_ES_ACT_VAL 0xff
187
188/* Energy Star Assert Bypass Time register. This determines the number
189 * of BBC clock cycles (which is half the system frequency) between
190 * the assertion of the CLK_CHANGE_L[2:0] signals and the assertion of
191 * the ESTAR_PLL_BYPASS signal.
192 */
193#define BBC_ES_ABT_VAL 0xffff
194
195/* Energy Star PLL Settle Time register. This determines the number of
196 * BBC clock cycles (which is half the system frequency) between the
197 * de-assertion of CLK_CHANGE_L[2:0] and the de-assertion of the FREEZE_L
198 * signal.
199 */
200#define BBC_ES_PST_VAL 0xffffffff
201
202/* Energy Star Frequency Switch Latency register. This is the number of
203 * BBC clocks between the de-assertion of CLK_CHANGE_L[2:0] and the first
204 * edge of the Safari clock at the new frequency.
205 */
206#define BBC_ES_FSL_VAL 0xffffffff
207
208/* Keyboard Beep control register. This is a simple enabler for the audio
209 * beep sound.
210 */
211#define BBC_KBD_BEEP_ENABLE 0x01 /* Enable beep */
212#define BBC_KBD_BEEP_RESV 0xfe /* Reserved */
213
214/* Keyboard Beep Counter register. There is a free-running counter inside
215 * the BBC which runs at half the system clock. The bit set in this register
216 * determines when the audio sound is generated. So for example if bit
217 * 10 is set, the audio beep will oscillate at 1/(2**12). The keyboard beep
218 * generator automatically selects a different bit to use if the system clock
219 * is changed via Energy Star.
220 */
221#define BBC_KBD_BCNT_BITS 0x0007fc00
222#define BBC_KBC_BCNT_RESV 0xfff803ff
223
224#endif /* _SPARC64_BBC_H */
225
diff --git a/include/asm-sparc/bitops.h b/include/asm-sparc/bitops.h
index 68b98a7e6454..1a2949d0193f 100644
--- a/include/asm-sparc/bitops.h
+++ b/include/asm-sparc/bitops.h
@@ -1,111 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_BITOPS_H
2 * bitops.h: Bit string operations on the Sparc. 2#define ___ASM_SPARC_BITOPS_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright 1995 David S. Miller (davem@caip.rutgers.edu) 4#include <asm-sparc/bitops_64.h>
5 * Copyright 1996 Eddie C. Dost (ecd@skynet.be) 5#else
6 * Copyright 2001 Anton Blanchard (anton@samba.org) 6#include <asm-sparc/bitops_32.h>
7 */ 7#endif
8
9#ifndef _SPARC_BITOPS_H
10#define _SPARC_BITOPS_H
11
12#include <linux/compiler.h>
13#include <asm/byteorder.h>
14
15#ifdef __KERNEL__
16
17#ifndef _LINUX_BITOPS_H
18#error only <linux/bitops.h> can be included directly
19#endif 8#endif
20
21extern unsigned long ___set_bit(unsigned long *addr, unsigned long mask);
22extern unsigned long ___clear_bit(unsigned long *addr, unsigned long mask);
23extern unsigned long ___change_bit(unsigned long *addr, unsigned long mask);
24
25/*
26 * Set bit 'nr' in 32-bit quantity at address 'addr' where bit '0'
27 * is in the highest of the four bytes and bit '31' is the high bit
28 * within the first byte. Sparc is BIG-Endian. Unless noted otherwise
29 * all bit-ops return 0 if bit was previously clear and != 0 otherwise.
30 */
31static inline int test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
32{
33 unsigned long *ADDR, mask;
34
35 ADDR = ((unsigned long *) addr) + (nr >> 5);
36 mask = 1 << (nr & 31);
37
38 return ___set_bit(ADDR, mask) != 0;
39}
40
41static inline void set_bit(unsigned long nr, volatile unsigned long *addr)
42{
43 unsigned long *ADDR, mask;
44
45 ADDR = ((unsigned long *) addr) + (nr >> 5);
46 mask = 1 << (nr & 31);
47
48 (void) ___set_bit(ADDR, mask);
49}
50
51static inline int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
52{
53 unsigned long *ADDR, mask;
54
55 ADDR = ((unsigned long *) addr) + (nr >> 5);
56 mask = 1 << (nr & 31);
57
58 return ___clear_bit(ADDR, mask) != 0;
59}
60
61static inline void clear_bit(unsigned long nr, volatile unsigned long *addr)
62{
63 unsigned long *ADDR, mask;
64
65 ADDR = ((unsigned long *) addr) + (nr >> 5);
66 mask = 1 << (nr & 31);
67
68 (void) ___clear_bit(ADDR, mask);
69}
70
71static inline int test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
72{
73 unsigned long *ADDR, mask;
74
75 ADDR = ((unsigned long *) addr) + (nr >> 5);
76 mask = 1 << (nr & 31);
77
78 return ___change_bit(ADDR, mask) != 0;
79}
80
81static inline void change_bit(unsigned long nr, volatile unsigned long *addr)
82{
83 unsigned long *ADDR, mask;
84
85 ADDR = ((unsigned long *) addr) + (nr >> 5);
86 mask = 1 << (nr & 31);
87
88 (void) ___change_bit(ADDR, mask);
89}
90
91#include <asm-generic/bitops/non-atomic.h>
92
93#define smp_mb__before_clear_bit() do { } while(0)
94#define smp_mb__after_clear_bit() do { } while(0)
95
96#include <asm-generic/bitops/ffz.h>
97#include <asm-generic/bitops/__ffs.h>
98#include <asm-generic/bitops/sched.h>
99#include <asm-generic/bitops/ffs.h>
100#include <asm-generic/bitops/fls.h>
101#include <asm-generic/bitops/fls64.h>
102#include <asm-generic/bitops/hweight.h>
103#include <asm-generic/bitops/lock.h>
104#include <asm-generic/bitops/find.h>
105#include <asm-generic/bitops/ext2-non-atomic.h>
106#include <asm-generic/bitops/ext2-atomic.h>
107#include <asm-generic/bitops/minix.h>
108
109#endif /* __KERNEL__ */
110
111#endif /* defined(_SPARC_BITOPS_H) */
diff --git a/include/asm-sparc/bitops_32.h b/include/asm-sparc/bitops_32.h
new file mode 100644
index 000000000000..68b98a7e6454
--- /dev/null
+++ b/include/asm-sparc/bitops_32.h
@@ -0,0 +1,111 @@
1/*
2 * bitops.h: Bit string operations on the Sparc.
3 *
4 * Copyright 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright 1996 Eddie C. Dost (ecd@skynet.be)
6 * Copyright 2001 Anton Blanchard (anton@samba.org)
7 */
8
9#ifndef _SPARC_BITOPS_H
10#define _SPARC_BITOPS_H
11
12#include <linux/compiler.h>
13#include <asm/byteorder.h>
14
15#ifdef __KERNEL__
16
17#ifndef _LINUX_BITOPS_H
18#error only <linux/bitops.h> can be included directly
19#endif
20
21extern unsigned long ___set_bit(unsigned long *addr, unsigned long mask);
22extern unsigned long ___clear_bit(unsigned long *addr, unsigned long mask);
23extern unsigned long ___change_bit(unsigned long *addr, unsigned long mask);
24
25/*
26 * Set bit 'nr' in 32-bit quantity at address 'addr' where bit '0'
27 * is in the highest of the four bytes and bit '31' is the high bit
28 * within the first byte. Sparc is BIG-Endian. Unless noted otherwise
29 * all bit-ops return 0 if bit was previously clear and != 0 otherwise.
30 */
31static inline int test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
32{
33 unsigned long *ADDR, mask;
34
35 ADDR = ((unsigned long *) addr) + (nr >> 5);
36 mask = 1 << (nr & 31);
37
38 return ___set_bit(ADDR, mask) != 0;
39}
40
41static inline void set_bit(unsigned long nr, volatile unsigned long *addr)
42{
43 unsigned long *ADDR, mask;
44
45 ADDR = ((unsigned long *) addr) + (nr >> 5);
46 mask = 1 << (nr & 31);
47
48 (void) ___set_bit(ADDR, mask);
49}
50
51static inline int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
52{
53 unsigned long *ADDR, mask;
54
55 ADDR = ((unsigned long *) addr) + (nr >> 5);
56 mask = 1 << (nr & 31);
57
58 return ___clear_bit(ADDR, mask) != 0;
59}
60
61static inline void clear_bit(unsigned long nr, volatile unsigned long *addr)
62{
63 unsigned long *ADDR, mask;
64
65 ADDR = ((unsigned long *) addr) + (nr >> 5);
66 mask = 1 << (nr & 31);
67
68 (void) ___clear_bit(ADDR, mask);
69}
70
71static inline int test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
72{
73 unsigned long *ADDR, mask;
74
75 ADDR = ((unsigned long *) addr) + (nr >> 5);
76 mask = 1 << (nr & 31);
77
78 return ___change_bit(ADDR, mask) != 0;
79}
80
81static inline void change_bit(unsigned long nr, volatile unsigned long *addr)
82{
83 unsigned long *ADDR, mask;
84
85 ADDR = ((unsigned long *) addr) + (nr >> 5);
86 mask = 1 << (nr & 31);
87
88 (void) ___change_bit(ADDR, mask);
89}
90
91#include <asm-generic/bitops/non-atomic.h>
92
93#define smp_mb__before_clear_bit() do { } while(0)
94#define smp_mb__after_clear_bit() do { } while(0)
95
96#include <asm-generic/bitops/ffz.h>
97#include <asm-generic/bitops/__ffs.h>
98#include <asm-generic/bitops/sched.h>
99#include <asm-generic/bitops/ffs.h>
100#include <asm-generic/bitops/fls.h>
101#include <asm-generic/bitops/fls64.h>
102#include <asm-generic/bitops/hweight.h>
103#include <asm-generic/bitops/lock.h>
104#include <asm-generic/bitops/find.h>
105#include <asm-generic/bitops/ext2-non-atomic.h>
106#include <asm-generic/bitops/ext2-atomic.h>
107#include <asm-generic/bitops/minix.h>
108
109#endif /* __KERNEL__ */
110
111#endif /* defined(_SPARC_BITOPS_H) */
diff --git a/include/asm-sparc/bitops_64.h b/include/asm-sparc/bitops_64.h
new file mode 100644
index 000000000000..bb87b8080220
--- /dev/null
+++ b/include/asm-sparc/bitops_64.h
@@ -0,0 +1,107 @@
1/*
2 * bitops.h: Bit string operations on the V9.
3 *
4 * Copyright 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef _SPARC64_BITOPS_H
8#define _SPARC64_BITOPS_H
9
10#ifndef _LINUX_BITOPS_H
11#error only <linux/bitops.h> can be included directly
12#endif
13
14#include <linux/compiler.h>
15#include <asm/byteorder.h>
16
17extern int test_and_set_bit(unsigned long nr, volatile unsigned long *addr);
18extern int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr);
19extern int test_and_change_bit(unsigned long nr, volatile unsigned long *addr);
20extern void set_bit(unsigned long nr, volatile unsigned long *addr);
21extern void clear_bit(unsigned long nr, volatile unsigned long *addr);
22extern void change_bit(unsigned long nr, volatile unsigned long *addr);
23
24#include <asm-generic/bitops/non-atomic.h>
25
26#ifdef CONFIG_SMP
27#define smp_mb__before_clear_bit() membar_storeload_loadload()
28#define smp_mb__after_clear_bit() membar_storeload_storestore()
29#else
30#define smp_mb__before_clear_bit() barrier()
31#define smp_mb__after_clear_bit() barrier()
32#endif
33
34#include <asm-generic/bitops/ffz.h>
35#include <asm-generic/bitops/__ffs.h>
36#include <asm-generic/bitops/fls.h>
37#include <asm-generic/bitops/__fls.h>
38#include <asm-generic/bitops/fls64.h>
39
40#ifdef __KERNEL__
41
42#include <asm-generic/bitops/sched.h>
43#include <asm-generic/bitops/ffs.h>
44
45/*
46 * hweightN: returns the hamming weight (i.e. the number
47 * of bits set) of a N-bit word
48 */
49
50#ifdef ULTRA_HAS_POPULATION_COUNT
51
52static inline unsigned int hweight64(unsigned long w)
53{
54 unsigned int res;
55
56 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w));
57 return res;
58}
59
60static inline unsigned int hweight32(unsigned int w)
61{
62 unsigned int res;
63
64 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffffffff));
65 return res;
66}
67
68static inline unsigned int hweight16(unsigned int w)
69{
70 unsigned int res;
71
72 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffff));
73 return res;
74}
75
76static inline unsigned int hweight8(unsigned int w)
77{
78 unsigned int res;
79
80 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xff));
81 return res;
82}
83
84#else
85
86#include <asm-generic/bitops/hweight.h>
87
88#endif
89#include <asm-generic/bitops/lock.h>
90#endif /* __KERNEL__ */
91
92#include <asm-generic/bitops/find.h>
93
94#ifdef __KERNEL__
95
96#include <asm-generic/bitops/ext2-non-atomic.h>
97
98#define ext2_set_bit_atomic(lock,nr,addr) \
99 test_and_set_bit((nr) ^ 0x38,(unsigned long *)(addr))
100#define ext2_clear_bit_atomic(lock,nr,addr) \
101 test_and_clear_bit((nr) ^ 0x38,(unsigned long *)(addr))
102
103#include <asm-generic/bitops/minix.h>
104
105#endif /* __KERNEL__ */
106
107#endif /* defined(_SPARC64_BITOPS_H) */
diff --git a/include/asm-sparc/cacheflush.h b/include/asm-sparc/cacheflush.h
index 68ac10910271..2b6a37957c2d 100644
--- a/include/asm-sparc/cacheflush.h
+++ b/include/asm-sparc/cacheflush.h
@@ -1,85 +1,8 @@
1#ifndef _SPARC_CACHEFLUSH_H 1#ifndef ___ASM_SPARC_CACHEFLUSH_H
2#define _SPARC_CACHEFLUSH_H 2#define ___ASM_SPARC_CACHEFLUSH_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <linux/mm.h> /* Common for other includes */ 4#include <asm-sparc/cacheflush_64.h>
5// #include <linux/kernel.h> from pgalloc.h 5#else
6// #include <linux/sched.h> from pgalloc.h 6#include <asm-sparc/cacheflush_32.h>
7 7#endif
8// #include <asm/page.h> 8#endif
9#include <asm/btfixup.h>
10
11/*
12 * Fine grained cache flushing.
13 */
14#ifdef CONFIG_SMP
15
16BTFIXUPDEF_CALL(void, local_flush_cache_all, void)
17BTFIXUPDEF_CALL(void, local_flush_cache_mm, struct mm_struct *)
18BTFIXUPDEF_CALL(void, local_flush_cache_range, struct vm_area_struct *, unsigned long, unsigned long)
19BTFIXUPDEF_CALL(void, local_flush_cache_page, struct vm_area_struct *, unsigned long)
20
21#define local_flush_cache_all() BTFIXUP_CALL(local_flush_cache_all)()
22#define local_flush_cache_mm(mm) BTFIXUP_CALL(local_flush_cache_mm)(mm)
23#define local_flush_cache_range(vma,start,end) BTFIXUP_CALL(local_flush_cache_range)(vma,start,end)
24#define local_flush_cache_page(vma,addr) BTFIXUP_CALL(local_flush_cache_page)(vma,addr)
25
26BTFIXUPDEF_CALL(void, local_flush_page_to_ram, unsigned long)
27BTFIXUPDEF_CALL(void, local_flush_sig_insns, struct mm_struct *, unsigned long)
28
29#define local_flush_page_to_ram(addr) BTFIXUP_CALL(local_flush_page_to_ram)(addr)
30#define local_flush_sig_insns(mm,insn_addr) BTFIXUP_CALL(local_flush_sig_insns)(mm,insn_addr)
31
32extern void smp_flush_cache_all(void);
33extern void smp_flush_cache_mm(struct mm_struct *mm);
34extern void smp_flush_cache_range(struct vm_area_struct *vma,
35 unsigned long start,
36 unsigned long end);
37extern void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
38
39extern void smp_flush_page_to_ram(unsigned long page);
40extern void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
41
42#endif /* CONFIG_SMP */
43
44BTFIXUPDEF_CALL(void, flush_cache_all, void)
45BTFIXUPDEF_CALL(void, flush_cache_mm, struct mm_struct *)
46BTFIXUPDEF_CALL(void, flush_cache_range, struct vm_area_struct *, unsigned long, unsigned long)
47BTFIXUPDEF_CALL(void, flush_cache_page, struct vm_area_struct *, unsigned long)
48
49#define flush_cache_all() BTFIXUP_CALL(flush_cache_all)()
50#define flush_cache_mm(mm) BTFIXUP_CALL(flush_cache_mm)(mm)
51#define flush_cache_dup_mm(mm) BTFIXUP_CALL(flush_cache_mm)(mm)
52#define flush_cache_range(vma,start,end) BTFIXUP_CALL(flush_cache_range)(vma,start,end)
53#define flush_cache_page(vma,addr,pfn) BTFIXUP_CALL(flush_cache_page)(vma,addr)
54#define flush_icache_range(start, end) do { } while (0)
55#define flush_icache_page(vma, pg) do { } while (0)
56
57#define flush_icache_user_range(vma,pg,adr,len) do { } while (0)
58
59#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
60 do { \
61 flush_cache_page(vma, vaddr, page_to_pfn(page));\
62 memcpy(dst, src, len); \
63 } while (0)
64#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
65 do { \
66 flush_cache_page(vma, vaddr, page_to_pfn(page));\
67 memcpy(dst, src, len); \
68 } while (0)
69
70BTFIXUPDEF_CALL(void, __flush_page_to_ram, unsigned long)
71BTFIXUPDEF_CALL(void, flush_sig_insns, struct mm_struct *, unsigned long)
72
73#define __flush_page_to_ram(addr) BTFIXUP_CALL(__flush_page_to_ram)(addr)
74#define flush_sig_insns(mm,insn_addr) BTFIXUP_CALL(flush_sig_insns)(mm,insn_addr)
75
76extern void sparc_flush_page_to_ram(struct page *page);
77
78#define flush_dcache_page(page) sparc_flush_page_to_ram(page)
79#define flush_dcache_mmap_lock(mapping) do { } while (0)
80#define flush_dcache_mmap_unlock(mapping) do { } while (0)
81
82#define flush_cache_vmap(start, end) flush_cache_all()
83#define flush_cache_vunmap(start, end) flush_cache_all()
84
85#endif /* _SPARC_CACHEFLUSH_H */
diff --git a/include/asm-sparc/cacheflush_32.h b/include/asm-sparc/cacheflush_32.h
new file mode 100644
index 000000000000..68ac10910271
--- /dev/null
+++ b/include/asm-sparc/cacheflush_32.h
@@ -0,0 +1,85 @@
1#ifndef _SPARC_CACHEFLUSH_H
2#define _SPARC_CACHEFLUSH_H
3
4#include <linux/mm.h> /* Common for other includes */
5// #include <linux/kernel.h> from pgalloc.h
6// #include <linux/sched.h> from pgalloc.h
7
8// #include <asm/page.h>
9#include <asm/btfixup.h>
10
11/*
12 * Fine grained cache flushing.
13 */
14#ifdef CONFIG_SMP
15
16BTFIXUPDEF_CALL(void, local_flush_cache_all, void)
17BTFIXUPDEF_CALL(void, local_flush_cache_mm, struct mm_struct *)
18BTFIXUPDEF_CALL(void, local_flush_cache_range, struct vm_area_struct *, unsigned long, unsigned long)
19BTFIXUPDEF_CALL(void, local_flush_cache_page, struct vm_area_struct *, unsigned long)
20
21#define local_flush_cache_all() BTFIXUP_CALL(local_flush_cache_all)()
22#define local_flush_cache_mm(mm) BTFIXUP_CALL(local_flush_cache_mm)(mm)
23#define local_flush_cache_range(vma,start,end) BTFIXUP_CALL(local_flush_cache_range)(vma,start,end)
24#define local_flush_cache_page(vma,addr) BTFIXUP_CALL(local_flush_cache_page)(vma,addr)
25
26BTFIXUPDEF_CALL(void, local_flush_page_to_ram, unsigned long)
27BTFIXUPDEF_CALL(void, local_flush_sig_insns, struct mm_struct *, unsigned long)
28
29#define local_flush_page_to_ram(addr) BTFIXUP_CALL(local_flush_page_to_ram)(addr)
30#define local_flush_sig_insns(mm,insn_addr) BTFIXUP_CALL(local_flush_sig_insns)(mm,insn_addr)
31
32extern void smp_flush_cache_all(void);
33extern void smp_flush_cache_mm(struct mm_struct *mm);
34extern void smp_flush_cache_range(struct vm_area_struct *vma,
35 unsigned long start,
36 unsigned long end);
37extern void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
38
39extern void smp_flush_page_to_ram(unsigned long page);
40extern void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
41
42#endif /* CONFIG_SMP */
43
44BTFIXUPDEF_CALL(void, flush_cache_all, void)
45BTFIXUPDEF_CALL(void, flush_cache_mm, struct mm_struct *)
46BTFIXUPDEF_CALL(void, flush_cache_range, struct vm_area_struct *, unsigned long, unsigned long)
47BTFIXUPDEF_CALL(void, flush_cache_page, struct vm_area_struct *, unsigned long)
48
49#define flush_cache_all() BTFIXUP_CALL(flush_cache_all)()
50#define flush_cache_mm(mm) BTFIXUP_CALL(flush_cache_mm)(mm)
51#define flush_cache_dup_mm(mm) BTFIXUP_CALL(flush_cache_mm)(mm)
52#define flush_cache_range(vma,start,end) BTFIXUP_CALL(flush_cache_range)(vma,start,end)
53#define flush_cache_page(vma,addr,pfn) BTFIXUP_CALL(flush_cache_page)(vma,addr)
54#define flush_icache_range(start, end) do { } while (0)
55#define flush_icache_page(vma, pg) do { } while (0)
56
57#define flush_icache_user_range(vma,pg,adr,len) do { } while (0)
58
59#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
60 do { \
61 flush_cache_page(vma, vaddr, page_to_pfn(page));\
62 memcpy(dst, src, len); \
63 } while (0)
64#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
65 do { \
66 flush_cache_page(vma, vaddr, page_to_pfn(page));\
67 memcpy(dst, src, len); \
68 } while (0)
69
70BTFIXUPDEF_CALL(void, __flush_page_to_ram, unsigned long)
71BTFIXUPDEF_CALL(void, flush_sig_insns, struct mm_struct *, unsigned long)
72
73#define __flush_page_to_ram(addr) BTFIXUP_CALL(__flush_page_to_ram)(addr)
74#define flush_sig_insns(mm,insn_addr) BTFIXUP_CALL(flush_sig_insns)(mm,insn_addr)
75
76extern void sparc_flush_page_to_ram(struct page *page);
77
78#define flush_dcache_page(page) sparc_flush_page_to_ram(page)
79#define flush_dcache_mmap_lock(mapping) do { } while (0)
80#define flush_dcache_mmap_unlock(mapping) do { } while (0)
81
82#define flush_cache_vmap(start, end) flush_cache_all()
83#define flush_cache_vunmap(start, end) flush_cache_all()
84
85#endif /* _SPARC_CACHEFLUSH_H */
diff --git a/include/asm-sparc/cacheflush_64.h b/include/asm-sparc/cacheflush_64.h
new file mode 100644
index 000000000000..c43321729b3b
--- /dev/null
+++ b/include/asm-sparc/cacheflush_64.h
@@ -0,0 +1,76 @@
1#ifndef _SPARC64_CACHEFLUSH_H
2#define _SPARC64_CACHEFLUSH_H
3
4#include <asm/page.h>
5
6#ifndef __ASSEMBLY__
7
8#include <linux/mm.h>
9
10/* Cache flush operations. */
11
12/* These are the same regardless of whether this is an SMP kernel or not. */
13#define flush_cache_mm(__mm) \
14 do { if ((__mm) == current->mm) flushw_user(); } while(0)
15#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
16#define flush_cache_range(vma, start, end) \
17 flush_cache_mm((vma)->vm_mm)
18#define flush_cache_page(vma, page, pfn) \
19 flush_cache_mm((vma)->vm_mm)
20
21/*
22 * On spitfire, the icache doesn't snoop local stores and we don't
23 * use block commit stores (which invalidate icache lines) during
24 * module load, so we need this.
25 */
26extern void flush_icache_range(unsigned long start, unsigned long end);
27extern void __flush_icache_page(unsigned long);
28
29extern void __flush_dcache_page(void *addr, int flush_icache);
30extern void flush_dcache_page_impl(struct page *page);
31#ifdef CONFIG_SMP
32extern void smp_flush_dcache_page_impl(struct page *page, int cpu);
33extern void flush_dcache_page_all(struct mm_struct *mm, struct page *page);
34#else
35#define smp_flush_dcache_page_impl(page,cpu) flush_dcache_page_impl(page)
36#define flush_dcache_page_all(mm,page) flush_dcache_page_impl(page)
37#endif
38
39extern void __flush_dcache_range(unsigned long start, unsigned long end);
40extern void flush_dcache_page(struct page *page);
41
42#define flush_icache_page(vma, pg) do { } while(0)
43#define flush_icache_user_range(vma,pg,adr,len) do { } while (0)
44
45extern void flush_ptrace_access(struct vm_area_struct *, struct page *,
46 unsigned long uaddr, void *kaddr,
47 unsigned long len, int write);
48
49#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
50 do { \
51 flush_cache_page(vma, vaddr, page_to_pfn(page)); \
52 memcpy(dst, src, len); \
53 flush_ptrace_access(vma, page, vaddr, src, len, 0); \
54 } while (0)
55
56#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
57 do { \
58 flush_cache_page(vma, vaddr, page_to_pfn(page)); \
59 memcpy(dst, src, len); \
60 flush_ptrace_access(vma, page, vaddr, dst, len, 1); \
61 } while (0)
62
63#define flush_dcache_mmap_lock(mapping) do { } while (0)
64#define flush_dcache_mmap_unlock(mapping) do { } while (0)
65
66#define flush_cache_vmap(start, end) do { } while (0)
67#define flush_cache_vunmap(start, end) do { } while (0)
68
69#ifdef CONFIG_DEBUG_PAGEALLOC
70/* internal debugging function */
71void kernel_map_pages(struct page *page, int numpages, int enable);
72#endif
73
74#endif /* !__ASSEMBLY__ */
75
76#endif /* _SPARC64_CACHEFLUSH_H */
diff --git a/include/asm-sparc/chafsr.h b/include/asm-sparc/chafsr.h
new file mode 100644
index 000000000000..85c69b38220b
--- /dev/null
+++ b/include/asm-sparc/chafsr.h
@@ -0,0 +1,241 @@
1#ifndef _SPARC64_CHAFSR_H
2#define _SPARC64_CHAFSR_H
3
4/* Cheetah Asynchronous Fault Status register, ASI=0x4C VA<63:0>=0x0 */
5
6/* Comments indicate which processor variants on which the bit definition
7 * is valid. Codes are:
8 * ch --> cheetah
9 * ch+ --> cheetah plus
10 * jp --> jalapeno
11 */
12
13/* All bits of this register except M_SYNDROME and E_SYNDROME are
14 * read, write 1 to clear. M_SYNDROME and E_SYNDROME are read-only.
15 */
16
17/* Software bit set by linux trap handlers to indicate that the trap was
18 * signalled at %tl >= 1.
19 */
20#define CHAFSR_TL1 (1UL << 63UL) /* n/a */
21
22/* Unmapped error from system bus for prefetch queue or
23 * store queue read operation
24 */
25#define CHPAFSR_DTO (1UL << 59UL) /* ch+ */
26
27/* Bus error from system bus for prefetch queue or store queue
28 * read operation
29 */
30#define CHPAFSR_DBERR (1UL << 58UL) /* ch+ */
31
32/* Hardware corrected E-cache Tag ECC error */
33#define CHPAFSR_THCE (1UL << 57UL) /* ch+ */
34/* System interface protocol error, hw timeout caused */
35#define JPAFSR_JETO (1UL << 57UL) /* jp */
36
37/* SW handled correctable E-cache Tag ECC error */
38#define CHPAFSR_TSCE (1UL << 56UL) /* ch+ */
39/* Parity error on system snoop results */
40#define JPAFSR_SCE (1UL << 56UL) /* jp */
41
42/* Uncorrectable E-cache Tag ECC error */
43#define CHPAFSR_TUE (1UL << 55UL) /* ch+ */
44/* System interface protocol error, illegal command detected */
45#define JPAFSR_JEIC (1UL << 55UL) /* jp */
46
47/* Uncorrectable system bus data ECC error due to prefetch
48 * or store fill request
49 */
50#define CHPAFSR_DUE (1UL << 54UL) /* ch+ */
51/* System interface protocol error, illegal ADTYPE detected */
52#define JPAFSR_JEIT (1UL << 54UL) /* jp */
53
54/* Multiple errors of the same type have occurred. This bit is set when
55 * an uncorrectable error or a SW correctable error occurs and the status
56 * bit to report that error is already set. When multiple errors of
57 * different types are indicated by setting multiple status bits.
58 *
59 * This bit is not set if multiple HW corrected errors with the same
60 * status bit occur, only uncorrectable and SW correctable ones have
61 * this behavior.
62 *
63 * This bit is not set when multiple ECC errors happen within a single
64 * 64-byte system bus transaction. Only the first ECC error in a 16-byte
65 * subunit will be logged. All errors in subsequent 16-byte subunits
66 * from the same 64-byte transaction are ignored.
67 */
68#define CHAFSR_ME (1UL << 53UL) /* ch,ch+,jp */
69
70/* Privileged state error has occurred. This is a capture of PSTATE.PRIV
71 * at the time the error is detected.
72 */
73#define CHAFSR_PRIV (1UL << 52UL) /* ch,ch+,jp */
74
75/* The following bits 51 (CHAFSR_PERR) to 33 (CHAFSR_CE) are sticky error
76 * bits and record the most recently detected errors. Bits accumulate
77 * errors that have been detected since the last write to clear the bit.
78 */
79
80/* System interface protocol error. The processor asserts its' ERROR
81 * pin when this event occurs and it also logs a specific cause code
82 * into a JTAG scannable flop.
83 */
84#define CHAFSR_PERR (1UL << 51UL) /* ch,ch+,jp */
85
86/* Internal processor error. The processor asserts its' ERROR
87 * pin when this event occurs and it also logs a specific cause code
88 * into a JTAG scannable flop.
89 */
90#define CHAFSR_IERR (1UL << 50UL) /* ch,ch+,jp */
91
92/* System request parity error on incoming address */
93#define CHAFSR_ISAP (1UL << 49UL) /* ch,ch+,jp */
94
95/* HW Corrected system bus MTAG ECC error */
96#define CHAFSR_EMC (1UL << 48UL) /* ch,ch+ */
97/* Parity error on L2 cache tag SRAM */
98#define JPAFSR_ETP (1UL << 48UL) /* jp */
99
100/* Uncorrectable system bus MTAG ECC error */
101#define CHAFSR_EMU (1UL << 47UL) /* ch,ch+ */
102/* Out of range memory error has occurred */
103#define JPAFSR_OM (1UL << 47UL) /* jp */
104
105/* HW Corrected system bus data ECC error for read of interrupt vector */
106#define CHAFSR_IVC (1UL << 46UL) /* ch,ch+ */
107/* Error due to unsupported store */
108#define JPAFSR_UMS (1UL << 46UL) /* jp */
109
110/* Uncorrectable system bus data ECC error for read of interrupt vector */
111#define CHAFSR_IVU (1UL << 45UL) /* ch,ch+,jp */
112
113/* Unmapped error from system bus */
114#define CHAFSR_TO (1UL << 44UL) /* ch,ch+,jp */
115
116/* Bus error response from system bus */
117#define CHAFSR_BERR (1UL << 43UL) /* ch,ch+,jp */
118
119/* SW Correctable E-cache ECC error for instruction fetch or data access
120 * other than block load.
121 */
122#define CHAFSR_UCC (1UL << 42UL) /* ch,ch+,jp */
123
124/* Uncorrectable E-cache ECC error for instruction fetch or data access
125 * other than block load.
126 */
127#define CHAFSR_UCU (1UL << 41UL) /* ch,ch+,jp */
128
129/* Copyout HW Corrected ECC error */
130#define CHAFSR_CPC (1UL << 40UL) /* ch,ch+,jp */
131
132/* Copyout Uncorrectable ECC error */
133#define CHAFSR_CPU (1UL << 39UL) /* ch,ch+,jp */
134
135/* HW Corrected ECC error from E-cache for writeback */
136#define CHAFSR_WDC (1UL << 38UL) /* ch,ch+,jp */
137
138/* Uncorrectable ECC error from E-cache for writeback */
139#define CHAFSR_WDU (1UL << 37UL) /* ch,ch+,jp */
140
141/* HW Corrected ECC error from E-cache for store merge or block load */
142#define CHAFSR_EDC (1UL << 36UL) /* ch,ch+,jp */
143
144/* Uncorrectable ECC error from E-cache for store merge or block load */
145#define CHAFSR_EDU (1UL << 35UL) /* ch,ch+,jp */
146
147/* Uncorrectable system bus data ECC error for read of memory or I/O */
148#define CHAFSR_UE (1UL << 34UL) /* ch,ch+,jp */
149
150/* HW Corrected system bus data ECC error for read of memory or I/O */
151#define CHAFSR_CE (1UL << 33UL) /* ch,ch+,jp */
152
153/* Uncorrectable ECC error from remote cache/memory */
154#define JPAFSR_RUE (1UL << 32UL) /* jp */
155
156/* Correctable ECC error from remote cache/memory */
157#define JPAFSR_RCE (1UL << 31UL) /* jp */
158
159/* JBUS parity error on returned read data */
160#define JPAFSR_BP (1UL << 30UL) /* jp */
161
162/* JBUS parity error on data for writeback or block store */
163#define JPAFSR_WBP (1UL << 29UL) /* jp */
164
165/* Foreign read to DRAM incurring correctable ECC error */
166#define JPAFSR_FRC (1UL << 28UL) /* jp */
167
168/* Foreign read to DRAM incurring uncorrectable ECC error */
169#define JPAFSR_FRU (1UL << 27UL) /* jp */
170
171#define CHAFSR_ERRORS (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP | CHAFSR_EMC | \
172 CHAFSR_EMU | CHAFSR_IVC | CHAFSR_IVU | CHAFSR_TO | \
173 CHAFSR_BERR | CHAFSR_UCC | CHAFSR_UCU | CHAFSR_CPC | \
174 CHAFSR_CPU | CHAFSR_WDC | CHAFSR_WDU | CHAFSR_EDC | \
175 CHAFSR_EDU | CHAFSR_UE | CHAFSR_CE)
176#define CHPAFSR_ERRORS (CHPAFSR_DTO | CHPAFSR_DBERR | CHPAFSR_THCE | \
177 CHPAFSR_TSCE | CHPAFSR_TUE | CHPAFSR_DUE | \
178 CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP | CHAFSR_EMC | \
179 CHAFSR_EMU | CHAFSR_IVC | CHAFSR_IVU | CHAFSR_TO | \
180 CHAFSR_BERR | CHAFSR_UCC | CHAFSR_UCU | CHAFSR_CPC | \
181 CHAFSR_CPU | CHAFSR_WDC | CHAFSR_WDU | CHAFSR_EDC | \
182 CHAFSR_EDU | CHAFSR_UE | CHAFSR_CE)
183#define JPAFSR_ERRORS (JPAFSR_JETO | JPAFSR_SCE | JPAFSR_JEIC | \
184 JPAFSR_JEIT | CHAFSR_PERR | CHAFSR_IERR | \
185 CHAFSR_ISAP | JPAFSR_ETP | JPAFSR_OM | \
186 JPAFSR_UMS | CHAFSR_IVU | CHAFSR_TO | \
187 CHAFSR_BERR | CHAFSR_UCC | CHAFSR_UCU | \
188 CHAFSR_CPC | CHAFSR_CPU | CHAFSR_WDC | \
189 CHAFSR_WDU | CHAFSR_EDC | CHAFSR_EDU | \
190 CHAFSR_UE | CHAFSR_CE | JPAFSR_RUE | \
191 JPAFSR_RCE | JPAFSR_BP | JPAFSR_WBP | \
192 JPAFSR_FRC | JPAFSR_FRU)
193
194/* Active JBUS request signal when error occurred */
195#define JPAFSR_JBREQ (0x7UL << 24UL) /* jp */
196#define JPAFSR_JBREQ_SHIFT 24UL
197
198/* L2 cache way information */
199#define JPAFSR_ETW (0x3UL << 22UL) /* jp */
200#define JPAFSR_ETW_SHIFT 22UL
201
202/* System bus MTAG ECC syndrome. This field captures the status of the
203 * first occurrence of the highest-priority error according to the M_SYND
204 * overwrite policy. After the AFSR sticky bit, corresponding to the error
205 * for which the M_SYND is reported, is cleared, the contents of the M_SYND
206 * field will be unchanged by will be unfrozen for further error capture.
207 */
208#define CHAFSR_M_SYNDROME (0xfUL << 16UL) /* ch,ch+,jp */
209#define CHAFSR_M_SYNDROME_SHIFT 16UL
210
211/* Agenid Id of the foreign device causing the UE/CE errors */
212#define JPAFSR_AID (0x1fUL << 9UL) /* jp */
213#define JPAFSR_AID_SHIFT 9UL
214
215/* System bus or E-cache data ECC syndrome. This field captures the status
216 * of the first occurrence of the highest-priority error according to the
217 * E_SYND overwrite policy. After the AFSR sticky bit, corresponding to the
218 * error for which the E_SYND is reported, is cleare, the contents of the E_SYND
219 * field will be unchanged but will be unfrozen for further error capture.
220 */
221#define CHAFSR_E_SYNDROME (0x1ffUL << 0UL) /* ch,ch+,jp */
222#define CHAFSR_E_SYNDROME_SHIFT 0UL
223
224/* The AFSR must be explicitly cleared by software, it is not cleared automatically
225 * by a read. Writes to bits <51:33> with bits set will clear the corresponding
226 * bits in the AFSR. Bits associated with disrupting traps must be cleared before
227 * interrupts are re-enabled to prevent multiple traps for the same error. I.e.
228 * PSTATE.IE and AFSR bits control delivery of disrupting traps.
229 *
230 * Since there is only one AFAR, when multiple events have been logged by the
231 * bits in the AFSR, at most one of these events will have its status captured
232 * in the AFAR. The highest priority of those event bits will get AFAR logging.
233 * The AFAR will be unlocked and available to capture the address of another event
234 * as soon as the one bit in AFSR that corresponds to the event logged in AFAR is
235 * cleared. For example, if AFSR.CE is detected, then AFSR.UE (which overwrites
236 * the AFAR), and AFSR.UE is cleared by not AFSR.CE, then the AFAR will be unlocked
237 * and ready for another event, even though AFSR.CE is still set. The same rules
238 * also apply to the M_SYNDROME and E_SYNDROME fields of the AFSR.
239 */
240
241#endif /* _SPARC64_CHAFSR_H */
diff --git a/include/asm-sparc/checksum.h b/include/asm-sparc/checksum.h
index d044ddb5a3cf..4e3553d4f6e1 100644
--- a/include/asm-sparc/checksum.h
+++ b/include/asm-sparc/checksum.h
@@ -1,241 +1,8 @@
1#ifndef __SPARC_CHECKSUM_H 1#ifndef ___ASM_SPARC_CHECKSUM_H
2#define __SPARC_CHECKSUM_H 2#define ___ASM_SPARC_CHECKSUM_H
3 3#if defined(__sparc__) && defined(__arch64__)
4/* checksum.h: IP/UDP/TCP checksum routines on the Sparc. 4#include <asm-sparc/checksum_64.h>
5 * 5#else
6 * Copyright(C) 1995 Linus Torvalds 6#include <asm-sparc/checksum_32.h>
7 * Copyright(C) 1995 Miguel de Icaza 7#endif
8 * Copyright(C) 1996 David S. Miller 8#endif
9 * Copyright(C) 1996 Eddie C. Dost
10 * Copyright(C) 1997 Jakub Jelinek
11 *
12 * derived from:
13 * Alpha checksum c-code
14 * ix86 inline assembly
15 * RFC1071 Computing the Internet Checksum
16 */
17
18#include <linux/in6.h>
19#include <asm/uaccess.h>
20
21/* computes the checksum of a memory block at buff, length len,
22 * and adds in "sum" (32-bit)
23 *
24 * returns a 32-bit number suitable for feeding into itself
25 * or csum_tcpudp_magic
26 *
27 * this function must be called with even lengths, except
28 * for the last fragment, which may be odd
29 *
30 * it's best to have buff aligned on a 32-bit boundary
31 */
32extern __wsum csum_partial(const void *buff, int len, __wsum sum);
33
34/* the same as csum_partial, but copies from fs:src while it
35 * checksums
36 *
37 * here even more important to align src and dst on a 32-bit (or even
38 * better 64-bit) boundary
39 */
40
41extern unsigned int __csum_partial_copy_sparc_generic (const unsigned char *, unsigned char *);
42
43static inline __wsum
44csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
45{
46 register unsigned int ret asm("o0") = (unsigned int)src;
47 register char *d asm("o1") = dst;
48 register int l asm("g1") = len;
49
50 __asm__ __volatile__ (
51 "call __csum_partial_copy_sparc_generic\n\t"
52 " mov %6, %%g7\n"
53 : "=&r" (ret), "=&r" (d), "=&r" (l)
54 : "0" (ret), "1" (d), "2" (l), "r" (sum)
55 : "o2", "o3", "o4", "o5", "o7",
56 "g2", "g3", "g4", "g5", "g7",
57 "memory", "cc");
58 return (__force __wsum)ret;
59}
60
61static inline __wsum
62csum_partial_copy_from_user(const void __user *src, void *dst, int len,
63 __wsum sum, int *err)
64 {
65 register unsigned long ret asm("o0") = (unsigned long)src;
66 register char *d asm("o1") = dst;
67 register int l asm("g1") = len;
68 register __wsum s asm("g7") = sum;
69
70 __asm__ __volatile__ (
71 ".section __ex_table,#alloc\n\t"
72 ".align 4\n\t"
73 ".word 1f,2\n\t"
74 ".previous\n"
75 "1:\n\t"
76 "call __csum_partial_copy_sparc_generic\n\t"
77 " st %8, [%%sp + 64]\n"
78 : "=&r" (ret), "=&r" (d), "=&r" (l), "=&r" (s)
79 : "0" (ret), "1" (d), "2" (l), "3" (s), "r" (err)
80 : "o2", "o3", "o4", "o5", "o7", "g2", "g3", "g4", "g5",
81 "cc", "memory");
82 return (__force __wsum)ret;
83}
84
85static inline __wsum
86csum_partial_copy_to_user(const void *src, void __user *dst, int len,
87 __wsum sum, int *err)
88{
89 if (!access_ok (VERIFY_WRITE, dst, len)) {
90 *err = -EFAULT;
91 return sum;
92 } else {
93 register unsigned long ret asm("o0") = (unsigned long)src;
94 register char __user *d asm("o1") = dst;
95 register int l asm("g1") = len;
96 register __wsum s asm("g7") = sum;
97
98 __asm__ __volatile__ (
99 ".section __ex_table,#alloc\n\t"
100 ".align 4\n\t"
101 ".word 1f,1\n\t"
102 ".previous\n"
103 "1:\n\t"
104 "call __csum_partial_copy_sparc_generic\n\t"
105 " st %8, [%%sp + 64]\n"
106 : "=&r" (ret), "=&r" (d), "=&r" (l), "=&r" (s)
107 : "0" (ret), "1" (d), "2" (l), "3" (s), "r" (err)
108 : "o2", "o3", "o4", "o5", "o7",
109 "g2", "g3", "g4", "g5",
110 "cc", "memory");
111 return (__force __wsum)ret;
112 }
113}
114
115#define HAVE_CSUM_COPY_USER
116#define csum_and_copy_to_user csum_partial_copy_to_user
117
118/* ihl is always 5 or greater, almost always is 5, and iph is word aligned
119 * the majority of the time.
120 */
121static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
122{
123 __sum16 sum;
124
125 /* Note: We must read %2 before we touch %0 for the first time,
126 * because GCC can legitimately use the same register for
127 * both operands.
128 */
129 __asm__ __volatile__("sub\t%2, 4, %%g4\n\t"
130 "ld\t[%1 + 0x00], %0\n\t"
131 "ld\t[%1 + 0x04], %%g2\n\t"
132 "ld\t[%1 + 0x08], %%g3\n\t"
133 "addcc\t%%g2, %0, %0\n\t"
134 "addxcc\t%%g3, %0, %0\n\t"
135 "ld\t[%1 + 0x0c], %%g2\n\t"
136 "ld\t[%1 + 0x10], %%g3\n\t"
137 "addxcc\t%%g2, %0, %0\n\t"
138 "addx\t%0, %%g0, %0\n"
139 "1:\taddcc\t%%g3, %0, %0\n\t"
140 "add\t%1, 4, %1\n\t"
141 "addxcc\t%0, %%g0, %0\n\t"
142 "subcc\t%%g4, 1, %%g4\n\t"
143 "be,a\t2f\n\t"
144 "sll\t%0, 16, %%g2\n\t"
145 "b\t1b\n\t"
146 "ld\t[%1 + 0x10], %%g3\n"
147 "2:\taddcc\t%0, %%g2, %%g2\n\t"
148 "srl\t%%g2, 16, %0\n\t"
149 "addx\t%0, %%g0, %0\n\t"
150 "xnor\t%%g0, %0, %0"
151 : "=r" (sum), "=&r" (iph)
152 : "r" (ihl), "1" (iph)
153 : "g2", "g3", "g4", "cc", "memory");
154 return sum;
155}
156
157/* Fold a partial checksum without adding pseudo headers. */
158static inline __sum16 csum_fold(__wsum sum)
159{
160 unsigned int tmp;
161
162 __asm__ __volatile__("addcc\t%0, %1, %1\n\t"
163 "srl\t%1, 16, %1\n\t"
164 "addx\t%1, %%g0, %1\n\t"
165 "xnor\t%%g0, %1, %0"
166 : "=&r" (sum), "=r" (tmp)
167 : "0" (sum), "1" ((__force u32)sum<<16)
168 : "cc");
169 return (__force __sum16)sum;
170}
171
172static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
173 unsigned short len,
174 unsigned short proto,
175 __wsum sum)
176{
177 __asm__ __volatile__("addcc\t%1, %0, %0\n\t"
178 "addxcc\t%2, %0, %0\n\t"
179 "addxcc\t%3, %0, %0\n\t"
180 "addx\t%0, %%g0, %0\n\t"
181 : "=r" (sum), "=r" (saddr)
182 : "r" (daddr), "r" (proto + len), "0" (sum),
183 "1" (saddr)
184 : "cc");
185 return sum;
186}
187
188/*
189 * computes the checksum of the TCP/UDP pseudo-header
190 * returns a 16-bit checksum, already complemented
191 */
192static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
193 unsigned short len,
194 unsigned short proto,
195 __wsum sum)
196{
197 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
198}
199
200#define _HAVE_ARCH_IPV6_CSUM
201
202static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
203 const struct in6_addr *daddr,
204 __u32 len, unsigned short proto,
205 __wsum sum)
206{
207 __asm__ __volatile__ (
208 "addcc %3, %4, %%g4\n\t"
209 "addxcc %5, %%g4, %%g4\n\t"
210 "ld [%2 + 0x0c], %%g2\n\t"
211 "ld [%2 + 0x08], %%g3\n\t"
212 "addxcc %%g2, %%g4, %%g4\n\t"
213 "ld [%2 + 0x04], %%g2\n\t"
214 "addxcc %%g3, %%g4, %%g4\n\t"
215 "ld [%2 + 0x00], %%g3\n\t"
216 "addxcc %%g2, %%g4, %%g4\n\t"
217 "ld [%1 + 0x0c], %%g2\n\t"
218 "addxcc %%g3, %%g4, %%g4\n\t"
219 "ld [%1 + 0x08], %%g3\n\t"
220 "addxcc %%g2, %%g4, %%g4\n\t"
221 "ld [%1 + 0x04], %%g2\n\t"
222 "addxcc %%g3, %%g4, %%g4\n\t"
223 "ld [%1 + 0x00], %%g3\n\t"
224 "addxcc %%g2, %%g4, %%g4\n\t"
225 "addxcc %%g3, %%g4, %0\n\t"
226 "addx 0, %0, %0\n"
227 : "=&r" (sum)
228 : "r" (saddr), "r" (daddr),
229 "r"(htonl(len)), "r"(htonl(proto)), "r"(sum)
230 : "g2", "g3", "g4", "cc");
231
232 return csum_fold(sum);
233}
234
235/* this routine is used for miscellaneous IP-like checksums, mainly in icmp.c */
236static inline __sum16 ip_compute_csum(const void *buff, int len)
237{
238 return csum_fold(csum_partial(buff, len, 0));
239}
240
241#endif /* !(__SPARC_CHECKSUM_H) */
diff --git a/include/asm-sparc/checksum_32.h b/include/asm-sparc/checksum_32.h
new file mode 100644
index 000000000000..bdbda1453aa9
--- /dev/null
+++ b/include/asm-sparc/checksum_32.h
@@ -0,0 +1,241 @@
1#ifndef __SPARC_CHECKSUM_H
2#define __SPARC_CHECKSUM_H
3
4/* checksum.h: IP/UDP/TCP checksum routines on the Sparc.
5 *
6 * Copyright(C) 1995 Linus Torvalds
7 * Copyright(C) 1995 Miguel de Icaza
8 * Copyright(C) 1996 David S. Miller
9 * Copyright(C) 1996 Eddie C. Dost
10 * Copyright(C) 1997 Jakub Jelinek
11 *
12 * derived from:
13 * Alpha checksum c-code
14 * ix86 inline assembly
15 * RFC1071 Computing the Internet Checksum
16 */
17
18#include <linux/in6.h>
19#include <asm/uaccess.h>
20
21/* computes the checksum of a memory block at buff, length len,
22 * and adds in "sum" (32-bit)
23 *
24 * returns a 32-bit number suitable for feeding into itself
25 * or csum_tcpudp_magic
26 *
27 * this function must be called with even lengths, except
28 * for the last fragment, which may be odd
29 *
30 * it's best to have buff aligned on a 32-bit boundary
31 */
32extern __wsum csum_partial(const void *buff, int len, __wsum sum);
33
34/* the same as csum_partial, but copies from fs:src while it
35 * checksums
36 *
37 * here even more important to align src and dst on a 32-bit (or even
38 * better 64-bit) boundary
39 */
40
41extern unsigned int __csum_partial_copy_sparc_generic (const unsigned char *, unsigned char *);
42
43static inline __wsum
44csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
45{
46 register unsigned int ret asm("o0") = (unsigned int)src;
47 register char *d asm("o1") = dst;
48 register int l asm("g1") = len;
49
50 __asm__ __volatile__ (
51 "call __csum_partial_copy_sparc_generic\n\t"
52 " mov %6, %%g7\n"
53 : "=&r" (ret), "=&r" (d), "=&r" (l)
54 : "0" (ret), "1" (d), "2" (l), "r" (sum)
55 : "o2", "o3", "o4", "o5", "o7",
56 "g2", "g3", "g4", "g5", "g7",
57 "memory", "cc");
58 return (__force __wsum)ret;
59}
60
61static inline __wsum
62csum_partial_copy_from_user(const void __user *src, void *dst, int len,
63 __wsum sum, int *err)
64 {
65 register unsigned long ret asm("o0") = (unsigned long)src;
66 register char *d asm("o1") = dst;
67 register int l asm("g1") = len;
68 register __wsum s asm("g7") = sum;
69
70 __asm__ __volatile__ (
71 ".section __ex_table,#alloc\n\t"
72 ".align 4\n\t"
73 ".word 1f,2\n\t"
74 ".previous\n"
75 "1:\n\t"
76 "call __csum_partial_copy_sparc_generic\n\t"
77 " st %8, [%%sp + 64]\n"
78 : "=&r" (ret), "=&r" (d), "=&r" (l), "=&r" (s)
79 : "0" (ret), "1" (d), "2" (l), "3" (s), "r" (err)
80 : "o2", "o3", "o4", "o5", "o7", "g2", "g3", "g4", "g5",
81 "cc", "memory");
82 return (__force __wsum)ret;
83}
84
85static inline __wsum
86csum_partial_copy_to_user(const void *src, void __user *dst, int len,
87 __wsum sum, int *err)
88{
89 if (!access_ok (VERIFY_WRITE, dst, len)) {
90 *err = -EFAULT;
91 return sum;
92 } else {
93 register unsigned long ret asm("o0") = (unsigned long)src;
94 register char __user *d asm("o1") = dst;
95 register int l asm("g1") = len;
96 register __wsum s asm("g7") = sum;
97
98 __asm__ __volatile__ (
99 ".section __ex_table,#alloc\n\t"
100 ".align 4\n\t"
101 ".word 1f,1\n\t"
102 ".previous\n"
103 "1:\n\t"
104 "call __csum_partial_copy_sparc_generic\n\t"
105 " st %8, [%%sp + 64]\n"
106 : "=&r" (ret), "=&r" (d), "=&r" (l), "=&r" (s)
107 : "0" (ret), "1" (d), "2" (l), "3" (s), "r" (err)
108 : "o2", "o3", "o4", "o5", "o7",
109 "g2", "g3", "g4", "g5",
110 "cc", "memory");
111 return (__force __wsum)ret;
112 }
113}
114
115#define HAVE_CSUM_COPY_USER
116#define csum_and_copy_to_user csum_partial_copy_to_user
117
118/* ihl is always 5 or greater, almost always is 5, and iph is word aligned
119 * the majority of the time.
120 */
121static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
122{
123 __sum16 sum;
124
125 /* Note: We must read %2 before we touch %0 for the first time,
126 * because GCC can legitimately use the same register for
127 * both operands.
128 */
129 __asm__ __volatile__("sub\t%2, 4, %%g4\n\t"
130 "ld\t[%1 + 0x00], %0\n\t"
131 "ld\t[%1 + 0x04], %%g2\n\t"
132 "ld\t[%1 + 0x08], %%g3\n\t"
133 "addcc\t%%g2, %0, %0\n\t"
134 "addxcc\t%%g3, %0, %0\n\t"
135 "ld\t[%1 + 0x0c], %%g2\n\t"
136 "ld\t[%1 + 0x10], %%g3\n\t"
137 "addxcc\t%%g2, %0, %0\n\t"
138 "addx\t%0, %%g0, %0\n"
139 "1:\taddcc\t%%g3, %0, %0\n\t"
140 "add\t%1, 4, %1\n\t"
141 "addxcc\t%0, %%g0, %0\n\t"
142 "subcc\t%%g4, 1, %%g4\n\t"
143 "be,a\t2f\n\t"
144 "sll\t%0, 16, %%g2\n\t"
145 "b\t1b\n\t"
146 "ld\t[%1 + 0x10], %%g3\n"
147 "2:\taddcc\t%0, %%g2, %%g2\n\t"
148 "srl\t%%g2, 16, %0\n\t"
149 "addx\t%0, %%g0, %0\n\t"
150 "xnor\t%%g0, %0, %0"
151 : "=r" (sum), "=&r" (iph)
152 : "r" (ihl), "1" (iph)
153 : "g2", "g3", "g4", "cc", "memory");
154 return sum;
155}
156
157/* Fold a partial checksum without adding pseudo headers. */
158static inline __sum16 csum_fold(__wsum sum)
159{
160 unsigned int tmp;
161
162 __asm__ __volatile__("addcc\t%0, %1, %1\n\t"
163 "srl\t%1, 16, %1\n\t"
164 "addx\t%1, %%g0, %1\n\t"
165 "xnor\t%%g0, %1, %0"
166 : "=&r" (sum), "=r" (tmp)
167 : "0" (sum), "1" ((__force u32)sum<<16)
168 : "cc");
169 return (__force __sum16)sum;
170}
171
172static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
173 unsigned short len,
174 unsigned short proto,
175 __wsum sum)
176{
177 __asm__ __volatile__("addcc\t%1, %0, %0\n\t"
178 "addxcc\t%2, %0, %0\n\t"
179 "addxcc\t%3, %0, %0\n\t"
180 "addx\t%0, %%g0, %0\n\t"
181 : "=r" (sum), "=r" (saddr)
182 : "r" (daddr), "r" (proto + len), "0" (sum),
183 "1" (saddr)
184 : "cc");
185 return sum;
186}
187
188/*
189 * computes the checksum of the TCP/UDP pseudo-header
190 * returns a 16-bit checksum, already complemented
191 */
192static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
193 unsigned short len,
194 unsigned short proto,
195 __wsum sum)
196{
197 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
198}
199
200#define _HAVE_ARCH_IPV6_CSUM
201
202static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
203 const struct in6_addr *daddr,
204 __u32 len, unsigned short proto,
205 __wsum sum)
206{
207 __asm__ __volatile__ (
208 "addcc %3, %4, %%g4\n\t"
209 "addxcc %5, %%g4, %%g4\n\t"
210 "ld [%2 + 0x0c], %%g2\n\t"
211 "ld [%2 + 0x08], %%g3\n\t"
212 "addxcc %%g2, %%g4, %%g4\n\t"
213 "ld [%2 + 0x04], %%g2\n\t"
214 "addxcc %%g3, %%g4, %%g4\n\t"
215 "ld [%2 + 0x00], %%g3\n\t"
216 "addxcc %%g2, %%g4, %%g4\n\t"
217 "ld [%1 + 0x0c], %%g2\n\t"
218 "addxcc %%g3, %%g4, %%g4\n\t"
219 "ld [%1 + 0x08], %%g3\n\t"
220 "addxcc %%g2, %%g4, %%g4\n\t"
221 "ld [%1 + 0x04], %%g2\n\t"
222 "addxcc %%g3, %%g4, %%g4\n\t"
223 "ld [%1 + 0x00], %%g3\n\t"
224 "addxcc %%g2, %%g4, %%g4\n\t"
225 "addxcc %%g3, %%g4, %0\n\t"
226 "addx 0, %0, %0\n"
227 : "=&r" (sum)
228 : "r" (saddr), "r" (daddr),
229 "r"(htonl(len)), "r"(htonl(proto)), "r"(sum)
230 : "g2", "g3", "g4", "cc");
231
232 return csum_fold(sum);
233}
234
235/* this routine is used for miscellaneous IP-like checksums, mainly in icmp.c */
236static inline __sum16 ip_compute_csum(const void *buff, int len)
237{
238 return csum_fold(csum_partial(buff, len, 0));
239}
240
241#endif /* !(__SPARC_CHECKSUM_H) */
diff --git a/include/asm-sparc/checksum_64.h b/include/asm-sparc/checksum_64.h
new file mode 100644
index 000000000000..019b9615e43c
--- /dev/null
+++ b/include/asm-sparc/checksum_64.h
@@ -0,0 +1,167 @@
1#ifndef __SPARC64_CHECKSUM_H
2#define __SPARC64_CHECKSUM_H
3
4/* checksum.h: IP/UDP/TCP checksum routines on the V9.
5 *
6 * Copyright(C) 1995 Linus Torvalds
7 * Copyright(C) 1995 Miguel de Icaza
8 * Copyright(C) 1996 David S. Miller
9 * Copyright(C) 1996 Eddie C. Dost
10 * Copyright(C) 1997 Jakub Jelinek
11 *
12 * derived from:
13 * Alpha checksum c-code
14 * ix86 inline assembly
15 * RFC1071 Computing the Internet Checksum
16 */
17
18#include <linux/in6.h>
19#include <asm/uaccess.h>
20
21/* computes the checksum of a memory block at buff, length len,
22 * and adds in "sum" (32-bit)
23 *
24 * returns a 32-bit number suitable for feeding into itself
25 * or csum_tcpudp_magic
26 *
27 * this function must be called with even lengths, except
28 * for the last fragment, which may be odd
29 *
30 * it's best to have buff aligned on a 32-bit boundary
31 */
32extern __wsum csum_partial(const void * buff, int len, __wsum sum);
33
34/* the same as csum_partial, but copies from user space while it
35 * checksums
36 *
37 * here even more important to align src and dst on a 32-bit (or even
38 * better 64-bit) boundary
39 */
40extern __wsum csum_partial_copy_nocheck(const void *src, void *dst,
41 int len, __wsum sum);
42
43extern long __csum_partial_copy_from_user(const void __user *src,
44 void *dst, int len,
45 __wsum sum);
46
47static inline __wsum
48csum_partial_copy_from_user(const void __user *src,
49 void *dst, int len,
50 __wsum sum, int *err)
51{
52 long ret = __csum_partial_copy_from_user(src, dst, len, sum);
53 if (ret < 0)
54 *err = -EFAULT;
55 return (__force __wsum) ret;
56}
57
58/*
59 * Copy and checksum to user
60 */
61#define HAVE_CSUM_COPY_USER
62extern long __csum_partial_copy_to_user(const void *src,
63 void __user *dst, int len,
64 __wsum sum);
65
66static inline __wsum
67csum_and_copy_to_user(const void *src,
68 void __user *dst, int len,
69 __wsum sum, int *err)
70{
71 long ret = __csum_partial_copy_to_user(src, dst, len, sum);
72 if (ret < 0)
73 *err = -EFAULT;
74 return (__force __wsum) ret;
75}
76
77/* ihl is always 5 or greater, almost always is 5, and iph is word aligned
78 * the majority of the time.
79 */
80extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
81
82/* Fold a partial checksum without adding pseudo headers. */
83static inline __sum16 csum_fold(__wsum sum)
84{
85 unsigned int tmp;
86
87 __asm__ __volatile__(
88" addcc %0, %1, %1\n"
89" srl %1, 16, %1\n"
90" addc %1, %%g0, %1\n"
91" xnor %%g0, %1, %0\n"
92 : "=&r" (sum), "=r" (tmp)
93 : "0" (sum), "1" ((__force u32)sum<<16)
94 : "cc");
95 return (__force __sum16)sum;
96}
97
98static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
99 unsigned int len,
100 unsigned short proto,
101 __wsum sum)
102{
103 __asm__ __volatile__(
104" addcc %1, %0, %0\n"
105" addccc %2, %0, %0\n"
106" addccc %3, %0, %0\n"
107" addc %0, %%g0, %0\n"
108 : "=r" (sum), "=r" (saddr)
109 : "r" (daddr), "r" (proto + len), "0" (sum), "1" (saddr)
110 : "cc");
111 return sum;
112}
113
114/*
115 * computes the checksum of the TCP/UDP pseudo-header
116 * returns a 16-bit checksum, already complemented
117 */
118static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
119 unsigned short len,
120 unsigned short proto,
121 __wsum sum)
122{
123 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
124}
125
126#define _HAVE_ARCH_IPV6_CSUM
127
128static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
129 const struct in6_addr *daddr,
130 __u32 len, unsigned short proto,
131 __wsum sum)
132{
133 __asm__ __volatile__ (
134" addcc %3, %4, %%g7\n"
135" addccc %5, %%g7, %%g7\n"
136" lduw [%2 + 0x0c], %%g2\n"
137" lduw [%2 + 0x08], %%g3\n"
138" addccc %%g2, %%g7, %%g7\n"
139" lduw [%2 + 0x04], %%g2\n"
140" addccc %%g3, %%g7, %%g7\n"
141" lduw [%2 + 0x00], %%g3\n"
142" addccc %%g2, %%g7, %%g7\n"
143" lduw [%1 + 0x0c], %%g2\n"
144" addccc %%g3, %%g7, %%g7\n"
145" lduw [%1 + 0x08], %%g3\n"
146" addccc %%g2, %%g7, %%g7\n"
147" lduw [%1 + 0x04], %%g2\n"
148" addccc %%g3, %%g7, %%g7\n"
149" lduw [%1 + 0x00], %%g3\n"
150" addccc %%g2, %%g7, %%g7\n"
151" addccc %%g3, %%g7, %0\n"
152" addc 0, %0, %0\n"
153 : "=&r" (sum)
154 : "r" (saddr), "r" (daddr), "r"(htonl(len)),
155 "r"(htonl(proto)), "r"(sum)
156 : "g2", "g3", "g7", "cc");
157
158 return csum_fold(sum);
159}
160
161/* this routine is used for miscellaneous IP-like checksums, mainly in icmp.c */
162static inline __sum16 ip_compute_csum(const void *buff, int len)
163{
164 return csum_fold(csum_partial(buff, len, 0));
165}
166
167#endif /* !(__SPARC64_CHECKSUM_H) */
diff --git a/include/asm-sparc/chmctrl.h b/include/asm-sparc/chmctrl.h
new file mode 100644
index 000000000000..859b4a4b0d30
--- /dev/null
+++ b/include/asm-sparc/chmctrl.h
@@ -0,0 +1,183 @@
1#ifndef _SPARC64_CHMCTRL_H
2#define _SPARC64_CHMCTRL_H
3
4/* Cheetah memory controller programmable registers. */
5#define CHMCTRL_TCTRL1 0x00 /* Memory Timing Control I */
6#define CHMCTRL_TCTRL2 0x08 /* Memory Timing Control II */
7#define CHMCTRL_TCTRL3 0x38 /* Memory Timing Control III */
8#define CHMCTRL_TCTRL4 0x40 /* Memory Timing Control IV */
9#define CHMCTRL_DECODE1 0x10 /* Memory Address Decode I */
10#define CHMCTRL_DECODE2 0x18 /* Memory Address Decode II */
11#define CHMCTRL_DECODE3 0x20 /* Memory Address Decode III */
12#define CHMCTRL_DECODE4 0x28 /* Memory Address Decode IV */
13#define CHMCTRL_MACTRL 0x30 /* Memory Address Control */
14
15/* Memory Timing Control I */
16#define TCTRL1_SDRAMCTL_DLY 0xf000000000000000UL
17#define TCTRL1_SDRAMCTL_DLY_SHIFT 60
18#define TCTRL1_SDRAMCLK_DLY 0x0e00000000000000UL
19#define TCTRL1_SDRAMCLK_DLY_SHIFT 57
20#define TCTRL1_R 0x0100000000000000UL
21#define TCTRL1_R_SHIFT 56
22#define TCTRL1_AUTORFR_CYCLE 0x00fe000000000000UL
23#define TCTRL1_AUTORFR_CYCLE_SHIFT 49
24#define TCTRL1_RD_WAIT 0x0001f00000000000UL
25#define TCTRL1_RD_WAIT_SHIFT 44
26#define TCTRL1_PC_CYCLE 0x00000fc000000000UL
27#define TCTRL1_PC_CYCLE_SHIFT 38
28#define TCTRL1_WR_MORE_RAS_PW 0x0000003f00000000UL
29#define TCTRL1_WR_MORE_RAS_PW_SHIFT 32
30#define TCTRL1_RD_MORE_RAW_PW 0x00000000fc000000UL
31#define TCTRL1_RD_MORE_RAS_PW_SHIFT 26
32#define TCTRL1_ACT_WR_DLY 0x0000000003f00000UL
33#define TCTRL1_ACT_WR_DLY_SHIFT 20
34#define TCTRL1_ACT_RD_DLY 0x00000000000fc000UL
35#define TCTRL1_ACT_RD_DLY_SHIFT 14
36#define TCTRL1_BANK_PRESENT 0x0000000000003000UL
37#define TCTRL1_BANK_PRESENT_SHIFT 12
38#define TCTRL1_RFR_INT 0x0000000000000ff8UL
39#define TCTRL1_RFR_INT_SHIFT 3
40#define TCTRL1_SET_MODE_REG 0x0000000000000004UL
41#define TCTRL1_SET_MODE_REG_SHIFT 2
42#define TCTRL1_RFR_ENABLE 0x0000000000000002UL
43#define TCTRL1_RFR_ENABLE_SHIFT 1
44#define TCTRL1_PRECHG_ALL 0x0000000000000001UL
45#define TCTRL1_PRECHG_ALL_SHIFT 0
46
47/* Memory Timing Control II */
48#define TCTRL2_WR_MSEL_DLY 0xfc00000000000000UL
49#define TCTRL2_WR_MSEL_DLY_SHIFT 58
50#define TCTRL2_RD_MSEL_DLY 0x03f0000000000000UL
51#define TCTRL2_RD_MSEL_DLY_SHIFT 52
52#define TCTRL2_WRDATA_THLD 0x000c000000000000UL
53#define TCTRL2_WRDATA_THLD_SHIFT 50
54#define TCTRL2_RDWR_RD_TI_DLY 0x0003f00000000000UL
55#define TCTRL2_RDWR_RD_TI_DLY_SHIFT 44
56#define TCTRL2_AUTOPRECHG_ENBL 0x0000080000000000UL
57#define TCTRL2_AUTOPRECHG_ENBL_SHIFT 43
58#define TCTRL2_RDWR_PI_MORE_DLY 0x000007c000000000UL
59#define TCTRL2_RDWR_PI_MORE_DLY_SHIFT 38
60#define TCTRL2_RDWR_1_DLY 0x0000003f00000000UL
61#define TCTRL2_RDWR_1_DLY_SHIFT 32
62#define TCTRL2_WRWR_PI_MORE_DLY 0x00000000f8000000UL
63#define TCTRL2_WRWR_PI_MORE_DLY_SHIFT 27
64#define TCTRL2_WRWR_1_DLY 0x0000000007e00000UL
65#define TCTRL2_WRWR_1_DLY_SHIFT 21
66#define TCTRL2_RDWR_RD_PI_MORE_DLY 0x00000000001f0000UL
67#define TCTRL2_RDWR_RD_PI_MORE_DLY_SHIFT 16
68#define TCTRL2_R 0x0000000000008000UL
69#define TCTRL2_R_SHIFT 15
70#define TCTRL2_SDRAM_MODE_REG_DATA 0x0000000000007fffUL
71#define TCTRL2_SDRAM_MODE_REG_DATA_SHIFT 0
72
73/* Memory Timing Control III */
74#define TCTRL3_SDRAM_CTL_DLY 0xf000000000000000UL
75#define TCTRL3_SDRAM_CTL_DLY_SHIFT 60
76#define TCTRL3_SDRAM_CLK_DLY 0x0e00000000000000UL
77#define TCTRL3_SDRAM_CLK_DLY_SHIFT 57
78#define TCTRL3_R 0x0100000000000000UL
79#define TCTRL3_R_SHIFT 56
80#define TCTRL3_AUTO_RFR_CYCLE 0x00fe000000000000UL
81#define TCTRL3_AUTO_RFR_CYCLE_SHIFT 49
82#define TCTRL3_RD_WAIT 0x0001f00000000000UL
83#define TCTRL3_RD_WAIT_SHIFT 44
84#define TCTRL3_PC_CYCLE 0x00000fc000000000UL
85#define TCTRL3_PC_CYCLE_SHIFT 38
86#define TCTRL3_WR_MORE_RAW_PW 0x0000003f00000000UL
87#define TCTRL3_WR_MORE_RAW_PW_SHIFT 32
88#define TCTRL3_RD_MORE_RAW_PW 0x00000000fc000000UL
89#define TCTRL3_RD_MORE_RAW_PW_SHIFT 26
90#define TCTRL3_ACT_WR_DLY 0x0000000003f00000UL
91#define TCTRL3_ACT_WR_DLY_SHIFT 20
92#define TCTRL3_ACT_RD_DLY 0x00000000000fc000UL
93#define TCTRL3_ACT_RD_DLY_SHIFT 14
94#define TCTRL3_BANK_PRESENT 0x0000000000003000UL
95#define TCTRL3_BANK_PRESENT_SHIFT 12
96#define TCTRL3_RFR_INT 0x0000000000000ff8UL
97#define TCTRL3_RFR_INT_SHIFT 3
98#define TCTRL3_SET_MODE_REG 0x0000000000000004UL
99#define TCTRL3_SET_MODE_REG_SHIFT 2
100#define TCTRL3_RFR_ENABLE 0x0000000000000002UL
101#define TCTRL3_RFR_ENABLE_SHIFT 1
102#define TCTRL3_PRECHG_ALL 0x0000000000000001UL
103#define TCTRL3_PRECHG_ALL_SHIFT 0
104
105/* Memory Timing Control IV */
106#define TCTRL4_WR_MSEL_DLY 0xfc00000000000000UL
107#define TCTRL4_WR_MSEL_DLY_SHIFT 58
108#define TCTRL4_RD_MSEL_DLY 0x03f0000000000000UL
109#define TCTRL4_RD_MSEL_DLY_SHIFT 52
110#define TCTRL4_WRDATA_THLD 0x000c000000000000UL
111#define TCTRL4_WRDATA_THLD_SHIFT 50
112#define TCTRL4_RDWR_RD_RI_DLY 0x0003f00000000000UL
113#define TCTRL4_RDWR_RD_RI_DLY_SHIFT 44
114#define TCTRL4_AUTO_PRECHG_ENBL 0x0000080000000000UL
115#define TCTRL4_AUTO_PRECHG_ENBL_SHIFT 43
116#define TCTRL4_RD_WR_PI_MORE_DLY 0x000007c000000000UL
117#define TCTRL4_RD_WR_PI_MORE_DLY_SHIFT 38
118#define TCTRL4_RD_WR_TI_DLY 0x0000003f00000000UL
119#define TCTRL4_RD_WR_TI_DLY_SHIFT 32
120#define TCTRL4_WR_WR_PI_MORE_DLY 0x00000000f8000000UL
121#define TCTRL4_WR_WR_PI_MORE_DLY_SHIFT 27
122#define TCTRL4_WR_WR_TI_DLY 0x0000000007e00000UL
123#define TCTRL4_WR_WR_TI_DLY_SHIFT 21
124#define TCTRL4_RDWR_RD_PI_MORE_DLY 0x00000000001f000UL0
125#define TCTRL4_RDWR_RD_PI_MORE_DLY_SHIFT 16
126#define TCTRL4_R 0x0000000000008000UL
127#define TCTRL4_R_SHIFT 15
128#define TCTRL4_SDRAM_MODE_REG_DATA 0x0000000000007fffUL
129#define TCTRL4_SDRAM_MODE_REG_DATA_SHIFT 0
130
131/* All 4 memory address decoding registers have the
132 * same layout.
133 */
134#define MEM_DECODE_VALID 0x8000000000000000UL /* Valid */
135#define MEM_DECODE_VALID_SHIFT 63
136#define MEM_DECODE_UK 0x001ffe0000000000UL /* Upper mask */
137#define MEM_DECODE_UK_SHIFT 41
138#define MEM_DECODE_UM 0x0000001ffff00000UL /* Upper match */
139#define MEM_DECODE_UM_SHIFT 20
140#define MEM_DECODE_LK 0x000000000003c000UL /* Lower mask */
141#define MEM_DECODE_LK_SHIFT 14
142#define MEM_DECODE_LM 0x0000000000000f00UL /* Lower match */
143#define MEM_DECODE_LM_SHIFT 8
144
145#define PA_UPPER_BITS 0x000007fffc000000UL
146#define PA_UPPER_BITS_SHIFT 26
147#define PA_LOWER_BITS 0x00000000000003c0UL
148#define PA_LOWER_BITS_SHIFT 6
149
150#define MACTRL_R0 0x8000000000000000UL
151#define MACTRL_R0_SHIFT 63
152#define MACTRL_ADDR_LE_PW 0x7000000000000000UL
153#define MACTRL_ADDR_LE_PW_SHIFT 60
154#define MACTRL_CMD_PW 0x0f00000000000000UL
155#define MACTRL_CMD_PW_SHIFT 56
156#define MACTRL_HALF_MODE_WR_MSEL_DLY 0x00fc000000000000UL
157#define MACTRL_HALF_MODE_WR_MSEL_DLY_SHIFT 50
158#define MACTRL_HALF_MODE_RD_MSEL_DLY 0x0003f00000000000UL
159#define MACTRL_HALF_MODE_RD_MSEL_DLY_SHIFT 44
160#define MACTRL_HALF_MODE_SDRAM_CTL_DLY 0x00000f0000000000UL
161#define MACTRL_HALF_MODE_SDRAM_CTL_DLY_SHIFT 40
162#define MACTRL_HALF_MODE_SDRAM_CLK_DLY 0x000000e000000000UL
163#define MACTRL_HALF_MODE_SDRAM_CLK_DLY_SHIFT 37
164#define MACTRL_R1 0x0000001000000000UL
165#define MACTRL_R1_SHIFT 36
166#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B3 0x0000000f00000000UL
167#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B3_SHIFT 32
168#define MACTRL_ENC_INTLV_B3 0x00000000f8000000UL
169#define MACTRL_ENC_INTLV_B3_SHIFT 27
170#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B2 0x0000000007800000UL
171#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B2_SHIFT 23
172#define MACTRL_ENC_INTLV_B2 0x00000000007c0000UL
173#define MACTRL_ENC_INTLV_B2_SHIFT 18
174#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B1 0x000000000003c000UL
175#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B1_SHIFT 14
176#define MACTRL_ENC_INTLV_B1 0x0000000000003e00UL
177#define MACTRL_ENC_INTLV_B1_SHIFT 9
178#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B0 0x00000000000001e0UL
179#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B0_SHIFT 5
180#define MACTRL_ENC_INTLV_B0 0x000000000000001fUL
181#define MACTRL_ENC_INTLV_B0_SHIFT 0
182
183#endif /* _SPARC64_CHMCTRL_H */
diff --git a/include/asm-sparc/cmt.h b/include/asm-sparc/cmt.h
new file mode 100644
index 000000000000..870db5928577
--- /dev/null
+++ b/include/asm-sparc/cmt.h
@@ -0,0 +1,59 @@
1#ifndef _SPARC64_CMT_H
2#define _SPARC64_CMT_H
3
4/* cmt.h: Chip Multi-Threading register definitions
5 *
6 * Copyright (C) 2004 David S. Miller (davem@redhat.com)
7 */
8
9/* ASI_CORE_ID - private */
10#define LP_ID 0x0000000000000010UL
11#define LP_ID_MAX 0x00000000003f0000UL
12#define LP_ID_ID 0x000000000000003fUL
13
14/* ASI_INTR_ID - private */
15#define LP_INTR_ID 0x0000000000000000UL
16#define LP_INTR_ID_ID 0x00000000000003ffUL
17
18/* ASI_CESR_ID - private */
19#define CESR_ID 0x0000000000000040UL
20#define CESR_ID_ID 0x00000000000000ffUL
21
22/* ASI_CORE_AVAILABLE - shared */
23#define LP_AVAIL 0x0000000000000000UL
24#define LP_AVAIL_1 0x0000000000000002UL
25#define LP_AVAIL_0 0x0000000000000001UL
26
27/* ASI_CORE_ENABLE_STATUS - shared */
28#define LP_ENAB_STAT 0x0000000000000010UL
29#define LP_ENAB_STAT_1 0x0000000000000002UL
30#define LP_ENAB_STAT_0 0x0000000000000001UL
31
32/* ASI_CORE_ENABLE - shared */
33#define LP_ENAB 0x0000000000000020UL
34#define LP_ENAB_1 0x0000000000000002UL
35#define LP_ENAB_0 0x0000000000000001UL
36
37/* ASI_CORE_RUNNING - shared */
38#define LP_RUNNING_RW 0x0000000000000050UL
39#define LP_RUNNING_W1S 0x0000000000000060UL
40#define LP_RUNNING_W1C 0x0000000000000068UL
41#define LP_RUNNING_1 0x0000000000000002UL
42#define LP_RUNNING_0 0x0000000000000001UL
43
44/* ASI_CORE_RUNNING_STAT - shared */
45#define LP_RUN_STAT 0x0000000000000058UL
46#define LP_RUN_STAT_1 0x0000000000000002UL
47#define LP_RUN_STAT_0 0x0000000000000001UL
48
49/* ASI_XIR_STEERING - shared */
50#define LP_XIR_STEER 0x0000000000000030UL
51#define LP_XIR_STEER_1 0x0000000000000002UL
52#define LP_XIR_STEER_0 0x0000000000000001UL
53
54/* ASI_CMT_ERROR_STEERING - shared */
55#define CMT_ER_STEER 0x0000000000000040UL
56#define CMT_ER_STEER_1 0x0000000000000002UL
57#define CMT_ER_STEER_0 0x0000000000000001UL
58
59#endif /* _SPARC64_CMT_H */
diff --git a/include/asm-sparc/compat.h b/include/asm-sparc/compat.h
new file mode 100644
index 000000000000..f260b58f5ce9
--- /dev/null
+++ b/include/asm-sparc/compat.h
@@ -0,0 +1,243 @@
1#ifndef _ASM_SPARC64_COMPAT_H
2#define _ASM_SPARC64_COMPAT_H
3/*
4 * Architecture specific compatibility types
5 */
6#include <linux/types.h>
7
8#define COMPAT_USER_HZ 100
9
10typedef u32 compat_size_t;
11typedef s32 compat_ssize_t;
12typedef s32 compat_time_t;
13typedef s32 compat_clock_t;
14typedef s32 compat_pid_t;
15typedef u16 __compat_uid_t;
16typedef u16 __compat_gid_t;
17typedef u32 __compat_uid32_t;
18typedef u32 __compat_gid32_t;
19typedef u16 compat_mode_t;
20typedef u32 compat_ino_t;
21typedef u16 compat_dev_t;
22typedef s32 compat_off_t;
23typedef s64 compat_loff_t;
24typedef s16 compat_nlink_t;
25typedef u16 compat_ipc_pid_t;
26typedef s32 compat_daddr_t;
27typedef u32 compat_caddr_t;
28typedef __kernel_fsid_t compat_fsid_t;
29typedef s32 compat_key_t;
30typedef s32 compat_timer_t;
31
32typedef s32 compat_int_t;
33typedef s32 compat_long_t;
34typedef s64 compat_s64;
35typedef u32 compat_uint_t;
36typedef u32 compat_ulong_t;
37typedef u64 compat_u64;
38
39struct compat_timespec {
40 compat_time_t tv_sec;
41 s32 tv_nsec;
42};
43
44struct compat_timeval {
45 compat_time_t tv_sec;
46 s32 tv_usec;
47};
48
49struct compat_stat {
50 compat_dev_t st_dev;
51 compat_ino_t st_ino;
52 compat_mode_t st_mode;
53 compat_nlink_t st_nlink;
54 __compat_uid_t st_uid;
55 __compat_gid_t st_gid;
56 compat_dev_t st_rdev;
57 compat_off_t st_size;
58 compat_time_t st_atime;
59 compat_ulong_t st_atime_nsec;
60 compat_time_t st_mtime;
61 compat_ulong_t st_mtime_nsec;
62 compat_time_t st_ctime;
63 compat_ulong_t st_ctime_nsec;
64 compat_off_t st_blksize;
65 compat_off_t st_blocks;
66 u32 __unused4[2];
67};
68
69struct compat_stat64 {
70 unsigned long long st_dev;
71
72 unsigned long long st_ino;
73
74 unsigned int st_mode;
75 unsigned int st_nlink;
76
77 unsigned int st_uid;
78 unsigned int st_gid;
79
80 unsigned long long st_rdev;
81
82 unsigned char __pad3[8];
83
84 long long st_size;
85 unsigned int st_blksize;
86
87 unsigned char __pad4[8];
88 unsigned int st_blocks;
89
90 unsigned int st_atime;
91 unsigned int st_atime_nsec;
92
93 unsigned int st_mtime;
94 unsigned int st_mtime_nsec;
95
96 unsigned int st_ctime;
97 unsigned int st_ctime_nsec;
98
99 unsigned int __unused4;
100 unsigned int __unused5;
101};
102
103struct compat_flock {
104 short l_type;
105 short l_whence;
106 compat_off_t l_start;
107 compat_off_t l_len;
108 compat_pid_t l_pid;
109 short __unused;
110};
111
112#define F_GETLK64 12
113#define F_SETLK64 13
114#define F_SETLKW64 14
115
116struct compat_flock64 {
117 short l_type;
118 short l_whence;
119 compat_loff_t l_start;
120 compat_loff_t l_len;
121 compat_pid_t l_pid;
122 short __unused;
123};
124
125struct compat_statfs {
126 int f_type;
127 int f_bsize;
128 int f_blocks;
129 int f_bfree;
130 int f_bavail;
131 int f_files;
132 int f_ffree;
133 compat_fsid_t f_fsid;
134 int f_namelen; /* SunOS ignores this field. */
135 int f_frsize;
136 int f_spare[5];
137};
138
139#define COMPAT_RLIM_INFINITY 0x7fffffff
140
141typedef u32 compat_old_sigset_t;
142
143#define _COMPAT_NSIG 64
144#define _COMPAT_NSIG_BPW 32
145
146typedef u32 compat_sigset_word;
147
148#define COMPAT_OFF_T_MAX 0x7fffffff
149#define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
150
151/*
152 * A pointer passed in from user mode. This should not
153 * be used for syscall parameters, just declare them
154 * as pointers because the syscall entry code will have
155 * appropriately converted them already.
156 */
157typedef u32 compat_uptr_t;
158
159static inline void __user *compat_ptr(compat_uptr_t uptr)
160{
161 return (void __user *)(unsigned long)uptr;
162}
163
164static inline compat_uptr_t ptr_to_compat(void __user *uptr)
165{
166 return (u32)(unsigned long)uptr;
167}
168
169static inline void __user *compat_alloc_user_space(long len)
170{
171 struct pt_regs *regs = current_thread_info()->kregs;
172 unsigned long usp = regs->u_regs[UREG_I6];
173
174 if (!(test_thread_flag(TIF_32BIT)))
175 usp += STACK_BIAS;
176 else
177 usp &= 0xffffffffUL;
178
179 usp -= len;
180 usp &= ~0x7UL;
181
182 return (void __user *) usp;
183}
184
185struct compat_ipc64_perm {
186 compat_key_t key;
187 __compat_uid32_t uid;
188 __compat_gid32_t gid;
189 __compat_uid32_t cuid;
190 __compat_gid32_t cgid;
191 unsigned short __pad1;
192 compat_mode_t mode;
193 unsigned short __pad2;
194 unsigned short seq;
195 unsigned long __unused1; /* yes they really are 64bit pads */
196 unsigned long __unused2;
197};
198
199struct compat_semid64_ds {
200 struct compat_ipc64_perm sem_perm;
201 unsigned int __pad1;
202 compat_time_t sem_otime;
203 unsigned int __pad2;
204 compat_time_t sem_ctime;
205 u32 sem_nsems;
206 u32 __unused1;
207 u32 __unused2;
208};
209
210struct compat_msqid64_ds {
211 struct compat_ipc64_perm msg_perm;
212 unsigned int __pad1;
213 compat_time_t msg_stime;
214 unsigned int __pad2;
215 compat_time_t msg_rtime;
216 unsigned int __pad3;
217 compat_time_t msg_ctime;
218 unsigned int msg_cbytes;
219 unsigned int msg_qnum;
220 unsigned int msg_qbytes;
221 compat_pid_t msg_lspid;
222 compat_pid_t msg_lrpid;
223 unsigned int __unused1;
224 unsigned int __unused2;
225};
226
227struct compat_shmid64_ds {
228 struct compat_ipc64_perm shm_perm;
229 unsigned int __pad1;
230 compat_time_t shm_atime;
231 unsigned int __pad2;
232 compat_time_t shm_dtime;
233 unsigned int __pad3;
234 compat_time_t shm_ctime;
235 compat_size_t shm_segsz;
236 compat_pid_t shm_cpid;
237 compat_pid_t shm_lpid;
238 unsigned int shm_nattch;
239 unsigned int __unused1;
240 unsigned int __unused2;
241};
242
243#endif /* _ASM_SPARC64_COMPAT_H */
diff --git a/include/asm-sparc/compat_signal.h b/include/asm-sparc/compat_signal.h
new file mode 100644
index 000000000000..b759eab9b51c
--- /dev/null
+++ b/include/asm-sparc/compat_signal.h
@@ -0,0 +1,29 @@
1#ifndef _COMPAT_SIGNAL_H
2#define _COMPAT_SIGNAL_H
3
4#include <linux/compat.h>
5#include <asm/signal.h>
6
7#ifdef CONFIG_COMPAT
8struct __new_sigaction32 {
9 unsigned sa_handler;
10 unsigned int sa_flags;
11 unsigned sa_restorer; /* not used by Linux/SPARC yet */
12 compat_sigset_t sa_mask;
13};
14
15struct __old_sigaction32 {
16 unsigned sa_handler;
17 compat_old_sigset_t sa_mask;
18 unsigned int sa_flags;
19 unsigned sa_restorer; /* not used by Linux/SPARC yet */
20};
21
22typedef struct sigaltstack32 {
23 u32 ss_sp;
24 int ss_flags;
25 compat_size_t ss_size;
26} stack_t32;
27#endif
28
29#endif /* !(_COMPAT_SIGNAL_H) */
diff --git a/include/asm-sparc/cpudata.h b/include/asm-sparc/cpudata.h
index a2c4d51d36c4..b76fac0c8d8f 100644
--- a/include/asm-sparc/cpudata.h
+++ b/include/asm-sparc/cpudata.h
@@ -1,27 +1,8 @@
1/* cpudata.h: Per-cpu parameters. 1#ifndef ___ASM_SPARC_CPUDATA_H
2 * 2#define ___ASM_SPARC_CPUDATA_H
3 * Copyright (C) 2004 Keith M Wesolowski (wesolows@foobazco.org) 3#if defined(__sparc__) && defined(__arch64__)
4 * 4#include <asm-sparc/cpudata_64.h>
5 * Based on include/asm-sparc64/cpudata.h and Linux 2.4 smp.h 5#else
6 * both (C) David S. Miller. 6#include <asm-sparc/cpudata_32.h>
7 */ 7#endif
8 8#endif
9#ifndef _SPARC_CPUDATA_H
10#define _SPARC_CPUDATA_H
11
12#include <linux/percpu.h>
13
14typedef struct {
15 unsigned long udelay_val;
16 unsigned long clock_tick;
17 unsigned int multiplier;
18 unsigned int counter;
19 int prom_node;
20 int mid;
21 int next;
22} cpuinfo_sparc;
23
24DECLARE_PER_CPU(cpuinfo_sparc, __cpu_data);
25#define cpu_data(__cpu) per_cpu(__cpu_data, (__cpu))
26
27#endif /* _SPARC_CPUDATA_H */
diff --git a/include/asm-sparc/cpudata_32.h b/include/asm-sparc/cpudata_32.h
new file mode 100644
index 000000000000..a2c4d51d36c4
--- /dev/null
+++ b/include/asm-sparc/cpudata_32.h
@@ -0,0 +1,27 @@
1/* cpudata.h: Per-cpu parameters.
2 *
3 * Copyright (C) 2004 Keith M Wesolowski (wesolows@foobazco.org)
4 *
5 * Based on include/asm-sparc64/cpudata.h and Linux 2.4 smp.h
6 * both (C) David S. Miller.
7 */
8
9#ifndef _SPARC_CPUDATA_H
10#define _SPARC_CPUDATA_H
11
12#include <linux/percpu.h>
13
14typedef struct {
15 unsigned long udelay_val;
16 unsigned long clock_tick;
17 unsigned int multiplier;
18 unsigned int counter;
19 int prom_node;
20 int mid;
21 int next;
22} cpuinfo_sparc;
23
24DECLARE_PER_CPU(cpuinfo_sparc, __cpu_data);
25#define cpu_data(__cpu) per_cpu(__cpu_data, (__cpu))
26
27#endif /* _SPARC_CPUDATA_H */
diff --git a/include/asm-sparc/cpudata_64.h b/include/asm-sparc/cpudata_64.h
new file mode 100644
index 000000000000..532975ecfe10
--- /dev/null
+++ b/include/asm-sparc/cpudata_64.h
@@ -0,0 +1,240 @@
1/* cpudata.h: Per-cpu parameters.
2 *
3 * Copyright (C) 2003, 2005, 2006 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_CPUDATA_H
7#define _SPARC64_CPUDATA_H
8
9#include <asm/hypervisor.h>
10#include <asm/asi.h>
11
12#ifndef __ASSEMBLY__
13
14#include <linux/percpu.h>
15#include <linux/threads.h>
16
17typedef struct {
18 /* Dcache line 1 */
19 unsigned int __softirq_pending; /* must be 1st, see rtrap.S */
20 unsigned int __pad0;
21 unsigned long clock_tick; /* %tick's per second */
22 unsigned long __pad;
23 unsigned int __pad1;
24 unsigned int __pad2;
25
26 /* Dcache line 2, rarely used */
27 unsigned int dcache_size;
28 unsigned int dcache_line_size;
29 unsigned int icache_size;
30 unsigned int icache_line_size;
31 unsigned int ecache_size;
32 unsigned int ecache_line_size;
33 int core_id;
34 int proc_id;
35} cpuinfo_sparc;
36
37DECLARE_PER_CPU(cpuinfo_sparc, __cpu_data);
38#define cpu_data(__cpu) per_cpu(__cpu_data, (__cpu))
39#define local_cpu_data() __get_cpu_var(__cpu_data)
40
41/* Trap handling code needs to get at a few critical values upon
42 * trap entry and to process TSB misses. These cannot be in the
43 * per_cpu() area as we really need to lock them into the TLB and
44 * thus make them part of the main kernel image. As a result we
45 * try to make this as small as possible.
46 *
47 * This is padded out and aligned to 64-bytes to avoid false sharing
48 * on SMP.
49 */
50
51/* If you modify the size of this structure, please update
52 * TRAP_BLOCK_SZ_SHIFT below.
53 */
54struct thread_info;
55struct trap_per_cpu {
56/* D-cache line 1: Basic thread information, cpu and device mondo queues */
57 struct thread_info *thread;
58 unsigned long pgd_paddr;
59 unsigned long cpu_mondo_pa;
60 unsigned long dev_mondo_pa;
61
62/* D-cache line 2: Error Mondo Queue and kernel buffer pointers */
63 unsigned long resum_mondo_pa;
64 unsigned long resum_kernel_buf_pa;
65 unsigned long nonresum_mondo_pa;
66 unsigned long nonresum_kernel_buf_pa;
67
68/* Dcache lines 3, 4, 5, and 6: Hypervisor Fault Status */
69 struct hv_fault_status fault_info;
70
71/* Dcache line 7: Physical addresses of CPU send mondo block and CPU list. */
72 unsigned long cpu_mondo_block_pa;
73 unsigned long cpu_list_pa;
74 unsigned long tsb_huge;
75 unsigned long tsb_huge_temp;
76
77/* Dcache line 8: IRQ work list, and keep trap_block a power-of-2 in size. */
78 unsigned long irq_worklist_pa;
79 unsigned int cpu_mondo_qmask;
80 unsigned int dev_mondo_qmask;
81 unsigned int resum_qmask;
82 unsigned int nonresum_qmask;
83 void *hdesc;
84} __attribute__((aligned(64)));
85extern struct trap_per_cpu trap_block[NR_CPUS];
86extern void init_cur_cpu_trap(struct thread_info *);
87extern void setup_tba(void);
88extern int ncpus_probed;
89extern void __init cpu_probe(void);
90extern const struct seq_operations cpuinfo_op;
91
92extern unsigned long real_hard_smp_processor_id(void);
93
94struct cpuid_patch_entry {
95 unsigned int addr;
96 unsigned int cheetah_safari[4];
97 unsigned int cheetah_jbus[4];
98 unsigned int starfire[4];
99 unsigned int sun4v[4];
100};
101extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
102
103struct sun4v_1insn_patch_entry {
104 unsigned int addr;
105 unsigned int insn;
106};
107extern struct sun4v_1insn_patch_entry __sun4v_1insn_patch,
108 __sun4v_1insn_patch_end;
109
110struct sun4v_2insn_patch_entry {
111 unsigned int addr;
112 unsigned int insns[2];
113};
114extern struct sun4v_2insn_patch_entry __sun4v_2insn_patch,
115 __sun4v_2insn_patch_end;
116
117#endif /* !(__ASSEMBLY__) */
118
119#define TRAP_PER_CPU_THREAD 0x00
120#define TRAP_PER_CPU_PGD_PADDR 0x08
121#define TRAP_PER_CPU_CPU_MONDO_PA 0x10
122#define TRAP_PER_CPU_DEV_MONDO_PA 0x18
123#define TRAP_PER_CPU_RESUM_MONDO_PA 0x20
124#define TRAP_PER_CPU_RESUM_KBUF_PA 0x28
125#define TRAP_PER_CPU_NONRESUM_MONDO_PA 0x30
126#define TRAP_PER_CPU_NONRESUM_KBUF_PA 0x38
127#define TRAP_PER_CPU_FAULT_INFO 0x40
128#define TRAP_PER_CPU_CPU_MONDO_BLOCK_PA 0xc0
129#define TRAP_PER_CPU_CPU_LIST_PA 0xc8
130#define TRAP_PER_CPU_TSB_HUGE 0xd0
131#define TRAP_PER_CPU_TSB_HUGE_TEMP 0xd8
132#define TRAP_PER_CPU_IRQ_WORKLIST_PA 0xe0
133#define TRAP_PER_CPU_CPU_MONDO_QMASK 0xe8
134#define TRAP_PER_CPU_DEV_MONDO_QMASK 0xec
135#define TRAP_PER_CPU_RESUM_QMASK 0xf0
136#define TRAP_PER_CPU_NONRESUM_QMASK 0xf4
137
138#define TRAP_BLOCK_SZ_SHIFT 8
139
140#include <asm/scratchpad.h>
141
142#define __GET_CPUID(REG) \
143 /* Spitfire implementation (default). */ \
144661: ldxa [%g0] ASI_UPA_CONFIG, REG; \
145 srlx REG, 17, REG; \
146 and REG, 0x1f, REG; \
147 nop; \
148 .section .cpuid_patch, "ax"; \
149 /* Instruction location. */ \
150 .word 661b; \
151 /* Cheetah Safari implementation. */ \
152 ldxa [%g0] ASI_SAFARI_CONFIG, REG; \
153 srlx REG, 17, REG; \
154 and REG, 0x3ff, REG; \
155 nop; \
156 /* Cheetah JBUS implementation. */ \
157 ldxa [%g0] ASI_JBUS_CONFIG, REG; \
158 srlx REG, 17, REG; \
159 and REG, 0x1f, REG; \
160 nop; \
161 /* Starfire implementation. */ \
162 sethi %hi(0x1fff40000d0 >> 9), REG; \
163 sllx REG, 9, REG; \
164 or REG, 0xd0, REG; \
165 lduwa [REG] ASI_PHYS_BYPASS_EC_E, REG;\
166 /* sun4v implementation. */ \
167 mov SCRATCHPAD_CPUID, REG; \
168 ldxa [REG] ASI_SCRATCHPAD, REG; \
169 nop; \
170 nop; \
171 .previous;
172
173#ifdef CONFIG_SMP
174
175#define TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
176 __GET_CPUID(TMP) \
177 sethi %hi(trap_block), DEST; \
178 sllx TMP, TRAP_BLOCK_SZ_SHIFT, TMP; \
179 or DEST, %lo(trap_block), DEST; \
180 add DEST, TMP, DEST; \
181
182/* Clobbers TMP, current address space PGD phys address into DEST. */
183#define TRAP_LOAD_PGD_PHYS(DEST, TMP) \
184 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
185 ldx [DEST + TRAP_PER_CPU_PGD_PADDR], DEST;
186
187/* Clobbers TMP, loads local processor's IRQ work area into DEST. */
188#define TRAP_LOAD_IRQ_WORK_PA(DEST, TMP) \
189 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
190 add DEST, TRAP_PER_CPU_IRQ_WORKLIST_PA, DEST;
191
192/* Clobbers TMP, loads DEST with current thread info pointer. */
193#define TRAP_LOAD_THREAD_REG(DEST, TMP) \
194 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
195 ldx [DEST + TRAP_PER_CPU_THREAD], DEST;
196
197/* Given the current thread info pointer in THR, load the per-cpu
198 * area base of the current processor into DEST. REG1, REG2, and REG3 are
199 * clobbered.
200 *
201 * You absolutely cannot use DEST as a temporary in this code. The
202 * reason is that traps can happen during execution, and return from
203 * trap will load the fully resolved DEST per-cpu base. This can corrupt
204 * the calculations done by the macro mid-stream.
205 */
206#define LOAD_PER_CPU_BASE(DEST, THR, REG1, REG2, REG3) \
207 lduh [THR + TI_CPU], REG1; \
208 sethi %hi(__per_cpu_shift), REG3; \
209 sethi %hi(__per_cpu_base), REG2; \
210 ldx [REG3 + %lo(__per_cpu_shift)], REG3; \
211 ldx [REG2 + %lo(__per_cpu_base)], REG2; \
212 sllx REG1, REG3, REG3; \
213 add REG3, REG2, DEST;
214
215#else
216
217#define TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
218 sethi %hi(trap_block), DEST; \
219 or DEST, %lo(trap_block), DEST; \
220
221/* Uniprocessor versions, we know the cpuid is zero. */
222#define TRAP_LOAD_PGD_PHYS(DEST, TMP) \
223 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
224 ldx [DEST + TRAP_PER_CPU_PGD_PADDR], DEST;
225
226/* Clobbers TMP, loads local processor's IRQ work area into DEST. */
227#define TRAP_LOAD_IRQ_WORK_PA(DEST, TMP) \
228 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
229 add DEST, TRAP_PER_CPU_IRQ_WORKLIST_PA, DEST;
230
231#define TRAP_LOAD_THREAD_REG(DEST, TMP) \
232 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
233 ldx [DEST + TRAP_PER_CPU_THREAD], DEST;
234
235/* No per-cpu areas on uniprocessor, so no need to load DEST. */
236#define LOAD_PER_CPU_BASE(DEST, THR, REG1, REG2, REG3)
237
238#endif /* !(CONFIG_SMP) */
239
240#endif /* _SPARC64_CPUDATA_H */
diff --git a/include/asm-sparc/dcr.h b/include/asm-sparc/dcr.h
new file mode 100644
index 000000000000..620c9ba642e9
--- /dev/null
+++ b/include/asm-sparc/dcr.h
@@ -0,0 +1,14 @@
1#ifndef _SPARC64_DCR_H
2#define _SPARC64_DCR_H
3
4/* UltraSparc-III/III+ Dispatch Control Register, ASR 0x12 */
5#define DCR_DPE 0x0000000000001000 /* III+: D$ Parity Error Enable */
6#define DCR_OBS 0x0000000000000fc0 /* Observability Bus Controls */
7#define DCR_BPE 0x0000000000000020 /* Branch Predict Enable */
8#define DCR_RPE 0x0000000000000010 /* Return Address Prediction Enable */
9#define DCR_SI 0x0000000000000008 /* Single Instruction Disable */
10#define DCR_IPE 0x0000000000000004 /* III+: I$ Parity Error Enable */
11#define DCR_IFPOE 0x0000000000000002 /* IRQ FP Operation Enable */
12#define DCR_MS 0x0000000000000001 /* Multi-Scalar dispatch */
13
14#endif /* _SPARC64_DCR_H */
diff --git a/include/asm-sparc/dcu.h b/include/asm-sparc/dcu.h
new file mode 100644
index 000000000000..0f704e106a1b
--- /dev/null
+++ b/include/asm-sparc/dcu.h
@@ -0,0 +1,27 @@
1#ifndef _SPARC64_DCU_H
2#define _SPARC64_DCU_H
3
4#include <linux/const.h>
5
6/* UltraSparc-III Data Cache Unit Control Register */
7#define DCU_CP _AC(0x0002000000000000,UL) /* Phys Cache Enable w/o mmu */
8#define DCU_CV _AC(0x0001000000000000,UL) /* Virt Cache Enable w/o mmu */
9#define DCU_ME _AC(0x0000800000000000,UL) /* NC-store Merging Enable */
10#define DCU_RE _AC(0x0000400000000000,UL) /* RAW bypass Enable */
11#define DCU_PE _AC(0x0000200000000000,UL) /* PCache Enable */
12#define DCU_HPE _AC(0x0000100000000000,UL) /* HW prefetch Enable */
13#define DCU_SPE _AC(0x0000080000000000,UL) /* SW prefetch Enable */
14#define DCU_SL _AC(0x0000040000000000,UL) /* Secondary ld-steering Enab*/
15#define DCU_WE _AC(0x0000020000000000,UL) /* WCache enable */
16#define DCU_PM _AC(0x000001fe00000000,UL) /* PA Watchpoint Byte Mask */
17#define DCU_VM _AC(0x00000001fe000000,UL) /* VA Watchpoint Byte Mask */
18#define DCU_PR _AC(0x0000000001000000,UL) /* PA Watchpoint Read Enable */
19#define DCU_PW _AC(0x0000000000800000,UL) /* PA Watchpoint Write Enable*/
20#define DCU_VR _AC(0x0000000000400000,UL) /* VA Watchpoint Read Enable */
21#define DCU_VW _AC(0x0000000000200000,UL) /* VA Watchpoint Write Enable*/
22#define DCU_DM _AC(0x0000000000000008,UL) /* DMMU Enable */
23#define DCU_IM _AC(0x0000000000000004,UL) /* IMMU Enable */
24#define DCU_DC _AC(0x0000000000000002,UL) /* Data Cache Enable */
25#define DCU_IC _AC(0x0000000000000001,UL) /* Instruction Cache Enable */
26
27#endif /* _SPARC64_DCU_H */
diff --git a/include/asm-sparc/delay.h b/include/asm-sparc/delay.h
index bc9aba2bead6..6210a3ce9751 100644
--- a/include/asm-sparc/delay.h
+++ b/include/asm-sparc/delay.h
@@ -1,34 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_DELAY_H
2 * delay.h: Linux delay routines on the Sparc. 2#define ___ASM_SPARC_DELAY_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 1994 David S. Miller (davem@caip.rutgers.edu). 4#include <asm-sparc/delay_64.h>
5 */ 5#else
6 6#include <asm-sparc/delay_32.h>
7#ifndef __SPARC_DELAY_H 7#endif
8#define __SPARC_DELAY_H 8#endif
9
10#include <asm/cpudata.h>
11
12static inline void __delay(unsigned long loops)
13{
14 __asm__ __volatile__("cmp %0, 0\n\t"
15 "1: bne 1b\n\t"
16 "subcc %0, 1, %0\n" :
17 "=&r" (loops) :
18 "0" (loops) :
19 "cc");
20}
21
22/* This is too messy with inline asm on the Sparc. */
23extern void __udelay(unsigned long usecs, unsigned long lpj);
24extern void __ndelay(unsigned long nsecs, unsigned long lpj);
25
26#ifdef CONFIG_SMP
27#define __udelay_val cpu_data(smp_processor_id()).udelay_val
28#else /* SMP */
29#define __udelay_val loops_per_jiffy
30#endif /* SMP */
31#define udelay(__usecs) __udelay(__usecs, __udelay_val)
32#define ndelay(__nsecs) __ndelay(__nsecs, __udelay_val)
33
34#endif /* defined(__SPARC_DELAY_H) */
diff --git a/include/asm-sparc/delay_32.h b/include/asm-sparc/delay_32.h
new file mode 100644
index 000000000000..bc9aba2bead6
--- /dev/null
+++ b/include/asm-sparc/delay_32.h
@@ -0,0 +1,34 @@
1/*
2 * delay.h: Linux delay routines on the Sparc.
3 *
4 * Copyright (C) 1994 David S. Miller (davem@caip.rutgers.edu).
5 */
6
7#ifndef __SPARC_DELAY_H
8#define __SPARC_DELAY_H
9
10#include <asm/cpudata.h>
11
12static inline void __delay(unsigned long loops)
13{
14 __asm__ __volatile__("cmp %0, 0\n\t"
15 "1: bne 1b\n\t"
16 "subcc %0, 1, %0\n" :
17 "=&r" (loops) :
18 "0" (loops) :
19 "cc");
20}
21
22/* This is too messy with inline asm on the Sparc. */
23extern void __udelay(unsigned long usecs, unsigned long lpj);
24extern void __ndelay(unsigned long nsecs, unsigned long lpj);
25
26#ifdef CONFIG_SMP
27#define __udelay_val cpu_data(smp_processor_id()).udelay_val
28#else /* SMP */
29#define __udelay_val loops_per_jiffy
30#endif /* SMP */
31#define udelay(__usecs) __udelay(__usecs, __udelay_val)
32#define ndelay(__nsecs) __ndelay(__nsecs, __udelay_val)
33
34#endif /* defined(__SPARC_DELAY_H) */
diff --git a/include/asm-sparc/delay_64.h b/include/asm-sparc/delay_64.h
new file mode 100644
index 000000000000..a77aa622d762
--- /dev/null
+++ b/include/asm-sparc/delay_64.h
@@ -0,0 +1,17 @@
1/* delay.h: Linux delay routines on sparc64.
2 *
3 * Copyright (C) 1996, 2004, 2007 David S. Miller (davem@davemloft.net).
4 */
5
6#ifndef _SPARC64_DELAY_H
7#define _SPARC64_DELAY_H
8
9#ifndef __ASSEMBLY__
10
11extern void __delay(unsigned long loops);
12extern void udelay(unsigned long usecs);
13#define mdelay(n) udelay((n) * 1000)
14
15#endif /* !__ASSEMBLY__ */
16
17#endif /* _SPARC64_DELAY_H */
diff --git a/include/asm-sparc/display7seg.h b/include/asm-sparc/display7seg.h
new file mode 100644
index 000000000000..86d4a901df24
--- /dev/null
+++ b/include/asm-sparc/display7seg.h
@@ -0,0 +1,79 @@
1/*
2 *
3 * display7seg - Driver interface for the 7-segment display
4 * present on Sun Microsystems CP1400 and CP1500
5 *
6 * Copyright (c) 2000 Eric Brower <ebrower@usa.net>
7 *
8 */
9
10#ifndef __display7seg_h__
11#define __display7seg_h__
12
13#define D7S_IOC 'p'
14
15#define D7SIOCRD _IOR(D7S_IOC, 0x45, int) /* Read device state */
16#define D7SIOCWR _IOW(D7S_IOC, 0x46, int) /* Write device state */
17#define D7SIOCTM _IO (D7S_IOC, 0x47) /* Translate mode (FLIP)*/
18
19/*
20 * ioctl flag definitions
21 *
22 * POINT - Toggle decimal point (0=absent 1=present)
23 * ALARM - Toggle alarm LED (0=green 1=red)
24 * FLIP - Toggle inverted mode (0=normal 1=flipped)
25 * bits 0-4 - Character displayed (see definitions below)
26 *
27 * Display segments are defined as follows,
28 * subject to D7S_FLIP register state:
29 *
30 * a
31 * ---
32 * f| |b
33 * -g-
34 * e| |c
35 * ---
36 * d
37 */
38
39#define D7S_POINT (1 << 7) /* Decimal point*/
40#define D7S_ALARM (1 << 6) /* Alarm LED */
41#define D7S_FLIP (1 << 5) /* Flip display */
42
43#define D7S_0 0x00 /* Numerals 0-9 */
44#define D7S_1 0x01
45#define D7S_2 0x02
46#define D7S_3 0x03
47#define D7S_4 0x04
48#define D7S_5 0x05
49#define D7S_6 0x06
50#define D7S_7 0x07
51#define D7S_8 0x08
52#define D7S_9 0x09
53#define D7S_A 0x0A /* Letters A-F, H, L, P */
54#define D7S_B 0x0B
55#define D7S_C 0x0C
56#define D7S_D 0x0D
57#define D7S_E 0x0E
58#define D7S_F 0x0F
59#define D7S_H 0x10
60#define D7S_E2 0x11
61#define D7S_L 0x12
62#define D7S_P 0x13
63#define D7S_SEGA 0x14 /* Individual segments */
64#define D7S_SEGB 0x15
65#define D7S_SEGC 0x16
66#define D7S_SEGD 0x17
67#define D7S_SEGE 0x18
68#define D7S_SEGF 0x19
69#define D7S_SEGG 0x1A
70#define D7S_SEGABFG 0x1B /* Segment groupings */
71#define D7S_SEGCDEG 0x1C
72#define D7S_SEGBCEF 0x1D
73#define D7S_SEGADG 0x1E
74#define D7S_BLANK 0x1F /* Clear all segments */
75
76#define D7S_MIN_VAL 0x0
77#define D7S_MAX_VAL 0x1F
78
79#endif /* ifndef __display7seg_h__ */
diff --git a/include/asm-sparc/dma-mapping.h b/include/asm-sparc/dma-mapping.h
index f3a641e6b2c8..7483504259ce 100644
--- a/include/asm-sparc/dma-mapping.h
+++ b/include/asm-sparc/dma-mapping.h
@@ -1,11 +1,8 @@
1#ifndef _ASM_SPARC_DMA_MAPPING_H 1#ifndef ___ASM_SPARC_DMA_MAPPING_H
2#define _ASM_SPARC_DMA_MAPPING_H 2#define ___ASM_SPARC_DMA_MAPPING_H
3 3#if defined(__sparc__) && defined(__arch64__)
4 4#include <asm-sparc/dma-mapping_64.h>
5#ifdef CONFIG_PCI
6#include <asm-generic/dma-mapping.h>
7#else 5#else
8#include <asm-generic/dma-mapping-broken.h> 6#include <asm-sparc/dma-mapping_32.h>
9#endif /* PCI */ 7#endif
10 8#endif
11#endif /* _ASM_SPARC_DMA_MAPPING_H */
diff --git a/include/asm-sparc/dma-mapping_32.h b/include/asm-sparc/dma-mapping_32.h
new file mode 100644
index 000000000000..f3a641e6b2c8
--- /dev/null
+++ b/include/asm-sparc/dma-mapping_32.h
@@ -0,0 +1,11 @@
1#ifndef _ASM_SPARC_DMA_MAPPING_H
2#define _ASM_SPARC_DMA_MAPPING_H
3
4
5#ifdef CONFIG_PCI
6#include <asm-generic/dma-mapping.h>
7#else
8#include <asm-generic/dma-mapping-broken.h>
9#endif /* PCI */
10
11#endif /* _ASM_SPARC_DMA_MAPPING_H */
diff --git a/include/asm-sparc/dma-mapping_64.h b/include/asm-sparc/dma-mapping_64.h
new file mode 100644
index 000000000000..38cbec76a33f
--- /dev/null
+++ b/include/asm-sparc/dma-mapping_64.h
@@ -0,0 +1,154 @@
1#ifndef _ASM_SPARC64_DMA_MAPPING_H
2#define _ASM_SPARC64_DMA_MAPPING_H
3
4#include <linux/scatterlist.h>
5#include <linux/mm.h>
6
7#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
8
9struct dma_ops {
10 void *(*alloc_coherent)(struct device *dev, size_t size,
11 dma_addr_t *dma_handle, gfp_t flag);
12 void (*free_coherent)(struct device *dev, size_t size,
13 void *cpu_addr, dma_addr_t dma_handle);
14 dma_addr_t (*map_single)(struct device *dev, void *cpu_addr,
15 size_t size,
16 enum dma_data_direction direction);
17 void (*unmap_single)(struct device *dev, dma_addr_t dma_addr,
18 size_t size,
19 enum dma_data_direction direction);
20 int (*map_sg)(struct device *dev, struct scatterlist *sg, int nents,
21 enum dma_data_direction direction);
22 void (*unmap_sg)(struct device *dev, struct scatterlist *sg,
23 int nhwentries,
24 enum dma_data_direction direction);
25 void (*sync_single_for_cpu)(struct device *dev,
26 dma_addr_t dma_handle, size_t size,
27 enum dma_data_direction direction);
28 void (*sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg,
29 int nelems,
30 enum dma_data_direction direction);
31};
32extern const struct dma_ops *dma_ops;
33
34extern int dma_supported(struct device *dev, u64 mask);
35extern int dma_set_mask(struct device *dev, u64 dma_mask);
36
37static inline void *dma_alloc_coherent(struct device *dev, size_t size,
38 dma_addr_t *dma_handle, gfp_t flag)
39{
40 return dma_ops->alloc_coherent(dev, size, dma_handle, flag);
41}
42
43static inline void dma_free_coherent(struct device *dev, size_t size,
44 void *cpu_addr, dma_addr_t dma_handle)
45{
46 dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
47}
48
49static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
50 size_t size,
51 enum dma_data_direction direction)
52{
53 return dma_ops->map_single(dev, cpu_addr, size, direction);
54}
55
56static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
57 size_t size,
58 enum dma_data_direction direction)
59{
60 dma_ops->unmap_single(dev, dma_addr, size, direction);
61}
62
63static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
64 unsigned long offset, size_t size,
65 enum dma_data_direction direction)
66{
67 return dma_ops->map_single(dev, page_address(page) + offset,
68 size, direction);
69}
70
71static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
72 size_t size,
73 enum dma_data_direction direction)
74{
75 dma_ops->unmap_single(dev, dma_address, size, direction);
76}
77
78static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
79 int nents, enum dma_data_direction direction)
80{
81 return dma_ops->map_sg(dev, sg, nents, direction);
82}
83
84static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
85 int nents, enum dma_data_direction direction)
86{
87 dma_ops->unmap_sg(dev, sg, nents, direction);
88}
89
90static inline void dma_sync_single_for_cpu(struct device *dev,
91 dma_addr_t dma_handle, size_t size,
92 enum dma_data_direction direction)
93{
94 dma_ops->sync_single_for_cpu(dev, dma_handle, size, direction);
95}
96
97static inline void dma_sync_single_for_device(struct device *dev,
98 dma_addr_t dma_handle,
99 size_t size,
100 enum dma_data_direction direction)
101{
102 /* No flushing needed to sync cpu writes to the device. */
103}
104
105static inline void dma_sync_single_range_for_cpu(struct device *dev,
106 dma_addr_t dma_handle,
107 unsigned long offset,
108 size_t size,
109 enum dma_data_direction direction)
110{
111 dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
112}
113
114static inline void dma_sync_single_range_for_device(struct device *dev,
115 dma_addr_t dma_handle,
116 unsigned long offset,
117 size_t size,
118 enum dma_data_direction direction)
119{
120 /* No flushing needed to sync cpu writes to the device. */
121}
122
123
124static inline void dma_sync_sg_for_cpu(struct device *dev,
125 struct scatterlist *sg, int nelems,
126 enum dma_data_direction direction)
127{
128 dma_ops->sync_sg_for_cpu(dev, sg, nelems, direction);
129}
130
131static inline void dma_sync_sg_for_device(struct device *dev,
132 struct scatterlist *sg, int nelems,
133 enum dma_data_direction direction)
134{
135 /* No flushing needed to sync cpu writes to the device. */
136}
137
138static inline int dma_mapping_error(dma_addr_t dma_addr)
139{
140 return (dma_addr == DMA_ERROR_CODE);
141}
142
143static inline int dma_get_cache_alignment(void)
144{
145 /* no easy way to get cache size on all processors, so return
146 * the maximum possible, to be safe */
147 return (1 << INTERNODE_CACHE_SHIFT);
148}
149
150#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
151#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
152#define dma_is_consistent(d, h) (1)
153
154#endif /* _ASM_SPARC64_DMA_MAPPING_H */
diff --git a/include/asm-sparc/dma.h b/include/asm-sparc/dma.h
index 959d6c8a71ae..8cc69bfaae2a 100644
--- a/include/asm-sparc/dma.h
+++ b/include/asm-sparc/dma.h
@@ -1,288 +1,8 @@
1/* include/asm-sparc/dma.h 1#ifndef ___ASM_SPARC_DMA_H
2 * 2#define ___ASM_SPARC_DMA_H
3 * Copyright 1995 (C) David S. Miller (davem@davemloft.net) 3#if defined(__sparc__) && defined(__arch64__)
4 */ 4#include <asm-sparc/dma_64.h>
5
6#ifndef _ASM_SPARC_DMA_H
7#define _ASM_SPARC_DMA_H
8
9#include <linux/kernel.h>
10#include <linux/types.h>
11
12#include <asm/vac-ops.h> /* for invalidate's, etc. */
13#include <asm/sbus.h>
14#include <asm/delay.h>
15#include <asm/oplib.h>
16#include <asm/system.h>
17#include <asm/io.h>
18#include <linux/spinlock.h>
19
20struct page;
21extern spinlock_t dma_spin_lock;
22
23static inline unsigned long claim_dma_lock(void)
24{
25 unsigned long flags;
26 spin_lock_irqsave(&dma_spin_lock, flags);
27 return flags;
28}
29
30static inline void release_dma_lock(unsigned long flags)
31{
32 spin_unlock_irqrestore(&dma_spin_lock, flags);
33}
34
35/* These are irrelevant for Sparc DMA, but we leave it in so that
36 * things can compile.
37 */
38#define MAX_DMA_CHANNELS 8
39#define MAX_DMA_ADDRESS (~0UL)
40#define DMA_MODE_READ 1
41#define DMA_MODE_WRITE 2
42
43/* Useful constants */
44#define SIZE_16MB (16*1024*1024)
45#define SIZE_64K (64*1024)
46
47/* SBUS DMA controller reg offsets */
48#define DMA_CSR 0x00UL /* rw DMA control/status register 0x00 */
49#define DMA_ADDR 0x04UL /* rw DMA transfer address register 0x04 */
50#define DMA_COUNT 0x08UL /* rw DMA transfer count register 0x08 */
51#define DMA_TEST 0x0cUL /* rw DMA test/debug register 0x0c */
52
53/* DVMA chip revisions */
54enum dvma_rev {
55 dvmarev0,
56 dvmaesc1,
57 dvmarev1,
58 dvmarev2,
59 dvmarev3,
60 dvmarevplus,
61 dvmahme
62};
63
64#define DMA_HASCOUNT(rev) ((rev)==dvmaesc1)
65
66/* Linux DMA information structure, filled during probe. */
67struct sbus_dma {
68 struct sbus_dma *next;
69 struct sbus_dev *sdev;
70 void __iomem *regs;
71
72 /* Status, misc info */
73 int node; /* Prom node for this DMA device */
74 int running; /* Are we doing DMA now? */
75 int allocated; /* Are we "owned" by anyone yet? */
76
77 /* Transfer information. */
78 unsigned long addr; /* Start address of current transfer */
79 int nbytes; /* Size of current transfer */
80 int realbytes; /* For splitting up large transfers, etc. */
81
82 /* DMA revision */
83 enum dvma_rev revision;
84};
85
86extern struct sbus_dma *dma_chain;
87
88/* Broken hardware... */
89#ifdef CONFIG_SUN4
90/* Have to sort this out. Does rev0 work fine on sun4[cmd] without isbroken?
91 * Or is rev0 present only on sun4 boxes? -jj */
92#define DMA_ISBROKEN(dma) ((dma)->revision == dvmarev0 || (dma)->revision == dvmarev1)
93#else 5#else
94#define DMA_ISBROKEN(dma) ((dma)->revision == dvmarev1) 6#include <asm-sparc/dma_32.h>
95#endif 7#endif
96#define DMA_ISESC1(dma) ((dma)->revision == dvmaesc1)
97
98/* Main routines in dma.c */
99extern void dvma_init(struct sbus_bus *);
100
101/* Fields in the cond_reg register */
102/* First, the version identification bits */
103#define DMA_DEVICE_ID 0xf0000000 /* Device identification bits */
104#define DMA_VERS0 0x00000000 /* Sunray DMA version */
105#define DMA_ESCV1 0x40000000 /* DMA ESC Version 1 */
106#define DMA_VERS1 0x80000000 /* DMA rev 1 */
107#define DMA_VERS2 0xa0000000 /* DMA rev 2 */
108#define DMA_VERHME 0xb0000000 /* DMA hme gate array */
109#define DMA_VERSPLUS 0x90000000 /* DMA rev 1 PLUS */
110
111#define DMA_HNDL_INTR 0x00000001 /* An IRQ needs to be handled */
112#define DMA_HNDL_ERROR 0x00000002 /* We need to take an error */
113#define DMA_FIFO_ISDRAIN 0x0000000c /* The DMA FIFO is draining */
114#define DMA_INT_ENAB 0x00000010 /* Turn on interrupts */
115#define DMA_FIFO_INV 0x00000020 /* Invalidate the FIFO */
116#define DMA_ACC_SZ_ERR 0x00000040 /* The access size was bad */
117#define DMA_FIFO_STDRAIN 0x00000040 /* DMA_VERS1 Drain the FIFO */
118#define DMA_RST_SCSI 0x00000080 /* Reset the SCSI controller */
119#define DMA_RST_ENET DMA_RST_SCSI /* Reset the ENET controller */
120#define DMA_RST_BPP DMA_RST_SCSI /* Reset the BPP controller */
121#define DMA_ST_WRITE 0x00000100 /* write from device to memory */
122#define DMA_ENABLE 0x00000200 /* Fire up DMA, handle requests */
123#define DMA_PEND_READ 0x00000400 /* DMA_VERS1/0/PLUS Pending Read */
124#define DMA_ESC_BURST 0x00000800 /* 1=16byte 0=32byte */
125#define DMA_READ_AHEAD 0x00001800 /* DMA read ahead partial longword */
126#define DMA_DSBL_RD_DRN 0x00001000 /* No EC drain on slave reads */
127#define DMA_BCNT_ENAB 0x00002000 /* If on, use the byte counter */
128#define DMA_TERM_CNTR 0x00004000 /* Terminal counter */
129#define DMA_SCSI_SBUS64 0x00008000 /* HME: Enable 64-bit SBUS mode. */
130#define DMA_CSR_DISAB 0x00010000 /* No FIFO drains during csr */
131#define DMA_SCSI_DISAB 0x00020000 /* No FIFO drains during reg */
132#define DMA_DSBL_WR_INV 0x00020000 /* No EC inval. on slave writes */
133#define DMA_ADD_ENABLE 0x00040000 /* Special ESC DVMA optimization */
134#define DMA_E_BURSTS 0x000c0000 /* ENET: SBUS r/w burst mask */
135#define DMA_E_BURST32 0x00040000 /* ENET: SBUS 32 byte r/w burst */
136#define DMA_E_BURST16 0x00000000 /* ENET: SBUS 16 byte r/w burst */
137#define DMA_BRST_SZ 0x000c0000 /* SCSI: SBUS r/w burst size */
138#define DMA_BRST64 0x00080000 /* SCSI: 64byte bursts (HME on UltraSparc only) */
139#define DMA_BRST32 0x00040000 /* SCSI/BPP: 32byte bursts */
140#define DMA_BRST16 0x00000000 /* SCSI/BPP: 16byte bursts */
141#define DMA_BRST0 0x00080000 /* SCSI: no bursts (non-HME gate arrays) */
142#define DMA_ADDR_DISAB 0x00100000 /* No FIFO drains during addr */
143#define DMA_2CLKS 0x00200000 /* Each transfer = 2 clock ticks */
144#define DMA_3CLKS 0x00400000 /* Each transfer = 3 clock ticks */
145#define DMA_EN_ENETAUI DMA_3CLKS /* Put lance into AUI-cable mode */
146#define DMA_CNTR_DISAB 0x00800000 /* No IRQ when DMA_TERM_CNTR set */
147#define DMA_AUTO_NADDR 0x01000000 /* Use "auto nxt addr" feature */
148#define DMA_SCSI_ON 0x02000000 /* Enable SCSI dma */
149#define DMA_BPP_ON DMA_SCSI_ON /* Enable BPP dma */
150#define DMA_PARITY_OFF 0x02000000 /* HME: disable parity checking */
151#define DMA_LOADED_ADDR 0x04000000 /* Address has been loaded */
152#define DMA_LOADED_NADDR 0x08000000 /* Next address has been loaded */
153#define DMA_RESET_FAS366 0x08000000 /* HME: Assert RESET to FAS366 */
154
155/* Values describing the burst-size property from the PROM */
156#define DMA_BURST1 0x01
157#define DMA_BURST2 0x02
158#define DMA_BURST4 0x04
159#define DMA_BURST8 0x08
160#define DMA_BURST16 0x10
161#define DMA_BURST32 0x20
162#define DMA_BURST64 0x40
163#define DMA_BURSTBITS 0x7f
164
165/* Determine highest possible final transfer address given a base */
166#define DMA_MAXEND(addr) (0x01000000UL-(((unsigned long)(addr))&0x00ffffffUL))
167
168/* Yes, I hack a lot of elisp in my spare time... */
169#define DMA_ERROR_P(regs) ((((regs)->cond_reg) & DMA_HNDL_ERROR))
170#define DMA_IRQ_P(regs) ((((regs)->cond_reg) & (DMA_HNDL_INTR | DMA_HNDL_ERROR)))
171#define DMA_WRITE_P(regs) ((((regs)->cond_reg) & DMA_ST_WRITE))
172#define DMA_OFF(regs) ((((regs)->cond_reg) &= (~DMA_ENABLE)))
173#define DMA_INTSOFF(regs) ((((regs)->cond_reg) &= (~DMA_INT_ENAB)))
174#define DMA_INTSON(regs) ((((regs)->cond_reg) |= (DMA_INT_ENAB)))
175#define DMA_PUNTFIFO(regs) ((((regs)->cond_reg) |= DMA_FIFO_INV))
176#define DMA_SETSTART(regs, addr) ((((regs)->st_addr) = (char *) addr))
177#define DMA_BEGINDMA_W(regs) \
178 ((((regs)->cond_reg |= (DMA_ST_WRITE|DMA_ENABLE|DMA_INT_ENAB))))
179#define DMA_BEGINDMA_R(regs) \
180 ((((regs)->cond_reg |= ((DMA_ENABLE|DMA_INT_ENAB)&(~DMA_ST_WRITE)))))
181
182/* For certain DMA chips, we need to disable ints upon irq entry
183 * and turn them back on when we are done. So in any ESP interrupt
184 * handler you *must* call DMA_IRQ_ENTRY upon entry and DMA_IRQ_EXIT
185 * when leaving the handler. You have been warned...
186 */
187#define DMA_IRQ_ENTRY(dma, dregs) do { \
188 if(DMA_ISBROKEN(dma)) DMA_INTSOFF(dregs); \
189 } while (0)
190
191#define DMA_IRQ_EXIT(dma, dregs) do { \
192 if(DMA_ISBROKEN(dma)) DMA_INTSON(dregs); \
193 } while(0)
194
195#if 0 /* P3 this stuff is inline in ledma.c:init_restart_ledma() */
196/* Pause until counter runs out or BIT isn't set in the DMA condition
197 * register.
198 */
199static inline void sparc_dma_pause(struct sparc_dma_registers *regs,
200 unsigned long bit)
201{
202 int ctr = 50000; /* Let's find some bugs ;) */
203
204 /* Busy wait until the bit is not set any more */
205 while((regs->cond_reg&bit) && (ctr>0)) {
206 ctr--;
207 __delay(5);
208 }
209
210 /* Check for bogus outcome. */
211 if(!ctr)
212 panic("DMA timeout");
213}
214
215/* Reset the friggin' thing... */
216#define DMA_RESET(dma) do { \
217 struct sparc_dma_registers *regs = dma->regs; \
218 /* Let the current FIFO drain itself */ \
219 sparc_dma_pause(regs, (DMA_FIFO_ISDRAIN)); \
220 /* Reset the logic */ \
221 regs->cond_reg |= (DMA_RST_SCSI); /* assert */ \
222 __delay(400); /* let the bits set ;) */ \
223 regs->cond_reg &= ~(DMA_RST_SCSI); /* de-assert */ \
224 sparc_dma_enable_interrupts(regs); /* Re-enable interrupts */ \
225 /* Enable FAST transfers if available */ \
226 if(dma->revision>dvmarev1) regs->cond_reg |= DMA_3CLKS; \
227 dma->running = 0; \
228} while(0)
229#endif 8#endif
230
231#define for_each_dvma(dma) \
232 for((dma) = dma_chain; (dma); (dma) = (dma)->next)
233
234extern int get_dma_list(char *);
235extern int request_dma(unsigned int, __const__ char *);
236extern void free_dma(unsigned int);
237
238/* From PCI */
239
240#ifdef CONFIG_PCI
241extern int isa_dma_bridge_buggy;
242#else
243#define isa_dma_bridge_buggy (0)
244#endif
245
246/* Routines for data transfer buffers. */
247BTFIXUPDEF_CALL(char *, mmu_lockarea, char *, unsigned long)
248BTFIXUPDEF_CALL(void, mmu_unlockarea, char *, unsigned long)
249
250#define mmu_lockarea(vaddr,len) BTFIXUP_CALL(mmu_lockarea)(vaddr,len)
251#define mmu_unlockarea(vaddr,len) BTFIXUP_CALL(mmu_unlockarea)(vaddr,len)
252
253/* These are implementations for sbus_map_sg/sbus_unmap_sg... collapse later */
254BTFIXUPDEF_CALL(__u32, mmu_get_scsi_one, char *, unsigned long, struct sbus_bus *sbus)
255BTFIXUPDEF_CALL(void, mmu_get_scsi_sgl, struct scatterlist *, int, struct sbus_bus *sbus)
256BTFIXUPDEF_CALL(void, mmu_release_scsi_one, __u32, unsigned long, struct sbus_bus *sbus)
257BTFIXUPDEF_CALL(void, mmu_release_scsi_sgl, struct scatterlist *, int, struct sbus_bus *sbus)
258
259#define mmu_get_scsi_one(vaddr,len,sbus) BTFIXUP_CALL(mmu_get_scsi_one)(vaddr,len,sbus)
260#define mmu_get_scsi_sgl(sg,sz,sbus) BTFIXUP_CALL(mmu_get_scsi_sgl)(sg,sz,sbus)
261#define mmu_release_scsi_one(vaddr,len,sbus) BTFIXUP_CALL(mmu_release_scsi_one)(vaddr,len,sbus)
262#define mmu_release_scsi_sgl(sg,sz,sbus) BTFIXUP_CALL(mmu_release_scsi_sgl)(sg,sz,sbus)
263
264/*
265 * mmu_map/unmap are provided by iommu/iounit; Invalid to call on IIep.
266 *
267 * The mmu_map_dma_area establishes two mappings in one go.
268 * These mappings point to pages normally mapped at 'va' (linear address).
269 * First mapping is for CPU visible address at 'a', uncached.
270 * This is an alias, but it works because it is an uncached mapping.
271 * Second mapping is for device visible address, or "bus" address.
272 * The bus address is returned at '*pba'.
273 *
274 * These functions seem distinct, but are hard to split. On sun4c,
275 * at least for now, 'a' is equal to bus address, and retured in *pba.
276 * On sun4m, page attributes depend on the CPU type, so we have to
277 * know if we are mapping RAM or I/O, so it has to be an additional argument
278 * to a separate mapping function for CPU visible mappings.
279 */
280BTFIXUPDEF_CALL(int, mmu_map_dma_area, dma_addr_t *, unsigned long, unsigned long, int len)
281BTFIXUPDEF_CALL(struct page *, mmu_translate_dvma, unsigned long busa)
282BTFIXUPDEF_CALL(void, mmu_unmap_dma_area, unsigned long busa, int len)
283
284#define mmu_map_dma_area(pba,va,a,len) BTFIXUP_CALL(mmu_map_dma_area)(pba,va,a,len)
285#define mmu_unmap_dma_area(ba,len) BTFIXUP_CALL(mmu_unmap_dma_area)(ba,len)
286#define mmu_translate_dvma(ba) BTFIXUP_CALL(mmu_translate_dvma)(ba)
287
288#endif /* !(_ASM_SPARC_DMA_H) */
diff --git a/include/asm-sparc/dma_32.h b/include/asm-sparc/dma_32.h
new file mode 100644
index 000000000000..959d6c8a71ae
--- /dev/null
+++ b/include/asm-sparc/dma_32.h
@@ -0,0 +1,288 @@
1/* include/asm-sparc/dma.h
2 *
3 * Copyright 1995 (C) David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _ASM_SPARC_DMA_H
7#define _ASM_SPARC_DMA_H
8
9#include <linux/kernel.h>
10#include <linux/types.h>
11
12#include <asm/vac-ops.h> /* for invalidate's, etc. */
13#include <asm/sbus.h>
14#include <asm/delay.h>
15#include <asm/oplib.h>
16#include <asm/system.h>
17#include <asm/io.h>
18#include <linux/spinlock.h>
19
20struct page;
21extern spinlock_t dma_spin_lock;
22
23static inline unsigned long claim_dma_lock(void)
24{
25 unsigned long flags;
26 spin_lock_irqsave(&dma_spin_lock, flags);
27 return flags;
28}
29
30static inline void release_dma_lock(unsigned long flags)
31{
32 spin_unlock_irqrestore(&dma_spin_lock, flags);
33}
34
35/* These are irrelevant for Sparc DMA, but we leave it in so that
36 * things can compile.
37 */
38#define MAX_DMA_CHANNELS 8
39#define MAX_DMA_ADDRESS (~0UL)
40#define DMA_MODE_READ 1
41#define DMA_MODE_WRITE 2
42
43/* Useful constants */
44#define SIZE_16MB (16*1024*1024)
45#define SIZE_64K (64*1024)
46
47/* SBUS DMA controller reg offsets */
48#define DMA_CSR 0x00UL /* rw DMA control/status register 0x00 */
49#define DMA_ADDR 0x04UL /* rw DMA transfer address register 0x04 */
50#define DMA_COUNT 0x08UL /* rw DMA transfer count register 0x08 */
51#define DMA_TEST 0x0cUL /* rw DMA test/debug register 0x0c */
52
53/* DVMA chip revisions */
54enum dvma_rev {
55 dvmarev0,
56 dvmaesc1,
57 dvmarev1,
58 dvmarev2,
59 dvmarev3,
60 dvmarevplus,
61 dvmahme
62};
63
64#define DMA_HASCOUNT(rev) ((rev)==dvmaesc1)
65
66/* Linux DMA information structure, filled during probe. */
67struct sbus_dma {
68 struct sbus_dma *next;
69 struct sbus_dev *sdev;
70 void __iomem *regs;
71
72 /* Status, misc info */
73 int node; /* Prom node for this DMA device */
74 int running; /* Are we doing DMA now? */
75 int allocated; /* Are we "owned" by anyone yet? */
76
77 /* Transfer information. */
78 unsigned long addr; /* Start address of current transfer */
79 int nbytes; /* Size of current transfer */
80 int realbytes; /* For splitting up large transfers, etc. */
81
82 /* DMA revision */
83 enum dvma_rev revision;
84};
85
86extern struct sbus_dma *dma_chain;
87
88/* Broken hardware... */
89#ifdef CONFIG_SUN4
90/* Have to sort this out. Does rev0 work fine on sun4[cmd] without isbroken?
91 * Or is rev0 present only on sun4 boxes? -jj */
92#define DMA_ISBROKEN(dma) ((dma)->revision == dvmarev0 || (dma)->revision == dvmarev1)
93#else
94#define DMA_ISBROKEN(dma) ((dma)->revision == dvmarev1)
95#endif
96#define DMA_ISESC1(dma) ((dma)->revision == dvmaesc1)
97
98/* Main routines in dma.c */
99extern void dvma_init(struct sbus_bus *);
100
101/* Fields in the cond_reg register */
102/* First, the version identification bits */
103#define DMA_DEVICE_ID 0xf0000000 /* Device identification bits */
104#define DMA_VERS0 0x00000000 /* Sunray DMA version */
105#define DMA_ESCV1 0x40000000 /* DMA ESC Version 1 */
106#define DMA_VERS1 0x80000000 /* DMA rev 1 */
107#define DMA_VERS2 0xa0000000 /* DMA rev 2 */
108#define DMA_VERHME 0xb0000000 /* DMA hme gate array */
109#define DMA_VERSPLUS 0x90000000 /* DMA rev 1 PLUS */
110
111#define DMA_HNDL_INTR 0x00000001 /* An IRQ needs to be handled */
112#define DMA_HNDL_ERROR 0x00000002 /* We need to take an error */
113#define DMA_FIFO_ISDRAIN 0x0000000c /* The DMA FIFO is draining */
114#define DMA_INT_ENAB 0x00000010 /* Turn on interrupts */
115#define DMA_FIFO_INV 0x00000020 /* Invalidate the FIFO */
116#define DMA_ACC_SZ_ERR 0x00000040 /* The access size was bad */
117#define DMA_FIFO_STDRAIN 0x00000040 /* DMA_VERS1 Drain the FIFO */
118#define DMA_RST_SCSI 0x00000080 /* Reset the SCSI controller */
119#define DMA_RST_ENET DMA_RST_SCSI /* Reset the ENET controller */
120#define DMA_RST_BPP DMA_RST_SCSI /* Reset the BPP controller */
121#define DMA_ST_WRITE 0x00000100 /* write from device to memory */
122#define DMA_ENABLE 0x00000200 /* Fire up DMA, handle requests */
123#define DMA_PEND_READ 0x00000400 /* DMA_VERS1/0/PLUS Pending Read */
124#define DMA_ESC_BURST 0x00000800 /* 1=16byte 0=32byte */
125#define DMA_READ_AHEAD 0x00001800 /* DMA read ahead partial longword */
126#define DMA_DSBL_RD_DRN 0x00001000 /* No EC drain on slave reads */
127#define DMA_BCNT_ENAB 0x00002000 /* If on, use the byte counter */
128#define DMA_TERM_CNTR 0x00004000 /* Terminal counter */
129#define DMA_SCSI_SBUS64 0x00008000 /* HME: Enable 64-bit SBUS mode. */
130#define DMA_CSR_DISAB 0x00010000 /* No FIFO drains during csr */
131#define DMA_SCSI_DISAB 0x00020000 /* No FIFO drains during reg */
132#define DMA_DSBL_WR_INV 0x00020000 /* No EC inval. on slave writes */
133#define DMA_ADD_ENABLE 0x00040000 /* Special ESC DVMA optimization */
134#define DMA_E_BURSTS 0x000c0000 /* ENET: SBUS r/w burst mask */
135#define DMA_E_BURST32 0x00040000 /* ENET: SBUS 32 byte r/w burst */
136#define DMA_E_BURST16 0x00000000 /* ENET: SBUS 16 byte r/w burst */
137#define DMA_BRST_SZ 0x000c0000 /* SCSI: SBUS r/w burst size */
138#define DMA_BRST64 0x00080000 /* SCSI: 64byte bursts (HME on UltraSparc only) */
139#define DMA_BRST32 0x00040000 /* SCSI/BPP: 32byte bursts */
140#define DMA_BRST16 0x00000000 /* SCSI/BPP: 16byte bursts */
141#define DMA_BRST0 0x00080000 /* SCSI: no bursts (non-HME gate arrays) */
142#define DMA_ADDR_DISAB 0x00100000 /* No FIFO drains during addr */
143#define DMA_2CLKS 0x00200000 /* Each transfer = 2 clock ticks */
144#define DMA_3CLKS 0x00400000 /* Each transfer = 3 clock ticks */
145#define DMA_EN_ENETAUI DMA_3CLKS /* Put lance into AUI-cable mode */
146#define DMA_CNTR_DISAB 0x00800000 /* No IRQ when DMA_TERM_CNTR set */
147#define DMA_AUTO_NADDR 0x01000000 /* Use "auto nxt addr" feature */
148#define DMA_SCSI_ON 0x02000000 /* Enable SCSI dma */
149#define DMA_BPP_ON DMA_SCSI_ON /* Enable BPP dma */
150#define DMA_PARITY_OFF 0x02000000 /* HME: disable parity checking */
151#define DMA_LOADED_ADDR 0x04000000 /* Address has been loaded */
152#define DMA_LOADED_NADDR 0x08000000 /* Next address has been loaded */
153#define DMA_RESET_FAS366 0x08000000 /* HME: Assert RESET to FAS366 */
154
155/* Values describing the burst-size property from the PROM */
156#define DMA_BURST1 0x01
157#define DMA_BURST2 0x02
158#define DMA_BURST4 0x04
159#define DMA_BURST8 0x08
160#define DMA_BURST16 0x10
161#define DMA_BURST32 0x20
162#define DMA_BURST64 0x40
163#define DMA_BURSTBITS 0x7f
164
165/* Determine highest possible final transfer address given a base */
166#define DMA_MAXEND(addr) (0x01000000UL-(((unsigned long)(addr))&0x00ffffffUL))
167
168/* Yes, I hack a lot of elisp in my spare time... */
169#define DMA_ERROR_P(regs) ((((regs)->cond_reg) & DMA_HNDL_ERROR))
170#define DMA_IRQ_P(regs) ((((regs)->cond_reg) & (DMA_HNDL_INTR | DMA_HNDL_ERROR)))
171#define DMA_WRITE_P(regs) ((((regs)->cond_reg) & DMA_ST_WRITE))
172#define DMA_OFF(regs) ((((regs)->cond_reg) &= (~DMA_ENABLE)))
173#define DMA_INTSOFF(regs) ((((regs)->cond_reg) &= (~DMA_INT_ENAB)))
174#define DMA_INTSON(regs) ((((regs)->cond_reg) |= (DMA_INT_ENAB)))
175#define DMA_PUNTFIFO(regs) ((((regs)->cond_reg) |= DMA_FIFO_INV))
176#define DMA_SETSTART(regs, addr) ((((regs)->st_addr) = (char *) addr))
177#define DMA_BEGINDMA_W(regs) \
178 ((((regs)->cond_reg |= (DMA_ST_WRITE|DMA_ENABLE|DMA_INT_ENAB))))
179#define DMA_BEGINDMA_R(regs) \
180 ((((regs)->cond_reg |= ((DMA_ENABLE|DMA_INT_ENAB)&(~DMA_ST_WRITE)))))
181
182/* For certain DMA chips, we need to disable ints upon irq entry
183 * and turn them back on when we are done. So in any ESP interrupt
184 * handler you *must* call DMA_IRQ_ENTRY upon entry and DMA_IRQ_EXIT
185 * when leaving the handler. You have been warned...
186 */
187#define DMA_IRQ_ENTRY(dma, dregs) do { \
188 if(DMA_ISBROKEN(dma)) DMA_INTSOFF(dregs); \
189 } while (0)
190
191#define DMA_IRQ_EXIT(dma, dregs) do { \
192 if(DMA_ISBROKEN(dma)) DMA_INTSON(dregs); \
193 } while(0)
194
195#if 0 /* P3 this stuff is inline in ledma.c:init_restart_ledma() */
196/* Pause until counter runs out or BIT isn't set in the DMA condition
197 * register.
198 */
199static inline void sparc_dma_pause(struct sparc_dma_registers *regs,
200 unsigned long bit)
201{
202 int ctr = 50000; /* Let's find some bugs ;) */
203
204 /* Busy wait until the bit is not set any more */
205 while((regs->cond_reg&bit) && (ctr>0)) {
206 ctr--;
207 __delay(5);
208 }
209
210 /* Check for bogus outcome. */
211 if(!ctr)
212 panic("DMA timeout");
213}
214
215/* Reset the friggin' thing... */
216#define DMA_RESET(dma) do { \
217 struct sparc_dma_registers *regs = dma->regs; \
218 /* Let the current FIFO drain itself */ \
219 sparc_dma_pause(regs, (DMA_FIFO_ISDRAIN)); \
220 /* Reset the logic */ \
221 regs->cond_reg |= (DMA_RST_SCSI); /* assert */ \
222 __delay(400); /* let the bits set ;) */ \
223 regs->cond_reg &= ~(DMA_RST_SCSI); /* de-assert */ \
224 sparc_dma_enable_interrupts(regs); /* Re-enable interrupts */ \
225 /* Enable FAST transfers if available */ \
226 if(dma->revision>dvmarev1) regs->cond_reg |= DMA_3CLKS; \
227 dma->running = 0; \
228} while(0)
229#endif
230
231#define for_each_dvma(dma) \
232 for((dma) = dma_chain; (dma); (dma) = (dma)->next)
233
234extern int get_dma_list(char *);
235extern int request_dma(unsigned int, __const__ char *);
236extern void free_dma(unsigned int);
237
238/* From PCI */
239
240#ifdef CONFIG_PCI
241extern int isa_dma_bridge_buggy;
242#else
243#define isa_dma_bridge_buggy (0)
244#endif
245
246/* Routines for data transfer buffers. */
247BTFIXUPDEF_CALL(char *, mmu_lockarea, char *, unsigned long)
248BTFIXUPDEF_CALL(void, mmu_unlockarea, char *, unsigned long)
249
250#define mmu_lockarea(vaddr,len) BTFIXUP_CALL(mmu_lockarea)(vaddr,len)
251#define mmu_unlockarea(vaddr,len) BTFIXUP_CALL(mmu_unlockarea)(vaddr,len)
252
253/* These are implementations for sbus_map_sg/sbus_unmap_sg... collapse later */
254BTFIXUPDEF_CALL(__u32, mmu_get_scsi_one, char *, unsigned long, struct sbus_bus *sbus)
255BTFIXUPDEF_CALL(void, mmu_get_scsi_sgl, struct scatterlist *, int, struct sbus_bus *sbus)
256BTFIXUPDEF_CALL(void, mmu_release_scsi_one, __u32, unsigned long, struct sbus_bus *sbus)
257BTFIXUPDEF_CALL(void, mmu_release_scsi_sgl, struct scatterlist *, int, struct sbus_bus *sbus)
258
259#define mmu_get_scsi_one(vaddr,len,sbus) BTFIXUP_CALL(mmu_get_scsi_one)(vaddr,len,sbus)
260#define mmu_get_scsi_sgl(sg,sz,sbus) BTFIXUP_CALL(mmu_get_scsi_sgl)(sg,sz,sbus)
261#define mmu_release_scsi_one(vaddr,len,sbus) BTFIXUP_CALL(mmu_release_scsi_one)(vaddr,len,sbus)
262#define mmu_release_scsi_sgl(sg,sz,sbus) BTFIXUP_CALL(mmu_release_scsi_sgl)(sg,sz,sbus)
263
264/*
265 * mmu_map/unmap are provided by iommu/iounit; Invalid to call on IIep.
266 *
267 * The mmu_map_dma_area establishes two mappings in one go.
268 * These mappings point to pages normally mapped at 'va' (linear address).
269 * First mapping is for CPU visible address at 'a', uncached.
270 * This is an alias, but it works because it is an uncached mapping.
271 * Second mapping is for device visible address, or "bus" address.
272 * The bus address is returned at '*pba'.
273 *
274 * These functions seem distinct, but are hard to split. On sun4c,
275 * at least for now, 'a' is equal to bus address, and retured in *pba.
276 * On sun4m, page attributes depend on the CPU type, so we have to
277 * know if we are mapping RAM or I/O, so it has to be an additional argument
278 * to a separate mapping function for CPU visible mappings.
279 */
280BTFIXUPDEF_CALL(int, mmu_map_dma_area, dma_addr_t *, unsigned long, unsigned long, int len)
281BTFIXUPDEF_CALL(struct page *, mmu_translate_dvma, unsigned long busa)
282BTFIXUPDEF_CALL(void, mmu_unmap_dma_area, unsigned long busa, int len)
283
284#define mmu_map_dma_area(pba,va,a,len) BTFIXUP_CALL(mmu_map_dma_area)(pba,va,a,len)
285#define mmu_unmap_dma_area(ba,len) BTFIXUP_CALL(mmu_unmap_dma_area)(ba,len)
286#define mmu_translate_dvma(ba) BTFIXUP_CALL(mmu_translate_dvma)(ba)
287
288#endif /* !(_ASM_SPARC_DMA_H) */
diff --git a/include/asm-sparc/dma_64.h b/include/asm-sparc/dma_64.h
new file mode 100644
index 000000000000..9d4c024bd3b3
--- /dev/null
+++ b/include/asm-sparc/dma_64.h
@@ -0,0 +1,205 @@
1/*
2 * include/asm-sparc64/dma.h
3 *
4 * Copyright 1996 (C) David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef _ASM_SPARC64_DMA_H
8#define _ASM_SPARC64_DMA_H
9
10#include <linux/kernel.h>
11#include <linux/types.h>
12#include <linux/spinlock.h>
13
14#include <asm/sbus.h>
15#include <asm/delay.h>
16#include <asm/oplib.h>
17
18/* These are irrelevant for Sparc DMA, but we leave it in so that
19 * things can compile.
20 */
21#define MAX_DMA_CHANNELS 8
22#define DMA_MODE_READ 1
23#define DMA_MODE_WRITE 2
24#define MAX_DMA_ADDRESS (~0UL)
25
26/* Useful constants */
27#define SIZE_16MB (16*1024*1024)
28#define SIZE_64K (64*1024)
29
30/* SBUS DMA controller reg offsets */
31#define DMA_CSR 0x00UL /* rw DMA control/status register 0x00 */
32#define DMA_ADDR 0x04UL /* rw DMA transfer address register 0x04 */
33#define DMA_COUNT 0x08UL /* rw DMA transfer count register 0x08 */
34#define DMA_TEST 0x0cUL /* rw DMA test/debug register 0x0c */
35
36/* DVMA chip revisions */
37enum dvma_rev {
38 dvmarev0,
39 dvmaesc1,
40 dvmarev1,
41 dvmarev2,
42 dvmarev3,
43 dvmarevplus,
44 dvmahme
45};
46
47#define DMA_HASCOUNT(rev) ((rev)==dvmaesc1)
48
49/* Linux DMA information structure, filled during probe. */
50struct sbus_dma {
51 struct sbus_dma *next;
52 struct sbus_dev *sdev;
53 void __iomem *regs;
54
55 /* Status, misc info */
56 int node; /* Prom node for this DMA device */
57 int running; /* Are we doing DMA now? */
58 int allocated; /* Are we "owned" by anyone yet? */
59
60 /* Transfer information. */
61 u32 addr; /* Start address of current transfer */
62 int nbytes; /* Size of current transfer */
63 int realbytes; /* For splitting up large transfers, etc. */
64
65 /* DMA revision */
66 enum dvma_rev revision;
67};
68
69extern struct sbus_dma *dma_chain;
70
71/* Broken hardware... */
72#define DMA_ISBROKEN(dma) ((dma)->revision == dvmarev1)
73#define DMA_ISESC1(dma) ((dma)->revision == dvmaesc1)
74
75/* Main routines in dma.c */
76extern void dvma_init(struct sbus_bus *);
77
78/* Fields in the cond_reg register */
79/* First, the version identification bits */
80#define DMA_DEVICE_ID 0xf0000000 /* Device identification bits */
81#define DMA_VERS0 0x00000000 /* Sunray DMA version */
82#define DMA_ESCV1 0x40000000 /* DMA ESC Version 1 */
83#define DMA_VERS1 0x80000000 /* DMA rev 1 */
84#define DMA_VERS2 0xa0000000 /* DMA rev 2 */
85#define DMA_VERHME 0xb0000000 /* DMA hme gate array */
86#define DMA_VERSPLUS 0x90000000 /* DMA rev 1 PLUS */
87
88#define DMA_HNDL_INTR 0x00000001 /* An IRQ needs to be handled */
89#define DMA_HNDL_ERROR 0x00000002 /* We need to take an error */
90#define DMA_FIFO_ISDRAIN 0x0000000c /* The DMA FIFO is draining */
91#define DMA_INT_ENAB 0x00000010 /* Turn on interrupts */
92#define DMA_FIFO_INV 0x00000020 /* Invalidate the FIFO */
93#define DMA_ACC_SZ_ERR 0x00000040 /* The access size was bad */
94#define DMA_FIFO_STDRAIN 0x00000040 /* DMA_VERS1 Drain the FIFO */
95#define DMA_RST_SCSI 0x00000080 /* Reset the SCSI controller */
96#define DMA_RST_ENET DMA_RST_SCSI /* Reset the ENET controller */
97#define DMA_ST_WRITE 0x00000100 /* write from device to memory */
98#define DMA_ENABLE 0x00000200 /* Fire up DMA, handle requests */
99#define DMA_PEND_READ 0x00000400 /* DMA_VERS1/0/PLUS Pending Read */
100#define DMA_ESC_BURST 0x00000800 /* 1=16byte 0=32byte */
101#define DMA_READ_AHEAD 0x00001800 /* DMA read ahead partial longword */
102#define DMA_DSBL_RD_DRN 0x00001000 /* No EC drain on slave reads */
103#define DMA_BCNT_ENAB 0x00002000 /* If on, use the byte counter */
104#define DMA_TERM_CNTR 0x00004000 /* Terminal counter */
105#define DMA_SCSI_SBUS64 0x00008000 /* HME: Enable 64-bit SBUS mode. */
106#define DMA_CSR_DISAB 0x00010000 /* No FIFO drains during csr */
107#define DMA_SCSI_DISAB 0x00020000 /* No FIFO drains during reg */
108#define DMA_DSBL_WR_INV 0x00020000 /* No EC inval. on slave writes */
109#define DMA_ADD_ENABLE 0x00040000 /* Special ESC DVMA optimization */
110#define DMA_E_BURSTS 0x000c0000 /* ENET: SBUS r/w burst mask */
111#define DMA_E_BURST32 0x00040000 /* ENET: SBUS 32 byte r/w burst */
112#define DMA_E_BURST16 0x00000000 /* ENET: SBUS 16 byte r/w burst */
113#define DMA_BRST_SZ 0x000c0000 /* SCSI: SBUS r/w burst size */
114#define DMA_BRST64 0x000c0000 /* SCSI: 64byte bursts (HME on UltraSparc only) */
115#define DMA_BRST32 0x00040000 /* SCSI: 32byte bursts */
116#define DMA_BRST16 0x00000000 /* SCSI: 16byte bursts */
117#define DMA_BRST0 0x00080000 /* SCSI: no bursts (non-HME gate arrays) */
118#define DMA_ADDR_DISAB 0x00100000 /* No FIFO drains during addr */
119#define DMA_2CLKS 0x00200000 /* Each transfer = 2 clock ticks */
120#define DMA_3CLKS 0x00400000 /* Each transfer = 3 clock ticks */
121#define DMA_EN_ENETAUI DMA_3CLKS /* Put lance into AUI-cable mode */
122#define DMA_CNTR_DISAB 0x00800000 /* No IRQ when DMA_TERM_CNTR set */
123#define DMA_AUTO_NADDR 0x01000000 /* Use "auto nxt addr" feature */
124#define DMA_SCSI_ON 0x02000000 /* Enable SCSI dma */
125#define DMA_PARITY_OFF 0x02000000 /* HME: disable parity checking */
126#define DMA_LOADED_ADDR 0x04000000 /* Address has been loaded */
127#define DMA_LOADED_NADDR 0x08000000 /* Next address has been loaded */
128#define DMA_RESET_FAS366 0x08000000 /* HME: Assert RESET to FAS366 */
129
130/* Values describing the burst-size property from the PROM */
131#define DMA_BURST1 0x01
132#define DMA_BURST2 0x02
133#define DMA_BURST4 0x04
134#define DMA_BURST8 0x08
135#define DMA_BURST16 0x10
136#define DMA_BURST32 0x20
137#define DMA_BURST64 0x40
138#define DMA_BURSTBITS 0x7f
139
140/* Determine highest possible final transfer address given a base */
141#define DMA_MAXEND(addr) (0x01000000UL-(((unsigned long)(addr))&0x00ffffffUL))
142
143/* Yes, I hack a lot of elisp in my spare time... */
144#define DMA_ERROR_P(regs) ((sbus_readl((regs) + DMA_CSR) & DMA_HNDL_ERROR))
145#define DMA_IRQ_P(regs) ((sbus_readl((regs) + DMA_CSR)) & (DMA_HNDL_INTR | DMA_HNDL_ERROR))
146#define DMA_WRITE_P(regs) ((sbus_readl((regs) + DMA_CSR) & DMA_ST_WRITE))
147#define DMA_OFF(__regs) \
148do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
149 tmp &= ~DMA_ENABLE; \
150 sbus_writel(tmp, (__regs) + DMA_CSR); \
151} while(0)
152#define DMA_INTSOFF(__regs) \
153do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
154 tmp &= ~DMA_INT_ENAB; \
155 sbus_writel(tmp, (__regs) + DMA_CSR); \
156} while(0)
157#define DMA_INTSON(__regs) \
158do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
159 tmp |= DMA_INT_ENAB; \
160 sbus_writel(tmp, (__regs) + DMA_CSR); \
161} while(0)
162#define DMA_PUNTFIFO(__regs) \
163do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
164 tmp |= DMA_FIFO_INV; \
165 sbus_writel(tmp, (__regs) + DMA_CSR); \
166} while(0)
167#define DMA_SETSTART(__regs, __addr) \
168 sbus_writel((u32)(__addr), (__regs) + DMA_ADDR);
169#define DMA_BEGINDMA_W(__regs) \
170do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
171 tmp |= (DMA_ST_WRITE|DMA_ENABLE|DMA_INT_ENAB); \
172 sbus_writel(tmp, (__regs) + DMA_CSR); \
173} while(0)
174#define DMA_BEGINDMA_R(__regs) \
175do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
176 tmp |= (DMA_ENABLE|DMA_INT_ENAB); \
177 tmp &= ~DMA_ST_WRITE; \
178 sbus_writel(tmp, (__regs) + DMA_CSR); \
179} while(0)
180
181/* For certain DMA chips, we need to disable ints upon irq entry
182 * and turn them back on when we are done. So in any ESP interrupt
183 * handler you *must* call DMA_IRQ_ENTRY upon entry and DMA_IRQ_EXIT
184 * when leaving the handler. You have been warned...
185 */
186#define DMA_IRQ_ENTRY(dma, dregs) do { \
187 if(DMA_ISBROKEN(dma)) DMA_INTSOFF(dregs); \
188 } while (0)
189
190#define DMA_IRQ_EXIT(dma, dregs) do { \
191 if(DMA_ISBROKEN(dma)) DMA_INTSON(dregs); \
192 } while(0)
193
194#define for_each_dvma(dma) \
195 for((dma) = dma_chain; (dma); (dma) = (dma)->next)
196
197/* From PCI */
198
199#ifdef CONFIG_PCI
200extern int isa_dma_bridge_buggy;
201#else
202#define isa_dma_bridge_buggy (0)
203#endif
204
205#endif /* !(_ASM_SPARC64_DMA_H) */
diff --git a/include/asm-sparc/ebus.h b/include/asm-sparc/ebus.h
index 491f85d662df..a5da2d00cd18 100644
--- a/include/asm-sparc/ebus.h
+++ b/include/asm-sparc/ebus.h
@@ -1,99 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_EBUS_H
2 * ebus.h: PCI to Ebus pseudo driver software state. 2#define ___ASM_SPARC_EBUS_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be) 4#include <asm-sparc/ebus_64.h>
5 * 5#else
6 * Adopted for sparc by V. Roganov and G. Raiko. 6#include <asm-sparc/ebus_32.h>
7 */ 7#endif
8
9#ifndef __SPARC_EBUS_H
10#define __SPARC_EBUS_H
11
12#ifndef _LINUX_IOPORT_H
13#include <linux/ioport.h>
14#endif 8#endif
15#include <asm/oplib.h>
16#include <asm/prom.h>
17#include <asm/of_device.h>
18
19struct linux_ebus_child {
20 struct linux_ebus_child *next;
21 struct linux_ebus_device *parent;
22 struct linux_ebus *bus;
23 struct device_node *prom_node;
24 struct resource resource[PROMREG_MAX];
25 int num_addrs;
26 unsigned int irqs[PROMINTR_MAX];
27 int num_irqs;
28};
29
30struct linux_ebus_device {
31 struct of_device ofdev;
32 struct linux_ebus_device *next;
33 struct linux_ebus_child *children;
34 struct linux_ebus *bus;
35 struct device_node *prom_node;
36 struct resource resource[PROMREG_MAX];
37 int num_addrs;
38 unsigned int irqs[PROMINTR_MAX];
39 int num_irqs;
40};
41#define to_ebus_device(d) container_of(d, struct linux_ebus_device, ofdev.dev)
42
43struct linux_ebus {
44 struct of_device ofdev;
45 struct linux_ebus *next;
46 struct linux_ebus_device *devices;
47 struct linux_pbm_info *parent;
48 struct pci_dev *self;
49 struct device_node *prom_node;
50};
51#define to_ebus(d) container_of(d, struct linux_ebus, ofdev.dev)
52
53struct linux_ebus_dma {
54 unsigned int dcsr;
55 unsigned int dacr;
56 unsigned int dbcr;
57};
58
59#define EBUS_DCSR_INT_PEND 0x00000001
60#define EBUS_DCSR_ERR_PEND 0x00000002
61#define EBUS_DCSR_DRAIN 0x00000004
62#define EBUS_DCSR_INT_EN 0x00000010
63#define EBUS_DCSR_RESET 0x00000080
64#define EBUS_DCSR_WRITE 0x00000100
65#define EBUS_DCSR_EN_DMA 0x00000200
66#define EBUS_DCSR_CYC_PEND 0x00000400
67#define EBUS_DCSR_DIAG_RD_DONE 0x00000800
68#define EBUS_DCSR_DIAG_WR_DONE 0x00001000
69#define EBUS_DCSR_EN_CNT 0x00002000
70#define EBUS_DCSR_TC 0x00004000
71#define EBUS_DCSR_DIS_CSR_DRN 0x00010000
72#define EBUS_DCSR_BURST_SZ_MASK 0x000c0000
73#define EBUS_DCSR_BURST_SZ_1 0x00080000
74#define EBUS_DCSR_BURST_SZ_4 0x00000000
75#define EBUS_DCSR_BURST_SZ_8 0x00040000
76#define EBUS_DCSR_BURST_SZ_16 0x000c0000
77#define EBUS_DCSR_DIAG_EN 0x00100000
78#define EBUS_DCSR_DIS_ERR_PEND 0x00400000
79#define EBUS_DCSR_TCI_DIS 0x00800000
80#define EBUS_DCSR_EN_NEXT 0x01000000
81#define EBUS_DCSR_DMA_ON 0x02000000
82#define EBUS_DCSR_A_LOADED 0x04000000
83#define EBUS_DCSR_NA_LOADED 0x08000000
84#define EBUS_DCSR_DEV_ID_MASK 0xf0000000
85
86extern struct linux_ebus *ebus_chain;
87
88extern void ebus_init(void);
89
90#define for_each_ebus(bus) \
91 for((bus) = ebus_chain; (bus); (bus) = (bus)->next)
92
93#define for_each_ebusdev(dev, bus) \
94 for((dev) = (bus)->devices; (dev); (dev) = (dev)->next)
95
96#define for_each_edevchild(dev, child) \
97 for((child) = (dev)->children; (child); (child) = (child)->next)
98
99#endif /* !(__SPARC_EBUS_H) */
diff --git a/include/asm-sparc/ebus_32.h b/include/asm-sparc/ebus_32.h
new file mode 100644
index 000000000000..29cb7dfc6b79
--- /dev/null
+++ b/include/asm-sparc/ebus_32.h
@@ -0,0 +1,99 @@
1/*
2 * ebus.h: PCI to Ebus pseudo driver software state.
3 *
4 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
5 *
6 * Adopted for sparc by V. Roganov and G. Raiko.
7 */
8
9#ifndef __SPARC_EBUS_H
10#define __SPARC_EBUS_H
11
12#ifndef _LINUX_IOPORT_H
13#include <linux/ioport.h>
14#endif
15#include <asm/oplib.h>
16#include <asm/prom.h>
17#include <asm/of_device.h>
18
19struct linux_ebus_child {
20 struct linux_ebus_child *next;
21 struct linux_ebus_device *parent;
22 struct linux_ebus *bus;
23 struct device_node *prom_node;
24 struct resource resource[PROMREG_MAX];
25 int num_addrs;
26 unsigned int irqs[PROMINTR_MAX];
27 int num_irqs;
28};
29
30struct linux_ebus_device {
31 struct of_device ofdev;
32 struct linux_ebus_device *next;
33 struct linux_ebus_child *children;
34 struct linux_ebus *bus;
35 struct device_node *prom_node;
36 struct resource resource[PROMREG_MAX];
37 int num_addrs;
38 unsigned int irqs[PROMINTR_MAX];
39 int num_irqs;
40};
41#define to_ebus_device(d) container_of(d, struct linux_ebus_device, ofdev.dev)
42
43struct linux_ebus {
44 struct of_device ofdev;
45 struct linux_ebus *next;
46 struct linux_ebus_device *devices;
47 struct linux_pbm_info *parent;
48 struct pci_dev *self;
49 struct device_node *prom_node;
50};
51#define to_ebus(d) container_of(d, struct linux_ebus, ofdev.dev)
52
53struct linux_ebus_dma {
54 unsigned int dcsr;
55 unsigned int dacr;
56 unsigned int dbcr;
57};
58
59#define EBUS_DCSR_INT_PEND 0x00000001
60#define EBUS_DCSR_ERR_PEND 0x00000002
61#define EBUS_DCSR_DRAIN 0x00000004
62#define EBUS_DCSR_INT_EN 0x00000010
63#define EBUS_DCSR_RESET 0x00000080
64#define EBUS_DCSR_WRITE 0x00000100
65#define EBUS_DCSR_EN_DMA 0x00000200
66#define EBUS_DCSR_CYC_PEND 0x00000400
67#define EBUS_DCSR_DIAG_RD_DONE 0x00000800
68#define EBUS_DCSR_DIAG_WR_DONE 0x00001000
69#define EBUS_DCSR_EN_CNT 0x00002000
70#define EBUS_DCSR_TC 0x00004000
71#define EBUS_DCSR_DIS_CSR_DRN 0x00010000
72#define EBUS_DCSR_BURST_SZ_MASK 0x000c0000
73#define EBUS_DCSR_BURST_SZ_1 0x00080000
74#define EBUS_DCSR_BURST_SZ_4 0x00000000
75#define EBUS_DCSR_BURST_SZ_8 0x00040000
76#define EBUS_DCSR_BURST_SZ_16 0x000c0000
77#define EBUS_DCSR_DIAG_EN 0x00100000
78#define EBUS_DCSR_DIS_ERR_PEND 0x00400000
79#define EBUS_DCSR_TCI_DIS 0x00800000
80#define EBUS_DCSR_EN_NEXT 0x01000000
81#define EBUS_DCSR_DMA_ON 0x02000000
82#define EBUS_DCSR_A_LOADED 0x04000000
83#define EBUS_DCSR_NA_LOADED 0x08000000
84#define EBUS_DCSR_DEV_ID_MASK 0xf0000000
85
86extern struct linux_ebus *ebus_chain;
87
88extern void ebus_init(void);
89
90#define for_each_ebus(bus) \
91 for((bus) = ebus_chain; (bus); (bus) = (bus)->next)
92
93#define for_each_ebusdev(dev, bus) \
94 for((dev) = (bus)->devices; (dev); (dev) = (dev)->next)
95
96#define for_each_edevchild(dev, child) \
97 for((child) = (dev)->children; (child); (child) = (child)->next)
98
99#endif /* !(__SPARC_EBUS_H) */
diff --git a/include/asm-sparc/ebus_64.h b/include/asm-sparc/ebus_64.h
new file mode 100644
index 000000000000..fcc62b97ced5
--- /dev/null
+++ b/include/asm-sparc/ebus_64.h
@@ -0,0 +1,94 @@
1/*
2 * ebus.h: PCI to Ebus pseudo driver software state.
3 *
4 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
5 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
6 */
7
8#ifndef __SPARC64_EBUS_H
9#define __SPARC64_EBUS_H
10
11#include <asm/oplib.h>
12#include <asm/prom.h>
13#include <asm/of_device.h>
14
15struct linux_ebus_child {
16 struct linux_ebus_child *next;
17 struct linux_ebus_device *parent;
18 struct linux_ebus *bus;
19 struct device_node *prom_node;
20 struct resource resource[PROMREG_MAX];
21 int num_addrs;
22 unsigned int irqs[PROMINTR_MAX];
23 int num_irqs;
24};
25
26struct linux_ebus_device {
27 struct of_device ofdev;
28 struct linux_ebus_device *next;
29 struct linux_ebus_child *children;
30 struct linux_ebus *bus;
31 struct device_node *prom_node;
32 struct resource resource[PROMREG_MAX];
33 int num_addrs;
34 unsigned int irqs[PROMINTR_MAX];
35 int num_irqs;
36};
37#define to_ebus_device(d) container_of(d, struct linux_ebus_device, ofdev.dev)
38
39struct linux_ebus {
40 struct of_device ofdev;
41 struct linux_ebus *next;
42 struct linux_ebus_device *devices;
43 struct pci_dev *self;
44 int index;
45 int is_rio;
46 struct device_node *prom_node;
47};
48#define to_ebus(d) container_of(d, struct linux_ebus, ofdev.dev)
49
50struct ebus_dma_info {
51 spinlock_t lock;
52 void __iomem *regs;
53
54 unsigned int flags;
55#define EBUS_DMA_FLAG_USE_EBDMA_HANDLER 0x00000001
56#define EBUS_DMA_FLAG_TCI_DISABLE 0x00000002
57
58 /* These are only valid is EBUS_DMA_FLAG_USE_EBDMA_HANDLER is
59 * set.
60 */
61 void (*callback)(struct ebus_dma_info *p, int event, void *cookie);
62 void *client_cookie;
63 unsigned int irq;
64#define EBUS_DMA_EVENT_ERROR 1
65#define EBUS_DMA_EVENT_DMA 2
66#define EBUS_DMA_EVENT_DEVICE 4
67
68 unsigned char name[64];
69};
70
71extern int ebus_dma_register(struct ebus_dma_info *p);
72extern int ebus_dma_irq_enable(struct ebus_dma_info *p, int on);
73extern void ebus_dma_unregister(struct ebus_dma_info *p);
74extern int ebus_dma_request(struct ebus_dma_info *p, dma_addr_t bus_addr,
75 size_t len);
76extern void ebus_dma_prepare(struct ebus_dma_info *p, int write);
77extern unsigned int ebus_dma_residue(struct ebus_dma_info *p);
78extern unsigned int ebus_dma_addr(struct ebus_dma_info *p);
79extern void ebus_dma_enable(struct ebus_dma_info *p, int on);
80
81extern struct linux_ebus *ebus_chain;
82
83extern void ebus_init(void);
84
85#define for_each_ebus(bus) \
86 for((bus) = ebus_chain; (bus); (bus) = (bus)->next)
87
88#define for_each_ebusdev(dev, bus) \
89 for((dev) = (bus)->devices; (dev); (dev) = (dev)->next)
90
91#define for_each_edevchild(dev, child) \
92 for((child) = (dev)->children; (child); (child) = (child)->next)
93
94#endif /* !(__SPARC64_EBUS_H) */
diff --git a/include/asm-sparc/elf.h b/include/asm-sparc/elf.h
index d043f80bc2fd..f035c45d7b5e 100644
--- a/include/asm-sparc/elf.h
+++ b/include/asm-sparc/elf.h
@@ -1,145 +1,8 @@
1#ifndef __ASMSPARC_ELF_H 1#ifndef ___ASM_SPARC_ELF_H
2#define __ASMSPARC_ELF_H 2#define ___ASM_SPARC_ELF_H
3 3#if defined(__sparc__) && defined(__arch64__)
4/* 4#include <asm-sparc/elf_64.h>
5 * ELF register definitions..
6 */
7
8#include <asm/ptrace.h>
9
10/*
11 * Sparc section types
12 */
13#define STT_REGISTER 13
14
15/*
16 * Sparc ELF relocation types
17 */
18#define R_SPARC_NONE 0
19#define R_SPARC_8 1
20#define R_SPARC_16 2
21#define R_SPARC_32 3
22#define R_SPARC_DISP8 4
23#define R_SPARC_DISP16 5
24#define R_SPARC_DISP32 6
25#define R_SPARC_WDISP30 7
26#define R_SPARC_WDISP22 8
27#define R_SPARC_HI22 9
28#define R_SPARC_22 10
29#define R_SPARC_13 11
30#define R_SPARC_LO10 12
31#define R_SPARC_GOT10 13
32#define R_SPARC_GOT13 14
33#define R_SPARC_GOT22 15
34#define R_SPARC_PC10 16
35#define R_SPARC_PC22 17
36#define R_SPARC_WPLT30 18
37#define R_SPARC_COPY 19
38#define R_SPARC_GLOB_DAT 20
39#define R_SPARC_JMP_SLOT 21
40#define R_SPARC_RELATIVE 22
41#define R_SPARC_UA32 23
42#define R_SPARC_PLT32 24
43#define R_SPARC_HIPLT22 25
44#define R_SPARC_LOPLT10 26
45#define R_SPARC_PCPLT32 27
46#define R_SPARC_PCPLT22 28
47#define R_SPARC_PCPLT10 29
48#define R_SPARC_10 30
49#define R_SPARC_11 31
50#define R_SPARC_64 32
51#define R_SPARC_OLO10 33
52#define R_SPARC_WDISP16 40
53#define R_SPARC_WDISP19 41
54#define R_SPARC_7 43
55#define R_SPARC_5 44
56#define R_SPARC_6 45
57
58/* Bits present in AT_HWCAP, primarily for Sparc32. */
59
60#define HWCAP_SPARC_FLUSH 1 /* CPU supports flush instruction. */
61#define HWCAP_SPARC_STBAR 2
62#define HWCAP_SPARC_SWAP 4
63#define HWCAP_SPARC_MULDIV 8
64#define HWCAP_SPARC_V9 16
65#define HWCAP_SPARC_ULTRA3 32
66
67#define CORE_DUMP_USE_REGSET
68
69/* Format is:
70 * G0 --> G7
71 * O0 --> O7
72 * L0 --> L7
73 * I0 --> I7
74 * PSR, PC, nPC, Y, WIM, TBR
75 */
76typedef unsigned long elf_greg_t;
77#define ELF_NGREG 38
78typedef elf_greg_t elf_gregset_t[ELF_NGREG];
79
80typedef struct {
81 union {
82 unsigned long pr_regs[32];
83 double pr_dregs[16];
84 } pr_fr;
85 unsigned long __unused;
86 unsigned long pr_fsr;
87 unsigned char pr_qcnt;
88 unsigned char pr_q_entrysize;
89 unsigned char pr_en;
90 unsigned int pr_q[64];
91} elf_fpregset_t;
92
93#include <asm/mbus.h>
94
95/*
96 * This is used to ensure we don't load something for the wrong architecture.
97 */
98#define elf_check_arch(x) ((x)->e_machine == EM_SPARC)
99
100/*
101 * These are used to set parameters in the core dumps.
102 */
103#define ELF_ARCH EM_SPARC
104#define ELF_CLASS ELFCLASS32
105#define ELF_DATA ELFDATA2MSB
106
107#define USE_ELF_CORE_DUMP
108#ifndef CONFIG_SUN4
109#define ELF_EXEC_PAGESIZE 4096
110#else 5#else
111#define ELF_EXEC_PAGESIZE 8192 6#include <asm-sparc/elf_32.h>
7#endif
112#endif 8#endif
113
114
115/* This is the location that an ET_DYN program is loaded if exec'ed. Typical
116 use of this is to invoke "./ld.so someprog" to test out a new version of
117 the loader. We need to make sure that it is out of the way of the program
118 that it will "exec", and that there is sufficient room for the brk. */
119
120#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
121
122/* This yields a mask that user programs can use to figure out what
123 instruction set this cpu supports. This can NOT be done in userspace
124 on Sparc. */
125
126/* Sun4c has none of the capabilities, most sun4m's have them all.
127 * XXX This is gross, set some global variable at boot time. -DaveM
128 */
129#define ELF_HWCAP ((ARCH_SUN4C_SUN4) ? 0 : \
130 (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR | \
131 HWCAP_SPARC_SWAP | \
132 ((srmmu_modtype != Cypress && \
133 srmmu_modtype != Cypress_vE && \
134 srmmu_modtype != Cypress_vD) ? \
135 HWCAP_SPARC_MULDIV : 0)))
136
137/* This yields a string that ld.so will use to load implementation
138 specific libraries for optimization. This is more specific in
139 intent than poking at uname or /proc/cpuinfo. */
140
141#define ELF_PLATFORM (NULL)
142
143#define SET_PERSONALITY(ex, ibcs2) set_personality((ibcs2)?PER_SVR4:PER_LINUX)
144
145#endif /* !(__ASMSPARC_ELF_H) */
diff --git a/include/asm-sparc/elf_32.h b/include/asm-sparc/elf_32.h
new file mode 100644
index 000000000000..d043f80bc2fd
--- /dev/null
+++ b/include/asm-sparc/elf_32.h
@@ -0,0 +1,145 @@
1#ifndef __ASMSPARC_ELF_H
2#define __ASMSPARC_ELF_H
3
4/*
5 * ELF register definitions..
6 */
7
8#include <asm/ptrace.h>
9
10/*
11 * Sparc section types
12 */
13#define STT_REGISTER 13
14
15/*
16 * Sparc ELF relocation types
17 */
18#define R_SPARC_NONE 0
19#define R_SPARC_8 1
20#define R_SPARC_16 2
21#define R_SPARC_32 3
22#define R_SPARC_DISP8 4
23#define R_SPARC_DISP16 5
24#define R_SPARC_DISP32 6
25#define R_SPARC_WDISP30 7
26#define R_SPARC_WDISP22 8
27#define R_SPARC_HI22 9
28#define R_SPARC_22 10
29#define R_SPARC_13 11
30#define R_SPARC_LO10 12
31#define R_SPARC_GOT10 13
32#define R_SPARC_GOT13 14
33#define R_SPARC_GOT22 15
34#define R_SPARC_PC10 16
35#define R_SPARC_PC22 17
36#define R_SPARC_WPLT30 18
37#define R_SPARC_COPY 19
38#define R_SPARC_GLOB_DAT 20
39#define R_SPARC_JMP_SLOT 21
40#define R_SPARC_RELATIVE 22
41#define R_SPARC_UA32 23
42#define R_SPARC_PLT32 24
43#define R_SPARC_HIPLT22 25
44#define R_SPARC_LOPLT10 26
45#define R_SPARC_PCPLT32 27
46#define R_SPARC_PCPLT22 28
47#define R_SPARC_PCPLT10 29
48#define R_SPARC_10 30
49#define R_SPARC_11 31
50#define R_SPARC_64 32
51#define R_SPARC_OLO10 33
52#define R_SPARC_WDISP16 40
53#define R_SPARC_WDISP19 41
54#define R_SPARC_7 43
55#define R_SPARC_5 44
56#define R_SPARC_6 45
57
58/* Bits present in AT_HWCAP, primarily for Sparc32. */
59
60#define HWCAP_SPARC_FLUSH 1 /* CPU supports flush instruction. */
61#define HWCAP_SPARC_STBAR 2
62#define HWCAP_SPARC_SWAP 4
63#define HWCAP_SPARC_MULDIV 8
64#define HWCAP_SPARC_V9 16
65#define HWCAP_SPARC_ULTRA3 32
66
67#define CORE_DUMP_USE_REGSET
68
69/* Format is:
70 * G0 --> G7
71 * O0 --> O7
72 * L0 --> L7
73 * I0 --> I7
74 * PSR, PC, nPC, Y, WIM, TBR
75 */
76typedef unsigned long elf_greg_t;
77#define ELF_NGREG 38
78typedef elf_greg_t elf_gregset_t[ELF_NGREG];
79
80typedef struct {
81 union {
82 unsigned long pr_regs[32];
83 double pr_dregs[16];
84 } pr_fr;
85 unsigned long __unused;
86 unsigned long pr_fsr;
87 unsigned char pr_qcnt;
88 unsigned char pr_q_entrysize;
89 unsigned char pr_en;
90 unsigned int pr_q[64];
91} elf_fpregset_t;
92
93#include <asm/mbus.h>
94
95/*
96 * This is used to ensure we don't load something for the wrong architecture.
97 */
98#define elf_check_arch(x) ((x)->e_machine == EM_SPARC)
99
100/*
101 * These are used to set parameters in the core dumps.
102 */
103#define ELF_ARCH EM_SPARC
104#define ELF_CLASS ELFCLASS32
105#define ELF_DATA ELFDATA2MSB
106
107#define USE_ELF_CORE_DUMP
108#ifndef CONFIG_SUN4
109#define ELF_EXEC_PAGESIZE 4096
110#else
111#define ELF_EXEC_PAGESIZE 8192
112#endif
113
114
115/* This is the location that an ET_DYN program is loaded if exec'ed. Typical
116 use of this is to invoke "./ld.so someprog" to test out a new version of
117 the loader. We need to make sure that it is out of the way of the program
118 that it will "exec", and that there is sufficient room for the brk. */
119
120#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
121
122/* This yields a mask that user programs can use to figure out what
123 instruction set this cpu supports. This can NOT be done in userspace
124 on Sparc. */
125
126/* Sun4c has none of the capabilities, most sun4m's have them all.
127 * XXX This is gross, set some global variable at boot time. -DaveM
128 */
129#define ELF_HWCAP ((ARCH_SUN4C_SUN4) ? 0 : \
130 (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR | \
131 HWCAP_SPARC_SWAP | \
132 ((srmmu_modtype != Cypress && \
133 srmmu_modtype != Cypress_vE && \
134 srmmu_modtype != Cypress_vD) ? \
135 HWCAP_SPARC_MULDIV : 0)))
136
137/* This yields a string that ld.so will use to load implementation
138 specific libraries for optimization. This is more specific in
139 intent than poking at uname or /proc/cpuinfo. */
140
141#define ELF_PLATFORM (NULL)
142
143#define SET_PERSONALITY(ex, ibcs2) set_personality((ibcs2)?PER_SVR4:PER_LINUX)
144
145#endif /* !(__ASMSPARC_ELF_H) */
diff --git a/include/asm-sparc/elf_64.h b/include/asm-sparc/elf_64.h
new file mode 100644
index 000000000000..0818a1308f4e
--- /dev/null
+++ b/include/asm-sparc/elf_64.h
@@ -0,0 +1,217 @@
1#ifndef __ASM_SPARC64_ELF_H
2#define __ASM_SPARC64_ELF_H
3
4/*
5 * ELF register definitions..
6 */
7
8#include <asm/ptrace.h>
9#include <asm/processor.h>
10#include <asm/uaccess.h>
11#include <asm/spitfire.h>
12
13/*
14 * Sparc section types
15 */
16#define STT_REGISTER 13
17
18/*
19 * Sparc ELF relocation types
20 */
21#define R_SPARC_NONE 0
22#define R_SPARC_8 1
23#define R_SPARC_16 2
24#define R_SPARC_32 3
25#define R_SPARC_DISP8 4
26#define R_SPARC_DISP16 5
27#define R_SPARC_DISP32 6
28#define R_SPARC_WDISP30 7
29#define R_SPARC_WDISP22 8
30#define R_SPARC_HI22 9
31#define R_SPARC_22 10
32#define R_SPARC_13 11
33#define R_SPARC_LO10 12
34#define R_SPARC_GOT10 13
35#define R_SPARC_GOT13 14
36#define R_SPARC_GOT22 15
37#define R_SPARC_PC10 16
38#define R_SPARC_PC22 17
39#define R_SPARC_WPLT30 18
40#define R_SPARC_COPY 19
41#define R_SPARC_GLOB_DAT 20
42#define R_SPARC_JMP_SLOT 21
43#define R_SPARC_RELATIVE 22
44#define R_SPARC_UA32 23
45#define R_SPARC_PLT32 24
46#define R_SPARC_HIPLT22 25
47#define R_SPARC_LOPLT10 26
48#define R_SPARC_PCPLT32 27
49#define R_SPARC_PCPLT22 28
50#define R_SPARC_PCPLT10 29
51#define R_SPARC_10 30
52#define R_SPARC_11 31
53#define R_SPARC_64 32
54#define R_SPARC_OLO10 33
55#define R_SPARC_WDISP16 40
56#define R_SPARC_WDISP19 41
57#define R_SPARC_7 43
58#define R_SPARC_5 44
59#define R_SPARC_6 45
60
61/* Bits present in AT_HWCAP, primarily for Sparc32. */
62
63#define HWCAP_SPARC_FLUSH 1 /* CPU supports flush instruction. */
64#define HWCAP_SPARC_STBAR 2
65#define HWCAP_SPARC_SWAP 4
66#define HWCAP_SPARC_MULDIV 8
67#define HWCAP_SPARC_V9 16
68#define HWCAP_SPARC_ULTRA3 32
69#define HWCAP_SPARC_BLKINIT 64
70#define HWCAP_SPARC_N2 128
71
72#define CORE_DUMP_USE_REGSET
73
74/*
75 * These are used to set parameters in the core dumps.
76 */
77#define ELF_ARCH EM_SPARCV9
78#define ELF_CLASS ELFCLASS64
79#define ELF_DATA ELFDATA2MSB
80
81/* Format of 64-bit elf_gregset_t is:
82 * G0 --> G7
83 * O0 --> O7
84 * L0 --> L7
85 * I0 --> I7
86 * TSTATE
87 * TPC
88 * TNPC
89 * Y
90 */
91typedef unsigned long elf_greg_t;
92#define ELF_NGREG 36
93typedef elf_greg_t elf_gregset_t[ELF_NGREG];
94
95typedef struct {
96 unsigned long pr_regs[32];
97 unsigned long pr_fsr;
98 unsigned long pr_gsr;
99 unsigned long pr_fprs;
100} elf_fpregset_t;
101
102/* Format of 32-bit elf_gregset_t is:
103 * G0 --> G7
104 * O0 --> O7
105 * L0 --> L7
106 * I0 --> I7
107 * PSR, PC, nPC, Y, WIM, TBR
108 */
109typedef unsigned int compat_elf_greg_t;
110#define COMPAT_ELF_NGREG 38
111typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
112
113typedef struct {
114 union {
115 unsigned int pr_regs[32];
116 unsigned long pr_dregs[16];
117 } pr_fr;
118 unsigned int __unused;
119 unsigned int pr_fsr;
120 unsigned char pr_qcnt;
121 unsigned char pr_q_entrysize;
122 unsigned char pr_en;
123 unsigned int pr_q[64];
124} compat_elf_fpregset_t;
125
126/* UltraSparc extensions. Still unused, but will be eventually. */
127typedef struct {
128 unsigned int pr_type;
129 unsigned int pr_align;
130 union {
131 struct {
132 union {
133 unsigned int pr_regs[32];
134 unsigned long pr_dregs[16];
135 long double pr_qregs[8];
136 } pr_xfr;
137 } pr_v8p;
138 unsigned int pr_xfsr;
139 unsigned int pr_fprs;
140 unsigned int pr_xg[8];
141 unsigned int pr_xo[8];
142 unsigned long pr_tstate;
143 unsigned int pr_filler[8];
144 } pr_un;
145} elf_xregset_t;
146
147/*
148 * This is used to ensure we don't load something for the wrong architecture.
149 */
150#define elf_check_arch(x) ((x)->e_machine == ELF_ARCH)
151#define compat_elf_check_arch(x) ((x)->e_machine == EM_SPARC || \
152 (x)->e_machine == EM_SPARC32PLUS)
153#define compat_start_thread start_thread32
154
155#define USE_ELF_CORE_DUMP
156#define ELF_EXEC_PAGESIZE PAGE_SIZE
157
158/* This is the location that an ET_DYN program is loaded if exec'ed. Typical
159 use of this is to invoke "./ld.so someprog" to test out a new version of
160 the loader. We need to make sure that it is out of the way of the program
161 that it will "exec", and that there is sufficient room for the brk. */
162
163#define ELF_ET_DYN_BASE 0x0000010000000000UL
164#define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
165
166
167/* This yields a mask that user programs can use to figure out what
168 instruction set this cpu supports. */
169
170/* On Ultra, we support all of the v8 capabilities. */
171static inline unsigned int sparc64_elf_hwcap(void)
172{
173 unsigned int cap = (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR |
174 HWCAP_SPARC_SWAP | HWCAP_SPARC_MULDIV |
175 HWCAP_SPARC_V9);
176
177 if (tlb_type == cheetah || tlb_type == cheetah_plus)
178 cap |= HWCAP_SPARC_ULTRA3;
179 else if (tlb_type == hypervisor) {
180 if (sun4v_chip_type == SUN4V_CHIP_NIAGARA1 ||
181 sun4v_chip_type == SUN4V_CHIP_NIAGARA2)
182 cap |= HWCAP_SPARC_BLKINIT;
183 if (sun4v_chip_type == SUN4V_CHIP_NIAGARA2)
184 cap |= HWCAP_SPARC_N2;
185 }
186
187 return cap;
188}
189
190#define ELF_HWCAP sparc64_elf_hwcap();
191
192/* This yields a string that ld.so will use to load implementation
193 specific libraries for optimization. This is more specific in
194 intent than poking at uname or /proc/cpuinfo. */
195
196#define ELF_PLATFORM (NULL)
197
198#define SET_PERSONALITY(ex, ibcs2) \
199do { unsigned long new_flags = current_thread_info()->flags; \
200 new_flags &= _TIF_32BIT; \
201 if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
202 new_flags |= _TIF_32BIT; \
203 else \
204 new_flags &= ~_TIF_32BIT; \
205 if ((current_thread_info()->flags & _TIF_32BIT) \
206 != new_flags) \
207 set_thread_flag(TIF_ABI_PENDING); \
208 else \
209 clear_thread_flag(TIF_ABI_PENDING); \
210 /* flush_thread will update pgd cache */ \
211 if (ibcs2) \
212 set_personality(PER_SVR4); \
213 else if (current->personality != PER_LINUX32) \
214 set_personality(PER_LINUX); \
215} while (0)
216
217#endif /* !(__ASM_SPARC64_ELF_H) */
diff --git a/include/asm-sparc/envctrl.h b/include/asm-sparc/envctrl.h
new file mode 100644
index 000000000000..624fa7e2da8e
--- /dev/null
+++ b/include/asm-sparc/envctrl.h
@@ -0,0 +1,103 @@
1/*
2 *
3 * envctrl.h: Definitions for access to the i2c environment
4 * monitoring on Ultrasparc systems.
5 *
6 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
7 * Copyright (C) 2000 Vinh Truong (vinh.truong@eng.sun.com)
8 * VT - Add all ioctl commands and environment status definitions
9 * VT - Add application note
10 */
11#ifndef _SPARC64_ENVCTRL_H
12#define _SPARC64_ENVCTRL_H 1
13
14#include <linux/ioctl.h>
15
16/* Application note:
17 *
18 * The driver supports 4 operations: open(), close(), ioctl(), read()
19 * The device name is /dev/envctrl.
20 * Below is sample usage:
21 *
22 * fd = open("/dev/envtrl", O_RDONLY);
23 * if (ioctl(fd, ENVCTRL_READ_SHUTDOWN_TEMPERATURE, 0) < 0)
24 * printf("error\n");
25 * ret = read(fd, buf, 10);
26 * close(fd);
27 *
28 * Notice in the case of cpu voltage and temperature, the default is
29 * cpu0. If we need to know the info of cpu1, cpu2, cpu3, we need to
30 * pass in cpu number in ioctl() last parameter. For example, to
31 * get the voltage of cpu2:
32 *
33 * ioctlbuf[0] = 2;
34 * if (ioctl(fd, ENVCTRL_READ_CPU_VOLTAGE, ioctlbuf) < 0)
35 * printf("error\n");
36 * ret = read(fd, buf, 10);
37 *
38 * All the return values are in ascii. So check read return value
39 * and do appropriate conversions in your application.
40 */
41
42/* IOCTL commands */
43
44/* Note: these commands reflect possible monitor features.
45 * Some boards choose to support some of the features only.
46 */
47#define ENVCTRL_RD_CPU_TEMPERATURE _IOR('p', 0x40, int)
48#define ENVCTRL_RD_CPU_VOLTAGE _IOR('p', 0x41, int)
49#define ENVCTRL_RD_FAN_STATUS _IOR('p', 0x42, int)
50#define ENVCTRL_RD_WARNING_TEMPERATURE _IOR('p', 0x43, int)
51#define ENVCTRL_RD_SHUTDOWN_TEMPERATURE _IOR('p', 0x44, int)
52#define ENVCTRL_RD_VOLTAGE_STATUS _IOR('p', 0x45, int)
53#define ENVCTRL_RD_SCSI_TEMPERATURE _IOR('p', 0x46, int)
54#define ENVCTRL_RD_ETHERNET_TEMPERATURE _IOR('p', 0x47, int)
55#define ENVCTRL_RD_MTHRBD_TEMPERATURE _IOR('p', 0x48, int)
56
57#define ENVCTRL_RD_GLOBALADDRESS _IOR('p', 0x49, int)
58
59/* Read return values for a voltage status request. */
60#define ENVCTRL_VOLTAGE_POWERSUPPLY_GOOD 0x01
61#define ENVCTRL_VOLTAGE_BAD 0x02
62#define ENVCTRL_POWERSUPPLY_BAD 0x03
63#define ENVCTRL_VOLTAGE_POWERSUPPLY_BAD 0x04
64
65/* Read return values for a fan status request.
66 * A failure match means either the fan fails or
67 * the fan is not connected. Some boards have optional
68 * connectors to connect extra fans.
69 *
70 * There are maximum 8 monitor fans. Some are cpu fans
71 * some are system fans. The mask below only indicates
72 * fan by order number.
73 * Below is a sample application:
74 *
75 * if (ioctl(fd, ENVCTRL_READ_FAN_STATUS, 0) < 0) {
76 * printf("ioctl fan failed\n");
77 * }
78 * if (read(fd, rslt, 1) <= 0) {
79 * printf("error or fan not monitored\n");
80 * } else {
81 * if (rslt[0] == ENVCTRL_ALL_FANS_GOOD) {
82 * printf("all fans good\n");
83 * } else if (rslt[0] == ENVCTRL_ALL_FANS_BAD) {
84 * printf("all fans bad\n");
85 * } else {
86 * if (rslt[0] & ENVCTRL_FAN0_FAILURE_MASK) {
87 * printf("fan 0 failed or not connected\n");
88 * }
89 * ......
90 */
91
92#define ENVCTRL_ALL_FANS_GOOD 0x00
93#define ENVCTRL_FAN0_FAILURE_MASK 0x01
94#define ENVCTRL_FAN1_FAILURE_MASK 0x02
95#define ENVCTRL_FAN2_FAILURE_MASK 0x04
96#define ENVCTRL_FAN3_FAILURE_MASK 0x08
97#define ENVCTRL_FAN4_FAILURE_MASK 0x10
98#define ENVCTRL_FAN5_FAILURE_MASK 0x20
99#define ENVCTRL_FAN6_FAILURE_MASK 0x40
100#define ENVCTRL_FAN7_FAILURE_MASK 0x80
101#define ENVCTRL_ALL_FANS_BAD 0xFF
102
103#endif /* !(_SPARC64_ENVCTRL_H) */
diff --git a/include/asm-sparc/estate.h b/include/asm-sparc/estate.h
new file mode 100644
index 000000000000..520c08560d1b
--- /dev/null
+++ b/include/asm-sparc/estate.h
@@ -0,0 +1,49 @@
1#ifndef _SPARC64_ESTATE_H
2#define _SPARC64_ESTATE_H
3
4/* UltraSPARC-III E-cache Error Enable */
5#define ESTATE_ERROR_FMT 0x0000000000040000 /* Force MTAG ECC */
6#define ESTATE_ERROR_FMESS 0x000000000003c000 /* Forced MTAG ECC val */
7#define ESTATE_ERROR_FMD 0x0000000000002000 /* Force DATA ECC */
8#define ESTATE_ERROR_FDECC 0x0000000000001ff0 /* Forced DATA ECC val */
9#define ESTATE_ERROR_UCEEN 0x0000000000000008 /* See below */
10#define ESTATE_ERROR_NCEEN 0x0000000000000002 /* See below */
11#define ESTATE_ERROR_CEEN 0x0000000000000001 /* See below */
12
13/* UCEEN enables the fast_ECC_error trap for: 1) software correctable E-cache
14 * errors 2) uncorrectable E-cache errors. Such events only occur on reads
15 * of the E-cache by the local processor for: 1) data loads 2) instruction
16 * fetches 3) atomic operations. Such events _cannot_ occur for: 1) merge
17 * 2) writeback 2) copyout. The AFSR bits associated with these traps are
18 * UCC and UCU.
19 */
20
21/* NCEEN enables instruction_access_error, data_access_error, and ECC_error traps
22 * for uncorrectable ECC errors and system errors.
23 *
24 * Uncorrectable system bus data error or MTAG ECC error, system bus TimeOUT,
25 * or system bus BusERR:
26 * 1) As the result of an instruction fetch, will generate instruction_access_error
27 * 2) As the result of a load etc. will generate data_access_error.
28 * 3) As the result of store merge completion, writeback, or copyout will
29 * generate a disrupting ECC_error trap.
30 * 4) As the result of such errors on instruction vector fetch can generate any
31 * of the 3 trap types.
32 *
33 * The AFSR bits associated with these traps are EMU, EDU, WDU, CPU, IVU, UE,
34 * BERR, and TO.
35 */
36
37/* CEEN enables the ECC_error trap for hardware corrected ECC errors. System bus
38 * reads resulting in a hardware corrected data or MTAG ECC error will generate an
39 * ECC_error disrupting trap with this bit enabled.
40 *
41 * This same trap will also be generated when a hardware corrected ECC error results
42 * during store merge, writeback, and copyout operations.
43 */
44
45/* In general, if the trap enable bits above are disabled the AFSR bits will still
46 * log the events even though the trap will not be generated by the processor.
47 */
48
49#endif /* _SPARC64_ESTATE_H */
diff --git a/include/asm-sparc/fbio.h b/include/asm-sparc/fbio.h
index c2b27e7a7cad..b9215a0907d3 100644
--- a/include/asm-sparc/fbio.h
+++ b/include/asm-sparc/fbio.h
@@ -1,6 +1,9 @@
1#ifndef __LINUX_FBIO_H 1#ifndef __LINUX_FBIO_H
2#define __LINUX_FBIO_H 2#define __LINUX_FBIO_H
3 3
4#include <linux/compiler.h>
5#include <linux/types.h>
6
4/* Constants used for fbio SunOS compatibility */ 7/* Constants used for fbio SunOS compatibility */
5/* (C) 1996 Miguel de Icaza */ 8/* (C) 1996 Miguel de Icaza */
6 9
@@ -38,6 +41,9 @@
38#define FBTYPE_PCI_IGA1682 23 41#define FBTYPE_PCI_IGA1682 23
39#define FBTYPE_P9100COLOR 24 42#define FBTYPE_P9100COLOR 24
40 43
44#define FBTYPE_PCI_GENERIC 1000
45#define FBTYPE_PCI_MACH64 1001
46
41/* fbio ioctls */ 47/* fbio ioctls */
42/* Returned by FBIOGTYPE */ 48/* Returned by FBIOGTYPE */
43struct fbtype { 49struct fbtype {
@@ -97,8 +103,8 @@ struct fbcursor {
97 struct fbcurpos hot; /* cursor hot spot */ 103 struct fbcurpos hot; /* cursor hot spot */
98 struct fbcmap cmap; /* color map info */ 104 struct fbcmap cmap; /* color map info */
99 struct fbcurpos size; /* cursor bit map size */ 105 struct fbcurpos size; /* cursor bit map size */
100 char *image; /* cursor image bits */ 106 char __user *image; /* cursor image bits */
101 char *mask; /* cursor mask bits */ 107 char __user *mask; /* cursor mask bits */
102}; 108};
103 109
104/* set/get cursor attributes/shape */ 110/* set/get cursor attributes/shape */
@@ -294,4 +300,31 @@ struct fb_clut32 {
294#define LEO_LD_GBL_MAP 0x01009000 300#define LEO_LD_GBL_MAP 0x01009000
295#define LEO_UNK2_MAP 0x0100a000 301#define LEO_UNK2_MAP 0x0100a000
296 302
303#ifdef __KERNEL__
304struct fbcmap32 {
305 int index; /* first element (0 origin) */
306 int count;
307 u32 red;
308 u32 green;
309 u32 blue;
310};
311
312#define FBIOPUTCMAP32 _IOW('F', 3, struct fbcmap32)
313#define FBIOGETCMAP32 _IOW('F', 4, struct fbcmap32)
314
315struct fbcursor32 {
316 short set; /* what to set, choose from the list above */
317 short enable; /* cursor on/off */
318 struct fbcurpos pos; /* cursor position */
319 struct fbcurpos hot; /* cursor hot spot */
320 struct fbcmap32 cmap; /* color map info */
321 struct fbcurpos size; /* cursor bit map size */
322 u32 image; /* cursor image bits */
323 u32 mask; /* cursor mask bits */
324};
325
326#define FBIOSCURSOR32 _IOW('F', 24, struct fbcursor32)
327#define FBIOGCURSOR32 _IOW('F', 25, struct fbcursor32)
328#endif
329
297#endif /* __LINUX_FBIO_H */ 330#endif /* __LINUX_FBIO_H */
diff --git a/include/asm-sparc/fcntl.h b/include/asm-sparc/fcntl.h
index 07bd2d80257f..d4d9c9d852c3 100644
--- a/include/asm-sparc/fcntl.h
+++ b/include/asm-sparc/fcntl.h
@@ -10,7 +10,11 @@
10#define O_EXCL 0x0800 /* not fcntl */ 10#define O_EXCL 0x0800 /* not fcntl */
11#define O_SYNC 0x2000 11#define O_SYNC 0x2000
12#define O_NONBLOCK 0x4000 12#define O_NONBLOCK 0x4000
13#if defined(__sparc__) && defined(__arch64__)
14#define O_NDELAY 0x0004
15#else
13#define O_NDELAY (0x0004 | O_NONBLOCK) 16#define O_NDELAY (0x0004 | O_NONBLOCK)
17#endif
14#define O_NOCTTY 0x8000 /* not fcntl */ 18#define O_NOCTTY 0x8000 /* not fcntl */
15#define O_LARGEFILE 0x40000 19#define O_LARGEFILE 0x40000
16#define O_DIRECT 0x100000 /* direct disk access hint */ 20#define O_DIRECT 0x100000 /* direct disk access hint */
diff --git a/include/asm-sparc/fhc.h b/include/asm-sparc/fhc.h
new file mode 100644
index 000000000000..788cbc46a116
--- /dev/null
+++ b/include/asm-sparc/fhc.h
@@ -0,0 +1,121 @@
1/*
2 * fhc.h: Structures for central/fhc pseudo driver on Sunfire/Starfire/Wildfire.
3 *
4 * Copyright (C) 1997, 1999 David S. Miller (davem@redhat.com)
5 */
6
7#ifndef _SPARC64_FHC_H
8#define _SPARC64_FHC_H
9
10#include <linux/timer.h>
11
12#include <asm/oplib.h>
13#include <asm/prom.h>
14#include <asm/upa.h>
15
16struct linux_fhc;
17
18/* Clock board register offsets. */
19#define CLOCK_CTRL 0x00UL /* Main control */
20#define CLOCK_STAT1 0x10UL /* Status one */
21#define CLOCK_STAT2 0x20UL /* Status two */
22#define CLOCK_PWRSTAT 0x30UL /* Power status */
23#define CLOCK_PWRPRES 0x40UL /* Power presence */
24#define CLOCK_TEMP 0x50UL /* Temperature */
25#define CLOCK_IRQDIAG 0x60UL /* IRQ diagnostics */
26#define CLOCK_PWRSTAT2 0x70UL /* Power status two */
27
28#define CLOCK_CTRL_LLED 0x04 /* Left LED, 0 == on */
29#define CLOCK_CTRL_MLED 0x02 /* Mid LED, 1 == on */
30#define CLOCK_CTRL_RLED 0x01 /* RIght LED, 1 == on */
31
32struct linux_central {
33 struct linux_fhc *child;
34 unsigned long cfreg;
35 unsigned long clkregs;
36 unsigned long clkver;
37 int slots;
38 struct device_node *prom_node;
39
40 struct linux_prom_ranges central_ranges[PROMREG_MAX];
41 int num_central_ranges;
42};
43
44/* Firehose controller register offsets */
45struct fhc_regs {
46 unsigned long pregs; /* FHC internal regs */
47#define FHC_PREGS_ID 0x00UL /* FHC ID */
48#define FHC_ID_VERS 0xf0000000 /* Version of this FHC */
49#define FHC_ID_PARTID 0x0ffff000 /* Part ID code (0x0f9f == FHC) */
50#define FHC_ID_MANUF 0x0000007e /* Manufacturer (0x3e == SUN's JEDEC)*/
51#define FHC_ID_RESV 0x00000001 /* Read as one */
52#define FHC_PREGS_RCS 0x10UL /* FHC Reset Control/Status Register */
53#define FHC_RCS_POR 0x80000000 /* Last reset was a power cycle */
54#define FHC_RCS_SPOR 0x40000000 /* Last reset was sw power on reset */
55#define FHC_RCS_SXIR 0x20000000 /* Last reset was sw XIR reset */
56#define FHC_RCS_BPOR 0x10000000 /* Last reset was due to POR button */
57#define FHC_RCS_BXIR 0x08000000 /* Last reset was due to XIR button */
58#define FHC_RCS_WEVENT 0x04000000 /* CPU reset was due to wakeup event */
59#define FHC_RCS_CFATAL 0x02000000 /* Centerplane Fatal Error signalled */
60#define FHC_RCS_FENAB 0x01000000 /* Fatal errors elicit system reset */
61#define FHC_PREGS_CTRL 0x20UL /* FHC Control Register */
62#define FHC_CONTROL_ICS 0x00100000 /* Ignore Centerplane Signals */
63#define FHC_CONTROL_FRST 0x00080000 /* Fatal Error Reset Enable */
64#define FHC_CONTROL_LFAT 0x00040000 /* AC/DC signalled a local error */
65#define FHC_CONTROL_SLINE 0x00010000 /* Firmware Synchronization Line */
66#define FHC_CONTROL_DCD 0x00008000 /* DC-->DC Converter Disable */
67#define FHC_CONTROL_POFF 0x00004000 /* AC/DC Controller PLL Disable */
68#define FHC_CONTROL_FOFF 0x00002000 /* FHC Controller PLL Disable */
69#define FHC_CONTROL_AOFF 0x00001000 /* CPU A SRAM/SBD Low Power Mode */
70#define FHC_CONTROL_BOFF 0x00000800 /* CPU B SRAM/SBD Low Power Mode */
71#define FHC_CONTROL_PSOFF 0x00000400 /* Turns off this FHC's power supply */
72#define FHC_CONTROL_IXIST 0x00000200 /* 0=FHC tells clock board it exists */
73#define FHC_CONTROL_XMSTR 0x00000100 /* 1=Causes this FHC to be XIR master*/
74#define FHC_CONTROL_LLED 0x00000040 /* 0=Left LED ON */
75#define FHC_CONTROL_MLED 0x00000020 /* 1=Middle LED ON */
76#define FHC_CONTROL_RLED 0x00000010 /* 1=Right LED */
77#define FHC_CONTROL_BPINS 0x00000003 /* Spare Bidirectional Pins */
78#define FHC_PREGS_BSR 0x30UL /* FHC Board Status Register */
79#define FHC_BSR_DA64 0x00040000 /* Port A: 0=128bit 1=64bit data path */
80#define FHC_BSR_DB64 0x00020000 /* Port B: 0=128bit 1=64bit data path */
81#define FHC_BSR_BID 0x0001e000 /* Board ID */
82#define FHC_BSR_SA 0x00001c00 /* Port A UPA Speed (from the pins) */
83#define FHC_BSR_SB 0x00000380 /* Port B UPA Speed (from the pins) */
84#define FHC_BSR_NDIAG 0x00000040 /* Not in Diag Mode */
85#define FHC_BSR_NTBED 0x00000020 /* Not in TestBED Mode */
86#define FHC_BSR_NIA 0x0000001c /* Jumper, bit 18 in PROM space */
87#define FHC_BSR_SI 0x00000001 /* Spare input pin value */
88#define FHC_PREGS_ECC 0x40UL /* FHC ECC Control Register (16 bits) */
89#define FHC_PREGS_JCTRL 0xf0UL /* FHC JTAG Control Register */
90#define FHC_JTAG_CTRL_MENAB 0x80000000 /* Indicates this is JTAG Master */
91#define FHC_JTAG_CTRL_MNONE 0x40000000 /* Indicates no JTAG Master present */
92#define FHC_PREGS_JCMD 0x100UL /* FHC JTAG Command Register */
93 unsigned long ireg; /* FHC IGN reg */
94#define FHC_IREG_IGN 0x00UL /* This FHC's IGN */
95 unsigned long ffregs; /* FHC fanfail regs */
96#define FHC_FFREGS_IMAP 0x00UL /* FHC Fanfail IMAP */
97#define FHC_FFREGS_ICLR 0x10UL /* FHC Fanfail ICLR */
98 unsigned long sregs; /* FHC system regs */
99#define FHC_SREGS_IMAP 0x00UL /* FHC System IMAP */
100#define FHC_SREGS_ICLR 0x10UL /* FHC System ICLR */
101 unsigned long uregs; /* FHC uart regs */
102#define FHC_UREGS_IMAP 0x00UL /* FHC Uart IMAP */
103#define FHC_UREGS_ICLR 0x10UL /* FHC Uart ICLR */
104 unsigned long tregs; /* FHC TOD regs */
105#define FHC_TREGS_IMAP 0x00UL /* FHC TOD IMAP */
106#define FHC_TREGS_ICLR 0x10UL /* FHC TOD ICLR */
107};
108
109struct linux_fhc {
110 struct linux_fhc *next;
111 struct linux_central *parent; /* NULL if not central FHC */
112 struct fhc_regs fhc_regs;
113 int board;
114 int jtag_master;
115 struct device_node *prom_node;
116
117 struct linux_prom_ranges fhc_ranges[PROMREG_MAX];
118 int num_fhc_ranges;
119};
120
121#endif /* !(_SPARC64_FHC_H) */
diff --git a/include/asm-sparc/floppy.h b/include/asm-sparc/floppy.h
index d3978e068e2b..6c628ba15a8d 100644
--- a/include/asm-sparc/floppy.h
+++ b/include/asm-sparc/floppy.h
@@ -1,388 +1,8 @@
1/* asm-sparc/floppy.h: Sparc specific parts of the Floppy driver. 1#ifndef ___ASM_SPARC_FLOPPY_H
2 * 2#define ___ASM_SPARC_FLOPPY_H
3 * Copyright (C) 1995 David S. Miller (davem@davemloft.net) 3#if defined(__sparc__) && defined(__arch64__)
4 */ 4#include <asm-sparc/floppy_64.h>
5 5#else
6#ifndef __ASM_SPARC_FLOPPY_H 6#include <asm-sparc/floppy_32.h>
7#define __ASM_SPARC_FLOPPY_H 7#endif
8
9#include <asm/page.h>
10#include <asm/pgtable.h>
11#include <asm/system.h>
12#include <asm/idprom.h>
13#include <asm/machines.h>
14#include <asm/oplib.h>
15#include <asm/auxio.h>
16#include <asm/irq.h>
17
18/* We don't need no stinkin' I/O port allocation crap. */
19#undef release_region
20#undef request_region
21#define release_region(X, Y) do { } while(0)
22#define request_region(X, Y, Z) (1)
23
24/* References:
25 * 1) Netbsd Sun floppy driver.
26 * 2) NCR 82077 controller manual
27 * 3) Intel 82077 controller manual
28 */
29struct sun_flpy_controller {
30 volatile unsigned char status_82072; /* Main Status reg. */
31#define dcr_82072 status_82072 /* Digital Control reg. */
32#define status1_82077 status_82072 /* Auxiliary Status reg. 1 */
33
34 volatile unsigned char data_82072; /* Data fifo. */
35#define status2_82077 data_82072 /* Auxiliary Status reg. 2 */
36
37 volatile unsigned char dor_82077; /* Digital Output reg. */
38 volatile unsigned char tapectl_82077; /* What the? Tape control reg? */
39
40 volatile unsigned char status_82077; /* Main Status Register. */
41#define drs_82077 status_82077 /* Digital Rate Select reg. */
42
43 volatile unsigned char data_82077; /* Data fifo. */
44 volatile unsigned char ___unused;
45 volatile unsigned char dir_82077; /* Digital Input reg. */
46#define dcr_82077 dir_82077 /* Config Control reg. */
47};
48
49/* You'll only ever find one controller on a SparcStation anyways. */
50static struct sun_flpy_controller *sun_fdc = NULL;
51extern volatile unsigned char *fdc_status;
52
53struct sun_floppy_ops {
54 unsigned char (*fd_inb)(int port);
55 void (*fd_outb)(unsigned char value, int port);
56};
57
58static struct sun_floppy_ops sun_fdops;
59
60#define fd_inb(port) sun_fdops.fd_inb(port)
61#define fd_outb(value,port) sun_fdops.fd_outb(value,port)
62#define fd_enable_dma() sun_fd_enable_dma()
63#define fd_disable_dma() sun_fd_disable_dma()
64#define fd_request_dma() (0) /* nothing... */
65#define fd_free_dma() /* nothing... */
66#define fd_clear_dma_ff() /* nothing... */
67#define fd_set_dma_mode(mode) sun_fd_set_dma_mode(mode)
68#define fd_set_dma_addr(addr) sun_fd_set_dma_addr(addr)
69#define fd_set_dma_count(count) sun_fd_set_dma_count(count)
70#define fd_enable_irq() /* nothing... */
71#define fd_disable_irq() /* nothing... */
72#define fd_cacheflush(addr, size) /* nothing... */
73#define fd_request_irq() sun_fd_request_irq()
74#define fd_free_irq() /* nothing... */
75#if 0 /* P3: added by Alain, these cause a MMU corruption. 19960524 XXX */
76#define fd_dma_mem_alloc(size) ((unsigned long) vmalloc(size))
77#define fd_dma_mem_free(addr,size) (vfree((void *)(addr)))
78#endif 8#endif
79
80/* XXX This isn't really correct. XXX */
81#define get_dma_residue(x) (0)
82
83#define FLOPPY0_TYPE 4
84#define FLOPPY1_TYPE 0
85
86/* Super paranoid... */
87#undef HAVE_DISABLE_HLT
88
89/* Here is where we catch the floppy driver trying to initialize,
90 * therefore this is where we call the PROM device tree probing
91 * routine etc. on the Sparc.
92 */
93#define FDC1 sun_floppy_init()
94
95#define N_FDC 1
96#define N_DRIVE 8
97
98/* No 64k boundary crossing problems on the Sparc. */
99#define CROSS_64KB(a,s) (0)
100
101/* Routines unique to each controller type on a Sun. */
102static void sun_set_dor(unsigned char value, int fdc_82077)
103{
104 if (sparc_cpu_model == sun4c) {
105 unsigned int bits = 0;
106 if (value & 0x10)
107 bits |= AUXIO_FLPY_DSEL;
108 if ((value & 0x80) == 0)
109 bits |= AUXIO_FLPY_EJCT;
110 set_auxio(bits, (~bits) & (AUXIO_FLPY_DSEL|AUXIO_FLPY_EJCT));
111 }
112 if (fdc_82077) {
113 sun_fdc->dor_82077 = value;
114 }
115}
116
117static unsigned char sun_read_dir(void)
118{
119 if (sparc_cpu_model == sun4c)
120 return (get_auxio() & AUXIO_FLPY_DCHG) ? 0x80 : 0;
121 else
122 return sun_fdc->dir_82077;
123}
124
125static unsigned char sun_82072_fd_inb(int port)
126{
127 udelay(5);
128 switch(port & 7) {
129 default:
130 printk("floppy: Asked to read unknown port %d\n", port);
131 panic("floppy: Port bolixed.");
132 case 4: /* FD_STATUS */
133 return sun_fdc->status_82072 & ~STATUS_DMA;
134 case 5: /* FD_DATA */
135 return sun_fdc->data_82072;
136 case 7: /* FD_DIR */
137 return sun_read_dir();
138 };
139 panic("sun_82072_fd_inb: How did I get here?");
140}
141
142static void sun_82072_fd_outb(unsigned char value, int port)
143{
144 udelay(5);
145 switch(port & 7) {
146 default:
147 printk("floppy: Asked to write to unknown port %d\n", port);
148 panic("floppy: Port bolixed.");
149 case 2: /* FD_DOR */
150 sun_set_dor(value, 0);
151 break;
152 case 5: /* FD_DATA */
153 sun_fdc->data_82072 = value;
154 break;
155 case 7: /* FD_DCR */
156 sun_fdc->dcr_82072 = value;
157 break;
158 case 4: /* FD_STATUS */
159 sun_fdc->status_82072 = value;
160 break;
161 };
162 return;
163}
164
165static unsigned char sun_82077_fd_inb(int port)
166{
167 udelay(5);
168 switch(port & 7) {
169 default:
170 printk("floppy: Asked to read unknown port %d\n", port);
171 panic("floppy: Port bolixed.");
172 case 0: /* FD_STATUS_0 */
173 return sun_fdc->status1_82077;
174 case 1: /* FD_STATUS_1 */
175 return sun_fdc->status2_82077;
176 case 2: /* FD_DOR */
177 return sun_fdc->dor_82077;
178 case 3: /* FD_TDR */
179 return sun_fdc->tapectl_82077;
180 case 4: /* FD_STATUS */
181 return sun_fdc->status_82077 & ~STATUS_DMA;
182 case 5: /* FD_DATA */
183 return sun_fdc->data_82077;
184 case 7: /* FD_DIR */
185 return sun_read_dir();
186 };
187 panic("sun_82077_fd_inb: How did I get here?");
188}
189
190static void sun_82077_fd_outb(unsigned char value, int port)
191{
192 udelay(5);
193 switch(port & 7) {
194 default:
195 printk("floppy: Asked to write to unknown port %d\n", port);
196 panic("floppy: Port bolixed.");
197 case 2: /* FD_DOR */
198 sun_set_dor(value, 1);
199 break;
200 case 5: /* FD_DATA */
201 sun_fdc->data_82077 = value;
202 break;
203 case 7: /* FD_DCR */
204 sun_fdc->dcr_82077 = value;
205 break;
206 case 4: /* FD_STATUS */
207 sun_fdc->status_82077 = value;
208 break;
209 case 3: /* FD_TDR */
210 sun_fdc->tapectl_82077 = value;
211 break;
212 };
213 return;
214}
215
216/* For pseudo-dma (Sun floppy drives have no real DMA available to
217 * them so we must eat the data fifo bytes directly ourselves) we have
218 * three state variables. doing_pdma tells our inline low-level
219 * assembly floppy interrupt entry point whether it should sit and eat
220 * bytes from the fifo or just transfer control up to the higher level
221 * floppy interrupt c-code. I tried very hard but I could not get the
222 * pseudo-dma to work in c-code without getting many overruns and
223 * underruns. If non-zero, doing_pdma encodes the direction of
224 * the transfer for debugging. 1=read 2=write
225 */
226extern char *pdma_vaddr;
227extern unsigned long pdma_size;
228extern volatile int doing_pdma;
229
230/* This is software state */
231extern char *pdma_base;
232extern unsigned long pdma_areasize;
233
234/* Common routines to all controller types on the Sparc. */
235static inline void virtual_dma_init(void)
236{
237 /* nothing... */
238}
239
240static inline void sun_fd_disable_dma(void)
241{
242 doing_pdma = 0;
243 if (pdma_base) {
244 mmu_unlockarea(pdma_base, pdma_areasize);
245 pdma_base = NULL;
246 }
247}
248
249static inline void sun_fd_set_dma_mode(int mode)
250{
251 switch(mode) {
252 case DMA_MODE_READ:
253 doing_pdma = 1;
254 break;
255 case DMA_MODE_WRITE:
256 doing_pdma = 2;
257 break;
258 default:
259 printk("Unknown dma mode %d\n", mode);
260 panic("floppy: Giving up...");
261 }
262}
263
264static inline void sun_fd_set_dma_addr(char *buffer)
265{
266 pdma_vaddr = buffer;
267}
268
269static inline void sun_fd_set_dma_count(int length)
270{
271 pdma_size = length;
272}
273
274static inline void sun_fd_enable_dma(void)
275{
276 pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
277 pdma_base = pdma_vaddr;
278 pdma_areasize = pdma_size;
279}
280
281/* Our low-level entry point in arch/sparc/kernel/entry.S */
282extern int sparc_floppy_request_irq(int irq, unsigned long flags,
283 irq_handler_t irq_handler);
284
285static int sun_fd_request_irq(void)
286{
287 static int once = 0;
288 int error;
289
290 if(!once) {
291 once = 1;
292 error = sparc_floppy_request_irq(FLOPPY_IRQ,
293 IRQF_DISABLED,
294 floppy_interrupt);
295 return ((error == 0) ? 0 : -1);
296 } else return 0;
297}
298
299static struct linux_prom_registers fd_regs[2];
300
301static int sun_floppy_init(void)
302{
303 char state[128];
304 int tnode, fd_node, num_regs;
305 struct resource r;
306
307 use_virtual_dma = 1;
308
309 FLOPPY_IRQ = 11;
310 /* Forget it if we aren't on a machine that could possibly
311 * ever have a floppy drive.
312 */
313 if((sparc_cpu_model != sun4c && sparc_cpu_model != sun4m) ||
314 ((idprom->id_machtype == (SM_SUN4C | SM_4C_SLC)) ||
315 (idprom->id_machtype == (SM_SUN4C | SM_4C_ELC)))) {
316 /* We certainly don't have a floppy controller. */
317 goto no_sun_fdc;
318 }
319 /* Well, try to find one. */
320 tnode = prom_getchild(prom_root_node);
321 fd_node = prom_searchsiblings(tnode, "obio");
322 if(fd_node != 0) {
323 tnode = prom_getchild(fd_node);
324 fd_node = prom_searchsiblings(tnode, "SUNW,fdtwo");
325 } else {
326 fd_node = prom_searchsiblings(tnode, "fd");
327 }
328 if(fd_node == 0) {
329 goto no_sun_fdc;
330 }
331
332 /* The sun4m lets us know if the controller is actually usable. */
333 if(sparc_cpu_model == sun4m &&
334 prom_getproperty(fd_node, "status", state, sizeof(state)) != -1) {
335 if(!strcmp(state, "disabled")) {
336 goto no_sun_fdc;
337 }
338 }
339 num_regs = prom_getproperty(fd_node, "reg", (char *) fd_regs, sizeof(fd_regs));
340 num_regs = (num_regs / sizeof(fd_regs[0]));
341 prom_apply_obio_ranges(fd_regs, num_regs);
342 memset(&r, 0, sizeof(r));
343 r.flags = fd_regs[0].which_io;
344 r.start = fd_regs[0].phys_addr;
345 sun_fdc = (struct sun_flpy_controller *)
346 sbus_ioremap(&r, 0, fd_regs[0].reg_size, "floppy");
347
348 /* Last minute sanity check... */
349 if(sun_fdc->status_82072 == 0xff) {
350 sun_fdc = NULL;
351 goto no_sun_fdc;
352 }
353
354 sun_fdops.fd_inb = sun_82077_fd_inb;
355 sun_fdops.fd_outb = sun_82077_fd_outb;
356 fdc_status = &sun_fdc->status_82077;
357
358 if (sun_fdc->dor_82077 == 0x80) {
359 sun_fdc->dor_82077 = 0x02;
360 if (sun_fdc->dor_82077 == 0x80) {
361 sun_fdops.fd_inb = sun_82072_fd_inb;
362 sun_fdops.fd_outb = sun_82072_fd_outb;
363 fdc_status = &sun_fdc->status_82072;
364 }
365 }
366
367 /* Success... */
368 allowed_drive_mask = 0x01;
369 return (int) sun_fdc;
370
371no_sun_fdc:
372 return -1;
373}
374
375static int sparc_eject(void)
376{
377 set_dor(0x00, 0xff, 0x90);
378 udelay(500);
379 set_dor(0x00, 0x6f, 0x00);
380 udelay(500);
381 return 0;
382}
383
384#define fd_eject(drive) sparc_eject()
385
386#define EXTRA_FLOPPY_PARAMS
387
388#endif /* !(__ASM_SPARC_FLOPPY_H) */
diff --git a/include/asm-sparc/floppy_32.h b/include/asm-sparc/floppy_32.h
new file mode 100644
index 000000000000..acdd06eafe59
--- /dev/null
+++ b/include/asm-sparc/floppy_32.h
@@ -0,0 +1,388 @@
1/* asm-sparc/floppy.h: Sparc specific parts of the Floppy driver.
2 *
3 * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef __ASM_SPARC_FLOPPY_H
7#define __ASM_SPARC_FLOPPY_H
8
9#include <asm/page.h>
10#include <asm/pgtable.h>
11#include <asm/system.h>
12#include <asm/idprom.h>
13#include <asm/machines.h>
14#include <asm/oplib.h>
15#include <asm/auxio.h>
16#include <asm/irq.h>
17
18/* We don't need no stinkin' I/O port allocation crap. */
19#undef release_region
20#undef request_region
21#define release_region(X, Y) do { } while(0)
22#define request_region(X, Y, Z) (1)
23
24/* References:
25 * 1) Netbsd Sun floppy driver.
26 * 2) NCR 82077 controller manual
27 * 3) Intel 82077 controller manual
28 */
29struct sun_flpy_controller {
30 volatile unsigned char status_82072; /* Main Status reg. */
31#define dcr_82072 status_82072 /* Digital Control reg. */
32#define status1_82077 status_82072 /* Auxiliary Status reg. 1 */
33
34 volatile unsigned char data_82072; /* Data fifo. */
35#define status2_82077 data_82072 /* Auxiliary Status reg. 2 */
36
37 volatile unsigned char dor_82077; /* Digital Output reg. */
38 volatile unsigned char tapectl_82077; /* What the? Tape control reg? */
39
40 volatile unsigned char status_82077; /* Main Status Register. */
41#define drs_82077 status_82077 /* Digital Rate Select reg. */
42
43 volatile unsigned char data_82077; /* Data fifo. */
44 volatile unsigned char ___unused;
45 volatile unsigned char dir_82077; /* Digital Input reg. */
46#define dcr_82077 dir_82077 /* Config Control reg. */
47};
48
49/* You'll only ever find one controller on a SparcStation anyways. */
50static struct sun_flpy_controller *sun_fdc = NULL;
51extern volatile unsigned char *fdc_status;
52
53struct sun_floppy_ops {
54 unsigned char (*fd_inb)(int port);
55 void (*fd_outb)(unsigned char value, int port);
56};
57
58static struct sun_floppy_ops sun_fdops;
59
60#define fd_inb(port) sun_fdops.fd_inb(port)
61#define fd_outb(value,port) sun_fdops.fd_outb(value,port)
62#define fd_enable_dma() sun_fd_enable_dma()
63#define fd_disable_dma() sun_fd_disable_dma()
64#define fd_request_dma() (0) /* nothing... */
65#define fd_free_dma() /* nothing... */
66#define fd_clear_dma_ff() /* nothing... */
67#define fd_set_dma_mode(mode) sun_fd_set_dma_mode(mode)
68#define fd_set_dma_addr(addr) sun_fd_set_dma_addr(addr)
69#define fd_set_dma_count(count) sun_fd_set_dma_count(count)
70#define fd_enable_irq() /* nothing... */
71#define fd_disable_irq() /* nothing... */
72#define fd_cacheflush(addr, size) /* nothing... */
73#define fd_request_irq() sun_fd_request_irq()
74#define fd_free_irq() /* nothing... */
75#if 0 /* P3: added by Alain, these cause a MMU corruption. 19960524 XXX */
76#define fd_dma_mem_alloc(size) ((unsigned long) vmalloc(size))
77#define fd_dma_mem_free(addr,size) (vfree((void *)(addr)))
78#endif
79
80/* XXX This isn't really correct. XXX */
81#define get_dma_residue(x) (0)
82
83#define FLOPPY0_TYPE 4
84#define FLOPPY1_TYPE 0
85
86/* Super paranoid... */
87#undef HAVE_DISABLE_HLT
88
89/* Here is where we catch the floppy driver trying to initialize,
90 * therefore this is where we call the PROM device tree probing
91 * routine etc. on the Sparc.
92 */
93#define FDC1 sun_floppy_init()
94
95#define N_FDC 1
96#define N_DRIVE 8
97
98/* No 64k boundary crossing problems on the Sparc. */
99#define CROSS_64KB(a,s) (0)
100
101/* Routines unique to each controller type on a Sun. */
102static void sun_set_dor(unsigned char value, int fdc_82077)
103{
104 if (sparc_cpu_model == sun4c) {
105 unsigned int bits = 0;
106 if (value & 0x10)
107 bits |= AUXIO_FLPY_DSEL;
108 if ((value & 0x80) == 0)
109 bits |= AUXIO_FLPY_EJCT;
110 set_auxio(bits, (~bits) & (AUXIO_FLPY_DSEL|AUXIO_FLPY_EJCT));
111 }
112 if (fdc_82077) {
113 sun_fdc->dor_82077 = value;
114 }
115}
116
117static unsigned char sun_read_dir(void)
118{
119 if (sparc_cpu_model == sun4c)
120 return (get_auxio() & AUXIO_FLPY_DCHG) ? 0x80 : 0;
121 else
122 return sun_fdc->dir_82077;
123}
124
125static unsigned char sun_82072_fd_inb(int port)
126{
127 udelay(5);
128 switch(port & 7) {
129 default:
130 printk("floppy: Asked to read unknown port %d\n", port);
131 panic("floppy: Port bolixed.");
132 case 4: /* FD_STATUS */
133 return sun_fdc->status_82072 & ~STATUS_DMA;
134 case 5: /* FD_DATA */
135 return sun_fdc->data_82072;
136 case 7: /* FD_DIR */
137 return sun_read_dir();
138 };
139 panic("sun_82072_fd_inb: How did I get here?");
140}
141
142static void sun_82072_fd_outb(unsigned char value, int port)
143{
144 udelay(5);
145 switch(port & 7) {
146 default:
147 printk("floppy: Asked to write to unknown port %d\n", port);
148 panic("floppy: Port bolixed.");
149 case 2: /* FD_DOR */
150 sun_set_dor(value, 0);
151 break;
152 case 5: /* FD_DATA */
153 sun_fdc->data_82072 = value;
154 break;
155 case 7: /* FD_DCR */
156 sun_fdc->dcr_82072 = value;
157 break;
158 case 4: /* FD_STATUS */
159 sun_fdc->status_82072 = value;
160 break;
161 };
162 return;
163}
164
165static unsigned char sun_82077_fd_inb(int port)
166{
167 udelay(5);
168 switch(port & 7) {
169 default:
170 printk("floppy: Asked to read unknown port %d\n", port);
171 panic("floppy: Port bolixed.");
172 case 0: /* FD_STATUS_0 */
173 return sun_fdc->status1_82077;
174 case 1: /* FD_STATUS_1 */
175 return sun_fdc->status2_82077;
176 case 2: /* FD_DOR */
177 return sun_fdc->dor_82077;
178 case 3: /* FD_TDR */
179 return sun_fdc->tapectl_82077;
180 case 4: /* FD_STATUS */
181 return sun_fdc->status_82077 & ~STATUS_DMA;
182 case 5: /* FD_DATA */
183 return sun_fdc->data_82077;
184 case 7: /* FD_DIR */
185 return sun_read_dir();
186 };
187 panic("sun_82077_fd_inb: How did I get here?");
188}
189
190static void sun_82077_fd_outb(unsigned char value, int port)
191{
192 udelay(5);
193 switch(port & 7) {
194 default:
195 printk("floppy: Asked to write to unknown port %d\n", port);
196 panic("floppy: Port bolixed.");
197 case 2: /* FD_DOR */
198 sun_set_dor(value, 1);
199 break;
200 case 5: /* FD_DATA */
201 sun_fdc->data_82077 = value;
202 break;
203 case 7: /* FD_DCR */
204 sun_fdc->dcr_82077 = value;
205 break;
206 case 4: /* FD_STATUS */
207 sun_fdc->status_82077 = value;
208 break;
209 case 3: /* FD_TDR */
210 sun_fdc->tapectl_82077 = value;
211 break;
212 };
213 return;
214}
215
216/* For pseudo-dma (Sun floppy drives have no real DMA available to
217 * them so we must eat the data fifo bytes directly ourselves) we have
218 * three state variables. doing_pdma tells our inline low-level
219 * assembly floppy interrupt entry point whether it should sit and eat
220 * bytes from the fifo or just transfer control up to the higher level
221 * floppy interrupt c-code. I tried very hard but I could not get the
222 * pseudo-dma to work in c-code without getting many overruns and
223 * underruns. If non-zero, doing_pdma encodes the direction of
224 * the transfer for debugging. 1=read 2=write
225 */
226extern char *pdma_vaddr;
227extern unsigned long pdma_size;
228extern volatile int doing_pdma;
229
230/* This is software state */
231extern char *pdma_base;
232extern unsigned long pdma_areasize;
233
234/* Common routines to all controller types on the Sparc. */
235static inline void virtual_dma_init(void)
236{
237 /* nothing... */
238}
239
240static inline void sun_fd_disable_dma(void)
241{
242 doing_pdma = 0;
243 if (pdma_base) {
244 mmu_unlockarea(pdma_base, pdma_areasize);
245 pdma_base = NULL;
246 }
247}
248
249static inline void sun_fd_set_dma_mode(int mode)
250{
251 switch(mode) {
252 case DMA_MODE_READ:
253 doing_pdma = 1;
254 break;
255 case DMA_MODE_WRITE:
256 doing_pdma = 2;
257 break;
258 default:
259 printk("Unknown dma mode %d\n", mode);
260 panic("floppy: Giving up...");
261 }
262}
263
264static inline void sun_fd_set_dma_addr(char *buffer)
265{
266 pdma_vaddr = buffer;
267}
268
269static inline void sun_fd_set_dma_count(int length)
270{
271 pdma_size = length;
272}
273
274static inline void sun_fd_enable_dma(void)
275{
276 pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
277 pdma_base = pdma_vaddr;
278 pdma_areasize = pdma_size;
279}
280
281/* Our low-level entry point in arch/sparc/kernel/entry.S */
282extern int sparc_floppy_request_irq(int irq, unsigned long flags,
283 irq_handler_t irq_handler);
284
285static int sun_fd_request_irq(void)
286{
287 static int once = 0;
288 int error;
289
290 if(!once) {
291 once = 1;
292 error = sparc_floppy_request_irq(FLOPPY_IRQ,
293 IRQF_DISABLED,
294 floppy_interrupt);
295 return ((error == 0) ? 0 : -1);
296 } else return 0;
297}
298
299static struct linux_prom_registers fd_regs[2];
300
301static int sun_floppy_init(void)
302{
303 char state[128];
304 int tnode, fd_node, num_regs;
305 struct resource r;
306
307 use_virtual_dma = 1;
308
309 FLOPPY_IRQ = 11;
310 /* Forget it if we aren't on a machine that could possibly
311 * ever have a floppy drive.
312 */
313 if((sparc_cpu_model != sun4c && sparc_cpu_model != sun4m) ||
314 ((idprom->id_machtype == (SM_SUN4C | SM_4C_SLC)) ||
315 (idprom->id_machtype == (SM_SUN4C | SM_4C_ELC)))) {
316 /* We certainly don't have a floppy controller. */
317 goto no_sun_fdc;
318 }
319 /* Well, try to find one. */
320 tnode = prom_getchild(prom_root_node);
321 fd_node = prom_searchsiblings(tnode, "obio");
322 if(fd_node != 0) {
323 tnode = prom_getchild(fd_node);
324 fd_node = prom_searchsiblings(tnode, "SUNW,fdtwo");
325 } else {
326 fd_node = prom_searchsiblings(tnode, "fd");
327 }
328 if(fd_node == 0) {
329 goto no_sun_fdc;
330 }
331
332 /* The sun4m lets us know if the controller is actually usable. */
333 if(sparc_cpu_model == sun4m &&
334 prom_getproperty(fd_node, "status", state, sizeof(state)) != -1) {
335 if(!strcmp(state, "disabled")) {
336 goto no_sun_fdc;
337 }
338 }
339 num_regs = prom_getproperty(fd_node, "reg", (char *) fd_regs, sizeof(fd_regs));
340 num_regs = (num_regs / sizeof(fd_regs[0]));
341 prom_apply_obio_ranges(fd_regs, num_regs);
342 memset(&r, 0, sizeof(r));
343 r.flags = fd_regs[0].which_io;
344 r.start = fd_regs[0].phys_addr;
345 sun_fdc = (struct sun_flpy_controller *)
346 sbus_ioremap(&r, 0, fd_regs[0].reg_size, "floppy");
347
348 /* Last minute sanity check... */
349 if(sun_fdc->status_82072 == 0xff) {
350 sun_fdc = NULL;
351 goto no_sun_fdc;
352 }
353
354 sun_fdops.fd_inb = sun_82077_fd_inb;
355 sun_fdops.fd_outb = sun_82077_fd_outb;
356 fdc_status = &sun_fdc->status_82077;
357
358 if (sun_fdc->dor_82077 == 0x80) {
359 sun_fdc->dor_82077 = 0x02;
360 if (sun_fdc->dor_82077 == 0x80) {
361 sun_fdops.fd_inb = sun_82072_fd_inb;
362 sun_fdops.fd_outb = sun_82072_fd_outb;
363 fdc_status = &sun_fdc->status_82072;
364 }
365 }
366
367 /* Success... */
368 allowed_drive_mask = 0x01;
369 return (int) sun_fdc;
370
371no_sun_fdc:
372 return -1;
373}
374
375static int sparc_eject(void)
376{
377 set_dor(0x00, 0xff, 0x90);
378 udelay(500);
379 set_dor(0x00, 0x6f, 0x00);
380 udelay(500);
381 return 0;
382}
383
384#define fd_eject(drive) sparc_eject()
385
386#define EXTRA_FLOPPY_PARAMS
387
388#endif /* !(__ASM_SPARC_FLOPPY_H) */
diff --git a/include/asm-sparc/floppy_64.h b/include/asm-sparc/floppy_64.h
new file mode 100644
index 000000000000..c39db1060bc7
--- /dev/null
+++ b/include/asm-sparc/floppy_64.h
@@ -0,0 +1,782 @@
1/* floppy.h: Sparc specific parts of the Floppy driver.
2 *
3 * Copyright (C) 1996, 2007 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 *
6 * Ultra/PCI support added: Sep 1997 Eddie C. Dost (ecd@skynet.be)
7 */
8
9#ifndef __ASM_SPARC64_FLOPPY_H
10#define __ASM_SPARC64_FLOPPY_H
11
12#include <linux/init.h>
13#include <linux/pci.h>
14
15#include <asm/page.h>
16#include <asm/pgtable.h>
17#include <asm/system.h>
18#include <asm/idprom.h>
19#include <asm/oplib.h>
20#include <asm/auxio.h>
21#include <asm/sbus.h>
22#include <asm/irq.h>
23
24
25/*
26 * Define this to enable exchanging drive 0 and 1 if only drive 1 is
27 * probed on PCI machines.
28 */
29#undef PCI_FDC_SWAP_DRIVES
30
31
32/* References:
33 * 1) Netbsd Sun floppy driver.
34 * 2) NCR 82077 controller manual
35 * 3) Intel 82077 controller manual
36 */
37struct sun_flpy_controller {
38 volatile unsigned char status1_82077; /* Auxiliary Status reg. 1 */
39 volatile unsigned char status2_82077; /* Auxiliary Status reg. 2 */
40 volatile unsigned char dor_82077; /* Digital Output reg. */
41 volatile unsigned char tapectl_82077; /* Tape Control reg */
42 volatile unsigned char status_82077; /* Main Status Register. */
43#define drs_82077 status_82077 /* Digital Rate Select reg. */
44 volatile unsigned char data_82077; /* Data fifo. */
45 volatile unsigned char ___unused;
46 volatile unsigned char dir_82077; /* Digital Input reg. */
47#define dcr_82077 dir_82077 /* Config Control reg. */
48};
49
50/* You'll only ever find one controller on an Ultra anyways. */
51static struct sun_flpy_controller *sun_fdc = (struct sun_flpy_controller *)-1;
52unsigned long fdc_status;
53static struct sbus_dev *floppy_sdev = NULL;
54
55struct sun_floppy_ops {
56 unsigned char (*fd_inb) (unsigned long port);
57 void (*fd_outb) (unsigned char value, unsigned long port);
58 void (*fd_enable_dma) (void);
59 void (*fd_disable_dma) (void);
60 void (*fd_set_dma_mode) (int);
61 void (*fd_set_dma_addr) (char *);
62 void (*fd_set_dma_count) (int);
63 unsigned int (*get_dma_residue) (void);
64 int (*fd_request_irq) (void);
65 void (*fd_free_irq) (void);
66 int (*fd_eject) (int);
67};
68
69static struct sun_floppy_ops sun_fdops;
70
71#define fd_inb(port) sun_fdops.fd_inb(port)
72#define fd_outb(value,port) sun_fdops.fd_outb(value,port)
73#define fd_enable_dma() sun_fdops.fd_enable_dma()
74#define fd_disable_dma() sun_fdops.fd_disable_dma()
75#define fd_request_dma() (0) /* nothing... */
76#define fd_free_dma() /* nothing... */
77#define fd_clear_dma_ff() /* nothing... */
78#define fd_set_dma_mode(mode) sun_fdops.fd_set_dma_mode(mode)
79#define fd_set_dma_addr(addr) sun_fdops.fd_set_dma_addr(addr)
80#define fd_set_dma_count(count) sun_fdops.fd_set_dma_count(count)
81#define get_dma_residue(x) sun_fdops.get_dma_residue()
82#define fd_cacheflush(addr, size) /* nothing... */
83#define fd_request_irq() sun_fdops.fd_request_irq()
84#define fd_free_irq() sun_fdops.fd_free_irq()
85#define fd_eject(drive) sun_fdops.fd_eject(drive)
86
87/* Super paranoid... */
88#undef HAVE_DISABLE_HLT
89
90static int sun_floppy_types[2] = { 0, 0 };
91
92/* Here is where we catch the floppy driver trying to initialize,
93 * therefore this is where we call the PROM device tree probing
94 * routine etc. on the Sparc.
95 */
96#define FLOPPY0_TYPE sun_floppy_init()
97#define FLOPPY1_TYPE sun_floppy_types[1]
98
99#define FDC1 ((unsigned long)sun_fdc)
100
101#define N_FDC 1
102#define N_DRIVE 8
103
104/* No 64k boundary crossing problems on the Sparc. */
105#define CROSS_64KB(a,s) (0)
106
107static unsigned char sun_82077_fd_inb(unsigned long port)
108{
109 udelay(5);
110 switch(port & 7) {
111 default:
112 printk("floppy: Asked to read unknown port %lx\n", port);
113 panic("floppy: Port bolixed.");
114 case 4: /* FD_STATUS */
115 return sbus_readb(&sun_fdc->status_82077) & ~STATUS_DMA;
116 case 5: /* FD_DATA */
117 return sbus_readb(&sun_fdc->data_82077);
118 case 7: /* FD_DIR */
119 /* XXX: Is DCL on 0x80 in sun4m? */
120 return sbus_readb(&sun_fdc->dir_82077);
121 };
122 panic("sun_82072_fd_inb: How did I get here?");
123}
124
125static void sun_82077_fd_outb(unsigned char value, unsigned long port)
126{
127 udelay(5);
128 switch(port & 7) {
129 default:
130 printk("floppy: Asked to write to unknown port %lx\n", port);
131 panic("floppy: Port bolixed.");
132 case 2: /* FD_DOR */
133 /* Happily, the 82077 has a real DOR register. */
134 sbus_writeb(value, &sun_fdc->dor_82077);
135 break;
136 case 5: /* FD_DATA */
137 sbus_writeb(value, &sun_fdc->data_82077);
138 break;
139 case 7: /* FD_DCR */
140 sbus_writeb(value, &sun_fdc->dcr_82077);
141 break;
142 case 4: /* FD_STATUS */
143 sbus_writeb(value, &sun_fdc->status_82077);
144 break;
145 };
146 return;
147}
148
149/* For pseudo-dma (Sun floppy drives have no real DMA available to
150 * them so we must eat the data fifo bytes directly ourselves) we have
151 * three state variables. doing_pdma tells our inline low-level
152 * assembly floppy interrupt entry point whether it should sit and eat
153 * bytes from the fifo or just transfer control up to the higher level
154 * floppy interrupt c-code. I tried very hard but I could not get the
155 * pseudo-dma to work in c-code without getting many overruns and
156 * underruns. If non-zero, doing_pdma encodes the direction of
157 * the transfer for debugging. 1=read 2=write
158 */
159unsigned char *pdma_vaddr;
160unsigned long pdma_size;
161volatile int doing_pdma = 0;
162
163/* This is software state */
164char *pdma_base = NULL;
165unsigned long pdma_areasize;
166
167/* Common routines to all controller types on the Sparc. */
168static void sun_fd_disable_dma(void)
169{
170 doing_pdma = 0;
171 if (pdma_base) {
172 mmu_unlockarea(pdma_base, pdma_areasize);
173 pdma_base = NULL;
174 }
175}
176
177static void sun_fd_set_dma_mode(int mode)
178{
179 switch(mode) {
180 case DMA_MODE_READ:
181 doing_pdma = 1;
182 break;
183 case DMA_MODE_WRITE:
184 doing_pdma = 2;
185 break;
186 default:
187 printk("Unknown dma mode %d\n", mode);
188 panic("floppy: Giving up...");
189 }
190}
191
192static void sun_fd_set_dma_addr(char *buffer)
193{
194 pdma_vaddr = buffer;
195}
196
197static void sun_fd_set_dma_count(int length)
198{
199 pdma_size = length;
200}
201
202static void sun_fd_enable_dma(void)
203{
204 pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
205 pdma_base = pdma_vaddr;
206 pdma_areasize = pdma_size;
207}
208
209irqreturn_t sparc_floppy_irq(int irq, void *dev_cookie)
210{
211 if (likely(doing_pdma)) {
212 void __iomem *stat = (void __iomem *) fdc_status;
213 unsigned char *vaddr = pdma_vaddr;
214 unsigned long size = pdma_size;
215 u8 val;
216
217 while (size) {
218 val = readb(stat);
219 if (unlikely(!(val & 0x80))) {
220 pdma_vaddr = vaddr;
221 pdma_size = size;
222 return IRQ_HANDLED;
223 }
224 if (unlikely(!(val & 0x20))) {
225 pdma_vaddr = vaddr;
226 pdma_size = size;
227 doing_pdma = 0;
228 goto main_interrupt;
229 }
230 if (val & 0x40) {
231 /* read */
232 *vaddr++ = readb(stat + 1);
233 } else {
234 unsigned char data = *vaddr++;
235
236 /* write */
237 writeb(data, stat + 1);
238 }
239 size--;
240 }
241
242 pdma_vaddr = vaddr;
243 pdma_size = size;
244
245 /* Send Terminal Count pulse to floppy controller. */
246 val = readb(auxio_register);
247 val |= AUXIO_AUX1_FTCNT;
248 writeb(val, auxio_register);
249 val &= ~AUXIO_AUX1_FTCNT;
250 writeb(val, auxio_register);
251
252 doing_pdma = 0;
253 }
254
255main_interrupt:
256 return floppy_interrupt(irq, dev_cookie);
257}
258
259static int sun_fd_request_irq(void)
260{
261 static int once = 0;
262 int error;
263
264 if(!once) {
265 once = 1;
266
267 error = request_irq(FLOPPY_IRQ, sparc_floppy_irq,
268 IRQF_DISABLED, "floppy", NULL);
269
270 return ((error == 0) ? 0 : -1);
271 }
272 return 0;
273}
274
275static void sun_fd_free_irq(void)
276{
277}
278
279static unsigned int sun_get_dma_residue(void)
280{
281 /* XXX This isn't really correct. XXX */
282 return 0;
283}
284
285static int sun_fd_eject(int drive)
286{
287 set_dor(0x00, 0xff, 0x90);
288 udelay(500);
289 set_dor(0x00, 0x6f, 0x00);
290 udelay(500);
291 return 0;
292}
293
294#ifdef CONFIG_PCI
295#include <asm/ebus.h>
296#include <asm/ns87303.h>
297
298static struct ebus_dma_info sun_pci_fd_ebus_dma;
299static struct pci_dev *sun_pci_ebus_dev;
300static int sun_pci_broken_drive = -1;
301
302struct sun_pci_dma_op {
303 unsigned int addr;
304 int len;
305 int direction;
306 char *buf;
307};
308static struct sun_pci_dma_op sun_pci_dma_current = { -1U, 0, 0, NULL};
309static struct sun_pci_dma_op sun_pci_dma_pending = { -1U, 0, 0, NULL};
310
311extern irqreturn_t floppy_interrupt(int irq, void *dev_id);
312
313static unsigned char sun_pci_fd_inb(unsigned long port)
314{
315 udelay(5);
316 return inb(port);
317}
318
319static void sun_pci_fd_outb(unsigned char val, unsigned long port)
320{
321 udelay(5);
322 outb(val, port);
323}
324
325static void sun_pci_fd_broken_outb(unsigned char val, unsigned long port)
326{
327 udelay(5);
328 /*
329 * XXX: Due to SUN's broken floppy connector on AX and AXi
330 * we need to turn on MOTOR_0 also, if the floppy is
331 * jumpered to DS1 (like most PC floppies are). I hope
332 * this does not hurt correct hardware like the AXmp.
333 * (Eddie, Sep 12 1998).
334 */
335 if (port == ((unsigned long)sun_fdc) + 2) {
336 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x20)) {
337 val |= 0x10;
338 }
339 }
340 outb(val, port);
341}
342
343#ifdef PCI_FDC_SWAP_DRIVES
344static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long port)
345{
346 udelay(5);
347 /*
348 * XXX: Due to SUN's broken floppy connector on AX and AXi
349 * we need to turn on MOTOR_0 also, if the floppy is
350 * jumpered to DS1 (like most PC floppies are). I hope
351 * this does not hurt correct hardware like the AXmp.
352 * (Eddie, Sep 12 1998).
353 */
354 if (port == ((unsigned long)sun_fdc) + 2) {
355 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x10)) {
356 val &= ~(0x03);
357 val |= 0x21;
358 }
359 }
360 outb(val, port);
361}
362#endif /* PCI_FDC_SWAP_DRIVES */
363
364static void sun_pci_fd_enable_dma(void)
365{
366 BUG_ON((NULL == sun_pci_dma_pending.buf) ||
367 (0 == sun_pci_dma_pending.len) ||
368 (0 == sun_pci_dma_pending.direction));
369
370 sun_pci_dma_current.buf = sun_pci_dma_pending.buf;
371 sun_pci_dma_current.len = sun_pci_dma_pending.len;
372 sun_pci_dma_current.direction = sun_pci_dma_pending.direction;
373
374 sun_pci_dma_pending.buf = NULL;
375 sun_pci_dma_pending.len = 0;
376 sun_pci_dma_pending.direction = 0;
377 sun_pci_dma_pending.addr = -1U;
378
379 sun_pci_dma_current.addr =
380 pci_map_single(sun_pci_ebus_dev,
381 sun_pci_dma_current.buf,
382 sun_pci_dma_current.len,
383 sun_pci_dma_current.direction);
384
385 ebus_dma_enable(&sun_pci_fd_ebus_dma, 1);
386
387 if (ebus_dma_request(&sun_pci_fd_ebus_dma,
388 sun_pci_dma_current.addr,
389 sun_pci_dma_current.len))
390 BUG();
391}
392
393static void sun_pci_fd_disable_dma(void)
394{
395 ebus_dma_enable(&sun_pci_fd_ebus_dma, 0);
396 if (sun_pci_dma_current.addr != -1U)
397 pci_unmap_single(sun_pci_ebus_dev,
398 sun_pci_dma_current.addr,
399 sun_pci_dma_current.len,
400 sun_pci_dma_current.direction);
401 sun_pci_dma_current.addr = -1U;
402}
403
404static void sun_pci_fd_set_dma_mode(int mode)
405{
406 if (mode == DMA_MODE_WRITE)
407 sun_pci_dma_pending.direction = PCI_DMA_TODEVICE;
408 else
409 sun_pci_dma_pending.direction = PCI_DMA_FROMDEVICE;
410
411 ebus_dma_prepare(&sun_pci_fd_ebus_dma, mode != DMA_MODE_WRITE);
412}
413
414static void sun_pci_fd_set_dma_count(int length)
415{
416 sun_pci_dma_pending.len = length;
417}
418
419static void sun_pci_fd_set_dma_addr(char *buffer)
420{
421 sun_pci_dma_pending.buf = buffer;
422}
423
424static unsigned int sun_pci_get_dma_residue(void)
425{
426 return ebus_dma_residue(&sun_pci_fd_ebus_dma);
427}
428
429static int sun_pci_fd_request_irq(void)
430{
431 return ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 1);
432}
433
434static void sun_pci_fd_free_irq(void)
435{
436 ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 0);
437}
438
439static int sun_pci_fd_eject(int drive)
440{
441 return -EINVAL;
442}
443
444void sun_pci_fd_dma_callback(struct ebus_dma_info *p, int event, void *cookie)
445{
446 floppy_interrupt(0, NULL);
447}
448
449/*
450 * Floppy probing, we'd like to use /dev/fd0 for a single Floppy on PCI,
451 * even if this is configured using DS1, thus looks like /dev/fd1 with
452 * the cabling used in Ultras.
453 */
454#define DOR (port + 2)
455#define MSR (port + 4)
456#define FIFO (port + 5)
457
458static void sun_pci_fd_out_byte(unsigned long port, unsigned char val,
459 unsigned long reg)
460{
461 unsigned char status;
462 int timeout = 1000;
463
464 while (!((status = inb(MSR)) & 0x80) && --timeout)
465 udelay(100);
466 outb(val, reg);
467}
468
469static unsigned char sun_pci_fd_sensei(unsigned long port)
470{
471 unsigned char result[2] = { 0x70, 0x00 };
472 unsigned char status;
473 int i = 0;
474
475 sun_pci_fd_out_byte(port, 0x08, FIFO);
476 do {
477 int timeout = 1000;
478
479 while (!((status = inb(MSR)) & 0x80) && --timeout)
480 udelay(100);
481
482 if (!timeout)
483 break;
484
485 if ((status & 0xf0) == 0xd0)
486 result[i++] = inb(FIFO);
487 else
488 break;
489 } while (i < 2);
490
491 return result[0];
492}
493
494static void sun_pci_fd_reset(unsigned long port)
495{
496 unsigned char mask = 0x00;
497 unsigned char status;
498 int timeout = 10000;
499
500 outb(0x80, MSR);
501 do {
502 status = sun_pci_fd_sensei(port);
503 if ((status & 0xc0) == 0xc0)
504 mask |= 1 << (status & 0x03);
505 else
506 udelay(100);
507 } while ((mask != 0x0f) && --timeout);
508}
509
510static int sun_pci_fd_test_drive(unsigned long port, int drive)
511{
512 unsigned char status, data;
513 int timeout = 1000;
514 int ready;
515
516 sun_pci_fd_reset(port);
517
518 data = (0x10 << drive) | 0x0c | drive;
519 sun_pci_fd_out_byte(port, data, DOR);
520
521 sun_pci_fd_out_byte(port, 0x07, FIFO);
522 sun_pci_fd_out_byte(port, drive & 0x03, FIFO);
523
524 do {
525 udelay(100);
526 status = sun_pci_fd_sensei(port);
527 } while (((status & 0xc0) == 0x80) && --timeout);
528
529 if (!timeout)
530 ready = 0;
531 else
532 ready = (status & 0x10) ? 0 : 1;
533
534 sun_pci_fd_reset(port);
535 return ready;
536}
537#undef FIFO
538#undef MSR
539#undef DOR
540
541#endif /* CONFIG_PCI */
542
543#ifdef CONFIG_PCI
544static int __init ebus_fdthree_p(struct linux_ebus_device *edev)
545{
546 if (!strcmp(edev->prom_node->name, "fdthree"))
547 return 1;
548 if (!strcmp(edev->prom_node->name, "floppy")) {
549 const char *compat;
550
551 compat = of_get_property(edev->prom_node,
552 "compatible", NULL);
553 if (compat && !strcmp(compat, "fdthree"))
554 return 1;
555 }
556 return 0;
557}
558#endif
559
560static unsigned long __init sun_floppy_init(void)
561{
562 char state[128];
563 struct sbus_bus *bus;
564 struct sbus_dev *sdev = NULL;
565 static int initialized = 0;
566
567 if (initialized)
568 return sun_floppy_types[0];
569 initialized = 1;
570
571 for_all_sbusdev (sdev, bus) {
572 if (!strcmp(sdev->prom_name, "SUNW,fdtwo"))
573 break;
574 }
575 if(sdev) {
576 floppy_sdev = sdev;
577 FLOPPY_IRQ = sdev->irqs[0];
578 } else {
579#ifdef CONFIG_PCI
580 struct linux_ebus *ebus;
581 struct linux_ebus_device *edev = NULL;
582 unsigned long config = 0;
583 void __iomem *auxio_reg;
584 const char *state_prop;
585
586 for_each_ebus(ebus) {
587 for_each_ebusdev(edev, ebus) {
588 if (ebus_fdthree_p(edev))
589 goto ebus_done;
590 }
591 }
592 ebus_done:
593 if (!edev)
594 return 0;
595
596 state_prop = of_get_property(edev->prom_node, "status", NULL);
597 if (state_prop && !strncmp(state_prop, "disabled", 8))
598 return 0;
599
600 FLOPPY_IRQ = edev->irqs[0];
601
602 /* Make sure the high density bit is set, some systems
603 * (most notably Ultra5/Ultra10) come up with it clear.
604 */
605 auxio_reg = (void __iomem *) edev->resource[2].start;
606 writel(readl(auxio_reg)|0x2, auxio_reg);
607
608 sun_pci_ebus_dev = ebus->self;
609
610 spin_lock_init(&sun_pci_fd_ebus_dma.lock);
611
612 /* XXX ioremap */
613 sun_pci_fd_ebus_dma.regs = (void __iomem *)
614 edev->resource[1].start;
615 if (!sun_pci_fd_ebus_dma.regs)
616 return 0;
617
618 sun_pci_fd_ebus_dma.flags = (EBUS_DMA_FLAG_USE_EBDMA_HANDLER |
619 EBUS_DMA_FLAG_TCI_DISABLE);
620 sun_pci_fd_ebus_dma.callback = sun_pci_fd_dma_callback;
621 sun_pci_fd_ebus_dma.client_cookie = NULL;
622 sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ;
623 strcpy(sun_pci_fd_ebus_dma.name, "floppy");
624 if (ebus_dma_register(&sun_pci_fd_ebus_dma))
625 return 0;
626
627 /* XXX ioremap */
628 sun_fdc = (struct sun_flpy_controller *)edev->resource[0].start;
629
630 sun_fdops.fd_inb = sun_pci_fd_inb;
631 sun_fdops.fd_outb = sun_pci_fd_outb;
632
633 can_use_virtual_dma = use_virtual_dma = 0;
634 sun_fdops.fd_enable_dma = sun_pci_fd_enable_dma;
635 sun_fdops.fd_disable_dma = sun_pci_fd_disable_dma;
636 sun_fdops.fd_set_dma_mode = sun_pci_fd_set_dma_mode;
637 sun_fdops.fd_set_dma_addr = sun_pci_fd_set_dma_addr;
638 sun_fdops.fd_set_dma_count = sun_pci_fd_set_dma_count;
639 sun_fdops.get_dma_residue = sun_pci_get_dma_residue;
640
641 sun_fdops.fd_request_irq = sun_pci_fd_request_irq;
642 sun_fdops.fd_free_irq = sun_pci_fd_free_irq;
643
644 sun_fdops.fd_eject = sun_pci_fd_eject;
645
646 fdc_status = (unsigned long) &sun_fdc->status_82077;
647
648 /*
649 * XXX: Find out on which machines this is really needed.
650 */
651 if (1) {
652 sun_pci_broken_drive = 1;
653 sun_fdops.fd_outb = sun_pci_fd_broken_outb;
654 }
655
656 allowed_drive_mask = 0;
657 if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 0))
658 sun_floppy_types[0] = 4;
659 if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 1))
660 sun_floppy_types[1] = 4;
661
662 /*
663 * Find NS87303 SuperIO config registers (through ecpp).
664 */
665 for_each_ebus(ebus) {
666 for_each_ebusdev(edev, ebus) {
667 if (!strcmp(edev->prom_node->name, "ecpp")) {
668 config = edev->resource[1].start;
669 goto config_done;
670 }
671 }
672 }
673 config_done:
674
675 /*
676 * Sanity check, is this really the NS87303?
677 */
678 switch (config & 0x3ff) {
679 case 0x02e:
680 case 0x15c:
681 case 0x26e:
682 case 0x398:
683 break;
684 default:
685 config = 0;
686 }
687
688 if (!config)
689 return sun_floppy_types[0];
690
691 /* Enable PC-AT mode. */
692 ns87303_modify(config, ASC, 0, 0xc0);
693
694#ifdef PCI_FDC_SWAP_DRIVES
695 /*
696 * If only Floppy 1 is present, swap drives.
697 */
698 if (!sun_floppy_types[0] && sun_floppy_types[1]) {
699 /*
700 * Set the drive exchange bit in FCR on NS87303,
701 * make sure other bits are sane before doing so.
702 */
703 ns87303_modify(config, FER, FER_EDM, 0);
704 ns87303_modify(config, ASC, ASC_DRV2_SEL, 0);
705 ns87303_modify(config, FCR, 0, FCR_LDE);
706
707 config = sun_floppy_types[0];
708 sun_floppy_types[0] = sun_floppy_types[1];
709 sun_floppy_types[1] = config;
710
711 if (sun_pci_broken_drive != -1) {
712 sun_pci_broken_drive = 1 - sun_pci_broken_drive;
713 sun_fdops.fd_outb = sun_pci_fd_lde_broken_outb;
714 }
715 }
716#endif /* PCI_FDC_SWAP_DRIVES */
717
718 return sun_floppy_types[0];
719#else
720 return 0;
721#endif
722 }
723 prom_getproperty(sdev->prom_node, "status", state, sizeof(state));
724 if(!strncmp(state, "disabled", 8))
725 return 0;
726
727 /*
728 * We cannot do sbus_ioremap here: it does request_region,
729 * which the generic floppy driver tries to do once again.
730 * But we must use the sdev resource values as they have
731 * had parent ranges applied.
732 */
733 sun_fdc = (struct sun_flpy_controller *)
734 (sdev->resource[0].start +
735 ((sdev->resource[0].flags & 0x1ffUL) << 32UL));
736
737 /* Last minute sanity check... */
738 if(sbus_readb(&sun_fdc->status1_82077) == 0xff) {
739 sun_fdc = (struct sun_flpy_controller *)-1;
740 return 0;
741 }
742
743 sun_fdops.fd_inb = sun_82077_fd_inb;
744 sun_fdops.fd_outb = sun_82077_fd_outb;
745
746 can_use_virtual_dma = use_virtual_dma = 1;
747 sun_fdops.fd_enable_dma = sun_fd_enable_dma;
748 sun_fdops.fd_disable_dma = sun_fd_disable_dma;
749 sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
750 sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
751 sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
752 sun_fdops.get_dma_residue = sun_get_dma_residue;
753
754 sun_fdops.fd_request_irq = sun_fd_request_irq;
755 sun_fdops.fd_free_irq = sun_fd_free_irq;
756
757 sun_fdops.fd_eject = sun_fd_eject;
758
759 fdc_status = (unsigned long) &sun_fdc->status_82077;
760
761 /* Success... */
762 allowed_drive_mask = 0x01;
763 sun_floppy_types[0] = 4;
764 sun_floppy_types[1] = 0;
765
766 return sun_floppy_types[0];
767}
768
769#define EXTRA_FLOPPY_PARAMS
770
771static DEFINE_SPINLOCK(dma_spin_lock);
772
773#define claim_dma_lock() \
774({ unsigned long flags; \
775 spin_lock_irqsave(&dma_spin_lock, flags); \
776 flags; \
777})
778
779#define release_dma_lock(__flags) \
780 spin_unlock_irqrestore(&dma_spin_lock, __flags);
781
782#endif /* !(__ASM_SPARC64_FLOPPY_H) */
diff --git a/include/asm-sparc/fpumacro.h b/include/asm-sparc/fpumacro.h
new file mode 100644
index 000000000000..cc463fec806f
--- /dev/null
+++ b/include/asm-sparc/fpumacro.h
@@ -0,0 +1,33 @@
1/* fpumacro.h: FPU related macros.
2 *
3 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef _SPARC64_FPUMACRO_H
8#define _SPARC64_FPUMACRO_H
9
10#include <asm/asi.h>
11#include <asm/visasm.h>
12
13struct fpustate {
14 u32 regs[64];
15};
16
17#define FPUSTATE (struct fpustate *)(current_thread_info()->fpregs)
18
19static inline unsigned long fprs_read(void)
20{
21 unsigned long retval;
22
23 __asm__ __volatile__("rd %%fprs, %0" : "=r" (retval));
24
25 return retval;
26}
27
28static inline void fprs_write(unsigned long val)
29{
30 __asm__ __volatile__("wr %0, 0x0, %%fprs" : : "r" (val));
31}
32
33#endif /* !(_SPARC64_FPUMACRO_H) */
diff --git a/include/asm-sparc/futex.h b/include/asm-sparc/futex.h
index 6a332a9f099c..c6a9f038c531 100644
--- a/include/asm-sparc/futex.h
+++ b/include/asm-sparc/futex.h
@@ -1,6 +1,8 @@
1#ifndef _ASM_FUTEX_H 1#ifndef ___ASM_SPARC_FUTEX_H
2#define _ASM_FUTEX_H 2#define ___ASM_SPARC_FUTEX_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <asm-generic/futex.h> 4#include <asm-sparc/futex_64.h>
5 5#else
6#include <asm-sparc/futex_32.h>
7#endif
6#endif 8#endif
diff --git a/include/asm-sparc/futex_32.h b/include/asm-sparc/futex_32.h
new file mode 100644
index 000000000000..6a332a9f099c
--- /dev/null
+++ b/include/asm-sparc/futex_32.h
@@ -0,0 +1,6 @@
1#ifndef _ASM_FUTEX_H
2#define _ASM_FUTEX_H
3
4#include <asm-generic/futex.h>
5
6#endif
diff --git a/include/asm-sparc/futex_64.h b/include/asm-sparc/futex_64.h
new file mode 100644
index 000000000000..d8378935ae90
--- /dev/null
+++ b/include/asm-sparc/futex_64.h
@@ -0,0 +1,110 @@
1#ifndef _SPARC64_FUTEX_H
2#define _SPARC64_FUTEX_H
3
4#include <linux/futex.h>
5#include <linux/uaccess.h>
6#include <asm/errno.h>
7#include <asm/system.h>
8
9#define __futex_cas_op(insn, ret, oldval, uaddr, oparg) \
10 __asm__ __volatile__( \
11 "\n1: lduwa [%3] %%asi, %2\n" \
12 " " insn "\n" \
13 "2: casa [%3] %%asi, %2, %1\n" \
14 " cmp %2, %1\n" \
15 " bne,pn %%icc, 1b\n" \
16 " mov 0, %0\n" \
17 "3:\n" \
18 " .section .fixup,#alloc,#execinstr\n" \
19 " .align 4\n" \
20 "4: sethi %%hi(3b), %0\n" \
21 " jmpl %0 + %%lo(3b), %%g0\n" \
22 " mov %5, %0\n" \
23 " .previous\n" \
24 " .section __ex_table,\"a\"\n" \
25 " .align 4\n" \
26 " .word 1b, 4b\n" \
27 " .word 2b, 4b\n" \
28 " .previous\n" \
29 : "=&r" (ret), "=&r" (oldval), "=&r" (tem) \
30 : "r" (uaddr), "r" (oparg), "i" (-EFAULT) \
31 : "memory")
32
33static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
34{
35 int op = (encoded_op >> 28) & 7;
36 int cmp = (encoded_op >> 24) & 15;
37 int oparg = (encoded_op << 8) >> 20;
38 int cmparg = (encoded_op << 20) >> 20;
39 int oldval = 0, ret, tem;
40
41 if (unlikely(!access_ok(VERIFY_WRITE, uaddr, sizeof(int))))
42 return -EFAULT;
43 if (unlikely((((unsigned long) uaddr) & 0x3UL)))
44 return -EINVAL;
45
46 if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
47 oparg = 1 << oparg;
48
49 pagefault_disable();
50
51 switch (op) {
52 case FUTEX_OP_SET:
53 __futex_cas_op("mov\t%4, %1", ret, oldval, uaddr, oparg);
54 break;
55 case FUTEX_OP_ADD:
56 __futex_cas_op("add\t%2, %4, %1", ret, oldval, uaddr, oparg);
57 break;
58 case FUTEX_OP_OR:
59 __futex_cas_op("or\t%2, %4, %1", ret, oldval, uaddr, oparg);
60 break;
61 case FUTEX_OP_ANDN:
62 __futex_cas_op("and\t%2, %4, %1", ret, oldval, uaddr, oparg);
63 break;
64 case FUTEX_OP_XOR:
65 __futex_cas_op("xor\t%2, %4, %1", ret, oldval, uaddr, oparg);
66 break;
67 default:
68 ret = -ENOSYS;
69 }
70
71 pagefault_enable();
72
73 if (!ret) {
74 switch (cmp) {
75 case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
76 case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
77 case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break;
78 case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break;
79 case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break;
80 case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break;
81 default: ret = -ENOSYS;
82 }
83 }
84 return ret;
85}
86
87static inline int
88futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
89{
90 __asm__ __volatile__(
91 "\n1: casa [%3] %%asi, %2, %0\n"
92 "2:\n"
93 " .section .fixup,#alloc,#execinstr\n"
94 " .align 4\n"
95 "3: sethi %%hi(2b), %0\n"
96 " jmpl %0 + %%lo(2b), %%g0\n"
97 " mov %4, %0\n"
98 " .previous\n"
99 " .section __ex_table,\"a\"\n"
100 " .align 4\n"
101 " .word 1b, 3b\n"
102 " .previous\n"
103 : "=r" (newval)
104 : "0" (newval), "r" (oldval), "r" (uaddr), "i" (-EFAULT)
105 : "memory");
106
107 return newval;
108}
109
110#endif /* !(_SPARC64_FUTEX_H) */
diff --git a/include/asm-sparc/hardirq.h b/include/asm-sparc/hardirq.h
index 4f63ed8df551..156478773100 100644
--- a/include/asm-sparc/hardirq.h
+++ b/include/asm-sparc/hardirq.h
@@ -1,23 +1,8 @@
1/* hardirq.h: 32-bit Sparc hard IRQ support. 1#ifndef ___ASM_SPARC_HARDIRQ_H
2 * 2#define ___ASM_SPARC_HARDIRQ_H
3 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 1998-2000 Anton Blanchard (anton@samba.org) 4#include <asm-sparc/hardirq_64.h>
5 */ 5#else
6 6#include <asm-sparc/hardirq_32.h>
7#ifndef __SPARC_HARDIRQ_H 7#endif
8#define __SPARC_HARDIRQ_H 8#endif
9
10#include <linux/threads.h>
11#include <linux/spinlock.h>
12#include <linux/cache.h>
13
14/* entry.S is sensitive to the offsets of these fields */ /* XXX P3 Is it? */
15typedef struct {
16 unsigned int __softirq_pending;
17} ____cacheline_aligned irq_cpustat_t;
18
19#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
20
21#define HARDIRQ_BITS 8
22
23#endif /* __SPARC_HARDIRQ_H */
diff --git a/include/asm-sparc/hardirq_32.h b/include/asm-sparc/hardirq_32.h
new file mode 100644
index 000000000000..4f63ed8df551
--- /dev/null
+++ b/include/asm-sparc/hardirq_32.h
@@ -0,0 +1,23 @@
1/* hardirq.h: 32-bit Sparc hard IRQ support.
2 *
3 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
4 * Copyright (C) 1998-2000 Anton Blanchard (anton@samba.org)
5 */
6
7#ifndef __SPARC_HARDIRQ_H
8#define __SPARC_HARDIRQ_H
9
10#include <linux/threads.h>
11#include <linux/spinlock.h>
12#include <linux/cache.h>
13
14/* entry.S is sensitive to the offsets of these fields */ /* XXX P3 Is it? */
15typedef struct {
16 unsigned int __softirq_pending;
17} ____cacheline_aligned irq_cpustat_t;
18
19#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
20
21#define HARDIRQ_BITS 8
22
23#endif /* __SPARC_HARDIRQ_H */
diff --git a/include/asm-sparc/hardirq_64.h b/include/asm-sparc/hardirq_64.h
new file mode 100644
index 000000000000..7c29fd1a87aa
--- /dev/null
+++ b/include/asm-sparc/hardirq_64.h
@@ -0,0 +1,19 @@
1/* hardirq.h: 64-bit Sparc hard IRQ support.
2 *
3 * Copyright (C) 1997, 1998, 2005 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef __SPARC64_HARDIRQ_H
7#define __SPARC64_HARDIRQ_H
8
9#include <asm/cpudata.h>
10
11#define __ARCH_IRQ_STAT
12#define local_softirq_pending() \
13 (local_cpu_data().__softirq_pending)
14
15void ack_bad_irq(unsigned int irq);
16
17#define HARDIRQ_BITS 8
18
19#endif /* !(__SPARC64_HARDIRQ_H) */
diff --git a/include/asm-sparc/head.h b/include/asm-sparc/head.h
index 7c35491a8b53..14652abdea31 100644
--- a/include/asm-sparc/head.h
+++ b/include/asm-sparc/head.h
@@ -1,102 +1,8 @@
1#ifndef __SPARC_HEAD_H 1#ifndef ___ASM_SPARC_HEAD_H
2#define __SPARC_HEAD_H 2#define ___ASM_SPARC_HEAD_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#define KERNBASE 0xf0000000 /* First address the kernel will eventually be */ 4#include <asm-sparc/head_64.h>
5#define LOAD_ADDR 0x4000 /* prom jumps to us here unless this is elf /boot */
6#define SUN4C_SEGSZ (1 << 18)
7#define SRMMU_L1_KBASE_OFFSET ((KERNBASE>>24)<<2) /* Used in boot remapping. */
8#define INTS_ENAB 0x01 /* entry.S uses this. */
9
10#define SUN4_PROM_VECTOR 0xFFE81000 /* SUN4 PROM needs to be hardwired */
11
12#define WRITE_PAUSE nop; nop; nop; /* Have to do this after %wim/%psr chg */
13#define NOP_INSN 0x01000000 /* Used to patch sparc_save_state */
14
15/* Here are some trap goodies */
16
17/* Generic trap entry. */
18#define TRAP_ENTRY(type, label) \
19 rd %psr, %l0; b label; rd %wim, %l3; nop;
20
21/* Data/text faults. Defaults to sun4c version at boot time. */
22#define SPARC_TFAULT rd %psr, %l0; rd %wim, %l3; b sun4c_fault; mov 1, %l7;
23#define SPARC_DFAULT rd %psr, %l0; rd %wim, %l3; b sun4c_fault; mov 0, %l7;
24#define SRMMU_TFAULT rd %psr, %l0; rd %wim, %l3; b srmmu_fault; mov 1, %l7;
25#define SRMMU_DFAULT rd %psr, %l0; rd %wim, %l3; b srmmu_fault; mov 0, %l7;
26
27/* This is for traps we should NEVER get. */
28#define BAD_TRAP(num) \
29 rd %psr, %l0; mov num, %l7; b bad_trap_handler; rd %wim, %l3;
30
31/* This is for traps when we want just skip the instruction which caused it */
32#define SKIP_TRAP(type, name) \
33 jmpl %l2, %g0; rett %l2 + 4; nop; nop;
34
35/* Notice that for the system calls we pull a trick. We load up a
36 * different pointer to the system call vector table in %l7, but call
37 * the same generic system call low-level entry point. The trap table
38 * entry sequences are also HyperSparc pipeline friendly ;-)
39 */
40
41/* Software trap for Linux system calls. */
42#define LINUX_SYSCALL_TRAP \
43 sethi %hi(sys_call_table), %l7; \
44 or %l7, %lo(sys_call_table), %l7; \
45 b linux_sparc_syscall; \
46 rd %psr, %l0;
47
48#define BREAKPOINT_TRAP \
49 b breakpoint_trap; \
50 rd %psr,%l0; \
51 nop; \
52 nop;
53
54#ifdef CONFIG_KGDB
55#define KGDB_TRAP(num) \
56 b kgdb_trap_low; \
57 rd %psr,%l0; \
58 nop; \
59 nop;
60#else 5#else
61#define KGDB_TRAP(num) \ 6#include <asm-sparc/head_32.h>
62 BAD_TRAP(num) 7#endif
63#endif 8#endif
64
65/* The Get Condition Codes software trap for userland. */
66#define GETCC_TRAP \
67 b getcc_trap_handler; mov %psr, %l0; nop; nop;
68
69/* The Set Condition Codes software trap for userland. */
70#define SETCC_TRAP \
71 b setcc_trap_handler; mov %psr, %l0; nop; nop;
72
73/* The Get PSR software trap for userland. */
74#define GETPSR_TRAP \
75 mov %psr, %i0; jmp %l2; rett %l2 + 4; nop;
76
77/* This is for hard interrupts from level 1-14, 15 is non-maskable (nmi) and
78 * gets handled with another macro.
79 */
80#define TRAP_ENTRY_INTERRUPT(int_level) \
81 mov int_level, %l7; rd %psr, %l0; b real_irq_entry; rd %wim, %l3;
82
83/* NMI's (Non Maskable Interrupts) are special, you can't keep them
84 * from coming in, and basically if you get one, the shows over. ;(
85 * On the sun4c they are usually asynchronous memory errors, on the
86 * the sun4m they could be either due to mem errors or a software
87 * initiated interrupt from the prom/kern on an SMP box saying "I
88 * command you to do CPU tricks, read your mailbox for more info."
89 */
90#define NMI_TRAP \
91 rd %wim, %l3; b linux_trap_nmi_sun4c; mov %psr, %l0; nop;
92
93/* Window overflows/underflows are special and we need to try to be as
94 * efficient as possible here....
95 */
96#define WINDOW_SPILL \
97 rd %psr, %l0; rd %wim, %l3; b spill_window_entry; andcc %l0, PSR_PS, %g0;
98
99#define WINDOW_FILL \
100 rd %psr, %l0; rd %wim, %l3; b fill_window_entry; andcc %l0, PSR_PS, %g0;
101
102#endif /* __SPARC_HEAD_H */
diff --git a/include/asm-sparc/head_32.h b/include/asm-sparc/head_32.h
new file mode 100644
index 000000000000..7c35491a8b53
--- /dev/null
+++ b/include/asm-sparc/head_32.h
@@ -0,0 +1,102 @@
1#ifndef __SPARC_HEAD_H
2#define __SPARC_HEAD_H
3
4#define KERNBASE 0xf0000000 /* First address the kernel will eventually be */
5#define LOAD_ADDR 0x4000 /* prom jumps to us here unless this is elf /boot */
6#define SUN4C_SEGSZ (1 << 18)
7#define SRMMU_L1_KBASE_OFFSET ((KERNBASE>>24)<<2) /* Used in boot remapping. */
8#define INTS_ENAB 0x01 /* entry.S uses this. */
9
10#define SUN4_PROM_VECTOR 0xFFE81000 /* SUN4 PROM needs to be hardwired */
11
12#define WRITE_PAUSE nop; nop; nop; /* Have to do this after %wim/%psr chg */
13#define NOP_INSN 0x01000000 /* Used to patch sparc_save_state */
14
15/* Here are some trap goodies */
16
17/* Generic trap entry. */
18#define TRAP_ENTRY(type, label) \
19 rd %psr, %l0; b label; rd %wim, %l3; nop;
20
21/* Data/text faults. Defaults to sun4c version at boot time. */
22#define SPARC_TFAULT rd %psr, %l0; rd %wim, %l3; b sun4c_fault; mov 1, %l7;
23#define SPARC_DFAULT rd %psr, %l0; rd %wim, %l3; b sun4c_fault; mov 0, %l7;
24#define SRMMU_TFAULT rd %psr, %l0; rd %wim, %l3; b srmmu_fault; mov 1, %l7;
25#define SRMMU_DFAULT rd %psr, %l0; rd %wim, %l3; b srmmu_fault; mov 0, %l7;
26
27/* This is for traps we should NEVER get. */
28#define BAD_TRAP(num) \
29 rd %psr, %l0; mov num, %l7; b bad_trap_handler; rd %wim, %l3;
30
31/* This is for traps when we want just skip the instruction which caused it */
32#define SKIP_TRAP(type, name) \
33 jmpl %l2, %g0; rett %l2 + 4; nop; nop;
34
35/* Notice that for the system calls we pull a trick. We load up a
36 * different pointer to the system call vector table in %l7, but call
37 * the same generic system call low-level entry point. The trap table
38 * entry sequences are also HyperSparc pipeline friendly ;-)
39 */
40
41/* Software trap for Linux system calls. */
42#define LINUX_SYSCALL_TRAP \
43 sethi %hi(sys_call_table), %l7; \
44 or %l7, %lo(sys_call_table), %l7; \
45 b linux_sparc_syscall; \
46 rd %psr, %l0;
47
48#define BREAKPOINT_TRAP \
49 b breakpoint_trap; \
50 rd %psr,%l0; \
51 nop; \
52 nop;
53
54#ifdef CONFIG_KGDB
55#define KGDB_TRAP(num) \
56 b kgdb_trap_low; \
57 rd %psr,%l0; \
58 nop; \
59 nop;
60#else
61#define KGDB_TRAP(num) \
62 BAD_TRAP(num)
63#endif
64
65/* The Get Condition Codes software trap for userland. */
66#define GETCC_TRAP \
67 b getcc_trap_handler; mov %psr, %l0; nop; nop;
68
69/* The Set Condition Codes software trap for userland. */
70#define SETCC_TRAP \
71 b setcc_trap_handler; mov %psr, %l0; nop; nop;
72
73/* The Get PSR software trap for userland. */
74#define GETPSR_TRAP \
75 mov %psr, %i0; jmp %l2; rett %l2 + 4; nop;
76
77/* This is for hard interrupts from level 1-14, 15 is non-maskable (nmi) and
78 * gets handled with another macro.
79 */
80#define TRAP_ENTRY_INTERRUPT(int_level) \
81 mov int_level, %l7; rd %psr, %l0; b real_irq_entry; rd %wim, %l3;
82
83/* NMI's (Non Maskable Interrupts) are special, you can't keep them
84 * from coming in, and basically if you get one, the shows over. ;(
85 * On the sun4c they are usually asynchronous memory errors, on the
86 * the sun4m they could be either due to mem errors or a software
87 * initiated interrupt from the prom/kern on an SMP box saying "I
88 * command you to do CPU tricks, read your mailbox for more info."
89 */
90#define NMI_TRAP \
91 rd %wim, %l3; b linux_trap_nmi_sun4c; mov %psr, %l0; nop;
92
93/* Window overflows/underflows are special and we need to try to be as
94 * efficient as possible here....
95 */
96#define WINDOW_SPILL \
97 rd %psr, %l0; rd %wim, %l3; b spill_window_entry; andcc %l0, PSR_PS, %g0;
98
99#define WINDOW_FILL \
100 rd %psr, %l0; rd %wim, %l3; b fill_window_entry; andcc %l0, PSR_PS, %g0;
101
102#endif /* __SPARC_HEAD_H */
diff --git a/include/asm-sparc/head_64.h b/include/asm-sparc/head_64.h
new file mode 100644
index 000000000000..10e9dabc4c41
--- /dev/null
+++ b/include/asm-sparc/head_64.h
@@ -0,0 +1,76 @@
1#ifndef _SPARC64_HEAD_H
2#define _SPARC64_HEAD_H
3
4#include <asm/pstate.h>
5
6 /* wrpr %g0, val, %gl */
7#define SET_GL(val) \
8 .word 0xa1902000 | val
9
10 /* rdpr %gl, %gN */
11#define GET_GL_GLOBAL(N) \
12 .word 0x81540000 | (N << 25)
13
14#define KERNBASE 0x400000
15
16#define PTREGS_OFF (STACK_BIAS + STACKFRAME_SZ)
17
18#define __CHEETAH_ID 0x003e0014
19#define __JALAPENO_ID 0x003e0016
20#define __SERRANO_ID 0x003e0022
21
22#define CHEETAH_MANUF 0x003e
23#define CHEETAH_IMPL 0x0014 /* Ultra-III */
24#define CHEETAH_PLUS_IMPL 0x0015 /* Ultra-III+ */
25#define JALAPENO_IMPL 0x0016 /* Ultra-IIIi */
26#define JAGUAR_IMPL 0x0018 /* Ultra-IV */
27#define PANTHER_IMPL 0x0019 /* Ultra-IV+ */
28#define SERRANO_IMPL 0x0022 /* Ultra-IIIi+ */
29
30#define BRANCH_IF_SUN4V(tmp1,label) \
31 sethi %hi(is_sun4v), %tmp1; \
32 lduw [%tmp1 + %lo(is_sun4v)], %tmp1; \
33 brnz,pn %tmp1, label; \
34 nop
35
36#define BRANCH_IF_CHEETAH_BASE(tmp1,tmp2,label) \
37 rdpr %ver, %tmp1; \
38 sethi %hi(__CHEETAH_ID), %tmp2; \
39 srlx %tmp1, 32, %tmp1; \
40 or %tmp2, %lo(__CHEETAH_ID), %tmp2;\
41 cmp %tmp1, %tmp2; \
42 be,pn %icc, label; \
43 nop;
44
45#define BRANCH_IF_JALAPENO(tmp1,tmp2,label) \
46 rdpr %ver, %tmp1; \
47 sethi %hi(__JALAPENO_ID), %tmp2; \
48 srlx %tmp1, 32, %tmp1; \
49 or %tmp2, %lo(__JALAPENO_ID), %tmp2;\
50 cmp %tmp1, %tmp2; \
51 be,pn %icc, label; \
52 nop;
53
54#define BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(tmp1,tmp2,label) \
55 rdpr %ver, %tmp1; \
56 srlx %tmp1, (32 + 16), %tmp2; \
57 cmp %tmp2, CHEETAH_MANUF; \
58 bne,pt %xcc, 99f; \
59 sllx %tmp1, 16, %tmp1; \
60 srlx %tmp1, (32 + 16), %tmp2; \
61 cmp %tmp2, CHEETAH_PLUS_IMPL; \
62 bgeu,pt %xcc, label; \
6399: nop;
64
65#define BRANCH_IF_ANY_CHEETAH(tmp1,tmp2,label) \
66 rdpr %ver, %tmp1; \
67 srlx %tmp1, (32 + 16), %tmp2; \
68 cmp %tmp2, CHEETAH_MANUF; \
69 bne,pt %xcc, 99f; \
70 sllx %tmp1, 16, %tmp1; \
71 srlx %tmp1, (32 + 16), %tmp2; \
72 cmp %tmp2, CHEETAH_IMPL; \
73 bgeu,pt %xcc, label; \
7499: nop;
75
76#endif /* !(_SPARC64_HEAD_H) */
diff --git a/include/asm-sparc/hugetlb.h b/include/asm-sparc/hugetlb.h
new file mode 100644
index 000000000000..412af58926a0
--- /dev/null
+++ b/include/asm-sparc/hugetlb.h
@@ -0,0 +1,84 @@
1#ifndef _ASM_SPARC64_HUGETLB_H
2#define _ASM_SPARC64_HUGETLB_H
3
4#include <asm/page.h>
5
6
7void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
8 pte_t *ptep, pte_t pte);
9
10pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
11 pte_t *ptep);
12
13void hugetlb_prefault_arch_hook(struct mm_struct *mm);
14
15static inline int is_hugepage_only_range(struct mm_struct *mm,
16 unsigned long addr,
17 unsigned long len) {
18 return 0;
19}
20
21/*
22 * If the arch doesn't supply something else, assume that hugepage
23 * size aligned regions are ok without further preparation.
24 */
25static inline int prepare_hugepage_range(unsigned long addr, unsigned long len)
26{
27 if (len & ~HPAGE_MASK)
28 return -EINVAL;
29 if (addr & ~HPAGE_MASK)
30 return -EINVAL;
31 return 0;
32}
33
34static inline void hugetlb_free_pgd_range(struct mmu_gather **tlb,
35 unsigned long addr, unsigned long end,
36 unsigned long floor,
37 unsigned long ceiling)
38{
39 free_pgd_range(tlb, addr, end, floor, ceiling);
40}
41
42static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
43 unsigned long addr, pte_t *ptep)
44{
45}
46
47static inline int huge_pte_none(pte_t pte)
48{
49 return pte_none(pte);
50}
51
52static inline pte_t huge_pte_wrprotect(pte_t pte)
53{
54 return pte_wrprotect(pte);
55}
56
57static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
58 unsigned long addr, pte_t *ptep)
59{
60 ptep_set_wrprotect(mm, addr, ptep);
61}
62
63static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
64 unsigned long addr, pte_t *ptep,
65 pte_t pte, int dirty)
66{
67 return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
68}
69
70static inline pte_t huge_ptep_get(pte_t *ptep)
71{
72 return *ptep;
73}
74
75static inline int arch_prepare_hugepage(struct page *page)
76{
77 return 0;
78}
79
80static inline void arch_release_hugepage(struct page *page)
81{
82}
83
84#endif /* _ASM_SPARC64_HUGETLB_H */
diff --git a/include/asm-sparc/hvtramp.h b/include/asm-sparc/hvtramp.h
new file mode 100644
index 000000000000..b2b9b947b3a4
--- /dev/null
+++ b/include/asm-sparc/hvtramp.h
@@ -0,0 +1,37 @@
1#ifndef _SPARC64_HVTRAP_H
2#define _SPARC64_HVTRAP_H
3
4#ifndef __ASSEMBLY__
5
6#include <linux/types.h>
7
8struct hvtramp_mapping {
9 __u64 vaddr;
10 __u64 tte;
11};
12
13struct hvtramp_descr {
14 __u32 cpu;
15 __u32 num_mappings;
16 __u64 fault_info_va;
17 __u64 fault_info_pa;
18 __u64 thread_reg;
19 struct hvtramp_mapping maps[1];
20};
21
22extern void hv_cpu_startup(unsigned long hvdescr_pa);
23
24#endif
25
26#define HVTRAMP_DESCR_CPU 0x00
27#define HVTRAMP_DESCR_NUM_MAPPINGS 0x04
28#define HVTRAMP_DESCR_FAULT_INFO_VA 0x08
29#define HVTRAMP_DESCR_FAULT_INFO_PA 0x10
30#define HVTRAMP_DESCR_THREAD_REG 0x18
31#define HVTRAMP_DESCR_MAPS 0x20
32
33#define HVTRAMP_MAPPING_VADDR 0x00
34#define HVTRAMP_MAPPING_TTE 0x08
35#define HVTRAMP_MAPPING_SIZE 0x10
36
37#endif /* _SPARC64_HVTRAP_H */
diff --git a/include/asm-sparc/hypervisor.h b/include/asm-sparc/hypervisor.h
new file mode 100644
index 000000000000..109ae24ba242
--- /dev/null
+++ b/include/asm-sparc/hypervisor.h
@@ -0,0 +1,2949 @@
1#ifndef _SPARC64_HYPERVISOR_H
2#define _SPARC64_HYPERVISOR_H
3
4/* Sun4v hypervisor interfaces and defines.
5 *
6 * Hypervisor calls are made via traps to software traps number 0x80
7 * and above. Registers %o0 to %o5 serve as argument, status, and
8 * return value registers.
9 *
10 * There are two kinds of these traps. First there are the normal
11 * "fast traps" which use software trap 0x80 and encode the function
12 * to invoke by number in register %o5. Argument and return value
13 * handling is as follows:
14 *
15 * -----------------------------------------------
16 * | %o5 | function number | undefined |
17 * | %o0 | argument 0 | return status |
18 * | %o1 | argument 1 | return value 1 |
19 * | %o2 | argument 2 | return value 2 |
20 * | %o3 | argument 3 | return value 3 |
21 * | %o4 | argument 4 | return value 4 |
22 * -----------------------------------------------
23 *
24 * The second type are "hyper-fast traps" which encode the function
25 * number in the software trap number itself. So these use trap
26 * numbers > 0x80. The register usage for hyper-fast traps is as
27 * follows:
28 *
29 * -----------------------------------------------
30 * | %o0 | argument 0 | return status |
31 * | %o1 | argument 1 | return value 1 |
32 * | %o2 | argument 2 | return value 2 |
33 * | %o3 | argument 3 | return value 3 |
34 * | %o4 | argument 4 | return value 4 |
35 * -----------------------------------------------
36 *
37 * Registers providing explicit arguments to the hypervisor calls
38 * are volatile across the call. Upon return their values are
39 * undefined unless explicitly specified as containing a particular
40 * return value by the specific call. The return status is always
41 * returned in register %o0, zero indicates a successful execution of
42 * the hypervisor call and other values indicate an error status as
43 * defined below. So, for example, if a hyper-fast trap takes
44 * arguments 0, 1, and 2, then %o0, %o1, and %o2 are volatile across
45 * the call and %o3, %o4, and %o5 would be preserved.
46 *
47 * If the hypervisor trap is invalid, or the fast trap function number
48 * is invalid, HV_EBADTRAP will be returned in %o0. Also, all 64-bits
49 * of the argument and return values are significant.
50 */
51
52/* Trap numbers. */
53#define HV_FAST_TRAP 0x80
54#define HV_MMU_MAP_ADDR_TRAP 0x83
55#define HV_MMU_UNMAP_ADDR_TRAP 0x84
56#define HV_TTRACE_ADDENTRY_TRAP 0x85
57#define HV_CORE_TRAP 0xff
58
59/* Error codes. */
60#define HV_EOK 0 /* Successful return */
61#define HV_ENOCPU 1 /* Invalid CPU id */
62#define HV_ENORADDR 2 /* Invalid real address */
63#define HV_ENOINTR 3 /* Invalid interrupt id */
64#define HV_EBADPGSZ 4 /* Invalid pagesize encoding */
65#define HV_EBADTSB 5 /* Invalid TSB description */
66#define HV_EINVAL 6 /* Invalid argument */
67#define HV_EBADTRAP 7 /* Invalid function number */
68#define HV_EBADALIGN 8 /* Invalid address alignment */
69#define HV_EWOULDBLOCK 9 /* Cannot complete w/o blocking */
70#define HV_ENOACCESS 10 /* No access to resource */
71#define HV_EIO 11 /* I/O error */
72#define HV_ECPUERROR 12 /* CPU in error state */
73#define HV_ENOTSUPPORTED 13 /* Function not supported */
74#define HV_ENOMAP 14 /* No mapping found */
75#define HV_ETOOMANY 15 /* Too many items specified */
76#define HV_ECHANNEL 16 /* Invalid LDC channel */
77#define HV_EBUSY 17 /* Resource busy */
78
79/* mach_exit()
80 * TRAP: HV_FAST_TRAP
81 * FUNCTION: HV_FAST_MACH_EXIT
82 * ARG0: exit code
83 * ERRORS: This service does not return.
84 *
85 * Stop all CPUs in the virtual domain and place them into the stopped
86 * state. The 64-bit exit code may be passed to a service entity as
87 * the domain's exit status. On systems without a service entity, the
88 * domain will undergo a reset, and the boot firmware will be
89 * reloaded.
90 *
91 * This function will never return to the guest that invokes it.
92 *
93 * Note: By convention an exit code of zero denotes a successful exit by
94 * the guest code. A non-zero exit code denotes a guest specific
95 * error indication.
96 *
97 */
98#define HV_FAST_MACH_EXIT 0x00
99
100#ifndef __ASSEMBLY__
101extern void sun4v_mach_exit(unsigned long exit_code);
102#endif
103
104/* Domain services. */
105
106/* mach_desc()
107 * TRAP: HV_FAST_TRAP
108 * FUNCTION: HV_FAST_MACH_DESC
109 * ARG0: buffer
110 * ARG1: length
111 * RET0: status
112 * RET1: length
113 * ERRORS: HV_EBADALIGN Buffer is badly aligned
114 * HV_ENORADDR Buffer is to an illegal real address.
115 * HV_EINVAL Buffer length is too small for complete
116 * machine description.
117 *
118 * Copy the most current machine description into the buffer indicated
119 * by the real address in ARG0. The buffer provided must be 16 byte
120 * aligned. Upon success or HV_EINVAL, this service returns the
121 * actual size of the machine description in the RET1 return value.
122 *
123 * Note: A method of determining the appropriate buffer size for the
124 * machine description is to first call this service with a buffer
125 * length of 0 bytes.
126 */
127#define HV_FAST_MACH_DESC 0x01
128
129#ifndef __ASSEMBLY__
130extern unsigned long sun4v_mach_desc(unsigned long buffer_pa,
131 unsigned long buf_len,
132 unsigned long *real_buf_len);
133#endif
134
135/* mach_sir()
136 * TRAP: HV_FAST_TRAP
137 * FUNCTION: HV_FAST_MACH_SIR
138 * ERRORS: This service does not return.
139 *
140 * Perform a software initiated reset of the virtual machine domain.
141 * All CPUs are captured as soon as possible, all hardware devices are
142 * returned to the entry default state, and the domain is restarted at
143 * the SIR (trap type 0x04) real trap table (RTBA) entry point on one
144 * of the CPUs. The single CPU restarted is selected as determined by
145 * platform specific policy. Memory is preserved across this
146 * operation.
147 */
148#define HV_FAST_MACH_SIR 0x02
149
150#ifndef __ASSEMBLY__
151extern void sun4v_mach_sir(void);
152#endif
153
154/* mach_set_watchdog()
155 * TRAP: HV_FAST_TRAP
156 * FUNCTION: HV_FAST_MACH_SET_WATCHDOG
157 * ARG0: timeout in milliseconds
158 * RET0: status
159 * RET1: time remaining in milliseconds
160 *
161 * A guest uses this API to set a watchdog timer. Once the gues has set
162 * the timer, it must call the timer service again either to disable or
163 * postpone the expiration. If the timer expires before being reset or
164 * disabled, then the hypervisor take a platform specific action leading
165 * to guest termination within a bounded time period. The platform action
166 * may include recovery actions such as reporting the expiration to a
167 * Service Processor, and/or automatically restarting the gues.
168 *
169 * The 'timeout' parameter is specified in milliseconds, however the
170 * implementated granularity is given by the 'watchdog-resolution'
171 * property in the 'platform' node of the guest's machine description.
172 * The largest allowed timeout value is specified by the
173 * 'watchdog-max-timeout' property of the 'platform' node.
174 *
175 * If the 'timeout' argument is not zero, the watchdog timer is set to
176 * expire after a minimum of 'timeout' milliseconds.
177 *
178 * If the 'timeout' argument is zero, the watchdog timer is disabled.
179 *
180 * If the 'timeout' value exceeds the value of the 'max-watchdog-timeout'
181 * property, the hypervisor leaves the watchdog timer state unchanged,
182 * and returns a status of EINVAL.
183 *
184 * The 'time remaining' return value is valid regardless of whether the
185 * return status is EOK or EINVAL. A non-zero return value indicates the
186 * number of milliseconds that were remaining until the timer was to expire.
187 * If less than one millisecond remains, the return value is '1'. If the
188 * watchdog timer was disabled at the time of the call, the return value is
189 * zero.
190 *
191 * If the hypervisor cannot support the exact timeout value requested, but
192 * can support a larger timeout value, the hypervisor may round the actual
193 * timeout to a value larger than the requested timeout, consequently the
194 * 'time remaining' return value may be larger than the previously requested
195 * timeout value.
196 *
197 * Any guest OS debugger should be aware that the watchdog service may be in
198 * use. Consequently, it is recommended that the watchdog service is
199 * disabled upon debugger entry (e.g. reaching a breakpoint), and then
200 * re-enabled upon returning to normal execution. The API has been designed
201 * with this in mind, and the 'time remaining' result of the disable call may
202 * be used directly as the timeout argument of the re-enable call.
203 */
204#define HV_FAST_MACH_SET_WATCHDOG 0x05
205
206#ifndef __ASSEMBLY__
207extern unsigned long sun4v_mach_set_watchdog(unsigned long timeout,
208 unsigned long *orig_timeout);
209#endif
210
211/* CPU services.
212 *
213 * CPUs represent devices that can execute software threads. A single
214 * chip that contains multiple cores or strands is represented as
215 * multiple CPUs with unique CPU identifiers. CPUs are exported to
216 * OBP via the machine description (and to the OS via the OBP device
217 * tree). CPUs are always in one of three states: stopped, running,
218 * or error.
219 *
220 * A CPU ID is a pre-assigned 16-bit value that uniquely identifies a
221 * CPU within a logical domain. Operations that are to be performed
222 * on multiple CPUs specify them via a CPU list. A CPU list is an
223 * array in real memory, of which each 16-bit word is a CPU ID. CPU
224 * lists are passed through the API as two arguments. The first is
225 * the number of entries (16-bit words) in the CPU list, and the
226 * second is the (real address) pointer to the CPU ID list.
227 */
228
229/* cpu_start()
230 * TRAP: HV_FAST_TRAP
231 * FUNCTION: HV_FAST_CPU_START
232 * ARG0: CPU ID
233 * ARG1: PC
234 * ARG2: RTBA
235 * ARG3: target ARG0
236 * RET0: status
237 * ERRORS: ENOCPU Invalid CPU ID
238 * EINVAL Target CPU ID is not in the stopped state
239 * ENORADDR Invalid PC or RTBA real address
240 * EBADALIGN Unaligned PC or unaligned RTBA
241 * EWOULDBLOCK Starting resources are not available
242 *
243 * Start CPU with given CPU ID with PC in %pc and with a real trap
244 * base address value of RTBA. The indicated CPU must be in the
245 * stopped state. The supplied RTBA must be aligned on a 256 byte
246 * boundary. On successful completion, the specified CPU will be in
247 * the running state and will be supplied with "target ARG0" in %o0
248 * and RTBA in %tba.
249 */
250#define HV_FAST_CPU_START 0x10
251
252#ifndef __ASSEMBLY__
253extern unsigned long sun4v_cpu_start(unsigned long cpuid,
254 unsigned long pc,
255 unsigned long rtba,
256 unsigned long arg0);
257#endif
258
259/* cpu_stop()
260 * TRAP: HV_FAST_TRAP
261 * FUNCTION: HV_FAST_CPU_STOP
262 * ARG0: CPU ID
263 * RET0: status
264 * ERRORS: ENOCPU Invalid CPU ID
265 * EINVAL Target CPU ID is the current cpu
266 * EINVAL Target CPU ID is not in the running state
267 * EWOULDBLOCK Stopping resources are not available
268 * ENOTSUPPORTED Not supported on this platform
269 *
270 * The specified CPU is stopped. The indicated CPU must be in the
271 * running state. On completion, it will be in the stopped state. It
272 * is not legal to stop the current CPU.
273 *
274 * Note: As this service cannot be used to stop the current cpu, this service
275 * may not be used to stop the last running CPU in a domain. To stop
276 * and exit a running domain, a guest must use the mach_exit() service.
277 */
278#define HV_FAST_CPU_STOP 0x11
279
280#ifndef __ASSEMBLY__
281extern unsigned long sun4v_cpu_stop(unsigned long cpuid);
282#endif
283
284/* cpu_yield()
285 * TRAP: HV_FAST_TRAP
286 * FUNCTION: HV_FAST_CPU_YIELD
287 * RET0: status
288 * ERRORS: No possible error.
289 *
290 * Suspend execution on the current CPU. Execution will resume when
291 * an interrupt (device, %stick_compare, or cross-call) is targeted to
292 * the CPU. On some CPUs, this API may be used by the hypervisor to
293 * save power by disabling hardware strands.
294 */
295#define HV_FAST_CPU_YIELD 0x12
296
297#ifndef __ASSEMBLY__
298extern unsigned long sun4v_cpu_yield(void);
299#endif
300
301/* cpu_qconf()
302 * TRAP: HV_FAST_TRAP
303 * FUNCTION: HV_FAST_CPU_QCONF
304 * ARG0: queue
305 * ARG1: base real address
306 * ARG2: number of entries
307 * RET0: status
308 * ERRORS: ENORADDR Invalid base real address
309 * EINVAL Invalid queue or number of entries is less
310 * than 2 or too large.
311 * EBADALIGN Base real address is not correctly aligned
312 * for size.
313 *
314 * Configure the given queue to be placed at the given base real
315 * address, with the given number of entries. The number of entries
316 * must be a power of 2. The base real address must be aligned
317 * exactly to match the queue size. Each queue entry is 64 bytes
318 * long, so for example a 32 entry queue must be aligned on a 2048
319 * byte real address boundary.
320 *
321 * The specified queue is unconfigured if the number of entries is given
322 * as zero.
323 *
324 * For the current version of this API service, the argument queue is defined
325 * as follows:
326 *
327 * queue description
328 * ----- -------------------------
329 * 0x3c cpu mondo queue
330 * 0x3d device mondo queue
331 * 0x3e resumable error queue
332 * 0x3f non-resumable error queue
333 *
334 * Note: The maximum number of entries for each queue for a specific cpu may
335 * be determined from the machine description.
336 */
337#define HV_FAST_CPU_QCONF 0x14
338#define HV_CPU_QUEUE_CPU_MONDO 0x3c
339#define HV_CPU_QUEUE_DEVICE_MONDO 0x3d
340#define HV_CPU_QUEUE_RES_ERROR 0x3e
341#define HV_CPU_QUEUE_NONRES_ERROR 0x3f
342
343#ifndef __ASSEMBLY__
344extern unsigned long sun4v_cpu_qconf(unsigned long type,
345 unsigned long queue_paddr,
346 unsigned long num_queue_entries);
347#endif
348
349/* cpu_qinfo()
350 * TRAP: HV_FAST_TRAP
351 * FUNCTION: HV_FAST_CPU_QINFO
352 * ARG0: queue
353 * RET0: status
354 * RET1: base real address
355 * RET1: number of entries
356 * ERRORS: EINVAL Invalid queue
357 *
358 * Return the configuration info for the given queue. The base real
359 * address and number of entries of the defined queue are returned.
360 * The queue argument values are the same as for cpu_qconf() above.
361 *
362 * If the specified queue is a valid queue number, but no queue has
363 * been defined, the number of entries will be set to zero and the
364 * base real address returned is undefined.
365 */
366#define HV_FAST_CPU_QINFO 0x15
367
368/* cpu_mondo_send()
369 * TRAP: HV_FAST_TRAP
370 * FUNCTION: HV_FAST_CPU_MONDO_SEND
371 * ARG0-1: CPU list
372 * ARG2: data real address
373 * RET0: status
374 * ERRORS: EBADALIGN Mondo data is not 64-byte aligned or CPU list
375 * is not 2-byte aligned.
376 * ENORADDR Invalid data mondo address, or invalid cpu list
377 * address.
378 * ENOCPU Invalid cpu in CPU list
379 * EWOULDBLOCK Some or all of the listed CPUs did not receive
380 * the mondo
381 * ECPUERROR One or more of the listed CPUs are in error
382 * state, use HV_FAST_CPU_STATE to see which ones
383 * EINVAL CPU list includes caller's CPU ID
384 *
385 * Send a mondo interrupt to the CPUs in the given CPU list with the
386 * 64-bytes at the given data real address. The data must be 64-byte
387 * aligned. The mondo data will be delivered to the cpu_mondo queues
388 * of the recipient CPUs.
389 *
390 * In all cases, error or not, the CPUs in the CPU list to which the
391 * mondo has been successfully delivered will be indicated by having
392 * their entry in CPU list updated with the value 0xffff.
393 */
394#define HV_FAST_CPU_MONDO_SEND 0x42
395
396#ifndef __ASSEMBLY__
397extern unsigned long sun4v_cpu_mondo_send(unsigned long cpu_count, unsigned long cpu_list_pa, unsigned long mondo_block_pa);
398#endif
399
400/* cpu_myid()
401 * TRAP: HV_FAST_TRAP
402 * FUNCTION: HV_FAST_CPU_MYID
403 * RET0: status
404 * RET1: CPU ID
405 * ERRORS: No errors defined.
406 *
407 * Return the hypervisor ID handle for the current CPU. Use by a
408 * virtual CPU to discover it's own identity.
409 */
410#define HV_FAST_CPU_MYID 0x16
411
412/* cpu_state()
413 * TRAP: HV_FAST_TRAP
414 * FUNCTION: HV_FAST_CPU_STATE
415 * ARG0: CPU ID
416 * RET0: status
417 * RET1: state
418 * ERRORS: ENOCPU Invalid CPU ID
419 *
420 * Retrieve the current state of the CPU with the given CPU ID.
421 */
422#define HV_FAST_CPU_STATE 0x17
423#define HV_CPU_STATE_STOPPED 0x01
424#define HV_CPU_STATE_RUNNING 0x02
425#define HV_CPU_STATE_ERROR 0x03
426
427#ifndef __ASSEMBLY__
428extern long sun4v_cpu_state(unsigned long cpuid);
429#endif
430
431/* cpu_set_rtba()
432 * TRAP: HV_FAST_TRAP
433 * FUNCTION: HV_FAST_CPU_SET_RTBA
434 * ARG0: RTBA
435 * RET0: status
436 * RET1: previous RTBA
437 * ERRORS: ENORADDR Invalid RTBA real address
438 * EBADALIGN RTBA is incorrectly aligned for a trap table
439 *
440 * Set the real trap base address of the local cpu to the given RTBA.
441 * The supplied RTBA must be aligned on a 256 byte boundary. Upon
442 * success the previous value of the RTBA is returned in RET1.
443 *
444 * Note: This service does not affect %tba
445 */
446#define HV_FAST_CPU_SET_RTBA 0x18
447
448/* cpu_set_rtba()
449 * TRAP: HV_FAST_TRAP
450 * FUNCTION: HV_FAST_CPU_GET_RTBA
451 * RET0: status
452 * RET1: previous RTBA
453 * ERRORS: No possible error.
454 *
455 * Returns the current value of RTBA in RET1.
456 */
457#define HV_FAST_CPU_GET_RTBA 0x19
458
459/* MMU services.
460 *
461 * Layout of a TSB description for mmu_tsb_ctx{,non}0() calls.
462 */
463#ifndef __ASSEMBLY__
464struct hv_tsb_descr {
465 unsigned short pgsz_idx;
466 unsigned short assoc;
467 unsigned int num_ttes; /* in TTEs */
468 unsigned int ctx_idx;
469 unsigned int pgsz_mask;
470 unsigned long tsb_base;
471 unsigned long resv;
472};
473#endif
474#define HV_TSB_DESCR_PGSZ_IDX_OFFSET 0x00
475#define HV_TSB_DESCR_ASSOC_OFFSET 0x02
476#define HV_TSB_DESCR_NUM_TTES_OFFSET 0x04
477#define HV_TSB_DESCR_CTX_IDX_OFFSET 0x08
478#define HV_TSB_DESCR_PGSZ_MASK_OFFSET 0x0c
479#define HV_TSB_DESCR_TSB_BASE_OFFSET 0x10
480#define HV_TSB_DESCR_RESV_OFFSET 0x18
481
482/* Page size bitmask. */
483#define HV_PGSZ_MASK_8K (1 << 0)
484#define HV_PGSZ_MASK_64K (1 << 1)
485#define HV_PGSZ_MASK_512K (1 << 2)
486#define HV_PGSZ_MASK_4MB (1 << 3)
487#define HV_PGSZ_MASK_32MB (1 << 4)
488#define HV_PGSZ_MASK_256MB (1 << 5)
489#define HV_PGSZ_MASK_2GB (1 << 6)
490#define HV_PGSZ_MASK_16GB (1 << 7)
491
492/* Page size index. The value given in the TSB descriptor must correspond
493 * to the smallest page size specified in the pgsz_mask page size bitmask.
494 */
495#define HV_PGSZ_IDX_8K 0
496#define HV_PGSZ_IDX_64K 1
497#define HV_PGSZ_IDX_512K 2
498#define HV_PGSZ_IDX_4MB 3
499#define HV_PGSZ_IDX_32MB 4
500#define HV_PGSZ_IDX_256MB 5
501#define HV_PGSZ_IDX_2GB 6
502#define HV_PGSZ_IDX_16GB 7
503
504/* MMU fault status area.
505 *
506 * MMU related faults have their status and fault address information
507 * placed into a memory region made available by privileged code. Each
508 * virtual processor must make a mmu_fault_area_conf() call to tell the
509 * hypervisor where that processor's fault status should be stored.
510 *
511 * The fault status block is a multiple of 64-bytes and must be aligned
512 * on a 64-byte boundary.
513 */
514#ifndef __ASSEMBLY__
515struct hv_fault_status {
516 unsigned long i_fault_type;
517 unsigned long i_fault_addr;
518 unsigned long i_fault_ctx;
519 unsigned long i_reserved[5];
520 unsigned long d_fault_type;
521 unsigned long d_fault_addr;
522 unsigned long d_fault_ctx;
523 unsigned long d_reserved[5];
524};
525#endif
526#define HV_FAULT_I_TYPE_OFFSET 0x00
527#define HV_FAULT_I_ADDR_OFFSET 0x08
528#define HV_FAULT_I_CTX_OFFSET 0x10
529#define HV_FAULT_D_TYPE_OFFSET 0x40
530#define HV_FAULT_D_ADDR_OFFSET 0x48
531#define HV_FAULT_D_CTX_OFFSET 0x50
532
533#define HV_FAULT_TYPE_FAST_MISS 1
534#define HV_FAULT_TYPE_FAST_PROT 2
535#define HV_FAULT_TYPE_MMU_MISS 3
536#define HV_FAULT_TYPE_INV_RA 4
537#define HV_FAULT_TYPE_PRIV_VIOL 5
538#define HV_FAULT_TYPE_PROT_VIOL 6
539#define HV_FAULT_TYPE_NFO 7
540#define HV_FAULT_TYPE_NFO_SEFF 8
541#define HV_FAULT_TYPE_INV_VA 9
542#define HV_FAULT_TYPE_INV_ASI 10
543#define HV_FAULT_TYPE_NC_ATOMIC 11
544#define HV_FAULT_TYPE_PRIV_ACT 12
545#define HV_FAULT_TYPE_RESV1 13
546#define HV_FAULT_TYPE_UNALIGNED 14
547#define HV_FAULT_TYPE_INV_PGSZ 15
548/* Values 16 --> -2 are reserved. */
549#define HV_FAULT_TYPE_MULTIPLE -1
550
551/* Flags argument for mmu_{map,unmap}_addr(), mmu_demap_{page,context,all}(),
552 * and mmu_{map,unmap}_perm_addr().
553 */
554#define HV_MMU_DMMU 0x01
555#define HV_MMU_IMMU 0x02
556#define HV_MMU_ALL (HV_MMU_DMMU | HV_MMU_IMMU)
557
558/* mmu_map_addr()
559 * TRAP: HV_MMU_MAP_ADDR_TRAP
560 * ARG0: virtual address
561 * ARG1: mmu context
562 * ARG2: TTE
563 * ARG3: flags (HV_MMU_{IMMU,DMMU})
564 * ERRORS: EINVAL Invalid virtual address, mmu context, or flags
565 * EBADPGSZ Invalid page size value
566 * ENORADDR Invalid real address in TTE
567 *
568 * Create a non-permanent mapping using the given TTE, virtual
569 * address, and mmu context. The flags argument determines which
570 * (data, or instruction, or both) TLB the mapping gets loaded into.
571 *
572 * The behavior is undefined if the valid bit is clear in the TTE.
573 *
574 * Note: This API call is for privileged code to specify temporary translation
575 * mappings without the need to create and manage a TSB.
576 */
577
578/* mmu_unmap_addr()
579 * TRAP: HV_MMU_UNMAP_ADDR_TRAP
580 * ARG0: virtual address
581 * ARG1: mmu context
582 * ARG2: flags (HV_MMU_{IMMU,DMMU})
583 * ERRORS: EINVAL Invalid virtual address, mmu context, or flags
584 *
585 * Demaps the given virtual address in the given mmu context on this
586 * CPU. This function is intended to be used to demap pages mapped
587 * with mmu_map_addr. This service is equivalent to invoking
588 * mmu_demap_page() with only the current CPU in the CPU list. The
589 * flags argument determines which (data, or instruction, or both) TLB
590 * the mapping gets unmapped from.
591 *
592 * Attempting to perform an unmap operation for a previously defined
593 * permanent mapping will have undefined results.
594 */
595
596/* mmu_tsb_ctx0()
597 * TRAP: HV_FAST_TRAP
598 * FUNCTION: HV_FAST_MMU_TSB_CTX0
599 * ARG0: number of TSB descriptions
600 * ARG1: TSB descriptions pointer
601 * RET0: status
602 * ERRORS: ENORADDR Invalid TSB descriptions pointer or
603 * TSB base within a descriptor
604 * EBADALIGN TSB descriptions pointer is not aligned
605 * to an 8-byte boundary, or TSB base
606 * within a descriptor is not aligned for
607 * the given TSB size
608 * EBADPGSZ Invalid page size in a TSB descriptor
609 * EBADTSB Invalid associativity or size in a TSB
610 * descriptor
611 * EINVAL Invalid number of TSB descriptions, or
612 * invalid context index in a TSB
613 * descriptor, or index page size not
614 * equal to smallest page size in page
615 * size bitmask field.
616 *
617 * Configures the TSBs for the current CPU for virtual addresses with
618 * context zero. The TSB descriptions pointer is a pointer to an
619 * array of the given number of TSB descriptions.
620 *
621 * Note: The maximum number of TSBs available to a virtual CPU is given by the
622 * mmu-max-#tsbs property of the cpu's corresponding "cpu" node in the
623 * machine description.
624 */
625#define HV_FAST_MMU_TSB_CTX0 0x20
626
627#ifndef __ASSEMBLY__
628extern unsigned long sun4v_mmu_tsb_ctx0(unsigned long num_descriptions,
629 unsigned long tsb_desc_ra);
630#endif
631
632/* mmu_tsb_ctxnon0()
633 * TRAP: HV_FAST_TRAP
634 * FUNCTION: HV_FAST_MMU_TSB_CTXNON0
635 * ARG0: number of TSB descriptions
636 * ARG1: TSB descriptions pointer
637 * RET0: status
638 * ERRORS: Same as for mmu_tsb_ctx0() above.
639 *
640 * Configures the TSBs for the current CPU for virtual addresses with
641 * non-zero contexts. The TSB descriptions pointer is a pointer to an
642 * array of the given number of TSB descriptions.
643 *
644 * Note: A maximum of 16 TSBs may be specified in the TSB description list.
645 */
646#define HV_FAST_MMU_TSB_CTXNON0 0x21
647
648/* mmu_demap_page()
649 * TRAP: HV_FAST_TRAP
650 * FUNCTION: HV_FAST_MMU_DEMAP_PAGE
651 * ARG0: reserved, must be zero
652 * ARG1: reserved, must be zero
653 * ARG2: virtual address
654 * ARG3: mmu context
655 * ARG4: flags (HV_MMU_{IMMU,DMMU})
656 * RET0: status
657 * ERRORS: EINVAL Invalid virutal address, context, or
658 * flags value
659 * ENOTSUPPORTED ARG0 or ARG1 is non-zero
660 *
661 * Demaps any page mapping of the given virtual address in the given
662 * mmu context for the current virtual CPU. Any virtually tagged
663 * caches are guaranteed to be kept consistent. The flags argument
664 * determines which TLB (instruction, or data, or both) participate in
665 * the operation.
666 *
667 * ARG0 and ARG1 are both reserved and must be set to zero.
668 */
669#define HV_FAST_MMU_DEMAP_PAGE 0x22
670
671/* mmu_demap_ctx()
672 * TRAP: HV_FAST_TRAP
673 * FUNCTION: HV_FAST_MMU_DEMAP_CTX
674 * ARG0: reserved, must be zero
675 * ARG1: reserved, must be zero
676 * ARG2: mmu context
677 * ARG3: flags (HV_MMU_{IMMU,DMMU})
678 * RET0: status
679 * ERRORS: EINVAL Invalid context or flags value
680 * ENOTSUPPORTED ARG0 or ARG1 is non-zero
681 *
682 * Demaps all non-permanent virtual page mappings previously specified
683 * for the given context for the current virtual CPU. Any virtual
684 * tagged caches are guaranteed to be kept consistent. The flags
685 * argument determines which TLB (instruction, or data, or both)
686 * participate in the operation.
687 *
688 * ARG0 and ARG1 are both reserved and must be set to zero.
689 */
690#define HV_FAST_MMU_DEMAP_CTX 0x23
691
692/* mmu_demap_all()
693 * TRAP: HV_FAST_TRAP
694 * FUNCTION: HV_FAST_MMU_DEMAP_ALL
695 * ARG0: reserved, must be zero
696 * ARG1: reserved, must be zero
697 * ARG2: flags (HV_MMU_{IMMU,DMMU})
698 * RET0: status
699 * ERRORS: EINVAL Invalid flags value
700 * ENOTSUPPORTED ARG0 or ARG1 is non-zero
701 *
702 * Demaps all non-permanent virtual page mappings previously specified
703 * for the current virtual CPU. Any virtual tagged caches are
704 * guaranteed to be kept consistent. The flags argument determines
705 * which TLB (instruction, or data, or both) participate in the
706 * operation.
707 *
708 * ARG0 and ARG1 are both reserved and must be set to zero.
709 */
710#define HV_FAST_MMU_DEMAP_ALL 0x24
711
712#ifndef __ASSEMBLY__
713extern void sun4v_mmu_demap_all(void);
714#endif
715
716/* mmu_map_perm_addr()
717 * TRAP: HV_FAST_TRAP
718 * FUNCTION: HV_FAST_MMU_MAP_PERM_ADDR
719 * ARG0: virtual address
720 * ARG1: reserved, must be zero
721 * ARG2: TTE
722 * ARG3: flags (HV_MMU_{IMMU,DMMU})
723 * RET0: status
724 * ERRORS: EINVAL Invalid virutal address or flags value
725 * EBADPGSZ Invalid page size value
726 * ENORADDR Invalid real address in TTE
727 * ETOOMANY Too many mappings (max of 8 reached)
728 *
729 * Create a permanent mapping using the given TTE and virtual address
730 * for context 0 on the calling virtual CPU. A maximum of 8 such
731 * permanent mappings may be specified by privileged code. Mappings
732 * may be removed with mmu_unmap_perm_addr().
733 *
734 * The behavior is undefined if a TTE with the valid bit clear is given.
735 *
736 * Note: This call is used to specify address space mappings for which
737 * privileged code does not expect to receive misses. For example,
738 * this mechanism can be used to map kernel nucleus code and data.
739 */
740#define HV_FAST_MMU_MAP_PERM_ADDR 0x25
741
742#ifndef __ASSEMBLY__
743extern unsigned long sun4v_mmu_map_perm_addr(unsigned long vaddr,
744 unsigned long set_to_zero,
745 unsigned long tte,
746 unsigned long flags);
747#endif
748
749/* mmu_fault_area_conf()
750 * TRAP: HV_FAST_TRAP
751 * FUNCTION: HV_FAST_MMU_FAULT_AREA_CONF
752 * ARG0: real address
753 * RET0: status
754 * RET1: previous mmu fault area real address
755 * ERRORS: ENORADDR Invalid real address
756 * EBADALIGN Invalid alignment for fault area
757 *
758 * Configure the MMU fault status area for the calling CPU. A 64-byte
759 * aligned real address specifies where MMU fault status information
760 * is placed. The return value is the previously specified area, or 0
761 * for the first invocation. Specifying a fault area at real address
762 * 0 is not allowed.
763 */
764#define HV_FAST_MMU_FAULT_AREA_CONF 0x26
765
766/* mmu_enable()
767 * TRAP: HV_FAST_TRAP
768 * FUNCTION: HV_FAST_MMU_ENABLE
769 * ARG0: enable flag
770 * ARG1: return target address
771 * RET0: status
772 * ERRORS: ENORADDR Invalid real address when disabling
773 * translation.
774 * EBADALIGN The return target address is not
775 * aligned to an instruction.
776 * EINVAL The enable flag request the current
777 * operating mode (e.g. disable if already
778 * disabled)
779 *
780 * Enable or disable virtual address translation for the calling CPU
781 * within the virtual machine domain. If the enable flag is zero,
782 * translation is disabled, any non-zero value will enable
783 * translation.
784 *
785 * When this function returns, the newly selected translation mode
786 * will be active. If the mmu is being enabled, then the return
787 * target address is a virtual address else it is a real address.
788 *
789 * Upon successful completion, control will be returned to the given
790 * return target address (ie. the cpu will jump to that address). On
791 * failure, the previous mmu mode remains and the trap simply returns
792 * as normal with the appropriate error code in RET0.
793 */
794#define HV_FAST_MMU_ENABLE 0x27
795
796/* mmu_unmap_perm_addr()
797 * TRAP: HV_FAST_TRAP
798 * FUNCTION: HV_FAST_MMU_UNMAP_PERM_ADDR
799 * ARG0: virtual address
800 * ARG1: reserved, must be zero
801 * ARG2: flags (HV_MMU_{IMMU,DMMU})
802 * RET0: status
803 * ERRORS: EINVAL Invalid virutal address or flags value
804 * ENOMAP Specified mapping was not found
805 *
806 * Demaps any permanent page mapping (established via
807 * mmu_map_perm_addr()) at the given virtual address for context 0 on
808 * the current virtual CPU. Any virtual tagged caches are guaranteed
809 * to be kept consistent.
810 */
811#define HV_FAST_MMU_UNMAP_PERM_ADDR 0x28
812
813/* mmu_tsb_ctx0_info()
814 * TRAP: HV_FAST_TRAP
815 * FUNCTION: HV_FAST_MMU_TSB_CTX0_INFO
816 * ARG0: max TSBs
817 * ARG1: buffer pointer
818 * RET0: status
819 * RET1: number of TSBs
820 * ERRORS: EINVAL Supplied buffer is too small
821 * EBADALIGN The buffer pointer is badly aligned
822 * ENORADDR Invalid real address for buffer pointer
823 *
824 * Return the TSB configuration as previous defined by mmu_tsb_ctx0()
825 * into the provided buffer. The size of the buffer is given in ARG1
826 * in terms of the number of TSB description entries.
827 *
828 * Upon return, RET1 always contains the number of TSB descriptions
829 * previously configured. If zero TSBs were configured, EOK is
830 * returned with RET1 containing 0.
831 */
832#define HV_FAST_MMU_TSB_CTX0_INFO 0x29
833
834/* mmu_tsb_ctxnon0_info()
835 * TRAP: HV_FAST_TRAP
836 * FUNCTION: HV_FAST_MMU_TSB_CTXNON0_INFO
837 * ARG0: max TSBs
838 * ARG1: buffer pointer
839 * RET0: status
840 * RET1: number of TSBs
841 * ERRORS: EINVAL Supplied buffer is too small
842 * EBADALIGN The buffer pointer is badly aligned
843 * ENORADDR Invalid real address for buffer pointer
844 *
845 * Return the TSB configuration as previous defined by
846 * mmu_tsb_ctxnon0() into the provided buffer. The size of the buffer
847 * is given in ARG1 in terms of the number of TSB description entries.
848 *
849 * Upon return, RET1 always contains the number of TSB descriptions
850 * previously configured. If zero TSBs were configured, EOK is
851 * returned with RET1 containing 0.
852 */
853#define HV_FAST_MMU_TSB_CTXNON0_INFO 0x2a
854
855/* mmu_fault_area_info()
856 * TRAP: HV_FAST_TRAP
857 * FUNCTION: HV_FAST_MMU_FAULT_AREA_INFO
858 * RET0: status
859 * RET1: fault area real address
860 * ERRORS: No errors defined.
861 *
862 * Return the currently defined MMU fault status area for the current
863 * CPU. The real address of the fault status area is returned in
864 * RET1, or 0 is returned in RET1 if no fault status area is defined.
865 *
866 * Note: mmu_fault_area_conf() may be called with the return value (RET1)
867 * from this service if there is a need to save and restore the fault
868 * area for a cpu.
869 */
870#define HV_FAST_MMU_FAULT_AREA_INFO 0x2b
871
872/* Cache and Memory services. */
873
874/* mem_scrub()
875 * TRAP: HV_FAST_TRAP
876 * FUNCTION: HV_FAST_MEM_SCRUB
877 * ARG0: real address
878 * ARG1: length
879 * RET0: status
880 * RET1: length scrubbed
881 * ERRORS: ENORADDR Invalid real address
882 * EBADALIGN Start address or length are not correctly
883 * aligned
884 * EINVAL Length is zero
885 *
886 * Zero the memory contents in the range real address to real address
887 * plus length minus 1. Also, valid ECC will be generated for that
888 * memory address range. Scrubbing is started at the given real
889 * address, but may not scrub the entire given length. The actual
890 * length scrubbed will be returned in RET1.
891 *
892 * The real address and length must be aligned on an 8K boundary, or
893 * contain the start address and length from a sun4v error report.
894 *
895 * Note: There are two uses for this function. The first use is to block clear
896 * and initialize memory and the second is to scrub an u ncorrectable
897 * error reported via a resumable or non-resumable trap. The second
898 * use requires the arguments to be equal to the real address and length
899 * provided in a sun4v memory error report.
900 */
901#define HV_FAST_MEM_SCRUB 0x31
902
903/* mem_sync()
904 * TRAP: HV_FAST_TRAP
905 * FUNCTION: HV_FAST_MEM_SYNC
906 * ARG0: real address
907 * ARG1: length
908 * RET0: status
909 * RET1: length synced
910 * ERRORS: ENORADDR Invalid real address
911 * EBADALIGN Start address or length are not correctly
912 * aligned
913 * EINVAL Length is zero
914 *
915 * Force the next access within the real address to real address plus
916 * length minus 1 to be fetches from main system memory. Less than
917 * the given length may be synced, the actual amount synced is
918 * returned in RET1. The real address and length must be aligned on
919 * an 8K boundary.
920 */
921#define HV_FAST_MEM_SYNC 0x32
922
923/* Time of day services.
924 *
925 * The hypervisor maintains the time of day on a per-domain basis.
926 * Changing the time of day in one domain does not affect the time of
927 * day on any other domain.
928 *
929 * Time is described by a single unsigned 64-bit word which is the
930 * number of seconds since the UNIX Epoch (00:00:00 UTC, January 1,
931 * 1970).
932 */
933
934/* tod_get()
935 * TRAP: HV_FAST_TRAP
936 * FUNCTION: HV_FAST_TOD_GET
937 * RET0: status
938 * RET1: TOD
939 * ERRORS: EWOULDBLOCK TOD resource is temporarily unavailable
940 * ENOTSUPPORTED If TOD not supported on this platform
941 *
942 * Return the current time of day. May block if TOD access is
943 * temporarily not possible.
944 */
945#define HV_FAST_TOD_GET 0x50
946
947#ifndef __ASSEMBLY__
948extern unsigned long sun4v_tod_get(unsigned long *time);
949#endif
950
951/* tod_set()
952 * TRAP: HV_FAST_TRAP
953 * FUNCTION: HV_FAST_TOD_SET
954 * ARG0: TOD
955 * RET0: status
956 * ERRORS: EWOULDBLOCK TOD resource is temporarily unavailable
957 * ENOTSUPPORTED If TOD not supported on this platform
958 *
959 * The current time of day is set to the value specified in ARG0. May
960 * block if TOD access is temporarily not possible.
961 */
962#define HV_FAST_TOD_SET 0x51
963
964#ifndef __ASSEMBLY__
965extern unsigned long sun4v_tod_set(unsigned long time);
966#endif
967
968/* Console services */
969
970/* con_getchar()
971 * TRAP: HV_FAST_TRAP
972 * FUNCTION: HV_FAST_CONS_GETCHAR
973 * RET0: status
974 * RET1: character
975 * ERRORS: EWOULDBLOCK No character available.
976 *
977 * Returns a character from the console device. If no character is
978 * available then an EWOULDBLOCK error is returned. If a character is
979 * available, then the returned status is EOK and the character value
980 * is in RET1.
981 *
982 * A virtual BREAK is represented by the 64-bit value -1.
983 *
984 * A virtual HUP signal is represented by the 64-bit value -2.
985 */
986#define HV_FAST_CONS_GETCHAR 0x60
987
988/* con_putchar()
989 * TRAP: HV_FAST_TRAP
990 * FUNCTION: HV_FAST_CONS_PUTCHAR
991 * ARG0: character
992 * RET0: status
993 * ERRORS: EINVAL Illegal character
994 * EWOULDBLOCK Output buffer currently full, would block
995 *
996 * Send a character to the console device. Only character values
997 * between 0 and 255 may be used. Values outside this range are
998 * invalid except for the 64-bit value -1 which is used to send a
999 * virtual BREAK.
1000 */
1001#define HV_FAST_CONS_PUTCHAR 0x61
1002
1003/* con_read()
1004 * TRAP: HV_FAST_TRAP
1005 * FUNCTION: HV_FAST_CONS_READ
1006 * ARG0: buffer real address
1007 * ARG1: buffer size in bytes
1008 * RET0: status
1009 * RET1: bytes read or BREAK or HUP
1010 * ERRORS: EWOULDBLOCK No character available.
1011 *
1012 * Reads characters into a buffer from the console device. If no
1013 * character is available then an EWOULDBLOCK error is returned.
1014 * If a character is available, then the returned status is EOK
1015 * and the number of bytes read into the given buffer is provided
1016 * in RET1.
1017 *
1018 * A virtual BREAK is represented by the 64-bit RET1 value -1.
1019 *
1020 * A virtual HUP signal is represented by the 64-bit RET1 value -2.
1021 *
1022 * If BREAK or HUP are indicated, no bytes were read into buffer.
1023 */
1024#define HV_FAST_CONS_READ 0x62
1025
1026/* con_write()
1027 * TRAP: HV_FAST_TRAP
1028 * FUNCTION: HV_FAST_CONS_WRITE
1029 * ARG0: buffer real address
1030 * ARG1: buffer size in bytes
1031 * RET0: status
1032 * RET1: bytes written
1033 * ERRORS: EWOULDBLOCK Output buffer currently full, would block
1034 *
1035 * Send a characters in buffer to the console device. Breaks must be
1036 * sent using con_putchar().
1037 */
1038#define HV_FAST_CONS_WRITE 0x63
1039
1040#ifndef __ASSEMBLY__
1041extern long sun4v_con_getchar(long *status);
1042extern long sun4v_con_putchar(long c);
1043extern long sun4v_con_read(unsigned long buffer,
1044 unsigned long size,
1045 unsigned long *bytes_read);
1046extern unsigned long sun4v_con_write(unsigned long buffer,
1047 unsigned long size,
1048 unsigned long *bytes_written);
1049#endif
1050
1051/* mach_set_soft_state()
1052 * TRAP: HV_FAST_TRAP
1053 * FUNCTION: HV_FAST_MACH_SET_SOFT_STATE
1054 * ARG0: software state
1055 * ARG1: software state description pointer
1056 * RET0: status
1057 * ERRORS: EINVAL software state not valid or software state
1058 * description is not NULL terminated
1059 * ENORADDR software state description pointer is not a
1060 * valid real address
1061 * EBADALIGNED software state description is not correctly
1062 * aligned
1063 *
1064 * This allows the guest to report it's soft state to the hypervisor. There
1065 * are two primary components to this state. The first part states whether
1066 * the guest software is running or not. The second containts optional
1067 * details specific to the software.
1068 *
1069 * The software state argument is defined below in HV_SOFT_STATE_*, and
1070 * indicates whether the guest is operating normally or in a transitional
1071 * state.
1072 *
1073 * The software state description argument is a real address of a data buffer
1074 * of size 32-bytes aligned on a 32-byte boundary. It is treated as a NULL
1075 * terminated 7-bit ASCII string of up to 31 characters not including the
1076 * NULL termination.
1077 */
1078#define HV_FAST_MACH_SET_SOFT_STATE 0x70
1079#define HV_SOFT_STATE_NORMAL 0x01
1080#define HV_SOFT_STATE_TRANSITION 0x02
1081
1082#ifndef __ASSEMBLY__
1083extern unsigned long sun4v_mach_set_soft_state(unsigned long soft_state,
1084 unsigned long msg_string_ra);
1085#endif
1086
1087/* mach_get_soft_state()
1088 * TRAP: HV_FAST_TRAP
1089 * FUNCTION: HV_FAST_MACH_GET_SOFT_STATE
1090 * ARG0: software state description pointer
1091 * RET0: status
1092 * RET1: software state
1093 * ERRORS: ENORADDR software state description pointer is not a
1094 * valid real address
1095 * EBADALIGNED software state description is not correctly
1096 * aligned
1097 *
1098 * Retrieve the current value of the guest's software state. The rules
1099 * for the software state pointer are the same as for mach_set_soft_state()
1100 * above.
1101 */
1102#define HV_FAST_MACH_GET_SOFT_STATE 0x71
1103
1104/* svc_send()
1105 * TRAP: HV_FAST_TRAP
1106 * FUNCTION: HV_FAST_SVC_SEND
1107 * ARG0: service ID
1108 * ARG1: buffer real address
1109 * ARG2: buffer size
1110 * RET0: STATUS
1111 * RET1: sent_bytes
1112 *
1113 * Be careful, all output registers are clobbered by this operation,
1114 * so for example it is not possible to save away a value in %o4
1115 * across the trap.
1116 */
1117#define HV_FAST_SVC_SEND 0x80
1118
1119/* svc_recv()
1120 * TRAP: HV_FAST_TRAP
1121 * FUNCTION: HV_FAST_SVC_RECV
1122 * ARG0: service ID
1123 * ARG1: buffer real address
1124 * ARG2: buffer size
1125 * RET0: STATUS
1126 * RET1: recv_bytes
1127 *
1128 * Be careful, all output registers are clobbered by this operation,
1129 * so for example it is not possible to save away a value in %o4
1130 * across the trap.
1131 */
1132#define HV_FAST_SVC_RECV 0x81
1133
1134/* svc_getstatus()
1135 * TRAP: HV_FAST_TRAP
1136 * FUNCTION: HV_FAST_SVC_GETSTATUS
1137 * ARG0: service ID
1138 * RET0: STATUS
1139 * RET1: status bits
1140 */
1141#define HV_FAST_SVC_GETSTATUS 0x82
1142
1143/* svc_setstatus()
1144 * TRAP: HV_FAST_TRAP
1145 * FUNCTION: HV_FAST_SVC_SETSTATUS
1146 * ARG0: service ID
1147 * ARG1: bits to set
1148 * RET0: STATUS
1149 */
1150#define HV_FAST_SVC_SETSTATUS 0x83
1151
1152/* svc_clrstatus()
1153 * TRAP: HV_FAST_TRAP
1154 * FUNCTION: HV_FAST_SVC_CLRSTATUS
1155 * ARG0: service ID
1156 * ARG1: bits to clear
1157 * RET0: STATUS
1158 */
1159#define HV_FAST_SVC_CLRSTATUS 0x84
1160
1161#ifndef __ASSEMBLY__
1162extern unsigned long sun4v_svc_send(unsigned long svc_id,
1163 unsigned long buffer,
1164 unsigned long buffer_size,
1165 unsigned long *sent_bytes);
1166extern unsigned long sun4v_svc_recv(unsigned long svc_id,
1167 unsigned long buffer,
1168 unsigned long buffer_size,
1169 unsigned long *recv_bytes);
1170extern unsigned long sun4v_svc_getstatus(unsigned long svc_id,
1171 unsigned long *status_bits);
1172extern unsigned long sun4v_svc_setstatus(unsigned long svc_id,
1173 unsigned long status_bits);
1174extern unsigned long sun4v_svc_clrstatus(unsigned long svc_id,
1175 unsigned long status_bits);
1176#endif
1177
1178/* Trap trace services.
1179 *
1180 * The hypervisor provides a trap tracing capability for privileged
1181 * code running on each virtual CPU. Privileged code provides a
1182 * round-robin trap trace queue within which the hypervisor writes
1183 * 64-byte entries detailing hyperprivileged traps taken n behalf of
1184 * privileged code. This is provided as a debugging capability for
1185 * privileged code.
1186 *
1187 * The trap trace control structure is 64-bytes long and placed at the
1188 * start (offset 0) of the trap trace buffer, and is described as
1189 * follows:
1190 */
1191#ifndef __ASSEMBLY__
1192struct hv_trap_trace_control {
1193 unsigned long head_offset;
1194 unsigned long tail_offset;
1195 unsigned long __reserved[0x30 / sizeof(unsigned long)];
1196};
1197#endif
1198#define HV_TRAP_TRACE_CTRL_HEAD_OFFSET 0x00
1199#define HV_TRAP_TRACE_CTRL_TAIL_OFFSET 0x08
1200
1201/* The head offset is the offset of the most recently completed entry
1202 * in the trap-trace buffer. The tail offset is the offset of the
1203 * next entry to be written. The control structure is owned and
1204 * modified by the hypervisor. A guest may not modify the control
1205 * structure contents. Attempts to do so will result in undefined
1206 * behavior for the guest.
1207 *
1208 * Each trap trace buffer entry is layed out as follows:
1209 */
1210#ifndef __ASSEMBLY__
1211struct hv_trap_trace_entry {
1212 unsigned char type; /* Hypervisor or guest entry? */
1213 unsigned char hpstate; /* Hyper-privileged state */
1214 unsigned char tl; /* Trap level */
1215 unsigned char gl; /* Global register level */
1216 unsigned short tt; /* Trap type */
1217 unsigned short tag; /* Extended trap identifier */
1218 unsigned long tstate; /* Trap state */
1219 unsigned long tick; /* Tick */
1220 unsigned long tpc; /* Trap PC */
1221 unsigned long f1; /* Entry specific */
1222 unsigned long f2; /* Entry specific */
1223 unsigned long f3; /* Entry specific */
1224 unsigned long f4; /* Entry specific */
1225};
1226#endif
1227#define HV_TRAP_TRACE_ENTRY_TYPE 0x00
1228#define HV_TRAP_TRACE_ENTRY_HPSTATE 0x01
1229#define HV_TRAP_TRACE_ENTRY_TL 0x02
1230#define HV_TRAP_TRACE_ENTRY_GL 0x03
1231#define HV_TRAP_TRACE_ENTRY_TT 0x04
1232#define HV_TRAP_TRACE_ENTRY_TAG 0x06
1233#define HV_TRAP_TRACE_ENTRY_TSTATE 0x08
1234#define HV_TRAP_TRACE_ENTRY_TICK 0x10
1235#define HV_TRAP_TRACE_ENTRY_TPC 0x18
1236#define HV_TRAP_TRACE_ENTRY_F1 0x20
1237#define HV_TRAP_TRACE_ENTRY_F2 0x28
1238#define HV_TRAP_TRACE_ENTRY_F3 0x30
1239#define HV_TRAP_TRACE_ENTRY_F4 0x38
1240
1241/* The type field is encoded as follows. */
1242#define HV_TRAP_TYPE_UNDEF 0x00 /* Entry content undefined */
1243#define HV_TRAP_TYPE_HV 0x01 /* Hypervisor trap entry */
1244#define HV_TRAP_TYPE_GUEST 0xff /* Added via ttrace_addentry() */
1245
1246/* ttrace_buf_conf()
1247 * TRAP: HV_FAST_TRAP
1248 * FUNCTION: HV_FAST_TTRACE_BUF_CONF
1249 * ARG0: real address
1250 * ARG1: number of entries
1251 * RET0: status
1252 * RET1: number of entries
1253 * ERRORS: ENORADDR Invalid real address
1254 * EINVAL Size is too small
1255 * EBADALIGN Real address not aligned on 64-byte boundary
1256 *
1257 * Requests hypervisor trap tracing and declares a virtual CPU's trap
1258 * trace buffer to the hypervisor. The real address supplies the real
1259 * base address of the trap trace queue and must be 64-byte aligned.
1260 * Specifying a value of 0 for the number of entries disables trap
1261 * tracing for the calling virtual CPU. The buffer allocated must be
1262 * sized for a power of two number of 64-byte trap trace entries plus
1263 * an initial 64-byte control structure.
1264 *
1265 * This may be invoked any number of times so that a virtual CPU may
1266 * relocate a trap trace buffer or create "snapshots" of information.
1267 *
1268 * If the real address is illegal or badly aligned, then trap tracing
1269 * is disabled and an error is returned.
1270 *
1271 * Upon failure with EINVAL, this service call returns in RET1 the
1272 * minimum number of buffer entries required. Upon other failures
1273 * RET1 is undefined.
1274 */
1275#define HV_FAST_TTRACE_BUF_CONF 0x90
1276
1277/* ttrace_buf_info()
1278 * TRAP: HV_FAST_TRAP
1279 * FUNCTION: HV_FAST_TTRACE_BUF_INFO
1280 * RET0: status
1281 * RET1: real address
1282 * RET2: size
1283 * ERRORS: None defined.
1284 *
1285 * Returns the size and location of the previously declared trap-trace
1286 * buffer. In the event that no buffer was previously defined, or the
1287 * buffer is disabled, this call will return a size of zero bytes.
1288 */
1289#define HV_FAST_TTRACE_BUF_INFO 0x91
1290
1291/* ttrace_enable()
1292 * TRAP: HV_FAST_TRAP
1293 * FUNCTION: HV_FAST_TTRACE_ENABLE
1294 * ARG0: enable
1295 * RET0: status
1296 * RET1: previous enable state
1297 * ERRORS: EINVAL No trap trace buffer currently defined
1298 *
1299 * Enable or disable trap tracing, and return the previous enabled
1300 * state in RET1. Future systems may define various flags for the
1301 * enable argument (ARG0), for the moment a guest should pass
1302 * "(uint64_t) -1" to enable, and "(uint64_t) 0" to disable all
1303 * tracing - which will ensure future compatability.
1304 */
1305#define HV_FAST_TTRACE_ENABLE 0x92
1306
1307/* ttrace_freeze()
1308 * TRAP: HV_FAST_TRAP
1309 * FUNCTION: HV_FAST_TTRACE_FREEZE
1310 * ARG0: freeze
1311 * RET0: status
1312 * RET1: previous freeze state
1313 * ERRORS: EINVAL No trap trace buffer currently defined
1314 *
1315 * Freeze or unfreeze trap tracing, returning the previous freeze
1316 * state in RET1. A guest should pass a non-zero value to freeze and
1317 * a zero value to unfreeze all tracing. The returned previous state
1318 * is 0 for not frozen and 1 for frozen.
1319 */
1320#define HV_FAST_TTRACE_FREEZE 0x93
1321
1322/* ttrace_addentry()
1323 * TRAP: HV_TTRACE_ADDENTRY_TRAP
1324 * ARG0: tag (16-bits)
1325 * ARG1: data word 0
1326 * ARG2: data word 1
1327 * ARG3: data word 2
1328 * ARG4: data word 3
1329 * RET0: status
1330 * ERRORS: EINVAL No trap trace buffer currently defined
1331 *
1332 * Add an entry to the trap trace buffer. Upon return only ARG0/RET0
1333 * is modified - none of the other registers holding arguments are
1334 * volatile across this hypervisor service.
1335 */
1336
1337/* Core dump services.
1338 *
1339 * Since the hypervisor viraulizes and thus obscures a lot of the
1340 * physical machine layout and state, traditional OS crash dumps can
1341 * be difficult to diagnose especially when the problem is a
1342 * configuration error of some sort.
1343 *
1344 * The dump services provide an opaque buffer into which the
1345 * hypervisor can place it's internal state in order to assist in
1346 * debugging such situations. The contents are opaque and extremely
1347 * platform and hypervisor implementation specific. The guest, during
1348 * a core dump, requests that the hypervisor update any information in
1349 * the dump buffer in preparation to being dumped as part of the
1350 * domain's memory image.
1351 */
1352
1353/* dump_buf_update()
1354 * TRAP: HV_FAST_TRAP
1355 * FUNCTION: HV_FAST_DUMP_BUF_UPDATE
1356 * ARG0: real address
1357 * ARG1: size
1358 * RET0: status
1359 * RET1: required size of dump buffer
1360 * ERRORS: ENORADDR Invalid real address
1361 * EBADALIGN Real address is not aligned on a 64-byte
1362 * boundary
1363 * EINVAL Size is non-zero but less than minimum size
1364 * required
1365 * ENOTSUPPORTED Operation not supported on current logical
1366 * domain
1367 *
1368 * Declare a domain dump buffer to the hypervisor. The real address
1369 * provided for the domain dump buffer must be 64-byte aligned. The
1370 * size specifies the size of the dump buffer and may be larger than
1371 * the minimum size specified in the machine description. The
1372 * hypervisor will fill the dump buffer with opaque data.
1373 *
1374 * Note: A guest may elect to include dump buffer contents as part of a crash
1375 * dump to assist with debugging. This function may be called any number
1376 * of times so that a guest may relocate a dump buffer, or create
1377 * "snapshots" of any dump-buffer information. Each call to
1378 * dump_buf_update() atomically declares the new dump buffer to the
1379 * hypervisor.
1380 *
1381 * A specified size of 0 unconfigures the dump buffer. If the real
1382 * address is illegal or badly aligned, then any currently active dump
1383 * buffer is disabled and an error is returned.
1384 *
1385 * In the event that the call fails with EINVAL, RET1 contains the
1386 * minimum size requires by the hypervisor for a valid dump buffer.
1387 */
1388#define HV_FAST_DUMP_BUF_UPDATE 0x94
1389
1390/* dump_buf_info()
1391 * TRAP: HV_FAST_TRAP
1392 * FUNCTION: HV_FAST_DUMP_BUF_INFO
1393 * RET0: status
1394 * RET1: real address of current dump buffer
1395 * RET2: size of current dump buffer
1396 * ERRORS: No errors defined.
1397 *
1398 * Return the currently configures dump buffer description. A
1399 * returned size of 0 bytes indicates an undefined dump buffer. In
1400 * this case the return address in RET1 is undefined.
1401 */
1402#define HV_FAST_DUMP_BUF_INFO 0x95
1403
1404/* Device interrupt services.
1405 *
1406 * Device interrupts are allocated to system bus bridges by the hypervisor,
1407 * and described to OBP in the machine description. OBP then describes
1408 * these interrupts to the OS via properties in the device tree.
1409 *
1410 * Terminology:
1411 *
1412 * cpuid Unique opaque value which represents a target cpu.
1413 *
1414 * devhandle Device handle. It uniquely identifies a device, and
1415 * consistes of the lower 28-bits of the hi-cell of the
1416 * first entry of the device's "reg" property in the
1417 * OBP device tree.
1418 *
1419 * devino Device interrupt number. Specifies the relative
1420 * interrupt number within the device. The unique
1421 * combination of devhandle and devino are used to
1422 * identify a specific device interrupt.
1423 *
1424 * Note: The devino value is the same as the values in the
1425 * "interrupts" property or "interrupt-map" property
1426 * in the OBP device tree for that device.
1427 *
1428 * sysino System interrupt number. A 64-bit unsigned interger
1429 * representing a unique interrupt within a virtual
1430 * machine.
1431 *
1432 * intr_state A flag representing the interrupt state for a given
1433 * sysino. The state values are defined below.
1434 *
1435 * intr_enabled A flag representing the 'enabled' state for a given
1436 * sysino. The enable values are defined below.
1437 */
1438
1439#define HV_INTR_STATE_IDLE 0 /* Nothing pending */
1440#define HV_INTR_STATE_RECEIVED 1 /* Interrupt received by hardware */
1441#define HV_INTR_STATE_DELIVERED 2 /* Interrupt delivered to queue */
1442
1443#define HV_INTR_DISABLED 0 /* sysino not enabled */
1444#define HV_INTR_ENABLED 1 /* sysino enabled */
1445
1446/* intr_devino_to_sysino()
1447 * TRAP: HV_FAST_TRAP
1448 * FUNCTION: HV_FAST_INTR_DEVINO2SYSINO
1449 * ARG0: devhandle
1450 * ARG1: devino
1451 * RET0: status
1452 * RET1: sysino
1453 * ERRORS: EINVAL Invalid devhandle/devino
1454 *
1455 * Converts a device specific interrupt number of the given
1456 * devhandle/devino into a system specific ino (sysino).
1457 */
1458#define HV_FAST_INTR_DEVINO2SYSINO 0xa0
1459
1460#ifndef __ASSEMBLY__
1461extern unsigned long sun4v_devino_to_sysino(unsigned long devhandle,
1462 unsigned long devino);
1463#endif
1464
1465/* intr_getenabled()
1466 * TRAP: HV_FAST_TRAP
1467 * FUNCTION: HV_FAST_INTR_GETENABLED
1468 * ARG0: sysino
1469 * RET0: status
1470 * RET1: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1471 * ERRORS: EINVAL Invalid sysino
1472 *
1473 * Returns interrupt enabled state in RET1 for the interrupt defined
1474 * by the given sysino.
1475 */
1476#define HV_FAST_INTR_GETENABLED 0xa1
1477
1478#ifndef __ASSEMBLY__
1479extern unsigned long sun4v_intr_getenabled(unsigned long sysino);
1480#endif
1481
1482/* intr_setenabled()
1483 * TRAP: HV_FAST_TRAP
1484 * FUNCTION: HV_FAST_INTR_SETENABLED
1485 * ARG0: sysino
1486 * ARG1: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1487 * RET0: status
1488 * ERRORS: EINVAL Invalid sysino or intr_enabled value
1489 *
1490 * Set the 'enabled' state of the interrupt sysino.
1491 */
1492#define HV_FAST_INTR_SETENABLED 0xa2
1493
1494#ifndef __ASSEMBLY__
1495extern unsigned long sun4v_intr_setenabled(unsigned long sysino, unsigned long intr_enabled);
1496#endif
1497
1498/* intr_getstate()
1499 * TRAP: HV_FAST_TRAP
1500 * FUNCTION: HV_FAST_INTR_GETSTATE
1501 * ARG0: sysino
1502 * RET0: status
1503 * RET1: intr_state (HV_INTR_STATE_*)
1504 * ERRORS: EINVAL Invalid sysino
1505 *
1506 * Returns current state of the interrupt defined by the given sysino.
1507 */
1508#define HV_FAST_INTR_GETSTATE 0xa3
1509
1510#ifndef __ASSEMBLY__
1511extern unsigned long sun4v_intr_getstate(unsigned long sysino);
1512#endif
1513
1514/* intr_setstate()
1515 * TRAP: HV_FAST_TRAP
1516 * FUNCTION: HV_FAST_INTR_SETSTATE
1517 * ARG0: sysino
1518 * ARG1: intr_state (HV_INTR_STATE_*)
1519 * RET0: status
1520 * ERRORS: EINVAL Invalid sysino or intr_state value
1521 *
1522 * Sets the current state of the interrupt described by the given sysino
1523 * value.
1524 *
1525 * Note: Setting the state to HV_INTR_STATE_IDLE clears any pending
1526 * interrupt for sysino.
1527 */
1528#define HV_FAST_INTR_SETSTATE 0xa4
1529
1530#ifndef __ASSEMBLY__
1531extern unsigned long sun4v_intr_setstate(unsigned long sysino, unsigned long intr_state);
1532#endif
1533
1534/* intr_gettarget()
1535 * TRAP: HV_FAST_TRAP
1536 * FUNCTION: HV_FAST_INTR_GETTARGET
1537 * ARG0: sysino
1538 * RET0: status
1539 * RET1: cpuid
1540 * ERRORS: EINVAL Invalid sysino
1541 *
1542 * Returns CPU that is the current target of the interrupt defined by
1543 * the given sysino. The CPU value returned is undefined if the target
1544 * has not been set via intr_settarget().
1545 */
1546#define HV_FAST_INTR_GETTARGET 0xa5
1547
1548#ifndef __ASSEMBLY__
1549extern unsigned long sun4v_intr_gettarget(unsigned long sysino);
1550#endif
1551
1552/* intr_settarget()
1553 * TRAP: HV_FAST_TRAP
1554 * FUNCTION: HV_FAST_INTR_SETTARGET
1555 * ARG0: sysino
1556 * ARG1: cpuid
1557 * RET0: status
1558 * ERRORS: EINVAL Invalid sysino
1559 * ENOCPU Invalid cpuid
1560 *
1561 * Set the target CPU for the interrupt defined by the given sysino.
1562 */
1563#define HV_FAST_INTR_SETTARGET 0xa6
1564
1565#ifndef __ASSEMBLY__
1566extern unsigned long sun4v_intr_settarget(unsigned long sysino, unsigned long cpuid);
1567#endif
1568
1569/* vintr_get_cookie()
1570 * TRAP: HV_FAST_TRAP
1571 * FUNCTION: HV_FAST_VINTR_GET_COOKIE
1572 * ARG0: device handle
1573 * ARG1: device ino
1574 * RET0: status
1575 * RET1: cookie
1576 */
1577#define HV_FAST_VINTR_GET_COOKIE 0xa7
1578
1579/* vintr_set_cookie()
1580 * TRAP: HV_FAST_TRAP
1581 * FUNCTION: HV_FAST_VINTR_SET_COOKIE
1582 * ARG0: device handle
1583 * ARG1: device ino
1584 * ARG2: cookie
1585 * RET0: status
1586 */
1587#define HV_FAST_VINTR_SET_COOKIE 0xa8
1588
1589/* vintr_get_valid()
1590 * TRAP: HV_FAST_TRAP
1591 * FUNCTION: HV_FAST_VINTR_GET_VALID
1592 * ARG0: device handle
1593 * ARG1: device ino
1594 * RET0: status
1595 * RET1: valid state
1596 */
1597#define HV_FAST_VINTR_GET_VALID 0xa9
1598
1599/* vintr_set_valid()
1600 * TRAP: HV_FAST_TRAP
1601 * FUNCTION: HV_FAST_VINTR_SET_VALID
1602 * ARG0: device handle
1603 * ARG1: device ino
1604 * ARG2: valid state
1605 * RET0: status
1606 */
1607#define HV_FAST_VINTR_SET_VALID 0xaa
1608
1609/* vintr_get_state()
1610 * TRAP: HV_FAST_TRAP
1611 * FUNCTION: HV_FAST_VINTR_GET_STATE
1612 * ARG0: device handle
1613 * ARG1: device ino
1614 * RET0: status
1615 * RET1: state
1616 */
1617#define HV_FAST_VINTR_GET_STATE 0xab
1618
1619/* vintr_set_state()
1620 * TRAP: HV_FAST_TRAP
1621 * FUNCTION: HV_FAST_VINTR_SET_STATE
1622 * ARG0: device handle
1623 * ARG1: device ino
1624 * ARG2: state
1625 * RET0: status
1626 */
1627#define HV_FAST_VINTR_SET_STATE 0xac
1628
1629/* vintr_get_target()
1630 * TRAP: HV_FAST_TRAP
1631 * FUNCTION: HV_FAST_VINTR_GET_TARGET
1632 * ARG0: device handle
1633 * ARG1: device ino
1634 * RET0: status
1635 * RET1: cpuid
1636 */
1637#define HV_FAST_VINTR_GET_TARGET 0xad
1638
1639/* vintr_set_target()
1640 * TRAP: HV_FAST_TRAP
1641 * FUNCTION: HV_FAST_VINTR_SET_TARGET
1642 * ARG0: device handle
1643 * ARG1: device ino
1644 * ARG2: cpuid
1645 * RET0: status
1646 */
1647#define HV_FAST_VINTR_SET_TARGET 0xae
1648
1649#ifndef __ASSEMBLY__
1650extern unsigned long sun4v_vintr_get_cookie(unsigned long dev_handle,
1651 unsigned long dev_ino,
1652 unsigned long *cookie);
1653extern unsigned long sun4v_vintr_set_cookie(unsigned long dev_handle,
1654 unsigned long dev_ino,
1655 unsigned long cookie);
1656extern unsigned long sun4v_vintr_get_valid(unsigned long dev_handle,
1657 unsigned long dev_ino,
1658 unsigned long *valid);
1659extern unsigned long sun4v_vintr_set_valid(unsigned long dev_handle,
1660 unsigned long dev_ino,
1661 unsigned long valid);
1662extern unsigned long sun4v_vintr_get_state(unsigned long dev_handle,
1663 unsigned long dev_ino,
1664 unsigned long *state);
1665extern unsigned long sun4v_vintr_set_state(unsigned long dev_handle,
1666 unsigned long dev_ino,
1667 unsigned long state);
1668extern unsigned long sun4v_vintr_get_target(unsigned long dev_handle,
1669 unsigned long dev_ino,
1670 unsigned long *cpuid);
1671extern unsigned long sun4v_vintr_set_target(unsigned long dev_handle,
1672 unsigned long dev_ino,
1673 unsigned long cpuid);
1674#endif
1675
1676/* PCI IO services.
1677 *
1678 * See the terminology descriptions in the device interrupt services
1679 * section above as those apply here too. Here are terminology
1680 * definitions specific to these PCI IO services:
1681 *
1682 * tsbnum TSB number. Indentifies which io-tsb is used.
1683 * For this version of the specification, tsbnum
1684 * must be zero.
1685 *
1686 * tsbindex TSB index. Identifies which entry in the TSB
1687 * is used. The first entry is zero.
1688 *
1689 * tsbid A 64-bit aligned data structure which contains
1690 * a tsbnum and a tsbindex. Bits 63:32 contain the
1691 * tsbnum and bits 31:00 contain the tsbindex.
1692 *
1693 * Use the HV_PCI_TSBID() macro to construct such
1694 * values.
1695 *
1696 * io_attributes IO attributes for IOMMU mappings. One of more
1697 * of the attritbute bits are stores in a 64-bit
1698 * value. The values are defined below.
1699 *
1700 * r_addr 64-bit real address
1701 *
1702 * pci_device PCI device address. A PCI device address identifies
1703 * a specific device on a specific PCI bus segment.
1704 * A PCI device address ia a 32-bit unsigned integer
1705 * with the following format:
1706 *
1707 * 00000000.bbbbbbbb.dddddfff.00000000
1708 *
1709 * Use the HV_PCI_DEVICE_BUILD() macro to construct
1710 * such values.
1711 *
1712 * pci_config_offset
1713 * PCI configureation space offset. For conventional
1714 * PCI a value between 0 and 255. For extended
1715 * configuration space, a value between 0 and 4095.
1716 *
1717 * Note: For PCI configuration space accesses, the offset
1718 * must be aligned to the access size.
1719 *
1720 * error_flag A return value which specifies if the action succeeded
1721 * or failed. 0 means no error, non-0 means some error
1722 * occurred while performing the service.
1723 *
1724 * io_sync_direction
1725 * Direction definition for pci_dma_sync(), defined
1726 * below in HV_PCI_SYNC_*.
1727 *
1728 * io_page_list A list of io_page_addresses, an io_page_address is
1729 * a real address.
1730 *
1731 * io_page_list_p A pointer to an io_page_list.
1732 *
1733 * "size based byte swap" - Some functions do size based byte swapping
1734 * which allows sw to access pointers and
1735 * counters in native form when the processor
1736 * operates in a different endianness than the
1737 * IO bus. Size-based byte swapping converts a
1738 * multi-byte field between big-endian and
1739 * little-endian format.
1740 */
1741
1742#define HV_PCI_MAP_ATTR_READ 0x01
1743#define HV_PCI_MAP_ATTR_WRITE 0x02
1744
1745#define HV_PCI_DEVICE_BUILD(b,d,f) \
1746 ((((b) & 0xff) << 16) | \
1747 (((d) & 0x1f) << 11) | \
1748 (((f) & 0x07) << 8))
1749
1750#define HV_PCI_TSBID(__tsb_num, __tsb_index) \
1751 ((((u64)(__tsb_num)) << 32UL) | ((u64)(__tsb_index)))
1752
1753#define HV_PCI_SYNC_FOR_DEVICE 0x01
1754#define HV_PCI_SYNC_FOR_CPU 0x02
1755
1756/* pci_iommu_map()
1757 * TRAP: HV_FAST_TRAP
1758 * FUNCTION: HV_FAST_PCI_IOMMU_MAP
1759 * ARG0: devhandle
1760 * ARG1: tsbid
1761 * ARG2: #ttes
1762 * ARG3: io_attributes
1763 * ARG4: io_page_list_p
1764 * RET0: status
1765 * RET1: #ttes mapped
1766 * ERRORS: EINVAL Invalid devhandle/tsbnum/tsbindex/io_attributes
1767 * EBADALIGN Improperly aligned real address
1768 * ENORADDR Invalid real address
1769 *
1770 * Create IOMMU mappings in the sun4v device defined by the given
1771 * devhandle. The mappings are created in the TSB defined by the
1772 * tsbnum component of the given tsbid. The first mapping is created
1773 * in the TSB i ndex defined by the tsbindex component of the given tsbid.
1774 * The call creates up to #ttes mappings, the first one at tsbnum, tsbindex,
1775 * the second at tsbnum, tsbindex + 1, etc.
1776 *
1777 * All mappings are created with the attributes defined by the io_attributes
1778 * argument. The page mapping addresses are described in the io_page_list
1779 * defined by the given io_page_list_p, which is a pointer to the io_page_list.
1780 * The first entry in the io_page_list is the address for the first iotte, the
1781 * 2nd for the 2nd iotte, and so on.
1782 *
1783 * Each io_page_address in the io_page_list must be appropriately aligned.
1784 * #ttes must be greater than zero. For this version of the spec, the tsbnum
1785 * component of the given tsbid must be zero.
1786 *
1787 * Returns the actual number of mappings creates, which may be less than
1788 * or equal to the argument #ttes. If the function returns a value which
1789 * is less than the #ttes, the caller may continus to call the function with
1790 * an updated tsbid, #ttes, io_page_list_p arguments until all pages are
1791 * mapped.
1792 *
1793 * Note: This function does not imply an iotte cache flush. The guest must
1794 * demap an entry before re-mapping it.
1795 */
1796#define HV_FAST_PCI_IOMMU_MAP 0xb0
1797
1798/* pci_iommu_demap()
1799 * TRAP: HV_FAST_TRAP
1800 * FUNCTION: HV_FAST_PCI_IOMMU_DEMAP
1801 * ARG0: devhandle
1802 * ARG1: tsbid
1803 * ARG2: #ttes
1804 * RET0: status
1805 * RET1: #ttes demapped
1806 * ERRORS: EINVAL Invalid devhandle/tsbnum/tsbindex
1807 *
1808 * Demap and flush IOMMU mappings in the device defined by the given
1809 * devhandle. Demaps up to #ttes entries in the TSB defined by the tsbnum
1810 * component of the given tsbid, starting at the TSB index defined by the
1811 * tsbindex component of the given tsbid.
1812 *
1813 * For this version of the spec, the tsbnum of the given tsbid must be zero.
1814 * #ttes must be greater than zero.
1815 *
1816 * Returns the actual number of ttes demapped, which may be less than or equal
1817 * to the argument #ttes. If #ttes demapped is less than #ttes, the caller
1818 * may continue to call this function with updated tsbid and #ttes arguments
1819 * until all pages are demapped.
1820 *
1821 * Note: Entries do not have to be mapped to be demapped. A demap of an
1822 * unmapped page will flush the entry from the tte cache.
1823 */
1824#define HV_FAST_PCI_IOMMU_DEMAP 0xb1
1825
1826/* pci_iommu_getmap()
1827 * TRAP: HV_FAST_TRAP
1828 * FUNCTION: HV_FAST_PCI_IOMMU_GETMAP
1829 * ARG0: devhandle
1830 * ARG1: tsbid
1831 * RET0: status
1832 * RET1: io_attributes
1833 * RET2: real address
1834 * ERRORS: EINVAL Invalid devhandle/tsbnum/tsbindex
1835 * ENOMAP Mapping is not valid, no translation exists
1836 *
1837 * Read and return the mapping in the device described by the given devhandle
1838 * and tsbid. If successful, the io_attributes shall be returned in RET1
1839 * and the page address of the mapping shall be returned in RET2.
1840 *
1841 * For this version of the spec, the tsbnum component of the given tsbid
1842 * must be zero.
1843 */
1844#define HV_FAST_PCI_IOMMU_GETMAP 0xb2
1845
1846/* pci_iommu_getbypass()
1847 * TRAP: HV_FAST_TRAP
1848 * FUNCTION: HV_FAST_PCI_IOMMU_GETBYPASS
1849 * ARG0: devhandle
1850 * ARG1: real address
1851 * ARG2: io_attributes
1852 * RET0: status
1853 * RET1: io_addr
1854 * ERRORS: EINVAL Invalid devhandle/io_attributes
1855 * ENORADDR Invalid real address
1856 * ENOTSUPPORTED Function not supported in this implementation.
1857 *
1858 * Create a "special" mapping in the device described by the given devhandle,
1859 * for the given real address and attributes. Return the IO address in RET1
1860 * if successful.
1861 */
1862#define HV_FAST_PCI_IOMMU_GETBYPASS 0xb3
1863
1864/* pci_config_get()
1865 * TRAP: HV_FAST_TRAP
1866 * FUNCTION: HV_FAST_PCI_CONFIG_GET
1867 * ARG0: devhandle
1868 * ARG1: pci_device
1869 * ARG2: pci_config_offset
1870 * ARG3: size
1871 * RET0: status
1872 * RET1: error_flag
1873 * RET2: data
1874 * ERRORS: EINVAL Invalid devhandle/pci_device/offset/size
1875 * EBADALIGN pci_config_offset not size aligned
1876 * ENOACCESS Access to this offset is not permitted
1877 *
1878 * Read PCI configuration space for the adapter described by the given
1879 * devhandle. Read size (1, 2, or 4) bytes of data from the given
1880 * pci_device, at pci_config_offset from the beginning of the device's
1881 * configuration space. If there was no error, RET1 is set to zero and
1882 * RET2 is set to the data read. Insignificant bits in RET2 are not
1883 * guarenteed to have any specific value and therefore must be ignored.
1884 *
1885 * The data returned in RET2 is size based byte swapped.
1886 *
1887 * If an error occurs during the read, set RET1 to a non-zero value. The
1888 * given pci_config_offset must be 'size' aligned.
1889 */
1890#define HV_FAST_PCI_CONFIG_GET 0xb4
1891
1892/* pci_config_put()
1893 * TRAP: HV_FAST_TRAP
1894 * FUNCTION: HV_FAST_PCI_CONFIG_PUT
1895 * ARG0: devhandle
1896 * ARG1: pci_device
1897 * ARG2: pci_config_offset
1898 * ARG3: size
1899 * ARG4: data
1900 * RET0: status
1901 * RET1: error_flag
1902 * ERRORS: EINVAL Invalid devhandle/pci_device/offset/size
1903 * EBADALIGN pci_config_offset not size aligned
1904 * ENOACCESS Access to this offset is not permitted
1905 *
1906 * Write PCI configuration space for the adapter described by the given
1907 * devhandle. Write size (1, 2, or 4) bytes of data in a single operation,
1908 * at pci_config_offset from the beginning of the device's configuration
1909 * space. The data argument contains the data to be written to configuration
1910 * space. Prior to writing, the data is size based byte swapped.
1911 *
1912 * If an error occurs during the write access, do not generate an error
1913 * report, do set RET1 to a non-zero value. Otherwise RET1 is zero.
1914 * The given pci_config_offset must be 'size' aligned.
1915 *
1916 * This function is permitted to read from offset zero in the configuration
1917 * space described by the given pci_device if necessary to ensure that the
1918 * write access to config space completes.
1919 */
1920#define HV_FAST_PCI_CONFIG_PUT 0xb5
1921
1922/* pci_peek()
1923 * TRAP: HV_FAST_TRAP
1924 * FUNCTION: HV_FAST_PCI_PEEK
1925 * ARG0: devhandle
1926 * ARG1: real address
1927 * ARG2: size
1928 * RET0: status
1929 * RET1: error_flag
1930 * RET2: data
1931 * ERRORS: EINVAL Invalid devhandle or size
1932 * EBADALIGN Improperly aligned real address
1933 * ENORADDR Bad real address
1934 * ENOACCESS Guest access prohibited
1935 *
1936 * Attempt to read the IO address given by the given devhandle, real address,
1937 * and size. Size must be 1, 2, 4, or 8. The read is performed as a single
1938 * access operation using the given size. If an error occurs when reading
1939 * from the given location, do not generate an error report, but return a
1940 * non-zero value in RET1. If the read was successful, return zero in RET1
1941 * and return the actual data read in RET2. The data returned is size based
1942 * byte swapped.
1943 *
1944 * Non-significant bits in RET2 are not guarenteed to have any specific value
1945 * and therefore must be ignored. If RET1 is returned as non-zero, the data
1946 * value is not guarenteed to have any specific value and should be ignored.
1947 *
1948 * The caller must have permission to read from the given devhandle, real
1949 * address, which must be an IO address. The argument real address must be a
1950 * size aligned address.
1951 *
1952 * The hypervisor implementation of this function must block access to any
1953 * IO address that the guest does not have explicit permission to access.
1954 */
1955#define HV_FAST_PCI_PEEK 0xb6
1956
1957/* pci_poke()
1958 * TRAP: HV_FAST_TRAP
1959 * FUNCTION: HV_FAST_PCI_POKE
1960 * ARG0: devhandle
1961 * ARG1: real address
1962 * ARG2: size
1963 * ARG3: data
1964 * ARG4: pci_device
1965 * RET0: status
1966 * RET1: error_flag
1967 * ERRORS: EINVAL Invalid devhandle, size, or pci_device
1968 * EBADALIGN Improperly aligned real address
1969 * ENORADDR Bad real address
1970 * ENOACCESS Guest access prohibited
1971 * ENOTSUPPORTED Function is not supported by implementation
1972 *
1973 * Attempt to write data to the IO address given by the given devhandle,
1974 * real address, and size. Size must be 1, 2, 4, or 8. The write is
1975 * performed as a single access operation using the given size. Prior to
1976 * writing the data is size based swapped.
1977 *
1978 * If an error occurs when writing to the given location, do not generate an
1979 * error report, but return a non-zero value in RET1. If the write was
1980 * successful, return zero in RET1.
1981 *
1982 * pci_device describes the configuration address of the device being
1983 * written to. The implementation may safely read from offset 0 with
1984 * the configuration space of the device described by devhandle and
1985 * pci_device in order to guarantee that the write portion of the operation
1986 * completes
1987 *
1988 * Any error that occurs due to the read shall be reported using the normal
1989 * error reporting mechanisms .. the read error is not suppressed.
1990 *
1991 * The caller must have permission to write to the given devhandle, real
1992 * address, which must be an IO address. The argument real address must be a
1993 * size aligned address. The caller must have permission to read from
1994 * the given devhandle, pci_device cofiguration space offset 0.
1995 *
1996 * The hypervisor implementation of this function must block access to any
1997 * IO address that the guest does not have explicit permission to access.
1998 */
1999#define HV_FAST_PCI_POKE 0xb7
2000
2001/* pci_dma_sync()
2002 * TRAP: HV_FAST_TRAP
2003 * FUNCTION: HV_FAST_PCI_DMA_SYNC
2004 * ARG0: devhandle
2005 * ARG1: real address
2006 * ARG2: size
2007 * ARG3: io_sync_direction
2008 * RET0: status
2009 * RET1: #synced
2010 * ERRORS: EINVAL Invalid devhandle or io_sync_direction
2011 * ENORADDR Bad real address
2012 *
2013 * Synchronize a memory region described by the given real address and size,
2014 * for the device defined by the given devhandle using the direction(s)
2015 * defined by the given io_sync_direction. The argument size is the size of
2016 * the memory region in bytes.
2017 *
2018 * Return the actual number of bytes synchronized in the return value #synced,
2019 * which may be less than or equal to the argument size. If the return
2020 * value #synced is less than size, the caller must continue to call this
2021 * function with updated real address and size arguments until the entire
2022 * memory region is synchronized.
2023 */
2024#define HV_FAST_PCI_DMA_SYNC 0xb8
2025
2026/* PCI MSI services. */
2027
2028#define HV_MSITYPE_MSI32 0x00
2029#define HV_MSITYPE_MSI64 0x01
2030
2031#define HV_MSIQSTATE_IDLE 0x00
2032#define HV_MSIQSTATE_ERROR 0x01
2033
2034#define HV_MSIQ_INVALID 0x00
2035#define HV_MSIQ_VALID 0x01
2036
2037#define HV_MSISTATE_IDLE 0x00
2038#define HV_MSISTATE_DELIVERED 0x01
2039
2040#define HV_MSIVALID_INVALID 0x00
2041#define HV_MSIVALID_VALID 0x01
2042
2043#define HV_PCIE_MSGTYPE_PME_MSG 0x18
2044#define HV_PCIE_MSGTYPE_PME_ACK_MSG 0x1b
2045#define HV_PCIE_MSGTYPE_CORR_MSG 0x30
2046#define HV_PCIE_MSGTYPE_NONFATAL_MSG 0x31
2047#define HV_PCIE_MSGTYPE_FATAL_MSG 0x33
2048
2049#define HV_MSG_INVALID 0x00
2050#define HV_MSG_VALID 0x01
2051
2052/* pci_msiq_conf()
2053 * TRAP: HV_FAST_TRAP
2054 * FUNCTION: HV_FAST_PCI_MSIQ_CONF
2055 * ARG0: devhandle
2056 * ARG1: msiqid
2057 * ARG2: real address
2058 * ARG3: number of entries
2059 * RET0: status
2060 * ERRORS: EINVAL Invalid devhandle, msiqid or nentries
2061 * EBADALIGN Improperly aligned real address
2062 * ENORADDR Bad real address
2063 *
2064 * Configure the MSI queue given by the devhandle and msiqid arguments,
2065 * and to be placed at the given real address and be of the given
2066 * number of entries. The real address must be aligned exactly to match
2067 * the queue size. Each queue entry is 64-bytes long, so f.e. a 32 entry
2068 * queue must be aligned on a 2048 byte real address boundary. The MSI-EQ
2069 * Head and Tail are initialized so that the MSI-EQ is 'empty'.
2070 *
2071 * Implementation Note: Certain implementations have fixed sized queues. In
2072 * that case, number of entries must contain the correct
2073 * value.
2074 */
2075#define HV_FAST_PCI_MSIQ_CONF 0xc0
2076
2077/* pci_msiq_info()
2078 * TRAP: HV_FAST_TRAP
2079 * FUNCTION: HV_FAST_PCI_MSIQ_INFO
2080 * ARG0: devhandle
2081 * ARG1: msiqid
2082 * RET0: status
2083 * RET1: real address
2084 * RET2: number of entries
2085 * ERRORS: EINVAL Invalid devhandle or msiqid
2086 *
2087 * Return the configuration information for the MSI queue described
2088 * by the given devhandle and msiqid. The base address of the queue
2089 * is returned in ARG1 and the number of entries is returned in ARG2.
2090 * If the queue is unconfigured, the real address is undefined and the
2091 * number of entries will be returned as zero.
2092 */
2093#define HV_FAST_PCI_MSIQ_INFO 0xc1
2094
2095/* pci_msiq_getvalid()
2096 * TRAP: HV_FAST_TRAP
2097 * FUNCTION: HV_FAST_PCI_MSIQ_GETVALID
2098 * ARG0: devhandle
2099 * ARG1: msiqid
2100 * RET0: status
2101 * RET1: msiqvalid (HV_MSIQ_VALID or HV_MSIQ_INVALID)
2102 * ERRORS: EINVAL Invalid devhandle or msiqid
2103 *
2104 * Get the valid state of the MSI-EQ described by the given devhandle and
2105 * msiqid.
2106 */
2107#define HV_FAST_PCI_MSIQ_GETVALID 0xc2
2108
2109/* pci_msiq_setvalid()
2110 * TRAP: HV_FAST_TRAP
2111 * FUNCTION: HV_FAST_PCI_MSIQ_SETVALID
2112 * ARG0: devhandle
2113 * ARG1: msiqid
2114 * ARG2: msiqvalid (HV_MSIQ_VALID or HV_MSIQ_INVALID)
2115 * RET0: status
2116 * ERRORS: EINVAL Invalid devhandle or msiqid or msiqvalid
2117 * value or MSI EQ is uninitialized
2118 *
2119 * Set the valid state of the MSI-EQ described by the given devhandle and
2120 * msiqid to the given msiqvalid.
2121 */
2122#define HV_FAST_PCI_MSIQ_SETVALID 0xc3
2123
2124/* pci_msiq_getstate()
2125 * TRAP: HV_FAST_TRAP
2126 * FUNCTION: HV_FAST_PCI_MSIQ_GETSTATE
2127 * ARG0: devhandle
2128 * ARG1: msiqid
2129 * RET0: status
2130 * RET1: msiqstate (HV_MSIQSTATE_IDLE or HV_MSIQSTATE_ERROR)
2131 * ERRORS: EINVAL Invalid devhandle or msiqid
2132 *
2133 * Get the state of the MSI-EQ described by the given devhandle and
2134 * msiqid.
2135 */
2136#define HV_FAST_PCI_MSIQ_GETSTATE 0xc4
2137
2138/* pci_msiq_getvalid()
2139 * TRAP: HV_FAST_TRAP
2140 * FUNCTION: HV_FAST_PCI_MSIQ_GETVALID
2141 * ARG0: devhandle
2142 * ARG1: msiqid
2143 * ARG2: msiqstate (HV_MSIQSTATE_IDLE or HV_MSIQSTATE_ERROR)
2144 * RET0: status
2145 * ERRORS: EINVAL Invalid devhandle or msiqid or msiqstate
2146 * value or MSI EQ is uninitialized
2147 *
2148 * Set the state of the MSI-EQ described by the given devhandle and
2149 * msiqid to the given msiqvalid.
2150 */
2151#define HV_FAST_PCI_MSIQ_SETSTATE 0xc5
2152
2153/* pci_msiq_gethead()
2154 * TRAP: HV_FAST_TRAP
2155 * FUNCTION: HV_FAST_PCI_MSIQ_GETHEAD
2156 * ARG0: devhandle
2157 * ARG1: msiqid
2158 * RET0: status
2159 * RET1: msiqhead
2160 * ERRORS: EINVAL Invalid devhandle or msiqid
2161 *
2162 * Get the current MSI EQ queue head for the MSI-EQ described by the
2163 * given devhandle and msiqid.
2164 */
2165#define HV_FAST_PCI_MSIQ_GETHEAD 0xc6
2166
2167/* pci_msiq_sethead()
2168 * TRAP: HV_FAST_TRAP
2169 * FUNCTION: HV_FAST_PCI_MSIQ_SETHEAD
2170 * ARG0: devhandle
2171 * ARG1: msiqid
2172 * ARG2: msiqhead
2173 * RET0: status
2174 * ERRORS: EINVAL Invalid devhandle or msiqid or msiqhead,
2175 * or MSI EQ is uninitialized
2176 *
2177 * Set the current MSI EQ queue head for the MSI-EQ described by the
2178 * given devhandle and msiqid.
2179 */
2180#define HV_FAST_PCI_MSIQ_SETHEAD 0xc7
2181
2182/* pci_msiq_gettail()
2183 * TRAP: HV_FAST_TRAP
2184 * FUNCTION: HV_FAST_PCI_MSIQ_GETTAIL
2185 * ARG0: devhandle
2186 * ARG1: msiqid
2187 * RET0: status
2188 * RET1: msiqtail
2189 * ERRORS: EINVAL Invalid devhandle or msiqid
2190 *
2191 * Get the current MSI EQ queue tail for the MSI-EQ described by the
2192 * given devhandle and msiqid.
2193 */
2194#define HV_FAST_PCI_MSIQ_GETTAIL 0xc8
2195
2196/* pci_msi_getvalid()
2197 * TRAP: HV_FAST_TRAP
2198 * FUNCTION: HV_FAST_PCI_MSI_GETVALID
2199 * ARG0: devhandle
2200 * ARG1: msinum
2201 * RET0: status
2202 * RET1: msivalidstate
2203 * ERRORS: EINVAL Invalid devhandle or msinum
2204 *
2205 * Get the current valid/enabled state for the MSI defined by the
2206 * given devhandle and msinum.
2207 */
2208#define HV_FAST_PCI_MSI_GETVALID 0xc9
2209
2210/* pci_msi_setvalid()
2211 * TRAP: HV_FAST_TRAP
2212 * FUNCTION: HV_FAST_PCI_MSI_SETVALID
2213 * ARG0: devhandle
2214 * ARG1: msinum
2215 * ARG2: msivalidstate
2216 * RET0: status
2217 * ERRORS: EINVAL Invalid devhandle or msinum or msivalidstate
2218 *
2219 * Set the current valid/enabled state for the MSI defined by the
2220 * given devhandle and msinum.
2221 */
2222#define HV_FAST_PCI_MSI_SETVALID 0xca
2223
2224/* pci_msi_getmsiq()
2225 * TRAP: HV_FAST_TRAP
2226 * FUNCTION: HV_FAST_PCI_MSI_GETMSIQ
2227 * ARG0: devhandle
2228 * ARG1: msinum
2229 * RET0: status
2230 * RET1: msiqid
2231 * ERRORS: EINVAL Invalid devhandle or msinum or MSI is unbound
2232 *
2233 * Get the MSI EQ that the MSI defined by the given devhandle and
2234 * msinum is bound to.
2235 */
2236#define HV_FAST_PCI_MSI_GETMSIQ 0xcb
2237
2238/* pci_msi_setmsiq()
2239 * TRAP: HV_FAST_TRAP
2240 * FUNCTION: HV_FAST_PCI_MSI_SETMSIQ
2241 * ARG0: devhandle
2242 * ARG1: msinum
2243 * ARG2: msitype
2244 * ARG3: msiqid
2245 * RET0: status
2246 * ERRORS: EINVAL Invalid devhandle or msinum or msiqid
2247 *
2248 * Set the MSI EQ that the MSI defined by the given devhandle and
2249 * msinum is bound to.
2250 */
2251#define HV_FAST_PCI_MSI_SETMSIQ 0xcc
2252
2253/* pci_msi_getstate()
2254 * TRAP: HV_FAST_TRAP
2255 * FUNCTION: HV_FAST_PCI_MSI_GETSTATE
2256 * ARG0: devhandle
2257 * ARG1: msinum
2258 * RET0: status
2259 * RET1: msistate
2260 * ERRORS: EINVAL Invalid devhandle or msinum
2261 *
2262 * Get the state of the MSI defined by the given devhandle and msinum.
2263 * If not initialized, return HV_MSISTATE_IDLE.
2264 */
2265#define HV_FAST_PCI_MSI_GETSTATE 0xcd
2266
2267/* pci_msi_setstate()
2268 * TRAP: HV_FAST_TRAP
2269 * FUNCTION: HV_FAST_PCI_MSI_SETSTATE
2270 * ARG0: devhandle
2271 * ARG1: msinum
2272 * ARG2: msistate
2273 * RET0: status
2274 * ERRORS: EINVAL Invalid devhandle or msinum or msistate
2275 *
2276 * Set the state of the MSI defined by the given devhandle and msinum.
2277 */
2278#define HV_FAST_PCI_MSI_SETSTATE 0xce
2279
2280/* pci_msg_getmsiq()
2281 * TRAP: HV_FAST_TRAP
2282 * FUNCTION: HV_FAST_PCI_MSG_GETMSIQ
2283 * ARG0: devhandle
2284 * ARG1: msgtype
2285 * RET0: status
2286 * RET1: msiqid
2287 * ERRORS: EINVAL Invalid devhandle or msgtype
2288 *
2289 * Get the MSI EQ of the MSG defined by the given devhandle and msgtype.
2290 */
2291#define HV_FAST_PCI_MSG_GETMSIQ 0xd0
2292
2293/* pci_msg_setmsiq()
2294 * TRAP: HV_FAST_TRAP
2295 * FUNCTION: HV_FAST_PCI_MSG_SETMSIQ
2296 * ARG0: devhandle
2297 * ARG1: msgtype
2298 * ARG2: msiqid
2299 * RET0: status
2300 * ERRORS: EINVAL Invalid devhandle, msgtype, or msiqid
2301 *
2302 * Set the MSI EQ of the MSG defined by the given devhandle and msgtype.
2303 */
2304#define HV_FAST_PCI_MSG_SETMSIQ 0xd1
2305
2306/* pci_msg_getvalid()
2307 * TRAP: HV_FAST_TRAP
2308 * FUNCTION: HV_FAST_PCI_MSG_GETVALID
2309 * ARG0: devhandle
2310 * ARG1: msgtype
2311 * RET0: status
2312 * RET1: msgvalidstate
2313 * ERRORS: EINVAL Invalid devhandle or msgtype
2314 *
2315 * Get the valid/enabled state of the MSG defined by the given
2316 * devhandle and msgtype.
2317 */
2318#define HV_FAST_PCI_MSG_GETVALID 0xd2
2319
2320/* pci_msg_setvalid()
2321 * TRAP: HV_FAST_TRAP
2322 * FUNCTION: HV_FAST_PCI_MSG_SETVALID
2323 * ARG0: devhandle
2324 * ARG1: msgtype
2325 * ARG2: msgvalidstate
2326 * RET0: status
2327 * ERRORS: EINVAL Invalid devhandle or msgtype or msgvalidstate
2328 *
2329 * Set the valid/enabled state of the MSG defined by the given
2330 * devhandle and msgtype.
2331 */
2332#define HV_FAST_PCI_MSG_SETVALID 0xd3
2333
2334/* Logical Domain Channel services. */
2335
2336#define LDC_CHANNEL_DOWN 0
2337#define LDC_CHANNEL_UP 1
2338#define LDC_CHANNEL_RESETTING 2
2339
2340/* ldc_tx_qconf()
2341 * TRAP: HV_FAST_TRAP
2342 * FUNCTION: HV_FAST_LDC_TX_QCONF
2343 * ARG0: channel ID
2344 * ARG1: real address base of queue
2345 * ARG2: num entries in queue
2346 * RET0: status
2347 *
2348 * Configure transmit queue for the LDC endpoint specified by the
2349 * given channel ID, to be placed at the given real address, and
2350 * be of the given num entries. Num entries must be a power of two.
2351 * The real address base of the queue must be aligned on the queue
2352 * size. Each queue entry is 64-bytes, so for example, a 32 entry
2353 * queue must be aligned on a 2048 byte real address boundary.
2354 *
2355 * Upon configuration of a valid transmit queue the head and tail
2356 * pointers are set to a hypervisor specific identical value indicating
2357 * that the queue initially is empty.
2358 *
2359 * The endpoint's transmit queue is un-configured if num entries is zero.
2360 *
2361 * The maximum number of entries for each queue for a specific cpu may be
2362 * determined from the machine description. A transmit queue may be
2363 * specified even in the event that the LDC is down (peer endpoint has no
2364 * receive queue specified). Transmission will begin as soon as the peer
2365 * endpoint defines a receive queue.
2366 *
2367 * It is recommended that a guest wait for a transmit queue to empty prior
2368 * to reconfiguring it, or un-configuring it. Re or un-configuring of a
2369 * non-empty transmit queue behaves exactly as defined above, however it
2370 * is undefined as to how many of the pending entries in the original queue
2371 * will be delivered prior to the re-configuration taking effect.
2372 * Furthermore, as the queue configuration causes a reset of the head and
2373 * tail pointers there is no way for a guest to determine how many entries
2374 * have been sent after the configuration operation.
2375 */
2376#define HV_FAST_LDC_TX_QCONF 0xe0
2377
2378/* ldc_tx_qinfo()
2379 * TRAP: HV_FAST_TRAP
2380 * FUNCTION: HV_FAST_LDC_TX_QINFO
2381 * ARG0: channel ID
2382 * RET0: status
2383 * RET1: real address base of queue
2384 * RET2: num entries in queue
2385 *
2386 * Return the configuration info for the transmit queue of LDC endpoint
2387 * defined by the given channel ID. The real address is the currently
2388 * defined real address base of the defined queue, and num entries is the
2389 * size of the queue in terms of number of entries.
2390 *
2391 * If the specified channel ID is a valid endpoint number, but no transmit
2392 * queue has been defined this service will return success, but with num
2393 * entries set to zero and the real address will have an undefined value.
2394 */
2395#define HV_FAST_LDC_TX_QINFO 0xe1
2396
2397/* ldc_tx_get_state()
2398 * TRAP: HV_FAST_TRAP
2399 * FUNCTION: HV_FAST_LDC_TX_GET_STATE
2400 * ARG0: channel ID
2401 * RET0: status
2402 * RET1: head offset
2403 * RET2: tail offset
2404 * RET3: channel state
2405 *
2406 * Return the transmit state, and the head and tail queue pointers, for
2407 * the transmit queue of the LDC endpoint defined by the given channel ID.
2408 * The head and tail values are the byte offset of the head and tail
2409 * positions of the transmit queue for the specified endpoint.
2410 */
2411#define HV_FAST_LDC_TX_GET_STATE 0xe2
2412
2413/* ldc_tx_set_qtail()
2414 * TRAP: HV_FAST_TRAP
2415 * FUNCTION: HV_FAST_LDC_TX_SET_QTAIL
2416 * ARG0: channel ID
2417 * ARG1: tail offset
2418 * RET0: status
2419 *
2420 * Update the tail pointer for the transmit queue associated with the LDC
2421 * endpoint defined by the given channel ID. The tail offset specified
2422 * must be aligned on a 64 byte boundary, and calculated so as to increase
2423 * the number of pending entries on the transmit queue. Any attempt to
2424 * decrease the number of pending transmit queue entires is considered
2425 * an invalid tail offset and will result in an EINVAL error.
2426 *
2427 * Since the tail of the transmit queue may not be moved backwards, the
2428 * transmit queue may be flushed by configuring a new transmit queue,
2429 * whereupon the hypervisor will configure the initial transmit head and
2430 * tail pointers to be equal.
2431 */
2432#define HV_FAST_LDC_TX_SET_QTAIL 0xe3
2433
2434/* ldc_rx_qconf()
2435 * TRAP: HV_FAST_TRAP
2436 * FUNCTION: HV_FAST_LDC_RX_QCONF
2437 * ARG0: channel ID
2438 * ARG1: real address base of queue
2439 * ARG2: num entries in queue
2440 * RET0: status
2441 *
2442 * Configure receive queue for the LDC endpoint specified by the
2443 * given channel ID, to be placed at the given real address, and
2444 * be of the given num entries. Num entries must be a power of two.
2445 * The real address base of the queue must be aligned on the queue
2446 * size. Each queue entry is 64-bytes, so for example, a 32 entry
2447 * queue must be aligned on a 2048 byte real address boundary.
2448 *
2449 * The endpoint's transmit queue is un-configured if num entries is zero.
2450 *
2451 * If a valid receive queue is specified for a local endpoint the LDC is
2452 * in the up state for the purpose of transmission to this endpoint.
2453 *
2454 * The maximum number of entries for each queue for a specific cpu may be
2455 * determined from the machine description.
2456 *
2457 * As receive queue configuration causes a reset of the queue's head and
2458 * tail pointers there is no way for a gues to determine how many entries
2459 * have been received between a preceeding ldc_get_rx_state() API call
2460 * and the completion of the configuration operation. It should be noted
2461 * that datagram delivery is not guarenteed via domain channels anyway,
2462 * and therefore any higher protocol should be resilient to datagram
2463 * loss if necessary. However, to overcome this specific race potential
2464 * it is recommended, for example, that a higher level protocol be employed
2465 * to ensure either retransmission, or ensure that no datagrams are pending
2466 * on the peer endpoint's transmit queue prior to the configuration process.
2467 */
2468#define HV_FAST_LDC_RX_QCONF 0xe4
2469
2470/* ldc_rx_qinfo()
2471 * TRAP: HV_FAST_TRAP
2472 * FUNCTION: HV_FAST_LDC_RX_QINFO
2473 * ARG0: channel ID
2474 * RET0: status
2475 * RET1: real address base of queue
2476 * RET2: num entries in queue
2477 *
2478 * Return the configuration info for the receive queue of LDC endpoint
2479 * defined by the given channel ID. The real address is the currently
2480 * defined real address base of the defined queue, and num entries is the
2481 * size of the queue in terms of number of entries.
2482 *
2483 * If the specified channel ID is a valid endpoint number, but no receive
2484 * queue has been defined this service will return success, but with num
2485 * entries set to zero and the real address will have an undefined value.
2486 */
2487#define HV_FAST_LDC_RX_QINFO 0xe5
2488
2489/* ldc_rx_get_state()
2490 * TRAP: HV_FAST_TRAP
2491 * FUNCTION: HV_FAST_LDC_RX_GET_STATE
2492 * ARG0: channel ID
2493 * RET0: status
2494 * RET1: head offset
2495 * RET2: tail offset
2496 * RET3: channel state
2497 *
2498 * Return the receive state, and the head and tail queue pointers, for
2499 * the receive queue of the LDC endpoint defined by the given channel ID.
2500 * The head and tail values are the byte offset of the head and tail
2501 * positions of the receive queue for the specified endpoint.
2502 */
2503#define HV_FAST_LDC_RX_GET_STATE 0xe6
2504
2505/* ldc_rx_set_qhead()
2506 * TRAP: HV_FAST_TRAP
2507 * FUNCTION: HV_FAST_LDC_RX_SET_QHEAD
2508 * ARG0: channel ID
2509 * ARG1: head offset
2510 * RET0: status
2511 *
2512 * Update the head pointer for the receive queue associated with the LDC
2513 * endpoint defined by the given channel ID. The head offset specified
2514 * must be aligned on a 64 byte boundary, and calculated so as to decrease
2515 * the number of pending entries on the receive queue. Any attempt to
2516 * increase the number of pending receive queue entires is considered
2517 * an invalid head offset and will result in an EINVAL error.
2518 *
2519 * The receive queue may be flushed by setting the head offset equal
2520 * to the current tail offset.
2521 */
2522#define HV_FAST_LDC_RX_SET_QHEAD 0xe7
2523
2524/* LDC Map Table Entry. Each slot is defined by a translation table
2525 * entry, as specified by the LDC_MTE_* bits below, and a 64-bit
2526 * hypervisor invalidation cookie.
2527 */
2528#define LDC_MTE_PADDR 0x0fffffffffffe000 /* pa[55:13] */
2529#define LDC_MTE_COPY_W 0x0000000000000400 /* copy write access */
2530#define LDC_MTE_COPY_R 0x0000000000000200 /* copy read access */
2531#define LDC_MTE_IOMMU_W 0x0000000000000100 /* IOMMU write access */
2532#define LDC_MTE_IOMMU_R 0x0000000000000080 /* IOMMU read access */
2533#define LDC_MTE_EXEC 0x0000000000000040 /* execute */
2534#define LDC_MTE_WRITE 0x0000000000000020 /* read */
2535#define LDC_MTE_READ 0x0000000000000010 /* write */
2536#define LDC_MTE_SZALL 0x000000000000000f /* page size bits */
2537#define LDC_MTE_SZ16GB 0x0000000000000007 /* 16GB page */
2538#define LDC_MTE_SZ2GB 0x0000000000000006 /* 2GB page */
2539#define LDC_MTE_SZ256MB 0x0000000000000005 /* 256MB page */
2540#define LDC_MTE_SZ32MB 0x0000000000000004 /* 32MB page */
2541#define LDC_MTE_SZ4MB 0x0000000000000003 /* 4MB page */
2542#define LDC_MTE_SZ512K 0x0000000000000002 /* 512K page */
2543#define LDC_MTE_SZ64K 0x0000000000000001 /* 64K page */
2544#define LDC_MTE_SZ8K 0x0000000000000000 /* 8K page */
2545
2546#ifndef __ASSEMBLY__
2547struct ldc_mtable_entry {
2548 unsigned long mte;
2549 unsigned long cookie;
2550};
2551#endif
2552
2553/* ldc_set_map_table()
2554 * TRAP: HV_FAST_TRAP
2555 * FUNCTION: HV_FAST_LDC_SET_MAP_TABLE
2556 * ARG0: channel ID
2557 * ARG1: table real address
2558 * ARG2: num entries
2559 * RET0: status
2560 *
2561 * Register the MTE table at the given table real address, with the
2562 * specified num entries, for the LDC indicated by the given channel
2563 * ID.
2564 */
2565#define HV_FAST_LDC_SET_MAP_TABLE 0xea
2566
2567/* ldc_get_map_table()
2568 * TRAP: HV_FAST_TRAP
2569 * FUNCTION: HV_FAST_LDC_GET_MAP_TABLE
2570 * ARG0: channel ID
2571 * RET0: status
2572 * RET1: table real address
2573 * RET2: num entries
2574 *
2575 * Return the configuration of the current mapping table registered
2576 * for the given channel ID.
2577 */
2578#define HV_FAST_LDC_GET_MAP_TABLE 0xeb
2579
2580#define LDC_COPY_IN 0
2581#define LDC_COPY_OUT 1
2582
2583/* ldc_copy()
2584 * TRAP: HV_FAST_TRAP
2585 * FUNCTION: HV_FAST_LDC_COPY
2586 * ARG0: channel ID
2587 * ARG1: LDC_COPY_* direction code
2588 * ARG2: target real address
2589 * ARG3: local real address
2590 * ARG4: length in bytes
2591 * RET0: status
2592 * RET1: actual length in bytes
2593 */
2594#define HV_FAST_LDC_COPY 0xec
2595
2596#define LDC_MEM_READ 1
2597#define LDC_MEM_WRITE 2
2598#define LDC_MEM_EXEC 4
2599
2600/* ldc_mapin()
2601 * TRAP: HV_FAST_TRAP
2602 * FUNCTION: HV_FAST_LDC_MAPIN
2603 * ARG0: channel ID
2604 * ARG1: cookie
2605 * RET0: status
2606 * RET1: real address
2607 * RET2: LDC_MEM_* permissions
2608 */
2609#define HV_FAST_LDC_MAPIN 0xed
2610
2611/* ldc_unmap()
2612 * TRAP: HV_FAST_TRAP
2613 * FUNCTION: HV_FAST_LDC_UNMAP
2614 * ARG0: real address
2615 * RET0: status
2616 */
2617#define HV_FAST_LDC_UNMAP 0xee
2618
2619/* ldc_revoke()
2620 * TRAP: HV_FAST_TRAP
2621 * FUNCTION: HV_FAST_LDC_REVOKE
2622 * ARG0: channel ID
2623 * ARG1: cookie
2624 * ARG2: ldc_mtable_entry cookie
2625 * RET0: status
2626 */
2627#define HV_FAST_LDC_REVOKE 0xef
2628
2629#ifndef __ASSEMBLY__
2630extern unsigned long sun4v_ldc_tx_qconf(unsigned long channel,
2631 unsigned long ra,
2632 unsigned long num_entries);
2633extern unsigned long sun4v_ldc_tx_qinfo(unsigned long channel,
2634 unsigned long *ra,
2635 unsigned long *num_entries);
2636extern unsigned long sun4v_ldc_tx_get_state(unsigned long channel,
2637 unsigned long *head_off,
2638 unsigned long *tail_off,
2639 unsigned long *chan_state);
2640extern unsigned long sun4v_ldc_tx_set_qtail(unsigned long channel,
2641 unsigned long tail_off);
2642extern unsigned long sun4v_ldc_rx_qconf(unsigned long channel,
2643 unsigned long ra,
2644 unsigned long num_entries);
2645extern unsigned long sun4v_ldc_rx_qinfo(unsigned long channel,
2646 unsigned long *ra,
2647 unsigned long *num_entries);
2648extern unsigned long sun4v_ldc_rx_get_state(unsigned long channel,
2649 unsigned long *head_off,
2650 unsigned long *tail_off,
2651 unsigned long *chan_state);
2652extern unsigned long sun4v_ldc_rx_set_qhead(unsigned long channel,
2653 unsigned long head_off);
2654extern unsigned long sun4v_ldc_set_map_table(unsigned long channel,
2655 unsigned long ra,
2656 unsigned long num_entries);
2657extern unsigned long sun4v_ldc_get_map_table(unsigned long channel,
2658 unsigned long *ra,
2659 unsigned long *num_entries);
2660extern unsigned long sun4v_ldc_copy(unsigned long channel,
2661 unsigned long dir_code,
2662 unsigned long tgt_raddr,
2663 unsigned long lcl_raddr,
2664 unsigned long len,
2665 unsigned long *actual_len);
2666extern unsigned long sun4v_ldc_mapin(unsigned long channel,
2667 unsigned long cookie,
2668 unsigned long *ra,
2669 unsigned long *perm);
2670extern unsigned long sun4v_ldc_unmap(unsigned long ra);
2671extern unsigned long sun4v_ldc_revoke(unsigned long channel,
2672 unsigned long cookie,
2673 unsigned long mte_cookie);
2674#endif
2675
2676/* Performance counter services. */
2677
2678#define HV_PERF_JBUS_PERF_CTRL_REG 0x00
2679#define HV_PERF_JBUS_PERF_CNT_REG 0x01
2680#define HV_PERF_DRAM_PERF_CTRL_REG_0 0x02
2681#define HV_PERF_DRAM_PERF_CNT_REG_0 0x03
2682#define HV_PERF_DRAM_PERF_CTRL_REG_1 0x04
2683#define HV_PERF_DRAM_PERF_CNT_REG_1 0x05
2684#define HV_PERF_DRAM_PERF_CTRL_REG_2 0x06
2685#define HV_PERF_DRAM_PERF_CNT_REG_2 0x07
2686#define HV_PERF_DRAM_PERF_CTRL_REG_3 0x08
2687#define HV_PERF_DRAM_PERF_CNT_REG_3 0x09
2688
2689/* get_perfreg()
2690 * TRAP: HV_FAST_TRAP
2691 * FUNCTION: HV_FAST_GET_PERFREG
2692 * ARG0: performance reg number
2693 * RET0: status
2694 * RET1: performance reg value
2695 * ERRORS: EINVAL Invalid performance register number
2696 * ENOACCESS No access allowed to performance counters
2697 *
2698 * Read the value of the given DRAM/JBUS performance counter/control register.
2699 */
2700#define HV_FAST_GET_PERFREG 0x100
2701
2702/* set_perfreg()
2703 * TRAP: HV_FAST_TRAP
2704 * FUNCTION: HV_FAST_SET_PERFREG
2705 * ARG0: performance reg number
2706 * ARG1: performance reg value
2707 * RET0: status
2708 * ERRORS: EINVAL Invalid performance register number
2709 * ENOACCESS No access allowed to performance counters
2710 *
2711 * Write the given performance reg value to the given DRAM/JBUS
2712 * performance counter/control register.
2713 */
2714#define HV_FAST_SET_PERFREG 0x101
2715
2716/* MMU statistics services.
2717 *
2718 * The hypervisor maintains MMU statistics and privileged code provides
2719 * a buffer where these statistics can be collected. It is continually
2720 * updated once configured. The layout is as follows:
2721 */
2722#ifndef __ASSEMBLY__
2723struct hv_mmu_statistics {
2724 unsigned long immu_tsb_hits_ctx0_8k_tte;
2725 unsigned long immu_tsb_ticks_ctx0_8k_tte;
2726 unsigned long immu_tsb_hits_ctx0_64k_tte;
2727 unsigned long immu_tsb_ticks_ctx0_64k_tte;
2728 unsigned long __reserved1[2];
2729 unsigned long immu_tsb_hits_ctx0_4mb_tte;
2730 unsigned long immu_tsb_ticks_ctx0_4mb_tte;
2731 unsigned long __reserved2[2];
2732 unsigned long immu_tsb_hits_ctx0_256mb_tte;
2733 unsigned long immu_tsb_ticks_ctx0_256mb_tte;
2734 unsigned long __reserved3[4];
2735 unsigned long immu_tsb_hits_ctxnon0_8k_tte;
2736 unsigned long immu_tsb_ticks_ctxnon0_8k_tte;
2737 unsigned long immu_tsb_hits_ctxnon0_64k_tte;
2738 unsigned long immu_tsb_ticks_ctxnon0_64k_tte;
2739 unsigned long __reserved4[2];
2740 unsigned long immu_tsb_hits_ctxnon0_4mb_tte;
2741 unsigned long immu_tsb_ticks_ctxnon0_4mb_tte;
2742 unsigned long __reserved5[2];
2743 unsigned long immu_tsb_hits_ctxnon0_256mb_tte;
2744 unsigned long immu_tsb_ticks_ctxnon0_256mb_tte;
2745 unsigned long __reserved6[4];
2746 unsigned long dmmu_tsb_hits_ctx0_8k_tte;
2747 unsigned long dmmu_tsb_ticks_ctx0_8k_tte;
2748 unsigned long dmmu_tsb_hits_ctx0_64k_tte;
2749 unsigned long dmmu_tsb_ticks_ctx0_64k_tte;
2750 unsigned long __reserved7[2];
2751 unsigned long dmmu_tsb_hits_ctx0_4mb_tte;
2752 unsigned long dmmu_tsb_ticks_ctx0_4mb_tte;
2753 unsigned long __reserved8[2];
2754 unsigned long dmmu_tsb_hits_ctx0_256mb_tte;
2755 unsigned long dmmu_tsb_ticks_ctx0_256mb_tte;
2756 unsigned long __reserved9[4];
2757 unsigned long dmmu_tsb_hits_ctxnon0_8k_tte;
2758 unsigned long dmmu_tsb_ticks_ctxnon0_8k_tte;
2759 unsigned long dmmu_tsb_hits_ctxnon0_64k_tte;
2760 unsigned long dmmu_tsb_ticks_ctxnon0_64k_tte;
2761 unsigned long __reserved10[2];
2762 unsigned long dmmu_tsb_hits_ctxnon0_4mb_tte;
2763 unsigned long dmmu_tsb_ticks_ctxnon0_4mb_tte;
2764 unsigned long __reserved11[2];
2765 unsigned long dmmu_tsb_hits_ctxnon0_256mb_tte;
2766 unsigned long dmmu_tsb_ticks_ctxnon0_256mb_tte;
2767 unsigned long __reserved12[4];
2768};
2769#endif
2770
2771/* mmustat_conf()
2772 * TRAP: HV_FAST_TRAP
2773 * FUNCTION: HV_FAST_MMUSTAT_CONF
2774 * ARG0: real address
2775 * RET0: status
2776 * RET1: real address
2777 * ERRORS: ENORADDR Invalid real address
2778 * EBADALIGN Real address not aligned on 64-byte boundary
2779 * EBADTRAP API not supported on this processor
2780 *
2781 * Enable MMU statistic gathering using the buffer at the given real
2782 * address on the current virtual CPU. The new buffer real address
2783 * is given in ARG1, and the previously specified buffer real address
2784 * is returned in RET1, or is returned as zero for the first invocation.
2785 *
2786 * If the passed in real address argument is zero, this will disable
2787 * MMU statistic collection on the current virtual CPU. If an error is
2788 * returned then no statistics are collected.
2789 *
2790 * The buffer contents should be initialized to all zeros before being
2791 * given to the hypervisor or else the statistics will be meaningless.
2792 */
2793#define HV_FAST_MMUSTAT_CONF 0x102
2794
2795/* mmustat_info()
2796 * TRAP: HV_FAST_TRAP
2797 * FUNCTION: HV_FAST_MMUSTAT_INFO
2798 * RET0: status
2799 * RET1: real address
2800 * ERRORS: EBADTRAP API not supported on this processor
2801 *
2802 * Return the current state and real address of the currently configured
2803 * MMU statistics buffer on the current virtual CPU.
2804 */
2805#define HV_FAST_MMUSTAT_INFO 0x103
2806
2807#ifndef __ASSEMBLY__
2808extern unsigned long sun4v_mmustat_conf(unsigned long ra, unsigned long *orig_ra);
2809extern unsigned long sun4v_mmustat_info(unsigned long *ra);
2810#endif
2811
2812/* NCS crypto services */
2813
2814/* ncs_request() sub-function numbers */
2815#define HV_NCS_QCONF 0x01
2816#define HV_NCS_QTAIL_UPDATE 0x02
2817
2818#ifndef __ASSEMBLY__
2819struct hv_ncs_queue_entry {
2820 /* MAU Control Register */
2821 unsigned long mau_control;
2822#define MAU_CONTROL_INV_PARITY 0x0000000000002000
2823#define MAU_CONTROL_STRAND 0x0000000000001800
2824#define MAU_CONTROL_BUSY 0x0000000000000400
2825#define MAU_CONTROL_INT 0x0000000000000200
2826#define MAU_CONTROL_OP 0x00000000000001c0
2827#define MAU_CONTROL_OP_SHIFT 6
2828#define MAU_OP_LOAD_MA_MEMORY 0x0
2829#define MAU_OP_STORE_MA_MEMORY 0x1
2830#define MAU_OP_MODULAR_MULT 0x2
2831#define MAU_OP_MODULAR_REDUCE 0x3
2832#define MAU_OP_MODULAR_EXP_LOOP 0x4
2833#define MAU_CONTROL_LEN 0x000000000000003f
2834#define MAU_CONTROL_LEN_SHIFT 0
2835
2836 /* Real address of bytes to load or store bytes
2837 * into/out-of the MAU.
2838 */
2839 unsigned long mau_mpa;
2840
2841 /* Modular Arithmetic MA Offset Register. */
2842 unsigned long mau_ma;
2843
2844 /* Modular Arithmetic N Prime Register. */
2845 unsigned long mau_np;
2846};
2847
2848struct hv_ncs_qconf_arg {
2849 unsigned long mid; /* MAU ID, 1 per core on Niagara */
2850 unsigned long base; /* Real address base of queue */
2851 unsigned long end; /* Real address end of queue */
2852 unsigned long num_ents; /* Number of entries in queue */
2853};
2854
2855struct hv_ncs_qtail_update_arg {
2856 unsigned long mid; /* MAU ID, 1 per core on Niagara */
2857 unsigned long tail; /* New tail index to use */
2858 unsigned long syncflag; /* only SYNCFLAG_SYNC is implemented */
2859#define HV_NCS_SYNCFLAG_SYNC 0x00
2860#define HV_NCS_SYNCFLAG_ASYNC 0x01
2861};
2862#endif
2863
2864/* ncs_request()
2865 * TRAP: HV_FAST_TRAP
2866 * FUNCTION: HV_FAST_NCS_REQUEST
2867 * ARG0: NCS sub-function
2868 * ARG1: sub-function argument real address
2869 * ARG2: size in bytes of sub-function argument
2870 * RET0: status
2871 *
2872 * The MAU chip of the Niagara processor is not directly accessible
2873 * to privileged code, instead it is programmed indirectly via this
2874 * hypervisor API.
2875 *
2876 * The interfaces defines a queue of MAU operations to perform.
2877 * Privileged code registers a queue with the hypervisor by invoking
2878 * this HVAPI with the HV_NCS_QCONF sub-function, which defines the
2879 * base, end, and number of entries of the queue. Each queue entry
2880 * contains a MAU register struct block.
2881 *
2882 * The privileged code then proceeds to add entries to the queue and
2883 * then invoke the HV_NCS_QTAIL_UPDATE sub-function. Since only
2884 * synchronous operations are supported by the current hypervisor,
2885 * HV_NCS_QTAIL_UPDATE will run all the pending queue entries to
2886 * completion and return HV_EOK, or return an error code.
2887 *
2888 * The real address of the sub-function argument must be aligned on at
2889 * least an 8-byte boundary.
2890 *
2891 * The tail argument of HV_NCS_QTAIL_UPDATE is an index, not a byte
2892 * offset, into the queue and must be less than or equal the 'num_ents'
2893 * argument given in the HV_NCS_QCONF call.
2894 */
2895#define HV_FAST_NCS_REQUEST 0x110
2896
2897#ifndef __ASSEMBLY__
2898extern unsigned long sun4v_ncs_request(unsigned long request,
2899 unsigned long arg_ra,
2900 unsigned long arg_size);
2901#endif
2902
2903#define HV_FAST_FIRE_GET_PERFREG 0x120
2904#define HV_FAST_FIRE_SET_PERFREG 0x121
2905
2906/* Function numbers for HV_CORE_TRAP. */
2907#define HV_CORE_SET_VER 0x00
2908#define HV_CORE_PUTCHAR 0x01
2909#define HV_CORE_EXIT 0x02
2910#define HV_CORE_GET_VER 0x03
2911
2912/* Hypervisor API groups for use with HV_CORE_SET_VER and
2913 * HV_CORE_GET_VER.
2914 */
2915#define HV_GRP_SUN4V 0x0000
2916#define HV_GRP_CORE 0x0001
2917#define HV_GRP_INTR 0x0002
2918#define HV_GRP_SOFT_STATE 0x0003
2919#define HV_GRP_PCI 0x0100
2920#define HV_GRP_LDOM 0x0101
2921#define HV_GRP_SVC_CHAN 0x0102
2922#define HV_GRP_NCS 0x0103
2923#define HV_GRP_RNG 0x0104
2924#define HV_GRP_NIAG_PERF 0x0200
2925#define HV_GRP_FIRE_PERF 0x0201
2926#define HV_GRP_N2_CPU 0x0202
2927#define HV_GRP_NIU 0x0204
2928#define HV_GRP_VF_CPU 0x0205
2929#define HV_GRP_DIAG 0x0300
2930
2931#ifndef __ASSEMBLY__
2932extern unsigned long sun4v_get_version(unsigned long group,
2933 unsigned long *major,
2934 unsigned long *minor);
2935extern unsigned long sun4v_set_version(unsigned long group,
2936 unsigned long major,
2937 unsigned long minor,
2938 unsigned long *actual_minor);
2939
2940extern int sun4v_hvapi_register(unsigned long group, unsigned long major,
2941 unsigned long *minor);
2942extern void sun4v_hvapi_unregister(unsigned long group);
2943extern int sun4v_hvapi_get(unsigned long group,
2944 unsigned long *major,
2945 unsigned long *minor);
2946extern void sun4v_hvapi_init(void);
2947#endif
2948
2949#endif /* !(_SPARC64_HYPERVISOR_H) */
diff --git a/include/asm-sparc/ide.h b/include/asm-sparc/ide.h
index afd1736ed480..a3c7f5ff270a 100644
--- a/include/asm-sparc/ide.h
+++ b/include/asm-sparc/ide.h
@@ -1,95 +1,8 @@
1/* ide.h: SPARC PCI specific IDE glue. 1#ifndef ___ASM_SPARC_IDE_H
2 * 2#define ___ASM_SPARC_IDE_H
3 * Copyright (C) 1997 David S. Miller (davem@davemloft.net) 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) 4#include <asm-sparc/ide_64.h>
5 * Adaptation from sparc64 version to sparc by Pete Zaitcev. 5#else
6 */ 6#include <asm-sparc/ide_32.h>
7 7#endif
8#ifndef _SPARC_IDE_H 8#endif
9#define _SPARC_IDE_H
10
11#ifdef __KERNEL__
12
13#include <asm/pgtable.h>
14#include <asm/io.h>
15#include <asm/psr.h>
16
17#undef MAX_HWIFS
18#define MAX_HWIFS 2
19
20#define __ide_insl(data_reg, buffer, wcount) \
21 __ide_insw(data_reg, buffer, (wcount)<<1)
22#define __ide_outsl(data_reg, buffer, wcount) \
23 __ide_outsw(data_reg, buffer, (wcount)<<1)
24
25/* On sparc, I/O ports and MMIO registers are accessed identically. */
26#define __ide_mm_insw __ide_insw
27#define __ide_mm_insl __ide_insl
28#define __ide_mm_outsw __ide_outsw
29#define __ide_mm_outsl __ide_outsl
30
31static inline void __ide_insw(unsigned long port,
32 void *dst,
33 unsigned long count)
34{
35 volatile unsigned short *data_port;
36 /* unsigned long end = (unsigned long)dst + (count << 1); */ /* P3 */
37 u16 *ps = dst;
38 u32 *pi;
39
40 data_port = (volatile unsigned short *)port;
41
42 if(((unsigned long)ps) & 0x2) {
43 *ps++ = *data_port;
44 count--;
45 }
46 pi = (u32 *)ps;
47 while(count >= 2) {
48 u32 w;
49
50 w = (*data_port) << 16;
51 w |= (*data_port);
52 *pi++ = w;
53 count -= 2;
54 }
55 ps = (u16 *)pi;
56 if(count)
57 *ps++ = *data_port;
58
59 /* __flush_dcache_range((unsigned long)dst, end); */ /* P3 see hme */
60}
61
62static inline void __ide_outsw(unsigned long port,
63 const void *src,
64 unsigned long count)
65{
66 volatile unsigned short *data_port;
67 /* unsigned long end = (unsigned long)src + (count << 1); */
68 const u16 *ps = src;
69 const u32 *pi;
70
71 data_port = (volatile unsigned short *)port;
72
73 if(((unsigned long)src) & 0x2) {
74 *data_port = *ps++;
75 count--;
76 }
77 pi = (const u32 *)ps;
78 while(count >= 2) {
79 u32 w;
80
81 w = *pi++;
82 *data_port = (w >> 16);
83 *data_port = w;
84 count -= 2;
85 }
86 ps = (const u16 *)pi;
87 if(count)
88 *data_port = *ps;
89
90 /* __flush_dcache_range((unsigned long)src, end); */ /* P3 see hme */
91}
92
93#endif /* __KERNEL__ */
94
95#endif /* _SPARC_IDE_H */
diff --git a/include/asm-sparc/ide_32.h b/include/asm-sparc/ide_32.h
new file mode 100644
index 000000000000..afd1736ed480
--- /dev/null
+++ b/include/asm-sparc/ide_32.h
@@ -0,0 +1,95 @@
1/* ide.h: SPARC PCI specific IDE glue.
2 *
3 * Copyright (C) 1997 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
5 * Adaptation from sparc64 version to sparc by Pete Zaitcev.
6 */
7
8#ifndef _SPARC_IDE_H
9#define _SPARC_IDE_H
10
11#ifdef __KERNEL__
12
13#include <asm/pgtable.h>
14#include <asm/io.h>
15#include <asm/psr.h>
16
17#undef MAX_HWIFS
18#define MAX_HWIFS 2
19
20#define __ide_insl(data_reg, buffer, wcount) \
21 __ide_insw(data_reg, buffer, (wcount)<<1)
22#define __ide_outsl(data_reg, buffer, wcount) \
23 __ide_outsw(data_reg, buffer, (wcount)<<1)
24
25/* On sparc, I/O ports and MMIO registers are accessed identically. */
26#define __ide_mm_insw __ide_insw
27#define __ide_mm_insl __ide_insl
28#define __ide_mm_outsw __ide_outsw
29#define __ide_mm_outsl __ide_outsl
30
31static inline void __ide_insw(unsigned long port,
32 void *dst,
33 unsigned long count)
34{
35 volatile unsigned short *data_port;
36 /* unsigned long end = (unsigned long)dst + (count << 1); */ /* P3 */
37 u16 *ps = dst;
38 u32 *pi;
39
40 data_port = (volatile unsigned short *)port;
41
42 if(((unsigned long)ps) & 0x2) {
43 *ps++ = *data_port;
44 count--;
45 }
46 pi = (u32 *)ps;
47 while(count >= 2) {
48 u32 w;
49
50 w = (*data_port) << 16;
51 w |= (*data_port);
52 *pi++ = w;
53 count -= 2;
54 }
55 ps = (u16 *)pi;
56 if(count)
57 *ps++ = *data_port;
58
59 /* __flush_dcache_range((unsigned long)dst, end); */ /* P3 see hme */
60}
61
62static inline void __ide_outsw(unsigned long port,
63 const void *src,
64 unsigned long count)
65{
66 volatile unsigned short *data_port;
67 /* unsigned long end = (unsigned long)src + (count << 1); */
68 const u16 *ps = src;
69 const u32 *pi;
70
71 data_port = (volatile unsigned short *)port;
72
73 if(((unsigned long)src) & 0x2) {
74 *data_port = *ps++;
75 count--;
76 }
77 pi = (const u32 *)ps;
78 while(count >= 2) {
79 u32 w;
80
81 w = *pi++;
82 *data_port = (w >> 16);
83 *data_port = w;
84 count -= 2;
85 }
86 ps = (const u16 *)pi;
87 if(count)
88 *data_port = *ps;
89
90 /* __flush_dcache_range((unsigned long)src, end); */ /* P3 see hme */
91}
92
93#endif /* __KERNEL__ */
94
95#endif /* _SPARC_IDE_H */
diff --git a/include/asm-sparc/ide_64.h b/include/asm-sparc/ide_64.h
new file mode 100644
index 000000000000..1282676da1cd
--- /dev/null
+++ b/include/asm-sparc/ide_64.h
@@ -0,0 +1,118 @@
1/*
2 * ide.h: Ultra/PCI specific IDE glue.
3 *
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
6 */
7
8#ifndef _SPARC64_IDE_H
9#define _SPARC64_IDE_H
10
11#ifdef __KERNEL__
12
13#include <asm/pgalloc.h>
14#include <asm/io.h>
15#include <asm/spitfire.h>
16#include <asm/cacheflush.h>
17#include <asm/page.h>
18
19#ifndef MAX_HWIFS
20# ifdef CONFIG_BLK_DEV_IDEPCI
21#define MAX_HWIFS 10
22# else
23#define MAX_HWIFS 2
24# endif
25#endif
26
27#define __ide_insl(data_reg, buffer, wcount) \
28 __ide_insw(data_reg, buffer, (wcount)<<1)
29#define __ide_outsl(data_reg, buffer, wcount) \
30 __ide_outsw(data_reg, buffer, (wcount)<<1)
31
32/* On sparc64, I/O ports and MMIO registers are accessed identically. */
33#define __ide_mm_insw __ide_insw
34#define __ide_mm_insl __ide_insl
35#define __ide_mm_outsw __ide_outsw
36#define __ide_mm_outsl __ide_outsl
37
38static inline unsigned int inw_be(void __iomem *addr)
39{
40 unsigned int ret;
41
42 __asm__ __volatile__("lduha [%1] %2, %0"
43 : "=r" (ret)
44 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
45
46 return ret;
47}
48
49static inline void __ide_insw(void __iomem *port, void *dst, u32 count)
50{
51#ifdef DCACHE_ALIASING_POSSIBLE
52 unsigned long end = (unsigned long)dst + (count << 1);
53#endif
54 u16 *ps = dst;
55 u32 *pi;
56
57 if(((u64)ps) & 0x2) {
58 *ps++ = inw_be(port);
59 count--;
60 }
61 pi = (u32 *)ps;
62 while(count >= 2) {
63 u32 w;
64
65 w = inw_be(port) << 16;
66 w |= inw_be(port);
67 *pi++ = w;
68 count -= 2;
69 }
70 ps = (u16 *)pi;
71 if(count)
72 *ps++ = inw_be(port);
73
74#ifdef DCACHE_ALIASING_POSSIBLE
75 __flush_dcache_range((unsigned long)dst, end);
76#endif
77}
78
79static inline void outw_be(unsigned short w, void __iomem *addr)
80{
81 __asm__ __volatile__("stha %0, [%1] %2"
82 : /* no outputs */
83 : "r" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
84}
85
86static inline void __ide_outsw(void __iomem *port, void *src, u32 count)
87{
88#ifdef DCACHE_ALIASING_POSSIBLE
89 unsigned long end = (unsigned long)src + (count << 1);
90#endif
91 const u16 *ps = src;
92 const u32 *pi;
93
94 if(((u64)src) & 0x2) {
95 outw_be(*ps++, port);
96 count--;
97 }
98 pi = (const u32 *)ps;
99 while(count >= 2) {
100 u32 w;
101
102 w = *pi++;
103 outw_be((w >> 16), port);
104 outw_be(w, port);
105 count -= 2;
106 }
107 ps = (const u16 *)pi;
108 if(count)
109 outw_be(*ps, port);
110
111#ifdef DCACHE_ALIASING_POSSIBLE
112 __flush_dcache_range((unsigned long)src, end);
113#endif
114}
115
116#endif /* __KERNEL__ */
117
118#endif /* _SPARC64_IDE_H */
diff --git a/include/asm-sparc/idprom.h b/include/asm-sparc/idprom.h
index 41adb417a4e5..6976aa2439c6 100644
--- a/include/asm-sparc/idprom.h
+++ b/include/asm-sparc/idprom.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * idprom.h: Macros and defines for idprom routines 2 * idprom.h: Macros and defines for idprom routines
3 * 3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 4 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
5 */ 5 */
6 6
7#ifndef _SPARC_IDPROM_H 7#ifndef _SPARC_IDPROM_H
diff --git a/include/asm-sparc/intr_queue.h b/include/asm-sparc/intr_queue.h
new file mode 100644
index 000000000000..206077dedc2a
--- /dev/null
+++ b/include/asm-sparc/intr_queue.h
@@ -0,0 +1,15 @@
1#ifndef _SPARC64_INTR_QUEUE_H
2#define _SPARC64_INTR_QUEUE_H
3
4/* Sun4v interrupt queue registers, accessed via ASI_QUEUE. */
5
6#define INTRQ_CPU_MONDO_HEAD 0x3c0 /* CPU mondo head */
7#define INTRQ_CPU_MONDO_TAIL 0x3c8 /* CPU mondo tail */
8#define INTRQ_DEVICE_MONDO_HEAD 0x3d0 /* Device mondo head */
9#define INTRQ_DEVICE_MONDO_TAIL 0x3d8 /* Device mondo tail */
10#define INTRQ_RESUM_MONDO_HEAD 0x3e0 /* Resumable error mondo head */
11#define INTRQ_RESUM_MONDO_TAIL 0x3e8 /* Resumable error mondo tail */
12#define INTRQ_NONRESUM_MONDO_HEAD 0x3f0 /* Non-resumable error mondo head */
13#define INTRQ_NONRESUM_MONDO_TAIL 0x3f8 /* Non-resumable error mondo head */
14
15#endif /* !(_SPARC64_INTR_QUEUE_H) */
diff --git a/include/asm-sparc/io.h b/include/asm-sparc/io.h
index 3a3e7bdb06b3..fc9024d3dfc3 100644
--- a/include/asm-sparc/io.h
+++ b/include/asm-sparc/io.h
@@ -1,325 +1,8 @@
1#ifndef __SPARC_IO_H 1#ifndef ___ASM_SPARC_IO_H
2#define __SPARC_IO_H 2#define ___ASM_SPARC_IO_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <linux/kernel.h> 4#include <asm-sparc/io_64.h>
5#include <linux/types.h> 5#else
6#include <linux/ioport.h> /* struct resource */ 6#include <asm-sparc/io_32.h>
7 7#endif
8#include <asm/page.h> /* IO address mapping routines need this */
9#include <asm/system.h>
10
11#define page_to_phys(page) (((page) - mem_map) << PAGE_SHIFT)
12
13static inline u32 flip_dword (u32 l)
14{
15 return ((l&0xff)<<24) | (((l>>8)&0xff)<<16) | (((l>>16)&0xff)<<8)| ((l>>24)&0xff);
16}
17
18static inline u16 flip_word (u16 w)
19{
20 return ((w&0xff) << 8) | ((w>>8)&0xff);
21}
22
23#define mmiowb()
24
25/*
26 * Memory mapped I/O to PCI
27 */
28
29static inline u8 __raw_readb(const volatile void __iomem *addr)
30{
31 return *(__force volatile u8 *)addr;
32}
33
34static inline u16 __raw_readw(const volatile void __iomem *addr)
35{
36 return *(__force volatile u16 *)addr;
37}
38
39static inline u32 __raw_readl(const volatile void __iomem *addr)
40{
41 return *(__force volatile u32 *)addr;
42}
43
44static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
45{
46 *(__force volatile u8 *)addr = b;
47}
48
49static inline void __raw_writew(u16 w, volatile void __iomem *addr)
50{
51 *(__force volatile u16 *)addr = w;
52}
53
54static inline void __raw_writel(u32 l, volatile void __iomem *addr)
55{
56 *(__force volatile u32 *)addr = l;
57}
58
59static inline u8 __readb(const volatile void __iomem *addr)
60{
61 return *(__force volatile u8 *)addr;
62}
63
64static inline u16 __readw(const volatile void __iomem *addr)
65{
66 return flip_word(*(__force volatile u16 *)addr);
67}
68
69static inline u32 __readl(const volatile void __iomem *addr)
70{
71 return flip_dword(*(__force volatile u32 *)addr);
72}
73
74static inline void __writeb(u8 b, volatile void __iomem *addr)
75{
76 *(__force volatile u8 *)addr = b;
77}
78
79static inline void __writew(u16 w, volatile void __iomem *addr)
80{
81 *(__force volatile u16 *)addr = flip_word(w);
82}
83
84static inline void __writel(u32 l, volatile void __iomem *addr)
85{
86 *(__force volatile u32 *)addr = flip_dword(l);
87}
88
89#define readb(__addr) __readb(__addr)
90#define readw(__addr) __readw(__addr)
91#define readl(__addr) __readl(__addr)
92#define readb_relaxed(__addr) readb(__addr)
93#define readw_relaxed(__addr) readw(__addr)
94#define readl_relaxed(__addr) readl(__addr)
95
96#define writeb(__b, __addr) __writeb((__b),(__addr))
97#define writew(__w, __addr) __writew((__w),(__addr))
98#define writel(__l, __addr) __writel((__l),(__addr))
99
100/*
101 * I/O space operations
102 *
103 * Arrangement on a Sun is somewhat complicated.
104 *
105 * First of all, we want to use standard Linux drivers
106 * for keyboard, PC serial, etc. These drivers think
107 * they access I/O space and use inb/outb.
108 * On the other hand, EBus bridge accepts PCI *memory*
109 * cycles and converts them into ISA *I/O* cycles.
110 * Ergo, we want inb & outb to generate PCI memory cycles.
111 *
112 * If we want to issue PCI *I/O* cycles, we do this
113 * with a low 64K fixed window in PCIC. This window gets
114 * mapped somewhere into virtual kernel space and we
115 * can use inb/outb again.
116 */
117#define inb_local(__addr) __readb((void __iomem *)(unsigned long)(__addr))
118#define inb(__addr) __readb((void __iomem *)(unsigned long)(__addr))
119#define inw(__addr) __readw((void __iomem *)(unsigned long)(__addr))
120#define inl(__addr) __readl((void __iomem *)(unsigned long)(__addr))
121
122#define outb_local(__b, __addr) __writeb(__b, (void __iomem *)(unsigned long)(__addr))
123#define outb(__b, __addr) __writeb(__b, (void __iomem *)(unsigned long)(__addr))
124#define outw(__w, __addr) __writew(__w, (void __iomem *)(unsigned long)(__addr))
125#define outl(__l, __addr) __writel(__l, (void __iomem *)(unsigned long)(__addr))
126
127#define inb_p(__addr) inb(__addr)
128#define outb_p(__b, __addr) outb(__b, __addr)
129#define inw_p(__addr) inw(__addr)
130#define outw_p(__w, __addr) outw(__w, __addr)
131#define inl_p(__addr) inl(__addr)
132#define outl_p(__l, __addr) outl(__l, __addr)
133
134void outsb(unsigned long addr, const void *src, unsigned long cnt);
135void outsw(unsigned long addr, const void *src, unsigned long cnt);
136void outsl(unsigned long addr, const void *src, unsigned long cnt);
137void insb(unsigned long addr, void *dst, unsigned long count);
138void insw(unsigned long addr, void *dst, unsigned long count);
139void insl(unsigned long addr, void *dst, unsigned long count);
140
141#define IO_SPACE_LIMIT 0xffffffff
142
143/*
144 * SBus accessors.
145 *
146 * SBus has only one, memory mapped, I/O space.
147 * We do not need to flip bytes for SBus of course.
148 */
149static inline u8 _sbus_readb(const volatile void __iomem *addr)
150{
151 return *(__force volatile u8 *)addr;
152}
153
154static inline u16 _sbus_readw(const volatile void __iomem *addr)
155{
156 return *(__force volatile u16 *)addr;
157}
158
159static inline u32 _sbus_readl(const volatile void __iomem *addr)
160{
161 return *(__force volatile u32 *)addr;
162}
163
164static inline void _sbus_writeb(u8 b, volatile void __iomem *addr)
165{
166 *(__force volatile u8 *)addr = b;
167}
168
169static inline void _sbus_writew(u16 w, volatile void __iomem *addr)
170{
171 *(__force volatile u16 *)addr = w;
172}
173
174static inline void _sbus_writel(u32 l, volatile void __iomem *addr)
175{
176 *(__force volatile u32 *)addr = l;
177}
178
179/*
180 * The only reason for #define's is to hide casts to unsigned long.
181 */
182#define sbus_readb(__addr) _sbus_readb(__addr)
183#define sbus_readw(__addr) _sbus_readw(__addr)
184#define sbus_readl(__addr) _sbus_readl(__addr)
185#define sbus_writeb(__b, __addr) _sbus_writeb(__b, __addr)
186#define sbus_writew(__w, __addr) _sbus_writew(__w, __addr)
187#define sbus_writel(__l, __addr) _sbus_writel(__l, __addr)
188
189static inline void sbus_memset_io(volatile void __iomem *__dst, int c, __kernel_size_t n)
190{
191 while(n--) {
192 sbus_writeb(c, __dst);
193 __dst++;
194 }
195}
196
197static inline void
198_memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
199{
200 volatile void __iomem *d = dst;
201
202 while (n--) {
203 writeb(c, d);
204 d++;
205 }
206}
207
208#define memset_io(d,c,sz) _memset_io(d,c,sz)
209
210static inline void
211_memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
212{
213 char *d = dst;
214
215 while (n--) {
216 char tmp = readb(src);
217 *d++ = tmp;
218 src++;
219 }
220}
221
222#define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
223
224static inline void
225_memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n)
226{
227 const char *s = src;
228 volatile void __iomem *d = dst;
229
230 while (n--) {
231 char tmp = *s++;
232 writeb(tmp, d);
233 d++;
234 }
235}
236
237#define memcpy_toio(d,s,sz) _memcpy_toio(d,s,sz)
238
239#ifdef __KERNEL__
240
241/*
242 * Bus number may be embedded in the higher bits of the physical address.
243 * This is why we have no bus number argument to ioremap().
244 */
245extern void __iomem *ioremap(unsigned long offset, unsigned long size);
246#define ioremap_nocache(X,Y) ioremap((X),(Y))
247extern void iounmap(volatile void __iomem *addr);
248
249#define ioread8(X) readb(X)
250#define ioread16(X) readw(X)
251#define ioread32(X) readl(X)
252#define iowrite8(val,X) writeb(val,X)
253#define iowrite16(val,X) writew(val,X)
254#define iowrite32(val,X) writel(val,X)
255
256static inline void ioread8_rep(void __iomem *port, void *buf, unsigned long count)
257{
258 insb((unsigned long __force)port, buf, count);
259}
260static inline void ioread16_rep(void __iomem *port, void *buf, unsigned long count)
261{
262 insw((unsigned long __force)port, buf, count);
263}
264
265static inline void ioread32_rep(void __iomem *port, void *buf, unsigned long count)
266{
267 insl((unsigned long __force)port, buf, count);
268}
269
270static inline void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count)
271{
272 outsb((unsigned long __force)port, buf, count);
273}
274
275static inline void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count)
276{
277 outsw((unsigned long __force)port, buf, count);
278}
279
280static inline void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count)
281{
282 outsl((unsigned long __force)port, buf, count);
283}
284
285/* Create a virtual mapping cookie for an IO port range */
286extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
287extern void ioport_unmap(void __iomem *);
288
289/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
290struct pci_dev;
291extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
292extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
293
294/*
295 * Bus number may be in res->flags... somewhere.
296 */
297extern void __iomem *sbus_ioremap(struct resource *res, unsigned long offset,
298 unsigned long size, char *name);
299extern void sbus_iounmap(volatile void __iomem *vaddr, unsigned long size);
300
301
302/*
303 * At the moment, we do not use CMOS_READ anywhere outside of rtc.c,
304 * so rtc_port is static in it. This should not change unless a new
305 * hardware pops up.
306 */
307#define RTC_PORT(x) (rtc_port + (x))
308#define RTC_ALWAYS_BCD 0
309
310#endif 8#endif
311
312#define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
313
314/*
315 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
316 * access
317 */
318#define xlate_dev_mem_ptr(p) __va(p)
319
320/*
321 * Convert a virtual cached pointer to an uncached pointer
322 */
323#define xlate_dev_kmem_ptr(p) p
324
325#endif /* !(__SPARC_IO_H) */
diff --git a/include/asm-sparc/io_32.h b/include/asm-sparc/io_32.h
new file mode 100644
index 000000000000..c43af722ae8c
--- /dev/null
+++ b/include/asm-sparc/io_32.h
@@ -0,0 +1,325 @@
1#ifndef __SPARC_IO_H
2#define __SPARC_IO_H
3
4#include <linux/kernel.h>
5#include <linux/types.h>
6#include <linux/ioport.h> /* struct resource */
7
8#include <asm/page.h> /* IO address mapping routines need this */
9#include <asm/system.h>
10
11#define page_to_phys(page) (((page) - mem_map) << PAGE_SHIFT)
12
13static inline u32 flip_dword (u32 l)
14{
15 return ((l&0xff)<<24) | (((l>>8)&0xff)<<16) | (((l>>16)&0xff)<<8)| ((l>>24)&0xff);
16}
17
18static inline u16 flip_word (u16 w)
19{
20 return ((w&0xff) << 8) | ((w>>8)&0xff);
21}
22
23#define mmiowb()
24
25/*
26 * Memory mapped I/O to PCI
27 */
28
29static inline u8 __raw_readb(const volatile void __iomem *addr)
30{
31 return *(__force volatile u8 *)addr;
32}
33
34static inline u16 __raw_readw(const volatile void __iomem *addr)
35{
36 return *(__force volatile u16 *)addr;
37}
38
39static inline u32 __raw_readl(const volatile void __iomem *addr)
40{
41 return *(__force volatile u32 *)addr;
42}
43
44static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
45{
46 *(__force volatile u8 *)addr = b;
47}
48
49static inline void __raw_writew(u16 w, volatile void __iomem *addr)
50{
51 *(__force volatile u16 *)addr = w;
52}
53
54static inline void __raw_writel(u32 l, volatile void __iomem *addr)
55{
56 *(__force volatile u32 *)addr = l;
57}
58
59static inline u8 __readb(const volatile void __iomem *addr)
60{
61 return *(__force volatile u8 *)addr;
62}
63
64static inline u16 __readw(const volatile void __iomem *addr)
65{
66 return flip_word(*(__force volatile u16 *)addr);
67}
68
69static inline u32 __readl(const volatile void __iomem *addr)
70{
71 return flip_dword(*(__force volatile u32 *)addr);
72}
73
74static inline void __writeb(u8 b, volatile void __iomem *addr)
75{
76 *(__force volatile u8 *)addr = b;
77}
78
79static inline void __writew(u16 w, volatile void __iomem *addr)
80{
81 *(__force volatile u16 *)addr = flip_word(w);
82}
83
84static inline void __writel(u32 l, volatile void __iomem *addr)
85{
86 *(__force volatile u32 *)addr = flip_dword(l);
87}
88
89#define readb(__addr) __readb(__addr)
90#define readw(__addr) __readw(__addr)
91#define readl(__addr) __readl(__addr)
92#define readb_relaxed(__addr) readb(__addr)
93#define readw_relaxed(__addr) readw(__addr)
94#define readl_relaxed(__addr) readl(__addr)
95
96#define writeb(__b, __addr) __writeb((__b),(__addr))
97#define writew(__w, __addr) __writew((__w),(__addr))
98#define writel(__l, __addr) __writel((__l),(__addr))
99
100/*
101 * I/O space operations
102 *
103 * Arrangement on a Sun is somewhat complicated.
104 *
105 * First of all, we want to use standard Linux drivers
106 * for keyboard, PC serial, etc. These drivers think
107 * they access I/O space and use inb/outb.
108 * On the other hand, EBus bridge accepts PCI *memory*
109 * cycles and converts them into ISA *I/O* cycles.
110 * Ergo, we want inb & outb to generate PCI memory cycles.
111 *
112 * If we want to issue PCI *I/O* cycles, we do this
113 * with a low 64K fixed window in PCIC. This window gets
114 * mapped somewhere into virtual kernel space and we
115 * can use inb/outb again.
116 */
117#define inb_local(__addr) __readb((void __iomem *)(unsigned long)(__addr))
118#define inb(__addr) __readb((void __iomem *)(unsigned long)(__addr))
119#define inw(__addr) __readw((void __iomem *)(unsigned long)(__addr))
120#define inl(__addr) __readl((void __iomem *)(unsigned long)(__addr))
121
122#define outb_local(__b, __addr) __writeb(__b, (void __iomem *)(unsigned long)(__addr))
123#define outb(__b, __addr) __writeb(__b, (void __iomem *)(unsigned long)(__addr))
124#define outw(__w, __addr) __writew(__w, (void __iomem *)(unsigned long)(__addr))
125#define outl(__l, __addr) __writel(__l, (void __iomem *)(unsigned long)(__addr))
126
127#define inb_p(__addr) inb(__addr)
128#define outb_p(__b, __addr) outb(__b, __addr)
129#define inw_p(__addr) inw(__addr)
130#define outw_p(__w, __addr) outw(__w, __addr)
131#define inl_p(__addr) inl(__addr)
132#define outl_p(__l, __addr) outl(__l, __addr)
133
134void outsb(unsigned long addr, const void *src, unsigned long cnt);
135void outsw(unsigned long addr, const void *src, unsigned long cnt);
136void outsl(unsigned long addr, const void *src, unsigned long cnt);
137void insb(unsigned long addr, void *dst, unsigned long count);
138void insw(unsigned long addr, void *dst, unsigned long count);
139void insl(unsigned long addr, void *dst, unsigned long count);
140
141#define IO_SPACE_LIMIT 0xffffffff
142
143/*
144 * SBus accessors.
145 *
146 * SBus has only one, memory mapped, I/O space.
147 * We do not need to flip bytes for SBus of course.
148 */
149static inline u8 _sbus_readb(const volatile void __iomem *addr)
150{
151 return *(__force volatile u8 *)addr;
152}
153
154static inline u16 _sbus_readw(const volatile void __iomem *addr)
155{
156 return *(__force volatile u16 *)addr;
157}
158
159static inline u32 _sbus_readl(const volatile void __iomem *addr)
160{
161 return *(__force volatile u32 *)addr;
162}
163
164static inline void _sbus_writeb(u8 b, volatile void __iomem *addr)
165{
166 *(__force volatile u8 *)addr = b;
167}
168
169static inline void _sbus_writew(u16 w, volatile void __iomem *addr)
170{
171 *(__force volatile u16 *)addr = w;
172}
173
174static inline void _sbus_writel(u32 l, volatile void __iomem *addr)
175{
176 *(__force volatile u32 *)addr = l;
177}
178
179/*
180 * The only reason for #define's is to hide casts to unsigned long.
181 */
182#define sbus_readb(__addr) _sbus_readb(__addr)
183#define sbus_readw(__addr) _sbus_readw(__addr)
184#define sbus_readl(__addr) _sbus_readl(__addr)
185#define sbus_writeb(__b, __addr) _sbus_writeb(__b, __addr)
186#define sbus_writew(__w, __addr) _sbus_writew(__w, __addr)
187#define sbus_writel(__l, __addr) _sbus_writel(__l, __addr)
188
189static inline void sbus_memset_io(volatile void __iomem *__dst, int c, __kernel_size_t n)
190{
191 while(n--) {
192 sbus_writeb(c, __dst);
193 __dst++;
194 }
195}
196
197static inline void
198_memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
199{
200 volatile void __iomem *d = dst;
201
202 while (n--) {
203 writeb(c, d);
204 d++;
205 }
206}
207
208#define memset_io(d,c,sz) _memset_io(d,c,sz)
209
210static inline void
211_memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
212{
213 char *d = dst;
214
215 while (n--) {
216 char tmp = readb(src);
217 *d++ = tmp;
218 src++;
219 }
220}
221
222#define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
223
224static inline void
225_memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n)
226{
227 const char *s = src;
228 volatile void __iomem *d = dst;
229
230 while (n--) {
231 char tmp = *s++;
232 writeb(tmp, d);
233 d++;
234 }
235}
236
237#define memcpy_toio(d,s,sz) _memcpy_toio(d,s,sz)
238
239#ifdef __KERNEL__
240
241/*
242 * Bus number may be embedded in the higher bits of the physical address.
243 * This is why we have no bus number argument to ioremap().
244 */
245extern void __iomem *ioremap(unsigned long offset, unsigned long size);
246#define ioremap_nocache(X,Y) ioremap((X),(Y))
247extern void iounmap(volatile void __iomem *addr);
248
249#define ioread8(X) readb(X)
250#define ioread16(X) readw(X)
251#define ioread32(X) readl(X)
252#define iowrite8(val,X) writeb(val,X)
253#define iowrite16(val,X) writew(val,X)
254#define iowrite32(val,X) writel(val,X)
255
256static inline void ioread8_rep(void __iomem *port, void *buf, unsigned long count)
257{
258 insb((unsigned long __force)port, buf, count);
259}
260static inline void ioread16_rep(void __iomem *port, void *buf, unsigned long count)
261{
262 insw((unsigned long __force)port, buf, count);
263}
264
265static inline void ioread32_rep(void __iomem *port, void *buf, unsigned long count)
266{
267 insl((unsigned long __force)port, buf, count);
268}
269
270static inline void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count)
271{
272 outsb((unsigned long __force)port, buf, count);
273}
274
275static inline void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count)
276{
277 outsw((unsigned long __force)port, buf, count);
278}
279
280static inline void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count)
281{
282 outsl((unsigned long __force)port, buf, count);
283}
284
285/* Create a virtual mapping cookie for an IO port range */
286extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
287extern void ioport_unmap(void __iomem *);
288
289/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
290struct pci_dev;
291extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
292extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
293
294/*
295 * Bus number may be in res->flags... somewhere.
296 */
297extern void __iomem *sbus_ioremap(struct resource *res, unsigned long offset,
298 unsigned long size, char *name);
299extern void sbus_iounmap(volatile void __iomem *vaddr, unsigned long size);
300
301
302/*
303 * At the moment, we do not use CMOS_READ anywhere outside of rtc.c,
304 * so rtc_port is static in it. This should not change unless a new
305 * hardware pops up.
306 */
307#define RTC_PORT(x) (rtc_port + (x))
308#define RTC_ALWAYS_BCD 0
309
310#endif
311
312#define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
313
314/*
315 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
316 * access
317 */
318#define xlate_dev_mem_ptr(p) __va(p)
319
320/*
321 * Convert a virtual cached pointer to an uncached pointer
322 */
323#define xlate_dev_kmem_ptr(p) p
324
325#endif /* !(__SPARC_IO_H) */
diff --git a/include/asm-sparc/io_64.h b/include/asm-sparc/io_64.h
new file mode 100644
index 000000000000..f4907414b39d
--- /dev/null
+++ b/include/asm-sparc/io_64.h
@@ -0,0 +1,511 @@
1#ifndef __SPARC64_IO_H
2#define __SPARC64_IO_H
3
4#include <linux/kernel.h>
5#include <linux/compiler.h>
6#include <linux/types.h>
7
8#include <asm/page.h> /* IO address mapping routines need this */
9#include <asm/system.h>
10#include <asm/asi.h>
11
12/* PC crapola... */
13#define __SLOW_DOWN_IO do { } while (0)
14#define SLOW_DOWN_IO do { } while (0)
15
16/* BIO layer definitions. */
17extern unsigned long kern_base, kern_size;
18#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
19#define BIO_VMERGE_BOUNDARY 8192
20
21static inline u8 _inb(unsigned long addr)
22{
23 u8 ret;
24
25 __asm__ __volatile__("lduba\t[%1] %2, %0\t/* pci_inb */"
26 : "=r" (ret)
27 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
28 : "memory");
29
30 return ret;
31}
32
33static inline u16 _inw(unsigned long addr)
34{
35 u16 ret;
36
37 __asm__ __volatile__("lduha\t[%1] %2, %0\t/* pci_inw */"
38 : "=r" (ret)
39 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
40 : "memory");
41
42 return ret;
43}
44
45static inline u32 _inl(unsigned long addr)
46{
47 u32 ret;
48
49 __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* pci_inl */"
50 : "=r" (ret)
51 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
52 : "memory");
53
54 return ret;
55}
56
57static inline void _outb(u8 b, unsigned long addr)
58{
59 __asm__ __volatile__("stba\t%r0, [%1] %2\t/* pci_outb */"
60 : /* no outputs */
61 : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
62 : "memory");
63}
64
65static inline void _outw(u16 w, unsigned long addr)
66{
67 __asm__ __volatile__("stha\t%r0, [%1] %2\t/* pci_outw */"
68 : /* no outputs */
69 : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
70 : "memory");
71}
72
73static inline void _outl(u32 l, unsigned long addr)
74{
75 __asm__ __volatile__("stwa\t%r0, [%1] %2\t/* pci_outl */"
76 : /* no outputs */
77 : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
78 : "memory");
79}
80
81#define inb(__addr) (_inb((unsigned long)(__addr)))
82#define inw(__addr) (_inw((unsigned long)(__addr)))
83#define inl(__addr) (_inl((unsigned long)(__addr)))
84#define outb(__b, __addr) (_outb((u8)(__b), (unsigned long)(__addr)))
85#define outw(__w, __addr) (_outw((u16)(__w), (unsigned long)(__addr)))
86#define outl(__l, __addr) (_outl((u32)(__l), (unsigned long)(__addr)))
87
88#define inb_p(__addr) inb(__addr)
89#define outb_p(__b, __addr) outb(__b, __addr)
90#define inw_p(__addr) inw(__addr)
91#define outw_p(__w, __addr) outw(__w, __addr)
92#define inl_p(__addr) inl(__addr)
93#define outl_p(__l, __addr) outl(__l, __addr)
94
95extern void outsb(unsigned long, const void *, unsigned long);
96extern void outsw(unsigned long, const void *, unsigned long);
97extern void outsl(unsigned long, const void *, unsigned long);
98extern void insb(unsigned long, void *, unsigned long);
99extern void insw(unsigned long, void *, unsigned long);
100extern void insl(unsigned long, void *, unsigned long);
101
102static inline void ioread8_rep(void __iomem *port, void *buf, unsigned long count)
103{
104 insb((unsigned long __force)port, buf, count);
105}
106static inline void ioread16_rep(void __iomem *port, void *buf, unsigned long count)
107{
108 insw((unsigned long __force)port, buf, count);
109}
110
111static inline void ioread32_rep(void __iomem *port, void *buf, unsigned long count)
112{
113 insl((unsigned long __force)port, buf, count);
114}
115
116static inline void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count)
117{
118 outsb((unsigned long __force)port, buf, count);
119}
120
121static inline void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count)
122{
123 outsw((unsigned long __force)port, buf, count);
124}
125
126static inline void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count)
127{
128 outsl((unsigned long __force)port, buf, count);
129}
130
131/* Memory functions, same as I/O accesses on Ultra. */
132static inline u8 _readb(const volatile void __iomem *addr)
133{ u8 ret;
134
135 __asm__ __volatile__("lduba\t[%1] %2, %0\t/* pci_readb */"
136 : "=r" (ret)
137 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
138 : "memory");
139 return ret;
140}
141
142static inline u16 _readw(const volatile void __iomem *addr)
143{ u16 ret;
144
145 __asm__ __volatile__("lduha\t[%1] %2, %0\t/* pci_readw */"
146 : "=r" (ret)
147 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
148 : "memory");
149
150 return ret;
151}
152
153static inline u32 _readl(const volatile void __iomem *addr)
154{ u32 ret;
155
156 __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* pci_readl */"
157 : "=r" (ret)
158 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
159 : "memory");
160
161 return ret;
162}
163
164static inline u64 _readq(const volatile void __iomem *addr)
165{ u64 ret;
166
167 __asm__ __volatile__("ldxa\t[%1] %2, %0\t/* pci_readq */"
168 : "=r" (ret)
169 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
170 : "memory");
171
172 return ret;
173}
174
175static inline void _writeb(u8 b, volatile void __iomem *addr)
176{
177 __asm__ __volatile__("stba\t%r0, [%1] %2\t/* pci_writeb */"
178 : /* no outputs */
179 : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
180 : "memory");
181}
182
183static inline void _writew(u16 w, volatile void __iomem *addr)
184{
185 __asm__ __volatile__("stha\t%r0, [%1] %2\t/* pci_writew */"
186 : /* no outputs */
187 : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
188 : "memory");
189}
190
191static inline void _writel(u32 l, volatile void __iomem *addr)
192{
193 __asm__ __volatile__("stwa\t%r0, [%1] %2\t/* pci_writel */"
194 : /* no outputs */
195 : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
196 : "memory");
197}
198
199static inline void _writeq(u64 q, volatile void __iomem *addr)
200{
201 __asm__ __volatile__("stxa\t%r0, [%1] %2\t/* pci_writeq */"
202 : /* no outputs */
203 : "Jr" (q), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
204 : "memory");
205}
206
207#define readb(__addr) _readb(__addr)
208#define readw(__addr) _readw(__addr)
209#define readl(__addr) _readl(__addr)
210#define readq(__addr) _readq(__addr)
211#define readb_relaxed(__addr) _readb(__addr)
212#define readw_relaxed(__addr) _readw(__addr)
213#define readl_relaxed(__addr) _readl(__addr)
214#define readq_relaxed(__addr) _readq(__addr)
215#define writeb(__b, __addr) _writeb(__b, __addr)
216#define writew(__w, __addr) _writew(__w, __addr)
217#define writel(__l, __addr) _writel(__l, __addr)
218#define writeq(__q, __addr) _writeq(__q, __addr)
219
220/* Now versions without byte-swapping. */
221static inline u8 _raw_readb(unsigned long addr)
222{
223 u8 ret;
224
225 __asm__ __volatile__("lduba\t[%1] %2, %0\t/* pci_raw_readb */"
226 : "=r" (ret)
227 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
228
229 return ret;
230}
231
232static inline u16 _raw_readw(unsigned long addr)
233{
234 u16 ret;
235
236 __asm__ __volatile__("lduha\t[%1] %2, %0\t/* pci_raw_readw */"
237 : "=r" (ret)
238 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
239
240 return ret;
241}
242
243static inline u32 _raw_readl(unsigned long addr)
244{
245 u32 ret;
246
247 __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* pci_raw_readl */"
248 : "=r" (ret)
249 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
250
251 return ret;
252}
253
254static inline u64 _raw_readq(unsigned long addr)
255{
256 u64 ret;
257
258 __asm__ __volatile__("ldxa\t[%1] %2, %0\t/* pci_raw_readq */"
259 : "=r" (ret)
260 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
261
262 return ret;
263}
264
265static inline void _raw_writeb(u8 b, unsigned long addr)
266{
267 __asm__ __volatile__("stba\t%r0, [%1] %2\t/* pci_raw_writeb */"
268 : /* no outputs */
269 : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
270}
271
272static inline void _raw_writew(u16 w, unsigned long addr)
273{
274 __asm__ __volatile__("stha\t%r0, [%1] %2\t/* pci_raw_writew */"
275 : /* no outputs */
276 : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
277}
278
279static inline void _raw_writel(u32 l, unsigned long addr)
280{
281 __asm__ __volatile__("stwa\t%r0, [%1] %2\t/* pci_raw_writel */"
282 : /* no outputs */
283 : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
284}
285
286static inline void _raw_writeq(u64 q, unsigned long addr)
287{
288 __asm__ __volatile__("stxa\t%r0, [%1] %2\t/* pci_raw_writeq */"
289 : /* no outputs */
290 : "Jr" (q), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
291}
292
293#define __raw_readb(__addr) (_raw_readb((unsigned long)(__addr)))
294#define __raw_readw(__addr) (_raw_readw((unsigned long)(__addr)))
295#define __raw_readl(__addr) (_raw_readl((unsigned long)(__addr)))
296#define __raw_readq(__addr) (_raw_readq((unsigned long)(__addr)))
297#define __raw_writeb(__b, __addr) (_raw_writeb((u8)(__b), (unsigned long)(__addr)))
298#define __raw_writew(__w, __addr) (_raw_writew((u16)(__w), (unsigned long)(__addr)))
299#define __raw_writel(__l, __addr) (_raw_writel((u32)(__l), (unsigned long)(__addr)))
300#define __raw_writeq(__q, __addr) (_raw_writeq((u64)(__q), (unsigned long)(__addr)))
301
302/* Valid I/O Space regions are anywhere, because each PCI bus supported
303 * can live in an arbitrary area of the physical address range.
304 */
305#define IO_SPACE_LIMIT 0xffffffffffffffffUL
306
307/* Now, SBUS variants, only difference from PCI is that we do
308 * not use little-endian ASIs.
309 */
310static inline u8 _sbus_readb(const volatile void __iomem *addr)
311{
312 u8 ret;
313
314 __asm__ __volatile__("lduba\t[%1] %2, %0\t/* sbus_readb */"
315 : "=r" (ret)
316 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
317 : "memory");
318
319 return ret;
320}
321
322static inline u16 _sbus_readw(const volatile void __iomem *addr)
323{
324 u16 ret;
325
326 __asm__ __volatile__("lduha\t[%1] %2, %0\t/* sbus_readw */"
327 : "=r" (ret)
328 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
329 : "memory");
330
331 return ret;
332}
333
334static inline u32 _sbus_readl(const volatile void __iomem *addr)
335{
336 u32 ret;
337
338 __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* sbus_readl */"
339 : "=r" (ret)
340 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
341 : "memory");
342
343 return ret;
344}
345
346static inline u64 _sbus_readq(const volatile void __iomem *addr)
347{
348 u64 ret;
349
350 __asm__ __volatile__("ldxa\t[%1] %2, %0\t/* sbus_readq */"
351 : "=r" (ret)
352 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
353 : "memory");
354
355 return ret;
356}
357
358static inline void _sbus_writeb(u8 b, volatile void __iomem *addr)
359{
360 __asm__ __volatile__("stba\t%r0, [%1] %2\t/* sbus_writeb */"
361 : /* no outputs */
362 : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
363 : "memory");
364}
365
366static inline void _sbus_writew(u16 w, volatile void __iomem *addr)
367{
368 __asm__ __volatile__("stha\t%r0, [%1] %2\t/* sbus_writew */"
369 : /* no outputs */
370 : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
371 : "memory");
372}
373
374static inline void _sbus_writel(u32 l, volatile void __iomem *addr)
375{
376 __asm__ __volatile__("stwa\t%r0, [%1] %2\t/* sbus_writel */"
377 : /* no outputs */
378 : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
379 : "memory");
380}
381
382static inline void _sbus_writeq(u64 l, volatile void __iomem *addr)
383{
384 __asm__ __volatile__("stxa\t%r0, [%1] %2\t/* sbus_writeq */"
385 : /* no outputs */
386 : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
387 : "memory");
388}
389
390#define sbus_readb(__addr) _sbus_readb(__addr)
391#define sbus_readw(__addr) _sbus_readw(__addr)
392#define sbus_readl(__addr) _sbus_readl(__addr)
393#define sbus_readq(__addr) _sbus_readq(__addr)
394#define sbus_writeb(__b, __addr) _sbus_writeb(__b, __addr)
395#define sbus_writew(__w, __addr) _sbus_writew(__w, __addr)
396#define sbus_writel(__l, __addr) _sbus_writel(__l, __addr)
397#define sbus_writeq(__l, __addr) _sbus_writeq(__l, __addr)
398
399static inline void _sbus_memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
400{
401 while(n--) {
402 sbus_writeb(c, dst);
403 dst++;
404 }
405}
406
407#define sbus_memset_io(d,c,sz) _sbus_memset_io(d,c,sz)
408
409static inline void
410_memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
411{
412 volatile void __iomem *d = dst;
413
414 while (n--) {
415 writeb(c, d);
416 d++;
417 }
418}
419
420#define memset_io(d,c,sz) _memset_io(d,c,sz)
421
422static inline void
423_memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
424{
425 char *d = dst;
426
427 while (n--) {
428 char tmp = readb(src);
429 *d++ = tmp;
430 src++;
431 }
432}
433
434#define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
435
436static inline void
437_memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n)
438{
439 const char *s = src;
440 volatile void __iomem *d = dst;
441
442 while (n--) {
443 char tmp = *s++;
444 writeb(tmp, d);
445 d++;
446 }
447}
448
449#define memcpy_toio(d,s,sz) _memcpy_toio(d,s,sz)
450
451#define mmiowb()
452
453#ifdef __KERNEL__
454
455/* On sparc64 we have the whole physical IO address space accessible
456 * using physically addressed loads and stores, so this does nothing.
457 */
458static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
459{
460 return (void __iomem *)offset;
461}
462
463#define ioremap_nocache(X,Y) ioremap((X),(Y))
464
465static inline void iounmap(volatile void __iomem *addr)
466{
467}
468
469#define ioread8(X) readb(X)
470#define ioread16(X) readw(X)
471#define ioread32(X) readl(X)
472#define iowrite8(val,X) writeb(val,X)
473#define iowrite16(val,X) writew(val,X)
474#define iowrite32(val,X) writel(val,X)
475
476/* Create a virtual mapping cookie for an IO port range */
477extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
478extern void ioport_unmap(void __iomem *);
479
480/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
481struct pci_dev;
482extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
483extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
484
485/* Similarly for SBUS. */
486#define sbus_ioremap(__res, __offset, __size, __name) \
487({ unsigned long __ret; \
488 __ret = (__res)->start + (((__res)->flags & 0x1ffUL) << 32UL); \
489 __ret += (unsigned long) (__offset); \
490 if (! request_region((__ret), (__size), (__name))) \
491 __ret = 0UL; \
492 (void __iomem *) __ret; \
493})
494
495#define sbus_iounmap(__addr, __size) \
496 release_region((unsigned long)(__addr), (__size))
497
498/*
499 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
500 * access
501 */
502#define xlate_dev_mem_ptr(p) __va(p)
503
504/*
505 * Convert a virtual cached pointer to an uncached pointer
506 */
507#define xlate_dev_kmem_ptr(p) p
508
509#endif
510
511#endif /* !(__SPARC64_IO_H) */
diff --git a/include/asm-sparc/ioctls.h b/include/asm-sparc/ioctls.h
index 3f4d0087b6a3..1fe6855c5c18 100644
--- a/include/asm-sparc/ioctls.h
+++ b/include/asm-sparc/ioctls.h
@@ -22,7 +22,7 @@
22 22
23/* Note that all the ioctls that are not available in Linux have a 23/* Note that all the ioctls that are not available in Linux have a
24 * double underscore on the front to: a) avoid some programs to 24 * double underscore on the front to: a) avoid some programs to
25 * thing we support some ioctls under Linux (autoconfiguration stuff) 25 * think we support some ioctls under Linux (autoconfiguration stuff)
26 */ 26 */
27/* Little t */ 27/* Little t */
28#define TIOCGETD _IOR('t', 0, int) 28#define TIOCGETD _IOR('t', 0, int)
@@ -110,7 +110,7 @@
110#define TIOCSERGETLSR 0x5459 /* Get line status register */ 110#define TIOCSERGETLSR 0x5459 /* Get line status register */
111#define TIOCSERGETMULTI 0x545A /* Get multiport config */ 111#define TIOCSERGETMULTI 0x545A /* Get multiport config */
112#define TIOCSERSETMULTI 0x545B /* Set multiport config */ 112#define TIOCSERSETMULTI 0x545B /* Set multiport config */
113#define TIOCMIWAIT 0x545C /* Wait input */ 113#define TIOCMIWAIT 0x545C /* Wait for change on serial input line(s) */
114#define TIOCGICOUNT 0x545D /* Read serial port inline interrupt counts */ 114#define TIOCGICOUNT 0x545D /* Read serial port inline interrupt counts */
115 115
116/* Kernel definitions */ 116/* Kernel definitions */
diff --git a/include/asm-sparc/iommu.h b/include/asm-sparc/iommu.h
index 70c589c05a10..91b072b0d7a0 100644
--- a/include/asm-sparc/iommu.h
+++ b/include/asm-sparc/iommu.h
@@ -1,121 +1,8 @@
1/* iommu.h: Definitions for the sun4m IOMMU. 1#ifndef ___ASM_SPARC_IOMMU_H
2 * 2#define ___ASM_SPARC_IOMMU_H
3 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 3#if defined(__sparc__) && defined(__arch64__)
4 */ 4#include <asm-sparc/iommu_64.h>
5#ifndef _SPARC_IOMMU_H 5#else
6#define _SPARC_IOMMU_H 6#include <asm-sparc/iommu_32.h>
7 7#endif
8#include <asm/page.h> 8#endif
9#include <asm/bitext.h>
10
11/* The iommu handles all virtual to physical address translations
12 * that occur between the SBUS and physical memory. Access by
13 * the cpu to IO registers and similar go over the mbus so are
14 * translated by the on chip SRMMU. The iommu and the srmmu do
15 * not need to have the same translations at all, in fact most
16 * of the time the translations they handle are a disjunct set.
17 * Basically the iommu handles all dvma sbus activity.
18 */
19
20/* The IOMMU registers occupy three pages in IO space. */
21struct iommu_regs {
22 /* First page */
23 volatile unsigned long control; /* IOMMU control */
24 volatile unsigned long base; /* Physical base of iopte page table */
25 volatile unsigned long _unused1[3];
26 volatile unsigned long tlbflush; /* write only */
27 volatile unsigned long pageflush; /* write only */
28 volatile unsigned long _unused2[1017];
29 /* Second page */
30 volatile unsigned long afsr; /* Async-fault status register */
31 volatile unsigned long afar; /* Async-fault physical address */
32 volatile unsigned long _unused3[2];
33 volatile unsigned long sbuscfg0; /* SBUS configuration registers, per-slot */
34 volatile unsigned long sbuscfg1;
35 volatile unsigned long sbuscfg2;
36 volatile unsigned long sbuscfg3;
37 volatile unsigned long mfsr; /* Memory-fault status register */
38 volatile unsigned long mfar; /* Memory-fault physical address */
39 volatile unsigned long _unused4[1014];
40 /* Third page */
41 volatile unsigned long mid; /* IOMMU module-id */
42};
43
44#define IOMMU_CTRL_IMPL 0xf0000000 /* Implementation */
45#define IOMMU_CTRL_VERS 0x0f000000 /* Version */
46#define IOMMU_CTRL_RNGE 0x0000001c /* Mapping RANGE */
47#define IOMMU_RNGE_16MB 0x00000000 /* 0xff000000 -> 0xffffffff */
48#define IOMMU_RNGE_32MB 0x00000004 /* 0xfe000000 -> 0xffffffff */
49#define IOMMU_RNGE_64MB 0x00000008 /* 0xfc000000 -> 0xffffffff */
50#define IOMMU_RNGE_128MB 0x0000000c /* 0xf8000000 -> 0xffffffff */
51#define IOMMU_RNGE_256MB 0x00000010 /* 0xf0000000 -> 0xffffffff */
52#define IOMMU_RNGE_512MB 0x00000014 /* 0xe0000000 -> 0xffffffff */
53#define IOMMU_RNGE_1GB 0x00000018 /* 0xc0000000 -> 0xffffffff */
54#define IOMMU_RNGE_2GB 0x0000001c /* 0x80000000 -> 0xffffffff */
55#define IOMMU_CTRL_ENAB 0x00000001 /* IOMMU Enable */
56
57#define IOMMU_AFSR_ERR 0x80000000 /* LE, TO, or BE asserted */
58#define IOMMU_AFSR_LE 0x40000000 /* SBUS reports error after transaction */
59#define IOMMU_AFSR_TO 0x20000000 /* Write access took more than 12.8 us. */
60#define IOMMU_AFSR_BE 0x10000000 /* Write access received error acknowledge */
61#define IOMMU_AFSR_SIZE 0x0e000000 /* Size of transaction causing error */
62#define IOMMU_AFSR_S 0x01000000 /* Sparc was in supervisor mode */
63#define IOMMU_AFSR_RESV 0x00f00000 /* Reserver, forced to 0x8 by hardware */
64#define IOMMU_AFSR_ME 0x00080000 /* Multiple errors occurred */
65#define IOMMU_AFSR_RD 0x00040000 /* A read operation was in progress */
66#define IOMMU_AFSR_FAV 0x00020000 /* IOMMU afar has valid contents */
67
68#define IOMMU_SBCFG_SAB30 0x00010000 /* Phys-address bit 30 when bypass enabled */
69#define IOMMU_SBCFG_BA16 0x00000004 /* Slave supports 16 byte bursts */
70#define IOMMU_SBCFG_BA8 0x00000002 /* Slave supports 8 byte bursts */
71#define IOMMU_SBCFG_BYPASS 0x00000001 /* Bypass IOMMU, treat all addresses
72 produced by this device as pure
73 physical. */
74
75#define IOMMU_MFSR_ERR 0x80000000 /* One or more of PERR1 or PERR0 */
76#define IOMMU_MFSR_S 0x01000000 /* Sparc was in supervisor mode */
77#define IOMMU_MFSR_CPU 0x00800000 /* CPU transaction caused parity error */
78#define IOMMU_MFSR_ME 0x00080000 /* Multiple parity errors occurred */
79#define IOMMU_MFSR_PERR 0x00006000 /* high bit indicates parity error occurred
80 on the even word of the access, low bit
81 indicated odd word caused the parity error */
82#define IOMMU_MFSR_BM 0x00001000 /* Error occurred while in boot mode */
83#define IOMMU_MFSR_C 0x00000800 /* Address causing error was marked cacheable */
84#define IOMMU_MFSR_RTYP 0x000000f0 /* Memory request transaction type */
85
86#define IOMMU_MID_SBAE 0x001f0000 /* SBus arbitration enable */
87#define IOMMU_MID_SE 0x00100000 /* Enables SCSI/ETHERNET arbitration */
88#define IOMMU_MID_SB3 0x00080000 /* Enable SBUS device 3 arbitration */
89#define IOMMU_MID_SB2 0x00040000 /* Enable SBUS device 2 arbitration */
90#define IOMMU_MID_SB1 0x00020000 /* Enable SBUS device 1 arbitration */
91#define IOMMU_MID_SB0 0x00010000 /* Enable SBUS device 0 arbitration */
92#define IOMMU_MID_MID 0x0000000f /* Module-id, hardcoded to 0x8 */
93
94/* The format of an iopte in the page tables */
95#define IOPTE_PAGE 0x07ffff00 /* Physical page number (PA[30:12]) */
96#define IOPTE_CACHE 0x00000080 /* Cached (in vme IOCACHE or Viking/MXCC) */
97#define IOPTE_WRITE 0x00000004 /* Writeable */
98#define IOPTE_VALID 0x00000002 /* IOPTE is valid */
99#define IOPTE_WAZ 0x00000001 /* Write as zeros */
100
101struct iommu_struct {
102 struct iommu_regs *regs;
103 iopte_t *page_table;
104 /* For convenience */
105 unsigned long start; /* First managed virtual address */
106 unsigned long end; /* Last managed virtual address */
107
108 struct bit_map usemap;
109};
110
111static inline void iommu_invalidate(struct iommu_regs *regs)
112{
113 regs->tlbflush = 0;
114}
115
116static inline void iommu_invalidate_page(struct iommu_regs *regs, unsigned long ba)
117{
118 regs->pageflush = (ba & PAGE_MASK);
119}
120
121#endif /* !(_SPARC_IOMMU_H) */
diff --git a/include/asm-sparc/iommu_32.h b/include/asm-sparc/iommu_32.h
new file mode 100644
index 000000000000..70c589c05a10
--- /dev/null
+++ b/include/asm-sparc/iommu_32.h
@@ -0,0 +1,121 @@
1/* iommu.h: Definitions for the sun4m IOMMU.
2 *
3 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
4 */
5#ifndef _SPARC_IOMMU_H
6#define _SPARC_IOMMU_H
7
8#include <asm/page.h>
9#include <asm/bitext.h>
10
11/* The iommu handles all virtual to physical address translations
12 * that occur between the SBUS and physical memory. Access by
13 * the cpu to IO registers and similar go over the mbus so are
14 * translated by the on chip SRMMU. The iommu and the srmmu do
15 * not need to have the same translations at all, in fact most
16 * of the time the translations they handle are a disjunct set.
17 * Basically the iommu handles all dvma sbus activity.
18 */
19
20/* The IOMMU registers occupy three pages in IO space. */
21struct iommu_regs {
22 /* First page */
23 volatile unsigned long control; /* IOMMU control */
24 volatile unsigned long base; /* Physical base of iopte page table */
25 volatile unsigned long _unused1[3];
26 volatile unsigned long tlbflush; /* write only */
27 volatile unsigned long pageflush; /* write only */
28 volatile unsigned long _unused2[1017];
29 /* Second page */
30 volatile unsigned long afsr; /* Async-fault status register */
31 volatile unsigned long afar; /* Async-fault physical address */
32 volatile unsigned long _unused3[2];
33 volatile unsigned long sbuscfg0; /* SBUS configuration registers, per-slot */
34 volatile unsigned long sbuscfg1;
35 volatile unsigned long sbuscfg2;
36 volatile unsigned long sbuscfg3;
37 volatile unsigned long mfsr; /* Memory-fault status register */
38 volatile unsigned long mfar; /* Memory-fault physical address */
39 volatile unsigned long _unused4[1014];
40 /* Third page */
41 volatile unsigned long mid; /* IOMMU module-id */
42};
43
44#define IOMMU_CTRL_IMPL 0xf0000000 /* Implementation */
45#define IOMMU_CTRL_VERS 0x0f000000 /* Version */
46#define IOMMU_CTRL_RNGE 0x0000001c /* Mapping RANGE */
47#define IOMMU_RNGE_16MB 0x00000000 /* 0xff000000 -> 0xffffffff */
48#define IOMMU_RNGE_32MB 0x00000004 /* 0xfe000000 -> 0xffffffff */
49#define IOMMU_RNGE_64MB 0x00000008 /* 0xfc000000 -> 0xffffffff */
50#define IOMMU_RNGE_128MB 0x0000000c /* 0xf8000000 -> 0xffffffff */
51#define IOMMU_RNGE_256MB 0x00000010 /* 0xf0000000 -> 0xffffffff */
52#define IOMMU_RNGE_512MB 0x00000014 /* 0xe0000000 -> 0xffffffff */
53#define IOMMU_RNGE_1GB 0x00000018 /* 0xc0000000 -> 0xffffffff */
54#define IOMMU_RNGE_2GB 0x0000001c /* 0x80000000 -> 0xffffffff */
55#define IOMMU_CTRL_ENAB 0x00000001 /* IOMMU Enable */
56
57#define IOMMU_AFSR_ERR 0x80000000 /* LE, TO, or BE asserted */
58#define IOMMU_AFSR_LE 0x40000000 /* SBUS reports error after transaction */
59#define IOMMU_AFSR_TO 0x20000000 /* Write access took more than 12.8 us. */
60#define IOMMU_AFSR_BE 0x10000000 /* Write access received error acknowledge */
61#define IOMMU_AFSR_SIZE 0x0e000000 /* Size of transaction causing error */
62#define IOMMU_AFSR_S 0x01000000 /* Sparc was in supervisor mode */
63#define IOMMU_AFSR_RESV 0x00f00000 /* Reserver, forced to 0x8 by hardware */
64#define IOMMU_AFSR_ME 0x00080000 /* Multiple errors occurred */
65#define IOMMU_AFSR_RD 0x00040000 /* A read operation was in progress */
66#define IOMMU_AFSR_FAV 0x00020000 /* IOMMU afar has valid contents */
67
68#define IOMMU_SBCFG_SAB30 0x00010000 /* Phys-address bit 30 when bypass enabled */
69#define IOMMU_SBCFG_BA16 0x00000004 /* Slave supports 16 byte bursts */
70#define IOMMU_SBCFG_BA8 0x00000002 /* Slave supports 8 byte bursts */
71#define IOMMU_SBCFG_BYPASS 0x00000001 /* Bypass IOMMU, treat all addresses
72 produced by this device as pure
73 physical. */
74
75#define IOMMU_MFSR_ERR 0x80000000 /* One or more of PERR1 or PERR0 */
76#define IOMMU_MFSR_S 0x01000000 /* Sparc was in supervisor mode */
77#define IOMMU_MFSR_CPU 0x00800000 /* CPU transaction caused parity error */
78#define IOMMU_MFSR_ME 0x00080000 /* Multiple parity errors occurred */
79#define IOMMU_MFSR_PERR 0x00006000 /* high bit indicates parity error occurred
80 on the even word of the access, low bit
81 indicated odd word caused the parity error */
82#define IOMMU_MFSR_BM 0x00001000 /* Error occurred while in boot mode */
83#define IOMMU_MFSR_C 0x00000800 /* Address causing error was marked cacheable */
84#define IOMMU_MFSR_RTYP 0x000000f0 /* Memory request transaction type */
85
86#define IOMMU_MID_SBAE 0x001f0000 /* SBus arbitration enable */
87#define IOMMU_MID_SE 0x00100000 /* Enables SCSI/ETHERNET arbitration */
88#define IOMMU_MID_SB3 0x00080000 /* Enable SBUS device 3 arbitration */
89#define IOMMU_MID_SB2 0x00040000 /* Enable SBUS device 2 arbitration */
90#define IOMMU_MID_SB1 0x00020000 /* Enable SBUS device 1 arbitration */
91#define IOMMU_MID_SB0 0x00010000 /* Enable SBUS device 0 arbitration */
92#define IOMMU_MID_MID 0x0000000f /* Module-id, hardcoded to 0x8 */
93
94/* The format of an iopte in the page tables */
95#define IOPTE_PAGE 0x07ffff00 /* Physical page number (PA[30:12]) */
96#define IOPTE_CACHE 0x00000080 /* Cached (in vme IOCACHE or Viking/MXCC) */
97#define IOPTE_WRITE 0x00000004 /* Writeable */
98#define IOPTE_VALID 0x00000002 /* IOPTE is valid */
99#define IOPTE_WAZ 0x00000001 /* Write as zeros */
100
101struct iommu_struct {
102 struct iommu_regs *regs;
103 iopte_t *page_table;
104 /* For convenience */
105 unsigned long start; /* First managed virtual address */
106 unsigned long end; /* Last managed virtual address */
107
108 struct bit_map usemap;
109};
110
111static inline void iommu_invalidate(struct iommu_regs *regs)
112{
113 regs->tlbflush = 0;
114}
115
116static inline void iommu_invalidate_page(struct iommu_regs *regs, unsigned long ba)
117{
118 regs->pageflush = (ba & PAGE_MASK);
119}
120
121#endif /* !(_SPARC_IOMMU_H) */
diff --git a/include/asm-sparc/iommu_64.h b/include/asm-sparc/iommu_64.h
new file mode 100644
index 000000000000..d7b9afcba08b
--- /dev/null
+++ b/include/asm-sparc/iommu_64.h
@@ -0,0 +1,62 @@
1/* iommu.h: Definitions for the sun5 IOMMU.
2 *
3 * Copyright (C) 1996, 1999, 2007 David S. Miller (davem@davemloft.net)
4 */
5#ifndef _SPARC64_IOMMU_H
6#define _SPARC64_IOMMU_H
7
8/* The format of an iopte in the page tables. */
9#define IOPTE_VALID 0x8000000000000000UL
10#define IOPTE_64K 0x2000000000000000UL
11#define IOPTE_STBUF 0x1000000000000000UL
12#define IOPTE_INTRA 0x0800000000000000UL
13#define IOPTE_CONTEXT 0x07ff800000000000UL
14#define IOPTE_PAGE 0x00007fffffffe000UL
15#define IOPTE_CACHE 0x0000000000000010UL
16#define IOPTE_WRITE 0x0000000000000002UL
17
18#define IOMMU_NUM_CTXS 4096
19
20struct iommu_arena {
21 unsigned long *map;
22 unsigned int hint;
23 unsigned int limit;
24};
25
26struct iommu {
27 spinlock_t lock;
28 struct iommu_arena arena;
29 void (*flush_all)(struct iommu *);
30 iopte_t *page_table;
31 u32 page_table_map_base;
32 unsigned long iommu_control;
33 unsigned long iommu_tsbbase;
34 unsigned long iommu_flush;
35 unsigned long iommu_flushinv;
36 unsigned long iommu_tags;
37 unsigned long iommu_ctxflush;
38 unsigned long write_complete_reg;
39 unsigned long dummy_page;
40 unsigned long dummy_page_pa;
41 unsigned long ctx_lowest_free;
42 DECLARE_BITMAP(ctx_bitmap, IOMMU_NUM_CTXS);
43 u32 dma_addr_mask;
44};
45
46struct strbuf {
47 int strbuf_enabled;
48 unsigned long strbuf_control;
49 unsigned long strbuf_pflush;
50 unsigned long strbuf_fsync;
51 unsigned long strbuf_ctxflush;
52 unsigned long strbuf_ctxmatch_base;
53 unsigned long strbuf_flushflag_pa;
54 volatile unsigned long *strbuf_flushflag;
55 volatile unsigned long __flushflag_buf[(64+(64-1)) / sizeof(long)];
56};
57
58extern int iommu_table_init(struct iommu *iommu, int tsbsize,
59 u32 dma_offset, u32 dma_addr_mask,
60 int numa_node);
61
62#endif /* !(_SPARC64_IOMMU_H) */
diff --git a/include/asm-sparc/ipcbuf.h b/include/asm-sparc/ipcbuf.h
index 9bef02d04e4b..037605d986e2 100644
--- a/include/asm-sparc/ipcbuf.h
+++ b/include/asm-sparc/ipcbuf.h
@@ -1,31 +1,8 @@
1#ifndef _SPARC_IPCBUF_H 1#ifndef ___ASM_SPARC_IPCBUF_H
2#define _SPARC_IPCBUF_H 2#define ___ASM_SPARC_IPCBUF_H
3 3#if defined(__sparc__) && defined(__arch64__)
4/* 4#include <asm-sparc/ipcbuf_64.h>
5 * The ipc64_perm structure for sparc architecture. 5#else
6 * Note extra padding because this structure is passed back and forth 6#include <asm-sparc/ipcbuf_32.h>
7 * between kernel and user space. 7#endif
8 * 8#endif
9 * Pad space is left for:
10 * - 32-bit mode
11 * - 32-bit seq
12 * - 2 miscellaneous 64-bit values (so that this structure matches
13 * sparc64 ipc64_perm)
14 */
15
16struct ipc64_perm
17{
18 __kernel_key_t key;
19 __kernel_uid32_t uid;
20 __kernel_gid32_t gid;
21 __kernel_uid32_t cuid;
22 __kernel_gid32_t cgid;
23 unsigned short __pad1;
24 __kernel_mode_t mode;
25 unsigned short __pad2;
26 unsigned short seq;
27 unsigned long long __unused1;
28 unsigned long long __unused2;
29};
30
31#endif /* _SPARC_IPCBUF_H */
diff --git a/include/asm-sparc/ipcbuf_32.h b/include/asm-sparc/ipcbuf_32.h
new file mode 100644
index 000000000000..6387209518f2
--- /dev/null
+++ b/include/asm-sparc/ipcbuf_32.h
@@ -0,0 +1,31 @@
1#ifndef _SPARC_IPCBUF_H
2#define _SPARC_IPCBUF_H
3
4/*
5 * The ipc64_perm structure for sparc architecture.
6 * Note extra padding because this structure is passed back and forth
7 * between kernel and user space.
8 *
9 * Pad space is left for:
10 * - 32-bit mode
11 * - 32-bit seq
12 * - 2 miscellaneous 64-bit values (so that this structure matches
13 * sparc64 ipc64_perm)
14 */
15
16struct ipc64_perm
17{
18 __kernel_key_t key;
19 __kernel_uid32_t uid;
20 __kernel_gid32_t gid;
21 __kernel_uid32_t cuid;
22 __kernel_gid32_t cgid;
23 unsigned short __pad1;
24 __kernel_mode_t mode;
25 unsigned short __pad2;
26 unsigned short seq;
27 unsigned long long __unused1;
28 unsigned long long __unused2;
29};
30
31#endif /* _SPARC_IPCBUF_H */
diff --git a/include/asm-sparc/ipcbuf_64.h b/include/asm-sparc/ipcbuf_64.h
new file mode 100644
index 000000000000..a44b855b98db
--- /dev/null
+++ b/include/asm-sparc/ipcbuf_64.h
@@ -0,0 +1,28 @@
1#ifndef _SPARC64_IPCBUF_H
2#define _SPARC64_IPCBUF_H
3
4/*
5 * The ipc64_perm structure for sparc64 architecture.
6 * Note extra padding because this structure is passed back and forth
7 * between kernel and user space.
8 *
9 * Pad space is left for:
10 * - 32-bit seq
11 * - 2 miscellaneous 64-bit values
12 */
13
14struct ipc64_perm
15{
16 __kernel_key_t key;
17 __kernel_uid_t uid;
18 __kernel_gid_t gid;
19 __kernel_uid_t cuid;
20 __kernel_gid_t cgid;
21 __kernel_mode_t mode;
22 unsigned short __pad1;
23 unsigned short seq;
24 unsigned long __unused1;
25 unsigned long __unused2;
26};
27
28#endif /* _SPARC64_IPCBUF_H */
diff --git a/include/asm-sparc/irq.h b/include/asm-sparc/irq.h
index fe205cc444b8..7af6bb4aa09c 100644
--- a/include/asm-sparc/irq.h
+++ b/include/asm-sparc/irq.h
@@ -1,15 +1,8 @@
1/* irq.h: IRQ registers on the Sparc. 1#ifndef ___ASM_SPARC_IRQ_H
2 * 2#define ___ASM_SPARC_IRQ_H
3 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net) 3#if defined(__sparc__) && defined(__arch64__)
4 */ 4#include <asm-sparc/irq_64.h>
5 5#else
6#ifndef _SPARC_IRQ_H 6#include <asm-sparc/irq_32.h>
7#define _SPARC_IRQ_H 7#endif
8
9#include <linux/interrupt.h>
10
11#define NR_IRQS 16
12
13#define irq_canonicalize(irq) (irq)
14
15#endif 8#endif
diff --git a/include/asm-sparc/irq_32.h b/include/asm-sparc/irq_32.h
new file mode 100644
index 000000000000..fe205cc444b8
--- /dev/null
+++ b/include/asm-sparc/irq_32.h
@@ -0,0 +1,15 @@
1/* irq.h: IRQ registers on the Sparc.
2 *
3 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC_IRQ_H
7#define _SPARC_IRQ_H
8
9#include <linux/interrupt.h>
10
11#define NR_IRQS 16
12
13#define irq_canonicalize(irq) (irq)
14
15#endif
diff --git a/include/asm-sparc/irq_64.h b/include/asm-sparc/irq_64.h
new file mode 100644
index 000000000000..0bb9bf531745
--- /dev/null
+++ b/include/asm-sparc/irq_64.h
@@ -0,0 +1,93 @@
1/* irq.h: IRQ registers on the 64-bit Sparc.
2 *
3 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz)
5 */
6
7#ifndef _SPARC64_IRQ_H
8#define _SPARC64_IRQ_H
9
10#include <linux/linkage.h>
11#include <linux/kernel.h>
12#include <linux/errno.h>
13#include <linux/interrupt.h>
14#include <asm/pil.h>
15#include <asm/ptrace.h>
16
17/* IMAP/ICLR register defines */
18#define IMAP_VALID 0x80000000UL /* IRQ Enabled */
19#define IMAP_TID_UPA 0x7c000000UL /* UPA TargetID */
20#define IMAP_TID_JBUS 0x7c000000UL /* JBUS TargetID */
21#define IMAP_TID_SHIFT 26
22#define IMAP_AID_SAFARI 0x7c000000UL /* Safari AgentID */
23#define IMAP_AID_SHIFT 26
24#define IMAP_NID_SAFARI 0x03e00000UL /* Safari NodeID */
25#define IMAP_NID_SHIFT 21
26#define IMAP_IGN 0x000007c0UL /* IRQ Group Number */
27#define IMAP_INO 0x0000003fUL /* IRQ Number */
28#define IMAP_INR 0x000007ffUL /* Full interrupt number*/
29
30#define ICLR_IDLE 0x00000000UL /* Idle state */
31#define ICLR_TRANSMIT 0x00000001UL /* Transmit state */
32#define ICLR_PENDING 0x00000003UL /* Pending state */
33
34/* The largest number of unique interrupt sources we support.
35 * If this needs to ever be larger than 255, you need to change
36 * the type of ino_bucket->virt_irq as appropriate.
37 *
38 * ino_bucket->virt_irq allocation is made during {sun4v_,}build_irq().
39 */
40#define NR_IRQS 255
41
42extern void irq_install_pre_handler(int virt_irq,
43 void (*func)(unsigned int, void *, void *),
44 void *arg1, void *arg2);
45#define irq_canonicalize(irq) (irq)
46extern unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap);
47extern unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino);
48extern unsigned int sun4v_build_virq(u32 devhandle, unsigned int devino);
49extern unsigned int sun4v_build_msi(u32 devhandle, unsigned int *virt_irq_p,
50 unsigned int msi_devino_start,
51 unsigned int msi_devino_end);
52extern void sun4v_destroy_msi(unsigned int virt_irq);
53extern unsigned int sun4u_build_msi(u32 portid, unsigned int *virt_irq_p,
54 unsigned int msi_devino_start,
55 unsigned int msi_devino_end,
56 unsigned long imap_base,
57 unsigned long iclr_base);
58extern void sun4u_destroy_msi(unsigned int virt_irq);
59extern unsigned int sbus_build_irq(void *sbus, unsigned int ino);
60
61extern unsigned char virt_irq_alloc(unsigned int dev_handle,
62 unsigned int dev_ino);
63#ifdef CONFIG_PCI_MSI
64extern void virt_irq_free(unsigned int virt_irq);
65#endif
66
67extern void __init init_IRQ(void);
68extern void fixup_irqs(void);
69
70static inline void set_softint(unsigned long bits)
71{
72 __asm__ __volatile__("wr %0, 0x0, %%set_softint"
73 : /* No outputs */
74 : "r" (bits));
75}
76
77static inline void clear_softint(unsigned long bits)
78{
79 __asm__ __volatile__("wr %0, 0x0, %%clear_softint"
80 : /* No outputs */
81 : "r" (bits));
82}
83
84static inline unsigned long get_softint(void)
85{
86 unsigned long retval;
87
88 __asm__ __volatile__("rd %%softint, %0"
89 : "=r" (retval));
90 return retval;
91}
92
93#endif
diff --git a/include/asm-sparc/irqflags.h b/include/asm-sparc/irqflags.h
index db398fb32826..c6402b187e23 100644
--- a/include/asm-sparc/irqflags.h
+++ b/include/asm-sparc/irqflags.h
@@ -1,39 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_IRQFLAGS_H
2 * include/asm-sparc/irqflags.h 2#define ___ASM_SPARC_IRQFLAGS_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * IRQ flags handling 4#include <asm-sparc/irqflags_64.h>
5 * 5#else
6 * This file gets included from lowlevel asm headers too, to provide 6#include <asm-sparc/irqflags_32.h>
7 * wrapped versions of the local_irq_*() APIs, based on the 7#endif
8 * raw_local_irq_*() functions from the lowlevel headers. 8#endif
9 */
10#ifndef _ASM_IRQFLAGS_H
11#define _ASM_IRQFLAGS_H
12
13#ifndef __ASSEMBLY__
14
15extern void raw_local_irq_restore(unsigned long);
16extern unsigned long __raw_local_irq_save(void);
17extern void raw_local_irq_enable(void);
18
19static inline unsigned long getipl(void)
20{
21 unsigned long retval;
22
23 __asm__ __volatile__("rd %%psr, %0" : "=r" (retval));
24 return retval;
25}
26
27#define raw_local_save_flags(flags) ((flags) = getipl())
28#define raw_local_irq_save(flags) ((flags) = __raw_local_irq_save())
29#define raw_local_irq_disable() ((void) __raw_local_irq_save())
30#define raw_irqs_disabled() ((getipl() & PSR_PIL) != 0)
31
32static inline int raw_irqs_disabled_flags(unsigned long flags)
33{
34 return ((flags & PSR_PIL) != 0);
35}
36
37#endif /* (__ASSEMBLY__) */
38
39#endif /* !(_ASM_IRQFLAGS_H) */
diff --git a/include/asm-sparc/irqflags_32.h b/include/asm-sparc/irqflags_32.h
new file mode 100644
index 000000000000..db398fb32826
--- /dev/null
+++ b/include/asm-sparc/irqflags_32.h
@@ -0,0 +1,39 @@
1/*
2 * include/asm-sparc/irqflags.h
3 *
4 * IRQ flags handling
5 *
6 * This file gets included from lowlevel asm headers too, to provide
7 * wrapped versions of the local_irq_*() APIs, based on the
8 * raw_local_irq_*() functions from the lowlevel headers.
9 */
10#ifndef _ASM_IRQFLAGS_H
11#define _ASM_IRQFLAGS_H
12
13#ifndef __ASSEMBLY__
14
15extern void raw_local_irq_restore(unsigned long);
16extern unsigned long __raw_local_irq_save(void);
17extern void raw_local_irq_enable(void);
18
19static inline unsigned long getipl(void)
20{
21 unsigned long retval;
22
23 __asm__ __volatile__("rd %%psr, %0" : "=r" (retval));
24 return retval;
25}
26
27#define raw_local_save_flags(flags) ((flags) = getipl())
28#define raw_local_irq_save(flags) ((flags) = __raw_local_irq_save())
29#define raw_local_irq_disable() ((void) __raw_local_irq_save())
30#define raw_irqs_disabled() ((getipl() & PSR_PIL) != 0)
31
32static inline int raw_irqs_disabled_flags(unsigned long flags)
33{
34 return ((flags & PSR_PIL) != 0);
35}
36
37#endif /* (__ASSEMBLY__) */
38
39#endif /* !(_ASM_IRQFLAGS_H) */
diff --git a/include/asm-sparc/irqflags_64.h b/include/asm-sparc/irqflags_64.h
new file mode 100644
index 000000000000..024fc54d0682
--- /dev/null
+++ b/include/asm-sparc/irqflags_64.h
@@ -0,0 +1,89 @@
1/*
2 * include/asm-sparc64/irqflags.h
3 *
4 * IRQ flags handling
5 *
6 * This file gets included from lowlevel asm headers too, to provide
7 * wrapped versions of the local_irq_*() APIs, based on the
8 * raw_local_irq_*() functions from the lowlevel headers.
9 */
10#ifndef _ASM_IRQFLAGS_H
11#define _ASM_IRQFLAGS_H
12
13#ifndef __ASSEMBLY__
14
15static inline unsigned long __raw_local_save_flags(void)
16{
17 unsigned long flags;
18
19 __asm__ __volatile__(
20 "rdpr %%pil, %0"
21 : "=r" (flags)
22 );
23
24 return flags;
25}
26
27#define raw_local_save_flags(flags) \
28 do { (flags) = __raw_local_save_flags(); } while (0)
29
30static inline void raw_local_irq_restore(unsigned long flags)
31{
32 __asm__ __volatile__(
33 "wrpr %0, %%pil"
34 : /* no output */
35 : "r" (flags)
36 : "memory"
37 );
38}
39
40static inline void raw_local_irq_disable(void)
41{
42 __asm__ __volatile__(
43 "wrpr 15, %%pil"
44 : /* no outputs */
45 : /* no inputs */
46 : "memory"
47 );
48}
49
50static inline void raw_local_irq_enable(void)
51{
52 __asm__ __volatile__(
53 "wrpr 0, %%pil"
54 : /* no outputs */
55 : /* no inputs */
56 : "memory"
57 );
58}
59
60static inline int raw_irqs_disabled_flags(unsigned long flags)
61{
62 return (flags > 0);
63}
64
65static inline int raw_irqs_disabled(void)
66{
67 unsigned long flags = __raw_local_save_flags();
68
69 return raw_irqs_disabled_flags(flags);
70}
71
72/*
73 * For spinlocks, etc:
74 */
75static inline unsigned long __raw_local_irq_save(void)
76{
77 unsigned long flags = __raw_local_save_flags();
78
79 raw_local_irq_disable();
80
81 return flags;
82}
83
84#define raw_local_irq_save(flags) \
85 do { (flags) = __raw_local_irq_save(); } while (0)
86
87#endif /* (__ASSEMBLY__) */
88
89#endif /* !(_ASM_IRQFLAGS_H) */
diff --git a/include/asm-sparc/kdebug.h b/include/asm-sparc/kdebug.h
index f69fe7d84b3c..fe07d00d0534 100644
--- a/include/asm-sparc/kdebug.h
+++ b/include/asm-sparc/kdebug.h
@@ -1,73 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_KDEBUG_H
2 * kdebug.h: Defines and definitions for debugging the Linux kernel 2#define ___ASM_SPARC_KDEBUG_H
3 * under various kernel debuggers. 3#if defined(__sparc__) && defined(__arch64__)
4 * 4#include <asm-sparc/kdebug_64.h>
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 5#else
6 */ 6#include <asm-sparc/kdebug_32.h>
7#ifndef _SPARC_KDEBUG_H 7#endif
8#define _SPARC_KDEBUG_H 8#endif
9
10#include <asm/openprom.h>
11#include <asm/vaddrs.h>
12
13/* Breakpoints are enter through trap table entry 126. So in sparc assembly
14 * if you want to drop into the debugger you do:
15 *
16 * t DEBUG_BP_TRAP
17 */
18
19#define DEBUG_BP_TRAP 126
20
21#ifndef __ASSEMBLY__
22/* The debug vector is passed in %o1 at boot time. It is a pointer to
23 * a structure in the debuggers address space. Here is its format.
24 */
25
26typedef unsigned int (*debugger_funct)(void);
27
28struct kernel_debug {
29 /* First the entry point into the debugger. You jump here
30 * to give control over to the debugger.
31 */
32 unsigned long kdebug_entry;
33 unsigned long kdebug_trapme; /* Figure out later... */
34 /* The following is the number of pages that the debugger has
35 * taken from to total pool.
36 */
37 unsigned long *kdebug_stolen_pages;
38 /* Ok, after you remap yourself and/or change the trap table
39 * from what you were left with at boot time you have to call
40 * this synchronization function so the debugger can check out
41 * what you have done.
42 */
43 debugger_funct teach_debugger;
44}; /* I think that is it... */
45
46extern struct kernel_debug *linux_dbvec;
47
48/* Use this macro in C-code to enter the debugger. */
49static inline void sp_enter_debugger(void)
50{
51 __asm__ __volatile__("jmpl %0, %%o7\n\t"
52 "nop\n\t" : :
53 "r" (linux_dbvec) : "o7", "memory");
54}
55
56#define SP_ENTER_DEBUGGER do { \
57 if((linux_dbvec!=0) && ((*(short *)linux_dbvec)!=-1)) \
58 sp_enter_debugger(); \
59 } while(0)
60
61enum die_val {
62 DIE_UNUSED,
63};
64
65#endif /* !(__ASSEMBLY__) */
66
67/* Some nice offset defines for assembler code. */
68#define KDEBUG_ENTRY_OFF 0x0
69#define KDEBUG_DUNNO_OFF 0x4
70#define KDEBUG_DUNNO2_OFF 0x8
71#define KDEBUG_TEACH_OFF 0xc
72
73#endif /* !(_SPARC_KDEBUG_H) */
diff --git a/include/asm-sparc/kdebug_32.h b/include/asm-sparc/kdebug_32.h
new file mode 100644
index 000000000000..f69fe7d84b3c
--- /dev/null
+++ b/include/asm-sparc/kdebug_32.h
@@ -0,0 +1,73 @@
1/*
2 * kdebug.h: Defines and definitions for debugging the Linux kernel
3 * under various kernel debuggers.
4 *
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 */
7#ifndef _SPARC_KDEBUG_H
8#define _SPARC_KDEBUG_H
9
10#include <asm/openprom.h>
11#include <asm/vaddrs.h>
12
13/* Breakpoints are enter through trap table entry 126. So in sparc assembly
14 * if you want to drop into the debugger you do:
15 *
16 * t DEBUG_BP_TRAP
17 */
18
19#define DEBUG_BP_TRAP 126
20
21#ifndef __ASSEMBLY__
22/* The debug vector is passed in %o1 at boot time. It is a pointer to
23 * a structure in the debuggers address space. Here is its format.
24 */
25
26typedef unsigned int (*debugger_funct)(void);
27
28struct kernel_debug {
29 /* First the entry point into the debugger. You jump here
30 * to give control over to the debugger.
31 */
32 unsigned long kdebug_entry;
33 unsigned long kdebug_trapme; /* Figure out later... */
34 /* The following is the number of pages that the debugger has
35 * taken from to total pool.
36 */
37 unsigned long *kdebug_stolen_pages;
38 /* Ok, after you remap yourself and/or change the trap table
39 * from what you were left with at boot time you have to call
40 * this synchronization function so the debugger can check out
41 * what you have done.
42 */
43 debugger_funct teach_debugger;
44}; /* I think that is it... */
45
46extern struct kernel_debug *linux_dbvec;
47
48/* Use this macro in C-code to enter the debugger. */
49static inline void sp_enter_debugger(void)
50{
51 __asm__ __volatile__("jmpl %0, %%o7\n\t"
52 "nop\n\t" : :
53 "r" (linux_dbvec) : "o7", "memory");
54}
55
56#define SP_ENTER_DEBUGGER do { \
57 if((linux_dbvec!=0) && ((*(short *)linux_dbvec)!=-1)) \
58 sp_enter_debugger(); \
59 } while(0)
60
61enum die_val {
62 DIE_UNUSED,
63};
64
65#endif /* !(__ASSEMBLY__) */
66
67/* Some nice offset defines for assembler code. */
68#define KDEBUG_ENTRY_OFF 0x0
69#define KDEBUG_DUNNO_OFF 0x4
70#define KDEBUG_DUNNO2_OFF 0x8
71#define KDEBUG_TEACH_OFF 0xc
72
73#endif /* !(_SPARC_KDEBUG_H) */
diff --git a/include/asm-sparc/kdebug_64.h b/include/asm-sparc/kdebug_64.h
new file mode 100644
index 000000000000..f905b773235a
--- /dev/null
+++ b/include/asm-sparc/kdebug_64.h
@@ -0,0 +1,19 @@
1#ifndef _SPARC64_KDEBUG_H
2#define _SPARC64_KDEBUG_H
3
4struct pt_regs;
5
6extern void bad_trap(struct pt_regs *, long);
7
8/* Grossly misnamed. */
9enum die_val {
10 DIE_OOPS = 1,
11 DIE_DEBUG, /* ta 0x70 */
12 DIE_DEBUG_2, /* ta 0x71 */
13 DIE_DIE,
14 DIE_TRAP,
15 DIE_TRAP_TL1,
16 DIE_CALL,
17};
18
19#endif
diff --git a/include/asm-sparc/kmap_types.h b/include/asm-sparc/kmap_types.h
index e215f7104974..602f5e034f7a 100644
--- a/include/asm-sparc/kmap_types.h
+++ b/include/asm-sparc/kmap_types.h
@@ -1,6 +1,10 @@
1#ifndef _ASM_KMAP_TYPES_H 1#ifndef _ASM_KMAP_TYPES_H
2#define _ASM_KMAP_TYPES_H 2#define _ASM_KMAP_TYPES_H
3 3
4/* Dummy header just to define km_type. None of this
5 * is actually used on sparc. -DaveM
6 */
7
4enum km_type { 8enum km_type {
5 KM_BOUNCE_READ, 9 KM_BOUNCE_READ,
6 KM_SKB_SUNRPC_DATA, 10 KM_SKB_SUNRPC_DATA,
diff --git a/include/asm-sparc/kprobes.h b/include/asm-sparc/kprobes.h
new file mode 100644
index 000000000000..5879d71afdaa
--- /dev/null
+++ b/include/asm-sparc/kprobes.h
@@ -0,0 +1,49 @@
1#ifndef _SPARC64_KPROBES_H
2#define _SPARC64_KPROBES_H
3
4#include <linux/types.h>
5#include <linux/percpu.h>
6
7typedef u32 kprobe_opcode_t;
8
9#define BREAKPOINT_INSTRUCTION 0x91d02070 /* ta 0x70 */
10#define BREAKPOINT_INSTRUCTION_2 0x91d02071 /* ta 0x71 */
11#define MAX_INSN_SIZE 2
12
13#define kretprobe_blacklist_size 0
14
15#define arch_remove_kprobe(p) do {} while (0)
16
17#define flush_insn_slot(p) \
18do { flushi(&(p)->ainsn.insn[0]); \
19 flushi(&(p)->ainsn.insn[1]); \
20} while (0)
21
22void kretprobe_trampoline(void);
23
24/* Architecture specific copy of original instruction*/
25struct arch_specific_insn {
26 /* copy of the original instruction */
27 kprobe_opcode_t insn[MAX_INSN_SIZE];
28};
29
30struct prev_kprobe {
31 struct kprobe *kp;
32 unsigned long status;
33 unsigned long orig_tnpc;
34 unsigned long orig_tstate_pil;
35};
36
37/* per-cpu kprobe control block */
38struct kprobe_ctlblk {
39 unsigned long kprobe_status;
40 unsigned long kprobe_orig_tnpc;
41 unsigned long kprobe_orig_tstate_pil;
42 struct pt_regs jprobe_saved_regs;
43 struct prev_kprobe prev_kprobe;
44};
45
46extern int kprobe_exceptions_notify(struct notifier_block *self,
47 unsigned long val, void *data);
48extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
49#endif /* _SPARC64_KPROBES_H */
diff --git a/include/asm-sparc/ldc.h b/include/asm-sparc/ldc.h
new file mode 100644
index 000000000000..bdb524a7b814
--- /dev/null
+++ b/include/asm-sparc/ldc.h
@@ -0,0 +1,138 @@
1#ifndef _SPARC64_LDC_H
2#define _SPARC64_LDC_H
3
4#include <asm/hypervisor.h>
5
6extern int ldom_domaining_enabled;
7extern void ldom_set_var(const char *var, const char *value);
8extern void ldom_reboot(const char *boot_command);
9extern void ldom_power_off(void);
10
11/* The event handler will be evoked when link state changes
12 * or data becomes available on the receive side.
13 *
14 * For non-RAW links, if the LDC_EVENT_RESET event arrives the
15 * driver should reset all of it's internal state and reinvoke
16 * ldc_connect() to try and bring the link up again.
17 *
18 * For RAW links, ldc_connect() is not used. Instead the driver
19 * just waits for the LDC_EVENT_UP event.
20 */
21struct ldc_channel_config {
22 void (*event)(void *arg, int event);
23
24 u32 mtu;
25 unsigned int rx_irq;
26 unsigned int tx_irq;
27 u8 mode;
28#define LDC_MODE_RAW 0x00
29#define LDC_MODE_UNRELIABLE 0x01
30#define LDC_MODE_RESERVED 0x02
31#define LDC_MODE_STREAM 0x03
32
33 u8 debug;
34#define LDC_DEBUG_HS 0x01
35#define LDC_DEBUG_STATE 0x02
36#define LDC_DEBUG_RX 0x04
37#define LDC_DEBUG_TX 0x08
38#define LDC_DEBUG_DATA 0x10
39};
40
41#define LDC_EVENT_RESET 0x01
42#define LDC_EVENT_UP 0x02
43#define LDC_EVENT_DATA_READY 0x04
44
45#define LDC_STATE_INVALID 0x00
46#define LDC_STATE_INIT 0x01
47#define LDC_STATE_BOUND 0x02
48#define LDC_STATE_READY 0x03
49#define LDC_STATE_CONNECTED 0x04
50
51struct ldc_channel;
52
53/* Allocate state for a channel. */
54extern struct ldc_channel *ldc_alloc(unsigned long id,
55 const struct ldc_channel_config *cfgp,
56 void *event_arg);
57
58/* Shut down and free state for a channel. */
59extern void ldc_free(struct ldc_channel *lp);
60
61/* Register TX and RX queues of the link with the hypervisor. */
62extern int ldc_bind(struct ldc_channel *lp, const char *name);
63
64/* For non-RAW protocols we need to complete a handshake before
65 * communication can proceed. ldc_connect() does that, if the
66 * handshake completes successfully, an LDC_EVENT_UP event will
67 * be sent up to the driver.
68 */
69extern int ldc_connect(struct ldc_channel *lp);
70extern int ldc_disconnect(struct ldc_channel *lp);
71
72extern int ldc_state(struct ldc_channel *lp);
73
74/* Read and write operations. Only valid when the link is up. */
75extern int ldc_write(struct ldc_channel *lp, const void *buf,
76 unsigned int size);
77extern int ldc_read(struct ldc_channel *lp, void *buf, unsigned int size);
78
79#define LDC_MAP_SHADOW 0x01
80#define LDC_MAP_DIRECT 0x02
81#define LDC_MAP_IO 0x04
82#define LDC_MAP_R 0x08
83#define LDC_MAP_W 0x10
84#define LDC_MAP_X 0x20
85#define LDC_MAP_RW (LDC_MAP_R | LDC_MAP_W)
86#define LDC_MAP_RWX (LDC_MAP_R | LDC_MAP_W | LDC_MAP_X)
87#define LDC_MAP_ALL 0x03f
88
89struct ldc_trans_cookie {
90 u64 cookie_addr;
91 u64 cookie_size;
92};
93
94struct scatterlist;
95extern int ldc_map_sg(struct ldc_channel *lp,
96 struct scatterlist *sg, int num_sg,
97 struct ldc_trans_cookie *cookies, int ncookies,
98 unsigned int map_perm);
99
100extern int ldc_map_single(struct ldc_channel *lp,
101 void *buf, unsigned int len,
102 struct ldc_trans_cookie *cookies, int ncookies,
103 unsigned int map_perm);
104
105extern void ldc_unmap(struct ldc_channel *lp, struct ldc_trans_cookie *cookies,
106 int ncookies);
107
108extern int ldc_copy(struct ldc_channel *lp, int copy_dir,
109 void *buf, unsigned int len, unsigned long offset,
110 struct ldc_trans_cookie *cookies, int ncookies);
111
112static inline int ldc_get_dring_entry(struct ldc_channel *lp,
113 void *buf, unsigned int len,
114 unsigned long offset,
115 struct ldc_trans_cookie *cookies,
116 int ncookies)
117{
118 return ldc_copy(lp, LDC_COPY_IN, buf, len, offset, cookies, ncookies);
119}
120
121static inline int ldc_put_dring_entry(struct ldc_channel *lp,
122 void *buf, unsigned int len,
123 unsigned long offset,
124 struct ldc_trans_cookie *cookies,
125 int ncookies)
126{
127 return ldc_copy(lp, LDC_COPY_OUT, buf, len, offset, cookies, ncookies);
128}
129
130extern void *ldc_alloc_exp_dring(struct ldc_channel *lp, unsigned int len,
131 struct ldc_trans_cookie *cookies,
132 int *ncookies, unsigned int map_perm);
133
134extern void ldc_free_exp_dring(struct ldc_channel *lp, void *buf,
135 unsigned int len,
136 struct ldc_trans_cookie *cookies, int ncookies);
137
138#endif /* _SPARC64_LDC_H */
diff --git a/include/asm-sparc/lmb.h b/include/asm-sparc/lmb.h
new file mode 100644
index 000000000000..6a352cbcf520
--- /dev/null
+++ b/include/asm-sparc/lmb.h
@@ -0,0 +1,10 @@
1#ifndef _SPARC64_LMB_H
2#define _SPARC64_LMB_H
3
4#include <asm/oplib.h>
5
6#define LMB_DBG(fmt...) prom_printf(fmt)
7
8#define LMB_REAL_LIMIT 0
9
10#endif /* !(_SPARC64_LMB_H) */
diff --git a/include/asm-sparc/lsu.h b/include/asm-sparc/lsu.h
new file mode 100644
index 000000000000..7190f8de90a0
--- /dev/null
+++ b/include/asm-sparc/lsu.h
@@ -0,0 +1,19 @@
1#ifndef _SPARC64_LSU_H
2#define _SPARC64_LSU_H
3
4#include <linux/const.h>
5
6/* LSU Control Register */
7#define LSU_CONTROL_PM _AC(0x000001fe00000000,UL) /* Phys-watchpoint byte mask*/
8#define LSU_CONTROL_VM _AC(0x00000001fe000000,UL) /* Virt-watchpoint byte mask*/
9#define LSU_CONTROL_PR _AC(0x0000000001000000,UL) /* Phys-rd watchpoint enable*/
10#define LSU_CONTROL_PW _AC(0x0000000000800000,UL) /* Phys-wr watchpoint enable*/
11#define LSU_CONTROL_VR _AC(0x0000000000400000,UL) /* Virt-rd watchpoint enable*/
12#define LSU_CONTROL_VW _AC(0x0000000000200000,UL) /* Virt-wr watchpoint enable*/
13#define LSU_CONTROL_FM _AC(0x00000000000ffff0,UL) /* Parity mask enables. */
14#define LSU_CONTROL_DM _AC(0x0000000000000008,UL) /* Data MMU enable. */
15#define LSU_CONTROL_IM _AC(0x0000000000000004,UL) /* Instruction MMU enable. */
16#define LSU_CONTROL_DC _AC(0x0000000000000002,UL) /* Data cache enable. */
17#define LSU_CONTROL_IC _AC(0x0000000000000001,UL) /* Instruction cache enable.*/
18
19#endif /* !(_SPARC64_LSU_H) */
diff --git a/include/asm-sparc/machines.h b/include/asm-sparc/machines.h
index d6c6bf836206..c28c2f248794 100644
--- a/include/asm-sparc/machines.h
+++ b/include/asm-sparc/machines.h
@@ -17,8 +17,6 @@ struct Sun_Machine_Models {
17 */ 17 */
18#define NUM_SUN_MACHINES 15 18#define NUM_SUN_MACHINES 15
19 19
20extern struct Sun_Machine_Models Sun_Machines[NUM_SUN_MACHINES];
21
22/* The machine type in the idprom area looks like this: 20/* The machine type in the idprom area looks like this:
23 * 21 *
24 * --------------- 22 * ---------------
diff --git a/include/asm-sparc/mbus.h b/include/asm-sparc/mbus.h
index bb5ae614b166..69f07a022ee6 100644
--- a/include/asm-sparc/mbus.h
+++ b/include/asm-sparc/mbus.h
@@ -43,8 +43,6 @@ extern unsigned int viking_rev, swift_rev, cypress_rev;
43#define HWBUG_SUPERSCALAR_BAD 0x00000080 43#define HWBUG_SUPERSCALAR_BAD 0x00000080
44#define HWBUG_PACINIT_BITROT 0x00000100 44#define HWBUG_PACINIT_BITROT 0x00000100
45 45
46extern unsigned int hwbug_bitmask;
47
48/* First the module type values. To find out which you have, just load 46/* First the module type values. To find out which you have, just load
49 * the mmu control register from ASI_M_MMUREG alternate address space and 47 * the mmu control register from ASI_M_MMUREG alternate address space and
50 * shift the value right 28 bits. 48 * shift the value right 28 bits.
diff --git a/include/asm-sparc/mc146818rtc.h b/include/asm-sparc/mc146818rtc.h
index fa7eac926582..9ab65c21e9e4 100644
--- a/include/asm-sparc/mc146818rtc.h
+++ b/include/asm-sparc/mc146818rtc.h
@@ -1,29 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_MC146818RTC_H
2 * Machine dependent access functions for RTC registers. 2#define ___ASM_SPARC_MC146818RTC_H
3 */ 3#if defined(__sparc__) && defined(__arch64__)
4#ifndef __ASM_SPARC_MC146818RTC_H 4#include <asm-sparc/mc146818rtc_64.h>
5#define __ASM_SPARC_MC146818RTC_H 5#else
6 6#include <asm-sparc/mc146818rtc_32.h>
7#include <asm/io.h> 7#endif
8
9#ifndef RTC_PORT
10#define RTC_PORT(x) (0x70 + (x))
11#define RTC_ALWAYS_BCD 1 /* RTC operates in binary mode */
12#endif 8#endif
13
14/*
15 * The yet supported machines all access the RTC index register via
16 * an ISA port access but the way to access the date register differs ...
17 */
18#define CMOS_READ(addr) ({ \
19outb_p((addr),RTC_PORT(0)); \
20inb_p(RTC_PORT(1)); \
21})
22#define CMOS_WRITE(val, addr) ({ \
23outb_p((addr),RTC_PORT(0)); \
24outb_p((val),RTC_PORT(1)); \
25})
26
27#define RTC_IRQ 8
28
29#endif /* __ASM_SPARC_MC146818RTC_H */
diff --git a/include/asm-sparc/mc146818rtc_32.h b/include/asm-sparc/mc146818rtc_32.h
new file mode 100644
index 000000000000..fa7eac926582
--- /dev/null
+++ b/include/asm-sparc/mc146818rtc_32.h
@@ -0,0 +1,29 @@
1/*
2 * Machine dependent access functions for RTC registers.
3 */
4#ifndef __ASM_SPARC_MC146818RTC_H
5#define __ASM_SPARC_MC146818RTC_H
6
7#include <asm/io.h>
8
9#ifndef RTC_PORT
10#define RTC_PORT(x) (0x70 + (x))
11#define RTC_ALWAYS_BCD 1 /* RTC operates in binary mode */
12#endif
13
14/*
15 * The yet supported machines all access the RTC index register via
16 * an ISA port access but the way to access the date register differs ...
17 */
18#define CMOS_READ(addr) ({ \
19outb_p((addr),RTC_PORT(0)); \
20inb_p(RTC_PORT(1)); \
21})
22#define CMOS_WRITE(val, addr) ({ \
23outb_p((addr),RTC_PORT(0)); \
24outb_p((val),RTC_PORT(1)); \
25})
26
27#define RTC_IRQ 8
28
29#endif /* __ASM_SPARC_MC146818RTC_H */
diff --git a/include/asm-sparc/mc146818rtc_64.h b/include/asm-sparc/mc146818rtc_64.h
new file mode 100644
index 000000000000..e9c0fcc25c6f
--- /dev/null
+++ b/include/asm-sparc/mc146818rtc_64.h
@@ -0,0 +1,34 @@
1/*
2 * Machine dependent access functions for RTC registers.
3 */
4#ifndef __ASM_SPARC64_MC146818RTC_H
5#define __ASM_SPARC64_MC146818RTC_H
6
7#include <asm/io.h>
8
9#ifndef RTC_PORT
10#ifdef CONFIG_PCI
11extern unsigned long ds1287_regs;
12#else
13#define ds1287_regs (0UL)
14#endif
15#define RTC_PORT(x) (ds1287_regs + (x))
16#define RTC_ALWAYS_BCD 0
17#endif
18
19/*
20 * The yet supported machines all access the RTC index register via
21 * an ISA port access but the way to access the date register differs ...
22 */
23#define CMOS_READ(addr) ({ \
24outb_p((addr),RTC_PORT(0)); \
25inb_p(RTC_PORT(1)); \
26})
27#define CMOS_WRITE(val, addr) ({ \
28outb_p((addr),RTC_PORT(0)); \
29outb_p((val),RTC_PORT(1)); \
30})
31
32#define RTC_IRQ 8
33
34#endif /* __ASM_SPARC64_MC146818RTC_H */
diff --git a/include/asm-sparc/mdesc.h b/include/asm-sparc/mdesc.h
new file mode 100644
index 000000000000..1acc7272e537
--- /dev/null
+++ b/include/asm-sparc/mdesc.h
@@ -0,0 +1,78 @@
1#ifndef _SPARC64_MDESC_H
2#define _SPARC64_MDESC_H
3
4#include <linux/types.h>
5#include <linux/cpumask.h>
6#include <asm/prom.h>
7
8struct mdesc_handle;
9
10/* Machine description operations are to be surrounded by grab and
11 * release calls. The mdesc_handle returned from the grab is
12 * the first argument to all of the operational calls that work
13 * on mdescs.
14 */
15extern struct mdesc_handle *mdesc_grab(void);
16extern void mdesc_release(struct mdesc_handle *);
17
18#define MDESC_NODE_NULL (~(u64)0)
19
20extern u64 mdesc_node_by_name(struct mdesc_handle *handle,
21 u64 from_node, const char *name);
22#define mdesc_for_each_node_by_name(__hdl, __node, __name) \
23 for (__node = mdesc_node_by_name(__hdl, MDESC_NODE_NULL, __name); \
24 (__node) != MDESC_NODE_NULL; \
25 __node = mdesc_node_by_name(__hdl, __node, __name))
26
27/* Access to property values returned from mdesc_get_property() are
28 * only valid inside of a mdesc_grab()/mdesc_release() sequence.
29 * Once mdesc_release() is called, the memory backed up by these
30 * pointers may reference freed up memory.
31 *
32 * Therefore callers must make copies of any property values
33 * they need.
34 *
35 * These same rules apply to mdesc_node_name().
36 */
37extern const void *mdesc_get_property(struct mdesc_handle *handle,
38 u64 node, const char *name, int *lenp);
39extern const char *mdesc_node_name(struct mdesc_handle *hp, u64 node);
40
41/* MD arc iteration, the standard sequence is:
42 *
43 * unsigned long arc;
44 * mdesc_for_each_arc(arc, handle, node, MDESC_ARC_TYPE_{FWD,BACK}) {
45 * unsigned long target = mdesc_arc_target(handle, arc);
46 * ...
47 * }
48 */
49
50#define MDESC_ARC_TYPE_FWD "fwd"
51#define MDESC_ARC_TYPE_BACK "back"
52
53extern u64 mdesc_next_arc(struct mdesc_handle *handle, u64 from,
54 const char *arc_type);
55#define mdesc_for_each_arc(__arc, __hdl, __node, __type) \
56 for (__arc = mdesc_next_arc(__hdl, __node, __type); \
57 (__arc) != MDESC_NODE_NULL; \
58 __arc = mdesc_next_arc(__hdl, __arc, __type))
59
60extern u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc);
61
62extern void mdesc_update(void);
63
64struct mdesc_notifier_client {
65 void (*add)(struct mdesc_handle *handle, u64 node);
66 void (*remove)(struct mdesc_handle *handle, u64 node);
67
68 const char *node_name;
69 struct mdesc_notifier_client *next;
70};
71
72extern void mdesc_register_notifier(struct mdesc_notifier_client *client);
73
74extern void mdesc_fill_in_cpu_data(cpumask_t mask);
75
76extern void sun4v_mdesc_init(void);
77
78#endif
diff --git a/include/asm-sparc/mmu.h b/include/asm-sparc/mmu.h
index ccd36d26615a..ee66bf6dcbd6 100644
--- a/include/asm-sparc/mmu.h
+++ b/include/asm-sparc/mmu.h
@@ -1,7 +1,8 @@
1#ifndef __MMU_H 1#ifndef ___ASM_SPARC_MMU_H
2#define __MMU_H 2#define ___ASM_SPARC_MMU_H
3 3#if defined(__sparc__) && defined(__arch64__)
4/* Default "unsigned long" context */ 4#include <asm-sparc/mmu_64.h>
5typedef unsigned long mm_context_t; 5#else
6 6#include <asm-sparc/mmu_32.h>
7#endif
7#endif 8#endif
diff --git a/include/asm-sparc/mmu_32.h b/include/asm-sparc/mmu_32.h
new file mode 100644
index 000000000000..ccd36d26615a
--- /dev/null
+++ b/include/asm-sparc/mmu_32.h
@@ -0,0 +1,7 @@
1#ifndef __MMU_H
2#define __MMU_H
3
4/* Default "unsigned long" context */
5typedef unsigned long mm_context_t;
6
7#endif
diff --git a/include/asm-sparc/mmu_64.h b/include/asm-sparc/mmu_64.h
new file mode 100644
index 000000000000..9067dc500535
--- /dev/null
+++ b/include/asm-sparc/mmu_64.h
@@ -0,0 +1,123 @@
1#ifndef __MMU_H
2#define __MMU_H
3
4#include <linux/const.h>
5#include <asm/page.h>
6#include <asm/hypervisor.h>
7
8#define CTX_NR_BITS 13
9
10#define TAG_CONTEXT_BITS ((_AC(1,UL) << CTX_NR_BITS) - _AC(1,UL))
11
12/* UltraSPARC-III+ and later have a feature whereby you can
13 * select what page size the various Data-TLB instances in the
14 * chip. In order to gracefully support this, we put the version
15 * field in a spot outside of the areas of the context register
16 * where this parameter is specified.
17 */
18#define CTX_VERSION_SHIFT 22
19#define CTX_VERSION_MASK ((~0UL) << CTX_VERSION_SHIFT)
20
21#define CTX_PGSZ_8KB _AC(0x0,UL)
22#define CTX_PGSZ_64KB _AC(0x1,UL)
23#define CTX_PGSZ_512KB _AC(0x2,UL)
24#define CTX_PGSZ_4MB _AC(0x3,UL)
25#define CTX_PGSZ_BITS _AC(0x7,UL)
26#define CTX_PGSZ0_NUC_SHIFT 61
27#define CTX_PGSZ1_NUC_SHIFT 58
28#define CTX_PGSZ0_SHIFT 16
29#define CTX_PGSZ1_SHIFT 19
30#define CTX_PGSZ_MASK ((CTX_PGSZ_BITS << CTX_PGSZ0_SHIFT) | \
31 (CTX_PGSZ_BITS << CTX_PGSZ1_SHIFT))
32
33#if defined(CONFIG_SPARC64_PAGE_SIZE_8KB)
34#define CTX_PGSZ_BASE CTX_PGSZ_8KB
35#elif defined(CONFIG_SPARC64_PAGE_SIZE_64KB)
36#define CTX_PGSZ_BASE CTX_PGSZ_64KB
37#else
38#error No page size specified in kernel configuration
39#endif
40
41#if defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
42#define CTX_PGSZ_HUGE CTX_PGSZ_4MB
43#elif defined(CONFIG_HUGETLB_PAGE_SIZE_512K)
44#define CTX_PGSZ_HUGE CTX_PGSZ_512KB
45#elif defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
46#define CTX_PGSZ_HUGE CTX_PGSZ_64KB
47#endif
48
49#define CTX_PGSZ_KERN CTX_PGSZ_4MB
50
51/* Thus, when running on UltraSPARC-III+ and later, we use the following
52 * PRIMARY_CONTEXT register values for the kernel context.
53 */
54#define CTX_CHEETAH_PLUS_NUC \
55 ((CTX_PGSZ_KERN << CTX_PGSZ0_NUC_SHIFT) | \
56 (CTX_PGSZ_BASE << CTX_PGSZ1_NUC_SHIFT))
57
58#define CTX_CHEETAH_PLUS_CTX0 \
59 ((CTX_PGSZ_KERN << CTX_PGSZ0_SHIFT) | \
60 (CTX_PGSZ_BASE << CTX_PGSZ1_SHIFT))
61
62/* If you want "the TLB context number" use CTX_NR_MASK. If you
63 * want "the bits I program into the context registers" use
64 * CTX_HW_MASK.
65 */
66#define CTX_NR_MASK TAG_CONTEXT_BITS
67#define CTX_HW_MASK (CTX_NR_MASK | CTX_PGSZ_MASK)
68
69#define CTX_FIRST_VERSION ((_AC(1,UL) << CTX_VERSION_SHIFT) + _AC(1,UL))
70#define CTX_VALID(__ctx) \
71 (!(((__ctx.sparc64_ctx_val) ^ tlb_context_cache) & CTX_VERSION_MASK))
72#define CTX_HWBITS(__ctx) ((__ctx.sparc64_ctx_val) & CTX_HW_MASK)
73#define CTX_NRBITS(__ctx) ((__ctx.sparc64_ctx_val) & CTX_NR_MASK)
74
75#ifndef __ASSEMBLY__
76
77#define TSB_ENTRY_ALIGNMENT 16
78
79struct tsb {
80 unsigned long tag;
81 unsigned long pte;
82} __attribute__((aligned(TSB_ENTRY_ALIGNMENT)));
83
84extern void __tsb_insert(unsigned long ent, unsigned long tag, unsigned long pte);
85extern void tsb_flush(unsigned long ent, unsigned long tag);
86extern void tsb_init(struct tsb *tsb, unsigned long size);
87
88struct tsb_config {
89 struct tsb *tsb;
90 unsigned long tsb_rss_limit;
91 unsigned long tsb_nentries;
92 unsigned long tsb_reg_val;
93 unsigned long tsb_map_vaddr;
94 unsigned long tsb_map_pte;
95};
96
97#define MM_TSB_BASE 0
98
99#ifdef CONFIG_HUGETLB_PAGE
100#define MM_TSB_HUGE 1
101#define MM_NUM_TSBS 2
102#else
103#define MM_NUM_TSBS 1
104#endif
105
106typedef struct {
107 spinlock_t lock;
108 unsigned long sparc64_ctx_val;
109 unsigned long huge_pte_count;
110 struct tsb_config tsb_block[MM_NUM_TSBS];
111 struct hv_tsb_descr tsb_descr[MM_NUM_TSBS];
112} mm_context_t;
113
114#endif /* !__ASSEMBLY__ */
115
116#define TSB_CONFIG_TSB 0x00
117#define TSB_CONFIG_RSS_LIMIT 0x08
118#define TSB_CONFIG_NENTRIES 0x10
119#define TSB_CONFIG_REG_VAL 0x18
120#define TSB_CONFIG_MAP_VADDR 0x20
121#define TSB_CONFIG_MAP_PTE 0x28
122
123#endif /* __MMU_H */
diff --git a/include/asm-sparc/mmu_context.h b/include/asm-sparc/mmu_context.h
index 671a997b9e69..e14efb9532ff 100644
--- a/include/asm-sparc/mmu_context.h
+++ b/include/asm-sparc/mmu_context.h
@@ -1,42 +1,8 @@
1#ifndef __SPARC_MMU_CONTEXT_H 1#ifndef ___ASM_SPARC_MMU_CONTEXT_H
2#define __SPARC_MMU_CONTEXT_H 2#define ___ASM_SPARC_MMU_CONTEXT_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <asm/btfixup.h> 4#include <asm-sparc/mmu_context_64.h>
5 5#else
6#ifndef __ASSEMBLY__ 6#include <asm-sparc/mmu_context_32.h>
7 7#endif
8#include <asm-generic/mm_hooks.h> 8#endif
9
10static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11{
12}
13
14/*
15 * Initialize a new mmu context. This is invoked when a new
16 * address space instance (unique or shared) is instantiated.
17 */
18#define init_new_context(tsk, mm) (((mm)->context = NO_CONTEXT), 0)
19
20/*
21 * Destroy a dead context. This occurs when mmput drops the
22 * mm_users count to zero, the mmaps have been released, and
23 * all the page tables have been flushed. Our job is to destroy
24 * any remaining processor-specific state.
25 */
26BTFIXUPDEF_CALL(void, destroy_context, struct mm_struct *)
27
28#define destroy_context(mm) BTFIXUP_CALL(destroy_context)(mm)
29
30/* Switch the current MM context. */
31BTFIXUPDEF_CALL(void, switch_mm, struct mm_struct *, struct mm_struct *, struct task_struct *)
32
33#define switch_mm(old_mm, mm, tsk) BTFIXUP_CALL(switch_mm)(old_mm, mm, tsk)
34
35#define deactivate_mm(tsk,mm) do { } while (0)
36
37/* Activate a new MM instance for the current task. */
38#define activate_mm(active_mm, mm) switch_mm((active_mm), (mm), NULL)
39
40#endif /* !(__ASSEMBLY__) */
41
42#endif /* !(__SPARC_MMU_CONTEXT_H) */
diff --git a/include/asm-sparc/mmu_context_32.h b/include/asm-sparc/mmu_context_32.h
new file mode 100644
index 000000000000..671a997b9e69
--- /dev/null
+++ b/include/asm-sparc/mmu_context_32.h
@@ -0,0 +1,42 @@
1#ifndef __SPARC_MMU_CONTEXT_H
2#define __SPARC_MMU_CONTEXT_H
3
4#include <asm/btfixup.h>
5
6#ifndef __ASSEMBLY__
7
8#include <asm-generic/mm_hooks.h>
9
10static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11{
12}
13
14/*
15 * Initialize a new mmu context. This is invoked when a new
16 * address space instance (unique or shared) is instantiated.
17 */
18#define init_new_context(tsk, mm) (((mm)->context = NO_CONTEXT), 0)
19
20/*
21 * Destroy a dead context. This occurs when mmput drops the
22 * mm_users count to zero, the mmaps have been released, and
23 * all the page tables have been flushed. Our job is to destroy
24 * any remaining processor-specific state.
25 */
26BTFIXUPDEF_CALL(void, destroy_context, struct mm_struct *)
27
28#define destroy_context(mm) BTFIXUP_CALL(destroy_context)(mm)
29
30/* Switch the current MM context. */
31BTFIXUPDEF_CALL(void, switch_mm, struct mm_struct *, struct mm_struct *, struct task_struct *)
32
33#define switch_mm(old_mm, mm, tsk) BTFIXUP_CALL(switch_mm)(old_mm, mm, tsk)
34
35#define deactivate_mm(tsk,mm) do { } while (0)
36
37/* Activate a new MM instance for the current task. */
38#define activate_mm(active_mm, mm) switch_mm((active_mm), (mm), NULL)
39
40#endif /* !(__ASSEMBLY__) */
41
42#endif /* !(__SPARC_MMU_CONTEXT_H) */
diff --git a/include/asm-sparc/mmu_context_64.h b/include/asm-sparc/mmu_context_64.h
new file mode 100644
index 000000000000..5693ab482606
--- /dev/null
+++ b/include/asm-sparc/mmu_context_64.h
@@ -0,0 +1,155 @@
1#ifndef __SPARC64_MMU_CONTEXT_H
2#define __SPARC64_MMU_CONTEXT_H
3
4/* Derived heavily from Linus's Alpha/AXP ASN code... */
5
6#ifndef __ASSEMBLY__
7
8#include <linux/spinlock.h>
9#include <asm/system.h>
10#include <asm/spitfire.h>
11#include <asm-generic/mm_hooks.h>
12
13static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
14{
15}
16
17extern spinlock_t ctx_alloc_lock;
18extern unsigned long tlb_context_cache;
19extern unsigned long mmu_context_bmap[];
20
21extern void get_new_mmu_context(struct mm_struct *mm);
22#ifdef CONFIG_SMP
23extern void smp_new_mmu_context_version(void);
24#else
25#define smp_new_mmu_context_version() do { } while (0)
26#endif
27
28extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
29extern void destroy_context(struct mm_struct *mm);
30
31extern void __tsb_context_switch(unsigned long pgd_pa,
32 struct tsb_config *tsb_base,
33 struct tsb_config *tsb_huge,
34 unsigned long tsb_descr_pa);
35
36static inline void tsb_context_switch(struct mm_struct *mm)
37{
38 __tsb_context_switch(__pa(mm->pgd),
39 &mm->context.tsb_block[0],
40#ifdef CONFIG_HUGETLB_PAGE
41 (mm->context.tsb_block[1].tsb ?
42 &mm->context.tsb_block[1] :
43 NULL)
44#else
45 NULL
46#endif
47 , __pa(&mm->context.tsb_descr[0]));
48}
49
50extern void tsb_grow(struct mm_struct *mm, unsigned long tsb_index, unsigned long mm_rss);
51#ifdef CONFIG_SMP
52extern void smp_tsb_sync(struct mm_struct *mm);
53#else
54#define smp_tsb_sync(__mm) do { } while (0)
55#endif
56
57/* Set MMU context in the actual hardware. */
58#define load_secondary_context(__mm) \
59 __asm__ __volatile__( \
60 "\n661: stxa %0, [%1] %2\n" \
61 " .section .sun4v_1insn_patch, \"ax\"\n" \
62 " .word 661b\n" \
63 " stxa %0, [%1] %3\n" \
64 " .previous\n" \
65 " flush %%g6\n" \
66 : /* No outputs */ \
67 : "r" (CTX_HWBITS((__mm)->context)), \
68 "r" (SECONDARY_CONTEXT), "i" (ASI_DMMU), "i" (ASI_MMU))
69
70extern void __flush_tlb_mm(unsigned long, unsigned long);
71
72/* Switch the current MM context. Interrupts are disabled. */
73static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk)
74{
75 unsigned long ctx_valid, flags;
76 int cpu;
77
78 if (unlikely(mm == &init_mm))
79 return;
80
81 spin_lock_irqsave(&mm->context.lock, flags);
82 ctx_valid = CTX_VALID(mm->context);
83 if (!ctx_valid)
84 get_new_mmu_context(mm);
85
86 /* We have to be extremely careful here or else we will miss
87 * a TSB grow if we switch back and forth between a kernel
88 * thread and an address space which has it's TSB size increased
89 * on another processor.
90 *
91 * It is possible to play some games in order to optimize the
92 * switch, but the safest thing to do is to unconditionally
93 * perform the secondary context load and the TSB context switch.
94 *
95 * For reference the bad case is, for address space "A":
96 *
97 * CPU 0 CPU 1
98 * run address space A
99 * set cpu0's bits in cpu_vm_mask
100 * switch to kernel thread, borrow
101 * address space A via entry_lazy_tlb
102 * run address space A
103 * set cpu1's bit in cpu_vm_mask
104 * flush_tlb_pending()
105 * reset cpu_vm_mask to just cpu1
106 * TSB grow
107 * run address space A
108 * context was valid, so skip
109 * TSB context switch
110 *
111 * At that point cpu0 continues to use a stale TSB, the one from
112 * before the TSB grow performed on cpu1. cpu1 did not cross-call
113 * cpu0 to update it's TSB because at that point the cpu_vm_mask
114 * only had cpu1 set in it.
115 */
116 load_secondary_context(mm);
117 tsb_context_switch(mm);
118
119 /* Any time a processor runs a context on an address space
120 * for the first time, we must flush that context out of the
121 * local TLB.
122 */
123 cpu = smp_processor_id();
124 if (!ctx_valid || !cpu_isset(cpu, mm->cpu_vm_mask)) {
125 cpu_set(cpu, mm->cpu_vm_mask);
126 __flush_tlb_mm(CTX_HWBITS(mm->context),
127 SECONDARY_CONTEXT);
128 }
129 spin_unlock_irqrestore(&mm->context.lock, flags);
130}
131
132#define deactivate_mm(tsk,mm) do { } while (0)
133
134/* Activate a new MM instance for the current task. */
135static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm)
136{
137 unsigned long flags;
138 int cpu;
139
140 spin_lock_irqsave(&mm->context.lock, flags);
141 if (!CTX_VALID(mm->context))
142 get_new_mmu_context(mm);
143 cpu = smp_processor_id();
144 if (!cpu_isset(cpu, mm->cpu_vm_mask))
145 cpu_set(cpu, mm->cpu_vm_mask);
146
147 load_secondary_context(mm);
148 __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT);
149 tsb_context_switch(mm);
150 spin_unlock_irqrestore(&mm->context.lock, flags);
151}
152
153#endif /* !(__ASSEMBLY__) */
154
155#endif /* !(__SPARC64_MMU_CONTEXT_H) */
diff --git a/include/asm-sparc/mmzone.h b/include/asm-sparc/mmzone.h
new file mode 100644
index 000000000000..ebf5986c12ed
--- /dev/null
+++ b/include/asm-sparc/mmzone.h
@@ -0,0 +1,17 @@
1#ifndef _SPARC64_MMZONE_H
2#define _SPARC64_MMZONE_H
3
4#ifdef CONFIG_NEED_MULTIPLE_NODES
5
6extern struct pglist_data *node_data[];
7
8#define NODE_DATA(nid) (node_data[nid])
9#define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
10#define node_end_pfn(nid) (NODE_DATA(nid)->node_end_pfn)
11
12extern int numa_cpu_lookup_table[];
13extern cpumask_t numa_cpumask_lookup_table[];
14
15#endif /* CONFIG_NEED_MULTIPLE_NODES */
16
17#endif /* _SPARC64_MMZONE_H */
diff --git a/include/asm-sparc/module.h b/include/asm-sparc/module.h
index cbd9e67b0c0b..516138fe681a 100644
--- a/include/asm-sparc/module.h
+++ b/include/asm-sparc/module.h
@@ -1,7 +1,8 @@
1#ifndef _ASM_SPARC_MODULE_H 1#ifndef ___ASM_SPARC_MODULE_H
2#define _ASM_SPARC_MODULE_H 2#define ___ASM_SPARC_MODULE_H
3struct mod_arch_specific { }; 3#if defined(__sparc__) && defined(__arch64__)
4#define Elf_Shdr Elf32_Shdr 4#include <asm-sparc/module_64.h>
5#define Elf_Sym Elf32_Sym 5#else
6#define Elf_Ehdr Elf32_Ehdr 6#include <asm-sparc/module_32.h>
7#endif /* _ASM_SPARC_MODULE_H */ 7#endif
8#endif
diff --git a/include/asm-sparc/module_32.h b/include/asm-sparc/module_32.h
new file mode 100644
index 000000000000..cbd9e67b0c0b
--- /dev/null
+++ b/include/asm-sparc/module_32.h
@@ -0,0 +1,7 @@
1#ifndef _ASM_SPARC_MODULE_H
2#define _ASM_SPARC_MODULE_H
3struct mod_arch_specific { };
4#define Elf_Shdr Elf32_Shdr
5#define Elf_Sym Elf32_Sym
6#define Elf_Ehdr Elf32_Ehdr
7#endif /* _ASM_SPARC_MODULE_H */
diff --git a/include/asm-sparc/module_64.h b/include/asm-sparc/module_64.h
new file mode 100644
index 000000000000..3d77ba465783
--- /dev/null
+++ b/include/asm-sparc/module_64.h
@@ -0,0 +1,7 @@
1#ifndef _ASM_SPARC64_MODULE_H
2#define _ASM_SPARC64_MODULE_H
3struct mod_arch_specific { };
4#define Elf_Shdr Elf64_Shdr
5#define Elf_Sym Elf64_Sym
6#define Elf_Ehdr Elf64_Ehdr
7#endif /* _ASM_SPARC64_MODULE_H */
diff --git a/include/asm-sparc/mostek.h b/include/asm-sparc/mostek.h
index 29aad11b8f00..5b9f7fec7ee7 100644
--- a/include/asm-sparc/mostek.h
+++ b/include/asm-sparc/mostek.h
@@ -1,173 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_MOSTEK_H
2 * mostek.h: Describes the various Mostek time of day clock registers. 2#define ___ASM_SPARC_MOSTEK_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 4#include <asm-sparc/mostek_64.h>
5 * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
6 * Added intersil code 05/25/98 Chris Davis (cdavis@cois.on.ca)
7 */
8
9#ifndef _SPARC_MOSTEK_H
10#define _SPARC_MOSTEK_H
11
12#include <asm/idprom.h>
13#include <asm/io.h>
14
15/* M48T02 Register Map (adapted from Sun NVRAM/Hostid FAQ)
16 *
17 * Data
18 * Address Function
19 * Bit 7 Bit 6 Bit 5 Bit 4Bit 3 Bit 2 Bit 1 Bit 0
20 * 7ff - - - - - - - - Year 00-99
21 * 7fe 0 0 0 - - - - - Month 01-12
22 * 7fd 0 0 - - - - - - Date 01-31
23 * 7fc 0 FT 0 0 0 - - - Day 01-07
24 * 7fb KS 0 - - - - - - Hours 00-23
25 * 7fa 0 - - - - - - - Minutes 00-59
26 * 7f9 ST - - - - - - - Seconds 00-59
27 * 7f8 W R S - - - - - Control
28 *
29 * * ST is STOP BIT
30 * * W is WRITE BIT
31 * * R is READ BIT
32 * * S is SIGN BIT
33 * * FT is FREQ TEST BIT
34 * * KS is KICK START BIT
35 */
36
37/* The Mostek 48t02 real time clock and NVRAM chip. The registers
38 * other than the control register are in binary coded decimal. Some
39 * control bits also live outside the control register.
40 */
41#define mostek_read(_addr) readb(_addr)
42#define mostek_write(_addr,_val) writeb(_val, _addr)
43#define MOSTEK_EEPROM 0x0000UL
44#define MOSTEK_IDPROM 0x07d8UL
45#define MOSTEK_CREG 0x07f8UL
46#define MOSTEK_SEC 0x07f9UL
47#define MOSTEK_MIN 0x07faUL
48#define MOSTEK_HOUR 0x07fbUL
49#define MOSTEK_DOW 0x07fcUL
50#define MOSTEK_DOM 0x07fdUL
51#define MOSTEK_MONTH 0x07feUL
52#define MOSTEK_YEAR 0x07ffUL
53
54struct mostek48t02 {
55 volatile char eeprom[2008]; /* This is the eeprom, don't touch! */
56 struct idprom idprom; /* The idprom lives here. */
57 volatile unsigned char creg; /* Control register */
58 volatile unsigned char sec; /* Seconds (0-59) */
59 volatile unsigned char min; /* Minutes (0-59) */
60 volatile unsigned char hour; /* Hour (0-23) */
61 volatile unsigned char dow; /* Day of the week (1-7) */
62 volatile unsigned char dom; /* Day of the month (1-31) */
63 volatile unsigned char month; /* Month of year (1-12) */
64 volatile unsigned char year; /* Year (0-99) */
65};
66
67extern spinlock_t mostek_lock;
68extern void __iomem *mstk48t02_regs;
69
70/* Control register values. */
71#define MSTK_CREG_WRITE 0x80 /* Must set this before placing values. */
72#define MSTK_CREG_READ 0x40 /* Stop updates to allow a clean read. */
73#define MSTK_CREG_SIGN 0x20 /* Slow/speed clock in calibration mode. */
74
75/* Control bits that live in the other registers. */
76#define MSTK_STOP 0x80 /* Stop the clock oscillator. (sec) */
77#define MSTK_KICK_START 0x80 /* Kick start the clock chip. (hour) */
78#define MSTK_FREQ_TEST 0x40 /* Frequency test mode. (day) */
79
80#define MSTK_YEAR_ZERO 1968 /* If year reg has zero, it is 1968. */
81#define MSTK_CVT_YEAR(yr) ((yr) + MSTK_YEAR_ZERO)
82
83/* Masks that define how much space each value takes up. */
84#define MSTK_SEC_MASK 0x7f
85#define MSTK_MIN_MASK 0x7f
86#define MSTK_HOUR_MASK 0x3f
87#define MSTK_DOW_MASK 0x07
88#define MSTK_DOM_MASK 0x3f
89#define MSTK_MONTH_MASK 0x1f
90#define MSTK_YEAR_MASK 0xffU
91
92/* Binary coded decimal conversion macros. */
93#define MSTK_REGVAL_TO_DECIMAL(x) (((x) & 0x0F) + 0x0A * ((x) >> 0x04))
94#define MSTK_DECIMAL_TO_REGVAL(x) ((((x) / 0x0A) << 0x04) + ((x) % 0x0A))
95
96/* Generic register set and get macros for internal use. */
97#define MSTK_GET(regs,var,mask) (MSTK_REGVAL_TO_DECIMAL(((struct mostek48t02 *)regs)->var & MSTK_ ## mask ## _MASK))
98#define MSTK_SET(regs,var,value,mask) do { ((struct mostek48t02 *)regs)->var &= ~(MSTK_ ## mask ## _MASK); ((struct mostek48t02 *)regs)->var |= MSTK_DECIMAL_TO_REGVAL(value) & (MSTK_ ## mask ## _MASK); } while (0)
99
100/* Macros to make register access easier on our fingers. These give you
101 * the decimal value of the register requested if applicable. You pass
102 * the a pointer to a 'struct mostek48t02'.
103 */
104#define MSTK_REG_CREG(regs) (((struct mostek48t02 *)regs)->creg)
105#define MSTK_REG_SEC(regs) MSTK_GET(regs,sec,SEC)
106#define MSTK_REG_MIN(regs) MSTK_GET(regs,min,MIN)
107#define MSTK_REG_HOUR(regs) MSTK_GET(regs,hour,HOUR)
108#define MSTK_REG_DOW(regs) MSTK_GET(regs,dow,DOW)
109#define MSTK_REG_DOM(regs) MSTK_GET(regs,dom,DOM)
110#define MSTK_REG_MONTH(regs) MSTK_GET(regs,month,MONTH)
111#define MSTK_REG_YEAR(regs) MSTK_GET(regs,year,YEAR)
112
113#define MSTK_SET_REG_SEC(regs,value) MSTK_SET(regs,sec,value,SEC)
114#define MSTK_SET_REG_MIN(regs,value) MSTK_SET(regs,min,value,MIN)
115#define MSTK_SET_REG_HOUR(regs,value) MSTK_SET(regs,hour,value,HOUR)
116#define MSTK_SET_REG_DOW(regs,value) MSTK_SET(regs,dow,value,DOW)
117#define MSTK_SET_REG_DOM(regs,value) MSTK_SET(regs,dom,value,DOM)
118#define MSTK_SET_REG_MONTH(regs,value) MSTK_SET(regs,month,value,MONTH)
119#define MSTK_SET_REG_YEAR(regs,value) MSTK_SET(regs,year,value,YEAR)
120
121
122/* The Mostek 48t08 clock chip. Found on Sun4m's I think. It has the
123 * same (basically) layout of the 48t02 chip except for the extra
124 * NVRAM on board (8 KB against the 48t02's 2 KB).
125 */
126struct mostek48t08 {
127 char offset[6*1024]; /* Magic things may be here, who knows? */
128 struct mostek48t02 regs; /* Here is what we are interested in. */
129};
130
131extern enum sparc_clock_type sp_clock_typ;
132
133#ifdef CONFIG_SUN4
134enum sparc_clock_type { MSTK48T02, MSTK48T08, \
135INTERSIL, MSTK_INVALID };
136#else 5#else
137enum sparc_clock_type { MSTK48T02, MSTK48T08, \ 6#include <asm-sparc/mostek_32.h>
138MSTK_INVALID };
139#endif 7#endif
140
141#ifdef CONFIG_SUN4
142/* intersil on a sun 4/260 code data from harris doc */
143struct intersil_dt {
144 volatile unsigned char int_csec;
145 volatile unsigned char int_hour;
146 volatile unsigned char int_min;
147 volatile unsigned char int_sec;
148 volatile unsigned char int_month;
149 volatile unsigned char int_day;
150 volatile unsigned char int_year;
151 volatile unsigned char int_dow;
152};
153
154struct intersil {
155 struct intersil_dt clk;
156 struct intersil_dt cmp;
157 volatile unsigned char int_intr_reg;
158 volatile unsigned char int_cmd_reg;
159};
160
161#define INTERSIL_STOP 0x0
162#define INTERSIL_START 0x8
163#define INTERSIL_INTR_DISABLE 0x0
164#define INTERSIL_INTR_ENABLE 0x10
165#define INTERSIL_32K 0x0
166#define INTERSIL_NORMAL 0x0
167#define INTERSIL_24H 0x4
168#define INTERSIL_INT_100HZ 0x2
169
170/* end of intersil info */
171#endif 8#endif
172
173#endif /* !(_SPARC_MOSTEK_H) */
diff --git a/include/asm-sparc/mostek_32.h b/include/asm-sparc/mostek_32.h
new file mode 100644
index 000000000000..a99590c4c507
--- /dev/null
+++ b/include/asm-sparc/mostek_32.h
@@ -0,0 +1,171 @@
1/*
2 * mostek.h: Describes the various Mostek time of day clock registers.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
6 * Added intersil code 05/25/98 Chris Davis (cdavis@cois.on.ca)
7 */
8
9#ifndef _SPARC_MOSTEK_H
10#define _SPARC_MOSTEK_H
11
12#include <asm/idprom.h>
13#include <asm/io.h>
14
15/* M48T02 Register Map (adapted from Sun NVRAM/Hostid FAQ)
16 *
17 * Data
18 * Address Function
19 * Bit 7 Bit 6 Bit 5 Bit 4Bit 3 Bit 2 Bit 1 Bit 0
20 * 7ff - - - - - - - - Year 00-99
21 * 7fe 0 0 0 - - - - - Month 01-12
22 * 7fd 0 0 - - - - - - Date 01-31
23 * 7fc 0 FT 0 0 0 - - - Day 01-07
24 * 7fb KS 0 - - - - - - Hours 00-23
25 * 7fa 0 - - - - - - - Minutes 00-59
26 * 7f9 ST - - - - - - - Seconds 00-59
27 * 7f8 W R S - - - - - Control
28 *
29 * * ST is STOP BIT
30 * * W is WRITE BIT
31 * * R is READ BIT
32 * * S is SIGN BIT
33 * * FT is FREQ TEST BIT
34 * * KS is KICK START BIT
35 */
36
37/* The Mostek 48t02 real time clock and NVRAM chip. The registers
38 * other than the control register are in binary coded decimal. Some
39 * control bits also live outside the control register.
40 */
41#define mostek_read(_addr) readb(_addr)
42#define mostek_write(_addr,_val) writeb(_val, _addr)
43#define MOSTEK_EEPROM 0x0000UL
44#define MOSTEK_IDPROM 0x07d8UL
45#define MOSTEK_CREG 0x07f8UL
46#define MOSTEK_SEC 0x07f9UL
47#define MOSTEK_MIN 0x07faUL
48#define MOSTEK_HOUR 0x07fbUL
49#define MOSTEK_DOW 0x07fcUL
50#define MOSTEK_DOM 0x07fdUL
51#define MOSTEK_MONTH 0x07feUL
52#define MOSTEK_YEAR 0x07ffUL
53
54struct mostek48t02 {
55 volatile char eeprom[2008]; /* This is the eeprom, don't touch! */
56 struct idprom idprom; /* The idprom lives here. */
57 volatile unsigned char creg; /* Control register */
58 volatile unsigned char sec; /* Seconds (0-59) */
59 volatile unsigned char min; /* Minutes (0-59) */
60 volatile unsigned char hour; /* Hour (0-23) */
61 volatile unsigned char dow; /* Day of the week (1-7) */
62 volatile unsigned char dom; /* Day of the month (1-31) */
63 volatile unsigned char month; /* Month of year (1-12) */
64 volatile unsigned char year; /* Year (0-99) */
65};
66
67extern spinlock_t mostek_lock;
68extern void __iomem *mstk48t02_regs;
69
70/* Control register values. */
71#define MSTK_CREG_WRITE 0x80 /* Must set this before placing values. */
72#define MSTK_CREG_READ 0x40 /* Stop updates to allow a clean read. */
73#define MSTK_CREG_SIGN 0x20 /* Slow/speed clock in calibration mode. */
74
75/* Control bits that live in the other registers. */
76#define MSTK_STOP 0x80 /* Stop the clock oscillator. (sec) */
77#define MSTK_KICK_START 0x80 /* Kick start the clock chip. (hour) */
78#define MSTK_FREQ_TEST 0x40 /* Frequency test mode. (day) */
79
80#define MSTK_YEAR_ZERO 1968 /* If year reg has zero, it is 1968. */
81#define MSTK_CVT_YEAR(yr) ((yr) + MSTK_YEAR_ZERO)
82
83/* Masks that define how much space each value takes up. */
84#define MSTK_SEC_MASK 0x7f
85#define MSTK_MIN_MASK 0x7f
86#define MSTK_HOUR_MASK 0x3f
87#define MSTK_DOW_MASK 0x07
88#define MSTK_DOM_MASK 0x3f
89#define MSTK_MONTH_MASK 0x1f
90#define MSTK_YEAR_MASK 0xffU
91
92/* Binary coded decimal conversion macros. */
93#define MSTK_REGVAL_TO_DECIMAL(x) (((x) & 0x0F) + 0x0A * ((x) >> 0x04))
94#define MSTK_DECIMAL_TO_REGVAL(x) ((((x) / 0x0A) << 0x04) + ((x) % 0x0A))
95
96/* Generic register set and get macros for internal use. */
97#define MSTK_GET(regs,var,mask) (MSTK_REGVAL_TO_DECIMAL(((struct mostek48t02 *)regs)->var & MSTK_ ## mask ## _MASK))
98#define MSTK_SET(regs,var,value,mask) do { ((struct mostek48t02 *)regs)->var &= ~(MSTK_ ## mask ## _MASK); ((struct mostek48t02 *)regs)->var |= MSTK_DECIMAL_TO_REGVAL(value) & (MSTK_ ## mask ## _MASK); } while (0)
99
100/* Macros to make register access easier on our fingers. These give you
101 * the decimal value of the register requested if applicable. You pass
102 * the a pointer to a 'struct mostek48t02'.
103 */
104#define MSTK_REG_CREG(regs) (((struct mostek48t02 *)regs)->creg)
105#define MSTK_REG_SEC(regs) MSTK_GET(regs,sec,SEC)
106#define MSTK_REG_MIN(regs) MSTK_GET(regs,min,MIN)
107#define MSTK_REG_HOUR(regs) MSTK_GET(regs,hour,HOUR)
108#define MSTK_REG_DOW(regs) MSTK_GET(regs,dow,DOW)
109#define MSTK_REG_DOM(regs) MSTK_GET(regs,dom,DOM)
110#define MSTK_REG_MONTH(regs) MSTK_GET(regs,month,MONTH)
111#define MSTK_REG_YEAR(regs) MSTK_GET(regs,year,YEAR)
112
113#define MSTK_SET_REG_SEC(regs,value) MSTK_SET(regs,sec,value,SEC)
114#define MSTK_SET_REG_MIN(regs,value) MSTK_SET(regs,min,value,MIN)
115#define MSTK_SET_REG_HOUR(regs,value) MSTK_SET(regs,hour,value,HOUR)
116#define MSTK_SET_REG_DOW(regs,value) MSTK_SET(regs,dow,value,DOW)
117#define MSTK_SET_REG_DOM(regs,value) MSTK_SET(regs,dom,value,DOM)
118#define MSTK_SET_REG_MONTH(regs,value) MSTK_SET(regs,month,value,MONTH)
119#define MSTK_SET_REG_YEAR(regs,value) MSTK_SET(regs,year,value,YEAR)
120
121
122/* The Mostek 48t08 clock chip. Found on Sun4m's I think. It has the
123 * same (basically) layout of the 48t02 chip except for the extra
124 * NVRAM on board (8 KB against the 48t02's 2 KB).
125 */
126struct mostek48t08 {
127 char offset[6*1024]; /* Magic things may be here, who knows? */
128 struct mostek48t02 regs; /* Here is what we are interested in. */
129};
130
131#ifdef CONFIG_SUN4
132enum sparc_clock_type { MSTK48T02, MSTK48T08, \
133INTERSIL, MSTK_INVALID };
134#else
135enum sparc_clock_type { MSTK48T02, MSTK48T08, \
136MSTK_INVALID };
137#endif
138
139#ifdef CONFIG_SUN4
140/* intersil on a sun 4/260 code data from harris doc */
141struct intersil_dt {
142 volatile unsigned char int_csec;
143 volatile unsigned char int_hour;
144 volatile unsigned char int_min;
145 volatile unsigned char int_sec;
146 volatile unsigned char int_month;
147 volatile unsigned char int_day;
148 volatile unsigned char int_year;
149 volatile unsigned char int_dow;
150};
151
152struct intersil {
153 struct intersil_dt clk;
154 struct intersil_dt cmp;
155 volatile unsigned char int_intr_reg;
156 volatile unsigned char int_cmd_reg;
157};
158
159#define INTERSIL_STOP 0x0
160#define INTERSIL_START 0x8
161#define INTERSIL_INTR_DISABLE 0x0
162#define INTERSIL_INTR_ENABLE 0x10
163#define INTERSIL_32K 0x0
164#define INTERSIL_NORMAL 0x0
165#define INTERSIL_24H 0x4
166#define INTERSIL_INT_100HZ 0x2
167
168/* end of intersil info */
169#endif
170
171#endif /* !(_SPARC_MOSTEK_H) */
diff --git a/include/asm-sparc/mostek_64.h b/include/asm-sparc/mostek_64.h
new file mode 100644
index 000000000000..c5652de2ace2
--- /dev/null
+++ b/include/asm-sparc/mostek_64.h
@@ -0,0 +1,143 @@
1/* mostek.h: Describes the various Mostek time of day clock registers.
2 *
3 * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
5 */
6
7#ifndef _SPARC64_MOSTEK_H
8#define _SPARC64_MOSTEK_H
9
10#include <asm/idprom.h>
11
12/* M48T02 Register Map (adapted from Sun NVRAM/Hostid FAQ)
13 *
14 * Data
15 * Address Function
16 * Bit 7 Bit 6 Bit 5 Bit 4Bit 3 Bit 2 Bit 1 Bit 0
17 * 7ff - - - - - - - - Year 00-99
18 * 7fe 0 0 0 - - - - - Month 01-12
19 * 7fd 0 0 - - - - - - Date 01-31
20 * 7fc 0 FT 0 0 0 - - - Day 01-07
21 * 7fb KS 0 - - - - - - Hours 00-23
22 * 7fa 0 - - - - - - - Minutes 00-59
23 * 7f9 ST - - - - - - - Seconds 00-59
24 * 7f8 W R S - - - - - Control
25 *
26 * * ST is STOP BIT
27 * * W is WRITE BIT
28 * * R is READ BIT
29 * * S is SIGN BIT
30 * * FT is FREQ TEST BIT
31 * * KS is KICK START BIT
32 */
33
34/* The Mostek 48t02 real time clock and NVRAM chip. The registers
35 * other than the control register are in binary coded decimal. Some
36 * control bits also live outside the control register.
37 *
38 * We now deal with physical addresses for I/O to the chip. -DaveM
39 */
40static inline u8 mostek_read(void __iomem *addr)
41{
42 u8 ret;
43
44 __asm__ __volatile__("lduba [%1] %2, %0"
45 : "=r" (ret)
46 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
47 return ret;
48}
49
50static inline void mostek_write(void __iomem *addr, u8 val)
51{
52 __asm__ __volatile__("stba %0, [%1] %2"
53 : /* no outputs */
54 : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
55}
56
57#define MOSTEK_EEPROM 0x0000UL
58#define MOSTEK_IDPROM 0x07d8UL
59#define MOSTEK_CREG 0x07f8UL
60#define MOSTEK_SEC 0x07f9UL
61#define MOSTEK_MIN 0x07faUL
62#define MOSTEK_HOUR 0x07fbUL
63#define MOSTEK_DOW 0x07fcUL
64#define MOSTEK_DOM 0x07fdUL
65#define MOSTEK_MONTH 0x07feUL
66#define MOSTEK_YEAR 0x07ffUL
67
68extern spinlock_t mostek_lock;
69extern void __iomem *mstk48t02_regs;
70
71/* Control register values. */
72#define MSTK_CREG_WRITE 0x80 /* Must set this before placing values. */
73#define MSTK_CREG_READ 0x40 /* Stop updates to allow a clean read. */
74#define MSTK_CREG_SIGN 0x20 /* Slow/speed clock in calibration mode. */
75
76/* Control bits that live in the other registers. */
77#define MSTK_STOP 0x80 /* Stop the clock oscillator. (sec) */
78#define MSTK_KICK_START 0x80 /* Kick start the clock chip. (hour) */
79#define MSTK_FREQ_TEST 0x40 /* Frequency test mode. (day) */
80
81#define MSTK_YEAR_ZERO 1968 /* If year reg has zero, it is 1968. */
82#define MSTK_CVT_YEAR(yr) ((yr) + MSTK_YEAR_ZERO)
83
84/* Masks that define how much space each value takes up. */
85#define MSTK_SEC_MASK 0x7f
86#define MSTK_MIN_MASK 0x7f
87#define MSTK_HOUR_MASK 0x3f
88#define MSTK_DOW_MASK 0x07
89#define MSTK_DOM_MASK 0x3f
90#define MSTK_MONTH_MASK 0x1f
91#define MSTK_YEAR_MASK 0xffU
92
93/* Binary coded decimal conversion macros. */
94#define MSTK_REGVAL_TO_DECIMAL(x) (((x) & 0x0F) + 0x0A * ((x) >> 0x04))
95#define MSTK_DECIMAL_TO_REGVAL(x) ((((x) / 0x0A) << 0x04) + ((x) % 0x0A))
96
97/* Generic register set and get macros for internal use. */
98#define MSTK_GET(regs,name) \
99 (MSTK_REGVAL_TO_DECIMAL(mostek_read(regs + MOSTEK_ ## name) & MSTK_ ## name ## _MASK))
100#define MSTK_SET(regs,name,value) \
101do { u8 __val = mostek_read(regs + MOSTEK_ ## name); \
102 __val &= ~(MSTK_ ## name ## _MASK); \
103 __val |= (MSTK_DECIMAL_TO_REGVAL(value) & \
104 (MSTK_ ## name ## _MASK)); \
105 mostek_write(regs + MOSTEK_ ## name, __val); \
106} while(0)
107
108/* Macros to make register access easier on our fingers. These give you
109 * the decimal value of the register requested if applicable. You pass
110 * the a pointer to a 'struct mostek48t02'.
111 */
112#define MSTK_REG_CREG(regs) (mostek_read((regs) + MOSTEK_CREG))
113#define MSTK_REG_SEC(regs) MSTK_GET(regs,SEC)
114#define MSTK_REG_MIN(regs) MSTK_GET(regs,MIN)
115#define MSTK_REG_HOUR(regs) MSTK_GET(regs,HOUR)
116#define MSTK_REG_DOW(regs) MSTK_GET(regs,DOW)
117#define MSTK_REG_DOM(regs) MSTK_GET(regs,DOM)
118#define MSTK_REG_MONTH(regs) MSTK_GET(regs,MONTH)
119#define MSTK_REG_YEAR(regs) MSTK_GET(regs,YEAR)
120
121#define MSTK_SET_REG_SEC(regs,value) MSTK_SET(regs,SEC,value)
122#define MSTK_SET_REG_MIN(regs,value) MSTK_SET(regs,MIN,value)
123#define MSTK_SET_REG_HOUR(regs,value) MSTK_SET(regs,HOUR,value)
124#define MSTK_SET_REG_DOW(regs,value) MSTK_SET(regs,DOW,value)
125#define MSTK_SET_REG_DOM(regs,value) MSTK_SET(regs,DOM,value)
126#define MSTK_SET_REG_MONTH(regs,value) MSTK_SET(regs,MONTH,value)
127#define MSTK_SET_REG_YEAR(regs,value) MSTK_SET(regs,YEAR,value)
128
129
130/* The Mostek 48t08 clock chip. Found on Sun4m's I think. It has the
131 * same (basically) layout of the 48t02 chip except for the extra
132 * NVRAM on board (8 KB against the 48t02's 2 KB).
133 */
134#define MOSTEK_48T08_OFFSET 0x0000UL /* Lower NVRAM portions */
135#define MOSTEK_48T08_48T02 0x1800UL /* Offset to 48T02 chip */
136
137/* SUN5 systems usually have 48t59 model clock chipsets. But we keep the older
138 * clock chip definitions around just in case.
139 */
140#define MOSTEK_48T59_OFFSET 0x0000UL /* Lower NVRAM portions */
141#define MOSTEK_48T59_48T02 0x1800UL /* Offset to 48T02 chip */
142
143#endif /* !(_SPARC64_MOSTEK_H) */
diff --git a/include/asm-sparc/msgbuf.h b/include/asm-sparc/msgbuf.h
index 8cec9ad0b825..efc7cbe9788f 100644
--- a/include/asm-sparc/msgbuf.h
+++ b/include/asm-sparc/msgbuf.h
@@ -1,7 +1,7 @@
1#ifndef _SPARC64_MSGBUF_H 1#ifndef _SPARC_MSGBUF_H
2#define _SPARC64_MSGBUF_H 2#define _SPARC_MSGBUF_H
3 3
4/* 4/*
5 * The msqid64_ds structure for sparc64 architecture. 5 * The msqid64_ds structure for sparc64 architecture.
6 * Note extra padding because this structure is passed back and forth 6 * Note extra padding because this structure is passed back and forth
7 * between kernel and user space. 7 * between kernel and user space.
@@ -11,13 +11,20 @@
11 * - 2 miscellaneous 32-bit values 11 * - 2 miscellaneous 32-bit values
12 */ 12 */
13 13
14#if defined(__sparc__) && defined(__arch64__)
15# define PADDING(x)
16#else
17# define PADDING(x) unsigned int x;
18#endif
19
20
14struct msqid64_ds { 21struct msqid64_ds {
15 struct ipc64_perm msg_perm; 22 struct ipc64_perm msg_perm;
16 unsigned int __pad1; 23 PADDING(__pad1)
17 __kernel_time_t msg_stime; /* last msgsnd time */ 24 __kernel_time_t msg_stime; /* last msgsnd time */
18 unsigned int __pad2; 25 PADDING(__pad2)
19 __kernel_time_t msg_rtime; /* last msgrcv time */ 26 __kernel_time_t msg_rtime; /* last msgrcv time */
20 unsigned int __pad3; 27 PADDING(__pad3)
21 __kernel_time_t msg_ctime; /* last change time */ 28 __kernel_time_t msg_ctime; /* last change time */
22 unsigned long msg_cbytes; /* current number of bytes on queue */ 29 unsigned long msg_cbytes; /* current number of bytes on queue */
23 unsigned long msg_qnum; /* number of messages in queue */ 30 unsigned long msg_qnum; /* number of messages in queue */
@@ -27,5 +34,5 @@ struct msqid64_ds {
27 unsigned long __unused1; 34 unsigned long __unused1;
28 unsigned long __unused2; 35 unsigned long __unused2;
29}; 36};
30 37#undef PADDING
31#endif /* _SPARC64_MSGBUF_H */ 38#endif /* _SPARC_MSGBUF_H */
diff --git a/include/asm-sparc/namei.h b/include/asm-sparc/namei.h
index 0646102fb020..eff944b8e321 100644
--- a/include/asm-sparc/namei.h
+++ b/include/asm-sparc/namei.h
@@ -1,13 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_NAMEI_H
2 * linux/include/asm-sparc/namei.h 2#define ___ASM_SPARC_NAMEI_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * Routines to handle famous /usr/gnemul/s*. 4#include <asm-sparc/namei_64.h>
5 * Included from linux/fs/namei.c 5#else
6 */ 6#include <asm-sparc/namei_32.h>
7 7#endif
8#ifndef __SPARC_NAMEI_H 8#endif
9#define __SPARC_NAMEI_H
10
11#define __emul_prefix() NULL
12
13#endif /* __SPARC_NAMEI_H */
diff --git a/include/asm-sparc/namei_32.h b/include/asm-sparc/namei_32.h
new file mode 100644
index 000000000000..0646102fb020
--- /dev/null
+++ b/include/asm-sparc/namei_32.h
@@ -0,0 +1,13 @@
1/*
2 * linux/include/asm-sparc/namei.h
3 *
4 * Routines to handle famous /usr/gnemul/s*.
5 * Included from linux/fs/namei.c
6 */
7
8#ifndef __SPARC_NAMEI_H
9#define __SPARC_NAMEI_H
10
11#define __emul_prefix() NULL
12
13#endif /* __SPARC_NAMEI_H */
diff --git a/include/asm-sparc/namei_64.h b/include/asm-sparc/namei_64.h
new file mode 100644
index 000000000000..cbc1b4c06891
--- /dev/null
+++ b/include/asm-sparc/namei_64.h
@@ -0,0 +1,13 @@
1/*
2 * linux/include/asm-sparc64/namei.h
3 *
4 * Routines to handle famous /usr/gnemul/s*.
5 * Included from linux/fs/namei.c
6 */
7
8#ifndef __SPARC64_NAMEI_H
9#define __SPARC64_NAMEI_H
10
11#define __emul_prefix() NULL
12
13#endif /* __SPARC64_NAMEI_H */
diff --git a/include/asm-sparc/ns87303.h b/include/asm-sparc/ns87303.h
new file mode 100644
index 000000000000..686defe6aaa0
--- /dev/null
+++ b/include/asm-sparc/ns87303.h
@@ -0,0 +1,118 @@
1/* ns87303.h: Configuration Register Description for the
2 * National Semiconductor PC87303 (SuperIO).
3 *
4 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
5 */
6
7#ifndef _SPARC_NS87303_H
8#define _SPARC_NS87303_H 1
9
10/*
11 * Control Register Index Values
12 */
13#define FER 0x00
14#define FAR 0x01
15#define PTR 0x02
16#define FCR 0x03
17#define PCR 0x04
18#define KRR 0x05
19#define PMC 0x06
20#define TUP 0x07
21#define SID 0x08
22#define ASC 0x09
23#define CS0CF0 0x0a
24#define CS0CF1 0x0b
25#define CS1CF0 0x0c
26#define CS1CF1 0x0d
27
28/* Function Enable Register (FER) bits */
29#define FER_EDM 0x10 /* Encoded Drive and Motor pin information */
30
31/* Function Address Register (FAR) bits */
32#define FAR_LPT_MASK 0x03
33#define FAR_LPTB 0x00
34#define FAR_LPTA 0x01
35#define FAR_LPTC 0x02
36
37/* Power and Test Register (PTR) bits */
38#define PTR_LPTB_IRQ7 0x08
39#define PTR_LEVEL_IRQ 0x80 /* When not ECP/EPP: Use level IRQ */
40#define PTR_LPT_REG_DIR 0x80 /* When ECP/EPP: LPT CTR controlls direction */
41 /* of the parallel port */
42
43/* Function Control Register (FCR) bits */
44#define FCR_LDE 0x10 /* Logical Drive Exchange */
45#define FCR_ZWS_ENA 0x20 /* Enable short host read/write in ECP/EPP */
46
47/* Printer Control Register (PCR) bits */
48#define PCR_EPP_ENABLE 0x01
49#define PCR_EPP_IEEE 0x02 /* Enable EPP Version 1.9 (IEEE 1284) */
50#define PCR_ECP_ENABLE 0x04
51#define PCR_ECP_CLK_ENA 0x08 /* If 0 ECP Clock is stopped on Power down */
52#define PCR_IRQ_POLAR 0x20 /* If 0 IRQ is level high or negative pulse, */
53 /* if 1 polarity is inverted */
54#define PCR_IRQ_ODRAIN 0x40 /* If 1, IRQ is open drain */
55
56/* Tape UARTs and Parallel Port Config Register (TUP) bits */
57#define TUP_EPP_TIMO 0x02 /* Enable EPP timeout IRQ */
58
59/* Advanced SuperIO Config Register (ASC) bits */
60#define ASC_LPT_IRQ7 0x01 /* Always use IRQ7 for LPT */
61#define ASC_DRV2_SEL 0x02 /* Logical Drive Exchange controlled by TDR */
62
63#define FER_RESERVED 0x00
64#define FAR_RESERVED 0x00
65#define PTR_RESERVED 0x73
66#define FCR_RESERVED 0xc4
67#define PCR_RESERVED 0x10
68#define KRR_RESERVED 0x00
69#define PMC_RESERVED 0x98
70#define TUP_RESERVED 0xfb
71#define SIP_RESERVED 0x00
72#define ASC_RESERVED 0x18
73#define CS0CF0_RESERVED 0x00
74#define CS0CF1_RESERVED 0x08
75#define CS1CF0_RESERVED 0x00
76#define CS1CF1_RESERVED 0x08
77
78#ifdef __KERNEL__
79
80#include <linux/spinlock.h>
81
82#include <asm/system.h>
83#include <asm/io.h>
84
85extern spinlock_t ns87303_lock;
86
87static inline int ns87303_modify(unsigned long port, unsigned int index,
88 unsigned char clr, unsigned char set)
89{
90 static unsigned char reserved[] = {
91 FER_RESERVED, FAR_RESERVED, PTR_RESERVED, FCR_RESERVED,
92 PCR_RESERVED, KRR_RESERVED, PMC_RESERVED, TUP_RESERVED,
93 SIP_RESERVED, ASC_RESERVED, CS0CF0_RESERVED, CS0CF1_RESERVED,
94 CS1CF0_RESERVED, CS1CF1_RESERVED
95 };
96 unsigned long flags;
97 unsigned char value;
98
99 if (index > 0x0d)
100 return -EINVAL;
101
102 spin_lock_irqsave(&ns87303_lock, flags);
103
104 outb(index, port);
105 value = inb(port + 1);
106 value &= ~(reserved[index] | clr);
107 value |= set;
108 outb(value, port + 1);
109 outb(value, port + 1);
110
111 spin_unlock_irqrestore(&ns87303_lock, flags);
112
113 return 0;
114}
115
116#endif /* __KERNEL__ */
117
118#endif /* !(_SPARC_NS87303_H) */
diff --git a/include/asm-sparc/of_platform.h b/include/asm-sparc/of_platform.h
index 38334351c36b..851eb84d737e 100644
--- a/include/asm-sparc/of_platform.h
+++ b/include/asm-sparc/of_platform.h
@@ -1,24 +1,8 @@
1#ifndef _ASM_SPARC_OF_PLATFORM_H 1#ifndef ___ASM_SPARC_OF_PLATFORM_H
2#define _ASM_SPARC_OF_PLATFORM_H 2#define ___ASM_SPARC_OF_PLATFORM_H
3/* 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp. 4#include <asm-sparc/of_platform_64.h>
5 * <benh@kernel.crashing.org> 5#else
6 * Modified for Sparc by merging parts of asm-sparc/of_device.h 6#include <asm-sparc/of_platform_32.h>
7 * by Stephen Rothwell 7#endif
8 * 8#endif
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 */
15
16/* This is just here during the transition */
17#include <linux/of_platform.h>
18
19extern struct bus_type ebus_bus_type;
20extern struct bus_type sbus_bus_type;
21
22#define of_bus_type of_platform_bus_type /* for compatibility */
23
24#endif /* _ASM_SPARC_OF_PLATFORM_H */
diff --git a/include/asm-sparc/of_platform_32.h b/include/asm-sparc/of_platform_32.h
new file mode 100644
index 000000000000..38334351c36b
--- /dev/null
+++ b/include/asm-sparc/of_platform_32.h
@@ -0,0 +1,24 @@
1#ifndef _ASM_SPARC_OF_PLATFORM_H
2#define _ASM_SPARC_OF_PLATFORM_H
3/*
4 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
5 * <benh@kernel.crashing.org>
6 * Modified for Sparc by merging parts of asm-sparc/of_device.h
7 * by Stephen Rothwell
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 */
15
16/* This is just here during the transition */
17#include <linux/of_platform.h>
18
19extern struct bus_type ebus_bus_type;
20extern struct bus_type sbus_bus_type;
21
22#define of_bus_type of_platform_bus_type /* for compatibility */
23
24#endif /* _ASM_SPARC_OF_PLATFORM_H */
diff --git a/include/asm-sparc/of_platform_64.h b/include/asm-sparc/of_platform_64.h
new file mode 100644
index 000000000000..78aa032b674c
--- /dev/null
+++ b/include/asm-sparc/of_platform_64.h
@@ -0,0 +1,25 @@
1#ifndef _ASM_SPARC64_OF_PLATFORM_H
2#define _ASM_SPARC64_OF_PLATFORM_H
3/*
4 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
5 * <benh@kernel.crashing.org>
6 * Modified for Sparc by merging parts of asm-sparc/of_device.h
7 * by Stephen Rothwell
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 */
15
16/* This is just here during the transition */
17#include <linux/of_platform.h>
18
19extern struct bus_type isa_bus_type;
20extern struct bus_type ebus_bus_type;
21extern struct bus_type sbus_bus_type;
22
23#define of_bus_type of_platform_bus_type /* for compatibility */
24
25#endif /* _ASM_SPARC64_OF_PLATFORM_H */
diff --git a/include/asm-sparc/openprom.h b/include/asm-sparc/openprom.h
index ed4b6bc2b102..8c349f061994 100644
--- a/include/asm-sparc/openprom.h
+++ b/include/asm-sparc/openprom.h
@@ -1,257 +1,8 @@
1#ifndef __SPARC_OPENPROM_H 1#ifndef ___ASM_SPARC_OPENPROM_H
2#define __SPARC_OPENPROM_H 2#define ___ASM_SPARC_OPENPROM_H
3 3#if defined(__sparc__) && defined(__arch64__)
4/* openprom.h: Prom structures and defines for access to the OPENBOOT 4#include <asm-sparc/openprom_64.h>
5 * prom routines and data areas. 5#else
6 * 6#include <asm-sparc/openprom_32.h>
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 7#endif
8 */ 8#endif
9
10#include <asm/vaddrs.h>
11
12/* Empirical constants... */
13#define LINUX_OPPROM_MAGIC 0x10010407
14
15#ifndef __ASSEMBLY__
16/* V0 prom device operations. */
17struct linux_dev_v0_funcs {
18 int (*v0_devopen)(char *device_str);
19 int (*v0_devclose)(int dev_desc);
20 int (*v0_rdblkdev)(int dev_desc, int num_blks, int blk_st, char *buf);
21 int (*v0_wrblkdev)(int dev_desc, int num_blks, int blk_st, char *buf);
22 int (*v0_wrnetdev)(int dev_desc, int num_bytes, char *buf);
23 int (*v0_rdnetdev)(int dev_desc, int num_bytes, char *buf);
24 int (*v0_rdchardev)(int dev_desc, int num_bytes, int dummy, char *buf);
25 int (*v0_wrchardev)(int dev_desc, int num_bytes, int dummy, char *buf);
26 int (*v0_seekdev)(int dev_desc, long logical_offst, int from);
27};
28
29/* V2 and later prom device operations. */
30struct linux_dev_v2_funcs {
31 int (*v2_inst2pkg)(int d); /* Convert ihandle to phandle */
32 char * (*v2_dumb_mem_alloc)(char *va, unsigned sz);
33 void (*v2_dumb_mem_free)(char *va, unsigned sz);
34
35 /* To map devices into virtual I/O space. */
36 char * (*v2_dumb_mmap)(char *virta, int which_io, unsigned paddr, unsigned sz);
37 void (*v2_dumb_munmap)(char *virta, unsigned size);
38
39 int (*v2_dev_open)(char *devpath);
40 void (*v2_dev_close)(int d);
41 int (*v2_dev_read)(int d, char *buf, int nbytes);
42 int (*v2_dev_write)(int d, char *buf, int nbytes);
43 int (*v2_dev_seek)(int d, int hi, int lo);
44
45 /* Never issued (multistage load support) */
46 void (*v2_wheee2)(void);
47 void (*v2_wheee3)(void);
48};
49
50struct linux_mlist_v0 {
51 struct linux_mlist_v0 *theres_more;
52 char *start_adr;
53 unsigned num_bytes;
54};
55
56struct linux_mem_v0 {
57 struct linux_mlist_v0 **v0_totphys;
58 struct linux_mlist_v0 **v0_prommap;
59 struct linux_mlist_v0 **v0_available; /* What we can use */
60};
61
62/* Arguments sent to the kernel from the boot prompt. */
63struct linux_arguments_v0 {
64 char *argv[8];
65 char args[100];
66 char boot_dev[2];
67 int boot_dev_ctrl;
68 int boot_dev_unit;
69 int dev_partition;
70 char *kernel_file_name;
71 void *aieee1; /* XXX */
72};
73
74/* V2 and up boot things. */
75struct linux_bootargs_v2 {
76 char **bootpath;
77 char **bootargs;
78 int *fd_stdin;
79 int *fd_stdout;
80};
81
82/* The top level PROM vector. */
83struct linux_romvec {
84 /* Version numbers. */
85 unsigned int pv_magic_cookie;
86 unsigned int pv_romvers;
87 unsigned int pv_plugin_revision;
88 unsigned int pv_printrev;
89
90 /* Version 0 memory descriptors. */
91 struct linux_mem_v0 pv_v0mem;
92
93 /* Node operations. */
94 struct linux_nodeops *pv_nodeops;
95
96 char **pv_bootstr;
97 struct linux_dev_v0_funcs pv_v0devops;
98
99 char *pv_stdin;
100 char *pv_stdout;
101#define PROMDEV_KBD 0 /* input from keyboard */
102#define PROMDEV_SCREEN 0 /* output to screen */
103#define PROMDEV_TTYA 1 /* in/out to ttya */
104#define PROMDEV_TTYB 2 /* in/out to ttyb */
105
106 /* Blocking getchar/putchar. NOT REENTRANT! (grr) */
107 int (*pv_getchar)(void);
108 void (*pv_putchar)(int ch);
109
110 /* Non-blocking variants. */
111 int (*pv_nbgetchar)(void);
112 int (*pv_nbputchar)(int ch);
113
114 void (*pv_putstr)(char *str, int len);
115
116 /* Miscellany. */
117 void (*pv_reboot)(char *bootstr);
118 void (*pv_printf)(__const__ char *fmt, ...);
119 void (*pv_abort)(void);
120 __volatile__ int *pv_ticks;
121 void (*pv_halt)(void);
122 void (**pv_synchook)(void);
123
124 /* Evaluate a forth string, not different proto for V0 and V2->up. */
125 union {
126 void (*v0_eval)(int len, char *str);
127 void (*v2_eval)(char *str);
128 } pv_fortheval;
129
130 struct linux_arguments_v0 **pv_v0bootargs;
131
132 /* Get ether address. */
133 unsigned int (*pv_enaddr)(int d, char *enaddr);
134
135 struct linux_bootargs_v2 pv_v2bootargs;
136 struct linux_dev_v2_funcs pv_v2devops;
137
138 int filler[15];
139
140 /* This one is sun4c/sun4 only. */
141 void (*pv_setctxt)(int ctxt, char *va, int pmeg);
142
143 /* Prom version 3 Multiprocessor routines. This stuff is crazy.
144 * No joke. Calling these when there is only one cpu probably
145 * crashes the machine, have to test this. :-)
146 */
147
148 /* v3_cpustart() will start the cpu 'whichcpu' in mmu-context
149 * 'thiscontext' executing at address 'prog_counter'
150 */
151 int (*v3_cpustart)(unsigned int whichcpu, int ctxtbl_ptr,
152 int thiscontext, char *prog_counter);
153
154 /* v3_cpustop() will cause cpu 'whichcpu' to stop executing
155 * until a resume cpu call is made.
156 */
157 int (*v3_cpustop)(unsigned int whichcpu);
158
159 /* v3_cpuidle() will idle cpu 'whichcpu' until a stop or
160 * resume cpu call is made.
161 */
162 int (*v3_cpuidle)(unsigned int whichcpu);
163
164 /* v3_cpuresume() will resume processor 'whichcpu' executing
165 * starting with whatever 'pc' and 'npc' were left at the
166 * last 'idle' or 'stop' call.
167 */
168 int (*v3_cpuresume)(unsigned int whichcpu);
169};
170
171/* Routines for traversing the prom device tree. */
172struct linux_nodeops {
173 int (*no_nextnode)(int node);
174 int (*no_child)(int node);
175 int (*no_proplen)(int node, char *name);
176 int (*no_getprop)(int node, char *name, char *val);
177 int (*no_setprop)(int node, char *name, char *val, int len);
178 char * (*no_nextprop)(int node, char *name);
179};
180
181/* More fun PROM structures for device probing. */
182#define PROMREG_MAX 16
183#define PROMVADDR_MAX 16
184#define PROMINTR_MAX 15
185
186struct linux_prom_registers {
187 unsigned int which_io; /* is this in OBIO space? */
188 unsigned int phys_addr; /* The physical address of this register */
189 unsigned int reg_size; /* How many bytes does this register take up? */
190};
191
192struct linux_prom_irqs {
193 int pri; /* IRQ priority */
194 int vector; /* This is foobar, what does it do? */
195};
196
197/* Element of the "ranges" vector */
198struct linux_prom_ranges {
199 unsigned int ot_child_space;
200 unsigned int ot_child_base; /* Bus feels this */
201 unsigned int ot_parent_space;
202 unsigned int ot_parent_base; /* CPU looks from here */
203 unsigned int or_size;
204};
205
206/* Ranges and reg properties are a bit different for PCI. */
207struct linux_prom_pci_registers {
208 /*
209 * We don't know what information this field contain.
210 * We guess, PCI device function is in bits 15:8
211 * So, ...
212 */
213 unsigned int which_io; /* Let it be which_io */
214
215 unsigned int phys_hi;
216 unsigned int phys_lo;
217
218 unsigned int size_hi;
219 unsigned int size_lo;
220};
221
222struct linux_prom_pci_ranges {
223 unsigned int child_phys_hi; /* Only certain bits are encoded here. */
224 unsigned int child_phys_mid;
225 unsigned int child_phys_lo;
226
227 unsigned int parent_phys_hi;
228 unsigned int parent_phys_lo;
229
230 unsigned int size_hi;
231 unsigned int size_lo;
232};
233
234struct linux_prom_pci_assigned_addresses {
235 unsigned int which_io;
236
237 unsigned int phys_hi;
238 unsigned int phys_lo;
239
240 unsigned int size_hi;
241 unsigned int size_lo;
242};
243
244struct linux_prom_ebus_ranges {
245 unsigned int child_phys_hi;
246 unsigned int child_phys_lo;
247
248 unsigned int parent_phys_hi;
249 unsigned int parent_phys_mid;
250 unsigned int parent_phys_lo;
251
252 unsigned int size;
253};
254
255#endif /* !(__ASSEMBLY__) */
256
257#endif /* !(__SPARC_OPENPROM_H) */
diff --git a/include/asm-sparc/openprom_32.h b/include/asm-sparc/openprom_32.h
new file mode 100644
index 000000000000..8b1649f29ed9
--- /dev/null
+++ b/include/asm-sparc/openprom_32.h
@@ -0,0 +1,255 @@
1#ifndef __SPARC_OPENPROM_H
2#define __SPARC_OPENPROM_H
3
4/* openprom.h: Prom structures and defines for access to the OPENBOOT
5 * prom routines and data areas.
6 *
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 */
9
10/* Empirical constants... */
11#define LINUX_OPPROM_MAGIC 0x10010407
12
13#ifndef __ASSEMBLY__
14/* V0 prom device operations. */
15struct linux_dev_v0_funcs {
16 int (*v0_devopen)(char *device_str);
17 int (*v0_devclose)(int dev_desc);
18 int (*v0_rdblkdev)(int dev_desc, int num_blks, int blk_st, char *buf);
19 int (*v0_wrblkdev)(int dev_desc, int num_blks, int blk_st, char *buf);
20 int (*v0_wrnetdev)(int dev_desc, int num_bytes, char *buf);
21 int (*v0_rdnetdev)(int dev_desc, int num_bytes, char *buf);
22 int (*v0_rdchardev)(int dev_desc, int num_bytes, int dummy, char *buf);
23 int (*v0_wrchardev)(int dev_desc, int num_bytes, int dummy, char *buf);
24 int (*v0_seekdev)(int dev_desc, long logical_offst, int from);
25};
26
27/* V2 and later prom device operations. */
28struct linux_dev_v2_funcs {
29 int (*v2_inst2pkg)(int d); /* Convert ihandle to phandle */
30 char * (*v2_dumb_mem_alloc)(char *va, unsigned sz);
31 void (*v2_dumb_mem_free)(char *va, unsigned sz);
32
33 /* To map devices into virtual I/O space. */
34 char * (*v2_dumb_mmap)(char *virta, int which_io, unsigned paddr, unsigned sz);
35 void (*v2_dumb_munmap)(char *virta, unsigned size);
36
37 int (*v2_dev_open)(char *devpath);
38 void (*v2_dev_close)(int d);
39 int (*v2_dev_read)(int d, char *buf, int nbytes);
40 int (*v2_dev_write)(int d, char *buf, int nbytes);
41 int (*v2_dev_seek)(int d, int hi, int lo);
42
43 /* Never issued (multistage load support) */
44 void (*v2_wheee2)(void);
45 void (*v2_wheee3)(void);
46};
47
48struct linux_mlist_v0 {
49 struct linux_mlist_v0 *theres_more;
50 char *start_adr;
51 unsigned num_bytes;
52};
53
54struct linux_mem_v0 {
55 struct linux_mlist_v0 **v0_totphys;
56 struct linux_mlist_v0 **v0_prommap;
57 struct linux_mlist_v0 **v0_available; /* What we can use */
58};
59
60/* Arguments sent to the kernel from the boot prompt. */
61struct linux_arguments_v0 {
62 char *argv[8];
63 char args[100];
64 char boot_dev[2];
65 int boot_dev_ctrl;
66 int boot_dev_unit;
67 int dev_partition;
68 char *kernel_file_name;
69 void *aieee1; /* XXX */
70};
71
72/* V2 and up boot things. */
73struct linux_bootargs_v2 {
74 char **bootpath;
75 char **bootargs;
76 int *fd_stdin;
77 int *fd_stdout;
78};
79
80/* The top level PROM vector. */
81struct linux_romvec {
82 /* Version numbers. */
83 unsigned int pv_magic_cookie;
84 unsigned int pv_romvers;
85 unsigned int pv_plugin_revision;
86 unsigned int pv_printrev;
87
88 /* Version 0 memory descriptors. */
89 struct linux_mem_v0 pv_v0mem;
90
91 /* Node operations. */
92 struct linux_nodeops *pv_nodeops;
93
94 char **pv_bootstr;
95 struct linux_dev_v0_funcs pv_v0devops;
96
97 char *pv_stdin;
98 char *pv_stdout;
99#define PROMDEV_KBD 0 /* input from keyboard */
100#define PROMDEV_SCREEN 0 /* output to screen */
101#define PROMDEV_TTYA 1 /* in/out to ttya */
102#define PROMDEV_TTYB 2 /* in/out to ttyb */
103
104 /* Blocking getchar/putchar. NOT REENTRANT! (grr) */
105 int (*pv_getchar)(void);
106 void (*pv_putchar)(int ch);
107
108 /* Non-blocking variants. */
109 int (*pv_nbgetchar)(void);
110 int (*pv_nbputchar)(int ch);
111
112 void (*pv_putstr)(char *str, int len);
113
114 /* Miscellany. */
115 void (*pv_reboot)(char *bootstr);
116 void (*pv_printf)(__const__ char *fmt, ...);
117 void (*pv_abort)(void);
118 __volatile__ int *pv_ticks;
119 void (*pv_halt)(void);
120 void (**pv_synchook)(void);
121
122 /* Evaluate a forth string, not different proto for V0 and V2->up. */
123 union {
124 void (*v0_eval)(int len, char *str);
125 void (*v2_eval)(char *str);
126 } pv_fortheval;
127
128 struct linux_arguments_v0 **pv_v0bootargs;
129
130 /* Get ether address. */
131 unsigned int (*pv_enaddr)(int d, char *enaddr);
132
133 struct linux_bootargs_v2 pv_v2bootargs;
134 struct linux_dev_v2_funcs pv_v2devops;
135
136 int filler[15];
137
138 /* This one is sun4c/sun4 only. */
139 void (*pv_setctxt)(int ctxt, char *va, int pmeg);
140
141 /* Prom version 3 Multiprocessor routines. This stuff is crazy.
142 * No joke. Calling these when there is only one cpu probably
143 * crashes the machine, have to test this. :-)
144 */
145
146 /* v3_cpustart() will start the cpu 'whichcpu' in mmu-context
147 * 'thiscontext' executing at address 'prog_counter'
148 */
149 int (*v3_cpustart)(unsigned int whichcpu, int ctxtbl_ptr,
150 int thiscontext, char *prog_counter);
151
152 /* v3_cpustop() will cause cpu 'whichcpu' to stop executing
153 * until a resume cpu call is made.
154 */
155 int (*v3_cpustop)(unsigned int whichcpu);
156
157 /* v3_cpuidle() will idle cpu 'whichcpu' until a stop or
158 * resume cpu call is made.
159 */
160 int (*v3_cpuidle)(unsigned int whichcpu);
161
162 /* v3_cpuresume() will resume processor 'whichcpu' executing
163 * starting with whatever 'pc' and 'npc' were left at the
164 * last 'idle' or 'stop' call.
165 */
166 int (*v3_cpuresume)(unsigned int whichcpu);
167};
168
169/* Routines for traversing the prom device tree. */
170struct linux_nodeops {
171 int (*no_nextnode)(int node);
172 int (*no_child)(int node);
173 int (*no_proplen)(int node, char *name);
174 int (*no_getprop)(int node, char *name, char *val);
175 int (*no_setprop)(int node, char *name, char *val, int len);
176 char * (*no_nextprop)(int node, char *name);
177};
178
179/* More fun PROM structures for device probing. */
180#define PROMREG_MAX 16
181#define PROMVADDR_MAX 16
182#define PROMINTR_MAX 15
183
184struct linux_prom_registers {
185 unsigned int which_io; /* is this in OBIO space? */
186 unsigned int phys_addr; /* The physical address of this register */
187 unsigned int reg_size; /* How many bytes does this register take up? */
188};
189
190struct linux_prom_irqs {
191 int pri; /* IRQ priority */
192 int vector; /* This is foobar, what does it do? */
193};
194
195/* Element of the "ranges" vector */
196struct linux_prom_ranges {
197 unsigned int ot_child_space;
198 unsigned int ot_child_base; /* Bus feels this */
199 unsigned int ot_parent_space;
200 unsigned int ot_parent_base; /* CPU looks from here */
201 unsigned int or_size;
202};
203
204/* Ranges and reg properties are a bit different for PCI. */
205struct linux_prom_pci_registers {
206 /*
207 * We don't know what information this field contain.
208 * We guess, PCI device function is in bits 15:8
209 * So, ...
210 */
211 unsigned int which_io; /* Let it be which_io */
212
213 unsigned int phys_hi;
214 unsigned int phys_lo;
215
216 unsigned int size_hi;
217 unsigned int size_lo;
218};
219
220struct linux_prom_pci_ranges {
221 unsigned int child_phys_hi; /* Only certain bits are encoded here. */
222 unsigned int child_phys_mid;
223 unsigned int child_phys_lo;
224
225 unsigned int parent_phys_hi;
226 unsigned int parent_phys_lo;
227
228 unsigned int size_hi;
229 unsigned int size_lo;
230};
231
232struct linux_prom_pci_assigned_addresses {
233 unsigned int which_io;
234
235 unsigned int phys_hi;
236 unsigned int phys_lo;
237
238 unsigned int size_hi;
239 unsigned int size_lo;
240};
241
242struct linux_prom_ebus_ranges {
243 unsigned int child_phys_hi;
244 unsigned int child_phys_lo;
245
246 unsigned int parent_phys_hi;
247 unsigned int parent_phys_mid;
248 unsigned int parent_phys_lo;
249
250 unsigned int size;
251};
252
253#endif /* !(__ASSEMBLY__) */
254
255#endif /* !(__SPARC_OPENPROM_H) */
diff --git a/include/asm-sparc/openprom_64.h b/include/asm-sparc/openprom_64.h
new file mode 100644
index 000000000000..b69e4a8c9170
--- /dev/null
+++ b/include/asm-sparc/openprom_64.h
@@ -0,0 +1,280 @@
1#ifndef __SPARC64_OPENPROM_H
2#define __SPARC64_OPENPROM_H
3
4/* openprom.h: Prom structures and defines for access to the OPENBOOT
5 * prom routines and data areas.
6 *
7 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
8 */
9
10#ifndef __ASSEMBLY__
11/* V0 prom device operations. */
12struct linux_dev_v0_funcs {
13 int (*v0_devopen)(char *device_str);
14 int (*v0_devclose)(int dev_desc);
15 int (*v0_rdblkdev)(int dev_desc, int num_blks, int blk_st, char *buf);
16 int (*v0_wrblkdev)(int dev_desc, int num_blks, int blk_st, char *buf);
17 int (*v0_wrnetdev)(int dev_desc, int num_bytes, char *buf);
18 int (*v0_rdnetdev)(int dev_desc, int num_bytes, char *buf);
19 int (*v0_rdchardev)(int dev_desc, int num_bytes, int dummy, char *buf);
20 int (*v0_wrchardev)(int dev_desc, int num_bytes, int dummy, char *buf);
21 int (*v0_seekdev)(int dev_desc, long logical_offst, int from);
22};
23
24/* V2 and later prom device operations. */
25struct linux_dev_v2_funcs {
26 int (*v2_inst2pkg)(int d); /* Convert ihandle to phandle */
27 char * (*v2_dumb_mem_alloc)(char *va, unsigned sz);
28 void (*v2_dumb_mem_free)(char *va, unsigned sz);
29
30 /* To map devices into virtual I/O space. */
31 char * (*v2_dumb_mmap)(char *virta, int which_io, unsigned paddr, unsigned sz);
32 void (*v2_dumb_munmap)(char *virta, unsigned size);
33
34 int (*v2_dev_open)(char *devpath);
35 void (*v2_dev_close)(int d);
36 int (*v2_dev_read)(int d, char *buf, int nbytes);
37 int (*v2_dev_write)(int d, char *buf, int nbytes);
38 int (*v2_dev_seek)(int d, int hi, int lo);
39
40 /* Never issued (multistage load support) */
41 void (*v2_wheee2)(void);
42 void (*v2_wheee3)(void);
43};
44
45struct linux_mlist_v0 {
46 struct linux_mlist_v0 *theres_more;
47 unsigned start_adr;
48 unsigned num_bytes;
49};
50
51struct linux_mem_v0 {
52 struct linux_mlist_v0 **v0_totphys;
53 struct linux_mlist_v0 **v0_prommap;
54 struct linux_mlist_v0 **v0_available; /* What we can use */
55};
56
57/* Arguments sent to the kernel from the boot prompt. */
58struct linux_arguments_v0 {
59 char *argv[8];
60 char args[100];
61 char boot_dev[2];
62 int boot_dev_ctrl;
63 int boot_dev_unit;
64 int dev_partition;
65 char *kernel_file_name;
66 void *aieee1; /* XXX */
67};
68
69/* V2 and up boot things. */
70struct linux_bootargs_v2 {
71 char **bootpath;
72 char **bootargs;
73 int *fd_stdin;
74 int *fd_stdout;
75};
76
77/* The top level PROM vector. */
78struct linux_romvec {
79 /* Version numbers. */
80 unsigned int pv_magic_cookie;
81 unsigned int pv_romvers;
82 unsigned int pv_plugin_revision;
83 unsigned int pv_printrev;
84
85 /* Version 0 memory descriptors. */
86 struct linux_mem_v0 pv_v0mem;
87
88 /* Node operations. */
89 struct linux_nodeops *pv_nodeops;
90
91 char **pv_bootstr;
92 struct linux_dev_v0_funcs pv_v0devops;
93
94 char *pv_stdin;
95 char *pv_stdout;
96#define PROMDEV_KBD 0 /* input from keyboard */
97#define PROMDEV_SCREEN 0 /* output to screen */
98#define PROMDEV_TTYA 1 /* in/out to ttya */
99#define PROMDEV_TTYB 2 /* in/out to ttyb */
100
101 /* Blocking getchar/putchar. NOT REENTRANT! (grr) */
102 int (*pv_getchar)(void);
103 void (*pv_putchar)(int ch);
104
105 /* Non-blocking variants. */
106 int (*pv_nbgetchar)(void);
107 int (*pv_nbputchar)(int ch);
108
109 void (*pv_putstr)(char *str, int len);
110
111 /* Miscellany. */
112 void (*pv_reboot)(char *bootstr);
113 void (*pv_printf)(__const__ char *fmt, ...);
114 void (*pv_abort)(void);
115 __volatile__ int *pv_ticks;
116 void (*pv_halt)(void);
117 void (**pv_synchook)(void);
118
119 /* Evaluate a forth string, not different proto for V0 and V2->up. */
120 union {
121 void (*v0_eval)(int len, char *str);
122 void (*v2_eval)(char *str);
123 } pv_fortheval;
124
125 struct linux_arguments_v0 **pv_v0bootargs;
126
127 /* Get ether address. */
128 unsigned int (*pv_enaddr)(int d, char *enaddr);
129
130 struct linux_bootargs_v2 pv_v2bootargs;
131 struct linux_dev_v2_funcs pv_v2devops;
132
133 int filler[15];
134
135 /* This one is sun4c/sun4 only. */
136 void (*pv_setctxt)(int ctxt, char *va, int pmeg);
137
138 /* Prom version 3 Multiprocessor routines. This stuff is crazy.
139 * No joke. Calling these when there is only one cpu probably
140 * crashes the machine, have to test this. :-)
141 */
142
143 /* v3_cpustart() will start the cpu 'whichcpu' in mmu-context
144 * 'thiscontext' executing at address 'prog_counter'
145 */
146 int (*v3_cpustart)(unsigned int whichcpu, int ctxtbl_ptr,
147 int thiscontext, char *prog_counter);
148
149 /* v3_cpustop() will cause cpu 'whichcpu' to stop executing
150 * until a resume cpu call is made.
151 */
152 int (*v3_cpustop)(unsigned int whichcpu);
153
154 /* v3_cpuidle() will idle cpu 'whichcpu' until a stop or
155 * resume cpu call is made.
156 */
157 int (*v3_cpuidle)(unsigned int whichcpu);
158
159 /* v3_cpuresume() will resume processor 'whichcpu' executing
160 * starting with whatever 'pc' and 'npc' were left at the
161 * last 'idle' or 'stop' call.
162 */
163 int (*v3_cpuresume)(unsigned int whichcpu);
164};
165
166/* Routines for traversing the prom device tree. */
167struct linux_nodeops {
168 int (*no_nextnode)(int node);
169 int (*no_child)(int node);
170 int (*no_proplen)(int node, char *name);
171 int (*no_getprop)(int node, char *name, char *val);
172 int (*no_setprop)(int node, char *name, char *val, int len);
173 char * (*no_nextprop)(int node, char *name);
174};
175
176/* More fun PROM structures for device probing. */
177#define PROMREG_MAX 24
178#define PROMVADDR_MAX 16
179#define PROMINTR_MAX 32
180
181struct linux_prom_registers {
182 unsigned which_io; /* hi part of physical address */
183 unsigned phys_addr; /* The physical address of this register */
184 int reg_size; /* How many bytes does this register take up? */
185};
186
187struct linux_prom64_registers {
188 unsigned long phys_addr;
189 unsigned long reg_size;
190};
191
192struct linux_prom_irqs {
193 int pri; /* IRQ priority */
194 int vector; /* This is foobar, what does it do? */
195};
196
197/* Element of the "ranges" vector */
198struct linux_prom_ranges {
199 unsigned int ot_child_space;
200 unsigned int ot_child_base; /* Bus feels this */
201 unsigned int ot_parent_space;
202 unsigned int ot_parent_base; /* CPU looks from here */
203 unsigned int or_size;
204};
205
206struct linux_prom64_ranges {
207 unsigned long ot_child_base; /* Bus feels this */
208 unsigned long ot_parent_base; /* CPU looks from here */
209 unsigned long or_size;
210};
211
212/* Ranges and reg properties are a bit different for PCI. */
213struct linux_prom_pci_registers {
214 unsigned int phys_hi;
215 unsigned int phys_mid;
216 unsigned int phys_lo;
217
218 unsigned int size_hi;
219 unsigned int size_lo;
220};
221
222struct linux_prom_pci_ranges {
223 unsigned int child_phys_hi; /* Only certain bits are encoded here. */
224 unsigned int child_phys_mid;
225 unsigned int child_phys_lo;
226
227 unsigned int parent_phys_hi;
228 unsigned int parent_phys_lo;
229
230 unsigned int size_hi;
231 unsigned int size_lo;
232};
233
234struct linux_prom_pci_intmap {
235 unsigned int phys_hi;
236 unsigned int phys_mid;
237 unsigned int phys_lo;
238
239 unsigned int interrupt;
240
241 int cnode;
242 unsigned int cinterrupt;
243};
244
245struct linux_prom_pci_intmask {
246 unsigned int phys_hi;
247 unsigned int phys_mid;
248 unsigned int phys_lo;
249 unsigned int interrupt;
250};
251
252struct linux_prom_ebus_ranges {
253 unsigned int child_phys_hi;
254 unsigned int child_phys_lo;
255
256 unsigned int parent_phys_hi;
257 unsigned int parent_phys_mid;
258 unsigned int parent_phys_lo;
259
260 unsigned int size;
261};
262
263struct linux_prom_ebus_intmap {
264 unsigned int phys_hi;
265 unsigned int phys_lo;
266
267 unsigned int interrupt;
268
269 int cnode;
270 unsigned int cinterrupt;
271};
272
273struct linux_prom_ebus_intmask {
274 unsigned int phys_hi;
275 unsigned int phys_lo;
276 unsigned int interrupt;
277};
278#endif /* !(__ASSEMBLY__) */
279
280#endif /* !(__SPARC64_OPENPROM_H) */
diff --git a/include/asm-sparc/oplib.h b/include/asm-sparc/oplib.h
index 61c3ca6a8ac3..e88d7c04a292 100644
--- a/include/asm-sparc/oplib.h
+++ b/include/asm-sparc/oplib.h
@@ -1,273 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_OPLIB_H
2 * oplib.h: Describes the interface and available routines in the 2#define ___ASM_SPARC_OPLIB_H
3 * Linux Prom library. 3#if defined(__sparc__) && defined(__arch64__)
4 * 4#include <asm-sparc/oplib_64.h>
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 5#else
6 */ 6#include <asm-sparc/oplib_32.h>
7 7#endif
8#ifndef __SPARC_OPLIB_H
9#define __SPARC_OPLIB_H
10
11#include <asm/openprom.h>
12#include <linux/spinlock.h>
13#include <linux/compiler.h>
14
15/* The master romvec pointer... */
16extern struct linux_romvec *romvec;
17
18/* Enumeration to describe the prom major version we have detected. */
19enum prom_major_version {
20 PROM_V0, /* Original sun4c V0 prom */
21 PROM_V2, /* sun4c and early sun4m V2 prom */
22 PROM_V3, /* sun4m and later, up to sun4d/sun4e machines V3 */
23 PROM_P1275, /* IEEE compliant ISA based Sun PROM, only sun4u */
24 PROM_AP1000, /* actually no prom at all */
25 PROM_SUN4, /* Old sun4 proms are totally different, but we'll shoehorn it to make it fit */
26};
27
28extern enum prom_major_version prom_vers;
29/* Revision, and firmware revision. */
30extern unsigned int prom_rev, prom_prev;
31
32/* Root node of the prom device tree, this stays constant after
33 * initialization is complete.
34 */
35extern int prom_root_node;
36
37/* Pointer to prom structure containing the device tree traversal
38 * and usage utility functions. Only prom-lib should use these,
39 * users use the interface defined by the library only!
40 */
41extern struct linux_nodeops *prom_nodeops;
42
43/* The functions... */
44
45/* You must call prom_init() before using any of the library services,
46 * preferably as early as possible. Pass it the romvec pointer.
47 */
48extern void prom_init(struct linux_romvec *rom_ptr);
49
50/* Boot argument acquisition, returns the boot command line string. */
51extern char *prom_getbootargs(void);
52
53/* Device utilities. */
54
55/* Map and unmap devices in IO space at virtual addresses. Note that the
56 * virtual address you pass is a request and the prom may put your mappings
57 * somewhere else, so check your return value as that is where your new
58 * mappings really are!
59 *
60 * Another note, these are only available on V2 or higher proms!
61 */
62extern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes);
63extern void prom_unmapio(char *virt_addr, unsigned int num_bytes);
64
65/* Device operations. */
66
67/* Open the device described by the passed string. Note, that the format
68 * of the string is different on V0 vs. V2->higher proms. The caller must
69 * know what he/she is doing! Returns the device descriptor, an int.
70 */
71extern int prom_devopen(char *device_string);
72
73/* Close a previously opened device described by the passed integer
74 * descriptor.
75 */
76extern int prom_devclose(int device_handle);
77
78/* Do a seek operation on the device described by the passed integer
79 * descriptor.
80 */
81extern void prom_seek(int device_handle, unsigned int seek_hival,
82 unsigned int seek_lowval);
83
84/* Miscellaneous routines, don't really fit in any category per se. */
85
86/* Reboot the machine with the command line passed. */
87extern void prom_reboot(char *boot_command);
88
89/* Evaluate the forth string passed. */
90extern void prom_feval(char *forth_string);
91
92/* Enter the prom, with possibility of continuation with the 'go'
93 * command in newer proms.
94 */
95extern void prom_cmdline(void);
96
97/* Enter the prom, with no chance of continuation for the stand-alone
98 * which calls this.
99 */
100extern void prom_halt(void) __attribute__ ((noreturn));
101
102/* Set the PROM 'sync' callback function to the passed function pointer.
103 * When the user gives the 'sync' command at the prom prompt while the
104 * kernel is still active, the prom will call this routine.
105 *
106 * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
107 */
108typedef void (*sync_func_t)(void);
109extern void prom_setsync(sync_func_t func_ptr);
110
111/* Acquire the IDPROM of the root node in the prom device tree. This
112 * gets passed a buffer where you would like it stuffed. The return value
113 * is the format type of this idprom or 0xff on error.
114 */
115extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
116
117/* Get the prom major version. */
118extern int prom_version(void);
119
120/* Get the prom plugin revision. */
121extern int prom_getrev(void);
122
123/* Get the prom firmware revision. */
124extern int prom_getprev(void);
125
126/* Character operations to/from the console.... */
127
128/* Non-blocking get character from console. */
129extern int prom_nbgetchar(void);
130
131/* Non-blocking put character to console. */
132extern int prom_nbputchar(char character);
133
134/* Blocking get character from console. */
135extern char prom_getchar(void);
136
137/* Blocking put character to console. */
138extern void prom_putchar(char character);
139
140/* Prom's internal routines, don't use in kernel/boot code. */
141extern void prom_printf(char *fmt, ...);
142extern void prom_write(const char *buf, unsigned int len);
143
144/* Multiprocessor operations... */
145
146/* Start the CPU with the given device tree node, context table, and context
147 * at the passed program counter.
148 */
149extern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
150 int context, char *program_counter);
151
152/* Stop the CPU with the passed device tree node. */
153extern int prom_stopcpu(int cpunode);
154
155/* Idle the CPU with the passed device tree node. */
156extern int prom_idlecpu(int cpunode);
157
158/* Re-Start the CPU with the passed device tree node. */
159extern int prom_restartcpu(int cpunode);
160
161/* PROM memory allocation facilities... */
162
163/* Allocated at possibly the given virtual address a chunk of the
164 * indicated size.
165 */
166extern char *prom_alloc(char *virt_hint, unsigned int size);
167
168/* Free a previously allocated chunk. */
169extern void prom_free(char *virt_addr, unsigned int size);
170
171/* Sun4/sun4c specific memory-management startup hook. */
172
173/* Map the passed segment in the given context at the passed
174 * virtual address.
175 */
176extern void prom_putsegment(int context, unsigned long virt_addr,
177 int physical_segment);
178
179
180/* PROM device tree traversal functions... */
181
182#ifdef PROMLIB_INTERNAL
183
184/* Internal version of prom_getchild. */
185extern int __prom_getchild(int parent_node);
186
187/* Internal version of prom_getsibling. */
188extern int __prom_getsibling(int node);
189
190#endif 8#endif
191
192
193/* Get the child node of the given node, or zero if no child exists. */
194extern int prom_getchild(int parent_node);
195
196/* Get the next sibling node of the given node, or zero if no further
197 * siblings exist.
198 */
199extern int prom_getsibling(int node);
200
201/* Get the length, at the passed node, of the given property type.
202 * Returns -1 on error (ie. no such property at this node).
203 */
204extern int prom_getproplen(int thisnode, char *property);
205
206/* Fetch the requested property using the given buffer. Returns
207 * the number of bytes the prom put into your buffer or -1 on error.
208 */
209extern int __must_check prom_getproperty(int thisnode, char *property,
210 char *prop_buffer, int propbuf_size);
211
212/* Acquire an integer property. */
213extern int prom_getint(int node, char *property);
214
215/* Acquire an integer property, with a default value. */
216extern int prom_getintdefault(int node, char *property, int defval);
217
218/* Acquire a boolean property, 0=FALSE 1=TRUE. */
219extern int prom_getbool(int node, char *prop);
220
221/* Acquire a string property, null string on error. */
222extern void prom_getstring(int node, char *prop, char *buf, int bufsize);
223
224/* Does the passed node have the given "name"? YES=1 NO=0 */
225extern int prom_nodematch(int thisnode, char *name);
226
227/* Search all siblings starting at the passed node for "name" matching
228 * the given string. Returns the node on success, zero on failure.
229 */
230extern int prom_searchsiblings(int node_start, char *name);
231
232/* Return the first property type, as a string, for the given node.
233 * Returns a null string on error.
234 */
235extern char *prom_firstprop(int node, char *buffer);
236
237/* Returns the next property after the passed property for the given
238 * node. Returns null string on failure.
239 */
240extern char *prom_nextprop(int node, char *prev_property, char *buffer);
241
242/* Returns phandle of the path specified */
243extern int prom_finddevice(char *name);
244
245/* Returns 1 if the specified node has given property. */
246extern int prom_node_has_property(int node, char *property);
247
248/* Set the indicated property at the given node with the passed value.
249 * Returns the number of bytes of your value that the prom took.
250 */
251extern int prom_setprop(int node, char *prop_name, char *prop_value,
252 int value_size);
253
254extern int prom_pathtoinode(char *path);
255extern int prom_inst2pkg(int);
256
257/* Dorking with Bus ranges... */
258
259/* Apply promlib probes OBIO ranges to registers. */
260extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
261
262/* Apply ranges of any prom node (and optionally parent node as well) to registers. */
263extern void prom_apply_generic_ranges(int node, int parent,
264 struct linux_prom_registers *sbusregs, int nregs);
265
266/* CPU probing helpers. */
267int cpu_find_by_instance(int instance, int *prom_node, int *mid);
268int cpu_find_by_mid(int mid, int *prom_node);
269int cpu_get_hwmid(int prom_node);
270
271extern spinlock_t prom_lock;
272
273#endif /* !(__SPARC_OPLIB_H) */
diff --git a/include/asm-sparc/oplib_32.h b/include/asm-sparc/oplib_32.h
new file mode 100644
index 000000000000..b2631da259e0
--- /dev/null
+++ b/include/asm-sparc/oplib_32.h
@@ -0,0 +1,272 @@
1/*
2 * oplib.h: Describes the interface and available routines in the
3 * Linux Prom library.
4 *
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 */
7
8#ifndef __SPARC_OPLIB_H
9#define __SPARC_OPLIB_H
10
11#include <asm/openprom.h>
12#include <linux/spinlock.h>
13#include <linux/compiler.h>
14
15/* The master romvec pointer... */
16extern struct linux_romvec *romvec;
17
18/* Enumeration to describe the prom major version we have detected. */
19enum prom_major_version {
20 PROM_V0, /* Original sun4c V0 prom */
21 PROM_V2, /* sun4c and early sun4m V2 prom */
22 PROM_V3, /* sun4m and later, up to sun4d/sun4e machines V3 */
23 PROM_P1275, /* IEEE compliant ISA based Sun PROM, only sun4u */
24 PROM_SUN4, /* Old sun4 proms are totally different, but we'll shoehorn it to make it fit */
25};
26
27extern enum prom_major_version prom_vers;
28/* Revision, and firmware revision. */
29extern unsigned int prom_rev, prom_prev;
30
31/* Root node of the prom device tree, this stays constant after
32 * initialization is complete.
33 */
34extern int prom_root_node;
35
36/* Pointer to prom structure containing the device tree traversal
37 * and usage utility functions. Only prom-lib should use these,
38 * users use the interface defined by the library only!
39 */
40extern struct linux_nodeops *prom_nodeops;
41
42/* The functions... */
43
44/* You must call prom_init() before using any of the library services,
45 * preferably as early as possible. Pass it the romvec pointer.
46 */
47extern void prom_init(struct linux_romvec *rom_ptr);
48
49/* Boot argument acquisition, returns the boot command line string. */
50extern char *prom_getbootargs(void);
51
52/* Device utilities. */
53
54/* Map and unmap devices in IO space at virtual addresses. Note that the
55 * virtual address you pass is a request and the prom may put your mappings
56 * somewhere else, so check your return value as that is where your new
57 * mappings really are!
58 *
59 * Another note, these are only available on V2 or higher proms!
60 */
61extern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes);
62extern void prom_unmapio(char *virt_addr, unsigned int num_bytes);
63
64/* Device operations. */
65
66/* Open the device described by the passed string. Note, that the format
67 * of the string is different on V0 vs. V2->higher proms. The caller must
68 * know what he/she is doing! Returns the device descriptor, an int.
69 */
70extern int prom_devopen(char *device_string);
71
72/* Close a previously opened device described by the passed integer
73 * descriptor.
74 */
75extern int prom_devclose(int device_handle);
76
77/* Do a seek operation on the device described by the passed integer
78 * descriptor.
79 */
80extern void prom_seek(int device_handle, unsigned int seek_hival,
81 unsigned int seek_lowval);
82
83/* Miscellaneous routines, don't really fit in any category per se. */
84
85/* Reboot the machine with the command line passed. */
86extern void prom_reboot(char *boot_command);
87
88/* Evaluate the forth string passed. */
89extern void prom_feval(char *forth_string);
90
91/* Enter the prom, with possibility of continuation with the 'go'
92 * command in newer proms.
93 */
94extern void prom_cmdline(void);
95
96/* Enter the prom, with no chance of continuation for the stand-alone
97 * which calls this.
98 */
99extern void prom_halt(void) __attribute__ ((noreturn));
100
101/* Set the PROM 'sync' callback function to the passed function pointer.
102 * When the user gives the 'sync' command at the prom prompt while the
103 * kernel is still active, the prom will call this routine.
104 *
105 * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
106 */
107typedef void (*sync_func_t)(void);
108extern void prom_setsync(sync_func_t func_ptr);
109
110/* Acquire the IDPROM of the root node in the prom device tree. This
111 * gets passed a buffer where you would like it stuffed. The return value
112 * is the format type of this idprom or 0xff on error.
113 */
114extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
115
116/* Get the prom major version. */
117extern int prom_version(void);
118
119/* Get the prom plugin revision. */
120extern int prom_getrev(void);
121
122/* Get the prom firmware revision. */
123extern int prom_getprev(void);
124
125/* Character operations to/from the console.... */
126
127/* Non-blocking get character from console. */
128extern int prom_nbgetchar(void);
129
130/* Non-blocking put character to console. */
131extern int prom_nbputchar(char character);
132
133/* Blocking get character from console. */
134extern char prom_getchar(void);
135
136/* Blocking put character to console. */
137extern void prom_putchar(char character);
138
139/* Prom's internal routines, don't use in kernel/boot code. */
140extern void prom_printf(char *fmt, ...);
141extern void prom_write(const char *buf, unsigned int len);
142
143/* Multiprocessor operations... */
144
145/* Start the CPU with the given device tree node, context table, and context
146 * at the passed program counter.
147 */
148extern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
149 int context, char *program_counter);
150
151/* Stop the CPU with the passed device tree node. */
152extern int prom_stopcpu(int cpunode);
153
154/* Idle the CPU with the passed device tree node. */
155extern int prom_idlecpu(int cpunode);
156
157/* Re-Start the CPU with the passed device tree node. */
158extern int prom_restartcpu(int cpunode);
159
160/* PROM memory allocation facilities... */
161
162/* Allocated at possibly the given virtual address a chunk of the
163 * indicated size.
164 */
165extern char *prom_alloc(char *virt_hint, unsigned int size);
166
167/* Free a previously allocated chunk. */
168extern void prom_free(char *virt_addr, unsigned int size);
169
170/* Sun4/sun4c specific memory-management startup hook. */
171
172/* Map the passed segment in the given context at the passed
173 * virtual address.
174 */
175extern void prom_putsegment(int context, unsigned long virt_addr,
176 int physical_segment);
177
178
179/* PROM device tree traversal functions... */
180
181#ifdef PROMLIB_INTERNAL
182
183/* Internal version of prom_getchild. */
184extern int __prom_getchild(int parent_node);
185
186/* Internal version of prom_getsibling. */
187extern int __prom_getsibling(int node);
188
189#endif
190
191
192/* Get the child node of the given node, or zero if no child exists. */
193extern int prom_getchild(int parent_node);
194
195/* Get the next sibling node of the given node, or zero if no further
196 * siblings exist.
197 */
198extern int prom_getsibling(int node);
199
200/* Get the length, at the passed node, of the given property type.
201 * Returns -1 on error (ie. no such property at this node).
202 */
203extern int prom_getproplen(int thisnode, char *property);
204
205/* Fetch the requested property using the given buffer. Returns
206 * the number of bytes the prom put into your buffer or -1 on error.
207 */
208extern int __must_check prom_getproperty(int thisnode, char *property,
209 char *prop_buffer, int propbuf_size);
210
211/* Acquire an integer property. */
212extern int prom_getint(int node, char *property);
213
214/* Acquire an integer property, with a default value. */
215extern int prom_getintdefault(int node, char *property, int defval);
216
217/* Acquire a boolean property, 0=FALSE 1=TRUE. */
218extern int prom_getbool(int node, char *prop);
219
220/* Acquire a string property, null string on error. */
221extern void prom_getstring(int node, char *prop, char *buf, int bufsize);
222
223/* Does the passed node have the given "name"? YES=1 NO=0 */
224extern int prom_nodematch(int thisnode, char *name);
225
226/* Search all siblings starting at the passed node for "name" matching
227 * the given string. Returns the node on success, zero on failure.
228 */
229extern int prom_searchsiblings(int node_start, char *name);
230
231/* Return the first property type, as a string, for the given node.
232 * Returns a null string on error.
233 */
234extern char *prom_firstprop(int node, char *buffer);
235
236/* Returns the next property after the passed property for the given
237 * node. Returns null string on failure.
238 */
239extern char *prom_nextprop(int node, char *prev_property, char *buffer);
240
241/* Returns phandle of the path specified */
242extern int prom_finddevice(char *name);
243
244/* Returns 1 if the specified node has given property. */
245extern int prom_node_has_property(int node, char *property);
246
247/* Set the indicated property at the given node with the passed value.
248 * Returns the number of bytes of your value that the prom took.
249 */
250extern int prom_setprop(int node, char *prop_name, char *prop_value,
251 int value_size);
252
253extern int prom_pathtoinode(char *path);
254extern int prom_inst2pkg(int);
255
256/* Dorking with Bus ranges... */
257
258/* Apply promlib probes OBIO ranges to registers. */
259extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
260
261/* Apply ranges of any prom node (and optionally parent node as well) to registers. */
262extern void prom_apply_generic_ranges(int node, int parent,
263 struct linux_prom_registers *sbusregs, int nregs);
264
265/* CPU probing helpers. */
266int cpu_find_by_instance(int instance, int *prom_node, int *mid);
267int cpu_find_by_mid(int mid, int *prom_node);
268int cpu_get_hwmid(int prom_node);
269
270extern spinlock_t prom_lock;
271
272#endif /* !(__SPARC_OPLIB_H) */
diff --git a/include/asm-sparc/oplib_64.h b/include/asm-sparc/oplib_64.h
new file mode 100644
index 000000000000..6d2c2ca98039
--- /dev/null
+++ b/include/asm-sparc/oplib_64.h
@@ -0,0 +1,322 @@
1/* oplib.h: Describes the interface and available routines in the
2 * Linux Prom library.
3 *
4 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
5 * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7
8#ifndef __SPARC64_OPLIB_H
9#define __SPARC64_OPLIB_H
10
11#include <asm/openprom.h>
12
13/* OBP version string. */
14extern char prom_version[];
15
16/* Root node of the prom device tree, this stays constant after
17 * initialization is complete.
18 */
19extern int prom_root_node;
20
21/* PROM stdin and stdout */
22extern int prom_stdin, prom_stdout;
23
24/* /chosen node of the prom device tree, this stays constant after
25 * initialization is complete.
26 */
27extern int prom_chosen_node;
28
29/* Helper values and strings in arch/sparc64/kernel/head.S */
30extern const char prom_peer_name[];
31extern const char prom_compatible_name[];
32extern const char prom_root_compatible[];
33extern const char prom_cpu_compatible[];
34extern const char prom_finddev_name[];
35extern const char prom_chosen_path[];
36extern const char prom_cpu_path[];
37extern const char prom_getprop_name[];
38extern const char prom_mmu_name[];
39extern const char prom_callmethod_name[];
40extern const char prom_translate_name[];
41extern const char prom_map_name[];
42extern const char prom_unmap_name[];
43extern int prom_mmu_ihandle_cache;
44extern unsigned int prom_boot_mapped_pc;
45extern unsigned int prom_boot_mapping_mode;
46extern unsigned long prom_boot_mapping_phys_high, prom_boot_mapping_phys_low;
47
48struct linux_mlist_p1275 {
49 struct linux_mlist_p1275 *theres_more;
50 unsigned long start_adr;
51 unsigned long num_bytes;
52};
53
54struct linux_mem_p1275 {
55 struct linux_mlist_p1275 **p1275_totphys;
56 struct linux_mlist_p1275 **p1275_prommap;
57 struct linux_mlist_p1275 **p1275_available; /* What we can use */
58};
59
60/* The functions... */
61
62/* You must call prom_init() before using any of the library services,
63 * preferably as early as possible. Pass it the romvec pointer.
64 */
65extern void prom_init(void *cif_handler, void *cif_stack);
66
67/* Boot argument acquisition, returns the boot command line string. */
68extern char *prom_getbootargs(void);
69
70/* Device utilities. */
71
72/* Device operations. */
73
74/* Open the device described by the passed string. Note, that the format
75 * of the string is different on V0 vs. V2->higher proms. The caller must
76 * know what he/she is doing! Returns the device descriptor, an int.
77 */
78extern int prom_devopen(const char *device_string);
79
80/* Close a previously opened device described by the passed integer
81 * descriptor.
82 */
83extern int prom_devclose(int device_handle);
84
85/* Do a seek operation on the device described by the passed integer
86 * descriptor.
87 */
88extern void prom_seek(int device_handle, unsigned int seek_hival,
89 unsigned int seek_lowval);
90
91/* Miscellaneous routines, don't really fit in any category per se. */
92
93/* Reboot the machine with the command line passed. */
94extern void prom_reboot(const char *boot_command);
95
96/* Evaluate the forth string passed. */
97extern void prom_feval(const char *forth_string);
98
99/* Enter the prom, with possibility of continuation with the 'go'
100 * command in newer proms.
101 */
102extern void prom_cmdline(void);
103
104/* Enter the prom, with no chance of continuation for the stand-alone
105 * which calls this.
106 */
107extern void prom_halt(void) __attribute__ ((noreturn));
108
109/* Halt and power-off the machine. */
110extern void prom_halt_power_off(void) __attribute__ ((noreturn));
111
112/* Set the PROM 'sync' callback function to the passed function pointer.
113 * When the user gives the 'sync' command at the prom prompt while the
114 * kernel is still active, the prom will call this routine.
115 *
116 */
117typedef int (*callback_func_t)(long *cmd);
118extern void prom_setcallback(callback_func_t func_ptr);
119
120/* Acquire the IDPROM of the root node in the prom device tree. This
121 * gets passed a buffer where you would like it stuffed. The return value
122 * is the format type of this idprom or 0xff on error.
123 */
124extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
125
126/* Character operations to/from the console.... */
127
128/* Non-blocking get character from console. */
129extern int prom_nbgetchar(void);
130
131/* Non-blocking put character to console. */
132extern int prom_nbputchar(char character);
133
134/* Blocking get character from console. */
135extern char prom_getchar(void);
136
137/* Blocking put character to console. */
138extern void prom_putchar(char character);
139
140/* Prom's internal routines, don't use in kernel/boot code. */
141extern void prom_printf(const char *fmt, ...);
142extern void prom_write(const char *buf, unsigned int len);
143
144/* Multiprocessor operations... */
145#ifdef CONFIG_SMP
146/* Start the CPU with the given device tree node at the passed program
147 * counter with the given arg passed in via register %o0.
148 */
149extern void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg);
150
151/* Start the CPU with the given cpu ID at the passed program
152 * counter with the given arg passed in via register %o0.
153 */
154extern void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg);
155
156/* Stop the CPU with the given cpu ID. */
157extern void prom_stopcpu_cpuid(int cpuid);
158
159/* Stop the current CPU. */
160extern void prom_stopself(void);
161
162/* Idle the current CPU. */
163extern void prom_idleself(void);
164
165/* Resume the CPU with the passed device tree node. */
166extern void prom_resumecpu(int cpunode);
167#endif
168
169/* Power management interfaces. */
170
171/* Put the current CPU to sleep. */
172extern void prom_sleepself(void);
173
174/* Put the entire system to sleep. */
175extern int prom_sleepsystem(void);
176
177/* Initiate a wakeup event. */
178extern int prom_wakeupsystem(void);
179
180/* MMU and memory related OBP interfaces. */
181
182/* Get unique string identifying SIMM at given physical address. */
183extern int prom_getunumber(int syndrome_code,
184 unsigned long phys_addr,
185 char *buf, int buflen);
186
187/* Retain physical memory to the caller across soft resets. */
188extern unsigned long prom_retain(const char *name,
189 unsigned long pa_low, unsigned long pa_high,
190 long size, long align);
191
192/* Load explicit I/D TLB entries into the calling processor. */
193extern long prom_itlb_load(unsigned long index,
194 unsigned long tte_data,
195 unsigned long vaddr);
196
197extern long prom_dtlb_load(unsigned long index,
198 unsigned long tte_data,
199 unsigned long vaddr);
200
201/* Map/Unmap client program address ranges. First the format of
202 * the mapping mode argument.
203 */
204#define PROM_MAP_WRITE 0x0001 /* Writable */
205#define PROM_MAP_READ 0x0002 /* Readable - sw */
206#define PROM_MAP_EXEC 0x0004 /* Executable - sw */
207#define PROM_MAP_LOCKED 0x0010 /* Locked, use i/dtlb load calls for this instead */
208#define PROM_MAP_CACHED 0x0020 /* Cacheable in both L1 and L2 caches */
209#define PROM_MAP_SE 0x0040 /* Side-Effects */
210#define PROM_MAP_GLOB 0x0080 /* Global */
211#define PROM_MAP_IE 0x0100 /* Invert-Endianness */
212#define PROM_MAP_DEFAULT (PROM_MAP_WRITE | PROM_MAP_READ | PROM_MAP_EXEC | PROM_MAP_CACHED)
213
214extern int prom_map(int mode, unsigned long size,
215 unsigned long vaddr, unsigned long paddr);
216extern void prom_unmap(unsigned long size, unsigned long vaddr);
217
218
219/* PROM device tree traversal functions... */
220
221#ifdef PROMLIB_INTERNAL
222
223/* Internal version of prom_getchild. */
224extern int __prom_getchild(int parent_node);
225
226/* Internal version of prom_getsibling. */
227extern int __prom_getsibling(int node);
228
229#endif
230
231/* Get the child node of the given node, or zero if no child exists. */
232extern int prom_getchild(int parent_node);
233
234/* Get the next sibling node of the given node, or zero if no further
235 * siblings exist.
236 */
237extern int prom_getsibling(int node);
238
239/* Get the length, at the passed node, of the given property type.
240 * Returns -1 on error (ie. no such property at this node).
241 */
242extern int prom_getproplen(int thisnode, const char *property);
243
244/* Fetch the requested property using the given buffer. Returns
245 * the number of bytes the prom put into your buffer or -1 on error.
246 */
247extern int prom_getproperty(int thisnode, const char *property,
248 char *prop_buffer, int propbuf_size);
249
250/* Acquire an integer property. */
251extern int prom_getint(int node, const char *property);
252
253/* Acquire an integer property, with a default value. */
254extern int prom_getintdefault(int node, const char *property, int defval);
255
256/* Acquire a boolean property, 0=FALSE 1=TRUE. */
257extern int prom_getbool(int node, const char *prop);
258
259/* Acquire a string property, null string on error. */
260extern void prom_getstring(int node, const char *prop, char *buf, int bufsize);
261
262/* Does the passed node have the given "name"? YES=1 NO=0 */
263extern int prom_nodematch(int thisnode, const char *name);
264
265/* Search all siblings starting at the passed node for "name" matching
266 * the given string. Returns the node on success, zero on failure.
267 */
268extern int prom_searchsiblings(int node_start, const char *name);
269
270/* Return the first property type, as a string, for the given node.
271 * Returns a null string on error. Buffer should be at least 32B long.
272 */
273extern char *prom_firstprop(int node, char *buffer);
274
275/* Returns the next property after the passed property for the given
276 * node. Returns null string on failure. Buffer should be at least 32B long.
277 */
278extern char *prom_nextprop(int node, const char *prev_property, char *buffer);
279
280/* Returns 1 if the specified node has given property. */
281extern int prom_node_has_property(int node, const char *property);
282
283/* Returns phandle of the path specified */
284extern int prom_finddevice(const char *name);
285
286/* Set the indicated property at the given node with the passed value.
287 * Returns the number of bytes of your value that the prom took.
288 */
289extern int prom_setprop(int node, const char *prop_name, char *prop_value,
290 int value_size);
291
292extern int prom_pathtoinode(const char *path);
293extern int prom_inst2pkg(int);
294extern int prom_service_exists(const char *service_name);
295extern void prom_sun4v_guest_soft_state(void);
296
297extern int prom_ihandle2path(int handle, char *buffer, int bufsize);
298
299/* Client interface level routines. */
300extern long p1275_cmd(const char *, long, ...);
301
302#if 0
303#define P1275_SIZE(x) ((((long)((x) / 32)) << 32) | (x))
304#else
305#define P1275_SIZE(x) x
306#endif
307
308/* We support at most 16 input and 1 output argument */
309#define P1275_ARG_NUMBER 0
310#define P1275_ARG_IN_STRING 1
311#define P1275_ARG_OUT_BUF 2
312#define P1275_ARG_OUT_32B 3
313#define P1275_ARG_IN_FUNCTION 4
314#define P1275_ARG_IN_BUF 5
315#define P1275_ARG_IN_64B 6
316
317#define P1275_IN(x) ((x) & 0xf)
318#define P1275_OUT(x) (((x) << 4) & 0xf0)
319#define P1275_INOUT(i,o) (P1275_IN(i)|P1275_OUT(o))
320#define P1275_ARG(n,x) ((x) << ((n)*3 + 8))
321
322#endif /* !(__SPARC64_OPLIB_H) */
diff --git a/include/asm-sparc/page.h b/include/asm-sparc/page.h
index 6aa9e4c910cf..f32f49fcf75c 100644
--- a/include/asm-sparc/page.h
+++ b/include/asm-sparc/page.h
@@ -1,165 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_PAGE_H
2 * page.h: Various defines and such for MMU operations on the Sparc for 2#define ___ASM_SPARC_PAGE_H
3 * the Linux kernel. 3#if defined(__sparc__) && defined(__arch64__)
4 * 4#include <asm-sparc/page_64.h>
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 */
7
8#ifndef _SPARC_PAGE_H
9#define _SPARC_PAGE_H
10
11#ifdef CONFIG_SUN4
12#define PAGE_SHIFT 13
13#else 5#else
14#define PAGE_SHIFT 12 6#include <asm-sparc/page_32.h>
15#endif 7#endif
16#ifndef __ASSEMBLY__
17/* I have my suspicions... -DaveM */
18#define PAGE_SIZE (1UL << PAGE_SHIFT)
19#else
20#define PAGE_SIZE (1 << PAGE_SHIFT)
21#endif
22#define PAGE_MASK (~(PAGE_SIZE-1))
23
24#include <asm/btfixup.h>
25
26#ifndef __ASSEMBLY__
27
28#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
29#define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE)
30#define clear_user_page(addr, vaddr, page) \
31 do { clear_page(addr); \
32 sparc_flush_page_to_ram(page); \
33 } while (0)
34#define copy_user_page(to, from, vaddr, page) \
35 do { copy_page(to, from); \
36 sparc_flush_page_to_ram(page); \
37 } while (0)
38
39/* The following structure is used to hold the physical
40 * memory configuration of the machine. This is filled in
41 * prom_meminit() and is later used by mem_init() to set up
42 * mem_map[]. We statically allocate SPARC_PHYS_BANKS+1 of
43 * these structs, this is arbitrary. The entry after the
44 * last valid one has num_bytes==0.
45 */
46struct sparc_phys_banks {
47 unsigned long base_addr;
48 unsigned long num_bytes;
49};
50
51#define SPARC_PHYS_BANKS 32
52
53extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS+1];
54
55/* Cache alias structure. Entry is valid if context != -1. */
56struct cache_palias {
57 unsigned long vaddr;
58 int context;
59};
60
61extern struct cache_palias *sparc_aliases;
62
63/* passing structs on the Sparc slow us down tremendously... */
64
65/* #define STRICT_MM_TYPECHECKS */
66
67#ifdef STRICT_MM_TYPECHECKS
68/*
69 * These are used to make use of C type-checking..
70 */
71typedef struct { unsigned long pte; } pte_t;
72typedef struct { unsigned long iopte; } iopte_t;
73typedef struct { unsigned long pmdv[16]; } pmd_t;
74typedef struct { unsigned long pgd; } pgd_t;
75typedef struct { unsigned long ctxd; } ctxd_t;
76typedef struct { unsigned long pgprot; } pgprot_t;
77typedef struct { unsigned long iopgprot; } iopgprot_t;
78
79#define pte_val(x) ((x).pte)
80#define iopte_val(x) ((x).iopte)
81#define pmd_val(x) ((x).pmdv[0])
82#define pgd_val(x) ((x).pgd)
83#define ctxd_val(x) ((x).ctxd)
84#define pgprot_val(x) ((x).pgprot)
85#define iopgprot_val(x) ((x).iopgprot)
86
87#define __pte(x) ((pte_t) { (x) } )
88#define __iopte(x) ((iopte_t) { (x) } )
89/* #define __pmd(x) ((pmd_t) { (x) } ) */ /* XXX procedure with loop */
90#define __pgd(x) ((pgd_t) { (x) } )
91#define __ctxd(x) ((ctxd_t) { (x) } )
92#define __pgprot(x) ((pgprot_t) { (x) } )
93#define __iopgprot(x) ((iopgprot_t) { (x) } )
94
95#else
96/*
97 * .. while these make it easier on the compiler
98 */
99typedef unsigned long pte_t;
100typedef unsigned long iopte_t;
101typedef struct { unsigned long pmdv[16]; } pmd_t;
102typedef unsigned long pgd_t;
103typedef unsigned long ctxd_t;
104typedef unsigned long pgprot_t;
105typedef unsigned long iopgprot_t;
106
107#define pte_val(x) (x)
108#define iopte_val(x) (x)
109#define pmd_val(x) ((x).pmdv[0])
110#define pgd_val(x) (x)
111#define ctxd_val(x) (x)
112#define pgprot_val(x) (x)
113#define iopgprot_val(x) (x)
114
115#define __pte(x) (x)
116#define __iopte(x) (x)
117/* #define __pmd(x) (x) */ /* XXX later */
118#define __pgd(x) (x)
119#define __ctxd(x) (x)
120#define __pgprot(x) (x)
121#define __iopgprot(x) (x)
122
123#endif
124
125typedef struct page *pgtable_t;
126
127extern unsigned long sparc_unmapped_base;
128
129BTFIXUPDEF_SETHI(sparc_unmapped_base)
130
131#define TASK_UNMAPPED_BASE BTFIXUP_SETHI(sparc_unmapped_base)
132
133#else /* !(__ASSEMBLY__) */
134
135#define __pgprot(x) (x)
136
137#endif /* !(__ASSEMBLY__) */
138
139/* to align the pointer to the (next) page boundary */
140#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
141
142#define PAGE_OFFSET 0xf0000000
143#ifndef __ASSEMBLY__
144extern unsigned long phys_base;
145extern unsigned long pfn_base;
146#endif 8#endif
147#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + phys_base)
148#define __va(x) ((void *)((unsigned long) (x) - phys_base + PAGE_OFFSET))
149
150#define virt_to_phys __pa
151#define phys_to_virt __va
152
153#define ARCH_PFN_OFFSET (pfn_base)
154#define virt_to_page(kaddr) (mem_map + ((((unsigned long)(kaddr)-PAGE_OFFSET)>>PAGE_SHIFT)))
155
156#define pfn_valid(pfn) (((pfn) >= (pfn_base)) && (((pfn)-(pfn_base)) < max_mapnr))
157#define virt_addr_valid(kaddr) ((((unsigned long)(kaddr)-PAGE_OFFSET)>>PAGE_SHIFT) < max_mapnr)
158
159#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
160 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
161
162#include <asm-generic/memory_model.h>
163#include <asm-generic/page.h>
164
165#endif /* _SPARC_PAGE_H */
diff --git a/include/asm-sparc/page_32.h b/include/asm-sparc/page_32.h
new file mode 100644
index 000000000000..14de518cc38f
--- /dev/null
+++ b/include/asm-sparc/page_32.h
@@ -0,0 +1,163 @@
1/*
2 * page.h: Various defines and such for MMU operations on the Sparc for
3 * the Linux kernel.
4 *
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 */
7
8#ifndef _SPARC_PAGE_H
9#define _SPARC_PAGE_H
10
11#ifdef CONFIG_SUN4
12#define PAGE_SHIFT 13
13#else
14#define PAGE_SHIFT 12
15#endif
16#ifndef __ASSEMBLY__
17/* I have my suspicions... -DaveM */
18#define PAGE_SIZE (1UL << PAGE_SHIFT)
19#else
20#define PAGE_SIZE (1 << PAGE_SHIFT)
21#endif
22#define PAGE_MASK (~(PAGE_SIZE-1))
23
24#include <asm/btfixup.h>
25
26#ifndef __ASSEMBLY__
27
28#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
29#define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE)
30#define clear_user_page(addr, vaddr, page) \
31 do { clear_page(addr); \
32 sparc_flush_page_to_ram(page); \
33 } while (0)
34#define copy_user_page(to, from, vaddr, page) \
35 do { copy_page(to, from); \
36 sparc_flush_page_to_ram(page); \
37 } while (0)
38
39/* The following structure is used to hold the physical
40 * memory configuration of the machine. This is filled in
41 * prom_meminit() and is later used by mem_init() to set up
42 * mem_map[]. We statically allocate SPARC_PHYS_BANKS+1 of
43 * these structs, this is arbitrary. The entry after the
44 * last valid one has num_bytes==0.
45 */
46struct sparc_phys_banks {
47 unsigned long base_addr;
48 unsigned long num_bytes;
49};
50
51#define SPARC_PHYS_BANKS 32
52
53extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS+1];
54
55/* Cache alias structure. Entry is valid if context != -1. */
56struct cache_palias {
57 unsigned long vaddr;
58 int context;
59};
60
61/* passing structs on the Sparc slow us down tremendously... */
62
63/* #define STRICT_MM_TYPECHECKS */
64
65#ifdef STRICT_MM_TYPECHECKS
66/*
67 * These are used to make use of C type-checking..
68 */
69typedef struct { unsigned long pte; } pte_t;
70typedef struct { unsigned long iopte; } iopte_t;
71typedef struct { unsigned long pmdv[16]; } pmd_t;
72typedef struct { unsigned long pgd; } pgd_t;
73typedef struct { unsigned long ctxd; } ctxd_t;
74typedef struct { unsigned long pgprot; } pgprot_t;
75typedef struct { unsigned long iopgprot; } iopgprot_t;
76
77#define pte_val(x) ((x).pte)
78#define iopte_val(x) ((x).iopte)
79#define pmd_val(x) ((x).pmdv[0])
80#define pgd_val(x) ((x).pgd)
81#define ctxd_val(x) ((x).ctxd)
82#define pgprot_val(x) ((x).pgprot)
83#define iopgprot_val(x) ((x).iopgprot)
84
85#define __pte(x) ((pte_t) { (x) } )
86#define __iopte(x) ((iopte_t) { (x) } )
87/* #define __pmd(x) ((pmd_t) { (x) } ) */ /* XXX procedure with loop */
88#define __pgd(x) ((pgd_t) { (x) } )
89#define __ctxd(x) ((ctxd_t) { (x) } )
90#define __pgprot(x) ((pgprot_t) { (x) } )
91#define __iopgprot(x) ((iopgprot_t) { (x) } )
92
93#else
94/*
95 * .. while these make it easier on the compiler
96 */
97typedef unsigned long pte_t;
98typedef unsigned long iopte_t;
99typedef struct { unsigned long pmdv[16]; } pmd_t;
100typedef unsigned long pgd_t;
101typedef unsigned long ctxd_t;
102typedef unsigned long pgprot_t;
103typedef unsigned long iopgprot_t;
104
105#define pte_val(x) (x)
106#define iopte_val(x) (x)
107#define pmd_val(x) ((x).pmdv[0])
108#define pgd_val(x) (x)
109#define ctxd_val(x) (x)
110#define pgprot_val(x) (x)
111#define iopgprot_val(x) (x)
112
113#define __pte(x) (x)
114#define __iopte(x) (x)
115/* #define __pmd(x) (x) */ /* XXX later */
116#define __pgd(x) (x)
117#define __ctxd(x) (x)
118#define __pgprot(x) (x)
119#define __iopgprot(x) (x)
120
121#endif
122
123typedef struct page *pgtable_t;
124
125extern unsigned long sparc_unmapped_base;
126
127BTFIXUPDEF_SETHI(sparc_unmapped_base)
128
129#define TASK_UNMAPPED_BASE BTFIXUP_SETHI(sparc_unmapped_base)
130
131#else /* !(__ASSEMBLY__) */
132
133#define __pgprot(x) (x)
134
135#endif /* !(__ASSEMBLY__) */
136
137/* to align the pointer to the (next) page boundary */
138#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
139
140#define PAGE_OFFSET 0xf0000000
141#ifndef __ASSEMBLY__
142extern unsigned long phys_base;
143extern unsigned long pfn_base;
144#endif
145#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + phys_base)
146#define __va(x) ((void *)((unsigned long) (x) - phys_base + PAGE_OFFSET))
147
148#define virt_to_phys __pa
149#define phys_to_virt __va
150
151#define ARCH_PFN_OFFSET (pfn_base)
152#define virt_to_page(kaddr) (mem_map + ((((unsigned long)(kaddr)-PAGE_OFFSET)>>PAGE_SHIFT)))
153
154#define pfn_valid(pfn) (((pfn) >= (pfn_base)) && (((pfn)-(pfn_base)) < max_mapnr))
155#define virt_addr_valid(kaddr) ((((unsigned long)(kaddr)-PAGE_OFFSET)>>PAGE_SHIFT) < max_mapnr)
156
157#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
158 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
159
160#include <asm-generic/memory_model.h>
161#include <asm-generic/page.h>
162
163#endif /* _SPARC_PAGE_H */
diff --git a/include/asm-sparc/page_64.h b/include/asm-sparc/page_64.h
new file mode 100644
index 000000000000..a8a2bba032c1
--- /dev/null
+++ b/include/asm-sparc/page_64.h
@@ -0,0 +1,138 @@
1#ifndef _SPARC64_PAGE_H
2#define _SPARC64_PAGE_H
3
4#include <linux/const.h>
5
6#if defined(CONFIG_SPARC64_PAGE_SIZE_8KB)
7#define PAGE_SHIFT 13
8#elif defined(CONFIG_SPARC64_PAGE_SIZE_64KB)
9#define PAGE_SHIFT 16
10#else
11#error No page size specified in kernel configuration
12#endif
13
14#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
15#define PAGE_MASK (~(PAGE_SIZE-1))
16
17/* Flushing for D-cache alias handling is only needed if
18 * the page size is smaller than 16K.
19 */
20#if PAGE_SHIFT < 14
21#define DCACHE_ALIASING_POSSIBLE
22#endif
23
24#if defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
25#define HPAGE_SHIFT 22
26#elif defined(CONFIG_HUGETLB_PAGE_SIZE_512K)
27#define HPAGE_SHIFT 19
28#elif defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
29#define HPAGE_SHIFT 16
30#endif
31
32#ifdef CONFIG_HUGETLB_PAGE
33#define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT)
34#define HPAGE_MASK (~(HPAGE_SIZE - 1UL))
35#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
36#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
37#endif
38
39#ifndef __ASSEMBLY__
40
41extern void _clear_page(void *page);
42#define clear_page(X) _clear_page((void *)(X))
43struct page;
44extern void clear_user_page(void *addr, unsigned long vaddr, struct page *page);
45#define copy_page(X,Y) memcpy((void *)(X), (void *)(Y), PAGE_SIZE)
46extern void copy_user_page(void *to, void *from, unsigned long vaddr, struct page *topage);
47
48/* Unlike sparc32, sparc64's parameter passing API is more
49 * sane in that structures which as small enough are passed
50 * in registers instead of on the stack. Thus, setting
51 * STRICT_MM_TYPECHECKS does not generate worse code so
52 * let's enable it to get the type checking.
53 */
54
55#define STRICT_MM_TYPECHECKS
56
57#ifdef STRICT_MM_TYPECHECKS
58/* These are used to make use of C type-checking.. */
59typedef struct { unsigned long pte; } pte_t;
60typedef struct { unsigned long iopte; } iopte_t;
61typedef struct { unsigned int pmd; } pmd_t;
62typedef struct { unsigned int pgd; } pgd_t;
63typedef struct { unsigned long pgprot; } pgprot_t;
64
65#define pte_val(x) ((x).pte)
66#define iopte_val(x) ((x).iopte)
67#define pmd_val(x) ((x).pmd)
68#define pgd_val(x) ((x).pgd)
69#define pgprot_val(x) ((x).pgprot)
70
71#define __pte(x) ((pte_t) { (x) } )
72#define __iopte(x) ((iopte_t) { (x) } )
73#define __pmd(x) ((pmd_t) { (x) } )
74#define __pgd(x) ((pgd_t) { (x) } )
75#define __pgprot(x) ((pgprot_t) { (x) } )
76
77#else
78/* .. while these make it easier on the compiler */
79typedef unsigned long pte_t;
80typedef unsigned long iopte_t;
81typedef unsigned int pmd_t;
82typedef unsigned int pgd_t;
83typedef unsigned long pgprot_t;
84
85#define pte_val(x) (x)
86#define iopte_val(x) (x)
87#define pmd_val(x) (x)
88#define pgd_val(x) (x)
89#define pgprot_val(x) (x)
90
91#define __pte(x) (x)
92#define __iopte(x) (x)
93#define __pmd(x) (x)
94#define __pgd(x) (x)
95#define __pgprot(x) (x)
96
97#endif /* (STRICT_MM_TYPECHECKS) */
98
99typedef struct page *pgtable_t;
100
101#define TASK_UNMAPPED_BASE (test_thread_flag(TIF_32BIT) ? \
102 (_AC(0x0000000070000000,UL)) : \
103 (_AC(0xfffff80000000000,UL) + (1UL << 32UL)))
104
105#include <asm-generic/memory_model.h>
106
107#endif /* !(__ASSEMBLY__) */
108
109/* to align the pointer to the (next) page boundary */
110#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
111
112/* We used to stick this into a hard-coded global register (%g4)
113 * but that does not make sense anymore.
114 */
115#define PAGE_OFFSET _AC(0xFFFFF80000000000,UL)
116
117#ifndef __ASSEMBLY__
118
119#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET)
120#define __va(x) ((void *)((unsigned long) (x) + PAGE_OFFSET))
121
122#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
123
124#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr)>>PAGE_SHIFT)
125
126#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
127
128#define virt_to_phys __pa
129#define phys_to_virt __va
130
131#endif /* !(__ASSEMBLY__) */
132
133#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
134 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
135
136#include <asm-generic/page.h>
137
138#endif /* _SPARC64_PAGE_H */
diff --git a/include/asm-sparc/parport.h b/include/asm-sparc/parport.h
new file mode 100644
index 000000000000..7818b2523b8d
--- /dev/null
+++ b/include/asm-sparc/parport.h
@@ -0,0 +1,246 @@
1/* parport.h: sparc64 specific parport initialization and dma.
2 *
3 * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be)
4 */
5
6#ifndef _ASM_SPARC64_PARPORT_H
7#define _ASM_SPARC64_PARPORT_H 1
8
9#include <asm/ebus.h>
10#include <asm/ns87303.h>
11#include <asm/of_device.h>
12#include <asm/prom.h>
13
14#define PARPORT_PC_MAX_PORTS PARPORT_MAX
15
16/*
17 * While sparc64 doesn't have an ISA DMA API, we provide something that looks
18 * close enough to make parport_pc happy
19 */
20#define HAS_DMA
21
22static DEFINE_SPINLOCK(dma_spin_lock);
23
24#define claim_dma_lock() \
25({ unsigned long flags; \
26 spin_lock_irqsave(&dma_spin_lock, flags); \
27 flags; \
28})
29
30#define release_dma_lock(__flags) \
31 spin_unlock_irqrestore(&dma_spin_lock, __flags);
32
33static struct sparc_ebus_info {
34 struct ebus_dma_info info;
35 unsigned int addr;
36 unsigned int count;
37 int lock;
38
39 struct parport *port;
40} sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
41
42static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS);
43
44static inline int request_dma(unsigned int dmanr, const char *device_id)
45{
46 if (dmanr >= PARPORT_PC_MAX_PORTS)
47 return -EINVAL;
48 if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
49 return -EBUSY;
50 return 0;
51}
52
53static inline void free_dma(unsigned int dmanr)
54{
55 if (dmanr >= PARPORT_PC_MAX_PORTS) {
56 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
57 return;
58 }
59 if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
60 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
61 return;
62 }
63}
64
65static inline void enable_dma(unsigned int dmanr)
66{
67 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
68
69 if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
70 sparc_ebus_dmas[dmanr].addr,
71 sparc_ebus_dmas[dmanr].count))
72 BUG();
73}
74
75static inline void disable_dma(unsigned int dmanr)
76{
77 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
78}
79
80static inline void clear_dma_ff(unsigned int dmanr)
81{
82 /* nothing */
83}
84
85static inline void set_dma_mode(unsigned int dmanr, char mode)
86{
87 ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
88}
89
90static inline void set_dma_addr(unsigned int dmanr, unsigned int addr)
91{
92 sparc_ebus_dmas[dmanr].addr = addr;
93}
94
95static inline void set_dma_count(unsigned int dmanr, unsigned int count)
96{
97 sparc_ebus_dmas[dmanr].count = count;
98}
99
100static inline unsigned int get_dma_residue(unsigned int dmanr)
101{
102 return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
103}
104
105static int __devinit ecpp_probe(struct of_device *op, const struct of_device_id *match)
106{
107 unsigned long base = op->resource[0].start;
108 unsigned long config = op->resource[1].start;
109 unsigned long d_base = op->resource[2].start;
110 unsigned long d_len;
111 struct device_node *parent;
112 struct parport *p;
113 int slot, err;
114
115 parent = op->node->parent;
116 if (!strcmp(parent->name, "dma")) {
117 p = parport_pc_probe_port(base, base + 0x400,
118 op->irqs[0], PARPORT_DMA_NOFIFO,
119 op->dev.parent->parent);
120 if (!p)
121 return -ENOMEM;
122 dev_set_drvdata(&op->dev, p);
123 return 0;
124 }
125
126 for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) {
127 if (!test_and_set_bit(slot, dma_slot_map))
128 break;
129 }
130 err = -ENODEV;
131 if (slot >= PARPORT_PC_MAX_PORTS)
132 goto out_err;
133
134 spin_lock_init(&sparc_ebus_dmas[slot].info.lock);
135
136 d_len = (op->resource[2].end - d_base) + 1UL;
137 sparc_ebus_dmas[slot].info.regs =
138 of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA");
139
140 if (!sparc_ebus_dmas[slot].info.regs)
141 goto out_clear_map;
142
143 sparc_ebus_dmas[slot].info.flags = 0;
144 sparc_ebus_dmas[slot].info.callback = NULL;
145 sparc_ebus_dmas[slot].info.client_cookie = NULL;
146 sparc_ebus_dmas[slot].info.irq = 0xdeadbeef;
147 strcpy(sparc_ebus_dmas[slot].info.name, "parport");
148 if (ebus_dma_register(&sparc_ebus_dmas[slot].info))
149 goto out_unmap_regs;
150
151 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1);
152
153 /* Configure IRQ to Push Pull, Level Low */
154 /* Enable ECP, set bit 2 of the CTR first */
155 outb(0x04, base + 0x02);
156 ns87303_modify(config, PCR,
157 PCR_EPP_ENABLE |
158 PCR_IRQ_ODRAIN,
159 PCR_ECP_ENABLE |
160 PCR_ECP_CLK_ENA |
161 PCR_IRQ_POLAR);
162
163 /* CTR bit 5 controls direction of port */
164 ns87303_modify(config, PTR,
165 0, PTR_LPT_REG_DIR);
166
167 p = parport_pc_probe_port(base, base + 0x400,
168 op->irqs[0],
169 slot,
170 op->dev.parent);
171 err = -ENOMEM;
172 if (!p)
173 goto out_disable_irq;
174
175 dev_set_drvdata(&op->dev, p);
176
177 return 0;
178
179out_disable_irq:
180 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
181 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
182
183out_unmap_regs:
184 of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len);
185
186out_clear_map:
187 clear_bit(slot, dma_slot_map);
188
189out_err:
190 return err;
191}
192
193static int __devexit ecpp_remove(struct of_device *op)
194{
195 struct parport *p = dev_get_drvdata(&op->dev);
196 int slot = p->dma;
197
198 parport_pc_unregister_port(p);
199
200 if (slot != PARPORT_DMA_NOFIFO) {
201 unsigned long d_base = op->resource[2].start;
202 unsigned long d_len;
203
204 d_len = (op->resource[2].end - d_base) + 1UL;
205
206 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
207 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
208 of_iounmap(&op->resource[2],
209 sparc_ebus_dmas[slot].info.regs,
210 d_len);
211 clear_bit(slot, dma_slot_map);
212 }
213
214 return 0;
215}
216
217static struct of_device_id ecpp_match[] = {
218 {
219 .name = "ecpp",
220 },
221 {
222 .name = "parallel",
223 .compatible = "ecpp",
224 },
225 {
226 .name = "parallel",
227 .compatible = "ns87317-ecpp",
228 },
229 {},
230};
231
232static struct of_platform_driver ecpp_driver = {
233 .name = "ecpp",
234 .match_table = ecpp_match,
235 .probe = ecpp_probe,
236 .remove = __devexit_p(ecpp_remove),
237};
238
239static int parport_pc_find_nonpci_ports(int autoirq, int autodma)
240{
241 of_register_driver(&ecpp_driver, &of_bus_type);
242
243 return 0;
244}
245
246#endif /* !(_ASM_SPARC64_PARPORT_H */
diff --git a/include/asm-sparc/pci.h b/include/asm-sparc/pci.h
index b93b6c79e08f..b807d52a4809 100644
--- a/include/asm-sparc/pci.h
+++ b/include/asm-sparc/pci.h
@@ -1,170 +1,8 @@
1#ifndef __SPARC_PCI_H 1#ifndef ___ASM_SPARC_PCI_H
2#define __SPARC_PCI_H 2#define ___ASM_SPARC_PCI_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#ifdef __KERNEL__ 4#include <asm-sparc/pci_64.h>
5 5#else
6/* Can be used to override the logic in pci_scan_bus for skipping 6#include <asm-sparc/pci_32.h>
7 * already-configured bus numbers - to be used for buggy BIOSes 7#endif
8 * or architectures with incomplete PCI setup by the loader.
9 */
10#define pcibios_assign_all_busses() 0
11#define pcibios_scan_all_fns(a, b) 0
12
13#define PCIBIOS_MIN_IO 0UL
14#define PCIBIOS_MIN_MEM 0UL
15
16#define PCI_IRQ_NONE 0xffffffff
17
18static inline void pcibios_set_master(struct pci_dev *dev)
19{
20 /* No special bus mastering setup handling */
21}
22
23static inline void pcibios_penalize_isa_irq(int irq, int active)
24{
25 /* We don't do dynamic PCI IRQ allocation */
26}
27
28/* Dynamic DMA mapping stuff.
29 */
30#define PCI_DMA_BUS_IS_PHYS (0)
31
32#include <asm/scatterlist.h>
33
34struct pci_dev;
35
36/* Allocate and map kernel buffer using consistent mode DMA for a device.
37 * hwdev should be valid struct pci_dev pointer for PCI devices.
38 */
39extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle);
40
41/* Free and unmap a consistent DMA buffer.
42 * cpu_addr is what was returned from pci_alloc_consistent,
43 * size must be the same as what as passed into pci_alloc_consistent,
44 * and likewise dma_addr must be the same as what *dma_addrp was set to.
45 *
46 * References to the memory and mappings assosciated with cpu_addr/dma_addr
47 * past this call are illegal.
48 */
49extern void pci_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle);
50
51/* Map a single buffer of the indicated size for DMA in streaming mode.
52 * The 32-bit bus address to use is returned.
53 *
54 * Once the device is given the dma address, the device owns this memory
55 * until either pci_unmap_single or pci_dma_sync_single_for_cpu is performed.
56 */
57extern dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction);
58
59/* Unmap a single streaming mode DMA translation. The dma_addr and size
60 * must match what was provided for in a previous pci_map_single call. All
61 * other usages are undefined.
62 *
63 * After this call, reads by the cpu to the buffer are guaranteed to see
64 * whatever the device wrote there.
65 */
66extern void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr, size_t size, int direction);
67
68/* pci_unmap_{single,page} is not a nop, thus... */
69#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
70 dma_addr_t ADDR_NAME;
71#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
72 __u32 LEN_NAME;
73#define pci_unmap_addr(PTR, ADDR_NAME) \
74 ((PTR)->ADDR_NAME)
75#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
76 (((PTR)->ADDR_NAME) = (VAL))
77#define pci_unmap_len(PTR, LEN_NAME) \
78 ((PTR)->LEN_NAME)
79#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
80 (((PTR)->LEN_NAME) = (VAL))
81
82/*
83 * Same as above, only with pages instead of mapped addresses.
84 */
85extern dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
86 unsigned long offset, size_t size, int direction);
87extern void pci_unmap_page(struct pci_dev *hwdev,
88 dma_addr_t dma_address, size_t size, int direction);
89
90/* Map a set of buffers described by scatterlist in streaming
91 * mode for DMA. This is the scather-gather version of the
92 * above pci_map_single interface. Here the scatter gather list
93 * elements are each tagged with the appropriate dma address
94 * and length. They are obtained via sg_dma_{address,length}(SG).
95 *
96 * NOTE: An implementation may be able to use a smaller number of
97 * DMA address/length pairs than there are SG table elements.
98 * (for example via virtual mapping capabilities)
99 * The routine returns the number of addr/length pairs actually
100 * used, at most nents.
101 *
102 * Device ownership issues as mentioned above for pci_map_single are
103 * the same here.
104 */
105extern int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction);
106
107/* Unmap a set of streaming mode DMA translations.
108 * Again, cpu read rules concerning calls here are the same as for
109 * pci_unmap_single() above.
110 */
111extern void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nhwents, int direction);
112
113/* Make physical memory consistent for a single
114 * streaming mode DMA translation after a transfer.
115 *
116 * If you perform a pci_map_single() but wish to interrogate the
117 * buffer using the cpu, yet do not wish to teardown the PCI dma
118 * mapping, you must call this function before doing so. At the
119 * next point you give the PCI dma address back to the card, you
120 * must first perform a pci_dma_sync_for_device, and then the device
121 * again owns the buffer.
122 */
123extern void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction);
124extern void pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction);
125
126/* Make physical memory consistent for a set of streaming
127 * mode DMA translations after a transfer.
128 *
129 * The same as pci_dma_sync_single_* but for a scatter-gather list,
130 * same rules and usage.
131 */
132extern void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction);
133extern void pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction);
134
135/* Return whether the given PCI device DMA address mask can
136 * be supported properly. For example, if your device can
137 * only drive the low 24-bits during PCI bus mastering, then
138 * you would pass 0x00ffffff as the mask to this function.
139 */
140static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
141{
142 return 1;
143}
144
145#ifdef CONFIG_PCI
146static inline void pci_dma_burst_advice(struct pci_dev *pdev,
147 enum pci_dma_burst_strategy *strat,
148 unsigned long *strategy_parameter)
149{
150 *strat = PCI_DMA_BURST_INFINITY;
151 *strategy_parameter = ~0UL;
152}
153#endif 8#endif
154
155#define PCI_DMA_ERROR_CODE (~(dma_addr_t)0x0)
156
157static inline int pci_dma_mapping_error(dma_addr_t dma_addr)
158{
159 return (dma_addr == PCI_DMA_ERROR_CODE);
160}
161
162struct device_node;
163extern struct device_node *pci_device_to_OF_node(struct pci_dev *pdev);
164
165#endif /* __KERNEL__ */
166
167/* generic pci stuff */
168#include <asm-generic/pci.h>
169
170#endif /* __SPARC_PCI_H */
diff --git a/include/asm-sparc/pci_32.h b/include/asm-sparc/pci_32.h
new file mode 100644
index 000000000000..b93b6c79e08f
--- /dev/null
+++ b/include/asm-sparc/pci_32.h
@@ -0,0 +1,170 @@
1#ifndef __SPARC_PCI_H
2#define __SPARC_PCI_H
3
4#ifdef __KERNEL__
5
6/* Can be used to override the logic in pci_scan_bus for skipping
7 * already-configured bus numbers - to be used for buggy BIOSes
8 * or architectures with incomplete PCI setup by the loader.
9 */
10#define pcibios_assign_all_busses() 0
11#define pcibios_scan_all_fns(a, b) 0
12
13#define PCIBIOS_MIN_IO 0UL
14#define PCIBIOS_MIN_MEM 0UL
15
16#define PCI_IRQ_NONE 0xffffffff
17
18static inline void pcibios_set_master(struct pci_dev *dev)
19{
20 /* No special bus mastering setup handling */
21}
22
23static inline void pcibios_penalize_isa_irq(int irq, int active)
24{
25 /* We don't do dynamic PCI IRQ allocation */
26}
27
28/* Dynamic DMA mapping stuff.
29 */
30#define PCI_DMA_BUS_IS_PHYS (0)
31
32#include <asm/scatterlist.h>
33
34struct pci_dev;
35
36/* Allocate and map kernel buffer using consistent mode DMA for a device.
37 * hwdev should be valid struct pci_dev pointer for PCI devices.
38 */
39extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle);
40
41/* Free and unmap a consistent DMA buffer.
42 * cpu_addr is what was returned from pci_alloc_consistent,
43 * size must be the same as what as passed into pci_alloc_consistent,
44 * and likewise dma_addr must be the same as what *dma_addrp was set to.
45 *
46 * References to the memory and mappings assosciated with cpu_addr/dma_addr
47 * past this call are illegal.
48 */
49extern void pci_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle);
50
51/* Map a single buffer of the indicated size for DMA in streaming mode.
52 * The 32-bit bus address to use is returned.
53 *
54 * Once the device is given the dma address, the device owns this memory
55 * until either pci_unmap_single or pci_dma_sync_single_for_cpu is performed.
56 */
57extern dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction);
58
59/* Unmap a single streaming mode DMA translation. The dma_addr and size
60 * must match what was provided for in a previous pci_map_single call. All
61 * other usages are undefined.
62 *
63 * After this call, reads by the cpu to the buffer are guaranteed to see
64 * whatever the device wrote there.
65 */
66extern void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr, size_t size, int direction);
67
68/* pci_unmap_{single,page} is not a nop, thus... */
69#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
70 dma_addr_t ADDR_NAME;
71#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
72 __u32 LEN_NAME;
73#define pci_unmap_addr(PTR, ADDR_NAME) \
74 ((PTR)->ADDR_NAME)
75#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
76 (((PTR)->ADDR_NAME) = (VAL))
77#define pci_unmap_len(PTR, LEN_NAME) \
78 ((PTR)->LEN_NAME)
79#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
80 (((PTR)->LEN_NAME) = (VAL))
81
82/*
83 * Same as above, only with pages instead of mapped addresses.
84 */
85extern dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
86 unsigned long offset, size_t size, int direction);
87extern void pci_unmap_page(struct pci_dev *hwdev,
88 dma_addr_t dma_address, size_t size, int direction);
89
90/* Map a set of buffers described by scatterlist in streaming
91 * mode for DMA. This is the scather-gather version of the
92 * above pci_map_single interface. Here the scatter gather list
93 * elements are each tagged with the appropriate dma address
94 * and length. They are obtained via sg_dma_{address,length}(SG).
95 *
96 * NOTE: An implementation may be able to use a smaller number of
97 * DMA address/length pairs than there are SG table elements.
98 * (for example via virtual mapping capabilities)
99 * The routine returns the number of addr/length pairs actually
100 * used, at most nents.
101 *
102 * Device ownership issues as mentioned above for pci_map_single are
103 * the same here.
104 */
105extern int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction);
106
107/* Unmap a set of streaming mode DMA translations.
108 * Again, cpu read rules concerning calls here are the same as for
109 * pci_unmap_single() above.
110 */
111extern void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nhwents, int direction);
112
113/* Make physical memory consistent for a single
114 * streaming mode DMA translation after a transfer.
115 *
116 * If you perform a pci_map_single() but wish to interrogate the
117 * buffer using the cpu, yet do not wish to teardown the PCI dma
118 * mapping, you must call this function before doing so. At the
119 * next point you give the PCI dma address back to the card, you
120 * must first perform a pci_dma_sync_for_device, and then the device
121 * again owns the buffer.
122 */
123extern void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction);
124extern void pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction);
125
126/* Make physical memory consistent for a set of streaming
127 * mode DMA translations after a transfer.
128 *
129 * The same as pci_dma_sync_single_* but for a scatter-gather list,
130 * same rules and usage.
131 */
132extern void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction);
133extern void pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction);
134
135/* Return whether the given PCI device DMA address mask can
136 * be supported properly. For example, if your device can
137 * only drive the low 24-bits during PCI bus mastering, then
138 * you would pass 0x00ffffff as the mask to this function.
139 */
140static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
141{
142 return 1;
143}
144
145#ifdef CONFIG_PCI
146static inline void pci_dma_burst_advice(struct pci_dev *pdev,
147 enum pci_dma_burst_strategy *strat,
148 unsigned long *strategy_parameter)
149{
150 *strat = PCI_DMA_BURST_INFINITY;
151 *strategy_parameter = ~0UL;
152}
153#endif
154
155#define PCI_DMA_ERROR_CODE (~(dma_addr_t)0x0)
156
157static inline int pci_dma_mapping_error(dma_addr_t dma_addr)
158{
159 return (dma_addr == PCI_DMA_ERROR_CODE);
160}
161
162struct device_node;
163extern struct device_node *pci_device_to_OF_node(struct pci_dev *pdev);
164
165#endif /* __KERNEL__ */
166
167/* generic pci stuff */
168#include <asm-generic/pci.h>
169
170#endif /* __SPARC_PCI_H */
diff --git a/include/asm-sparc/pci_64.h b/include/asm-sparc/pci_64.h
new file mode 100644
index 000000000000..f59f2571295b
--- /dev/null
+++ b/include/asm-sparc/pci_64.h
@@ -0,0 +1,209 @@
1#ifndef __SPARC64_PCI_H
2#define __SPARC64_PCI_H
3
4#ifdef __KERNEL__
5
6#include <linux/dma-mapping.h>
7
8/* Can be used to override the logic in pci_scan_bus for skipping
9 * already-configured bus numbers - to be used for buggy BIOSes
10 * or architectures with incomplete PCI setup by the loader.
11 */
12#define pcibios_assign_all_busses() 0
13#define pcibios_scan_all_fns(a, b) 0
14
15#define PCIBIOS_MIN_IO 0UL
16#define PCIBIOS_MIN_MEM 0UL
17
18#define PCI_IRQ_NONE 0xffffffff
19
20#define PCI_CACHE_LINE_BYTES 64
21
22static inline void pcibios_set_master(struct pci_dev *dev)
23{
24 /* No special bus mastering setup handling */
25}
26
27static inline void pcibios_penalize_isa_irq(int irq, int active)
28{
29 /* We don't do dynamic PCI IRQ allocation */
30}
31
32/* The PCI address space does not equal the physical memory
33 * address space. The networking and block device layers use
34 * this boolean for bounce buffer decisions.
35 */
36#define PCI_DMA_BUS_IS_PHYS (0)
37
38static inline void *pci_alloc_consistent(struct pci_dev *pdev, size_t size,
39 dma_addr_t *dma_handle)
40{
41 return dma_alloc_coherent(&pdev->dev, size, dma_handle, GFP_ATOMIC);
42}
43
44static inline void pci_free_consistent(struct pci_dev *pdev, size_t size,
45 void *vaddr, dma_addr_t dma_handle)
46{
47 return dma_free_coherent(&pdev->dev, size, vaddr, dma_handle);
48}
49
50static inline dma_addr_t pci_map_single(struct pci_dev *pdev, void *ptr,
51 size_t size, int direction)
52{
53 return dma_map_single(&pdev->dev, ptr, size,
54 (enum dma_data_direction) direction);
55}
56
57static inline void pci_unmap_single(struct pci_dev *pdev, dma_addr_t dma_addr,
58 size_t size, int direction)
59{
60 dma_unmap_single(&pdev->dev, dma_addr, size,
61 (enum dma_data_direction) direction);
62}
63
64#define pci_map_page(dev, page, off, size, dir) \
65 pci_map_single(dev, (page_address(page) + (off)), size, dir)
66#define pci_unmap_page(dev,addr,sz,dir) \
67 pci_unmap_single(dev,addr,sz,dir)
68
69/* pci_unmap_{single,page} is not a nop, thus... */
70#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
71 dma_addr_t ADDR_NAME;
72#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
73 __u32 LEN_NAME;
74#define pci_unmap_addr(PTR, ADDR_NAME) \
75 ((PTR)->ADDR_NAME)
76#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
77 (((PTR)->ADDR_NAME) = (VAL))
78#define pci_unmap_len(PTR, LEN_NAME) \
79 ((PTR)->LEN_NAME)
80#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
81 (((PTR)->LEN_NAME) = (VAL))
82
83static inline int pci_map_sg(struct pci_dev *pdev, struct scatterlist *sg,
84 int nents, int direction)
85{
86 return dma_map_sg(&pdev->dev, sg, nents,
87 (enum dma_data_direction) direction);
88}
89
90static inline void pci_unmap_sg(struct pci_dev *pdev, struct scatterlist *sg,
91 int nents, int direction)
92{
93 dma_unmap_sg(&pdev->dev, sg, nents,
94 (enum dma_data_direction) direction);
95}
96
97static inline void pci_dma_sync_single_for_cpu(struct pci_dev *pdev,
98 dma_addr_t dma_handle,
99 size_t size, int direction)
100{
101 dma_sync_single_for_cpu(&pdev->dev, dma_handle, size,
102 (enum dma_data_direction) direction);
103}
104
105static inline void pci_dma_sync_single_for_device(struct pci_dev *pdev,
106 dma_addr_t dma_handle,
107 size_t size, int direction)
108{
109 /* No flushing needed to sync cpu writes to the device. */
110}
111
112static inline void pci_dma_sync_sg_for_cpu(struct pci_dev *pdev,
113 struct scatterlist *sg,
114 int nents, int direction)
115{
116 dma_sync_sg_for_cpu(&pdev->dev, sg, nents,
117 (enum dma_data_direction) direction);
118}
119
120static inline void pci_dma_sync_sg_for_device(struct pci_dev *pdev,
121 struct scatterlist *sg,
122 int nelems, int direction)
123{
124 /* No flushing needed to sync cpu writes to the device. */
125}
126
127/* Return whether the given PCI device DMA address mask can
128 * be supported properly. For example, if your device can
129 * only drive the low 24-bits during PCI bus mastering, then
130 * you would pass 0x00ffffff as the mask to this function.
131 */
132extern int pci_dma_supported(struct pci_dev *hwdev, u64 mask);
133
134/* PCI IOMMU mapping bypass support. */
135
136/* PCI 64-bit addressing works for all slots on all controller
137 * types on sparc64. However, it requires that the device
138 * can drive enough of the 64 bits.
139 */
140#define PCI64_REQUIRED_MASK (~(dma64_addr_t)0)
141#define PCI64_ADDR_BASE 0xfffc000000000000UL
142
143static inline int pci_dma_mapping_error(dma_addr_t dma_addr)
144{
145 return dma_mapping_error(dma_addr);
146}
147
148#ifdef CONFIG_PCI
149static inline void pci_dma_burst_advice(struct pci_dev *pdev,
150 enum pci_dma_burst_strategy *strat,
151 unsigned long *strategy_parameter)
152{
153 unsigned long cacheline_size;
154 u8 byte;
155
156 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte);
157 if (byte == 0)
158 cacheline_size = 1024;
159 else
160 cacheline_size = (int) byte * 4;
161
162 *strat = PCI_DMA_BURST_BOUNDARY;
163 *strategy_parameter = cacheline_size;
164}
165#endif
166
167/* Return the index of the PCI controller for device PDEV. */
168
169extern int pci_domain_nr(struct pci_bus *bus);
170static inline int pci_proc_domain(struct pci_bus *bus)
171{
172 return 1;
173}
174
175/* Platform support for /proc/bus/pci/X/Y mmap()s. */
176
177#define HAVE_PCI_MMAP
178#define HAVE_ARCH_PCI_GET_UNMAPPED_AREA
179#define get_pci_unmapped_area get_fb_unmapped_area
180
181extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
182 enum pci_mmap_state mmap_state,
183 int write_combine);
184
185extern void
186pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
187 struct resource *res);
188
189extern void
190pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
191 struct pci_bus_region *region);
192
193extern struct resource *pcibios_select_root(struct pci_dev *, struct resource *);
194
195static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
196{
197 return PCI_IRQ_NONE;
198}
199
200struct device_node;
201extern struct device_node *pci_device_to_OF_node(struct pci_dev *pdev);
202
203#define HAVE_ARCH_PCI_RESOURCE_TO_USER
204extern void pci_resource_to_user(const struct pci_dev *dev, int bar,
205 const struct resource *rsrc,
206 resource_size_t *start, resource_size_t *end);
207#endif /* __KERNEL__ */
208
209#endif /* __SPARC64_PCI_H */
diff --git a/include/asm-sparc/percpu.h b/include/asm-sparc/percpu.h
index 06066a7aaec3..d98ed6cf2e36 100644
--- a/include/asm-sparc/percpu.h
+++ b/include/asm-sparc/percpu.h
@@ -1,6 +1,8 @@
1#ifndef __ARCH_SPARC_PERCPU__ 1#ifndef ___ASM_SPARC_PERCPU_H
2#define __ARCH_SPARC_PERCPU__ 2#define ___ASM_SPARC_PERCPU_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <asm-generic/percpu.h> 4#include <asm-sparc/percpu_64.h>
5 5#else
6#endif /* __ARCH_SPARC_PERCPU__ */ 6#include <asm-sparc/percpu_32.h>
7#endif
8#endif
diff --git a/include/asm-sparc/percpu_32.h b/include/asm-sparc/percpu_32.h
new file mode 100644
index 000000000000..06066a7aaec3
--- /dev/null
+++ b/include/asm-sparc/percpu_32.h
@@ -0,0 +1,6 @@
1#ifndef __ARCH_SPARC_PERCPU__
2#define __ARCH_SPARC_PERCPU__
3
4#include <asm-generic/percpu.h>
5
6#endif /* __ARCH_SPARC_PERCPU__ */
diff --git a/include/asm-sparc/percpu_64.h b/include/asm-sparc/percpu_64.h
new file mode 100644
index 000000000000..bee64593023e
--- /dev/null
+++ b/include/asm-sparc/percpu_64.h
@@ -0,0 +1,28 @@
1#ifndef __ARCH_SPARC64_PERCPU__
2#define __ARCH_SPARC64_PERCPU__
3
4#include <linux/compiler.h>
5
6register unsigned long __local_per_cpu_offset asm("g5");
7
8#ifdef CONFIG_SMP
9
10extern void real_setup_per_cpu_areas(void);
11
12extern unsigned long __per_cpu_base;
13extern unsigned long __per_cpu_shift;
14#define __per_cpu_offset(__cpu) \
15 (__per_cpu_base + ((unsigned long)(__cpu) << __per_cpu_shift))
16#define per_cpu_offset(x) (__per_cpu_offset(x))
17
18#define __my_cpu_offset __local_per_cpu_offset
19
20#else /* ! SMP */
21
22#define real_setup_per_cpu_areas() do { } while (0)
23
24#endif /* SMP */
25
26#include <asm-generic/percpu.h>
27
28#endif /* __ARCH_SPARC64_PERCPU__ */
diff --git a/include/asm-sparc/pgalloc.h b/include/asm-sparc/pgalloc.h
index 681582d26969..7fa02b53d392 100644
--- a/include/asm-sparc/pgalloc.h
+++ b/include/asm-sparc/pgalloc.h
@@ -1,68 +1,8 @@
1#ifndef _SPARC_PGALLOC_H 1#ifndef ___ASM_SPARC_PGALLOC_H
2#define _SPARC_PGALLOC_H 2#define ___ASM_SPARC_PGALLOC_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <linux/kernel.h> 4#include <asm-sparc/pgalloc_64.h>
5#include <linux/sched.h> 5#else
6 6#include <asm-sparc/pgalloc_32.h>
7#include <asm/page.h> 7#endif
8#include <asm/btfixup.h> 8#endif
9
10struct page;
11
12extern struct pgtable_cache_struct {
13 unsigned long *pgd_cache;
14 unsigned long *pte_cache;
15 unsigned long pgtable_cache_sz;
16 unsigned long pgd_cache_sz;
17} pgt_quicklists;
18#define pgd_quicklist (pgt_quicklists.pgd_cache)
19#define pmd_quicklist ((unsigned long *)0)
20#define pte_quicklist (pgt_quicklists.pte_cache)
21#define pgtable_cache_size (pgt_quicklists.pgtable_cache_sz)
22#define pgd_cache_size (pgt_quicklists.pgd_cache_sz)
23
24extern void check_pgt_cache(void);
25BTFIXUPDEF_CALL(void, do_check_pgt_cache, int, int)
26#define do_check_pgt_cache(low,high) BTFIXUP_CALL(do_check_pgt_cache)(low,high)
27
28BTFIXUPDEF_CALL(pgd_t *, get_pgd_fast, void)
29#define get_pgd_fast() BTFIXUP_CALL(get_pgd_fast)()
30
31BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
32#define free_pgd_fast(pgd) BTFIXUP_CALL(free_pgd_fast)(pgd)
33
34#define pgd_free(mm, pgd) free_pgd_fast(pgd)
35#define pgd_alloc(mm) get_pgd_fast()
36
37BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
38#define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
39#define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
40
41BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
42#define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
43
44BTFIXUPDEF_CALL(void, free_pmd_fast, pmd_t *)
45#define free_pmd_fast(pmd) BTFIXUP_CALL(free_pmd_fast)(pmd)
46
47#define pmd_free(mm, pmd) free_pmd_fast(pmd)
48#define __pmd_free_tlb(tlb, pmd) pmd_free((tlb)->mm, pmd)
49
50BTFIXUPDEF_CALL(void, pmd_populate, pmd_t *, struct page *)
51#define pmd_populate(MM, PMD, PTE) BTFIXUP_CALL(pmd_populate)(PMD, PTE)
52#define pmd_pgtable(pmd) pmd_page(pmd)
53BTFIXUPDEF_CALL(void, pmd_set, pmd_t *, pte_t *)
54#define pmd_populate_kernel(MM, PMD, PTE) BTFIXUP_CALL(pmd_set)(PMD, PTE)
55
56BTFIXUPDEF_CALL(pgtable_t , pte_alloc_one, struct mm_struct *, unsigned long)
57#define pte_alloc_one(mm, address) BTFIXUP_CALL(pte_alloc_one)(mm, address)
58BTFIXUPDEF_CALL(pte_t *, pte_alloc_one_kernel, struct mm_struct *, unsigned long)
59#define pte_alloc_one_kernel(mm, addr) BTFIXUP_CALL(pte_alloc_one_kernel)(mm, addr)
60
61BTFIXUPDEF_CALL(void, free_pte_fast, pte_t *)
62#define pte_free_kernel(mm, pte) BTFIXUP_CALL(free_pte_fast)(pte)
63
64BTFIXUPDEF_CALL(void, pte_free, pgtable_t )
65#define pte_free(mm, pte) BTFIXUP_CALL(pte_free)(pte)
66#define __pte_free_tlb(tlb, pte) pte_free((tlb)->mm, pte)
67
68#endif /* _SPARC_PGALLOC_H */
diff --git a/include/asm-sparc/pgalloc_32.h b/include/asm-sparc/pgalloc_32.h
new file mode 100644
index 000000000000..681582d26969
--- /dev/null
+++ b/include/asm-sparc/pgalloc_32.h
@@ -0,0 +1,68 @@
1#ifndef _SPARC_PGALLOC_H
2#define _SPARC_PGALLOC_H
3
4#include <linux/kernel.h>
5#include <linux/sched.h>
6
7#include <asm/page.h>
8#include <asm/btfixup.h>
9
10struct page;
11
12extern struct pgtable_cache_struct {
13 unsigned long *pgd_cache;
14 unsigned long *pte_cache;
15 unsigned long pgtable_cache_sz;
16 unsigned long pgd_cache_sz;
17} pgt_quicklists;
18#define pgd_quicklist (pgt_quicklists.pgd_cache)
19#define pmd_quicklist ((unsigned long *)0)
20#define pte_quicklist (pgt_quicklists.pte_cache)
21#define pgtable_cache_size (pgt_quicklists.pgtable_cache_sz)
22#define pgd_cache_size (pgt_quicklists.pgd_cache_sz)
23
24extern void check_pgt_cache(void);
25BTFIXUPDEF_CALL(void, do_check_pgt_cache, int, int)
26#define do_check_pgt_cache(low,high) BTFIXUP_CALL(do_check_pgt_cache)(low,high)
27
28BTFIXUPDEF_CALL(pgd_t *, get_pgd_fast, void)
29#define get_pgd_fast() BTFIXUP_CALL(get_pgd_fast)()
30
31BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
32#define free_pgd_fast(pgd) BTFIXUP_CALL(free_pgd_fast)(pgd)
33
34#define pgd_free(mm, pgd) free_pgd_fast(pgd)
35#define pgd_alloc(mm) get_pgd_fast()
36
37BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
38#define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
39#define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
40
41BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
42#define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
43
44BTFIXUPDEF_CALL(void, free_pmd_fast, pmd_t *)
45#define free_pmd_fast(pmd) BTFIXUP_CALL(free_pmd_fast)(pmd)
46
47#define pmd_free(mm, pmd) free_pmd_fast(pmd)
48#define __pmd_free_tlb(tlb, pmd) pmd_free((tlb)->mm, pmd)
49
50BTFIXUPDEF_CALL(void, pmd_populate, pmd_t *, struct page *)
51#define pmd_populate(MM, PMD, PTE) BTFIXUP_CALL(pmd_populate)(PMD, PTE)
52#define pmd_pgtable(pmd) pmd_page(pmd)
53BTFIXUPDEF_CALL(void, pmd_set, pmd_t *, pte_t *)
54#define pmd_populate_kernel(MM, PMD, PTE) BTFIXUP_CALL(pmd_set)(PMD, PTE)
55
56BTFIXUPDEF_CALL(pgtable_t , pte_alloc_one, struct mm_struct *, unsigned long)
57#define pte_alloc_one(mm, address) BTFIXUP_CALL(pte_alloc_one)(mm, address)
58BTFIXUPDEF_CALL(pte_t *, pte_alloc_one_kernel, struct mm_struct *, unsigned long)
59#define pte_alloc_one_kernel(mm, addr) BTFIXUP_CALL(pte_alloc_one_kernel)(mm, addr)
60
61BTFIXUPDEF_CALL(void, free_pte_fast, pte_t *)
62#define pte_free_kernel(mm, pte) BTFIXUP_CALL(free_pte_fast)(pte)
63
64BTFIXUPDEF_CALL(void, pte_free, pgtable_t )
65#define pte_free(mm, pte) BTFIXUP_CALL(pte_free)(pte)
66#define __pte_free_tlb(tlb, pte) pte_free((tlb)->mm, pte)
67
68#endif /* _SPARC_PGALLOC_H */
diff --git a/include/asm-sparc/pgalloc_64.h b/include/asm-sparc/pgalloc_64.h
new file mode 100644
index 000000000000..5bdfa2c6e400
--- /dev/null
+++ b/include/asm-sparc/pgalloc_64.h
@@ -0,0 +1,81 @@
1#ifndef _SPARC64_PGALLOC_H
2#define _SPARC64_PGALLOC_H
3
4#include <linux/kernel.h>
5#include <linux/sched.h>
6#include <linux/mm.h>
7#include <linux/slab.h>
8#include <linux/quicklist.h>
9
10#include <asm/spitfire.h>
11#include <asm/cpudata.h>
12#include <asm/cacheflush.h>
13#include <asm/page.h>
14
15/* Page table allocation/freeing. */
16
17static inline pgd_t *pgd_alloc(struct mm_struct *mm)
18{
19 return quicklist_alloc(0, GFP_KERNEL, NULL);
20}
21
22static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
23{
24 quicklist_free(0, NULL, pgd);
25}
26
27#define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
28
29static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
30{
31 return quicklist_alloc(0, GFP_KERNEL, NULL);
32}
33
34static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
35{
36 quicklist_free(0, NULL, pmd);
37}
38
39static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
40 unsigned long address)
41{
42 return quicklist_alloc(0, GFP_KERNEL, NULL);
43}
44
45static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
46 unsigned long address)
47{
48 struct page *page;
49 void *pg;
50
51 pg = quicklist_alloc(0, GFP_KERNEL, NULL);
52 if (!pg)
53 return NULL;
54 page = virt_to_page(pg);
55 pgtable_page_ctor(page);
56 return page;
57}
58
59static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
60{
61 quicklist_free(0, NULL, pte);
62}
63
64static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
65{
66 pgtable_page_dtor(ptepage);
67 quicklist_free_page(0, NULL, ptepage);
68}
69
70
71#define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
72#define pmd_populate(MM,PMD,PTE_PAGE) \
73 pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
74#define pmd_pgtable(pmd) pmd_page(pmd)
75
76static inline void check_pgt_cache(void)
77{
78 quicklist_trim(0, NULL, 25, 16);
79}
80
81#endif /* _SPARC64_PGALLOC_H */
diff --git a/include/asm-sparc/pgtable.h b/include/asm-sparc/pgtable.h
index 60512296b2ca..63cdef53bc52 100644
--- a/include/asm-sparc/pgtable.h
+++ b/include/asm-sparc/pgtable.h
@@ -1,475 +1,8 @@
1#ifndef _SPARC_PGTABLE_H 1#ifndef ___ASM_SPARC_PGTABLE_H
2#define _SPARC_PGTABLE_H 2#define ___ASM_SPARC_PGTABLE_H
3 3#if defined(__sparc__) && defined(__arch64__)
4/* asm-sparc/pgtable.h: Defines and functions used to work 4#include <asm-sparc/pgtable_64.h>
5 * with Sparc page tables.
6 *
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
9 */
10
11#include <asm-generic/4level-fixup.h>
12
13#include <linux/spinlock.h>
14#include <linux/swap.h>
15#include <asm/types.h>
16#ifdef CONFIG_SUN4
17#include <asm/pgtsun4.h>
18#else 5#else
19#include <asm/pgtsun4c.h> 6#include <asm-sparc/pgtable_32.h>
20#endif 7#endif
21#include <asm/pgtsrmmu.h>
22#include <asm/vac-ops.h>
23#include <asm/oplib.h>
24#include <asm/btfixup.h>
25#include <asm/system.h>
26
27#ifndef __ASSEMBLY__
28
29struct vm_area_struct;
30struct page;
31
32extern void load_mmu(void);
33extern unsigned long calc_highpages(void);
34
35BTFIXUPDEF_SIMM13(pgdir_shift)
36BTFIXUPDEF_SETHI(pgdir_size)
37BTFIXUPDEF_SETHI(pgdir_mask)
38
39BTFIXUPDEF_SIMM13(ptrs_per_pmd)
40BTFIXUPDEF_SIMM13(ptrs_per_pgd)
41BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
42
43#define pte_ERROR(e) __builtin_trap()
44#define pmd_ERROR(e) __builtin_trap()
45#define pgd_ERROR(e) __builtin_trap()
46
47BTFIXUPDEF_INT(page_none)
48BTFIXUPDEF_INT(page_copy)
49BTFIXUPDEF_INT(page_readonly)
50BTFIXUPDEF_INT(page_kernel)
51
52#define PMD_SHIFT SUN4C_PMD_SHIFT
53#define PMD_SIZE (1UL << PMD_SHIFT)
54#define PMD_MASK (~(PMD_SIZE-1))
55#define PMD_ALIGN(__addr) (((__addr) + ~PMD_MASK) & PMD_MASK)
56#define PGDIR_SHIFT BTFIXUP_SIMM13(pgdir_shift)
57#define PGDIR_SIZE BTFIXUP_SETHI(pgdir_size)
58#define PGDIR_MASK BTFIXUP_SETHI(pgdir_mask)
59#define PTRS_PER_PTE 1024
60#define PTRS_PER_PMD BTFIXUP_SIMM13(ptrs_per_pmd)
61#define PTRS_PER_PGD BTFIXUP_SIMM13(ptrs_per_pgd)
62#define USER_PTRS_PER_PGD BTFIXUP_SIMM13(user_ptrs_per_pgd)
63#define FIRST_USER_ADDRESS 0
64#define PTE_SIZE (PTRS_PER_PTE*4)
65
66#define PAGE_NONE __pgprot(BTFIXUP_INT(page_none))
67extern pgprot_t PAGE_SHARED;
68#define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
69#define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
70
71extern unsigned long page_kernel;
72
73#ifdef MODULE
74#define PAGE_KERNEL page_kernel
75#else
76#define PAGE_KERNEL __pgprot(BTFIXUP_INT(page_kernel))
77#endif 8#endif
78
79/* Top-level page directory */
80extern pgd_t swapper_pg_dir[1024];
81
82extern void paging_init(void);
83
84/* Page table for 0-4MB for everybody, on the Sparc this
85 * holds the same as on the i386.
86 */
87extern pte_t pg0[1024];
88extern pte_t pg1[1024];
89extern pte_t pg2[1024];
90extern pte_t pg3[1024];
91
92extern unsigned long ptr_in_current_pgd;
93
94/* Here is a trick, since mmap.c need the initializer elements for
95 * protection_map[] to be constant at compile time, I set the following
96 * to all zeros. I set it to the real values after I link in the
97 * appropriate MMU page table routines at boot time.
98 */
99#define __P000 __pgprot(0)
100#define __P001 __pgprot(0)
101#define __P010 __pgprot(0)
102#define __P011 __pgprot(0)
103#define __P100 __pgprot(0)
104#define __P101 __pgprot(0)
105#define __P110 __pgprot(0)
106#define __P111 __pgprot(0)
107
108#define __S000 __pgprot(0)
109#define __S001 __pgprot(0)
110#define __S010 __pgprot(0)
111#define __S011 __pgprot(0)
112#define __S100 __pgprot(0)
113#define __S101 __pgprot(0)
114#define __S110 __pgprot(0)
115#define __S111 __pgprot(0)
116
117extern int num_contexts;
118
119/* First physical page can be anywhere, the following is needed so that
120 * va-->pa and vice versa conversions work properly without performance
121 * hit for all __pa()/__va() operations.
122 */
123extern unsigned long phys_base;
124extern unsigned long pfn_base;
125
126/*
127 * BAD_PAGETABLE is used when we need a bogus page-table, while
128 * BAD_PAGE is used for a bogus page.
129 *
130 * ZERO_PAGE is a global shared page that is always zero: used
131 * for zero-mapped memory areas etc..
132 */
133extern pte_t * __bad_pagetable(void);
134extern pte_t __bad_page(void);
135extern unsigned long empty_zero_page;
136
137#define BAD_PAGETABLE __bad_pagetable()
138#define BAD_PAGE __bad_page()
139#define ZERO_PAGE(vaddr) (virt_to_page(&empty_zero_page))
140
141/*
142 */
143BTFIXUPDEF_CALL_CONST(struct page *, pmd_page, pmd_t)
144BTFIXUPDEF_CALL_CONST(unsigned long, pgd_page_vaddr, pgd_t)
145
146#define pmd_page(pmd) BTFIXUP_CALL(pmd_page)(pmd)
147#define pgd_page_vaddr(pgd) BTFIXUP_CALL(pgd_page_vaddr)(pgd)
148
149BTFIXUPDEF_SETHI(none_mask)
150BTFIXUPDEF_CALL_CONST(int, pte_present, pte_t)
151BTFIXUPDEF_CALL(void, pte_clear, pte_t *)
152
153static inline int pte_none(pte_t pte)
154{
155 return !(pte_val(pte) & ~BTFIXUP_SETHI(none_mask));
156}
157
158#define pte_present(pte) BTFIXUP_CALL(pte_present)(pte)
159#define pte_clear(mm,addr,pte) BTFIXUP_CALL(pte_clear)(pte)
160
161BTFIXUPDEF_CALL_CONST(int, pmd_bad, pmd_t)
162BTFIXUPDEF_CALL_CONST(int, pmd_present, pmd_t)
163BTFIXUPDEF_CALL(void, pmd_clear, pmd_t *)
164
165static inline int pmd_none(pmd_t pmd)
166{
167 return !(pmd_val(pmd) & ~BTFIXUP_SETHI(none_mask));
168}
169
170#define pmd_bad(pmd) BTFIXUP_CALL(pmd_bad)(pmd)
171#define pmd_present(pmd) BTFIXUP_CALL(pmd_present)(pmd)
172#define pmd_clear(pmd) BTFIXUP_CALL(pmd_clear)(pmd)
173
174BTFIXUPDEF_CALL_CONST(int, pgd_none, pgd_t)
175BTFIXUPDEF_CALL_CONST(int, pgd_bad, pgd_t)
176BTFIXUPDEF_CALL_CONST(int, pgd_present, pgd_t)
177BTFIXUPDEF_CALL(void, pgd_clear, pgd_t *)
178
179#define pgd_none(pgd) BTFIXUP_CALL(pgd_none)(pgd)
180#define pgd_bad(pgd) BTFIXUP_CALL(pgd_bad)(pgd)
181#define pgd_present(pgd) BTFIXUP_CALL(pgd_present)(pgd)
182#define pgd_clear(pgd) BTFIXUP_CALL(pgd_clear)(pgd)
183
184/*
185 * The following only work if pte_present() is true.
186 * Undefined behaviour if not..
187 */
188BTFIXUPDEF_HALF(pte_writei)
189BTFIXUPDEF_HALF(pte_dirtyi)
190BTFIXUPDEF_HALF(pte_youngi)
191
192static int pte_write(pte_t pte) __attribute_const__;
193static inline int pte_write(pte_t pte)
194{
195 return pte_val(pte) & BTFIXUP_HALF(pte_writei);
196}
197
198static int pte_dirty(pte_t pte) __attribute_const__;
199static inline int pte_dirty(pte_t pte)
200{
201 return pte_val(pte) & BTFIXUP_HALF(pte_dirtyi);
202}
203
204static int pte_young(pte_t pte) __attribute_const__;
205static inline int pte_young(pte_t pte)
206{
207 return pte_val(pte) & BTFIXUP_HALF(pte_youngi);
208}
209
210/*
211 * The following only work if pte_present() is not true.
212 */
213BTFIXUPDEF_HALF(pte_filei)
214
215static int pte_file(pte_t pte) __attribute_const__;
216static inline int pte_file(pte_t pte)
217{
218 return pte_val(pte) & BTFIXUP_HALF(pte_filei);
219}
220
221static inline int pte_special(pte_t pte)
222{
223 return 0;
224}
225
226/*
227 */
228BTFIXUPDEF_HALF(pte_wrprotecti)
229BTFIXUPDEF_HALF(pte_mkcleani)
230BTFIXUPDEF_HALF(pte_mkoldi)
231
232static pte_t pte_wrprotect(pte_t pte) __attribute_const__;
233static inline pte_t pte_wrprotect(pte_t pte)
234{
235 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_wrprotecti));
236}
237
238static pte_t pte_mkclean(pte_t pte) __attribute_const__;
239static inline pte_t pte_mkclean(pte_t pte)
240{
241 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkcleani));
242}
243
244static pte_t pte_mkold(pte_t pte) __attribute_const__;
245static inline pte_t pte_mkold(pte_t pte)
246{
247 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkoldi));
248}
249
250BTFIXUPDEF_CALL_CONST(pte_t, pte_mkwrite, pte_t)
251BTFIXUPDEF_CALL_CONST(pte_t, pte_mkdirty, pte_t)
252BTFIXUPDEF_CALL_CONST(pte_t, pte_mkyoung, pte_t)
253
254#define pte_mkwrite(pte) BTFIXUP_CALL(pte_mkwrite)(pte)
255#define pte_mkdirty(pte) BTFIXUP_CALL(pte_mkdirty)(pte)
256#define pte_mkyoung(pte) BTFIXUP_CALL(pte_mkyoung)(pte)
257
258#define pte_mkspecial(pte) (pte)
259
260#define pfn_pte(pfn, prot) mk_pte(pfn_to_page(pfn), prot)
261
262BTFIXUPDEF_CALL(unsigned long, pte_pfn, pte_t)
263#define pte_pfn(pte) BTFIXUP_CALL(pte_pfn)(pte)
264#define pte_page(pte) pfn_to_page(pte_pfn(pte))
265
266/*
267 * Conversion functions: convert a page and protection to a page entry,
268 * and a page entry and page directory to the page they refer to.
269 */
270BTFIXUPDEF_CALL_CONST(pte_t, mk_pte, struct page *, pgprot_t)
271
272BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_phys, unsigned long, pgprot_t)
273BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_io, unsigned long, pgprot_t, int)
274BTFIXUPDEF_CALL_CONST(pgprot_t, pgprot_noncached, pgprot_t)
275
276#define mk_pte(page,pgprot) BTFIXUP_CALL(mk_pte)(page,pgprot)
277#define mk_pte_phys(page,pgprot) BTFIXUP_CALL(mk_pte_phys)(page,pgprot)
278#define mk_pte_io(page,pgprot,space) BTFIXUP_CALL(mk_pte_io)(page,pgprot,space)
279
280#define pgprot_noncached(pgprot) BTFIXUP_CALL(pgprot_noncached)(pgprot)
281
282BTFIXUPDEF_INT(pte_modify_mask)
283
284static pte_t pte_modify(pte_t pte, pgprot_t newprot) __attribute_const__;
285static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
286{
287 return __pte((pte_val(pte) & BTFIXUP_INT(pte_modify_mask)) |
288 pgprot_val(newprot));
289}
290
291#define pgd_index(address) ((address) >> PGDIR_SHIFT)
292
293/* to find an entry in a page-table-directory */
294#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
295
296/* to find an entry in a kernel page-table-directory */
297#define pgd_offset_k(address) pgd_offset(&init_mm, address)
298
299/* Find an entry in the second-level page table.. */
300BTFIXUPDEF_CALL(pmd_t *, pmd_offset, pgd_t *, unsigned long)
301#define pmd_offset(dir,addr) BTFIXUP_CALL(pmd_offset)(dir,addr)
302
303/* Find an entry in the third-level page table.. */
304BTFIXUPDEF_CALL(pte_t *, pte_offset_kernel, pmd_t *, unsigned long)
305#define pte_offset_kernel(dir,addr) BTFIXUP_CALL(pte_offset_kernel)(dir,addr)
306
307/*
308 * This shortcut works on sun4m (and sun4d) because the nocache area is static,
309 * and sun4c is guaranteed to have no highmem anyway.
310 */
311#define pte_offset_map(d, a) pte_offset_kernel(d,a)
312#define pte_offset_map_nested(d, a) pte_offset_kernel(d,a)
313
314#define pte_unmap(pte) do{}while(0)
315#define pte_unmap_nested(pte) do{}while(0)
316
317/* Certain architectures need to do special things when pte's
318 * within a page table are directly modified. Thus, the following
319 * hook is made available.
320 */
321
322BTFIXUPDEF_CALL(void, set_pte, pte_t *, pte_t)
323
324#define set_pte(ptep,pteval) BTFIXUP_CALL(set_pte)(ptep,pteval)
325#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
326
327struct seq_file;
328BTFIXUPDEF_CALL(void, mmu_info, struct seq_file *)
329
330#define mmu_info(p) BTFIXUP_CALL(mmu_info)(p)
331
332/* Fault handler stuff... */
333#define FAULT_CODE_PROT 0x1
334#define FAULT_CODE_WRITE 0x2
335#define FAULT_CODE_USER 0x4
336
337BTFIXUPDEF_CALL(void, update_mmu_cache, struct vm_area_struct *, unsigned long, pte_t)
338
339#define update_mmu_cache(vma,addr,pte) BTFIXUP_CALL(update_mmu_cache)(vma,addr,pte)
340
341BTFIXUPDEF_CALL(void, sparc_mapiorange, unsigned int, unsigned long,
342 unsigned long, unsigned int)
343BTFIXUPDEF_CALL(void, sparc_unmapiorange, unsigned long, unsigned int)
344#define sparc_mapiorange(bus,pa,va,len) BTFIXUP_CALL(sparc_mapiorange)(bus,pa,va,len)
345#define sparc_unmapiorange(va,len) BTFIXUP_CALL(sparc_unmapiorange)(va,len)
346
347extern int invalid_segment;
348
349/* Encode and de-code a swap entry */
350BTFIXUPDEF_CALL(unsigned long, __swp_type, swp_entry_t)
351BTFIXUPDEF_CALL(unsigned long, __swp_offset, swp_entry_t)
352BTFIXUPDEF_CALL(swp_entry_t, __swp_entry, unsigned long, unsigned long)
353
354#define __swp_type(__x) BTFIXUP_CALL(__swp_type)(__x)
355#define __swp_offset(__x) BTFIXUP_CALL(__swp_offset)(__x)
356#define __swp_entry(__type,__off) BTFIXUP_CALL(__swp_entry)(__type,__off)
357
358#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
359#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
360
361/* file-offset-in-pte helpers */
362BTFIXUPDEF_CALL(unsigned long, pte_to_pgoff, pte_t pte);
363BTFIXUPDEF_CALL(pte_t, pgoff_to_pte, unsigned long pgoff);
364
365#define pte_to_pgoff(pte) BTFIXUP_CALL(pte_to_pgoff)(pte)
366#define pgoff_to_pte(off) BTFIXUP_CALL(pgoff_to_pte)(off)
367
368/*
369 * This is made a constant because mm/fremap.c required a constant.
370 * Note that layout of these bits is different between sun4c.c and srmmu.c.
371 */
372#define PTE_FILE_MAX_BITS 24
373
374/*
375 */
376struct ctx_list {
377 struct ctx_list *next;
378 struct ctx_list *prev;
379 unsigned int ctx_number;
380 struct mm_struct *ctx_mm;
381};
382
383extern struct ctx_list *ctx_list_pool; /* Dynamically allocated */
384extern struct ctx_list ctx_free; /* Head of free list */
385extern struct ctx_list ctx_used; /* Head of used contexts list */
386
387#define NO_CONTEXT -1
388
389static inline void remove_from_ctx_list(struct ctx_list *entry)
390{
391 entry->next->prev = entry->prev;
392 entry->prev->next = entry->next;
393}
394
395static inline void add_to_ctx_list(struct ctx_list *head, struct ctx_list *entry)
396{
397 entry->next = head;
398 (entry->prev = head->prev)->next = entry;
399 head->prev = entry;
400}
401#define add_to_free_ctxlist(entry) add_to_ctx_list(&ctx_free, entry)
402#define add_to_used_ctxlist(entry) add_to_ctx_list(&ctx_used, entry)
403
404static inline unsigned long
405__get_phys (unsigned long addr)
406{
407 switch (sparc_cpu_model){
408 case sun4:
409 case sun4c:
410 return sun4c_get_pte (addr) << PAGE_SHIFT;
411 case sun4m:
412 case sun4d:
413 return ((srmmu_get_pte (addr) & 0xffffff00) << 4);
414 default:
415 return 0;
416 }
417}
418
419static inline int
420__get_iospace (unsigned long addr)
421{
422 switch (sparc_cpu_model){
423 case sun4:
424 case sun4c:
425 return -1; /* Don't check iospace on sun4c */
426 case sun4m:
427 case sun4d:
428 return (srmmu_get_pte (addr) >> 28);
429 default:
430 return -1;
431 }
432}
433
434extern unsigned long *sparc_valid_addr_bitmap;
435
436/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
437#define kern_addr_valid(addr) \
438 (test_bit(__pa((unsigned long)(addr))>>20, sparc_valid_addr_bitmap))
439
440extern int io_remap_pfn_range(struct vm_area_struct *vma,
441 unsigned long from, unsigned long pfn,
442 unsigned long size, pgprot_t prot);
443
444/*
445 * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
446 * its high 4 bits. These macros/functions put it there or get it from there.
447 */
448#define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
449#define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
450#define GET_PFN(pfn) (pfn & 0x0fffffffUL)
451
452#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
453#define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
454({ \
455 int __changed = !pte_same(*(__ptep), __entry); \
456 if (__changed) { \
457 set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \
458 flush_tlb_page(__vma, __address); \
459 } \
460 (sparc_cpu_model == sun4c) || __changed; \
461})
462
463#include <asm-generic/pgtable.h>
464
465#endif /* !(__ASSEMBLY__) */
466
467/* We provide our own get_unmapped_area to cope with VA holes for userland */
468#define HAVE_ARCH_UNMAPPED_AREA
469
470/*
471 * No page table caches to initialise
472 */
473#define pgtable_cache_init() do { } while (0)
474
475#endif /* !(_SPARC_PGTABLE_H) */
diff --git a/include/asm-sparc/pgtable_32.h b/include/asm-sparc/pgtable_32.h
new file mode 100644
index 000000000000..781bd4694a1c
--- /dev/null
+++ b/include/asm-sparc/pgtable_32.h
@@ -0,0 +1,480 @@
1#ifndef _SPARC_PGTABLE_H
2#define _SPARC_PGTABLE_H
3
4/* asm-sparc/pgtable.h: Defines and functions used to work
5 * with Sparc page tables.
6 *
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
9 */
10
11#ifndef __ASSEMBLY__
12#include <asm-generic/4level-fixup.h>
13
14#include <linux/spinlock.h>
15#include <linux/swap.h>
16#include <asm/types.h>
17#ifdef CONFIG_SUN4
18#include <asm/pgtsun4.h>
19#else
20#include <asm/pgtsun4c.h>
21#endif
22#include <asm/pgtsrmmu.h>
23#include <asm/vac-ops.h>
24#include <asm/oplib.h>
25#include <asm/btfixup.h>
26#include <asm/system.h>
27
28
29struct vm_area_struct;
30struct page;
31
32extern void load_mmu(void);
33extern unsigned long calc_highpages(void);
34
35BTFIXUPDEF_SIMM13(pgdir_shift)
36BTFIXUPDEF_SETHI(pgdir_size)
37BTFIXUPDEF_SETHI(pgdir_mask)
38
39BTFIXUPDEF_SIMM13(ptrs_per_pmd)
40BTFIXUPDEF_SIMM13(ptrs_per_pgd)
41BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
42
43#define pte_ERROR(e) __builtin_trap()
44#define pmd_ERROR(e) __builtin_trap()
45#define pgd_ERROR(e) __builtin_trap()
46
47BTFIXUPDEF_INT(page_none)
48BTFIXUPDEF_INT(page_copy)
49BTFIXUPDEF_INT(page_readonly)
50BTFIXUPDEF_INT(page_kernel)
51
52#define PMD_SHIFT SUN4C_PMD_SHIFT
53#define PMD_SIZE (1UL << PMD_SHIFT)
54#define PMD_MASK (~(PMD_SIZE-1))
55#define PMD_ALIGN(__addr) (((__addr) + ~PMD_MASK) & PMD_MASK)
56#define PGDIR_SHIFT BTFIXUP_SIMM13(pgdir_shift)
57#define PGDIR_SIZE BTFIXUP_SETHI(pgdir_size)
58#define PGDIR_MASK BTFIXUP_SETHI(pgdir_mask)
59#define PTRS_PER_PTE 1024
60#define PTRS_PER_PMD BTFIXUP_SIMM13(ptrs_per_pmd)
61#define PTRS_PER_PGD BTFIXUP_SIMM13(ptrs_per_pgd)
62#define USER_PTRS_PER_PGD BTFIXUP_SIMM13(user_ptrs_per_pgd)
63#define FIRST_USER_ADDRESS 0
64#define PTE_SIZE (PTRS_PER_PTE*4)
65
66#define PAGE_NONE __pgprot(BTFIXUP_INT(page_none))
67extern pgprot_t PAGE_SHARED;
68#define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
69#define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
70
71extern unsigned long page_kernel;
72
73#ifdef MODULE
74#define PAGE_KERNEL page_kernel
75#else
76#define PAGE_KERNEL __pgprot(BTFIXUP_INT(page_kernel))
77#endif
78
79/* Top-level page directory */
80extern pgd_t swapper_pg_dir[1024];
81
82extern void paging_init(void);
83
84/* Page table for 0-4MB for everybody, on the Sparc this
85 * holds the same as on the i386.
86 */
87extern pte_t pg0[1024];
88extern pte_t pg1[1024];
89extern pte_t pg2[1024];
90extern pte_t pg3[1024];
91
92extern unsigned long ptr_in_current_pgd;
93
94/* Here is a trick, since mmap.c need the initializer elements for
95 * protection_map[] to be constant at compile time, I set the following
96 * to all zeros. I set it to the real values after I link in the
97 * appropriate MMU page table routines at boot time.
98 */
99#define __P000 __pgprot(0)
100#define __P001 __pgprot(0)
101#define __P010 __pgprot(0)
102#define __P011 __pgprot(0)
103#define __P100 __pgprot(0)
104#define __P101 __pgprot(0)
105#define __P110 __pgprot(0)
106#define __P111 __pgprot(0)
107
108#define __S000 __pgprot(0)
109#define __S001 __pgprot(0)
110#define __S010 __pgprot(0)
111#define __S011 __pgprot(0)
112#define __S100 __pgprot(0)
113#define __S101 __pgprot(0)
114#define __S110 __pgprot(0)
115#define __S111 __pgprot(0)
116
117extern int num_contexts;
118
119/* First physical page can be anywhere, the following is needed so that
120 * va-->pa and vice versa conversions work properly without performance
121 * hit for all __pa()/__va() operations.
122 */
123extern unsigned long phys_base;
124extern unsigned long pfn_base;
125
126/*
127 * BAD_PAGETABLE is used when we need a bogus page-table, while
128 * BAD_PAGE is used for a bogus page.
129 *
130 * ZERO_PAGE is a global shared page that is always zero: used
131 * for zero-mapped memory areas etc..
132 */
133extern pte_t * __bad_pagetable(void);
134extern pte_t __bad_page(void);
135extern unsigned long empty_zero_page;
136
137#define BAD_PAGETABLE __bad_pagetable()
138#define BAD_PAGE __bad_page()
139#define ZERO_PAGE(vaddr) (virt_to_page(&empty_zero_page))
140
141/*
142 */
143BTFIXUPDEF_CALL_CONST(struct page *, pmd_page, pmd_t)
144BTFIXUPDEF_CALL_CONST(unsigned long, pgd_page_vaddr, pgd_t)
145
146#define pmd_page(pmd) BTFIXUP_CALL(pmd_page)(pmd)
147#define pgd_page_vaddr(pgd) BTFIXUP_CALL(pgd_page_vaddr)(pgd)
148
149BTFIXUPDEF_SETHI(none_mask)
150BTFIXUPDEF_CALL_CONST(int, pte_present, pte_t)
151BTFIXUPDEF_CALL(void, pte_clear, pte_t *)
152
153static inline int pte_none(pte_t pte)
154{
155 return !(pte_val(pte) & ~BTFIXUP_SETHI(none_mask));
156}
157
158#define pte_present(pte) BTFIXUP_CALL(pte_present)(pte)
159#define pte_clear(mm,addr,pte) BTFIXUP_CALL(pte_clear)(pte)
160
161BTFIXUPDEF_CALL_CONST(int, pmd_bad, pmd_t)
162BTFIXUPDEF_CALL_CONST(int, pmd_present, pmd_t)
163BTFIXUPDEF_CALL(void, pmd_clear, pmd_t *)
164
165static inline int pmd_none(pmd_t pmd)
166{
167 return !(pmd_val(pmd) & ~BTFIXUP_SETHI(none_mask));
168}
169
170#define pmd_bad(pmd) BTFIXUP_CALL(pmd_bad)(pmd)
171#define pmd_present(pmd) BTFIXUP_CALL(pmd_present)(pmd)
172#define pmd_clear(pmd) BTFIXUP_CALL(pmd_clear)(pmd)
173
174BTFIXUPDEF_CALL_CONST(int, pgd_none, pgd_t)
175BTFIXUPDEF_CALL_CONST(int, pgd_bad, pgd_t)
176BTFIXUPDEF_CALL_CONST(int, pgd_present, pgd_t)
177BTFIXUPDEF_CALL(void, pgd_clear, pgd_t *)
178
179#define pgd_none(pgd) BTFIXUP_CALL(pgd_none)(pgd)
180#define pgd_bad(pgd) BTFIXUP_CALL(pgd_bad)(pgd)
181#define pgd_present(pgd) BTFIXUP_CALL(pgd_present)(pgd)
182#define pgd_clear(pgd) BTFIXUP_CALL(pgd_clear)(pgd)
183
184/*
185 * The following only work if pte_present() is true.
186 * Undefined behaviour if not..
187 */
188BTFIXUPDEF_HALF(pte_writei)
189BTFIXUPDEF_HALF(pte_dirtyi)
190BTFIXUPDEF_HALF(pte_youngi)
191
192static int pte_write(pte_t pte) __attribute_const__;
193static inline int pte_write(pte_t pte)
194{
195 return pte_val(pte) & BTFIXUP_HALF(pte_writei);
196}
197
198static int pte_dirty(pte_t pte) __attribute_const__;
199static inline int pte_dirty(pte_t pte)
200{
201 return pte_val(pte) & BTFIXUP_HALF(pte_dirtyi);
202}
203
204static int pte_young(pte_t pte) __attribute_const__;
205static inline int pte_young(pte_t pte)
206{
207 return pte_val(pte) & BTFIXUP_HALF(pte_youngi);
208}
209
210/*
211 * The following only work if pte_present() is not true.
212 */
213BTFIXUPDEF_HALF(pte_filei)
214
215static int pte_file(pte_t pte) __attribute_const__;
216static inline int pte_file(pte_t pte)
217{
218 return pte_val(pte) & BTFIXUP_HALF(pte_filei);
219}
220
221static inline int pte_special(pte_t pte)
222{
223 return 0;
224}
225
226/*
227 */
228BTFIXUPDEF_HALF(pte_wrprotecti)
229BTFIXUPDEF_HALF(pte_mkcleani)
230BTFIXUPDEF_HALF(pte_mkoldi)
231
232static pte_t pte_wrprotect(pte_t pte) __attribute_const__;
233static inline pte_t pte_wrprotect(pte_t pte)
234{
235 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_wrprotecti));
236}
237
238static pte_t pte_mkclean(pte_t pte) __attribute_const__;
239static inline pte_t pte_mkclean(pte_t pte)
240{
241 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkcleani));
242}
243
244static pte_t pte_mkold(pte_t pte) __attribute_const__;
245static inline pte_t pte_mkold(pte_t pte)
246{
247 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkoldi));
248}
249
250BTFIXUPDEF_CALL_CONST(pte_t, pte_mkwrite, pte_t)
251BTFIXUPDEF_CALL_CONST(pte_t, pte_mkdirty, pte_t)
252BTFIXUPDEF_CALL_CONST(pte_t, pte_mkyoung, pte_t)
253
254#define pte_mkwrite(pte) BTFIXUP_CALL(pte_mkwrite)(pte)
255#define pte_mkdirty(pte) BTFIXUP_CALL(pte_mkdirty)(pte)
256#define pte_mkyoung(pte) BTFIXUP_CALL(pte_mkyoung)(pte)
257
258#define pte_mkspecial(pte) (pte)
259
260#define pfn_pte(pfn, prot) mk_pte(pfn_to_page(pfn), prot)
261
262BTFIXUPDEF_CALL(unsigned long, pte_pfn, pte_t)
263#define pte_pfn(pte) BTFIXUP_CALL(pte_pfn)(pte)
264#define pte_page(pte) pfn_to_page(pte_pfn(pte))
265
266/*
267 * Conversion functions: convert a page and protection to a page entry,
268 * and a page entry and page directory to the page they refer to.
269 */
270BTFIXUPDEF_CALL_CONST(pte_t, mk_pte, struct page *, pgprot_t)
271
272BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_phys, unsigned long, pgprot_t)
273BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_io, unsigned long, pgprot_t, int)
274BTFIXUPDEF_CALL_CONST(pgprot_t, pgprot_noncached, pgprot_t)
275
276#define mk_pte(page,pgprot) BTFIXUP_CALL(mk_pte)(page,pgprot)
277#define mk_pte_phys(page,pgprot) BTFIXUP_CALL(mk_pte_phys)(page,pgprot)
278#define mk_pte_io(page,pgprot,space) BTFIXUP_CALL(mk_pte_io)(page,pgprot,space)
279
280#define pgprot_noncached(pgprot) BTFIXUP_CALL(pgprot_noncached)(pgprot)
281
282BTFIXUPDEF_INT(pte_modify_mask)
283
284static pte_t pte_modify(pte_t pte, pgprot_t newprot) __attribute_const__;
285static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
286{
287 return __pte((pte_val(pte) & BTFIXUP_INT(pte_modify_mask)) |
288 pgprot_val(newprot));
289}
290
291#define pgd_index(address) ((address) >> PGDIR_SHIFT)
292
293/* to find an entry in a page-table-directory */
294#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
295
296/* to find an entry in a kernel page-table-directory */
297#define pgd_offset_k(address) pgd_offset(&init_mm, address)
298
299/* Find an entry in the second-level page table.. */
300BTFIXUPDEF_CALL(pmd_t *, pmd_offset, pgd_t *, unsigned long)
301#define pmd_offset(dir,addr) BTFIXUP_CALL(pmd_offset)(dir,addr)
302
303/* Find an entry in the third-level page table.. */
304BTFIXUPDEF_CALL(pte_t *, pte_offset_kernel, pmd_t *, unsigned long)
305#define pte_offset_kernel(dir,addr) BTFIXUP_CALL(pte_offset_kernel)(dir,addr)
306
307/*
308 * This shortcut works on sun4m (and sun4d) because the nocache area is static,
309 * and sun4c is guaranteed to have no highmem anyway.
310 */
311#define pte_offset_map(d, a) pte_offset_kernel(d,a)
312#define pte_offset_map_nested(d, a) pte_offset_kernel(d,a)
313
314#define pte_unmap(pte) do{}while(0)
315#define pte_unmap_nested(pte) do{}while(0)
316
317/* Certain architectures need to do special things when pte's
318 * within a page table are directly modified. Thus, the following
319 * hook is made available.
320 */
321
322BTFIXUPDEF_CALL(void, set_pte, pte_t *, pte_t)
323
324#define set_pte(ptep,pteval) BTFIXUP_CALL(set_pte)(ptep,pteval)
325#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
326
327struct seq_file;
328BTFIXUPDEF_CALL(void, mmu_info, struct seq_file *)
329
330#define mmu_info(p) BTFIXUP_CALL(mmu_info)(p)
331
332/* Fault handler stuff... */
333#define FAULT_CODE_PROT 0x1
334#define FAULT_CODE_WRITE 0x2
335#define FAULT_CODE_USER 0x4
336
337BTFIXUPDEF_CALL(void, update_mmu_cache, struct vm_area_struct *, unsigned long, pte_t)
338
339#define update_mmu_cache(vma,addr,pte) BTFIXUP_CALL(update_mmu_cache)(vma,addr,pte)
340
341BTFIXUPDEF_CALL(void, sparc_mapiorange, unsigned int, unsigned long,
342 unsigned long, unsigned int)
343BTFIXUPDEF_CALL(void, sparc_unmapiorange, unsigned long, unsigned int)
344#define sparc_mapiorange(bus,pa,va,len) BTFIXUP_CALL(sparc_mapiorange)(bus,pa,va,len)
345#define sparc_unmapiorange(va,len) BTFIXUP_CALL(sparc_unmapiorange)(va,len)
346
347extern int invalid_segment;
348
349/* Encode and de-code a swap entry */
350BTFIXUPDEF_CALL(unsigned long, __swp_type, swp_entry_t)
351BTFIXUPDEF_CALL(unsigned long, __swp_offset, swp_entry_t)
352BTFIXUPDEF_CALL(swp_entry_t, __swp_entry, unsigned long, unsigned long)
353
354#define __swp_type(__x) BTFIXUP_CALL(__swp_type)(__x)
355#define __swp_offset(__x) BTFIXUP_CALL(__swp_offset)(__x)
356#define __swp_entry(__type,__off) BTFIXUP_CALL(__swp_entry)(__type,__off)
357
358#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
359#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
360
361/* file-offset-in-pte helpers */
362BTFIXUPDEF_CALL(unsigned long, pte_to_pgoff, pte_t pte);
363BTFIXUPDEF_CALL(pte_t, pgoff_to_pte, unsigned long pgoff);
364
365#define pte_to_pgoff(pte) BTFIXUP_CALL(pte_to_pgoff)(pte)
366#define pgoff_to_pte(off) BTFIXUP_CALL(pgoff_to_pte)(off)
367
368/*
369 * This is made a constant because mm/fremap.c required a constant.
370 * Note that layout of these bits is different between sun4c.c and srmmu.c.
371 */
372#define PTE_FILE_MAX_BITS 24
373
374/*
375 */
376struct ctx_list {
377 struct ctx_list *next;
378 struct ctx_list *prev;
379 unsigned int ctx_number;
380 struct mm_struct *ctx_mm;
381};
382
383extern struct ctx_list *ctx_list_pool; /* Dynamically allocated */
384extern struct ctx_list ctx_free; /* Head of free list */
385extern struct ctx_list ctx_used; /* Head of used contexts list */
386
387#define NO_CONTEXT -1
388
389static inline void remove_from_ctx_list(struct ctx_list *entry)
390{
391 entry->next->prev = entry->prev;
392 entry->prev->next = entry->next;
393}
394
395static inline void add_to_ctx_list(struct ctx_list *head, struct ctx_list *entry)
396{
397 entry->next = head;
398 (entry->prev = head->prev)->next = entry;
399 head->prev = entry;
400}
401#define add_to_free_ctxlist(entry) add_to_ctx_list(&ctx_free, entry)
402#define add_to_used_ctxlist(entry) add_to_ctx_list(&ctx_used, entry)
403
404static inline unsigned long
405__get_phys (unsigned long addr)
406{
407 switch (sparc_cpu_model){
408 case sun4:
409 case sun4c:
410 return sun4c_get_pte (addr) << PAGE_SHIFT;
411 case sun4m:
412 case sun4d:
413 return ((srmmu_get_pte (addr) & 0xffffff00) << 4);
414 default:
415 return 0;
416 }
417}
418
419static inline int
420__get_iospace (unsigned long addr)
421{
422 switch (sparc_cpu_model){
423 case sun4:
424 case sun4c:
425 return -1; /* Don't check iospace on sun4c */
426 case sun4m:
427 case sun4d:
428 return (srmmu_get_pte (addr) >> 28);
429 default:
430 return -1;
431 }
432}
433
434extern unsigned long *sparc_valid_addr_bitmap;
435
436/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
437#define kern_addr_valid(addr) \
438 (test_bit(__pa((unsigned long)(addr))>>20, sparc_valid_addr_bitmap))
439
440extern int io_remap_pfn_range(struct vm_area_struct *vma,
441 unsigned long from, unsigned long pfn,
442 unsigned long size, pgprot_t prot);
443
444/*
445 * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
446 * its high 4 bits. These macros/functions put it there or get it from there.
447 */
448#define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
449#define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
450#define GET_PFN(pfn) (pfn & 0x0fffffffUL)
451
452#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
453#define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
454({ \
455 int __changed = !pte_same(*(__ptep), __entry); \
456 if (__changed) { \
457 set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \
458 flush_tlb_page(__vma, __address); \
459 } \
460 (sparc_cpu_model == sun4c) || __changed; \
461})
462
463#include <asm-generic/pgtable.h>
464
465#endif /* !(__ASSEMBLY__) */
466
467#define VMALLOC_START 0xfe600000
468/* XXX Alter this when I get around to fixing sun4c - Anton */
469#define VMALLOC_END 0xffc00000
470
471
472/* We provide our own get_unmapped_area to cope with VA holes for userland */
473#define HAVE_ARCH_UNMAPPED_AREA
474
475/*
476 * No page table caches to initialise
477 */
478#define pgtable_cache_init() do { } while (0)
479
480#endif /* !(_SPARC_PGTABLE_H) */
diff --git a/include/asm-sparc/pgtable_64.h b/include/asm-sparc/pgtable_64.h
new file mode 100644
index 000000000000..bb9ec2cce355
--- /dev/null
+++ b/include/asm-sparc/pgtable_64.h
@@ -0,0 +1,775 @@
1/*
2 * pgtable.h: SpitFire page table operations.
3 *
4 * Copyright 1996,1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7
8#ifndef _SPARC64_PGTABLE_H
9#define _SPARC64_PGTABLE_H
10
11/* This file contains the functions and defines necessary to modify and use
12 * the SpitFire page tables.
13 */
14
15#include <asm-generic/pgtable-nopud.h>
16
17#include <linux/compiler.h>
18#include <linux/const.h>
19#include <asm/types.h>
20#include <asm/spitfire.h>
21#include <asm/asi.h>
22#include <asm/system.h>
23#include <asm/page.h>
24#include <asm/processor.h>
25
26/* The kernel image occupies 0x4000000 to 0x6000000 (4MB --> 96MB).
27 * The page copy blockops can use 0x6000000 to 0x8000000.
28 * The TSB is mapped in the 0x8000000 to 0xa000000 range.
29 * The PROM resides in an area spanning 0xf0000000 to 0x100000000.
30 * The vmalloc area spans 0x100000000 to 0x200000000.
31 * Since modules need to be in the lowest 32-bits of the address space,
32 * we place them right before the OBP area from 0x10000000 to 0xf0000000.
33 * There is a single static kernel PMD which maps from 0x0 to address
34 * 0x400000000.
35 */
36#define TLBTEMP_BASE _AC(0x0000000006000000,UL)
37#define TSBMAP_BASE _AC(0x0000000008000000,UL)
38#define MODULES_VADDR _AC(0x0000000010000000,UL)
39#define MODULES_LEN _AC(0x00000000e0000000,UL)
40#define MODULES_END _AC(0x00000000f0000000,UL)
41#define LOW_OBP_ADDRESS _AC(0x00000000f0000000,UL)
42#define HI_OBP_ADDRESS _AC(0x0000000100000000,UL)
43#define VMALLOC_START _AC(0x0000000100000000,UL)
44#define VMALLOC_END _AC(0x0000000200000000,UL)
45#define VMEMMAP_BASE _AC(0x0000000200000000,UL)
46
47#define vmemmap ((struct page *)VMEMMAP_BASE)
48
49/* XXX All of this needs to be rethought so we can take advantage
50 * XXX cheetah's full 64-bit virtual address space, ie. no more hole
51 * XXX in the middle like on spitfire. -DaveM
52 */
53/*
54 * Given a virtual address, the lowest PAGE_SHIFT bits determine offset
55 * into the page; the next higher PAGE_SHIFT-3 bits determine the pte#
56 * in the proper pagetable (the -3 is from the 8 byte ptes, and each page
57 * table is a single page long). The next higher PMD_BITS determine pmd#
58 * in the proper pmdtable (where we must have PMD_BITS <= (PAGE_SHIFT-2)
59 * since the pmd entries are 4 bytes, and each pmd page is a single page
60 * long). Finally, the higher few bits determine pgde#.
61 */
62
63/* PMD_SHIFT determines the size of the area a second-level page
64 * table can map
65 */
66#define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3))
67#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
68#define PMD_MASK (~(PMD_SIZE-1))
69#define PMD_BITS (PAGE_SHIFT - 2)
70
71/* PGDIR_SHIFT determines what a third-level page table entry can map */
72#define PGDIR_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3) + PMD_BITS)
73#define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
74#define PGDIR_MASK (~(PGDIR_SIZE-1))
75#define PGDIR_BITS (PAGE_SHIFT - 2)
76
77#ifndef __ASSEMBLY__
78
79#include <linux/sched.h>
80
81/* Entries per page directory level. */
82#define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
83#define PTRS_PER_PMD (1UL << PMD_BITS)
84#define PTRS_PER_PGD (1UL << PGDIR_BITS)
85
86/* Kernel has a separate 44bit address space. */
87#define FIRST_USER_ADDRESS 0
88
89#define pte_ERROR(e) __builtin_trap()
90#define pmd_ERROR(e) __builtin_trap()
91#define pgd_ERROR(e) __builtin_trap()
92
93#endif /* !(__ASSEMBLY__) */
94
95/* PTE bits which are the same in SUN4U and SUN4V format. */
96#define _PAGE_VALID _AC(0x8000000000000000,UL) /* Valid TTE */
97#define _PAGE_R _AC(0x8000000000000000,UL) /* Keep ref bit uptodate*/
98
99/* SUN4U pte bits... */
100#define _PAGE_SZ4MB_4U _AC(0x6000000000000000,UL) /* 4MB Page */
101#define _PAGE_SZ512K_4U _AC(0x4000000000000000,UL) /* 512K Page */
102#define _PAGE_SZ64K_4U _AC(0x2000000000000000,UL) /* 64K Page */
103#define _PAGE_SZ8K_4U _AC(0x0000000000000000,UL) /* 8K Page */
104#define _PAGE_NFO_4U _AC(0x1000000000000000,UL) /* No Fault Only */
105#define _PAGE_IE_4U _AC(0x0800000000000000,UL) /* Invert Endianness */
106#define _PAGE_SOFT2_4U _AC(0x07FC000000000000,UL) /* Software bits, set 2 */
107#define _PAGE_RES1_4U _AC(0x0002000000000000,UL) /* Reserved */
108#define _PAGE_SZ32MB_4U _AC(0x0001000000000000,UL) /* (Panther) 32MB page */
109#define _PAGE_SZ256MB_4U _AC(0x2001000000000000,UL) /* (Panther) 256MB page */
110#define _PAGE_SZALL_4U _AC(0x6001000000000000,UL) /* All pgsz bits */
111#define _PAGE_SN_4U _AC(0x0000800000000000,UL) /* (Cheetah) Snoop */
112#define _PAGE_RES2_4U _AC(0x0000780000000000,UL) /* Reserved */
113#define _PAGE_PADDR_4U _AC(0x000007FFFFFFE000,UL) /* (Cheetah) pa[42:13] */
114#define _PAGE_SOFT_4U _AC(0x0000000000001F80,UL) /* Software bits: */
115#define _PAGE_EXEC_4U _AC(0x0000000000001000,UL) /* Executable SW bit */
116#define _PAGE_MODIFIED_4U _AC(0x0000000000000800,UL) /* Modified (dirty) */
117#define _PAGE_FILE_4U _AC(0x0000000000000800,UL) /* Pagecache page */
118#define _PAGE_ACCESSED_4U _AC(0x0000000000000400,UL) /* Accessed (ref'd) */
119#define _PAGE_READ_4U _AC(0x0000000000000200,UL) /* Readable SW Bit */
120#define _PAGE_WRITE_4U _AC(0x0000000000000100,UL) /* Writable SW Bit */
121#define _PAGE_PRESENT_4U _AC(0x0000000000000080,UL) /* Present */
122#define _PAGE_L_4U _AC(0x0000000000000040,UL) /* Locked TTE */
123#define _PAGE_CP_4U _AC(0x0000000000000020,UL) /* Cacheable in P-Cache */
124#define _PAGE_CV_4U _AC(0x0000000000000010,UL) /* Cacheable in V-Cache */
125#define _PAGE_E_4U _AC(0x0000000000000008,UL) /* side-Effect */
126#define _PAGE_P_4U _AC(0x0000000000000004,UL) /* Privileged Page */
127#define _PAGE_W_4U _AC(0x0000000000000002,UL) /* Writable */
128
129/* SUN4V pte bits... */
130#define _PAGE_NFO_4V _AC(0x4000000000000000,UL) /* No Fault Only */
131#define _PAGE_SOFT2_4V _AC(0x3F00000000000000,UL) /* Software bits, set 2 */
132#define _PAGE_MODIFIED_4V _AC(0x2000000000000000,UL) /* Modified (dirty) */
133#define _PAGE_ACCESSED_4V _AC(0x1000000000000000,UL) /* Accessed (ref'd) */
134#define _PAGE_READ_4V _AC(0x0800000000000000,UL) /* Readable SW Bit */
135#define _PAGE_WRITE_4V _AC(0x0400000000000000,UL) /* Writable SW Bit */
136#define _PAGE_PADDR_4V _AC(0x00FFFFFFFFFFE000,UL) /* paddr[55:13] */
137#define _PAGE_IE_4V _AC(0x0000000000001000,UL) /* Invert Endianness */
138#define _PAGE_E_4V _AC(0x0000000000000800,UL) /* side-Effect */
139#define _PAGE_CP_4V _AC(0x0000000000000400,UL) /* Cacheable in P-Cache */
140#define _PAGE_CV_4V _AC(0x0000000000000200,UL) /* Cacheable in V-Cache */
141#define _PAGE_P_4V _AC(0x0000000000000100,UL) /* Privileged Page */
142#define _PAGE_EXEC_4V _AC(0x0000000000000080,UL) /* Executable Page */
143#define _PAGE_W_4V _AC(0x0000000000000040,UL) /* Writable */
144#define _PAGE_SOFT_4V _AC(0x0000000000000030,UL) /* Software bits */
145#define _PAGE_FILE_4V _AC(0x0000000000000020,UL) /* Pagecache page */
146#define _PAGE_PRESENT_4V _AC(0x0000000000000010,UL) /* Present */
147#define _PAGE_RESV_4V _AC(0x0000000000000008,UL) /* Reserved */
148#define _PAGE_SZ16GB_4V _AC(0x0000000000000007,UL) /* 16GB Page */
149#define _PAGE_SZ2GB_4V _AC(0x0000000000000006,UL) /* 2GB Page */
150#define _PAGE_SZ256MB_4V _AC(0x0000000000000005,UL) /* 256MB Page */
151#define _PAGE_SZ32MB_4V _AC(0x0000000000000004,UL) /* 32MB Page */
152#define _PAGE_SZ4MB_4V _AC(0x0000000000000003,UL) /* 4MB Page */
153#define _PAGE_SZ512K_4V _AC(0x0000000000000002,UL) /* 512K Page */
154#define _PAGE_SZ64K_4V _AC(0x0000000000000001,UL) /* 64K Page */
155#define _PAGE_SZ8K_4V _AC(0x0000000000000000,UL) /* 8K Page */
156#define _PAGE_SZALL_4V _AC(0x0000000000000007,UL) /* All pgsz bits */
157
158#if PAGE_SHIFT == 13
159#define _PAGE_SZBITS_4U _PAGE_SZ8K_4U
160#define _PAGE_SZBITS_4V _PAGE_SZ8K_4V
161#elif PAGE_SHIFT == 16
162#define _PAGE_SZBITS_4U _PAGE_SZ64K_4U
163#define _PAGE_SZBITS_4V _PAGE_SZ64K_4V
164#else
165#error Wrong PAGE_SHIFT specified
166#endif
167
168#if defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
169#define _PAGE_SZHUGE_4U _PAGE_SZ4MB_4U
170#define _PAGE_SZHUGE_4V _PAGE_SZ4MB_4V
171#elif defined(CONFIG_HUGETLB_PAGE_SIZE_512K)
172#define _PAGE_SZHUGE_4U _PAGE_SZ512K_4U
173#define _PAGE_SZHUGE_4V _PAGE_SZ512K_4V
174#elif defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
175#define _PAGE_SZHUGE_4U _PAGE_SZ64K_4U
176#define _PAGE_SZHUGE_4V _PAGE_SZ64K_4V
177#endif
178
179/* These are actually filled in at boot time by sun4{u,v}_pgprot_init() */
180#define __P000 __pgprot(0)
181#define __P001 __pgprot(0)
182#define __P010 __pgprot(0)
183#define __P011 __pgprot(0)
184#define __P100 __pgprot(0)
185#define __P101 __pgprot(0)
186#define __P110 __pgprot(0)
187#define __P111 __pgprot(0)
188
189#define __S000 __pgprot(0)
190#define __S001 __pgprot(0)
191#define __S010 __pgprot(0)
192#define __S011 __pgprot(0)
193#define __S100 __pgprot(0)
194#define __S101 __pgprot(0)
195#define __S110 __pgprot(0)
196#define __S111 __pgprot(0)
197
198#ifndef __ASSEMBLY__
199
200extern pte_t mk_pte_io(unsigned long, pgprot_t, int, unsigned long);
201
202extern unsigned long pte_sz_bits(unsigned long size);
203
204extern pgprot_t PAGE_KERNEL;
205extern pgprot_t PAGE_KERNEL_LOCKED;
206extern pgprot_t PAGE_COPY;
207extern pgprot_t PAGE_SHARED;
208
209/* XXX This uglyness is for the atyfb driver's sparc mmap() support. XXX */
210extern unsigned long _PAGE_IE;
211extern unsigned long _PAGE_E;
212extern unsigned long _PAGE_CACHE;
213
214extern unsigned long pg_iobits;
215extern unsigned long _PAGE_ALL_SZ_BITS;
216extern unsigned long _PAGE_SZBITS;
217
218extern struct page *mem_map_zero;
219#define ZERO_PAGE(vaddr) (mem_map_zero)
220
221/* PFNs are real physical page numbers. However, mem_map only begins to record
222 * per-page information starting at pfn_base. This is to handle systems where
223 * the first physical page in the machine is at some huge physical address,
224 * such as 4GB. This is common on a partitioned E10000, for example.
225 */
226static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
227{
228 unsigned long paddr = pfn << PAGE_SHIFT;
229 unsigned long sz_bits;
230
231 sz_bits = 0UL;
232 if (_PAGE_SZBITS_4U != 0UL || _PAGE_SZBITS_4V != 0UL) {
233 __asm__ __volatile__(
234 "\n661: sethi %%uhi(%1), %0\n"
235 " sllx %0, 32, %0\n"
236 " .section .sun4v_2insn_patch, \"ax\"\n"
237 " .word 661b\n"
238 " mov %2, %0\n"
239 " nop\n"
240 " .previous\n"
241 : "=r" (sz_bits)
242 : "i" (_PAGE_SZBITS_4U), "i" (_PAGE_SZBITS_4V));
243 }
244 return __pte(paddr | sz_bits | pgprot_val(prot));
245}
246#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
247
248/* This one can be done with two shifts. */
249static inline unsigned long pte_pfn(pte_t pte)
250{
251 unsigned long ret;
252
253 __asm__ __volatile__(
254 "\n661: sllx %1, %2, %0\n"
255 " srlx %0, %3, %0\n"
256 " .section .sun4v_2insn_patch, \"ax\"\n"
257 " .word 661b\n"
258 " sllx %1, %4, %0\n"
259 " srlx %0, %5, %0\n"
260 " .previous\n"
261 : "=r" (ret)
262 : "r" (pte_val(pte)),
263 "i" (21), "i" (21 + PAGE_SHIFT),
264 "i" (8), "i" (8 + PAGE_SHIFT));
265
266 return ret;
267}
268#define pte_page(x) pfn_to_page(pte_pfn(x))
269
270static inline pte_t pte_modify(pte_t pte, pgprot_t prot)
271{
272 unsigned long mask, tmp;
273
274 /* SUN4U: 0x600307ffffffecb8 (negated == 0x9ffcf80000001347)
275 * SUN4V: 0x30ffffffffffee17 (negated == 0xcf000000000011e8)
276 *
277 * Even if we use negation tricks the result is still a 6
278 * instruction sequence, so don't try to play fancy and just
279 * do the most straightforward implementation.
280 *
281 * Note: We encode this into 3 sun4v 2-insn patch sequences.
282 */
283
284 __asm__ __volatile__(
285 "\n661: sethi %%uhi(%2), %1\n"
286 " sethi %%hi(%2), %0\n"
287 "\n662: or %1, %%ulo(%2), %1\n"
288 " or %0, %%lo(%2), %0\n"
289 "\n663: sllx %1, 32, %1\n"
290 " or %0, %1, %0\n"
291 " .section .sun4v_2insn_patch, \"ax\"\n"
292 " .word 661b\n"
293 " sethi %%uhi(%3), %1\n"
294 " sethi %%hi(%3), %0\n"
295 " .word 662b\n"
296 " or %1, %%ulo(%3), %1\n"
297 " or %0, %%lo(%3), %0\n"
298 " .word 663b\n"
299 " sllx %1, 32, %1\n"
300 " or %0, %1, %0\n"
301 " .previous\n"
302 : "=r" (mask), "=r" (tmp)
303 : "i" (_PAGE_PADDR_4U | _PAGE_MODIFIED_4U | _PAGE_ACCESSED_4U |
304 _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_E_4U | _PAGE_PRESENT_4U |
305 _PAGE_SZBITS_4U),
306 "i" (_PAGE_PADDR_4V | _PAGE_MODIFIED_4V | _PAGE_ACCESSED_4V |
307 _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_E_4V | _PAGE_PRESENT_4V |
308 _PAGE_SZBITS_4V));
309
310 return __pte((pte_val(pte) & mask) | (pgprot_val(prot) & ~mask));
311}
312
313static inline pte_t pgoff_to_pte(unsigned long off)
314{
315 off <<= PAGE_SHIFT;
316
317 __asm__ __volatile__(
318 "\n661: or %0, %2, %0\n"
319 " .section .sun4v_1insn_patch, \"ax\"\n"
320 " .word 661b\n"
321 " or %0, %3, %0\n"
322 " .previous\n"
323 : "=r" (off)
324 : "0" (off), "i" (_PAGE_FILE_4U), "i" (_PAGE_FILE_4V));
325
326 return __pte(off);
327}
328
329static inline pgprot_t pgprot_noncached(pgprot_t prot)
330{
331 unsigned long val = pgprot_val(prot);
332
333 __asm__ __volatile__(
334 "\n661: andn %0, %2, %0\n"
335 " or %0, %3, %0\n"
336 " .section .sun4v_2insn_patch, \"ax\"\n"
337 " .word 661b\n"
338 " andn %0, %4, %0\n"
339 " or %0, %5, %0\n"
340 " .previous\n"
341 : "=r" (val)
342 : "0" (val), "i" (_PAGE_CP_4U | _PAGE_CV_4U), "i" (_PAGE_E_4U),
343 "i" (_PAGE_CP_4V | _PAGE_CV_4V), "i" (_PAGE_E_4V));
344
345 return __pgprot(val);
346}
347/* Various pieces of code check for platform support by ifdef testing
348 * on "pgprot_noncached". That's broken and should be fixed, but for
349 * now...
350 */
351#define pgprot_noncached pgprot_noncached
352
353#ifdef CONFIG_HUGETLB_PAGE
354static inline pte_t pte_mkhuge(pte_t pte)
355{
356 unsigned long mask;
357
358 __asm__ __volatile__(
359 "\n661: sethi %%uhi(%1), %0\n"
360 " sllx %0, 32, %0\n"
361 " .section .sun4v_2insn_patch, \"ax\"\n"
362 " .word 661b\n"
363 " mov %2, %0\n"
364 " nop\n"
365 " .previous\n"
366 : "=r" (mask)
367 : "i" (_PAGE_SZHUGE_4U), "i" (_PAGE_SZHUGE_4V));
368
369 return __pte(pte_val(pte) | mask);
370}
371#endif
372
373static inline pte_t pte_mkdirty(pte_t pte)
374{
375 unsigned long val = pte_val(pte), tmp;
376
377 __asm__ __volatile__(
378 "\n661: or %0, %3, %0\n"
379 " nop\n"
380 "\n662: nop\n"
381 " nop\n"
382 " .section .sun4v_2insn_patch, \"ax\"\n"
383 " .word 661b\n"
384 " sethi %%uhi(%4), %1\n"
385 " sllx %1, 32, %1\n"
386 " .word 662b\n"
387 " or %1, %%lo(%4), %1\n"
388 " or %0, %1, %0\n"
389 " .previous\n"
390 : "=r" (val), "=r" (tmp)
391 : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
392 "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
393
394 return __pte(val);
395}
396
397static inline pte_t pte_mkclean(pte_t pte)
398{
399 unsigned long val = pte_val(pte), tmp;
400
401 __asm__ __volatile__(
402 "\n661: andn %0, %3, %0\n"
403 " nop\n"
404 "\n662: nop\n"
405 " nop\n"
406 " .section .sun4v_2insn_patch, \"ax\"\n"
407 " .word 661b\n"
408 " sethi %%uhi(%4), %1\n"
409 " sllx %1, 32, %1\n"
410 " .word 662b\n"
411 " or %1, %%lo(%4), %1\n"
412 " andn %0, %1, %0\n"
413 " .previous\n"
414 : "=r" (val), "=r" (tmp)
415 : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
416 "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
417
418 return __pte(val);
419}
420
421static inline pte_t pte_mkwrite(pte_t pte)
422{
423 unsigned long val = pte_val(pte), mask;
424
425 __asm__ __volatile__(
426 "\n661: mov %1, %0\n"
427 " nop\n"
428 " .section .sun4v_2insn_patch, \"ax\"\n"
429 " .word 661b\n"
430 " sethi %%uhi(%2), %0\n"
431 " sllx %0, 32, %0\n"
432 " .previous\n"
433 : "=r" (mask)
434 : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
435
436 return __pte(val | mask);
437}
438
439static inline pte_t pte_wrprotect(pte_t pte)
440{
441 unsigned long val = pte_val(pte), tmp;
442
443 __asm__ __volatile__(
444 "\n661: andn %0, %3, %0\n"
445 " nop\n"
446 "\n662: nop\n"
447 " nop\n"
448 " .section .sun4v_2insn_patch, \"ax\"\n"
449 " .word 661b\n"
450 " sethi %%uhi(%4), %1\n"
451 " sllx %1, 32, %1\n"
452 " .word 662b\n"
453 " or %1, %%lo(%4), %1\n"
454 " andn %0, %1, %0\n"
455 " .previous\n"
456 : "=r" (val), "=r" (tmp)
457 : "0" (val), "i" (_PAGE_WRITE_4U | _PAGE_W_4U),
458 "i" (_PAGE_WRITE_4V | _PAGE_W_4V));
459
460 return __pte(val);
461}
462
463static inline pte_t pte_mkold(pte_t pte)
464{
465 unsigned long mask;
466
467 __asm__ __volatile__(
468 "\n661: mov %1, %0\n"
469 " nop\n"
470 " .section .sun4v_2insn_patch, \"ax\"\n"
471 " .word 661b\n"
472 " sethi %%uhi(%2), %0\n"
473 " sllx %0, 32, %0\n"
474 " .previous\n"
475 : "=r" (mask)
476 : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
477
478 mask |= _PAGE_R;
479
480 return __pte(pte_val(pte) & ~mask);
481}
482
483static inline pte_t pte_mkyoung(pte_t pte)
484{
485 unsigned long mask;
486
487 __asm__ __volatile__(
488 "\n661: mov %1, %0\n"
489 " nop\n"
490 " .section .sun4v_2insn_patch, \"ax\"\n"
491 " .word 661b\n"
492 " sethi %%uhi(%2), %0\n"
493 " sllx %0, 32, %0\n"
494 " .previous\n"
495 : "=r" (mask)
496 : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
497
498 mask |= _PAGE_R;
499
500 return __pte(pte_val(pte) | mask);
501}
502
503static inline pte_t pte_mkspecial(pte_t pte)
504{
505 return pte;
506}
507
508static inline unsigned long pte_young(pte_t pte)
509{
510 unsigned long mask;
511
512 __asm__ __volatile__(
513 "\n661: mov %1, %0\n"
514 " nop\n"
515 " .section .sun4v_2insn_patch, \"ax\"\n"
516 " .word 661b\n"
517 " sethi %%uhi(%2), %0\n"
518 " sllx %0, 32, %0\n"
519 " .previous\n"
520 : "=r" (mask)
521 : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
522
523 return (pte_val(pte) & mask);
524}
525
526static inline unsigned long pte_dirty(pte_t pte)
527{
528 unsigned long mask;
529
530 __asm__ __volatile__(
531 "\n661: mov %1, %0\n"
532 " nop\n"
533 " .section .sun4v_2insn_patch, \"ax\"\n"
534 " .word 661b\n"
535 " sethi %%uhi(%2), %0\n"
536 " sllx %0, 32, %0\n"
537 " .previous\n"
538 : "=r" (mask)
539 : "i" (_PAGE_MODIFIED_4U), "i" (_PAGE_MODIFIED_4V));
540
541 return (pte_val(pte) & mask);
542}
543
544static inline unsigned long pte_write(pte_t pte)
545{
546 unsigned long mask;
547
548 __asm__ __volatile__(
549 "\n661: mov %1, %0\n"
550 " nop\n"
551 " .section .sun4v_2insn_patch, \"ax\"\n"
552 " .word 661b\n"
553 " sethi %%uhi(%2), %0\n"
554 " sllx %0, 32, %0\n"
555 " .previous\n"
556 : "=r" (mask)
557 : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
558
559 return (pte_val(pte) & mask);
560}
561
562static inline unsigned long pte_exec(pte_t pte)
563{
564 unsigned long mask;
565
566 __asm__ __volatile__(
567 "\n661: sethi %%hi(%1), %0\n"
568 " .section .sun4v_1insn_patch, \"ax\"\n"
569 " .word 661b\n"
570 " mov %2, %0\n"
571 " .previous\n"
572 : "=r" (mask)
573 : "i" (_PAGE_EXEC_4U), "i" (_PAGE_EXEC_4V));
574
575 return (pte_val(pte) & mask);
576}
577
578static inline unsigned long pte_file(pte_t pte)
579{
580 unsigned long val = pte_val(pte);
581
582 __asm__ __volatile__(
583 "\n661: and %0, %2, %0\n"
584 " .section .sun4v_1insn_patch, \"ax\"\n"
585 " .word 661b\n"
586 " and %0, %3, %0\n"
587 " .previous\n"
588 : "=r" (val)
589 : "0" (val), "i" (_PAGE_FILE_4U), "i" (_PAGE_FILE_4V));
590
591 return val;
592}
593
594static inline unsigned long pte_present(pte_t pte)
595{
596 unsigned long val = pte_val(pte);
597
598 __asm__ __volatile__(
599 "\n661: and %0, %2, %0\n"
600 " .section .sun4v_1insn_patch, \"ax\"\n"
601 " .word 661b\n"
602 " and %0, %3, %0\n"
603 " .previous\n"
604 : "=r" (val)
605 : "0" (val), "i" (_PAGE_PRESENT_4U), "i" (_PAGE_PRESENT_4V));
606
607 return val;
608}
609
610static inline int pte_special(pte_t pte)
611{
612 return 0;
613}
614
615#define pmd_set(pmdp, ptep) \
616 (pmd_val(*(pmdp)) = (__pa((unsigned long) (ptep)) >> 11UL))
617#define pud_set(pudp, pmdp) \
618 (pud_val(*(pudp)) = (__pa((unsigned long) (pmdp)) >> 11UL))
619#define __pmd_page(pmd) \
620 ((unsigned long) __va((((unsigned long)pmd_val(pmd))<<11UL)))
621#define pmd_page(pmd) virt_to_page((void *)__pmd_page(pmd))
622#define pud_page_vaddr(pud) \
623 ((unsigned long) __va((((unsigned long)pud_val(pud))<<11UL)))
624#define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
625#define pmd_none(pmd) (!pmd_val(pmd))
626#define pmd_bad(pmd) (0)
627#define pmd_present(pmd) (pmd_val(pmd) != 0U)
628#define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0U)
629#define pud_none(pud) (!pud_val(pud))
630#define pud_bad(pud) (0)
631#define pud_present(pud) (pud_val(pud) != 0U)
632#define pud_clear(pudp) (pud_val(*(pudp)) = 0U)
633
634/* Same in both SUN4V and SUN4U. */
635#define pte_none(pte) (!pte_val(pte))
636
637/* to find an entry in a page-table-directory. */
638#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
639#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
640
641/* to find an entry in a kernel page-table-directory */
642#define pgd_offset_k(address) pgd_offset(&init_mm, address)
643
644/* Find an entry in the second-level page table.. */
645#define pmd_offset(pudp, address) \
646 ((pmd_t *) pud_page_vaddr(*(pudp)) + \
647 (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)))
648
649/* Find an entry in the third-level page table.. */
650#define pte_index(dir, address) \
651 ((pte_t *) __pmd_page(*(dir)) + \
652 ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
653#define pte_offset_kernel pte_index
654#define pte_offset_map pte_index
655#define pte_offset_map_nested pte_index
656#define pte_unmap(pte) do { } while (0)
657#define pte_unmap_nested(pte) do { } while (0)
658
659/* Actual page table PTE updates. */
660extern void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, pte_t *ptep, pte_t orig);
661
662static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte)
663{
664 pte_t orig = *ptep;
665
666 *ptep = pte;
667
668 /* It is more efficient to let flush_tlb_kernel_range()
669 * handle init_mm tlb flushes.
670 *
671 * SUN4V NOTE: _PAGE_VALID is the same value in both the SUN4U
672 * and SUN4V pte layout, so this inline test is fine.
673 */
674 if (likely(mm != &init_mm) && (pte_val(orig) & _PAGE_VALID))
675 tlb_batch_add(mm, addr, ptep, orig);
676}
677
678#define pte_clear(mm,addr,ptep) \
679 set_pte_at((mm), (addr), (ptep), __pte(0UL))
680
681#ifdef DCACHE_ALIASING_POSSIBLE
682#define __HAVE_ARCH_MOVE_PTE
683#define move_pte(pte, prot, old_addr, new_addr) \
684({ \
685 pte_t newpte = (pte); \
686 if (tlb_type != hypervisor && pte_present(pte)) { \
687 unsigned long this_pfn = pte_pfn(pte); \
688 \
689 if (pfn_valid(this_pfn) && \
690 (((old_addr) ^ (new_addr)) & (1 << 13))) \
691 flush_dcache_page_all(current->mm, \
692 pfn_to_page(this_pfn)); \
693 } \
694 newpte; \
695})
696#endif
697
698extern pgd_t swapper_pg_dir[2048];
699extern pmd_t swapper_low_pmd_dir[2048];
700
701extern void paging_init(void);
702extern unsigned long find_ecache_flush_span(unsigned long size);
703
704/* These do nothing with the way I have things setup. */
705#define mmu_lockarea(vaddr, len) (vaddr)
706#define mmu_unlockarea(vaddr, len) do { } while(0)
707
708struct vm_area_struct;
709extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t);
710
711/* Encode and de-code a swap entry */
712#define __swp_type(entry) (((entry).val >> PAGE_SHIFT) & 0xffUL)
713#define __swp_offset(entry) ((entry).val >> (PAGE_SHIFT + 8UL))
714#define __swp_entry(type, offset) \
715 ( (swp_entry_t) \
716 { \
717 (((long)(type) << PAGE_SHIFT) | \
718 ((long)(offset) << (PAGE_SHIFT + 8UL))) \
719 } )
720#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
721#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
722
723/* File offset in PTE support. */
724extern unsigned long pte_file(pte_t);
725#define pte_to_pgoff(pte) (pte_val(pte) >> PAGE_SHIFT)
726extern pte_t pgoff_to_pte(unsigned long);
727#define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
728
729extern unsigned long *sparc64_valid_addr_bitmap;
730
731/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
732#define kern_addr_valid(addr) \
733 (test_bit(__pa((unsigned long)(addr))>>22, sparc64_valid_addr_bitmap))
734
735extern int page_in_phys_avail(unsigned long paddr);
736
737extern int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
738 unsigned long pfn,
739 unsigned long size, pgprot_t prot);
740
741/*
742 * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
743 * its high 4 bits. These macros/functions put it there or get it from there.
744 */
745#define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
746#define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
747#define GET_PFN(pfn) (pfn & 0x0fffffffffffffffUL)
748
749#include <asm-generic/pgtable.h>
750
751/* We provide our own get_unmapped_area to cope with VA holes and
752 * SHM area cache aliasing for userland.
753 */
754#define HAVE_ARCH_UNMAPPED_AREA
755#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
756
757/* We provide a special get_unmapped_area for framebuffer mmaps to try and use
758 * the largest alignment possible such that larget PTEs can be used.
759 */
760extern unsigned long get_fb_unmapped_area(struct file *filp, unsigned long,
761 unsigned long, unsigned long,
762 unsigned long);
763#define HAVE_ARCH_FB_UNMAPPED_AREA
764
765extern void pgtable_cache_init(void);
766extern void sun4v_register_fault_status(void);
767extern void sun4v_ktsb_register(void);
768extern void __init cheetah_ecache_flush_init(void);
769extern void sun4v_patch_tlb_handlers(void);
770
771extern unsigned long cmdline_memory_size;
772
773#endif /* !(__ASSEMBLY__) */
774
775#endif /* !(_SPARC64_PGTABLE_H) */
diff --git a/include/asm-sparc/pil.h b/include/asm-sparc/pil.h
new file mode 100644
index 000000000000..71819bb943fc
--- /dev/null
+++ b/include/asm-sparc/pil.h
@@ -0,0 +1,22 @@
1#ifndef _SPARC64_PIL_H
2#define _SPARC64_PIL_H
3
4/* To avoid some locking problems, we hard allocate certain PILs
5 * for SMP cross call messages that must do a etrap/rtrap.
6 *
7 * A local_irq_disable() does not block the cross call delivery, so
8 * when SMP locking is an issue we reschedule the event into a PIL
9 * interrupt which is blocked by local_irq_disable().
10 *
11 * In fact any XCALL which has to etrap/rtrap has a problem because
12 * it is difficult to prevent rtrap from running BH's, and that would
13 * need to be done if the XCALL arrived while %pil==15.
14 */
15#define PIL_SMP_CALL_FUNC 1
16#define PIL_SMP_RECEIVE_SIGNAL 2
17#define PIL_SMP_CAPTURE 3
18#define PIL_SMP_CTX_NEW_VERSION 4
19#define PIL_DEVICE_IRQ 5
20#define PIL_SMP_CALL_FUNC_SNGL 6
21
22#endif /* !(_SPARC64_PIL_H) */
diff --git a/include/asm-sparc/posix_types.h b/include/asm-sparc/posix_types.h
index dcc07eb5e181..58c820d75e83 100644
--- a/include/asm-sparc/posix_types.h
+++ b/include/asm-sparc/posix_types.h
@@ -1,118 +1,8 @@
1#ifndef __ARCH_SPARC_POSIX_TYPES_H 1#ifndef ___ASM_SPARC_POSIX_TYPES_H
2#define __ARCH_SPARC_POSIX_TYPES_H 2#define ___ASM_SPARC_POSIX_TYPES_H
3 3#if defined(__sparc__) && defined(__arch64__)
4/* 4#include <asm-sparc/posix_types_64.h>
5 * This file is generally used by user-level software, so you need to 5#else
6 * be a little careful about namespace pollution etc. Also, we cannot 6#include <asm-sparc/posix_types_32.h>
7 * assume GCC is being used. 7#endif
8 */
9
10typedef unsigned int __kernel_size_t;
11typedef int __kernel_ssize_t;
12typedef long int __kernel_ptrdiff_t;
13typedef long __kernel_time_t;
14typedef long __kernel_suseconds_t;
15typedef long __kernel_clock_t;
16typedef int __kernel_pid_t;
17typedef unsigned short __kernel_ipc_pid_t;
18typedef unsigned short __kernel_uid_t;
19typedef unsigned short __kernel_gid_t;
20typedef unsigned long __kernel_ino_t;
21typedef unsigned short __kernel_mode_t;
22typedef unsigned short __kernel_umode_t;
23typedef short __kernel_nlink_t;
24typedef long __kernel_daddr_t;
25typedef long __kernel_off_t;
26typedef char * __kernel_caddr_t;
27typedef unsigned short __kernel_uid16_t;
28typedef unsigned short __kernel_gid16_t;
29typedef unsigned int __kernel_uid32_t;
30typedef unsigned int __kernel_gid32_t;
31typedef unsigned short __kernel_old_uid_t;
32typedef unsigned short __kernel_old_gid_t;
33typedef unsigned short __kernel_old_dev_t;
34typedef int __kernel_clockid_t;
35typedef int __kernel_timer_t;
36
37#ifdef __GNUC__
38typedef long long __kernel_loff_t;
39#endif 8#endif
40
41typedef struct {
42 int val[2];
43} __kernel_fsid_t;
44
45#if defined(__KERNEL__)
46
47#undef __FD_SET
48static inline void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
49{
50 unsigned long _tmp = fd / __NFDBITS;
51 unsigned long _rem = fd % __NFDBITS;
52 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
53}
54
55#undef __FD_CLR
56static inline void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
57{
58 unsigned long _tmp = fd / __NFDBITS;
59 unsigned long _rem = fd % __NFDBITS;
60 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
61}
62
63#undef __FD_ISSET
64static inline int __FD_ISSET(unsigned long fd, __const__ __kernel_fd_set *p)
65{
66 unsigned long _tmp = fd / __NFDBITS;
67 unsigned long _rem = fd % __NFDBITS;
68 return (p->fds_bits[_tmp] & (1UL<<_rem)) != 0;
69}
70
71/*
72 * This will unroll the loop for the normal constant cases (8 or 32 longs,
73 * for 256 and 1024-bit fd_sets respectively)
74 */
75#undef __FD_ZERO
76static inline void __FD_ZERO(__kernel_fd_set *p)
77{
78 unsigned long *tmp = p->fds_bits;
79 int i;
80
81 if (__builtin_constant_p(__FDSET_LONGS)) {
82 switch (__FDSET_LONGS) {
83 case 32:
84 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
85 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
86 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
87 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
88 tmp[16] = 0; tmp[17] = 0; tmp[18] = 0; tmp[19] = 0;
89 tmp[20] = 0; tmp[21] = 0; tmp[22] = 0; tmp[23] = 0;
90 tmp[24] = 0; tmp[25] = 0; tmp[26] = 0; tmp[27] = 0;
91 tmp[28] = 0; tmp[29] = 0; tmp[30] = 0; tmp[31] = 0;
92 return;
93 case 16:
94 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
95 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
96 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
97 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
98 return;
99 case 8:
100 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
101 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
102 return;
103 case 4:
104 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
105 return;
106 }
107 }
108 i = __FDSET_LONGS;
109 while (i) {
110 i--;
111 *tmp = 0;
112 tmp++;
113 }
114}
115
116#endif /* defined(__KERNEL__) */
117
118#endif /* !(__ARCH_SPARC_POSIX_TYPES_H) */
diff --git a/include/asm-sparc/posix_types_32.h b/include/asm-sparc/posix_types_32.h
new file mode 100644
index 000000000000..6bb6eb1ca0f2
--- /dev/null
+++ b/include/asm-sparc/posix_types_32.h
@@ -0,0 +1,118 @@
1#ifndef __ARCH_SPARC_POSIX_TYPES_H
2#define __ARCH_SPARC_POSIX_TYPES_H
3
4/*
5 * This file is generally used by user-level software, so you need to
6 * be a little careful about namespace pollution etc. Also, we cannot
7 * assume GCC is being used.
8 */
9
10typedef unsigned int __kernel_size_t;
11typedef int __kernel_ssize_t;
12typedef long int __kernel_ptrdiff_t;
13typedef long __kernel_time_t;
14typedef long __kernel_suseconds_t;
15typedef long __kernel_clock_t;
16typedef int __kernel_pid_t;
17typedef unsigned short __kernel_ipc_pid_t;
18typedef unsigned short __kernel_uid_t;
19typedef unsigned short __kernel_gid_t;
20typedef unsigned long __kernel_ino_t;
21typedef unsigned short __kernel_mode_t;
22typedef unsigned short __kernel_umode_t;
23typedef short __kernel_nlink_t;
24typedef long __kernel_daddr_t;
25typedef long __kernel_off_t;
26typedef char * __kernel_caddr_t;
27typedef unsigned short __kernel_uid16_t;
28typedef unsigned short __kernel_gid16_t;
29typedef unsigned int __kernel_uid32_t;
30typedef unsigned int __kernel_gid32_t;
31typedef unsigned short __kernel_old_uid_t;
32typedef unsigned short __kernel_old_gid_t;
33typedef unsigned short __kernel_old_dev_t;
34typedef int __kernel_clockid_t;
35typedef int __kernel_timer_t;
36
37#ifdef __GNUC__
38typedef long long __kernel_loff_t;
39#endif
40
41typedef struct {
42 int val[2];
43} __kernel_fsid_t;
44
45#if defined(__KERNEL__)
46
47#undef __FD_SET
48static inline void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
49{
50 unsigned long _tmp = fd / __NFDBITS;
51 unsigned long _rem = fd % __NFDBITS;
52 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
53}
54
55#undef __FD_CLR
56static inline void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
57{
58 unsigned long _tmp = fd / __NFDBITS;
59 unsigned long _rem = fd % __NFDBITS;
60 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
61}
62
63#undef __FD_ISSET
64static inline int __FD_ISSET(unsigned long fd, __const__ __kernel_fd_set *p)
65{
66 unsigned long _tmp = fd / __NFDBITS;
67 unsigned long _rem = fd % __NFDBITS;
68 return (p->fds_bits[_tmp] & (1UL<<_rem)) != 0;
69}
70
71/*
72 * This will unroll the loop for the normal constant cases (8 or 32 longs,
73 * for 256 and 1024-bit fd_sets respectively)
74 */
75#undef __FD_ZERO
76static inline void __FD_ZERO(__kernel_fd_set *p)
77{
78 unsigned long *tmp = p->fds_bits;
79 int i;
80
81 if (__builtin_constant_p(__FDSET_LONGS)) {
82 switch (__FDSET_LONGS) {
83 case 32:
84 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
85 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
86 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
87 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
88 tmp[16] = 0; tmp[17] = 0; tmp[18] = 0; tmp[19] = 0;
89 tmp[20] = 0; tmp[21] = 0; tmp[22] = 0; tmp[23] = 0;
90 tmp[24] = 0; tmp[25] = 0; tmp[26] = 0; tmp[27] = 0;
91 tmp[28] = 0; tmp[29] = 0; tmp[30] = 0; tmp[31] = 0;
92 return;
93 case 16:
94 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
95 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
96 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
97 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
98 return;
99 case 8:
100 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
101 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
102 return;
103 case 4:
104 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
105 return;
106 }
107 }
108 i = __FDSET_LONGS;
109 while (i) {
110 i--;
111 *tmp = 0;
112 tmp++;
113 }
114}
115
116#endif /* defined(__KERNEL__) */
117
118#endif /* !(__ARCH_SPARC_POSIX_TYPES_H) */
diff --git a/include/asm-sparc/posix_types_64.h b/include/asm-sparc/posix_types_64.h
new file mode 100644
index 000000000000..ba8f93295763
--- /dev/null
+++ b/include/asm-sparc/posix_types_64.h
@@ -0,0 +1,122 @@
1#ifndef __ARCH_SPARC64_POSIX_TYPES_H
2#define __ARCH_SPARC64_POSIX_TYPES_H
3
4/*
5 * This file is generally used by user-level software, so you need to
6 * be a little careful about namespace pollution etc. Also, we cannot
7 * assume GCC is being used.
8 */
9
10typedef unsigned long __kernel_size_t;
11typedef long __kernel_ssize_t;
12typedef long __kernel_ptrdiff_t;
13typedef long __kernel_time_t;
14typedef long __kernel_clock_t;
15typedef int __kernel_pid_t;
16typedef int __kernel_ipc_pid_t;
17typedef unsigned int __kernel_uid_t;
18typedef unsigned int __kernel_gid_t;
19typedef unsigned long __kernel_ino_t;
20typedef unsigned int __kernel_mode_t;
21typedef unsigned short __kernel_umode_t;
22typedef unsigned int __kernel_nlink_t;
23typedef int __kernel_daddr_t;
24typedef long __kernel_off_t;
25typedef char * __kernel_caddr_t;
26typedef unsigned short __kernel_uid16_t;
27typedef unsigned short __kernel_gid16_t;
28typedef int __kernel_clockid_t;
29typedef int __kernel_timer_t;
30
31typedef unsigned short __kernel_old_uid_t;
32typedef unsigned short __kernel_old_gid_t;
33typedef __kernel_uid_t __kernel_uid32_t;
34typedef __kernel_gid_t __kernel_gid32_t;
35
36typedef unsigned int __kernel_old_dev_t;
37
38/* Note this piece of asymmetry from the v9 ABI. */
39typedef int __kernel_suseconds_t;
40
41#ifdef __GNUC__
42typedef long long __kernel_loff_t;
43#endif
44
45typedef struct {
46 int val[2];
47} __kernel_fsid_t;
48
49#if defined(__KERNEL__)
50
51#undef __FD_SET
52static inline void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
53{
54 unsigned long _tmp = fd / __NFDBITS;
55 unsigned long _rem = fd % __NFDBITS;
56 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
57}
58
59#undef __FD_CLR
60static inline void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
61{
62 unsigned long _tmp = fd / __NFDBITS;
63 unsigned long _rem = fd % __NFDBITS;
64 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
65}
66
67#undef __FD_ISSET
68static inline int __FD_ISSET(unsigned long fd, __const__ __kernel_fd_set *p)
69{
70 unsigned long _tmp = fd / __NFDBITS;
71 unsigned long _rem = fd % __NFDBITS;
72 return (p->fds_bits[_tmp] & (1UL<<_rem)) != 0;
73}
74
75/*
76 * This will unroll the loop for the normal constant cases (8 or 32 longs,
77 * for 256 and 1024-bit fd_sets respectively)
78 */
79#undef __FD_ZERO
80static inline void __FD_ZERO(__kernel_fd_set *p)
81{
82 unsigned long *tmp = p->fds_bits;
83 int i;
84
85 if (__builtin_constant_p(__FDSET_LONGS)) {
86 switch (__FDSET_LONGS) {
87 case 32:
88 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
89 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
90 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
91 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
92 tmp[16] = 0; tmp[17] = 0; tmp[18] = 0; tmp[19] = 0;
93 tmp[20] = 0; tmp[21] = 0; tmp[22] = 0; tmp[23] = 0;
94 tmp[24] = 0; tmp[25] = 0; tmp[26] = 0; tmp[27] = 0;
95 tmp[28] = 0; tmp[29] = 0; tmp[30] = 0; tmp[31] = 0;
96 return;
97 case 16:
98 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
99 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
100 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
101 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
102 return;
103 case 8:
104 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
105 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
106 return;
107 case 4:
108 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
109 return;
110 }
111 }
112 i = __FDSET_LONGS;
113 while (i) {
114 i--;
115 *tmp = 0;
116 tmp++;
117 }
118}
119
120#endif /* defined(__KERNEL__) */
121
122#endif /* !(__ARCH_SPARC64_POSIX_TYPES_H) */
diff --git a/include/asm-sparc/processor.h b/include/asm-sparc/processor.h
index 8898efbbbe07..11a66bb02eaa 100644
--- a/include/asm-sparc/processor.h
+++ b/include/asm-sparc/processor.h
@@ -1,128 +1,8 @@
1/* include/asm-sparc/processor.h 1#ifndef ___ASM_SPARC_PROCESSOR_H
2 * 2#define ___ASM_SPARC_PROCESSOR_H
3 * Copyright (C) 1994 David S. Miller (davem@caip.rutgers.edu) 3#if defined(__sparc__) && defined(__arch64__)
4 */ 4#include <asm-sparc/processor_64.h>
5 5#else
6#ifndef __ASM_SPARC_PROCESSOR_H 6#include <asm-sparc/processor_32.h>
7#define __ASM_SPARC_PROCESSOR_H
8
9/*
10 * Sparc32 implementation of macro that returns current
11 * instruction pointer ("program counter").
12 */
13#define current_text_addr() ({ void *pc; __asm__("sethi %%hi(1f), %0; or %0, %%lo(1f), %0;\n1:" : "=r" (pc)); pc; })
14
15#include <asm/psr.h>
16#include <asm/ptrace.h>
17#include <asm/head.h>
18#include <asm/signal.h>
19#include <asm/btfixup.h>
20#include <asm/page.h>
21
22/*
23 * The sparc has no problems with write protection
24 */
25#define wp_works_ok 1
26#define wp_works_ok__is_a_macro /* for versions in ksyms.c */
27
28/* Whee, this is STACK_TOP + PAGE_SIZE and the lowest kernel address too...
29 * That one page is used to protect kernel from intruders, so that
30 * we can make our access_ok test faster
31 */
32#define TASK_SIZE PAGE_OFFSET
33#ifdef __KERNEL__
34#define STACK_TOP (PAGE_OFFSET - PAGE_SIZE)
35#define STACK_TOP_MAX STACK_TOP
36#endif /* __KERNEL__ */
37
38struct task_struct;
39
40#ifdef __KERNEL__
41struct fpq {
42 unsigned long *insn_addr;
43 unsigned long insn;
44};
45#endif 7#endif
46
47typedef struct {
48 int seg;
49} mm_segment_t;
50
51/* The Sparc processor specific thread struct. */
52struct thread_struct {
53 struct pt_regs *kregs;
54 unsigned int _pad1;
55
56 /* Special child fork kpsr/kwim values. */
57 unsigned long fork_kpsr __attribute__ ((aligned (8)));
58 unsigned long fork_kwim;
59
60 /* Floating point regs */
61 unsigned long float_regs[32] __attribute__ ((aligned (8)));
62 unsigned long fsr;
63 unsigned long fpqdepth;
64 struct fpq fpqueue[16];
65 unsigned long flags;
66 mm_segment_t current_ds;
67};
68
69#define SPARC_FLAG_KTHREAD 0x1 /* task is a kernel thread */
70#define SPARC_FLAG_UNALIGNED 0x2 /* is allowed to do unaligned accesses */
71
72#define INIT_THREAD { \
73 .flags = SPARC_FLAG_KTHREAD, \
74 .current_ds = KERNEL_DS, \
75}
76
77/* Return saved PC of a blocked thread. */
78extern unsigned long thread_saved_pc(struct task_struct *t);
79
80/* Do necessary setup to start up a newly executed thread. */
81static inline void start_thread(struct pt_regs * regs, unsigned long pc,
82 unsigned long sp)
83{
84 register unsigned long zero asm("g1");
85
86 regs->psr = (regs->psr & (PSR_CWP)) | PSR_S;
87 regs->pc = ((pc & (~3)) - 4);
88 regs->npc = regs->pc + 4;
89 regs->y = 0;
90 zero = 0;
91 __asm__ __volatile__("std\t%%g0, [%0 + %3 + 0x00]\n\t"
92 "std\t%%g0, [%0 + %3 + 0x08]\n\t"
93 "std\t%%g0, [%0 + %3 + 0x10]\n\t"
94 "std\t%%g0, [%0 + %3 + 0x18]\n\t"
95 "std\t%%g0, [%0 + %3 + 0x20]\n\t"
96 "std\t%%g0, [%0 + %3 + 0x28]\n\t"
97 "std\t%%g0, [%0 + %3 + 0x30]\n\t"
98 "st\t%1, [%0 + %3 + 0x38]\n\t"
99 "st\t%%g0, [%0 + %3 + 0x3c]"
100 : /* no outputs */
101 : "r" (regs),
102 "r" (sp - sizeof(struct reg_window)),
103 "r" (zero),
104 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))
105 : "memory");
106}
107
108/* Free all resources held by a thread. */
109#define release_thread(tsk) do { } while(0)
110extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
111
112/* Prepare to copy thread state - unlazy all lazy status */
113#define prepare_to_copy(tsk) do { } while (0)
114
115extern unsigned long get_wchan(struct task_struct *);
116
117#define KSTK_EIP(tsk) ((tsk)->thread.kregs->pc)
118#define KSTK_ESP(tsk) ((tsk)->thread.kregs->u_regs[UREG_FP])
119
120#ifdef __KERNEL__
121
122extern struct task_struct *last_task_used_math;
123
124#define cpu_relax() barrier()
125
126#endif 8#endif
127
128#endif /* __ASM_SPARC_PROCESSOR_H */
diff --git a/include/asm-sparc/processor_32.h b/include/asm-sparc/processor_32.h
new file mode 100644
index 000000000000..562c0d69c537
--- /dev/null
+++ b/include/asm-sparc/processor_32.h
@@ -0,0 +1,128 @@
1/* include/asm-sparc/processor.h
2 *
3 * Copyright (C) 1994 David S. Miller (davem@caip.rutgers.edu)
4 */
5
6#ifndef __ASM_SPARC_PROCESSOR_H
7#define __ASM_SPARC_PROCESSOR_H
8
9/*
10 * Sparc32 implementation of macro that returns current
11 * instruction pointer ("program counter").
12 */
13#define current_text_addr() ({ void *pc; __asm__("sethi %%hi(1f), %0; or %0, %%lo(1f), %0;\n1:" : "=r" (pc)); pc; })
14
15#include <asm/psr.h>
16#include <asm/ptrace.h>
17#include <asm/head.h>
18#include <asm/signal.h>
19#include <asm/btfixup.h>
20#include <asm/page.h>
21
22/*
23 * The sparc has no problems with write protection
24 */
25#define wp_works_ok 1
26#define wp_works_ok__is_a_macro /* for versions in ksyms.c */
27
28/* Whee, this is STACK_TOP + PAGE_SIZE and the lowest kernel address too...
29 * That one page is used to protect kernel from intruders, so that
30 * we can make our access_ok test faster
31 */
32#define TASK_SIZE PAGE_OFFSET
33#ifdef __KERNEL__
34#define STACK_TOP (PAGE_OFFSET - PAGE_SIZE)
35#define STACK_TOP_MAX STACK_TOP
36#endif /* __KERNEL__ */
37
38struct task_struct;
39
40#ifdef __KERNEL__
41struct fpq {
42 unsigned long *insn_addr;
43 unsigned long insn;
44};
45#endif
46
47typedef struct {
48 int seg;
49} mm_segment_t;
50
51/* The Sparc processor specific thread struct. */
52struct thread_struct {
53 struct pt_regs *kregs;
54 unsigned int _pad1;
55
56 /* Special child fork kpsr/kwim values. */
57 unsigned long fork_kpsr __attribute__ ((aligned (8)));
58 unsigned long fork_kwim;
59
60 /* Floating point regs */
61 unsigned long float_regs[32] __attribute__ ((aligned (8)));
62 unsigned long fsr;
63 unsigned long fpqdepth;
64 struct fpq fpqueue[16];
65 unsigned long flags;
66 mm_segment_t current_ds;
67};
68
69#define SPARC_FLAG_KTHREAD 0x1 /* task is a kernel thread */
70#define SPARC_FLAG_UNALIGNED 0x2 /* is allowed to do unaligned accesses */
71
72#define INIT_THREAD { \
73 .flags = SPARC_FLAG_KTHREAD, \
74 .current_ds = KERNEL_DS, \
75}
76
77/* Return saved PC of a blocked thread. */
78extern unsigned long thread_saved_pc(struct task_struct *t);
79
80/* Do necessary setup to start up a newly executed thread. */
81static inline void start_thread(struct pt_regs * regs, unsigned long pc,
82 unsigned long sp)
83{
84 register unsigned long zero asm("g1");
85
86 regs->psr = (regs->psr & (PSR_CWP)) | PSR_S;
87 regs->pc = ((pc & (~3)) - 4);
88 regs->npc = regs->pc + 4;
89 regs->y = 0;
90 zero = 0;
91 __asm__ __volatile__("std\t%%g0, [%0 + %3 + 0x00]\n\t"
92 "std\t%%g0, [%0 + %3 + 0x08]\n\t"
93 "std\t%%g0, [%0 + %3 + 0x10]\n\t"
94 "std\t%%g0, [%0 + %3 + 0x18]\n\t"
95 "std\t%%g0, [%0 + %3 + 0x20]\n\t"
96 "std\t%%g0, [%0 + %3 + 0x28]\n\t"
97 "std\t%%g0, [%0 + %3 + 0x30]\n\t"
98 "st\t%1, [%0 + %3 + 0x38]\n\t"
99 "st\t%%g0, [%0 + %3 + 0x3c]"
100 : /* no outputs */
101 : "r" (regs),
102 "r" (sp - sizeof(struct reg_window)),
103 "r" (zero),
104 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))
105 : "memory");
106}
107
108/* Free all resources held by a thread. */
109#define release_thread(tsk) do { } while(0)
110extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
111
112/* Prepare to copy thread state - unlazy all lazy status */
113#define prepare_to_copy(tsk) do { } while (0)
114
115extern unsigned long get_wchan(struct task_struct *);
116
117#define KSTK_EIP(tsk) ((tsk)->thread.kregs->pc)
118#define KSTK_ESP(tsk) ((tsk)->thread.kregs->u_regs[UREG_FP])
119
120#ifdef __KERNEL__
121
122extern struct task_struct *last_task_used_math;
123
124#define cpu_relax() barrier()
125
126#endif
127
128#endif /* __ASM_SPARC_PROCESSOR_H */
diff --git a/include/asm-sparc/processor_64.h b/include/asm-sparc/processor_64.h
new file mode 100644
index 000000000000..70d42801a0d2
--- /dev/null
+++ b/include/asm-sparc/processor_64.h
@@ -0,0 +1,237 @@
1/*
2 * include/asm-sparc64/processor.h
3 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef __ASM_SPARC64_PROCESSOR_H
8#define __ASM_SPARC64_PROCESSOR_H
9
10/*
11 * Sparc64 implementation of macro that returns current
12 * instruction pointer ("program counter").
13 */
14#define current_text_addr() ({ void *pc; __asm__("rd %%pc, %0" : "=r" (pc)); pc; })
15
16#include <asm/asi.h>
17#include <asm/pstate.h>
18#include <asm/ptrace.h>
19#include <asm/page.h>
20
21/* The sparc has no problems with write protection */
22#define wp_works_ok 1
23#define wp_works_ok__is_a_macro /* for versions in ksyms.c */
24
25/*
26 * User lives in his very own context, and cannot reference us. Note
27 * that TASK_SIZE is a misnomer, it really gives maximum user virtual
28 * address that the kernel will allocate out.
29 *
30 * XXX No longer using virtual page tables, kill this upper limit...
31 */
32#define VA_BITS 44
33#ifndef __ASSEMBLY__
34#define VPTE_SIZE (1UL << (VA_BITS - PAGE_SHIFT + 3))
35#else
36#define VPTE_SIZE (1 << (VA_BITS - PAGE_SHIFT + 3))
37#endif
38
39#define TASK_SIZE ((unsigned long)-VPTE_SIZE)
40#define TASK_SIZE_OF(tsk) \
41 (test_tsk_thread_flag(tsk,TIF_32BIT) ? \
42 (1UL << 32UL) : TASK_SIZE)
43#ifdef __KERNEL__
44
45#define STACK_TOP32 ((1UL << 32UL) - PAGE_SIZE)
46#define STACK_TOP64 (0x0000080000000000UL - (1UL << 32UL))
47
48#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
49 STACK_TOP32 : STACK_TOP64)
50
51#define STACK_TOP_MAX STACK_TOP64
52
53#endif
54
55#ifndef __ASSEMBLY__
56
57typedef struct {
58 unsigned char seg;
59} mm_segment_t;
60
61/* The Sparc processor specific thread struct. */
62/* XXX This should die, everything can go into thread_info now. */
63struct thread_struct {
64#ifdef CONFIG_DEBUG_SPINLOCK
65 /* How many spinlocks held by this thread.
66 * Used with spin lock debugging to catch tasks
67 * sleeping illegally with locks held.
68 */
69 int smp_lock_count;
70 unsigned int smp_lock_pc;
71#else
72 int dummy; /* f'in gcc bug... */
73#endif
74};
75
76#endif /* !(__ASSEMBLY__) */
77
78#ifndef CONFIG_DEBUG_SPINLOCK
79#define INIT_THREAD { \
80 0, \
81}
82#else /* CONFIG_DEBUG_SPINLOCK */
83#define INIT_THREAD { \
84/* smp_lock_count, smp_lock_pc, */ \
85 0, 0, \
86}
87#endif /* !(CONFIG_DEBUG_SPINLOCK) */
88
89#ifndef __ASSEMBLY__
90
91#include <linux/types.h>
92
93/* Return saved PC of a blocked thread. */
94struct task_struct;
95extern unsigned long thread_saved_pc(struct task_struct *);
96
97/* On Uniprocessor, even in RMO processes see TSO semantics */
98#ifdef CONFIG_SMP
99#define TSTATE_INITIAL_MM TSTATE_TSO
100#else
101#define TSTATE_INITIAL_MM TSTATE_RMO
102#endif
103
104/* Do necessary setup to start up a newly executed thread. */
105#define start_thread(regs, pc, sp) \
106do { \
107 unsigned long __asi = ASI_PNF; \
108 regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (__asi << 24UL); \
109 regs->tpc = ((pc & (~3)) - 4); \
110 regs->tnpc = regs->tpc + 4; \
111 regs->y = 0; \
112 set_thread_wstate(1 << 3); \
113 if (current_thread_info()->utraps) { \
114 if (*(current_thread_info()->utraps) < 2) \
115 kfree(current_thread_info()->utraps); \
116 else \
117 (*(current_thread_info()->utraps))--; \
118 current_thread_info()->utraps = NULL; \
119 } \
120 __asm__ __volatile__( \
121 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
122 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
123 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
124 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
125 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
126 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
127 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
128 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
129 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
130 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
131 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
132 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
133 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
134 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
135 "stx %1, [%0 + %2 + 0x70]\n\t" \
136 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
137 "wrpr %%g0, (1 << 3), %%wstate\n\t" \
138 : \
139 : "r" (regs), "r" (sp - sizeof(struct reg_window) - STACK_BIAS), \
140 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
141} while (0)
142
143#define start_thread32(regs, pc, sp) \
144do { \
145 unsigned long __asi = ASI_PNF; \
146 pc &= 0x00000000ffffffffUL; \
147 sp &= 0x00000000ffffffffUL; \
148 regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM) | (__asi << 24UL); \
149 regs->tpc = ((pc & (~3)) - 4); \
150 regs->tnpc = regs->tpc + 4; \
151 regs->y = 0; \
152 set_thread_wstate(2 << 3); \
153 if (current_thread_info()->utraps) { \
154 if (*(current_thread_info()->utraps) < 2) \
155 kfree(current_thread_info()->utraps); \
156 else \
157 (*(current_thread_info()->utraps))--; \
158 current_thread_info()->utraps = NULL; \
159 } \
160 __asm__ __volatile__( \
161 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
162 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
163 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
164 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
165 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
166 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
167 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
168 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
169 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
170 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
171 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
172 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
173 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
174 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
175 "stx %1, [%0 + %2 + 0x70]\n\t" \
176 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
177 "wrpr %%g0, (2 << 3), %%wstate\n\t" \
178 : \
179 : "r" (regs), "r" (sp - sizeof(struct reg_window32)), \
180 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
181} while (0)
182
183/* Free all resources held by a thread. */
184#define release_thread(tsk) do { } while (0)
185
186/* Prepare to copy thread state - unlazy all lazy status */
187#define prepare_to_copy(tsk) do { } while (0)
188
189extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
190
191extern unsigned long get_wchan(struct task_struct *task);
192
193#define task_pt_regs(tsk) (task_thread_info(tsk)->kregs)
194#define KSTK_EIP(tsk) (task_pt_regs(tsk)->tpc)
195#define KSTK_ESP(tsk) (task_pt_regs(tsk)->u_regs[UREG_FP])
196
197#define cpu_relax() barrier()
198
199/* Prefetch support. This is tuned for UltraSPARC-III and later.
200 * UltraSPARC-I will treat these as nops, and UltraSPARC-II has
201 * a shallower prefetch queue than later chips.
202 */
203#define ARCH_HAS_PREFETCH
204#define ARCH_HAS_PREFETCHW
205#define ARCH_HAS_SPINLOCK_PREFETCH
206
207static inline void prefetch(const void *x)
208{
209 /* We do not use the read prefetch mnemonic because that
210 * prefetches into the prefetch-cache which only is accessible
211 * by floating point operations in UltraSPARC-III and later.
212 * By contrast, "#one_write" prefetches into the L2 cache
213 * in shared state.
214 */
215 __asm__ __volatile__("prefetch [%0], #one_write"
216 : /* no outputs */
217 : "r" (x));
218}
219
220static inline void prefetchw(const void *x)
221{
222 /* The most optimal prefetch to use for writes is
223 * "#n_writes". This brings the cacheline into the
224 * L2 cache in "owned" state.
225 */
226 __asm__ __volatile__("prefetch [%0], #n_writes"
227 : /* no outputs */
228 : "r" (x));
229}
230
231#define spin_lock_prefetch(x) prefetchw(x)
232
233#define HAVE_ARCH_PICK_MMAP_LAYOUT
234
235#endif /* !(__ASSEMBLY__) */
236
237#endif /* !(__ASM_SPARC64_PROCESSOR_H) */
diff --git a/include/asm-sparc/psrcompat.h b/include/asm-sparc/psrcompat.h
new file mode 100644
index 000000000000..44b6327dbbf5
--- /dev/null
+++ b/include/asm-sparc/psrcompat.h
@@ -0,0 +1,45 @@
1#ifndef _SPARC64_PSRCOMPAT_H
2#define _SPARC64_PSRCOMPAT_H
3
4#include <asm/pstate.h>
5
6/* Old 32-bit PSR fields for the compatibility conversion code. */
7#define PSR_CWP 0x0000001f /* current window pointer */
8#define PSR_ET 0x00000020 /* enable traps field */
9#define PSR_PS 0x00000040 /* previous privilege level */
10#define PSR_S 0x00000080 /* current privilege level */
11#define PSR_PIL 0x00000f00 /* processor interrupt level */
12#define PSR_EF 0x00001000 /* enable floating point */
13#define PSR_EC 0x00002000 /* enable co-processor */
14#define PSR_SYSCALL 0x00004000 /* inside of a syscall */
15#define PSR_LE 0x00008000 /* SuperSparcII little-endian */
16#define PSR_ICC 0x00f00000 /* integer condition codes */
17#define PSR_C 0x00100000 /* carry bit */
18#define PSR_V 0x00200000 /* overflow bit */
19#define PSR_Z 0x00400000 /* zero bit */
20#define PSR_N 0x00800000 /* negative bit */
21#define PSR_VERS 0x0f000000 /* cpu-version field */
22#define PSR_IMPL 0xf0000000 /* cpu-implementation field */
23
24#define PSR_V8PLUS 0xff000000 /* fake impl/ver, meaning a 64bit CPU is present */
25#define PSR_XCC 0x000f0000 /* if PSR_V8PLUS, this is %xcc */
26
27static inline unsigned int tstate_to_psr(unsigned long tstate)
28{
29 return ((tstate & TSTATE_CWP) |
30 PSR_S |
31 ((tstate & TSTATE_ICC) >> 12) |
32 ((tstate & TSTATE_XCC) >> 20) |
33 ((tstate & TSTATE_SYSCALL) ? PSR_SYSCALL : 0) |
34 PSR_V8PLUS);
35}
36
37static inline unsigned long psr_to_tstate_icc(unsigned int psr)
38{
39 unsigned long tstate = ((unsigned long)(psr & PSR_ICC)) << 12;
40 if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS)
41 tstate |= ((unsigned long)(psr & PSR_XCC)) << 20;
42 return tstate;
43}
44
45#endif /* !(_SPARC64_PSRCOMPAT_H) */
diff --git a/include/asm-sparc/pstate.h b/include/asm-sparc/pstate.h
new file mode 100644
index 000000000000..a26a53777bb0
--- /dev/null
+++ b/include/asm-sparc/pstate.h
@@ -0,0 +1,91 @@
1#ifndef _SPARC64_PSTATE_H
2#define _SPARC64_PSTATE_H
3
4#include <linux/const.h>
5
6/* The V9 PSTATE Register (with SpitFire extensions).
7 *
8 * -----------------------------------------------------------------------
9 * | Resv | IG | MG | CLE | TLE | MM | RED | PEF | AM | PRIV | IE | AG |
10 * -----------------------------------------------------------------------
11 * 63 12 11 10 9 8 7 6 5 4 3 2 1 0
12 */
13#define PSTATE_IG _AC(0x0000000000000800,UL) /* Interrupt Globals. */
14#define PSTATE_MG _AC(0x0000000000000400,UL) /* MMU Globals. */
15#define PSTATE_CLE _AC(0x0000000000000200,UL) /* Current Little Endian.*/
16#define PSTATE_TLE _AC(0x0000000000000100,UL) /* Trap Little Endian. */
17#define PSTATE_MM _AC(0x00000000000000c0,UL) /* Memory Model. */
18#define PSTATE_TSO _AC(0x0000000000000000,UL) /* MM: TotalStoreOrder */
19#define PSTATE_PSO _AC(0x0000000000000040,UL) /* MM: PartialStoreOrder */
20#define PSTATE_RMO _AC(0x0000000000000080,UL) /* MM: RelaxedMemoryOrder*/
21#define PSTATE_RED _AC(0x0000000000000020,UL) /* Reset Error Debug. */
22#define PSTATE_PEF _AC(0x0000000000000010,UL) /* Floating Point Enable.*/
23#define PSTATE_AM _AC(0x0000000000000008,UL) /* Address Mask. */
24#define PSTATE_PRIV _AC(0x0000000000000004,UL) /* Privilege. */
25#define PSTATE_IE _AC(0x0000000000000002,UL) /* Interrupt Enable. */
26#define PSTATE_AG _AC(0x0000000000000001,UL) /* Alternate Globals. */
27
28/* The V9 TSTATE Register (with SpitFire and Linux extensions).
29 *
30 * ---------------------------------------------------------------------
31 * | Resv | GL | CCR | ASI | %pil | PSTATE | Resv | CWP |
32 * ---------------------------------------------------------------------
33 * 63 43 42 40 39 32 31 24 23 20 19 8 7 5 4 0
34 */
35#define TSTATE_GL _AC(0x0000070000000000,UL) /* Global reg level */
36#define TSTATE_CCR _AC(0x000000ff00000000,UL) /* Condition Codes. */
37#define TSTATE_XCC _AC(0x000000f000000000,UL) /* Condition Codes. */
38#define TSTATE_XNEG _AC(0x0000008000000000,UL) /* %xcc Negative. */
39#define TSTATE_XZERO _AC(0x0000004000000000,UL) /* %xcc Zero. */
40#define TSTATE_XOVFL _AC(0x0000002000000000,UL) /* %xcc Overflow. */
41#define TSTATE_XCARRY _AC(0x0000001000000000,UL) /* %xcc Carry. */
42#define TSTATE_ICC _AC(0x0000000f00000000,UL) /* Condition Codes. */
43#define TSTATE_INEG _AC(0x0000000800000000,UL) /* %icc Negative. */
44#define TSTATE_IZERO _AC(0x0000000400000000,UL) /* %icc Zero. */
45#define TSTATE_IOVFL _AC(0x0000000200000000,UL) /* %icc Overflow. */
46#define TSTATE_ICARRY _AC(0x0000000100000000,UL) /* %icc Carry. */
47#define TSTATE_ASI _AC(0x00000000ff000000,UL) /* AddrSpace ID. */
48#define TSTATE_PIL _AC(0x0000000000f00000,UL) /* %pil (Linux traps)*/
49#define TSTATE_PSTATE _AC(0x00000000000fff00,UL) /* PSTATE. */
50#define TSTATE_IG _AC(0x0000000000080000,UL) /* Interrupt Globals.*/
51#define TSTATE_MG _AC(0x0000000000040000,UL) /* MMU Globals. */
52#define TSTATE_CLE _AC(0x0000000000020000,UL) /* CurrLittleEndian. */
53#define TSTATE_TLE _AC(0x0000000000010000,UL) /* TrapLittleEndian. */
54#define TSTATE_MM _AC(0x000000000000c000,UL) /* Memory Model. */
55#define TSTATE_TSO _AC(0x0000000000000000,UL) /* MM: TSO */
56#define TSTATE_PSO _AC(0x0000000000004000,UL) /* MM: PSO */
57#define TSTATE_RMO _AC(0x0000000000008000,UL) /* MM: RMO */
58#define TSTATE_RED _AC(0x0000000000002000,UL) /* Reset Error Debug.*/
59#define TSTATE_PEF _AC(0x0000000000001000,UL) /* FPU Enable. */
60#define TSTATE_AM _AC(0x0000000000000800,UL) /* Address Mask. */
61#define TSTATE_PRIV _AC(0x0000000000000400,UL) /* Privilege. */
62#define TSTATE_IE _AC(0x0000000000000200,UL) /* Interrupt Enable. */
63#define TSTATE_AG _AC(0x0000000000000100,UL) /* Alternate Globals.*/
64#define TSTATE_SYSCALL _AC(0x0000000000000020,UL) /* in syscall trap */
65#define TSTATE_CWP _AC(0x000000000000001f,UL) /* Curr Win-Pointer. */
66
67/* Floating-Point Registers State Register.
68 *
69 * --------------------------------
70 * | Resv | FEF | DU | DL |
71 * --------------------------------
72 * 63 3 2 1 0
73 */
74#define FPRS_FEF _AC(0x0000000000000004,UL) /* FPU Enable. */
75#define FPRS_DU _AC(0x0000000000000002,UL) /* Dirty Upper. */
76#define FPRS_DL _AC(0x0000000000000001,UL) /* Dirty Lower. */
77
78/* Version Register.
79 *
80 * ------------------------------------------------------
81 * | MANUF | IMPL | MASK | Resv | MAXTL | Resv | MAXWIN |
82 * ------------------------------------------------------
83 * 63 48 47 32 31 24 23 16 15 8 7 5 4 0
84 */
85#define VERS_MANUF _AC(0xffff000000000000,UL) /* Manufacturer. */
86#define VERS_IMPL _AC(0x0000ffff00000000,UL) /* Implementation. */
87#define VERS_MASK _AC(0x00000000ff000000,UL) /* Mask Set Revision.*/
88#define VERS_MAXTL _AC(0x000000000000ff00,UL) /* Max Trap Level. */
89#define VERS_MAXWIN _AC(0x000000000000001f,UL) /* Max RegWindow Idx.*/
90
91#endif /* !(_SPARC64_PSTATE_H) */
diff --git a/include/asm-sparc/ptrace.h b/include/asm-sparc/ptrace.h
index 11f3bc2bb3f5..f36ab6c30ff3 100644
--- a/include/asm-sparc/ptrace.h
+++ b/include/asm-sparc/ptrace.h
@@ -1,175 +1,8 @@
1#ifndef _SPARC_PTRACE_H 1#ifndef ___ASM_SPARC_PTRACE_H
2#define _SPARC_PTRACE_H 2#define ___ASM_SPARC_PTRACE_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <asm/psr.h> 4#include <asm-sparc/ptrace_64.h>
5 5#else
6/* This struct defines the way the registers are stored on the 6#include <asm-sparc/ptrace_32.h>
7 * stack during a system call and basically all traps.
8 */
9
10#ifndef __ASSEMBLY__
11
12#include <linux/types.h>
13
14struct pt_regs {
15 unsigned long psr;
16 unsigned long pc;
17 unsigned long npc;
18 unsigned long y;
19 unsigned long u_regs[16]; /* globals and ins */
20};
21
22#define UREG_G0 0
23#define UREG_G1 1
24#define UREG_G2 2
25#define UREG_G3 3
26#define UREG_G4 4
27#define UREG_G5 5
28#define UREG_G6 6
29#define UREG_G7 7
30#define UREG_I0 8
31#define UREG_I1 9
32#define UREG_I2 10
33#define UREG_I3 11
34#define UREG_I4 12
35#define UREG_I5 13
36#define UREG_I6 14
37#define UREG_I7 15
38#define UREG_WIM UREG_G0
39#define UREG_FADDR UREG_G0
40#define UREG_FP UREG_I6
41#define UREG_RETPC UREG_I7
42
43static inline bool pt_regs_is_syscall(struct pt_regs *regs)
44{
45 return (regs->psr & PSR_SYSCALL);
46}
47
48static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
49{
50 return (regs->psr &= ~PSR_SYSCALL);
51}
52
53/* A register window */
54struct reg_window {
55 unsigned long locals[8];
56 unsigned long ins[8];
57};
58
59/* A Sparc stack frame */
60struct sparc_stackf {
61 unsigned long locals[8];
62 unsigned long ins[6];
63 struct sparc_stackf *fp;
64 unsigned long callers_pc;
65 char *structptr;
66 unsigned long xargs[6];
67 unsigned long xxargs[1];
68};
69
70#define TRACEREG_SZ sizeof(struct pt_regs)
71#define STACKFRAME_SZ sizeof(struct sparc_stackf)
72
73#ifdef __KERNEL__
74
75#define user_mode(regs) (!((regs)->psr & PSR_PS))
76#define instruction_pointer(regs) ((regs)->pc)
77unsigned long profile_pc(struct pt_regs *);
78extern void show_regs(struct pt_regs *);
79#endif 7#endif
80
81#else /* __ASSEMBLY__ */
82/* For assembly code. */
83#define TRACEREG_SZ 0x50
84#define STACKFRAME_SZ 0x60
85#endif 8#endif
86
87/*
88 * The asm-offsets.h is a generated file, so we cannot include it.
89 * It may be OK for glibc headers, but it's utterly pointless for C code.
90 * The assembly code using those offsets has to include it explicitly.
91 */
92/* #include <asm/asm-offsets.h> */
93
94/* These are for pt_regs. */
95#define PT_PSR 0x0
96#define PT_PC 0x4
97#define PT_NPC 0x8
98#define PT_Y 0xc
99#define PT_G0 0x10
100#define PT_WIM PT_G0
101#define PT_G1 0x14
102#define PT_G2 0x18
103#define PT_G3 0x1c
104#define PT_G4 0x20
105#define PT_G5 0x24
106#define PT_G6 0x28
107#define PT_G7 0x2c
108#define PT_I0 0x30
109#define PT_I1 0x34
110#define PT_I2 0x38
111#define PT_I3 0x3c
112#define PT_I4 0x40
113#define PT_I5 0x44
114#define PT_I6 0x48
115#define PT_FP PT_I6
116#define PT_I7 0x4c
117
118/* Reg_window offsets */
119#define RW_L0 0x00
120#define RW_L1 0x04
121#define RW_L2 0x08
122#define RW_L3 0x0c
123#define RW_L4 0x10
124#define RW_L5 0x14
125#define RW_L6 0x18
126#define RW_L7 0x1c
127#define RW_I0 0x20
128#define RW_I1 0x24
129#define RW_I2 0x28
130#define RW_I3 0x2c
131#define RW_I4 0x30
132#define RW_I5 0x34
133#define RW_I6 0x38
134#define RW_I7 0x3c
135
136/* Stack_frame offsets */
137#define SF_L0 0x00
138#define SF_L1 0x04
139#define SF_L2 0x08
140#define SF_L3 0x0c
141#define SF_L4 0x10
142#define SF_L5 0x14
143#define SF_L6 0x18
144#define SF_L7 0x1c
145#define SF_I0 0x20
146#define SF_I1 0x24
147#define SF_I2 0x28
148#define SF_I3 0x2c
149#define SF_I4 0x30
150#define SF_I5 0x34
151#define SF_FP 0x38
152#define SF_PC 0x3c
153#define SF_RETP 0x40
154#define SF_XARG0 0x44
155#define SF_XARG1 0x48
156#define SF_XARG2 0x4c
157#define SF_XARG3 0x50
158#define SF_XARG4 0x54
159#define SF_XARG5 0x58
160#define SF_XXARG 0x5c
161
162/* Stuff for the ptrace system call */
163#define PTRACE_SPARC_DETACH 11
164#define PTRACE_GETREGS 12
165#define PTRACE_SETREGS 13
166#define PTRACE_GETFPREGS 14
167#define PTRACE_SETFPREGS 15
168#define PTRACE_READDATA 16
169#define PTRACE_WRITEDATA 17
170#define PTRACE_READTEXT 18
171#define PTRACE_WRITETEXT 19
172#define PTRACE_GETFPAREGS 20
173#define PTRACE_SETFPAREGS 21
174
175#endif /* !(_SPARC_PTRACE_H) */
diff --git a/include/asm-sparc/ptrace_32.h b/include/asm-sparc/ptrace_32.h
new file mode 100644
index 000000000000..0401cc7ec38e
--- /dev/null
+++ b/include/asm-sparc/ptrace_32.h
@@ -0,0 +1,175 @@
1#ifndef _SPARC_PTRACE_H
2#define _SPARC_PTRACE_H
3
4#include <asm/psr.h>
5
6/* This struct defines the way the registers are stored on the
7 * stack during a system call and basically all traps.
8 */
9
10#ifndef __ASSEMBLY__
11
12#include <linux/types.h>
13
14struct pt_regs {
15 unsigned long psr;
16 unsigned long pc;
17 unsigned long npc;
18 unsigned long y;
19 unsigned long u_regs[16]; /* globals and ins */
20};
21
22#define UREG_G0 0
23#define UREG_G1 1
24#define UREG_G2 2
25#define UREG_G3 3
26#define UREG_G4 4
27#define UREG_G5 5
28#define UREG_G6 6
29#define UREG_G7 7
30#define UREG_I0 8
31#define UREG_I1 9
32#define UREG_I2 10
33#define UREG_I3 11
34#define UREG_I4 12
35#define UREG_I5 13
36#define UREG_I6 14
37#define UREG_I7 15
38#define UREG_WIM UREG_G0
39#define UREG_FADDR UREG_G0
40#define UREG_FP UREG_I6
41#define UREG_RETPC UREG_I7
42
43static inline bool pt_regs_is_syscall(struct pt_regs *regs)
44{
45 return (regs->psr & PSR_SYSCALL);
46}
47
48static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
49{
50 return (regs->psr &= ~PSR_SYSCALL);
51}
52
53/* A register window */
54struct reg_window {
55 unsigned long locals[8];
56 unsigned long ins[8];
57};
58
59/* A Sparc stack frame */
60struct sparc_stackf {
61 unsigned long locals[8];
62 unsigned long ins[6];
63 struct sparc_stackf *fp;
64 unsigned long callers_pc;
65 char *structptr;
66 unsigned long xargs[6];
67 unsigned long xxargs[1];
68};
69
70#define TRACEREG_SZ sizeof(struct pt_regs)
71#define STACKFRAME_SZ sizeof(struct sparc_stackf)
72
73#ifdef __KERNEL__
74
75#define user_mode(regs) (!((regs)->psr & PSR_PS))
76#define instruction_pointer(regs) ((regs)->pc)
77unsigned long profile_pc(struct pt_regs *);
78extern void show_regs(struct pt_regs *);
79#endif
80
81#else /* __ASSEMBLY__ */
82/* For assembly code. */
83#define TRACEREG_SZ 0x50
84#define STACKFRAME_SZ 0x60
85#endif
86
87/*
88 * The asm-offsets.h is a generated file, so we cannot include it.
89 * It may be OK for glibc headers, but it's utterly pointless for C code.
90 * The assembly code using those offsets has to include it explicitly.
91 */
92/* #include <asm/asm-offsets.h> */
93
94/* These are for pt_regs. */
95#define PT_PSR 0x0
96#define PT_PC 0x4
97#define PT_NPC 0x8
98#define PT_Y 0xc
99#define PT_G0 0x10
100#define PT_WIM PT_G0
101#define PT_G1 0x14
102#define PT_G2 0x18
103#define PT_G3 0x1c
104#define PT_G4 0x20
105#define PT_G5 0x24
106#define PT_G6 0x28
107#define PT_G7 0x2c
108#define PT_I0 0x30
109#define PT_I1 0x34
110#define PT_I2 0x38
111#define PT_I3 0x3c
112#define PT_I4 0x40
113#define PT_I5 0x44
114#define PT_I6 0x48
115#define PT_FP PT_I6
116#define PT_I7 0x4c
117
118/* Reg_window offsets */
119#define RW_L0 0x00
120#define RW_L1 0x04
121#define RW_L2 0x08
122#define RW_L3 0x0c
123#define RW_L4 0x10
124#define RW_L5 0x14
125#define RW_L6 0x18
126#define RW_L7 0x1c
127#define RW_I0 0x20
128#define RW_I1 0x24
129#define RW_I2 0x28
130#define RW_I3 0x2c
131#define RW_I4 0x30
132#define RW_I5 0x34
133#define RW_I6 0x38
134#define RW_I7 0x3c
135
136/* Stack_frame offsets */
137#define SF_L0 0x00
138#define SF_L1 0x04
139#define SF_L2 0x08
140#define SF_L3 0x0c
141#define SF_L4 0x10
142#define SF_L5 0x14
143#define SF_L6 0x18
144#define SF_L7 0x1c
145#define SF_I0 0x20
146#define SF_I1 0x24
147#define SF_I2 0x28
148#define SF_I3 0x2c
149#define SF_I4 0x30
150#define SF_I5 0x34
151#define SF_FP 0x38
152#define SF_PC 0x3c
153#define SF_RETP 0x40
154#define SF_XARG0 0x44
155#define SF_XARG1 0x48
156#define SF_XARG2 0x4c
157#define SF_XARG3 0x50
158#define SF_XARG4 0x54
159#define SF_XARG5 0x58
160#define SF_XXARG 0x5c
161
162/* Stuff for the ptrace system call */
163#define PTRACE_SPARC_DETACH 11
164#define PTRACE_GETREGS 12
165#define PTRACE_SETREGS 13
166#define PTRACE_GETFPREGS 14
167#define PTRACE_SETFPREGS 15
168#define PTRACE_READDATA 16
169#define PTRACE_WRITEDATA 17
170#define PTRACE_READTEXT 18
171#define PTRACE_WRITETEXT 19
172#define PTRACE_GETFPAREGS 20
173#define PTRACE_SETFPAREGS 21
174
175#endif /* !(_SPARC_PTRACE_H) */
diff --git a/include/asm-sparc/ptrace_64.h b/include/asm-sparc/ptrace_64.h
new file mode 100644
index 000000000000..a682e66d5c4a
--- /dev/null
+++ b/include/asm-sparc/ptrace_64.h
@@ -0,0 +1,346 @@
1#ifndef _SPARC64_PTRACE_H
2#define _SPARC64_PTRACE_H
3
4#include <asm/pstate.h>
5
6/* This struct defines the way the registers are stored on the
7 * stack during a system call and basically all traps.
8 */
9
10/* This magic value must have the low 9 bits clear,
11 * as that is where we encode the %tt value, see below.
12 */
13#define PT_REGS_MAGIC 0x57ac6c00
14
15#ifndef __ASSEMBLY__
16
17#include <linux/types.h>
18
19struct pt_regs {
20 unsigned long u_regs[16]; /* globals and ins */
21 unsigned long tstate;
22 unsigned long tpc;
23 unsigned long tnpc;
24 unsigned int y;
25
26 /* We encode a magic number, PT_REGS_MAGIC, along
27 * with the %tt (trap type) register value at trap
28 * entry time. The magic number allows us to identify
29 * accurately a trap stack frame in the stack
30 * unwinder, and the %tt value allows us to test
31 * things like "in a system call" etc. for an arbitray
32 * process.
33 *
34 * The PT_REGS_MAGIC is choosen such that it can be
35 * loaded completely using just a sethi instruction.
36 */
37 unsigned int magic;
38};
39
40static inline int pt_regs_trap_type(struct pt_regs *regs)
41{
42 return regs->magic & 0x1ff;
43}
44
45static inline bool pt_regs_is_syscall(struct pt_regs *regs)
46{
47 return (regs->tstate & TSTATE_SYSCALL);
48}
49
50static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
51{
52 return (regs->tstate &= ~TSTATE_SYSCALL);
53}
54
55struct pt_regs32 {
56 unsigned int psr;
57 unsigned int pc;
58 unsigned int npc;
59 unsigned int y;
60 unsigned int u_regs[16]; /* globals and ins */
61};
62
63#define UREG_G0 0
64#define UREG_G1 1
65#define UREG_G2 2
66#define UREG_G3 3
67#define UREG_G4 4
68#define UREG_G5 5
69#define UREG_G6 6
70#define UREG_G7 7
71#define UREG_I0 8
72#define UREG_I1 9
73#define UREG_I2 10
74#define UREG_I3 11
75#define UREG_I4 12
76#define UREG_I5 13
77#define UREG_I6 14
78#define UREG_I7 15
79#define UREG_FP UREG_I6
80#define UREG_RETPC UREG_I7
81
82/* A V9 register window */
83struct reg_window {
84 unsigned long locals[8];
85 unsigned long ins[8];
86};
87
88/* A 32-bit register window. */
89struct reg_window32 {
90 unsigned int locals[8];
91 unsigned int ins[8];
92};
93
94/* A V9 Sparc stack frame */
95struct sparc_stackf {
96 unsigned long locals[8];
97 unsigned long ins[6];
98 struct sparc_stackf *fp;
99 unsigned long callers_pc;
100 char *structptr;
101 unsigned long xargs[6];
102 unsigned long xxargs[1];
103};
104
105/* A 32-bit Sparc stack frame */
106struct sparc_stackf32 {
107 unsigned int locals[8];
108 unsigned int ins[6];
109 unsigned int fp;
110 unsigned int callers_pc;
111 unsigned int structptr;
112 unsigned int xargs[6];
113 unsigned int xxargs[1];
114};
115
116struct sparc_trapf {
117 unsigned long locals[8];
118 unsigned long ins[8];
119 unsigned long _unused;
120 struct pt_regs *regs;
121};
122
123#define TRACEREG_SZ sizeof(struct pt_regs)
124#define STACKFRAME_SZ sizeof(struct sparc_stackf)
125
126#define TRACEREG32_SZ sizeof(struct pt_regs32)
127#define STACKFRAME32_SZ sizeof(struct sparc_stackf32)
128
129#ifdef __KERNEL__
130
131struct global_reg_snapshot {
132 unsigned long tstate;
133 unsigned long tpc;
134 unsigned long tnpc;
135 unsigned long o7;
136 unsigned long i7;
137 struct thread_info *thread;
138 unsigned long pad1;
139 unsigned long pad2;
140};
141
142#define __ARCH_WANT_COMPAT_SYS_PTRACE
143
144#define force_successful_syscall_return() \
145do { current_thread_info()->syscall_noerror = 1; \
146} while (0)
147#define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV))
148#define instruction_pointer(regs) ((regs)->tpc)
149#define regs_return_value(regs) ((regs)->u_regs[UREG_I0])
150#ifdef CONFIG_SMP
151extern unsigned long profile_pc(struct pt_regs *);
152#else
153#define profile_pc(regs) instruction_pointer(regs)
154#endif
155extern void show_regs(struct pt_regs *);
156extern void __show_regs(struct pt_regs *);
157#endif
158
159#else /* __ASSEMBLY__ */
160/* For assembly code. */
161#define TRACEREG_SZ 0xa0
162#define STACKFRAME_SZ 0xc0
163
164#define TRACEREG32_SZ 0x50
165#define STACKFRAME32_SZ 0x60
166#endif
167
168#ifdef __KERNEL__
169#define STACK_BIAS 2047
170#endif
171
172/* These are for pt_regs. */
173#define PT_V9_G0 0x00
174#define PT_V9_G1 0x08
175#define PT_V9_G2 0x10
176#define PT_V9_G3 0x18
177#define PT_V9_G4 0x20
178#define PT_V9_G5 0x28
179#define PT_V9_G6 0x30
180#define PT_V9_G7 0x38
181#define PT_V9_I0 0x40
182#define PT_V9_I1 0x48
183#define PT_V9_I2 0x50
184#define PT_V9_I3 0x58
185#define PT_V9_I4 0x60
186#define PT_V9_I5 0x68
187#define PT_V9_I6 0x70
188#define PT_V9_FP PT_V9_I6
189#define PT_V9_I7 0x78
190#define PT_V9_TSTATE 0x80
191#define PT_V9_TPC 0x88
192#define PT_V9_TNPC 0x90
193#define PT_V9_Y 0x98
194#define PT_V9_MAGIC 0x9c
195#define PT_TSTATE PT_V9_TSTATE
196#define PT_TPC PT_V9_TPC
197#define PT_TNPC PT_V9_TNPC
198
199/* These for pt_regs32. */
200#define PT_PSR 0x0
201#define PT_PC 0x4
202#define PT_NPC 0x8
203#define PT_Y 0xc
204#define PT_G0 0x10
205#define PT_WIM PT_G0
206#define PT_G1 0x14
207#define PT_G2 0x18
208#define PT_G3 0x1c
209#define PT_G4 0x20
210#define PT_G5 0x24
211#define PT_G6 0x28
212#define PT_G7 0x2c
213#define PT_I0 0x30
214#define PT_I1 0x34
215#define PT_I2 0x38
216#define PT_I3 0x3c
217#define PT_I4 0x40
218#define PT_I5 0x44
219#define PT_I6 0x48
220#define PT_FP PT_I6
221#define PT_I7 0x4c
222
223/* Reg_window offsets */
224#define RW_V9_L0 0x00
225#define RW_V9_L1 0x08
226#define RW_V9_L2 0x10
227#define RW_V9_L3 0x18
228#define RW_V9_L4 0x20
229#define RW_V9_L5 0x28
230#define RW_V9_L6 0x30
231#define RW_V9_L7 0x38
232#define RW_V9_I0 0x40
233#define RW_V9_I1 0x48
234#define RW_V9_I2 0x50
235#define RW_V9_I3 0x58
236#define RW_V9_I4 0x60
237#define RW_V9_I5 0x68
238#define RW_V9_I6 0x70
239#define RW_V9_I7 0x78
240
241#define RW_L0 0x00
242#define RW_L1 0x04
243#define RW_L2 0x08
244#define RW_L3 0x0c
245#define RW_L4 0x10
246#define RW_L5 0x14
247#define RW_L6 0x18
248#define RW_L7 0x1c
249#define RW_I0 0x20
250#define RW_I1 0x24
251#define RW_I2 0x28
252#define RW_I3 0x2c
253#define RW_I4 0x30
254#define RW_I5 0x34
255#define RW_I6 0x38
256#define RW_I7 0x3c
257
258/* Stack_frame offsets */
259#define SF_V9_L0 0x00
260#define SF_V9_L1 0x08
261#define SF_V9_L2 0x10
262#define SF_V9_L3 0x18
263#define SF_V9_L4 0x20
264#define SF_V9_L5 0x28
265#define SF_V9_L6 0x30
266#define SF_V9_L7 0x38
267#define SF_V9_I0 0x40
268#define SF_V9_I1 0x48
269#define SF_V9_I2 0x50
270#define SF_V9_I3 0x58
271#define SF_V9_I4 0x60
272#define SF_V9_I5 0x68
273#define SF_V9_FP 0x70
274#define SF_V9_PC 0x78
275#define SF_V9_RETP 0x80
276#define SF_V9_XARG0 0x88
277#define SF_V9_XARG1 0x90
278#define SF_V9_XARG2 0x98
279#define SF_V9_XARG3 0xa0
280#define SF_V9_XARG4 0xa8
281#define SF_V9_XARG5 0xb0
282#define SF_V9_XXARG 0xb8
283
284#define SF_L0 0x00
285#define SF_L1 0x04
286#define SF_L2 0x08
287#define SF_L3 0x0c
288#define SF_L4 0x10
289#define SF_L5 0x14
290#define SF_L6 0x18
291#define SF_L7 0x1c
292#define SF_I0 0x20
293#define SF_I1 0x24
294#define SF_I2 0x28
295#define SF_I3 0x2c
296#define SF_I4 0x30
297#define SF_I5 0x34
298#define SF_FP 0x38
299#define SF_PC 0x3c
300#define SF_RETP 0x40
301#define SF_XARG0 0x44
302#define SF_XARG1 0x48
303#define SF_XARG2 0x4c
304#define SF_XARG3 0x50
305#define SF_XARG4 0x54
306#define SF_XARG5 0x58
307#define SF_XXARG 0x5c
308
309#ifdef __KERNEL__
310
311/* global_reg_snapshot offsets */
312#define GR_SNAP_TSTATE 0x00
313#define GR_SNAP_TPC 0x08
314#define GR_SNAP_TNPC 0x10
315#define GR_SNAP_O7 0x18
316#define GR_SNAP_I7 0x20
317#define GR_SNAP_THREAD 0x28
318#define GR_SNAP_PAD1 0x30
319#define GR_SNAP_PAD2 0x38
320
321#endif /* __KERNEL__ */
322
323/* Stuff for the ptrace system call */
324#define PTRACE_SPARC_DETACH 11
325#define PTRACE_GETREGS 12
326#define PTRACE_SETREGS 13
327#define PTRACE_GETFPREGS 14
328#define PTRACE_SETFPREGS 15
329#define PTRACE_READDATA 16
330#define PTRACE_WRITEDATA 17
331#define PTRACE_READTEXT 18
332#define PTRACE_WRITETEXT 19
333#define PTRACE_GETFPAREGS 20
334#define PTRACE_SETFPAREGS 21
335
336/* There are for debugging 64-bit processes, either from a 32 or 64 bit
337 * parent. Thus their complements are for debugging 32-bit processes only.
338 */
339
340#define PTRACE_GETREGS64 22
341#define PTRACE_SETREGS64 23
342/* PTRACE_SYSCALL is 24 */
343#define PTRACE_GETFPREGS64 25
344#define PTRACE_SETFPREGS64 26
345
346#endif /* !(_SPARC64_PTRACE_H) */
diff --git a/include/asm-sparc/reboot.h b/include/asm-sparc/reboot.h
new file mode 100644
index 000000000000..3f3f43f5be5e
--- /dev/null
+++ b/include/asm-sparc/reboot.h
@@ -0,0 +1,6 @@
1#ifndef _SPARC64_REBOOT_H
2#define _SPARC64_REBOOT_H
3
4extern void machine_alt_power_off(void);
5
6#endif /* _SPARC64_REBOOT_H */
diff --git a/include/asm-sparc/reg.h b/include/asm-sparc/reg.h
index ea0a7e590bb3..cb34b0a49aad 100644
--- a/include/asm-sparc/reg.h
+++ b/include/asm-sparc/reg.h
@@ -1,79 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_REG_H
2 * linux/include/asm-sparc/reg.h 2#define ___ASM_SPARC_REG_H
3 * Layout of the registers as expected by gdb on the Sparc 3#if defined(__sparc__) && defined(__arch64__)
4 * we should replace the user.h definitions with those in 4#include <asm-sparc/reg_64.h>
5 * this file, we don't even use the other 5#else
6 * -miguel 6#include <asm-sparc/reg_32.h>
7 * 7#endif
8 * The names of the structures, constants and aliases in this file 8#endif
9 * have the same names as the sunos ones, some programs rely on these
10 * names (gdb for example).
11 *
12 */
13
14#ifndef __SPARC_REG_H
15#define __SPARC_REG_H
16
17struct regs {
18 int r_psr;
19#define r_ps r_psr
20 int r_pc;
21 int r_npc;
22 int r_y;
23 int r_g1;
24 int r_g2;
25 int r_g3;
26 int r_g4;
27 int r_g5;
28 int r_g6;
29 int r_g7;
30 int r_o0;
31 int r_o1;
32 int r_o2;
33 int r_o3;
34 int r_o4;
35 int r_o5;
36 int r_o6;
37 int r_o7;
38};
39
40struct fpq {
41 unsigned long *addr;
42 unsigned long instr;
43};
44
45struct fq {
46 union {
47 double whole;
48 struct fpq fpq;
49 } FQu;
50};
51
52#define FPU_REGS_TYPE unsigned int
53#define FPU_FSR_TYPE unsigned
54
55struct fp_status {
56 union {
57 FPU_REGS_TYPE Fpu_regs[32];
58 double Fpu_dregs[16];
59 } fpu_fr;
60 FPU_FSR_TYPE Fpu_fsr;
61 unsigned Fpu_flags;
62 unsigned Fpu_extra;
63 unsigned Fpu_qcnt;
64 struct fq Fpu_q[16];
65};
66
67#define fpu_regs f_fpstatus.fpu_fr.Fpu_regs
68#define fpu_dregs f_fpstatus.fpu_fr.Fpu_dregs
69#define fpu_fsr f_fpstatus.Fpu_fsr
70#define fpu_flags f_fpstatus.Fpu_flags
71#define fpu_extra f_fpstatus.Fpu_extra
72#define fpu_q f_fpstatus.Fpu_q
73#define fpu_qcnt f_fpstatus.Fpu_qcnt
74
75struct fpu {
76 struct fp_status f_fpstatus;
77};
78
79#endif /* __SPARC_REG_H */
diff --git a/include/asm-sparc/reg_32.h b/include/asm-sparc/reg_32.h
new file mode 100644
index 000000000000..42fecfcd97e7
--- /dev/null
+++ b/include/asm-sparc/reg_32.h
@@ -0,0 +1,79 @@
1/*
2 * linux/include/asm-sparc/reg.h
3 * Layout of the registers as expected by gdb on the Sparc
4 * we should replace the user.h definitions with those in
5 * this file, we don't even use the other
6 * -miguel
7 *
8 * The names of the structures, constants and aliases in this file
9 * have the same names as the sunos ones, some programs rely on these
10 * names (gdb for example).
11 *
12 */
13
14#ifndef __SPARC_REG_H
15#define __SPARC_REG_H
16
17struct regs {
18 int r_psr;
19#define r_ps r_psr
20 int r_pc;
21 int r_npc;
22 int r_y;
23 int r_g1;
24 int r_g2;
25 int r_g3;
26 int r_g4;
27 int r_g5;
28 int r_g6;
29 int r_g7;
30 int r_o0;
31 int r_o1;
32 int r_o2;
33 int r_o3;
34 int r_o4;
35 int r_o5;
36 int r_o6;
37 int r_o7;
38};
39
40struct fpq {
41 unsigned long *addr;
42 unsigned long instr;
43};
44
45struct fq {
46 union {
47 double whole;
48 struct fpq fpq;
49 } FQu;
50};
51
52#define FPU_REGS_TYPE unsigned int
53#define FPU_FSR_TYPE unsigned
54
55struct fp_status {
56 union {
57 FPU_REGS_TYPE Fpu_regs[32];
58 double Fpu_dregs[16];
59 } fpu_fr;
60 FPU_FSR_TYPE Fpu_fsr;
61 unsigned Fpu_flags;
62 unsigned Fpu_extra;
63 unsigned Fpu_qcnt;
64 struct fq Fpu_q[16];
65};
66
67#define fpu_regs f_fpstatus.fpu_fr.Fpu_regs
68#define fpu_dregs f_fpstatus.fpu_fr.Fpu_dregs
69#define fpu_fsr f_fpstatus.Fpu_fsr
70#define fpu_flags f_fpstatus.Fpu_flags
71#define fpu_extra f_fpstatus.Fpu_extra
72#define fpu_q f_fpstatus.Fpu_q
73#define fpu_qcnt f_fpstatus.Fpu_qcnt
74
75struct fpu {
76 struct fp_status f_fpstatus;
77};
78
79#endif /* __SPARC_REG_H */
diff --git a/include/asm-sparc/reg_64.h b/include/asm-sparc/reg_64.h
new file mode 100644
index 000000000000..eb24a07ff4d5
--- /dev/null
+++ b/include/asm-sparc/reg_64.h
@@ -0,0 +1,56 @@
1/*
2 * linux/asm-sparc64/reg.h
3 * Layout of the registers as expected by gdb on the Sparc
4 * we should replace the user.h definitions with those in
5 * this file, we don't even use the other
6 * -miguel
7 *
8 * The names of the structures, constants and aliases in this file
9 * have the same names as the sunos ones, some programs rely on these
10 * names (gdb for example).
11 *
12 */
13
14#ifndef __SPARC64_REG_H
15#define __SPARC64_REG_H
16
17struct regs {
18 unsigned long r_g1;
19 unsigned long r_g2;
20 unsigned long r_g3;
21 unsigned long r_g4;
22 unsigned long r_g5;
23 unsigned long r_g6;
24 unsigned long r_g7;
25 unsigned long r_o0;
26 unsigned long r_o1;
27 unsigned long r_o2;
28 unsigned long r_o3;
29 unsigned long r_o4;
30 unsigned long r_o5;
31 unsigned long r_o6;
32 unsigned long r_o7;
33 unsigned long __pad;
34 unsigned long r_tstate;
35 unsigned long r_tpc;
36 unsigned long r_tnpc;
37 unsigned int r_y;
38 unsigned int r_fprs;
39};
40
41#define FPU_REGS_TYPE unsigned int
42#define FPU_FSR_TYPE unsigned long
43
44struct fp_status {
45 unsigned long fpu_fr[32];
46 unsigned long Fpu_fsr;
47};
48
49struct fpu {
50 struct fp_status f_fpstatus;
51};
52
53#define fpu_regs f_fpstatus.fpu_fr
54#define fpu_fsr f_fpstatus.Fpu_fsr
55
56#endif /* __SPARC64_REG_H */
diff --git a/include/asm-sparc/resource.h b/include/asm-sparc/resource.h
index 985948a41299..fe163cafb4c7 100644
--- a/include/asm-sparc/resource.h
+++ b/include/asm-sparc/resource.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * resource.h: Resource definitions. 2 * resource.h: Resource definitions.
3 * 3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 4 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
5 */ 5 */
6 6
7#ifndef _SPARC_RESOURCE_H 7#ifndef _SPARC_RESOURCE_H
@@ -14,12 +14,16 @@
14#define RLIMIT_NOFILE 6 /* max number of open files */ 14#define RLIMIT_NOFILE 6 /* max number of open files */
15#define RLIMIT_NPROC 7 /* max number of processes */ 15#define RLIMIT_NPROC 7 /* max number of processes */
16 16
17#if defined(__sparc__) && defined(__arch64__)
18/* Use generic version */
19#else
17/* 20/*
18 * SuS says limits have to be unsigned. 21 * SuS says limits have to be unsigned.
19 * We make this unsigned, but keep the 22 * We make this unsigned, but keep the
20 * old value for compatibility: 23 * old value for compatibility:
21 */ 24 */
22#define RLIM_INFINITY 0x7fffffff 25#define RLIM_INFINITY 0x7fffffff
26#endif
23 27
24#include <asm-generic/resource.h> 28#include <asm-generic/resource.h>
25 29
diff --git a/include/asm-sparc/rwsem-const.h b/include/asm-sparc/rwsem-const.h
new file mode 100644
index 000000000000..a303c9d64d84
--- /dev/null
+++ b/include/asm-sparc/rwsem-const.h
@@ -0,0 +1,12 @@
1/* rwsem-const.h: RW semaphore counter constants. */
2#ifndef _SPARC64_RWSEM_CONST_H
3#define _SPARC64_RWSEM_CONST_H
4
5#define RWSEM_UNLOCKED_VALUE 0x00000000
6#define RWSEM_ACTIVE_BIAS 0x00000001
7#define RWSEM_ACTIVE_MASK 0x0000ffff
8#define RWSEM_WAITING_BIAS 0xffff0000
9#define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS
10#define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
11
12#endif /* _SPARC64_RWSEM_CONST_H */
diff --git a/include/asm-sparc/rwsem.h b/include/asm-sparc/rwsem.h
new file mode 100644
index 000000000000..1dc129ac2feb
--- /dev/null
+++ b/include/asm-sparc/rwsem.h
@@ -0,0 +1,84 @@
1/*
2 * rwsem.h: R/W semaphores implemented using CAS
3 *
4 * Written by David S. Miller (davem@redhat.com), 2001.
5 * Derived from asm-i386/rwsem.h
6 */
7#ifndef _SPARC64_RWSEM_H
8#define _SPARC64_RWSEM_H
9
10#ifndef _LINUX_RWSEM_H
11#error "please don't include asm/rwsem.h directly, use linux/rwsem.h instead"
12#endif
13
14#ifdef __KERNEL__
15
16#include <linux/list.h>
17#include <linux/spinlock.h>
18#include <asm/rwsem-const.h>
19
20struct rwsem_waiter;
21
22struct rw_semaphore {
23 signed int count;
24 spinlock_t wait_lock;
25 struct list_head wait_list;
26#ifdef CONFIG_DEBUG_LOCK_ALLOC
27 struct lockdep_map dep_map;
28#endif
29};
30
31#ifdef CONFIG_DEBUG_LOCK_ALLOC
32# define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
33#else
34# define __RWSEM_DEP_MAP_INIT(lockname)
35#endif
36
37#define __RWSEM_INITIALIZER(name) \
38{ RWSEM_UNLOCKED_VALUE, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) \
39 __RWSEM_DEP_MAP_INIT(name) }
40
41#define DECLARE_RWSEM(name) \
42 struct rw_semaphore name = __RWSEM_INITIALIZER(name)
43
44extern void __init_rwsem(struct rw_semaphore *sem, const char *name,
45 struct lock_class_key *key);
46
47#define init_rwsem(sem) \
48do { \
49 static struct lock_class_key __key; \
50 \
51 __init_rwsem((sem), #sem, &__key); \
52} while (0)
53
54extern void __down_read(struct rw_semaphore *sem);
55extern int __down_read_trylock(struct rw_semaphore *sem);
56extern void __down_write(struct rw_semaphore *sem);
57extern int __down_write_trylock(struct rw_semaphore *sem);
58extern void __up_read(struct rw_semaphore *sem);
59extern void __up_write(struct rw_semaphore *sem);
60extern void __downgrade_write(struct rw_semaphore *sem);
61
62static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
63{
64 __down_write(sem);
65}
66
67static inline int rwsem_atomic_update(int delta, struct rw_semaphore *sem)
68{
69 return atomic_add_return(delta, (atomic_t *)(&sem->count));
70}
71
72static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
73{
74 atomic_add(delta, (atomic_t *)(&sem->count));
75}
76
77static inline int rwsem_is_locked(struct rw_semaphore *sem)
78{
79 return (sem->count != 0);
80}
81
82#endif /* __KERNEL__ */
83
84#endif /* _SPARC64_RWSEM_H */
diff --git a/include/asm-sparc/sbus.h b/include/asm-sparc/sbus.h
index f1d2fe1c9a30..8f29a1979665 100644
--- a/include/asm-sparc/sbus.h
+++ b/include/asm-sparc/sbus.h
@@ -1,153 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_SBUS_H
2 * sbus.h: Defines for the Sun SBus. 2#define ___ASM_SPARC_SBUS_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 4#include <asm-sparc/sbus_64.h>
5 */ 5#else
6 6#include <asm-sparc/sbus_32.h>
7#ifndef _SPARC_SBUS_H 7#endif
8#define _SPARC_SBUS_H 8#endif
9
10#include <linux/dma-mapping.h>
11#include <linux/ioport.h>
12
13#include <asm/oplib.h>
14#include <asm/prom.h>
15#include <asm/of_device.h>
16#include <asm/scatterlist.h>
17
18/* We scan which devices are on the SBus using the PROM node device
19 * tree. SBus devices are described in two different ways. You can
20 * either get an absolute address at which to access the device, or
21 * you can get a SBus 'slot' number and an offset within that slot.
22 */
23
24/* The base address at which to calculate device OBIO addresses. */
25#define SUN_SBUS_BVADDR 0xf8000000
26#define SBUS_OFF_MASK 0x01ffffff
27
28/* These routines are used to calculate device address from slot
29 * numbers + offsets, and vice versa.
30 */
31
32static inline unsigned long sbus_devaddr(int slotnum, unsigned long offset)
33{
34 return (unsigned long) (SUN_SBUS_BVADDR+((slotnum)<<25)+(offset));
35}
36
37static inline int sbus_dev_slot(unsigned long dev_addr)
38{
39 return (int) (((dev_addr)-SUN_SBUS_BVADDR)>>25);
40}
41
42struct sbus_bus;
43
44/* Linux SBUS device tables */
45struct sbus_dev {
46 struct of_device ofdev;
47 struct sbus_bus *bus;
48 struct sbus_dev *next;
49 struct sbus_dev *child;
50 struct sbus_dev *parent;
51 int prom_node;
52 char prom_name[64];
53 int slot;
54
55 struct resource resource[PROMREG_MAX];
56
57 struct linux_prom_registers reg_addrs[PROMREG_MAX];
58 int num_registers;
59
60 struct linux_prom_ranges device_ranges[PROMREG_MAX];
61 int num_device_ranges;
62
63 unsigned int irqs[4];
64 int num_irqs;
65};
66#define to_sbus_device(d) container_of(d, struct sbus_dev, ofdev.dev)
67
68/* This struct describes the SBus(s) found on this machine. */
69struct sbus_bus {
70 struct of_device ofdev;
71 struct sbus_dev *devices; /* Link to devices on this SBus */
72 struct sbus_bus *next; /* next SBus, if more than one SBus */
73 int prom_node; /* PROM device tree node for this SBus */
74 char prom_name[64]; /* Usually "sbus" or "sbi" */
75 int clock_freq;
76
77 struct linux_prom_ranges sbus_ranges[PROMREG_MAX];
78 int num_sbus_ranges;
79
80 int devid;
81 int board;
82};
83#define to_sbus(d) container_of(d, struct sbus_bus, ofdev.dev)
84
85extern struct sbus_bus *sbus_root;
86
87static inline int
88sbus_is_slave(struct sbus_dev *dev)
89{
90 /* XXX Have to write this for sun4c's */
91 return 0;
92}
93
94/* Device probing routines could find these handy */
95#define for_each_sbus(bus) \
96 for((bus) = sbus_root; (bus); (bus)=(bus)->next)
97
98#define for_each_sbusdev(device, bus) \
99 for((device) = (bus)->devices; (device); (device)=(device)->next)
100
101#define for_all_sbusdev(device, bus) \
102 for ((bus) = sbus_root; (bus); (bus) = (bus)->next) \
103 for ((device) = (bus)->devices; (device); (device) = (device)->next)
104
105/* Driver DVMA interfaces. */
106#define sbus_can_dma_64bit(sdev) (0) /* actually, sparc_cpu_model==sun4d */
107#define sbus_can_burst64(sdev) (0) /* actually, sparc_cpu_model==sun4d */
108extern void sbus_set_sbus64(struct sbus_dev *, int);
109extern void sbus_fill_device_irq(struct sbus_dev *);
110
111/* These yield IOMMU mappings in consistent mode. */
112extern void *sbus_alloc_consistent(struct sbus_dev *, long, u32 *dma_addrp);
113extern void sbus_free_consistent(struct sbus_dev *, long, void *, u32);
114void prom_adjust_ranges(struct linux_prom_ranges *, int,
115 struct linux_prom_ranges *, int);
116
117#define SBUS_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL
118#define SBUS_DMA_TODEVICE DMA_TO_DEVICE
119#define SBUS_DMA_FROMDEVICE DMA_FROM_DEVICE
120#define SBUS_DMA_NONE DMA_NONE
121
122/* All the rest use streaming mode mappings. */
123extern dma_addr_t sbus_map_single(struct sbus_dev *, void *, size_t, int);
124extern void sbus_unmap_single(struct sbus_dev *, dma_addr_t, size_t, int);
125extern int sbus_map_sg(struct sbus_dev *, struct scatterlist *, int, int);
126extern void sbus_unmap_sg(struct sbus_dev *, struct scatterlist *, int, int);
127
128/* Finally, allow explicit synchronization of streamable mappings. */
129extern void sbus_dma_sync_single_for_cpu(struct sbus_dev *, dma_addr_t, size_t, int);
130#define sbus_dma_sync_single sbus_dma_sync_single_for_cpu
131extern void sbus_dma_sync_single_for_device(struct sbus_dev *, dma_addr_t, size_t, int);
132extern void sbus_dma_sync_sg_for_cpu(struct sbus_dev *, struct scatterlist *, int, int);
133#define sbus_dma_sync_sg sbus_dma_sync_sg_for_cpu
134extern void sbus_dma_sync_sg_for_device(struct sbus_dev *, struct scatterlist *, int, int);
135
136/* Eric Brower (ebrower@usa.net)
137 * Translate SBus interrupt levels to ino values--
138 * this is used when converting sbus "interrupts" OBP
139 * node values to "intr" node values, and is platform
140 * dependent. If only we could call OBP with
141 * "sbus-intr>cpu (sbint -- ino)" from kernel...
142 * See .../drivers/sbus/sbus.c for details.
143 */
144BTFIXUPDEF_CALL(unsigned int, sbint_to_irq, struct sbus_dev *sdev, unsigned int)
145#define sbint_to_irq(sdev, sbint) BTFIXUP_CALL(sbint_to_irq)(sdev, sbint)
146
147extern void sbus_arch_bus_ranges_init(struct device_node *, struct sbus_bus *);
148extern void sbus_setup_iommu(struct sbus_bus *, struct device_node *);
149extern void sbus_setup_arch_props(struct sbus_bus *, struct device_node *);
150extern int sbus_arch_preinit(void);
151extern void sbus_arch_postinit(void);
152
153#endif /* !(_SPARC_SBUS_H) */
diff --git a/include/asm-sparc/sbus_32.h b/include/asm-sparc/sbus_32.h
new file mode 100644
index 000000000000..77b5d3aadc99
--- /dev/null
+++ b/include/asm-sparc/sbus_32.h
@@ -0,0 +1,153 @@
1/*
2 * sbus.h: Defines for the Sun SBus.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef _SPARC_SBUS_H
8#define _SPARC_SBUS_H
9
10#include <linux/dma-mapping.h>
11#include <linux/ioport.h>
12
13#include <asm/oplib.h>
14#include <asm/prom.h>
15#include <asm/of_device.h>
16#include <asm/scatterlist.h>
17
18/* We scan which devices are on the SBus using the PROM node device
19 * tree. SBus devices are described in two different ways. You can
20 * either get an absolute address at which to access the device, or
21 * you can get a SBus 'slot' number and an offset within that slot.
22 */
23
24/* The base address at which to calculate device OBIO addresses. */
25#define SUN_SBUS_BVADDR 0xf8000000
26#define SBUS_OFF_MASK 0x01ffffff
27
28/* These routines are used to calculate device address from slot
29 * numbers + offsets, and vice versa.
30 */
31
32static inline unsigned long sbus_devaddr(int slotnum, unsigned long offset)
33{
34 return (unsigned long) (SUN_SBUS_BVADDR+((slotnum)<<25)+(offset));
35}
36
37static inline int sbus_dev_slot(unsigned long dev_addr)
38{
39 return (int) (((dev_addr)-SUN_SBUS_BVADDR)>>25);
40}
41
42struct sbus_bus;
43
44/* Linux SBUS device tables */
45struct sbus_dev {
46 struct of_device ofdev;
47 struct sbus_bus *bus;
48 struct sbus_dev *next;
49 struct sbus_dev *child;
50 struct sbus_dev *parent;
51 int prom_node;
52 char prom_name[64];
53 int slot;
54
55 struct resource resource[PROMREG_MAX];
56
57 struct linux_prom_registers reg_addrs[PROMREG_MAX];
58 int num_registers;
59
60 struct linux_prom_ranges device_ranges[PROMREG_MAX];
61 int num_device_ranges;
62
63 unsigned int irqs[4];
64 int num_irqs;
65};
66#define to_sbus_device(d) container_of(d, struct sbus_dev, ofdev.dev)
67
68/* This struct describes the SBus(s) found on this machine. */
69struct sbus_bus {
70 struct of_device ofdev;
71 struct sbus_dev *devices; /* Link to devices on this SBus */
72 struct sbus_bus *next; /* next SBus, if more than one SBus */
73 int prom_node; /* PROM device tree node for this SBus */
74 char prom_name[64]; /* Usually "sbus" or "sbi" */
75 int clock_freq;
76
77 struct linux_prom_ranges sbus_ranges[PROMREG_MAX];
78 int num_sbus_ranges;
79
80 int devid;
81 int board;
82};
83#define to_sbus(d) container_of(d, struct sbus_bus, ofdev.dev)
84
85extern struct sbus_bus *sbus_root;
86
87static inline int
88sbus_is_slave(struct sbus_dev *dev)
89{
90 /* XXX Have to write this for sun4c's */
91 return 0;
92}
93
94/* Device probing routines could find these handy */
95#define for_each_sbus(bus) \
96 for((bus) = sbus_root; (bus); (bus)=(bus)->next)
97
98#define for_each_sbusdev(device, bus) \
99 for((device) = (bus)->devices; (device); (device)=(device)->next)
100
101#define for_all_sbusdev(device, bus) \
102 for ((bus) = sbus_root; (bus); (bus) = (bus)->next) \
103 for ((device) = (bus)->devices; (device); (device) = (device)->next)
104
105/* Driver DVMA interfaces. */
106#define sbus_can_dma_64bit(sdev) (0) /* actually, sparc_cpu_model==sun4d */
107#define sbus_can_burst64(sdev) (0) /* actually, sparc_cpu_model==sun4d */
108extern void sbus_set_sbus64(struct sbus_dev *, int);
109extern void sbus_fill_device_irq(struct sbus_dev *);
110
111/* These yield IOMMU mappings in consistent mode. */
112extern void *sbus_alloc_consistent(struct sbus_dev *, long, u32 *dma_addrp);
113extern void sbus_free_consistent(struct sbus_dev *, long, void *, u32);
114void prom_adjust_ranges(struct linux_prom_ranges *, int,
115 struct linux_prom_ranges *, int);
116
117#define SBUS_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL
118#define SBUS_DMA_TODEVICE DMA_TO_DEVICE
119#define SBUS_DMA_FROMDEVICE DMA_FROM_DEVICE
120#define SBUS_DMA_NONE DMA_NONE
121
122/* All the rest use streaming mode mappings. */
123extern dma_addr_t sbus_map_single(struct sbus_dev *, void *, size_t, int);
124extern void sbus_unmap_single(struct sbus_dev *, dma_addr_t, size_t, int);
125extern int sbus_map_sg(struct sbus_dev *, struct scatterlist *, int, int);
126extern void sbus_unmap_sg(struct sbus_dev *, struct scatterlist *, int, int);
127
128/* Finally, allow explicit synchronization of streamable mappings. */
129extern void sbus_dma_sync_single_for_cpu(struct sbus_dev *, dma_addr_t, size_t, int);
130#define sbus_dma_sync_single sbus_dma_sync_single_for_cpu
131extern void sbus_dma_sync_single_for_device(struct sbus_dev *, dma_addr_t, size_t, int);
132extern void sbus_dma_sync_sg_for_cpu(struct sbus_dev *, struct scatterlist *, int, int);
133#define sbus_dma_sync_sg sbus_dma_sync_sg_for_cpu
134extern void sbus_dma_sync_sg_for_device(struct sbus_dev *, struct scatterlist *, int, int);
135
136/* Eric Brower (ebrower@usa.net)
137 * Translate SBus interrupt levels to ino values--
138 * this is used when converting sbus "interrupts" OBP
139 * node values to "intr" node values, and is platform
140 * dependent. If only we could call OBP with
141 * "sbus-intr>cpu (sbint -- ino)" from kernel...
142 * See .../drivers/sbus/sbus.c for details.
143 */
144BTFIXUPDEF_CALL(unsigned int, sbint_to_irq, struct sbus_dev *sdev, unsigned int)
145#define sbint_to_irq(sdev, sbint) BTFIXUP_CALL(sbint_to_irq)(sdev, sbint)
146
147extern void sbus_arch_bus_ranges_init(struct device_node *, struct sbus_bus *);
148extern void sbus_setup_iommu(struct sbus_bus *, struct device_node *);
149extern void sbus_setup_arch_props(struct sbus_bus *, struct device_node *);
150extern int sbus_arch_preinit(void);
151extern void sbus_arch_postinit(void);
152
153#endif /* !(_SPARC_SBUS_H) */
diff --git a/include/asm-sparc/sbus_64.h b/include/asm-sparc/sbus_64.h
new file mode 100644
index 000000000000..0e16b6dd7e96
--- /dev/null
+++ b/include/asm-sparc/sbus_64.h
@@ -0,0 +1,190 @@
1/* sbus.h: Defines for the Sun SBus.
2 *
3 * Copyright (C) 1996, 1999, 2007 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_SBUS_H
7#define _SPARC64_SBUS_H
8
9#include <linux/dma-mapping.h>
10#include <linux/ioport.h>
11
12#include <asm/oplib.h>
13#include <asm/prom.h>
14#include <asm/of_device.h>
15#include <asm/iommu.h>
16#include <asm/scatterlist.h>
17
18/* We scan which devices are on the SBus using the PROM node device
19 * tree. SBus devices are described in two different ways. You can
20 * either get an absolute address at which to access the device, or
21 * you can get a SBus 'slot' number and an offset within that slot.
22 */
23
24/* The base address at which to calculate device OBIO addresses. */
25#define SUN_SBUS_BVADDR 0x00000000
26#define SBUS_OFF_MASK 0x0fffffff
27
28/* These routines are used to calculate device address from slot
29 * numbers + offsets, and vice versa.
30 */
31
32static inline unsigned long sbus_devaddr(int slotnum, unsigned long offset)
33{
34 return (unsigned long) (SUN_SBUS_BVADDR+((slotnum)<<28)+(offset));
35}
36
37static inline int sbus_dev_slot(unsigned long dev_addr)
38{
39 return (int) (((dev_addr)-SUN_SBUS_BVADDR)>>28);
40}
41
42struct sbus_bus;
43
44/* Linux SBUS device tables */
45struct sbus_dev {
46 struct of_device ofdev;
47 struct sbus_bus *bus;
48 struct sbus_dev *next;
49 struct sbus_dev *child;
50 struct sbus_dev *parent;
51 int prom_node;
52 char prom_name[64];
53 int slot;
54
55 struct resource resource[PROMREG_MAX];
56
57 struct linux_prom_registers reg_addrs[PROMREG_MAX];
58 int num_registers;
59
60 struct linux_prom_ranges device_ranges[PROMREG_MAX];
61 int num_device_ranges;
62
63 unsigned int irqs[4];
64 int num_irqs;
65};
66#define to_sbus_device(d) container_of(d, struct sbus_dev, ofdev.dev)
67
68/* This struct describes the SBus(s) found on this machine. */
69struct sbus_bus {
70 struct of_device ofdev;
71 struct sbus_dev *devices; /* Tree of SBUS devices */
72 struct sbus_bus *next; /* Next SBUS in system */
73 int prom_node; /* OBP node of SBUS */
74 char prom_name[64]; /* Usually "sbus" or "sbi" */
75 int clock_freq;
76
77 struct linux_prom_ranges sbus_ranges[PROMREG_MAX];
78 int num_sbus_ranges;
79
80 int portid;
81};
82#define to_sbus(d) container_of(d, struct sbus_bus, ofdev.dev)
83
84extern struct sbus_bus *sbus_root;
85
86/* Device probing routines could find these handy */
87#define for_each_sbus(bus) \
88 for((bus) = sbus_root; (bus); (bus)=(bus)->next)
89
90#define for_each_sbusdev(device, bus) \
91 for((device) = (bus)->devices; (device); (device)=(device)->next)
92
93#define for_all_sbusdev(device, bus) \
94 for ((bus) = sbus_root; (bus); (bus) = (bus)->next) \
95 for ((device) = (bus)->devices; (device); (device) = (device)->next)
96
97/* Driver DVMA interfaces. */
98#define sbus_can_dma_64bit(sdev) (1)
99#define sbus_can_burst64(sdev) (1)
100extern void sbus_set_sbus64(struct sbus_dev *, int);
101extern void sbus_fill_device_irq(struct sbus_dev *);
102
103static inline void *sbus_alloc_consistent(struct sbus_dev *sdev , size_t size,
104 dma_addr_t *dma_handle)
105{
106 return dma_alloc_coherent(&sdev->ofdev.dev, size,
107 dma_handle, GFP_ATOMIC);
108}
109
110static inline void sbus_free_consistent(struct sbus_dev *sdev, size_t size,
111 void *vaddr, dma_addr_t dma_handle)
112{
113 return dma_free_coherent(&sdev->ofdev.dev, size, vaddr, dma_handle);
114}
115
116#define SBUS_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL
117#define SBUS_DMA_TODEVICE DMA_TO_DEVICE
118#define SBUS_DMA_FROMDEVICE DMA_FROM_DEVICE
119#define SBUS_DMA_NONE DMA_NONE
120
121/* All the rest use streaming mode mappings. */
122static inline dma_addr_t sbus_map_single(struct sbus_dev *sdev, void *ptr,
123 size_t size, int direction)
124{
125 return dma_map_single(&sdev->ofdev.dev, ptr, size,
126 (enum dma_data_direction) direction);
127}
128
129static inline void sbus_unmap_single(struct sbus_dev *sdev,
130 dma_addr_t dma_addr, size_t size,
131 int direction)
132{
133 dma_unmap_single(&sdev->ofdev.dev, dma_addr, size,
134 (enum dma_data_direction) direction);
135}
136
137static inline int sbus_map_sg(struct sbus_dev *sdev, struct scatterlist *sg,
138 int nents, int direction)
139{
140 return dma_map_sg(&sdev->ofdev.dev, sg, nents,
141 (enum dma_data_direction) direction);
142}
143
144static inline void sbus_unmap_sg(struct sbus_dev *sdev, struct scatterlist *sg,
145 int nents, int direction)
146{
147 dma_unmap_sg(&sdev->ofdev.dev, sg, nents,
148 (enum dma_data_direction) direction);
149}
150
151/* Finally, allow explicit synchronization of streamable mappings. */
152static inline void sbus_dma_sync_single_for_cpu(struct sbus_dev *sdev,
153 dma_addr_t dma_handle,
154 size_t size, int direction)
155{
156 dma_sync_single_for_cpu(&sdev->ofdev.dev, dma_handle, size,
157 (enum dma_data_direction) direction);
158}
159#define sbus_dma_sync_single sbus_dma_sync_single_for_cpu
160
161static inline void sbus_dma_sync_single_for_device(struct sbus_dev *sdev,
162 dma_addr_t dma_handle,
163 size_t size, int direction)
164{
165 /* No flushing needed to sync cpu writes to the device. */
166}
167
168static inline void sbus_dma_sync_sg_for_cpu(struct sbus_dev *sdev,
169 struct scatterlist *sg,
170 int nents, int direction)
171{
172 dma_sync_sg_for_cpu(&sdev->ofdev.dev, sg, nents,
173 (enum dma_data_direction) direction);
174}
175#define sbus_dma_sync_sg sbus_dma_sync_sg_for_cpu
176
177static inline void sbus_dma_sync_sg_for_device(struct sbus_dev *sdev,
178 struct scatterlist *sg,
179 int nents, int direction)
180{
181 /* No flushing needed to sync cpu writes to the device. */
182}
183
184extern void sbus_arch_bus_ranges_init(struct device_node *, struct sbus_bus *);
185extern void sbus_setup_iommu(struct sbus_bus *, struct device_node *);
186extern void sbus_setup_arch_props(struct sbus_bus *, struct device_node *);
187extern int sbus_arch_preinit(void);
188extern void sbus_arch_postinit(void);
189
190#endif /* !(_SPARC64_SBUS_H) */
diff --git a/include/asm-sparc/scatterlist.h b/include/asm-sparc/scatterlist.h
index c82609ca1d0f..b1a0e316c2b6 100644
--- a/include/asm-sparc/scatterlist.h
+++ b/include/asm-sparc/scatterlist.h
@@ -1,26 +1,8 @@
1#ifndef _SPARC_SCATTERLIST_H 1#ifndef ___ASM_SPARC_SCATTERLIST_H
2#define _SPARC_SCATTERLIST_H 2#define ___ASM_SPARC_SCATTERLIST_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <linux/types.h> 4#include <asm-sparc/scatterlist_64.h>
5 5#else
6struct scatterlist { 6#include <asm-sparc/scatterlist_32.h>
7#ifdef CONFIG_DEBUG_SG 7#endif
8 unsigned long sg_magic;
9#endif 8#endif
10 unsigned long page_link;
11 unsigned int offset;
12
13 unsigned int length;
14
15 __u32 dvma_address; /* A place to hang host-specific addresses at. */
16 __u32 dvma_length;
17};
18
19#define sg_dma_address(sg) ((sg)->dvma_address)
20#define sg_dma_len(sg) ((sg)->dvma_length)
21
22#define ISA_DMA_THRESHOLD (~0UL)
23
24#define ARCH_HAS_SG_CHAIN
25
26#endif /* !(_SPARC_SCATTERLIST_H) */
diff --git a/include/asm-sparc/scatterlist_32.h b/include/asm-sparc/scatterlist_32.h
new file mode 100644
index 000000000000..c82609ca1d0f
--- /dev/null
+++ b/include/asm-sparc/scatterlist_32.h
@@ -0,0 +1,26 @@
1#ifndef _SPARC_SCATTERLIST_H
2#define _SPARC_SCATTERLIST_H
3
4#include <linux/types.h>
5
6struct scatterlist {
7#ifdef CONFIG_DEBUG_SG
8 unsigned long sg_magic;
9#endif
10 unsigned long page_link;
11 unsigned int offset;
12
13 unsigned int length;
14
15 __u32 dvma_address; /* A place to hang host-specific addresses at. */
16 __u32 dvma_length;
17};
18
19#define sg_dma_address(sg) ((sg)->dvma_address)
20#define sg_dma_len(sg) ((sg)->dvma_length)
21
22#define ISA_DMA_THRESHOLD (~0UL)
23
24#define ARCH_HAS_SG_CHAIN
25
26#endif /* !(_SPARC_SCATTERLIST_H) */
diff --git a/include/asm-sparc/scatterlist_64.h b/include/asm-sparc/scatterlist_64.h
new file mode 100644
index 000000000000..81bd058f9382
--- /dev/null
+++ b/include/asm-sparc/scatterlist_64.h
@@ -0,0 +1,27 @@
1#ifndef _SPARC64_SCATTERLIST_H
2#define _SPARC64_SCATTERLIST_H
3
4#include <asm/page.h>
5#include <asm/types.h>
6
7struct scatterlist {
8#ifdef CONFIG_DEBUG_SG
9 unsigned long sg_magic;
10#endif
11 unsigned long page_link;
12 unsigned int offset;
13
14 unsigned int length;
15
16 dma_addr_t dma_address;
17 __u32 dma_length;
18};
19
20#define sg_dma_address(sg) ((sg)->dma_address)
21#define sg_dma_len(sg) ((sg)->dma_length)
22
23#define ISA_DMA_THRESHOLD (~0UL)
24
25#define ARCH_HAS_SG_CHAIN
26
27#endif /* !(_SPARC64_SCATTERLIST_H) */
diff --git a/include/asm-sparc/scratchpad.h b/include/asm-sparc/scratchpad.h
new file mode 100644
index 000000000000..5e8b01fb3343
--- /dev/null
+++ b/include/asm-sparc/scratchpad.h
@@ -0,0 +1,14 @@
1#ifndef _SPARC64_SCRATCHPAD_H
2#define _SPARC64_SCRATCHPAD_H
3
4/* Sun4v scratchpad registers, accessed via ASI_SCRATCHPAD. */
5
6#define SCRATCHPAD_MMU_MISS 0x00 /* Shared with OBP - set by OBP */
7#define SCRATCHPAD_CPUID 0x08 /* Shared with OBP - set by hypervisor */
8#define SCRATCHPAD_UTSBREG1 0x10
9#define SCRATCHPAD_UTSBREG2 0x18
10 /* 0x20 and 0x28, hypervisor only... */
11#define SCRATCHPAD_UNUSED1 0x30
12#define SCRATCHPAD_UNUSED2 0x38 /* Reserved for OBP */
13
14#endif /* !(_SPARC64_SCRATCHPAD_H) */
diff --git a/include/asm-sparc/seccomp.h b/include/asm-sparc/seccomp.h
new file mode 100644
index 000000000000..7fcd9968192b
--- /dev/null
+++ b/include/asm-sparc/seccomp.h
@@ -0,0 +1,21 @@
1#ifndef _ASM_SECCOMP_H
2
3#include <linux/thread_info.h> /* already defines TIF_32BIT */
4
5#ifndef TIF_32BIT
6#error "unexpected TIF_32BIT on sparc64"
7#endif
8
9#include <linux/unistd.h>
10
11#define __NR_seccomp_read __NR_read
12#define __NR_seccomp_write __NR_write
13#define __NR_seccomp_exit __NR_exit
14#define __NR_seccomp_sigreturn __NR_rt_sigreturn
15
16#define __NR_seccomp_read_32 __NR_read
17#define __NR_seccomp_write_32 __NR_write
18#define __NR_seccomp_exit_32 __NR_exit
19#define __NR_seccomp_sigreturn_32 __NR_sigreturn
20
21#endif /* _ASM_SECCOMP_H */
diff --git a/include/asm-sparc/sections.h b/include/asm-sparc/sections.h
index 6832841df051..cbd019162425 100644
--- a/include/asm-sparc/sections.h
+++ b/include/asm-sparc/sections.h
@@ -1,6 +1,8 @@
1#ifndef _SPARC_SECTIONS_H 1#ifndef ___ASM_SPARC_SECTIONS_H
2#define _SPARC_SECTIONS_H 2#define ___ASM_SPARC_SECTIONS_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <asm-generic/sections.h> 4#include <asm-sparc/sections_64.h>
5 5#else
6#include <asm-sparc/sections_32.h>
7#endif
6#endif 8#endif
diff --git a/include/asm-sparc/sections_32.h b/include/asm-sparc/sections_32.h
new file mode 100644
index 000000000000..6832841df051
--- /dev/null
+++ b/include/asm-sparc/sections_32.h
@@ -0,0 +1,6 @@
1#ifndef _SPARC_SECTIONS_H
2#define _SPARC_SECTIONS_H
3
4#include <asm-generic/sections.h>
5
6#endif
diff --git a/include/asm-sparc/sections_64.h b/include/asm-sparc/sections_64.h
new file mode 100644
index 000000000000..3f4b9fdc28d0
--- /dev/null
+++ b/include/asm-sparc/sections_64.h
@@ -0,0 +1,9 @@
1#ifndef _SPARC64_SECTIONS_H
2#define _SPARC64_SECTIONS_H
3
4/* nothing to see, move along */
5#include <asm-generic/sections.h>
6
7extern char _start[];
8
9#endif
diff --git a/include/asm-sparc/sembuf.h b/include/asm-sparc/sembuf.h
index a79c4bb3c08a..faee1be08d67 100644
--- a/include/asm-sparc/sembuf.h
+++ b/include/asm-sparc/sembuf.h
@@ -1,7 +1,7 @@
1#ifndef _SPARC_SEMBUF_H 1#ifndef _SPARC_SEMBUF_H
2#define _SPARC_SEMBUF_H 2#define _SPARC_SEMBUF_H
3 3
4/* 4/*
5 * The semid64_ds structure for sparc architecture. 5 * The semid64_ds structure for sparc architecture.
6 * Note extra padding because this structure is passed back and forth 6 * Note extra padding because this structure is passed back and forth
7 * between kernel and user space. 7 * between kernel and user space.
@@ -10,16 +10,22 @@
10 * - 64-bit time_t to solve y2038 problem 10 * - 64-bit time_t to solve y2038 problem
11 * - 2 miscellaneous 32-bit values 11 * - 2 miscellaneous 32-bit values
12 */ 12 */
13#if defined(__sparc__) && defined(__arch64__)
14# define PADDING(x)
15#else
16# define PADDING(x) unsigned int x;
17#endif
13 18
14struct semid64_ds { 19struct semid64_ds {
15 struct ipc64_perm sem_perm; /* permissions .. see ipc.h */ 20 struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
16 unsigned int __pad1; 21 PADDING(__pad1)
17 __kernel_time_t sem_otime; /* last semop time */ 22 __kernel_time_t sem_otime; /* last semop time */
18 unsigned int __pad2; 23 PADDING(__pad2)
19 __kernel_time_t sem_ctime; /* last change time */ 24 __kernel_time_t sem_ctime; /* last change time */
20 unsigned long sem_nsems; /* no. of semaphores in array */ 25 unsigned long sem_nsems; /* no. of semaphores in array */
21 unsigned long __unused1; 26 unsigned long __unused1;
22 unsigned long __unused2; 27 unsigned long __unused2;
23}; 28};
29#undef PADDING
24 30
25#endif /* _SPARC64_SEMBUF_H */ 31#endif /* _SPARC64_SEMBUF_H */
diff --git a/include/asm-sparc/setup.h b/include/asm-sparc/setup.h
index b3af958a2ad2..2643c62f4ac0 100644
--- a/include/asm-sparc/setup.h
+++ b/include/asm-sparc/setup.h
@@ -5,6 +5,10 @@
5#ifndef _SPARC_SETUP_H 5#ifndef _SPARC_SETUP_H
6#define _SPARC_SETUP_H 6#define _SPARC_SETUP_H
7 7
8#define COMMAND_LINE_SIZE 256 8#if defined(__sparc__) && defined(__arch64__)
9# define COMMAND_LINE_SIZE 2048
10#else
11# define COMMAND_LINE_SIZE 256
12#endif
9 13
10#endif /* _SPARC_SETUP_H */ 14#endif /* _SPARC_SETUP_H */
diff --git a/include/asm-sparc/sfafsr.h b/include/asm-sparc/sfafsr.h
new file mode 100644
index 000000000000..e96137b04a4f
--- /dev/null
+++ b/include/asm-sparc/sfafsr.h
@@ -0,0 +1,82 @@
1#ifndef _SPARC64_SFAFSR_H
2#define _SPARC64_SFAFSR_H
3
4#include <linux/const.h>
5
6/* Spitfire Asynchronous Fault Status register, ASI=0x4C VA<63:0>=0x0 */
7
8#define SFAFSR_ME (_AC(1,UL) << SFAFSR_ME_SHIFT)
9#define SFAFSR_ME_SHIFT 32
10#define SFAFSR_PRIV (_AC(1,UL) << SFAFSR_PRIV_SHIFT)
11#define SFAFSR_PRIV_SHIFT 31
12#define SFAFSR_ISAP (_AC(1,UL) << SFAFSR_ISAP_SHIFT)
13#define SFAFSR_ISAP_SHIFT 30
14#define SFAFSR_ETP (_AC(1,UL) << SFAFSR_ETP_SHIFT)
15#define SFAFSR_ETP_SHIFT 29
16#define SFAFSR_IVUE (_AC(1,UL) << SFAFSR_IVUE_SHIFT)
17#define SFAFSR_IVUE_SHIFT 28
18#define SFAFSR_TO (_AC(1,UL) << SFAFSR_TO_SHIFT)
19#define SFAFSR_TO_SHIFT 27
20#define SFAFSR_BERR (_AC(1,UL) << SFAFSR_BERR_SHIFT)
21#define SFAFSR_BERR_SHIFT 26
22#define SFAFSR_LDP (_AC(1,UL) << SFAFSR_LDP_SHIFT)
23#define SFAFSR_LDP_SHIFT 25
24#define SFAFSR_CP (_AC(1,UL) << SFAFSR_CP_SHIFT)
25#define SFAFSR_CP_SHIFT 24
26#define SFAFSR_WP (_AC(1,UL) << SFAFSR_WP_SHIFT)
27#define SFAFSR_WP_SHIFT 23
28#define SFAFSR_EDP (_AC(1,UL) << SFAFSR_EDP_SHIFT)
29#define SFAFSR_EDP_SHIFT 22
30#define SFAFSR_UE (_AC(1,UL) << SFAFSR_UE_SHIFT)
31#define SFAFSR_UE_SHIFT 21
32#define SFAFSR_CE (_AC(1,UL) << SFAFSR_CE_SHIFT)
33#define SFAFSR_CE_SHIFT 20
34#define SFAFSR_ETS (_AC(0xf,UL) << SFAFSR_ETS_SHIFT)
35#define SFAFSR_ETS_SHIFT 16
36#define SFAFSR_PSYND (_AC(0xffff,UL) << SFAFSR_PSYND_SHIFT)
37#define SFAFSR_PSYND_SHIFT 0
38
39/* UDB Error Register, ASI=0x7f VA<63:0>=0x0(High),0x18(Low) for read
40 * ASI=0x77 VA<63:0>=0x0(High),0x18(Low) for write
41 */
42
43#define UDBE_UE (_AC(1,UL) << 9)
44#define UDBE_CE (_AC(1,UL) << 8)
45#define UDBE_E_SYNDR (_AC(0xff,UL) << 0)
46
47/* The trap handlers for asynchronous errors encode the AFSR and
48 * other pieces of information into a 64-bit argument for C code
49 * encoded as follows:
50 *
51 * -----------------------------------------------
52 * | UDB_H | UDB_L | TL>1 | TT | AFSR |
53 * -----------------------------------------------
54 * 63 54 53 44 42 41 33 32 0
55 *
56 * The AFAR is passed in unchanged.
57 */
58#define SFSTAT_UDBH_MASK (_AC(0x3ff,UL) << SFSTAT_UDBH_SHIFT)
59#define SFSTAT_UDBH_SHIFT 54
60#define SFSTAT_UDBL_MASK (_AC(0x3ff,UL) << SFSTAT_UDBH_SHIFT)
61#define SFSTAT_UDBL_SHIFT 44
62#define SFSTAT_TL_GT_ONE (_AC(1,UL) << SFSTAT_TL_GT_ONE_SHIFT)
63#define SFSTAT_TL_GT_ONE_SHIFT 42
64#define SFSTAT_TRAP_TYPE (_AC(0x1FF,UL) << SFSTAT_TRAP_TYPE_SHIFT)
65#define SFSTAT_TRAP_TYPE_SHIFT 33
66#define SFSTAT_AFSR_MASK (_AC(0x1ffffffff,UL) << SFSTAT_AFSR_SHIFT)
67#define SFSTAT_AFSR_SHIFT 0
68
69/* ESTATE Error Enable Register, ASI=0x4b VA<63:0>=0x0 */
70#define ESTATE_ERR_CE 0x1 /* Correctable errors */
71#define ESTATE_ERR_NCE 0x2 /* TO, BERR, LDP, ETP, EDP, WP, UE, IVUE */
72#define ESTATE_ERR_ISAP 0x4 /* System address parity error */
73#define ESTATE_ERR_ALL (ESTATE_ERR_CE | \
74 ESTATE_ERR_NCE | \
75 ESTATE_ERR_ISAP)
76
77/* The various trap types that report using the above state. */
78#define TRAP_TYPE_IAE 0x09 /* Instruction Access Error */
79#define TRAP_TYPE_DAE 0x32 /* Data Access Error */
80#define TRAP_TYPE_CEE 0x63 /* Correctable ECC Error */
81
82#endif /* _SPARC64_SFAFSR_H */
diff --git a/include/asm-sparc/sfp-machine.h b/include/asm-sparc/sfp-machine.h
index 266a42b8f99f..c676fcc2dd27 100644
--- a/include/asm-sparc/sfp-machine.h
+++ b/include/asm-sparc/sfp-machine.h
@@ -1,212 +1,8 @@
1/* Machine-dependent software floating-point definitions. 1#ifndef ___ASM_SPARC_SFP_MACHINE_H
2 Sparc userland (_Q_*) version. 2#define ___ASM_SPARC_SFP_MACHINE_H
3 Copyright (C) 1997,1998,1999 Free Software Foundation, Inc. 3#if defined(__sparc__) && defined(__arch64__)
4 This file is part of the GNU C Library. 4#include <asm-sparc/sfp-machine_64.h>
5 Contributed by Richard Henderson (rth@cygnus.com),
6 Jakub Jelinek (jj@ultra.linux.cz),
7 David S. Miller (davem@redhat.com) and
8 Peter Maydell (pmaydell@chiark.greenend.org.uk).
9
10 The GNU C Library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public License as
12 published by the Free Software Foundation; either version 2 of the
13 License, or (at your option) any later version.
14
15 The GNU C Library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
19
20 You should have received a copy of the GNU Library General Public
21 License along with the GNU C Library; see the file COPYING.LIB. If
22 not, write to the Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24
25#ifndef _SFP_MACHINE_H
26#define _SFP_MACHINE_H
27
28
29#define _FP_W_TYPE_SIZE 32
30#define _FP_W_TYPE unsigned long
31#define _FP_WS_TYPE signed long
32#define _FP_I_TYPE long
33
34#define _FP_MUL_MEAT_S(R,X,Y) \
35 _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm)
36#define _FP_MUL_MEAT_D(R,X,Y) \
37 _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
38#define _FP_MUL_MEAT_Q(R,X,Y) \
39 _FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
40
41#define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv(S,R,X,Y)
42#define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y)
43#define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_4_udiv(Q,R,X,Y)
44
45#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
46#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1
47#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1
48#define _FP_NANSIGN_S 0
49#define _FP_NANSIGN_D 0
50#define _FP_NANSIGN_Q 0
51
52#define _FP_KEEPNANFRACP 1
53
54/* If one NaN is signaling and the other is not,
55 * we choose that one, otherwise we choose X.
56 */
57/* For _Qp_* and _Q_*, this should prefer X, for
58 * CPU instruction emulation this should prefer Y.
59 * (see SPAMv9 B.2.2 section).
60 */
61#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
62 do { \
63 if ((_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs) \
64 && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
65 { \
66 R##_s = X##_s; \
67 _FP_FRAC_COPY_##wc(R,X); \
68 } \
69 else \
70 { \
71 R##_s = Y##_s; \
72 _FP_FRAC_COPY_##wc(R,Y); \
73 } \
74 R##_c = FP_CLS_NAN; \
75 } while (0)
76
77/* Some assembly to speed things up. */
78#define __FP_FRAC_ADD_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \
79 __asm__ ("addcc %r7,%8,%2\n\t" \
80 "addxcc %r5,%6,%1\n\t" \
81 "addx %r3,%4,%0\n" \
82 : "=r" ((USItype)(r2)), \
83 "=&r" ((USItype)(r1)), \
84 "=&r" ((USItype)(r0)) \
85 : "%rJ" ((USItype)(x2)), \
86 "rI" ((USItype)(y2)), \
87 "%rJ" ((USItype)(x1)), \
88 "rI" ((USItype)(y1)), \
89 "%rJ" ((USItype)(x0)), \
90 "rI" ((USItype)(y0)) \
91 : "cc")
92
93#define __FP_FRAC_SUB_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \
94 __asm__ ("subcc %r7,%8,%2\n\t" \
95 "subxcc %r5,%6,%1\n\t" \
96 "subx %r3,%4,%0\n" \
97 : "=r" ((USItype)(r2)), \
98 "=&r" ((USItype)(r1)), \
99 "=&r" ((USItype)(r0)) \
100 : "%rJ" ((USItype)(x2)), \
101 "rI" ((USItype)(y2)), \
102 "%rJ" ((USItype)(x1)), \
103 "rI" ((USItype)(y1)), \
104 "%rJ" ((USItype)(x0)), \
105 "rI" ((USItype)(y0)) \
106 : "cc")
107
108#define __FP_FRAC_ADD_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \
109 do { \
110 /* We need to fool gcc, as we need to pass more than 10 \
111 input/outputs. */ \
112 register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \
113 __asm__ __volatile__ ( \
114 "addcc %r8,%9,%1\n\t" \
115 "addxcc %r6,%7,%0\n\t" \
116 "addxcc %r4,%5,%%g2\n\t" \
117 "addx %r2,%3,%%g1\n\t" \
118 : "=&r" ((USItype)(r1)), \
119 "=&r" ((USItype)(r0)) \
120 : "%rJ" ((USItype)(x3)), \
121 "rI" ((USItype)(y3)), \
122 "%rJ" ((USItype)(x2)), \
123 "rI" ((USItype)(y2)), \
124 "%rJ" ((USItype)(x1)), \
125 "rI" ((USItype)(y1)), \
126 "%rJ" ((USItype)(x0)), \
127 "rI" ((USItype)(y0)) \
128 : "cc", "g1", "g2"); \
129 __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \
130 r3 = _t1; r2 = _t2; \
131 } while (0)
132
133#define __FP_FRAC_SUB_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \
134 do { \
135 /* We need to fool gcc, as we need to pass more than 10 \
136 input/outputs. */ \
137 register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \
138 __asm__ __volatile__ ( \
139 "subcc %r8,%9,%1\n\t" \
140 "subxcc %r6,%7,%0\n\t" \
141 "subxcc %r4,%5,%%g2\n\t" \
142 "subx %r2,%3,%%g1\n\t" \
143 : "=&r" ((USItype)(r1)), \
144 "=&r" ((USItype)(r0)) \
145 : "%rJ" ((USItype)(x3)), \
146 "rI" ((USItype)(y3)), \
147 "%rJ" ((USItype)(x2)), \
148 "rI" ((USItype)(y2)), \
149 "%rJ" ((USItype)(x1)), \
150 "rI" ((USItype)(y1)), \
151 "%rJ" ((USItype)(x0)), \
152 "rI" ((USItype)(y0)) \
153 : "cc", "g1", "g2"); \
154 __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \
155 r3 = _t1; r2 = _t2; \
156 } while (0)
157
158#define __FP_FRAC_DEC_3(x2,x1,x0,y2,y1,y0) __FP_FRAC_SUB_3(x2,x1,x0,x2,x1,x0,y2,y1,y0)
159
160#define __FP_FRAC_DEC_4(x3,x2,x1,x0,y3,y2,y1,y0) __FP_FRAC_SUB_4(x3,x2,x1,x0,x3,x2,x1,x0,y3,y2,y1,y0)
161
162#define __FP_FRAC_ADDI_4(x3,x2,x1,x0,i) \
163 __asm__ ("addcc %3,%4,%3\n\t" \
164 "addxcc %2,%%g0,%2\n\t" \
165 "addxcc %1,%%g0,%1\n\t" \
166 "addx %0,%%g0,%0\n\t" \
167 : "=&r" ((USItype)(x3)), \
168 "=&r" ((USItype)(x2)), \
169 "=&r" ((USItype)(x1)), \
170 "=&r" ((USItype)(x0)) \
171 : "rI" ((USItype)(i)), \
172 "0" ((USItype)(x3)), \
173 "1" ((USItype)(x2)), \
174 "2" ((USItype)(x1)), \
175 "3" ((USItype)(x0)) \
176 : "cc")
177
178#ifndef CONFIG_SMP
179extern struct task_struct *last_task_used_math;
180#endif
181
182/* Obtain the current rounding mode. */
183#ifndef FP_ROUNDMODE
184#ifdef CONFIG_SMP
185#define FP_ROUNDMODE ((current->thread.fsr >> 30) & 0x3)
186#else
187#define FP_ROUNDMODE ((last_task_used_math->thread.fsr >> 30) & 0x3)
188#endif
189#endif
190
191/* Exception flags. */
192#define FP_EX_INVALID (1 << 4)
193#define FP_EX_OVERFLOW (1 << 3)
194#define FP_EX_UNDERFLOW (1 << 2)
195#define FP_EX_DIVZERO (1 << 1)
196#define FP_EX_INEXACT (1 << 0)
197
198#define FP_HANDLE_EXCEPTIONS return _fex
199
200#ifdef CONFIG_SMP
201#define FP_INHIBIT_RESULTS ((current->thread.fsr >> 23) & _fex)
202#else
203#define FP_INHIBIT_RESULTS ((last_task_used_math->thread.fsr >> 23) & _fex)
204#endif
205
206#ifdef CONFIG_SMP
207#define FP_TRAPPING_EXCEPTIONS ((current->thread.fsr >> 23) & 0x1f)
208#else 5#else
209#define FP_TRAPPING_EXCEPTIONS ((last_task_used_math->thread.fsr >> 23) & 0x1f) 6#include <asm-sparc/sfp-machine_32.h>
210#endif 7#endif
211
212#endif 8#endif
diff --git a/include/asm-sparc/sfp-machine_32.h b/include/asm-sparc/sfp-machine_32.h
new file mode 100644
index 000000000000..01d9c3b5a73b
--- /dev/null
+++ b/include/asm-sparc/sfp-machine_32.h
@@ -0,0 +1,212 @@
1/* Machine-dependent software floating-point definitions.
2 Sparc userland (_Q_*) version.
3 Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Richard Henderson (rth@cygnus.com),
6 Jakub Jelinek (jj@ultra.linux.cz),
7 David S. Miller (davem@redhat.com) and
8 Peter Maydell (pmaydell@chiark.greenend.org.uk).
9
10 The GNU C Library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public License as
12 published by the Free Software Foundation; either version 2 of the
13 License, or (at your option) any later version.
14
15 The GNU C Library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
19
20 You should have received a copy of the GNU Library General Public
21 License along with the GNU C Library; see the file COPYING.LIB. If
22 not, write to the Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24
25#ifndef _SFP_MACHINE_H
26#define _SFP_MACHINE_H
27
28
29#define _FP_W_TYPE_SIZE 32
30#define _FP_W_TYPE unsigned long
31#define _FP_WS_TYPE signed long
32#define _FP_I_TYPE long
33
34#define _FP_MUL_MEAT_S(R,X,Y) \
35 _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm)
36#define _FP_MUL_MEAT_D(R,X,Y) \
37 _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
38#define _FP_MUL_MEAT_Q(R,X,Y) \
39 _FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
40
41#define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv(S,R,X,Y)
42#define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y)
43#define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_4_udiv(Q,R,X,Y)
44
45#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
46#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1
47#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1
48#define _FP_NANSIGN_S 0
49#define _FP_NANSIGN_D 0
50#define _FP_NANSIGN_Q 0
51
52#define _FP_KEEPNANFRACP 1
53
54/* If one NaN is signaling and the other is not,
55 * we choose that one, otherwise we choose X.
56 */
57/* For _Qp_* and _Q_*, this should prefer X, for
58 * CPU instruction emulation this should prefer Y.
59 * (see SPAMv9 B.2.2 section).
60 */
61#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
62 do { \
63 if ((_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs) \
64 && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
65 { \
66 R##_s = X##_s; \
67 _FP_FRAC_COPY_##wc(R,X); \
68 } \
69 else \
70 { \
71 R##_s = Y##_s; \
72 _FP_FRAC_COPY_##wc(R,Y); \
73 } \
74 R##_c = FP_CLS_NAN; \
75 } while (0)
76
77/* Some assembly to speed things up. */
78#define __FP_FRAC_ADD_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \
79 __asm__ ("addcc %r7,%8,%2\n\t" \
80 "addxcc %r5,%6,%1\n\t" \
81 "addx %r3,%4,%0\n" \
82 : "=r" ((USItype)(r2)), \
83 "=&r" ((USItype)(r1)), \
84 "=&r" ((USItype)(r0)) \
85 : "%rJ" ((USItype)(x2)), \
86 "rI" ((USItype)(y2)), \
87 "%rJ" ((USItype)(x1)), \
88 "rI" ((USItype)(y1)), \
89 "%rJ" ((USItype)(x0)), \
90 "rI" ((USItype)(y0)) \
91 : "cc")
92
93#define __FP_FRAC_SUB_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \
94 __asm__ ("subcc %r7,%8,%2\n\t" \
95 "subxcc %r5,%6,%1\n\t" \
96 "subx %r3,%4,%0\n" \
97 : "=r" ((USItype)(r2)), \
98 "=&r" ((USItype)(r1)), \
99 "=&r" ((USItype)(r0)) \
100 : "%rJ" ((USItype)(x2)), \
101 "rI" ((USItype)(y2)), \
102 "%rJ" ((USItype)(x1)), \
103 "rI" ((USItype)(y1)), \
104 "%rJ" ((USItype)(x0)), \
105 "rI" ((USItype)(y0)) \
106 : "cc")
107
108#define __FP_FRAC_ADD_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \
109 do { \
110 /* We need to fool gcc, as we need to pass more than 10 \
111 input/outputs. */ \
112 register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \
113 __asm__ __volatile__ ( \
114 "addcc %r8,%9,%1\n\t" \
115 "addxcc %r6,%7,%0\n\t" \
116 "addxcc %r4,%5,%%g2\n\t" \
117 "addx %r2,%3,%%g1\n\t" \
118 : "=&r" ((USItype)(r1)), \
119 "=&r" ((USItype)(r0)) \
120 : "%rJ" ((USItype)(x3)), \
121 "rI" ((USItype)(y3)), \
122 "%rJ" ((USItype)(x2)), \
123 "rI" ((USItype)(y2)), \
124 "%rJ" ((USItype)(x1)), \
125 "rI" ((USItype)(y1)), \
126 "%rJ" ((USItype)(x0)), \
127 "rI" ((USItype)(y0)) \
128 : "cc", "g1", "g2"); \
129 __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \
130 r3 = _t1; r2 = _t2; \
131 } while (0)
132
133#define __FP_FRAC_SUB_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \
134 do { \
135 /* We need to fool gcc, as we need to pass more than 10 \
136 input/outputs. */ \
137 register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \
138 __asm__ __volatile__ ( \
139 "subcc %r8,%9,%1\n\t" \
140 "subxcc %r6,%7,%0\n\t" \
141 "subxcc %r4,%5,%%g2\n\t" \
142 "subx %r2,%3,%%g1\n\t" \
143 : "=&r" ((USItype)(r1)), \
144 "=&r" ((USItype)(r0)) \
145 : "%rJ" ((USItype)(x3)), \
146 "rI" ((USItype)(y3)), \
147 "%rJ" ((USItype)(x2)), \
148 "rI" ((USItype)(y2)), \
149 "%rJ" ((USItype)(x1)), \
150 "rI" ((USItype)(y1)), \
151 "%rJ" ((USItype)(x0)), \
152 "rI" ((USItype)(y0)) \
153 : "cc", "g1", "g2"); \
154 __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \
155 r3 = _t1; r2 = _t2; \
156 } while (0)
157
158#define __FP_FRAC_DEC_3(x2,x1,x0,y2,y1,y0) __FP_FRAC_SUB_3(x2,x1,x0,x2,x1,x0,y2,y1,y0)
159
160#define __FP_FRAC_DEC_4(x3,x2,x1,x0,y3,y2,y1,y0) __FP_FRAC_SUB_4(x3,x2,x1,x0,x3,x2,x1,x0,y3,y2,y1,y0)
161
162#define __FP_FRAC_ADDI_4(x3,x2,x1,x0,i) \
163 __asm__ ("addcc %3,%4,%3\n\t" \
164 "addxcc %2,%%g0,%2\n\t" \
165 "addxcc %1,%%g0,%1\n\t" \
166 "addx %0,%%g0,%0\n\t" \
167 : "=&r" ((USItype)(x3)), \
168 "=&r" ((USItype)(x2)), \
169 "=&r" ((USItype)(x1)), \
170 "=&r" ((USItype)(x0)) \
171 : "rI" ((USItype)(i)), \
172 "0" ((USItype)(x3)), \
173 "1" ((USItype)(x2)), \
174 "2" ((USItype)(x1)), \
175 "3" ((USItype)(x0)) \
176 : "cc")
177
178#ifndef CONFIG_SMP
179extern struct task_struct *last_task_used_math;
180#endif
181
182/* Obtain the current rounding mode. */
183#ifndef FP_ROUNDMODE
184#ifdef CONFIG_SMP
185#define FP_ROUNDMODE ((current->thread.fsr >> 30) & 0x3)
186#else
187#define FP_ROUNDMODE ((last_task_used_math->thread.fsr >> 30) & 0x3)
188#endif
189#endif
190
191/* Exception flags. */
192#define FP_EX_INVALID (1 << 4)
193#define FP_EX_OVERFLOW (1 << 3)
194#define FP_EX_UNDERFLOW (1 << 2)
195#define FP_EX_DIVZERO (1 << 1)
196#define FP_EX_INEXACT (1 << 0)
197
198#define FP_HANDLE_EXCEPTIONS return _fex
199
200#ifdef CONFIG_SMP
201#define FP_INHIBIT_RESULTS ((current->thread.fsr >> 23) & _fex)
202#else
203#define FP_INHIBIT_RESULTS ((last_task_used_math->thread.fsr >> 23) & _fex)
204#endif
205
206#ifdef CONFIG_SMP
207#define FP_TRAPPING_EXCEPTIONS ((current->thread.fsr >> 23) & 0x1f)
208#else
209#define FP_TRAPPING_EXCEPTIONS ((last_task_used_math->thread.fsr >> 23) & 0x1f)
210#endif
211
212#endif
diff --git a/include/asm-sparc/sfp-machine_64.h b/include/asm-sparc/sfp-machine_64.h
new file mode 100644
index 000000000000..ca913ef40bd5
--- /dev/null
+++ b/include/asm-sparc/sfp-machine_64.h
@@ -0,0 +1,93 @@
1/* Machine-dependent software floating-point definitions.
2 Sparc64 kernel version.
3 Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Richard Henderson (rth@cygnus.com),
6 Jakub Jelinek (jj@ultra.linux.cz) and
7 David S. Miller (davem@redhat.com).
8
9 The GNU C Library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
13
14 The GNU C Library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public
20 License along with the GNU C Library; see the file COPYING.LIB. If
21 not, write to the Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23
24#ifndef _SFP_MACHINE_H
25#define _SFP_MACHINE_H
26
27#define _FP_W_TYPE_SIZE 64
28#define _FP_W_TYPE unsigned long
29#define _FP_WS_TYPE signed long
30#define _FP_I_TYPE long
31
32#define _FP_MUL_MEAT_S(R,X,Y) \
33 _FP_MUL_MEAT_1_imm(_FP_WFRACBITS_S,R,X,Y)
34#define _FP_MUL_MEAT_D(R,X,Y) \
35 _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
36#define _FP_MUL_MEAT_Q(R,X,Y) \
37 _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
38
39#define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_imm(S,R,X,Y,_FP_DIV_HELP_imm)
40#define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_1_udiv_norm(D,R,X,Y)
41#define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_2_udiv(Q,R,X,Y)
42
43#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
44#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1)
45#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1
46#define _FP_NANSIGN_S 0
47#define _FP_NANSIGN_D 0
48#define _FP_NANSIGN_Q 0
49
50#define _FP_KEEPNANFRACP 1
51
52/* If one NaN is signaling and the other is not,
53 * we choose that one, otherwise we choose X.
54 */
55/* For _Qp_* and _Q_*, this should prefer X, for
56 * CPU instruction emulation this should prefer Y.
57 * (see SPAMv9 B.2.2 section).
58 */
59#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
60 do { \
61 if ((_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs) \
62 && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
63 { \
64 R##_s = X##_s; \
65 _FP_FRAC_COPY_##wc(R,X); \
66 } \
67 else \
68 { \
69 R##_s = Y##_s; \
70 _FP_FRAC_COPY_##wc(R,Y); \
71 } \
72 R##_c = FP_CLS_NAN; \
73 } while (0)
74
75/* Obtain the current rounding mode. */
76#ifndef FP_ROUNDMODE
77#define FP_ROUNDMODE ((current_thread_info()->xfsr[0] >> 30) & 0x3)
78#endif
79
80/* Exception flags. */
81#define FP_EX_INVALID (1 << 4)
82#define FP_EX_OVERFLOW (1 << 3)
83#define FP_EX_UNDERFLOW (1 << 2)
84#define FP_EX_DIVZERO (1 << 1)
85#define FP_EX_INEXACT (1 << 0)
86
87#define FP_HANDLE_EXCEPTIONS return _fex
88
89#define FP_INHIBIT_RESULTS ((current_thread_info()->xfsr[0] >> 23) & _fex)
90
91#define FP_TRAPPING_EXCEPTIONS ((current_thread_info()->xfsr[0] >> 23) & 0x1f)
92
93#endif
diff --git a/include/asm-sparc/shmbuf.h b/include/asm-sparc/shmbuf.h
index 1ff9da8bec73..83a16055363f 100644
--- a/include/asm-sparc/shmbuf.h
+++ b/include/asm-sparc/shmbuf.h
@@ -11,13 +11,19 @@
11 * - 2 miscellaneous 32-bit values 11 * - 2 miscellaneous 32-bit values
12 */ 12 */
13 13
14#if defined(__sparc__) && defined(__arch64__)
15# define PADDING(x)
16#else
17# define PADDING(x) unsigned int x;
18#endif
19
14struct shmid64_ds { 20struct shmid64_ds {
15 struct ipc64_perm shm_perm; /* operation perms */ 21 struct ipc64_perm shm_perm; /* operation perms */
16 unsigned int __pad1; 22 PADDING(__pad1)
17 __kernel_time_t shm_atime; /* last attach time */ 23 __kernel_time_t shm_atime; /* last attach time */
18 unsigned int __pad2; 24 PADDING(__pad2)
19 __kernel_time_t shm_dtime; /* last detach time */ 25 __kernel_time_t shm_dtime; /* last detach time */
20 unsigned int __pad3; 26 PADDING(__pad3)
21 __kernel_time_t shm_ctime; /* last change time */ 27 __kernel_time_t shm_ctime; /* last change time */
22 size_t shm_segsz; /* size of segment (bytes) */ 28 size_t shm_segsz; /* size of segment (bytes) */
23 __kernel_pid_t shm_cpid; /* pid of creator */ 29 __kernel_pid_t shm_cpid; /* pid of creator */
@@ -39,4 +45,6 @@ struct shminfo64 {
39 unsigned long __unused4; 45 unsigned long __unused4;
40}; 46};
41 47
48#undef PADDING
49
42#endif /* _SPARC_SHMBUF_H */ 50#endif /* _SPARC_SHMBUF_H */
diff --git a/include/asm-sparc/shmparam.h b/include/asm-sparc/shmparam.h
index 59a1243c12f3..16fda7e9acc8 100644
--- a/include/asm-sparc/shmparam.h
+++ b/include/asm-sparc/shmparam.h
@@ -1,11 +1,8 @@
1#ifndef _ASMSPARC_SHMPARAM_H 1#ifndef ___ASM_SPARC_SHMPARAM_H
2#define _ASMSPARC_SHMPARAM_H 2#define ___ASM_SPARC_SHMPARAM_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#define __ARCH_FORCE_SHMLBA 1 4#include <asm-sparc/shmparam_64.h>
5 5#else
6extern int vac_cache_size; 6#include <asm-sparc/shmparam_32.h>
7#define SHMLBA (vac_cache_size ? vac_cache_size : \ 7#endif
8 (sparc_cpu_model == sun4c ? (64 * 1024) : \ 8#endif
9 (sparc_cpu_model == sun4 ? (128 * 1024) : PAGE_SIZE)))
10
11#endif /* _ASMSPARC_SHMPARAM_H */
diff --git a/include/asm-sparc/shmparam_32.h b/include/asm-sparc/shmparam_32.h
new file mode 100644
index 000000000000..59a1243c12f3
--- /dev/null
+++ b/include/asm-sparc/shmparam_32.h
@@ -0,0 +1,11 @@
1#ifndef _ASMSPARC_SHMPARAM_H
2#define _ASMSPARC_SHMPARAM_H
3
4#define __ARCH_FORCE_SHMLBA 1
5
6extern int vac_cache_size;
7#define SHMLBA (vac_cache_size ? vac_cache_size : \
8 (sparc_cpu_model == sun4c ? (64 * 1024) : \
9 (sparc_cpu_model == sun4 ? (128 * 1024) : PAGE_SIZE)))
10
11#endif /* _ASMSPARC_SHMPARAM_H */
diff --git a/include/asm-sparc/shmparam_64.h b/include/asm-sparc/shmparam_64.h
new file mode 100644
index 000000000000..1ed0d6701a9b
--- /dev/null
+++ b/include/asm-sparc/shmparam_64.h
@@ -0,0 +1,10 @@
1#ifndef _ASMSPARC64_SHMPARAM_H
2#define _ASMSPARC64_SHMPARAM_H
3
4#include <asm/spitfire.h>
5
6#define __ARCH_FORCE_SHMLBA 1
7/* attach addr a multiple of this */
8#define SHMLBA ((PAGE_SIZE > L1DCACHE_SIZE) ? PAGE_SIZE : L1DCACHE_SIZE)
9
10#endif /* _ASMSPARC64_SHMPARAM_H */
diff --git a/include/asm-sparc/sigcontext.h b/include/asm-sparc/sigcontext.h
index c5fb60dcbd75..82fc7d54a4fa 100644
--- a/include/asm-sparc/sigcontext.h
+++ b/include/asm-sparc/sigcontext.h
@@ -1,62 +1,8 @@
1#ifndef __SPARC_SIGCONTEXT_H 1#ifndef ___ASM_SPARC_SIGCONTEXT_H
2#define __SPARC_SIGCONTEXT_H 2#define ___ASM_SPARC_SIGCONTEXT_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#ifdef __KERNEL__ 4#include <asm-sparc/sigcontext_64.h>
5#include <asm/ptrace.h> 5#else
6 6#include <asm-sparc/sigcontext_32.h>
7#ifndef __ASSEMBLY__ 7#endif
8 8#endif
9#define __SUNOS_MAXWIN 31
10
11/* This is what SunOS does, so shall I. */
12struct sigcontext {
13 int sigc_onstack; /* state to restore */
14 int sigc_mask; /* sigmask to restore */
15 int sigc_sp; /* stack pointer */
16 int sigc_pc; /* program counter */
17 int sigc_npc; /* next program counter */
18 int sigc_psr; /* for condition codes etc */
19 int sigc_g1; /* User uses these two registers */
20 int sigc_o0; /* within the trampoline code. */
21
22 /* Now comes information regarding the users window set
23 * at the time of the signal.
24 */
25 int sigc_oswins; /* outstanding windows */
26
27 /* stack ptrs for each regwin buf */
28 char *sigc_spbuf[__SUNOS_MAXWIN];
29
30 /* Windows to restore after signal */
31 struct {
32 unsigned long locals[8];
33 unsigned long ins[8];
34 } sigc_wbuf[__SUNOS_MAXWIN];
35};
36
37typedef struct {
38 struct {
39 unsigned long psr;
40 unsigned long pc;
41 unsigned long npc;
42 unsigned long y;
43 unsigned long u_regs[16]; /* globals and ins */
44 } si_regs;
45 int si_mask;
46} __siginfo_t;
47
48typedef struct {
49 unsigned long si_float_regs [32];
50 unsigned long si_fsr;
51 unsigned long si_fpqdepth;
52 struct {
53 unsigned long *insn_addr;
54 unsigned long insn;
55 } si_fpqueue [16];
56} __siginfo_fpu_t;
57
58#endif /* !(__ASSEMBLY__) */
59
60#endif /* (__KERNEL__) */
61
62#endif /* !(__SPARC_SIGCONTEXT_H) */
diff --git a/include/asm-sparc/sigcontext_32.h b/include/asm-sparc/sigcontext_32.h
new file mode 100644
index 000000000000..c5fb60dcbd75
--- /dev/null
+++ b/include/asm-sparc/sigcontext_32.h
@@ -0,0 +1,62 @@
1#ifndef __SPARC_SIGCONTEXT_H
2#define __SPARC_SIGCONTEXT_H
3
4#ifdef __KERNEL__
5#include <asm/ptrace.h>
6
7#ifndef __ASSEMBLY__
8
9#define __SUNOS_MAXWIN 31
10
11/* This is what SunOS does, so shall I. */
12struct sigcontext {
13 int sigc_onstack; /* state to restore */
14 int sigc_mask; /* sigmask to restore */
15 int sigc_sp; /* stack pointer */
16 int sigc_pc; /* program counter */
17 int sigc_npc; /* next program counter */
18 int sigc_psr; /* for condition codes etc */
19 int sigc_g1; /* User uses these two registers */
20 int sigc_o0; /* within the trampoline code. */
21
22 /* Now comes information regarding the users window set
23 * at the time of the signal.
24 */
25 int sigc_oswins; /* outstanding windows */
26
27 /* stack ptrs for each regwin buf */
28 char *sigc_spbuf[__SUNOS_MAXWIN];
29
30 /* Windows to restore after signal */
31 struct {
32 unsigned long locals[8];
33 unsigned long ins[8];
34 } sigc_wbuf[__SUNOS_MAXWIN];
35};
36
37typedef struct {
38 struct {
39 unsigned long psr;
40 unsigned long pc;
41 unsigned long npc;
42 unsigned long y;
43 unsigned long u_regs[16]; /* globals and ins */
44 } si_regs;
45 int si_mask;
46} __siginfo_t;
47
48typedef struct {
49 unsigned long si_float_regs [32];
50 unsigned long si_fsr;
51 unsigned long si_fpqdepth;
52 struct {
53 unsigned long *insn_addr;
54 unsigned long insn;
55 } si_fpqueue [16];
56} __siginfo_fpu_t;
57
58#endif /* !(__ASSEMBLY__) */
59
60#endif /* (__KERNEL__) */
61
62#endif /* !(__SPARC_SIGCONTEXT_H) */
diff --git a/include/asm-sparc/sigcontext_64.h b/include/asm-sparc/sigcontext_64.h
new file mode 100644
index 000000000000..1c868d680cfc
--- /dev/null
+++ b/include/asm-sparc/sigcontext_64.h
@@ -0,0 +1,87 @@
1#ifndef __SPARC64_SIGCONTEXT_H
2#define __SPARC64_SIGCONTEXT_H
3
4#ifdef __KERNEL__
5#include <asm/ptrace.h>
6#endif
7
8#ifndef __ASSEMBLY__
9
10#ifdef __KERNEL__
11
12#define __SUNOS_MAXWIN 31
13
14/* This is what SunOS does, so shall I unless we use new 32bit signals or rt signals. */
15struct sigcontext32 {
16 int sigc_onstack; /* state to restore */
17 int sigc_mask; /* sigmask to restore */
18 int sigc_sp; /* stack pointer */
19 int sigc_pc; /* program counter */
20 int sigc_npc; /* next program counter */
21 int sigc_psr; /* for condition codes etc */
22 int sigc_g1; /* User uses these two registers */
23 int sigc_o0; /* within the trampoline code. */
24
25 /* Now comes information regarding the users window set
26 * at the time of the signal.
27 */
28 int sigc_oswins; /* outstanding windows */
29
30 /* stack ptrs for each regwin buf */
31 unsigned sigc_spbuf[__SUNOS_MAXWIN];
32
33 /* Windows to restore after signal */
34 struct reg_window32 sigc_wbuf[__SUNOS_MAXWIN];
35};
36
37#endif
38
39#ifdef __KERNEL__
40
41/* This is what we use for 32bit new non-rt signals. */
42
43typedef struct {
44 struct {
45 unsigned int psr;
46 unsigned int pc;
47 unsigned int npc;
48 unsigned int y;
49 unsigned int u_regs[16]; /* globals and ins */
50 } si_regs;
51 int si_mask;
52} __siginfo32_t;
53
54#endif
55
56typedef struct {
57 unsigned int si_float_regs [64];
58 unsigned long si_fsr;
59 unsigned long si_gsr;
60 unsigned long si_fprs;
61} __siginfo_fpu_t;
62
63/* This is what SunOS doesn't, so we have to write this alone
64 and do it properly. */
65struct sigcontext {
66 /* The size of this array has to match SI_MAX_SIZE from siginfo.h */
67 char sigc_info[128];
68 struct {
69 unsigned long u_regs[16]; /* globals and ins */
70 unsigned long tstate;
71 unsigned long tpc;
72 unsigned long tnpc;
73 unsigned int y;
74 unsigned int fprs;
75 } sigc_regs;
76 __siginfo_fpu_t * sigc_fpu_save;
77 struct {
78 void * ss_sp;
79 int ss_flags;
80 unsigned long ss_size;
81 } sigc_stack;
82 unsigned long sigc_mask;
83};
84
85#endif /* !(__ASSEMBLY__) */
86
87#endif /* !(__SPARC64_SIGCONTEXT_H) */
diff --git a/include/asm-sparc/siginfo.h b/include/asm-sparc/siginfo.h
index 3c71af135c52..2c9fccf4ce18 100644
--- a/include/asm-sparc/siginfo.h
+++ b/include/asm-sparc/siginfo.h
@@ -1,17 +1,8 @@
1#ifndef _SPARC_SIGINFO_H 1#ifndef ___ASM_SPARC_SIGINFO_H
2#define _SPARC_SIGINFO_H 2#define ___ASM_SPARC_SIGINFO_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#define __ARCH_SI_UID_T unsigned int 4#include <asm-sparc/siginfo_64.h>
5#define __ARCH_SI_TRAPNO 5#else
6 6#include <asm-sparc/siginfo_32.h>
7#include <asm-generic/siginfo.h> 7#endif
8 8#endif
9#define SI_NOINFO 32767 /* no information in siginfo_t */
10
11/*
12 * SIGEMT si_codes
13 */
14#define EMT_TAGOVF (__SI_FAULT|1) /* tag overflow */
15#define NSIGEMT 1
16
17#endif /* !(_SPARC_SIGINFO_H) */
diff --git a/include/asm-sparc/siginfo_32.h b/include/asm-sparc/siginfo_32.h
new file mode 100644
index 000000000000..3c71af135c52
--- /dev/null
+++ b/include/asm-sparc/siginfo_32.h
@@ -0,0 +1,17 @@
1#ifndef _SPARC_SIGINFO_H
2#define _SPARC_SIGINFO_H
3
4#define __ARCH_SI_UID_T unsigned int
5#define __ARCH_SI_TRAPNO
6
7#include <asm-generic/siginfo.h>
8
9#define SI_NOINFO 32767 /* no information in siginfo_t */
10
11/*
12 * SIGEMT si_codes
13 */
14#define EMT_TAGOVF (__SI_FAULT|1) /* tag overflow */
15#define NSIGEMT 1
16
17#endif /* !(_SPARC_SIGINFO_H) */
diff --git a/include/asm-sparc/siginfo_64.h b/include/asm-sparc/siginfo_64.h
new file mode 100644
index 000000000000..c96e6c30f8b0
--- /dev/null
+++ b/include/asm-sparc/siginfo_64.h
@@ -0,0 +1,32 @@
1#ifndef _SPARC64_SIGINFO_H
2#define _SPARC64_SIGINFO_H
3
4#define SI_PAD_SIZE32 ((SI_MAX_SIZE/sizeof(int)) - 3)
5
6#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
7#define __ARCH_SI_TRAPNO
8#define __ARCH_SI_BAND_T int
9
10#include <asm-generic/siginfo.h>
11
12#ifdef __KERNEL__
13
14#include <linux/compat.h>
15
16#ifdef CONFIG_COMPAT
17
18struct compat_siginfo;
19
20#endif /* CONFIG_COMPAT */
21
22#endif /* __KERNEL__ */
23
24#define SI_NOINFO 32767 /* no information in siginfo_t */
25
26/*
27 * SIGEMT si_codes
28 */
29#define EMT_TAGOVF (__SI_FAULT|1) /* tag overflow */
30#define NSIGEMT 1
31
32#endif
diff --git a/include/asm-sparc/signal.h b/include/asm-sparc/signal.h
index 683657d6e685..36f5f9e482f7 100644
--- a/include/asm-sparc/signal.h
+++ b/include/asm-sparc/signal.h
@@ -1,207 +1,8 @@
1#ifndef _ASMSPARC_SIGNAL_H 1#ifndef ___ASM_SPARC_SIGNAL_H
2#define _ASMSPARC_SIGNAL_H 2#define ___ASM_SPARC_SIGNAL_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <asm/sigcontext.h> 4#include <asm-sparc/signal_64.h>
5#include <linux/compiler.h>
6
7#ifdef __KERNEL__
8#ifndef __ASSEMBLY__
9#include <linux/personality.h>
10#include <linux/types.h>
11#endif
12#endif
13
14/* On the Sparc the signal handlers get passed a 'sub-signal' code
15 * for certain signal types, which we document here.
16 */
17#define SIGHUP 1
18#define SIGINT 2
19#define SIGQUIT 3
20#define SIGILL 4
21#define SUBSIG_STACK 0
22#define SUBSIG_ILLINST 2
23#define SUBSIG_PRIVINST 3
24#define SUBSIG_BADTRAP(t) (0x80 + (t))
25
26#define SIGTRAP 5
27#define SIGABRT 6
28#define SIGIOT 6
29
30#define SIGEMT 7
31#define SUBSIG_TAG 10
32
33#define SIGFPE 8
34#define SUBSIG_FPDISABLED 0x400
35#define SUBSIG_FPERROR 0x404
36#define SUBSIG_FPINTOVFL 0x001
37#define SUBSIG_FPSTSIG 0x002
38#define SUBSIG_IDIVZERO 0x014
39#define SUBSIG_FPINEXACT 0x0c4
40#define SUBSIG_FPDIVZERO 0x0c8
41#define SUBSIG_FPUNFLOW 0x0cc
42#define SUBSIG_FPOPERROR 0x0d0
43#define SUBSIG_FPOVFLOW 0x0d4
44
45#define SIGKILL 9
46#define SIGBUS 10
47#define SUBSIG_BUSTIMEOUT 1
48#define SUBSIG_ALIGNMENT 2
49#define SUBSIG_MISCERROR 5
50
51#define SIGSEGV 11
52#define SUBSIG_NOMAPPING 3
53#define SUBSIG_PROTECTION 4
54#define SUBSIG_SEGERROR 5
55
56#define SIGSYS 12
57
58#define SIGPIPE 13
59#define SIGALRM 14
60#define SIGTERM 15
61#define SIGURG 16
62
63/* SunOS values which deviate from the Linux/i386 ones */
64#define SIGSTOP 17
65#define SIGTSTP 18
66#define SIGCONT 19
67#define SIGCHLD 20
68#define SIGTTIN 21
69#define SIGTTOU 22
70#define SIGIO 23
71#define SIGPOLL SIGIO /* SysV name for SIGIO */
72#define SIGXCPU 24
73#define SIGXFSZ 25
74#define SIGVTALRM 26
75#define SIGPROF 27
76#define SIGWINCH 28
77#define SIGLOST 29
78#define SIGPWR SIGLOST
79#define SIGUSR1 30
80#define SIGUSR2 31
81
82/* Most things should be clean enough to redefine this at will, if care
83 * is taken to make libc match.
84 */
85
86#define __OLD_NSIG 32
87#define __NEW_NSIG 64
88#define _NSIG_BPW 32
89#define _NSIG_WORDS (__NEW_NSIG / _NSIG_BPW)
90
91#define SIGRTMIN 32
92#define SIGRTMAX __NEW_NSIG
93
94#if defined(__KERNEL__) || defined(__WANT_POSIX1B_SIGNALS__)
95#define _NSIG __NEW_NSIG
96#define __new_sigset_t sigset_t
97#define __new_sigaction sigaction
98#define __old_sigset_t old_sigset_t
99#define __old_sigaction old_sigaction
100#else 5#else
101#define _NSIG __OLD_NSIG 6#include <asm-sparc/signal_32.h>
102#define __old_sigset_t sigset_t
103#define __old_sigaction sigaction
104#endif
105
106#ifndef __ASSEMBLY__
107
108typedef unsigned long __old_sigset_t;
109
110typedef struct {
111 unsigned long sig[_NSIG_WORDS];
112} __new_sigset_t;
113
114
115#ifdef __KERNEL__
116/* A SunOS sigstack */
117struct sigstack {
118 char *the_stack;
119 int cur_status;
120};
121#endif 7#endif
122
123/* Sigvec flags */
124#define _SV_SSTACK 1u /* This signal handler should use sig-stack */
125#define _SV_INTR 2u /* Sig return should not restart system call */
126#define _SV_RESET 4u /* Set handler to SIG_DFL upon taken signal */
127#define _SV_IGNCHILD 8u /* Do not send SIGCHLD */
128
129/*
130 * sa_flags values: SA_STACK is not currently supported, but will allow the
131 * usage of signal stacks by using the (now obsolete) sa_restorer field in
132 * the sigaction structure as a stack pointer. This is now possible due to
133 * the changes in signal handling. LBT 010493.
134 * SA_RESTART flag to get restarting signals (which were the default long ago)
135 */
136#define SA_NOCLDSTOP _SV_IGNCHILD
137#define SA_STACK _SV_SSTACK
138#define SA_ONSTACK _SV_SSTACK
139#define SA_RESTART _SV_INTR
140#define SA_ONESHOT _SV_RESET
141#define SA_NOMASK 0x20u
142#define SA_NOCLDWAIT 0x100u
143#define SA_SIGINFO 0x200u
144
145#define SIG_BLOCK 0x01 /* for blocking signals */
146#define SIG_UNBLOCK 0x02 /* for unblocking signals */
147#define SIG_SETMASK 0x04 /* for setting the signal mask */
148
149/*
150 * sigaltstack controls
151 */
152#define SS_ONSTACK 1
153#define SS_DISABLE 2
154
155#define MINSIGSTKSZ 4096
156#define SIGSTKSZ 16384
157
158#ifdef __KERNEL__
159/*
160 * DJHR
161 * SA_STATIC_ALLOC is used for the SPARC system to indicate that this
162 * interrupt handler's irq structure should be statically allocated
163 * by the request_irq routine.
164 * The alternative is that arch/sparc/kernel/irq.c has carnal knowledge
165 * of interrupt usage and that sucks. Also without a flag like this
166 * it may be possible for the free_irq routine to attempt to free
167 * statically allocated data.. which is NOT GOOD.
168 *
169 */
170#define SA_STATIC_ALLOC 0x8000
171#endif 8#endif
172
173#include <asm-generic/signal.h>
174
175#ifdef __KERNEL__
176struct __new_sigaction {
177 __sighandler_t sa_handler;
178 unsigned long sa_flags;
179 void (*sa_restorer)(void); /* Not used by Linux/SPARC */
180 __new_sigset_t sa_mask;
181};
182
183struct k_sigaction {
184 struct __new_sigaction sa;
185 void __user *ka_restorer;
186};
187
188struct __old_sigaction {
189 __sighandler_t sa_handler;
190 __old_sigset_t sa_mask;
191 unsigned long sa_flags;
192 void (*sa_restorer) (void); /* not used by Linux/SPARC */
193};
194
195typedef struct sigaltstack {
196 void __user *ss_sp;
197 int ss_flags;
198 size_t ss_size;
199} stack_t;
200
201#define ptrace_signal_deliver(regs, cookie) do { } while (0)
202
203#endif /* !(__KERNEL__) */
204
205#endif /* !(__ASSEMBLY__) */
206
207#endif /* !(_ASMSPARC_SIGNAL_H) */
diff --git a/include/asm-sparc/signal_32.h b/include/asm-sparc/signal_32.h
new file mode 100644
index 000000000000..96a60ab03ca1
--- /dev/null
+++ b/include/asm-sparc/signal_32.h
@@ -0,0 +1,207 @@
1#ifndef _ASMSPARC_SIGNAL_H
2#define _ASMSPARC_SIGNAL_H
3
4#include <asm/sigcontext.h>
5#include <linux/compiler.h>
6
7#ifdef __KERNEL__
8#ifndef __ASSEMBLY__
9#include <linux/personality.h>
10#include <linux/types.h>
11#endif
12#endif
13
14/* On the Sparc the signal handlers get passed a 'sub-signal' code
15 * for certain signal types, which we document here.
16 */
17#define SIGHUP 1
18#define SIGINT 2
19#define SIGQUIT 3
20#define SIGILL 4
21#define SUBSIG_STACK 0
22#define SUBSIG_ILLINST 2
23#define SUBSIG_PRIVINST 3
24#define SUBSIG_BADTRAP(t) (0x80 + (t))
25
26#define SIGTRAP 5
27#define SIGABRT 6
28#define SIGIOT 6
29
30#define SIGEMT 7
31#define SUBSIG_TAG 10
32
33#define SIGFPE 8
34#define SUBSIG_FPDISABLED 0x400
35#define SUBSIG_FPERROR 0x404
36#define SUBSIG_FPINTOVFL 0x001
37#define SUBSIG_FPSTSIG 0x002
38#define SUBSIG_IDIVZERO 0x014
39#define SUBSIG_FPINEXACT 0x0c4
40#define SUBSIG_FPDIVZERO 0x0c8
41#define SUBSIG_FPUNFLOW 0x0cc
42#define SUBSIG_FPOPERROR 0x0d0
43#define SUBSIG_FPOVFLOW 0x0d4
44
45#define SIGKILL 9
46#define SIGBUS 10
47#define SUBSIG_BUSTIMEOUT 1
48#define SUBSIG_ALIGNMENT 2
49#define SUBSIG_MISCERROR 5
50
51#define SIGSEGV 11
52#define SUBSIG_NOMAPPING 3
53#define SUBSIG_PROTECTION 4
54#define SUBSIG_SEGERROR 5
55
56#define SIGSYS 12
57
58#define SIGPIPE 13
59#define SIGALRM 14
60#define SIGTERM 15
61#define SIGURG 16
62
63/* SunOS values which deviate from the Linux/i386 ones */
64#define SIGSTOP 17
65#define SIGTSTP 18
66#define SIGCONT 19
67#define SIGCHLD 20
68#define SIGTTIN 21
69#define SIGTTOU 22
70#define SIGIO 23
71#define SIGPOLL SIGIO /* SysV name for SIGIO */
72#define SIGXCPU 24
73#define SIGXFSZ 25
74#define SIGVTALRM 26
75#define SIGPROF 27
76#define SIGWINCH 28
77#define SIGLOST 29
78#define SIGPWR SIGLOST
79#define SIGUSR1 30
80#define SIGUSR2 31
81
82/* Most things should be clean enough to redefine this at will, if care
83 * is taken to make libc match.
84 */
85
86#define __OLD_NSIG 32
87#define __NEW_NSIG 64
88#define _NSIG_BPW 32
89#define _NSIG_WORDS (__NEW_NSIG / _NSIG_BPW)
90
91#define SIGRTMIN 32
92#define SIGRTMAX __NEW_NSIG
93
94#if defined(__KERNEL__) || defined(__WANT_POSIX1B_SIGNALS__)
95#define _NSIG __NEW_NSIG
96#define __new_sigset_t sigset_t
97#define __new_sigaction sigaction
98#define __old_sigset_t old_sigset_t
99#define __old_sigaction old_sigaction
100#else
101#define _NSIG __OLD_NSIG
102#define __old_sigset_t sigset_t
103#define __old_sigaction sigaction
104#endif
105
106#ifndef __ASSEMBLY__
107
108typedef unsigned long __old_sigset_t;
109
110typedef struct {
111 unsigned long sig[_NSIG_WORDS];
112} __new_sigset_t;
113
114
115#ifdef __KERNEL__
116/* A SunOS sigstack */
117struct sigstack {
118 char *the_stack;
119 int cur_status;
120};
121#endif
122
123/* Sigvec flags */
124#define _SV_SSTACK 1u /* This signal handler should use sig-stack */
125#define _SV_INTR 2u /* Sig return should not restart system call */
126#define _SV_RESET 4u /* Set handler to SIG_DFL upon taken signal */
127#define _SV_IGNCHILD 8u /* Do not send SIGCHLD */
128
129/*
130 * sa_flags values: SA_STACK is not currently supported, but will allow the
131 * usage of signal stacks by using the (now obsolete) sa_restorer field in
132 * the sigaction structure as a stack pointer. This is now possible due to
133 * the changes in signal handling. LBT 010493.
134 * SA_RESTART flag to get restarting signals (which were the default long ago)
135 */
136#define SA_NOCLDSTOP _SV_IGNCHILD
137#define SA_STACK _SV_SSTACK
138#define SA_ONSTACK _SV_SSTACK
139#define SA_RESTART _SV_INTR
140#define SA_ONESHOT _SV_RESET
141#define SA_NOMASK 0x20u
142#define SA_NOCLDWAIT 0x100u
143#define SA_SIGINFO 0x200u
144
145#define SIG_BLOCK 0x01 /* for blocking signals */
146#define SIG_UNBLOCK 0x02 /* for unblocking signals */
147#define SIG_SETMASK 0x04 /* for setting the signal mask */
148
149/*
150 * sigaltstack controls
151 */
152#define SS_ONSTACK 1
153#define SS_DISABLE 2
154
155#define MINSIGSTKSZ 4096
156#define SIGSTKSZ 16384
157
158#ifdef __KERNEL__
159/*
160 * DJHR
161 * SA_STATIC_ALLOC is used for the SPARC system to indicate that this
162 * interrupt handler's irq structure should be statically allocated
163 * by the request_irq routine.
164 * The alternative is that arch/sparc/kernel/irq.c has carnal knowledge
165 * of interrupt usage and that sucks. Also without a flag like this
166 * it may be possible for the free_irq routine to attempt to free
167 * statically allocated data.. which is NOT GOOD.
168 *
169 */
170#define SA_STATIC_ALLOC 0x8000
171#endif
172
173#include <asm-generic/signal.h>
174
175#ifdef __KERNEL__
176struct __new_sigaction {
177 __sighandler_t sa_handler;
178 unsigned long sa_flags;
179 void (*sa_restorer)(void); /* Not used by Linux/SPARC */
180 __new_sigset_t sa_mask;
181};
182
183struct k_sigaction {
184 struct __new_sigaction sa;
185 void __user *ka_restorer;
186};
187
188struct __old_sigaction {
189 __sighandler_t sa_handler;
190 __old_sigset_t sa_mask;
191 unsigned long sa_flags;
192 void (*sa_restorer) (void); /* not used by Linux/SPARC */
193};
194
195typedef struct sigaltstack {
196 void __user *ss_sp;
197 int ss_flags;
198 size_t ss_size;
199} stack_t;
200
201#define ptrace_signal_deliver(regs, cookie) do { } while (0)
202
203#endif /* !(__KERNEL__) */
204
205#endif /* !(__ASSEMBLY__) */
206
207#endif /* !(_ASMSPARC_SIGNAL_H) */
diff --git a/include/asm-sparc/signal_64.h b/include/asm-sparc/signal_64.h
new file mode 100644
index 000000000000..ab1509a101c5
--- /dev/null
+++ b/include/asm-sparc/signal_64.h
@@ -0,0 +1,194 @@
1#ifndef _ASMSPARC64_SIGNAL_H
2#define _ASMSPARC64_SIGNAL_H
3
4#include <asm/sigcontext.h>
5
6#ifdef __KERNEL__
7#ifndef __ASSEMBLY__
8#include <linux/personality.h>
9#include <linux/types.h>
10#endif
11#endif
12
13/* On the Sparc the signal handlers get passed a 'sub-signal' code
14 * for certain signal types, which we document here.
15 */
16#define SIGHUP 1
17#define SIGINT 2
18#define SIGQUIT 3
19#define SIGILL 4
20#define SUBSIG_STACK 0
21#define SUBSIG_ILLINST 2
22#define SUBSIG_PRIVINST 3
23#define SUBSIG_BADTRAP(t) (0x80 + (t))
24
25#define SIGTRAP 5
26#define SIGABRT 6
27#define SIGIOT 6
28
29#define SIGEMT 7
30#define SUBSIG_TAG 10
31
32#define SIGFPE 8
33#define SUBSIG_FPDISABLED 0x400
34#define SUBSIG_FPERROR 0x404
35#define SUBSIG_FPINTOVFL 0x001
36#define SUBSIG_FPSTSIG 0x002
37#define SUBSIG_IDIVZERO 0x014
38#define SUBSIG_FPINEXACT 0x0c4
39#define SUBSIG_FPDIVZERO 0x0c8
40#define SUBSIG_FPUNFLOW 0x0cc
41#define SUBSIG_FPOPERROR 0x0d0
42#define SUBSIG_FPOVFLOW 0x0d4
43
44#define SIGKILL 9
45#define SIGBUS 10
46#define SUBSIG_BUSTIMEOUT 1
47#define SUBSIG_ALIGNMENT 2
48#define SUBSIG_MISCERROR 5
49
50#define SIGSEGV 11
51#define SUBSIG_NOMAPPING 3
52#define SUBSIG_PROTECTION 4
53#define SUBSIG_SEGERROR 5
54
55#define SIGSYS 12
56
57#define SIGPIPE 13
58#define SIGALRM 14
59#define SIGTERM 15
60#define SIGURG 16
61
62/* SunOS values which deviate from the Linux/i386 ones */
63#define SIGSTOP 17
64#define SIGTSTP 18
65#define SIGCONT 19
66#define SIGCHLD 20
67#define SIGTTIN 21
68#define SIGTTOU 22
69#define SIGIO 23
70#define SIGPOLL SIGIO /* SysV name for SIGIO */
71#define SIGXCPU 24
72#define SIGXFSZ 25
73#define SIGVTALRM 26
74#define SIGPROF 27
75#define SIGWINCH 28
76#define SIGLOST 29
77#define SIGPWR SIGLOST
78#define SIGUSR1 30
79#define SIGUSR2 31
80
81/* Most things should be clean enough to redefine this at will, if care
82 is taken to make libc match. */
83
84#define __OLD_NSIG 32
85#define __NEW_NSIG 64
86#define _NSIG_BPW 64
87#define _NSIG_WORDS (__NEW_NSIG / _NSIG_BPW)
88
89#define SIGRTMIN 32
90#define SIGRTMAX __NEW_NSIG
91
92#if defined(__KERNEL__) || defined(__WANT_POSIX1B_SIGNALS__)
93#define _NSIG __NEW_NSIG
94#define __new_sigset_t sigset_t
95#define __new_sigaction sigaction
96#define __new_sigaction32 sigaction32
97#define __old_sigset_t old_sigset_t
98#define __old_sigaction old_sigaction
99#define __old_sigaction32 old_sigaction32
100#else
101#define _NSIG __OLD_NSIG
102#define NSIG _NSIG
103#define __old_sigset_t sigset_t
104#define __old_sigaction sigaction
105#define __old_sigaction32 sigaction32
106#endif
107
108#ifndef __ASSEMBLY__
109
110typedef unsigned long __old_sigset_t; /* at least 32 bits */
111
112typedef struct {
113 unsigned long sig[_NSIG_WORDS];
114} __new_sigset_t;
115
116/* A SunOS sigstack */
117struct sigstack {
118 /* XXX 32-bit pointers pinhead XXX */
119 char *the_stack;
120 int cur_status;
121};
122
123/* Sigvec flags */
124#define _SV_SSTACK 1u /* This signal handler should use sig-stack */
125#define _SV_INTR 2u /* Sig return should not restart system call */
126#define _SV_RESET 4u /* Set handler to SIG_DFL upon taken signal */
127#define _SV_IGNCHILD 8u /* Do not send SIGCHLD */
128
129/*
130 * sa_flags values: SA_STACK is not currently supported, but will allow the
131 * usage of signal stacks by using the (now obsolete) sa_restorer field in
132 * the sigaction structure as a stack pointer. This is now possible due to
133 * the changes in signal handling. LBT 010493.
134 * SA_RESTART flag to get restarting signals (which were the default long ago)
135 */
136#define SA_NOCLDSTOP _SV_IGNCHILD
137#define SA_STACK _SV_SSTACK
138#define SA_ONSTACK _SV_SSTACK
139#define SA_RESTART _SV_INTR
140#define SA_ONESHOT _SV_RESET
141#define SA_NOMASK 0x20u
142#define SA_NOCLDWAIT 0x100u
143#define SA_SIGINFO 0x200u
144
145
146#define SIG_BLOCK 0x01 /* for blocking signals */
147#define SIG_UNBLOCK 0x02 /* for unblocking signals */
148#define SIG_SETMASK 0x04 /* for setting the signal mask */
149
150/*
151 * sigaltstack controls
152 */
153#define SS_ONSTACK 1
154#define SS_DISABLE 2
155
156#define MINSIGSTKSZ 4096
157#define SIGSTKSZ 16384
158
159#include <asm-generic/signal.h>
160
161struct __new_sigaction {
162 __sighandler_t sa_handler;
163 unsigned long sa_flags;
164 __sigrestore_t sa_restorer; /* not used by Linux/SPARC yet */
165 __new_sigset_t sa_mask;
166};
167
168struct __old_sigaction {
169 __sighandler_t sa_handler;
170 __old_sigset_t sa_mask;
171 unsigned long sa_flags;
172 void (*sa_restorer)(void); /* not used by Linux/SPARC yet */
173};
174
175typedef struct sigaltstack {
176 void __user *ss_sp;
177 int ss_flags;
178 size_t ss_size;
179} stack_t;
180
181#ifdef __KERNEL__
182
183struct k_sigaction {
184 struct __new_sigaction sa;
185 void __user *ka_restorer;
186};
187
188#define ptrace_signal_deliver(regs, cookie) do { } while (0)
189
190#endif /* !(__KERNEL__) */
191
192#endif /* !(__ASSEMBLY__) */
193
194#endif /* !(_ASMSPARC64_SIGNAL_H) */
diff --git a/include/asm-sparc/smp.h b/include/asm-sparc/smp.h
index b61e74bea06a..1f9dedfbabd8 100644
--- a/include/asm-sparc/smp.h
+++ b/include/asm-sparc/smp.h
@@ -1,173 +1,8 @@
1/* smp.h: Sparc specific SMP stuff. 1#ifndef ___ASM_SPARC_SMP_H
2 * 2#define ___ASM_SPARC_SMP_H
3 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 3#if defined(__sparc__) && defined(__arch64__)
4 */ 4#include <asm-sparc/smp_64.h>
5
6#ifndef _SPARC_SMP_H
7#define _SPARC_SMP_H
8
9#include <linux/threads.h>
10#include <asm/head.h>
11#include <asm/btfixup.h>
12
13#ifndef __ASSEMBLY__
14
15#include <linux/cpumask.h>
16
17#endif /* __ASSEMBLY__ */
18
19#ifdef CONFIG_SMP
20
21#ifndef __ASSEMBLY__
22
23#include <asm/ptrace.h>
24#include <asm/asi.h>
25#include <asm/atomic.h>
26
27/*
28 * Private routines/data
29 */
30
31extern unsigned char boot_cpu_id;
32extern cpumask_t phys_cpu_present_map;
33#define cpu_possible_map phys_cpu_present_map
34
35typedef void (*smpfunc_t)(unsigned long, unsigned long, unsigned long,
36 unsigned long, unsigned long);
37
38/*
39 * General functions that each host system must provide.
40 */
41
42void sun4m_init_smp(void);
43void sun4d_init_smp(void);
44
45void smp_callin(void);
46void smp_boot_cpus(void);
47void smp_store_cpu_info(int);
48
49struct seq_file;
50void smp_bogo(struct seq_file *);
51void smp_info(struct seq_file *);
52
53BTFIXUPDEF_CALL(void, smp_cross_call, smpfunc_t, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
54BTFIXUPDEF_CALL(int, __hard_smp_processor_id, void)
55BTFIXUPDEF_BLACKBOX(hard_smp_processor_id)
56BTFIXUPDEF_BLACKBOX(load_current)
57
58#define smp_cross_call(func,arg1,arg2,arg3,arg4,arg5) BTFIXUP_CALL(smp_cross_call)(func,arg1,arg2,arg3,arg4,arg5)
59
60static inline void xc0(smpfunc_t func) { smp_cross_call(func, 0, 0, 0, 0, 0); }
61static inline void xc1(smpfunc_t func, unsigned long arg1)
62{ smp_cross_call(func, arg1, 0, 0, 0, 0); }
63static inline void xc2(smpfunc_t func, unsigned long arg1, unsigned long arg2)
64{ smp_cross_call(func, arg1, arg2, 0, 0, 0); }
65static inline void xc3(smpfunc_t func, unsigned long arg1, unsigned long arg2,
66 unsigned long arg3)
67{ smp_cross_call(func, arg1, arg2, arg3, 0, 0); }
68static inline void xc4(smpfunc_t func, unsigned long arg1, unsigned long arg2,
69 unsigned long arg3, unsigned long arg4)
70{ smp_cross_call(func, arg1, arg2, arg3, arg4, 0); }
71static inline void xc5(smpfunc_t func, unsigned long arg1, unsigned long arg2,
72 unsigned long arg3, unsigned long arg4, unsigned long arg5)
73{ smp_cross_call(func, arg1, arg2, arg3, arg4, arg5); }
74
75static inline int smp_call_function(void (*func)(void *info), void *info, int wait)
76{
77 xc1((smpfunc_t)func, (unsigned long)info);
78 return 0;
79}
80
81static inline int cpu_logical_map(int cpu)
82{
83 return cpu;
84}
85
86static inline int hard_smp4m_processor_id(void)
87{
88 int cpuid;
89
90 __asm__ __volatile__("rd %%tbr, %0\n\t"
91 "srl %0, 12, %0\n\t"
92 "and %0, 3, %0\n\t" :
93 "=&r" (cpuid));
94 return cpuid;
95}
96
97static inline int hard_smp4d_processor_id(void)
98{
99 int cpuid;
100
101 __asm__ __volatile__("lda [%%g0] %1, %0\n\t" :
102 "=&r" (cpuid) : "i" (ASI_M_VIKING_TMP1));
103 return cpuid;
104}
105
106#ifndef MODULE
107static inline int hard_smp_processor_id(void)
108{
109 int cpuid;
110
111 /* Black box - sun4m
112 __asm__ __volatile__("rd %%tbr, %0\n\t"
113 "srl %0, 12, %0\n\t"
114 "and %0, 3, %0\n\t" :
115 "=&r" (cpuid));
116 - sun4d
117 __asm__ __volatile__("lda [%g0] ASI_M_VIKING_TMP1, %0\n\t"
118 "nop; nop" :
119 "=&r" (cpuid));
120 See btfixup.h and btfixupprep.c to understand how a blackbox works.
121 */
122 __asm__ __volatile__("sethi %%hi(___b_hard_smp_processor_id), %0\n\t"
123 "sethi %%hi(boot_cpu_id), %0\n\t"
124 "ldub [%0 + %%lo(boot_cpu_id)], %0\n\t" :
125 "=&r" (cpuid));
126 return cpuid;
127}
128#else 5#else
129static inline int hard_smp_processor_id(void) 6#include <asm-sparc/smp_32.h>
130{ 7#endif
131 int cpuid;
132
133 __asm__ __volatile__("mov %%o7, %%g1\n\t"
134 "call ___f___hard_smp_processor_id\n\t"
135 " nop\n\t"
136 "mov %%g2, %0\n\t" : "=r"(cpuid) : : "g1", "g2");
137 return cpuid;
138}
139#endif 8#endif
140
141#define raw_smp_processor_id() (current_thread_info()->cpu)
142
143#define prof_multiplier(__cpu) cpu_data(__cpu).multiplier
144#define prof_counter(__cpu) cpu_data(__cpu).counter
145
146void smp_setup_cpu_possible_map(void);
147
148#endif /* !(__ASSEMBLY__) */
149
150/* Sparc specific messages. */
151#define MSG_CROSS_CALL 0x0005 /* run func on cpus */
152
153/* Empirical PROM processor mailbox constants. If the per-cpu mailbox
154 * contains something other than one of these then the ipi is from
155 * Linux's active_kernel_processor. This facility exists so that
156 * the boot monitor can capture all the other cpus when one catches
157 * a watchdog reset or the user enters the monitor using L1-A keys.
158 */
159#define MBOX_STOPCPU 0xFB
160#define MBOX_IDLECPU 0xFC
161#define MBOX_IDLECPU2 0xFD
162#define MBOX_STOPCPU2 0xFE
163
164#else /* SMP */
165
166#define hard_smp_processor_id() 0
167#define smp_setup_cpu_possible_map() do { } while (0)
168
169#endif /* !(SMP) */
170
171#define NO_PROC_ID 0xFF
172
173#endif /* !(_SPARC_SMP_H) */
diff --git a/include/asm-sparc/smp_32.h b/include/asm-sparc/smp_32.h
new file mode 100644
index 000000000000..7201752cf934
--- /dev/null
+++ b/include/asm-sparc/smp_32.h
@@ -0,0 +1,173 @@
1/* smp.h: Sparc specific SMP stuff.
2 *
3 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
4 */
5
6#ifndef _SPARC_SMP_H
7#define _SPARC_SMP_H
8
9#include <linux/threads.h>
10#include <asm/head.h>
11#include <asm/btfixup.h>
12
13#ifndef __ASSEMBLY__
14
15#include <linux/cpumask.h>
16
17#endif /* __ASSEMBLY__ */
18
19#ifdef CONFIG_SMP
20
21#ifndef __ASSEMBLY__
22
23#include <asm/ptrace.h>
24#include <asm/asi.h>
25#include <asm/atomic.h>
26
27/*
28 * Private routines/data
29 */
30
31extern unsigned char boot_cpu_id;
32extern cpumask_t phys_cpu_present_map;
33#define cpu_possible_map phys_cpu_present_map
34
35typedef void (*smpfunc_t)(unsigned long, unsigned long, unsigned long,
36 unsigned long, unsigned long);
37
38/*
39 * General functions that each host system must provide.
40 */
41
42void sun4m_init_smp(void);
43void sun4d_init_smp(void);
44
45void smp_callin(void);
46void smp_boot_cpus(void);
47void smp_store_cpu_info(int);
48
49struct seq_file;
50void smp_bogo(struct seq_file *);
51void smp_info(struct seq_file *);
52
53BTFIXUPDEF_CALL(void, smp_cross_call, smpfunc_t, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
54BTFIXUPDEF_CALL(int, __hard_smp_processor_id, void)
55BTFIXUPDEF_BLACKBOX(hard_smp_processor_id)
56BTFIXUPDEF_BLACKBOX(load_current)
57
58#define smp_cross_call(func,arg1,arg2,arg3,arg4,arg5) BTFIXUP_CALL(smp_cross_call)(func,arg1,arg2,arg3,arg4,arg5)
59
60static inline void xc0(smpfunc_t func) { smp_cross_call(func, 0, 0, 0, 0, 0); }
61static inline void xc1(smpfunc_t func, unsigned long arg1)
62{ smp_cross_call(func, arg1, 0, 0, 0, 0); }
63static inline void xc2(smpfunc_t func, unsigned long arg1, unsigned long arg2)
64{ smp_cross_call(func, arg1, arg2, 0, 0, 0); }
65static inline void xc3(smpfunc_t func, unsigned long arg1, unsigned long arg2,
66 unsigned long arg3)
67{ smp_cross_call(func, arg1, arg2, arg3, 0, 0); }
68static inline void xc4(smpfunc_t func, unsigned long arg1, unsigned long arg2,
69 unsigned long arg3, unsigned long arg4)
70{ smp_cross_call(func, arg1, arg2, arg3, arg4, 0); }
71static inline void xc5(smpfunc_t func, unsigned long arg1, unsigned long arg2,
72 unsigned long arg3, unsigned long arg4, unsigned long arg5)
73{ smp_cross_call(func, arg1, arg2, arg3, arg4, arg5); }
74
75static inline int smp_call_function(void (*func)(void *info), void *info, int wait)
76{
77 xc1((smpfunc_t)func, (unsigned long)info);
78 return 0;
79}
80
81static inline int cpu_logical_map(int cpu)
82{
83 return cpu;
84}
85
86static inline int hard_smp4m_processor_id(void)
87{
88 int cpuid;
89
90 __asm__ __volatile__("rd %%tbr, %0\n\t"
91 "srl %0, 12, %0\n\t"
92 "and %0, 3, %0\n\t" :
93 "=&r" (cpuid));
94 return cpuid;
95}
96
97static inline int hard_smp4d_processor_id(void)
98{
99 int cpuid;
100
101 __asm__ __volatile__("lda [%%g0] %1, %0\n\t" :
102 "=&r" (cpuid) : "i" (ASI_M_VIKING_TMP1));
103 return cpuid;
104}
105
106#ifndef MODULE
107static inline int hard_smp_processor_id(void)
108{
109 int cpuid;
110
111 /* Black box - sun4m
112 __asm__ __volatile__("rd %%tbr, %0\n\t"
113 "srl %0, 12, %0\n\t"
114 "and %0, 3, %0\n\t" :
115 "=&r" (cpuid));
116 - sun4d
117 __asm__ __volatile__("lda [%g0] ASI_M_VIKING_TMP1, %0\n\t"
118 "nop; nop" :
119 "=&r" (cpuid));
120 See btfixup.h and btfixupprep.c to understand how a blackbox works.
121 */
122 __asm__ __volatile__("sethi %%hi(___b_hard_smp_processor_id), %0\n\t"
123 "sethi %%hi(boot_cpu_id), %0\n\t"
124 "ldub [%0 + %%lo(boot_cpu_id)], %0\n\t" :
125 "=&r" (cpuid));
126 return cpuid;
127}
128#else
129static inline int hard_smp_processor_id(void)
130{
131 int cpuid;
132
133 __asm__ __volatile__("mov %%o7, %%g1\n\t"
134 "call ___f___hard_smp_processor_id\n\t"
135 " nop\n\t"
136 "mov %%g2, %0\n\t" : "=r"(cpuid) : : "g1", "g2");
137 return cpuid;
138}
139#endif
140
141#define raw_smp_processor_id() (current_thread_info()->cpu)
142
143#define prof_multiplier(__cpu) cpu_data(__cpu).multiplier
144#define prof_counter(__cpu) cpu_data(__cpu).counter
145
146void smp_setup_cpu_possible_map(void);
147
148#endif /* !(__ASSEMBLY__) */
149
150/* Sparc specific messages. */
151#define MSG_CROSS_CALL 0x0005 /* run func on cpus */
152
153/* Empirical PROM processor mailbox constants. If the per-cpu mailbox
154 * contains something other than one of these then the ipi is from
155 * Linux's active_kernel_processor. This facility exists so that
156 * the boot monitor can capture all the other cpus when one catches
157 * a watchdog reset or the user enters the monitor using L1-A keys.
158 */
159#define MBOX_STOPCPU 0xFB
160#define MBOX_IDLECPU 0xFC
161#define MBOX_IDLECPU2 0xFD
162#define MBOX_STOPCPU2 0xFE
163
164#else /* SMP */
165
166#define hard_smp_processor_id() 0
167#define smp_setup_cpu_possible_map() do { } while (0)
168
169#endif /* !(SMP) */
170
171#define NO_PROC_ID 0xFF
172
173#endif /* !(_SPARC_SMP_H) */
diff --git a/include/asm-sparc/smp_64.h b/include/asm-sparc/smp_64.h
new file mode 100644
index 000000000000..57224dd37b3a
--- /dev/null
+++ b/include/asm-sparc/smp_64.h
@@ -0,0 +1,67 @@
1/* smp.h: Sparc64 specific SMP stuff.
2 *
3 * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_SMP_H
7#define _SPARC64_SMP_H
8
9#include <linux/threads.h>
10#include <asm/asi.h>
11#include <asm/starfire.h>
12#include <asm/spitfire.h>
13
14#ifndef __ASSEMBLY__
15
16#include <linux/cpumask.h>
17#include <linux/cache.h>
18
19#endif /* !(__ASSEMBLY__) */
20
21#ifdef CONFIG_SMP
22
23#ifndef __ASSEMBLY__
24
25/*
26 * Private routines/data
27 */
28
29#include <linux/bitops.h>
30#include <asm/atomic.h>
31#include <asm/percpu.h>
32
33DECLARE_PER_CPU(cpumask_t, cpu_sibling_map);
34extern cpumask_t cpu_core_map[NR_CPUS];
35extern int sparc64_multi_core;
36
37extern void arch_send_call_function_single_ipi(int cpu);
38extern void arch_send_call_function_ipi(cpumask_t mask);
39
40/*
41 * General functions that each host system must provide.
42 */
43
44extern int hard_smp_processor_id(void);
45#define raw_smp_processor_id() (current_thread_info()->cpu)
46
47extern void smp_fill_in_sib_core_maps(void);
48extern void cpu_play_dead(void);
49
50extern void smp_fetch_global_regs(void);
51
52#ifdef CONFIG_HOTPLUG_CPU
53extern int __cpu_disable(void);
54extern void __cpu_die(unsigned int cpu);
55#endif
56
57#endif /* !(__ASSEMBLY__) */
58
59#else
60
61#define hard_smp_processor_id() 0
62#define smp_fill_in_sib_core_maps() do { } while (0)
63#define smp_fetch_global_regs() do { } while (0)
64
65#endif /* !(CONFIG_SMP) */
66
67#endif /* !(_SPARC64_SMP_H) */
diff --git a/include/asm-sparc/sparsemem.h b/include/asm-sparc/sparsemem.h
new file mode 100644
index 000000000000..b99d4e4b6d28
--- /dev/null
+++ b/include/asm-sparc/sparsemem.h
@@ -0,0 +1,12 @@
1#ifndef _SPARC64_SPARSEMEM_H
2#define _SPARC64_SPARSEMEM_H
3
4#ifdef __KERNEL__
5
6#define SECTION_SIZE_BITS 30
7#define MAX_PHYSADDR_BITS 42
8#define MAX_PHYSMEM_BITS 42
9
10#endif /* !(__KERNEL__) */
11
12#endif /* !(_SPARC64_SPARSEMEM_H) */
diff --git a/include/asm-sparc/spinlock.h b/include/asm-sparc/spinlock.h
index de2249b267c6..3b71c50b72eb 100644
--- a/include/asm-sparc/spinlock.h
+++ b/include/asm-sparc/spinlock.h
@@ -1,192 +1,8 @@
1/* spinlock.h: 32-bit Sparc spinlock support. 1#ifndef ___ASM_SPARC_SPINLOCK_H
2 * 2#define ___ASM_SPARC_SPINLOCK_H
3 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) 3#if defined(__sparc__) && defined(__arch64__)
4 */ 4#include <asm-sparc/spinlock_64.h>
5 5#else
6#ifndef __SPARC_SPINLOCK_H 6#include <asm-sparc/spinlock_32.h>
7#define __SPARC_SPINLOCK_H 7#endif
8 8#endif
9#include <linux/threads.h> /* For NR_CPUS */
10
11#ifndef __ASSEMBLY__
12
13#include <asm/psr.h>
14
15#define __raw_spin_is_locked(lock) (*((volatile unsigned char *)(lock)) != 0)
16
17#define __raw_spin_unlock_wait(lock) \
18 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
19
20static inline void __raw_spin_lock(raw_spinlock_t *lock)
21{
22 __asm__ __volatile__(
23 "\n1:\n\t"
24 "ldstub [%0], %%g2\n\t"
25 "orcc %%g2, 0x0, %%g0\n\t"
26 "bne,a 2f\n\t"
27 " ldub [%0], %%g2\n\t"
28 ".subsection 2\n"
29 "2:\n\t"
30 "orcc %%g2, 0x0, %%g0\n\t"
31 "bne,a 2b\n\t"
32 " ldub [%0], %%g2\n\t"
33 "b,a 1b\n\t"
34 ".previous\n"
35 : /* no outputs */
36 : "r" (lock)
37 : "g2", "memory", "cc");
38}
39
40static inline int __raw_spin_trylock(raw_spinlock_t *lock)
41{
42 unsigned int result;
43 __asm__ __volatile__("ldstub [%1], %0"
44 : "=r" (result)
45 : "r" (lock)
46 : "memory");
47 return (result == 0);
48}
49
50static inline void __raw_spin_unlock(raw_spinlock_t *lock)
51{
52 __asm__ __volatile__("stb %%g0, [%0]" : : "r" (lock) : "memory");
53}
54
55/* Read-write spinlocks, allowing multiple readers
56 * but only one writer.
57 *
58 * NOTE! it is quite common to have readers in interrupts
59 * but no interrupt writers. For those circumstances we
60 * can "mix" irq-safe locks - any writer needs to get a
61 * irq-safe write-lock, but readers can get non-irqsafe
62 * read-locks.
63 *
64 * XXX This might create some problems with my dual spinlock
65 * XXX scheme, deadlocks etc. -DaveM
66 *
67 * Sort of like atomic_t's on Sparc, but even more clever.
68 *
69 * ------------------------------------
70 * | 24-bit counter | wlock | raw_rwlock_t
71 * ------------------------------------
72 * 31 8 7 0
73 *
74 * wlock signifies the one writer is in or somebody is updating
75 * counter. For a writer, if he successfully acquires the wlock,
76 * but counter is non-zero, he has to release the lock and wait,
77 * till both counter and wlock are zero.
78 *
79 * Unfortunately this scheme limits us to ~16,000,000 cpus.
80 */
81static inline void __read_lock(raw_rwlock_t *rw)
82{
83 register raw_rwlock_t *lp asm("g1");
84 lp = rw;
85 __asm__ __volatile__(
86 "mov %%o7, %%g4\n\t"
87 "call ___rw_read_enter\n\t"
88 " ldstub [%%g1 + 3], %%g2\n"
89 : /* no outputs */
90 : "r" (lp)
91 : "g2", "g4", "memory", "cc");
92}
93
94#define __raw_read_lock(lock) \
95do { unsigned long flags; \
96 local_irq_save(flags); \
97 __read_lock(lock); \
98 local_irq_restore(flags); \
99} while(0)
100
101static inline void __read_unlock(raw_rwlock_t *rw)
102{
103 register raw_rwlock_t *lp asm("g1");
104 lp = rw;
105 __asm__ __volatile__(
106 "mov %%o7, %%g4\n\t"
107 "call ___rw_read_exit\n\t"
108 " ldstub [%%g1 + 3], %%g2\n"
109 : /* no outputs */
110 : "r" (lp)
111 : "g2", "g4", "memory", "cc");
112}
113
114#define __raw_read_unlock(lock) \
115do { unsigned long flags; \
116 local_irq_save(flags); \
117 __read_unlock(lock); \
118 local_irq_restore(flags); \
119} while(0)
120
121static inline void __raw_write_lock(raw_rwlock_t *rw)
122{
123 register raw_rwlock_t *lp asm("g1");
124 lp = rw;
125 __asm__ __volatile__(
126 "mov %%o7, %%g4\n\t"
127 "call ___rw_write_enter\n\t"
128 " ldstub [%%g1 + 3], %%g2\n"
129 : /* no outputs */
130 : "r" (lp)
131 : "g2", "g4", "memory", "cc");
132 *(volatile __u32 *)&lp->lock = ~0U;
133}
134
135static inline int __raw_write_trylock(raw_rwlock_t *rw)
136{
137 unsigned int val;
138
139 __asm__ __volatile__("ldstub [%1 + 3], %0"
140 : "=r" (val)
141 : "r" (&rw->lock)
142 : "memory");
143
144 if (val == 0) {
145 val = rw->lock & ~0xff;
146 if (val)
147 ((volatile u8*)&rw->lock)[3] = 0;
148 else
149 *(volatile u32*)&rw->lock = ~0U;
150 }
151
152 return (val == 0);
153}
154
155static inline int __read_trylock(raw_rwlock_t *rw)
156{
157 register raw_rwlock_t *lp asm("g1");
158 register int res asm("o0");
159 lp = rw;
160 __asm__ __volatile__(
161 "mov %%o7, %%g4\n\t"
162 "call ___rw_read_try\n\t"
163 " ldstub [%%g1 + 3], %%g2\n"
164 : "=r" (res)
165 : "r" (lp)
166 : "g2", "g4", "memory", "cc");
167 return res;
168}
169
170#define __raw_read_trylock(lock) \
171({ unsigned long flags; \
172 int res; \
173 local_irq_save(flags); \
174 res = __read_trylock(lock); \
175 local_irq_restore(flags); \
176 res; \
177})
178
179#define __raw_write_unlock(rw) do { (rw)->lock = 0; } while(0)
180
181#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
182
183#define _raw_spin_relax(lock) cpu_relax()
184#define _raw_read_relax(lock) cpu_relax()
185#define _raw_write_relax(lock) cpu_relax()
186
187#define __raw_read_can_lock(rw) (!((rw)->lock & 0xff))
188#define __raw_write_can_lock(rw) (!(rw)->lock)
189
190#endif /* !(__ASSEMBLY__) */
191
192#endif /* __SPARC_SPINLOCK_H */
diff --git a/include/asm-sparc/spinlock_32.h b/include/asm-sparc/spinlock_32.h
new file mode 100644
index 000000000000..de2249b267c6
--- /dev/null
+++ b/include/asm-sparc/spinlock_32.h
@@ -0,0 +1,192 @@
1/* spinlock.h: 32-bit Sparc spinlock support.
2 *
3 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
4 */
5
6#ifndef __SPARC_SPINLOCK_H
7#define __SPARC_SPINLOCK_H
8
9#include <linux/threads.h> /* For NR_CPUS */
10
11#ifndef __ASSEMBLY__
12
13#include <asm/psr.h>
14
15#define __raw_spin_is_locked(lock) (*((volatile unsigned char *)(lock)) != 0)
16
17#define __raw_spin_unlock_wait(lock) \
18 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
19
20static inline void __raw_spin_lock(raw_spinlock_t *lock)
21{
22 __asm__ __volatile__(
23 "\n1:\n\t"
24 "ldstub [%0], %%g2\n\t"
25 "orcc %%g2, 0x0, %%g0\n\t"
26 "bne,a 2f\n\t"
27 " ldub [%0], %%g2\n\t"
28 ".subsection 2\n"
29 "2:\n\t"
30 "orcc %%g2, 0x0, %%g0\n\t"
31 "bne,a 2b\n\t"
32 " ldub [%0], %%g2\n\t"
33 "b,a 1b\n\t"
34 ".previous\n"
35 : /* no outputs */
36 : "r" (lock)
37 : "g2", "memory", "cc");
38}
39
40static inline int __raw_spin_trylock(raw_spinlock_t *lock)
41{
42 unsigned int result;
43 __asm__ __volatile__("ldstub [%1], %0"
44 : "=r" (result)
45 : "r" (lock)
46 : "memory");
47 return (result == 0);
48}
49
50static inline void __raw_spin_unlock(raw_spinlock_t *lock)
51{
52 __asm__ __volatile__("stb %%g0, [%0]" : : "r" (lock) : "memory");
53}
54
55/* Read-write spinlocks, allowing multiple readers
56 * but only one writer.
57 *
58 * NOTE! it is quite common to have readers in interrupts
59 * but no interrupt writers. For those circumstances we
60 * can "mix" irq-safe locks - any writer needs to get a
61 * irq-safe write-lock, but readers can get non-irqsafe
62 * read-locks.
63 *
64 * XXX This might create some problems with my dual spinlock
65 * XXX scheme, deadlocks etc. -DaveM
66 *
67 * Sort of like atomic_t's on Sparc, but even more clever.
68 *
69 * ------------------------------------
70 * | 24-bit counter | wlock | raw_rwlock_t
71 * ------------------------------------
72 * 31 8 7 0
73 *
74 * wlock signifies the one writer is in or somebody is updating
75 * counter. For a writer, if he successfully acquires the wlock,
76 * but counter is non-zero, he has to release the lock and wait,
77 * till both counter and wlock are zero.
78 *
79 * Unfortunately this scheme limits us to ~16,000,000 cpus.
80 */
81static inline void __read_lock(raw_rwlock_t *rw)
82{
83 register raw_rwlock_t *lp asm("g1");
84 lp = rw;
85 __asm__ __volatile__(
86 "mov %%o7, %%g4\n\t"
87 "call ___rw_read_enter\n\t"
88 " ldstub [%%g1 + 3], %%g2\n"
89 : /* no outputs */
90 : "r" (lp)
91 : "g2", "g4", "memory", "cc");
92}
93
94#define __raw_read_lock(lock) \
95do { unsigned long flags; \
96 local_irq_save(flags); \
97 __read_lock(lock); \
98 local_irq_restore(flags); \
99} while(0)
100
101static inline void __read_unlock(raw_rwlock_t *rw)
102{
103 register raw_rwlock_t *lp asm("g1");
104 lp = rw;
105 __asm__ __volatile__(
106 "mov %%o7, %%g4\n\t"
107 "call ___rw_read_exit\n\t"
108 " ldstub [%%g1 + 3], %%g2\n"
109 : /* no outputs */
110 : "r" (lp)
111 : "g2", "g4", "memory", "cc");
112}
113
114#define __raw_read_unlock(lock) \
115do { unsigned long flags; \
116 local_irq_save(flags); \
117 __read_unlock(lock); \
118 local_irq_restore(flags); \
119} while(0)
120
121static inline void __raw_write_lock(raw_rwlock_t *rw)
122{
123 register raw_rwlock_t *lp asm("g1");
124 lp = rw;
125 __asm__ __volatile__(
126 "mov %%o7, %%g4\n\t"
127 "call ___rw_write_enter\n\t"
128 " ldstub [%%g1 + 3], %%g2\n"
129 : /* no outputs */
130 : "r" (lp)
131 : "g2", "g4", "memory", "cc");
132 *(volatile __u32 *)&lp->lock = ~0U;
133}
134
135static inline int __raw_write_trylock(raw_rwlock_t *rw)
136{
137 unsigned int val;
138
139 __asm__ __volatile__("ldstub [%1 + 3], %0"
140 : "=r" (val)
141 : "r" (&rw->lock)
142 : "memory");
143
144 if (val == 0) {
145 val = rw->lock & ~0xff;
146 if (val)
147 ((volatile u8*)&rw->lock)[3] = 0;
148 else
149 *(volatile u32*)&rw->lock = ~0U;
150 }
151
152 return (val == 0);
153}
154
155static inline int __read_trylock(raw_rwlock_t *rw)
156{
157 register raw_rwlock_t *lp asm("g1");
158 register int res asm("o0");
159 lp = rw;
160 __asm__ __volatile__(
161 "mov %%o7, %%g4\n\t"
162 "call ___rw_read_try\n\t"
163 " ldstub [%%g1 + 3], %%g2\n"
164 : "=r" (res)
165 : "r" (lp)
166 : "g2", "g4", "memory", "cc");
167 return res;
168}
169
170#define __raw_read_trylock(lock) \
171({ unsigned long flags; \
172 int res; \
173 local_irq_save(flags); \
174 res = __read_trylock(lock); \
175 local_irq_restore(flags); \
176 res; \
177})
178
179#define __raw_write_unlock(rw) do { (rw)->lock = 0; } while(0)
180
181#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
182
183#define _raw_spin_relax(lock) cpu_relax()
184#define _raw_read_relax(lock) cpu_relax()
185#define _raw_write_relax(lock) cpu_relax()
186
187#define __raw_read_can_lock(rw) (!((rw)->lock & 0xff))
188#define __raw_write_can_lock(rw) (!(rw)->lock)
189
190#endif /* !(__ASSEMBLY__) */
191
192#endif /* __SPARC_SPINLOCK_H */
diff --git a/include/asm-sparc/spinlock_64.h b/include/asm-sparc/spinlock_64.h
new file mode 100644
index 000000000000..0006fe9f8c7a
--- /dev/null
+++ b/include/asm-sparc/spinlock_64.h
@@ -0,0 +1,250 @@
1/* spinlock.h: 64-bit Sparc spinlock support.
2 *
3 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
4 */
5
6#ifndef __SPARC64_SPINLOCK_H
7#define __SPARC64_SPINLOCK_H
8
9#include <linux/threads.h> /* For NR_CPUS */
10
11#ifndef __ASSEMBLY__
12
13/* To get debugging spinlocks which detect and catch
14 * deadlock situations, set CONFIG_DEBUG_SPINLOCK
15 * and rebuild your kernel.
16 */
17
18/* All of these locking primitives are expected to work properly
19 * even in an RMO memory model, which currently is what the kernel
20 * runs in.
21 *
22 * There is another issue. Because we play games to save cycles
23 * in the non-contention case, we need to be extra careful about
24 * branch targets into the "spinning" code. They live in their
25 * own section, but the newer V9 branches have a shorter range
26 * than the traditional 32-bit sparc branch variants. The rule
27 * is that the branches that go into and out of the spinner sections
28 * must be pre-V9 branches.
29 */
30
31#define __raw_spin_is_locked(lp) ((lp)->lock != 0)
32
33#define __raw_spin_unlock_wait(lp) \
34 do { rmb(); \
35 } while((lp)->lock)
36
37static inline void __raw_spin_lock(raw_spinlock_t *lock)
38{
39 unsigned long tmp;
40
41 __asm__ __volatile__(
42"1: ldstub [%1], %0\n"
43" membar #StoreLoad | #StoreStore\n"
44" brnz,pn %0, 2f\n"
45" nop\n"
46" .subsection 2\n"
47"2: ldub [%1], %0\n"
48" membar #LoadLoad\n"
49" brnz,pt %0, 2b\n"
50" nop\n"
51" ba,a,pt %%xcc, 1b\n"
52" .previous"
53 : "=&r" (tmp)
54 : "r" (lock)
55 : "memory");
56}
57
58static inline int __raw_spin_trylock(raw_spinlock_t *lock)
59{
60 unsigned long result;
61
62 __asm__ __volatile__(
63" ldstub [%1], %0\n"
64" membar #StoreLoad | #StoreStore"
65 : "=r" (result)
66 : "r" (lock)
67 : "memory");
68
69 return (result == 0UL);
70}
71
72static inline void __raw_spin_unlock(raw_spinlock_t *lock)
73{
74 __asm__ __volatile__(
75" membar #StoreStore | #LoadStore\n"
76" stb %%g0, [%0]"
77 : /* No outputs */
78 : "r" (lock)
79 : "memory");
80}
81
82static inline void __raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
83{
84 unsigned long tmp1, tmp2;
85
86 __asm__ __volatile__(
87"1: ldstub [%2], %0\n"
88" membar #StoreLoad | #StoreStore\n"
89" brnz,pn %0, 2f\n"
90" nop\n"
91" .subsection 2\n"
92"2: rdpr %%pil, %1\n"
93" wrpr %3, %%pil\n"
94"3: ldub [%2], %0\n"
95" membar #LoadLoad\n"
96" brnz,pt %0, 3b\n"
97" nop\n"
98" ba,pt %%xcc, 1b\n"
99" wrpr %1, %%pil\n"
100" .previous"
101 : "=&r" (tmp1), "=&r" (tmp2)
102 : "r"(lock), "r"(flags)
103 : "memory");
104}
105
106/* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
107
108static void inline __read_lock(raw_rwlock_t *lock)
109{
110 unsigned long tmp1, tmp2;
111
112 __asm__ __volatile__ (
113"1: ldsw [%2], %0\n"
114" brlz,pn %0, 2f\n"
115"4: add %0, 1, %1\n"
116" cas [%2], %0, %1\n"
117" cmp %0, %1\n"
118" membar #StoreLoad | #StoreStore\n"
119" bne,pn %%icc, 1b\n"
120" nop\n"
121" .subsection 2\n"
122"2: ldsw [%2], %0\n"
123" membar #LoadLoad\n"
124" brlz,pt %0, 2b\n"
125" nop\n"
126" ba,a,pt %%xcc, 4b\n"
127" .previous"
128 : "=&r" (tmp1), "=&r" (tmp2)
129 : "r" (lock)
130 : "memory");
131}
132
133static int inline __read_trylock(raw_rwlock_t *lock)
134{
135 int tmp1, tmp2;
136
137 __asm__ __volatile__ (
138"1: ldsw [%2], %0\n"
139" brlz,a,pn %0, 2f\n"
140" mov 0, %0\n"
141" add %0, 1, %1\n"
142" cas [%2], %0, %1\n"
143" cmp %0, %1\n"
144" membar #StoreLoad | #StoreStore\n"
145" bne,pn %%icc, 1b\n"
146" mov 1, %0\n"
147"2:"
148 : "=&r" (tmp1), "=&r" (tmp2)
149 : "r" (lock)
150 : "memory");
151
152 return tmp1;
153}
154
155static void inline __read_unlock(raw_rwlock_t *lock)
156{
157 unsigned long tmp1, tmp2;
158
159 __asm__ __volatile__(
160" membar #StoreLoad | #LoadLoad\n"
161"1: lduw [%2], %0\n"
162" sub %0, 1, %1\n"
163" cas [%2], %0, %1\n"
164" cmp %0, %1\n"
165" bne,pn %%xcc, 1b\n"
166" nop"
167 : "=&r" (tmp1), "=&r" (tmp2)
168 : "r" (lock)
169 : "memory");
170}
171
172static void inline __write_lock(raw_rwlock_t *lock)
173{
174 unsigned long mask, tmp1, tmp2;
175
176 mask = 0x80000000UL;
177
178 __asm__ __volatile__(
179"1: lduw [%2], %0\n"
180" brnz,pn %0, 2f\n"
181"4: or %0, %3, %1\n"
182" cas [%2], %0, %1\n"
183" cmp %0, %1\n"
184" membar #StoreLoad | #StoreStore\n"
185" bne,pn %%icc, 1b\n"
186" nop\n"
187" .subsection 2\n"
188"2: lduw [%2], %0\n"
189" membar #LoadLoad\n"
190" brnz,pt %0, 2b\n"
191" nop\n"
192" ba,a,pt %%xcc, 4b\n"
193" .previous"
194 : "=&r" (tmp1), "=&r" (tmp2)
195 : "r" (lock), "r" (mask)
196 : "memory");
197}
198
199static void inline __write_unlock(raw_rwlock_t *lock)
200{
201 __asm__ __volatile__(
202" membar #LoadStore | #StoreStore\n"
203" stw %%g0, [%0]"
204 : /* no outputs */
205 : "r" (lock)
206 : "memory");
207}
208
209static int inline __write_trylock(raw_rwlock_t *lock)
210{
211 unsigned long mask, tmp1, tmp2, result;
212
213 mask = 0x80000000UL;
214
215 __asm__ __volatile__(
216" mov 0, %2\n"
217"1: lduw [%3], %0\n"
218" brnz,pn %0, 2f\n"
219" or %0, %4, %1\n"
220" cas [%3], %0, %1\n"
221" cmp %0, %1\n"
222" membar #StoreLoad | #StoreStore\n"
223" bne,pn %%icc, 1b\n"
224" nop\n"
225" mov 1, %2\n"
226"2:"
227 : "=&r" (tmp1), "=&r" (tmp2), "=&r" (result)
228 : "r" (lock), "r" (mask)
229 : "memory");
230
231 return result;
232}
233
234#define __raw_read_lock(p) __read_lock(p)
235#define __raw_read_trylock(p) __read_trylock(p)
236#define __raw_read_unlock(p) __read_unlock(p)
237#define __raw_write_lock(p) __write_lock(p)
238#define __raw_write_unlock(p) __write_unlock(p)
239#define __raw_write_trylock(p) __write_trylock(p)
240
241#define __raw_read_can_lock(rw) (!((rw)->lock & 0x80000000UL))
242#define __raw_write_can_lock(rw) (!(rw)->lock)
243
244#define _raw_spin_relax(lock) cpu_relax()
245#define _raw_read_relax(lock) cpu_relax()
246#define _raw_write_relax(lock) cpu_relax()
247
248#endif /* !(__ASSEMBLY__) */
249
250#endif /* !(__SPARC64_SPINLOCK_H) */
diff --git a/include/asm-sparc/spinlock_types.h b/include/asm-sparc/spinlock_types.h
index 0a0fb116c4ec..37cbe01c585b 100644
--- a/include/asm-sparc/spinlock_types.h
+++ b/include/asm-sparc/spinlock_types.h
@@ -6,7 +6,7 @@
6#endif 6#endif
7 7
8typedef struct { 8typedef struct {
9 unsigned char lock; 9 volatile unsigned char lock;
10} raw_spinlock_t; 10} raw_spinlock_t;
11 11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 } 12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
diff --git a/include/asm-sparc/spitfire.h b/include/asm-sparc/spitfire.h
new file mode 100644
index 000000000000..985ea7e31992
--- /dev/null
+++ b/include/asm-sparc/spitfire.h
@@ -0,0 +1,342 @@
1/* spitfire.h: SpitFire/BlackBird/Cheetah inline MMU operations.
2 *
3 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_SPITFIRE_H
7#define _SPARC64_SPITFIRE_H
8
9#include <asm/asi.h>
10
11/* The following register addresses are accessible via ASI_DMMU
12 * and ASI_IMMU, that is there is a distinct and unique copy of
13 * each these registers for each TLB.
14 */
15#define TSB_TAG_TARGET 0x0000000000000000 /* All chips */
16#define TLB_SFSR 0x0000000000000018 /* All chips */
17#define TSB_REG 0x0000000000000028 /* All chips */
18#define TLB_TAG_ACCESS 0x0000000000000030 /* All chips */
19#define VIRT_WATCHPOINT 0x0000000000000038 /* All chips */
20#define PHYS_WATCHPOINT 0x0000000000000040 /* All chips */
21#define TSB_EXTENSION_P 0x0000000000000048 /* Ultra-III and later */
22#define TSB_EXTENSION_S 0x0000000000000050 /* Ultra-III and later, D-TLB only */
23#define TSB_EXTENSION_N 0x0000000000000058 /* Ultra-III and later */
24#define TLB_TAG_ACCESS_EXT 0x0000000000000060 /* Ultra-III+ and later */
25
26/* These registers only exist as one entity, and are accessed
27 * via ASI_DMMU only.
28 */
29#define PRIMARY_CONTEXT 0x0000000000000008
30#define SECONDARY_CONTEXT 0x0000000000000010
31#define DMMU_SFAR 0x0000000000000020
32#define VIRT_WATCHPOINT 0x0000000000000038
33#define PHYS_WATCHPOINT 0x0000000000000040
34
35#define SPITFIRE_HIGHEST_LOCKED_TLBENT (64 - 1)
36#define CHEETAH_HIGHEST_LOCKED_TLBENT (16 - 1)
37
38#define L1DCACHE_SIZE 0x4000
39
40#define SUN4V_CHIP_INVALID 0x00
41#define SUN4V_CHIP_NIAGARA1 0x01
42#define SUN4V_CHIP_NIAGARA2 0x02
43#define SUN4V_CHIP_UNKNOWN 0xff
44
45#ifndef __ASSEMBLY__
46
47enum ultra_tlb_layout {
48 spitfire = 0,
49 cheetah = 1,
50 cheetah_plus = 2,
51 hypervisor = 3,
52};
53
54extern enum ultra_tlb_layout tlb_type;
55
56extern int sun4v_chip_type;
57
58extern int cheetah_pcache_forced_on;
59extern void cheetah_enable_pcache(void);
60
61#define sparc64_highest_locked_tlbent() \
62 (tlb_type == spitfire ? \
63 SPITFIRE_HIGHEST_LOCKED_TLBENT : \
64 CHEETAH_HIGHEST_LOCKED_TLBENT)
65
66extern int num_kernel_image_mappings;
67
68/* The data cache is write through, so this just invalidates the
69 * specified line.
70 */
71static inline void spitfire_put_dcache_tag(unsigned long addr, unsigned long tag)
72{
73 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
74 "membar #Sync"
75 : /* No outputs */
76 : "r" (tag), "r" (addr), "i" (ASI_DCACHE_TAG));
77}
78
79/* The instruction cache lines are flushed with this, but note that
80 * this does not flush the pipeline. It is possible for a line to
81 * get flushed but stale instructions to still be in the pipeline,
82 * a flush instruction (to any address) is sufficient to handle
83 * this issue after the line is invalidated.
84 */
85static inline void spitfire_put_icache_tag(unsigned long addr, unsigned long tag)
86{
87 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
88 "membar #Sync"
89 : /* No outputs */
90 : "r" (tag), "r" (addr), "i" (ASI_IC_TAG));
91}
92
93static inline unsigned long spitfire_get_dtlb_data(int entry)
94{
95 unsigned long data;
96
97 __asm__ __volatile__("ldxa [%1] %2, %0"
98 : "=r" (data)
99 : "r" (entry << 3), "i" (ASI_DTLB_DATA_ACCESS));
100
101 /* Clear TTE diag bits. */
102 data &= ~0x0003fe0000000000UL;
103
104 return data;
105}
106
107static inline unsigned long spitfire_get_dtlb_tag(int entry)
108{
109 unsigned long tag;
110
111 __asm__ __volatile__("ldxa [%1] %2, %0"
112 : "=r" (tag)
113 : "r" (entry << 3), "i" (ASI_DTLB_TAG_READ));
114 return tag;
115}
116
117static inline void spitfire_put_dtlb_data(int entry, unsigned long data)
118{
119 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
120 "membar #Sync"
121 : /* No outputs */
122 : "r" (data), "r" (entry << 3),
123 "i" (ASI_DTLB_DATA_ACCESS));
124}
125
126static inline unsigned long spitfire_get_itlb_data(int entry)
127{
128 unsigned long data;
129
130 __asm__ __volatile__("ldxa [%1] %2, %0"
131 : "=r" (data)
132 : "r" (entry << 3), "i" (ASI_ITLB_DATA_ACCESS));
133
134 /* Clear TTE diag bits. */
135 data &= ~0x0003fe0000000000UL;
136
137 return data;
138}
139
140static inline unsigned long spitfire_get_itlb_tag(int entry)
141{
142 unsigned long tag;
143
144 __asm__ __volatile__("ldxa [%1] %2, %0"
145 : "=r" (tag)
146 : "r" (entry << 3), "i" (ASI_ITLB_TAG_READ));
147 return tag;
148}
149
150static inline void spitfire_put_itlb_data(int entry, unsigned long data)
151{
152 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
153 "membar #Sync"
154 : /* No outputs */
155 : "r" (data), "r" (entry << 3),
156 "i" (ASI_ITLB_DATA_ACCESS));
157}
158
159static inline void spitfire_flush_dtlb_nucleus_page(unsigned long page)
160{
161 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
162 "membar #Sync"
163 : /* No outputs */
164 : "r" (page | 0x20), "i" (ASI_DMMU_DEMAP));
165}
166
167static inline void spitfire_flush_itlb_nucleus_page(unsigned long page)
168{
169 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
170 "membar #Sync"
171 : /* No outputs */
172 : "r" (page | 0x20), "i" (ASI_IMMU_DEMAP));
173}
174
175/* Cheetah has "all non-locked" tlb flushes. */
176static inline void cheetah_flush_dtlb_all(void)
177{
178 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
179 "membar #Sync"
180 : /* No outputs */
181 : "r" (0x80), "i" (ASI_DMMU_DEMAP));
182}
183
184static inline void cheetah_flush_itlb_all(void)
185{
186 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
187 "membar #Sync"
188 : /* No outputs */
189 : "r" (0x80), "i" (ASI_IMMU_DEMAP));
190}
191
192/* Cheetah has a 4-tlb layout so direct access is a bit different.
193 * The first two TLBs are fully assosciative, hold 16 entries, and are
194 * used only for locked and >8K sized translations. One exists for
195 * data accesses and one for instruction accesses.
196 *
197 * The third TLB is for data accesses to 8K non-locked translations, is
198 * 2 way assosciative, and holds 512 entries. The fourth TLB is for
199 * instruction accesses to 8K non-locked translations, is 2 way
200 * assosciative, and holds 128 entries.
201 *
202 * Cheetah has some bug where bogus data can be returned from
203 * ASI_{D,I}TLB_DATA_ACCESS loads, doing the load twice fixes
204 * the problem for me. -DaveM
205 */
206static inline unsigned long cheetah_get_ldtlb_data(int entry)
207{
208 unsigned long data;
209
210 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
211 "ldxa [%1] %2, %0"
212 : "=r" (data)
213 : "r" ((0 << 16) | (entry << 3)),
214 "i" (ASI_DTLB_DATA_ACCESS));
215
216 return data;
217}
218
219static inline unsigned long cheetah_get_litlb_data(int entry)
220{
221 unsigned long data;
222
223 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
224 "ldxa [%1] %2, %0"
225 : "=r" (data)
226 : "r" ((0 << 16) | (entry << 3)),
227 "i" (ASI_ITLB_DATA_ACCESS));
228
229 return data;
230}
231
232static inline unsigned long cheetah_get_ldtlb_tag(int entry)
233{
234 unsigned long tag;
235
236 __asm__ __volatile__("ldxa [%1] %2, %0"
237 : "=r" (tag)
238 : "r" ((0 << 16) | (entry << 3)),
239 "i" (ASI_DTLB_TAG_READ));
240
241 return tag;
242}
243
244static inline unsigned long cheetah_get_litlb_tag(int entry)
245{
246 unsigned long tag;
247
248 __asm__ __volatile__("ldxa [%1] %2, %0"
249 : "=r" (tag)
250 : "r" ((0 << 16) | (entry << 3)),
251 "i" (ASI_ITLB_TAG_READ));
252
253 return tag;
254}
255
256static inline void cheetah_put_ldtlb_data(int entry, unsigned long data)
257{
258 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
259 "membar #Sync"
260 : /* No outputs */
261 : "r" (data),
262 "r" ((0 << 16) | (entry << 3)),
263 "i" (ASI_DTLB_DATA_ACCESS));
264}
265
266static inline void cheetah_put_litlb_data(int entry, unsigned long data)
267{
268 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
269 "membar #Sync"
270 : /* No outputs */
271 : "r" (data),
272 "r" ((0 << 16) | (entry << 3)),
273 "i" (ASI_ITLB_DATA_ACCESS));
274}
275
276static inline unsigned long cheetah_get_dtlb_data(int entry, int tlb)
277{
278 unsigned long data;
279
280 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
281 "ldxa [%1] %2, %0"
282 : "=r" (data)
283 : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_DATA_ACCESS));
284
285 return data;
286}
287
288static inline unsigned long cheetah_get_dtlb_tag(int entry, int tlb)
289{
290 unsigned long tag;
291
292 __asm__ __volatile__("ldxa [%1] %2, %0"
293 : "=r" (tag)
294 : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_TAG_READ));
295 return tag;
296}
297
298static inline void cheetah_put_dtlb_data(int entry, unsigned long data, int tlb)
299{
300 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
301 "membar #Sync"
302 : /* No outputs */
303 : "r" (data),
304 "r" ((tlb << 16) | (entry << 3)),
305 "i" (ASI_DTLB_DATA_ACCESS));
306}
307
308static inline unsigned long cheetah_get_itlb_data(int entry)
309{
310 unsigned long data;
311
312 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
313 "ldxa [%1] %2, %0"
314 : "=r" (data)
315 : "r" ((2 << 16) | (entry << 3)),
316 "i" (ASI_ITLB_DATA_ACCESS));
317
318 return data;
319}
320
321static inline unsigned long cheetah_get_itlb_tag(int entry)
322{
323 unsigned long tag;
324
325 __asm__ __volatile__("ldxa [%1] %2, %0"
326 : "=r" (tag)
327 : "r" ((2 << 16) | (entry << 3)), "i" (ASI_ITLB_TAG_READ));
328 return tag;
329}
330
331static inline void cheetah_put_itlb_data(int entry, unsigned long data)
332{
333 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
334 "membar #Sync"
335 : /* No outputs */
336 : "r" (data), "r" ((2 << 16) | (entry << 3)),
337 "i" (ASI_ITLB_DATA_ACCESS));
338}
339
340#endif /* !(__ASSEMBLY__) */
341
342#endif /* !(_SPARC64_SPITFIRE_H) */
diff --git a/include/asm-sparc/sstate.h b/include/asm-sparc/sstate.h
new file mode 100644
index 000000000000..a7c35dbcb281
--- /dev/null
+++ b/include/asm-sparc/sstate.h
@@ -0,0 +1,13 @@
1#ifndef _SPARC64_SSTATE_H
2#define _SPARC64_SSTATE_H
3
4extern void sstate_booting(void);
5extern void sstate_running(void);
6extern void sstate_halt(void);
7extern void sstate_poweroff(void);
8extern void sstate_panic(void);
9extern void sstate_reboot(void);
10
11extern void sun4v_sstate_init(void);
12
13#endif /* _SPARC64_SSTATE_H */
diff --git a/include/asm-sparc/stacktrace.h b/include/asm-sparc/stacktrace.h
new file mode 100644
index 000000000000..6cee39adf6d6
--- /dev/null
+++ b/include/asm-sparc/stacktrace.h
@@ -0,0 +1,6 @@
1#ifndef _SPARC64_STACKTRACE_H
2#define _SPARC64_STACKTRACE_H
3
4extern void stack_trace_flush(void);
5
6#endif /* _SPARC64_STACKTRACE_H */
diff --git a/include/asm-sparc/starfire.h b/include/asm-sparc/starfire.h
new file mode 100644
index 000000000000..07bafd31e33c
--- /dev/null
+++ b/include/asm-sparc/starfire.h
@@ -0,0 +1,21 @@
1/*
2 * starfire.h: Group all starfire specific code together.
3 *
4 * Copyright (C) 2000 Anton Blanchard (anton@samba.org)
5 */
6
7#ifndef _SPARC64_STARFIRE_H
8#define _SPARC64_STARFIRE_H
9
10#ifndef __ASSEMBLY__
11
12extern int this_is_starfire;
13
14extern void check_if_starfire(void);
15extern void starfire_cpu_setup(void);
16extern int starfire_hard_smp_processor_id(void);
17extern void starfire_hookup(int);
18extern unsigned int starfire_translate(unsigned long imap, unsigned int upaid);
19
20#endif
21#endif
diff --git a/include/asm-sparc/stat.h b/include/asm-sparc/stat.h
index 2299e1d5d94c..9fdcaf8c9cd3 100644
--- a/include/asm-sparc/stat.h
+++ b/include/asm-sparc/stat.h
@@ -1,76 +1,8 @@
1#ifndef _SPARC_STAT_H 1#ifndef ___ASM_SPARC_STAT_H
2#define _SPARC_STAT_H 2#define ___ASM_SPARC_STAT_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <linux/types.h> 4#include <asm-sparc/stat_64.h>
5 5#else
6struct __old_kernel_stat { 6#include <asm-sparc/stat_32.h>
7 unsigned short st_dev; 7#endif
8 unsigned short st_ino;
9 unsigned short st_mode;
10 unsigned short st_nlink;
11 unsigned short st_uid;
12 unsigned short st_gid;
13 unsigned short st_rdev;
14 unsigned long st_size;
15 unsigned long st_atime;
16 unsigned long st_mtime;
17 unsigned long st_ctime;
18};
19
20struct stat {
21 unsigned short st_dev;
22 unsigned long st_ino;
23 unsigned short st_mode;
24 short st_nlink;
25 unsigned short st_uid;
26 unsigned short st_gid;
27 unsigned short st_rdev;
28 long st_size;
29 long st_atime;
30 unsigned long st_atime_nsec;
31 long st_mtime;
32 unsigned long st_mtime_nsec;
33 long st_ctime;
34 unsigned long st_ctime_nsec;
35 long st_blksize;
36 long st_blocks;
37 unsigned long __unused4[2];
38};
39
40#define STAT_HAVE_NSEC 1
41
42struct stat64 {
43 unsigned long long st_dev;
44
45 unsigned long long st_ino;
46
47 unsigned int st_mode;
48 unsigned int st_nlink;
49
50 unsigned int st_uid;
51 unsigned int st_gid;
52
53 unsigned long long st_rdev;
54
55 unsigned char __pad3[8];
56
57 long long st_size;
58 unsigned int st_blksize;
59
60 unsigned char __pad4[8];
61 unsigned int st_blocks;
62
63 unsigned int st_atime;
64 unsigned int st_atime_nsec;
65
66 unsigned int st_mtime;
67 unsigned int st_mtime_nsec;
68
69 unsigned int st_ctime;
70 unsigned int st_ctime_nsec;
71
72 unsigned int __unused4;
73 unsigned int __unused5;
74};
75
76#endif 8#endif
diff --git a/include/asm-sparc/stat_32.h b/include/asm-sparc/stat_32.h
new file mode 100644
index 000000000000..2299e1d5d94c
--- /dev/null
+++ b/include/asm-sparc/stat_32.h
@@ -0,0 +1,76 @@
1#ifndef _SPARC_STAT_H
2#define _SPARC_STAT_H
3
4#include <linux/types.h>
5
6struct __old_kernel_stat {
7 unsigned short st_dev;
8 unsigned short st_ino;
9 unsigned short st_mode;
10 unsigned short st_nlink;
11 unsigned short st_uid;
12 unsigned short st_gid;
13 unsigned short st_rdev;
14 unsigned long st_size;
15 unsigned long st_atime;
16 unsigned long st_mtime;
17 unsigned long st_ctime;
18};
19
20struct stat {
21 unsigned short st_dev;
22 unsigned long st_ino;
23 unsigned short st_mode;
24 short st_nlink;
25 unsigned short st_uid;
26 unsigned short st_gid;
27 unsigned short st_rdev;
28 long st_size;
29 long st_atime;
30 unsigned long st_atime_nsec;
31 long st_mtime;
32 unsigned long st_mtime_nsec;
33 long st_ctime;
34 unsigned long st_ctime_nsec;
35 long st_blksize;
36 long st_blocks;
37 unsigned long __unused4[2];
38};
39
40#define STAT_HAVE_NSEC 1
41
42struct stat64 {
43 unsigned long long st_dev;
44
45 unsigned long long st_ino;
46
47 unsigned int st_mode;
48 unsigned int st_nlink;
49
50 unsigned int st_uid;
51 unsigned int st_gid;
52
53 unsigned long long st_rdev;
54
55 unsigned char __pad3[8];
56
57 long long st_size;
58 unsigned int st_blksize;
59
60 unsigned char __pad4[8];
61 unsigned int st_blocks;
62
63 unsigned int st_atime;
64 unsigned int st_atime_nsec;
65
66 unsigned int st_mtime;
67 unsigned int st_mtime_nsec;
68
69 unsigned int st_ctime;
70 unsigned int st_ctime_nsec;
71
72 unsigned int __unused4;
73 unsigned int __unused5;
74};
75
76#endif
diff --git a/include/asm-sparc/stat_64.h b/include/asm-sparc/stat_64.h
new file mode 100644
index 000000000000..9650fdea847f
--- /dev/null
+++ b/include/asm-sparc/stat_64.h
@@ -0,0 +1,47 @@
1#ifndef _SPARC64_STAT_H
2#define _SPARC64_STAT_H
3
4#include <linux/types.h>
5
6struct stat {
7 unsigned st_dev;
8 ino_t st_ino;
9 mode_t st_mode;
10 short st_nlink;
11 uid_t st_uid;
12 gid_t st_gid;
13 unsigned st_rdev;
14 off_t st_size;
15 time_t st_atime;
16 time_t st_mtime;
17 time_t st_ctime;
18 off_t st_blksize;
19 off_t st_blocks;
20 unsigned long __unused4[2];
21};
22
23struct stat64 {
24 unsigned long st_dev;
25 unsigned long st_ino;
26 unsigned long st_nlink;
27
28 unsigned int st_mode;
29 unsigned int st_uid;
30 unsigned int st_gid;
31 unsigned int __pad0;
32
33 unsigned long st_rdev;
34 long st_size;
35 long st_blksize;
36 long st_blocks;
37
38 unsigned long st_atime;
39 unsigned long st_atime_nsec;
40 unsigned long st_mtime;
41 unsigned long st_mtime_nsec;
42 unsigned long st_ctime;
43 unsigned long st_ctime_nsec;
44 long __unused[3];
45};
46
47#endif
diff --git a/include/asm-sparc/statfs.h b/include/asm-sparc/statfs.h
index 304520fa8863..a70cc52e7018 100644
--- a/include/asm-sparc/statfs.h
+++ b/include/asm-sparc/statfs.h
@@ -1,6 +1,8 @@
1#ifndef _SPARC_STATFS_H 1#ifndef ___ASM_SPARC_STATFS_H
2#define _SPARC_STATFS_H 2#define ___ASM_SPARC_STATFS_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <asm-generic/statfs.h> 4#include <asm-sparc/statfs_64.h>
5 5#else
6#include <asm-sparc/statfs_32.h>
7#endif
6#endif 8#endif
diff --git a/include/asm-sparc/statfs_32.h b/include/asm-sparc/statfs_32.h
new file mode 100644
index 000000000000..304520fa8863
--- /dev/null
+++ b/include/asm-sparc/statfs_32.h
@@ -0,0 +1,6 @@
1#ifndef _SPARC_STATFS_H
2#define _SPARC_STATFS_H
3
4#include <asm-generic/statfs.h>
5
6#endif
diff --git a/include/asm-sparc/statfs_64.h b/include/asm-sparc/statfs_64.h
new file mode 100644
index 000000000000..79b3c890a5fa
--- /dev/null
+++ b/include/asm-sparc/statfs_64.h
@@ -0,0 +1,54 @@
1#ifndef _SPARC64_STATFS_H
2#define _SPARC64_STATFS_H
3
4#ifndef __KERNEL_STRICT_NAMES
5
6#include <linux/types.h>
7
8typedef __kernel_fsid_t fsid_t;
9
10#endif
11
12struct statfs {
13 long f_type;
14 long f_bsize;
15 long f_blocks;
16 long f_bfree;
17 long f_bavail;
18 long f_files;
19 long f_ffree;
20 __kernel_fsid_t f_fsid;
21 long f_namelen;
22 long f_frsize;
23 long f_spare[5];
24};
25
26struct statfs64 {
27 long f_type;
28 long f_bsize;
29 long f_blocks;
30 long f_bfree;
31 long f_bavail;
32 long f_files;
33 long f_ffree;
34 __kernel_fsid_t f_fsid;
35 long f_namelen;
36 long f_frsize;
37 long f_spare[5];
38};
39
40struct compat_statfs64 {
41 __u32 f_type;
42 __u32 f_bsize;
43 __u64 f_blocks;
44 __u64 f_bfree;
45 __u64 f_bavail;
46 __u64 f_files;
47 __u64 f_ffree;
48 __kernel_fsid_t f_fsid;
49 __u32 f_namelen;
50 __u32 f_frsize;
51 __u32 f_spare[5];
52};
53
54#endif
diff --git a/include/asm-sparc/string.h b/include/asm-sparc/string.h
index 8d7c0dd4f299..14c04c7697a5 100644
--- a/include/asm-sparc/string.h
+++ b/include/asm-sparc/string.h
@@ -1,205 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_STRING_H
2 * string.h: External definitions for optimized assembly string 2#define ___ASM_SPARC_STRING_H
3 * routines for the Linux Kernel. 3#if defined(__sparc__) && defined(__arch64__)
4 * 4#include <asm-sparc/string_64.h>
5 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu) 5#else
6 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 6#include <asm-sparc/string_32.h>
7 */ 7#endif
8 8#endif
9#ifndef __SPARC_STRING_H__
10#define __SPARC_STRING_H__
11
12#include <asm/page.h>
13
14/* Really, userland/ksyms should not see any of this stuff. */
15
16#ifdef __KERNEL__
17
18extern void __memmove(void *,const void *,__kernel_size_t);
19extern __kernel_size_t __memcpy(void *,const void *,__kernel_size_t);
20extern __kernel_size_t __memset(void *,int,__kernel_size_t);
21
22#ifndef EXPORT_SYMTAB_STROPS
23
24/* First the mem*() things. */
25#define __HAVE_ARCH_MEMMOVE
26#undef memmove
27#define memmove(_to, _from, _n) \
28({ \
29 void *_t = (_to); \
30 __memmove(_t, (_from), (_n)); \
31 _t; \
32})
33
34#define __HAVE_ARCH_MEMCPY
35
36static inline void *__constant_memcpy(void *to, const void *from, __kernel_size_t n)
37{
38 extern void __copy_1page(void *, const void *);
39
40 if(n <= 32) {
41 __builtin_memcpy(to, from, n);
42 } else if (((unsigned int) to & 7) != 0) {
43 /* Destination is not aligned on the double-word boundary */
44 __memcpy(to, from, n);
45 } else {
46 switch(n) {
47 case PAGE_SIZE:
48 __copy_1page(to, from);
49 break;
50 default:
51 __memcpy(to, from, n);
52 break;
53 }
54 }
55 return to;
56}
57
58static inline void *__nonconstant_memcpy(void *to, const void *from, __kernel_size_t n)
59{
60 __memcpy(to, from, n);
61 return to;
62}
63
64#undef memcpy
65#define memcpy(t, f, n) \
66(__builtin_constant_p(n) ? \
67 __constant_memcpy((t),(f),(n)) : \
68 __nonconstant_memcpy((t),(f),(n)))
69
70#define __HAVE_ARCH_MEMSET
71
72static inline void *__constant_c_and_count_memset(void *s, char c, __kernel_size_t count)
73{
74 extern void bzero_1page(void *);
75 extern __kernel_size_t __bzero(void *, __kernel_size_t);
76
77 if(!c) {
78 if(count == PAGE_SIZE)
79 bzero_1page(s);
80 else
81 __bzero(s, count);
82 } else {
83 __memset(s, c, count);
84 }
85 return s;
86}
87
88static inline void *__constant_c_memset(void *s, char c, __kernel_size_t count)
89{
90 extern __kernel_size_t __bzero(void *, __kernel_size_t);
91
92 if(!c)
93 __bzero(s, count);
94 else
95 __memset(s, c, count);
96 return s;
97}
98
99static inline void *__nonconstant_memset(void *s, char c, __kernel_size_t count)
100{
101 __memset(s, c, count);
102 return s;
103}
104
105#undef memset
106#define memset(s, c, count) \
107(__builtin_constant_p(c) ? (__builtin_constant_p(count) ? \
108 __constant_c_and_count_memset((s), (c), (count)) : \
109 __constant_c_memset((s), (c), (count))) \
110 : __nonconstant_memset((s), (c), (count)))
111
112#define __HAVE_ARCH_MEMSCAN
113
114#undef memscan
115#define memscan(__arg0, __char, __arg2) \
116({ \
117 extern void *__memscan_zero(void *, size_t); \
118 extern void *__memscan_generic(void *, int, size_t); \
119 void *__retval, *__addr = (__arg0); \
120 size_t __size = (__arg2); \
121 \
122 if(__builtin_constant_p(__char) && !(__char)) \
123 __retval = __memscan_zero(__addr, __size); \
124 else \
125 __retval = __memscan_generic(__addr, (__char), __size); \
126 \
127 __retval; \
128})
129
130#define __HAVE_ARCH_MEMCMP
131extern int memcmp(const void *,const void *,__kernel_size_t);
132
133/* Now the str*() stuff... */
134#define __HAVE_ARCH_STRLEN
135extern __kernel_size_t strlen(const char *);
136
137#define __HAVE_ARCH_STRNCMP
138
139extern int __strncmp(const char *, const char *, __kernel_size_t);
140
141static inline int __constant_strncmp(const char *src, const char *dest, __kernel_size_t count)
142{
143 register int retval;
144 switch(count) {
145 case 0: return 0;
146 case 1: return (src[0] - dest[0]);
147 case 2: retval = (src[0] - dest[0]);
148 if(!retval && src[0])
149 retval = (src[1] - dest[1]);
150 return retval;
151 case 3: retval = (src[0] - dest[0]);
152 if(!retval && src[0]) {
153 retval = (src[1] - dest[1]);
154 if(!retval && src[1])
155 retval = (src[2] - dest[2]);
156 }
157 return retval;
158 case 4: retval = (src[0] - dest[0]);
159 if(!retval && src[0]) {
160 retval = (src[1] - dest[1]);
161 if(!retval && src[1]) {
162 retval = (src[2] - dest[2]);
163 if (!retval && src[2])
164 retval = (src[3] - dest[3]);
165 }
166 }
167 return retval;
168 case 5: retval = (src[0] - dest[0]);
169 if(!retval && src[0]) {
170 retval = (src[1] - dest[1]);
171 if(!retval && src[1]) {
172 retval = (src[2] - dest[2]);
173 if (!retval && src[2]) {
174 retval = (src[3] - dest[3]);
175 if (!retval && src[3])
176 retval = (src[4] - dest[4]);
177 }
178 }
179 }
180 return retval;
181 default:
182 retval = (src[0] - dest[0]);
183 if(!retval && src[0]) {
184 retval = (src[1] - dest[1]);
185 if(!retval && src[1]) {
186 retval = (src[2] - dest[2]);
187 if(!retval && src[2])
188 retval = __strncmp(src+3,dest+3,count-3);
189 }
190 }
191 return retval;
192 }
193}
194
195#undef strncmp
196#define strncmp(__arg0, __arg1, __arg2) \
197(__builtin_constant_p(__arg2) ? \
198 __constant_strncmp(__arg0, __arg1, __arg2) : \
199 __strncmp(__arg0, __arg1, __arg2))
200
201#endif /* !EXPORT_SYMTAB_STROPS */
202
203#endif /* __KERNEL__ */
204
205#endif /* !(__SPARC_STRING_H__) */
diff --git a/include/asm-sparc/string_32.h b/include/asm-sparc/string_32.h
new file mode 100644
index 000000000000..6c5fddb7e6b5
--- /dev/null
+++ b/include/asm-sparc/string_32.h
@@ -0,0 +1,205 @@
1/*
2 * string.h: External definitions for optimized assembly string
3 * routines for the Linux Kernel.
4 *
5 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 */
8
9#ifndef __SPARC_STRING_H__
10#define __SPARC_STRING_H__
11
12#include <asm/page.h>
13
14/* Really, userland/ksyms should not see any of this stuff. */
15
16#ifdef __KERNEL__
17
18extern void __memmove(void *,const void *,__kernel_size_t);
19extern __kernel_size_t __memcpy(void *,const void *,__kernel_size_t);
20extern __kernel_size_t __memset(void *,int,__kernel_size_t);
21
22#ifndef EXPORT_SYMTAB_STROPS
23
24/* First the mem*() things. */
25#define __HAVE_ARCH_MEMMOVE
26#undef memmove
27#define memmove(_to, _from, _n) \
28({ \
29 void *_t = (_to); \
30 __memmove(_t, (_from), (_n)); \
31 _t; \
32})
33
34#define __HAVE_ARCH_MEMCPY
35
36static inline void *__constant_memcpy(void *to, const void *from, __kernel_size_t n)
37{
38 extern void __copy_1page(void *, const void *);
39
40 if(n <= 32) {
41 __builtin_memcpy(to, from, n);
42 } else if (((unsigned int) to & 7) != 0) {
43 /* Destination is not aligned on the double-word boundary */
44 __memcpy(to, from, n);
45 } else {
46 switch(n) {
47 case PAGE_SIZE:
48 __copy_1page(to, from);
49 break;
50 default:
51 __memcpy(to, from, n);
52 break;
53 }
54 }
55 return to;
56}
57
58static inline void *__nonconstant_memcpy(void *to, const void *from, __kernel_size_t n)
59{
60 __memcpy(to, from, n);
61 return to;
62}
63
64#undef memcpy
65#define memcpy(t, f, n) \
66(__builtin_constant_p(n) ? \
67 __constant_memcpy((t),(f),(n)) : \
68 __nonconstant_memcpy((t),(f),(n)))
69
70#define __HAVE_ARCH_MEMSET
71
72static inline void *__constant_c_and_count_memset(void *s, char c, __kernel_size_t count)
73{
74 extern void bzero_1page(void *);
75 extern __kernel_size_t __bzero(void *, __kernel_size_t);
76
77 if(!c) {
78 if(count == PAGE_SIZE)
79 bzero_1page(s);
80 else
81 __bzero(s, count);
82 } else {
83 __memset(s, c, count);
84 }
85 return s;
86}
87
88static inline void *__constant_c_memset(void *s, char c, __kernel_size_t count)
89{
90 extern __kernel_size_t __bzero(void *, __kernel_size_t);
91
92 if(!c)
93 __bzero(s, count);
94 else
95 __memset(s, c, count);
96 return s;
97}
98
99static inline void *__nonconstant_memset(void *s, char c, __kernel_size_t count)
100{
101 __memset(s, c, count);
102 return s;
103}
104
105#undef memset
106#define memset(s, c, count) \
107(__builtin_constant_p(c) ? (__builtin_constant_p(count) ? \
108 __constant_c_and_count_memset((s), (c), (count)) : \
109 __constant_c_memset((s), (c), (count))) \
110 : __nonconstant_memset((s), (c), (count)))
111
112#define __HAVE_ARCH_MEMSCAN
113
114#undef memscan
115#define memscan(__arg0, __char, __arg2) \
116({ \
117 extern void *__memscan_zero(void *, size_t); \
118 extern void *__memscan_generic(void *, int, size_t); \
119 void *__retval, *__addr = (__arg0); \
120 size_t __size = (__arg2); \
121 \
122 if(__builtin_constant_p(__char) && !(__char)) \
123 __retval = __memscan_zero(__addr, __size); \
124 else \
125 __retval = __memscan_generic(__addr, (__char), __size); \
126 \
127 __retval; \
128})
129
130#define __HAVE_ARCH_MEMCMP
131extern int memcmp(const void *,const void *,__kernel_size_t);
132
133/* Now the str*() stuff... */
134#define __HAVE_ARCH_STRLEN
135extern __kernel_size_t strlen(const char *);
136
137#define __HAVE_ARCH_STRNCMP
138
139extern int __strncmp(const char *, const char *, __kernel_size_t);
140
141static inline int __constant_strncmp(const char *src, const char *dest, __kernel_size_t count)
142{
143 register int retval;
144 switch(count) {
145 case 0: return 0;
146 case 1: return (src[0] - dest[0]);
147 case 2: retval = (src[0] - dest[0]);
148 if(!retval && src[0])
149 retval = (src[1] - dest[1]);
150 return retval;
151 case 3: retval = (src[0] - dest[0]);
152 if(!retval && src[0]) {
153 retval = (src[1] - dest[1]);
154 if(!retval && src[1])
155 retval = (src[2] - dest[2]);
156 }
157 return retval;
158 case 4: retval = (src[0] - dest[0]);
159 if(!retval && src[0]) {
160 retval = (src[1] - dest[1]);
161 if(!retval && src[1]) {
162 retval = (src[2] - dest[2]);
163 if (!retval && src[2])
164 retval = (src[3] - dest[3]);
165 }
166 }
167 return retval;
168 case 5: retval = (src[0] - dest[0]);
169 if(!retval && src[0]) {
170 retval = (src[1] - dest[1]);
171 if(!retval && src[1]) {
172 retval = (src[2] - dest[2]);
173 if (!retval && src[2]) {
174 retval = (src[3] - dest[3]);
175 if (!retval && src[3])
176 retval = (src[4] - dest[4]);
177 }
178 }
179 }
180 return retval;
181 default:
182 retval = (src[0] - dest[0]);
183 if(!retval && src[0]) {
184 retval = (src[1] - dest[1]);
185 if(!retval && src[1]) {
186 retval = (src[2] - dest[2]);
187 if(!retval && src[2])
188 retval = __strncmp(src+3,dest+3,count-3);
189 }
190 }
191 return retval;
192 }
193}
194
195#undef strncmp
196#define strncmp(__arg0, __arg1, __arg2) \
197(__builtin_constant_p(__arg2) ? \
198 __constant_strncmp(__arg0, __arg1, __arg2) : \
199 __strncmp(__arg0, __arg1, __arg2))
200
201#endif /* !EXPORT_SYMTAB_STROPS */
202
203#endif /* __KERNEL__ */
204
205#endif /* !(__SPARC_STRING_H__) */
diff --git a/include/asm-sparc/string_64.h b/include/asm-sparc/string_64.h
new file mode 100644
index 000000000000..43161f2d17eb
--- /dev/null
+++ b/include/asm-sparc/string_64.h
@@ -0,0 +1,83 @@
1/*
2 * string.h: External definitions for optimized assembly string
3 * routines for the Linux Kernel.
4 *
5 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996,1997,1999 Jakub Jelinek (jakub@redhat.com)
7 */
8
9#ifndef __SPARC64_STRING_H__
10#define __SPARC64_STRING_H__
11
12/* Really, userland/ksyms should not see any of this stuff. */
13
14#ifdef __KERNEL__
15
16#include <asm/asi.h>
17
18extern void *__memset(void *,int,__kernel_size_t);
19
20#ifndef EXPORT_SYMTAB_STROPS
21
22/* First the mem*() things. */
23#define __HAVE_ARCH_MEMMOVE
24extern void *memmove(void *, const void *, __kernel_size_t);
25
26#define __HAVE_ARCH_MEMCPY
27extern void *memcpy(void *, const void *, __kernel_size_t);
28
29#define __HAVE_ARCH_MEMSET
30extern void *__builtin_memset(void *,int,__kernel_size_t);
31
32static inline void *__constant_memset(void *s, int c, __kernel_size_t count)
33{
34 extern __kernel_size_t __bzero(void *, __kernel_size_t);
35
36 if (!c) {
37 __bzero(s, count);
38 return s;
39 } else
40 return __memset(s, c, count);
41}
42
43#undef memset
44#define memset(s, c, count) \
45((__builtin_constant_p(count) && (count) <= 32) ? \
46 __builtin_memset((s), (c), (count)) : \
47 (__builtin_constant_p(c) ? \
48 __constant_memset((s), (c), (count)) : \
49 __memset((s), (c), (count))))
50
51#define __HAVE_ARCH_MEMSCAN
52
53#undef memscan
54#define memscan(__arg0, __char, __arg2) \
55({ \
56 extern void *__memscan_zero(void *, size_t); \
57 extern void *__memscan_generic(void *, int, size_t); \
58 void *__retval, *__addr = (__arg0); \
59 size_t __size = (__arg2); \
60 \
61 if(__builtin_constant_p(__char) && !(__char)) \
62 __retval = __memscan_zero(__addr, __size); \
63 else \
64 __retval = __memscan_generic(__addr, (__char), __size); \
65 \
66 __retval; \
67})
68
69#define __HAVE_ARCH_MEMCMP
70extern int memcmp(const void *,const void *,__kernel_size_t);
71
72/* Now the str*() stuff... */
73#define __HAVE_ARCH_STRLEN
74extern __kernel_size_t strlen(const char *);
75
76#define __HAVE_ARCH_STRNCMP
77extern int strncmp(const char *, const char *, __kernel_size_t);
78
79#endif /* !EXPORT_SYMTAB_STROPS */
80
81#endif /* __KERNEL__ */
82
83#endif /* !(__SPARC64_STRING_H__) */
diff --git a/include/asm-sparc/syscalls.h b/include/asm-sparc/syscalls.h
new file mode 100644
index 000000000000..45a43f637a14
--- /dev/null
+++ b/include/asm-sparc/syscalls.h
@@ -0,0 +1,13 @@
1#ifndef _SPARC64_SYSCALLS_H
2#define _SPARC64_SYSCALLS_H
3
4struct pt_regs;
5
6extern asmlinkage long sparc_do_fork(unsigned long clone_flags,
7 unsigned long stack_start,
8 struct pt_regs *regs,
9 unsigned long stack_size);
10
11extern asmlinkage int sparc_execve(struct pt_regs *regs);
12
13#endif /* _SPARC64_SYSCALLS_H */
diff --git a/include/asm-sparc/system.h b/include/asm-sparc/system.h
index b4b024445fc9..15e2a3bc4f61 100644
--- a/include/asm-sparc/system.h
+++ b/include/asm-sparc/system.h
@@ -1,288 +1,8 @@
1#ifndef __SPARC_SYSTEM_H 1#ifndef ___ASM_SPARC_SYSTEM_H
2#define __SPARC_SYSTEM_H 2#define ___ASM_SPARC_SYSTEM_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <linux/kernel.h> 4#include <asm-sparc/system_64.h>
5#include <linux/threads.h> /* NR_CPUS */
6#include <linux/thread_info.h>
7
8#include <asm/page.h>
9#include <asm/psr.h>
10#include <asm/ptrace.h>
11#include <asm/btfixup.h>
12#include <asm/smp.h>
13
14#ifndef __ASSEMBLY__
15
16#include <linux/irqflags.h>
17
18/*
19 * Sparc (general) CPU types
20 */
21enum sparc_cpu {
22 sun4 = 0x00,
23 sun4c = 0x01,
24 sun4m = 0x02,
25 sun4d = 0x03,
26 sun4e = 0x04,
27 sun4u = 0x05, /* V8 ploos ploos */
28 sun_unknown = 0x06,
29 ap1000 = 0x07, /* almost a sun4m */
30};
31
32/* Really, userland should not be looking at any of this... */
33#ifdef __KERNEL__
34
35extern enum sparc_cpu sparc_cpu_model;
36
37#ifndef CONFIG_SUN4
38#define ARCH_SUN4C_SUN4 (sparc_cpu_model==sun4c)
39#define ARCH_SUN4 0
40#else 5#else
41#define ARCH_SUN4C_SUN4 1 6#include <asm-sparc/system_32.h>
42#define ARCH_SUN4 1
43#endif 7#endif
44
45#define SUN4M_NCPUS 4 /* Architectural limit of sun4m. */
46
47extern char reboot_command[];
48
49extern struct thread_info *current_set[NR_CPUS];
50
51extern unsigned long empty_bad_page;
52extern unsigned long empty_bad_page_table;
53extern unsigned long empty_zero_page;
54
55extern void sun_do_break(void);
56extern int serial_console;
57extern int stop_a_enabled;
58
59static inline int con_is_present(void)
60{
61 return serial_console ? 0 : 1;
62}
63
64/* When a context switch happens we must flush all user windows so that
65 * the windows of the current process are flushed onto its stack. This
66 * way the windows are all clean for the next process and the stack
67 * frames are up to date.
68 */
69extern void flush_user_windows(void);
70extern void kill_user_windows(void);
71extern void synchronize_user_stack(void);
72extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
73 void *fpqueue, unsigned long *fpqdepth);
74
75#ifdef CONFIG_SMP
76#define SWITCH_ENTER(prv) \
77 do { \
78 if (test_tsk_thread_flag(prv, TIF_USEDFPU)) { \
79 put_psr(get_psr() | PSR_EF); \
80 fpsave(&(prv)->thread.float_regs[0], &(prv)->thread.fsr, \
81 &(prv)->thread.fpqueue[0], &(prv)->thread.fpqdepth); \
82 clear_tsk_thread_flag(prv, TIF_USEDFPU); \
83 (prv)->thread.kregs->psr &= ~PSR_EF; \
84 } \
85 } while(0)
86
87#define SWITCH_DO_LAZY_FPU(next) /* */
88#else
89#define SWITCH_ENTER(prv) /* */
90#define SWITCH_DO_LAZY_FPU(nxt) \
91 do { \
92 if (last_task_used_math != (nxt)) \
93 (nxt)->thread.kregs->psr&=~PSR_EF; \
94 } while(0)
95#endif
96
97extern void flushw_all(void);
98
99/*
100 * Flush windows so that the VM switch which follows
101 * would not pull the stack from under us.
102 *
103 * SWITCH_ENTER and SWITH_DO_LAZY_FPU do not work yet (e.g. SMP does not work)
104 * XXX WTF is the above comment? Found in late teen 2.4.x.
105 */
106#define prepare_arch_switch(next) do { \
107 __asm__ __volatile__( \
108 ".globl\tflush_patch_switch\nflush_patch_switch:\n\t" \
109 "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
110 "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
111 "save %sp, -0x40, %sp\n\t" \
112 "restore; restore; restore; restore; restore; restore; restore"); \
113} while(0)
114
115 /* Much care has gone into this code, do not touch it.
116 *
117 * We need to loadup regs l0/l1 for the newly forked child
118 * case because the trap return path relies on those registers
119 * holding certain values, gcc is told that they are clobbered.
120 * Gcc needs registers for 3 values in and 1 value out, so we
121 * clobber every non-fixed-usage register besides l2/l3/o4/o5. -DaveM
122 *
123 * Hey Dave, that do not touch sign is too much of an incentive
124 * - Anton & Pete
125 */
126#define switch_to(prev, next, last) do { \
127 SWITCH_ENTER(prev); \
128 SWITCH_DO_LAZY_FPU(next); \
129 cpu_set(smp_processor_id(), next->active_mm->cpu_vm_mask); \
130 __asm__ __volatile__( \
131 "sethi %%hi(here - 0x8), %%o7\n\t" \
132 "mov %%g6, %%g3\n\t" \
133 "or %%o7, %%lo(here - 0x8), %%o7\n\t" \
134 "rd %%psr, %%g4\n\t" \
135 "std %%sp, [%%g6 + %4]\n\t" \
136 "rd %%wim, %%g5\n\t" \
137 "wr %%g4, 0x20, %%psr\n\t" \
138 "nop\n\t" \
139 "std %%g4, [%%g6 + %3]\n\t" \
140 "ldd [%2 + %3], %%g4\n\t" \
141 "mov %2, %%g6\n\t" \
142 ".globl patchme_store_new_current\n" \
143"patchme_store_new_current:\n\t" \
144 "st %2, [%1]\n\t" \
145 "wr %%g4, 0x20, %%psr\n\t" \
146 "nop\n\t" \
147 "nop\n\t" \
148 "nop\n\t" /* LEON needs all 3 nops: load to %sp depends on CWP. */ \
149 "ldd [%%g6 + %4], %%sp\n\t" \
150 "wr %%g5, 0x0, %%wim\n\t" \
151 "ldd [%%sp + 0x00], %%l0\n\t" \
152 "ldd [%%sp + 0x38], %%i6\n\t" \
153 "wr %%g4, 0x0, %%psr\n\t" \
154 "nop\n\t" \
155 "nop\n\t" \
156 "jmpl %%o7 + 0x8, %%g0\n\t" \
157 " ld [%%g3 + %5], %0\n\t" \
158 "here:\n" \
159 : "=&r" (last) \
160 : "r" (&(current_set[hard_smp_processor_id()])), \
161 "r" (task_thread_info(next)), \
162 "i" (TI_KPSR), \
163 "i" (TI_KSP), \
164 "i" (TI_TASK) \
165 : "g1", "g2", "g3", "g4", "g5", "g7", \
166 "l0", "l1", "l3", "l4", "l5", "l6", "l7", \
167 "i0", "i1", "i2", "i3", "i4", "i5", \
168 "o0", "o1", "o2", "o3", "o7"); \
169 } while(0)
170
171/* XXX Change this if we ever use a PSO mode kernel. */
172#define mb() __asm__ __volatile__ ("" : : : "memory")
173#define rmb() mb()
174#define wmb() mb()
175#define read_barrier_depends() do { } while(0)
176#define set_mb(__var, __value) do { __var = __value; mb(); } while(0)
177#define smp_mb() __asm__ __volatile__("":::"memory")
178#define smp_rmb() __asm__ __volatile__("":::"memory")
179#define smp_wmb() __asm__ __volatile__("":::"memory")
180#define smp_read_barrier_depends() do { } while(0)
181
182#define nop() __asm__ __volatile__ ("nop")
183
184/* This has special calling conventions */
185#ifndef CONFIG_SMP
186BTFIXUPDEF_CALL(void, ___xchg32, void)
187#endif
188
189static inline unsigned long xchg_u32(__volatile__ unsigned long *m, unsigned long val)
190{
191#ifdef CONFIG_SMP
192 __asm__ __volatile__("swap [%2], %0"
193 : "=&r" (val)
194 : "0" (val), "r" (m)
195 : "memory");
196 return val;
197#else
198 register unsigned long *ptr asm("g1");
199 register unsigned long ret asm("g2");
200
201 ptr = (unsigned long *) m;
202 ret = val;
203
204 /* Note: this is magic and the nop there is
205 really needed. */
206 __asm__ __volatile__(
207 "mov %%o7, %%g4\n\t"
208 "call ___f____xchg32\n\t"
209 " nop\n\t"
210 : "=&r" (ret)
211 : "0" (ret), "r" (ptr)
212 : "g3", "g4", "g7", "memory", "cc");
213
214 return ret;
215#endif 8#endif
216}
217
218#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
219
220extern void __xchg_called_with_bad_pointer(void);
221
222static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size)
223{
224 switch (size) {
225 case 4:
226 return xchg_u32(ptr, x);
227 };
228 __xchg_called_with_bad_pointer();
229 return x;
230}
231
232/* Emulate cmpxchg() the same way we emulate atomics,
233 * by hashing the object address and indexing into an array
234 * of spinlocks to get a bit of performance...
235 *
236 * See arch/sparc/lib/atomic32.c for implementation.
237 *
238 * Cribbed from <asm-parisc/atomic.h>
239 */
240#define __HAVE_ARCH_CMPXCHG 1
241
242/* bug catcher for when unsupported size is used - won't link */
243extern void __cmpxchg_called_with_bad_pointer(void);
244/* we only need to support cmpxchg of a u32 on sparc */
245extern unsigned long __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_);
246
247/* don't worry...optimizer will get rid of most of this */
248static inline unsigned long
249__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
250{
251 switch (size) {
252 case 4:
253 return __cmpxchg_u32((u32 *)ptr, (u32)old, (u32)new_);
254 default:
255 __cmpxchg_called_with_bad_pointer();
256 break;
257 }
258 return old;
259}
260
261#define cmpxchg(ptr, o, n) \
262({ \
263 __typeof__(*(ptr)) _o_ = (o); \
264 __typeof__(*(ptr)) _n_ = (n); \
265 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
266 (unsigned long)_n_, sizeof(*(ptr))); \
267})
268
269#include <asm-generic/cmpxchg-local.h>
270
271/*
272 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
273 * them available.
274 */
275#define cmpxchg_local(ptr, o, n) \
276 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
277 (unsigned long)(n), sizeof(*(ptr))))
278#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
279
280extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noreturn));
281
282#endif /* __KERNEL__ */
283
284#endif /* __ASSEMBLY__ */
285
286#define arch_align_stack(x) (x)
287
288#endif /* !(__SPARC_SYSTEM_H) */
diff --git a/include/asm-sparc/system_32.h b/include/asm-sparc/system_32.h
new file mode 100644
index 000000000000..b4b024445fc9
--- /dev/null
+++ b/include/asm-sparc/system_32.h
@@ -0,0 +1,288 @@
1#ifndef __SPARC_SYSTEM_H
2#define __SPARC_SYSTEM_H
3
4#include <linux/kernel.h>
5#include <linux/threads.h> /* NR_CPUS */
6#include <linux/thread_info.h>
7
8#include <asm/page.h>
9#include <asm/psr.h>
10#include <asm/ptrace.h>
11#include <asm/btfixup.h>
12#include <asm/smp.h>
13
14#ifndef __ASSEMBLY__
15
16#include <linux/irqflags.h>
17
18/*
19 * Sparc (general) CPU types
20 */
21enum sparc_cpu {
22 sun4 = 0x00,
23 sun4c = 0x01,
24 sun4m = 0x02,
25 sun4d = 0x03,
26 sun4e = 0x04,
27 sun4u = 0x05, /* V8 ploos ploos */
28 sun_unknown = 0x06,
29 ap1000 = 0x07, /* almost a sun4m */
30};
31
32/* Really, userland should not be looking at any of this... */
33#ifdef __KERNEL__
34
35extern enum sparc_cpu sparc_cpu_model;
36
37#ifndef CONFIG_SUN4
38#define ARCH_SUN4C_SUN4 (sparc_cpu_model==sun4c)
39#define ARCH_SUN4 0
40#else
41#define ARCH_SUN4C_SUN4 1
42#define ARCH_SUN4 1
43#endif
44
45#define SUN4M_NCPUS 4 /* Architectural limit of sun4m. */
46
47extern char reboot_command[];
48
49extern struct thread_info *current_set[NR_CPUS];
50
51extern unsigned long empty_bad_page;
52extern unsigned long empty_bad_page_table;
53extern unsigned long empty_zero_page;
54
55extern void sun_do_break(void);
56extern int serial_console;
57extern int stop_a_enabled;
58
59static inline int con_is_present(void)
60{
61 return serial_console ? 0 : 1;
62}
63
64/* When a context switch happens we must flush all user windows so that
65 * the windows of the current process are flushed onto its stack. This
66 * way the windows are all clean for the next process and the stack
67 * frames are up to date.
68 */
69extern void flush_user_windows(void);
70extern void kill_user_windows(void);
71extern void synchronize_user_stack(void);
72extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
73 void *fpqueue, unsigned long *fpqdepth);
74
75#ifdef CONFIG_SMP
76#define SWITCH_ENTER(prv) \
77 do { \
78 if (test_tsk_thread_flag(prv, TIF_USEDFPU)) { \
79 put_psr(get_psr() | PSR_EF); \
80 fpsave(&(prv)->thread.float_regs[0], &(prv)->thread.fsr, \
81 &(prv)->thread.fpqueue[0], &(prv)->thread.fpqdepth); \
82 clear_tsk_thread_flag(prv, TIF_USEDFPU); \
83 (prv)->thread.kregs->psr &= ~PSR_EF; \
84 } \
85 } while(0)
86
87#define SWITCH_DO_LAZY_FPU(next) /* */
88#else
89#define SWITCH_ENTER(prv) /* */
90#define SWITCH_DO_LAZY_FPU(nxt) \
91 do { \
92 if (last_task_used_math != (nxt)) \
93 (nxt)->thread.kregs->psr&=~PSR_EF; \
94 } while(0)
95#endif
96
97extern void flushw_all(void);
98
99/*
100 * Flush windows so that the VM switch which follows
101 * would not pull the stack from under us.
102 *
103 * SWITCH_ENTER and SWITH_DO_LAZY_FPU do not work yet (e.g. SMP does not work)
104 * XXX WTF is the above comment? Found in late teen 2.4.x.
105 */
106#define prepare_arch_switch(next) do { \
107 __asm__ __volatile__( \
108 ".globl\tflush_patch_switch\nflush_patch_switch:\n\t" \
109 "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
110 "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
111 "save %sp, -0x40, %sp\n\t" \
112 "restore; restore; restore; restore; restore; restore; restore"); \
113} while(0)
114
115 /* Much care has gone into this code, do not touch it.
116 *
117 * We need to loadup regs l0/l1 for the newly forked child
118 * case because the trap return path relies on those registers
119 * holding certain values, gcc is told that they are clobbered.
120 * Gcc needs registers for 3 values in and 1 value out, so we
121 * clobber every non-fixed-usage register besides l2/l3/o4/o5. -DaveM
122 *
123 * Hey Dave, that do not touch sign is too much of an incentive
124 * - Anton & Pete
125 */
126#define switch_to(prev, next, last) do { \
127 SWITCH_ENTER(prev); \
128 SWITCH_DO_LAZY_FPU(next); \
129 cpu_set(smp_processor_id(), next->active_mm->cpu_vm_mask); \
130 __asm__ __volatile__( \
131 "sethi %%hi(here - 0x8), %%o7\n\t" \
132 "mov %%g6, %%g3\n\t" \
133 "or %%o7, %%lo(here - 0x8), %%o7\n\t" \
134 "rd %%psr, %%g4\n\t" \
135 "std %%sp, [%%g6 + %4]\n\t" \
136 "rd %%wim, %%g5\n\t" \
137 "wr %%g4, 0x20, %%psr\n\t" \
138 "nop\n\t" \
139 "std %%g4, [%%g6 + %3]\n\t" \
140 "ldd [%2 + %3], %%g4\n\t" \
141 "mov %2, %%g6\n\t" \
142 ".globl patchme_store_new_current\n" \
143"patchme_store_new_current:\n\t" \
144 "st %2, [%1]\n\t" \
145 "wr %%g4, 0x20, %%psr\n\t" \
146 "nop\n\t" \
147 "nop\n\t" \
148 "nop\n\t" /* LEON needs all 3 nops: load to %sp depends on CWP. */ \
149 "ldd [%%g6 + %4], %%sp\n\t" \
150 "wr %%g5, 0x0, %%wim\n\t" \
151 "ldd [%%sp + 0x00], %%l0\n\t" \
152 "ldd [%%sp + 0x38], %%i6\n\t" \
153 "wr %%g4, 0x0, %%psr\n\t" \
154 "nop\n\t" \
155 "nop\n\t" \
156 "jmpl %%o7 + 0x8, %%g0\n\t" \
157 " ld [%%g3 + %5], %0\n\t" \
158 "here:\n" \
159 : "=&r" (last) \
160 : "r" (&(current_set[hard_smp_processor_id()])), \
161 "r" (task_thread_info(next)), \
162 "i" (TI_KPSR), \
163 "i" (TI_KSP), \
164 "i" (TI_TASK) \
165 : "g1", "g2", "g3", "g4", "g5", "g7", \
166 "l0", "l1", "l3", "l4", "l5", "l6", "l7", \
167 "i0", "i1", "i2", "i3", "i4", "i5", \
168 "o0", "o1", "o2", "o3", "o7"); \
169 } while(0)
170
171/* XXX Change this if we ever use a PSO mode kernel. */
172#define mb() __asm__ __volatile__ ("" : : : "memory")
173#define rmb() mb()
174#define wmb() mb()
175#define read_barrier_depends() do { } while(0)
176#define set_mb(__var, __value) do { __var = __value; mb(); } while(0)
177#define smp_mb() __asm__ __volatile__("":::"memory")
178#define smp_rmb() __asm__ __volatile__("":::"memory")
179#define smp_wmb() __asm__ __volatile__("":::"memory")
180#define smp_read_barrier_depends() do { } while(0)
181
182#define nop() __asm__ __volatile__ ("nop")
183
184/* This has special calling conventions */
185#ifndef CONFIG_SMP
186BTFIXUPDEF_CALL(void, ___xchg32, void)
187#endif
188
189static inline unsigned long xchg_u32(__volatile__ unsigned long *m, unsigned long val)
190{
191#ifdef CONFIG_SMP
192 __asm__ __volatile__("swap [%2], %0"
193 : "=&r" (val)
194 : "0" (val), "r" (m)
195 : "memory");
196 return val;
197#else
198 register unsigned long *ptr asm("g1");
199 register unsigned long ret asm("g2");
200
201 ptr = (unsigned long *) m;
202 ret = val;
203
204 /* Note: this is magic and the nop there is
205 really needed. */
206 __asm__ __volatile__(
207 "mov %%o7, %%g4\n\t"
208 "call ___f____xchg32\n\t"
209 " nop\n\t"
210 : "=&r" (ret)
211 : "0" (ret), "r" (ptr)
212 : "g3", "g4", "g7", "memory", "cc");
213
214 return ret;
215#endif
216}
217
218#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
219
220extern void __xchg_called_with_bad_pointer(void);
221
222static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size)
223{
224 switch (size) {
225 case 4:
226 return xchg_u32(ptr, x);
227 };
228 __xchg_called_with_bad_pointer();
229 return x;
230}
231
232/* Emulate cmpxchg() the same way we emulate atomics,
233 * by hashing the object address and indexing into an array
234 * of spinlocks to get a bit of performance...
235 *
236 * See arch/sparc/lib/atomic32.c for implementation.
237 *
238 * Cribbed from <asm-parisc/atomic.h>
239 */
240#define __HAVE_ARCH_CMPXCHG 1
241
242/* bug catcher for when unsupported size is used - won't link */
243extern void __cmpxchg_called_with_bad_pointer(void);
244/* we only need to support cmpxchg of a u32 on sparc */
245extern unsigned long __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_);
246
247/* don't worry...optimizer will get rid of most of this */
248static inline unsigned long
249__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
250{
251 switch (size) {
252 case 4:
253 return __cmpxchg_u32((u32 *)ptr, (u32)old, (u32)new_);
254 default:
255 __cmpxchg_called_with_bad_pointer();
256 break;
257 }
258 return old;
259}
260
261#define cmpxchg(ptr, o, n) \
262({ \
263 __typeof__(*(ptr)) _o_ = (o); \
264 __typeof__(*(ptr)) _n_ = (n); \
265 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
266 (unsigned long)_n_, sizeof(*(ptr))); \
267})
268
269#include <asm-generic/cmpxchg-local.h>
270
271/*
272 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
273 * them available.
274 */
275#define cmpxchg_local(ptr, o, n) \
276 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
277 (unsigned long)(n), sizeof(*(ptr))))
278#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
279
280extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noreturn));
281
282#endif /* __KERNEL__ */
283
284#endif /* __ASSEMBLY__ */
285
286#define arch_align_stack(x) (x)
287
288#endif /* !(__SPARC_SYSTEM_H) */
diff --git a/include/asm-sparc/system_64.h b/include/asm-sparc/system_64.h
new file mode 100644
index 000000000000..db9e742a406a
--- /dev/null
+++ b/include/asm-sparc/system_64.h
@@ -0,0 +1,355 @@
1#ifndef __SPARC64_SYSTEM_H
2#define __SPARC64_SYSTEM_H
3
4#include <asm/ptrace.h>
5#include <asm/processor.h>
6#include <asm/visasm.h>
7
8#ifndef __ASSEMBLY__
9
10#include <linux/irqflags.h>
11#include <asm-generic/cmpxchg-local.h>
12
13/*
14 * Sparc (general) CPU types
15 */
16enum sparc_cpu {
17 sun4 = 0x00,
18 sun4c = 0x01,
19 sun4m = 0x02,
20 sun4d = 0x03,
21 sun4e = 0x04,
22 sun4u = 0x05, /* V8 ploos ploos */
23 sun_unknown = 0x06,
24 ap1000 = 0x07, /* almost a sun4m */
25};
26
27#define sparc_cpu_model sun4u
28
29/* This cannot ever be a sun4c nor sun4 :) That's just history. */
30#define ARCH_SUN4C_SUN4 0
31#define ARCH_SUN4 0
32
33extern char reboot_command[];
34
35/* These are here in an effort to more fully work around Spitfire Errata
36 * #51. Essentially, if a memory barrier occurs soon after a mispredicted
37 * branch, the chip can stop executing instructions until a trap occurs.
38 * Therefore, if interrupts are disabled, the chip can hang forever.
39 *
40 * It used to be believed that the memory barrier had to be right in the
41 * delay slot, but a case has been traced recently wherein the memory barrier
42 * was one instruction after the branch delay slot and the chip still hung.
43 * The offending sequence was the following in sym_wakeup_done() of the
44 * sym53c8xx_2 driver:
45 *
46 * call sym_ccb_from_dsa, 0
47 * movge %icc, 0, %l0
48 * brz,pn %o0, .LL1303
49 * mov %o0, %l2
50 * membar #LoadLoad
51 *
52 * The branch has to be mispredicted for the bug to occur. Therefore, we put
53 * the memory barrier explicitly into a "branch always, predicted taken"
54 * delay slot to avoid the problem case.
55 */
56#define membar_safe(type) \
57do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
58 " membar " type "\n" \
59 "1:\n" \
60 : : : "memory"); \
61} while (0)
62
63#define mb() \
64 membar_safe("#LoadLoad | #LoadStore | #StoreStore | #StoreLoad")
65#define rmb() \
66 membar_safe("#LoadLoad")
67#define wmb() \
68 membar_safe("#StoreStore")
69#define membar_storeload() \
70 membar_safe("#StoreLoad")
71#define membar_storeload_storestore() \
72 membar_safe("#StoreLoad | #StoreStore")
73#define membar_storeload_loadload() \
74 membar_safe("#StoreLoad | #LoadLoad")
75#define membar_storestore_loadstore() \
76 membar_safe("#StoreStore | #LoadStore")
77
78#endif
79
80#define nop() __asm__ __volatile__ ("nop")
81
82#define read_barrier_depends() do { } while(0)
83#define set_mb(__var, __value) \
84 do { __var = __value; membar_storeload_storestore(); } while(0)
85
86#ifdef CONFIG_SMP
87#define smp_mb() mb()
88#define smp_rmb() rmb()
89#define smp_wmb() wmb()
90#define smp_read_barrier_depends() read_barrier_depends()
91#else
92#define smp_mb() __asm__ __volatile__("":::"memory")
93#define smp_rmb() __asm__ __volatile__("":::"memory")
94#define smp_wmb() __asm__ __volatile__("":::"memory")
95#define smp_read_barrier_depends() do { } while(0)
96#endif
97
98#define flushi(addr) __asm__ __volatile__ ("flush %0" : : "r" (addr) : "memory")
99
100#define flushw_all() __asm__ __volatile__("flushw")
101
102/* Performance counter register access. */
103#define read_pcr(__p) __asm__ __volatile__("rd %%pcr, %0" : "=r" (__p))
104#define write_pcr(__p) __asm__ __volatile__("wr %0, 0x0, %%pcr" : : "r" (__p))
105#define read_pic(__p) __asm__ __volatile__("rd %%pic, %0" : "=r" (__p))
106
107/* Blackbird errata workaround. See commentary in
108 * arch/sparc64/kernel/smp.c:smp_percpu_timer_interrupt()
109 * for more information.
110 */
111#define reset_pic() \
112 __asm__ __volatile__("ba,pt %xcc, 99f\n\t" \
113 ".align 64\n" \
114 "99:wr %g0, 0x0, %pic\n\t" \
115 "rd %pic, %g0")
116
117#ifndef __ASSEMBLY__
118
119extern void sun_do_break(void);
120extern int stop_a_enabled;
121
122extern void fault_in_user_windows(void);
123extern void synchronize_user_stack(void);
124
125extern void __flushw_user(void);
126#define flushw_user() __flushw_user()
127
128#define flush_user_windows flushw_user
129#define flush_register_windows flushw_all
130
131/* Don't hold the runqueue lock over context switch */
132#define __ARCH_WANT_UNLOCKED_CTXSW
133#define prepare_arch_switch(next) \
134do { \
135 flushw_all(); \
136} while (0)
137
138 /* See what happens when you design the chip correctly?
139 *
140 * We tell gcc we clobber all non-fixed-usage registers except
141 * for l0/l1. It will use one for 'next' and the other to hold
142 * the output value of 'last'. 'next' is not referenced again
143 * past the invocation of switch_to in the scheduler, so we need
144 * not preserve it's value. Hairy, but it lets us remove 2 loads
145 * and 2 stores in this critical code path. -DaveM
146 */
147#define switch_to(prev, next, last) \
148do { if (test_thread_flag(TIF_PERFCTR)) { \
149 unsigned long __tmp; \
150 read_pcr(__tmp); \
151 current_thread_info()->pcr_reg = __tmp; \
152 read_pic(__tmp); \
153 current_thread_info()->kernel_cntd0 += (unsigned int)(__tmp);\
154 current_thread_info()->kernel_cntd1 += ((__tmp) >> 32); \
155 } \
156 flush_tlb_pending(); \
157 save_and_clear_fpu(); \
158 /* If you are tempted to conditionalize the following */ \
159 /* so that ASI is only written if it changes, think again. */ \
160 __asm__ __volatile__("wr %%g0, %0, %%asi" \
161 : : "r" (__thread_flag_byte_ptr(task_thread_info(next))[TI_FLAG_BYTE_CURRENT_DS]));\
162 trap_block[current_thread_info()->cpu].thread = \
163 task_thread_info(next); \
164 __asm__ __volatile__( \
165 "mov %%g4, %%g7\n\t" \
166 "stx %%i6, [%%sp + 2047 + 0x70]\n\t" \
167 "stx %%i7, [%%sp + 2047 + 0x78]\n\t" \
168 "rdpr %%wstate, %%o5\n\t" \
169 "stx %%o6, [%%g6 + %6]\n\t" \
170 "stb %%o5, [%%g6 + %5]\n\t" \
171 "rdpr %%cwp, %%o5\n\t" \
172 "stb %%o5, [%%g6 + %8]\n\t" \
173 "mov %4, %%g6\n\t" \
174 "ldub [%4 + %8], %%g1\n\t" \
175 "wrpr %%g1, %%cwp\n\t" \
176 "ldx [%%g6 + %6], %%o6\n\t" \
177 "ldub [%%g6 + %5], %%o5\n\t" \
178 "ldub [%%g6 + %7], %%o7\n\t" \
179 "wrpr %%o5, 0x0, %%wstate\n\t" \
180 "ldx [%%sp + 2047 + 0x70], %%i6\n\t" \
181 "ldx [%%sp + 2047 + 0x78], %%i7\n\t" \
182 "ldx [%%g6 + %9], %%g4\n\t" \
183 "brz,pt %%o7, switch_to_pc\n\t" \
184 " mov %%g7, %0\n\t" \
185 "sethi %%hi(ret_from_syscall), %%g1\n\t" \
186 "jmpl %%g1 + %%lo(ret_from_syscall), %%g0\n\t" \
187 " nop\n\t" \
188 ".globl switch_to_pc\n\t" \
189 "switch_to_pc:\n\t" \
190 : "=&r" (last), "=r" (current), "=r" (current_thread_info_reg), \
191 "=r" (__local_per_cpu_offset) \
192 : "0" (task_thread_info(next)), \
193 "i" (TI_WSTATE), "i" (TI_KSP), "i" (TI_NEW_CHILD), \
194 "i" (TI_CWP), "i" (TI_TASK) \
195 : "cc", \
196 "g1", "g2", "g3", "g7", \
197 "l1", "l2", "l3", "l4", "l5", "l6", "l7", \
198 "i0", "i1", "i2", "i3", "i4", "i5", \
199 "o0", "o1", "o2", "o3", "o4", "o5", "o7"); \
200 /* If you fuck with this, update ret_from_syscall code too. */ \
201 if (test_thread_flag(TIF_PERFCTR)) { \
202 write_pcr(current_thread_info()->pcr_reg); \
203 reset_pic(); \
204 } \
205} while(0)
206
207static inline unsigned long xchg32(__volatile__ unsigned int *m, unsigned int val)
208{
209 unsigned long tmp1, tmp2;
210
211 __asm__ __volatile__(
212" membar #StoreLoad | #LoadLoad\n"
213" mov %0, %1\n"
214"1: lduw [%4], %2\n"
215" cas [%4], %2, %0\n"
216" cmp %2, %0\n"
217" bne,a,pn %%icc, 1b\n"
218" mov %1, %0\n"
219" membar #StoreLoad | #StoreStore\n"
220 : "=&r" (val), "=&r" (tmp1), "=&r" (tmp2)
221 : "0" (val), "r" (m)
222 : "cc", "memory");
223 return val;
224}
225
226static inline unsigned long xchg64(__volatile__ unsigned long *m, unsigned long val)
227{
228 unsigned long tmp1, tmp2;
229
230 __asm__ __volatile__(
231" membar #StoreLoad | #LoadLoad\n"
232" mov %0, %1\n"
233"1: ldx [%4], %2\n"
234" casx [%4], %2, %0\n"
235" cmp %2, %0\n"
236" bne,a,pn %%xcc, 1b\n"
237" mov %1, %0\n"
238" membar #StoreLoad | #StoreStore\n"
239 : "=&r" (val), "=&r" (tmp1), "=&r" (tmp2)
240 : "0" (val), "r" (m)
241 : "cc", "memory");
242 return val;
243}
244
245#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
246
247extern void __xchg_called_with_bad_pointer(void);
248
249static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr,
250 int size)
251{
252 switch (size) {
253 case 4:
254 return xchg32(ptr, x);
255 case 8:
256 return xchg64(ptr, x);
257 };
258 __xchg_called_with_bad_pointer();
259 return x;
260}
261
262extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noreturn));
263
264/*
265 * Atomic compare and exchange. Compare OLD with MEM, if identical,
266 * store NEW in MEM. Return the initial value in MEM. Success is
267 * indicated by comparing RETURN with OLD.
268 */
269
270#define __HAVE_ARCH_CMPXCHG 1
271
272static inline unsigned long
273__cmpxchg_u32(volatile int *m, int old, int new)
274{
275 __asm__ __volatile__("membar #StoreLoad | #LoadLoad\n"
276 "cas [%2], %3, %0\n\t"
277 "membar #StoreLoad | #StoreStore"
278 : "=&r" (new)
279 : "0" (new), "r" (m), "r" (old)
280 : "memory");
281
282 return new;
283}
284
285static inline unsigned long
286__cmpxchg_u64(volatile long *m, unsigned long old, unsigned long new)
287{
288 __asm__ __volatile__("membar #StoreLoad | #LoadLoad\n"
289 "casx [%2], %3, %0\n\t"
290 "membar #StoreLoad | #StoreStore"
291 : "=&r" (new)
292 : "0" (new), "r" (m), "r" (old)
293 : "memory");
294
295 return new;
296}
297
298/* This function doesn't exist, so you'll get a linker error
299 if something tries to do an invalid cmpxchg(). */
300extern void __cmpxchg_called_with_bad_pointer(void);
301
302static inline unsigned long
303__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
304{
305 switch (size) {
306 case 4:
307 return __cmpxchg_u32(ptr, old, new);
308 case 8:
309 return __cmpxchg_u64(ptr, old, new);
310 }
311 __cmpxchg_called_with_bad_pointer();
312 return old;
313}
314
315#define cmpxchg(ptr,o,n) \
316 ({ \
317 __typeof__(*(ptr)) _o_ = (o); \
318 __typeof__(*(ptr)) _n_ = (n); \
319 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
320 (unsigned long)_n_, sizeof(*(ptr))); \
321 })
322
323/*
324 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
325 * them available.
326 */
327
328static inline unsigned long __cmpxchg_local(volatile void *ptr,
329 unsigned long old,
330 unsigned long new, int size)
331{
332 switch (size) {
333 case 4:
334 case 8: return __cmpxchg(ptr, old, new, size);
335 default:
336 return __cmpxchg_local_generic(ptr, old, new, size);
337 }
338
339 return old;
340}
341
342#define cmpxchg_local(ptr, o, n) \
343 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
344 (unsigned long)(n), sizeof(*(ptr))))
345#define cmpxchg64_local(ptr, o, n) \
346 ({ \
347 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
348 cmpxchg_local((ptr), (o), (n)); \
349 })
350
351#endif /* !(__ASSEMBLY__) */
352
353#define arch_align_stack(x) (x)
354
355#endif /* !(__SPARC64_SYSTEM_H) */
diff --git a/include/asm-sparc/termbits.h b/include/asm-sparc/termbits.h
index 90cf2210118b..d6ca3e2754f5 100644
--- a/include/asm-sparc/termbits.h
+++ b/include/asm-sparc/termbits.h
@@ -5,7 +5,12 @@
5 5
6typedef unsigned char cc_t; 6typedef unsigned char cc_t;
7typedef unsigned int speed_t; 7typedef unsigned int speed_t;
8
9#if defined(__sparc__) && defined(__arch64__)
10typedef unsigned int tcflag_t;
11#else
8typedef unsigned long tcflag_t; 12typedef unsigned long tcflag_t;
13#endif
9 14
10#define NCC 8 15#define NCC 8
11struct termio { 16struct termio {
diff --git a/include/asm-sparc/termios.h b/include/asm-sparc/termios.h
index f7b4409c35ff..e8ba95399643 100644
--- a/include/asm-sparc/termios.h
+++ b/include/asm-sparc/termios.h
@@ -53,7 +53,6 @@ struct winsize {
53#define _VMIN 4 53#define _VMIN 4
54#define _VTIME 5 54#define _VTIME 5
55 55
56
57/* intr=^C quit=^\ erase=del kill=^U 56/* intr=^C quit=^\ erase=del kill=^U
58 eof=^D eol=\0 eol2=\0 sxtc=\0 57 eof=^D eol=\0 eol2=\0 sxtc=\0
59 start=^Q stop=^S susp=^Z dsusp=^Y 58 start=^Q stop=^S susp=^Z dsusp=^Y
@@ -68,16 +67,17 @@ struct winsize {
68#define user_termio_to_kernel_termios(termios, termio) \ 67#define user_termio_to_kernel_termios(termios, termio) \
69({ \ 68({ \
70 unsigned short tmp; \ 69 unsigned short tmp; \
71 get_user(tmp, &(termio)->c_iflag); \ 70 int err; \
71 err = get_user(tmp, &(termio)->c_iflag); \
72 (termios)->c_iflag = (0xffff0000 & ((termios)->c_iflag)) | tmp; \ 72 (termios)->c_iflag = (0xffff0000 & ((termios)->c_iflag)) | tmp; \
73 get_user(tmp, &(termio)->c_oflag); \ 73 err |= get_user(tmp, &(termio)->c_oflag); \
74 (termios)->c_oflag = (0xffff0000 & ((termios)->c_oflag)) | tmp; \ 74 (termios)->c_oflag = (0xffff0000 & ((termios)->c_oflag)) | tmp; \
75 get_user(tmp, &(termio)->c_cflag); \ 75 err |= get_user(tmp, &(termio)->c_cflag); \
76 (termios)->c_cflag = (0xffff0000 & ((termios)->c_cflag)) | tmp; \ 76 (termios)->c_cflag = (0xffff0000 & ((termios)->c_cflag)) | tmp; \
77 get_user(tmp, &(termio)->c_lflag); \ 77 err |= get_user(tmp, &(termio)->c_lflag); \
78 (termios)->c_lflag = (0xffff0000 & ((termios)->c_lflag)) | tmp; \ 78 (termios)->c_lflag = (0xffff0000 & ((termios)->c_lflag)) | tmp; \
79 copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \ 79 err |= copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
80 0; \ 80 err; \
81}) 81})
82 82
83/* 83/*
@@ -87,17 +87,18 @@ struct winsize {
87 */ 87 */
88#define kernel_termios_to_user_termio(termio, termios) \ 88#define kernel_termios_to_user_termio(termio, termios) \
89({ \ 89({ \
90 put_user((termios)->c_iflag, &(termio)->c_iflag); \ 90 int err; \
91 put_user((termios)->c_oflag, &(termio)->c_oflag); \ 91 err = put_user((termios)->c_iflag, &(termio)->c_iflag); \
92 put_user((termios)->c_cflag, &(termio)->c_cflag); \ 92 err |= put_user((termios)->c_oflag, &(termio)->c_oflag); \
93 put_user((termios)->c_lflag, &(termio)->c_lflag); \ 93 err |= put_user((termios)->c_cflag, &(termio)->c_cflag); \
94 put_user((termios)->c_line, &(termio)->c_line); \ 94 err |= put_user((termios)->c_lflag, &(termio)->c_lflag); \
95 copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \ 95 err |= put_user((termios)->c_line, &(termio)->c_line); \
96 err |= copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
96 if (!((termios)->c_lflag & ICANON)) { \ 97 if (!((termios)->c_lflag & ICANON)) { \
97 put_user((termios)->c_cc[VMIN], &(termio)->c_cc[_VMIN]); \ 98 err |= put_user((termios)->c_cc[VMIN], &(termio)->c_cc[_VMIN]); \
98 put_user((termios)->c_cc[VTIME], &(termio)->c_cc[_VTIME]); \ 99 err |= put_user((termios)->c_cc[VTIME], &(termio)->c_cc[_VTIME]); \
99 } \ 100 } \
100 0; \ 101 err; \
101}) 102})
102 103
103#define user_termios_to_kernel_termios(k, u) \ 104#define user_termios_to_kernel_termios(k, u) \
@@ -144,38 +145,40 @@ struct winsize {
144 145
145#define user_termios_to_kernel_termios_1(k, u) \ 146#define user_termios_to_kernel_termios_1(k, u) \
146({ \ 147({ \
147 get_user((k)->c_iflag, &(u)->c_iflag); \ 148 int err; \
148 get_user((k)->c_oflag, &(u)->c_oflag); \ 149 err = get_user((k)->c_iflag, &(u)->c_iflag); \
149 get_user((k)->c_cflag, &(u)->c_cflag); \ 150 err |= get_user((k)->c_oflag, &(u)->c_oflag); \
150 get_user((k)->c_lflag, &(u)->c_lflag); \ 151 err |= get_user((k)->c_cflag, &(u)->c_cflag); \
151 get_user((k)->c_line, &(u)->c_line); \ 152 err |= get_user((k)->c_lflag, &(u)->c_lflag); \
152 copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \ 153 err |= get_user((k)->c_line, &(u)->c_line); \
154 err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \
153 if ((k)->c_lflag & ICANON) { \ 155 if ((k)->c_lflag & ICANON) { \
154 get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \ 156 err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
155 get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \ 157 err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
156 } else { \ 158 } else { \
157 get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \ 159 err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
158 get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \ 160 err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
159 } \ 161 } \
160 0; \ 162 err; \
161}) 163})
162 164
163#define kernel_termios_to_user_termios_1(u, k) \ 165#define kernel_termios_to_user_termios_1(u, k) \
164({ \ 166({ \
165 put_user((k)->c_iflag, &(u)->c_iflag); \ 167 int err; \
166 put_user((k)->c_oflag, &(u)->c_oflag); \ 168 err = put_user((k)->c_iflag, &(u)->c_iflag); \
167 put_user((k)->c_cflag, &(u)->c_cflag); \ 169 err |= put_user((k)->c_oflag, &(u)->c_oflag); \
168 put_user((k)->c_lflag, &(u)->c_lflag); \ 170 err |= put_user((k)->c_cflag, &(u)->c_cflag); \
169 put_user((k)->c_line, &(u)->c_line); \ 171 err |= put_user((k)->c_lflag, &(u)->c_lflag); \
170 copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \ 172 err |= put_user((k)->c_line, &(u)->c_line); \
173 err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \
171 if (!((k)->c_lflag & ICANON)) { \ 174 if (!((k)->c_lflag & ICANON)) { \
172 put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \ 175 err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
173 put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \ 176 err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
174 } else { \ 177 } else { \
175 put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \ 178 err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
176 put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \ 179 err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
177 } \ 180 } \
178 0; \ 181 err; \
179}) 182})
180 183
181#endif /* __KERNEL__ */ 184#endif /* __KERNEL__ */
diff --git a/include/asm-sparc/thread_info.h b/include/asm-sparc/thread_info.h
index 91b9f5888c85..64155cf89f37 100644
--- a/include/asm-sparc/thread_info.h
+++ b/include/asm-sparc/thread_info.h
@@ -1,151 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_THREAD_INFO_H
2 * thread_info.h: sparc low-level thread information 2#define ___ASM_SPARC_THREAD_INFO_H
3 * adapted from the ppc version by Pete Zaitcev, which was 3#if defined(__sparc__) && defined(__arch64__)
4 * adapted from the i386 version by Paul Mackerras 4#include <asm-sparc/thread_info_64.h>
5 * 5#else
6 * Copyright (C) 2002 David Howells (dhowells@redhat.com) 6#include <asm-sparc/thread_info_32.h>
7 * Copyright (c) 2002 Pete Zaitcev (zaitcev@yahoo.com) 7#endif
8 * - Incorporating suggestions made by Linus Torvalds and Dave Miller
9 */
10
11#ifndef _ASM_THREAD_INFO_H
12#define _ASM_THREAD_INFO_H
13
14#ifdef __KERNEL__
15
16#ifndef __ASSEMBLY__
17
18#include <asm/btfixup.h>
19#include <asm/ptrace.h>
20#include <asm/page.h>
21
22/*
23 * Low level task data.
24 *
25 * If you change this, change the TI_* offsets below to match.
26 */
27#define NSWINS 8
28struct thread_info {
29 unsigned long uwinmask;
30 struct task_struct *task; /* main task structure */
31 struct exec_domain *exec_domain; /* execution domain */
32 unsigned long flags; /* low level flags */
33 int cpu; /* cpu we're on */
34 int preempt_count; /* 0 => preemptable,
35 <0 => BUG */
36 int softirq_count;
37 int hardirq_count;
38
39 /* Context switch saved kernel state. */
40 unsigned long ksp; /* ... ksp __attribute__ ((aligned (8))); */
41 unsigned long kpc;
42 unsigned long kpsr;
43 unsigned long kwim;
44
45 /* A place to store user windows and stack pointers
46 * when the stack needs inspection.
47 */
48 struct reg_window reg_window[NSWINS]; /* align for ldd! */
49 unsigned long rwbuf_stkptrs[NSWINS];
50 unsigned long w_saved;
51
52 struct restart_block restart_block;
53};
54
55/*
56 * macros/functions for gaining access to the thread information structure
57 *
58 * preempt_count needs to be 1 initially, until the scheduler is functional.
59 */
60#define INIT_THREAD_INFO(tsk) \
61{ \
62 .uwinmask = 0, \
63 .task = &tsk, \
64 .exec_domain = &default_exec_domain, \
65 .flags = 0, \
66 .cpu = 0, \
67 .preempt_count = 1, \
68 .restart_block = { \
69 .fn = do_no_restart_syscall, \
70 }, \
71}
72
73#define init_thread_info (init_thread_union.thread_info)
74#define init_stack (init_thread_union.stack)
75
76/* how to get the thread information struct from C */
77register struct thread_info *current_thread_info_reg asm("g6");
78#define current_thread_info() (current_thread_info_reg)
79
80/*
81 * thread information allocation
82 */
83#if PAGE_SHIFT == 13
84#define THREAD_INFO_ORDER 0
85#else /* PAGE_SHIFT */
86#define THREAD_INFO_ORDER 1
87#endif 8#endif
88
89BTFIXUPDEF_CALL(struct thread_info *, alloc_thread_info, void)
90#define alloc_thread_info(tsk) BTFIXUP_CALL(alloc_thread_info)()
91
92BTFIXUPDEF_CALL(void, free_thread_info, struct thread_info *)
93#define free_thread_info(ti) BTFIXUP_CALL(free_thread_info)(ti)
94
95#endif /* __ASSEMBLY__ */
96
97/*
98 * Size of kernel stack for each process.
99 * Observe the order of get_free_pages() in alloc_thread_info().
100 * The sun4 has 8K stack too, because it's short on memory, and 16K is a waste.
101 */
102#define THREAD_SIZE 8192
103
104/*
105 * Offsets in thread_info structure, used in assembly code
106 * The "#define REGWIN_SZ 0x40" was abolished, so no multiplications.
107 */
108#define TI_UWINMASK 0x00 /* uwinmask */
109#define TI_TASK 0x04
110#define TI_EXECDOMAIN 0x08 /* exec_domain */
111#define TI_FLAGS 0x0c
112#define TI_CPU 0x10
113#define TI_PREEMPT 0x14 /* preempt_count */
114#define TI_SOFTIRQ 0x18 /* softirq_count */
115#define TI_HARDIRQ 0x1c /* hardirq_count */
116#define TI_KSP 0x20 /* ksp */
117#define TI_KPC 0x24 /* kpc (ldd'ed with kpc) */
118#define TI_KPSR 0x28 /* kpsr */
119#define TI_KWIM 0x2c /* kwim (ldd'ed with kpsr) */
120#define TI_REG_WINDOW 0x30
121#define TI_RWIN_SPTRS 0x230
122#define TI_W_SAVED 0x250
123/* #define TI_RESTART_BLOCK 0x25n */ /* Nobody cares */
124
125#define PREEMPT_ACTIVE 0x4000000
126
127/*
128 * thread information flag bit numbers
129 */
130#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
131/* flag bit 1 is available */
132#define TIF_SIGPENDING 2 /* signal pending */
133#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
134#define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
135#define TIF_USEDFPU 8 /* FPU was used by this task
136 * this quantum (SMP) */
137#define TIF_POLLING_NRFLAG 9 /* true if poll_idle() is polling
138 * TIF_NEED_RESCHED */
139#define TIF_MEMDIE 10
140
141/* as above, but as bit values */
142#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
143#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
144#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
145#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)
146#define _TIF_USEDFPU (1<<TIF_USEDFPU)
147#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
148
149#endif /* __KERNEL__ */
150
151#endif /* _ASM_THREAD_INFO_H */
diff --git a/include/asm-sparc/thread_info_32.h b/include/asm-sparc/thread_info_32.h
new file mode 100644
index 000000000000..91b9f5888c85
--- /dev/null
+++ b/include/asm-sparc/thread_info_32.h
@@ -0,0 +1,151 @@
1/*
2 * thread_info.h: sparc low-level thread information
3 * adapted from the ppc version by Pete Zaitcev, which was
4 * adapted from the i386 version by Paul Mackerras
5 *
6 * Copyright (C) 2002 David Howells (dhowells@redhat.com)
7 * Copyright (c) 2002 Pete Zaitcev (zaitcev@yahoo.com)
8 * - Incorporating suggestions made by Linus Torvalds and Dave Miller
9 */
10
11#ifndef _ASM_THREAD_INFO_H
12#define _ASM_THREAD_INFO_H
13
14#ifdef __KERNEL__
15
16#ifndef __ASSEMBLY__
17
18#include <asm/btfixup.h>
19#include <asm/ptrace.h>
20#include <asm/page.h>
21
22/*
23 * Low level task data.
24 *
25 * If you change this, change the TI_* offsets below to match.
26 */
27#define NSWINS 8
28struct thread_info {
29 unsigned long uwinmask;
30 struct task_struct *task; /* main task structure */
31 struct exec_domain *exec_domain; /* execution domain */
32 unsigned long flags; /* low level flags */
33 int cpu; /* cpu we're on */
34 int preempt_count; /* 0 => preemptable,
35 <0 => BUG */
36 int softirq_count;
37 int hardirq_count;
38
39 /* Context switch saved kernel state. */
40 unsigned long ksp; /* ... ksp __attribute__ ((aligned (8))); */
41 unsigned long kpc;
42 unsigned long kpsr;
43 unsigned long kwim;
44
45 /* A place to store user windows and stack pointers
46 * when the stack needs inspection.
47 */
48 struct reg_window reg_window[NSWINS]; /* align for ldd! */
49 unsigned long rwbuf_stkptrs[NSWINS];
50 unsigned long w_saved;
51
52 struct restart_block restart_block;
53};
54
55/*
56 * macros/functions for gaining access to the thread information structure
57 *
58 * preempt_count needs to be 1 initially, until the scheduler is functional.
59 */
60#define INIT_THREAD_INFO(tsk) \
61{ \
62 .uwinmask = 0, \
63 .task = &tsk, \
64 .exec_domain = &default_exec_domain, \
65 .flags = 0, \
66 .cpu = 0, \
67 .preempt_count = 1, \
68 .restart_block = { \
69 .fn = do_no_restart_syscall, \
70 }, \
71}
72
73#define init_thread_info (init_thread_union.thread_info)
74#define init_stack (init_thread_union.stack)
75
76/* how to get the thread information struct from C */
77register struct thread_info *current_thread_info_reg asm("g6");
78#define current_thread_info() (current_thread_info_reg)
79
80/*
81 * thread information allocation
82 */
83#if PAGE_SHIFT == 13
84#define THREAD_INFO_ORDER 0
85#else /* PAGE_SHIFT */
86#define THREAD_INFO_ORDER 1
87#endif
88
89BTFIXUPDEF_CALL(struct thread_info *, alloc_thread_info, void)
90#define alloc_thread_info(tsk) BTFIXUP_CALL(alloc_thread_info)()
91
92BTFIXUPDEF_CALL(void, free_thread_info, struct thread_info *)
93#define free_thread_info(ti) BTFIXUP_CALL(free_thread_info)(ti)
94
95#endif /* __ASSEMBLY__ */
96
97/*
98 * Size of kernel stack for each process.
99 * Observe the order of get_free_pages() in alloc_thread_info().
100 * The sun4 has 8K stack too, because it's short on memory, and 16K is a waste.
101 */
102#define THREAD_SIZE 8192
103
104/*
105 * Offsets in thread_info structure, used in assembly code
106 * The "#define REGWIN_SZ 0x40" was abolished, so no multiplications.
107 */
108#define TI_UWINMASK 0x00 /* uwinmask */
109#define TI_TASK 0x04
110#define TI_EXECDOMAIN 0x08 /* exec_domain */
111#define TI_FLAGS 0x0c
112#define TI_CPU 0x10
113#define TI_PREEMPT 0x14 /* preempt_count */
114#define TI_SOFTIRQ 0x18 /* softirq_count */
115#define TI_HARDIRQ 0x1c /* hardirq_count */
116#define TI_KSP 0x20 /* ksp */
117#define TI_KPC 0x24 /* kpc (ldd'ed with kpc) */
118#define TI_KPSR 0x28 /* kpsr */
119#define TI_KWIM 0x2c /* kwim (ldd'ed with kpsr) */
120#define TI_REG_WINDOW 0x30
121#define TI_RWIN_SPTRS 0x230
122#define TI_W_SAVED 0x250
123/* #define TI_RESTART_BLOCK 0x25n */ /* Nobody cares */
124
125#define PREEMPT_ACTIVE 0x4000000
126
127/*
128 * thread information flag bit numbers
129 */
130#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
131/* flag bit 1 is available */
132#define TIF_SIGPENDING 2 /* signal pending */
133#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
134#define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
135#define TIF_USEDFPU 8 /* FPU was used by this task
136 * this quantum (SMP) */
137#define TIF_POLLING_NRFLAG 9 /* true if poll_idle() is polling
138 * TIF_NEED_RESCHED */
139#define TIF_MEMDIE 10
140
141/* as above, but as bit values */
142#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
143#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
144#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
145#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)
146#define _TIF_USEDFPU (1<<TIF_USEDFPU)
147#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
148
149#endif /* __KERNEL__ */
150
151#endif /* _ASM_THREAD_INFO_H */
diff --git a/include/asm-sparc/thread_info_64.h b/include/asm-sparc/thread_info_64.h
new file mode 100644
index 000000000000..c6d2e6c7f844
--- /dev/null
+++ b/include/asm-sparc/thread_info_64.h
@@ -0,0 +1,277 @@
1/* thread_info.h: sparc64 low-level thread information
2 *
3 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
4 */
5
6#ifndef _ASM_THREAD_INFO_H
7#define _ASM_THREAD_INFO_H
8
9#ifdef __KERNEL__
10
11#define NSWINS 7
12
13#define TI_FLAG_BYTE_FAULT_CODE 0
14#define TI_FLAG_FAULT_CODE_SHIFT 56
15#define TI_FLAG_BYTE_WSTATE 1
16#define TI_FLAG_WSTATE_SHIFT 48
17#define TI_FLAG_BYTE_CWP 2
18#define TI_FLAG_CWP_SHIFT 40
19#define TI_FLAG_BYTE_CURRENT_DS 3
20#define TI_FLAG_CURRENT_DS_SHIFT 32
21#define TI_FLAG_BYTE_FPDEPTH 4
22#define TI_FLAG_FPDEPTH_SHIFT 24
23#define TI_FLAG_BYTE_WSAVED 5
24#define TI_FLAG_WSAVED_SHIFT 16
25
26#include <asm/page.h>
27
28#ifndef __ASSEMBLY__
29
30#include <asm/ptrace.h>
31#include <asm/types.h>
32
33struct task_struct;
34struct exec_domain;
35
36struct thread_info {
37 /* D$ line 1 */
38 struct task_struct *task;
39 unsigned long flags;
40 __u8 fpsaved[7];
41 __u8 status;
42 unsigned long ksp;
43
44 /* D$ line 2 */
45 unsigned long fault_address;
46 struct pt_regs *kregs;
47 struct exec_domain *exec_domain;
48 int preempt_count; /* 0 => preemptable, <0 => BUG */
49 __u8 new_child;
50 __u8 syscall_noerror;
51 __u16 cpu;
52
53 unsigned long *utraps;
54
55 struct reg_window reg_window[NSWINS];
56 unsigned long rwbuf_stkptrs[NSWINS];
57
58 unsigned long gsr[7];
59 unsigned long xfsr[7];
60
61 __u64 __user *user_cntd0;
62 __u64 __user *user_cntd1;
63 __u64 kernel_cntd0, kernel_cntd1;
64 __u64 pcr_reg;
65
66 struct restart_block restart_block;
67
68 struct pt_regs *kern_una_regs;
69 unsigned int kern_una_insn;
70
71 unsigned long fpregs[0] __attribute__ ((aligned(64)));
72};
73
74#endif /* !(__ASSEMBLY__) */
75
76/* offsets into the thread_info struct for assembly code access */
77#define TI_TASK 0x00000000
78#define TI_FLAGS 0x00000008
79#define TI_FAULT_CODE (TI_FLAGS + TI_FLAG_BYTE_FAULT_CODE)
80#define TI_WSTATE (TI_FLAGS + TI_FLAG_BYTE_WSTATE)
81#define TI_CWP (TI_FLAGS + TI_FLAG_BYTE_CWP)
82#define TI_CURRENT_DS (TI_FLAGS + TI_FLAG_BYTE_CURRENT_DS)
83#define TI_FPDEPTH (TI_FLAGS + TI_FLAG_BYTE_FPDEPTH)
84#define TI_WSAVED (TI_FLAGS + TI_FLAG_BYTE_WSAVED)
85#define TI_FPSAVED 0x00000010
86#define TI_KSP 0x00000018
87#define TI_FAULT_ADDR 0x00000020
88#define TI_KREGS 0x00000028
89#define TI_EXEC_DOMAIN 0x00000030
90#define TI_PRE_COUNT 0x00000038
91#define TI_NEW_CHILD 0x0000003c
92#define TI_SYS_NOERROR 0x0000003d
93#define TI_CPU 0x0000003e
94#define TI_UTRAPS 0x00000040
95#define TI_REG_WINDOW 0x00000048
96#define TI_RWIN_SPTRS 0x000003c8
97#define TI_GSR 0x00000400
98#define TI_XFSR 0x00000438
99#define TI_USER_CNTD0 0x00000470
100#define TI_USER_CNTD1 0x00000478
101#define TI_KERN_CNTD0 0x00000480
102#define TI_KERN_CNTD1 0x00000488
103#define TI_PCR 0x00000490
104#define TI_RESTART_BLOCK 0x00000498
105#define TI_KUNA_REGS 0x000004c0
106#define TI_KUNA_INSN 0x000004c8
107#define TI_FPREGS 0x00000500
108
109/* We embed this in the uppermost byte of thread_info->flags */
110#define FAULT_CODE_WRITE 0x01 /* Write access, implies D-TLB */
111#define FAULT_CODE_DTLB 0x02 /* Miss happened in D-TLB */
112#define FAULT_CODE_ITLB 0x04 /* Miss happened in I-TLB */
113#define FAULT_CODE_WINFIXUP 0x08 /* Miss happened during spill/fill */
114#define FAULT_CODE_BLKCOMMIT 0x10 /* Use blk-commit ASI in copy_page */
115
116#if PAGE_SHIFT == 13
117#define THREAD_SIZE (2*PAGE_SIZE)
118#define THREAD_SHIFT (PAGE_SHIFT + 1)
119#else /* PAGE_SHIFT == 13 */
120#define THREAD_SIZE PAGE_SIZE
121#define THREAD_SHIFT PAGE_SHIFT
122#endif /* PAGE_SHIFT == 13 */
123
124#define PREEMPT_ACTIVE 0x4000000
125
126/*
127 * macros/functions for gaining access to the thread information structure
128 *
129 * preempt_count needs to be 1 initially, until the scheduler is functional.
130 */
131#ifndef __ASSEMBLY__
132
133#define INIT_THREAD_INFO(tsk) \
134{ \
135 .task = &tsk, \
136 .flags = ((unsigned long)ASI_P) << TI_FLAG_CURRENT_DS_SHIFT, \
137 .exec_domain = &default_exec_domain, \
138 .preempt_count = 1, \
139 .restart_block = { \
140 .fn = do_no_restart_syscall, \
141 }, \
142}
143
144#define init_thread_info (init_thread_union.thread_info)
145#define init_stack (init_thread_union.stack)
146
147/* how to get the thread information struct from C */
148register struct thread_info *current_thread_info_reg asm("g6");
149#define current_thread_info() (current_thread_info_reg)
150
151/* thread information allocation */
152#if PAGE_SHIFT == 13
153#define __THREAD_INFO_ORDER 1
154#else /* PAGE_SHIFT == 13 */
155#define __THREAD_INFO_ORDER 0
156#endif /* PAGE_SHIFT == 13 */
157
158#ifdef CONFIG_DEBUG_STACK_USAGE
159#define alloc_thread_info(tsk) \
160({ \
161 struct thread_info *ret; \
162 \
163 ret = (struct thread_info *) \
164 __get_free_pages(GFP_KERNEL, __THREAD_INFO_ORDER); \
165 if (ret) \
166 memset(ret, 0, PAGE_SIZE<<__THREAD_INFO_ORDER); \
167 ret; \
168})
169#else
170#define alloc_thread_info(tsk) \
171 ((struct thread_info *)__get_free_pages(GFP_KERNEL, __THREAD_INFO_ORDER))
172#endif
173
174#define free_thread_info(ti) \
175 free_pages((unsigned long)(ti),__THREAD_INFO_ORDER)
176
177#define __thread_flag_byte_ptr(ti) \
178 ((unsigned char *)(&((ti)->flags)))
179#define __cur_thread_flag_byte_ptr __thread_flag_byte_ptr(current_thread_info())
180
181#define get_thread_fault_code() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE])
182#define set_thread_fault_code(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE] = (val))
183#define get_thread_wstate() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE])
184#define set_thread_wstate(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE] = (val))
185#define get_thread_cwp() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP])
186#define set_thread_cwp(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP] = (val))
187#define get_thread_current_ds() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CURRENT_DS])
188#define set_thread_current_ds(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CURRENT_DS] = (val))
189#define get_thread_fpdepth() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH])
190#define set_thread_fpdepth(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH] = (val))
191#define get_thread_wsaved() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED])
192#define set_thread_wsaved(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED] = (val))
193
194#endif /* !(__ASSEMBLY__) */
195
196/*
197 * Thread information flags, only 16 bits are available as we encode
198 * other values into the upper 6 bytes.
199 *
200 * On trap return we need to test several values:
201 *
202 * user: need_resched, notify_resume, sigpending, wsaved, perfctr
203 * kernel: fpdepth
204 *
205 * So to check for work in the kernel case we simply load the fpdepth
206 * byte out of the flags and test it. For the user case we encode the
207 * lower 3 bytes of flags as follows:
208 * ----------------------------------------
209 * | wsaved | flags byte 1 | flags byte 2 |
210 * ----------------------------------------
211 * This optimizes the user test into:
212 * ldx [%g6 + TI_FLAGS], REG1
213 * sethi %hi(_TIF_USER_WORK_MASK), REG2
214 * or REG2, %lo(_TIF_USER_WORK_MASK), REG2
215 * andcc REG1, REG2, %g0
216 * be,pt no_work_to_do
217 * nop
218 */
219#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
220/* flags bit 1 is available */
221#define TIF_SIGPENDING 2 /* signal pending */
222#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
223#define TIF_PERFCTR 4 /* performance counters active */
224#define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
225/* flag bit 6 is available */
226#define TIF_32BIT 7 /* 32-bit binary */
227/* flag bit 8 is available */
228#define TIF_SECCOMP 9 /* secure computing */
229#define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
230/* flag bit 11 is available */
231/* NOTE: Thread flags >= 12 should be ones we have no interest
232 * in using in assembly, else we can't use the mask as
233 * an immediate value in instructions such as andcc.
234 */
235#define TIF_ABI_PENDING 12
236#define TIF_MEMDIE 13
237#define TIF_POLLING_NRFLAG 14
238
239#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
240#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
241#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
242#define _TIF_PERFCTR (1<<TIF_PERFCTR)
243#define _TIF_UNALIGNED (1<<TIF_UNALIGNED)
244#define _TIF_32BIT (1<<TIF_32BIT)
245#define _TIF_SECCOMP (1<<TIF_SECCOMP)
246#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
247#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)
248#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
249
250#define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
251 (_TIF_SIGPENDING | \
252 _TIF_NEED_RESCHED | _TIF_PERFCTR))
253
254/*
255 * Thread-synchronous status.
256 *
257 * This is different from the flags in that nobody else
258 * ever touches our thread-synchronous status, so we don't
259 * have to worry about atomic accesses.
260 *
261 * Note that there are only 8 bits available.
262 */
263#define TS_RESTORE_SIGMASK 0x0001 /* restore signal mask in do_signal() */
264
265#ifndef __ASSEMBLY__
266#define HAVE_SET_RESTORE_SIGMASK 1
267static inline void set_restore_sigmask(void)
268{
269 struct thread_info *ti = current_thread_info();
270 ti->status |= TS_RESTORE_SIGMASK;
271 set_bit(TIF_SIGPENDING, &ti->flags);
272}
273#endif /* !__ASSEMBLY__ */
274
275#endif /* __KERNEL__ */
276
277#endif /* _ASM_THREAD_INFO_H */
diff --git a/include/asm-sparc/timer.h b/include/asm-sparc/timer.h
index d909565f9410..475baa05a96e 100644
--- a/include/asm-sparc/timer.h
+++ b/include/asm-sparc/timer.h
@@ -1,109 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_TIMER_H
2 * timer.h: Definitions for the timer chips on the Sparc. 2#define ___ASM_SPARC_TIMER_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 4#include <asm-sparc/timer_64.h>
5 */
6
7
8#ifndef _SPARC_TIMER_H
9#define _SPARC_TIMER_H
10
11#include <asm/system.h> /* For SUN4M_NCPUS */
12#include <asm/sun4paddr.h>
13#include <asm/btfixup.h>
14
15/* Timer structures. The interrupt timer has two properties which
16 * are the counter (which is handled in do_timer in sched.c) and the limit.
17 * This limit is where the timer's counter 'wraps' around. Oddly enough,
18 * the sun4c timer when it hits the limit wraps back to 1 and not zero
19 * thus when calculating the value at which it will fire a microsecond you
20 * must adjust by one. Thanks SUN for designing such great hardware ;(
21 */
22
23/* Note that I am only going to use the timer that interrupts at
24 * Sparc IRQ 10. There is another one available that can fire at
25 * IRQ 14. Currently it is left untouched, we keep the PROM's limit
26 * register value and let the prom take these interrupts. This allows
27 * L1-A to work.
28 */
29
30struct sun4c_timer_info {
31 __volatile__ unsigned int cur_count10;
32 __volatile__ unsigned int timer_limit10;
33 __volatile__ unsigned int cur_count14;
34 __volatile__ unsigned int timer_limit14;
35};
36
37#define SUN4C_TIMER_PHYSADDR 0xf3000000
38#ifdef CONFIG_SUN4
39#define SUN_TIMER_PHYSADDR SUN4_300_TIMER_PHYSADDR
40#else 5#else
41#define SUN_TIMER_PHYSADDR SUN4C_TIMER_PHYSADDR 6#include <asm-sparc/timer_32.h>
7#endif
42#endif 8#endif
43
44/* A sun4m has two blocks of registers which are probably of the same
45 * structure. LSI Logic's L64851 is told to _decrement_ from the limit
46 * value. Aurora behaves similarly but its limit value is compacted in
47 * other fashion (it's wider). Documented fields are defined here.
48 */
49
50/* As with the interrupt register, we have two classes of timer registers
51 * which are per-cpu and master. Per-cpu timers only hit that cpu and are
52 * only level 14 ticks, master timer hits all cpus and is level 10.
53 */
54
55#define SUN4M_PRM_CNT_L 0x80000000
56#define SUN4M_PRM_CNT_LVALUE 0x7FFFFC00
57
58struct sun4m_timer_percpu_info {
59 __volatile__ unsigned int l14_timer_limit; /* Initial value is 0x009c4000 */
60 __volatile__ unsigned int l14_cur_count;
61
62 /* This register appears to be write only and/or inaccessible
63 * on Uni-Processor sun4m machines.
64 */
65 __volatile__ unsigned int l14_limit_noclear; /* Data access error is here */
66
67 __volatile__ unsigned int cntrl; /* =1 after POST on Aurora */
68 __volatile__ unsigned char space[PAGE_SIZE - 16];
69};
70
71struct sun4m_timer_regs {
72 struct sun4m_timer_percpu_info cpu_timers[SUN4M_NCPUS];
73 volatile unsigned int l10_timer_limit;
74 volatile unsigned int l10_cur_count;
75
76 /* Again, this appears to be write only and/or inaccessible
77 * on uni-processor sun4m machines.
78 */
79 volatile unsigned int l10_limit_noclear;
80
81 /* This register too, it must be magic. */
82 volatile unsigned int foobar;
83
84 volatile unsigned int cfg; /* equals zero at boot time... */
85};
86
87extern struct sun4m_timer_regs *sun4m_timers;
88
89#define SUN4D_PRM_CNT_L 0x80000000
90#define SUN4D_PRM_CNT_LVALUE 0x7FFFFC00
91
92struct sun4d_timer_regs {
93 volatile unsigned int l10_timer_limit;
94 volatile unsigned int l10_cur_countx;
95 volatile unsigned int l10_limit_noclear;
96 volatile unsigned int ctrl;
97 volatile unsigned int l10_cur_count;
98};
99
100extern struct sun4d_timer_regs *sun4d_timers;
101
102extern __volatile__ unsigned int *master_l10_counter;
103extern __volatile__ unsigned int *master_l10_limit;
104
105/* FIXME: Make do_[gs]ettimeofday btfixup calls */
106BTFIXUPDEF_CALL(int, bus_do_settimeofday, struct timespec *tv)
107#define bus_do_settimeofday(tv) BTFIXUP_CALL(bus_do_settimeofday)(tv)
108
109#endif /* !(_SPARC_TIMER_H) */
diff --git a/include/asm-sparc/timer_32.h b/include/asm-sparc/timer_32.h
new file mode 100644
index 000000000000..361e53898dd7
--- /dev/null
+++ b/include/asm-sparc/timer_32.h
@@ -0,0 +1,107 @@
1/*
2 * timer.h: Definitions for the timer chips on the Sparc.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7
8#ifndef _SPARC_TIMER_H
9#define _SPARC_TIMER_H
10
11#include <asm/system.h> /* For SUN4M_NCPUS */
12#include <asm/sun4paddr.h>
13#include <asm/btfixup.h>
14
15/* Timer structures. The interrupt timer has two properties which
16 * are the counter (which is handled in do_timer in sched.c) and the limit.
17 * This limit is where the timer's counter 'wraps' around. Oddly enough,
18 * the sun4c timer when it hits the limit wraps back to 1 and not zero
19 * thus when calculating the value at which it will fire a microsecond you
20 * must adjust by one. Thanks SUN for designing such great hardware ;(
21 */
22
23/* Note that I am only going to use the timer that interrupts at
24 * Sparc IRQ 10. There is another one available that can fire at
25 * IRQ 14. Currently it is left untouched, we keep the PROM's limit
26 * register value and let the prom take these interrupts. This allows
27 * L1-A to work.
28 */
29
30struct sun4c_timer_info {
31 __volatile__ unsigned int cur_count10;
32 __volatile__ unsigned int timer_limit10;
33 __volatile__ unsigned int cur_count14;
34 __volatile__ unsigned int timer_limit14;
35};
36
37#define SUN4C_TIMER_PHYSADDR 0xf3000000
38#ifdef CONFIG_SUN4
39#define SUN_TIMER_PHYSADDR SUN4_300_TIMER_PHYSADDR
40#else
41#define SUN_TIMER_PHYSADDR SUN4C_TIMER_PHYSADDR
42#endif
43
44/* A sun4m has two blocks of registers which are probably of the same
45 * structure. LSI Logic's L64851 is told to _decrement_ from the limit
46 * value. Aurora behaves similarly but its limit value is compacted in
47 * other fashion (it's wider). Documented fields are defined here.
48 */
49
50/* As with the interrupt register, we have two classes of timer registers
51 * which are per-cpu and master. Per-cpu timers only hit that cpu and are
52 * only level 14 ticks, master timer hits all cpus and is level 10.
53 */
54
55#define SUN4M_PRM_CNT_L 0x80000000
56#define SUN4M_PRM_CNT_LVALUE 0x7FFFFC00
57
58struct sun4m_timer_percpu_info {
59 __volatile__ unsigned int l14_timer_limit; /* Initial value is 0x009c4000 */
60 __volatile__ unsigned int l14_cur_count;
61
62 /* This register appears to be write only and/or inaccessible
63 * on Uni-Processor sun4m machines.
64 */
65 __volatile__ unsigned int l14_limit_noclear; /* Data access error is here */
66
67 __volatile__ unsigned int cntrl; /* =1 after POST on Aurora */
68 __volatile__ unsigned char space[PAGE_SIZE - 16];
69};
70
71struct sun4m_timer_regs {
72 struct sun4m_timer_percpu_info cpu_timers[SUN4M_NCPUS];
73 volatile unsigned int l10_timer_limit;
74 volatile unsigned int l10_cur_count;
75
76 /* Again, this appears to be write only and/or inaccessible
77 * on uni-processor sun4m machines.
78 */
79 volatile unsigned int l10_limit_noclear;
80
81 /* This register too, it must be magic. */
82 volatile unsigned int foobar;
83
84 volatile unsigned int cfg; /* equals zero at boot time... */
85};
86
87#define SUN4D_PRM_CNT_L 0x80000000
88#define SUN4D_PRM_CNT_LVALUE 0x7FFFFC00
89
90struct sun4d_timer_regs {
91 volatile unsigned int l10_timer_limit;
92 volatile unsigned int l10_cur_countx;
93 volatile unsigned int l10_limit_noclear;
94 volatile unsigned int ctrl;
95 volatile unsigned int l10_cur_count;
96};
97
98extern struct sun4d_timer_regs *sun4d_timers;
99
100extern __volatile__ unsigned int *master_l10_counter;
101extern __volatile__ unsigned int *master_l10_limit;
102
103/* FIXME: Make do_[gs]ettimeofday btfixup calls */
104BTFIXUPDEF_CALL(int, bus_do_settimeofday, struct timespec *tv)
105#define bus_do_settimeofday(tv) BTFIXUP_CALL(bus_do_settimeofday)(tv)
106
107#endif /* !(_SPARC_TIMER_H) */
diff --git a/include/asm-sparc/timer_64.h b/include/asm-sparc/timer_64.h
new file mode 100644
index 000000000000..5b779fd1f788
--- /dev/null
+++ b/include/asm-sparc/timer_64.h
@@ -0,0 +1,30 @@
1/* timer.h: System timer definitions for sun5.
2 *
3 * Copyright (C) 1997, 2008 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_TIMER_H
7#define _SPARC64_TIMER_H
8
9#include <linux/types.h>
10#include <linux/init.h>
11
12struct sparc64_tick_ops {
13 unsigned long (*get_tick)(void);
14 int (*add_compare)(unsigned long);
15 unsigned long softint_mask;
16 void (*disable_irq)(void);
17
18 void (*init_tick)(void);
19 unsigned long (*add_tick)(unsigned long);
20
21 char *name;
22};
23
24extern struct sparc64_tick_ops *tick_ops;
25
26extern unsigned long sparc64_get_clock_tick(unsigned int cpu);
27extern void __devinit setup_sparc64_timer(void);
28extern void __init time_init(void);
29
30#endif /* _SPARC64_TIMER_H */
diff --git a/include/asm-sparc/timex.h b/include/asm-sparc/timex.h
index 71b45c90ccae..01d9f199d452 100644
--- a/include/asm-sparc/timex.h
+++ b/include/asm-sparc/timex.h
@@ -1,15 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_TIMEX_H
2 * linux/include/asm-sparc/timex.h 2#define ___ASM_SPARC_TIMEX_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * sparc architecture timex specifications 4#include <asm-sparc/timex_64.h>
5 */ 5#else
6#ifndef _ASMsparc_TIMEX_H 6#include <asm-sparc/timex_32.h>
7#define _ASMsparc_TIMEX_H 7#endif
8
9#define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
10
11/* XXX Maybe do something better at some point... -DaveM */
12typedef unsigned long cycles_t;
13#define get_cycles() (0)
14
15#endif 8#endif
diff --git a/include/asm-sparc/timex_32.h b/include/asm-sparc/timex_32.h
new file mode 100644
index 000000000000..71b45c90ccae
--- /dev/null
+++ b/include/asm-sparc/timex_32.h
@@ -0,0 +1,15 @@
1/*
2 * linux/include/asm-sparc/timex.h
3 *
4 * sparc architecture timex specifications
5 */
6#ifndef _ASMsparc_TIMEX_H
7#define _ASMsparc_TIMEX_H
8
9#define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
10
11/* XXX Maybe do something better at some point... -DaveM */
12typedef unsigned long cycles_t;
13#define get_cycles() (0)
14
15#endif
diff --git a/include/asm-sparc/timex_64.h b/include/asm-sparc/timex_64.h
new file mode 100644
index 000000000000..c622535c4560
--- /dev/null
+++ b/include/asm-sparc/timex_64.h
@@ -0,0 +1,19 @@
1/*
2 * linux/include/asm-sparc64/timex.h
3 *
4 * sparc64 architecture timex specifications
5 */
6#ifndef _ASMsparc64_TIMEX_H
7#define _ASMsparc64_TIMEX_H
8
9#include <asm/timer.h>
10
11#define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
12
13/* Getting on the cycle counter on sparc64. */
14typedef unsigned long cycles_t;
15#define get_cycles() tick_ops->get_tick()
16
17#define ARCH_HAS_READ_CURRENT_TIMER
18
19#endif
diff --git a/include/asm-sparc/tlb.h b/include/asm-sparc/tlb.h
index 6d02d1ce53f3..a821057327c4 100644
--- a/include/asm-sparc/tlb.h
+++ b/include/asm-sparc/tlb.h
@@ -1,24 +1,8 @@
1#ifndef _SPARC_TLB_H 1#ifndef ___ASM_SPARC_TLB_H
2#define _SPARC_TLB_H 2#define ___ASM_SPARC_TLB_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#define tlb_start_vma(tlb, vma) \ 4#include <asm-sparc/tlb_64.h>
5do { \ 5#else
6 flush_cache_range(vma, vma->vm_start, vma->vm_end); \ 6#include <asm-sparc/tlb_32.h>
7} while (0) 7#endif
8 8#endif
9#define tlb_end_vma(tlb, vma) \
10do { \
11 flush_tlb_range(vma, vma->vm_start, vma->vm_end); \
12} while (0)
13
14#define __tlb_remove_tlb_entry(tlb, pte, address) \
15 do { } while (0)
16
17#define tlb_flush(tlb) \
18do { \
19 flush_tlb_mm((tlb)->mm); \
20} while (0)
21
22#include <asm-generic/tlb.h>
23
24#endif /* _SPARC_TLB_H */
diff --git a/include/asm-sparc/tlb_32.h b/include/asm-sparc/tlb_32.h
new file mode 100644
index 000000000000..6d02d1ce53f3
--- /dev/null
+++ b/include/asm-sparc/tlb_32.h
@@ -0,0 +1,24 @@
1#ifndef _SPARC_TLB_H
2#define _SPARC_TLB_H
3
4#define tlb_start_vma(tlb, vma) \
5do { \
6 flush_cache_range(vma, vma->vm_start, vma->vm_end); \
7} while (0)
8
9#define tlb_end_vma(tlb, vma) \
10do { \
11 flush_tlb_range(vma, vma->vm_start, vma->vm_end); \
12} while (0)
13
14#define __tlb_remove_tlb_entry(tlb, pte, address) \
15 do { } while (0)
16
17#define tlb_flush(tlb) \
18do { \
19 flush_tlb_mm((tlb)->mm); \
20} while (0)
21
22#include <asm-generic/tlb.h>
23
24#endif /* _SPARC_TLB_H */
diff --git a/include/asm-sparc/tlb_64.h b/include/asm-sparc/tlb_64.h
new file mode 100644
index 000000000000..ec81cdedef2c
--- /dev/null
+++ b/include/asm-sparc/tlb_64.h
@@ -0,0 +1,111 @@
1#ifndef _SPARC64_TLB_H
2#define _SPARC64_TLB_H
3
4#include <linux/swap.h>
5#include <linux/pagemap.h>
6#include <asm/pgalloc.h>
7#include <asm/tlbflush.h>
8#include <asm/mmu_context.h>
9
10#define TLB_BATCH_NR 192
11
12/*
13 * For UP we don't need to worry about TLB flush
14 * and page free order so much..
15 */
16#ifdef CONFIG_SMP
17 #define FREE_PTE_NR 506
18 #define tlb_fast_mode(bp) ((bp)->pages_nr == ~0U)
19#else
20 #define FREE_PTE_NR 1
21 #define tlb_fast_mode(bp) 1
22#endif
23
24struct mmu_gather {
25 struct mm_struct *mm;
26 unsigned int pages_nr;
27 unsigned int need_flush;
28 unsigned int fullmm;
29 unsigned int tlb_nr;
30 unsigned long vaddrs[TLB_BATCH_NR];
31 struct page *pages[FREE_PTE_NR];
32};
33
34DECLARE_PER_CPU(struct mmu_gather, mmu_gathers);
35
36#ifdef CONFIG_SMP
37extern void smp_flush_tlb_pending(struct mm_struct *,
38 unsigned long, unsigned long *);
39#endif
40
41extern void __flush_tlb_pending(unsigned long, unsigned long, unsigned long *);
42extern void flush_tlb_pending(void);
43
44static inline struct mmu_gather *tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush)
45{
46 struct mmu_gather *mp = &get_cpu_var(mmu_gathers);
47
48 BUG_ON(mp->tlb_nr);
49
50 mp->mm = mm;
51 mp->pages_nr = num_online_cpus() > 1 ? 0U : ~0U;
52 mp->fullmm = full_mm_flush;
53
54 return mp;
55}
56
57
58static inline void tlb_flush_mmu(struct mmu_gather *mp)
59{
60 if (mp->need_flush) {
61 free_pages_and_swap_cache(mp->pages, mp->pages_nr);
62 mp->pages_nr = 0;
63 mp->need_flush = 0;
64 }
65
66}
67
68#ifdef CONFIG_SMP
69extern void smp_flush_tlb_mm(struct mm_struct *mm);
70#define do_flush_tlb_mm(mm) smp_flush_tlb_mm(mm)
71#else
72#define do_flush_tlb_mm(mm) __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT)
73#endif
74
75static inline void tlb_finish_mmu(struct mmu_gather *mp, unsigned long start, unsigned long end)
76{
77 tlb_flush_mmu(mp);
78
79 if (mp->fullmm)
80 mp->fullmm = 0;
81 else
82 flush_tlb_pending();
83
84 /* keep the page table cache within bounds */
85 check_pgt_cache();
86
87 put_cpu_var(mmu_gathers);
88}
89
90static inline void tlb_remove_page(struct mmu_gather *mp, struct page *page)
91{
92 if (tlb_fast_mode(mp)) {
93 free_page_and_swap_cache(page);
94 return;
95 }
96 mp->need_flush = 1;
97 mp->pages[mp->pages_nr++] = page;
98 if (mp->pages_nr >= FREE_PTE_NR)
99 tlb_flush_mmu(mp);
100}
101
102#define tlb_remove_tlb_entry(mp,ptep,addr) do { } while (0)
103#define pte_free_tlb(mp, ptepage) pte_free((mp)->mm, ptepage)
104#define pmd_free_tlb(mp, pmdp) pmd_free((mp)->mm, pmdp)
105#define pud_free_tlb(tlb,pudp) __pud_free_tlb(tlb,pudp)
106
107#define tlb_migrate_finish(mm) do { } while (0)
108#define tlb_start_vma(tlb, vma) do { } while (0)
109#define tlb_end_vma(tlb, vma) do { } while (0)
110
111#endif /* _SPARC64_TLB_H */
diff --git a/include/asm-sparc/tlbflush.h b/include/asm-sparc/tlbflush.h
index b957e29d2ae1..6e6bc12227b8 100644
--- a/include/asm-sparc/tlbflush.h
+++ b/include/asm-sparc/tlbflush.h
@@ -1,60 +1,8 @@
1#ifndef _SPARC_TLBFLUSH_H 1#ifndef ___ASM_SPARC_TLBFLUSH_H
2#define _SPARC_TLBFLUSH_H 2#define ___ASM_SPARC_TLBFLUSH_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <linux/mm.h> 4#include <asm-sparc/tlbflush_64.h>
5// #include <asm/processor.h> 5#else
6 6#include <asm-sparc/tlbflush_32.h>
7/* 7#endif
8 * TLB flushing: 8#endif
9 *
10 * - flush_tlb() flushes the current mm struct TLBs XXX Exists?
11 * - flush_tlb_all() flushes all processes TLBs
12 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
13 * - flush_tlb_page(vma, vmaddr) flushes one page
14 * - flush_tlb_range(vma, start, end) flushes a range of pages
15 * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
16 */
17
18#ifdef CONFIG_SMP
19
20BTFIXUPDEF_CALL(void, local_flush_tlb_all, void)
21BTFIXUPDEF_CALL(void, local_flush_tlb_mm, struct mm_struct *)
22BTFIXUPDEF_CALL(void, local_flush_tlb_range, struct vm_area_struct *, unsigned long, unsigned long)
23BTFIXUPDEF_CALL(void, local_flush_tlb_page, struct vm_area_struct *, unsigned long)
24
25#define local_flush_tlb_all() BTFIXUP_CALL(local_flush_tlb_all)()
26#define local_flush_tlb_mm(mm) BTFIXUP_CALL(local_flush_tlb_mm)(mm)
27#define local_flush_tlb_range(vma,start,end) BTFIXUP_CALL(local_flush_tlb_range)(vma,start,end)
28#define local_flush_tlb_page(vma,addr) BTFIXUP_CALL(local_flush_tlb_page)(vma,addr)
29
30extern void smp_flush_tlb_all(void);
31extern void smp_flush_tlb_mm(struct mm_struct *mm);
32extern void smp_flush_tlb_range(struct vm_area_struct *vma,
33 unsigned long start,
34 unsigned long end);
35extern void smp_flush_tlb_page(struct vm_area_struct *mm, unsigned long page);
36
37#endif /* CONFIG_SMP */
38
39BTFIXUPDEF_CALL(void, flush_tlb_all, void)
40BTFIXUPDEF_CALL(void, flush_tlb_mm, struct mm_struct *)
41BTFIXUPDEF_CALL(void, flush_tlb_range, struct vm_area_struct *, unsigned long, unsigned long)
42BTFIXUPDEF_CALL(void, flush_tlb_page, struct vm_area_struct *, unsigned long)
43
44#define flush_tlb_all() BTFIXUP_CALL(flush_tlb_all)()
45#define flush_tlb_mm(mm) BTFIXUP_CALL(flush_tlb_mm)(mm)
46#define flush_tlb_range(vma,start,end) BTFIXUP_CALL(flush_tlb_range)(vma,start,end)
47#define flush_tlb_page(vma,addr) BTFIXUP_CALL(flush_tlb_page)(vma,addr)
48
49// #define flush_tlb() flush_tlb_mm(current->active_mm) /* XXX Sure? */
50
51/*
52 * This is a kludge, until I know better. --zaitcev XXX
53 */
54static inline void flush_tlb_kernel_range(unsigned long start,
55 unsigned long end)
56{
57 flush_tlb_all();
58}
59
60#endif /* _SPARC_TLBFLUSH_H */
diff --git a/include/asm-sparc/tlbflush_32.h b/include/asm-sparc/tlbflush_32.h
new file mode 100644
index 000000000000..fe0a71abc9bb
--- /dev/null
+++ b/include/asm-sparc/tlbflush_32.h
@@ -0,0 +1,60 @@
1#ifndef _SPARC_TLBFLUSH_H
2#define _SPARC_TLBFLUSH_H
3
4#include <linux/mm.h>
5// #include <asm/processor.h>
6
7/*
8 * TLB flushing:
9 *
10 * - flush_tlb() flushes the current mm struct TLBs XXX Exists?
11 * - flush_tlb_all() flushes all processes TLBs
12 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
13 * - flush_tlb_page(vma, vmaddr) flushes one page
14 * - flush_tlb_range(vma, start, end) flushes a range of pages
15 * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
16 */
17
18#ifdef CONFIG_SMP
19
20BTFIXUPDEF_CALL(void, local_flush_tlb_all, void)
21BTFIXUPDEF_CALL(void, local_flush_tlb_mm, struct mm_struct *)
22BTFIXUPDEF_CALL(void, local_flush_tlb_range, struct vm_area_struct *, unsigned long, unsigned long)
23BTFIXUPDEF_CALL(void, local_flush_tlb_page, struct vm_area_struct *, unsigned long)
24
25#define local_flush_tlb_all() BTFIXUP_CALL(local_flush_tlb_all)()
26#define local_flush_tlb_mm(mm) BTFIXUP_CALL(local_flush_tlb_mm)(mm)
27#define local_flush_tlb_range(vma,start,end) BTFIXUP_CALL(local_flush_tlb_range)(vma,start,end)
28#define local_flush_tlb_page(vma,addr) BTFIXUP_CALL(local_flush_tlb_page)(vma,addr)
29
30extern void smp_flush_tlb_all(void);
31extern void smp_flush_tlb_mm(struct mm_struct *mm);
32extern void smp_flush_tlb_range(struct vm_area_struct *vma,
33 unsigned long start,
34 unsigned long end);
35extern void smp_flush_tlb_page(struct vm_area_struct *mm, unsigned long page);
36
37#endif /* CONFIG_SMP */
38
39BTFIXUPDEF_CALL(void, flush_tlb_all, void)
40BTFIXUPDEF_CALL(void, flush_tlb_mm, struct mm_struct *)
41BTFIXUPDEF_CALL(void, flush_tlb_range, struct vm_area_struct *, unsigned long, unsigned long)
42BTFIXUPDEF_CALL(void, flush_tlb_page, struct vm_area_struct *, unsigned long)
43
44#define flush_tlb_all() BTFIXUP_CALL(flush_tlb_all)()
45#define flush_tlb_mm(mm) BTFIXUP_CALL(flush_tlb_mm)(mm)
46#define flush_tlb_range(vma,start,end) BTFIXUP_CALL(flush_tlb_range)(vma,start,end)
47#define flush_tlb_page(vma,addr) BTFIXUP_CALL(flush_tlb_page)(vma,addr)
48
49// #define flush_tlb() flush_tlb_mm(current->active_mm) /* XXX Sure? */
50
51/*
52 * This is a kludge, until I know better. --zaitcev XXX
53 */
54static inline void flush_tlb_kernel_range(unsigned long start,
55 unsigned long end)
56{
57 flush_tlb_all();
58}
59
60#endif /* _SPARC_TLBFLUSH_H */
diff --git a/include/asm-sparc/tlbflush_64.h b/include/asm-sparc/tlbflush_64.h
new file mode 100644
index 000000000000..fbb675dbe0c9
--- /dev/null
+++ b/include/asm-sparc/tlbflush_64.h
@@ -0,0 +1,44 @@
1#ifndef _SPARC64_TLBFLUSH_H
2#define _SPARC64_TLBFLUSH_H
3
4#include <linux/mm.h>
5#include <asm/mmu_context.h>
6
7/* TSB flush operations. */
8struct mmu_gather;
9extern void flush_tsb_kernel_range(unsigned long start, unsigned long end);
10extern void flush_tsb_user(struct mmu_gather *mp);
11
12/* TLB flush operations. */
13
14extern void flush_tlb_pending(void);
15
16#define flush_tlb_range(vma,start,end) \
17 do { (void)(start); flush_tlb_pending(); } while (0)
18#define flush_tlb_page(vma,addr) flush_tlb_pending()
19#define flush_tlb_mm(mm) flush_tlb_pending()
20
21/* Local cpu only. */
22extern void __flush_tlb_all(void);
23
24extern void __flush_tlb_kernel_range(unsigned long start, unsigned long end);
25
26#ifndef CONFIG_SMP
27
28#define flush_tlb_kernel_range(start,end) \
29do { flush_tsb_kernel_range(start,end); \
30 __flush_tlb_kernel_range(start,end); \
31} while (0)
32
33#else /* CONFIG_SMP */
34
35extern void smp_flush_tlb_kernel_range(unsigned long start, unsigned long end);
36
37#define flush_tlb_kernel_range(start, end) \
38do { flush_tsb_kernel_range(start,end); \
39 smp_flush_tlb_kernel_range(start, end); \
40} while (0)
41
42#endif /* ! CONFIG_SMP */
43
44#endif /* _SPARC64_TLBFLUSH_H */
diff --git a/include/asm-sparc/topology.h b/include/asm-sparc/topology.h
index ee5ac9c9da28..ed13630f32e2 100644
--- a/include/asm-sparc/topology.h
+++ b/include/asm-sparc/topology.h
@@ -1,6 +1,8 @@
1#ifndef _ASM_SPARC_TOPOLOGY_H 1#ifndef ___ASM_SPARC_TOPOLOGY_H
2#define _ASM_SPARC_TOPOLOGY_H 2#define ___ASM_SPARC_TOPOLOGY_H
3 3#if defined(__sparc__) && defined(__arch64__)
4#include <asm-generic/topology.h> 4#include <asm-sparc/topology_64.h>
5 5#else
6#endif /* _ASM_SPARC_TOPOLOGY_H */ 6#include <asm-sparc/topology_32.h>
7#endif
8#endif
diff --git a/include/asm-sparc/topology_32.h b/include/asm-sparc/topology_32.h
new file mode 100644
index 000000000000..ee5ac9c9da28
--- /dev/null
+++ b/include/asm-sparc/topology_32.h
@@ -0,0 +1,6 @@
1#ifndef _ASM_SPARC_TOPOLOGY_H
2#define _ASM_SPARC_TOPOLOGY_H
3
4#include <asm-generic/topology.h>
5
6#endif /* _ASM_SPARC_TOPOLOGY_H */
diff --git a/include/asm-sparc/topology_64.h b/include/asm-sparc/topology_64.h
new file mode 100644
index 000000000000..001c04027c82
--- /dev/null
+++ b/include/asm-sparc/topology_64.h
@@ -0,0 +1,86 @@
1#ifndef _ASM_SPARC64_TOPOLOGY_H
2#define _ASM_SPARC64_TOPOLOGY_H
3
4#ifdef CONFIG_NUMA
5
6#include <asm/mmzone.h>
7
8static inline int cpu_to_node(int cpu)
9{
10 return numa_cpu_lookup_table[cpu];
11}
12
13#define parent_node(node) (node)
14
15static inline cpumask_t node_to_cpumask(int node)
16{
17 return numa_cpumask_lookup_table[node];
18}
19
20/* Returns a pointer to the cpumask of CPUs on Node 'node'. */
21#define node_to_cpumask_ptr(v, node) \
22 cpumask_t *v = &(numa_cpumask_lookup_table[node])
23
24#define node_to_cpumask_ptr_next(v, node) \
25 v = &(numa_cpumask_lookup_table[node])
26
27static inline int node_to_first_cpu(int node)
28{
29 cpumask_t tmp;
30 tmp = node_to_cpumask(node);
31 return first_cpu(tmp);
32}
33
34struct pci_bus;
35#ifdef CONFIG_PCI
36extern int pcibus_to_node(struct pci_bus *pbus);
37#else
38static inline int pcibus_to_node(struct pci_bus *pbus)
39{
40 return -1;
41}
42#endif
43
44#define pcibus_to_cpumask(bus) \
45 (pcibus_to_node(bus) == -1 ? \
46 CPU_MASK_ALL : \
47 node_to_cpumask(pcibus_to_node(bus)))
48
49#define SD_NODE_INIT (struct sched_domain) { \
50 .min_interval = 8, \
51 .max_interval = 32, \
52 .busy_factor = 32, \
53 .imbalance_pct = 125, \
54 .cache_nice_tries = 2, \
55 .busy_idx = 3, \
56 .idle_idx = 2, \
57 .newidle_idx = 0, \
58 .wake_idx = 1, \
59 .forkexec_idx = 1, \
60 .flags = SD_LOAD_BALANCE \
61 | SD_BALANCE_FORK \
62 | SD_BALANCE_EXEC \
63 | SD_SERIALIZE \
64 | SD_WAKE_BALANCE, \
65 .last_balance = jiffies, \
66 .balance_interval = 1, \
67}
68
69#else /* CONFIG_NUMA */
70
71#include <asm-generic/topology.h>
72
73#endif /* !(CONFIG_NUMA) */
74
75#ifdef CONFIG_SMP
76#define topology_physical_package_id(cpu) (cpu_data(cpu).proc_id)
77#define topology_core_id(cpu) (cpu_data(cpu).core_id)
78#define topology_core_siblings(cpu) (cpu_core_map[cpu])
79#define topology_thread_siblings(cpu) (per_cpu(cpu_sibling_map, cpu))
80#define mc_capable() (sparc64_multi_core)
81#define smt_capable() (sparc64_multi_core)
82#endif /* CONFIG_SMP */
83
84#define cpu_coregroup_map(cpu) (cpu_core_map[cpu])
85
86#endif /* _ASM_SPARC64_TOPOLOGY_H */
diff --git a/include/asm-sparc/tsb.h b/include/asm-sparc/tsb.h
new file mode 100644
index 000000000000..76e4299dd9bc
--- /dev/null
+++ b/include/asm-sparc/tsb.h
@@ -0,0 +1,283 @@
1#ifndef _SPARC64_TSB_H
2#define _SPARC64_TSB_H
3
4/* The sparc64 TSB is similar to the powerpc hashtables. It's a
5 * power-of-2 sized table of TAG/PTE pairs. The cpu precomputes
6 * pointers into this table for 8K and 64K page sizes, and also a
7 * comparison TAG based upon the virtual address and context which
8 * faults.
9 *
10 * TLB miss trap handler software does the actual lookup via something
11 * of the form:
12 *
13 * ldxa [%g0] ASI_{D,I}MMU_TSB_8KB_PTR, %g1
14 * ldxa [%g0] ASI_{D,I}MMU, %g6
15 * sllx %g6, 22, %g6
16 * srlx %g6, 22, %g6
17 * ldda [%g1] ASI_NUCLEUS_QUAD_LDD, %g4
18 * cmp %g4, %g6
19 * bne,pn %xcc, tsb_miss_{d,i}tlb
20 * mov FAULT_CODE_{D,I}TLB, %g3
21 * stxa %g5, [%g0] ASI_{D,I}TLB_DATA_IN
22 * retry
23 *
24 *
25 * Each 16-byte slot of the TSB is the 8-byte tag and then the 8-byte
26 * PTE. The TAG is of the same layout as the TLB TAG TARGET mmu
27 * register which is:
28 *
29 * -------------------------------------------------
30 * | - | CONTEXT | - | VADDR bits 63:22 |
31 * -------------------------------------------------
32 * 63 61 60 48 47 42 41 0
33 *
34 * But actually, since we use per-mm TSB's, we zero out the CONTEXT
35 * field.
36 *
37 * Like the powerpc hashtables we need to use locking in order to
38 * synchronize while we update the entries. PTE updates need locking
39 * as well.
40 *
41 * We need to carefully choose a lock bits for the TSB entry. We
42 * choose to use bit 47 in the tag. Also, since we never map anything
43 * at page zero in context zero, we use zero as an invalid tag entry.
44 * When the lock bit is set, this forces a tag comparison failure.
45 */
46
47#define TSB_TAG_LOCK_BIT 47
48#define TSB_TAG_LOCK_HIGH (1 << (TSB_TAG_LOCK_BIT - 32))
49
50#define TSB_TAG_INVALID_BIT 46
51#define TSB_TAG_INVALID_HIGH (1 << (TSB_TAG_INVALID_BIT - 32))
52
53#define TSB_MEMBAR membar #StoreStore
54
55/* Some cpus support physical address quad loads. We want to use
56 * those if possible so we don't need to hard-lock the TSB mapping
57 * into the TLB. We encode some instruction patching in order to
58 * support this.
59 *
60 * The kernel TSB is locked into the TLB by virtue of being in the
61 * kernel image, so we don't play these games for swapper_tsb access.
62 */
63#ifndef __ASSEMBLY__
64struct tsb_ldquad_phys_patch_entry {
65 unsigned int addr;
66 unsigned int sun4u_insn;
67 unsigned int sun4v_insn;
68};
69extern struct tsb_ldquad_phys_patch_entry __tsb_ldquad_phys_patch,
70 __tsb_ldquad_phys_patch_end;
71
72struct tsb_phys_patch_entry {
73 unsigned int addr;
74 unsigned int insn;
75};
76extern struct tsb_phys_patch_entry __tsb_phys_patch, __tsb_phys_patch_end;
77#endif
78#define TSB_LOAD_QUAD(TSB, REG) \
79661: ldda [TSB] ASI_NUCLEUS_QUAD_LDD, REG; \
80 .section .tsb_ldquad_phys_patch, "ax"; \
81 .word 661b; \
82 ldda [TSB] ASI_QUAD_LDD_PHYS, REG; \
83 ldda [TSB] ASI_QUAD_LDD_PHYS_4V, REG; \
84 .previous
85
86#define TSB_LOAD_TAG_HIGH(TSB, REG) \
87661: lduwa [TSB] ASI_N, REG; \
88 .section .tsb_phys_patch, "ax"; \
89 .word 661b; \
90 lduwa [TSB] ASI_PHYS_USE_EC, REG; \
91 .previous
92
93#define TSB_LOAD_TAG(TSB, REG) \
94661: ldxa [TSB] ASI_N, REG; \
95 .section .tsb_phys_patch, "ax"; \
96 .word 661b; \
97 ldxa [TSB] ASI_PHYS_USE_EC, REG; \
98 .previous
99
100#define TSB_CAS_TAG_HIGH(TSB, REG1, REG2) \
101661: casa [TSB] ASI_N, REG1, REG2; \
102 .section .tsb_phys_patch, "ax"; \
103 .word 661b; \
104 casa [TSB] ASI_PHYS_USE_EC, REG1, REG2; \
105 .previous
106
107#define TSB_CAS_TAG(TSB, REG1, REG2) \
108661: casxa [TSB] ASI_N, REG1, REG2; \
109 .section .tsb_phys_patch, "ax"; \
110 .word 661b; \
111 casxa [TSB] ASI_PHYS_USE_EC, REG1, REG2; \
112 .previous
113
114#define TSB_STORE(ADDR, VAL) \
115661: stxa VAL, [ADDR] ASI_N; \
116 .section .tsb_phys_patch, "ax"; \
117 .word 661b; \
118 stxa VAL, [ADDR] ASI_PHYS_USE_EC; \
119 .previous
120
121#define TSB_LOCK_TAG(TSB, REG1, REG2) \
12299: TSB_LOAD_TAG_HIGH(TSB, REG1); \
123 sethi %hi(TSB_TAG_LOCK_HIGH), REG2;\
124 andcc REG1, REG2, %g0; \
125 bne,pn %icc, 99b; \
126 nop; \
127 TSB_CAS_TAG_HIGH(TSB, REG1, REG2); \
128 cmp REG1, REG2; \
129 bne,pn %icc, 99b; \
130 nop; \
131 TSB_MEMBAR
132
133#define TSB_WRITE(TSB, TTE, TAG) \
134 add TSB, 0x8, TSB; \
135 TSB_STORE(TSB, TTE); \
136 sub TSB, 0x8, TSB; \
137 TSB_MEMBAR; \
138 TSB_STORE(TSB, TAG);
139
140#define KTSB_LOAD_QUAD(TSB, REG) \
141 ldda [TSB] ASI_NUCLEUS_QUAD_LDD, REG;
142
143#define KTSB_STORE(ADDR, VAL) \
144 stxa VAL, [ADDR] ASI_N;
145
146#define KTSB_LOCK_TAG(TSB, REG1, REG2) \
14799: lduwa [TSB] ASI_N, REG1; \
148 sethi %hi(TSB_TAG_LOCK_HIGH), REG2;\
149 andcc REG1, REG2, %g0; \
150 bne,pn %icc, 99b; \
151 nop; \
152 casa [TSB] ASI_N, REG1, REG2;\
153 cmp REG1, REG2; \
154 bne,pn %icc, 99b; \
155 nop; \
156 TSB_MEMBAR
157
158#define KTSB_WRITE(TSB, TTE, TAG) \
159 add TSB, 0x8, TSB; \
160 stxa TTE, [TSB] ASI_N; \
161 sub TSB, 0x8, TSB; \
162 TSB_MEMBAR; \
163 stxa TAG, [TSB] ASI_N;
164
165 /* Do a kernel page table walk. Leaves physical PTE pointer in
166 * REG1. Jumps to FAIL_LABEL on early page table walk termination.
167 * VADDR will not be clobbered, but REG2 will.
168 */
169#define KERN_PGTABLE_WALK(VADDR, REG1, REG2, FAIL_LABEL) \
170 sethi %hi(swapper_pg_dir), REG1; \
171 or REG1, %lo(swapper_pg_dir), REG1; \
172 sllx VADDR, 64 - (PGDIR_SHIFT + PGDIR_BITS), REG2; \
173 srlx REG2, 64 - PAGE_SHIFT, REG2; \
174 andn REG2, 0x3, REG2; \
175 lduw [REG1 + REG2], REG1; \
176 brz,pn REG1, FAIL_LABEL; \
177 sllx VADDR, 64 - (PMD_SHIFT + PMD_BITS), REG2; \
178 srlx REG2, 64 - PAGE_SHIFT, REG2; \
179 sllx REG1, 11, REG1; \
180 andn REG2, 0x3, REG2; \
181 lduwa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \
182 brz,pn REG1, FAIL_LABEL; \
183 sllx VADDR, 64 - PMD_SHIFT, REG2; \
184 srlx REG2, 64 - PAGE_SHIFT, REG2; \
185 sllx REG1, 11, REG1; \
186 andn REG2, 0x7, REG2; \
187 add REG1, REG2, REG1;
188
189 /* Do a user page table walk in MMU globals. Leaves physical PTE
190 * pointer in REG1. Jumps to FAIL_LABEL on early page table walk
191 * termination. Physical base of page tables is in PHYS_PGD which
192 * will not be modified.
193 *
194 * VADDR will not be clobbered, but REG1 and REG2 will.
195 */
196#define USER_PGTABLE_WALK_TL1(VADDR, PHYS_PGD, REG1, REG2, FAIL_LABEL) \
197 sllx VADDR, 64 - (PGDIR_SHIFT + PGDIR_BITS), REG2; \
198 srlx REG2, 64 - PAGE_SHIFT, REG2; \
199 andn REG2, 0x3, REG2; \
200 lduwa [PHYS_PGD + REG2] ASI_PHYS_USE_EC, REG1; \
201 brz,pn REG1, FAIL_LABEL; \
202 sllx VADDR, 64 - (PMD_SHIFT + PMD_BITS), REG2; \
203 srlx REG2, 64 - PAGE_SHIFT, REG2; \
204 sllx REG1, 11, REG1; \
205 andn REG2, 0x3, REG2; \
206 lduwa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \
207 brz,pn REG1, FAIL_LABEL; \
208 sllx VADDR, 64 - PMD_SHIFT, REG2; \
209 srlx REG2, 64 - PAGE_SHIFT, REG2; \
210 sllx REG1, 11, REG1; \
211 andn REG2, 0x7, REG2; \
212 add REG1, REG2, REG1;
213
214/* Lookup a OBP mapping on VADDR in the prom_trans[] table at TL>0.
215 * If no entry is found, FAIL_LABEL will be branched to. On success
216 * the resulting PTE value will be left in REG1. VADDR is preserved
217 * by this routine.
218 */
219#define OBP_TRANS_LOOKUP(VADDR, REG1, REG2, REG3, FAIL_LABEL) \
220 sethi %hi(prom_trans), REG1; \
221 or REG1, %lo(prom_trans), REG1; \
22297: ldx [REG1 + 0x00], REG2; \
223 brz,pn REG2, FAIL_LABEL; \
224 nop; \
225 ldx [REG1 + 0x08], REG3; \
226 add REG2, REG3, REG3; \
227 cmp REG2, VADDR; \
228 bgu,pt %xcc, 98f; \
229 cmp VADDR, REG3; \
230 bgeu,pt %xcc, 98f; \
231 ldx [REG1 + 0x10], REG3; \
232 sub VADDR, REG2, REG2; \
233 ba,pt %xcc, 99f; \
234 add REG3, REG2, REG1; \
23598: ba,pt %xcc, 97b; \
236 add REG1, (3 * 8), REG1; \
23799:
238
239 /* We use a 32K TSB for the whole kernel, this allows to
240 * handle about 16MB of modules and vmalloc mappings without
241 * incurring many hash conflicts.
242 */
243#define KERNEL_TSB_SIZE_BYTES (32 * 1024)
244#define KERNEL_TSB_NENTRIES \
245 (KERNEL_TSB_SIZE_BYTES / 16)
246#define KERNEL_TSB4M_NENTRIES 4096
247
248 /* Do a kernel TSB lookup at tl>0 on VADDR+TAG, branch to OK_LABEL
249 * on TSB hit. REG1, REG2, REG3, and REG4 are used as temporaries
250 * and the found TTE will be left in REG1. REG3 and REG4 must
251 * be an even/odd pair of registers.
252 *
253 * VADDR and TAG will be preserved and not clobbered by this macro.
254 */
255#define KERN_TSB_LOOKUP_TL1(VADDR, TAG, REG1, REG2, REG3, REG4, OK_LABEL) \
256 sethi %hi(swapper_tsb), REG1; \
257 or REG1, %lo(swapper_tsb), REG1; \
258 srlx VADDR, PAGE_SHIFT, REG2; \
259 and REG2, (KERNEL_TSB_NENTRIES - 1), REG2; \
260 sllx REG2, 4, REG2; \
261 add REG1, REG2, REG2; \
262 KTSB_LOAD_QUAD(REG2, REG3); \
263 cmp REG3, TAG; \
264 be,a,pt %xcc, OK_LABEL; \
265 mov REG4, REG1;
266
267#ifndef CONFIG_DEBUG_PAGEALLOC
268 /* This version uses a trick, the TAG is already (VADDR >> 22) so
269 * we can make use of that for the index computation.
270 */
271#define KERN_TSB4M_LOOKUP_TL1(TAG, REG1, REG2, REG3, REG4, OK_LABEL) \
272 sethi %hi(swapper_4m_tsb), REG1; \
273 or REG1, %lo(swapper_4m_tsb), REG1; \
274 and TAG, (KERNEL_TSB4M_NENTRIES - 1), REG2; \
275 sllx REG2, 4, REG2; \
276 add REG1, REG2, REG2; \
277 KTSB_LOAD_QUAD(REG2, REG3); \
278 cmp REG3, TAG; \
279 be,a,pt %xcc, OK_LABEL; \
280 mov REG4, REG1;
281#endif
282
283#endif /* !(_SPARC64_TSB_H) */
diff --git a/include/asm-sparc/ttable.h b/include/asm-sparc/ttable.h
new file mode 100644
index 000000000000..5708ba2719fb
--- /dev/null
+++ b/include/asm-sparc/ttable.h
@@ -0,0 +1,658 @@
1#ifndef _SPARC64_TTABLE_H
2#define _SPARC64_TTABLE_H
3
4#include <asm/utrap.h>
5
6#ifdef __ASSEMBLY__
7#include <asm/thread_info.h>
8#endif
9
10#define BOOT_KERNEL b sparc64_boot; nop; nop; nop; nop; nop; nop; nop;
11
12/* We need a "cleaned" instruction... */
13#define CLEAN_WINDOW \
14 rdpr %cleanwin, %l0; add %l0, 1, %l0; \
15 wrpr %l0, 0x0, %cleanwin; \
16 clr %o0; clr %o1; clr %o2; clr %o3; \
17 clr %o4; clr %o5; clr %o6; clr %o7; \
18 clr %l0; clr %l1; clr %l2; clr %l3; \
19 clr %l4; clr %l5; clr %l6; clr %l7; \
20 retry; \
21 nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
22
23#define TRAP(routine) \
24 sethi %hi(109f), %g7; \
25 ba,pt %xcc, etrap; \
26109: or %g7, %lo(109b), %g7; \
27 call routine; \
28 add %sp, PTREGS_OFF, %o0; \
29 ba,pt %xcc, rtrap; \
30 nop; \
31 nop;
32
33#define TRAP_7INSNS(routine) \
34 sethi %hi(109f), %g7; \
35 ba,pt %xcc, etrap; \
36109: or %g7, %lo(109b), %g7; \
37 call routine; \
38 add %sp, PTREGS_OFF, %o0; \
39 ba,pt %xcc, rtrap; \
40 nop;
41
42#define TRAP_SAVEFPU(routine) \
43 sethi %hi(109f), %g7; \
44 ba,pt %xcc, do_fptrap; \
45109: or %g7, %lo(109b), %g7; \
46 call routine; \
47 add %sp, PTREGS_OFF, %o0; \
48 ba,pt %xcc, rtrap; \
49 nop; \
50 nop;
51
52#define TRAP_NOSAVE(routine) \
53 ba,pt %xcc, routine; \
54 nop; \
55 nop; nop; nop; nop; nop; nop;
56
57#define TRAP_NOSAVE_7INSNS(routine) \
58 ba,pt %xcc, routine; \
59 nop; \
60 nop; nop; nop; nop; nop;
61
62#define TRAPTL1(routine) \
63 sethi %hi(109f), %g7; \
64 ba,pt %xcc, etraptl1; \
65109: or %g7, %lo(109b), %g7; \
66 call routine; \
67 add %sp, PTREGS_OFF, %o0; \
68 ba,pt %xcc, rtrap; \
69 nop; \
70 nop;
71
72#define TRAP_ARG(routine, arg) \
73 sethi %hi(109f), %g7; \
74 ba,pt %xcc, etrap; \
75109: or %g7, %lo(109b), %g7; \
76 add %sp, PTREGS_OFF, %o0; \
77 call routine; \
78 mov arg, %o1; \
79 ba,pt %xcc, rtrap; \
80 nop;
81
82#define TRAPTL1_ARG(routine, arg) \
83 sethi %hi(109f), %g7; \
84 ba,pt %xcc, etraptl1; \
85109: or %g7, %lo(109b), %g7; \
86 add %sp, PTREGS_OFF, %o0; \
87 call routine; \
88 mov arg, %o1; \
89 ba,pt %xcc, rtrap; \
90 nop;
91
92#define SYSCALL_TRAP(routine, systbl) \
93 rdpr %pil, %g2; \
94 mov TSTATE_SYSCALL, %g3; \
95 sethi %hi(109f), %g7; \
96 ba,pt %xcc, etrap_syscall; \
97109: or %g7, %lo(109b), %g7; \
98 sethi %hi(systbl), %l7; \
99 ba,pt %xcc, routine; \
100 or %l7, %lo(systbl), %l7;
101
102#define TRAP_UTRAP(handler,lvl) \
103 mov handler, %g3; \
104 ba,pt %xcc, utrap_trap; \
105 mov lvl, %g4; \
106 nop; \
107 nop; \
108 nop; \
109 nop; \
110 nop;
111
112#ifdef CONFIG_COMPAT
113#define LINUX_32BIT_SYSCALL_TRAP SYSCALL_TRAP(linux_sparc_syscall32, sys_call_table32)
114#else
115#define LINUX_32BIT_SYSCALL_TRAP BTRAP(0x110)
116#endif
117#define LINUX_64BIT_SYSCALL_TRAP SYSCALL_TRAP(linux_sparc_syscall, sys_call_table64)
118#define GETCC_TRAP TRAP(getcc)
119#define SETCC_TRAP TRAP(setcc)
120#define BREAKPOINT_TRAP TRAP(breakpoint_trap)
121
122#ifdef CONFIG_TRACE_IRQFLAGS
123
124#define TRAP_IRQ(routine, level) \
125 rdpr %pil, %g2; \
126 wrpr %g0, 15, %pil; \
127 sethi %hi(1f-4), %g7; \
128 ba,pt %xcc, etrap_irq; \
129 or %g7, %lo(1f-4), %g7; \
130 nop; \
131 nop; \
132 nop; \
133 .subsection 2; \
1341: call trace_hardirqs_off; \
135 nop; \
136 mov level, %o0; \
137 call routine; \
138 add %sp, PTREGS_OFF, %o1; \
139 ba,a,pt %xcc, rtrap_irq; \
140 .previous;
141
142#else
143
144#define TRAP_IRQ(routine, level) \
145 rdpr %pil, %g2; \
146 wrpr %g0, 15, %pil; \
147 ba,pt %xcc, etrap_irq; \
148 rd %pc, %g7; \
149 mov level, %o0; \
150 call routine; \
151 add %sp, PTREGS_OFF, %o1; \
152 ba,a,pt %xcc, rtrap_irq;
153
154#endif
155
156#define TRAP_IVEC TRAP_NOSAVE(do_ivec)
157
158#define BTRAP(lvl) TRAP_ARG(bad_trap, lvl)
159
160#define BTRAPTL1(lvl) TRAPTL1_ARG(bad_trap_tl1, lvl)
161
162#define FLUSH_WINDOW_TRAP \
163 ba,pt %xcc, etrap; \
164 rd %pc, %g7; \
165 flushw; \
166 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1; \
167 add %l1, 4, %l2; \
168 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]; \
169 ba,pt %xcc, rtrap; \
170 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC];
171
172#ifdef CONFIG_KPROBES
173#define KPROBES_TRAP(lvl) TRAP_IRQ(kprobe_trap, lvl)
174#else
175#define KPROBES_TRAP(lvl) TRAP_ARG(bad_trap, lvl)
176#endif
177
178#ifdef CONFIG_KGDB
179#define KGDB_TRAP(lvl) TRAP_IRQ(kgdb_trap, lvl)
180#else
181#define KGDB_TRAP(lvl) TRAP_ARG(bad_trap, lvl)
182#endif
183
184#define SUN4V_ITSB_MISS \
185 ldxa [%g0] ASI_SCRATCHPAD, %g2; \
186 ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4; \
187 ldx [%g2 + HV_FAULT_I_CTX_OFFSET], %g5; \
188 srlx %g4, 22, %g6; \
189 ba,pt %xcc, sun4v_itsb_miss; \
190 nop; \
191 nop; \
192 nop;
193
194#define SUN4V_DTSB_MISS \
195 ldxa [%g0] ASI_SCRATCHPAD, %g2; \
196 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4; \
197 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5; \
198 srlx %g4, 22, %g6; \
199 ba,pt %xcc, sun4v_dtsb_miss; \
200 nop; \
201 nop; \
202 nop;
203
204/* Before touching these macros, you owe it to yourself to go and
205 * see how arch/sparc64/kernel/winfixup.S works... -DaveM
206 *
207 * For the user cases we used to use the %asi register, but
208 * it turns out that the "wr xxx, %asi" costs ~5 cycles, so
209 * now we use immediate ASI loads and stores instead. Kudos
210 * to Greg Onufer for pointing out this performance anomaly.
211 *
212 * Further note that we cannot use the g2, g4, g5, and g7 alternate
213 * globals in the spill routines, check out the save instruction in
214 * arch/sparc64/kernel/etrap.S to see what I mean about g2, and
215 * g4/g5 are the globals which are preserved by etrap processing
216 * for the caller of it. The g7 register is the return pc for
217 * etrap. Finally, g6 is the current thread register so we cannot
218 * us it in the spill handlers either. Most of these rules do not
219 * apply to fill processing, only g6 is not usable.
220 */
221
222/* Normal kernel spill */
223#define SPILL_0_NORMAL \
224 stx %l0, [%sp + STACK_BIAS + 0x00]; \
225 stx %l1, [%sp + STACK_BIAS + 0x08]; \
226 stx %l2, [%sp + STACK_BIAS + 0x10]; \
227 stx %l3, [%sp + STACK_BIAS + 0x18]; \
228 stx %l4, [%sp + STACK_BIAS + 0x20]; \
229 stx %l5, [%sp + STACK_BIAS + 0x28]; \
230 stx %l6, [%sp + STACK_BIAS + 0x30]; \
231 stx %l7, [%sp + STACK_BIAS + 0x38]; \
232 stx %i0, [%sp + STACK_BIAS + 0x40]; \
233 stx %i1, [%sp + STACK_BIAS + 0x48]; \
234 stx %i2, [%sp + STACK_BIAS + 0x50]; \
235 stx %i3, [%sp + STACK_BIAS + 0x58]; \
236 stx %i4, [%sp + STACK_BIAS + 0x60]; \
237 stx %i5, [%sp + STACK_BIAS + 0x68]; \
238 stx %i6, [%sp + STACK_BIAS + 0x70]; \
239 stx %i7, [%sp + STACK_BIAS + 0x78]; \
240 saved; retry; nop; nop; nop; nop; nop; nop; \
241 nop; nop; nop; nop; nop; nop; nop; nop;
242
243#define SPILL_0_NORMAL_ETRAP \
244etrap_kernel_spill: \
245 stx %l0, [%sp + STACK_BIAS + 0x00]; \
246 stx %l1, [%sp + STACK_BIAS + 0x08]; \
247 stx %l2, [%sp + STACK_BIAS + 0x10]; \
248 stx %l3, [%sp + STACK_BIAS + 0x18]; \
249 stx %l4, [%sp + STACK_BIAS + 0x20]; \
250 stx %l5, [%sp + STACK_BIAS + 0x28]; \
251 stx %l6, [%sp + STACK_BIAS + 0x30]; \
252 stx %l7, [%sp + STACK_BIAS + 0x38]; \
253 stx %i0, [%sp + STACK_BIAS + 0x40]; \
254 stx %i1, [%sp + STACK_BIAS + 0x48]; \
255 stx %i2, [%sp + STACK_BIAS + 0x50]; \
256 stx %i3, [%sp + STACK_BIAS + 0x58]; \
257 stx %i4, [%sp + STACK_BIAS + 0x60]; \
258 stx %i5, [%sp + STACK_BIAS + 0x68]; \
259 stx %i6, [%sp + STACK_BIAS + 0x70]; \
260 stx %i7, [%sp + STACK_BIAS + 0x78]; \
261 saved; \
262 sub %g1, 2, %g1; \
263 ba,pt %xcc, etrap_save; \
264 wrpr %g1, %cwp; \
265 nop; nop; nop; nop; nop; nop; nop; nop; \
266 nop; nop; nop; nop;
267
268/* Normal 64bit spill */
269#define SPILL_1_GENERIC(ASI) \
270 add %sp, STACK_BIAS + 0x00, %g1; \
271 stxa %l0, [%g1 + %g0] ASI; \
272 mov 0x08, %g3; \
273 stxa %l1, [%g1 + %g3] ASI; \
274 add %g1, 0x10, %g1; \
275 stxa %l2, [%g1 + %g0] ASI; \
276 stxa %l3, [%g1 + %g3] ASI; \
277 add %g1, 0x10, %g1; \
278 stxa %l4, [%g1 + %g0] ASI; \
279 stxa %l5, [%g1 + %g3] ASI; \
280 add %g1, 0x10, %g1; \
281 stxa %l6, [%g1 + %g0] ASI; \
282 stxa %l7, [%g1 + %g3] ASI; \
283 add %g1, 0x10, %g1; \
284 stxa %i0, [%g1 + %g0] ASI; \
285 stxa %i1, [%g1 + %g3] ASI; \
286 add %g1, 0x10, %g1; \
287 stxa %i2, [%g1 + %g0] ASI; \
288 stxa %i3, [%g1 + %g3] ASI; \
289 add %g1, 0x10, %g1; \
290 stxa %i4, [%g1 + %g0] ASI; \
291 stxa %i5, [%g1 + %g3] ASI; \
292 add %g1, 0x10, %g1; \
293 stxa %i6, [%g1 + %g0] ASI; \
294 stxa %i7, [%g1 + %g3] ASI; \
295 saved; \
296 retry; nop; nop; \
297 b,a,pt %xcc, spill_fixup_dax; \
298 b,a,pt %xcc, spill_fixup_mna; \
299 b,a,pt %xcc, spill_fixup;
300
301#define SPILL_1_GENERIC_ETRAP \
302etrap_user_spill_64bit: \
303 stxa %l0, [%sp + STACK_BIAS + 0x00] %asi; \
304 stxa %l1, [%sp + STACK_BIAS + 0x08] %asi; \
305 stxa %l2, [%sp + STACK_BIAS + 0x10] %asi; \
306 stxa %l3, [%sp + STACK_BIAS + 0x18] %asi; \
307 stxa %l4, [%sp + STACK_BIAS + 0x20] %asi; \
308 stxa %l5, [%sp + STACK_BIAS + 0x28] %asi; \
309 stxa %l6, [%sp + STACK_BIAS + 0x30] %asi; \
310 stxa %l7, [%sp + STACK_BIAS + 0x38] %asi; \
311 stxa %i0, [%sp + STACK_BIAS + 0x40] %asi; \
312 stxa %i1, [%sp + STACK_BIAS + 0x48] %asi; \
313 stxa %i2, [%sp + STACK_BIAS + 0x50] %asi; \
314 stxa %i3, [%sp + STACK_BIAS + 0x58] %asi; \
315 stxa %i4, [%sp + STACK_BIAS + 0x60] %asi; \
316 stxa %i5, [%sp + STACK_BIAS + 0x68] %asi; \
317 stxa %i6, [%sp + STACK_BIAS + 0x70] %asi; \
318 stxa %i7, [%sp + STACK_BIAS + 0x78] %asi; \
319 saved; \
320 sub %g1, 2, %g1; \
321 ba,pt %xcc, etrap_save; \
322 wrpr %g1, %cwp; \
323 nop; nop; nop; nop; nop; \
324 nop; nop; nop; nop; \
325 ba,a,pt %xcc, etrap_spill_fixup_64bit; \
326 ba,a,pt %xcc, etrap_spill_fixup_64bit; \
327 ba,a,pt %xcc, etrap_spill_fixup_64bit;
328
329#define SPILL_1_GENERIC_ETRAP_FIXUP \
330etrap_spill_fixup_64bit: \
331 ldub [%g6 + TI_WSAVED], %g1; \
332 sll %g1, 3, %g3; \
333 add %g6, %g3, %g3; \
334 stx %sp, [%g3 + TI_RWIN_SPTRS]; \
335 sll %g1, 7, %g3; \
336 add %g6, %g3, %g3; \
337 stx %l0, [%g3 + TI_REG_WINDOW + 0x00]; \
338 stx %l1, [%g3 + TI_REG_WINDOW + 0x08]; \
339 stx %l2, [%g3 + TI_REG_WINDOW + 0x10]; \
340 stx %l3, [%g3 + TI_REG_WINDOW + 0x18]; \
341 stx %l4, [%g3 + TI_REG_WINDOW + 0x20]; \
342 stx %l5, [%g3 + TI_REG_WINDOW + 0x28]; \
343 stx %l6, [%g3 + TI_REG_WINDOW + 0x30]; \
344 stx %l7, [%g3 + TI_REG_WINDOW + 0x38]; \
345 stx %i0, [%g3 + TI_REG_WINDOW + 0x40]; \
346 stx %i1, [%g3 + TI_REG_WINDOW + 0x48]; \
347 stx %i2, [%g3 + TI_REG_WINDOW + 0x50]; \
348 stx %i3, [%g3 + TI_REG_WINDOW + 0x58]; \
349 stx %i4, [%g3 + TI_REG_WINDOW + 0x60]; \
350 stx %i5, [%g3 + TI_REG_WINDOW + 0x68]; \
351 stx %i6, [%g3 + TI_REG_WINDOW + 0x70]; \
352 stx %i7, [%g3 + TI_REG_WINDOW + 0x78]; \
353 add %g1, 1, %g1; \
354 stb %g1, [%g6 + TI_WSAVED]; \
355 saved; \
356 rdpr %cwp, %g1; \
357 sub %g1, 2, %g1; \
358 ba,pt %xcc, etrap_save; \
359 wrpr %g1, %cwp; \
360 nop; nop; nop
361
362/* Normal 32bit spill */
363#define SPILL_2_GENERIC(ASI) \
364 srl %sp, 0, %sp; \
365 stwa %l0, [%sp + %g0] ASI; \
366 mov 0x04, %g3; \
367 stwa %l1, [%sp + %g3] ASI; \
368 add %sp, 0x08, %g1; \
369 stwa %l2, [%g1 + %g0] ASI; \
370 stwa %l3, [%g1 + %g3] ASI; \
371 add %g1, 0x08, %g1; \
372 stwa %l4, [%g1 + %g0] ASI; \
373 stwa %l5, [%g1 + %g3] ASI; \
374 add %g1, 0x08, %g1; \
375 stwa %l6, [%g1 + %g0] ASI; \
376 stwa %l7, [%g1 + %g3] ASI; \
377 add %g1, 0x08, %g1; \
378 stwa %i0, [%g1 + %g0] ASI; \
379 stwa %i1, [%g1 + %g3] ASI; \
380 add %g1, 0x08, %g1; \
381 stwa %i2, [%g1 + %g0] ASI; \
382 stwa %i3, [%g1 + %g3] ASI; \
383 add %g1, 0x08, %g1; \
384 stwa %i4, [%g1 + %g0] ASI; \
385 stwa %i5, [%g1 + %g3] ASI; \
386 add %g1, 0x08, %g1; \
387 stwa %i6, [%g1 + %g0] ASI; \
388 stwa %i7, [%g1 + %g3] ASI; \
389 saved; \
390 retry; nop; nop; \
391 b,a,pt %xcc, spill_fixup_dax; \
392 b,a,pt %xcc, spill_fixup_mna; \
393 b,a,pt %xcc, spill_fixup;
394
395#define SPILL_2_GENERIC_ETRAP \
396etrap_user_spill_32bit: \
397 srl %sp, 0, %sp; \
398 stwa %l0, [%sp + 0x00] %asi; \
399 stwa %l1, [%sp + 0x04] %asi; \
400 stwa %l2, [%sp + 0x08] %asi; \
401 stwa %l3, [%sp + 0x0c] %asi; \
402 stwa %l4, [%sp + 0x10] %asi; \
403 stwa %l5, [%sp + 0x14] %asi; \
404 stwa %l6, [%sp + 0x18] %asi; \
405 stwa %l7, [%sp + 0x1c] %asi; \
406 stwa %i0, [%sp + 0x20] %asi; \
407 stwa %i1, [%sp + 0x24] %asi; \
408 stwa %i2, [%sp + 0x28] %asi; \
409 stwa %i3, [%sp + 0x2c] %asi; \
410 stwa %i4, [%sp + 0x30] %asi; \
411 stwa %i5, [%sp + 0x34] %asi; \
412 stwa %i6, [%sp + 0x38] %asi; \
413 stwa %i7, [%sp + 0x3c] %asi; \
414 saved; \
415 sub %g1, 2, %g1; \
416 ba,pt %xcc, etrap_save; \
417 wrpr %g1, %cwp; \
418 nop; nop; nop; nop; \
419 nop; nop; nop; nop; \
420 ba,a,pt %xcc, etrap_spill_fixup_32bit; \
421 ba,a,pt %xcc, etrap_spill_fixup_32bit; \
422 ba,a,pt %xcc, etrap_spill_fixup_32bit;
423
424#define SPILL_2_GENERIC_ETRAP_FIXUP \
425etrap_spill_fixup_32bit: \
426 ldub [%g6 + TI_WSAVED], %g1; \
427 sll %g1, 3, %g3; \
428 add %g6, %g3, %g3; \
429 stx %sp, [%g3 + TI_RWIN_SPTRS]; \
430 sll %g1, 7, %g3; \
431 add %g6, %g3, %g3; \
432 stw %l0, [%g3 + TI_REG_WINDOW + 0x00]; \
433 stw %l1, [%g3 + TI_REG_WINDOW + 0x04]; \
434 stw %l2, [%g3 + TI_REG_WINDOW + 0x08]; \
435 stw %l3, [%g3 + TI_REG_WINDOW + 0x0c]; \
436 stw %l4, [%g3 + TI_REG_WINDOW + 0x10]; \
437 stw %l5, [%g3 + TI_REG_WINDOW + 0x14]; \
438 stw %l6, [%g3 + TI_REG_WINDOW + 0x18]; \
439 stw %l7, [%g3 + TI_REG_WINDOW + 0x1c]; \
440 stw %i0, [%g3 + TI_REG_WINDOW + 0x20]; \
441 stw %i1, [%g3 + TI_REG_WINDOW + 0x24]; \
442 stw %i2, [%g3 + TI_REG_WINDOW + 0x28]; \
443 stw %i3, [%g3 + TI_REG_WINDOW + 0x2c]; \
444 stw %i4, [%g3 + TI_REG_WINDOW + 0x30]; \
445 stw %i5, [%g3 + TI_REG_WINDOW + 0x34]; \
446 stw %i6, [%g3 + TI_REG_WINDOW + 0x38]; \
447 stw %i7, [%g3 + TI_REG_WINDOW + 0x3c]; \
448 add %g1, 1, %g1; \
449 stb %g1, [%g6 + TI_WSAVED]; \
450 saved; \
451 rdpr %cwp, %g1; \
452 sub %g1, 2, %g1; \
453 ba,pt %xcc, etrap_save; \
454 wrpr %g1, %cwp; \
455 nop; nop; nop
456
457#define SPILL_1_NORMAL SPILL_1_GENERIC(ASI_AIUP)
458#define SPILL_2_NORMAL SPILL_2_GENERIC(ASI_AIUP)
459#define SPILL_3_NORMAL SPILL_0_NORMAL
460#define SPILL_4_NORMAL SPILL_0_NORMAL
461#define SPILL_5_NORMAL SPILL_0_NORMAL
462#define SPILL_6_NORMAL SPILL_0_NORMAL
463#define SPILL_7_NORMAL SPILL_0_NORMAL
464
465#define SPILL_0_OTHER SPILL_0_NORMAL
466#define SPILL_1_OTHER SPILL_1_GENERIC(ASI_AIUS)
467#define SPILL_2_OTHER SPILL_2_GENERIC(ASI_AIUS)
468#define SPILL_3_OTHER SPILL_3_NORMAL
469#define SPILL_4_OTHER SPILL_4_NORMAL
470#define SPILL_5_OTHER SPILL_5_NORMAL
471#define SPILL_6_OTHER SPILL_6_NORMAL
472#define SPILL_7_OTHER SPILL_7_NORMAL
473
474/* Normal kernel fill */
475#define FILL_0_NORMAL \
476 ldx [%sp + STACK_BIAS + 0x00], %l0; \
477 ldx [%sp + STACK_BIAS + 0x08], %l1; \
478 ldx [%sp + STACK_BIAS + 0x10], %l2; \
479 ldx [%sp + STACK_BIAS + 0x18], %l3; \
480 ldx [%sp + STACK_BIAS + 0x20], %l4; \
481 ldx [%sp + STACK_BIAS + 0x28], %l5; \
482 ldx [%sp + STACK_BIAS + 0x30], %l6; \
483 ldx [%sp + STACK_BIAS + 0x38], %l7; \
484 ldx [%sp + STACK_BIAS + 0x40], %i0; \
485 ldx [%sp + STACK_BIAS + 0x48], %i1; \
486 ldx [%sp + STACK_BIAS + 0x50], %i2; \
487 ldx [%sp + STACK_BIAS + 0x58], %i3; \
488 ldx [%sp + STACK_BIAS + 0x60], %i4; \
489 ldx [%sp + STACK_BIAS + 0x68], %i5; \
490 ldx [%sp + STACK_BIAS + 0x70], %i6; \
491 ldx [%sp + STACK_BIAS + 0x78], %i7; \
492 restored; retry; nop; nop; nop; nop; nop; nop; \
493 nop; nop; nop; nop; nop; nop; nop; nop;
494
495#define FILL_0_NORMAL_RTRAP \
496kern_rtt_fill: \
497 rdpr %cwp, %g1; \
498 sub %g1, 1, %g1; \
499 wrpr %g1, %cwp; \
500 ldx [%sp + STACK_BIAS + 0x00], %l0; \
501 ldx [%sp + STACK_BIAS + 0x08], %l1; \
502 ldx [%sp + STACK_BIAS + 0x10], %l2; \
503 ldx [%sp + STACK_BIAS + 0x18], %l3; \
504 ldx [%sp + STACK_BIAS + 0x20], %l4; \
505 ldx [%sp + STACK_BIAS + 0x28], %l5; \
506 ldx [%sp + STACK_BIAS + 0x30], %l6; \
507 ldx [%sp + STACK_BIAS + 0x38], %l7; \
508 ldx [%sp + STACK_BIAS + 0x40], %i0; \
509 ldx [%sp + STACK_BIAS + 0x48], %i1; \
510 ldx [%sp + STACK_BIAS + 0x50], %i2; \
511 ldx [%sp + STACK_BIAS + 0x58], %i3; \
512 ldx [%sp + STACK_BIAS + 0x60], %i4; \
513 ldx [%sp + STACK_BIAS + 0x68], %i5; \
514 ldx [%sp + STACK_BIAS + 0x70], %i6; \
515 ldx [%sp + STACK_BIAS + 0x78], %i7; \
516 restored; \
517 add %g1, 1, %g1; \
518 ba,pt %xcc, kern_rtt_restore; \
519 wrpr %g1, %cwp; \
520 nop; nop; nop; nop; nop; \
521 nop; nop; nop; nop;
522
523
524/* Normal 64bit fill */
525#define FILL_1_GENERIC(ASI) \
526 add %sp, STACK_BIAS + 0x00, %g1; \
527 ldxa [%g1 + %g0] ASI, %l0; \
528 mov 0x08, %g2; \
529 mov 0x10, %g3; \
530 ldxa [%g1 + %g2] ASI, %l1; \
531 mov 0x18, %g5; \
532 ldxa [%g1 + %g3] ASI, %l2; \
533 ldxa [%g1 + %g5] ASI, %l3; \
534 add %g1, 0x20, %g1; \
535 ldxa [%g1 + %g0] ASI, %l4; \
536 ldxa [%g1 + %g2] ASI, %l5; \
537 ldxa [%g1 + %g3] ASI, %l6; \
538 ldxa [%g1 + %g5] ASI, %l7; \
539 add %g1, 0x20, %g1; \
540 ldxa [%g1 + %g0] ASI, %i0; \
541 ldxa [%g1 + %g2] ASI, %i1; \
542 ldxa [%g1 + %g3] ASI, %i2; \
543 ldxa [%g1 + %g5] ASI, %i3; \
544 add %g1, 0x20, %g1; \
545 ldxa [%g1 + %g0] ASI, %i4; \
546 ldxa [%g1 + %g2] ASI, %i5; \
547 ldxa [%g1 + %g3] ASI, %i6; \
548 ldxa [%g1 + %g5] ASI, %i7; \
549 restored; \
550 retry; nop; nop; nop; nop; \
551 b,a,pt %xcc, fill_fixup_dax; \
552 b,a,pt %xcc, fill_fixup_mna; \
553 b,a,pt %xcc, fill_fixup;
554
555#define FILL_1_GENERIC_RTRAP \
556user_rtt_fill_64bit: \
557 ldxa [%sp + STACK_BIAS + 0x00] %asi, %l0; \
558 ldxa [%sp + STACK_BIAS + 0x08] %asi, %l1; \
559 ldxa [%sp + STACK_BIAS + 0x10] %asi, %l2; \
560 ldxa [%sp + STACK_BIAS + 0x18] %asi, %l3; \
561 ldxa [%sp + STACK_BIAS + 0x20] %asi, %l4; \
562 ldxa [%sp + STACK_BIAS + 0x28] %asi, %l5; \
563 ldxa [%sp + STACK_BIAS + 0x30] %asi, %l6; \
564 ldxa [%sp + STACK_BIAS + 0x38] %asi, %l7; \
565 ldxa [%sp + STACK_BIAS + 0x40] %asi, %i0; \
566 ldxa [%sp + STACK_BIAS + 0x48] %asi, %i1; \
567 ldxa [%sp + STACK_BIAS + 0x50] %asi, %i2; \
568 ldxa [%sp + STACK_BIAS + 0x58] %asi, %i3; \
569 ldxa [%sp + STACK_BIAS + 0x60] %asi, %i4; \
570 ldxa [%sp + STACK_BIAS + 0x68] %asi, %i5; \
571 ldxa [%sp + STACK_BIAS + 0x70] %asi, %i6; \
572 ldxa [%sp + STACK_BIAS + 0x78] %asi, %i7; \
573 ba,pt %xcc, user_rtt_pre_restore; \
574 restored; \
575 nop; nop; nop; nop; nop; nop; \
576 nop; nop; nop; nop; nop; \
577 ba,a,pt %xcc, user_rtt_fill_fixup; \
578 ba,a,pt %xcc, user_rtt_fill_fixup; \
579 ba,a,pt %xcc, user_rtt_fill_fixup;
580
581
582/* Normal 32bit fill */
583#define FILL_2_GENERIC(ASI) \
584 srl %sp, 0, %sp; \
585 lduwa [%sp + %g0] ASI, %l0; \
586 mov 0x04, %g2; \
587 mov 0x08, %g3; \
588 lduwa [%sp + %g2] ASI, %l1; \
589 mov 0x0c, %g5; \
590 lduwa [%sp + %g3] ASI, %l2; \
591 lduwa [%sp + %g5] ASI, %l3; \
592 add %sp, 0x10, %g1; \
593 lduwa [%g1 + %g0] ASI, %l4; \
594 lduwa [%g1 + %g2] ASI, %l5; \
595 lduwa [%g1 + %g3] ASI, %l6; \
596 lduwa [%g1 + %g5] ASI, %l7; \
597 add %g1, 0x10, %g1; \
598 lduwa [%g1 + %g0] ASI, %i0; \
599 lduwa [%g1 + %g2] ASI, %i1; \
600 lduwa [%g1 + %g3] ASI, %i2; \
601 lduwa [%g1 + %g5] ASI, %i3; \
602 add %g1, 0x10, %g1; \
603 lduwa [%g1 + %g0] ASI, %i4; \
604 lduwa [%g1 + %g2] ASI, %i5; \
605 lduwa [%g1 + %g3] ASI, %i6; \
606 lduwa [%g1 + %g5] ASI, %i7; \
607 restored; \
608 retry; nop; nop; nop; nop; \
609 b,a,pt %xcc, fill_fixup_dax; \
610 b,a,pt %xcc, fill_fixup_mna; \
611 b,a,pt %xcc, fill_fixup;
612
613#define FILL_2_GENERIC_RTRAP \
614user_rtt_fill_32bit: \
615 srl %sp, 0, %sp; \
616 lduwa [%sp + 0x00] %asi, %l0; \
617 lduwa [%sp + 0x04] %asi, %l1; \
618 lduwa [%sp + 0x08] %asi, %l2; \
619 lduwa [%sp + 0x0c] %asi, %l3; \
620 lduwa [%sp + 0x10] %asi, %l4; \
621 lduwa [%sp + 0x14] %asi, %l5; \
622 lduwa [%sp + 0x18] %asi, %l6; \
623 lduwa [%sp + 0x1c] %asi, %l7; \
624 lduwa [%sp + 0x20] %asi, %i0; \
625 lduwa [%sp + 0x24] %asi, %i1; \
626 lduwa [%sp + 0x28] %asi, %i2; \
627 lduwa [%sp + 0x2c] %asi, %i3; \
628 lduwa [%sp + 0x30] %asi, %i4; \
629 lduwa [%sp + 0x34] %asi, %i5; \
630 lduwa [%sp + 0x38] %asi, %i6; \
631 lduwa [%sp + 0x3c] %asi, %i7; \
632 ba,pt %xcc, user_rtt_pre_restore; \
633 restored; \
634 nop; nop; nop; nop; nop; \
635 nop; nop; nop; nop; nop; \
636 ba,a,pt %xcc, user_rtt_fill_fixup; \
637 ba,a,pt %xcc, user_rtt_fill_fixup; \
638 ba,a,pt %xcc, user_rtt_fill_fixup;
639
640
641#define FILL_1_NORMAL FILL_1_GENERIC(ASI_AIUP)
642#define FILL_2_NORMAL FILL_2_GENERIC(ASI_AIUP)
643#define FILL_3_NORMAL FILL_0_NORMAL
644#define FILL_4_NORMAL FILL_0_NORMAL
645#define FILL_5_NORMAL FILL_0_NORMAL
646#define FILL_6_NORMAL FILL_0_NORMAL
647#define FILL_7_NORMAL FILL_0_NORMAL
648
649#define FILL_0_OTHER FILL_0_NORMAL
650#define FILL_1_OTHER FILL_1_GENERIC(ASI_AIUS)
651#define FILL_2_OTHER FILL_2_GENERIC(ASI_AIUS)
652#define FILL_3_OTHER FILL_3_NORMAL
653#define FILL_4_OTHER FILL_4_NORMAL
654#define FILL_5_OTHER FILL_5_NORMAL
655#define FILL_6_OTHER FILL_6_NORMAL
656#define FILL_7_OTHER FILL_7_NORMAL
657
658#endif /* !(_SPARC64_TTABLE_H) */
diff --git a/include/asm-sparc/types.h b/include/asm-sparc/types.h
index 07734f942405..8c28fde5eaa2 100644
--- a/include/asm-sparc/types.h
+++ b/include/asm-sparc/types.h
@@ -1,6 +1,5 @@
1#ifndef _SPARC_TYPES_H 1#ifndef _SPARC_TYPES_H
2#define _SPARC_TYPES_H 2#define _SPARC_TYPES_H
3
4/* 3/*
5 * This file is never included by application software unless 4 * This file is never included by application software unless
6 * explicitly requested (e.g., via linux/types.h) in which case the 5 * explicitly requested (e.g., via linux/types.h) in which case the
@@ -8,6 +7,35 @@
8 * not a major issue. However, for interoperability, libraries still 7 * not a major issue. However, for interoperability, libraries still
9 * need to be careful to avoid a name clashes. 8 * need to be careful to avoid a name clashes.
10 */ 9 */
10
11#if defined(__sparc__) && defined(__arch64__)
12
13/*** SPARC 64 bit ***/
14#include <asm-generic/int-l64.h>
15
16#ifndef __ASSEMBLY__
17
18typedef unsigned short umode_t;
19
20#endif /* __ASSEMBLY__ */
21
22#ifdef __KERNEL__
23
24#define BITS_PER_LONG 64
25
26#ifndef __ASSEMBLY__
27
28/* Dma addresses come in generic and 64-bit flavours. */
29
30typedef u32 dma_addr_t;
31typedef u64 dma64_addr_t;
32
33#endif /* __ASSEMBLY__ */
34
35#endif /* __KERNEL__ */
36#else
37
38/*** SPARC 32 bit ***/
11#include <asm-generic/int-ll64.h> 39#include <asm-generic/int-ll64.h>
12 40
13#ifndef __ASSEMBLY__ 41#ifndef __ASSEMBLY__
@@ -29,4 +57,6 @@ typedef u32 dma64_addr_t;
29 57
30#endif /* __KERNEL__ */ 58#endif /* __KERNEL__ */
31 59
60#endif /* defined(__sparc__) && defined(__arch64__) */
61
32#endif /* defined(_SPARC_TYPES_H) */ 62#endif /* defined(_SPARC_TYPES_H) */
diff --git a/include/asm-sparc/uaccess.h b/include/asm-sparc/uaccess.h
index 47d5619d43fa..424facce5238 100644
--- a/include/asm-sparc/uaccess.h
+++ b/include/asm-sparc/uaccess.h
@@ -1,336 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_UACCESS_H
2 * uaccess.h: User space memore access functions. 2#define ___ASM_SPARC_UACCESS_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 4#include <asm-sparc/uaccess_64.h>
5 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 5#else
6 */ 6#include <asm-sparc/uaccess_32.h>
7#ifndef _ASM_UACCESS_H 7#endif
8#define _ASM_UACCESS_H
9
10#ifdef __KERNEL__
11#include <linux/compiler.h>
12#include <linux/sched.h>
13#include <linux/string.h>
14#include <linux/errno.h>
15#include <asm/vac-ops.h>
16#endif 8#endif
17
18#ifndef __ASSEMBLY__
19
20/* Sparc is not segmented, however we need to be able to fool access_ok()
21 * when doing system calls from kernel mode legitimately.
22 *
23 * "For historical reasons, these macros are grossly misnamed." -Linus
24 */
25
26#define KERNEL_DS ((mm_segment_t) { 0 })
27#define USER_DS ((mm_segment_t) { -1 })
28
29#define VERIFY_READ 0
30#define VERIFY_WRITE 1
31
32#define get_ds() (KERNEL_DS)
33#define get_fs() (current->thread.current_ds)
34#define set_fs(val) ((current->thread.current_ds) = (val))
35
36#define segment_eq(a,b) ((a).seg == (b).seg)
37
38/* We have there a nice not-mapped page at PAGE_OFFSET - PAGE_SIZE, so that this test
39 * can be fairly lightweight.
40 * No one can read/write anything from userland in the kernel space by setting
41 * large size and address near to PAGE_OFFSET - a fault will break his intentions.
42 */
43#define __user_ok(addr, size) ({ (void)(size); (addr) < STACK_TOP; })
44#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS))
45#define __access_ok(addr,size) (__user_ok((addr) & get_fs().seg,(size)))
46#define access_ok(type, addr, size) \
47 ({ (void)(type); __access_ok((unsigned long)(addr), size); })
48
49/*
50 * The exception table consists of pairs of addresses: the first is the
51 * address of an instruction that is allowed to fault, and the second is
52 * the address at which the program should continue. No registers are
53 * modified, so it is entirely up to the continuation code to figure out
54 * what to do.
55 *
56 * All the routines below use bits of fixup code that are out of line
57 * with the main instruction path. This means when everything is well,
58 * we don't even have to jump over them. Further, they do not intrude
59 * on our cache or tlb entries.
60 *
61 * There is a special way how to put a range of potentially faulting
62 * insns (like twenty ldd/std's with now intervening other instructions)
63 * You specify address of first in insn and 0 in fixup and in the next
64 * exception_table_entry you specify last potentially faulting insn + 1
65 * and in fixup the routine which should handle the fault.
66 * That fixup code will get
67 * (faulting_insn_address - first_insn_in_the_range_address)/4
68 * in %g2 (ie. index of the faulting instruction in the range).
69 */
70
71struct exception_table_entry
72{
73 unsigned long insn, fixup;
74};
75
76/* Returns 0 if exception not found and fixup otherwise. */
77extern unsigned long search_extables_range(unsigned long addr, unsigned long *g2);
78
79extern void __ret_efault(void);
80
81/* Uh, these should become the main single-value transfer routines..
82 * They automatically use the right size if we just have the right
83 * pointer type..
84 *
85 * This gets kind of ugly. We want to return _two_ values in "get_user()"
86 * and yet we don't want to do any pointers, because that is too much
87 * of a performance impact. Thus we have a few rather ugly macros here,
88 * and hide all the ugliness from the user.
89 */
90#define put_user(x,ptr) ({ \
91unsigned long __pu_addr = (unsigned long)(ptr); \
92__chk_user_ptr(ptr); \
93__put_user_check((__typeof__(*(ptr)))(x),__pu_addr,sizeof(*(ptr))); })
94
95#define get_user(x,ptr) ({ \
96unsigned long __gu_addr = (unsigned long)(ptr); \
97__chk_user_ptr(ptr); \
98__get_user_check((x),__gu_addr,sizeof(*(ptr)),__typeof__(*(ptr))); })
99
100/*
101 * The "__xxx" versions do not do address space checking, useful when
102 * doing multiple accesses to the same area (the user has to do the
103 * checks by hand with "access_ok()")
104 */
105#define __put_user(x,ptr) __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
106#define __get_user(x,ptr) __get_user_nocheck((x),(ptr),sizeof(*(ptr)),__typeof__(*(ptr)))
107
108struct __large_struct { unsigned long buf[100]; };
109#define __m(x) ((struct __large_struct __user *)(x))
110
111#define __put_user_check(x,addr,size) ({ \
112register int __pu_ret; \
113if (__access_ok(addr,size)) { \
114switch (size) { \
115case 1: __put_user_asm(x,b,addr,__pu_ret); break; \
116case 2: __put_user_asm(x,h,addr,__pu_ret); break; \
117case 4: __put_user_asm(x,,addr,__pu_ret); break; \
118case 8: __put_user_asm(x,d,addr,__pu_ret); break; \
119default: __pu_ret = __put_user_bad(); break; \
120} } else { __pu_ret = -EFAULT; } __pu_ret; })
121
122#define __put_user_nocheck(x,addr,size) ({ \
123register int __pu_ret; \
124switch (size) { \
125case 1: __put_user_asm(x,b,addr,__pu_ret); break; \
126case 2: __put_user_asm(x,h,addr,__pu_ret); break; \
127case 4: __put_user_asm(x,,addr,__pu_ret); break; \
128case 8: __put_user_asm(x,d,addr,__pu_ret); break; \
129default: __pu_ret = __put_user_bad(); break; \
130} __pu_ret; })
131
132#define __put_user_asm(x,size,addr,ret) \
133__asm__ __volatile__( \
134 "/* Put user asm, inline. */\n" \
135"1:\t" "st"#size " %1, %2\n\t" \
136 "clr %0\n" \
137"2:\n\n\t" \
138 ".section .fixup,#alloc,#execinstr\n\t" \
139 ".align 4\n" \
140"3:\n\t" \
141 "b 2b\n\t" \
142 " mov %3, %0\n\t" \
143 ".previous\n\n\t" \
144 ".section __ex_table,#alloc\n\t" \
145 ".align 4\n\t" \
146 ".word 1b, 3b\n\t" \
147 ".previous\n\n\t" \
148 : "=&r" (ret) : "r" (x), "m" (*__m(addr)), \
149 "i" (-EFAULT))
150
151extern int __put_user_bad(void);
152
153#define __get_user_check(x,addr,size,type) ({ \
154register int __gu_ret; \
155register unsigned long __gu_val; \
156if (__access_ok(addr,size)) { \
157switch (size) { \
158case 1: __get_user_asm(__gu_val,ub,addr,__gu_ret); break; \
159case 2: __get_user_asm(__gu_val,uh,addr,__gu_ret); break; \
160case 4: __get_user_asm(__gu_val,,addr,__gu_ret); break; \
161case 8: __get_user_asm(__gu_val,d,addr,__gu_ret); break; \
162default: __gu_val = 0; __gu_ret = __get_user_bad(); break; \
163} } else { __gu_val = 0; __gu_ret = -EFAULT; } x = (type) __gu_val; __gu_ret; })
164
165#define __get_user_check_ret(x,addr,size,type,retval) ({ \
166register unsigned long __gu_val __asm__ ("l1"); \
167if (__access_ok(addr,size)) { \
168switch (size) { \
169case 1: __get_user_asm_ret(__gu_val,ub,addr,retval); break; \
170case 2: __get_user_asm_ret(__gu_val,uh,addr,retval); break; \
171case 4: __get_user_asm_ret(__gu_val,,addr,retval); break; \
172case 8: __get_user_asm_ret(__gu_val,d,addr,retval); break; \
173default: if (__get_user_bad()) return retval; \
174} x = (type) __gu_val; } else return retval; })
175
176#define __get_user_nocheck(x,addr,size,type) ({ \
177register int __gu_ret; \
178register unsigned long __gu_val; \
179switch (size) { \
180case 1: __get_user_asm(__gu_val,ub,addr,__gu_ret); break; \
181case 2: __get_user_asm(__gu_val,uh,addr,__gu_ret); break; \
182case 4: __get_user_asm(__gu_val,,addr,__gu_ret); break; \
183case 8: __get_user_asm(__gu_val,d,addr,__gu_ret); break; \
184default: __gu_val = 0; __gu_ret = __get_user_bad(); break; \
185} x = (type) __gu_val; __gu_ret; })
186
187#define __get_user_nocheck_ret(x,addr,size,type,retval) ({ \
188register unsigned long __gu_val __asm__ ("l1"); \
189switch (size) { \
190case 1: __get_user_asm_ret(__gu_val,ub,addr,retval); break; \
191case 2: __get_user_asm_ret(__gu_val,uh,addr,retval); break; \
192case 4: __get_user_asm_ret(__gu_val,,addr,retval); break; \
193case 8: __get_user_asm_ret(__gu_val,d,addr,retval); break; \
194default: if (__get_user_bad()) return retval; \
195} x = (type) __gu_val; })
196
197#define __get_user_asm(x,size,addr,ret) \
198__asm__ __volatile__( \
199 "/* Get user asm, inline. */\n" \
200"1:\t" "ld"#size " %2, %1\n\t" \
201 "clr %0\n" \
202"2:\n\n\t" \
203 ".section .fixup,#alloc,#execinstr\n\t" \
204 ".align 4\n" \
205"3:\n\t" \
206 "clr %1\n\t" \
207 "b 2b\n\t" \
208 " mov %3, %0\n\n\t" \
209 ".previous\n\t" \
210 ".section __ex_table,#alloc\n\t" \
211 ".align 4\n\t" \
212 ".word 1b, 3b\n\n\t" \
213 ".previous\n\t" \
214 : "=&r" (ret), "=&r" (x) : "m" (*__m(addr)), \
215 "i" (-EFAULT))
216
217#define __get_user_asm_ret(x,size,addr,retval) \
218if (__builtin_constant_p(retval) && retval == -EFAULT) \
219__asm__ __volatile__( \
220 "/* Get user asm ret, inline. */\n" \
221"1:\t" "ld"#size " %1, %0\n\n\t" \
222 ".section __ex_table,#alloc\n\t" \
223 ".align 4\n\t" \
224 ".word 1b,__ret_efault\n\n\t" \
225 ".previous\n\t" \
226 : "=&r" (x) : "m" (*__m(addr))); \
227else \
228__asm__ __volatile__( \
229 "/* Get user asm ret, inline. */\n" \
230"1:\t" "ld"#size " %1, %0\n\n\t" \
231 ".section .fixup,#alloc,#execinstr\n\t" \
232 ".align 4\n" \
233"3:\n\t" \
234 "ret\n\t" \
235 " restore %%g0, %2, %%o0\n\n\t" \
236 ".previous\n\t" \
237 ".section __ex_table,#alloc\n\t" \
238 ".align 4\n\t" \
239 ".word 1b, 3b\n\n\t" \
240 ".previous\n\t" \
241 : "=&r" (x) : "m" (*__m(addr)), "i" (retval))
242
243extern int __get_user_bad(void);
244
245extern unsigned long __copy_user(void __user *to, const void __user *from, unsigned long size);
246
247static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
248{
249 if (n && __access_ok((unsigned long) to, n))
250 return __copy_user(to, (__force void __user *) from, n);
251 else
252 return n;
253}
254
255static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
256{
257 return __copy_user(to, (__force void __user *) from, n);
258}
259
260static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
261{
262 if (n && __access_ok((unsigned long) from, n))
263 return __copy_user((__force void __user *) to, from, n);
264 else
265 return n;
266}
267
268static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
269{
270 return __copy_user((__force void __user *) to, from, n);
271}
272
273#define __copy_to_user_inatomic __copy_to_user
274#define __copy_from_user_inatomic __copy_from_user
275
276static inline unsigned long __clear_user(void __user *addr, unsigned long size)
277{
278 unsigned long ret;
279
280 __asm__ __volatile__ (
281 ".section __ex_table,#alloc\n\t"
282 ".align 4\n\t"
283 ".word 1f,3\n\t"
284 ".previous\n\t"
285 "mov %2, %%o1\n"
286 "1:\n\t"
287 "call __bzero\n\t"
288 " mov %1, %%o0\n\t"
289 "mov %%o0, %0\n"
290 : "=r" (ret) : "r" (addr), "r" (size) :
291 "o0", "o1", "o2", "o3", "o4", "o5", "o7",
292 "g1", "g2", "g3", "g4", "g5", "g7", "cc");
293
294 return ret;
295}
296
297static inline unsigned long clear_user(void __user *addr, unsigned long n)
298{
299 if (n && __access_ok((unsigned long) addr, n))
300 return __clear_user(addr, n);
301 else
302 return n;
303}
304
305extern long __strncpy_from_user(char *dest, const char __user *src, long count);
306
307static inline long strncpy_from_user(char *dest, const char __user *src, long count)
308{
309 if (__access_ok((unsigned long) src, count))
310 return __strncpy_from_user(dest, src, count);
311 else
312 return -EFAULT;
313}
314
315extern long __strlen_user(const char __user *);
316extern long __strnlen_user(const char __user *, long len);
317
318static inline long strlen_user(const char __user *str)
319{
320 if (!access_ok(VERIFY_READ, str, 0))
321 return 0;
322 else
323 return __strlen_user(str);
324}
325
326static inline long strnlen_user(const char __user *str, long len)
327{
328 if (!access_ok(VERIFY_READ, str, 0))
329 return 0;
330 else
331 return __strnlen_user(str, len);
332}
333
334#endif /* __ASSEMBLY__ */
335
336#endif /* _ASM_UACCESS_H */
diff --git a/include/asm-sparc/uaccess_32.h b/include/asm-sparc/uaccess_32.h
new file mode 100644
index 000000000000..47d5619d43fa
--- /dev/null
+++ b/include/asm-sparc/uaccess_32.h
@@ -0,0 +1,336 @@
1/*
2 * uaccess.h: User space memore access functions.
3 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7#ifndef _ASM_UACCESS_H
8#define _ASM_UACCESS_H
9
10#ifdef __KERNEL__
11#include <linux/compiler.h>
12#include <linux/sched.h>
13#include <linux/string.h>
14#include <linux/errno.h>
15#include <asm/vac-ops.h>
16#endif
17
18#ifndef __ASSEMBLY__
19
20/* Sparc is not segmented, however we need to be able to fool access_ok()
21 * when doing system calls from kernel mode legitimately.
22 *
23 * "For historical reasons, these macros are grossly misnamed." -Linus
24 */
25
26#define KERNEL_DS ((mm_segment_t) { 0 })
27#define USER_DS ((mm_segment_t) { -1 })
28
29#define VERIFY_READ 0
30#define VERIFY_WRITE 1
31
32#define get_ds() (KERNEL_DS)
33#define get_fs() (current->thread.current_ds)
34#define set_fs(val) ((current->thread.current_ds) = (val))
35
36#define segment_eq(a,b) ((a).seg == (b).seg)
37
38/* We have there a nice not-mapped page at PAGE_OFFSET - PAGE_SIZE, so that this test
39 * can be fairly lightweight.
40 * No one can read/write anything from userland in the kernel space by setting
41 * large size and address near to PAGE_OFFSET - a fault will break his intentions.
42 */
43#define __user_ok(addr, size) ({ (void)(size); (addr) < STACK_TOP; })
44#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS))
45#define __access_ok(addr,size) (__user_ok((addr) & get_fs().seg,(size)))
46#define access_ok(type, addr, size) \
47 ({ (void)(type); __access_ok((unsigned long)(addr), size); })
48
49/*
50 * The exception table consists of pairs of addresses: the first is the
51 * address of an instruction that is allowed to fault, and the second is
52 * the address at which the program should continue. No registers are
53 * modified, so it is entirely up to the continuation code to figure out
54 * what to do.
55 *
56 * All the routines below use bits of fixup code that are out of line
57 * with the main instruction path. This means when everything is well,
58 * we don't even have to jump over them. Further, they do not intrude
59 * on our cache or tlb entries.
60 *
61 * There is a special way how to put a range of potentially faulting
62 * insns (like twenty ldd/std's with now intervening other instructions)
63 * You specify address of first in insn and 0 in fixup and in the next
64 * exception_table_entry you specify last potentially faulting insn + 1
65 * and in fixup the routine which should handle the fault.
66 * That fixup code will get
67 * (faulting_insn_address - first_insn_in_the_range_address)/4
68 * in %g2 (ie. index of the faulting instruction in the range).
69 */
70
71struct exception_table_entry
72{
73 unsigned long insn, fixup;
74};
75
76/* Returns 0 if exception not found and fixup otherwise. */
77extern unsigned long search_extables_range(unsigned long addr, unsigned long *g2);
78
79extern void __ret_efault(void);
80
81/* Uh, these should become the main single-value transfer routines..
82 * They automatically use the right size if we just have the right
83 * pointer type..
84 *
85 * This gets kind of ugly. We want to return _two_ values in "get_user()"
86 * and yet we don't want to do any pointers, because that is too much
87 * of a performance impact. Thus we have a few rather ugly macros here,
88 * and hide all the ugliness from the user.
89 */
90#define put_user(x,ptr) ({ \
91unsigned long __pu_addr = (unsigned long)(ptr); \
92__chk_user_ptr(ptr); \
93__put_user_check((__typeof__(*(ptr)))(x),__pu_addr,sizeof(*(ptr))); })
94
95#define get_user(x,ptr) ({ \
96unsigned long __gu_addr = (unsigned long)(ptr); \
97__chk_user_ptr(ptr); \
98__get_user_check((x),__gu_addr,sizeof(*(ptr)),__typeof__(*(ptr))); })
99
100/*
101 * The "__xxx" versions do not do address space checking, useful when
102 * doing multiple accesses to the same area (the user has to do the
103 * checks by hand with "access_ok()")
104 */
105#define __put_user(x,ptr) __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
106#define __get_user(x,ptr) __get_user_nocheck((x),(ptr),sizeof(*(ptr)),__typeof__(*(ptr)))
107
108struct __large_struct { unsigned long buf[100]; };
109#define __m(x) ((struct __large_struct __user *)(x))
110
111#define __put_user_check(x,addr,size) ({ \
112register int __pu_ret; \
113if (__access_ok(addr,size)) { \
114switch (size) { \
115case 1: __put_user_asm(x,b,addr,__pu_ret); break; \
116case 2: __put_user_asm(x,h,addr,__pu_ret); break; \
117case 4: __put_user_asm(x,,addr,__pu_ret); break; \
118case 8: __put_user_asm(x,d,addr,__pu_ret); break; \
119default: __pu_ret = __put_user_bad(); break; \
120} } else { __pu_ret = -EFAULT; } __pu_ret; })
121
122#define __put_user_nocheck(x,addr,size) ({ \
123register int __pu_ret; \
124switch (size) { \
125case 1: __put_user_asm(x,b,addr,__pu_ret); break; \
126case 2: __put_user_asm(x,h,addr,__pu_ret); break; \
127case 4: __put_user_asm(x,,addr,__pu_ret); break; \
128case 8: __put_user_asm(x,d,addr,__pu_ret); break; \
129default: __pu_ret = __put_user_bad(); break; \
130} __pu_ret; })
131
132#define __put_user_asm(x,size,addr,ret) \
133__asm__ __volatile__( \
134 "/* Put user asm, inline. */\n" \
135"1:\t" "st"#size " %1, %2\n\t" \
136 "clr %0\n" \
137"2:\n\n\t" \
138 ".section .fixup,#alloc,#execinstr\n\t" \
139 ".align 4\n" \
140"3:\n\t" \
141 "b 2b\n\t" \
142 " mov %3, %0\n\t" \
143 ".previous\n\n\t" \
144 ".section __ex_table,#alloc\n\t" \
145 ".align 4\n\t" \
146 ".word 1b, 3b\n\t" \
147 ".previous\n\n\t" \
148 : "=&r" (ret) : "r" (x), "m" (*__m(addr)), \
149 "i" (-EFAULT))
150
151extern int __put_user_bad(void);
152
153#define __get_user_check(x,addr,size,type) ({ \
154register int __gu_ret; \
155register unsigned long __gu_val; \
156if (__access_ok(addr,size)) { \
157switch (size) { \
158case 1: __get_user_asm(__gu_val,ub,addr,__gu_ret); break; \
159case 2: __get_user_asm(__gu_val,uh,addr,__gu_ret); break; \
160case 4: __get_user_asm(__gu_val,,addr,__gu_ret); break; \
161case 8: __get_user_asm(__gu_val,d,addr,__gu_ret); break; \
162default: __gu_val = 0; __gu_ret = __get_user_bad(); break; \
163} } else { __gu_val = 0; __gu_ret = -EFAULT; } x = (type) __gu_val; __gu_ret; })
164
165#define __get_user_check_ret(x,addr,size,type,retval) ({ \
166register unsigned long __gu_val __asm__ ("l1"); \
167if (__access_ok(addr,size)) { \
168switch (size) { \
169case 1: __get_user_asm_ret(__gu_val,ub,addr,retval); break; \
170case 2: __get_user_asm_ret(__gu_val,uh,addr,retval); break; \
171case 4: __get_user_asm_ret(__gu_val,,addr,retval); break; \
172case 8: __get_user_asm_ret(__gu_val,d,addr,retval); break; \
173default: if (__get_user_bad()) return retval; \
174} x = (type) __gu_val; } else return retval; })
175
176#define __get_user_nocheck(x,addr,size,type) ({ \
177register int __gu_ret; \
178register unsigned long __gu_val; \
179switch (size) { \
180case 1: __get_user_asm(__gu_val,ub,addr,__gu_ret); break; \
181case 2: __get_user_asm(__gu_val,uh,addr,__gu_ret); break; \
182case 4: __get_user_asm(__gu_val,,addr,__gu_ret); break; \
183case 8: __get_user_asm(__gu_val,d,addr,__gu_ret); break; \
184default: __gu_val = 0; __gu_ret = __get_user_bad(); break; \
185} x = (type) __gu_val; __gu_ret; })
186
187#define __get_user_nocheck_ret(x,addr,size,type,retval) ({ \
188register unsigned long __gu_val __asm__ ("l1"); \
189switch (size) { \
190case 1: __get_user_asm_ret(__gu_val,ub,addr,retval); break; \
191case 2: __get_user_asm_ret(__gu_val,uh,addr,retval); break; \
192case 4: __get_user_asm_ret(__gu_val,,addr,retval); break; \
193case 8: __get_user_asm_ret(__gu_val,d,addr,retval); break; \
194default: if (__get_user_bad()) return retval; \
195} x = (type) __gu_val; })
196
197#define __get_user_asm(x,size,addr,ret) \
198__asm__ __volatile__( \
199 "/* Get user asm, inline. */\n" \
200"1:\t" "ld"#size " %2, %1\n\t" \
201 "clr %0\n" \
202"2:\n\n\t" \
203 ".section .fixup,#alloc,#execinstr\n\t" \
204 ".align 4\n" \
205"3:\n\t" \
206 "clr %1\n\t" \
207 "b 2b\n\t" \
208 " mov %3, %0\n\n\t" \
209 ".previous\n\t" \
210 ".section __ex_table,#alloc\n\t" \
211 ".align 4\n\t" \
212 ".word 1b, 3b\n\n\t" \
213 ".previous\n\t" \
214 : "=&r" (ret), "=&r" (x) : "m" (*__m(addr)), \
215 "i" (-EFAULT))
216
217#define __get_user_asm_ret(x,size,addr,retval) \
218if (__builtin_constant_p(retval) && retval == -EFAULT) \
219__asm__ __volatile__( \
220 "/* Get user asm ret, inline. */\n" \
221"1:\t" "ld"#size " %1, %0\n\n\t" \
222 ".section __ex_table,#alloc\n\t" \
223 ".align 4\n\t" \
224 ".word 1b,__ret_efault\n\n\t" \
225 ".previous\n\t" \
226 : "=&r" (x) : "m" (*__m(addr))); \
227else \
228__asm__ __volatile__( \
229 "/* Get user asm ret, inline. */\n" \
230"1:\t" "ld"#size " %1, %0\n\n\t" \
231 ".section .fixup,#alloc,#execinstr\n\t" \
232 ".align 4\n" \
233"3:\n\t" \
234 "ret\n\t" \
235 " restore %%g0, %2, %%o0\n\n\t" \
236 ".previous\n\t" \
237 ".section __ex_table,#alloc\n\t" \
238 ".align 4\n\t" \
239 ".word 1b, 3b\n\n\t" \
240 ".previous\n\t" \
241 : "=&r" (x) : "m" (*__m(addr)), "i" (retval))
242
243extern int __get_user_bad(void);
244
245extern unsigned long __copy_user(void __user *to, const void __user *from, unsigned long size);
246
247static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
248{
249 if (n && __access_ok((unsigned long) to, n))
250 return __copy_user(to, (__force void __user *) from, n);
251 else
252 return n;
253}
254
255static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
256{
257 return __copy_user(to, (__force void __user *) from, n);
258}
259
260static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
261{
262 if (n && __access_ok((unsigned long) from, n))
263 return __copy_user((__force void __user *) to, from, n);
264 else
265 return n;
266}
267
268static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
269{
270 return __copy_user((__force void __user *) to, from, n);
271}
272
273#define __copy_to_user_inatomic __copy_to_user
274#define __copy_from_user_inatomic __copy_from_user
275
276static inline unsigned long __clear_user(void __user *addr, unsigned long size)
277{
278 unsigned long ret;
279
280 __asm__ __volatile__ (
281 ".section __ex_table,#alloc\n\t"
282 ".align 4\n\t"
283 ".word 1f,3\n\t"
284 ".previous\n\t"
285 "mov %2, %%o1\n"
286 "1:\n\t"
287 "call __bzero\n\t"
288 " mov %1, %%o0\n\t"
289 "mov %%o0, %0\n"
290 : "=r" (ret) : "r" (addr), "r" (size) :
291 "o0", "o1", "o2", "o3", "o4", "o5", "o7",
292 "g1", "g2", "g3", "g4", "g5", "g7", "cc");
293
294 return ret;
295}
296
297static inline unsigned long clear_user(void __user *addr, unsigned long n)
298{
299 if (n && __access_ok((unsigned long) addr, n))
300 return __clear_user(addr, n);
301 else
302 return n;
303}
304
305extern long __strncpy_from_user(char *dest, const char __user *src, long count);
306
307static inline long strncpy_from_user(char *dest, const char __user *src, long count)
308{
309 if (__access_ok((unsigned long) src, count))
310 return __strncpy_from_user(dest, src, count);
311 else
312 return -EFAULT;
313}
314
315extern long __strlen_user(const char __user *);
316extern long __strnlen_user(const char __user *, long len);
317
318static inline long strlen_user(const char __user *str)
319{
320 if (!access_ok(VERIFY_READ, str, 0))
321 return 0;
322 else
323 return __strlen_user(str);
324}
325
326static inline long strnlen_user(const char __user *str, long len)
327{
328 if (!access_ok(VERIFY_READ, str, 0))
329 return 0;
330 else
331 return __strnlen_user(str, len);
332}
333
334#endif /* __ASSEMBLY__ */
335
336#endif /* _ASM_UACCESS_H */
diff --git a/include/asm-sparc/uaccess_64.h b/include/asm-sparc/uaccess_64.h
new file mode 100644
index 000000000000..296ef30e05c8
--- /dev/null
+++ b/include/asm-sparc/uaccess_64.h
@@ -0,0 +1,273 @@
1#ifndef _ASM_UACCESS_H
2#define _ASM_UACCESS_H
3
4/*
5 * User space memory access functions
6 */
7
8#ifdef __KERNEL__
9#include <linux/compiler.h>
10#include <linux/sched.h>
11#include <linux/string.h>
12#include <asm/asi.h>
13#include <asm/system.h>
14#include <asm/spitfire.h>
15#include <asm-generic/uaccess.h>
16#endif
17
18#ifndef __ASSEMBLY__
19
20/*
21 * Sparc64 is segmented, though more like the M68K than the I386.
22 * We use the secondary ASI to address user memory, which references a
23 * completely different VM map, thus there is zero chance of the user
24 * doing something queer and tricking us into poking kernel memory.
25 *
26 * What is left here is basically what is needed for the other parts of
27 * the kernel that expect to be able to manipulate, erum, "segments".
28 * Or perhaps more properly, permissions.
29 *
30 * "For historical reasons, these macros are grossly misnamed." -Linus
31 */
32
33#define KERNEL_DS ((mm_segment_t) { ASI_P })
34#define USER_DS ((mm_segment_t) { ASI_AIUS }) /* har har har */
35
36#define VERIFY_READ 0
37#define VERIFY_WRITE 1
38
39#define get_fs() ((mm_segment_t) { get_thread_current_ds() })
40#define get_ds() (KERNEL_DS)
41
42#define segment_eq(a,b) ((a).seg == (b).seg)
43
44#define set_fs(val) \
45do { \
46 set_thread_current_ds((val).seg); \
47 __asm__ __volatile__ ("wr %%g0, %0, %%asi" : : "r" ((val).seg)); \
48} while(0)
49
50static inline int __access_ok(const void __user * addr, unsigned long size)
51{
52 return 1;
53}
54
55static inline int access_ok(int type, const void __user * addr, unsigned long size)
56{
57 return 1;
58}
59
60/*
61 * The exception table consists of pairs of addresses: the first is the
62 * address of an instruction that is allowed to fault, and the second is
63 * the address at which the program should continue. No registers are
64 * modified, so it is entirely up to the continuation code to figure out
65 * what to do.
66 *
67 * All the routines below use bits of fixup code that are out of line
68 * with the main instruction path. This means when everything is well,
69 * we don't even have to jump over them. Further, they do not intrude
70 * on our cache or tlb entries.
71 */
72
73struct exception_table_entry {
74 unsigned int insn, fixup;
75};
76
77extern void __ret_efault(void);
78extern void __retl_efault(void);
79
80/* Uh, these should become the main single-value transfer routines..
81 * They automatically use the right size if we just have the right
82 * pointer type..
83 *
84 * This gets kind of ugly. We want to return _two_ values in "get_user()"
85 * and yet we don't want to do any pointers, because that is too much
86 * of a performance impact. Thus we have a few rather ugly macros here,
87 * and hide all the ugliness from the user.
88 */
89#define put_user(x,ptr) ({ \
90unsigned long __pu_addr = (unsigned long)(ptr); \
91__chk_user_ptr(ptr); \
92__put_user_nocheck((__typeof__(*(ptr)))(x),__pu_addr,sizeof(*(ptr))); })
93
94#define get_user(x,ptr) ({ \
95unsigned long __gu_addr = (unsigned long)(ptr); \
96__chk_user_ptr(ptr); \
97__get_user_nocheck((x),__gu_addr,sizeof(*(ptr)),__typeof__(*(ptr))); })
98
99#define __put_user(x,ptr) put_user(x,ptr)
100#define __get_user(x,ptr) get_user(x,ptr)
101
102struct __large_struct { unsigned long buf[100]; };
103#define __m(x) ((struct __large_struct *)(x))
104
105#define __put_user_nocheck(data,addr,size) ({ \
106register int __pu_ret; \
107switch (size) { \
108case 1: __put_user_asm(data,b,addr,__pu_ret); break; \
109case 2: __put_user_asm(data,h,addr,__pu_ret); break; \
110case 4: __put_user_asm(data,w,addr,__pu_ret); break; \
111case 8: __put_user_asm(data,x,addr,__pu_ret); break; \
112default: __pu_ret = __put_user_bad(); break; \
113} __pu_ret; })
114
115#define __put_user_asm(x,size,addr,ret) \
116__asm__ __volatile__( \
117 "/* Put user asm, inline. */\n" \
118"1:\t" "st"#size "a %1, [%2] %%asi\n\t" \
119 "clr %0\n" \
120"2:\n\n\t" \
121 ".section .fixup,#alloc,#execinstr\n\t" \
122 ".align 4\n" \
123"3:\n\t" \
124 "sethi %%hi(2b), %0\n\t" \
125 "jmpl %0 + %%lo(2b), %%g0\n\t" \
126 " mov %3, %0\n\n\t" \
127 ".previous\n\t" \
128 ".section __ex_table,\"a\"\n\t" \
129 ".align 4\n\t" \
130 ".word 1b, 3b\n\t" \
131 ".previous\n\n\t" \
132 : "=r" (ret) : "r" (x), "r" (__m(addr)), \
133 "i" (-EFAULT))
134
135extern int __put_user_bad(void);
136
137#define __get_user_nocheck(data,addr,size,type) ({ \
138register int __gu_ret; \
139register unsigned long __gu_val; \
140switch (size) { \
141case 1: __get_user_asm(__gu_val,ub,addr,__gu_ret); break; \
142case 2: __get_user_asm(__gu_val,uh,addr,__gu_ret); break; \
143case 4: __get_user_asm(__gu_val,uw,addr,__gu_ret); break; \
144case 8: __get_user_asm(__gu_val,x,addr,__gu_ret); break; \
145default: __gu_val = 0; __gu_ret = __get_user_bad(); break; \
146} data = (type) __gu_val; __gu_ret; })
147
148#define __get_user_nocheck_ret(data,addr,size,type,retval) ({ \
149register unsigned long __gu_val __asm__ ("l1"); \
150switch (size) { \
151case 1: __get_user_asm_ret(__gu_val,ub,addr,retval); break; \
152case 2: __get_user_asm_ret(__gu_val,uh,addr,retval); break; \
153case 4: __get_user_asm_ret(__gu_val,uw,addr,retval); break; \
154case 8: __get_user_asm_ret(__gu_val,x,addr,retval); break; \
155default: if (__get_user_bad()) return retval; \
156} data = (type) __gu_val; })
157
158#define __get_user_asm(x,size,addr,ret) \
159__asm__ __volatile__( \
160 "/* Get user asm, inline. */\n" \
161"1:\t" "ld"#size "a [%2] %%asi, %1\n\t" \
162 "clr %0\n" \
163"2:\n\n\t" \
164 ".section .fixup,#alloc,#execinstr\n\t" \
165 ".align 4\n" \
166"3:\n\t" \
167 "sethi %%hi(2b), %0\n\t" \
168 "clr %1\n\t" \
169 "jmpl %0 + %%lo(2b), %%g0\n\t" \
170 " mov %3, %0\n\n\t" \
171 ".previous\n\t" \
172 ".section __ex_table,\"a\"\n\t" \
173 ".align 4\n\t" \
174 ".word 1b, 3b\n\n\t" \
175 ".previous\n\t" \
176 : "=r" (ret), "=r" (x) : "r" (__m(addr)), \
177 "i" (-EFAULT))
178
179#define __get_user_asm_ret(x,size,addr,retval) \
180if (__builtin_constant_p(retval) && retval == -EFAULT) \
181__asm__ __volatile__( \
182 "/* Get user asm ret, inline. */\n" \
183"1:\t" "ld"#size "a [%1] %%asi, %0\n\n\t" \
184 ".section __ex_table,\"a\"\n\t" \
185 ".align 4\n\t" \
186 ".word 1b,__ret_efault\n\n\t" \
187 ".previous\n\t" \
188 : "=r" (x) : "r" (__m(addr))); \
189else \
190__asm__ __volatile__( \
191 "/* Get user asm ret, inline. */\n" \
192"1:\t" "ld"#size "a [%1] %%asi, %0\n\n\t" \
193 ".section .fixup,#alloc,#execinstr\n\t" \
194 ".align 4\n" \
195"3:\n\t" \
196 "ret\n\t" \
197 " restore %%g0, %2, %%o0\n\n\t" \
198 ".previous\n\t" \
199 ".section __ex_table,\"a\"\n\t" \
200 ".align 4\n\t" \
201 ".word 1b, 3b\n\n\t" \
202 ".previous\n\t" \
203 : "=r" (x) : "r" (__m(addr)), "i" (retval))
204
205extern int __get_user_bad(void);
206
207extern unsigned long __must_check ___copy_from_user(void *to,
208 const void __user *from,
209 unsigned long size);
210extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
211 unsigned long size);
212static inline unsigned long __must_check
213copy_from_user(void *to, const void __user *from, unsigned long size)
214{
215 unsigned long ret = ___copy_from_user(to, from, size);
216
217 if (unlikely(ret))
218 ret = copy_from_user_fixup(to, from, size);
219 return ret;
220}
221#define __copy_from_user copy_from_user
222
223extern unsigned long __must_check ___copy_to_user(void __user *to,
224 const void *from,
225 unsigned long size);
226extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
227 unsigned long size);
228static inline unsigned long __must_check
229copy_to_user(void __user *to, const void *from, unsigned long size)
230{
231 unsigned long ret = ___copy_to_user(to, from, size);
232
233 if (unlikely(ret))
234 ret = copy_to_user_fixup(to, from, size);
235 return ret;
236}
237#define __copy_to_user copy_to_user
238
239extern unsigned long __must_check ___copy_in_user(void __user *to,
240 const void __user *from,
241 unsigned long size);
242extern unsigned long copy_in_user_fixup(void __user *to, void __user *from,
243 unsigned long size);
244static inline unsigned long __must_check
245copy_in_user(void __user *to, void __user *from, unsigned long size)
246{
247 unsigned long ret = ___copy_in_user(to, from, size);
248
249 if (unlikely(ret))
250 ret = copy_in_user_fixup(to, from, size);
251 return ret;
252}
253#define __copy_in_user copy_in_user
254
255extern unsigned long __must_check __clear_user(void __user *, unsigned long);
256
257#define clear_user __clear_user
258
259extern long __must_check __strncpy_from_user(char *dest, const char __user *src, long count);
260
261#define strncpy_from_user __strncpy_from_user
262
263extern long __strlen_user(const char __user *);
264extern long __strnlen_user(const char __user *, long len);
265
266#define strlen_user __strlen_user
267#define strnlen_user __strnlen_user
268#define __copy_to_user_inatomic __copy_to_user
269#define __copy_from_user_inatomic __copy_from_user
270
271#endif /* __ASSEMBLY__ */
272
273#endif /* _ASM_UACCESS_H */
diff --git a/include/asm-sparc/uctx.h b/include/asm-sparc/uctx.h
new file mode 100644
index 000000000000..dc937c75ffdd
--- /dev/null
+++ b/include/asm-sparc/uctx.h
@@ -0,0 +1,71 @@
1/*
2 * uctx.h: Sparc64 {set,get}context() register state layouts.
3 *
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef __SPARC64_UCTX_H
8#define __SPARC64_UCTX_H
9
10#define MC_TSTATE 0
11#define MC_PC 1
12#define MC_NPC 2
13#define MC_Y 3
14#define MC_G1 4
15#define MC_G2 5
16#define MC_G3 6
17#define MC_G4 7
18#define MC_G5 8
19#define MC_G6 9
20#define MC_G7 10
21#define MC_O0 11
22#define MC_O1 12
23#define MC_O2 13
24#define MC_O3 14
25#define MC_O4 15
26#define MC_O5 16
27#define MC_O6 17
28#define MC_O7 18
29#define MC_NGREG 19
30
31typedef unsigned long mc_greg_t;
32typedef mc_greg_t mc_gregset_t[MC_NGREG];
33
34#define MC_MAXFPQ 16
35struct mc_fq {
36 unsigned long *mcfq_addr;
37 unsigned int mcfq_insn;
38};
39
40struct mc_fpu {
41 union {
42 unsigned int sregs[32];
43 unsigned long dregs[32];
44 long double qregs[16];
45 } mcfpu_fregs;
46 unsigned long mcfpu_fsr;
47 unsigned long mcfpu_fprs;
48 unsigned long mcfpu_gsr;
49 struct mc_fq *mcfpu_fq;
50 unsigned char mcfpu_qcnt;
51 unsigned char mcfpu_qentsz;
52 unsigned char mcfpu_enab;
53};
54typedef struct mc_fpu mc_fpu_t;
55
56typedef struct {
57 mc_gregset_t mc_gregs;
58 mc_greg_t mc_fp;
59 mc_greg_t mc_i7;
60 mc_fpu_t mc_fpregs;
61} mcontext_t;
62
63struct ucontext {
64 struct ucontext *uc_link;
65 unsigned long uc_flags;
66 sigset_t uc_sigmask;
67 mcontext_t uc_mcontext;
68};
69typedef struct ucontext ucontext_t;
70
71#endif /* __SPARC64_UCTX_H */
diff --git a/include/asm-sparc/unistd.h b/include/asm-sparc/unistd.h
index 2338a0276377..3c2609618a09 100644
--- a/include/asm-sparc/unistd.h
+++ b/include/asm-sparc/unistd.h
@@ -1,378 +1,8 @@
1#ifndef _SPARC_UNISTD_H 1#ifndef ___ASM_SPARC_UNISTD_H
2#define _SPARC_UNISTD_H 2#define ___ASM_SPARC_UNISTD_H
3 3#if defined(__sparc__) && defined(__arch64__)
4/* 4#include <asm-sparc/unistd_64.h>
5 * System calls under the Sparc. 5#else
6 * 6#include <asm-sparc/unistd_32.h>
7 * Don't be scared by the ugly clobbers, it is the only way I can 7#endif
8 * think of right now to force the arguments into fixed registers 8#endif
9 * before the trap into the system call with gcc 'asm' statements.
10 *
11 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
12 *
13 * SunOS compatibility based upon preliminary work which is:
14 *
15 * Copyright (C) 1995 Adrian M. Rodriguez (adrian@remus.rutgers.edu)
16 */
17
18#define __NR_restart_syscall 0 /* Linux Specific */
19#define __NR_exit 1 /* Common */
20#define __NR_fork 2 /* Common */
21#define __NR_read 3 /* Common */
22#define __NR_write 4 /* Common */
23#define __NR_open 5 /* Common */
24#define __NR_close 6 /* Common */
25#define __NR_wait4 7 /* Common */
26#define __NR_creat 8 /* Common */
27#define __NR_link 9 /* Common */
28#define __NR_unlink 10 /* Common */
29#define __NR_execv 11 /* SunOS Specific */
30#define __NR_chdir 12 /* Common */
31#define __NR_chown 13 /* Common */
32#define __NR_mknod 14 /* Common */
33#define __NR_chmod 15 /* Common */
34#define __NR_lchown 16 /* Common */
35#define __NR_brk 17 /* Common */
36#define __NR_perfctr 18 /* Performance counter operations */
37#define __NR_lseek 19 /* Common */
38#define __NR_getpid 20 /* Common */
39#define __NR_capget 21 /* Linux Specific */
40#define __NR_capset 22 /* Linux Specific */
41#define __NR_setuid 23 /* Implemented via setreuid in SunOS */
42#define __NR_getuid 24 /* Common */
43#define __NR_vmsplice 25 /* ENOSYS under SunOS */
44#define __NR_ptrace 26 /* Common */
45#define __NR_alarm 27 /* Implemented via setitimer in SunOS */
46#define __NR_sigaltstack 28 /* Common */
47#define __NR_pause 29 /* Is sigblock(0)->sigpause() in SunOS */
48#define __NR_utime 30 /* Implemented via utimes() under SunOS */
49#define __NR_lchown32 31 /* Linux sparc32 specific */
50#define __NR_fchown32 32 /* Linux sparc32 specific */
51#define __NR_access 33 /* Common */
52#define __NR_nice 34 /* Implemented via get/setpriority() in SunOS */
53#define __NR_chown32 35 /* Linux sparc32 specific */
54#define __NR_sync 36 /* Common */
55#define __NR_kill 37 /* Common */
56#define __NR_stat 38 /* Common */
57#define __NR_sendfile 39 /* Linux Specific */
58#define __NR_lstat 40 /* Common */
59#define __NR_dup 41 /* Common */
60#define __NR_pipe 42 /* Common */
61#define __NR_times 43 /* Implemented via getrusage() in SunOS */
62#define __NR_getuid32 44 /* Linux sparc32 specific */
63#define __NR_umount2 45 /* Linux Specific */
64#define __NR_setgid 46 /* Implemented via setregid() in SunOS */
65#define __NR_getgid 47 /* Common */
66#define __NR_signal 48 /* Implemented via sigvec() in SunOS */
67#define __NR_geteuid 49 /* SunOS calls getuid() */
68#define __NR_getegid 50 /* SunOS calls getgid() */
69#define __NR_acct 51 /* Common */
70/* #define __NR_memory_ordering 52 Linux sparc64 specific */
71#define __NR_getgid32 53 /* Linux sparc32 specific */
72#define __NR_ioctl 54 /* Common */
73#define __NR_reboot 55 /* Common */
74#define __NR_mmap2 56 /* Linux sparc32 Specific */
75#define __NR_symlink 57 /* Common */
76#define __NR_readlink 58 /* Common */
77#define __NR_execve 59 /* Common */
78#define __NR_umask 60 /* Common */
79#define __NR_chroot 61 /* Common */
80#define __NR_fstat 62 /* Common */
81#define __NR_fstat64 63 /* Linux Specific */
82#define __NR_getpagesize 64 /* Common */
83#define __NR_msync 65 /* Common in newer 1.3.x revs... */
84#define __NR_vfork 66 /* Common */
85#define __NR_pread64 67 /* Linux Specific */
86#define __NR_pwrite64 68 /* Linux Specific */
87#define __NR_geteuid32 69 /* Linux sparc32, sbrk under SunOS */
88#define __NR_getegid32 70 /* Linux sparc32, sstk under SunOS */
89#define __NR_mmap 71 /* Common */
90#define __NR_setreuid32 72 /* Linux sparc32, vadvise under SunOS */
91#define __NR_munmap 73 /* Common */
92#define __NR_mprotect 74 /* Common */
93#define __NR_madvise 75 /* Common */
94#define __NR_vhangup 76 /* Common */
95#define __NR_truncate64 77 /* Linux sparc32 Specific */
96#define __NR_mincore 78 /* Common */
97#define __NR_getgroups 79 /* Common */
98#define __NR_setgroups 80 /* Common */
99#define __NR_getpgrp 81 /* Common */
100#define __NR_setgroups32 82 /* Linux sparc32, setpgrp under SunOS */
101#define __NR_setitimer 83 /* Common */
102#define __NR_ftruncate64 84 /* Linux sparc32 Specific */
103#define __NR_swapon 85 /* Common */
104#define __NR_getitimer 86 /* Common */
105#define __NR_setuid32 87 /* Linux sparc32, gethostname under SunOS */
106#define __NR_sethostname 88 /* Common */
107#define __NR_setgid32 89 /* Linux sparc32, getdtablesize under SunOS */
108#define __NR_dup2 90 /* Common */
109#define __NR_setfsuid32 91 /* Linux sparc32, getdopt under SunOS */
110#define __NR_fcntl 92 /* Common */
111#define __NR_select 93 /* Common */
112#define __NR_setfsgid32 94 /* Linux sparc32, setdopt under SunOS */
113#define __NR_fsync 95 /* Common */
114#define __NR_setpriority 96 /* Common */
115#define __NR_socket 97 /* Common */
116#define __NR_connect 98 /* Common */
117#define __NR_accept 99 /* Common */
118#define __NR_getpriority 100 /* Common */
119#define __NR_rt_sigreturn 101 /* Linux Specific */
120#define __NR_rt_sigaction 102 /* Linux Specific */
121#define __NR_rt_sigprocmask 103 /* Linux Specific */
122#define __NR_rt_sigpending 104 /* Linux Specific */
123#define __NR_rt_sigtimedwait 105 /* Linux Specific */
124#define __NR_rt_sigqueueinfo 106 /* Linux Specific */
125#define __NR_rt_sigsuspend 107 /* Linux Specific */
126#define __NR_setresuid32 108 /* Linux Specific, sigvec under SunOS */
127#define __NR_getresuid32 109 /* Linux Specific, sigblock under SunOS */
128#define __NR_setresgid32 110 /* Linux Specific, sigsetmask under SunOS */
129#define __NR_getresgid32 111 /* Linux Specific, sigpause under SunOS */
130#define __NR_setregid32 112 /* Linux sparc32, sigstack under SunOS */
131#define __NR_recvmsg 113 /* Common */
132#define __NR_sendmsg 114 /* Common */
133#define __NR_getgroups32 115 /* Linux sparc32, vtrace under SunOS */
134#define __NR_gettimeofday 116 /* Common */
135#define __NR_getrusage 117 /* Common */
136#define __NR_getsockopt 118 /* Common */
137#define __NR_getcwd 119 /* Linux Specific */
138#define __NR_readv 120 /* Common */
139#define __NR_writev 121 /* Common */
140#define __NR_settimeofday 122 /* Common */
141#define __NR_fchown 123 /* Common */
142#define __NR_fchmod 124 /* Common */
143#define __NR_recvfrom 125 /* Common */
144#define __NR_setreuid 126 /* Common */
145#define __NR_setregid 127 /* Common */
146#define __NR_rename 128 /* Common */
147#define __NR_truncate 129 /* Common */
148#define __NR_ftruncate 130 /* Common */
149#define __NR_flock 131 /* Common */
150#define __NR_lstat64 132 /* Linux Specific */
151#define __NR_sendto 133 /* Common */
152#define __NR_shutdown 134 /* Common */
153#define __NR_socketpair 135 /* Common */
154#define __NR_mkdir 136 /* Common */
155#define __NR_rmdir 137 /* Common */
156#define __NR_utimes 138 /* SunOS Specific */
157#define __NR_stat64 139 /* Linux Specific */
158#define __NR_sendfile64 140 /* adjtime under SunOS */
159#define __NR_getpeername 141 /* Common */
160#define __NR_futex 142 /* gethostid under SunOS */
161#define __NR_gettid 143 /* ENOSYS under SunOS */
162#define __NR_getrlimit 144 /* Common */
163#define __NR_setrlimit 145 /* Common */
164#define __NR_pivot_root 146 /* Linux Specific, killpg under SunOS */
165#define __NR_prctl 147 /* ENOSYS under SunOS */
166#define __NR_pciconfig_read 148 /* ENOSYS under SunOS */
167#define __NR_pciconfig_write 149 /* ENOSYS under SunOS */
168#define __NR_getsockname 150 /* Common */
169#define __NR_inotify_init 151 /* Linux specific */
170#define __NR_inotify_add_watch 152 /* Linux specific */
171#define __NR_poll 153 /* Common */
172#define __NR_getdents64 154 /* Linux specific */
173#define __NR_fcntl64 155 /* Linux sparc32 Specific */
174#define __NR_inotify_rm_watch 156 /* Linux specific */
175#define __NR_statfs 157 /* Common */
176#define __NR_fstatfs 158 /* Common */
177#define __NR_umount 159 /* Common */
178#define __NR_sched_set_affinity 160 /* Linux specific, async_daemon under SunOS */
179#define __NR_sched_get_affinity 161 /* Linux specific, getfh under SunOS */
180#define __NR_getdomainname 162 /* SunOS Specific */
181#define __NR_setdomainname 163 /* Common */
182/* #define __NR_utrap_install 164 Linux sparc64 specific */
183#define __NR_quotactl 165 /* Common */
184#define __NR_set_tid_address 166 /* Linux specific, exportfs under SunOS */
185#define __NR_mount 167 /* Common */
186#define __NR_ustat 168 /* Common */
187#define __NR_setxattr 169 /* SunOS: semsys */
188#define __NR_lsetxattr 170 /* SunOS: msgsys */
189#define __NR_fsetxattr 171 /* SunOS: shmsys */
190#define __NR_getxattr 172 /* SunOS: auditsys */
191#define __NR_lgetxattr 173 /* SunOS: rfssys */
192#define __NR_getdents 174 /* Common */
193#define __NR_setsid 175 /* Common */
194#define __NR_fchdir 176 /* Common */
195#define __NR_fgetxattr 177 /* SunOS: fchroot */
196#define __NR_listxattr 178 /* SunOS: vpixsys */
197#define __NR_llistxattr 179 /* SunOS: aioread */
198#define __NR_flistxattr 180 /* SunOS: aiowrite */
199#define __NR_removexattr 181 /* SunOS: aiowait */
200#define __NR_lremovexattr 182 /* SunOS: aiocancel */
201#define __NR_sigpending 183 /* Common */
202#define __NR_query_module 184 /* Linux Specific */
203#define __NR_setpgid 185 /* Common */
204#define __NR_fremovexattr 186 /* SunOS: pathconf */
205#define __NR_tkill 187 /* SunOS: fpathconf */
206#define __NR_exit_group 188 /* Linux specific, sysconf undef SunOS */
207#define __NR_uname 189 /* Linux Specific */
208#define __NR_init_module 190 /* Linux Specific */
209#define __NR_personality 191 /* Linux Specific */
210#define __NR_remap_file_pages 192 /* Linux Specific */
211#define __NR_epoll_create 193 /* Linux Specific */
212#define __NR_epoll_ctl 194 /* Linux Specific */
213#define __NR_epoll_wait 195 /* Linux Specific */
214#define __NR_ioprio_set 196 /* Linux Specific */
215#define __NR_getppid 197 /* Linux Specific */
216#define __NR_sigaction 198 /* Linux Specific */
217#define __NR_sgetmask 199 /* Linux Specific */
218#define __NR_ssetmask 200 /* Linux Specific */
219#define __NR_sigsuspend 201 /* Linux Specific */
220#define __NR_oldlstat 202 /* Linux Specific */
221#define __NR_uselib 203 /* Linux Specific */
222#define __NR_readdir 204 /* Linux Specific */
223#define __NR_readahead 205 /* Linux Specific */
224#define __NR_socketcall 206 /* Linux Specific */
225#define __NR_syslog 207 /* Linux Specific */
226#define __NR_lookup_dcookie 208 /* Linux Specific */
227#define __NR_fadvise64 209 /* Linux Specific */
228#define __NR_fadvise64_64 210 /* Linux Specific */
229#define __NR_tgkill 211 /* Linux Specific */
230#define __NR_waitpid 212 /* Linux Specific */
231#define __NR_swapoff 213 /* Linux Specific */
232#define __NR_sysinfo 214 /* Linux Specific */
233#define __NR_ipc 215 /* Linux Specific */
234#define __NR_sigreturn 216 /* Linux Specific */
235#define __NR_clone 217 /* Linux Specific */
236#define __NR_ioprio_get 218 /* Linux Specific */
237#define __NR_adjtimex 219 /* Linux Specific */
238#define __NR_sigprocmask 220 /* Linux Specific */
239#define __NR_create_module 221 /* Linux Specific */
240#define __NR_delete_module 222 /* Linux Specific */
241#define __NR_get_kernel_syms 223 /* Linux Specific */
242#define __NR_getpgid 224 /* Linux Specific */
243#define __NR_bdflush 225 /* Linux Specific */
244#define __NR_sysfs 226 /* Linux Specific */
245#define __NR_afs_syscall 227 /* Linux Specific */
246#define __NR_setfsuid 228 /* Linux Specific */
247#define __NR_setfsgid 229 /* Linux Specific */
248#define __NR__newselect 230 /* Linux Specific */
249#define __NR_time 231 /* Linux Specific */
250#define __NR_splice 232 /* Linux Specific */
251#define __NR_stime 233 /* Linux Specific */
252#define __NR_statfs64 234 /* Linux Specific */
253#define __NR_fstatfs64 235 /* Linux Specific */
254#define __NR__llseek 236 /* Linux Specific */
255#define __NR_mlock 237
256#define __NR_munlock 238
257#define __NR_mlockall 239
258#define __NR_munlockall 240
259#define __NR_sched_setparam 241
260#define __NR_sched_getparam 242
261#define __NR_sched_setscheduler 243
262#define __NR_sched_getscheduler 244
263#define __NR_sched_yield 245
264#define __NR_sched_get_priority_max 246
265#define __NR_sched_get_priority_min 247
266#define __NR_sched_rr_get_interval 248
267#define __NR_nanosleep 249
268#define __NR_mremap 250
269#define __NR__sysctl 251
270#define __NR_getsid 252
271#define __NR_fdatasync 253
272#define __NR_nfsservctl 254
273#define __NR_sync_file_range 255
274#define __NR_clock_settime 256
275#define __NR_clock_gettime 257
276#define __NR_clock_getres 258
277#define __NR_clock_nanosleep 259
278#define __NR_sched_getaffinity 260
279#define __NR_sched_setaffinity 261
280#define __NR_timer_settime 262
281#define __NR_timer_gettime 263
282#define __NR_timer_getoverrun 264
283#define __NR_timer_delete 265
284#define __NR_timer_create 266
285/* #define __NR_vserver 267 Reserved for VSERVER */
286#define __NR_io_setup 268
287#define __NR_io_destroy 269
288#define __NR_io_submit 270
289#define __NR_io_cancel 271
290#define __NR_io_getevents 272
291#define __NR_mq_open 273
292#define __NR_mq_unlink 274
293#define __NR_mq_timedsend 275
294#define __NR_mq_timedreceive 276
295#define __NR_mq_notify 277
296#define __NR_mq_getsetattr 278
297#define __NR_waitid 279
298#define __NR_tee 280
299#define __NR_add_key 281
300#define __NR_request_key 282
301#define __NR_keyctl 283
302#define __NR_openat 284
303#define __NR_mkdirat 285
304#define __NR_mknodat 286
305#define __NR_fchownat 287
306#define __NR_futimesat 288
307#define __NR_fstatat64 289
308#define __NR_unlinkat 290
309#define __NR_renameat 291
310#define __NR_linkat 292
311#define __NR_symlinkat 293
312#define __NR_readlinkat 294
313#define __NR_fchmodat 295
314#define __NR_faccessat 296
315#define __NR_pselect6 297
316#define __NR_ppoll 298
317#define __NR_unshare 299
318#define __NR_set_robust_list 300
319#define __NR_get_robust_list 301
320#define __NR_migrate_pages 302
321#define __NR_mbind 303
322#define __NR_get_mempolicy 304
323#define __NR_set_mempolicy 305
324#define __NR_kexec_load 306
325#define __NR_move_pages 307
326#define __NR_getcpu 308
327#define __NR_epoll_pwait 309
328#define __NR_utimensat 310
329#define __NR_signalfd 311
330#define __NR_timerfd_create 312
331#define __NR_eventfd 313
332#define __NR_fallocate 314
333#define __NR_timerfd_settime 315
334#define __NR_timerfd_gettime 316
335
336#define NR_SYSCALLS 317
337
338/* Sparc 32-bit only has the "setresuid32", "getresuid32" variants,
339 * it never had the plain ones and there is no value to adding those
340 * old versions into the syscall table.
341 */
342#define __IGNORE_setresuid
343#define __IGNORE_getresuid
344#define __IGNORE_setresgid
345#define __IGNORE_getresgid
346
347#ifdef __KERNEL__
348#define __ARCH_WANT_IPC_PARSE_VERSION
349#define __ARCH_WANT_OLD_READDIR
350#define __ARCH_WANT_STAT64
351#define __ARCH_WANT_SYS_ALARM
352#define __ARCH_WANT_SYS_GETHOSTNAME
353#define __ARCH_WANT_SYS_PAUSE
354#define __ARCH_WANT_SYS_SGETMASK
355#define __ARCH_WANT_SYS_SIGNAL
356#define __ARCH_WANT_SYS_TIME
357#define __ARCH_WANT_SYS_UTIME
358#define __ARCH_WANT_SYS_WAITPID
359#define __ARCH_WANT_SYS_SOCKETCALL
360#define __ARCH_WANT_SYS_FADVISE64
361#define __ARCH_WANT_SYS_GETPGRP
362#define __ARCH_WANT_SYS_LLSEEK
363#define __ARCH_WANT_SYS_NICE
364#define __ARCH_WANT_SYS_OLDUMOUNT
365#define __ARCH_WANT_SYS_SIGPENDING
366#define __ARCH_WANT_SYS_SIGPROCMASK
367#define __ARCH_WANT_SYS_RT_SIGSUSPEND
368
369/*
370 * "Conditional" syscalls
371 *
372 * What we want is __attribute__((weak,alias("sys_ni_syscall"))),
373 * but it doesn't work on all toolchains, so we just do it by hand
374 */
375#define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall")
376
377#endif /* __KERNEL__ */
378#endif /* _SPARC_UNISTD_H */
diff --git a/include/asm-sparc/unistd_32.h b/include/asm-sparc/unistd_32.h
new file mode 100644
index 000000000000..2338a0276377
--- /dev/null
+++ b/include/asm-sparc/unistd_32.h
@@ -0,0 +1,378 @@
1#ifndef _SPARC_UNISTD_H
2#define _SPARC_UNISTD_H
3
4/*
5 * System calls under the Sparc.
6 *
7 * Don't be scared by the ugly clobbers, it is the only way I can
8 * think of right now to force the arguments into fixed registers
9 * before the trap into the system call with gcc 'asm' statements.
10 *
11 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
12 *
13 * SunOS compatibility based upon preliminary work which is:
14 *
15 * Copyright (C) 1995 Adrian M. Rodriguez (adrian@remus.rutgers.edu)
16 */
17
18#define __NR_restart_syscall 0 /* Linux Specific */
19#define __NR_exit 1 /* Common */
20#define __NR_fork 2 /* Common */
21#define __NR_read 3 /* Common */
22#define __NR_write 4 /* Common */
23#define __NR_open 5 /* Common */
24#define __NR_close 6 /* Common */
25#define __NR_wait4 7 /* Common */
26#define __NR_creat 8 /* Common */
27#define __NR_link 9 /* Common */
28#define __NR_unlink 10 /* Common */
29#define __NR_execv 11 /* SunOS Specific */
30#define __NR_chdir 12 /* Common */
31#define __NR_chown 13 /* Common */
32#define __NR_mknod 14 /* Common */
33#define __NR_chmod 15 /* Common */
34#define __NR_lchown 16 /* Common */
35#define __NR_brk 17 /* Common */
36#define __NR_perfctr 18 /* Performance counter operations */
37#define __NR_lseek 19 /* Common */
38#define __NR_getpid 20 /* Common */
39#define __NR_capget 21 /* Linux Specific */
40#define __NR_capset 22 /* Linux Specific */
41#define __NR_setuid 23 /* Implemented via setreuid in SunOS */
42#define __NR_getuid 24 /* Common */
43#define __NR_vmsplice 25 /* ENOSYS under SunOS */
44#define __NR_ptrace 26 /* Common */
45#define __NR_alarm 27 /* Implemented via setitimer in SunOS */
46#define __NR_sigaltstack 28 /* Common */
47#define __NR_pause 29 /* Is sigblock(0)->sigpause() in SunOS */
48#define __NR_utime 30 /* Implemented via utimes() under SunOS */
49#define __NR_lchown32 31 /* Linux sparc32 specific */
50#define __NR_fchown32 32 /* Linux sparc32 specific */
51#define __NR_access 33 /* Common */
52#define __NR_nice 34 /* Implemented via get/setpriority() in SunOS */
53#define __NR_chown32 35 /* Linux sparc32 specific */
54#define __NR_sync 36 /* Common */
55#define __NR_kill 37 /* Common */
56#define __NR_stat 38 /* Common */
57#define __NR_sendfile 39 /* Linux Specific */
58#define __NR_lstat 40 /* Common */
59#define __NR_dup 41 /* Common */
60#define __NR_pipe 42 /* Common */
61#define __NR_times 43 /* Implemented via getrusage() in SunOS */
62#define __NR_getuid32 44 /* Linux sparc32 specific */
63#define __NR_umount2 45 /* Linux Specific */
64#define __NR_setgid 46 /* Implemented via setregid() in SunOS */
65#define __NR_getgid 47 /* Common */
66#define __NR_signal 48 /* Implemented via sigvec() in SunOS */
67#define __NR_geteuid 49 /* SunOS calls getuid() */
68#define __NR_getegid 50 /* SunOS calls getgid() */
69#define __NR_acct 51 /* Common */
70/* #define __NR_memory_ordering 52 Linux sparc64 specific */
71#define __NR_getgid32 53 /* Linux sparc32 specific */
72#define __NR_ioctl 54 /* Common */
73#define __NR_reboot 55 /* Common */
74#define __NR_mmap2 56 /* Linux sparc32 Specific */
75#define __NR_symlink 57 /* Common */
76#define __NR_readlink 58 /* Common */
77#define __NR_execve 59 /* Common */
78#define __NR_umask 60 /* Common */
79#define __NR_chroot 61 /* Common */
80#define __NR_fstat 62 /* Common */
81#define __NR_fstat64 63 /* Linux Specific */
82#define __NR_getpagesize 64 /* Common */
83#define __NR_msync 65 /* Common in newer 1.3.x revs... */
84#define __NR_vfork 66 /* Common */
85#define __NR_pread64 67 /* Linux Specific */
86#define __NR_pwrite64 68 /* Linux Specific */
87#define __NR_geteuid32 69 /* Linux sparc32, sbrk under SunOS */
88#define __NR_getegid32 70 /* Linux sparc32, sstk under SunOS */
89#define __NR_mmap 71 /* Common */
90#define __NR_setreuid32 72 /* Linux sparc32, vadvise under SunOS */
91#define __NR_munmap 73 /* Common */
92#define __NR_mprotect 74 /* Common */
93#define __NR_madvise 75 /* Common */
94#define __NR_vhangup 76 /* Common */
95#define __NR_truncate64 77 /* Linux sparc32 Specific */
96#define __NR_mincore 78 /* Common */
97#define __NR_getgroups 79 /* Common */
98#define __NR_setgroups 80 /* Common */
99#define __NR_getpgrp 81 /* Common */
100#define __NR_setgroups32 82 /* Linux sparc32, setpgrp under SunOS */
101#define __NR_setitimer 83 /* Common */
102#define __NR_ftruncate64 84 /* Linux sparc32 Specific */
103#define __NR_swapon 85 /* Common */
104#define __NR_getitimer 86 /* Common */
105#define __NR_setuid32 87 /* Linux sparc32, gethostname under SunOS */
106#define __NR_sethostname 88 /* Common */
107#define __NR_setgid32 89 /* Linux sparc32, getdtablesize under SunOS */
108#define __NR_dup2 90 /* Common */
109#define __NR_setfsuid32 91 /* Linux sparc32, getdopt under SunOS */
110#define __NR_fcntl 92 /* Common */
111#define __NR_select 93 /* Common */
112#define __NR_setfsgid32 94 /* Linux sparc32, setdopt under SunOS */
113#define __NR_fsync 95 /* Common */
114#define __NR_setpriority 96 /* Common */
115#define __NR_socket 97 /* Common */
116#define __NR_connect 98 /* Common */
117#define __NR_accept 99 /* Common */
118#define __NR_getpriority 100 /* Common */
119#define __NR_rt_sigreturn 101 /* Linux Specific */
120#define __NR_rt_sigaction 102 /* Linux Specific */
121#define __NR_rt_sigprocmask 103 /* Linux Specific */
122#define __NR_rt_sigpending 104 /* Linux Specific */
123#define __NR_rt_sigtimedwait 105 /* Linux Specific */
124#define __NR_rt_sigqueueinfo 106 /* Linux Specific */
125#define __NR_rt_sigsuspend 107 /* Linux Specific */
126#define __NR_setresuid32 108 /* Linux Specific, sigvec under SunOS */
127#define __NR_getresuid32 109 /* Linux Specific, sigblock under SunOS */
128#define __NR_setresgid32 110 /* Linux Specific, sigsetmask under SunOS */
129#define __NR_getresgid32 111 /* Linux Specific, sigpause under SunOS */
130#define __NR_setregid32 112 /* Linux sparc32, sigstack under SunOS */
131#define __NR_recvmsg 113 /* Common */
132#define __NR_sendmsg 114 /* Common */
133#define __NR_getgroups32 115 /* Linux sparc32, vtrace under SunOS */
134#define __NR_gettimeofday 116 /* Common */
135#define __NR_getrusage 117 /* Common */
136#define __NR_getsockopt 118 /* Common */
137#define __NR_getcwd 119 /* Linux Specific */
138#define __NR_readv 120 /* Common */
139#define __NR_writev 121 /* Common */
140#define __NR_settimeofday 122 /* Common */
141#define __NR_fchown 123 /* Common */
142#define __NR_fchmod 124 /* Common */
143#define __NR_recvfrom 125 /* Common */
144#define __NR_setreuid 126 /* Common */
145#define __NR_setregid 127 /* Common */
146#define __NR_rename 128 /* Common */
147#define __NR_truncate 129 /* Common */
148#define __NR_ftruncate 130 /* Common */
149#define __NR_flock 131 /* Common */
150#define __NR_lstat64 132 /* Linux Specific */
151#define __NR_sendto 133 /* Common */
152#define __NR_shutdown 134 /* Common */
153#define __NR_socketpair 135 /* Common */
154#define __NR_mkdir 136 /* Common */
155#define __NR_rmdir 137 /* Common */
156#define __NR_utimes 138 /* SunOS Specific */
157#define __NR_stat64 139 /* Linux Specific */
158#define __NR_sendfile64 140 /* adjtime under SunOS */
159#define __NR_getpeername 141 /* Common */
160#define __NR_futex 142 /* gethostid under SunOS */
161#define __NR_gettid 143 /* ENOSYS under SunOS */
162#define __NR_getrlimit 144 /* Common */
163#define __NR_setrlimit 145 /* Common */
164#define __NR_pivot_root 146 /* Linux Specific, killpg under SunOS */
165#define __NR_prctl 147 /* ENOSYS under SunOS */
166#define __NR_pciconfig_read 148 /* ENOSYS under SunOS */
167#define __NR_pciconfig_write 149 /* ENOSYS under SunOS */
168#define __NR_getsockname 150 /* Common */
169#define __NR_inotify_init 151 /* Linux specific */
170#define __NR_inotify_add_watch 152 /* Linux specific */
171#define __NR_poll 153 /* Common */
172#define __NR_getdents64 154 /* Linux specific */
173#define __NR_fcntl64 155 /* Linux sparc32 Specific */
174#define __NR_inotify_rm_watch 156 /* Linux specific */
175#define __NR_statfs 157 /* Common */
176#define __NR_fstatfs 158 /* Common */
177#define __NR_umount 159 /* Common */
178#define __NR_sched_set_affinity 160 /* Linux specific, async_daemon under SunOS */
179#define __NR_sched_get_affinity 161 /* Linux specific, getfh under SunOS */
180#define __NR_getdomainname 162 /* SunOS Specific */
181#define __NR_setdomainname 163 /* Common */
182/* #define __NR_utrap_install 164 Linux sparc64 specific */
183#define __NR_quotactl 165 /* Common */
184#define __NR_set_tid_address 166 /* Linux specific, exportfs under SunOS */
185#define __NR_mount 167 /* Common */
186#define __NR_ustat 168 /* Common */
187#define __NR_setxattr 169 /* SunOS: semsys */
188#define __NR_lsetxattr 170 /* SunOS: msgsys */
189#define __NR_fsetxattr 171 /* SunOS: shmsys */
190#define __NR_getxattr 172 /* SunOS: auditsys */
191#define __NR_lgetxattr 173 /* SunOS: rfssys */
192#define __NR_getdents 174 /* Common */
193#define __NR_setsid 175 /* Common */
194#define __NR_fchdir 176 /* Common */
195#define __NR_fgetxattr 177 /* SunOS: fchroot */
196#define __NR_listxattr 178 /* SunOS: vpixsys */
197#define __NR_llistxattr 179 /* SunOS: aioread */
198#define __NR_flistxattr 180 /* SunOS: aiowrite */
199#define __NR_removexattr 181 /* SunOS: aiowait */
200#define __NR_lremovexattr 182 /* SunOS: aiocancel */
201#define __NR_sigpending 183 /* Common */
202#define __NR_query_module 184 /* Linux Specific */
203#define __NR_setpgid 185 /* Common */
204#define __NR_fremovexattr 186 /* SunOS: pathconf */
205#define __NR_tkill 187 /* SunOS: fpathconf */
206#define __NR_exit_group 188 /* Linux specific, sysconf undef SunOS */
207#define __NR_uname 189 /* Linux Specific */
208#define __NR_init_module 190 /* Linux Specific */
209#define __NR_personality 191 /* Linux Specific */
210#define __NR_remap_file_pages 192 /* Linux Specific */
211#define __NR_epoll_create 193 /* Linux Specific */
212#define __NR_epoll_ctl 194 /* Linux Specific */
213#define __NR_epoll_wait 195 /* Linux Specific */
214#define __NR_ioprio_set 196 /* Linux Specific */
215#define __NR_getppid 197 /* Linux Specific */
216#define __NR_sigaction 198 /* Linux Specific */
217#define __NR_sgetmask 199 /* Linux Specific */
218#define __NR_ssetmask 200 /* Linux Specific */
219#define __NR_sigsuspend 201 /* Linux Specific */
220#define __NR_oldlstat 202 /* Linux Specific */
221#define __NR_uselib 203 /* Linux Specific */
222#define __NR_readdir 204 /* Linux Specific */
223#define __NR_readahead 205 /* Linux Specific */
224#define __NR_socketcall 206 /* Linux Specific */
225#define __NR_syslog 207 /* Linux Specific */
226#define __NR_lookup_dcookie 208 /* Linux Specific */
227#define __NR_fadvise64 209 /* Linux Specific */
228#define __NR_fadvise64_64 210 /* Linux Specific */
229#define __NR_tgkill 211 /* Linux Specific */
230#define __NR_waitpid 212 /* Linux Specific */
231#define __NR_swapoff 213 /* Linux Specific */
232#define __NR_sysinfo 214 /* Linux Specific */
233#define __NR_ipc 215 /* Linux Specific */
234#define __NR_sigreturn 216 /* Linux Specific */
235#define __NR_clone 217 /* Linux Specific */
236#define __NR_ioprio_get 218 /* Linux Specific */
237#define __NR_adjtimex 219 /* Linux Specific */
238#define __NR_sigprocmask 220 /* Linux Specific */
239#define __NR_create_module 221 /* Linux Specific */
240#define __NR_delete_module 222 /* Linux Specific */
241#define __NR_get_kernel_syms 223 /* Linux Specific */
242#define __NR_getpgid 224 /* Linux Specific */
243#define __NR_bdflush 225 /* Linux Specific */
244#define __NR_sysfs 226 /* Linux Specific */
245#define __NR_afs_syscall 227 /* Linux Specific */
246#define __NR_setfsuid 228 /* Linux Specific */
247#define __NR_setfsgid 229 /* Linux Specific */
248#define __NR__newselect 230 /* Linux Specific */
249#define __NR_time 231 /* Linux Specific */
250#define __NR_splice 232 /* Linux Specific */
251#define __NR_stime 233 /* Linux Specific */
252#define __NR_statfs64 234 /* Linux Specific */
253#define __NR_fstatfs64 235 /* Linux Specific */
254#define __NR__llseek 236 /* Linux Specific */
255#define __NR_mlock 237
256#define __NR_munlock 238
257#define __NR_mlockall 239
258#define __NR_munlockall 240
259#define __NR_sched_setparam 241
260#define __NR_sched_getparam 242
261#define __NR_sched_setscheduler 243
262#define __NR_sched_getscheduler 244
263#define __NR_sched_yield 245
264#define __NR_sched_get_priority_max 246
265#define __NR_sched_get_priority_min 247
266#define __NR_sched_rr_get_interval 248
267#define __NR_nanosleep 249
268#define __NR_mremap 250
269#define __NR__sysctl 251
270#define __NR_getsid 252
271#define __NR_fdatasync 253
272#define __NR_nfsservctl 254
273#define __NR_sync_file_range 255
274#define __NR_clock_settime 256
275#define __NR_clock_gettime 257
276#define __NR_clock_getres 258
277#define __NR_clock_nanosleep 259
278#define __NR_sched_getaffinity 260
279#define __NR_sched_setaffinity 261
280#define __NR_timer_settime 262
281#define __NR_timer_gettime 263
282#define __NR_timer_getoverrun 264
283#define __NR_timer_delete 265
284#define __NR_timer_create 266
285/* #define __NR_vserver 267 Reserved for VSERVER */
286#define __NR_io_setup 268
287#define __NR_io_destroy 269
288#define __NR_io_submit 270
289#define __NR_io_cancel 271
290#define __NR_io_getevents 272
291#define __NR_mq_open 273
292#define __NR_mq_unlink 274
293#define __NR_mq_timedsend 275
294#define __NR_mq_timedreceive 276
295#define __NR_mq_notify 277
296#define __NR_mq_getsetattr 278
297#define __NR_waitid 279
298#define __NR_tee 280
299#define __NR_add_key 281
300#define __NR_request_key 282
301#define __NR_keyctl 283
302#define __NR_openat 284
303#define __NR_mkdirat 285
304#define __NR_mknodat 286
305#define __NR_fchownat 287
306#define __NR_futimesat 288
307#define __NR_fstatat64 289
308#define __NR_unlinkat 290
309#define __NR_renameat 291
310#define __NR_linkat 292
311#define __NR_symlinkat 293
312#define __NR_readlinkat 294
313#define __NR_fchmodat 295
314#define __NR_faccessat 296
315#define __NR_pselect6 297
316#define __NR_ppoll 298
317#define __NR_unshare 299
318#define __NR_set_robust_list 300
319#define __NR_get_robust_list 301
320#define __NR_migrate_pages 302
321#define __NR_mbind 303
322#define __NR_get_mempolicy 304
323#define __NR_set_mempolicy 305
324#define __NR_kexec_load 306
325#define __NR_move_pages 307
326#define __NR_getcpu 308
327#define __NR_epoll_pwait 309
328#define __NR_utimensat 310
329#define __NR_signalfd 311
330#define __NR_timerfd_create 312
331#define __NR_eventfd 313
332#define __NR_fallocate 314
333#define __NR_timerfd_settime 315
334#define __NR_timerfd_gettime 316
335
336#define NR_SYSCALLS 317
337
338/* Sparc 32-bit only has the "setresuid32", "getresuid32" variants,
339 * it never had the plain ones and there is no value to adding those
340 * old versions into the syscall table.
341 */
342#define __IGNORE_setresuid
343#define __IGNORE_getresuid
344#define __IGNORE_setresgid
345#define __IGNORE_getresgid
346
347#ifdef __KERNEL__
348#define __ARCH_WANT_IPC_PARSE_VERSION
349#define __ARCH_WANT_OLD_READDIR
350#define __ARCH_WANT_STAT64
351#define __ARCH_WANT_SYS_ALARM
352#define __ARCH_WANT_SYS_GETHOSTNAME
353#define __ARCH_WANT_SYS_PAUSE
354#define __ARCH_WANT_SYS_SGETMASK
355#define __ARCH_WANT_SYS_SIGNAL
356#define __ARCH_WANT_SYS_TIME
357#define __ARCH_WANT_SYS_UTIME
358#define __ARCH_WANT_SYS_WAITPID
359#define __ARCH_WANT_SYS_SOCKETCALL
360#define __ARCH_WANT_SYS_FADVISE64
361#define __ARCH_WANT_SYS_GETPGRP
362#define __ARCH_WANT_SYS_LLSEEK
363#define __ARCH_WANT_SYS_NICE
364#define __ARCH_WANT_SYS_OLDUMOUNT
365#define __ARCH_WANT_SYS_SIGPENDING
366#define __ARCH_WANT_SYS_SIGPROCMASK
367#define __ARCH_WANT_SYS_RT_SIGSUSPEND
368
369/*
370 * "Conditional" syscalls
371 *
372 * What we want is __attribute__((weak,alias("sys_ni_syscall"))),
373 * but it doesn't work on all toolchains, so we just do it by hand
374 */
375#define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall")
376
377#endif /* __KERNEL__ */
378#endif /* _SPARC_UNISTD_H */
diff --git a/include/asm-sparc/unistd_64.h b/include/asm-sparc/unistd_64.h
new file mode 100644
index 000000000000..13be4453a1f0
--- /dev/null
+++ b/include/asm-sparc/unistd_64.h
@@ -0,0 +1,373 @@
1#ifndef _SPARC64_UNISTD_H
2#define _SPARC64_UNISTD_H
3
4/*
5 * System calls under the Sparc.
6 *
7 * Don't be scared by the ugly clobbers, it is the only way I can
8 * think of right now to force the arguments into fixed registers
9 * before the trap into the system call with gcc 'asm' statements.
10 *
11 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
12 *
13 * SunOS compatibility based upon preliminary work which is:
14 *
15 * Copyright (C) 1995 Adrian M. Rodriguez (adrian@remus.rutgers.edu)
16 */
17
18#define __NR_restart_syscall 0 /* Linux Specific */
19#define __NR_exit 1 /* Common */
20#define __NR_fork 2 /* Common */
21#define __NR_read 3 /* Common */
22#define __NR_write 4 /* Common */
23#define __NR_open 5 /* Common */
24#define __NR_close 6 /* Common */
25#define __NR_wait4 7 /* Common */
26#define __NR_creat 8 /* Common */
27#define __NR_link 9 /* Common */
28#define __NR_unlink 10 /* Common */
29#define __NR_execv 11 /* SunOS Specific */
30#define __NR_chdir 12 /* Common */
31#define __NR_chown 13 /* Common */
32#define __NR_mknod 14 /* Common */
33#define __NR_chmod 15 /* Common */
34#define __NR_lchown 16 /* Common */
35#define __NR_brk 17 /* Common */
36#define __NR_perfctr 18 /* Performance counter operations */
37#define __NR_lseek 19 /* Common */
38#define __NR_getpid 20 /* Common */
39#define __NR_capget 21 /* Linux Specific */
40#define __NR_capset 22 /* Linux Specific */
41#define __NR_setuid 23 /* Implemented via setreuid in SunOS */
42#define __NR_getuid 24 /* Common */
43#define __NR_vmsplice 25 /* ENOSYS under SunOS */
44#define __NR_ptrace 26 /* Common */
45#define __NR_alarm 27 /* Implemented via setitimer in SunOS */
46#define __NR_sigaltstack 28 /* Common */
47#define __NR_pause 29 /* Is sigblock(0)->sigpause() in SunOS */
48#define __NR_utime 30 /* Implemented via utimes() under SunOS */
49/* #define __NR_lchown32 31 Linux sparc32 specific */
50/* #define __NR_fchown32 32 Linux sparc32 specific */
51#define __NR_access 33 /* Common */
52#define __NR_nice 34 /* Implemented via get/setpriority() in SunOS */
53/* #define __NR_chown32 35 Linux sparc32 specific */
54#define __NR_sync 36 /* Common */
55#define __NR_kill 37 /* Common */
56#define __NR_stat 38 /* Common */
57#define __NR_sendfile 39 /* Linux Specific */
58#define __NR_lstat 40 /* Common */
59#define __NR_dup 41 /* Common */
60#define __NR_pipe 42 /* Common */
61#define __NR_times 43 /* Implemented via getrusage() in SunOS */
62/* #define __NR_getuid32 44 Linux sparc32 specific */
63#define __NR_umount2 45 /* Linux Specific */
64#define __NR_setgid 46 /* Implemented via setregid() in SunOS */
65#define __NR_getgid 47 /* Common */
66#define __NR_signal 48 /* Implemented via sigvec() in SunOS */
67#define __NR_geteuid 49 /* SunOS calls getuid() */
68#define __NR_getegid 50 /* SunOS calls getgid() */
69#define __NR_acct 51 /* Common */
70#define __NR_memory_ordering 52 /* Linux Specific */
71/* #define __NR_getgid32 53 Linux sparc32 specific */
72#define __NR_ioctl 54 /* Common */
73#define __NR_reboot 55 /* Common */
74/* #define __NR_mmap2 56 Linux sparc32 Specific */
75#define __NR_symlink 57 /* Common */
76#define __NR_readlink 58 /* Common */
77#define __NR_execve 59 /* Common */
78#define __NR_umask 60 /* Common */
79#define __NR_chroot 61 /* Common */
80#define __NR_fstat 62 /* Common */
81#define __NR_fstat64 63 /* Linux Specific */
82#define __NR_getpagesize 64 /* Common */
83#define __NR_msync 65 /* Common in newer 1.3.x revs... */
84#define __NR_vfork 66 /* Common */
85#define __NR_pread64 67 /* Linux Specific */
86#define __NR_pwrite64 68 /* Linux Specific */
87/* #define __NR_geteuid32 69 Linux sparc32, sbrk under SunOS */
88/* #define __NR_getegid32 70 Linux sparc32, sstk under SunOS */
89#define __NR_mmap 71 /* Common */
90/* #define __NR_setreuid32 72 Linux sparc32, vadvise under SunOS */
91#define __NR_munmap 73 /* Common */
92#define __NR_mprotect 74 /* Common */
93#define __NR_madvise 75 /* Common */
94#define __NR_vhangup 76 /* Common */
95/* #define __NR_truncate64 77 Linux sparc32 Specific */
96#define __NR_mincore 78 /* Common */
97#define __NR_getgroups 79 /* Common */
98#define __NR_setgroups 80 /* Common */
99#define __NR_getpgrp 81 /* Common */
100/* #define __NR_setgroups32 82 Linux sparc32, setpgrp under SunOS */
101#define __NR_setitimer 83 /* Common */
102/* #define __NR_ftruncate64 84 Linux sparc32 Specific */
103#define __NR_swapon 85 /* Common */
104#define __NR_getitimer 86 /* Common */
105/* #define __NR_setuid32 87 Linux sparc32, gethostname under SunOS */
106#define __NR_sethostname 88 /* Common */
107/* #define __NR_setgid32 89 Linux sparc32, getdtablesize under SunOS */
108#define __NR_dup2 90 /* Common */
109/* #define __NR_setfsuid32 91 Linux sparc32, getdopt under SunOS */
110#define __NR_fcntl 92 /* Common */
111#define __NR_select 93 /* Common */
112/* #define __NR_setfsgid32 94 Linux sparc32, setdopt under SunOS */
113#define __NR_fsync 95 /* Common */
114#define __NR_setpriority 96 /* Common */
115#define __NR_socket 97 /* Common */
116#define __NR_connect 98 /* Common */
117#define __NR_accept 99 /* Common */
118#define __NR_getpriority 100 /* Common */
119#define __NR_rt_sigreturn 101 /* Linux Specific */
120#define __NR_rt_sigaction 102 /* Linux Specific */
121#define __NR_rt_sigprocmask 103 /* Linux Specific */
122#define __NR_rt_sigpending 104 /* Linux Specific */
123#define __NR_rt_sigtimedwait 105 /* Linux Specific */
124#define __NR_rt_sigqueueinfo 106 /* Linux Specific */
125#define __NR_rt_sigsuspend 107 /* Linux Specific */
126#define __NR_setresuid 108 /* Linux Specific, sigvec under SunOS */
127#define __NR_getresuid 109 /* Linux Specific, sigblock under SunOS */
128#define __NR_setresgid 110 /* Linux Specific, sigsetmask under SunOS */
129#define __NR_getresgid 111 /* Linux Specific, sigpause under SunOS */
130/* #define __NR_setregid32 75 Linux sparc32, sigstack under SunOS */
131#define __NR_recvmsg 113 /* Common */
132#define __NR_sendmsg 114 /* Common */
133/* #define __NR_getgroups32 115 Linux sparc32, vtrace under SunOS */
134#define __NR_gettimeofday 116 /* Common */
135#define __NR_getrusage 117 /* Common */
136#define __NR_getsockopt 118 /* Common */
137#define __NR_getcwd 119 /* Linux Specific */
138#define __NR_readv 120 /* Common */
139#define __NR_writev 121 /* Common */
140#define __NR_settimeofday 122 /* Common */
141#define __NR_fchown 123 /* Common */
142#define __NR_fchmod 124 /* Common */
143#define __NR_recvfrom 125 /* Common */
144#define __NR_setreuid 126 /* Common */
145#define __NR_setregid 127 /* Common */
146#define __NR_rename 128 /* Common */
147#define __NR_truncate 129 /* Common */
148#define __NR_ftruncate 130 /* Common */
149#define __NR_flock 131 /* Common */
150#define __NR_lstat64 132 /* Linux Specific */
151#define __NR_sendto 133 /* Common */
152#define __NR_shutdown 134 /* Common */
153#define __NR_socketpair 135 /* Common */
154#define __NR_mkdir 136 /* Common */
155#define __NR_rmdir 137 /* Common */
156#define __NR_utimes 138 /* SunOS Specific */
157#define __NR_stat64 139 /* Linux Specific */
158#define __NR_sendfile64 140 /* adjtime under SunOS */
159#define __NR_getpeername 141 /* Common */
160#define __NR_futex 142 /* gethostid under SunOS */
161#define __NR_gettid 143 /* ENOSYS under SunOS */
162#define __NR_getrlimit 144 /* Common */
163#define __NR_setrlimit 145 /* Common */
164#define __NR_pivot_root 146 /* Linux Specific, killpg under SunOS */
165#define __NR_prctl 147 /* ENOSYS under SunOS */
166#define __NR_pciconfig_read 148 /* ENOSYS under SunOS */
167#define __NR_pciconfig_write 149 /* ENOSYS under SunOS */
168#define __NR_getsockname 150 /* Common */
169#define __NR_inotify_init 151 /* Linux specific */
170#define __NR_inotify_add_watch 152 /* Linux specific */
171#define __NR_poll 153 /* Common */
172#define __NR_getdents64 154 /* Linux specific */
173/* #define __NR_fcntl64 155 Linux sparc32 Specific */
174#define __NR_inotify_rm_watch 156 /* Linux specific */
175#define __NR_statfs 157 /* Common */
176#define __NR_fstatfs 158 /* Common */
177#define __NR_umount 159 /* Common */
178#define __NR_sched_set_affinity 160 /* Linux specific, async_daemon under SunOS */
179#define __NR_sched_get_affinity 161 /* Linux specific, getfh under SunOS */
180#define __NR_getdomainname 162 /* SunOS Specific */
181#define __NR_setdomainname 163 /* Common */
182#define __NR_utrap_install 164 /* SYSV ABI/v9 required */
183#define __NR_quotactl 165 /* Common */
184#define __NR_set_tid_address 166 /* Linux specific, exportfs under SunOS */
185#define __NR_mount 167 /* Common */
186#define __NR_ustat 168 /* Common */
187#define __NR_setxattr 169 /* SunOS: semsys */
188#define __NR_lsetxattr 170 /* SunOS: msgsys */
189#define __NR_fsetxattr 171 /* SunOS: shmsys */
190#define __NR_getxattr 172 /* SunOS: auditsys */
191#define __NR_lgetxattr 173 /* SunOS: rfssys */
192#define __NR_getdents 174 /* Common */
193#define __NR_setsid 175 /* Common */
194#define __NR_fchdir 176 /* Common */
195#define __NR_fgetxattr 177 /* SunOS: fchroot */
196#define __NR_listxattr 178 /* SunOS: vpixsys */
197#define __NR_llistxattr 179 /* SunOS: aioread */
198#define __NR_flistxattr 180 /* SunOS: aiowrite */
199#define __NR_removexattr 181 /* SunOS: aiowait */
200#define __NR_lremovexattr 182 /* SunOS: aiocancel */
201#define __NR_sigpending 183 /* Common */
202#define __NR_query_module 184 /* Linux Specific */
203#define __NR_setpgid 185 /* Common */
204#define __NR_fremovexattr 186 /* SunOS: pathconf */
205#define __NR_tkill 187 /* SunOS: fpathconf */
206#define __NR_exit_group 188 /* Linux specific, sysconf undef SunOS */
207#define __NR_uname 189 /* Linux Specific */
208#define __NR_init_module 190 /* Linux Specific */
209#define __NR_personality 191 /* Linux Specific */
210#define __NR_remap_file_pages 192 /* Linux Specific */
211#define __NR_epoll_create 193 /* Linux Specific */
212#define __NR_epoll_ctl 194 /* Linux Specific */
213#define __NR_epoll_wait 195 /* Linux Specific */
214#define __NR_ioprio_set 196 /* Linux Specific */
215#define __NR_getppid 197 /* Linux Specific */
216#define __NR_sigaction 198 /* Linux Specific */
217#define __NR_sgetmask 199 /* Linux Specific */
218#define __NR_ssetmask 200 /* Linux Specific */
219#define __NR_sigsuspend 201 /* Linux Specific */
220#define __NR_oldlstat 202 /* Linux Specific */
221#define __NR_uselib 203 /* Linux Specific */
222#define __NR_readdir 204 /* Linux Specific */
223#define __NR_readahead 205 /* Linux Specific */
224#define __NR_socketcall 206 /* Linux Specific */
225#define __NR_syslog 207 /* Linux Specific */
226#define __NR_lookup_dcookie 208 /* Linux Specific */
227#define __NR_fadvise64 209 /* Linux Specific */
228#define __NR_fadvise64_64 210 /* Linux Specific */
229#define __NR_tgkill 211 /* Linux Specific */
230#define __NR_waitpid 212 /* Linux Specific */
231#define __NR_swapoff 213 /* Linux Specific */
232#define __NR_sysinfo 214 /* Linux Specific */
233#define __NR_ipc 215 /* Linux Specific */
234#define __NR_sigreturn 216 /* Linux Specific */
235#define __NR_clone 217 /* Linux Specific */
236#define __NR_ioprio_get 218 /* Linux Specific */
237#define __NR_adjtimex 219 /* Linux Specific */
238#define __NR_sigprocmask 220 /* Linux Specific */
239#define __NR_create_module 221 /* Linux Specific */
240#define __NR_delete_module 222 /* Linux Specific */
241#define __NR_get_kernel_syms 223 /* Linux Specific */
242#define __NR_getpgid 224 /* Linux Specific */
243#define __NR_bdflush 225 /* Linux Specific */
244#define __NR_sysfs 226 /* Linux Specific */
245#define __NR_afs_syscall 227 /* Linux Specific */
246#define __NR_setfsuid 228 /* Linux Specific */
247#define __NR_setfsgid 229 /* Linux Specific */
248#define __NR__newselect 230 /* Linux Specific */
249#ifdef __KERNEL__
250#define __NR_time 231 /* Linux sparc32 */
251#endif
252#define __NR_splice 232 /* Linux Specific */
253#define __NR_stime 233 /* Linux Specific */
254#define __NR_statfs64 234 /* Linux Specific */
255#define __NR_fstatfs64 235 /* Linux Specific */
256#define __NR__llseek 236 /* Linux Specific */
257#define __NR_mlock 237
258#define __NR_munlock 238
259#define __NR_mlockall 239
260#define __NR_munlockall 240
261#define __NR_sched_setparam 241
262#define __NR_sched_getparam 242
263#define __NR_sched_setscheduler 243
264#define __NR_sched_getscheduler 244
265#define __NR_sched_yield 245
266#define __NR_sched_get_priority_max 246
267#define __NR_sched_get_priority_min 247
268#define __NR_sched_rr_get_interval 248
269#define __NR_nanosleep 249
270#define __NR_mremap 250
271#define __NR__sysctl 251
272#define __NR_getsid 252
273#define __NR_fdatasync 253
274#define __NR_nfsservctl 254
275#define __NR_sync_file_range 255
276#define __NR_clock_settime 256
277#define __NR_clock_gettime 257
278#define __NR_clock_getres 258
279#define __NR_clock_nanosleep 259
280#define __NR_sched_getaffinity 260
281#define __NR_sched_setaffinity 261
282#define __NR_timer_settime 262
283#define __NR_timer_gettime 263
284#define __NR_timer_getoverrun 264
285#define __NR_timer_delete 265
286#define __NR_timer_create 266
287/* #define __NR_vserver 267 Reserved for VSERVER */
288#define __NR_io_setup 268
289#define __NR_io_destroy 269
290#define __NR_io_submit 270
291#define __NR_io_cancel 271
292#define __NR_io_getevents 272
293#define __NR_mq_open 273
294#define __NR_mq_unlink 274
295#define __NR_mq_timedsend 275
296#define __NR_mq_timedreceive 276
297#define __NR_mq_notify 277
298#define __NR_mq_getsetattr 278
299#define __NR_waitid 279
300#define __NR_tee 280
301#define __NR_add_key 281
302#define __NR_request_key 282
303#define __NR_keyctl 283
304#define __NR_openat 284
305#define __NR_mkdirat 285
306#define __NR_mknodat 286
307#define __NR_fchownat 287
308#define __NR_futimesat 288
309#define __NR_fstatat64 289
310#define __NR_unlinkat 290
311#define __NR_renameat 291
312#define __NR_linkat 292
313#define __NR_symlinkat 293
314#define __NR_readlinkat 294
315#define __NR_fchmodat 295
316#define __NR_faccessat 296
317#define __NR_pselect6 297
318#define __NR_ppoll 298
319#define __NR_unshare 299
320#define __NR_set_robust_list 300
321#define __NR_get_robust_list 301
322#define __NR_migrate_pages 302
323#define __NR_mbind 303
324#define __NR_get_mempolicy 304
325#define __NR_set_mempolicy 305
326#define __NR_kexec_load 306
327#define __NR_move_pages 307
328#define __NR_getcpu 308
329#define __NR_epoll_pwait 309
330#define __NR_utimensat 310
331#define __NR_signalfd 311
332#define __NR_timerfd_create 312
333#define __NR_eventfd 313
334#define __NR_fallocate 314
335#define __NR_timerfd_settime 315
336#define __NR_timerfd_gettime 316
337
338#define NR_SYSCALLS 317
339
340#ifdef __KERNEL__
341#define __ARCH_WANT_IPC_PARSE_VERSION
342#define __ARCH_WANT_OLD_READDIR
343#define __ARCH_WANT_STAT64
344#define __ARCH_WANT_SYS_ALARM
345#define __ARCH_WANT_SYS_GETHOSTNAME
346#define __ARCH_WANT_SYS_PAUSE
347#define __ARCH_WANT_SYS_SGETMASK
348#define __ARCH_WANT_SYS_SIGNAL
349#define __ARCH_WANT_SYS_TIME
350#define __ARCH_WANT_COMPAT_SYS_TIME
351#define __ARCH_WANT_SYS_UTIME
352#define __ARCH_WANT_SYS_WAITPID
353#define __ARCH_WANT_SYS_SOCKETCALL
354#define __ARCH_WANT_SYS_FADVISE64
355#define __ARCH_WANT_SYS_GETPGRP
356#define __ARCH_WANT_SYS_LLSEEK
357#define __ARCH_WANT_SYS_NICE
358#define __ARCH_WANT_SYS_OLDUMOUNT
359#define __ARCH_WANT_SYS_SIGPENDING
360#define __ARCH_WANT_SYS_SIGPROCMASK
361#define __ARCH_WANT_SYS_RT_SIGSUSPEND
362#define __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND
363
364/*
365 * "Conditional" syscalls
366 *
367 * What we want is __attribute__((weak,alias("sys_ni_syscall"))),
368 * but it doesn't work on all toolchains, so we just do it by hand
369 */
370#define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall")
371
372#endif /* __KERNEL__ */
373#endif /* _SPARC64_UNISTD_H */
diff --git a/include/asm-sparc/upa.h b/include/asm-sparc/upa.h
new file mode 100644
index 000000000000..5b1633223f92
--- /dev/null
+++ b/include/asm-sparc/upa.h
@@ -0,0 +1,109 @@
1#ifndef _SPARC64_UPA_H
2#define _SPARC64_UPA_H
3
4#include <asm/asi.h>
5
6/* UPA level registers and defines. */
7
8/* UPA Config Register */
9#define UPA_CONFIG_RESV 0xffffffffc0000000 /* Reserved. */
10#define UPA_CONFIG_PCON 0x000000003fc00000 /* Depth of various sys queues. */
11#define UPA_CONFIG_MID 0x00000000003e0000 /* Module ID. */
12#define UPA_CONFIG_PCAP 0x000000000001ffff /* Port Capabilities. */
13
14/* UPA Port ID Register */
15#define UPA_PORTID_FNP 0xff00000000000000 /* Hardcoded to 0xfc on ultra. */
16#define UPA_PORTID_RESV 0x00fffff800000000 /* Reserved. */
17#define UPA_PORTID_ECCVALID 0x0000000400000000 /* Zero if mod can generate ECC */
18#define UPA_PORTID_ONEREAD 0x0000000200000000 /* Set if mod generates P_RASB */
19#define UPA_PORTID_PINTRDQ 0x0000000180000000 /* # outstanding P_INT_REQ's */
20#define UPA_PORTID_PREQDQ 0x000000007e000000 /* slave-wr's to mod supported */
21#define UPA_PORTID_PREQRD 0x0000000001e00000 /* # incoming P_REQ's supported */
22#define UPA_PORTID_UPACAP 0x00000000001f0000 /* UPA capabilities of mod */
23#define UPA_PORTID_ID 0x000000000000ffff /* Module Identification bits */
24
25/* UPA I/O space accessors */
26#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
27static inline unsigned char _upa_readb(unsigned long addr)
28{
29 unsigned char ret;
30
31 __asm__ __volatile__("lduba\t[%1] %2, %0\t/* upa_readb */"
32 : "=r" (ret)
33 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
34
35 return ret;
36}
37
38static inline unsigned short _upa_readw(unsigned long addr)
39{
40 unsigned short ret;
41
42 __asm__ __volatile__("lduha\t[%1] %2, %0\t/* upa_readw */"
43 : "=r" (ret)
44 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
45
46 return ret;
47}
48
49static inline unsigned int _upa_readl(unsigned long addr)
50{
51 unsigned int ret;
52
53 __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* upa_readl */"
54 : "=r" (ret)
55 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
56
57 return ret;
58}
59
60static inline unsigned long _upa_readq(unsigned long addr)
61{
62 unsigned long ret;
63
64 __asm__ __volatile__("ldxa\t[%1] %2, %0\t/* upa_readq */"
65 : "=r" (ret)
66 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
67
68 return ret;
69}
70
71static inline void _upa_writeb(unsigned char b, unsigned long addr)
72{
73 __asm__ __volatile__("stba\t%0, [%1] %2\t/* upa_writeb */"
74 : /* no outputs */
75 : "r" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
76}
77
78static inline void _upa_writew(unsigned short w, unsigned long addr)
79{
80 __asm__ __volatile__("stha\t%0, [%1] %2\t/* upa_writew */"
81 : /* no outputs */
82 : "r" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
83}
84
85static inline void _upa_writel(unsigned int l, unsigned long addr)
86{
87 __asm__ __volatile__("stwa\t%0, [%1] %2\t/* upa_writel */"
88 : /* no outputs */
89 : "r" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
90}
91
92static inline void _upa_writeq(unsigned long q, unsigned long addr)
93{
94 __asm__ __volatile__("stxa\t%0, [%1] %2\t/* upa_writeq */"
95 : /* no outputs */
96 : "r" (q), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
97}
98
99#define upa_readb(__addr) (_upa_readb((unsigned long)(__addr)))
100#define upa_readw(__addr) (_upa_readw((unsigned long)(__addr)))
101#define upa_readl(__addr) (_upa_readl((unsigned long)(__addr)))
102#define upa_readq(__addr) (_upa_readq((unsigned long)(__addr)))
103#define upa_writeb(__b, __addr) (_upa_writeb((__b), (unsigned long)(__addr)))
104#define upa_writew(__w, __addr) (_upa_writew((__w), (unsigned long)(__addr)))
105#define upa_writel(__l, __addr) (_upa_writel((__l), (unsigned long)(__addr)))
106#define upa_writeq(__q, __addr) (_upa_writeq((__q), (unsigned long)(__addr)))
107#endif /* __KERNEL__ && !__ASSEMBLY__ */
108
109#endif /* !(_SPARC64_UPA_H) */
diff --git a/include/asm-sparc/utrap.h b/include/asm-sparc/utrap.h
new file mode 100644
index 000000000000..9da37babbe5b
--- /dev/null
+++ b/include/asm-sparc/utrap.h
@@ -0,0 +1,51 @@
1/*
2 * include/asm-sparc64/utrap.h
3 *
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 */
6
7#ifndef __ASM_SPARC64_UTRAP_H
8#define __ASM_SPARC64_UTRAP_H
9
10#define UT_INSTRUCTION_EXCEPTION 1
11#define UT_INSTRUCTION_ERROR 2
12#define UT_INSTRUCTION_PROTECTION 3
13#define UT_ILLTRAP_INSTRUCTION 4
14#define UT_ILLEGAL_INSTRUCTION 5
15#define UT_PRIVILEGED_OPCODE 6
16#define UT_FP_DISABLED 7
17#define UT_FP_EXCEPTION_IEEE_754 8
18#define UT_FP_EXCEPTION_OTHER 9
19#define UT_TAG_OVERVIEW 10
20#define UT_DIVISION_BY_ZERO 11
21#define UT_DATA_EXCEPTION 12
22#define UT_DATA_ERROR 13
23#define UT_DATA_PROTECTION 14
24#define UT_MEM_ADDRESS_NOT_ALIGNED 15
25#define UT_PRIVILEGED_ACTION 16
26#define UT_ASYNC_DATA_ERROR 17
27#define UT_TRAP_INSTRUCTION_16 18
28#define UT_TRAP_INSTRUCTION_17 19
29#define UT_TRAP_INSTRUCTION_18 20
30#define UT_TRAP_INSTRUCTION_19 21
31#define UT_TRAP_INSTRUCTION_20 22
32#define UT_TRAP_INSTRUCTION_21 23
33#define UT_TRAP_INSTRUCTION_22 24
34#define UT_TRAP_INSTRUCTION_23 25
35#define UT_TRAP_INSTRUCTION_24 26
36#define UT_TRAP_INSTRUCTION_25 27
37#define UT_TRAP_INSTRUCTION_26 28
38#define UT_TRAP_INSTRUCTION_27 29
39#define UT_TRAP_INSTRUCTION_28 30
40#define UT_TRAP_INSTRUCTION_29 31
41#define UT_TRAP_INSTRUCTION_30 32
42#define UT_TRAP_INSTRUCTION_31 33
43
44#define UTH_NOCHANGE (-1)
45
46#ifndef __ASSEMBLY__
47typedef int utrap_entry_t;
48typedef void *utrap_handler_t;
49#endif /* __ASSEMBLY__ */
50
51#endif /* !(__ASM_SPARC64_PROCESSOR_H) */
diff --git a/include/asm-sparc/vaddrs.h b/include/asm-sparc/vaddrs.h
index f6ca4779056c..a22fed5a3c6b 100644
--- a/include/asm-sparc/vaddrs.h
+++ b/include/asm-sparc/vaddrs.h
@@ -34,11 +34,6 @@
34#define IOBASE_VADDR 0xfe000000 34#define IOBASE_VADDR 0xfe000000
35#define IOBASE_END 0xfe600000 35#define IOBASE_END 0xfe600000
36 36
37#define VMALLOC_START 0xfe600000
38
39/* XXX Alter this when I get around to fixing sun4c - Anton */
40#define VMALLOC_END 0xffc00000
41
42/* 37/*
43 * On the sun4/4c we need a place 38 * On the sun4/4c we need a place
44 * to reliably map locked down kernel data. This includes the 39 * to reliably map locked down kernel data. This includes the
diff --git a/include/asm-sparc/vio.h b/include/asm-sparc/vio.h
new file mode 100644
index 000000000000..d4de32f0f8af
--- /dev/null
+++ b/include/asm-sparc/vio.h
@@ -0,0 +1,406 @@
1#ifndef _SPARC64_VIO_H
2#define _SPARC64_VIO_H
3
4#include <linux/kernel.h>
5#include <linux/device.h>
6#include <linux/mod_devicetable.h>
7#include <linux/timer.h>
8#include <linux/spinlock.h>
9#include <linux/completion.h>
10#include <linux/list.h>
11#include <linux/log2.h>
12
13#include <asm/ldc.h>
14#include <asm/mdesc.h>
15
16struct vio_msg_tag {
17 u8 type;
18#define VIO_TYPE_CTRL 0x01
19#define VIO_TYPE_DATA 0x02
20#define VIO_TYPE_ERR 0x04
21
22 u8 stype;
23#define VIO_SUBTYPE_INFO 0x01
24#define VIO_SUBTYPE_ACK 0x02
25#define VIO_SUBTYPE_NACK 0x04
26
27 u16 stype_env;
28#define VIO_VER_INFO 0x0001
29#define VIO_ATTR_INFO 0x0002
30#define VIO_DRING_REG 0x0003
31#define VIO_DRING_UNREG 0x0004
32#define VIO_RDX 0x0005
33#define VIO_PKT_DATA 0x0040
34#define VIO_DESC_DATA 0x0041
35#define VIO_DRING_DATA 0x0042
36#define VNET_MCAST_INFO 0x0101
37
38 u32 sid;
39};
40
41struct vio_rdx {
42 struct vio_msg_tag tag;
43 u64 resv[6];
44};
45
46struct vio_ver_info {
47 struct vio_msg_tag tag;
48 u16 major;
49 u16 minor;
50 u8 dev_class;
51#define VDEV_NETWORK 0x01
52#define VDEV_NETWORK_SWITCH 0x02
53#define VDEV_DISK 0x03
54#define VDEV_DISK_SERVER 0x04
55
56 u8 resv1[3];
57 u64 resv2[5];
58};
59
60struct vio_dring_register {
61 struct vio_msg_tag tag;
62 u64 dring_ident;
63 u32 num_descr;
64 u32 descr_size;
65 u16 options;
66#define VIO_TX_DRING 0x0001
67#define VIO_RX_DRING 0x0002
68 u16 resv;
69 u32 num_cookies;
70 struct ldc_trans_cookie cookies[0];
71};
72
73struct vio_dring_unregister {
74 struct vio_msg_tag tag;
75 u64 dring_ident;
76 u64 resv[5];
77};
78
79/* Data transfer modes */
80#define VIO_PKT_MODE 0x01 /* Packet based transfer */
81#define VIO_DESC_MODE 0x02 /* In-band descriptors */
82#define VIO_DRING_MODE 0x03 /* Descriptor rings */
83
84struct vio_dring_data {
85 struct vio_msg_tag tag;
86 u64 seq;
87 u64 dring_ident;
88 u32 start_idx;
89 u32 end_idx;
90 u8 state;
91#define VIO_DRING_ACTIVE 0x01
92#define VIO_DRING_STOPPED 0x02
93
94 u8 __pad1;
95 u16 __pad2;
96 u32 __pad3;
97 u64 __par4[2];
98};
99
100struct vio_dring_hdr {
101 u8 state;
102#define VIO_DESC_FREE 0x01
103#define VIO_DESC_READY 0x02
104#define VIO_DESC_ACCEPTED 0x03
105#define VIO_DESC_DONE 0x04
106 u8 ack;
107#define VIO_ACK_ENABLE 0x01
108#define VIO_ACK_DISABLE 0x00
109
110 u16 __pad1;
111 u32 __pad2;
112};
113
114/* VIO disk specific structures and defines */
115struct vio_disk_attr_info {
116 struct vio_msg_tag tag;
117 u8 xfer_mode;
118 u8 vdisk_type;
119#define VD_DISK_TYPE_SLICE 0x01 /* Slice in block device */
120#define VD_DISK_TYPE_DISK 0x02 /* Entire block device */
121 u16 resv1;
122 u32 vdisk_block_size;
123 u64 operations;
124 u64 vdisk_size;
125 u64 max_xfer_size;
126 u64 resv2[2];
127};
128
129struct vio_disk_desc {
130 struct vio_dring_hdr hdr;
131 u64 req_id;
132 u8 operation;
133#define VD_OP_BREAD 0x01 /* Block read */
134#define VD_OP_BWRITE 0x02 /* Block write */
135#define VD_OP_FLUSH 0x03 /* Flush disk contents */
136#define VD_OP_GET_WCE 0x04 /* Get write-cache status */
137#define VD_OP_SET_WCE 0x05 /* Enable/disable write-cache */
138#define VD_OP_GET_VTOC 0x06 /* Get VTOC */
139#define VD_OP_SET_VTOC 0x07 /* Set VTOC */
140#define VD_OP_GET_DISKGEOM 0x08 /* Get disk geometry */
141#define VD_OP_SET_DISKGEOM 0x09 /* Set disk geometry */
142#define VD_OP_SCSICMD 0x0a /* SCSI control command */
143#define VD_OP_GET_DEVID 0x0b /* Get device ID */
144#define VD_OP_GET_EFI 0x0c /* Get EFI */
145#define VD_OP_SET_EFI 0x0d /* Set EFI */
146 u8 slice;
147 u16 resv1;
148 u32 status;
149 u64 offset;
150 u64 size;
151 u32 ncookies;
152 u32 resv2;
153 struct ldc_trans_cookie cookies[0];
154};
155
156#define VIO_DISK_VNAME_LEN 8
157#define VIO_DISK_ALABEL_LEN 128
158#define VIO_DISK_NUM_PART 8
159
160struct vio_disk_vtoc {
161 u8 volume_name[VIO_DISK_VNAME_LEN];
162 u16 sector_size;
163 u16 num_partitions;
164 u8 ascii_label[VIO_DISK_ALABEL_LEN];
165 struct {
166 u16 id;
167 u16 perm_flags;
168 u32 resv;
169 u64 start_block;
170 u64 num_blocks;
171 } partitions[VIO_DISK_NUM_PART];
172};
173
174struct vio_disk_geom {
175 u16 num_cyl; /* Num data cylinders */
176 u16 alt_cyl; /* Num alternate cylinders */
177 u16 beg_cyl; /* Cyl off of fixed head area */
178 u16 num_hd; /* Num heads */
179 u16 num_sec; /* Num sectors */
180 u16 ifact; /* Interleave factor */
181 u16 apc; /* Alts per cylinder (SCSI) */
182 u16 rpm; /* Revolutions per minute */
183 u16 phy_cyl; /* Num physical cylinders */
184 u16 wr_skip; /* Num sects to skip, writes */
185 u16 rd_skip; /* Num sects to skip, writes */
186};
187
188struct vio_disk_devid {
189 u16 resv;
190 u16 type;
191 u32 len;
192 char id[0];
193};
194
195struct vio_disk_efi {
196 u64 lba;
197 u64 len;
198 char data[0];
199};
200
201/* VIO net specific structures and defines */
202struct vio_net_attr_info {
203 struct vio_msg_tag tag;
204 u8 xfer_mode;
205 u8 addr_type;
206#define VNET_ADDR_ETHERMAC 0x01
207 u16 ack_freq;
208 u32 resv1;
209 u64 addr;
210 u64 mtu;
211 u64 resv2[3];
212};
213
214#define VNET_NUM_MCAST 7
215
216struct vio_net_mcast_info {
217 struct vio_msg_tag tag;
218 u8 set;
219 u8 count;
220 u8 mcast_addr[VNET_NUM_MCAST * 6];
221 u32 resv;
222};
223
224struct vio_net_desc {
225 struct vio_dring_hdr hdr;
226 u32 size;
227 u32 ncookies;
228 struct ldc_trans_cookie cookies[0];
229};
230
231#define VIO_MAX_RING_COOKIES 24
232
233struct vio_dring_state {
234 u64 ident;
235 void *base;
236 u64 snd_nxt;
237 u64 rcv_nxt;
238 u32 entry_size;
239 u32 num_entries;
240 u32 prod;
241 u32 cons;
242 u32 pending;
243 int ncookies;
244 struct ldc_trans_cookie cookies[VIO_MAX_RING_COOKIES];
245};
246
247static inline void *vio_dring_cur(struct vio_dring_state *dr)
248{
249 return dr->base + (dr->entry_size * dr->prod);
250}
251
252static inline void *vio_dring_entry(struct vio_dring_state *dr,
253 unsigned int index)
254{
255 return dr->base + (dr->entry_size * index);
256}
257
258static inline u32 vio_dring_avail(struct vio_dring_state *dr,
259 unsigned int ring_size)
260{
261 BUILD_BUG_ON(!is_power_of_2(ring_size));
262
263 return (dr->pending -
264 ((dr->prod - dr->cons) & (ring_size - 1)));
265}
266
267#define VIO_MAX_TYPE_LEN 32
268#define VIO_MAX_COMPAT_LEN 64
269
270struct vio_dev {
271 u64 mp;
272 struct device_node *dp;
273
274 char type[VIO_MAX_TYPE_LEN];
275 char compat[VIO_MAX_COMPAT_LEN];
276 int compat_len;
277
278 u64 dev_no;
279
280 unsigned long channel_id;
281
282 unsigned int tx_irq;
283 unsigned int rx_irq;
284
285 struct device dev;
286};
287
288struct vio_driver {
289 struct list_head node;
290 const struct vio_device_id *id_table;
291 int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
292 int (*remove)(struct vio_dev *dev);
293 void (*shutdown)(struct vio_dev *dev);
294 unsigned long driver_data;
295 struct device_driver driver;
296};
297
298struct vio_version {
299 u16 major;
300 u16 minor;
301};
302
303struct vio_driver_state;
304struct vio_driver_ops {
305 int (*send_attr)(struct vio_driver_state *vio);
306 int (*handle_attr)(struct vio_driver_state *vio, void *pkt);
307 void (*handshake_complete)(struct vio_driver_state *vio);
308};
309
310struct vio_completion {
311 struct completion com;
312 int err;
313 int waiting_for;
314};
315
316struct vio_driver_state {
317 /* Protects VIO handshake and, optionally, driver private state. */
318 spinlock_t lock;
319
320 struct ldc_channel *lp;
321
322 u32 _peer_sid;
323 u32 _local_sid;
324 struct vio_dring_state drings[2];
325#define VIO_DRIVER_TX_RING 0
326#define VIO_DRIVER_RX_RING 1
327
328 u8 hs_state;
329#define VIO_HS_INVALID 0x00
330#define VIO_HS_GOTVERS 0x01
331#define VIO_HS_GOT_ATTR 0x04
332#define VIO_HS_SENT_DREG 0x08
333#define VIO_HS_SENT_RDX 0x10
334#define VIO_HS_GOT_RDX_ACK 0x20
335#define VIO_HS_GOT_RDX 0x40
336#define VIO_HS_SENT_RDX_ACK 0x80
337#define VIO_HS_COMPLETE (VIO_HS_GOT_RDX_ACK | VIO_HS_SENT_RDX_ACK)
338
339 u8 dev_class;
340
341 u8 dr_state;
342#define VIO_DR_STATE_TXREG 0x01
343#define VIO_DR_STATE_RXREG 0x02
344#define VIO_DR_STATE_TXREQ 0x10
345#define VIO_DR_STATE_RXREQ 0x20
346
347 u8 debug;
348#define VIO_DEBUG_HS 0x01
349#define VIO_DEBUG_DATA 0x02
350
351 void *desc_buf;
352 unsigned int desc_buf_len;
353
354 struct vio_completion *cmp;
355
356 struct vio_dev *vdev;
357
358 struct timer_list timer;
359
360 struct vio_version ver;
361
362 struct vio_version *ver_table;
363 int ver_table_entries;
364
365 char *name;
366
367 struct vio_driver_ops *ops;
368};
369
370#define viodbg(TYPE, f, a...) \
371do { if (vio->debug & VIO_DEBUG_##TYPE) \
372 printk(KERN_INFO "vio: ID[%lu] " f, \
373 vio->vdev->channel_id, ## a); \
374} while (0)
375
376extern int vio_register_driver(struct vio_driver *drv);
377extern void vio_unregister_driver(struct vio_driver *drv);
378
379static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
380{
381 return container_of(drv, struct vio_driver, driver);
382}
383
384static inline struct vio_dev *to_vio_dev(struct device *dev)
385{
386 return container_of(dev, struct vio_dev, dev);
387}
388
389extern int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
390extern void vio_link_state_change(struct vio_driver_state *vio, int event);
391extern void vio_conn_reset(struct vio_driver_state *vio);
392extern int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
393extern int vio_validate_sid(struct vio_driver_state *vio,
394 struct vio_msg_tag *tp);
395extern u32 vio_send_sid(struct vio_driver_state *vio);
396extern int vio_ldc_alloc(struct vio_driver_state *vio,
397 struct ldc_channel_config *base_cfg, void *event_arg);
398extern void vio_ldc_free(struct vio_driver_state *vio);
399extern int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
400 u8 dev_class, struct vio_version *ver_table,
401 int ver_table_size, struct vio_driver_ops *ops,
402 char *name);
403
404extern void vio_port_up(struct vio_driver_state *vio);
405
406#endif /* _SPARC64_VIO_H */
diff --git a/include/asm-sparc/visasm.h b/include/asm-sparc/visasm.h
new file mode 100644
index 000000000000..de797b9bf552
--- /dev/null
+++ b/include/asm-sparc/visasm.h
@@ -0,0 +1,62 @@
1#ifndef _SPARC64_VISASM_H
2#define _SPARC64_VISASM_H
3
4/* visasm.h: FPU saving macros for VIS routines
5 *
6 * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz)
7 */
8
9#include <asm/pstate.h>
10#include <asm/ptrace.h>
11
12/* Clobbers %o5, %g1, %g2, %g3, %g7, %icc, %xcc */
13
14#define VISEntry \
15 rd %fprs, %o5; \
16 andcc %o5, (FPRS_FEF|FPRS_DU), %g0; \
17 be,pt %icc, 297f; \
18 sethi %hi(297f), %g7; \
19 sethi %hi(VISenter), %g1; \
20 jmpl %g1 + %lo(VISenter), %g0; \
21 or %g7, %lo(297f), %g7; \
22297: wr %g0, FPRS_FEF, %fprs; \
23
24#define VISExit \
25 wr %g0, 0, %fprs;
26
27/* Clobbers %o5, %g1, %g2, %g3, %g7, %icc, %xcc.
28 * Must preserve %o5 between VISEntryHalf and VISExitHalf */
29
30#define VISEntryHalf \
31 rd %fprs, %o5; \
32 andcc %o5, FPRS_FEF, %g0; \
33 be,pt %icc, 297f; \
34 sethi %hi(298f), %g7; \
35 sethi %hi(VISenterhalf), %g1; \
36 jmpl %g1 + %lo(VISenterhalf), %g0; \
37 or %g7, %lo(298f), %g7; \
38 clr %o5; \
39297: wr %o5, FPRS_FEF, %fprs; \
40298:
41
42#define VISExitHalf \
43 wr %o5, 0, %fprs;
44
45#ifndef __ASSEMBLY__
46static inline void save_and_clear_fpu(void) {
47 __asm__ __volatile__ (
48" rd %%fprs, %%o5\n"
49" andcc %%o5, %0, %%g0\n"
50" be,pt %%icc, 299f\n"
51" sethi %%hi(298f), %%g7\n"
52" sethi %%hi(VISenter), %%g1\n"
53" jmpl %%g1 + %%lo(VISenter), %%g0\n"
54" or %%g7, %%lo(298f), %%g7\n"
55" 298: wr %%g0, 0, %%fprs\n"
56" 299:\n"
57" " : : "i" (FPRS_FEF|FPRS_DU) :
58 "o5", "g1", "g2", "g3", "g7", "cc");
59}
60#endif
61
62#endif /* _SPARC64_ASI_H */
diff --git a/include/asm-sparc/watchdog.h b/include/asm-sparc/watchdog.h
new file mode 100644
index 000000000000..5baf2d3919cf
--- /dev/null
+++ b/include/asm-sparc/watchdog.h
@@ -0,0 +1,31 @@
1/*
2 *
3 * watchdog - Driver interface for the hardware watchdog timers
4 * present on Sun Microsystems boardsets
5 *
6 * Copyright (c) 2000 Eric Brower <ebrower@usa.net>
7 *
8 */
9
10#ifndef _SPARC64_WATCHDOG_H
11#define _SPARC64_WATCHDOG_H
12
13#include <linux/watchdog.h>
14
15/* Solaris compatibility ioctls--
16 * Ref. <linux/watchdog.h> for standard linux watchdog ioctls
17 */
18#define WIOCSTART _IO (WATCHDOG_IOCTL_BASE, 10) /* Start Timer */
19#define WIOCSTOP _IO (WATCHDOG_IOCTL_BASE, 11) /* Stop Timer */
20#define WIOCGSTAT _IOR(WATCHDOG_IOCTL_BASE, 12, int)/* Get Timer Status */
21
22/* Status flags from WIOCGSTAT ioctl
23 */
24#define WD_FREERUN 0x01 /* timer is running, interrupts disabled */
25#define WD_EXPIRED 0x02 /* timer has expired */
26#define WD_RUNNING 0x04 /* timer is running, interrupts enabled */
27#define WD_STOPPED 0x08 /* timer has not been started */
28#define WD_SERVICED 0x10 /* timer interrupt was serviced */
29
30#endif /* ifndef _SPARC64_WATCHDOG_H */
31
diff --git a/include/asm-sparc/xor.h b/include/asm-sparc/xor.h
index f34b2cfa8206..35089a838c3f 100644
--- a/include/asm-sparc/xor.h
+++ b/include/asm-sparc/xor.h
@@ -1,269 +1,8 @@
1/* 1#ifndef ___ASM_SPARC_XOR_H
2 * include/asm-sparc/xor.h 2#define ___ASM_SPARC_XOR_H
3 * 3#if defined(__sparc__) && defined(__arch64__)
4 * Optimized RAID-5 checksumming functions for 32-bit Sparc. 4#include <asm-sparc/xor_64.h>
5 * 5#else
6 * This program is free software; you can redistribute it and/or modify 6#include <asm-sparc/xor_32.h>
7 * it under the terms of the GNU General Public License as published by 7#endif
8 * the Free Software Foundation; either version 2, or (at your option) 8#endif
9 * any later version.
10 *
11 * You should have received a copy of the GNU General Public License
12 * (for example /usr/src/linux/COPYING); if not, write to the Free
13 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
14 */
15
16/*
17 * High speed xor_block operation for RAID4/5 utilizing the
18 * ldd/std SPARC instructions.
19 *
20 * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
21 */
22
23static void
24sparc_2(unsigned long bytes, unsigned long *p1, unsigned long *p2)
25{
26 int lines = bytes / (sizeof (long)) / 8;
27
28 do {
29 __asm__ __volatile__(
30 "ldd [%0 + 0x00], %%g2\n\t"
31 "ldd [%0 + 0x08], %%g4\n\t"
32 "ldd [%0 + 0x10], %%o0\n\t"
33 "ldd [%0 + 0x18], %%o2\n\t"
34 "ldd [%1 + 0x00], %%o4\n\t"
35 "ldd [%1 + 0x08], %%l0\n\t"
36 "ldd [%1 + 0x10], %%l2\n\t"
37 "ldd [%1 + 0x18], %%l4\n\t"
38 "xor %%g2, %%o4, %%g2\n\t"
39 "xor %%g3, %%o5, %%g3\n\t"
40 "xor %%g4, %%l0, %%g4\n\t"
41 "xor %%g5, %%l1, %%g5\n\t"
42 "xor %%o0, %%l2, %%o0\n\t"
43 "xor %%o1, %%l3, %%o1\n\t"
44 "xor %%o2, %%l4, %%o2\n\t"
45 "xor %%o3, %%l5, %%o3\n\t"
46 "std %%g2, [%0 + 0x00]\n\t"
47 "std %%g4, [%0 + 0x08]\n\t"
48 "std %%o0, [%0 + 0x10]\n\t"
49 "std %%o2, [%0 + 0x18]\n"
50 :
51 : "r" (p1), "r" (p2)
52 : "g2", "g3", "g4", "g5",
53 "o0", "o1", "o2", "o3", "o4", "o5",
54 "l0", "l1", "l2", "l3", "l4", "l5");
55 p1 += 8;
56 p2 += 8;
57 } while (--lines > 0);
58}
59
60static void
61sparc_3(unsigned long bytes, unsigned long *p1, unsigned long *p2,
62 unsigned long *p3)
63{
64 int lines = bytes / (sizeof (long)) / 8;
65
66 do {
67 __asm__ __volatile__(
68 "ldd [%0 + 0x00], %%g2\n\t"
69 "ldd [%0 + 0x08], %%g4\n\t"
70 "ldd [%0 + 0x10], %%o0\n\t"
71 "ldd [%0 + 0x18], %%o2\n\t"
72 "ldd [%1 + 0x00], %%o4\n\t"
73 "ldd [%1 + 0x08], %%l0\n\t"
74 "ldd [%1 + 0x10], %%l2\n\t"
75 "ldd [%1 + 0x18], %%l4\n\t"
76 "xor %%g2, %%o4, %%g2\n\t"
77 "xor %%g3, %%o5, %%g3\n\t"
78 "ldd [%2 + 0x00], %%o4\n\t"
79 "xor %%g4, %%l0, %%g4\n\t"
80 "xor %%g5, %%l1, %%g5\n\t"
81 "ldd [%2 + 0x08], %%l0\n\t"
82 "xor %%o0, %%l2, %%o0\n\t"
83 "xor %%o1, %%l3, %%o1\n\t"
84 "ldd [%2 + 0x10], %%l2\n\t"
85 "xor %%o2, %%l4, %%o2\n\t"
86 "xor %%o3, %%l5, %%o3\n\t"
87 "ldd [%2 + 0x18], %%l4\n\t"
88 "xor %%g2, %%o4, %%g2\n\t"
89 "xor %%g3, %%o5, %%g3\n\t"
90 "xor %%g4, %%l0, %%g4\n\t"
91 "xor %%g5, %%l1, %%g5\n\t"
92 "xor %%o0, %%l2, %%o0\n\t"
93 "xor %%o1, %%l3, %%o1\n\t"
94 "xor %%o2, %%l4, %%o2\n\t"
95 "xor %%o3, %%l5, %%o3\n\t"
96 "std %%g2, [%0 + 0x00]\n\t"
97 "std %%g4, [%0 + 0x08]\n\t"
98 "std %%o0, [%0 + 0x10]\n\t"
99 "std %%o2, [%0 + 0x18]\n"
100 :
101 : "r" (p1), "r" (p2), "r" (p3)
102 : "g2", "g3", "g4", "g5",
103 "o0", "o1", "o2", "o3", "o4", "o5",
104 "l0", "l1", "l2", "l3", "l4", "l5");
105 p1 += 8;
106 p2 += 8;
107 p3 += 8;
108 } while (--lines > 0);
109}
110
111static void
112sparc_4(unsigned long bytes, unsigned long *p1, unsigned long *p2,
113 unsigned long *p3, unsigned long *p4)
114{
115 int lines = bytes / (sizeof (long)) / 8;
116
117 do {
118 __asm__ __volatile__(
119 "ldd [%0 + 0x00], %%g2\n\t"
120 "ldd [%0 + 0x08], %%g4\n\t"
121 "ldd [%0 + 0x10], %%o0\n\t"
122 "ldd [%0 + 0x18], %%o2\n\t"
123 "ldd [%1 + 0x00], %%o4\n\t"
124 "ldd [%1 + 0x08], %%l0\n\t"
125 "ldd [%1 + 0x10], %%l2\n\t"
126 "ldd [%1 + 0x18], %%l4\n\t"
127 "xor %%g2, %%o4, %%g2\n\t"
128 "xor %%g3, %%o5, %%g3\n\t"
129 "ldd [%2 + 0x00], %%o4\n\t"
130 "xor %%g4, %%l0, %%g4\n\t"
131 "xor %%g5, %%l1, %%g5\n\t"
132 "ldd [%2 + 0x08], %%l0\n\t"
133 "xor %%o0, %%l2, %%o0\n\t"
134 "xor %%o1, %%l3, %%o1\n\t"
135 "ldd [%2 + 0x10], %%l2\n\t"
136 "xor %%o2, %%l4, %%o2\n\t"
137 "xor %%o3, %%l5, %%o3\n\t"
138 "ldd [%2 + 0x18], %%l4\n\t"
139 "xor %%g2, %%o4, %%g2\n\t"
140 "xor %%g3, %%o5, %%g3\n\t"
141 "ldd [%3 + 0x00], %%o4\n\t"
142 "xor %%g4, %%l0, %%g4\n\t"
143 "xor %%g5, %%l1, %%g5\n\t"
144 "ldd [%3 + 0x08], %%l0\n\t"
145 "xor %%o0, %%l2, %%o0\n\t"
146 "xor %%o1, %%l3, %%o1\n\t"
147 "ldd [%3 + 0x10], %%l2\n\t"
148 "xor %%o2, %%l4, %%o2\n\t"
149 "xor %%o3, %%l5, %%o3\n\t"
150 "ldd [%3 + 0x18], %%l4\n\t"
151 "xor %%g2, %%o4, %%g2\n\t"
152 "xor %%g3, %%o5, %%g3\n\t"
153 "xor %%g4, %%l0, %%g4\n\t"
154 "xor %%g5, %%l1, %%g5\n\t"
155 "xor %%o0, %%l2, %%o0\n\t"
156 "xor %%o1, %%l3, %%o1\n\t"
157 "xor %%o2, %%l4, %%o2\n\t"
158 "xor %%o3, %%l5, %%o3\n\t"
159 "std %%g2, [%0 + 0x00]\n\t"
160 "std %%g4, [%0 + 0x08]\n\t"
161 "std %%o0, [%0 + 0x10]\n\t"
162 "std %%o2, [%0 + 0x18]\n"
163 :
164 : "r" (p1), "r" (p2), "r" (p3), "r" (p4)
165 : "g2", "g3", "g4", "g5",
166 "o0", "o1", "o2", "o3", "o4", "o5",
167 "l0", "l1", "l2", "l3", "l4", "l5");
168 p1 += 8;
169 p2 += 8;
170 p3 += 8;
171 p4 += 8;
172 } while (--lines > 0);
173}
174
175static void
176sparc_5(unsigned long bytes, unsigned long *p1, unsigned long *p2,
177 unsigned long *p3, unsigned long *p4, unsigned long *p5)
178{
179 int lines = bytes / (sizeof (long)) / 8;
180
181 do {
182 __asm__ __volatile__(
183 "ldd [%0 + 0x00], %%g2\n\t"
184 "ldd [%0 + 0x08], %%g4\n\t"
185 "ldd [%0 + 0x10], %%o0\n\t"
186 "ldd [%0 + 0x18], %%o2\n\t"
187 "ldd [%1 + 0x00], %%o4\n\t"
188 "ldd [%1 + 0x08], %%l0\n\t"
189 "ldd [%1 + 0x10], %%l2\n\t"
190 "ldd [%1 + 0x18], %%l4\n\t"
191 "xor %%g2, %%o4, %%g2\n\t"
192 "xor %%g3, %%o5, %%g3\n\t"
193 "ldd [%2 + 0x00], %%o4\n\t"
194 "xor %%g4, %%l0, %%g4\n\t"
195 "xor %%g5, %%l1, %%g5\n\t"
196 "ldd [%2 + 0x08], %%l0\n\t"
197 "xor %%o0, %%l2, %%o0\n\t"
198 "xor %%o1, %%l3, %%o1\n\t"
199 "ldd [%2 + 0x10], %%l2\n\t"
200 "xor %%o2, %%l4, %%o2\n\t"
201 "xor %%o3, %%l5, %%o3\n\t"
202 "ldd [%2 + 0x18], %%l4\n\t"
203 "xor %%g2, %%o4, %%g2\n\t"
204 "xor %%g3, %%o5, %%g3\n\t"
205 "ldd [%3 + 0x00], %%o4\n\t"
206 "xor %%g4, %%l0, %%g4\n\t"
207 "xor %%g5, %%l1, %%g5\n\t"
208 "ldd [%3 + 0x08], %%l0\n\t"
209 "xor %%o0, %%l2, %%o0\n\t"
210 "xor %%o1, %%l3, %%o1\n\t"
211 "ldd [%3 + 0x10], %%l2\n\t"
212 "xor %%o2, %%l4, %%o2\n\t"
213 "xor %%o3, %%l5, %%o3\n\t"
214 "ldd [%3 + 0x18], %%l4\n\t"
215 "xor %%g2, %%o4, %%g2\n\t"
216 "xor %%g3, %%o5, %%g3\n\t"
217 "ldd [%4 + 0x00], %%o4\n\t"
218 "xor %%g4, %%l0, %%g4\n\t"
219 "xor %%g5, %%l1, %%g5\n\t"
220 "ldd [%4 + 0x08], %%l0\n\t"
221 "xor %%o0, %%l2, %%o0\n\t"
222 "xor %%o1, %%l3, %%o1\n\t"
223 "ldd [%4 + 0x10], %%l2\n\t"
224 "xor %%o2, %%l4, %%o2\n\t"
225 "xor %%o3, %%l5, %%o3\n\t"
226 "ldd [%4 + 0x18], %%l4\n\t"
227 "xor %%g2, %%o4, %%g2\n\t"
228 "xor %%g3, %%o5, %%g3\n\t"
229 "xor %%g4, %%l0, %%g4\n\t"
230 "xor %%g5, %%l1, %%g5\n\t"
231 "xor %%o0, %%l2, %%o0\n\t"
232 "xor %%o1, %%l3, %%o1\n\t"
233 "xor %%o2, %%l4, %%o2\n\t"
234 "xor %%o3, %%l5, %%o3\n\t"
235 "std %%g2, [%0 + 0x00]\n\t"
236 "std %%g4, [%0 + 0x08]\n\t"
237 "std %%o0, [%0 + 0x10]\n\t"
238 "std %%o2, [%0 + 0x18]\n"
239 :
240 : "r" (p1), "r" (p2), "r" (p3), "r" (p4), "r" (p5)
241 : "g2", "g3", "g4", "g5",
242 "o0", "o1", "o2", "o3", "o4", "o5",
243 "l0", "l1", "l2", "l3", "l4", "l5");
244 p1 += 8;
245 p2 += 8;
246 p3 += 8;
247 p4 += 8;
248 p5 += 8;
249 } while (--lines > 0);
250}
251
252static struct xor_block_template xor_block_SPARC = {
253 .name = "SPARC",
254 .do_2 = sparc_2,
255 .do_3 = sparc_3,
256 .do_4 = sparc_4,
257 .do_5 = sparc_5,
258};
259
260/* For grins, also test the generic routines. */
261#include <asm-generic/xor.h>
262
263#undef XOR_TRY_TEMPLATES
264#define XOR_TRY_TEMPLATES \
265 do { \
266 xor_speed(&xor_block_8regs); \
267 xor_speed(&xor_block_32regs); \
268 xor_speed(&xor_block_SPARC); \
269 } while (0)
diff --git a/include/asm-sparc/xor_32.h b/include/asm-sparc/xor_32.h
new file mode 100644
index 000000000000..f34b2cfa8206
--- /dev/null
+++ b/include/asm-sparc/xor_32.h
@@ -0,0 +1,269 @@
1/*
2 * include/asm-sparc/xor.h
3 *
4 * Optimized RAID-5 checksumming functions for 32-bit Sparc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * You should have received a copy of the GNU General Public License
12 * (for example /usr/src/linux/COPYING); if not, write to the Free
13 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
14 */
15
16/*
17 * High speed xor_block operation for RAID4/5 utilizing the
18 * ldd/std SPARC instructions.
19 *
20 * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
21 */
22
23static void
24sparc_2(unsigned long bytes, unsigned long *p1, unsigned long *p2)
25{
26 int lines = bytes / (sizeof (long)) / 8;
27
28 do {
29 __asm__ __volatile__(
30 "ldd [%0 + 0x00], %%g2\n\t"
31 "ldd [%0 + 0x08], %%g4\n\t"
32 "ldd [%0 + 0x10], %%o0\n\t"
33 "ldd [%0 + 0x18], %%o2\n\t"
34 "ldd [%1 + 0x00], %%o4\n\t"
35 "ldd [%1 + 0x08], %%l0\n\t"
36 "ldd [%1 + 0x10], %%l2\n\t"
37 "ldd [%1 + 0x18], %%l4\n\t"
38 "xor %%g2, %%o4, %%g2\n\t"
39 "xor %%g3, %%o5, %%g3\n\t"
40 "xor %%g4, %%l0, %%g4\n\t"
41 "xor %%g5, %%l1, %%g5\n\t"
42 "xor %%o0, %%l2, %%o0\n\t"
43 "xor %%o1, %%l3, %%o1\n\t"
44 "xor %%o2, %%l4, %%o2\n\t"
45 "xor %%o3, %%l5, %%o3\n\t"
46 "std %%g2, [%0 + 0x00]\n\t"
47 "std %%g4, [%0 + 0x08]\n\t"
48 "std %%o0, [%0 + 0x10]\n\t"
49 "std %%o2, [%0 + 0x18]\n"
50 :
51 : "r" (p1), "r" (p2)
52 : "g2", "g3", "g4", "g5",
53 "o0", "o1", "o2", "o3", "o4", "o5",
54 "l0", "l1", "l2", "l3", "l4", "l5");
55 p1 += 8;
56 p2 += 8;
57 } while (--lines > 0);
58}
59
60static void
61sparc_3(unsigned long bytes, unsigned long *p1, unsigned long *p2,
62 unsigned long *p3)
63{
64 int lines = bytes / (sizeof (long)) / 8;
65
66 do {
67 __asm__ __volatile__(
68 "ldd [%0 + 0x00], %%g2\n\t"
69 "ldd [%0 + 0x08], %%g4\n\t"
70 "ldd [%0 + 0x10], %%o0\n\t"
71 "ldd [%0 + 0x18], %%o2\n\t"
72 "ldd [%1 + 0x00], %%o4\n\t"
73 "ldd [%1 + 0x08], %%l0\n\t"
74 "ldd [%1 + 0x10], %%l2\n\t"
75 "ldd [%1 + 0x18], %%l4\n\t"
76 "xor %%g2, %%o4, %%g2\n\t"
77 "xor %%g3, %%o5, %%g3\n\t"
78 "ldd [%2 + 0x00], %%o4\n\t"
79 "xor %%g4, %%l0, %%g4\n\t"
80 "xor %%g5, %%l1, %%g5\n\t"
81 "ldd [%2 + 0x08], %%l0\n\t"
82 "xor %%o0, %%l2, %%o0\n\t"
83 "xor %%o1, %%l3, %%o1\n\t"
84 "ldd [%2 + 0x10], %%l2\n\t"
85 "xor %%o2, %%l4, %%o2\n\t"
86 "xor %%o3, %%l5, %%o3\n\t"
87 "ldd [%2 + 0x18], %%l4\n\t"
88 "xor %%g2, %%o4, %%g2\n\t"
89 "xor %%g3, %%o5, %%g3\n\t"
90 "xor %%g4, %%l0, %%g4\n\t"
91 "xor %%g5, %%l1, %%g5\n\t"
92 "xor %%o0, %%l2, %%o0\n\t"
93 "xor %%o1, %%l3, %%o1\n\t"
94 "xor %%o2, %%l4, %%o2\n\t"
95 "xor %%o3, %%l5, %%o3\n\t"
96 "std %%g2, [%0 + 0x00]\n\t"
97 "std %%g4, [%0 + 0x08]\n\t"
98 "std %%o0, [%0 + 0x10]\n\t"
99 "std %%o2, [%0 + 0x18]\n"
100 :
101 : "r" (p1), "r" (p2), "r" (p3)
102 : "g2", "g3", "g4", "g5",
103 "o0", "o1", "o2", "o3", "o4", "o5",
104 "l0", "l1", "l2", "l3", "l4", "l5");
105 p1 += 8;
106 p2 += 8;
107 p3 += 8;
108 } while (--lines > 0);
109}
110
111static void
112sparc_4(unsigned long bytes, unsigned long *p1, unsigned long *p2,
113 unsigned long *p3, unsigned long *p4)
114{
115 int lines = bytes / (sizeof (long)) / 8;
116
117 do {
118 __asm__ __volatile__(
119 "ldd [%0 + 0x00], %%g2\n\t"
120 "ldd [%0 + 0x08], %%g4\n\t"
121 "ldd [%0 + 0x10], %%o0\n\t"
122 "ldd [%0 + 0x18], %%o2\n\t"
123 "ldd [%1 + 0x00], %%o4\n\t"
124 "ldd [%1 + 0x08], %%l0\n\t"
125 "ldd [%1 + 0x10], %%l2\n\t"
126 "ldd [%1 + 0x18], %%l4\n\t"
127 "xor %%g2, %%o4, %%g2\n\t"
128 "xor %%g3, %%o5, %%g3\n\t"
129 "ldd [%2 + 0x00], %%o4\n\t"
130 "xor %%g4, %%l0, %%g4\n\t"
131 "xor %%g5, %%l1, %%g5\n\t"
132 "ldd [%2 + 0x08], %%l0\n\t"
133 "xor %%o0, %%l2, %%o0\n\t"
134 "xor %%o1, %%l3, %%o1\n\t"
135 "ldd [%2 + 0x10], %%l2\n\t"
136 "xor %%o2, %%l4, %%o2\n\t"
137 "xor %%o3, %%l5, %%o3\n\t"
138 "ldd [%2 + 0x18], %%l4\n\t"
139 "xor %%g2, %%o4, %%g2\n\t"
140 "xor %%g3, %%o5, %%g3\n\t"
141 "ldd [%3 + 0x00], %%o4\n\t"
142 "xor %%g4, %%l0, %%g4\n\t"
143 "xor %%g5, %%l1, %%g5\n\t"
144 "ldd [%3 + 0x08], %%l0\n\t"
145 "xor %%o0, %%l2, %%o0\n\t"
146 "xor %%o1, %%l3, %%o1\n\t"
147 "ldd [%3 + 0x10], %%l2\n\t"
148 "xor %%o2, %%l4, %%o2\n\t"
149 "xor %%o3, %%l5, %%o3\n\t"
150 "ldd [%3 + 0x18], %%l4\n\t"
151 "xor %%g2, %%o4, %%g2\n\t"
152 "xor %%g3, %%o5, %%g3\n\t"
153 "xor %%g4, %%l0, %%g4\n\t"
154 "xor %%g5, %%l1, %%g5\n\t"
155 "xor %%o0, %%l2, %%o0\n\t"
156 "xor %%o1, %%l3, %%o1\n\t"
157 "xor %%o2, %%l4, %%o2\n\t"
158 "xor %%o3, %%l5, %%o3\n\t"
159 "std %%g2, [%0 + 0x00]\n\t"
160 "std %%g4, [%0 + 0x08]\n\t"
161 "std %%o0, [%0 + 0x10]\n\t"
162 "std %%o2, [%0 + 0x18]\n"
163 :
164 : "r" (p1), "r" (p2), "r" (p3), "r" (p4)
165 : "g2", "g3", "g4", "g5",
166 "o0", "o1", "o2", "o3", "o4", "o5",
167 "l0", "l1", "l2", "l3", "l4", "l5");
168 p1 += 8;
169 p2 += 8;
170 p3 += 8;
171 p4 += 8;
172 } while (--lines > 0);
173}
174
175static void
176sparc_5(unsigned long bytes, unsigned long *p1, unsigned long *p2,
177 unsigned long *p3, unsigned long *p4, unsigned long *p5)
178{
179 int lines = bytes / (sizeof (long)) / 8;
180
181 do {
182 __asm__ __volatile__(
183 "ldd [%0 + 0x00], %%g2\n\t"
184 "ldd [%0 + 0x08], %%g4\n\t"
185 "ldd [%0 + 0x10], %%o0\n\t"
186 "ldd [%0 + 0x18], %%o2\n\t"
187 "ldd [%1 + 0x00], %%o4\n\t"
188 "ldd [%1 + 0x08], %%l0\n\t"
189 "ldd [%1 + 0x10], %%l2\n\t"
190 "ldd [%1 + 0x18], %%l4\n\t"
191 "xor %%g2, %%o4, %%g2\n\t"
192 "xor %%g3, %%o5, %%g3\n\t"
193 "ldd [%2 + 0x00], %%o4\n\t"
194 "xor %%g4, %%l0, %%g4\n\t"
195 "xor %%g5, %%l1, %%g5\n\t"
196 "ldd [%2 + 0x08], %%l0\n\t"
197 "xor %%o0, %%l2, %%o0\n\t"
198 "xor %%o1, %%l3, %%o1\n\t"
199 "ldd [%2 + 0x10], %%l2\n\t"
200 "xor %%o2, %%l4, %%o2\n\t"
201 "xor %%o3, %%l5, %%o3\n\t"
202 "ldd [%2 + 0x18], %%l4\n\t"
203 "xor %%g2, %%o4, %%g2\n\t"
204 "xor %%g3, %%o5, %%g3\n\t"
205 "ldd [%3 + 0x00], %%o4\n\t"
206 "xor %%g4, %%l0, %%g4\n\t"
207 "xor %%g5, %%l1, %%g5\n\t"
208 "ldd [%3 + 0x08], %%l0\n\t"
209 "xor %%o0, %%l2, %%o0\n\t"
210 "xor %%o1, %%l3, %%o1\n\t"
211 "ldd [%3 + 0x10], %%l2\n\t"
212 "xor %%o2, %%l4, %%o2\n\t"
213 "xor %%o3, %%l5, %%o3\n\t"
214 "ldd [%3 + 0x18], %%l4\n\t"
215 "xor %%g2, %%o4, %%g2\n\t"
216 "xor %%g3, %%o5, %%g3\n\t"
217 "ldd [%4 + 0x00], %%o4\n\t"
218 "xor %%g4, %%l0, %%g4\n\t"
219 "xor %%g5, %%l1, %%g5\n\t"
220 "ldd [%4 + 0x08], %%l0\n\t"
221 "xor %%o0, %%l2, %%o0\n\t"
222 "xor %%o1, %%l3, %%o1\n\t"
223 "ldd [%4 + 0x10], %%l2\n\t"
224 "xor %%o2, %%l4, %%o2\n\t"
225 "xor %%o3, %%l5, %%o3\n\t"
226 "ldd [%4 + 0x18], %%l4\n\t"
227 "xor %%g2, %%o4, %%g2\n\t"
228 "xor %%g3, %%o5, %%g3\n\t"
229 "xor %%g4, %%l0, %%g4\n\t"
230 "xor %%g5, %%l1, %%g5\n\t"
231 "xor %%o0, %%l2, %%o0\n\t"
232 "xor %%o1, %%l3, %%o1\n\t"
233 "xor %%o2, %%l4, %%o2\n\t"
234 "xor %%o3, %%l5, %%o3\n\t"
235 "std %%g2, [%0 + 0x00]\n\t"
236 "std %%g4, [%0 + 0x08]\n\t"
237 "std %%o0, [%0 + 0x10]\n\t"
238 "std %%o2, [%0 + 0x18]\n"
239 :
240 : "r" (p1), "r" (p2), "r" (p3), "r" (p4), "r" (p5)
241 : "g2", "g3", "g4", "g5",
242 "o0", "o1", "o2", "o3", "o4", "o5",
243 "l0", "l1", "l2", "l3", "l4", "l5");
244 p1 += 8;
245 p2 += 8;
246 p3 += 8;
247 p4 += 8;
248 p5 += 8;
249 } while (--lines > 0);
250}
251
252static struct xor_block_template xor_block_SPARC = {
253 .name = "SPARC",
254 .do_2 = sparc_2,
255 .do_3 = sparc_3,
256 .do_4 = sparc_4,
257 .do_5 = sparc_5,
258};
259
260/* For grins, also test the generic routines. */
261#include <asm-generic/xor.h>
262
263#undef XOR_TRY_TEMPLATES
264#define XOR_TRY_TEMPLATES \
265 do { \
266 xor_speed(&xor_block_8regs); \
267 xor_speed(&xor_block_32regs); \
268 xor_speed(&xor_block_SPARC); \
269 } while (0)
diff --git a/include/asm-sparc/xor_64.h b/include/asm-sparc/xor_64.h
new file mode 100644
index 000000000000..a0233884fc94
--- /dev/null
+++ b/include/asm-sparc/xor_64.h
@@ -0,0 +1,70 @@
1/*
2 * include/asm-sparc64/xor.h
3 *
4 * High speed xor_block operation for RAID4/5 utilizing the
5 * UltraSparc Visual Instruction Set and Niagara block-init
6 * twin-load instructions.
7 *
8 * Copyright (C) 1997, 1999 Jakub Jelinek (jj@ultra.linux.cz)
9 * Copyright (C) 2006 David S. Miller <davem@davemloft.net>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * You should have received a copy of the GNU General Public License
17 * (for example /usr/src/linux/COPYING); if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <asm/spitfire.h>
22
23extern void xor_vis_2(unsigned long, unsigned long *, unsigned long *);
24extern void xor_vis_3(unsigned long, unsigned long *, unsigned long *,
25 unsigned long *);
26extern void xor_vis_4(unsigned long, unsigned long *, unsigned long *,
27 unsigned long *, unsigned long *);
28extern void xor_vis_5(unsigned long, unsigned long *, unsigned long *,
29 unsigned long *, unsigned long *, unsigned long *);
30
31/* XXX Ugh, write cheetah versions... -DaveM */
32
33static struct xor_block_template xor_block_VIS = {
34 .name = "VIS",
35 .do_2 = xor_vis_2,
36 .do_3 = xor_vis_3,
37 .do_4 = xor_vis_4,
38 .do_5 = xor_vis_5,
39};
40
41extern void xor_niagara_2(unsigned long, unsigned long *, unsigned long *);
42extern void xor_niagara_3(unsigned long, unsigned long *, unsigned long *,
43 unsigned long *);
44extern void xor_niagara_4(unsigned long, unsigned long *, unsigned long *,
45 unsigned long *, unsigned long *);
46extern void xor_niagara_5(unsigned long, unsigned long *, unsigned long *,
47 unsigned long *, unsigned long *, unsigned long *);
48
49static struct xor_block_template xor_block_niagara = {
50 .name = "Niagara",
51 .do_2 = xor_niagara_2,
52 .do_3 = xor_niagara_3,
53 .do_4 = xor_niagara_4,
54 .do_5 = xor_niagara_5,
55};
56
57#undef XOR_TRY_TEMPLATES
58#define XOR_TRY_TEMPLATES \
59 do { \
60 xor_speed(&xor_block_VIS); \
61 xor_speed(&xor_block_niagara); \
62 } while (0)
63
64/* For VIS for everything except Niagara. */
65#define XOR_SELECT_TEMPLATE(FASTEST) \
66 ((tlb_type == hypervisor && \
67 (sun4v_chip_type == SUN4V_CHIP_NIAGARA1 || \
68 sun4v_chip_type == SUN4V_CHIP_NIAGARA2)) ? \
69 &xor_block_niagara : \
70 &xor_block_VIS)
diff --git a/include/asm-sparc64/Kbuild b/include/asm-sparc64/Kbuild
index dce1cf9a9313..6cdaf9d33b38 100644
--- a/include/asm-sparc64/Kbuild
+++ b/include/asm-sparc64/Kbuild
@@ -1,23 +1 @@
1include include/asm-generic/Kbuild.asm # dummy file to avoid breaking make headers_install
2
3ALTARCH := sparc
4ARCHDEF := defined __sparc__ && defined __arch64__
5ALTARCHDEF := defined __sparc__ && !defined __arch64__
6
7header-y += apb.h
8header-y += asi.h
9header-y += bbc.h
10header-y += bpp.h
11header-y += display7seg.h
12header-y += envctrl.h
13header-y += openprom.h
14header-y += openpromio.h
15header-y += psrcompat.h
16header-y += pstate.h
17header-y += reg.h
18header-y += uctx.h
19header-y += utrap.h
20header-y += watchdog.h
21
22unifdef-y += fbio.h
23unifdef-y += perfctr.h
diff --git a/include/asm-sparc64/agp.h b/include/asm-sparc64/agp.h
index e9fcf0e781ea..eb8d4b3f5163 100644
--- a/include/asm-sparc64/agp.h
+++ b/include/asm-sparc64/agp.h
@@ -1,20 +1 @@
1#ifndef AGP_H #include <asm-sparc/agp.h>
2#define AGP_H 1
3
4/* dummy for now */
5
6#define map_page_into_agp(page)
7#define unmap_page_from_agp(page)
8#define flush_agp_cache() mb()
9
10/* Convert a physical address to an address suitable for the GART. */
11#define phys_to_gart(x) (x)
12#define gart_to_phys(x) (x)
13
14/* GATT allocation. Returns/accepts GATT kernel virtual address. */
15#define alloc_gatt_pages(order) \
16 ((char *)__get_free_pages(GFP_KERNEL, (order)))
17#define free_gatt_pages(table, order) \
18 free_pages((unsigned long)(table), (order))
19
20#endif
diff --git a/include/asm-sparc64/apb.h b/include/asm-sparc64/apb.h
index 8f3b57db810f..5e236ca6e492 100644
--- a/include/asm-sparc64/apb.h
+++ b/include/asm-sparc64/apb.h
@@ -1,36 +1 @@
1/* #include <asm-sparc/apb.h>
2 * apb.h: Advanced PCI Bridge Configuration Registers and Bits
3 *
4 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
5 */
6
7#ifndef _SPARC64_APB_H
8#define _SPARC64_APB_H
9
10#define APB_TICK_REGISTER 0xb0
11#define APB_INT_ACK 0xb8
12#define APB_PRIMARY_MASTER_RETRY_LIMIT 0xc0
13#define APB_DMA_ASFR 0xc8
14#define APB_DMA_AFAR 0xd0
15#define APB_PIO_TARGET_RETRY_LIMIT 0xd8
16#define APB_PIO_TARGET_LATENCY_TIMER 0xd9
17#define APB_DMA_TARGET_RETRY_LIMIT 0xda
18#define APB_DMA_TARGET_LATENCY_TIMER 0xdb
19#define APB_SECONDARY_MASTER_RETRY_LIMIT 0xdc
20#define APB_SECONDARY_CONTROL 0xdd
21#define APB_IO_ADDRESS_MAP 0xde
22#define APB_MEM_ADDRESS_MAP 0xdf
23
24#define APB_PCI_CONTROL_LOW 0xe0
25# define APB_PCI_CTL_LOW_ARB_PARK (1 << 21)
26# define APB_PCI_CTL_LOW_ERRINT_EN (1 << 8)
27
28#define APB_PCI_CONTROL_HIGH 0xe4
29# define APB_PCI_CTL_HIGH_SERR (1 << 2)
30# define APB_PCI_CTL_HIGH_ARBITER_EN (1 << 0)
31
32#define APB_PIO_ASFR 0xe8
33#define APB_PIO_AFAR 0xf0
34#define APB_DIAG_REGISTER 0xf8
35
36#endif /* !(_SPARC64_APB_H) */
diff --git a/include/asm-sparc64/asi.h b/include/asm-sparc64/asi.h
index bc57c405e7d3..9b7110c516e8 100644
--- a/include/asm-sparc64/asi.h
+++ b/include/asm-sparc64/asi.h
@@ -1,160 +1 @@
1#ifndef _SPARC64_ASI_H #include <asm-sparc/asi.h>
2#define _SPARC64_ASI_H
3
4/* asi.h: Address Space Identifier values for the V9.
5 *
6 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
7 */
8
9/* V9 Architecture mandary ASIs. */
10#define ASI_N 0x04 /* Nucleus */
11#define ASI_NL 0x0c /* Nucleus, little endian */
12#define ASI_AIUP 0x10 /* Primary, user */
13#define ASI_AIUS 0x11 /* Secondary, user */
14#define ASI_AIUPL 0x18 /* Primary, user, little endian */
15#define ASI_AIUSL 0x19 /* Secondary, user, little endian */
16#define ASI_P 0x80 /* Primary, implicit */
17#define ASI_S 0x81 /* Secondary, implicit */
18#define ASI_PNF 0x82 /* Primary, no fault */
19#define ASI_SNF 0x83 /* Secondary, no fault */
20#define ASI_PL 0x88 /* Primary, implicit, l-endian */
21#define ASI_SL 0x89 /* Secondary, implicit, l-endian */
22#define ASI_PNFL 0x8a /* Primary, no fault, l-endian */
23#define ASI_SNFL 0x8b /* Secondary, no fault, l-endian */
24
25/* SpitFire and later extended ASIs. The "(III)" marker designates
26 * UltraSparc-III and later specific ASIs. The "(CMT)" marker designates
27 * Chip Multi Threading specific ASIs. "(NG)" designates Niagara specific
28 * ASIs, "(4V)" designates SUN4V specific ASIs.
29 */
30#define ASI_PHYS_USE_EC 0x14 /* PADDR, E-cachable */
31#define ASI_PHYS_BYPASS_EC_E 0x15 /* PADDR, E-bit */
32#define ASI_BLK_AIUP_4V 0x16 /* (4V) Prim, user, block ld/st */
33#define ASI_BLK_AIUS_4V 0x17 /* (4V) Sec, user, block ld/st */
34#define ASI_PHYS_USE_EC_L 0x1c /* PADDR, E-cachable, little endian*/
35#define ASI_PHYS_BYPASS_EC_E_L 0x1d /* PADDR, E-bit, little endian */
36#define ASI_BLK_AIUP_L_4V 0x1e /* (4V) Prim, user, block, l-endian*/
37#define ASI_BLK_AIUS_L_4V 0x1f /* (4V) Sec, user, block, l-endian */
38#define ASI_SCRATCHPAD 0x20 /* (4V) Scratch Pad Registers */
39#define ASI_MMU 0x21 /* (4V) MMU Context Registers */
40#define ASI_BLK_INIT_QUAD_LDD_AIUS 0x23 /* (NG) init-store, twin load,
41 * secondary, user
42 */
43#define ASI_NUCLEUS_QUAD_LDD 0x24 /* Cachable, qword load */
44#define ASI_QUEUE 0x25 /* (4V) Interrupt Queue Registers */
45#define ASI_QUAD_LDD_PHYS_4V 0x26 /* (4V) Physical, qword load */
46#define ASI_NUCLEUS_QUAD_LDD_L 0x2c /* Cachable, qword load, l-endian */
47#define ASI_QUAD_LDD_PHYS_L_4V 0x2e /* (4V) Phys, qword load, l-endian */
48#define ASI_PCACHE_DATA_STATUS 0x30 /* (III) PCache data stat RAM diag */
49#define ASI_PCACHE_DATA 0x31 /* (III) PCache data RAM diag */
50#define ASI_PCACHE_TAG 0x32 /* (III) PCache tag RAM diag */
51#define ASI_PCACHE_SNOOP_TAG 0x33 /* (III) PCache snoop tag RAM diag */
52#define ASI_QUAD_LDD_PHYS 0x34 /* (III+) PADDR, qword load */
53#define ASI_WCACHE_VALID_BITS 0x38 /* (III) WCache Valid Bits diag */
54#define ASI_WCACHE_DATA 0x39 /* (III) WCache data RAM diag */
55#define ASI_WCACHE_TAG 0x3a /* (III) WCache tag RAM diag */
56#define ASI_WCACHE_SNOOP_TAG 0x3b /* (III) WCache snoop tag RAM diag */
57#define ASI_QUAD_LDD_PHYS_L 0x3c /* (III+) PADDR, qw-load, l-endian */
58#define ASI_SRAM_FAST_INIT 0x40 /* (III+) Fast SRAM init */
59#define ASI_CORE_AVAILABLE 0x41 /* (CMT) LP Available */
60#define ASI_CORE_ENABLE_STAT 0x41 /* (CMT) LP Enable Status */
61#define ASI_CORE_ENABLE 0x41 /* (CMT) LP Enable RW */
62#define ASI_XIR_STEERING 0x41 /* (CMT) XIR Steering RW */
63#define ASI_CORE_RUNNING_RW 0x41 /* (CMT) LP Running RW */
64#define ASI_CORE_RUNNING_W1S 0x41 /* (CMT) LP Running Write-One Set */
65#define ASI_CORE_RUNNING_W1C 0x41 /* (CMT) LP Running Write-One Clr */
66#define ASI_CORE_RUNNING_STAT 0x41 /* (CMT) LP Running Status */
67#define ASI_CMT_ERROR_STEERING 0x41 /* (CMT) Error Steering RW */
68#define ASI_DCACHE_INVALIDATE 0x42 /* (III) DCache Invalidate diag */
69#define ASI_DCACHE_UTAG 0x43 /* (III) DCache uTag diag */
70#define ASI_DCACHE_SNOOP_TAG 0x44 /* (III) DCache snoop tag RAM diag */
71#define ASI_LSU_CONTROL 0x45 /* Load-store control unit */
72#define ASI_DCU_CONTROL_REG 0x45 /* (III) DCache Unit Control reg */
73#define ASI_DCACHE_DATA 0x46 /* DCache data-ram diag access */
74#define ASI_DCACHE_TAG 0x47 /* Dcache tag/valid ram diag access*/
75#define ASI_INTR_DISPATCH_STAT 0x48 /* IRQ vector dispatch status */
76#define ASI_INTR_RECEIVE 0x49 /* IRQ vector receive status */
77#define ASI_UPA_CONFIG 0x4a /* UPA config space */
78#define ASI_JBUS_CONFIG 0x4a /* (IIIi) JBUS Config Register */
79#define ASI_SAFARI_CONFIG 0x4a /* (III) Safari Config Register */
80#define ASI_SAFARI_ADDRESS 0x4a /* (III) Safari Address Register */
81#define ASI_ESTATE_ERROR_EN 0x4b /* E-cache error enable space */
82#define ASI_AFSR 0x4c /* Async fault status register */
83#define ASI_AFAR 0x4d /* Async fault address register */
84#define ASI_EC_TAG_DATA 0x4e /* E-cache tag/valid ram diag acc */
85#define ASI_IMMU 0x50 /* Insn-MMU main register space */
86#define ASI_IMMU_TSB_8KB_PTR 0x51 /* Insn-MMU 8KB TSB pointer reg */
87#define ASI_IMMU_TSB_64KB_PTR 0x52 /* Insn-MMU 64KB TSB pointer reg */
88#define ASI_ITLB_DATA_IN 0x54 /* Insn-MMU TLB data in reg */
89#define ASI_ITLB_DATA_ACCESS 0x55 /* Insn-MMU TLB data access reg */
90#define ASI_ITLB_TAG_READ 0x56 /* Insn-MMU TLB tag read reg */
91#define ASI_IMMU_DEMAP 0x57 /* Insn-MMU TLB demap */
92#define ASI_DMMU 0x58 /* Data-MMU main register space */
93#define ASI_DMMU_TSB_8KB_PTR 0x59 /* Data-MMU 8KB TSB pointer reg */
94#define ASI_DMMU_TSB_64KB_PTR 0x5a /* Data-MMU 16KB TSB pointer reg */
95#define ASI_DMMU_TSB_DIRECT_PTR 0x5b /* Data-MMU TSB direct pointer reg */
96#define ASI_DTLB_DATA_IN 0x5c /* Data-MMU TLB data in reg */
97#define ASI_DTLB_DATA_ACCESS 0x5d /* Data-MMU TLB data access reg */
98#define ASI_DTLB_TAG_READ 0x5e /* Data-MMU TLB tag read reg */
99#define ASI_DMMU_DEMAP 0x5f /* Data-MMU TLB demap */
100#define ASI_IIU_INST_TRAP 0x60 /* (III) Instruction Breakpoint */
101#define ASI_INTR_ID 0x63 /* (CMT) Interrupt ID register */
102#define ASI_CORE_ID 0x63 /* (CMT) LP ID register */
103#define ASI_CESR_ID 0x63 /* (CMT) CESR ID register */
104#define ASI_IC_INSTR 0x66 /* Insn cache instrucion ram diag */
105#define ASI_IC_TAG 0x67 /* Insn cache tag/valid ram diag */
106#define ASI_IC_STAG 0x68 /* (III) Insn cache snoop tag ram */
107#define ASI_IC_PRE_DECODE 0x6e /* Insn cache pre-decode ram diag */
108#define ASI_IC_NEXT_FIELD 0x6f /* Insn cache next-field ram diag */
109#define ASI_BRPRED_ARRAY 0x6f /* (III) Branch Prediction RAM diag*/
110#define ASI_BLK_AIUP 0x70 /* Primary, user, block load/store */
111#define ASI_BLK_AIUS 0x71 /* Secondary, user, block ld/st */
112#define ASI_MCU_CTRL_REG 0x72 /* (III) Memory controller regs */
113#define ASI_EC_DATA 0x74 /* (III) E-cache data staging reg */
114#define ASI_EC_CTRL 0x75 /* (III) E-cache control reg */
115#define ASI_EC_W 0x76 /* E-cache diag write access */
116#define ASI_UDB_ERROR_W 0x77 /* External UDB error regs W */
117#define ASI_UDB_CONTROL_W 0x77 /* External UDB control regs W */
118#define ASI_INTR_W 0x77 /* IRQ vector dispatch write */
119#define ASI_INTR_DATAN_W 0x77 /* (III) Out irq vector data reg N */
120#define ASI_INTR_DISPATCH_W 0x77 /* (III) Interrupt vector dispatch */
121#define ASI_BLK_AIUPL 0x78 /* Primary, user, little, blk ld/st*/
122#define ASI_BLK_AIUSL 0x79 /* Secondary, user, little, blk ld/st*/
123#define ASI_EC_R 0x7e /* E-cache diag read access */
124#define ASI_UDBH_ERROR_R 0x7f /* External UDB error regs rd hi */
125#define ASI_UDBL_ERROR_R 0x7f /* External UDB error regs rd low */
126#define ASI_UDBH_CONTROL_R 0x7f /* External UDB control regs rd hi */
127#define ASI_UDBL_CONTROL_R 0x7f /* External UDB control regs rd low*/
128#define ASI_INTR_R 0x7f /* IRQ vector dispatch read */
129#define ASI_INTR_DATAN_R 0x7f /* (III) In irq vector data reg N */
130#define ASI_PST8_P 0xc0 /* Primary, 8 8-bit, partial */
131#define ASI_PST8_S 0xc1 /* Secondary, 8 8-bit, partial */
132#define ASI_PST16_P 0xc2 /* Primary, 4 16-bit, partial */
133#define ASI_PST16_S 0xc3 /* Secondary, 4 16-bit, partial */
134#define ASI_PST32_P 0xc4 /* Primary, 2 32-bit, partial */
135#define ASI_PST32_S 0xc5 /* Secondary, 2 32-bit, partial */
136#define ASI_PST8_PL 0xc8 /* Primary, 8 8-bit, partial, L */
137#define ASI_PST8_SL 0xc9 /* Secondary, 8 8-bit, partial, L */
138#define ASI_PST16_PL 0xca /* Primary, 4 16-bit, partial, L */
139#define ASI_PST16_SL 0xcb /* Secondary, 4 16-bit, partial, L */
140#define ASI_PST32_PL 0xcc /* Primary, 2 32-bit, partial, L */
141#define ASI_PST32_SL 0xcd /* Secondary, 2 32-bit, partial, L */
142#define ASI_FL8_P 0xd0 /* Primary, 1 8-bit, fpu ld/st */
143#define ASI_FL8_S 0xd1 /* Secondary, 1 8-bit, fpu ld/st */
144#define ASI_FL16_P 0xd2 /* Primary, 1 16-bit, fpu ld/st */
145#define ASI_FL16_S 0xd3 /* Secondary, 1 16-bit, fpu ld/st */
146#define ASI_FL8_PL 0xd8 /* Primary, 1 8-bit, fpu ld/st, L */
147#define ASI_FL8_SL 0xd9 /* Secondary, 1 8-bit, fpu ld/st, L*/
148#define ASI_FL16_PL 0xda /* Primary, 1 16-bit, fpu ld/st, L */
149#define ASI_FL16_SL 0xdb /* Secondary, 1 16-bit, fpu ld/st,L*/
150#define ASI_BLK_COMMIT_P 0xe0 /* Primary, blk store commit */
151#define ASI_BLK_COMMIT_S 0xe1 /* Secondary, blk store commit */
152#define ASI_BLK_INIT_QUAD_LDD_P 0xe2 /* (NG) init-store, twin load,
153 * primary, implicit
154 */
155#define ASI_BLK_P 0xf0 /* Primary, blk ld/st */
156#define ASI_BLK_S 0xf1 /* Secondary, blk ld/st */
157#define ASI_BLK_PL 0xf8 /* Primary, blk ld/st, little */
158#define ASI_BLK_SL 0xf9 /* Secondary, blk ld/st, little */
159
160#endif /* _SPARC64_ASI_H */
diff --git a/include/asm-sparc64/atomic.h b/include/asm-sparc64/atomic.h
index 2c71ec4a3b18..f5126826ba34 100644
--- a/include/asm-sparc64/atomic.h
+++ b/include/asm-sparc64/atomic.h
@@ -1,128 +1 @@
1/* atomic.h: Thankfully the V9 is at least reasonable for this #include <asm-sparc/atomic.h>
2 * stuff.
3 *
4 * Copyright (C) 1996, 1997, 2000 David S. Miller (davem@redhat.com)
5 */
6
7#ifndef __ARCH_SPARC64_ATOMIC__
8#define __ARCH_SPARC64_ATOMIC__
9
10#include <linux/types.h>
11#include <asm/system.h>
12
13typedef struct { volatile int counter; } atomic_t;
14typedef struct { volatile __s64 counter; } atomic64_t;
15
16#define ATOMIC_INIT(i) { (i) }
17#define ATOMIC64_INIT(i) { (i) }
18
19#define atomic_read(v) ((v)->counter)
20#define atomic64_read(v) ((v)->counter)
21
22#define atomic_set(v, i) (((v)->counter) = i)
23#define atomic64_set(v, i) (((v)->counter) = i)
24
25extern void atomic_add(int, atomic_t *);
26extern void atomic64_add(int, atomic64_t *);
27extern void atomic_sub(int, atomic_t *);
28extern void atomic64_sub(int, atomic64_t *);
29
30extern int atomic_add_ret(int, atomic_t *);
31extern int atomic64_add_ret(int, atomic64_t *);
32extern int atomic_sub_ret(int, atomic_t *);
33extern int atomic64_sub_ret(int, atomic64_t *);
34
35#define atomic_dec_return(v) atomic_sub_ret(1, v)
36#define atomic64_dec_return(v) atomic64_sub_ret(1, v)
37
38#define atomic_inc_return(v) atomic_add_ret(1, v)
39#define atomic64_inc_return(v) atomic64_add_ret(1, v)
40
41#define atomic_sub_return(i, v) atomic_sub_ret(i, v)
42#define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
43
44#define atomic_add_return(i, v) atomic_add_ret(i, v)
45#define atomic64_add_return(i, v) atomic64_add_ret(i, v)
46
47/*
48 * atomic_inc_and_test - increment and test
49 * @v: pointer of type atomic_t
50 *
51 * Atomically increments @v by 1
52 * and returns true if the result is zero, or false for all
53 * other cases.
54 */
55#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
56#define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
57
58#define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
59#define atomic64_sub_and_test(i, v) (atomic64_sub_ret(i, v) == 0)
60
61#define atomic_dec_and_test(v) (atomic_sub_ret(1, v) == 0)
62#define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
63
64#define atomic_inc(v) atomic_add(1, v)
65#define atomic64_inc(v) atomic64_add(1, v)
66
67#define atomic_dec(v) atomic_sub(1, v)
68#define atomic64_dec(v) atomic64_sub(1, v)
69
70#define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
71#define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
72
73#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
74#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
75
76static inline int atomic_add_unless(atomic_t *v, int a, int u)
77{
78 int c, old;
79 c = atomic_read(v);
80 for (;;) {
81 if (unlikely(c == (u)))
82 break;
83 old = atomic_cmpxchg((v), c, c + (a));
84 if (likely(old == c))
85 break;
86 c = old;
87 }
88 return c != (u);
89}
90
91#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
92
93#define atomic64_cmpxchg(v, o, n) \
94 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
95#define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
96
97static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
98{
99 long c, old;
100 c = atomic64_read(v);
101 for (;;) {
102 if (unlikely(c == (u)))
103 break;
104 old = atomic64_cmpxchg((v), c, c + (a));
105 if (likely(old == c))
106 break;
107 c = old;
108 }
109 return c != (u);
110}
111
112#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
113
114/* Atomic operations are already serializing */
115#ifdef CONFIG_SMP
116#define smp_mb__before_atomic_dec() membar_storeload_loadload();
117#define smp_mb__after_atomic_dec() membar_storeload_storestore();
118#define smp_mb__before_atomic_inc() membar_storeload_loadload();
119#define smp_mb__after_atomic_inc() membar_storeload_storestore();
120#else
121#define smp_mb__before_atomic_dec() barrier()
122#define smp_mb__after_atomic_dec() barrier()
123#define smp_mb__before_atomic_inc() barrier()
124#define smp_mb__after_atomic_inc() barrier()
125#endif
126
127#include <asm-generic/atomic.h>
128#endif /* !(__ARCH_SPARC64_ATOMIC__) */
diff --git a/include/asm-sparc64/auxio.h b/include/asm-sparc64/auxio.h
index c4100494c7a5..46c9042f30b4 100644
--- a/include/asm-sparc64/auxio.h
+++ b/include/asm-sparc64/auxio.h
@@ -1,100 +1 @@
1/* #include <asm-sparc/auxio.h>
2 * auxio.h: Definitions and code for the Auxiliary I/O registers.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 *
6 * Refactoring for unified NCR/PCIO support 2002 Eric Brower (ebrower@usa.net)
7 */
8#ifndef _SPARC64_AUXIO_H
9#define _SPARC64_AUXIO_H
10
11/* AUXIO implementations:
12 * sbus-based NCR89C105 "Slavio"
13 * LED/Floppy (AUX1) register
14 * Power (AUX2) register
15 *
16 * ebus-based auxio on PCIO
17 * LED Auxio Register
18 * Power Auxio Register
19 *
20 * Register definitions from NCR _NCR89C105 Chip Specification_
21 *
22 * SLAVIO AUX1 @ 0x1900000
23 * -------------------------------------------------
24 * | (R) | (R) | D | (R) | E | M | T | L |
25 * -------------------------------------------------
26 * (R) - bit 7:6,4 are reserved and should be masked in s/w
27 * D - Floppy Density Sense (1=high density) R/O
28 * E - Link Test Enable, directly reflected on AT&T 7213 LTE pin
29 * M - Monitor/Mouse Mux, directly reflected on MON_MSE_MUX pin
30 * T - Terminal Count: sends TC pulse to 82077 floppy controller
31 * L - System LED on front panel (0=off, 1=on)
32 */
33#define AUXIO_AUX1_MASK 0xc0 /* Mask bits */
34#define AUXIO_AUX1_FDENS 0x20 /* Floppy Density Sense */
35#define AUXIO_AUX1_LTE 0x08 /* Link Test Enable */
36#define AUXIO_AUX1_MMUX 0x04 /* Monitor/Mouse Mux */
37#define AUXIO_AUX1_FTCNT 0x02 /* Terminal Count, */
38#define AUXIO_AUX1_LED 0x01 /* System LED */
39
40/* SLAVIO AUX2 @ 0x1910000
41 * -------------------------------------------------
42 * | (R) | (R) | D | (R) | (R) | (R) | C | F |
43 * -------------------------------------------------
44 * (R) - bits 7:6,4:2 are reserved and should be masked in s/w
45 * D - Power Failure Detect (1=power fail)
46 * C - Clear Power Failure Detect Int (1=clear)
47 * F - Power Off (1=power off)
48 */
49#define AUXIO_AUX2_MASK 0xdc /* Mask Bits */
50#define AUXIO_AUX2_PFAILDET 0x20 /* Power Fail Detect */
51#define AUXIO_AUX2_PFAILCLR 0x02 /* Clear Pwr Fail Det Intr */
52#define AUXIO_AUX2_PWR_OFF 0x01 /* Power Off */
53
54/* Register definitions from Sun Microsystems _PCIO_ p/n 802-7837
55 *
56 * PCIO LED Auxio @ 0x726000
57 * -------------------------------------------------
58 * | 31:1 Unused | LED |
59 * -------------------------------------------------
60 * Bits 31:1 unused
61 * LED - System LED on front panel (0=off, 1=on)
62 */
63#define AUXIO_PCIO_LED 0x01 /* System LED */
64
65/* PCIO Power Auxio @ 0x724000
66 * -------------------------------------------------
67 * | 31:2 Unused | CPO | SPO |
68 * -------------------------------------------------
69 * Bits 31:2 unused
70 * CPO - Courtesy Power Off (1=off)
71 * SPO - System Power Off (1=off)
72 */
73#define AUXIO_PCIO_CPWR_OFF 0x02 /* Courtesy Power Off */
74#define AUXIO_PCIO_SPWR_OFF 0x01 /* System Power Off */
75
76#ifndef __ASSEMBLY__
77
78extern void __iomem *auxio_register;
79
80#define AUXIO_LTE_ON 1
81#define AUXIO_LTE_OFF 0
82
83/* auxio_set_lte - Set Link Test Enable (TPE Link Detect)
84 *
85 * on - AUXIO_LTE_ON or AUXIO_LTE_OFF
86 */
87extern void auxio_set_lte(int on);
88
89#define AUXIO_LED_ON 1
90#define AUXIO_LED_OFF 0
91
92/* auxio_set_led - Set system front panel LED
93 *
94 * on - AUXIO_LED_ON or AUXIO_LED_OFF
95 */
96extern void auxio_set_led(int on);
97
98#endif /* ifndef __ASSEMBLY__ */
99
100#endif /* !(_SPARC64_AUXIO_H) */
diff --git a/include/asm-sparc64/backoff.h b/include/asm-sparc64/backoff.h
index fa1fdf67e350..8ee26d947e0e 100644
--- a/include/asm-sparc64/backoff.h
+++ b/include/asm-sparc64/backoff.h
@@ -1,31 +1 @@
1#ifndef _SPARC64_BACKOFF_H #include <asm-sparc/backoff.h>
2#define _SPARC64_BACKOFF_H
3
4#define BACKOFF_LIMIT (4 * 1024)
5
6#ifdef CONFIG_SMP
7
8#define BACKOFF_SETUP(reg) \
9 mov 1, reg
10
11#define BACKOFF_SPIN(reg, tmp, label) \
12 mov reg, tmp; \
1388: brnz,pt tmp, 88b; \
14 sub tmp, 1, tmp; \
15 set BACKOFF_LIMIT, tmp; \
16 cmp reg, tmp; \
17 bg,pn %xcc, label; \
18 nop; \
19 ba,pt %xcc, label; \
20 sllx reg, 1, reg;
21
22#else
23
24#define BACKOFF_SETUP(reg)
25#define BACKOFF_SPIN(reg, tmp, label) \
26 ba,pt %xcc, label; \
27 nop;
28
29#endif
30
31#endif /* _SPARC64_BACKOFF_H */
diff --git a/include/asm-sparc64/bbc.h b/include/asm-sparc64/bbc.h
index 423a85800aae..06e8b6306514 100644
--- a/include/asm-sparc64/bbc.h
+++ b/include/asm-sparc64/bbc.h
@@ -1,225 +1 @@
1/* #include <asm-sparc/bbc.h>
2 * bbc.h: Defines for BootBus Controller found on UltraSPARC-III
3 * systems.
4 *
5 * Copyright (C) 2000 David S. Miller (davem@redhat.com)
6 */
7
8#ifndef _SPARC64_BBC_H
9#define _SPARC64_BBC_H
10
11/* Register sizes are indicated by "B" (Byte, 1-byte),
12 * "H" (Half-word, 2 bytes), "W" (Word, 4 bytes) or
13 * "Q" (Quad, 8 bytes) inside brackets.
14 */
15
16#define BBC_AID 0x00 /* [B] Agent ID */
17#define BBC_DEVP 0x01 /* [B] Device Present */
18#define BBC_ARB 0x02 /* [B] Arbitration */
19#define BBC_QUIESCE 0x03 /* [B] Quiesce */
20#define BBC_WDACTION 0x04 /* [B] Watchdog Action */
21#define BBC_SPG 0x06 /* [B] Soft POR Gen */
22#define BBC_SXG 0x07 /* [B] Soft XIR Gen */
23#define BBC_PSRC 0x08 /* [W] POR Source */
24#define BBC_XSRC 0x0c /* [B] XIR Source */
25#define BBC_CSC 0x0d /* [B] Clock Synthesizers Control*/
26#define BBC_ES_CTRL 0x0e /* [H] Energy Star Control */
27#define BBC_ES_ACT 0x10 /* [W] E* Assert Change Time */
28#define BBC_ES_DACT 0x14 /* [B] E* De-Assert Change Time */
29#define BBC_ES_DABT 0x15 /* [B] E* De-Assert Bypass Time */
30#define BBC_ES_ABT 0x16 /* [H] E* Assert Bypass Time */
31#define BBC_ES_PST 0x18 /* [W] E* PLL Settle Time */
32#define BBC_ES_FSL 0x1c /* [W] E* Frequency Switch Latency*/
33#define BBC_EBUST 0x20 /* [Q] EBUS Timing */
34#define BBC_JTAG_CMD 0x28 /* [W] JTAG+ Command */
35#define BBC_JTAG_CTRL 0x2c /* [B] JTAG+ Control */
36#define BBC_I2C_SEL 0x2d /* [B] I2C Selection */
37#define BBC_I2C_0_S1 0x2e /* [B] I2C ctrlr-0 reg S1 */
38#define BBC_I2C_0_S0 0x2f /* [B] I2C ctrlr-0 regs S0,S0',S2,S3*/
39#define BBC_I2C_1_S1 0x30 /* [B] I2C ctrlr-1 reg S1 */
40#define BBC_I2C_1_S0 0x31 /* [B] I2C ctrlr-1 regs S0,S0',S2,S3*/
41#define BBC_KBD_BEEP 0x32 /* [B] Keyboard Beep */
42#define BBC_KBD_BCNT 0x34 /* [W] Keyboard Beep Counter */
43
44#define BBC_REGS_SIZE 0x40
45
46/* There is a 2K scratch ram area at offset 0x80000 but I doubt
47 * we will use it for anything.
48 */
49
50/* Agent ID register. This register shows the Safari Agent ID
51 * for the processors. The value returned depends upon which
52 * cpu is reading the register.
53 */
54#define BBC_AID_ID 0x07 /* Safari ID */
55#define BBC_AID_RESV 0xf8 /* Reserved */
56
57/* Device Present register. One can determine which cpus are actually
58 * present in the machine by interrogating this register.
59 */
60#define BBC_DEVP_CPU0 0x01 /* Processor 0 present */
61#define BBC_DEVP_CPU1 0x02 /* Processor 1 present */
62#define BBC_DEVP_CPU2 0x04 /* Processor 2 present */
63#define BBC_DEVP_CPU3 0x08 /* Processor 3 present */
64#define BBC_DEVP_RESV 0xf0 /* Reserved */
65
66/* Arbitration register. This register is used to block access to
67 * the BBC from a particular cpu.
68 */
69#define BBC_ARB_CPU0 0x01 /* Enable cpu 0 BBC arbitratrion */
70#define BBC_ARB_CPU1 0x02 /* Enable cpu 1 BBC arbitratrion */
71#define BBC_ARB_CPU2 0x04 /* Enable cpu 2 BBC arbitratrion */
72#define BBC_ARB_CPU3 0x08 /* Enable cpu 3 BBC arbitratrion */
73#define BBC_ARB_RESV 0xf0 /* Reserved */
74
75/* Quiesce register. Bus and BBC segments for cpus can be disabled
76 * with this register, ie. for hot plugging.
77 */
78#define BBC_QUIESCE_S02 0x01 /* Quiesce Safari segment for cpu 0 and 2 */
79#define BBC_QUIESCE_S13 0x02 /* Quiesce Safari segment for cpu 1 and 3 */
80#define BBC_QUIESCE_B02 0x04 /* Quiesce BBC segment for cpu 0 and 2 */
81#define BBC_QUIESCE_B13 0x08 /* Quiesce BBC segment for cpu 1 and 3 */
82#define BBC_QUIESCE_FD0 0x10 /* Disable Fatal_Error[0] reporting */
83#define BBC_QUIESCE_FD1 0x20 /* Disable Fatal_Error[1] reporting */
84#define BBC_QUIESCE_FD2 0x40 /* Disable Fatal_Error[2] reporting */
85#define BBC_QUIESCE_FD3 0x80 /* Disable Fatal_Error[3] reporting */
86
87/* Watchdog Action register. When the watchdog device timer expires
88 * a line is enabled to the BBC. The action BBC takes when this line
89 * is asserted can be controlled by this regiser.
90 */
91#define BBC_WDACTION_RST 0x01 /* When set, watchdog causes system reset.
92 * When clear, BBC ignores watchdog signal.
93 */
94#define BBC_WDACTION_RESV 0xfe /* Reserved */
95
96/* Soft_POR_GEN register. The POR (Power On Reset) signal may be asserted
97 * for specific processors or all processors via this register.
98 */
99#define BBC_SPG_CPU0 0x01 /* Assert POR for processor 0 */
100#define BBC_SPG_CPU1 0x02 /* Assert POR for processor 1 */
101#define BBC_SPG_CPU2 0x04 /* Assert POR for processor 2 */
102#define BBC_SPG_CPU3 0x08 /* Assert POR for processor 3 */
103#define BBC_SPG_CPUALL 0x10 /* Reset all processors and reset
104 * the entire system.
105 */
106#define BBC_SPG_RESV 0xe0 /* Reserved */
107
108/* Soft_XIR_GEN register. The XIR (eXternally Initiated Reset) signal
109 * may be asserted to specific processors via this register.
110 */
111#define BBC_SXG_CPU0 0x01 /* Assert XIR for processor 0 */
112#define BBC_SXG_CPU1 0x02 /* Assert XIR for processor 1 */
113#define BBC_SXG_CPU2 0x04 /* Assert XIR for processor 2 */
114#define BBC_SXG_CPU3 0x08 /* Assert XIR for processor 3 */
115#define BBC_SXG_RESV 0xf0 /* Reserved */
116
117/* POR Source register. One may identify the cause of the most recent
118 * reset by reading this register.
119 */
120#define BBC_PSRC_SPG0 0x0001 /* CPU 0 reset via BBC_SPG register */
121#define BBC_PSRC_SPG1 0x0002 /* CPU 1 reset via BBC_SPG register */
122#define BBC_PSRC_SPG2 0x0004 /* CPU 2 reset via BBC_SPG register */
123#define BBC_PSRC_SPG3 0x0008 /* CPU 3 reset via BBC_SPG register */
124#define BBC_PSRC_SPGSYS 0x0010 /* System reset via BBC_SPG register */
125#define BBC_PSRC_JTAG 0x0020 /* System reset via JTAG+ */
126#define BBC_PSRC_BUTTON 0x0040 /* System reset via push-button dongle */
127#define BBC_PSRC_PWRUP 0x0080 /* System reset via power-up */
128#define BBC_PSRC_FE0 0x0100 /* CPU 0 reported Fatal_Error */
129#define BBC_PSRC_FE1 0x0200 /* CPU 1 reported Fatal_Error */
130#define BBC_PSRC_FE2 0x0400 /* CPU 2 reported Fatal_Error */
131#define BBC_PSRC_FE3 0x0800 /* CPU 3 reported Fatal_Error */
132#define BBC_PSRC_FE4 0x1000 /* Schizo reported Fatal_Error */
133#define BBC_PSRC_FE5 0x2000 /* Safari device 5 reported Fatal_Error */
134#define BBC_PSRC_FE6 0x4000 /* CPMS reported Fatal_Error */
135#define BBC_PSRC_SYNTH 0x8000 /* System reset when on-board clock synthesizers
136 * were updated.
137 */
138#define BBC_PSRC_WDT 0x10000 /* System reset via Super I/O watchdog */
139#define BBC_PSRC_RSC 0x20000 /* System reset via RSC remote monitoring
140 * device
141 */
142
143/* XIR Source register. The source of an XIR event sent to a processor may
144 * be determined via this register.
145 */
146#define BBC_XSRC_SXG0 0x01 /* CPU 0 received XIR via Soft_XIR_GEN reg */
147#define BBC_XSRC_SXG1 0x02 /* CPU 1 received XIR via Soft_XIR_GEN reg */
148#define BBC_XSRC_SXG2 0x04 /* CPU 2 received XIR via Soft_XIR_GEN reg */
149#define BBC_XSRC_SXG3 0x08 /* CPU 3 received XIR via Soft_XIR_GEN reg */
150#define BBC_XSRC_JTAG 0x10 /* All CPUs received XIR via JTAG+ */
151#define BBC_XSRC_W_OR_B 0x20 /* All CPUs received XIR either because:
152 * a) Super I/O watchdog fired, or
153 * b) XIR push button was activated
154 */
155#define BBC_XSRC_RESV 0xc0 /* Reserved */
156
157/* Clock Synthesizers Control register. This register provides the big-bang
158 * programming interface to the two clock synthesizers of the machine.
159 */
160#define BBC_CSC_SLOAD 0x01 /* Directly connected to S_LOAD pins */
161#define BBC_CSC_SDATA 0x02 /* Directly connected to S_DATA pins */
162#define BBC_CSC_SCLOCK 0x04 /* Directly connected to S_CLOCK pins */
163#define BBC_CSC_RESV 0x78 /* Reserved */
164#define BBC_CSC_RST 0x80 /* Generate system reset when S_LOAD==1 */
165
166/* Energy Star Control register. This register is used to generate the
167 * clock frequency change trigger to the main system devices (Schizo and
168 * the processors). The transition occurs when bits in this register
169 * go from 0 to 1, only one bit must be set at once else no action
170 * occurs. Basically the sequence of events is:
171 * a) Choose new frequency: full, 1/2 or 1/32
172 * b) Program this desired frequency into the cpus and Schizo.
173 * c) Set the same value in this register.
174 * d) 16 system clocks later, clear this register.
175 */
176#define BBC_ES_CTRL_1_1 0x01 /* Full frequency */
177#define BBC_ES_CTRL_1_2 0x02 /* 1/2 frequency */
178#define BBC_ES_CTRL_1_32 0x20 /* 1/32 frequency */
179#define BBC_ES_RESV 0xdc /* Reserved */
180
181/* Energy Star Assert Change Time register. This determines the number
182 * of BBC clock cycles (which is half the system frequency) between
183 * the detection of FREEZE_ACK being asserted and the assertion of
184 * the CLK_CHANGE_L[2:0] signals.
185 */
186#define BBC_ES_ACT_VAL 0xff
187
188/* Energy Star Assert Bypass Time register. This determines the number
189 * of BBC clock cycles (which is half the system frequency) between
190 * the assertion of the CLK_CHANGE_L[2:0] signals and the assertion of
191 * the ESTAR_PLL_BYPASS signal.
192 */
193#define BBC_ES_ABT_VAL 0xffff
194
195/* Energy Star PLL Settle Time register. This determines the number of
196 * BBC clock cycles (which is half the system frequency) between the
197 * de-assertion of CLK_CHANGE_L[2:0] and the de-assertion of the FREEZE_L
198 * signal.
199 */
200#define BBC_ES_PST_VAL 0xffffffff
201
202/* Energy Star Frequency Switch Latency register. This is the number of
203 * BBC clocks between the de-assertion of CLK_CHANGE_L[2:0] and the first
204 * edge of the Safari clock at the new frequency.
205 */
206#define BBC_ES_FSL_VAL 0xffffffff
207
208/* Keyboard Beep control register. This is a simple enabler for the audio
209 * beep sound.
210 */
211#define BBC_KBD_BEEP_ENABLE 0x01 /* Enable beep */
212#define BBC_KBD_BEEP_RESV 0xfe /* Reserved */
213
214/* Keyboard Beep Counter register. There is a free-running counter inside
215 * the BBC which runs at half the system clock. The bit set in this register
216 * determines when the audio sound is generated. So for example if bit
217 * 10 is set, the audio beep will oscillate at 1/(2**12). The keyboard beep
218 * generator automatically selects a different bit to use if the system clock
219 * is changed via Energy Star.
220 */
221#define BBC_KBD_BCNT_BITS 0x0007fc00
222#define BBC_KBC_BCNT_RESV 0xfff803ff
223
224#endif /* _SPARC64_BBC_H */
225
diff --git a/include/asm-sparc64/bitops.h b/include/asm-sparc64/bitops.h
index bb87b8080220..204404355bdd 100644
--- a/include/asm-sparc64/bitops.h
+++ b/include/asm-sparc64/bitops.h
@@ -1,107 +1 @@
1/* #include <asm-sparc/bitops.h>
2 * bitops.h: Bit string operations on the V9.
3 *
4 * Copyright 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef _SPARC64_BITOPS_H
8#define _SPARC64_BITOPS_H
9
10#ifndef _LINUX_BITOPS_H
11#error only <linux/bitops.h> can be included directly
12#endif
13
14#include <linux/compiler.h>
15#include <asm/byteorder.h>
16
17extern int test_and_set_bit(unsigned long nr, volatile unsigned long *addr);
18extern int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr);
19extern int test_and_change_bit(unsigned long nr, volatile unsigned long *addr);
20extern void set_bit(unsigned long nr, volatile unsigned long *addr);
21extern void clear_bit(unsigned long nr, volatile unsigned long *addr);
22extern void change_bit(unsigned long nr, volatile unsigned long *addr);
23
24#include <asm-generic/bitops/non-atomic.h>
25
26#ifdef CONFIG_SMP
27#define smp_mb__before_clear_bit() membar_storeload_loadload()
28#define smp_mb__after_clear_bit() membar_storeload_storestore()
29#else
30#define smp_mb__before_clear_bit() barrier()
31#define smp_mb__after_clear_bit() barrier()
32#endif
33
34#include <asm-generic/bitops/ffz.h>
35#include <asm-generic/bitops/__ffs.h>
36#include <asm-generic/bitops/fls.h>
37#include <asm-generic/bitops/__fls.h>
38#include <asm-generic/bitops/fls64.h>
39
40#ifdef __KERNEL__
41
42#include <asm-generic/bitops/sched.h>
43#include <asm-generic/bitops/ffs.h>
44
45/*
46 * hweightN: returns the hamming weight (i.e. the number
47 * of bits set) of a N-bit word
48 */
49
50#ifdef ULTRA_HAS_POPULATION_COUNT
51
52static inline unsigned int hweight64(unsigned long w)
53{
54 unsigned int res;
55
56 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w));
57 return res;
58}
59
60static inline unsigned int hweight32(unsigned int w)
61{
62 unsigned int res;
63
64 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffffffff));
65 return res;
66}
67
68static inline unsigned int hweight16(unsigned int w)
69{
70 unsigned int res;
71
72 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffff));
73 return res;
74}
75
76static inline unsigned int hweight8(unsigned int w)
77{
78 unsigned int res;
79
80 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xff));
81 return res;
82}
83
84#else
85
86#include <asm-generic/bitops/hweight.h>
87
88#endif
89#include <asm-generic/bitops/lock.h>
90#endif /* __KERNEL__ */
91
92#include <asm-generic/bitops/find.h>
93
94#ifdef __KERNEL__
95
96#include <asm-generic/bitops/ext2-non-atomic.h>
97
98#define ext2_set_bit_atomic(lock,nr,addr) \
99 test_and_set_bit((nr) ^ 0x38,(unsigned long *)(addr))
100#define ext2_clear_bit_atomic(lock,nr,addr) \
101 test_and_clear_bit((nr) ^ 0x38,(unsigned long *)(addr))
102
103#include <asm-generic/bitops/minix.h>
104
105#endif /* __KERNEL__ */
106
107#endif /* defined(_SPARC64_BITOPS_H) */
diff --git a/include/asm-sparc64/cacheflush.h b/include/asm-sparc64/cacheflush.h
index 122e4058dd9e..cf5b6b3e8a55 100644
--- a/include/asm-sparc64/cacheflush.h
+++ b/include/asm-sparc64/cacheflush.h
@@ -1,76 +1 @@
1#ifndef _SPARC64_CACHEFLUSH_H #include <asm-sparc/cacheflush.h>
2#define _SPARC64_CACHEFLUSH_H
3
4#include <asm/page.h>
5
6#ifndef __ASSEMBLY__
7
8#include <linux/mm.h>
9
10/* Cache flush operations. */
11
12/* These are the same regardless of whether this is an SMP kernel or not. */
13#define flush_cache_mm(__mm) \
14 do { if ((__mm) == current->mm) flushw_user(); } while(0)
15#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
16#define flush_cache_range(vma, start, end) \
17 flush_cache_mm((vma)->vm_mm)
18#define flush_cache_page(vma, page, pfn) \
19 flush_cache_mm((vma)->vm_mm)
20
21/*
22 * On spitfire, the icache doesn't snoop local stores and we don't
23 * use block commit stores (which invalidate icache lines) during
24 * module load, so we need this.
25 */
26extern void flush_icache_range(unsigned long start, unsigned long end);
27extern void __flush_icache_page(unsigned long);
28
29extern void __flush_dcache_page(void *addr, int flush_icache);
30extern void flush_dcache_page_impl(struct page *page);
31#ifdef CONFIG_SMP
32extern void smp_flush_dcache_page_impl(struct page *page, int cpu);
33extern void flush_dcache_page_all(struct mm_struct *mm, struct page *page);
34#else
35#define smp_flush_dcache_page_impl(page,cpu) flush_dcache_page_impl(page)
36#define flush_dcache_page_all(mm,page) flush_dcache_page_impl(page)
37#endif
38
39extern void __flush_dcache_range(unsigned long start, unsigned long end);
40extern void flush_dcache_page(struct page *page);
41
42#define flush_icache_page(vma, pg) do { } while(0)
43#define flush_icache_user_range(vma,pg,adr,len) do { } while (0)
44
45extern void flush_ptrace_access(struct vm_area_struct *, struct page *,
46 unsigned long uaddr, void *kaddr,
47 unsigned long len, int write);
48
49#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
50 do { \
51 flush_cache_page(vma, vaddr, page_to_pfn(page)); \
52 memcpy(dst, src, len); \
53 flush_ptrace_access(vma, page, vaddr, src, len, 0); \
54 } while (0)
55
56#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
57 do { \
58 flush_cache_page(vma, vaddr, page_to_pfn(page)); \
59 memcpy(dst, src, len); \
60 flush_ptrace_access(vma, page, vaddr, dst, len, 1); \
61 } while (0)
62
63#define flush_dcache_mmap_lock(mapping) do { } while (0)
64#define flush_dcache_mmap_unlock(mapping) do { } while (0)
65
66#define flush_cache_vmap(start, end) do { } while (0)
67#define flush_cache_vunmap(start, end) do { } while (0)
68
69#ifdef CONFIG_DEBUG_PAGEALLOC
70/* internal debugging function */
71void kernel_map_pages(struct page *page, int numpages, int enable);
72#endif
73
74#endif /* !__ASSEMBLY__ */
75
76#endif /* _SPARC64_CACHEFLUSH_H */
diff --git a/include/asm-sparc64/chafsr.h b/include/asm-sparc64/chafsr.h
index 85c69b38220b..aaab97562a39 100644
--- a/include/asm-sparc64/chafsr.h
+++ b/include/asm-sparc64/chafsr.h
@@ -1,241 +1 @@
1#ifndef _SPARC64_CHAFSR_H #include <asm-sparc/chafsr.h>
2#define _SPARC64_CHAFSR_H
3
4/* Cheetah Asynchronous Fault Status register, ASI=0x4C VA<63:0>=0x0 */
5
6/* Comments indicate which processor variants on which the bit definition
7 * is valid. Codes are:
8 * ch --> cheetah
9 * ch+ --> cheetah plus
10 * jp --> jalapeno
11 */
12
13/* All bits of this register except M_SYNDROME and E_SYNDROME are
14 * read, write 1 to clear. M_SYNDROME and E_SYNDROME are read-only.
15 */
16
17/* Software bit set by linux trap handlers to indicate that the trap was
18 * signalled at %tl >= 1.
19 */
20#define CHAFSR_TL1 (1UL << 63UL) /* n/a */
21
22/* Unmapped error from system bus for prefetch queue or
23 * store queue read operation
24 */
25#define CHPAFSR_DTO (1UL << 59UL) /* ch+ */
26
27/* Bus error from system bus for prefetch queue or store queue
28 * read operation
29 */
30#define CHPAFSR_DBERR (1UL << 58UL) /* ch+ */
31
32/* Hardware corrected E-cache Tag ECC error */
33#define CHPAFSR_THCE (1UL << 57UL) /* ch+ */
34/* System interface protocol error, hw timeout caused */
35#define JPAFSR_JETO (1UL << 57UL) /* jp */
36
37/* SW handled correctable E-cache Tag ECC error */
38#define CHPAFSR_TSCE (1UL << 56UL) /* ch+ */
39/* Parity error on system snoop results */
40#define JPAFSR_SCE (1UL << 56UL) /* jp */
41
42/* Uncorrectable E-cache Tag ECC error */
43#define CHPAFSR_TUE (1UL << 55UL) /* ch+ */
44/* System interface protocol error, illegal command detected */
45#define JPAFSR_JEIC (1UL << 55UL) /* jp */
46
47/* Uncorrectable system bus data ECC error due to prefetch
48 * or store fill request
49 */
50#define CHPAFSR_DUE (1UL << 54UL) /* ch+ */
51/* System interface protocol error, illegal ADTYPE detected */
52#define JPAFSR_JEIT (1UL << 54UL) /* jp */
53
54/* Multiple errors of the same type have occurred. This bit is set when
55 * an uncorrectable error or a SW correctable error occurs and the status
56 * bit to report that error is already set. When multiple errors of
57 * different types are indicated by setting multiple status bits.
58 *
59 * This bit is not set if multiple HW corrected errors with the same
60 * status bit occur, only uncorrectable and SW correctable ones have
61 * this behavior.
62 *
63 * This bit is not set when multiple ECC errors happen within a single
64 * 64-byte system bus transaction. Only the first ECC error in a 16-byte
65 * subunit will be logged. All errors in subsequent 16-byte subunits
66 * from the same 64-byte transaction are ignored.
67 */
68#define CHAFSR_ME (1UL << 53UL) /* ch,ch+,jp */
69
70/* Privileged state error has occurred. This is a capture of PSTATE.PRIV
71 * at the time the error is detected.
72 */
73#define CHAFSR_PRIV (1UL << 52UL) /* ch,ch+,jp */
74
75/* The following bits 51 (CHAFSR_PERR) to 33 (CHAFSR_CE) are sticky error
76 * bits and record the most recently detected errors. Bits accumulate
77 * errors that have been detected since the last write to clear the bit.
78 */
79
80/* System interface protocol error. The processor asserts its' ERROR
81 * pin when this event occurs and it also logs a specific cause code
82 * into a JTAG scannable flop.
83 */
84#define CHAFSR_PERR (1UL << 51UL) /* ch,ch+,jp */
85
86/* Internal processor error. The processor asserts its' ERROR
87 * pin when this event occurs and it also logs a specific cause code
88 * into a JTAG scannable flop.
89 */
90#define CHAFSR_IERR (1UL << 50UL) /* ch,ch+,jp */
91
92/* System request parity error on incoming address */
93#define CHAFSR_ISAP (1UL << 49UL) /* ch,ch+,jp */
94
95/* HW Corrected system bus MTAG ECC error */
96#define CHAFSR_EMC (1UL << 48UL) /* ch,ch+ */
97/* Parity error on L2 cache tag SRAM */
98#define JPAFSR_ETP (1UL << 48UL) /* jp */
99
100/* Uncorrectable system bus MTAG ECC error */
101#define CHAFSR_EMU (1UL << 47UL) /* ch,ch+ */
102/* Out of range memory error has occurred */
103#define JPAFSR_OM (1UL << 47UL) /* jp */
104
105/* HW Corrected system bus data ECC error for read of interrupt vector */
106#define CHAFSR_IVC (1UL << 46UL) /* ch,ch+ */
107/* Error due to unsupported store */
108#define JPAFSR_UMS (1UL << 46UL) /* jp */
109
110/* Uncorrectable system bus data ECC error for read of interrupt vector */
111#define CHAFSR_IVU (1UL << 45UL) /* ch,ch+,jp */
112
113/* Unmapped error from system bus */
114#define CHAFSR_TO (1UL << 44UL) /* ch,ch+,jp */
115
116/* Bus error response from system bus */
117#define CHAFSR_BERR (1UL << 43UL) /* ch,ch+,jp */
118
119/* SW Correctable E-cache ECC error for instruction fetch or data access
120 * other than block load.
121 */
122#define CHAFSR_UCC (1UL << 42UL) /* ch,ch+,jp */
123
124/* Uncorrectable E-cache ECC error for instruction fetch or data access
125 * other than block load.
126 */
127#define CHAFSR_UCU (1UL << 41UL) /* ch,ch+,jp */
128
129/* Copyout HW Corrected ECC error */
130#define CHAFSR_CPC (1UL << 40UL) /* ch,ch+,jp */
131
132/* Copyout Uncorrectable ECC error */
133#define CHAFSR_CPU (1UL << 39UL) /* ch,ch+,jp */
134
135/* HW Corrected ECC error from E-cache for writeback */
136#define CHAFSR_WDC (1UL << 38UL) /* ch,ch+,jp */
137
138/* Uncorrectable ECC error from E-cache for writeback */
139#define CHAFSR_WDU (1UL << 37UL) /* ch,ch+,jp */
140
141/* HW Corrected ECC error from E-cache for store merge or block load */
142#define CHAFSR_EDC (1UL << 36UL) /* ch,ch+,jp */
143
144/* Uncorrectable ECC error from E-cache for store merge or block load */
145#define CHAFSR_EDU (1UL << 35UL) /* ch,ch+,jp */
146
147/* Uncorrectable system bus data ECC error for read of memory or I/O */
148#define CHAFSR_UE (1UL << 34UL) /* ch,ch+,jp */
149
150/* HW Corrected system bus data ECC error for read of memory or I/O */
151#define CHAFSR_CE (1UL << 33UL) /* ch,ch+,jp */
152
153/* Uncorrectable ECC error from remote cache/memory */
154#define JPAFSR_RUE (1UL << 32UL) /* jp */
155
156/* Correctable ECC error from remote cache/memory */
157#define JPAFSR_RCE (1UL << 31UL) /* jp */
158
159/* JBUS parity error on returned read data */
160#define JPAFSR_BP (1UL << 30UL) /* jp */
161
162/* JBUS parity error on data for writeback or block store */
163#define JPAFSR_WBP (1UL << 29UL) /* jp */
164
165/* Foreign read to DRAM incurring correctable ECC error */
166#define JPAFSR_FRC (1UL << 28UL) /* jp */
167
168/* Foreign read to DRAM incurring uncorrectable ECC error */
169#define JPAFSR_FRU (1UL << 27UL) /* jp */
170
171#define CHAFSR_ERRORS (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP | CHAFSR_EMC | \
172 CHAFSR_EMU | CHAFSR_IVC | CHAFSR_IVU | CHAFSR_TO | \
173 CHAFSR_BERR | CHAFSR_UCC | CHAFSR_UCU | CHAFSR_CPC | \
174 CHAFSR_CPU | CHAFSR_WDC | CHAFSR_WDU | CHAFSR_EDC | \
175 CHAFSR_EDU | CHAFSR_UE | CHAFSR_CE)
176#define CHPAFSR_ERRORS (CHPAFSR_DTO | CHPAFSR_DBERR | CHPAFSR_THCE | \
177 CHPAFSR_TSCE | CHPAFSR_TUE | CHPAFSR_DUE | \
178 CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP | CHAFSR_EMC | \
179 CHAFSR_EMU | CHAFSR_IVC | CHAFSR_IVU | CHAFSR_TO | \
180 CHAFSR_BERR | CHAFSR_UCC | CHAFSR_UCU | CHAFSR_CPC | \
181 CHAFSR_CPU | CHAFSR_WDC | CHAFSR_WDU | CHAFSR_EDC | \
182 CHAFSR_EDU | CHAFSR_UE | CHAFSR_CE)
183#define JPAFSR_ERRORS (JPAFSR_JETO | JPAFSR_SCE | JPAFSR_JEIC | \
184 JPAFSR_JEIT | CHAFSR_PERR | CHAFSR_IERR | \
185 CHAFSR_ISAP | JPAFSR_ETP | JPAFSR_OM | \
186 JPAFSR_UMS | CHAFSR_IVU | CHAFSR_TO | \
187 CHAFSR_BERR | CHAFSR_UCC | CHAFSR_UCU | \
188 CHAFSR_CPC | CHAFSR_CPU | CHAFSR_WDC | \
189 CHAFSR_WDU | CHAFSR_EDC | CHAFSR_EDU | \
190 CHAFSR_UE | CHAFSR_CE | JPAFSR_RUE | \
191 JPAFSR_RCE | JPAFSR_BP | JPAFSR_WBP | \
192 JPAFSR_FRC | JPAFSR_FRU)
193
194/* Active JBUS request signal when error occurred */
195#define JPAFSR_JBREQ (0x7UL << 24UL) /* jp */
196#define JPAFSR_JBREQ_SHIFT 24UL
197
198/* L2 cache way information */
199#define JPAFSR_ETW (0x3UL << 22UL) /* jp */
200#define JPAFSR_ETW_SHIFT 22UL
201
202/* System bus MTAG ECC syndrome. This field captures the status of the
203 * first occurrence of the highest-priority error according to the M_SYND
204 * overwrite policy. After the AFSR sticky bit, corresponding to the error
205 * for which the M_SYND is reported, is cleared, the contents of the M_SYND
206 * field will be unchanged by will be unfrozen for further error capture.
207 */
208#define CHAFSR_M_SYNDROME (0xfUL << 16UL) /* ch,ch+,jp */
209#define CHAFSR_M_SYNDROME_SHIFT 16UL
210
211/* Agenid Id of the foreign device causing the UE/CE errors */
212#define JPAFSR_AID (0x1fUL << 9UL) /* jp */
213#define JPAFSR_AID_SHIFT 9UL
214
215/* System bus or E-cache data ECC syndrome. This field captures the status
216 * of the first occurrence of the highest-priority error according to the
217 * E_SYND overwrite policy. After the AFSR sticky bit, corresponding to the
218 * error for which the E_SYND is reported, is cleare, the contents of the E_SYND
219 * field will be unchanged but will be unfrozen for further error capture.
220 */
221#define CHAFSR_E_SYNDROME (0x1ffUL << 0UL) /* ch,ch+,jp */
222#define CHAFSR_E_SYNDROME_SHIFT 0UL
223
224/* The AFSR must be explicitly cleared by software, it is not cleared automatically
225 * by a read. Writes to bits <51:33> with bits set will clear the corresponding
226 * bits in the AFSR. Bits associated with disrupting traps must be cleared before
227 * interrupts are re-enabled to prevent multiple traps for the same error. I.e.
228 * PSTATE.IE and AFSR bits control delivery of disrupting traps.
229 *
230 * Since there is only one AFAR, when multiple events have been logged by the
231 * bits in the AFSR, at most one of these events will have its status captured
232 * in the AFAR. The highest priority of those event bits will get AFAR logging.
233 * The AFAR will be unlocked and available to capture the address of another event
234 * as soon as the one bit in AFSR that corresponds to the event logged in AFAR is
235 * cleared. For example, if AFSR.CE is detected, then AFSR.UE (which overwrites
236 * the AFAR), and AFSR.UE is cleared by not AFSR.CE, then the AFAR will be unlocked
237 * and ready for another event, even though AFSR.CE is still set. The same rules
238 * also apply to the M_SYNDROME and E_SYNDROME fields of the AFSR.
239 */
240
241#endif /* _SPARC64_CHAFSR_H */
diff --git a/include/asm-sparc64/checksum.h b/include/asm-sparc64/checksum.h
index b290564c8ce0..c3966c5e29d8 100644
--- a/include/asm-sparc64/checksum.h
+++ b/include/asm-sparc64/checksum.h
@@ -1,167 +1 @@
1#ifndef __SPARC64_CHECKSUM_H #include <asm-sparc/checksum.h>
2#define __SPARC64_CHECKSUM_H
3
4/* checksum.h: IP/UDP/TCP checksum routines on the V9.
5 *
6 * Copyright(C) 1995 Linus Torvalds
7 * Copyright(C) 1995 Miguel de Icaza
8 * Copyright(C) 1996 David S. Miller
9 * Copyright(C) 1996 Eddie C. Dost
10 * Copyright(C) 1997 Jakub Jelinek
11 *
12 * derived from:
13 * Alpha checksum c-code
14 * ix86 inline assembly
15 * RFC1071 Computing the Internet Checksum
16 */
17
18#include <linux/in6.h>
19#include <asm/uaccess.h>
20
21/* computes the checksum of a memory block at buff, length len,
22 * and adds in "sum" (32-bit)
23 *
24 * returns a 32-bit number suitable for feeding into itself
25 * or csum_tcpudp_magic
26 *
27 * this function must be called with even lengths, except
28 * for the last fragment, which may be odd
29 *
30 * it's best to have buff aligned on a 32-bit boundary
31 */
32extern __wsum csum_partial(const void * buff, int len, __wsum sum);
33
34/* the same as csum_partial, but copies from user space while it
35 * checksums
36 *
37 * here even more important to align src and dst on a 32-bit (or even
38 * better 64-bit) boundary
39 */
40extern __wsum csum_partial_copy_nocheck(const void *src, void *dst,
41 int len, __wsum sum);
42
43extern long __csum_partial_copy_from_user(const void __user *src,
44 void *dst, int len,
45 __wsum sum);
46
47static inline __wsum
48csum_partial_copy_from_user(const void __user *src,
49 void *dst, int len,
50 __wsum sum, int *err)
51{
52 long ret = __csum_partial_copy_from_user(src, dst, len, sum);
53 if (ret < 0)
54 *err = -EFAULT;
55 return (__force __wsum) ret;
56}
57
58/*
59 * Copy and checksum to user
60 */
61#define HAVE_CSUM_COPY_USER
62extern long __csum_partial_copy_to_user(const void *src,
63 void __user *dst, int len,
64 __wsum sum);
65
66static inline __wsum
67csum_and_copy_to_user(const void *src,
68 void __user *dst, int len,
69 __wsum sum, int *err)
70{
71 long ret = __csum_partial_copy_to_user(src, dst, len, sum);
72 if (ret < 0)
73 *err = -EFAULT;
74 return (__force __wsum) ret;
75}
76
77/* ihl is always 5 or greater, almost always is 5, and iph is word aligned
78 * the majority of the time.
79 */
80extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
81
82/* Fold a partial checksum without adding pseudo headers. */
83static inline __sum16 csum_fold(__wsum sum)
84{
85 unsigned int tmp;
86
87 __asm__ __volatile__(
88" addcc %0, %1, %1\n"
89" srl %1, 16, %1\n"
90" addc %1, %%g0, %1\n"
91" xnor %%g0, %1, %0\n"
92 : "=&r" (sum), "=r" (tmp)
93 : "0" (sum), "1" ((__force u32)sum<<16)
94 : "cc");
95 return (__force __sum16)sum;
96}
97
98static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
99 unsigned int len,
100 unsigned short proto,
101 __wsum sum)
102{
103 __asm__ __volatile__(
104" addcc %1, %0, %0\n"
105" addccc %2, %0, %0\n"
106" addccc %3, %0, %0\n"
107" addc %0, %%g0, %0\n"
108 : "=r" (sum), "=r" (saddr)
109 : "r" (daddr), "r" (proto + len), "0" (sum), "1" (saddr)
110 : "cc");
111 return sum;
112}
113
114/*
115 * computes the checksum of the TCP/UDP pseudo-header
116 * returns a 16-bit checksum, already complemented
117 */
118static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
119 unsigned short len,
120 unsigned short proto,
121 __wsum sum)
122{
123 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
124}
125
126#define _HAVE_ARCH_IPV6_CSUM
127
128static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
129 const struct in6_addr *daddr,
130 __u32 len, unsigned short proto,
131 __wsum sum)
132{
133 __asm__ __volatile__ (
134" addcc %3, %4, %%g7\n"
135" addccc %5, %%g7, %%g7\n"
136" lduw [%2 + 0x0c], %%g2\n"
137" lduw [%2 + 0x08], %%g3\n"
138" addccc %%g2, %%g7, %%g7\n"
139" lduw [%2 + 0x04], %%g2\n"
140" addccc %%g3, %%g7, %%g7\n"
141" lduw [%2 + 0x00], %%g3\n"
142" addccc %%g2, %%g7, %%g7\n"
143" lduw [%1 + 0x0c], %%g2\n"
144" addccc %%g3, %%g7, %%g7\n"
145" lduw [%1 + 0x08], %%g3\n"
146" addccc %%g2, %%g7, %%g7\n"
147" lduw [%1 + 0x04], %%g2\n"
148" addccc %%g3, %%g7, %%g7\n"
149" lduw [%1 + 0x00], %%g3\n"
150" addccc %%g2, %%g7, %%g7\n"
151" addccc %%g3, %%g7, %0\n"
152" addc 0, %0, %0\n"
153 : "=&r" (sum)
154 : "r" (saddr), "r" (daddr), "r"(htonl(len)),
155 "r"(htonl(proto)), "r"(sum)
156 : "g2", "g3", "g7", "cc");
157
158 return csum_fold(sum);
159}
160
161/* this routine is used for miscellaneous IP-like checksums, mainly in icmp.c */
162static inline __sum16 ip_compute_csum(const void *buff, int len)
163{
164 return csum_fold(csum_partial(buff, len, 0));
165}
166
167#endif /* !(__SPARC64_CHECKSUM_H) */
diff --git a/include/asm-sparc64/chmctrl.h b/include/asm-sparc64/chmctrl.h
index 859b4a4b0d30..eb757b483b30 100644
--- a/include/asm-sparc64/chmctrl.h
+++ b/include/asm-sparc64/chmctrl.h
@@ -1,183 +1 @@
1#ifndef _SPARC64_CHMCTRL_H #include <asm-sparc/chmctrl.h>
2#define _SPARC64_CHMCTRL_H
3
4/* Cheetah memory controller programmable registers. */
5#define CHMCTRL_TCTRL1 0x00 /* Memory Timing Control I */
6#define CHMCTRL_TCTRL2 0x08 /* Memory Timing Control II */
7#define CHMCTRL_TCTRL3 0x38 /* Memory Timing Control III */
8#define CHMCTRL_TCTRL4 0x40 /* Memory Timing Control IV */
9#define CHMCTRL_DECODE1 0x10 /* Memory Address Decode I */
10#define CHMCTRL_DECODE2 0x18 /* Memory Address Decode II */
11#define CHMCTRL_DECODE3 0x20 /* Memory Address Decode III */
12#define CHMCTRL_DECODE4 0x28 /* Memory Address Decode IV */
13#define CHMCTRL_MACTRL 0x30 /* Memory Address Control */
14
15/* Memory Timing Control I */
16#define TCTRL1_SDRAMCTL_DLY 0xf000000000000000UL
17#define TCTRL1_SDRAMCTL_DLY_SHIFT 60
18#define TCTRL1_SDRAMCLK_DLY 0x0e00000000000000UL
19#define TCTRL1_SDRAMCLK_DLY_SHIFT 57
20#define TCTRL1_R 0x0100000000000000UL
21#define TCTRL1_R_SHIFT 56
22#define TCTRL1_AUTORFR_CYCLE 0x00fe000000000000UL
23#define TCTRL1_AUTORFR_CYCLE_SHIFT 49
24#define TCTRL1_RD_WAIT 0x0001f00000000000UL
25#define TCTRL1_RD_WAIT_SHIFT 44
26#define TCTRL1_PC_CYCLE 0x00000fc000000000UL
27#define TCTRL1_PC_CYCLE_SHIFT 38
28#define TCTRL1_WR_MORE_RAS_PW 0x0000003f00000000UL
29#define TCTRL1_WR_MORE_RAS_PW_SHIFT 32
30#define TCTRL1_RD_MORE_RAW_PW 0x00000000fc000000UL
31#define TCTRL1_RD_MORE_RAS_PW_SHIFT 26
32#define TCTRL1_ACT_WR_DLY 0x0000000003f00000UL
33#define TCTRL1_ACT_WR_DLY_SHIFT 20
34#define TCTRL1_ACT_RD_DLY 0x00000000000fc000UL
35#define TCTRL1_ACT_RD_DLY_SHIFT 14
36#define TCTRL1_BANK_PRESENT 0x0000000000003000UL
37#define TCTRL1_BANK_PRESENT_SHIFT 12
38#define TCTRL1_RFR_INT 0x0000000000000ff8UL
39#define TCTRL1_RFR_INT_SHIFT 3
40#define TCTRL1_SET_MODE_REG 0x0000000000000004UL
41#define TCTRL1_SET_MODE_REG_SHIFT 2
42#define TCTRL1_RFR_ENABLE 0x0000000000000002UL
43#define TCTRL1_RFR_ENABLE_SHIFT 1
44#define TCTRL1_PRECHG_ALL 0x0000000000000001UL
45#define TCTRL1_PRECHG_ALL_SHIFT 0
46
47/* Memory Timing Control II */
48#define TCTRL2_WR_MSEL_DLY 0xfc00000000000000UL
49#define TCTRL2_WR_MSEL_DLY_SHIFT 58
50#define TCTRL2_RD_MSEL_DLY 0x03f0000000000000UL
51#define TCTRL2_RD_MSEL_DLY_SHIFT 52
52#define TCTRL2_WRDATA_THLD 0x000c000000000000UL
53#define TCTRL2_WRDATA_THLD_SHIFT 50
54#define TCTRL2_RDWR_RD_TI_DLY 0x0003f00000000000UL
55#define TCTRL2_RDWR_RD_TI_DLY_SHIFT 44
56#define TCTRL2_AUTOPRECHG_ENBL 0x0000080000000000UL
57#define TCTRL2_AUTOPRECHG_ENBL_SHIFT 43
58#define TCTRL2_RDWR_PI_MORE_DLY 0x000007c000000000UL
59#define TCTRL2_RDWR_PI_MORE_DLY_SHIFT 38
60#define TCTRL2_RDWR_1_DLY 0x0000003f00000000UL
61#define TCTRL2_RDWR_1_DLY_SHIFT 32
62#define TCTRL2_WRWR_PI_MORE_DLY 0x00000000f8000000UL
63#define TCTRL2_WRWR_PI_MORE_DLY_SHIFT 27
64#define TCTRL2_WRWR_1_DLY 0x0000000007e00000UL
65#define TCTRL2_WRWR_1_DLY_SHIFT 21
66#define TCTRL2_RDWR_RD_PI_MORE_DLY 0x00000000001f0000UL
67#define TCTRL2_RDWR_RD_PI_MORE_DLY_SHIFT 16
68#define TCTRL2_R 0x0000000000008000UL
69#define TCTRL2_R_SHIFT 15
70#define TCTRL2_SDRAM_MODE_REG_DATA 0x0000000000007fffUL
71#define TCTRL2_SDRAM_MODE_REG_DATA_SHIFT 0
72
73/* Memory Timing Control III */
74#define TCTRL3_SDRAM_CTL_DLY 0xf000000000000000UL
75#define TCTRL3_SDRAM_CTL_DLY_SHIFT 60
76#define TCTRL3_SDRAM_CLK_DLY 0x0e00000000000000UL
77#define TCTRL3_SDRAM_CLK_DLY_SHIFT 57
78#define TCTRL3_R 0x0100000000000000UL
79#define TCTRL3_R_SHIFT 56
80#define TCTRL3_AUTO_RFR_CYCLE 0x00fe000000000000UL
81#define TCTRL3_AUTO_RFR_CYCLE_SHIFT 49
82#define TCTRL3_RD_WAIT 0x0001f00000000000UL
83#define TCTRL3_RD_WAIT_SHIFT 44
84#define TCTRL3_PC_CYCLE 0x00000fc000000000UL
85#define TCTRL3_PC_CYCLE_SHIFT 38
86#define TCTRL3_WR_MORE_RAW_PW 0x0000003f00000000UL
87#define TCTRL3_WR_MORE_RAW_PW_SHIFT 32
88#define TCTRL3_RD_MORE_RAW_PW 0x00000000fc000000UL
89#define TCTRL3_RD_MORE_RAW_PW_SHIFT 26
90#define TCTRL3_ACT_WR_DLY 0x0000000003f00000UL
91#define TCTRL3_ACT_WR_DLY_SHIFT 20
92#define TCTRL3_ACT_RD_DLY 0x00000000000fc000UL
93#define TCTRL3_ACT_RD_DLY_SHIFT 14
94#define TCTRL3_BANK_PRESENT 0x0000000000003000UL
95#define TCTRL3_BANK_PRESENT_SHIFT 12
96#define TCTRL3_RFR_INT 0x0000000000000ff8UL
97#define TCTRL3_RFR_INT_SHIFT 3
98#define TCTRL3_SET_MODE_REG 0x0000000000000004UL
99#define TCTRL3_SET_MODE_REG_SHIFT 2
100#define TCTRL3_RFR_ENABLE 0x0000000000000002UL
101#define TCTRL3_RFR_ENABLE_SHIFT 1
102#define TCTRL3_PRECHG_ALL 0x0000000000000001UL
103#define TCTRL3_PRECHG_ALL_SHIFT 0
104
105/* Memory Timing Control IV */
106#define TCTRL4_WR_MSEL_DLY 0xfc00000000000000UL
107#define TCTRL4_WR_MSEL_DLY_SHIFT 58
108#define TCTRL4_RD_MSEL_DLY 0x03f0000000000000UL
109#define TCTRL4_RD_MSEL_DLY_SHIFT 52
110#define TCTRL4_WRDATA_THLD 0x000c000000000000UL
111#define TCTRL4_WRDATA_THLD_SHIFT 50
112#define TCTRL4_RDWR_RD_RI_DLY 0x0003f00000000000UL
113#define TCTRL4_RDWR_RD_RI_DLY_SHIFT 44
114#define TCTRL4_AUTO_PRECHG_ENBL 0x0000080000000000UL
115#define TCTRL4_AUTO_PRECHG_ENBL_SHIFT 43
116#define TCTRL4_RD_WR_PI_MORE_DLY 0x000007c000000000UL
117#define TCTRL4_RD_WR_PI_MORE_DLY_SHIFT 38
118#define TCTRL4_RD_WR_TI_DLY 0x0000003f00000000UL
119#define TCTRL4_RD_WR_TI_DLY_SHIFT 32
120#define TCTRL4_WR_WR_PI_MORE_DLY 0x00000000f8000000UL
121#define TCTRL4_WR_WR_PI_MORE_DLY_SHIFT 27
122#define TCTRL4_WR_WR_TI_DLY 0x0000000007e00000UL
123#define TCTRL4_WR_WR_TI_DLY_SHIFT 21
124#define TCTRL4_RDWR_RD_PI_MORE_DLY 0x00000000001f000UL0
125#define TCTRL4_RDWR_RD_PI_MORE_DLY_SHIFT 16
126#define TCTRL4_R 0x0000000000008000UL
127#define TCTRL4_R_SHIFT 15
128#define TCTRL4_SDRAM_MODE_REG_DATA 0x0000000000007fffUL
129#define TCTRL4_SDRAM_MODE_REG_DATA_SHIFT 0
130
131/* All 4 memory address decoding registers have the
132 * same layout.
133 */
134#define MEM_DECODE_VALID 0x8000000000000000UL /* Valid */
135#define MEM_DECODE_VALID_SHIFT 63
136#define MEM_DECODE_UK 0x001ffe0000000000UL /* Upper mask */
137#define MEM_DECODE_UK_SHIFT 41
138#define MEM_DECODE_UM 0x0000001ffff00000UL /* Upper match */
139#define MEM_DECODE_UM_SHIFT 20
140#define MEM_DECODE_LK 0x000000000003c000UL /* Lower mask */
141#define MEM_DECODE_LK_SHIFT 14
142#define MEM_DECODE_LM 0x0000000000000f00UL /* Lower match */
143#define MEM_DECODE_LM_SHIFT 8
144
145#define PA_UPPER_BITS 0x000007fffc000000UL
146#define PA_UPPER_BITS_SHIFT 26
147#define PA_LOWER_BITS 0x00000000000003c0UL
148#define PA_LOWER_BITS_SHIFT 6
149
150#define MACTRL_R0 0x8000000000000000UL
151#define MACTRL_R0_SHIFT 63
152#define MACTRL_ADDR_LE_PW 0x7000000000000000UL
153#define MACTRL_ADDR_LE_PW_SHIFT 60
154#define MACTRL_CMD_PW 0x0f00000000000000UL
155#define MACTRL_CMD_PW_SHIFT 56
156#define MACTRL_HALF_MODE_WR_MSEL_DLY 0x00fc000000000000UL
157#define MACTRL_HALF_MODE_WR_MSEL_DLY_SHIFT 50
158#define MACTRL_HALF_MODE_RD_MSEL_DLY 0x0003f00000000000UL
159#define MACTRL_HALF_MODE_RD_MSEL_DLY_SHIFT 44
160#define MACTRL_HALF_MODE_SDRAM_CTL_DLY 0x00000f0000000000UL
161#define MACTRL_HALF_MODE_SDRAM_CTL_DLY_SHIFT 40
162#define MACTRL_HALF_MODE_SDRAM_CLK_DLY 0x000000e000000000UL
163#define MACTRL_HALF_MODE_SDRAM_CLK_DLY_SHIFT 37
164#define MACTRL_R1 0x0000001000000000UL
165#define MACTRL_R1_SHIFT 36
166#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B3 0x0000000f00000000UL
167#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B3_SHIFT 32
168#define MACTRL_ENC_INTLV_B3 0x00000000f8000000UL
169#define MACTRL_ENC_INTLV_B3_SHIFT 27
170#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B2 0x0000000007800000UL
171#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B2_SHIFT 23
172#define MACTRL_ENC_INTLV_B2 0x00000000007c0000UL
173#define MACTRL_ENC_INTLV_B2_SHIFT 18
174#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B1 0x000000000003c000UL
175#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B1_SHIFT 14
176#define MACTRL_ENC_INTLV_B1 0x0000000000003e00UL
177#define MACTRL_ENC_INTLV_B1_SHIFT 9
178#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B0 0x00000000000001e0UL
179#define MACTRL_BANKSEL_N_ROWADDR_SIZE_B0_SHIFT 5
180#define MACTRL_ENC_INTLV_B0 0x000000000000001fUL
181#define MACTRL_ENC_INTLV_B0_SHIFT 0
182
183#endif /* _SPARC64_CHMCTRL_H */
diff --git a/include/asm-sparc64/cmt.h b/include/asm-sparc64/cmt.h
index 870db5928577..b19b445cb810 100644
--- a/include/asm-sparc64/cmt.h
+++ b/include/asm-sparc64/cmt.h
@@ -1,59 +1 @@
1#ifndef _SPARC64_CMT_H #include <asm-sparc/cmt.h>
2#define _SPARC64_CMT_H
3
4/* cmt.h: Chip Multi-Threading register definitions
5 *
6 * Copyright (C) 2004 David S. Miller (davem@redhat.com)
7 */
8
9/* ASI_CORE_ID - private */
10#define LP_ID 0x0000000000000010UL
11#define LP_ID_MAX 0x00000000003f0000UL
12#define LP_ID_ID 0x000000000000003fUL
13
14/* ASI_INTR_ID - private */
15#define LP_INTR_ID 0x0000000000000000UL
16#define LP_INTR_ID_ID 0x00000000000003ffUL
17
18/* ASI_CESR_ID - private */
19#define CESR_ID 0x0000000000000040UL
20#define CESR_ID_ID 0x00000000000000ffUL
21
22/* ASI_CORE_AVAILABLE - shared */
23#define LP_AVAIL 0x0000000000000000UL
24#define LP_AVAIL_1 0x0000000000000002UL
25#define LP_AVAIL_0 0x0000000000000001UL
26
27/* ASI_CORE_ENABLE_STATUS - shared */
28#define LP_ENAB_STAT 0x0000000000000010UL
29#define LP_ENAB_STAT_1 0x0000000000000002UL
30#define LP_ENAB_STAT_0 0x0000000000000001UL
31
32/* ASI_CORE_ENABLE - shared */
33#define LP_ENAB 0x0000000000000020UL
34#define LP_ENAB_1 0x0000000000000002UL
35#define LP_ENAB_0 0x0000000000000001UL
36
37/* ASI_CORE_RUNNING - shared */
38#define LP_RUNNING_RW 0x0000000000000050UL
39#define LP_RUNNING_W1S 0x0000000000000060UL
40#define LP_RUNNING_W1C 0x0000000000000068UL
41#define LP_RUNNING_1 0x0000000000000002UL
42#define LP_RUNNING_0 0x0000000000000001UL
43
44/* ASI_CORE_RUNNING_STAT - shared */
45#define LP_RUN_STAT 0x0000000000000058UL
46#define LP_RUN_STAT_1 0x0000000000000002UL
47#define LP_RUN_STAT_0 0x0000000000000001UL
48
49/* ASI_XIR_STEERING - shared */
50#define LP_XIR_STEER 0x0000000000000030UL
51#define LP_XIR_STEER_1 0x0000000000000002UL
52#define LP_XIR_STEER_0 0x0000000000000001UL
53
54/* ASI_CMT_ERROR_STEERING - shared */
55#define CMT_ER_STEER 0x0000000000000040UL
56#define CMT_ER_STEER_1 0x0000000000000002UL
57#define CMT_ER_STEER_0 0x0000000000000001UL
58
59#endif /* _SPARC64_CMT_H */
diff --git a/include/asm-sparc64/compat.h b/include/asm-sparc64/compat.h
index f260b58f5ce9..8c155d221952 100644
--- a/include/asm-sparc64/compat.h
+++ b/include/asm-sparc64/compat.h
@@ -1,243 +1 @@
1#ifndef _ASM_SPARC64_COMPAT_H #include <asm-sparc/compat.h>
2#define _ASM_SPARC64_COMPAT_H
3/*
4 * Architecture specific compatibility types
5 */
6#include <linux/types.h>
7
8#define COMPAT_USER_HZ 100
9
10typedef u32 compat_size_t;
11typedef s32 compat_ssize_t;
12typedef s32 compat_time_t;
13typedef s32 compat_clock_t;
14typedef s32 compat_pid_t;
15typedef u16 __compat_uid_t;
16typedef u16 __compat_gid_t;
17typedef u32 __compat_uid32_t;
18typedef u32 __compat_gid32_t;
19typedef u16 compat_mode_t;
20typedef u32 compat_ino_t;
21typedef u16 compat_dev_t;
22typedef s32 compat_off_t;
23typedef s64 compat_loff_t;
24typedef s16 compat_nlink_t;
25typedef u16 compat_ipc_pid_t;
26typedef s32 compat_daddr_t;
27typedef u32 compat_caddr_t;
28typedef __kernel_fsid_t compat_fsid_t;
29typedef s32 compat_key_t;
30typedef s32 compat_timer_t;
31
32typedef s32 compat_int_t;
33typedef s32 compat_long_t;
34typedef s64 compat_s64;
35typedef u32 compat_uint_t;
36typedef u32 compat_ulong_t;
37typedef u64 compat_u64;
38
39struct compat_timespec {
40 compat_time_t tv_sec;
41 s32 tv_nsec;
42};
43
44struct compat_timeval {
45 compat_time_t tv_sec;
46 s32 tv_usec;
47};
48
49struct compat_stat {
50 compat_dev_t st_dev;
51 compat_ino_t st_ino;
52 compat_mode_t st_mode;
53 compat_nlink_t st_nlink;
54 __compat_uid_t st_uid;
55 __compat_gid_t st_gid;
56 compat_dev_t st_rdev;
57 compat_off_t st_size;
58 compat_time_t st_atime;
59 compat_ulong_t st_atime_nsec;
60 compat_time_t st_mtime;
61 compat_ulong_t st_mtime_nsec;
62 compat_time_t st_ctime;
63 compat_ulong_t st_ctime_nsec;
64 compat_off_t st_blksize;
65 compat_off_t st_blocks;
66 u32 __unused4[2];
67};
68
69struct compat_stat64 {
70 unsigned long long st_dev;
71
72 unsigned long long st_ino;
73
74 unsigned int st_mode;
75 unsigned int st_nlink;
76
77 unsigned int st_uid;
78 unsigned int st_gid;
79
80 unsigned long long st_rdev;
81
82 unsigned char __pad3[8];
83
84 long long st_size;
85 unsigned int st_blksize;
86
87 unsigned char __pad4[8];
88 unsigned int st_blocks;
89
90 unsigned int st_atime;
91 unsigned int st_atime_nsec;
92
93 unsigned int st_mtime;
94 unsigned int st_mtime_nsec;
95
96 unsigned int st_ctime;
97 unsigned int st_ctime_nsec;
98
99 unsigned int __unused4;
100 unsigned int __unused5;
101};
102
103struct compat_flock {
104 short l_type;
105 short l_whence;
106 compat_off_t l_start;
107 compat_off_t l_len;
108 compat_pid_t l_pid;
109 short __unused;
110};
111
112#define F_GETLK64 12
113#define F_SETLK64 13
114#define F_SETLKW64 14
115
116struct compat_flock64 {
117 short l_type;
118 short l_whence;
119 compat_loff_t l_start;
120 compat_loff_t l_len;
121 compat_pid_t l_pid;
122 short __unused;
123};
124
125struct compat_statfs {
126 int f_type;
127 int f_bsize;
128 int f_blocks;
129 int f_bfree;
130 int f_bavail;
131 int f_files;
132 int f_ffree;
133 compat_fsid_t f_fsid;
134 int f_namelen; /* SunOS ignores this field. */
135 int f_frsize;
136 int f_spare[5];
137};
138
139#define COMPAT_RLIM_INFINITY 0x7fffffff
140
141typedef u32 compat_old_sigset_t;
142
143#define _COMPAT_NSIG 64
144#define _COMPAT_NSIG_BPW 32
145
146typedef u32 compat_sigset_word;
147
148#define COMPAT_OFF_T_MAX 0x7fffffff
149#define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
150
151/*
152 * A pointer passed in from user mode. This should not
153 * be used for syscall parameters, just declare them
154 * as pointers because the syscall entry code will have
155 * appropriately converted them already.
156 */
157typedef u32 compat_uptr_t;
158
159static inline void __user *compat_ptr(compat_uptr_t uptr)
160{
161 return (void __user *)(unsigned long)uptr;
162}
163
164static inline compat_uptr_t ptr_to_compat(void __user *uptr)
165{
166 return (u32)(unsigned long)uptr;
167}
168
169static inline void __user *compat_alloc_user_space(long len)
170{
171 struct pt_regs *regs = current_thread_info()->kregs;
172 unsigned long usp = regs->u_regs[UREG_I6];
173
174 if (!(test_thread_flag(TIF_32BIT)))
175 usp += STACK_BIAS;
176 else
177 usp &= 0xffffffffUL;
178
179 usp -= len;
180 usp &= ~0x7UL;
181
182 return (void __user *) usp;
183}
184
185struct compat_ipc64_perm {
186 compat_key_t key;
187 __compat_uid32_t uid;
188 __compat_gid32_t gid;
189 __compat_uid32_t cuid;
190 __compat_gid32_t cgid;
191 unsigned short __pad1;
192 compat_mode_t mode;
193 unsigned short __pad2;
194 unsigned short seq;
195 unsigned long __unused1; /* yes they really are 64bit pads */
196 unsigned long __unused2;
197};
198
199struct compat_semid64_ds {
200 struct compat_ipc64_perm sem_perm;
201 unsigned int __pad1;
202 compat_time_t sem_otime;
203 unsigned int __pad2;
204 compat_time_t sem_ctime;
205 u32 sem_nsems;
206 u32 __unused1;
207 u32 __unused2;
208};
209
210struct compat_msqid64_ds {
211 struct compat_ipc64_perm msg_perm;
212 unsigned int __pad1;
213 compat_time_t msg_stime;
214 unsigned int __pad2;
215 compat_time_t msg_rtime;
216 unsigned int __pad3;
217 compat_time_t msg_ctime;
218 unsigned int msg_cbytes;
219 unsigned int msg_qnum;
220 unsigned int msg_qbytes;
221 compat_pid_t msg_lspid;
222 compat_pid_t msg_lrpid;
223 unsigned int __unused1;
224 unsigned int __unused2;
225};
226
227struct compat_shmid64_ds {
228 struct compat_ipc64_perm shm_perm;
229 unsigned int __pad1;
230 compat_time_t shm_atime;
231 unsigned int __pad2;
232 compat_time_t shm_dtime;
233 unsigned int __pad3;
234 compat_time_t shm_ctime;
235 compat_size_t shm_segsz;
236 compat_pid_t shm_cpid;
237 compat_pid_t shm_lpid;
238 unsigned int shm_nattch;
239 unsigned int __unused1;
240 unsigned int __unused2;
241};
242
243#endif /* _ASM_SPARC64_COMPAT_H */
diff --git a/include/asm-sparc64/compat_signal.h b/include/asm-sparc64/compat_signal.h
index b759eab9b51c..7187dcc8cac7 100644
--- a/include/asm-sparc64/compat_signal.h
+++ b/include/asm-sparc64/compat_signal.h
@@ -1,29 +1 @@
1#ifndef _COMPAT_SIGNAL_H #include <asm-sparc/compat_signal.h>
2#define _COMPAT_SIGNAL_H
3
4#include <linux/compat.h>
5#include <asm/signal.h>
6
7#ifdef CONFIG_COMPAT
8struct __new_sigaction32 {
9 unsigned sa_handler;
10 unsigned int sa_flags;
11 unsigned sa_restorer; /* not used by Linux/SPARC yet */
12 compat_sigset_t sa_mask;
13};
14
15struct __old_sigaction32 {
16 unsigned sa_handler;
17 compat_old_sigset_t sa_mask;
18 unsigned int sa_flags;
19 unsigned sa_restorer; /* not used by Linux/SPARC yet */
20};
21
22typedef struct sigaltstack32 {
23 u32 ss_sp;
24 int ss_flags;
25 compat_size_t ss_size;
26} stack_t32;
27#endif
28
29#endif /* !(_COMPAT_SIGNAL_H) */
diff --git a/include/asm-sparc64/cpudata.h b/include/asm-sparc64/cpudata.h
index 532975ecfe10..3220e134a579 100644
--- a/include/asm-sparc64/cpudata.h
+++ b/include/asm-sparc64/cpudata.h
@@ -1,240 +1 @@
1/* cpudata.h: Per-cpu parameters. #include <asm-sparc/cpudata.h>
2 *
3 * Copyright (C) 2003, 2005, 2006 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_CPUDATA_H
7#define _SPARC64_CPUDATA_H
8
9#include <asm/hypervisor.h>
10#include <asm/asi.h>
11
12#ifndef __ASSEMBLY__
13
14#include <linux/percpu.h>
15#include <linux/threads.h>
16
17typedef struct {
18 /* Dcache line 1 */
19 unsigned int __softirq_pending; /* must be 1st, see rtrap.S */
20 unsigned int __pad0;
21 unsigned long clock_tick; /* %tick's per second */
22 unsigned long __pad;
23 unsigned int __pad1;
24 unsigned int __pad2;
25
26 /* Dcache line 2, rarely used */
27 unsigned int dcache_size;
28 unsigned int dcache_line_size;
29 unsigned int icache_size;
30 unsigned int icache_line_size;
31 unsigned int ecache_size;
32 unsigned int ecache_line_size;
33 int core_id;
34 int proc_id;
35} cpuinfo_sparc;
36
37DECLARE_PER_CPU(cpuinfo_sparc, __cpu_data);
38#define cpu_data(__cpu) per_cpu(__cpu_data, (__cpu))
39#define local_cpu_data() __get_cpu_var(__cpu_data)
40
41/* Trap handling code needs to get at a few critical values upon
42 * trap entry and to process TSB misses. These cannot be in the
43 * per_cpu() area as we really need to lock them into the TLB and
44 * thus make them part of the main kernel image. As a result we
45 * try to make this as small as possible.
46 *
47 * This is padded out and aligned to 64-bytes to avoid false sharing
48 * on SMP.
49 */
50
51/* If you modify the size of this structure, please update
52 * TRAP_BLOCK_SZ_SHIFT below.
53 */
54struct thread_info;
55struct trap_per_cpu {
56/* D-cache line 1: Basic thread information, cpu and device mondo queues */
57 struct thread_info *thread;
58 unsigned long pgd_paddr;
59 unsigned long cpu_mondo_pa;
60 unsigned long dev_mondo_pa;
61
62/* D-cache line 2: Error Mondo Queue and kernel buffer pointers */
63 unsigned long resum_mondo_pa;
64 unsigned long resum_kernel_buf_pa;
65 unsigned long nonresum_mondo_pa;
66 unsigned long nonresum_kernel_buf_pa;
67
68/* Dcache lines 3, 4, 5, and 6: Hypervisor Fault Status */
69 struct hv_fault_status fault_info;
70
71/* Dcache line 7: Physical addresses of CPU send mondo block and CPU list. */
72 unsigned long cpu_mondo_block_pa;
73 unsigned long cpu_list_pa;
74 unsigned long tsb_huge;
75 unsigned long tsb_huge_temp;
76
77/* Dcache line 8: IRQ work list, and keep trap_block a power-of-2 in size. */
78 unsigned long irq_worklist_pa;
79 unsigned int cpu_mondo_qmask;
80 unsigned int dev_mondo_qmask;
81 unsigned int resum_qmask;
82 unsigned int nonresum_qmask;
83 void *hdesc;
84} __attribute__((aligned(64)));
85extern struct trap_per_cpu trap_block[NR_CPUS];
86extern void init_cur_cpu_trap(struct thread_info *);
87extern void setup_tba(void);
88extern int ncpus_probed;
89extern void __init cpu_probe(void);
90extern const struct seq_operations cpuinfo_op;
91
92extern unsigned long real_hard_smp_processor_id(void);
93
94struct cpuid_patch_entry {
95 unsigned int addr;
96 unsigned int cheetah_safari[4];
97 unsigned int cheetah_jbus[4];
98 unsigned int starfire[4];
99 unsigned int sun4v[4];
100};
101extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
102
103struct sun4v_1insn_patch_entry {
104 unsigned int addr;
105 unsigned int insn;
106};
107extern struct sun4v_1insn_patch_entry __sun4v_1insn_patch,
108 __sun4v_1insn_patch_end;
109
110struct sun4v_2insn_patch_entry {
111 unsigned int addr;
112 unsigned int insns[2];
113};
114extern struct sun4v_2insn_patch_entry __sun4v_2insn_patch,
115 __sun4v_2insn_patch_end;
116
117#endif /* !(__ASSEMBLY__) */
118
119#define TRAP_PER_CPU_THREAD 0x00
120#define TRAP_PER_CPU_PGD_PADDR 0x08
121#define TRAP_PER_CPU_CPU_MONDO_PA 0x10
122#define TRAP_PER_CPU_DEV_MONDO_PA 0x18
123#define TRAP_PER_CPU_RESUM_MONDO_PA 0x20
124#define TRAP_PER_CPU_RESUM_KBUF_PA 0x28
125#define TRAP_PER_CPU_NONRESUM_MONDO_PA 0x30
126#define TRAP_PER_CPU_NONRESUM_KBUF_PA 0x38
127#define TRAP_PER_CPU_FAULT_INFO 0x40
128#define TRAP_PER_CPU_CPU_MONDO_BLOCK_PA 0xc0
129#define TRAP_PER_CPU_CPU_LIST_PA 0xc8
130#define TRAP_PER_CPU_TSB_HUGE 0xd0
131#define TRAP_PER_CPU_TSB_HUGE_TEMP 0xd8
132#define TRAP_PER_CPU_IRQ_WORKLIST_PA 0xe0
133#define TRAP_PER_CPU_CPU_MONDO_QMASK 0xe8
134#define TRAP_PER_CPU_DEV_MONDO_QMASK 0xec
135#define TRAP_PER_CPU_RESUM_QMASK 0xf0
136#define TRAP_PER_CPU_NONRESUM_QMASK 0xf4
137
138#define TRAP_BLOCK_SZ_SHIFT 8
139
140#include <asm/scratchpad.h>
141
142#define __GET_CPUID(REG) \
143 /* Spitfire implementation (default). */ \
144661: ldxa [%g0] ASI_UPA_CONFIG, REG; \
145 srlx REG, 17, REG; \
146 and REG, 0x1f, REG; \
147 nop; \
148 .section .cpuid_patch, "ax"; \
149 /* Instruction location. */ \
150 .word 661b; \
151 /* Cheetah Safari implementation. */ \
152 ldxa [%g0] ASI_SAFARI_CONFIG, REG; \
153 srlx REG, 17, REG; \
154 and REG, 0x3ff, REG; \
155 nop; \
156 /* Cheetah JBUS implementation. */ \
157 ldxa [%g0] ASI_JBUS_CONFIG, REG; \
158 srlx REG, 17, REG; \
159 and REG, 0x1f, REG; \
160 nop; \
161 /* Starfire implementation. */ \
162 sethi %hi(0x1fff40000d0 >> 9), REG; \
163 sllx REG, 9, REG; \
164 or REG, 0xd0, REG; \
165 lduwa [REG] ASI_PHYS_BYPASS_EC_E, REG;\
166 /* sun4v implementation. */ \
167 mov SCRATCHPAD_CPUID, REG; \
168 ldxa [REG] ASI_SCRATCHPAD, REG; \
169 nop; \
170 nop; \
171 .previous;
172
173#ifdef CONFIG_SMP
174
175#define TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
176 __GET_CPUID(TMP) \
177 sethi %hi(trap_block), DEST; \
178 sllx TMP, TRAP_BLOCK_SZ_SHIFT, TMP; \
179 or DEST, %lo(trap_block), DEST; \
180 add DEST, TMP, DEST; \
181
182/* Clobbers TMP, current address space PGD phys address into DEST. */
183#define TRAP_LOAD_PGD_PHYS(DEST, TMP) \
184 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
185 ldx [DEST + TRAP_PER_CPU_PGD_PADDR], DEST;
186
187/* Clobbers TMP, loads local processor's IRQ work area into DEST. */
188#define TRAP_LOAD_IRQ_WORK_PA(DEST, TMP) \
189 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
190 add DEST, TRAP_PER_CPU_IRQ_WORKLIST_PA, DEST;
191
192/* Clobbers TMP, loads DEST with current thread info pointer. */
193#define TRAP_LOAD_THREAD_REG(DEST, TMP) \
194 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
195 ldx [DEST + TRAP_PER_CPU_THREAD], DEST;
196
197/* Given the current thread info pointer in THR, load the per-cpu
198 * area base of the current processor into DEST. REG1, REG2, and REG3 are
199 * clobbered.
200 *
201 * You absolutely cannot use DEST as a temporary in this code. The
202 * reason is that traps can happen during execution, and return from
203 * trap will load the fully resolved DEST per-cpu base. This can corrupt
204 * the calculations done by the macro mid-stream.
205 */
206#define LOAD_PER_CPU_BASE(DEST, THR, REG1, REG2, REG3) \
207 lduh [THR + TI_CPU], REG1; \
208 sethi %hi(__per_cpu_shift), REG3; \
209 sethi %hi(__per_cpu_base), REG2; \
210 ldx [REG3 + %lo(__per_cpu_shift)], REG3; \
211 ldx [REG2 + %lo(__per_cpu_base)], REG2; \
212 sllx REG1, REG3, REG3; \
213 add REG3, REG2, DEST;
214
215#else
216
217#define TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
218 sethi %hi(trap_block), DEST; \
219 or DEST, %lo(trap_block), DEST; \
220
221/* Uniprocessor versions, we know the cpuid is zero. */
222#define TRAP_LOAD_PGD_PHYS(DEST, TMP) \
223 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
224 ldx [DEST + TRAP_PER_CPU_PGD_PADDR], DEST;
225
226/* Clobbers TMP, loads local processor's IRQ work area into DEST. */
227#define TRAP_LOAD_IRQ_WORK_PA(DEST, TMP) \
228 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
229 add DEST, TRAP_PER_CPU_IRQ_WORKLIST_PA, DEST;
230
231#define TRAP_LOAD_THREAD_REG(DEST, TMP) \
232 TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
233 ldx [DEST + TRAP_PER_CPU_THREAD], DEST;
234
235/* No per-cpu areas on uniprocessor, so no need to load DEST. */
236#define LOAD_PER_CPU_BASE(DEST, THR, REG1, REG2, REG3)
237
238#endif /* !(CONFIG_SMP) */
239
240#endif /* _SPARC64_CPUDATA_H */
diff --git a/include/asm-sparc64/dcr.h b/include/asm-sparc64/dcr.h
index 620c9ba642e9..d67613b1f5fe 100644
--- a/include/asm-sparc64/dcr.h
+++ b/include/asm-sparc64/dcr.h
@@ -1,14 +1 @@
1#ifndef _SPARC64_DCR_H #include <asm-sparc/dcr.h>
2#define _SPARC64_DCR_H
3
4/* UltraSparc-III/III+ Dispatch Control Register, ASR 0x12 */
5#define DCR_DPE 0x0000000000001000 /* III+: D$ Parity Error Enable */
6#define DCR_OBS 0x0000000000000fc0 /* Observability Bus Controls */
7#define DCR_BPE 0x0000000000000020 /* Branch Predict Enable */
8#define DCR_RPE 0x0000000000000010 /* Return Address Prediction Enable */
9#define DCR_SI 0x0000000000000008 /* Single Instruction Disable */
10#define DCR_IPE 0x0000000000000004 /* III+: I$ Parity Error Enable */
11#define DCR_IFPOE 0x0000000000000002 /* IRQ FP Operation Enable */
12#define DCR_MS 0x0000000000000001 /* Multi-Scalar dispatch */
13
14#endif /* _SPARC64_DCR_H */
diff --git a/include/asm-sparc64/dcu.h b/include/asm-sparc64/dcu.h
index 0f704e106a1b..28853f4968d1 100644
--- a/include/asm-sparc64/dcu.h
+++ b/include/asm-sparc64/dcu.h
@@ -1,27 +1 @@
1#ifndef _SPARC64_DCU_H #include <asm-sparc/dcu.h>
2#define _SPARC64_DCU_H
3
4#include <linux/const.h>
5
6/* UltraSparc-III Data Cache Unit Control Register */
7#define DCU_CP _AC(0x0002000000000000,UL) /* Phys Cache Enable w/o mmu */
8#define DCU_CV _AC(0x0001000000000000,UL) /* Virt Cache Enable w/o mmu */
9#define DCU_ME _AC(0x0000800000000000,UL) /* NC-store Merging Enable */
10#define DCU_RE _AC(0x0000400000000000,UL) /* RAW bypass Enable */
11#define DCU_PE _AC(0x0000200000000000,UL) /* PCache Enable */
12#define DCU_HPE _AC(0x0000100000000000,UL) /* HW prefetch Enable */
13#define DCU_SPE _AC(0x0000080000000000,UL) /* SW prefetch Enable */
14#define DCU_SL _AC(0x0000040000000000,UL) /* Secondary ld-steering Enab*/
15#define DCU_WE _AC(0x0000020000000000,UL) /* WCache enable */
16#define DCU_PM _AC(0x000001fe00000000,UL) /* PA Watchpoint Byte Mask */
17#define DCU_VM _AC(0x00000001fe000000,UL) /* VA Watchpoint Byte Mask */
18#define DCU_PR _AC(0x0000000001000000,UL) /* PA Watchpoint Read Enable */
19#define DCU_PW _AC(0x0000000000800000,UL) /* PA Watchpoint Write Enable*/
20#define DCU_VR _AC(0x0000000000400000,UL) /* VA Watchpoint Read Enable */
21#define DCU_VW _AC(0x0000000000200000,UL) /* VA Watchpoint Write Enable*/
22#define DCU_DM _AC(0x0000000000000008,UL) /* DMMU Enable */
23#define DCU_IM _AC(0x0000000000000004,UL) /* IMMU Enable */
24#define DCU_DC _AC(0x0000000000000002,UL) /* Data Cache Enable */
25#define DCU_IC _AC(0x0000000000000001,UL) /* Instruction Cache Enable */
26
27#endif /* _SPARC64_DCU_H */
diff --git a/include/asm-sparc64/delay.h b/include/asm-sparc64/delay.h
index a77aa622d762..33dc5589d841 100644
--- a/include/asm-sparc64/delay.h
+++ b/include/asm-sparc64/delay.h
@@ -1,17 +1 @@
1/* delay.h: Linux delay routines on sparc64. #include <asm-sparc/delay.h>
2 *
3 * Copyright (C) 1996, 2004, 2007 David S. Miller (davem@davemloft.net).
4 */
5
6#ifndef _SPARC64_DELAY_H
7#define _SPARC64_DELAY_H
8
9#ifndef __ASSEMBLY__
10
11extern void __delay(unsigned long loops);
12extern void udelay(unsigned long usecs);
13#define mdelay(n) udelay((n) * 1000)
14
15#endif /* !__ASSEMBLY__ */
16
17#endif /* _SPARC64_DELAY_H */
diff --git a/include/asm-sparc64/display7seg.h b/include/asm-sparc64/display7seg.h
index c066a8964eab..e74f046b41de 100644
--- a/include/asm-sparc64/display7seg.h
+++ b/include/asm-sparc64/display7seg.h
@@ -1,79 +1 @@
1/* #include <asm-sparc/display7seg.h>
2 *
3 * display7seg - Driver interface for the 7-segment display
4 * present on Sun Microsystems CP1400 and CP1500
5 *
6 * Copyright (c) 2000 Eric Brower <ebrower@usa.net>
7 *
8 */
9
10#ifndef __display7seg_h__
11#define __display7seg_h__
12
13#define D7S_IOC 'p'
14
15#define D7SIOCRD _IOR(D7S_IOC, 0x45, int) /* Read device state */
16#define D7SIOCWR _IOW(D7S_IOC, 0x46, int) /* Write device state */
17#define D7SIOCTM _IO (D7S_IOC, 0x47) /* Translate mode (FLIP)*/
18
19/*
20 * ioctl flag definitions
21 *
22 * POINT - Toggle decimal point (0=absent 1=present)
23 * ALARM - Toggle alarm LED (0=green 1=red)
24 * FLIP - Toggle inverted mode (0=normal 1=flipped)
25 * bits 0-4 - Character displayed (see definitions below)
26 *
27 * Display segments are defined as follows,
28 * subject to D7S_FLIP register state:
29 *
30 * a
31 * ---
32 * f| |b
33 * -g-
34 * e| |c
35 * ---
36 * d
37 */
38
39#define D7S_POINT (1 << 7) /* Decimal point*/
40#define D7S_ALARM (1 << 6) /* Alarm LED */
41#define D7S_FLIP (1 << 5) /* Flip display */
42
43#define D7S_0 0x00 /* Numerals 0-9 */
44#define D7S_1 0x01
45#define D7S_2 0x02
46#define D7S_3 0x03
47#define D7S_4 0x04
48#define D7S_5 0x05
49#define D7S_6 0x06
50#define D7S_7 0x07
51#define D7S_8 0x08
52#define D7S_9 0x09
53#define D7S_A 0x0A /* Letters A-F, H, L, P */
54#define D7S_B 0x0B
55#define D7S_C 0x0C
56#define D7S_D 0x0D
57#define D7S_E 0x0E
58#define D7S_F 0x0F
59#define D7S_H 0x10
60#define D7S_E2 0x11
61#define D7S_L 0x12
62#define D7S_P 0x13
63#define D7S_SEGA 0x14 /* Individual segments */
64#define D7S_SEGB 0x15
65#define D7S_SEGC 0x16
66#define D7S_SEGD 0x17
67#define D7S_SEGE 0x18
68#define D7S_SEGF 0x19
69#define D7S_SEGG 0x1A
70#define D7S_SEGABFG 0x1B /* Segment groupings */
71#define D7S_SEGCDEG 0x1C
72#define D7S_SEGBCEF 0x1D
73#define D7S_SEGADG 0x1E
74#define D7S_BLANK 0x1F /* Clear all segments */
75
76#define D7S_MIN_VAL 0x0
77#define D7S_MAX_VAL 0x1F
78
79#endif /* ifndef __display7seg_h__ */
diff --git a/include/asm-sparc64/dma-mapping.h b/include/asm-sparc64/dma-mapping.h
index 38cbec76a33f..380b7b63147f 100644
--- a/include/asm-sparc64/dma-mapping.h
+++ b/include/asm-sparc64/dma-mapping.h
@@ -1,154 +1 @@
1#ifndef _ASM_SPARC64_DMA_MAPPING_H #include <asm-sparc/dma-mapping.h>
2#define _ASM_SPARC64_DMA_MAPPING_H
3
4#include <linux/scatterlist.h>
5#include <linux/mm.h>
6
7#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
8
9struct dma_ops {
10 void *(*alloc_coherent)(struct device *dev, size_t size,
11 dma_addr_t *dma_handle, gfp_t flag);
12 void (*free_coherent)(struct device *dev, size_t size,
13 void *cpu_addr, dma_addr_t dma_handle);
14 dma_addr_t (*map_single)(struct device *dev, void *cpu_addr,
15 size_t size,
16 enum dma_data_direction direction);
17 void (*unmap_single)(struct device *dev, dma_addr_t dma_addr,
18 size_t size,
19 enum dma_data_direction direction);
20 int (*map_sg)(struct device *dev, struct scatterlist *sg, int nents,
21 enum dma_data_direction direction);
22 void (*unmap_sg)(struct device *dev, struct scatterlist *sg,
23 int nhwentries,
24 enum dma_data_direction direction);
25 void (*sync_single_for_cpu)(struct device *dev,
26 dma_addr_t dma_handle, size_t size,
27 enum dma_data_direction direction);
28 void (*sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg,
29 int nelems,
30 enum dma_data_direction direction);
31};
32extern const struct dma_ops *dma_ops;
33
34extern int dma_supported(struct device *dev, u64 mask);
35extern int dma_set_mask(struct device *dev, u64 dma_mask);
36
37static inline void *dma_alloc_coherent(struct device *dev, size_t size,
38 dma_addr_t *dma_handle, gfp_t flag)
39{
40 return dma_ops->alloc_coherent(dev, size, dma_handle, flag);
41}
42
43static inline void dma_free_coherent(struct device *dev, size_t size,
44 void *cpu_addr, dma_addr_t dma_handle)
45{
46 dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
47}
48
49static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
50 size_t size,
51 enum dma_data_direction direction)
52{
53 return dma_ops->map_single(dev, cpu_addr, size, direction);
54}
55
56static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
57 size_t size,
58 enum dma_data_direction direction)
59{
60 dma_ops->unmap_single(dev, dma_addr, size, direction);
61}
62
63static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
64 unsigned long offset, size_t size,
65 enum dma_data_direction direction)
66{
67 return dma_ops->map_single(dev, page_address(page) + offset,
68 size, direction);
69}
70
71static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
72 size_t size,
73 enum dma_data_direction direction)
74{
75 dma_ops->unmap_single(dev, dma_address, size, direction);
76}
77
78static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
79 int nents, enum dma_data_direction direction)
80{
81 return dma_ops->map_sg(dev, sg, nents, direction);
82}
83
84static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
85 int nents, enum dma_data_direction direction)
86{
87 dma_ops->unmap_sg(dev, sg, nents, direction);
88}
89
90static inline void dma_sync_single_for_cpu(struct device *dev,
91 dma_addr_t dma_handle, size_t size,
92 enum dma_data_direction direction)
93{
94 dma_ops->sync_single_for_cpu(dev, dma_handle, size, direction);
95}
96
97static inline void dma_sync_single_for_device(struct device *dev,
98 dma_addr_t dma_handle,
99 size_t size,
100 enum dma_data_direction direction)
101{
102 /* No flushing needed to sync cpu writes to the device. */
103}
104
105static inline void dma_sync_single_range_for_cpu(struct device *dev,
106 dma_addr_t dma_handle,
107 unsigned long offset,
108 size_t size,
109 enum dma_data_direction direction)
110{
111 dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
112}
113
114static inline void dma_sync_single_range_for_device(struct device *dev,
115 dma_addr_t dma_handle,
116 unsigned long offset,
117 size_t size,
118 enum dma_data_direction direction)
119{
120 /* No flushing needed to sync cpu writes to the device. */
121}
122
123
124static inline void dma_sync_sg_for_cpu(struct device *dev,
125 struct scatterlist *sg, int nelems,
126 enum dma_data_direction direction)
127{
128 dma_ops->sync_sg_for_cpu(dev, sg, nelems, direction);
129}
130
131static inline void dma_sync_sg_for_device(struct device *dev,
132 struct scatterlist *sg, int nelems,
133 enum dma_data_direction direction)
134{
135 /* No flushing needed to sync cpu writes to the device. */
136}
137
138static inline int dma_mapping_error(dma_addr_t dma_addr)
139{
140 return (dma_addr == DMA_ERROR_CODE);
141}
142
143static inline int dma_get_cache_alignment(void)
144{
145 /* no easy way to get cache size on all processors, so return
146 * the maximum possible, to be safe */
147 return (1 << INTERNODE_CACHE_SHIFT);
148}
149
150#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
151#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
152#define dma_is_consistent(d, h) (1)
153
154#endif /* _ASM_SPARC64_DMA_MAPPING_H */
diff --git a/include/asm-sparc64/dma.h b/include/asm-sparc64/dma.h
index 9d4c024bd3b3..2e36248e6b59 100644
--- a/include/asm-sparc64/dma.h
+++ b/include/asm-sparc64/dma.h
@@ -1,205 +1 @@
1/* #include <asm-sparc/dma.h>
2 * include/asm-sparc64/dma.h
3 *
4 * Copyright 1996 (C) David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef _ASM_SPARC64_DMA_H
8#define _ASM_SPARC64_DMA_H
9
10#include <linux/kernel.h>
11#include <linux/types.h>
12#include <linux/spinlock.h>
13
14#include <asm/sbus.h>
15#include <asm/delay.h>
16#include <asm/oplib.h>
17
18/* These are irrelevant for Sparc DMA, but we leave it in so that
19 * things can compile.
20 */
21#define MAX_DMA_CHANNELS 8
22#define DMA_MODE_READ 1
23#define DMA_MODE_WRITE 2
24#define MAX_DMA_ADDRESS (~0UL)
25
26/* Useful constants */
27#define SIZE_16MB (16*1024*1024)
28#define SIZE_64K (64*1024)
29
30/* SBUS DMA controller reg offsets */
31#define DMA_CSR 0x00UL /* rw DMA control/status register 0x00 */
32#define DMA_ADDR 0x04UL /* rw DMA transfer address register 0x04 */
33#define DMA_COUNT 0x08UL /* rw DMA transfer count register 0x08 */
34#define DMA_TEST 0x0cUL /* rw DMA test/debug register 0x0c */
35
36/* DVMA chip revisions */
37enum dvma_rev {
38 dvmarev0,
39 dvmaesc1,
40 dvmarev1,
41 dvmarev2,
42 dvmarev3,
43 dvmarevplus,
44 dvmahme
45};
46
47#define DMA_HASCOUNT(rev) ((rev)==dvmaesc1)
48
49/* Linux DMA information structure, filled during probe. */
50struct sbus_dma {
51 struct sbus_dma *next;
52 struct sbus_dev *sdev;
53 void __iomem *regs;
54
55 /* Status, misc info */
56 int node; /* Prom node for this DMA device */
57 int running; /* Are we doing DMA now? */
58 int allocated; /* Are we "owned" by anyone yet? */
59
60 /* Transfer information. */
61 u32 addr; /* Start address of current transfer */
62 int nbytes; /* Size of current transfer */
63 int realbytes; /* For splitting up large transfers, etc. */
64
65 /* DMA revision */
66 enum dvma_rev revision;
67};
68
69extern struct sbus_dma *dma_chain;
70
71/* Broken hardware... */
72#define DMA_ISBROKEN(dma) ((dma)->revision == dvmarev1)
73#define DMA_ISESC1(dma) ((dma)->revision == dvmaesc1)
74
75/* Main routines in dma.c */
76extern void dvma_init(struct sbus_bus *);
77
78/* Fields in the cond_reg register */
79/* First, the version identification bits */
80#define DMA_DEVICE_ID 0xf0000000 /* Device identification bits */
81#define DMA_VERS0 0x00000000 /* Sunray DMA version */
82#define DMA_ESCV1 0x40000000 /* DMA ESC Version 1 */
83#define DMA_VERS1 0x80000000 /* DMA rev 1 */
84#define DMA_VERS2 0xa0000000 /* DMA rev 2 */
85#define DMA_VERHME 0xb0000000 /* DMA hme gate array */
86#define DMA_VERSPLUS 0x90000000 /* DMA rev 1 PLUS */
87
88#define DMA_HNDL_INTR 0x00000001 /* An IRQ needs to be handled */
89#define DMA_HNDL_ERROR 0x00000002 /* We need to take an error */
90#define DMA_FIFO_ISDRAIN 0x0000000c /* The DMA FIFO is draining */
91#define DMA_INT_ENAB 0x00000010 /* Turn on interrupts */
92#define DMA_FIFO_INV 0x00000020 /* Invalidate the FIFO */
93#define DMA_ACC_SZ_ERR 0x00000040 /* The access size was bad */
94#define DMA_FIFO_STDRAIN 0x00000040 /* DMA_VERS1 Drain the FIFO */
95#define DMA_RST_SCSI 0x00000080 /* Reset the SCSI controller */
96#define DMA_RST_ENET DMA_RST_SCSI /* Reset the ENET controller */
97#define DMA_ST_WRITE 0x00000100 /* write from device to memory */
98#define DMA_ENABLE 0x00000200 /* Fire up DMA, handle requests */
99#define DMA_PEND_READ 0x00000400 /* DMA_VERS1/0/PLUS Pending Read */
100#define DMA_ESC_BURST 0x00000800 /* 1=16byte 0=32byte */
101#define DMA_READ_AHEAD 0x00001800 /* DMA read ahead partial longword */
102#define DMA_DSBL_RD_DRN 0x00001000 /* No EC drain on slave reads */
103#define DMA_BCNT_ENAB 0x00002000 /* If on, use the byte counter */
104#define DMA_TERM_CNTR 0x00004000 /* Terminal counter */
105#define DMA_SCSI_SBUS64 0x00008000 /* HME: Enable 64-bit SBUS mode. */
106#define DMA_CSR_DISAB 0x00010000 /* No FIFO drains during csr */
107#define DMA_SCSI_DISAB 0x00020000 /* No FIFO drains during reg */
108#define DMA_DSBL_WR_INV 0x00020000 /* No EC inval. on slave writes */
109#define DMA_ADD_ENABLE 0x00040000 /* Special ESC DVMA optimization */
110#define DMA_E_BURSTS 0x000c0000 /* ENET: SBUS r/w burst mask */
111#define DMA_E_BURST32 0x00040000 /* ENET: SBUS 32 byte r/w burst */
112#define DMA_E_BURST16 0x00000000 /* ENET: SBUS 16 byte r/w burst */
113#define DMA_BRST_SZ 0x000c0000 /* SCSI: SBUS r/w burst size */
114#define DMA_BRST64 0x000c0000 /* SCSI: 64byte bursts (HME on UltraSparc only) */
115#define DMA_BRST32 0x00040000 /* SCSI: 32byte bursts */
116#define DMA_BRST16 0x00000000 /* SCSI: 16byte bursts */
117#define DMA_BRST0 0x00080000 /* SCSI: no bursts (non-HME gate arrays) */
118#define DMA_ADDR_DISAB 0x00100000 /* No FIFO drains during addr */
119#define DMA_2CLKS 0x00200000 /* Each transfer = 2 clock ticks */
120#define DMA_3CLKS 0x00400000 /* Each transfer = 3 clock ticks */
121#define DMA_EN_ENETAUI DMA_3CLKS /* Put lance into AUI-cable mode */
122#define DMA_CNTR_DISAB 0x00800000 /* No IRQ when DMA_TERM_CNTR set */
123#define DMA_AUTO_NADDR 0x01000000 /* Use "auto nxt addr" feature */
124#define DMA_SCSI_ON 0x02000000 /* Enable SCSI dma */
125#define DMA_PARITY_OFF 0x02000000 /* HME: disable parity checking */
126#define DMA_LOADED_ADDR 0x04000000 /* Address has been loaded */
127#define DMA_LOADED_NADDR 0x08000000 /* Next address has been loaded */
128#define DMA_RESET_FAS366 0x08000000 /* HME: Assert RESET to FAS366 */
129
130/* Values describing the burst-size property from the PROM */
131#define DMA_BURST1 0x01
132#define DMA_BURST2 0x02
133#define DMA_BURST4 0x04
134#define DMA_BURST8 0x08
135#define DMA_BURST16 0x10
136#define DMA_BURST32 0x20
137#define DMA_BURST64 0x40
138#define DMA_BURSTBITS 0x7f
139
140/* Determine highest possible final transfer address given a base */
141#define DMA_MAXEND(addr) (0x01000000UL-(((unsigned long)(addr))&0x00ffffffUL))
142
143/* Yes, I hack a lot of elisp in my spare time... */
144#define DMA_ERROR_P(regs) ((sbus_readl((regs) + DMA_CSR) & DMA_HNDL_ERROR))
145#define DMA_IRQ_P(regs) ((sbus_readl((regs) + DMA_CSR)) & (DMA_HNDL_INTR | DMA_HNDL_ERROR))
146#define DMA_WRITE_P(regs) ((sbus_readl((regs) + DMA_CSR) & DMA_ST_WRITE))
147#define DMA_OFF(__regs) \
148do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
149 tmp &= ~DMA_ENABLE; \
150 sbus_writel(tmp, (__regs) + DMA_CSR); \
151} while(0)
152#define DMA_INTSOFF(__regs) \
153do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
154 tmp &= ~DMA_INT_ENAB; \
155 sbus_writel(tmp, (__regs) + DMA_CSR); \
156} while(0)
157#define DMA_INTSON(__regs) \
158do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
159 tmp |= DMA_INT_ENAB; \
160 sbus_writel(tmp, (__regs) + DMA_CSR); \
161} while(0)
162#define DMA_PUNTFIFO(__regs) \
163do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
164 tmp |= DMA_FIFO_INV; \
165 sbus_writel(tmp, (__regs) + DMA_CSR); \
166} while(0)
167#define DMA_SETSTART(__regs, __addr) \
168 sbus_writel((u32)(__addr), (__regs) + DMA_ADDR);
169#define DMA_BEGINDMA_W(__regs) \
170do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
171 tmp |= (DMA_ST_WRITE|DMA_ENABLE|DMA_INT_ENAB); \
172 sbus_writel(tmp, (__regs) + DMA_CSR); \
173} while(0)
174#define DMA_BEGINDMA_R(__regs) \
175do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
176 tmp |= (DMA_ENABLE|DMA_INT_ENAB); \
177 tmp &= ~DMA_ST_WRITE; \
178 sbus_writel(tmp, (__regs) + DMA_CSR); \
179} while(0)
180
181/* For certain DMA chips, we need to disable ints upon irq entry
182 * and turn them back on when we are done. So in any ESP interrupt
183 * handler you *must* call DMA_IRQ_ENTRY upon entry and DMA_IRQ_EXIT
184 * when leaving the handler. You have been warned...
185 */
186#define DMA_IRQ_ENTRY(dma, dregs) do { \
187 if(DMA_ISBROKEN(dma)) DMA_INTSOFF(dregs); \
188 } while (0)
189
190#define DMA_IRQ_EXIT(dma, dregs) do { \
191 if(DMA_ISBROKEN(dma)) DMA_INTSON(dregs); \
192 } while(0)
193
194#define for_each_dvma(dma) \
195 for((dma) = dma_chain; (dma); (dma) = (dma)->next)
196
197/* From PCI */
198
199#ifdef CONFIG_PCI
200extern int isa_dma_bridge_buggy;
201#else
202#define isa_dma_bridge_buggy (0)
203#endif
204
205#endif /* !(_ASM_SPARC64_DMA_H) */
diff --git a/include/asm-sparc64/ebus.h b/include/asm-sparc64/ebus.h
index fcc62b97ced5..d7d476158bd5 100644
--- a/include/asm-sparc64/ebus.h
+++ b/include/asm-sparc64/ebus.h
@@ -1,94 +1 @@
1/* #include <asm-sparc/ebus.h>
2 * ebus.h: PCI to Ebus pseudo driver software state.
3 *
4 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
5 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
6 */
7
8#ifndef __SPARC64_EBUS_H
9#define __SPARC64_EBUS_H
10
11#include <asm/oplib.h>
12#include <asm/prom.h>
13#include <asm/of_device.h>
14
15struct linux_ebus_child {
16 struct linux_ebus_child *next;
17 struct linux_ebus_device *parent;
18 struct linux_ebus *bus;
19 struct device_node *prom_node;
20 struct resource resource[PROMREG_MAX];
21 int num_addrs;
22 unsigned int irqs[PROMINTR_MAX];
23 int num_irqs;
24};
25
26struct linux_ebus_device {
27 struct of_device ofdev;
28 struct linux_ebus_device *next;
29 struct linux_ebus_child *children;
30 struct linux_ebus *bus;
31 struct device_node *prom_node;
32 struct resource resource[PROMREG_MAX];
33 int num_addrs;
34 unsigned int irqs[PROMINTR_MAX];
35 int num_irqs;
36};
37#define to_ebus_device(d) container_of(d, struct linux_ebus_device, ofdev.dev)
38
39struct linux_ebus {
40 struct of_device ofdev;
41 struct linux_ebus *next;
42 struct linux_ebus_device *devices;
43 struct pci_dev *self;
44 int index;
45 int is_rio;
46 struct device_node *prom_node;
47};
48#define to_ebus(d) container_of(d, struct linux_ebus, ofdev.dev)
49
50struct ebus_dma_info {
51 spinlock_t lock;
52 void __iomem *regs;
53
54 unsigned int flags;
55#define EBUS_DMA_FLAG_USE_EBDMA_HANDLER 0x00000001
56#define EBUS_DMA_FLAG_TCI_DISABLE 0x00000002
57
58 /* These are only valid is EBUS_DMA_FLAG_USE_EBDMA_HANDLER is
59 * set.
60 */
61 void (*callback)(struct ebus_dma_info *p, int event, void *cookie);
62 void *client_cookie;
63 unsigned int irq;
64#define EBUS_DMA_EVENT_ERROR 1
65#define EBUS_DMA_EVENT_DMA 2
66#define EBUS_DMA_EVENT_DEVICE 4
67
68 unsigned char name[64];
69};
70
71extern int ebus_dma_register(struct ebus_dma_info *p);
72extern int ebus_dma_irq_enable(struct ebus_dma_info *p, int on);
73extern void ebus_dma_unregister(struct ebus_dma_info *p);
74extern int ebus_dma_request(struct ebus_dma_info *p, dma_addr_t bus_addr,
75 size_t len);
76extern void ebus_dma_prepare(struct ebus_dma_info *p, int write);
77extern unsigned int ebus_dma_residue(struct ebus_dma_info *p);
78extern unsigned int ebus_dma_addr(struct ebus_dma_info *p);
79extern void ebus_dma_enable(struct ebus_dma_info *p, int on);
80
81extern struct linux_ebus *ebus_chain;
82
83extern void ebus_init(void);
84
85#define for_each_ebus(bus) \
86 for((bus) = ebus_chain; (bus); (bus) = (bus)->next)
87
88#define for_each_ebusdev(dev, bus) \
89 for((dev) = (bus)->devices; (dev); (dev) = (dev)->next)
90
91#define for_each_edevchild(dev, child) \
92 for((child) = (dev)->children; (child); (child) = (child)->next)
93
94#endif /* !(__SPARC64_EBUS_H) */
diff --git a/include/asm-sparc64/elf.h b/include/asm-sparc64/elf.h
index 0818a1308f4e..f256d9472c82 100644
--- a/include/asm-sparc64/elf.h
+++ b/include/asm-sparc64/elf.h
@@ -1,217 +1 @@
1#ifndef __ASM_SPARC64_ELF_H #include <asm-sparc/elf.h>
2#define __ASM_SPARC64_ELF_H
3
4/*
5 * ELF register definitions..
6 */
7
8#include <asm/ptrace.h>
9#include <asm/processor.h>
10#include <asm/uaccess.h>
11#include <asm/spitfire.h>
12
13/*
14 * Sparc section types
15 */
16#define STT_REGISTER 13
17
18/*
19 * Sparc ELF relocation types
20 */
21#define R_SPARC_NONE 0
22#define R_SPARC_8 1
23#define R_SPARC_16 2
24#define R_SPARC_32 3
25#define R_SPARC_DISP8 4
26#define R_SPARC_DISP16 5
27#define R_SPARC_DISP32 6
28#define R_SPARC_WDISP30 7
29#define R_SPARC_WDISP22 8
30#define R_SPARC_HI22 9
31#define R_SPARC_22 10
32#define R_SPARC_13 11
33#define R_SPARC_LO10 12
34#define R_SPARC_GOT10 13
35#define R_SPARC_GOT13 14
36#define R_SPARC_GOT22 15
37#define R_SPARC_PC10 16
38#define R_SPARC_PC22 17
39#define R_SPARC_WPLT30 18
40#define R_SPARC_COPY 19
41#define R_SPARC_GLOB_DAT 20
42#define R_SPARC_JMP_SLOT 21
43#define R_SPARC_RELATIVE 22
44#define R_SPARC_UA32 23
45#define R_SPARC_PLT32 24
46#define R_SPARC_HIPLT22 25
47#define R_SPARC_LOPLT10 26
48#define R_SPARC_PCPLT32 27
49#define R_SPARC_PCPLT22 28
50#define R_SPARC_PCPLT10 29
51#define R_SPARC_10 30
52#define R_SPARC_11 31
53#define R_SPARC_64 32
54#define R_SPARC_OLO10 33
55#define R_SPARC_WDISP16 40
56#define R_SPARC_WDISP19 41
57#define R_SPARC_7 43
58#define R_SPARC_5 44
59#define R_SPARC_6 45
60
61/* Bits present in AT_HWCAP, primarily for Sparc32. */
62
63#define HWCAP_SPARC_FLUSH 1 /* CPU supports flush instruction. */
64#define HWCAP_SPARC_STBAR 2
65#define HWCAP_SPARC_SWAP 4
66#define HWCAP_SPARC_MULDIV 8
67#define HWCAP_SPARC_V9 16
68#define HWCAP_SPARC_ULTRA3 32
69#define HWCAP_SPARC_BLKINIT 64
70#define HWCAP_SPARC_N2 128
71
72#define CORE_DUMP_USE_REGSET
73
74/*
75 * These are used to set parameters in the core dumps.
76 */
77#define ELF_ARCH EM_SPARCV9
78#define ELF_CLASS ELFCLASS64
79#define ELF_DATA ELFDATA2MSB
80
81/* Format of 64-bit elf_gregset_t is:
82 * G0 --> G7
83 * O0 --> O7
84 * L0 --> L7
85 * I0 --> I7
86 * TSTATE
87 * TPC
88 * TNPC
89 * Y
90 */
91typedef unsigned long elf_greg_t;
92#define ELF_NGREG 36
93typedef elf_greg_t elf_gregset_t[ELF_NGREG];
94
95typedef struct {
96 unsigned long pr_regs[32];
97 unsigned long pr_fsr;
98 unsigned long pr_gsr;
99 unsigned long pr_fprs;
100} elf_fpregset_t;
101
102/* Format of 32-bit elf_gregset_t is:
103 * G0 --> G7
104 * O0 --> O7
105 * L0 --> L7
106 * I0 --> I7
107 * PSR, PC, nPC, Y, WIM, TBR
108 */
109typedef unsigned int compat_elf_greg_t;
110#define COMPAT_ELF_NGREG 38
111typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
112
113typedef struct {
114 union {
115 unsigned int pr_regs[32];
116 unsigned long pr_dregs[16];
117 } pr_fr;
118 unsigned int __unused;
119 unsigned int pr_fsr;
120 unsigned char pr_qcnt;
121 unsigned char pr_q_entrysize;
122 unsigned char pr_en;
123 unsigned int pr_q[64];
124} compat_elf_fpregset_t;
125
126/* UltraSparc extensions. Still unused, but will be eventually. */
127typedef struct {
128 unsigned int pr_type;
129 unsigned int pr_align;
130 union {
131 struct {
132 union {
133 unsigned int pr_regs[32];
134 unsigned long pr_dregs[16];
135 long double pr_qregs[8];
136 } pr_xfr;
137 } pr_v8p;
138 unsigned int pr_xfsr;
139 unsigned int pr_fprs;
140 unsigned int pr_xg[8];
141 unsigned int pr_xo[8];
142 unsigned long pr_tstate;
143 unsigned int pr_filler[8];
144 } pr_un;
145} elf_xregset_t;
146
147/*
148 * This is used to ensure we don't load something for the wrong architecture.
149 */
150#define elf_check_arch(x) ((x)->e_machine == ELF_ARCH)
151#define compat_elf_check_arch(x) ((x)->e_machine == EM_SPARC || \
152 (x)->e_machine == EM_SPARC32PLUS)
153#define compat_start_thread start_thread32
154
155#define USE_ELF_CORE_DUMP
156#define ELF_EXEC_PAGESIZE PAGE_SIZE
157
158/* This is the location that an ET_DYN program is loaded if exec'ed. Typical
159 use of this is to invoke "./ld.so someprog" to test out a new version of
160 the loader. We need to make sure that it is out of the way of the program
161 that it will "exec", and that there is sufficient room for the brk. */
162
163#define ELF_ET_DYN_BASE 0x0000010000000000UL
164#define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
165
166
167/* This yields a mask that user programs can use to figure out what
168 instruction set this cpu supports. */
169
170/* On Ultra, we support all of the v8 capabilities. */
171static inline unsigned int sparc64_elf_hwcap(void)
172{
173 unsigned int cap = (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR |
174 HWCAP_SPARC_SWAP | HWCAP_SPARC_MULDIV |
175 HWCAP_SPARC_V9);
176
177 if (tlb_type == cheetah || tlb_type == cheetah_plus)
178 cap |= HWCAP_SPARC_ULTRA3;
179 else if (tlb_type == hypervisor) {
180 if (sun4v_chip_type == SUN4V_CHIP_NIAGARA1 ||
181 sun4v_chip_type == SUN4V_CHIP_NIAGARA2)
182 cap |= HWCAP_SPARC_BLKINIT;
183 if (sun4v_chip_type == SUN4V_CHIP_NIAGARA2)
184 cap |= HWCAP_SPARC_N2;
185 }
186
187 return cap;
188}
189
190#define ELF_HWCAP sparc64_elf_hwcap();
191
192/* This yields a string that ld.so will use to load implementation
193 specific libraries for optimization. This is more specific in
194 intent than poking at uname or /proc/cpuinfo. */
195
196#define ELF_PLATFORM (NULL)
197
198#define SET_PERSONALITY(ex, ibcs2) \
199do { unsigned long new_flags = current_thread_info()->flags; \
200 new_flags &= _TIF_32BIT; \
201 if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
202 new_flags |= _TIF_32BIT; \
203 else \
204 new_flags &= ~_TIF_32BIT; \
205 if ((current_thread_info()->flags & _TIF_32BIT) \
206 != new_flags) \
207 set_thread_flag(TIF_ABI_PENDING); \
208 else \
209 clear_thread_flag(TIF_ABI_PENDING); \
210 /* flush_thread will update pgd cache */ \
211 if (ibcs2) \
212 set_personality(PER_SVR4); \
213 else if (current->personality != PER_LINUX32) \
214 set_personality(PER_LINUX); \
215} while (0)
216
217#endif /* !(__ASM_SPARC64_ELF_H) */
diff --git a/include/asm-sparc64/envctrl.h b/include/asm-sparc64/envctrl.h
index a5668a082b14..a2cc0ca334ba 100644
--- a/include/asm-sparc64/envctrl.h
+++ b/include/asm-sparc64/envctrl.h
@@ -1,103 +1 @@
1/* #include <asm-sparc/envctrl.h>
2 *
3 * envctrl.h: Definitions for access to the i2c environment
4 * monitoring on Ultrasparc systems.
5 *
6 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
7 * Copyright (C) 2000 Vinh Truong (vinh.truong@eng.sun.com)
8 * VT - Add all ioctl commands and environment status definitions
9 * VT - Add application note
10 */
11#ifndef _SPARC64_ENVCTRL_H
12#define _SPARC64_ENVCTRL_H 1
13
14#include <linux/ioctl.h>
15
16/* Application note:
17 *
18 * The driver supports 4 operations: open(), close(), ioctl(), read()
19 * The device name is /dev/envctrl.
20 * Below is sample usage:
21 *
22 * fd = open("/dev/envtrl", O_RDONLY);
23 * if (ioctl(fd, ENVCTRL_READ_SHUTDOWN_TEMPERATURE, 0) < 0)
24 * printf("error\n");
25 * ret = read(fd, buf, 10);
26 * close(fd);
27 *
28 * Notice in the case of cpu voltage and temperature, the default is
29 * cpu0. If we need to know the info of cpu1, cpu2, cpu3, we need to
30 * pass in cpu number in ioctl() last parameter. For example, to
31 * get the voltage of cpu2:
32 *
33 * ioctlbuf[0] = 2;
34 * if (ioctl(fd, ENVCTRL_READ_CPU_VOLTAGE, ioctlbuf) < 0)
35 * printf("error\n");
36 * ret = read(fd, buf, 10);
37 *
38 * All the return values are in ascii. So check read return value
39 * and do appropriate conversions in your application.
40 */
41
42/* IOCTL commands */
43
44/* Note: these commands reflect possible monitor features.
45 * Some boards choose to support some of the features only.
46 */
47#define ENVCTRL_RD_CPU_TEMPERATURE _IOR('p', 0x40, int)
48#define ENVCTRL_RD_CPU_VOLTAGE _IOR('p', 0x41, int)
49#define ENVCTRL_RD_FAN_STATUS _IOR('p', 0x42, int)
50#define ENVCTRL_RD_WARNING_TEMPERATURE _IOR('p', 0x43, int)
51#define ENVCTRL_RD_SHUTDOWN_TEMPERATURE _IOR('p', 0x44, int)
52#define ENVCTRL_RD_VOLTAGE_STATUS _IOR('p', 0x45, int)
53#define ENVCTRL_RD_SCSI_TEMPERATURE _IOR('p', 0x46, int)
54#define ENVCTRL_RD_ETHERNET_TEMPERATURE _IOR('p', 0x47, int)
55#define ENVCTRL_RD_MTHRBD_TEMPERATURE _IOR('p', 0x48, int)
56
57#define ENVCTRL_RD_GLOBALADDRESS _IOR('p', 0x49, int)
58
59/* Read return values for a voltage status request. */
60#define ENVCTRL_VOLTAGE_POWERSUPPLY_GOOD 0x01
61#define ENVCTRL_VOLTAGE_BAD 0x02
62#define ENVCTRL_POWERSUPPLY_BAD 0x03
63#define ENVCTRL_VOLTAGE_POWERSUPPLY_BAD 0x04
64
65/* Read return values for a fan status request.
66 * A failure match means either the fan fails or
67 * the fan is not connected. Some boards have optional
68 * connectors to connect extra fans.
69 *
70 * There are maximum 8 monitor fans. Some are cpu fans
71 * some are system fans. The mask below only indicates
72 * fan by order number.
73 * Below is a sample application:
74 *
75 * if (ioctl(fd, ENVCTRL_READ_FAN_STATUS, 0) < 0) {
76 * printf("ioctl fan failed\n");
77 * }
78 * if (read(fd, rslt, 1) <= 0) {
79 * printf("error or fan not monitored\n");
80 * } else {
81 * if (rslt[0] == ENVCTRL_ALL_FANS_GOOD) {
82 * printf("all fans good\n");
83 * } else if (rslt[0] == ENVCTRL_ALL_FANS_BAD) {
84 * printf("all fans bad\n");
85 * } else {
86 * if (rslt[0] & ENVCTRL_FAN0_FAILURE_MASK) {
87 * printf("fan 0 failed or not connected\n");
88 * }
89 * ......
90 */
91
92#define ENVCTRL_ALL_FANS_GOOD 0x00
93#define ENVCTRL_FAN0_FAILURE_MASK 0x01
94#define ENVCTRL_FAN1_FAILURE_MASK 0x02
95#define ENVCTRL_FAN2_FAILURE_MASK 0x04
96#define ENVCTRL_FAN3_FAILURE_MASK 0x08
97#define ENVCTRL_FAN4_FAILURE_MASK 0x10
98#define ENVCTRL_FAN5_FAILURE_MASK 0x20
99#define ENVCTRL_FAN6_FAILURE_MASK 0x40
100#define ENVCTRL_FAN7_FAILURE_MASK 0x80
101#define ENVCTRL_ALL_FANS_BAD 0xFF
102
103#endif /* !(_SPARC64_ENVCTRL_H) */
diff --git a/include/asm-sparc64/estate.h b/include/asm-sparc64/estate.h
index 520c08560d1b..bedd0ef5f19c 100644
--- a/include/asm-sparc64/estate.h
+++ b/include/asm-sparc64/estate.h
@@ -1,49 +1 @@
1#ifndef _SPARC64_ESTATE_H #include <asm-sparc/estate.h>
2#define _SPARC64_ESTATE_H
3
4/* UltraSPARC-III E-cache Error Enable */
5#define ESTATE_ERROR_FMT 0x0000000000040000 /* Force MTAG ECC */
6#define ESTATE_ERROR_FMESS 0x000000000003c000 /* Forced MTAG ECC val */
7#define ESTATE_ERROR_FMD 0x0000000000002000 /* Force DATA ECC */
8#define ESTATE_ERROR_FDECC 0x0000000000001ff0 /* Forced DATA ECC val */
9#define ESTATE_ERROR_UCEEN 0x0000000000000008 /* See below */
10#define ESTATE_ERROR_NCEEN 0x0000000000000002 /* See below */
11#define ESTATE_ERROR_CEEN 0x0000000000000001 /* See below */
12
13/* UCEEN enables the fast_ECC_error trap for: 1) software correctable E-cache
14 * errors 2) uncorrectable E-cache errors. Such events only occur on reads
15 * of the E-cache by the local processor for: 1) data loads 2) instruction
16 * fetches 3) atomic operations. Such events _cannot_ occur for: 1) merge
17 * 2) writeback 2) copyout. The AFSR bits associated with these traps are
18 * UCC and UCU.
19 */
20
21/* NCEEN enables instruction_access_error, data_access_error, and ECC_error traps
22 * for uncorrectable ECC errors and system errors.
23 *
24 * Uncorrectable system bus data error or MTAG ECC error, system bus TimeOUT,
25 * or system bus BusERR:
26 * 1) As the result of an instruction fetch, will generate instruction_access_error
27 * 2) As the result of a load etc. will generate data_access_error.
28 * 3) As the result of store merge completion, writeback, or copyout will
29 * generate a disrupting ECC_error trap.
30 * 4) As the result of such errors on instruction vector fetch can generate any
31 * of the 3 trap types.
32 *
33 * The AFSR bits associated with these traps are EMU, EDU, WDU, CPU, IVU, UE,
34 * BERR, and TO.
35 */
36
37/* CEEN enables the ECC_error trap for hardware corrected ECC errors. System bus
38 * reads resulting in a hardware corrected data or MTAG ECC error will generate an
39 * ECC_error disrupting trap with this bit enabled.
40 *
41 * This same trap will also be generated when a hardware corrected ECC error results
42 * during store merge, writeback, and copyout operations.
43 */
44
45/* In general, if the trap enable bits above are disabled the AFSR bits will still
46 * log the events even though the trap will not be generated by the processor.
47 */
48
49#endif /* _SPARC64_ESTATE_H */
diff --git a/include/asm-sparc64/fbio.h b/include/asm-sparc64/fbio.h
index b9215a0907d3..c17edf8c7bc4 100644
--- a/include/asm-sparc64/fbio.h
+++ b/include/asm-sparc64/fbio.h
@@ -1,330 +1 @@
1#ifndef __LINUX_FBIO_H #include <asm-sparc/fbio.h>
2#define __LINUX_FBIO_H
3
4#include <linux/compiler.h>
5#include <linux/types.h>
6
7/* Constants used for fbio SunOS compatibility */
8/* (C) 1996 Miguel de Icaza */
9
10/* Frame buffer types */
11#define FBTYPE_NOTYPE -1
12#define FBTYPE_SUN1BW 0 /* mono */
13#define FBTYPE_SUN1COLOR 1
14#define FBTYPE_SUN2BW 2
15#define FBTYPE_SUN2COLOR 3
16#define FBTYPE_SUN2GP 4
17#define FBTYPE_SUN5COLOR 5
18#define FBTYPE_SUN3COLOR 6
19#define FBTYPE_MEMCOLOR 7
20#define FBTYPE_SUN4COLOR 8
21
22#define FBTYPE_NOTSUN1 9
23#define FBTYPE_NOTSUN2 10
24#define FBTYPE_NOTSUN3 11
25
26#define FBTYPE_SUNFAST_COLOR 12 /* cg6 */
27#define FBTYPE_SUNROP_COLOR 13
28#define FBTYPE_SUNFB_VIDEO 14
29#define FBTYPE_SUNGIFB 15
30#define FBTYPE_SUNGPLAS 16
31#define FBTYPE_SUNGP3 17
32#define FBTYPE_SUNGT 18
33#define FBTYPE_SUNLEO 19 /* zx Leo card */
34#define FBTYPE_MDICOLOR 20 /* cg14 */
35#define FBTYPE_TCXCOLOR 21 /* SUNW,tcx card */
36
37#define FBTYPE_LASTPLUSONE 21 /* This is not last + 1 in fact... */
38
39/* Does not seem to be listed in the Sun file either */
40#define FBTYPE_CREATOR 22
41#define FBTYPE_PCI_IGA1682 23
42#define FBTYPE_P9100COLOR 24
43
44#define FBTYPE_PCI_GENERIC 1000
45#define FBTYPE_PCI_MACH64 1001
46
47/* fbio ioctls */
48/* Returned by FBIOGTYPE */
49struct fbtype {
50 int fb_type; /* fb type, see above */
51 int fb_height; /* pixels */
52 int fb_width; /* pixels */
53 int fb_depth;
54 int fb_cmsize; /* color map entries */
55 int fb_size; /* fb size in bytes */
56};
57#define FBIOGTYPE _IOR('F', 0, struct fbtype)
58
59struct fbcmap {
60 int index; /* first element (0 origin) */
61 int count;
62 unsigned char __user *red;
63 unsigned char __user *green;
64 unsigned char __user *blue;
65};
66
67#ifdef __KERNEL__
68#define FBIOPUTCMAP_SPARC _IOW('F', 3, struct fbcmap)
69#define FBIOGETCMAP_SPARC _IOW('F', 4, struct fbcmap)
70#else
71#define FBIOPUTCMAP _IOW('F', 3, struct fbcmap)
72#define FBIOGETCMAP _IOW('F', 4, struct fbcmap)
73#endif
74
75/* # of device specific values */
76#define FB_ATTR_NDEVSPECIFIC 8
77/* # of possible emulations */
78#define FB_ATTR_NEMUTYPES 4
79
80struct fbsattr {
81 int flags;
82 int emu_type; /* -1 if none */
83 int dev_specific[FB_ATTR_NDEVSPECIFIC];
84};
85
86struct fbgattr {
87 int real_type; /* real frame buffer type */
88 int owner; /* unknown */
89 struct fbtype fbtype; /* real frame buffer fbtype */
90 struct fbsattr sattr;
91 int emu_types[FB_ATTR_NEMUTYPES]; /* supported emulations */
92};
93#define FBIOSATTR _IOW('F', 5, struct fbgattr) /* Unsupported: */
94#define FBIOGATTR _IOR('F', 6, struct fbgattr) /* supported */
95
96#define FBIOSVIDEO _IOW('F', 7, int)
97#define FBIOGVIDEO _IOR('F', 8, int)
98
99struct fbcursor {
100 short set; /* what to set, choose from the list above */
101 short enable; /* cursor on/off */
102 struct fbcurpos pos; /* cursor position */
103 struct fbcurpos hot; /* cursor hot spot */
104 struct fbcmap cmap; /* color map info */
105 struct fbcurpos size; /* cursor bit map size */
106 char __user *image; /* cursor image bits */
107 char __user *mask; /* cursor mask bits */
108};
109
110/* set/get cursor attributes/shape */
111#define FBIOSCURSOR _IOW('F', 24, struct fbcursor)
112#define FBIOGCURSOR _IOWR('F', 25, struct fbcursor)
113
114/* set/get cursor position */
115#define FBIOSCURPOS _IOW('F', 26, struct fbcurpos)
116#define FBIOGCURPOS _IOW('F', 27, struct fbcurpos)
117
118/* get max cursor size */
119#define FBIOGCURMAX _IOR('F', 28, struct fbcurpos)
120
121/* wid manipulation */
122struct fb_wid_alloc {
123#define FB_WID_SHARED_8 0
124#define FB_WID_SHARED_24 1
125#define FB_WID_DBL_8 2
126#define FB_WID_DBL_24 3
127 __u32 wa_type;
128 __s32 wa_index; /* Set on return */
129 __u32 wa_count;
130};
131struct fb_wid_item {
132 __u32 wi_type;
133 __s32 wi_index;
134 __u32 wi_attrs;
135 __u32 wi_values[32];
136};
137struct fb_wid_list {
138 __u32 wl_flags;
139 __u32 wl_count;
140 struct fb_wid_item *wl_list;
141};
142
143#define FBIO_WID_ALLOC _IOWR('F', 30, struct fb_wid_alloc)
144#define FBIO_WID_FREE _IOW('F', 31, struct fb_wid_alloc)
145#define FBIO_WID_PUT _IOW('F', 32, struct fb_wid_list)
146#define FBIO_WID_GET _IOWR('F', 33, struct fb_wid_list)
147
148/* Creator ioctls */
149#define FFB_IOCTL ('F'<<8)
150#define FFB_SYS_INFO (FFB_IOCTL|80)
151#define FFB_CLUTREAD (FFB_IOCTL|81)
152#define FFB_CLUTPOST (FFB_IOCTL|82)
153#define FFB_SETDIAGMODE (FFB_IOCTL|83)
154#define FFB_GETMONITORID (FFB_IOCTL|84)
155#define FFB_GETVIDEOMODE (FFB_IOCTL|85)
156#define FFB_SETVIDEOMODE (FFB_IOCTL|86)
157#define FFB_SETSERVER (FFB_IOCTL|87)
158#define FFB_SETOVCTL (FFB_IOCTL|88)
159#define FFB_GETOVCTL (FFB_IOCTL|89)
160#define FFB_GETSAXNUM (FFB_IOCTL|90)
161#define FFB_FBDEBUG (FFB_IOCTL|91)
162
163/* Cg14 ioctls */
164#define MDI_IOCTL ('M'<<8)
165#define MDI_RESET (MDI_IOCTL|1)
166#define MDI_GET_CFGINFO (MDI_IOCTL|2)
167#define MDI_SET_PIXELMODE (MDI_IOCTL|3)
168# define MDI_32_PIX 32
169# define MDI_16_PIX 16
170# define MDI_8_PIX 8
171
172struct mdi_cfginfo {
173 int mdi_ncluts; /* Number of implemented CLUTs in this MDI */
174 int mdi_type; /* FBTYPE name */
175 int mdi_height; /* height */
176 int mdi_width; /* widht */
177 int mdi_size; /* available ram */
178 int mdi_mode; /* 8bpp, 16bpp or 32bpp */
179 int mdi_pixfreq; /* pixel clock (from PROM) */
180};
181
182/* SparcLinux specific ioctl for the MDI, should be replaced for
183 * the SET_XLUT/SET_CLUTn ioctls instead
184 */
185#define MDI_CLEAR_XLUT (MDI_IOCTL|9)
186
187/* leo & ffb ioctls */
188struct fb_clut_alloc {
189 __u32 clutid; /* Set on return */
190 __u32 flag;
191 __u32 index;
192};
193
194struct fb_clut {
195#define FB_CLUT_WAIT 0x00000001 /* Not yet implemented */
196 __u32 flag;
197 __u32 clutid;
198 __u32 offset;
199 __u32 count;
200 char * red;
201 char * green;
202 char * blue;
203};
204
205struct fb_clut32 {
206 __u32 flag;
207 __u32 clutid;
208 __u32 offset;
209 __u32 count;
210 __u32 red;
211 __u32 green;
212 __u32 blue;
213};
214
215#define LEO_CLUTALLOC _IOWR('L', 53, struct fb_clut_alloc)
216#define LEO_CLUTFREE _IOW('L', 54, struct fb_clut_alloc)
217#define LEO_CLUTREAD _IOW('L', 55, struct fb_clut)
218#define LEO_CLUTPOST _IOW('L', 56, struct fb_clut)
219#define LEO_SETGAMMA _IOW('L', 68, int) /* Not yet implemented */
220#define LEO_GETGAMMA _IOR('L', 69, int) /* Not yet implemented */
221
222#ifdef __KERNEL__
223/* Addresses on the fd of a cgsix that are mappable */
224#define CG6_FBC 0x70000000
225#define CG6_TEC 0x70001000
226#define CG6_BTREGS 0x70002000
227#define CG6_FHC 0x70004000
228#define CG6_THC 0x70005000
229#define CG6_ROM 0x70006000
230#define CG6_RAM 0x70016000
231#define CG6_DHC 0x80000000
232
233#define CG3_MMAP_OFFSET 0x4000000
234
235/* Addresses on the fd of a tcx that are mappable */
236#define TCX_RAM8BIT 0x00000000
237#define TCX_RAM24BIT 0x01000000
238#define TCX_UNK3 0x10000000
239#define TCX_UNK4 0x20000000
240#define TCX_CONTROLPLANE 0x28000000
241#define TCX_UNK6 0x30000000
242#define TCX_UNK7 0x38000000
243#define TCX_TEC 0x70000000
244#define TCX_BTREGS 0x70002000
245#define TCX_THC 0x70004000
246#define TCX_DHC 0x70008000
247#define TCX_ALT 0x7000a000
248#define TCX_SYNC 0x7000e000
249#define TCX_UNK2 0x70010000
250
251/* CG14 definitions */
252
253/* Offsets into the OBIO space: */
254#define CG14_REGS 0 /* registers */
255#define CG14_CURSORREGS 0x1000 /* cursor registers */
256#define CG14_DACREGS 0x2000 /* DAC registers */
257#define CG14_XLUT 0x3000 /* X Look Up Table -- ??? */
258#define CG14_CLUT1 0x4000 /* Color Look Up Table */
259#define CG14_CLUT2 0x5000 /* Color Look Up Table */
260#define CG14_CLUT3 0x6000 /* Color Look Up Table */
261#define CG14_AUTO 0xf000
262
263#endif /* KERNEL */
264
265/* These are exported to userland for applications to use */
266/* Mappable offsets for the cg14: control registers */
267#define MDI_DIRECT_MAP 0x10000000
268#define MDI_CTLREG_MAP 0x20000000
269#define MDI_CURSOR_MAP 0x30000000
270#define MDI_SHDW_VRT_MAP 0x40000000
271
272/* Mappable offsets for the cg14: frame buffer resolutions */
273/* 32 bits */
274#define MDI_CHUNKY_XBGR_MAP 0x50000000
275#define MDI_CHUNKY_BGR_MAP 0x60000000
276
277/* 16 bits */
278#define MDI_PLANAR_X16_MAP 0x70000000
279#define MDI_PLANAR_C16_MAP 0x80000000
280
281/* 8 bit is done as CG3 MMAP offset */
282/* 32 bits, planar */
283#define MDI_PLANAR_X32_MAP 0x90000000
284#define MDI_PLANAR_B32_MAP 0xa0000000
285#define MDI_PLANAR_G32_MAP 0xb0000000
286#define MDI_PLANAR_R32_MAP 0xc0000000
287
288/* Mappable offsets on leo */
289#define LEO_SS0_MAP 0x00000000
290#define LEO_LC_SS0_USR_MAP 0x00800000
291#define LEO_LD_SS0_MAP 0x00801000
292#define LEO_LX_CURSOR_MAP 0x00802000
293#define LEO_SS1_MAP 0x00803000
294#define LEO_LC_SS1_USR_MAP 0x01003000
295#define LEO_LD_SS1_MAP 0x01004000
296#define LEO_UNK_MAP 0x01005000
297#define LEO_LX_KRN_MAP 0x01006000
298#define LEO_LC_SS0_KRN_MAP 0x01007000
299#define LEO_LC_SS1_KRN_MAP 0x01008000
300#define LEO_LD_GBL_MAP 0x01009000
301#define LEO_UNK2_MAP 0x0100a000
302
303#ifdef __KERNEL__
304struct fbcmap32 {
305 int index; /* first element (0 origin) */
306 int count;
307 u32 red;
308 u32 green;
309 u32 blue;
310};
311
312#define FBIOPUTCMAP32 _IOW('F', 3, struct fbcmap32)
313#define FBIOGETCMAP32 _IOW('F', 4, struct fbcmap32)
314
315struct fbcursor32 {
316 short set; /* what to set, choose from the list above */
317 short enable; /* cursor on/off */
318 struct fbcurpos pos; /* cursor position */
319 struct fbcurpos hot; /* cursor hot spot */
320 struct fbcmap32 cmap; /* color map info */
321 struct fbcurpos size; /* cursor bit map size */
322 u32 image; /* cursor image bits */
323 u32 mask; /* cursor mask bits */
324};
325
326#define FBIOSCURSOR32 _IOW('F', 24, struct fbcursor32)
327#define FBIOGCURSOR32 _IOW('F', 25, struct fbcursor32)
328#endif
329
330#endif /* __LINUX_FBIO_H */
diff --git a/include/asm-sparc64/fcntl.h b/include/asm-sparc64/fcntl.h
index 8a09ca7aa2f2..8b1beae48cd1 100644
--- a/include/asm-sparc64/fcntl.h
+++ b/include/asm-sparc64/fcntl.h
@@ -1,35 +1 @@
1#ifndef _SPARC64_FCNTL_H #include <asm-sparc/fcntl.h>
2#define _SPARC64_FCNTL_H
3
4/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
5 located on an ext2 file system */
6#define O_NDELAY 0x0004
7#define O_APPEND 0x0008
8#define FASYNC 0x0040 /* fcntl, for BSD compatibility */
9#define O_CREAT 0x0200 /* not fcntl */
10#define O_TRUNC 0x0400 /* not fcntl */
11#define O_EXCL 0x0800 /* not fcntl */
12#define O_SYNC 0x2000
13#define O_NONBLOCK 0x4000
14#define O_NOCTTY 0x8000 /* not fcntl */
15#define O_LARGEFILE 0x40000
16#define O_DIRECT 0x100000 /* direct disk access hint */
17#define O_NOATIME 0x200000
18#define O_CLOEXEC 0x400000
19
20#define F_GETOWN 5 /* for sockets. */
21#define F_SETOWN 6 /* for sockets. */
22#define F_GETLK 7
23#define F_SETLK 8
24#define F_SETLKW 9
25
26/* for posix fcntl() and lockf() */
27#define F_RDLCK 1
28#define F_WRLCK 2
29#define F_UNLCK 3
30
31#define __ARCH_FLOCK_PAD short __unused;
32
33#include <asm-generic/fcntl.h>
34
35#endif /* !(_SPARC64_FCNTL_H) */
diff --git a/include/asm-sparc64/fhc.h b/include/asm-sparc64/fhc.h
index ddffcdfbc984..73eb04c19c47 100644
--- a/include/asm-sparc64/fhc.h
+++ b/include/asm-sparc64/fhc.h
@@ -1,131 +1 @@
1/* #include <asm-sparc/fhc.h>
2 * fhc.h: Structures for central/fhc pseudo driver on Sunfire/Starfire/Wildfire.
3 *
4 * Copyright (C) 1997, 1999 David S. Miller (davem@redhat.com)
5 */
6
7#ifndef _SPARC64_FHC_H
8#define _SPARC64_FHC_H
9
10#include <linux/timer.h>
11
12#include <asm/oplib.h>
13#include <asm/prom.h>
14#include <asm/upa.h>
15
16struct linux_fhc;
17
18/* Clock board register offsets. */
19#define CLOCK_CTRL 0x00UL /* Main control */
20#define CLOCK_STAT1 0x10UL /* Status one */
21#define CLOCK_STAT2 0x20UL /* Status two */
22#define CLOCK_PWRSTAT 0x30UL /* Power status */
23#define CLOCK_PWRPRES 0x40UL /* Power presence */
24#define CLOCK_TEMP 0x50UL /* Temperature */
25#define CLOCK_IRQDIAG 0x60UL /* IRQ diagnostics */
26#define CLOCK_PWRSTAT2 0x70UL /* Power status two */
27
28#define CLOCK_CTRL_LLED 0x04 /* Left LED, 0 == on */
29#define CLOCK_CTRL_MLED 0x02 /* Mid LED, 1 == on */
30#define CLOCK_CTRL_RLED 0x01 /* RIght LED, 1 == on */
31
32struct linux_central {
33 struct linux_fhc *child;
34 unsigned long cfreg;
35 unsigned long clkregs;
36 unsigned long clkver;
37 int slots;
38 struct device_node *prom_node;
39
40 struct linux_prom_ranges central_ranges[PROMREG_MAX];
41 int num_central_ranges;
42};
43
44/* Firehose controller register offsets */
45struct fhc_regs {
46 unsigned long pregs; /* FHC internal regs */
47#define FHC_PREGS_ID 0x00UL /* FHC ID */
48#define FHC_ID_VERS 0xf0000000 /* Version of this FHC */
49#define FHC_ID_PARTID 0x0ffff000 /* Part ID code (0x0f9f == FHC) */
50#define FHC_ID_MANUF 0x0000007e /* Manufacturer (0x3e == SUN's JEDEC)*/
51#define FHC_ID_RESV 0x00000001 /* Read as one */
52#define FHC_PREGS_RCS 0x10UL /* FHC Reset Control/Status Register */
53#define FHC_RCS_POR 0x80000000 /* Last reset was a power cycle */
54#define FHC_RCS_SPOR 0x40000000 /* Last reset was sw power on reset */
55#define FHC_RCS_SXIR 0x20000000 /* Last reset was sw XIR reset */
56#define FHC_RCS_BPOR 0x10000000 /* Last reset was due to POR button */
57#define FHC_RCS_BXIR 0x08000000 /* Last reset was due to XIR button */
58#define FHC_RCS_WEVENT 0x04000000 /* CPU reset was due to wakeup event */
59#define FHC_RCS_CFATAL 0x02000000 /* Centerplane Fatal Error signalled */
60#define FHC_RCS_FENAB 0x01000000 /* Fatal errors elicit system reset */
61#define FHC_PREGS_CTRL 0x20UL /* FHC Control Register */
62#define FHC_CONTROL_ICS 0x00100000 /* Ignore Centerplane Signals */
63#define FHC_CONTROL_FRST 0x00080000 /* Fatal Error Reset Enable */
64#define FHC_CONTROL_LFAT 0x00040000 /* AC/DC signalled a local error */
65#define FHC_CONTROL_SLINE 0x00010000 /* Firmware Synchronization Line */
66#define FHC_CONTROL_DCD 0x00008000 /* DC-->DC Converter Disable */
67#define FHC_CONTROL_POFF 0x00004000 /* AC/DC Controller PLL Disable */
68#define FHC_CONTROL_FOFF 0x00002000 /* FHC Controller PLL Disable */
69#define FHC_CONTROL_AOFF 0x00001000 /* CPU A SRAM/SBD Low Power Mode */
70#define FHC_CONTROL_BOFF 0x00000800 /* CPU B SRAM/SBD Low Power Mode */
71#define FHC_CONTROL_PSOFF 0x00000400 /* Turns off this FHC's power supply */
72#define FHC_CONTROL_IXIST 0x00000200 /* 0=FHC tells clock board it exists */
73#define FHC_CONTROL_XMSTR 0x00000100 /* 1=Causes this FHC to be XIR master*/
74#define FHC_CONTROL_LLED 0x00000040 /* 0=Left LED ON */
75#define FHC_CONTROL_MLED 0x00000020 /* 1=Middle LED ON */
76#define FHC_CONTROL_RLED 0x00000010 /* 1=Right LED */
77#define FHC_CONTROL_BPINS 0x00000003 /* Spare Bidirectional Pins */
78#define FHC_PREGS_BSR 0x30UL /* FHC Board Status Register */
79#define FHC_BSR_DA64 0x00040000 /* Port A: 0=128bit 1=64bit data path */
80#define FHC_BSR_DB64 0x00020000 /* Port B: 0=128bit 1=64bit data path */
81#define FHC_BSR_BID 0x0001e000 /* Board ID */
82#define FHC_BSR_SA 0x00001c00 /* Port A UPA Speed (from the pins) */
83#define FHC_BSR_SB 0x00000380 /* Port B UPA Speed (from the pins) */
84#define FHC_BSR_NDIAG 0x00000040 /* Not in Diag Mode */
85#define FHC_BSR_NTBED 0x00000020 /* Not in TestBED Mode */
86#define FHC_BSR_NIA 0x0000001c /* Jumper, bit 18 in PROM space */
87#define FHC_BSR_SI 0x00000001 /* Spare input pin value */
88#define FHC_PREGS_ECC 0x40UL /* FHC ECC Control Register (16 bits) */
89#define FHC_PREGS_JCTRL 0xf0UL /* FHC JTAG Control Register */
90#define FHC_JTAG_CTRL_MENAB 0x80000000 /* Indicates this is JTAG Master */
91#define FHC_JTAG_CTRL_MNONE 0x40000000 /* Indicates no JTAG Master present */
92#define FHC_PREGS_JCMD 0x100UL /* FHC JTAG Command Register */
93 unsigned long ireg; /* FHC IGN reg */
94#define FHC_IREG_IGN 0x00UL /* This FHC's IGN */
95 unsigned long ffregs; /* FHC fanfail regs */
96#define FHC_FFREGS_IMAP 0x00UL /* FHC Fanfail IMAP */
97#define FHC_FFREGS_ICLR 0x10UL /* FHC Fanfail ICLR */
98 unsigned long sregs; /* FHC system regs */
99#define FHC_SREGS_IMAP 0x00UL /* FHC System IMAP */
100#define FHC_SREGS_ICLR 0x10UL /* FHC System ICLR */
101 unsigned long uregs; /* FHC uart regs */
102#define FHC_UREGS_IMAP 0x00UL /* FHC Uart IMAP */
103#define FHC_UREGS_ICLR 0x10UL /* FHC Uart ICLR */
104 unsigned long tregs; /* FHC TOD regs */
105#define FHC_TREGS_IMAP 0x00UL /* FHC TOD IMAP */
106#define FHC_TREGS_ICLR 0x10UL /* FHC TOD ICLR */
107};
108
109struct linux_fhc {
110 struct linux_fhc *next;
111 struct linux_central *parent; /* NULL if not central FHC */
112 struct fhc_regs fhc_regs;
113 int board;
114 int jtag_master;
115 struct device_node *prom_node;
116
117 struct linux_prom_ranges fhc_ranges[PROMREG_MAX];
118 int num_fhc_ranges;
119};
120
121extern struct linux_central *central_bus;
122
123extern void apply_central_ranges(struct linux_central *central,
124 struct linux_prom_registers *regs,
125 int nregs);
126
127extern void apply_fhc_ranges(struct linux_fhc *fhc,
128 struct linux_prom_registers *regs,
129 int nregs);
130
131#endif /* !(_SPARC64_FHC_H) */
diff --git a/include/asm-sparc64/floppy.h b/include/asm-sparc64/floppy.h
index ca19f80a9b7d..214878114436 100644
--- a/include/asm-sparc64/floppy.h
+++ b/include/asm-sparc64/floppy.h
@@ -1,782 +1 @@
1/* floppy.h: Sparc specific parts of the Floppy driver. #include <asm-sparc/floppy.h>
2 *
3 * Copyright (C) 1996, 2007 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 *
6 * Ultra/PCI support added: Sep 1997 Eddie C. Dost (ecd@skynet.be)
7 */
8
9#ifndef __ASM_SPARC64_FLOPPY_H
10#define __ASM_SPARC64_FLOPPY_H
11
12#include <linux/init.h>
13#include <linux/pci.h>
14
15#include <asm/page.h>
16#include <asm/pgtable.h>
17#include <asm/system.h>
18#include <asm/idprom.h>
19#include <asm/oplib.h>
20#include <asm/auxio.h>
21#include <asm/sbus.h>
22#include <asm/irq.h>
23
24
25/*
26 * Define this to enable exchanging drive 0 and 1 if only drive 1 is
27 * probed on PCI machines.
28 */
29#undef PCI_FDC_SWAP_DRIVES
30
31
32/* References:
33 * 1) Netbsd Sun floppy driver.
34 * 2) NCR 82077 controller manual
35 * 3) Intel 82077 controller manual
36 */
37struct sun_flpy_controller {
38 volatile unsigned char status1_82077; /* Auxiliary Status reg. 1 */
39 volatile unsigned char status2_82077; /* Auxiliary Status reg. 2 */
40 volatile unsigned char dor_82077; /* Digital Output reg. */
41 volatile unsigned char tapectl_82077; /* Tape Control reg */
42 volatile unsigned char status_82077; /* Main Status Register. */
43#define drs_82077 status_82077 /* Digital Rate Select reg. */
44 volatile unsigned char data_82077; /* Data fifo. */
45 volatile unsigned char ___unused;
46 volatile unsigned char dir_82077; /* Digital Input reg. */
47#define dcr_82077 dir_82077 /* Config Control reg. */
48};
49
50/* You'll only ever find one controller on an Ultra anyways. */
51static struct sun_flpy_controller *sun_fdc = (struct sun_flpy_controller *)-1;
52unsigned long fdc_status;
53static struct sbus_dev *floppy_sdev = NULL;
54
55struct sun_floppy_ops {
56 unsigned char (*fd_inb) (unsigned long port);
57 void (*fd_outb) (unsigned char value, unsigned long port);
58 void (*fd_enable_dma) (void);
59 void (*fd_disable_dma) (void);
60 void (*fd_set_dma_mode) (int);
61 void (*fd_set_dma_addr) (char *);
62 void (*fd_set_dma_count) (int);
63 unsigned int (*get_dma_residue) (void);
64 int (*fd_request_irq) (void);
65 void (*fd_free_irq) (void);
66 int (*fd_eject) (int);
67};
68
69static struct sun_floppy_ops sun_fdops;
70
71#define fd_inb(port) sun_fdops.fd_inb(port)
72#define fd_outb(value,port) sun_fdops.fd_outb(value,port)
73#define fd_enable_dma() sun_fdops.fd_enable_dma()
74#define fd_disable_dma() sun_fdops.fd_disable_dma()
75#define fd_request_dma() (0) /* nothing... */
76#define fd_free_dma() /* nothing... */
77#define fd_clear_dma_ff() /* nothing... */
78#define fd_set_dma_mode(mode) sun_fdops.fd_set_dma_mode(mode)
79#define fd_set_dma_addr(addr) sun_fdops.fd_set_dma_addr(addr)
80#define fd_set_dma_count(count) sun_fdops.fd_set_dma_count(count)
81#define get_dma_residue(x) sun_fdops.get_dma_residue()
82#define fd_cacheflush(addr, size) /* nothing... */
83#define fd_request_irq() sun_fdops.fd_request_irq()
84#define fd_free_irq() sun_fdops.fd_free_irq()
85#define fd_eject(drive) sun_fdops.fd_eject(drive)
86
87/* Super paranoid... */
88#undef HAVE_DISABLE_HLT
89
90static int sun_floppy_types[2] = { 0, 0 };
91
92/* Here is where we catch the floppy driver trying to initialize,
93 * therefore this is where we call the PROM device tree probing
94 * routine etc. on the Sparc.
95 */
96#define FLOPPY0_TYPE sun_floppy_init()
97#define FLOPPY1_TYPE sun_floppy_types[1]
98
99#define FDC1 ((unsigned long)sun_fdc)
100
101#define N_FDC 1
102#define N_DRIVE 8
103
104/* No 64k boundary crossing problems on the Sparc. */
105#define CROSS_64KB(a,s) (0)
106
107static unsigned char sun_82077_fd_inb(unsigned long port)
108{
109 udelay(5);
110 switch(port & 7) {
111 default:
112 printk("floppy: Asked to read unknown port %lx\n", port);
113 panic("floppy: Port bolixed.");
114 case 4: /* FD_STATUS */
115 return sbus_readb(&sun_fdc->status_82077) & ~STATUS_DMA;
116 case 5: /* FD_DATA */
117 return sbus_readb(&sun_fdc->data_82077);
118 case 7: /* FD_DIR */
119 /* XXX: Is DCL on 0x80 in sun4m? */
120 return sbus_readb(&sun_fdc->dir_82077);
121 };
122 panic("sun_82072_fd_inb: How did I get here?");
123}
124
125static void sun_82077_fd_outb(unsigned char value, unsigned long port)
126{
127 udelay(5);
128 switch(port & 7) {
129 default:
130 printk("floppy: Asked to write to unknown port %lx\n", port);
131 panic("floppy: Port bolixed.");
132 case 2: /* FD_DOR */
133 /* Happily, the 82077 has a real DOR register. */
134 sbus_writeb(value, &sun_fdc->dor_82077);
135 break;
136 case 5: /* FD_DATA */
137 sbus_writeb(value, &sun_fdc->data_82077);
138 break;
139 case 7: /* FD_DCR */
140 sbus_writeb(value, &sun_fdc->dcr_82077);
141 break;
142 case 4: /* FD_STATUS */
143 sbus_writeb(value, &sun_fdc->status_82077);
144 break;
145 };
146 return;
147}
148
149/* For pseudo-dma (Sun floppy drives have no real DMA available to
150 * them so we must eat the data fifo bytes directly ourselves) we have
151 * three state variables. doing_pdma tells our inline low-level
152 * assembly floppy interrupt entry point whether it should sit and eat
153 * bytes from the fifo or just transfer control up to the higher level
154 * floppy interrupt c-code. I tried very hard but I could not get the
155 * pseudo-dma to work in c-code without getting many overruns and
156 * underruns. If non-zero, doing_pdma encodes the direction of
157 * the transfer for debugging. 1=read 2=write
158 */
159unsigned char *pdma_vaddr;
160unsigned long pdma_size;
161volatile int doing_pdma = 0;
162
163/* This is software state */
164char *pdma_base = NULL;
165unsigned long pdma_areasize;
166
167/* Common routines to all controller types on the Sparc. */
168static void sun_fd_disable_dma(void)
169{
170 doing_pdma = 0;
171 if (pdma_base) {
172 mmu_unlockarea(pdma_base, pdma_areasize);
173 pdma_base = NULL;
174 }
175}
176
177static void sun_fd_set_dma_mode(int mode)
178{
179 switch(mode) {
180 case DMA_MODE_READ:
181 doing_pdma = 1;
182 break;
183 case DMA_MODE_WRITE:
184 doing_pdma = 2;
185 break;
186 default:
187 printk("Unknown dma mode %d\n", mode);
188 panic("floppy: Giving up...");
189 }
190}
191
192static void sun_fd_set_dma_addr(char *buffer)
193{
194 pdma_vaddr = buffer;
195}
196
197static void sun_fd_set_dma_count(int length)
198{
199 pdma_size = length;
200}
201
202static void sun_fd_enable_dma(void)
203{
204 pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
205 pdma_base = pdma_vaddr;
206 pdma_areasize = pdma_size;
207}
208
209irqreturn_t sparc_floppy_irq(int irq, void *dev_cookie)
210{
211 if (likely(doing_pdma)) {
212 void __iomem *stat = (void __iomem *) fdc_status;
213 unsigned char *vaddr = pdma_vaddr;
214 unsigned long size = pdma_size;
215 u8 val;
216
217 while (size) {
218 val = readb(stat);
219 if (unlikely(!(val & 0x80))) {
220 pdma_vaddr = vaddr;
221 pdma_size = size;
222 return IRQ_HANDLED;
223 }
224 if (unlikely(!(val & 0x20))) {
225 pdma_vaddr = vaddr;
226 pdma_size = size;
227 doing_pdma = 0;
228 goto main_interrupt;
229 }
230 if (val & 0x40) {
231 /* read */
232 *vaddr++ = readb(stat + 1);
233 } else {
234 unsigned char data = *vaddr++;
235
236 /* write */
237 writeb(data, stat + 1);
238 }
239 size--;
240 }
241
242 pdma_vaddr = vaddr;
243 pdma_size = size;
244
245 /* Send Terminal Count pulse to floppy controller. */
246 val = readb(auxio_register);
247 val |= AUXIO_AUX1_FTCNT;
248 writeb(val, auxio_register);
249 val &= ~AUXIO_AUX1_FTCNT;
250 writeb(val, auxio_register);
251
252 doing_pdma = 0;
253 }
254
255main_interrupt:
256 return floppy_interrupt(irq, dev_cookie);
257}
258
259static int sun_fd_request_irq(void)
260{
261 static int once = 0;
262 int error;
263
264 if(!once) {
265 once = 1;
266
267 error = request_irq(FLOPPY_IRQ, sparc_floppy_irq,
268 IRQF_DISABLED, "floppy", NULL);
269
270 return ((error == 0) ? 0 : -1);
271 }
272 return 0;
273}
274
275static void sun_fd_free_irq(void)
276{
277}
278
279static unsigned int sun_get_dma_residue(void)
280{
281 /* XXX This isn't really correct. XXX */
282 return 0;
283}
284
285static int sun_fd_eject(int drive)
286{
287 set_dor(0x00, 0xff, 0x90);
288 udelay(500);
289 set_dor(0x00, 0x6f, 0x00);
290 udelay(500);
291 return 0;
292}
293
294#ifdef CONFIG_PCI
295#include <asm/ebus.h>
296#include <asm/ns87303.h>
297
298static struct ebus_dma_info sun_pci_fd_ebus_dma;
299static struct pci_dev *sun_pci_ebus_dev;
300static int sun_pci_broken_drive = -1;
301
302struct sun_pci_dma_op {
303 unsigned int addr;
304 int len;
305 int direction;
306 char *buf;
307};
308static struct sun_pci_dma_op sun_pci_dma_current = { -1U, 0, 0, NULL};
309static struct sun_pci_dma_op sun_pci_dma_pending = { -1U, 0, 0, NULL};
310
311extern irqreturn_t floppy_interrupt(int irq, void *dev_id);
312
313static unsigned char sun_pci_fd_inb(unsigned long port)
314{
315 udelay(5);
316 return inb(port);
317}
318
319static void sun_pci_fd_outb(unsigned char val, unsigned long port)
320{
321 udelay(5);
322 outb(val, port);
323}
324
325static void sun_pci_fd_broken_outb(unsigned char val, unsigned long port)
326{
327 udelay(5);
328 /*
329 * XXX: Due to SUN's broken floppy connector on AX and AXi
330 * we need to turn on MOTOR_0 also, if the floppy is
331 * jumpered to DS1 (like most PC floppies are). I hope
332 * this does not hurt correct hardware like the AXmp.
333 * (Eddie, Sep 12 1998).
334 */
335 if (port == ((unsigned long)sun_fdc) + 2) {
336 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x20)) {
337 val |= 0x10;
338 }
339 }
340 outb(val, port);
341}
342
343#ifdef PCI_FDC_SWAP_DRIVES
344static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long port)
345{
346 udelay(5);
347 /*
348 * XXX: Due to SUN's broken floppy connector on AX and AXi
349 * we need to turn on MOTOR_0 also, if the floppy is
350 * jumpered to DS1 (like most PC floppies are). I hope
351 * this does not hurt correct hardware like the AXmp.
352 * (Eddie, Sep 12 1998).
353 */
354 if (port == ((unsigned long)sun_fdc) + 2) {
355 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x10)) {
356 val &= ~(0x03);
357 val |= 0x21;
358 }
359 }
360 outb(val, port);
361}
362#endif /* PCI_FDC_SWAP_DRIVES */
363
364static void sun_pci_fd_enable_dma(void)
365{
366 BUG_ON((NULL == sun_pci_dma_pending.buf) ||
367 (0 == sun_pci_dma_pending.len) ||
368 (0 == sun_pci_dma_pending.direction));
369
370 sun_pci_dma_current.buf = sun_pci_dma_pending.buf;
371 sun_pci_dma_current.len = sun_pci_dma_pending.len;
372 sun_pci_dma_current.direction = sun_pci_dma_pending.direction;
373
374 sun_pci_dma_pending.buf = NULL;
375 sun_pci_dma_pending.len = 0;
376 sun_pci_dma_pending.direction = 0;
377 sun_pci_dma_pending.addr = -1U;
378
379 sun_pci_dma_current.addr =
380 pci_map_single(sun_pci_ebus_dev,
381 sun_pci_dma_current.buf,
382 sun_pci_dma_current.len,
383 sun_pci_dma_current.direction);
384
385 ebus_dma_enable(&sun_pci_fd_ebus_dma, 1);
386
387 if (ebus_dma_request(&sun_pci_fd_ebus_dma,
388 sun_pci_dma_current.addr,
389 sun_pci_dma_current.len))
390 BUG();
391}
392
393static void sun_pci_fd_disable_dma(void)
394{
395 ebus_dma_enable(&sun_pci_fd_ebus_dma, 0);
396 if (sun_pci_dma_current.addr != -1U)
397 pci_unmap_single(sun_pci_ebus_dev,
398 sun_pci_dma_current.addr,
399 sun_pci_dma_current.len,
400 sun_pci_dma_current.direction);
401 sun_pci_dma_current.addr = -1U;
402}
403
404static void sun_pci_fd_set_dma_mode(int mode)
405{
406 if (mode == DMA_MODE_WRITE)
407 sun_pci_dma_pending.direction = PCI_DMA_TODEVICE;
408 else
409 sun_pci_dma_pending.direction = PCI_DMA_FROMDEVICE;
410
411 ebus_dma_prepare(&sun_pci_fd_ebus_dma, mode != DMA_MODE_WRITE);
412}
413
414static void sun_pci_fd_set_dma_count(int length)
415{
416 sun_pci_dma_pending.len = length;
417}
418
419static void sun_pci_fd_set_dma_addr(char *buffer)
420{
421 sun_pci_dma_pending.buf = buffer;
422}
423
424static unsigned int sun_pci_get_dma_residue(void)
425{
426 return ebus_dma_residue(&sun_pci_fd_ebus_dma);
427}
428
429static int sun_pci_fd_request_irq(void)
430{
431 return ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 1);
432}
433
434static void sun_pci_fd_free_irq(void)
435{
436 ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 0);
437}
438
439static int sun_pci_fd_eject(int drive)
440{
441 return -EINVAL;
442}
443
444void sun_pci_fd_dma_callback(struct ebus_dma_info *p, int event, void *cookie)
445{
446 floppy_interrupt(0, NULL);
447}
448
449/*
450 * Floppy probing, we'd like to use /dev/fd0 for a single Floppy on PCI,
451 * even if this is configured using DS1, thus looks like /dev/fd1 with
452 * the cabling used in Ultras.
453 */
454#define DOR (port + 2)
455#define MSR (port + 4)
456#define FIFO (port + 5)
457
458static void sun_pci_fd_out_byte(unsigned long port, unsigned char val,
459 unsigned long reg)
460{
461 unsigned char status;
462 int timeout = 1000;
463
464 while (!((status = inb(MSR)) & 0x80) && --timeout)
465 udelay(100);
466 outb(val, reg);
467}
468
469static unsigned char sun_pci_fd_sensei(unsigned long port)
470{
471 unsigned char result[2] = { 0x70, 0x00 };
472 unsigned char status;
473 int i = 0;
474
475 sun_pci_fd_out_byte(port, 0x08, FIFO);
476 do {
477 int timeout = 1000;
478
479 while (!((status = inb(MSR)) & 0x80) && --timeout)
480 udelay(100);
481
482 if (!timeout)
483 break;
484
485 if ((status & 0xf0) == 0xd0)
486 result[i++] = inb(FIFO);
487 else
488 break;
489 } while (i < 2);
490
491 return result[0];
492}
493
494static void sun_pci_fd_reset(unsigned long port)
495{
496 unsigned char mask = 0x00;
497 unsigned char status;
498 int timeout = 10000;
499
500 outb(0x80, MSR);
501 do {
502 status = sun_pci_fd_sensei(port);
503 if ((status & 0xc0) == 0xc0)
504 mask |= 1 << (status & 0x03);
505 else
506 udelay(100);
507 } while ((mask != 0x0f) && --timeout);
508}
509
510static int sun_pci_fd_test_drive(unsigned long port, int drive)
511{
512 unsigned char status, data;
513 int timeout = 1000;
514 int ready;
515
516 sun_pci_fd_reset(port);
517
518 data = (0x10 << drive) | 0x0c | drive;
519 sun_pci_fd_out_byte(port, data, DOR);
520
521 sun_pci_fd_out_byte(port, 0x07, FIFO);
522 sun_pci_fd_out_byte(port, drive & 0x03, FIFO);
523
524 do {
525 udelay(100);
526 status = sun_pci_fd_sensei(port);
527 } while (((status & 0xc0) == 0x80) && --timeout);
528
529 if (!timeout)
530 ready = 0;
531 else
532 ready = (status & 0x10) ? 0 : 1;
533
534 sun_pci_fd_reset(port);
535 return ready;
536}
537#undef FIFO
538#undef MSR
539#undef DOR
540
541#endif /* CONFIG_PCI */
542
543#ifdef CONFIG_PCI
544static int __init ebus_fdthree_p(struct linux_ebus_device *edev)
545{
546 if (!strcmp(edev->prom_node->name, "fdthree"))
547 return 1;
548 if (!strcmp(edev->prom_node->name, "floppy")) {
549 const char *compat;
550
551 compat = of_get_property(edev->prom_node,
552 "compatible", NULL);
553 if (compat && !strcmp(compat, "fdthree"))
554 return 1;
555 }
556 return 0;
557}
558#endif
559
560static unsigned long __init sun_floppy_init(void)
561{
562 char state[128];
563 struct sbus_bus *bus;
564 struct sbus_dev *sdev = NULL;
565 static int initialized = 0;
566
567 if (initialized)
568 return sun_floppy_types[0];
569 initialized = 1;
570
571 for_all_sbusdev (sdev, bus) {
572 if (!strcmp(sdev->prom_name, "SUNW,fdtwo"))
573 break;
574 }
575 if(sdev) {
576 floppy_sdev = sdev;
577 FLOPPY_IRQ = sdev->irqs[0];
578 } else {
579#ifdef CONFIG_PCI
580 struct linux_ebus *ebus;
581 struct linux_ebus_device *edev = NULL;
582 unsigned long config = 0;
583 void __iomem *auxio_reg;
584 const char *state_prop;
585
586 for_each_ebus(ebus) {
587 for_each_ebusdev(edev, ebus) {
588 if (ebus_fdthree_p(edev))
589 goto ebus_done;
590 }
591 }
592 ebus_done:
593 if (!edev)
594 return 0;
595
596 state_prop = of_get_property(edev->prom_node, "status", NULL);
597 if (state_prop && !strncmp(state_prop, "disabled", 8))
598 return 0;
599
600 FLOPPY_IRQ = edev->irqs[0];
601
602 /* Make sure the high density bit is set, some systems
603 * (most notably Ultra5/Ultra10) come up with it clear.
604 */
605 auxio_reg = (void __iomem *) edev->resource[2].start;
606 writel(readl(auxio_reg)|0x2, auxio_reg);
607
608 sun_pci_ebus_dev = ebus->self;
609
610 spin_lock_init(&sun_pci_fd_ebus_dma.lock);
611
612 /* XXX ioremap */
613 sun_pci_fd_ebus_dma.regs = (void __iomem *)
614 edev->resource[1].start;
615 if (!sun_pci_fd_ebus_dma.regs)
616 return 0;
617
618 sun_pci_fd_ebus_dma.flags = (EBUS_DMA_FLAG_USE_EBDMA_HANDLER |
619 EBUS_DMA_FLAG_TCI_DISABLE);
620 sun_pci_fd_ebus_dma.callback = sun_pci_fd_dma_callback;
621 sun_pci_fd_ebus_dma.client_cookie = NULL;
622 sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ;
623 strcpy(sun_pci_fd_ebus_dma.name, "floppy");
624 if (ebus_dma_register(&sun_pci_fd_ebus_dma))
625 return 0;
626
627 /* XXX ioremap */
628 sun_fdc = (struct sun_flpy_controller *)edev->resource[0].start;
629
630 sun_fdops.fd_inb = sun_pci_fd_inb;
631 sun_fdops.fd_outb = sun_pci_fd_outb;
632
633 can_use_virtual_dma = use_virtual_dma = 0;
634 sun_fdops.fd_enable_dma = sun_pci_fd_enable_dma;
635 sun_fdops.fd_disable_dma = sun_pci_fd_disable_dma;
636 sun_fdops.fd_set_dma_mode = sun_pci_fd_set_dma_mode;
637 sun_fdops.fd_set_dma_addr = sun_pci_fd_set_dma_addr;
638 sun_fdops.fd_set_dma_count = sun_pci_fd_set_dma_count;
639 sun_fdops.get_dma_residue = sun_pci_get_dma_residue;
640
641 sun_fdops.fd_request_irq = sun_pci_fd_request_irq;
642 sun_fdops.fd_free_irq = sun_pci_fd_free_irq;
643
644 sun_fdops.fd_eject = sun_pci_fd_eject;
645
646 fdc_status = (unsigned long) &sun_fdc->status_82077;
647
648 /*
649 * XXX: Find out on which machines this is really needed.
650 */
651 if (1) {
652 sun_pci_broken_drive = 1;
653 sun_fdops.fd_outb = sun_pci_fd_broken_outb;
654 }
655
656 allowed_drive_mask = 0;
657 if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 0))
658 sun_floppy_types[0] = 4;
659 if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 1))
660 sun_floppy_types[1] = 4;
661
662 /*
663 * Find NS87303 SuperIO config registers (through ecpp).
664 */
665 for_each_ebus(ebus) {
666 for_each_ebusdev(edev, ebus) {
667 if (!strcmp(edev->prom_node->name, "ecpp")) {
668 config = edev->resource[1].start;
669 goto config_done;
670 }
671 }
672 }
673 config_done:
674
675 /*
676 * Sanity check, is this really the NS87303?
677 */
678 switch (config & 0x3ff) {
679 case 0x02e:
680 case 0x15c:
681 case 0x26e:
682 case 0x398:
683 break;
684 default:
685 config = 0;
686 }
687
688 if (!config)
689 return sun_floppy_types[0];
690
691 /* Enable PC-AT mode. */
692 ns87303_modify(config, ASC, 0, 0xc0);
693
694#ifdef PCI_FDC_SWAP_DRIVES
695 /*
696 * If only Floppy 1 is present, swap drives.
697 */
698 if (!sun_floppy_types[0] && sun_floppy_types[1]) {
699 /*
700 * Set the drive exchange bit in FCR on NS87303,
701 * make sure other bits are sane before doing so.
702 */
703 ns87303_modify(config, FER, FER_EDM, 0);
704 ns87303_modify(config, ASC, ASC_DRV2_SEL, 0);
705 ns87303_modify(config, FCR, 0, FCR_LDE);
706
707 config = sun_floppy_types[0];
708 sun_floppy_types[0] = sun_floppy_types[1];
709 sun_floppy_types[1] = config;
710
711 if (sun_pci_broken_drive != -1) {
712 sun_pci_broken_drive = 1 - sun_pci_broken_drive;
713 sun_fdops.fd_outb = sun_pci_fd_lde_broken_outb;
714 }
715 }
716#endif /* PCI_FDC_SWAP_DRIVES */
717
718 return sun_floppy_types[0];
719#else
720 return 0;
721#endif
722 }
723 prom_getproperty(sdev->prom_node, "status", state, sizeof(state));
724 if(!strncmp(state, "disabled", 8))
725 return 0;
726
727 /*
728 * We cannot do sbus_ioremap here: it does request_region,
729 * which the generic floppy driver tries to do once again.
730 * But we must use the sdev resource values as they have
731 * had parent ranges applied.
732 */
733 sun_fdc = (struct sun_flpy_controller *)
734 (sdev->resource[0].start +
735 ((sdev->resource[0].flags & 0x1ffUL) << 32UL));
736
737 /* Last minute sanity check... */
738 if(sbus_readb(&sun_fdc->status1_82077) == 0xff) {
739 sun_fdc = (struct sun_flpy_controller *)-1;
740 return 0;
741 }
742
743 sun_fdops.fd_inb = sun_82077_fd_inb;
744 sun_fdops.fd_outb = sun_82077_fd_outb;
745
746 can_use_virtual_dma = use_virtual_dma = 1;
747 sun_fdops.fd_enable_dma = sun_fd_enable_dma;
748 sun_fdops.fd_disable_dma = sun_fd_disable_dma;
749 sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
750 sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
751 sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
752 sun_fdops.get_dma_residue = sun_get_dma_residue;
753
754 sun_fdops.fd_request_irq = sun_fd_request_irq;
755 sun_fdops.fd_free_irq = sun_fd_free_irq;
756
757 sun_fdops.fd_eject = sun_fd_eject;
758
759 fdc_status = (unsigned long) &sun_fdc->status_82077;
760
761 /* Success... */
762 allowed_drive_mask = 0x01;
763 sun_floppy_types[0] = 4;
764 sun_floppy_types[1] = 0;
765
766 return sun_floppy_types[0];
767}
768
769#define EXTRA_FLOPPY_PARAMS
770
771static DEFINE_SPINLOCK(dma_spin_lock);
772
773#define claim_dma_lock() \
774({ unsigned long flags; \
775 spin_lock_irqsave(&dma_spin_lock, flags); \
776 flags; \
777})
778
779#define release_dma_lock(__flags) \
780 spin_unlock_irqrestore(&dma_spin_lock, __flags);
781
782#endif /* !(__ASM_SPARC64_FLOPPY_H) */
diff --git a/include/asm-sparc64/fpumacro.h b/include/asm-sparc64/fpumacro.h
index cc463fec806f..30d6d0f68bc3 100644
--- a/include/asm-sparc64/fpumacro.h
+++ b/include/asm-sparc64/fpumacro.h
@@ -1,33 +1 @@
1/* fpumacro.h: FPU related macros. #include <asm-sparc/fpumacro.h>
2 *
3 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef _SPARC64_FPUMACRO_H
8#define _SPARC64_FPUMACRO_H
9
10#include <asm/asi.h>
11#include <asm/visasm.h>
12
13struct fpustate {
14 u32 regs[64];
15};
16
17#define FPUSTATE (struct fpustate *)(current_thread_info()->fpregs)
18
19static inline unsigned long fprs_read(void)
20{
21 unsigned long retval;
22
23 __asm__ __volatile__("rd %%fprs, %0" : "=r" (retval));
24
25 return retval;
26}
27
28static inline void fprs_write(unsigned long val)
29{
30 __asm__ __volatile__("wr %0, 0x0, %%fprs" : : "r" (val));
31}
32
33#endif /* !(_SPARC64_FPUMACRO_H) */
diff --git a/include/asm-sparc64/futex.h b/include/asm-sparc64/futex.h
index d8378935ae90..1ceb0bb2fe53 100644
--- a/include/asm-sparc64/futex.h
+++ b/include/asm-sparc64/futex.h
@@ -1,110 +1 @@
1#ifndef _SPARC64_FUTEX_H #include <asm-sparc/futex.h>
2#define _SPARC64_FUTEX_H
3
4#include <linux/futex.h>
5#include <linux/uaccess.h>
6#include <asm/errno.h>
7#include <asm/system.h>
8
9#define __futex_cas_op(insn, ret, oldval, uaddr, oparg) \
10 __asm__ __volatile__( \
11 "\n1: lduwa [%3] %%asi, %2\n" \
12 " " insn "\n" \
13 "2: casa [%3] %%asi, %2, %1\n" \
14 " cmp %2, %1\n" \
15 " bne,pn %%icc, 1b\n" \
16 " mov 0, %0\n" \
17 "3:\n" \
18 " .section .fixup,#alloc,#execinstr\n" \
19 " .align 4\n" \
20 "4: sethi %%hi(3b), %0\n" \
21 " jmpl %0 + %%lo(3b), %%g0\n" \
22 " mov %5, %0\n" \
23 " .previous\n" \
24 " .section __ex_table,\"a\"\n" \
25 " .align 4\n" \
26 " .word 1b, 4b\n" \
27 " .word 2b, 4b\n" \
28 " .previous\n" \
29 : "=&r" (ret), "=&r" (oldval), "=&r" (tem) \
30 : "r" (uaddr), "r" (oparg), "i" (-EFAULT) \
31 : "memory")
32
33static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
34{
35 int op = (encoded_op >> 28) & 7;
36 int cmp = (encoded_op >> 24) & 15;
37 int oparg = (encoded_op << 8) >> 20;
38 int cmparg = (encoded_op << 20) >> 20;
39 int oldval = 0, ret, tem;
40
41 if (unlikely(!access_ok(VERIFY_WRITE, uaddr, sizeof(int))))
42 return -EFAULT;
43 if (unlikely((((unsigned long) uaddr) & 0x3UL)))
44 return -EINVAL;
45
46 if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
47 oparg = 1 << oparg;
48
49 pagefault_disable();
50
51 switch (op) {
52 case FUTEX_OP_SET:
53 __futex_cas_op("mov\t%4, %1", ret, oldval, uaddr, oparg);
54 break;
55 case FUTEX_OP_ADD:
56 __futex_cas_op("add\t%2, %4, %1", ret, oldval, uaddr, oparg);
57 break;
58 case FUTEX_OP_OR:
59 __futex_cas_op("or\t%2, %4, %1", ret, oldval, uaddr, oparg);
60 break;
61 case FUTEX_OP_ANDN:
62 __futex_cas_op("and\t%2, %4, %1", ret, oldval, uaddr, oparg);
63 break;
64 case FUTEX_OP_XOR:
65 __futex_cas_op("xor\t%2, %4, %1", ret, oldval, uaddr, oparg);
66 break;
67 default:
68 ret = -ENOSYS;
69 }
70
71 pagefault_enable();
72
73 if (!ret) {
74 switch (cmp) {
75 case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
76 case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
77 case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break;
78 case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break;
79 case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break;
80 case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break;
81 default: ret = -ENOSYS;
82 }
83 }
84 return ret;
85}
86
87static inline int
88futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
89{
90 __asm__ __volatile__(
91 "\n1: casa [%3] %%asi, %2, %0\n"
92 "2:\n"
93 " .section .fixup,#alloc,#execinstr\n"
94 " .align 4\n"
95 "3: sethi %%hi(2b), %0\n"
96 " jmpl %0 + %%lo(2b), %%g0\n"
97 " mov %4, %0\n"
98 " .previous\n"
99 " .section __ex_table,\"a\"\n"
100 " .align 4\n"
101 " .word 1b, 3b\n"
102 " .previous\n"
103 : "=r" (newval)
104 : "0" (newval), "r" (oldval), "r" (uaddr), "i" (-EFAULT)
105 : "memory");
106
107 return newval;
108}
109
110#endif /* !(_SPARC64_FUTEX_H) */
diff --git a/include/asm-sparc64/hardirq.h b/include/asm-sparc64/hardirq.h
index 7c29fd1a87aa..63dca3db11f3 100644
--- a/include/asm-sparc64/hardirq.h
+++ b/include/asm-sparc64/hardirq.h
@@ -1,19 +1 @@
1/* hardirq.h: 64-bit Sparc hard IRQ support. #include <asm-sparc/hardirq.h>
2 *
3 * Copyright (C) 1997, 1998, 2005 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef __SPARC64_HARDIRQ_H
7#define __SPARC64_HARDIRQ_H
8
9#include <asm/cpudata.h>
10
11#define __ARCH_IRQ_STAT
12#define local_softirq_pending() \
13 (local_cpu_data().__softirq_pending)
14
15void ack_bad_irq(unsigned int irq);
16
17#define HARDIRQ_BITS 8
18
19#endif /* !(__SPARC64_HARDIRQ_H) */
diff --git a/include/asm-sparc64/head.h b/include/asm-sparc64/head.h
index 10e9dabc4c41..2254c09e53f9 100644
--- a/include/asm-sparc64/head.h
+++ b/include/asm-sparc64/head.h
@@ -1,76 +1 @@
1#ifndef _SPARC64_HEAD_H #include <asm-sparc/head.h>
2#define _SPARC64_HEAD_H
3
4#include <asm/pstate.h>
5
6 /* wrpr %g0, val, %gl */
7#define SET_GL(val) \
8 .word 0xa1902000 | val
9
10 /* rdpr %gl, %gN */
11#define GET_GL_GLOBAL(N) \
12 .word 0x81540000 | (N << 25)
13
14#define KERNBASE 0x400000
15
16#define PTREGS_OFF (STACK_BIAS + STACKFRAME_SZ)
17
18#define __CHEETAH_ID 0x003e0014
19#define __JALAPENO_ID 0x003e0016
20#define __SERRANO_ID 0x003e0022
21
22#define CHEETAH_MANUF 0x003e
23#define CHEETAH_IMPL 0x0014 /* Ultra-III */
24#define CHEETAH_PLUS_IMPL 0x0015 /* Ultra-III+ */
25#define JALAPENO_IMPL 0x0016 /* Ultra-IIIi */
26#define JAGUAR_IMPL 0x0018 /* Ultra-IV */
27#define PANTHER_IMPL 0x0019 /* Ultra-IV+ */
28#define SERRANO_IMPL 0x0022 /* Ultra-IIIi+ */
29
30#define BRANCH_IF_SUN4V(tmp1,label) \
31 sethi %hi(is_sun4v), %tmp1; \
32 lduw [%tmp1 + %lo(is_sun4v)], %tmp1; \
33 brnz,pn %tmp1, label; \
34 nop
35
36#define BRANCH_IF_CHEETAH_BASE(tmp1,tmp2,label) \
37 rdpr %ver, %tmp1; \
38 sethi %hi(__CHEETAH_ID), %tmp2; \
39 srlx %tmp1, 32, %tmp1; \
40 or %tmp2, %lo(__CHEETAH_ID), %tmp2;\
41 cmp %tmp1, %tmp2; \
42 be,pn %icc, label; \
43 nop;
44
45#define BRANCH_IF_JALAPENO(tmp1,tmp2,label) \
46 rdpr %ver, %tmp1; \
47 sethi %hi(__JALAPENO_ID), %tmp2; \
48 srlx %tmp1, 32, %tmp1; \
49 or %tmp2, %lo(__JALAPENO_ID), %tmp2;\
50 cmp %tmp1, %tmp2; \
51 be,pn %icc, label; \
52 nop;
53
54#define BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(tmp1,tmp2,label) \
55 rdpr %ver, %tmp1; \
56 srlx %tmp1, (32 + 16), %tmp2; \
57 cmp %tmp2, CHEETAH_MANUF; \
58 bne,pt %xcc, 99f; \
59 sllx %tmp1, 16, %tmp1; \
60 srlx %tmp1, (32 + 16), %tmp2; \
61 cmp %tmp2, CHEETAH_PLUS_IMPL; \
62 bgeu,pt %xcc, label; \
6399: nop;
64
65#define BRANCH_IF_ANY_CHEETAH(tmp1,tmp2,label) \
66 rdpr %ver, %tmp1; \
67 srlx %tmp1, (32 + 16), %tmp2; \
68 cmp %tmp2, CHEETAH_MANUF; \
69 bne,pt %xcc, 99f; \
70 sllx %tmp1, 16, %tmp1; \
71 srlx %tmp1, (32 + 16), %tmp2; \
72 cmp %tmp2, CHEETAH_IMPL; \
73 bgeu,pt %xcc, label; \
7499: nop;
75
76#endif /* !(_SPARC64_HEAD_H) */
diff --git a/include/asm-sparc64/hugetlb.h b/include/asm-sparc64/hugetlb.h
index 412af58926a0..21d8f0a9c243 100644
--- a/include/asm-sparc64/hugetlb.h
+++ b/include/asm-sparc64/hugetlb.h
@@ -1,84 +1 @@
1#ifndef _ASM_SPARC64_HUGETLB_H #include <asm-sparc/hugetlb.h>
2#define _ASM_SPARC64_HUGETLB_H
3
4#include <asm/page.h>
5
6
7void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
8 pte_t *ptep, pte_t pte);
9
10pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
11 pte_t *ptep);
12
13void hugetlb_prefault_arch_hook(struct mm_struct *mm);
14
15static inline int is_hugepage_only_range(struct mm_struct *mm,
16 unsigned long addr,
17 unsigned long len) {
18 return 0;
19}
20
21/*
22 * If the arch doesn't supply something else, assume that hugepage
23 * size aligned regions are ok without further preparation.
24 */
25static inline int prepare_hugepage_range(unsigned long addr, unsigned long len)
26{
27 if (len & ~HPAGE_MASK)
28 return -EINVAL;
29 if (addr & ~HPAGE_MASK)
30 return -EINVAL;
31 return 0;
32}
33
34static inline void hugetlb_free_pgd_range(struct mmu_gather **tlb,
35 unsigned long addr, unsigned long end,
36 unsigned long floor,
37 unsigned long ceiling)
38{
39 free_pgd_range(tlb, addr, end, floor, ceiling);
40}
41
42static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
43 unsigned long addr, pte_t *ptep)
44{
45}
46
47static inline int huge_pte_none(pte_t pte)
48{
49 return pte_none(pte);
50}
51
52static inline pte_t huge_pte_wrprotect(pte_t pte)
53{
54 return pte_wrprotect(pte);
55}
56
57static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
58 unsigned long addr, pte_t *ptep)
59{
60 ptep_set_wrprotect(mm, addr, ptep);
61}
62
63static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
64 unsigned long addr, pte_t *ptep,
65 pte_t pte, int dirty)
66{
67 return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
68}
69
70static inline pte_t huge_ptep_get(pte_t *ptep)
71{
72 return *ptep;
73}
74
75static inline int arch_prepare_hugepage(struct page *page)
76{
77 return 0;
78}
79
80static inline void arch_release_hugepage(struct page *page)
81{
82}
83
84#endif /* _ASM_SPARC64_HUGETLB_H */
diff --git a/include/asm-sparc64/hvtramp.h b/include/asm-sparc64/hvtramp.h
index b2b9b947b3a4..fb46bfe934a7 100644
--- a/include/asm-sparc64/hvtramp.h
+++ b/include/asm-sparc64/hvtramp.h
@@ -1,37 +1 @@
1#ifndef _SPARC64_HVTRAP_H #include <asm-sparc/hvtramp.h>
2#define _SPARC64_HVTRAP_H
3
4#ifndef __ASSEMBLY__
5
6#include <linux/types.h>
7
8struct hvtramp_mapping {
9 __u64 vaddr;
10 __u64 tte;
11};
12
13struct hvtramp_descr {
14 __u32 cpu;
15 __u32 num_mappings;
16 __u64 fault_info_va;
17 __u64 fault_info_pa;
18 __u64 thread_reg;
19 struct hvtramp_mapping maps[1];
20};
21
22extern void hv_cpu_startup(unsigned long hvdescr_pa);
23
24#endif
25
26#define HVTRAMP_DESCR_CPU 0x00
27#define HVTRAMP_DESCR_NUM_MAPPINGS 0x04
28#define HVTRAMP_DESCR_FAULT_INFO_VA 0x08
29#define HVTRAMP_DESCR_FAULT_INFO_PA 0x10
30#define HVTRAMP_DESCR_THREAD_REG 0x18
31#define HVTRAMP_DESCR_MAPS 0x20
32
33#define HVTRAMP_MAPPING_VADDR 0x00
34#define HVTRAMP_MAPPING_TTE 0x08
35#define HVTRAMP_MAPPING_SIZE 0x10
36
37#endif /* _SPARC64_HVTRAP_H */
diff --git a/include/asm-sparc64/hw_irq.h b/include/asm-sparc64/hw_irq.h
index 8e44a8360829..16920a291f51 100644
--- a/include/asm-sparc64/hw_irq.h
+++ b/include/asm-sparc64/hw_irq.h
@@ -1,4 +1 @@
1#ifndef __ASM_SPARC64_HW_IRQ_H #include <asm-sparc/hw_irq.h>
2#define __ASM_SPARC64_HW_IRQ_H
3
4#endif
diff --git a/include/asm-sparc64/hypervisor.h b/include/asm-sparc64/hypervisor.h
index 3ad45dff52f8..fe7e51a9e429 100644
--- a/include/asm-sparc64/hypervisor.h
+++ b/include/asm-sparc64/hypervisor.h
@@ -1,2945 +1 @@
1#ifndef _SPARC64_HYPERVISOR_H #include <asm-sparc/hypervisor.h>
2#define _SPARC64_HYPERVISOR_H
3
4/* Sun4v hypervisor interfaces and defines.
5 *
6 * Hypervisor calls are made via traps to software traps number 0x80
7 * and above. Registers %o0 to %o5 serve as argument, status, and
8 * return value registers.
9 *
10 * There are two kinds of these traps. First there are the normal
11 * "fast traps" which use software trap 0x80 and encode the function
12 * to invoke by number in register %o5. Argument and return value
13 * handling is as follows:
14 *
15 * -----------------------------------------------
16 * | %o5 | function number | undefined |
17 * | %o0 | argument 0 | return status |
18 * | %o1 | argument 1 | return value 1 |
19 * | %o2 | argument 2 | return value 2 |
20 * | %o3 | argument 3 | return value 3 |
21 * | %o4 | argument 4 | return value 4 |
22 * -----------------------------------------------
23 *
24 * The second type are "hyper-fast traps" which encode the function
25 * number in the software trap number itself. So these use trap
26 * numbers > 0x80. The register usage for hyper-fast traps is as
27 * follows:
28 *
29 * -----------------------------------------------
30 * | %o0 | argument 0 | return status |
31 * | %o1 | argument 1 | return value 1 |
32 * | %o2 | argument 2 | return value 2 |
33 * | %o3 | argument 3 | return value 3 |
34 * | %o4 | argument 4 | return value 4 |
35 * -----------------------------------------------
36 *
37 * Registers providing explicit arguments to the hypervisor calls
38 * are volatile across the call. Upon return their values are
39 * undefined unless explicitly specified as containing a particular
40 * return value by the specific call. The return status is always
41 * returned in register %o0, zero indicates a successful execution of
42 * the hypervisor call and other values indicate an error status as
43 * defined below. So, for example, if a hyper-fast trap takes
44 * arguments 0, 1, and 2, then %o0, %o1, and %o2 are volatile across
45 * the call and %o3, %o4, and %o5 would be preserved.
46 *
47 * If the hypervisor trap is invalid, or the fast trap function number
48 * is invalid, HV_EBADTRAP will be returned in %o0. Also, all 64-bits
49 * of the argument and return values are significant.
50 */
51
52/* Trap numbers. */
53#define HV_FAST_TRAP 0x80
54#define HV_MMU_MAP_ADDR_TRAP 0x83
55#define HV_MMU_UNMAP_ADDR_TRAP 0x84
56#define HV_TTRACE_ADDENTRY_TRAP 0x85
57#define HV_CORE_TRAP 0xff
58
59/* Error codes. */
60#define HV_EOK 0 /* Successful return */
61#define HV_ENOCPU 1 /* Invalid CPU id */
62#define HV_ENORADDR 2 /* Invalid real address */
63#define HV_ENOINTR 3 /* Invalid interrupt id */
64#define HV_EBADPGSZ 4 /* Invalid pagesize encoding */
65#define HV_EBADTSB 5 /* Invalid TSB description */
66#define HV_EINVAL 6 /* Invalid argument */
67#define HV_EBADTRAP 7 /* Invalid function number */
68#define HV_EBADALIGN 8 /* Invalid address alignment */
69#define HV_EWOULDBLOCK 9 /* Cannot complete w/o blocking */
70#define HV_ENOACCESS 10 /* No access to resource */
71#define HV_EIO 11 /* I/O error */
72#define HV_ECPUERROR 12 /* CPU in error state */
73#define HV_ENOTSUPPORTED 13 /* Function not supported */
74#define HV_ENOMAP 14 /* No mapping found */
75#define HV_ETOOMANY 15 /* Too many items specified */
76#define HV_ECHANNEL 16 /* Invalid LDC channel */
77#define HV_EBUSY 17 /* Resource busy */
78
79/* mach_exit()
80 * TRAP: HV_FAST_TRAP
81 * FUNCTION: HV_FAST_MACH_EXIT
82 * ARG0: exit code
83 * ERRORS: This service does not return.
84 *
85 * Stop all CPUs in the virtual domain and place them into the stopped
86 * state. The 64-bit exit code may be passed to a service entity as
87 * the domain's exit status. On systems without a service entity, the
88 * domain will undergo a reset, and the boot firmware will be
89 * reloaded.
90 *
91 * This function will never return to the guest that invokes it.
92 *
93 * Note: By convention an exit code of zero denotes a successful exit by
94 * the guest code. A non-zero exit code denotes a guest specific
95 * error indication.
96 *
97 */
98#define HV_FAST_MACH_EXIT 0x00
99
100#ifndef __ASSEMBLY__
101extern void sun4v_mach_exit(unsigned long exit_code);
102#endif
103
104/* Domain services. */
105
106/* mach_desc()
107 * TRAP: HV_FAST_TRAP
108 * FUNCTION: HV_FAST_MACH_DESC
109 * ARG0: buffer
110 * ARG1: length
111 * RET0: status
112 * RET1: length
113 * ERRORS: HV_EBADALIGN Buffer is badly aligned
114 * HV_ENORADDR Buffer is to an illegal real address.
115 * HV_EINVAL Buffer length is too small for complete
116 * machine description.
117 *
118 * Copy the most current machine description into the buffer indicated
119 * by the real address in ARG0. The buffer provided must be 16 byte
120 * aligned. Upon success or HV_EINVAL, this service returns the
121 * actual size of the machine description in the RET1 return value.
122 *
123 * Note: A method of determining the appropriate buffer size for the
124 * machine description is to first call this service with a buffer
125 * length of 0 bytes.
126 */
127#define HV_FAST_MACH_DESC 0x01
128
129#ifndef __ASSEMBLY__
130extern unsigned long sun4v_mach_desc(unsigned long buffer_pa,
131 unsigned long buf_len,
132 unsigned long *real_buf_len);
133#endif
134
135/* mach_sir()
136 * TRAP: HV_FAST_TRAP
137 * FUNCTION: HV_FAST_MACH_SIR
138 * ERRORS: This service does not return.
139 *
140 * Perform a software initiated reset of the virtual machine domain.
141 * All CPUs are captured as soon as possible, all hardware devices are
142 * returned to the entry default state, and the domain is restarted at
143 * the SIR (trap type 0x04) real trap table (RTBA) entry point on one
144 * of the CPUs. The single CPU restarted is selected as determined by
145 * platform specific policy. Memory is preserved across this
146 * operation.
147 */
148#define HV_FAST_MACH_SIR 0x02
149
150#ifndef __ASSEMBLY__
151extern void sun4v_mach_sir(void);
152#endif
153
154/* mach_set_watchdog()
155 * TRAP: HV_FAST_TRAP
156 * FUNCTION: HV_FAST_MACH_SET_WATCHDOG
157 * ARG0: timeout in milliseconds
158 * RET0: status
159 * RET1: time remaining in milliseconds
160 *
161 * A guest uses this API to set a watchdog timer. Once the gues has set
162 * the timer, it must call the timer service again either to disable or
163 * postpone the expiration. If the timer expires before being reset or
164 * disabled, then the hypervisor take a platform specific action leading
165 * to guest termination within a bounded time period. The platform action
166 * may include recovery actions such as reporting the expiration to a
167 * Service Processor, and/or automatically restarting the gues.
168 *
169 * The 'timeout' parameter is specified in milliseconds, however the
170 * implementated granularity is given by the 'watchdog-resolution'
171 * property in the 'platform' node of the guest's machine description.
172 * The largest allowed timeout value is specified by the
173 * 'watchdog-max-timeout' property of the 'platform' node.
174 *
175 * If the 'timeout' argument is not zero, the watchdog timer is set to
176 * expire after a minimum of 'timeout' milliseconds.
177 *
178 * If the 'timeout' argument is zero, the watchdog timer is disabled.
179 *
180 * If the 'timeout' value exceeds the value of the 'max-watchdog-timeout'
181 * property, the hypervisor leaves the watchdog timer state unchanged,
182 * and returns a status of EINVAL.
183 *
184 * The 'time remaining' return value is valid regardless of whether the
185 * return status is EOK or EINVAL. A non-zero return value indicates the
186 * number of milliseconds that were remaining until the timer was to expire.
187 * If less than one millisecond remains, the return value is '1'. If the
188 * watchdog timer was disabled at the time of the call, the return value is
189 * zero.
190 *
191 * If the hypervisor cannot support the exact timeout value requested, but
192 * can support a larger timeout value, the hypervisor may round the actual
193 * timeout to a value larger than the requested timeout, consequently the
194 * 'time remaining' return value may be larger than the previously requested
195 * timeout value.
196 *
197 * Any guest OS debugger should be aware that the watchdog service may be in
198 * use. Consequently, it is recommended that the watchdog service is
199 * disabled upon debugger entry (e.g. reaching a breakpoint), and then
200 * re-enabled upon returning to normal execution. The API has been designed
201 * with this in mind, and the 'time remaining' result of the disable call may
202 * be used directly as the timeout argument of the re-enable call.
203 */
204#define HV_FAST_MACH_SET_WATCHDOG 0x05
205
206#ifndef __ASSEMBLY__
207extern unsigned long sun4v_mach_set_watchdog(unsigned long timeout,
208 unsigned long *orig_timeout);
209#endif
210
211/* CPU services.
212 *
213 * CPUs represent devices that can execute software threads. A single
214 * chip that contains multiple cores or strands is represented as
215 * multiple CPUs with unique CPU identifiers. CPUs are exported to
216 * OBP via the machine description (and to the OS via the OBP device
217 * tree). CPUs are always in one of three states: stopped, running,
218 * or error.
219 *
220 * A CPU ID is a pre-assigned 16-bit value that uniquely identifies a
221 * CPU within a logical domain. Operations that are to be performed
222 * on multiple CPUs specify them via a CPU list. A CPU list is an
223 * array in real memory, of which each 16-bit word is a CPU ID. CPU
224 * lists are passed through the API as two arguments. The first is
225 * the number of entries (16-bit words) in the CPU list, and the
226 * second is the (real address) pointer to the CPU ID list.
227 */
228
229/* cpu_start()
230 * TRAP: HV_FAST_TRAP
231 * FUNCTION: HV_FAST_CPU_START
232 * ARG0: CPU ID
233 * ARG1: PC
234 * ARG2: RTBA
235 * ARG3: target ARG0
236 * RET0: status
237 * ERRORS: ENOCPU Invalid CPU ID
238 * EINVAL Target CPU ID is not in the stopped state
239 * ENORADDR Invalid PC or RTBA real address
240 * EBADALIGN Unaligned PC or unaligned RTBA
241 * EWOULDBLOCK Starting resources are not available
242 *
243 * Start CPU with given CPU ID with PC in %pc and with a real trap
244 * base address value of RTBA. The indicated CPU must be in the
245 * stopped state. The supplied RTBA must be aligned on a 256 byte
246 * boundary. On successful completion, the specified CPU will be in
247 * the running state and will be supplied with "target ARG0" in %o0
248 * and RTBA in %tba.
249 */
250#define HV_FAST_CPU_START 0x10
251
252#ifndef __ASSEMBLY__
253extern unsigned long sun4v_cpu_start(unsigned long cpuid,
254 unsigned long pc,
255 unsigned long rtba,
256 unsigned long arg0);
257#endif
258
259/* cpu_stop()
260 * TRAP: HV_FAST_TRAP
261 * FUNCTION: HV_FAST_CPU_STOP
262 * ARG0: CPU ID
263 * RET0: status
264 * ERRORS: ENOCPU Invalid CPU ID
265 * EINVAL Target CPU ID is the current cpu
266 * EINVAL Target CPU ID is not in the running state
267 * EWOULDBLOCK Stopping resources are not available
268 * ENOTSUPPORTED Not supported on this platform
269 *
270 * The specified CPU is stopped. The indicated CPU must be in the
271 * running state. On completion, it will be in the stopped state. It
272 * is not legal to stop the current CPU.
273 *
274 * Note: As this service cannot be used to stop the current cpu, this service
275 * may not be used to stop the last running CPU in a domain. To stop
276 * and exit a running domain, a guest must use the mach_exit() service.
277 */
278#define HV_FAST_CPU_STOP 0x11
279
280#ifndef __ASSEMBLY__
281extern unsigned long sun4v_cpu_stop(unsigned long cpuid);
282#endif
283
284/* cpu_yield()
285 * TRAP: HV_FAST_TRAP
286 * FUNCTION: HV_FAST_CPU_YIELD
287 * RET0: status
288 * ERRORS: No possible error.
289 *
290 * Suspend execution on the current CPU. Execution will resume when
291 * an interrupt (device, %stick_compare, or cross-call) is targeted to
292 * the CPU. On some CPUs, this API may be used by the hypervisor to
293 * save power by disabling hardware strands.
294 */
295#define HV_FAST_CPU_YIELD 0x12
296
297#ifndef __ASSEMBLY__
298extern unsigned long sun4v_cpu_yield(void);
299#endif
300
301/* cpu_qconf()
302 * TRAP: HV_FAST_TRAP
303 * FUNCTION: HV_FAST_CPU_QCONF
304 * ARG0: queue
305 * ARG1: base real address
306 * ARG2: number of entries
307 * RET0: status
308 * ERRORS: ENORADDR Invalid base real address
309 * EINVAL Invalid queue or number of entries is less
310 * than 2 or too large.
311 * EBADALIGN Base real address is not correctly aligned
312 * for size.
313 *
314 * Configure the given queue to be placed at the given base real
315 * address, with the given number of entries. The number of entries
316 * must be a power of 2. The base real address must be aligned
317 * exactly to match the queue size. Each queue entry is 64 bytes
318 * long, so for example a 32 entry queue must be aligned on a 2048
319 * byte real address boundary.
320 *
321 * The specified queue is unconfigured if the number of entries is given
322 * as zero.
323 *
324 * For the current version of this API service, the argument queue is defined
325 * as follows:
326 *
327 * queue description
328 * ----- -------------------------
329 * 0x3c cpu mondo queue
330 * 0x3d device mondo queue
331 * 0x3e resumable error queue
332 * 0x3f non-resumable error queue
333 *
334 * Note: The maximum number of entries for each queue for a specific cpu may
335 * be determined from the machine description.
336 */
337#define HV_FAST_CPU_QCONF 0x14
338#define HV_CPU_QUEUE_CPU_MONDO 0x3c
339#define HV_CPU_QUEUE_DEVICE_MONDO 0x3d
340#define HV_CPU_QUEUE_RES_ERROR 0x3e
341#define HV_CPU_QUEUE_NONRES_ERROR 0x3f
342
343#ifndef __ASSEMBLY__
344extern unsigned long sun4v_cpu_qconf(unsigned long type,
345 unsigned long queue_paddr,
346 unsigned long num_queue_entries);
347#endif
348
349/* cpu_qinfo()
350 * TRAP: HV_FAST_TRAP
351 * FUNCTION: HV_FAST_CPU_QINFO
352 * ARG0: queue
353 * RET0: status
354 * RET1: base real address
355 * RET1: number of entries
356 * ERRORS: EINVAL Invalid queue
357 *
358 * Return the configuration info for the given queue. The base real
359 * address and number of entries of the defined queue are returned.
360 * The queue argument values are the same as for cpu_qconf() above.
361 *
362 * If the specified queue is a valid queue number, but no queue has
363 * been defined, the number of entries will be set to zero and the
364 * base real address returned is undefined.
365 */
366#define HV_FAST_CPU_QINFO 0x15
367
368/* cpu_mondo_send()
369 * TRAP: HV_FAST_TRAP
370 * FUNCTION: HV_FAST_CPU_MONDO_SEND
371 * ARG0-1: CPU list
372 * ARG2: data real address
373 * RET0: status
374 * ERRORS: EBADALIGN Mondo data is not 64-byte aligned or CPU list
375 * is not 2-byte aligned.
376 * ENORADDR Invalid data mondo address, or invalid cpu list
377 * address.
378 * ENOCPU Invalid cpu in CPU list
379 * EWOULDBLOCK Some or all of the listed CPUs did not receive
380 * the mondo
381 * ECPUERROR One or more of the listed CPUs are in error
382 * state, use HV_FAST_CPU_STATE to see which ones
383 * EINVAL CPU list includes caller's CPU ID
384 *
385 * Send a mondo interrupt to the CPUs in the given CPU list with the
386 * 64-bytes at the given data real address. The data must be 64-byte
387 * aligned. The mondo data will be delivered to the cpu_mondo queues
388 * of the recipient CPUs.
389 *
390 * In all cases, error or not, the CPUs in the CPU list to which the
391 * mondo has been successfully delivered will be indicated by having
392 * their entry in CPU list updated with the value 0xffff.
393 */
394#define HV_FAST_CPU_MONDO_SEND 0x42
395
396#ifndef __ASSEMBLY__
397extern unsigned long sun4v_cpu_mondo_send(unsigned long cpu_count, unsigned long cpu_list_pa, unsigned long mondo_block_pa);
398#endif
399
400/* cpu_myid()
401 * TRAP: HV_FAST_TRAP
402 * FUNCTION: HV_FAST_CPU_MYID
403 * RET0: status
404 * RET1: CPU ID
405 * ERRORS: No errors defined.
406 *
407 * Return the hypervisor ID handle for the current CPU. Use by a
408 * virtual CPU to discover it's own identity.
409 */
410#define HV_FAST_CPU_MYID 0x16
411
412/* cpu_state()
413 * TRAP: HV_FAST_TRAP
414 * FUNCTION: HV_FAST_CPU_STATE
415 * ARG0: CPU ID
416 * RET0: status
417 * RET1: state
418 * ERRORS: ENOCPU Invalid CPU ID
419 *
420 * Retrieve the current state of the CPU with the given CPU ID.
421 */
422#define HV_FAST_CPU_STATE 0x17
423#define HV_CPU_STATE_STOPPED 0x01
424#define HV_CPU_STATE_RUNNING 0x02
425#define HV_CPU_STATE_ERROR 0x03
426
427#ifndef __ASSEMBLY__
428extern long sun4v_cpu_state(unsigned long cpuid);
429#endif
430
431/* cpu_set_rtba()
432 * TRAP: HV_FAST_TRAP
433 * FUNCTION: HV_FAST_CPU_SET_RTBA
434 * ARG0: RTBA
435 * RET0: status
436 * RET1: previous RTBA
437 * ERRORS: ENORADDR Invalid RTBA real address
438 * EBADALIGN RTBA is incorrectly aligned for a trap table
439 *
440 * Set the real trap base address of the local cpu to the given RTBA.
441 * The supplied RTBA must be aligned on a 256 byte boundary. Upon
442 * success the previous value of the RTBA is returned in RET1.
443 *
444 * Note: This service does not affect %tba
445 */
446#define HV_FAST_CPU_SET_RTBA 0x18
447
448/* cpu_set_rtba()
449 * TRAP: HV_FAST_TRAP
450 * FUNCTION: HV_FAST_CPU_GET_RTBA
451 * RET0: status
452 * RET1: previous RTBA
453 * ERRORS: No possible error.
454 *
455 * Returns the current value of RTBA in RET1.
456 */
457#define HV_FAST_CPU_GET_RTBA 0x19
458
459/* MMU services.
460 *
461 * Layout of a TSB description for mmu_tsb_ctx{,non}0() calls.
462 */
463#ifndef __ASSEMBLY__
464struct hv_tsb_descr {
465 unsigned short pgsz_idx;
466 unsigned short assoc;
467 unsigned int num_ttes; /* in TTEs */
468 unsigned int ctx_idx;
469 unsigned int pgsz_mask;
470 unsigned long tsb_base;
471 unsigned long resv;
472};
473#endif
474#define HV_TSB_DESCR_PGSZ_IDX_OFFSET 0x00
475#define HV_TSB_DESCR_ASSOC_OFFSET 0x02
476#define HV_TSB_DESCR_NUM_TTES_OFFSET 0x04
477#define HV_TSB_DESCR_CTX_IDX_OFFSET 0x08
478#define HV_TSB_DESCR_PGSZ_MASK_OFFSET 0x0c
479#define HV_TSB_DESCR_TSB_BASE_OFFSET 0x10
480#define HV_TSB_DESCR_RESV_OFFSET 0x18
481
482/* Page size bitmask. */
483#define HV_PGSZ_MASK_8K (1 << 0)
484#define HV_PGSZ_MASK_64K (1 << 1)
485#define HV_PGSZ_MASK_512K (1 << 2)
486#define HV_PGSZ_MASK_4MB (1 << 3)
487#define HV_PGSZ_MASK_32MB (1 << 4)
488#define HV_PGSZ_MASK_256MB (1 << 5)
489#define HV_PGSZ_MASK_2GB (1 << 6)
490#define HV_PGSZ_MASK_16GB (1 << 7)
491
492/* Page size index. The value given in the TSB descriptor must correspond
493 * to the smallest page size specified in the pgsz_mask page size bitmask.
494 */
495#define HV_PGSZ_IDX_8K 0
496#define HV_PGSZ_IDX_64K 1
497#define HV_PGSZ_IDX_512K 2
498#define HV_PGSZ_IDX_4MB 3
499#define HV_PGSZ_IDX_32MB 4
500#define HV_PGSZ_IDX_256MB 5
501#define HV_PGSZ_IDX_2GB 6
502#define HV_PGSZ_IDX_16GB 7
503
504/* MMU fault status area.
505 *
506 * MMU related faults have their status and fault address information
507 * placed into a memory region made available by privileged code. Each
508 * virtual processor must make a mmu_fault_area_conf() call to tell the
509 * hypervisor where that processor's fault status should be stored.
510 *
511 * The fault status block is a multiple of 64-bytes and must be aligned
512 * on a 64-byte boundary.
513 */
514#ifndef __ASSEMBLY__
515struct hv_fault_status {
516 unsigned long i_fault_type;
517 unsigned long i_fault_addr;
518 unsigned long i_fault_ctx;
519 unsigned long i_reserved[5];
520 unsigned long d_fault_type;
521 unsigned long d_fault_addr;
522 unsigned long d_fault_ctx;
523 unsigned long d_reserved[5];
524};
525#endif
526#define HV_FAULT_I_TYPE_OFFSET 0x00
527#define HV_FAULT_I_ADDR_OFFSET 0x08
528#define HV_FAULT_I_CTX_OFFSET 0x10
529#define HV_FAULT_D_TYPE_OFFSET 0x40
530#define HV_FAULT_D_ADDR_OFFSET 0x48
531#define HV_FAULT_D_CTX_OFFSET 0x50
532
533#define HV_FAULT_TYPE_FAST_MISS 1
534#define HV_FAULT_TYPE_FAST_PROT 2
535#define HV_FAULT_TYPE_MMU_MISS 3
536#define HV_FAULT_TYPE_INV_RA 4
537#define HV_FAULT_TYPE_PRIV_VIOL 5
538#define HV_FAULT_TYPE_PROT_VIOL 6
539#define HV_FAULT_TYPE_NFO 7
540#define HV_FAULT_TYPE_NFO_SEFF 8
541#define HV_FAULT_TYPE_INV_VA 9
542#define HV_FAULT_TYPE_INV_ASI 10
543#define HV_FAULT_TYPE_NC_ATOMIC 11
544#define HV_FAULT_TYPE_PRIV_ACT 12
545#define HV_FAULT_TYPE_RESV1 13
546#define HV_FAULT_TYPE_UNALIGNED 14
547#define HV_FAULT_TYPE_INV_PGSZ 15
548/* Values 16 --> -2 are reserved. */
549#define HV_FAULT_TYPE_MULTIPLE -1
550
551/* Flags argument for mmu_{map,unmap}_addr(), mmu_demap_{page,context,all}(),
552 * and mmu_{map,unmap}_perm_addr().
553 */
554#define HV_MMU_DMMU 0x01
555#define HV_MMU_IMMU 0x02
556#define HV_MMU_ALL (HV_MMU_DMMU | HV_MMU_IMMU)
557
558/* mmu_map_addr()
559 * TRAP: HV_MMU_MAP_ADDR_TRAP
560 * ARG0: virtual address
561 * ARG1: mmu context
562 * ARG2: TTE
563 * ARG3: flags (HV_MMU_{IMMU,DMMU})
564 * ERRORS: EINVAL Invalid virtual address, mmu context, or flags
565 * EBADPGSZ Invalid page size value
566 * ENORADDR Invalid real address in TTE
567 *
568 * Create a non-permanent mapping using the given TTE, virtual
569 * address, and mmu context. The flags argument determines which
570 * (data, or instruction, or both) TLB the mapping gets loaded into.
571 *
572 * The behavior is undefined if the valid bit is clear in the TTE.
573 *
574 * Note: This API call is for privileged code to specify temporary translation
575 * mappings without the need to create and manage a TSB.
576 */
577
578/* mmu_unmap_addr()
579 * TRAP: HV_MMU_UNMAP_ADDR_TRAP
580 * ARG0: virtual address
581 * ARG1: mmu context
582 * ARG2: flags (HV_MMU_{IMMU,DMMU})
583 * ERRORS: EINVAL Invalid virtual address, mmu context, or flags
584 *
585 * Demaps the given virtual address in the given mmu context on this
586 * CPU. This function is intended to be used to demap pages mapped
587 * with mmu_map_addr. This service is equivalent to invoking
588 * mmu_demap_page() with only the current CPU in the CPU list. The
589 * flags argument determines which (data, or instruction, or both) TLB
590 * the mapping gets unmapped from.
591 *
592 * Attempting to perform an unmap operation for a previously defined
593 * permanent mapping will have undefined results.
594 */
595
596/* mmu_tsb_ctx0()
597 * TRAP: HV_FAST_TRAP
598 * FUNCTION: HV_FAST_MMU_TSB_CTX0
599 * ARG0: number of TSB descriptions
600 * ARG1: TSB descriptions pointer
601 * RET0: status
602 * ERRORS: ENORADDR Invalid TSB descriptions pointer or
603 * TSB base within a descriptor
604 * EBADALIGN TSB descriptions pointer is not aligned
605 * to an 8-byte boundary, or TSB base
606 * within a descriptor is not aligned for
607 * the given TSB size
608 * EBADPGSZ Invalid page size in a TSB descriptor
609 * EBADTSB Invalid associativity or size in a TSB
610 * descriptor
611 * EINVAL Invalid number of TSB descriptions, or
612 * invalid context index in a TSB
613 * descriptor, or index page size not
614 * equal to smallest page size in page
615 * size bitmask field.
616 *
617 * Configures the TSBs for the current CPU for virtual addresses with
618 * context zero. The TSB descriptions pointer is a pointer to an
619 * array of the given number of TSB descriptions.
620 *
621 * Note: The maximum number of TSBs available to a virtual CPU is given by the
622 * mmu-max-#tsbs property of the cpu's corresponding "cpu" node in the
623 * machine description.
624 */
625#define HV_FAST_MMU_TSB_CTX0 0x20
626
627#ifndef __ASSEMBLY__
628extern unsigned long sun4v_mmu_tsb_ctx0(unsigned long num_descriptions,
629 unsigned long tsb_desc_ra);
630#endif
631
632/* mmu_tsb_ctxnon0()
633 * TRAP: HV_FAST_TRAP
634 * FUNCTION: HV_FAST_MMU_TSB_CTXNON0
635 * ARG0: number of TSB descriptions
636 * ARG1: TSB descriptions pointer
637 * RET0: status
638 * ERRORS: Same as for mmu_tsb_ctx0() above.
639 *
640 * Configures the TSBs for the current CPU for virtual addresses with
641 * non-zero contexts. The TSB descriptions pointer is a pointer to an
642 * array of the given number of TSB descriptions.
643 *
644 * Note: A maximum of 16 TSBs may be specified in the TSB description list.
645 */
646#define HV_FAST_MMU_TSB_CTXNON0 0x21
647
648/* mmu_demap_page()
649 * TRAP: HV_FAST_TRAP
650 * FUNCTION: HV_FAST_MMU_DEMAP_PAGE
651 * ARG0: reserved, must be zero
652 * ARG1: reserved, must be zero
653 * ARG2: virtual address
654 * ARG3: mmu context
655 * ARG4: flags (HV_MMU_{IMMU,DMMU})
656 * RET0: status
657 * ERRORS: EINVAL Invalid virutal address, context, or
658 * flags value
659 * ENOTSUPPORTED ARG0 or ARG1 is non-zero
660 *
661 * Demaps any page mapping of the given virtual address in the given
662 * mmu context for the current virtual CPU. Any virtually tagged
663 * caches are guaranteed to be kept consistent. The flags argument
664 * determines which TLB (instruction, or data, or both) participate in
665 * the operation.
666 *
667 * ARG0 and ARG1 are both reserved and must be set to zero.
668 */
669#define HV_FAST_MMU_DEMAP_PAGE 0x22
670
671/* mmu_demap_ctx()
672 * TRAP: HV_FAST_TRAP
673 * FUNCTION: HV_FAST_MMU_DEMAP_CTX
674 * ARG0: reserved, must be zero
675 * ARG1: reserved, must be zero
676 * ARG2: mmu context
677 * ARG3: flags (HV_MMU_{IMMU,DMMU})
678 * RET0: status
679 * ERRORS: EINVAL Invalid context or flags value
680 * ENOTSUPPORTED ARG0 or ARG1 is non-zero
681 *
682 * Demaps all non-permanent virtual page mappings previously specified
683 * for the given context for the current virtual CPU. Any virtual
684 * tagged caches are guaranteed to be kept consistent. The flags
685 * argument determines which TLB (instruction, or data, or both)
686 * participate in the operation.
687 *
688 * ARG0 and ARG1 are both reserved and must be set to zero.
689 */
690#define HV_FAST_MMU_DEMAP_CTX 0x23
691
692/* mmu_demap_all()
693 * TRAP: HV_FAST_TRAP
694 * FUNCTION: HV_FAST_MMU_DEMAP_ALL
695 * ARG0: reserved, must be zero
696 * ARG1: reserved, must be zero
697 * ARG2: flags (HV_MMU_{IMMU,DMMU})
698 * RET0: status
699 * ERRORS: EINVAL Invalid flags value
700 * ENOTSUPPORTED ARG0 or ARG1 is non-zero
701 *
702 * Demaps all non-permanent virtual page mappings previously specified
703 * for the current virtual CPU. Any virtual tagged caches are
704 * guaranteed to be kept consistent. The flags argument determines
705 * which TLB (instruction, or data, or both) participate in the
706 * operation.
707 *
708 * ARG0 and ARG1 are both reserved and must be set to zero.
709 */
710#define HV_FAST_MMU_DEMAP_ALL 0x24
711
712#ifndef __ASSEMBLY__
713extern void sun4v_mmu_demap_all(void);
714#endif
715
716/* mmu_map_perm_addr()
717 * TRAP: HV_FAST_TRAP
718 * FUNCTION: HV_FAST_MMU_MAP_PERM_ADDR
719 * ARG0: virtual address
720 * ARG1: reserved, must be zero
721 * ARG2: TTE
722 * ARG3: flags (HV_MMU_{IMMU,DMMU})
723 * RET0: status
724 * ERRORS: EINVAL Invalid virutal address or flags value
725 * EBADPGSZ Invalid page size value
726 * ENORADDR Invalid real address in TTE
727 * ETOOMANY Too many mappings (max of 8 reached)
728 *
729 * Create a permanent mapping using the given TTE and virtual address
730 * for context 0 on the calling virtual CPU. A maximum of 8 such
731 * permanent mappings may be specified by privileged code. Mappings
732 * may be removed with mmu_unmap_perm_addr().
733 *
734 * The behavior is undefined if a TTE with the valid bit clear is given.
735 *
736 * Note: This call is used to specify address space mappings for which
737 * privileged code does not expect to receive misses. For example,
738 * this mechanism can be used to map kernel nucleus code and data.
739 */
740#define HV_FAST_MMU_MAP_PERM_ADDR 0x25
741
742#ifndef __ASSEMBLY__
743extern unsigned long sun4v_mmu_map_perm_addr(unsigned long vaddr,
744 unsigned long set_to_zero,
745 unsigned long tte,
746 unsigned long flags);
747#endif
748
749/* mmu_fault_area_conf()
750 * TRAP: HV_FAST_TRAP
751 * FUNCTION: HV_FAST_MMU_FAULT_AREA_CONF
752 * ARG0: real address
753 * RET0: status
754 * RET1: previous mmu fault area real address
755 * ERRORS: ENORADDR Invalid real address
756 * EBADALIGN Invalid alignment for fault area
757 *
758 * Configure the MMU fault status area for the calling CPU. A 64-byte
759 * aligned real address specifies where MMU fault status information
760 * is placed. The return value is the previously specified area, or 0
761 * for the first invocation. Specifying a fault area at real address
762 * 0 is not allowed.
763 */
764#define HV_FAST_MMU_FAULT_AREA_CONF 0x26
765
766/* mmu_enable()
767 * TRAP: HV_FAST_TRAP
768 * FUNCTION: HV_FAST_MMU_ENABLE
769 * ARG0: enable flag
770 * ARG1: return target address
771 * RET0: status
772 * ERRORS: ENORADDR Invalid real address when disabling
773 * translation.
774 * EBADALIGN The return target address is not
775 * aligned to an instruction.
776 * EINVAL The enable flag request the current
777 * operating mode (e.g. disable if already
778 * disabled)
779 *
780 * Enable or disable virtual address translation for the calling CPU
781 * within the virtual machine domain. If the enable flag is zero,
782 * translation is disabled, any non-zero value will enable
783 * translation.
784 *
785 * When this function returns, the newly selected translation mode
786 * will be active. If the mmu is being enabled, then the return
787 * target address is a virtual address else it is a real address.
788 *
789 * Upon successful completion, control will be returned to the given
790 * return target address (ie. the cpu will jump to that address). On
791 * failure, the previous mmu mode remains and the trap simply returns
792 * as normal with the appropriate error code in RET0.
793 */
794#define HV_FAST_MMU_ENABLE 0x27
795
796/* mmu_unmap_perm_addr()
797 * TRAP: HV_FAST_TRAP
798 * FUNCTION: HV_FAST_MMU_UNMAP_PERM_ADDR
799 * ARG0: virtual address
800 * ARG1: reserved, must be zero
801 * ARG2: flags (HV_MMU_{IMMU,DMMU})
802 * RET0: status
803 * ERRORS: EINVAL Invalid virutal address or flags value
804 * ENOMAP Specified mapping was not found
805 *
806 * Demaps any permanent page mapping (established via
807 * mmu_map_perm_addr()) at the given virtual address for context 0 on
808 * the current virtual CPU. Any virtual tagged caches are guaranteed
809 * to be kept consistent.
810 */
811#define HV_FAST_MMU_UNMAP_PERM_ADDR 0x28
812
813/* mmu_tsb_ctx0_info()
814 * TRAP: HV_FAST_TRAP
815 * FUNCTION: HV_FAST_MMU_TSB_CTX0_INFO
816 * ARG0: max TSBs
817 * ARG1: buffer pointer
818 * RET0: status
819 * RET1: number of TSBs
820 * ERRORS: EINVAL Supplied buffer is too small
821 * EBADALIGN The buffer pointer is badly aligned
822 * ENORADDR Invalid real address for buffer pointer
823 *
824 * Return the TSB configuration as previous defined by mmu_tsb_ctx0()
825 * into the provided buffer. The size of the buffer is given in ARG1
826 * in terms of the number of TSB description entries.
827 *
828 * Upon return, RET1 always contains the number of TSB descriptions
829 * previously configured. If zero TSBs were configured, EOK is
830 * returned with RET1 containing 0.
831 */
832#define HV_FAST_MMU_TSB_CTX0_INFO 0x29
833
834/* mmu_tsb_ctxnon0_info()
835 * TRAP: HV_FAST_TRAP
836 * FUNCTION: HV_FAST_MMU_TSB_CTXNON0_INFO
837 * ARG0: max TSBs
838 * ARG1: buffer pointer
839 * RET0: status
840 * RET1: number of TSBs
841 * ERRORS: EINVAL Supplied buffer is too small
842 * EBADALIGN The buffer pointer is badly aligned
843 * ENORADDR Invalid real address for buffer pointer
844 *
845 * Return the TSB configuration as previous defined by
846 * mmu_tsb_ctxnon0() into the provided buffer. The size of the buffer
847 * is given in ARG1 in terms of the number of TSB description entries.
848 *
849 * Upon return, RET1 always contains the number of TSB descriptions
850 * previously configured. If zero TSBs were configured, EOK is
851 * returned with RET1 containing 0.
852 */
853#define HV_FAST_MMU_TSB_CTXNON0_INFO 0x2a
854
855/* mmu_fault_area_info()
856 * TRAP: HV_FAST_TRAP
857 * FUNCTION: HV_FAST_MMU_FAULT_AREA_INFO
858 * RET0: status
859 * RET1: fault area real address
860 * ERRORS: No errors defined.
861 *
862 * Return the currently defined MMU fault status area for the current
863 * CPU. The real address of the fault status area is returned in
864 * RET1, or 0 is returned in RET1 if no fault status area is defined.
865 *
866 * Note: mmu_fault_area_conf() may be called with the return value (RET1)
867 * from this service if there is a need to save and restore the fault
868 * area for a cpu.
869 */
870#define HV_FAST_MMU_FAULT_AREA_INFO 0x2b
871
872/* Cache and Memory services. */
873
874/* mem_scrub()
875 * TRAP: HV_FAST_TRAP
876 * FUNCTION: HV_FAST_MEM_SCRUB
877 * ARG0: real address
878 * ARG1: length
879 * RET0: status
880 * RET1: length scrubbed
881 * ERRORS: ENORADDR Invalid real address
882 * EBADALIGN Start address or length are not correctly
883 * aligned
884 * EINVAL Length is zero
885 *
886 * Zero the memory contents in the range real address to real address
887 * plus length minus 1. Also, valid ECC will be generated for that
888 * memory address range. Scrubbing is started at the given real
889 * address, but may not scrub the entire given length. The actual
890 * length scrubbed will be returned in RET1.
891 *
892 * The real address and length must be aligned on an 8K boundary, or
893 * contain the start address and length from a sun4v error report.
894 *
895 * Note: There are two uses for this function. The first use is to block clear
896 * and initialize memory and the second is to scrub an u ncorrectable
897 * error reported via a resumable or non-resumable trap. The second
898 * use requires the arguments to be equal to the real address and length
899 * provided in a sun4v memory error report.
900 */
901#define HV_FAST_MEM_SCRUB 0x31
902
903/* mem_sync()
904 * TRAP: HV_FAST_TRAP
905 * FUNCTION: HV_FAST_MEM_SYNC
906 * ARG0: real address
907 * ARG1: length
908 * RET0: status
909 * RET1: length synced
910 * ERRORS: ENORADDR Invalid real address
911 * EBADALIGN Start address or length are not correctly
912 * aligned
913 * EINVAL Length is zero
914 *
915 * Force the next access within the real address to real address plus
916 * length minus 1 to be fetches from main system memory. Less than
917 * the given length may be synced, the actual amount synced is
918 * returned in RET1. The real address and length must be aligned on
919 * an 8K boundary.
920 */
921#define HV_FAST_MEM_SYNC 0x32
922
923/* Time of day services.
924 *
925 * The hypervisor maintains the time of day on a per-domain basis.
926 * Changing the time of day in one domain does not affect the time of
927 * day on any other domain.
928 *
929 * Time is described by a single unsigned 64-bit word which is the
930 * number of seconds since the UNIX Epoch (00:00:00 UTC, January 1,
931 * 1970).
932 */
933
934/* tod_get()
935 * TRAP: HV_FAST_TRAP
936 * FUNCTION: HV_FAST_TOD_GET
937 * RET0: status
938 * RET1: TOD
939 * ERRORS: EWOULDBLOCK TOD resource is temporarily unavailable
940 * ENOTSUPPORTED If TOD not supported on this platform
941 *
942 * Return the current time of day. May block if TOD access is
943 * temporarily not possible.
944 */
945#define HV_FAST_TOD_GET 0x50
946
947#ifndef __ASSEMBLY__
948extern unsigned long sun4v_tod_get(unsigned long *time);
949#endif
950
951/* tod_set()
952 * TRAP: HV_FAST_TRAP
953 * FUNCTION: HV_FAST_TOD_SET
954 * ARG0: TOD
955 * RET0: status
956 * ERRORS: EWOULDBLOCK TOD resource is temporarily unavailable
957 * ENOTSUPPORTED If TOD not supported on this platform
958 *
959 * The current time of day is set to the value specified in ARG0. May
960 * block if TOD access is temporarily not possible.
961 */
962#define HV_FAST_TOD_SET 0x51
963
964#ifndef __ASSEMBLY__
965extern unsigned long sun4v_tod_set(unsigned long time);
966#endif
967
968/* Console services */
969
970/* con_getchar()
971 * TRAP: HV_FAST_TRAP
972 * FUNCTION: HV_FAST_CONS_GETCHAR
973 * RET0: status
974 * RET1: character
975 * ERRORS: EWOULDBLOCK No character available.
976 *
977 * Returns a character from the console device. If no character is
978 * available then an EWOULDBLOCK error is returned. If a character is
979 * available, then the returned status is EOK and the character value
980 * is in RET1.
981 *
982 * A virtual BREAK is represented by the 64-bit value -1.
983 *
984 * A virtual HUP signal is represented by the 64-bit value -2.
985 */
986#define HV_FAST_CONS_GETCHAR 0x60
987
988/* con_putchar()
989 * TRAP: HV_FAST_TRAP
990 * FUNCTION: HV_FAST_CONS_PUTCHAR
991 * ARG0: character
992 * RET0: status
993 * ERRORS: EINVAL Illegal character
994 * EWOULDBLOCK Output buffer currently full, would block
995 *
996 * Send a character to the console device. Only character values
997 * between 0 and 255 may be used. Values outside this range are
998 * invalid except for the 64-bit value -1 which is used to send a
999 * virtual BREAK.
1000 */
1001#define HV_FAST_CONS_PUTCHAR 0x61
1002
1003/* con_read()
1004 * TRAP: HV_FAST_TRAP
1005 * FUNCTION: HV_FAST_CONS_READ
1006 * ARG0: buffer real address
1007 * ARG1: buffer size in bytes
1008 * RET0: status
1009 * RET1: bytes read or BREAK or HUP
1010 * ERRORS: EWOULDBLOCK No character available.
1011 *
1012 * Reads characters into a buffer from the console device. If no
1013 * character is available then an EWOULDBLOCK error is returned.
1014 * If a character is available, then the returned status is EOK
1015 * and the number of bytes read into the given buffer is provided
1016 * in RET1.
1017 *
1018 * A virtual BREAK is represented by the 64-bit RET1 value -1.
1019 *
1020 * A virtual HUP signal is represented by the 64-bit RET1 value -2.
1021 *
1022 * If BREAK or HUP are indicated, no bytes were read into buffer.
1023 */
1024#define HV_FAST_CONS_READ 0x62
1025
1026/* con_write()
1027 * TRAP: HV_FAST_TRAP
1028 * FUNCTION: HV_FAST_CONS_WRITE
1029 * ARG0: buffer real address
1030 * ARG1: buffer size in bytes
1031 * RET0: status
1032 * RET1: bytes written
1033 * ERRORS: EWOULDBLOCK Output buffer currently full, would block
1034 *
1035 * Send a characters in buffer to the console device. Breaks must be
1036 * sent using con_putchar().
1037 */
1038#define HV_FAST_CONS_WRITE 0x63
1039
1040#ifndef __ASSEMBLY__
1041extern long sun4v_con_getchar(long *status);
1042extern long sun4v_con_putchar(long c);
1043extern long sun4v_con_read(unsigned long buffer,
1044 unsigned long size,
1045 unsigned long *bytes_read);
1046extern unsigned long sun4v_con_write(unsigned long buffer,
1047 unsigned long size,
1048 unsigned long *bytes_written);
1049#endif
1050
1051/* mach_set_soft_state()
1052 * TRAP: HV_FAST_TRAP
1053 * FUNCTION: HV_FAST_MACH_SET_SOFT_STATE
1054 * ARG0: software state
1055 * ARG1: software state description pointer
1056 * RET0: status
1057 * ERRORS: EINVAL software state not valid or software state
1058 * description is not NULL terminated
1059 * ENORADDR software state description pointer is not a
1060 * valid real address
1061 * EBADALIGNED software state description is not correctly
1062 * aligned
1063 *
1064 * This allows the guest to report it's soft state to the hypervisor. There
1065 * are two primary components to this state. The first part states whether
1066 * the guest software is running or not. The second containts optional
1067 * details specific to the software.
1068 *
1069 * The software state argument is defined below in HV_SOFT_STATE_*, and
1070 * indicates whether the guest is operating normally or in a transitional
1071 * state.
1072 *
1073 * The software state description argument is a real address of a data buffer
1074 * of size 32-bytes aligned on a 32-byte boundary. It is treated as a NULL
1075 * terminated 7-bit ASCII string of up to 31 characters not including the
1076 * NULL termination.
1077 */
1078#define HV_FAST_MACH_SET_SOFT_STATE 0x70
1079#define HV_SOFT_STATE_NORMAL 0x01
1080#define HV_SOFT_STATE_TRANSITION 0x02
1081
1082#ifndef __ASSEMBLY__
1083extern unsigned long sun4v_mach_set_soft_state(unsigned long soft_state,
1084 unsigned long msg_string_ra);
1085#endif
1086
1087/* mach_get_soft_state()
1088 * TRAP: HV_FAST_TRAP
1089 * FUNCTION: HV_FAST_MACH_GET_SOFT_STATE
1090 * ARG0: software state description pointer
1091 * RET0: status
1092 * RET1: software state
1093 * ERRORS: ENORADDR software state description pointer is not a
1094 * valid real address
1095 * EBADALIGNED software state description is not correctly
1096 * aligned
1097 *
1098 * Retrieve the current value of the guest's software state. The rules
1099 * for the software state pointer are the same as for mach_set_soft_state()
1100 * above.
1101 */
1102#define HV_FAST_MACH_GET_SOFT_STATE 0x71
1103
1104/* svc_send()
1105 * TRAP: HV_FAST_TRAP
1106 * FUNCTION: HV_FAST_SVC_SEND
1107 * ARG0: service ID
1108 * ARG1: buffer real address
1109 * ARG2: buffer size
1110 * RET0: STATUS
1111 * RET1: sent_bytes
1112 *
1113 * Be careful, all output registers are clobbered by this operation,
1114 * so for example it is not possible to save away a value in %o4
1115 * across the trap.
1116 */
1117#define HV_FAST_SVC_SEND 0x80
1118
1119/* svc_recv()
1120 * TRAP: HV_FAST_TRAP
1121 * FUNCTION: HV_FAST_SVC_RECV
1122 * ARG0: service ID
1123 * ARG1: buffer real address
1124 * ARG2: buffer size
1125 * RET0: STATUS
1126 * RET1: recv_bytes
1127 *
1128 * Be careful, all output registers are clobbered by this operation,
1129 * so for example it is not possible to save away a value in %o4
1130 * across the trap.
1131 */
1132#define HV_FAST_SVC_RECV 0x81
1133
1134/* svc_getstatus()
1135 * TRAP: HV_FAST_TRAP
1136 * FUNCTION: HV_FAST_SVC_GETSTATUS
1137 * ARG0: service ID
1138 * RET0: STATUS
1139 * RET1: status bits
1140 */
1141#define HV_FAST_SVC_GETSTATUS 0x82
1142
1143/* svc_setstatus()
1144 * TRAP: HV_FAST_TRAP
1145 * FUNCTION: HV_FAST_SVC_SETSTATUS
1146 * ARG0: service ID
1147 * ARG1: bits to set
1148 * RET0: STATUS
1149 */
1150#define HV_FAST_SVC_SETSTATUS 0x83
1151
1152/* svc_clrstatus()
1153 * TRAP: HV_FAST_TRAP
1154 * FUNCTION: HV_FAST_SVC_CLRSTATUS
1155 * ARG0: service ID
1156 * ARG1: bits to clear
1157 * RET0: STATUS
1158 */
1159#define HV_FAST_SVC_CLRSTATUS 0x84
1160
1161#ifndef __ASSEMBLY__
1162extern unsigned long sun4v_svc_send(unsigned long svc_id,
1163 unsigned long buffer,
1164 unsigned long buffer_size,
1165 unsigned long *sent_bytes);
1166extern unsigned long sun4v_svc_recv(unsigned long svc_id,
1167 unsigned long buffer,
1168 unsigned long buffer_size,
1169 unsigned long *recv_bytes);
1170extern unsigned long sun4v_svc_getstatus(unsigned long svc_id,
1171 unsigned long *status_bits);
1172extern unsigned long sun4v_svc_setstatus(unsigned long svc_id,
1173 unsigned long status_bits);
1174extern unsigned long sun4v_svc_clrstatus(unsigned long svc_id,
1175 unsigned long status_bits);
1176#endif
1177
1178/* Trap trace services.
1179 *
1180 * The hypervisor provides a trap tracing capability for privileged
1181 * code running on each virtual CPU. Privileged code provides a
1182 * round-robin trap trace queue within which the hypervisor writes
1183 * 64-byte entries detailing hyperprivileged traps taken n behalf of
1184 * privileged code. This is provided as a debugging capability for
1185 * privileged code.
1186 *
1187 * The trap trace control structure is 64-bytes long and placed at the
1188 * start (offset 0) of the trap trace buffer, and is described as
1189 * follows:
1190 */
1191#ifndef __ASSEMBLY__
1192struct hv_trap_trace_control {
1193 unsigned long head_offset;
1194 unsigned long tail_offset;
1195 unsigned long __reserved[0x30 / sizeof(unsigned long)];
1196};
1197#endif
1198#define HV_TRAP_TRACE_CTRL_HEAD_OFFSET 0x00
1199#define HV_TRAP_TRACE_CTRL_TAIL_OFFSET 0x08
1200
1201/* The head offset is the offset of the most recently completed entry
1202 * in the trap-trace buffer. The tail offset is the offset of the
1203 * next entry to be written. The control structure is owned and
1204 * modified by the hypervisor. A guest may not modify the control
1205 * structure contents. Attempts to do so will result in undefined
1206 * behavior for the guest.
1207 *
1208 * Each trap trace buffer entry is layed out as follows:
1209 */
1210#ifndef __ASSEMBLY__
1211struct hv_trap_trace_entry {
1212 unsigned char type; /* Hypervisor or guest entry? */
1213 unsigned char hpstate; /* Hyper-privileged state */
1214 unsigned char tl; /* Trap level */
1215 unsigned char gl; /* Global register level */
1216 unsigned short tt; /* Trap type */
1217 unsigned short tag; /* Extended trap identifier */
1218 unsigned long tstate; /* Trap state */
1219 unsigned long tick; /* Tick */
1220 unsigned long tpc; /* Trap PC */
1221 unsigned long f1; /* Entry specific */
1222 unsigned long f2; /* Entry specific */
1223 unsigned long f3; /* Entry specific */
1224 unsigned long f4; /* Entry specific */
1225};
1226#endif
1227#define HV_TRAP_TRACE_ENTRY_TYPE 0x00
1228#define HV_TRAP_TRACE_ENTRY_HPSTATE 0x01
1229#define HV_TRAP_TRACE_ENTRY_TL 0x02
1230#define HV_TRAP_TRACE_ENTRY_GL 0x03
1231#define HV_TRAP_TRACE_ENTRY_TT 0x04
1232#define HV_TRAP_TRACE_ENTRY_TAG 0x06
1233#define HV_TRAP_TRACE_ENTRY_TSTATE 0x08
1234#define HV_TRAP_TRACE_ENTRY_TICK 0x10
1235#define HV_TRAP_TRACE_ENTRY_TPC 0x18
1236#define HV_TRAP_TRACE_ENTRY_F1 0x20
1237#define HV_TRAP_TRACE_ENTRY_F2 0x28
1238#define HV_TRAP_TRACE_ENTRY_F3 0x30
1239#define HV_TRAP_TRACE_ENTRY_F4 0x38
1240
1241/* The type field is encoded as follows. */
1242#define HV_TRAP_TYPE_UNDEF 0x00 /* Entry content undefined */
1243#define HV_TRAP_TYPE_HV 0x01 /* Hypervisor trap entry */
1244#define HV_TRAP_TYPE_GUEST 0xff /* Added via ttrace_addentry() */
1245
1246/* ttrace_buf_conf()
1247 * TRAP: HV_FAST_TRAP
1248 * FUNCTION: HV_FAST_TTRACE_BUF_CONF
1249 * ARG0: real address
1250 * ARG1: number of entries
1251 * RET0: status
1252 * RET1: number of entries
1253 * ERRORS: ENORADDR Invalid real address
1254 * EINVAL Size is too small
1255 * EBADALIGN Real address not aligned on 64-byte boundary
1256 *
1257 * Requests hypervisor trap tracing and declares a virtual CPU's trap
1258 * trace buffer to the hypervisor. The real address supplies the real
1259 * base address of the trap trace queue and must be 64-byte aligned.
1260 * Specifying a value of 0 for the number of entries disables trap
1261 * tracing for the calling virtual CPU. The buffer allocated must be
1262 * sized for a power of two number of 64-byte trap trace entries plus
1263 * an initial 64-byte control structure.
1264 *
1265 * This may be invoked any number of times so that a virtual CPU may
1266 * relocate a trap trace buffer or create "snapshots" of information.
1267 *
1268 * If the real address is illegal or badly aligned, then trap tracing
1269 * is disabled and an error is returned.
1270 *
1271 * Upon failure with EINVAL, this service call returns in RET1 the
1272 * minimum number of buffer entries required. Upon other failures
1273 * RET1 is undefined.
1274 */
1275#define HV_FAST_TTRACE_BUF_CONF 0x90
1276
1277/* ttrace_buf_info()
1278 * TRAP: HV_FAST_TRAP
1279 * FUNCTION: HV_FAST_TTRACE_BUF_INFO
1280 * RET0: status
1281 * RET1: real address
1282 * RET2: size
1283 * ERRORS: None defined.
1284 *
1285 * Returns the size and location of the previously declared trap-trace
1286 * buffer. In the event that no buffer was previously defined, or the
1287 * buffer is disabled, this call will return a size of zero bytes.
1288 */
1289#define HV_FAST_TTRACE_BUF_INFO 0x91
1290
1291/* ttrace_enable()
1292 * TRAP: HV_FAST_TRAP
1293 * FUNCTION: HV_FAST_TTRACE_ENABLE
1294 * ARG0: enable
1295 * RET0: status
1296 * RET1: previous enable state
1297 * ERRORS: EINVAL No trap trace buffer currently defined
1298 *
1299 * Enable or disable trap tracing, and return the previous enabled
1300 * state in RET1. Future systems may define various flags for the
1301 * enable argument (ARG0), for the moment a guest should pass
1302 * "(uint64_t) -1" to enable, and "(uint64_t) 0" to disable all
1303 * tracing - which will ensure future compatability.
1304 */
1305#define HV_FAST_TTRACE_ENABLE 0x92
1306
1307/* ttrace_freeze()
1308 * TRAP: HV_FAST_TRAP
1309 * FUNCTION: HV_FAST_TTRACE_FREEZE
1310 * ARG0: freeze
1311 * RET0: status
1312 * RET1: previous freeze state
1313 * ERRORS: EINVAL No trap trace buffer currently defined
1314 *
1315 * Freeze or unfreeze trap tracing, returning the previous freeze
1316 * state in RET1. A guest should pass a non-zero value to freeze and
1317 * a zero value to unfreeze all tracing. The returned previous state
1318 * is 0 for not frozen and 1 for frozen.
1319 */
1320#define HV_FAST_TTRACE_FREEZE 0x93
1321
1322/* ttrace_addentry()
1323 * TRAP: HV_TTRACE_ADDENTRY_TRAP
1324 * ARG0: tag (16-bits)
1325 * ARG1: data word 0
1326 * ARG2: data word 1
1327 * ARG3: data word 2
1328 * ARG4: data word 3
1329 * RET0: status
1330 * ERRORS: EINVAL No trap trace buffer currently defined
1331 *
1332 * Add an entry to the trap trace buffer. Upon return only ARG0/RET0
1333 * is modified - none of the other registers holding arguments are
1334 * volatile across this hypervisor service.
1335 */
1336
1337/* Core dump services.
1338 *
1339 * Since the hypervisor viraulizes and thus obscures a lot of the
1340 * physical machine layout and state, traditional OS crash dumps can
1341 * be difficult to diagnose especially when the problem is a
1342 * configuration error of some sort.
1343 *
1344 * The dump services provide an opaque buffer into which the
1345 * hypervisor can place it's internal state in order to assist in
1346 * debugging such situations. The contents are opaque and extremely
1347 * platform and hypervisor implementation specific. The guest, during
1348 * a core dump, requests that the hypervisor update any information in
1349 * the dump buffer in preparation to being dumped as part of the
1350 * domain's memory image.
1351 */
1352
1353/* dump_buf_update()
1354 * TRAP: HV_FAST_TRAP
1355 * FUNCTION: HV_FAST_DUMP_BUF_UPDATE
1356 * ARG0: real address
1357 * ARG1: size
1358 * RET0: status
1359 * RET1: required size of dump buffer
1360 * ERRORS: ENORADDR Invalid real address
1361 * EBADALIGN Real address is not aligned on a 64-byte
1362 * boundary
1363 * EINVAL Size is non-zero but less than minimum size
1364 * required
1365 * ENOTSUPPORTED Operation not supported on current logical
1366 * domain
1367 *
1368 * Declare a domain dump buffer to the hypervisor. The real address
1369 * provided for the domain dump buffer must be 64-byte aligned. The
1370 * size specifies the size of the dump buffer and may be larger than
1371 * the minimum size specified in the machine description. The
1372 * hypervisor will fill the dump buffer with opaque data.
1373 *
1374 * Note: A guest may elect to include dump buffer contents as part of a crash
1375 * dump to assist with debugging. This function may be called any number
1376 * of times so that a guest may relocate a dump buffer, or create
1377 * "snapshots" of any dump-buffer information. Each call to
1378 * dump_buf_update() atomically declares the new dump buffer to the
1379 * hypervisor.
1380 *
1381 * A specified size of 0 unconfigures the dump buffer. If the real
1382 * address is illegal or badly aligned, then any currently active dump
1383 * buffer is disabled and an error is returned.
1384 *
1385 * In the event that the call fails with EINVAL, RET1 contains the
1386 * minimum size requires by the hypervisor for a valid dump buffer.
1387 */
1388#define HV_FAST_DUMP_BUF_UPDATE 0x94
1389
1390/* dump_buf_info()
1391 * TRAP: HV_FAST_TRAP
1392 * FUNCTION: HV_FAST_DUMP_BUF_INFO
1393 * RET0: status
1394 * RET1: real address of current dump buffer
1395 * RET2: size of current dump buffer
1396 * ERRORS: No errors defined.
1397 *
1398 * Return the currently configures dump buffer description. A
1399 * returned size of 0 bytes indicates an undefined dump buffer. In
1400 * this case the return address in RET1 is undefined.
1401 */
1402#define HV_FAST_DUMP_BUF_INFO 0x95
1403
1404/* Device interrupt services.
1405 *
1406 * Device interrupts are allocated to system bus bridges by the hypervisor,
1407 * and described to OBP in the machine description. OBP then describes
1408 * these interrupts to the OS via properties in the device tree.
1409 *
1410 * Terminology:
1411 *
1412 * cpuid Unique opaque value which represents a target cpu.
1413 *
1414 * devhandle Device handle. It uniquely identifies a device, and
1415 * consistes of the lower 28-bits of the hi-cell of the
1416 * first entry of the device's "reg" property in the
1417 * OBP device tree.
1418 *
1419 * devino Device interrupt number. Specifies the relative
1420 * interrupt number within the device. The unique
1421 * combination of devhandle and devino are used to
1422 * identify a specific device interrupt.
1423 *
1424 * Note: The devino value is the same as the values in the
1425 * "interrupts" property or "interrupt-map" property
1426 * in the OBP device tree for that device.
1427 *
1428 * sysino System interrupt number. A 64-bit unsigned interger
1429 * representing a unique interrupt within a virtual
1430 * machine.
1431 *
1432 * intr_state A flag representing the interrupt state for a given
1433 * sysino. The state values are defined below.
1434 *
1435 * intr_enabled A flag representing the 'enabled' state for a given
1436 * sysino. The enable values are defined below.
1437 */
1438
1439#define HV_INTR_STATE_IDLE 0 /* Nothing pending */
1440#define HV_INTR_STATE_RECEIVED 1 /* Interrupt received by hardware */
1441#define HV_INTR_STATE_DELIVERED 2 /* Interrupt delivered to queue */
1442
1443#define HV_INTR_DISABLED 0 /* sysino not enabled */
1444#define HV_INTR_ENABLED 1 /* sysino enabled */
1445
1446/* intr_devino_to_sysino()
1447 * TRAP: HV_FAST_TRAP
1448 * FUNCTION: HV_FAST_INTR_DEVINO2SYSINO
1449 * ARG0: devhandle
1450 * ARG1: devino
1451 * RET0: status
1452 * RET1: sysino
1453 * ERRORS: EINVAL Invalid devhandle/devino
1454 *
1455 * Converts a device specific interrupt number of the given
1456 * devhandle/devino into a system specific ino (sysino).
1457 */
1458#define HV_FAST_INTR_DEVINO2SYSINO 0xa0
1459
1460#ifndef __ASSEMBLY__
1461extern unsigned long sun4v_devino_to_sysino(unsigned long devhandle,
1462 unsigned long devino);
1463#endif
1464
1465/* intr_getenabled()
1466 * TRAP: HV_FAST_TRAP
1467 * FUNCTION: HV_FAST_INTR_GETENABLED
1468 * ARG0: sysino
1469 * RET0: status
1470 * RET1: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1471 * ERRORS: EINVAL Invalid sysino
1472 *
1473 * Returns interrupt enabled state in RET1 for the interrupt defined
1474 * by the given sysino.
1475 */
1476#define HV_FAST_INTR_GETENABLED 0xa1
1477
1478#ifndef __ASSEMBLY__
1479extern unsigned long sun4v_intr_getenabled(unsigned long sysino);
1480#endif
1481
1482/* intr_setenabled()
1483 * TRAP: HV_FAST_TRAP
1484 * FUNCTION: HV_FAST_INTR_SETENABLED
1485 * ARG0: sysino
1486 * ARG1: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1487 * RET0: status
1488 * ERRORS: EINVAL Invalid sysino or intr_enabled value
1489 *
1490 * Set the 'enabled' state of the interrupt sysino.
1491 */
1492#define HV_FAST_INTR_SETENABLED 0xa2
1493
1494#ifndef __ASSEMBLY__
1495extern unsigned long sun4v_intr_setenabled(unsigned long sysino, unsigned long intr_enabled);
1496#endif
1497
1498/* intr_getstate()
1499 * TRAP: HV_FAST_TRAP
1500 * FUNCTION: HV_FAST_INTR_GETSTATE
1501 * ARG0: sysino
1502 * RET0: status
1503 * RET1: intr_state (HV_INTR_STATE_*)
1504 * ERRORS: EINVAL Invalid sysino
1505 *
1506 * Returns current state of the interrupt defined by the given sysino.
1507 */
1508#define HV_FAST_INTR_GETSTATE 0xa3
1509
1510#ifndef __ASSEMBLY__
1511extern unsigned long sun4v_intr_getstate(unsigned long sysino);
1512#endif
1513
1514/* intr_setstate()
1515 * TRAP: HV_FAST_TRAP
1516 * FUNCTION: HV_FAST_INTR_SETSTATE
1517 * ARG0: sysino
1518 * ARG1: intr_state (HV_INTR_STATE_*)
1519 * RET0: status
1520 * ERRORS: EINVAL Invalid sysino or intr_state value
1521 *
1522 * Sets the current state of the interrupt described by the given sysino
1523 * value.
1524 *
1525 * Note: Setting the state to HV_INTR_STATE_IDLE clears any pending
1526 * interrupt for sysino.
1527 */
1528#define HV_FAST_INTR_SETSTATE 0xa4
1529
1530#ifndef __ASSEMBLY__
1531extern unsigned long sun4v_intr_setstate(unsigned long sysino, unsigned long intr_state);
1532#endif
1533
1534/* intr_gettarget()
1535 * TRAP: HV_FAST_TRAP
1536 * FUNCTION: HV_FAST_INTR_GETTARGET
1537 * ARG0: sysino
1538 * RET0: status
1539 * RET1: cpuid
1540 * ERRORS: EINVAL Invalid sysino
1541 *
1542 * Returns CPU that is the current target of the interrupt defined by
1543 * the given sysino. The CPU value returned is undefined if the target
1544 * has not been set via intr_settarget().
1545 */
1546#define HV_FAST_INTR_GETTARGET 0xa5
1547
1548#ifndef __ASSEMBLY__
1549extern unsigned long sun4v_intr_gettarget(unsigned long sysino);
1550#endif
1551
1552/* intr_settarget()
1553 * TRAP: HV_FAST_TRAP
1554 * FUNCTION: HV_FAST_INTR_SETTARGET
1555 * ARG0: sysino
1556 * ARG1: cpuid
1557 * RET0: status
1558 * ERRORS: EINVAL Invalid sysino
1559 * ENOCPU Invalid cpuid
1560 *
1561 * Set the target CPU for the interrupt defined by the given sysino.
1562 */
1563#define HV_FAST_INTR_SETTARGET 0xa6
1564
1565#ifndef __ASSEMBLY__
1566extern unsigned long sun4v_intr_settarget(unsigned long sysino, unsigned long cpuid);
1567#endif
1568
1569/* vintr_get_cookie()
1570 * TRAP: HV_FAST_TRAP
1571 * FUNCTION: HV_FAST_VINTR_GET_COOKIE
1572 * ARG0: device handle
1573 * ARG1: device ino
1574 * RET0: status
1575 * RET1: cookie
1576 */
1577#define HV_FAST_VINTR_GET_COOKIE 0xa7
1578
1579/* vintr_set_cookie()
1580 * TRAP: HV_FAST_TRAP
1581 * FUNCTION: HV_FAST_VINTR_SET_COOKIE
1582 * ARG0: device handle
1583 * ARG1: device ino
1584 * ARG2: cookie
1585 * RET0: status
1586 */
1587#define HV_FAST_VINTR_SET_COOKIE 0xa8
1588
1589/* vintr_get_valid()
1590 * TRAP: HV_FAST_TRAP
1591 * FUNCTION: HV_FAST_VINTR_GET_VALID
1592 * ARG0: device handle
1593 * ARG1: device ino
1594 * RET0: status
1595 * RET1: valid state
1596 */
1597#define HV_FAST_VINTR_GET_VALID 0xa9
1598
1599/* vintr_set_valid()
1600 * TRAP: HV_FAST_TRAP
1601 * FUNCTION: HV_FAST_VINTR_SET_VALID
1602 * ARG0: device handle
1603 * ARG1: device ino
1604 * ARG2: valid state
1605 * RET0: status
1606 */
1607#define HV_FAST_VINTR_SET_VALID 0xaa
1608
1609/* vintr_get_state()
1610 * TRAP: HV_FAST_TRAP
1611 * FUNCTION: HV_FAST_VINTR_GET_STATE
1612 * ARG0: device handle
1613 * ARG1: device ino
1614 * RET0: status
1615 * RET1: state
1616 */
1617#define HV_FAST_VINTR_GET_STATE 0xab
1618
1619/* vintr_set_state()
1620 * TRAP: HV_FAST_TRAP
1621 * FUNCTION: HV_FAST_VINTR_SET_STATE
1622 * ARG0: device handle
1623 * ARG1: device ino
1624 * ARG2: state
1625 * RET0: status
1626 */
1627#define HV_FAST_VINTR_SET_STATE 0xac
1628
1629/* vintr_get_target()
1630 * TRAP: HV_FAST_TRAP
1631 * FUNCTION: HV_FAST_VINTR_GET_TARGET
1632 * ARG0: device handle
1633 * ARG1: device ino
1634 * RET0: status
1635 * RET1: cpuid
1636 */
1637#define HV_FAST_VINTR_GET_TARGET 0xad
1638
1639/* vintr_set_target()
1640 * TRAP: HV_FAST_TRAP
1641 * FUNCTION: HV_FAST_VINTR_SET_TARGET
1642 * ARG0: device handle
1643 * ARG1: device ino
1644 * ARG2: cpuid
1645 * RET0: status
1646 */
1647#define HV_FAST_VINTR_SET_TARGET 0xae
1648
1649#ifndef __ASSEMBLY__
1650extern unsigned long sun4v_vintr_get_cookie(unsigned long dev_handle,
1651 unsigned long dev_ino,
1652 unsigned long *cookie);
1653extern unsigned long sun4v_vintr_set_cookie(unsigned long dev_handle,
1654 unsigned long dev_ino,
1655 unsigned long cookie);
1656extern unsigned long sun4v_vintr_get_valid(unsigned long dev_handle,
1657 unsigned long dev_ino,
1658 unsigned long *valid);
1659extern unsigned long sun4v_vintr_set_valid(unsigned long dev_handle,
1660 unsigned long dev_ino,
1661 unsigned long valid);
1662extern unsigned long sun4v_vintr_get_state(unsigned long dev_handle,
1663 unsigned long dev_ino,
1664 unsigned long *state);
1665extern unsigned long sun4v_vintr_set_state(unsigned long dev_handle,
1666 unsigned long dev_ino,
1667 unsigned long state);
1668extern unsigned long sun4v_vintr_get_target(unsigned long dev_handle,
1669 unsigned long dev_ino,
1670 unsigned long *cpuid);
1671extern unsigned long sun4v_vintr_set_target(unsigned long dev_handle,
1672 unsigned long dev_ino,
1673 unsigned long cpuid);
1674#endif
1675
1676/* PCI IO services.
1677 *
1678 * See the terminology descriptions in the device interrupt services
1679 * section above as those apply here too. Here are terminology
1680 * definitions specific to these PCI IO services:
1681 *
1682 * tsbnum TSB number. Indentifies which io-tsb is used.
1683 * For this version of the specification, tsbnum
1684 * must be zero.
1685 *
1686 * tsbindex TSB index. Identifies which entry in the TSB
1687 * is used. The first entry is zero.
1688 *
1689 * tsbid A 64-bit aligned data structure which contains
1690 * a tsbnum and a tsbindex. Bits 63:32 contain the
1691 * tsbnum and bits 31:00 contain the tsbindex.
1692 *
1693 * Use the HV_PCI_TSBID() macro to construct such
1694 * values.
1695 *
1696 * io_attributes IO attributes for IOMMU mappings. One of more
1697 * of the attritbute bits are stores in a 64-bit
1698 * value. The values are defined below.
1699 *
1700 * r_addr 64-bit real address
1701 *
1702 * pci_device PCI device address. A PCI device address identifies
1703 * a specific device on a specific PCI bus segment.
1704 * A PCI device address ia a 32-bit unsigned integer
1705 * with the following format:
1706 *
1707 * 00000000.bbbbbbbb.dddddfff.00000000
1708 *
1709 * Use the HV_PCI_DEVICE_BUILD() macro to construct
1710 * such values.
1711 *
1712 * pci_config_offset
1713 * PCI configureation space offset. For conventional
1714 * PCI a value between 0 and 255. For extended
1715 * configuration space, a value between 0 and 4095.
1716 *
1717 * Note: For PCI configuration space accesses, the offset
1718 * must be aligned to the access size.
1719 *
1720 * error_flag A return value which specifies if the action succeeded
1721 * or failed. 0 means no error, non-0 means some error
1722 * occurred while performing the service.
1723 *
1724 * io_sync_direction
1725 * Direction definition for pci_dma_sync(), defined
1726 * below in HV_PCI_SYNC_*.
1727 *
1728 * io_page_list A list of io_page_addresses, an io_page_address is
1729 * a real address.
1730 *
1731 * io_page_list_p A pointer to an io_page_list.
1732 *
1733 * "size based byte swap" - Some functions do size based byte swapping
1734 * which allows sw to access pointers and
1735 * counters in native form when the processor
1736 * operates in a different endianness than the
1737 * IO bus. Size-based byte swapping converts a
1738 * multi-byte field between big-endian and
1739 * little-endian format.
1740 */
1741
1742#define HV_PCI_MAP_ATTR_READ 0x01
1743#define HV_PCI_MAP_ATTR_WRITE 0x02
1744
1745#define HV_PCI_DEVICE_BUILD(b,d,f) \
1746 ((((b) & 0xff) << 16) | \
1747 (((d) & 0x1f) << 11) | \
1748 (((f) & 0x07) << 8))
1749
1750#define HV_PCI_TSBID(__tsb_num, __tsb_index) \
1751 ((((u64)(__tsb_num)) << 32UL) | ((u64)(__tsb_index)))
1752
1753#define HV_PCI_SYNC_FOR_DEVICE 0x01
1754#define HV_PCI_SYNC_FOR_CPU 0x02
1755
1756/* pci_iommu_map()
1757 * TRAP: HV_FAST_TRAP
1758 * FUNCTION: HV_FAST_PCI_IOMMU_MAP
1759 * ARG0: devhandle
1760 * ARG1: tsbid
1761 * ARG2: #ttes
1762 * ARG3: io_attributes
1763 * ARG4: io_page_list_p
1764 * RET0: status
1765 * RET1: #ttes mapped
1766 * ERRORS: EINVAL Invalid devhandle/tsbnum/tsbindex/io_attributes
1767 * EBADALIGN Improperly aligned real address
1768 * ENORADDR Invalid real address
1769 *
1770 * Create IOMMU mappings in the sun4v device defined by the given
1771 * devhandle. The mappings are created in the TSB defined by the
1772 * tsbnum component of the given tsbid. The first mapping is created
1773 * in the TSB i ndex defined by the tsbindex component of the given tsbid.
1774 * The call creates up to #ttes mappings, the first one at tsbnum, tsbindex,
1775 * the second at tsbnum, tsbindex + 1, etc.
1776 *
1777 * All mappings are created with the attributes defined by the io_attributes
1778 * argument. The page mapping addresses are described in the io_page_list
1779 * defined by the given io_page_list_p, which is a pointer to the io_page_list.
1780 * The first entry in the io_page_list is the address for the first iotte, the
1781 * 2nd for the 2nd iotte, and so on.
1782 *
1783 * Each io_page_address in the io_page_list must be appropriately aligned.
1784 * #ttes must be greater than zero. For this version of the spec, the tsbnum
1785 * component of the given tsbid must be zero.
1786 *
1787 * Returns the actual number of mappings creates, which may be less than
1788 * or equal to the argument #ttes. If the function returns a value which
1789 * is less than the #ttes, the caller may continus to call the function with
1790 * an updated tsbid, #ttes, io_page_list_p arguments until all pages are
1791 * mapped.
1792 *
1793 * Note: This function does not imply an iotte cache flush. The guest must
1794 * demap an entry before re-mapping it.
1795 */
1796#define HV_FAST_PCI_IOMMU_MAP 0xb0
1797
1798/* pci_iommu_demap()
1799 * TRAP: HV_FAST_TRAP
1800 * FUNCTION: HV_FAST_PCI_IOMMU_DEMAP
1801 * ARG0: devhandle
1802 * ARG1: tsbid
1803 * ARG2: #ttes
1804 * RET0: status
1805 * RET1: #ttes demapped
1806 * ERRORS: EINVAL Invalid devhandle/tsbnum/tsbindex
1807 *
1808 * Demap and flush IOMMU mappings in the device defined by the given
1809 * devhandle. Demaps up to #ttes entries in the TSB defined by the tsbnum
1810 * component of the given tsbid, starting at the TSB index defined by the
1811 * tsbindex component of the given tsbid.
1812 *
1813 * For this version of the spec, the tsbnum of the given tsbid must be zero.
1814 * #ttes must be greater than zero.
1815 *
1816 * Returns the actual number of ttes demapped, which may be less than or equal
1817 * to the argument #ttes. If #ttes demapped is less than #ttes, the caller
1818 * may continue to call this function with updated tsbid and #ttes arguments
1819 * until all pages are demapped.
1820 *
1821 * Note: Entries do not have to be mapped to be demapped. A demap of an
1822 * unmapped page will flush the entry from the tte cache.
1823 */
1824#define HV_FAST_PCI_IOMMU_DEMAP 0xb1
1825
1826/* pci_iommu_getmap()
1827 * TRAP: HV_FAST_TRAP
1828 * FUNCTION: HV_FAST_PCI_IOMMU_GETMAP
1829 * ARG0: devhandle
1830 * ARG1: tsbid
1831 * RET0: status
1832 * RET1: io_attributes
1833 * RET2: real address
1834 * ERRORS: EINVAL Invalid devhandle/tsbnum/tsbindex
1835 * ENOMAP Mapping is not valid, no translation exists
1836 *
1837 * Read and return the mapping in the device described by the given devhandle
1838 * and tsbid. If successful, the io_attributes shall be returned in RET1
1839 * and the page address of the mapping shall be returned in RET2.
1840 *
1841 * For this version of the spec, the tsbnum component of the given tsbid
1842 * must be zero.
1843 */
1844#define HV_FAST_PCI_IOMMU_GETMAP 0xb2
1845
1846/* pci_iommu_getbypass()
1847 * TRAP: HV_FAST_TRAP
1848 * FUNCTION: HV_FAST_PCI_IOMMU_GETBYPASS
1849 * ARG0: devhandle
1850 * ARG1: real address
1851 * ARG2: io_attributes
1852 * RET0: status
1853 * RET1: io_addr
1854 * ERRORS: EINVAL Invalid devhandle/io_attributes
1855 * ENORADDR Invalid real address
1856 * ENOTSUPPORTED Function not supported in this implementation.
1857 *
1858 * Create a "special" mapping in the device described by the given devhandle,
1859 * for the given real address and attributes. Return the IO address in RET1
1860 * if successful.
1861 */
1862#define HV_FAST_PCI_IOMMU_GETBYPASS 0xb3
1863
1864/* pci_config_get()
1865 * TRAP: HV_FAST_TRAP
1866 * FUNCTION: HV_FAST_PCI_CONFIG_GET
1867 * ARG0: devhandle
1868 * ARG1: pci_device
1869 * ARG2: pci_config_offset
1870 * ARG3: size
1871 * RET0: status
1872 * RET1: error_flag
1873 * RET2: data
1874 * ERRORS: EINVAL Invalid devhandle/pci_device/offset/size
1875 * EBADALIGN pci_config_offset not size aligned
1876 * ENOACCESS Access to this offset is not permitted
1877 *
1878 * Read PCI configuration space for the adapter described by the given
1879 * devhandle. Read size (1, 2, or 4) bytes of data from the given
1880 * pci_device, at pci_config_offset from the beginning of the device's
1881 * configuration space. If there was no error, RET1 is set to zero and
1882 * RET2 is set to the data read. Insignificant bits in RET2 are not
1883 * guarenteed to have any specific value and therefore must be ignored.
1884 *
1885 * The data returned in RET2 is size based byte swapped.
1886 *
1887 * If an error occurs during the read, set RET1 to a non-zero value. The
1888 * given pci_config_offset must be 'size' aligned.
1889 */
1890#define HV_FAST_PCI_CONFIG_GET 0xb4
1891
1892/* pci_config_put()
1893 * TRAP: HV_FAST_TRAP
1894 * FUNCTION: HV_FAST_PCI_CONFIG_PUT
1895 * ARG0: devhandle
1896 * ARG1: pci_device
1897 * ARG2: pci_config_offset
1898 * ARG3: size
1899 * ARG4: data
1900 * RET0: status
1901 * RET1: error_flag
1902 * ERRORS: EINVAL Invalid devhandle/pci_device/offset/size
1903 * EBADALIGN pci_config_offset not size aligned
1904 * ENOACCESS Access to this offset is not permitted
1905 *
1906 * Write PCI configuration space for the adapter described by the given
1907 * devhandle. Write size (1, 2, or 4) bytes of data in a single operation,
1908 * at pci_config_offset from the beginning of the device's configuration
1909 * space. The data argument contains the data to be written to configuration
1910 * space. Prior to writing, the data is size based byte swapped.
1911 *
1912 * If an error occurs during the write access, do not generate an error
1913 * report, do set RET1 to a non-zero value. Otherwise RET1 is zero.
1914 * The given pci_config_offset must be 'size' aligned.
1915 *
1916 * This function is permitted to read from offset zero in the configuration
1917 * space described by the given pci_device if necessary to ensure that the
1918 * write access to config space completes.
1919 */
1920#define HV_FAST_PCI_CONFIG_PUT 0xb5
1921
1922/* pci_peek()
1923 * TRAP: HV_FAST_TRAP
1924 * FUNCTION: HV_FAST_PCI_PEEK
1925 * ARG0: devhandle
1926 * ARG1: real address
1927 * ARG2: size
1928 * RET0: status
1929 * RET1: error_flag
1930 * RET2: data
1931 * ERRORS: EINVAL Invalid devhandle or size
1932 * EBADALIGN Improperly aligned real address
1933 * ENORADDR Bad real address
1934 * ENOACCESS Guest access prohibited
1935 *
1936 * Attempt to read the IO address given by the given devhandle, real address,
1937 * and size. Size must be 1, 2, 4, or 8. The read is performed as a single
1938 * access operation using the given size. If an error occurs when reading
1939 * from the given location, do not generate an error report, but return a
1940 * non-zero value in RET1. If the read was successful, return zero in RET1
1941 * and return the actual data read in RET2. The data returned is size based
1942 * byte swapped.
1943 *
1944 * Non-significant bits in RET2 are not guarenteed to have any specific value
1945 * and therefore must be ignored. If RET1 is returned as non-zero, the data
1946 * value is not guarenteed to have any specific value and should be ignored.
1947 *
1948 * The caller must have permission to read from the given devhandle, real
1949 * address, which must be an IO address. The argument real address must be a
1950 * size aligned address.
1951 *
1952 * The hypervisor implementation of this function must block access to any
1953 * IO address that the guest does not have explicit permission to access.
1954 */
1955#define HV_FAST_PCI_PEEK 0xb6
1956
1957/* pci_poke()
1958 * TRAP: HV_FAST_TRAP
1959 * FUNCTION: HV_FAST_PCI_POKE
1960 * ARG0: devhandle
1961 * ARG1: real address
1962 * ARG2: size
1963 * ARG3: data
1964 * ARG4: pci_device
1965 * RET0: status
1966 * RET1: error_flag
1967 * ERRORS: EINVAL Invalid devhandle, size, or pci_device
1968 * EBADALIGN Improperly aligned real address
1969 * ENORADDR Bad real address
1970 * ENOACCESS Guest access prohibited
1971 * ENOTSUPPORTED Function is not supported by implementation
1972 *
1973 * Attempt to write data to the IO address given by the given devhandle,
1974 * real address, and size. Size must be 1, 2, 4, or 8. The write is
1975 * performed as a single access operation using the given size. Prior to
1976 * writing the data is size based swapped.
1977 *
1978 * If an error occurs when writing to the given location, do not generate an
1979 * error report, but return a non-zero value in RET1. If the write was
1980 * successful, return zero in RET1.
1981 *
1982 * pci_device describes the configuration address of the device being
1983 * written to. The implementation may safely read from offset 0 with
1984 * the configuration space of the device described by devhandle and
1985 * pci_device in order to guarantee that the write portion of the operation
1986 * completes
1987 *
1988 * Any error that occurs due to the read shall be reported using the normal
1989 * error reporting mechanisms .. the read error is not suppressed.
1990 *
1991 * The caller must have permission to write to the given devhandle, real
1992 * address, which must be an IO address. The argument real address must be a
1993 * size aligned address. The caller must have permission to read from
1994 * the given devhandle, pci_device cofiguration space offset 0.
1995 *
1996 * The hypervisor implementation of this function must block access to any
1997 * IO address that the guest does not have explicit permission to access.
1998 */
1999#define HV_FAST_PCI_POKE 0xb7
2000
2001/* pci_dma_sync()
2002 * TRAP: HV_FAST_TRAP
2003 * FUNCTION: HV_FAST_PCI_DMA_SYNC
2004 * ARG0: devhandle
2005 * ARG1: real address
2006 * ARG2: size
2007 * ARG3: io_sync_direction
2008 * RET0: status
2009 * RET1: #synced
2010 * ERRORS: EINVAL Invalid devhandle or io_sync_direction
2011 * ENORADDR Bad real address
2012 *
2013 * Synchronize a memory region described by the given real address and size,
2014 * for the device defined by the given devhandle using the direction(s)
2015 * defined by the given io_sync_direction. The argument size is the size of
2016 * the memory region in bytes.
2017 *
2018 * Return the actual number of bytes synchronized in the return value #synced,
2019 * which may be less than or equal to the argument size. If the return
2020 * value #synced is less than size, the caller must continue to call this
2021 * function with updated real address and size arguments until the entire
2022 * memory region is synchronized.
2023 */
2024#define HV_FAST_PCI_DMA_SYNC 0xb8
2025
2026/* PCI MSI services. */
2027
2028#define HV_MSITYPE_MSI32 0x00
2029#define HV_MSITYPE_MSI64 0x01
2030
2031#define HV_MSIQSTATE_IDLE 0x00
2032#define HV_MSIQSTATE_ERROR 0x01
2033
2034#define HV_MSIQ_INVALID 0x00
2035#define HV_MSIQ_VALID 0x01
2036
2037#define HV_MSISTATE_IDLE 0x00
2038#define HV_MSISTATE_DELIVERED 0x01
2039
2040#define HV_MSIVALID_INVALID 0x00
2041#define HV_MSIVALID_VALID 0x01
2042
2043#define HV_PCIE_MSGTYPE_PME_MSG 0x18
2044#define HV_PCIE_MSGTYPE_PME_ACK_MSG 0x1b
2045#define HV_PCIE_MSGTYPE_CORR_MSG 0x30
2046#define HV_PCIE_MSGTYPE_NONFATAL_MSG 0x31
2047#define HV_PCIE_MSGTYPE_FATAL_MSG 0x33
2048
2049#define HV_MSG_INVALID 0x00
2050#define HV_MSG_VALID 0x01
2051
2052/* pci_msiq_conf()
2053 * TRAP: HV_FAST_TRAP
2054 * FUNCTION: HV_FAST_PCI_MSIQ_CONF
2055 * ARG0: devhandle
2056 * ARG1: msiqid
2057 * ARG2: real address
2058 * ARG3: number of entries
2059 * RET0: status
2060 * ERRORS: EINVAL Invalid devhandle, msiqid or nentries
2061 * EBADALIGN Improperly aligned real address
2062 * ENORADDR Bad real address
2063 *
2064 * Configure the MSI queue given by the devhandle and msiqid arguments,
2065 * and to be placed at the given real address and be of the given
2066 * number of entries. The real address must be aligned exactly to match
2067 * the queue size. Each queue entry is 64-bytes long, so f.e. a 32 entry
2068 * queue must be aligned on a 2048 byte real address boundary. The MSI-EQ
2069 * Head and Tail are initialized so that the MSI-EQ is 'empty'.
2070 *
2071 * Implementation Note: Certain implementations have fixed sized queues. In
2072 * that case, number of entries must contain the correct
2073 * value.
2074 */
2075#define HV_FAST_PCI_MSIQ_CONF 0xc0
2076
2077/* pci_msiq_info()
2078 * TRAP: HV_FAST_TRAP
2079 * FUNCTION: HV_FAST_PCI_MSIQ_INFO
2080 * ARG0: devhandle
2081 * ARG1: msiqid
2082 * RET0: status
2083 * RET1: real address
2084 * RET2: number of entries
2085 * ERRORS: EINVAL Invalid devhandle or msiqid
2086 *
2087 * Return the configuration information for the MSI queue described
2088 * by the given devhandle and msiqid. The base address of the queue
2089 * is returned in ARG1 and the number of entries is returned in ARG2.
2090 * If the queue is unconfigured, the real address is undefined and the
2091 * number of entries will be returned as zero.
2092 */
2093#define HV_FAST_PCI_MSIQ_INFO 0xc1
2094
2095/* pci_msiq_getvalid()
2096 * TRAP: HV_FAST_TRAP
2097 * FUNCTION: HV_FAST_PCI_MSIQ_GETVALID
2098 * ARG0: devhandle
2099 * ARG1: msiqid
2100 * RET0: status
2101 * RET1: msiqvalid (HV_MSIQ_VALID or HV_MSIQ_INVALID)
2102 * ERRORS: EINVAL Invalid devhandle or msiqid
2103 *
2104 * Get the valid state of the MSI-EQ described by the given devhandle and
2105 * msiqid.
2106 */
2107#define HV_FAST_PCI_MSIQ_GETVALID 0xc2
2108
2109/* pci_msiq_setvalid()
2110 * TRAP: HV_FAST_TRAP
2111 * FUNCTION: HV_FAST_PCI_MSIQ_SETVALID
2112 * ARG0: devhandle
2113 * ARG1: msiqid
2114 * ARG2: msiqvalid (HV_MSIQ_VALID or HV_MSIQ_INVALID)
2115 * RET0: status
2116 * ERRORS: EINVAL Invalid devhandle or msiqid or msiqvalid
2117 * value or MSI EQ is uninitialized
2118 *
2119 * Set the valid state of the MSI-EQ described by the given devhandle and
2120 * msiqid to the given msiqvalid.
2121 */
2122#define HV_FAST_PCI_MSIQ_SETVALID 0xc3
2123
2124/* pci_msiq_getstate()
2125 * TRAP: HV_FAST_TRAP
2126 * FUNCTION: HV_FAST_PCI_MSIQ_GETSTATE
2127 * ARG0: devhandle
2128 * ARG1: msiqid
2129 * RET0: status
2130 * RET1: msiqstate (HV_MSIQSTATE_IDLE or HV_MSIQSTATE_ERROR)
2131 * ERRORS: EINVAL Invalid devhandle or msiqid
2132 *
2133 * Get the state of the MSI-EQ described by the given devhandle and
2134 * msiqid.
2135 */
2136#define HV_FAST_PCI_MSIQ_GETSTATE 0xc4
2137
2138/* pci_msiq_getvalid()
2139 * TRAP: HV_FAST_TRAP
2140 * FUNCTION: HV_FAST_PCI_MSIQ_GETVALID
2141 * ARG0: devhandle
2142 * ARG1: msiqid
2143 * ARG2: msiqstate (HV_MSIQSTATE_IDLE or HV_MSIQSTATE_ERROR)
2144 * RET0: status
2145 * ERRORS: EINVAL Invalid devhandle or msiqid or msiqstate
2146 * value or MSI EQ is uninitialized
2147 *
2148 * Set the state of the MSI-EQ described by the given devhandle and
2149 * msiqid to the given msiqvalid.
2150 */
2151#define HV_FAST_PCI_MSIQ_SETSTATE 0xc5
2152
2153/* pci_msiq_gethead()
2154 * TRAP: HV_FAST_TRAP
2155 * FUNCTION: HV_FAST_PCI_MSIQ_GETHEAD
2156 * ARG0: devhandle
2157 * ARG1: msiqid
2158 * RET0: status
2159 * RET1: msiqhead
2160 * ERRORS: EINVAL Invalid devhandle or msiqid
2161 *
2162 * Get the current MSI EQ queue head for the MSI-EQ described by the
2163 * given devhandle and msiqid.
2164 */
2165#define HV_FAST_PCI_MSIQ_GETHEAD 0xc6
2166
2167/* pci_msiq_sethead()
2168 * TRAP: HV_FAST_TRAP
2169 * FUNCTION: HV_FAST_PCI_MSIQ_SETHEAD
2170 * ARG0: devhandle
2171 * ARG1: msiqid
2172 * ARG2: msiqhead
2173 * RET0: status
2174 * ERRORS: EINVAL Invalid devhandle or msiqid or msiqhead,
2175 * or MSI EQ is uninitialized
2176 *
2177 * Set the current MSI EQ queue head for the MSI-EQ described by the
2178 * given devhandle and msiqid.
2179 */
2180#define HV_FAST_PCI_MSIQ_SETHEAD 0xc7
2181
2182/* pci_msiq_gettail()
2183 * TRAP: HV_FAST_TRAP
2184 * FUNCTION: HV_FAST_PCI_MSIQ_GETTAIL
2185 * ARG0: devhandle
2186 * ARG1: msiqid
2187 * RET0: status
2188 * RET1: msiqtail
2189 * ERRORS: EINVAL Invalid devhandle or msiqid
2190 *
2191 * Get the current MSI EQ queue tail for the MSI-EQ described by the
2192 * given devhandle and msiqid.
2193 */
2194#define HV_FAST_PCI_MSIQ_GETTAIL 0xc8
2195
2196/* pci_msi_getvalid()
2197 * TRAP: HV_FAST_TRAP
2198 * FUNCTION: HV_FAST_PCI_MSI_GETVALID
2199 * ARG0: devhandle
2200 * ARG1: msinum
2201 * RET0: status
2202 * RET1: msivalidstate
2203 * ERRORS: EINVAL Invalid devhandle or msinum
2204 *
2205 * Get the current valid/enabled state for the MSI defined by the
2206 * given devhandle and msinum.
2207 */
2208#define HV_FAST_PCI_MSI_GETVALID 0xc9
2209
2210/* pci_msi_setvalid()
2211 * TRAP: HV_FAST_TRAP
2212 * FUNCTION: HV_FAST_PCI_MSI_SETVALID
2213 * ARG0: devhandle
2214 * ARG1: msinum
2215 * ARG2: msivalidstate
2216 * RET0: status
2217 * ERRORS: EINVAL Invalid devhandle or msinum or msivalidstate
2218 *
2219 * Set the current valid/enabled state for the MSI defined by the
2220 * given devhandle and msinum.
2221 */
2222#define HV_FAST_PCI_MSI_SETVALID 0xca
2223
2224/* pci_msi_getmsiq()
2225 * TRAP: HV_FAST_TRAP
2226 * FUNCTION: HV_FAST_PCI_MSI_GETMSIQ
2227 * ARG0: devhandle
2228 * ARG1: msinum
2229 * RET0: status
2230 * RET1: msiqid
2231 * ERRORS: EINVAL Invalid devhandle or msinum or MSI is unbound
2232 *
2233 * Get the MSI EQ that the MSI defined by the given devhandle and
2234 * msinum is bound to.
2235 */
2236#define HV_FAST_PCI_MSI_GETMSIQ 0xcb
2237
2238/* pci_msi_setmsiq()
2239 * TRAP: HV_FAST_TRAP
2240 * FUNCTION: HV_FAST_PCI_MSI_SETMSIQ
2241 * ARG0: devhandle
2242 * ARG1: msinum
2243 * ARG2: msitype
2244 * ARG3: msiqid
2245 * RET0: status
2246 * ERRORS: EINVAL Invalid devhandle or msinum or msiqid
2247 *
2248 * Set the MSI EQ that the MSI defined by the given devhandle and
2249 * msinum is bound to.
2250 */
2251#define HV_FAST_PCI_MSI_SETMSIQ 0xcc
2252
2253/* pci_msi_getstate()
2254 * TRAP: HV_FAST_TRAP
2255 * FUNCTION: HV_FAST_PCI_MSI_GETSTATE
2256 * ARG0: devhandle
2257 * ARG1: msinum
2258 * RET0: status
2259 * RET1: msistate
2260 * ERRORS: EINVAL Invalid devhandle or msinum
2261 *
2262 * Get the state of the MSI defined by the given devhandle and msinum.
2263 * If not initialized, return HV_MSISTATE_IDLE.
2264 */
2265#define HV_FAST_PCI_MSI_GETSTATE 0xcd
2266
2267/* pci_msi_setstate()
2268 * TRAP: HV_FAST_TRAP
2269 * FUNCTION: HV_FAST_PCI_MSI_SETSTATE
2270 * ARG0: devhandle
2271 * ARG1: msinum
2272 * ARG2: msistate
2273 * RET0: status
2274 * ERRORS: EINVAL Invalid devhandle or msinum or msistate
2275 *
2276 * Set the state of the MSI defined by the given devhandle and msinum.
2277 */
2278#define HV_FAST_PCI_MSI_SETSTATE 0xce
2279
2280/* pci_msg_getmsiq()
2281 * TRAP: HV_FAST_TRAP
2282 * FUNCTION: HV_FAST_PCI_MSG_GETMSIQ
2283 * ARG0: devhandle
2284 * ARG1: msgtype
2285 * RET0: status
2286 * RET1: msiqid
2287 * ERRORS: EINVAL Invalid devhandle or msgtype
2288 *
2289 * Get the MSI EQ of the MSG defined by the given devhandle and msgtype.
2290 */
2291#define HV_FAST_PCI_MSG_GETMSIQ 0xd0
2292
2293/* pci_msg_setmsiq()
2294 * TRAP: HV_FAST_TRAP
2295 * FUNCTION: HV_FAST_PCI_MSG_SETMSIQ
2296 * ARG0: devhandle
2297 * ARG1: msgtype
2298 * ARG2: msiqid
2299 * RET0: status
2300 * ERRORS: EINVAL Invalid devhandle, msgtype, or msiqid
2301 *
2302 * Set the MSI EQ of the MSG defined by the given devhandle and msgtype.
2303 */
2304#define HV_FAST_PCI_MSG_SETMSIQ 0xd1
2305
2306/* pci_msg_getvalid()
2307 * TRAP: HV_FAST_TRAP
2308 * FUNCTION: HV_FAST_PCI_MSG_GETVALID
2309 * ARG0: devhandle
2310 * ARG1: msgtype
2311 * RET0: status
2312 * RET1: msgvalidstate
2313 * ERRORS: EINVAL Invalid devhandle or msgtype
2314 *
2315 * Get the valid/enabled state of the MSG defined by the given
2316 * devhandle and msgtype.
2317 */
2318#define HV_FAST_PCI_MSG_GETVALID 0xd2
2319
2320/* pci_msg_setvalid()
2321 * TRAP: HV_FAST_TRAP
2322 * FUNCTION: HV_FAST_PCI_MSG_SETVALID
2323 * ARG0: devhandle
2324 * ARG1: msgtype
2325 * ARG2: msgvalidstate
2326 * RET0: status
2327 * ERRORS: EINVAL Invalid devhandle or msgtype or msgvalidstate
2328 *
2329 * Set the valid/enabled state of the MSG defined by the given
2330 * devhandle and msgtype.
2331 */
2332#define HV_FAST_PCI_MSG_SETVALID 0xd3
2333
2334/* Logical Domain Channel services. */
2335
2336#define LDC_CHANNEL_DOWN 0
2337#define LDC_CHANNEL_UP 1
2338#define LDC_CHANNEL_RESETTING 2
2339
2340/* ldc_tx_qconf()
2341 * TRAP: HV_FAST_TRAP
2342 * FUNCTION: HV_FAST_LDC_TX_QCONF
2343 * ARG0: channel ID
2344 * ARG1: real address base of queue
2345 * ARG2: num entries in queue
2346 * RET0: status
2347 *
2348 * Configure transmit queue for the LDC endpoint specified by the
2349 * given channel ID, to be placed at the given real address, and
2350 * be of the given num entries. Num entries must be a power of two.
2351 * The real address base of the queue must be aligned on the queue
2352 * size. Each queue entry is 64-bytes, so for example, a 32 entry
2353 * queue must be aligned on a 2048 byte real address boundary.
2354 *
2355 * Upon configuration of a valid transmit queue the head and tail
2356 * pointers are set to a hypervisor specific identical value indicating
2357 * that the queue initially is empty.
2358 *
2359 * The endpoint's transmit queue is un-configured if num entries is zero.
2360 *
2361 * The maximum number of entries for each queue for a specific cpu may be
2362 * determined from the machine description. A transmit queue may be
2363 * specified even in the event that the LDC is down (peer endpoint has no
2364 * receive queue specified). Transmission will begin as soon as the peer
2365 * endpoint defines a receive queue.
2366 *
2367 * It is recommended that a guest wait for a transmit queue to empty prior
2368 * to reconfiguring it, or un-configuring it. Re or un-configuring of a
2369 * non-empty transmit queue behaves exactly as defined above, however it
2370 * is undefined as to how many of the pending entries in the original queue
2371 * will be delivered prior to the re-configuration taking effect.
2372 * Furthermore, as the queue configuration causes a reset of the head and
2373 * tail pointers there is no way for a guest to determine how many entries
2374 * have been sent after the configuration operation.
2375 */
2376#define HV_FAST_LDC_TX_QCONF 0xe0
2377
2378/* ldc_tx_qinfo()
2379 * TRAP: HV_FAST_TRAP
2380 * FUNCTION: HV_FAST_LDC_TX_QINFO
2381 * ARG0: channel ID
2382 * RET0: status
2383 * RET1: real address base of queue
2384 * RET2: num entries in queue
2385 *
2386 * Return the configuration info for the transmit queue of LDC endpoint
2387 * defined by the given channel ID. The real address is the currently
2388 * defined real address base of the defined queue, and num entries is the
2389 * size of the queue in terms of number of entries.
2390 *
2391 * If the specified channel ID is a valid endpoint number, but no transmit
2392 * queue has been defined this service will return success, but with num
2393 * entries set to zero and the real address will have an undefined value.
2394 */
2395#define HV_FAST_LDC_TX_QINFO 0xe1
2396
2397/* ldc_tx_get_state()
2398 * TRAP: HV_FAST_TRAP
2399 * FUNCTION: HV_FAST_LDC_TX_GET_STATE
2400 * ARG0: channel ID
2401 * RET0: status
2402 * RET1: head offset
2403 * RET2: tail offset
2404 * RET3: channel state
2405 *
2406 * Return the transmit state, and the head and tail queue pointers, for
2407 * the transmit queue of the LDC endpoint defined by the given channel ID.
2408 * The head and tail values are the byte offset of the head and tail
2409 * positions of the transmit queue for the specified endpoint.
2410 */
2411#define HV_FAST_LDC_TX_GET_STATE 0xe2
2412
2413/* ldc_tx_set_qtail()
2414 * TRAP: HV_FAST_TRAP
2415 * FUNCTION: HV_FAST_LDC_TX_SET_QTAIL
2416 * ARG0: channel ID
2417 * ARG1: tail offset
2418 * RET0: status
2419 *
2420 * Update the tail pointer for the transmit queue associated with the LDC
2421 * endpoint defined by the given channel ID. The tail offset specified
2422 * must be aligned on a 64 byte boundary, and calculated so as to increase
2423 * the number of pending entries on the transmit queue. Any attempt to
2424 * decrease the number of pending transmit queue entires is considered
2425 * an invalid tail offset and will result in an EINVAL error.
2426 *
2427 * Since the tail of the transmit queue may not be moved backwards, the
2428 * transmit queue may be flushed by configuring a new transmit queue,
2429 * whereupon the hypervisor will configure the initial transmit head and
2430 * tail pointers to be equal.
2431 */
2432#define HV_FAST_LDC_TX_SET_QTAIL 0xe3
2433
2434/* ldc_rx_qconf()
2435 * TRAP: HV_FAST_TRAP
2436 * FUNCTION: HV_FAST_LDC_RX_QCONF
2437 * ARG0: channel ID
2438 * ARG1: real address base of queue
2439 * ARG2: num entries in queue
2440 * RET0: status
2441 *
2442 * Configure receive queue for the LDC endpoint specified by the
2443 * given channel ID, to be placed at the given real address, and
2444 * be of the given num entries. Num entries must be a power of two.
2445 * The real address base of the queue must be aligned on the queue
2446 * size. Each queue entry is 64-bytes, so for example, a 32 entry
2447 * queue must be aligned on a 2048 byte real address boundary.
2448 *
2449 * The endpoint's transmit queue is un-configured if num entries is zero.
2450 *
2451 * If a valid receive queue is specified for a local endpoint the LDC is
2452 * in the up state for the purpose of transmission to this endpoint.
2453 *
2454 * The maximum number of entries for each queue for a specific cpu may be
2455 * determined from the machine description.
2456 *
2457 * As receive queue configuration causes a reset of the queue's head and
2458 * tail pointers there is no way for a gues to determine how many entries
2459 * have been received between a preceeding ldc_get_rx_state() API call
2460 * and the completion of the configuration operation. It should be noted
2461 * that datagram delivery is not guarenteed via domain channels anyway,
2462 * and therefore any higher protocol should be resilient to datagram
2463 * loss if necessary. However, to overcome this specific race potential
2464 * it is recommended, for example, that a higher level protocol be employed
2465 * to ensure either retransmission, or ensure that no datagrams are pending
2466 * on the peer endpoint's transmit queue prior to the configuration process.
2467 */
2468#define HV_FAST_LDC_RX_QCONF 0xe4
2469
2470/* ldc_rx_qinfo()
2471 * TRAP: HV_FAST_TRAP
2472 * FUNCTION: HV_FAST_LDC_RX_QINFO
2473 * ARG0: channel ID
2474 * RET0: status
2475 * RET1: real address base of queue
2476 * RET2: num entries in queue
2477 *
2478 * Return the configuration info for the receive queue of LDC endpoint
2479 * defined by the given channel ID. The real address is the currently
2480 * defined real address base of the defined queue, and num entries is the
2481 * size of the queue in terms of number of entries.
2482 *
2483 * If the specified channel ID is a valid endpoint number, but no receive
2484 * queue has been defined this service will return success, but with num
2485 * entries set to zero and the real address will have an undefined value.
2486 */
2487#define HV_FAST_LDC_RX_QINFO 0xe5
2488
2489/* ldc_rx_get_state()
2490 * TRAP: HV_FAST_TRAP
2491 * FUNCTION: HV_FAST_LDC_RX_GET_STATE
2492 * ARG0: channel ID
2493 * RET0: status
2494 * RET1: head offset
2495 * RET2: tail offset
2496 * RET3: channel state
2497 *
2498 * Return the receive state, and the head and tail queue pointers, for
2499 * the receive queue of the LDC endpoint defined by the given channel ID.
2500 * The head and tail values are the byte offset of the head and tail
2501 * positions of the receive queue for the specified endpoint.
2502 */
2503#define HV_FAST_LDC_RX_GET_STATE 0xe6
2504
2505/* ldc_rx_set_qhead()
2506 * TRAP: HV_FAST_TRAP
2507 * FUNCTION: HV_FAST_LDC_RX_SET_QHEAD
2508 * ARG0: channel ID
2509 * ARG1: head offset
2510 * RET0: status
2511 *
2512 * Update the head pointer for the receive queue associated with the LDC
2513 * endpoint defined by the given channel ID. The head offset specified
2514 * must be aligned on a 64 byte boundary, and calculated so as to decrease
2515 * the number of pending entries on the receive queue. Any attempt to
2516 * increase the number of pending receive queue entires is considered
2517 * an invalid head offset and will result in an EINVAL error.
2518 *
2519 * The receive queue may be flushed by setting the head offset equal
2520 * to the current tail offset.
2521 */
2522#define HV_FAST_LDC_RX_SET_QHEAD 0xe7
2523
2524/* LDC Map Table Entry. Each slot is defined by a translation table
2525 * entry, as specified by the LDC_MTE_* bits below, and a 64-bit
2526 * hypervisor invalidation cookie.
2527 */
2528#define LDC_MTE_PADDR 0x0fffffffffffe000 /* pa[55:13] */
2529#define LDC_MTE_COPY_W 0x0000000000000400 /* copy write access */
2530#define LDC_MTE_COPY_R 0x0000000000000200 /* copy read access */
2531#define LDC_MTE_IOMMU_W 0x0000000000000100 /* IOMMU write access */
2532#define LDC_MTE_IOMMU_R 0x0000000000000080 /* IOMMU read access */
2533#define LDC_MTE_EXEC 0x0000000000000040 /* execute */
2534#define LDC_MTE_WRITE 0x0000000000000020 /* read */
2535#define LDC_MTE_READ 0x0000000000000010 /* write */
2536#define LDC_MTE_SZALL 0x000000000000000f /* page size bits */
2537#define LDC_MTE_SZ16GB 0x0000000000000007 /* 16GB page */
2538#define LDC_MTE_SZ2GB 0x0000000000000006 /* 2GB page */
2539#define LDC_MTE_SZ256MB 0x0000000000000005 /* 256MB page */
2540#define LDC_MTE_SZ32MB 0x0000000000000004 /* 32MB page */
2541#define LDC_MTE_SZ4MB 0x0000000000000003 /* 4MB page */
2542#define LDC_MTE_SZ512K 0x0000000000000002 /* 512K page */
2543#define LDC_MTE_SZ64K 0x0000000000000001 /* 64K page */
2544#define LDC_MTE_SZ8K 0x0000000000000000 /* 8K page */
2545
2546#ifndef __ASSEMBLY__
2547struct ldc_mtable_entry {
2548 unsigned long mte;
2549 unsigned long cookie;
2550};
2551#endif
2552
2553/* ldc_set_map_table()
2554 * TRAP: HV_FAST_TRAP
2555 * FUNCTION: HV_FAST_LDC_SET_MAP_TABLE
2556 * ARG0: channel ID
2557 * ARG1: table real address
2558 * ARG2: num entries
2559 * RET0: status
2560 *
2561 * Register the MTE table at the given table real address, with the
2562 * specified num entries, for the LDC indicated by the given channel
2563 * ID.
2564 */
2565#define HV_FAST_LDC_SET_MAP_TABLE 0xea
2566
2567/* ldc_get_map_table()
2568 * TRAP: HV_FAST_TRAP
2569 * FUNCTION: HV_FAST_LDC_GET_MAP_TABLE
2570 * ARG0: channel ID
2571 * RET0: status
2572 * RET1: table real address
2573 * RET2: num entries
2574 *
2575 * Return the configuration of the current mapping table registered
2576 * for the given channel ID.
2577 */
2578#define HV_FAST_LDC_GET_MAP_TABLE 0xeb
2579
2580#define LDC_COPY_IN 0
2581#define LDC_COPY_OUT 1
2582
2583/* ldc_copy()
2584 * TRAP: HV_FAST_TRAP
2585 * FUNCTION: HV_FAST_LDC_COPY
2586 * ARG0: channel ID
2587 * ARG1: LDC_COPY_* direction code
2588 * ARG2: target real address
2589 * ARG3: local real address
2590 * ARG4: length in bytes
2591 * RET0: status
2592 * RET1: actual length in bytes
2593 */
2594#define HV_FAST_LDC_COPY 0xec
2595
2596#define LDC_MEM_READ 1
2597#define LDC_MEM_WRITE 2
2598#define LDC_MEM_EXEC 4
2599
2600/* ldc_mapin()
2601 * TRAP: HV_FAST_TRAP
2602 * FUNCTION: HV_FAST_LDC_MAPIN
2603 * ARG0: channel ID
2604 * ARG1: cookie
2605 * RET0: status
2606 * RET1: real address
2607 * RET2: LDC_MEM_* permissions
2608 */
2609#define HV_FAST_LDC_MAPIN 0xed
2610
2611/* ldc_unmap()
2612 * TRAP: HV_FAST_TRAP
2613 * FUNCTION: HV_FAST_LDC_UNMAP
2614 * ARG0: real address
2615 * RET0: status
2616 */
2617#define HV_FAST_LDC_UNMAP 0xee
2618
2619/* ldc_revoke()
2620 * TRAP: HV_FAST_TRAP
2621 * FUNCTION: HV_FAST_LDC_REVOKE
2622 * ARG0: channel ID
2623 * ARG1: cookie
2624 * ARG2: ldc_mtable_entry cookie
2625 * RET0: status
2626 */
2627#define HV_FAST_LDC_REVOKE 0xef
2628
2629#ifndef __ASSEMBLY__
2630extern unsigned long sun4v_ldc_tx_qconf(unsigned long channel,
2631 unsigned long ra,
2632 unsigned long num_entries);
2633extern unsigned long sun4v_ldc_tx_qinfo(unsigned long channel,
2634 unsigned long *ra,
2635 unsigned long *num_entries);
2636extern unsigned long sun4v_ldc_tx_get_state(unsigned long channel,
2637 unsigned long *head_off,
2638 unsigned long *tail_off,
2639 unsigned long *chan_state);
2640extern unsigned long sun4v_ldc_tx_set_qtail(unsigned long channel,
2641 unsigned long tail_off);
2642extern unsigned long sun4v_ldc_rx_qconf(unsigned long channel,
2643 unsigned long ra,
2644 unsigned long num_entries);
2645extern unsigned long sun4v_ldc_rx_qinfo(unsigned long channel,
2646 unsigned long *ra,
2647 unsigned long *num_entries);
2648extern unsigned long sun4v_ldc_rx_get_state(unsigned long channel,
2649 unsigned long *head_off,
2650 unsigned long *tail_off,
2651 unsigned long *chan_state);
2652extern unsigned long sun4v_ldc_rx_set_qhead(unsigned long channel,
2653 unsigned long head_off);
2654extern unsigned long sun4v_ldc_set_map_table(unsigned long channel,
2655 unsigned long ra,
2656 unsigned long num_entries);
2657extern unsigned long sun4v_ldc_get_map_table(unsigned long channel,
2658 unsigned long *ra,
2659 unsigned long *num_entries);
2660extern unsigned long sun4v_ldc_copy(unsigned long channel,
2661 unsigned long dir_code,
2662 unsigned long tgt_raddr,
2663 unsigned long lcl_raddr,
2664 unsigned long len,
2665 unsigned long *actual_len);
2666extern unsigned long sun4v_ldc_mapin(unsigned long channel,
2667 unsigned long cookie,
2668 unsigned long *ra,
2669 unsigned long *perm);
2670extern unsigned long sun4v_ldc_unmap(unsigned long ra);
2671extern unsigned long sun4v_ldc_revoke(unsigned long channel,
2672 unsigned long cookie,
2673 unsigned long mte_cookie);
2674#endif
2675
2676/* Performance counter services. */
2677
2678#define HV_PERF_JBUS_PERF_CTRL_REG 0x00
2679#define HV_PERF_JBUS_PERF_CNT_REG 0x01
2680#define HV_PERF_DRAM_PERF_CTRL_REG_0 0x02
2681#define HV_PERF_DRAM_PERF_CNT_REG_0 0x03
2682#define HV_PERF_DRAM_PERF_CTRL_REG_1 0x04
2683#define HV_PERF_DRAM_PERF_CNT_REG_1 0x05
2684#define HV_PERF_DRAM_PERF_CTRL_REG_2 0x06
2685#define HV_PERF_DRAM_PERF_CNT_REG_2 0x07
2686#define HV_PERF_DRAM_PERF_CTRL_REG_3 0x08
2687#define HV_PERF_DRAM_PERF_CNT_REG_3 0x09
2688
2689/* get_perfreg()
2690 * TRAP: HV_FAST_TRAP
2691 * FUNCTION: HV_FAST_GET_PERFREG
2692 * ARG0: performance reg number
2693 * RET0: status
2694 * RET1: performance reg value
2695 * ERRORS: EINVAL Invalid performance register number
2696 * ENOACCESS No access allowed to performance counters
2697 *
2698 * Read the value of the given DRAM/JBUS performance counter/control register.
2699 */
2700#define HV_FAST_GET_PERFREG 0x100
2701
2702/* set_perfreg()
2703 * TRAP: HV_FAST_TRAP
2704 * FUNCTION: HV_FAST_SET_PERFREG
2705 * ARG0: performance reg number
2706 * ARG1: performance reg value
2707 * RET0: status
2708 * ERRORS: EINVAL Invalid performance register number
2709 * ENOACCESS No access allowed to performance counters
2710 *
2711 * Write the given performance reg value to the given DRAM/JBUS
2712 * performance counter/control register.
2713 */
2714#define HV_FAST_SET_PERFREG 0x101
2715
2716/* MMU statistics services.
2717 *
2718 * The hypervisor maintains MMU statistics and privileged code provides
2719 * a buffer where these statistics can be collected. It is continually
2720 * updated once configured. The layout is as follows:
2721 */
2722#ifndef __ASSEMBLY__
2723struct hv_mmu_statistics {
2724 unsigned long immu_tsb_hits_ctx0_8k_tte;
2725 unsigned long immu_tsb_ticks_ctx0_8k_tte;
2726 unsigned long immu_tsb_hits_ctx0_64k_tte;
2727 unsigned long immu_tsb_ticks_ctx0_64k_tte;
2728 unsigned long __reserved1[2];
2729 unsigned long immu_tsb_hits_ctx0_4mb_tte;
2730 unsigned long immu_tsb_ticks_ctx0_4mb_tte;
2731 unsigned long __reserved2[2];
2732 unsigned long immu_tsb_hits_ctx0_256mb_tte;
2733 unsigned long immu_tsb_ticks_ctx0_256mb_tte;
2734 unsigned long __reserved3[4];
2735 unsigned long immu_tsb_hits_ctxnon0_8k_tte;
2736 unsigned long immu_tsb_ticks_ctxnon0_8k_tte;
2737 unsigned long immu_tsb_hits_ctxnon0_64k_tte;
2738 unsigned long immu_tsb_ticks_ctxnon0_64k_tte;
2739 unsigned long __reserved4[2];
2740 unsigned long immu_tsb_hits_ctxnon0_4mb_tte;
2741 unsigned long immu_tsb_ticks_ctxnon0_4mb_tte;
2742 unsigned long __reserved5[2];
2743 unsigned long immu_tsb_hits_ctxnon0_256mb_tte;
2744 unsigned long immu_tsb_ticks_ctxnon0_256mb_tte;
2745 unsigned long __reserved6[4];
2746 unsigned long dmmu_tsb_hits_ctx0_8k_tte;
2747 unsigned long dmmu_tsb_ticks_ctx0_8k_tte;
2748 unsigned long dmmu_tsb_hits_ctx0_64k_tte;
2749 unsigned long dmmu_tsb_ticks_ctx0_64k_tte;
2750 unsigned long __reserved7[2];
2751 unsigned long dmmu_tsb_hits_ctx0_4mb_tte;
2752 unsigned long dmmu_tsb_ticks_ctx0_4mb_tte;
2753 unsigned long __reserved8[2];
2754 unsigned long dmmu_tsb_hits_ctx0_256mb_tte;
2755 unsigned long dmmu_tsb_ticks_ctx0_256mb_tte;
2756 unsigned long __reserved9[4];
2757 unsigned long dmmu_tsb_hits_ctxnon0_8k_tte;
2758 unsigned long dmmu_tsb_ticks_ctxnon0_8k_tte;
2759 unsigned long dmmu_tsb_hits_ctxnon0_64k_tte;
2760 unsigned long dmmu_tsb_ticks_ctxnon0_64k_tte;
2761 unsigned long __reserved10[2];
2762 unsigned long dmmu_tsb_hits_ctxnon0_4mb_tte;
2763 unsigned long dmmu_tsb_ticks_ctxnon0_4mb_tte;
2764 unsigned long __reserved11[2];
2765 unsigned long dmmu_tsb_hits_ctxnon0_256mb_tte;
2766 unsigned long dmmu_tsb_ticks_ctxnon0_256mb_tte;
2767 unsigned long __reserved12[4];
2768};
2769#endif
2770
2771/* mmustat_conf()
2772 * TRAP: HV_FAST_TRAP
2773 * FUNCTION: HV_FAST_MMUSTAT_CONF
2774 * ARG0: real address
2775 * RET0: status
2776 * RET1: real address
2777 * ERRORS: ENORADDR Invalid real address
2778 * EBADALIGN Real address not aligned on 64-byte boundary
2779 * EBADTRAP API not supported on this processor
2780 *
2781 * Enable MMU statistic gathering using the buffer at the given real
2782 * address on the current virtual CPU. The new buffer real address
2783 * is given in ARG1, and the previously specified buffer real address
2784 * is returned in RET1, or is returned as zero for the first invocation.
2785 *
2786 * If the passed in real address argument is zero, this will disable
2787 * MMU statistic collection on the current virtual CPU. If an error is
2788 * returned then no statistics are collected.
2789 *
2790 * The buffer contents should be initialized to all zeros before being
2791 * given to the hypervisor or else the statistics will be meaningless.
2792 */
2793#define HV_FAST_MMUSTAT_CONF 0x102
2794
2795/* mmustat_info()
2796 * TRAP: HV_FAST_TRAP
2797 * FUNCTION: HV_FAST_MMUSTAT_INFO
2798 * RET0: status
2799 * RET1: real address
2800 * ERRORS: EBADTRAP API not supported on this processor
2801 *
2802 * Return the current state and real address of the currently configured
2803 * MMU statistics buffer on the current virtual CPU.
2804 */
2805#define HV_FAST_MMUSTAT_INFO 0x103
2806
2807#ifndef __ASSEMBLY__
2808extern unsigned long sun4v_mmustat_conf(unsigned long ra, unsigned long *orig_ra);
2809extern unsigned long sun4v_mmustat_info(unsigned long *ra);
2810#endif
2811
2812/* NCS crypto services */
2813
2814/* ncs_request() sub-function numbers */
2815#define HV_NCS_QCONF 0x01
2816#define HV_NCS_QTAIL_UPDATE 0x02
2817
2818#ifndef __ASSEMBLY__
2819struct hv_ncs_queue_entry {
2820 /* MAU Control Register */
2821 unsigned long mau_control;
2822#define MAU_CONTROL_INV_PARITY 0x0000000000002000
2823#define MAU_CONTROL_STRAND 0x0000000000001800
2824#define MAU_CONTROL_BUSY 0x0000000000000400
2825#define MAU_CONTROL_INT 0x0000000000000200
2826#define MAU_CONTROL_OP 0x00000000000001c0
2827#define MAU_CONTROL_OP_SHIFT 6
2828#define MAU_OP_LOAD_MA_MEMORY 0x0
2829#define MAU_OP_STORE_MA_MEMORY 0x1
2830#define MAU_OP_MODULAR_MULT 0x2
2831#define MAU_OP_MODULAR_REDUCE 0x3
2832#define MAU_OP_MODULAR_EXP_LOOP 0x4
2833#define MAU_CONTROL_LEN 0x000000000000003f
2834#define MAU_CONTROL_LEN_SHIFT 0
2835
2836 /* Real address of bytes to load or store bytes
2837 * into/out-of the MAU.
2838 */
2839 unsigned long mau_mpa;
2840
2841 /* Modular Arithmetic MA Offset Register. */
2842 unsigned long mau_ma;
2843
2844 /* Modular Arithmetic N Prime Register. */
2845 unsigned long mau_np;
2846};
2847
2848struct hv_ncs_qconf_arg {
2849 unsigned long mid; /* MAU ID, 1 per core on Niagara */
2850 unsigned long base; /* Real address base of queue */
2851 unsigned long end; /* Real address end of queue */
2852 unsigned long num_ents; /* Number of entries in queue */
2853};
2854
2855struct hv_ncs_qtail_update_arg {
2856 unsigned long mid; /* MAU ID, 1 per core on Niagara */
2857 unsigned long tail; /* New tail index to use */
2858 unsigned long syncflag; /* only SYNCFLAG_SYNC is implemented */
2859#define HV_NCS_SYNCFLAG_SYNC 0x00
2860#define HV_NCS_SYNCFLAG_ASYNC 0x01
2861};
2862#endif
2863
2864/* ncs_request()
2865 * TRAP: HV_FAST_TRAP
2866 * FUNCTION: HV_FAST_NCS_REQUEST
2867 * ARG0: NCS sub-function
2868 * ARG1: sub-function argument real address
2869 * ARG2: size in bytes of sub-function argument
2870 * RET0: status
2871 *
2872 * The MAU chip of the Niagara processor is not directly accessible
2873 * to privileged code, instead it is programmed indirectly via this
2874 * hypervisor API.
2875 *
2876 * The interfaces defines a queue of MAU operations to perform.
2877 * Privileged code registers a queue with the hypervisor by invoking
2878 * this HVAPI with the HV_NCS_QCONF sub-function, which defines the
2879 * base, end, and number of entries of the queue. Each queue entry
2880 * contains a MAU register struct block.
2881 *
2882 * The privileged code then proceeds to add entries to the queue and
2883 * then invoke the HV_NCS_QTAIL_UPDATE sub-function. Since only
2884 * synchronous operations are supported by the current hypervisor,
2885 * HV_NCS_QTAIL_UPDATE will run all the pending queue entries to
2886 * completion and return HV_EOK, or return an error code.
2887 *
2888 * The real address of the sub-function argument must be aligned on at
2889 * least an 8-byte boundary.
2890 *
2891 * The tail argument of HV_NCS_QTAIL_UPDATE is an index, not a byte
2892 * offset, into the queue and must be less than or equal the 'num_ents'
2893 * argument given in the HV_NCS_QCONF call.
2894 */
2895#define HV_FAST_NCS_REQUEST 0x110
2896
2897#ifndef __ASSEMBLY__
2898extern unsigned long sun4v_ncs_request(unsigned long request,
2899 unsigned long arg_ra,
2900 unsigned long arg_size);
2901#endif
2902
2903#define HV_FAST_FIRE_GET_PERFREG 0x120
2904#define HV_FAST_FIRE_SET_PERFREG 0x121
2905
2906/* Function numbers for HV_CORE_TRAP. */
2907#define HV_CORE_SET_VER 0x00
2908#define HV_CORE_PUTCHAR 0x01
2909#define HV_CORE_EXIT 0x02
2910#define HV_CORE_GET_VER 0x03
2911
2912/* Hypervisor API groups for use with HV_CORE_SET_VER and
2913 * HV_CORE_GET_VER.
2914 */
2915#define HV_GRP_SUN4V 0x0000
2916#define HV_GRP_CORE 0x0001
2917#define HV_GRP_INTR 0x0002
2918#define HV_GRP_SOFT_STATE 0x0003
2919#define HV_GRP_PCI 0x0100
2920#define HV_GRP_LDOM 0x0101
2921#define HV_GRP_SVC_CHAN 0x0102
2922#define HV_GRP_NCS 0x0103
2923#define HV_GRP_NIAG_PERF 0x0200
2924#define HV_GRP_FIRE_PERF 0x0201
2925#define HV_GRP_DIAG 0x0300
2926
2927#ifndef __ASSEMBLY__
2928extern unsigned long sun4v_get_version(unsigned long group,
2929 unsigned long *major,
2930 unsigned long *minor);
2931extern unsigned long sun4v_set_version(unsigned long group,
2932 unsigned long major,
2933 unsigned long minor,
2934 unsigned long *actual_minor);
2935
2936extern int sun4v_hvapi_register(unsigned long group, unsigned long major,
2937 unsigned long *minor);
2938extern void sun4v_hvapi_unregister(unsigned long group);
2939extern int sun4v_hvapi_get(unsigned long group,
2940 unsigned long *major,
2941 unsigned long *minor);
2942extern void sun4v_hvapi_init(void);
2943#endif
2944
2945#endif /* !(_SPARC64_HYPERVISOR_H) */
diff --git a/include/asm-sparc64/ide.h b/include/asm-sparc64/ide.h
index 1282676da1cd..7125317a428d 100644
--- a/include/asm-sparc64/ide.h
+++ b/include/asm-sparc64/ide.h
@@ -1,118 +1 @@
1/* #include <asm-sparc/ide.h>
2 * ide.h: Ultra/PCI specific IDE glue.
3 *
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
6 */
7
8#ifndef _SPARC64_IDE_H
9#define _SPARC64_IDE_H
10
11#ifdef __KERNEL__
12
13#include <asm/pgalloc.h>
14#include <asm/io.h>
15#include <asm/spitfire.h>
16#include <asm/cacheflush.h>
17#include <asm/page.h>
18
19#ifndef MAX_HWIFS
20# ifdef CONFIG_BLK_DEV_IDEPCI
21#define MAX_HWIFS 10
22# else
23#define MAX_HWIFS 2
24# endif
25#endif
26
27#define __ide_insl(data_reg, buffer, wcount) \
28 __ide_insw(data_reg, buffer, (wcount)<<1)
29#define __ide_outsl(data_reg, buffer, wcount) \
30 __ide_outsw(data_reg, buffer, (wcount)<<1)
31
32/* On sparc64, I/O ports and MMIO registers are accessed identically. */
33#define __ide_mm_insw __ide_insw
34#define __ide_mm_insl __ide_insl
35#define __ide_mm_outsw __ide_outsw
36#define __ide_mm_outsl __ide_outsl
37
38static inline unsigned int inw_be(void __iomem *addr)
39{
40 unsigned int ret;
41
42 __asm__ __volatile__("lduha [%1] %2, %0"
43 : "=r" (ret)
44 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
45
46 return ret;
47}
48
49static inline void __ide_insw(void __iomem *port, void *dst, u32 count)
50{
51#ifdef DCACHE_ALIASING_POSSIBLE
52 unsigned long end = (unsigned long)dst + (count << 1);
53#endif
54 u16 *ps = dst;
55 u32 *pi;
56
57 if(((u64)ps) & 0x2) {
58 *ps++ = inw_be(port);
59 count--;
60 }
61 pi = (u32 *)ps;
62 while(count >= 2) {
63 u32 w;
64
65 w = inw_be(port) << 16;
66 w |= inw_be(port);
67 *pi++ = w;
68 count -= 2;
69 }
70 ps = (u16 *)pi;
71 if(count)
72 *ps++ = inw_be(port);
73
74#ifdef DCACHE_ALIASING_POSSIBLE
75 __flush_dcache_range((unsigned long)dst, end);
76#endif
77}
78
79static inline void outw_be(unsigned short w, void __iomem *addr)
80{
81 __asm__ __volatile__("stha %0, [%1] %2"
82 : /* no outputs */
83 : "r" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
84}
85
86static inline void __ide_outsw(void __iomem *port, void *src, u32 count)
87{
88#ifdef DCACHE_ALIASING_POSSIBLE
89 unsigned long end = (unsigned long)src + (count << 1);
90#endif
91 const u16 *ps = src;
92 const u32 *pi;
93
94 if(((u64)src) & 0x2) {
95 outw_be(*ps++, port);
96 count--;
97 }
98 pi = (const u32 *)ps;
99 while(count >= 2) {
100 u32 w;
101
102 w = *pi++;
103 outw_be((w >> 16), port);
104 outw_be(w, port);
105 count -= 2;
106 }
107 ps = (const u16 *)pi;
108 if(count)
109 outw_be(*ps, port);
110
111#ifdef DCACHE_ALIASING_POSSIBLE
112 __flush_dcache_range((unsigned long)src, end);
113#endif
114}
115
116#endif /* __KERNEL__ */
117
118#endif /* _SPARC64_IDE_H */
diff --git a/include/asm-sparc64/idprom.h b/include/asm-sparc64/idprom.h
index a363fa0a112a..c22f9c30bc78 100644
--- a/include/asm-sparc64/idprom.h
+++ b/include/asm-sparc64/idprom.h
@@ -1,25 +1 @@
1/* #include <asm-sparc/idprom.h>
2 * idprom.h: Macros and defines for idprom routines
3 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef _SPARC64_IDPROM_H
8#define _SPARC64_IDPROM_H
9
10#include <linux/types.h>
11
12struct idprom {
13 u8 id_format; /* Format identifier (always 0x01) */
14 u8 id_machtype; /* Machine type */
15 u8 id_ethaddr[6]; /* Hardware ethernet address */
16 s32 id_date; /* Date of manufacture */
17 u32 id_sernum:24; /* Unique serial number */
18 u8 id_cksum; /* Checksum - xor of the data bytes */
19 u8 reserved[16];
20};
21
22extern struct idprom *idprom;
23extern void idprom_init(void);
24
25#endif /* !(_SPARC_IDPROM_H) */
diff --git a/include/asm-sparc64/intr_queue.h b/include/asm-sparc64/intr_queue.h
index 206077dedc2a..f7225015b3db 100644
--- a/include/asm-sparc64/intr_queue.h
+++ b/include/asm-sparc64/intr_queue.h
@@ -1,15 +1 @@
1#ifndef _SPARC64_INTR_QUEUE_H #include <asm-sparc/intr_queue.h>
2#define _SPARC64_INTR_QUEUE_H
3
4/* Sun4v interrupt queue registers, accessed via ASI_QUEUE. */
5
6#define INTRQ_CPU_MONDO_HEAD 0x3c0 /* CPU mondo head */
7#define INTRQ_CPU_MONDO_TAIL 0x3c8 /* CPU mondo tail */
8#define INTRQ_DEVICE_MONDO_HEAD 0x3d0 /* Device mondo head */
9#define INTRQ_DEVICE_MONDO_TAIL 0x3d8 /* Device mondo tail */
10#define INTRQ_RESUM_MONDO_HEAD 0x3e0 /* Resumable error mondo head */
11#define INTRQ_RESUM_MONDO_TAIL 0x3e8 /* Resumable error mondo tail */
12#define INTRQ_NONRESUM_MONDO_HEAD 0x3f0 /* Non-resumable error mondo head */
13#define INTRQ_NONRESUM_MONDO_TAIL 0x3f8 /* Non-resumable error mondo head */
14
15#endif /* !(_SPARC64_INTR_QUEUE_H) */
diff --git a/include/asm-sparc64/io.h b/include/asm-sparc64/io.h
index 3158960f3eb5..25ff258dfd33 100644
--- a/include/asm-sparc64/io.h
+++ b/include/asm-sparc64/io.h
@@ -1,511 +1 @@
1#ifndef __SPARC64_IO_H #include <asm-sparc/io.h>
2#define __SPARC64_IO_H
3
4#include <linux/kernel.h>
5#include <linux/compiler.h>
6#include <linux/types.h>
7
8#include <asm/page.h> /* IO address mapping routines need this */
9#include <asm/system.h>
10#include <asm/asi.h>
11
12/* PC crapola... */
13#define __SLOW_DOWN_IO do { } while (0)
14#define SLOW_DOWN_IO do { } while (0)
15
16/* BIO layer definitions. */
17extern unsigned long kern_base, kern_size;
18#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
19#define BIO_VMERGE_BOUNDARY 8192
20
21static inline u8 _inb(unsigned long addr)
22{
23 u8 ret;
24
25 __asm__ __volatile__("lduba\t[%1] %2, %0\t/* pci_inb */"
26 : "=r" (ret)
27 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
28 : "memory");
29
30 return ret;
31}
32
33static inline u16 _inw(unsigned long addr)
34{
35 u16 ret;
36
37 __asm__ __volatile__("lduha\t[%1] %2, %0\t/* pci_inw */"
38 : "=r" (ret)
39 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
40 : "memory");
41
42 return ret;
43}
44
45static inline u32 _inl(unsigned long addr)
46{
47 u32 ret;
48
49 __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* pci_inl */"
50 : "=r" (ret)
51 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
52 : "memory");
53
54 return ret;
55}
56
57static inline void _outb(u8 b, unsigned long addr)
58{
59 __asm__ __volatile__("stba\t%r0, [%1] %2\t/* pci_outb */"
60 : /* no outputs */
61 : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
62 : "memory");
63}
64
65static inline void _outw(u16 w, unsigned long addr)
66{
67 __asm__ __volatile__("stha\t%r0, [%1] %2\t/* pci_outw */"
68 : /* no outputs */
69 : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
70 : "memory");
71}
72
73static inline void _outl(u32 l, unsigned long addr)
74{
75 __asm__ __volatile__("stwa\t%r0, [%1] %2\t/* pci_outl */"
76 : /* no outputs */
77 : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
78 : "memory");
79}
80
81#define inb(__addr) (_inb((unsigned long)(__addr)))
82#define inw(__addr) (_inw((unsigned long)(__addr)))
83#define inl(__addr) (_inl((unsigned long)(__addr)))
84#define outb(__b, __addr) (_outb((u8)(__b), (unsigned long)(__addr)))
85#define outw(__w, __addr) (_outw((u16)(__w), (unsigned long)(__addr)))
86#define outl(__l, __addr) (_outl((u32)(__l), (unsigned long)(__addr)))
87
88#define inb_p(__addr) inb(__addr)
89#define outb_p(__b, __addr) outb(__b, __addr)
90#define inw_p(__addr) inw(__addr)
91#define outw_p(__w, __addr) outw(__w, __addr)
92#define inl_p(__addr) inl(__addr)
93#define outl_p(__l, __addr) outl(__l, __addr)
94
95extern void outsb(unsigned long, const void *, unsigned long);
96extern void outsw(unsigned long, const void *, unsigned long);
97extern void outsl(unsigned long, const void *, unsigned long);
98extern void insb(unsigned long, void *, unsigned long);
99extern void insw(unsigned long, void *, unsigned long);
100extern void insl(unsigned long, void *, unsigned long);
101
102static inline void ioread8_rep(void __iomem *port, void *buf, unsigned long count)
103{
104 insb((unsigned long __force)port, buf, count);
105}
106static inline void ioread16_rep(void __iomem *port, void *buf, unsigned long count)
107{
108 insw((unsigned long __force)port, buf, count);
109}
110
111static inline void ioread32_rep(void __iomem *port, void *buf, unsigned long count)
112{
113 insl((unsigned long __force)port, buf, count);
114}
115
116static inline void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count)
117{
118 outsb((unsigned long __force)port, buf, count);
119}
120
121static inline void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count)
122{
123 outsw((unsigned long __force)port, buf, count);
124}
125
126static inline void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count)
127{
128 outsl((unsigned long __force)port, buf, count);
129}
130
131/* Memory functions, same as I/O accesses on Ultra. */
132static inline u8 _readb(const volatile void __iomem *addr)
133{ u8 ret;
134
135 __asm__ __volatile__("lduba\t[%1] %2, %0\t/* pci_readb */"
136 : "=r" (ret)
137 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
138 : "memory");
139 return ret;
140}
141
142static inline u16 _readw(const volatile void __iomem *addr)
143{ u16 ret;
144
145 __asm__ __volatile__("lduha\t[%1] %2, %0\t/* pci_readw */"
146 : "=r" (ret)
147 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
148 : "memory");
149
150 return ret;
151}
152
153static inline u32 _readl(const volatile void __iomem *addr)
154{ u32 ret;
155
156 __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* pci_readl */"
157 : "=r" (ret)
158 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
159 : "memory");
160
161 return ret;
162}
163
164static inline u64 _readq(const volatile void __iomem *addr)
165{ u64 ret;
166
167 __asm__ __volatile__("ldxa\t[%1] %2, %0\t/* pci_readq */"
168 : "=r" (ret)
169 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
170 : "memory");
171
172 return ret;
173}
174
175static inline void _writeb(u8 b, volatile void __iomem *addr)
176{
177 __asm__ __volatile__("stba\t%r0, [%1] %2\t/* pci_writeb */"
178 : /* no outputs */
179 : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
180 : "memory");
181}
182
183static inline void _writew(u16 w, volatile void __iomem *addr)
184{
185 __asm__ __volatile__("stha\t%r0, [%1] %2\t/* pci_writew */"
186 : /* no outputs */
187 : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
188 : "memory");
189}
190
191static inline void _writel(u32 l, volatile void __iomem *addr)
192{
193 __asm__ __volatile__("stwa\t%r0, [%1] %2\t/* pci_writel */"
194 : /* no outputs */
195 : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
196 : "memory");
197}
198
199static inline void _writeq(u64 q, volatile void __iomem *addr)
200{
201 __asm__ __volatile__("stxa\t%r0, [%1] %2\t/* pci_writeq */"
202 : /* no outputs */
203 : "Jr" (q), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
204 : "memory");
205}
206
207#define readb(__addr) _readb(__addr)
208#define readw(__addr) _readw(__addr)
209#define readl(__addr) _readl(__addr)
210#define readq(__addr) _readq(__addr)
211#define readb_relaxed(__addr) _readb(__addr)
212#define readw_relaxed(__addr) _readw(__addr)
213#define readl_relaxed(__addr) _readl(__addr)
214#define readq_relaxed(__addr) _readq(__addr)
215#define writeb(__b, __addr) _writeb(__b, __addr)
216#define writew(__w, __addr) _writew(__w, __addr)
217#define writel(__l, __addr) _writel(__l, __addr)
218#define writeq(__q, __addr) _writeq(__q, __addr)
219
220/* Now versions without byte-swapping. */
221static inline u8 _raw_readb(unsigned long addr)
222{
223 u8 ret;
224
225 __asm__ __volatile__("lduba\t[%1] %2, %0\t/* pci_raw_readb */"
226 : "=r" (ret)
227 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
228
229 return ret;
230}
231
232static inline u16 _raw_readw(unsigned long addr)
233{
234 u16 ret;
235
236 __asm__ __volatile__("lduha\t[%1] %2, %0\t/* pci_raw_readw */"
237 : "=r" (ret)
238 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
239
240 return ret;
241}
242
243static inline u32 _raw_readl(unsigned long addr)
244{
245 u32 ret;
246
247 __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* pci_raw_readl */"
248 : "=r" (ret)
249 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
250
251 return ret;
252}
253
254static inline u64 _raw_readq(unsigned long addr)
255{
256 u64 ret;
257
258 __asm__ __volatile__("ldxa\t[%1] %2, %0\t/* pci_raw_readq */"
259 : "=r" (ret)
260 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
261
262 return ret;
263}
264
265static inline void _raw_writeb(u8 b, unsigned long addr)
266{
267 __asm__ __volatile__("stba\t%r0, [%1] %2\t/* pci_raw_writeb */"
268 : /* no outputs */
269 : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
270}
271
272static inline void _raw_writew(u16 w, unsigned long addr)
273{
274 __asm__ __volatile__("stha\t%r0, [%1] %2\t/* pci_raw_writew */"
275 : /* no outputs */
276 : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
277}
278
279static inline void _raw_writel(u32 l, unsigned long addr)
280{
281 __asm__ __volatile__("stwa\t%r0, [%1] %2\t/* pci_raw_writel */"
282 : /* no outputs */
283 : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
284}
285
286static inline void _raw_writeq(u64 q, unsigned long addr)
287{
288 __asm__ __volatile__("stxa\t%r0, [%1] %2\t/* pci_raw_writeq */"
289 : /* no outputs */
290 : "Jr" (q), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
291}
292
293#define __raw_readb(__addr) (_raw_readb((unsigned long)(__addr)))
294#define __raw_readw(__addr) (_raw_readw((unsigned long)(__addr)))
295#define __raw_readl(__addr) (_raw_readl((unsigned long)(__addr)))
296#define __raw_readq(__addr) (_raw_readq((unsigned long)(__addr)))
297#define __raw_writeb(__b, __addr) (_raw_writeb((u8)(__b), (unsigned long)(__addr)))
298#define __raw_writew(__w, __addr) (_raw_writew((u16)(__w), (unsigned long)(__addr)))
299#define __raw_writel(__l, __addr) (_raw_writel((u32)(__l), (unsigned long)(__addr)))
300#define __raw_writeq(__q, __addr) (_raw_writeq((u64)(__q), (unsigned long)(__addr)))
301
302/* Valid I/O Space regions are anywhere, because each PCI bus supported
303 * can live in an arbitrary area of the physical address range.
304 */
305#define IO_SPACE_LIMIT 0xffffffffffffffffUL
306
307/* Now, SBUS variants, only difference from PCI is that we do
308 * not use little-endian ASIs.
309 */
310static inline u8 _sbus_readb(const volatile void __iomem *addr)
311{
312 u8 ret;
313
314 __asm__ __volatile__("lduba\t[%1] %2, %0\t/* sbus_readb */"
315 : "=r" (ret)
316 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
317 : "memory");
318
319 return ret;
320}
321
322static inline u16 _sbus_readw(const volatile void __iomem *addr)
323{
324 u16 ret;
325
326 __asm__ __volatile__("lduha\t[%1] %2, %0\t/* sbus_readw */"
327 : "=r" (ret)
328 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
329 : "memory");
330
331 return ret;
332}
333
334static inline u32 _sbus_readl(const volatile void __iomem *addr)
335{
336 u32 ret;
337
338 __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* sbus_readl */"
339 : "=r" (ret)
340 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
341 : "memory");
342
343 return ret;
344}
345
346static inline u64 _sbus_readq(const volatile void __iomem *addr)
347{
348 u64 ret;
349
350 __asm__ __volatile__("ldxa\t[%1] %2, %0\t/* sbus_readq */"
351 : "=r" (ret)
352 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
353 : "memory");
354
355 return ret;
356}
357
358static inline void _sbus_writeb(u8 b, volatile void __iomem *addr)
359{
360 __asm__ __volatile__("stba\t%r0, [%1] %2\t/* sbus_writeb */"
361 : /* no outputs */
362 : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
363 : "memory");
364}
365
366static inline void _sbus_writew(u16 w, volatile void __iomem *addr)
367{
368 __asm__ __volatile__("stha\t%r0, [%1] %2\t/* sbus_writew */"
369 : /* no outputs */
370 : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
371 : "memory");
372}
373
374static inline void _sbus_writel(u32 l, volatile void __iomem *addr)
375{
376 __asm__ __volatile__("stwa\t%r0, [%1] %2\t/* sbus_writel */"
377 : /* no outputs */
378 : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
379 : "memory");
380}
381
382static inline void _sbus_writeq(u64 l, volatile void __iomem *addr)
383{
384 __asm__ __volatile__("stxa\t%r0, [%1] %2\t/* sbus_writeq */"
385 : /* no outputs */
386 : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E)
387 : "memory");
388}
389
390#define sbus_readb(__addr) _sbus_readb(__addr)
391#define sbus_readw(__addr) _sbus_readw(__addr)
392#define sbus_readl(__addr) _sbus_readl(__addr)
393#define sbus_readq(__addr) _sbus_readq(__addr)
394#define sbus_writeb(__b, __addr) _sbus_writeb(__b, __addr)
395#define sbus_writew(__w, __addr) _sbus_writew(__w, __addr)
396#define sbus_writel(__l, __addr) _sbus_writel(__l, __addr)
397#define sbus_writeq(__l, __addr) _sbus_writeq(__l, __addr)
398
399static inline void _sbus_memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
400{
401 while(n--) {
402 sbus_writeb(c, dst);
403 dst++;
404 }
405}
406
407#define sbus_memset_io(d,c,sz) _sbus_memset_io(d,c,sz)
408
409static inline void
410_memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
411{
412 volatile void __iomem *d = dst;
413
414 while (n--) {
415 writeb(c, d);
416 d++;
417 }
418}
419
420#define memset_io(d,c,sz) _memset_io(d,c,sz)
421
422static inline void
423_memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
424{
425 char *d = dst;
426
427 while (n--) {
428 char tmp = readb(src);
429 *d++ = tmp;
430 src++;
431 }
432}
433
434#define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
435
436static inline void
437_memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n)
438{
439 const char *s = src;
440 volatile void __iomem *d = dst;
441
442 while (n--) {
443 char tmp = *s++;
444 writeb(tmp, d);
445 d++;
446 }
447}
448
449#define memcpy_toio(d,s,sz) _memcpy_toio(d,s,sz)
450
451#define mmiowb()
452
453#ifdef __KERNEL__
454
455/* On sparc64 we have the whole physical IO address space accessible
456 * using physically addressed loads and stores, so this does nothing.
457 */
458static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
459{
460 return (void __iomem *)offset;
461}
462
463#define ioremap_nocache(X,Y) ioremap((X),(Y))
464
465static inline void iounmap(volatile void __iomem *addr)
466{
467}
468
469#define ioread8(X) readb(X)
470#define ioread16(X) readw(X)
471#define ioread32(X) readl(X)
472#define iowrite8(val,X) writeb(val,X)
473#define iowrite16(val,X) writew(val,X)
474#define iowrite32(val,X) writel(val,X)
475
476/* Create a virtual mapping cookie for an IO port range */
477extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
478extern void ioport_unmap(void __iomem *);
479
480/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
481struct pci_dev;
482extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
483extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
484
485/* Similarly for SBUS. */
486#define sbus_ioremap(__res, __offset, __size, __name) \
487({ unsigned long __ret; \
488 __ret = (__res)->start + (((__res)->flags & 0x1ffUL) << 32UL); \
489 __ret += (unsigned long) (__offset); \
490 if (! request_region((__ret), (__size), (__name))) \
491 __ret = 0UL; \
492 (void __iomem *) __ret; \
493})
494
495#define sbus_iounmap(__addr, __size) \
496 release_region((unsigned long)(__addr), (__size))
497
498/*
499 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
500 * access
501 */
502#define xlate_dev_mem_ptr(p) __va(p)
503
504/*
505 * Convert a virtual cached pointer to an uncached pointer
506 */
507#define xlate_dev_kmem_ptr(p) p
508
509#endif
510
511#endif /* !(__SPARC64_IO_H) */
diff --git a/include/asm-sparc64/ioctl.h b/include/asm-sparc64/ioctl.h
index d634c21b4724..18fc5623ff51 100644
--- a/include/asm-sparc64/ioctl.h
+++ b/include/asm-sparc64/ioctl.h
@@ -1,67 +1 @@
1#ifndef _SPARC64_IOCTL_H #include <asm-sparc/ioctl.h>
2#define _SPARC64_IOCTL_H
3
4/*
5 * Our DIR and SIZE overlap in order to simulteneously provide
6 * a non-zero _IOC_NONE (for binary compatibility) and
7 * 14 bits of size as on i386. Here's the layout:
8 *
9 * 0xE0000000 DIR
10 * 0x80000000 DIR = WRITE
11 * 0x40000000 DIR = READ
12 * 0x20000000 DIR = NONE
13 * 0x3FFF0000 SIZE (overlaps NONE bit)
14 * 0x0000FF00 TYPE
15 * 0x000000FF NR (CMD)
16 */
17
18#define _IOC_NRBITS 8
19#define _IOC_TYPEBITS 8
20#define _IOC_SIZEBITS 13 /* Actually 14, see below. */
21#define _IOC_DIRBITS 3
22
23#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
24#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
25#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
26#define _IOC_XSIZEMASK ((1 << (_IOC_SIZEBITS+1))-1)
27#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
28
29#define _IOC_NRSHIFT 0
30#define _IOC_TYPESHIFT (_IOC_NRSHIFT + _IOC_NRBITS)
31#define _IOC_SIZESHIFT (_IOC_TYPESHIFT + _IOC_TYPEBITS)
32#define _IOC_DIRSHIFT (_IOC_SIZESHIFT + _IOC_SIZEBITS)
33
34#define _IOC_NONE 1U
35#define _IOC_READ 2U
36#define _IOC_WRITE 4U
37
38#define _IOC(dir,type,nr,size) \
39 (((dir) << _IOC_DIRSHIFT) | \
40 ((type) << _IOC_TYPESHIFT) | \
41 ((nr) << _IOC_NRSHIFT) | \
42 ((size) << _IOC_SIZESHIFT))
43
44#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
45#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
46#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
47#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
48
49/* Used to decode ioctl numbers in drivers despite the leading underscore... */
50#define _IOC_DIR(nr) \
51 ( (((((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) & (_IOC_WRITE|_IOC_READ)) != 0)? \
52 (((nr) >> _IOC_DIRSHIFT) & (_IOC_WRITE|_IOC_READ)): \
53 (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) )
54#define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
55#define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
56#define _IOC_SIZE(nr) \
57 ((((((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) & (_IOC_WRITE|_IOC_READ)) == 0)? \
58 0: (((nr) >> _IOC_SIZESHIFT) & _IOC_XSIZEMASK))
59
60/* ...and for the PCMCIA and sound. */
61#define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT)
62#define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT)
63#define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
64#define IOCSIZE_MASK (_IOC_XSIZEMASK << _IOC_SIZESHIFT)
65#define IOCSIZE_SHIFT (_IOC_SIZESHIFT)
66
67#endif /* !(_SPARC64_IOCTL_H) */
diff --git a/include/asm-sparc64/ioctls.h b/include/asm-sparc64/ioctls.h
index 94d1b75e512b..dcd5540ec103 100644
--- a/include/asm-sparc64/ioctls.h
+++ b/include/asm-sparc64/ioctls.h
@@ -1,136 +1 @@
1#ifndef _ASM_SPARC64_IOCTLS_H #include <asm-sparc/ioctls.h>
2#define _ASM_SPARC64_IOCTLS_H
3
4#include <asm/ioctl.h>
5
6/* Big T */
7#define TCGETA _IOR('T', 1, struct termio)
8#define TCSETA _IOW('T', 2, struct termio)
9#define TCSETAW _IOW('T', 3, struct termio)
10#define TCSETAF _IOW('T', 4, struct termio)
11#define TCSBRK _IO('T', 5)
12#define TCXONC _IO('T', 6)
13#define TCFLSH _IO('T', 7)
14#define TCGETS _IOR('T', 8, struct termios)
15#define TCSETS _IOW('T', 9, struct termios)
16#define TCSETSW _IOW('T', 10, struct termios)
17#define TCSETSF _IOW('T', 11, struct termios)
18#define TCGETS2 _IOR('T', 12, struct termios2)
19#define TCSETS2 _IOW('T', 13, struct termios2)
20#define TCSETSW2 _IOW('T', 14, struct termios2)
21#define TCSETSF2 _IOW('T', 15, struct termios2)
22
23/* Note that all the ioctls that are not available in Linux have a
24 * double underscore on the front to: a) avoid some programs to
25 * think we support some ioctls under Linux (autoconfiguration stuff)
26 */
27/* Little t */
28#define TIOCGETD _IOR('t', 0, int)
29#define TIOCSETD _IOW('t', 1, int)
30#define __TIOCHPCL _IO('t', 2) /* SunOS Specific */
31#define __TIOCMODG _IOR('t', 3, int) /* SunOS Specific */
32#define __TIOCMODS _IOW('t', 4, int) /* SunOS Specific */
33#define __TIOCGETP _IOR('t', 8, struct sgttyb) /* SunOS Specific */
34#define __TIOCSETP _IOW('t', 9, struct sgttyb) /* SunOS Specific */
35#define __TIOCSETN _IOW('t', 10, struct sgttyb) /* SunOS Specific */
36#define TIOCEXCL _IO('t', 13)
37#define TIOCNXCL _IO('t', 14)
38#define __TIOCFLUSH _IOW('t', 16, int) /* SunOS Specific */
39#define __TIOCSETC _IOW('t', 17, struct tchars) /* SunOS Specific */
40#define __TIOCGETC _IOR('t', 18, struct tchars) /* SunOS Specific */
41#define __TIOCTCNTL _IOW('t', 32, int) /* SunOS Specific */
42#define __TIOCSIGNAL _IOW('t', 33, int) /* SunOS Specific */
43#define __TIOCSETX _IOW('t', 34, int) /* SunOS Specific */
44#define __TIOCGETX _IOR('t', 35, int) /* SunOS Specific */
45#define TIOCCONS _IO('t', 36)
46#define TIOCGSOFTCAR _IOR('t', 100, int)
47#define TIOCSSOFTCAR _IOW('t', 101, int)
48#define __TIOCUCNTL _IOW('t', 102, int) /* SunOS Specific */
49#define TIOCSWINSZ _IOW('t', 103, struct winsize)
50#define TIOCGWINSZ _IOR('t', 104, struct winsize)
51#define __TIOCREMOTE _IOW('t', 105, int) /* SunOS Specific */
52#define TIOCMGET _IOR('t', 106, int)
53#define TIOCMBIC _IOW('t', 107, int)
54#define TIOCMBIS _IOW('t', 108, int)
55#define TIOCMSET _IOW('t', 109, int)
56#define TIOCSTART _IO('t', 110)
57#define TIOCSTOP _IO('t', 111)
58#define TIOCPKT _IOW('t', 112, int)
59#define TIOCNOTTY _IO('t', 113)
60#define TIOCSTI _IOW('t', 114, char)
61#define TIOCOUTQ _IOR('t', 115, int)
62#define __TIOCGLTC _IOR('t', 116, struct ltchars) /* SunOS Specific */
63#define __TIOCSLTC _IOW('t', 117, struct ltchars) /* SunOS Specific */
64/* 118 is the non-posix setpgrp tty ioctl */
65/* 119 is the non-posix getpgrp tty ioctl */
66#define __TIOCCDTR _IO('t', 120) /* SunOS Specific */
67#define __TIOCSDTR _IO('t', 121) /* SunOS Specific */
68#define TIOCCBRK _IO('t', 122)
69#define TIOCSBRK _IO('t', 123)
70#define __TIOCLGET _IOW('t', 124, int) /* SunOS Specific */
71#define __TIOCLSET _IOW('t', 125, int) /* SunOS Specific */
72#define __TIOCLBIC _IOW('t', 126, int) /* SunOS Specific */
73#define __TIOCLBIS _IOW('t', 127, int) /* SunOS Specific */
74#define __TIOCISPACE _IOR('t', 128, int) /* SunOS Specific */
75#define __TIOCISIZE _IOR('t', 129, int) /* SunOS Specific */
76#define TIOCSPGRP _IOW('t', 130, int)
77#define TIOCGPGRP _IOR('t', 131, int)
78#define TIOCSCTTY _IO('t', 132)
79#define TIOCGSID _IOR('t', 133, int)
80/* Get minor device of a pty master's FD -- Solaris equiv is ISPTM */
81#define TIOCGPTN _IOR('t', 134, unsigned int) /* Get Pty Number */
82#define TIOCSPTLCK _IOW('t', 135, int) /* Lock/unlock PTY */
83
84/* Little f */
85#define FIOCLEX _IO('f', 1)
86#define FIONCLEX _IO('f', 2)
87#define FIOASYNC _IOW('f', 125, int)
88#define FIONBIO _IOW('f', 126, int)
89#define FIONREAD _IOR('f', 127, int)
90#define TIOCINQ FIONREAD
91#define FIOQSIZE _IOR('f', 128, loff_t)
92
93/* SCARY Rutgers local SunOS kernel hackery, perhaps I will support it
94 * someday. This is completely bogus, I know...
95 */
96#define __TCGETSTAT _IO('T', 200) /* Rutgers specific */
97#define __TCSETSTAT _IO('T', 201) /* Rutgers specific */
98
99/* Linux specific, no SunOS equivalent. */
100#define TIOCLINUX 0x541C
101#define TIOCGSERIAL 0x541E
102#define TIOCSSERIAL 0x541F
103#define TCSBRKP 0x5425
104#define TIOCSERCONFIG 0x5453
105#define TIOCSERGWILD 0x5454
106#define TIOCSERSWILD 0x5455
107#define TIOCGLCKTRMIOS 0x5456
108#define TIOCSLCKTRMIOS 0x5457
109#define TIOCSERGSTRUCT 0x5458 /* For debugging only */
110#define TIOCSERGETLSR 0x5459 /* Get line status register */
111#define TIOCSERGETMULTI 0x545A /* Get multiport config */
112#define TIOCSERSETMULTI 0x545B /* Set multiport config */
113#define TIOCMIWAIT 0x545C /* Wait for change on serial input line(s) */
114#define TIOCGICOUNT 0x545D /* Read serial port inline interrupt counts */
115
116/* Kernel definitions */
117#ifdef __KERNEL__
118#define TIOCGETC __TIOCGETC
119#define TIOCGETP __TIOCGETP
120#define TIOCGLTC __TIOCGLTC
121#define TIOCSLTC __TIOCSLTC
122#define TIOCSETP __TIOCSETP
123#define TIOCSETN __TIOCSETN
124#define TIOCSETC __TIOCSETC
125#endif
126
127/* Used for packet mode */
128#define TIOCPKT_DATA 0
129#define TIOCPKT_FLUSHREAD 1
130#define TIOCPKT_FLUSHWRITE 2
131#define TIOCPKT_STOP 4
132#define TIOCPKT_START 8
133#define TIOCPKT_NOSTOP 16
134#define TIOCPKT_DOSTOP 32
135
136#endif /* !(_ASM_SPARC64_IOCTLS_H) */
diff --git a/include/asm-sparc64/iommu.h b/include/asm-sparc64/iommu.h
index d7b9afcba08b..76252bb85e97 100644
--- a/include/asm-sparc64/iommu.h
+++ b/include/asm-sparc64/iommu.h
@@ -1,62 +1 @@
1/* iommu.h: Definitions for the sun5 IOMMU. #include <asm-sparc/iommu.h>
2 *
3 * Copyright (C) 1996, 1999, 2007 David S. Miller (davem@davemloft.net)
4 */
5#ifndef _SPARC64_IOMMU_H
6#define _SPARC64_IOMMU_H
7
8/* The format of an iopte in the page tables. */
9#define IOPTE_VALID 0x8000000000000000UL
10#define IOPTE_64K 0x2000000000000000UL
11#define IOPTE_STBUF 0x1000000000000000UL
12#define IOPTE_INTRA 0x0800000000000000UL
13#define IOPTE_CONTEXT 0x07ff800000000000UL
14#define IOPTE_PAGE 0x00007fffffffe000UL
15#define IOPTE_CACHE 0x0000000000000010UL
16#define IOPTE_WRITE 0x0000000000000002UL
17
18#define IOMMU_NUM_CTXS 4096
19
20struct iommu_arena {
21 unsigned long *map;
22 unsigned int hint;
23 unsigned int limit;
24};
25
26struct iommu {
27 spinlock_t lock;
28 struct iommu_arena arena;
29 void (*flush_all)(struct iommu *);
30 iopte_t *page_table;
31 u32 page_table_map_base;
32 unsigned long iommu_control;
33 unsigned long iommu_tsbbase;
34 unsigned long iommu_flush;
35 unsigned long iommu_flushinv;
36 unsigned long iommu_tags;
37 unsigned long iommu_ctxflush;
38 unsigned long write_complete_reg;
39 unsigned long dummy_page;
40 unsigned long dummy_page_pa;
41 unsigned long ctx_lowest_free;
42 DECLARE_BITMAP(ctx_bitmap, IOMMU_NUM_CTXS);
43 u32 dma_addr_mask;
44};
45
46struct strbuf {
47 int strbuf_enabled;
48 unsigned long strbuf_control;
49 unsigned long strbuf_pflush;
50 unsigned long strbuf_fsync;
51 unsigned long strbuf_ctxflush;
52 unsigned long strbuf_ctxmatch_base;
53 unsigned long strbuf_flushflag_pa;
54 volatile unsigned long *strbuf_flushflag;
55 volatile unsigned long __flushflag_buf[(64+(64-1)) / sizeof(long)];
56};
57
58extern int iommu_table_init(struct iommu *iommu, int tsbsize,
59 u32 dma_offset, u32 dma_addr_mask,
60 int numa_node);
61
62#endif /* !(_SPARC64_IOMMU_H) */
diff --git a/include/asm-sparc64/ipcbuf.h b/include/asm-sparc64/ipcbuf.h
index 9c5bf1bc423f..41dfaf1149b5 100644
--- a/include/asm-sparc64/ipcbuf.h
+++ b/include/asm-sparc64/ipcbuf.h
@@ -1,28 +1 @@
1#ifndef _SPARC64_IPCBUF_H #include <asm-sparc/ipcbuf.h>
2#define _SPARC64_IPCBUF_H
3
4/*
5 * The ipc64_perm structure for sparc64 architecture.
6 * Note extra padding because this structure is passed back and forth
7 * between kernel and user space.
8 *
9 * Pad space is left for:
10 * - 32-bit seq
11 * - 2 miscellaneous 64-bit values
12 */
13
14struct ipc64_perm
15{
16 __kernel_key_t key;
17 __kernel_uid_t uid;
18 __kernel_gid_t gid;
19 __kernel_uid_t cuid;
20 __kernel_gid_t cgid;
21 __kernel_mode_t mode;
22 unsigned short __pad1;
23 unsigned short seq;
24 unsigned long __unused1;
25 unsigned long __unused2;
26};
27
28#endif /* _SPARC64_IPCBUF_H */
diff --git a/include/asm-sparc64/irq.h b/include/asm-sparc64/irq.h
index 0bb9bf531745..b2102e65947c 100644
--- a/include/asm-sparc64/irq.h
+++ b/include/asm-sparc64/irq.h
@@ -1,93 +1 @@
1/* irq.h: IRQ registers on the 64-bit Sparc. #include <asm-sparc/irq.h>
2 *
3 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz)
5 */
6
7#ifndef _SPARC64_IRQ_H
8#define _SPARC64_IRQ_H
9
10#include <linux/linkage.h>
11#include <linux/kernel.h>
12#include <linux/errno.h>
13#include <linux/interrupt.h>
14#include <asm/pil.h>
15#include <asm/ptrace.h>
16
17/* IMAP/ICLR register defines */
18#define IMAP_VALID 0x80000000UL /* IRQ Enabled */
19#define IMAP_TID_UPA 0x7c000000UL /* UPA TargetID */
20#define IMAP_TID_JBUS 0x7c000000UL /* JBUS TargetID */
21#define IMAP_TID_SHIFT 26
22#define IMAP_AID_SAFARI 0x7c000000UL /* Safari AgentID */
23#define IMAP_AID_SHIFT 26
24#define IMAP_NID_SAFARI 0x03e00000UL /* Safari NodeID */
25#define IMAP_NID_SHIFT 21
26#define IMAP_IGN 0x000007c0UL /* IRQ Group Number */
27#define IMAP_INO 0x0000003fUL /* IRQ Number */
28#define IMAP_INR 0x000007ffUL /* Full interrupt number*/
29
30#define ICLR_IDLE 0x00000000UL /* Idle state */
31#define ICLR_TRANSMIT 0x00000001UL /* Transmit state */
32#define ICLR_PENDING 0x00000003UL /* Pending state */
33
34/* The largest number of unique interrupt sources we support.
35 * If this needs to ever be larger than 255, you need to change
36 * the type of ino_bucket->virt_irq as appropriate.
37 *
38 * ino_bucket->virt_irq allocation is made during {sun4v_,}build_irq().
39 */
40#define NR_IRQS 255
41
42extern void irq_install_pre_handler(int virt_irq,
43 void (*func)(unsigned int, void *, void *),
44 void *arg1, void *arg2);
45#define irq_canonicalize(irq) (irq)
46extern unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap);
47extern unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino);
48extern unsigned int sun4v_build_virq(u32 devhandle, unsigned int devino);
49extern unsigned int sun4v_build_msi(u32 devhandle, unsigned int *virt_irq_p,
50 unsigned int msi_devino_start,
51 unsigned int msi_devino_end);
52extern void sun4v_destroy_msi(unsigned int virt_irq);
53extern unsigned int sun4u_build_msi(u32 portid, unsigned int *virt_irq_p,
54 unsigned int msi_devino_start,
55 unsigned int msi_devino_end,
56 unsigned long imap_base,
57 unsigned long iclr_base);
58extern void sun4u_destroy_msi(unsigned int virt_irq);
59extern unsigned int sbus_build_irq(void *sbus, unsigned int ino);
60
61extern unsigned char virt_irq_alloc(unsigned int dev_handle,
62 unsigned int dev_ino);
63#ifdef CONFIG_PCI_MSI
64extern void virt_irq_free(unsigned int virt_irq);
65#endif
66
67extern void __init init_IRQ(void);
68extern void fixup_irqs(void);
69
70static inline void set_softint(unsigned long bits)
71{
72 __asm__ __volatile__("wr %0, 0x0, %%set_softint"
73 : /* No outputs */
74 : "r" (bits));
75}
76
77static inline void clear_softint(unsigned long bits)
78{
79 __asm__ __volatile__("wr %0, 0x0, %%clear_softint"
80 : /* No outputs */
81 : "r" (bits));
82}
83
84static inline unsigned long get_softint(void)
85{
86 unsigned long retval;
87
88 __asm__ __volatile__("rd %%softint, %0"
89 : "=r" (retval));
90 return retval;
91}
92
93#endif
diff --git a/include/asm-sparc64/irq_regs.h b/include/asm-sparc64/irq_regs.h
index 3dd9c0b70270..1e2b8a1e745a 100644
--- a/include/asm-sparc64/irq_regs.h
+++ b/include/asm-sparc64/irq_regs.h
@@ -1 +1 @@
#include <asm-generic/irq_regs.h> #include <asm-sparc/irq_regs.h>
diff --git a/include/asm-sparc64/irqflags.h b/include/asm-sparc64/irqflags.h
index 024fc54d0682..27b091fc3fa0 100644
--- a/include/asm-sparc64/irqflags.h
+++ b/include/asm-sparc64/irqflags.h
@@ -1,89 +1 @@
1/* #include <asm-sparc/irqflags.h>
2 * include/asm-sparc64/irqflags.h
3 *
4 * IRQ flags handling
5 *
6 * This file gets included from lowlevel asm headers too, to provide
7 * wrapped versions of the local_irq_*() APIs, based on the
8 * raw_local_irq_*() functions from the lowlevel headers.
9 */
10#ifndef _ASM_IRQFLAGS_H
11#define _ASM_IRQFLAGS_H
12
13#ifndef __ASSEMBLY__
14
15static inline unsigned long __raw_local_save_flags(void)
16{
17 unsigned long flags;
18
19 __asm__ __volatile__(
20 "rdpr %%pil, %0"
21 : "=r" (flags)
22 );
23
24 return flags;
25}
26
27#define raw_local_save_flags(flags) \
28 do { (flags) = __raw_local_save_flags(); } while (0)
29
30static inline void raw_local_irq_restore(unsigned long flags)
31{
32 __asm__ __volatile__(
33 "wrpr %0, %%pil"
34 : /* no output */
35 : "r" (flags)
36 : "memory"
37 );
38}
39
40static inline void raw_local_irq_disable(void)
41{
42 __asm__ __volatile__(
43 "wrpr 15, %%pil"
44 : /* no outputs */
45 : /* no inputs */
46 : "memory"
47 );
48}
49
50static inline void raw_local_irq_enable(void)
51{
52 __asm__ __volatile__(
53 "wrpr 0, %%pil"
54 : /* no outputs */
55 : /* no inputs */
56 : "memory"
57 );
58}
59
60static inline int raw_irqs_disabled_flags(unsigned long flags)
61{
62 return (flags > 0);
63}
64
65static inline int raw_irqs_disabled(void)
66{
67 unsigned long flags = __raw_local_save_flags();
68
69 return raw_irqs_disabled_flags(flags);
70}
71
72/*
73 * For spinlocks, etc:
74 */
75static inline unsigned long __raw_local_irq_save(void)
76{
77 unsigned long flags = __raw_local_save_flags();
78
79 raw_local_irq_disable();
80
81 return flags;
82}
83
84#define raw_local_irq_save(flags) \
85 do { (flags) = __raw_local_irq_save(); } while (0)
86
87#endif /* (__ASSEMBLY__) */
88
89#endif /* !(_ASM_IRQFLAGS_H) */
diff --git a/include/asm-sparc64/kdebug.h b/include/asm-sparc64/kdebug.h
index f905b773235a..78cfd5d2749b 100644
--- a/include/asm-sparc64/kdebug.h
+++ b/include/asm-sparc64/kdebug.h
@@ -1,19 +1 @@
1#ifndef _SPARC64_KDEBUG_H #include <asm-sparc/kdebug.h>
2#define _SPARC64_KDEBUG_H
3
4struct pt_regs;
5
6extern void bad_trap(struct pt_regs *, long);
7
8/* Grossly misnamed. */
9enum die_val {
10 DIE_OOPS = 1,
11 DIE_DEBUG, /* ta 0x70 */
12 DIE_DEBUG_2, /* ta 0x71 */
13 DIE_DIE,
14 DIE_TRAP,
15 DIE_TRAP_TL1,
16 DIE_CALL,
17};
18
19#endif
diff --git a/include/asm-sparc64/kmap_types.h b/include/asm-sparc64/kmap_types.h
index 34c1d3d9a3b0..276530cf5395 100644
--- a/include/asm-sparc64/kmap_types.h
+++ b/include/asm-sparc64/kmap_types.h
@@ -1,25 +1 @@
1#ifndef _ASM_KMAP_TYPES_H #include <asm-sparc/kmap_types.h>
2#define _ASM_KMAP_TYPES_H
3
4/* Dummy header just to define km_type. None of this
5 * is actually used on sparc64. -DaveM
6 */
7
8enum km_type {
9 KM_BOUNCE_READ,
10 KM_SKB_SUNRPC_DATA,
11 KM_SKB_DATA_SOFTIRQ,
12 KM_USER0,
13 KM_USER1,
14 KM_BIO_SRC_IRQ,
15 KM_BIO_DST_IRQ,
16 KM_PTE0,
17 KM_PTE1,
18 KM_IRQ0,
19 KM_IRQ1,
20 KM_SOFTIRQ0,
21 KM_SOFTIRQ1,
22 KM_TYPE_NR
23};
24
25#endif
diff --git a/include/asm-sparc64/kprobes.h b/include/asm-sparc64/kprobes.h
index 5879d71afdaa..c55e43e4d2a4 100644
--- a/include/asm-sparc64/kprobes.h
+++ b/include/asm-sparc64/kprobes.h
@@ -1,49 +1 @@
1#ifndef _SPARC64_KPROBES_H #include <asm-sparc/kprobes.h>
2#define _SPARC64_KPROBES_H
3
4#include <linux/types.h>
5#include <linux/percpu.h>
6
7typedef u32 kprobe_opcode_t;
8
9#define BREAKPOINT_INSTRUCTION 0x91d02070 /* ta 0x70 */
10#define BREAKPOINT_INSTRUCTION_2 0x91d02071 /* ta 0x71 */
11#define MAX_INSN_SIZE 2
12
13#define kretprobe_blacklist_size 0
14
15#define arch_remove_kprobe(p) do {} while (0)
16
17#define flush_insn_slot(p) \
18do { flushi(&(p)->ainsn.insn[0]); \
19 flushi(&(p)->ainsn.insn[1]); \
20} while (0)
21
22void kretprobe_trampoline(void);
23
24/* Architecture specific copy of original instruction*/
25struct arch_specific_insn {
26 /* copy of the original instruction */
27 kprobe_opcode_t insn[MAX_INSN_SIZE];
28};
29
30struct prev_kprobe {
31 struct kprobe *kp;
32 unsigned long status;
33 unsigned long orig_tnpc;
34 unsigned long orig_tstate_pil;
35};
36
37/* per-cpu kprobe control block */
38struct kprobe_ctlblk {
39 unsigned long kprobe_status;
40 unsigned long kprobe_orig_tnpc;
41 unsigned long kprobe_orig_tstate_pil;
42 struct pt_regs jprobe_saved_regs;
43 struct prev_kprobe prev_kprobe;
44};
45
46extern int kprobe_exceptions_notify(struct notifier_block *self,
47 unsigned long val, void *data);
48extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
49#endif /* _SPARC64_KPROBES_H */
diff --git a/include/asm-sparc64/kvm.h b/include/asm-sparc64/kvm.h
index 380537a77bf9..53564ad86b15 100644
--- a/include/asm-sparc64/kvm.h
+++ b/include/asm-sparc64/kvm.h
@@ -1,6 +1 @@
1#ifndef __LINUX_KVM_SPARC64_H #include <asm-sparc/kvm.h>
2#define __LINUX_KVM_SPARC64_H
3
4/* sparc64 does not support KVM */
5
6#endif
diff --git a/include/asm-sparc64/ldc.h b/include/asm-sparc64/ldc.h
index bdb524a7b814..40f3f231c457 100644
--- a/include/asm-sparc64/ldc.h
+++ b/include/asm-sparc64/ldc.h
@@ -1,138 +1 @@
1#ifndef _SPARC64_LDC_H #include <asm-sparc/ldc.h>
2#define _SPARC64_LDC_H
3
4#include <asm/hypervisor.h>
5
6extern int ldom_domaining_enabled;
7extern void ldom_set_var(const char *var, const char *value);
8extern void ldom_reboot(const char *boot_command);
9extern void ldom_power_off(void);
10
11/* The event handler will be evoked when link state changes
12 * or data becomes available on the receive side.
13 *
14 * For non-RAW links, if the LDC_EVENT_RESET event arrives the
15 * driver should reset all of it's internal state and reinvoke
16 * ldc_connect() to try and bring the link up again.
17 *
18 * For RAW links, ldc_connect() is not used. Instead the driver
19 * just waits for the LDC_EVENT_UP event.
20 */
21struct ldc_channel_config {
22 void (*event)(void *arg, int event);
23
24 u32 mtu;
25 unsigned int rx_irq;
26 unsigned int tx_irq;
27 u8 mode;
28#define LDC_MODE_RAW 0x00
29#define LDC_MODE_UNRELIABLE 0x01
30#define LDC_MODE_RESERVED 0x02
31#define LDC_MODE_STREAM 0x03
32
33 u8 debug;
34#define LDC_DEBUG_HS 0x01
35#define LDC_DEBUG_STATE 0x02
36#define LDC_DEBUG_RX 0x04
37#define LDC_DEBUG_TX 0x08
38#define LDC_DEBUG_DATA 0x10
39};
40
41#define LDC_EVENT_RESET 0x01
42#define LDC_EVENT_UP 0x02
43#define LDC_EVENT_DATA_READY 0x04
44
45#define LDC_STATE_INVALID 0x00
46#define LDC_STATE_INIT 0x01
47#define LDC_STATE_BOUND 0x02
48#define LDC_STATE_READY 0x03
49#define LDC_STATE_CONNECTED 0x04
50
51struct ldc_channel;
52
53/* Allocate state for a channel. */
54extern struct ldc_channel *ldc_alloc(unsigned long id,
55 const struct ldc_channel_config *cfgp,
56 void *event_arg);
57
58/* Shut down and free state for a channel. */
59extern void ldc_free(struct ldc_channel *lp);
60
61/* Register TX and RX queues of the link with the hypervisor. */
62extern int ldc_bind(struct ldc_channel *lp, const char *name);
63
64/* For non-RAW protocols we need to complete a handshake before
65 * communication can proceed. ldc_connect() does that, if the
66 * handshake completes successfully, an LDC_EVENT_UP event will
67 * be sent up to the driver.
68 */
69extern int ldc_connect(struct ldc_channel *lp);
70extern int ldc_disconnect(struct ldc_channel *lp);
71
72extern int ldc_state(struct ldc_channel *lp);
73
74/* Read and write operations. Only valid when the link is up. */
75extern int ldc_write(struct ldc_channel *lp, const void *buf,
76 unsigned int size);
77extern int ldc_read(struct ldc_channel *lp, void *buf, unsigned int size);
78
79#define LDC_MAP_SHADOW 0x01
80#define LDC_MAP_DIRECT 0x02
81#define LDC_MAP_IO 0x04
82#define LDC_MAP_R 0x08
83#define LDC_MAP_W 0x10
84#define LDC_MAP_X 0x20
85#define LDC_MAP_RW (LDC_MAP_R | LDC_MAP_W)
86#define LDC_MAP_RWX (LDC_MAP_R | LDC_MAP_W | LDC_MAP_X)
87#define LDC_MAP_ALL 0x03f
88
89struct ldc_trans_cookie {
90 u64 cookie_addr;
91 u64 cookie_size;
92};
93
94struct scatterlist;
95extern int ldc_map_sg(struct ldc_channel *lp,
96 struct scatterlist *sg, int num_sg,
97 struct ldc_trans_cookie *cookies, int ncookies,
98 unsigned int map_perm);
99
100extern int ldc_map_single(struct ldc_channel *lp,
101 void *buf, unsigned int len,
102 struct ldc_trans_cookie *cookies, int ncookies,
103 unsigned int map_perm);
104
105extern void ldc_unmap(struct ldc_channel *lp, struct ldc_trans_cookie *cookies,
106 int ncookies);
107
108extern int ldc_copy(struct ldc_channel *lp, int copy_dir,
109 void *buf, unsigned int len, unsigned long offset,
110 struct ldc_trans_cookie *cookies, int ncookies);
111
112static inline int ldc_get_dring_entry(struct ldc_channel *lp,
113 void *buf, unsigned int len,
114 unsigned long offset,
115 struct ldc_trans_cookie *cookies,
116 int ncookies)
117{
118 return ldc_copy(lp, LDC_COPY_IN, buf, len, offset, cookies, ncookies);
119}
120
121static inline int ldc_put_dring_entry(struct ldc_channel *lp,
122 void *buf, unsigned int len,
123 unsigned long offset,
124 struct ldc_trans_cookie *cookies,
125 int ncookies)
126{
127 return ldc_copy(lp, LDC_COPY_OUT, buf, len, offset, cookies, ncookies);
128}
129
130extern void *ldc_alloc_exp_dring(struct ldc_channel *lp, unsigned int len,
131 struct ldc_trans_cookie *cookies,
132 int *ncookies, unsigned int map_perm);
133
134extern void ldc_free_exp_dring(struct ldc_channel *lp, void *buf,
135 unsigned int len,
136 struct ldc_trans_cookie *cookies, int ncookies);
137
138#endif /* _SPARC64_LDC_H */
diff --git a/include/asm-sparc64/linkage.h b/include/asm-sparc64/linkage.h
index 291c2d01c44f..3ea4fd13f193 100644
--- a/include/asm-sparc64/linkage.h
+++ b/include/asm-sparc64/linkage.h
@@ -1,6 +1 @@
1#ifndef __ASM_LINKAGE_H #include <asm-sparc/linkage.h>
2#define __ASM_LINKAGE_H
3
4/* Nothing to see here... */
5
6#endif
diff --git a/include/asm-sparc64/lmb.h b/include/asm-sparc64/lmb.h
index 6a352cbcf520..3d04981701e2 100644
--- a/include/asm-sparc64/lmb.h
+++ b/include/asm-sparc64/lmb.h
@@ -1,10 +1 @@
1#ifndef _SPARC64_LMB_H #include <asm-sparc/lmb.h>
2#define _SPARC64_LMB_H
3
4#include <asm/oplib.h>
5
6#define LMB_DBG(fmt...) prom_printf(fmt)
7
8#define LMB_REAL_LIMIT 0
9
10#endif /* !(_SPARC64_LMB_H) */
diff --git a/include/asm-sparc64/lsu.h b/include/asm-sparc64/lsu.h
index 7190f8de90a0..4e3d8b128a58 100644
--- a/include/asm-sparc64/lsu.h
+++ b/include/asm-sparc64/lsu.h
@@ -1,19 +1 @@
1#ifndef _SPARC64_LSU_H #include <asm-sparc/lsu.h>
2#define _SPARC64_LSU_H
3
4#include <linux/const.h>
5
6/* LSU Control Register */
7#define LSU_CONTROL_PM _AC(0x000001fe00000000,UL) /* Phys-watchpoint byte mask*/
8#define LSU_CONTROL_VM _AC(0x00000001fe000000,UL) /* Virt-watchpoint byte mask*/
9#define LSU_CONTROL_PR _AC(0x0000000001000000,UL) /* Phys-rd watchpoint enable*/
10#define LSU_CONTROL_PW _AC(0x0000000000800000,UL) /* Phys-wr watchpoint enable*/
11#define LSU_CONTROL_VR _AC(0x0000000000400000,UL) /* Virt-rd watchpoint enable*/
12#define LSU_CONTROL_VW _AC(0x0000000000200000,UL) /* Virt-wr watchpoint enable*/
13#define LSU_CONTROL_FM _AC(0x00000000000ffff0,UL) /* Parity mask enables. */
14#define LSU_CONTROL_DM _AC(0x0000000000000008,UL) /* Data MMU enable. */
15#define LSU_CONTROL_IM _AC(0x0000000000000004,UL) /* Instruction MMU enable. */
16#define LSU_CONTROL_DC _AC(0x0000000000000002,UL) /* Data cache enable. */
17#define LSU_CONTROL_IC _AC(0x0000000000000001,UL) /* Instruction cache enable.*/
18
19#endif /* !(_SPARC64_LSU_H) */
diff --git a/include/asm-sparc64/mc146818rtc.h b/include/asm-sparc64/mc146818rtc.h
index e9c0fcc25c6f..97842e6ed1c2 100644
--- a/include/asm-sparc64/mc146818rtc.h
+++ b/include/asm-sparc64/mc146818rtc.h
@@ -1,34 +1 @@
1/* #include <asm-sparc/mc146818rtc.h>
2 * Machine dependent access functions for RTC registers.
3 */
4#ifndef __ASM_SPARC64_MC146818RTC_H
5#define __ASM_SPARC64_MC146818RTC_H
6
7#include <asm/io.h>
8
9#ifndef RTC_PORT
10#ifdef CONFIG_PCI
11extern unsigned long ds1287_regs;
12#else
13#define ds1287_regs (0UL)
14#endif
15#define RTC_PORT(x) (ds1287_regs + (x))
16#define RTC_ALWAYS_BCD 0
17#endif
18
19/*
20 * The yet supported machines all access the RTC index register via
21 * an ISA port access but the way to access the date register differs ...
22 */
23#define CMOS_READ(addr) ({ \
24outb_p((addr),RTC_PORT(0)); \
25inb_p(RTC_PORT(1)); \
26})
27#define CMOS_WRITE(val, addr) ({ \
28outb_p((addr),RTC_PORT(0)); \
29outb_p((val),RTC_PORT(1)); \
30})
31
32#define RTC_IRQ 8
33
34#endif /* __ASM_SPARC64_MC146818RTC_H */
diff --git a/include/asm-sparc64/mdesc.h b/include/asm-sparc64/mdesc.h
index 1acc7272e537..165a19347286 100644
--- a/include/asm-sparc64/mdesc.h
+++ b/include/asm-sparc64/mdesc.h
@@ -1,78 +1 @@
1#ifndef _SPARC64_MDESC_H #include <asm-sparc/mdesc.h>
2#define _SPARC64_MDESC_H
3
4#include <linux/types.h>
5#include <linux/cpumask.h>
6#include <asm/prom.h>
7
8struct mdesc_handle;
9
10/* Machine description operations are to be surrounded by grab and
11 * release calls. The mdesc_handle returned from the grab is
12 * the first argument to all of the operational calls that work
13 * on mdescs.
14 */
15extern struct mdesc_handle *mdesc_grab(void);
16extern void mdesc_release(struct mdesc_handle *);
17
18#define MDESC_NODE_NULL (~(u64)0)
19
20extern u64 mdesc_node_by_name(struct mdesc_handle *handle,
21 u64 from_node, const char *name);
22#define mdesc_for_each_node_by_name(__hdl, __node, __name) \
23 for (__node = mdesc_node_by_name(__hdl, MDESC_NODE_NULL, __name); \
24 (__node) != MDESC_NODE_NULL; \
25 __node = mdesc_node_by_name(__hdl, __node, __name))
26
27/* Access to property values returned from mdesc_get_property() are
28 * only valid inside of a mdesc_grab()/mdesc_release() sequence.
29 * Once mdesc_release() is called, the memory backed up by these
30 * pointers may reference freed up memory.
31 *
32 * Therefore callers must make copies of any property values
33 * they need.
34 *
35 * These same rules apply to mdesc_node_name().
36 */
37extern const void *mdesc_get_property(struct mdesc_handle *handle,
38 u64 node, const char *name, int *lenp);
39extern const char *mdesc_node_name(struct mdesc_handle *hp, u64 node);
40
41/* MD arc iteration, the standard sequence is:
42 *
43 * unsigned long arc;
44 * mdesc_for_each_arc(arc, handle, node, MDESC_ARC_TYPE_{FWD,BACK}) {
45 * unsigned long target = mdesc_arc_target(handle, arc);
46 * ...
47 * }
48 */
49
50#define MDESC_ARC_TYPE_FWD "fwd"
51#define MDESC_ARC_TYPE_BACK "back"
52
53extern u64 mdesc_next_arc(struct mdesc_handle *handle, u64 from,
54 const char *arc_type);
55#define mdesc_for_each_arc(__arc, __hdl, __node, __type) \
56 for (__arc = mdesc_next_arc(__hdl, __node, __type); \
57 (__arc) != MDESC_NODE_NULL; \
58 __arc = mdesc_next_arc(__hdl, __arc, __type))
59
60extern u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc);
61
62extern void mdesc_update(void);
63
64struct mdesc_notifier_client {
65 void (*add)(struct mdesc_handle *handle, u64 node);
66 void (*remove)(struct mdesc_handle *handle, u64 node);
67
68 const char *node_name;
69 struct mdesc_notifier_client *next;
70};
71
72extern void mdesc_register_notifier(struct mdesc_notifier_client *client);
73
74extern void mdesc_fill_in_cpu_data(cpumask_t mask);
75
76extern void sun4v_mdesc_init(void);
77
78#endif
diff --git a/include/asm-sparc64/mman.h b/include/asm-sparc64/mman.h
index d2ae67cd1bdc..17ddb1724f51 100644
--- a/include/asm-sparc64/mman.h
+++ b/include/asm-sparc64/mman.h
@@ -1,31 +1 @@
1#ifndef __SPARC64_MMAN_H__ #include <asm-sparc/mman.h>
2#define __SPARC64_MMAN_H__
3
4#include <asm-generic/mman.h>
5
6/* SunOS'ified... */
7
8#define MAP_RENAME MAP_ANONYMOUS /* In SunOS terminology */
9#define MAP_NORESERVE 0x40 /* don't reserve swap pages */
10#define MAP_INHERIT 0x80 /* SunOS doesn't do this, but... */
11#define MAP_LOCKED 0x100 /* lock the mapping */
12#define _MAP_NEW 0x80000000 /* Binary compatibility is fun... */
13
14#define MAP_GROWSDOWN 0x0200 /* stack-like segment */
15#define MAP_DENYWRITE 0x0800 /* ETXTBSY */
16#define MAP_EXECUTABLE 0x1000 /* mark it as an executable */
17
18#define MCL_CURRENT 0x2000 /* lock all currently mapped pages */
19#define MCL_FUTURE 0x4000 /* lock all additions to address space */
20
21#define MAP_POPULATE 0x8000 /* populate (prefault) pagetables */
22#define MAP_NONBLOCK 0x10000 /* do not block on IO */
23
24#ifdef __KERNEL__
25#ifndef __ASSEMBLY__
26#define arch_mmap_check(addr,len,flags) sparc64_mmap_check(addr,len)
27int sparc64_mmap_check(unsigned long addr, unsigned long len);
28#endif
29#endif
30
31#endif /* __SPARC64_MMAN_H__ */
diff --git a/include/asm-sparc64/mmu.h b/include/asm-sparc64/mmu.h
index 8abc58f0f9d7..e677a64d8db1 100644
--- a/include/asm-sparc64/mmu.h
+++ b/include/asm-sparc64/mmu.h
@@ -1,127 +1 @@
1#ifndef __MMU_H #include <asm-sparc/mmu.h>
2#define __MMU_H
3
4#include <linux/const.h>
5#include <asm/page.h>
6#include <asm/hypervisor.h>
7
8#define CTX_NR_BITS 13
9
10#define TAG_CONTEXT_BITS ((_AC(1,UL) << CTX_NR_BITS) - _AC(1,UL))
11
12/* UltraSPARC-III+ and later have a feature whereby you can
13 * select what page size the various Data-TLB instances in the
14 * chip. In order to gracefully support this, we put the version
15 * field in a spot outside of the areas of the context register
16 * where this parameter is specified.
17 */
18#define CTX_VERSION_SHIFT 22
19#define CTX_VERSION_MASK ((~0UL) << CTX_VERSION_SHIFT)
20
21#define CTX_PGSZ_8KB _AC(0x0,UL)
22#define CTX_PGSZ_64KB _AC(0x1,UL)
23#define CTX_PGSZ_512KB _AC(0x2,UL)
24#define CTX_PGSZ_4MB _AC(0x3,UL)
25#define CTX_PGSZ_BITS _AC(0x7,UL)
26#define CTX_PGSZ0_NUC_SHIFT 61
27#define CTX_PGSZ1_NUC_SHIFT 58
28#define CTX_PGSZ0_SHIFT 16
29#define CTX_PGSZ1_SHIFT 19
30#define CTX_PGSZ_MASK ((CTX_PGSZ_BITS << CTX_PGSZ0_SHIFT) | \
31 (CTX_PGSZ_BITS << CTX_PGSZ1_SHIFT))
32
33#if defined(CONFIG_SPARC64_PAGE_SIZE_8KB)
34#define CTX_PGSZ_BASE CTX_PGSZ_8KB
35#elif defined(CONFIG_SPARC64_PAGE_SIZE_64KB)
36#define CTX_PGSZ_BASE CTX_PGSZ_64KB
37#elif defined(CONFIG_SPARC64_PAGE_SIZE_512KB)
38#define CTX_PGSZ_BASE CTX_PGSZ_512KB
39#elif defined(CONFIG_SPARC64_PAGE_SIZE_4MB)
40#define CTX_PGSZ_BASE CTX_PGSZ_4MB
41#else
42#error No page size specified in kernel configuration
43#endif
44
45#if defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
46#define CTX_PGSZ_HUGE CTX_PGSZ_4MB
47#elif defined(CONFIG_HUGETLB_PAGE_SIZE_512K)
48#define CTX_PGSZ_HUGE CTX_PGSZ_512KB
49#elif defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
50#define CTX_PGSZ_HUGE CTX_PGSZ_64KB
51#endif
52
53#define CTX_PGSZ_KERN CTX_PGSZ_4MB
54
55/* Thus, when running on UltraSPARC-III+ and later, we use the following
56 * PRIMARY_CONTEXT register values for the kernel context.
57 */
58#define CTX_CHEETAH_PLUS_NUC \
59 ((CTX_PGSZ_KERN << CTX_PGSZ0_NUC_SHIFT) | \
60 (CTX_PGSZ_BASE << CTX_PGSZ1_NUC_SHIFT))
61
62#define CTX_CHEETAH_PLUS_CTX0 \
63 ((CTX_PGSZ_KERN << CTX_PGSZ0_SHIFT) | \
64 (CTX_PGSZ_BASE << CTX_PGSZ1_SHIFT))
65
66/* If you want "the TLB context number" use CTX_NR_MASK. If you
67 * want "the bits I program into the context registers" use
68 * CTX_HW_MASK.
69 */
70#define CTX_NR_MASK TAG_CONTEXT_BITS
71#define CTX_HW_MASK (CTX_NR_MASK | CTX_PGSZ_MASK)
72
73#define CTX_FIRST_VERSION ((_AC(1,UL) << CTX_VERSION_SHIFT) + _AC(1,UL))
74#define CTX_VALID(__ctx) \
75 (!(((__ctx.sparc64_ctx_val) ^ tlb_context_cache) & CTX_VERSION_MASK))
76#define CTX_HWBITS(__ctx) ((__ctx.sparc64_ctx_val) & CTX_HW_MASK)
77#define CTX_NRBITS(__ctx) ((__ctx.sparc64_ctx_val) & CTX_NR_MASK)
78
79#ifndef __ASSEMBLY__
80
81#define TSB_ENTRY_ALIGNMENT 16
82
83struct tsb {
84 unsigned long tag;
85 unsigned long pte;
86} __attribute__((aligned(TSB_ENTRY_ALIGNMENT)));
87
88extern void __tsb_insert(unsigned long ent, unsigned long tag, unsigned long pte);
89extern void tsb_flush(unsigned long ent, unsigned long tag);
90extern void tsb_init(struct tsb *tsb, unsigned long size);
91
92struct tsb_config {
93 struct tsb *tsb;
94 unsigned long tsb_rss_limit;
95 unsigned long tsb_nentries;
96 unsigned long tsb_reg_val;
97 unsigned long tsb_map_vaddr;
98 unsigned long tsb_map_pte;
99};
100
101#define MM_TSB_BASE 0
102
103#ifdef CONFIG_HUGETLB_PAGE
104#define MM_TSB_HUGE 1
105#define MM_NUM_TSBS 2
106#else
107#define MM_NUM_TSBS 1
108#endif
109
110typedef struct {
111 spinlock_t lock;
112 unsigned long sparc64_ctx_val;
113 unsigned long huge_pte_count;
114 struct tsb_config tsb_block[MM_NUM_TSBS];
115 struct hv_tsb_descr tsb_descr[MM_NUM_TSBS];
116} mm_context_t;
117
118#endif /* !__ASSEMBLY__ */
119
120#define TSB_CONFIG_TSB 0x00
121#define TSB_CONFIG_RSS_LIMIT 0x08
122#define TSB_CONFIG_NENTRIES 0x10
123#define TSB_CONFIG_REG_VAL 0x18
124#define TSB_CONFIG_MAP_VADDR 0x20
125#define TSB_CONFIG_MAP_PTE 0x28
126
127#endif /* __MMU_H */
diff --git a/include/asm-sparc64/mmu_context.h b/include/asm-sparc64/mmu_context.h
index 5693ab482606..877fee94bd4e 100644
--- a/include/asm-sparc64/mmu_context.h
+++ b/include/asm-sparc64/mmu_context.h
@@ -1,155 +1 @@
1#ifndef __SPARC64_MMU_CONTEXT_H #include <asm-sparc/mmu_context.h>
2#define __SPARC64_MMU_CONTEXT_H
3
4/* Derived heavily from Linus's Alpha/AXP ASN code... */
5
6#ifndef __ASSEMBLY__
7
8#include <linux/spinlock.h>
9#include <asm/system.h>
10#include <asm/spitfire.h>
11#include <asm-generic/mm_hooks.h>
12
13static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
14{
15}
16
17extern spinlock_t ctx_alloc_lock;
18extern unsigned long tlb_context_cache;
19extern unsigned long mmu_context_bmap[];
20
21extern void get_new_mmu_context(struct mm_struct *mm);
22#ifdef CONFIG_SMP
23extern void smp_new_mmu_context_version(void);
24#else
25#define smp_new_mmu_context_version() do { } while (0)
26#endif
27
28extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
29extern void destroy_context(struct mm_struct *mm);
30
31extern void __tsb_context_switch(unsigned long pgd_pa,
32 struct tsb_config *tsb_base,
33 struct tsb_config *tsb_huge,
34 unsigned long tsb_descr_pa);
35
36static inline void tsb_context_switch(struct mm_struct *mm)
37{
38 __tsb_context_switch(__pa(mm->pgd),
39 &mm->context.tsb_block[0],
40#ifdef CONFIG_HUGETLB_PAGE
41 (mm->context.tsb_block[1].tsb ?
42 &mm->context.tsb_block[1] :
43 NULL)
44#else
45 NULL
46#endif
47 , __pa(&mm->context.tsb_descr[0]));
48}
49
50extern void tsb_grow(struct mm_struct *mm, unsigned long tsb_index, unsigned long mm_rss);
51#ifdef CONFIG_SMP
52extern void smp_tsb_sync(struct mm_struct *mm);
53#else
54#define smp_tsb_sync(__mm) do { } while (0)
55#endif
56
57/* Set MMU context in the actual hardware. */
58#define load_secondary_context(__mm) \
59 __asm__ __volatile__( \
60 "\n661: stxa %0, [%1] %2\n" \
61 " .section .sun4v_1insn_patch, \"ax\"\n" \
62 " .word 661b\n" \
63 " stxa %0, [%1] %3\n" \
64 " .previous\n" \
65 " flush %%g6\n" \
66 : /* No outputs */ \
67 : "r" (CTX_HWBITS((__mm)->context)), \
68 "r" (SECONDARY_CONTEXT), "i" (ASI_DMMU), "i" (ASI_MMU))
69
70extern void __flush_tlb_mm(unsigned long, unsigned long);
71
72/* Switch the current MM context. Interrupts are disabled. */
73static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk)
74{
75 unsigned long ctx_valid, flags;
76 int cpu;
77
78 if (unlikely(mm == &init_mm))
79 return;
80
81 spin_lock_irqsave(&mm->context.lock, flags);
82 ctx_valid = CTX_VALID(mm->context);
83 if (!ctx_valid)
84 get_new_mmu_context(mm);
85
86 /* We have to be extremely careful here or else we will miss
87 * a TSB grow if we switch back and forth between a kernel
88 * thread and an address space which has it's TSB size increased
89 * on another processor.
90 *
91 * It is possible to play some games in order to optimize the
92 * switch, but the safest thing to do is to unconditionally
93 * perform the secondary context load and the TSB context switch.
94 *
95 * For reference the bad case is, for address space "A":
96 *
97 * CPU 0 CPU 1
98 * run address space A
99 * set cpu0's bits in cpu_vm_mask
100 * switch to kernel thread, borrow
101 * address space A via entry_lazy_tlb
102 * run address space A
103 * set cpu1's bit in cpu_vm_mask
104 * flush_tlb_pending()
105 * reset cpu_vm_mask to just cpu1
106 * TSB grow
107 * run address space A
108 * context was valid, so skip
109 * TSB context switch
110 *
111 * At that point cpu0 continues to use a stale TSB, the one from
112 * before the TSB grow performed on cpu1. cpu1 did not cross-call
113 * cpu0 to update it's TSB because at that point the cpu_vm_mask
114 * only had cpu1 set in it.
115 */
116 load_secondary_context(mm);
117 tsb_context_switch(mm);
118
119 /* Any time a processor runs a context on an address space
120 * for the first time, we must flush that context out of the
121 * local TLB.
122 */
123 cpu = smp_processor_id();
124 if (!ctx_valid || !cpu_isset(cpu, mm->cpu_vm_mask)) {
125 cpu_set(cpu, mm->cpu_vm_mask);
126 __flush_tlb_mm(CTX_HWBITS(mm->context),
127 SECONDARY_CONTEXT);
128 }
129 spin_unlock_irqrestore(&mm->context.lock, flags);
130}
131
132#define deactivate_mm(tsk,mm) do { } while (0)
133
134/* Activate a new MM instance for the current task. */
135static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm)
136{
137 unsigned long flags;
138 int cpu;
139
140 spin_lock_irqsave(&mm->context.lock, flags);
141 if (!CTX_VALID(mm->context))
142 get_new_mmu_context(mm);
143 cpu = smp_processor_id();
144 if (!cpu_isset(cpu, mm->cpu_vm_mask))
145 cpu_set(cpu, mm->cpu_vm_mask);
146
147 load_secondary_context(mm);
148 __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT);
149 tsb_context_switch(mm);
150 spin_unlock_irqrestore(&mm->context.lock, flags);
151}
152
153#endif /* !(__ASSEMBLY__) */
154
155#endif /* !(__SPARC64_MMU_CONTEXT_H) */
diff --git a/include/asm-sparc64/mmzone.h b/include/asm-sparc64/mmzone.h
index ebf5986c12ed..43a710f7892a 100644
--- a/include/asm-sparc64/mmzone.h
+++ b/include/asm-sparc64/mmzone.h
@@ -1,17 +1 @@
1#ifndef _SPARC64_MMZONE_H #include <asm-sparc/mmzone.h>
2#define _SPARC64_MMZONE_H
3
4#ifdef CONFIG_NEED_MULTIPLE_NODES
5
6extern struct pglist_data *node_data[];
7
8#define NODE_DATA(nid) (node_data[nid])
9#define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
10#define node_end_pfn(nid) (NODE_DATA(nid)->node_end_pfn)
11
12extern int numa_cpu_lookup_table[];
13extern cpumask_t numa_cpumask_lookup_table[];
14
15#endif /* CONFIG_NEED_MULTIPLE_NODES */
16
17#endif /* _SPARC64_MMZONE_H */
diff --git a/include/asm-sparc64/module.h b/include/asm-sparc64/module.h
index 3d77ba465783..a9606db55e4a 100644
--- a/include/asm-sparc64/module.h
+++ b/include/asm-sparc64/module.h
@@ -1,7 +1 @@
1#ifndef _ASM_SPARC64_MODULE_H #include <asm-sparc/module.h>
2#define _ASM_SPARC64_MODULE_H
3struct mod_arch_specific { };
4#define Elf_Shdr Elf64_Shdr
5#define Elf_Sym Elf64_Sym
6#define Elf_Ehdr Elf64_Ehdr
7#endif /* _ASM_SPARC64_MODULE_H */
diff --git a/include/asm-sparc64/mostek.h b/include/asm-sparc64/mostek.h
index c5652de2ace2..95a752f7e875 100644
--- a/include/asm-sparc64/mostek.h
+++ b/include/asm-sparc64/mostek.h
@@ -1,143 +1 @@
1/* mostek.h: Describes the various Mostek time of day clock registers. #include <asm-sparc/mostek.h>
2 *
3 * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
5 */
6
7#ifndef _SPARC64_MOSTEK_H
8#define _SPARC64_MOSTEK_H
9
10#include <asm/idprom.h>
11
12/* M48T02 Register Map (adapted from Sun NVRAM/Hostid FAQ)
13 *
14 * Data
15 * Address Function
16 * Bit 7 Bit 6 Bit 5 Bit 4Bit 3 Bit 2 Bit 1 Bit 0
17 * 7ff - - - - - - - - Year 00-99
18 * 7fe 0 0 0 - - - - - Month 01-12
19 * 7fd 0 0 - - - - - - Date 01-31
20 * 7fc 0 FT 0 0 0 - - - Day 01-07
21 * 7fb KS 0 - - - - - - Hours 00-23
22 * 7fa 0 - - - - - - - Minutes 00-59
23 * 7f9 ST - - - - - - - Seconds 00-59
24 * 7f8 W R S - - - - - Control
25 *
26 * * ST is STOP BIT
27 * * W is WRITE BIT
28 * * R is READ BIT
29 * * S is SIGN BIT
30 * * FT is FREQ TEST BIT
31 * * KS is KICK START BIT
32 */
33
34/* The Mostek 48t02 real time clock and NVRAM chip. The registers
35 * other than the control register are in binary coded decimal. Some
36 * control bits also live outside the control register.
37 *
38 * We now deal with physical addresses for I/O to the chip. -DaveM
39 */
40static inline u8 mostek_read(void __iomem *addr)
41{
42 u8 ret;
43
44 __asm__ __volatile__("lduba [%1] %2, %0"
45 : "=r" (ret)
46 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
47 return ret;
48}
49
50static inline void mostek_write(void __iomem *addr, u8 val)
51{
52 __asm__ __volatile__("stba %0, [%1] %2"
53 : /* no outputs */
54 : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
55}
56
57#define MOSTEK_EEPROM 0x0000UL
58#define MOSTEK_IDPROM 0x07d8UL
59#define MOSTEK_CREG 0x07f8UL
60#define MOSTEK_SEC 0x07f9UL
61#define MOSTEK_MIN 0x07faUL
62#define MOSTEK_HOUR 0x07fbUL
63#define MOSTEK_DOW 0x07fcUL
64#define MOSTEK_DOM 0x07fdUL
65#define MOSTEK_MONTH 0x07feUL
66#define MOSTEK_YEAR 0x07ffUL
67
68extern spinlock_t mostek_lock;
69extern void __iomem *mstk48t02_regs;
70
71/* Control register values. */
72#define MSTK_CREG_WRITE 0x80 /* Must set this before placing values. */
73#define MSTK_CREG_READ 0x40 /* Stop updates to allow a clean read. */
74#define MSTK_CREG_SIGN 0x20 /* Slow/speed clock in calibration mode. */
75
76/* Control bits that live in the other registers. */
77#define MSTK_STOP 0x80 /* Stop the clock oscillator. (sec) */
78#define MSTK_KICK_START 0x80 /* Kick start the clock chip. (hour) */
79#define MSTK_FREQ_TEST 0x40 /* Frequency test mode. (day) */
80
81#define MSTK_YEAR_ZERO 1968 /* If year reg has zero, it is 1968. */
82#define MSTK_CVT_YEAR(yr) ((yr) + MSTK_YEAR_ZERO)
83
84/* Masks that define how much space each value takes up. */
85#define MSTK_SEC_MASK 0x7f
86#define MSTK_MIN_MASK 0x7f
87#define MSTK_HOUR_MASK 0x3f
88#define MSTK_DOW_MASK 0x07
89#define MSTK_DOM_MASK 0x3f
90#define MSTK_MONTH_MASK 0x1f
91#define MSTK_YEAR_MASK 0xffU
92
93/* Binary coded decimal conversion macros. */
94#define MSTK_REGVAL_TO_DECIMAL(x) (((x) & 0x0F) + 0x0A * ((x) >> 0x04))
95#define MSTK_DECIMAL_TO_REGVAL(x) ((((x) / 0x0A) << 0x04) + ((x) % 0x0A))
96
97/* Generic register set and get macros for internal use. */
98#define MSTK_GET(regs,name) \
99 (MSTK_REGVAL_TO_DECIMAL(mostek_read(regs + MOSTEK_ ## name) & MSTK_ ## name ## _MASK))
100#define MSTK_SET(regs,name,value) \
101do { u8 __val = mostek_read(regs + MOSTEK_ ## name); \
102 __val &= ~(MSTK_ ## name ## _MASK); \
103 __val |= (MSTK_DECIMAL_TO_REGVAL(value) & \
104 (MSTK_ ## name ## _MASK)); \
105 mostek_write(regs + MOSTEK_ ## name, __val); \
106} while(0)
107
108/* Macros to make register access easier on our fingers. These give you
109 * the decimal value of the register requested if applicable. You pass
110 * the a pointer to a 'struct mostek48t02'.
111 */
112#define MSTK_REG_CREG(regs) (mostek_read((regs) + MOSTEK_CREG))
113#define MSTK_REG_SEC(regs) MSTK_GET(regs,SEC)
114#define MSTK_REG_MIN(regs) MSTK_GET(regs,MIN)
115#define MSTK_REG_HOUR(regs) MSTK_GET(regs,HOUR)
116#define MSTK_REG_DOW(regs) MSTK_GET(regs,DOW)
117#define MSTK_REG_DOM(regs) MSTK_GET(regs,DOM)
118#define MSTK_REG_MONTH(regs) MSTK_GET(regs,MONTH)
119#define MSTK_REG_YEAR(regs) MSTK_GET(regs,YEAR)
120
121#define MSTK_SET_REG_SEC(regs,value) MSTK_SET(regs,SEC,value)
122#define MSTK_SET_REG_MIN(regs,value) MSTK_SET(regs,MIN,value)
123#define MSTK_SET_REG_HOUR(regs,value) MSTK_SET(regs,HOUR,value)
124#define MSTK_SET_REG_DOW(regs,value) MSTK_SET(regs,DOW,value)
125#define MSTK_SET_REG_DOM(regs,value) MSTK_SET(regs,DOM,value)
126#define MSTK_SET_REG_MONTH(regs,value) MSTK_SET(regs,MONTH,value)
127#define MSTK_SET_REG_YEAR(regs,value) MSTK_SET(regs,YEAR,value)
128
129
130/* The Mostek 48t08 clock chip. Found on Sun4m's I think. It has the
131 * same (basically) layout of the 48t02 chip except for the extra
132 * NVRAM on board (8 KB against the 48t02's 2 KB).
133 */
134#define MOSTEK_48T08_OFFSET 0x0000UL /* Lower NVRAM portions */
135#define MOSTEK_48T08_48T02 0x1800UL /* Offset to 48T02 chip */
136
137/* SUN5 systems usually have 48t59 model clock chipsets. But we keep the older
138 * clock chip definitions around just in case.
139 */
140#define MOSTEK_48T59_OFFSET 0x0000UL /* Lower NVRAM portions */
141#define MOSTEK_48T59_48T02 0x1800UL /* Offset to 48T02 chip */
142
143#endif /* !(_SPARC64_MOSTEK_H) */
diff --git a/include/asm-sparc64/msgbuf.h b/include/asm-sparc64/msgbuf.h
index 55c101bd0e7d..5b33cc9d9bfb 100644
--- a/include/asm-sparc64/msgbuf.h
+++ b/include/asm-sparc64/msgbuf.h
@@ -1,27 +1 @@
1#ifndef _SPARC64_MSGBUF_H #include <asm-sparc/msgbuf.h>
2#define _SPARC64_MSGBUF_H
3
4/*
5 * The msqid64_ds structure for sparc64 architecture.
6 * Note extra padding because this structure is passed back and forth
7 * between kernel and user space.
8 *
9 * Pad space is left for:
10 * - 2 miscellaneous 64-bit values
11 */
12
13struct msqid64_ds {
14 struct ipc64_perm msg_perm;
15 __kernel_time_t msg_stime; /* last msgsnd time */
16 __kernel_time_t msg_rtime; /* last msgrcv time */
17 __kernel_time_t msg_ctime; /* last change time */
18 unsigned long msg_cbytes; /* current number of bytes on queue */
19 unsigned long msg_qnum; /* number of messages in queue */
20 unsigned long msg_qbytes; /* max number of bytes on queue */
21 __kernel_pid_t msg_lspid; /* pid of last msgsnd */
22 __kernel_pid_t msg_lrpid; /* last receive pid */
23 unsigned long __unused1;
24 unsigned long __unused2;
25};
26
27#endif /* _SPARC64_MSGBUF_H */
diff --git a/include/asm-sparc64/mutex.h b/include/asm-sparc64/mutex.h
index 458c1f7fbc18..c0c0f8f260d6 100644
--- a/include/asm-sparc64/mutex.h
+++ b/include/asm-sparc64/mutex.h
@@ -1,9 +1 @@
1/* #include <asm-sparc/mutex.h>
2 * Pull in the generic implementation for the mutex fastpath.
3 *
4 * TODO: implement optimized primitives instead, or leave the generic
5 * implementation in place, or pick the atomic_xchg() based generic
6 * implementation. (see asm-generic/mutex-xchg.h for details)
7 */
8
9#include <asm-generic/mutex-dec.h>
diff --git a/include/asm-sparc64/namei.h b/include/asm-sparc64/namei.h
index cbc1b4c06891..1344a910ba2f 100644
--- a/include/asm-sparc64/namei.h
+++ b/include/asm-sparc64/namei.h
@@ -1,13 +1 @@
1/* #include <asm-sparc/namei.h>
2 * linux/include/asm-sparc64/namei.h
3 *
4 * Routines to handle famous /usr/gnemul/s*.
5 * Included from linux/fs/namei.c
6 */
7
8#ifndef __SPARC64_NAMEI_H
9#define __SPARC64_NAMEI_H
10
11#define __emul_prefix() NULL
12
13#endif /* __SPARC64_NAMEI_H */
diff --git a/include/asm-sparc64/ns87303.h b/include/asm-sparc64/ns87303.h
index 686defe6aaa0..5f369d4df3db 100644
--- a/include/asm-sparc64/ns87303.h
+++ b/include/asm-sparc64/ns87303.h
@@ -1,118 +1 @@
1/* ns87303.h: Configuration Register Description for the #include <asm-sparc/ns87303.h>
2 * National Semiconductor PC87303 (SuperIO).
3 *
4 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
5 */
6
7#ifndef _SPARC_NS87303_H
8#define _SPARC_NS87303_H 1
9
10/*
11 * Control Register Index Values
12 */
13#define FER 0x00
14#define FAR 0x01
15#define PTR 0x02
16#define FCR 0x03
17#define PCR 0x04
18#define KRR 0x05
19#define PMC 0x06
20#define TUP 0x07
21#define SID 0x08
22#define ASC 0x09
23#define CS0CF0 0x0a
24#define CS0CF1 0x0b
25#define CS1CF0 0x0c
26#define CS1CF1 0x0d
27
28/* Function Enable Register (FER) bits */
29#define FER_EDM 0x10 /* Encoded Drive and Motor pin information */
30
31/* Function Address Register (FAR) bits */
32#define FAR_LPT_MASK 0x03
33#define FAR_LPTB 0x00
34#define FAR_LPTA 0x01
35#define FAR_LPTC 0x02
36
37/* Power and Test Register (PTR) bits */
38#define PTR_LPTB_IRQ7 0x08
39#define PTR_LEVEL_IRQ 0x80 /* When not ECP/EPP: Use level IRQ */
40#define PTR_LPT_REG_DIR 0x80 /* When ECP/EPP: LPT CTR controlls direction */
41 /* of the parallel port */
42
43/* Function Control Register (FCR) bits */
44#define FCR_LDE 0x10 /* Logical Drive Exchange */
45#define FCR_ZWS_ENA 0x20 /* Enable short host read/write in ECP/EPP */
46
47/* Printer Control Register (PCR) bits */
48#define PCR_EPP_ENABLE 0x01
49#define PCR_EPP_IEEE 0x02 /* Enable EPP Version 1.9 (IEEE 1284) */
50#define PCR_ECP_ENABLE 0x04
51#define PCR_ECP_CLK_ENA 0x08 /* If 0 ECP Clock is stopped on Power down */
52#define PCR_IRQ_POLAR 0x20 /* If 0 IRQ is level high or negative pulse, */
53 /* if 1 polarity is inverted */
54#define PCR_IRQ_ODRAIN 0x40 /* If 1, IRQ is open drain */
55
56/* Tape UARTs and Parallel Port Config Register (TUP) bits */
57#define TUP_EPP_TIMO 0x02 /* Enable EPP timeout IRQ */
58
59/* Advanced SuperIO Config Register (ASC) bits */
60#define ASC_LPT_IRQ7 0x01 /* Always use IRQ7 for LPT */
61#define ASC_DRV2_SEL 0x02 /* Logical Drive Exchange controlled by TDR */
62
63#define FER_RESERVED 0x00
64#define FAR_RESERVED 0x00
65#define PTR_RESERVED 0x73
66#define FCR_RESERVED 0xc4
67#define PCR_RESERVED 0x10
68#define KRR_RESERVED 0x00
69#define PMC_RESERVED 0x98
70#define TUP_RESERVED 0xfb
71#define SIP_RESERVED 0x00
72#define ASC_RESERVED 0x18
73#define CS0CF0_RESERVED 0x00
74#define CS0CF1_RESERVED 0x08
75#define CS1CF0_RESERVED 0x00
76#define CS1CF1_RESERVED 0x08
77
78#ifdef __KERNEL__
79
80#include <linux/spinlock.h>
81
82#include <asm/system.h>
83#include <asm/io.h>
84
85extern spinlock_t ns87303_lock;
86
87static inline int ns87303_modify(unsigned long port, unsigned int index,
88 unsigned char clr, unsigned char set)
89{
90 static unsigned char reserved[] = {
91 FER_RESERVED, FAR_RESERVED, PTR_RESERVED, FCR_RESERVED,
92 PCR_RESERVED, KRR_RESERVED, PMC_RESERVED, TUP_RESERVED,
93 SIP_RESERVED, ASC_RESERVED, CS0CF0_RESERVED, CS0CF1_RESERVED,
94 CS1CF0_RESERVED, CS1CF1_RESERVED
95 };
96 unsigned long flags;
97 unsigned char value;
98
99 if (index > 0x0d)
100 return -EINVAL;
101
102 spin_lock_irqsave(&ns87303_lock, flags);
103
104 outb(index, port);
105 value = inb(port + 1);
106 value &= ~(reserved[index] | clr);
107 value |= set;
108 outb(value, port + 1);
109 outb(value, port + 1);
110
111 spin_unlock_irqrestore(&ns87303_lock, flags);
112
113 return 0;
114}
115
116#endif /* __KERNEL__ */
117
118#endif /* !(_SPARC_NS87303_H) */
diff --git a/include/asm-sparc64/of_platform.h b/include/asm-sparc64/of_platform.h
index 78aa032b674c..f7c427b8bc61 100644
--- a/include/asm-sparc64/of_platform.h
+++ b/include/asm-sparc64/of_platform.h
@@ -1,25 +1 @@
1#ifndef _ASM_SPARC64_OF_PLATFORM_H #include <asm-sparc/of_platform.h>
2#define _ASM_SPARC64_OF_PLATFORM_H
3/*
4 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
5 * <benh@kernel.crashing.org>
6 * Modified for Sparc by merging parts of asm-sparc/of_device.h
7 * by Stephen Rothwell
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 */
15
16/* This is just here during the transition */
17#include <linux/of_platform.h>
18
19extern struct bus_type isa_bus_type;
20extern struct bus_type ebus_bus_type;
21extern struct bus_type sbus_bus_type;
22
23#define of_bus_type of_platform_bus_type /* for compatibility */
24
25#endif /* _ASM_SPARC64_OF_PLATFORM_H */
diff --git a/include/asm-sparc64/openprom.h b/include/asm-sparc64/openprom.h
index b69e4a8c9170..acf4b234fae3 100644
--- a/include/asm-sparc64/openprom.h
+++ b/include/asm-sparc64/openprom.h
@@ -1,280 +1 @@
1#ifndef __SPARC64_OPENPROM_H #include <asm-sparc/openprom.h>
2#define __SPARC64_OPENPROM_H
3
4/* openprom.h: Prom structures and defines for access to the OPENBOOT
5 * prom routines and data areas.
6 *
7 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
8 */
9
10#ifndef __ASSEMBLY__
11/* V0 prom device operations. */
12struct linux_dev_v0_funcs {
13 int (*v0_devopen)(char *device_str);
14 int (*v0_devclose)(int dev_desc);
15 int (*v0_rdblkdev)(int dev_desc, int num_blks, int blk_st, char *buf);
16 int (*v0_wrblkdev)(int dev_desc, int num_blks, int blk_st, char *buf);
17 int (*v0_wrnetdev)(int dev_desc, int num_bytes, char *buf);
18 int (*v0_rdnetdev)(int dev_desc, int num_bytes, char *buf);
19 int (*v0_rdchardev)(int dev_desc, int num_bytes, int dummy, char *buf);
20 int (*v0_wrchardev)(int dev_desc, int num_bytes, int dummy, char *buf);
21 int (*v0_seekdev)(int dev_desc, long logical_offst, int from);
22};
23
24/* V2 and later prom device operations. */
25struct linux_dev_v2_funcs {
26 int (*v2_inst2pkg)(int d); /* Convert ihandle to phandle */
27 char * (*v2_dumb_mem_alloc)(char *va, unsigned sz);
28 void (*v2_dumb_mem_free)(char *va, unsigned sz);
29
30 /* To map devices into virtual I/O space. */
31 char * (*v2_dumb_mmap)(char *virta, int which_io, unsigned paddr, unsigned sz);
32 void (*v2_dumb_munmap)(char *virta, unsigned size);
33
34 int (*v2_dev_open)(char *devpath);
35 void (*v2_dev_close)(int d);
36 int (*v2_dev_read)(int d, char *buf, int nbytes);
37 int (*v2_dev_write)(int d, char *buf, int nbytes);
38 int (*v2_dev_seek)(int d, int hi, int lo);
39
40 /* Never issued (multistage load support) */
41 void (*v2_wheee2)(void);
42 void (*v2_wheee3)(void);
43};
44
45struct linux_mlist_v0 {
46 struct linux_mlist_v0 *theres_more;
47 unsigned start_adr;
48 unsigned num_bytes;
49};
50
51struct linux_mem_v0 {
52 struct linux_mlist_v0 **v0_totphys;
53 struct linux_mlist_v0 **v0_prommap;
54 struct linux_mlist_v0 **v0_available; /* What we can use */
55};
56
57/* Arguments sent to the kernel from the boot prompt. */
58struct linux_arguments_v0 {
59 char *argv[8];
60 char args[100];
61 char boot_dev[2];
62 int boot_dev_ctrl;
63 int boot_dev_unit;
64 int dev_partition;
65 char *kernel_file_name;
66 void *aieee1; /* XXX */
67};
68
69/* V2 and up boot things. */
70struct linux_bootargs_v2 {
71 char **bootpath;
72 char **bootargs;
73 int *fd_stdin;
74 int *fd_stdout;
75};
76
77/* The top level PROM vector. */
78struct linux_romvec {
79 /* Version numbers. */
80 unsigned int pv_magic_cookie;
81 unsigned int pv_romvers;
82 unsigned int pv_plugin_revision;
83 unsigned int pv_printrev;
84
85 /* Version 0 memory descriptors. */
86 struct linux_mem_v0 pv_v0mem;
87
88 /* Node operations. */
89 struct linux_nodeops *pv_nodeops;
90
91 char **pv_bootstr;
92 struct linux_dev_v0_funcs pv_v0devops;
93
94 char *pv_stdin;
95 char *pv_stdout;
96#define PROMDEV_KBD 0 /* input from keyboard */
97#define PROMDEV_SCREEN 0 /* output to screen */
98#define PROMDEV_TTYA 1 /* in/out to ttya */
99#define PROMDEV_TTYB 2 /* in/out to ttyb */
100
101 /* Blocking getchar/putchar. NOT REENTRANT! (grr) */
102 int (*pv_getchar)(void);
103 void (*pv_putchar)(int ch);
104
105 /* Non-blocking variants. */
106 int (*pv_nbgetchar)(void);
107 int (*pv_nbputchar)(int ch);
108
109 void (*pv_putstr)(char *str, int len);
110
111 /* Miscellany. */
112 void (*pv_reboot)(char *bootstr);
113 void (*pv_printf)(__const__ char *fmt, ...);
114 void (*pv_abort)(void);
115 __volatile__ int *pv_ticks;
116 void (*pv_halt)(void);
117 void (**pv_synchook)(void);
118
119 /* Evaluate a forth string, not different proto for V0 and V2->up. */
120 union {
121 void (*v0_eval)(int len, char *str);
122 void (*v2_eval)(char *str);
123 } pv_fortheval;
124
125 struct linux_arguments_v0 **pv_v0bootargs;
126
127 /* Get ether address. */
128 unsigned int (*pv_enaddr)(int d, char *enaddr);
129
130 struct linux_bootargs_v2 pv_v2bootargs;
131 struct linux_dev_v2_funcs pv_v2devops;
132
133 int filler[15];
134
135 /* This one is sun4c/sun4 only. */
136 void (*pv_setctxt)(int ctxt, char *va, int pmeg);
137
138 /* Prom version 3 Multiprocessor routines. This stuff is crazy.
139 * No joke. Calling these when there is only one cpu probably
140 * crashes the machine, have to test this. :-)
141 */
142
143 /* v3_cpustart() will start the cpu 'whichcpu' in mmu-context
144 * 'thiscontext' executing at address 'prog_counter'
145 */
146 int (*v3_cpustart)(unsigned int whichcpu, int ctxtbl_ptr,
147 int thiscontext, char *prog_counter);
148
149 /* v3_cpustop() will cause cpu 'whichcpu' to stop executing
150 * until a resume cpu call is made.
151 */
152 int (*v3_cpustop)(unsigned int whichcpu);
153
154 /* v3_cpuidle() will idle cpu 'whichcpu' until a stop or
155 * resume cpu call is made.
156 */
157 int (*v3_cpuidle)(unsigned int whichcpu);
158
159 /* v3_cpuresume() will resume processor 'whichcpu' executing
160 * starting with whatever 'pc' and 'npc' were left at the
161 * last 'idle' or 'stop' call.
162 */
163 int (*v3_cpuresume)(unsigned int whichcpu);
164};
165
166/* Routines for traversing the prom device tree. */
167struct linux_nodeops {
168 int (*no_nextnode)(int node);
169 int (*no_child)(int node);
170 int (*no_proplen)(int node, char *name);
171 int (*no_getprop)(int node, char *name, char *val);
172 int (*no_setprop)(int node, char *name, char *val, int len);
173 char * (*no_nextprop)(int node, char *name);
174};
175
176/* More fun PROM structures for device probing. */
177#define PROMREG_MAX 24
178#define PROMVADDR_MAX 16
179#define PROMINTR_MAX 32
180
181struct linux_prom_registers {
182 unsigned which_io; /* hi part of physical address */
183 unsigned phys_addr; /* The physical address of this register */
184 int reg_size; /* How many bytes does this register take up? */
185};
186
187struct linux_prom64_registers {
188 unsigned long phys_addr;
189 unsigned long reg_size;
190};
191
192struct linux_prom_irqs {
193 int pri; /* IRQ priority */
194 int vector; /* This is foobar, what does it do? */
195};
196
197/* Element of the "ranges" vector */
198struct linux_prom_ranges {
199 unsigned int ot_child_space;
200 unsigned int ot_child_base; /* Bus feels this */
201 unsigned int ot_parent_space;
202 unsigned int ot_parent_base; /* CPU looks from here */
203 unsigned int or_size;
204};
205
206struct linux_prom64_ranges {
207 unsigned long ot_child_base; /* Bus feels this */
208 unsigned long ot_parent_base; /* CPU looks from here */
209 unsigned long or_size;
210};
211
212/* Ranges and reg properties are a bit different for PCI. */
213struct linux_prom_pci_registers {
214 unsigned int phys_hi;
215 unsigned int phys_mid;
216 unsigned int phys_lo;
217
218 unsigned int size_hi;
219 unsigned int size_lo;
220};
221
222struct linux_prom_pci_ranges {
223 unsigned int child_phys_hi; /* Only certain bits are encoded here. */
224 unsigned int child_phys_mid;
225 unsigned int child_phys_lo;
226
227 unsigned int parent_phys_hi;
228 unsigned int parent_phys_lo;
229
230 unsigned int size_hi;
231 unsigned int size_lo;
232};
233
234struct linux_prom_pci_intmap {
235 unsigned int phys_hi;
236 unsigned int phys_mid;
237 unsigned int phys_lo;
238
239 unsigned int interrupt;
240
241 int cnode;
242 unsigned int cinterrupt;
243};
244
245struct linux_prom_pci_intmask {
246 unsigned int phys_hi;
247 unsigned int phys_mid;
248 unsigned int phys_lo;
249 unsigned int interrupt;
250};
251
252struct linux_prom_ebus_ranges {
253 unsigned int child_phys_hi;
254 unsigned int child_phys_lo;
255
256 unsigned int parent_phys_hi;
257 unsigned int parent_phys_mid;
258 unsigned int parent_phys_lo;
259
260 unsigned int size;
261};
262
263struct linux_prom_ebus_intmap {
264 unsigned int phys_hi;
265 unsigned int phys_lo;
266
267 unsigned int interrupt;
268
269 int cnode;
270 unsigned int cinterrupt;
271};
272
273struct linux_prom_ebus_intmask {
274 unsigned int phys_hi;
275 unsigned int phys_lo;
276 unsigned int interrupt;
277};
278#endif /* !(__ASSEMBLY__) */
279
280#endif /* !(__SPARC64_OPENPROM_H) */
diff --git a/include/asm-sparc64/openpromio.h b/include/asm-sparc64/openpromio.h
index 847ce2326ad5..122fabda21f1 100644
--- a/include/asm-sparc64/openpromio.h
+++ b/include/asm-sparc64/openpromio.h
@@ -1,69 +1 @@
1#ifndef _SPARC64_OPENPROMIO_H #include <asm-sparc/openpromio.h>
2#define _SPARC64_OPENPROMIO_H
3
4#include <linux/compiler.h>
5#include <linux/ioctl.h>
6#include <linux/types.h>
7
8/*
9 * SunOS and Solaris /dev/openprom definitions. The ioctl values
10 * were chosen to be exactly equal to the SunOS equivalents.
11 */
12
13struct openpromio
14{
15 u_int oprom_size; /* Actual size of the oprom_array. */
16 char oprom_array[1]; /* Holds property names and values. */
17};
18
19#define OPROMMAXPARAM 4096 /* Maximum size of oprom_array. */
20
21#define OPROMGETOPT 0x20004F01
22#define OPROMSETOPT 0x20004F02
23#define OPROMNXTOPT 0x20004F03
24#define OPROMSETOPT2 0x20004F04
25#define OPROMNEXT 0x20004F05
26#define OPROMCHILD 0x20004F06
27#define OPROMGETPROP 0x20004F07
28#define OPROMNXTPROP 0x20004F08
29#define OPROMU2P 0x20004F09
30#define OPROMGETCONS 0x20004F0A
31#define OPROMGETFBNAME 0x20004F0B
32#define OPROMGETBOOTARGS 0x20004F0C
33/* Linux extensions */ /* Arguments in oprom_array: */
34#define OPROMSETCUR 0x20004FF0 /* int node - Sets current node */
35#define OPROMPCI2NODE 0x20004FF1 /* int pci_bus, pci_devfn - Sets current node to PCI device's node */
36#define OPROMPATH2NODE 0x20004FF2 /* char path[] - Set current node from fully qualified PROM path */
37
38/*
39 * Return values from OPROMGETCONS:
40 */
41
42#define OPROMCONS_NOT_WSCONS 0
43#define OPROMCONS_STDIN_IS_KBD 0x1 /* stdin device is kbd */
44#define OPROMCONS_STDOUT_IS_FB 0x2 /* stdout is a framebuffer */
45#define OPROMCONS_OPENPROM 0x4 /* supports openboot */
46
47
48/*
49 * NetBSD/OpenBSD /dev/openprom definitions.
50 */
51
52struct opiocdesc
53{
54 int op_nodeid; /* PROM Node ID (value-result) */
55 int op_namelen; /* Length of op_name. */
56 char __user *op_name; /* Pointer to the property name. */
57 int op_buflen; /* Length of op_buf (value-result) */
58 char __user *op_buf; /* Pointer to buffer. */
59};
60
61#define OPIOCGET _IOWR('O', 1, struct opiocdesc)
62#define OPIOCSET _IOW('O', 2, struct opiocdesc)
63#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc)
64#define OPIOCGETOPTNODE _IOR('O', 4, int)
65#define OPIOCGETNEXT _IOWR('O', 5, int)
66#define OPIOCGETCHILD _IOWR('O', 6, int)
67
68#endif /* _SPARC64_OPENPROMIO_H */
69
diff --git a/include/asm-sparc64/oplib.h b/include/asm-sparc64/oplib.h
index 55c5bb27e4da..d93e44e63510 100644
--- a/include/asm-sparc64/oplib.h
+++ b/include/asm-sparc64/oplib.h
@@ -1,322 +1 @@
1/* oplib.h: Describes the interface and available routines in the #include <asm-sparc/oplib.h>
2 * Linux Prom library.
3 *
4 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
5 * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7
8#ifndef __SPARC64_OPLIB_H
9#define __SPARC64_OPLIB_H
10
11#include <asm/openprom.h>
12
13/* OBP version string. */
14extern char prom_version[];
15
16/* Root node of the prom device tree, this stays constant after
17 * initialization is complete.
18 */
19extern int prom_root_node;
20
21/* PROM stdin and stdout */
22extern int prom_stdin, prom_stdout;
23
24/* /chosen node of the prom device tree, this stays constant after
25 * initialization is complete.
26 */
27extern int prom_chosen_node;
28
29/* Helper values and strings in arch/sparc64/kernel/head.S */
30extern const char prom_peer_name[];
31extern const char prom_compatible_name[];
32extern const char prom_root_compatible[];
33extern const char prom_cpu_compatible[];
34extern const char prom_finddev_name[];
35extern const char prom_chosen_path[];
36extern const char prom_cpu_path[];
37extern const char prom_getprop_name[];
38extern const char prom_mmu_name[];
39extern const char prom_callmethod_name[];
40extern const char prom_translate_name[];
41extern const char prom_map_name[];
42extern const char prom_unmap_name[];
43extern int prom_mmu_ihandle_cache;
44extern unsigned int prom_boot_mapped_pc;
45extern unsigned int prom_boot_mapping_mode;
46extern unsigned long prom_boot_mapping_phys_high, prom_boot_mapping_phys_low;
47
48struct linux_mlist_p1275 {
49 struct linux_mlist_p1275 *theres_more;
50 unsigned long start_adr;
51 unsigned long num_bytes;
52};
53
54struct linux_mem_p1275 {
55 struct linux_mlist_p1275 **p1275_totphys;
56 struct linux_mlist_p1275 **p1275_prommap;
57 struct linux_mlist_p1275 **p1275_available; /* What we can use */
58};
59
60/* The functions... */
61
62/* You must call prom_init() before using any of the library services,
63 * preferably as early as possible. Pass it the romvec pointer.
64 */
65extern void prom_init(void *cif_handler, void *cif_stack);
66
67/* Boot argument acquisition, returns the boot command line string. */
68extern char *prom_getbootargs(void);
69
70/* Device utilities. */
71
72/* Device operations. */
73
74/* Open the device described by the passed string. Note, that the format
75 * of the string is different on V0 vs. V2->higher proms. The caller must
76 * know what he/she is doing! Returns the device descriptor, an int.
77 */
78extern int prom_devopen(const char *device_string);
79
80/* Close a previously opened device described by the passed integer
81 * descriptor.
82 */
83extern int prom_devclose(int device_handle);
84
85/* Do a seek operation on the device described by the passed integer
86 * descriptor.
87 */
88extern void prom_seek(int device_handle, unsigned int seek_hival,
89 unsigned int seek_lowval);
90
91/* Miscellaneous routines, don't really fit in any category per se. */
92
93/* Reboot the machine with the command line passed. */
94extern void prom_reboot(const char *boot_command);
95
96/* Evaluate the forth string passed. */
97extern void prom_feval(const char *forth_string);
98
99/* Enter the prom, with possibility of continuation with the 'go'
100 * command in newer proms.
101 */
102extern void prom_cmdline(void);
103
104/* Enter the prom, with no chance of continuation for the stand-alone
105 * which calls this.
106 */
107extern void prom_halt(void) __attribute__ ((noreturn));
108
109/* Halt and power-off the machine. */
110extern void prom_halt_power_off(void) __attribute__ ((noreturn));
111
112/* Set the PROM 'sync' callback function to the passed function pointer.
113 * When the user gives the 'sync' command at the prom prompt while the
114 * kernel is still active, the prom will call this routine.
115 *
116 */
117typedef int (*callback_func_t)(long *cmd);
118extern void prom_setcallback(callback_func_t func_ptr);
119
120/* Acquire the IDPROM of the root node in the prom device tree. This
121 * gets passed a buffer where you would like it stuffed. The return value
122 * is the format type of this idprom or 0xff on error.
123 */
124extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
125
126/* Character operations to/from the console.... */
127
128/* Non-blocking get character from console. */
129extern int prom_nbgetchar(void);
130
131/* Non-blocking put character to console. */
132extern int prom_nbputchar(char character);
133
134/* Blocking get character from console. */
135extern char prom_getchar(void);
136
137/* Blocking put character to console. */
138extern void prom_putchar(char character);
139
140/* Prom's internal routines, don't use in kernel/boot code. */
141extern void prom_printf(const char *fmt, ...);
142extern void prom_write(const char *buf, unsigned int len);
143
144/* Multiprocessor operations... */
145#ifdef CONFIG_SMP
146/* Start the CPU with the given device tree node at the passed program
147 * counter with the given arg passed in via register %o0.
148 */
149extern void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg);
150
151/* Start the CPU with the given cpu ID at the passed program
152 * counter with the given arg passed in via register %o0.
153 */
154extern void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg);
155
156/* Stop the CPU with the given cpu ID. */
157extern void prom_stopcpu_cpuid(int cpuid);
158
159/* Stop the current CPU. */
160extern void prom_stopself(void);
161
162/* Idle the current CPU. */
163extern void prom_idleself(void);
164
165/* Resume the CPU with the passed device tree node. */
166extern void prom_resumecpu(int cpunode);
167#endif
168
169/* Power management interfaces. */
170
171/* Put the current CPU to sleep. */
172extern void prom_sleepself(void);
173
174/* Put the entire system to sleep. */
175extern int prom_sleepsystem(void);
176
177/* Initiate a wakeup event. */
178extern int prom_wakeupsystem(void);
179
180/* MMU and memory related OBP interfaces. */
181
182/* Get unique string identifying SIMM at given physical address. */
183extern int prom_getunumber(int syndrome_code,
184 unsigned long phys_addr,
185 char *buf, int buflen);
186
187/* Retain physical memory to the caller across soft resets. */
188extern unsigned long prom_retain(const char *name,
189 unsigned long pa_low, unsigned long pa_high,
190 long size, long align);
191
192/* Load explicit I/D TLB entries into the calling processor. */
193extern long prom_itlb_load(unsigned long index,
194 unsigned long tte_data,
195 unsigned long vaddr);
196
197extern long prom_dtlb_load(unsigned long index,
198 unsigned long tte_data,
199 unsigned long vaddr);
200
201/* Map/Unmap client program address ranges. First the format of
202 * the mapping mode argument.
203 */
204#define PROM_MAP_WRITE 0x0001 /* Writable */
205#define PROM_MAP_READ 0x0002 /* Readable - sw */
206#define PROM_MAP_EXEC 0x0004 /* Executable - sw */
207#define PROM_MAP_LOCKED 0x0010 /* Locked, use i/dtlb load calls for this instead */
208#define PROM_MAP_CACHED 0x0020 /* Cacheable in both L1 and L2 caches */
209#define PROM_MAP_SE 0x0040 /* Side-Effects */
210#define PROM_MAP_GLOB 0x0080 /* Global */
211#define PROM_MAP_IE 0x0100 /* Invert-Endianness */
212#define PROM_MAP_DEFAULT (PROM_MAP_WRITE | PROM_MAP_READ | PROM_MAP_EXEC | PROM_MAP_CACHED)
213
214extern int prom_map(int mode, unsigned long size,
215 unsigned long vaddr, unsigned long paddr);
216extern void prom_unmap(unsigned long size, unsigned long vaddr);
217
218
219/* PROM device tree traversal functions... */
220
221#ifdef PROMLIB_INTERNAL
222
223/* Internal version of prom_getchild. */
224extern int __prom_getchild(int parent_node);
225
226/* Internal version of prom_getsibling. */
227extern int __prom_getsibling(int node);
228
229#endif
230
231/* Get the child node of the given node, or zero if no child exists. */
232extern int prom_getchild(int parent_node);
233
234/* Get the next sibling node of the given node, or zero if no further
235 * siblings exist.
236 */
237extern int prom_getsibling(int node);
238
239/* Get the length, at the passed node, of the given property type.
240 * Returns -1 on error (ie. no such property at this node).
241 */
242extern int prom_getproplen(int thisnode, const char *property);
243
244/* Fetch the requested property using the given buffer. Returns
245 * the number of bytes the prom put into your buffer or -1 on error.
246 */
247extern int prom_getproperty(int thisnode, const char *property,
248 char *prop_buffer, int propbuf_size);
249
250/* Acquire an integer property. */
251extern int prom_getint(int node, const char *property);
252
253/* Acquire an integer property, with a default value. */
254extern int prom_getintdefault(int node, const char *property, int defval);
255
256/* Acquire a boolean property, 0=FALSE 1=TRUE. */
257extern int prom_getbool(int node, const char *prop);
258
259/* Acquire a string property, null string on error. */
260extern void prom_getstring(int node, const char *prop, char *buf, int bufsize);
261
262/* Does the passed node have the given "name"? YES=1 NO=0 */
263extern int prom_nodematch(int thisnode, const char *name);
264
265/* Search all siblings starting at the passed node for "name" matching
266 * the given string. Returns the node on success, zero on failure.
267 */
268extern int prom_searchsiblings(int node_start, const char *name);
269
270/* Return the first property type, as a string, for the given node.
271 * Returns a null string on error. Buffer should be at least 32B long.
272 */
273extern char *prom_firstprop(int node, char *buffer);
274
275/* Returns the next property after the passed property for the given
276 * node. Returns null string on failure. Buffer should be at least 32B long.
277 */
278extern char *prom_nextprop(int node, const char *prev_property, char *buffer);
279
280/* Returns 1 if the specified node has given property. */
281extern int prom_node_has_property(int node, const char *property);
282
283/* Returns phandle of the path specified */
284extern int prom_finddevice(const char *name);
285
286/* Set the indicated property at the given node with the passed value.
287 * Returns the number of bytes of your value that the prom took.
288 */
289extern int prom_setprop(int node, const char *prop_name, char *prop_value,
290 int value_size);
291
292extern int prom_pathtoinode(const char *path);
293extern int prom_inst2pkg(int);
294extern int prom_service_exists(const char *service_name);
295extern void prom_sun4v_guest_soft_state(void);
296
297extern int prom_ihandle2path(int handle, char *buffer, int bufsize);
298
299/* Client interface level routines. */
300extern long p1275_cmd(const char *, long, ...);
301
302#if 0
303#define P1275_SIZE(x) ((((long)((x) / 32)) << 32) | (x))
304#else
305#define P1275_SIZE(x) x
306#endif
307
308/* We support at most 16 input and 1 output argument */
309#define P1275_ARG_NUMBER 0
310#define P1275_ARG_IN_STRING 1
311#define P1275_ARG_OUT_BUF 2
312#define P1275_ARG_OUT_32B 3
313#define P1275_ARG_IN_FUNCTION 4
314#define P1275_ARG_IN_BUF 5
315#define P1275_ARG_IN_64B 6
316
317#define P1275_IN(x) ((x) & 0xf)
318#define P1275_OUT(x) (((x) << 4) & 0xf0)
319#define P1275_INOUT(i,o) (P1275_IN(i)|P1275_OUT(o))
320#define P1275_ARG(n,x) ((x) << ((n)*3 + 8))
321
322#endif /* !(__SPARC64_OPLIB_H) */
diff --git a/include/asm-sparc64/page.h b/include/asm-sparc64/page.h
index 93f0881b766e..f46c1fb53028 100644
--- a/include/asm-sparc64/page.h
+++ b/include/asm-sparc64/page.h
@@ -1,142 +1 @@
1#ifndef _SPARC64_PAGE_H #include <asm-sparc/page.h>
2#define _SPARC64_PAGE_H
3
4#include <linux/const.h>
5
6#if defined(CONFIG_SPARC64_PAGE_SIZE_8KB)
7#define PAGE_SHIFT 13
8#elif defined(CONFIG_SPARC64_PAGE_SIZE_64KB)
9#define PAGE_SHIFT 16
10#elif defined(CONFIG_SPARC64_PAGE_SIZE_512KB)
11#define PAGE_SHIFT 19
12#elif defined(CONFIG_SPARC64_PAGE_SIZE_4MB)
13#define PAGE_SHIFT 22
14#else
15#error No page size specified in kernel configuration
16#endif
17
18#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
19#define PAGE_MASK (~(PAGE_SIZE-1))
20
21/* Flushing for D-cache alias handling is only needed if
22 * the page size is smaller than 16K.
23 */
24#if PAGE_SHIFT < 14
25#define DCACHE_ALIASING_POSSIBLE
26#endif
27
28#if defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
29#define HPAGE_SHIFT 22
30#elif defined(CONFIG_HUGETLB_PAGE_SIZE_512K)
31#define HPAGE_SHIFT 19
32#elif defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
33#define HPAGE_SHIFT 16
34#endif
35
36#ifdef CONFIG_HUGETLB_PAGE
37#define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT)
38#define HPAGE_MASK (~(HPAGE_SIZE - 1UL))
39#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
40#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
41#endif
42
43#ifndef __ASSEMBLY__
44
45extern void _clear_page(void *page);
46#define clear_page(X) _clear_page((void *)(X))
47struct page;
48extern void clear_user_page(void *addr, unsigned long vaddr, struct page *page);
49#define copy_page(X,Y) memcpy((void *)(X), (void *)(Y), PAGE_SIZE)
50extern void copy_user_page(void *to, void *from, unsigned long vaddr, struct page *topage);
51
52/* Unlike sparc32, sparc64's parameter passing API is more
53 * sane in that structures which as small enough are passed
54 * in registers instead of on the stack. Thus, setting
55 * STRICT_MM_TYPECHECKS does not generate worse code so
56 * let's enable it to get the type checking.
57 */
58
59#define STRICT_MM_TYPECHECKS
60
61#ifdef STRICT_MM_TYPECHECKS
62/* These are used to make use of C type-checking.. */
63typedef struct { unsigned long pte; } pte_t;
64typedef struct { unsigned long iopte; } iopte_t;
65typedef struct { unsigned int pmd; } pmd_t;
66typedef struct { unsigned int pgd; } pgd_t;
67typedef struct { unsigned long pgprot; } pgprot_t;
68
69#define pte_val(x) ((x).pte)
70#define iopte_val(x) ((x).iopte)
71#define pmd_val(x) ((x).pmd)
72#define pgd_val(x) ((x).pgd)
73#define pgprot_val(x) ((x).pgprot)
74
75#define __pte(x) ((pte_t) { (x) } )
76#define __iopte(x) ((iopte_t) { (x) } )
77#define __pmd(x) ((pmd_t) { (x) } )
78#define __pgd(x) ((pgd_t) { (x) } )
79#define __pgprot(x) ((pgprot_t) { (x) } )
80
81#else
82/* .. while these make it easier on the compiler */
83typedef unsigned long pte_t;
84typedef unsigned long iopte_t;
85typedef unsigned int pmd_t;
86typedef unsigned int pgd_t;
87typedef unsigned long pgprot_t;
88
89#define pte_val(x) (x)
90#define iopte_val(x) (x)
91#define pmd_val(x) (x)
92#define pgd_val(x) (x)
93#define pgprot_val(x) (x)
94
95#define __pte(x) (x)
96#define __iopte(x) (x)
97#define __pmd(x) (x)
98#define __pgd(x) (x)
99#define __pgprot(x) (x)
100
101#endif /* (STRICT_MM_TYPECHECKS) */
102
103typedef struct page *pgtable_t;
104
105#define TASK_UNMAPPED_BASE (test_thread_flag(TIF_32BIT) ? \
106 (_AC(0x0000000070000000,UL)) : \
107 (_AC(0xfffff80000000000,UL) + (1UL << 32UL)))
108
109#include <asm-generic/memory_model.h>
110
111#endif /* !(__ASSEMBLY__) */
112
113/* to align the pointer to the (next) page boundary */
114#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
115
116/* We used to stick this into a hard-coded global register (%g4)
117 * but that does not make sense anymore.
118 */
119#define PAGE_OFFSET _AC(0xFFFFF80000000000,UL)
120
121#ifndef __ASSEMBLY__
122
123#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET)
124#define __va(x) ((void *)((unsigned long) (x) + PAGE_OFFSET))
125
126#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
127
128#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr)>>PAGE_SHIFT)
129
130#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
131
132#define virt_to_phys __pa
133#define phys_to_virt __va
134
135#endif /* !(__ASSEMBLY__) */
136
137#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
138 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
139
140#include <asm-generic/page.h>
141
142#endif /* _SPARC64_PAGE_H */
diff --git a/include/asm-sparc64/param.h b/include/asm-sparc64/param.h
index f0125cf5a9df..40c6dc110822 100644
--- a/include/asm-sparc64/param.h
+++ b/include/asm-sparc64/param.h
@@ -1,23 +1 @@
1#ifndef _ASMSPARC64_PARAM_H #include <asm-sparc/param.h>
2#define _ASMSPARC64_PARAM_H
3
4
5#ifdef __KERNEL__
6# define HZ CONFIG_HZ /* Internal kernel timer frequency */
7# define USER_HZ 100 /* .. some user interfaces are in "ticks" */
8# define CLOCKS_PER_SEC (USER_HZ)
9#endif
10
11#ifndef HZ
12#define HZ 100
13#endif
14
15#define EXEC_PAGESIZE 8192 /* Thanks for sun4's we carry baggage... */
16
17#ifndef NOGROUP
18#define NOGROUP (-1)
19#endif
20
21#define MAXHOSTNAMELEN 64 /* max length of hostname */
22
23#endif /* _ASMSPARC64_PARAM_H */
diff --git a/include/asm-sparc64/parport.h b/include/asm-sparc64/parport.h
index e9555b246c8d..b4e4ca812eb6 100644
--- a/include/asm-sparc64/parport.h
+++ b/include/asm-sparc64/parport.h
@@ -1,246 +1 @@
1/* parport.h: sparc64 specific parport initialization and dma. #include <asm-sparc/parport.h>
2 *
3 * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be)
4 */
5
6#ifndef _ASM_SPARC64_PARPORT_H
7#define _ASM_SPARC64_PARPORT_H 1
8
9#include <asm/ebus.h>
10#include <asm/ns87303.h>
11#include <asm/of_device.h>
12#include <asm/prom.h>
13
14#define PARPORT_PC_MAX_PORTS PARPORT_MAX
15
16/*
17 * While sparc64 doesn't have an ISA DMA API, we provide something that looks
18 * close enough to make parport_pc happy
19 */
20#define HAS_DMA
21
22static DEFINE_SPINLOCK(dma_spin_lock);
23
24#define claim_dma_lock() \
25({ unsigned long flags; \
26 spin_lock_irqsave(&dma_spin_lock, flags); \
27 flags; \
28})
29
30#define release_dma_lock(__flags) \
31 spin_unlock_irqrestore(&dma_spin_lock, __flags);
32
33static struct sparc_ebus_info {
34 struct ebus_dma_info info;
35 unsigned int addr;
36 unsigned int count;
37 int lock;
38
39 struct parport *port;
40} sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
41
42static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS);
43
44static inline int request_dma(unsigned int dmanr, const char *device_id)
45{
46 if (dmanr >= PARPORT_PC_MAX_PORTS)
47 return -EINVAL;
48 if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
49 return -EBUSY;
50 return 0;
51}
52
53static inline void free_dma(unsigned int dmanr)
54{
55 if (dmanr >= PARPORT_PC_MAX_PORTS) {
56 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
57 return;
58 }
59 if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
60 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
61 return;
62 }
63}
64
65static inline void enable_dma(unsigned int dmanr)
66{
67 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
68
69 if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
70 sparc_ebus_dmas[dmanr].addr,
71 sparc_ebus_dmas[dmanr].count))
72 BUG();
73}
74
75static inline void disable_dma(unsigned int dmanr)
76{
77 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
78}
79
80static inline void clear_dma_ff(unsigned int dmanr)
81{
82 /* nothing */
83}
84
85static inline void set_dma_mode(unsigned int dmanr, char mode)
86{
87 ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
88}
89
90static inline void set_dma_addr(unsigned int dmanr, unsigned int addr)
91{
92 sparc_ebus_dmas[dmanr].addr = addr;
93}
94
95static inline void set_dma_count(unsigned int dmanr, unsigned int count)
96{
97 sparc_ebus_dmas[dmanr].count = count;
98}
99
100static inline unsigned int get_dma_residue(unsigned int dmanr)
101{
102 return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
103}
104
105static int __devinit ecpp_probe(struct of_device *op, const struct of_device_id *match)
106{
107 unsigned long base = op->resource[0].start;
108 unsigned long config = op->resource[1].start;
109 unsigned long d_base = op->resource[2].start;
110 unsigned long d_len;
111 struct device_node *parent;
112 struct parport *p;
113 int slot, err;
114
115 parent = op->node->parent;
116 if (!strcmp(parent->name, "dma")) {
117 p = parport_pc_probe_port(base, base + 0x400,
118 op->irqs[0], PARPORT_DMA_NOFIFO,
119 op->dev.parent->parent);
120 if (!p)
121 return -ENOMEM;
122 dev_set_drvdata(&op->dev, p);
123 return 0;
124 }
125
126 for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) {
127 if (!test_and_set_bit(slot, dma_slot_map))
128 break;
129 }
130 err = -ENODEV;
131 if (slot >= PARPORT_PC_MAX_PORTS)
132 goto out_err;
133
134 spin_lock_init(&sparc_ebus_dmas[slot].info.lock);
135
136 d_len = (op->resource[2].end - d_base) + 1UL;
137 sparc_ebus_dmas[slot].info.regs =
138 of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA");
139
140 if (!sparc_ebus_dmas[slot].info.regs)
141 goto out_clear_map;
142
143 sparc_ebus_dmas[slot].info.flags = 0;
144 sparc_ebus_dmas[slot].info.callback = NULL;
145 sparc_ebus_dmas[slot].info.client_cookie = NULL;
146 sparc_ebus_dmas[slot].info.irq = 0xdeadbeef;
147 strcpy(sparc_ebus_dmas[slot].info.name, "parport");
148 if (ebus_dma_register(&sparc_ebus_dmas[slot].info))
149 goto out_unmap_regs;
150
151 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1);
152
153 /* Configure IRQ to Push Pull, Level Low */
154 /* Enable ECP, set bit 2 of the CTR first */
155 outb(0x04, base + 0x02);
156 ns87303_modify(config, PCR,
157 PCR_EPP_ENABLE |
158 PCR_IRQ_ODRAIN,
159 PCR_ECP_ENABLE |
160 PCR_ECP_CLK_ENA |
161 PCR_IRQ_POLAR);
162
163 /* CTR bit 5 controls direction of port */
164 ns87303_modify(config, PTR,
165 0, PTR_LPT_REG_DIR);
166
167 p = parport_pc_probe_port(base, base + 0x400,
168 op->irqs[0],
169 slot,
170 op->dev.parent);
171 err = -ENOMEM;
172 if (!p)
173 goto out_disable_irq;
174
175 dev_set_drvdata(&op->dev, p);
176
177 return 0;
178
179out_disable_irq:
180 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
181 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
182
183out_unmap_regs:
184 of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len);
185
186out_clear_map:
187 clear_bit(slot, dma_slot_map);
188
189out_err:
190 return err;
191}
192
193static int __devexit ecpp_remove(struct of_device *op)
194{
195 struct parport *p = dev_get_drvdata(&op->dev);
196 int slot = p->dma;
197
198 parport_pc_unregister_port(p);
199
200 if (slot != PARPORT_DMA_NOFIFO) {
201 unsigned long d_base = op->resource[2].start;
202 unsigned long d_len;
203
204 d_len = (op->resource[2].end - d_base) + 1UL;
205
206 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
207 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
208 of_iounmap(&op->resource[2],
209 sparc_ebus_dmas[slot].info.regs,
210 d_len);
211 clear_bit(slot, dma_slot_map);
212 }
213
214 return 0;
215}
216
217static struct of_device_id ecpp_match[] = {
218 {
219 .name = "ecpp",
220 },
221 {
222 .name = "parallel",
223 .compatible = "ecpp",
224 },
225 {
226 .name = "parallel",
227 .compatible = "ns87317-ecpp",
228 },
229 {},
230};
231
232static struct of_platform_driver ecpp_driver = {
233 .name = "ecpp",
234 .match_table = ecpp_match,
235 .probe = ecpp_probe,
236 .remove = __devexit_p(ecpp_remove),
237};
238
239static int parport_pc_find_nonpci_ports(int autoirq, int autodma)
240{
241 of_register_driver(&ecpp_driver, &of_bus_type);
242
243 return 0;
244}
245
246#endif /* !(_ASM_SPARC64_PARPORT_H */
diff --git a/include/asm-sparc64/pci.h b/include/asm-sparc64/pci.h
index f59f2571295b..da54c4d1f39c 100644
--- a/include/asm-sparc64/pci.h
+++ b/include/asm-sparc64/pci.h
@@ -1,209 +1 @@
1#ifndef __SPARC64_PCI_H #include <asm-sparc/pci.h>
2#define __SPARC64_PCI_H
3
4#ifdef __KERNEL__
5
6#include <linux/dma-mapping.h>
7
8/* Can be used to override the logic in pci_scan_bus for skipping
9 * already-configured bus numbers - to be used for buggy BIOSes
10 * or architectures with incomplete PCI setup by the loader.
11 */
12#define pcibios_assign_all_busses() 0
13#define pcibios_scan_all_fns(a, b) 0
14
15#define PCIBIOS_MIN_IO 0UL
16#define PCIBIOS_MIN_MEM 0UL
17
18#define PCI_IRQ_NONE 0xffffffff
19
20#define PCI_CACHE_LINE_BYTES 64
21
22static inline void pcibios_set_master(struct pci_dev *dev)
23{
24 /* No special bus mastering setup handling */
25}
26
27static inline void pcibios_penalize_isa_irq(int irq, int active)
28{
29 /* We don't do dynamic PCI IRQ allocation */
30}
31
32/* The PCI address space does not equal the physical memory
33 * address space. The networking and block device layers use
34 * this boolean for bounce buffer decisions.
35 */
36#define PCI_DMA_BUS_IS_PHYS (0)
37
38static inline void *pci_alloc_consistent(struct pci_dev *pdev, size_t size,
39 dma_addr_t *dma_handle)
40{
41 return dma_alloc_coherent(&pdev->dev, size, dma_handle, GFP_ATOMIC);
42}
43
44static inline void pci_free_consistent(struct pci_dev *pdev, size_t size,
45 void *vaddr, dma_addr_t dma_handle)
46{
47 return dma_free_coherent(&pdev->dev, size, vaddr, dma_handle);
48}
49
50static inline dma_addr_t pci_map_single(struct pci_dev *pdev, void *ptr,
51 size_t size, int direction)
52{
53 return dma_map_single(&pdev->dev, ptr, size,
54 (enum dma_data_direction) direction);
55}
56
57static inline void pci_unmap_single(struct pci_dev *pdev, dma_addr_t dma_addr,
58 size_t size, int direction)
59{
60 dma_unmap_single(&pdev->dev, dma_addr, size,
61 (enum dma_data_direction) direction);
62}
63
64#define pci_map_page(dev, page, off, size, dir) \
65 pci_map_single(dev, (page_address(page) + (off)), size, dir)
66#define pci_unmap_page(dev,addr,sz,dir) \
67 pci_unmap_single(dev,addr,sz,dir)
68
69/* pci_unmap_{single,page} is not a nop, thus... */
70#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
71 dma_addr_t ADDR_NAME;
72#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
73 __u32 LEN_NAME;
74#define pci_unmap_addr(PTR, ADDR_NAME) \
75 ((PTR)->ADDR_NAME)
76#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
77 (((PTR)->ADDR_NAME) = (VAL))
78#define pci_unmap_len(PTR, LEN_NAME) \
79 ((PTR)->LEN_NAME)
80#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
81 (((PTR)->LEN_NAME) = (VAL))
82
83static inline int pci_map_sg(struct pci_dev *pdev, struct scatterlist *sg,
84 int nents, int direction)
85{
86 return dma_map_sg(&pdev->dev, sg, nents,
87 (enum dma_data_direction) direction);
88}
89
90static inline void pci_unmap_sg(struct pci_dev *pdev, struct scatterlist *sg,
91 int nents, int direction)
92{
93 dma_unmap_sg(&pdev->dev, sg, nents,
94 (enum dma_data_direction) direction);
95}
96
97static inline void pci_dma_sync_single_for_cpu(struct pci_dev *pdev,
98 dma_addr_t dma_handle,
99 size_t size, int direction)
100{
101 dma_sync_single_for_cpu(&pdev->dev, dma_handle, size,
102 (enum dma_data_direction) direction);
103}
104
105static inline void pci_dma_sync_single_for_device(struct pci_dev *pdev,
106 dma_addr_t dma_handle,
107 size_t size, int direction)
108{
109 /* No flushing needed to sync cpu writes to the device. */
110}
111
112static inline void pci_dma_sync_sg_for_cpu(struct pci_dev *pdev,
113 struct scatterlist *sg,
114 int nents, int direction)
115{
116 dma_sync_sg_for_cpu(&pdev->dev, sg, nents,
117 (enum dma_data_direction) direction);
118}
119
120static inline void pci_dma_sync_sg_for_device(struct pci_dev *pdev,
121 struct scatterlist *sg,
122 int nelems, int direction)
123{
124 /* No flushing needed to sync cpu writes to the device. */
125}
126
127/* Return whether the given PCI device DMA address mask can
128 * be supported properly. For example, if your device can
129 * only drive the low 24-bits during PCI bus mastering, then
130 * you would pass 0x00ffffff as the mask to this function.
131 */
132extern int pci_dma_supported(struct pci_dev *hwdev, u64 mask);
133
134/* PCI IOMMU mapping bypass support. */
135
136/* PCI 64-bit addressing works for all slots on all controller
137 * types on sparc64. However, it requires that the device
138 * can drive enough of the 64 bits.
139 */
140#define PCI64_REQUIRED_MASK (~(dma64_addr_t)0)
141#define PCI64_ADDR_BASE 0xfffc000000000000UL
142
143static inline int pci_dma_mapping_error(dma_addr_t dma_addr)
144{
145 return dma_mapping_error(dma_addr);
146}
147
148#ifdef CONFIG_PCI
149static inline void pci_dma_burst_advice(struct pci_dev *pdev,
150 enum pci_dma_burst_strategy *strat,
151 unsigned long *strategy_parameter)
152{
153 unsigned long cacheline_size;
154 u8 byte;
155
156 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte);
157 if (byte == 0)
158 cacheline_size = 1024;
159 else
160 cacheline_size = (int) byte * 4;
161
162 *strat = PCI_DMA_BURST_BOUNDARY;
163 *strategy_parameter = cacheline_size;
164}
165#endif
166
167/* Return the index of the PCI controller for device PDEV. */
168
169extern int pci_domain_nr(struct pci_bus *bus);
170static inline int pci_proc_domain(struct pci_bus *bus)
171{
172 return 1;
173}
174
175/* Platform support for /proc/bus/pci/X/Y mmap()s. */
176
177#define HAVE_PCI_MMAP
178#define HAVE_ARCH_PCI_GET_UNMAPPED_AREA
179#define get_pci_unmapped_area get_fb_unmapped_area
180
181extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
182 enum pci_mmap_state mmap_state,
183 int write_combine);
184
185extern void
186pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
187 struct resource *res);
188
189extern void
190pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
191 struct pci_bus_region *region);
192
193extern struct resource *pcibios_select_root(struct pci_dev *, struct resource *);
194
195static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
196{
197 return PCI_IRQ_NONE;
198}
199
200struct device_node;
201extern struct device_node *pci_device_to_OF_node(struct pci_dev *pdev);
202
203#define HAVE_ARCH_PCI_RESOURCE_TO_USER
204extern void pci_resource_to_user(const struct pci_dev *dev, int bar,
205 const struct resource *rsrc,
206 resource_size_t *start, resource_size_t *end);
207#endif /* __KERNEL__ */
208
209#endif /* __SPARC64_PCI_H */
diff --git a/include/asm-sparc64/percpu.h b/include/asm-sparc64/percpu.h
index bee64593023e..292729bb350f 100644
--- a/include/asm-sparc64/percpu.h
+++ b/include/asm-sparc64/percpu.h
@@ -1,28 +1 @@
1#ifndef __ARCH_SPARC64_PERCPU__ #include <asm-sparc/percpu.h>
2#define __ARCH_SPARC64_PERCPU__
3
4#include <linux/compiler.h>
5
6register unsigned long __local_per_cpu_offset asm("g5");
7
8#ifdef CONFIG_SMP
9
10extern void real_setup_per_cpu_areas(void);
11
12extern unsigned long __per_cpu_base;
13extern unsigned long __per_cpu_shift;
14#define __per_cpu_offset(__cpu) \
15 (__per_cpu_base + ((unsigned long)(__cpu) << __per_cpu_shift))
16#define per_cpu_offset(x) (__per_cpu_offset(x))
17
18#define __my_cpu_offset __local_per_cpu_offset
19
20#else /* ! SMP */
21
22#define real_setup_per_cpu_areas() do { } while (0)
23
24#endif /* SMP */
25
26#include <asm-generic/percpu.h>
27
28#endif /* __ARCH_SPARC64_PERCPU__ */
diff --git a/include/asm-sparc64/perfctr.h b/include/asm-sparc64/perfctr.h
index 836873002b75..52073a9f8e30 100644
--- a/include/asm-sparc64/perfctr.h
+++ b/include/asm-sparc64/perfctr.h
@@ -1,173 +1 @@
1/*---------------------------------------- #include <asm-sparc/perfctr.h>
2 PERFORMANCE INSTRUMENTATION
3 Guillaume Thouvenin 08/10/98
4 David S. Miller 10/06/98
5 ---------------------------------------*/
6#ifndef PERF_COUNTER_API
7#define PERF_COUNTER_API
8
9/* sys_perfctr() interface. First arg is operation code
10 * from enumeration below. The meaning of further arguments
11 * are determined by the operation code.
12 *
13 * int sys_perfctr(int opcode, unsigned long arg0,
14 * unsigned long arg1, unsigned long arg2)
15 *
16 * Pointers which are passed by the user are pointers to 64-bit
17 * integers.
18 *
19 * Once enabled, performance counter state is retained until the
20 * process either exits or performs an exec. That is, performance
21 * counters remain enabled for fork/clone children.
22 */
23enum perfctr_opcode {
24 /* Enable UltraSparc performance counters, ARG0 is pointer
25 * to 64-bit accumulator for D0 counter in PIC, ARG1 is pointer
26 * to 64-bit accumulator for D1 counter. ARG2 is a pointer to
27 * the initial PCR register value to use.
28 */
29 PERFCTR_ON,
30
31 /* Disable UltraSparc performance counters. The PCR is written
32 * with zero and the user counter accumulator pointers and
33 * working PCR register value are forgotten.
34 */
35 PERFCTR_OFF,
36
37 /* Add current D0 and D1 PIC values into user pointers given
38 * in PERFCTR_ON operation. The PIC is cleared before returning.
39 */
40 PERFCTR_READ,
41
42 /* Clear the PIC register. */
43 PERFCTR_CLRPIC,
44
45 /* Begin using a new PCR value, the pointer to which is passed
46 * in ARG0. The PIC is also cleared after the new PCR value is
47 * written.
48 */
49 PERFCTR_SETPCR,
50
51 /* Store in pointer given in ARG0 the current PCR register value
52 * being used.
53 */
54 PERFCTR_GETPCR
55};
56
57/* I don't want the kernel's namespace to be polluted with this
58 * stuff when this file is included. --DaveM
59 */
60#ifndef __KERNEL__
61
62#define PRIV 0x00000001
63#define SYS 0x00000002
64#define USR 0x00000004
65
66/* Pic.S0 Selection Bit Field Encoding, Ultra-I/II */
67#define CYCLE_CNT 0x00000000
68#define INSTR_CNT 0x00000010
69#define DISPATCH0_IC_MISS 0x00000020
70#define DISPATCH0_STOREBUF 0x00000030
71#define IC_REF 0x00000080
72#define DC_RD 0x00000090
73#define DC_WR 0x000000A0
74#define LOAD_USE 0x000000B0
75#define EC_REF 0x000000C0
76#define EC_WRITE_HIT_RDO 0x000000D0
77#define EC_SNOOP_INV 0x000000E0
78#define EC_RD_HIT 0x000000F0
79
80/* Pic.S0 Selection Bit Field Encoding, Ultra-III */
81#define US3_CYCLE_CNT 0x00000000
82#define US3_INSTR_CNT 0x00000010
83#define US3_DISPATCH0_IC_MISS 0x00000020
84#define US3_DISPATCH0_BR_TGT 0x00000030
85#define US3_DISPATCH0_2ND_BR 0x00000040
86#define US3_RSTALL_STOREQ 0x00000050
87#define US3_RSTALL_IU_USE 0x00000060
88#define US3_IC_REF 0x00000080
89#define US3_DC_RD 0x00000090
90#define US3_DC_WR 0x000000a0
91#define US3_EC_REF 0x000000c0
92#define US3_EC_WR_HIT_RTO 0x000000d0
93#define US3_EC_SNOOP_INV 0x000000e0
94#define US3_EC_RD_MISS 0x000000f0
95#define US3_PC_PORT0_RD 0x00000100
96#define US3_SI_SNOOP 0x00000110
97#define US3_SI_CIQ_FLOW 0x00000120
98#define US3_SI_OWNED 0x00000130
99#define US3_SW_COUNT_0 0x00000140
100#define US3_IU_BR_MISS_TAKEN 0x00000150
101#define US3_IU_BR_COUNT_TAKEN 0x00000160
102#define US3_DISP_RS_MISPRED 0x00000170
103#define US3_FA_PIPE_COMPL 0x00000180
104#define US3_MC_READS_0 0x00000200
105#define US3_MC_READS_1 0x00000210
106#define US3_MC_READS_2 0x00000220
107#define US3_MC_READS_3 0x00000230
108#define US3_MC_STALLS_0 0x00000240
109#define US3_MC_STALLS_2 0x00000250
110
111/* Pic.S1 Selection Bit Field Encoding, Ultra-I/II */
112#define CYCLE_CNT_D1 0x00000000
113#define INSTR_CNT_D1 0x00000800
114#define DISPATCH0_IC_MISPRED 0x00001000
115#define DISPATCH0_FP_USE 0x00001800
116#define IC_HIT 0x00004000
117#define DC_RD_HIT 0x00004800
118#define DC_WR_HIT 0x00005000
119#define LOAD_USE_RAW 0x00005800
120#define EC_HIT 0x00006000
121#define EC_WB 0x00006800
122#define EC_SNOOP_CB 0x00007000
123#define EC_IT_HIT 0x00007800
124
125/* Pic.S1 Selection Bit Field Encoding, Ultra-III */
126#define US3_CYCLE_CNT_D1 0x00000000
127#define US3_INSTR_CNT_D1 0x00000800
128#define US3_DISPATCH0_MISPRED 0x00001000
129#define US3_IC_MISS_CANCELLED 0x00001800
130#define US3_RE_ENDIAN_MISS 0x00002000
131#define US3_RE_FPU_BYPASS 0x00002800
132#define US3_RE_DC_MISS 0x00003000
133#define US3_RE_EC_MISS 0x00003800
134#define US3_IC_MISS 0x00004000
135#define US3_DC_RD_MISS 0x00004800
136#define US3_DC_WR_MISS 0x00005000
137#define US3_RSTALL_FP_USE 0x00005800
138#define US3_EC_MISSES 0x00006000
139#define US3_EC_WB 0x00006800
140#define US3_EC_SNOOP_CB 0x00007000
141#define US3_EC_IC_MISS 0x00007800
142#define US3_RE_PC_MISS 0x00008000
143#define US3_ITLB_MISS 0x00008800
144#define US3_DTLB_MISS 0x00009000
145#define US3_WC_MISS 0x00009800
146#define US3_WC_SNOOP_CB 0x0000a000
147#define US3_WC_SCRUBBED 0x0000a800
148#define US3_WC_WB_WO_READ 0x0000b000
149#define US3_PC_SOFT_HIT 0x0000c000
150#define US3_PC_SNOOP_INV 0x0000c800
151#define US3_PC_HARD_HIT 0x0000d000
152#define US3_PC_PORT1_RD 0x0000d800
153#define US3_SW_COUNT_1 0x0000e000
154#define US3_IU_STAT_BR_MIS_UNTAKEN 0x0000e800
155#define US3_IU_STAT_BR_COUNT_UNTAKEN 0x0000f000
156#define US3_PC_MS_MISSES 0x0000f800
157#define US3_MC_WRITES_0 0x00010800
158#define US3_MC_WRITES_1 0x00011000
159#define US3_MC_WRITES_2 0x00011800
160#define US3_MC_WRITES_3 0x00012000
161#define US3_MC_STALLS_1 0x00012800
162#define US3_MC_STALLS_3 0x00013000
163#define US3_RE_RAW_MISS 0x00013800
164#define US3_FM_PIPE_COMPLETION 0x00014000
165
166struct vcounter_struct {
167 unsigned long long vcnt0;
168 unsigned long long vcnt1;
169};
170
171#endif /* !(__KERNEL__) */
172
173#endif /* !(PERF_COUNTER_API) */
diff --git a/include/asm-sparc64/pgalloc.h b/include/asm-sparc64/pgalloc.h
index 326de104d014..bec31641011c 100644
--- a/include/asm-sparc64/pgalloc.h
+++ b/include/asm-sparc64/pgalloc.h
@@ -1,81 +1 @@
1#ifndef _SPARC64_PGALLOC_H #include <asm-sparc/pgalloc.h>
2#define _SPARC64_PGALLOC_H
3
4#include <linux/kernel.h>
5#include <linux/sched.h>
6#include <linux/mm.h>
7#include <linux/slab.h>
8#include <linux/quicklist.h>
9
10#include <asm/spitfire.h>
11#include <asm/cpudata.h>
12#include <asm/cacheflush.h>
13#include <asm/page.h>
14
15/* Page table allocation/freeing. */
16
17static inline pgd_t *pgd_alloc(struct mm_struct *mm)
18{
19 return quicklist_alloc(0, GFP_KERNEL, NULL);
20}
21
22static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
23{
24 quicklist_free(0, NULL, pgd);
25}
26
27#define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
28
29static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
30{
31 return quicklist_alloc(0, GFP_KERNEL, NULL);
32}
33
34static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
35{
36 quicklist_free(0, NULL, pmd);
37}
38
39static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
40 unsigned long address)
41{
42 return quicklist_alloc(0, GFP_KERNEL, NULL);
43}
44
45static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
46 unsigned long address)
47{
48 struct page *page;
49 void *pg;
50
51 pg = quicklist_alloc(0, GFP_KERNEL, NULL);
52 if (!pg)
53 return NULL;
54 page = virt_to_page(pg);
55 pgtable_page_ctor(page);
56 return page;
57}
58
59static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
60{
61 quicklist_free(0, NULL, pte);
62}
63
64static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
65{
66 pgtable_page_dtor(ptepage);
67 quicklist_free_page(0, NULL, ptepage);
68}
69
70
71#define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
72#define pmd_populate(MM,PMD,PTE_PAGE) \
73 pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
74#define pmd_pgtable(pmd) pmd_page(pmd)
75
76static inline void check_pgt_cache(void)
77{
78 quicklist_trim(0, NULL, 25, 16);
79}
80
81#endif /* _SPARC64_PGALLOC_H */
diff --git a/include/asm-sparc64/pgtable.h b/include/asm-sparc64/pgtable.h
index b87017747b5d..9decbd99aeff 100644
--- a/include/asm-sparc64/pgtable.h
+++ b/include/asm-sparc64/pgtable.h
@@ -1,781 +1 @@
1/* #include <asm-sparc/pgtable.h>
2 * pgtable.h: SpitFire page table operations.
3 *
4 * Copyright 1996,1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7
8#ifndef _SPARC64_PGTABLE_H
9#define _SPARC64_PGTABLE_H
10
11/* This file contains the functions and defines necessary to modify and use
12 * the SpitFire page tables.
13 */
14
15#include <asm-generic/pgtable-nopud.h>
16
17#include <linux/compiler.h>
18#include <linux/const.h>
19#include <asm/types.h>
20#include <asm/spitfire.h>
21#include <asm/asi.h>
22#include <asm/system.h>
23#include <asm/page.h>
24#include <asm/processor.h>
25
26/* The kernel image occupies 0x4000000 to 0x6000000 (4MB --> 96MB).
27 * The page copy blockops can use 0x6000000 to 0x8000000.
28 * The TSB is mapped in the 0x8000000 to 0xa000000 range.
29 * The PROM resides in an area spanning 0xf0000000 to 0x100000000.
30 * The vmalloc area spans 0x100000000 to 0x200000000.
31 * Since modules need to be in the lowest 32-bits of the address space,
32 * we place them right before the OBP area from 0x10000000 to 0xf0000000.
33 * There is a single static kernel PMD which maps from 0x0 to address
34 * 0x400000000.
35 */
36#define TLBTEMP_BASE _AC(0x0000000006000000,UL)
37#define TSBMAP_BASE _AC(0x0000000008000000,UL)
38#define MODULES_VADDR _AC(0x0000000010000000,UL)
39#define MODULES_LEN _AC(0x00000000e0000000,UL)
40#define MODULES_END _AC(0x00000000f0000000,UL)
41#define LOW_OBP_ADDRESS _AC(0x00000000f0000000,UL)
42#define HI_OBP_ADDRESS _AC(0x0000000100000000,UL)
43#define VMALLOC_START _AC(0x0000000100000000,UL)
44#define VMALLOC_END _AC(0x0000000200000000,UL)
45#define VMEMMAP_BASE _AC(0x0000000200000000,UL)
46
47#define vmemmap ((struct page *)VMEMMAP_BASE)
48
49/* XXX All of this needs to be rethought so we can take advantage
50 * XXX cheetah's full 64-bit virtual address space, ie. no more hole
51 * XXX in the middle like on spitfire. -DaveM
52 */
53/*
54 * Given a virtual address, the lowest PAGE_SHIFT bits determine offset
55 * into the page; the next higher PAGE_SHIFT-3 bits determine the pte#
56 * in the proper pagetable (the -3 is from the 8 byte ptes, and each page
57 * table is a single page long). The next higher PMD_BITS determine pmd#
58 * in the proper pmdtable (where we must have PMD_BITS <= (PAGE_SHIFT-2)
59 * since the pmd entries are 4 bytes, and each pmd page is a single page
60 * long). Finally, the higher few bits determine pgde#.
61 */
62
63/* PMD_SHIFT determines the size of the area a second-level page
64 * table can map
65 */
66#define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3))
67#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
68#define PMD_MASK (~(PMD_SIZE-1))
69#define PMD_BITS (PAGE_SHIFT - 2)
70
71/* PGDIR_SHIFT determines what a third-level page table entry can map */
72#define PGDIR_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3) + PMD_BITS)
73#define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
74#define PGDIR_MASK (~(PGDIR_SIZE-1))
75#define PGDIR_BITS (PAGE_SHIFT - 2)
76
77#ifndef __ASSEMBLY__
78
79#include <linux/sched.h>
80
81/* Entries per page directory level. */
82#define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
83#define PTRS_PER_PMD (1UL << PMD_BITS)
84#define PTRS_PER_PGD (1UL << PGDIR_BITS)
85
86/* Kernel has a separate 44bit address space. */
87#define FIRST_USER_ADDRESS 0
88
89#define pte_ERROR(e) __builtin_trap()
90#define pmd_ERROR(e) __builtin_trap()
91#define pgd_ERROR(e) __builtin_trap()
92
93#endif /* !(__ASSEMBLY__) */
94
95/* PTE bits which are the same in SUN4U and SUN4V format. */
96#define _PAGE_VALID _AC(0x8000000000000000,UL) /* Valid TTE */
97#define _PAGE_R _AC(0x8000000000000000,UL) /* Keep ref bit uptodate*/
98
99/* SUN4U pte bits... */
100#define _PAGE_SZ4MB_4U _AC(0x6000000000000000,UL) /* 4MB Page */
101#define _PAGE_SZ512K_4U _AC(0x4000000000000000,UL) /* 512K Page */
102#define _PAGE_SZ64K_4U _AC(0x2000000000000000,UL) /* 64K Page */
103#define _PAGE_SZ8K_4U _AC(0x0000000000000000,UL) /* 8K Page */
104#define _PAGE_NFO_4U _AC(0x1000000000000000,UL) /* No Fault Only */
105#define _PAGE_IE_4U _AC(0x0800000000000000,UL) /* Invert Endianness */
106#define _PAGE_SOFT2_4U _AC(0x07FC000000000000,UL) /* Software bits, set 2 */
107#define _PAGE_RES1_4U _AC(0x0002000000000000,UL) /* Reserved */
108#define _PAGE_SZ32MB_4U _AC(0x0001000000000000,UL) /* (Panther) 32MB page */
109#define _PAGE_SZ256MB_4U _AC(0x2001000000000000,UL) /* (Panther) 256MB page */
110#define _PAGE_SZALL_4U _AC(0x6001000000000000,UL) /* All pgsz bits */
111#define _PAGE_SN_4U _AC(0x0000800000000000,UL) /* (Cheetah) Snoop */
112#define _PAGE_RES2_4U _AC(0x0000780000000000,UL) /* Reserved */
113#define _PAGE_PADDR_4U _AC(0x000007FFFFFFE000,UL) /* (Cheetah) pa[42:13] */
114#define _PAGE_SOFT_4U _AC(0x0000000000001F80,UL) /* Software bits: */
115#define _PAGE_EXEC_4U _AC(0x0000000000001000,UL) /* Executable SW bit */
116#define _PAGE_MODIFIED_4U _AC(0x0000000000000800,UL) /* Modified (dirty) */
117#define _PAGE_FILE_4U _AC(0x0000000000000800,UL) /* Pagecache page */
118#define _PAGE_ACCESSED_4U _AC(0x0000000000000400,UL) /* Accessed (ref'd) */
119#define _PAGE_READ_4U _AC(0x0000000000000200,UL) /* Readable SW Bit */
120#define _PAGE_WRITE_4U _AC(0x0000000000000100,UL) /* Writable SW Bit */
121#define _PAGE_PRESENT_4U _AC(0x0000000000000080,UL) /* Present */
122#define _PAGE_L_4U _AC(0x0000000000000040,UL) /* Locked TTE */
123#define _PAGE_CP_4U _AC(0x0000000000000020,UL) /* Cacheable in P-Cache */
124#define _PAGE_CV_4U _AC(0x0000000000000010,UL) /* Cacheable in V-Cache */
125#define _PAGE_E_4U _AC(0x0000000000000008,UL) /* side-Effect */
126#define _PAGE_P_4U _AC(0x0000000000000004,UL) /* Privileged Page */
127#define _PAGE_W_4U _AC(0x0000000000000002,UL) /* Writable */
128
129/* SUN4V pte bits... */
130#define _PAGE_NFO_4V _AC(0x4000000000000000,UL) /* No Fault Only */
131#define _PAGE_SOFT2_4V _AC(0x3F00000000000000,UL) /* Software bits, set 2 */
132#define _PAGE_MODIFIED_4V _AC(0x2000000000000000,UL) /* Modified (dirty) */
133#define _PAGE_ACCESSED_4V _AC(0x1000000000000000,UL) /* Accessed (ref'd) */
134#define _PAGE_READ_4V _AC(0x0800000000000000,UL) /* Readable SW Bit */
135#define _PAGE_WRITE_4V _AC(0x0400000000000000,UL) /* Writable SW Bit */
136#define _PAGE_PADDR_4V _AC(0x00FFFFFFFFFFE000,UL) /* paddr[55:13] */
137#define _PAGE_IE_4V _AC(0x0000000000001000,UL) /* Invert Endianness */
138#define _PAGE_E_4V _AC(0x0000000000000800,UL) /* side-Effect */
139#define _PAGE_CP_4V _AC(0x0000000000000400,UL) /* Cacheable in P-Cache */
140#define _PAGE_CV_4V _AC(0x0000000000000200,UL) /* Cacheable in V-Cache */
141#define _PAGE_P_4V _AC(0x0000000000000100,UL) /* Privileged Page */
142#define _PAGE_EXEC_4V _AC(0x0000000000000080,UL) /* Executable Page */
143#define _PAGE_W_4V _AC(0x0000000000000040,UL) /* Writable */
144#define _PAGE_SOFT_4V _AC(0x0000000000000030,UL) /* Software bits */
145#define _PAGE_FILE_4V _AC(0x0000000000000020,UL) /* Pagecache page */
146#define _PAGE_PRESENT_4V _AC(0x0000000000000010,UL) /* Present */
147#define _PAGE_RESV_4V _AC(0x0000000000000008,UL) /* Reserved */
148#define _PAGE_SZ16GB_4V _AC(0x0000000000000007,UL) /* 16GB Page */
149#define _PAGE_SZ2GB_4V _AC(0x0000000000000006,UL) /* 2GB Page */
150#define _PAGE_SZ256MB_4V _AC(0x0000000000000005,UL) /* 256MB Page */
151#define _PAGE_SZ32MB_4V _AC(0x0000000000000004,UL) /* 32MB Page */
152#define _PAGE_SZ4MB_4V _AC(0x0000000000000003,UL) /* 4MB Page */
153#define _PAGE_SZ512K_4V _AC(0x0000000000000002,UL) /* 512K Page */
154#define _PAGE_SZ64K_4V _AC(0x0000000000000001,UL) /* 64K Page */
155#define _PAGE_SZ8K_4V _AC(0x0000000000000000,UL) /* 8K Page */
156#define _PAGE_SZALL_4V _AC(0x0000000000000007,UL) /* All pgsz bits */
157
158#if PAGE_SHIFT == 13
159#define _PAGE_SZBITS_4U _PAGE_SZ8K_4U
160#define _PAGE_SZBITS_4V _PAGE_SZ8K_4V
161#elif PAGE_SHIFT == 16
162#define _PAGE_SZBITS_4U _PAGE_SZ64K_4U
163#define _PAGE_SZBITS_4V _PAGE_SZ64K_4V
164#elif PAGE_SHIFT == 19
165#define _PAGE_SZBITS_4U _PAGE_SZ512K_4U
166#define _PAGE_SZBITS_4V _PAGE_SZ512K_4V
167#elif PAGE_SHIFT == 22
168#define _PAGE_SZBITS_4U _PAGE_SZ4MB_4U
169#define _PAGE_SZBITS_4V _PAGE_SZ4MB_4V
170#else
171#error Wrong PAGE_SHIFT specified
172#endif
173
174#if defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
175#define _PAGE_SZHUGE_4U _PAGE_SZ4MB_4U
176#define _PAGE_SZHUGE_4V _PAGE_SZ4MB_4V
177#elif defined(CONFIG_HUGETLB_PAGE_SIZE_512K)
178#define _PAGE_SZHUGE_4U _PAGE_SZ512K_4U
179#define _PAGE_SZHUGE_4V _PAGE_SZ512K_4V
180#elif defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
181#define _PAGE_SZHUGE_4U _PAGE_SZ64K_4U
182#define _PAGE_SZHUGE_4V _PAGE_SZ64K_4V
183#endif
184
185/* These are actually filled in at boot time by sun4{u,v}_pgprot_init() */
186#define __P000 __pgprot(0)
187#define __P001 __pgprot(0)
188#define __P010 __pgprot(0)
189#define __P011 __pgprot(0)
190#define __P100 __pgprot(0)
191#define __P101 __pgprot(0)
192#define __P110 __pgprot(0)
193#define __P111 __pgprot(0)
194
195#define __S000 __pgprot(0)
196#define __S001 __pgprot(0)
197#define __S010 __pgprot(0)
198#define __S011 __pgprot(0)
199#define __S100 __pgprot(0)
200#define __S101 __pgprot(0)
201#define __S110 __pgprot(0)
202#define __S111 __pgprot(0)
203
204#ifndef __ASSEMBLY__
205
206extern pte_t mk_pte_io(unsigned long, pgprot_t, int, unsigned long);
207
208extern unsigned long pte_sz_bits(unsigned long size);
209
210extern pgprot_t PAGE_KERNEL;
211extern pgprot_t PAGE_KERNEL_LOCKED;
212extern pgprot_t PAGE_COPY;
213extern pgprot_t PAGE_SHARED;
214
215/* XXX This uglyness is for the atyfb driver's sparc mmap() support. XXX */
216extern unsigned long _PAGE_IE;
217extern unsigned long _PAGE_E;
218extern unsigned long _PAGE_CACHE;
219
220extern unsigned long pg_iobits;
221extern unsigned long _PAGE_ALL_SZ_BITS;
222extern unsigned long _PAGE_SZBITS;
223
224extern struct page *mem_map_zero;
225#define ZERO_PAGE(vaddr) (mem_map_zero)
226
227/* PFNs are real physical page numbers. However, mem_map only begins to record
228 * per-page information starting at pfn_base. This is to handle systems where
229 * the first physical page in the machine is at some huge physical address,
230 * such as 4GB. This is common on a partitioned E10000, for example.
231 */
232static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
233{
234 unsigned long paddr = pfn << PAGE_SHIFT;
235 unsigned long sz_bits;
236
237 sz_bits = 0UL;
238 if (_PAGE_SZBITS_4U != 0UL || _PAGE_SZBITS_4V != 0UL) {
239 __asm__ __volatile__(
240 "\n661: sethi %%uhi(%1), %0\n"
241 " sllx %0, 32, %0\n"
242 " .section .sun4v_2insn_patch, \"ax\"\n"
243 " .word 661b\n"
244 " mov %2, %0\n"
245 " nop\n"
246 " .previous\n"
247 : "=r" (sz_bits)
248 : "i" (_PAGE_SZBITS_4U), "i" (_PAGE_SZBITS_4V));
249 }
250 return __pte(paddr | sz_bits | pgprot_val(prot));
251}
252#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
253
254/* This one can be done with two shifts. */
255static inline unsigned long pte_pfn(pte_t pte)
256{
257 unsigned long ret;
258
259 __asm__ __volatile__(
260 "\n661: sllx %1, %2, %0\n"
261 " srlx %0, %3, %0\n"
262 " .section .sun4v_2insn_patch, \"ax\"\n"
263 " .word 661b\n"
264 " sllx %1, %4, %0\n"
265 " srlx %0, %5, %0\n"
266 " .previous\n"
267 : "=r" (ret)
268 : "r" (pte_val(pte)),
269 "i" (21), "i" (21 + PAGE_SHIFT),
270 "i" (8), "i" (8 + PAGE_SHIFT));
271
272 return ret;
273}
274#define pte_page(x) pfn_to_page(pte_pfn(x))
275
276static inline pte_t pte_modify(pte_t pte, pgprot_t prot)
277{
278 unsigned long mask, tmp;
279
280 /* SUN4U: 0x600307ffffffecb8 (negated == 0x9ffcf80000001347)
281 * SUN4V: 0x30ffffffffffee17 (negated == 0xcf000000000011e8)
282 *
283 * Even if we use negation tricks the result is still a 6
284 * instruction sequence, so don't try to play fancy and just
285 * do the most straightforward implementation.
286 *
287 * Note: We encode this into 3 sun4v 2-insn patch sequences.
288 */
289
290 __asm__ __volatile__(
291 "\n661: sethi %%uhi(%2), %1\n"
292 " sethi %%hi(%2), %0\n"
293 "\n662: or %1, %%ulo(%2), %1\n"
294 " or %0, %%lo(%2), %0\n"
295 "\n663: sllx %1, 32, %1\n"
296 " or %0, %1, %0\n"
297 " .section .sun4v_2insn_patch, \"ax\"\n"
298 " .word 661b\n"
299 " sethi %%uhi(%3), %1\n"
300 " sethi %%hi(%3), %0\n"
301 " .word 662b\n"
302 " or %1, %%ulo(%3), %1\n"
303 " or %0, %%lo(%3), %0\n"
304 " .word 663b\n"
305 " sllx %1, 32, %1\n"
306 " or %0, %1, %0\n"
307 " .previous\n"
308 : "=r" (mask), "=r" (tmp)
309 : "i" (_PAGE_PADDR_4U | _PAGE_MODIFIED_4U | _PAGE_ACCESSED_4U |
310 _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_E_4U | _PAGE_PRESENT_4U |
311 _PAGE_SZBITS_4U),
312 "i" (_PAGE_PADDR_4V | _PAGE_MODIFIED_4V | _PAGE_ACCESSED_4V |
313 _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_E_4V | _PAGE_PRESENT_4V |
314 _PAGE_SZBITS_4V));
315
316 return __pte((pte_val(pte) & mask) | (pgprot_val(prot) & ~mask));
317}
318
319static inline pte_t pgoff_to_pte(unsigned long off)
320{
321 off <<= PAGE_SHIFT;
322
323 __asm__ __volatile__(
324 "\n661: or %0, %2, %0\n"
325 " .section .sun4v_1insn_patch, \"ax\"\n"
326 " .word 661b\n"
327 " or %0, %3, %0\n"
328 " .previous\n"
329 : "=r" (off)
330 : "0" (off), "i" (_PAGE_FILE_4U), "i" (_PAGE_FILE_4V));
331
332 return __pte(off);
333}
334
335static inline pgprot_t pgprot_noncached(pgprot_t prot)
336{
337 unsigned long val = pgprot_val(prot);
338
339 __asm__ __volatile__(
340 "\n661: andn %0, %2, %0\n"
341 " or %0, %3, %0\n"
342 " .section .sun4v_2insn_patch, \"ax\"\n"
343 " .word 661b\n"
344 " andn %0, %4, %0\n"
345 " or %0, %5, %0\n"
346 " .previous\n"
347 : "=r" (val)
348 : "0" (val), "i" (_PAGE_CP_4U | _PAGE_CV_4U), "i" (_PAGE_E_4U),
349 "i" (_PAGE_CP_4V | _PAGE_CV_4V), "i" (_PAGE_E_4V));
350
351 return __pgprot(val);
352}
353/* Various pieces of code check for platform support by ifdef testing
354 * on "pgprot_noncached". That's broken and should be fixed, but for
355 * now...
356 */
357#define pgprot_noncached pgprot_noncached
358
359#ifdef CONFIG_HUGETLB_PAGE
360static inline pte_t pte_mkhuge(pte_t pte)
361{
362 unsigned long mask;
363
364 __asm__ __volatile__(
365 "\n661: sethi %%uhi(%1), %0\n"
366 " sllx %0, 32, %0\n"
367 " .section .sun4v_2insn_patch, \"ax\"\n"
368 " .word 661b\n"
369 " mov %2, %0\n"
370 " nop\n"
371 " .previous\n"
372 : "=r" (mask)
373 : "i" (_PAGE_SZHUGE_4U), "i" (_PAGE_SZHUGE_4V));
374
375 return __pte(pte_val(pte) | mask);
376}
377#endif
378
379static inline pte_t pte_mkdirty(pte_t pte)
380{
381 unsigned long val = pte_val(pte), tmp;
382
383 __asm__ __volatile__(
384 "\n661: or %0, %3, %0\n"
385 " nop\n"
386 "\n662: nop\n"
387 " nop\n"
388 " .section .sun4v_2insn_patch, \"ax\"\n"
389 " .word 661b\n"
390 " sethi %%uhi(%4), %1\n"
391 " sllx %1, 32, %1\n"
392 " .word 662b\n"
393 " or %1, %%lo(%4), %1\n"
394 " or %0, %1, %0\n"
395 " .previous\n"
396 : "=r" (val), "=r" (tmp)
397 : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
398 "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
399
400 return __pte(val);
401}
402
403static inline pte_t pte_mkclean(pte_t pte)
404{
405 unsigned long val = pte_val(pte), tmp;
406
407 __asm__ __volatile__(
408 "\n661: andn %0, %3, %0\n"
409 " nop\n"
410 "\n662: nop\n"
411 " nop\n"
412 " .section .sun4v_2insn_patch, \"ax\"\n"
413 " .word 661b\n"
414 " sethi %%uhi(%4), %1\n"
415 " sllx %1, 32, %1\n"
416 " .word 662b\n"
417 " or %1, %%lo(%4), %1\n"
418 " andn %0, %1, %0\n"
419 " .previous\n"
420 : "=r" (val), "=r" (tmp)
421 : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
422 "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
423
424 return __pte(val);
425}
426
427static inline pte_t pte_mkwrite(pte_t pte)
428{
429 unsigned long val = pte_val(pte), mask;
430
431 __asm__ __volatile__(
432 "\n661: mov %1, %0\n"
433 " nop\n"
434 " .section .sun4v_2insn_patch, \"ax\"\n"
435 " .word 661b\n"
436 " sethi %%uhi(%2), %0\n"
437 " sllx %0, 32, %0\n"
438 " .previous\n"
439 : "=r" (mask)
440 : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
441
442 return __pte(val | mask);
443}
444
445static inline pte_t pte_wrprotect(pte_t pte)
446{
447 unsigned long val = pte_val(pte), tmp;
448
449 __asm__ __volatile__(
450 "\n661: andn %0, %3, %0\n"
451 " nop\n"
452 "\n662: nop\n"
453 " nop\n"
454 " .section .sun4v_2insn_patch, \"ax\"\n"
455 " .word 661b\n"
456 " sethi %%uhi(%4), %1\n"
457 " sllx %1, 32, %1\n"
458 " .word 662b\n"
459 " or %1, %%lo(%4), %1\n"
460 " andn %0, %1, %0\n"
461 " .previous\n"
462 : "=r" (val), "=r" (tmp)
463 : "0" (val), "i" (_PAGE_WRITE_4U | _PAGE_W_4U),
464 "i" (_PAGE_WRITE_4V | _PAGE_W_4V));
465
466 return __pte(val);
467}
468
469static inline pte_t pte_mkold(pte_t pte)
470{
471 unsigned long mask;
472
473 __asm__ __volatile__(
474 "\n661: mov %1, %0\n"
475 " nop\n"
476 " .section .sun4v_2insn_patch, \"ax\"\n"
477 " .word 661b\n"
478 " sethi %%uhi(%2), %0\n"
479 " sllx %0, 32, %0\n"
480 " .previous\n"
481 : "=r" (mask)
482 : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
483
484 mask |= _PAGE_R;
485
486 return __pte(pte_val(pte) & ~mask);
487}
488
489static inline pte_t pte_mkyoung(pte_t pte)
490{
491 unsigned long mask;
492
493 __asm__ __volatile__(
494 "\n661: mov %1, %0\n"
495 " nop\n"
496 " .section .sun4v_2insn_patch, \"ax\"\n"
497 " .word 661b\n"
498 " sethi %%uhi(%2), %0\n"
499 " sllx %0, 32, %0\n"
500 " .previous\n"
501 : "=r" (mask)
502 : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
503
504 mask |= _PAGE_R;
505
506 return __pte(pte_val(pte) | mask);
507}
508
509static inline pte_t pte_mkspecial(pte_t pte)
510{
511 return pte;
512}
513
514static inline unsigned long pte_young(pte_t pte)
515{
516 unsigned long mask;
517
518 __asm__ __volatile__(
519 "\n661: mov %1, %0\n"
520 " nop\n"
521 " .section .sun4v_2insn_patch, \"ax\"\n"
522 " .word 661b\n"
523 " sethi %%uhi(%2), %0\n"
524 " sllx %0, 32, %0\n"
525 " .previous\n"
526 : "=r" (mask)
527 : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
528
529 return (pte_val(pte) & mask);
530}
531
532static inline unsigned long pte_dirty(pte_t pte)
533{
534 unsigned long mask;
535
536 __asm__ __volatile__(
537 "\n661: mov %1, %0\n"
538 " nop\n"
539 " .section .sun4v_2insn_patch, \"ax\"\n"
540 " .word 661b\n"
541 " sethi %%uhi(%2), %0\n"
542 " sllx %0, 32, %0\n"
543 " .previous\n"
544 : "=r" (mask)
545 : "i" (_PAGE_MODIFIED_4U), "i" (_PAGE_MODIFIED_4V));
546
547 return (pte_val(pte) & mask);
548}
549
550static inline unsigned long pte_write(pte_t pte)
551{
552 unsigned long mask;
553
554 __asm__ __volatile__(
555 "\n661: mov %1, %0\n"
556 " nop\n"
557 " .section .sun4v_2insn_patch, \"ax\"\n"
558 " .word 661b\n"
559 " sethi %%uhi(%2), %0\n"
560 " sllx %0, 32, %0\n"
561 " .previous\n"
562 : "=r" (mask)
563 : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
564
565 return (pte_val(pte) & mask);
566}
567
568static inline unsigned long pte_exec(pte_t pte)
569{
570 unsigned long mask;
571
572 __asm__ __volatile__(
573 "\n661: sethi %%hi(%1), %0\n"
574 " .section .sun4v_1insn_patch, \"ax\"\n"
575 " .word 661b\n"
576 " mov %2, %0\n"
577 " .previous\n"
578 : "=r" (mask)
579 : "i" (_PAGE_EXEC_4U), "i" (_PAGE_EXEC_4V));
580
581 return (pte_val(pte) & mask);
582}
583
584static inline unsigned long pte_file(pte_t pte)
585{
586 unsigned long val = pte_val(pte);
587
588 __asm__ __volatile__(
589 "\n661: and %0, %2, %0\n"
590 " .section .sun4v_1insn_patch, \"ax\"\n"
591 " .word 661b\n"
592 " and %0, %3, %0\n"
593 " .previous\n"
594 : "=r" (val)
595 : "0" (val), "i" (_PAGE_FILE_4U), "i" (_PAGE_FILE_4V));
596
597 return val;
598}
599
600static inline unsigned long pte_present(pte_t pte)
601{
602 unsigned long val = pte_val(pte);
603
604 __asm__ __volatile__(
605 "\n661: and %0, %2, %0\n"
606 " .section .sun4v_1insn_patch, \"ax\"\n"
607 " .word 661b\n"
608 " and %0, %3, %0\n"
609 " .previous\n"
610 : "=r" (val)
611 : "0" (val), "i" (_PAGE_PRESENT_4U), "i" (_PAGE_PRESENT_4V));
612
613 return val;
614}
615
616static inline int pte_special(pte_t pte)
617{
618 return 0;
619}
620
621#define pmd_set(pmdp, ptep) \
622 (pmd_val(*(pmdp)) = (__pa((unsigned long) (ptep)) >> 11UL))
623#define pud_set(pudp, pmdp) \
624 (pud_val(*(pudp)) = (__pa((unsigned long) (pmdp)) >> 11UL))
625#define __pmd_page(pmd) \
626 ((unsigned long) __va((((unsigned long)pmd_val(pmd))<<11UL)))
627#define pmd_page(pmd) virt_to_page((void *)__pmd_page(pmd))
628#define pud_page_vaddr(pud) \
629 ((unsigned long) __va((((unsigned long)pud_val(pud))<<11UL)))
630#define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
631#define pmd_none(pmd) (!pmd_val(pmd))
632#define pmd_bad(pmd) (0)
633#define pmd_present(pmd) (pmd_val(pmd) != 0U)
634#define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0U)
635#define pud_none(pud) (!pud_val(pud))
636#define pud_bad(pud) (0)
637#define pud_present(pud) (pud_val(pud) != 0U)
638#define pud_clear(pudp) (pud_val(*(pudp)) = 0U)
639
640/* Same in both SUN4V and SUN4U. */
641#define pte_none(pte) (!pte_val(pte))
642
643/* to find an entry in a page-table-directory. */
644#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
645#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
646
647/* to find an entry in a kernel page-table-directory */
648#define pgd_offset_k(address) pgd_offset(&init_mm, address)
649
650/* Find an entry in the second-level page table.. */
651#define pmd_offset(pudp, address) \
652 ((pmd_t *) pud_page_vaddr(*(pudp)) + \
653 (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)))
654
655/* Find an entry in the third-level page table.. */
656#define pte_index(dir, address) \
657 ((pte_t *) __pmd_page(*(dir)) + \
658 ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
659#define pte_offset_kernel pte_index
660#define pte_offset_map pte_index
661#define pte_offset_map_nested pte_index
662#define pte_unmap(pte) do { } while (0)
663#define pte_unmap_nested(pte) do { } while (0)
664
665/* Actual page table PTE updates. */
666extern void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, pte_t *ptep, pte_t orig);
667
668static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte)
669{
670 pte_t orig = *ptep;
671
672 *ptep = pte;
673
674 /* It is more efficient to let flush_tlb_kernel_range()
675 * handle init_mm tlb flushes.
676 *
677 * SUN4V NOTE: _PAGE_VALID is the same value in both the SUN4U
678 * and SUN4V pte layout, so this inline test is fine.
679 */
680 if (likely(mm != &init_mm) && (pte_val(orig) & _PAGE_VALID))
681 tlb_batch_add(mm, addr, ptep, orig);
682}
683
684#define pte_clear(mm,addr,ptep) \
685 set_pte_at((mm), (addr), (ptep), __pte(0UL))
686
687#ifdef DCACHE_ALIASING_POSSIBLE
688#define __HAVE_ARCH_MOVE_PTE
689#define move_pte(pte, prot, old_addr, new_addr) \
690({ \
691 pte_t newpte = (pte); \
692 if (tlb_type != hypervisor && pte_present(pte)) { \
693 unsigned long this_pfn = pte_pfn(pte); \
694 \
695 if (pfn_valid(this_pfn) && \
696 (((old_addr) ^ (new_addr)) & (1 << 13))) \
697 flush_dcache_page_all(current->mm, \
698 pfn_to_page(this_pfn)); \
699 } \
700 newpte; \
701})
702#endif
703
704extern pgd_t swapper_pg_dir[2048];
705extern pmd_t swapper_low_pmd_dir[2048];
706
707extern void paging_init(void);
708extern unsigned long find_ecache_flush_span(unsigned long size);
709
710/* These do nothing with the way I have things setup. */
711#define mmu_lockarea(vaddr, len) (vaddr)
712#define mmu_unlockarea(vaddr, len) do { } while(0)
713
714struct vm_area_struct;
715extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t);
716
717/* Encode and de-code a swap entry */
718#define __swp_type(entry) (((entry).val >> PAGE_SHIFT) & 0xffUL)
719#define __swp_offset(entry) ((entry).val >> (PAGE_SHIFT + 8UL))
720#define __swp_entry(type, offset) \
721 ( (swp_entry_t) \
722 { \
723 (((long)(type) << PAGE_SHIFT) | \
724 ((long)(offset) << (PAGE_SHIFT + 8UL))) \
725 } )
726#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
727#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
728
729/* File offset in PTE support. */
730extern unsigned long pte_file(pte_t);
731#define pte_to_pgoff(pte) (pte_val(pte) >> PAGE_SHIFT)
732extern pte_t pgoff_to_pte(unsigned long);
733#define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
734
735extern unsigned long *sparc64_valid_addr_bitmap;
736
737/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
738#define kern_addr_valid(addr) \
739 (test_bit(__pa((unsigned long)(addr))>>22, sparc64_valid_addr_bitmap))
740
741extern int page_in_phys_avail(unsigned long paddr);
742
743extern int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
744 unsigned long pfn,
745 unsigned long size, pgprot_t prot);
746
747/*
748 * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
749 * its high 4 bits. These macros/functions put it there or get it from there.
750 */
751#define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
752#define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
753#define GET_PFN(pfn) (pfn & 0x0fffffffffffffffUL)
754
755#include <asm-generic/pgtable.h>
756
757/* We provide our own get_unmapped_area to cope with VA holes and
758 * SHM area cache aliasing for userland.
759 */
760#define HAVE_ARCH_UNMAPPED_AREA
761#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
762
763/* We provide a special get_unmapped_area for framebuffer mmaps to try and use
764 * the largest alignment possible such that larget PTEs can be used.
765 */
766extern unsigned long get_fb_unmapped_area(struct file *filp, unsigned long,
767 unsigned long, unsigned long,
768 unsigned long);
769#define HAVE_ARCH_FB_UNMAPPED_AREA
770
771extern void pgtable_cache_init(void);
772extern void sun4v_register_fault_status(void);
773extern void sun4v_ktsb_register(void);
774extern void __init cheetah_ecache_flush_init(void);
775extern void sun4v_patch_tlb_handlers(void);
776
777extern unsigned long cmdline_memory_size;
778
779#endif /* !(__ASSEMBLY__) */
780
781#endif /* !(_SPARC64_PGTABLE_H) */
diff --git a/include/asm-sparc64/pil.h b/include/asm-sparc64/pil.h
index eaac842d88c3..d805f33f1e0f 100644
--- a/include/asm-sparc64/pil.h
+++ b/include/asm-sparc64/pil.h
@@ -1,21 +1 @@
1#ifndef _SPARC64_PIL_H #include <asm-sparc/pil.h>
2#define _SPARC64_PIL_H
3
4/* To avoid some locking problems, we hard allocate certain PILs
5 * for SMP cross call messages that must do a etrap/rtrap.
6 *
7 * A local_irq_disable() does not block the cross call delivery, so
8 * when SMP locking is an issue we reschedule the event into a PIL
9 * interrupt which is blocked by local_irq_disable().
10 *
11 * In fact any XCALL which has to etrap/rtrap has a problem because
12 * it is difficult to prevent rtrap from running BH's, and that would
13 * need to be done if the XCALL arrived while %pil==15.
14 */
15#define PIL_SMP_CALL_FUNC 1
16#define PIL_SMP_RECEIVE_SIGNAL 2
17#define PIL_SMP_CAPTURE 3
18#define PIL_SMP_CTX_NEW_VERSION 4
19#define PIL_DEVICE_IRQ 5
20
21#endif /* !(_SPARC64_PIL_H) */
diff --git a/include/asm-sparc64/poll.h b/include/asm-sparc64/poll.h
index ebeeb3816c40..8e2f31b4641a 100644
--- a/include/asm-sparc64/poll.h
+++ b/include/asm-sparc64/poll.h
@@ -1,12 +1 @@
1#ifndef __SPARC64_POLL_H #include <asm-sparc/poll.h>
2#define __SPARC64_POLL_H
3
4#define POLLWRNORM POLLOUT
5#define POLLWRBAND 256
6#define POLLMSG 512
7#define POLLREMOVE 1024
8#define POLLRDHUP 2048
9
10#include <asm-generic/poll.h>
11
12#endif
diff --git a/include/asm-sparc64/posix_types.h b/include/asm-sparc64/posix_types.h
index 4eaaa0196636..8cee99200232 100644
--- a/include/asm-sparc64/posix_types.h
+++ b/include/asm-sparc64/posix_types.h
@@ -1,122 +1 @@
1#ifndef __ARCH_SPARC64_POSIX_TYPES_H #include <asm-sparc/posix_types.h>
2#define __ARCH_SPARC64_POSIX_TYPES_H
3
4/*
5 * This file is generally used by user-level software, so you need to
6 * be a little careful about namespace pollution etc. Also, we cannot
7 * assume GCC is being used.
8 */
9
10typedef unsigned long __kernel_size_t;
11typedef long __kernel_ssize_t;
12typedef long __kernel_ptrdiff_t;
13typedef long __kernel_time_t;
14typedef long __kernel_clock_t;
15typedef int __kernel_pid_t;
16typedef int __kernel_ipc_pid_t;
17typedef unsigned int __kernel_uid_t;
18typedef unsigned int __kernel_gid_t;
19typedef unsigned long __kernel_ino_t;
20typedef unsigned int __kernel_mode_t;
21typedef unsigned short __kernel_umode_t;
22typedef unsigned int __kernel_nlink_t;
23typedef int __kernel_daddr_t;
24typedef long __kernel_off_t;
25typedef char * __kernel_caddr_t;
26typedef unsigned short __kernel_uid16_t;
27typedef unsigned short __kernel_gid16_t;
28typedef int __kernel_clockid_t;
29typedef int __kernel_timer_t;
30
31typedef unsigned short __kernel_old_uid_t;
32typedef unsigned short __kernel_old_gid_t;
33typedef __kernel_uid_t __kernel_uid32_t;
34typedef __kernel_gid_t __kernel_gid32_t;
35
36typedef unsigned int __kernel_old_dev_t;
37
38/* Note this piece of asymmetry from the v9 ABI. */
39typedef int __kernel_suseconds_t;
40
41#ifdef __GNUC__
42typedef long long __kernel_loff_t;
43#endif
44
45typedef struct {
46 int val[2];
47} __kernel_fsid_t;
48
49#if defined(__KERNEL__)
50
51#undef __FD_SET
52static inline void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
53{
54 unsigned long _tmp = fd / __NFDBITS;
55 unsigned long _rem = fd % __NFDBITS;
56 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
57}
58
59#undef __FD_CLR
60static inline void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
61{
62 unsigned long _tmp = fd / __NFDBITS;
63 unsigned long _rem = fd % __NFDBITS;
64 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
65}
66
67#undef __FD_ISSET
68static inline int __FD_ISSET(unsigned long fd, __const__ __kernel_fd_set *p)
69{
70 unsigned long _tmp = fd / __NFDBITS;
71 unsigned long _rem = fd % __NFDBITS;
72 return (p->fds_bits[_tmp] & (1UL<<_rem)) != 0;
73}
74
75/*
76 * This will unroll the loop for the normal constant cases (8 or 32 longs,
77 * for 256 and 1024-bit fd_sets respectively)
78 */
79#undef __FD_ZERO
80static inline void __FD_ZERO(__kernel_fd_set *p)
81{
82 unsigned long *tmp = p->fds_bits;
83 int i;
84
85 if (__builtin_constant_p(__FDSET_LONGS)) {
86 switch (__FDSET_LONGS) {
87 case 32:
88 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
89 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
90 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
91 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
92 tmp[16] = 0; tmp[17] = 0; tmp[18] = 0; tmp[19] = 0;
93 tmp[20] = 0; tmp[21] = 0; tmp[22] = 0; tmp[23] = 0;
94 tmp[24] = 0; tmp[25] = 0; tmp[26] = 0; tmp[27] = 0;
95 tmp[28] = 0; tmp[29] = 0; tmp[30] = 0; tmp[31] = 0;
96 return;
97 case 16:
98 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
99 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
100 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
101 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
102 return;
103 case 8:
104 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
105 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
106 return;
107 case 4:
108 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
109 return;
110 }
111 }
112 i = __FDSET_LONGS;
113 while (i) {
114 i--;
115 *tmp = 0;
116 tmp++;
117 }
118}
119
120#endif /* defined(__KERNEL__) */
121
122#endif /* !(__ARCH_SPARC64_POSIX_TYPES_H) */
diff --git a/include/asm-sparc64/processor.h b/include/asm-sparc64/processor.h
index 26b4e5255761..21de6cc182eb 100644
--- a/include/asm-sparc64/processor.h
+++ b/include/asm-sparc64/processor.h
@@ -1,237 +1 @@
1/* #include <asm-sparc/processor.h>
2 * include/asm-sparc64/processor.h
3 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef __ASM_SPARC64_PROCESSOR_H
8#define __ASM_SPARC64_PROCESSOR_H
9
10/*
11 * Sparc64 implementation of macro that returns current
12 * instruction pointer ("program counter").
13 */
14#define current_text_addr() ({ void *pc; __asm__("rd %%pc, %0" : "=r" (pc)); pc; })
15
16#include <asm/asi.h>
17#include <asm/pstate.h>
18#include <asm/ptrace.h>
19#include <asm/page.h>
20
21/* The sparc has no problems with write protection */
22#define wp_works_ok 1
23#define wp_works_ok__is_a_macro /* for versions in ksyms.c */
24
25/*
26 * User lives in his very own context, and cannot reference us. Note
27 * that TASK_SIZE is a misnomer, it really gives maximum user virtual
28 * address that the kernel will allocate out.
29 *
30 * XXX No longer using virtual page tables, kill this upper limit...
31 */
32#define VA_BITS 44
33#ifndef __ASSEMBLY__
34#define VPTE_SIZE (1UL << (VA_BITS - PAGE_SHIFT + 3))
35#else
36#define VPTE_SIZE (1 << (VA_BITS - PAGE_SHIFT + 3))
37#endif
38
39#define TASK_SIZE ((unsigned long)-VPTE_SIZE)
40#define TASK_SIZE_OF(tsk) \
41 (test_tsk_thread_flag(tsk,TIF_32BIT) ? \
42 (1UL << 32UL) : TASK_SIZE)
43#ifdef __KERNEL__
44
45#define STACK_TOP32 ((1UL << 32UL) - PAGE_SIZE)
46#define STACK_TOP64 (0x0000080000000000UL - (1UL << 32UL))
47
48#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
49 STACK_TOP32 : STACK_TOP64)
50
51#define STACK_TOP_MAX STACK_TOP64
52
53#endif
54
55#ifndef __ASSEMBLY__
56
57typedef struct {
58 unsigned char seg;
59} mm_segment_t;
60
61/* The Sparc processor specific thread struct. */
62/* XXX This should die, everything can go into thread_info now. */
63struct thread_struct {
64#ifdef CONFIG_DEBUG_SPINLOCK
65 /* How many spinlocks held by this thread.
66 * Used with spin lock debugging to catch tasks
67 * sleeping illegally with locks held.
68 */
69 int smp_lock_count;
70 unsigned int smp_lock_pc;
71#else
72 int dummy; /* f'in gcc bug... */
73#endif
74};
75
76#endif /* !(__ASSEMBLY__) */
77
78#ifndef CONFIG_DEBUG_SPINLOCK
79#define INIT_THREAD { \
80 0, \
81}
82#else /* CONFIG_DEBUG_SPINLOCK */
83#define INIT_THREAD { \
84/* smp_lock_count, smp_lock_pc, */ \
85 0, 0, \
86}
87#endif /* !(CONFIG_DEBUG_SPINLOCK) */
88
89#ifndef __ASSEMBLY__
90
91#include <linux/types.h>
92
93/* Return saved PC of a blocked thread. */
94struct task_struct;
95extern unsigned long thread_saved_pc(struct task_struct *);
96
97/* On Uniprocessor, even in RMO processes see TSO semantics */
98#ifdef CONFIG_SMP
99#define TSTATE_INITIAL_MM TSTATE_TSO
100#else
101#define TSTATE_INITIAL_MM TSTATE_RMO
102#endif
103
104/* Do necessary setup to start up a newly executed thread. */
105#define start_thread(regs, pc, sp) \
106do { \
107 unsigned long __asi = ASI_PNF; \
108 regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (__asi << 24UL); \
109 regs->tpc = ((pc & (~3)) - 4); \
110 regs->tnpc = regs->tpc + 4; \
111 regs->y = 0; \
112 set_thread_wstate(1 << 3); \
113 if (current_thread_info()->utraps) { \
114 if (*(current_thread_info()->utraps) < 2) \
115 kfree(current_thread_info()->utraps); \
116 else \
117 (*(current_thread_info()->utraps))--; \
118 current_thread_info()->utraps = NULL; \
119 } \
120 __asm__ __volatile__( \
121 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
122 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
123 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
124 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
125 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
126 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
127 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
128 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
129 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
130 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
131 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
132 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
133 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
134 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
135 "stx %1, [%0 + %2 + 0x70]\n\t" \
136 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
137 "wrpr %%g0, (1 << 3), %%wstate\n\t" \
138 : \
139 : "r" (regs), "r" (sp - sizeof(struct reg_window) - STACK_BIAS), \
140 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
141} while (0)
142
143#define start_thread32(regs, pc, sp) \
144do { \
145 unsigned long __asi = ASI_PNF; \
146 pc &= 0x00000000ffffffffUL; \
147 sp &= 0x00000000ffffffffUL; \
148 regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM) | (__asi << 24UL); \
149 regs->tpc = ((pc & (~3)) - 4); \
150 regs->tnpc = regs->tpc + 4; \
151 regs->y = 0; \
152 set_thread_wstate(2 << 3); \
153 if (current_thread_info()->utraps) { \
154 if (*(current_thread_info()->utraps) < 2) \
155 kfree(current_thread_info()->utraps); \
156 else \
157 (*(current_thread_info()->utraps))--; \
158 current_thread_info()->utraps = NULL; \
159 } \
160 __asm__ __volatile__( \
161 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
162 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
163 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
164 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
165 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
166 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
167 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
168 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
169 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
170 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
171 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
172 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
173 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
174 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
175 "stx %1, [%0 + %2 + 0x70]\n\t" \
176 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
177 "wrpr %%g0, (2 << 3), %%wstate\n\t" \
178 : \
179 : "r" (regs), "r" (sp - sizeof(struct reg_window32)), \
180 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
181} while (0)
182
183/* Free all resources held by a thread. */
184#define release_thread(tsk) do { } while (0)
185
186/* Prepare to copy thread state - unlazy all lazy status */
187#define prepare_to_copy(tsk) do { } while (0)
188
189extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
190
191extern unsigned long get_wchan(struct task_struct *task);
192
193#define task_pt_regs(tsk) (task_thread_info(tsk)->kregs)
194#define KSTK_EIP(tsk) (task_pt_regs(tsk)->tpc)
195#define KSTK_ESP(tsk) (task_pt_regs(tsk)->u_regs[UREG_FP])
196
197#define cpu_relax() barrier()
198
199/* Prefetch support. This is tuned for UltraSPARC-III and later.
200 * UltraSPARC-I will treat these as nops, and UltraSPARC-II has
201 * a shallower prefetch queue than later chips.
202 */
203#define ARCH_HAS_PREFETCH
204#define ARCH_HAS_PREFETCHW
205#define ARCH_HAS_SPINLOCK_PREFETCH
206
207static inline void prefetch(const void *x)
208{
209 /* We do not use the read prefetch mnemonic because that
210 * prefetches into the prefetch-cache which only is accessible
211 * by floating point operations in UltraSPARC-III and later.
212 * By contrast, "#one_write" prefetches into the L2 cache
213 * in shared state.
214 */
215 __asm__ __volatile__("prefetch [%0], #one_write"
216 : /* no outputs */
217 : "r" (x));
218}
219
220static inline void prefetchw(const void *x)
221{
222 /* The most optimal prefetch to use for writes is
223 * "#n_writes". This brings the cacheline into the
224 * L2 cache in "owned" state.
225 */
226 __asm__ __volatile__("prefetch [%0], #n_writes"
227 : /* no outputs */
228 : "r" (x));
229}
230
231#define spin_lock_prefetch(x) prefetchw(x)
232
233#define HAVE_ARCH_PICK_MMAP_LAYOUT
234
235#endif /* !(__ASSEMBLY__) */
236
237#endif /* !(__ASM_SPARC64_PROCESSOR_H) */
diff --git a/include/asm-sparc64/psrcompat.h b/include/asm-sparc64/psrcompat.h
index 44b6327dbbf5..587846f48358 100644
--- a/include/asm-sparc64/psrcompat.h
+++ b/include/asm-sparc64/psrcompat.h
@@ -1,45 +1 @@
1#ifndef _SPARC64_PSRCOMPAT_H #include <asm-sparc/psrcompat.h>
2#define _SPARC64_PSRCOMPAT_H
3
4#include <asm/pstate.h>
5
6/* Old 32-bit PSR fields for the compatibility conversion code. */
7#define PSR_CWP 0x0000001f /* current window pointer */
8#define PSR_ET 0x00000020 /* enable traps field */
9#define PSR_PS 0x00000040 /* previous privilege level */
10#define PSR_S 0x00000080 /* current privilege level */
11#define PSR_PIL 0x00000f00 /* processor interrupt level */
12#define PSR_EF 0x00001000 /* enable floating point */
13#define PSR_EC 0x00002000 /* enable co-processor */
14#define PSR_SYSCALL 0x00004000 /* inside of a syscall */
15#define PSR_LE 0x00008000 /* SuperSparcII little-endian */
16#define PSR_ICC 0x00f00000 /* integer condition codes */
17#define PSR_C 0x00100000 /* carry bit */
18#define PSR_V 0x00200000 /* overflow bit */
19#define PSR_Z 0x00400000 /* zero bit */
20#define PSR_N 0x00800000 /* negative bit */
21#define PSR_VERS 0x0f000000 /* cpu-version field */
22#define PSR_IMPL 0xf0000000 /* cpu-implementation field */
23
24#define PSR_V8PLUS 0xff000000 /* fake impl/ver, meaning a 64bit CPU is present */
25#define PSR_XCC 0x000f0000 /* if PSR_V8PLUS, this is %xcc */
26
27static inline unsigned int tstate_to_psr(unsigned long tstate)
28{
29 return ((tstate & TSTATE_CWP) |
30 PSR_S |
31 ((tstate & TSTATE_ICC) >> 12) |
32 ((tstate & TSTATE_XCC) >> 20) |
33 ((tstate & TSTATE_SYSCALL) ? PSR_SYSCALL : 0) |
34 PSR_V8PLUS);
35}
36
37static inline unsigned long psr_to_tstate_icc(unsigned int psr)
38{
39 unsigned long tstate = ((unsigned long)(psr & PSR_ICC)) << 12;
40 if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS)
41 tstate |= ((unsigned long)(psr & PSR_XCC)) << 20;
42 return tstate;
43}
44
45#endif /* !(_SPARC64_PSRCOMPAT_H) */
diff --git a/include/asm-sparc64/pstate.h b/include/asm-sparc64/pstate.h
index a26a53777bb0..3ccf0be25360 100644
--- a/include/asm-sparc64/pstate.h
+++ b/include/asm-sparc64/pstate.h
@@ -1,91 +1 @@
1#ifndef _SPARC64_PSTATE_H #include <asm-sparc/pstate.h>
2#define _SPARC64_PSTATE_H
3
4#include <linux/const.h>
5
6/* The V9 PSTATE Register (with SpitFire extensions).
7 *
8 * -----------------------------------------------------------------------
9 * | Resv | IG | MG | CLE | TLE | MM | RED | PEF | AM | PRIV | IE | AG |
10 * -----------------------------------------------------------------------
11 * 63 12 11 10 9 8 7 6 5 4 3 2 1 0
12 */
13#define PSTATE_IG _AC(0x0000000000000800,UL) /* Interrupt Globals. */
14#define PSTATE_MG _AC(0x0000000000000400,UL) /* MMU Globals. */
15#define PSTATE_CLE _AC(0x0000000000000200,UL) /* Current Little Endian.*/
16#define PSTATE_TLE _AC(0x0000000000000100,UL) /* Trap Little Endian. */
17#define PSTATE_MM _AC(0x00000000000000c0,UL) /* Memory Model. */
18#define PSTATE_TSO _AC(0x0000000000000000,UL) /* MM: TotalStoreOrder */
19#define PSTATE_PSO _AC(0x0000000000000040,UL) /* MM: PartialStoreOrder */
20#define PSTATE_RMO _AC(0x0000000000000080,UL) /* MM: RelaxedMemoryOrder*/
21#define PSTATE_RED _AC(0x0000000000000020,UL) /* Reset Error Debug. */
22#define PSTATE_PEF _AC(0x0000000000000010,UL) /* Floating Point Enable.*/
23#define PSTATE_AM _AC(0x0000000000000008,UL) /* Address Mask. */
24#define PSTATE_PRIV _AC(0x0000000000000004,UL) /* Privilege. */
25#define PSTATE_IE _AC(0x0000000000000002,UL) /* Interrupt Enable. */
26#define PSTATE_AG _AC(0x0000000000000001,UL) /* Alternate Globals. */
27
28/* The V9 TSTATE Register (with SpitFire and Linux extensions).
29 *
30 * ---------------------------------------------------------------------
31 * | Resv | GL | CCR | ASI | %pil | PSTATE | Resv | CWP |
32 * ---------------------------------------------------------------------
33 * 63 43 42 40 39 32 31 24 23 20 19 8 7 5 4 0
34 */
35#define TSTATE_GL _AC(0x0000070000000000,UL) /* Global reg level */
36#define TSTATE_CCR _AC(0x000000ff00000000,UL) /* Condition Codes. */
37#define TSTATE_XCC _AC(0x000000f000000000,UL) /* Condition Codes. */
38#define TSTATE_XNEG _AC(0x0000008000000000,UL) /* %xcc Negative. */
39#define TSTATE_XZERO _AC(0x0000004000000000,UL) /* %xcc Zero. */
40#define TSTATE_XOVFL _AC(0x0000002000000000,UL) /* %xcc Overflow. */
41#define TSTATE_XCARRY _AC(0x0000001000000000,UL) /* %xcc Carry. */
42#define TSTATE_ICC _AC(0x0000000f00000000,UL) /* Condition Codes. */
43#define TSTATE_INEG _AC(0x0000000800000000,UL) /* %icc Negative. */
44#define TSTATE_IZERO _AC(0x0000000400000000,UL) /* %icc Zero. */
45#define TSTATE_IOVFL _AC(0x0000000200000000,UL) /* %icc Overflow. */
46#define TSTATE_ICARRY _AC(0x0000000100000000,UL) /* %icc Carry. */
47#define TSTATE_ASI _AC(0x00000000ff000000,UL) /* AddrSpace ID. */
48#define TSTATE_PIL _AC(0x0000000000f00000,UL) /* %pil (Linux traps)*/
49#define TSTATE_PSTATE _AC(0x00000000000fff00,UL) /* PSTATE. */
50#define TSTATE_IG _AC(0x0000000000080000,UL) /* Interrupt Globals.*/
51#define TSTATE_MG _AC(0x0000000000040000,UL) /* MMU Globals. */
52#define TSTATE_CLE _AC(0x0000000000020000,UL) /* CurrLittleEndian. */
53#define TSTATE_TLE _AC(0x0000000000010000,UL) /* TrapLittleEndian. */
54#define TSTATE_MM _AC(0x000000000000c000,UL) /* Memory Model. */
55#define TSTATE_TSO _AC(0x0000000000000000,UL) /* MM: TSO */
56#define TSTATE_PSO _AC(0x0000000000004000,UL) /* MM: PSO */
57#define TSTATE_RMO _AC(0x0000000000008000,UL) /* MM: RMO */
58#define TSTATE_RED _AC(0x0000000000002000,UL) /* Reset Error Debug.*/
59#define TSTATE_PEF _AC(0x0000000000001000,UL) /* FPU Enable. */
60#define TSTATE_AM _AC(0x0000000000000800,UL) /* Address Mask. */
61#define TSTATE_PRIV _AC(0x0000000000000400,UL) /* Privilege. */
62#define TSTATE_IE _AC(0x0000000000000200,UL) /* Interrupt Enable. */
63#define TSTATE_AG _AC(0x0000000000000100,UL) /* Alternate Globals.*/
64#define TSTATE_SYSCALL _AC(0x0000000000000020,UL) /* in syscall trap */
65#define TSTATE_CWP _AC(0x000000000000001f,UL) /* Curr Win-Pointer. */
66
67/* Floating-Point Registers State Register.
68 *
69 * --------------------------------
70 * | Resv | FEF | DU | DL |
71 * --------------------------------
72 * 63 3 2 1 0
73 */
74#define FPRS_FEF _AC(0x0000000000000004,UL) /* FPU Enable. */
75#define FPRS_DU _AC(0x0000000000000002,UL) /* Dirty Upper. */
76#define FPRS_DL _AC(0x0000000000000001,UL) /* Dirty Lower. */
77
78/* Version Register.
79 *
80 * ------------------------------------------------------
81 * | MANUF | IMPL | MASK | Resv | MAXTL | Resv | MAXWIN |
82 * ------------------------------------------------------
83 * 63 48 47 32 31 24 23 16 15 8 7 5 4 0
84 */
85#define VERS_MANUF _AC(0xffff000000000000,UL) /* Manufacturer. */
86#define VERS_IMPL _AC(0x0000ffff00000000,UL) /* Implementation. */
87#define VERS_MASK _AC(0x00000000ff000000,UL) /* Mask Set Revision.*/
88#define VERS_MAXTL _AC(0x000000000000ff00,UL) /* Max Trap Level. */
89#define VERS_MAXWIN _AC(0x000000000000001f,UL) /* Max RegWindow Idx.*/
90
91#endif /* !(_SPARC64_PSTATE_H) */
diff --git a/include/asm-sparc64/ptrace.h b/include/asm-sparc64/ptrace.h
index b163da79bb6d..1a55b9fb3b0c 100644
--- a/include/asm-sparc64/ptrace.h
+++ b/include/asm-sparc64/ptrace.h
@@ -1,346 +1 @@
1#ifndef _SPARC64_PTRACE_H #include <asm-sparc/ptrace.h>
2#define _SPARC64_PTRACE_H
3
4#include <asm/pstate.h>
5
6/* This struct defines the way the registers are stored on the
7 * stack during a system call and basically all traps.
8 */
9
10/* This magic value must have the low 9 bits clear,
11 * as that is where we encode the %tt value, see below.
12 */
13#define PT_REGS_MAGIC 0x57ac6c00
14
15#ifndef __ASSEMBLY__
16
17#include <linux/types.h>
18
19struct pt_regs {
20 unsigned long u_regs[16]; /* globals and ins */
21 unsigned long tstate;
22 unsigned long tpc;
23 unsigned long tnpc;
24 unsigned int y;
25
26 /* We encode a magic number, PT_REGS_MAGIC, along
27 * with the %tt (trap type) register value at trap
28 * entry time. The magic number allows us to identify
29 * accurately a trap stack frame in the stack
30 * unwinder, and the %tt value allows us to test
31 * things like "in a system call" etc. for an arbitray
32 * process.
33 *
34 * The PT_REGS_MAGIC is choosen such that it can be
35 * loaded completely using just a sethi instruction.
36 */
37 unsigned int magic;
38};
39
40static inline int pt_regs_trap_type(struct pt_regs *regs)
41{
42 return regs->magic & 0x1ff;
43}
44
45static inline bool pt_regs_is_syscall(struct pt_regs *regs)
46{
47 return (regs->tstate & TSTATE_SYSCALL);
48}
49
50static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
51{
52 return (regs->tstate &= ~TSTATE_SYSCALL);
53}
54
55struct pt_regs32 {
56 unsigned int psr;
57 unsigned int pc;
58 unsigned int npc;
59 unsigned int y;
60 unsigned int u_regs[16]; /* globals and ins */
61};
62
63#define UREG_G0 0
64#define UREG_G1 1
65#define UREG_G2 2
66#define UREG_G3 3
67#define UREG_G4 4
68#define UREG_G5 5
69#define UREG_G6 6
70#define UREG_G7 7
71#define UREG_I0 8
72#define UREG_I1 9
73#define UREG_I2 10
74#define UREG_I3 11
75#define UREG_I4 12
76#define UREG_I5 13
77#define UREG_I6 14
78#define UREG_I7 15
79#define UREG_FP UREG_I6
80#define UREG_RETPC UREG_I7
81
82/* A V9 register window */
83struct reg_window {
84 unsigned long locals[8];
85 unsigned long ins[8];
86};
87
88/* A 32-bit register window. */
89struct reg_window32 {
90 unsigned int locals[8];
91 unsigned int ins[8];
92};
93
94/* A V9 Sparc stack frame */
95struct sparc_stackf {
96 unsigned long locals[8];
97 unsigned long ins[6];
98 struct sparc_stackf *fp;
99 unsigned long callers_pc;
100 char *structptr;
101 unsigned long xargs[6];
102 unsigned long xxargs[1];
103};
104
105/* A 32-bit Sparc stack frame */
106struct sparc_stackf32 {
107 unsigned int locals[8];
108 unsigned int ins[6];
109 unsigned int fp;
110 unsigned int callers_pc;
111 unsigned int structptr;
112 unsigned int xargs[6];
113 unsigned int xxargs[1];
114};
115
116struct sparc_trapf {
117 unsigned long locals[8];
118 unsigned long ins[8];
119 unsigned long _unused;
120 struct pt_regs *regs;
121};
122
123#define TRACEREG_SZ sizeof(struct pt_regs)
124#define STACKFRAME_SZ sizeof(struct sparc_stackf)
125
126#define TRACEREG32_SZ sizeof(struct pt_regs32)
127#define STACKFRAME32_SZ sizeof(struct sparc_stackf32)
128
129#ifdef __KERNEL__
130
131struct global_reg_snapshot {
132 unsigned long tstate;
133 unsigned long tpc;
134 unsigned long tnpc;
135 unsigned long o7;
136 unsigned long i7;
137 struct thread_info *thread;
138 unsigned long pad1;
139 unsigned long pad2;
140};
141
142#define __ARCH_WANT_COMPAT_SYS_PTRACE
143
144#define force_successful_syscall_return() \
145do { current_thread_info()->syscall_noerror = 1; \
146} while (0)
147#define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV))
148#define instruction_pointer(regs) ((regs)->tpc)
149#define regs_return_value(regs) ((regs)->u_regs[UREG_I0])
150#ifdef CONFIG_SMP
151extern unsigned long profile_pc(struct pt_regs *);
152#else
153#define profile_pc(regs) instruction_pointer(regs)
154#endif
155extern void show_regs(struct pt_regs *);
156extern void __show_regs(struct pt_regs *);
157#endif
158
159#else /* __ASSEMBLY__ */
160/* For assembly code. */
161#define TRACEREG_SZ 0xa0
162#define STACKFRAME_SZ 0xc0
163
164#define TRACEREG32_SZ 0x50
165#define STACKFRAME32_SZ 0x60
166#endif
167
168#ifdef __KERNEL__
169#define STACK_BIAS 2047
170#endif
171
172/* These are for pt_regs. */
173#define PT_V9_G0 0x00
174#define PT_V9_G1 0x08
175#define PT_V9_G2 0x10
176#define PT_V9_G3 0x18
177#define PT_V9_G4 0x20
178#define PT_V9_G5 0x28
179#define PT_V9_G6 0x30
180#define PT_V9_G7 0x38
181#define PT_V9_I0 0x40
182#define PT_V9_I1 0x48
183#define PT_V9_I2 0x50
184#define PT_V9_I3 0x58
185#define PT_V9_I4 0x60
186#define PT_V9_I5 0x68
187#define PT_V9_I6 0x70
188#define PT_V9_FP PT_V9_I6
189#define PT_V9_I7 0x78
190#define PT_V9_TSTATE 0x80
191#define PT_V9_TPC 0x88
192#define PT_V9_TNPC 0x90
193#define PT_V9_Y 0x98
194#define PT_V9_MAGIC 0x9c
195#define PT_TSTATE PT_V9_TSTATE
196#define PT_TPC PT_V9_TPC
197#define PT_TNPC PT_V9_TNPC
198
199/* These for pt_regs32. */
200#define PT_PSR 0x0
201#define PT_PC 0x4
202#define PT_NPC 0x8
203#define PT_Y 0xc
204#define PT_G0 0x10
205#define PT_WIM PT_G0
206#define PT_G1 0x14
207#define PT_G2 0x18
208#define PT_G3 0x1c
209#define PT_G4 0x20
210#define PT_G5 0x24
211#define PT_G6 0x28
212#define PT_G7 0x2c
213#define PT_I0 0x30
214#define PT_I1 0x34
215#define PT_I2 0x38
216#define PT_I3 0x3c
217#define PT_I4 0x40
218#define PT_I5 0x44
219#define PT_I6 0x48
220#define PT_FP PT_I6
221#define PT_I7 0x4c
222
223/* Reg_window offsets */
224#define RW_V9_L0 0x00
225#define RW_V9_L1 0x08
226#define RW_V9_L2 0x10
227#define RW_V9_L3 0x18
228#define RW_V9_L4 0x20
229#define RW_V9_L5 0x28
230#define RW_V9_L6 0x30
231#define RW_V9_L7 0x38
232#define RW_V9_I0 0x40
233#define RW_V9_I1 0x48
234#define RW_V9_I2 0x50
235#define RW_V9_I3 0x58
236#define RW_V9_I4 0x60
237#define RW_V9_I5 0x68
238#define RW_V9_I6 0x70
239#define RW_V9_I7 0x78
240
241#define RW_L0 0x00
242#define RW_L1 0x04
243#define RW_L2 0x08
244#define RW_L3 0x0c
245#define RW_L4 0x10
246#define RW_L5 0x14
247#define RW_L6 0x18
248#define RW_L7 0x1c
249#define RW_I0 0x20
250#define RW_I1 0x24
251#define RW_I2 0x28
252#define RW_I3 0x2c
253#define RW_I4 0x30
254#define RW_I5 0x34
255#define RW_I6 0x38
256#define RW_I7 0x3c
257
258/* Stack_frame offsets */
259#define SF_V9_L0 0x00
260#define SF_V9_L1 0x08
261#define SF_V9_L2 0x10
262#define SF_V9_L3 0x18
263#define SF_V9_L4 0x20
264#define SF_V9_L5 0x28
265#define SF_V9_L6 0x30
266#define SF_V9_L7 0x38
267#define SF_V9_I0 0x40
268#define SF_V9_I1 0x48
269#define SF_V9_I2 0x50
270#define SF_V9_I3 0x58
271#define SF_V9_I4 0x60
272#define SF_V9_I5 0x68
273#define SF_V9_FP 0x70
274#define SF_V9_PC 0x78
275#define SF_V9_RETP 0x80
276#define SF_V9_XARG0 0x88
277#define SF_V9_XARG1 0x90
278#define SF_V9_XARG2 0x98
279#define SF_V9_XARG3 0xa0
280#define SF_V9_XARG4 0xa8
281#define SF_V9_XARG5 0xb0
282#define SF_V9_XXARG 0xb8
283
284#define SF_L0 0x00
285#define SF_L1 0x04
286#define SF_L2 0x08
287#define SF_L3 0x0c
288#define SF_L4 0x10
289#define SF_L5 0x14
290#define SF_L6 0x18
291#define SF_L7 0x1c
292#define SF_I0 0x20
293#define SF_I1 0x24
294#define SF_I2 0x28
295#define SF_I3 0x2c
296#define SF_I4 0x30
297#define SF_I5 0x34
298#define SF_FP 0x38
299#define SF_PC 0x3c
300#define SF_RETP 0x40
301#define SF_XARG0 0x44
302#define SF_XARG1 0x48
303#define SF_XARG2 0x4c
304#define SF_XARG3 0x50
305#define SF_XARG4 0x54
306#define SF_XARG5 0x58
307#define SF_XXARG 0x5c
308
309#ifdef __KERNEL__
310
311/* global_reg_snapshot offsets */
312#define GR_SNAP_TSTATE 0x00
313#define GR_SNAP_TPC 0x08
314#define GR_SNAP_TNPC 0x10
315#define GR_SNAP_O7 0x18
316#define GR_SNAP_I7 0x20
317#define GR_SNAP_THREAD 0x28
318#define GR_SNAP_PAD1 0x30
319#define GR_SNAP_PAD2 0x38
320
321#endif /* __KERNEL__ */
322
323/* Stuff for the ptrace system call */
324#define PTRACE_SPARC_DETACH 11
325#define PTRACE_GETREGS 12
326#define PTRACE_SETREGS 13
327#define PTRACE_GETFPREGS 14
328#define PTRACE_SETFPREGS 15
329#define PTRACE_READDATA 16
330#define PTRACE_WRITEDATA 17
331#define PTRACE_READTEXT 18
332#define PTRACE_WRITETEXT 19
333#define PTRACE_GETFPAREGS 20
334#define PTRACE_SETFPAREGS 21
335
336/* There are for debugging 64-bit processes, either from a 32 or 64 bit
337 * parent. Thus their complements are for debugging 32-bit processes only.
338 */
339
340#define PTRACE_GETREGS64 22
341#define PTRACE_SETREGS64 23
342/* PTRACE_SYSCALL is 24 */
343#define PTRACE_GETFPREGS64 25
344#define PTRACE_SETFPREGS64 26
345
346#endif /* !(_SPARC64_PTRACE_H) */
diff --git a/include/asm-sparc64/reboot.h b/include/asm-sparc64/reboot.h
index 3f3f43f5be5e..0d72eb811cc8 100644
--- a/include/asm-sparc64/reboot.h
+++ b/include/asm-sparc64/reboot.h
@@ -1,6 +1 @@
1#ifndef _SPARC64_REBOOT_H #include <asm-sparc/reboot.h>
2#define _SPARC64_REBOOT_H
3
4extern void machine_alt_power_off(void);
5
6#endif /* _SPARC64_REBOOT_H */
diff --git a/include/asm-sparc64/reg.h b/include/asm-sparc64/reg.h
index 77aa4804a60d..495bab27da07 100644
--- a/include/asm-sparc64/reg.h
+++ b/include/asm-sparc64/reg.h
@@ -1,56 +1 @@
1/* #include <asm-sparc/reg.h>
2 * linux/asm-sparc64/reg.h
3 * Layout of the registers as expected by gdb on the Sparc
4 * we should replace the user.h definitions with those in
5 * this file, we don't even use the other
6 * -miguel
7 *
8 * The names of the structures, constants and aliases in this file
9 * have the same names as the sunos ones, some programs rely on these
10 * names (gdb for example).
11 *
12 */
13
14#ifndef __SPARC64_REG_H
15#define __SPARC64_REG_H
16
17struct regs {
18 unsigned long r_g1;
19 unsigned long r_g2;
20 unsigned long r_g3;
21 unsigned long r_g4;
22 unsigned long r_g5;
23 unsigned long r_g6;
24 unsigned long r_g7;
25 unsigned long r_o0;
26 unsigned long r_o1;
27 unsigned long r_o2;
28 unsigned long r_o3;
29 unsigned long r_o4;
30 unsigned long r_o5;
31 unsigned long r_o6;
32 unsigned long r_o7;
33 unsigned long __pad;
34 unsigned long r_tstate;
35 unsigned long r_tpc;
36 unsigned long r_tnpc;
37 unsigned int r_y;
38 unsigned int r_fprs;
39};
40
41#define FPU_REGS_TYPE unsigned int
42#define FPU_FSR_TYPE unsigned long
43
44struct fp_status {
45 unsigned long fpu_fr[32];
46 unsigned long Fpu_fsr;
47};
48
49struct fpu {
50 struct fp_status f_fpstatus;
51};
52
53#define fpu_regs f_fpstatus.fpu_fr
54#define fpu_fsr f_fpstatus.Fpu_fsr
55
56#endif /* __SPARC64_REG_H */
diff --git a/include/asm-sparc64/resource.h b/include/asm-sparc64/resource.h
index 4f08fb5e4ca4..46e3bc0de476 100644
--- a/include/asm-sparc64/resource.h
+++ b/include/asm-sparc64/resource.h
@@ -1,19 +1 @@
1/* #include <asm-sparc/resource.h>
2 * resource.h: Resource definitions.
3 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef _SPARC64_RESOURCE_H
8#define _SPARC64_RESOURCE_H
9
10/*
11 * These two resource limit IDs have a Sparc/Linux-specific ordering,
12 * the rest comes from the generic header:
13 */
14#define RLIMIT_NOFILE 6 /* max number of open files */
15#define RLIMIT_NPROC 7 /* max number of processes */
16
17#include <asm-generic/resource.h>
18
19#endif /* !(_SPARC64_RESOURCE_H) */
diff --git a/include/asm-sparc64/rtc.h b/include/asm-sparc64/rtc.h
index f9ecb1fe2ecd..e49a9685aead 100644
--- a/include/asm-sparc64/rtc.h
+++ b/include/asm-sparc64/rtc.h
@@ -1,26 +1 @@
1/* #include <asm-sparc/rtc.h>
2 * rtc.h: Definitions for access to the Mostek real time clock
3 *
4 * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
5 */
6
7#ifndef _RTC_H
8#define _RTC_H
9
10#include <linux/ioctl.h>
11
12struct rtc_time
13{
14 int sec; /* Seconds (0-59) */
15 int min; /* Minutes (0-59) */
16 int hour; /* Hour (0-23) */
17 int dow; /* Day of the week (1-7) */
18 int dom; /* Day of the month (1-31) */
19 int month; /* Month of year (1-12) */
20 int year; /* Year (0-99) */
21};
22
23#define RTCGET _IOR('p', 20, struct rtc_time)
24#define RTCSET _IOW('p', 21, struct rtc_time)
25
26#endif
diff --git a/include/asm-sparc64/rwsem-const.h b/include/asm-sparc64/rwsem-const.h
index a303c9d64d84..2a1de315c86a 100644
--- a/include/asm-sparc64/rwsem-const.h
+++ b/include/asm-sparc64/rwsem-const.h
@@ -1,12 +1 @@
1/* rwsem-const.h: RW semaphore counter constants. */ #include <asm-sparc/rwsem-const.h>
2#ifndef _SPARC64_RWSEM_CONST_H
3#define _SPARC64_RWSEM_CONST_H
4
5#define RWSEM_UNLOCKED_VALUE 0x00000000
6#define RWSEM_ACTIVE_BIAS 0x00000001
7#define RWSEM_ACTIVE_MASK 0x0000ffff
8#define RWSEM_WAITING_BIAS 0xffff0000
9#define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS
10#define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
11
12#endif /* _SPARC64_RWSEM_CONST_H */
diff --git a/include/asm-sparc64/rwsem.h b/include/asm-sparc64/rwsem.h
index 1dc129ac2feb..6943c56ed087 100644
--- a/include/asm-sparc64/rwsem.h
+++ b/include/asm-sparc64/rwsem.h
@@ -1,84 +1 @@
1/* #include <asm-sparc/rwsem.h>
2 * rwsem.h: R/W semaphores implemented using CAS
3 *
4 * Written by David S. Miller (davem@redhat.com), 2001.
5 * Derived from asm-i386/rwsem.h
6 */
7#ifndef _SPARC64_RWSEM_H
8#define _SPARC64_RWSEM_H
9
10#ifndef _LINUX_RWSEM_H
11#error "please don't include asm/rwsem.h directly, use linux/rwsem.h instead"
12#endif
13
14#ifdef __KERNEL__
15
16#include <linux/list.h>
17#include <linux/spinlock.h>
18#include <asm/rwsem-const.h>
19
20struct rwsem_waiter;
21
22struct rw_semaphore {
23 signed int count;
24 spinlock_t wait_lock;
25 struct list_head wait_list;
26#ifdef CONFIG_DEBUG_LOCK_ALLOC
27 struct lockdep_map dep_map;
28#endif
29};
30
31#ifdef CONFIG_DEBUG_LOCK_ALLOC
32# define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
33#else
34# define __RWSEM_DEP_MAP_INIT(lockname)
35#endif
36
37#define __RWSEM_INITIALIZER(name) \
38{ RWSEM_UNLOCKED_VALUE, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) \
39 __RWSEM_DEP_MAP_INIT(name) }
40
41#define DECLARE_RWSEM(name) \
42 struct rw_semaphore name = __RWSEM_INITIALIZER(name)
43
44extern void __init_rwsem(struct rw_semaphore *sem, const char *name,
45 struct lock_class_key *key);
46
47#define init_rwsem(sem) \
48do { \
49 static struct lock_class_key __key; \
50 \
51 __init_rwsem((sem), #sem, &__key); \
52} while (0)
53
54extern void __down_read(struct rw_semaphore *sem);
55extern int __down_read_trylock(struct rw_semaphore *sem);
56extern void __down_write(struct rw_semaphore *sem);
57extern int __down_write_trylock(struct rw_semaphore *sem);
58extern void __up_read(struct rw_semaphore *sem);
59extern void __up_write(struct rw_semaphore *sem);
60extern void __downgrade_write(struct rw_semaphore *sem);
61
62static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
63{
64 __down_write(sem);
65}
66
67static inline int rwsem_atomic_update(int delta, struct rw_semaphore *sem)
68{
69 return atomic_add_return(delta, (atomic_t *)(&sem->count));
70}
71
72static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
73{
74 atomic_add(delta, (atomic_t *)(&sem->count));
75}
76
77static inline int rwsem_is_locked(struct rw_semaphore *sem)
78{
79 return (sem->count != 0);
80}
81
82#endif /* __KERNEL__ */
83
84#endif /* _SPARC64_RWSEM_H */
diff --git a/include/asm-sparc64/sbus.h b/include/asm-sparc64/sbus.h
index 24a04a55cf85..0cab0e89b874 100644
--- a/include/asm-sparc64/sbus.h
+++ b/include/asm-sparc64/sbus.h
@@ -1,190 +1 @@
1/* sbus.h: Defines for the Sun SBus. #include <asm-sparc/sbus.h>
2 *
3 * Copyright (C) 1996, 1999, 2007 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_SBUS_H
7#define _SPARC64_SBUS_H
8
9#include <linux/dma-mapping.h>
10#include <linux/ioport.h>
11
12#include <asm/oplib.h>
13#include <asm/prom.h>
14#include <asm/of_device.h>
15#include <asm/iommu.h>
16#include <asm/scatterlist.h>
17
18/* We scan which devices are on the SBus using the PROM node device
19 * tree. SBus devices are described in two different ways. You can
20 * either get an absolute address at which to access the device, or
21 * you can get a SBus 'slot' number and an offset within that slot.
22 */
23
24/* The base address at which to calculate device OBIO addresses. */
25#define SUN_SBUS_BVADDR 0x00000000
26#define SBUS_OFF_MASK 0x0fffffff
27
28/* These routines are used to calculate device address from slot
29 * numbers + offsets, and vice versa.
30 */
31
32static inline unsigned long sbus_devaddr(int slotnum, unsigned long offset)
33{
34 return (unsigned long) (SUN_SBUS_BVADDR+((slotnum)<<28)+(offset));
35}
36
37static inline int sbus_dev_slot(unsigned long dev_addr)
38{
39 return (int) (((dev_addr)-SUN_SBUS_BVADDR)>>28);
40}
41
42struct sbus_bus;
43
44/* Linux SBUS device tables */
45struct sbus_dev {
46 struct of_device ofdev;
47 struct sbus_bus *bus;
48 struct sbus_dev *next;
49 struct sbus_dev *child;
50 struct sbus_dev *parent;
51 int prom_node;
52 char prom_name[64];
53 int slot;
54
55 struct resource resource[PROMREG_MAX];
56
57 struct linux_prom_registers reg_addrs[PROMREG_MAX];
58 int num_registers;
59
60 struct linux_prom_ranges device_ranges[PROMREG_MAX];
61 int num_device_ranges;
62
63 unsigned int irqs[4];
64 int num_irqs;
65};
66#define to_sbus_device(d) container_of(d, struct sbus_dev, ofdev.dev)
67
68/* This struct describes the SBus(s) found on this machine. */
69struct sbus_bus {
70 struct of_device ofdev;
71 struct sbus_dev *devices; /* Tree of SBUS devices */
72 struct sbus_bus *next; /* Next SBUS in system */
73 int prom_node; /* OBP node of SBUS */
74 char prom_name[64]; /* Usually "sbus" or "sbi" */
75 int clock_freq;
76
77 struct linux_prom_ranges sbus_ranges[PROMREG_MAX];
78 int num_sbus_ranges;
79
80 int portid;
81};
82#define to_sbus(d) container_of(d, struct sbus_bus, ofdev.dev)
83
84extern struct sbus_bus *sbus_root;
85
86/* Device probing routines could find these handy */
87#define for_each_sbus(bus) \
88 for((bus) = sbus_root; (bus); (bus)=(bus)->next)
89
90#define for_each_sbusdev(device, bus) \
91 for((device) = (bus)->devices; (device); (device)=(device)->next)
92
93#define for_all_sbusdev(device, bus) \
94 for ((bus) = sbus_root; (bus); (bus) = (bus)->next) \
95 for ((device) = (bus)->devices; (device); (device) = (device)->next)
96
97/* Driver DVMA interfaces. */
98#define sbus_can_dma_64bit(sdev) (1)
99#define sbus_can_burst64(sdev) (1)
100extern void sbus_set_sbus64(struct sbus_dev *, int);
101extern void sbus_fill_device_irq(struct sbus_dev *);
102
103static inline void *sbus_alloc_consistent(struct sbus_dev *sdev , size_t size,
104 dma_addr_t *dma_handle)
105{
106 return dma_alloc_coherent(&sdev->ofdev.dev, size,
107 dma_handle, GFP_ATOMIC);
108}
109
110static inline void sbus_free_consistent(struct sbus_dev *sdev, size_t size,
111 void *vaddr, dma_addr_t dma_handle)
112{
113 return dma_free_coherent(&sdev->ofdev.dev, size, vaddr, dma_handle);
114}
115
116#define SBUS_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL
117#define SBUS_DMA_TODEVICE DMA_TO_DEVICE
118#define SBUS_DMA_FROMDEVICE DMA_FROM_DEVICE
119#define SBUS_DMA_NONE DMA_NONE
120
121/* All the rest use streaming mode mappings. */
122static inline dma_addr_t sbus_map_single(struct sbus_dev *sdev, void *ptr,
123 size_t size, int direction)
124{
125 return dma_map_single(&sdev->ofdev.dev, ptr, size,
126 (enum dma_data_direction) direction);
127}
128
129static inline void sbus_unmap_single(struct sbus_dev *sdev,
130 dma_addr_t dma_addr, size_t size,
131 int direction)
132{
133 dma_unmap_single(&sdev->ofdev.dev, dma_addr, size,
134 (enum dma_data_direction) direction);
135}
136
137static inline int sbus_map_sg(struct sbus_dev *sdev, struct scatterlist *sg,
138 int nents, int direction)
139{
140 return dma_map_sg(&sdev->ofdev.dev, sg, nents,
141 (enum dma_data_direction) direction);
142}
143
144static inline void sbus_unmap_sg(struct sbus_dev *sdev, struct scatterlist *sg,
145 int nents, int direction)
146{
147 dma_unmap_sg(&sdev->ofdev.dev, sg, nents,
148 (enum dma_data_direction) direction);
149}
150
151/* Finally, allow explicit synchronization of streamable mappings. */
152static inline void sbus_dma_sync_single_for_cpu(struct sbus_dev *sdev,
153 dma_addr_t dma_handle,
154 size_t size, int direction)
155{
156 dma_sync_single_for_cpu(&sdev->ofdev.dev, dma_handle, size,
157 (enum dma_data_direction) direction);
158}
159#define sbus_dma_sync_single sbus_dma_sync_single_for_cpu
160
161static inline void sbus_dma_sync_single_for_device(struct sbus_dev *sdev,
162 dma_addr_t dma_handle,
163 size_t size, int direction)
164{
165 /* No flushing needed to sync cpu writes to the device. */
166}
167
168static inline void sbus_dma_sync_sg_for_cpu(struct sbus_dev *sdev,
169 struct scatterlist *sg,
170 int nents, int direction)
171{
172 dma_sync_sg_for_cpu(&sdev->ofdev.dev, sg, nents,
173 (enum dma_data_direction) direction);
174}
175#define sbus_dma_sync_sg sbus_dma_sync_sg_for_cpu
176
177static inline void sbus_dma_sync_sg_for_device(struct sbus_dev *sdev,
178 struct scatterlist *sg,
179 int nents, int direction)
180{
181 /* No flushing needed to sync cpu writes to the device. */
182}
183
184extern void sbus_arch_bus_ranges_init(struct device_node *, struct sbus_bus *);
185extern void sbus_setup_iommu(struct sbus_bus *, struct device_node *);
186extern void sbus_setup_arch_props(struct sbus_bus *, struct device_node *);
187extern int sbus_arch_preinit(void);
188extern void sbus_arch_postinit(void);
189
190#endif /* !(_SPARC64_SBUS_H) */
diff --git a/include/asm-sparc64/scatterlist.h b/include/asm-sparc64/scatterlist.h
index 81bd058f9382..b7fef95953ca 100644
--- a/include/asm-sparc64/scatterlist.h
+++ b/include/asm-sparc64/scatterlist.h
@@ -1,27 +1 @@
1#ifndef _SPARC64_SCATTERLIST_H #include <asm-sparc/scatterlist.h>
2#define _SPARC64_SCATTERLIST_H
3
4#include <asm/page.h>
5#include <asm/types.h>
6
7struct scatterlist {
8#ifdef CONFIG_DEBUG_SG
9 unsigned long sg_magic;
10#endif
11 unsigned long page_link;
12 unsigned int offset;
13
14 unsigned int length;
15
16 dma_addr_t dma_address;
17 __u32 dma_length;
18};
19
20#define sg_dma_address(sg) ((sg)->dma_address)
21#define sg_dma_len(sg) ((sg)->dma_length)
22
23#define ISA_DMA_THRESHOLD (~0UL)
24
25#define ARCH_HAS_SG_CHAIN
26
27#endif /* !(_SPARC64_SCATTERLIST_H) */
diff --git a/include/asm-sparc64/scratchpad.h b/include/asm-sparc64/scratchpad.h
index 5e8b01fb3343..23675f6a915a 100644
--- a/include/asm-sparc64/scratchpad.h
+++ b/include/asm-sparc64/scratchpad.h
@@ -1,14 +1 @@
1#ifndef _SPARC64_SCRATCHPAD_H #include <asm-sparc/scratchpad.h>
2#define _SPARC64_SCRATCHPAD_H
3
4/* Sun4v scratchpad registers, accessed via ASI_SCRATCHPAD. */
5
6#define SCRATCHPAD_MMU_MISS 0x00 /* Shared with OBP - set by OBP */
7#define SCRATCHPAD_CPUID 0x08 /* Shared with OBP - set by hypervisor */
8#define SCRATCHPAD_UTSBREG1 0x10
9#define SCRATCHPAD_UTSBREG2 0x18
10 /* 0x20 and 0x28, hypervisor only... */
11#define SCRATCHPAD_UNUSED1 0x30
12#define SCRATCHPAD_UNUSED2 0x38 /* Reserved for OBP */
13
14#endif /* !(_SPARC64_SCRATCHPAD_H) */
diff --git a/include/asm-sparc64/seccomp.h b/include/asm-sparc64/seccomp.h
index 7fcd9968192b..f22f02a08a61 100644
--- a/include/asm-sparc64/seccomp.h
+++ b/include/asm-sparc64/seccomp.h
@@ -1,21 +1 @@
1#ifndef _ASM_SECCOMP_H #include <asm-sparc/seccomp.h>
2
3#include <linux/thread_info.h> /* already defines TIF_32BIT */
4
5#ifndef TIF_32BIT
6#error "unexpected TIF_32BIT on sparc64"
7#endif
8
9#include <linux/unistd.h>
10
11#define __NR_seccomp_read __NR_read
12#define __NR_seccomp_write __NR_write
13#define __NR_seccomp_exit __NR_exit
14#define __NR_seccomp_sigreturn __NR_rt_sigreturn
15
16#define __NR_seccomp_read_32 __NR_read
17#define __NR_seccomp_write_32 __NR_write
18#define __NR_seccomp_exit_32 __NR_exit
19#define __NR_seccomp_sigreturn_32 __NR_sigreturn
20
21#endif /* _ASM_SECCOMP_H */
diff --git a/include/asm-sparc64/sections.h b/include/asm-sparc64/sections.h
index 3f4b9fdc28d0..721496f8b2be 100644
--- a/include/asm-sparc64/sections.h
+++ b/include/asm-sparc64/sections.h
@@ -1,9 +1 @@
1#ifndef _SPARC64_SECTIONS_H #include <asm-sparc/sections.h>
2#define _SPARC64_SECTIONS_H
3
4/* nothing to see, move along */
5#include <asm-generic/sections.h>
6
7extern char _start[];
8
9#endif
diff --git a/include/asm-sparc64/semaphore.h b/include/asm-sparc64/semaphore.h
index d9b2034ed1d2..39362afde5fe 100644
--- a/include/asm-sparc64/semaphore.h
+++ b/include/asm-sparc64/semaphore.h
@@ -1 +1 @@
#include <linux/semaphore.h> #include <asm-sparc/semaphore.h>
diff --git a/include/asm-sparc64/sembuf.h b/include/asm-sparc64/sembuf.h
index 99f04e4e288c..c55b95214136 100644
--- a/include/asm-sparc64/sembuf.h
+++ b/include/asm-sparc64/sembuf.h
@@ -1,22 +1 @@
1#ifndef _SPARC64_SEMBUF_H #include <asm-sparc/sembuf.h>
2#define _SPARC64_SEMBUF_H
3
4/*
5 * The semid64_ds structure for sparc64 architecture.
6 * Note extra padding because this structure is passed back and forth
7 * between kernel and user space.
8 *
9 * Pad space is left for:
10 * - 2 miscellaneous 64-bit values
11 */
12
13struct semid64_ds {
14 struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
15 __kernel_time_t sem_otime; /* last semop time */
16 __kernel_time_t sem_ctime; /* last change time */
17 unsigned long sem_nsems; /* no. of semaphores in array */
18 unsigned long __unused1;
19 unsigned long __unused2;
20};
21
22#endif /* _SPARC64_SEMBUF_H */
diff --git a/include/asm-sparc64/setup.h b/include/asm-sparc64/setup.h
index 5053df3cec40..7143d06b2c55 100644
--- a/include/asm-sparc64/setup.h
+++ b/include/asm-sparc64/setup.h
@@ -1,10 +1 @@
1/* #include <asm-sparc/setup.h>
2 * Just a place holder.
3 */
4
5#ifndef _SPARC64_SETUP_H
6#define _SPARC64_SETUP_H
7
8#define COMMAND_LINE_SIZE 2048
9
10#endif /* _SPARC64_SETUP_H */
diff --git a/include/asm-sparc64/sfafsr.h b/include/asm-sparc64/sfafsr.h
index e96137b04a4f..8036fc377a4d 100644
--- a/include/asm-sparc64/sfafsr.h
+++ b/include/asm-sparc64/sfafsr.h
@@ -1,82 +1 @@
1#ifndef _SPARC64_SFAFSR_H #include <asm-sparc/sfafsr.h>
2#define _SPARC64_SFAFSR_H
3
4#include <linux/const.h>
5
6/* Spitfire Asynchronous Fault Status register, ASI=0x4C VA<63:0>=0x0 */
7
8#define SFAFSR_ME (_AC(1,UL) << SFAFSR_ME_SHIFT)
9#define SFAFSR_ME_SHIFT 32
10#define SFAFSR_PRIV (_AC(1,UL) << SFAFSR_PRIV_SHIFT)
11#define SFAFSR_PRIV_SHIFT 31
12#define SFAFSR_ISAP (_AC(1,UL) << SFAFSR_ISAP_SHIFT)
13#define SFAFSR_ISAP_SHIFT 30
14#define SFAFSR_ETP (_AC(1,UL) << SFAFSR_ETP_SHIFT)
15#define SFAFSR_ETP_SHIFT 29
16#define SFAFSR_IVUE (_AC(1,UL) << SFAFSR_IVUE_SHIFT)
17#define SFAFSR_IVUE_SHIFT 28
18#define SFAFSR_TO (_AC(1,UL) << SFAFSR_TO_SHIFT)
19#define SFAFSR_TO_SHIFT 27
20#define SFAFSR_BERR (_AC(1,UL) << SFAFSR_BERR_SHIFT)
21#define SFAFSR_BERR_SHIFT 26
22#define SFAFSR_LDP (_AC(1,UL) << SFAFSR_LDP_SHIFT)
23#define SFAFSR_LDP_SHIFT 25
24#define SFAFSR_CP (_AC(1,UL) << SFAFSR_CP_SHIFT)
25#define SFAFSR_CP_SHIFT 24
26#define SFAFSR_WP (_AC(1,UL) << SFAFSR_WP_SHIFT)
27#define SFAFSR_WP_SHIFT 23
28#define SFAFSR_EDP (_AC(1,UL) << SFAFSR_EDP_SHIFT)
29#define SFAFSR_EDP_SHIFT 22
30#define SFAFSR_UE (_AC(1,UL) << SFAFSR_UE_SHIFT)
31#define SFAFSR_UE_SHIFT 21
32#define SFAFSR_CE (_AC(1,UL) << SFAFSR_CE_SHIFT)
33#define SFAFSR_CE_SHIFT 20
34#define SFAFSR_ETS (_AC(0xf,UL) << SFAFSR_ETS_SHIFT)
35#define SFAFSR_ETS_SHIFT 16
36#define SFAFSR_PSYND (_AC(0xffff,UL) << SFAFSR_PSYND_SHIFT)
37#define SFAFSR_PSYND_SHIFT 0
38
39/* UDB Error Register, ASI=0x7f VA<63:0>=0x0(High),0x18(Low) for read
40 * ASI=0x77 VA<63:0>=0x0(High),0x18(Low) for write
41 */
42
43#define UDBE_UE (_AC(1,UL) << 9)
44#define UDBE_CE (_AC(1,UL) << 8)
45#define UDBE_E_SYNDR (_AC(0xff,UL) << 0)
46
47/* The trap handlers for asynchronous errors encode the AFSR and
48 * other pieces of information into a 64-bit argument for C code
49 * encoded as follows:
50 *
51 * -----------------------------------------------
52 * | UDB_H | UDB_L | TL>1 | TT | AFSR |
53 * -----------------------------------------------
54 * 63 54 53 44 42 41 33 32 0
55 *
56 * The AFAR is passed in unchanged.
57 */
58#define SFSTAT_UDBH_MASK (_AC(0x3ff,UL) << SFSTAT_UDBH_SHIFT)
59#define SFSTAT_UDBH_SHIFT 54
60#define SFSTAT_UDBL_MASK (_AC(0x3ff,UL) << SFSTAT_UDBH_SHIFT)
61#define SFSTAT_UDBL_SHIFT 44
62#define SFSTAT_TL_GT_ONE (_AC(1,UL) << SFSTAT_TL_GT_ONE_SHIFT)
63#define SFSTAT_TL_GT_ONE_SHIFT 42
64#define SFSTAT_TRAP_TYPE (_AC(0x1FF,UL) << SFSTAT_TRAP_TYPE_SHIFT)
65#define SFSTAT_TRAP_TYPE_SHIFT 33
66#define SFSTAT_AFSR_MASK (_AC(0x1ffffffff,UL) << SFSTAT_AFSR_SHIFT)
67#define SFSTAT_AFSR_SHIFT 0
68
69/* ESTATE Error Enable Register, ASI=0x4b VA<63:0>=0x0 */
70#define ESTATE_ERR_CE 0x1 /* Correctable errors */
71#define ESTATE_ERR_NCE 0x2 /* TO, BERR, LDP, ETP, EDP, WP, UE, IVUE */
72#define ESTATE_ERR_ISAP 0x4 /* System address parity error */
73#define ESTATE_ERR_ALL (ESTATE_ERR_CE | \
74 ESTATE_ERR_NCE | \
75 ESTATE_ERR_ISAP)
76
77/* The various trap types that report using the above state. */
78#define TRAP_TYPE_IAE 0x09 /* Instruction Access Error */
79#define TRAP_TYPE_DAE 0x32 /* Data Access Error */
80#define TRAP_TYPE_CEE 0x63 /* Correctable ECC Error */
81
82#endif /* _SPARC64_SFAFSR_H */
diff --git a/include/asm-sparc64/sfp-machine.h b/include/asm-sparc64/sfp-machine.h
index c9331b02d9c8..7bbc4fecdc7d 100644
--- a/include/asm-sparc64/sfp-machine.h
+++ b/include/asm-sparc64/sfp-machine.h
@@ -1,93 +1 @@
1/* Machine-dependent software floating-point definitions. #include <asm-sparc/sfp-machine.h>
2 Sparc64 kernel version.
3 Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Richard Henderson (rth@cygnus.com),
6 Jakub Jelinek (jj@ultra.linux.cz) and
7 David S. Miller (davem@redhat.com).
8
9 The GNU C Library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
13
14 The GNU C Library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public
20 License along with the GNU C Library; see the file COPYING.LIB. If
21 not, write to the Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23
24#ifndef _SFP_MACHINE_H
25#define _SFP_MACHINE_H
26
27#define _FP_W_TYPE_SIZE 64
28#define _FP_W_TYPE unsigned long
29#define _FP_WS_TYPE signed long
30#define _FP_I_TYPE long
31
32#define _FP_MUL_MEAT_S(R,X,Y) \
33 _FP_MUL_MEAT_1_imm(_FP_WFRACBITS_S,R,X,Y)
34#define _FP_MUL_MEAT_D(R,X,Y) \
35 _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
36#define _FP_MUL_MEAT_Q(R,X,Y) \
37 _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
38
39#define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_imm(S,R,X,Y,_FP_DIV_HELP_imm)
40#define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_1_udiv_norm(D,R,X,Y)
41#define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_2_udiv(Q,R,X,Y)
42
43#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
44#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1)
45#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1
46#define _FP_NANSIGN_S 0
47#define _FP_NANSIGN_D 0
48#define _FP_NANSIGN_Q 0
49
50#define _FP_KEEPNANFRACP 1
51
52/* If one NaN is signaling and the other is not,
53 * we choose that one, otherwise we choose X.
54 */
55/* For _Qp_* and _Q_*, this should prefer X, for
56 * CPU instruction emulation this should prefer Y.
57 * (see SPAMv9 B.2.2 section).
58 */
59#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
60 do { \
61 if ((_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs) \
62 && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
63 { \
64 R##_s = X##_s; \
65 _FP_FRAC_COPY_##wc(R,X); \
66 } \
67 else \
68 { \
69 R##_s = Y##_s; \
70 _FP_FRAC_COPY_##wc(R,Y); \
71 } \
72 R##_c = FP_CLS_NAN; \
73 } while (0)
74
75/* Obtain the current rounding mode. */
76#ifndef FP_ROUNDMODE
77#define FP_ROUNDMODE ((current_thread_info()->xfsr[0] >> 30) & 0x3)
78#endif
79
80/* Exception flags. */
81#define FP_EX_INVALID (1 << 4)
82#define FP_EX_OVERFLOW (1 << 3)
83#define FP_EX_UNDERFLOW (1 << 2)
84#define FP_EX_DIVZERO (1 << 1)
85#define FP_EX_INEXACT (1 << 0)
86
87#define FP_HANDLE_EXCEPTIONS return _fex
88
89#define FP_INHIBIT_RESULTS ((current_thread_info()->xfsr[0] >> 23) & _fex)
90
91#define FP_TRAPPING_EXCEPTIONS ((current_thread_info()->xfsr[0] >> 23) & 0x1f)
92
93#endif
diff --git a/include/asm-sparc64/shmbuf.h b/include/asm-sparc64/shmbuf.h
index 61c2ef42eba3..0c54a2d68681 100644
--- a/include/asm-sparc64/shmbuf.h
+++ b/include/asm-sparc64/shmbuf.h
@@ -1,38 +1 @@
1#ifndef _SPARC64_SHMBUF_H #include <asm-sparc/shmbuf.h>
2#define _SPARC64_SHMBUF_H
3
4/*
5 * The shmid64_ds structure for sparc64 architecture.
6 * Note extra padding because this structure is passed back and forth
7 * between kernel and user space.
8 *
9 * Pad space is left for:
10 * - 2 miscellaneous 64-bit values
11 */
12
13struct shmid64_ds {
14 struct ipc64_perm shm_perm; /* operation perms */
15 __kernel_time_t shm_atime; /* last attach time */
16 __kernel_time_t shm_dtime; /* last detach time */
17 __kernel_time_t shm_ctime; /* last change time */
18 size_t shm_segsz; /* size of segment (bytes) */
19 __kernel_pid_t shm_cpid; /* pid of creator */
20 __kernel_pid_t shm_lpid; /* pid of last operator */
21 unsigned long shm_nattch; /* no. of current attaches */
22 unsigned long __unused1;
23 unsigned long __unused2;
24};
25
26struct shminfo64 {
27 unsigned long shmmax;
28 unsigned long shmmin;
29 unsigned long shmmni;
30 unsigned long shmseg;
31 unsigned long shmall;
32 unsigned long __unused1;
33 unsigned long __unused2;
34 unsigned long __unused3;
35 unsigned long __unused4;
36};
37
38#endif /* _SPARC64_SHMBUF_H */
diff --git a/include/asm-sparc64/shmparam.h b/include/asm-sparc64/shmparam.h
index 1ed0d6701a9b..5fa3a9b05e7f 100644
--- a/include/asm-sparc64/shmparam.h
+++ b/include/asm-sparc64/shmparam.h
@@ -1,10 +1 @@
1#ifndef _ASMSPARC64_SHMPARAM_H #include <asm-sparc/shmparam.h>
2#define _ASMSPARC64_SHMPARAM_H
3
4#include <asm/spitfire.h>
5
6#define __ARCH_FORCE_SHMLBA 1
7/* attach addr a multiple of this */
8#define SHMLBA ((PAGE_SIZE > L1DCACHE_SIZE) ? PAGE_SIZE : L1DCACHE_SIZE)
9
10#endif /* _ASMSPARC64_SHMPARAM_H */
diff --git a/include/asm-sparc64/sigcontext.h b/include/asm-sparc64/sigcontext.h
index 1c868d680cfc..5b16dcce44f2 100644
--- a/include/asm-sparc64/sigcontext.h
+++ b/include/asm-sparc64/sigcontext.h
@@ -1,87 +1 @@
1#ifndef __SPARC64_SIGCONTEXT_H #include <asm-sparc/sigcontext.h>
2#define __SPARC64_SIGCONTEXT_H
3
4#ifdef __KERNEL__
5#include <asm/ptrace.h>
6#endif
7
8#ifndef __ASSEMBLY__
9
10#ifdef __KERNEL__
11
12#define __SUNOS_MAXWIN 31
13
14/* This is what SunOS does, so shall I unless we use new 32bit signals or rt signals. */
15struct sigcontext32 {
16 int sigc_onstack; /* state to restore */
17 int sigc_mask; /* sigmask to restore */
18 int sigc_sp; /* stack pointer */
19 int sigc_pc; /* program counter */
20 int sigc_npc; /* next program counter */
21 int sigc_psr; /* for condition codes etc */
22 int sigc_g1; /* User uses these two registers */
23 int sigc_o0; /* within the trampoline code. */
24
25 /* Now comes information regarding the users window set
26 * at the time of the signal.
27 */
28 int sigc_oswins; /* outstanding windows */
29
30 /* stack ptrs for each regwin buf */
31 unsigned sigc_spbuf[__SUNOS_MAXWIN];
32
33 /* Windows to restore after signal */
34 struct reg_window32 sigc_wbuf[__SUNOS_MAXWIN];
35};
36
37#endif
38
39#ifdef __KERNEL__
40
41/* This is what we use for 32bit new non-rt signals. */
42
43typedef struct {
44 struct {
45 unsigned int psr;
46 unsigned int pc;
47 unsigned int npc;
48 unsigned int y;
49 unsigned int u_regs[16]; /* globals and ins */
50 } si_regs;
51 int si_mask;
52} __siginfo32_t;
53
54#endif
55
56typedef struct {
57 unsigned int si_float_regs [64];
58 unsigned long si_fsr;
59 unsigned long si_gsr;
60 unsigned long si_fprs;
61} __siginfo_fpu_t;
62
63/* This is what SunOS doesn't, so we have to write this alone
64 and do it properly. */
65struct sigcontext {
66 /* The size of this array has to match SI_MAX_SIZE from siginfo.h */
67 char sigc_info[128];
68 struct {
69 unsigned long u_regs[16]; /* globals and ins */
70 unsigned long tstate;
71 unsigned long tpc;
72 unsigned long tnpc;
73 unsigned int y;
74 unsigned int fprs;
75 } sigc_regs;
76 __siginfo_fpu_t * sigc_fpu_save;
77 struct {
78 void * ss_sp;
79 int ss_flags;
80 unsigned long ss_size;
81 } sigc_stack;
82 unsigned long sigc_mask;
83};
84
85#endif /* !(__ASSEMBLY__) */
86
87#endif /* !(__SPARC64_SIGCONTEXT_H) */
diff --git a/include/asm-sparc64/siginfo.h b/include/asm-sparc64/siginfo.h
index c96e6c30f8b0..8ffd6ebabc7a 100644
--- a/include/asm-sparc64/siginfo.h
+++ b/include/asm-sparc64/siginfo.h
@@ -1,32 +1 @@
1#ifndef _SPARC64_SIGINFO_H #include <asm-sparc/siginfo.h>
2#define _SPARC64_SIGINFO_H
3
4#define SI_PAD_SIZE32 ((SI_MAX_SIZE/sizeof(int)) - 3)
5
6#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
7#define __ARCH_SI_TRAPNO
8#define __ARCH_SI_BAND_T int
9
10#include <asm-generic/siginfo.h>
11
12#ifdef __KERNEL__
13
14#include <linux/compat.h>
15
16#ifdef CONFIG_COMPAT
17
18struct compat_siginfo;
19
20#endif /* CONFIG_COMPAT */
21
22#endif /* __KERNEL__ */
23
24#define SI_NOINFO 32767 /* no information in siginfo_t */
25
26/*
27 * SIGEMT si_codes
28 */
29#define EMT_TAGOVF (__SI_FAULT|1) /* tag overflow */
30#define NSIGEMT 1
31
32#endif
diff --git a/include/asm-sparc64/signal.h b/include/asm-sparc64/signal.h
index 2a7c7934ac0a..79705e5d49c3 100644
--- a/include/asm-sparc64/signal.h
+++ b/include/asm-sparc64/signal.h
@@ -1,194 +1 @@
1#ifndef _ASMSPARC64_SIGNAL_H #include <asm-sparc/signal.h>
2#define _ASMSPARC64_SIGNAL_H
3
4#include <asm/sigcontext.h>
5
6#ifdef __KERNEL__
7#ifndef __ASSEMBLY__
8#include <linux/personality.h>
9#include <linux/types.h>
10#endif
11#endif
12
13/* On the Sparc the signal handlers get passed a 'sub-signal' code
14 * for certain signal types, which we document here.
15 */
16#define SIGHUP 1
17#define SIGINT 2
18#define SIGQUIT 3
19#define SIGILL 4
20#define SUBSIG_STACK 0
21#define SUBSIG_ILLINST 2
22#define SUBSIG_PRIVINST 3
23#define SUBSIG_BADTRAP(t) (0x80 + (t))
24
25#define SIGTRAP 5
26#define SIGABRT 6
27#define SIGIOT 6
28
29#define SIGEMT 7
30#define SUBSIG_TAG 10
31
32#define SIGFPE 8
33#define SUBSIG_FPDISABLED 0x400
34#define SUBSIG_FPERROR 0x404
35#define SUBSIG_FPINTOVFL 0x001
36#define SUBSIG_FPSTSIG 0x002
37#define SUBSIG_IDIVZERO 0x014
38#define SUBSIG_FPINEXACT 0x0c4
39#define SUBSIG_FPDIVZERO 0x0c8
40#define SUBSIG_FPUNFLOW 0x0cc
41#define SUBSIG_FPOPERROR 0x0d0
42#define SUBSIG_FPOVFLOW 0x0d4
43
44#define SIGKILL 9
45#define SIGBUS 10
46#define SUBSIG_BUSTIMEOUT 1
47#define SUBSIG_ALIGNMENT 2
48#define SUBSIG_MISCERROR 5
49
50#define SIGSEGV 11
51#define SUBSIG_NOMAPPING 3
52#define SUBSIG_PROTECTION 4
53#define SUBSIG_SEGERROR 5
54
55#define SIGSYS 12
56
57#define SIGPIPE 13
58#define SIGALRM 14
59#define SIGTERM 15
60#define SIGURG 16
61
62/* SunOS values which deviate from the Linux/i386 ones */
63#define SIGSTOP 17
64#define SIGTSTP 18
65#define SIGCONT 19
66#define SIGCHLD 20
67#define SIGTTIN 21
68#define SIGTTOU 22
69#define SIGIO 23
70#define SIGPOLL SIGIO /* SysV name for SIGIO */
71#define SIGXCPU 24
72#define SIGXFSZ 25
73#define SIGVTALRM 26
74#define SIGPROF 27
75#define SIGWINCH 28
76#define SIGLOST 29
77#define SIGPWR SIGLOST
78#define SIGUSR1 30
79#define SIGUSR2 31
80
81/* Most things should be clean enough to redefine this at will, if care
82 is taken to make libc match. */
83
84#define __OLD_NSIG 32
85#define __NEW_NSIG 64
86#define _NSIG_BPW 64
87#define _NSIG_WORDS (__NEW_NSIG / _NSIG_BPW)
88
89#define SIGRTMIN 32
90#define SIGRTMAX __NEW_NSIG
91
92#if defined(__KERNEL__) || defined(__WANT_POSIX1B_SIGNALS__)
93#define _NSIG __NEW_NSIG
94#define __new_sigset_t sigset_t
95#define __new_sigaction sigaction
96#define __new_sigaction32 sigaction32
97#define __old_sigset_t old_sigset_t
98#define __old_sigaction old_sigaction
99#define __old_sigaction32 old_sigaction32
100#else
101#define _NSIG __OLD_NSIG
102#define NSIG _NSIG
103#define __old_sigset_t sigset_t
104#define __old_sigaction sigaction
105#define __old_sigaction32 sigaction32
106#endif
107
108#ifndef __ASSEMBLY__
109
110typedef unsigned long __old_sigset_t; /* at least 32 bits */
111
112typedef struct {
113 unsigned long sig[_NSIG_WORDS];
114} __new_sigset_t;
115
116/* A SunOS sigstack */
117struct sigstack {
118 /* XXX 32-bit pointers pinhead XXX */
119 char *the_stack;
120 int cur_status;
121};
122
123/* Sigvec flags */
124#define _SV_SSTACK 1u /* This signal handler should use sig-stack */
125#define _SV_INTR 2u /* Sig return should not restart system call */
126#define _SV_RESET 4u /* Set handler to SIG_DFL upon taken signal */
127#define _SV_IGNCHILD 8u /* Do not send SIGCHLD */
128
129/*
130 * sa_flags values: SA_STACK is not currently supported, but will allow the
131 * usage of signal stacks by using the (now obsolete) sa_restorer field in
132 * the sigaction structure as a stack pointer. This is now possible due to
133 * the changes in signal handling. LBT 010493.
134 * SA_RESTART flag to get restarting signals (which were the default long ago)
135 */
136#define SA_NOCLDSTOP _SV_IGNCHILD
137#define SA_STACK _SV_SSTACK
138#define SA_ONSTACK _SV_SSTACK
139#define SA_RESTART _SV_INTR
140#define SA_ONESHOT _SV_RESET
141#define SA_NOMASK 0x20u
142#define SA_NOCLDWAIT 0x100u
143#define SA_SIGINFO 0x200u
144
145
146#define SIG_BLOCK 0x01 /* for blocking signals */
147#define SIG_UNBLOCK 0x02 /* for unblocking signals */
148#define SIG_SETMASK 0x04 /* for setting the signal mask */
149
150/*
151 * sigaltstack controls
152 */
153#define SS_ONSTACK 1
154#define SS_DISABLE 2
155
156#define MINSIGSTKSZ 4096
157#define SIGSTKSZ 16384
158
159#include <asm-generic/signal.h>
160
161struct __new_sigaction {
162 __sighandler_t sa_handler;
163 unsigned long sa_flags;
164 __sigrestore_t sa_restorer; /* not used by Linux/SPARC yet */
165 __new_sigset_t sa_mask;
166};
167
168struct __old_sigaction {
169 __sighandler_t sa_handler;
170 __old_sigset_t sa_mask;
171 unsigned long sa_flags;
172 void (*sa_restorer)(void); /* not used by Linux/SPARC yet */
173};
174
175typedef struct sigaltstack {
176 void __user *ss_sp;
177 int ss_flags;
178 size_t ss_size;
179} stack_t;
180
181#ifdef __KERNEL__
182
183struct k_sigaction {
184 struct __new_sigaction sa;
185 void __user *ka_restorer;
186};
187
188#define ptrace_signal_deliver(regs, cookie) do { } while (0)
189
190#endif /* !(__KERNEL__) */
191
192#endif /* !(__ASSEMBLY__) */
193
194#endif /* !(_ASMSPARC64_SIGNAL_H) */
diff --git a/include/asm-sparc64/smp.h b/include/asm-sparc64/smp.h
index cd0311b2e19d..5095a2cbea52 100644
--- a/include/asm-sparc64/smp.h
+++ b/include/asm-sparc64/smp.h
@@ -1,64 +1 @@
1/* smp.h: Sparc64 specific SMP stuff. #include <asm-sparc/smp.h>
2 *
3 * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_SMP_H
7#define _SPARC64_SMP_H
8
9#include <linux/threads.h>
10#include <asm/asi.h>
11#include <asm/starfire.h>
12#include <asm/spitfire.h>
13
14#ifndef __ASSEMBLY__
15
16#include <linux/cpumask.h>
17#include <linux/cache.h>
18
19#endif /* !(__ASSEMBLY__) */
20
21#ifdef CONFIG_SMP
22
23#ifndef __ASSEMBLY__
24
25/*
26 * Private routines/data
27 */
28
29#include <linux/bitops.h>
30#include <asm/atomic.h>
31#include <asm/percpu.h>
32
33DECLARE_PER_CPU(cpumask_t, cpu_sibling_map);
34extern cpumask_t cpu_core_map[NR_CPUS];
35extern int sparc64_multi_core;
36
37/*
38 * General functions that each host system must provide.
39 */
40
41extern int hard_smp_processor_id(void);
42#define raw_smp_processor_id() (current_thread_info()->cpu)
43
44extern void smp_fill_in_sib_core_maps(void);
45extern void cpu_play_dead(void);
46
47extern void smp_fetch_global_regs(void);
48
49#ifdef CONFIG_HOTPLUG_CPU
50extern int __cpu_disable(void);
51extern void __cpu_die(unsigned int cpu);
52#endif
53
54#endif /* !(__ASSEMBLY__) */
55
56#else
57
58#define hard_smp_processor_id() 0
59#define smp_fill_in_sib_core_maps() do { } while (0)
60#define smp_fetch_global_regs() do { } while (0)
61
62#endif /* !(CONFIG_SMP) */
63
64#endif /* !(_SPARC64_SMP_H) */
diff --git a/include/asm-sparc64/socket.h b/include/asm-sparc64/socket.h
index 5af688f56716..13e0d5d94bb3 100644
--- a/include/asm-sparc64/socket.h
+++ b/include/asm-sparc64/socket.h
@@ -1,57 +1 @@
1#ifndef _ASM_SOCKET_H #include <asm-sparc/socket.h>
2#define _ASM_SOCKET_H
3
4#include <asm/sockios.h>
5
6/* For setsockopt(2) */
7#define SOL_SOCKET 0xffff
8
9#define SO_DEBUG 0x0001
10#define SO_PASSCRED 0x0002
11#define SO_REUSEADDR 0x0004
12#define SO_KEEPALIVE 0x0008
13#define SO_DONTROUTE 0x0010
14#define SO_BROADCAST 0x0020
15#define SO_PEERCRED 0x0040
16#define SO_LINGER 0x0080
17#define SO_OOBINLINE 0x0100
18/* To add :#define SO_REUSEPORT 0x0200 */
19#define SO_BSDCOMPAT 0x0400
20#define SO_RCVLOWAT 0x0800
21#define SO_SNDLOWAT 0x1000
22#define SO_RCVTIMEO 0x2000
23#define SO_SNDTIMEO 0x4000
24#define SO_ACCEPTCONN 0x8000
25
26#define SO_SNDBUF 0x1001
27#define SO_RCVBUF 0x1002
28#define SO_SNDBUFFORCE 0x100a
29#define SO_RCVBUFFORCE 0x100b
30#define SO_ERROR 0x1007
31#define SO_TYPE 0x1008
32
33/* Linux specific, keep the same. */
34#define SO_NO_CHECK 0x000b
35#define SO_PRIORITY 0x000c
36
37#define SO_BINDTODEVICE 0x000d
38
39#define SO_ATTACH_FILTER 0x001a
40#define SO_DETACH_FILTER 0x001b
41
42#define SO_PEERNAME 0x001c
43#define SO_TIMESTAMP 0x001d
44#define SCM_TIMESTAMP SO_TIMESTAMP
45
46#define SO_PEERSEC 0x001e
47#define SO_PASSSEC 0x001f
48#define SO_TIMESTAMPNS 0x0021
49#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
50
51/* Security levels - as per NRL IPv6 - don't actually do anything */
52#define SO_SECURITY_AUTHENTICATION 0x5001
53#define SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002
54#define SO_SECURITY_ENCRYPTION_NETWORK 0x5004
55
56#define SO_MARK 0x0022
57#endif /* _ASM_SOCKET_H */
diff --git a/include/asm-sparc64/sockios.h b/include/asm-sparc64/sockios.h
index c7d9900638d0..2cb4b641482c 100644
--- a/include/asm-sparc64/sockios.h
+++ b/include/asm-sparc64/sockios.h
@@ -1,14 +1 @@
1#ifndef _ASM_SPARC64_SOCKIOS_H #include <asm-sparc/sockios.h>
2#define _ASM_SPARC64_SOCKIOS_H
3
4/* Socket-level I/O control calls. */
5#define FIOSETOWN 0x8901
6#define SIOCSPGRP 0x8902
7#define FIOGETOWN 0x8903
8#define SIOCGPGRP 0x8904
9#define SIOCATMARK 0x8905
10#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
11#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
12
13#endif /* !(_ASM_SPARC64_SOCKIOS_H) */
14
diff --git a/include/asm-sparc64/sparsemem.h b/include/asm-sparc64/sparsemem.h
index b99d4e4b6d28..e681f22a97ae 100644
--- a/include/asm-sparc64/sparsemem.h
+++ b/include/asm-sparc64/sparsemem.h
@@ -1,12 +1 @@
1#ifndef _SPARC64_SPARSEMEM_H #include <asm-sparc/sparsemem.h>
2#define _SPARC64_SPARSEMEM_H
3
4#ifdef __KERNEL__
5
6#define SECTION_SIZE_BITS 30
7#define MAX_PHYSADDR_BITS 42
8#define MAX_PHYSMEM_BITS 42
9
10#endif /* !(__KERNEL__) */
11
12#endif /* !(_SPARC64_SPARSEMEM_H) */
diff --git a/include/asm-sparc64/spinlock.h b/include/asm-sparc64/spinlock.h
index 0006fe9f8c7a..0115b8156eb8 100644
--- a/include/asm-sparc64/spinlock.h
+++ b/include/asm-sparc64/spinlock.h
@@ -1,250 +1 @@
1/* spinlock.h: 64-bit Sparc spinlock support. #include <asm-sparc/spinlock.h>
2 *
3 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
4 */
5
6#ifndef __SPARC64_SPINLOCK_H
7#define __SPARC64_SPINLOCK_H
8
9#include <linux/threads.h> /* For NR_CPUS */
10
11#ifndef __ASSEMBLY__
12
13/* To get debugging spinlocks which detect and catch
14 * deadlock situations, set CONFIG_DEBUG_SPINLOCK
15 * and rebuild your kernel.
16 */
17
18/* All of these locking primitives are expected to work properly
19 * even in an RMO memory model, which currently is what the kernel
20 * runs in.
21 *
22 * There is another issue. Because we play games to save cycles
23 * in the non-contention case, we need to be extra careful about
24 * branch targets into the "spinning" code. They live in their
25 * own section, but the newer V9 branches have a shorter range
26 * than the traditional 32-bit sparc branch variants. The rule
27 * is that the branches that go into and out of the spinner sections
28 * must be pre-V9 branches.
29 */
30
31#define __raw_spin_is_locked(lp) ((lp)->lock != 0)
32
33#define __raw_spin_unlock_wait(lp) \
34 do { rmb(); \
35 } while((lp)->lock)
36
37static inline void __raw_spin_lock(raw_spinlock_t *lock)
38{
39 unsigned long tmp;
40
41 __asm__ __volatile__(
42"1: ldstub [%1], %0\n"
43" membar #StoreLoad | #StoreStore\n"
44" brnz,pn %0, 2f\n"
45" nop\n"
46" .subsection 2\n"
47"2: ldub [%1], %0\n"
48" membar #LoadLoad\n"
49" brnz,pt %0, 2b\n"
50" nop\n"
51" ba,a,pt %%xcc, 1b\n"
52" .previous"
53 : "=&r" (tmp)
54 : "r" (lock)
55 : "memory");
56}
57
58static inline int __raw_spin_trylock(raw_spinlock_t *lock)
59{
60 unsigned long result;
61
62 __asm__ __volatile__(
63" ldstub [%1], %0\n"
64" membar #StoreLoad | #StoreStore"
65 : "=r" (result)
66 : "r" (lock)
67 : "memory");
68
69 return (result == 0UL);
70}
71
72static inline void __raw_spin_unlock(raw_spinlock_t *lock)
73{
74 __asm__ __volatile__(
75" membar #StoreStore | #LoadStore\n"
76" stb %%g0, [%0]"
77 : /* No outputs */
78 : "r" (lock)
79 : "memory");
80}
81
82static inline void __raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
83{
84 unsigned long tmp1, tmp2;
85
86 __asm__ __volatile__(
87"1: ldstub [%2], %0\n"
88" membar #StoreLoad | #StoreStore\n"
89" brnz,pn %0, 2f\n"
90" nop\n"
91" .subsection 2\n"
92"2: rdpr %%pil, %1\n"
93" wrpr %3, %%pil\n"
94"3: ldub [%2], %0\n"
95" membar #LoadLoad\n"
96" brnz,pt %0, 3b\n"
97" nop\n"
98" ba,pt %%xcc, 1b\n"
99" wrpr %1, %%pil\n"
100" .previous"
101 : "=&r" (tmp1), "=&r" (tmp2)
102 : "r"(lock), "r"(flags)
103 : "memory");
104}
105
106/* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
107
108static void inline __read_lock(raw_rwlock_t *lock)
109{
110 unsigned long tmp1, tmp2;
111
112 __asm__ __volatile__ (
113"1: ldsw [%2], %0\n"
114" brlz,pn %0, 2f\n"
115"4: add %0, 1, %1\n"
116" cas [%2], %0, %1\n"
117" cmp %0, %1\n"
118" membar #StoreLoad | #StoreStore\n"
119" bne,pn %%icc, 1b\n"
120" nop\n"
121" .subsection 2\n"
122"2: ldsw [%2], %0\n"
123" membar #LoadLoad\n"
124" brlz,pt %0, 2b\n"
125" nop\n"
126" ba,a,pt %%xcc, 4b\n"
127" .previous"
128 : "=&r" (tmp1), "=&r" (tmp2)
129 : "r" (lock)
130 : "memory");
131}
132
133static int inline __read_trylock(raw_rwlock_t *lock)
134{
135 int tmp1, tmp2;
136
137 __asm__ __volatile__ (
138"1: ldsw [%2], %0\n"
139" brlz,a,pn %0, 2f\n"
140" mov 0, %0\n"
141" add %0, 1, %1\n"
142" cas [%2], %0, %1\n"
143" cmp %0, %1\n"
144" membar #StoreLoad | #StoreStore\n"
145" bne,pn %%icc, 1b\n"
146" mov 1, %0\n"
147"2:"
148 : "=&r" (tmp1), "=&r" (tmp2)
149 : "r" (lock)
150 : "memory");
151
152 return tmp1;
153}
154
155static void inline __read_unlock(raw_rwlock_t *lock)
156{
157 unsigned long tmp1, tmp2;
158
159 __asm__ __volatile__(
160" membar #StoreLoad | #LoadLoad\n"
161"1: lduw [%2], %0\n"
162" sub %0, 1, %1\n"
163" cas [%2], %0, %1\n"
164" cmp %0, %1\n"
165" bne,pn %%xcc, 1b\n"
166" nop"
167 : "=&r" (tmp1), "=&r" (tmp2)
168 : "r" (lock)
169 : "memory");
170}
171
172static void inline __write_lock(raw_rwlock_t *lock)
173{
174 unsigned long mask, tmp1, tmp2;
175
176 mask = 0x80000000UL;
177
178 __asm__ __volatile__(
179"1: lduw [%2], %0\n"
180" brnz,pn %0, 2f\n"
181"4: or %0, %3, %1\n"
182" cas [%2], %0, %1\n"
183" cmp %0, %1\n"
184" membar #StoreLoad | #StoreStore\n"
185" bne,pn %%icc, 1b\n"
186" nop\n"
187" .subsection 2\n"
188"2: lduw [%2], %0\n"
189" membar #LoadLoad\n"
190" brnz,pt %0, 2b\n"
191" nop\n"
192" ba,a,pt %%xcc, 4b\n"
193" .previous"
194 : "=&r" (tmp1), "=&r" (tmp2)
195 : "r" (lock), "r" (mask)
196 : "memory");
197}
198
199static void inline __write_unlock(raw_rwlock_t *lock)
200{
201 __asm__ __volatile__(
202" membar #LoadStore | #StoreStore\n"
203" stw %%g0, [%0]"
204 : /* no outputs */
205 : "r" (lock)
206 : "memory");
207}
208
209static int inline __write_trylock(raw_rwlock_t *lock)
210{
211 unsigned long mask, tmp1, tmp2, result;
212
213 mask = 0x80000000UL;
214
215 __asm__ __volatile__(
216" mov 0, %2\n"
217"1: lduw [%3], %0\n"
218" brnz,pn %0, 2f\n"
219" or %0, %4, %1\n"
220" cas [%3], %0, %1\n"
221" cmp %0, %1\n"
222" membar #StoreLoad | #StoreStore\n"
223" bne,pn %%icc, 1b\n"
224" nop\n"
225" mov 1, %2\n"
226"2:"
227 : "=&r" (tmp1), "=&r" (tmp2), "=&r" (result)
228 : "r" (lock), "r" (mask)
229 : "memory");
230
231 return result;
232}
233
234#define __raw_read_lock(p) __read_lock(p)
235#define __raw_read_trylock(p) __read_trylock(p)
236#define __raw_read_unlock(p) __read_unlock(p)
237#define __raw_write_lock(p) __write_lock(p)
238#define __raw_write_unlock(p) __write_unlock(p)
239#define __raw_write_trylock(p) __write_trylock(p)
240
241#define __raw_read_can_lock(rw) (!((rw)->lock & 0x80000000UL))
242#define __raw_write_can_lock(rw) (!(rw)->lock)
243
244#define _raw_spin_relax(lock) cpu_relax()
245#define _raw_read_relax(lock) cpu_relax()
246#define _raw_write_relax(lock) cpu_relax()
247
248#endif /* !(__ASSEMBLY__) */
249
250#endif /* !(__SPARC64_SPINLOCK_H) */
diff --git a/include/asm-sparc64/spinlock_types.h b/include/asm-sparc64/spinlock_types.h
index e128112a0d7c..48d81c8734b5 100644
--- a/include/asm-sparc64/spinlock_types.h
+++ b/include/asm-sparc64/spinlock_types.h
@@ -1,20 +1 @@
1#ifndef __SPARC64_SPINLOCK_TYPES_H #include <asm-sparc/spinlock_types.h>
2#define __SPARC64_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned char lock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 volatile unsigned int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { 0 }
19
20#endif
diff --git a/include/asm-sparc64/spitfire.h b/include/asm-sparc64/spitfire.h
index 985ea7e31992..4430d2fbb0dc 100644
--- a/include/asm-sparc64/spitfire.h
+++ b/include/asm-sparc64/spitfire.h
@@ -1,342 +1 @@
1/* spitfire.h: SpitFire/BlackBird/Cheetah inline MMU operations. #include <asm-sparc/spitfire.h>
2 *
3 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_SPITFIRE_H
7#define _SPARC64_SPITFIRE_H
8
9#include <asm/asi.h>
10
11/* The following register addresses are accessible via ASI_DMMU
12 * and ASI_IMMU, that is there is a distinct and unique copy of
13 * each these registers for each TLB.
14 */
15#define TSB_TAG_TARGET 0x0000000000000000 /* All chips */
16#define TLB_SFSR 0x0000000000000018 /* All chips */
17#define TSB_REG 0x0000000000000028 /* All chips */
18#define TLB_TAG_ACCESS 0x0000000000000030 /* All chips */
19#define VIRT_WATCHPOINT 0x0000000000000038 /* All chips */
20#define PHYS_WATCHPOINT 0x0000000000000040 /* All chips */
21#define TSB_EXTENSION_P 0x0000000000000048 /* Ultra-III and later */
22#define TSB_EXTENSION_S 0x0000000000000050 /* Ultra-III and later, D-TLB only */
23#define TSB_EXTENSION_N 0x0000000000000058 /* Ultra-III and later */
24#define TLB_TAG_ACCESS_EXT 0x0000000000000060 /* Ultra-III+ and later */
25
26/* These registers only exist as one entity, and are accessed
27 * via ASI_DMMU only.
28 */
29#define PRIMARY_CONTEXT 0x0000000000000008
30#define SECONDARY_CONTEXT 0x0000000000000010
31#define DMMU_SFAR 0x0000000000000020
32#define VIRT_WATCHPOINT 0x0000000000000038
33#define PHYS_WATCHPOINT 0x0000000000000040
34
35#define SPITFIRE_HIGHEST_LOCKED_TLBENT (64 - 1)
36#define CHEETAH_HIGHEST_LOCKED_TLBENT (16 - 1)
37
38#define L1DCACHE_SIZE 0x4000
39
40#define SUN4V_CHIP_INVALID 0x00
41#define SUN4V_CHIP_NIAGARA1 0x01
42#define SUN4V_CHIP_NIAGARA2 0x02
43#define SUN4V_CHIP_UNKNOWN 0xff
44
45#ifndef __ASSEMBLY__
46
47enum ultra_tlb_layout {
48 spitfire = 0,
49 cheetah = 1,
50 cheetah_plus = 2,
51 hypervisor = 3,
52};
53
54extern enum ultra_tlb_layout tlb_type;
55
56extern int sun4v_chip_type;
57
58extern int cheetah_pcache_forced_on;
59extern void cheetah_enable_pcache(void);
60
61#define sparc64_highest_locked_tlbent() \
62 (tlb_type == spitfire ? \
63 SPITFIRE_HIGHEST_LOCKED_TLBENT : \
64 CHEETAH_HIGHEST_LOCKED_TLBENT)
65
66extern int num_kernel_image_mappings;
67
68/* The data cache is write through, so this just invalidates the
69 * specified line.
70 */
71static inline void spitfire_put_dcache_tag(unsigned long addr, unsigned long tag)
72{
73 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
74 "membar #Sync"
75 : /* No outputs */
76 : "r" (tag), "r" (addr), "i" (ASI_DCACHE_TAG));
77}
78
79/* The instruction cache lines are flushed with this, but note that
80 * this does not flush the pipeline. It is possible for a line to
81 * get flushed but stale instructions to still be in the pipeline,
82 * a flush instruction (to any address) is sufficient to handle
83 * this issue after the line is invalidated.
84 */
85static inline void spitfire_put_icache_tag(unsigned long addr, unsigned long tag)
86{
87 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
88 "membar #Sync"
89 : /* No outputs */
90 : "r" (tag), "r" (addr), "i" (ASI_IC_TAG));
91}
92
93static inline unsigned long spitfire_get_dtlb_data(int entry)
94{
95 unsigned long data;
96
97 __asm__ __volatile__("ldxa [%1] %2, %0"
98 : "=r" (data)
99 : "r" (entry << 3), "i" (ASI_DTLB_DATA_ACCESS));
100
101 /* Clear TTE diag bits. */
102 data &= ~0x0003fe0000000000UL;
103
104 return data;
105}
106
107static inline unsigned long spitfire_get_dtlb_tag(int entry)
108{
109 unsigned long tag;
110
111 __asm__ __volatile__("ldxa [%1] %2, %0"
112 : "=r" (tag)
113 : "r" (entry << 3), "i" (ASI_DTLB_TAG_READ));
114 return tag;
115}
116
117static inline void spitfire_put_dtlb_data(int entry, unsigned long data)
118{
119 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
120 "membar #Sync"
121 : /* No outputs */
122 : "r" (data), "r" (entry << 3),
123 "i" (ASI_DTLB_DATA_ACCESS));
124}
125
126static inline unsigned long spitfire_get_itlb_data(int entry)
127{
128 unsigned long data;
129
130 __asm__ __volatile__("ldxa [%1] %2, %0"
131 : "=r" (data)
132 : "r" (entry << 3), "i" (ASI_ITLB_DATA_ACCESS));
133
134 /* Clear TTE diag bits. */
135 data &= ~0x0003fe0000000000UL;
136
137 return data;
138}
139
140static inline unsigned long spitfire_get_itlb_tag(int entry)
141{
142 unsigned long tag;
143
144 __asm__ __volatile__("ldxa [%1] %2, %0"
145 : "=r" (tag)
146 : "r" (entry << 3), "i" (ASI_ITLB_TAG_READ));
147 return tag;
148}
149
150static inline void spitfire_put_itlb_data(int entry, unsigned long data)
151{
152 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
153 "membar #Sync"
154 : /* No outputs */
155 : "r" (data), "r" (entry << 3),
156 "i" (ASI_ITLB_DATA_ACCESS));
157}
158
159static inline void spitfire_flush_dtlb_nucleus_page(unsigned long page)
160{
161 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
162 "membar #Sync"
163 : /* No outputs */
164 : "r" (page | 0x20), "i" (ASI_DMMU_DEMAP));
165}
166
167static inline void spitfire_flush_itlb_nucleus_page(unsigned long page)
168{
169 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
170 "membar #Sync"
171 : /* No outputs */
172 : "r" (page | 0x20), "i" (ASI_IMMU_DEMAP));
173}
174
175/* Cheetah has "all non-locked" tlb flushes. */
176static inline void cheetah_flush_dtlb_all(void)
177{
178 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
179 "membar #Sync"
180 : /* No outputs */
181 : "r" (0x80), "i" (ASI_DMMU_DEMAP));
182}
183
184static inline void cheetah_flush_itlb_all(void)
185{
186 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
187 "membar #Sync"
188 : /* No outputs */
189 : "r" (0x80), "i" (ASI_IMMU_DEMAP));
190}
191
192/* Cheetah has a 4-tlb layout so direct access is a bit different.
193 * The first two TLBs are fully assosciative, hold 16 entries, and are
194 * used only for locked and >8K sized translations. One exists for
195 * data accesses and one for instruction accesses.
196 *
197 * The third TLB is for data accesses to 8K non-locked translations, is
198 * 2 way assosciative, and holds 512 entries. The fourth TLB is for
199 * instruction accesses to 8K non-locked translations, is 2 way
200 * assosciative, and holds 128 entries.
201 *
202 * Cheetah has some bug where bogus data can be returned from
203 * ASI_{D,I}TLB_DATA_ACCESS loads, doing the load twice fixes
204 * the problem for me. -DaveM
205 */
206static inline unsigned long cheetah_get_ldtlb_data(int entry)
207{
208 unsigned long data;
209
210 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
211 "ldxa [%1] %2, %0"
212 : "=r" (data)
213 : "r" ((0 << 16) | (entry << 3)),
214 "i" (ASI_DTLB_DATA_ACCESS));
215
216 return data;
217}
218
219static inline unsigned long cheetah_get_litlb_data(int entry)
220{
221 unsigned long data;
222
223 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
224 "ldxa [%1] %2, %0"
225 : "=r" (data)
226 : "r" ((0 << 16) | (entry << 3)),
227 "i" (ASI_ITLB_DATA_ACCESS));
228
229 return data;
230}
231
232static inline unsigned long cheetah_get_ldtlb_tag(int entry)
233{
234 unsigned long tag;
235
236 __asm__ __volatile__("ldxa [%1] %2, %0"
237 : "=r" (tag)
238 : "r" ((0 << 16) | (entry << 3)),
239 "i" (ASI_DTLB_TAG_READ));
240
241 return tag;
242}
243
244static inline unsigned long cheetah_get_litlb_tag(int entry)
245{
246 unsigned long tag;
247
248 __asm__ __volatile__("ldxa [%1] %2, %0"
249 : "=r" (tag)
250 : "r" ((0 << 16) | (entry << 3)),
251 "i" (ASI_ITLB_TAG_READ));
252
253 return tag;
254}
255
256static inline void cheetah_put_ldtlb_data(int entry, unsigned long data)
257{
258 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
259 "membar #Sync"
260 : /* No outputs */
261 : "r" (data),
262 "r" ((0 << 16) | (entry << 3)),
263 "i" (ASI_DTLB_DATA_ACCESS));
264}
265
266static inline void cheetah_put_litlb_data(int entry, unsigned long data)
267{
268 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
269 "membar #Sync"
270 : /* No outputs */
271 : "r" (data),
272 "r" ((0 << 16) | (entry << 3)),
273 "i" (ASI_ITLB_DATA_ACCESS));
274}
275
276static inline unsigned long cheetah_get_dtlb_data(int entry, int tlb)
277{
278 unsigned long data;
279
280 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
281 "ldxa [%1] %2, %0"
282 : "=r" (data)
283 : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_DATA_ACCESS));
284
285 return data;
286}
287
288static inline unsigned long cheetah_get_dtlb_tag(int entry, int tlb)
289{
290 unsigned long tag;
291
292 __asm__ __volatile__("ldxa [%1] %2, %0"
293 : "=r" (tag)
294 : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_TAG_READ));
295 return tag;
296}
297
298static inline void cheetah_put_dtlb_data(int entry, unsigned long data, int tlb)
299{
300 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
301 "membar #Sync"
302 : /* No outputs */
303 : "r" (data),
304 "r" ((tlb << 16) | (entry << 3)),
305 "i" (ASI_DTLB_DATA_ACCESS));
306}
307
308static inline unsigned long cheetah_get_itlb_data(int entry)
309{
310 unsigned long data;
311
312 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
313 "ldxa [%1] %2, %0"
314 : "=r" (data)
315 : "r" ((2 << 16) | (entry << 3)),
316 "i" (ASI_ITLB_DATA_ACCESS));
317
318 return data;
319}
320
321static inline unsigned long cheetah_get_itlb_tag(int entry)
322{
323 unsigned long tag;
324
325 __asm__ __volatile__("ldxa [%1] %2, %0"
326 : "=r" (tag)
327 : "r" ((2 << 16) | (entry << 3)), "i" (ASI_ITLB_TAG_READ));
328 return tag;
329}
330
331static inline void cheetah_put_itlb_data(int entry, unsigned long data)
332{
333 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
334 "membar #Sync"
335 : /* No outputs */
336 : "r" (data), "r" ((2 << 16) | (entry << 3)),
337 "i" (ASI_ITLB_DATA_ACCESS));
338}
339
340#endif /* !(__ASSEMBLY__) */
341
342#endif /* !(_SPARC64_SPITFIRE_H) */
diff --git a/include/asm-sparc64/sstate.h b/include/asm-sparc64/sstate.h
index a7c35dbcb281..97720ce2fd43 100644
--- a/include/asm-sparc64/sstate.h
+++ b/include/asm-sparc64/sstate.h
@@ -1,13 +1 @@
1#ifndef _SPARC64_SSTATE_H #include <asm-sparc/sstate.h>
2#define _SPARC64_SSTATE_H
3
4extern void sstate_booting(void);
5extern void sstate_running(void);
6extern void sstate_halt(void);
7extern void sstate_poweroff(void);
8extern void sstate_panic(void);
9extern void sstate_reboot(void);
10
11extern void sun4v_sstate_init(void);
12
13#endif /* _SPARC64_SSTATE_H */
diff --git a/include/asm-sparc64/stacktrace.h b/include/asm-sparc64/stacktrace.h
index 6cee39adf6d6..adc9b92c0ef1 100644
--- a/include/asm-sparc64/stacktrace.h
+++ b/include/asm-sparc64/stacktrace.h
@@ -1,6 +1 @@
1#ifndef _SPARC64_STACKTRACE_H #include <asm-sparc/stacktrace.h>
2#define _SPARC64_STACKTRACE_H
3
4extern void stack_trace_flush(void);
5
6#endif /* _SPARC64_STACKTRACE_H */
diff --git a/include/asm-sparc64/starfire.h b/include/asm-sparc64/starfire.h
index 07bafd31e33c..db97daa3bed4 100644
--- a/include/asm-sparc64/starfire.h
+++ b/include/asm-sparc64/starfire.h
@@ -1,21 +1 @@
1/* #include <asm-sparc/starfire.h>
2 * starfire.h: Group all starfire specific code together.
3 *
4 * Copyright (C) 2000 Anton Blanchard (anton@samba.org)
5 */
6
7#ifndef _SPARC64_STARFIRE_H
8#define _SPARC64_STARFIRE_H
9
10#ifndef __ASSEMBLY__
11
12extern int this_is_starfire;
13
14extern void check_if_starfire(void);
15extern void starfire_cpu_setup(void);
16extern int starfire_hard_smp_processor_id(void);
17extern void starfire_hookup(int);
18extern unsigned int starfire_translate(unsigned long imap, unsigned int upaid);
19
20#endif
21#endif
diff --git a/include/asm-sparc64/stat.h b/include/asm-sparc64/stat.h
index 9650fdea847f..b108a866256b 100644
--- a/include/asm-sparc64/stat.h
+++ b/include/asm-sparc64/stat.h
@@ -1,47 +1 @@
1#ifndef _SPARC64_STAT_H #include <asm-sparc/stat.h>
2#define _SPARC64_STAT_H
3
4#include <linux/types.h>
5
6struct stat {
7 unsigned st_dev;
8 ino_t st_ino;
9 mode_t st_mode;
10 short st_nlink;
11 uid_t st_uid;
12 gid_t st_gid;
13 unsigned st_rdev;
14 off_t st_size;
15 time_t st_atime;
16 time_t st_mtime;
17 time_t st_ctime;
18 off_t st_blksize;
19 off_t st_blocks;
20 unsigned long __unused4[2];
21};
22
23struct stat64 {
24 unsigned long st_dev;
25 unsigned long st_ino;
26 unsigned long st_nlink;
27
28 unsigned int st_mode;
29 unsigned int st_uid;
30 unsigned int st_gid;
31 unsigned int __pad0;
32
33 unsigned long st_rdev;
34 long st_size;
35 long st_blksize;
36 long st_blocks;
37
38 unsigned long st_atime;
39 unsigned long st_atime_nsec;
40 unsigned long st_mtime;
41 unsigned long st_mtime_nsec;
42 unsigned long st_ctime;
43 unsigned long st_ctime_nsec;
44 long __unused[3];
45};
46
47#endif
diff --git a/include/asm-sparc64/statfs.h b/include/asm-sparc64/statfs.h
index 79b3c890a5fa..5503d6a4c67e 100644
--- a/include/asm-sparc64/statfs.h
+++ b/include/asm-sparc64/statfs.h
@@ -1,54 +1 @@
1#ifndef _SPARC64_STATFS_H #include <asm-sparc/statfs.h>
2#define _SPARC64_STATFS_H
3
4#ifndef __KERNEL_STRICT_NAMES
5
6#include <linux/types.h>
7
8typedef __kernel_fsid_t fsid_t;
9
10#endif
11
12struct statfs {
13 long f_type;
14 long f_bsize;
15 long f_blocks;
16 long f_bfree;
17 long f_bavail;
18 long f_files;
19 long f_ffree;
20 __kernel_fsid_t f_fsid;
21 long f_namelen;
22 long f_frsize;
23 long f_spare[5];
24};
25
26struct statfs64 {
27 long f_type;
28 long f_bsize;
29 long f_blocks;
30 long f_bfree;
31 long f_bavail;
32 long f_files;
33 long f_ffree;
34 __kernel_fsid_t f_fsid;
35 long f_namelen;
36 long f_frsize;
37 long f_spare[5];
38};
39
40struct compat_statfs64 {
41 __u32 f_type;
42 __u32 f_bsize;
43 __u64 f_blocks;
44 __u64 f_bfree;
45 __u64 f_bavail;
46 __u64 f_files;
47 __u64 f_ffree;
48 __kernel_fsid_t f_fsid;
49 __u32 f_namelen;
50 __u32 f_frsize;
51 __u32 f_spare[5];
52};
53
54#endif
diff --git a/include/asm-sparc64/string.h b/include/asm-sparc64/string.h
index 43161f2d17eb..5018cd8b6ad0 100644
--- a/include/asm-sparc64/string.h
+++ b/include/asm-sparc64/string.h
@@ -1,83 +1 @@
1/* #include <asm-sparc/string.h>
2 * string.h: External definitions for optimized assembly string
3 * routines for the Linux Kernel.
4 *
5 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996,1997,1999 Jakub Jelinek (jakub@redhat.com)
7 */
8
9#ifndef __SPARC64_STRING_H__
10#define __SPARC64_STRING_H__
11
12/* Really, userland/ksyms should not see any of this stuff. */
13
14#ifdef __KERNEL__
15
16#include <asm/asi.h>
17
18extern void *__memset(void *,int,__kernel_size_t);
19
20#ifndef EXPORT_SYMTAB_STROPS
21
22/* First the mem*() things. */
23#define __HAVE_ARCH_MEMMOVE
24extern void *memmove(void *, const void *, __kernel_size_t);
25
26#define __HAVE_ARCH_MEMCPY
27extern void *memcpy(void *, const void *, __kernel_size_t);
28
29#define __HAVE_ARCH_MEMSET
30extern void *__builtin_memset(void *,int,__kernel_size_t);
31
32static inline void *__constant_memset(void *s, int c, __kernel_size_t count)
33{
34 extern __kernel_size_t __bzero(void *, __kernel_size_t);
35
36 if (!c) {
37 __bzero(s, count);
38 return s;
39 } else
40 return __memset(s, c, count);
41}
42
43#undef memset
44#define memset(s, c, count) \
45((__builtin_constant_p(count) && (count) <= 32) ? \
46 __builtin_memset((s), (c), (count)) : \
47 (__builtin_constant_p(c) ? \
48 __constant_memset((s), (c), (count)) : \
49 __memset((s), (c), (count))))
50
51#define __HAVE_ARCH_MEMSCAN
52
53#undef memscan
54#define memscan(__arg0, __char, __arg2) \
55({ \
56 extern void *__memscan_zero(void *, size_t); \
57 extern void *__memscan_generic(void *, int, size_t); \
58 void *__retval, *__addr = (__arg0); \
59 size_t __size = (__arg2); \
60 \
61 if(__builtin_constant_p(__char) && !(__char)) \
62 __retval = __memscan_zero(__addr, __size); \
63 else \
64 __retval = __memscan_generic(__addr, (__char), __size); \
65 \
66 __retval; \
67})
68
69#define __HAVE_ARCH_MEMCMP
70extern int memcmp(const void *,const void *,__kernel_size_t);
71
72/* Now the str*() stuff... */
73#define __HAVE_ARCH_STRLEN
74extern __kernel_size_t strlen(const char *);
75
76#define __HAVE_ARCH_STRNCMP
77extern int strncmp(const char *, const char *, __kernel_size_t);
78
79#endif /* !EXPORT_SYMTAB_STROPS */
80
81#endif /* __KERNEL__ */
82
83#endif /* !(__SPARC64_STRING_H__) */
diff --git a/include/asm-sparc64/sunbpp.h b/include/asm-sparc64/sunbpp.h
index 8e171b7a9f4f..9632be290eb5 100644
--- a/include/asm-sparc64/sunbpp.h
+++ b/include/asm-sparc64/sunbpp.h
@@ -1,80 +1 @@
1/* #include <asm-sparc/sunbpp.h>
2 * include/asm-sparc64/sunbpp.h
3 */
4
5#ifndef _ASM_SPARC64_SUNBPP_H
6#define _ASM_SPARC64_SUNBPP_H
7
8struct bpp_regs {
9 /* DMA registers */
10 __volatile__ __u32 p_csr; /* DMA Control/Status Register */
11 __volatile__ __u32 p_addr; /* Address Register */
12 __volatile__ __u32 p_bcnt; /* Byte Count Register */
13 __volatile__ __u32 p_tst_csr; /* Test Control/Status (DMA2 only) */
14 /* Parallel Port registers */
15 __volatile__ __u16 p_hcr; /* Hardware Configuration Register */
16 __volatile__ __u16 p_ocr; /* Operation Configuration Register */
17 __volatile__ __u8 p_dr; /* Parallel Data Register */
18 __volatile__ __u8 p_tcr; /* Transfer Control Register */
19 __volatile__ __u8 p_or; /* Output Register */
20 __volatile__ __u8 p_ir; /* Input Register */
21 __volatile__ __u16 p_icr; /* Interrupt Control Register */
22};
23
24/* P_HCR. Time is in increments of SBus clock. */
25#define P_HCR_TEST 0x8000 /* Allows buried counters to be read */
26#define P_HCR_DSW 0x7f00 /* Data strobe width (in ticks) */
27#define P_HCR_DDS 0x007f /* Data setup before strobe (in ticks) */
28
29/* P_OCR. */
30#define P_OCR_MEM_CLR 0x8000
31#define P_OCR_DATA_SRC 0x4000 /* ) */
32#define P_OCR_DS_DSEL 0x2000 /* ) Bidirectional */
33#define P_OCR_BUSY_DSEL 0x1000 /* ) selects */
34#define P_OCR_ACK_DSEL 0x0800 /* ) */
35#define P_OCR_EN_DIAG 0x0400
36#define P_OCR_BUSY_OP 0x0200 /* Busy operation */
37#define P_OCR_ACK_OP 0x0100 /* Ack operation */
38#define P_OCR_SRST 0x0080 /* Reset state machines. Not selfcleaning. */
39#define P_OCR_IDLE 0x0008 /* PP data transfer state machine is idle */
40#define P_OCR_V_ILCK 0x0002 /* Versatec faded. Zebra only. */
41#define P_OCR_EN_VER 0x0001 /* Enable Versatec (0 - enable). Zebra only. */
42
43/* P_TCR */
44#define P_TCR_DIR 0x08
45#define P_TCR_BUSY 0x04
46#define P_TCR_ACK 0x02
47#define P_TCR_DS 0x01 /* Strobe */
48
49/* P_OR */
50#define P_OR_V3 0x20 /* ) */
51#define P_OR_V2 0x10 /* ) on Zebra only */
52#define P_OR_V1 0x08 /* ) */
53#define P_OR_INIT 0x04
54#define P_OR_AFXN 0x02 /* Auto Feed */
55#define P_OR_SLCT_IN 0x01
56
57/* P_IR */
58#define P_IR_PE 0x04
59#define P_IR_SLCT 0x02
60#define P_IR_ERR 0x01
61
62/* P_ICR */
63#define P_DS_IRQ 0x8000 /* RW1 */
64#define P_ACK_IRQ 0x4000 /* RW1 */
65#define P_BUSY_IRQ 0x2000 /* RW1 */
66#define P_PE_IRQ 0x1000 /* RW1 */
67#define P_SLCT_IRQ 0x0800 /* RW1 */
68#define P_ERR_IRQ 0x0400 /* RW1 */
69#define P_DS_IRQ_EN 0x0200 /* RW Always on rising edge */
70#define P_ACK_IRQ_EN 0x0100 /* RW Always on rising edge */
71#define P_BUSY_IRP 0x0080 /* RW 1= rising edge */
72#define P_BUSY_IRQ_EN 0x0040 /* RW */
73#define P_PE_IRP 0x0020 /* RW 1= rising edge */
74#define P_PE_IRQ_EN 0x0010 /* RW */
75#define P_SLCT_IRP 0x0008 /* RW 1= rising edge */
76#define P_SLCT_IRQ_EN 0x0004 /* RW */
77#define P_ERR_IRP 0x0002 /* RW1 1= rising edge */
78#define P_ERR_IRQ_EN 0x0001 /* RW */
79
80#endif /* !(_ASM_SPARC64_SUNBPP_H) */
diff --git a/include/asm-sparc64/syscalls.h b/include/asm-sparc64/syscalls.h
index 45a43f637a14..3477b16e30ca 100644
--- a/include/asm-sparc64/syscalls.h
+++ b/include/asm-sparc64/syscalls.h
@@ -1,13 +1 @@
1#ifndef _SPARC64_SYSCALLS_H #include <asm-sparc/syscalls.h>
2#define _SPARC64_SYSCALLS_H
3
4struct pt_regs;
5
6extern asmlinkage long sparc_do_fork(unsigned long clone_flags,
7 unsigned long stack_start,
8 struct pt_regs *regs,
9 unsigned long stack_size);
10
11extern asmlinkage int sparc_execve(struct pt_regs *regs);
12
13#endif /* _SPARC64_SYSCALLS_H */
diff --git a/include/asm-sparc64/system.h b/include/asm-sparc64/system.h
index 6897ac31be41..be2603c2e527 100644
--- a/include/asm-sparc64/system.h
+++ b/include/asm-sparc64/system.h
@@ -1,355 +1 @@
1#ifndef __SPARC64_SYSTEM_H #include <asm-sparc/system.h>
2#define __SPARC64_SYSTEM_H
3
4#include <asm/ptrace.h>
5#include <asm/processor.h>
6#include <asm/visasm.h>
7
8#ifndef __ASSEMBLY__
9
10#include <linux/irqflags.h>
11#include <asm-generic/cmpxchg-local.h>
12
13/*
14 * Sparc (general) CPU types
15 */
16enum sparc_cpu {
17 sun4 = 0x00,
18 sun4c = 0x01,
19 sun4m = 0x02,
20 sun4d = 0x03,
21 sun4e = 0x04,
22 sun4u = 0x05, /* V8 ploos ploos */
23 sun_unknown = 0x06,
24 ap1000 = 0x07, /* almost a sun4m */
25};
26
27#define sparc_cpu_model sun4u
28
29/* This cannot ever be a sun4c nor sun4 :) That's just history. */
30#define ARCH_SUN4C_SUN4 0
31#define ARCH_SUN4 0
32
33extern char reboot_command[];
34
35/* These are here in an effort to more fully work around Spitfire Errata
36 * #51. Essentially, if a memory barrier occurs soon after a mispredicted
37 * branch, the chip can stop executing instructions until a trap occurs.
38 * Therefore, if interrupts are disabled, the chip can hang forever.
39 *
40 * It used to be believed that the memory barrier had to be right in the
41 * delay slot, but a case has been traced recently wherein the memory barrier
42 * was one instruction after the branch delay slot and the chip still hung.
43 * The offending sequence was the following in sym_wakeup_done() of the
44 * sym53c8xx_2 driver:
45 *
46 * call sym_ccb_from_dsa, 0
47 * movge %icc, 0, %l0
48 * brz,pn %o0, .LL1303
49 * mov %o0, %l2
50 * membar #LoadLoad
51 *
52 * The branch has to be mispredicted for the bug to occur. Therefore, we put
53 * the memory barrier explicitly into a "branch always, predicted taken"
54 * delay slot to avoid the problem case.
55 */
56#define membar_safe(type) \
57do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
58 " membar " type "\n" \
59 "1:\n" \
60 : : : "memory"); \
61} while (0)
62
63#define mb() \
64 membar_safe("#LoadLoad | #LoadStore | #StoreStore | #StoreLoad")
65#define rmb() \
66 membar_safe("#LoadLoad")
67#define wmb() \
68 membar_safe("#StoreStore")
69#define membar_storeload() \
70 membar_safe("#StoreLoad")
71#define membar_storeload_storestore() \
72 membar_safe("#StoreLoad | #StoreStore")
73#define membar_storeload_loadload() \
74 membar_safe("#StoreLoad | #LoadLoad")
75#define membar_storestore_loadstore() \
76 membar_safe("#StoreStore | #LoadStore")
77
78#endif
79
80#define nop() __asm__ __volatile__ ("nop")
81
82#define read_barrier_depends() do { } while(0)
83#define set_mb(__var, __value) \
84 do { __var = __value; membar_storeload_storestore(); } while(0)
85
86#ifdef CONFIG_SMP
87#define smp_mb() mb()
88#define smp_rmb() rmb()
89#define smp_wmb() wmb()
90#define smp_read_barrier_depends() read_barrier_depends()
91#else
92#define smp_mb() __asm__ __volatile__("":::"memory")
93#define smp_rmb() __asm__ __volatile__("":::"memory")
94#define smp_wmb() __asm__ __volatile__("":::"memory")
95#define smp_read_barrier_depends() do { } while(0)
96#endif
97
98#define flushi(addr) __asm__ __volatile__ ("flush %0" : : "r" (addr) : "memory")
99
100#define flushw_all() __asm__ __volatile__("flushw")
101
102/* Performance counter register access. */
103#define read_pcr(__p) __asm__ __volatile__("rd %%pcr, %0" : "=r" (__p))
104#define write_pcr(__p) __asm__ __volatile__("wr %0, 0x0, %%pcr" : : "r" (__p))
105#define read_pic(__p) __asm__ __volatile__("rd %%pic, %0" : "=r" (__p))
106
107/* Blackbird errata workaround. See commentary in
108 * arch/sparc64/kernel/smp.c:smp_percpu_timer_interrupt()
109 * for more information.
110 */
111#define reset_pic() \
112 __asm__ __volatile__("ba,pt %xcc, 99f\n\t" \
113 ".align 64\n" \
114 "99:wr %g0, 0x0, %pic\n\t" \
115 "rd %pic, %g0")
116
117#ifndef __ASSEMBLY__
118
119extern void sun_do_break(void);
120extern int stop_a_enabled;
121
122extern void fault_in_user_windows(void);
123extern void synchronize_user_stack(void);
124
125extern void __flushw_user(void);
126#define flushw_user() __flushw_user()
127
128#define flush_user_windows flushw_user
129#define flush_register_windows flushw_all
130
131/* Don't hold the runqueue lock over context switch */
132#define __ARCH_WANT_UNLOCKED_CTXSW
133#define prepare_arch_switch(next) \
134do { \
135 flushw_all(); \
136} while (0)
137
138 /* See what happens when you design the chip correctly?
139 *
140 * We tell gcc we clobber all non-fixed-usage registers except
141 * for l0/l1. It will use one for 'next' and the other to hold
142 * the output value of 'last'. 'next' is not referenced again
143 * past the invocation of switch_to in the scheduler, so we need
144 * not preserve it's value. Hairy, but it lets us remove 2 loads
145 * and 2 stores in this critical code path. -DaveM
146 */
147#define switch_to(prev, next, last) \
148do { if (test_thread_flag(TIF_PERFCTR)) { \
149 unsigned long __tmp; \
150 read_pcr(__tmp); \
151 current_thread_info()->pcr_reg = __tmp; \
152 read_pic(__tmp); \
153 current_thread_info()->kernel_cntd0 += (unsigned int)(__tmp);\
154 current_thread_info()->kernel_cntd1 += ((__tmp) >> 32); \
155 } \
156 flush_tlb_pending(); \
157 save_and_clear_fpu(); \
158 /* If you are tempted to conditionalize the following */ \
159 /* so that ASI is only written if it changes, think again. */ \
160 __asm__ __volatile__("wr %%g0, %0, %%asi" \
161 : : "r" (__thread_flag_byte_ptr(task_thread_info(next))[TI_FLAG_BYTE_CURRENT_DS]));\
162 trap_block[current_thread_info()->cpu].thread = \
163 task_thread_info(next); \
164 __asm__ __volatile__( \
165 "mov %%g4, %%g7\n\t" \
166 "stx %%i6, [%%sp + 2047 + 0x70]\n\t" \
167 "stx %%i7, [%%sp + 2047 + 0x78]\n\t" \
168 "rdpr %%wstate, %%o5\n\t" \
169 "stx %%o6, [%%g6 + %6]\n\t" \
170 "stb %%o5, [%%g6 + %5]\n\t" \
171 "rdpr %%cwp, %%o5\n\t" \
172 "stb %%o5, [%%g6 + %8]\n\t" \
173 "mov %4, %%g6\n\t" \
174 "ldub [%4 + %8], %%g1\n\t" \
175 "wrpr %%g1, %%cwp\n\t" \
176 "ldx [%%g6 + %6], %%o6\n\t" \
177 "ldub [%%g6 + %5], %%o5\n\t" \
178 "ldub [%%g6 + %7], %%o7\n\t" \
179 "wrpr %%o5, 0x0, %%wstate\n\t" \
180 "ldx [%%sp + 2047 + 0x70], %%i6\n\t" \
181 "ldx [%%sp + 2047 + 0x78], %%i7\n\t" \
182 "ldx [%%g6 + %9], %%g4\n\t" \
183 "brz,pt %%o7, switch_to_pc\n\t" \
184 " mov %%g7, %0\n\t" \
185 "sethi %%hi(ret_from_syscall), %%g1\n\t" \
186 "jmpl %%g1 + %%lo(ret_from_syscall), %%g0\n\t" \
187 " nop\n\t" \
188 ".globl switch_to_pc\n\t" \
189 "switch_to_pc:\n\t" \
190 : "=&r" (last), "=r" (current), "=r" (current_thread_info_reg), \
191 "=r" (__local_per_cpu_offset) \
192 : "0" (task_thread_info(next)), \
193 "i" (TI_WSTATE), "i" (TI_KSP), "i" (TI_NEW_CHILD), \
194 "i" (TI_CWP), "i" (TI_TASK) \
195 : "cc", \
196 "g1", "g2", "g3", "g7", \
197 "l1", "l2", "l3", "l4", "l5", "l6", "l7", \
198 "i0", "i1", "i2", "i3", "i4", "i5", \
199 "o0", "o1", "o2", "o3", "o4", "o5", "o7"); \
200 /* If you fuck with this, update ret_from_syscall code too. */ \
201 if (test_thread_flag(TIF_PERFCTR)) { \
202 write_pcr(current_thread_info()->pcr_reg); \
203 reset_pic(); \
204 } \
205} while(0)
206
207static inline unsigned long xchg32(__volatile__ unsigned int *m, unsigned int val)
208{
209 unsigned long tmp1, tmp2;
210
211 __asm__ __volatile__(
212" membar #StoreLoad | #LoadLoad\n"
213" mov %0, %1\n"
214"1: lduw [%4], %2\n"
215" cas [%4], %2, %0\n"
216" cmp %2, %0\n"
217" bne,a,pn %%icc, 1b\n"
218" mov %1, %0\n"
219" membar #StoreLoad | #StoreStore\n"
220 : "=&r" (val), "=&r" (tmp1), "=&r" (tmp2)
221 : "0" (val), "r" (m)
222 : "cc", "memory");
223 return val;
224}
225
226static inline unsigned long xchg64(__volatile__ unsigned long *m, unsigned long val)
227{
228 unsigned long tmp1, tmp2;
229
230 __asm__ __volatile__(
231" membar #StoreLoad | #LoadLoad\n"
232" mov %0, %1\n"
233"1: ldx [%4], %2\n"
234" casx [%4], %2, %0\n"
235" cmp %2, %0\n"
236" bne,a,pn %%xcc, 1b\n"
237" mov %1, %0\n"
238" membar #StoreLoad | #StoreStore\n"
239 : "=&r" (val), "=&r" (tmp1), "=&r" (tmp2)
240 : "0" (val), "r" (m)
241 : "cc", "memory");
242 return val;
243}
244
245#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
246
247extern void __xchg_called_with_bad_pointer(void);
248
249static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr,
250 int size)
251{
252 switch (size) {
253 case 4:
254 return xchg32(ptr, x);
255 case 8:
256 return xchg64(ptr, x);
257 };
258 __xchg_called_with_bad_pointer();
259 return x;
260}
261
262extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noreturn));
263
264/*
265 * Atomic compare and exchange. Compare OLD with MEM, if identical,
266 * store NEW in MEM. Return the initial value in MEM. Success is
267 * indicated by comparing RETURN with OLD.
268 */
269
270#define __HAVE_ARCH_CMPXCHG 1
271
272static inline unsigned long
273__cmpxchg_u32(volatile int *m, int old, int new)
274{
275 __asm__ __volatile__("membar #StoreLoad | #LoadLoad\n"
276 "cas [%2], %3, %0\n\t"
277 "membar #StoreLoad | #StoreStore"
278 : "=&r" (new)
279 : "0" (new), "r" (m), "r" (old)
280 : "memory");
281
282 return new;
283}
284
285static inline unsigned long
286__cmpxchg_u64(volatile long *m, unsigned long old, unsigned long new)
287{
288 __asm__ __volatile__("membar #StoreLoad | #LoadLoad\n"
289 "casx [%2], %3, %0\n\t"
290 "membar #StoreLoad | #StoreStore"
291 : "=&r" (new)
292 : "0" (new), "r" (m), "r" (old)
293 : "memory");
294
295 return new;
296}
297
298/* This function doesn't exist, so you'll get a linker error
299 if something tries to do an invalid cmpxchg(). */
300extern void __cmpxchg_called_with_bad_pointer(void);
301
302static inline unsigned long
303__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
304{
305 switch (size) {
306 case 4:
307 return __cmpxchg_u32(ptr, old, new);
308 case 8:
309 return __cmpxchg_u64(ptr, old, new);
310 }
311 __cmpxchg_called_with_bad_pointer();
312 return old;
313}
314
315#define cmpxchg(ptr,o,n) \
316 ({ \
317 __typeof__(*(ptr)) _o_ = (o); \
318 __typeof__(*(ptr)) _n_ = (n); \
319 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
320 (unsigned long)_n_, sizeof(*(ptr))); \
321 })
322
323/*
324 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
325 * them available.
326 */
327
328static inline unsigned long __cmpxchg_local(volatile void *ptr,
329 unsigned long old,
330 unsigned long new, int size)
331{
332 switch (size) {
333 case 4:
334 case 8: return __cmpxchg(ptr, old, new, size);
335 default:
336 return __cmpxchg_local_generic(ptr, old, new, size);
337 }
338
339 return old;
340}
341
342#define cmpxchg_local(ptr, o, n) \
343 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
344 (unsigned long)(n), sizeof(*(ptr))))
345#define cmpxchg64_local(ptr, o, n) \
346 ({ \
347 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
348 cmpxchg_local((ptr), (o), (n)); \
349 })
350
351#endif /* !(__ASSEMBLY__) */
352
353#define arch_align_stack(x) (x)
354
355#endif /* !(__SPARC64_SYSTEM_H) */
diff --git a/include/asm-sparc64/termbits.h b/include/asm-sparc64/termbits.h
index ebe31c152f16..e03f97592c70 100644
--- a/include/asm-sparc64/termbits.h
+++ b/include/asm-sparc64/termbits.h
@@ -1,260 +1 @@
1#ifndef _SPARC64_TERMBITS_H #include <asm-sparc/termbits.h>
2#define _SPARC64_TERMBITS_H
3
4#include <linux/posix_types.h>
5
6typedef unsigned char cc_t;
7typedef unsigned int speed_t;
8typedef unsigned int tcflag_t;
9
10#define NCC 8
11struct termio {
12 unsigned short c_iflag; /* input mode flags */
13 unsigned short c_oflag; /* output mode flags */
14 unsigned short c_cflag; /* control mode flags */
15 unsigned short c_lflag; /* local mode flags */
16 unsigned char c_line; /* line discipline */
17 unsigned char c_cc[NCC]; /* control characters */
18};
19
20#define NCCS 17
21struct termios {
22 tcflag_t c_iflag; /* input mode flags */
23 tcflag_t c_oflag; /* output mode flags */
24 tcflag_t c_cflag; /* control mode flags */
25 tcflag_t c_lflag; /* local mode flags */
26 cc_t c_line; /* line discipline */
27 cc_t c_cc[NCCS]; /* control characters */
28#ifdef __KERNEL__
29#define SIZEOF_USER_TERMIOS sizeof (struct termios) - (2*sizeof (cc_t))
30 cc_t _x_cc[2]; /* We need them to hold vmin/vtime */
31#endif
32};
33
34struct termios2 {
35 tcflag_t c_iflag; /* input mode flags */
36 tcflag_t c_oflag; /* output mode flags */
37 tcflag_t c_cflag; /* control mode flags */
38 tcflag_t c_lflag; /* local mode flags */
39 cc_t c_line; /* line discipline */
40 cc_t c_cc[NCCS]; /* control characters */
41 cc_t _x_cc[2]; /* padding to match ktermios */
42 speed_t c_ispeed; /* input speed */
43 speed_t c_ospeed; /* output speed */
44};
45
46struct ktermios {
47 tcflag_t c_iflag; /* input mode flags */
48 tcflag_t c_oflag; /* output mode flags */
49 tcflag_t c_cflag; /* control mode flags */
50 tcflag_t c_lflag; /* local mode flags */
51 cc_t c_line; /* line discipline */
52 cc_t c_cc[NCCS]; /* control characters */
53 cc_t _x_cc[2]; /* We need them to hold vmin/vtime */
54 speed_t c_ispeed; /* input speed */
55 speed_t c_ospeed; /* output speed */
56};
57
58/* c_cc characters */
59#define VINTR 0
60#define VQUIT 1
61#define VERASE 2
62#define VKILL 3
63#define VEOF 4
64#define VEOL 5
65#define VEOL2 6
66#define VSWTC 7
67#define VSTART 8
68#define VSTOP 9
69
70
71
72#define VSUSP 10
73#define VDSUSP 11 /* SunOS POSIX nicety I do believe... */
74#define VREPRINT 12
75#define VDISCARD 13
76#define VWERASE 14
77#define VLNEXT 15
78
79/* Kernel keeps vmin/vtime separated, user apps assume vmin/vtime is
80 * shared with eof/eol
81 */
82#ifdef __KERNEL__
83#define VMIN 16
84#define VTIME 17
85#else
86#define VMIN VEOF
87#define VTIME VEOL
88#endif
89
90/* c_iflag bits */
91#define IGNBRK 0x00000001
92#define BRKINT 0x00000002
93#define IGNPAR 0x00000004
94#define PARMRK 0x00000008
95#define INPCK 0x00000010
96#define ISTRIP 0x00000020
97#define INLCR 0x00000040
98#define IGNCR 0x00000080
99#define ICRNL 0x00000100
100#define IUCLC 0x00000200
101#define IXON 0x00000400
102#define IXANY 0x00000800
103#define IXOFF 0x00001000
104#define IMAXBEL 0x00002000
105#define IUTF8 0x00004000
106
107/* c_oflag bits */
108#define OPOST 0x00000001
109#define OLCUC 0x00000002
110#define ONLCR 0x00000004
111#define OCRNL 0x00000008
112#define ONOCR 0x00000010
113#define ONLRET 0x00000020
114#define OFILL 0x00000040
115#define OFDEL 0x00000080
116#define NLDLY 0x00000100
117#define NL0 0x00000000
118#define NL1 0x00000100
119#define CRDLY 0x00000600
120#define CR0 0x00000000
121#define CR1 0x00000200
122#define CR2 0x00000400
123#define CR3 0x00000600
124#define TABDLY 0x00001800
125#define TAB0 0x00000000
126#define TAB1 0x00000800
127#define TAB2 0x00001000
128#define TAB3 0x00001800
129#define XTABS 0x00001800
130#define BSDLY 0x00002000
131#define BS0 0x00000000
132#define BS1 0x00002000
133#define VTDLY 0x00004000
134#define VT0 0x00000000
135#define VT1 0x00004000
136#define FFDLY 0x00008000
137#define FF0 0x00000000
138#define FF1 0x00008000
139#define PAGEOUT 0x00010000 /* SUNOS specific */
140#define WRAP 0x00020000 /* SUNOS specific */
141
142/* c_cflag bit meaning */
143#define CBAUD 0x0000100f
144#define B0 0x00000000 /* hang up */
145#define B50 0x00000001
146#define B75 0x00000002
147#define B110 0x00000003
148#define B134 0x00000004
149#define B150 0x00000005
150#define B200 0x00000006
151#define B300 0x00000007
152#define B600 0x00000008
153#define B1200 0x00000009
154#define B1800 0x0000000a
155#define B2400 0x0000000b
156#define B4800 0x0000000c
157#define B9600 0x0000000d
158#define B19200 0x0000000e
159#define B38400 0x0000000f
160#define EXTA B19200
161#define EXTB B38400
162#define CSIZE 0x00000030
163#define CS5 0x00000000
164#define CS6 0x00000010
165#define CS7 0x00000020
166#define CS8 0x00000030
167#define CSTOPB 0x00000040
168#define CREAD 0x00000080
169#define PARENB 0x00000100
170#define PARODD 0x00000200
171#define HUPCL 0x00000400
172#define CLOCAL 0x00000800
173#define CBAUDEX 0x00001000
174#define BOTHER 0x00001000
175#define B57600 0x00001001
176#define B115200 0x00001002
177#define B230400 0x00001003
178#define B460800 0x00001004
179/* This is what we can do with the Zilogs. */
180#define B76800 0x00001005
181/* This is what we can do with the SAB82532. */
182#define B153600 0x00001006
183#define B307200 0x00001007
184#define B614400 0x00001008
185#define B921600 0x00001009
186/* And these are the rest... */
187#define B500000 0x0000100a
188#define B576000 0x0000100b
189#define B1000000 0x0000100c
190#define B1152000 0x0000100d
191#define B1500000 0x0000100e
192#define B2000000 0x0000100f
193/* These have totally bogus values and nobody uses them
194 so far. Later on we'd have to use say 0x10000x and
195 adjust CBAUD constant and drivers accordingly.
196#define B2500000 0x00001010
197#define B3000000 0x00001011
198#define B3500000 0x00001012
199#define B4000000 0x00001013 */
200#define CIBAUD 0x100f0000 /* input baud rate (not used) */
201#define CMSPAR 0x40000000 /* mark or space (stick) parity */
202#define CRTSCTS 0x80000000 /* flow control */
203
204#define IBSHIFT 16 /* Shift from CBAUD to CIBAUD */
205
206/* c_lflag bits */
207#define ISIG 0x00000001
208#define ICANON 0x00000002
209#define XCASE 0x00000004
210#define ECHO 0x00000008
211#define ECHOE 0x00000010
212#define ECHOK 0x00000020
213#define ECHONL 0x00000040
214#define NOFLSH 0x00000080
215#define TOSTOP 0x00000100
216#define ECHOCTL 0x00000200
217#define ECHOPRT 0x00000400
218#define ECHOKE 0x00000800
219#define DEFECHO 0x00001000 /* SUNOS thing, what is it? */
220#define FLUSHO 0x00002000
221#define PENDIN 0x00004000
222#define IEXTEN 0x00008000
223
224/* modem lines */
225#define TIOCM_LE 0x001
226#define TIOCM_DTR 0x002
227#define TIOCM_RTS 0x004
228#define TIOCM_ST 0x008
229#define TIOCM_SR 0x010
230#define TIOCM_CTS 0x020
231#define TIOCM_CAR 0x040
232#define TIOCM_RNG 0x080
233#define TIOCM_DSR 0x100
234#define TIOCM_CD TIOCM_CAR
235#define TIOCM_RI TIOCM_RNG
236#define TIOCM_OUT1 0x2000
237#define TIOCM_OUT2 0x4000
238#define TIOCM_LOOP 0x8000
239
240/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
241#define TIOCSER_TEMT 0x01 /* Transmitter physically empty */
242
243
244/* tcflow() and TCXONC use these */
245#define TCOOFF 0
246#define TCOON 1
247#define TCIOFF 2
248#define TCION 3
249
250/* tcflush() and TCFLSH use these */
251#define TCIFLUSH 0
252#define TCOFLUSH 1
253#define TCIOFLUSH 2
254
255/* tcsetattr uses these */
256#define TCSANOW 0
257#define TCSADRAIN 1
258#define TCSAFLUSH 2
259
260#endif /* !(_SPARC64_TERMBITS_H) */
diff --git a/include/asm-sparc64/termios.h b/include/asm-sparc64/termios.h
index 1f5dab25dda5..940495eb05cc 100644
--- a/include/asm-sparc64/termios.h
+++ b/include/asm-sparc64/termios.h
@@ -1,186 +1 @@
1#ifndef _SPARC64_TERMIOS_H #include <asm-sparc/termios.h>
2#define _SPARC64_TERMIOS_H
3
4#include <asm/ioctls.h>
5#include <asm/termbits.h>
6
7#if defined(__KERNEL__) || defined(__DEFINE_BSD_TERMIOS)
8struct sgttyb {
9 char sg_ispeed;
10 char sg_ospeed;
11 char sg_erase;
12 char sg_kill;
13 short sg_flags;
14};
15
16struct tchars {
17 char t_intrc;
18 char t_quitc;
19 char t_startc;
20 char t_stopc;
21 char t_eofc;
22 char t_brkc;
23};
24
25struct ltchars {
26 char t_suspc;
27 char t_dsuspc;
28 char t_rprntc;
29 char t_flushc;
30 char t_werasc;
31 char t_lnextc;
32};
33#endif /* __KERNEL__ */
34
35struct winsize {
36 unsigned short ws_row;
37 unsigned short ws_col;
38 unsigned short ws_xpixel;
39 unsigned short ws_ypixel;
40};
41
42#ifdef __KERNEL__
43#include <linux/module.h>
44
45/*
46 * c_cc characters in the termio structure. Oh, how I love being
47 * backwardly compatible. Notice that character 4 and 5 are
48 * interpreted differently depending on whether ICANON is set in
49 * c_lflag. If it's set, they are used as _VEOF and _VEOL, otherwise
50 * as _VMIN and V_TIME. This is for compatibility with OSF/1 (which
51 * is compatible with sysV)...
52 */
53#define _VMIN 4
54#define _VTIME 5
55
56/* intr=^C quit=^\ erase=del kill=^U
57 eof=^D eol=\0 eol2=\0 sxtc=\0
58 start=^Q stop=^S susp=^Z dsusp=^Y
59 reprint=^R discard=^U werase=^W lnext=^V
60 vmin=\1 vtime=\0
61*/
62#define INIT_C_CC "\003\034\177\025\004\000\000\000\021\023\032\031\022\025\027\026\001"
63
64/*
65 * Translate a "termio" structure into a "termios". Ugh.
66 */
67#define user_termio_to_kernel_termios(termios, termio) \
68({ \
69 unsigned short tmp; \
70 int err; \
71 err = get_user(tmp, &(termio)->c_iflag); \
72 (termios)->c_iflag = (0xffff0000 & ((termios)->c_iflag)) | tmp; \
73 err |= get_user(tmp, &(termio)->c_oflag); \
74 (termios)->c_oflag = (0xffff0000 & ((termios)->c_oflag)) | tmp; \
75 err |= get_user(tmp, &(termio)->c_cflag); \
76 (termios)->c_cflag = (0xffff0000 & ((termios)->c_cflag)) | tmp; \
77 err |= get_user(tmp, &(termio)->c_lflag); \
78 (termios)->c_lflag = (0xffff0000 & ((termios)->c_lflag)) | tmp; \
79 err |= copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
80 err; \
81})
82
83/*
84 * Translate a "termios" structure into a "termio". Ugh.
85 *
86 * Note the "fun" _VMIN overloading.
87 */
88#define kernel_termios_to_user_termio(termio, termios) \
89({ \
90 int err; \
91 err = put_user((termios)->c_iflag, &(termio)->c_iflag); \
92 err |= put_user((termios)->c_oflag, &(termio)->c_oflag); \
93 err |= put_user((termios)->c_cflag, &(termio)->c_cflag); \
94 err |= put_user((termios)->c_lflag, &(termio)->c_lflag); \
95 err |= put_user((termios)->c_line, &(termio)->c_line); \
96 err |= copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
97 if (!((termios)->c_lflag & ICANON)) { \
98 err |= put_user((termios)->c_cc[VMIN], &(termio)->c_cc[_VMIN]); \
99 err |= put_user((termios)->c_cc[VTIME], &(termio)->c_cc[_VTIME]); \
100 } \
101 err; \
102})
103
104#define user_termios_to_kernel_termios(k, u) \
105({ \
106 int err; \
107 err = get_user((k)->c_iflag, &(u)->c_iflag); \
108 err |= get_user((k)->c_oflag, &(u)->c_oflag); \
109 err |= get_user((k)->c_cflag, &(u)->c_cflag); \
110 err |= get_user((k)->c_lflag, &(u)->c_lflag); \
111 err |= get_user((k)->c_line, &(u)->c_line); \
112 err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \
113 if((k)->c_lflag & ICANON) { \
114 err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
115 err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
116 } else { \
117 err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
118 err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
119 } \
120 err |= get_user((k)->c_ispeed, &(u)->c_ispeed); \
121 err |= get_user((k)->c_ospeed, &(u)->c_ospeed); \
122 err; \
123})
124
125#define kernel_termios_to_user_termios(u, k) \
126({ \
127 int err; \
128 err = put_user((k)->c_iflag, &(u)->c_iflag); \
129 err |= put_user((k)->c_oflag, &(u)->c_oflag); \
130 err |= put_user((k)->c_cflag, &(u)->c_cflag); \
131 err |= put_user((k)->c_lflag, &(u)->c_lflag); \
132 err |= put_user((k)->c_line, &(u)->c_line); \
133 err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \
134 if(!((k)->c_lflag & ICANON)) { \
135 err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
136 err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
137 } else { \
138 err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
139 err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
140 } \
141 err |= put_user((k)->c_ispeed, &(u)->c_ispeed); \
142 err |= put_user((k)->c_ospeed, &(u)->c_ospeed); \
143 err; \
144})
145
146#define user_termios_to_kernel_termios_1(k, u) \
147({ \
148 int err; \
149 err = get_user((k)->c_iflag, &(u)->c_iflag); \
150 err |= get_user((k)->c_oflag, &(u)->c_oflag); \
151 err |= get_user((k)->c_cflag, &(u)->c_cflag); \
152 err |= get_user((k)->c_lflag, &(u)->c_lflag); \
153 err |= get_user((k)->c_line, &(u)->c_line); \
154 err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \
155 if((k)->c_lflag & ICANON) { \
156 err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
157 err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
158 } else { \
159 err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
160 err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
161 } \
162 err; \
163})
164
165#define kernel_termios_to_user_termios_1(u, k) \
166({ \
167 int err; \
168 err = put_user((k)->c_iflag, &(u)->c_iflag); \
169 err |= put_user((k)->c_oflag, &(u)->c_oflag); \
170 err |= put_user((k)->c_cflag, &(u)->c_cflag); \
171 err |= put_user((k)->c_lflag, &(u)->c_lflag); \
172 err |= put_user((k)->c_line, &(u)->c_line); \
173 err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \
174 if(!((k)->c_lflag & ICANON)) { \
175 err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
176 err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
177 } else { \
178 err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
179 err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
180 } \
181 err; \
182})
183
184#endif /* __KERNEL__ */
185
186#endif /* _SPARC64_TERMIOS_H */
diff --git a/include/asm-sparc64/thread_info.h b/include/asm-sparc64/thread_info.h
index e5873e385306..92bed7913395 100644
--- a/include/asm-sparc64/thread_info.h
+++ b/include/asm-sparc64/thread_info.h
@@ -1,277 +1 @@
1/* thread_info.h: sparc64 low-level thread information #include <asm-sparc/thread_info.h>
2 *
3 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
4 */
5
6#ifndef _ASM_THREAD_INFO_H
7#define _ASM_THREAD_INFO_H
8
9#ifdef __KERNEL__
10
11#define NSWINS 7
12
13#define TI_FLAG_BYTE_FAULT_CODE 0
14#define TI_FLAG_FAULT_CODE_SHIFT 56
15#define TI_FLAG_BYTE_WSTATE 1
16#define TI_FLAG_WSTATE_SHIFT 48
17#define TI_FLAG_BYTE_CWP 2
18#define TI_FLAG_CWP_SHIFT 40
19#define TI_FLAG_BYTE_CURRENT_DS 3
20#define TI_FLAG_CURRENT_DS_SHIFT 32
21#define TI_FLAG_BYTE_FPDEPTH 4
22#define TI_FLAG_FPDEPTH_SHIFT 24
23#define TI_FLAG_BYTE_WSAVED 5
24#define TI_FLAG_WSAVED_SHIFT 16
25
26#include <asm/page.h>
27
28#ifndef __ASSEMBLY__
29
30#include <asm/ptrace.h>
31#include <asm/types.h>
32
33struct task_struct;
34struct exec_domain;
35
36struct thread_info {
37 /* D$ line 1 */
38 struct task_struct *task;
39 unsigned long flags;
40 __u8 fpsaved[7];
41 __u8 status;
42 unsigned long ksp;
43
44 /* D$ line 2 */
45 unsigned long fault_address;
46 struct pt_regs *kregs;
47 struct exec_domain *exec_domain;
48 int preempt_count; /* 0 => preemptable, <0 => BUG */
49 __u8 new_child;
50 __u8 syscall_noerror;
51 __u16 cpu;
52
53 unsigned long *utraps;
54
55 struct reg_window reg_window[NSWINS];
56 unsigned long rwbuf_stkptrs[NSWINS];
57
58 unsigned long gsr[7];
59 unsigned long xfsr[7];
60
61 __u64 __user *user_cntd0;
62 __u64 __user *user_cntd1;
63 __u64 kernel_cntd0, kernel_cntd1;
64 __u64 pcr_reg;
65
66 struct restart_block restart_block;
67
68 struct pt_regs *kern_una_regs;
69 unsigned int kern_una_insn;
70
71 unsigned long fpregs[0] __attribute__ ((aligned(64)));
72};
73
74#endif /* !(__ASSEMBLY__) */
75
76/* offsets into the thread_info struct for assembly code access */
77#define TI_TASK 0x00000000
78#define TI_FLAGS 0x00000008
79#define TI_FAULT_CODE (TI_FLAGS + TI_FLAG_BYTE_FAULT_CODE)
80#define TI_WSTATE (TI_FLAGS + TI_FLAG_BYTE_WSTATE)
81#define TI_CWP (TI_FLAGS + TI_FLAG_BYTE_CWP)
82#define TI_CURRENT_DS (TI_FLAGS + TI_FLAG_BYTE_CURRENT_DS)
83#define TI_FPDEPTH (TI_FLAGS + TI_FLAG_BYTE_FPDEPTH)
84#define TI_WSAVED (TI_FLAGS + TI_FLAG_BYTE_WSAVED)
85#define TI_FPSAVED 0x00000010
86#define TI_KSP 0x00000018
87#define TI_FAULT_ADDR 0x00000020
88#define TI_KREGS 0x00000028
89#define TI_EXEC_DOMAIN 0x00000030
90#define TI_PRE_COUNT 0x00000038
91#define TI_NEW_CHILD 0x0000003c
92#define TI_SYS_NOERROR 0x0000003d
93#define TI_CPU 0x0000003e
94#define TI_UTRAPS 0x00000040
95#define TI_REG_WINDOW 0x00000048
96#define TI_RWIN_SPTRS 0x000003c8
97#define TI_GSR 0x00000400
98#define TI_XFSR 0x00000438
99#define TI_USER_CNTD0 0x00000470
100#define TI_USER_CNTD1 0x00000478
101#define TI_KERN_CNTD0 0x00000480
102#define TI_KERN_CNTD1 0x00000488
103#define TI_PCR 0x00000490
104#define TI_RESTART_BLOCK 0x00000498
105#define TI_KUNA_REGS 0x000004c0
106#define TI_KUNA_INSN 0x000004c8
107#define TI_FPREGS 0x00000500
108
109/* We embed this in the uppermost byte of thread_info->flags */
110#define FAULT_CODE_WRITE 0x01 /* Write access, implies D-TLB */
111#define FAULT_CODE_DTLB 0x02 /* Miss happened in D-TLB */
112#define FAULT_CODE_ITLB 0x04 /* Miss happened in I-TLB */
113#define FAULT_CODE_WINFIXUP 0x08 /* Miss happened during spill/fill */
114#define FAULT_CODE_BLKCOMMIT 0x10 /* Use blk-commit ASI in copy_page */
115
116#if PAGE_SHIFT == 13
117#define THREAD_SIZE (2*PAGE_SIZE)
118#define THREAD_SHIFT (PAGE_SHIFT + 1)
119#else /* PAGE_SHIFT == 13 */
120#define THREAD_SIZE PAGE_SIZE
121#define THREAD_SHIFT PAGE_SHIFT
122#endif /* PAGE_SHIFT == 13 */
123
124#define PREEMPT_ACTIVE 0x4000000
125
126/*
127 * macros/functions for gaining access to the thread information structure
128 *
129 * preempt_count needs to be 1 initially, until the scheduler is functional.
130 */
131#ifndef __ASSEMBLY__
132
133#define INIT_THREAD_INFO(tsk) \
134{ \
135 .task = &tsk, \
136 .flags = ((unsigned long)ASI_P) << TI_FLAG_CURRENT_DS_SHIFT, \
137 .exec_domain = &default_exec_domain, \
138 .preempt_count = 1, \
139 .restart_block = { \
140 .fn = do_no_restart_syscall, \
141 }, \
142}
143
144#define init_thread_info (init_thread_union.thread_info)
145#define init_stack (init_thread_union.stack)
146
147/* how to get the thread information struct from C */
148register struct thread_info *current_thread_info_reg asm("g6");
149#define current_thread_info() (current_thread_info_reg)
150
151/* thread information allocation */
152#if PAGE_SHIFT == 13
153#define __THREAD_INFO_ORDER 1
154#else /* PAGE_SHIFT == 13 */
155#define __THREAD_INFO_ORDER 0
156#endif /* PAGE_SHIFT == 13 */
157
158#ifdef CONFIG_DEBUG_STACK_USAGE
159#define alloc_thread_info(tsk) \
160({ \
161 struct thread_info *ret; \
162 \
163 ret = (struct thread_info *) \
164 __get_free_pages(GFP_KERNEL, __THREAD_INFO_ORDER); \
165 if (ret) \
166 memset(ret, 0, PAGE_SIZE<<__THREAD_INFO_ORDER); \
167 ret; \
168})
169#else
170#define alloc_thread_info(tsk) \
171 ((struct thread_info *)__get_free_pages(GFP_KERNEL, __THREAD_INFO_ORDER))
172#endif
173
174#define free_thread_info(ti) \
175 free_pages((unsigned long)(ti),__THREAD_INFO_ORDER)
176
177#define __thread_flag_byte_ptr(ti) \
178 ((unsigned char *)(&((ti)->flags)))
179#define __cur_thread_flag_byte_ptr __thread_flag_byte_ptr(current_thread_info())
180
181#define get_thread_fault_code() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE])
182#define set_thread_fault_code(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE] = (val))
183#define get_thread_wstate() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE])
184#define set_thread_wstate(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE] = (val))
185#define get_thread_cwp() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP])
186#define set_thread_cwp(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP] = (val))
187#define get_thread_current_ds() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CURRENT_DS])
188#define set_thread_current_ds(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CURRENT_DS] = (val))
189#define get_thread_fpdepth() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH])
190#define set_thread_fpdepth(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH] = (val))
191#define get_thread_wsaved() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED])
192#define set_thread_wsaved(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED] = (val))
193
194#endif /* !(__ASSEMBLY__) */
195
196/*
197 * Thread information flags, only 16 bits are available as we encode
198 * other values into the upper 6 bytes.
199 *
200 * On trap return we need to test several values:
201 *
202 * user: need_resched, notify_resume, sigpending, wsaved, perfctr
203 * kernel: fpdepth
204 *
205 * So to check for work in the kernel case we simply load the fpdepth
206 * byte out of the flags and test it. For the user case we encode the
207 * lower 3 bytes of flags as follows:
208 * ----------------------------------------
209 * | wsaved | flags byte 1 | flags byte 2 |
210 * ----------------------------------------
211 * This optimizes the user test into:
212 * ldx [%g6 + TI_FLAGS], REG1
213 * sethi %hi(_TIF_USER_WORK_MASK), REG2
214 * or REG2, %lo(_TIF_USER_WORK_MASK), REG2
215 * andcc REG1, REG2, %g0
216 * be,pt no_work_to_do
217 * nop
218 */
219#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
220/* flags bit 1 is available */
221#define TIF_SIGPENDING 2 /* signal pending */
222#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
223#define TIF_PERFCTR 4 /* performance counters active */
224#define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
225/* flag bit 6 is available */
226#define TIF_32BIT 7 /* 32-bit binary */
227/* flag bit 8 is available */
228#define TIF_SECCOMP 9 /* secure computing */
229#define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
230/* flag bit 11 is available */
231/* NOTE: Thread flags >= 12 should be ones we have no interest
232 * in using in assembly, else we can't use the mask as
233 * an immediate value in instructions such as andcc.
234 */
235#define TIF_ABI_PENDING 12
236#define TIF_MEMDIE 13
237#define TIF_POLLING_NRFLAG 14
238
239#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
240#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
241#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
242#define _TIF_PERFCTR (1<<TIF_PERFCTR)
243#define _TIF_UNALIGNED (1<<TIF_UNALIGNED)
244#define _TIF_32BIT (1<<TIF_32BIT)
245#define _TIF_SECCOMP (1<<TIF_SECCOMP)
246#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
247#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)
248#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
249
250#define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
251 (_TIF_SIGPENDING | \
252 _TIF_NEED_RESCHED | _TIF_PERFCTR))
253
254/*
255 * Thread-synchronous status.
256 *
257 * This is different from the flags in that nobody else
258 * ever touches our thread-synchronous status, so we don't
259 * have to worry about atomic accesses.
260 *
261 * Note that there are only 8 bits available.
262 */
263#define TS_RESTORE_SIGMASK 0x0001 /* restore signal mask in do_signal() */
264
265#ifndef __ASSEMBLY__
266#define HAVE_SET_RESTORE_SIGMASK 1
267static inline void set_restore_sigmask(void)
268{
269 struct thread_info *ti = current_thread_info();
270 ti->status |= TS_RESTORE_SIGMASK;
271 set_bit(TIF_SIGPENDING, &ti->flags);
272}
273#endif /* !__ASSEMBLY__ */
274
275#endif /* __KERNEL__ */
276
277#endif /* _ASM_THREAD_INFO_H */
diff --git a/include/asm-sparc64/timer.h b/include/asm-sparc64/timer.h
index 5b779fd1f788..88026d83cc93 100644
--- a/include/asm-sparc64/timer.h
+++ b/include/asm-sparc64/timer.h
@@ -1,30 +1 @@
1/* timer.h: System timer definitions for sun5. #include <asm-sparc/timer.h>
2 *
3 * Copyright (C) 1997, 2008 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_TIMER_H
7#define _SPARC64_TIMER_H
8
9#include <linux/types.h>
10#include <linux/init.h>
11
12struct sparc64_tick_ops {
13 unsigned long (*get_tick)(void);
14 int (*add_compare)(unsigned long);
15 unsigned long softint_mask;
16 void (*disable_irq)(void);
17
18 void (*init_tick)(void);
19 unsigned long (*add_tick)(unsigned long);
20
21 char *name;
22};
23
24extern struct sparc64_tick_ops *tick_ops;
25
26extern unsigned long sparc64_get_clock_tick(unsigned int cpu);
27extern void __devinit setup_sparc64_timer(void);
28extern void __init time_init(void);
29
30#endif /* _SPARC64_TIMER_H */
diff --git a/include/asm-sparc64/timex.h b/include/asm-sparc64/timex.h
index c622535c4560..8dd59ee24b48 100644
--- a/include/asm-sparc64/timex.h
+++ b/include/asm-sparc64/timex.h
@@ -1,19 +1 @@
1/* #include <asm-sparc/timex.h>
2 * linux/include/asm-sparc64/timex.h
3 *
4 * sparc64 architecture timex specifications
5 */
6#ifndef _ASMsparc64_TIMEX_H
7#define _ASMsparc64_TIMEX_H
8
9#include <asm/timer.h>
10
11#define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
12
13/* Getting on the cycle counter on sparc64. */
14typedef unsigned long cycles_t;
15#define get_cycles() tick_ops->get_tick()
16
17#define ARCH_HAS_READ_CURRENT_TIMER
18
19#endif
diff --git a/include/asm-sparc64/tlb.h b/include/asm-sparc64/tlb.h
index ec81cdedef2c..ae92fce10936 100644
--- a/include/asm-sparc64/tlb.h
+++ b/include/asm-sparc64/tlb.h
@@ -1,111 +1 @@
1#ifndef _SPARC64_TLB_H #include <asm-sparc/tlb.h>
2#define _SPARC64_TLB_H
3
4#include <linux/swap.h>
5#include <linux/pagemap.h>
6#include <asm/pgalloc.h>
7#include <asm/tlbflush.h>
8#include <asm/mmu_context.h>
9
10#define TLB_BATCH_NR 192
11
12/*
13 * For UP we don't need to worry about TLB flush
14 * and page free order so much..
15 */
16#ifdef CONFIG_SMP
17 #define FREE_PTE_NR 506
18 #define tlb_fast_mode(bp) ((bp)->pages_nr == ~0U)
19#else
20 #define FREE_PTE_NR 1
21 #define tlb_fast_mode(bp) 1
22#endif
23
24struct mmu_gather {
25 struct mm_struct *mm;
26 unsigned int pages_nr;
27 unsigned int need_flush;
28 unsigned int fullmm;
29 unsigned int tlb_nr;
30 unsigned long vaddrs[TLB_BATCH_NR];
31 struct page *pages[FREE_PTE_NR];
32};
33
34DECLARE_PER_CPU(struct mmu_gather, mmu_gathers);
35
36#ifdef CONFIG_SMP
37extern void smp_flush_tlb_pending(struct mm_struct *,
38 unsigned long, unsigned long *);
39#endif
40
41extern void __flush_tlb_pending(unsigned long, unsigned long, unsigned long *);
42extern void flush_tlb_pending(void);
43
44static inline struct mmu_gather *tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush)
45{
46 struct mmu_gather *mp = &get_cpu_var(mmu_gathers);
47
48 BUG_ON(mp->tlb_nr);
49
50 mp->mm = mm;
51 mp->pages_nr = num_online_cpus() > 1 ? 0U : ~0U;
52 mp->fullmm = full_mm_flush;
53
54 return mp;
55}
56
57
58static inline void tlb_flush_mmu(struct mmu_gather *mp)
59{
60 if (mp->need_flush) {
61 free_pages_and_swap_cache(mp->pages, mp->pages_nr);
62 mp->pages_nr = 0;
63 mp->need_flush = 0;
64 }
65
66}
67
68#ifdef CONFIG_SMP
69extern void smp_flush_tlb_mm(struct mm_struct *mm);
70#define do_flush_tlb_mm(mm) smp_flush_tlb_mm(mm)
71#else
72#define do_flush_tlb_mm(mm) __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT)
73#endif
74
75static inline void tlb_finish_mmu(struct mmu_gather *mp, unsigned long start, unsigned long end)
76{
77 tlb_flush_mmu(mp);
78
79 if (mp->fullmm)
80 mp->fullmm = 0;
81 else
82 flush_tlb_pending();
83
84 /* keep the page table cache within bounds */
85 check_pgt_cache();
86
87 put_cpu_var(mmu_gathers);
88}
89
90static inline void tlb_remove_page(struct mmu_gather *mp, struct page *page)
91{
92 if (tlb_fast_mode(mp)) {
93 free_page_and_swap_cache(page);
94 return;
95 }
96 mp->need_flush = 1;
97 mp->pages[mp->pages_nr++] = page;
98 if (mp->pages_nr >= FREE_PTE_NR)
99 tlb_flush_mmu(mp);
100}
101
102#define tlb_remove_tlb_entry(mp,ptep,addr) do { } while (0)
103#define pte_free_tlb(mp, ptepage) pte_free((mp)->mm, ptepage)
104#define pmd_free_tlb(mp, pmdp) pmd_free((mp)->mm, pmdp)
105#define pud_free_tlb(tlb,pudp) __pud_free_tlb(tlb,pudp)
106
107#define tlb_migrate_finish(mm) do { } while (0)
108#define tlb_start_vma(tlb, vma) do { } while (0)
109#define tlb_end_vma(tlb, vma) do { } while (0)
110
111#endif /* _SPARC64_TLB_H */
diff --git a/include/asm-sparc64/tlbflush.h b/include/asm-sparc64/tlbflush.h
index fbb675dbe0c9..a43979a06cd9 100644
--- a/include/asm-sparc64/tlbflush.h
+++ b/include/asm-sparc64/tlbflush.h
@@ -1,44 +1 @@
1#ifndef _SPARC64_TLBFLUSH_H #include <asm-sparc/tlbflush.h>
2#define _SPARC64_TLBFLUSH_H
3
4#include <linux/mm.h>
5#include <asm/mmu_context.h>
6
7/* TSB flush operations. */
8struct mmu_gather;
9extern void flush_tsb_kernel_range(unsigned long start, unsigned long end);
10extern void flush_tsb_user(struct mmu_gather *mp);
11
12/* TLB flush operations. */
13
14extern void flush_tlb_pending(void);
15
16#define flush_tlb_range(vma,start,end) \
17 do { (void)(start); flush_tlb_pending(); } while (0)
18#define flush_tlb_page(vma,addr) flush_tlb_pending()
19#define flush_tlb_mm(mm) flush_tlb_pending()
20
21/* Local cpu only. */
22extern void __flush_tlb_all(void);
23
24extern void __flush_tlb_kernel_range(unsigned long start, unsigned long end);
25
26#ifndef CONFIG_SMP
27
28#define flush_tlb_kernel_range(start,end) \
29do { flush_tsb_kernel_range(start,end); \
30 __flush_tlb_kernel_range(start,end); \
31} while (0)
32
33#else /* CONFIG_SMP */
34
35extern void smp_flush_tlb_kernel_range(unsigned long start, unsigned long end);
36
37#define flush_tlb_kernel_range(start, end) \
38do { flush_tsb_kernel_range(start,end); \
39 smp_flush_tlb_kernel_range(start, end); \
40} while (0)
41
42#endif /* ! CONFIG_SMP */
43
44#endif /* _SPARC64_TLBFLUSH_H */
diff --git a/include/asm-sparc64/topology.h b/include/asm-sparc64/topology.h
index 001c04027c82..46999b60fbba 100644
--- a/include/asm-sparc64/topology.h
+++ b/include/asm-sparc64/topology.h
@@ -1,86 +1 @@
1#ifndef _ASM_SPARC64_TOPOLOGY_H #include <asm-sparc/topology.h>
2#define _ASM_SPARC64_TOPOLOGY_H
3
4#ifdef CONFIG_NUMA
5
6#include <asm/mmzone.h>
7
8static inline int cpu_to_node(int cpu)
9{
10 return numa_cpu_lookup_table[cpu];
11}
12
13#define parent_node(node) (node)
14
15static inline cpumask_t node_to_cpumask(int node)
16{
17 return numa_cpumask_lookup_table[node];
18}
19
20/* Returns a pointer to the cpumask of CPUs on Node 'node'. */
21#define node_to_cpumask_ptr(v, node) \
22 cpumask_t *v = &(numa_cpumask_lookup_table[node])
23
24#define node_to_cpumask_ptr_next(v, node) \
25 v = &(numa_cpumask_lookup_table[node])
26
27static inline int node_to_first_cpu(int node)
28{
29 cpumask_t tmp;
30 tmp = node_to_cpumask(node);
31 return first_cpu(tmp);
32}
33
34struct pci_bus;
35#ifdef CONFIG_PCI
36extern int pcibus_to_node(struct pci_bus *pbus);
37#else
38static inline int pcibus_to_node(struct pci_bus *pbus)
39{
40 return -1;
41}
42#endif
43
44#define pcibus_to_cpumask(bus) \
45 (pcibus_to_node(bus) == -1 ? \
46 CPU_MASK_ALL : \
47 node_to_cpumask(pcibus_to_node(bus)))
48
49#define SD_NODE_INIT (struct sched_domain) { \
50 .min_interval = 8, \
51 .max_interval = 32, \
52 .busy_factor = 32, \
53 .imbalance_pct = 125, \
54 .cache_nice_tries = 2, \
55 .busy_idx = 3, \
56 .idle_idx = 2, \
57 .newidle_idx = 0, \
58 .wake_idx = 1, \
59 .forkexec_idx = 1, \
60 .flags = SD_LOAD_BALANCE \
61 | SD_BALANCE_FORK \
62 | SD_BALANCE_EXEC \
63 | SD_SERIALIZE \
64 | SD_WAKE_BALANCE, \
65 .last_balance = jiffies, \
66 .balance_interval = 1, \
67}
68
69#else /* CONFIG_NUMA */
70
71#include <asm-generic/topology.h>
72
73#endif /* !(CONFIG_NUMA) */
74
75#ifdef CONFIG_SMP
76#define topology_physical_package_id(cpu) (cpu_data(cpu).proc_id)
77#define topology_core_id(cpu) (cpu_data(cpu).core_id)
78#define topology_core_siblings(cpu) (cpu_core_map[cpu])
79#define topology_thread_siblings(cpu) (per_cpu(cpu_sibling_map, cpu))
80#define mc_capable() (sparc64_multi_core)
81#define smt_capable() (sparc64_multi_core)
82#endif /* CONFIG_SMP */
83
84#define cpu_coregroup_map(cpu) (cpu_core_map[cpu])
85
86#endif /* _ASM_SPARC64_TOPOLOGY_H */
diff --git a/include/asm-sparc64/tsb.h b/include/asm-sparc64/tsb.h
index 76e4299dd9bc..3677a302ea3e 100644
--- a/include/asm-sparc64/tsb.h
+++ b/include/asm-sparc64/tsb.h
@@ -1,283 +1 @@
1#ifndef _SPARC64_TSB_H #include <asm-sparc/tsb.h>
2#define _SPARC64_TSB_H
3
4/* The sparc64 TSB is similar to the powerpc hashtables. It's a
5 * power-of-2 sized table of TAG/PTE pairs. The cpu precomputes
6 * pointers into this table for 8K and 64K page sizes, and also a
7 * comparison TAG based upon the virtual address and context which
8 * faults.
9 *
10 * TLB miss trap handler software does the actual lookup via something
11 * of the form:
12 *
13 * ldxa [%g0] ASI_{D,I}MMU_TSB_8KB_PTR, %g1
14 * ldxa [%g0] ASI_{D,I}MMU, %g6
15 * sllx %g6, 22, %g6
16 * srlx %g6, 22, %g6
17 * ldda [%g1] ASI_NUCLEUS_QUAD_LDD, %g4
18 * cmp %g4, %g6
19 * bne,pn %xcc, tsb_miss_{d,i}tlb
20 * mov FAULT_CODE_{D,I}TLB, %g3
21 * stxa %g5, [%g0] ASI_{D,I}TLB_DATA_IN
22 * retry
23 *
24 *
25 * Each 16-byte slot of the TSB is the 8-byte tag and then the 8-byte
26 * PTE. The TAG is of the same layout as the TLB TAG TARGET mmu
27 * register which is:
28 *
29 * -------------------------------------------------
30 * | - | CONTEXT | - | VADDR bits 63:22 |
31 * -------------------------------------------------
32 * 63 61 60 48 47 42 41 0
33 *
34 * But actually, since we use per-mm TSB's, we zero out the CONTEXT
35 * field.
36 *
37 * Like the powerpc hashtables we need to use locking in order to
38 * synchronize while we update the entries. PTE updates need locking
39 * as well.
40 *
41 * We need to carefully choose a lock bits for the TSB entry. We
42 * choose to use bit 47 in the tag. Also, since we never map anything
43 * at page zero in context zero, we use zero as an invalid tag entry.
44 * When the lock bit is set, this forces a tag comparison failure.
45 */
46
47#define TSB_TAG_LOCK_BIT 47
48#define TSB_TAG_LOCK_HIGH (1 << (TSB_TAG_LOCK_BIT - 32))
49
50#define TSB_TAG_INVALID_BIT 46
51#define TSB_TAG_INVALID_HIGH (1 << (TSB_TAG_INVALID_BIT - 32))
52
53#define TSB_MEMBAR membar #StoreStore
54
55/* Some cpus support physical address quad loads. We want to use
56 * those if possible so we don't need to hard-lock the TSB mapping
57 * into the TLB. We encode some instruction patching in order to
58 * support this.
59 *
60 * The kernel TSB is locked into the TLB by virtue of being in the
61 * kernel image, so we don't play these games for swapper_tsb access.
62 */
63#ifndef __ASSEMBLY__
64struct tsb_ldquad_phys_patch_entry {
65 unsigned int addr;
66 unsigned int sun4u_insn;
67 unsigned int sun4v_insn;
68};
69extern struct tsb_ldquad_phys_patch_entry __tsb_ldquad_phys_patch,
70 __tsb_ldquad_phys_patch_end;
71
72struct tsb_phys_patch_entry {
73 unsigned int addr;
74 unsigned int insn;
75};
76extern struct tsb_phys_patch_entry __tsb_phys_patch, __tsb_phys_patch_end;
77#endif
78#define TSB_LOAD_QUAD(TSB, REG) \
79661: ldda [TSB] ASI_NUCLEUS_QUAD_LDD, REG; \
80 .section .tsb_ldquad_phys_patch, "ax"; \
81 .word 661b; \
82 ldda [TSB] ASI_QUAD_LDD_PHYS, REG; \
83 ldda [TSB] ASI_QUAD_LDD_PHYS_4V, REG; \
84 .previous
85
86#define TSB_LOAD_TAG_HIGH(TSB, REG) \
87661: lduwa [TSB] ASI_N, REG; \
88 .section .tsb_phys_patch, "ax"; \
89 .word 661b; \
90 lduwa [TSB] ASI_PHYS_USE_EC, REG; \
91 .previous
92
93#define TSB_LOAD_TAG(TSB, REG) \
94661: ldxa [TSB] ASI_N, REG; \
95 .section .tsb_phys_patch, "ax"; \
96 .word 661b; \
97 ldxa [TSB] ASI_PHYS_USE_EC, REG; \
98 .previous
99
100#define TSB_CAS_TAG_HIGH(TSB, REG1, REG2) \
101661: casa [TSB] ASI_N, REG1, REG2; \
102 .section .tsb_phys_patch, "ax"; \
103 .word 661b; \
104 casa [TSB] ASI_PHYS_USE_EC, REG1, REG2; \
105 .previous
106
107#define TSB_CAS_TAG(TSB, REG1, REG2) \
108661: casxa [TSB] ASI_N, REG1, REG2; \
109 .section .tsb_phys_patch, "ax"; \
110 .word 661b; \
111 casxa [TSB] ASI_PHYS_USE_EC, REG1, REG2; \
112 .previous
113
114#define TSB_STORE(ADDR, VAL) \
115661: stxa VAL, [ADDR] ASI_N; \
116 .section .tsb_phys_patch, "ax"; \
117 .word 661b; \
118 stxa VAL, [ADDR] ASI_PHYS_USE_EC; \
119 .previous
120
121#define TSB_LOCK_TAG(TSB, REG1, REG2) \
12299: TSB_LOAD_TAG_HIGH(TSB, REG1); \
123 sethi %hi(TSB_TAG_LOCK_HIGH), REG2;\
124 andcc REG1, REG2, %g0; \
125 bne,pn %icc, 99b; \
126 nop; \
127 TSB_CAS_TAG_HIGH(TSB, REG1, REG2); \
128 cmp REG1, REG2; \
129 bne,pn %icc, 99b; \
130 nop; \
131 TSB_MEMBAR
132
133#define TSB_WRITE(TSB, TTE, TAG) \
134 add TSB, 0x8, TSB; \
135 TSB_STORE(TSB, TTE); \
136 sub TSB, 0x8, TSB; \
137 TSB_MEMBAR; \
138 TSB_STORE(TSB, TAG);
139
140#define KTSB_LOAD_QUAD(TSB, REG) \
141 ldda [TSB] ASI_NUCLEUS_QUAD_LDD, REG;
142
143#define KTSB_STORE(ADDR, VAL) \
144 stxa VAL, [ADDR] ASI_N;
145
146#define KTSB_LOCK_TAG(TSB, REG1, REG2) \
14799: lduwa [TSB] ASI_N, REG1; \
148 sethi %hi(TSB_TAG_LOCK_HIGH), REG2;\
149 andcc REG1, REG2, %g0; \
150 bne,pn %icc, 99b; \
151 nop; \
152 casa [TSB] ASI_N, REG1, REG2;\
153 cmp REG1, REG2; \
154 bne,pn %icc, 99b; \
155 nop; \
156 TSB_MEMBAR
157
158#define KTSB_WRITE(TSB, TTE, TAG) \
159 add TSB, 0x8, TSB; \
160 stxa TTE, [TSB] ASI_N; \
161 sub TSB, 0x8, TSB; \
162 TSB_MEMBAR; \
163 stxa TAG, [TSB] ASI_N;
164
165 /* Do a kernel page table walk. Leaves physical PTE pointer in
166 * REG1. Jumps to FAIL_LABEL on early page table walk termination.
167 * VADDR will not be clobbered, but REG2 will.
168 */
169#define KERN_PGTABLE_WALK(VADDR, REG1, REG2, FAIL_LABEL) \
170 sethi %hi(swapper_pg_dir), REG1; \
171 or REG1, %lo(swapper_pg_dir), REG1; \
172 sllx VADDR, 64 - (PGDIR_SHIFT + PGDIR_BITS), REG2; \
173 srlx REG2, 64 - PAGE_SHIFT, REG2; \
174 andn REG2, 0x3, REG2; \
175 lduw [REG1 + REG2], REG1; \
176 brz,pn REG1, FAIL_LABEL; \
177 sllx VADDR, 64 - (PMD_SHIFT + PMD_BITS), REG2; \
178 srlx REG2, 64 - PAGE_SHIFT, REG2; \
179 sllx REG1, 11, REG1; \
180 andn REG2, 0x3, REG2; \
181 lduwa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \
182 brz,pn REG1, FAIL_LABEL; \
183 sllx VADDR, 64 - PMD_SHIFT, REG2; \
184 srlx REG2, 64 - PAGE_SHIFT, REG2; \
185 sllx REG1, 11, REG1; \
186 andn REG2, 0x7, REG2; \
187 add REG1, REG2, REG1;
188
189 /* Do a user page table walk in MMU globals. Leaves physical PTE
190 * pointer in REG1. Jumps to FAIL_LABEL on early page table walk
191 * termination. Physical base of page tables is in PHYS_PGD which
192 * will not be modified.
193 *
194 * VADDR will not be clobbered, but REG1 and REG2 will.
195 */
196#define USER_PGTABLE_WALK_TL1(VADDR, PHYS_PGD, REG1, REG2, FAIL_LABEL) \
197 sllx VADDR, 64 - (PGDIR_SHIFT + PGDIR_BITS), REG2; \
198 srlx REG2, 64 - PAGE_SHIFT, REG2; \
199 andn REG2, 0x3, REG2; \
200 lduwa [PHYS_PGD + REG2] ASI_PHYS_USE_EC, REG1; \
201 brz,pn REG1, FAIL_LABEL; \
202 sllx VADDR, 64 - (PMD_SHIFT + PMD_BITS), REG2; \
203 srlx REG2, 64 - PAGE_SHIFT, REG2; \
204 sllx REG1, 11, REG1; \
205 andn REG2, 0x3, REG2; \
206 lduwa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \
207 brz,pn REG1, FAIL_LABEL; \
208 sllx VADDR, 64 - PMD_SHIFT, REG2; \
209 srlx REG2, 64 - PAGE_SHIFT, REG2; \
210 sllx REG1, 11, REG1; \
211 andn REG2, 0x7, REG2; \
212 add REG1, REG2, REG1;
213
214/* Lookup a OBP mapping on VADDR in the prom_trans[] table at TL>0.
215 * If no entry is found, FAIL_LABEL will be branched to. On success
216 * the resulting PTE value will be left in REG1. VADDR is preserved
217 * by this routine.
218 */
219#define OBP_TRANS_LOOKUP(VADDR, REG1, REG2, REG3, FAIL_LABEL) \
220 sethi %hi(prom_trans), REG1; \
221 or REG1, %lo(prom_trans), REG1; \
22297: ldx [REG1 + 0x00], REG2; \
223 brz,pn REG2, FAIL_LABEL; \
224 nop; \
225 ldx [REG1 + 0x08], REG3; \
226 add REG2, REG3, REG3; \
227 cmp REG2, VADDR; \
228 bgu,pt %xcc, 98f; \
229 cmp VADDR, REG3; \
230 bgeu,pt %xcc, 98f; \
231 ldx [REG1 + 0x10], REG3; \
232 sub VADDR, REG2, REG2; \
233 ba,pt %xcc, 99f; \
234 add REG3, REG2, REG1; \
23598: ba,pt %xcc, 97b; \
236 add REG1, (3 * 8), REG1; \
23799:
238
239 /* We use a 32K TSB for the whole kernel, this allows to
240 * handle about 16MB of modules and vmalloc mappings without
241 * incurring many hash conflicts.
242 */
243#define KERNEL_TSB_SIZE_BYTES (32 * 1024)
244#define KERNEL_TSB_NENTRIES \
245 (KERNEL_TSB_SIZE_BYTES / 16)
246#define KERNEL_TSB4M_NENTRIES 4096
247
248 /* Do a kernel TSB lookup at tl>0 on VADDR+TAG, branch to OK_LABEL
249 * on TSB hit. REG1, REG2, REG3, and REG4 are used as temporaries
250 * and the found TTE will be left in REG1. REG3 and REG4 must
251 * be an even/odd pair of registers.
252 *
253 * VADDR and TAG will be preserved and not clobbered by this macro.
254 */
255#define KERN_TSB_LOOKUP_TL1(VADDR, TAG, REG1, REG2, REG3, REG4, OK_LABEL) \
256 sethi %hi(swapper_tsb), REG1; \
257 or REG1, %lo(swapper_tsb), REG1; \
258 srlx VADDR, PAGE_SHIFT, REG2; \
259 and REG2, (KERNEL_TSB_NENTRIES - 1), REG2; \
260 sllx REG2, 4, REG2; \
261 add REG1, REG2, REG2; \
262 KTSB_LOAD_QUAD(REG2, REG3); \
263 cmp REG3, TAG; \
264 be,a,pt %xcc, OK_LABEL; \
265 mov REG4, REG1;
266
267#ifndef CONFIG_DEBUG_PAGEALLOC
268 /* This version uses a trick, the TAG is already (VADDR >> 22) so
269 * we can make use of that for the index computation.
270 */
271#define KERN_TSB4M_LOOKUP_TL1(TAG, REG1, REG2, REG3, REG4, OK_LABEL) \
272 sethi %hi(swapper_4m_tsb), REG1; \
273 or REG1, %lo(swapper_4m_tsb), REG1; \
274 and TAG, (KERNEL_TSB4M_NENTRIES - 1), REG2; \
275 sllx REG2, 4, REG2; \
276 add REG1, REG2, REG2; \
277 KTSB_LOAD_QUAD(REG2, REG3); \
278 cmp REG3, TAG; \
279 be,a,pt %xcc, OK_LABEL; \
280 mov REG4, REG1;
281#endif
282
283#endif /* !(_SPARC64_TSB_H) */
diff --git a/include/asm-sparc64/ttable.h b/include/asm-sparc64/ttable.h
index 0ba199587e07..a550f1bf6f9b 100644
--- a/include/asm-sparc64/ttable.h
+++ b/include/asm-sparc64/ttable.h
@@ -1,658 +1 @@
1#ifndef _SPARC64_TTABLE_H #include <asm-sparc/ttable.h>
2#define _SPARC64_TTABLE_H
3
4#include <asm/utrap.h>
5
6#ifdef __ASSEMBLY__
7#include <asm/thread_info.h>
8#endif
9
10#define BOOT_KERNEL b sparc64_boot; nop; nop; nop; nop; nop; nop; nop;
11
12/* We need a "cleaned" instruction... */
13#define CLEAN_WINDOW \
14 rdpr %cleanwin, %l0; add %l0, 1, %l0; \
15 wrpr %l0, 0x0, %cleanwin; \
16 clr %o0; clr %o1; clr %o2; clr %o3; \
17 clr %o4; clr %o5; clr %o6; clr %o7; \
18 clr %l0; clr %l1; clr %l2; clr %l3; \
19 clr %l4; clr %l5; clr %l6; clr %l7; \
20 retry; \
21 nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
22
23#define TRAP(routine) \
24 sethi %hi(109f), %g7; \
25 ba,pt %xcc, etrap; \
26109: or %g7, %lo(109b), %g7; \
27 call routine; \
28 add %sp, PTREGS_OFF, %o0; \
29 ba,pt %xcc, rtrap; \
30 nop; \
31 nop;
32
33#define TRAP_7INSNS(routine) \
34 sethi %hi(109f), %g7; \
35 ba,pt %xcc, etrap; \
36109: or %g7, %lo(109b), %g7; \
37 call routine; \
38 add %sp, PTREGS_OFF, %o0; \
39 ba,pt %xcc, rtrap; \
40 nop;
41
42#define TRAP_SAVEFPU(routine) \
43 sethi %hi(109f), %g7; \
44 ba,pt %xcc, do_fptrap; \
45109: or %g7, %lo(109b), %g7; \
46 call routine; \
47 add %sp, PTREGS_OFF, %o0; \
48 ba,pt %xcc, rtrap; \
49 nop; \
50 nop;
51
52#define TRAP_NOSAVE(routine) \
53 ba,pt %xcc, routine; \
54 nop; \
55 nop; nop; nop; nop; nop; nop;
56
57#define TRAP_NOSAVE_7INSNS(routine) \
58 ba,pt %xcc, routine; \
59 nop; \
60 nop; nop; nop; nop; nop;
61
62#define TRAPTL1(routine) \
63 sethi %hi(109f), %g7; \
64 ba,pt %xcc, etraptl1; \
65109: or %g7, %lo(109b), %g7; \
66 call routine; \
67 add %sp, PTREGS_OFF, %o0; \
68 ba,pt %xcc, rtrap; \
69 nop; \
70 nop;
71
72#define TRAP_ARG(routine, arg) \
73 sethi %hi(109f), %g7; \
74 ba,pt %xcc, etrap; \
75109: or %g7, %lo(109b), %g7; \
76 add %sp, PTREGS_OFF, %o0; \
77 call routine; \
78 mov arg, %o1; \
79 ba,pt %xcc, rtrap; \
80 nop;
81
82#define TRAPTL1_ARG(routine, arg) \
83 sethi %hi(109f), %g7; \
84 ba,pt %xcc, etraptl1; \
85109: or %g7, %lo(109b), %g7; \
86 add %sp, PTREGS_OFF, %o0; \
87 call routine; \
88 mov arg, %o1; \
89 ba,pt %xcc, rtrap; \
90 nop;
91
92#define SYSCALL_TRAP(routine, systbl) \
93 rdpr %pil, %g2; \
94 mov TSTATE_SYSCALL, %g3; \
95 sethi %hi(109f), %g7; \
96 ba,pt %xcc, etrap_syscall; \
97109: or %g7, %lo(109b), %g7; \
98 sethi %hi(systbl), %l7; \
99 ba,pt %xcc, routine; \
100 or %l7, %lo(systbl), %l7;
101
102#define TRAP_UTRAP(handler,lvl) \
103 mov handler, %g3; \
104 ba,pt %xcc, utrap_trap; \
105 mov lvl, %g4; \
106 nop; \
107 nop; \
108 nop; \
109 nop; \
110 nop;
111
112#ifdef CONFIG_COMPAT
113#define LINUX_32BIT_SYSCALL_TRAP SYSCALL_TRAP(linux_sparc_syscall32, sys_call_table32)
114#else
115#define LINUX_32BIT_SYSCALL_TRAP BTRAP(0x110)
116#endif
117#define LINUX_64BIT_SYSCALL_TRAP SYSCALL_TRAP(linux_sparc_syscall, sys_call_table64)
118#define GETCC_TRAP TRAP(getcc)
119#define SETCC_TRAP TRAP(setcc)
120#define BREAKPOINT_TRAP TRAP(breakpoint_trap)
121
122#ifdef CONFIG_TRACE_IRQFLAGS
123
124#define TRAP_IRQ(routine, level) \
125 rdpr %pil, %g2; \
126 wrpr %g0, 15, %pil; \
127 sethi %hi(1f-4), %g7; \
128 ba,pt %xcc, etrap_irq; \
129 or %g7, %lo(1f-4), %g7; \
130 nop; \
131 nop; \
132 nop; \
133 .subsection 2; \
1341: call trace_hardirqs_off; \
135 nop; \
136 mov level, %o0; \
137 call routine; \
138 add %sp, PTREGS_OFF, %o1; \
139 ba,a,pt %xcc, rtrap_irq; \
140 .previous;
141
142#else
143
144#define TRAP_IRQ(routine, level) \
145 rdpr %pil, %g2; \
146 wrpr %g0, 15, %pil; \
147 ba,pt %xcc, etrap_irq; \
148 rd %pc, %g7; \
149 mov level, %o0; \
150 call routine; \
151 add %sp, PTREGS_OFF, %o1; \
152 ba,a,pt %xcc, rtrap_irq;
153
154#endif
155
156#define TRAP_IVEC TRAP_NOSAVE(do_ivec)
157
158#define BTRAP(lvl) TRAP_ARG(bad_trap, lvl)
159
160#define BTRAPTL1(lvl) TRAPTL1_ARG(bad_trap_tl1, lvl)
161
162#define FLUSH_WINDOW_TRAP \
163 ba,pt %xcc, etrap; \
164 rd %pc, %g7; \
165 flushw; \
166 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1; \
167 add %l1, 4, %l2; \
168 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]; \
169 ba,pt %xcc, rtrap; \
170 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC];
171
172#ifdef CONFIG_KPROBES
173#define KPROBES_TRAP(lvl) TRAP_IRQ(kprobe_trap, lvl)
174#else
175#define KPROBES_TRAP(lvl) TRAP_ARG(bad_trap, lvl)
176#endif
177
178#ifdef CONFIG_KGDB
179#define KGDB_TRAP(lvl) TRAP_IRQ(kgdb_trap, lvl)
180#else
181#define KGDB_TRAP(lvl) TRAP_ARG(bad_trap, lvl)
182#endif
183
184#define SUN4V_ITSB_MISS \
185 ldxa [%g0] ASI_SCRATCHPAD, %g2; \
186 ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4; \
187 ldx [%g2 + HV_FAULT_I_CTX_OFFSET], %g5; \
188 srlx %g4, 22, %g6; \
189 ba,pt %xcc, sun4v_itsb_miss; \
190 nop; \
191 nop; \
192 nop;
193
194#define SUN4V_DTSB_MISS \
195 ldxa [%g0] ASI_SCRATCHPAD, %g2; \
196 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4; \
197 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5; \
198 srlx %g4, 22, %g6; \
199 ba,pt %xcc, sun4v_dtsb_miss; \
200 nop; \
201 nop; \
202 nop;
203
204/* Before touching these macros, you owe it to yourself to go and
205 * see how arch/sparc64/kernel/winfixup.S works... -DaveM
206 *
207 * For the user cases we used to use the %asi register, but
208 * it turns out that the "wr xxx, %asi" costs ~5 cycles, so
209 * now we use immediate ASI loads and stores instead. Kudos
210 * to Greg Onufer for pointing out this performance anomaly.
211 *
212 * Further note that we cannot use the g2, g4, g5, and g7 alternate
213 * globals in the spill routines, check out the save instruction in
214 * arch/sparc64/kernel/etrap.S to see what I mean about g2, and
215 * g4/g5 are the globals which are preserved by etrap processing
216 * for the caller of it. The g7 register is the return pc for
217 * etrap. Finally, g6 is the current thread register so we cannot
218 * us it in the spill handlers either. Most of these rules do not
219 * apply to fill processing, only g6 is not usable.
220 */
221
222/* Normal kernel spill */
223#define SPILL_0_NORMAL \
224 stx %l0, [%sp + STACK_BIAS + 0x00]; \
225 stx %l1, [%sp + STACK_BIAS + 0x08]; \
226 stx %l2, [%sp + STACK_BIAS + 0x10]; \
227 stx %l3, [%sp + STACK_BIAS + 0x18]; \
228 stx %l4, [%sp + STACK_BIAS + 0x20]; \
229 stx %l5, [%sp + STACK_BIAS + 0x28]; \
230 stx %l6, [%sp + STACK_BIAS + 0x30]; \
231 stx %l7, [%sp + STACK_BIAS + 0x38]; \
232 stx %i0, [%sp + STACK_BIAS + 0x40]; \
233 stx %i1, [%sp + STACK_BIAS + 0x48]; \
234 stx %i2, [%sp + STACK_BIAS + 0x50]; \
235 stx %i3, [%sp + STACK_BIAS + 0x58]; \
236 stx %i4, [%sp + STACK_BIAS + 0x60]; \
237 stx %i5, [%sp + STACK_BIAS + 0x68]; \
238 stx %i6, [%sp + STACK_BIAS + 0x70]; \
239 stx %i7, [%sp + STACK_BIAS + 0x78]; \
240 saved; retry; nop; nop; nop; nop; nop; nop; \
241 nop; nop; nop; nop; nop; nop; nop; nop;
242
243#define SPILL_0_NORMAL_ETRAP \
244etrap_kernel_spill: \
245 stx %l0, [%sp + STACK_BIAS + 0x00]; \
246 stx %l1, [%sp + STACK_BIAS + 0x08]; \
247 stx %l2, [%sp + STACK_BIAS + 0x10]; \
248 stx %l3, [%sp + STACK_BIAS + 0x18]; \
249 stx %l4, [%sp + STACK_BIAS + 0x20]; \
250 stx %l5, [%sp + STACK_BIAS + 0x28]; \
251 stx %l6, [%sp + STACK_BIAS + 0x30]; \
252 stx %l7, [%sp + STACK_BIAS + 0x38]; \
253 stx %i0, [%sp + STACK_BIAS + 0x40]; \
254 stx %i1, [%sp + STACK_BIAS + 0x48]; \
255 stx %i2, [%sp + STACK_BIAS + 0x50]; \
256 stx %i3, [%sp + STACK_BIAS + 0x58]; \
257 stx %i4, [%sp + STACK_BIAS + 0x60]; \
258 stx %i5, [%sp + STACK_BIAS + 0x68]; \
259 stx %i6, [%sp + STACK_BIAS + 0x70]; \
260 stx %i7, [%sp + STACK_BIAS + 0x78]; \
261 saved; \
262 sub %g1, 2, %g1; \
263 ba,pt %xcc, etrap_save; \
264 wrpr %g1, %cwp; \
265 nop; nop; nop; nop; nop; nop; nop; nop; \
266 nop; nop; nop; nop;
267
268/* Normal 64bit spill */
269#define SPILL_1_GENERIC(ASI) \
270 add %sp, STACK_BIAS + 0x00, %g1; \
271 stxa %l0, [%g1 + %g0] ASI; \
272 mov 0x08, %g3; \
273 stxa %l1, [%g1 + %g3] ASI; \
274 add %g1, 0x10, %g1; \
275 stxa %l2, [%g1 + %g0] ASI; \
276 stxa %l3, [%g1 + %g3] ASI; \
277 add %g1, 0x10, %g1; \
278 stxa %l4, [%g1 + %g0] ASI; \
279 stxa %l5, [%g1 + %g3] ASI; \
280 add %g1, 0x10, %g1; \
281 stxa %l6, [%g1 + %g0] ASI; \
282 stxa %l7, [%g1 + %g3] ASI; \
283 add %g1, 0x10, %g1; \
284 stxa %i0, [%g1 + %g0] ASI; \
285 stxa %i1, [%g1 + %g3] ASI; \
286 add %g1, 0x10, %g1; \
287 stxa %i2, [%g1 + %g0] ASI; \
288 stxa %i3, [%g1 + %g3] ASI; \
289 add %g1, 0x10, %g1; \
290 stxa %i4, [%g1 + %g0] ASI; \
291 stxa %i5, [%g1 + %g3] ASI; \
292 add %g1, 0x10, %g1; \
293 stxa %i6, [%g1 + %g0] ASI; \
294 stxa %i7, [%g1 + %g3] ASI; \
295 saved; \
296 retry; nop; nop; \
297 b,a,pt %xcc, spill_fixup_dax; \
298 b,a,pt %xcc, spill_fixup_mna; \
299 b,a,pt %xcc, spill_fixup;
300
301#define SPILL_1_GENERIC_ETRAP \
302etrap_user_spill_64bit: \
303 stxa %l0, [%sp + STACK_BIAS + 0x00] %asi; \
304 stxa %l1, [%sp + STACK_BIAS + 0x08] %asi; \
305 stxa %l2, [%sp + STACK_BIAS + 0x10] %asi; \
306 stxa %l3, [%sp + STACK_BIAS + 0x18] %asi; \
307 stxa %l4, [%sp + STACK_BIAS + 0x20] %asi; \
308 stxa %l5, [%sp + STACK_BIAS + 0x28] %asi; \
309 stxa %l6, [%sp + STACK_BIAS + 0x30] %asi; \
310 stxa %l7, [%sp + STACK_BIAS + 0x38] %asi; \
311 stxa %i0, [%sp + STACK_BIAS + 0x40] %asi; \
312 stxa %i1, [%sp + STACK_BIAS + 0x48] %asi; \
313 stxa %i2, [%sp + STACK_BIAS + 0x50] %asi; \
314 stxa %i3, [%sp + STACK_BIAS + 0x58] %asi; \
315 stxa %i4, [%sp + STACK_BIAS + 0x60] %asi; \
316 stxa %i5, [%sp + STACK_BIAS + 0x68] %asi; \
317 stxa %i6, [%sp + STACK_BIAS + 0x70] %asi; \
318 stxa %i7, [%sp + STACK_BIAS + 0x78] %asi; \
319 saved; \
320 sub %g1, 2, %g1; \
321 ba,pt %xcc, etrap_save; \
322 wrpr %g1, %cwp; \
323 nop; nop; nop; nop; nop; \
324 nop; nop; nop; nop; \
325 ba,a,pt %xcc, etrap_spill_fixup_64bit; \
326 ba,a,pt %xcc, etrap_spill_fixup_64bit; \
327 ba,a,pt %xcc, etrap_spill_fixup_64bit;
328
329#define SPILL_1_GENERIC_ETRAP_FIXUP \
330etrap_spill_fixup_64bit: \
331 ldub [%g6 + TI_WSAVED], %g1; \
332 sll %g1, 3, %g3; \
333 add %g6, %g3, %g3; \
334 stx %sp, [%g3 + TI_RWIN_SPTRS]; \
335 sll %g1, 7, %g3; \
336 add %g6, %g3, %g3; \
337 stx %l0, [%g3 + TI_REG_WINDOW + 0x00]; \
338 stx %l1, [%g3 + TI_REG_WINDOW + 0x08]; \
339 stx %l2, [%g3 + TI_REG_WINDOW + 0x10]; \
340 stx %l3, [%g3 + TI_REG_WINDOW + 0x18]; \
341 stx %l4, [%g3 + TI_REG_WINDOW + 0x20]; \
342 stx %l5, [%g3 + TI_REG_WINDOW + 0x28]; \
343 stx %l6, [%g3 + TI_REG_WINDOW + 0x30]; \
344 stx %l7, [%g3 + TI_REG_WINDOW + 0x38]; \
345 stx %i0, [%g3 + TI_REG_WINDOW + 0x40]; \
346 stx %i1, [%g3 + TI_REG_WINDOW + 0x48]; \
347 stx %i2, [%g3 + TI_REG_WINDOW + 0x50]; \
348 stx %i3, [%g3 + TI_REG_WINDOW + 0x58]; \
349 stx %i4, [%g3 + TI_REG_WINDOW + 0x60]; \
350 stx %i5, [%g3 + TI_REG_WINDOW + 0x68]; \
351 stx %i6, [%g3 + TI_REG_WINDOW + 0x70]; \
352 stx %i7, [%g3 + TI_REG_WINDOW + 0x78]; \
353 add %g1, 1, %g1; \
354 stb %g1, [%g6 + TI_WSAVED]; \
355 saved; \
356 rdpr %cwp, %g1; \
357 sub %g1, 2, %g1; \
358 ba,pt %xcc, etrap_save; \
359 wrpr %g1, %cwp; \
360 nop; nop; nop
361
362/* Normal 32bit spill */
363#define SPILL_2_GENERIC(ASI) \
364 srl %sp, 0, %sp; \
365 stwa %l0, [%sp + %g0] ASI; \
366 mov 0x04, %g3; \
367 stwa %l1, [%sp + %g3] ASI; \
368 add %sp, 0x08, %g1; \
369 stwa %l2, [%g1 + %g0] ASI; \
370 stwa %l3, [%g1 + %g3] ASI; \
371 add %g1, 0x08, %g1; \
372 stwa %l4, [%g1 + %g0] ASI; \
373 stwa %l5, [%g1 + %g3] ASI; \
374 add %g1, 0x08, %g1; \
375 stwa %l6, [%g1 + %g0] ASI; \
376 stwa %l7, [%g1 + %g3] ASI; \
377 add %g1, 0x08, %g1; \
378 stwa %i0, [%g1 + %g0] ASI; \
379 stwa %i1, [%g1 + %g3] ASI; \
380 add %g1, 0x08, %g1; \
381 stwa %i2, [%g1 + %g0] ASI; \
382 stwa %i3, [%g1 + %g3] ASI; \
383 add %g1, 0x08, %g1; \
384 stwa %i4, [%g1 + %g0] ASI; \
385 stwa %i5, [%g1 + %g3] ASI; \
386 add %g1, 0x08, %g1; \
387 stwa %i6, [%g1 + %g0] ASI; \
388 stwa %i7, [%g1 + %g3] ASI; \
389 saved; \
390 retry; nop; nop; \
391 b,a,pt %xcc, spill_fixup_dax; \
392 b,a,pt %xcc, spill_fixup_mna; \
393 b,a,pt %xcc, spill_fixup;
394
395#define SPILL_2_GENERIC_ETRAP \
396etrap_user_spill_32bit: \
397 srl %sp, 0, %sp; \
398 stwa %l0, [%sp + 0x00] %asi; \
399 stwa %l1, [%sp + 0x04] %asi; \
400 stwa %l2, [%sp + 0x08] %asi; \
401 stwa %l3, [%sp + 0x0c] %asi; \
402 stwa %l4, [%sp + 0x10] %asi; \
403 stwa %l5, [%sp + 0x14] %asi; \
404 stwa %l6, [%sp + 0x18] %asi; \
405 stwa %l7, [%sp + 0x1c] %asi; \
406 stwa %i0, [%sp + 0x20] %asi; \
407 stwa %i1, [%sp + 0x24] %asi; \
408 stwa %i2, [%sp + 0x28] %asi; \
409 stwa %i3, [%sp + 0x2c] %asi; \
410 stwa %i4, [%sp + 0x30] %asi; \
411 stwa %i5, [%sp + 0x34] %asi; \
412 stwa %i6, [%sp + 0x38] %asi; \
413 stwa %i7, [%sp + 0x3c] %asi; \
414 saved; \
415 sub %g1, 2, %g1; \
416 ba,pt %xcc, etrap_save; \
417 wrpr %g1, %cwp; \
418 nop; nop; nop; nop; \
419 nop; nop; nop; nop; \
420 ba,a,pt %xcc, etrap_spill_fixup_32bit; \
421 ba,a,pt %xcc, etrap_spill_fixup_32bit; \
422 ba,a,pt %xcc, etrap_spill_fixup_32bit;
423
424#define SPILL_2_GENERIC_ETRAP_FIXUP \
425etrap_spill_fixup_32bit: \
426 ldub [%g6 + TI_WSAVED], %g1; \
427 sll %g1, 3, %g3; \
428 add %g6, %g3, %g3; \
429 stx %sp, [%g3 + TI_RWIN_SPTRS]; \
430 sll %g1, 7, %g3; \
431 add %g6, %g3, %g3; \
432 stw %l0, [%g3 + TI_REG_WINDOW + 0x00]; \
433 stw %l1, [%g3 + TI_REG_WINDOW + 0x04]; \
434 stw %l2, [%g3 + TI_REG_WINDOW + 0x08]; \
435 stw %l3, [%g3 + TI_REG_WINDOW + 0x0c]; \
436 stw %l4, [%g3 + TI_REG_WINDOW + 0x10]; \
437 stw %l5, [%g3 + TI_REG_WINDOW + 0x14]; \
438 stw %l6, [%g3 + TI_REG_WINDOW + 0x18]; \
439 stw %l7, [%g3 + TI_REG_WINDOW + 0x1c]; \
440 stw %i0, [%g3 + TI_REG_WINDOW + 0x20]; \
441 stw %i1, [%g3 + TI_REG_WINDOW + 0x24]; \
442 stw %i2, [%g3 + TI_REG_WINDOW + 0x28]; \
443 stw %i3, [%g3 + TI_REG_WINDOW + 0x2c]; \
444 stw %i4, [%g3 + TI_REG_WINDOW + 0x30]; \
445 stw %i5, [%g3 + TI_REG_WINDOW + 0x34]; \
446 stw %i6, [%g3 + TI_REG_WINDOW + 0x38]; \
447 stw %i7, [%g3 + TI_REG_WINDOW + 0x3c]; \
448 add %g1, 1, %g1; \
449 stb %g1, [%g6 + TI_WSAVED]; \
450 saved; \
451 rdpr %cwp, %g1; \
452 sub %g1, 2, %g1; \
453 ba,pt %xcc, etrap_save; \
454 wrpr %g1, %cwp; \
455 nop; nop; nop
456
457#define SPILL_1_NORMAL SPILL_1_GENERIC(ASI_AIUP)
458#define SPILL_2_NORMAL SPILL_2_GENERIC(ASI_AIUP)
459#define SPILL_3_NORMAL SPILL_0_NORMAL
460#define SPILL_4_NORMAL SPILL_0_NORMAL
461#define SPILL_5_NORMAL SPILL_0_NORMAL
462#define SPILL_6_NORMAL SPILL_0_NORMAL
463#define SPILL_7_NORMAL SPILL_0_NORMAL
464
465#define SPILL_0_OTHER SPILL_0_NORMAL
466#define SPILL_1_OTHER SPILL_1_GENERIC(ASI_AIUS)
467#define SPILL_2_OTHER SPILL_2_GENERIC(ASI_AIUS)
468#define SPILL_3_OTHER SPILL_3_NORMAL
469#define SPILL_4_OTHER SPILL_4_NORMAL
470#define SPILL_5_OTHER SPILL_5_NORMAL
471#define SPILL_6_OTHER SPILL_6_NORMAL
472#define SPILL_7_OTHER SPILL_7_NORMAL
473
474/* Normal kernel fill */
475#define FILL_0_NORMAL \
476 ldx [%sp + STACK_BIAS + 0x00], %l0; \
477 ldx [%sp + STACK_BIAS + 0x08], %l1; \
478 ldx [%sp + STACK_BIAS + 0x10], %l2; \
479 ldx [%sp + STACK_BIAS + 0x18], %l3; \
480 ldx [%sp + STACK_BIAS + 0x20], %l4; \
481 ldx [%sp + STACK_BIAS + 0x28], %l5; \
482 ldx [%sp + STACK_BIAS + 0x30], %l6; \
483 ldx [%sp + STACK_BIAS + 0x38], %l7; \
484 ldx [%sp + STACK_BIAS + 0x40], %i0; \
485 ldx [%sp + STACK_BIAS + 0x48], %i1; \
486 ldx [%sp + STACK_BIAS + 0x50], %i2; \
487 ldx [%sp + STACK_BIAS + 0x58], %i3; \
488 ldx [%sp + STACK_BIAS + 0x60], %i4; \
489 ldx [%sp + STACK_BIAS + 0x68], %i5; \
490 ldx [%sp + STACK_BIAS + 0x70], %i6; \
491 ldx [%sp + STACK_BIAS + 0x78], %i7; \
492 restored; retry; nop; nop; nop; nop; nop; nop; \
493 nop; nop; nop; nop; nop; nop; nop; nop;
494
495#define FILL_0_NORMAL_RTRAP \
496kern_rtt_fill: \
497 rdpr %cwp, %g1; \
498 sub %g1, 1, %g1; \
499 wrpr %g1, %cwp; \
500 ldx [%sp + STACK_BIAS + 0x00], %l0; \
501 ldx [%sp + STACK_BIAS + 0x08], %l1; \
502 ldx [%sp + STACK_BIAS + 0x10], %l2; \
503 ldx [%sp + STACK_BIAS + 0x18], %l3; \
504 ldx [%sp + STACK_BIAS + 0x20], %l4; \
505 ldx [%sp + STACK_BIAS + 0x28], %l5; \
506 ldx [%sp + STACK_BIAS + 0x30], %l6; \
507 ldx [%sp + STACK_BIAS + 0x38], %l7; \
508 ldx [%sp + STACK_BIAS + 0x40], %i0; \
509 ldx [%sp + STACK_BIAS + 0x48], %i1; \
510 ldx [%sp + STACK_BIAS + 0x50], %i2; \
511 ldx [%sp + STACK_BIAS + 0x58], %i3; \
512 ldx [%sp + STACK_BIAS + 0x60], %i4; \
513 ldx [%sp + STACK_BIAS + 0x68], %i5; \
514 ldx [%sp + STACK_BIAS + 0x70], %i6; \
515 ldx [%sp + STACK_BIAS + 0x78], %i7; \
516 restored; \
517 add %g1, 1, %g1; \
518 ba,pt %xcc, kern_rtt_restore; \
519 wrpr %g1, %cwp; \
520 nop; nop; nop; nop; nop; \
521 nop; nop; nop; nop;
522
523
524/* Normal 64bit fill */
525#define FILL_1_GENERIC(ASI) \
526 add %sp, STACK_BIAS + 0x00, %g1; \
527 ldxa [%g1 + %g0] ASI, %l0; \
528 mov 0x08, %g2; \
529 mov 0x10, %g3; \
530 ldxa [%g1 + %g2] ASI, %l1; \
531 mov 0x18, %g5; \
532 ldxa [%g1 + %g3] ASI, %l2; \
533 ldxa [%g1 + %g5] ASI, %l3; \
534 add %g1, 0x20, %g1; \
535 ldxa [%g1 + %g0] ASI, %l4; \
536 ldxa [%g1 + %g2] ASI, %l5; \
537 ldxa [%g1 + %g3] ASI, %l6; \
538 ldxa [%g1 + %g5] ASI, %l7; \
539 add %g1, 0x20, %g1; \
540 ldxa [%g1 + %g0] ASI, %i0; \
541 ldxa [%g1 + %g2] ASI, %i1; \
542 ldxa [%g1 + %g3] ASI, %i2; \
543 ldxa [%g1 + %g5] ASI, %i3; \
544 add %g1, 0x20, %g1; \
545 ldxa [%g1 + %g0] ASI, %i4; \
546 ldxa [%g1 + %g2] ASI, %i5; \
547 ldxa [%g1 + %g3] ASI, %i6; \
548 ldxa [%g1 + %g5] ASI, %i7; \
549 restored; \
550 retry; nop; nop; nop; nop; \
551 b,a,pt %xcc, fill_fixup_dax; \
552 b,a,pt %xcc, fill_fixup_mna; \
553 b,a,pt %xcc, fill_fixup;
554
555#define FILL_1_GENERIC_RTRAP \
556user_rtt_fill_64bit: \
557 ldxa [%sp + STACK_BIAS + 0x00] %asi, %l0; \
558 ldxa [%sp + STACK_BIAS + 0x08] %asi, %l1; \
559 ldxa [%sp + STACK_BIAS + 0x10] %asi, %l2; \
560 ldxa [%sp + STACK_BIAS + 0x18] %asi, %l3; \
561 ldxa [%sp + STACK_BIAS + 0x20] %asi, %l4; \
562 ldxa [%sp + STACK_BIAS + 0x28] %asi, %l5; \
563 ldxa [%sp + STACK_BIAS + 0x30] %asi, %l6; \
564 ldxa [%sp + STACK_BIAS + 0x38] %asi, %l7; \
565 ldxa [%sp + STACK_BIAS + 0x40] %asi, %i0; \
566 ldxa [%sp + STACK_BIAS + 0x48] %asi, %i1; \
567 ldxa [%sp + STACK_BIAS + 0x50] %asi, %i2; \
568 ldxa [%sp + STACK_BIAS + 0x58] %asi, %i3; \
569 ldxa [%sp + STACK_BIAS + 0x60] %asi, %i4; \
570 ldxa [%sp + STACK_BIAS + 0x68] %asi, %i5; \
571 ldxa [%sp + STACK_BIAS + 0x70] %asi, %i6; \
572 ldxa [%sp + STACK_BIAS + 0x78] %asi, %i7; \
573 ba,pt %xcc, user_rtt_pre_restore; \
574 restored; \
575 nop; nop; nop; nop; nop; nop; \
576 nop; nop; nop; nop; nop; \
577 ba,a,pt %xcc, user_rtt_fill_fixup; \
578 ba,a,pt %xcc, user_rtt_fill_fixup; \
579 ba,a,pt %xcc, user_rtt_fill_fixup;
580
581
582/* Normal 32bit fill */
583#define FILL_2_GENERIC(ASI) \
584 srl %sp, 0, %sp; \
585 lduwa [%sp + %g0] ASI, %l0; \
586 mov 0x04, %g2; \
587 mov 0x08, %g3; \
588 lduwa [%sp + %g2] ASI, %l1; \
589 mov 0x0c, %g5; \
590 lduwa [%sp + %g3] ASI, %l2; \
591 lduwa [%sp + %g5] ASI, %l3; \
592 add %sp, 0x10, %g1; \
593 lduwa [%g1 + %g0] ASI, %l4; \
594 lduwa [%g1 + %g2] ASI, %l5; \
595 lduwa [%g1 + %g3] ASI, %l6; \
596 lduwa [%g1 + %g5] ASI, %l7; \
597 add %g1, 0x10, %g1; \
598 lduwa [%g1 + %g0] ASI, %i0; \
599 lduwa [%g1 + %g2] ASI, %i1; \
600 lduwa [%g1 + %g3] ASI, %i2; \
601 lduwa [%g1 + %g5] ASI, %i3; \
602 add %g1, 0x10, %g1; \
603 lduwa [%g1 + %g0] ASI, %i4; \
604 lduwa [%g1 + %g2] ASI, %i5; \
605 lduwa [%g1 + %g3] ASI, %i6; \
606 lduwa [%g1 + %g5] ASI, %i7; \
607 restored; \
608 retry; nop; nop; nop; nop; \
609 b,a,pt %xcc, fill_fixup_dax; \
610 b,a,pt %xcc, fill_fixup_mna; \
611 b,a,pt %xcc, fill_fixup;
612
613#define FILL_2_GENERIC_RTRAP \
614user_rtt_fill_32bit: \
615 srl %sp, 0, %sp; \
616 lduwa [%sp + 0x00] %asi, %l0; \
617 lduwa [%sp + 0x04] %asi, %l1; \
618 lduwa [%sp + 0x08] %asi, %l2; \
619 lduwa [%sp + 0x0c] %asi, %l3; \
620 lduwa [%sp + 0x10] %asi, %l4; \
621 lduwa [%sp + 0x14] %asi, %l5; \
622 lduwa [%sp + 0x18] %asi, %l6; \
623 lduwa [%sp + 0x1c] %asi, %l7; \
624 lduwa [%sp + 0x20] %asi, %i0; \
625 lduwa [%sp + 0x24] %asi, %i1; \
626 lduwa [%sp + 0x28] %asi, %i2; \
627 lduwa [%sp + 0x2c] %asi, %i3; \
628 lduwa [%sp + 0x30] %asi, %i4; \
629 lduwa [%sp + 0x34] %asi, %i5; \
630 lduwa [%sp + 0x38] %asi, %i6; \
631 lduwa [%sp + 0x3c] %asi, %i7; \
632 ba,pt %xcc, user_rtt_pre_restore; \
633 restored; \
634 nop; nop; nop; nop; nop; \
635 nop; nop; nop; nop; nop; \
636 ba,a,pt %xcc, user_rtt_fill_fixup; \
637 ba,a,pt %xcc, user_rtt_fill_fixup; \
638 ba,a,pt %xcc, user_rtt_fill_fixup;
639
640
641#define FILL_1_NORMAL FILL_1_GENERIC(ASI_AIUP)
642#define FILL_2_NORMAL FILL_2_GENERIC(ASI_AIUP)
643#define FILL_3_NORMAL FILL_0_NORMAL
644#define FILL_4_NORMAL FILL_0_NORMAL
645#define FILL_5_NORMAL FILL_0_NORMAL
646#define FILL_6_NORMAL FILL_0_NORMAL
647#define FILL_7_NORMAL FILL_0_NORMAL
648
649#define FILL_0_OTHER FILL_0_NORMAL
650#define FILL_1_OTHER FILL_1_GENERIC(ASI_AIUS)
651#define FILL_2_OTHER FILL_2_GENERIC(ASI_AIUS)
652#define FILL_3_OTHER FILL_3_NORMAL
653#define FILL_4_OTHER FILL_4_NORMAL
654#define FILL_5_OTHER FILL_5_NORMAL
655#define FILL_6_OTHER FILL_6_NORMAL
656#define FILL_7_OTHER FILL_7_NORMAL
657
658#endif /* !(_SPARC64_TTABLE_H) */
diff --git a/include/asm-sparc64/types.h b/include/asm-sparc64/types.h
index b27ccc85202f..cfbfad5043eb 100644
--- a/include/asm-sparc64/types.h
+++ b/include/asm-sparc64/types.h
@@ -1,34 +1 @@
1#ifndef _SPARC64_TYPES_H #include <asm-sparc/types.h>
2#define _SPARC64_TYPES_H
3
4/*
5 * This file is never included by application software unless
6 * explicitly requested (e.g., via linux/types.h) in which case the
7 * application is Linux specific so (user-) name space pollution is
8 * not a major issue. However, for interoperability, libraries still
9 * need to be careful to avoid a name clashes.
10 */
11#include <asm-generic/int-l64.h>
12
13#ifndef __ASSEMBLY__
14
15typedef unsigned short umode_t;
16
17#endif /* __ASSEMBLY__ */
18
19#ifdef __KERNEL__
20
21#define BITS_PER_LONG 64
22
23#ifndef __ASSEMBLY__
24
25/* Dma addresses come in generic and 64-bit flavours. */
26
27typedef u32 dma_addr_t;
28typedef u64 dma64_addr_t;
29
30#endif /* __ASSEMBLY__ */
31
32#endif /* __KERNEL__ */
33
34#endif /* defined(_SPARC64_TYPES_H) */
diff --git a/include/asm-sparc64/uaccess.h b/include/asm-sparc64/uaccess.h
index 5fcbaf68c3f6..2872d22844f3 100644
--- a/include/asm-sparc64/uaccess.h
+++ b/include/asm-sparc64/uaccess.h
@@ -1,273 +1 @@
1#ifndef _ASM_UACCESS_H #include <asm-sparc/uaccess.h>
2#define _ASM_UACCESS_H
3
4/*
5 * User space memory access functions
6 */
7
8#ifdef __KERNEL__
9#include <linux/compiler.h>
10#include <linux/sched.h>
11#include <linux/string.h>
12#include <asm/asi.h>
13#include <asm/system.h>
14#include <asm/spitfire.h>
15#include <asm-generic/uaccess.h>
16#endif
17
18#ifndef __ASSEMBLY__
19
20/*
21 * Sparc64 is segmented, though more like the M68K than the I386.
22 * We use the secondary ASI to address user memory, which references a
23 * completely different VM map, thus there is zero chance of the user
24 * doing something queer and tricking us into poking kernel memory.
25 *
26 * What is left here is basically what is needed for the other parts of
27 * the kernel that expect to be able to manipulate, erum, "segments".
28 * Or perhaps more properly, permissions.
29 *
30 * "For historical reasons, these macros are grossly misnamed." -Linus
31 */
32
33#define KERNEL_DS ((mm_segment_t) { ASI_P })
34#define USER_DS ((mm_segment_t) { ASI_AIUS }) /* har har har */
35
36#define VERIFY_READ 0
37#define VERIFY_WRITE 1
38
39#define get_fs() ((mm_segment_t) { get_thread_current_ds() })
40#define get_ds() (KERNEL_DS)
41
42#define segment_eq(a,b) ((a).seg == (b).seg)
43
44#define set_fs(val) \
45do { \
46 set_thread_current_ds((val).seg); \
47 __asm__ __volatile__ ("wr %%g0, %0, %%asi" : : "r" ((val).seg)); \
48} while(0)
49
50static inline int __access_ok(const void __user * addr, unsigned long size)
51{
52 return 1;
53}
54
55static inline int access_ok(int type, const void __user * addr, unsigned long size)
56{
57 return 1;
58}
59
60/*
61 * The exception table consists of pairs of addresses: the first is the
62 * address of an instruction that is allowed to fault, and the second is
63 * the address at which the program should continue. No registers are
64 * modified, so it is entirely up to the continuation code to figure out
65 * what to do.
66 *
67 * All the routines below use bits of fixup code that are out of line
68 * with the main instruction path. This means when everything is well,
69 * we don't even have to jump over them. Further, they do not intrude
70 * on our cache or tlb entries.
71 */
72
73struct exception_table_entry {
74 unsigned int insn, fixup;
75};
76
77extern void __ret_efault(void);
78extern void __retl_efault(void);
79
80/* Uh, these should become the main single-value transfer routines..
81 * They automatically use the right size if we just have the right
82 * pointer type..
83 *
84 * This gets kind of ugly. We want to return _two_ values in "get_user()"
85 * and yet we don't want to do any pointers, because that is too much
86 * of a performance impact. Thus we have a few rather ugly macros here,
87 * and hide all the ugliness from the user.
88 */
89#define put_user(x,ptr) ({ \
90unsigned long __pu_addr = (unsigned long)(ptr); \
91__chk_user_ptr(ptr); \
92__put_user_nocheck((__typeof__(*(ptr)))(x),__pu_addr,sizeof(*(ptr))); })
93
94#define get_user(x,ptr) ({ \
95unsigned long __gu_addr = (unsigned long)(ptr); \
96__chk_user_ptr(ptr); \
97__get_user_nocheck((x),__gu_addr,sizeof(*(ptr)),__typeof__(*(ptr))); })
98
99#define __put_user(x,ptr) put_user(x,ptr)
100#define __get_user(x,ptr) get_user(x,ptr)
101
102struct __large_struct { unsigned long buf[100]; };
103#define __m(x) ((struct __large_struct *)(x))
104
105#define __put_user_nocheck(data,addr,size) ({ \
106register int __pu_ret; \
107switch (size) { \
108case 1: __put_user_asm(data,b,addr,__pu_ret); break; \
109case 2: __put_user_asm(data,h,addr,__pu_ret); break; \
110case 4: __put_user_asm(data,w,addr,__pu_ret); break; \
111case 8: __put_user_asm(data,x,addr,__pu_ret); break; \
112default: __pu_ret = __put_user_bad(); break; \
113} __pu_ret; })
114
115#define __put_user_asm(x,size,addr,ret) \
116__asm__ __volatile__( \
117 "/* Put user asm, inline. */\n" \
118"1:\t" "st"#size "a %1, [%2] %%asi\n\t" \
119 "clr %0\n" \
120"2:\n\n\t" \
121 ".section .fixup,#alloc,#execinstr\n\t" \
122 ".align 4\n" \
123"3:\n\t" \
124 "sethi %%hi(2b), %0\n\t" \
125 "jmpl %0 + %%lo(2b), %%g0\n\t" \
126 " mov %3, %0\n\n\t" \
127 ".previous\n\t" \
128 ".section __ex_table,\"a\"\n\t" \
129 ".align 4\n\t" \
130 ".word 1b, 3b\n\t" \
131 ".previous\n\n\t" \
132 : "=r" (ret) : "r" (x), "r" (__m(addr)), \
133 "i" (-EFAULT))
134
135extern int __put_user_bad(void);
136
137#define __get_user_nocheck(data,addr,size,type) ({ \
138register int __gu_ret; \
139register unsigned long __gu_val; \
140switch (size) { \
141case 1: __get_user_asm(__gu_val,ub,addr,__gu_ret); break; \
142case 2: __get_user_asm(__gu_val,uh,addr,__gu_ret); break; \
143case 4: __get_user_asm(__gu_val,uw,addr,__gu_ret); break; \
144case 8: __get_user_asm(__gu_val,x,addr,__gu_ret); break; \
145default: __gu_val = 0; __gu_ret = __get_user_bad(); break; \
146} data = (type) __gu_val; __gu_ret; })
147
148#define __get_user_nocheck_ret(data,addr,size,type,retval) ({ \
149register unsigned long __gu_val __asm__ ("l1"); \
150switch (size) { \
151case 1: __get_user_asm_ret(__gu_val,ub,addr,retval); break; \
152case 2: __get_user_asm_ret(__gu_val,uh,addr,retval); break; \
153case 4: __get_user_asm_ret(__gu_val,uw,addr,retval); break; \
154case 8: __get_user_asm_ret(__gu_val,x,addr,retval); break; \
155default: if (__get_user_bad()) return retval; \
156} data = (type) __gu_val; })
157
158#define __get_user_asm(x,size,addr,ret) \
159__asm__ __volatile__( \
160 "/* Get user asm, inline. */\n" \
161"1:\t" "ld"#size "a [%2] %%asi, %1\n\t" \
162 "clr %0\n" \
163"2:\n\n\t" \
164 ".section .fixup,#alloc,#execinstr\n\t" \
165 ".align 4\n" \
166"3:\n\t" \
167 "sethi %%hi(2b), %0\n\t" \
168 "clr %1\n\t" \
169 "jmpl %0 + %%lo(2b), %%g0\n\t" \
170 " mov %3, %0\n\n\t" \
171 ".previous\n\t" \
172 ".section __ex_table,\"a\"\n\t" \
173 ".align 4\n\t" \
174 ".word 1b, 3b\n\n\t" \
175 ".previous\n\t" \
176 : "=r" (ret), "=r" (x) : "r" (__m(addr)), \
177 "i" (-EFAULT))
178
179#define __get_user_asm_ret(x,size,addr,retval) \
180if (__builtin_constant_p(retval) && retval == -EFAULT) \
181__asm__ __volatile__( \
182 "/* Get user asm ret, inline. */\n" \
183"1:\t" "ld"#size "a [%1] %%asi, %0\n\n\t" \
184 ".section __ex_table,\"a\"\n\t" \
185 ".align 4\n\t" \
186 ".word 1b,__ret_efault\n\n\t" \
187 ".previous\n\t" \
188 : "=r" (x) : "r" (__m(addr))); \
189else \
190__asm__ __volatile__( \
191 "/* Get user asm ret, inline. */\n" \
192"1:\t" "ld"#size "a [%1] %%asi, %0\n\n\t" \
193 ".section .fixup,#alloc,#execinstr\n\t" \
194 ".align 4\n" \
195"3:\n\t" \
196 "ret\n\t" \
197 " restore %%g0, %2, %%o0\n\n\t" \
198 ".previous\n\t" \
199 ".section __ex_table,\"a\"\n\t" \
200 ".align 4\n\t" \
201 ".word 1b, 3b\n\n\t" \
202 ".previous\n\t" \
203 : "=r" (x) : "r" (__m(addr)), "i" (retval))
204
205extern int __get_user_bad(void);
206
207extern unsigned long __must_check ___copy_from_user(void *to,
208 const void __user *from,
209 unsigned long size);
210extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
211 unsigned long size);
212static inline unsigned long __must_check
213copy_from_user(void *to, const void __user *from, unsigned long size)
214{
215 unsigned long ret = ___copy_from_user(to, from, size);
216
217 if (unlikely(ret))
218 ret = copy_from_user_fixup(to, from, size);
219 return ret;
220}
221#define __copy_from_user copy_from_user
222
223extern unsigned long __must_check ___copy_to_user(void __user *to,
224 const void *from,
225 unsigned long size);
226extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
227 unsigned long size);
228static inline unsigned long __must_check
229copy_to_user(void __user *to, const void *from, unsigned long size)
230{
231 unsigned long ret = ___copy_to_user(to, from, size);
232
233 if (unlikely(ret))
234 ret = copy_to_user_fixup(to, from, size);
235 return ret;
236}
237#define __copy_to_user copy_to_user
238
239extern unsigned long __must_check ___copy_in_user(void __user *to,
240 const void __user *from,
241 unsigned long size);
242extern unsigned long copy_in_user_fixup(void __user *to, void __user *from,
243 unsigned long size);
244static inline unsigned long __must_check
245copy_in_user(void __user *to, void __user *from, unsigned long size)
246{
247 unsigned long ret = ___copy_in_user(to, from, size);
248
249 if (unlikely(ret))
250 ret = copy_in_user_fixup(to, from, size);
251 return ret;
252}
253#define __copy_in_user copy_in_user
254
255extern unsigned long __must_check __clear_user(void __user *, unsigned long);
256
257#define clear_user __clear_user
258
259extern long __must_check __strncpy_from_user(char *dest, const char __user *src, long count);
260
261#define strncpy_from_user __strncpy_from_user
262
263extern long __strlen_user(const char __user *);
264extern long __strnlen_user(const char __user *, long len);
265
266#define strlen_user __strlen_user
267#define strnlen_user __strnlen_user
268#define __copy_to_user_inatomic __copy_to_user
269#define __copy_from_user_inatomic __copy_from_user
270
271#endif /* __ASSEMBLY__ */
272
273#endif /* _ASM_UACCESS_H */
diff --git a/include/asm-sparc64/uctx.h b/include/asm-sparc64/uctx.h
index dc937c75ffdd..9e1b5794b07f 100644
--- a/include/asm-sparc64/uctx.h
+++ b/include/asm-sparc64/uctx.h
@@ -1,71 +1 @@
1/* #include <asm-sparc/uctx.h>
2 * uctx.h: Sparc64 {set,get}context() register state layouts.
3 *
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef __SPARC64_UCTX_H
8#define __SPARC64_UCTX_H
9
10#define MC_TSTATE 0
11#define MC_PC 1
12#define MC_NPC 2
13#define MC_Y 3
14#define MC_G1 4
15#define MC_G2 5
16#define MC_G3 6
17#define MC_G4 7
18#define MC_G5 8
19#define MC_G6 9
20#define MC_G7 10
21#define MC_O0 11
22#define MC_O1 12
23#define MC_O2 13
24#define MC_O3 14
25#define MC_O4 15
26#define MC_O5 16
27#define MC_O6 17
28#define MC_O7 18
29#define MC_NGREG 19
30
31typedef unsigned long mc_greg_t;
32typedef mc_greg_t mc_gregset_t[MC_NGREG];
33
34#define MC_MAXFPQ 16
35struct mc_fq {
36 unsigned long *mcfq_addr;
37 unsigned int mcfq_insn;
38};
39
40struct mc_fpu {
41 union {
42 unsigned int sregs[32];
43 unsigned long dregs[32];
44 long double qregs[16];
45 } mcfpu_fregs;
46 unsigned long mcfpu_fsr;
47 unsigned long mcfpu_fprs;
48 unsigned long mcfpu_gsr;
49 struct mc_fq *mcfpu_fq;
50 unsigned char mcfpu_qcnt;
51 unsigned char mcfpu_qentsz;
52 unsigned char mcfpu_enab;
53};
54typedef struct mc_fpu mc_fpu_t;
55
56typedef struct {
57 mc_gregset_t mc_gregs;
58 mc_greg_t mc_fp;
59 mc_greg_t mc_i7;
60 mc_fpu_t mc_fpregs;
61} mcontext_t;
62
63struct ucontext {
64 struct ucontext *uc_link;
65 unsigned long uc_flags;
66 sigset_t uc_sigmask;
67 mcontext_t uc_mcontext;
68};
69typedef struct ucontext ucontext_t;
70
71#endif /* __SPARC64_UCTX_H */
diff --git a/include/asm-sparc64/unaligned.h b/include/asm-sparc64/unaligned.h
index edcebb09441e..19fbf9508acf 100644
--- a/include/asm-sparc64/unaligned.h
+++ b/include/asm-sparc64/unaligned.h
@@ -1,10 +1 @@
1#ifndef _ASM_SPARC64_UNALIGNED_H #include <asm-sparc/unaligned.h>
2#define _ASM_SPARC64_UNALIGNED_H
3
4#include <linux/unaligned/be_struct.h>
5#include <linux/unaligned/le_byteshift.h>
6#include <linux/unaligned/generic.h>
7#define get_unaligned __get_unaligned_be
8#define put_unaligned __put_unaligned_be
9
10#endif /* _ASM_SPARC64_UNALIGNED_H */
diff --git a/include/asm-sparc64/unistd.h b/include/asm-sparc64/unistd.h
index 13be4453a1f0..ad86e0b7a455 100644
--- a/include/asm-sparc64/unistd.h
+++ b/include/asm-sparc64/unistd.h
@@ -1,373 +1 @@
1#ifndef _SPARC64_UNISTD_H #include <asm-sparc/unistd.h>
2#define _SPARC64_UNISTD_H
3
4/*
5 * System calls under the Sparc.
6 *
7 * Don't be scared by the ugly clobbers, it is the only way I can
8 * think of right now to force the arguments into fixed registers
9 * before the trap into the system call with gcc 'asm' statements.
10 *
11 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
12 *
13 * SunOS compatibility based upon preliminary work which is:
14 *
15 * Copyright (C) 1995 Adrian M. Rodriguez (adrian@remus.rutgers.edu)
16 */
17
18#define __NR_restart_syscall 0 /* Linux Specific */
19#define __NR_exit 1 /* Common */
20#define __NR_fork 2 /* Common */
21#define __NR_read 3 /* Common */
22#define __NR_write 4 /* Common */
23#define __NR_open 5 /* Common */
24#define __NR_close 6 /* Common */
25#define __NR_wait4 7 /* Common */
26#define __NR_creat 8 /* Common */
27#define __NR_link 9 /* Common */
28#define __NR_unlink 10 /* Common */
29#define __NR_execv 11 /* SunOS Specific */
30#define __NR_chdir 12 /* Common */
31#define __NR_chown 13 /* Common */
32#define __NR_mknod 14 /* Common */
33#define __NR_chmod 15 /* Common */
34#define __NR_lchown 16 /* Common */
35#define __NR_brk 17 /* Common */
36#define __NR_perfctr 18 /* Performance counter operations */
37#define __NR_lseek 19 /* Common */
38#define __NR_getpid 20 /* Common */
39#define __NR_capget 21 /* Linux Specific */
40#define __NR_capset 22 /* Linux Specific */
41#define __NR_setuid 23 /* Implemented via setreuid in SunOS */
42#define __NR_getuid 24 /* Common */
43#define __NR_vmsplice 25 /* ENOSYS under SunOS */
44#define __NR_ptrace 26 /* Common */
45#define __NR_alarm 27 /* Implemented via setitimer in SunOS */
46#define __NR_sigaltstack 28 /* Common */
47#define __NR_pause 29 /* Is sigblock(0)->sigpause() in SunOS */
48#define __NR_utime 30 /* Implemented via utimes() under SunOS */
49/* #define __NR_lchown32 31 Linux sparc32 specific */
50/* #define __NR_fchown32 32 Linux sparc32 specific */
51#define __NR_access 33 /* Common */
52#define __NR_nice 34 /* Implemented via get/setpriority() in SunOS */
53/* #define __NR_chown32 35 Linux sparc32 specific */
54#define __NR_sync 36 /* Common */
55#define __NR_kill 37 /* Common */
56#define __NR_stat 38 /* Common */
57#define __NR_sendfile 39 /* Linux Specific */
58#define __NR_lstat 40 /* Common */
59#define __NR_dup 41 /* Common */
60#define __NR_pipe 42 /* Common */
61#define __NR_times 43 /* Implemented via getrusage() in SunOS */
62/* #define __NR_getuid32 44 Linux sparc32 specific */
63#define __NR_umount2 45 /* Linux Specific */
64#define __NR_setgid 46 /* Implemented via setregid() in SunOS */
65#define __NR_getgid 47 /* Common */
66#define __NR_signal 48 /* Implemented via sigvec() in SunOS */
67#define __NR_geteuid 49 /* SunOS calls getuid() */
68#define __NR_getegid 50 /* SunOS calls getgid() */
69#define __NR_acct 51 /* Common */
70#define __NR_memory_ordering 52 /* Linux Specific */
71/* #define __NR_getgid32 53 Linux sparc32 specific */
72#define __NR_ioctl 54 /* Common */
73#define __NR_reboot 55 /* Common */
74/* #define __NR_mmap2 56 Linux sparc32 Specific */
75#define __NR_symlink 57 /* Common */
76#define __NR_readlink 58 /* Common */
77#define __NR_execve 59 /* Common */
78#define __NR_umask 60 /* Common */
79#define __NR_chroot 61 /* Common */
80#define __NR_fstat 62 /* Common */
81#define __NR_fstat64 63 /* Linux Specific */
82#define __NR_getpagesize 64 /* Common */
83#define __NR_msync 65 /* Common in newer 1.3.x revs... */
84#define __NR_vfork 66 /* Common */
85#define __NR_pread64 67 /* Linux Specific */
86#define __NR_pwrite64 68 /* Linux Specific */
87/* #define __NR_geteuid32 69 Linux sparc32, sbrk under SunOS */
88/* #define __NR_getegid32 70 Linux sparc32, sstk under SunOS */
89#define __NR_mmap 71 /* Common */
90/* #define __NR_setreuid32 72 Linux sparc32, vadvise under SunOS */
91#define __NR_munmap 73 /* Common */
92#define __NR_mprotect 74 /* Common */
93#define __NR_madvise 75 /* Common */
94#define __NR_vhangup 76 /* Common */
95/* #define __NR_truncate64 77 Linux sparc32 Specific */
96#define __NR_mincore 78 /* Common */
97#define __NR_getgroups 79 /* Common */
98#define __NR_setgroups 80 /* Common */
99#define __NR_getpgrp 81 /* Common */
100/* #define __NR_setgroups32 82 Linux sparc32, setpgrp under SunOS */
101#define __NR_setitimer 83 /* Common */
102/* #define __NR_ftruncate64 84 Linux sparc32 Specific */
103#define __NR_swapon 85 /* Common */
104#define __NR_getitimer 86 /* Common */
105/* #define __NR_setuid32 87 Linux sparc32, gethostname under SunOS */
106#define __NR_sethostname 88 /* Common */
107/* #define __NR_setgid32 89 Linux sparc32, getdtablesize under SunOS */
108#define __NR_dup2 90 /* Common */
109/* #define __NR_setfsuid32 91 Linux sparc32, getdopt under SunOS */
110#define __NR_fcntl 92 /* Common */
111#define __NR_select 93 /* Common */
112/* #define __NR_setfsgid32 94 Linux sparc32, setdopt under SunOS */
113#define __NR_fsync 95 /* Common */
114#define __NR_setpriority 96 /* Common */
115#define __NR_socket 97 /* Common */
116#define __NR_connect 98 /* Common */
117#define __NR_accept 99 /* Common */
118#define __NR_getpriority 100 /* Common */
119#define __NR_rt_sigreturn 101 /* Linux Specific */
120#define __NR_rt_sigaction 102 /* Linux Specific */
121#define __NR_rt_sigprocmask 103 /* Linux Specific */
122#define __NR_rt_sigpending 104 /* Linux Specific */
123#define __NR_rt_sigtimedwait 105 /* Linux Specific */
124#define __NR_rt_sigqueueinfo 106 /* Linux Specific */
125#define __NR_rt_sigsuspend 107 /* Linux Specific */
126#define __NR_setresuid 108 /* Linux Specific, sigvec under SunOS */
127#define __NR_getresuid 109 /* Linux Specific, sigblock under SunOS */
128#define __NR_setresgid 110 /* Linux Specific, sigsetmask under SunOS */
129#define __NR_getresgid 111 /* Linux Specific, sigpause under SunOS */
130/* #define __NR_setregid32 75 Linux sparc32, sigstack under SunOS */
131#define __NR_recvmsg 113 /* Common */
132#define __NR_sendmsg 114 /* Common */
133/* #define __NR_getgroups32 115 Linux sparc32, vtrace under SunOS */
134#define __NR_gettimeofday 116 /* Common */
135#define __NR_getrusage 117 /* Common */
136#define __NR_getsockopt 118 /* Common */
137#define __NR_getcwd 119 /* Linux Specific */
138#define __NR_readv 120 /* Common */
139#define __NR_writev 121 /* Common */
140#define __NR_settimeofday 122 /* Common */
141#define __NR_fchown 123 /* Common */
142#define __NR_fchmod 124 /* Common */
143#define __NR_recvfrom 125 /* Common */
144#define __NR_setreuid 126 /* Common */
145#define __NR_setregid 127 /* Common */
146#define __NR_rename 128 /* Common */
147#define __NR_truncate 129 /* Common */
148#define __NR_ftruncate 130 /* Common */
149#define __NR_flock 131 /* Common */
150#define __NR_lstat64 132 /* Linux Specific */
151#define __NR_sendto 133 /* Common */
152#define __NR_shutdown 134 /* Common */
153#define __NR_socketpair 135 /* Common */
154#define __NR_mkdir 136 /* Common */
155#define __NR_rmdir 137 /* Common */
156#define __NR_utimes 138 /* SunOS Specific */
157#define __NR_stat64 139 /* Linux Specific */
158#define __NR_sendfile64 140 /* adjtime under SunOS */
159#define __NR_getpeername 141 /* Common */
160#define __NR_futex 142 /* gethostid under SunOS */
161#define __NR_gettid 143 /* ENOSYS under SunOS */
162#define __NR_getrlimit 144 /* Common */
163#define __NR_setrlimit 145 /* Common */
164#define __NR_pivot_root 146 /* Linux Specific, killpg under SunOS */
165#define __NR_prctl 147 /* ENOSYS under SunOS */
166#define __NR_pciconfig_read 148 /* ENOSYS under SunOS */
167#define __NR_pciconfig_write 149 /* ENOSYS under SunOS */
168#define __NR_getsockname 150 /* Common */
169#define __NR_inotify_init 151 /* Linux specific */
170#define __NR_inotify_add_watch 152 /* Linux specific */
171#define __NR_poll 153 /* Common */
172#define __NR_getdents64 154 /* Linux specific */
173/* #define __NR_fcntl64 155 Linux sparc32 Specific */
174#define __NR_inotify_rm_watch 156 /* Linux specific */
175#define __NR_statfs 157 /* Common */
176#define __NR_fstatfs 158 /* Common */
177#define __NR_umount 159 /* Common */
178#define __NR_sched_set_affinity 160 /* Linux specific, async_daemon under SunOS */
179#define __NR_sched_get_affinity 161 /* Linux specific, getfh under SunOS */
180#define __NR_getdomainname 162 /* SunOS Specific */
181#define __NR_setdomainname 163 /* Common */
182#define __NR_utrap_install 164 /* SYSV ABI/v9 required */
183#define __NR_quotactl 165 /* Common */
184#define __NR_set_tid_address 166 /* Linux specific, exportfs under SunOS */
185#define __NR_mount 167 /* Common */
186#define __NR_ustat 168 /* Common */
187#define __NR_setxattr 169 /* SunOS: semsys */
188#define __NR_lsetxattr 170 /* SunOS: msgsys */
189#define __NR_fsetxattr 171 /* SunOS: shmsys */
190#define __NR_getxattr 172 /* SunOS: auditsys */
191#define __NR_lgetxattr 173 /* SunOS: rfssys */
192#define __NR_getdents 174 /* Common */
193#define __NR_setsid 175 /* Common */
194#define __NR_fchdir 176 /* Common */
195#define __NR_fgetxattr 177 /* SunOS: fchroot */
196#define __NR_listxattr 178 /* SunOS: vpixsys */
197#define __NR_llistxattr 179 /* SunOS: aioread */
198#define __NR_flistxattr 180 /* SunOS: aiowrite */
199#define __NR_removexattr 181 /* SunOS: aiowait */
200#define __NR_lremovexattr 182 /* SunOS: aiocancel */
201#define __NR_sigpending 183 /* Common */
202#define __NR_query_module 184 /* Linux Specific */
203#define __NR_setpgid 185 /* Common */
204#define __NR_fremovexattr 186 /* SunOS: pathconf */
205#define __NR_tkill 187 /* SunOS: fpathconf */
206#define __NR_exit_group 188 /* Linux specific, sysconf undef SunOS */
207#define __NR_uname 189 /* Linux Specific */
208#define __NR_init_module 190 /* Linux Specific */
209#define __NR_personality 191 /* Linux Specific */
210#define __NR_remap_file_pages 192 /* Linux Specific */
211#define __NR_epoll_create 193 /* Linux Specific */
212#define __NR_epoll_ctl 194 /* Linux Specific */
213#define __NR_epoll_wait 195 /* Linux Specific */
214#define __NR_ioprio_set 196 /* Linux Specific */
215#define __NR_getppid 197 /* Linux Specific */
216#define __NR_sigaction 198 /* Linux Specific */
217#define __NR_sgetmask 199 /* Linux Specific */
218#define __NR_ssetmask 200 /* Linux Specific */
219#define __NR_sigsuspend 201 /* Linux Specific */
220#define __NR_oldlstat 202 /* Linux Specific */
221#define __NR_uselib 203 /* Linux Specific */
222#define __NR_readdir 204 /* Linux Specific */
223#define __NR_readahead 205 /* Linux Specific */
224#define __NR_socketcall 206 /* Linux Specific */
225#define __NR_syslog 207 /* Linux Specific */
226#define __NR_lookup_dcookie 208 /* Linux Specific */
227#define __NR_fadvise64 209 /* Linux Specific */
228#define __NR_fadvise64_64 210 /* Linux Specific */
229#define __NR_tgkill 211 /* Linux Specific */
230#define __NR_waitpid 212 /* Linux Specific */
231#define __NR_swapoff 213 /* Linux Specific */
232#define __NR_sysinfo 214 /* Linux Specific */
233#define __NR_ipc 215 /* Linux Specific */
234#define __NR_sigreturn 216 /* Linux Specific */
235#define __NR_clone 217 /* Linux Specific */
236#define __NR_ioprio_get 218 /* Linux Specific */
237#define __NR_adjtimex 219 /* Linux Specific */
238#define __NR_sigprocmask 220 /* Linux Specific */
239#define __NR_create_module 221 /* Linux Specific */
240#define __NR_delete_module 222 /* Linux Specific */
241#define __NR_get_kernel_syms 223 /* Linux Specific */
242#define __NR_getpgid 224 /* Linux Specific */
243#define __NR_bdflush 225 /* Linux Specific */
244#define __NR_sysfs 226 /* Linux Specific */
245#define __NR_afs_syscall 227 /* Linux Specific */
246#define __NR_setfsuid 228 /* Linux Specific */
247#define __NR_setfsgid 229 /* Linux Specific */
248#define __NR__newselect 230 /* Linux Specific */
249#ifdef __KERNEL__
250#define __NR_time 231 /* Linux sparc32 */
251#endif
252#define __NR_splice 232 /* Linux Specific */
253#define __NR_stime 233 /* Linux Specific */
254#define __NR_statfs64 234 /* Linux Specific */
255#define __NR_fstatfs64 235 /* Linux Specific */
256#define __NR__llseek 236 /* Linux Specific */
257#define __NR_mlock 237
258#define __NR_munlock 238
259#define __NR_mlockall 239
260#define __NR_munlockall 240
261#define __NR_sched_setparam 241
262#define __NR_sched_getparam 242
263#define __NR_sched_setscheduler 243
264#define __NR_sched_getscheduler 244
265#define __NR_sched_yield 245
266#define __NR_sched_get_priority_max 246
267#define __NR_sched_get_priority_min 247
268#define __NR_sched_rr_get_interval 248
269#define __NR_nanosleep 249
270#define __NR_mremap 250
271#define __NR__sysctl 251
272#define __NR_getsid 252
273#define __NR_fdatasync 253
274#define __NR_nfsservctl 254
275#define __NR_sync_file_range 255
276#define __NR_clock_settime 256
277#define __NR_clock_gettime 257
278#define __NR_clock_getres 258
279#define __NR_clock_nanosleep 259
280#define __NR_sched_getaffinity 260
281#define __NR_sched_setaffinity 261
282#define __NR_timer_settime 262
283#define __NR_timer_gettime 263
284#define __NR_timer_getoverrun 264
285#define __NR_timer_delete 265
286#define __NR_timer_create 266
287/* #define __NR_vserver 267 Reserved for VSERVER */
288#define __NR_io_setup 268
289#define __NR_io_destroy 269
290#define __NR_io_submit 270
291#define __NR_io_cancel 271
292#define __NR_io_getevents 272
293#define __NR_mq_open 273
294#define __NR_mq_unlink 274
295#define __NR_mq_timedsend 275
296#define __NR_mq_timedreceive 276
297#define __NR_mq_notify 277
298#define __NR_mq_getsetattr 278
299#define __NR_waitid 279
300#define __NR_tee 280
301#define __NR_add_key 281
302#define __NR_request_key 282
303#define __NR_keyctl 283
304#define __NR_openat 284
305#define __NR_mkdirat 285
306#define __NR_mknodat 286
307#define __NR_fchownat 287
308#define __NR_futimesat 288
309#define __NR_fstatat64 289
310#define __NR_unlinkat 290
311#define __NR_renameat 291
312#define __NR_linkat 292
313#define __NR_symlinkat 293
314#define __NR_readlinkat 294
315#define __NR_fchmodat 295
316#define __NR_faccessat 296
317#define __NR_pselect6 297
318#define __NR_ppoll 298
319#define __NR_unshare 299
320#define __NR_set_robust_list 300
321#define __NR_get_robust_list 301
322#define __NR_migrate_pages 302
323#define __NR_mbind 303
324#define __NR_get_mempolicy 304
325#define __NR_set_mempolicy 305
326#define __NR_kexec_load 306
327#define __NR_move_pages 307
328#define __NR_getcpu 308
329#define __NR_epoll_pwait 309
330#define __NR_utimensat 310
331#define __NR_signalfd 311
332#define __NR_timerfd_create 312
333#define __NR_eventfd 313
334#define __NR_fallocate 314
335#define __NR_timerfd_settime 315
336#define __NR_timerfd_gettime 316
337
338#define NR_SYSCALLS 317
339
340#ifdef __KERNEL__
341#define __ARCH_WANT_IPC_PARSE_VERSION
342#define __ARCH_WANT_OLD_READDIR
343#define __ARCH_WANT_STAT64
344#define __ARCH_WANT_SYS_ALARM
345#define __ARCH_WANT_SYS_GETHOSTNAME
346#define __ARCH_WANT_SYS_PAUSE
347#define __ARCH_WANT_SYS_SGETMASK
348#define __ARCH_WANT_SYS_SIGNAL
349#define __ARCH_WANT_SYS_TIME
350#define __ARCH_WANT_COMPAT_SYS_TIME
351#define __ARCH_WANT_SYS_UTIME
352#define __ARCH_WANT_SYS_WAITPID
353#define __ARCH_WANT_SYS_SOCKETCALL
354#define __ARCH_WANT_SYS_FADVISE64
355#define __ARCH_WANT_SYS_GETPGRP
356#define __ARCH_WANT_SYS_LLSEEK
357#define __ARCH_WANT_SYS_NICE
358#define __ARCH_WANT_SYS_OLDUMOUNT
359#define __ARCH_WANT_SYS_SIGPENDING
360#define __ARCH_WANT_SYS_SIGPROCMASK
361#define __ARCH_WANT_SYS_RT_SIGSUSPEND
362#define __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND
363
364/*
365 * "Conditional" syscalls
366 *
367 * What we want is __attribute__((weak,alias("sys_ni_syscall"))),
368 * but it doesn't work on all toolchains, so we just do it by hand
369 */
370#define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall")
371
372#endif /* __KERNEL__ */
373#endif /* _SPARC64_UNISTD_H */
diff --git a/include/asm-sparc64/upa.h b/include/asm-sparc64/upa.h
index 5b1633223f92..aab72930815a 100644
--- a/include/asm-sparc64/upa.h
+++ b/include/asm-sparc64/upa.h
@@ -1,109 +1 @@
1#ifndef _SPARC64_UPA_H #include <asm-sparc/upa.h>
2#define _SPARC64_UPA_H
3
4#include <asm/asi.h>
5
6/* UPA level registers and defines. */
7
8/* UPA Config Register */
9#define UPA_CONFIG_RESV 0xffffffffc0000000 /* Reserved. */
10#define UPA_CONFIG_PCON 0x000000003fc00000 /* Depth of various sys queues. */
11#define UPA_CONFIG_MID 0x00000000003e0000 /* Module ID. */
12#define UPA_CONFIG_PCAP 0x000000000001ffff /* Port Capabilities. */
13
14/* UPA Port ID Register */
15#define UPA_PORTID_FNP 0xff00000000000000 /* Hardcoded to 0xfc on ultra. */
16#define UPA_PORTID_RESV 0x00fffff800000000 /* Reserved. */
17#define UPA_PORTID_ECCVALID 0x0000000400000000 /* Zero if mod can generate ECC */
18#define UPA_PORTID_ONEREAD 0x0000000200000000 /* Set if mod generates P_RASB */
19#define UPA_PORTID_PINTRDQ 0x0000000180000000 /* # outstanding P_INT_REQ's */
20#define UPA_PORTID_PREQDQ 0x000000007e000000 /* slave-wr's to mod supported */
21#define UPA_PORTID_PREQRD 0x0000000001e00000 /* # incoming P_REQ's supported */
22#define UPA_PORTID_UPACAP 0x00000000001f0000 /* UPA capabilities of mod */
23#define UPA_PORTID_ID 0x000000000000ffff /* Module Identification bits */
24
25/* UPA I/O space accessors */
26#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
27static inline unsigned char _upa_readb(unsigned long addr)
28{
29 unsigned char ret;
30
31 __asm__ __volatile__("lduba\t[%1] %2, %0\t/* upa_readb */"
32 : "=r" (ret)
33 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
34
35 return ret;
36}
37
38static inline unsigned short _upa_readw(unsigned long addr)
39{
40 unsigned short ret;
41
42 __asm__ __volatile__("lduha\t[%1] %2, %0\t/* upa_readw */"
43 : "=r" (ret)
44 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
45
46 return ret;
47}
48
49static inline unsigned int _upa_readl(unsigned long addr)
50{
51 unsigned int ret;
52
53 __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* upa_readl */"
54 : "=r" (ret)
55 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
56
57 return ret;
58}
59
60static inline unsigned long _upa_readq(unsigned long addr)
61{
62 unsigned long ret;
63
64 __asm__ __volatile__("ldxa\t[%1] %2, %0\t/* upa_readq */"
65 : "=r" (ret)
66 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
67
68 return ret;
69}
70
71static inline void _upa_writeb(unsigned char b, unsigned long addr)
72{
73 __asm__ __volatile__("stba\t%0, [%1] %2\t/* upa_writeb */"
74 : /* no outputs */
75 : "r" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
76}
77
78static inline void _upa_writew(unsigned short w, unsigned long addr)
79{
80 __asm__ __volatile__("stha\t%0, [%1] %2\t/* upa_writew */"
81 : /* no outputs */
82 : "r" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
83}
84
85static inline void _upa_writel(unsigned int l, unsigned long addr)
86{
87 __asm__ __volatile__("stwa\t%0, [%1] %2\t/* upa_writel */"
88 : /* no outputs */
89 : "r" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
90}
91
92static inline void _upa_writeq(unsigned long q, unsigned long addr)
93{
94 __asm__ __volatile__("stxa\t%0, [%1] %2\t/* upa_writeq */"
95 : /* no outputs */
96 : "r" (q), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
97}
98
99#define upa_readb(__addr) (_upa_readb((unsigned long)(__addr)))
100#define upa_readw(__addr) (_upa_readw((unsigned long)(__addr)))
101#define upa_readl(__addr) (_upa_readl((unsigned long)(__addr)))
102#define upa_readq(__addr) (_upa_readq((unsigned long)(__addr)))
103#define upa_writeb(__b, __addr) (_upa_writeb((__b), (unsigned long)(__addr)))
104#define upa_writew(__w, __addr) (_upa_writew((__w), (unsigned long)(__addr)))
105#define upa_writel(__l, __addr) (_upa_writel((__l), (unsigned long)(__addr)))
106#define upa_writeq(__q, __addr) (_upa_writeq((__q), (unsigned long)(__addr)))
107#endif /* __KERNEL__ && !__ASSEMBLY__ */
108
109#endif /* !(_SPARC64_UPA_H) */
diff --git a/include/asm-sparc64/utrap.h b/include/asm-sparc64/utrap.h
index e49e5c46ad68..b030a41f1895 100644
--- a/include/asm-sparc64/utrap.h
+++ b/include/asm-sparc64/utrap.h
@@ -1,51 +1 @@
1/* #include <asm-sparc/utrap.h>
2 * include/asm-sparc64/utrap.h
3 *
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 */
6
7#ifndef __ASM_SPARC64_UTRAP_H
8#define __ASM_SPARC64_UTRAP_H
9
10#define UT_INSTRUCTION_EXCEPTION 1
11#define UT_INSTRUCTION_ERROR 2
12#define UT_INSTRUCTION_PROTECTION 3
13#define UT_ILLTRAP_INSTRUCTION 4
14#define UT_ILLEGAL_INSTRUCTION 5
15#define UT_PRIVILEGED_OPCODE 6
16#define UT_FP_DISABLED 7
17#define UT_FP_EXCEPTION_IEEE_754 8
18#define UT_FP_EXCEPTION_OTHER 9
19#define UT_TAG_OVERVIEW 10
20#define UT_DIVISION_BY_ZERO 11
21#define UT_DATA_EXCEPTION 12
22#define UT_DATA_ERROR 13
23#define UT_DATA_PROTECTION 14
24#define UT_MEM_ADDRESS_NOT_ALIGNED 15
25#define UT_PRIVILEGED_ACTION 16
26#define UT_ASYNC_DATA_ERROR 17
27#define UT_TRAP_INSTRUCTION_16 18
28#define UT_TRAP_INSTRUCTION_17 19
29#define UT_TRAP_INSTRUCTION_18 20
30#define UT_TRAP_INSTRUCTION_19 21
31#define UT_TRAP_INSTRUCTION_20 22
32#define UT_TRAP_INSTRUCTION_21 23
33#define UT_TRAP_INSTRUCTION_22 24
34#define UT_TRAP_INSTRUCTION_23 25
35#define UT_TRAP_INSTRUCTION_24 26
36#define UT_TRAP_INSTRUCTION_25 27
37#define UT_TRAP_INSTRUCTION_26 28
38#define UT_TRAP_INSTRUCTION_27 29
39#define UT_TRAP_INSTRUCTION_28 30
40#define UT_TRAP_INSTRUCTION_29 31
41#define UT_TRAP_INSTRUCTION_30 32
42#define UT_TRAP_INSTRUCTION_31 33
43
44#define UTH_NOCHANGE (-1)
45
46#ifndef __ASSEMBLY__
47typedef int utrap_entry_t;
48typedef void *utrap_handler_t;
49#endif /* __ASSEMBLY__ */
50
51#endif /* !(__ASM_SPARC64_PROCESSOR_H) */
diff --git a/include/asm-sparc64/vga.h b/include/asm-sparc64/vga.h
index c69d5b2ba19a..fbf4d58a56f0 100644
--- a/include/asm-sparc64/vga.h
+++ b/include/asm-sparc64/vga.h
@@ -1,33 +1 @@
1/* #include <asm-sparc/vga.h>
2 * Access to VGA videoram
3 *
4 * (c) 1998 Martin Mares <mj@ucw.cz>
5 */
6
7#ifndef _LINUX_ASM_VGA_H_
8#define _LINUX_ASM_VGA_H_
9
10#include <asm/types.h>
11
12#define VT_BUF_HAVE_RW
13
14#undef scr_writew
15#undef scr_readw
16
17static inline void scr_writew(u16 val, u16 *addr)
18{
19 BUG_ON((long) addr >= 0);
20
21 *addr = val;
22}
23
24static inline u16 scr_readw(const u16 *addr)
25{
26 BUG_ON((long) addr >= 0);
27
28 return *addr;
29}
30
31#define VGA_MAP_MEM(x,s) (x)
32
33#endif
diff --git a/include/asm-sparc64/vio.h b/include/asm-sparc64/vio.h
index d4de32f0f8af..299b26ab81a7 100644
--- a/include/asm-sparc64/vio.h
+++ b/include/asm-sparc64/vio.h
@@ -1,406 +1 @@
1#ifndef _SPARC64_VIO_H #include <asm-sparc/vio.h>
2#define _SPARC64_VIO_H
3
4#include <linux/kernel.h>
5#include <linux/device.h>
6#include <linux/mod_devicetable.h>
7#include <linux/timer.h>
8#include <linux/spinlock.h>
9#include <linux/completion.h>
10#include <linux/list.h>
11#include <linux/log2.h>
12
13#include <asm/ldc.h>
14#include <asm/mdesc.h>
15
16struct vio_msg_tag {
17 u8 type;
18#define VIO_TYPE_CTRL 0x01
19#define VIO_TYPE_DATA 0x02
20#define VIO_TYPE_ERR 0x04
21
22 u8 stype;
23#define VIO_SUBTYPE_INFO 0x01
24#define VIO_SUBTYPE_ACK 0x02
25#define VIO_SUBTYPE_NACK 0x04
26
27 u16 stype_env;
28#define VIO_VER_INFO 0x0001
29#define VIO_ATTR_INFO 0x0002
30#define VIO_DRING_REG 0x0003
31#define VIO_DRING_UNREG 0x0004
32#define VIO_RDX 0x0005
33#define VIO_PKT_DATA 0x0040
34#define VIO_DESC_DATA 0x0041
35#define VIO_DRING_DATA 0x0042
36#define VNET_MCAST_INFO 0x0101
37
38 u32 sid;
39};
40
41struct vio_rdx {
42 struct vio_msg_tag tag;
43 u64 resv[6];
44};
45
46struct vio_ver_info {
47 struct vio_msg_tag tag;
48 u16 major;
49 u16 minor;
50 u8 dev_class;
51#define VDEV_NETWORK 0x01
52#define VDEV_NETWORK_SWITCH 0x02
53#define VDEV_DISK 0x03
54#define VDEV_DISK_SERVER 0x04
55
56 u8 resv1[3];
57 u64 resv2[5];
58};
59
60struct vio_dring_register {
61 struct vio_msg_tag tag;
62 u64 dring_ident;
63 u32 num_descr;
64 u32 descr_size;
65 u16 options;
66#define VIO_TX_DRING 0x0001
67#define VIO_RX_DRING 0x0002
68 u16 resv;
69 u32 num_cookies;
70 struct ldc_trans_cookie cookies[0];
71};
72
73struct vio_dring_unregister {
74 struct vio_msg_tag tag;
75 u64 dring_ident;
76 u64 resv[5];
77};
78
79/* Data transfer modes */
80#define VIO_PKT_MODE 0x01 /* Packet based transfer */
81#define VIO_DESC_MODE 0x02 /* In-band descriptors */
82#define VIO_DRING_MODE 0x03 /* Descriptor rings */
83
84struct vio_dring_data {
85 struct vio_msg_tag tag;
86 u64 seq;
87 u64 dring_ident;
88 u32 start_idx;
89 u32 end_idx;
90 u8 state;
91#define VIO_DRING_ACTIVE 0x01
92#define VIO_DRING_STOPPED 0x02
93
94 u8 __pad1;
95 u16 __pad2;
96 u32 __pad3;
97 u64 __par4[2];
98};
99
100struct vio_dring_hdr {
101 u8 state;
102#define VIO_DESC_FREE 0x01
103#define VIO_DESC_READY 0x02
104#define VIO_DESC_ACCEPTED 0x03
105#define VIO_DESC_DONE 0x04
106 u8 ack;
107#define VIO_ACK_ENABLE 0x01
108#define VIO_ACK_DISABLE 0x00
109
110 u16 __pad1;
111 u32 __pad2;
112};
113
114/* VIO disk specific structures and defines */
115struct vio_disk_attr_info {
116 struct vio_msg_tag tag;
117 u8 xfer_mode;
118 u8 vdisk_type;
119#define VD_DISK_TYPE_SLICE 0x01 /* Slice in block device */
120#define VD_DISK_TYPE_DISK 0x02 /* Entire block device */
121 u16 resv1;
122 u32 vdisk_block_size;
123 u64 operations;
124 u64 vdisk_size;
125 u64 max_xfer_size;
126 u64 resv2[2];
127};
128
129struct vio_disk_desc {
130 struct vio_dring_hdr hdr;
131 u64 req_id;
132 u8 operation;
133#define VD_OP_BREAD 0x01 /* Block read */
134#define VD_OP_BWRITE 0x02 /* Block write */
135#define VD_OP_FLUSH 0x03 /* Flush disk contents */
136#define VD_OP_GET_WCE 0x04 /* Get write-cache status */
137#define VD_OP_SET_WCE 0x05 /* Enable/disable write-cache */
138#define VD_OP_GET_VTOC 0x06 /* Get VTOC */
139#define VD_OP_SET_VTOC 0x07 /* Set VTOC */
140#define VD_OP_GET_DISKGEOM 0x08 /* Get disk geometry */
141#define VD_OP_SET_DISKGEOM 0x09 /* Set disk geometry */
142#define VD_OP_SCSICMD 0x0a /* SCSI control command */
143#define VD_OP_GET_DEVID 0x0b /* Get device ID */
144#define VD_OP_GET_EFI 0x0c /* Get EFI */
145#define VD_OP_SET_EFI 0x0d /* Set EFI */
146 u8 slice;
147 u16 resv1;
148 u32 status;
149 u64 offset;
150 u64 size;
151 u32 ncookies;
152 u32 resv2;
153 struct ldc_trans_cookie cookies[0];
154};
155
156#define VIO_DISK_VNAME_LEN 8
157#define VIO_DISK_ALABEL_LEN 128
158#define VIO_DISK_NUM_PART 8
159
160struct vio_disk_vtoc {
161 u8 volume_name[VIO_DISK_VNAME_LEN];
162 u16 sector_size;
163 u16 num_partitions;
164 u8 ascii_label[VIO_DISK_ALABEL_LEN];
165 struct {
166 u16 id;
167 u16 perm_flags;
168 u32 resv;
169 u64 start_block;
170 u64 num_blocks;
171 } partitions[VIO_DISK_NUM_PART];
172};
173
174struct vio_disk_geom {
175 u16 num_cyl; /* Num data cylinders */
176 u16 alt_cyl; /* Num alternate cylinders */
177 u16 beg_cyl; /* Cyl off of fixed head area */
178 u16 num_hd; /* Num heads */
179 u16 num_sec; /* Num sectors */
180 u16 ifact; /* Interleave factor */
181 u16 apc; /* Alts per cylinder (SCSI) */
182 u16 rpm; /* Revolutions per minute */
183 u16 phy_cyl; /* Num physical cylinders */
184 u16 wr_skip; /* Num sects to skip, writes */
185 u16 rd_skip; /* Num sects to skip, writes */
186};
187
188struct vio_disk_devid {
189 u16 resv;
190 u16 type;
191 u32 len;
192 char id[0];
193};
194
195struct vio_disk_efi {
196 u64 lba;
197 u64 len;
198 char data[0];
199};
200
201/* VIO net specific structures and defines */
202struct vio_net_attr_info {
203 struct vio_msg_tag tag;
204 u8 xfer_mode;
205 u8 addr_type;
206#define VNET_ADDR_ETHERMAC 0x01
207 u16 ack_freq;
208 u32 resv1;
209 u64 addr;
210 u64 mtu;
211 u64 resv2[3];
212};
213
214#define VNET_NUM_MCAST 7
215
216struct vio_net_mcast_info {
217 struct vio_msg_tag tag;
218 u8 set;
219 u8 count;
220 u8 mcast_addr[VNET_NUM_MCAST * 6];
221 u32 resv;
222};
223
224struct vio_net_desc {
225 struct vio_dring_hdr hdr;
226 u32 size;
227 u32 ncookies;
228 struct ldc_trans_cookie cookies[0];
229};
230
231#define VIO_MAX_RING_COOKIES 24
232
233struct vio_dring_state {
234 u64 ident;
235 void *base;
236 u64 snd_nxt;
237 u64 rcv_nxt;
238 u32 entry_size;
239 u32 num_entries;
240 u32 prod;
241 u32 cons;
242 u32 pending;
243 int ncookies;
244 struct ldc_trans_cookie cookies[VIO_MAX_RING_COOKIES];
245};
246
247static inline void *vio_dring_cur(struct vio_dring_state *dr)
248{
249 return dr->base + (dr->entry_size * dr->prod);
250}
251
252static inline void *vio_dring_entry(struct vio_dring_state *dr,
253 unsigned int index)
254{
255 return dr->base + (dr->entry_size * index);
256}
257
258static inline u32 vio_dring_avail(struct vio_dring_state *dr,
259 unsigned int ring_size)
260{
261 BUILD_BUG_ON(!is_power_of_2(ring_size));
262
263 return (dr->pending -
264 ((dr->prod - dr->cons) & (ring_size - 1)));
265}
266
267#define VIO_MAX_TYPE_LEN 32
268#define VIO_MAX_COMPAT_LEN 64
269
270struct vio_dev {
271 u64 mp;
272 struct device_node *dp;
273
274 char type[VIO_MAX_TYPE_LEN];
275 char compat[VIO_MAX_COMPAT_LEN];
276 int compat_len;
277
278 u64 dev_no;
279
280 unsigned long channel_id;
281
282 unsigned int tx_irq;
283 unsigned int rx_irq;
284
285 struct device dev;
286};
287
288struct vio_driver {
289 struct list_head node;
290 const struct vio_device_id *id_table;
291 int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
292 int (*remove)(struct vio_dev *dev);
293 void (*shutdown)(struct vio_dev *dev);
294 unsigned long driver_data;
295 struct device_driver driver;
296};
297
298struct vio_version {
299 u16 major;
300 u16 minor;
301};
302
303struct vio_driver_state;
304struct vio_driver_ops {
305 int (*send_attr)(struct vio_driver_state *vio);
306 int (*handle_attr)(struct vio_driver_state *vio, void *pkt);
307 void (*handshake_complete)(struct vio_driver_state *vio);
308};
309
310struct vio_completion {
311 struct completion com;
312 int err;
313 int waiting_for;
314};
315
316struct vio_driver_state {
317 /* Protects VIO handshake and, optionally, driver private state. */
318 spinlock_t lock;
319
320 struct ldc_channel *lp;
321
322 u32 _peer_sid;
323 u32 _local_sid;
324 struct vio_dring_state drings[2];
325#define VIO_DRIVER_TX_RING 0
326#define VIO_DRIVER_RX_RING 1
327
328 u8 hs_state;
329#define VIO_HS_INVALID 0x00
330#define VIO_HS_GOTVERS 0x01
331#define VIO_HS_GOT_ATTR 0x04
332#define VIO_HS_SENT_DREG 0x08
333#define VIO_HS_SENT_RDX 0x10
334#define VIO_HS_GOT_RDX_ACK 0x20
335#define VIO_HS_GOT_RDX 0x40
336#define VIO_HS_SENT_RDX_ACK 0x80
337#define VIO_HS_COMPLETE (VIO_HS_GOT_RDX_ACK | VIO_HS_SENT_RDX_ACK)
338
339 u8 dev_class;
340
341 u8 dr_state;
342#define VIO_DR_STATE_TXREG 0x01
343#define VIO_DR_STATE_RXREG 0x02
344#define VIO_DR_STATE_TXREQ 0x10
345#define VIO_DR_STATE_RXREQ 0x20
346
347 u8 debug;
348#define VIO_DEBUG_HS 0x01
349#define VIO_DEBUG_DATA 0x02
350
351 void *desc_buf;
352 unsigned int desc_buf_len;
353
354 struct vio_completion *cmp;
355
356 struct vio_dev *vdev;
357
358 struct timer_list timer;
359
360 struct vio_version ver;
361
362 struct vio_version *ver_table;
363 int ver_table_entries;
364
365 char *name;
366
367 struct vio_driver_ops *ops;
368};
369
370#define viodbg(TYPE, f, a...) \
371do { if (vio->debug & VIO_DEBUG_##TYPE) \
372 printk(KERN_INFO "vio: ID[%lu] " f, \
373 vio->vdev->channel_id, ## a); \
374} while (0)
375
376extern int vio_register_driver(struct vio_driver *drv);
377extern void vio_unregister_driver(struct vio_driver *drv);
378
379static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
380{
381 return container_of(drv, struct vio_driver, driver);
382}
383
384static inline struct vio_dev *to_vio_dev(struct device *dev)
385{
386 return container_of(dev, struct vio_dev, dev);
387}
388
389extern int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
390extern void vio_link_state_change(struct vio_driver_state *vio, int event);
391extern void vio_conn_reset(struct vio_driver_state *vio);
392extern int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
393extern int vio_validate_sid(struct vio_driver_state *vio,
394 struct vio_msg_tag *tp);
395extern u32 vio_send_sid(struct vio_driver_state *vio);
396extern int vio_ldc_alloc(struct vio_driver_state *vio,
397 struct ldc_channel_config *base_cfg, void *event_arg);
398extern void vio_ldc_free(struct vio_driver_state *vio);
399extern int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
400 u8 dev_class, struct vio_version *ver_table,
401 int ver_table_size, struct vio_driver_ops *ops,
402 char *name);
403
404extern void vio_port_up(struct vio_driver_state *vio);
405
406#endif /* _SPARC64_VIO_H */
diff --git a/include/asm-sparc64/visasm.h b/include/asm-sparc64/visasm.h
index 34f2ec64933b..837a12278f4a 100644
--- a/include/asm-sparc64/visasm.h
+++ b/include/asm-sparc64/visasm.h
@@ -1,62 +1 @@
1#ifndef _SPARC64_VISASM_H #include <asm-sparc/visasm.h>
2#define _SPARC64_VISASM_H
3
4/* visasm.h: FPU saving macros for VIS routines
5 *
6 * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz)
7 */
8
9#include <asm/pstate.h>
10#include <asm/ptrace.h>
11
12/* Clobbers %o5, %g1, %g2, %g3, %g7, %icc, %xcc */
13
14#define VISEntry \
15 rd %fprs, %o5; \
16 andcc %o5, (FPRS_FEF|FPRS_DU), %g0; \
17 be,pt %icc, 297f; \
18 sethi %hi(297f), %g7; \
19 sethi %hi(VISenter), %g1; \
20 jmpl %g1 + %lo(VISenter), %g0; \
21 or %g7, %lo(297f), %g7; \
22297: wr %g0, FPRS_FEF, %fprs; \
23
24#define VISExit \
25 wr %g0, 0, %fprs;
26
27/* Clobbers %o5, %g1, %g2, %g3, %g7, %icc, %xcc.
28 * Must preserve %o5 between VISEntryHalf and VISExitHalf */
29
30#define VISEntryHalf \
31 rd %fprs, %o5; \
32 andcc %o5, FPRS_FEF, %g0; \
33 be,pt %icc, 297f; \
34 sethi %hi(298f), %g7; \
35 sethi %hi(VISenterhalf), %g1; \
36 jmpl %g1 + %lo(VISenterhalf), %g0; \
37 or %g7, %lo(298f), %g7; \
38 clr %o5; \
39297: wr %o5, FPRS_FEF, %fprs; \
40298:
41
42#define VISExitHalf \
43 wr %o5, 0, %fprs;
44
45#ifndef __ASSEMBLY__
46static inline void save_and_clear_fpu(void) {
47 __asm__ __volatile__ (
48" rd %%fprs, %%o5\n"
49" andcc %%o5, %0, %%g0\n"
50" be,pt %%icc, 299f\n"
51" sethi %%hi(298f), %%g7\n"
52" sethi %%hi(VISenter), %%g1\n"
53" jmpl %%g1 + %%lo(VISenter), %%g0\n"
54" or %%g7, %%lo(298f), %%g7\n"
55" 298: wr %%g0, 0, %%fprs\n"
56" 299:\n"
57" " : : "i" (FPRS_FEF|FPRS_DU) :
58 "o5", "g1", "g2", "g3", "g7", "cc");
59}
60#endif
61
62#endif /* _SPARC64_ASI_H */
diff --git a/include/asm-sparc64/watchdog.h b/include/asm-sparc64/watchdog.h
index 5baf2d3919cf..b0f2857145f7 100644
--- a/include/asm-sparc64/watchdog.h
+++ b/include/asm-sparc64/watchdog.h
@@ -1,31 +1 @@
1/* #include <asm-sparc/watchdog.h>
2 *
3 * watchdog - Driver interface for the hardware watchdog timers
4 * present on Sun Microsystems boardsets
5 *
6 * Copyright (c) 2000 Eric Brower <ebrower@usa.net>
7 *
8 */
9
10#ifndef _SPARC64_WATCHDOG_H
11#define _SPARC64_WATCHDOG_H
12
13#include <linux/watchdog.h>
14
15/* Solaris compatibility ioctls--
16 * Ref. <linux/watchdog.h> for standard linux watchdog ioctls
17 */
18#define WIOCSTART _IO (WATCHDOG_IOCTL_BASE, 10) /* Start Timer */
19#define WIOCSTOP _IO (WATCHDOG_IOCTL_BASE, 11) /* Stop Timer */
20#define WIOCGSTAT _IOR(WATCHDOG_IOCTL_BASE, 12, int)/* Get Timer Status */
21
22/* Status flags from WIOCGSTAT ioctl
23 */
24#define WD_FREERUN 0x01 /* timer is running, interrupts disabled */
25#define WD_EXPIRED 0x02 /* timer has expired */
26#define WD_RUNNING 0x04 /* timer is running, interrupts enabled */
27#define WD_STOPPED 0x08 /* timer has not been started */
28#define WD_SERVICED 0x10 /* timer interrupt was serviced */
29
30#endif /* ifndef _SPARC64_WATCHDOG_H */
31
diff --git a/include/asm-sparc64/xor.h b/include/asm-sparc64/xor.h
index a0233884fc94..ef187cc07ed5 100644
--- a/include/asm-sparc64/xor.h
+++ b/include/asm-sparc64/xor.h
@@ -1,70 +1 @@
1/* #include <asm-sparc/xor.h>
2 * include/asm-sparc64/xor.h
3 *
4 * High speed xor_block operation for RAID4/5 utilizing the
5 * UltraSparc Visual Instruction Set and Niagara block-init
6 * twin-load instructions.
7 *
8 * Copyright (C) 1997, 1999 Jakub Jelinek (jj@ultra.linux.cz)
9 * Copyright (C) 2006 David S. Miller <davem@davemloft.net>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * You should have received a copy of the GNU General Public License
17 * (for example /usr/src/linux/COPYING); if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <asm/spitfire.h>
22
23extern void xor_vis_2(unsigned long, unsigned long *, unsigned long *);
24extern void xor_vis_3(unsigned long, unsigned long *, unsigned long *,
25 unsigned long *);
26extern void xor_vis_4(unsigned long, unsigned long *, unsigned long *,
27 unsigned long *, unsigned long *);
28extern void xor_vis_5(unsigned long, unsigned long *, unsigned long *,
29 unsigned long *, unsigned long *, unsigned long *);
30
31/* XXX Ugh, write cheetah versions... -DaveM */
32
33static struct xor_block_template xor_block_VIS = {
34 .name = "VIS",
35 .do_2 = xor_vis_2,
36 .do_3 = xor_vis_3,
37 .do_4 = xor_vis_4,
38 .do_5 = xor_vis_5,
39};
40
41extern void xor_niagara_2(unsigned long, unsigned long *, unsigned long *);
42extern void xor_niagara_3(unsigned long, unsigned long *, unsigned long *,
43 unsigned long *);
44extern void xor_niagara_4(unsigned long, unsigned long *, unsigned long *,
45 unsigned long *, unsigned long *);
46extern void xor_niagara_5(unsigned long, unsigned long *, unsigned long *,
47 unsigned long *, unsigned long *, unsigned long *);
48
49static struct xor_block_template xor_block_niagara = {
50 .name = "Niagara",
51 .do_2 = xor_niagara_2,
52 .do_3 = xor_niagara_3,
53 .do_4 = xor_niagara_4,
54 .do_5 = xor_niagara_5,
55};
56
57#undef XOR_TRY_TEMPLATES
58#define XOR_TRY_TEMPLATES \
59 do { \
60 xor_speed(&xor_block_VIS); \
61 xor_speed(&xor_block_niagara); \
62 } while (0)
63
64/* For VIS for everything except Niagara. */
65#define XOR_SELECT_TEMPLATE(FASTEST) \
66 ((tlb_type == hypervisor && \
67 (sun4v_chip_type == SUN4V_CHIP_NIAGARA1 || \
68 sun4v_chip_type == SUN4V_CHIP_NIAGARA2)) ? \
69 &xor_block_niagara : \
70 &xor_block_VIS)
diff --git a/include/linux/auxvec.h b/include/linux/auxvec.h
index ad895455ab72..0da17d14fd13 100644
--- a/include/linux/auxvec.h
+++ b/include/linux/auxvec.h
@@ -26,8 +26,10 @@
26 26
27#define AT_SECURE 23 /* secure mode boolean */ 27#define AT_SECURE 23 /* secure mode boolean */
28 28
29#define AT_EXECFN 31 /* filename of program */
29#ifdef __KERNEL__ 30#ifdef __KERNEL__
30#define AT_VECTOR_SIZE_BASE (14 + 2) /* NEW_AUX_ENT entries in auxiliary table */ 31#define AT_VECTOR_SIZE_BASE 17 /* NEW_AUX_ENT entries in auxiliary table */
32 /* number of "#define AT_.*" above, minus {AT_NULL, AT_IGNORE, AT_NOTELF} */
31#endif 33#endif
32 34
33#endif /* _LINUX_AUXVEC_H */ 35#endif /* _LINUX_AUXVEC_H */
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index e7e91dbfde0f..2270ca5ec631 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -4,9 +4,6 @@
4 * Copyright (C) 2001 Russell King 4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> 5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 * 6 *
7 *
8 * $Id: cpufreq.h,v 1.36 2003/01/20 17:31:48 db Exp $
9 *
10 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index 32755cdf68db..e1a6c046cea3 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -44,6 +44,7 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
44 const char *dest); 44 const char *dest);
45 45
46void debugfs_remove(struct dentry *dentry); 46void debugfs_remove(struct dentry *dentry);
47void debugfs_remove_recursive(struct dentry *dentry);
47 48
48struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, 49struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
49 struct dentry *new_dir, const char *new_name); 50 struct dentry *new_dir, const char *new_name);
@@ -101,6 +102,9 @@ static inline struct dentry *debugfs_create_symlink(const char *name,
101static inline void debugfs_remove(struct dentry *dentry) 102static inline void debugfs_remove(struct dentry *dentry)
102{ } 103{ }
103 104
105static inline void debugfs_remove_recursive(struct dentry *dentry)
106{ }
107
104static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, 108static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
105 struct dentry *new_dir, char *new_name) 109 struct dentry *new_dir, char *new_name)
106{ 110{
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index 0d8d419d191a..a90222e3297d 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -9,11 +9,13 @@
9#define _LINUX_DEVICE_MAPPER_H 9#define _LINUX_DEVICE_MAPPER_H
10 10
11#include <linux/bio.h> 11#include <linux/bio.h>
12#include <linux/blkdev.h>
12 13
13struct dm_target; 14struct dm_target;
14struct dm_table; 15struct dm_table;
15struct dm_dev; 16struct dm_dev;
16struct mapped_device; 17struct mapped_device;
18struct bio_vec;
17 19
18typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t; 20typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
19 21
@@ -72,6 +74,9 @@ typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode,
72 struct file *filp, unsigned int cmd, 74 struct file *filp, unsigned int cmd,
73 unsigned long arg); 75 unsigned long arg);
74 76
77typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
78 struct bio_vec *biovec, int max_size);
79
75void dm_error(const char *message); 80void dm_error(const char *message);
76 81
77/* 82/*
@@ -107,6 +112,7 @@ struct target_type {
107 dm_status_fn status; 112 dm_status_fn status;
108 dm_message_fn message; 113 dm_message_fn message;
109 dm_ioctl_fn ioctl; 114 dm_ioctl_fn ioctl;
115 dm_merge_fn merge;
110}; 116};
111 117
112struct io_restrictions { 118struct io_restrictions {
diff --git a/include/linux/device.h b/include/linux/device.h
index f71a78d123ae..d24a47f80f9c 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -16,6 +16,7 @@
16#include <linux/kobject.h> 16#include <linux/kobject.h>
17#include <linux/klist.h> 17#include <linux/klist.h>
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/lockdep.h>
19#include <linux/compiler.h> 20#include <linux/compiler.h>
20#include <linux/types.h> 21#include <linux/types.h>
21#include <linux/module.h> 22#include <linux/module.h>
@@ -24,17 +25,13 @@
24#include <asm/atomic.h> 25#include <asm/atomic.h>
25#include <asm/device.h> 26#include <asm/device.h>
26 27
27#define DEVICE_NAME_SIZE 50 28#define BUS_ID_SIZE 20
28/* DEVICE_NAME_HALF is really less than half to accommodate slop */
29#define DEVICE_NAME_HALF __stringify(20)
30#define DEVICE_ID_SIZE 32
31#define BUS_ID_SIZE KOBJ_NAME_LEN
32
33 29
34struct device; 30struct device;
35struct device_driver; 31struct device_driver;
36struct driver_private; 32struct driver_private;
37struct class; 33struct class;
34struct class_private;
38struct bus_type; 35struct bus_type;
39struct bus_type_private; 36struct bus_type_private;
40 37
@@ -186,13 +183,9 @@ struct class {
186 const char *name; 183 const char *name;
187 struct module *owner; 184 struct module *owner;
188 185
189 struct kset subsys;
190 struct list_head devices;
191 struct list_head interfaces;
192 struct kset class_dirs;
193 struct semaphore sem; /* locks children, devices, interfaces */
194 struct class_attribute *class_attrs; 186 struct class_attribute *class_attrs;
195 struct device_attribute *dev_attrs; 187 struct device_attribute *dev_attrs;
188 struct kobject *dev_kobj;
196 189
197 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); 190 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
198 191
@@ -203,13 +196,28 @@ struct class {
203 int (*resume)(struct device *dev); 196 int (*resume)(struct device *dev);
204 197
205 struct pm_ops *pm; 198 struct pm_ops *pm;
199 struct class_private *p;
206}; 200};
207 201
208extern int __must_check class_register(struct class *class); 202extern struct kobject *sysfs_dev_block_kobj;
203extern struct kobject *sysfs_dev_char_kobj;
204extern int __must_check __class_register(struct class *class,
205 struct lock_class_key *key);
209extern void class_unregister(struct class *class); 206extern void class_unregister(struct class *class);
210extern int class_for_each_device(struct class *class, void *data, 207
208/* This is a #define to keep the compiler from merging different
209 * instances of the __key variable */
210#define class_register(class) \
211({ \
212 static struct lock_class_key __key; \
213 __class_register(class, &__key); \
214})
215
216extern int class_for_each_device(struct class *class, struct device *start,
217 void *data,
211 int (*fn)(struct device *dev, void *data)); 218 int (*fn)(struct device *dev, void *data));
212extern struct device *class_find_device(struct class *class, void *data, 219extern struct device *class_find_device(struct class *class,
220 struct device *start, void *data,
213 int (*match)(struct device *, void *)); 221 int (*match)(struct device *, void *));
214 222
215struct class_attribute { 223struct class_attribute {
@@ -237,9 +245,19 @@ struct class_interface {
237extern int __must_check class_interface_register(struct class_interface *); 245extern int __must_check class_interface_register(struct class_interface *);
238extern void class_interface_unregister(struct class_interface *); 246extern void class_interface_unregister(struct class_interface *);
239 247
240extern struct class *class_create(struct module *owner, const char *name); 248extern struct class * __must_check __class_create(struct module *owner,
249 const char *name,
250 struct lock_class_key *key);
241extern void class_destroy(struct class *cls); 251extern void class_destroy(struct class *cls);
242 252
253/* This is a #define to keep the compiler from merging different
254 * instances of the __key variable */
255#define class_create(owner, name) \
256({ \
257 static struct lock_class_key __key; \
258 __class_create(owner, name, &__key); \
259})
260
243/* 261/*
244 * The type of device, "struct device" is embedded in. A class 262 * The type of device, "struct device" is embedded in. A class
245 * or bus can contain devices of different types 263 * or bus can contain devices of different types
@@ -468,14 +486,10 @@ extern struct device *device_create_vargs(struct class *cls,
468 const char *fmt, 486 const char *fmt,
469 va_list vargs); 487 va_list vargs);
470extern struct device *device_create(struct class *cls, struct device *parent, 488extern struct device *device_create(struct class *cls, struct device *parent,
471 dev_t devt, const char *fmt, ...) 489 dev_t devt, void *drvdata,
472 __attribute__((format(printf, 4, 5))); 490 const char *fmt, ...)
473extern struct device *device_create_drvdata(struct class *cls,
474 struct device *parent,
475 dev_t devt,
476 void *drvdata,
477 const char *fmt, ...)
478 __attribute__((format(printf, 5, 6))); 491 __attribute__((format(printf, 5, 6)));
492#define device_create_drvdata device_create
479extern void device_destroy(struct class *cls, dev_t devt); 493extern void device_destroy(struct class *cls, dev_t devt);
480 494
481/* 495/*
diff --git a/include/linux/dm-ioctl.h b/include/linux/dm-ioctl.h
index b03c41bbfa14..28c2940eb30d 100644
--- a/include/linux/dm-ioctl.h
+++ b/include/linux/dm-ioctl.h
@@ -256,9 +256,9 @@ enum {
256#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl) 256#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
257 257
258#define DM_VERSION_MAJOR 4 258#define DM_VERSION_MAJOR 4
259#define DM_VERSION_MINOR 13 259#define DM_VERSION_MINOR 14
260#define DM_VERSION_PATCHLEVEL 0 260#define DM_VERSION_PATCHLEVEL 0
261#define DM_VERSION_EXTRA "-ioctl (2007-10-18)" 261#define DM_VERSION_EXTRA "-ioctl (2008-04-23)"
262 262
263/* Status bits */ 263/* Status bits */
264#define DM_READONLY_FLAG (1 << 0) /* In/Out */ 264#define DM_READONLY_FLAG (1 << 0) /* In/Out */
diff --git a/include/linux/dma-attrs.h b/include/linux/dma-attrs.h
index 1677e2bfa00c..71ad34eca6e3 100644
--- a/include/linux/dma-attrs.h
+++ b/include/linux/dma-attrs.h
@@ -12,6 +12,7 @@
12 */ 12 */
13enum dma_attr { 13enum dma_attr {
14 DMA_ATTR_WRITE_BARRIER, 14 DMA_ATTR_WRITE_BARRIER,
15 DMA_ATTR_WEAK_ORDERING,
15 DMA_ATTR_MAX, 16 DMA_ATTR_MAX,
16}; 17};
17 18
diff --git a/include/linux/eisa.h b/include/linux/eisa.h
index fe806b6f030d..e61c0be2a459 100644
--- a/include/linux/eisa.h
+++ b/include/linux/eisa.h
@@ -40,7 +40,7 @@ struct eisa_device {
40 u64 dma_mask; 40 u64 dma_mask;
41 struct device dev; /* generic device */ 41 struct device dev; /* generic device */
42#ifdef CONFIG_EISA_NAMES 42#ifdef CONFIG_EISA_NAMES
43 char pretty_name[DEVICE_NAME_SIZE]; 43 char pretty_name[50];
44#endif 44#endif
45}; 45};
46 46
diff --git a/include/linux/fs_enet_pd.h b/include/linux/fs_enet_pd.h
index 9bc045b8c478..0ba21ee0f58c 100644
--- a/include/linux/fs_enet_pd.h
+++ b/include/linux/fs_enet_pd.h
@@ -135,11 +135,7 @@ struct fs_platform_info {
135 u32 device_flags; 135 u32 device_flags;
136 136
137 int phy_addr; /* the phy address (-1 no phy) */ 137 int phy_addr; /* the phy address (-1 no phy) */
138#ifdef CONFIG_PPC_CPM_NEW_BINDING
139 char bus_id[16]; 138 char bus_id[16];
140#else
141 const char* bus_id;
142#endif
143 int phy_irq; /* the phy irq (if it exists) */ 139 int phy_irq; /* the phy irq (if it exists) */
144 140
145 const struct fs_mii_bus_info *bus_info; 141 const struct fs_mii_bus_info *bus_info;
diff --git a/include/linux/fsl_devices.h b/include/linux/fsl_devices.h
index c415a496de3a..4e625e0094c8 100644
--- a/include/linux/fsl_devices.h
+++ b/include/linux/fsl_devices.h
@@ -69,6 +69,7 @@ struct gianfar_mdio_data {
69#define FSL_GIANFAR_DEV_HAS_VLAN 0x00000020 69#define FSL_GIANFAR_DEV_HAS_VLAN 0x00000020
70#define FSL_GIANFAR_DEV_HAS_EXTENDED_HASH 0x00000040 70#define FSL_GIANFAR_DEV_HAS_EXTENDED_HASH 0x00000040
71#define FSL_GIANFAR_DEV_HAS_PADDING 0x00000080 71#define FSL_GIANFAR_DEV_HAS_PADDING 0x00000080
72#define FSL_GIANFAR_DEV_HAS_MAGIC_PACKET 0x00000100
72 73
73/* Flags in gianfar_platform_data */ 74/* Flags in gianfar_platform_data */
74#define FSL_GIANFAR_BRD_HAS_PHY_INTR 0x00000001 /* set or use a timer */ 75#define FSL_GIANFAR_BRD_HAS_PHY_INTR 0x00000001 /* set or use a timer */
@@ -125,4 +126,10 @@ struct mpc8xx_pcmcia_ops {
125 int(*voltage_set)(int slot, int vcc, int vpp); 126 int(*voltage_set)(int slot, int vcc, int vpp);
126}; 127};
127 128
129/* Returns non-zero if the current suspend operation would
130 * lead to a deep sleep (i.e. power removed from the core,
131 * instead of just the clock).
132 */
133int fsl_deep_sleep(void);
134
128#endif /* _FSL_DEVICE_H_ */ 135#endif /* _FSL_DEVICE_H_ */
diff --git a/include/linux/gameport.h b/include/linux/gameport.h
index afad95272841..f64e29c0ef3f 100644
--- a/include/linux/gameport.h
+++ b/include/linux/gameport.h
@@ -68,7 +68,6 @@ struct gameport_driver {
68 68
69int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode); 69int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode);
70void gameport_close(struct gameport *gameport); 70void gameport_close(struct gameport *gameport);
71void gameport_rescan(struct gameport *gameport);
72 71
73#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) 72#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
74 73
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index c6d3a9de5634..ec6ecd74781d 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -9,6 +9,7 @@ struct gpio_keys_button {
9 char *desc; 9 char *desc;
10 int type; /* input event type (EV_KEY, EV_SW) */ 10 int type; /* input event type (EV_KEY, EV_SW) */
11 int wakeup; /* configure the button as a wake-up source */ 11 int wakeup; /* configure the button as a wake-up source */
12 int debounce_interval; /* debounce ticks interval in msecs */
12}; 13};
13 14
14struct gpio_keys_platform_data { 15struct gpio_keys_platform_data {
diff --git a/include/linux/input.h b/include/linux/input.h
index d150c57e5f0a..a5802c9c81a4 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -373,6 +373,8 @@ struct input_absinfo {
373 373
374#define KEY_WIMAX 246 374#define KEY_WIMAX 246
375 375
376/* Range 248 - 255 is reserved for special needs of AT keyboard driver */
377
376#define BTN_MISC 0x100 378#define BTN_MISC 0x100
377#define BTN_0 0x100 379#define BTN_0 0x100
378#define BTN_1 0x101 380#define BTN_1 0x101
@@ -640,6 +642,8 @@ struct input_absinfo {
640#define SW_RFKILL_ALL 0x03 /* rfkill master switch, type "any" 642#define SW_RFKILL_ALL 0x03 /* rfkill master switch, type "any"
641 set = radio enabled */ 643 set = radio enabled */
642#define SW_RADIO SW_RFKILL_ALL /* deprecated */ 644#define SW_RADIO SW_RFKILL_ALL /* deprecated */
645#define SW_MICROPHONE_INSERT 0x04 /* set = inserted */
646#define SW_DOCK 0x05 /* set = plugged into dock */
643#define SW_MAX 0x0f 647#define SW_MAX 0x0f
644#define SW_CNT (SW_MAX+1) 648#define SW_CNT (SW_MAX+1)
645 649
@@ -1215,11 +1219,6 @@ struct input_handle {
1215 struct list_head h_node; 1219 struct list_head h_node;
1216}; 1220};
1217 1221
1218#define to_dev(n) container_of(n, struct input_dev, node)
1219#define to_handler(n) container_of(n, struct input_handler, node)
1220#define to_handle(n) container_of(n, struct input_handle, d_node)
1221#define to_handle_h(n) container_of(n, struct input_handle, h_node)
1222
1223struct input_dev *input_allocate_device(void); 1222struct input_dev *input_allocate_device(void);
1224void input_free_device(struct input_dev *dev); 1223void input_free_device(struct input_dev *dev);
1225 1224
diff --git a/include/linux/joystick.h b/include/linux/joystick.h
index e2d3a18af456..b5e051295a67 100644
--- a/include/linux/joystick.h
+++ b/include/linux/joystick.h
@@ -2,8 +2,6 @@
2#define _LINUX_JOYSTICK_H 2#define _LINUX_JOYSTICK_H
3 3
4/* 4/*
5 * $Id: joystick.h,v 1.3 2000/11/30 11:07:05 vojtech Exp $
6 *
7 * Copyright (C) 1996-2000 Vojtech Pavlik 5 * Copyright (C) 1996-2000 Vojtech Pavlik
8 * 6 *
9 * Sponsored by SuSE 7 * Sponsored by SuSE
diff --git a/include/linux/kmod.h b/include/linux/kmod.h
index 5dc13848891b..0509c4ce4857 100644
--- a/include/linux/kmod.h
+++ b/include/linux/kmod.h
@@ -25,15 +25,16 @@
25 25
26#define KMOD_PATH_LEN 256 26#define KMOD_PATH_LEN 256
27 27
28#ifdef CONFIG_KMOD 28#ifdef CONFIG_MODULES
29/* modprobe exit status on success, -ve on error. Return value 29/* modprobe exit status on success, -ve on error. Return value
30 * usually useless though. */ 30 * usually useless though. */
31extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2))); 31extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2)));
32#define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x)))
32#else 33#else
33static inline int request_module(const char * name, ...) { return -ENOSYS; } 34static inline int request_module(const char * name, ...) { return -ENOSYS; }
35#define try_then_request_module(x, mod...) (x)
34#endif 36#endif
35 37
36#define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x)))
37 38
38struct key; 39struct key;
39struct file; 40struct file;
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 39e709f88aa0..60f0d418ae32 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -26,7 +26,6 @@
26#include <linux/wait.h> 26#include <linux/wait.h>
27#include <asm/atomic.h> 27#include <asm/atomic.h>
28 28
29#define KOBJ_NAME_LEN 20
30#define UEVENT_HELPER_PATH_LEN 256 29#define UEVENT_HELPER_PATH_LEN 256
31#define UEVENT_NUM_ENVP 32 /* number of env pointers */ 30#define UEVENT_NUM_ENVP 32 /* number of env pointers */
32#define UEVENT_BUFFER_SIZE 2048 /* buffer for the variables */ 31#define UEVENT_BUFFER_SIZE 2048 /* buffer for the variables */
@@ -59,12 +58,12 @@ enum kobject_action {
59 58
60struct kobject { 59struct kobject {
61 const char *name; 60 const char *name;
62 struct kref kref;
63 struct list_head entry; 61 struct list_head entry;
64 struct kobject *parent; 62 struct kobject *parent;
65 struct kset *kset; 63 struct kset *kset;
66 struct kobj_type *ktype; 64 struct kobj_type *ktype;
67 struct sysfs_dirent *sd; 65 struct sysfs_dirent *sd;
66 struct kref kref;
68 unsigned int state_initialized:1; 67 unsigned int state_initialized:1;
69 unsigned int state_in_sysfs:1; 68 unsigned int state_in_sysfs:1;
70 unsigned int state_add_uevent_sent:1; 69 unsigned int state_add_uevent_sent:1;
diff --git a/include/linux/libps2.h b/include/linux/libps2.h
index f6f301e2b0f5..afc413369101 100644
--- a/include/linux/libps2.h
+++ b/include/linux/libps2.h
@@ -43,7 +43,6 @@ void ps2_init(struct ps2dev *ps2dev, struct serio *serio);
43int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout); 43int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout);
44void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout); 44void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout);
45int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command); 45int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command);
46int ps2_schedule_command(struct ps2dev *ps2dev, unsigned char *param, int command);
47int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data); 46int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data);
48int ps2_handle_response(struct ps2dev *ps2dev, unsigned char data); 47int ps2_handle_response(struct ps2dev *ps2dev, unsigned char data);
49void ps2_cmd_aborted(struct ps2dev *ps2dev); 48void ps2_cmd_aborted(struct ps2dev *ps2dev);
diff --git a/include/linux/module.h b/include/linux/module.h
index 3e03b1acbc94..fce15ebd0e1c 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -249,27 +249,30 @@ struct module
249 249
250 /* Exported symbols */ 250 /* Exported symbols */
251 const struct kernel_symbol *syms; 251 const struct kernel_symbol *syms;
252 unsigned int num_syms;
253 const unsigned long *crcs; 252 const unsigned long *crcs;
253 unsigned int num_syms;
254 254
255 /* GPL-only exported symbols. */ 255 /* GPL-only exported symbols. */
256 const struct kernel_symbol *gpl_syms;
257 unsigned int num_gpl_syms; 256 unsigned int num_gpl_syms;
257 const struct kernel_symbol *gpl_syms;
258 const unsigned long *gpl_crcs; 258 const unsigned long *gpl_crcs;
259 259
260#ifdef CONFIG_UNUSED_SYMBOLS
260 /* unused exported symbols. */ 261 /* unused exported symbols. */
261 const struct kernel_symbol *unused_syms; 262 const struct kernel_symbol *unused_syms;
262 unsigned int num_unused_syms;
263 const unsigned long *unused_crcs; 263 const unsigned long *unused_crcs;
264 unsigned int num_unused_syms;
265
264 /* GPL-only, unused exported symbols. */ 266 /* GPL-only, unused exported symbols. */
265 const struct kernel_symbol *unused_gpl_syms;
266 unsigned int num_unused_gpl_syms; 267 unsigned int num_unused_gpl_syms;
268 const struct kernel_symbol *unused_gpl_syms;
267 const unsigned long *unused_gpl_crcs; 269 const unsigned long *unused_gpl_crcs;
270#endif
268 271
269 /* symbols that will be GPL-only in the near future. */ 272 /* symbols that will be GPL-only in the near future. */
270 const struct kernel_symbol *gpl_future_syms; 273 const struct kernel_symbol *gpl_future_syms;
271 unsigned int num_gpl_future_syms;
272 const unsigned long *gpl_future_crcs; 274 const unsigned long *gpl_future_crcs;
275 unsigned int num_gpl_future_syms;
273 276
274 /* Exception table */ 277 /* Exception table */
275 unsigned int num_exentries; 278 unsigned int num_exentries;
@@ -285,10 +288,10 @@ struct module
285 void *module_core; 288 void *module_core;
286 289
287 /* Here are the sizes of the init and core sections */ 290 /* Here are the sizes of the init and core sections */
288 unsigned long init_size, core_size; 291 unsigned int init_size, core_size;
289 292
290 /* The size of the executable code in each section. */ 293 /* The size of the executable code in each section. */
291 unsigned long init_text_size, core_text_size; 294 unsigned int init_text_size, core_text_size;
292 295
293 /* The handle returned from unwind_add_table. */ 296 /* The handle returned from unwind_add_table. */
294 void *unwind_info; 297 void *unwind_info;
@@ -300,29 +303,15 @@ struct module
300 303
301#ifdef CONFIG_GENERIC_BUG 304#ifdef CONFIG_GENERIC_BUG
302 /* Support for BUG */ 305 /* Support for BUG */
306 unsigned num_bugs;
303 struct list_head bug_list; 307 struct list_head bug_list;
304 struct bug_entry *bug_table; 308 struct bug_entry *bug_table;
305 unsigned num_bugs;
306#endif
307
308#ifdef CONFIG_MODULE_UNLOAD
309 /* Reference counts */
310 struct module_ref ref[NR_CPUS];
311
312 /* What modules depend on me? */
313 struct list_head modules_which_use_me;
314
315 /* Who is waiting for us to be unloaded */
316 struct task_struct *waiter;
317
318 /* Destruction function. */
319 void (*exit)(void);
320#endif 309#endif
321 310
322#ifdef CONFIG_KALLSYMS 311#ifdef CONFIG_KALLSYMS
323 /* We keep the symbol and string tables for kallsyms. */ 312 /* We keep the symbol and string tables for kallsyms. */
324 Elf_Sym *symtab; 313 Elf_Sym *symtab;
325 unsigned long num_symtab; 314 unsigned int num_symtab;
326 char *strtab; 315 char *strtab;
327 316
328 /* Section attributes */ 317 /* Section attributes */
@@ -342,6 +331,21 @@ struct module
342 struct marker *markers; 331 struct marker *markers;
343 unsigned int num_markers; 332 unsigned int num_markers;
344#endif 333#endif
334
335#ifdef CONFIG_MODULE_UNLOAD
336 /* What modules depend on me? */
337 struct list_head modules_which_use_me;
338
339 /* Who is waiting for us to be unloaded */
340 struct task_struct *waiter;
341
342 /* Destruction function. */
343 void (*exit)(void);
344
345 /* Reference counts */
346 struct module_ref ref[NR_CPUS];
347#endif
348
345}; 349};
346#ifndef MODULE_ARCH_INIT 350#ifndef MODULE_ARCH_INIT
347#define MODULE_ARCH_INIT {} 351#define MODULE_ARCH_INIT {}
diff --git a/include/linux/mtd/map.h b/include/linux/mtd/map.h
index a9fae032ba81..9c1d95491f8b 100644
--- a/include/linux/mtd/map.h
+++ b/include/linux/mtd/map.h
@@ -189,7 +189,7 @@ typedef union {
189*/ 189*/
190 190
191struct map_info { 191struct map_info {
192 char *name; 192 const char *name;
193 unsigned long size; 193 unsigned long size;
194 resource_size_t phys; 194 resource_size_t phys;
195#define NO_XIP (-1UL) 195#define NO_XIP (-1UL)
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 245f9098e171..8b5d49133ec6 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -121,7 +121,7 @@ struct mtd_info {
121 u_int32_t oobavail; // Available OOB bytes per block 121 u_int32_t oobavail; // Available OOB bytes per block
122 122
123 // Kernel-only stuff starts here. 123 // Kernel-only stuff starts here.
124 char *name; 124 const char *name;
125 int index; 125 int index;
126 126
127 /* ecc layout structure pointer - read only ! */ 127 /* ecc layout structure pointer - read only ! */
diff --git a/include/linux/netfilter/nf_conntrack_common.h b/include/linux/netfilter/nf_conntrack_common.h
index bad1eb760f61..885cbe282260 100644
--- a/include/linux/netfilter/nf_conntrack_common.h
+++ b/include/linux/netfilter/nf_conntrack_common.h
@@ -122,7 +122,7 @@ enum ip_conntrack_events
122 IPCT_NATINFO_BIT = 10, 122 IPCT_NATINFO_BIT = 10,
123 IPCT_NATINFO = (1 << IPCT_NATINFO_BIT), 123 IPCT_NATINFO = (1 << IPCT_NATINFO_BIT),
124 124
125 /* Counter highest bit has been set */ 125 /* Counter highest bit has been set, unused */
126 IPCT_COUNTER_FILLING_BIT = 11, 126 IPCT_COUNTER_FILLING_BIT = 11,
127 IPCT_COUNTER_FILLING = (1 << IPCT_COUNTER_FILLING_BIT), 127 IPCT_COUNTER_FILLING = (1 << IPCT_COUNTER_FILLING_BIT),
128 128
@@ -145,12 +145,6 @@ enum ip_conntrack_expect_events {
145}; 145};
146 146
147#ifdef __KERNEL__ 147#ifdef __KERNEL__
148struct ip_conntrack_counter
149{
150 u_int32_t packets;
151 u_int32_t bytes;
152};
153
154struct ip_conntrack_stat 148struct ip_conntrack_stat
155{ 149{
156 unsigned int searched; 150 unsigned int searched;
diff --git a/include/linux/netfilter/nfnetlink_conntrack.h b/include/linux/netfilter/nfnetlink_conntrack.h
index 759bc043dc65..c19595c89304 100644
--- a/include/linux/netfilter/nfnetlink_conntrack.h
+++ b/include/linux/netfilter/nfnetlink_conntrack.h
@@ -115,10 +115,10 @@ enum ctattr_protoinfo_sctp {
115 115
116enum ctattr_counters { 116enum ctattr_counters {
117 CTA_COUNTERS_UNSPEC, 117 CTA_COUNTERS_UNSPEC,
118 CTA_COUNTERS_PACKETS, /* old 64bit counters */ 118 CTA_COUNTERS_PACKETS, /* 64bit counters */
119 CTA_COUNTERS_BYTES, /* old 64bit counters */ 119 CTA_COUNTERS_BYTES, /* 64bit counters */
120 CTA_COUNTERS32_PACKETS, 120 CTA_COUNTERS32_PACKETS, /* old 32bit counters, unused */
121 CTA_COUNTERS32_BYTES, 121 CTA_COUNTERS32_BYTES, /* old 32bit counters, unused */
122 __CTA_COUNTERS_MAX 122 __CTA_COUNTERS_MAX
123}; 123};
124#define CTA_COUNTERS_MAX (__CTA_COUNTERS_MAX - 1) 124#define CTA_COUNTERS_MAX (__CTA_COUNTERS_MAX - 1)
diff --git a/include/linux/netfilter/nfnetlink_log.h b/include/linux/netfilter/nfnetlink_log.h
index a85721332924..f661731f3cb1 100644
--- a/include/linux/netfilter/nfnetlink_log.h
+++ b/include/linux/netfilter/nfnetlink_log.h
@@ -48,6 +48,9 @@ enum nfulnl_attr_type {
48 NFULA_SEQ, /* instance-local sequence number */ 48 NFULA_SEQ, /* instance-local sequence number */
49 NFULA_SEQ_GLOBAL, /* global sequence number */ 49 NFULA_SEQ_GLOBAL, /* global sequence number */
50 NFULA_GID, /* group id of socket */ 50 NFULA_GID, /* group id of socket */
51 NFULA_HWTYPE, /* hardware type */
52 NFULA_HWHEADER, /* hardware header */
53 NFULA_HWLEN, /* hardware header length */
51 54
52 __NFULA_MAX 55 __NFULA_MAX
53}; 56};
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index 2ee97e9877a7..67db101d0eb8 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -15,7 +15,7 @@
15#define __LINUX_OF_GPIO_H 15#define __LINUX_OF_GPIO_H
16 16
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <asm/gpio.h> 18#include <linux/gpio.h>
19 19
20#ifdef CONFIG_OF_GPIO 20#ifdef CONFIG_OF_GPIO
21 21
diff --git a/include/linux/raid/bitmap.h b/include/linux/raid/bitmap.h
index 78bfdea24a8e..e98900671ca9 100644
--- a/include/linux/raid/bitmap.h
+++ b/include/linux/raid/bitmap.h
@@ -221,6 +221,7 @@ struct bitmap {
221 unsigned long syncchunk; 221 unsigned long syncchunk;
222 222
223 __u64 events_cleared; 223 __u64 events_cleared;
224 int need_sync;
224 225
225 /* bitmap spinlock */ 226 /* bitmap spinlock */
226 spinlock_t lock; 227 spinlock_t lock;
diff --git a/include/linux/raid/linear.h b/include/linux/raid/linear.h
index ba15469daf11..7e375111d007 100644
--- a/include/linux/raid/linear.h
+++ b/include/linux/raid/linear.h
@@ -16,7 +16,7 @@ struct linear_private_data
16 struct linear_private_data *prev; /* earlier version */ 16 struct linear_private_data *prev; /* earlier version */
17 dev_info_t **hash_table; 17 dev_info_t **hash_table;
18 sector_t hash_spacing; 18 sector_t hash_spacing;
19 sector_t array_size; 19 sector_t array_sectors;
20 int preshift; /* shift before dividing by hash_spacing */ 20 int preshift; /* shift before dividing by hash_spacing */
21 dev_info_t disks[0]; 21 dev_info_t disks[0];
22}; 22};
diff --git a/include/linux/raid/md.h b/include/linux/raid/md.h
index b7386ae9d288..dc0e3fcb9f28 100644
--- a/include/linux/raid/md.h
+++ b/include/linux/raid/md.h
@@ -95,7 +95,7 @@ extern int sync_page_io(struct block_device *bdev, sector_t sector, int size,
95 struct page *page, int rw); 95 struct page *page, int rw);
96extern void md_do_sync(mddev_t *mddev); 96extern void md_do_sync(mddev_t *mddev);
97extern void md_new_event(mddev_t *mddev); 97extern void md_new_event(mddev_t *mddev);
98extern void md_allow_write(mddev_t *mddev); 98extern int md_allow_write(mddev_t *mddev);
99extern void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev); 99extern void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev);
100 100
101#endif /* CONFIG_MD */ 101#endif /* CONFIG_MD */
diff --git a/include/linux/raid/md_k.h b/include/linux/raid/md_k.h
index 3dea9f545c8f..9f2549ac0e2d 100644
--- a/include/linux/raid/md_k.h
+++ b/include/linux/raid/md_k.h
@@ -59,7 +59,7 @@ struct mdk_rdev_s
59 int sb_loaded; 59 int sb_loaded;
60 __u64 sb_events; 60 __u64 sb_events;
61 sector_t data_offset; /* start of data in array */ 61 sector_t data_offset; /* start of data in array */
62 sector_t sb_offset; 62 sector_t sb_start; /* offset of the super block (in 512byte sectors) */
63 int sb_size; /* bytes in the superblock */ 63 int sb_size; /* bytes in the superblock */
64 int preferred_minor; /* autorun support */ 64 int preferred_minor; /* autorun support */
65 65
@@ -87,6 +87,9 @@ struct mdk_rdev_s
87#define Blocked 8 /* An error occured on an externally 87#define Blocked 8 /* An error occured on an externally
88 * managed array, don't allow writes 88 * managed array, don't allow writes
89 * until it is cleared */ 89 * until it is cleared */
90#define StateChanged 9 /* Faulty or Blocked has changed during
91 * interrupt, so it needs to be
92 * notified by the thread */
90 wait_queue_head_t blocked_wait; 93 wait_queue_head_t blocked_wait;
91 94
92 int desc_nr; /* descriptor index in the superblock */ 95 int desc_nr; /* descriptor index in the superblock */
@@ -147,7 +150,7 @@ struct mddev_s
147 int raid_disks; 150 int raid_disks;
148 int max_disks; 151 int max_disks;
149 sector_t size; /* used size of component devices */ 152 sector_t size; /* used size of component devices */
150 sector_t array_size; /* exported array size */ 153 sector_t array_sectors; /* exported array size */
151 __u64 events; 154 __u64 events;
152 155
153 char uuid[16]; 156 char uuid[16];
@@ -188,6 +191,7 @@ struct mddev_s
188 * NEEDED: we might need to start a resync/recover 191 * NEEDED: we might need to start a resync/recover
189 * RUNNING: a thread is running, or about to be started 192 * RUNNING: a thread is running, or about to be started
190 * SYNC: actually doing a resync, not a recovery 193 * SYNC: actually doing a resync, not a recovery
194 * RECOVER: doing recovery, or need to try it.
191 * INTR: resync needs to be aborted for some reason 195 * INTR: resync needs to be aborted for some reason
192 * DONE: thread is done and is waiting to be reaped 196 * DONE: thread is done and is waiting to be reaped
193 * REQUEST: user-space has requested a sync (used with SYNC) 197 * REQUEST: user-space has requested a sync (used with SYNC)
@@ -198,6 +202,7 @@ struct mddev_s
198 */ 202 */
199#define MD_RECOVERY_RUNNING 0 203#define MD_RECOVERY_RUNNING 0
200#define MD_RECOVERY_SYNC 1 204#define MD_RECOVERY_SYNC 1
205#define MD_RECOVERY_RECOVER 2
201#define MD_RECOVERY_INTR 3 206#define MD_RECOVERY_INTR 3
202#define MD_RECOVERY_DONE 4 207#define MD_RECOVERY_DONE 4
203#define MD_RECOVERY_NEEDED 5 208#define MD_RECOVERY_NEEDED 5
@@ -210,7 +215,8 @@ struct mddev_s
210 215
211 int in_sync; /* know to not need resync */ 216 int in_sync; /* know to not need resync */
212 struct mutex reconfig_mutex; 217 struct mutex reconfig_mutex;
213 atomic_t active; 218 atomic_t active; /* general refcount */
219 atomic_t openers; /* number of active opens */
214 220
215 int changed; /* true if we might need to reread partition info */ 221 int changed; /* true if we might need to reread partition info */
216 int degraded; /* whether md should consider 222 int degraded; /* whether md should consider
@@ -227,6 +233,8 @@ struct mddev_s
227 atomic_t recovery_active; /* blocks scheduled, but not written */ 233 atomic_t recovery_active; /* blocks scheduled, but not written */
228 wait_queue_head_t recovery_wait; 234 wait_queue_head_t recovery_wait;
229 sector_t recovery_cp; 235 sector_t recovery_cp;
236 sector_t resync_min; /* user requested sync
237 * starts here */
230 sector_t resync_max; /* resync should pause 238 sector_t resync_max; /* resync should pause
231 * when it gets here */ 239 * when it gets here */
232 240
@@ -331,6 +339,9 @@ static inline char * mdname (mddev_t * mddev)
331#define rdev_for_each(rdev, tmp, mddev) \ 339#define rdev_for_each(rdev, tmp, mddev) \
332 rdev_for_each_list(rdev, tmp, (mddev)->disks) 340 rdev_for_each_list(rdev, tmp, (mddev)->disks)
333 341
342#define rdev_for_each_rcu(rdev, mddev) \
343 list_for_each_entry_rcu(rdev, &((mddev)->disks), same_set)
344
334typedef struct mdk_thread_s { 345typedef struct mdk_thread_s {
335 void (*run) (mddev_t *mddev); 346 void (*run) (mddev_t *mddev);
336 mddev_t *mddev; 347 mddev_t *mddev;
diff --git a/include/linux/raid/md_p.h b/include/linux/raid/md_p.h
index 3f2cd98c508b..8b4de4a41ff1 100644
--- a/include/linux/raid/md_p.h
+++ b/include/linux/raid/md_p.h
@@ -43,14 +43,11 @@
43 */ 43 */
44#define MD_RESERVED_BYTES (64 * 1024) 44#define MD_RESERVED_BYTES (64 * 1024)
45#define MD_RESERVED_SECTORS (MD_RESERVED_BYTES / 512) 45#define MD_RESERVED_SECTORS (MD_RESERVED_BYTES / 512)
46#define MD_RESERVED_BLOCKS (MD_RESERVED_BYTES / BLOCK_SIZE)
47 46
48#define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS) 47#define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS)
49#define MD_NEW_SIZE_BLOCKS(x) ((x & ~(MD_RESERVED_BLOCKS - 1)) - MD_RESERVED_BLOCKS)
50 48
51#define MD_SB_BYTES 4096 49#define MD_SB_BYTES 4096
52#define MD_SB_WORDS (MD_SB_BYTES / 4) 50#define MD_SB_WORDS (MD_SB_BYTES / 4)
53#define MD_SB_BLOCKS (MD_SB_BYTES / BLOCK_SIZE)
54#define MD_SB_SECTORS (MD_SB_BYTES / 512) 51#define MD_SB_SECTORS (MD_SB_BYTES / 512)
55 52
56/* 53/*
diff --git a/include/linux/raid/raid5.h b/include/linux/raid/raid5.h
index f0827d31ae6f..3b2672792457 100644
--- a/include/linux/raid/raid5.h
+++ b/include/linux/raid/raid5.h
@@ -158,6 +158,43 @@
158 * the compute block completes. 158 * the compute block completes.
159 */ 159 */
160 160
161/*
162 * Operations state - intermediate states that are visible outside of sh->lock
163 * In general _idle indicates nothing is running, _run indicates a data
164 * processing operation is active, and _result means the data processing result
165 * is stable and can be acted upon. For simple operations like biofill and
166 * compute that only have an _idle and _run state they are indicated with
167 * sh->state flags (STRIPE_BIOFILL_RUN and STRIPE_COMPUTE_RUN)
168 */
169/**
170 * enum check_states - handles syncing / repairing a stripe
171 * @check_state_idle - check operations are quiesced
172 * @check_state_run - check operation is running
173 * @check_state_result - set outside lock when check result is valid
174 * @check_state_compute_run - check failed and we are repairing
175 * @check_state_compute_result - set outside lock when compute result is valid
176 */
177enum check_states {
178 check_state_idle = 0,
179 check_state_run, /* parity check */
180 check_state_check_result,
181 check_state_compute_run, /* parity repair */
182 check_state_compute_result,
183};
184
185/**
186 * enum reconstruct_states - handles writing or expanding a stripe
187 */
188enum reconstruct_states {
189 reconstruct_state_idle = 0,
190 reconstruct_state_prexor_drain_run, /* prexor-write */
191 reconstruct_state_drain_run, /* write */
192 reconstruct_state_run, /* expand */
193 reconstruct_state_prexor_drain_result,
194 reconstruct_state_drain_result,
195 reconstruct_state_result,
196};
197
161struct stripe_head { 198struct stripe_head {
162 struct hlist_node hash; 199 struct hlist_node hash;
163 struct list_head lru; /* inactive_list or handle_list */ 200 struct list_head lru; /* inactive_list or handle_list */
@@ -169,19 +206,13 @@ struct stripe_head {
169 spinlock_t lock; 206 spinlock_t lock;
170 int bm_seq; /* sequence number for bitmap flushes */ 207 int bm_seq; /* sequence number for bitmap flushes */
171 int disks; /* disks in stripe */ 208 int disks; /* disks in stripe */
209 enum check_states check_state;
210 enum reconstruct_states reconstruct_state;
172 /* stripe_operations 211 /* stripe_operations
173 * @pending - pending ops flags (set for request->issue->complete)
174 * @ack - submitted ops flags (set for issue->complete)
175 * @complete - completed ops flags (set for complete)
176 * @target - STRIPE_OP_COMPUTE_BLK target 212 * @target - STRIPE_OP_COMPUTE_BLK target
177 * @count - raid5_runs_ops is set to run when this is non-zero
178 */ 213 */
179 struct stripe_operations { 214 struct stripe_operations {
180 unsigned long pending;
181 unsigned long ack;
182 unsigned long complete;
183 int target; 215 int target;
184 int count;
185 u32 zero_sum_result; 216 u32 zero_sum_result;
186 } ops; 217 } ops;
187 struct r5dev { 218 struct r5dev {
@@ -202,6 +233,7 @@ struct stripe_head_state {
202 int locked, uptodate, to_read, to_write, failed, written; 233 int locked, uptodate, to_read, to_write, failed, written;
203 int to_fill, compute, req_compute, non_overwrite; 234 int to_fill, compute, req_compute, non_overwrite;
204 int failed_num; 235 int failed_num;
236 unsigned long ops_request;
205}; 237};
206 238
207/* r6_state - extra state data only relevant to r6 */ 239/* r6_state - extra state data only relevant to r6 */
@@ -228,9 +260,7 @@ struct r6_state {
228#define R5_Wantfill 12 /* dev->toread contains a bio that needs 260#define R5_Wantfill 12 /* dev->toread contains a bio that needs
229 * filling 261 * filling
230 */ 262 */
231#define R5_Wantprexor 13 /* distinguish blocks ready for rmw from 263#define R5_Wantdrain 13 /* dev->towrite needs to be drained */
232 * other "towrites"
233 */
234/* 264/*
235 * Write method 265 * Write method
236 */ 266 */
@@ -254,8 +284,10 @@ struct r6_state {
254#define STRIPE_EXPAND_READY 11 284#define STRIPE_EXPAND_READY 11
255#define STRIPE_IO_STARTED 12 /* do not count towards 'bypass_count' */ 285#define STRIPE_IO_STARTED 12 /* do not count towards 'bypass_count' */
256#define STRIPE_FULL_WRITE 13 /* all blocks are set to be overwritten */ 286#define STRIPE_FULL_WRITE 13 /* all blocks are set to be overwritten */
287#define STRIPE_BIOFILL_RUN 14
288#define STRIPE_COMPUTE_RUN 15
257/* 289/*
258 * Operations flags (in issue order) 290 * Operation request flags
259 */ 291 */
260#define STRIPE_OP_BIOFILL 0 292#define STRIPE_OP_BIOFILL 0
261#define STRIPE_OP_COMPUTE_BLK 1 293#define STRIPE_OP_COMPUTE_BLK 1
@@ -263,14 +295,6 @@ struct r6_state {
263#define STRIPE_OP_BIODRAIN 3 295#define STRIPE_OP_BIODRAIN 3
264#define STRIPE_OP_POSTXOR 4 296#define STRIPE_OP_POSTXOR 4
265#define STRIPE_OP_CHECK 5 297#define STRIPE_OP_CHECK 5
266#define STRIPE_OP_IO 6
267
268/* modifiers to the base operations
269 * STRIPE_OP_MOD_REPAIR_PD - compute the parity block and write it back
270 * STRIPE_OP_MOD_DMA_CHECK - parity is not corrupted by the check
271 */
272#define STRIPE_OP_MOD_REPAIR_PD 7
273#define STRIPE_OP_MOD_DMA_CHECK 8
274 298
275/* 299/*
276 * Plugging: 300 * Plugging:
diff --git a/include/linux/serio.h b/include/linux/serio.h
index 95674d97dabd..e72716cca577 100644
--- a/include/linux/serio.h
+++ b/include/linux/serio.h
@@ -175,7 +175,7 @@ static inline void serio_unpin_driver(struct serio *serio)
175#define SERIO_8042_XL 0x06 175#define SERIO_8042_XL 0x06
176 176
177/* 177/*
178 * Serio types 178 * Serio protocols
179 */ 179 */
180#define SERIO_UNKNOWN 0x00 180#define SERIO_UNKNOWN 0x00
181#define SERIO_MSC 0x01 181#define SERIO_MSC 0x01
@@ -212,5 +212,7 @@ static inline void serio_unpin_driver(struct serio *serio)
212#define SERIO_TAOSEVM 0x34 212#define SERIO_TAOSEVM 0x34
213#define SERIO_FUJITSU 0x35 213#define SERIO_FUJITSU 0x35
214#define SERIO_ZHENHUA 0x36 214#define SERIO_ZHENHUA 0x36
215#define SERIO_INEXIO 0x37
216#define SERIO_TOUCHIT213 0x37
215 217
216#endif 218#endif
diff --git a/include/linux/spi/max7301.h b/include/linux/spi/max7301.h
new file mode 100644
index 000000000000..6dfd83f19b4b
--- /dev/null
+++ b/include/linux/spi/max7301.h
@@ -0,0 +1,9 @@
1#ifndef LINUX_SPI_MAX7301_H
2#define LINUX_SPI_MAX7301_H
3
4struct max7301_platform_data {
5 /* number assigned to the first GPIO */
6 unsigned base;
7};
8
9#endif
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 387e428f1cdf..b9a76c972084 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -733,7 +733,7 @@ struct spi_board_info {
733 * controller_data goes to spi_device.controller_data, 733 * controller_data goes to spi_device.controller_data,
734 * irq is copied too 734 * irq is copied too
735 */ 735 */
736 char modalias[KOBJ_NAME_LEN]; 736 char modalias[32];
737 const void *platform_data; 737 const void *platform_data;
738 void *controller_data; 738 void *controller_data;
739 int irq; 739 int irq;
diff --git a/include/linux/synclink.h b/include/linux/synclink.h
index 45f6bc82d317..c844a229acc9 100644
--- a/include/linux/synclink.h
+++ b/include/linux/synclink.h
@@ -136,6 +136,7 @@
136#define MGSL_INTERFACE_RTS_EN 0x10 136#define MGSL_INTERFACE_RTS_EN 0x10
137#define MGSL_INTERFACE_LL 0x20 137#define MGSL_INTERFACE_LL 0x20
138#define MGSL_INTERFACE_RL 0x40 138#define MGSL_INTERFACE_RL 0x40
139#define MGSL_INTERFACE_MSB_FIRST 0x80
139 140
140typedef struct _MGSL_PARAMS 141typedef struct _MGSL_PARAMS
141{ 142{
diff --git a/include/linux/sysdev.h b/include/linux/sysdev.h
index f2767bc6b735..f395bb3fa2f2 100644
--- a/include/linux/sysdev.h
+++ b/include/linux/sysdev.h
@@ -99,8 +99,9 @@ extern void sysdev_unregister(struct sys_device *);
99 99
100struct sysdev_attribute { 100struct sysdev_attribute {
101 struct attribute attr; 101 struct attribute attr;
102 ssize_t (*show)(struct sys_device *, char *); 102 ssize_t (*show)(struct sys_device *, struct sysdev_attribute *, char *);
103 ssize_t (*store)(struct sys_device *, const char *, size_t); 103 ssize_t (*store)(struct sys_device *, struct sysdev_attribute *,
104 const char *, size_t);
104}; 105};
105 106
106 107
@@ -118,4 +119,38 @@ struct sysdev_attribute {
118extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *); 119extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *);
119extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *); 120extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *);
120 121
122struct sysdev_ext_attribute {
123 struct sysdev_attribute attr;
124 void *var;
125};
126
127/*
128 * Support for simple variable sysdev attributes.
129 * The pointer to the variable is stored in a sysdev_ext_attribute
130 */
131
132/* Add more types as needed */
133
134extern ssize_t sysdev_show_ulong(struct sys_device *, struct sysdev_attribute *,
135 char *);
136extern ssize_t sysdev_store_ulong(struct sys_device *,
137 struct sysdev_attribute *, const char *, size_t);
138extern ssize_t sysdev_show_int(struct sys_device *, struct sysdev_attribute *,
139 char *);
140extern ssize_t sysdev_store_int(struct sys_device *,
141 struct sysdev_attribute *, const char *, size_t);
142
143#define _SYSDEV_ULONG_ATTR(_name, _mode, _var) \
144 { _SYSDEV_ATTR(_name, _mode, sysdev_show_ulong, sysdev_store_ulong), \
145 &(_var) }
146#define SYSDEV_ULONG_ATTR(_name, _mode, _var) \
147 struct sysdev_ext_attribute attr_##_name = \
148 _SYSDEV_ULONG_ATTR(_name, _mode, _var);
149#define _SYSDEV_INT_ATTR(_name, _mode, _var) \
150 { _SYSDEV_ATTR(_name, _mode, sysdev_show_int, sysdev_store_int), \
151 &(_var) }
152#define SYSDEV_INT_ATTR(_name, _mode, _var) \
153 struct sysdev_ext_attribute attr_##_name = \
154 _SYSDEV_INT_ATTR(_name, _mode, _var);
155
121#endif /* _SYSDEV_H_ */ 156#endif /* _SYSDEV_H_ */
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 7858eac40aa7..37fa24152bd8 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -101,6 +101,9 @@ void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
101 101
102int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target, 102int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
103 const char *name); 103 const char *name);
104int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
105 struct kobject *target,
106 const char *name);
104void sysfs_remove_link(struct kobject *kobj, const char *name); 107void sysfs_remove_link(struct kobject *kobj, const char *name);
105 108
106int __must_check sysfs_create_group(struct kobject *kobj, 109int __must_check sysfs_create_group(struct kobject *kobj,
@@ -180,6 +183,13 @@ static inline int sysfs_create_link(struct kobject *kobj,
180 return 0; 183 return 0;
181} 184}
182 185
186static inline int sysfs_create_link_nowarn(struct kobject *kobj,
187 struct kobject *target,
188 const char *name)
189{
190 return 0;
191}
192
183static inline void sysfs_remove_link(struct kobject *kobj, const char *name) 193static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
184{ 194{
185} 195}
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 4e5833073aa6..e3579cb086e0 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -317,8 +317,6 @@ extern void tty_wait_until_sent(struct tty_struct *tty, long timeout);
317extern int tty_check_change(struct tty_struct *tty); 317extern int tty_check_change(struct tty_struct *tty);
318extern void stop_tty(struct tty_struct *tty); 318extern void stop_tty(struct tty_struct *tty);
319extern void start_tty(struct tty_struct *tty); 319extern void start_tty(struct tty_struct *tty);
320extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
321extern int tty_unregister_ldisc(int disc);
322extern int tty_register_driver(struct tty_driver *driver); 320extern int tty_register_driver(struct tty_driver *driver);
323extern int tty_unregister_driver(struct tty_driver *driver); 321extern int tty_unregister_driver(struct tty_driver *driver);
324extern struct device *tty_register_device(struct tty_driver *driver, 322extern struct device *tty_register_device(struct tty_driver *driver,
@@ -383,6 +381,15 @@ extern void tty_port_init(struct tty_port *port);
383extern int tty_port_alloc_xmit_buf(struct tty_port *port); 381extern int tty_port_alloc_xmit_buf(struct tty_port *port);
384extern void tty_port_free_xmit_buf(struct tty_port *port); 382extern void tty_port_free_xmit_buf(struct tty_port *port);
385 383
384extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
385extern int tty_unregister_ldisc(int disc);
386extern int tty_set_ldisc(struct tty_struct *tty, int ldisc);
387extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);
388extern void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty);
389extern void tty_ldisc_init(struct tty_struct *tty);
390extern void tty_ldisc_begin(void);
391/* This last one is just for the tty layer internals and shouldn't be used elsewhere */
392extern void tty_ldisc_enable(struct tty_struct *tty);
386 393
387 394
388/* n_tty.c */ 395/* n_tty.c */
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index d2a003586761..e1065ac0d922 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -135,7 +135,7 @@
135 * 135 *
136 * Optional: 136 * Optional:
137 * 137 *
138 * void (*break_ctl)(struct tty_stuct *tty, int state); 138 * int (*break_ctl)(struct tty_stuct *tty, int state);
139 * 139 *
140 * This optional routine requests the tty driver to turn on or 140 * This optional routine requests the tty driver to turn on or
141 * off BREAK status on the RS-232 port. If state is -1, 141 * off BREAK status on the RS-232 port. If state is -1,
@@ -146,6 +146,10 @@
146 * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK, 146 * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK,
147 * TIOCCBRK. 147 * TIOCCBRK.
148 * 148 *
149 * If the driver sets TTY_DRIVER_HARDWARE_BREAK then the interface
150 * will also be called with actual times and the hardware is expected
151 * to do the delay work itself. 0 and -1 are still used for on/off.
152 *
149 * Optional: Required for TCSBRK/BRKP/etc handling. 153 * Optional: Required for TCSBRK/BRKP/etc handling.
150 * 154 *
151 * void (*wait_until_sent)(struct tty_struct *tty, int timeout); 155 * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
@@ -192,7 +196,7 @@ struct tty_operations {
192 void (*stop)(struct tty_struct *tty); 196 void (*stop)(struct tty_struct *tty);
193 void (*start)(struct tty_struct *tty); 197 void (*start)(struct tty_struct *tty);
194 void (*hangup)(struct tty_struct *tty); 198 void (*hangup)(struct tty_struct *tty);
195 void (*break_ctl)(struct tty_struct *tty, int state); 199 int (*break_ctl)(struct tty_struct *tty, int state);
196 void (*flush_buffer)(struct tty_struct *tty); 200 void (*flush_buffer)(struct tty_struct *tty);
197 void (*set_ldisc)(struct tty_struct *tty); 201 void (*set_ldisc)(struct tty_struct *tty);
198 void (*wait_until_sent)(struct tty_struct *tty, int timeout); 202 void (*wait_until_sent)(struct tty_struct *tty, int timeout);
@@ -285,12 +289,18 @@ extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
285 * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead 289 * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead
286 * use dynamic memory keyed through the devpts filesystem. This 290 * use dynamic memory keyed through the devpts filesystem. This
287 * is only applicable to the pty driver. 291 * is only applicable to the pty driver.
292 *
293 * TTY_DRIVER_HARDWARE_BREAK -- hardware handles break signals. Pass
294 * the requested timeout to the caller instead of using a simple
295 * on/off interface.
296 *
288 */ 297 */
289#define TTY_DRIVER_INSTALLED 0x0001 298#define TTY_DRIVER_INSTALLED 0x0001
290#define TTY_DRIVER_RESET_TERMIOS 0x0002 299#define TTY_DRIVER_RESET_TERMIOS 0x0002
291#define TTY_DRIVER_REAL_RAW 0x0004 300#define TTY_DRIVER_REAL_RAW 0x0004
292#define TTY_DRIVER_DYNAMIC_DEV 0x0008 301#define TTY_DRIVER_DYNAMIC_DEV 0x0008
293#define TTY_DRIVER_DEVPTS_MEM 0x0010 302#define TTY_DRIVER_DEVPTS_MEM 0x0010
303#define TTY_DRIVER_HARDWARE_BREAK 0x0020
294 304
295/* tty driver types */ 305/* tty driver types */
296#define TTY_DRIVER_TYPE_SYSTEM 0x0001 306#define TTY_DRIVER_TYPE_SYSTEM 0x0001
diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index 973386d439da..cdf338d94b7f 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -36,7 +36,7 @@ struct uio_mem {
36 struct uio_map *map; 36 struct uio_map *map;
37}; 37};
38 38
39#define MAX_UIO_MAPS 5 39#define MAX_UIO_MAPS 5
40 40
41struct uio_device; 41struct uio_device;
42 42
@@ -53,6 +53,7 @@ struct uio_device;
53 * @mmap: mmap operation for this uio device 53 * @mmap: mmap operation for this uio device
54 * @open: open operation for this uio device 54 * @open: open operation for this uio device
55 * @release: release operation for this uio device 55 * @release: release operation for this uio device
56 * @irqcontrol: disable/enable irqs when 0/1 is written to /dev/uioX
56 */ 57 */
57struct uio_info { 58struct uio_info {
58 struct uio_device *uio_dev; 59 struct uio_device *uio_dev;
@@ -66,6 +67,7 @@ struct uio_info {
66 int (*mmap)(struct uio_info *info, struct vm_area_struct *vma); 67 int (*mmap)(struct uio_info *info, struct vm_area_struct *vma);
67 int (*open)(struct uio_info *info, struct inode *inode); 68 int (*open)(struct uio_info *info, struct inode *inode);
68 int (*release)(struct uio_info *info, struct inode *inode); 69 int (*release)(struct uio_info *info, struct inode *inode);
70 int (*irqcontrol)(struct uio_info *info, s32 irq_on);
69}; 71};
70 72
71extern int __must_check 73extern int __must_check
@@ -80,11 +82,11 @@ static inline int __must_check
80extern void uio_unregister_device(struct uio_info *info); 82extern void uio_unregister_device(struct uio_info *info);
81extern void uio_event_notify(struct uio_info *info); 83extern void uio_event_notify(struct uio_info *info);
82 84
83/* defines for uio_device->irq */ 85/* defines for uio_info->irq */
84#define UIO_IRQ_CUSTOM -1 86#define UIO_IRQ_CUSTOM -1
85#define UIO_IRQ_NONE -2 87#define UIO_IRQ_NONE -2
86 88
87/* defines for uio_device->memtype */ 89/* defines for uio_mem->memtype */
88#define UIO_MEM_NONE 0 90#define UIO_MEM_NONE 0
89#define UIO_MEM_PHYS 1 91#define UIO_MEM_PHYS 1
90#define UIO_MEM_LOGICAL 2 92#define UIO_MEM_LOGICAL 2
diff --git a/include/linux/usb.h b/include/linux/usb.h
index c08689ea9b4b..5811c5da69f9 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -160,6 +160,7 @@ struct usb_interface {
160 unsigned is_active:1; /* the interface is not suspended */ 160 unsigned is_active:1; /* the interface is not suspended */
161 unsigned sysfs_files_created:1; /* the sysfs attributes exist */ 161 unsigned sysfs_files_created:1; /* the sysfs attributes exist */
162 unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */ 162 unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */
163 unsigned needs_binding:1; /* needs delayed unbind/rebind */
163 164
164 struct device dev; /* interface specific device info */ 165 struct device dev; /* interface specific device info */
165 struct device *usb_dev; 166 struct device *usb_dev;
@@ -293,7 +294,7 @@ struct usb_devmap {
293struct usb_bus { 294struct usb_bus {
294 struct device *controller; /* host/master side hardware */ 295 struct device *controller; /* host/master side hardware */
295 int busnum; /* Bus number (in order of reg) */ 296 int busnum; /* Bus number (in order of reg) */
296 char *bus_name; /* stable id (PCI slot_name etc) */ 297 const char *bus_name; /* stable id (PCI slot_name etc) */
297 u8 uses_dma; /* Does the host controller use DMA? */ 298 u8 uses_dma; /* Does the host controller use DMA? */
298 u8 otg_port; /* 0, or number of OTG/HNP port */ 299 u8 otg_port; /* 0, or number of OTG/HNP port */
299 unsigned is_b_host:1; /* true during some HNP roleswitches */ 300 unsigned is_b_host:1; /* true during some HNP roleswitches */
@@ -497,8 +498,6 @@ extern int usb_lock_device_for_reset(struct usb_device *udev,
497 498
498/* USB port reset for device reinitialization */ 499/* USB port reset for device reinitialization */
499extern int usb_reset_device(struct usb_device *dev); 500extern int usb_reset_device(struct usb_device *dev);
500extern int usb_reset_composite_device(struct usb_device *dev,
501 struct usb_interface *iface);
502 501
503extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id); 502extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id);
504 503
@@ -958,9 +957,9 @@ struct usbdrv_wrap {
958 * @resume: Called when the device is being resumed by the system. 957 * @resume: Called when the device is being resumed by the system.
959 * @reset_resume: Called when the suspended device has been reset instead 958 * @reset_resume: Called when the suspended device has been reset instead
960 * of being resumed. 959 * of being resumed.
961 * @pre_reset: Called by usb_reset_composite_device() when the device 960 * @pre_reset: Called by usb_reset_device() when the device
962 * is about to be reset. 961 * is about to be reset.
963 * @post_reset: Called by usb_reset_composite_device() after the device 962 * @post_reset: Called by usb_reset_device() after the device
964 * has been reset 963 * has been reset
965 * @id_table: USB drivers use ID table to support hotplugging. 964 * @id_table: USB drivers use ID table to support hotplugging.
966 * Export this with MODULE_DEVICE_TABLE(usb,...). This must be set 965 * Export this with MODULE_DEVICE_TABLE(usb,...). This must be set
@@ -972,6 +971,8 @@ struct usbdrv_wrap {
972 * added to this driver by preventing the sysfs file from being created. 971 * added to this driver by preventing the sysfs file from being created.
973 * @supports_autosuspend: if set to 0, the USB core will not allow autosuspend 972 * @supports_autosuspend: if set to 0, the USB core will not allow autosuspend
974 * for interfaces bound to this driver. 973 * for interfaces bound to this driver.
974 * @soft_unbind: if set to 1, the USB core will not kill URBs and disable
975 * endpoints before calling the driver's disconnect method.
975 * 976 *
976 * USB interface drivers must provide a name, probe() and disconnect() 977 * USB interface drivers must provide a name, probe() and disconnect()
977 * methods, and an id_table. Other driver fields are optional. 978 * methods, and an id_table. Other driver fields are optional.
@@ -1012,6 +1013,7 @@ struct usb_driver {
1012 struct usbdrv_wrap drvwrap; 1013 struct usbdrv_wrap drvwrap;
1013 unsigned int no_dynamic_id:1; 1014 unsigned int no_dynamic_id:1;
1014 unsigned int supports_autosuspend:1; 1015 unsigned int supports_autosuspend:1;
1016 unsigned int soft_unbind:1;
1015}; 1017};
1016#define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver) 1018#define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver)
1017 1019
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
new file mode 100644
index 000000000000..747c3a49cdc9
--- /dev/null
+++ b/include/linux/usb/composite.h
@@ -0,0 +1,338 @@
1/*
2 * composite.h -- framework for usb gadgets which are composite devices
3 *
4 * Copyright (C) 2006-2008 David Brownell
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef __LINUX_USB_COMPOSITE_H
22#define __LINUX_USB_COMPOSITE_H
23
24/*
25 * This framework is an optional layer on top of the USB Gadget interface,
26 * making it easier to build (a) Composite devices, supporting multiple
27 * functions within any single configuration, and (b) Multi-configuration
28 * devices, also supporting multiple functions but without necessarily
29 * having more than one function per configuration.
30 *
31 * Example: a device with a single configuration supporting both network
32 * link and mass storage functions is a composite device. Those functions
33 * might alternatively be packaged in individual configurations, but in
34 * the composite model the host can use both functions at the same time.
35 */
36
37#include <linux/usb/ch9.h>
38#include <linux/usb/gadget.h>
39
40
41struct usb_configuration;
42
43/**
44 * struct usb_function - describes one function of a configuration
45 * @name: For diagnostics, identifies the function.
46 * @strings: tables of strings, keyed by identifiers assigned during bind()
47 * and by language IDs provided in control requests
48 * @descriptors: Table of full (or low) speed descriptors, using interface and
49 * string identifiers assigned during @bind(). If this pointer is null,
50 * the function will not be available at full speed (or at low speed).
51 * @hs_descriptors: Table of high speed descriptors, using interface and
52 * string identifiers assigned during @bind(). If this pointer is null,
53 * the function will not be available at high speed.
54 * @config: assigned when @usb_add_function() is called; this is the
55 * configuration with which this function is associated.
56 * @bind: Before the gadget can register, all of its functions bind() to the
57 * available resources including string and interface identifiers used
58 * in interface or class descriptors; endpoints; I/O buffers; and so on.
59 * @unbind: Reverses @bind; called as a side effect of unregistering the
60 * driver which added this function.
61 * @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may
62 * initialize usb_ep.driver data at this time (when it is used).
63 * Note that setting an interface to its current altsetting resets
64 * interface state, and that all interfaces have a disabled state.
65 * @get_alt: Returns the active altsetting. If this is not provided,
66 * then only altsetting zero is supported.
67 * @disable: (REQUIRED) Indicates the function should be disabled. Reasons
68 * include host resetting or reconfiguring the gadget, and disconnection.
69 * @setup: Used for interface-specific control requests.
70 * @suspend: Notifies functions when the host stops sending USB traffic.
71 * @resume: Notifies functions when the host restarts USB traffic.
72 *
73 * A single USB function uses one or more interfaces, and should in most
74 * cases support operation at both full and high speeds. Each function is
75 * associated by @usb_add_function() with a one configuration; that function
76 * causes @bind() to be called so resources can be allocated as part of
77 * setting up a gadget driver. Those resources include endpoints, which
78 * should be allocated using @usb_ep_autoconfig().
79 *
80 * To support dual speed operation, a function driver provides descriptors
81 * for both high and full speed operation. Except in rare cases that don't
82 * involve bulk endpoints, each speed needs different endpoint descriptors.
83 *
84 * Function drivers choose their own strategies for managing instance data.
85 * The simplest strategy just declares it "static', which means the function
86 * can only be activated once. If the function needs to be exposed in more
87 * than one configuration at a given speed, it needs to support multiple
88 * usb_function structures (one for each configuration).
89 *
90 * A more complex strategy might encapsulate a @usb_function structure inside
91 * a driver-specific instance structure to allows multiple activations. An
92 * example of multiple activations might be a CDC ACM function that supports
93 * two or more distinct instances within the same configuration, providing
94 * several independent logical data links to a USB host.
95 */
96struct usb_function {
97 const char *name;
98 struct usb_gadget_strings **strings;
99 struct usb_descriptor_header **descriptors;
100 struct usb_descriptor_header **hs_descriptors;
101
102 struct usb_configuration *config;
103
104 /* REVISIT: bind() functions can be marked __init, which
105 * makes trouble for section mismatch analysis. See if
106 * we can't restructure things to avoid mismatching.
107 * Related: unbind() may kfree() but bind() won't...
108 */
109
110 /* configuration management: bind/unbind */
111 int (*bind)(struct usb_configuration *,
112 struct usb_function *);
113 void (*unbind)(struct usb_configuration *,
114 struct usb_function *);
115
116 /* runtime state management */
117 int (*set_alt)(struct usb_function *,
118 unsigned interface, unsigned alt);
119 int (*get_alt)(struct usb_function *,
120 unsigned interface);
121 void (*disable)(struct usb_function *);
122 int (*setup)(struct usb_function *,
123 const struct usb_ctrlrequest *);
124 void (*suspend)(struct usb_function *);
125 void (*resume)(struct usb_function *);
126
127 /* internals */
128 struct list_head list;
129};
130
131int usb_add_function(struct usb_configuration *, struct usb_function *);
132
133int usb_interface_id(struct usb_configuration *, struct usb_function *);
134
135/**
136 * ep_choose - select descriptor endpoint at current device speed
137 * @g: gadget, connected and running at some speed
138 * @hs: descriptor to use for high speed operation
139 * @fs: descriptor to use for full or low speed operation
140 */
141static inline struct usb_endpoint_descriptor *
142ep_choose(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
143 struct usb_endpoint_descriptor *fs)
144{
145 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
146 return hs;
147 return fs;
148}
149
150#define MAX_CONFIG_INTERFACES 16 /* arbitrary; max 255 */
151
152/**
153 * struct usb_configuration - represents one gadget configuration
154 * @label: For diagnostics, describes the configuration.
155 * @strings: Tables of strings, keyed by identifiers assigned during @bind()
156 * and by language IDs provided in control requests.
157 * @descriptors: Table of descriptors preceding all function descriptors.
158 * Examples include OTG and vendor-specific descriptors.
159 * @bind: Called from @usb_add_config() to allocate resources unique to this
160 * configuration and to call @usb_add_function() for each function used.
161 * @unbind: Reverses @bind; called as a side effect of unregistering the
162 * driver which added this configuration.
163 * @setup: Used to delegate control requests that aren't handled by standard
164 * device infrastructure or directed at a specific interface.
165 * @bConfigurationValue: Copied into configuration descriptor.
166 * @iConfiguration: Copied into configuration descriptor.
167 * @bmAttributes: Copied into configuration descriptor.
168 * @bMaxPower: Copied into configuration descriptor.
169 * @cdev: assigned by @usb_add_config() before calling @bind(); this is
170 * the device associated with this configuration.
171 *
172 * Configurations are building blocks for gadget drivers structured around
173 * function drivers. Simple USB gadgets require only one function and one
174 * configuration, and handle dual-speed hardware by always providing the same
175 * functionality. Slightly more complex gadgets may have more than one
176 * single-function configuration at a given speed; or have configurations
177 * that only work at one speed.
178 *
179 * Composite devices are, by definition, ones with configurations which
180 * include more than one function.
181 *
182 * The lifecycle of a usb_configuration includes allocation, initialization
183 * of the fields described above, and calling @usb_add_config() to set up
184 * internal data and bind it to a specific device. The configuration's
185 * @bind() method is then used to initialize all the functions and then
186 * call @usb_add_function() for them.
187 *
188 * Those functions would normally be independant of each other, but that's
189 * not mandatory. CDC WMC devices are an example where functions often
190 * depend on other functions, with some functions subsidiary to others.
191 * Such interdependency may be managed in any way, so long as all of the
192 * descriptors complete by the time the composite driver returns from
193 * its bind() routine.
194 */
195struct usb_configuration {
196 const char *label;
197 struct usb_gadget_strings **strings;
198 const struct usb_descriptor_header **descriptors;
199
200 /* REVISIT: bind() functions can be marked __init, which
201 * makes trouble for section mismatch analysis. See if
202 * we can't restructure things to avoid mismatching...
203 */
204
205 /* configuration management: bind/unbind */
206 int (*bind)(struct usb_configuration *);
207 void (*unbind)(struct usb_configuration *);
208 int (*setup)(struct usb_configuration *,
209 const struct usb_ctrlrequest *);
210
211 /* fields in the config descriptor */
212 u8 bConfigurationValue;
213 u8 iConfiguration;
214 u8 bmAttributes;
215 u8 bMaxPower;
216
217 struct usb_composite_dev *cdev;
218
219 /* internals */
220 struct list_head list;
221 struct list_head functions;
222 u8 next_interface_id;
223 unsigned highspeed:1;
224 unsigned fullspeed:1;
225 struct usb_function *interface[MAX_CONFIG_INTERFACES];
226};
227
228int usb_add_config(struct usb_composite_dev *,
229 struct usb_configuration *);
230
231/**
232 * struct usb_composite_driver - groups configurations into a gadget
233 * @name: For diagnostics, identifies the driver.
234 * @dev: Template descriptor for the device, including default device
235 * identifiers.
236 * @strings: tables of strings, keyed by identifiers assigned during bind()
237 * and language IDs provided in control requests
238 * @bind: (REQUIRED) Used to allocate resources that are shared across the
239 * whole device, such as string IDs, and add its configurations using
240 * @usb_add_config(). This may fail by returning a negative errno
241 * value; it should return zero on successful initialization.
242 * @unbind: Reverses @bind(); called as a side effect of unregistering
243 * this driver.
244 *
245 * Devices default to reporting self powered operation. Devices which rely
246 * on bus powered operation should report this in their @bind() method.
247 *
248 * Before returning from @bind, various fields in the template descriptor
249 * may be overridden. These include the idVendor/idProduct/bcdDevice values
250 * normally to bind the appropriate host side driver, and the three strings
251 * (iManufacturer, iProduct, iSerialNumber) normally used to provide user
252 * meaningful device identifiers. (The strings will not be defined unless
253 * they are defined in @dev and @strings.) The correct ep0 maxpacket size
254 * is also reported, as defined by the underlying controller driver.
255 */
256struct usb_composite_driver {
257 const char *name;
258 const struct usb_device_descriptor *dev;
259 struct usb_gadget_strings **strings;
260
261 /* REVISIT: bind() functions can be marked __init, which
262 * makes trouble for section mismatch analysis. See if
263 * we can't restructure things to avoid mismatching...
264 */
265
266 int (*bind)(struct usb_composite_dev *);
267 int (*unbind)(struct usb_composite_dev *);
268};
269
270extern int usb_composite_register(struct usb_composite_driver *);
271extern void usb_composite_unregister(struct usb_composite_driver *);
272
273
274/**
275 * struct usb_composite_device - represents one composite usb gadget
276 * @gadget: read-only, abstracts the gadget's usb peripheral controller
277 * @req: used for control responses; buffer is pre-allocated
278 * @bufsiz: size of buffer pre-allocated in @req
279 * @config: the currently active configuration
280 *
281 * One of these devices is allocated and initialized before the
282 * associated device driver's bind() is called.
283 *
284 * OPEN ISSUE: it appears that some WUSB devices will need to be
285 * built by combining a normal (wired) gadget with a wireless one.
286 * This revision of the gadget framework should probably try to make
287 * sure doing that won't hurt too much.
288 *
289 * One notion for how to handle Wireless USB devices involves:
290 * (a) a second gadget here, discovery mechanism TBD, but likely
291 * needing separate "register/unregister WUSB gadget" calls;
292 * (b) updates to usb_gadget to include flags "is it wireless",
293 * "is it wired", plus (presumably in a wrapper structure)
294 * bandgroup and PHY info;
295 * (c) presumably a wireless_ep wrapping a usb_ep, and reporting
296 * wireless-specific parameters like maxburst and maxsequence;
297 * (d) configurations that are specific to wireless links;
298 * (e) function drivers that understand wireless configs and will
299 * support wireless for (additional) function instances;
300 * (f) a function to support association setup (like CBAF), not
301 * necessarily requiring a wireless adapter;
302 * (g) composite device setup that can create one or more wireless
303 * configs, including appropriate association setup support;
304 * (h) more, TBD.
305 */
306struct usb_composite_dev {
307 struct usb_gadget *gadget;
308 struct usb_request *req;
309 unsigned bufsiz;
310
311 struct usb_configuration *config;
312
313 /* internals */
314 struct usb_device_descriptor desc;
315 struct list_head configs;
316 struct usb_composite_driver *driver;
317 u8 next_string_id;
318
319 spinlock_t lock;
320
321 /* REVISIT use and existence of lock ... */
322};
323
324extern int usb_string_id(struct usb_composite_dev *c);
325
326/* messaging utils */
327#define DBG(d, fmt, args...) \
328 dev_dbg(&(d)->gadget->dev , fmt , ## args)
329#define VDBG(d, fmt, args...) \
330 dev_vdbg(&(d)->gadget->dev , fmt , ## args)
331#define ERROR(d, fmt, args...) \
332 dev_err(&(d)->gadget->dev , fmt , ## args)
333#define WARN(d, fmt, args...) \
334 dev_warn(&(d)->gadget->dev , fmt , ## args)
335#define INFO(d, fmt, args...) \
336 dev_info(&(d)->gadget->dev , fmt , ## args)
337
338#endif /* __LINUX_USB_COMPOSITE_H */
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index cf468fbdbf8e..0460a746480c 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -33,7 +33,8 @@ struct usb_ep;
33 * @short_not_ok: When reading data, makes short packets be 33 * @short_not_ok: When reading data, makes short packets be
34 * treated as errors (queue stops advancing till cleanup). 34 * treated as errors (queue stops advancing till cleanup).
35 * @complete: Function called when request completes, so this request and 35 * @complete: Function called when request completes, so this request and
36 * its buffer may be re-used. 36 * its buffer may be re-used. The function will always be called with
37 * interrupts disabled, and it must not sleep.
37 * Reads terminate with a short packet, or when the buffer fills, 38 * Reads terminate with a short packet, or when the buffer fills,
38 * whichever comes first. When writes terminate, some data bytes 39 * whichever comes first. When writes terminate, some data bytes
39 * will usually still be in flight (often in a hardware fifo). 40 * will usually still be in flight (often in a hardware fifo).
@@ -271,7 +272,10 @@ static inline void usb_ep_free_request(struct usb_ep *ep,
271 * (Note that some USB device controllers disallow protocol stall responses 272 * (Note that some USB device controllers disallow protocol stall responses
272 * in some cases.) When control responses are deferred (the response is 273 * in some cases.) When control responses are deferred (the response is
273 * written after the setup callback returns), then usb_ep_set_halt() may be 274 * written after the setup callback returns), then usb_ep_set_halt() may be
274 * used on ep0 to trigger protocol stalls. 275 * used on ep0 to trigger protocol stalls. Depending on the controller,
276 * it may not be possible to trigger a status-stage protocol stall when the
277 * data stage is over, that is, from within the response's completion
278 * routine.
275 * 279 *
276 * For periodic endpoints, like interrupt or isochronous ones, the usb host 280 * For periodic endpoints, like interrupt or isochronous ones, the usb host
277 * arranges to poll once per interval, and the gadget driver usually will 281 * arranges to poll once per interval, and the gadget driver usually will
@@ -858,6 +862,25 @@ int usb_descriptor_fillbuf(void *, unsigned,
858int usb_gadget_config_buf(const struct usb_config_descriptor *config, 862int usb_gadget_config_buf(const struct usb_config_descriptor *config,
859 void *buf, unsigned buflen, const struct usb_descriptor_header **desc); 863 void *buf, unsigned buflen, const struct usb_descriptor_header **desc);
860 864
865/* copy a NULL-terminated vector of descriptors */
866struct usb_descriptor_header **usb_copy_descriptors(
867 struct usb_descriptor_header **);
868
869/* return copy of endpoint descriptor given original descriptor set */
870struct usb_endpoint_descriptor *usb_find_endpoint(
871 struct usb_descriptor_header **src,
872 struct usb_descriptor_header **copy,
873 struct usb_endpoint_descriptor *match);
874
875/**
876 * usb_free_descriptors - free descriptors returned by usb_copy_descriptors()
877 * @v: vector of descriptors
878 */
879static inline void usb_free_descriptors(struct usb_descriptor_header **v)
880{
881 kfree(v);
882}
883
861/*-------------------------------------------------------------------------*/ 884/*-------------------------------------------------------------------------*/
862 885
863/* utility wrapping a simple endpoint selection policy */ 886/* utility wrapping a simple endpoint selection policy */
diff --git a/include/linux/usb/irda.h b/include/linux/usb/irda.h
new file mode 100644
index 000000000000..e345ceaf72d6
--- /dev/null
+++ b/include/linux/usb/irda.h
@@ -0,0 +1,151 @@
1/*
2 * USB IrDA Bridge Device Definition
3 */
4
5#ifndef __LINUX_USB_IRDA_H
6#define __LINUX_USB_IRDA_H
7
8/* This device should use Application-specific class */
9
10#define USB_SUBCLASS_IRDA 0x02
11
12/*-------------------------------------------------------------------------*/
13
14/* Class-Specific requests (bRequest field) */
15
16#define USB_REQ_CS_IRDA_RECEIVING 1
17#define USB_REQ_CS_IRDA_CHECK_MEDIA_BUSY 3
18#define USB_REQ_CS_IRDA_RATE_SNIFF 4
19#define USB_REQ_CS_IRDA_UNICAST_LIST 5
20#define USB_REQ_CS_IRDA_GET_CLASS_DESC 6
21
22/*-------------------------------------------------------------------------*/
23
24/* Class-Specific descriptor */
25
26#define USB_DT_CS_IRDA 0x21
27
28/*-------------------------------------------------------------------------*/
29
30/* Data sizes */
31
32#define USB_IRDA_DS_2048 (1 << 5)
33#define USB_IRDA_DS_1024 (1 << 4)
34#define USB_IRDA_DS_512 (1 << 3)
35#define USB_IRDA_DS_256 (1 << 2)
36#define USB_IRDA_DS_128 (1 << 1)
37#define USB_IRDA_DS_64 (1 << 0)
38
39/* Window sizes */
40
41#define USB_IRDA_WS_7 (1 << 6)
42#define USB_IRDA_WS_6 (1 << 5)
43#define USB_IRDA_WS_5 (1 << 4)
44#define USB_IRDA_WS_4 (1 << 3)
45#define USB_IRDA_WS_3 (1 << 2)
46#define USB_IRDA_WS_2 (1 << 1)
47#define USB_IRDA_WS_1 (1 << 0)
48
49/* Min turnaround times in usecs */
50
51#define USB_IRDA_MTT_0 (1 << 7)
52#define USB_IRDA_MTT_10 (1 << 6)
53#define USB_IRDA_MTT_50 (1 << 5)
54#define USB_IRDA_MTT_100 (1 << 4)
55#define USB_IRDA_MTT_500 (1 << 3)
56#define USB_IRDA_MTT_1000 (1 << 2)
57#define USB_IRDA_MTT_5000 (1 << 1)
58#define USB_IRDA_MTT_10000 (1 << 0)
59
60/* Baud rates */
61
62#define USB_IRDA_BR_4000000 (1 << 8)
63#define USB_IRDA_BR_1152000 (1 << 7)
64#define USB_IRDA_BR_576000 (1 << 6)
65#define USB_IRDA_BR_115200 (1 << 5)
66#define USB_IRDA_BR_57600 (1 << 4)
67#define USB_IRDA_BR_38400 (1 << 3)
68#define USB_IRDA_BR_19200 (1 << 2)
69#define USB_IRDA_BR_9600 (1 << 1)
70#define USB_IRDA_BR_2400 (1 << 0)
71
72/* Additional BOFs */
73
74#define USB_IRDA_AB_0 (1 << 7)
75#define USB_IRDA_AB_1 (1 << 6)
76#define USB_IRDA_AB_2 (1 << 5)
77#define USB_IRDA_AB_3 (1 << 4)
78#define USB_IRDA_AB_6 (1 << 3)
79#define USB_IRDA_AB_12 (1 << 2)
80#define USB_IRDA_AB_24 (1 << 1)
81#define USB_IRDA_AB_48 (1 << 0)
82
83/* IRDA Rate Sniff */
84
85#define USB_IRDA_RATE_SNIFF 1
86
87/*-------------------------------------------------------------------------*/
88
89struct usb_irda_cs_descriptor {
90 __u8 bLength;
91 __u8 bDescriptorType;
92
93 __le16 bcdSpecRevision;
94 __u8 bmDataSize;
95 __u8 bmWindowSize;
96 __u8 bmMinTurnaroundTime;
97 __le16 wBaudRate;
98 __u8 bmAdditionalBOFs;
99 __u8 bIrdaRateSniff;
100 __u8 bMaxUnicastList;
101} __attribute__ ((packed));
102
103/*-------------------------------------------------------------------------*/
104
105/* Data Format */
106
107#define USB_IRDA_STATUS_MEDIA_BUSY (1 << 7)
108
109/* The following is a 4-bit value used for both
110 * inbound and outbound headers:
111 *
112 * 0 - speed ignored
113 * 1 - 2400 bps
114 * 2 - 9600 bps
115 * 3 - 19200 bps
116 * 4 - 38400 bps
117 * 5 - 57600 bps
118 * 6 - 115200 bps
119 * 7 - 576000 bps
120 * 8 - 1.152 Mbps
121 * 9 - 5 mbps
122 * 10..15 - Reserved
123 */
124#define USB_IRDA_STATUS_LINK_SPEED 0x0f
125
126/* The following is a 4-bit value used only for
127 * outbound header:
128 *
129 * 0 - No change (BOF ignored)
130 * 1 - 48 BOFs
131 * 2 - 24 BOFs
132 * 3 - 12 BOFs
133 * 4 - 6 BOFs
134 * 5 - 3 BOFs
135 * 6 - 2 BOFs
136 * 7 - 1 BOFs
137 * 8 - 0 BOFs
138 * 9..15 - Reserved
139 */
140#define USB_IRDA_EXTRA_BOFS 0xf0
141
142struct usb_irda_inbound_header {
143 __u8 bmStatus;
144};
145
146struct usb_irda_outbound_header {
147 __u8 bmChange;
148};
149
150#endif /* __LINUX_USB_IRDA_H */
151
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 8f891cbaf9ab..09a3e6a7518f 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -62,7 +62,7 @@
62 */ 62 */
63struct usb_serial_port { 63struct usb_serial_port {
64 struct usb_serial *serial; 64 struct usb_serial *serial;
65 struct tty_struct *tty; 65 struct tty_port port;
66 spinlock_t lock; 66 spinlock_t lock;
67 struct mutex mutex; 67 struct mutex mutex;
68 unsigned char number; 68 unsigned char number;
@@ -89,7 +89,6 @@ struct usb_serial_port {
89 89
90 wait_queue_head_t write_wait; 90 wait_queue_head_t write_wait;
91 struct work_struct work; 91 struct work_struct work;
92 int open_count;
93 char throttled; 92 char throttled;
94 char throttle_req; 93 char throttle_req;
95 char console; 94 char console;
@@ -217,22 +216,27 @@ struct usb_serial_driver {
217 int (*resume)(struct usb_serial *serial); 216 int (*resume)(struct usb_serial *serial);
218 217
219 /* serial function calls */ 218 /* serial function calls */
220 int (*open)(struct usb_serial_port *port, struct file *filp); 219 /* Called by console with tty = NULL and by tty */
221 void (*close)(struct usb_serial_port *port, struct file *filp); 220 int (*open)(struct tty_struct *tty,
222 int (*write)(struct usb_serial_port *port, const unsigned char *buf, 221 struct usb_serial_port *port, struct file *filp);
223 int count); 222 void (*close)(struct tty_struct *tty,
224 int (*write_room)(struct usb_serial_port *port); 223 struct usb_serial_port *port, struct file *filp);
225 int (*ioctl)(struct usb_serial_port *port, struct file *file, 224 int (*write)(struct tty_struct *tty, struct usb_serial_port *port,
225 const unsigned char *buf, int count);
226 /* Called only by the tty layer */
227 int (*write_room)(struct tty_struct *tty);
228 int (*ioctl)(struct tty_struct *tty, struct file *file,
226 unsigned int cmd, unsigned long arg); 229 unsigned int cmd, unsigned long arg);
227 void (*set_termios)(struct usb_serial_port *port, struct ktermios *old); 230 void (*set_termios)(struct tty_struct *tty,
228 void (*break_ctl)(struct usb_serial_port *port, int break_state); 231 struct usb_serial_port *port, struct ktermios *old);
229 int (*chars_in_buffer)(struct usb_serial_port *port); 232 void (*break_ctl)(struct tty_struct *tty, int break_state);
230 void (*throttle)(struct usb_serial_port *port); 233 int (*chars_in_buffer)(struct tty_struct *tty);
231 void (*unthrottle)(struct usb_serial_port *port); 234 void (*throttle)(struct tty_struct *tty);
232 int (*tiocmget)(struct usb_serial_port *port, struct file *file); 235 void (*unthrottle)(struct tty_struct *tty);
233 int (*tiocmset)(struct usb_serial_port *port, struct file *file, 236 int (*tiocmget)(struct tty_struct *tty, struct file *file);
237 int (*tiocmset)(struct tty_struct *tty, struct file *file,
234 unsigned int set, unsigned int clear); 238 unsigned int set, unsigned int clear);
235 239 /* USB events */
236 void (*read_int_callback)(struct urb *urb); 240 void (*read_int_callback)(struct urb *urb);
237 void (*write_int_callback)(struct urb *urb); 241 void (*write_int_callback)(struct urb *urb);
238 void (*read_bulk_callback)(struct urb *urb); 242 void (*read_bulk_callback)(struct urb *urb);
@@ -270,19 +274,19 @@ static inline void usb_serial_console_disconnect(struct usb_serial *serial) {}
270/* Functions needed by other parts of the usbserial core */ 274/* Functions needed by other parts of the usbserial core */
271extern struct usb_serial *usb_serial_get_by_index(unsigned int minor); 275extern struct usb_serial *usb_serial_get_by_index(unsigned int minor);
272extern void usb_serial_put(struct usb_serial *serial); 276extern void usb_serial_put(struct usb_serial *serial);
273extern int usb_serial_generic_open(struct usb_serial_port *port, 277extern int usb_serial_generic_open(struct tty_struct *tty,
274 struct file *filp); 278 struct usb_serial_port *port, struct file *filp);
275extern int usb_serial_generic_write(struct usb_serial_port *port, 279extern int usb_serial_generic_write(struct tty_struct *tty,
276 const unsigned char *buf, int count); 280 struct usb_serial_port *port, const unsigned char *buf, int count);
277extern void usb_serial_generic_close(struct usb_serial_port *port, 281extern void usb_serial_generic_close(struct tty_struct *tty,
278 struct file *filp); 282 struct usb_serial_port *port, struct file *filp);
279extern int usb_serial_generic_resume(struct usb_serial *serial); 283extern int usb_serial_generic_resume(struct usb_serial *serial);
280extern int usb_serial_generic_write_room(struct usb_serial_port *port); 284extern int usb_serial_generic_write_room(struct tty_struct *tty);
281extern int usb_serial_generic_chars_in_buffer(struct usb_serial_port *port); 285extern int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
282extern void usb_serial_generic_read_bulk_callback(struct urb *urb); 286extern void usb_serial_generic_read_bulk_callback(struct urb *urb);
283extern void usb_serial_generic_write_bulk_callback(struct urb *urb); 287extern void usb_serial_generic_write_bulk_callback(struct urb *urb);
284extern void usb_serial_generic_throttle(struct usb_serial_port *port); 288extern void usb_serial_generic_throttle(struct tty_struct *tty);
285extern void usb_serial_generic_unthrottle(struct usb_serial_port *port); 289extern void usb_serial_generic_unthrottle(struct tty_struct *tty);
286extern void usb_serial_generic_shutdown(struct usb_serial *serial); 290extern void usb_serial_generic_shutdown(struct usb_serial *serial);
287extern int usb_serial_generic_register(int debug); 291extern int usb_serial_generic_register(int debug);
288extern void usb_serial_generic_deregister(void); 292extern void usb_serial_generic_deregister(void);
diff --git a/include/linux/usbdevice_fs.h b/include/linux/usbdevice_fs.h
index 3118ede2c67b..0044d9b4cb85 100644
--- a/include/linux/usbdevice_fs.h
+++ b/include/linux/usbdevice_fs.h
@@ -22,8 +22,6 @@
22 * 22 *
23 * History: 23 * History:
24 * 0.1 04.01.2000 Created 24 * 0.1 04.01.2000 Created
25 *
26 * $Id: usbdevice_fs.h,v 1.1 2000/01/06 18:40:41 tom Exp $
27 */ 25 */
28 26
29/*****************************************************************************/ 27/*****************************************************************************/
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index 8f5b75734dd0..0741ad592da0 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -88,7 +88,6 @@ struct nf_conn_help {
88 u8 expecting[NF_CT_MAX_EXPECT_CLASSES]; 88 u8 expecting[NF_CT_MAX_EXPECT_CLASSES];
89}; 89};
90 90
91
92#include <net/netfilter/ipv4/nf_conntrack_ipv4.h> 91#include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
93#include <net/netfilter/ipv6/nf_conntrack_ipv6.h> 92#include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
94 93
@@ -111,11 +110,6 @@ struct nf_conn
111 /* Timer function; drops refcnt when it goes off. */ 110 /* Timer function; drops refcnt when it goes off. */
112 struct timer_list timeout; 111 struct timer_list timeout;
113 112
114#ifdef CONFIG_NF_CT_ACCT
115 /* Accounting Information (same cache line as other written members) */
116 struct ip_conntrack_counter counters[IP_CT_DIR_MAX];
117#endif
118
119#if defined(CONFIG_NF_CONNTRACK_MARK) 113#if defined(CONFIG_NF_CONNTRACK_MARK)
120 u_int32_t mark; 114 u_int32_t mark;
121#endif 115#endif
diff --git a/include/net/netfilter/nf_conntrack_acct.h b/include/net/netfilter/nf_conntrack_acct.h
new file mode 100644
index 000000000000..5d5ae55d54c4
--- /dev/null
+++ b/include/net/netfilter/nf_conntrack_acct.h
@@ -0,0 +1,51 @@
1/*
2 * (C) 2008 Krzysztof Piotr Oledzki <ole@ans.pl>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#ifndef _NF_CONNTRACK_ACCT_H
10#define _NF_CONNTRACK_ACCT_H
11#include <linux/netfilter/nf_conntrack_common.h>
12#include <linux/netfilter/nf_conntrack_tuple_common.h>
13#include <net/netfilter/nf_conntrack.h>
14#include <net/netfilter/nf_conntrack_extend.h>
15
16struct nf_conn_counter {
17 u_int64_t packets;
18 u_int64_t bytes;
19};
20
21extern int nf_ct_acct;
22
23static inline
24struct nf_conn_counter *nf_conn_acct_find(const struct nf_conn *ct)
25{
26 return nf_ct_ext_find(ct, NF_CT_EXT_ACCT);
27}
28
29static inline
30struct nf_conn_counter *nf_ct_acct_ext_add(struct nf_conn *ct, gfp_t gfp)
31{
32 struct nf_conn_counter *acct;
33
34 if (!nf_ct_acct)
35 return NULL;
36
37 acct = nf_ct_ext_add(ct, NF_CT_EXT_ACCT, gfp);
38 if (!acct)
39 pr_debug("failed to add accounting extension area");
40
41
42 return acct;
43};
44
45extern unsigned int
46seq_print_acct(struct seq_file *s, const struct nf_conn *ct, int dir);
47
48extern int nf_conntrack_acct_init(void);
49extern void nf_conntrack_acct_fini(void);
50
51#endif /* _NF_CONNTRACK_ACCT_H */
diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
index f80c0ed6d870..da8ee52613a5 100644
--- a/include/net/netfilter/nf_conntrack_extend.h
+++ b/include/net/netfilter/nf_conntrack_extend.h
@@ -7,11 +7,13 @@ enum nf_ct_ext_id
7{ 7{
8 NF_CT_EXT_HELPER, 8 NF_CT_EXT_HELPER,
9 NF_CT_EXT_NAT, 9 NF_CT_EXT_NAT,
10 NF_CT_EXT_ACCT,
10 NF_CT_EXT_NUM, 11 NF_CT_EXT_NUM,
11}; 12};
12 13
13#define NF_CT_EXT_HELPER_TYPE struct nf_conn_help 14#define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
14#define NF_CT_EXT_NAT_TYPE struct nf_conn_nat 15#define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
16#define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter
15 17
16/* Extensions: optional stuff which isn't permanently in struct. */ 18/* Extensions: optional stuff which isn't permanently in struct. */
17struct nf_ct_ext { 19struct nf_ct_ext {
diff --git a/include/net/netlink.h b/include/net/netlink.h
index dfc3701dfcc3..18024b8cecb8 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -896,6 +896,9 @@ static inline int nla_put_msecs(struct sk_buff *skb, int attrtype,
896#define NLA_PUT_U64(skb, attrtype, value) \ 896#define NLA_PUT_U64(skb, attrtype, value) \
897 NLA_PUT_TYPE(skb, u64, attrtype, value) 897 NLA_PUT_TYPE(skb, u64, attrtype, value)
898 898
899#define NLA_PUT_BE64(skb, attrtype, value) \
900 NLA_PUT_TYPE(skb, __be64, attrtype, value)
901
899#define NLA_PUT_STRING(skb, attrtype, value) \ 902#define NLA_PUT_STRING(skb, attrtype, value) \
900 NLA_PUT(skb, attrtype, strlen(value) + 1, value) 903 NLA_PUT(skb, attrtype, strlen(value) + 1, value)
901 904
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 1834fdfe82a7..a594bac4a77d 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -623,7 +623,7 @@ struct Scsi_Host {
623 /* 623 /*
624 * Optional work queue to be utilized by the transport 624 * Optional work queue to be utilized by the transport
625 */ 625 */
626 char work_q_name[KOBJ_NAME_LEN]; 626 char work_q_name[20];
627 struct workqueue_struct *work_q; 627 struct workqueue_struct *work_q;
628 628
629 /* 629 /*
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index 06f72bab9df0..878373c32ef7 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -489,9 +489,9 @@ struct fc_host_attrs {
489 u16 npiv_vports_inuse; 489 u16 npiv_vports_inuse;
490 490
491 /* work queues for rport state manipulation */ 491 /* work queues for rport state manipulation */
492 char work_q_name[KOBJ_NAME_LEN]; 492 char work_q_name[20];
493 struct workqueue_struct *work_q; 493 struct workqueue_struct *work_q;
494 char devloss_work_q_name[KOBJ_NAME_LEN]; 494 char devloss_work_q_name[20];
495 struct workqueue_struct *devloss_work_q; 495 struct workqueue_struct *devloss_work_q;
496}; 496};
497 497
diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h
index f5444e033cc9..8b6c91df4c7a 100644
--- a/include/scsi/scsi_transport_iscsi.h
+++ b/include/scsi/scsi_transport_iscsi.h
@@ -198,7 +198,7 @@ struct iscsi_cls_host {
198 atomic_t nr_scans; 198 atomic_t nr_scans;
199 struct mutex mutex; 199 struct mutex mutex;
200 struct workqueue_struct *scan_workq; 200 struct workqueue_struct *scan_workq;
201 char scan_workq_name[KOBJ_NAME_LEN]; 201 char scan_workq_name[20];
202}; 202};
203 203
204extern void iscsi_host_for_each_session(struct Scsi_Host *shost, 204extern void iscsi_host_for_each_session(struct Scsi_Host *shost,
diff --git a/init/Kconfig b/init/Kconfig
index 6199d1120900..a50bdfed2df7 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -856,8 +856,8 @@ config MODULE_UNLOAD
856 help 856 help
857 Without this option you will not be able to unload any 857 Without this option you will not be able to unload any
858 modules (note that some modules may not be unloadable 858 modules (note that some modules may not be unloadable
859 anyway), which makes your kernel slightly smaller and 859 anyway), which makes your kernel smaller, faster
860 simpler. If unsure, say Y. 860 and simpler. If unsure, say Y.
861 861
862config MODULE_FORCE_UNLOAD 862config MODULE_FORCE_UNLOAD
863 bool "Forced module unloading" 863 bool "Forced module unloading"
@@ -893,16 +893,11 @@ config MODULE_SRCVERSION_ALL
893 will be created for all modules. If unsure, say N. 893 will be created for all modules. If unsure, say N.
894 894
895config KMOD 895config KMOD
896 bool "Automatic kernel module loading" 896 def_bool y
897 depends on MODULES 897 depends on MODULES
898 help 898 help
899 Normally when you have selected some parts of the kernel to 899 This is being removed soon. These days, CONFIG_MODULES
900 be created as kernel modules, you must load them (using the 900 implies CONFIG_KMOD, so use that instead.
901 "modprobe" command) before you can use them. If you say Y
902 here, some parts of the kernel will be able to load modules
903 automatically: when a part of the kernel needs a module, it
904 runs modprobe with the appropriate arguments, thereby
905 loading the module if it is available. If unsure, say Y.
906 901
907config STOP_MACHINE 902config STOP_MACHINE
908 bool 903 bool
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 459d601947a8..d2cc67dac8b1 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -679,7 +679,9 @@ restart:
679 if (apn == b->pn) { 679 if (apn == b->pn) {
680 cpus_or(*dp, *dp, b->cpus_allowed); 680 cpus_or(*dp, *dp, b->cpus_allowed);
681 b->pn = -1; 681 b->pn = -1;
682 update_domain_attr(dattr, b); 682 if (dattr)
683 update_domain_attr(dattr
684 + nslot, b);
683 } 685 }
684 } 686 }
685 nslot++; 687 nslot++;
diff --git a/kernel/exec_domain.c b/kernel/exec_domain.c
index a9e6bad9f706..c1ef192aa655 100644
--- a/kernel/exec_domain.c
+++ b/kernel/exec_domain.c
@@ -65,7 +65,7 @@ lookup_exec_domain(u_long personality)
65 goto out; 65 goto out;
66 } 66 }
67 67
68#ifdef CONFIG_KMOD 68#ifdef CONFIG_MODULES
69 read_unlock(&exec_domains_lock); 69 read_unlock(&exec_domains_lock);
70 request_module("personality-%ld", pers); 70 request_module("personality-%ld", pers);
71 read_lock(&exec_domains_lock); 71 read_lock(&exec_domains_lock);
diff --git a/kernel/kmod.c b/kernel/kmod.c
index 8df97d3dfda8..90d7af1c1655 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -42,7 +42,7 @@ extern int max_threads;
42 42
43static struct workqueue_struct *khelper_wq; 43static struct workqueue_struct *khelper_wq;
44 44
45#ifdef CONFIG_KMOD 45#ifdef CONFIG_MODULES
46 46
47/* 47/*
48 modprobe_path is set via /proc/sys. 48 modprobe_path is set via /proc/sys.
diff --git a/kernel/module.c b/kernel/module.c
index 5f80478b746d..d8b5605132a0 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -70,6 +70,9 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq);
70 70
71static BLOCKING_NOTIFIER_HEAD(module_notify_list); 71static BLOCKING_NOTIFIER_HEAD(module_notify_list);
72 72
73/* Bounds of module allocation, for speeding __module_text_address */
74static unsigned long module_addr_min = -1UL, module_addr_max = 0;
75
73int register_module_notifier(struct notifier_block * nb) 76int register_module_notifier(struct notifier_block * nb)
74{ 77{
75 return blocking_notifier_chain_register(&module_notify_list, nb); 78 return blocking_notifier_chain_register(&module_notify_list, nb);
@@ -134,17 +137,19 @@ extern const struct kernel_symbol __start___ksymtab_gpl[];
134extern const struct kernel_symbol __stop___ksymtab_gpl[]; 137extern const struct kernel_symbol __stop___ksymtab_gpl[];
135extern const struct kernel_symbol __start___ksymtab_gpl_future[]; 138extern const struct kernel_symbol __start___ksymtab_gpl_future[];
136extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; 139extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
137extern const struct kernel_symbol __start___ksymtab_unused[];
138extern const struct kernel_symbol __stop___ksymtab_unused[];
139extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
140extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
141extern const struct kernel_symbol __start___ksymtab_gpl_future[]; 140extern const struct kernel_symbol __start___ksymtab_gpl_future[];
142extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; 141extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
143extern const unsigned long __start___kcrctab[]; 142extern const unsigned long __start___kcrctab[];
144extern const unsigned long __start___kcrctab_gpl[]; 143extern const unsigned long __start___kcrctab_gpl[];
145extern const unsigned long __start___kcrctab_gpl_future[]; 144extern const unsigned long __start___kcrctab_gpl_future[];
145#ifdef CONFIG_UNUSED_SYMBOLS
146extern const struct kernel_symbol __start___ksymtab_unused[];
147extern const struct kernel_symbol __stop___ksymtab_unused[];
148extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
149extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
146extern const unsigned long __start___kcrctab_unused[]; 150extern const unsigned long __start___kcrctab_unused[];
147extern const unsigned long __start___kcrctab_unused_gpl[]; 151extern const unsigned long __start___kcrctab_unused_gpl[];
152#endif
148 153
149#ifndef CONFIG_MODVERSIONS 154#ifndef CONFIG_MODVERSIONS
150#define symversion(base, idx) NULL 155#define symversion(base, idx) NULL
@@ -152,156 +157,186 @@ extern const unsigned long __start___kcrctab_unused_gpl[];
152#define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) 157#define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
153#endif 158#endif
154 159
155/* lookup symbol in given range of kernel_symbols */
156static const struct kernel_symbol *lookup_symbol(const char *name,
157 const struct kernel_symbol *start,
158 const struct kernel_symbol *stop)
159{
160 const struct kernel_symbol *ks = start;
161 for (; ks < stop; ks++)
162 if (strcmp(ks->name, name) == 0)
163 return ks;
164 return NULL;
165}
166
167static bool always_ok(bool gplok, bool warn, const char *name)
168{
169 return true;
170}
171
172static bool printk_unused_warning(bool gplok, bool warn, const char *name)
173{
174 if (warn) {
175 printk(KERN_WARNING "Symbol %s is marked as UNUSED, "
176 "however this module is using it.\n", name);
177 printk(KERN_WARNING
178 "This symbol will go away in the future.\n");
179 printk(KERN_WARNING
180 "Please evalute if this is the right api to use and if "
181 "it really is, submit a report the linux kernel "
182 "mailinglist together with submitting your code for "
183 "inclusion.\n");
184 }
185 return true;
186}
187
188static bool gpl_only_unused_warning(bool gplok, bool warn, const char *name)
189{
190 if (!gplok)
191 return false;
192 return printk_unused_warning(gplok, warn, name);
193}
194
195static bool gpl_only(bool gplok, bool warn, const char *name)
196{
197 return gplok;
198}
199
200static bool warn_if_not_gpl(bool gplok, bool warn, const char *name)
201{
202 if (!gplok && warn) {
203 printk(KERN_WARNING "Symbol %s is being used "
204 "by a non-GPL module, which will not "
205 "be allowed in the future\n", name);
206 printk(KERN_WARNING "Please see the file "
207 "Documentation/feature-removal-schedule.txt "
208 "in the kernel source tree for more details.\n");
209 }
210 return true;
211}
212
213struct symsearch { 160struct symsearch {
214 const struct kernel_symbol *start, *stop; 161 const struct kernel_symbol *start, *stop;
215 const unsigned long *crcs; 162 const unsigned long *crcs;
216 bool (*check)(bool gplok, bool warn, const char *name); 163 enum {
164 NOT_GPL_ONLY,
165 GPL_ONLY,
166 WILL_BE_GPL_ONLY,
167 } licence;
168 bool unused;
217}; 169};
218 170
219/* Look through this array of symbol tables for a symbol match which 171static bool each_symbol_in_section(const struct symsearch *arr,
220 * passes the check function. */ 172 unsigned int arrsize,
221static const struct kernel_symbol *search_symarrays(const struct symsearch *arr, 173 struct module *owner,
222 unsigned int num, 174 bool (*fn)(const struct symsearch *syms,
223 const char *name, 175 struct module *owner,
224 bool gplok, 176 unsigned int symnum, void *data),
225 bool warn, 177 void *data)
226 const unsigned long **crc)
227{ 178{
228 unsigned int i; 179 unsigned int i, j;
229 const struct kernel_symbol *ks;
230 180
231 for (i = 0; i < num; i++) { 181 for (j = 0; j < arrsize; j++) {
232 ks = lookup_symbol(name, arr[i].start, arr[i].stop); 182 for (i = 0; i < arr[j].stop - arr[j].start; i++)
233 if (!ks || !arr[i].check(gplok, warn, name)) 183 if (fn(&arr[j], owner, i, data))
234 continue; 184 return true;
235
236 if (crc)
237 *crc = symversion(arr[i].crcs, ks - arr[i].start);
238 return ks;
239 } 185 }
240 return NULL; 186
187 return false;
241} 188}
242 189
243/* Find a symbol, return value, (optional) crc and (optional) module 190/* Returns true as soon as fn returns true, otherwise false. */
244 * which owns it */ 191static bool each_symbol(bool (*fn)(const struct symsearch *arr,
245static unsigned long find_symbol(const char *name, 192 struct module *owner,
246 struct module **owner, 193 unsigned int symnum, void *data),
247 const unsigned long **crc, 194 void *data)
248 bool gplok,
249 bool warn)
250{ 195{
251 struct module *mod; 196 struct module *mod;
252 const struct kernel_symbol *ks;
253 const struct symsearch arr[] = { 197 const struct symsearch arr[] = {
254 { __start___ksymtab, __stop___ksymtab, __start___kcrctab, 198 { __start___ksymtab, __stop___ksymtab, __start___kcrctab,
255 always_ok }, 199 NOT_GPL_ONLY, false },
256 { __start___ksymtab_gpl, __stop___ksymtab_gpl, 200 { __start___ksymtab_gpl, __stop___ksymtab_gpl,
257 __start___kcrctab_gpl, gpl_only }, 201 __start___kcrctab_gpl,
202 GPL_ONLY, false },
258 { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future, 203 { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future,
259 __start___kcrctab_gpl_future, warn_if_not_gpl }, 204 __start___kcrctab_gpl_future,
205 WILL_BE_GPL_ONLY, false },
206#ifdef CONFIG_UNUSED_SYMBOLS
260 { __start___ksymtab_unused, __stop___ksymtab_unused, 207 { __start___ksymtab_unused, __stop___ksymtab_unused,
261 __start___kcrctab_unused, printk_unused_warning }, 208 __start___kcrctab_unused,
209 NOT_GPL_ONLY, true },
262 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl, 210 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl,
263 __start___kcrctab_unused_gpl, gpl_only_unused_warning }, 211 __start___kcrctab_unused_gpl,
212 GPL_ONLY, true },
213#endif
264 }; 214 };
265 215
266 /* Core kernel first. */ 216 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data))
267 ks = search_symarrays(arr, ARRAY_SIZE(arr), name, gplok, warn, crc); 217 return true;
268 if (ks) {
269 if (owner)
270 *owner = NULL;
271 return ks->value;
272 }
273 218
274 /* Now try modules. */
275 list_for_each_entry(mod, &modules, list) { 219 list_for_each_entry(mod, &modules, list) {
276 struct symsearch arr[] = { 220 struct symsearch arr[] = {
277 { mod->syms, mod->syms + mod->num_syms, mod->crcs, 221 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
278 always_ok }, 222 NOT_GPL_ONLY, false },
279 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, 223 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
280 mod->gpl_crcs, gpl_only }, 224 mod->gpl_crcs,
225 GPL_ONLY, false },
281 { mod->gpl_future_syms, 226 { mod->gpl_future_syms,
282 mod->gpl_future_syms + mod->num_gpl_future_syms, 227 mod->gpl_future_syms + mod->num_gpl_future_syms,
283 mod->gpl_future_crcs, warn_if_not_gpl }, 228 mod->gpl_future_crcs,
229 WILL_BE_GPL_ONLY, false },
230#ifdef CONFIG_UNUSED_SYMBOLS
284 { mod->unused_syms, 231 { mod->unused_syms,
285 mod->unused_syms + mod->num_unused_syms, 232 mod->unused_syms + mod->num_unused_syms,
286 mod->unused_crcs, printk_unused_warning }, 233 mod->unused_crcs,
234 NOT_GPL_ONLY, true },
287 { mod->unused_gpl_syms, 235 { mod->unused_gpl_syms,
288 mod->unused_gpl_syms + mod->num_unused_gpl_syms, 236 mod->unused_gpl_syms + mod->num_unused_gpl_syms,
289 mod->unused_gpl_crcs, gpl_only_unused_warning }, 237 mod->unused_gpl_crcs,
238 GPL_ONLY, true },
239#endif
290 }; 240 };
291 241
292 ks = search_symarrays(arr, ARRAY_SIZE(arr), 242 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
293 name, gplok, warn, crc); 243 return true;
294 if (ks) { 244 }
295 if (owner) 245 return false;
296 *owner = mod; 246}
297 return ks->value; 247
248struct find_symbol_arg {
249 /* Input */
250 const char *name;
251 bool gplok;
252 bool warn;
253
254 /* Output */
255 struct module *owner;
256 const unsigned long *crc;
257 unsigned long value;
258};
259
260static bool find_symbol_in_section(const struct symsearch *syms,
261 struct module *owner,
262 unsigned int symnum, void *data)
263{
264 struct find_symbol_arg *fsa = data;
265
266 if (strcmp(syms->start[symnum].name, fsa->name) != 0)
267 return false;
268
269 if (!fsa->gplok) {
270 if (syms->licence == GPL_ONLY)
271 return false;
272 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) {
273 printk(KERN_WARNING "Symbol %s is being used "
274 "by a non-GPL module, which will not "
275 "be allowed in the future\n", fsa->name);
276 printk(KERN_WARNING "Please see the file "
277 "Documentation/feature-removal-schedule.txt "
278 "in the kernel source tree for more details.\n");
298 } 279 }
299 } 280 }
300 281
282#ifdef CONFIG_UNUSED_SYMBOLS
283 if (syms->unused && fsa->warn) {
284 printk(KERN_WARNING "Symbol %s is marked as UNUSED, "
285 "however this module is using it.\n", fsa->name);
286 printk(KERN_WARNING
287 "This symbol will go away in the future.\n");
288 printk(KERN_WARNING
289 "Please evalute if this is the right api to use and if "
290 "it really is, submit a report the linux kernel "
291 "mailinglist together with submitting your code for "
292 "inclusion.\n");
293 }
294#endif
295
296 fsa->owner = owner;
297 fsa->crc = symversion(syms->crcs, symnum);
298 fsa->value = syms->start[symnum].value;
299 return true;
300}
301
302/* Find a symbol, return value, (optional) crc and (optional) module
303 * which owns it */
304static unsigned long find_symbol(const char *name,
305 struct module **owner,
306 const unsigned long **crc,
307 bool gplok,
308 bool warn)
309{
310 struct find_symbol_arg fsa;
311
312 fsa.name = name;
313 fsa.gplok = gplok;
314 fsa.warn = warn;
315
316 if (each_symbol(find_symbol_in_section, &fsa)) {
317 if (owner)
318 *owner = fsa.owner;
319 if (crc)
320 *crc = fsa.crc;
321 return fsa.value;
322 }
323
301 DEBUGP("Failed to find symbol %s\n", name); 324 DEBUGP("Failed to find symbol %s\n", name);
302 return -ENOENT; 325 return -ENOENT;
303} 326}
304 327
328/* lookup symbol in given range of kernel_symbols */
329static const struct kernel_symbol *lookup_symbol(const char *name,
330 const struct kernel_symbol *start,
331 const struct kernel_symbol *stop)
332{
333 const struct kernel_symbol *ks = start;
334 for (; ks < stop; ks++)
335 if (strcmp(ks->name, name) == 0)
336 return ks;
337 return NULL;
338}
339
305/* Search for module by name: must hold module_mutex. */ 340/* Search for module by name: must hold module_mutex. */
306static struct module *find_module(const char *name) 341static struct module *find_module(const char *name)
307{ 342{
@@ -639,8 +674,8 @@ static int __try_stop_module(void *_sref)
639{ 674{
640 struct stopref *sref = _sref; 675 struct stopref *sref = _sref;
641 676
642 /* If it's not unused, quit unless we are told to block. */ 677 /* If it's not unused, quit unless we're forcing. */
643 if ((sref->flags & O_NONBLOCK) && module_refcount(sref->mod) != 0) { 678 if (module_refcount(sref->mod) != 0) {
644 if (!(*sref->forced = try_force_unload(sref->flags))) 679 if (!(*sref->forced = try_force_unload(sref->flags)))
645 return -EWOULDBLOCK; 680 return -EWOULDBLOCK;
646 } 681 }
@@ -652,9 +687,16 @@ static int __try_stop_module(void *_sref)
652 687
653static int try_stop_module(struct module *mod, int flags, int *forced) 688static int try_stop_module(struct module *mod, int flags, int *forced)
654{ 689{
655 struct stopref sref = { mod, flags, forced }; 690 if (flags & O_NONBLOCK) {
691 struct stopref sref = { mod, flags, forced };
656 692
657 return stop_machine_run(__try_stop_module, &sref, NR_CPUS); 693 return stop_machine_run(__try_stop_module, &sref, NR_CPUS);
694 } else {
695 /* We don't need to stop the machine for this. */
696 mod->state = MODULE_STATE_GOING;
697 synchronize_sched();
698 return 0;
699 }
658} 700}
659 701
660unsigned int module_refcount(struct module *mod) 702unsigned int module_refcount(struct module *mod)
@@ -1445,8 +1487,10 @@ static int verify_export_symbols(struct module *mod)
1445 { mod->syms, mod->num_syms }, 1487 { mod->syms, mod->num_syms },
1446 { mod->gpl_syms, mod->num_gpl_syms }, 1488 { mod->gpl_syms, mod->num_gpl_syms },
1447 { mod->gpl_future_syms, mod->num_gpl_future_syms }, 1489 { mod->gpl_future_syms, mod->num_gpl_future_syms },
1490#ifdef CONFIG_UNUSED_SYMBOLS
1448 { mod->unused_syms, mod->num_unused_syms }, 1491 { mod->unused_syms, mod->num_unused_syms },
1449 { mod->unused_gpl_syms, mod->num_unused_gpl_syms }, 1492 { mod->unused_gpl_syms, mod->num_unused_gpl_syms },
1493#endif
1450 }; 1494 };
1451 1495
1452 for (i = 0; i < ARRAY_SIZE(arr); i++) { 1496 for (i = 0; i < ARRAY_SIZE(arr); i++) {
@@ -1526,7 +1570,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
1526} 1570}
1527 1571
1528/* Update size with this section: return offset. */ 1572/* Update size with this section: return offset. */
1529static long get_offset(unsigned long *size, Elf_Shdr *sechdr) 1573static long get_offset(unsigned int *size, Elf_Shdr *sechdr)
1530{ 1574{
1531 long ret; 1575 long ret;
1532 1576
@@ -1738,6 +1782,20 @@ static inline void add_kallsyms(struct module *mod,
1738} 1782}
1739#endif /* CONFIG_KALLSYMS */ 1783#endif /* CONFIG_KALLSYMS */
1740 1784
1785static void *module_alloc_update_bounds(unsigned long size)
1786{
1787 void *ret = module_alloc(size);
1788
1789 if (ret) {
1790 /* Update module bounds. */
1791 if ((unsigned long)ret < module_addr_min)
1792 module_addr_min = (unsigned long)ret;
1793 if ((unsigned long)ret + size > module_addr_max)
1794 module_addr_max = (unsigned long)ret + size;
1795 }
1796 return ret;
1797}
1798
1741/* Allocate and load the module: note that size of section 0 is always 1799/* Allocate and load the module: note that size of section 0 is always
1742 zero, and we rely on this for optional sections. */ 1800 zero, and we rely on this for optional sections. */
1743static struct module *load_module(void __user *umod, 1801static struct module *load_module(void __user *umod,
@@ -1764,10 +1822,12 @@ static struct module *load_module(void __user *umod,
1764 unsigned int gplfutureindex; 1822 unsigned int gplfutureindex;
1765 unsigned int gplfuturecrcindex; 1823 unsigned int gplfuturecrcindex;
1766 unsigned int unwindex = 0; 1824 unsigned int unwindex = 0;
1825#ifdef CONFIG_UNUSED_SYMBOLS
1767 unsigned int unusedindex; 1826 unsigned int unusedindex;
1768 unsigned int unusedcrcindex; 1827 unsigned int unusedcrcindex;
1769 unsigned int unusedgplindex; 1828 unsigned int unusedgplindex;
1770 unsigned int unusedgplcrcindex; 1829 unsigned int unusedgplcrcindex;
1830#endif
1771 unsigned int markersindex; 1831 unsigned int markersindex;
1772 unsigned int markersstringsindex; 1832 unsigned int markersstringsindex;
1773 struct module *mod; 1833 struct module *mod;
@@ -1850,13 +1910,15 @@ static struct module *load_module(void __user *umod,
1850 exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); 1910 exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab");
1851 gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); 1911 gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl");
1852 gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future"); 1912 gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future");
1853 unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused");
1854 unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl");
1855 crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); 1913 crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab");
1856 gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); 1914 gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl");
1857 gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future"); 1915 gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future");
1916#ifdef CONFIG_UNUSED_SYMBOLS
1917 unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused");
1918 unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl");
1858 unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused"); 1919 unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused");
1859 unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl"); 1920 unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl");
1921#endif
1860 setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); 1922 setupindex = find_sec(hdr, sechdrs, secstrings, "__param");
1861 exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); 1923 exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table");
1862 obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); 1924 obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm");
@@ -1935,7 +1997,7 @@ static struct module *load_module(void __user *umod,
1935 layout_sections(mod, hdr, sechdrs, secstrings); 1997 layout_sections(mod, hdr, sechdrs, secstrings);
1936 1998
1937 /* Do the allocs. */ 1999 /* Do the allocs. */
1938 ptr = module_alloc(mod->core_size); 2000 ptr = module_alloc_update_bounds(mod->core_size);
1939 if (!ptr) { 2001 if (!ptr) {
1940 err = -ENOMEM; 2002 err = -ENOMEM;
1941 goto free_percpu; 2003 goto free_percpu;
@@ -1943,7 +2005,7 @@ static struct module *load_module(void __user *umod,
1943 memset(ptr, 0, mod->core_size); 2005 memset(ptr, 0, mod->core_size);
1944 mod->module_core = ptr; 2006 mod->module_core = ptr;
1945 2007
1946 ptr = module_alloc(mod->init_size); 2008 ptr = module_alloc_update_bounds(mod->init_size);
1947 if (!ptr && mod->init_size) { 2009 if (!ptr && mod->init_size) {
1948 err = -ENOMEM; 2010 err = -ENOMEM;
1949 goto free_core; 2011 goto free_core;
@@ -2018,14 +2080,15 @@ static struct module *load_module(void __user *umod,
2018 mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; 2080 mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr;
2019 mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / 2081 mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size /
2020 sizeof(*mod->gpl_future_syms); 2082 sizeof(*mod->gpl_future_syms);
2021 mod->num_unused_syms = sechdrs[unusedindex].sh_size /
2022 sizeof(*mod->unused_syms);
2023 mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size /
2024 sizeof(*mod->unused_gpl_syms);
2025 mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; 2083 mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr;
2026 if (gplfuturecrcindex) 2084 if (gplfuturecrcindex)
2027 mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr; 2085 mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr;
2028 2086
2087#ifdef CONFIG_UNUSED_SYMBOLS
2088 mod->num_unused_syms = sechdrs[unusedindex].sh_size /
2089 sizeof(*mod->unused_syms);
2090 mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size /
2091 sizeof(*mod->unused_gpl_syms);
2029 mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr; 2092 mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr;
2030 if (unusedcrcindex) 2093 if (unusedcrcindex)
2031 mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr; 2094 mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr;
@@ -2033,13 +2096,17 @@ static struct module *load_module(void __user *umod,
2033 if (unusedgplcrcindex) 2096 if (unusedgplcrcindex)
2034 mod->unused_gpl_crcs 2097 mod->unused_gpl_crcs
2035 = (void *)sechdrs[unusedgplcrcindex].sh_addr; 2098 = (void *)sechdrs[unusedgplcrcindex].sh_addr;
2099#endif
2036 2100
2037#ifdef CONFIG_MODVERSIONS 2101#ifdef CONFIG_MODVERSIONS
2038 if ((mod->num_syms && !crcindex) || 2102 if ((mod->num_syms && !crcindex)
2039 (mod->num_gpl_syms && !gplcrcindex) || 2103 || (mod->num_gpl_syms && !gplcrcindex)
2040 (mod->num_gpl_future_syms && !gplfuturecrcindex) || 2104 || (mod->num_gpl_future_syms && !gplfuturecrcindex)
2041 (mod->num_unused_syms && !unusedcrcindex) || 2105#ifdef CONFIG_UNUSED_SYMBOLS
2042 (mod->num_unused_gpl_syms && !unusedgplcrcindex)) { 2106 || (mod->num_unused_syms && !unusedcrcindex)
2107 || (mod->num_unused_gpl_syms && !unusedgplcrcindex)
2108#endif
2109 ) {
2043 printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); 2110 printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name);
2044 err = try_to_force_load(mod, "nocrc"); 2111 err = try_to_force_load(mod, "nocrc");
2045 if (err) 2112 if (err)
@@ -2512,7 +2579,7 @@ static int m_show(struct seq_file *m, void *p)
2512 struct module *mod = list_entry(p, struct module, list); 2579 struct module *mod = list_entry(p, struct module, list);
2513 char buf[8]; 2580 char buf[8];
2514 2581
2515 seq_printf(m, "%s %lu", 2582 seq_printf(m, "%s %u",
2516 mod->name, mod->init_size + mod->core_size); 2583 mod->name, mod->init_size + mod->core_size);
2517 print_unload_info(m, mod); 2584 print_unload_info(m, mod);
2518 2585
@@ -2595,6 +2662,9 @@ struct module *__module_text_address(unsigned long addr)
2595{ 2662{
2596 struct module *mod; 2663 struct module *mod;
2597 2664
2665 if (addr < module_addr_min || addr > module_addr_max)
2666 return NULL;
2667
2598 list_for_each_entry(mod, &modules, list) 2668 list_for_each_entry(mod, &modules, list)
2599 if (within(addr, mod->module_init, mod->init_text_size) 2669 if (within(addr, mod->module_init, mod->init_text_size)
2600 || within(addr, mod->module_core, mod->core_text_size)) 2670 || within(addr, mod->module_core, mod->core_text_size))
diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
index 092e4c620af9..a56f629b057a 100644
--- a/kernel/rtmutex-tester.c
+++ b/kernel/rtmutex-tester.c
@@ -297,8 +297,8 @@ static int test_func(void *data)
297 * 297 *
298 * opcode:data 298 * opcode:data
299 */ 299 */
300static ssize_t sysfs_test_command(struct sys_device *dev, const char *buf, 300static ssize_t sysfs_test_command(struct sys_device *dev, struct sysdev_attribute *attr,
301 size_t count) 301 const char *buf, size_t count)
302{ 302{
303 struct sched_param schedpar; 303 struct sched_param schedpar;
304 struct test_thread_data *td; 304 struct test_thread_data *td;
@@ -360,7 +360,8 @@ static ssize_t sysfs_test_command(struct sys_device *dev, const char *buf,
360 * @dev: thread to query 360 * @dev: thread to query
361 * @buf: char buffer to be filled with thread status info 361 * @buf: char buffer to be filled with thread status info
362 */ 362 */
363static ssize_t sysfs_test_status(struct sys_device *dev, char *buf) 363static ssize_t sysfs_test_status(struct sys_device *dev, struct sysdev_attribute *attr,
364 char *buf)
364{ 365{
365 struct test_thread_data *td; 366 struct test_thread_data *td;
366 struct task_struct *tsk; 367 struct task_struct *tsk;
diff --git a/kernel/sched.c b/kernel/sched.c
index 99e6d850ecab..b1104ea5d255 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -7737,11 +7737,13 @@ static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt)
7737} 7737}
7738 7738
7739#ifdef CONFIG_SCHED_MC 7739#ifdef CONFIG_SCHED_MC
7740static ssize_t sched_mc_power_savings_show(struct sys_device *dev, char *page) 7740static ssize_t sched_mc_power_savings_show(struct sys_device *dev,
7741 struct sysdev_attribute *attr, char *page)
7741{ 7742{
7742 return sprintf(page, "%u\n", sched_mc_power_savings); 7743 return sprintf(page, "%u\n", sched_mc_power_savings);
7743} 7744}
7744static ssize_t sched_mc_power_savings_store(struct sys_device *dev, 7745static ssize_t sched_mc_power_savings_store(struct sys_device *dev,
7746 struct sysdev_attribute *attr,
7745 const char *buf, size_t count) 7747 const char *buf, size_t count)
7746{ 7748{
7747 return sched_power_savings_store(buf, count, 0); 7749 return sched_power_savings_store(buf, count, 0);
@@ -7751,11 +7753,13 @@ static SYSDEV_ATTR(sched_mc_power_savings, 0644, sched_mc_power_savings_show,
7751#endif 7753#endif
7752 7754
7753#ifdef CONFIG_SCHED_SMT 7755#ifdef CONFIG_SCHED_SMT
7754static ssize_t sched_smt_power_savings_show(struct sys_device *dev, char *page) 7756static ssize_t sched_smt_power_savings_show(struct sys_device *dev,
7757 struct sysdev_attribute *attr, char *page)
7755{ 7758{
7756 return sprintf(page, "%u\n", sched_smt_power_savings); 7759 return sprintf(page, "%u\n", sched_smt_power_savings);
7757} 7760}
7758static ssize_t sched_smt_power_savings_store(struct sys_device *dev, 7761static ssize_t sched_smt_power_savings_store(struct sys_device *dev,
7762 struct sysdev_attribute *attr,
7759 const char *buf, size_t count) 7763 const char *buf, size_t count)
7760{ 7764{
7761 return sched_power_savings_store(buf, count, 1); 7765 return sched_power_savings_store(buf, count, 1);
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 5b9b467de070..0fea0ee12da9 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -59,6 +59,7 @@ cond_syscall(sys_epoll_create);
59cond_syscall(sys_epoll_ctl); 59cond_syscall(sys_epoll_ctl);
60cond_syscall(sys_epoll_wait); 60cond_syscall(sys_epoll_wait);
61cond_syscall(sys_epoll_pwait); 61cond_syscall(sys_epoll_pwait);
62cond_syscall(compat_sys_epoll_pwait);
62cond_syscall(sys_semget); 63cond_syscall(sys_semget);
63cond_syscall(sys_semop); 64cond_syscall(sys_semop);
64cond_syscall(sys_semtimedop); 65cond_syscall(sys_semtimedop);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 6b16e16428d8..b859e6b5a767 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -110,7 +110,7 @@ static int min_percpu_pagelist_fract = 8;
110 110
111static int ngroups_max = NGROUPS_MAX; 111static int ngroups_max = NGROUPS_MAX;
112 112
113#ifdef CONFIG_KMOD 113#ifdef CONFIG_MODULES
114extern char modprobe_path[]; 114extern char modprobe_path[];
115#endif 115#endif
116#ifdef CONFIG_CHR_DEV_SG 116#ifdef CONFIG_CHR_DEV_SG
@@ -475,7 +475,7 @@ static struct ctl_table kern_table[] = {
475 .proc_handler = &ftrace_enable_sysctl, 475 .proc_handler = &ftrace_enable_sysctl,
476 }, 476 },
477#endif 477#endif
478#ifdef CONFIG_KMOD 478#ifdef CONFIG_MODULES
479 { 479 {
480 .ctl_name = KERN_MODPROBE, 480 .ctl_name = KERN_MODPROBE,
481 .procname = "modprobe", 481 .procname = "modprobe",
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index dadde5361f32..b1c2da81b050 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -376,7 +376,8 @@ void clocksource_unregister(struct clocksource *cs)
376 * Provides sysfs interface for listing current clocksource. 376 * Provides sysfs interface for listing current clocksource.
377 */ 377 */
378static ssize_t 378static ssize_t
379sysfs_show_current_clocksources(struct sys_device *dev, char *buf) 379sysfs_show_current_clocksources(struct sys_device *dev,
380 struct sysdev_attribute *attr, char *buf)
380{ 381{
381 ssize_t count = 0; 382 ssize_t count = 0;
382 383
@@ -397,6 +398,7 @@ sysfs_show_current_clocksources(struct sys_device *dev, char *buf)
397 * clocksource selction. 398 * clocksource selction.
398 */ 399 */
399static ssize_t sysfs_override_clocksource(struct sys_device *dev, 400static ssize_t sysfs_override_clocksource(struct sys_device *dev,
401 struct sysdev_attribute *attr,
400 const char *buf, size_t count) 402 const char *buf, size_t count)
401{ 403{
402 struct clocksource *ovr = NULL; 404 struct clocksource *ovr = NULL;
@@ -449,7 +451,9 @@ static ssize_t sysfs_override_clocksource(struct sys_device *dev,
449 * Provides sysfs interface for listing registered clocksources 451 * Provides sysfs interface for listing registered clocksources
450 */ 452 */
451static ssize_t 453static ssize_t
452sysfs_show_available_clocksources(struct sys_device *dev, char *buf) 454sysfs_show_available_clocksources(struct sys_device *dev,
455 struct sysdev_attribute *attr,
456 char *buf)
453{ 457{
454 struct clocksource *src; 458 struct clocksource *src;
455 ssize_t count = 0; 459 ssize_t count = 0;
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index df27132a56f4..ba106db5a65b 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -74,6 +74,9 @@ config DEBUG_FS
74 debugging files into. Enable this option to be able to read and 74 debugging files into. Enable this option to be able to read and
75 write to these files. 75 write to these files.
76 76
77 For detailed documentation on the debugfs API, see
78 Documentation/DocBook/filesystems.
79
77 If unsure, say N. 80 If unsure, say N.
78 81
79config HEADERS_CHECK 82config HEADERS_CHECK
diff --git a/lib/kobject.c b/lib/kobject.c
index dcade0543bd2..744401571ed7 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -216,13 +216,19 @@ static int kobject_add_internal(struct kobject *kobj)
216static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, 216static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
217 va_list vargs) 217 va_list vargs)
218{ 218{
219 /* Free the old name, if necessary. */ 219 const char *old_name = kobj->name;
220 kfree(kobj->name); 220 char *s;
221 221
222 kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs); 222 kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
223 if (!kobj->name) 223 if (!kobj->name)
224 return -ENOMEM; 224 return -ENOMEM;
225 225
226 /* ewww... some of these buggers have '/' in the name ... */
227 s = strchr(kobj->name, '/');
228 if (s)
229 s[0] = '!';
230
231 kfree(old_name);
226 return 0; 232 return 0;
227} 233}
228 234
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 2fa545a63160..9f8d599459d1 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -245,7 +245,8 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
245 if (retval) 245 if (retval)
246 goto exit; 246 goto exit;
247 247
248 call_usermodehelper(argv[0], argv, env->envp, UMH_WAIT_EXEC); 248 retval = call_usermodehelper(argv[0], argv,
249 env->envp, UMH_WAIT_EXEC);
249 } 250 }
250 251
251exit: 252exit:
diff --git a/lib/textsearch.c b/lib/textsearch.c
index 4b7c6075256f..9fbcb44c554f 100644
--- a/lib/textsearch.c
+++ b/lib/textsearch.c
@@ -267,7 +267,7 @@ struct ts_config *textsearch_prepare(const char *algo, const void *pattern,
267 return ERR_PTR(-EINVAL); 267 return ERR_PTR(-EINVAL);
268 268
269 ops = lookup_ts_algo(algo); 269 ops = lookup_ts_algo(algo);
270#ifdef CONFIG_KMOD 270#ifdef CONFIG_MODULES
271 /* 271 /*
272 * Why not always autoload you may ask. Some users are 272 * Why not always autoload you may ask. Some users are
273 * in a situation where requesting a module may deadlock, 273 * in a situation where requesting a module may deadlock,
diff --git a/mm/slub.c b/mm/slub.c
index 35ab38a94b46..6d4a49c1ff2f 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -492,7 +492,7 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)
492 if (p > addr + 16) 492 if (p > addr + 16)
493 print_section("Bytes b4", p - 16, 16); 493 print_section("Bytes b4", p - 16, 16);
494 494
495 print_section("Object", p, min(s->objsize, 128)); 495 print_section("Object", p, min_t(unsigned long, s->objsize, PAGE_SIZE));
496 496
497 if (s->flags & SLAB_RED_ZONE) 497 if (s->flags & SLAB_RED_ZONE)
498 print_section("Redzone", p + s->objsize, 498 print_section("Redzone", p + s->objsize,
@@ -1495,15 +1495,7 @@ static void flush_cpu_slab(void *d)
1495 1495
1496static void flush_all(struct kmem_cache *s) 1496static void flush_all(struct kmem_cache *s)
1497{ 1497{
1498#ifdef CONFIG_SMP
1499 on_each_cpu(flush_cpu_slab, s, 1); 1498 on_each_cpu(flush_cpu_slab, s, 1);
1500#else
1501 unsigned long flags;
1502
1503 local_irq_save(flags);
1504 flush_cpu_slab(s);
1505 local_irq_restore(flags);
1506#endif
1507} 1499}
1508 1500
1509/* 1501/*
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 844ca5f1b2d4..c85bf8f678dc 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -398,10 +398,6 @@ int hci_register_sysfs(struct hci_dev *hdev)
398 if (device_create_file(dev, bt_attrs[i]) < 0) 398 if (device_create_file(dev, bt_attrs[i]) < 0)
399 BT_ERR("Failed to create device attribute"); 399 BT_ERR("Failed to create device attribute");
400 400
401 if (sysfs_create_link(&bt_class->subsys.kobj,
402 &dev->kobj, kobject_name(&dev->kobj)) < 0)
403 BT_ERR("Failed to create class symlink");
404
405 return 0; 401 return 0;
406} 402}
407 403
@@ -409,9 +405,6 @@ void hci_unregister_sysfs(struct hci_dev *hdev)
409{ 405{
410 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); 406 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
411 407
412 sysfs_remove_link(&bt_class->subsys.kobj,
413 kobject_name(&hdev->dev.kobj));
414
415 device_del(&hdev->dev); 408 device_del(&hdev->dev);
416} 409}
417 410
diff --git a/net/core/dev.c b/net/core/dev.c
index 2eed17bcb2dd..cbc34c0db376 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -124,6 +124,8 @@
124#include <linux/ip.h> 124#include <linux/ip.h>
125#include <linux/ipv6.h> 125#include <linux/ipv6.h>
126#include <linux/in.h> 126#include <linux/in.h>
127#include <linux/jhash.h>
128#include <linux/random.h>
127 129
128#include "net-sysfs.h" 130#include "net-sysfs.h"
129 131
@@ -1325,7 +1327,8 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
1325 1327
1326void __netif_schedule(struct Qdisc *q) 1328void __netif_schedule(struct Qdisc *q)
1327{ 1329{
1328 BUG_ON(q == &noop_qdisc); 1330 if (WARN_ON_ONCE(q == &noop_qdisc))
1331 return;
1329 1332
1330 if (!test_and_set_bit(__QDISC_STATE_SCHED, &q->state)) { 1333 if (!test_and_set_bit(__QDISC_STATE_SCHED, &q->state)) {
1331 struct softnet_data *sd; 1334 struct softnet_data *sd;
@@ -1668,34 +1671,37 @@ out_kfree_skb:
1668 * --BLG 1671 * --BLG
1669 */ 1672 */
1670 1673
1674static u32 simple_tx_hashrnd;
1675static int simple_tx_hashrnd_initialized = 0;
1676
1671static u16 simple_tx_hash(struct net_device *dev, struct sk_buff *skb) 1677static u16 simple_tx_hash(struct net_device *dev, struct sk_buff *skb)
1672{ 1678{
1673 u32 *addr, *ports, hash, ihl; 1679 u32 addr1, addr2, ports;
1680 u32 hash, ihl;
1674 u8 ip_proto; 1681 u8 ip_proto;
1675 int alen; 1682
1683 if (unlikely(!simple_tx_hashrnd_initialized)) {
1684 get_random_bytes(&simple_tx_hashrnd, 4);
1685 simple_tx_hashrnd_initialized = 1;
1686 }
1676 1687
1677 switch (skb->protocol) { 1688 switch (skb->protocol) {
1678 case __constant_htons(ETH_P_IP): 1689 case __constant_htons(ETH_P_IP):
1679 ip_proto = ip_hdr(skb)->protocol; 1690 ip_proto = ip_hdr(skb)->protocol;
1680 addr = &ip_hdr(skb)->saddr; 1691 addr1 = ip_hdr(skb)->saddr;
1692 addr2 = ip_hdr(skb)->daddr;
1681 ihl = ip_hdr(skb)->ihl; 1693 ihl = ip_hdr(skb)->ihl;
1682 alen = 2;
1683 break; 1694 break;
1684 case __constant_htons(ETH_P_IPV6): 1695 case __constant_htons(ETH_P_IPV6):
1685 ip_proto = ipv6_hdr(skb)->nexthdr; 1696 ip_proto = ipv6_hdr(skb)->nexthdr;
1686 addr = &ipv6_hdr(skb)->saddr.s6_addr32[0]; 1697 addr1 = ipv6_hdr(skb)->saddr.s6_addr32[3];
1698 addr2 = ipv6_hdr(skb)->daddr.s6_addr32[3];
1687 ihl = (40 >> 2); 1699 ihl = (40 >> 2);
1688 alen = 8;
1689 break; 1700 break;
1690 default: 1701 default:
1691 return 0; 1702 return 0;
1692 } 1703 }
1693 1704
1694 ports = (u32 *) (skb_network_header(skb) + (ihl * 4));
1695
1696 hash = 0;
1697 while (alen--)
1698 hash ^= *addr++;
1699 1705
1700 switch (ip_proto) { 1706 switch (ip_proto) {
1701 case IPPROTO_TCP: 1707 case IPPROTO_TCP:
@@ -1705,14 +1711,17 @@ static u16 simple_tx_hash(struct net_device *dev, struct sk_buff *skb)
1705 case IPPROTO_AH: 1711 case IPPROTO_AH:
1706 case IPPROTO_SCTP: 1712 case IPPROTO_SCTP:
1707 case IPPROTO_UDPLITE: 1713 case IPPROTO_UDPLITE:
1708 hash ^= *ports; 1714 ports = *((u32 *) (skb_network_header(skb) + (ihl * 4)));
1709 break; 1715 break;
1710 1716
1711 default: 1717 default:
1718 ports = 0;
1712 break; 1719 break;
1713 } 1720 }
1714 1721
1715 return hash % dev->real_num_tx_queues; 1722 hash = jhash_3words(addr1, addr2, ports, simple_tx_hashrnd);
1723
1724 return (u16) (((u64) hash * dev->real_num_tx_queues) >> 32);
1716} 1725}
1717 1726
1718static struct netdev_queue *dev_pick_tx(struct net_device *dev, 1727static struct netdev_queue *dev_pick_tx(struct net_device *dev,
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
index 40a46d482490..3a020720e40b 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
@@ -18,19 +18,7 @@
18#include <net/netfilter/nf_conntrack_l3proto.h> 18#include <net/netfilter/nf_conntrack_l3proto.h>
19#include <net/netfilter/nf_conntrack_l4proto.h> 19#include <net/netfilter/nf_conntrack_l4proto.h>
20#include <net/netfilter/nf_conntrack_expect.h> 20#include <net/netfilter/nf_conntrack_expect.h>
21 21#include <net/netfilter/nf_conntrack_acct.h>
22#ifdef CONFIG_NF_CT_ACCT
23static unsigned int
24seq_print_counters(struct seq_file *s,
25 const struct ip_conntrack_counter *counter)
26{
27 return seq_printf(s, "packets=%llu bytes=%llu ",
28 (unsigned long long)counter->packets,
29 (unsigned long long)counter->bytes);
30}
31#else
32#define seq_print_counters(x, y) 0
33#endif
34 22
35struct ct_iter_state { 23struct ct_iter_state {
36 unsigned int bucket; 24 unsigned int bucket;
@@ -127,7 +115,7 @@ static int ct_seq_show(struct seq_file *s, void *v)
127 l3proto, l4proto)) 115 l3proto, l4proto))
128 return -ENOSPC; 116 return -ENOSPC;
129 117
130 if (seq_print_counters(s, &ct->counters[IP_CT_DIR_ORIGINAL])) 118 if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL))
131 return -ENOSPC; 119 return -ENOSPC;
132 120
133 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) 121 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
@@ -138,7 +126,7 @@ static int ct_seq_show(struct seq_file *s, void *v)
138 l3proto, l4proto)) 126 l3proto, l4proto))
139 return -ENOSPC; 127 return -ENOSPC;
140 128
141 if (seq_print_counters(s, &ct->counters[IP_CT_DIR_REPLY])) 129 if (seq_print_acct(s, ct, IP_CT_DIR_REPLY))
142 return -ENOSPC; 130 return -ENOSPC;
143 131
144 if (test_bit(IPS_ASSURED_BIT, &ct->status)) 132 if (test_bit(IPS_ASSURED_BIT, &ct->status))
diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c
index d2a887fc8d9b..6c6a3cba8d50 100644
--- a/net/ipv4/netfilter/nf_nat_core.c
+++ b/net/ipv4/netfilter/nf_nat_core.c
@@ -240,12 +240,12 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
240 This is only required for source (ie. NAT/masq) mappings. 240 This is only required for source (ie. NAT/masq) mappings.
241 So far, we don't do local source mappings, so multiple 241 So far, we don't do local source mappings, so multiple
242 manips not an issue. */ 242 manips not an issue. */
243 if (maniptype == IP_NAT_MANIP_SRC) { 243 if (maniptype == IP_NAT_MANIP_SRC &&
244 !(range->flags & IP_NAT_RANGE_PROTO_RANDOM)) {
244 if (find_appropriate_src(orig_tuple, tuple, range)) { 245 if (find_appropriate_src(orig_tuple, tuple, range)) {
245 pr_debug("get_unique_tuple: Found current src map\n"); 246 pr_debug("get_unique_tuple: Found current src map\n");
246 if (!(range->flags & IP_NAT_RANGE_PROTO_RANDOM)) 247 if (!nf_nat_used_tuple(tuple, ct))
247 if (!nf_nat_used_tuple(tuple, ct)) 248 return;
248 return;
249 } 249 }
250 } 250 }
251 251
diff --git a/net/ipv4/netfilter/nf_nat_sip.c b/net/ipv4/netfilter/nf_nat_sip.c
index 4334d5cabc5b..14544320c545 100644
--- a/net/ipv4/netfilter/nf_nat_sip.c
+++ b/net/ipv4/netfilter/nf_nat_sip.c
@@ -318,11 +318,11 @@ static int mangle_content_len(struct sk_buff *skb,
318 buffer, buflen); 318 buffer, buflen);
319} 319}
320 320
321static unsigned mangle_sdp_packet(struct sk_buff *skb, const char **dptr, 321static int mangle_sdp_packet(struct sk_buff *skb, const char **dptr,
322 unsigned int dataoff, unsigned int *datalen, 322 unsigned int dataoff, unsigned int *datalen,
323 enum sdp_header_types type, 323 enum sdp_header_types type,
324 enum sdp_header_types term, 324 enum sdp_header_types term,
325 char *buffer, int buflen) 325 char *buffer, int buflen)
326{ 326{
327 enum ip_conntrack_info ctinfo; 327 enum ip_conntrack_info ctinfo;
328 struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 328 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
@@ -330,9 +330,9 @@ static unsigned mangle_sdp_packet(struct sk_buff *skb, const char **dptr,
330 330
331 if (ct_sip_get_sdp_header(ct, *dptr, dataoff, *datalen, type, term, 331 if (ct_sip_get_sdp_header(ct, *dptr, dataoff, *datalen, type, term,
332 &matchoff, &matchlen) <= 0) 332 &matchoff, &matchlen) <= 0)
333 return 0; 333 return -ENOENT;
334 return mangle_packet(skb, dptr, datalen, matchoff, matchlen, 334 return mangle_packet(skb, dptr, datalen, matchoff, matchlen,
335 buffer, buflen); 335 buffer, buflen) ? 0 : -EINVAL;
336} 336}
337 337
338static unsigned int ip_nat_sdp_addr(struct sk_buff *skb, const char **dptr, 338static unsigned int ip_nat_sdp_addr(struct sk_buff *skb, const char **dptr,
@@ -346,8 +346,8 @@ static unsigned int ip_nat_sdp_addr(struct sk_buff *skb, const char **dptr,
346 unsigned int buflen; 346 unsigned int buflen;
347 347
348 buflen = sprintf(buffer, NIPQUAD_FMT, NIPQUAD(addr->ip)); 348 buflen = sprintf(buffer, NIPQUAD_FMT, NIPQUAD(addr->ip));
349 if (!mangle_sdp_packet(skb, dptr, dataoff, datalen, type, term, 349 if (mangle_sdp_packet(skb, dptr, dataoff, datalen, type, term,
350 buffer, buflen)) 350 buffer, buflen))
351 return 0; 351 return 0;
352 352
353 return mangle_content_len(skb, dptr, datalen); 353 return mangle_content_len(skb, dptr, datalen);
@@ -381,15 +381,27 @@ static unsigned int ip_nat_sdp_session(struct sk_buff *skb, const char **dptr,
381 381
382 /* Mangle session description owner and contact addresses */ 382 /* Mangle session description owner and contact addresses */
383 buflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(addr->ip)); 383 buflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(addr->ip));
384 if (!mangle_sdp_packet(skb, dptr, dataoff, datalen, 384 if (mangle_sdp_packet(skb, dptr, dataoff, datalen,
385 SDP_HDR_OWNER_IP4, SDP_HDR_MEDIA, 385 SDP_HDR_OWNER_IP4, SDP_HDR_MEDIA,
386 buffer, buflen)) 386 buffer, buflen))
387 return 0; 387 return 0;
388 388
389 if (!mangle_sdp_packet(skb, dptr, dataoff, datalen, 389 switch (mangle_sdp_packet(skb, dptr, dataoff, datalen,
390 SDP_HDR_CONNECTION_IP4, SDP_HDR_MEDIA, 390 SDP_HDR_CONNECTION_IP4, SDP_HDR_MEDIA,
391 buffer, buflen)) 391 buffer, buflen)) {
392 case 0:
393 /*
394 * RFC 2327:
395 *
396 * Session description
397 *
398 * c=* (connection information - not required if included in all media)
399 */
400 case -ENOENT:
401 break;
402 default:
392 return 0; 403 return 0;
404 }
393 405
394 return mangle_content_len(skb, dptr, datalen); 406 return mangle_content_len(skb, dptr, datalen);
395} 407}
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index 316c7af1d2b1..ee898e74808d 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -49,6 +49,15 @@ config NF_CT_ACCT
49 Those counters can be used for flow-based accounting or the 49 Those counters can be used for flow-based accounting or the
50 `connbytes' match. 50 `connbytes' match.
51 51
52 Please note that currently this option only sets a default state.
53 You may change it at boot time with nf_conntrack.acct=0/1 kernel
54 paramater or by loading the nf_conntrack module with acct=0/1.
55
56 You may also disable/enable it on a running system with:
57 sysctl net.netfilter.nf_conntrack_acct=0/1
58
59 This option will be removed in 2.6.29.
60
52 If unsure, say `N'. 61 If unsure, say `N'.
53 62
54config NF_CONNTRACK_MARK 63config NF_CONNTRACK_MARK
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
index 5c4b183f6422..3bd2cc556aea 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -1,6 +1,6 @@
1netfilter-objs := core.o nf_log.o nf_queue.o nf_sockopt.o 1netfilter-objs := core.o nf_log.o nf_queue.o nf_sockopt.o
2 2
3nf_conntrack-y := nf_conntrack_core.o nf_conntrack_standalone.o nf_conntrack_expect.o nf_conntrack_helper.o nf_conntrack_proto.o nf_conntrack_l3proto_generic.o nf_conntrack_proto_generic.o nf_conntrack_proto_tcp.o nf_conntrack_proto_udp.o nf_conntrack_extend.o 3nf_conntrack-y := nf_conntrack_core.o nf_conntrack_standalone.o nf_conntrack_expect.o nf_conntrack_helper.o nf_conntrack_proto.o nf_conntrack_l3proto_generic.o nf_conntrack_proto_generic.o nf_conntrack_proto_tcp.o nf_conntrack_proto_udp.o nf_conntrack_extend.o nf_conntrack_acct.o
4nf_conntrack-$(CONFIG_NF_CONNTRACK_EVENTS) += nf_conntrack_ecache.o 4nf_conntrack-$(CONFIG_NF_CONNTRACK_EVENTS) += nf_conntrack_ecache.o
5 5
6obj-$(CONFIG_NETFILTER) = netfilter.o 6obj-$(CONFIG_NETFILTER) = netfilter.o
diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
new file mode 100644
index 000000000000..59bd8b903a19
--- /dev/null
+++ b/net/netfilter/nf_conntrack_acct.c
@@ -0,0 +1,104 @@
1/* Accouting handling for netfilter. */
2
3/*
4 * (C) 2008 Krzysztof Piotr Oledzki <ole@ans.pl>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/netfilter.h>
12#include <linux/kernel.h>
13#include <linux/moduleparam.h>
14
15#include <net/netfilter/nf_conntrack.h>
16#include <net/netfilter/nf_conntrack_extend.h>
17#include <net/netfilter/nf_conntrack_acct.h>
18
19#ifdef CONFIG_NF_CT_ACCT
20#define NF_CT_ACCT_DEFAULT 1
21#else
22#define NF_CT_ACCT_DEFAULT 0
23#endif
24
25int nf_ct_acct __read_mostly = NF_CT_ACCT_DEFAULT;
26EXPORT_SYMBOL_GPL(nf_ct_acct);
27
28module_param_named(acct, nf_ct_acct, bool, 0644);
29MODULE_PARM_DESC(acct, "Enable connection tracking flow accounting.");
30
31#ifdef CONFIG_SYSCTL
32static struct ctl_table_header *acct_sysctl_header;
33static struct ctl_table acct_sysctl_table[] = {
34 {
35 .ctl_name = CTL_UNNUMBERED,
36 .procname = "nf_conntrack_acct",
37 .data = &nf_ct_acct,
38 .maxlen = sizeof(unsigned int),
39 .mode = 0644,
40 .proc_handler = &proc_dointvec,
41 },
42 {}
43};
44#endif /* CONFIG_SYSCTL */
45
46unsigned int
47seq_print_acct(struct seq_file *s, const struct nf_conn *ct, int dir)
48{
49 struct nf_conn_counter *acct;
50
51 acct = nf_conn_acct_find(ct);
52 if (!acct)
53 return 0;
54
55 return seq_printf(s, "packets=%llu bytes=%llu ",
56 (unsigned long long)acct[dir].packets,
57 (unsigned long long)acct[dir].bytes);
58};
59EXPORT_SYMBOL_GPL(seq_print_acct);
60
61static struct nf_ct_ext_type acct_extend __read_mostly = {
62 .len = sizeof(struct nf_conn_counter[IP_CT_DIR_MAX]),
63 .align = __alignof__(struct nf_conn_counter[IP_CT_DIR_MAX]),
64 .id = NF_CT_EXT_ACCT,
65};
66
67int nf_conntrack_acct_init(void)
68{
69 int ret;
70
71#ifdef CONFIG_NF_CT_ACCT
72 printk(KERN_WARNING "CONFIG_NF_CT_ACCT is deprecated and will be removed soon. Plase use\n");
73 printk(KERN_WARNING "nf_conntrack.acct=1 kernel paramater, acct=1 nf_conntrack module option or\n");
74 printk(KERN_WARNING "sysctl net.netfilter.nf_conntrack_acct=1 to enable it.\n");
75#endif
76
77 ret = nf_ct_extend_register(&acct_extend);
78 if (ret < 0) {
79 printk(KERN_ERR "nf_conntrack_acct: Unable to register extension\n");
80 return ret;
81 }
82
83#ifdef CONFIG_SYSCTL
84 acct_sysctl_header = register_sysctl_paths(nf_net_netfilter_sysctl_path,
85 acct_sysctl_table);
86
87 if (!acct_sysctl_header) {
88 nf_ct_extend_unregister(&acct_extend);
89
90 printk(KERN_ERR "nf_conntrack_acct: can't register to sysctl.\n");
91 return -ENOMEM;
92 }
93#endif
94
95 return 0;
96}
97
98void nf_conntrack_acct_fini(void)
99{
100#ifdef CONFIG_SYSCTL
101 unregister_sysctl_table(acct_sysctl_header);
102#endif
103 nf_ct_extend_unregister(&acct_extend);
104}
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 28d03e64200b..c519d090bdb9 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -37,6 +37,7 @@
37#include <net/netfilter/nf_conntrack_helper.h> 37#include <net/netfilter/nf_conntrack_helper.h>
38#include <net/netfilter/nf_conntrack_core.h> 38#include <net/netfilter/nf_conntrack_core.h>
39#include <net/netfilter/nf_conntrack_extend.h> 39#include <net/netfilter/nf_conntrack_extend.h>
40#include <net/netfilter/nf_conntrack_acct.h>
40 41
41#define NF_CONNTRACK_VERSION "0.5.0" 42#define NF_CONNTRACK_VERSION "0.5.0"
42 43
@@ -555,6 +556,8 @@ init_conntrack(const struct nf_conntrack_tuple *tuple,
555 return NULL; 556 return NULL;
556 } 557 }
557 558
559 nf_ct_acct_ext_add(ct, GFP_ATOMIC);
560
558 spin_lock_bh(&nf_conntrack_lock); 561 spin_lock_bh(&nf_conntrack_lock);
559 exp = nf_ct_find_expectation(tuple); 562 exp = nf_ct_find_expectation(tuple);
560 if (exp) { 563 if (exp) {
@@ -828,17 +831,16 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
828 } 831 }
829 832
830acct: 833acct:
831#ifdef CONFIG_NF_CT_ACCT
832 if (do_acct) { 834 if (do_acct) {
833 ct->counters[CTINFO2DIR(ctinfo)].packets++; 835 struct nf_conn_counter *acct;
834 ct->counters[CTINFO2DIR(ctinfo)].bytes +=
835 skb->len - skb_network_offset(skb);
836 836
837 if ((ct->counters[CTINFO2DIR(ctinfo)].packets & 0x80000000) 837 acct = nf_conn_acct_find(ct);
838 || (ct->counters[CTINFO2DIR(ctinfo)].bytes & 0x80000000)) 838 if (acct) {
839 event |= IPCT_COUNTER_FILLING; 839 acct[CTINFO2DIR(ctinfo)].packets++;
840 acct[CTINFO2DIR(ctinfo)].bytes +=
841 skb->len - skb_network_offset(skb);
842 }
840 } 843 }
841#endif
842 844
843 spin_unlock_bh(&nf_conntrack_lock); 845 spin_unlock_bh(&nf_conntrack_lock);
844 846
@@ -853,15 +855,19 @@ bool __nf_ct_kill_acct(struct nf_conn *ct,
853 const struct sk_buff *skb, 855 const struct sk_buff *skb,
854 int do_acct) 856 int do_acct)
855{ 857{
856#ifdef CONFIG_NF_CT_ACCT
857 if (do_acct) { 858 if (do_acct) {
859 struct nf_conn_counter *acct;
860
858 spin_lock_bh(&nf_conntrack_lock); 861 spin_lock_bh(&nf_conntrack_lock);
859 ct->counters[CTINFO2DIR(ctinfo)].packets++; 862 acct = nf_conn_acct_find(ct);
860 ct->counters[CTINFO2DIR(ctinfo)].bytes += 863 if (acct) {
861 skb->len - skb_network_offset(skb); 864 acct[CTINFO2DIR(ctinfo)].packets++;
865 acct[CTINFO2DIR(ctinfo)].bytes +=
866 skb->len - skb_network_offset(skb);
867 }
862 spin_unlock_bh(&nf_conntrack_lock); 868 spin_unlock_bh(&nf_conntrack_lock);
863 } 869 }
864#endif 870
865 if (del_timer(&ct->timeout)) { 871 if (del_timer(&ct->timeout)) {
866 ct->timeout.function((unsigned long)ct); 872 ct->timeout.function((unsigned long)ct);
867 return true; 873 return true;
@@ -1029,6 +1035,7 @@ void nf_conntrack_cleanup(void)
1029 nf_conntrack_proto_fini(); 1035 nf_conntrack_proto_fini();
1030 nf_conntrack_helper_fini(); 1036 nf_conntrack_helper_fini();
1031 nf_conntrack_expect_fini(); 1037 nf_conntrack_expect_fini();
1038 nf_conntrack_acct_fini();
1032} 1039}
1033 1040
1034struct hlist_head *nf_ct_alloc_hashtable(unsigned int *sizep, int *vmalloced) 1041struct hlist_head *nf_ct_alloc_hashtable(unsigned int *sizep, int *vmalloced)
@@ -1168,6 +1175,10 @@ int __init nf_conntrack_init(void)
1168 if (ret < 0) 1175 if (ret < 0)
1169 goto out_fini_expect; 1176 goto out_fini_expect;
1170 1177
1178 ret = nf_conntrack_acct_init();
1179 if (ret < 0)
1180 goto out_fini_helper;
1181
1171 /* For use by REJECT target */ 1182 /* For use by REJECT target */
1172 rcu_assign_pointer(ip_ct_attach, nf_conntrack_attach); 1183 rcu_assign_pointer(ip_ct_attach, nf_conntrack_attach);
1173 rcu_assign_pointer(nf_ct_destroy, destroy_conntrack); 1184 rcu_assign_pointer(nf_ct_destroy, destroy_conntrack);
@@ -1180,6 +1191,8 @@ int __init nf_conntrack_init(void)
1180 1191
1181 return ret; 1192 return ret;
1182 1193
1194out_fini_helper:
1195 nf_conntrack_helper_fini();
1183out_fini_expect: 1196out_fini_expect:
1184 nf_conntrack_expect_fini(); 1197 nf_conntrack_expect_fini();
1185out_fini_proto: 1198out_fini_proto:
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 95a7967731f9..105a616c5c78 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -37,6 +37,7 @@
37#include <net/netfilter/nf_conntrack_l3proto.h> 37#include <net/netfilter/nf_conntrack_l3proto.h>
38#include <net/netfilter/nf_conntrack_l4proto.h> 38#include <net/netfilter/nf_conntrack_l4proto.h>
39#include <net/netfilter/nf_conntrack_tuple.h> 39#include <net/netfilter/nf_conntrack_tuple.h>
40#include <net/netfilter/nf_conntrack_acct.h>
40#ifdef CONFIG_NF_NAT_NEEDED 41#ifdef CONFIG_NF_NAT_NEEDED
41#include <net/netfilter/nf_nat_core.h> 42#include <net/netfilter/nf_nat_core.h>
42#include <net/netfilter/nf_nat_protocol.h> 43#include <net/netfilter/nf_nat_protocol.h>
@@ -206,22 +207,26 @@ nla_put_failure:
206 return -1; 207 return -1;
207} 208}
208 209
209#ifdef CONFIG_NF_CT_ACCT
210static int 210static int
211ctnetlink_dump_counters(struct sk_buff *skb, const struct nf_conn *ct, 211ctnetlink_dump_counters(struct sk_buff *skb, const struct nf_conn *ct,
212 enum ip_conntrack_dir dir) 212 enum ip_conntrack_dir dir)
213{ 213{
214 enum ctattr_type type = dir ? CTA_COUNTERS_REPLY: CTA_COUNTERS_ORIG; 214 enum ctattr_type type = dir ? CTA_COUNTERS_REPLY: CTA_COUNTERS_ORIG;
215 struct nlattr *nest_count; 215 struct nlattr *nest_count;
216 const struct nf_conn_counter *acct;
217
218 acct = nf_conn_acct_find(ct);
219 if (!acct)
220 return 0;
216 221
217 nest_count = nla_nest_start(skb, type | NLA_F_NESTED); 222 nest_count = nla_nest_start(skb, type | NLA_F_NESTED);
218 if (!nest_count) 223 if (!nest_count)
219 goto nla_put_failure; 224 goto nla_put_failure;
220 225
221 NLA_PUT_BE32(skb, CTA_COUNTERS32_PACKETS, 226 NLA_PUT_BE64(skb, CTA_COUNTERS_PACKETS,
222 htonl(ct->counters[dir].packets)); 227 cpu_to_be64(acct[dir].packets));
223 NLA_PUT_BE32(skb, CTA_COUNTERS32_BYTES, 228 NLA_PUT_BE64(skb, CTA_COUNTERS_BYTES,
224 htonl(ct->counters[dir].bytes)); 229 cpu_to_be64(acct[dir].bytes));
225 230
226 nla_nest_end(skb, nest_count); 231 nla_nest_end(skb, nest_count);
227 232
@@ -230,9 +235,6 @@ ctnetlink_dump_counters(struct sk_buff *skb, const struct nf_conn *ct,
230nla_put_failure: 235nla_put_failure:
231 return -1; 236 return -1;
232} 237}
233#else
234#define ctnetlink_dump_counters(a, b, c) (0)
235#endif
236 238
237#ifdef CONFIG_NF_CONNTRACK_MARK 239#ifdef CONFIG_NF_CONNTRACK_MARK
238static inline int 240static inline int
@@ -501,11 +503,6 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
501 goto nla_put_failure; 503 goto nla_put_failure;
502#endif 504#endif
503 505
504 if (events & IPCT_COUNTER_FILLING &&
505 (ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 ||
506 ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY) < 0))
507 goto nla_put_failure;
508
509 if (events & IPCT_RELATED && 506 if (events & IPCT_RELATED &&
510 ctnetlink_dump_master(skb, ct) < 0) 507 ctnetlink_dump_master(skb, ct) < 0)
511 goto nla_put_failure; 508 goto nla_put_failure;
@@ -576,11 +573,15 @@ restart:
576 cb->args[1] = (unsigned long)ct; 573 cb->args[1] = (unsigned long)ct;
577 goto out; 574 goto out;
578 } 575 }
579#ifdef CONFIG_NF_CT_ACCT 576
580 if (NFNL_MSG_TYPE(cb->nlh->nlmsg_type) == 577 if (NFNL_MSG_TYPE(cb->nlh->nlmsg_type) ==
581 IPCTNL_MSG_CT_GET_CTRZERO) 578 IPCTNL_MSG_CT_GET_CTRZERO) {
582 memset(&ct->counters, 0, sizeof(ct->counters)); 579 struct nf_conn_counter *acct;
583#endif 580
581 acct = nf_conn_acct_find(ct);
582 if (acct)
583 memset(acct, 0, sizeof(struct nf_conn_counter[IP_CT_DIR_MAX]));
584 }
584 } 585 }
585 if (cb->args[1]) { 586 if (cb->args[1]) {
586 cb->args[1] = 0; 587 cb->args[1] = 0;
@@ -832,14 +833,9 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
832 u_int8_t u3 = nfmsg->nfgen_family; 833 u_int8_t u3 = nfmsg->nfgen_family;
833 int err = 0; 834 int err = 0;
834 835
835 if (nlh->nlmsg_flags & NLM_F_DUMP) { 836 if (nlh->nlmsg_flags & NLM_F_DUMP)
836#ifndef CONFIG_NF_CT_ACCT
837 if (NFNL_MSG_TYPE(nlh->nlmsg_type) == IPCTNL_MSG_CT_GET_CTRZERO)
838 return -ENOTSUPP;
839#endif
840 return netlink_dump_start(ctnl, skb, nlh, ctnetlink_dump_table, 837 return netlink_dump_start(ctnl, skb, nlh, ctnetlink_dump_table,
841 ctnetlink_done); 838 ctnetlink_done);
842 }
843 839
844 if (cda[CTA_TUPLE_ORIG]) 840 if (cda[CTA_TUPLE_ORIG])
845 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3); 841 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
@@ -1152,6 +1148,8 @@ ctnetlink_create_conntrack(struct nlattr *cda[],
1152 goto err; 1148 goto err;
1153 } 1149 }
1154 1150
1151 nf_ct_acct_ext_add(ct, GFP_KERNEL);
1152
1155#if defined(CONFIG_NF_CONNTRACK_MARK) 1153#if defined(CONFIG_NF_CONNTRACK_MARK)
1156 if (cda[CTA_MARK]) 1154 if (cda[CTA_MARK])
1157 ct->mark = ntohl(nla_get_be32(cda[CTA_MARK])); 1155 ct->mark = ntohl(nla_get_be32(cda[CTA_MARK]));
diff --git a/net/netfilter/nf_conntrack_proto_sctp.c b/net/netfilter/nf_conntrack_proto_sctp.c
index 41183a4d2d62..30aa5b94a771 100644
--- a/net/netfilter/nf_conntrack_proto_sctp.c
+++ b/net/netfilter/nf_conntrack_proto_sctp.c
@@ -482,11 +482,11 @@ static int sctp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
482 482
483 NLA_PUT_BE32(skb, 483 NLA_PUT_BE32(skb,
484 CTA_PROTOINFO_SCTP_VTAG_ORIGINAL, 484 CTA_PROTOINFO_SCTP_VTAG_ORIGINAL,
485 htonl(ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL])); 485 ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL]);
486 486
487 NLA_PUT_BE32(skb, 487 NLA_PUT_BE32(skb,
488 CTA_PROTOINFO_SCTP_VTAG_REPLY, 488 CTA_PROTOINFO_SCTP_VTAG_REPLY,
489 htonl(ct->proto.sctp.vtag[IP_CT_DIR_REPLY])); 489 ct->proto.sctp.vtag[IP_CT_DIR_REPLY]);
490 490
491 read_unlock_bh(&sctp_lock); 491 read_unlock_bh(&sctp_lock);
492 492
@@ -530,9 +530,9 @@ static int nlattr_to_sctp(struct nlattr *cda[], struct nf_conn *ct)
530 write_lock_bh(&sctp_lock); 530 write_lock_bh(&sctp_lock);
531 ct->proto.sctp.state = nla_get_u8(tb[CTA_PROTOINFO_SCTP_STATE]); 531 ct->proto.sctp.state = nla_get_u8(tb[CTA_PROTOINFO_SCTP_STATE]);
532 ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL] = 532 ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL] =
533 ntohl(nla_get_be32(tb[CTA_PROTOINFO_SCTP_VTAG_ORIGINAL])); 533 nla_get_be32(tb[CTA_PROTOINFO_SCTP_VTAG_ORIGINAL]);
534 ct->proto.sctp.vtag[IP_CT_DIR_REPLY] = 534 ct->proto.sctp.vtag[IP_CT_DIR_REPLY] =
535 ntohl(nla_get_be32(tb[CTA_PROTOINFO_SCTP_VTAG_REPLY])); 535 nla_get_be32(tb[CTA_PROTOINFO_SCTP_VTAG_REPLY]);
536 write_unlock_bh(&sctp_lock); 536 write_unlock_bh(&sctp_lock);
537 537
538 return 0; 538 return 0;
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index 46ea542d0df9..869ef9349d0f 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -25,6 +25,7 @@
25#include <net/netfilter/nf_conntrack_l4proto.h> 25#include <net/netfilter/nf_conntrack_l4proto.h>
26#include <net/netfilter/nf_conntrack_expect.h> 26#include <net/netfilter/nf_conntrack_expect.h>
27#include <net/netfilter/nf_conntrack_helper.h> 27#include <net/netfilter/nf_conntrack_helper.h>
28#include <net/netfilter/nf_conntrack_acct.h>
28 29
29MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
30 31
@@ -38,19 +39,6 @@ print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
38} 39}
39EXPORT_SYMBOL_GPL(print_tuple); 40EXPORT_SYMBOL_GPL(print_tuple);
40 41
41#ifdef CONFIG_NF_CT_ACCT
42static unsigned int
43seq_print_counters(struct seq_file *s,
44 const struct ip_conntrack_counter *counter)
45{
46 return seq_printf(s, "packets=%llu bytes=%llu ",
47 (unsigned long long)counter->packets,
48 (unsigned long long)counter->bytes);
49}
50#else
51#define seq_print_counters(x, y) 0
52#endif
53
54struct ct_iter_state { 42struct ct_iter_state {
55 unsigned int bucket; 43 unsigned int bucket;
56}; 44};
@@ -146,7 +134,7 @@ static int ct_seq_show(struct seq_file *s, void *v)
146 l3proto, l4proto)) 134 l3proto, l4proto))
147 return -ENOSPC; 135 return -ENOSPC;
148 136
149 if (seq_print_counters(s, &ct->counters[IP_CT_DIR_ORIGINAL])) 137 if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL))
150 return -ENOSPC; 138 return -ENOSPC;
151 139
152 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) 140 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
@@ -157,7 +145,7 @@ static int ct_seq_show(struct seq_file *s, void *v)
157 l3proto, l4proto)) 145 l3proto, l4proto))
158 return -ENOSPC; 146 return -ENOSPC;
159 147
160 if (seq_print_counters(s, &ct->counters[IP_CT_DIR_REPLY])) 148 if (seq_print_acct(s, ct, IP_CT_DIR_REPLY))
161 return -ENOSPC; 149 return -ENOSPC;
162 150
163 if (test_bit(IPS_ASSURED_BIT, &ct->status)) 151 if (test_bit(IPS_ASSURED_BIT, &ct->status))
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index b8173af8c24a..9a35b57ab76d 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -453,6 +453,14 @@ __build_packet_message(struct nfulnl_instance *inst,
453 } 453 }
454 } 454 }
455 455
456 if (indev && skb_mac_header_was_set(skb)) {
457 NLA_PUT_BE16(inst->skb, NFULA_HWTYPE, htons(skb->dev->type));
458 NLA_PUT_BE16(inst->skb, NFULA_HWLEN,
459 htons(skb->dev->hard_header_len));
460 NLA_PUT(inst->skb, NFULA_HWHEADER, skb->dev->hard_header_len,
461 skb_mac_header(skb));
462 }
463
456 if (skb->tstamp.tv64) { 464 if (skb->tstamp.tv64) {
457 struct nfulnl_msg_packet_timestamp ts; 465 struct nfulnl_msg_packet_timestamp ts;
458 struct timeval tv = ktime_to_timeval(skb->tstamp); 466 struct timeval tv = ktime_to_timeval(skb->tstamp);
diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c
index 217e2b686322..beb5094703cb 100644
--- a/net/netfilter/xt_TCPMSS.c
+++ b/net/netfilter/xt_TCPMSS.c
@@ -147,17 +147,21 @@ tcpmss_mangle_packet(struct sk_buff *skb,
147 return TCPOLEN_MSS; 147 return TCPOLEN_MSS;
148} 148}
149 149
150static u_int32_t tcpmss_reverse_mtu4(const struct iphdr *iph) 150static u_int32_t tcpmss_reverse_mtu(const struct sk_buff *skb,
151 unsigned int family)
151{ 152{
152 struct flowi fl = { 153 struct flowi fl = {};
153 .fl4_dst = iph->saddr,
154 };
155 const struct nf_afinfo *ai; 154 const struct nf_afinfo *ai;
156 struct rtable *rt = NULL; 155 struct rtable *rt = NULL;
157 u_int32_t mtu = ~0U; 156 u_int32_t mtu = ~0U;
158 157
158 if (family == PF_INET)
159 fl.fl4_dst = ip_hdr(skb)->saddr;
160 else
161 fl.fl6_dst = ipv6_hdr(skb)->saddr;
162
159 rcu_read_lock(); 163 rcu_read_lock();
160 ai = nf_get_afinfo(AF_INET); 164 ai = nf_get_afinfo(family);
161 if (ai != NULL) 165 if (ai != NULL)
162 ai->route((struct dst_entry **)&rt, &fl); 166 ai->route((struct dst_entry **)&rt, &fl);
163 rcu_read_unlock(); 167 rcu_read_unlock();
@@ -178,7 +182,8 @@ tcpmss_tg4(struct sk_buff *skb, const struct net_device *in,
178 __be16 newlen; 182 __be16 newlen;
179 int ret; 183 int ret;
180 184
181 ret = tcpmss_mangle_packet(skb, targinfo, tcpmss_reverse_mtu4(iph), 185 ret = tcpmss_mangle_packet(skb, targinfo,
186 tcpmss_reverse_mtu(skb, PF_INET),
182 iph->ihl * 4, 187 iph->ihl * 4,
183 sizeof(*iph) + sizeof(struct tcphdr)); 188 sizeof(*iph) + sizeof(struct tcphdr));
184 if (ret < 0) 189 if (ret < 0)
@@ -193,28 +198,6 @@ tcpmss_tg4(struct sk_buff *skb, const struct net_device *in,
193} 198}
194 199
195#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) 200#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
196static u_int32_t tcpmss_reverse_mtu6(const struct ipv6hdr *iph)
197{
198 struct flowi fl = {
199 .fl6_dst = iph->saddr,
200 };
201 const struct nf_afinfo *ai;
202 struct rtable *rt = NULL;
203 u_int32_t mtu = ~0U;
204
205 rcu_read_lock();
206 ai = nf_get_afinfo(AF_INET6);
207 if (ai != NULL)
208 ai->route((struct dst_entry **)&rt, &fl);
209 rcu_read_unlock();
210
211 if (rt != NULL) {
212 mtu = dst_mtu(&rt->u.dst);
213 dst_release(&rt->u.dst);
214 }
215 return mtu;
216}
217
218static unsigned int 201static unsigned int
219tcpmss_tg6(struct sk_buff *skb, const struct net_device *in, 202tcpmss_tg6(struct sk_buff *skb, const struct net_device *in,
220 const struct net_device *out, unsigned int hooknum, 203 const struct net_device *out, unsigned int hooknum,
@@ -229,7 +212,8 @@ tcpmss_tg6(struct sk_buff *skb, const struct net_device *in,
229 tcphoff = ipv6_skip_exthdr(skb, sizeof(*ipv6h), &nexthdr); 212 tcphoff = ipv6_skip_exthdr(skb, sizeof(*ipv6h), &nexthdr);
230 if (tcphoff < 0) 213 if (tcphoff < 0)
231 return NF_DROP; 214 return NF_DROP;
232 ret = tcpmss_mangle_packet(skb, targinfo, tcpmss_reverse_mtu6(ipv6h), 215 ret = tcpmss_mangle_packet(skb, targinfo,
216 tcpmss_reverse_mtu(skb, PF_INET6),
233 tcphoff, 217 tcphoff,
234 sizeof(*ipv6h) + sizeof(struct tcphdr)); 218 sizeof(*ipv6h) + sizeof(struct tcphdr));
235 if (ret < 0) 219 if (ret < 0)
diff --git a/net/netfilter/xt_connbytes.c b/net/netfilter/xt_connbytes.c
index d7e8983cd37f..3e39c4fe1931 100644
--- a/net/netfilter/xt_connbytes.c
+++ b/net/netfilter/xt_connbytes.c
@@ -8,6 +8,7 @@
8#include <linux/netfilter/x_tables.h> 8#include <linux/netfilter/x_tables.h>
9#include <linux/netfilter/xt_connbytes.h> 9#include <linux/netfilter/xt_connbytes.h>
10#include <net/netfilter/nf_conntrack.h> 10#include <net/netfilter/nf_conntrack.h>
11#include <net/netfilter/nf_conntrack_acct.h>
11 12
12MODULE_LICENSE("GPL"); 13MODULE_LICENSE("GPL");
13MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); 14MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
@@ -27,12 +28,15 @@ connbytes_mt(const struct sk_buff *skb, const struct net_device *in,
27 u_int64_t what = 0; /* initialize to make gcc happy */ 28 u_int64_t what = 0; /* initialize to make gcc happy */
28 u_int64_t bytes = 0; 29 u_int64_t bytes = 0;
29 u_int64_t pkts = 0; 30 u_int64_t pkts = 0;
30 const struct ip_conntrack_counter *counters; 31 const struct nf_conn_counter *counters;
31 32
32 ct = nf_ct_get(skb, &ctinfo); 33 ct = nf_ct_get(skb, &ctinfo);
33 if (!ct) 34 if (!ct)
34 return false; 35 return false;
35 counters = ct->counters; 36
37 counters = nf_conn_acct_find(ct);
38 if (!counters)
39 return false;
36 40
37 switch (sinfo->what) { 41 switch (sinfo->what) {
38 case XT_CONNBYTES_PKTS: 42 case XT_CONNBYTES_PKTS:
diff --git a/net/netfilter/xt_time.c b/net/netfilter/xt_time.c
index ed76baab4734..9f328593287e 100644
--- a/net/netfilter/xt_time.c
+++ b/net/netfilter/xt_time.c
@@ -173,7 +173,7 @@ time_mt(const struct sk_buff *skb, const struct net_device *in,
173 __net_timestamp((struct sk_buff *)skb); 173 __net_timestamp((struct sk_buff *)skb);
174 174
175 stamp = ktime_to_ns(skb->tstamp); 175 stamp = ktime_to_ns(skb->tstamp);
176 do_div(stamp, NSEC_PER_SEC); 176 stamp = div_s64(stamp, NSEC_PER_SEC);
177 177
178 if (info->flags & XT_TIME_LOCAL_TZ) 178 if (info->flags & XT_TIME_LOCAL_TZ)
179 /* Adjust for local timezone */ 179 /* Adjust for local timezone */
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 0ddf69286f92..cb625b4d6da5 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -356,44 +356,99 @@ static struct Qdisc noqueue_qdisc = {
356}; 356};
357 357
358 358
359static int fifo_fast_enqueue(struct sk_buff *skb, struct Qdisc* qdisc) 359static const u8 prio2band[TC_PRIO_MAX+1] =
360 { 1, 2, 2, 2, 1, 2, 0, 0 , 1, 1, 1, 1, 1, 1, 1, 1 };
361
362/* 3-band FIFO queue: old style, but should be a bit faster than
363 generic prio+fifo combination.
364 */
365
366#define PFIFO_FAST_BANDS 3
367
368static inline struct sk_buff_head *prio2list(struct sk_buff *skb,
369 struct Qdisc *qdisc)
370{
371 struct sk_buff_head *list = qdisc_priv(qdisc);
372 return list + prio2band[skb->priority & TC_PRIO_MAX];
373}
374
375static int pfifo_fast_enqueue(struct sk_buff *skb, struct Qdisc* qdisc)
360{ 376{
361 struct sk_buff_head *list = &qdisc->q; 377 struct sk_buff_head *list = prio2list(skb, qdisc);
362 378
363 if (skb_queue_len(list) < qdisc_dev(qdisc)->tx_queue_len) 379 if (skb_queue_len(list) < qdisc_dev(qdisc)->tx_queue_len) {
380 qdisc->q.qlen++;
364 return __qdisc_enqueue_tail(skb, qdisc, list); 381 return __qdisc_enqueue_tail(skb, qdisc, list);
382 }
365 383
366 return qdisc_drop(skb, qdisc); 384 return qdisc_drop(skb, qdisc);
367} 385}
368 386
369static struct sk_buff *fifo_fast_dequeue(struct Qdisc* qdisc) 387static struct sk_buff *pfifo_fast_dequeue(struct Qdisc* qdisc)
370{ 388{
371 struct sk_buff_head *list = &qdisc->q; 389 int prio;
390 struct sk_buff_head *list = qdisc_priv(qdisc);
372 391
373 if (!skb_queue_empty(list)) 392 for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) {
374 return __qdisc_dequeue_head(qdisc, list); 393 if (!skb_queue_empty(list + prio)) {
394 qdisc->q.qlen--;
395 return __qdisc_dequeue_head(qdisc, list + prio);
396 }
397 }
375 398
376 return NULL; 399 return NULL;
377} 400}
378 401
379static int fifo_fast_requeue(struct sk_buff *skb, struct Qdisc* qdisc) 402static int pfifo_fast_requeue(struct sk_buff *skb, struct Qdisc* qdisc)
380{ 403{
381 return __qdisc_requeue(skb, qdisc, &qdisc->q); 404 qdisc->q.qlen++;
405 return __qdisc_requeue(skb, qdisc, prio2list(skb, qdisc));
382} 406}
383 407
384static void fifo_fast_reset(struct Qdisc* qdisc) 408static void pfifo_fast_reset(struct Qdisc* qdisc)
385{ 409{
386 __qdisc_reset_queue(qdisc, &qdisc->q); 410 int prio;
411 struct sk_buff_head *list = qdisc_priv(qdisc);
412
413 for (prio = 0; prio < PFIFO_FAST_BANDS; prio++)
414 __qdisc_reset_queue(qdisc, list + prio);
415
387 qdisc->qstats.backlog = 0; 416 qdisc->qstats.backlog = 0;
417 qdisc->q.qlen = 0;
388} 418}
389 419
390static struct Qdisc_ops fifo_fast_ops __read_mostly = { 420static int pfifo_fast_dump(struct Qdisc *qdisc, struct sk_buff *skb)
391 .id = "fifo_fast", 421{
392 .priv_size = 0, 422 struct tc_prio_qopt opt = { .bands = PFIFO_FAST_BANDS };
393 .enqueue = fifo_fast_enqueue, 423
394 .dequeue = fifo_fast_dequeue, 424 memcpy(&opt.priomap, prio2band, TC_PRIO_MAX+1);
395 .requeue = fifo_fast_requeue, 425 NLA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
396 .reset = fifo_fast_reset, 426 return skb->len;
427
428nla_put_failure:
429 return -1;
430}
431
432static int pfifo_fast_init(struct Qdisc *qdisc, struct nlattr *opt)
433{
434 int prio;
435 struct sk_buff_head *list = qdisc_priv(qdisc);
436
437 for (prio = 0; prio < PFIFO_FAST_BANDS; prio++)
438 skb_queue_head_init(list + prio);
439
440 return 0;
441}
442
443static struct Qdisc_ops pfifo_fast_ops __read_mostly = {
444 .id = "pfifo_fast",
445 .priv_size = PFIFO_FAST_BANDS * sizeof(struct sk_buff_head),
446 .enqueue = pfifo_fast_enqueue,
447 .dequeue = pfifo_fast_dequeue,
448 .requeue = pfifo_fast_requeue,
449 .init = pfifo_fast_init,
450 .reset = pfifo_fast_reset,
451 .dump = pfifo_fast_dump,
397 .owner = THIS_MODULE, 452 .owner = THIS_MODULE,
398}; 453};
399 454
@@ -522,7 +577,7 @@ static void attach_one_default_qdisc(struct net_device *dev,
522 577
523 if (dev->tx_queue_len) { 578 if (dev->tx_queue_len) {
524 qdisc = qdisc_create_dflt(dev, dev_queue, 579 qdisc = qdisc_create_dflt(dev, dev_queue,
525 &fifo_fast_ops, TC_H_ROOT); 580 &pfifo_fast_ops, TC_H_ROOT);
526 if (!qdisc) { 581 if (!qdisc) {
527 printk(KERN_INFO "%s: activation failed\n", dev->name); 582 printk(KERN_INFO "%s: activation failed\n", dev->name);
528 return; 583 return;
@@ -550,9 +605,9 @@ void dev_activate(struct net_device *dev)
550 int need_watchdog; 605 int need_watchdog;
551 606
552 /* No queueing discipline is attached to device; 607 /* No queueing discipline is attached to device;
553 * create default one i.e. fifo_fast for devices, 608 create default one i.e. pfifo_fast for devices,
554 * which need queueing and noqueue_qdisc for 609 which need queueing and noqueue_qdisc for
555 * virtual interfaces. 610 virtual interfaces
556 */ 611 */
557 612
558 if (dev_all_qdisc_sleeping_noop(dev)) 613 if (dev_all_qdisc_sleeping_noop(dev))
@@ -576,7 +631,6 @@ static void dev_deactivate_queue(struct net_device *dev,
576 void *_qdisc_default) 631 void *_qdisc_default)
577{ 632{
578 struct Qdisc *qdisc_default = _qdisc_default; 633 struct Qdisc *qdisc_default = _qdisc_default;
579 struct sk_buff *skb = NULL;
580 struct Qdisc *qdisc; 634 struct Qdisc *qdisc;
581 635
582 qdisc = dev_queue->qdisc; 636 qdisc = dev_queue->qdisc;
@@ -588,8 +642,6 @@ static void dev_deactivate_queue(struct net_device *dev,
588 642
589 spin_unlock_bh(qdisc_lock(qdisc)); 643 spin_unlock_bh(qdisc_lock(qdisc));
590 } 644 }
591
592 kfree_skb(skb);
593} 645}
594 646
595static bool some_qdisc_is_running(struct net_device *dev, int lock) 647static bool some_qdisc_is_running(struct net_device *dev, int lock)
diff --git a/samples/firmware_class/firmware_sample_firmware_class.c b/samples/firmware_class/firmware_sample_firmware_class.c
index 9392116e47b0..e6cf7a43a297 100644
--- a/samples/firmware_class/firmware_sample_firmware_class.c
+++ b/samples/firmware_class/firmware_sample_firmware_class.c
@@ -124,7 +124,7 @@ static int fw_setup_class_device(struct class_device *class_dev,
124 class_dev->class_id[BUS_ID_SIZE-1] = '\0'; 124 class_dev->class_id[BUS_ID_SIZE-1] = '\0';
125 class_dev->dev = device; 125 class_dev->dev = device;
126 126
127 class_dev->class = &firmware_class, 127 class_dev->class = &firmware_class;
128 class_set_devdata(class_dev, fw_priv); 128 class_set_devdata(class_dev, fw_priv);
129 retval = class_device_register(class_dev); 129 retval = class_device_register(class_dev);
130 if (retval) { 130 if (retval) {
diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c
index b0a1b4fe6584..7395c0bbae18 100644
--- a/samples/kobject/kset-example.c
+++ b/samples/kobject/kset-example.c
@@ -211,7 +211,7 @@ static struct foo_obj *create_foo_obj(const char *name)
211 */ 211 */
212 retval = kobject_init_and_add(&foo->kobj, &foo_ktype, NULL, "%s", name); 212 retval = kobject_init_and_add(&foo->kobj, &foo_ktype, NULL, "%s", name);
213 if (retval) { 213 if (retval) {
214 kfree(foo); 214 kobject_put(&foo->kobj);
215 return NULL; 215 return NULL;
216 } 216 }
217 217
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 17092d6c7db3..9ee9783aea57 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -101,6 +101,7 @@ quiet_cmd_kernel-mod = MODPOST $@
101 cmd_kernel-mod = $(modpost) $@ 101 cmd_kernel-mod = $(modpost) $@
102 102
103vmlinux.o: FORCE 103vmlinux.o: FORCE
104 @rm -fr $(kernelmarkersfile)
104 $(call cmd,kernel-mod) 105 $(call cmd,kernel-mod)
105 106
106# Declare generated files as targets for modpost 107# Declare generated files as targets for modpost
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 37d5c363fbcd..1fcaf3284a6a 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -340,11 +340,18 @@ static int do_acpi_entry(const char *filename,
340} 340}
341 341
342/* looks like: "pnp:dD" */ 342/* looks like: "pnp:dD" */
343static int do_pnp_entry(const char *filename, 343static void do_pnp_device_entry(void *symval, unsigned long size,
344 struct pnp_device_id *id, char *alias) 344 struct module *mod)
345{ 345{
346 sprintf(alias, "pnp:d%s*", id->id); 346 const unsigned long id_size = sizeof(struct pnp_device_id);
347 return 1; 347 const struct pnp_device_id *id = symval;
348
349 device_id_check(mod->name, "pnp", size, id_size, symval);
350
351 buf_printf(&mod->dev_table_buf,
352 "MODULE_ALIAS(\"pnp:d%s*\");\n", id->id);
353 buf_printf(&mod->dev_table_buf,
354 "MODULE_ALIAS(\"acpi*:%s:*\");\n", id->id);
348} 355}
349 356
350/* looks like: "pnp:dD" for every device of the card */ 357/* looks like: "pnp:dD" for every device of the card */
@@ -388,9 +395,12 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
388 } 395 }
389 396
390 /* add an individual alias for every device entry */ 397 /* add an individual alias for every device entry */
391 if (!dup) 398 if (!dup) {
392 buf_printf(&mod->dev_table_buf, 399 buf_printf(&mod->dev_table_buf,
393 "MODULE_ALIAS(\"pnp:d%s*\");\n", id); 400 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
401 buf_printf(&mod->dev_table_buf,
402 "MODULE_ALIAS(\"acpi*:%s:*\");\n", id);
403 }
394 } 404 }
395 } 405 }
396} 406}
@@ -701,9 +711,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
701 sizeof(struct acpi_device_id), "acpi", 711 sizeof(struct acpi_device_id), "acpi",
702 do_acpi_entry, mod); 712 do_acpi_entry, mod);
703 else if (sym_is(symname, "__mod_pnp_device_table")) 713 else if (sym_is(symname, "__mod_pnp_device_table"))
704 do_table(symval, sym->st_size, 714 do_pnp_device_entry(symval, sym->st_size, mod);
705 sizeof(struct pnp_device_id), "pnp",
706 do_pnp_entry, mod);
707 else if (sym_is(symname, "__mod_pnp_card_device_table")) 715 else if (sym_is(symname, "__mod_pnp_card_device_table"))
708 do_pnp_card_entries(symval, sym->st_size, mod); 716 do_pnp_card_entries(symval, sym->st_size, mod);
709 else if (sym_is(symname, "__mod_pcmcia_device_table")) 717 else if (sym_is(symname, "__mod_pcmcia_device_table"))
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index a07f91aac920..8f038e6d5f98 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1992,7 +1992,8 @@ static void read_markers(const char *fname)
1992 mod->skip = 1; 1992 mod->skip = 1;
1993 } 1993 }
1994 1994
1995 add_marker(mod, marker, fmt); 1995 if (!mod->skip)
1996 add_marker(mod, marker, fmt);
1996 } 1997 }
1997 return; 1998 return;
1998fail: 1999fail:
diff --git a/sound/core/init.c b/sound/core/init.c
index 5c254d498ae0..df46bbc25dc2 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -548,8 +548,9 @@ int snd_card_register(struct snd_card *card)
548 snd_assert(card != NULL, return -EINVAL); 548 snd_assert(card != NULL, return -EINVAL);
549#ifndef CONFIG_SYSFS_DEPRECATED 549#ifndef CONFIG_SYSFS_DEPRECATED
550 if (!card->card_dev) { 550 if (!card->card_dev) {
551 card->card_dev = device_create(sound_class, card->dev, 0, 551 card->card_dev = device_create_drvdata(sound_class, card->dev,
552 "card%i", card->number); 552 MKDEV(0, 0), NULL,
553 "card%i", card->number);
553 if (IS_ERR(card->card_dev)) 554 if (IS_ERR(card->card_dev))
554 card->card_dev = NULL; 555 card->card_dev = NULL;
555 } 556 }
diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c
index a9c23b2502ad..7d89c081a086 100644
--- a/sound/oss/soundcard.c
+++ b/sound/oss/soundcard.c
@@ -560,17 +560,19 @@ static int __init oss_init(void)
560 sound_dmap_flag = (dmabuf > 0 ? 1 : 0); 560 sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
561 561
562 for (i = 0; i < ARRAY_SIZE(dev_list); i++) { 562 for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
563 device_create(sound_class, NULL, 563 device_create_drvdata(sound_class, NULL,
564 MKDEV(SOUND_MAJOR, dev_list[i].minor), 564 MKDEV(SOUND_MAJOR, dev_list[i].minor),
565 "%s", dev_list[i].name); 565 NULL, "%s", dev_list[i].name);
566 566
567 if (!dev_list[i].num) 567 if (!dev_list[i].num)
568 continue; 568 continue;
569 569
570 for (j = 1; j < *dev_list[i].num; j++) 570 for (j = 1; j < *dev_list[i].num; j++)
571 device_create(sound_class, NULL, 571 device_create_drvdata(sound_class, NULL,
572 MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)), 572 MKDEV(SOUND_MAJOR,
573 "%s%d", dev_list[i].name, j); 573 dev_list[i].minor + (j*0x10)),
574 NULL,
575 "%s%d", dev_list[i].name, j);
574 } 576 }
575 577
576 if (sound_nblocks >= 1024) 578 if (sound_nblocks >= 1024)
diff --git a/sound/sound_core.c b/sound/sound_core.c
index dcfc1d5ce631..1b04259a4328 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -171,8 +171,9 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati
171 else 171 else
172 sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP); 172 sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP);
173 173
174 device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor), 174 device_create_drvdata(sound_class, dev,
175 s->name+6); 175 MKDEV(SOUND_MAJOR, s->unit_minor),
176 NULL, s->name+6);
176 return r; 177 return r;
177 178
178 fail: 179 fail: