aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Kconfig15
-rw-r--r--drivers/acpi/Makefile3
-rw-r--r--drivers/acpi/ac.c9
-rw-r--r--drivers/acpi/acpi_memhotplug.c5
-rw-r--r--drivers/acpi/asus_acpi.c73
-rw-r--r--drivers/acpi/battery.c31
-rw-r--r--drivers/acpi/bay.c506
-rw-r--r--drivers/acpi/blacklist.c29
-rw-r--r--drivers/acpi/bus.c45
-rw-r--r--drivers/acpi/button.c223
-rw-r--r--drivers/acpi/container.c5
-rw-r--r--drivers/acpi/dispatcher/dsfield.c32
-rw-r--r--drivers/acpi/dispatcher/dsinit.c25
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c55
-rw-r--r--drivers/acpi/dispatcher/dsmthdat.c2
-rw-r--r--drivers/acpi/dispatcher/dsobject.c78
-rw-r--r--drivers/acpi/dispatcher/dsopcode.c6
-rw-r--r--drivers/acpi/dispatcher/dsutils.c2
-rw-r--r--drivers/acpi/dispatcher/dswexec.c12
-rw-r--r--drivers/acpi/dispatcher/dswload.c19
-rw-r--r--drivers/acpi/dispatcher/dswscope.c2
-rw-r--r--drivers/acpi/dispatcher/dswstate.c2
-rw-r--r--drivers/acpi/dock.c169
-rw-r--r--drivers/acpi/ec.c363
-rw-r--r--drivers/acpi/events/evevent.c17
-rw-r--r--drivers/acpi/events/evgpe.c91
-rw-r--r--drivers/acpi/events/evgpeblk.c64
-rw-r--r--drivers/acpi/events/evmisc.c202
-rw-r--r--drivers/acpi/events/evregion.c17
-rw-r--r--drivers/acpi/events/evrgnini.c168
-rw-r--r--drivers/acpi/events/evsci.c14
-rw-r--r--drivers/acpi/events/evxface.c8
-rw-r--r--drivers/acpi/events/evxfevnt.c27
-rw-r--r--drivers/acpi/events/evxfregn.c2
-rw-r--r--drivers/acpi/executer/exconfig.c235
-rw-r--r--drivers/acpi/executer/exconvrt.c2
-rw-r--r--drivers/acpi/executer/excreate.c21
-rw-r--r--drivers/acpi/executer/exdump.c29
-rw-r--r--drivers/acpi/executer/exfield.c2
-rw-r--r--drivers/acpi/executer/exfldio.c7
-rw-r--r--drivers/acpi/executer/exmisc.c2
-rw-r--r--drivers/acpi/executer/exmutex.c92
-rw-r--r--drivers/acpi/executer/exnames.c2
-rw-r--r--drivers/acpi/executer/exoparg1.c4
-rw-r--r--drivers/acpi/executer/exoparg2.c2
-rw-r--r--drivers/acpi/executer/exoparg3.c2
-rw-r--r--drivers/acpi/executer/exoparg6.c2
-rw-r--r--drivers/acpi/executer/exprep.c2
-rw-r--r--drivers/acpi/executer/exregion.c16
-rw-r--r--drivers/acpi/executer/exresnte.c2
-rw-r--r--drivers/acpi/executer/exresolv.c10
-rw-r--r--drivers/acpi/executer/exresop.c12
-rw-r--r--drivers/acpi/executer/exstore.c2
-rw-r--r--drivers/acpi/executer/exstoren.c2
-rw-r--r--drivers/acpi/executer/exstorob.c2
-rw-r--r--drivers/acpi/executer/exsystem.c110
-rw-r--r--drivers/acpi/executer/exutils.c106
-rw-r--r--drivers/acpi/fan.c9
-rw-r--r--drivers/acpi/glue.c121
-rw-r--r--drivers/acpi/hardware/hwacpi.c56
-rw-r--r--drivers/acpi/hardware/hwgpe.c15
-rw-r--r--drivers/acpi/hardware/hwregs.c98
-rw-r--r--drivers/acpi/hardware/hwsleep.c81
-rw-r--r--drivers/acpi/hardware/hwtimer.c9
-rw-r--r--drivers/acpi/hotkey.c5
-rw-r--r--drivers/acpi/i2c_ec.c8
-rw-r--r--drivers/acpi/ibm_acpi.c1042
-rw-r--r--drivers/acpi/motherboard.c40
-rw-r--r--drivers/acpi/namespace/nsaccess.c36
-rw-r--r--drivers/acpi/namespace/nsalloc.c14
-rw-r--r--drivers/acpi/namespace/nsdump.c13
-rw-r--r--drivers/acpi/namespace/nsdumpdv.c2
-rw-r--r--drivers/acpi/namespace/nseval.c13
-rw-r--r--drivers/acpi/namespace/nsinit.c9
-rw-r--r--drivers/acpi/namespace/nsload.c160
-rw-r--r--drivers/acpi/namespace/nsnames.c2
-rw-r--r--drivers/acpi/namespace/nsobject.c2
-rw-r--r--drivers/acpi/namespace/nsparse.c52
-rw-r--r--drivers/acpi/namespace/nssearch.c9
-rw-r--r--drivers/acpi/namespace/nsutils.c9
-rw-r--r--drivers/acpi/namespace/nswalk.c65
-rw-r--r--drivers/acpi/namespace/nsxfeval.c13
-rw-r--r--drivers/acpi/namespace/nsxfname.c47
-rw-r--r--drivers/acpi/namespace/nsxfobj.c46
-rw-r--r--drivers/acpi/numa.c79
-rw-r--r--drivers/acpi/osl.c54
-rw-r--r--drivers/acpi/parser/psargs.c2
-rw-r--r--drivers/acpi/parser/psloop.c1408
-rw-r--r--drivers/acpi/parser/psopcode.c2
-rw-r--r--drivers/acpi/parser/psparse.c7
-rw-r--r--drivers/acpi/parser/psscope.c2
-rw-r--r--drivers/acpi/parser/pstree.c2
-rw-r--r--drivers/acpi/parser/psutils.c2
-rw-r--r--drivers/acpi/parser/pswalk.c2
-rw-r--r--drivers/acpi/parser/psxface.c116
-rw-r--r--drivers/acpi/pci_bind.c16
-rw-r--r--drivers/acpi/pci_irq.c9
-rw-r--r--drivers/acpi/pci_link.c18
-rw-r--r--drivers/acpi/pci_root.c29
-rw-r--r--drivers/acpi/power.c9
-rw-r--r--drivers/acpi/processor_core.c201
-rw-r--r--drivers/acpi/processor_idle.c78
-rw-r--r--drivers/acpi/processor_perflib.c45
-rw-r--r--drivers/acpi/processor_thermal.c6
-rw-r--r--drivers/acpi/processor_throttling.c10
-rw-r--r--drivers/acpi/resources/rsaddr.c2
-rw-r--r--drivers/acpi/resources/rscalc.c2
-rw-r--r--drivers/acpi/resources/rscreate.c2
-rw-r--r--drivers/acpi/resources/rsdump.c2
-rw-r--r--drivers/acpi/resources/rsinfo.c2
-rw-r--r--drivers/acpi/resources/rsio.c2
-rw-r--r--drivers/acpi/resources/rsirq.c2
-rw-r--r--drivers/acpi/resources/rslist.c2
-rw-r--r--drivers/acpi/resources/rsmemory.c2
-rw-r--r--drivers/acpi/resources/rsmisc.c2
-rw-r--r--drivers/acpi/resources/rsutils.c2
-rw-r--r--drivers/acpi/resources/rsxface.c2
-rw-r--r--drivers/acpi/sbs.c27
-rw-r--r--drivers/acpi/scan.c7
-rw-r--r--drivers/acpi/sleep/proc.c36
-rw-r--r--drivers/acpi/sleep/wakeup.c6
-rw-r--r--drivers/acpi/system.c15
-rw-r--r--drivers/acpi/tables.c508
-rw-r--r--drivers/acpi/tables/Makefile3
-rw-r--r--drivers/acpi/tables/tbconvrt.c622
-rw-r--r--drivers/acpi/tables/tbfadt.c434
-rw-r--r--drivers/acpi/tables/tbfind.c126
-rw-r--r--drivers/acpi/tables/tbget.c471
-rw-r--r--drivers/acpi/tables/tbgetall.c311
-rw-r--r--drivers/acpi/tables/tbinstal.c664
-rw-r--r--drivers/acpi/tables/tbrsdt.c307
-rw-r--r--drivers/acpi/tables/tbutils.c513
-rw-r--r--drivers/acpi/tables/tbxface.c641
-rw-r--r--drivers/acpi/tables/tbxfroot.c552
-rw-r--r--drivers/acpi/thermal.c37
-rw-r--r--drivers/acpi/toshiba_acpi.c86
-rw-r--r--drivers/acpi/utilities/utalloc.c11
-rw-r--r--drivers/acpi/utilities/utcache.c10
-rw-r--r--drivers/acpi/utilities/utcopy.c11
-rw-r--r--drivers/acpi/utilities/utdebug.c8
-rw-r--r--drivers/acpi/utilities/utdelete.c16
-rw-r--r--drivers/acpi/utilities/uteval.c2
-rw-r--r--drivers/acpi/utilities/utglobal.c199
-rw-r--r--drivers/acpi/utilities/utinit.c114
-rw-r--r--drivers/acpi/utilities/utmath.c2
-rw-r--r--drivers/acpi/utilities/utmisc.c102
-rw-r--r--drivers/acpi/utilities/utmutex.c18
-rw-r--r--drivers/acpi/utilities/utobject.c2
-rw-r--r--drivers/acpi/utilities/utresrc.c2
-rw-r--r--drivers/acpi/utilities/utstate.c2
-rw-r--r--drivers/acpi/utilities/utxface.c29
-rw-r--r--drivers/acpi/utils.c10
-rw-r--r--drivers/acpi/video.c241
-rw-r--r--drivers/ata/Kconfig12
-rw-r--r--drivers/ata/ahci.c111
-rw-r--r--drivers/ata/ata_generic.c6
-rw-r--r--drivers/ata/ata_piix.c22
-rw-r--r--drivers/ata/libata-core.c31
-rw-r--r--drivers/ata/libata-eh.c6
-rw-r--r--drivers/ata/libata-scsi.c304
-rw-r--r--drivers/ata/libata-sff.c63
-rw-r--r--drivers/ata/pata_atiixp.c11
-rw-r--r--drivers/ata/pata_cmd64x.c23
-rw-r--r--drivers/ata/pata_cs5530.c3
-rw-r--r--drivers/ata/pata_hpt37x.c6
-rw-r--r--drivers/ata/pata_hpt3x2n.c6
-rw-r--r--drivers/ata/pata_it821x.c4
-rw-r--r--drivers/ata/pata_ixp4xx_cf.c5
-rw-r--r--drivers/ata/pata_jmicron.c18
-rw-r--r--drivers/ata/pata_legacy.c8
-rw-r--r--drivers/ata/pata_platform.c3
-rw-r--r--drivers/ata/pata_qdi.c4
-rw-r--r--drivers/ata/pata_rz1000.c8
-rw-r--r--drivers/ata/pata_sil680.c2
-rw-r--r--drivers/ata/pata_via.c15
-rw-r--r--drivers/ata/pata_winbond.c4
-rw-r--r--drivers/ata/sata_mv.c5
-rw-r--r--drivers/ata/sata_nv.c22
-rw-r--r--drivers/ata/sata_svw.c82
-rw-r--r--drivers/ata/sata_uli.c3
-rw-r--r--drivers/ata/sata_via.c13
-rw-r--r--drivers/ata/sata_vsc.c43
-rw-r--r--drivers/atm/Kconfig4
-rw-r--r--drivers/atm/fore200e.c166
-rw-r--r--drivers/atm/horizon.c2
-rw-r--r--drivers/base/firmware_class.c1
-rw-r--r--drivers/block/aoe/aoecmd.c13
-rw-r--r--drivers/block/cciss.c6
-rw-r--r--drivers/block/pktcdvd.c49
-rw-r--r--drivers/block/viodasd.c6
-rw-r--r--drivers/bluetooth/hci_usb.c8
-rw-r--r--drivers/cdrom/cdrom.c11
-rw-r--r--drivers/cdrom/viocd.c4
-rw-r--r--drivers/char/agp/agp.h4
-rw-r--r--drivers/char/agp/amd-k7-agp.c5
-rw-r--r--drivers/char/agp/amd64-agp.c9
-rw-r--r--drivers/char/agp/ati-agp.c36
-rw-r--r--drivers/char/agp/generic.c11
-rw-r--r--drivers/char/agp/intel-agp.c181
-rw-r--r--drivers/char/agp/sgi-agp.c9
-rw-r--r--drivers/char/agp/via-agp.c21
-rw-r--r--drivers/char/drm/drmP.h7
-rw-r--r--drivers/char/drm/drm_lock.c2
-rw-r--r--drivers/char/drm/drm_stub.c12
-rw-r--r--drivers/char/drm/drm_sysfs.c8
-rw-r--r--drivers/char/drm/i915_irq.c201
-rw-r--r--drivers/char/drm/r128_drm.h3
-rw-r--r--drivers/char/drm/r128_drv.h3
-rw-r--r--drivers/char/drm/r128_state.c3
-rw-r--r--drivers/char/drm/r300_cmdbuf.c32
-rw-r--r--drivers/char/drm/radeon_drv.h15
-rw-r--r--drivers/char/drm/radeon_irq.c4
-rw-r--r--drivers/char/drm/radeon_mem.c4
-rw-r--r--drivers/char/drm/radeon_state.c13
-rw-r--r--drivers/char/drm/savage_bci.c4
-rw-r--r--drivers/char/hw_random/amd-rng.c2
-rw-r--r--drivers/char/hw_random/geode-rng.c2
-rw-r--r--drivers/char/hw_random/intel-rng.c34
-rw-r--r--drivers/char/hw_random/ixp4xx-rng.c2
-rw-r--r--drivers/char/hw_random/via-rng.c2
-rw-r--r--drivers/char/ip2/i2ellis.h4
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c3
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c18
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c11
-rw-r--r--drivers/char/isicom.c103
-rw-r--r--drivers/char/mem.c4
-rw-r--r--drivers/char/mxser.c1
-rw-r--r--drivers/char/mxser_new.c1
-rw-r--r--drivers/char/rtc.c7
-rw-r--r--drivers/char/sysrq.c20
-rw-r--r--drivers/char/tlclk.c45
-rw-r--r--drivers/char/tpm/tpm_bios.c8
-rw-r--r--drivers/char/viocons.c7
-rw-r--r--drivers/char/viotape.c5
-rw-r--r--drivers/char/vr41xx_giu.c114
-rw-r--r--drivers/connector/cn_proc.c11
-rw-r--r--drivers/connector/cn_queue.c5
-rw-r--r--drivers/connector/connector.c17
-rw-r--r--drivers/cpufreq/cpufreq.c19
-rw-r--r--drivers/cpufreq/cpufreq_stats.c4
-rw-r--r--drivers/firmware/efivars.c29
-rw-r--r--drivers/firmware/pcdp.c2
-rw-r--r--drivers/hid/Kconfig18
-rw-r--r--drivers/hid/hid-core.c19
-rw-r--r--drivers/hid/hid-input.c86
-rw-r--r--drivers/hwmon/hwmon-vid.c2
-rw-r--r--drivers/hwmon/w83793.c127
-rw-r--r--drivers/i2c/busses/Kconfig9
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c4
-rw-r--r--drivers/i2c/busses/i2c-pnx.c7
-rw-r--r--drivers/i2c/chips/m41t00.c1
-rw-r--r--drivers/i2c/i2c-core.c28
-rw-r--r--drivers/ide/ide-pnp.c5
-rw-r--r--drivers/ide/ide.c11
-rw-r--r--drivers/ide/pci/aec62xx.c2
-rw-r--r--drivers/ide/pci/alim15x3.c2
-rw-r--r--drivers/ide/pci/amd74xx.c2
-rw-r--r--drivers/ide/pci/atiixp.c61
-rw-r--r--drivers/ide/pci/cmd64x.c2
-rw-r--r--drivers/ide/pci/cs5520.c2
-rw-r--r--drivers/ide/pci/cs5530.c2
-rw-r--r--drivers/ide/pci/cy82c693.c2
-rw-r--r--drivers/ide/pci/generic.c37
-rw-r--r--drivers/ide/pci/hpt34x.c2
-rw-r--r--drivers/ide/pci/hpt366.c2
-rw-r--r--drivers/ide/pci/jmicron.c17
-rw-r--r--drivers/ide/pci/ns87415.c2
-rw-r--r--drivers/ide/pci/opti621.c2
-rw-r--r--drivers/ide/pci/pdc202xx_new.c2
-rw-r--r--drivers/ide/pci/pdc202xx_old.c2
-rw-r--r--drivers/ide/pci/piix.c66
-rw-r--r--drivers/ide/pci/rz1000.c2
-rw-r--r--drivers/ide/pci/sc1200.c2
-rw-r--r--drivers/ide/pci/serverworks.c2
-rw-r--r--drivers/ide/pci/sgiioc4.c3
-rw-r--r--drivers/ide/pci/siimage.c2
-rw-r--r--drivers/ide/pci/sis5513.c2
-rw-r--r--drivers/ide/pci/sl82c105.c2
-rw-r--r--drivers/ide/pci/slc90e66.c22
-rw-r--r--drivers/ide/pci/triflex.c2
-rw-r--r--drivers/ide/pci/trm290.c2
-rw-r--r--drivers/ide/pci/via82cxxx.c143
-rw-r--r--drivers/ieee1394/sbp2.c85
-rw-r--r--drivers/infiniband/core/cma.c17
-rw-r--r--drivers/infiniband/core/ucma.c11
-rw-r--r--drivers/infiniband/hw/ehca/ehca_cq.c5
-rw-r--r--drivers/infiniband/hw/ehca/ehca_hca.c8
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.c5
-rw-r--r--drivers/infiniband/hw/ehca/ehca_iverbs.h4
-rw-r--r--drivers/infiniband/hw/ehca/ehca_main.c10
-rw-r--r--drivers/infiniband/hw/ehca/ehca_mrmw.c4
-rw-r--r--drivers/infiniband/hw/ehca/ehca_qp.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cq.c8
-rw-r--r--drivers/infiniband/hw/mthca/mthca_main.c113
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c3
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c26
-rw-r--r--drivers/infiniband/ulp/iser/iscsi_iser.c4
-rw-r--r--drivers/infiniband/ulp/iser/iser_initiator.c26
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c22
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.h2
-rw-r--r--drivers/input/keyboard/amikbd.c2
-rw-r--r--drivers/input/keyboard/sunkbd.c2
-rw-r--r--drivers/input/serio/i8042-sparcio.h6
-rw-r--r--drivers/isdn/gigaset/common.c61
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c1
-rw-r--r--drivers/kvm/kvm.h125
-rw-r--r--drivers/kvm/kvm_main.c321
-rw-r--r--drivers/kvm/mmu.c1152
-rw-r--r--drivers/kvm/paging_tmpl.h313
-rw-r--r--drivers/kvm/svm.c214
-rw-r--r--drivers/kvm/vmx.c261
-rw-r--r--drivers/kvm/vmx.h10
-rw-r--r--drivers/kvm/x86_emulate.c100
-rw-r--r--drivers/leds/leds-s3c24xx.c2
-rw-r--r--drivers/macintosh/via-pmu-backlight.c2
-rw-r--r--drivers/macintosh/via-pmu.c1
-rw-r--r--drivers/md/bitmap.c12
-rw-r--r--drivers/md/dm.c27
-rw-r--r--drivers/md/md.c45
-rw-r--r--drivers/md/raid1.c20
-rw-r--r--drivers/md/raid10.c11
-rw-r--r--drivers/md/raid5.c5
-rw-r--r--drivers/media/common/ir-functions.c1
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c4
-rw-r--r--drivers/media/dvb/dvb-usb/nova-t-usb2.c4
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c2
-rw-r--r--drivers/media/video/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c4
-rw-r--r--drivers/media/video/cafe_ccic.c2
-rw-r--r--drivers/media/video/cpia2/cpia2_usb.c4
-rw-r--r--drivers/media/video/cx2341x.c21
-rw-r--r--drivers/media/video/cx25840/cx25840-vbi.c9
-rw-r--r--drivers/media/video/cx88/cx88-cards.c2
-rw-r--r--drivers/media/video/cx88/cx88-core.c35
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c2
-rw-r--r--drivers/media/video/cx88/cx88.h2
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c4
-rw-r--r--drivers/media/video/ks0127.c8
-rw-r--r--drivers/media/video/meye.c4
-rw-r--r--drivers/media/video/msp3400-driver.c8
-rw-r--r--drivers/media/video/msp3400-kthreads.c11
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c14
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c8
-rw-r--r--drivers/media/video/tuner-core.c4
-rw-r--r--drivers/media/video/tveeprom.c2
-rw-r--r--drivers/media/video/usbvideo/quickcam_messenger.h14
-rw-r--r--drivers/media/video/usbvision/usbvision-cards.c11
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c83
-rw-r--r--drivers/media/video/usbvision/usbvision-i2c.c35
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c153
-rw-r--r--drivers/media/video/usbvision/usbvision.h27
-rw-r--r--drivers/media/video/v4l2-common.c9
-rw-r--r--drivers/media/video/video-buf.c3
-rw-r--r--drivers/media/video/vivi.c15
-rw-r--r--drivers/media/video/w9966.c2
-rw-r--r--drivers/media/video/w9968cf.c24
-rw-r--r--drivers/media/video/zoran_device.c3
-rw-r--r--drivers/message/fusion/mptbase.c3
-rw-r--r--drivers/message/fusion/mptbase.h10
-rw-r--r--drivers/message/fusion/mptctl.c5
-rw-r--r--drivers/message/fusion/mptctl.h2
-rw-r--r--drivers/message/fusion/mptfc.c3
-rw-r--r--drivers/message/fusion/mptlan.c4
-rw-r--r--drivers/message/fusion/mptlan.h2
-rw-r--r--drivers/message/fusion/mptsas.c38
-rw-r--r--drivers/message/fusion/mptscsih.c19
-rw-r--r--drivers/message/fusion/mptscsih.h2
-rw-r--r--drivers/message/fusion/mptspi.c3
-rw-r--r--drivers/message/i2o/exec-osm.c2
-rw-r--r--drivers/misc/msi-laptop.c3
-rw-r--r--drivers/mmc/at91_mci.c11
-rw-r--r--drivers/mmc/imxmmc.c3
-rw-r--r--drivers/mmc/mmci.c4
-rw-r--r--drivers/mmc/omap.c21
-rw-r--r--drivers/mmc/pxamci.c2
-rw-r--r--drivers/mmc/tifm_sd.c3
-rw-r--r--drivers/mtd/Kconfig15
-rw-r--r--drivers/mtd/Makefile15
-rw-r--r--drivers/mtd/afs.c3
-rw-r--r--drivers/mtd/chips/amd_flash.c3
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c5
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c11
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c3
-rw-r--r--drivers/mtd/chips/gen_probe.c5
-rw-r--r--drivers/mtd/chips/jedec.c3
-rw-r--r--drivers/mtd/chips/jedec_probe.c17
-rw-r--r--drivers/mtd/chips/map_absent.c4
-rw-r--r--drivers/mtd/chips/map_ram.c4
-rw-r--r--drivers/mtd/chips/map_rom.c4
-rw-r--r--drivers/mtd/chips/sharp.c7
-rw-r--r--drivers/mtd/cmdlinepart.c5
-rw-r--r--drivers/mtd/devices/block2mtd.c3
-rw-r--r--drivers/mtd/devices/m25p80.c4
-rw-r--r--drivers/mtd/devices/ms02-nv.c18
-rw-r--r--drivers/mtd/devices/mtd_dataflash.c4
-rw-r--r--drivers/mtd/devices/phram.c4
-rw-r--r--drivers/mtd/devices/slram.c7
-rw-r--r--drivers/mtd/ftl.c7
-rw-r--r--drivers/mtd/inftlcore.c12
-rw-r--r--drivers/mtd/maps/Kconfig71
-rw-r--r--drivers/mtd/maps/Makefile4
-rw-r--r--drivers/mtd/maps/amd76xrom.c34
-rw-r--r--drivers/mtd/maps/bast-flash.c2
-rw-r--r--drivers/mtd/maps/ceiva.c3
-rw-r--r--drivers/mtd/maps/ck804xrom.c356
-rw-r--r--drivers/mtd/maps/cstm_mips_ixx.c283
-rw-r--r--drivers/mtd/maps/esb2rom.c450
-rw-r--r--drivers/mtd/maps/integrator-flash.c4
-rw-r--r--drivers/mtd/maps/nettel.c5
-rw-r--r--drivers/mtd/maps/omap_nor.c4
-rw-r--r--drivers/mtd/maps/pcmciamtd.c3
-rw-r--r--drivers/mtd/maps/physmap.c5
-rw-r--r--drivers/mtd/maps/physmap_of.c255
-rw-r--r--drivers/mtd/maps/plat-ram.c3
-rw-r--r--drivers/mtd/maps/sa1100-flash.c4
-rw-r--r--drivers/mtd/maps/tqm834x.c8
-rw-r--r--drivers/mtd/maps/tqm8xxl.c3
-rw-r--r--drivers/mtd/mtd_blkdevs.c19
-rw-r--r--drivers/mtd/mtdblock.c10
-rw-r--r--drivers/mtd/mtdblock_ro.c7
-rw-r--r--drivers/mtd/mtdchar.c23
-rw-r--r--drivers/mtd/mtdconcat.c43
-rw-r--r--drivers/mtd/mtdcore.c93
-rw-r--r--drivers/mtd/mtdpart.c8
-rw-r--r--drivers/mtd/nand/Kconfig16
-rw-r--r--drivers/mtd/nand/Makefile5
-rw-r--r--drivers/mtd/nand/at91_nand.c223
-rw-r--r--drivers/mtd/nand/cafe.c771
-rw-r--r--drivers/mtd/nand/cafe_ecc.c1381
-rw-r--r--drivers/mtd/nand/cs553x_nand.c4
-rw-r--r--drivers/mtd/nand/diskonchip.c3
-rw-r--r--drivers/mtd/nand/nand_base.c133
-rw-r--r--drivers/mtd/nand/nand_bbt.c11
-rw-r--r--drivers/mtd/nand/nand_ecc.c4
-rw-r--r--drivers/mtd/nand/nandsim.c243
-rw-r--r--drivers/mtd/nand/ndfc.c2
-rw-r--r--drivers/mtd/nand/rtc_from4.c46
-rw-r--r--drivers/mtd/nand/s3c2410.c2
-rw-r--r--drivers/mtd/nftlcore.c12
-rw-r--r--drivers/mtd/onenand/generic.c5
-rw-r--r--drivers/mtd/onenand/onenand_base.c374
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c14
-rw-r--r--drivers/mtd/redboot.c30
-rw-r--r--drivers/mtd/rfd_ftl.c3
-rw-r--r--drivers/mtd/ssfdc.c7
-rw-r--r--drivers/net/8139cp.c13
-rw-r--r--drivers/net/82596.c7
-rw-r--r--drivers/net/Space.c11
-rw-r--r--drivers/net/arm/ep93xx_eth.c4
-rw-r--r--drivers/net/b44.c58
-rw-r--r--drivers/net/bnx2.c110
-rw-r--r--drivers/net/bnx2.h6
-rw-r--r--drivers/net/bonding/bonding.h7
-rw-r--r--drivers/net/chelsio/my3126.c5
-rw-r--r--drivers/net/e100.c7
-rw-r--r--drivers/net/e1000/e1000_ethtool.c3
-rw-r--r--drivers/net/e1000/e1000_hw.c296
-rw-r--r--drivers/net/e1000/e1000_hw.h310
-rw-r--r--drivers/net/e1000/e1000_main.c339
-rw-r--r--drivers/net/e1000/e1000_param.c4
-rw-r--r--drivers/net/ehea/ehea.h2
-rw-r--r--drivers/net/ehea/ehea_main.c87
-rw-r--r--drivers/net/ehea/ehea_phyp.c10
-rw-r--r--drivers/net/forcedeth.c127
-rw-r--r--drivers/net/fs_enet/mac-fec.c13
-rw-r--r--drivers/net/fs_enet/mac-scc.c6
-rw-r--r--drivers/net/hamradio/Kconfig6
-rw-r--r--drivers/net/ibm_emac/ibm_emac_phy.c4
-rw-r--r--drivers/net/ifb.c4
-rw-r--r--drivers/net/irda/irda-usb.c45
-rw-r--r--drivers/net/irda/irda-usb.h1
-rw-r--r--drivers/net/irda/stir4200.c2
-rw-r--r--drivers/net/irda/vlsi_ir.c16
-rw-r--r--drivers/net/irda/vlsi_ir.h33
-rw-r--r--drivers/net/iseries_veth.c9
-rw-r--r--drivers/net/ixgb/ixgb.h1
-rw-r--r--drivers/net/ixgb/ixgb_ethtool.c1
-rw-r--r--drivers/net/ixgb/ixgb_hw.c3
-rw-r--r--drivers/net/ixgb/ixgb_main.c57
-rw-r--r--drivers/net/loopback.c4
-rw-r--r--drivers/net/mv643xx_eth.c11
-rw-r--r--drivers/net/myri10ge/myri10ge.c180
-rw-r--r--drivers/net/netxen/netxen_nic.h166
-rw-r--r--drivers/net/netxen/netxen_nic_ethtool.c27
-rw-r--r--drivers/net/netxen/netxen_nic_hw.c342
-rw-r--r--drivers/net/netxen/netxen_nic_hw.h74
-rw-r--r--drivers/net/netxen/netxen_nic_init.c260
-rw-r--r--drivers/net/netxen/netxen_nic_ioctl.h77
-rw-r--r--drivers/net/netxen/netxen_nic_isr.c7
-rw-r--r--drivers/net/netxen/netxen_nic_main.c91
-rw-r--r--drivers/net/netxen/netxen_nic_niu.c106
-rw-r--r--drivers/net/pcmcia/3c574_cs.c1
-rw-r--r--drivers/net/pcmcia/3c589_cs.c8
-rw-r--r--drivers/net/pcmcia/com20020_cs.c1
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c2
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c1
-rw-r--r--drivers/net/phy/fixed.c2
-rw-r--r--drivers/net/phy/phy.c3
-rw-r--r--drivers/net/qla3xxx.c38
-rw-r--r--drivers/net/r8169.c6
-rw-r--r--drivers/net/s2io.c3
-rw-r--r--drivers/net/sis190.c2
-rw-r--r--drivers/net/skge.c7
-rw-r--r--drivers/net/sky2.c12
-rw-r--r--drivers/net/smc911x.c23
-rw-r--r--drivers/net/spider_net.c2
-rw-r--r--drivers/net/sungem.c3
-rw-r--r--drivers/net/sungem_phy.c179
-rw-r--r--drivers/net/sungem_phy.h7
-rw-r--r--drivers/net/tg3.c55
-rw-r--r--drivers/net/tg3.h5
-rw-r--r--drivers/net/ucc_geth.c12
-rw-r--r--drivers/net/ucc_geth_phy.c134
-rw-r--r--drivers/net/via-velocity.c18
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.c11
-rw-r--r--drivers/net/wireless/ipw2100.c2
-rw-r--r--drivers/net/wireless/netwave_cs.c1
-rw-r--r--drivers/net/wireless/ray_cs.c1
-rw-r--r--drivers/net/wireless/wl3501_cs.c1
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c96
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.h5
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c4
-rw-r--r--drivers/pci/Kconfig2
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c12
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c3
-rw-r--r--drivers/pci/hotplug/rpaphp_slot.c47
-rw-r--r--drivers/pci/hotplug/sgi_hotplug.c155
-rw-r--r--drivers/pci/hotplug/shpchp.h238
-rw-r--r--drivers/pci/hotplug/shpchp_core.c116
-rw-r--r--drivers/pci/hotplug/shpchp_ctrl.c21
-rw-r--r--drivers/pci/hotplug/shpchp_hpc.c223
-rw-r--r--drivers/pci/htirq.c9
-rw-r--r--drivers/pci/pci-driver.c15
-rw-r--r--drivers/pci/pci.c113
-rw-r--r--drivers/pci/pcie/portdrv_pci.c2
-rw-r--r--drivers/pci/probe.c10
-rw-r--r--drivers/pci/quirks.c254
-rw-r--r--drivers/pci/search.c56
-rw-r--r--drivers/pci/setup-bus.c2
-rw-r--r--drivers/pci/setup-res.c19
-rw-r--r--drivers/rtc/rtc-at91rm9200.c2
-rw-r--r--drivers/rtc/rtc-rs5c372.c535
-rw-r--r--drivers/rtc/rtc-sh.c16
-rw-r--r--drivers/rtc/rtc-sysfs.c2
-rw-r--r--drivers/s390/char/monwriter.c2
-rw-r--r--drivers/s390/char/sclp_cpi.c2
-rw-r--r--drivers/s390/char/vmcp.c2
-rw-r--r--drivers/s390/cio/cio.c32
-rw-r--r--drivers/s390/cio/css.c3
-rw-r--r--drivers/s390/cio/qdio.c13
-rw-r--r--drivers/s390/crypto/ap_bus.c14
-rw-r--r--drivers/s390/net/Kconfig5
-rw-r--r--drivers/s390/net/qeth.h2
-rw-r--r--drivers/s390/net/qeth_main.c217
-rw-r--r--drivers/scsi/3w-xxxx.c60
-rw-r--r--drivers/scsi/3w-xxxx.h2
-rw-r--r--drivers/scsi/Kconfig2
-rw-r--r--drivers/scsi/aacraid/linit.c20
-rw-r--r--drivers/scsi/advansys.c3
-rw-r--r--drivers/scsi/ibmvscsi/Makefile2
-rw-r--r--drivers/scsi/iscsi_tcp.c12
-rw-r--r--drivers/scsi/libiscsi.c6
-rw-r--r--drivers/scsi/lpfc/lpfc_mem.c6
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c6
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.c1
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c3
-rw-r--r--drivers/scsi/qla1280.c6
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h2
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h1
-rw-r--r--drivers/scsi/qla2xxx/qla_gs.c24
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c76
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c15
-rw-r--r--drivers/scsi/qla2xxx/qla_mbx.c12
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c59
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h2
-rw-r--r--drivers/scsi/scsi_lib.c4
-rw-r--r--drivers/scsi/scsi_scan.c33
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c2
-rw-r--r--drivers/scsi/scsi_transport_spi.c2
-rw-r--r--drivers/scsi/seagate.c5
-rw-r--r--drivers/scsi/sr.c2
-rw-r--r--drivers/scsi/sun3_NCR5380.c6
-rw-r--r--drivers/serial/8250.c2
-rw-r--r--drivers/serial/amba-pl010.c2
-rw-r--r--drivers/serial/amba-pl011.c2
-rw-r--r--drivers/serial/atmel_serial.c7
-rw-r--r--drivers/serial/atmel_serial.h2
-rw-r--r--drivers/serial/mpc52xx_uart.c2
-rw-r--r--drivers/serial/sunsab.c11
-rw-r--r--drivers/serial/sunsu.c10
-rw-r--r--drivers/serial/sunzilog.c14
-rw-r--r--drivers/serial/uartlite.c4
-rw-r--r--drivers/spi/pxa2xx_spi.c5
-rw-r--r--drivers/spi/spi.c23
-rw-r--r--drivers/spi/spi_mpc83xx.c2
-rw-r--r--drivers/spi/spi_s3c24xx.c30
-rw-r--r--drivers/spi/spi_s3c24xx_gpio.c3
-rw-r--r--drivers/usb/class/usblp.c55
-rw-r--r--drivers/usb/core/Kconfig16
-rw-r--r--drivers/usb/core/devio.c6
-rw-r--r--drivers/usb/core/endpoint.c2
-rw-r--r--drivers/usb/core/hub.c9
-rw-r--r--drivers/usb/gadget/at91_udc.c236
-rw-r--r--drivers/usb/gadget/at91_udc.h7
-rw-r--r--drivers/usb/gadget/dummy_hcd.c7
-rw-r--r--drivers/usb/gadget/file_storage.c2
-rw-r--r--drivers/usb/gadget/gmidi.c12
-rw-r--r--drivers/usb/gadget/goku_udc.c12
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c13
-rw-r--r--drivers/usb/gadget/net2280.c11
-rw-r--r--drivers/usb/gadget/omap_udc.c258
-rw-r--r--drivers/usb/gadget/omap_udc.h3
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c7
-rw-r--r--drivers/usb/gadget/serial.c2
-rw-r--r--drivers/usb/host/ohci-at91.c3
-rw-r--r--drivers/usb/host/ohci-au1xxx.c4
-rw-r--r--drivers/usb/host/ohci-dbg.c8
-rw-r--r--drivers/usb/host/ohci-ep93xx.c4
-rw-r--r--drivers/usb/host/ohci-hcd.c110
-rw-r--r--drivers/usb/host/ohci-hub.c21
-rw-r--r--drivers/usb/host/ohci-lh7a404.c8
-rw-r--r--drivers/usb/host/ohci-mem.c10
-rw-r--r--drivers/usb/host/ohci-omap.c4
-rw-r--r--drivers/usb/host/ohci-pci.c16
-rw-r--r--drivers/usb/host/ohci-pnx4008.c4
-rw-r--r--drivers/usb/host/ohci-pnx8550.c258
-rw-r--r--drivers/usb/host/ohci-ppc-soc.c8
-rw-r--r--drivers/usb/host/ohci-pxa27x.c10
-rw-r--r--drivers/usb/host/ohci-q.c103
-rw-r--r--drivers/usb/host/ohci-s3c2410.c4
-rw-r--r--drivers/usb/host/ohci-sa1111.c8
-rw-r--r--drivers/usb/host/ohci.h92
-rw-r--r--drivers/usb/host/u132-hcd.c92
-rw-r--r--drivers/usb/host/uhci-hcd.c33
-rw-r--r--drivers/usb/host/uhci-hub.c14
-rw-r--r--drivers/usb/input/Kconfig11
-rw-r--r--drivers/usb/input/hid-core.c50
-rw-r--r--drivers/usb/input/hid-ff.c5
-rw-r--r--drivers/usb/input/hiddev.c2
-rw-r--r--drivers/usb/input/usbhid.h3
-rw-r--r--drivers/usb/input/usbtouchscreen.c98
-rw-r--r--drivers/usb/input/wacom_sys.c4
-rw-r--r--drivers/usb/input/wacom_wac.c26
-rw-r--r--drivers/usb/misc/appledisplay.c2
-rw-r--r--drivers/usb/misc/auerswald.c6
-rw-r--r--drivers/usb/misc/ftdi-elan.c592
-rw-r--r--drivers/usb/misc/phidgetservo.c1
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb_con.c12
-rw-r--r--drivers/usb/misc/trancevibrator.c2
-rw-r--r--drivers/usb/net/asix.c18
-rw-r--r--drivers/usb/net/gl620a.c154
-rw-r--r--drivers/usb/net/rndis_host.c23
-rw-r--r--drivers/usb/net/rtl8150.c6
-rw-r--r--drivers/usb/serial/airprime.c3
-rw-r--r--drivers/usb/serial/cp2101.c1
-rw-r--r--drivers/usb/serial/cypress_m8.c15
-rw-r--r--drivers/usb/serial/ftdi_sio.c1
-rw-r--r--drivers/usb/serial/ftdi_sio.h5
-rw-r--r--drivers/usb/serial/funsoft.c27
-rw-r--r--drivers/usb/serial/kl5kusb105.c68
-rw-r--r--drivers/usb/serial/mos7840.c6
-rw-r--r--drivers/usb/serial/option.c9
-rw-r--r--drivers/usb/storage/unusual_devs.h52
-rw-r--r--drivers/video/aty/aty128fb.c2
-rw-r--r--drivers/video/aty/atyfb_base.c2
-rw-r--r--drivers/video/aty/radeon_backlight.c2
-rw-r--r--drivers/video/backlight/backlight.c7
-rw-r--r--drivers/video/backlight/corgi_bl.c2
-rw-r--r--drivers/video/backlight/hp680_bl.c2
-rw-r--r--drivers/video/backlight/locomolcd.c2
-rw-r--r--drivers/video/bw2.c18
-rw-r--r--drivers/video/cg14.c28
-rw-r--r--drivers/video/cg3.c22
-rw-r--r--drivers/video/cg6.c33
-rw-r--r--drivers/video/ffb.c25
-rw-r--r--drivers/video/gxt4500.c95
-rw-r--r--drivers/video/leo.c29
-rw-r--r--drivers/video/nvidia/nv_backlight.c2
-rw-r--r--drivers/video/p9100.c25
-rw-r--r--drivers/video/pxafb.c40
-rw-r--r--drivers/video/riva/fbdev.c2
-rw-r--r--drivers/video/sa1100fb.c6
-rw-r--r--drivers/video/tcx.c33
684 files changed, 20272 insertions, 14010 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index df4514436b..5c087a5bdd 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -11,7 +11,7 @@ config ACPI
11 bool "ACPI Support" 11 bool "ACPI Support"
12 depends on IA64 || X86 12 depends on IA64 || X86
13 depends on PCI 13 depends on PCI
14 select PM 14 depends on PM
15 default y 15 default y
16 ---help--- 16 ---help---
17 Advanced Configuration and Power Interface (ACPI) support for 17 Advanced Configuration and Power Interface (ACPI) support for
@@ -111,6 +111,7 @@ config ACPI_BATTERY
111 111
112config ACPI_BUTTON 112config ACPI_BUTTON
113 tristate "Button" 113 tristate "Button"
114 depends on INPUT
114 default y 115 default y
115 help 116 help
116 This driver handles events on the power, sleep and lid buttons. 117 This driver handles events on the power, sleep and lid buttons.
@@ -120,7 +121,7 @@ config ACPI_BUTTON
120 121
121config ACPI_VIDEO 122config ACPI_VIDEO
122 tristate "Video" 123 tristate "Video"
123 depends on X86 124 depends on X86 && BACKLIGHT_CLASS_DEVICE
124 help 125 help
125 This driver implement the ACPI Extensions For Display Adapters 126 This driver implement the ACPI Extensions For Display Adapters
126 for integrated graphics devices on motherboard, as specified in 127 for integrated graphics devices on motherboard, as specified in
@@ -152,6 +153,13 @@ config ACPI_DOCK
152 help 153 help
153 This driver adds support for ACPI controlled docking stations 154 This driver adds support for ACPI controlled docking stations
154 155
156config ACPI_BAY
157 tristate "Removable Drive Bay (EXPERIMENTAL)"
158 depends on EXPERIMENTAL
159 help
160 This driver adds support for ACPI controlled removable drive
161 bays such as the IBM ultrabay or the Dell Module Bay.
162
155config ACPI_PROCESSOR 163config ACPI_PROCESSOR
156 tristate "Processor" 164 tristate "Processor"
157 default y 165 default y
@@ -186,6 +194,7 @@ config ACPI_NUMA
186config ACPI_ASUS 194config ACPI_ASUS
187 tristate "ASUS/Medion Laptop Extras" 195 tristate "ASUS/Medion Laptop Extras"
188 depends on X86 196 depends on X86
197 select BACKLIGHT_CLASS_DEVICE
189 ---help--- 198 ---help---
190 This driver provides support for extra features of ACPI-compatible 199 This driver provides support for extra features of ACPI-compatible
191 ASUS laptops. As some of Medion laptops are made by ASUS, it may also 200 ASUS laptops. As some of Medion laptops are made by ASUS, it may also
@@ -214,6 +223,7 @@ config ACPI_ASUS
214config ACPI_IBM 223config ACPI_IBM
215 tristate "IBM ThinkPad Laptop Extras" 224 tristate "IBM ThinkPad Laptop Extras"
216 depends on X86 225 depends on X86
226 select BACKLIGHT_CLASS_DEVICE
217 ---help--- 227 ---help---
218 This is a Linux ACPI driver for the IBM ThinkPad laptops. It adds 228 This is a Linux ACPI driver for the IBM ThinkPad laptops. It adds
219 support for Fn-Fx key combinations, Bluetooth control, video 229 support for Fn-Fx key combinations, Bluetooth control, video
@@ -239,6 +249,7 @@ config ACPI_IBM_DOCK
239config ACPI_TOSHIBA 249config ACPI_TOSHIBA
240 tristate "Toshiba Laptop Extras" 250 tristate "Toshiba Laptop Extras"
241 depends on X86 251 depends on X86
252 select BACKLIGHT_CLASS_DEVICE
242 ---help--- 253 ---help---
243 This driver adds support for access to certain system settings 254 This driver adds support for access to certain system settings
244 on "legacy free" Toshiba laptops. These laptops can be recognized by 255 on "legacy free" Toshiba laptops. These laptops can be recognized by
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index a749510705..399b0e8c41 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -44,7 +44,8 @@ obj-$(CONFIG_ACPI_BUTTON) += button.o
44obj-$(CONFIG_ACPI_EC) += ec.o 44obj-$(CONFIG_ACPI_EC) += ec.o
45obj-$(CONFIG_ACPI_FAN) += fan.o 45obj-$(CONFIG_ACPI_FAN) += fan.o
46obj-$(CONFIG_ACPI_DOCK) += dock.o 46obj-$(CONFIG_ACPI_DOCK) += dock.o
47obj-$(CONFIG_ACPI_VIDEO) += video.o 47obj-$(CONFIG_ACPI_BAY) += bay.o
48obj-$(CONFIG_ACPI_VIDEO) += video.o
48obj-$(CONFIG_ACPI_HOTKEY) += hotkey.o 49obj-$(CONFIG_ACPI_HOTKEY) += hotkey.o
49obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o 50obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o
50obj-$(CONFIG_ACPI_POWER) += power.o 51obj-$(CONFIG_ACPI_POWER) += power.o
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 11abc7bf77..6daeace796 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -109,7 +109,7 @@ static struct proc_dir_entry *acpi_ac_dir;
109 109
110static int acpi_ac_seq_show(struct seq_file *seq, void *offset) 110static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
111{ 111{
112 struct acpi_ac *ac = (struct acpi_ac *)seq->private; 112 struct acpi_ac *ac = seq->private;
113 113
114 114
115 if (!ac) 115 if (!ac)
@@ -187,7 +187,7 @@ static int acpi_ac_remove_fs(struct acpi_device *device)
187 187
188static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) 188static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
189{ 189{
190 struct acpi_ac *ac = (struct acpi_ac *)data; 190 struct acpi_ac *ac = data;
191 struct acpi_device *device = NULL; 191 struct acpi_device *device = NULL;
192 192
193 193
@@ -221,10 +221,9 @@ static int acpi_ac_add(struct acpi_device *device)
221 if (!device) 221 if (!device)
222 return -EINVAL; 222 return -EINVAL;
223 223
224 ac = kmalloc(sizeof(struct acpi_ac), GFP_KERNEL); 224 ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
225 if (!ac) 225 if (!ac)
226 return -ENOMEM; 226 return -ENOMEM;
227 memset(ac, 0, sizeof(struct acpi_ac));
228 227
229 ac->device = device; 228 ac->device = device;
230 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); 229 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
@@ -269,7 +268,7 @@ static int acpi_ac_remove(struct acpi_device *device, int type)
269 if (!device || !acpi_driver_data(device)) 268 if (!device || !acpi_driver_data(device))
270 return -EINVAL; 269 return -EINVAL;
271 270
272 ac = (struct acpi_ac *)acpi_driver_data(device); 271 ac = acpi_driver_data(device);
273 272
274 status = acpi_remove_notify_handler(device->handle, 273 status = acpi_remove_notify_handler(device->handle,
275 ACPI_ALL_NOTIFY, acpi_ac_notify); 274 ACPI_ALL_NOTIFY, acpi_ac_notify);
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index 6bcd9e8e7b..cd946ed192 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -395,10 +395,9 @@ static int acpi_memory_device_add(struct acpi_device *device)
395 if (!device) 395 if (!device)
396 return -EINVAL; 396 return -EINVAL;
397 397
398 mem_device = kmalloc(sizeof(struct acpi_memory_device), GFP_KERNEL); 398 mem_device = kzalloc(sizeof(struct acpi_memory_device), GFP_KERNEL);
399 if (!mem_device) 399 if (!mem_device)
400 return -ENOMEM; 400 return -ENOMEM;
401 memset(mem_device, 0, sizeof(struct acpi_memory_device));
402 401
403 INIT_LIST_HEAD(&mem_device->res_list); 402 INIT_LIST_HEAD(&mem_device->res_list);
404 mem_device->device = device; 403 mem_device->device = device;
@@ -429,7 +428,7 @@ static int acpi_memory_device_remove(struct acpi_device *device, int type)
429 if (!device || !acpi_driver_data(device)) 428 if (!device || !acpi_driver_data(device))
430 return -EINVAL; 429 return -EINVAL;
431 430
432 mem_device = (struct acpi_memory_device *)acpi_driver_data(device); 431 mem_device = acpi_driver_data(device);
433 kfree(mem_device); 432 kfree(mem_device);
434 433
435 return 0; 434 return 0;
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index c7ac9297a2..31ad70a6e2 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -26,7 +26,7 @@
26 * Pontus Fuchs - Helper functions, cleanup 26 * Pontus Fuchs - Helper functions, cleanup
27 * Johann Wiesner - Small compile fixes 27 * Johann Wiesner - Small compile fixes
28 * John Belmonte - ACPI code for Toshiba laptop was a good starting point. 28 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
29 * Éric Burghard - LED display support for W1N 29 * �ic Burghard - LED display support for W1N
30 * 30 *
31 */ 31 */
32 32
@@ -35,6 +35,7 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/types.h> 36#include <linux/types.h>
37#include <linux/proc_fs.h> 37#include <linux/proc_fs.h>
38#include <linux/backlight.h>
38#include <acpi/acpi_drivers.h> 39#include <acpi/acpi_drivers.h>
39#include <acpi/acpi_bus.h> 40#include <acpi/acpi_bus.h>
40#include <asm/uaccess.h> 41#include <asm/uaccess.h>
@@ -402,6 +403,8 @@ static struct model_data model_conf[END_MODEL] = {
402/* procdir we use */ 403/* procdir we use */
403static struct proc_dir_entry *asus_proc_dir; 404static struct proc_dir_entry *asus_proc_dir;
404 405
406static struct backlight_device *asus_backlight_device;
407
405/* 408/*
406 * This header is made available to allow proper configuration given model, 409 * This header is made available to allow proper configuration given model,
407 * revision number , ... this info cannot go in struct asus_hotk because it is 410 * revision number , ... this info cannot go in struct asus_hotk because it is
@@ -779,7 +782,7 @@ proc_write_lcd(struct file *file, const char __user * buffer,
779 return rv; 782 return rv;
780} 783}
781 784
782static int read_brightness(void) 785static int read_brightness(struct backlight_device *bd)
783{ 786{
784 int value; 787 int value;
785 788
@@ -801,9 +804,10 @@ static int read_brightness(void)
801/* 804/*
802 * Change the brightness level 805 * Change the brightness level
803 */ 806 */
804static void set_brightness(int value) 807static int set_brightness(int value)
805{ 808{
806 acpi_status status = 0; 809 acpi_status status = 0;
810 int ret = 0;
807 811
808 /* SPLV laptop */ 812 /* SPLV laptop */
809 if (hotk->methods->brightness_set) { 813 if (hotk->methods->brightness_set) {
@@ -811,11 +815,12 @@ static void set_brightness(int value)
811 value, NULL)) 815 value, NULL))
812 printk(KERN_WARNING 816 printk(KERN_WARNING
813 "Asus ACPI: Error changing brightness\n"); 817 "Asus ACPI: Error changing brightness\n");
814 return; 818 ret = -EIO;
819 goto out;
815 } 820 }
816 821
817 /* No SPLV method if we are here, act as appropriate */ 822 /* No SPLV method if we are here, act as appropriate */
818 value -= read_brightness(); 823 value -= read_brightness(NULL);
819 while (value != 0) { 824 while (value != 0) {
820 status = acpi_evaluate_object(NULL, (value > 0) ? 825 status = acpi_evaluate_object(NULL, (value > 0) ?
821 hotk->methods->brightness_up : 826 hotk->methods->brightness_up :
@@ -825,15 +830,22 @@ static void set_brightness(int value)
825 if (ACPI_FAILURE(status)) 830 if (ACPI_FAILURE(status))
826 printk(KERN_WARNING 831 printk(KERN_WARNING
827 "Asus ACPI: Error changing brightness\n"); 832 "Asus ACPI: Error changing brightness\n");
833 ret = -EIO;
828 } 834 }
829 return; 835out:
836 return ret;
837}
838
839static int set_brightness_status(struct backlight_device *bd)
840{
841 return set_brightness(bd->props->brightness);
830} 842}
831 843
832static int 844static int
833proc_read_brn(char *page, char **start, off_t off, int count, int *eof, 845proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
834 void *data) 846 void *data)
835{ 847{
836 return sprintf(page, "%d\n", read_brightness()); 848 return sprintf(page, "%d\n", read_brightness(NULL));
837} 849}
838 850
839static int 851static int
@@ -1116,7 +1128,6 @@ static int asus_model_match(char *model)
1116static int asus_hotk_get_info(void) 1128static int asus_hotk_get_info(void)
1117{ 1129{
1118 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 1130 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1119 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
1120 union acpi_object *model = NULL; 1131 union acpi_object *model = NULL;
1121 int bsts_result; 1132 int bsts_result;
1122 char *string = NULL; 1133 char *string = NULL;
@@ -1130,11 +1141,9 @@ static int asus_hotk_get_info(void)
1130 * HID), this bit will be moved. A global variable asus_info contains 1141 * HID), this bit will be moved. A global variable asus_info contains
1131 * the DSDT header. 1142 * the DSDT header.
1132 */ 1143 */
1133 status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt); 1144 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
1134 if (ACPI_FAILURE(status)) 1145 if (ACPI_FAILURE(status))
1135 printk(KERN_WARNING " Couldn't get the DSDT table header\n"); 1146 printk(KERN_WARNING " Couldn't get the DSDT table header\n");
1136 else
1137 asus_info = (struct acpi_table_header *)dsdt.pointer;
1138 1147
1139 /* We have to write 0 on init this far for all ASUS models */ 1148 /* We have to write 0 on init this far for all ASUS models */
1140 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) { 1149 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
@@ -1156,7 +1165,7 @@ static int asus_hotk_get_info(void)
1156 * asus_model_match() and try something completely different. 1165 * asus_model_match() and try something completely different.
1157 */ 1166 */
1158 if (buffer.pointer) { 1167 if (buffer.pointer) {
1159 model = (union acpi_object *)buffer.pointer; 1168 model = buffer.pointer;
1160 switch (model->type) { 1169 switch (model->type) {
1161 case ACPI_TYPE_STRING: 1170 case ACPI_TYPE_STRING:
1162 string = model->string.pointer; 1171 string = model->string.pointer;
@@ -1252,11 +1261,9 @@ static int asus_hotk_add(struct acpi_device *device)
1252 printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n", 1261 printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
1253 ASUS_ACPI_VERSION); 1262 ASUS_ACPI_VERSION);
1254 1263
1255 hotk = 1264 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
1256 (struct asus_hotk *)kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
1257 if (!hotk) 1265 if (!hotk)
1258 return -ENOMEM; 1266 return -ENOMEM;
1259 memset(hotk, 0, sizeof(struct asus_hotk));
1260 1267
1261 hotk->handle = device->handle; 1268 hotk->handle = device->handle;
1262 strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME); 1269 strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
@@ -1333,6 +1340,24 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
1333 return 0; 1340 return 0;
1334} 1341}
1335 1342
1343static struct backlight_properties asus_backlight_data = {
1344 .owner = THIS_MODULE,
1345 .get_brightness = read_brightness,
1346 .update_status = set_brightness_status,
1347 .max_brightness = 15,
1348};
1349
1350static void __exit asus_acpi_exit(void)
1351{
1352 if (asus_backlight_device)
1353 backlight_device_unregister(asus_backlight_device);
1354
1355 acpi_bus_unregister_driver(&asus_hotk_driver);
1356 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1357
1358 return;
1359}
1360
1336static int __init asus_acpi_init(void) 1361static int __init asus_acpi_init(void)
1337{ 1362{
1338 int result; 1363 int result;
@@ -1370,17 +1395,15 @@ static int __init asus_acpi_init(void)
1370 return result; 1395 return result;
1371 } 1396 }
1372 1397
1373 return 0; 1398 asus_backlight_device = backlight_device_register("asus",NULL,NULL,
1374} 1399 &asus_backlight_data);
1375 1400 if (IS_ERR(asus_backlight_device)) {
1376static void __exit asus_acpi_exit(void) 1401 printk(KERN_ERR "Could not register asus backlight device\n");
1377{ 1402 asus_backlight_device = NULL;
1378 acpi_bus_unregister_driver(&asus_hotk_driver); 1403 asus_acpi_exit();
1379 remove_proc_entry(PROC_ASUS, acpi_root_dir); 1404 }
1380
1381 kfree(asus_info);
1382 1405
1383 return; 1406 return 0;
1384} 1407}
1385 1408
1386module_init(asus_acpi_init); 1409module_init(asus_acpi_init);
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 07c3c276ad..2f4521a48f 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -149,7 +149,7 @@ acpi_battery_get_info(struct acpi_battery *battery,
149 return -ENODEV; 149 return -ENODEV;
150 } 150 }
151 151
152 package = (union acpi_object *)buffer.pointer; 152 package = buffer.pointer;
153 153
154 /* Extract Package Data */ 154 /* Extract Package Data */
155 155
@@ -160,12 +160,11 @@ acpi_battery_get_info(struct acpi_battery *battery,
160 goto end; 160 goto end;
161 } 161 }
162 162
163 data.pointer = kmalloc(data.length, GFP_KERNEL); 163 data.pointer = kzalloc(data.length, GFP_KERNEL);
164 if (!data.pointer) { 164 if (!data.pointer) {
165 result = -ENOMEM; 165 result = -ENOMEM;
166 goto end; 166 goto end;
167 } 167 }
168 memset(data.pointer, 0, data.length);
169 168
170 status = acpi_extract_package(package, &format, &data); 169 status = acpi_extract_package(package, &format, &data);
171 if (ACPI_FAILURE(status)) { 170 if (ACPI_FAILURE(status)) {
@@ -179,7 +178,7 @@ acpi_battery_get_info(struct acpi_battery *battery,
179 kfree(buffer.pointer); 178 kfree(buffer.pointer);
180 179
181 if (!result) 180 if (!result)
182 (*bif) = (struct acpi_battery_info *)data.pointer; 181 (*bif) = data.pointer;
183 182
184 return result; 183 return result;
185} 184}
@@ -209,7 +208,7 @@ acpi_battery_get_status(struct acpi_battery *battery,
209 return -ENODEV; 208 return -ENODEV;
210 } 209 }
211 210
212 package = (union acpi_object *)buffer.pointer; 211 package = buffer.pointer;
213 212
214 /* Extract Package Data */ 213 /* Extract Package Data */
215 214
@@ -220,12 +219,11 @@ acpi_battery_get_status(struct acpi_battery *battery,
220 goto end; 219 goto end;
221 } 220 }
222 221
223 data.pointer = kmalloc(data.length, GFP_KERNEL); 222 data.pointer = kzalloc(data.length, GFP_KERNEL);
224 if (!data.pointer) { 223 if (!data.pointer) {
225 result = -ENOMEM; 224 result = -ENOMEM;
226 goto end; 225 goto end;
227 } 226 }
228 memset(data.pointer, 0, data.length);
229 227
230 status = acpi_extract_package(package, &format, &data); 228 status = acpi_extract_package(package, &format, &data);
231 if (ACPI_FAILURE(status)) { 229 if (ACPI_FAILURE(status)) {
@@ -239,7 +237,7 @@ acpi_battery_get_status(struct acpi_battery *battery,
239 kfree(buffer.pointer); 237 kfree(buffer.pointer);
240 238
241 if (!result) 239 if (!result)
242 (*bst) = (struct acpi_battery_status *)data.pointer; 240 (*bst) = data.pointer;
243 241
244 return result; 242 return result;
245} 243}
@@ -334,7 +332,7 @@ static struct proc_dir_entry *acpi_battery_dir;
334static int acpi_battery_read_info(struct seq_file *seq, void *offset) 332static int acpi_battery_read_info(struct seq_file *seq, void *offset)
335{ 333{
336 int result = 0; 334 int result = 0;
337 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 335 struct acpi_battery *battery = seq->private;
338 struct acpi_battery_info *bif = NULL; 336 struct acpi_battery_info *bif = NULL;
339 char *units = "?"; 337 char *units = "?";
340 338
@@ -418,7 +416,7 @@ static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
418static int acpi_battery_read_state(struct seq_file *seq, void *offset) 416static int acpi_battery_read_state(struct seq_file *seq, void *offset)
419{ 417{
420 int result = 0; 418 int result = 0;
421 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 419 struct acpi_battery *battery = seq->private;
422 struct acpi_battery_status *bst = NULL; 420 struct acpi_battery_status *bst = NULL;
423 char *units = "?"; 421 char *units = "?";
424 422
@@ -494,7 +492,7 @@ static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
494 492
495static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) 493static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
496{ 494{
497 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 495 struct acpi_battery *battery = seq->private;
498 char *units = "?"; 496 char *units = "?";
499 497
500 498
@@ -531,8 +529,8 @@ acpi_battery_write_alarm(struct file *file,
531{ 529{
532 int result = 0; 530 int result = 0;
533 char alarm_string[12] = { '\0' }; 531 char alarm_string[12] = { '\0' };
534 struct seq_file *m = (struct seq_file *)file->private_data; 532 struct seq_file *m = file->private_data;
535 struct acpi_battery *battery = (struct acpi_battery *)m->private; 533 struct acpi_battery *battery = m->private;
536 534
537 535
538 if (!battery || (count > sizeof(alarm_string) - 1)) 536 if (!battery || (count > sizeof(alarm_string) - 1))
@@ -658,7 +656,7 @@ static int acpi_battery_remove_fs(struct acpi_device *device)
658 656
659static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) 657static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
660{ 658{
661 struct acpi_battery *battery = (struct acpi_battery *)data; 659 struct acpi_battery *battery = data;
662 struct acpi_device *device = NULL; 660 struct acpi_device *device = NULL;
663 661
664 662
@@ -694,10 +692,9 @@ static int acpi_battery_add(struct acpi_device *device)
694 if (!device) 692 if (!device)
695 return -EINVAL; 693 return -EINVAL;
696 694
697 battery = kmalloc(sizeof(struct acpi_battery), GFP_KERNEL); 695 battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL);
698 if (!battery) 696 if (!battery)
699 return -ENOMEM; 697 return -ENOMEM;
700 memset(battery, 0, sizeof(struct acpi_battery));
701 698
702 battery->device = device; 699 battery->device = device;
703 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); 700 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
@@ -742,7 +739,7 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
742 if (!device || !acpi_driver_data(device)) 739 if (!device || !acpi_driver_data(device))
743 return -EINVAL; 740 return -EINVAL;
744 741
745 battery = (struct acpi_battery *)acpi_driver_data(device); 742 battery = acpi_driver_data(device);
746 743
747 status = acpi_remove_notify_handler(device->handle, 744 status = acpi_remove_notify_handler(device->handle,
748 ACPI_ALL_NOTIFY, 745 ACPI_ALL_NOTIFY,
diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c
new file mode 100644
index 0000000000..aa1b131c0f
--- /dev/null
+++ b/drivers/acpi/bay.c
@@ -0,0 +1,506 @@
1/*
2 * bay.c - ACPI removable drive bay driver
3 *
4 * Copyright (C) 2006 Kristen Carlson Accardi <kristen.c.accardi@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/types.h>
28#include <linux/notifier.h>
29#include <acpi/acpi_bus.h>
30#include <acpi/acpi_drivers.h>
31#include <linux/seq_file.h>
32#include <asm/uaccess.h>
33#include <linux/platform_device.h>
34
35#define ACPI_BAY_DRIVER_NAME "ACPI Removable Drive Bay Driver"
36
37ACPI_MODULE_NAME("bay")
38MODULE_AUTHOR("Kristen Carlson Accardi");
39MODULE_DESCRIPTION(ACPI_BAY_DRIVER_NAME);
40MODULE_LICENSE("GPL");
41#define ACPI_BAY_CLASS "bay"
42#define ACPI_BAY_COMPONENT 0x10000000
43#define _COMPONENT ACPI_BAY_COMPONENT
44#define bay_dprintk(h,s) {\
45 char prefix[80] = {'\0'};\
46 struct acpi_buffer buffer = {sizeof(prefix), prefix};\
47 acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\
48 printk(KERN_DEBUG PREFIX "%s: %s\n", prefix, s); }
49static void bay_notify(acpi_handle handle, u32 event, void *data);
50static int acpi_bay_add(struct acpi_device *device);
51static int acpi_bay_remove(struct acpi_device *device, int type);
52static int acpi_bay_match(struct acpi_device *device,
53 struct acpi_driver *driver);
54
55static struct acpi_driver acpi_bay_driver = {
56 .name = ACPI_BAY_DRIVER_NAME,
57 .class = ACPI_BAY_CLASS,
58 .ops = {
59 .add = acpi_bay_add,
60 .remove = acpi_bay_remove,
61 .match = acpi_bay_match,
62 },
63};
64
65struct bay {
66 acpi_handle handle;
67 char *name;
68 struct list_head list;
69 struct platform_device *pdev;
70};
71
72static LIST_HEAD(drive_bays);
73
74
75/*****************************************************************************
76 * Drive Bay functions *
77 *****************************************************************************/
78/**
79 * is_ejectable - see if a device is ejectable
80 * @handle: acpi handle of the device
81 *
82 * If an acpi object has a _EJ0 method, then it is ejectable
83 */
84static int is_ejectable(acpi_handle handle)
85{
86 acpi_status status;
87 acpi_handle tmp;
88
89 status = acpi_get_handle(handle, "_EJ0", &tmp);
90 if (ACPI_FAILURE(status))
91 return 0;
92 return 1;
93}
94
95/**
96 * bay_present - see if the bay device is present
97 * @bay: the drive bay
98 *
99 * execute the _STA method.
100 */
101static int bay_present(struct bay *bay)
102{
103 unsigned long sta;
104 acpi_status status;
105
106 if (bay) {
107 status = acpi_evaluate_integer(bay->handle, "_STA", NULL, &sta);
108 if (ACPI_SUCCESS(status) && sta)
109 return 1;
110 }
111 return 0;
112}
113
114/**
115 * eject_device - respond to an eject request
116 * @handle - the device to eject
117 *
118 * Call this devices _EJ0 method.
119 */
120static void eject_device(acpi_handle handle)
121{
122 struct acpi_object_list arg_list;
123 union acpi_object arg;
124
125 bay_dprintk(handle, "Ejecting device");
126
127 arg_list.count = 1;
128 arg_list.pointer = &arg;
129 arg.type = ACPI_TYPE_INTEGER;
130 arg.integer.value = 1;
131
132 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_EJ0",
133 &arg_list, NULL)))
134 pr_debug("Failed to evaluate _EJ0!\n");
135}
136
137/*
138 * show_present - read method for "present" file in sysfs
139 */
140static ssize_t show_present(struct device *dev,
141 struct device_attribute *attr, char *buf)
142{
143 struct bay *bay = dev_get_drvdata(dev);
144 return snprintf(buf, PAGE_SIZE, "%d\n", bay_present(bay));
145
146}
147DEVICE_ATTR(present, S_IRUGO, show_present, NULL);
148
149/*
150 * write_eject - write method for "eject" file in sysfs
151 */
152static ssize_t write_eject(struct device *dev, struct device_attribute *attr,
153 const char *buf, size_t count)
154{
155 struct bay *bay = dev_get_drvdata(dev);
156
157 if (!count)
158 return -EINVAL;
159
160 eject_device(bay->handle);
161 return count;
162}
163DEVICE_ATTR(eject, S_IWUSR, NULL, write_eject);
164
165/**
166 * is_ata - see if a device is an ata device
167 * @handle: acpi handle of the device
168 *
169 * If an acpi object has one of 4 ATA ACPI methods defined,
170 * then it is an ATA device
171 */
172static int is_ata(acpi_handle handle)
173{
174 acpi_handle tmp;
175
176 if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
177 (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
178 (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
179 (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
180 return 1;
181
182 return 0;
183}
184
185/**
186 * parent_is_ata(acpi_handle handle)
187 *
188 */
189static int parent_is_ata(acpi_handle handle)
190{
191 acpi_handle phandle;
192
193 if (acpi_get_parent(handle, &phandle))
194 return 0;
195
196 return is_ata(phandle);
197}
198
199/**
200 * is_ejectable_bay - see if a device is an ejectable drive bay
201 * @handle: acpi handle of the device
202 *
203 * If an acpi object is ejectable and has one of the ACPI ATA
204 * methods defined, then we can safely call it an ejectable
205 * drive bay
206 */
207static int is_ejectable_bay(acpi_handle handle)
208{
209 if ((is_ata(handle) || parent_is_ata(handle)) && is_ejectable(handle))
210 return 1;
211 return 0;
212}
213
214/**
215 * eject_removable_drive - try to eject this drive
216 * @dev : the device structure of the drive
217 *
218 * If a device is a removable drive that requires an _EJ0 method
219 * to be executed in order to safely remove from the system, do
220 * it. ATM - always returns success
221 */
222int eject_removable_drive(struct device *dev)
223{
224 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
225
226 if (handle) {
227 bay_dprintk(handle, "Got device handle");
228 if (is_ejectable_bay(handle))
229 eject_device(handle);
230 } else {
231 printk("No acpi handle for device\n");
232 }
233
234 /* should I return an error code? */
235 return 0;
236}
237EXPORT_SYMBOL_GPL(eject_removable_drive);
238
239static int acpi_bay_add(struct acpi_device *device)
240{
241 bay_dprintk(device->handle, "adding bay device");
242 strcpy(acpi_device_name(device), "Dockable Bay");
243 strcpy(acpi_device_class(device), "bay");
244 return 0;
245}
246
247static int acpi_bay_add_fs(struct bay *bay)
248{
249 int ret;
250 struct device *dev = &bay->pdev->dev;
251
252 ret = device_create_file(dev, &dev_attr_present);
253 if (ret)
254 goto add_fs_err;
255 ret = device_create_file(dev, &dev_attr_eject);
256 if (ret) {
257 device_remove_file(dev, &dev_attr_present);
258 goto add_fs_err;
259 }
260 return 0;
261
262 add_fs_err:
263 bay_dprintk(bay->handle, "Error adding sysfs files\n");
264 return ret;
265}
266
267static void acpi_bay_remove_fs(struct bay *bay)
268{
269 struct device *dev = &bay->pdev->dev;
270
271 /* cleanup sysfs */
272 device_remove_file(dev, &dev_attr_present);
273 device_remove_file(dev, &dev_attr_eject);
274}
275
276static int bay_is_dock_device(acpi_handle handle)
277{
278 acpi_handle parent;
279
280 acpi_get_parent(handle, &parent);
281
282 /* if the device or it's parent is dependent on the
283 * dock, then we are a dock device
284 */
285 return (is_dock_device(handle) || is_dock_device(parent));
286}
287
288static int bay_add(acpi_handle handle, int id)
289{
290 acpi_status status;
291 struct bay *new_bay;
292 struct platform_device *pdev;
293 struct acpi_buffer nbuffer = {ACPI_ALLOCATE_BUFFER, NULL};
294 acpi_get_name(handle, ACPI_FULL_PATHNAME, &nbuffer);
295
296 bay_dprintk(handle, "Adding notify handler");
297
298 /*
299 * Initialize bay device structure
300 */
301 new_bay = kzalloc(GFP_ATOMIC, sizeof(*new_bay));
302 INIT_LIST_HEAD(&new_bay->list);
303 new_bay->handle = handle;
304 new_bay->name = (char *)nbuffer.pointer;
305
306 /* initialize platform device stuff */
307 pdev = platform_device_register_simple(ACPI_BAY_CLASS, id, NULL, 0);
308 if (pdev == NULL) {
309 printk(KERN_ERR PREFIX "Error registering bay device\n");
310 goto bay_add_err;
311 }
312 new_bay->pdev = pdev;
313 platform_set_drvdata(pdev, new_bay);
314
315 if (acpi_bay_add_fs(new_bay)) {
316 platform_device_unregister(new_bay->pdev);
317 goto bay_add_err;
318 }
319
320 /* register for events on this device */
321 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
322 bay_notify, new_bay);
323 if (ACPI_FAILURE(status)) {
324 printk(KERN_ERR PREFIX "Error installing bay notify handler\n");
325 }
326
327 /* if we are on a dock station, we should register for dock
328 * notifications.
329 */
330 if (bay_is_dock_device(handle)) {
331 bay_dprintk(handle, "Is dependent on dock\n");
332 register_hotplug_dock_device(handle, bay_notify, new_bay);
333 }
334 list_add(&new_bay->list, &drive_bays);
335 printk(KERN_INFO PREFIX "Bay [%s] Added\n", new_bay->name);
336 return 0;
337
338bay_add_err:
339 kfree(new_bay->name);
340 kfree(new_bay);
341 return -ENODEV;
342}
343
344static int acpi_bay_remove(struct acpi_device *device, int type)
345{
346 /*** FIXME: do something here */
347 return 0;
348}
349
350static int acpi_bay_match(struct acpi_device *device,
351 struct acpi_driver *driver)
352{
353 if (!device || !driver)
354 return -EINVAL;
355
356 if (is_ejectable_bay(device->handle)) {
357 bay_dprintk(device->handle, "matching bay device");
358 return 0;
359 }
360
361 return -ENODEV;
362}
363
364/**
365 * bay_create_acpi_device - add new devices to acpi
366 * @handle - handle of the device to add
367 *
368 * This function will create a new acpi_device for the given
369 * handle if one does not exist already. This should cause
370 * acpi to scan for drivers for the given devices, and call
371 * matching driver's add routine.
372 *
373 * Returns a pointer to the acpi_device corresponding to the handle.
374 */
375static struct acpi_device * bay_create_acpi_device(acpi_handle handle)
376{
377 struct acpi_device *device = NULL;
378 struct acpi_device *parent_device;
379 acpi_handle parent;
380 int ret;
381
382 bay_dprintk(handle, "Trying to get device");
383 if (acpi_bus_get_device(handle, &device)) {
384 /*
385 * no device created for this object,
386 * so we should create one.
387 */
388 bay_dprintk(handle, "No device for handle");
389 acpi_get_parent(handle, &parent);
390 if (acpi_bus_get_device(parent, &parent_device))
391 parent_device = NULL;
392
393 ret = acpi_bus_add(&device, parent_device, handle,
394 ACPI_BUS_TYPE_DEVICE);
395 if (ret) {
396 pr_debug("error adding bus, %x\n",
397 -ret);
398 return NULL;
399 }
400 }
401 return device;
402}
403
404/**
405 * bay_notify - act upon an acpi bay notification
406 * @handle: the bay handle
407 * @event: the acpi event
408 * @data: our driver data struct
409 *
410 */
411static void bay_notify(acpi_handle handle, u32 event, void *data)
412{
413 struct acpi_device *dev;
414
415 bay_dprintk(handle, "Bay event");
416
417 switch(event) {
418 case ACPI_NOTIFY_BUS_CHECK:
419 printk("Bus Check\n");
420 case ACPI_NOTIFY_DEVICE_CHECK:
421 printk("Device Check\n");
422 dev = bay_create_acpi_device(handle);
423 if (dev)
424 acpi_bus_generate_event(dev, event, 0);
425 else
426 printk("No device for generating event\n");
427 /* wouldn't it be a good idea to just rescan SATA
428 * right here?
429 */
430 break;
431 case ACPI_NOTIFY_EJECT_REQUEST:
432 printk("Eject request\n");
433 dev = bay_create_acpi_device(handle);
434 if (dev)
435 acpi_bus_generate_event(dev, event, 0);
436 else
437 printk("No device for generating eventn");
438
439 /* wouldn't it be a good idea to just call the
440 * eject_device here if we were a SATA device?
441 */
442 break;
443 default:
444 printk("unknown event %d\n", event);
445 }
446}
447
448static acpi_status
449find_bay(acpi_handle handle, u32 lvl, void *context, void **rv)
450{
451 int *count = (int *)context;
452
453 /*
454 * there could be more than one ejectable bay.
455 * so, just return AE_OK always so that every object
456 * will be checked.
457 */
458 if (is_ejectable_bay(handle)) {
459 bay_dprintk(handle, "found ejectable bay");
460 if (!bay_add(handle, *count))
461 (*count)++;
462 }
463 return AE_OK;
464}
465
466static int __init bay_init(void)
467{
468 int bays = 0;
469
470 INIT_LIST_HEAD(&drive_bays);
471
472 /* look for dockable drive bays */
473 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
474 ACPI_UINT32_MAX, find_bay, &bays, NULL);
475
476 if (bays)
477 if ((acpi_bus_register_driver(&acpi_bay_driver) < 0))
478 printk(KERN_ERR "Unable to register bay driver\n");
479
480 if (!bays)
481 return -ENODEV;
482
483 return 0;
484}
485
486static void __exit bay_exit(void)
487{
488 struct bay *bay, *tmp;
489
490 list_for_each_entry_safe(bay, tmp, &drive_bays, list) {
491 if (is_dock_device(bay->handle))
492 unregister_hotplug_dock_device(bay->handle);
493 acpi_bay_remove_fs(bay);
494 acpi_remove_notify_handler(bay->handle, ACPI_SYSTEM_NOTIFY,
495 bay_notify);
496 platform_device_unregister(bay->pdev);
497 kfree(bay->name);
498 kfree(bay);
499 }
500
501 acpi_bus_unregister_driver(&acpi_bay_driver);
502}
503
504postcore_initcall(bay_init);
505module_exit(bay_exit);
506
diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
index f9c972b26f..f289fd41e7 100644
--- a/drivers/acpi/blacklist.c
+++ b/drivers/acpi/blacklist.c
@@ -44,7 +44,7 @@ struct acpi_blacklist_item {
44 char oem_id[7]; 44 char oem_id[7];
45 char oem_table_id[9]; 45 char oem_table_id[9];
46 u32 oem_revision; 46 u32 oem_revision;
47 acpi_table_type table; 47 char *table;
48 enum acpi_blacklist_predicates oem_revision_predicate; 48 enum acpi_blacklist_predicates oem_revision_predicate;
49 char *reason; 49 char *reason;
50 u32 is_critical_error; 50 u32 is_critical_error;
@@ -56,18 +56,18 @@ struct acpi_blacklist_item {
56 */ 56 */
57static struct acpi_blacklist_item acpi_blacklist[] __initdata = { 57static struct acpi_blacklist_item acpi_blacklist[] __initdata = {
58 /* Compaq Presario 1700 */ 58 /* Compaq Presario 1700 */
59 {"PTLTD ", " DSDT ", 0x06040000, ACPI_DSDT, less_than_or_equal, 59 {"PTLTD ", " DSDT ", 0x06040000, ACPI_SIG_DSDT, less_than_or_equal,
60 "Multiple problems", 1}, 60 "Multiple problems", 1},
61 /* Sony FX120, FX140, FX150? */ 61 /* Sony FX120, FX140, FX150? */
62 {"SONY ", "U0 ", 0x20010313, ACPI_DSDT, less_than_or_equal, 62 {"SONY ", "U0 ", 0x20010313, ACPI_SIG_DSDT, less_than_or_equal,
63 "ACPI driver problem", 1}, 63 "ACPI driver problem", 1},
64 /* Compaq Presario 800, Insyde BIOS */ 64 /* Compaq Presario 800, Insyde BIOS */
65 {"INT440", "SYSFexxx", 0x00001001, ACPI_DSDT, less_than_or_equal, 65 {"INT440", "SYSFexxx", 0x00001001, ACPI_SIG_DSDT, less_than_or_equal,
66 "Does not use _REG to protect EC OpRegions", 1}, 66 "Does not use _REG to protect EC OpRegions", 1},
67 /* IBM 600E - _ADR should return 7, but it returns 1 */ 67 /* IBM 600E - _ADR should return 7, but it returns 1 */
68 {"IBM ", "TP600E ", 0x00000105, ACPI_DSDT, less_than_or_equal, 68 {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
69 "Incorrect _ADR", 1}, 69 "Incorrect _ADR", 1},
70 {"ASUS\0\0", "P2B-S ", 0, ACPI_DSDT, all_versions, 70 {"ASUS\0\0", "P2B-S ", 0, ACPI_SIG_DSDT, all_versions,
71 "Bogus PCI routing", 1}, 71 "Bogus PCI routing", 1},
72 72
73 {""} 73 {""}
@@ -79,7 +79,7 @@ static int __init blacklist_by_year(void)
79{ 79{
80 int year = dmi_get_year(DMI_BIOS_DATE); 80 int year = dmi_get_year(DMI_BIOS_DATE);
81 /* Doesn't exist? Likely an old system */ 81 /* Doesn't exist? Likely an old system */
82 if (year == -1) 82 if (year == -1)
83 return 1; 83 return 1;
84 /* 0? Likely a buggy new BIOS */ 84 /* 0? Likely a buggy new BIOS */
85 if (year == 0) 85 if (year == 0)
@@ -103,22 +103,21 @@ int __init acpi_blacklisted(void)
103{ 103{
104 int i = 0; 104 int i = 0;
105 int blacklisted = 0; 105 int blacklisted = 0;
106 struct acpi_table_header *table_header; 106 struct acpi_table_header table_header;
107 107
108 while (acpi_blacklist[i].oem_id[0] != '\0') { 108 while (acpi_blacklist[i].oem_id[0] != '\0') {
109 if (acpi_get_table_header_early 109 if (acpi_get_table_header(acpi_blacklist[i].table, 0, &table_header)) {
110 (acpi_blacklist[i].table, &table_header)) {
111 i++; 110 i++;
112 continue; 111 continue;
113 } 112 }
114 113
115 if (strncmp(acpi_blacklist[i].oem_id, table_header->oem_id, 6)) { 114 if (strncmp(acpi_blacklist[i].oem_id, table_header.oem_id, 6)) {
116 i++; 115 i++;
117 continue; 116 continue;
118 } 117 }
119 118
120 if (strncmp 119 if (strncmp
121 (acpi_blacklist[i].oem_table_id, table_header->oem_table_id, 120 (acpi_blacklist[i].oem_table_id, table_header.oem_table_id,
122 8)) { 121 8)) {
123 i++; 122 i++;
124 continue; 123 continue;
@@ -127,14 +126,14 @@ int __init acpi_blacklisted(void)
127 if ((acpi_blacklist[i].oem_revision_predicate == all_versions) 126 if ((acpi_blacklist[i].oem_revision_predicate == all_versions)
128 || (acpi_blacklist[i].oem_revision_predicate == 127 || (acpi_blacklist[i].oem_revision_predicate ==
129 less_than_or_equal 128 less_than_or_equal
130 && table_header->oem_revision <= 129 && table_header.oem_revision <=
131 acpi_blacklist[i].oem_revision) 130 acpi_blacklist[i].oem_revision)
132 || (acpi_blacklist[i].oem_revision_predicate == 131 || (acpi_blacklist[i].oem_revision_predicate ==
133 greater_than_or_equal 132 greater_than_or_equal
134 && table_header->oem_revision >= 133 && table_header.oem_revision >=
135 acpi_blacklist[i].oem_revision) 134 acpi_blacklist[i].oem_revision)
136 || (acpi_blacklist[i].oem_revision_predicate == equal 135 || (acpi_blacklist[i].oem_revision_predicate == equal
137 && table_header->oem_revision == 136 && table_header.oem_revision ==
138 acpi_blacklist[i].oem_revision)) { 137 acpi_blacklist[i].oem_revision)) {
139 138
140 printk(KERN_ERR PREFIX 139 printk(KERN_ERR PREFIX
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index da471f647d..c26468da42 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -44,9 +44,6 @@ ACPI_MODULE_NAME("acpi_bus")
44extern void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger); 44extern void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger);
45#endif 45#endif
46 46
47struct fadt_descriptor acpi_fadt;
48EXPORT_SYMBOL(acpi_fadt);
49
50struct acpi_device *acpi_root; 47struct acpi_device *acpi_root;
51struct proc_dir_entry *acpi_root_dir; 48struct proc_dir_entry *acpi_root_dir;
52EXPORT_SYMBOL(acpi_root_dir); 49EXPORT_SYMBOL(acpi_root_dir);
@@ -561,6 +558,9 @@ static int __init acpi_bus_init_irq(void)
561 case ACPI_IRQ_MODEL_IOSAPIC: 558 case ACPI_IRQ_MODEL_IOSAPIC:
562 message = "IOSAPIC"; 559 message = "IOSAPIC";
563 break; 560 break;
561 case ACPI_IRQ_MODEL_PLATFORM:
562 message = "platform specific model";
563 break;
564 default: 564 default:
565 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n"); 565 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
566 return -ENODEV; 566 return -ENODEV;
@@ -579,11 +579,12 @@ static int __init acpi_bus_init_irq(void)
579 return 0; 579 return 0;
580} 580}
581 581
582acpi_native_uint acpi_gbl_permanent_mmap;
583
584
582void __init acpi_early_init(void) 585void __init acpi_early_init(void)
583{ 586{
584 acpi_status status = AE_OK; 587 acpi_status status = AE_OK;
585 struct acpi_buffer buffer = { sizeof(acpi_fadt), &acpi_fadt };
586
587 588
588 if (acpi_disabled) 589 if (acpi_disabled)
589 return; 590 return;
@@ -594,6 +595,15 @@ void __init acpi_early_init(void)
594 if (!acpi_strict) 595 if (!acpi_strict)
595 acpi_gbl_enable_interpreter_slack = TRUE; 596 acpi_gbl_enable_interpreter_slack = TRUE;
596 597
598 acpi_gbl_permanent_mmap = 1;
599
600 status = acpi_reallocate_root_table();
601 if (ACPI_FAILURE(status)) {
602 printk(KERN_ERR PREFIX
603 "Unable to reallocate ACPI tables\n");
604 goto error0;
605 }
606
597 status = acpi_initialize_subsystem(); 607 status = acpi_initialize_subsystem();
598 if (ACPI_FAILURE(status)) { 608 if (ACPI_FAILURE(status)) {
599 printk(KERN_ERR PREFIX 609 printk(KERN_ERR PREFIX
@@ -608,32 +618,25 @@ void __init acpi_early_init(void)
608 goto error0; 618 goto error0;
609 } 619 }
610 620
611 /*
612 * Get a separate copy of the FADT for use by other drivers.
613 */
614 status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &buffer);
615 if (ACPI_FAILURE(status)) {
616 printk(KERN_ERR PREFIX "Unable to get the FADT\n");
617 goto error0;
618 }
619#ifdef CONFIG_X86 621#ifdef CONFIG_X86
620 if (!acpi_ioapic) { 622 if (!acpi_ioapic) {
621 extern acpi_interrupt_flags acpi_sci_flags; 623 extern u8 acpi_sci_flags;
622 624
623 /* compatible (0) means level (3) */ 625 /* compatible (0) means level (3) */
624 if (acpi_sci_flags.trigger == 0) 626 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
625 acpi_sci_flags.trigger = 3; 627 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
626 628 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
629 }
627 /* Set PIC-mode SCI trigger type */ 630 /* Set PIC-mode SCI trigger type */
628 acpi_pic_sci_set_trigger(acpi_fadt.sci_int, 631 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
629 acpi_sci_flags.trigger); 632 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
630 } else { 633 } else {
631 extern int acpi_sci_override_gsi; 634 extern int acpi_sci_override_gsi;
632 /* 635 /*
633 * now that acpi_fadt is initialized, 636 * now that acpi_gbl_FADT is initialized,
634 * update it with result from INT_SRC_OVR parsing 637 * update it with result from INT_SRC_OVR parsing
635 */ 638 */
636 acpi_fadt.sci_int = acpi_sci_override_gsi; 639 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
637 } 640 }
638#endif 641#endif
639 642
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 7fda02c983..c726612faf 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -29,6 +29,7 @@
29#include <linux/types.h> 29#include <linux/types.h>
30#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/input.h>
32#include <acpi/acpi_bus.h> 33#include <acpi/acpi_bus.h>
33#include <acpi/acpi_drivers.h> 34#include <acpi/acpi_drivers.h>
34 35
@@ -62,7 +63,7 @@
62#define _COMPONENT ACPI_BUTTON_COMPONENT 63#define _COMPONENT ACPI_BUTTON_COMPONENT
63ACPI_MODULE_NAME("acpi_button") 64ACPI_MODULE_NAME("acpi_button")
64 65
65 MODULE_AUTHOR("Paul Diefenbaugh"); 66MODULE_AUTHOR("Paul Diefenbaugh");
66MODULE_DESCRIPTION(ACPI_BUTTON_DRIVER_NAME); 67MODULE_DESCRIPTION(ACPI_BUTTON_DRIVER_NAME);
67MODULE_LICENSE("GPL"); 68MODULE_LICENSE("GPL");
68 69
@@ -78,12 +79,14 @@ static struct acpi_driver acpi_button_driver = {
78 .ops = { 79 .ops = {
79 .add = acpi_button_add, 80 .add = acpi_button_add,
80 .remove = acpi_button_remove, 81 .remove = acpi_button_remove,
81 }, 82 },
82}; 83};
83 84
84struct acpi_button { 85struct acpi_button {
85 struct acpi_device *device; /* Fixed button kludge */ 86 struct acpi_device *device; /* Fixed button kludge */
86 u8 type; 87 unsigned int type;
88 struct input_dev *input;
89 char phys[32]; /* for input device */
87 unsigned long pushed; 90 unsigned long pushed;
88}; 91};
89 92
@@ -109,8 +112,7 @@ static struct proc_dir_entry *acpi_button_dir;
109 112
110static int acpi_button_info_seq_show(struct seq_file *seq, void *offset) 113static int acpi_button_info_seq_show(struct seq_file *seq, void *offset)
111{ 114{
112 struct acpi_button *button = (struct acpi_button *)seq->private; 115 struct acpi_button *button = seq->private;
113
114 116
115 if (!button || !button->device) 117 if (!button || !button->device)
116 return 0; 118 return 0;
@@ -128,22 +130,17 @@ static int acpi_button_info_open_fs(struct inode *inode, struct file *file)
128 130
129static int acpi_button_state_seq_show(struct seq_file *seq, void *offset) 131static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
130{ 132{
131 struct acpi_button *button = (struct acpi_button *)seq->private; 133 struct acpi_button *button = seq->private;
132 acpi_status status; 134 acpi_status status;
133 unsigned long state; 135 unsigned long state;
134 136
135
136 if (!button || !button->device) 137 if (!button || !button->device)
137 return 0; 138 return 0;
138 139
139 status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state); 140 status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state);
140 if (ACPI_FAILURE(status)) { 141 seq_printf(seq, "state: %s\n",
141 seq_printf(seq, "state: unsupported\n"); 142 ACPI_FAILURE(status) ? "unsupported" :
142 } else { 143 (state ? "open" : "closed"));
143 seq_printf(seq, "state: %s\n",
144 (state ? "open" : "closed"));
145 }
146
147 return 0; 144 return 0;
148} 145}
149 146
@@ -159,8 +156,7 @@ static struct proc_dir_entry *acpi_lid_dir;
159static int acpi_button_add_fs(struct acpi_device *device) 156static int acpi_button_add_fs(struct acpi_device *device)
160{ 157{
161 struct proc_dir_entry *entry = NULL; 158 struct proc_dir_entry *entry = NULL;
162 struct acpi_button *button = NULL; 159 struct acpi_button *button;
163
164 160
165 if (!device || !acpi_driver_data(device)) 161 if (!device || !acpi_driver_data(device))
166 return -EINVAL; 162 return -EINVAL;
@@ -228,10 +224,8 @@ static int acpi_button_add_fs(struct acpi_device *device)
228 224
229static int acpi_button_remove_fs(struct acpi_device *device) 225static int acpi_button_remove_fs(struct acpi_device *device)
230{ 226{
231 struct acpi_button *button = NULL; 227 struct acpi_button *button = acpi_driver_data(device);
232
233 228
234 button = acpi_driver_data(device);
235 if (acpi_device_dir(device)) { 229 if (acpi_device_dir(device)) {
236 if (button->type == ACPI_BUTTON_TYPE_LID) 230 if (button->type == ACPI_BUTTON_TYPE_LID)
237 remove_proc_entry(ACPI_BUTTON_FILE_STATE, 231 remove_proc_entry(ACPI_BUTTON_FILE_STATE,
@@ -253,14 +247,34 @@ static int acpi_button_remove_fs(struct acpi_device *device)
253 247
254static void acpi_button_notify(acpi_handle handle, u32 event, void *data) 248static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
255{ 249{
256 struct acpi_button *button = (struct acpi_button *)data; 250 struct acpi_button *button = data;
257 251 struct input_dev *input;
258 252
259 if (!button || !button->device) 253 if (!button || !button->device)
260 return; 254 return;
261 255
262 switch (event) { 256 switch (event) {
263 case ACPI_BUTTON_NOTIFY_STATUS: 257 case ACPI_BUTTON_NOTIFY_STATUS:
258 input = button->input;
259
260 if (button->type == ACPI_BUTTON_TYPE_LID) {
261 struct acpi_handle *handle = button->device->handle;
262 unsigned long state;
263
264 if (!ACPI_FAILURE(acpi_evaluate_integer(handle, "_LID",
265 NULL, &state)))
266 input_report_switch(input, SW_LID, !state);
267
268 } else {
269 int keycode = test_bit(KEY_SLEEP, input->keybit) ?
270 KEY_SLEEP : KEY_POWER;
271
272 input_report_key(input, keycode, 1);
273 input_sync(input);
274 input_report_key(input, keycode, 0);
275 }
276 input_sync(input);
277
264 acpi_bus_generate_event(button->device, event, 278 acpi_bus_generate_event(button->device, event,
265 ++button->pushed); 279 ++button->pushed);
266 break; 280 break;
@@ -275,8 +289,7 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
275 289
276static acpi_status acpi_button_notify_fixed(void *data) 290static acpi_status acpi_button_notify_fixed(void *data)
277{ 291{
278 struct acpi_button *button = (struct acpi_button *)data; 292 struct acpi_button *button = data;
279
280 293
281 if (!button) 294 if (!button)
282 return AE_BAD_PARAMETER; 295 return AE_BAD_PARAMETER;
@@ -286,24 +299,75 @@ static acpi_status acpi_button_notify_fixed(void *data)
286 return AE_OK; 299 return AE_OK;
287} 300}
288 301
289static int acpi_button_add(struct acpi_device *device) 302static int acpi_button_install_notify_handlers(struct acpi_button *button)
290{ 303{
291 int result = 0; 304 acpi_status status;
292 acpi_status status = AE_OK;
293 struct acpi_button *button = NULL;
294 305
306 switch (button->type) {
307 case ACPI_BUTTON_TYPE_POWERF:
308 status =
309 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
310 acpi_button_notify_fixed,
311 button);
312 break;
313 case ACPI_BUTTON_TYPE_SLEEPF:
314 status =
315 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
316 acpi_button_notify_fixed,
317 button);
318 break;
319 default:
320 status = acpi_install_notify_handler(button->device->handle,
321 ACPI_DEVICE_NOTIFY,
322 acpi_button_notify,
323 button);
324 break;
325 }
326
327 return ACPI_FAILURE(status) ? -ENODEV : 0;
328}
329
330static void acpi_button_remove_notify_handlers(struct acpi_button *button)
331{
332 switch (button->type) {
333 case ACPI_BUTTON_TYPE_POWERF:
334 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
335 acpi_button_notify_fixed);
336 break;
337 case ACPI_BUTTON_TYPE_SLEEPF:
338 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
339 acpi_button_notify_fixed);
340 break;
341 default:
342 acpi_remove_notify_handler(button->device->handle,
343 ACPI_DEVICE_NOTIFY,
344 acpi_button_notify);
345 break;
346 }
347}
348
349static int acpi_button_add(struct acpi_device *device)
350{
351 int error;
352 struct acpi_button *button;
353 struct input_dev *input;
295 354
296 if (!device) 355 if (!device)
297 return -EINVAL; 356 return -EINVAL;
298 357
299 button = kmalloc(sizeof(struct acpi_button), GFP_KERNEL); 358 button = kzalloc(sizeof(struct acpi_button), GFP_KERNEL);
300 if (!button) 359 if (!button)
301 return -ENOMEM; 360 return -ENOMEM;
302 memset(button, 0, sizeof(struct acpi_button));
303 361
304 button->device = device; 362 button->device = device;
305 acpi_driver_data(device) = button; 363 acpi_driver_data(device) = button;
306 364
365 button->input = input = input_allocate_device();
366 if (!input) {
367 error = -ENOMEM;
368 goto err_free_button;
369 }
370
307 /* 371 /*
308 * Determine the button type (via hid), as fixed-feature buttons 372 * Determine the button type (via hid), as fixed-feature buttons
309 * need to be handled a bit differently than generic-space. 373 * need to be handled a bit differently than generic-space.
@@ -338,39 +402,48 @@ static int acpi_button_add(struct acpi_device *device)
338 } else { 402 } else {
339 printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", 403 printk(KERN_ERR PREFIX "Unsupported hid [%s]\n",
340 acpi_device_hid(device)); 404 acpi_device_hid(device));
341 result = -ENODEV; 405 error = -ENODEV;
342 goto end; 406 goto err_free_input;
343 } 407 }
344 408
345 result = acpi_button_add_fs(device); 409 error = acpi_button_add_fs(device);
346 if (result) 410 if (error)
347 goto end; 411 goto err_free_input;
412
413 error = acpi_button_install_notify_handlers(button);
414 if (error)
415 goto err_remove_fs;
416
417 snprintf(button->phys, sizeof(button->phys),
418 "%s/button/input0", acpi_device_hid(device));
419
420 input->name = acpi_device_name(device);
421 input->phys = button->phys;
422 input->id.bustype = BUS_HOST;
423 input->id.product = button->type;
348 424
349 switch (button->type) { 425 switch (button->type) {
426 case ACPI_BUTTON_TYPE_POWER:
350 case ACPI_BUTTON_TYPE_POWERF: 427 case ACPI_BUTTON_TYPE_POWERF:
351 status = 428 input->evbit[0] = BIT(EV_KEY);
352 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, 429 set_bit(KEY_POWER, input->keybit);
353 acpi_button_notify_fixed,
354 button);
355 break; 430 break;
431
432 case ACPI_BUTTON_TYPE_SLEEP:
356 case ACPI_BUTTON_TYPE_SLEEPF: 433 case ACPI_BUTTON_TYPE_SLEEPF:
357 status = 434 input->evbit[0] = BIT(EV_KEY);
358 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, 435 set_bit(KEY_SLEEP, input->keybit);
359 acpi_button_notify_fixed,
360 button);
361 break; 436 break;
362 default: 437
363 status = acpi_install_notify_handler(device->handle, 438 case ACPI_BUTTON_TYPE_LID:
364 ACPI_DEVICE_NOTIFY, 439 input->evbit[0] = BIT(EV_SW);
365 acpi_button_notify, 440 set_bit(SW_LID, input->swbit);
366 button);
367 break; 441 break;
368 } 442 }
369 443
370 if (ACPI_FAILURE(status)) { 444 error = input_register_device(input);
371 result = -ENODEV; 445 if (error)
372 goto end; 446 goto err_remove_handlers;
373 }
374 447
375 if (device->wakeup.flags.valid) { 448 if (device->wakeup.flags.valid) {
376 /* Button's GPE is run-wake GPE */ 449 /* Button's GPE is run-wake GPE */
@@ -385,47 +458,31 @@ static int acpi_button_add(struct acpi_device *device)
385 printk(KERN_INFO PREFIX "%s [%s]\n", 458 printk(KERN_INFO PREFIX "%s [%s]\n",
386 acpi_device_name(device), acpi_device_bid(device)); 459 acpi_device_name(device), acpi_device_bid(device));
387 460
388 end: 461 return 0;
389 if (result) {
390 acpi_button_remove_fs(device);
391 kfree(button);
392 }
393 462
394 return result; 463 err_remove_handlers:
464 acpi_button_remove_notify_handlers(button);
465 err_remove_fs:
466 acpi_button_remove_fs(device);
467 err_free_input:
468 input_free_device(input);
469 err_free_button:
470 kfree(button);
471 return error;
395} 472}
396 473
397static int acpi_button_remove(struct acpi_device *device, int type) 474static int acpi_button_remove(struct acpi_device *device, int type)
398{ 475{
399 acpi_status status = 0; 476 struct acpi_button *button;
400 struct acpi_button *button = NULL;
401
402 477
403 if (!device || !acpi_driver_data(device)) 478 if (!device || !acpi_driver_data(device))
404 return -EINVAL; 479 return -EINVAL;
405 480
406 button = acpi_driver_data(device); 481 button = acpi_driver_data(device);
407 482
408 /* Unregister for device notifications. */ 483 acpi_button_remove_notify_handlers(button);
409 switch (button->type) {
410 case ACPI_BUTTON_TYPE_POWERF:
411 status =
412 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
413 acpi_button_notify_fixed);
414 break;
415 case ACPI_BUTTON_TYPE_SLEEPF:
416 status =
417 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
418 acpi_button_notify_fixed);
419 break;
420 default:
421 status = acpi_remove_notify_handler(device->handle,
422 ACPI_DEVICE_NOTIFY,
423 acpi_button_notify);
424 break;
425 }
426
427 acpi_button_remove_fs(device); 484 acpi_button_remove_fs(device);
428 485 input_unregister_device(button->input);
429 kfree(button); 486 kfree(button);
430 487
431 return 0; 488 return 0;
@@ -433,8 +490,7 @@ static int acpi_button_remove(struct acpi_device *device, int type)
433 490
434static int __init acpi_button_init(void) 491static int __init acpi_button_init(void)
435{ 492{
436 int result = 0; 493 int result;
437
438 494
439 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir); 495 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir);
440 if (!acpi_button_dir) 496 if (!acpi_button_dir)
@@ -451,7 +507,6 @@ static int __init acpi_button_init(void)
451 507
452static void __exit acpi_button_exit(void) 508static void __exit acpi_button_exit(void)
453{ 509{
454
455 acpi_bus_unregister_driver(&acpi_button_driver); 510 acpi_bus_unregister_driver(&acpi_button_driver);
456 511
457 if (acpi_power_dir) 512 if (acpi_power_dir)
@@ -461,8 +516,6 @@ static void __exit acpi_button_exit(void)
461 if (acpi_lid_dir) 516 if (acpi_lid_dir)
462 remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir); 517 remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
463 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); 518 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
464
465 return;
466} 519}
467 520
468module_init(acpi_button_init); 521module_init(acpi_button_init);
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 914f56ae4b..69a68fd394 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -96,11 +96,10 @@ static int acpi_container_add(struct acpi_device *device)
96 return -EINVAL; 96 return -EINVAL;
97 } 97 }
98 98
99 container = kmalloc(sizeof(struct acpi_container), GFP_KERNEL); 99 container = kzalloc(sizeof(struct acpi_container), GFP_KERNEL);
100 if (!container) 100 if (!container)
101 return -ENOMEM; 101 return -ENOMEM;
102 102
103 memset(container, 0, sizeof(struct acpi_container));
104 container->handle = device->handle; 103 container->handle = device->handle;
105 strcpy(acpi_device_name(device), ACPI_CONTAINER_DEVICE_NAME); 104 strcpy(acpi_device_name(device), ACPI_CONTAINER_DEVICE_NAME);
106 strcpy(acpi_device_class(device), ACPI_CONTAINER_CLASS); 105 strcpy(acpi_device_class(device), ACPI_CONTAINER_CLASS);
@@ -117,7 +116,7 @@ static int acpi_container_remove(struct acpi_device *device, int type)
117 acpi_status status = AE_OK; 116 acpi_status status = AE_OK;
118 struct acpi_container *pc = NULL; 117 struct acpi_container *pc = NULL;
119 118
120 pc = (struct acpi_container *)acpi_driver_data(device); 119 pc = acpi_driver_data(device);
121 kfree(pc); 120 kfree(pc);
122 return status; 121 return status;
123} 122}
diff --git a/drivers/acpi/dispatcher/dsfield.c b/drivers/acpi/dispatcher/dsfield.c
index a6d77efb41..f049639bac 100644
--- a/drivers/acpi/dispatcher/dsfield.c
+++ b/drivers/acpi/dispatcher/dsfield.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -133,7 +133,8 @@ acpi_ds_create_buffer_field(union acpi_parse_object *op,
133 } 133 }
134 } 134 }
135 135
136 /* We could put the returned object (Node) on the object stack for later, 136 /*
137 * We could put the returned object (Node) on the object stack for later,
137 * but for now, we will put it in the "op" object that the parser uses, 138 * but for now, we will put it in the "op" object that the parser uses,
138 * so we can get it again at the end of this scope 139 * so we can get it again at the end of this scope
139 */ 140 */
@@ -514,8 +515,33 @@ acpi_ds_create_bank_field(union acpi_parse_object *op,
514 515
515 /* Third arg is the bank_value */ 516 /* Third arg is the bank_value */
516 517
518 /* TBD: This arg is a term_arg, not a constant, and must be evaluated */
519
517 arg = arg->common.next; 520 arg = arg->common.next;
518 info.bank_value = (u32) arg->common.value.integer; 521
522 /* Currently, only the following constants are supported */
523
524 switch (arg->common.aml_opcode) {
525 case AML_ZERO_OP:
526 info.bank_value = 0;
527 break;
528
529 case AML_ONE_OP:
530 info.bank_value = 1;
531 break;
532
533 case AML_BYTE_OP:
534 case AML_WORD_OP:
535 case AML_DWORD_OP:
536 case AML_QWORD_OP:
537 info.bank_value = (u32) arg->common.value.integer;
538 break;
539
540 default:
541 info.bank_value = 0;
542 ACPI_ERROR((AE_INFO,
543 "Non-constant BankValue for BankField is not implemented"));
544 }
519 545
520 /* Fourth arg is the field flags */ 546 /* Fourth arg is the field flags */
521 547
diff --git a/drivers/acpi/dispatcher/dsinit.c b/drivers/acpi/dispatcher/dsinit.c
index 1888c055d1..af923c3885 100644
--- a/drivers/acpi/dispatcher/dsinit.c
+++ b/drivers/acpi/dispatcher/dsinit.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
44#include <acpi/acpi.h> 44#include <acpi/acpi.h>
45#include <acpi/acdispat.h> 45#include <acpi/acdispat.h>
46#include <acpi/acnamesp.h> 46#include <acpi/acnamesp.h>
47#include <acpi/actables.h>
47 48
48#define _COMPONENT ACPI_DISPATCHER 49#define _COMPONENT ACPI_DISPATCHER
49ACPI_MODULE_NAME("dsinit") 50ACPI_MODULE_NAME("dsinit")
@@ -90,7 +91,7 @@ acpi_ds_init_one_object(acpi_handle obj_handle,
90 * We are only interested in NS nodes owned by the table that 91 * We are only interested in NS nodes owned by the table that
91 * was just loaded 92 * was just loaded
92 */ 93 */
93 if (node->owner_id != info->table_desc->owner_id) { 94 if (node->owner_id != info->owner_id) {
94 return (AE_OK); 95 return (AE_OK);
95 } 96 }
96 97
@@ -150,14 +151,21 @@ acpi_ds_init_one_object(acpi_handle obj_handle,
150 ******************************************************************************/ 151 ******************************************************************************/
151 152
152acpi_status 153acpi_status
153acpi_ds_initialize_objects(struct acpi_table_desc * table_desc, 154acpi_ds_initialize_objects(acpi_native_uint table_index,
154 struct acpi_namespace_node * start_node) 155 struct acpi_namespace_node * start_node)
155{ 156{
156 acpi_status status; 157 acpi_status status;
157 struct acpi_init_walk_info info; 158 struct acpi_init_walk_info info;
159 struct acpi_table_header *table;
160 acpi_owner_id owner_id;
158 161
159 ACPI_FUNCTION_TRACE(ds_initialize_objects); 162 ACPI_FUNCTION_TRACE(ds_initialize_objects);
160 163
164 status = acpi_tb_get_owner_id(table_index, &owner_id);
165 if (ACPI_FAILURE(status)) {
166 return_ACPI_STATUS(status);
167 }
168
161 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 169 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
162 "**** Starting initialization of namespace objects ****\n")); 170 "**** Starting initialization of namespace objects ****\n"));
163 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Parsing all Control Methods:")); 171 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Parsing all Control Methods:"));
@@ -166,7 +174,8 @@ acpi_ds_initialize_objects(struct acpi_table_desc * table_desc,
166 info.op_region_count = 0; 174 info.op_region_count = 0;
167 info.object_count = 0; 175 info.object_count = 0;
168 info.device_count = 0; 176 info.device_count = 0;
169 info.table_desc = table_desc; 177 info.table_index = table_index;
178 info.owner_id = owner_id;
170 179
171 /* Walk entire namespace from the supplied root */ 180 /* Walk entire namespace from the supplied root */
172 181
@@ -176,10 +185,14 @@ acpi_ds_initialize_objects(struct acpi_table_desc * table_desc,
176 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); 185 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
177 } 186 }
178 187
188 status = acpi_get_table_by_index(table_index, &table);
189 if (ACPI_FAILURE(status)) {
190 return_ACPI_STATUS(status);
191 }
192
179 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 193 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
180 "\nTable [%4.4s](id %4.4X) - %hd Objects with %hd Devices %hd Methods %hd Regions\n", 194 "\nTable [%4.4s](id %4.4X) - %hd Objects with %hd Devices %hd Methods %hd Regions\n",
181 table_desc->pointer->signature, 195 table->signature, owner_id, info.object_count,
182 table_desc->owner_id, info.object_count,
183 info.device_count, info.method_count, 196 info.device_count, info.method_count,
184 info.op_region_count)); 197 info.op_region_count));
185 198
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index cf888add31..1cbe619058 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -327,7 +327,7 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
327 ACPI_FUNCTION_TRACE_PTR(ds_call_control_method, this_walk_state); 327 ACPI_FUNCTION_TRACE_PTR(ds_call_control_method, this_walk_state);
328 328
329 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 329 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
330 "Execute method %p, currentstate=%p\n", 330 "Calling method %p, currentstate=%p\n",
331 this_walk_state->prev_op, this_walk_state)); 331 this_walk_state->prev_op, this_walk_state));
332 332
333 /* 333 /*
@@ -351,49 +351,7 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
351 return_ACPI_STATUS(status); 351 return_ACPI_STATUS(status);
352 } 352 }
353 353
354 /* 354 /* Begin method parse/execution. Create a new walk state */
355 * 1) Parse the method. All "normal" methods are parsed for each execution.
356 * Internal methods (_OSI, etc.) do not require parsing.
357 */
358 if (!(obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY)) {
359
360 /* Create a new walk state for the parse */
361
362 next_walk_state =
363 acpi_ds_create_walk_state(obj_desc->method.owner_id, op,
364 obj_desc, NULL);
365 if (!next_walk_state) {
366 status = AE_NO_MEMORY;
367 goto cleanup;
368 }
369
370 /* Create and init a parse tree root */
371
372 op = acpi_ps_create_scope_op();
373 if (!op) {
374 status = AE_NO_MEMORY;
375 goto cleanup;
376 }
377
378 status = acpi_ds_init_aml_walk(next_walk_state, op, method_node,
379 obj_desc->method.aml_start,
380 obj_desc->method.aml_length,
381 NULL, 1);
382 if (ACPI_FAILURE(status)) {
383 acpi_ps_delete_parse_tree(op);
384 goto cleanup;
385 }
386
387 /* Begin AML parse (deletes next_walk_state) */
388
389 status = acpi_ps_parse_aml(next_walk_state);
390 acpi_ps_delete_parse_tree(op);
391 if (ACPI_FAILURE(status)) {
392 goto cleanup;
393 }
394 }
395
396 /* 2) Begin method execution. Create a new walk state */
397 355
398 next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id, 356 next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id,
399 NULL, obj_desc, thread); 357 NULL, obj_desc, thread);
@@ -424,7 +382,8 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
424 382
425 status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node, 383 status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node,
426 obj_desc->method.aml_start, 384 obj_desc->method.aml_start,
427 obj_desc->method.aml_length, info, 3); 385 obj_desc->method.aml_length, info,
386 ACPI_IMODE_EXECUTE);
428 387
429 ACPI_FREE(info); 388 ACPI_FREE(info);
430 if (ACPI_FAILURE(status)) { 389 if (ACPI_FAILURE(status)) {
@@ -445,8 +404,8 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
445 this_walk_state->num_operands = 0; 404 this_walk_state->num_operands = 0;
446 405
447 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 406 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
448 "Starting nested execution, newstate=%p\n", 407 "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
449 next_walk_state)); 408 method_node->name.ascii, next_walk_state));
450 409
451 /* Invoke an internal method if necessary */ 410 /* Invoke an internal method if necessary */
452 411
diff --git a/drivers/acpi/dispatcher/dsmthdat.c b/drivers/acpi/dispatcher/dsmthdat.c
index 459160ff90..ba4626e06a 100644
--- a/drivers/acpi/dispatcher/dsmthdat.c
+++ b/drivers/acpi/dispatcher/dsmthdat.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/dispatcher/dsobject.c b/drivers/acpi/dispatcher/dsobject.c
index 72190abb1d..a474ca2334 100644
--- a/drivers/acpi/dispatcher/dsobject.c
+++ b/drivers/acpi/dispatcher/dsobject.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -260,7 +260,7 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
260 } 260 }
261 261
262 obj_desc->buffer.flags |= AOPOBJ_DATA_VALID; 262 obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
263 op->common.node = (struct acpi_namespace_node *)obj_desc; 263 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
264 return_ACPI_STATUS(AE_OK); 264 return_ACPI_STATUS(AE_OK);
265} 265}
266 266
@@ -270,7 +270,8 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
270 * 270 *
271 * PARAMETERS: walk_state - Current walk state 271 * PARAMETERS: walk_state - Current walk state
272 * Op - Parser object to be translated 272 * Op - Parser object to be translated
273 * package_length - Number of elements in the package 273 * element_count - Number of elements in the package - this is
274 * the num_elements argument to Package()
274 * obj_desc_ptr - Where the ACPI internal object is returned 275 * obj_desc_ptr - Where the ACPI internal object is returned
275 * 276 *
276 * RETURN: Status 277 * RETURN: Status
@@ -278,18 +279,29 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
278 * DESCRIPTION: Translate a parser Op package object to the equivalent 279 * DESCRIPTION: Translate a parser Op package object to the equivalent
279 * namespace object 280 * namespace object
280 * 281 *
282 * NOTE: The number of elements in the package will be always be the num_elements
283 * count, regardless of the number of elements in the package list. If
284 * num_elements is smaller, only that many package list elements are used.
285 * if num_elements is larger, the Package object is padded out with
286 * objects of type Uninitialized (as per ACPI spec.)
287 *
288 * Even though the ASL compilers do not allow num_elements to be smaller
289 * than the Package list length (for the fixed length package opcode), some
290 * BIOS code modifies the AML on the fly to adjust the num_elements, and
291 * this code compensates for that. This also provides compatibility with
292 * other AML interpreters.
293 *
281 ******************************************************************************/ 294 ******************************************************************************/
282 295
283acpi_status 296acpi_status
284acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state, 297acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
285 union acpi_parse_object *op, 298 union acpi_parse_object *op,
286 u32 package_length, 299 u32 element_count,
287 union acpi_operand_object **obj_desc_ptr) 300 union acpi_operand_object **obj_desc_ptr)
288{ 301{
289 union acpi_parse_object *arg; 302 union acpi_parse_object *arg;
290 union acpi_parse_object *parent; 303 union acpi_parse_object *parent;
291 union acpi_operand_object *obj_desc = NULL; 304 union acpi_operand_object *obj_desc = NULL;
292 u32 package_list_length;
293 acpi_status status = AE_OK; 305 acpi_status status = AE_OK;
294 acpi_native_uint i; 306 acpi_native_uint i;
295 307
@@ -318,32 +330,13 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
318 obj_desc->package.node = parent->common.node; 330 obj_desc->package.node = parent->common.node;
319 } 331 }
320 332
321 obj_desc->package.count = package_length;
322
323 /* Count the number of items in the package list */
324
325 arg = op->common.value.arg;
326 arg = arg->common.next;
327 for (package_list_length = 0; arg; package_list_length++) {
328 arg = arg->common.next;
329 }
330
331 /*
332 * The package length (number of elements) will be the greater
333 * of the specified length and the length of the initializer list
334 */
335 if (package_list_length > package_length) {
336 obj_desc->package.count = package_list_length;
337 }
338
339 /* 333 /*
340 * Allocate the pointer array (array of pointers to the 334 * Allocate the element array (array of pointers to the individual
341 * individual objects). Add an extra pointer slot so 335 * objects) based on the num_elements parameter. Add an extra pointer slot
342 * that the list is always null terminated. 336 * so that the list is always null terminated.
343 */ 337 */
344 obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size) 338 obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
345 obj_desc->package. 339 element_count +
346 count +
347 1) * sizeof(void *)); 340 1) * sizeof(void *));
348 341
349 if (!obj_desc->package.elements) { 342 if (!obj_desc->package.elements) {
@@ -351,15 +344,20 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
351 return_ACPI_STATUS(AE_NO_MEMORY); 344 return_ACPI_STATUS(AE_NO_MEMORY);
352 } 345 }
353 346
347 obj_desc->package.count = element_count;
348
354 /* 349 /*
355 * Initialize all elements of the package 350 * Initialize the elements of the package, up to the num_elements count.
351 * Package is automatically padded with uninitialized (NULL) elements
352 * if num_elements is greater than the package list length. Likewise,
353 * Package is truncated if num_elements is less than the list length.
356 */ 354 */
357 arg = op->common.value.arg; 355 arg = op->common.value.arg;
358 arg = arg->common.next; 356 arg = arg->common.next;
359 for (i = 0; arg; i++) { 357 for (i = 0; arg && (i < element_count); i++) {
360 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { 358 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
361 359
362 /* Object (package or buffer) is already built */ 360 /* This package element is already built, just get it */
363 361
364 obj_desc->package.elements[i] = 362 obj_desc->package.elements[i] =
365 ACPI_CAST_PTR(union acpi_operand_object, 363 ACPI_CAST_PTR(union acpi_operand_object,
@@ -373,8 +371,14 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
373 arg = arg->common.next; 371 arg = arg->common.next;
374 } 372 }
375 373
374 if (!arg) {
375 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
376 "Package List length larger than NumElements count (%X), truncated\n",
377 element_count));
378 }
379
376 obj_desc->package.flags |= AOPOBJ_DATA_VALID; 380 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
377 op->common.node = (struct acpi_namespace_node *)obj_desc; 381 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
378 return_ACPI_STATUS(status); 382 return_ACPI_STATUS(status);
379} 383}
380 384
@@ -488,8 +492,9 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
488 /* 492 /*
489 * Defer evaluation of Buffer term_arg operand 493 * Defer evaluation of Buffer term_arg operand
490 */ 494 */
491 obj_desc->buffer.node = (struct acpi_namespace_node *) 495 obj_desc->buffer.node =
492 walk_state->operands[0]; 496 ACPI_CAST_PTR(struct acpi_namespace_node,
497 walk_state->operands[0]);
493 obj_desc->buffer.aml_start = op->named.data; 498 obj_desc->buffer.aml_start = op->named.data;
494 obj_desc->buffer.aml_length = op->named.length; 499 obj_desc->buffer.aml_length = op->named.length;
495 break; 500 break;
@@ -499,8 +504,9 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
499 /* 504 /*
500 * Defer evaluation of Package term_arg operand 505 * Defer evaluation of Package term_arg operand
501 */ 506 */
502 obj_desc->package.node = (struct acpi_namespace_node *) 507 obj_desc->package.node =
503 walk_state->operands[0]; 508 ACPI_CAST_PTR(struct acpi_namespace_node,
509 walk_state->operands[0]);
504 obj_desc->package.aml_start = op->named.data; 510 obj_desc->package.aml_start = op->named.data;
505 obj_desc->package.aml_length = op->named.length; 511 obj_desc->package.aml_length = op->named.length;
506 break; 512 break;
diff --git a/drivers/acpi/dispatcher/dsopcode.c b/drivers/acpi/dispatcher/dsopcode.c
index 5b974a8fe6..6c6104a7a2 100644
--- a/drivers/acpi/dispatcher/dsopcode.c
+++ b/drivers/acpi/dispatcher/dsopcode.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -114,7 +114,7 @@ acpi_ds_execute_arguments(struct acpi_namespace_node *node,
114 } 114 }
115 115
116 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start, 116 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
117 aml_length, NULL, 1); 117 aml_length, NULL, ACPI_IMODE_LOAD_PASS1);
118 if (ACPI_FAILURE(status)) { 118 if (ACPI_FAILURE(status)) {
119 acpi_ds_delete_walk_state(walk_state); 119 acpi_ds_delete_walk_state(walk_state);
120 goto cleanup; 120 goto cleanup;
@@ -157,7 +157,7 @@ acpi_ds_execute_arguments(struct acpi_namespace_node *node,
157 /* Execute the opcode and arguments */ 157 /* Execute the opcode and arguments */
158 158
159 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start, 159 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
160 aml_length, NULL, 3); 160 aml_length, NULL, ACPI_IMODE_EXECUTE);
161 if (ACPI_FAILURE(status)) { 161 if (ACPI_FAILURE(status)) {
162 acpi_ds_delete_walk_state(walk_state); 162 acpi_ds_delete_walk_state(walk_state);
163 goto cleanup; 163 goto cleanup;
diff --git a/drivers/acpi/dispatcher/dsutils.c b/drivers/acpi/dispatcher/dsutils.c
index 05230baf5d..e4073e05a7 100644
--- a/drivers/acpi/dispatcher/dsutils.c
+++ b/drivers/acpi/dispatcher/dsutils.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/dispatcher/dswexec.c b/drivers/acpi/dispatcher/dswexec.c
index d7a616c310..69693fa072 100644
--- a/drivers/acpi/dispatcher/dswexec.c
+++ b/drivers/acpi/dispatcher/dswexec.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -219,7 +219,7 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
219 if (!op) { 219 if (!op) {
220 status = acpi_ds_load2_begin_op(walk_state, out_op); 220 status = acpi_ds_load2_begin_op(walk_state, out_op);
221 if (ACPI_FAILURE(status)) { 221 if (ACPI_FAILURE(status)) {
222 return_ACPI_STATUS(status); 222 goto error_exit;
223 } 223 }
224 224
225 op = *out_op; 225 op = *out_op;
@@ -238,7 +238,7 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
238 238
239 status = acpi_ds_scope_stack_pop(walk_state); 239 status = acpi_ds_scope_stack_pop(walk_state);
240 if (ACPI_FAILURE(status)) { 240 if (ACPI_FAILURE(status)) {
241 return_ACPI_STATUS(status); 241 goto error_exit;
242 } 242 }
243 } 243 }
244 } 244 }
@@ -287,7 +287,7 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
287 287
288 status = acpi_ds_result_stack_push(walk_state); 288 status = acpi_ds_result_stack_push(walk_state);
289 if (ACPI_FAILURE(status)) { 289 if (ACPI_FAILURE(status)) {
290 return_ACPI_STATUS(status); 290 goto error_exit;
291 } 291 }
292 292
293 status = acpi_ds_exec_begin_control_op(walk_state, op); 293 status = acpi_ds_exec_begin_control_op(walk_state, op);
@@ -328,6 +328,10 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
328 /* Nothing to do here during method execution */ 328 /* Nothing to do here during method execution */
329 329
330 return_ACPI_STATUS(status); 330 return_ACPI_STATUS(status);
331
332 error_exit:
333 status = acpi_ds_method_error(status, walk_state);
334 return_ACPI_STATUS(status);
331} 335}
332 336
333/***************************************************************************** 337/*****************************************************************************
diff --git a/drivers/acpi/dispatcher/dswload.c b/drivers/acpi/dispatcher/dswload.c
index e3ca7f6539..8ab9d1b29a 100644
--- a/drivers/acpi/dispatcher/dswload.c
+++ b/drivers/acpi/dispatcher/dswload.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -196,6 +196,7 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
196 * one of the opcodes that actually opens a scope 196 * one of the opcodes that actually opens a scope
197 */ 197 */
198 switch (node->type) { 198 switch (node->type) {
199 case ACPI_TYPE_ANY:
199 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */ 200 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
200 case ACPI_TYPE_DEVICE: 201 case ACPI_TYPE_DEVICE:
201 case ACPI_TYPE_POWER: 202 case ACPI_TYPE_POWER:
@@ -546,6 +547,7 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
546 acpi_status status; 547 acpi_status status;
547 acpi_object_type object_type; 548 acpi_object_type object_type;
548 char *buffer_ptr; 549 char *buffer_ptr;
550 u32 flags;
549 551
550 ACPI_FUNCTION_TRACE(ds_load2_begin_op); 552 ACPI_FUNCTION_TRACE(ds_load2_begin_op);
551 553
@@ -669,6 +671,7 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
669 * one of the opcodes that actually opens a scope 671 * one of the opcodes that actually opens a scope
670 */ 672 */
671 switch (node->type) { 673 switch (node->type) {
674 case ACPI_TYPE_ANY:
672 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */ 675 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
673 case ACPI_TYPE_DEVICE: 676 case ACPI_TYPE_DEVICE:
674 case ACPI_TYPE_POWER: 677 case ACPI_TYPE_POWER:
@@ -750,12 +753,20 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
750 break; 753 break;
751 } 754 }
752 755
753 /* Add new entry into namespace */ 756 flags = ACPI_NS_NO_UPSEARCH;
757 if (walk_state->pass_number == ACPI_IMODE_EXECUTE) {
758
759 /* Execution mode, node cannot already exist, node is temporary */
760
761 flags |= (ACPI_NS_ERROR_IF_FOUND | ACPI_NS_TEMPORARY);
762 }
763
764 /* Add new entry or lookup existing entry */
754 765
755 status = 766 status =
756 acpi_ns_lookup(walk_state->scope_info, buffer_ptr, 767 acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
757 object_type, ACPI_IMODE_LOAD_PASS2, 768 object_type, ACPI_IMODE_LOAD_PASS2, flags,
758 ACPI_NS_NO_UPSEARCH, walk_state, &(node)); 769 walk_state, &node);
759 break; 770 break;
760 } 771 }
761 772
diff --git a/drivers/acpi/dispatcher/dswscope.c b/drivers/acpi/dispatcher/dswscope.c
index c9228972f5..3927c495e4 100644
--- a/drivers/acpi/dispatcher/dswscope.c
+++ b/drivers/acpi/dispatcher/dswscope.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/dispatcher/dswstate.c b/drivers/acpi/dispatcher/dswstate.c
index 7817e55226..16c8e38b51 100644
--- a/drivers/acpi/dispatcher/dswstate.c
+++ b/drivers/acpi/dispatcher/dswstate.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index bf5b79ed36..688e83a169 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -27,6 +27,7 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/notifier.h> 29#include <linux/notifier.h>
30#include <linux/platform_device.h>
30#include <linux/jiffies.h> 31#include <linux/jiffies.h>
31#include <acpi/acpi_bus.h> 32#include <acpi/acpi_bus.h>
32#include <acpi/acpi_drivers.h> 33#include <acpi/acpi_drivers.h>
@@ -39,13 +40,15 @@ MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_NAME);
39MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
40 41
41static struct atomic_notifier_head dock_notifier_list; 42static struct atomic_notifier_head dock_notifier_list;
43static struct platform_device dock_device;
44static char dock_device_name[] = "dock";
42 45
43struct dock_station { 46struct dock_station {
44 acpi_handle handle; 47 acpi_handle handle;
45 unsigned long last_dock_time; 48 unsigned long last_dock_time;
46 u32 flags; 49 u32 flags;
47 spinlock_t dd_lock; 50 spinlock_t dd_lock;
48 spinlock_t hp_lock; 51 struct mutex hp_lock;
49 struct list_head dependent_devices; 52 struct list_head dependent_devices;
50 struct list_head hotplug_devices; 53 struct list_head hotplug_devices;
51}; 54};
@@ -115,9 +118,9 @@ static void
115dock_add_hotplug_device(struct dock_station *ds, 118dock_add_hotplug_device(struct dock_station *ds,
116 struct dock_dependent_device *dd) 119 struct dock_dependent_device *dd)
117{ 120{
118 spin_lock(&ds->hp_lock); 121 mutex_lock(&ds->hp_lock);
119 list_add_tail(&dd->hotplug_list, &ds->hotplug_devices); 122 list_add_tail(&dd->hotplug_list, &ds->hotplug_devices);
120 spin_unlock(&ds->hp_lock); 123 mutex_unlock(&ds->hp_lock);
121} 124}
122 125
123/** 126/**
@@ -131,9 +134,9 @@ static void
131dock_del_hotplug_device(struct dock_station *ds, 134dock_del_hotplug_device(struct dock_station *ds,
132 struct dock_dependent_device *dd) 135 struct dock_dependent_device *dd)
133{ 136{
134 spin_lock(&ds->hp_lock); 137 mutex_lock(&ds->hp_lock);
135 list_del(&dd->hotplug_list); 138 list_del(&dd->hotplug_list);
136 spin_unlock(&ds->hp_lock); 139 mutex_unlock(&ds->hp_lock);
137} 140}
138 141
139/** 142/**
@@ -296,7 +299,7 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event)
296{ 299{
297 struct dock_dependent_device *dd; 300 struct dock_dependent_device *dd;
298 301
299 spin_lock(&ds->hp_lock); 302 mutex_lock(&ds->hp_lock);
300 303
301 /* 304 /*
302 * First call driver specific hotplug functions 305 * First call driver specific hotplug functions
@@ -318,15 +321,17 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event)
318 else 321 else
319 dock_create_acpi_device(dd->handle); 322 dock_create_acpi_device(dd->handle);
320 } 323 }
321 spin_unlock(&ds->hp_lock); 324 mutex_unlock(&ds->hp_lock);
322} 325}
323 326
324static void dock_event(struct dock_station *ds, u32 event, int num) 327static void dock_event(struct dock_station *ds, u32 event, int num)
325{ 328{
329 struct device *dev = &dock_device.dev;
326 /* 330 /*
327 * we don't do events until someone tells me that 331 * Indicate that the status of the dock station has
328 * they would like to have them. 332 * changed.
329 */ 333 */
334 kobject_uevent(&dev->kobj, KOBJ_CHANGE);
330} 335}
331 336
332/** 337/**
@@ -441,6 +446,9 @@ static int dock_in_progress(struct dock_station *ds)
441 */ 446 */
442int register_dock_notifier(struct notifier_block *nb) 447int register_dock_notifier(struct notifier_block *nb)
443{ 448{
449 if (!dock_station)
450 return -ENODEV;
451
444 return atomic_notifier_chain_register(&dock_notifier_list, nb); 452 return atomic_notifier_chain_register(&dock_notifier_list, nb);
445} 453}
446 454
@@ -452,6 +460,9 @@ EXPORT_SYMBOL_GPL(register_dock_notifier);
452 */ 460 */
453void unregister_dock_notifier(struct notifier_block *nb) 461void unregister_dock_notifier(struct notifier_block *nb)
454{ 462{
463 if (!dock_station)
464 return;
465
455 atomic_notifier_chain_unregister(&dock_notifier_list, nb); 466 atomic_notifier_chain_unregister(&dock_notifier_list, nb);
456} 467}
457 468
@@ -512,6 +523,37 @@ void unregister_hotplug_dock_device(acpi_handle handle)
512EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device); 523EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device);
513 524
514/** 525/**
526 * handle_eject_request - handle an undock request checking for error conditions
527 *
528 * Check to make sure the dock device is still present, then undock and
529 * hotremove all the devices that may need removing.
530 */
531static int handle_eject_request(struct dock_station *ds, u32 event)
532{
533 if (!dock_present(ds))
534 return -ENODEV;
535
536 if (dock_in_progress(ds))
537 return -EBUSY;
538
539 /*
540 * here we need to generate the undock
541 * event prior to actually doing the undock
542 * so that the device struct still exists.
543 */
544 dock_event(ds, event, UNDOCK_EVENT);
545 hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST);
546 undock(ds);
547 eject_dock(ds);
548 if (dock_present(ds)) {
549 printk(KERN_ERR PREFIX "Unable to undock!\n");
550 return -EBUSY;
551 }
552
553 return 0;
554}
555
556/**
515 * dock_notify - act upon an acpi dock notification 557 * dock_notify - act upon an acpi dock notification
516 * @handle: the dock station handle 558 * @handle: the dock station handle
517 * @event: the acpi event 559 * @event: the acpi event
@@ -519,13 +561,11 @@ EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device);
519 * 561 *
520 * If we are notified to dock, then check to see if the dock is 562 * If we are notified to dock, then check to see if the dock is
521 * present and then dock. Notify all drivers of the dock event, 563 * present and then dock. Notify all drivers of the dock event,
522 * and then hotplug and devices that may need hotplugging. For undock 564 * and then hotplug and devices that may need hotplugging.
523 * check to make sure the dock device is still present, then undock
524 * and hotremove all the devices that may need removing.
525 */ 565 */
526static void dock_notify(acpi_handle handle, u32 event, void *data) 566static void dock_notify(acpi_handle handle, u32 event, void *data)
527{ 567{
528 struct dock_station *ds = (struct dock_station *)data; 568 struct dock_station *ds = data;
529 569
530 switch (event) { 570 switch (event) {
531 case ACPI_NOTIFY_BUS_CHECK: 571 case ACPI_NOTIFY_BUS_CHECK:
@@ -553,19 +593,7 @@ static void dock_notify(acpi_handle handle, u32 event, void *data)
553 * to the driver who wish to hotplug. 593 * to the driver who wish to hotplug.
554 */ 594 */
555 case ACPI_NOTIFY_EJECT_REQUEST: 595 case ACPI_NOTIFY_EJECT_REQUEST:
556 if (!dock_in_progress(ds) && dock_present(ds)) { 596 handle_eject_request(ds, event);
557 /*
558 * here we need to generate the undock
559 * event prior to actually doing the undock
560 * so that the device struct still exists.
561 */
562 dock_event(ds, event, UNDOCK_EVENT);
563 hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST);
564 undock(ds);
565 eject_dock(ds);
566 if (dock_present(ds))
567 printk(KERN_ERR PREFIX "Unable to undock!\n");
568 }
569 break; 597 break;
570 default: 598 default:
571 printk(KERN_ERR PREFIX "Unknown dock event %d\n", event); 599 printk(KERN_ERR PREFIX "Unknown dock event %d\n", event);
@@ -587,23 +615,58 @@ static acpi_status
587find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv) 615find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv)
588{ 616{
589 acpi_status status; 617 acpi_status status;
590 acpi_handle tmp; 618 acpi_handle tmp, parent;
591 struct dock_station *ds = (struct dock_station *)context; 619 struct dock_station *ds = context;
592 struct dock_dependent_device *dd; 620 struct dock_dependent_device *dd;
593 621
594 status = acpi_bus_get_ejd(handle, &tmp); 622 status = acpi_bus_get_ejd(handle, &tmp);
595 if (ACPI_FAILURE(status)) 623 if (ACPI_FAILURE(status)) {
596 return AE_OK; 624 /* try the parent device as well */
625 status = acpi_get_parent(handle, &parent);
626 if (ACPI_FAILURE(status))
627 goto fdd_out;
628 /* see if parent is dependent on dock */
629 status = acpi_bus_get_ejd(parent, &tmp);
630 if (ACPI_FAILURE(status))
631 goto fdd_out;
632 }
597 633
598 if (tmp == ds->handle) { 634 if (tmp == ds->handle) {
599 dd = alloc_dock_dependent_device(handle); 635 dd = alloc_dock_dependent_device(handle);
600 if (dd) 636 if (dd)
601 add_dock_dependent_device(ds, dd); 637 add_dock_dependent_device(ds, dd);
602 } 638 }
603 639fdd_out:
604 return AE_OK; 640 return AE_OK;
605} 641}
606 642
643/*
644 * show_docked - read method for "docked" file in sysfs
645 */
646static ssize_t show_docked(struct device *dev,
647 struct device_attribute *attr, char *buf)
648{
649 return snprintf(buf, PAGE_SIZE, "%d\n", dock_present(dock_station));
650
651}
652DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
653
654/*
655 * write_undock - write method for "undock" file in sysfs
656 */
657static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
658 const char *buf, size_t count)
659{
660 int ret;
661
662 if (!count)
663 return -EINVAL;
664
665 ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST);
666 return ret ? ret: count;
667}
668DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
669
607/** 670/**
608 * dock_add - add a new dock station 671 * dock_add - add a new dock station
609 * @handle: the dock station handle 672 * @handle: the dock station handle
@@ -626,9 +689,33 @@ static int dock_add(acpi_handle handle)
626 INIT_LIST_HEAD(&dock_station->dependent_devices); 689 INIT_LIST_HEAD(&dock_station->dependent_devices);
627 INIT_LIST_HEAD(&dock_station->hotplug_devices); 690 INIT_LIST_HEAD(&dock_station->hotplug_devices);
628 spin_lock_init(&dock_station->dd_lock); 691 spin_lock_init(&dock_station->dd_lock);
629 spin_lock_init(&dock_station->hp_lock); 692 mutex_init(&dock_station->hp_lock);
630 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list); 693 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
631 694
695 /* initialize platform device stuff */
696 dock_device.name = dock_device_name;
697 ret = platform_device_register(&dock_device);
698 if (ret) {
699 printk(KERN_ERR PREFIX "Error %d registering dock device\n", ret);
700 kfree(dock_station);
701 return ret;
702 }
703 ret = device_create_file(&dock_device.dev, &dev_attr_docked);
704 if (ret) {
705 printk("Error %d adding sysfs file\n", ret);
706 platform_device_unregister(&dock_device);
707 kfree(dock_station);
708 return ret;
709 }
710 ret = device_create_file(&dock_device.dev, &dev_attr_undock);
711 if (ret) {
712 printk("Error %d adding sysfs file\n", ret);
713 device_remove_file(&dock_device.dev, &dev_attr_docked);
714 platform_device_unregister(&dock_device);
715 kfree(dock_station);
716 return ret;
717 }
718
632 /* Find dependent devices */ 719 /* Find dependent devices */
633 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 720 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
634 ACPI_UINT32_MAX, find_dock_devices, dock_station, 721 ACPI_UINT32_MAX, find_dock_devices, dock_station,
@@ -638,7 +725,8 @@ static int dock_add(acpi_handle handle)
638 dd = alloc_dock_dependent_device(handle); 725 dd = alloc_dock_dependent_device(handle);
639 if (!dd) { 726 if (!dd) {
640 kfree(dock_station); 727 kfree(dock_station);
641 return -ENOMEM; 728 ret = -ENOMEM;
729 goto dock_add_err_unregister;
642 } 730 }
643 add_dock_dependent_device(dock_station, dd); 731 add_dock_dependent_device(dock_station, dd);
644 732
@@ -658,8 +746,12 @@ static int dock_add(acpi_handle handle)
658 return 0; 746 return 0;
659 747
660dock_add_err: 748dock_add_err:
661 kfree(dock_station);
662 kfree(dd); 749 kfree(dd);
750dock_add_err_unregister:
751 device_remove_file(&dock_device.dev, &dev_attr_docked);
752 device_remove_file(&dock_device.dev, &dev_attr_undock);
753 platform_device_unregister(&dock_device);
754 kfree(dock_station);
663 return ret; 755 return ret;
664} 756}
665 757
@@ -686,6 +778,11 @@ static int dock_remove(void)
686 if (ACPI_FAILURE(status)) 778 if (ACPI_FAILURE(status))
687 printk(KERN_ERR "Error removing notify handler\n"); 779 printk(KERN_ERR "Error removing notify handler\n");
688 780
781 /* cleanup sysfs */
782 device_remove_file(&dock_device.dev, &dev_attr_docked);
783 device_remove_file(&dock_device.dev, &dev_attr_undock);
784 platform_device_unregister(&dock_device);
785
689 /* free dock station memory */ 786 /* free dock station memory */
690 kfree(dock_station); 787 kfree(dock_station);
691 return 0; 788 return 0;
@@ -703,7 +800,7 @@ static int dock_remove(void)
703static acpi_status 800static acpi_status
704find_dock(acpi_handle handle, u32 lvl, void *context, void **rv) 801find_dock(acpi_handle handle, u32 lvl, void *context, void **rv)
705{ 802{
706 int *count = (int *)context; 803 int *count = context;
707 acpi_status status = AE_OK; 804 acpi_status status = AE_OK;
708 805
709 if (is_dock(handle)) { 806 if (is_dock(handle)) {
@@ -726,7 +823,7 @@ static int __init dock_init(void)
726 ACPI_UINT32_MAX, find_dock, &num, NULL); 823 ACPI_UINT32_MAX, find_dock, &num, NULL);
727 824
728 if (!num) 825 if (!num)
729 return -ENODEV; 826 printk(KERN_INFO "No dock devices found.\n");
730 827
731 return 0; 828 return 0;
732} 829}
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index e6d4b084dc..743ce27fa0 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -45,35 +45,34 @@ ACPI_MODULE_NAME("acpi_ec")
45#define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver" 45#define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
46#define ACPI_EC_DEVICE_NAME "Embedded Controller" 46#define ACPI_EC_DEVICE_NAME "Embedded Controller"
47#define ACPI_EC_FILE_INFO "info" 47#define ACPI_EC_FILE_INFO "info"
48 48#undef PREFIX
49#define PREFIX "ACPI: EC: "
49/* EC status register */ 50/* EC status register */
50#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ 51#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
51#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ 52#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
52#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ 53#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
53#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ 54#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
54
55/* EC commands */ 55/* EC commands */
56#define ACPI_EC_COMMAND_READ 0x80 56enum ec_command {
57#define ACPI_EC_COMMAND_WRITE 0x81 57 ACPI_EC_COMMAND_READ = 0x80,
58#define ACPI_EC_BURST_ENABLE 0x82 58 ACPI_EC_COMMAND_WRITE = 0x81,
59#define ACPI_EC_BURST_DISABLE 0x83 59 ACPI_EC_BURST_ENABLE = 0x82,
60#define ACPI_EC_COMMAND_QUERY 0x84 60 ACPI_EC_BURST_DISABLE = 0x83,
61 61 ACPI_EC_COMMAND_QUERY = 0x84,
62};
62/* EC events */ 63/* EC events */
63enum { 64enum ec_event {
64 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ 65 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
65 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */ 66 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
66}; 67};
67 68
68#define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */ 69#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
69#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 70#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
70#define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
71#define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
72 71
73enum { 72static enum ec_mode {
74 EC_INTR = 1, /* Output buffer full */ 73 EC_INTR = 1, /* Output buffer full */
75 EC_POLL, /* Input buffer empty */ 74 EC_POLL, /* Input buffer empty */
76}; 75} acpi_ec_mode = EC_INTR;
77 76
78static int acpi_ec_remove(struct acpi_device *device, int type); 77static int acpi_ec_remove(struct acpi_device *device, int type);
79static int acpi_ec_start(struct acpi_device *device); 78static int acpi_ec_start(struct acpi_device *device);
@@ -93,22 +92,21 @@ static struct acpi_driver acpi_ec_driver = {
93}; 92};
94 93
95/* If we find an EC via the ECDT, we need to keep a ptr to its context */ 94/* If we find an EC via the ECDT, we need to keep a ptr to its context */
96struct acpi_ec { 95static struct acpi_ec {
97 acpi_handle handle; 96 acpi_handle handle;
98 unsigned long uid; 97 unsigned long uid;
99 unsigned long gpe_bit; 98 unsigned long gpe;
100 unsigned long command_addr; 99 unsigned long command_addr;
101 unsigned long data_addr; 100 unsigned long data_addr;
102 unsigned long global_lock; 101 unsigned long global_lock;
103 struct semaphore sem; 102 struct mutex lock;
104 unsigned int expect_event; 103 atomic_t query_pending;
105 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */ 104 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */
106 wait_queue_head_t wait; 105 wait_queue_head_t wait;
107} *ec_ecdt; 106} *ec_ecdt;
108 107
109/* External interfaces use first EC only, so remember */ 108/* External interfaces use first EC only, so remember */
110static struct acpi_device *first_ec; 109static struct acpi_device *first_ec;
111static int acpi_ec_mode = EC_INTR;
112 110
113/* -------------------------------------------------------------------------- 111/* --------------------------------------------------------------------------
114 Transaction Management 112 Transaction Management
@@ -134,54 +132,41 @@ static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
134 outb(data, ec->data_addr); 132 outb(data, ec->data_addr);
135} 133}
136 134
137static int acpi_ec_check_status(u8 status, u8 event) 135static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
138{ 136{
139 switch (event) { 137 u8 status = acpi_ec_read_status(ec);
140 case ACPI_EC_EVENT_OBF_1: 138
139 if (event == ACPI_EC_EVENT_OBF_1) {
141 if (status & ACPI_EC_FLAG_OBF) 140 if (status & ACPI_EC_FLAG_OBF)
142 return 1; 141 return 1;
143 break; 142 } else if (event == ACPI_EC_EVENT_IBF_0) {
144 case ACPI_EC_EVENT_IBF_0:
145 if (!(status & ACPI_EC_FLAG_IBF)) 143 if (!(status & ACPI_EC_FLAG_IBF))
146 return 1; 144 return 1;
147 break;
148 default:
149 break;
150 } 145 }
151 146
152 return 0; 147 return 0;
153} 148}
154 149
155static int acpi_ec_wait(struct acpi_ec *ec, u8 event) 150static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event)
156{ 151{
157 int i = (acpi_ec_mode == EC_POLL) ? ACPI_EC_UDELAY_COUNT : 0; 152 if (acpi_ec_mode == EC_POLL) {
158 long time_left; 153 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
159 154 while (time_before(jiffies, delay)) {
160 ec->expect_event = event; 155 if (acpi_ec_check_status(ec, event))
161 if (acpi_ec_check_status(acpi_ec_read_status(ec), event)) {
162 ec->expect_event = 0;
163 return 0;
164 }
165
166 do {
167 if (acpi_ec_mode == EC_POLL) {
168 udelay(ACPI_EC_UDELAY);
169 } else {
170 time_left = wait_event_timeout(ec->wait,
171 !ec->expect_event,
172 msecs_to_jiffies(ACPI_EC_DELAY));
173 if (time_left > 0) {
174 ec->expect_event = 0;
175 return 0; 156 return 0;
176 }
177 } 157 }
178 if (acpi_ec_check_status(acpi_ec_read_status(ec), event)) { 158 } else {
179 ec->expect_event = 0; 159 if (wait_event_timeout(ec->wait,
160 acpi_ec_check_status(ec, event),
161 msecs_to_jiffies(ACPI_EC_DELAY)) ||
162 acpi_ec_check_status(ec, event)) {
180 return 0; 163 return 0;
164 } else {
165 printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
166 " status = %d, expect_event = %d\n",
167 acpi_ec_read_status(ec), event);
181 } 168 }
182 } while (--i > 0); 169 }
183
184 ec->expect_event = 0;
185 170
186 return -ETIME; 171 return -ETIME;
187} 172}
@@ -196,7 +181,6 @@ int acpi_ec_enter_burst_mode(struct acpi_ec *ec)
196 u8 tmp = 0; 181 u8 tmp = 0;
197 u8 status = 0; 182 u8 status = 0;
198 183
199
200 status = acpi_ec_read_status(ec); 184 status = acpi_ec_read_status(ec);
201 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) { 185 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
202 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 186 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
@@ -212,7 +196,7 @@ int acpi_ec_enter_burst_mode(struct acpi_ec *ec)
212 196
213 atomic_set(&ec->leaving_burst, 0); 197 atomic_set(&ec->leaving_burst, 0);
214 return 0; 198 return 0;
215 end: 199 end:
216 ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode")); 200 ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode"));
217 return -1; 201 return -1;
218} 202}
@@ -221,58 +205,68 @@ int acpi_ec_leave_burst_mode(struct acpi_ec *ec)
221{ 205{
222 u8 status = 0; 206 u8 status = 0;
223 207
224
225 status = acpi_ec_read_status(ec); 208 status = acpi_ec_read_status(ec);
226 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){ 209 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)) {
227 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 210 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
228 if(status) 211 if (status)
229 goto end; 212 goto end;
230 acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE); 213 acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE);
231 acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 214 acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
232 } 215 }
233 atomic_set(&ec->leaving_burst, 1); 216 atomic_set(&ec->leaving_burst, 1);
234 return 0; 217 return 0;
235 end: 218 end:
236 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode")); 219 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode"));
237 return -1; 220 return -1;
238} 221}
239#endif /* ACPI_FUTURE_USAGE */ 222#endif /* ACPI_FUTURE_USAGE */
240 223
241static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, 224static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
242 const u8 *wdata, unsigned wdata_len, 225 const u8 * wdata, unsigned wdata_len,
243 u8 *rdata, unsigned rdata_len) 226 u8 * rdata, unsigned rdata_len)
244{ 227{
245 int result; 228 int result = 0;
246 229
247 acpi_ec_write_cmd(ec, command); 230 acpi_ec_write_cmd(ec, command);
248 231
249 for (; wdata_len > 0; wdata_len --) { 232 for (; wdata_len > 0; --wdata_len) {
250 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 233 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
251 if (result) 234 if (result) {
252 return result; 235 printk(KERN_ERR PREFIX
236 "write_cmd timeout, command = %d\n", command);
237 goto end;
238 }
253 acpi_ec_write_data(ec, *(wdata++)); 239 acpi_ec_write_data(ec, *(wdata++));
254 } 240 }
255 241
256 if (command == ACPI_EC_COMMAND_WRITE) { 242 if (!rdata_len) {
257 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 243 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
258 if (result) 244 if (result) {
259 return result; 245 printk(KERN_ERR PREFIX
246 "finish-write timeout, command = %d\n", command);
247 goto end;
248 }
249 } else if (command == ACPI_EC_COMMAND_QUERY) {
250 atomic_set(&ec->query_pending, 0);
260 } 251 }
261 252
262 for (; rdata_len > 0; rdata_len --) { 253 for (; rdata_len > 0; --rdata_len) {
263 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1); 254 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
264 if (result) 255 if (result) {
265 return result; 256 printk(KERN_ERR PREFIX "read timeout, command = %d\n",
257 command);
258 goto end;
259 }
266 260
267 *(rdata++) = acpi_ec_read_data(ec); 261 *(rdata++) = acpi_ec_read_data(ec);
268 } 262 }
269 263 end:
270 return 0; 264 return result;
271} 265}
272 266
273static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, 267static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
274 const u8 *wdata, unsigned wdata_len, 268 const u8 * wdata, unsigned wdata_len,
275 u8 *rdata, unsigned rdata_len) 269 u8 * rdata, unsigned rdata_len)
276{ 270{
277 int status; 271 int status;
278 u32 glk; 272 u32 glk;
@@ -280,36 +274,40 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
280 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) 274 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
281 return -EINVAL; 275 return -EINVAL;
282 276
283 if (rdata) 277 if (rdata)
284 memset(rdata, 0, rdata_len); 278 memset(rdata, 0, rdata_len);
285 279
280 mutex_lock(&ec->lock);
286 if (ec->global_lock) { 281 if (ec->global_lock) {
287 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 282 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
288 if (ACPI_FAILURE(status)) 283 if (ACPI_FAILURE(status))
289 return -ENODEV; 284 return -ENODEV;
290 } 285 }
291 down(&ec->sem); 286
287 /* Make sure GPE is enabled before doing transaction */
288 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
292 289
293 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 290 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
294 if (status) { 291 if (status) {
295 printk(KERN_DEBUG PREFIX "read EC, IB not empty\n"); 292 printk(KERN_DEBUG PREFIX
293 "input buffer is not empty, aborting transaction\n");
296 goto end; 294 goto end;
297 } 295 }
298 296
299 status = acpi_ec_transaction_unlocked(ec, command, 297 status = acpi_ec_transaction_unlocked(ec, command,
300 wdata, wdata_len, 298 wdata, wdata_len,
301 rdata, rdata_len); 299 rdata, rdata_len);
302 300
303end: 301 end:
304 up(&ec->sem);
305 302
306 if (ec->global_lock) 303 if (ec->global_lock)
307 acpi_release_global_lock(glk); 304 acpi_release_global_lock(glk);
305 mutex_unlock(&ec->lock);
308 306
309 return status; 307 return status;
310} 308}
311 309
312static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data) 310static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
313{ 311{
314 int result; 312 int result;
315 u8 d; 313 u8 d;
@@ -322,15 +320,15 @@ static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data)
322 320
323static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data) 321static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
324{ 322{
325 u8 wdata[2] = { address, data }; 323 u8 wdata[2] = { address, data };
326 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE, 324 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
327 wdata, 2, NULL, 0); 325 wdata, 2, NULL, 0);
328} 326}
329 327
330/* 328/*
331 * Externally callable EC access functions. For now, assume 1 EC only 329 * Externally callable EC access functions. For now, assume 1 EC only
332 */ 330 */
333int ec_read(u8 addr, u8 *val) 331int ec_read(u8 addr, u8 * val)
334{ 332{
335 struct acpi_ec *ec; 333 struct acpi_ec *ec;
336 int err; 334 int err;
@@ -369,9 +367,9 @@ int ec_write(u8 addr, u8 val)
369 367
370EXPORT_SYMBOL(ec_write); 368EXPORT_SYMBOL(ec_write);
371 369
372extern int ec_transaction(u8 command, 370int ec_transaction(u8 command,
373 const u8 *wdata, unsigned wdata_len, 371 const u8 * wdata, unsigned wdata_len,
374 u8 *rdata, unsigned rdata_len) 372 u8 * rdata, unsigned rdata_len)
375{ 373{
376 struct acpi_ec *ec; 374 struct acpi_ec *ec;
377 375
@@ -386,65 +384,49 @@ extern int ec_transaction(u8 command,
386 384
387EXPORT_SYMBOL(ec_transaction); 385EXPORT_SYMBOL(ec_transaction);
388 386
389static int acpi_ec_query(struct acpi_ec *ec, u8 *data) 387static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
390{ 388{
391 int result; 389 int result;
392 u8 d; 390 u8 d;
393 391
394 if (!ec || !data) 392 if (!ec || !data)
395 return -EINVAL; 393 return -EINVAL;
396 394
397 /* 395 /*
398 * Query the EC to find out which _Qxx method we need to evaluate. 396 * Query the EC to find out which _Qxx method we need to evaluate.
399 * Note that successful completion of the query causes the ACPI_EC_SCI 397 * Note that successful completion of the query causes the ACPI_EC_SCI
400 * bit to be cleared (and thus clearing the interrupt source). 398 * bit to be cleared (and thus clearing the interrupt source).
401 */ 399 */
402 400
403 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1); 401 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1);
404 if (result) 402 if (result)
405 return result; 403 return result;
406 404
407 if (!d) 405 if (!d)
408 return -ENODATA; 406 return -ENODATA;
409 407
410 *data = d; 408 *data = d;
411 return 0; 409 return 0;
412} 410}
413 411
414/* -------------------------------------------------------------------------- 412/* --------------------------------------------------------------------------
415 Event Management 413 Event Management
416 -------------------------------------------------------------------------- */ 414 -------------------------------------------------------------------------- */
417 415
418struct acpi_ec_query_data {
419 acpi_handle handle;
420 u8 data;
421};
422
423static void acpi_ec_gpe_query(void *ec_cxt) 416static void acpi_ec_gpe_query(void *ec_cxt)
424{ 417{
425 struct acpi_ec *ec = (struct acpi_ec *)ec_cxt; 418 struct acpi_ec *ec = (struct acpi_ec *)ec_cxt;
426 u8 value = 0; 419 u8 value = 0;
427 static char object_name[8]; 420 char object_name[8];
428 421
429 if (!ec) 422 if (!ec || acpi_ec_query(ec, &value))
430 goto end; 423 return;
431
432 value = acpi_ec_read_status(ec);
433
434 if (!(value & ACPI_EC_FLAG_SCI))
435 goto end;
436
437 if (acpi_ec_query(ec, &value))
438 goto end;
439 424
440 snprintf(object_name, 8, "_Q%2.2X", value); 425 snprintf(object_name, 8, "_Q%2.2X", value);
441 426
442 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s", object_name)); 427 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s", object_name));
443 428
444 acpi_evaluate_object(ec->handle, object_name, NULL, NULL); 429 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
445
446 end:
447 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
448} 430}
449 431
450static u32 acpi_ec_gpe_handler(void *data) 432static u32 acpi_ec_gpe_handler(void *data)
@@ -453,22 +435,18 @@ static u32 acpi_ec_gpe_handler(void *data)
453 u8 value; 435 u8 value;
454 struct acpi_ec *ec = (struct acpi_ec *)data; 436 struct acpi_ec *ec = (struct acpi_ec *)data;
455 437
456 acpi_clear_gpe(NULL, ec->gpe_bit, ACPI_ISR);
457 value = acpi_ec_read_status(ec);
458
459 if (acpi_ec_mode == EC_INTR) { 438 if (acpi_ec_mode == EC_INTR) {
460 if (acpi_ec_check_status(value, ec->expect_event)) { 439 wake_up(&ec->wait);
461 ec->expect_event = 0;
462 wake_up(&ec->wait);
463 }
464 } 440 }
465 441
466 if (value & ACPI_EC_FLAG_SCI) { 442 value = acpi_ec_read_status(ec);
467 status = acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec); 443 if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) {
468 return status == AE_OK ? 444 atomic_set(&ec->query_pending, 1);
469 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; 445 status =
446 acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query,
447 ec);
470 } 448 }
471 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR); 449
472 return status == AE_OK ? 450 return status == AE_OK ?
473 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; 451 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
474} 452}
@@ -504,7 +482,6 @@ acpi_ec_space_handler(u32 function,
504 acpi_integer f_v = 0; 482 acpi_integer f_v = 0;
505 int i = 0; 483 int i = 0;
506 484
507
508 if ((address > 0xFF) || !value || !handler_context) 485 if ((address > 0xFF) || !value || !handler_context)
509 return AE_BAD_PARAMETER; 486 return AE_BAD_PARAMETER;
510 487
@@ -518,7 +495,7 @@ acpi_ec_space_handler(u32 function,
518 switch (function) { 495 switch (function) {
519 case ACPI_READ: 496 case ACPI_READ:
520 temp = 0; 497 temp = 0;
521 result = acpi_ec_read(ec, (u8) address, (u8 *) &temp); 498 result = acpi_ec_read(ec, (u8) address, (u8 *) & temp);
522 break; 499 break;
523 case ACPI_WRITE: 500 case ACPI_WRITE:
524 result = acpi_ec_write(ec, (u8) address, (u8) temp); 501 result = acpi_ec_write(ec, (u8) address, (u8) temp);
@@ -571,18 +548,15 @@ static int acpi_ec_read_info(struct seq_file *seq, void *offset)
571{ 548{
572 struct acpi_ec *ec = (struct acpi_ec *)seq->private; 549 struct acpi_ec *ec = (struct acpi_ec *)seq->private;
573 550
574
575 if (!ec) 551 if (!ec)
576 goto end; 552 goto end;
577 553
578 seq_printf(seq, "gpe bit: 0x%02x\n", 554 seq_printf(seq, "gpe: 0x%02x\n", (u32) ec->gpe);
579 (u32) ec->gpe_bit);
580 seq_printf(seq, "ports: 0x%02x, 0x%02x\n", 555 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
581 (u32) ec->command_addr, 556 (u32) ec->command_addr, (u32) ec->data_addr);
582 (u32) ec->data_addr);
583 seq_printf(seq, "use global lock: %s\n", 557 seq_printf(seq, "use global lock: %s\n",
584 ec->global_lock ? "yes" : "no"); 558 ec->global_lock ? "yes" : "no");
585 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 559 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
586 560
587 end: 561 end:
588 return 0; 562 return 0;
@@ -605,7 +579,6 @@ static int acpi_ec_add_fs(struct acpi_device *device)
605{ 579{
606 struct proc_dir_entry *entry = NULL; 580 struct proc_dir_entry *entry = NULL;
607 581
608
609 if (!acpi_device_dir(device)) { 582 if (!acpi_device_dir(device)) {
610 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 583 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
611 acpi_ec_dir); 584 acpi_ec_dir);
@@ -648,18 +621,17 @@ static int acpi_ec_add(struct acpi_device *device)
648 acpi_status status = AE_OK; 621 acpi_status status = AE_OK;
649 struct acpi_ec *ec = NULL; 622 struct acpi_ec *ec = NULL;
650 623
651
652 if (!device) 624 if (!device)
653 return -EINVAL; 625 return -EINVAL;
654 626
655 ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 627 ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
656 if (!ec) 628 if (!ec)
657 return -ENOMEM; 629 return -ENOMEM;
658 memset(ec, 0, sizeof(struct acpi_ec));
659 630
660 ec->handle = device->handle; 631 ec->handle = device->handle;
661 ec->uid = -1; 632 ec->uid = -1;
662 init_MUTEX(&ec->sem); 633 mutex_init(&ec->lock);
634 atomic_set(&ec->query_pending, 0);
663 if (acpi_ec_mode == EC_INTR) { 635 if (acpi_ec_mode == EC_INTR) {
664 atomic_set(&ec->leaving_burst, 1); 636 atomic_set(&ec->leaving_burst, 1);
665 init_waitqueue_head(&ec->wait); 637 init_waitqueue_head(&ec->wait);
@@ -669,8 +641,7 @@ static int acpi_ec_add(struct acpi_device *device)
669 acpi_driver_data(device) = ec; 641 acpi_driver_data(device) = ec;
670 642
671 /* Use the global lock for all EC transactions? */ 643 /* Use the global lock for all EC transactions? */
672 acpi_evaluate_integer(ec->handle, "_GLK", NULL, 644 acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock);
673 &ec->global_lock);
674 645
675 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see: 646 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see:
676 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */ 647 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */
@@ -679,7 +650,7 @@ static int acpi_ec_add(struct acpi_device *device)
679 ACPI_ADR_SPACE_EC, 650 ACPI_ADR_SPACE_EC,
680 &acpi_ec_space_handler); 651 &acpi_ec_space_handler);
681 652
682 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, 653 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe,
683 &acpi_ec_gpe_handler); 654 &acpi_ec_gpe_handler);
684 655
685 kfree(ec_ecdt); 656 kfree(ec_ecdt);
@@ -687,11 +658,10 @@ static int acpi_ec_add(struct acpi_device *device)
687 658
688 /* Get GPE bit assignment (EC events). */ 659 /* Get GPE bit assignment (EC events). */
689 /* TODO: Add support for _GPE returning a package */ 660 /* TODO: Add support for _GPE returning a package */
690 status = 661 status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe);
691 acpi_evaluate_integer(ec->handle, "_GPE", NULL,
692 &ec->gpe_bit);
693 if (ACPI_FAILURE(status)) { 662 if (ACPI_FAILURE(status)) {
694 ACPI_EXCEPTION((AE_INFO, status, "Obtaining GPE bit assignment")); 663 ACPI_EXCEPTION((AE_INFO, status,
664 "Obtaining GPE bit assignment"));
695 result = -ENODEV; 665 result = -ENODEV;
696 goto end; 666 goto end;
697 } 667 }
@@ -701,13 +671,13 @@ static int acpi_ec_add(struct acpi_device *device)
701 goto end; 671 goto end;
702 672
703 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.", 673 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
704 acpi_device_name(device), acpi_device_bid(device), 674 acpi_device_name(device), acpi_device_bid(device),
705 (u32) ec->gpe_bit)); 675 (u32) ec->gpe));
706 676
707 if (!first_ec) 677 if (!first_ec)
708 first_ec = device; 678 first_ec = device;
709 679
710 end: 680 end:
711 if (result) 681 if (result)
712 kfree(ec); 682 kfree(ec);
713 683
@@ -718,7 +688,6 @@ static int acpi_ec_remove(struct acpi_device *device, int type)
718{ 688{
719 struct acpi_ec *ec = NULL; 689 struct acpi_ec *ec = NULL;
720 690
721
722 if (!device) 691 if (!device)
723 return -EINVAL; 692 return -EINVAL;
724 693
@@ -761,7 +730,6 @@ static int acpi_ec_start(struct acpi_device *device)
761 acpi_status status = AE_OK; 730 acpi_status status = AE_OK;
762 struct acpi_ec *ec = NULL; 731 struct acpi_ec *ec = NULL;
763 732
764
765 if (!device) 733 if (!device)
766 return -EINVAL; 734 return -EINVAL;
767 735
@@ -782,27 +750,26 @@ static int acpi_ec_start(struct acpi_device *device)
782 } 750 }
783 751
784 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx", 752 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
785 ec->gpe_bit, ec->command_addr, ec->data_addr)); 753 ec->gpe, ec->command_addr, ec->data_addr));
786 754
787 /* 755 /*
788 * Install GPE handler 756 * Install GPE handler
789 */ 757 */
790 status = acpi_install_gpe_handler(NULL, ec->gpe_bit, 758 status = acpi_install_gpe_handler(NULL, ec->gpe,
791 ACPI_GPE_EDGE_TRIGGERED, 759 ACPI_GPE_EDGE_TRIGGERED,
792 &acpi_ec_gpe_handler, ec); 760 &acpi_ec_gpe_handler, ec);
793 if (ACPI_FAILURE(status)) { 761 if (ACPI_FAILURE(status)) {
794 return -ENODEV; 762 return -ENODEV;
795 } 763 }
796 acpi_set_gpe_type(NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME); 764 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
797 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 765 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
798 766
799 status = acpi_install_address_space_handler(ec->handle, 767 status = acpi_install_address_space_handler(ec->handle,
800 ACPI_ADR_SPACE_EC, 768 ACPI_ADR_SPACE_EC,
801 &acpi_ec_space_handler, 769 &acpi_ec_space_handler,
802 &acpi_ec_space_setup, ec); 770 &acpi_ec_space_setup, ec);
803 if (ACPI_FAILURE(status)) { 771 if (ACPI_FAILURE(status)) {
804 acpi_remove_gpe_handler(NULL, ec->gpe_bit, 772 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
805 &acpi_ec_gpe_handler);
806 return -ENODEV; 773 return -ENODEV;
807 } 774 }
808 775
@@ -814,7 +781,6 @@ static int acpi_ec_stop(struct acpi_device *device, int type)
814 acpi_status status = AE_OK; 781 acpi_status status = AE_OK;
815 struct acpi_ec *ec = NULL; 782 struct acpi_ec *ec = NULL;
816 783
817
818 if (!device) 784 if (!device)
819 return -EINVAL; 785 return -EINVAL;
820 786
@@ -826,9 +792,7 @@ static int acpi_ec_stop(struct acpi_device *device, int type)
826 if (ACPI_FAILURE(status)) 792 if (ACPI_FAILURE(status))
827 return -ENODEV; 793 return -ENODEV;
828 794
829 status = 795 status = acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
830 acpi_remove_gpe_handler(NULL, ec->gpe_bit,
831 &acpi_ec_gpe_handler);
832 if (ACPI_FAILURE(status)) 796 if (ACPI_FAILURE(status))
833 return -ENODEV; 797 return -ENODEV;
834 798
@@ -841,7 +805,7 @@ acpi_fake_ecdt_callback(acpi_handle handle,
841{ 805{
842 acpi_status status; 806 acpi_status status;
843 807
844 init_MUTEX(&ec_ecdt->sem); 808 mutex_init(&ec_ecdt->lock);
845 if (acpi_ec_mode == EC_INTR) { 809 if (acpi_ec_mode == EC_INTR) {
846 init_waitqueue_head(&ec_ecdt->wait); 810 init_waitqueue_head(&ec_ecdt->wait);
847 } 811 }
@@ -853,16 +817,15 @@ acpi_fake_ecdt_callback(acpi_handle handle,
853 ec_ecdt->uid = -1; 817 ec_ecdt->uid = -1;
854 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); 818 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid);
855 819
856 status = 820 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe);
857 acpi_evaluate_integer(handle, "_GPE", NULL,
858 &ec_ecdt->gpe_bit);
859 if (ACPI_FAILURE(status)) 821 if (ACPI_FAILURE(status))
860 return status; 822 return status;
861 ec_ecdt->global_lock = TRUE; 823 ec_ecdt->global_lock = TRUE;
862 ec_ecdt->handle = handle; 824 ec_ecdt->handle = handle;
863 825
864 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx", 826 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
865 ec_ecdt->gpe_bit, ec_ecdt->command_addr, ec_ecdt->data_addr)); 827 ec_ecdt->gpe, ec_ecdt->command_addr,
828 ec_ecdt->data_addr));
866 829
867 return AE_CTRL_TERMINATE; 830 return AE_CTRL_TERMINATE;
868} 831}
@@ -884,12 +847,11 @@ static int __init acpi_ec_fake_ecdt(void)
884 847
885 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT")); 848 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT"));
886 849
887 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 850 ec_ecdt = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
888 if (!ec_ecdt) { 851 if (!ec_ecdt) {
889 ret = -ENOMEM; 852 ret = -ENOMEM;
890 goto error; 853 goto error;
891 } 854 }
892 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
893 855
894 status = acpi_get_devices(ACPI_EC_HID, 856 status = acpi_get_devices(ACPI_EC_HID,
895 acpi_fake_ecdt_callback, NULL, NULL); 857 acpi_fake_ecdt_callback, NULL, NULL);
@@ -901,7 +863,7 @@ static int __init acpi_ec_fake_ecdt(void)
901 goto error; 863 goto error;
902 } 864 }
903 return 0; 865 return 0;
904 error: 866 error:
905 return ret; 867 return ret;
906} 868}
907 869
@@ -910,9 +872,8 @@ static int __init acpi_ec_get_real_ecdt(void)
910 acpi_status status; 872 acpi_status status;
911 struct acpi_table_ecdt *ecdt_ptr; 873 struct acpi_table_ecdt *ecdt_ptr;
912 874
913 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, 875 status = acpi_get_table(ACPI_SIG_ECDT, 1,
914 (struct acpi_table_header **) 876 (struct acpi_table_header **)&ecdt_ptr);
915 &ecdt_ptr);
916 if (ACPI_FAILURE(status)) 877 if (ACPI_FAILURE(status))
917 return -ENODEV; 878 return -ENODEV;
918 879
@@ -921,30 +882,28 @@ static int __init acpi_ec_get_real_ecdt(void)
921 /* 882 /*
922 * Generate a temporary ec context to use until the namespace is scanned 883 * Generate a temporary ec context to use until the namespace is scanned
923 */ 884 */
924 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 885 ec_ecdt = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
925 if (!ec_ecdt) 886 if (!ec_ecdt)
926 return -ENOMEM; 887 return -ENOMEM;
927 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
928 888
929 init_MUTEX(&ec_ecdt->sem); 889 mutex_init(&ec_ecdt->lock);
930 if (acpi_ec_mode == EC_INTR) { 890 if (acpi_ec_mode == EC_INTR) {
931 init_waitqueue_head(&ec_ecdt->wait); 891 init_waitqueue_head(&ec_ecdt->wait);
932 } 892 }
933 ec_ecdt->command_addr = ecdt_ptr->ec_control.address; 893 ec_ecdt->command_addr = ecdt_ptr->control.address;
934 ec_ecdt->data_addr = ecdt_ptr->ec_data.address; 894 ec_ecdt->data_addr = ecdt_ptr->data.address;
935 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit; 895 ec_ecdt->gpe = ecdt_ptr->gpe;
936 /* use the GL just to be safe */ 896 /* use the GL just to be safe */
937 ec_ecdt->global_lock = TRUE; 897 ec_ecdt->global_lock = TRUE;
938 ec_ecdt->uid = ecdt_ptr->uid; 898 ec_ecdt->uid = ecdt_ptr->uid;
939 899
940 status = 900 status = acpi_get_handle(NULL, ecdt_ptr->id, &ec_ecdt->handle);
941 acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle);
942 if (ACPI_FAILURE(status)) { 901 if (ACPI_FAILURE(status)) {
943 goto error; 902 goto error;
944 } 903 }
945 904
946 return 0; 905 return 0;
947 error: 906 error:
948 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); 907 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
949 kfree(ec_ecdt); 908 kfree(ec_ecdt);
950 ec_ecdt = NULL; 909 ec_ecdt = NULL;
@@ -970,14 +929,14 @@ int __init acpi_ec_ecdt_probe(void)
970 /* 929 /*
971 * Install GPE handler 930 * Install GPE handler
972 */ 931 */
973 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit, 932 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe,
974 ACPI_GPE_EDGE_TRIGGERED, 933 ACPI_GPE_EDGE_TRIGGERED,
975 &acpi_ec_gpe_handler, ec_ecdt); 934 &acpi_ec_gpe_handler, ec_ecdt);
976 if (ACPI_FAILURE(status)) { 935 if (ACPI_FAILURE(status)) {
977 goto error; 936 goto error;
978 } 937 }
979 acpi_set_gpe_type(NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME); 938 acpi_set_gpe_type(NULL, ec_ecdt->gpe, ACPI_GPE_TYPE_RUNTIME);
980 acpi_enable_gpe(NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR); 939 acpi_enable_gpe(NULL, ec_ecdt->gpe, ACPI_NOT_ISR);
981 940
982 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT, 941 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
983 ACPI_ADR_SPACE_EC, 942 ACPI_ADR_SPACE_EC,
@@ -985,7 +944,7 @@ int __init acpi_ec_ecdt_probe(void)
985 &acpi_ec_space_setup, 944 &acpi_ec_space_setup,
986 ec_ecdt); 945 ec_ecdt);
987 if (ACPI_FAILURE(status)) { 946 if (ACPI_FAILURE(status)) {
988 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, 947 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe,
989 &acpi_ec_gpe_handler); 948 &acpi_ec_gpe_handler);
990 goto error; 949 goto error;
991 } 950 }
@@ -1004,7 +963,6 @@ static int __init acpi_ec_init(void)
1004{ 963{
1005 int result = 0; 964 int result = 0;
1006 965
1007
1008 if (acpi_disabled) 966 if (acpi_disabled)
1009 return 0; 967 return 0;
1010 968
@@ -1057,7 +1015,8 @@ static int __init acpi_ec_set_intr_mode(char *str)
1057 acpi_ec_mode = EC_POLL; 1015 acpi_ec_mode = EC_POLL;
1058 } 1016 }
1059 acpi_ec_driver.ops.add = acpi_ec_add; 1017 acpi_ec_driver.ops.add = acpi_ec_add;
1060 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "EC %s mode.\n", intr ? "interrupt" : "polling")); 1018 printk(KERN_NOTICE PREFIX "%s mode.\n",
1019 intr ? "interrupt" : "polling");
1061 1020
1062 return 1; 1021 return 1;
1063} 1022}
diff --git a/drivers/acpi/events/evevent.c b/drivers/acpi/events/evevent.c
index 919037d6ac..a1f87b5def 100644
--- a/drivers/acpi/events/evevent.c
+++ b/drivers/acpi/events/evevent.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -70,13 +70,6 @@ acpi_status acpi_ev_initialize_events(void)
70 70
71 ACPI_FUNCTION_TRACE(ev_initialize_events); 71 ACPI_FUNCTION_TRACE(ev_initialize_events);
72 72
73 /* Make sure we have ACPI tables */
74
75 if (!acpi_gbl_DSDT) {
76 ACPI_WARNING((AE_INFO, "No ACPI tables present!"));
77 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
78 }
79
80 /* 73 /*
81 * Initialize the Fixed and General Purpose Events. This is done prior to 74 * Initialize the Fixed and General Purpose Events. This is done prior to
82 * enabling SCIs to prevent interrupts from occurring before the handlers are 75 * enabling SCIs to prevent interrupts from occurring before the handlers are
@@ -211,8 +204,7 @@ static acpi_status acpi_ev_fixed_event_initialize(void)
211 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) { 204 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
212 status = 205 status =
213 acpi_set_register(acpi_gbl_fixed_event_info[i]. 206 acpi_set_register(acpi_gbl_fixed_event_info[i].
214 enable_register_id, 0, 207 enable_register_id, 0);
215 ACPI_MTX_LOCK);
216 if (ACPI_FAILURE(status)) { 208 if (ACPI_FAILURE(status)) {
217 return (status); 209 return (status);
218 } 210 }
@@ -298,7 +290,7 @@ static u32 acpi_ev_fixed_event_dispatch(u32 event)
298 /* Clear the status bit */ 290 /* Clear the status bit */
299 291
300 (void)acpi_set_register(acpi_gbl_fixed_event_info[event]. 292 (void)acpi_set_register(acpi_gbl_fixed_event_info[event].
301 status_register_id, 1, ACPI_MTX_DO_NOT_LOCK); 293 status_register_id, 1);
302 294
303 /* 295 /*
304 * Make sure we've got a handler. If not, report an error. 296 * Make sure we've got a handler. If not, report an error.
@@ -306,8 +298,7 @@ static u32 acpi_ev_fixed_event_dispatch(u32 event)
306 */ 298 */
307 if (NULL == acpi_gbl_fixed_event_handlers[event].handler) { 299 if (NULL == acpi_gbl_fixed_event_handlers[event].handler) {
308 (void)acpi_set_register(acpi_gbl_fixed_event_info[event]. 300 (void)acpi_set_register(acpi_gbl_fixed_event_info[event].
309 enable_register_id, 0, 301 enable_register_id, 0);
310 ACPI_MTX_DO_NOT_LOCK);
311 302
312 ACPI_ERROR((AE_INFO, 303 ACPI_ERROR((AE_INFO,
313 "No installed handler for fixed event [%08X]", 304 "No installed handler for fixed event [%08X]",
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c
index c76c0583ca..dfac3ecc59 100644
--- a/drivers/acpi/events/evgpe.c
+++ b/drivers/acpi/events/evgpe.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -121,7 +121,9 @@ acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
121 if (!gpe_register_info) { 121 if (!gpe_register_info) {
122 return_ACPI_STATUS(AE_NOT_EXIST); 122 return_ACPI_STATUS(AE_NOT_EXIST);
123 } 123 }
124 register_bit = gpe_event_info->register_bit; 124 register_bit = (u8)
125 (1 <<
126 (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number));
125 127
126 /* 1) Disable case. Simply clear all enable bits */ 128 /* 1) Disable case. Simply clear all enable bits */
127 129
@@ -458,8 +460,7 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
458 460
459 /* Examine one GPE bit */ 461 /* Examine one GPE bit */
460 462
461 if (enabled_status_byte & 463 if (enabled_status_byte & (1 << j)) {
462 acpi_gbl_decode_to8bit[j]) {
463 /* 464 /*
464 * Found an active GPE. Dispatch the event to a handler 465 * Found an active GPE. Dispatch the event to a handler
465 * or method. 466 * or method.
@@ -570,7 +571,7 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
570 571
571 if (ACPI_FAILURE(status)) { 572 if (ACPI_FAILURE(status)) {
572 ACPI_EXCEPTION((AE_INFO, status, 573 ACPI_EXCEPTION((AE_INFO, status,
573 "While evaluating GPE method [%4.4s]", 574 "while evaluating GPE method [%4.4s]",
574 acpi_ut_get_node_name 575 acpi_ut_get_node_name
575 (local_gpe_event_info.dispatch. 576 (local_gpe_event_info.dispatch.
576 method_node))); 577 method_node)));
@@ -618,6 +619,8 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
618 619
619 ACPI_FUNCTION_TRACE(ev_gpe_dispatch); 620 ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
620 621
622 acpi_gpe_count++;
623
621 /* 624 /*
622 * If edge-triggered, clear the GPE status bit now. Note that 625 * If edge-triggered, clear the GPE status bit now. Note that
623 * level-triggered events are cleared after the GPE is serviced. 626 * level-triggered events are cleared after the GPE is serviced.
@@ -633,20 +636,23 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
633 } 636 }
634 } 637 }
635 638
636 /* Save current system state */ 639 if (!acpi_gbl_system_awake_and_running) {
637 640 /*
638 if (acpi_gbl_system_awake_and_running) { 641 * We just woke up because of a wake GPE. Disable any further GPEs
639 ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_SYSTEM_RUNNING); 642 * until we are fully up and running (Only wake GPEs should be enabled
640 } else { 643 * at this time, but we just brute-force disable them all.)
641 ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_SYSTEM_RUNNING); 644 * 1) We must disable this particular wake GPE so it won't fire again
645 * 2) We want to disable all wake GPEs, since we are now awake
646 */
647 (void)acpi_hw_disable_all_gpes();
642 } 648 }
643 649
644 /* 650 /*
645 * Dispatch the GPE to either an installed handler, or the control 651 * Dispatch the GPE to either an installed handler, or the control method
646 * method associated with this GPE (_Lxx or _Exx). 652 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
647 * If a handler exists, we invoke it and do not attempt to run the method. 653 * it and do not attempt to run the method. If there is neither a handler
648 * If there is neither a handler nor a method, we disable the level to 654 * nor a method, we disable this GPE to prevent further such pointless
649 * prevent further events from coming in here. 655 * events from firing.
650 */ 656 */
651 switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) { 657 switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
652 case ACPI_GPE_DISPATCH_HANDLER: 658 case ACPI_GPE_DISPATCH_HANDLER:
@@ -677,8 +683,8 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
677 case ACPI_GPE_DISPATCH_METHOD: 683 case ACPI_GPE_DISPATCH_METHOD:
678 684
679 /* 685 /*
680 * Disable GPE, so it doesn't keep firing before the method has a 686 * Disable the GPE, so it doesn't keep firing before the method has a
681 * chance to run. 687 * chance to run (it runs asynchronously with interrupts enabled).
682 */ 688 */
683 status = acpi_ev_disable_gpe(gpe_event_info); 689 status = acpi_ev_disable_gpe(gpe_event_info);
684 if (ACPI_FAILURE(status)) { 690 if (ACPI_FAILURE(status)) {
@@ -711,7 +717,7 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
711 gpe_number)); 717 gpe_number));
712 718
713 /* 719 /*
714 * Disable the GPE. The GPE will remain disabled until the ACPI 720 * Disable the GPE. The GPE will remain disabled until the ACPI
715 * Core Subsystem is restarted, or a handler is installed. 721 * Core Subsystem is restarted, or a handler is installed.
716 */ 722 */
717 status = acpi_ev_disable_gpe(gpe_event_info); 723 status = acpi_ev_disable_gpe(gpe_event_info);
@@ -726,50 +732,3 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
726 732
727 return_UINT32(ACPI_INTERRUPT_HANDLED); 733 return_UINT32(ACPI_INTERRUPT_HANDLED);
728} 734}
729
730#ifdef ACPI_GPE_NOTIFY_CHECK
731/*******************************************************************************
732 * TBD: NOT USED, PROTOTYPE ONLY AND WILL PROBABLY BE REMOVED
733 *
734 * FUNCTION: acpi_ev_check_for_wake_only_gpe
735 *
736 * PARAMETERS: gpe_event_info - info for this GPE
737 *
738 * RETURN: Status
739 *
740 * DESCRIPTION: Determine if a a GPE is "wake-only".
741 *
742 * Called from Notify() code in interpreter when a "DeviceWake"
743 * Notify comes in.
744 *
745 ******************************************************************************/
746
747acpi_status
748acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info)
749{
750 acpi_status status;
751
752 ACPI_FUNCTION_TRACE(ev_check_for_wake_only_gpe);
753
754 if ((gpe_event_info) && /* Only >0 for _Lxx/_Exx */
755 ((gpe_event_info->flags & ACPI_GPE_SYSTEM_MASK) == ACPI_GPE_SYSTEM_RUNNING)) { /* System state at GPE time */
756 /* This must be a wake-only GPE, disable it */
757
758 status = acpi_ev_disable_gpe(gpe_event_info);
759
760 /* Set GPE to wake-only. Do not change wake disabled/enabled status */
761
762 acpi_ev_set_gpe_type(gpe_event_info, ACPI_GPE_TYPE_WAKE);
763
764 ACPI_INFO((AE_INFO,
765 "GPE %p was updated from wake/run to wake-only",
766 gpe_event_info));
767
768 /* This was a wake-only GPE */
769
770 return_ACPI_STATUS(AE_WAKE_ONLY_GPE);
771 }
772
773 return_ACPI_STATUS(AE_OK);
774}
775#endif
diff --git a/drivers/acpi/events/evgpeblk.c b/drivers/acpi/events/evgpeblk.c
index 95ddeb48bc..ad5bc76edf 100644
--- a/drivers/acpi/events/evgpeblk.c
+++ b/drivers/acpi/events/evgpeblk.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -529,7 +529,7 @@ static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
529 529
530 /* Install new interrupt handler if not SCI_INT */ 530 /* Install new interrupt handler if not SCI_INT */
531 531
532 if (interrupt_number != acpi_gbl_FADT->sci_int) { 532 if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
533 status = acpi_os_install_interrupt_handler(interrupt_number, 533 status = acpi_os_install_interrupt_handler(interrupt_number,
534 acpi_ev_gpe_xrupt_handler, 534 acpi_ev_gpe_xrupt_handler,
535 gpe_xrupt); 535 gpe_xrupt);
@@ -567,7 +567,7 @@ acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
567 567
568 /* We never want to remove the SCI interrupt handler */ 568 /* We never want to remove the SCI interrupt handler */
569 569
570 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT->sci_int) { 570 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
571 gpe_xrupt->gpe_block_list_head = NULL; 571 gpe_xrupt->gpe_block_list_head = NULL;
572 return_ACPI_STATUS(AE_OK); 572 return_ACPI_STATUS(AE_OK);
573 } 573 }
@@ -796,30 +796,31 @@ acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
796 (u8) (gpe_block->block_base_number + 796 (u8) (gpe_block->block_base_number +
797 (i * ACPI_GPE_REGISTER_WIDTH)); 797 (i * ACPI_GPE_REGISTER_WIDTH));
798 798
799 ACPI_STORE_ADDRESS(this_register->status_address.address, 799 this_register->status_address.address =
800 (gpe_block->block_address.address + i)); 800 gpe_block->block_address.address + i;
801 801
802 ACPI_STORE_ADDRESS(this_register->enable_address.address, 802 this_register->enable_address.address =
803 (gpe_block->block_address.address 803 gpe_block->block_address.address + i +
804 + i + gpe_block->register_count)); 804 gpe_block->register_count;
805 805
806 this_register->status_address.address_space_id = 806 this_register->status_address.space_id =
807 gpe_block->block_address.address_space_id; 807 gpe_block->block_address.space_id;
808 this_register->enable_address.address_space_id = 808 this_register->enable_address.space_id =
809 gpe_block->block_address.address_space_id; 809 gpe_block->block_address.space_id;
810 this_register->status_address.register_bit_width = 810 this_register->status_address.bit_width =
811 ACPI_GPE_REGISTER_WIDTH; 811 ACPI_GPE_REGISTER_WIDTH;
812 this_register->enable_address.register_bit_width = 812 this_register->enable_address.bit_width =
813 ACPI_GPE_REGISTER_WIDTH; 813 ACPI_GPE_REGISTER_WIDTH;
814 this_register->status_address.register_bit_offset = 814 this_register->status_address.bit_offset =
815 ACPI_GPE_REGISTER_WIDTH; 815 ACPI_GPE_REGISTER_WIDTH;
816 this_register->enable_address.register_bit_offset = 816 this_register->enable_address.bit_offset =
817 ACPI_GPE_REGISTER_WIDTH; 817 ACPI_GPE_REGISTER_WIDTH;
818 818
819 /* Init the event_info for each GPE within this register */ 819 /* Init the event_info for each GPE within this register */
820 820
821 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { 821 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
822 this_event->register_bit = acpi_gbl_decode_to8bit[j]; 822 this_event->gpe_number =
823 (u8) (this_register->base_gpe_number + j);
823 this_event->register_info = this_register; 824 this_event->register_info = this_register;
824 this_event++; 825 this_event++;
825 } 826 }
@@ -1109,11 +1110,12 @@ acpi_status acpi_ev_gpe_initialize(void)
1109 * If EITHER the register length OR the block address are zero, then that 1110 * If EITHER the register length OR the block address are zero, then that
1110 * particular block is not supported. 1111 * particular block is not supported.
1111 */ 1112 */
1112 if (acpi_gbl_FADT->gpe0_blk_len && acpi_gbl_FADT->xgpe0_blk.address) { 1113 if (acpi_gbl_FADT.gpe0_block_length &&
1114 acpi_gbl_FADT.xgpe0_block.address) {
1113 1115
1114 /* GPE block 0 exists (has both length and address > 0) */ 1116 /* GPE block 0 exists (has both length and address > 0) */
1115 1117
1116 register_count0 = (u16) (acpi_gbl_FADT->gpe0_blk_len / 2); 1118 register_count0 = (u16) (acpi_gbl_FADT.gpe0_block_length / 2);
1117 1119
1118 gpe_number_max = 1120 gpe_number_max =
1119 (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1; 1121 (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
@@ -1121,9 +1123,9 @@ acpi_status acpi_ev_gpe_initialize(void)
1121 /* Install GPE Block 0 */ 1123 /* Install GPE Block 0 */
1122 1124
1123 status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device, 1125 status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
1124 &acpi_gbl_FADT->xgpe0_blk, 1126 &acpi_gbl_FADT.xgpe0_block,
1125 register_count0, 0, 1127 register_count0, 0,
1126 acpi_gbl_FADT->sci_int, 1128 acpi_gbl_FADT.sci_interrupt,
1127 &acpi_gbl_gpe_fadt_blocks[0]); 1129 &acpi_gbl_gpe_fadt_blocks[0]);
1128 1130
1129 if (ACPI_FAILURE(status)) { 1131 if (ACPI_FAILURE(status)) {
@@ -1132,20 +1134,21 @@ acpi_status acpi_ev_gpe_initialize(void)
1132 } 1134 }
1133 } 1135 }
1134 1136
1135 if (acpi_gbl_FADT->gpe1_blk_len && acpi_gbl_FADT->xgpe1_blk.address) { 1137 if (acpi_gbl_FADT.gpe1_block_length &&
1138 acpi_gbl_FADT.xgpe1_block.address) {
1136 1139
1137 /* GPE block 1 exists (has both length and address > 0) */ 1140 /* GPE block 1 exists (has both length and address > 0) */
1138 1141
1139 register_count1 = (u16) (acpi_gbl_FADT->gpe1_blk_len / 2); 1142 register_count1 = (u16) (acpi_gbl_FADT.gpe1_block_length / 2);
1140 1143
1141 /* Check for GPE0/GPE1 overlap (if both banks exist) */ 1144 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1142 1145
1143 if ((register_count0) && 1146 if ((register_count0) &&
1144 (gpe_number_max >= acpi_gbl_FADT->gpe1_base)) { 1147 (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
1145 ACPI_ERROR((AE_INFO, 1148 ACPI_ERROR((AE_INFO,
1146 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1", 1149 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1",
1147 gpe_number_max, acpi_gbl_FADT->gpe1_base, 1150 gpe_number_max, acpi_gbl_FADT.gpe1_base,
1148 acpi_gbl_FADT->gpe1_base + 1151 acpi_gbl_FADT.gpe1_base +
1149 ((register_count1 * 1152 ((register_count1 *
1150 ACPI_GPE_REGISTER_WIDTH) - 1))); 1153 ACPI_GPE_REGISTER_WIDTH) - 1)));
1151 1154
@@ -1157,10 +1160,11 @@ acpi_status acpi_ev_gpe_initialize(void)
1157 1160
1158 status = 1161 status =
1159 acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device, 1162 acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
1160 &acpi_gbl_FADT->xgpe1_blk, 1163 &acpi_gbl_FADT.xgpe1_block,
1161 register_count1, 1164 register_count1,
1162 acpi_gbl_FADT->gpe1_base, 1165 acpi_gbl_FADT.gpe1_base,
1163 acpi_gbl_FADT->sci_int, 1166 acpi_gbl_FADT.
1167 sci_interrupt,
1164 &acpi_gbl_gpe_fadt_blocks 1168 &acpi_gbl_gpe_fadt_blocks
1165 [1]); 1169 [1]);
1166 1170
@@ -1173,7 +1177,7 @@ acpi_status acpi_ev_gpe_initialize(void)
1173 * GPE0 and GPE1 do not have to be contiguous in the GPE number 1177 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1174 * space. However, GPE0 always starts at GPE number zero. 1178 * space. However, GPE0 always starts at GPE number zero.
1175 */ 1179 */
1176 gpe_number_max = acpi_gbl_FADT->gpe1_base + 1180 gpe_number_max = acpi_gbl_FADT.gpe1_base +
1177 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1); 1181 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1178 } 1182 }
1179 } 1183 }
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c
index ee2a10bf90..1b784ffe54 100644
--- a/drivers/acpi/events/evmisc.c
+++ b/drivers/acpi/events/evmisc.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -63,14 +63,18 @@ static const char *acpi_notify_value_names[] = {
63}; 63};
64#endif 64#endif
65 65
66/* Pointer to FACS needed for the Global Lock */
67
68static struct acpi_table_facs *facs = NULL;
69
66/* Local prototypes */ 70/* Local prototypes */
67 71
68static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context); 72static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context);
69 73
70static void ACPI_SYSTEM_XFACE acpi_ev_global_lock_thread(void *context);
71
72static u32 acpi_ev_global_lock_handler(void *context); 74static u32 acpi_ev_global_lock_handler(void *context);
73 75
76static acpi_status acpi_ev_remove_global_lock_handler(void);
77
74/******************************************************************************* 78/*******************************************************************************
75 * 79 *
76 * FUNCTION: acpi_ev_is_notify_object 80 * FUNCTION: acpi_ev_is_notify_object
@@ -282,68 +286,45 @@ static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)
282 286
283/******************************************************************************* 287/*******************************************************************************
284 * 288 *
285 * FUNCTION: acpi_ev_global_lock_thread
286 *
287 * PARAMETERS: Context - From thread interface, not used
288 *
289 * RETURN: None
290 *
291 * DESCRIPTION: Invoked by SCI interrupt handler upon acquisition of the
292 * Global Lock. Simply signal all threads that are waiting
293 * for the lock.
294 *
295 ******************************************************************************/
296
297static void ACPI_SYSTEM_XFACE acpi_ev_global_lock_thread(void *context)
298{
299 acpi_status status;
300
301 /* Signal threads that are waiting for the lock */
302
303 if (acpi_gbl_global_lock_thread_count) {
304
305 /* Send sufficient units to the semaphore */
306
307 status =
308 acpi_os_signal_semaphore(acpi_gbl_global_lock_semaphore,
309 acpi_gbl_global_lock_thread_count);
310 if (ACPI_FAILURE(status)) {
311 ACPI_ERROR((AE_INFO,
312 "Could not signal Global Lock semaphore"));
313 }
314 }
315}
316
317/*******************************************************************************
318 *
319 * FUNCTION: acpi_ev_global_lock_handler 289 * FUNCTION: acpi_ev_global_lock_handler
320 * 290 *
321 * PARAMETERS: Context - From thread interface, not used 291 * PARAMETERS: Context - From thread interface, not used
322 * 292 *
323 * RETURN: ACPI_INTERRUPT_HANDLED or ACPI_INTERRUPT_NOT_HANDLED 293 * RETURN: ACPI_INTERRUPT_HANDLED
324 * 294 *
325 * DESCRIPTION: Invoked directly from the SCI handler when a global lock 295 * DESCRIPTION: Invoked directly from the SCI handler when a global lock
326 * release interrupt occurs. Grab the global lock and queue 296 * release interrupt occurs. Attempt to acquire the global lock,
327 * the global lock thread for execution 297 * if successful, signal the thread waiting for the lock.
298 *
299 * NOTE: Assumes that the semaphore can be signaled from interrupt level. If
300 * this is not possible for some reason, a separate thread will have to be
301 * scheduled to do this.
328 * 302 *
329 ******************************************************************************/ 303 ******************************************************************************/
330 304
331static u32 acpi_ev_global_lock_handler(void *context) 305static u32 acpi_ev_global_lock_handler(void *context)
332{ 306{
333 u8 acquired = FALSE; 307 u8 acquired = FALSE;
334 acpi_status status;
335 308
336 /* 309 /*
337 * Attempt to get the lock 310 * Attempt to get the lock.
311 *
338 * If we don't get it now, it will be marked pending and we will 312 * If we don't get it now, it will be marked pending and we will
339 * take another interrupt when it becomes free. 313 * take another interrupt when it becomes free.
340 */ 314 */
341 ACPI_ACQUIRE_GLOBAL_LOCK(acpi_gbl_common_fACS.global_lock, acquired); 315 ACPI_ACQUIRE_GLOBAL_LOCK(facs, acquired);
342 if (acquired) { 316 if (acquired) {
343 317
344 /* Got the lock, now wake all threads waiting for it */ 318 /* Got the lock, now wake all threads waiting for it */
319
345 acpi_gbl_global_lock_acquired = TRUE; 320 acpi_gbl_global_lock_acquired = TRUE;
346 acpi_ev_global_lock_thread(context); 321 /* Send a unit to the semaphore */
322
323 if (ACPI_FAILURE(acpi_os_signal_semaphore(
324 acpi_gbl_global_lock_semaphore, 1))) {
325 ACPI_ERROR((AE_INFO,
326 "Could not signal Global Lock semaphore"));
327 }
347 } 328 }
348 329
349 return (ACPI_INTERRUPT_HANDLED); 330 return (ACPI_INTERRUPT_HANDLED);
@@ -367,6 +348,13 @@ acpi_status acpi_ev_init_global_lock_handler(void)
367 348
368 ACPI_FUNCTION_TRACE(ev_init_global_lock_handler); 349 ACPI_FUNCTION_TRACE(ev_init_global_lock_handler);
369 350
351 status =
352 acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
353 (struct acpi_table_header **)&facs);
354 if (ACPI_FAILURE(status)) {
355 return_ACPI_STATUS(status);
356 }
357
370 acpi_gbl_global_lock_present = TRUE; 358 acpi_gbl_global_lock_present = TRUE;
371 status = acpi_install_fixed_event_handler(ACPI_EVENT_GLOBAL, 359 status = acpi_install_fixed_event_handler(ACPI_EVENT_GLOBAL,
372 acpi_ev_global_lock_handler, 360 acpi_ev_global_lock_handler,
@@ -390,6 +378,31 @@ acpi_status acpi_ev_init_global_lock_handler(void)
390 return_ACPI_STATUS(status); 378 return_ACPI_STATUS(status);
391} 379}
392 380
381/*******************************************************************************
382 *
383 * FUNCTION: acpi_ev_remove_global_lock_handler
384 *
385 * PARAMETERS: None
386 *
387 * RETURN: Status
388 *
389 * DESCRIPTION: Remove the handler for the Global Lock
390 *
391 ******************************************************************************/
392
393static acpi_status acpi_ev_remove_global_lock_handler(void)
394{
395 acpi_status status;
396
397 ACPI_FUNCTION_TRACE(ev_remove_global_lock_handler);
398
399 acpi_gbl_global_lock_present = FALSE;
400 status = acpi_remove_fixed_event_handler(ACPI_EVENT_GLOBAL,
401 acpi_ev_global_lock_handler);
402
403 return_ACPI_STATUS(status);
404}
405
393/****************************************************************************** 406/******************************************************************************
394 * 407 *
395 * FUNCTION: acpi_ev_acquire_global_lock 408 * FUNCTION: acpi_ev_acquire_global_lock
@@ -400,6 +413,16 @@ acpi_status acpi_ev_init_global_lock_handler(void)
400 * 413 *
401 * DESCRIPTION: Attempt to gain ownership of the Global Lock. 414 * DESCRIPTION: Attempt to gain ownership of the Global Lock.
402 * 415 *
416 * MUTEX: Interpreter must be locked
417 *
418 * Note: The original implementation allowed multiple threads to "acquire" the
419 * Global Lock, and the OS would hold the lock until the last thread had
420 * released it. However, this could potentially starve the BIOS out of the
421 * lock, especially in the case where there is a tight handshake between the
422 * Embedded Controller driver and the BIOS. Therefore, this implementation
423 * allows only one thread to acquire the HW Global Lock at a time, and makes
424 * the global lock appear as a standard mutex on the OS side.
425 *
403 *****************************************************************************/ 426 *****************************************************************************/
404 427
405acpi_status acpi_ev_acquire_global_lock(u16 timeout) 428acpi_status acpi_ev_acquire_global_lock(u16 timeout)
@@ -409,53 +432,51 @@ acpi_status acpi_ev_acquire_global_lock(u16 timeout)
409 432
410 ACPI_FUNCTION_TRACE(ev_acquire_global_lock); 433 ACPI_FUNCTION_TRACE(ev_acquire_global_lock);
411 434
412#ifndef ACPI_APPLICATION 435 /*
413 /* Make sure that we actually have a global lock */ 436 * Only one thread can acquire the GL at a time, the global_lock_mutex
414 437 * enforces this. This interface releases the interpreter if we must wait.
415 if (!acpi_gbl_global_lock_present) { 438 */
416 return_ACPI_STATUS(AE_NO_GLOBAL_LOCK); 439 status = acpi_ex_system_wait_mutex(acpi_gbl_global_lock_mutex, timeout);
440 if (ACPI_FAILURE(status)) {
441 return_ACPI_STATUS(status);
417 } 442 }
418#endif
419
420 /* One more thread wants the global lock */
421
422 acpi_gbl_global_lock_thread_count++;
423 443
424 /* 444 /*
425 * If we (OS side vs. BIOS side) have the hardware lock already, 445 * Make sure that a global lock actually exists. If not, just treat
426 * we are done 446 * the lock as a standard mutex.
427 */ 447 */
428 if (acpi_gbl_global_lock_acquired) { 448 if (!acpi_gbl_global_lock_present) {
449 acpi_gbl_global_lock_acquired = TRUE;
429 return_ACPI_STATUS(AE_OK); 450 return_ACPI_STATUS(AE_OK);
430 } 451 }
431 452
432 /* We must acquire the actual hardware lock */ 453 /* Attempt to acquire the actual hardware lock */
433 454
434 ACPI_ACQUIRE_GLOBAL_LOCK(acpi_gbl_common_fACS.global_lock, acquired); 455 ACPI_ACQUIRE_GLOBAL_LOCK(facs, acquired);
435 if (acquired) { 456 if (acquired) {
436 457
437 /* We got the lock */ 458 /* We got the lock */
438 459
439 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 460 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
440 "Acquired the HW Global Lock\n")); 461 "Acquired hardware Global Lock\n"));
441 462
442 acpi_gbl_global_lock_acquired = TRUE; 463 acpi_gbl_global_lock_acquired = TRUE;
443 return_ACPI_STATUS(AE_OK); 464 return_ACPI_STATUS(AE_OK);
444 } 465 }
445 466
446 /* 467 /*
447 * Did not get the lock. The pending bit was set above, and we must now 468 * Did not get the lock. The pending bit was set above, and we must now
448 * wait until we get the global lock released interrupt. 469 * wait until we get the global lock released interrupt.
449 */ 470 */
450 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Waiting for the HW Global Lock\n")); 471 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Waiting for hardware Global Lock\n"));
451 472
452 /* 473 /*
453 * Acquire the global lock semaphore first. 474 * Wait for handshake with the global lock interrupt handler.
454 * Since this wait will block, we must release the interpreter 475 * This interface releases the interpreter if we must wait.
455 */ 476 */
456 status = 477 status = acpi_ex_system_wait_semaphore(acpi_gbl_global_lock_semaphore,
457 acpi_ex_system_wait_semaphore(acpi_gbl_global_lock_semaphore, 478 ACPI_WAIT_FOREVER);
458 timeout); 479
459 return_ACPI_STATUS(status); 480 return_ACPI_STATUS(status);
460} 481}
461 482
@@ -478,38 +499,39 @@ acpi_status acpi_ev_release_global_lock(void)
478 499
479 ACPI_FUNCTION_TRACE(ev_release_global_lock); 500 ACPI_FUNCTION_TRACE(ev_release_global_lock);
480 501
481 if (!acpi_gbl_global_lock_thread_count) { 502 /* Lock must be already acquired */
503
504 if (!acpi_gbl_global_lock_acquired) {
482 ACPI_WARNING((AE_INFO, 505 ACPI_WARNING((AE_INFO,
483 "Cannot release HW Global Lock, it has not been acquired")); 506 "Cannot release the ACPI Global Lock, it has not been acquired"));
484 return_ACPI_STATUS(AE_NOT_ACQUIRED); 507 return_ACPI_STATUS(AE_NOT_ACQUIRED);
485 } 508 }
486 509
487 /* One fewer thread has the global lock */ 510 if (acpi_gbl_global_lock_present) {
488 511
489 acpi_gbl_global_lock_thread_count--; 512 /* Allow any thread to release the lock */
490 if (acpi_gbl_global_lock_thread_count) {
491 513
492 /* There are still some threads holding the lock, cannot release */ 514 ACPI_RELEASE_GLOBAL_LOCK(facs, pending);
493 515
494 return_ACPI_STATUS(AE_OK); 516 /*
517 * If the pending bit was set, we must write GBL_RLS to the control
518 * register
519 */
520 if (pending) {
521 status =
522 acpi_set_register(ACPI_BITREG_GLOBAL_LOCK_RELEASE,
523 1);
524 }
525
526 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
527 "Released hardware Global Lock\n"));
495 } 528 }
496 529
497 /*
498 * No more threads holding lock, we can do the actual hardware
499 * release
500 */
501 ACPI_RELEASE_GLOBAL_LOCK(acpi_gbl_common_fACS.global_lock, pending);
502 acpi_gbl_global_lock_acquired = FALSE; 530 acpi_gbl_global_lock_acquired = FALSE;
503 531
504 /* 532 /* Release the local GL mutex */
505 * If the pending bit was set, we must write GBL_RLS to the control
506 * register
507 */
508 if (pending) {
509 status = acpi_set_register(ACPI_BITREG_GLOBAL_LOCK_RELEASE,
510 1, ACPI_MTX_LOCK);
511 }
512 533
534 acpi_os_release_mutex(acpi_gbl_global_lock_mutex);
513 return_ACPI_STATUS(status); 535 return_ACPI_STATUS(status);
514} 536}
515 537
@@ -559,6 +581,12 @@ void acpi_ev_terminate(void)
559 if (ACPI_FAILURE(status)) { 581 if (ACPI_FAILURE(status)) {
560 ACPI_ERROR((AE_INFO, "Could not remove SCI handler")); 582 ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));
561 } 583 }
584
585 status = acpi_ev_remove_global_lock_handler();
586 if (ACPI_FAILURE(status)) {
587 ACPI_ERROR((AE_INFO,
588 "Could not remove Global Lock handler"));
589 }
562 } 590 }
563 591
564 /* Deallocate all handler objects installed within GPE info structs */ 592 /* Deallocate all handler objects installed within GPE info structs */
diff --git a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c
index 21caae04fe..e99f0c435a 100644
--- a/drivers/acpi/events/evregion.c
+++ b/drivers/acpi/events/evregion.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -291,7 +291,6 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
291 u32 bit_width, acpi_integer * value) 291 u32 bit_width, acpi_integer * value)
292{ 292{
293 acpi_status status; 293 acpi_status status;
294 acpi_status status2;
295 acpi_adr_space_handler handler; 294 acpi_adr_space_handler handler;
296 acpi_adr_space_setup region_setup; 295 acpi_adr_space_setup region_setup;
297 union acpi_operand_object *handler_desc; 296 union acpi_operand_object *handler_desc;
@@ -345,7 +344,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
345 * setup will potentially execute control methods 344 * setup will potentially execute control methods
346 * (e.g., _REG method for this region) 345 * (e.g., _REG method for this region)
347 */ 346 */
348 acpi_ex_exit_interpreter(); 347 acpi_ex_relinquish_interpreter();
349 348
350 status = region_setup(region_obj, ACPI_REGION_ACTIVATE, 349 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
351 handler_desc->address_space.context, 350 handler_desc->address_space.context,
@@ -353,10 +352,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
353 352
354 /* Re-enter the interpreter */ 353 /* Re-enter the interpreter */
355 354
356 status2 = acpi_ex_enter_interpreter(); 355 acpi_ex_reacquire_interpreter();
357 if (ACPI_FAILURE(status2)) {
358 return_ACPI_STATUS(status2);
359 }
360 356
361 /* Check for failure of the Region Setup */ 357 /* Check for failure of the Region Setup */
362 358
@@ -409,7 +405,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
409 * exit the interpreter because the handler *might* block -- we don't 405 * exit the interpreter because the handler *might* block -- we don't
410 * know what it will do, so we can't hold the lock on the intepreter. 406 * know what it will do, so we can't hold the lock on the intepreter.
411 */ 407 */
412 acpi_ex_exit_interpreter(); 408 acpi_ex_relinquish_interpreter();
413 } 409 }
414 410
415 /* Call the handler */ 411 /* Call the handler */
@@ -430,10 +426,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
430 * We just returned from a non-default handler, we must re-enter the 426 * We just returned from a non-default handler, we must re-enter the
431 * interpreter 427 * interpreter
432 */ 428 */
433 status2 = acpi_ex_enter_interpreter(); 429 acpi_ex_reacquire_interpreter();
434 if (ACPI_FAILURE(status2)) {
435 return_ACPI_STATUS(status2);
436 }
437 } 430 }
438 431
439 return_ACPI_STATUS(status); 432 return_ACPI_STATUS(status);
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c
index 203d135919..a4fa7e6822 100644
--- a/drivers/acpi/events/evrgnini.c
+++ b/drivers/acpi/events/evrgnini.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -48,6 +48,11 @@
48#define _COMPONENT ACPI_EVENTS 48#define _COMPONENT ACPI_EVENTS
49ACPI_MODULE_NAME("evrgnini") 49ACPI_MODULE_NAME("evrgnini")
50 50
51/* Local prototypes */
52static u8 acpi_ev_match_pci_root_bridge(char *id);
53
54static u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node);
55
51/******************************************************************************* 56/*******************************************************************************
52 * 57 *
53 * FUNCTION: acpi_ev_system_memory_region_setup 58 * FUNCTION: acpi_ev_system_memory_region_setup
@@ -62,6 +67,7 @@ ACPI_MODULE_NAME("evrgnini")
62 * DESCRIPTION: Setup a system_memory operation region 67 * DESCRIPTION: Setup a system_memory operation region
63 * 68 *
64 ******************************************************************************/ 69 ******************************************************************************/
70
65acpi_status 71acpi_status
66acpi_ev_system_memory_region_setup(acpi_handle handle, 72acpi_ev_system_memory_region_setup(acpi_handle handle,
67 u32 function, 73 u32 function,
@@ -168,9 +174,9 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
168 union acpi_operand_object *handler_obj; 174 union acpi_operand_object *handler_obj;
169 struct acpi_namespace_node *parent_node; 175 struct acpi_namespace_node *parent_node;
170 struct acpi_namespace_node *pci_root_node; 176 struct acpi_namespace_node *pci_root_node;
177 struct acpi_namespace_node *pci_device_node;
171 union acpi_operand_object *region_obj = 178 union acpi_operand_object *region_obj =
172 (union acpi_operand_object *)handle; 179 (union acpi_operand_object *)handle;
173 struct acpi_device_id object_hID;
174 180
175 ACPI_FUNCTION_TRACE(ev_pci_config_region_setup); 181 ACPI_FUNCTION_TRACE(ev_pci_config_region_setup);
176 182
@@ -215,45 +221,30 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
215 221
216 pci_root_node = parent_node; 222 pci_root_node = parent_node;
217 while (pci_root_node != acpi_gbl_root_node) { 223 while (pci_root_node != acpi_gbl_root_node) {
218 status =
219 acpi_ut_execute_HID(pci_root_node, &object_hID);
220 if (ACPI_SUCCESS(status)) {
221 /*
222 * Got a valid _HID string, check if this is a PCI root.
223 * New for ACPI 3.0: check for a PCI Express root also.
224 */
225 if (!
226 (ACPI_STRNCMP
227 (object_hID.value, PCI_ROOT_HID_STRING,
228 sizeof(PCI_ROOT_HID_STRING)))
229 ||
230 !(ACPI_STRNCMP
231 (object_hID.value,
232 PCI_EXPRESS_ROOT_HID_STRING,
233 sizeof(PCI_EXPRESS_ROOT_HID_STRING)))) {
234
235 /* Install a handler for this PCI root bridge */
236 224
237 status = 225 /* Get the _HID/_CID in order to detect a root_bridge */
238 acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL); 226
239 if (ACPI_FAILURE(status)) { 227 if (acpi_ev_is_pci_root_bridge(pci_root_node)) {
240 if (status == AE_SAME_HANDLER) { 228
241 /* 229 /* Install a handler for this PCI root bridge */
242 * It is OK if the handler is already installed on the root 230
243 * bridge. Still need to return a context object for the 231 status = acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
244 * new PCI_Config operation region, however. 232 if (ACPI_FAILURE(status)) {
245 */ 233 if (status == AE_SAME_HANDLER) {
246 status = AE_OK; 234 /*
247 } else { 235 * It is OK if the handler is already installed on the root
248 ACPI_EXCEPTION((AE_INFO, 236 * bridge. Still need to return a context object for the
249 status, 237 * new PCI_Config operation region, however.
250 "Could not install PciConfig handler for Root Bridge %4.4s", 238 */
251 acpi_ut_get_node_name 239 status = AE_OK;
252 (pci_root_node))); 240 } else {
253 } 241 ACPI_EXCEPTION((AE_INFO, status,
242 "Could not install PciConfig handler for Root Bridge %4.4s",
243 acpi_ut_get_node_name
244 (pci_root_node)));
254 } 245 }
255 break;
256 } 246 }
247 break;
257 } 248 }
258 249
259 pci_root_node = acpi_ns_get_parent_node(pci_root_node); 250 pci_root_node = acpi_ns_get_parent_node(pci_root_node);
@@ -282,14 +273,25 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
282 /* 273 /*
283 * For PCI_Config space access, we need the segment, bus, 274 * For PCI_Config space access, we need the segment, bus,
284 * device and function numbers. Acquire them here. 275 * device and function numbers. Acquire them here.
276 *
277 * Find the parent device object. (This allows the operation region to be
278 * within a subscope under the device, such as a control method.)
285 */ 279 */
280 pci_device_node = region_obj->region.node;
281 while (pci_device_node && (pci_device_node->type != ACPI_TYPE_DEVICE)) {
282 pci_device_node = acpi_ns_get_parent_node(pci_device_node);
283 }
284
285 if (!pci_device_node) {
286 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
287 }
286 288
287 /* 289 /*
288 * Get the PCI device and function numbers from the _ADR object 290 * Get the PCI device and function numbers from the _ADR object
289 * contained in the parent's scope. 291 * contained in the parent's scope.
290 */ 292 */
291 status = 293 status =
292 acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, parent_node, 294 acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, pci_device_node,
293 &pci_value); 295 &pci_value);
294 296
295 /* 297 /*
@@ -329,6 +331,91 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
329 331
330/******************************************************************************* 332/*******************************************************************************
331 * 333 *
334 * FUNCTION: acpi_ev_match_pci_root_bridge
335 *
336 * PARAMETERS: Id - The HID/CID in string format
337 *
338 * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
339 *
340 * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
341 *
342 ******************************************************************************/
343
344static u8 acpi_ev_match_pci_root_bridge(char *id)
345{
346
347 /*
348 * Check if this is a PCI root.
349 * ACPI 3.0+: check for a PCI Express root also.
350 */
351 if (!(ACPI_STRNCMP(id,
352 PCI_ROOT_HID_STRING,
353 sizeof(PCI_ROOT_HID_STRING))) ||
354 !(ACPI_STRNCMP(id,
355 PCI_EXPRESS_ROOT_HID_STRING,
356 sizeof(PCI_EXPRESS_ROOT_HID_STRING)))) {
357 return (TRUE);
358 }
359
360 return (FALSE);
361}
362
363/*******************************************************************************
364 *
365 * FUNCTION: acpi_ev_is_pci_root_bridge
366 *
367 * PARAMETERS: Node - Device node being examined
368 *
369 * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge
370 *
371 * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
372 * examining the _HID and _CID for the device.
373 *
374 ******************************************************************************/
375
376static u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node)
377{
378 acpi_status status;
379 struct acpi_device_id hid;
380 struct acpi_compatible_id_list *cid;
381 acpi_native_uint i;
382
383 /*
384 * Get the _HID and check for a PCI Root Bridge
385 */
386 status = acpi_ut_execute_HID(node, &hid);
387 if (ACPI_FAILURE(status)) {
388 return (FALSE);
389 }
390
391 if (acpi_ev_match_pci_root_bridge(hid.value)) {
392 return (TRUE);
393 }
394
395 /*
396 * The _HID did not match.
397 * Get the _CID and check for a PCI Root Bridge
398 */
399 status = acpi_ut_execute_CID(node, &cid);
400 if (ACPI_FAILURE(status)) {
401 return (FALSE);
402 }
403
404 /* Check all _CIDs in the returned list */
405
406 for (i = 0; i < cid->count; i++) {
407 if (acpi_ev_match_pci_root_bridge(cid->id[i].value)) {
408 ACPI_FREE(cid);
409 return (TRUE);
410 }
411 }
412
413 ACPI_FREE(cid);
414 return (FALSE);
415}
416
417/*******************************************************************************
418 *
332 * FUNCTION: acpi_ev_pci_bar_region_setup 419 * FUNCTION: acpi_ev_pci_bar_region_setup
333 * 420 *
334 * PARAMETERS: Handle - Region we are interested in 421 * PARAMETERS: Handle - Region we are interested in
@@ -432,6 +519,9 @@ acpi_ev_default_region_setup(acpi_handle handle,
432 * a PCI address in the scope of the definition. This address is 519 * a PCI address in the scope of the definition. This address is
433 * required to perform an access to PCI config space. 520 * required to perform an access to PCI config space.
434 * 521 *
522 * MUTEX: Interpreter should be unlocked, because we may run the _REG
523 * method for this region.
524 *
435 ******************************************************************************/ 525 ******************************************************************************/
436 526
437acpi_status 527acpi_status
diff --git a/drivers/acpi/events/evsci.c b/drivers/acpi/events/evsci.c
index 8106215ad5..7e5d15ce23 100644
--- a/drivers/acpi/events/evsci.c
+++ b/drivers/acpi/events/evsci.c
@@ -6,7 +6,7 @@
6 ******************************************************************************/ 6 ******************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -142,9 +142,10 @@ u32 acpi_ev_install_sci_handler(void)
142 142
143 ACPI_FUNCTION_TRACE(ev_install_sci_handler); 143 ACPI_FUNCTION_TRACE(ev_install_sci_handler);
144 144
145 status = acpi_os_install_interrupt_handler((u32) acpi_gbl_FADT->sci_int, 145 status =
146 acpi_ev_sci_xrupt_handler, 146 acpi_os_install_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
147 acpi_gbl_gpe_xrupt_list_head); 147 acpi_ev_sci_xrupt_handler,
148 acpi_gbl_gpe_xrupt_list_head);
148 return_ACPI_STATUS(status); 149 return_ACPI_STATUS(status);
149} 150}
150 151
@@ -175,8 +176,9 @@ acpi_status acpi_ev_remove_sci_handler(void)
175 176
176 /* Just let the OS remove the handler and disable the level */ 177 /* Just let the OS remove the handler and disable the level */
177 178
178 status = acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT->sci_int, 179 status =
179 acpi_ev_sci_xrupt_handler); 180 acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
181 acpi_ev_sci_xrupt_handler);
180 182
181 return_ACPI_STATUS(status); 183 return_ACPI_STATUS(status);
182} 184}
diff --git a/drivers/acpi/events/evxface.c b/drivers/acpi/events/evxface.c
index 923fd2b469..685a103a35 100644
--- a/drivers/acpi/events/evxface.c
+++ b/drivers/acpi/events/evxface.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -768,11 +768,9 @@ acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
768 return (AE_BAD_PARAMETER); 768 return (AE_BAD_PARAMETER);
769 } 769 }
770 770
771 status = acpi_ex_enter_interpreter(); 771 /* Must lock interpreter to prevent race conditions */
772 if (ACPI_FAILURE(status)) {
773 return (status);
774 }
775 772
773 acpi_ex_enter_interpreter();
776 status = acpi_ev_acquire_global_lock(timeout); 774 status = acpi_ev_acquire_global_lock(timeout);
777 acpi_ex_exit_interpreter(); 775 acpi_ex_exit_interpreter();
778 776
diff --git a/drivers/acpi/events/evxfevnt.c b/drivers/acpi/events/evxfevnt.c
index 7ebc2efac9..17065e9880 100644
--- a/drivers/acpi/events/evxfevnt.c
+++ b/drivers/acpi/events/evxfevnt.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
44#include <acpi/acpi.h> 44#include <acpi/acpi.h>
45#include <acpi/acevents.h> 45#include <acpi/acevents.h>
46#include <acpi/acnamesp.h> 46#include <acpi/acnamesp.h>
47#include <acpi/actables.h>
47 48
48#define _COMPONENT ACPI_EVENTS 49#define _COMPONENT ACPI_EVENTS
49ACPI_MODULE_NAME("evxfevnt") 50ACPI_MODULE_NAME("evxfevnt")
@@ -65,13 +66,14 @@ acpi_status acpi_enable(void)
65 66
66 ACPI_FUNCTION_TRACE(acpi_enable); 67 ACPI_FUNCTION_TRACE(acpi_enable);
67 68
68 /* Make sure we have the FADT */ 69 /* ACPI tables must be present */
69 70
70 if (!acpi_gbl_FADT) { 71 if (!acpi_tb_tables_loaded()) {
71 ACPI_WARNING((AE_INFO, "No FADT information present!"));
72 return_ACPI_STATUS(AE_NO_ACPI_TABLES); 72 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
73 } 73 }
74 74
75 /* Check current mode */
76
75 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) { 77 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
76 ACPI_DEBUG_PRINT((ACPI_DB_INIT, 78 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
77 "System is already in ACPI mode\n")); 79 "System is already in ACPI mode\n"));
@@ -111,11 +113,6 @@ acpi_status acpi_disable(void)
111 113
112 ACPI_FUNCTION_TRACE(acpi_disable); 114 ACPI_FUNCTION_TRACE(acpi_disable);
113 115
114 if (!acpi_gbl_FADT) {
115 ACPI_WARNING((AE_INFO, "No FADT information present!"));
116 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
117 }
118
119 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) { 116 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
120 ACPI_DEBUG_PRINT((ACPI_DB_INIT, 117 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
121 "System is already in legacy (non-ACPI) mode\n")); 118 "System is already in legacy (non-ACPI) mode\n"));
@@ -169,7 +166,7 @@ acpi_status acpi_enable_event(u32 event, u32 flags)
169 */ 166 */
170 status = 167 status =
171 acpi_set_register(acpi_gbl_fixed_event_info[event]. 168 acpi_set_register(acpi_gbl_fixed_event_info[event].
172 enable_register_id, 1, ACPI_MTX_LOCK); 169 enable_register_id, 1);
173 if (ACPI_FAILURE(status)) { 170 if (ACPI_FAILURE(status)) {
174 return_ACPI_STATUS(status); 171 return_ACPI_STATUS(status);
175 } 172 }
@@ -178,7 +175,7 @@ acpi_status acpi_enable_event(u32 event, u32 flags)
178 175
179 status = 176 status =
180 acpi_get_register(acpi_gbl_fixed_event_info[event]. 177 acpi_get_register(acpi_gbl_fixed_event_info[event].
181 enable_register_id, &value, ACPI_MTX_LOCK); 178 enable_register_id, &value);
182 if (ACPI_FAILURE(status)) { 179 if (ACPI_FAILURE(status)) {
183 return_ACPI_STATUS(status); 180 return_ACPI_STATUS(status);
184 } 181 }
@@ -368,14 +365,14 @@ acpi_status acpi_disable_event(u32 event, u32 flags)
368 */ 365 */
369 status = 366 status =
370 acpi_set_register(acpi_gbl_fixed_event_info[event]. 367 acpi_set_register(acpi_gbl_fixed_event_info[event].
371 enable_register_id, 0, ACPI_MTX_LOCK); 368 enable_register_id, 0);
372 if (ACPI_FAILURE(status)) { 369 if (ACPI_FAILURE(status)) {
373 return_ACPI_STATUS(status); 370 return_ACPI_STATUS(status);
374 } 371 }
375 372
376 status = 373 status =
377 acpi_get_register(acpi_gbl_fixed_event_info[event]. 374 acpi_get_register(acpi_gbl_fixed_event_info[event].
378 enable_register_id, &value, ACPI_MTX_LOCK); 375 enable_register_id, &value);
379 if (ACPI_FAILURE(status)) { 376 if (ACPI_FAILURE(status)) {
380 return_ACPI_STATUS(status); 377 return_ACPI_STATUS(status);
381 } 378 }
@@ -421,7 +418,7 @@ acpi_status acpi_clear_event(u32 event)
421 */ 418 */
422 status = 419 status =
423 acpi_set_register(acpi_gbl_fixed_event_info[event]. 420 acpi_set_register(acpi_gbl_fixed_event_info[event].
424 status_register_id, 1, ACPI_MTX_LOCK); 421 status_register_id, 1);
425 422
426 return_ACPI_STATUS(status); 423 return_ACPI_STATUS(status);
427} 424}
@@ -510,7 +507,7 @@ acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
510 507
511 status = 508 status =
512 acpi_get_register(acpi_gbl_fixed_event_info[event]. 509 acpi_get_register(acpi_gbl_fixed_event_info[event].
513 status_register_id, event_status, ACPI_MTX_LOCK); 510 status_register_id, event_status);
514 511
515 return_ACPI_STATUS(status); 512 return_ACPI_STATUS(status);
516} 513}
diff --git a/drivers/acpi/events/evxfregn.c b/drivers/acpi/events/evxfregn.c
index 83b12a9afa..7bf09c5fb2 100644
--- a/drivers/acpi/events/evxfregn.c
+++ b/drivers/acpi/events/evxfregn.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c
index c8341fa5fe..25802f302f 100644
--- a/drivers/acpi/executer/exconfig.c
+++ b/drivers/acpi/executer/exconfig.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -54,7 +54,7 @@ ACPI_MODULE_NAME("exconfig")
54 54
55/* Local prototypes */ 55/* Local prototypes */
56static acpi_status 56static acpi_status
57acpi_ex_add_table(struct acpi_table_header *table, 57acpi_ex_add_table(acpi_native_uint table_index,
58 struct acpi_namespace_node *parent_node, 58 struct acpi_namespace_node *parent_node,
59 union acpi_operand_object **ddb_handle); 59 union acpi_operand_object **ddb_handle);
60 60
@@ -74,12 +74,11 @@ acpi_ex_add_table(struct acpi_table_header *table,
74 ******************************************************************************/ 74 ******************************************************************************/
75 75
76static acpi_status 76static acpi_status
77acpi_ex_add_table(struct acpi_table_header *table, 77acpi_ex_add_table(acpi_native_uint table_index,
78 struct acpi_namespace_node *parent_node, 78 struct acpi_namespace_node *parent_node,
79 union acpi_operand_object **ddb_handle) 79 union acpi_operand_object **ddb_handle)
80{ 80{
81 acpi_status status; 81 acpi_status status;
82 struct acpi_table_desc table_info;
83 union acpi_operand_object *obj_desc; 82 union acpi_operand_object *obj_desc;
84 83
85 ACPI_FUNCTION_TRACE(ex_add_table); 84 ACPI_FUNCTION_TRACE(ex_add_table);
@@ -98,42 +97,16 @@ acpi_ex_add_table(struct acpi_table_header *table,
98 97
99 /* Install the new table into the local data structures */ 98 /* Install the new table into the local data structures */
100 99
101 ACPI_MEMSET(&table_info, 0, sizeof(struct acpi_table_desc)); 100 obj_desc->reference.object = ACPI_CAST_PTR(void, table_index);
102
103 table_info.type = ACPI_TABLE_ID_SSDT;
104 table_info.pointer = table;
105 table_info.length = (acpi_size) table->length;
106 table_info.allocation = ACPI_MEM_ALLOCATED;
107
108 status = acpi_tb_install_table(&table_info);
109 obj_desc->reference.object = table_info.installed_desc;
110
111 if (ACPI_FAILURE(status)) {
112 if (status == AE_ALREADY_EXISTS) {
113
114 /* Table already exists, just return the handle */
115
116 return_ACPI_STATUS(AE_OK);
117 }
118 goto cleanup;
119 }
120 101
121 /* Add the table to the namespace */ 102 /* Add the table to the namespace */
122 103
123 status = acpi_ns_load_table(table_info.installed_desc, parent_node); 104 status = acpi_ns_load_table(table_index, parent_node);
124 if (ACPI_FAILURE(status)) { 105 if (ACPI_FAILURE(status)) {
125 106 acpi_ut_remove_reference(obj_desc);
126 /* Uninstall table on error */ 107 *ddb_handle = NULL;
127
128 (void)acpi_tb_uninstall_table(table_info.installed_desc);
129 goto cleanup;
130 } 108 }
131 109
132 return_ACPI_STATUS(AE_OK);
133
134 cleanup:
135 acpi_ut_remove_reference(obj_desc);
136 *ddb_handle = NULL;
137 return_ACPI_STATUS(status); 110 return_ACPI_STATUS(status);
138} 111}
139 112
@@ -146,7 +119,7 @@ acpi_ex_add_table(struct acpi_table_header *table,
146 * 119 *
147 * RETURN: Status 120 * RETURN: Status
148 * 121 *
149 * DESCRIPTION: Load an ACPI table 122 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
150 * 123 *
151 ******************************************************************************/ 124 ******************************************************************************/
152 125
@@ -156,33 +129,20 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
156{ 129{
157 acpi_status status; 130 acpi_status status;
158 union acpi_operand_object **operand = &walk_state->operands[0]; 131 union acpi_operand_object **operand = &walk_state->operands[0];
159 struct acpi_table_header *table; 132 acpi_native_uint table_index;
160 struct acpi_namespace_node *parent_node; 133 struct acpi_namespace_node *parent_node;
161 struct acpi_namespace_node *start_node; 134 struct acpi_namespace_node *start_node;
162 struct acpi_namespace_node *parameter_node = NULL; 135 struct acpi_namespace_node *parameter_node = NULL;
163 union acpi_operand_object *ddb_handle; 136 union acpi_operand_object *ddb_handle;
137 struct acpi_table_header *table;
164 138
165 ACPI_FUNCTION_TRACE(ex_load_table_op); 139 ACPI_FUNCTION_TRACE(ex_load_table_op);
166 140
167#if 0 141 /* Find the ACPI table in the RSDT/XSDT */
168 /*
169 * Make sure that the signature does not match one of the tables that
170 * is already loaded.
171 */
172 status = acpi_tb_match_signature(operand[0]->string.pointer, NULL);
173 if (status == AE_OK) {
174
175 /* Signature matched -- don't allow override */
176
177 return_ACPI_STATUS(AE_ALREADY_EXISTS);
178 }
179#endif
180
181 /* Find the ACPI table */
182 142
183 status = acpi_tb_find_table(operand[0]->string.pointer, 143 status = acpi_tb_find_table(operand[0]->string.pointer,
184 operand[1]->string.pointer, 144 operand[1]->string.pointer,
185 operand[2]->string.pointer, &table); 145 operand[2]->string.pointer, &table_index);
186 if (ACPI_FAILURE(status)) { 146 if (ACPI_FAILURE(status)) {
187 if (status != AE_NOT_FOUND) { 147 if (status != AE_NOT_FOUND) {
188 return_ACPI_STATUS(status); 148 return_ACPI_STATUS(status);
@@ -245,7 +205,7 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
245 205
246 /* Load the table into the namespace */ 206 /* Load the table into the namespace */
247 207
248 status = acpi_ex_add_table(table, parent_node, &ddb_handle); 208 status = acpi_ex_add_table(table_index, parent_node, &ddb_handle);
249 if (ACPI_FAILURE(status)) { 209 if (ACPI_FAILURE(status)) {
250 return_ACPI_STATUS(status); 210 return_ACPI_STATUS(status);
251 } 211 }
@@ -266,9 +226,13 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
266 } 226 }
267 } 227 }
268 228
269 ACPI_INFO((AE_INFO, 229 status = acpi_get_table_by_index(table_index, &table);
270 "Dynamic OEM Table Load - [%4.4s] OemId [%6.6s] OemTableId [%8.8s]", 230 if (ACPI_SUCCESS(status)) {
271 table->signature, table->oem_id, table->oem_table_id)); 231 ACPI_INFO((AE_INFO,
232 "Dynamic OEM Table Load - [%4.4s] OemId [%6.6s] OemTableId [%8.8s]",
233 table->signature, table->oem_id,
234 table->oem_table_id));
235 }
272 236
273 *return_desc = ddb_handle; 237 *return_desc = ddb_handle;
274 return_ACPI_STATUS(status); 238 return_ACPI_STATUS(status);
@@ -278,7 +242,7 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
278 * 242 *
279 * FUNCTION: acpi_ex_load_op 243 * FUNCTION: acpi_ex_load_op
280 * 244 *
281 * PARAMETERS: obj_desc - Region or Field where the table will be 245 * PARAMETERS: obj_desc - Region or Buffer/Field where the table will be
282 * obtained 246 * obtained
283 * Target - Where a handle to the table will be stored 247 * Target - Where a handle to the table will be stored
284 * walk_state - Current state 248 * walk_state - Current state
@@ -287,6 +251,12 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
287 * 251 *
288 * DESCRIPTION: Load an ACPI table from a field or operation region 252 * DESCRIPTION: Load an ACPI table from a field or operation region
289 * 253 *
254 * NOTE: Region Fields (Field, bank_field, index_fields) are resolved to buffer
255 * objects before this code is reached.
256 *
257 * If source is an operation region, it must refer to system_memory, as
258 * per the ACPI specification.
259 *
290 ******************************************************************************/ 260 ******************************************************************************/
291 261
292acpi_status 262acpi_status
@@ -294,22 +264,26 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
294 union acpi_operand_object *target, 264 union acpi_operand_object *target,
295 struct acpi_walk_state *walk_state) 265 struct acpi_walk_state *walk_state)
296{ 266{
297 acpi_status status;
298 union acpi_operand_object *ddb_handle; 267 union acpi_operand_object *ddb_handle;
299 union acpi_operand_object *buffer_desc = NULL; 268 struct acpi_table_desc table_desc;
300 struct acpi_table_header *table_ptr = NULL; 269 acpi_native_uint table_index;
301 acpi_physical_address address; 270 acpi_status status;
302 struct acpi_table_header table_header;
303 acpi_integer temp;
304 u32 i;
305 271
306 ACPI_FUNCTION_TRACE(ex_load_op); 272 ACPI_FUNCTION_TRACE(ex_load_op);
307 273
308 /* Object can be either an op_region or a Field */ 274 ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
275
276 /* Source Object can be either an op_region or a Buffer/Field */
309 277
310 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 278 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
311 case ACPI_TYPE_REGION: 279 case ACPI_TYPE_REGION:
312 280
281 /* Region must be system_memory (from ACPI spec) */
282
283 if (obj_desc->region.space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) {
284 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
285 }
286
313 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Region %p %s\n", 287 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Region %p %s\n",
314 obj_desc, 288 obj_desc,
315 acpi_ut_get_object_type_name(obj_desc))); 289 acpi_ut_get_object_type_name(obj_desc)));
@@ -325,113 +299,41 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
325 } 299 }
326 } 300 }
327 301
328 /* Get the base physical address of the region */ 302 table_desc.address = obj_desc->region.address;
329 303 table_desc.length = obj_desc->region.length;
330 address = obj_desc->region.address; 304 table_desc.flags = ACPI_TABLE_ORIGIN_MAPPED;
331
332 /* Get part of the table header to get the table length */
333
334 table_header.length = 0;
335 for (i = 0; i < 8; i++) {
336 status =
337 acpi_ev_address_space_dispatch(obj_desc, ACPI_READ,
338 (acpi_physical_address)
339 (i + address), 8,
340 &temp);
341 if (ACPI_FAILURE(status)) {
342 return_ACPI_STATUS(status);
343 }
344
345 /* Get the one valid byte of the returned 64-bit value */
346
347 ACPI_CAST_PTR(u8, &table_header)[i] = (u8) temp;
348 }
349
350 /* Sanity check the table length */
351
352 if (table_header.length < sizeof(struct acpi_table_header)) {
353 return_ACPI_STATUS(AE_BAD_HEADER);
354 }
355
356 /* Allocate a buffer for the entire table */
357
358 table_ptr = ACPI_ALLOCATE(table_header.length);
359 if (!table_ptr) {
360 return_ACPI_STATUS(AE_NO_MEMORY);
361 }
362
363 /* Get the entire table from the op region */
364
365 for (i = 0; i < table_header.length; i++) {
366 status =
367 acpi_ev_address_space_dispatch(obj_desc, ACPI_READ,
368 (acpi_physical_address)
369 (i + address), 8,
370 &temp);
371 if (ACPI_FAILURE(status)) {
372 goto cleanup;
373 }
374
375 /* Get the one valid byte of the returned 64-bit value */
376
377 ACPI_CAST_PTR(u8, table_ptr)[i] = (u8) temp;
378 }
379 break; 305 break;
380 306
381 case ACPI_TYPE_LOCAL_REGION_FIELD: 307 case ACPI_TYPE_BUFFER: /* Buffer or resolved region_field */
382 case ACPI_TYPE_LOCAL_BANK_FIELD:
383 case ACPI_TYPE_LOCAL_INDEX_FIELD:
384 308
385 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Field %p %s\n", 309 /* Simply extract the buffer from the buffer object */
386 obj_desc,
387 acpi_ut_get_object_type_name(obj_desc)));
388 310
389 /* 311 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
390 * The length of the field must be at least as large as the table. 312 "Load from Buffer or Field %p %s\n", obj_desc,
391 * Read the entire field and thus the entire table. Buffer is 313 acpi_ut_get_object_type_name(obj_desc)));
392 * allocated during the read.
393 */
394 status =
395 acpi_ex_read_data_from_field(walk_state, obj_desc,
396 &buffer_desc);
397 if (ACPI_FAILURE(status)) {
398 return_ACPI_STATUS(status);
399 }
400
401 table_ptr = ACPI_CAST_PTR(struct acpi_table_header,
402 buffer_desc->buffer.pointer);
403
404 /* All done with the buffer_desc, delete it */
405
406 buffer_desc->buffer.pointer = NULL;
407 acpi_ut_remove_reference(buffer_desc);
408 314
409 /* Sanity check the table length */ 315 table_desc.pointer = ACPI_CAST_PTR(struct acpi_table_header,
316 obj_desc->buffer.pointer);
317 table_desc.length = table_desc.pointer->length;
318 table_desc.flags = ACPI_TABLE_ORIGIN_ALLOCATED;
410 319
411 if (table_ptr->length < sizeof(struct acpi_table_header)) { 320 obj_desc->buffer.pointer = NULL;
412 status = AE_BAD_HEADER;
413 goto cleanup;
414 }
415 break; 321 break;
416 322
417 default: 323 default:
418 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 324 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
419 } 325 }
420 326
421 /* The table must be either an SSDT or a PSDT */ 327 /*
422 328 * Install the new table into the local data structures
423 if ((!ACPI_COMPARE_NAME(table_ptr->signature, PSDT_SIG)) && 329 */
424 (!ACPI_COMPARE_NAME(table_ptr->signature, SSDT_SIG))) { 330 status = acpi_tb_add_table(&table_desc, &table_index);
425 ACPI_ERROR((AE_INFO, 331 if (ACPI_FAILURE(status)) {
426 "Table has invalid signature [%4.4s], must be SSDT or PSDT",
427 table_ptr->signature));
428 status = AE_BAD_SIGNATURE;
429 goto cleanup; 332 goto cleanup;
430 } 333 }
431 334
432 /* Install the new table into the local data structures */ 335 status =
433 336 acpi_ex_add_table(table_index, acpi_gbl_root_node, &ddb_handle);
434 status = acpi_ex_add_table(table_ptr, acpi_gbl_root_node, &ddb_handle);
435 if (ACPI_FAILURE(status)) { 337 if (ACPI_FAILURE(status)) {
436 338
437 /* On error, table_ptr was deallocated above */ 339 /* On error, table_ptr was deallocated above */
@@ -450,13 +352,9 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
450 return_ACPI_STATUS(status); 352 return_ACPI_STATUS(status);
451 } 353 }
452 354
453 ACPI_INFO((AE_INFO,
454 "Dynamic SSDT Load - OemId [%6.6s] OemTableId [%8.8s]",
455 table_ptr->oem_id, table_ptr->oem_table_id));
456
457 cleanup: 355 cleanup:
458 if (ACPI_FAILURE(status)) { 356 if (ACPI_FAILURE(status)) {
459 ACPI_FREE(table_ptr); 357 acpi_tb_delete_table(&table_desc);
460 } 358 }
461 return_ACPI_STATUS(status); 359 return_ACPI_STATUS(status);
462} 360}
@@ -477,7 +375,7 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
477{ 375{
478 acpi_status status = AE_OK; 376 acpi_status status = AE_OK;
479 union acpi_operand_object *table_desc = ddb_handle; 377 union acpi_operand_object *table_desc = ddb_handle;
480 struct acpi_table_desc *table_info; 378 acpi_native_uint table_index;
481 379
482 ACPI_FUNCTION_TRACE(ex_unload_table); 380 ACPI_FUNCTION_TRACE(ex_unload_table);
483 381
@@ -493,19 +391,18 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
493 return_ACPI_STATUS(AE_BAD_PARAMETER); 391 return_ACPI_STATUS(AE_BAD_PARAMETER);
494 } 392 }
495 393
496 /* Get the actual table descriptor from the ddb_handle */ 394 /* Get the table index from the ddb_handle */
497 395
498 table_info = (struct acpi_table_desc *)table_desc->reference.object; 396 table_index = (acpi_native_uint) table_desc->reference.object;
499 397
500 /* 398 /*
501 * Delete the entire namespace under this table Node 399 * Delete the entire namespace under this table Node
502 * (Offset contains the table_id) 400 * (Offset contains the table_id)
503 */ 401 */
504 acpi_ns_delete_namespace_by_owner(table_info->owner_id); 402 acpi_tb_delete_namespace_by_owner(table_index);
505 403 acpi_tb_release_owner_id(table_index);
506 /* Delete the table itself */
507 404
508 (void)acpi_tb_uninstall_table(table_info->installed_desc); 405 acpi_tb_set_table_loaded_flag(table_index, FALSE);
509 406
510 /* Delete the table descriptor (ddb_handle) */ 407 /* Delete the table descriptor (ddb_handle) */
511 408
diff --git a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c
index 544e81a6a4..d470e8b1f4 100644
--- a/drivers/acpi/executer/exconvrt.c
+++ b/drivers/acpi/executer/exconvrt.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/excreate.c b/drivers/acpi/executer/excreate.c
index 34eec82c1b..7c38528a7e 100644
--- a/drivers/acpi/executer/excreate.c
+++ b/drivers/acpi/executer/excreate.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -359,8 +359,9 @@ acpi_status acpi_ex_create_table_region(struct acpi_walk_state *walk_state)
359 union acpi_operand_object **operand = &walk_state->operands[0]; 359 union acpi_operand_object **operand = &walk_state->operands[0];
360 union acpi_operand_object *obj_desc; 360 union acpi_operand_object *obj_desc;
361 struct acpi_namespace_node *node; 361 struct acpi_namespace_node *node;
362 struct acpi_table_header *table;
363 union acpi_operand_object *region_obj2; 362 union acpi_operand_object *region_obj2;
363 acpi_native_uint table_index;
364 struct acpi_table_header *table;
364 365
365 ACPI_FUNCTION_TRACE(ex_create_table_region); 366 ACPI_FUNCTION_TRACE(ex_create_table_region);
366 367
@@ -380,7 +381,7 @@ acpi_status acpi_ex_create_table_region(struct acpi_walk_state *walk_state)
380 381
381 status = acpi_tb_find_table(operand[1]->string.pointer, 382 status = acpi_tb_find_table(operand[1]->string.pointer,
382 operand[2]->string.pointer, 383 operand[2]->string.pointer,
383 operand[3]->string.pointer, &table); 384 operand[3]->string.pointer, &table_index);
384 if (ACPI_FAILURE(status)) { 385 if (ACPI_FAILURE(status)) {
385 return_ACPI_STATUS(status); 386 return_ACPI_STATUS(status);
386 } 387 }
@@ -395,6 +396,11 @@ acpi_status acpi_ex_create_table_region(struct acpi_walk_state *walk_state)
395 region_obj2 = obj_desc->common.next_object; 396 region_obj2 = obj_desc->common.next_object;
396 region_obj2->extra.region_context = NULL; 397 region_obj2->extra.region_context = NULL;
397 398
399 status = acpi_get_table_by_index(table_index, &table);
400 if (ACPI_FAILURE(status)) {
401 return_ACPI_STATUS(status);
402 }
403
398 /* Init the region from the operands */ 404 /* Init the region from the operands */
399 405
400 obj_desc->region.space_id = REGION_DATA_TABLE; 406 obj_desc->region.space_id = REGION_DATA_TABLE;
@@ -553,7 +559,8 @@ acpi_ex_create_method(u8 * aml_start,
553 559
554 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_METHOD); 560 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
555 if (!obj_desc) { 561 if (!obj_desc) {
556 return_ACPI_STATUS(AE_NO_MEMORY); 562 status = AE_NO_MEMORY;
563 goto exit;
557 } 564 }
558 565
559 /* Save the method's AML pointer and length */ 566 /* Save the method's AML pointer and length */
@@ -576,10 +583,7 @@ acpi_ex_create_method(u8 * aml_start,
576 * Get the sync_level. If method is serialized, a mutex will be 583 * Get the sync_level. If method is serialized, a mutex will be
577 * created for this method when it is parsed. 584 * created for this method when it is parsed.
578 */ 585 */
579 if (acpi_gbl_all_methods_serialized) { 586 if (method_flags & AML_METHOD_SERIALIZED) {
580 obj_desc->method.sync_level = 0;
581 obj_desc->method.method_flags |= AML_METHOD_SERIALIZED;
582 } else if (method_flags & AML_METHOD_SERIALIZED) {
583 /* 587 /*
584 * ACPI 1.0: sync_level = 0 588 * ACPI 1.0: sync_level = 0
585 * ACPI 2.0: sync_level = sync_level in method declaration 589 * ACPI 2.0: sync_level = sync_level in method declaration
@@ -597,6 +601,7 @@ acpi_ex_create_method(u8 * aml_start,
597 601
598 acpi_ut_remove_reference(obj_desc); 602 acpi_ut_remove_reference(obj_desc);
599 603
604 exit:
600 /* Remove a reference to the operand */ 605 /* Remove a reference to the operand */
601 606
602 acpi_ut_remove_reference(operand[1]); 607 acpi_ut_remove_reference(operand[1]);
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
index 2450943add..68d283fd60 100644
--- a/drivers/acpi/executer/exdump.c
+++ b/drivers/acpi/executer/exdump.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -59,8 +59,6 @@ static void acpi_ex_out_string(char *title, char *value);
59 59
60static void acpi_ex_out_pointer(char *title, void *value); 60static void acpi_ex_out_pointer(char *title, void *value);
61 61
62static void acpi_ex_out_address(char *title, acpi_physical_address value);
63
64static void 62static void
65acpi_ex_dump_object(union acpi_operand_object *obj_desc, 63acpi_ex_dump_object(union acpi_operand_object *obj_desc,
66 struct acpi_exdump_info *info); 64 struct acpi_exdump_info *info);
@@ -92,10 +90,11 @@ static struct acpi_exdump_info acpi_ex_dump_string[4] = {
92 {ACPI_EXD_STRING, 0, NULL} 90 {ACPI_EXD_STRING, 0, NULL}
93}; 91};
94 92
95static struct acpi_exdump_info acpi_ex_dump_buffer[4] = { 93static struct acpi_exdump_info acpi_ex_dump_buffer[5] = {
96 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_buffer), NULL}, 94 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_buffer), NULL},
97 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(buffer.length), "Length"}, 95 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(buffer.length), "Length"},
98 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer.pointer), "Pointer"}, 96 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer.pointer), "Pointer"},
97 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer.node), "Parent Node"},
99 {ACPI_EXD_BUFFER, 0, NULL} 98 {ACPI_EXD_BUFFER, 0, NULL}
100}; 99};
101 100
@@ -165,8 +164,8 @@ static struct acpi_exdump_info acpi_ex_dump_power[5] = {
165 164
166static struct acpi_exdump_info acpi_ex_dump_processor[7] = { 165static struct acpi_exdump_info acpi_ex_dump_processor[7] = {
167 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_processor), NULL}, 166 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_processor), NULL},
168 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(processor.proc_id), "Processor ID"}, 167 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(processor.proc_id), "Processor ID"},
169 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(processor.length), "Length"}, 168 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(processor.length), "Length"},
170 {ACPI_EXD_ADDRESS, ACPI_EXD_OFFSET(processor.address), "Address"}, 169 {ACPI_EXD_ADDRESS, ACPI_EXD_OFFSET(processor.address), "Address"},
171 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(processor.system_notify), 170 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(processor.system_notify),
172 "System Notify"}, 171 "System Notify"},
@@ -379,18 +378,12 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
379 break; 378 break;
380 379
381 case ACPI_EXD_POINTER: 380 case ACPI_EXD_POINTER:
381 case ACPI_EXD_ADDRESS:
382 382
383 acpi_ex_out_pointer(name, 383 acpi_ex_out_pointer(name,
384 *ACPI_CAST_PTR(void *, target)); 384 *ACPI_CAST_PTR(void *, target));
385 break; 385 break;
386 386
387 case ACPI_EXD_ADDRESS:
388
389 acpi_ex_out_address(name,
390 *ACPI_CAST_PTR
391 (acpi_physical_address, target));
392 break;
393
394 case ACPI_EXD_STRING: 387 case ACPI_EXD_STRING:
395 388
396 acpi_ut_print_string(obj_desc->string.pointer, 389 acpi_ut_print_string(obj_desc->string.pointer,
@@ -834,16 +827,6 @@ static void acpi_ex_out_pointer(char *title, void *value)
834 acpi_os_printf("%20s : %p\n", title, value); 827 acpi_os_printf("%20s : %p\n", title, value);
835} 828}
836 829
837static void acpi_ex_out_address(char *title, acpi_physical_address value)
838{
839
840#if ACPI_MACHINE_WIDTH == 16
841 acpi_os_printf("%20s : %p\n", title, value);
842#else
843 acpi_os_printf("%20s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
844#endif
845}
846
847/******************************************************************************* 830/*******************************************************************************
848 * 831 *
849 * FUNCTION: acpi_ex_dump_namespace_node 832 * FUNCTION: acpi_ex_dump_namespace_node
diff --git a/drivers/acpi/executer/exfield.c b/drivers/acpi/executer/exfield.c
index 9ea9c3a67c..2d88a3d8d1 100644
--- a/drivers/acpi/executer/exfield.c
+++ b/drivers/acpi/executer/exfield.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exfldio.c b/drivers/acpi/executer/exfldio.c
index 40f0bee6fa..65a48b6170 100644
--- a/drivers/acpi/executer/exfldio.c
+++ b/drivers/acpi/executer/exfldio.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -257,14 +257,13 @@ acpi_ex_access_region(union acpi_operand_object *obj_desc,
257 } 257 }
258 258
259 ACPI_DEBUG_PRINT_RAW((ACPI_DB_BFIELD, 259 ACPI_DEBUG_PRINT_RAW((ACPI_DB_BFIELD,
260 " Region [%s:%X], Width %X, ByteBase %X, Offset %X at %8.8X%8.8X\n", 260 " Region [%s:%X], Width %X, ByteBase %X, Offset %X at %p\n",
261 acpi_ut_get_region_name(rgn_desc->region. 261 acpi_ut_get_region_name(rgn_desc->region.
262 space_id), 262 space_id),
263 rgn_desc->region.space_id, 263 rgn_desc->region.space_id,
264 obj_desc->common_field.access_byte_width, 264 obj_desc->common_field.access_byte_width,
265 obj_desc->common_field.base_byte_offset, 265 obj_desc->common_field.base_byte_offset,
266 field_datum_byte_offset, 266 field_datum_byte_offset, (void *)address));
267 ACPI_FORMAT_UINT64(address)));
268 267
269 /* Invoke the appropriate address_space/op_region handler */ 268 /* Invoke the appropriate address_space/op_region handler */
270 269
diff --git a/drivers/acpi/executer/exmisc.c b/drivers/acpi/executer/exmisc.c
index bd98aab017..f13d1cec2d 100644
--- a/drivers/acpi/executer/exmisc.c
+++ b/drivers/acpi/executer/exmisc.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index 3a39c2e8e1..5101bad5ba 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
44 44
45#include <acpi/acpi.h> 45#include <acpi/acpi.h>
46#include <acpi/acinterp.h> 46#include <acpi/acinterp.h>
47#include <acpi/acevents.h>
47 48
48#define _COMPONENT ACPI_EXECUTER 49#define _COMPONENT ACPI_EXECUTER
49ACPI_MODULE_NAME("exmutex") 50ACPI_MODULE_NAME("exmutex")
@@ -150,7 +151,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
150 return_ACPI_STATUS(AE_BAD_PARAMETER); 151 return_ACPI_STATUS(AE_BAD_PARAMETER);
151 } 152 }
152 153
153 /* Sanity check -- we must have a valid thread ID */ 154 /* Sanity check: we must have a valid thread ID */
154 155
155 if (!walk_state->thread) { 156 if (!walk_state->thread) {
156 ACPI_ERROR((AE_INFO, 157 ACPI_ERROR((AE_INFO,
@@ -174,24 +175,28 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
174 /* Support for multiple acquires by the owning thread */ 175 /* Support for multiple acquires by the owning thread */
175 176
176 if (obj_desc->mutex.owner_thread) { 177 if (obj_desc->mutex.owner_thread) {
177 178 if (obj_desc->mutex.owner_thread->thread_id ==
178 /* Special case for Global Lock, allow all threads */ 179 walk_state->thread->thread_id) {
179
180 if ((obj_desc->mutex.owner_thread->thread_id ==
181 walk_state->thread->thread_id) ||
182 (obj_desc->mutex.os_mutex == ACPI_GLOBAL_LOCK)) {
183 /* 180 /*
184 * The mutex is already owned by this thread, 181 * The mutex is already owned by this thread, just increment the
185 * just increment the acquisition depth 182 * acquisition depth
186 */ 183 */
187 obj_desc->mutex.acquisition_depth++; 184 obj_desc->mutex.acquisition_depth++;
188 return_ACPI_STATUS(AE_OK); 185 return_ACPI_STATUS(AE_OK);
189 } 186 }
190 } 187 }
191 188
192 /* Acquire the mutex, wait if necessary */ 189 /* Acquire the mutex, wait if necessary. Special case for Global Lock */
190
191 if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) {
192 status =
193 acpi_ev_acquire_global_lock((u16) time_desc->integer.value);
194 } else {
195 status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex,
196 (u16) time_desc->integer.
197 value);
198 }
193 199
194 status = acpi_ex_system_acquire_mutex(time_desc, obj_desc);
195 if (ACPI_FAILURE(status)) { 200 if (ACPI_FAILURE(status)) {
196 201
197 /* Includes failure from a timeout on time_desc */ 202 /* Includes failure from a timeout on time_desc */
@@ -211,7 +216,6 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
211 /* Link the mutex to the current thread for force-unlock at method exit */ 216 /* Link the mutex to the current thread for force-unlock at method exit */
212 217
213 acpi_ex_link_mutex(obj_desc, walk_state->thread); 218 acpi_ex_link_mutex(obj_desc, walk_state->thread);
214
215 return_ACPI_STATUS(AE_OK); 219 return_ACPI_STATUS(AE_OK);
216} 220}
217 221
@@ -232,7 +236,7 @@ acpi_status
232acpi_ex_release_mutex(union acpi_operand_object *obj_desc, 236acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
233 struct acpi_walk_state *walk_state) 237 struct acpi_walk_state *walk_state)
234{ 238{
235 acpi_status status; 239 acpi_status status = AE_OK;
236 240
237 ACPI_FUNCTION_TRACE(ex_release_mutex); 241 ACPI_FUNCTION_TRACE(ex_release_mutex);
238 242
@@ -249,7 +253,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
249 return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED); 253 return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED);
250 } 254 }
251 255
252 /* Sanity check -- we must have a valid thread ID */ 256 /* Sanity check: we must have a valid thread ID */
253 257
254 if (!walk_state->thread) { 258 if (!walk_state->thread) {
255 ACPI_ERROR((AE_INFO, 259 ACPI_ERROR((AE_INFO,
@@ -264,18 +268,18 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
264 */ 268 */
265 if ((obj_desc->mutex.owner_thread->thread_id != 269 if ((obj_desc->mutex.owner_thread->thread_id !=
266 walk_state->thread->thread_id) 270 walk_state->thread->thread_id)
267 && (obj_desc->mutex.os_mutex != ACPI_GLOBAL_LOCK)) { 271 && (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) {
268 ACPI_ERROR((AE_INFO, 272 ACPI_ERROR((AE_INFO,
269 "Thread %X cannot release Mutex [%4.4s] acquired by thread %X", 273 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
270 (u32) walk_state->thread->thread_id, 274 (unsigned long)walk_state->thread->thread_id,
271 acpi_ut_get_node_name(obj_desc->mutex.node), 275 acpi_ut_get_node_name(obj_desc->mutex.node),
272 (u32) obj_desc->mutex.owner_thread->thread_id)); 276 (unsigned long)obj_desc->mutex.owner_thread->thread_id));
273 return_ACPI_STATUS(AE_AML_NOT_OWNER); 277 return_ACPI_STATUS(AE_AML_NOT_OWNER);
274 } 278 }
275 279
276 /* 280 /*
277 * The sync level of the mutex must be less than or 281 * The sync level of the mutex must be less than or equal to the current
278 * equal to the current sync level 282 * sync level
279 */ 283 */
280 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) { 284 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) {
281 ACPI_ERROR((AE_INFO, 285 ACPI_ERROR((AE_INFO,
@@ -298,11 +302,15 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
298 302
299 acpi_ex_unlink_mutex(obj_desc); 303 acpi_ex_unlink_mutex(obj_desc);
300 304
301 /* Release the mutex */ 305 /* Release the mutex, special case for Global Lock */
302 306
303 status = acpi_ex_system_release_mutex(obj_desc); 307 if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) {
308 status = acpi_ev_release_global_lock();
309 } else {
310 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
311 }
304 312
305 /* Update the mutex and walk state, restore sync_level before acquire */ 313 /* Update the mutex and restore sync_level */
306 314
307 obj_desc->mutex.owner_thread = NULL; 315 obj_desc->mutex.owner_thread = NULL;
308 walk_state->thread->current_sync_level = 316 walk_state->thread->current_sync_level =
@@ -321,39 +329,49 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
321 * 329 *
322 * DESCRIPTION: Release all mutexes held by this thread 330 * DESCRIPTION: Release all mutexes held by this thread
323 * 331 *
332 * NOTE: This function is called as the thread is exiting the interpreter.
333 * Mutexes are not released when an individual control method is exited, but
334 * only when the parent thread actually exits the interpreter. This allows one
335 * method to acquire a mutex, and a different method to release it, as long as
336 * this is performed underneath a single parent control method.
337 *
324 ******************************************************************************/ 338 ******************************************************************************/
325 339
326void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread) 340void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
327{ 341{
328 union acpi_operand_object *next = thread->acquired_mutex_list; 342 union acpi_operand_object *next = thread->acquired_mutex_list;
329 union acpi_operand_object *this; 343 union acpi_operand_object *obj_desc;
330 acpi_status status;
331 344
332 ACPI_FUNCTION_ENTRY(); 345 ACPI_FUNCTION_ENTRY();
333 346
334 /* Traverse the list of owned mutexes, releasing each one */ 347 /* Traverse the list of owned mutexes, releasing each one */
335 348
336 while (next) { 349 while (next) {
337 this = next; 350 obj_desc = next;
338 next = this->mutex.next; 351 next = obj_desc->mutex.next;
352
353 obj_desc->mutex.prev = NULL;
354 obj_desc->mutex.next = NULL;
355 obj_desc->mutex.acquisition_depth = 0;
356
357 /* Release the mutex, special case for Global Lock */
339 358
340 this->mutex.acquisition_depth = 1; 359 if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) {
341 this->mutex.prev = NULL;
342 this->mutex.next = NULL;
343 360
344 /* Release the mutex */ 361 /* Ignore errors */
345 362
346 status = acpi_ex_system_release_mutex(this); 363 (void)acpi_ev_release_global_lock();
347 if (ACPI_FAILURE(status)) { 364 } else {
348 continue; 365 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
349 } 366 }
350 367
351 /* Mark mutex unowned */ 368 /* Mark mutex unowned */
352 369
353 this->mutex.owner_thread = NULL; 370 obj_desc->mutex.owner_thread = NULL;
354 371
355 /* Update Thread sync_level (Last mutex is the important one) */ 372 /* Update Thread sync_level (Last mutex is the important one) */
356 373
357 thread->current_sync_level = this->mutex.original_sync_level; 374 thread->current_sync_level =
375 obj_desc->mutex.original_sync_level;
358 } 376 }
359} 377}
diff --git a/drivers/acpi/executer/exnames.c b/drivers/acpi/executer/exnames.c
index d3d7036462..1ee4fb1175 100644
--- a/drivers/acpi/executer/exnames.c
+++ b/drivers/acpi/executer/exnames.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exoparg1.c b/drivers/acpi/executer/exoparg1.c
index 6374d8be88..252f10acbb 100644
--- a/drivers/acpi/executer/exoparg1.c
+++ b/drivers/acpi/executer/exoparg1.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -104,9 +104,7 @@ acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
104 status = AE_NO_MEMORY; 104 status = AE_NO_MEMORY;
105 goto cleanup; 105 goto cleanup;
106 } 106 }
107#if ACPI_MACHINE_WIDTH != 16
108 return_desc->integer.value = acpi_os_get_timer(); 107 return_desc->integer.value = acpi_os_get_timer();
109#endif
110 break; 108 break;
111 109
112 default: /* Unknown opcode */ 110 default: /* Unknown opcode */
diff --git a/drivers/acpi/executer/exoparg2.c b/drivers/acpi/executer/exoparg2.c
index 7d2cbc1131..17e652e653 100644
--- a/drivers/acpi/executer/exoparg2.c
+++ b/drivers/acpi/executer/exoparg2.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exoparg3.c b/drivers/acpi/executer/exoparg3.c
index e2d945dfd5..7fe67cf82c 100644
--- a/drivers/acpi/executer/exoparg3.c
+++ b/drivers/acpi/executer/exoparg3.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exoparg6.c b/drivers/acpi/executer/exoparg6.c
index f0c0ba6eb4..bd80a9cb3d 100644
--- a/drivers/acpi/executer/exoparg6.c
+++ b/drivers/acpi/executer/exoparg6.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exprep.c b/drivers/acpi/executer/exprep.c
index 44d064f427..a6696621ff 100644
--- a/drivers/acpi/executer/exprep.c
+++ b/drivers/acpi/executer/exprep.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exregion.c b/drivers/acpi/executer/exregion.c
index 3cc97ba48b..2e9ce94798 100644
--- a/drivers/acpi/executer/exregion.c
+++ b/drivers/acpi/executer/exregion.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -155,16 +155,15 @@ acpi_ex_system_memory_space_handler(u32 function,
155 155
156 /* Create a new mapping starting at the address given */ 156 /* Create a new mapping starting at the address given */
157 157
158 status = acpi_os_map_memory(address, window_size, 158 mem_info->mapped_logical_address =
159 (void **)&mem_info-> 159 acpi_os_map_memory((acpi_native_uint) address, window_size);
160 mapped_logical_address); 160 if (!mem_info->mapped_logical_address) {
161 if (ACPI_FAILURE(status)) {
162 ACPI_ERROR((AE_INFO, 161 ACPI_ERROR((AE_INFO,
163 "Could not map memory at %8.8X%8.8X, size %X", 162 "Could not map memory at %8.8X%8.8X, size %X",
164 ACPI_FORMAT_UINT64(address), 163 ACPI_FORMAT_UINT64(address),
165 (u32) window_size)); 164 (u32) window_size));
166 mem_info->mapped_length = 0; 165 mem_info->mapped_length = 0;
167 return_ACPI_STATUS(status); 166 return_ACPI_STATUS(AE_NO_MEMORY);
168 } 167 }
169 168
170 /* Save the physical address and mapping size */ 169 /* Save the physical address and mapping size */
@@ -210,11 +209,10 @@ acpi_ex_system_memory_space_handler(u32 function,
210 *value = (acpi_integer) ACPI_GET32(logical_addr_ptr); 209 *value = (acpi_integer) ACPI_GET32(logical_addr_ptr);
211 break; 210 break;
212 211
213#if ACPI_MACHINE_WIDTH != 16
214 case 64: 212 case 64:
215 *value = (acpi_integer) ACPI_GET64(logical_addr_ptr); 213 *value = (acpi_integer) ACPI_GET64(logical_addr_ptr);
216 break; 214 break;
217#endif 215
218 default: 216 default:
219 /* bit_width was already validated */ 217 /* bit_width was already validated */
220 break; 218 break;
@@ -236,11 +234,9 @@ acpi_ex_system_memory_space_handler(u32 function,
236 ACPI_SET32(logical_addr_ptr) = (u32) * value; 234 ACPI_SET32(logical_addr_ptr) = (u32) * value;
237 break; 235 break;
238 236
239#if ACPI_MACHINE_WIDTH != 16
240 case 64: 237 case 64:
241 ACPI_SET64(logical_addr_ptr) = (u64) * value; 238 ACPI_SET64(logical_addr_ptr) = (u64) * value;
242 break; 239 break;
243#endif
244 240
245 default: 241 default:
246 /* bit_width was already validated */ 242 /* bit_width was already validated */
diff --git a/drivers/acpi/executer/exresnte.c b/drivers/acpi/executer/exresnte.c
index 3089b05a13..2b3a01cc49 100644
--- a/drivers/acpi/executer/exresnte.c
+++ b/drivers/acpi/executer/exresnte.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exresolv.c b/drivers/acpi/executer/exresolv.c
index 6499de8780..6c64e55dab 100644
--- a/drivers/acpi/executer/exresolv.c
+++ b/drivers/acpi/executer/exresolv.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -141,7 +141,7 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
141 acpi_status status = AE_OK; 141 acpi_status status = AE_OK;
142 union acpi_operand_object *stack_desc; 142 union acpi_operand_object *stack_desc;
143 void *temp_node; 143 void *temp_node;
144 union acpi_operand_object *obj_desc; 144 union acpi_operand_object *obj_desc = NULL;
145 u16 opcode; 145 u16 opcode;
146 146
147 ACPI_FUNCTION_TRACE(ex_resolve_object_to_value); 147 ACPI_FUNCTION_TRACE(ex_resolve_object_to_value);
@@ -299,8 +299,6 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
299 status = acpi_ds_get_package_arguments(stack_desc); 299 status = acpi_ds_get_package_arguments(stack_desc);
300 break; 300 break;
301 301
302 /* These cases may never happen here, but just in case.. */
303
304 case ACPI_TYPE_BUFFER_FIELD: 302 case ACPI_TYPE_BUFFER_FIELD:
305 case ACPI_TYPE_LOCAL_REGION_FIELD: 303 case ACPI_TYPE_LOCAL_REGION_FIELD:
306 case ACPI_TYPE_LOCAL_BANK_FIELD: 304 case ACPI_TYPE_LOCAL_BANK_FIELD:
@@ -314,6 +312,10 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
314 status = 312 status =
315 acpi_ex_read_data_from_field(walk_state, stack_desc, 313 acpi_ex_read_data_from_field(walk_state, stack_desc,
316 &obj_desc); 314 &obj_desc);
315
316 /* Remove a reference to the original operand, then override */
317
318 acpi_ut_remove_reference(*stack_ptr);
317 *stack_ptr = (void *)obj_desc; 319 *stack_ptr = (void *)obj_desc;
318 break; 320 break;
319 321
diff --git a/drivers/acpi/executer/exresop.c b/drivers/acpi/executer/exresop.c
index 4c93d09723..ba761862a5 100644
--- a/drivers/acpi/executer/exresop.c
+++ b/drivers/acpi/executer/exresop.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -611,22 +611,20 @@ acpi_ex_resolve_operands(u16 opcode,
611 } 611 }
612 goto next_operand; 612 goto next_operand;
613 613
614 case ARGI_REGION_OR_FIELD: 614 case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
615 615
616 /* Need an operand of type REGION or a FIELD in a region */ 616 /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
617 617
618 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 618 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
619 case ACPI_TYPE_BUFFER:
619 case ACPI_TYPE_REGION: 620 case ACPI_TYPE_REGION:
620 case ACPI_TYPE_LOCAL_REGION_FIELD:
621 case ACPI_TYPE_LOCAL_BANK_FIELD:
622 case ACPI_TYPE_LOCAL_INDEX_FIELD:
623 621
624 /* Valid operand */ 622 /* Valid operand */
625 break; 623 break;
626 624
627 default: 625 default:
628 ACPI_ERROR((AE_INFO, 626 ACPI_ERROR((AE_INFO,
629 "Needed [Region/RegionField], found [%s] %p", 627 "Needed [Region/Buffer], found [%s] %p",
630 acpi_ut_get_object_type_name 628 acpi_ut_get_object_type_name
631 (obj_desc), obj_desc)); 629 (obj_desc), obj_desc));
632 630
diff --git a/drivers/acpi/executer/exstore.c b/drivers/acpi/executer/exstore.c
index 0456405ba0..f4b69a6378 100644
--- a/drivers/acpi/executer/exstore.c
+++ b/drivers/acpi/executer/exstore.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exstoren.c b/drivers/acpi/executer/exstoren.c
index 591aaf0e18..1d622c625c 100644
--- a/drivers/acpi/executer/exstoren.c
+++ b/drivers/acpi/executer/exstoren.c
@@ -7,7 +7,7 @@
7 *****************************************************************************/ 7 *****************************************************************************/
8 8
9/* 9/*
10 * Copyright (C) 2000 - 2006, R. Byron Moore 10 * Copyright (C) 2000 - 2007, R. Byron Moore
11 * All rights reserved. 11 * All rights reserved.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exstorob.c b/drivers/acpi/executer/exstorob.c
index 99ebe5adfc..8233d40178 100644
--- a/drivers/acpi/executer/exstorob.c
+++ b/drivers/acpi/executer/exstorob.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exsystem.c b/drivers/acpi/executer/exsystem.c
index 28aef3e69e..9460baff30 100644
--- a/drivers/acpi/executer/exsystem.c
+++ b/drivers/acpi/executer/exsystem.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -66,7 +66,6 @@ ACPI_MODULE_NAME("exsystem")
66acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout) 66acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
67{ 67{
68 acpi_status status; 68 acpi_status status;
69 acpi_status status2;
70 69
71 ACPI_FUNCTION_TRACE(ex_system_wait_semaphore); 70 ACPI_FUNCTION_TRACE(ex_system_wait_semaphore);
72 71
@@ -79,7 +78,7 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
79 78
80 /* We must wait, so unlock the interpreter */ 79 /* We must wait, so unlock the interpreter */
81 80
82 acpi_ex_exit_interpreter(); 81 acpi_ex_relinquish_interpreter();
83 82
84 status = acpi_os_wait_semaphore(semaphore, 1, timeout); 83 status = acpi_os_wait_semaphore(semaphore, 1, timeout);
85 84
@@ -89,13 +88,7 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
89 88
90 /* Reacquire the interpreter */ 89 /* Reacquire the interpreter */
91 90
92 status2 = acpi_ex_enter_interpreter(); 91 acpi_ex_reacquire_interpreter();
93 if (ACPI_FAILURE(status2)) {
94
95 /* Report fatal error, could not acquire interpreter */
96
97 return_ACPI_STATUS(status2);
98 }
99 } 92 }
100 93
101 return_ACPI_STATUS(status); 94 return_ACPI_STATUS(status);
@@ -119,7 +112,6 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
119acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout) 112acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
120{ 113{
121 acpi_status status; 114 acpi_status status;
122 acpi_status status2;
123 115
124 ACPI_FUNCTION_TRACE(ex_system_wait_mutex); 116 ACPI_FUNCTION_TRACE(ex_system_wait_mutex);
125 117
@@ -132,7 +124,7 @@ acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
132 124
133 /* We must wait, so unlock the interpreter */ 125 /* We must wait, so unlock the interpreter */
134 126
135 acpi_ex_exit_interpreter(); 127 acpi_ex_relinquish_interpreter();
136 128
137 status = acpi_os_acquire_mutex(mutex, timeout); 129 status = acpi_os_acquire_mutex(mutex, timeout);
138 130
@@ -142,13 +134,7 @@ acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
142 134
143 /* Reacquire the interpreter */ 135 /* Reacquire the interpreter */
144 136
145 status2 = acpi_ex_enter_interpreter(); 137 acpi_ex_reacquire_interpreter();
146 if (ACPI_FAILURE(status2)) {
147
148 /* Report fatal error, could not acquire interpreter */
149
150 return_ACPI_STATUS(status2);
151 }
152 } 138 }
153 139
154 return_ACPI_STATUS(status); 140 return_ACPI_STATUS(status);
@@ -209,96 +195,18 @@ acpi_status acpi_ex_system_do_stall(u32 how_long)
209 195
210acpi_status acpi_ex_system_do_suspend(acpi_integer how_long) 196acpi_status acpi_ex_system_do_suspend(acpi_integer how_long)
211{ 197{
212 acpi_status status;
213
214 ACPI_FUNCTION_ENTRY(); 198 ACPI_FUNCTION_ENTRY();
215 199
216 /* Since this thread will sleep, we must release the interpreter */ 200 /* Since this thread will sleep, we must release the interpreter */
217 201
218 acpi_ex_exit_interpreter(); 202 acpi_ex_relinquish_interpreter();
219 203
220 acpi_os_sleep(how_long); 204 acpi_os_sleep(how_long);
221 205
222 /* And now we must get the interpreter again */ 206 /* And now we must get the interpreter again */
223 207
224 status = acpi_ex_enter_interpreter(); 208 acpi_ex_reacquire_interpreter();
225 return (status); 209 return (AE_OK);
226}
227
228/*******************************************************************************
229 *
230 * FUNCTION: acpi_ex_system_acquire_mutex
231 *
232 * PARAMETERS: time_desc - Maximum time to wait for the mutex
233 * obj_desc - The object descriptor for this op
234 *
235 * RETURN: Status
236 *
237 * DESCRIPTION: Provides an access point to perform synchronization operations
238 * within the AML. This function will cause a lock to be generated
239 * for the Mutex pointed to by obj_desc.
240 *
241 ******************************************************************************/
242
243acpi_status
244acpi_ex_system_acquire_mutex(union acpi_operand_object * time_desc,
245 union acpi_operand_object * obj_desc)
246{
247 acpi_status status = AE_OK;
248
249 ACPI_FUNCTION_TRACE_PTR(ex_system_acquire_mutex, obj_desc);
250
251 if (!obj_desc) {
252 return_ACPI_STATUS(AE_BAD_PARAMETER);
253 }
254
255 /* Support for the _GL_ Mutex object -- go get the global lock */
256
257 if (obj_desc->mutex.os_mutex == ACPI_GLOBAL_LOCK) {
258 status =
259 acpi_ev_acquire_global_lock((u16) time_desc->integer.value);
260 return_ACPI_STATUS(status);
261 }
262
263 status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex,
264 (u16) time_desc->integer.value);
265 return_ACPI_STATUS(status);
266}
267
268/*******************************************************************************
269 *
270 * FUNCTION: acpi_ex_system_release_mutex
271 *
272 * PARAMETERS: obj_desc - The object descriptor for this op
273 *
274 * RETURN: Status
275 *
276 * DESCRIPTION: Provides an access point to perform synchronization operations
277 * within the AML. This operation is a request to release a
278 * previously acquired Mutex. If the Mutex variable is set then
279 * it will be decremented.
280 *
281 ******************************************************************************/
282
283acpi_status acpi_ex_system_release_mutex(union acpi_operand_object *obj_desc)
284{
285 acpi_status status = AE_OK;
286
287 ACPI_FUNCTION_TRACE(ex_system_release_mutex);
288
289 if (!obj_desc) {
290 return_ACPI_STATUS(AE_BAD_PARAMETER);
291 }
292
293 /* Support for the _GL_ Mutex object -- release the global lock */
294
295 if (obj_desc->mutex.os_mutex == ACPI_GLOBAL_LOCK) {
296 status = acpi_ev_release_global_lock();
297 return_ACPI_STATUS(status);
298 }
299
300 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
301 return_ACPI_STATUS(AE_OK);
302} 210}
303 211
304/******************************************************************************* 212/*******************************************************************************
@@ -314,7 +222,7 @@ acpi_status acpi_ex_system_release_mutex(union acpi_operand_object *obj_desc)
314 * 222 *
315 ******************************************************************************/ 223 ******************************************************************************/
316 224
317acpi_status acpi_ex_system_signal_event(union acpi_operand_object *obj_desc) 225acpi_status acpi_ex_system_signal_event(union acpi_operand_object * obj_desc)
318{ 226{
319 acpi_status status = AE_OK; 227 acpi_status status = AE_OK;
320 228
diff --git a/drivers/acpi/executer/exutils.c b/drivers/acpi/executer/exutils.c
index 982c8b6587..6b0aeccbb6 100644
--- a/drivers/acpi/executer/exutils.c
+++ b/drivers/acpi/executer/exutils.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -76,14 +76,15 @@ static u32 acpi_ex_digits_needed(acpi_integer value, u32 base);
76 * 76 *
77 * PARAMETERS: None 77 * PARAMETERS: None
78 * 78 *
79 * RETURN: Status 79 * RETURN: None
80 * 80 *
81 * DESCRIPTION: Enter the interpreter execution region. Failure to enter 81 * DESCRIPTION: Enter the interpreter execution region. Failure to enter
82 * the interpreter region is a fatal system error 82 * the interpreter region is a fatal system error. Used in
83 * conjunction with exit_interpreter.
83 * 84 *
84 ******************************************************************************/ 85 ******************************************************************************/
85 86
86acpi_status acpi_ex_enter_interpreter(void) 87void acpi_ex_enter_interpreter(void)
87{ 88{
88 acpi_status status; 89 acpi_status status;
89 90
@@ -91,31 +92,55 @@ acpi_status acpi_ex_enter_interpreter(void)
91 92
92 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); 93 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
93 if (ACPI_FAILURE(status)) { 94 if (ACPI_FAILURE(status)) {
94 ACPI_ERROR((AE_INFO, "Could not acquire interpreter mutex")); 95 ACPI_ERROR((AE_INFO,
96 "Could not acquire AML Interpreter mutex"));
95 } 97 }
96 98
97 return_ACPI_STATUS(status); 99 return_VOID;
98} 100}
99 101
100/******************************************************************************* 102/*******************************************************************************
101 * 103 *
102 * FUNCTION: acpi_ex_exit_interpreter 104 * FUNCTION: acpi_ex_reacquire_interpreter
103 * 105 *
104 * PARAMETERS: None 106 * PARAMETERS: None
105 * 107 *
106 * RETURN: None 108 * RETURN: None
107 * 109 *
108 * DESCRIPTION: Exit the interpreter execution region 110 * DESCRIPTION: Reacquire the interpreter execution region from within the
111 * interpreter code. Failure to enter the interpreter region is a
112 * fatal system error. Used in conjuction with
113 * relinquish_interpreter
114 *
115 ******************************************************************************/
116
117void acpi_ex_reacquire_interpreter(void)
118{
119 ACPI_FUNCTION_TRACE(ex_reacquire_interpreter);
120
121 /*
122 * If the global serialized flag is set, do not release the interpreter,
123 * since it was not actually released by acpi_ex_relinquish_interpreter.
124 * This forces the interpreter to be single threaded.
125 */
126 if (!acpi_gbl_all_methods_serialized) {
127 acpi_ex_enter_interpreter();
128 }
129
130 return_VOID;
131}
132
133/*******************************************************************************
134 *
135 * FUNCTION: acpi_ex_exit_interpreter
136 *
137 * PARAMETERS: None
138 *
139 * RETURN: None
109 * 140 *
110 * Cases where the interpreter is unlocked: 141 * DESCRIPTION: Exit the interpreter execution region. This is the top level
111 * 1) Completion of the execution of a control method 142 * routine used to exit the interpreter when all processing has
112 * 2) Method blocked on a Sleep() AML opcode 143 * been completed.
113 * 3) Method blocked on an Acquire() AML opcode
114 * 4) Method blocked on a Wait() AML opcode
115 * 5) Method blocked to acquire the global lock
116 * 6) Method blocked to execute a serialized control method that is
117 * already executing
118 * 7) About to invoke a user-installed opregion handler
119 * 144 *
120 ******************************************************************************/ 145 ******************************************************************************/
121 146
@@ -127,7 +152,46 @@ void acpi_ex_exit_interpreter(void)
127 152
128 status = acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); 153 status = acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
129 if (ACPI_FAILURE(status)) { 154 if (ACPI_FAILURE(status)) {
130 ACPI_ERROR((AE_INFO, "Could not release interpreter mutex")); 155 ACPI_ERROR((AE_INFO,
156 "Could not release AML Interpreter mutex"));
157 }
158
159 return_VOID;
160}
161
162/*******************************************************************************
163 *
164 * FUNCTION: acpi_ex_relinquish_interpreter
165 *
166 * PARAMETERS: None
167 *
168 * RETURN: None
169 *
170 * DESCRIPTION: Exit the interpreter execution region, from within the
171 * interpreter - before attempting an operation that will possibly
172 * block the running thread.
173 *
174 * Cases where the interpreter is unlocked internally
175 * 1) Method to be blocked on a Sleep() AML opcode
176 * 2) Method to be blocked on an Acquire() AML opcode
177 * 3) Method to be blocked on a Wait() AML opcode
178 * 4) Method to be blocked to acquire the global lock
179 * 5) Method to be blocked waiting to execute a serialized control method
180 * that is currently executing
181 * 6) About to invoke a user-installed opregion handler
182 *
183 ******************************************************************************/
184
185void acpi_ex_relinquish_interpreter(void)
186{
187 ACPI_FUNCTION_TRACE(ex_relinquish_interpreter);
188
189 /*
190 * If the global serialized flag is set, do not release the interpreter.
191 * This forces the interpreter to be single threaded.
192 */
193 if (!acpi_gbl_all_methods_serialized) {
194 acpi_ex_exit_interpreter();
131 } 195 }
132 196
133 return_VOID; 197 return_VOID;
@@ -141,8 +205,8 @@ void acpi_ex_exit_interpreter(void)
141 * 205 *
142 * RETURN: none 206 * RETURN: none
143 * 207 *
144 * DESCRIPTION: Truncate a number to 32-bits if the currently executing method 208 * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
145 * belongs to a 32-bit ACPI table. 209 * 32-bit, as determined by the revision of the DSDT.
146 * 210 *
147 ******************************************************************************/ 211 ******************************************************************************/
148 212
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index b24942041b..af22fdf734 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -99,8 +99,8 @@ acpi_fan_write_state(struct file *file, const char __user * buffer,
99 size_t count, loff_t * ppos) 99 size_t count, loff_t * ppos)
100{ 100{
101 int result = 0; 101 int result = 0;
102 struct seq_file *m = (struct seq_file *)file->private_data; 102 struct seq_file *m = file->private_data;
103 struct acpi_fan *fan = (struct acpi_fan *)m->private; 103 struct acpi_fan *fan = m->private;
104 char state_string[12] = { '\0' }; 104 char state_string[12] = { '\0' };
105 105
106 106
@@ -186,10 +186,9 @@ static int acpi_fan_add(struct acpi_device *device)
186 if (!device) 186 if (!device)
187 return -EINVAL; 187 return -EINVAL;
188 188
189 fan = kmalloc(sizeof(struct acpi_fan), GFP_KERNEL); 189 fan = kzalloc(sizeof(struct acpi_fan), GFP_KERNEL);
190 if (!fan) 190 if (!fan)
191 return -ENOMEM; 191 return -ENOMEM;
192 memset(fan, 0, sizeof(struct acpi_fan));
193 192
194 fan->device = device; 193 fan->device = device;
195 strcpy(acpi_device_name(device), "Fan"); 194 strcpy(acpi_device_name(device), "Fan");
@@ -229,7 +228,7 @@ static int acpi_fan_remove(struct acpi_device *device, int type)
229 if (!device || !acpi_driver_data(device)) 228 if (!device || !acpi_driver_data(device))
230 return -EINVAL; 229 return -EINVAL;
231 230
232 fan = (struct acpi_fan *)acpi_driver_data(device); 231 fan = acpi_driver_data(device);
233 232
234 acpi_fan_remove_fs(device); 233 acpi_fan_remove_fs(device);
235 234
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index a2f46d587d..7b6c9ff9be 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -86,125 +86,6 @@ static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
86 return ret; 86 return ret;
87} 87}
88 88
89/* Get PCI root bridge's handle from its segment and bus number */
90struct acpi_find_pci_root {
91 unsigned int seg;
92 unsigned int bus;
93 acpi_handle handle;
94};
95
96static acpi_status
97do_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
98{
99 unsigned long *busnr = (unsigned long *)data;
100 struct acpi_resource_address64 address;
101
102 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
103 resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
104 resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
105 return AE_OK;
106
107 acpi_resource_to_address64(resource, &address);
108 if ((address.address_length > 0) &&
109 (address.resource_type == ACPI_BUS_NUMBER_RANGE))
110 *busnr = address.minimum;
111
112 return AE_OK;
113}
114
115static int get_root_bridge_busnr(acpi_handle handle)
116{
117 acpi_status status;
118 unsigned long bus, bbn;
119 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
120
121 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
122
123 status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL,
124 &bbn);
125 if (status == AE_NOT_FOUND) {
126 /* Assume bus = 0 */
127 printk(KERN_INFO PREFIX
128 "Assume root bridge [%s] bus is 0\n",
129 (char *)buffer.pointer);
130 status = AE_OK;
131 bbn = 0;
132 }
133 if (ACPI_FAILURE(status)) {
134 bbn = -ENODEV;
135 goto exit;
136 }
137 if (bbn > 0)
138 goto exit;
139
140 /* _BBN in some systems return 0 for all root bridges */
141 bus = -1;
142 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
143 do_root_bridge_busnr_callback, &bus);
144 /* If _CRS failed, we just use _BBN */
145 if (ACPI_FAILURE(status) || (bus == -1))
146 goto exit;
147 /* We select _CRS */
148 if (bbn != bus) {
149 printk(KERN_INFO PREFIX
150 "_BBN and _CRS returns different value for %s. Select _CRS\n",
151 (char *)buffer.pointer);
152 bbn = bus;
153 }
154 exit:
155 kfree(buffer.pointer);
156 return (int)bbn;
157}
158
159static acpi_status
160find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
161{
162 struct acpi_find_pci_root *find = (struct acpi_find_pci_root *)context;
163 unsigned long seg, bus;
164 acpi_status status;
165 int tmp;
166 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
167
168 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
169
170 status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL, &seg);
171 if (status == AE_NOT_FOUND) {
172 /* Assume seg = 0 */
173 status = AE_OK;
174 seg = 0;
175 }
176 if (ACPI_FAILURE(status)) {
177 status = AE_CTRL_DEPTH;
178 goto exit;
179 }
180
181 tmp = get_root_bridge_busnr(handle);
182 if (tmp < 0) {
183 printk(KERN_ERR PREFIX
184 "Find root bridge failed for %s\n",
185 (char *)buffer.pointer);
186 status = AE_CTRL_DEPTH;
187 goto exit;
188 }
189 bus = tmp;
190
191 if (seg == find->seg && bus == find->bus)
192 find->handle = handle;
193 status = AE_OK;
194 exit:
195 kfree(buffer.pointer);
196 return status;
197}
198
199acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
200{
201 struct acpi_find_pci_root find = { seg, bus, NULL };
202
203 acpi_get_devices(PCI_ROOT_HID_STRING, find_pci_rootbridge, &find, NULL);
204 return find.handle;
205}
206EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
207
208/* Get device's handler per its address under its parent */ 89/* Get device's handler per its address under its parent */
209struct acpi_find_child { 90struct acpi_find_child {
210 acpi_handle handle; 91 acpi_handle handle;
@@ -217,7 +98,7 @@ do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
217 acpi_status status; 98 acpi_status status;
218 struct acpi_device_info *info; 99 struct acpi_device_info *info;
219 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 100 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
220 struct acpi_find_child *find = (struct acpi_find_child *)context; 101 struct acpi_find_child *find = context;
221 102
222 status = acpi_get_object_info(handle, &buffer); 103 status = acpi_get_object_info(handle, &buffer);
223 if (ACPI_SUCCESS(status)) { 104 if (ACPI_SUCCESS(status)) {
diff --git a/drivers/acpi/hardware/hwacpi.c b/drivers/acpi/hardware/hwacpi.c
index de50fab2a9..6031ca13dd 100644
--- a/drivers/acpi/hardware/hwacpi.c
+++ b/drivers/acpi/hardware/hwacpi.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -49,41 +49,6 @@ ACPI_MODULE_NAME("hwacpi")
49 49
50/****************************************************************************** 50/******************************************************************************
51 * 51 *
52 * FUNCTION: acpi_hw_initialize
53 *
54 * PARAMETERS: None
55 *
56 * RETURN: Status
57 *
58 * DESCRIPTION: Initialize and validate the various ACPI registers defined in
59 * the FADT.
60 *
61 ******************************************************************************/
62acpi_status acpi_hw_initialize(void)
63{
64 acpi_status status;
65
66 ACPI_FUNCTION_TRACE(hw_initialize);
67
68 /* We must have the ACPI tables by the time we get here */
69
70 if (!acpi_gbl_FADT) {
71 ACPI_ERROR((AE_INFO, "No FADT is present"));
72 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
73 }
74
75 /* Sanity check the FADT for valid values */
76
77 status = acpi_ut_validate_fadt();
78 if (ACPI_FAILURE(status)) {
79 return_ACPI_STATUS(status);
80 }
81
82 return_ACPI_STATUS(AE_OK);
83}
84
85/******************************************************************************
86 *
87 * FUNCTION: acpi_hw_set_mode 52 * FUNCTION: acpi_hw_set_mode
88 * 53 *
89 * PARAMETERS: Mode - SYS_MODE_ACPI or SYS_MODE_LEGACY 54 * PARAMETERS: Mode - SYS_MODE_ACPI or SYS_MODE_LEGACY
@@ -93,7 +58,6 @@ acpi_status acpi_hw_initialize(void)
93 * DESCRIPTION: Transitions the system into the requested mode. 58 * DESCRIPTION: Transitions the system into the requested mode.
94 * 59 *
95 ******************************************************************************/ 60 ******************************************************************************/
96
97acpi_status acpi_hw_set_mode(u32 mode) 61acpi_status acpi_hw_set_mode(u32 mode)
98{ 62{
99 63
@@ -106,7 +70,7 @@ acpi_status acpi_hw_set_mode(u32 mode)
106 * ACPI 2.0 clarified that if SMI_CMD in FADT is zero, 70 * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
107 * system does not support mode transition. 71 * system does not support mode transition.
108 */ 72 */
109 if (!acpi_gbl_FADT->smi_cmd) { 73 if (!acpi_gbl_FADT.smi_command) {
110 ACPI_ERROR((AE_INFO, 74 ACPI_ERROR((AE_INFO,
111 "No SMI_CMD in FADT, mode transition failed")); 75 "No SMI_CMD in FADT, mode transition failed"));
112 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); 76 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
@@ -119,7 +83,7 @@ acpi_status acpi_hw_set_mode(u32 mode)
119 * we make sure both the numbers are zero to determine these 83 * we make sure both the numbers are zero to determine these
120 * transitions are not supported. 84 * transitions are not supported.
121 */ 85 */
122 if (!acpi_gbl_FADT->acpi_enable && !acpi_gbl_FADT->acpi_disable) { 86 if (!acpi_gbl_FADT.acpi_enable && !acpi_gbl_FADT.acpi_disable) {
123 ACPI_ERROR((AE_INFO, 87 ACPI_ERROR((AE_INFO,
124 "No ACPI mode transition supported in this system (enable/disable both zero)")); 88 "No ACPI mode transition supported in this system (enable/disable both zero)"));
125 return_ACPI_STATUS(AE_OK); 89 return_ACPI_STATUS(AE_OK);
@@ -130,9 +94,8 @@ acpi_status acpi_hw_set_mode(u32 mode)
130 94
131 /* BIOS should have disabled ALL fixed and GP events */ 95 /* BIOS should have disabled ALL fixed and GP events */
132 96
133 status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd, 97 status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
134 (u32) acpi_gbl_FADT->acpi_enable, 98 (u32) acpi_gbl_FADT.acpi_enable, 8);
135 8);
136 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 99 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
137 "Attempting to enable ACPI mode\n")); 100 "Attempting to enable ACPI mode\n"));
138 break; 101 break;
@@ -143,8 +106,8 @@ acpi_status acpi_hw_set_mode(u32 mode)
143 * BIOS should clear all fixed status bits and restore fixed event 106 * BIOS should clear all fixed status bits and restore fixed event
144 * enable bits to default 107 * enable bits to default
145 */ 108 */
146 status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd, 109 status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
147 (u32) acpi_gbl_FADT->acpi_disable, 110 (u32) acpi_gbl_FADT.acpi_disable,
148 8); 111 8);
149 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 112 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
150 "Attempting to enable Legacy (non-ACPI) mode\n")); 113 "Attempting to enable Legacy (non-ACPI) mode\n"));
@@ -204,12 +167,11 @@ u32 acpi_hw_get_mode(void)
204 * ACPI 2.0 clarified that if SMI_CMD in FADT is zero, 167 * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
205 * system does not support mode transition. 168 * system does not support mode transition.
206 */ 169 */
207 if (!acpi_gbl_FADT->smi_cmd) { 170 if (!acpi_gbl_FADT.smi_command) {
208 return_UINT32(ACPI_SYS_MODE_ACPI); 171 return_UINT32(ACPI_SYS_MODE_ACPI);
209 } 172 }
210 173
211 status = 174 status = acpi_get_register(ACPI_BITREG_SCI_ENABLE, &value);
212 acpi_get_register(ACPI_BITREG_SCI_ENABLE, &value, ACPI_MTX_LOCK);
213 if (ACPI_FAILURE(status)) { 175 if (ACPI_FAILURE(status)) {
214 return_UINT32(ACPI_SYS_MODE_LEGACY); 176 return_UINT32(ACPI_SYS_MODE_LEGACY);
215 } 177 }
diff --git a/drivers/acpi/hardware/hwgpe.c b/drivers/acpi/hardware/hwgpe.c
index 608a3a60ee..117a05cada 100644
--- a/drivers/acpi/hardware/hwgpe.c
+++ b/drivers/acpi/hardware/hwgpe.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -105,14 +105,20 @@ acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info *gpe_event_info)
105acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info) 105acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
106{ 106{
107 acpi_status status; 107 acpi_status status;
108 u8 register_bit;
108 109
109 ACPI_FUNCTION_ENTRY(); 110 ACPI_FUNCTION_ENTRY();
110 111
112 register_bit = (u8)
113 (1 <<
114 (gpe_event_info->gpe_number -
115 gpe_event_info->register_info->base_gpe_number));
116
111 /* 117 /*
112 * Write a one to the appropriate bit in the status register to 118 * Write a one to the appropriate bit in the status register to
113 * clear this GPE. 119 * clear this GPE.
114 */ 120 */
115 status = acpi_hw_low_level_write(8, gpe_event_info->register_bit, 121 status = acpi_hw_low_level_write(8, register_bit,
116 &gpe_event_info->register_info-> 122 &gpe_event_info->register_info->
117 status_address); 123 status_address);
118 124
@@ -155,7 +161,10 @@ acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
155 161
156 /* Get the register bitmask for this GPE */ 162 /* Get the register bitmask for this GPE */
157 163
158 register_bit = gpe_event_info->register_bit; 164 register_bit = (u8)
165 (1 <<
166 (gpe_event_info->gpe_number -
167 gpe_event_info->register_info->base_gpe_number));
159 168
160 /* GPE currently enabled? (enabled for runtime?) */ 169 /* GPE currently enabled? (enabled for runtime?) */
161 170
diff --git a/drivers/acpi/hardware/hwregs.c b/drivers/acpi/hardware/hwregs.c
index fa58c1edce..1d371fa663 100644
--- a/drivers/acpi/hardware/hwregs.c
+++ b/drivers/acpi/hardware/hwregs.c
@@ -7,7 +7,7 @@
7 ******************************************************************************/ 7 ******************************************************************************/
8 8
9/* 9/*
10 * Copyright (C) 2000 - 2006, R. Byron Moore 10 * Copyright (C) 2000 - 2007, R. Byron Moore
11 * All rights reserved. 11 * All rights reserved.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
@@ -54,17 +54,15 @@ ACPI_MODULE_NAME("hwregs")
54 * 54 *
55 * FUNCTION: acpi_hw_clear_acpi_status 55 * FUNCTION: acpi_hw_clear_acpi_status
56 * 56 *
57 * PARAMETERS: Flags - Lock the hardware or not 57 * PARAMETERS: None
58 * 58 *
59 * RETURN: none 59 * RETURN: None
60 * 60 *
61 * DESCRIPTION: Clears all fixed and general purpose status bits 61 * DESCRIPTION: Clears all fixed and general purpose status bits
62 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 62 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
63 * 63 *
64 * NOTE: TBD: Flags parameter is obsolete, to be removed
65 *
66 ******************************************************************************/ 64 ******************************************************************************/
67acpi_status acpi_hw_clear_acpi_status(u32 flags) 65acpi_status acpi_hw_clear_acpi_status(void)
68{ 66{
69 acpi_status status; 67 acpi_status status;
70 acpi_cpu_flags lock_flags = 0; 68 acpi_cpu_flags lock_flags = 0;
@@ -73,7 +71,7 @@ acpi_status acpi_hw_clear_acpi_status(u32 flags)
73 71
74 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n", 72 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n",
75 ACPI_BITMASK_ALL_FIXED_STATUS, 73 ACPI_BITMASK_ALL_FIXED_STATUS,
76 (u16) acpi_gbl_FADT->xpm1a_evt_blk.address)); 74 (u16) acpi_gbl_FADT.xpm1a_event_block.address));
77 75
78 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); 76 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
79 77
@@ -86,10 +84,10 @@ acpi_status acpi_hw_clear_acpi_status(u32 flags)
86 84
87 /* Clear the fixed events */ 85 /* Clear the fixed events */
88 86
89 if (acpi_gbl_FADT->xpm1b_evt_blk.address) { 87 if (acpi_gbl_FADT.xpm1b_event_block.address) {
90 status = 88 status =
91 acpi_hw_low_level_write(16, ACPI_BITMASK_ALL_FIXED_STATUS, 89 acpi_hw_low_level_write(16, ACPI_BITMASK_ALL_FIXED_STATUS,
92 &acpi_gbl_FADT->xpm1b_evt_blk); 90 &acpi_gbl_FADT.xpm1b_event_block);
93 if (ACPI_FAILURE(status)) { 91 if (ACPI_FAILURE(status)) {
94 goto unlock_and_exit; 92 goto unlock_and_exit;
95 } 93 }
@@ -253,18 +251,15 @@ struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
253 * 251 *
254 * PARAMETERS: register_id - ID of ACPI bit_register to access 252 * PARAMETERS: register_id - ID of ACPI bit_register to access
255 * return_value - Value that was read from the register 253 * return_value - Value that was read from the register
256 * Flags - Lock the hardware or not
257 * 254 *
258 * RETURN: Status and the value read from specified Register. Value 255 * RETURN: Status and the value read from specified Register. Value
259 * returned is normalized to bit0 (is shifted all the way right) 256 * returned is normalized to bit0 (is shifted all the way right)
260 * 257 *
261 * DESCRIPTION: ACPI bit_register read function. 258 * DESCRIPTION: ACPI bit_register read function.
262 * 259 *
263 * NOTE: TBD: Flags parameter is obsolete, to be removed
264 *
265 ******************************************************************************/ 260 ******************************************************************************/
266 261
267acpi_status acpi_get_register(u32 register_id, u32 * return_value, u32 flags) 262acpi_status acpi_get_register(u32 register_id, u32 * return_value)
268{ 263{
269 u32 register_value = 0; 264 u32 register_value = 0;
270 struct acpi_bit_register_info *bit_reg_info; 265 struct acpi_bit_register_info *bit_reg_info;
@@ -312,16 +307,13 @@ ACPI_EXPORT_SYMBOL(acpi_get_register)
312 * PARAMETERS: register_id - ID of ACPI bit_register to access 307 * PARAMETERS: register_id - ID of ACPI bit_register to access
313 * Value - (only used on write) value to write to the 308 * Value - (only used on write) value to write to the
314 * Register, NOT pre-normalized to the bit pos 309 * Register, NOT pre-normalized to the bit pos
315 * Flags - Lock the hardware or not
316 * 310 *
317 * RETURN: Status 311 * RETURN: Status
318 * 312 *
319 * DESCRIPTION: ACPI Bit Register write function. 313 * DESCRIPTION: ACPI Bit Register write function.
320 * 314 *
321 * NOTE: TBD: Flags parameter is obsolete, to be removed
322 *
323 ******************************************************************************/ 315 ******************************************************************************/
324acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags) 316acpi_status acpi_set_register(u32 register_id, u32 value)
325{ 317{
326 u32 register_value = 0; 318 u32 register_value = 0;
327 struct acpi_bit_register_info *bit_reg_info; 319 struct acpi_bit_register_info *bit_reg_info;
@@ -422,8 +414,9 @@ acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags)
422 ACPI_DEBUG_PRINT((ACPI_DB_IO, 414 ACPI_DEBUG_PRINT((ACPI_DB_IO,
423 "PM2 control: Read %X from %8.8X%8.8X\n", 415 "PM2 control: Read %X from %8.8X%8.8X\n",
424 register_value, 416 register_value,
425 ACPI_FORMAT_UINT64(acpi_gbl_FADT-> 417 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
426 xpm2_cnt_blk.address))); 418 xpm2_control_block.
419 address)));
427 420
428 ACPI_REGISTER_INSERT_VALUE(register_value, 421 ACPI_REGISTER_INSERT_VALUE(register_value,
429 bit_reg_info->bit_position, 422 bit_reg_info->bit_position,
@@ -433,8 +426,9 @@ acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags)
433 ACPI_DEBUG_PRINT((ACPI_DB_IO, 426 ACPI_DEBUG_PRINT((ACPI_DB_IO,
434 "About to write %4.4X to %8.8X%8.8X\n", 427 "About to write %4.4X to %8.8X%8.8X\n",
435 register_value, 428 register_value,
436 ACPI_FORMAT_UINT64(acpi_gbl_FADT-> 429 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
437 xpm2_cnt_blk.address))); 430 xpm2_control_block.
431 address)));
438 432
439 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, 433 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
440 ACPI_REGISTER_PM2_CONTROL, 434 ACPI_REGISTER_PM2_CONTROL,
@@ -495,7 +489,7 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
495 489
496 status = 490 status =
497 acpi_hw_low_level_read(16, &value1, 491 acpi_hw_low_level_read(16, &value1,
498 &acpi_gbl_FADT->xpm1a_evt_blk); 492 &acpi_gbl_FADT.xpm1a_event_block);
499 if (ACPI_FAILURE(status)) { 493 if (ACPI_FAILURE(status)) {
500 goto unlock_and_exit; 494 goto unlock_and_exit;
501 } 495 }
@@ -504,7 +498,7 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
504 498
505 status = 499 status =
506 acpi_hw_low_level_read(16, &value2, 500 acpi_hw_low_level_read(16, &value2,
507 &acpi_gbl_FADT->xpm1b_evt_blk); 501 &acpi_gbl_FADT.xpm1b_event_block);
508 value1 |= value2; 502 value1 |= value2;
509 break; 503 break;
510 504
@@ -527,14 +521,14 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
527 521
528 status = 522 status =
529 acpi_hw_low_level_read(16, &value1, 523 acpi_hw_low_level_read(16, &value1,
530 &acpi_gbl_FADT->xpm1a_cnt_blk); 524 &acpi_gbl_FADT.xpm1a_control_block);
531 if (ACPI_FAILURE(status)) { 525 if (ACPI_FAILURE(status)) {
532 goto unlock_and_exit; 526 goto unlock_and_exit;
533 } 527 }
534 528
535 status = 529 status =
536 acpi_hw_low_level_read(16, &value2, 530 acpi_hw_low_level_read(16, &value2,
537 &acpi_gbl_FADT->xpm1b_cnt_blk); 531 &acpi_gbl_FADT.xpm1b_control_block);
538 value1 |= value2; 532 value1 |= value2;
539 break; 533 break;
540 534
@@ -542,19 +536,20 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
542 536
543 status = 537 status =
544 acpi_hw_low_level_read(8, &value1, 538 acpi_hw_low_level_read(8, &value1,
545 &acpi_gbl_FADT->xpm2_cnt_blk); 539 &acpi_gbl_FADT.xpm2_control_block);
546 break; 540 break;
547 541
548 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ 542 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
549 543
550 status = 544 status =
551 acpi_hw_low_level_read(32, &value1, 545 acpi_hw_low_level_read(32, &value1,
552 &acpi_gbl_FADT->xpm_tmr_blk); 546 &acpi_gbl_FADT.xpm_timer_block);
553 break; 547 break;
554 548
555 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ 549 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
556 550
557 status = acpi_os_read_port(acpi_gbl_FADT->smi_cmd, &value1, 8); 551 status =
552 acpi_os_read_port(acpi_gbl_FADT.smi_command, &value1, 8);
558 break; 553 break;
559 554
560 default: 555 default:
@@ -635,7 +630,7 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
635 630
636 status = 631 status =
637 acpi_hw_low_level_write(16, value, 632 acpi_hw_low_level_write(16, value,
638 &acpi_gbl_FADT->xpm1a_evt_blk); 633 &acpi_gbl_FADT.xpm1a_event_block);
639 if (ACPI_FAILURE(status)) { 634 if (ACPI_FAILURE(status)) {
640 goto unlock_and_exit; 635 goto unlock_and_exit;
641 } 636 }
@@ -644,7 +639,7 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
644 639
645 status = 640 status =
646 acpi_hw_low_level_write(16, value, 641 acpi_hw_low_level_write(16, value,
647 &acpi_gbl_FADT->xpm1b_evt_blk); 642 &acpi_gbl_FADT.xpm1b_event_block);
648 break; 643 break;
649 644
650 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */ 645 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
@@ -682,49 +677,50 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
682 677
683 status = 678 status =
684 acpi_hw_low_level_write(16, value, 679 acpi_hw_low_level_write(16, value,
685 &acpi_gbl_FADT->xpm1a_cnt_blk); 680 &acpi_gbl_FADT.xpm1a_control_block);
686 if (ACPI_FAILURE(status)) { 681 if (ACPI_FAILURE(status)) {
687 goto unlock_and_exit; 682 goto unlock_and_exit;
688 } 683 }
689 684
690 status = 685 status =
691 acpi_hw_low_level_write(16, value, 686 acpi_hw_low_level_write(16, value,
692 &acpi_gbl_FADT->xpm1b_cnt_blk); 687 &acpi_gbl_FADT.xpm1b_control_block);
693 break; 688 break;
694 689
695 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */ 690 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
696 691
697 status = 692 status =
698 acpi_hw_low_level_write(16, value, 693 acpi_hw_low_level_write(16, value,
699 &acpi_gbl_FADT->xpm1a_cnt_blk); 694 &acpi_gbl_FADT.xpm1a_control_block);
700 break; 695 break;
701 696
702 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */ 697 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
703 698
704 status = 699 status =
705 acpi_hw_low_level_write(16, value, 700 acpi_hw_low_level_write(16, value,
706 &acpi_gbl_FADT->xpm1b_cnt_blk); 701 &acpi_gbl_FADT.xpm1b_control_block);
707 break; 702 break;
708 703
709 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ 704 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
710 705
711 status = 706 status =
712 acpi_hw_low_level_write(8, value, 707 acpi_hw_low_level_write(8, value,
713 &acpi_gbl_FADT->xpm2_cnt_blk); 708 &acpi_gbl_FADT.xpm2_control_block);
714 break; 709 break;
715 710
716 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ 711 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
717 712
718 status = 713 status =
719 acpi_hw_low_level_write(32, value, 714 acpi_hw_low_level_write(32, value,
720 &acpi_gbl_FADT->xpm_tmr_blk); 715 &acpi_gbl_FADT.xpm_timer_block);
721 break; 716 break;
722 717
723 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ 718 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
724 719
725 /* SMI_CMD is currently always in IO space */ 720 /* SMI_CMD is currently always in IO space */
726 721
727 status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd, value, 8); 722 status =
723 acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8);
728 break; 724 break;
729 725
730 default: 726 default:
@@ -783,7 +779,7 @@ acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
783 * Two address spaces supported: Memory or IO. 779 * Two address spaces supported: Memory or IO.
784 * PCI_Config is not supported here because the GAS struct is insufficient 780 * PCI_Config is not supported here because the GAS struct is insufficient
785 */ 781 */
786 switch (reg->address_space_id) { 782 switch (reg->space_id) {
787 case ACPI_ADR_SPACE_SYSTEM_MEMORY: 783 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
788 784
789 status = acpi_os_read_memory((acpi_physical_address) address, 785 status = acpi_os_read_memory((acpi_physical_address) address,
@@ -792,22 +788,20 @@ acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
792 788
793 case ACPI_ADR_SPACE_SYSTEM_IO: 789 case ACPI_ADR_SPACE_SYSTEM_IO:
794 790
795 status = acpi_os_read_port((acpi_io_address) address, 791 status =
796 value, width); 792 acpi_os_read_port((acpi_io_address) address, value, width);
797 break; 793 break;
798 794
799 default: 795 default:
800 ACPI_ERROR((AE_INFO, 796 ACPI_ERROR((AE_INFO,
801 "Unsupported address space: %X", 797 "Unsupported address space: %X", reg->space_id));
802 reg->address_space_id));
803 return (AE_BAD_PARAMETER); 798 return (AE_BAD_PARAMETER);
804 } 799 }
805 800
806 ACPI_DEBUG_PRINT((ACPI_DB_IO, 801 ACPI_DEBUG_PRINT((ACPI_DB_IO,
807 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", 802 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
808 *value, width, 803 *value, width, ACPI_FORMAT_UINT64(address),
809 ACPI_FORMAT_UINT64(address), 804 acpi_ut_get_region_name(reg->space_id)));
810 acpi_ut_get_region_name(reg->address_space_id)));
811 805
812 return (status); 806 return (status);
813} 807}
@@ -854,7 +848,7 @@ acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
854 * Two address spaces supported: Memory or IO. 848 * Two address spaces supported: Memory or IO.
855 * PCI_Config is not supported here because the GAS struct is insufficient 849 * PCI_Config is not supported here because the GAS struct is insufficient
856 */ 850 */
857 switch (reg->address_space_id) { 851 switch (reg->space_id) {
858 case ACPI_ADR_SPACE_SYSTEM_MEMORY: 852 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
859 853
860 status = acpi_os_write_memory((acpi_physical_address) address, 854 status = acpi_os_write_memory((acpi_physical_address) address,
@@ -863,22 +857,20 @@ acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
863 857
864 case ACPI_ADR_SPACE_SYSTEM_IO: 858 case ACPI_ADR_SPACE_SYSTEM_IO:
865 859
866 status = acpi_os_write_port((acpi_io_address) address, 860 status = acpi_os_write_port((acpi_io_address) address, value,
867 value, width); 861 width);
868 break; 862 break;
869 863
870 default: 864 default:
871 ACPI_ERROR((AE_INFO, 865 ACPI_ERROR((AE_INFO,
872 "Unsupported address space: %X", 866 "Unsupported address space: %X", reg->space_id));
873 reg->address_space_id));
874 return (AE_BAD_PARAMETER); 867 return (AE_BAD_PARAMETER);
875 } 868 }
876 869
877 ACPI_DEBUG_PRINT((ACPI_DB_IO, 870 ACPI_DEBUG_PRINT((ACPI_DB_IO,
878 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", 871 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
879 value, width, 872 value, width, ACPI_FORMAT_UINT64(address),
880 ACPI_FORMAT_UINT64(address), 873 acpi_ut_get_region_name(reg->space_id)));
881 acpi_ut_get_region_name(reg->address_space_id)));
882 874
883 return (status); 875 return (status);
884} 876}
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
index 8bb43cae60..57901ca3ad 100644
--- a/drivers/acpi/hardware/hwsleep.c
+++ b/drivers/acpi/hardware/hwsleep.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,7 @@
43 */ 43 */
44 44
45#include <acpi/acpi.h> 45#include <acpi/acpi.h>
46#include <acpi/actables.h>
46 47
47#define _COMPONENT ACPI_HARDWARE 48#define _COMPONENT ACPI_HARDWARE
48ACPI_MODULE_NAME("hwsleep") 49ACPI_MODULE_NAME("hwsleep")
@@ -62,17 +63,32 @@ ACPI_MODULE_NAME("hwsleep")
62acpi_status 63acpi_status
63acpi_set_firmware_waking_vector(acpi_physical_address physical_address) 64acpi_set_firmware_waking_vector(acpi_physical_address physical_address)
64{ 65{
66 struct acpi_table_facs *facs;
67 acpi_status status;
65 68
66 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector); 69 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector);
67 70
71 /* Get the FACS */
72
73 status =
74 acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
75 (struct acpi_table_header **)&facs);
76 if (ACPI_FAILURE(status)) {
77 return_ACPI_STATUS(status);
78 }
79
68 /* Set the vector */ 80 /* Set the vector */
69 81
70 if (acpi_gbl_common_fACS.vector_width == 32) { 82 if ((facs->length < 32) || (!(facs->xfirmware_waking_vector))) {
71 *(ACPI_CAST_PTR 83 /*
72 (u32, acpi_gbl_common_fACS.firmware_waking_vector)) 84 * ACPI 1.0 FACS or short table or optional X_ field is zero
73 = (u32) physical_address; 85 */
86 facs->firmware_waking_vector = (u32) physical_address;
74 } else { 87 } else {
75 *acpi_gbl_common_fACS.firmware_waking_vector = physical_address; 88 /*
89 * ACPI 2.0 FACS with valid X_ field
90 */
91 facs->xfirmware_waking_vector = physical_address;
76 } 92 }
77 93
78 return_ACPI_STATUS(AE_OK); 94 return_ACPI_STATUS(AE_OK);
@@ -97,6 +113,8 @@ ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector)
97acpi_status 113acpi_status
98acpi_get_firmware_waking_vector(acpi_physical_address * physical_address) 114acpi_get_firmware_waking_vector(acpi_physical_address * physical_address)
99{ 115{
116 struct acpi_table_facs *facs;
117 acpi_status status;
100 118
101 ACPI_FUNCTION_TRACE(acpi_get_firmware_waking_vector); 119 ACPI_FUNCTION_TRACE(acpi_get_firmware_waking_vector);
102 120
@@ -104,16 +122,29 @@ acpi_get_firmware_waking_vector(acpi_physical_address * physical_address)
104 return_ACPI_STATUS(AE_BAD_PARAMETER); 122 return_ACPI_STATUS(AE_BAD_PARAMETER);
105 } 123 }
106 124
125 /* Get the FACS */
126
127 status =
128 acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
129 (struct acpi_table_header **)&facs);
130 if (ACPI_FAILURE(status)) {
131 return_ACPI_STATUS(status);
132 }
133
107 /* Get the vector */ 134 /* Get the vector */
108 135
109 if (acpi_gbl_common_fACS.vector_width == 32) { 136 if ((facs->length < 32) || (!(facs->xfirmware_waking_vector))) {
110 *physical_address = (acpi_physical_address) 137 /*
111 * 138 * ACPI 1.0 FACS or short table or optional X_ field is zero
112 (ACPI_CAST_PTR 139 */
113 (u32, acpi_gbl_common_fACS.firmware_waking_vector)); 140 *physical_address =
141 (acpi_physical_address) facs->firmware_waking_vector;
114 } else { 142 } else {
143 /*
144 * ACPI 2.0 FACS with valid X_ field
145 */
115 *physical_address = 146 *physical_address =
116 *acpi_gbl_common_fACS.firmware_waking_vector; 147 (acpi_physical_address) facs->xfirmware_waking_vector;
117 } 148 }
118 149
119 return_ACPI_STATUS(AE_OK); 150 return_ACPI_STATUS(AE_OK);
@@ -246,15 +277,14 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
246 277
247 /* Clear wake status */ 278 /* Clear wake status */
248 279
249 status = 280 status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1);
250 acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
251 if (ACPI_FAILURE(status)) { 281 if (ACPI_FAILURE(status)) {
252 return_ACPI_STATUS(status); 282 return_ACPI_STATUS(status);
253 } 283 }
254 284
255 /* Clear all fixed and general purpose status bits */ 285 /* Clear all fixed and general purpose status bits */
256 286
257 status = acpi_hw_clear_acpi_status(ACPI_MTX_DO_NOT_LOCK); 287 status = acpi_hw_clear_acpi_status();
258 if (ACPI_FAILURE(status)) { 288 if (ACPI_FAILURE(status)) {
259 return_ACPI_STATUS(status); 289 return_ACPI_STATUS(status);
260 } 290 }
@@ -367,8 +397,7 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
367 /* Wait until we enter sleep state */ 397 /* Wait until we enter sleep state */
368 398
369 do { 399 do {
370 status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value, 400 status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value);
371 ACPI_MTX_DO_NOT_LOCK);
372 if (ACPI_FAILURE(status)) { 401 if (ACPI_FAILURE(status)) {
373 return_ACPI_STATUS(status); 402 return_ACPI_STATUS(status);
374 } 403 }
@@ -401,13 +430,12 @@ acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
401 430
402 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios); 431 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios);
403 432
404 status = 433 status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1);
405 acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
406 if (ACPI_FAILURE(status)) { 434 if (ACPI_FAILURE(status)) {
407 return_ACPI_STATUS(status); 435 return_ACPI_STATUS(status);
408 } 436 }
409 437
410 status = acpi_hw_clear_acpi_status(ACPI_MTX_DO_NOT_LOCK); 438 status = acpi_hw_clear_acpi_status();
411 if (ACPI_FAILURE(status)) { 439 if (ACPI_FAILURE(status)) {
412 return_ACPI_STATUS(status); 440 return_ACPI_STATUS(status);
413 } 441 }
@@ -429,13 +457,12 @@ acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
429 457
430 ACPI_FLUSH_CPU_CACHE(); 458 ACPI_FLUSH_CPU_CACHE();
431 459
432 status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd, 460 status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
433 (u32) acpi_gbl_FADT->S4bios_req, 8); 461 (u32) acpi_gbl_FADT.S4bios_request, 8);
434 462
435 do { 463 do {
436 acpi_os_stall(1000); 464 acpi_os_stall(1000);
437 status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value, 465 status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value);
438 ACPI_MTX_DO_NOT_LOCK);
439 if (ACPI_FAILURE(status)) { 466 if (ACPI_FAILURE(status)) {
440 return_ACPI_STATUS(status); 467 return_ACPI_STATUS(status);
441 } 468 }
@@ -568,13 +595,11 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state)
568 595
569 (void) 596 (void)
570 acpi_set_register(acpi_gbl_fixed_event_info 597 acpi_set_register(acpi_gbl_fixed_event_info
571 [ACPI_EVENT_POWER_BUTTON].enable_register_id, 1, 598 [ACPI_EVENT_POWER_BUTTON].enable_register_id, 1);
572 ACPI_MTX_DO_NOT_LOCK);
573 599
574 (void) 600 (void)
575 acpi_set_register(acpi_gbl_fixed_event_info 601 acpi_set_register(acpi_gbl_fixed_event_info
576 [ACPI_EVENT_POWER_BUTTON].status_register_id, 1, 602 [ACPI_EVENT_POWER_BUTTON].status_register_id, 1);
577 ACPI_MTX_DO_NOT_LOCK);
578 603
579 arg.integer.value = ACPI_SST_WORKING; 604 arg.integer.value = ACPI_SST_WORKING;
580 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); 605 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL);
diff --git a/drivers/acpi/hardware/hwtimer.c b/drivers/acpi/hardware/hwtimer.c
index c4ec47c939..c32eab696a 100644
--- a/drivers/acpi/hardware/hwtimer.c
+++ b/drivers/acpi/hardware/hwtimer.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -66,7 +66,7 @@ acpi_status acpi_get_timer_resolution(u32 * resolution)
66 return_ACPI_STATUS(AE_BAD_PARAMETER); 66 return_ACPI_STATUS(AE_BAD_PARAMETER);
67 } 67 }
68 68
69 if (acpi_gbl_FADT->tmr_val_ext == 0) { 69 if ((acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) == 0) {
70 *resolution = 24; 70 *resolution = 24;
71 } else { 71 } else {
72 *resolution = 32; 72 *resolution = 32;
@@ -98,7 +98,8 @@ acpi_status acpi_get_timer(u32 * ticks)
98 return_ACPI_STATUS(AE_BAD_PARAMETER); 98 return_ACPI_STATUS(AE_BAD_PARAMETER);
99 } 99 }
100 100
101 status = acpi_hw_low_level_read(32, ticks, &acpi_gbl_FADT->xpm_tmr_blk); 101 status =
102 acpi_hw_low_level_read(32, ticks, &acpi_gbl_FADT.xpm_timer_block);
102 103
103 return_ACPI_STATUS(status); 104 return_ACPI_STATUS(status);
104} 105}
@@ -153,7 +154,7 @@ acpi_get_timer_duration(u32 start_ticks, u32 end_ticks, u32 * time_elapsed)
153 if (start_ticks < end_ticks) { 154 if (start_ticks < end_ticks) {
154 delta_ticks = end_ticks - start_ticks; 155 delta_ticks = end_ticks - start_ticks;
155 } else if (start_ticks > end_ticks) { 156 } else if (start_ticks > end_ticks) {
156 if (acpi_gbl_FADT->tmr_val_ext == 0) { 157 if ((acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) == 0) {
157 158
158 /* 24-bit Timer */ 159 /* 24-bit Timer */
159 160
diff --git a/drivers/acpi/hotkey.c b/drivers/acpi/hotkey.c
index 1ba2db6718..8edfb92f7e 100644
--- a/drivers/acpi/hotkey.c
+++ b/drivers/acpi/hotkey.c
@@ -265,8 +265,7 @@ static char *format_result(union acpi_object *object)
265 265
266static int hotkey_polling_seq_show(struct seq_file *seq, void *offset) 266static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
267{ 267{
268 struct acpi_polling_hotkey *poll_hotkey = 268 struct acpi_polling_hotkey *poll_hotkey = seq->private;
269 (struct acpi_polling_hotkey *)seq->private;
270 char *buf; 269 char *buf;
271 270
272 271
@@ -577,7 +576,7 @@ init_poll_hotkey_device(union acpi_hotkey *key, char **config_entry,
577 if (ACPI_FAILURE(status)) 576 if (ACPI_FAILURE(status))
578 goto do_fail_zero; 577 goto do_fail_zero;
579 key->poll_hotkey.poll_result = 578 key->poll_hotkey.poll_result =
580 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL); 579 kmalloc(sizeof(union acpi_object), GFP_KERNEL);
581 if (!key->poll_hotkey.poll_result) 580 if (!key->poll_hotkey.poll_result)
582 goto do_fail_zero; 581 goto do_fail_zero;
583 return AE_OK; 582 return AE_OK;
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c
index 6342e612c2..8338be0990 100644
--- a/drivers/acpi/i2c_ec.c
+++ b/drivers/acpi/i2c_ec.c
@@ -309,18 +309,16 @@ static int acpi_ec_hc_add(struct acpi_device *device)
309 return -EINVAL; 309 return -EINVAL;
310 } 310 }
311 311
312 ec_hc = kmalloc(sizeof(struct acpi_ec_hc), GFP_KERNEL); 312 ec_hc = kzalloc(sizeof(struct acpi_ec_hc), GFP_KERNEL);
313 if (!ec_hc) { 313 if (!ec_hc) {
314 return -ENOMEM; 314 return -ENOMEM;
315 } 315 }
316 memset(ec_hc, 0, sizeof(struct acpi_ec_hc));
317 316
318 smbus = kmalloc(sizeof(struct acpi_ec_smbus), GFP_KERNEL); 317 smbus = kzalloc(sizeof(struct acpi_ec_smbus), GFP_KERNEL);
319 if (!smbus) { 318 if (!smbus) {
320 kfree(ec_hc); 319 kfree(ec_hc);
321 return -ENOMEM; 320 return -ENOMEM;
322 } 321 }
323 memset(smbus, 0, sizeof(struct acpi_ec_smbus));
324 322
325 ec_hc->handle = device->handle; 323 ec_hc->handle = device->handle;
326 strcpy(acpi_device_name(device), ACPI_EC_HC_DEVICE_NAME); 324 strcpy(acpi_device_name(device), ACPI_EC_HC_DEVICE_NAME);
@@ -393,7 +391,7 @@ static void __exit acpi_ec_hc_exit(void)
393 391
394struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device) 392struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device)
395{ 393{
396 return ((struct acpi_ec_hc *)acpi_driver_data(device->parent)); 394 return acpi_driver_data(device->parent);
397} 395}
398 396
399EXPORT_SYMBOL(acpi_get_ec_hc); 397EXPORT_SYMBOL(acpi_get_ec_hc);
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
index 003a9876c9..c6144ca666 100644
--- a/drivers/acpi/ibm_acpi.c
+++ b/drivers/acpi/ibm_acpi.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * 4 *
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> 5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
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
@@ -19,10 +20,14 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 21 */
21 22
22#define IBM_VERSION "0.12a" 23#define IBM_VERSION "0.13"
23 24
24/* 25/*
25 * Changelog: 26 * Changelog:
27 *
28 * 2006-11-22 0.13 new maintainer
29 * changelog now lives in git commit history, and will
30 * not be updated further in-file.
26 * 31 *
27 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels 32 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
28 * 2005-03-17 0.11 support for 600e, 770x 33 * 2005-03-17 0.11 support for 600e, 770x
@@ -77,9 +82,16 @@
77#include <linux/module.h> 82#include <linux/module.h>
78#include <linux/init.h> 83#include <linux/init.h>
79#include <linux/types.h> 84#include <linux/types.h>
85#include <linux/string.h>
86
80#include <linux/proc_fs.h> 87#include <linux/proc_fs.h>
88#include <linux/backlight.h>
81#include <asm/uaccess.h> 89#include <asm/uaccess.h>
82 90
91#include <linux/dmi.h>
92#include <linux/jiffies.h>
93#include <linux/workqueue.h>
94
83#include <acpi/acpi_drivers.h> 95#include <acpi/acpi_drivers.h>
84#include <acpi/acnamesp.h> 96#include <acpi/acnamesp.h>
85 97
@@ -88,7 +100,7 @@
88#define IBM_FILE "ibm_acpi" 100#define IBM_FILE "ibm_acpi"
89#define IBM_URL "http://ibm-acpi.sf.net/" 101#define IBM_URL "http://ibm-acpi.sf.net/"
90 102
91MODULE_AUTHOR("Borislav Deianov"); 103MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
92MODULE_DESCRIPTION(IBM_DESC); 104MODULE_DESCRIPTION(IBM_DESC);
93MODULE_VERSION(IBM_VERSION); 105MODULE_VERSION(IBM_VERSION);
94MODULE_LICENSE("GPL"); 106MODULE_LICENSE("GPL");
@@ -116,28 +128,6 @@ static acpi_handle root_handle = NULL;
116 static char *object##_path; \ 128 static char *object##_path; \
117 static char *object##_paths[] = { paths } 129 static char *object##_paths[] = { paths }
118 130
119/*
120 * The following models are supported to various degrees:
121 *
122 * 570, 600e, 600x, 770e, 770x
123 * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p
124 * G40, G41
125 * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51
126 * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43
127 * X20, X21, X22, X23, X24, X30, X31, X40
128 *
129 * The following models have no supported features:
130 *
131 * 240, 240x, i1400
132 *
133 * Still missing DSDTs for the following models:
134 *
135 * A20p, A22e, A22m
136 * R52
137 * S31
138 * T43p
139 */
140
141IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ 131IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
142 "\\_SB.PCI.ISA.EC", /* 570 */ 132 "\\_SB.PCI.ISA.EC", /* 570 */
143 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ 133 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
@@ -169,6 +159,7 @@ IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
169#endif 159#endif
170IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ 160IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
171 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ 161 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
162 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
172 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ 163 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
173 ); /* A21e, R30, R31 */ 164 ); /* A21e, R30, R31 */
174 165
@@ -203,7 +194,7 @@ IBM_HANDLE(led, ec, "SLED", /* 570 */
203IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ 194IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
204IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ 195IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
205IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ 196IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
206IBM_HANDLE(fans, ec, "FANS"); /* X31, X40 */ 197IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
207 198
208IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ 199IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
209 "\\FSPD", /* 600e/x, 770e, 770x */ 200 "\\FSPD", /* 600e/x, 770e, 770x */
@@ -216,6 +207,152 @@ IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
216#define IBM_HKEY_HID "IBM0068" 207#define IBM_HKEY_HID "IBM0068"
217#define IBM_PCI_HID "PNP0A03" 208#define IBM_PCI_HID "PNP0A03"
218 209
210enum thermal_access_mode {
211 IBMACPI_THERMAL_NONE = 0, /* No thermal support */
212 IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
213 IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
214 IBMACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
215 IBMACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
216};
217
218#define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
219struct ibm_thermal_sensors_struct {
220 s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
221};
222
223/*
224 * FAN ACCESS MODES
225 *
226 * IBMACPI_FAN_RD_ACPI_GFAN:
227 * ACPI GFAN method: returns fan level
228 *
229 * see IBMACPI_FAN_WR_ACPI_SFAN
230 * EC 0x2f not available if GFAN exists
231 *
232 * IBMACPI_FAN_WR_ACPI_SFAN:
233 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
234 *
235 * EC 0x2f might be available *for reading*, but never for writing.
236 *
237 * IBMACPI_FAN_WR_TPEC:
238 * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
239 * on almost all ThinkPads
240 *
241 * Fan speed changes of any sort (including those caused by the
242 * disengaged mode) are usually done slowly by the firmware as the
243 * maximum ammount of fan duty cycle change per second seems to be
244 * limited.
245 *
246 * Reading is not available if GFAN exists.
247 * Writing is not available if SFAN exists.
248 *
249 * Bits
250 * 7 automatic mode engaged;
251 * (default operation mode of the ThinkPad)
252 * fan level is ignored in this mode.
253 * 6 disengage mode (takes precedence over bit 7);
254 * not available on all thinkpads. May disable
255 * the tachometer, and speeds up fan to 100% duty-cycle,
256 * which speeds it up far above the standard RPM
257 * levels. It is not impossible that it could cause
258 * hardware damage.
259 * 5-3 unused in some models. Extra bits for fan level
260 * in others, but still useless as all values above
261 * 7 map to the same speed as level 7 in these models.
262 * 2-0 fan level (0..7 usually)
263 * 0x00 = stop
264 * 0x07 = max (set when temperatures critical)
265 * Some ThinkPads may have other levels, see
266 * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
267 *
268 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
269 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
270 * does so, its initial value is meaningless (0x07).
271 *
272 * For firmware bugs, refer to:
273 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
274 *
275 * ----
276 *
277 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
278 * Main fan tachometer reading (in RPM)
279 *
280 * This register is present on all ThinkPads with a new-style EC, and
281 * it is known not to be present on the A21m/e, and T22, as there is
282 * something else in offset 0x84 according to the ACPI DSDT. Other
283 * ThinkPads from this same time period (and earlier) probably lack the
284 * tachometer as well.
285 *
286 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
287 * was never fixed by IBM to report the EC firmware version string
288 * probably support the tachometer (like the early X models), so
289 * detecting it is quite hard. We need more data to know for sure.
290 *
291 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
292 * might result.
293 *
294 * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
295 * register is not invalidated in ThinkPads that disable tachometer
296 * readings. Thus, the tachometer readings go stale.
297 *
298 * For firmware bugs, refer to:
299 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
300 *
301 * IBMACPI_FAN_WR_ACPI_FANS:
302 * ThinkPad X31, X40, X41. Not available in the X60.
303 *
304 * FANS ACPI handle: takes three arguments: low speed, medium speed,
305 * high speed. ACPI DSDT seems to map these three speeds to levels
306 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
307 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
308 *
309 * The speeds are stored on handles
310 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
311 *
312 * There are three default speed sets, acessible as handles:
313 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
314 *
315 * ACPI DSDT switches which set is in use depending on various
316 * factors.
317 *
318 * IBMACPI_FAN_WR_TPEC is also available and should be used to
319 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
320 * but the ACPI tables just mention level 7.
321 */
322
323enum fan_status_access_mode {
324 IBMACPI_FAN_NONE = 0, /* No fan status or control */
325 IBMACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
326 IBMACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
327};
328
329enum fan_control_access_mode {
330 IBMACPI_FAN_WR_NONE = 0, /* No fan control */
331 IBMACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
332 IBMACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
333 IBMACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
334};
335
336enum fan_control_commands {
337 IBMACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
338 IBMACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
339 IBMACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
340 * and also watchdog cmd */
341};
342
343enum { /* Fan control constants */
344 fan_status_offset = 0x2f, /* EC register 0x2f */
345 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
346 * 0x84 must be read before 0x85 */
347
348 IBMACPI_FAN_EC_DISENGAGED = 0x40, /* EC mode: tachometer
349 * disengaged */
350 IBMACPI_FAN_EC_AUTO = 0x80, /* EC mode: auto fan
351 * control */
352};
353
354static char *ibm_thinkpad_ec_found = NULL;
355
219struct ibm_struct { 356struct ibm_struct {
220 char *name; 357 char *name;
221 char param[32]; 358 char param[32];
@@ -243,6 +380,8 @@ struct ibm_struct {
243 380
244static struct proc_dir_entry *proc_dir = NULL; 381static struct proc_dir_entry *proc_dir = NULL;
245 382
383static struct backlight_device *ibm_backlight_device = NULL;
384
246#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") 385#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
247#define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") 386#define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
248#define strlencmp(a,b) (strncmp((a), (b), strlen(b))) 387#define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
@@ -352,7 +491,7 @@ static char *next_cmd(char **cmds)
352 return start; 491 return start;
353} 492}
354 493
355static int driver_init(void) 494static int ibm_acpi_driver_init(void)
356{ 495{
357 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); 496 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
358 printk(IBM_INFO "%s\n", IBM_URL); 497 printk(IBM_INFO "%s\n", IBM_URL);
@@ -581,8 +720,7 @@ static int wan_status(void)
581{ 720{
582 int status; 721 int status;
583 722
584 if (!wan_supported || 723 if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
585 !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
586 status = 0; 724 status = 0;
587 725
588 return status; 726 return status;
@@ -630,12 +768,15 @@ static int wan_write(char *buf)
630 return 0; 768 return 0;
631} 769}
632 770
633static int video_supported; 771enum video_access_mode {
634static int video_orig_autosw; 772 IBMACPI_VIDEO_NONE = 0,
773 IBMACPI_VIDEO_570, /* 570 */
774 IBMACPI_VIDEO_770, /* 600e/x, 770e, 770x */
775 IBMACPI_VIDEO_NEW, /* all others */
776};
635 777
636#define VIDEO_570 1 778static enum video_access_mode video_supported;
637#define VIDEO_770 2 779static int video_orig_autosw;
638#define VIDEO_NEW 3
639 780
640static int video_init(void) 781static int video_init(void)
641{ 782{
@@ -647,16 +788,16 @@ static int video_init(void)
647 788
648 if (!vid_handle) 789 if (!vid_handle)
649 /* video switching not supported on R30, R31 */ 790 /* video switching not supported on R30, R31 */
650 video_supported = 0; 791 video_supported = IBMACPI_VIDEO_NONE;
651 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) 792 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
652 /* 570 */ 793 /* 570 */
653 video_supported = VIDEO_570; 794 video_supported = IBMACPI_VIDEO_570;
654 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) 795 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
655 /* 600e/x, 770e, 770x */ 796 /* 600e/x, 770e, 770x */
656 video_supported = VIDEO_770; 797 video_supported = IBMACPI_VIDEO_770;
657 else 798 else
658 /* all others */ 799 /* all others */
659 video_supported = VIDEO_NEW; 800 video_supported = IBMACPI_VIDEO_NEW;
660 801
661 return 0; 802 return 0;
662} 803}
@@ -666,15 +807,15 @@ static int video_status(void)
666 int status = 0; 807 int status = 0;
667 int i; 808 int i;
668 809
669 if (video_supported == VIDEO_570) { 810 if (video_supported == IBMACPI_VIDEO_570) {
670 if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87)) 811 if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
671 status = i & 3; 812 status = i & 3;
672 } else if (video_supported == VIDEO_770) { 813 } else if (video_supported == IBMACPI_VIDEO_770) {
673 if (acpi_evalf(NULL, &i, "\\VCDL", "d")) 814 if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
674 status |= 0x01 * i; 815 status |= 0x01 * i;
675 if (acpi_evalf(NULL, &i, "\\VCDC", "d")) 816 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
676 status |= 0x02 * i; 817 status |= 0x02 * i;
677 } else if (video_supported == VIDEO_NEW) { 818 } else if (video_supported == IBMACPI_VIDEO_NEW) {
678 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1); 819 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
679 if (acpi_evalf(NULL, &i, "\\VCDC", "d")) 820 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
680 status |= 0x02 * i; 821 status |= 0x02 * i;
@@ -693,9 +834,10 @@ static int video_autosw(void)
693{ 834{
694 int autosw = 0; 835 int autosw = 0;
695 836
696 if (video_supported == VIDEO_570) 837 if (video_supported == IBMACPI_VIDEO_570)
697 acpi_evalf(vid_handle, &autosw, "SWIT", "d"); 838 acpi_evalf(vid_handle, &autosw, "SWIT", "d");
698 else if (video_supported == VIDEO_770 || video_supported == VIDEO_NEW) 839 else if (video_supported == IBMACPI_VIDEO_770 ||
840 video_supported == IBMACPI_VIDEO_NEW)
699 acpi_evalf(vid_handle, &autosw, "^VDEE", "d"); 841 acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
700 842
701 return autosw & 1; 843 return autosw & 1;
@@ -715,12 +857,12 @@ static int video_read(char *p)
715 len += sprintf(p + len, "status:\t\tsupported\n"); 857 len += sprintf(p + len, "status:\t\tsupported\n");
716 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); 858 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
717 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1)); 859 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
718 if (video_supported == VIDEO_NEW) 860 if (video_supported == IBMACPI_VIDEO_NEW)
719 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); 861 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
720 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); 862 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
721 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); 863 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
722 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); 864 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
723 if (video_supported == VIDEO_NEW) 865 if (video_supported == IBMACPI_VIDEO_NEW)
724 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); 866 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
725 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); 867 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
726 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); 868 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
@@ -735,7 +877,7 @@ static int video_switch(void)
735 877
736 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) 878 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
737 return -EIO; 879 return -EIO;
738 ret = video_supported == VIDEO_570 ? 880 ret = video_supported == IBMACPI_VIDEO_570 ?
739 acpi_evalf(ec_handle, NULL, "_Q16", "v") : 881 acpi_evalf(ec_handle, NULL, "_Q16", "v") :
740 acpi_evalf(vid_handle, NULL, "VSWT", "v"); 882 acpi_evalf(vid_handle, NULL, "VSWT", "v");
741 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw); 883 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
@@ -745,9 +887,9 @@ static int video_switch(void)
745 887
746static int video_expand(void) 888static int video_expand(void)
747{ 889{
748 if (video_supported == VIDEO_570) 890 if (video_supported == IBMACPI_VIDEO_570)
749 return acpi_evalf(ec_handle, NULL, "_Q17", "v"); 891 return acpi_evalf(ec_handle, NULL, "_Q17", "v");
750 else if (video_supported == VIDEO_770) 892 else if (video_supported == IBMACPI_VIDEO_770)
751 return acpi_evalf(vid_handle, NULL, "VEXP", "v"); 893 return acpi_evalf(vid_handle, NULL, "VEXP", "v");
752 else 894 else
753 return acpi_evalf(NULL, NULL, "\\VEXP", "v"); 895 return acpi_evalf(NULL, NULL, "\\VEXP", "v");
@@ -757,10 +899,10 @@ static int video_switch2(int status)
757{ 899{
758 int ret; 900 int ret;
759 901
760 if (video_supported == VIDEO_570) { 902 if (video_supported == IBMACPI_VIDEO_570) {
761 ret = acpi_evalf(NULL, NULL, 903 ret = acpi_evalf(NULL, NULL,
762 "\\_SB.PHS2", "vdd", 0x8b, status | 0x80); 904 "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
763 } else if (video_supported == VIDEO_770) { 905 } else if (video_supported == IBMACPI_VIDEO_770) {
764 int autosw = video_autosw(); 906 int autosw = video_autosw();
765 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) 907 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
766 return -EIO; 908 return -EIO;
@@ -796,10 +938,10 @@ static int video_write(char *buf)
796 enable |= 0x02; 938 enable |= 0x02;
797 } else if (strlencmp(cmd, "crt_disable") == 0) { 939 } else if (strlencmp(cmd, "crt_disable") == 0) {
798 disable |= 0x02; 940 disable |= 0x02;
799 } else if (video_supported == VIDEO_NEW && 941 } else if (video_supported == IBMACPI_VIDEO_NEW &&
800 strlencmp(cmd, "dvi_enable") == 0) { 942 strlencmp(cmd, "dvi_enable") == 0) {
801 enable |= 0x08; 943 enable |= 0x08;
802 } else if (video_supported == VIDEO_NEW && 944 } else if (video_supported == IBMACPI_VIDEO_NEW &&
803 strlencmp(cmd, "dvi_disable") == 0) { 945 strlencmp(cmd, "dvi_disable") == 0) {
804 disable |= 0x08; 946 disable |= 0x08;
805 } else if (strlencmp(cmd, "auto_enable") == 0) { 947 } else if (strlencmp(cmd, "auto_enable") == 0) {
@@ -907,6 +1049,7 @@ static int _sta(acpi_handle handle)
907 1049
908 return status; 1050 return status;
909} 1051}
1052
910#ifdef CONFIG_ACPI_IBM_DOCK 1053#ifdef CONFIG_ACPI_IBM_DOCK
911#define dock_docked() (_sta(dock_handle) & 1) 1054#define dock_docked() (_sta(dock_handle) & 1)
912 1055
@@ -1094,26 +1237,28 @@ static int cmos_write(char *buf)
1094 return 0; 1237 return 0;
1095} 1238}
1096 1239
1097static int led_supported; 1240enum led_access_mode {
1098 1241 IBMACPI_LED_NONE = 0,
1099#define LED_570 1 1242 IBMACPI_LED_570, /* 570 */
1100#define LED_OLD 2 1243 IBMACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1101#define LED_NEW 3 1244 IBMACPI_LED_NEW, /* all others */
1245};
1246static enum led_access_mode led_supported;
1102 1247
1103static int led_init(void) 1248static int led_init(void)
1104{ 1249{
1105 if (!led_handle) 1250 if (!led_handle)
1106 /* led not supported on R30, R31 */ 1251 /* led not supported on R30, R31 */
1107 led_supported = 0; 1252 led_supported = IBMACPI_LED_NONE;
1108 else if (strlencmp(led_path, "SLED") == 0) 1253 else if (strlencmp(led_path, "SLED") == 0)
1109 /* 570 */ 1254 /* 570 */
1110 led_supported = LED_570; 1255 led_supported = IBMACPI_LED_570;
1111 else if (strlencmp(led_path, "SYSL") == 0) 1256 else if (strlencmp(led_path, "SYSL") == 0)
1112 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ 1257 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1113 led_supported = LED_OLD; 1258 led_supported = IBMACPI_LED_OLD;
1114 else 1259 else
1115 /* all others */ 1260 /* all others */
1116 led_supported = LED_NEW; 1261 led_supported = IBMACPI_LED_NEW;
1117 1262
1118 return 0; 1263 return 0;
1119} 1264}
@@ -1130,7 +1275,7 @@ static int led_read(char *p)
1130 } 1275 }
1131 len += sprintf(p + len, "status:\t\tsupported\n"); 1276 len += sprintf(p + len, "status:\t\tsupported\n");
1132 1277
1133 if (led_supported == LED_570) { 1278 if (led_supported == IBMACPI_LED_570) {
1134 /* 570 */ 1279 /* 570 */
1135 int i, status; 1280 int i, status;
1136 for (i = 0; i < 8; i++) { 1281 for (i = 0; i < 8; i++) {
@@ -1179,13 +1324,13 @@ static int led_write(char *buf)
1179 } else 1324 } else
1180 return -EINVAL; 1325 return -EINVAL;
1181 1326
1182 if (led_supported == LED_570) { 1327 if (led_supported == IBMACPI_LED_570) {
1183 /* 570 */ 1328 /* 570 */
1184 led = 1 << led; 1329 led = 1 << led;
1185 if (!acpi_evalf(led_handle, NULL, NULL, "vdd", 1330 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1186 led, led_sled_arg1[ind])) 1331 led, led_sled_arg1[ind]))
1187 return -EIO; 1332 return -EIO;
1188 } else if (led_supported == LED_OLD) { 1333 } else if (led_supported == IBMACPI_LED_OLD) {
1189 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ 1334 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1190 led = 1 << led; 1335 led = 1 << led;
1191 ret = ec_write(EC_HLMS, led); 1336 ret = ec_write(EC_HLMS, led);
@@ -1272,50 +1417,142 @@ static int acpi_ec_write(int i, u8 v)
1272 return 1; 1417 return 1;
1273} 1418}
1274 1419
1275static int thermal_tmp_supported; 1420static enum thermal_access_mode thermal_read_mode;
1276static int thermal_updt_supported;
1277 1421
1278static int thermal_init(void) 1422static int thermal_init(void)
1279{ 1423{
1280 /* temperatures not supported on 570, G4x, R30, R31, R32 */ 1424 u8 t, ta1, ta2;
1281 thermal_tmp_supported = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); 1425 int i;
1426 int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
1427
1428 if (ibm_thinkpad_ec_found && experimental) {
1429 /*
1430 * Direct EC access mode: sensors at registers
1431 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1432 * non-implemented, thermal sensors return 0x80 when
1433 * not available
1434 */
1282 1435
1283 /* 600e/x, 770e, 770x */ 1436 ta1 = ta2 = 0;
1284 thermal_updt_supported = acpi_evalf(ec_handle, NULL, "UPDT", "qv"); 1437 for (i = 0; i < 8; i++) {
1438 if (likely(acpi_ec_read(0x78 + i, &t))) {
1439 ta1 |= t;
1440 } else {
1441 ta1 = 0;
1442 break;
1443 }
1444 if (likely(acpi_ec_read(0xC0 + i, &t))) {
1445 ta2 |= t;
1446 } else {
1447 ta1 = 0;
1448 break;
1449 }
1450 }
1451 if (ta1 == 0) {
1452 /* This is sheer paranoia, but we handle it anyway */
1453 if (acpi_tmp7) {
1454 printk(IBM_ERR
1455 "ThinkPad ACPI EC access misbehaving, "
1456 "falling back to ACPI TMPx access mode\n");
1457 thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
1458 } else {
1459 printk(IBM_ERR
1460 "ThinkPad ACPI EC access misbehaving, "
1461 "disabling thermal sensors access\n");
1462 thermal_read_mode = IBMACPI_THERMAL_NONE;
1463 }
1464 } else {
1465 thermal_read_mode =
1466 (ta2 != 0) ?
1467 IBMACPI_THERMAL_TPEC_16 : IBMACPI_THERMAL_TPEC_8;
1468 }
1469 } else if (acpi_tmp7) {
1470 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
1471 /* 600e/x, 770e, 770x */
1472 thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT;
1473 } else {
1474 /* Standard ACPI TMPx access, max 8 sensors */
1475 thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
1476 }
1477 } else {
1478 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1479 thermal_read_mode = IBMACPI_THERMAL_NONE;
1480 }
1285 1481
1286 return 0; 1482 return 0;
1287} 1483}
1288 1484
1289static int thermal_read(char *p) 1485static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
1290{ 1486{
1291 int len = 0; 1487 int i, t;
1488 s8 tmp;
1489 char tmpi[] = "TMPi";
1292 1490
1293 if (!thermal_tmp_supported) 1491 if (!s)
1294 len += sprintf(p + len, "temperatures:\tnot supported\n"); 1492 return -EINVAL;
1295 else {
1296 int i, t;
1297 char tmpi[] = "TMPi";
1298 s8 tmp[8];
1299 1493
1300 if (thermal_updt_supported) 1494 switch (thermal_read_mode) {
1301 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) 1495#if IBMACPI_MAX_THERMAL_SENSORS >= 16
1496 case IBMACPI_THERMAL_TPEC_16:
1497 for (i = 0; i < 8; i++) {
1498 if (!acpi_ec_read(0xC0 + i, &tmp))
1499 return -EIO;
1500 s->temp[i + 8] = tmp * 1000;
1501 }
1502 /* fallthrough */
1503#endif
1504 case IBMACPI_THERMAL_TPEC_8:
1505 for (i = 0; i < 8; i++) {
1506 if (!acpi_ec_read(0x78 + i, &tmp))
1302 return -EIO; 1507 return -EIO;
1508 s->temp[i] = tmp * 1000;
1509 }
1510 return (thermal_read_mode == IBMACPI_THERMAL_TPEC_16) ? 16 : 8;
1303 1511
1512 case IBMACPI_THERMAL_ACPI_UPDT:
1513 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
1514 return -EIO;
1304 for (i = 0; i < 8; i++) { 1515 for (i = 0; i < 8; i++) {
1305 tmpi[3] = '0' + i; 1516 tmpi[3] = '0' + i;
1306 if (!acpi_evalf(ec_handle, &t, tmpi, "d")) 1517 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1307 return -EIO; 1518 return -EIO;
1308 if (thermal_updt_supported) 1519 s->temp[i] = (t - 2732) * 100;
1309 tmp[i] = (t - 2732 + 5) / 10;
1310 else
1311 tmp[i] = t;
1312 } 1520 }
1521 return 8;
1313 1522
1314 len += sprintf(p + len, 1523 case IBMACPI_THERMAL_ACPI_TMP07:
1315 "temperatures:\t%d %d %d %d %d %d %d %d\n", 1524 for (i = 0; i < 8; i++) {
1316 tmp[0], tmp[1], tmp[2], tmp[3], 1525 tmpi[3] = '0' + i;
1317 tmp[4], tmp[5], tmp[6], tmp[7]); 1526 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1527 return -EIO;
1528 s->temp[i] = t * 1000;
1529 }
1530 return 8;
1531
1532 case IBMACPI_THERMAL_NONE:
1533 default:
1534 return 0;
1318 } 1535 }
1536}
1537
1538static int thermal_read(char *p)
1539{
1540 int len = 0;
1541 int n, i;
1542 struct ibm_thermal_sensors_struct t;
1543
1544 n = thermal_get_sensors(&t);
1545 if (unlikely(n < 0))
1546 return n;
1547
1548 len += sprintf(p + len, "temperatures:\t");
1549
1550 if (n > 0) {
1551 for (i = 0; i < (n - 1); i++)
1552 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
1553 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
1554 } else
1555 len += sprintf(p + len, "not supported\n");
1319 1556
1320 return len; 1557 return len;
1321} 1558}
@@ -1381,12 +1618,23 @@ static int ecdump_write(char *buf)
1381 1618
1382static int brightness_offset = 0x31; 1619static int brightness_offset = 0x31;
1383 1620
1621static int brightness_get(struct backlight_device *bd)
1622{
1623 u8 level;
1624 if (!acpi_ec_read(brightness_offset, &level))
1625 return -EIO;
1626
1627 level &= 0x7;
1628
1629 return level;
1630}
1631
1384static int brightness_read(char *p) 1632static int brightness_read(char *p)
1385{ 1633{
1386 int len = 0; 1634 int len = 0;
1387 u8 level; 1635 int level;
1388 1636
1389 if (!acpi_ec_read(brightness_offset, &level)) { 1637 if ((level = brightness_get(NULL)) < 0) {
1390 len += sprintf(p + len, "level:\t\tunreadable\n"); 1638 len += sprintf(p + len, "level:\t\tunreadable\n");
1391 } else { 1639 } else {
1392 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7); 1640 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
@@ -1401,16 +1649,34 @@ static int brightness_read(char *p)
1401#define BRIGHTNESS_UP 4 1649#define BRIGHTNESS_UP 4
1402#define BRIGHTNESS_DOWN 5 1650#define BRIGHTNESS_DOWN 5
1403 1651
1404static int brightness_write(char *buf) 1652static int brightness_set(int value)
1405{ 1653{
1406 int cmos_cmd, inc, i; 1654 int cmos_cmd, inc, i;
1407 u8 level; 1655 int current_value = brightness_get(NULL);
1656
1657 value &= 7;
1658
1659 cmos_cmd = value > current_value ? BRIGHTNESS_UP : BRIGHTNESS_DOWN;
1660 inc = value > current_value ? 1 : -1;
1661 for (i = current_value; i != value; i += inc) {
1662 if (!cmos_eval(cmos_cmd))
1663 return -EIO;
1664 if (!acpi_ec_write(brightness_offset, i + inc))
1665 return -EIO;
1666 }
1667
1668 return 0;
1669}
1670
1671static int brightness_write(char *buf)
1672{
1673 int level;
1408 int new_level; 1674 int new_level;
1409 char *cmd; 1675 char *cmd;
1410 1676
1411 while ((cmd = next_cmd(&buf))) { 1677 while ((cmd = next_cmd(&buf))) {
1412 if (!acpi_ec_read(brightness_offset, &level)) 1678 if ((level = brightness_get(NULL)) < 0)
1413 return -EIO; 1679 return level;
1414 level &= 7; 1680 level &= 7;
1415 1681
1416 if (strlencmp(cmd, "up") == 0) { 1682 if (strlencmp(cmd, "up") == 0) {
@@ -1423,19 +1689,44 @@ static int brightness_write(char *buf)
1423 } else 1689 } else
1424 return -EINVAL; 1690 return -EINVAL;
1425 1691
1426 cmos_cmd = new_level > level ? BRIGHTNESS_UP : BRIGHTNESS_DOWN; 1692 brightness_set(new_level);
1427 inc = new_level > level ? 1 : -1; 1693 }
1428 for (i = level; i != new_level; i += inc) { 1694
1429 if (!cmos_eval(cmos_cmd)) 1695 return 0;
1430 return -EIO; 1696}
1431 if (!acpi_ec_write(brightness_offset, i + inc)) 1697
1432 return -EIO; 1698static int brightness_update_status(struct backlight_device *bd)
1433 } 1699{
1700 return brightness_set(bd->props->brightness);
1701}
1702
1703static struct backlight_properties ibm_backlight_data = {
1704 .owner = THIS_MODULE,
1705 .get_brightness = brightness_get,
1706 .update_status = brightness_update_status,
1707 .max_brightness = 7,
1708};
1709
1710static int brightness_init(void)
1711{
1712 ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
1713 &ibm_backlight_data);
1714 if (IS_ERR(ibm_backlight_device)) {
1715 printk(IBM_ERR "Could not register backlight device\n");
1716 return PTR_ERR(ibm_backlight_device);
1434 } 1717 }
1435 1718
1436 return 0; 1719 return 0;
1437} 1720}
1438 1721
1722static void brightness_exit(void)
1723{
1724 if (ibm_backlight_device) {
1725 backlight_device_unregister(ibm_backlight_device);
1726 ibm_backlight_device = NULL;
1727 }
1728}
1729
1439static int volume_offset = 0x30; 1730static int volume_offset = 0x30;
1440 1731
1441static int volume_read(char *p) 1732static int volume_read(char *p)
@@ -1522,90 +1813,486 @@ static int volume_write(char *buf)
1522 return 0; 1813 return 0;
1523} 1814}
1524 1815
1525static int fan_status_offset = 0x2f; 1816static enum fan_status_access_mode fan_status_access_mode;
1526static int fan_rpm_offset = 0x84; 1817static enum fan_control_access_mode fan_control_access_mode;
1818static enum fan_control_commands fan_control_commands;
1527 1819
1528static int fan_read(char *p) 1820static int fan_control_status_known;
1821static u8 fan_control_initial_status;
1822
1823static void fan_watchdog_fire(struct work_struct *ignored);
1824static int fan_watchdog_maxinterval;
1825static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
1826
1827static int fan_init(void)
1529{ 1828{
1530 int len = 0; 1829 fan_status_access_mode = IBMACPI_FAN_NONE;
1531 int s; 1830 fan_control_access_mode = IBMACPI_FAN_WR_NONE;
1532 u8 lo, hi, status; 1831 fan_control_commands = 0;
1832 fan_control_status_known = 1;
1833 fan_watchdog_maxinterval = 0;
1533 1834
1534 if (gfan_handle) { 1835 if (gfan_handle) {
1535 /* 570, 600e/x, 770e, 770x */ 1836 /* 570, 600e/x, 770e, 770x */
1536 if (!acpi_evalf(gfan_handle, &s, NULL, "d")) 1837 fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN;
1537 return -EIO; 1838 } else {
1839 /* all other ThinkPads: note that even old-style
1840 * ThinkPad ECs supports the fan control register */
1841 if (likely(acpi_ec_read(fan_status_offset,
1842 &fan_control_initial_status))) {
1843 fan_status_access_mode = IBMACPI_FAN_RD_TPEC;
1844
1845 /* In some ThinkPads, neither the EC nor the ACPI
1846 * DSDT initialize the fan status, and it ends up
1847 * being set to 0x07 when it *could* be either
1848 * 0x07 or 0x80.
1849 *
1850 * Enable for TP-1Y (T43), TP-78 (R51e),
1851 * TP-76 (R52), TP-70 (T43, R52), which are known
1852 * to be buggy. */
1853 if (fan_control_initial_status == 0x07 &&
1854 ibm_thinkpad_ec_found &&
1855 ((ibm_thinkpad_ec_found[0] == '1' &&
1856 ibm_thinkpad_ec_found[1] == 'Y') ||
1857 (ibm_thinkpad_ec_found[0] == '7' &&
1858 (ibm_thinkpad_ec_found[1] == '6' ||
1859 ibm_thinkpad_ec_found[1] == '8' ||
1860 ibm_thinkpad_ec_found[1] == '0'))
1861 )) {
1862 printk(IBM_NOTICE
1863 "fan_init: initial fan status is "
1864 "unknown, assuming it is in auto "
1865 "mode\n");
1866 fan_control_status_known = 0;
1867 }
1868 } else {
1869 printk(IBM_ERR
1870 "ThinkPad ACPI EC access misbehaving, "
1871 "fan status and control unavailable\n");
1872 return 0;
1873 }
1874 }
1538 1875
1539 len += sprintf(p + len, "level:\t\t%d\n", s); 1876 if (sfan_handle) {
1877 /* 570, 770x-JL */
1878 fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN;
1879 fan_control_commands |=
1880 IBMACPI_FAN_CMD_LEVEL | IBMACPI_FAN_CMD_ENABLE;
1540 } else { 1881 } else {
1882 if (!gfan_handle) {
1883 /* gfan without sfan means no fan control */
1884 /* all other models implement TP EC 0x2f control */
1885
1886 if (fans_handle) {
1887 /* X31, X40, X41 */
1888 fan_control_access_mode =
1889 IBMACPI_FAN_WR_ACPI_FANS;
1890 fan_control_commands |=
1891 IBMACPI_FAN_CMD_SPEED |
1892 IBMACPI_FAN_CMD_LEVEL |
1893 IBMACPI_FAN_CMD_ENABLE;
1894 } else {
1895 fan_control_access_mode = IBMACPI_FAN_WR_TPEC;
1896 fan_control_commands |=
1897 IBMACPI_FAN_CMD_LEVEL |
1898 IBMACPI_FAN_CMD_ENABLE;
1899 }
1900 }
1901 }
1902
1903 return 0;
1904}
1905
1906static int fan_get_status(u8 *status)
1907{
1908 u8 s;
1909
1910 /* TODO:
1911 * Add IBMACPI_FAN_RD_ACPI_FANS ? */
1912
1913 switch (fan_status_access_mode) {
1914 case IBMACPI_FAN_RD_ACPI_GFAN:
1915 /* 570, 600e/x, 770e, 770x */
1916
1917 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
1918 return -EIO;
1919
1920 if (likely(status))
1921 *status = s & 0x07;
1922
1923 break;
1924
1925 case IBMACPI_FAN_RD_TPEC:
1541 /* all except 570, 600e/x, 770e, 770x */ 1926 /* all except 570, 600e/x, 770e, 770x */
1542 if (!acpi_ec_read(fan_status_offset, &status)) 1927 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
1543 len += sprintf(p + len, "status:\t\tunreadable\n"); 1928 return -EIO;
1544 else
1545 len += sprintf(p + len, "status:\t\t%s\n",
1546 enabled(status, 7));
1547 1929
1548 if (!acpi_ec_read(fan_rpm_offset, &lo) || 1930 if (likely(status))
1549 !acpi_ec_read(fan_rpm_offset + 1, &hi)) 1931 *status = s;
1550 len += sprintf(p + len, "speed:\t\tunreadable\n"); 1932
1551 else 1933 break;
1552 len += sprintf(p + len, "speed:\t\t%d\n", 1934
1553 (hi << 8) + lo); 1935 default:
1936 return -ENXIO;
1554 } 1937 }
1555 1938
1556 if (sfan_handle) 1939 return 0;
1557 /* 570, 770x-JL */ 1940}
1558 len += sprintf(p + len, "commands:\tlevel <level>" 1941
1559 " (<level> is 0-7)\n"); 1942static int fan_get_speed(unsigned int *speed)
1560 if (!gfan_handle) 1943{
1944 u8 hi, lo;
1945
1946 switch (fan_status_access_mode) {
1947 case IBMACPI_FAN_RD_TPEC:
1561 /* all except 570, 600e/x, 770e, 770x */ 1948 /* all except 570, 600e/x, 770e, 770x */
1562 len += sprintf(p + len, "commands:\tenable, disable\n"); 1949 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
1563 if (fans_handle) 1950 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
1564 /* X31, X40 */ 1951 return -EIO;
1952
1953 if (likely(speed))
1954 *speed = (hi << 8) | lo;
1955
1956 break;
1957
1958 default:
1959 return -ENXIO;
1960 }
1961
1962 return 0;
1963}
1964
1965static void fan_exit(void)
1966{
1967 cancel_delayed_work(&fan_watchdog_task);
1968 flush_scheduled_work();
1969}
1970
1971static void fan_watchdog_reset(void)
1972{
1973 static int fan_watchdog_active = 0;
1974
1975 if (fan_watchdog_active)
1976 cancel_delayed_work(&fan_watchdog_task);
1977
1978 if (fan_watchdog_maxinterval > 0) {
1979 fan_watchdog_active = 1;
1980 if (!schedule_delayed_work(&fan_watchdog_task,
1981 msecs_to_jiffies(fan_watchdog_maxinterval
1982 * 1000))) {
1983 printk(IBM_ERR "failed to schedule the fan watchdog, "
1984 "watchdog will not trigger\n");
1985 }
1986 } else
1987 fan_watchdog_active = 0;
1988}
1989
1990static int fan_read(char *p)
1991{
1992 int len = 0;
1993 int rc;
1994 u8 status;
1995 unsigned int speed = 0;
1996
1997 switch (fan_status_access_mode) {
1998 case IBMACPI_FAN_RD_ACPI_GFAN:
1999 /* 570, 600e/x, 770e, 770x */
2000 if ((rc = fan_get_status(&status)) < 0)
2001 return rc;
2002
2003 len += sprintf(p + len, "status:\t\t%s\n"
2004 "level:\t\t%d\n",
2005 (status != 0) ? "enabled" : "disabled", status);
2006 break;
2007
2008 case IBMACPI_FAN_RD_TPEC:
2009 /* all except 570, 600e/x, 770e, 770x */
2010 if ((rc = fan_get_status(&status)) < 0)
2011 return rc;
2012
2013 if (unlikely(!fan_control_status_known)) {
2014 if (status != fan_control_initial_status)
2015 fan_control_status_known = 1;
2016 else
2017 /* Return most likely status. In fact, it
2018 * might be the only possible status */
2019 status = IBMACPI_FAN_EC_AUTO;
2020 }
2021
2022 len += sprintf(p + len, "status:\t\t%s\n",
2023 (status != 0) ? "enabled" : "disabled");
2024
2025 /* No ThinkPad boots on disengaged mode, we can safely
2026 * assume the tachometer is online if fan control status
2027 * was unknown */
2028 if ((rc = fan_get_speed(&speed)) < 0)
2029 return rc;
2030
2031 len += sprintf(p + len, "speed:\t\t%d\n", speed);
2032
2033 if (status & IBMACPI_FAN_EC_DISENGAGED)
2034 /* Disengaged mode takes precedence */
2035 len += sprintf(p + len, "level:\t\tdisengaged\n");
2036 else if (status & IBMACPI_FAN_EC_AUTO)
2037 len += sprintf(p + len, "level:\t\tauto\n");
2038 else
2039 len += sprintf(p + len, "level:\t\t%d\n", status);
2040 break;
2041
2042 case IBMACPI_FAN_NONE:
2043 default:
2044 len += sprintf(p + len, "status:\t\tnot supported\n");
2045 }
2046
2047 if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL) {
2048 len += sprintf(p + len, "commands:\tlevel <level>");
2049
2050 switch (fan_control_access_mode) {
2051 case IBMACPI_FAN_WR_ACPI_SFAN:
2052 len += sprintf(p + len, " (<level> is 0-7)\n");
2053 break;
2054
2055 default:
2056 len += sprintf(p + len, " (<level> is 0-7, "
2057 "auto, disengaged)\n");
2058 break;
2059 }
2060 }
2061
2062 if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE)
2063 len += sprintf(p + len, "commands:\tenable, disable\n"
2064 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2065 "1-120 (seconds))\n");
2066
2067 if (fan_control_commands & IBMACPI_FAN_CMD_SPEED)
1565 len += sprintf(p + len, "commands:\tspeed <speed>" 2068 len += sprintf(p + len, "commands:\tspeed <speed>"
1566 " (<speed> is 0-65535)\n"); 2069 " (<speed> is 0-65535)\n");
1567 2070
1568 return len; 2071 return len;
1569} 2072}
1570 2073
1571static int fan_write(char *buf) 2074static int fan_set_level(int level)
1572{ 2075{
1573 char *cmd; 2076 switch (fan_control_access_mode) {
1574 int level, speed; 2077 case IBMACPI_FAN_WR_ACPI_SFAN:
1575 2078 if (level >= 0 && level <= 7) {
1576 while ((cmd = next_cmd(&buf))) {
1577 if (sfan_handle &&
1578 sscanf(cmd, "level %d", &level) == 1 &&
1579 level >= 0 && level <= 7) {
1580 /* 570, 770x-JL */
1581 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) 2079 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
1582 return -EIO; 2080 return -EIO;
1583 } else if (!gfan_handle && strlencmp(cmd, "enable") == 0) { 2081 } else
1584 /* all except 570, 600e/x, 770e, 770x */ 2082 return -EINVAL;
1585 if (!acpi_ec_write(fan_status_offset, 0x80)) 2083 break;
1586 return -EIO; 2084
1587 } else if (!gfan_handle && strlencmp(cmd, "disable") == 0) { 2085 case IBMACPI_FAN_WR_ACPI_FANS:
1588 /* all except 570, 600e/x, 770e, 770x */ 2086 case IBMACPI_FAN_WR_TPEC:
1589 if (!acpi_ec_write(fan_status_offset, 0x00)) 2087 if ((level != IBMACPI_FAN_EC_AUTO) &&
1590 return -EIO; 2088 (level != IBMACPI_FAN_EC_DISENGAGED) &&
1591 } else if (fans_handle && 2089 ((level < 0) || (level > 7)))
1592 sscanf(cmd, "speed %d", &speed) == 1 && 2090 return -EINVAL;
1593 speed >= 0 && speed <= 65535) { 2091
1594 /* X31, X40 */ 2092 if (!acpi_ec_write(fan_status_offset, level))
2093 return -EIO;
2094 else
2095 fan_control_status_known = 1;
2096 break;
2097
2098 default:
2099 return -ENXIO;
2100 }
2101 return 0;
2102}
2103
2104static int fan_set_enable(void)
2105{
2106 u8 s;
2107 int rc;
2108
2109 switch (fan_control_access_mode) {
2110 case IBMACPI_FAN_WR_ACPI_FANS:
2111 case IBMACPI_FAN_WR_TPEC:
2112 if ((rc = fan_get_status(&s)) < 0)
2113 return rc;
2114
2115 /* Don't go out of emergency fan mode */
2116 if (s != 7)
2117 s = IBMACPI_FAN_EC_AUTO;
2118
2119 if (!acpi_ec_write(fan_status_offset, s))
2120 return -EIO;
2121 else
2122 fan_control_status_known = 1;
2123 break;
2124
2125 case IBMACPI_FAN_WR_ACPI_SFAN:
2126 if ((rc = fan_get_status(&s)) < 0)
2127 return rc;
2128
2129 s &= 0x07;
2130
2131 /* Set fan to at least level 4 */
2132 if (s < 4)
2133 s = 4;
2134
2135 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
2136 return -EIO;
2137 break;
2138
2139 default:
2140 return -ENXIO;
2141 }
2142 return 0;
2143}
2144
2145static int fan_set_disable(void)
2146{
2147 switch (fan_control_access_mode) {
2148 case IBMACPI_FAN_WR_ACPI_FANS:
2149 case IBMACPI_FAN_WR_TPEC:
2150 if (!acpi_ec_write(fan_status_offset, 0x00))
2151 return -EIO;
2152 else
2153 fan_control_status_known = 1;
2154 break;
2155
2156 case IBMACPI_FAN_WR_ACPI_SFAN:
2157 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
2158 return -EIO;
2159 break;
2160
2161 default:
2162 return -ENXIO;
2163 }
2164 return 0;
2165}
2166
2167static int fan_set_speed(int speed)
2168{
2169 switch (fan_control_access_mode) {
2170 case IBMACPI_FAN_WR_ACPI_FANS:
2171 if (speed >= 0 && speed <= 65535) {
1595 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", 2172 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
1596 speed, speed, speed)) 2173 speed, speed, speed))
1597 return -EIO; 2174 return -EIO;
1598 } else 2175 } else
1599 return -EINVAL; 2176 return -EINVAL;
1600 } 2177 break;
1601 2178
2179 default:
2180 return -ENXIO;
2181 }
1602 return 0; 2182 return 0;
1603} 2183}
1604 2184
2185static int fan_write_cmd_level(const char *cmd, int *rc)
2186{
2187 int level;
2188
2189 if (strlencmp(cmd, "level auto") == 0)
2190 level = IBMACPI_FAN_EC_AUTO;
2191 else if (strlencmp(cmd, "level disengaged") == 0)
2192 level = IBMACPI_FAN_EC_DISENGAGED;
2193 else if (sscanf(cmd, "level %d", &level) != 1)
2194 return 0;
2195
2196 if ((*rc = fan_set_level(level)) == -ENXIO)
2197 printk(IBM_ERR "level command accepted for unsupported "
2198 "access mode %d", fan_control_access_mode);
2199
2200 return 1;
2201}
2202
2203static int fan_write_cmd_enable(const char *cmd, int *rc)
2204{
2205 if (strlencmp(cmd, "enable") != 0)
2206 return 0;
2207
2208 if ((*rc = fan_set_enable()) == -ENXIO)
2209 printk(IBM_ERR "enable command accepted for unsupported "
2210 "access mode %d", fan_control_access_mode);
2211
2212 return 1;
2213}
2214
2215static int fan_write_cmd_disable(const char *cmd, int *rc)
2216{
2217 if (strlencmp(cmd, "disable") != 0)
2218 return 0;
2219
2220 if ((*rc = fan_set_disable()) == -ENXIO)
2221 printk(IBM_ERR "disable command accepted for unsupported "
2222 "access mode %d", fan_control_access_mode);
2223
2224 return 1;
2225}
2226
2227static int fan_write_cmd_speed(const char *cmd, int *rc)
2228{
2229 int speed;
2230
2231 /* TODO:
2232 * Support speed <low> <medium> <high> ? */
2233
2234 if (sscanf(cmd, "speed %d", &speed) != 1)
2235 return 0;
2236
2237 if ((*rc = fan_set_speed(speed)) == -ENXIO)
2238 printk(IBM_ERR "speed command accepted for unsupported "
2239 "access mode %d", fan_control_access_mode);
2240
2241 return 1;
2242}
2243
2244static int fan_write_cmd_watchdog(const char *cmd, int *rc)
2245{
2246 int interval;
2247
2248 if (sscanf(cmd, "watchdog %d", &interval) != 1)
2249 return 0;
2250
2251 if (interval < 0 || interval > 120)
2252 *rc = -EINVAL;
2253 else
2254 fan_watchdog_maxinterval = interval;
2255
2256 return 1;
2257}
2258
2259static int fan_write(char *buf)
2260{
2261 char *cmd;
2262 int rc = 0;
2263
2264 while (!rc && (cmd = next_cmd(&buf))) {
2265 if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) &&
2266 fan_write_cmd_level(cmd, &rc)) &&
2267 !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) &&
2268 (fan_write_cmd_enable(cmd, &rc) ||
2269 fan_write_cmd_disable(cmd, &rc) ||
2270 fan_write_cmd_watchdog(cmd, &rc))) &&
2271 !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) &&
2272 fan_write_cmd_speed(cmd, &rc))
2273 )
2274 rc = -EINVAL;
2275 else if (!rc)
2276 fan_watchdog_reset();
2277 }
2278
2279 return rc;
2280}
2281
2282static void fan_watchdog_fire(struct work_struct *ignored)
2283{
2284 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
2285 if (fan_set_enable()) {
2286 printk(IBM_ERR "fan watchdog: error while enabling fan\n");
2287 /* reschedule for later */
2288 fan_watchdog_reset();
2289 }
2290}
2291
1605static struct ibm_struct ibms[] = { 2292static struct ibm_struct ibms[] = {
1606 { 2293 {
1607 .name = "driver", 2294 .name = "driver",
1608 .init = driver_init, 2295 .init = ibm_acpi_driver_init,
1609 .read = driver_read, 2296 .read = driver_read,
1610 }, 2297 },
1611 { 2298 {
@@ -1702,6 +2389,8 @@ static struct ibm_struct ibms[] = {
1702 .name = "brightness", 2389 .name = "brightness",
1703 .read = brightness_read, 2390 .read = brightness_read,
1704 .write = brightness_write, 2391 .write = brightness_write,
2392 .init = brightness_init,
2393 .exit = brightness_exit,
1705 }, 2394 },
1706 { 2395 {
1707 .name = "volume", 2396 .name = "volume",
@@ -1712,6 +2401,8 @@ static struct ibm_struct ibms[] = {
1712 .name = "fan", 2401 .name = "fan",
1713 .read = fan_read, 2402 .read = fan_read,
1714 .write = fan_write, 2403 .write = fan_write,
2404 .init = fan_init,
2405 .exit = fan_exit,
1715 .experimental = 1, 2406 .experimental = 1,
1716 }, 2407 },
1717}; 2408};
@@ -1719,7 +2410,7 @@ static struct ibm_struct ibms[] = {
1719static int dispatch_read(char *page, char **start, off_t off, int count, 2410static int dispatch_read(char *page, char **start, off_t off, int count,
1720 int *eof, void *data) 2411 int *eof, void *data)
1721{ 2412{
1722 struct ibm_struct *ibm = (struct ibm_struct *)data; 2413 struct ibm_struct *ibm = data;
1723 int len; 2414 int len;
1724 2415
1725 if (!ibm || !ibm->read) 2416 if (!ibm || !ibm->read)
@@ -1744,7 +2435,7 @@ static int dispatch_read(char *page, char **start, off_t off, int count,
1744static int dispatch_write(struct file *file, const char __user * userbuf, 2435static int dispatch_write(struct file *file, const char __user * userbuf,
1745 unsigned long count, void *data) 2436 unsigned long count, void *data)
1746{ 2437{
1747 struct ibm_struct *ibm = (struct ibm_struct *)data; 2438 struct ibm_struct *ibm = data;
1748 char *kernbuf; 2439 char *kernbuf;
1749 int ret; 2440 int ret;
1750 2441
@@ -1773,7 +2464,7 @@ static int dispatch_write(struct file *file, const char __user * userbuf,
1773 2464
1774static void dispatch_notify(acpi_handle handle, u32 event, void *data) 2465static void dispatch_notify(acpi_handle handle, u32 event, void *data)
1775{ 2466{
1776 struct ibm_struct *ibm = (struct ibm_struct *)data; 2467 struct ibm_struct *ibm = data;
1777 2468
1778 if (!ibm || !ibm->notify) 2469 if (!ibm || !ibm->notify)
1779 return; 2470 return;
@@ -1805,7 +2496,7 @@ static int __init setup_notify(struct ibm_struct *ibm)
1805 ibm->name, status); 2496 ibm->name, status);
1806 return -ENODEV; 2497 return -ENODEV;
1807 } 2498 }
1808 2499 ibm->notify_installed = 1;
1809 return 0; 2500 return 0;
1810} 2501}
1811 2502
@@ -1818,14 +2509,13 @@ static int __init register_driver(struct ibm_struct *ibm)
1818{ 2509{
1819 int ret; 2510 int ret;
1820 2511
1821 ibm->driver = kmalloc(sizeof(struct acpi_driver), GFP_KERNEL); 2512 ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
1822 if (!ibm->driver) { 2513 if (!ibm->driver) {
1823 printk(IBM_ERR "kmalloc(ibm->driver) failed\n"); 2514 printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
1824 return -1; 2515 return -1;
1825 } 2516 }
1826 2517
1827 memset(ibm->driver, 0, sizeof(struct acpi_driver)); 2518 sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
1828 sprintf(ibm->driver->name, "%s/%s", IBM_NAME, ibm->name);
1829 ibm->driver->ids = ibm->hid; 2519 ibm->driver->ids = ibm->hid;
1830 ibm->driver->ops.add = &ibm_device_add; 2520 ibm->driver->ops.add = &ibm_device_add;
1831 2521
@@ -1882,7 +2572,6 @@ static int __init ibm_init(struct ibm_struct *ibm)
1882 ret = setup_notify(ibm); 2572 ret = setup_notify(ibm);
1883 if (ret < 0) 2573 if (ret < 0)
1884 return ret; 2574 return ret;
1885 ibm->notify_installed = 1;
1886 } 2575 }
1887 2576
1888 return 0; 2577 return 0;
@@ -1971,6 +2660,33 @@ static void acpi_ibm_exit(void)
1971 ibm_exit(&ibms[i]); 2660 ibm_exit(&ibms[i]);
1972 2661
1973 remove_proc_entry(IBM_DIR, acpi_root_dir); 2662 remove_proc_entry(IBM_DIR, acpi_root_dir);
2663
2664 if (ibm_thinkpad_ec_found)
2665 kfree(ibm_thinkpad_ec_found);
2666}
2667
2668static char* __init check_dmi_for_ec(void)
2669{
2670 struct dmi_device *dev = NULL;
2671 char ec_fw_string[18];
2672
2673 /*
2674 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2675 * X32 or newer, all Z series; Some models must have an
2676 * up-to-date BIOS or they will not be detected.
2677 *
2678 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2679 */
2680 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
2681 if (sscanf(dev->name,
2682 "IBM ThinkPad Embedded Controller -[%17c",
2683 ec_fw_string) == 1) {
2684 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
2685 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
2686 return kstrdup(ec_fw_string, GFP_KERNEL);
2687 }
2688 }
2689 return NULL;
1974} 2690}
1975 2691
1976static int __init acpi_ibm_init(void) 2692static int __init acpi_ibm_init(void)
@@ -1992,6 +2708,12 @@ static int __init acpi_ibm_init(void)
1992 return -ENODEV; 2708 return -ENODEV;
1993 } 2709 }
1994 2710
2711 /* Models with newer firmware report the EC in DMI */
2712 ibm_thinkpad_ec_found = check_dmi_for_ec();
2713 if (ibm_thinkpad_ec_found)
2714 printk(IBM_INFO "ThinkPad EC firmware %s\n",
2715 ibm_thinkpad_ec_found);
2716
1995 /* these handles are not required */ 2717 /* these handles are not required */
1996 IBM_HANDLE_INIT(vid); 2718 IBM_HANDLE_INIT(vid);
1997 IBM_HANDLE_INIT(vid2); 2719 IBM_HANDLE_INIT(vid2);
diff --git a/drivers/acpi/motherboard.c b/drivers/acpi/motherboard.c
index bedb5118e3..8f13b4f3e9 100644
--- a/drivers/acpi/motherboard.c
+++ b/drivers/acpi/motherboard.c
@@ -124,41 +124,41 @@ static void __init acpi_request_region (struct acpi_generic_address *addr,
124 if (!addr->address || !length) 124 if (!addr->address || !length)
125 return; 125 return;
126 126
127 if (addr->address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) 127 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
128 request_region(addr->address, length, desc); 128 request_region(addr->address, length, desc);
129 else if (addr->address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) 129 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
130 request_mem_region(addr->address, length, desc); 130 request_mem_region(addr->address, length, desc);
131} 131}
132 132
133static void __init acpi_reserve_resources(void) 133static void __init acpi_reserve_resources(void)
134{ 134{
135 acpi_request_region(&acpi_gbl_FADT->xpm1a_evt_blk, 135 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block,
136 acpi_gbl_FADT->pm1_evt_len, "ACPI PM1a_EVT_BLK"); 136 acpi_gbl_FADT.pm1_event_length, "ACPI PM1a_EVT_BLK");
137 137
138 acpi_request_region(&acpi_gbl_FADT->xpm1b_evt_blk, 138 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block,
139 acpi_gbl_FADT->pm1_evt_len, "ACPI PM1b_EVT_BLK"); 139 acpi_gbl_FADT.pm1_event_length, "ACPI PM1b_EVT_BLK");
140 140
141 acpi_request_region(&acpi_gbl_FADT->xpm1a_cnt_blk, 141 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block,
142 acpi_gbl_FADT->pm1_cnt_len, "ACPI PM1a_CNT_BLK"); 142 acpi_gbl_FADT.pm1_control_length, "ACPI PM1a_CNT_BLK");
143 143
144 acpi_request_region(&acpi_gbl_FADT->xpm1b_cnt_blk, 144 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block,
145 acpi_gbl_FADT->pm1_cnt_len, "ACPI PM1b_CNT_BLK"); 145 acpi_gbl_FADT.pm1_control_length, "ACPI PM1b_CNT_BLK");
146 146
147 if (acpi_gbl_FADT->pm_tm_len == 4) 147 if (acpi_gbl_FADT.pm_timer_length == 4)
148 acpi_request_region(&acpi_gbl_FADT->xpm_tmr_blk, 4, "ACPI PM_TMR"); 148 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
149 149
150 acpi_request_region(&acpi_gbl_FADT->xpm2_cnt_blk, 150 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block,
151 acpi_gbl_FADT->pm2_cnt_len, "ACPI PM2_CNT_BLK"); 151 acpi_gbl_FADT.pm2_control_length, "ACPI PM2_CNT_BLK");
152 152
153 /* Length of GPE blocks must be a non-negative multiple of 2 */ 153 /* Length of GPE blocks must be a non-negative multiple of 2 */
154 154
155 if (!(acpi_gbl_FADT->gpe0_blk_len & 0x1)) 155 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
156 acpi_request_region(&acpi_gbl_FADT->xgpe0_blk, 156 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
157 acpi_gbl_FADT->gpe0_blk_len, "ACPI GPE0_BLK"); 157 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
158 158
159 if (!(acpi_gbl_FADT->gpe1_blk_len & 0x1)) 159 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
160 acpi_request_region(&acpi_gbl_FADT->xgpe1_blk, 160 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
161 acpi_gbl_FADT->gpe1_blk_len, "ACPI GPE1_BLK"); 161 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
162} 162}
163 163
164static int __init acpi_motherboard_init(void) 164static int __init acpi_motherboard_init(void)
diff --git a/drivers/acpi/namespace/nsaccess.c b/drivers/acpi/namespace/nsaccess.c
index c1c6c236df..57faf598ba 100644
--- a/drivers/acpi/namespace/nsaccess.c
+++ b/drivers/acpi/namespace/nsaccess.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -195,31 +195,27 @@ acpi_status acpi_ns_root_initialize(void)
195 obj_desc->mutex.sync_level = 195 obj_desc->mutex.sync_level =
196 (u8) (ACPI_TO_INTEGER(val) - 1); 196 (u8) (ACPI_TO_INTEGER(val) - 1);
197 197
198 if (ACPI_STRCMP(init_val->name, "_GL_") == 0) { 198 /* Create a mutex */
199 199
200 /* Create a counting semaphore for the global lock */ 200 status =
201 acpi_os_create_mutex(&obj_desc->mutex.
202 os_mutex);
203 if (ACPI_FAILURE(status)) {
204 acpi_ut_remove_reference(obj_desc);
205 goto unlock_and_exit;
206 }
201 207
202 status = 208 /* Special case for ACPI Global Lock */
203 acpi_os_create_semaphore
204 (ACPI_NO_UNIT_LIMIT, 1,
205 &acpi_gbl_global_lock_semaphore);
206 if (ACPI_FAILURE(status)) {
207 acpi_ut_remove_reference
208 (obj_desc);
209 goto unlock_and_exit;
210 }
211 209
212 /* Mark this mutex as very special */ 210 if (ACPI_STRCMP(init_val->name, "_GL_") == 0) {
211 acpi_gbl_global_lock_mutex =
212 obj_desc->mutex.os_mutex;
213 213
214 obj_desc->mutex.os_mutex = 214 /* Create additional counting semaphore for global lock */
215 ACPI_GLOBAL_LOCK;
216 } else {
217 /* Create a mutex */
218 215
219 status = 216 status =
220 acpi_os_create_mutex(&obj_desc-> 217 acpi_os_create_semaphore(1, 0,
221 mutex. 218 &acpi_gbl_global_lock_semaphore);
222 os_mutex);
223 if (ACPI_FAILURE(status)) { 219 if (ACPI_FAILURE(status)) {
224 acpi_ut_remove_reference 220 acpi_ut_remove_reference
225 (obj_desc); 221 (obj_desc);
diff --git a/drivers/acpi/namespace/nsalloc.c b/drivers/acpi/namespace/nsalloc.c
index 55b407aae2..1d693d8ad2 100644
--- a/drivers/acpi/namespace/nsalloc.c
+++ b/drivers/acpi/namespace/nsalloc.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -61,6 +61,9 @@ ACPI_MODULE_NAME("nsalloc")
61struct acpi_namespace_node *acpi_ns_create_node(u32 name) 61struct acpi_namespace_node *acpi_ns_create_node(u32 name)
62{ 62{
63 struct acpi_namespace_node *node; 63 struct acpi_namespace_node *node;
64#ifdef ACPI_DBG_TRACK_ALLOCATIONS
65 u32 temp;
66#endif
64 67
65 ACPI_FUNCTION_TRACE(ns_create_node); 68 ACPI_FUNCTION_TRACE(ns_create_node);
66 69
@@ -71,6 +74,15 @@ struct acpi_namespace_node *acpi_ns_create_node(u32 name)
71 74
72 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++); 75 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++);
73 76
77#ifdef ACPI_DBG_TRACK_ALLOCATIONS
78 temp =
79 acpi_gbl_ns_node_list->total_allocated -
80 acpi_gbl_ns_node_list->total_freed;
81 if (temp > acpi_gbl_ns_node_list->max_occupied) {
82 acpi_gbl_ns_node_list->max_occupied = temp;
83 }
84#endif
85
74 node->name.integer = name; 86 node->name.integer = name;
75 ACPI_SET_DESCRIPTOR_TYPE(node, ACPI_DESC_TYPE_NAMED); 87 ACPI_SET_DESCRIPTOR_TYPE(node, ACPI_DESC_TYPE_NAMED);
76 return_PTR(node); 88 return_PTR(node);
diff --git a/drivers/acpi/namespace/nsdump.c b/drivers/acpi/namespace/nsdump.c
index d72df66aa9..1fc4f86676 100644
--- a/drivers/acpi/namespace/nsdump.c
+++ b/drivers/acpi/namespace/nsdump.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -205,7 +205,7 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
205 205
206 if (!acpi_ut_valid_acpi_name(this_node->name.integer)) { 206 if (!acpi_ut_valid_acpi_name(this_node->name.integer)) {
207 this_node->name.integer = 207 this_node->name.integer =
208 acpi_ut_repair_name(this_node->name.integer); 208 acpi_ut_repair_name(this_node->name.ascii);
209 209
210 ACPI_WARNING((AE_INFO, "Invalid ACPI Name %08X", 210 ACPI_WARNING((AE_INFO, "Invalid ACPI Name %08X",
211 this_node->name.integer)); 211 this_node->name.integer));
@@ -226,6 +226,12 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
226 obj_desc = acpi_ns_get_attached_object(this_node); 226 obj_desc = acpi_ns_get_attached_object(this_node);
227 acpi_dbg_level = dbg_level; 227 acpi_dbg_level = dbg_level;
228 228
229 /* Temp nodes are those nodes created by a control method */
230
231 if (this_node->flags & ANOBJ_TEMPORARY) {
232 acpi_os_printf("(T) ");
233 }
234
229 switch (info->display_type & ACPI_DISPLAY_MASK) { 235 switch (info->display_type & ACPI_DISPLAY_MASK) {
230 case ACPI_DISPLAY_SUMMARY: 236 case ACPI_DISPLAY_SUMMARY:
231 237
@@ -623,7 +629,8 @@ acpi_ns_dump_objects(acpi_object_type type,
623 info.display_type = display_type; 629 info.display_type = display_type;
624 630
625 (void)acpi_ns_walk_namespace(type, start_handle, max_depth, 631 (void)acpi_ns_walk_namespace(type, start_handle, max_depth,
626 ACPI_NS_WALK_NO_UNLOCK, 632 ACPI_NS_WALK_NO_UNLOCK |
633 ACPI_NS_WALK_TEMP_NODES,
627 acpi_ns_dump_one_object, (void *)&info, 634 acpi_ns_dump_one_object, (void *)&info,
628 NULL); 635 NULL);
629} 636}
diff --git a/drivers/acpi/namespace/nsdumpdv.c b/drivers/acpi/namespace/nsdumpdv.c
index c6bf5d30fc..5097e16793 100644
--- a/drivers/acpi/namespace/nsdumpdv.c
+++ b/drivers/acpi/namespace/nsdumpdv.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nseval.c b/drivers/acpi/namespace/nseval.c
index 4b0a4a8c98..aa6370c67e 100644
--- a/drivers/acpi/namespace/nseval.c
+++ b/drivers/acpi/namespace/nseval.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -154,11 +154,7 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info)
154 * Execute the method via the interpreter. The interpreter is locked 154 * Execute the method via the interpreter. The interpreter is locked
155 * here before calling into the AML parser 155 * here before calling into the AML parser
156 */ 156 */
157 status = acpi_ex_enter_interpreter(); 157 acpi_ex_enter_interpreter();
158 if (ACPI_FAILURE(status)) {
159 return_ACPI_STATUS(status);
160 }
161
162 status = acpi_ps_execute_method(info); 158 status = acpi_ps_execute_method(info);
163 acpi_ex_exit_interpreter(); 159 acpi_ex_exit_interpreter();
164 } else { 160 } else {
@@ -182,10 +178,7 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info)
182 * resolution, we must lock it because we could access an opregion. 178 * resolution, we must lock it because we could access an opregion.
183 * The opregion access code assumes that the interpreter is locked. 179 * The opregion access code assumes that the interpreter is locked.
184 */ 180 */
185 status = acpi_ex_enter_interpreter(); 181 acpi_ex_enter_interpreter();
186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status);
188 }
189 182
190 /* Function has a strange interface */ 183 /* Function has a strange interface */
191 184
diff --git a/drivers/acpi/namespace/nsinit.c b/drivers/acpi/namespace/nsinit.c
index aec8488c00..326af8fc0c 100644
--- a/drivers/acpi/namespace/nsinit.c
+++ b/drivers/acpi/namespace/nsinit.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -213,7 +213,7 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
213 u32 level, void *context, void **return_value) 213 u32 level, void *context, void **return_value)
214{ 214{
215 acpi_object_type type; 215 acpi_object_type type;
216 acpi_status status; 216 acpi_status status = AE_OK;
217 struct acpi_init_walk_info *info = 217 struct acpi_init_walk_info *info =
218 (struct acpi_init_walk_info *)context; 218 (struct acpi_init_walk_info *)context;
219 struct acpi_namespace_node *node = 219 struct acpi_namespace_node *node =
@@ -267,10 +267,7 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
267 /* 267 /*
268 * Must lock the interpreter before executing AML code 268 * Must lock the interpreter before executing AML code
269 */ 269 */
270 status = acpi_ex_enter_interpreter(); 270 acpi_ex_enter_interpreter();
271 if (ACPI_FAILURE(status)) {
272 return (status);
273 }
274 271
275 /* 272 /*
276 * Each of these types can contain executable AML code within the 273 * Each of these types can contain executable AML code within the
diff --git a/drivers/acpi/namespace/nsload.c b/drivers/acpi/namespace/nsload.c
index fe75d888e1..d4f9654fd2 100644
--- a/drivers/acpi/namespace/nsload.c
+++ b/drivers/acpi/namespace/nsload.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -44,13 +44,12 @@
44#include <acpi/acpi.h> 44#include <acpi/acpi.h>
45#include <acpi/acnamesp.h> 45#include <acpi/acnamesp.h>
46#include <acpi/acdispat.h> 46#include <acpi/acdispat.h>
47#include <acpi/actables.h>
47 48
48#define _COMPONENT ACPI_NAMESPACE 49#define _COMPONENT ACPI_NAMESPACE
49ACPI_MODULE_NAME("nsload") 50ACPI_MODULE_NAME("nsload")
50 51
51/* Local prototypes */ 52/* Local prototypes */
52static acpi_status acpi_ns_load_table_by_type(acpi_table_type table_type);
53
54#ifdef ACPI_FUTURE_IMPLEMENTATION 53#ifdef ACPI_FUTURE_IMPLEMENTATION
55acpi_status acpi_ns_unload_namespace(acpi_handle handle); 54acpi_status acpi_ns_unload_namespace(acpi_handle handle);
56 55
@@ -62,7 +61,7 @@ static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
62 * 61 *
63 * FUNCTION: acpi_ns_load_table 62 * FUNCTION: acpi_ns_load_table
64 * 63 *
65 * PARAMETERS: table_desc - Descriptor for table to be loaded 64 * PARAMETERS: table_index - Index for table to be loaded
66 * Node - Owning NS node 65 * Node - Owning NS node
67 * 66 *
68 * RETURN: Status 67 * RETURN: Status
@@ -72,42 +71,13 @@ static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
72 ******************************************************************************/ 71 ******************************************************************************/
73 72
74acpi_status 73acpi_status
75acpi_ns_load_table(struct acpi_table_desc *table_desc, 74acpi_ns_load_table(acpi_native_uint table_index,
76 struct acpi_namespace_node *node) 75 struct acpi_namespace_node *node)
77{ 76{
78 acpi_status status; 77 acpi_status status;
79 78
80 ACPI_FUNCTION_TRACE(ns_load_table); 79 ACPI_FUNCTION_TRACE(ns_load_table);
81 80
82 /* Check if table contains valid AML (must be DSDT, PSDT, SSDT, etc.) */
83
84 if (!
85 (acpi_gbl_table_data[table_desc->type].
86 flags & ACPI_TABLE_EXECUTABLE)) {
87
88 /* Just ignore this table */
89
90 return_ACPI_STATUS(AE_OK);
91 }
92
93 /* Check validity of the AML start and length */
94
95 if (!table_desc->aml_start) {
96 ACPI_ERROR((AE_INFO, "Null AML pointer"));
97 return_ACPI_STATUS(AE_BAD_PARAMETER);
98 }
99
100 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AML block at %p\n",
101 table_desc->aml_start));
102
103 /* Ignore table if there is no AML contained within */
104
105 if (!table_desc->aml_length) {
106 ACPI_WARNING((AE_INFO, "Zero-length AML block in table [%4.4s]",
107 table_desc->pointer->signature));
108 return_ACPI_STATUS(AE_OK);
109 }
110
111 /* 81 /*
112 * Parse the table and load the namespace with all named 82 * Parse the table and load the namespace with all named
113 * objects found within. Control methods are NOT parsed 83 * objects found within. Control methods are NOT parsed
@@ -117,15 +87,34 @@ acpi_ns_load_table(struct acpi_table_desc *table_desc,
117 * to another control method, we can't continue parsing 87 * to another control method, we can't continue parsing
118 * because we don't know how many arguments to parse next! 88 * because we don't know how many arguments to parse next!
119 */ 89 */
90 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
91 if (ACPI_FAILURE(status)) {
92 return_ACPI_STATUS(status);
93 }
94
95 /* If table already loaded into namespace, just return */
96
97 if (acpi_tb_is_table_loaded(table_index)) {
98 status = AE_ALREADY_EXISTS;
99 goto unlock;
100 }
101
120 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 102 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
121 "**** Loading table into namespace ****\n")); 103 "**** Loading table into namespace ****\n"));
122 104
123 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 105 status = acpi_tb_allocate_owner_id(table_index);
124 if (ACPI_FAILURE(status)) { 106 if (ACPI_FAILURE(status)) {
125 return_ACPI_STATUS(status); 107 goto unlock;
108 }
109
110 status = acpi_ns_parse_table(table_index, node->child);
111 if (ACPI_SUCCESS(status)) {
112 acpi_tb_set_table_loaded_flag(table_index, TRUE);
113 } else {
114 acpi_tb_release_owner_id(table_index);
126 } 115 }
127 116
128 status = acpi_ns_parse_table(table_desc, node->child); 117 unlock:
129 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 118 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
130 119
131 if (ACPI_FAILURE(status)) { 120 if (ACPI_FAILURE(status)) {
@@ -141,7 +130,7 @@ acpi_ns_load_table(struct acpi_table_desc *table_desc,
141 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 130 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
142 "**** Begin Table Method Parsing and Object Initialization ****\n")); 131 "**** Begin Table Method Parsing and Object Initialization ****\n"));
143 132
144 status = acpi_ds_initialize_objects(table_desc, node); 133 status = acpi_ds_initialize_objects(table_index, node);
145 134
146 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 135 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
147 "**** Completed Table Method Parsing and Object Initialization ****\n")); 136 "**** Completed Table Method Parsing and Object Initialization ****\n"));
@@ -149,99 +138,7 @@ acpi_ns_load_table(struct acpi_table_desc *table_desc,
149 return_ACPI_STATUS(status); 138 return_ACPI_STATUS(status);
150} 139}
151 140
152/******************************************************************************* 141#ifdef ACPI_OBSOLETE_FUNCTIONS
153 *
154 * FUNCTION: acpi_ns_load_table_by_type
155 *
156 * PARAMETERS: table_type - Id of the table type to load
157 *
158 * RETURN: Status
159 *
160 * DESCRIPTION: Load an ACPI table or tables into the namespace. All tables
161 * of the given type are loaded. The mechanism allows this
162 * routine to be called repeatedly.
163 *
164 ******************************************************************************/
165
166static acpi_status acpi_ns_load_table_by_type(acpi_table_type table_type)
167{
168 u32 i;
169 acpi_status status;
170 struct acpi_table_desc *table_desc;
171
172 ACPI_FUNCTION_TRACE(ns_load_table_by_type);
173
174 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
175 if (ACPI_FAILURE(status)) {
176 return_ACPI_STATUS(status);
177 }
178
179 /*
180 * Table types supported are:
181 * DSDT (one), SSDT/PSDT (multiple)
182 */
183 switch (table_type) {
184 case ACPI_TABLE_ID_DSDT:
185
186 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace load: DSDT\n"));
187
188 table_desc = acpi_gbl_table_lists[ACPI_TABLE_ID_DSDT].next;
189
190 /* If table already loaded into namespace, just return */
191
192 if (table_desc->loaded_into_namespace) {
193 goto unlock_and_exit;
194 }
195
196 /* Now load the single DSDT */
197
198 status = acpi_ns_load_table(table_desc, acpi_gbl_root_node);
199 if (ACPI_SUCCESS(status)) {
200 table_desc->loaded_into_namespace = TRUE;
201 }
202 break;
203
204 case ACPI_TABLE_ID_SSDT:
205 case ACPI_TABLE_ID_PSDT:
206
207 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
208 "Namespace load: %d SSDT or PSDTs\n",
209 acpi_gbl_table_lists[table_type].count));
210
211 /*
212 * Traverse list of SSDT or PSDT tables
213 */
214 table_desc = acpi_gbl_table_lists[table_type].next;
215 for (i = 0; i < acpi_gbl_table_lists[table_type].count; i++) {
216 /*
217 * Only attempt to load table into namespace if it is not
218 * already loaded!
219 */
220 if (!table_desc->loaded_into_namespace) {
221 status =
222 acpi_ns_load_table(table_desc,
223 acpi_gbl_root_node);
224 if (ACPI_FAILURE(status)) {
225 break;
226 }
227
228 table_desc->loaded_into_namespace = TRUE;
229 }
230
231 table_desc = table_desc->next;
232 }
233 break;
234
235 default:
236 status = AE_SUPPORT;
237 break;
238 }
239
240 unlock_and_exit:
241 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
242 return_ACPI_STATUS(status);
243}
244
245/******************************************************************************* 142/*******************************************************************************
246 * 143 *
247 * FUNCTION: acpi_load_namespace 144 * FUNCTION: acpi_load_namespace
@@ -288,6 +185,7 @@ acpi_status acpi_ns_load_namespace(void)
288 185
289 return_ACPI_STATUS(status); 186 return_ACPI_STATUS(status);
290} 187}
188#endif
291 189
292#ifdef ACPI_FUTURE_IMPLEMENTATION 190#ifdef ACPI_FUTURE_IMPLEMENTATION
293/******************************************************************************* 191/*******************************************************************************
diff --git a/drivers/acpi/namespace/nsnames.c b/drivers/acpi/namespace/nsnames.c
index 97b8332c97..cbd94af08c 100644
--- a/drivers/acpi/namespace/nsnames.c
+++ b/drivers/acpi/namespace/nsnames.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nsobject.c b/drivers/acpi/namespace/nsobject.c
index aabe8794b9..d9d7377bc6 100644
--- a/drivers/acpi/namespace/nsobject.c
+++ b/drivers/acpi/namespace/nsobject.c
@@ -6,7 +6,7 @@
6 ******************************************************************************/ 6 ******************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nsparse.c b/drivers/acpi/namespace/nsparse.c
index 155505a4ef..e696aa8479 100644
--- a/drivers/acpi/namespace/nsparse.c
+++ b/drivers/acpi/namespace/nsparse.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,7 @@
45#include <acpi/acnamesp.h> 45#include <acpi/acnamesp.h>
46#include <acpi/acparser.h> 46#include <acpi/acparser.h>
47#include <acpi/acdispat.h> 47#include <acpi/acdispat.h>
48#include <acpi/actables.h>
48 49
49#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
50ACPI_MODULE_NAME("nsparse") 51ACPI_MODULE_NAME("nsparse")
@@ -62,14 +63,24 @@ ACPI_MODULE_NAME("nsparse")
62 * 63 *
63 ******************************************************************************/ 64 ******************************************************************************/
64acpi_status 65acpi_status
65acpi_ns_one_complete_parse(u8 pass_number, struct acpi_table_desc *table_desc) 66acpi_ns_one_complete_parse(acpi_native_uint pass_number,
67 acpi_native_uint table_index)
66{ 68{
67 union acpi_parse_object *parse_root; 69 union acpi_parse_object *parse_root;
68 acpi_status status; 70 acpi_status status;
71 acpi_native_uint aml_length;
72 u8 *aml_start;
69 struct acpi_walk_state *walk_state; 73 struct acpi_walk_state *walk_state;
74 struct acpi_table_header *table;
75 acpi_owner_id owner_id;
70 76
71 ACPI_FUNCTION_TRACE(ns_one_complete_parse); 77 ACPI_FUNCTION_TRACE(ns_one_complete_parse);
72 78
79 status = acpi_tb_get_owner_id(table_index, &owner_id);
80 if (ACPI_FAILURE(status)) {
81 return_ACPI_STATUS(status);
82 }
83
73 /* Create and init a Root Node */ 84 /* Create and init a Root Node */
74 85
75 parse_root = acpi_ps_create_scope_op(); 86 parse_root = acpi_ps_create_scope_op();
@@ -79,26 +90,41 @@ acpi_ns_one_complete_parse(u8 pass_number, struct acpi_table_desc *table_desc)
79 90
80 /* Create and initialize a new walk state */ 91 /* Create and initialize a new walk state */
81 92
82 walk_state = acpi_ds_create_walk_state(table_desc->owner_id, 93 walk_state = acpi_ds_create_walk_state(owner_id, NULL, NULL, NULL);
83 NULL, NULL, NULL);
84 if (!walk_state) { 94 if (!walk_state) {
85 acpi_ps_free_op(parse_root); 95 acpi_ps_free_op(parse_root);
86 return_ACPI_STATUS(AE_NO_MEMORY); 96 return_ACPI_STATUS(AE_NO_MEMORY);
87 } 97 }
88 98
89 status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL, 99 status = acpi_get_table_by_index(table_index, &table);
90 table_desc->aml_start, 100 if (ACPI_FAILURE(status)) {
91 table_desc->aml_length, NULL, 101 acpi_ds_delete_walk_state(walk_state);
92 pass_number); 102 acpi_ps_free_op(parse_root);
103 return_ACPI_STATUS(status);
104 }
105
106 /* Table must consist of at least a complete header */
107
108 if (table->length < sizeof(struct acpi_table_header)) {
109 status = AE_BAD_HEADER;
110 } else {
111 aml_start = (u8 *) table + sizeof(struct acpi_table_header);
112 aml_length = table->length - sizeof(struct acpi_table_header);
113 status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL,
114 aml_start, aml_length, NULL,
115 (u8) pass_number);
116 }
117
93 if (ACPI_FAILURE(status)) { 118 if (ACPI_FAILURE(status)) {
94 acpi_ds_delete_walk_state(walk_state); 119 acpi_ds_delete_walk_state(walk_state);
120 acpi_ps_delete_parse_tree(parse_root);
95 return_ACPI_STATUS(status); 121 return_ACPI_STATUS(status);
96 } 122 }
97 123
98 /* Parse the AML */ 124 /* Parse the AML */
99 125
100 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "*PARSE* pass %d parse\n", 126 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "*PARSE* pass %d parse\n",
101 pass_number)); 127 (unsigned)pass_number));
102 status = acpi_ps_parse_aml(walk_state); 128 status = acpi_ps_parse_aml(walk_state);
103 129
104 acpi_ps_delete_parse_tree(parse_root); 130 acpi_ps_delete_parse_tree(parse_root);
@@ -119,7 +145,7 @@ acpi_ns_one_complete_parse(u8 pass_number, struct acpi_table_desc *table_desc)
119 ******************************************************************************/ 145 ******************************************************************************/
120 146
121acpi_status 147acpi_status
122acpi_ns_parse_table(struct acpi_table_desc *table_desc, 148acpi_ns_parse_table(acpi_native_uint table_index,
123 struct acpi_namespace_node *start_node) 149 struct acpi_namespace_node *start_node)
124{ 150{
125 acpi_status status; 151 acpi_status status;
@@ -134,10 +160,10 @@ acpi_ns_parse_table(struct acpi_table_desc *table_desc,
134 * each Parser Op subtree is deleted when it is finished. This saves 160 * each Parser Op subtree is deleted when it is finished. This saves
135 * a great deal of memory, and allows a small cache of parse objects 161 * a great deal of memory, and allows a small cache of parse objects
136 * to service the entire parse. The second pass of the parse then 162 * to service the entire parse. The second pass of the parse then
137 * performs another complete parse of the AML.. 163 * performs another complete parse of the AML.
138 */ 164 */
139 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n")); 165 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n"));
140 status = acpi_ns_one_complete_parse(1, table_desc); 166 status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS1, table_index);
141 if (ACPI_FAILURE(status)) { 167 if (ACPI_FAILURE(status)) {
142 return_ACPI_STATUS(status); 168 return_ACPI_STATUS(status);
143 } 169 }
@@ -152,7 +178,7 @@ acpi_ns_parse_table(struct acpi_table_desc *table_desc,
152 * parse objects are all cached. 178 * parse objects are all cached.
153 */ 179 */
154 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n")); 180 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n"));
155 status = acpi_ns_one_complete_parse(2, table_desc); 181 status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS2, table_index);
156 if (ACPI_FAILURE(status)) { 182 if (ACPI_FAILURE(status)) {
157 return_ACPI_STATUS(status); 183 return_ACPI_STATUS(status);
158 } 184 }
diff --git a/drivers/acpi/namespace/nssearch.c b/drivers/acpi/namespace/nssearch.c
index 500e2bbcfa..e863be665c 100644
--- a/drivers/acpi/namespace/nssearch.c
+++ b/drivers/acpi/namespace/nssearch.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -321,7 +321,8 @@ acpi_ns_search_and_enter(u32 target_name,
321 * even though there are a few bad names. 321 * even though there are a few bad names.
322 */ 322 */
323 if (!acpi_ut_valid_acpi_name(target_name)) { 323 if (!acpi_ut_valid_acpi_name(target_name)) {
324 target_name = acpi_ut_repair_name(target_name); 324 target_name =
325 acpi_ut_repair_name(ACPI_CAST_PTR(char, &target_name));
325 326
326 /* Report warning only if in strict mode or debug mode */ 327 /* Report warning only if in strict mode or debug mode */
327 328
@@ -401,6 +402,10 @@ acpi_ns_search_and_enter(u32 target_name,
401 } 402 }
402#endif 403#endif
403 404
405 if (flags & ACPI_NS_TEMPORARY) {
406 new_node->flags |= ANOBJ_TEMPORARY;
407 }
408
404 /* Install the new object into the parent's list of children */ 409 /* Install the new object into the parent's list of children */
405 410
406 acpi_ns_install_node(walk_state, node, new_node, type); 411 acpi_ns_install_node(walk_state, node, new_node, type);
diff --git a/drivers/acpi/namespace/nsutils.c b/drivers/acpi/namespace/nsutils.c
index aa4e799d9a..90fd059615 100644
--- a/drivers/acpi/namespace/nsutils.c
+++ b/drivers/acpi/namespace/nsutils.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -770,13 +770,6 @@ void acpi_ns_terminate(void)
770 } 770 }
771 771
772 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace freed\n")); 772 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace freed\n"));
773
774 /*
775 * 2) Now we can delete the ACPI tables
776 */
777 acpi_tb_delete_all_tables();
778 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
779
780 return_VOID; 773 return_VOID;
781} 774}
782 775
diff --git a/drivers/acpi/namespace/nswalk.c b/drivers/acpi/namespace/nswalk.c
index c8f6bef16e..94eb8f332d 100644
--- a/drivers/acpi/namespace/nswalk.c
+++ b/drivers/acpi/namespace/nswalk.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -126,7 +126,7 @@ struct acpi_namespace_node *acpi_ns_get_next_node(acpi_object_type type,
126 * PARAMETERS: Type - acpi_object_type to search for 126 * PARAMETERS: Type - acpi_object_type to search for
127 * start_node - Handle in namespace where search begins 127 * start_node - Handle in namespace where search begins
128 * max_depth - Depth to which search is to reach 128 * max_depth - Depth to which search is to reach
129 * unlock_before_callback- Whether to unlock the NS before invoking 129 * Flags - Whether to unlock the NS before invoking
130 * the callback routine 130 * the callback routine
131 * user_function - Called when an object of "Type" is found 131 * user_function - Called when an object of "Type" is found
132 * Context - Passed to user function 132 * Context - Passed to user function
@@ -153,7 +153,7 @@ acpi_status
153acpi_ns_walk_namespace(acpi_object_type type, 153acpi_ns_walk_namespace(acpi_object_type type,
154 acpi_handle start_node, 154 acpi_handle start_node,
155 u32 max_depth, 155 u32 max_depth,
156 u8 unlock_before_callback, 156 u32 flags,
157 acpi_walk_callback user_function, 157 acpi_walk_callback user_function,
158 void *context, void **return_value) 158 void *context, void **return_value)
159{ 159{
@@ -193,20 +193,34 @@ acpi_ns_walk_namespace(acpi_object_type type,
193 acpi_ns_get_next_node(ACPI_TYPE_ANY, parent_node, 193 acpi_ns_get_next_node(ACPI_TYPE_ANY, parent_node,
194 child_node); 194 child_node);
195 if (child_node) { 195 if (child_node) {
196 /* 196
197 * Found node, Get the type if we are not 197 /* Found next child, get the type if we are not searching for ANY */
198 * searching for ANY 198
199 */
200 if (type != ACPI_TYPE_ANY) { 199 if (type != ACPI_TYPE_ANY) {
201 child_type = child_node->type; 200 child_type = child_node->type;
202 } 201 }
203 202
204 if (child_type == type) { 203 /*
204 * Ignore all temporary namespace nodes (created during control
205 * method execution) unless told otherwise. These temporary nodes
206 * can cause a race condition because they can be deleted during the
207 * execution of the user function (if the namespace is unlocked before
208 * invocation of the user function.) Only the debugger namespace dump
209 * will examine the temporary nodes.
210 */
211 if ((child_node->flags & ANOBJ_TEMPORARY) &&
212 !(flags & ACPI_NS_WALK_TEMP_NODES)) {
213 status = AE_CTRL_DEPTH;
214 }
215
216 /* Type must match requested type */
217
218 else if (child_type == type) {
205 /* 219 /*
206 * Found a matching node, invoke the user 220 * Found a matching node, invoke the user callback function.
207 * callback function 221 * Unlock the namespace if flag is set.
208 */ 222 */
209 if (unlock_before_callback) { 223 if (flags & ACPI_NS_WALK_UNLOCK) {
210 mutex_status = 224 mutex_status =
211 acpi_ut_release_mutex 225 acpi_ut_release_mutex
212 (ACPI_MTX_NAMESPACE); 226 (ACPI_MTX_NAMESPACE);
@@ -216,10 +230,11 @@ acpi_ns_walk_namespace(acpi_object_type type,
216 } 230 }
217 } 231 }
218 232
219 status = user_function(child_node, level, 233 status =
220 context, return_value); 234 user_function(child_node, level, context,
235 return_value);
221 236
222 if (unlock_before_callback) { 237 if (flags & ACPI_NS_WALK_UNLOCK) {
223 mutex_status = 238 mutex_status =
224 acpi_ut_acquire_mutex 239 acpi_ut_acquire_mutex
225 (ACPI_MTX_NAMESPACE); 240 (ACPI_MTX_NAMESPACE);
@@ -251,20 +266,17 @@ acpi_ns_walk_namespace(acpi_object_type type,
251 } 266 }
252 267
253 /* 268 /*
254 * Depth first search: 269 * Depth first search: Attempt to go down another level in the
255 * Attempt to go down another level in the namespace 270 * namespace if we are allowed to. Don't go any further if we have
256 * if we are allowed to. Don't go any further if we 271 * reached the caller specified maximum depth or if the user
257 * have reached the caller specified maximum depth 272 * function has specified that the maximum depth has been reached.
258 * or if the user function has specified that the
259 * maximum depth has been reached.
260 */ 273 */
261 if ((level < max_depth) && (status != AE_CTRL_DEPTH)) { 274 if ((level < max_depth) && (status != AE_CTRL_DEPTH)) {
262 if (acpi_ns_get_next_node 275 if (acpi_ns_get_next_node
263 (ACPI_TYPE_ANY, child_node, NULL)) { 276 (ACPI_TYPE_ANY, child_node, NULL)) {
264 /* 277
265 * There is at least one child of this 278 /* There is at least one child of this node, visit it */
266 * node, visit the onde 279
267 */
268 level++; 280 level++;
269 parent_node = child_node; 281 parent_node = child_node;
270 child_node = NULL; 282 child_node = NULL;
@@ -272,9 +284,8 @@ acpi_ns_walk_namespace(acpi_object_type type,
272 } 284 }
273 } else { 285 } else {
274 /* 286 /*
275 * No more children of this node (acpi_ns_get_next_node 287 * No more children of this node (acpi_ns_get_next_node failed), go
276 * failed), go back upwards in the namespace tree to 288 * back upwards in the namespace tree to the node's parent.
277 * the node's parent.
278 */ 289 */
279 level--; 290 level--;
280 child_node = parent_node; 291 child_node = parent_node;
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
index dca6799ac6..7ac6ace500 100644
--- a/drivers/acpi/namespace/nsxfeval.c
+++ b/drivers/acpi/namespace/nsxfeval.c
@@ -6,7 +6,7 @@
6 ******************************************************************************/ 6 ******************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -170,7 +170,6 @@ acpi_evaluate_object(acpi_handle handle,
170 struct acpi_buffer *return_buffer) 170 struct acpi_buffer *return_buffer)
171{ 171{
172 acpi_status status; 172 acpi_status status;
173 acpi_status status2;
174 struct acpi_evaluate_info *info; 173 struct acpi_evaluate_info *info;
175 acpi_size buffer_space_needed; 174 acpi_size buffer_space_needed;
176 u32 i; 175 u32 i;
@@ -329,14 +328,12 @@ acpi_evaluate_object(acpi_handle handle,
329 * Delete the internal return object. NOTE: Interpreter must be 328 * Delete the internal return object. NOTE: Interpreter must be
330 * locked to avoid race condition. 329 * locked to avoid race condition.
331 */ 330 */
332 status2 = acpi_ex_enter_interpreter(); 331 acpi_ex_enter_interpreter();
333 if (ACPI_SUCCESS(status2)) {
334 332
335 /* Remove one reference on the return object (should delete it) */ 333 /* Remove one reference on the return object (should delete it) */
336 334
337 acpi_ut_remove_reference(info->return_object); 335 acpi_ut_remove_reference(info->return_object);
338 acpi_ex_exit_interpreter(); 336 acpi_ex_exit_interpreter();
339 }
340 } 337 }
341 338
342 cleanup: 339 cleanup:
diff --git a/drivers/acpi/namespace/nsxfname.c b/drivers/acpi/namespace/nsxfname.c
index 978213a6c1..b489781b22 100644
--- a/drivers/acpi/namespace/nsxfname.c
+++ b/drivers/acpi/namespace/nsxfname.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -84,38 +84,41 @@ acpi_get_handle(acpi_handle parent,
84 /* Convert a parent handle to a prefix node */ 84 /* Convert a parent handle to a prefix node */
85 85
86 if (parent) { 86 if (parent) {
87 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
88 if (ACPI_FAILURE(status)) {
89 return (status);
90 }
91
92 prefix_node = acpi_ns_map_handle_to_node(parent); 87 prefix_node = acpi_ns_map_handle_to_node(parent);
93 if (!prefix_node) { 88 if (!prefix_node) {
94 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
95 return (AE_BAD_PARAMETER); 89 return (AE_BAD_PARAMETER);
96 } 90 }
91 }
92
93 /*
94 * Valid cases are:
95 * 1) Fully qualified pathname
96 * 2) Parent + Relative pathname
97 *
98 * Error for <null Parent + relative path>
99 */
100 if (acpi_ns_valid_root_prefix(pathname[0])) {
97 101
98 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 102 /* Pathname is fully qualified (starts with '\') */
99 if (ACPI_FAILURE(status)) { 103
100 return (status); 104 /* Special case for root-only, since we can't search for it */
105
106 if (!ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH)) {
107 *ret_handle =
108 acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
109 return (AE_OK);
101 } 110 }
102 } 111 } else if (!prefix_node) {
103 112
104 /* Special case for root, since we can't search for it */ 113 /* Relative path with null prefix is disallowed */
105 114
106 if (ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH) == 0) { 115 return (AE_BAD_PARAMETER);
107 *ret_handle =
108 acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
109 return (AE_OK);
110 } 116 }
111 117
112 /* 118 /* Find the Node and convert to a handle */
113 * Find the Node and convert to a handle
114 */
115 status = acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH,
116 &node);
117 119
118 *ret_handle = NULL; 120 status =
121 acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH, &node);
119 if (ACPI_SUCCESS(status)) { 122 if (ACPI_SUCCESS(status)) {
120 *ret_handle = acpi_ns_convert_entry_to_handle(node); 123 *ret_handle = acpi_ns_convert_entry_to_handle(node);
121 } 124 }
diff --git a/drivers/acpi/namespace/nsxfobj.c b/drivers/acpi/namespace/nsxfobj.c
index a163e1d370..faa3758872 100644
--- a/drivers/acpi/namespace/nsxfobj.c
+++ b/drivers/acpi/namespace/nsxfobj.c
@@ -6,7 +6,7 @@
6 ******************************************************************************/ 6 ******************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,50 @@ ACPI_MODULE_NAME("nsxfobj")
50 50
51/******************************************************************************* 51/*******************************************************************************
52 * 52 *
53 * FUNCTION: acpi_get_id
54 *
55 * PARAMETERS: Handle - Handle of object whose id is desired
56 * ret_id - Where the id will be placed
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: This routine returns the owner id associated with a handle
61 *
62 ******************************************************************************/
63acpi_status acpi_get_id(acpi_handle handle, acpi_owner_id * ret_id)
64{
65 struct acpi_namespace_node *node;
66 acpi_status status;
67
68 /* Parameter Validation */
69
70 if (!ret_id) {
71 return (AE_BAD_PARAMETER);
72 }
73
74 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
75 if (ACPI_FAILURE(status)) {
76 return (status);
77 }
78
79 /* Convert and validate the handle */
80
81 node = acpi_ns_map_handle_to_node(handle);
82 if (!node) {
83 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
84 return (AE_BAD_PARAMETER);
85 }
86
87 *ret_id = node->owner_id;
88
89 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
90 return (status);
91}
92
93ACPI_EXPORT_SYMBOL(acpi_get_id)
94
95/*******************************************************************************
96 *
53 * FUNCTION: acpi_get_type 97 * FUNCTION: acpi_get_type
54 * 98 *
55 * PARAMETERS: Handle - Handle of object whose type is desired 99 * PARAMETERS: Handle - Handle of object whose type is desired
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index e5e448edca..4a9faff4c0 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -45,7 +45,7 @@ int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS]
45int __cpuinitdata node_to_pxm_map[MAX_NUMNODES] 45int __cpuinitdata node_to_pxm_map[MAX_NUMNODES]
46 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL }; 46 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
47 47
48extern int __init acpi_table_parse_madt_family(enum acpi_table_id id, 48extern int __init acpi_table_parse_madt_family(char *id,
49 unsigned long madt_size, 49 unsigned long madt_size,
50 int entry_id, 50 int entry_id,
51 acpi_madt_entry_handler handler, 51 acpi_madt_entry_handler handler,
@@ -89,7 +89,7 @@ void __cpuinit acpi_unmap_pxm_to_node(int node)
89 node_clear(node, nodes_found_map); 89 node_clear(node, nodes_found_map);
90} 90}
91 91
92void __init acpi_table_print_srat_entry(acpi_table_entry_header * header) 92void __init acpi_table_print_srat_entry(struct acpi_subtable_header * header)
93{ 93{
94 94
95 ACPI_FUNCTION_NAME("acpi_table_print_srat_entry"); 95 ACPI_FUNCTION_NAME("acpi_table_print_srat_entry");
@@ -99,36 +99,35 @@ void __init acpi_table_print_srat_entry(acpi_table_entry_header * header)
99 99
100 switch (header->type) { 100 switch (header->type) {
101 101
102 case ACPI_SRAT_PROCESSOR_AFFINITY: 102 case ACPI_SRAT_TYPE_CPU_AFFINITY:
103#ifdef ACPI_DEBUG_OUTPUT 103#ifdef ACPI_DEBUG_OUTPUT
104 { 104 {
105 struct acpi_table_processor_affinity *p = 105 struct acpi_srat_cpu_affinity *p =
106 (struct acpi_table_processor_affinity *)header; 106 (struct acpi_srat_cpu_affinity *)header;
107 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 107 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
108 "SRAT Processor (id[0x%02x] eid[0x%02x]) in proximity domain %d %s\n", 108 "SRAT Processor (id[0x%02x] eid[0x%02x]) in proximity domain %d %s\n",
109 p->apic_id, p->lsapic_eid, 109 p->apic_id, p->local_sapic_eid,
110 p->proximity_domain, 110 p->proximity_domain_lo,
111 p->flags. 111 (p->flags & ACPI_SRAT_CPU_ENABLED)?
112 enabled ? "enabled" : "disabled")); 112 "enabled" : "disabled"));
113 } 113 }
114#endif /* ACPI_DEBUG_OUTPUT */ 114#endif /* ACPI_DEBUG_OUTPUT */
115 break; 115 break;
116 116
117 case ACPI_SRAT_MEMORY_AFFINITY: 117 case ACPI_SRAT_TYPE_MEMORY_AFFINITY:
118#ifdef ACPI_DEBUG_OUTPUT 118#ifdef ACPI_DEBUG_OUTPUT
119 { 119 {
120 struct acpi_table_memory_affinity *p = 120 struct acpi_srat_mem_affinity *p =
121 (struct acpi_table_memory_affinity *)header; 121 (struct acpi_srat_mem_affinity *)header;
122 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 122 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
123 "SRAT Memory (0x%08x%08x length 0x%08x%08x type 0x%x) in proximity domain %d %s%s\n", 123 "SRAT Memory (0x%lx length 0x%lx type 0x%x) in proximity domain %d %s%s\n",
124 p->base_addr_hi, p->base_addr_lo, 124 (unsigned long)p->base_address,
125 p->length_hi, p->length_lo, 125 (unsigned long)p->length,
126 p->memory_type, p->proximity_domain, 126 p->memory_type, p->proximity_domain,
127 p->flags. 127 (p->flags & ACPI_SRAT_MEM_ENABLED)?
128 enabled ? "enabled" : "disabled", 128 "enabled" : "disabled",
129 p->flags. 129 (p->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)?
130 hot_pluggable ? " hot-pluggable" : 130 " hot-pluggable" : ""));
131 ""));
132 } 131 }
133#endif /* ACPI_DEBUG_OUTPUT */ 132#endif /* ACPI_DEBUG_OUTPUT */
134 break; 133 break;
@@ -141,18 +140,18 @@ void __init acpi_table_print_srat_entry(acpi_table_entry_header * header)
141 } 140 }
142} 141}
143 142
144static int __init acpi_parse_slit(unsigned long phys_addr, unsigned long size) 143static int __init acpi_parse_slit(struct acpi_table_header *table)
145{ 144{
146 struct acpi_table_slit *slit; 145 struct acpi_table_slit *slit;
147 u32 localities; 146 u32 localities;
148 147
149 if (!phys_addr || !size) 148 if (!table)
150 return -EINVAL; 149 return -EINVAL;
151 150
152 slit = (struct acpi_table_slit *)__va(phys_addr); 151 slit = (struct acpi_table_slit *)table;
153 152
154 /* downcast just for %llu vs %lu for i386/ia64 */ 153 /* downcast just for %llu vs %lu for i386/ia64 */
155 localities = (u32) slit->localities; 154 localities = (u32) slit->locality_count;
156 155
157 acpi_numa_slit_init(slit); 156 acpi_numa_slit_init(slit);
158 157
@@ -160,12 +159,12 @@ static int __init acpi_parse_slit(unsigned long phys_addr, unsigned long size)
160} 159}
161 160
162static int __init 161static int __init
163acpi_parse_processor_affinity(acpi_table_entry_header * header, 162acpi_parse_processor_affinity(struct acpi_subtable_header * header,
164 const unsigned long end) 163 const unsigned long end)
165{ 164{
166 struct acpi_table_processor_affinity *processor_affinity; 165 struct acpi_srat_cpu_affinity *processor_affinity;
167 166
168 processor_affinity = (struct acpi_table_processor_affinity *)header; 167 processor_affinity = (struct acpi_srat_cpu_affinity *)header;
169 if (!processor_affinity) 168 if (!processor_affinity)
170 return -EINVAL; 169 return -EINVAL;
171 170
@@ -178,12 +177,12 @@ acpi_parse_processor_affinity(acpi_table_entry_header * header,
178} 177}
179 178
180static int __init 179static int __init
181acpi_parse_memory_affinity(acpi_table_entry_header * header, 180acpi_parse_memory_affinity(struct acpi_subtable_header * header,
182 const unsigned long end) 181 const unsigned long end)
183{ 182{
184 struct acpi_table_memory_affinity *memory_affinity; 183 struct acpi_srat_mem_affinity *memory_affinity;
185 184
186 memory_affinity = (struct acpi_table_memory_affinity *)header; 185 memory_affinity = (struct acpi_srat_mem_affinity *)header;
187 if (!memory_affinity) 186 if (!memory_affinity)
188 return -EINVAL; 187 return -EINVAL;
189 188
@@ -195,23 +194,23 @@ acpi_parse_memory_affinity(acpi_table_entry_header * header,
195 return 0; 194 return 0;
196} 195}
197 196
198static int __init acpi_parse_srat(unsigned long phys_addr, unsigned long size) 197static int __init acpi_parse_srat(struct acpi_table_header *table)
199{ 198{
200 struct acpi_table_srat *srat; 199 struct acpi_table_srat *srat;
201 200
202 if (!phys_addr || !size) 201 if (!table)
203 return -EINVAL; 202 return -EINVAL;
204 203
205 srat = (struct acpi_table_srat *)__va(phys_addr); 204 srat = (struct acpi_table_srat *)table;
206 205
207 return 0; 206 return 0;
208} 207}
209 208
210int __init 209int __init
211acpi_table_parse_srat(enum acpi_srat_entry_id id, 210acpi_table_parse_srat(enum acpi_srat_type id,
212 acpi_madt_entry_handler handler, unsigned int max_entries) 211 acpi_madt_entry_handler handler, unsigned int max_entries)
213{ 212{
214 return acpi_table_parse_madt_family(ACPI_SRAT, 213 return acpi_table_parse_madt_family(ACPI_SIG_SRAT,
215 sizeof(struct acpi_table_srat), id, 214 sizeof(struct acpi_table_srat), id,
216 handler, max_entries); 215 handler, max_entries);
217} 216}
@@ -221,17 +220,17 @@ int __init acpi_numa_init(void)
221 int result; 220 int result;
222 221
223 /* SRAT: Static Resource Affinity Table */ 222 /* SRAT: Static Resource Affinity Table */
224 result = acpi_table_parse(ACPI_SRAT, acpi_parse_srat); 223 result = acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat);
225 224
226 if (result > 0) { 225 if (result > 0) {
227 result = acpi_table_parse_srat(ACPI_SRAT_PROCESSOR_AFFINITY, 226 result = acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
228 acpi_parse_processor_affinity, 227 acpi_parse_processor_affinity,
229 NR_CPUS); 228 NR_CPUS);
230 result = acpi_table_parse_srat(ACPI_SRAT_MEMORY_AFFINITY, acpi_parse_memory_affinity, NR_NODE_MEMBLKS); // IA64 specific 229 result = acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY, acpi_parse_memory_affinity, NR_NODE_MEMBLKS); // IA64 specific
231 } 230 }
232 231
233 /* SLIT: System Locality Information Table */ 232 /* SLIT: System Locality Information Table */
234 result = acpi_table_parse(ACPI_SLIT, acpi_parse_slit); 233 result = acpi_table_parse(ACPI_SIG_SLIT, acpi_parse_slit);
235 234
236 acpi_numa_arch_fixup(); 235 acpi_numa_arch_fixup();
237 return 0; 236 return 0;
@@ -248,7 +247,7 @@ int acpi_get_pxm(acpi_handle h)
248 handle = phandle; 247 handle = phandle;
249 status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm); 248 status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);
250 if (ACPI_SUCCESS(status)) 249 if (ACPI_SUCCESS(status))
251 return (int)pxm; 250 return pxm;
252 status = acpi_get_parent(handle, &phandle); 251 status = acpi_get_parent(handle, &phandle);
253 } while (ACPI_SUCCESS(status)); 252 } while (ACPI_SUCCESS(status));
254 return -1; 253 return -1;
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 02b30ae6a6..a28f5b8972 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -36,6 +36,7 @@
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <linux/workqueue.h> 37#include <linux/workqueue.h>
38#include <linux/nmi.h> 38#include <linux/nmi.h>
39#include <linux/acpi.h>
39#include <acpi/acpi.h> 40#include <acpi/acpi.h>
40#include <asm/io.h> 41#include <asm/io.h>
41#include <acpi/acpi_bus.h> 42#include <acpi/acpi_bus.h>
@@ -136,53 +137,43 @@ void acpi_os_vprintf(const char *fmt, va_list args)
136#endif 137#endif
137} 138}
138 139
139acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr) 140acpi_physical_address __init acpi_os_get_root_pointer(void)
140{ 141{
141 if (efi_enabled) { 142 if (efi_enabled) {
142 addr->pointer_type = ACPI_PHYSICAL_POINTER;
143 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR) 143 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
144 addr->pointer.physical = efi.acpi20; 144 return efi.acpi20;
145 else if (efi.acpi != EFI_INVALID_TABLE_ADDR) 145 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
146 addr->pointer.physical = efi.acpi; 146 return efi.acpi;
147 else { 147 else {
148 printk(KERN_ERR PREFIX 148 printk(KERN_ERR PREFIX
149 "System description tables not found\n"); 149 "System description tables not found\n");
150 return AE_NOT_FOUND; 150 return 0;
151 } 151 }
152 } else { 152 } else
153 if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) { 153 return acpi_find_rsdp();
154 printk(KERN_ERR PREFIX
155 "System description tables not found\n");
156 return AE_NOT_FOUND;
157 }
158 }
159
160 return AE_OK;
161} 154}
162 155
163acpi_status 156void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
164acpi_os_map_memory(acpi_physical_address phys, acpi_size size,
165 void __iomem ** virt)
166{ 157{
167 if (phys > ULONG_MAX) { 158 if (phys > ULONG_MAX) {
168 printk(KERN_ERR PREFIX "Cannot map memory that high\n"); 159 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
169 return AE_BAD_PARAMETER; 160 return 0;
170 } 161 }
171 /* 162 if (acpi_gbl_permanent_mmap)
172 * ioremap checks to ensure this is in reserved space 163 /*
173 */ 164 * ioremap checks to ensure this is in reserved space
174 *virt = ioremap((unsigned long)phys, size); 165 */
175 166 return ioremap((unsigned long)phys, size);
176 if (!*virt) 167 else
177 return AE_NO_MEMORY; 168 return __acpi_map_table((unsigned long)phys, size);
178
179 return AE_OK;
180} 169}
181EXPORT_SYMBOL_GPL(acpi_os_map_memory); 170EXPORT_SYMBOL_GPL(acpi_os_map_memory);
182 171
183void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) 172void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
184{ 173{
185 iounmap(virt); 174 if (acpi_gbl_permanent_mmap) {
175 iounmap(virt);
176 }
186} 177}
187EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); 178EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
188 179
@@ -254,7 +245,7 @@ acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
254 * FADT. It may not be the same if an interrupt source override exists 245 * FADT. It may not be the same if an interrupt source override exists
255 * for the SCI. 246 * for the SCI.
256 */ 247 */
257 gsi = acpi_fadt.sci_int; 248 gsi = acpi_gbl_FADT.sci_interrupt;
258 if (acpi_gsi_to_irq(gsi, &irq) < 0) { 249 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
259 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n", 250 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
260 gsi); 251 gsi);
@@ -568,6 +559,7 @@ void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
568static void acpi_os_execute_deferred(struct work_struct *work) 559static void acpi_os_execute_deferred(struct work_struct *work)
569{ 560{
570 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); 561 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
562
571 if (!dpc) { 563 if (!dpc) {
572 printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); 564 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
573 return; 565 return;
@@ -1031,7 +1023,7 @@ acpi_status
1031acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache) 1023acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1032{ 1024{
1033 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL); 1025 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
1034 if (cache == NULL) 1026 if (*cache == NULL)
1035 return AE_ERROR; 1027 return AE_ERROR;
1036 else 1028 else
1037 return AE_OK; 1029 return AE_OK;
@@ -1051,7 +1043,7 @@ acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1051 1043
1052acpi_status acpi_os_purge_cache(acpi_cache_t * cache) 1044acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1053{ 1045{
1054 (void)kmem_cache_shrink(cache); 1046 kmem_cache_shrink(cache);
1055 return (AE_OK); 1047 return (AE_OK);
1056} 1048}
1057 1049
diff --git a/drivers/acpi/parser/psargs.c b/drivers/acpi/parser/psargs.c
index bf88e076c3..c2b9835c89 100644
--- a/drivers/acpi/parser/psargs.c
+++ b/drivers/acpi/parser/psargs.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/parser/psloop.c b/drivers/acpi/parser/psloop.c
index e1541db375..773aee82fb 100644
--- a/drivers/acpi/parser/psloop.c
+++ b/drivers/acpi/parser/psloop.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -42,12 +42,11 @@
42 */ 42 */
43 43
44/* 44/*
45 * Parse the AML and build an operation tree as most interpreters, 45 * Parse the AML and build an operation tree as most interpreters, (such as
46 * like Perl, do. Parsing is done by hand rather than with a YACC 46 * Perl) do. Parsing is done by hand rather than with a YACC generated parser
47 * generated parser to tightly constrain stack and dynamic memory 47 * to tightly constrain stack and dynamic memory usage. Parsing is kept
48 * usage. At the same time, parsing is kept flexible and the code 48 * flexible and the code fairly compact by parsing based on a list of AML
49 * fairly compact by parsing based on a list of AML opcode 49 * opcode templates in aml_op_info[].
50 * templates in aml_op_info[]
51 */ 50 */
52 51
53#include <acpi/acpi.h> 52#include <acpi/acpi.h>
@@ -60,766 +59,679 @@ ACPI_MODULE_NAME("psloop")
60 59
61static u32 acpi_gbl_depth = 0; 60static u32 acpi_gbl_depth = 0;
62 61
62/* Local prototypes */
63
64static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state);
65
66static acpi_status
67acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
68 u8 * aml_op_start,
69 union acpi_parse_object *unnamed_op,
70 union acpi_parse_object **op);
71
72static acpi_status
73acpi_ps_create_op(struct acpi_walk_state *walk_state,
74 u8 * aml_op_start, union acpi_parse_object **new_op);
75
76static acpi_status
77acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
78 u8 * aml_op_start, union acpi_parse_object *op);
79
80static acpi_status
81acpi_ps_complete_op(struct acpi_walk_state *walk_state,
82 union acpi_parse_object **op, acpi_status status);
83
84static acpi_status
85acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
86 union acpi_parse_object *op, acpi_status status);
87
63/******************************************************************************* 88/*******************************************************************************
64 * 89 *
65 * FUNCTION: acpi_ps_parse_loop 90 * FUNCTION: acpi_ps_get_aml_opcode
66 * 91 *
67 * PARAMETERS: walk_state - Current state 92 * PARAMETERS: walk_state - Current state
68 * 93 *
69 * RETURN: Status 94 * RETURN: Status
70 * 95 *
71 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return 96 * DESCRIPTION: Extract the next AML opcode from the input stream.
72 * a tree of ops.
73 * 97 *
74 ******************************************************************************/ 98 ******************************************************************************/
75 99
76acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state) 100static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state)
77{ 101{
78 acpi_status status = AE_OK;
79 acpi_status status2;
80 union acpi_parse_object *op = NULL; /* current op */
81 union acpi_parse_object *arg = NULL;
82 union acpi_parse_object *pre_op = NULL;
83 struct acpi_parse_state *parser_state;
84 u8 *aml_op_start = NULL;
85 102
86 ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state); 103 ACPI_FUNCTION_TRACE_PTR(ps_get_aml_opcode, walk_state);
87 104
88 if (walk_state->descending_callback == NULL) { 105 walk_state->aml_offset =
89 return_ACPI_STATUS(AE_BAD_PARAMETER); 106 (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml,
90 } 107 walk_state->parser_state.aml_start);
108 walk_state->opcode = acpi_ps_peek_opcode(&(walk_state->parser_state));
91 109
92 parser_state = &walk_state->parser_state; 110 /*
93 walk_state->arg_types = 0; 111 * First cut to determine what we have found:
112 * 1) A valid AML opcode
113 * 2) A name string
114 * 3) An unknown/invalid opcode
115 */
116 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
94 117
95#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 118 switch (walk_state->op_info->class) {
119 case AML_CLASS_ASCII:
120 case AML_CLASS_PREFIX:
121 /*
122 * Starts with a valid prefix or ASCII char, this is a name
123 * string. Convert the bare name string to a namepath.
124 */
125 walk_state->opcode = AML_INT_NAMEPATH_OP;
126 walk_state->arg_types = ARGP_NAMESTRING;
127 break;
96 128
97 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) { 129 case AML_CLASS_UNKNOWN:
98 130
99 /* We are restarting a preempted control method */ 131 /* The opcode is unrecognized. Just skip unknown opcodes */
100 132
101 if (acpi_ps_has_completed_scope(parser_state)) { 133 ACPI_ERROR((AE_INFO,
102 /* 134 "Found unknown opcode %X at AML address %p offset %X, ignoring",
103 * We must check if a predicate to an IF or WHILE statement 135 walk_state->opcode, walk_state->parser_state.aml,
104 * was just completed 136 walk_state->aml_offset));
105 */
106 if ((parser_state->scope->parse_scope.op) &&
107 ((parser_state->scope->parse_scope.op->common.
108 aml_opcode == AML_IF_OP)
109 || (parser_state->scope->parse_scope.op->common.
110 aml_opcode == AML_WHILE_OP))
111 && (walk_state->control_state)
112 && (walk_state->control_state->common.state ==
113 ACPI_CONTROL_PREDICATE_EXECUTING)) {
114 /*
115 * A predicate was just completed, get the value of the
116 * predicate and branch based on that value
117 */
118 walk_state->op = NULL;
119 status =
120 acpi_ds_get_predicate_value(walk_state,
121 ACPI_TO_POINTER
122 (TRUE));
123 if (ACPI_FAILURE(status)
124 && ((status & AE_CODE_MASK) !=
125 AE_CODE_CONTROL)) {
126 if (status == AE_AML_NO_RETURN_VALUE) {
127 ACPI_EXCEPTION((AE_INFO, status,
128 "Invoked method did not return a value"));
129 137
130 } 138 ACPI_DUMP_BUFFER(walk_state->parser_state.aml, 128);
131 ACPI_EXCEPTION((AE_INFO, status,
132 "GetPredicate Failed"));
133 return_ACPI_STATUS(status);
134 }
135 139
136 status = 140 /* Assume one-byte bad opcode */
137 acpi_ps_next_parse_state(walk_state, op,
138 status);
139 }
140 141
141 acpi_ps_pop_scope(parser_state, &op, 142 walk_state->parser_state.aml++;
142 &walk_state->arg_types, 143 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
143 &walk_state->arg_count);
144 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
145 "Popped scope, Op=%p\n", op));
146 } else if (walk_state->prev_op) {
147 144
148 /* We were in the middle of an op */ 145 default:
149 146
150 op = walk_state->prev_op; 147 /* Found opcode info, this is a normal opcode */
151 walk_state->arg_types = walk_state->prev_arg_types; 148
152 } 149 walk_state->parser_state.aml +=
150 acpi_ps_get_opcode_size(walk_state->opcode);
151 walk_state->arg_types = walk_state->op_info->parse_args;
152 break;
153 } 153 }
154#endif
155 154
156 /* Iterative parsing loop, while there is more AML to process: */ 155 return_ACPI_STATUS(AE_OK);
156}
157 157
158 while ((parser_state->aml < parser_state->aml_end) || (op)) { 158/*******************************************************************************
159 aml_op_start = parser_state->aml; 159 *
160 if (!op) { 160 * FUNCTION: acpi_ps_build_named_op
161 *
162 * PARAMETERS: walk_state - Current state
163 * aml_op_start - Begin of named Op in AML
164 * unnamed_op - Early Op (not a named Op)
165 * Op - Returned Op
166 *
167 * RETURN: Status
168 *
169 * DESCRIPTION: Parse a named Op
170 *
171 ******************************************************************************/
161 172
162 /* Get the next opcode from the AML stream */ 173static acpi_status
174acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
175 u8 * aml_op_start,
176 union acpi_parse_object *unnamed_op,
177 union acpi_parse_object **op)
178{
179 acpi_status status = AE_OK;
180 union acpi_parse_object *arg = NULL;
163 181
164 walk_state->aml_offset = 182 ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state);
165 (u32) ACPI_PTR_DIFF(parser_state->aml,
166 parser_state->aml_start);
167 walk_state->opcode = acpi_ps_peek_opcode(parser_state);
168 183
169 /* 184 unnamed_op->common.value.arg = NULL;
170 * First cut to determine what we have found: 185 unnamed_op->common.aml_opcode = walk_state->opcode;
171 * 1) A valid AML opcode
172 * 2) A name string
173 * 3) An unknown/invalid opcode
174 */
175 walk_state->op_info =
176 acpi_ps_get_opcode_info(walk_state->opcode);
177 switch (walk_state->op_info->class) {
178 case AML_CLASS_ASCII:
179 case AML_CLASS_PREFIX:
180 /*
181 * Starts with a valid prefix or ASCII char, this is a name
182 * string. Convert the bare name string to a namepath.
183 */
184 walk_state->opcode = AML_INT_NAMEPATH_OP;
185 walk_state->arg_types = ARGP_NAMESTRING;
186 break;
187 186
188 case AML_CLASS_UNKNOWN: 187 /*
188 * Get and append arguments until we find the node that contains
189 * the name (the type ARGP_NAME).
190 */
191 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) &&
192 (GET_CURRENT_ARG_TYPE(walk_state->arg_types) != ARGP_NAME)) {
193 status =
194 acpi_ps_get_next_arg(walk_state,
195 &(walk_state->parser_state),
196 GET_CURRENT_ARG_TYPE(walk_state->
197 arg_types), &arg);
198 if (ACPI_FAILURE(status)) {
199 return_ACPI_STATUS(status);
200 }
189 201
190 /* The opcode is unrecognized. Just skip unknown opcodes */ 202 acpi_ps_append_arg(unnamed_op, arg);
203 INCREMENT_ARG_LIST(walk_state->arg_types);
204 }
191 205
192 ACPI_ERROR((AE_INFO, 206 /*
193 "Found unknown opcode %X at AML address %p offset %X, ignoring", 207 * Make sure that we found a NAME and didn't run out of arguments
194 walk_state->opcode, 208 */
195 parser_state->aml, 209 if (!GET_CURRENT_ARG_TYPE(walk_state->arg_types)) {
196 walk_state->aml_offset)); 210 return_ACPI_STATUS(AE_AML_NO_OPERAND);
211 }
197 212
198 ACPI_DUMP_BUFFER(parser_state->aml, 128); 213 /* We know that this arg is a name, move to next arg */
199 214
200 /* Assume one-byte bad opcode */ 215 INCREMENT_ARG_LIST(walk_state->arg_types);
201 216
202 parser_state->aml++; 217 /*
203 continue; 218 * Find the object. This will either insert the object into
219 * the namespace or simply look it up
220 */
221 walk_state->op = NULL;
204 222
205 default: 223 status = walk_state->descending_callback(walk_state, op);
224 if (ACPI_FAILURE(status)) {
225 ACPI_EXCEPTION((AE_INFO, status, "During name lookup/catalog"));
226 return_ACPI_STATUS(status);
227 }
206 228
207 /* Found opcode info, this is a normal opcode */ 229 if (!*op) {
230 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
231 }
208 232
209 parser_state->aml += 233 status = acpi_ps_next_parse_state(walk_state, *op, status);
210 acpi_ps_get_opcode_size(walk_state->opcode); 234 if (ACPI_FAILURE(status)) {
211 walk_state->arg_types = 235 if (status == AE_CTRL_PENDING) {
212 walk_state->op_info->parse_args; 236 return_ACPI_STATUS(AE_CTRL_PARSE_PENDING);
213 break; 237 }
214 } 238 return_ACPI_STATUS(status);
239 }
215 240
216 /* Create Op structure and append to parent's argument list */ 241 acpi_ps_append_arg(*op, unnamed_op->common.value.arg);
242 acpi_gbl_depth++;
217 243
218 if (walk_state->op_info->flags & AML_NAMED) { 244 if ((*op)->common.aml_opcode == AML_REGION_OP) {
245 /*
246 * Defer final parsing of an operation_region body, because we don't
247 * have enough info in the first pass to parse it correctly (i.e.,
248 * there may be method calls within the term_arg elements of the body.)
249 *
250 * However, we must continue parsing because the opregion is not a
251 * standalone package -- we don't know where the end is at this point.
252 *
253 * (Length is unknown until parse of the body complete)
254 */
255 (*op)->named.data = aml_op_start;
256 (*op)->named.length = 0;
257 }
219 258
220 /* Allocate a new pre_op if necessary */ 259 return_ACPI_STATUS(AE_OK);
260}
221 261
222 if (!pre_op) { 262/*******************************************************************************
223 pre_op = 263 *
224 acpi_ps_alloc_op(walk_state-> 264 * FUNCTION: acpi_ps_create_op
225 opcode); 265 *
226 if (!pre_op) { 266 * PARAMETERS: walk_state - Current state
227 status = AE_NO_MEMORY; 267 * aml_op_start - Op start in AML
228 goto close_this_op; 268 * new_op - Returned Op
229 } 269 *
230 } 270 * RETURN: Status
271 *
272 * DESCRIPTION: Get Op from AML
273 *
274 ******************************************************************************/
231 275
232 pre_op->common.value.arg = NULL; 276static acpi_status
233 pre_op->common.aml_opcode = walk_state->opcode; 277acpi_ps_create_op(struct acpi_walk_state *walk_state,
278 u8 * aml_op_start, union acpi_parse_object **new_op)
279{
280 acpi_status status = AE_OK;
281 union acpi_parse_object *op;
282 union acpi_parse_object *named_op = NULL;
234 283
235 /* 284 ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state);
236 * Get and append arguments until we find the node that contains
237 * the name (the type ARGP_NAME).
238 */
239 while (GET_CURRENT_ARG_TYPE
240 (walk_state->arg_types)
241 &&
242 (GET_CURRENT_ARG_TYPE
243 (walk_state->arg_types) != ARGP_NAME)) {
244 status =
245 acpi_ps_get_next_arg(walk_state,
246 parser_state,
247 GET_CURRENT_ARG_TYPE
248 (walk_state->
249 arg_types),
250 &arg);
251 if (ACPI_FAILURE(status)) {
252 goto close_this_op;
253 }
254 285
255 acpi_ps_append_arg(pre_op, arg); 286 status = acpi_ps_get_aml_opcode(walk_state);
256 INCREMENT_ARG_LIST(walk_state-> 287 if (status == AE_CTRL_PARSE_CONTINUE) {
257 arg_types); 288 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
258 } 289 }
259 290
260 /* 291 /* Create Op structure and append to parent's argument list */
261 * Make sure that we found a NAME and didn't run out of
262 * arguments
263 */
264 if (!GET_CURRENT_ARG_TYPE
265 (walk_state->arg_types)) {
266 status = AE_AML_NO_OPERAND;
267 goto close_this_op;
268 }
269 292
270 /* We know that this arg is a name, move to next arg */ 293 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
294 op = acpi_ps_alloc_op(walk_state->opcode);
295 if (!op) {
296 return_ACPI_STATUS(AE_NO_MEMORY);
297 }
271 298
272 INCREMENT_ARG_LIST(walk_state->arg_types); 299 if (walk_state->op_info->flags & AML_NAMED) {
300 status =
301 acpi_ps_build_named_op(walk_state, aml_op_start, op,
302 &named_op);
303 acpi_ps_free_op(op);
304 if (ACPI_FAILURE(status)) {
305 return_ACPI_STATUS(status);
306 }
273 307
274 /* 308 *new_op = named_op;
275 * Find the object. This will either insert the object into 309 return_ACPI_STATUS(AE_OK);
276 * the namespace or simply look it up 310 }
277 */
278 walk_state->op = NULL;
279 311
280 status = 312 /* Not a named opcode, just allocate Op and append to parent */
281 walk_state->descending_callback(walk_state,
282 &op);
283 if (ACPI_FAILURE(status)) {
284 ACPI_EXCEPTION((AE_INFO, status,
285 "During name lookup/catalog"));
286 goto close_this_op;
287 }
288 313
289 if (!op) { 314 if (walk_state->op_info->flags & AML_CREATE) {
290 continue; 315 /*
291 } 316 * Backup to beginning of create_xXXfield declaration
317 * body_length is unknown until we parse the body
318 */
319 op->named.data = aml_op_start;
320 op->named.length = 0;
321 }
292 322
293 status = 323 acpi_ps_append_arg(acpi_ps_get_parent_scope
294 acpi_ps_next_parse_state(walk_state, op, 324 (&(walk_state->parser_state)), op);
295 status);
296 if (status == AE_CTRL_PENDING) {
297 status = AE_OK;
298 goto close_this_op;
299 }
300 325
301 if (ACPI_FAILURE(status)) { 326 if (walk_state->descending_callback != NULL) {
302 goto close_this_op; 327 /*
303 } 328 * Find the object. This will either insert the object into
329 * the namespace or simply look it up
330 */
331 walk_state->op = *new_op = op;
304 332
305 acpi_ps_append_arg(op, 333 status = walk_state->descending_callback(walk_state, &op);
306 pre_op->common.value.arg); 334 status = acpi_ps_next_parse_state(walk_state, op, status);
307 acpi_gbl_depth++; 335 if (status == AE_CTRL_PENDING) {
308 336 status = AE_CTRL_PARSE_PENDING;
309 if (op->common.aml_opcode == AML_REGION_OP) { 337 }
310 /* 338 }
311 * Defer final parsing of an operation_region body,
312 * because we don't have enough info in the first pass
313 * to parse it correctly (i.e., there may be method
314 * calls within the term_arg elements of the body.)
315 *
316 * However, we must continue parsing because
317 * the opregion is not a standalone package --
318 * we don't know where the end is at this point.
319 *
320 * (Length is unknown until parse of the body complete)
321 */
322 op->named.data = aml_op_start;
323 op->named.length = 0;
324 }
325 } else {
326 /* Not a named opcode, just allocate Op and append to parent */
327 339
328 walk_state->op_info = 340 return_ACPI_STATUS(status);
329 acpi_ps_get_opcode_info(walk_state->opcode); 341}
330 op = acpi_ps_alloc_op(walk_state->opcode);
331 if (!op) {
332 status = AE_NO_MEMORY;
333 goto close_this_op;
334 }
335 342
336 if (walk_state->op_info->flags & AML_CREATE) { 343/*******************************************************************************
337 /* 344 *
338 * Backup to beginning of create_xXXfield declaration 345 * FUNCTION: acpi_ps_get_arguments
339 * body_length is unknown until we parse the body 346 *
340 */ 347 * PARAMETERS: walk_state - Current state
341 op->named.data = aml_op_start; 348 * aml_op_start - Op start in AML
342 op->named.length = 0; 349 * Op - Current Op
343 } 350 *
351 * RETURN: Status
352 *
353 * DESCRIPTION: Get arguments for passed Op.
354 *
355 ******************************************************************************/
344 356
345 acpi_ps_append_arg(acpi_ps_get_parent_scope 357static acpi_status
346 (parser_state), op); 358acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
359 u8 * aml_op_start, union acpi_parse_object *op)
360{
361 acpi_status status = AE_OK;
362 union acpi_parse_object *arg = NULL;
347 363
348 if ((walk_state->descending_callback != NULL)) { 364 ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state);
349 /*
350 * Find the object. This will either insert the object into
351 * the namespace or simply look it up
352 */
353 walk_state->op = op;
354 365
355 status = 366 switch (op->common.aml_opcode) {
356 walk_state-> 367 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
357 descending_callback(walk_state, 368 case AML_WORD_OP: /* AML_WORDDATA_ARG */
358 &op); 369 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
359 status = 370 case AML_QWORD_OP: /* AML_QWORDATA_ARG */
360 acpi_ps_next_parse_state(walk_state, 371 case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
361 op,
362 status);
363 if (status == AE_CTRL_PENDING) {
364 status = AE_OK;
365 goto close_this_op;
366 }
367 372
368 if (ACPI_FAILURE(status)) { 373 /* Fill in constant or string argument directly */
369 goto close_this_op;
370 }
371 }
372 }
373 374
374 op->common.aml_offset = walk_state->aml_offset; 375 acpi_ps_get_next_simple_arg(&(walk_state->parser_state),
376 GET_CURRENT_ARG_TYPE(walk_state->
377 arg_types),
378 op);
379 break;
375 380
376 if (walk_state->op_info) { 381 case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
377 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, 382
378 "Opcode %4.4X [%s] Op %p Aml %p AmlOffset %5.5X\n", 383 status =
379 (u32) op->common.aml_opcode, 384 acpi_ps_get_next_namepath(walk_state,
380 walk_state->op_info->name, op, 385 &(walk_state->parser_state), op,
381 parser_state->aml, 386 1);
382 op->common.aml_offset)); 387 if (ACPI_FAILURE(status)) {
383 } 388 return_ACPI_STATUS(status);
384 } 389 }
385 390
391 walk_state->arg_types = 0;
392 break;
393
394 default:
386 /* 395 /*
387 * Start arg_count at zero because we don't know if there are 396 * Op is not a constant or string, append each argument to the Op
388 * any args yet
389 */ 397 */
390 walk_state->arg_count = 0; 398 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types)
391 399 && !walk_state->arg_count) {
392 /* Are there any arguments that must be processed? */ 400 walk_state->aml_offset =
393 401 (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml,
394 if (walk_state->arg_types) { 402 walk_state->parser_state.
395 403 aml_start);
396 /* Get arguments */
397
398 switch (op->common.aml_opcode) {
399 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
400 case AML_WORD_OP: /* AML_WORDDATA_ARG */
401 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
402 case AML_QWORD_OP: /* AML_QWORDATA_ARG */
403 case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
404
405 /* Fill in constant or string argument directly */
406
407 acpi_ps_get_next_simple_arg(parser_state,
408 GET_CURRENT_ARG_TYPE
409 (walk_state->
410 arg_types), op);
411 break;
412
413 case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
414
415 status =
416 acpi_ps_get_next_namepath(walk_state,
417 parser_state, op,
418 1);
419 if (ACPI_FAILURE(status)) {
420 goto close_this_op;
421 }
422
423 walk_state->arg_types = 0;
424 break;
425 404
426 default: 405 status =
427 /* 406 acpi_ps_get_next_arg(walk_state,
428 * Op is not a constant or string, append each argument 407 &(walk_state->parser_state),
429 * to the Op 408 GET_CURRENT_ARG_TYPE
430 */ 409 (walk_state->arg_types), &arg);
431 while (GET_CURRENT_ARG_TYPE 410 if (ACPI_FAILURE(status)) {
432 (walk_state->arg_types) 411 return_ACPI_STATUS(status);
433 && !walk_state->arg_count) { 412 }
434 walk_state->aml_offset = (u32)
435 ACPI_PTR_DIFF(parser_state->aml,
436 parser_state->
437 aml_start);
438 413
439 status = 414 if (arg) {
440 acpi_ps_get_next_arg(walk_state, 415 arg->common.aml_offset = walk_state->aml_offset;
441 parser_state, 416 acpi_ps_append_arg(op, arg);
442 GET_CURRENT_ARG_TYPE 417 }
443 (walk_state->
444 arg_types),
445 &arg);
446 if (ACPI_FAILURE(status)) {
447 goto close_this_op;
448 }
449 418
450 if (arg) { 419 INCREMENT_ARG_LIST(walk_state->arg_types);
451 arg->common.aml_offset = 420 }
452 walk_state->aml_offset;
453 acpi_ps_append_arg(op, arg);
454 }
455 INCREMENT_ARG_LIST(walk_state->
456 arg_types);
457 }
458 421
459 /* Special processing for certain opcodes */ 422 /* Special processing for certain opcodes */
460 423
461 /* TBD (remove): Temporary mechanism to disable this code if needed */ 424 /* TBD (remove): Temporary mechanism to disable this code if needed */
462 425
463#ifdef ACPI_ENABLE_MODULE_LEVEL_CODE 426#ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
464 427
465 if ((walk_state->pass_number <= 428 if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS1) &&
466 ACPI_IMODE_LOAD_PASS1) 429 ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) {
467 && 430 /*
468 ((walk_state-> 431 * We want to skip If/Else/While constructs during Pass1 because we
469 parse_flags & ACPI_PARSE_DISASSEMBLE) == 432 * want to actually conditionally execute the code during Pass2.
470 0)) { 433 *
471 /* 434 * Except for disassembly, where we always want to walk the
472 * We want to skip If/Else/While constructs during Pass1 435 * If/Else/While packages
473 * because we want to actually conditionally execute the 436 */
474 * code during Pass2. 437 switch (op->common.aml_opcode) {
475 * 438 case AML_IF_OP:
476 * Except for disassembly, where we always want to 439 case AML_ELSE_OP:
477 * walk the If/Else/While packages 440 case AML_WHILE_OP:
478 */
479 switch (op->common.aml_opcode) {
480 case AML_IF_OP:
481 case AML_ELSE_OP:
482 case AML_WHILE_OP:
483
484 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
485 "Pass1: Skipping an If/Else/While body\n"));
486
487 /* Skip body of if/else/while in pass 1 */
488
489 parser_state->aml =
490 parser_state->pkg_end;
491 walk_state->arg_count = 0;
492 break;
493
494 default:
495 break;
496 }
497 }
498#endif
499 switch (op->common.aml_opcode) {
500 case AML_METHOD_OP:
501
502 /*
503 * Skip parsing of control method
504 * because we don't have enough info in the first pass
505 * to parse it correctly.
506 *
507 * Save the length and address of the body
508 */
509 op->named.data = parser_state->aml;
510 op->named.length =
511 (u32) (parser_state->pkg_end -
512 parser_state->aml);
513
514 /* Skip body of method */
515
516 parser_state->aml =
517 parser_state->pkg_end;
518 walk_state->arg_count = 0;
519 break;
520
521 case AML_BUFFER_OP:
522 case AML_PACKAGE_OP:
523 case AML_VAR_PACKAGE_OP:
524
525 if ((op->common.parent) &&
526 (op->common.parent->common.
527 aml_opcode == AML_NAME_OP)
528 && (walk_state->pass_number <=
529 ACPI_IMODE_LOAD_PASS2)) {
530 /*
531 * Skip parsing of Buffers and Packages
532 * because we don't have enough info in the first pass
533 * to parse them correctly.
534 */
535 op->named.data = aml_op_start;
536 op->named.length =
537 (u32) (parser_state->
538 pkg_end -
539 aml_op_start);
540
541 /* Skip body */
542
543 parser_state->aml =
544 parser_state->pkg_end;
545 walk_state->arg_count = 0;
546 }
547 break;
548 441
549 case AML_WHILE_OP: 442 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
443 "Pass1: Skipping an If/Else/While body\n"));
550 444
551 if (walk_state->control_state) { 445 /* Skip body of if/else/while in pass 1 */
552 walk_state->control_state->
553 control.package_end =
554 parser_state->pkg_end;
555 }
556 break;
557 446
558 default: 447 walk_state->parser_state.aml =
448 walk_state->parser_state.pkg_end;
449 walk_state->arg_count = 0;
450 break;
559 451
560 /* No action for all other opcodes */ 452 default:
561 break;
562 }
563 break; 453 break;
564 } 454 }
565 } 455 }
456#endif
566 457
567 /* Check for arguments that need to be processed */ 458 switch (op->common.aml_opcode) {
568 459 case AML_METHOD_OP:
569 if (walk_state->arg_count) {
570 /* 460 /*
571 * There are arguments (complex ones), push Op and 461 * Skip parsing of control method because we don't have enough
572 * prepare for argument 462 * info in the first pass to parse it correctly.
463 *
464 * Save the length and address of the body
573 */ 465 */
574 status = acpi_ps_push_scope(parser_state, op, 466 op->named.data = walk_state->parser_state.aml;
575 walk_state->arg_types, 467 op->named.length = (u32)
576 walk_state->arg_count); 468 (walk_state->parser_state.pkg_end -
577 if (ACPI_FAILURE(status)) { 469 walk_state->parser_state.aml);
578 goto close_this_op;
579 }
580 op = NULL;
581 continue;
582 }
583 470
584 /* 471 /* Skip body of method */
585 * All arguments have been processed -- Op is complete,
586 * prepare for next
587 */
588 walk_state->op_info =
589 acpi_ps_get_opcode_info(op->common.aml_opcode);
590 if (walk_state->op_info->flags & AML_NAMED) {
591 if (acpi_gbl_depth) {
592 acpi_gbl_depth--;
593 }
594 472
595 if (op->common.aml_opcode == AML_REGION_OP) { 473 walk_state->parser_state.aml =
474 walk_state->parser_state.pkg_end;
475 walk_state->arg_count = 0;
476 break;
477
478 case AML_BUFFER_OP:
479 case AML_PACKAGE_OP:
480 case AML_VAR_PACKAGE_OP:
481
482 if ((op->common.parent) &&
483 (op->common.parent->common.aml_opcode ==
484 AML_NAME_OP)
485 && (walk_state->pass_number <=
486 ACPI_IMODE_LOAD_PASS2)) {
596 /* 487 /*
597 * Skip parsing of control method or opregion body, 488 * Skip parsing of Buffers and Packages because we don't have
598 * because we don't have enough info in the first pass 489 * enough info in the first pass to parse them correctly.
599 * to parse them correctly.
600 *
601 * Completed parsing an op_region declaration, we now
602 * know the length.
603 */ 490 */
604 op->named.length = 491 op->named.data = aml_op_start;
605 (u32) (parser_state->aml - op->named.data); 492 op->named.length = (u32)
606 } 493 (walk_state->parser_state.pkg_end -
607 } 494 aml_op_start);
608 495
609 if (walk_state->op_info->flags & AML_CREATE) { 496 /* Skip body */
610 /*
611 * Backup to beginning of create_xXXfield declaration (1 for
612 * Opcode)
613 *
614 * body_length is unknown until we parse the body
615 */
616 op->named.length =
617 (u32) (parser_state->aml - op->named.data);
618 }
619 497
620 /* This op complete, notify the dispatcher */ 498 walk_state->parser_state.aml =
499 walk_state->parser_state.pkg_end;
500 walk_state->arg_count = 0;
501 }
502 break;
621 503
622 if (walk_state->ascending_callback != NULL) { 504 case AML_WHILE_OP:
623 walk_state->op = op;
624 walk_state->opcode = op->common.aml_opcode;
625 505
626 status = walk_state->ascending_callback(walk_state); 506 if (walk_state->control_state) {
627 status = 507 walk_state->control_state->control.package_end =
628 acpi_ps_next_parse_state(walk_state, op, status); 508 walk_state->parser_state.pkg_end;
629 if (status == AE_CTRL_PENDING) {
630 status = AE_OK;
631 goto close_this_op;
632 } 509 }
633 } 510 break;
634
635 close_this_op:
636 /*
637 * Finished one argument of the containing scope
638 */
639 parser_state->scope->parse_scope.arg_count--;
640 511
641 /* Finished with pre_op */ 512 default:
642 513
643 if (pre_op) { 514 /* No action for all other opcodes */
644 acpi_ps_free_op(pre_op); 515 break;
645 pre_op = NULL;
646 } 516 }
647 517
648 /* Close this Op (will result in parse subtree deletion) */ 518 break;
519 }
649 520
650 status2 = acpi_ps_complete_this_op(walk_state, op); 521 return_ACPI_STATUS(AE_OK);
651 if (ACPI_FAILURE(status2)) { 522}
652 return_ACPI_STATUS(status2);
653 }
654 op = NULL;
655 523
656 switch (status) { 524/*******************************************************************************
657 case AE_OK: 525 *
658 break; 526 * FUNCTION: acpi_ps_complete_op
527 *
528 * PARAMETERS: walk_state - Current state
529 * Op - Returned Op
530 * Status - Parse status before complete Op
531 *
532 * RETURN: Status
533 *
534 * DESCRIPTION: Complete Op
535 *
536 ******************************************************************************/
659 537
660 case AE_CTRL_TRANSFER: 538static acpi_status
539acpi_ps_complete_op(struct acpi_walk_state *walk_state,
540 union acpi_parse_object **op, acpi_status status)
541{
542 acpi_status status2;
661 543
662 /* We are about to transfer to a called method. */ 544 ACPI_FUNCTION_TRACE_PTR(ps_complete_op, walk_state);
663 545
664 walk_state->prev_op = op; 546 /*
665 walk_state->prev_arg_types = walk_state->arg_types; 547 * Finished one argument of the containing scope
666 return_ACPI_STATUS(status); 548 */
549 walk_state->parser_state.scope->parse_scope.arg_count--;
667 550
668 case AE_CTRL_END: 551 /* Close this Op (will result in parse subtree deletion) */
669 552
670 acpi_ps_pop_scope(parser_state, &op, 553 status2 = acpi_ps_complete_this_op(walk_state, *op);
671 &walk_state->arg_types, 554 if (ACPI_FAILURE(status2)) {
672 &walk_state->arg_count); 555 return_ACPI_STATUS(status2);
556 }
673 557
674 if (op) { 558 *op = NULL;
675 walk_state->op = op;
676 walk_state->op_info =
677 acpi_ps_get_opcode_info(op->common.
678 aml_opcode);
679 walk_state->opcode = op->common.aml_opcode;
680 559
681 status = 560 switch (status) {
682 walk_state->ascending_callback(walk_state); 561 case AE_OK:
683 status = 562 break;
684 acpi_ps_next_parse_state(walk_state, op,
685 status);
686 563
687 status2 = 564 case AE_CTRL_TRANSFER:
688 acpi_ps_complete_this_op(walk_state, op);
689 if (ACPI_FAILURE(status2)) {
690 return_ACPI_STATUS(status2);
691 }
692 op = NULL;
693 }
694 status = AE_OK;
695 break;
696 565
697 case AE_CTRL_BREAK: 566 /* We are about to transfer to a called method */
698 case AE_CTRL_CONTINUE:
699 567
700 /* Pop off scopes until we find the While */ 568 walk_state->prev_op = NULL;
569 walk_state->prev_arg_types = walk_state->arg_types;
570 return_ACPI_STATUS(status);
701 571
702 while (!op || (op->common.aml_opcode != AML_WHILE_OP)) { 572 case AE_CTRL_END:
703 acpi_ps_pop_scope(parser_state, &op,
704 &walk_state->arg_types,
705 &walk_state->arg_count);
706 573
707 if (op->common.aml_opcode != AML_WHILE_OP) { 574 acpi_ps_pop_scope(&(walk_state->parser_state), op,
708 status2 = 575 &walk_state->arg_types,
709 acpi_ds_result_stack_pop 576 &walk_state->arg_count);
710 (walk_state);
711 if (ACPI_FAILURE(status2)) {
712 return_ACPI_STATUS(status2);
713 }
714 }
715 }
716
717 /* Close this iteration of the While loop */
718 577
719 walk_state->op = op; 578 if (*op) {
579 walk_state->op = *op;
720 walk_state->op_info = 580 walk_state->op_info =
721 acpi_ps_get_opcode_info(op->common.aml_opcode); 581 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
722 walk_state->opcode = op->common.aml_opcode; 582 walk_state->opcode = (*op)->common.aml_opcode;
723 583
724 status = walk_state->ascending_callback(walk_state); 584 status = walk_state->ascending_callback(walk_state);
725 status = 585 status =
726 acpi_ps_next_parse_state(walk_state, op, status); 586 acpi_ps_next_parse_state(walk_state, *op, status);
727 587
728 status2 = acpi_ps_complete_this_op(walk_state, op); 588 status2 = acpi_ps_complete_this_op(walk_state, *op);
729 if (ACPI_FAILURE(status2)) { 589 if (ACPI_FAILURE(status2)) {
730 return_ACPI_STATUS(status2); 590 return_ACPI_STATUS(status2);
731 } 591 }
732 op = NULL; 592 }
733
734 status = AE_OK;
735 break;
736 593
737 case AE_CTRL_TERMINATE: 594 status = AE_OK;
595 break;
738 596
739 status = AE_OK; 597 case AE_CTRL_BREAK:
598 case AE_CTRL_CONTINUE:
740 599
741 /* Clean up */ 600 /* Pop off scopes until we find the While */
742 do {
743 if (op) {
744 status2 =
745 acpi_ps_complete_this_op(walk_state,
746 op);
747 if (ACPI_FAILURE(status2)) {
748 return_ACPI_STATUS(status2);
749 }
750 601
751 status2 = 602 while (!(*op) || ((*op)->common.aml_opcode != AML_WHILE_OP)) {
752 acpi_ds_result_stack_pop 603 acpi_ps_pop_scope(&(walk_state->parser_state), op,
753 (walk_state); 604 &walk_state->arg_types,
754 if (ACPI_FAILURE(status2)) { 605 &walk_state->arg_count);
755 return_ACPI_STATUS(status2);
756 }
757 606
758 acpi_ut_delete_generic_state 607 if ((*op)->common.aml_opcode != AML_WHILE_OP) {
759 (acpi_ut_pop_generic_state 608 status2 = acpi_ds_result_stack_pop(walk_state);
760 (&walk_state->control_state)); 609 if (ACPI_FAILURE(status2)) {
610 return_ACPI_STATUS(status2);
761 } 611 }
612 }
613 }
762 614
763 acpi_ps_pop_scope(parser_state, &op, 615 /* Close this iteration of the While loop */
764 &walk_state->arg_types,
765 &walk_state->arg_count);
766 616
767 } while (op); 617 walk_state->op = *op;
618 walk_state->op_info =
619 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
620 walk_state->opcode = (*op)->common.aml_opcode;
768 621
769 return_ACPI_STATUS(status); 622 status = walk_state->ascending_callback(walk_state);
623 status = acpi_ps_next_parse_state(walk_state, *op, status);
770 624
771 default: /* All other non-AE_OK status */ 625 status2 = acpi_ps_complete_this_op(walk_state, *op);
626 if (ACPI_FAILURE(status2)) {
627 return_ACPI_STATUS(status2);
628 }
772 629
773 do { 630 status = AE_OK;
774 if (op) { 631 break;
775 status2 = 632
776 acpi_ps_complete_this_op(walk_state, 633 case AE_CTRL_TERMINATE:
777 op); 634
778 if (ACPI_FAILURE(status2)) { 635 /* Clean up */
779 return_ACPI_STATUS(status2); 636 do {
780 } 637 if (*op) {
638 status2 =
639 acpi_ps_complete_this_op(walk_state, *op);
640 if (ACPI_FAILURE(status2)) {
641 return_ACPI_STATUS(status2);
642 }
643 status2 = acpi_ds_result_stack_pop(walk_state);
644 if (ACPI_FAILURE(status2)) {
645 return_ACPI_STATUS(status2);
781 } 646 }
782 647
783 acpi_ps_pop_scope(parser_state, &op, 648 acpi_ut_delete_generic_state
784 &walk_state->arg_types, 649 (acpi_ut_pop_generic_state
785 &walk_state->arg_count); 650 (&walk_state->control_state));
651 }
786 652
787 } while (op); 653 acpi_ps_pop_scope(&(walk_state->parser_state), op,
654 &walk_state->arg_types,
655 &walk_state->arg_count);
788 656
789 /* 657 } while (*op);
790 * TBD: Cleanup parse ops on error 658
791 */ 659 return_ACPI_STATUS(AE_OK);
792#if 0 660
793 if (op == NULL) { 661 default: /* All other non-AE_OK status */
794 acpi_ps_pop_scope(parser_state, &op, 662
795 &walk_state->arg_types, 663 do {
796 &walk_state->arg_count); 664 if (*op) {
665 status2 =
666 acpi_ps_complete_this_op(walk_state, *op);
667 if (ACPI_FAILURE(status2)) {
668 return_ACPI_STATUS(status2);
669 }
797 } 670 }
798#endif
799 walk_state->prev_op = op;
800 walk_state->prev_arg_types = walk_state->arg_types;
801 return_ACPI_STATUS(status);
802 }
803 671
804 /* This scope complete? */ 672 acpi_ps_pop_scope(&(walk_state->parser_state), op,
673 &walk_state->arg_types,
674 &walk_state->arg_count);
805 675
806 if (acpi_ps_has_completed_scope(parser_state)) { 676 } while (*op);
807 acpi_ps_pop_scope(parser_state, &op, 677
678#if 0
679 /*
680 * TBD: Cleanup parse ops on error
681 */
682 if (*op == NULL) {
683 acpi_ps_pop_scope(parser_state, op,
808 &walk_state->arg_types, 684 &walk_state->arg_types,
809 &walk_state->arg_count); 685 &walk_state->arg_count);
810 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
811 "Popped scope, Op=%p\n", op));
812 } else {
813 op = NULL;
814 } 686 }
687#endif
688 walk_state->prev_op = NULL;
689 walk_state->prev_arg_types = walk_state->arg_types;
690 return_ACPI_STATUS(status);
691 }
815 692
816 } /* while parser_state->Aml */ 693 /* This scope complete? */
694
695 if (acpi_ps_has_completed_scope(&(walk_state->parser_state))) {
696 acpi_ps_pop_scope(&(walk_state->parser_state), op,
697 &walk_state->arg_types,
698 &walk_state->arg_count);
699 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *op));
700 } else {
701 *op = NULL;
702 }
703
704 return_ACPI_STATUS(AE_OK);
705}
706
707/*******************************************************************************
708 *
709 * FUNCTION: acpi_ps_complete_final_op
710 *
711 * PARAMETERS: walk_state - Current state
712 * Op - Current Op
713 * Status - Current parse status before complete last
714 * Op
715 *
716 * RETURN: Status
717 *
718 * DESCRIPTION: Complete last Op.
719 *
720 ******************************************************************************/
721
722static acpi_status
723acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
724 union acpi_parse_object *op, acpi_status status)
725{
726 acpi_status status2;
727
728 ACPI_FUNCTION_TRACE_PTR(ps_complete_final_op, walk_state);
817 729
818 /* 730 /*
819 * Complete the last Op (if not completed), and clear the scope stack. 731 * Complete the last Op (if not completed), and clear the scope stack.
820 * It is easily possible to end an AML "package" with an unbounded number 732 * It is easily possible to end an AML "package" with an unbounded number
821 * of open scopes (such as when several ASL blocks are closed with 733 * of open scopes (such as when several ASL blocks are closed with
822 * sequential closing braces). We want to terminate each one cleanly. 734 * sequential closing braces). We want to terminate each one cleanly.
823 */ 735 */
824 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n", 736 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
825 op)); 737 op));
@@ -838,8 +750,12 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
838 acpi_ps_next_parse_state(walk_state, op, 750 acpi_ps_next_parse_state(walk_state, op,
839 status); 751 status);
840 if (status == AE_CTRL_PENDING) { 752 if (status == AE_CTRL_PENDING) {
841 status = AE_OK; 753 status =
842 goto close_this_op; 754 acpi_ps_complete_op(walk_state, &op,
755 AE_OK);
756 if (ACPI_FAILURE(status)) {
757 return_ACPI_STATUS(status);
758 }
843 } 759 }
844 760
845 if (status == AE_CTRL_TERMINATE) { 761 if (status == AE_CTRL_TERMINATE) {
@@ -858,7 +774,9 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
858 } 774 }
859 } 775 }
860 776
861 acpi_ps_pop_scope(parser_state, 777 acpi_ps_pop_scope(&
778 (walk_state->
779 parser_state),
862 &op, 780 &op,
863 &walk_state-> 781 &walk_state->
864 arg_types, 782 arg_types,
@@ -887,10 +805,252 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
887 } 805 }
888 } 806 }
889 807
890 acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types, 808 acpi_ps_pop_scope(&(walk_state->parser_state), &op,
809 &walk_state->arg_types,
891 &walk_state->arg_count); 810 &walk_state->arg_count);
892 811
893 } while (op); 812 } while (op);
894 813
895 return_ACPI_STATUS(status); 814 return_ACPI_STATUS(status);
896} 815}
816
817/*******************************************************************************
818 *
819 * FUNCTION: acpi_ps_parse_loop
820 *
821 * PARAMETERS: walk_state - Current state
822 *
823 * RETURN: Status
824 *
825 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
826 * a tree of ops.
827 *
828 ******************************************************************************/
829
830acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
831{
832 acpi_status status = AE_OK;
833 union acpi_parse_object *op = NULL; /* current op */
834 struct acpi_parse_state *parser_state;
835 u8 *aml_op_start = NULL;
836
837 ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state);
838
839 if (walk_state->descending_callback == NULL) {
840 return_ACPI_STATUS(AE_BAD_PARAMETER);
841 }
842
843 parser_state = &walk_state->parser_state;
844 walk_state->arg_types = 0;
845
846#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
847
848 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
849
850 /* We are restarting a preempted control method */
851
852 if (acpi_ps_has_completed_scope(parser_state)) {
853 /*
854 * We must check if a predicate to an IF or WHILE statement
855 * was just completed
856 */
857 if ((parser_state->scope->parse_scope.op) &&
858 ((parser_state->scope->parse_scope.op->common.
859 aml_opcode == AML_IF_OP)
860 || (parser_state->scope->parse_scope.op->common.
861 aml_opcode == AML_WHILE_OP))
862 && (walk_state->control_state)
863 && (walk_state->control_state->common.state ==
864 ACPI_CONTROL_PREDICATE_EXECUTING)) {
865 /*
866 * A predicate was just completed, get the value of the
867 * predicate and branch based on that value
868 */
869 walk_state->op = NULL;
870 status =
871 acpi_ds_get_predicate_value(walk_state,
872 ACPI_TO_POINTER
873 (TRUE));
874 if (ACPI_FAILURE(status)
875 && ((status & AE_CODE_MASK) !=
876 AE_CODE_CONTROL)) {
877 if (status == AE_AML_NO_RETURN_VALUE) {
878 ACPI_EXCEPTION((AE_INFO, status,
879 "Invoked method did not return a value"));
880
881 }
882
883 ACPI_EXCEPTION((AE_INFO, status,
884 "GetPredicate Failed"));
885 return_ACPI_STATUS(status);
886 }
887
888 status =
889 acpi_ps_next_parse_state(walk_state, op,
890 status);
891 }
892
893 acpi_ps_pop_scope(parser_state, &op,
894 &walk_state->arg_types,
895 &walk_state->arg_count);
896 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
897 "Popped scope, Op=%p\n", op));
898 } else if (walk_state->prev_op) {
899
900 /* We were in the middle of an op */
901
902 op = walk_state->prev_op;
903 walk_state->arg_types = walk_state->prev_arg_types;
904 }
905 }
906#endif
907
908 /* Iterative parsing loop, while there is more AML to process: */
909
910 while ((parser_state->aml < parser_state->aml_end) || (op)) {
911 aml_op_start = parser_state->aml;
912 if (!op) {
913 status =
914 acpi_ps_create_op(walk_state, aml_op_start, &op);
915 if (ACPI_FAILURE(status)) {
916 if (status == AE_CTRL_PARSE_CONTINUE) {
917 continue;
918 }
919
920 if (status == AE_CTRL_PARSE_PENDING) {
921 status = AE_OK;
922 }
923
924 status =
925 acpi_ps_complete_op(walk_state, &op,
926 status);
927 if (ACPI_FAILURE(status)) {
928 return_ACPI_STATUS(status);
929 }
930
931 continue;
932 }
933
934 op->common.aml_offset = walk_state->aml_offset;
935
936 if (walk_state->op_info) {
937 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
938 "Opcode %4.4X [%s] Op %p Aml %p AmlOffset %5.5X\n",
939 (u32) op->common.aml_opcode,
940 walk_state->op_info->name, op,
941 parser_state->aml,
942 op->common.aml_offset));
943 }
944 }
945
946 /*
947 * Start arg_count at zero because we don't know if there are
948 * any args yet
949 */
950 walk_state->arg_count = 0;
951
952 /* Are there any arguments that must be processed? */
953
954 if (walk_state->arg_types) {
955
956 /* Get arguments */
957
958 status =
959 acpi_ps_get_arguments(walk_state, aml_op_start, op);
960 if (ACPI_FAILURE(status)) {
961 status =
962 acpi_ps_complete_op(walk_state, &op,
963 status);
964 if (ACPI_FAILURE(status)) {
965 return_ACPI_STATUS(status);
966 }
967
968 continue;
969 }
970 }
971
972 /* Check for arguments that need to be processed */
973
974 if (walk_state->arg_count) {
975 /*
976 * There are arguments (complex ones), push Op and
977 * prepare for argument
978 */
979 status = acpi_ps_push_scope(parser_state, op,
980 walk_state->arg_types,
981 walk_state->arg_count);
982 if (ACPI_FAILURE(status)) {
983 status =
984 acpi_ps_complete_op(walk_state, &op,
985 status);
986 if (ACPI_FAILURE(status)) {
987 return_ACPI_STATUS(status);
988 }
989
990 continue;
991 }
992
993 op = NULL;
994 continue;
995 }
996
997 /*
998 * All arguments have been processed -- Op is complete,
999 * prepare for next
1000 */
1001 walk_state->op_info =
1002 acpi_ps_get_opcode_info(op->common.aml_opcode);
1003 if (walk_state->op_info->flags & AML_NAMED) {
1004 if (acpi_gbl_depth) {
1005 acpi_gbl_depth--;
1006 }
1007
1008 if (op->common.aml_opcode == AML_REGION_OP) {
1009 /*
1010 * Skip parsing of control method or opregion body,
1011 * because we don't have enough info in the first pass
1012 * to parse them correctly.
1013 *
1014 * Completed parsing an op_region declaration, we now
1015 * know the length.
1016 */
1017 op->named.length =
1018 (u32) (parser_state->aml - op->named.data);
1019 }
1020 }
1021
1022 if (walk_state->op_info->flags & AML_CREATE) {
1023 /*
1024 * Backup to beginning of create_xXXfield declaration (1 for
1025 * Opcode)
1026 *
1027 * body_length is unknown until we parse the body
1028 */
1029 op->named.length =
1030 (u32) (parser_state->aml - op->named.data);
1031 }
1032
1033 /* This op complete, notify the dispatcher */
1034
1035 if (walk_state->ascending_callback != NULL) {
1036 walk_state->op = op;
1037 walk_state->opcode = op->common.aml_opcode;
1038
1039 status = walk_state->ascending_callback(walk_state);
1040 status =
1041 acpi_ps_next_parse_state(walk_state, op, status);
1042 if (status == AE_CTRL_PENDING) {
1043 status = AE_OK;
1044 }
1045 }
1046
1047 status = acpi_ps_complete_op(walk_state, &op, status);
1048 if (ACPI_FAILURE(status)) {
1049 return_ACPI_STATUS(status);
1050 }
1051
1052 } /* while parser_state->Aml */
1053
1054 status = acpi_ps_complete_final_op(walk_state, op, status);
1055 return_ACPI_STATUS(status);
1056}
diff --git a/drivers/acpi/parser/psopcode.c b/drivers/acpi/parser/psopcode.c
index 4bd25e3276..16d8b6cc3c 100644
--- a/drivers/acpi/parser/psopcode.c
+++ b/drivers/acpi/parser/psopcode.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/parser/psparse.c b/drivers/acpi/parser/psparse.c
index a02aa62fe1..5d63f48e56 100644
--- a/drivers/acpi/parser/psparse.c
+++ b/drivers/acpi/parser/psparse.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -540,6 +540,11 @@ acpi_status acpi_ps_parse_aml(struct acpi_walk_state *walk_state)
540 540
541 if ((status == AE_ALREADY_EXISTS) && 541 if ((status == AE_ALREADY_EXISTS) &&
542 (!walk_state->method_desc->method.mutex)) { 542 (!walk_state->method_desc->method.mutex)) {
543 ACPI_INFO((AE_INFO,
544 "Marking method %4.4s as Serialized",
545 walk_state->method_node->name.
546 ascii));
547
543 /* 548 /*
544 * Method tried to create an object twice. The probable cause is 549 * Method tried to create an object twice. The probable cause is
545 * that the method cannot handle reentrancy. 550 * that the method cannot handle reentrancy.
diff --git a/drivers/acpi/parser/psscope.c b/drivers/acpi/parser/psscope.c
index a3e0314de2..77cfa4ed0c 100644
--- a/drivers/acpi/parser/psscope.c
+++ b/drivers/acpi/parser/psscope.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/parser/pstree.c b/drivers/acpi/parser/pstree.c
index 0015717ef0..966e7ea2a0 100644
--- a/drivers/acpi/parser/pstree.c
+++ b/drivers/acpi/parser/pstree.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/parser/psutils.c b/drivers/acpi/parser/psutils.c
index d405387b74..8ca52002db 100644
--- a/drivers/acpi/parser/psutils.c
+++ b/drivers/acpi/parser/psutils.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/parser/pswalk.c b/drivers/acpi/parser/pswalk.c
index a84a547a0f..49f9757434 100644
--- a/drivers/acpi/parser/pswalk.c
+++ b/drivers/acpi/parser/pswalk.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/parser/psxface.c b/drivers/acpi/parser/psxface.c
index 5d996c1140..94103bced7 100644
--- a/drivers/acpi/parser/psxface.c
+++ b/drivers/acpi/parser/psxface.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -54,8 +54,6 @@ static void acpi_ps_start_trace(struct acpi_evaluate_info *info);
54 54
55static void acpi_ps_stop_trace(struct acpi_evaluate_info *info); 55static void acpi_ps_stop_trace(struct acpi_evaluate_info *info);
56 56
57static acpi_status acpi_ps_execute_pass(struct acpi_evaluate_info *info);
58
59static void 57static void
60acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action); 58acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action);
61 59
@@ -215,6 +213,8 @@ static void acpi_ps_stop_trace(struct acpi_evaluate_info *info)
215acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info) 213acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
216{ 214{
217 acpi_status status; 215 acpi_status status;
216 union acpi_parse_object *op;
217 struct acpi_walk_state *walk_state;
218 218
219 ACPI_FUNCTION_TRACE(ps_execute_method); 219 ACPI_FUNCTION_TRACE(ps_execute_method);
220 220
@@ -234,8 +234,7 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
234 } 234 }
235 235
236 /* 236 /*
237 * The caller "owns" the parameters, so give each one an extra 237 * The caller "owns" the parameters, so give each one an extra reference
238 * reference
239 */ 238 */
240 acpi_ps_update_parameter_list(info, REF_INCREMENT); 239 acpi_ps_update_parameter_list(info, REF_INCREMENT);
241 240
@@ -244,30 +243,50 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
244 acpi_ps_start_trace(info); 243 acpi_ps_start_trace(info);
245 244
246 /* 245 /*
247 * 1) Perform the first pass parse of the method to enter any 246 * Execute the method. Performs parse simultaneously
248 * named objects that it creates into the namespace
249 */ 247 */
250 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, 248 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
251 "**** Begin Method Parse **** Entry=%p obj=%p\n", 249 "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",
252 info->resolved_node, info->obj_desc)); 250 info->resolved_node->name.ascii, info->resolved_node,
251 info->obj_desc));
252
253 /* Create and init a Root Node */
254
255 op = acpi_ps_create_scope_op();
256 if (!op) {
257 status = AE_NO_MEMORY;
258 goto cleanup;
259 }
260
261 /* Create and initialize a new walk state */
262
263 info->pass_number = ACPI_IMODE_EXECUTE;
264 walk_state =
265 acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
266 NULL, NULL);
267 if (!walk_state) {
268 status = AE_NO_MEMORY;
269 goto cleanup;
270 }
253 271
254 info->pass_number = 1; 272 status = acpi_ds_init_aml_walk(walk_state, op, info->resolved_node,
255 status = acpi_ps_execute_pass(info); 273 info->obj_desc->method.aml_start,
274 info->obj_desc->method.aml_length, info,
275 info->pass_number);
256 if (ACPI_FAILURE(status)) { 276 if (ACPI_FAILURE(status)) {
277 acpi_ds_delete_walk_state(walk_state);
257 goto cleanup; 278 goto cleanup;
258 } 279 }
259 280
260 /* 281 /* Parse the AML */
261 * 2) Execute the method. Performs second pass parse simultaneously
262 */
263 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
264 "**** Begin Method Execution **** Entry=%p obj=%p\n",
265 info->resolved_node, info->obj_desc));
266 282
267 info->pass_number = 3; 283 status = acpi_ps_parse_aml(walk_state);
268 status = acpi_ps_execute_pass(info); 284
285 /* walk_state was deleted by parse_aml */
269 286
270 cleanup: 287 cleanup:
288 acpi_ps_delete_parse_tree(op);
289
271 /* End optional tracing */ 290 /* End optional tracing */
272 291
273 acpi_ps_stop_trace(info); 292 acpi_ps_stop_trace(info);
@@ -330,62 +349,3 @@ acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action)
330 } 349 }
331 } 350 }
332} 351}
333
334/*******************************************************************************
335 *
336 * FUNCTION: acpi_ps_execute_pass
337 *
338 * PARAMETERS: Info - See struct acpi_evaluate_info
339 * (Used: pass_number, Node, and obj_desc)
340 *
341 * RETURN: Status
342 *
343 * DESCRIPTION: Single AML pass: Parse or Execute a control method
344 *
345 ******************************************************************************/
346
347static acpi_status acpi_ps_execute_pass(struct acpi_evaluate_info *info)
348{
349 acpi_status status;
350 union acpi_parse_object *op;
351 struct acpi_walk_state *walk_state;
352
353 ACPI_FUNCTION_TRACE(ps_execute_pass);
354
355 /* Create and init a Root Node */
356
357 op = acpi_ps_create_scope_op();
358 if (!op) {
359 return_ACPI_STATUS(AE_NO_MEMORY);
360 }
361
362 /* Create and initialize a new walk state */
363
364 walk_state =
365 acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
366 NULL, NULL);
367 if (!walk_state) {
368 status = AE_NO_MEMORY;
369 goto cleanup;
370 }
371
372 status = acpi_ds_init_aml_walk(walk_state, op, info->resolved_node,
373 info->obj_desc->method.aml_start,
374 info->obj_desc->method.aml_length,
375 info->pass_number == 1 ? NULL : info,
376 info->pass_number);
377 if (ACPI_FAILURE(status)) {
378 acpi_ds_delete_walk_state(walk_state);
379 goto cleanup;
380 }
381
382 /* Parse the AML */
383
384 status = acpi_ps_parse_aml(walk_state);
385
386 /* Walk state was deleted by parse_aml */
387
388 cleanup:
389 acpi_ps_delete_parse_tree(op);
390 return_ACPI_STATUS(status);
391}
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index 1e2ae6e7a7..55f57a61c5 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -122,19 +122,17 @@ int acpi_pci_bind(struct acpi_device *device)
122 if (!device || !device->parent) 122 if (!device || !device->parent)
123 return -EINVAL; 123 return -EINVAL;
124 124
125 pathname = kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 125 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
126 if (!pathname) 126 if (!pathname)
127 return -ENOMEM; 127 return -ENOMEM;
128 memset(pathname, 0, ACPI_PATHNAME_MAX);
129 buffer.length = ACPI_PATHNAME_MAX; 128 buffer.length = ACPI_PATHNAME_MAX;
130 buffer.pointer = pathname; 129 buffer.pointer = pathname;
131 130
132 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); 131 data = kzalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
133 if (!data) { 132 if (!data) {
134 kfree(pathname); 133 kfree(pathname);
135 return -ENOMEM; 134 return -ENOMEM;
136 } 135 }
137 memset(data, 0, sizeof(struct acpi_pci_data));
138 136
139 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer); 137 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
140 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI device [%s]...\n", 138 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI device [%s]...\n",
@@ -281,10 +279,9 @@ int acpi_pci_unbind(struct acpi_device *device)
281 if (!device || !device->parent) 279 if (!device || !device->parent)
282 return -EINVAL; 280 return -EINVAL;
283 281
284 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 282 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
285 if (!pathname) 283 if (!pathname)
286 return -ENOMEM; 284 return -ENOMEM;
287 memset(pathname, 0, ACPI_PATHNAME_MAX);
288 285
289 buffer.length = ACPI_PATHNAME_MAX; 286 buffer.length = ACPI_PATHNAME_MAX;
290 buffer.pointer = pathname; 287 buffer.pointer = pathname;
@@ -331,11 +328,9 @@ acpi_pci_bind_root(struct acpi_device *device,
331 char *pathname = NULL; 328 char *pathname = NULL;
332 struct acpi_buffer buffer = { 0, NULL }; 329 struct acpi_buffer buffer = { 0, NULL };
333 330
334 331 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
335 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
336 if (!pathname) 332 if (!pathname)
337 return -ENOMEM; 333 return -ENOMEM;
338 memset(pathname, 0, ACPI_PATHNAME_MAX);
339 334
340 buffer.length = ACPI_PATHNAME_MAX; 335 buffer.length = ACPI_PATHNAME_MAX;
341 buffer.pointer = pathname; 336 buffer.pointer = pathname;
@@ -345,12 +340,11 @@ acpi_pci_bind_root(struct acpi_device *device,
345 return -EINVAL; 340 return -EINVAL;
346 } 341 }
347 342
348 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); 343 data = kzalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
349 if (!data) { 344 if (!data) {
350 kfree(pathname); 345 kfree(pathname);
351 return -ENOMEM; 346 return -ENOMEM;
352 } 347 }
353 memset(data, 0, sizeof(struct acpi_pci_data));
354 348
355 data->id = *id; 349 data->id = *id;
356 data->bus = bus; 350 data->bus = bus;
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index feda0341f5..fe7d007833 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -89,10 +89,9 @@ acpi_pci_irq_add_entry(acpi_handle handle,
89 if (!prt) 89 if (!prt)
90 return -EINVAL; 90 return -EINVAL;
91 91
92 entry = kmalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL); 92 entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
93 if (!entry) 93 if (!entry)
94 return -ENOMEM; 94 return -ENOMEM;
95 memset(entry, 0, sizeof(struct acpi_prt_entry));
96 95
97 entry->id.segment = segment; 96 entry->id.segment = segment;
98 entry->id.bus = bus; 97 entry->id.bus = bus;
@@ -161,10 +160,9 @@ int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
161 static int first_time = 1; 160 static int first_time = 1;
162 161
163 162
164 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 163 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
165 if (!pathname) 164 if (!pathname)
166 return -ENOMEM; 165 return -ENOMEM;
167 memset(pathname, 0, ACPI_PATHNAME_MAX);
168 166
169 if (first_time) { 167 if (first_time) {
170 acpi_prt.count = 0; 168 acpi_prt.count = 0;
@@ -198,11 +196,10 @@ int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
198 return -ENODEV; 196 return -ENODEV;
199 } 197 }
200 198
201 prt = kmalloc(buffer.length, GFP_KERNEL); 199 prt = kzalloc(buffer.length, GFP_KERNEL);
202 if (!prt) { 200 if (!prt) {
203 return -ENOMEM; 201 return -ENOMEM;
204 } 202 }
205 memset(prt, 0, buffer.length);
206 buffer.pointer = prt; 203 buffer.pointer = prt;
207 204
208 status = acpi_get_irq_routing_table(handle, &buffer); 205 status = acpi_get_irq_routing_table(handle, &buffer);
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index d53bd9878c..0f683c8c6f 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -103,7 +103,7 @@ DEFINE_MUTEX(acpi_link_lock);
103static acpi_status 103static acpi_status
104acpi_pci_link_check_possible(struct acpi_resource *resource, void *context) 104acpi_pci_link_check_possible(struct acpi_resource *resource, void *context)
105{ 105{
106 struct acpi_pci_link *link = (struct acpi_pci_link *)context; 106 struct acpi_pci_link *link = context;
107 u32 i = 0; 107 u32 i = 0;
108 108
109 109
@@ -307,11 +307,10 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
307 if (!link || !irq) 307 if (!link || !irq)
308 return -EINVAL; 308 return -EINVAL;
309 309
310 resource = kmalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL); 310 resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
311 if (!resource) 311 if (!resource)
312 return -ENOMEM; 312 return -ENOMEM;
313 313
314 memset(resource, 0, sizeof(*resource) + 1);
315 buffer.length = sizeof(*resource) + 1; 314 buffer.length = sizeof(*resource) + 1;
316 buffer.pointer = resource; 315 buffer.pointer = resource;
317 316
@@ -514,7 +513,7 @@ int __init acpi_irq_penalty_init(void)
514 } 513 }
515 } 514 }
516 /* Add a penalty for the SCI */ 515 /* Add a penalty for the SCI */
517 acpi_irq_penalty[acpi_fadt.sci_int] += PIRQ_PENALTY_PCI_USING; 516 acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING;
518 517
519 return 0; 518 return 0;
520} 519}
@@ -613,7 +612,7 @@ acpi_pci_link_allocate_irq(acpi_handle handle,
613 return -1; 612 return -1;
614 } 613 }
615 614
616 link = (struct acpi_pci_link *)acpi_driver_data(device); 615 link = acpi_driver_data(device);
617 if (!link) { 616 if (!link) {
618 printk(KERN_ERR PREFIX "Invalid link context\n"); 617 printk(KERN_ERR PREFIX "Invalid link context\n");
619 return -1; 618 return -1;
@@ -668,7 +667,7 @@ int acpi_pci_link_free_irq(acpi_handle handle)
668 return -1; 667 return -1;
669 } 668 }
670 669
671 link = (struct acpi_pci_link *)acpi_driver_data(device); 670 link = acpi_driver_data(device);
672 if (!link) { 671 if (!link) {
673 printk(KERN_ERR PREFIX "Invalid link context\n"); 672 printk(KERN_ERR PREFIX "Invalid link context\n");
674 return -1; 673 return -1;
@@ -718,10 +717,9 @@ static int acpi_pci_link_add(struct acpi_device *device)
718 if (!device) 717 if (!device)
719 return -EINVAL; 718 return -EINVAL;
720 719
721 link = kmalloc(sizeof(struct acpi_pci_link), GFP_KERNEL); 720 link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
722 if (!link) 721 if (!link)
723 return -ENOMEM; 722 return -ENOMEM;
724 memset(link, 0, sizeof(struct acpi_pci_link));
725 723
726 link->device = device; 724 link->device = device;
727 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); 725 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
@@ -787,7 +785,7 @@ static int irqrouter_resume(struct sys_device *dev)
787 785
788 786
789 /* Make sure SCI is enabled again (Apple firmware bug?) */ 787 /* Make sure SCI is enabled again (Apple firmware bug?) */
790 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1, ACPI_MTX_DO_NOT_LOCK); 788 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1);
791 789
792 list_for_each(node, &acpi_link.entries) { 790 list_for_each(node, &acpi_link.entries) {
793 link = list_entry(node, struct acpi_pci_link, node); 791 link = list_entry(node, struct acpi_pci_link, node);
@@ -808,7 +806,7 @@ static int acpi_pci_link_remove(struct acpi_device *device, int type)
808 if (!device || !acpi_driver_data(device)) 806 if (!device || !acpi_driver_data(device))
809 return -EINVAL; 807 return -EINVAL;
810 808
811 link = (struct acpi_pci_link *)acpi_driver_data(device); 809 link = acpi_driver_data(device);
812 810
813 mutex_lock(&acpi_link_lock); 811 mutex_lock(&acpi_link_lock);
814 list_del(&link->node); 812 list_del(&link->node);
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 2e1a74a967..4ecf701687 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -98,11 +98,12 @@ void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
98 98
99 struct acpi_pci_driver **pptr = &sub_driver; 99 struct acpi_pci_driver **pptr = &sub_driver;
100 while (*pptr) { 100 while (*pptr) {
101 if (*pptr != driver) 101 if (*pptr == driver)
102 continue; 102 break;
103 *pptr = (*pptr)->next; 103 pptr = &(*pptr)->next;
104 break;
105 } 104 }
105 BUG_ON(!*pptr);
106 *pptr = (*pptr)->next;
106 107
107 if (!driver->remove) 108 if (!driver->remove)
108 return; 109 return;
@@ -116,10 +117,23 @@ void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
116 117
117EXPORT_SYMBOL(acpi_pci_unregister_driver); 118EXPORT_SYMBOL(acpi_pci_unregister_driver);
118 119
120acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
121{
122 struct acpi_pci_root *tmp;
123
124 list_for_each_entry(tmp, &acpi_pci_roots, node) {
125 if ((tmp->id.segment == (u16) seg) && (tmp->id.bus == (u16) bus))
126 return tmp->device->handle;
127 }
128 return NULL;
129}
130
131EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
132
119static acpi_status 133static acpi_status
120get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data) 134get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
121{ 135{
122 int *busnr = (int *)data; 136 int *busnr = data;
123 struct acpi_resource_address64 address; 137 struct acpi_resource_address64 address;
124 138
125 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 && 139 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
@@ -180,10 +194,9 @@ static int acpi_pci_root_add(struct acpi_device *device)
180 if (!device) 194 if (!device)
181 return -EINVAL; 195 return -EINVAL;
182 196
183 root = kmalloc(sizeof(struct acpi_pci_root), GFP_KERNEL); 197 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
184 if (!root) 198 if (!root)
185 return -ENOMEM; 199 return -ENOMEM;
186 memset(root, 0, sizeof(struct acpi_pci_root));
187 INIT_LIST_HEAD(&root->node); 200 INIT_LIST_HEAD(&root->node);
188 201
189 root->device = device; 202 root->device = device;
@@ -350,7 +363,7 @@ static int acpi_pci_root_remove(struct acpi_device *device, int type)
350 if (!device || !acpi_driver_data(device)) 363 if (!device || !acpi_driver_data(device))
351 return -EINVAL; 364 return -EINVAL;
352 365
353 root = (struct acpi_pci_root *)acpi_driver_data(device); 366 root = acpi_driver_data(device);
354 367
355 kfree(root); 368 kfree(root);
356 369
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index fe67a8af52..0ba7dfbbb2 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -108,7 +108,7 @@ acpi_power_get_context(acpi_handle handle,
108 return result; 108 return result;
109 } 109 }
110 110
111 *resource = (struct acpi_power_resource *)acpi_driver_data(device); 111 *resource = acpi_driver_data(device);
112 if (!resource) 112 if (!resource)
113 return -ENODEV; 113 return -ENODEV;
114 114
@@ -442,7 +442,7 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
442 struct acpi_power_resource *resource = NULL; 442 struct acpi_power_resource *resource = NULL;
443 443
444 444
445 resource = (struct acpi_power_resource *)seq->private; 445 resource = seq->private;
446 446
447 if (!resource) 447 if (!resource)
448 goto end; 448 goto end;
@@ -532,10 +532,9 @@ static int acpi_power_add(struct acpi_device *device)
532 if (!device) 532 if (!device)
533 return -EINVAL; 533 return -EINVAL;
534 534
535 resource = kmalloc(sizeof(struct acpi_power_resource), GFP_KERNEL); 535 resource = kzalloc(sizeof(struct acpi_power_resource), GFP_KERNEL);
536 if (!resource) 536 if (!resource)
537 return -ENOMEM; 537 return -ENOMEM;
538 memset(resource, 0, sizeof(struct acpi_power_resource));
539 538
540 resource->device = device; 539 resource->device = device;
541 strcpy(resource->name, device->pnp.bus_id); 540 strcpy(resource->name, device->pnp.bus_id);
@@ -590,7 +589,7 @@ static int acpi_power_remove(struct acpi_device *device, int type)
590 if (!device || !acpi_driver_data(device)) 589 if (!device || !acpi_driver_data(device))
591 return -EINVAL; 590 return -EINVAL;
592 591
593 resource = (struct acpi_power_resource *)acpi_driver_data(device); 592 resource = acpi_driver_data(device);
594 593
595 acpi_power_remove_fs(device); 594 acpi_power_remove_fs(device);
596 595
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 46e72c3887..0079bc5108 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -277,7 +277,7 @@ static struct proc_dir_entry *acpi_processor_dir = NULL;
277 277
278static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset) 278static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset)
279{ 279{
280 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 280 struct acpi_processor *pr = seq->private;
281 281
282 282
283 if (!pr) 283 if (!pr)
@@ -375,30 +375,126 @@ static int acpi_processor_remove_fs(struct acpi_device *device)
375} 375}
376 376
377/* Use the acpiid in MADT to map cpus in case of SMP */ 377/* Use the acpiid in MADT to map cpus in case of SMP */
378
378#ifndef CONFIG_SMP 379#ifndef CONFIG_SMP
379#define convert_acpiid_to_cpu(acpi_id) (-1) 380static int get_cpu_id(acpi_handle handle, u32 acpi_id) {return -1;}
380#else 381#else
381 382
383static struct acpi_table_madt *madt;
384
385static int map_lapic_id(struct acpi_subtable_header *entry,
386 u32 acpi_id, int *apic_id)
387{
388 struct acpi_madt_local_apic *lapic =
389 (struct acpi_madt_local_apic *)entry;
390 if ((lapic->lapic_flags & ACPI_MADT_ENABLED) &&
391 lapic->processor_id == acpi_id) {
392 *apic_id = lapic->id;
393 return 1;
394 }
395 return 0;
396}
397
398static int map_lsapic_id(struct acpi_subtable_header *entry,
399 u32 acpi_id, int *apic_id)
400{
401 struct acpi_madt_local_sapic *lsapic =
402 (struct acpi_madt_local_sapic *)entry;
403 /* Only check enabled APICs*/
404 if (lsapic->lapic_flags & ACPI_MADT_ENABLED) {
405 /* First check against id */
406 if (lsapic->processor_id == acpi_id) {
407 *apic_id = lsapic->id;
408 return 1;
409 /* Check against optional uid */
410 } else if (entry->length >= 16 &&
411 lsapic->uid == acpi_id) {
412 *apic_id = lsapic->uid;
413 return 1;
414 }
415 }
416 return 0;
417}
418
382#ifdef CONFIG_IA64 419#ifdef CONFIG_IA64
383#define arch_acpiid_to_apicid ia64_acpiid_to_sapicid
384#define arch_cpu_to_apicid ia64_cpu_to_sapicid 420#define arch_cpu_to_apicid ia64_cpu_to_sapicid
385#define ARCH_BAD_APICID (0xffff)
386#else 421#else
387#define arch_acpiid_to_apicid x86_acpiid_to_apicid
388#define arch_cpu_to_apicid x86_cpu_to_apicid 422#define arch_cpu_to_apicid x86_cpu_to_apicid
389#define ARCH_BAD_APICID (0xff)
390#endif 423#endif
391 424
392static int convert_acpiid_to_cpu(u8 acpi_id) 425static int map_madt_entry(u32 acpi_id)
426{
427 unsigned long madt_end, entry;
428 int apic_id = -1;
429
430 if (!madt)
431 return apic_id;
432
433 entry = (unsigned long)madt;
434 madt_end = entry + madt->header.length;
435
436 /* Parse all entries looking for a match. */
437
438 entry += sizeof(struct acpi_table_madt);
439 while (entry + sizeof(struct acpi_subtable_header) < madt_end) {
440 struct acpi_subtable_header *header =
441 (struct acpi_subtable_header *)entry;
442 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
443 if (map_lapic_id(header, acpi_id, &apic_id))
444 break;
445 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
446 if (map_lsapic_id(header, acpi_id, &apic_id))
447 break;
448 }
449 entry += header->length;
450 }
451 return apic_id;
452}
453
454static int map_mat_entry(acpi_handle handle, u32 acpi_id)
455{
456 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
457 union acpi_object *obj;
458 struct acpi_subtable_header *header;
459 int apic_id = -1;
460
461 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
462 goto exit;
463
464 if (!buffer.length || !buffer.pointer)
465 goto exit;
466
467 obj = buffer.pointer;
468 if (obj->type != ACPI_TYPE_BUFFER ||
469 obj->buffer.length < sizeof(struct acpi_subtable_header)) {
470 goto exit;
471 }
472
473 header = (struct acpi_subtable_header *)obj->buffer.pointer;
474 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
475 map_lapic_id(header, acpi_id, &apic_id);
476 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
477 map_lsapic_id(header, acpi_id, &apic_id);
478 }
479
480exit:
481 if (buffer.pointer)
482 kfree(buffer.pointer);
483 return apic_id;
484}
485
486static int get_cpu_id(acpi_handle handle, u32 acpi_id)
393{ 487{
394 u16 apic_id;
395 int i; 488 int i;
489 int apic_id = -1;
396 490
397 apic_id = arch_acpiid_to_apicid[acpi_id]; 491 apic_id = map_mat_entry(handle, acpi_id);
398 if (apic_id == ARCH_BAD_APICID) 492 if (apic_id == -1)
399 return -1; 493 apic_id = map_madt_entry(acpi_id);
494 if (apic_id == -1)
495 return apic_id;
400 496
401 for (i = 0; i < NR_CPUS; i++) { 497 for (i = 0; i < NR_CPUS; ++i) {
402 if (arch_cpu_to_apicid[i] == apic_id) 498 if (arch_cpu_to_apicid[i] == apic_id)
403 return i; 499 return i;
404 } 500 }
@@ -410,7 +506,7 @@ static int convert_acpiid_to_cpu(u8 acpi_id)
410 Driver Interface 506 Driver Interface
411 -------------------------------------------------------------------------- */ 507 -------------------------------------------------------------------------- */
412 508
413static int acpi_processor_get_info(struct acpi_processor *pr) 509static int acpi_processor_get_info(struct acpi_processor *pr, unsigned has_uid)
414{ 510{
415 acpi_status status = 0; 511 acpi_status status = 0;
416 union acpi_object object = { 0 }; 512 union acpi_object object = { 0 };
@@ -431,7 +527,7 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
431 * Check to see if we have bus mastering arbitration control. This 527 * Check to see if we have bus mastering arbitration control. This
432 * is required for proper C3 usage (to maintain cache coherency). 528 * is required for proper C3 usage (to maintain cache coherency).
433 */ 529 */
434 if (acpi_fadt.V1_pm2_cnt_blk && acpi_fadt.pm2_cnt_len) { 530 if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
435 pr->flags.bm_control = 1; 531 pr->flags.bm_control = 1;
436 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 532 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
437 "Bus mastering arbitration control present\n")); 533 "Bus mastering arbitration control present\n"));
@@ -439,24 +535,35 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
439 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 535 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
440 "No bus mastering arbitration control\n")); 536 "No bus mastering arbitration control\n"));
441 537
442 /* 538 /* Check if it is a Device with HID and UID */
443 * Evalute the processor object. Note that it is common on SMP to 539 if (has_uid) {
444 * have the first (boot) processor with a valid PBLK address while 540 unsigned long value;
445 * all others have a NULL address. 541 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
446 */ 542 NULL, &value);
447 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer); 543 if (ACPI_FAILURE(status)) {
448 if (ACPI_FAILURE(status)) { 544 printk(KERN_ERR PREFIX "Evaluating processor _UID\n");
449 printk(KERN_ERR PREFIX "Evaluating processor object\n"); 545 return -ENODEV;
450 return -ENODEV; 546 }
451 } 547 pr->acpi_id = value;
452 548 } else {
453 /* 549 /*
454 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP. 550 * Evalute the processor object. Note that it is common on SMP to
455 * >>> 'acpi_get_processor_id(acpi_id, &id)' in arch/xxx/acpi.c 551 * have the first (boot) processor with a valid PBLK address while
456 */ 552 * all others have a NULL address.
457 pr->acpi_id = object.processor.proc_id; 553 */
554 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
555 if (ACPI_FAILURE(status)) {
556 printk(KERN_ERR PREFIX "Evaluating processor object\n");
557 return -ENODEV;
558 }
458 559
459 cpu_index = convert_acpiid_to_cpu(pr->acpi_id); 560 /*
561 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
562 * >>> 'acpi_get_processor_id(acpi_id, &id)' in arch/xxx/acpi.c
563 */
564 pr->acpi_id = object.processor.proc_id;
565 }
566 cpu_index = get_cpu_id(pr->handle, pr->acpi_id);
460 567
461 /* Handle UP system running SMP kernel, with no LAPIC in MADT */ 568 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
462 if (!cpu0_initialized && (cpu_index == -1) && 569 if (!cpu0_initialized && (cpu_index == -1) &&
@@ -473,12 +580,9 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
473 * less than the max # of CPUs. They should be ignored _iff 580 * less than the max # of CPUs. They should be ignored _iff
474 * they are physically not present. 581 * they are physically not present.
475 */ 582 */
476 if (cpu_index == -1) { 583 if (pr->id == -1) {
477 if (ACPI_FAILURE 584 if (ACPI_FAILURE
478 (acpi_processor_hotadd_init(pr->handle, &pr->id))) { 585 (acpi_processor_hotadd_init(pr->handle, &pr->id))) {
479 printk(KERN_ERR PREFIX
480 "Getting cpuindex for acpiid 0x%x\n",
481 pr->acpi_id);
482 return -ENODEV; 586 return -ENODEV;
483 } 587 }
484 } 588 }
@@ -493,8 +597,8 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
493 object.processor.pblk_length); 597 object.processor.pblk_length);
494 else { 598 else {
495 pr->throttling.address = object.processor.pblk_address; 599 pr->throttling.address = object.processor.pblk_address;
496 pr->throttling.duty_offset = acpi_fadt.duty_offset; 600 pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
497 pr->throttling.duty_width = acpi_fadt.duty_width; 601 pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
498 602
499 pr->pblk = object.processor.pblk_address; 603 pr->pblk = object.processor.pblk_address;
500 604
@@ -528,7 +632,7 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
528 632
529 pr = acpi_driver_data(device); 633 pr = acpi_driver_data(device);
530 634
531 result = acpi_processor_get_info(pr); 635 result = acpi_processor_get_info(pr, device->flags.unique_id);
532 if (result) { 636 if (result) {
533 /* Processor is physically not present */ 637 /* Processor is physically not present */
534 return 0; 638 return 0;
@@ -542,12 +646,12 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
542 * Don't trust it blindly 646 * Don't trust it blindly
543 */ 647 */
544 if (processor_device_array[pr->id] != NULL && 648 if (processor_device_array[pr->id] != NULL &&
545 processor_device_array[pr->id] != (void *)device) { 649 processor_device_array[pr->id] != device) {
546 printk(KERN_WARNING "BIOS reported wrong ACPI id" 650 printk(KERN_WARNING "BIOS reported wrong ACPI id"
547 "for the processor\n"); 651 "for the processor\n");
548 return -ENODEV; 652 return -ENODEV;
549 } 653 }
550 processor_device_array[pr->id] = (void *)device; 654 processor_device_array[pr->id] = device;
551 655
552 processors[pr->id] = pr; 656 processors[pr->id] = pr;
553 657
@@ -578,7 +682,7 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
578 682
579static void acpi_processor_notify(acpi_handle handle, u32 event, void *data) 683static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
580{ 684{
581 struct acpi_processor *pr = (struct acpi_processor *)data; 685 struct acpi_processor *pr = data;
582 struct acpi_device *device = NULL; 686 struct acpi_device *device = NULL;
583 687
584 688
@@ -615,10 +719,9 @@ static int acpi_processor_add(struct acpi_device *device)
615 if (!device) 719 if (!device)
616 return -EINVAL; 720 return -EINVAL;
617 721
618 pr = kmalloc(sizeof(struct acpi_processor), GFP_KERNEL); 722 pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
619 if (!pr) 723 if (!pr)
620 return -ENOMEM; 724 return -ENOMEM;
621 memset(pr, 0, sizeof(struct acpi_processor));
622 725
623 pr->handle = device->handle; 726 pr->handle = device->handle;
624 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); 727 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
@@ -637,7 +740,7 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
637 if (!device || !acpi_driver_data(device)) 740 if (!device || !acpi_driver_data(device))
638 return -EINVAL; 741 return -EINVAL;
639 742
640 pr = (struct acpi_processor *)acpi_driver_data(device); 743 pr = acpi_driver_data(device);
641 744
642 if (pr->id >= NR_CPUS) { 745 if (pr->id >= NR_CPUS) {
643 kfree(pr); 746 kfree(pr);
@@ -899,15 +1002,21 @@ static int __init acpi_processor_init(void)
899 memset(&processors, 0, sizeof(processors)); 1002 memset(&processors, 0, sizeof(processors));
900 memset(&errata, 0, sizeof(errata)); 1003 memset(&errata, 0, sizeof(errata));
901 1004
1005#ifdef CONFIG_SMP
1006 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
1007 (struct acpi_table_header **)&madt)))
1008 madt = 0;
1009#endif
1010
902 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); 1011 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
903 if (!acpi_processor_dir) 1012 if (!acpi_processor_dir)
904 return 0; 1013 return -ENOMEM;
905 acpi_processor_dir->owner = THIS_MODULE; 1014 acpi_processor_dir->owner = THIS_MODULE;
906 1015
907 result = acpi_bus_register_driver(&acpi_processor_driver); 1016 result = acpi_bus_register_driver(&acpi_processor_driver);
908 if (result < 0) { 1017 if (result < 0) {
909 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); 1018 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
910 return 0; 1019 return result;
911 } 1020 }
912 1021
913 acpi_processor_install_hotplug_notify(); 1022 acpi_processor_install_hotplug_notify();
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 65b3f056ad..6c6751b140 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -160,7 +160,7 @@ static inline u32 ticks_elapsed(u32 t1, u32 t2)
160{ 160{
161 if (t2 >= t1) 161 if (t2 >= t1)
162 return (t2 - t1); 162 return (t2 - t1);
163 else if (!acpi_fadt.tmr_val_ext) 163 else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER))
164 return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF); 164 return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
165 else 165 else
166 return ((0xFFFFFFFF - t1) + t2); 166 return ((0xFFFFFFFF - t1) + t2);
@@ -187,8 +187,7 @@ acpi_processor_power_activate(struct acpi_processor *pr,
187 case ACPI_STATE_C3: 187 case ACPI_STATE_C3:
188 /* Disable bus master reload */ 188 /* Disable bus master reload */
189 if (new->type != ACPI_STATE_C3 && pr->flags.bm_check) 189 if (new->type != ACPI_STATE_C3 && pr->flags.bm_check)
190 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0, 190 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
191 ACPI_MTX_DO_NOT_LOCK);
192 break; 191 break;
193 } 192 }
194 } 193 }
@@ -198,8 +197,7 @@ acpi_processor_power_activate(struct acpi_processor *pr,
198 case ACPI_STATE_C3: 197 case ACPI_STATE_C3:
199 /* Enable bus master reload */ 198 /* Enable bus master reload */
200 if (old->type != ACPI_STATE_C3 && pr->flags.bm_check) 199 if (old->type != ACPI_STATE_C3 && pr->flags.bm_check)
201 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1, 200 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
202 ACPI_MTX_DO_NOT_LOCK);
203 break; 201 break;
204 } 202 }
205 203
@@ -211,7 +209,11 @@ acpi_processor_power_activate(struct acpi_processor *pr,
211static void acpi_safe_halt(void) 209static void acpi_safe_halt(void)
212{ 210{
213 current_thread_info()->status &= ~TS_POLLING; 211 current_thread_info()->status &= ~TS_POLLING;
214 smp_mb__after_clear_bit(); 212 /*
213 * TS_POLLING-cleared state must be visible before we
214 * test NEED_RESCHED:
215 */
216 smp_mb();
215 if (!need_resched()) 217 if (!need_resched())
216 safe_halt(); 218 safe_halt();
217 current_thread_info()->status |= TS_POLLING; 219 current_thread_info()->status |= TS_POLLING;
@@ -232,7 +234,7 @@ static void acpi_cstate_enter(struct acpi_processor_cx *cstate)
232 /* Dummy wait op - must do something useless after P_LVL2 read 234 /* Dummy wait op - must do something useless after P_LVL2 read
233 because chipsets cannot guarantee that STPCLK# signal 235 because chipsets cannot guarantee that STPCLK# signal
234 gets asserted in time to freeze execution properly. */ 236 gets asserted in time to freeze execution properly. */
235 unused = inl(acpi_fadt.xpm_tmr_blk.address); 237 unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
236 } 238 }
237} 239}
238 240
@@ -287,12 +289,10 @@ static void acpi_processor_idle(void)
287 289
288 pr->power.bm_activity <<= diff; 290 pr->power.bm_activity <<= diff;
289 291
290 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, 292 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
291 &bm_status, ACPI_MTX_DO_NOT_LOCK);
292 if (bm_status) { 293 if (bm_status) {
293 pr->power.bm_activity |= 0x1; 294 pr->power.bm_activity |= 0x1;
294 acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 295 acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
295 1, ACPI_MTX_DO_NOT_LOCK);
296 } 296 }
297 /* 297 /*
298 * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect 298 * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
@@ -334,7 +334,7 @@ static void acpi_processor_idle(void)
334 * detection phase, to work cleanly with logical CPU hotplug. 334 * detection phase, to work cleanly with logical CPU hotplug.
335 */ 335 */
336 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) && 336 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
337 !pr->flags.has_cst && !acpi_fadt.plvl2_up) 337 !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
338 cx = &pr->power.states[ACPI_STATE_C1]; 338 cx = &pr->power.states[ACPI_STATE_C1];
339#endif 339#endif
340 340
@@ -345,7 +345,11 @@ static void acpi_processor_idle(void)
345 */ 345 */
346 if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) { 346 if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) {
347 current_thread_info()->status &= ~TS_POLLING; 347 current_thread_info()->status &= ~TS_POLLING;
348 smp_mb__after_clear_bit(); 348 /*
349 * TS_POLLING-cleared state must be visible before we
350 * test NEED_RESCHED:
351 */
352 smp_mb();
349 if (need_resched()) { 353 if (need_resched()) {
350 current_thread_info()->status |= TS_POLLING; 354 current_thread_info()->status |= TS_POLLING;
351 local_irq_enable(); 355 local_irq_enable();
@@ -376,11 +380,11 @@ static void acpi_processor_idle(void)
376 380
377 case ACPI_STATE_C2: 381 case ACPI_STATE_C2:
378 /* Get start time (ticks) */ 382 /* Get start time (ticks) */
379 t1 = inl(acpi_fadt.xpm_tmr_blk.address); 383 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
380 /* Invoke C2 */ 384 /* Invoke C2 */
381 acpi_cstate_enter(cx); 385 acpi_cstate_enter(cx);
382 /* Get end time (ticks) */ 386 /* Get end time (ticks) */
383 t2 = inl(acpi_fadt.xpm_tmr_blk.address); 387 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
384 388
385#ifdef CONFIG_GENERIC_TIME 389#ifdef CONFIG_GENERIC_TIME
386 /* TSC halts in C2, so notify users */ 390 /* TSC halts in C2, so notify users */
@@ -403,8 +407,7 @@ static void acpi_processor_idle(void)
403 * All CPUs are trying to go to C3 407 * All CPUs are trying to go to C3
404 * Disable bus master arbitration 408 * Disable bus master arbitration
405 */ 409 */
406 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1, 410 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
407 ACPI_MTX_DO_NOT_LOCK);
408 } 411 }
409 } else { 412 } else {
410 /* SMP with no shared cache... Invalidate cache */ 413 /* SMP with no shared cache... Invalidate cache */
@@ -412,16 +415,15 @@ static void acpi_processor_idle(void)
412 } 415 }
413 416
414 /* Get start time (ticks) */ 417 /* Get start time (ticks) */
415 t1 = inl(acpi_fadt.xpm_tmr_blk.address); 418 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
416 /* Invoke C3 */ 419 /* Invoke C3 */
417 acpi_cstate_enter(cx); 420 acpi_cstate_enter(cx);
418 /* Get end time (ticks) */ 421 /* Get end time (ticks) */
419 t2 = inl(acpi_fadt.xpm_tmr_blk.address); 422 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
420 if (pr->flags.bm_check) { 423 if (pr->flags.bm_check) {
421 /* Enable bus master arbitration */ 424 /* Enable bus master arbitration */
422 atomic_dec(&c3_cpu_count); 425 atomic_dec(&c3_cpu_count);
423 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0, 426 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
424 ACPI_MTX_DO_NOT_LOCK);
425 } 427 }
426 428
427#ifdef CONFIG_GENERIC_TIME 429#ifdef CONFIG_GENERIC_TIME
@@ -449,7 +451,7 @@ static void acpi_processor_idle(void)
449#ifdef CONFIG_HOTPLUG_CPU 451#ifdef CONFIG_HOTPLUG_CPU
450 /* Don't do promotion/demotion */ 452 /* Don't do promotion/demotion */
451 if ((cx->type == ACPI_STATE_C1) && (num_online_cpus() > 1) && 453 if ((cx->type == ACPI_STATE_C1) && (num_online_cpus() > 1) &&
452 !pr->flags.has_cst && !acpi_fadt.plvl2_up) { 454 !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) {
453 next_state = cx; 455 next_state = cx;
454 goto end; 456 goto end;
455 } 457 }
@@ -619,7 +621,8 @@ static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
619 * Check for P_LVL2_UP flag before entering C2 and above on 621 * Check for P_LVL2_UP flag before entering C2 and above on
620 * an SMP system. 622 * an SMP system.
621 */ 623 */
622 if ((num_online_cpus() > 1) && !acpi_fadt.plvl2_up) 624 if ((num_online_cpus() > 1) &&
625 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
623 return -ENODEV; 626 return -ENODEV;
624#endif 627#endif
625 628
@@ -628,8 +631,8 @@ static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
628 pr->power.states[ACPI_STATE_C3].address = pr->pblk + 5; 631 pr->power.states[ACPI_STATE_C3].address = pr->pblk + 5;
629 632
630 /* determine latencies from FADT */ 633 /* determine latencies from FADT */
631 pr->power.states[ACPI_STATE_C2].latency = acpi_fadt.plvl2_lat; 634 pr->power.states[ACPI_STATE_C2].latency = acpi_gbl_FADT.C2latency;
632 pr->power.states[ACPI_STATE_C3].latency = acpi_fadt.plvl3_lat; 635 pr->power.states[ACPI_STATE_C3].latency = acpi_gbl_FADT.C3latency;
633 636
634 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 637 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
635 "lvl2[0x%08x] lvl3[0x%08x]\n", 638 "lvl2[0x%08x] lvl3[0x%08x]\n",
@@ -673,7 +676,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
673 return -ENODEV; 676 return -ENODEV;
674 } 677 }
675 678
676 cst = (union acpi_object *)buffer.pointer; 679 cst = buffer.pointer;
677 680
678 /* There must be at least 2 elements */ 681 /* There must be at least 2 elements */
679 if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) { 682 if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) {
@@ -702,14 +705,14 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
702 705
703 memset(&cx, 0, sizeof(cx)); 706 memset(&cx, 0, sizeof(cx));
704 707
705 element = (union acpi_object *)&(cst->package.elements[i]); 708 element = &(cst->package.elements[i]);
706 if (element->type != ACPI_TYPE_PACKAGE) 709 if (element->type != ACPI_TYPE_PACKAGE)
707 continue; 710 continue;
708 711
709 if (element->package.count != 4) 712 if (element->package.count != 4)
710 continue; 713 continue;
711 714
712 obj = (union acpi_object *)&(element->package.elements[0]); 715 obj = &(element->package.elements[0]);
713 716
714 if (obj->type != ACPI_TYPE_BUFFER) 717 if (obj->type != ACPI_TYPE_BUFFER)
715 continue; 718 continue;
@@ -721,7 +724,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
721 continue; 724 continue;
722 725
723 /* There should be an easy way to extract an integer... */ 726 /* There should be an easy way to extract an integer... */
724 obj = (union acpi_object *)&(element->package.elements[1]); 727 obj = &(element->package.elements[1]);
725 if (obj->type != ACPI_TYPE_INTEGER) 728 if (obj->type != ACPI_TYPE_INTEGER)
726 continue; 729 continue;
727 730
@@ -754,13 +757,13 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
754 } 757 }
755 } 758 }
756 759
757 obj = (union acpi_object *)&(element->package.elements[2]); 760 obj = &(element->package.elements[2]);
758 if (obj->type != ACPI_TYPE_INTEGER) 761 if (obj->type != ACPI_TYPE_INTEGER)
759 continue; 762 continue;
760 763
761 cx.latency = obj->integer.value; 764 cx.latency = obj->integer.value;
762 765
763 obj = (union acpi_object *)&(element->package.elements[3]); 766 obj = &(element->package.elements[3]);
764 if (obj->type != ACPI_TYPE_INTEGER) 767 if (obj->type != ACPI_TYPE_INTEGER)
765 continue; 768 continue;
766 769
@@ -875,14 +878,13 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
875 * WBINVD should be set in fadt, for C3 state to be 878 * WBINVD should be set in fadt, for C3 state to be
876 * supported on when bm_check is not required. 879 * supported on when bm_check is not required.
877 */ 880 */
878 if (acpi_fadt.wb_invd != 1) { 881 if (!(acpi_gbl_FADT.flags & ACPI_FADT_WBINVD)) {
879 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 882 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
880 "Cache invalidation should work properly" 883 "Cache invalidation should work properly"
881 " for C3 to be enabled on SMP systems\n")); 884 " for C3 to be enabled on SMP systems\n"));
882 return; 885 return;
883 } 886 }
884 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 887 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
885 0, ACPI_MTX_DO_NOT_LOCK);
886 } 888 }
887 889
888 /* 890 /*
@@ -1029,7 +1031,7 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1029 1031
1030static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset) 1032static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
1031{ 1033{
1032 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 1034 struct acpi_processor *pr = seq->private;
1033 unsigned int i; 1035 unsigned int i;
1034 1036
1035 1037
@@ -1088,7 +1090,7 @@ static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
1088 seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n", 1090 seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n",
1089 pr->power.states[i].latency, 1091 pr->power.states[i].latency,
1090 pr->power.states[i].usage, 1092 pr->power.states[i].usage,
1091 pr->power.states[i].time); 1093 (unsigned long long)pr->power.states[i].time);
1092 } 1094 }
1093 1095
1094 end: 1096 end:
@@ -1156,9 +1158,9 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1156 if (!pr) 1158 if (!pr)
1157 return -EINVAL; 1159 return -EINVAL;
1158 1160
1159 if (acpi_fadt.cst_cnt && !nocst) { 1161 if (acpi_gbl_FADT.cst_control && !nocst) {
1160 status = 1162 status =
1161 acpi_os_write_port(acpi_fadt.smi_cmd, acpi_fadt.cst_cnt, 8); 1163 acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8);
1162 if (ACPI_FAILURE(status)) { 1164 if (ACPI_FAILURE(status)) {
1163 ACPI_EXCEPTION((AE_INFO, status, 1165 ACPI_EXCEPTION((AE_INFO, status,
1164 "Notifying BIOS of _CST ability failed")); 1166 "Notifying BIOS of _CST ability failed"));
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 6fd174a371..058f13cf3b 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -236,7 +236,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
236 return -ENODEV; 236 return -ENODEV;
237 } 237 }
238 238
239 pss = (union acpi_object *)buffer.pointer; 239 pss = buffer.pointer;
240 if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) { 240 if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) {
241 printk(KERN_ERR PREFIX "Invalid _PSS data\n"); 241 printk(KERN_ERR PREFIX "Invalid _PSS data\n");
242 result = -EFAULT; 242 result = -EFAULT;
@@ -322,10 +322,6 @@ static int acpi_processor_get_performance_info(struct acpi_processor *pr)
322 if (result) 322 if (result)
323 return result; 323 return result;
324 324
325 result = acpi_processor_get_platform_limit(pr);
326 if (result)
327 return result;
328
329 return 0; 325 return 0;
330} 326}
331 327
@@ -356,31 +352,24 @@ int acpi_processor_notify_smm(struct module *calling_module)
356 352
357 is_done = -EIO; 353 is_done = -EIO;
358 354
359 /* Can't write pstate_cnt to smi_cmd if either value is zero */ 355 /* Can't write pstate_control to smi_command if either value is zero */
360 if ((!acpi_fadt.smi_cmd) || (!acpi_fadt.pstate_cnt)) { 356 if ((!acpi_gbl_FADT.smi_command) || (!acpi_gbl_FADT.pstate_control)) {
361 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_cnt\n")); 357 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_control\n"));
362 module_put(calling_module); 358 module_put(calling_module);
363 return 0; 359 return 0;
364 } 360 }
365 361
366 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 362 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
367 "Writing pstate_cnt [0x%x] to smi_cmd [0x%x]\n", 363 "Writing pstate_control [0x%x] to smi_command [0x%x]\n",
368 acpi_fadt.pstate_cnt, acpi_fadt.smi_cmd)); 364 acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command));
369
370 /* FADT v1 doesn't support pstate_cnt, many BIOS vendors use
371 * it anyway, so we need to support it... */
372 if (acpi_fadt_is_v1) {
373 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
374 "Using v1.0 FADT reserved value for pstate_cnt\n"));
375 }
376 365
377 status = acpi_os_write_port(acpi_fadt.smi_cmd, 366 status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
378 (u32) acpi_fadt.pstate_cnt, 8); 367 (u32) acpi_gbl_FADT.pstate_control, 8);
379 if (ACPI_FAILURE(status)) { 368 if (ACPI_FAILURE(status)) {
380 ACPI_EXCEPTION((AE_INFO, status, 369 ACPI_EXCEPTION((AE_INFO, status,
381 "Failed to write pstate_cnt [0x%x] to " 370 "Failed to write pstate_control [0x%x] to "
382 "smi_cmd [0x%x]", acpi_fadt.pstate_cnt, 371 "smi_command [0x%x]", acpi_gbl_FADT.pstate_control,
383 acpi_fadt.smi_cmd)); 372 acpi_gbl_FADT.smi_command));
384 module_put(calling_module); 373 module_put(calling_module);
385 return status; 374 return status;
386 } 375 }
@@ -410,7 +399,7 @@ static struct file_operations acpi_processor_perf_fops = {
410 399
411static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset) 400static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset)
412{ 401{
413 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 402 struct acpi_processor *pr = seq->private;
414 int i; 403 int i;
415 404
416 405
@@ -451,8 +440,8 @@ acpi_processor_write_performance(struct file *file,
451 size_t count, loff_t * data) 440 size_t count, loff_t * data)
452{ 441{
453 int result = 0; 442 int result = 0;
454 struct seq_file *m = (struct seq_file *)file->private_data; 443 struct seq_file *m = file->private_data;
455 struct acpi_processor *pr = (struct acpi_processor *)m->private; 444 struct acpi_processor *pr = m->private;
456 struct acpi_processor_performance *perf; 445 struct acpi_processor_performance *perf;
457 char state_string[12] = { '\0' }; 446 char state_string[12] = { '\0' };
458 unsigned int new_state = 0; 447 unsigned int new_state = 0;
@@ -551,7 +540,7 @@ static int acpi_processor_get_psd(struct acpi_processor *pr)
551 return -ENODEV; 540 return -ENODEV;
552 } 541 }
553 542
554 psd = (union acpi_object *) buffer.pointer; 543 psd = buffer.pointer;
555 if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) { 544 if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) {
556 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n")); 545 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n"));
557 result = -EFAULT; 546 result = -EFAULT;
@@ -736,10 +725,6 @@ int acpi_processor_preregister_performance(
736 } 725 }
737 726
738err_ret: 727err_ret:
739 if (retval) {
740 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error while parsing _PSD domain information. Assuming no coordination\n"));
741 }
742
743 for_each_possible_cpu(i) { 728 for_each_possible_cpu(i) {
744 pr = processors[i]; 729 pr = processors[i];
745 if (!pr || !pr->performance) 730 if (!pr || !pr->performance)
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index ef5e0f6efd..40fecd67ad 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -208,7 +208,7 @@ int acpi_processor_set_thermal_limit(acpi_handle handle, int type)
208 if (result) 208 if (result)
209 return result; 209 return result;
210 210
211 pr = (struct acpi_processor *)acpi_driver_data(device); 211 pr = acpi_driver_data(device);
212 if (!pr) 212 if (!pr)
213 return -ENODEV; 213 return -ENODEV;
214 214
@@ -348,8 +348,8 @@ static ssize_t acpi_processor_write_limit(struct file * file,
348 size_t count, loff_t * data) 348 size_t count, loff_t * data)
349{ 349{
350 int result = 0; 350 int result = 0;
351 struct seq_file *m = (struct seq_file *)file->private_data; 351 struct seq_file *m = file->private_data;
352 struct acpi_processor *pr = (struct acpi_processor *)m->private; 352 struct acpi_processor *pr = m->private;
353 char limit_string[25] = { '\0' }; 353 char limit_string[25] = { '\0' };
354 int px = 0; 354 int px = 0;
355 int tx = 0; 355 int tx = 0;
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index d044ec519d..89dff3639a 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -125,7 +125,7 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
125 /* Used to clear all duty_value bits */ 125 /* Used to clear all duty_value bits */
126 duty_mask = pr->throttling.state_count - 1; 126 duty_mask = pr->throttling.state_count - 1;
127 127
128 duty_mask <<= acpi_fadt.duty_offset; 128 duty_mask <<= acpi_gbl_FADT.duty_offset;
129 duty_mask = ~duty_mask; 129 duty_mask = ~duty_mask;
130 } 130 }
131 131
@@ -208,7 +208,7 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
208 return 0; 208 return 0;
209 } 209 }
210 210
211 pr->throttling.state_count = 1 << acpi_fadt.duty_width; 211 pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width;
212 212
213 /* 213 /*
214 * Compute state values. Note that throttling displays a linear power/ 214 * Compute state values. Note that throttling displays a linear power/
@@ -259,7 +259,7 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
259static int acpi_processor_throttling_seq_show(struct seq_file *seq, 259static int acpi_processor_throttling_seq_show(struct seq_file *seq,
260 void *offset) 260 void *offset)
261{ 261{
262 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 262 struct acpi_processor *pr = seq->private;
263 int i = 0; 263 int i = 0;
264 int result = 0; 264 int result = 0;
265 265
@@ -307,8 +307,8 @@ static ssize_t acpi_processor_write_throttling(struct file * file,
307 size_t count, loff_t * data) 307 size_t count, loff_t * data)
308{ 308{
309 int result = 0; 309 int result = 0;
310 struct seq_file *m = (struct seq_file *)file->private_data; 310 struct seq_file *m = file->private_data;
311 struct acpi_processor *pr = (struct acpi_processor *)m->private; 311 struct acpi_processor *pr = m->private;
312 char state_string[12] = { '\0' }; 312 char state_string[12] = { '\0' };
313 313
314 314
diff --git a/drivers/acpi/resources/rsaddr.c b/drivers/acpi/resources/rsaddr.c
index 8fa3213ce0..271e61509e 100644
--- a/drivers/acpi/resources/rsaddr.c
+++ b/drivers/acpi/resources/rsaddr.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rscalc.c b/drivers/acpi/resources/rscalc.c
index cf87b02300..8c6d3fdec3 100644
--- a/drivers/acpi/resources/rscalc.c
+++ b/drivers/acpi/resources/rscalc.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rscreate.c b/drivers/acpi/resources/rscreate.c
index 008058acdd..1358c06a96 100644
--- a/drivers/acpi/resources/rscreate.c
+++ b/drivers/acpi/resources/rscreate.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsdump.c b/drivers/acpi/resources/rsdump.c
index 9c99a723a8..de20a5d6de 100644
--- a/drivers/acpi/resources/rsdump.c
+++ b/drivers/acpi/resources/rsdump.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsinfo.c b/drivers/acpi/resources/rsinfo.c
index 9e7ae2f8a1..7e3c335ab3 100644
--- a/drivers/acpi/resources/rsinfo.c
+++ b/drivers/acpi/resources/rsinfo.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsio.c b/drivers/acpi/resources/rsio.c
index ea567167c4..b297bc3e44 100644
--- a/drivers/acpi/resources/rsio.c
+++ b/drivers/acpi/resources/rsio.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsirq.c b/drivers/acpi/resources/rsirq.c
index 1fa63bc2e3..5657f7b950 100644
--- a/drivers/acpi/resources/rsirq.c
+++ b/drivers/acpi/resources/rsirq.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rslist.c b/drivers/acpi/resources/rslist.c
index 29423ce030..a92755c887 100644
--- a/drivers/acpi/resources/rslist.c
+++ b/drivers/acpi/resources/rslist.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsmemory.c b/drivers/acpi/resources/rsmemory.c
index a5131936d6..521eab7dd8 100644
--- a/drivers/acpi/resources/rsmemory.c
+++ b/drivers/acpi/resources/rsmemory.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsmisc.c b/drivers/acpi/resources/rsmisc.c
index faf6e106b7..3b63b561b9 100644
--- a/drivers/acpi/resources/rsmisc.c
+++ b/drivers/acpi/resources/rsmisc.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsutils.c b/drivers/acpi/resources/rsutils.c
index a9cbee8e8b..2442a8f8df 100644
--- a/drivers/acpi/resources/rsutils.c
+++ b/drivers/acpi/resources/rsutils.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsxface.c b/drivers/acpi/resources/rsxface.c
index 1999e2ab7d..991f890149 100644
--- a/drivers/acpi/resources/rsxface.c
+++ b/drivers/acpi/resources/rsxface.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 8908a975e5..f58fc7447a 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -923,7 +923,7 @@ static struct proc_dir_entry *acpi_battery_dir = NULL;
923 923
924static int acpi_battery_read_info(struct seq_file *seq, void *offset) 924static int acpi_battery_read_info(struct seq_file *seq, void *offset)
925{ 925{
926 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 926 struct acpi_battery *battery = seq->private;
927 int cscale; 927 int cscale;
928 int result = 0; 928 int result = 0;
929 929
@@ -1076,7 +1076,7 @@ static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
1076 1076
1077static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) 1077static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
1078{ 1078{
1079 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 1079 struct acpi_battery *battery = seq->private;
1080 int result = 0; 1080 int result = 0;
1081 int cscale; 1081 int cscale;
1082 1082
@@ -1125,8 +1125,8 @@ static ssize_t
1125acpi_battery_write_alarm(struct file *file, const char __user * buffer, 1125acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1126 size_t count, loff_t * ppos) 1126 size_t count, loff_t * ppos)
1127{ 1127{
1128 struct seq_file *seq = (struct seq_file *)file->private_data; 1128 struct seq_file *seq = file->private_data;
1129 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 1129 struct acpi_battery *battery = seq->private;
1130 char alarm_string[12] = { '\0' }; 1130 char alarm_string[12] = { '\0' };
1131 int result, old_alarm, new_alarm; 1131 int result, old_alarm, new_alarm;
1132 1132
@@ -1160,14 +1160,14 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1160 if (result) { 1160 if (result) {
1161 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1161 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1162 "acpi_battery_set_alarm() failed\n")); 1162 "acpi_battery_set_alarm() failed\n"));
1163 (void)acpi_battery_set_alarm(battery, old_alarm); 1163 acpi_battery_set_alarm(battery, old_alarm);
1164 goto end; 1164 goto end;
1165 } 1165 }
1166 result = acpi_battery_get_alarm(battery); 1166 result = acpi_battery_get_alarm(battery);
1167 if (result) { 1167 if (result) {
1168 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1168 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1169 "acpi_battery_get_alarm() failed\n")); 1169 "acpi_battery_get_alarm() failed\n"));
1170 (void)acpi_battery_set_alarm(battery, old_alarm); 1170 acpi_battery_set_alarm(battery, old_alarm);
1171 goto end; 1171 goto end;
1172 } 1172 }
1173 1173
@@ -1217,7 +1217,7 @@ static struct proc_dir_entry *acpi_ac_dir = NULL;
1217 1217
1218static int acpi_ac_read_state(struct seq_file *seq, void *offset) 1218static int acpi_ac_read_state(struct seq_file *seq, void *offset)
1219{ 1219{
1220 struct acpi_sbs *sbs = (struct acpi_sbs *)seq->private; 1220 struct acpi_sbs *sbs = seq->private;
1221 int result; 1221 int result;
1222 1222
1223 if (sbs->zombie) { 1223 if (sbs->zombie) {
@@ -1302,7 +1302,7 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
1302 battery->init_state = 1; 1302 battery->init_state = 1;
1303 } 1303 }
1304 1304
1305 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); 1305 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1306 1306
1307 result = acpi_sbs_generic_add_fs(&battery->battery_entry, 1307 result = acpi_sbs_generic_add_fs(&battery->battery_entry,
1308 acpi_battery_dir, 1308 acpi_battery_dir,
@@ -1485,7 +1485,7 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1485 } 1485 }
1486 1486
1487 if (old_battery_present != new_battery_present) { 1487 if (old_battery_present != new_battery_present) {
1488 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); 1488 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1489 result = acpi_sbs_generate_event(sbs->device, 1489 result = acpi_sbs_generate_event(sbs->device,
1490 ACPI_SBS_BATTERY_NOTIFY_STATUS, 1490 ACPI_SBS_BATTERY_NOTIFY_STATUS,
1491 new_battery_present, 1491 new_battery_present,
@@ -1498,7 +1498,7 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1498 } 1498 }
1499 } 1499 }
1500 if (old_remaining_capacity != battery->state.remaining_capacity) { 1500 if (old_remaining_capacity != battery->state.remaining_capacity) {
1501 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); 1501 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1502 result = acpi_sbs_generate_event(sbs->device, 1502 result = acpi_sbs_generate_event(sbs->device,
1503 ACPI_SBS_BATTERY_NOTIFY_STATUS, 1503 ACPI_SBS_BATTERY_NOTIFY_STATUS,
1504 new_battery_present, 1504 new_battery_present,
@@ -1576,12 +1576,11 @@ static int acpi_sbs_add(struct acpi_device *device)
1576 int id, cnt; 1576 int id, cnt;
1577 acpi_status status = AE_OK; 1577 acpi_status status = AE_OK;
1578 1578
1579 sbs = kmalloc(sizeof(struct acpi_sbs), GFP_KERNEL); 1579 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
1580 if (!sbs) { 1580 if (!sbs) {
1581 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n")); 1581 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n"));
1582 return -ENOMEM; 1582 return -ENOMEM;
1583 } 1583 }
1584 memset(sbs, 0, sizeof(struct acpi_sbs));
1585 1584
1586 cnt = 0; 1585 cnt = 0;
1587 while (cnt < 10) { 1586 while (cnt < 10) {
@@ -1659,7 +1658,7 @@ static int acpi_sbs_add(struct acpi_device *device)
1659 init_timer(&sbs->update_timer); 1658 init_timer(&sbs->update_timer);
1660 if (update_mode == QUEUE_UPDATE_MODE) { 1659 if (update_mode == QUEUE_UPDATE_MODE) {
1661 status = acpi_os_execute(OSL_GPE_HANDLER, 1660 status = acpi_os_execute(OSL_GPE_HANDLER,
1662 acpi_sbs_update_queue, (void *)sbs); 1661 acpi_sbs_update_queue, sbs);
1663 if (status != AE_OK) { 1662 if (status != AE_OK) {
1664 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1663 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1665 "acpi_os_execute() failed\n")); 1664 "acpi_os_execute() failed\n"));
@@ -1685,7 +1684,7 @@ static int acpi_sbs_add(struct acpi_device *device)
1685 1684
1686int acpi_sbs_remove(struct acpi_device *device, int type) 1685int acpi_sbs_remove(struct acpi_device *device, int type)
1687{ 1686{
1688 struct acpi_sbs *sbs = NULL; 1687 struct acpi_sbs *sbs;
1689 int id; 1688 int id;
1690 1689
1691 if (!device) { 1690 if (!device) {
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 4139e65d0f..5049230ccf 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1027,12 +1027,11 @@ acpi_add_single_object(struct acpi_device **child,
1027 if (!child) 1027 if (!child)
1028 return -EINVAL; 1028 return -EINVAL;
1029 1029
1030 device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL); 1030 device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
1031 if (!device) { 1031 if (!device) {
1032 printk(KERN_ERR PREFIX "Memory allocation error\n"); 1032 printk(KERN_ERR PREFIX "Memory allocation error\n");
1033 return -ENOMEM; 1033 return -ENOMEM;
1034 } 1034 }
1035 memset(device, 0, sizeof(struct acpi_device));
1036 1035
1037 device->handle = handle; 1036 device->handle = handle;
1038 device->parent = parent; 1037 device->parent = parent;
@@ -1368,14 +1367,14 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
1368 /* 1367 /*
1369 * Enumerate all fixed-feature devices. 1368 * Enumerate all fixed-feature devices.
1370 */ 1369 */
1371 if (acpi_fadt.pwr_button == 0) { 1370 if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) {
1372 result = acpi_add_single_object(&device, acpi_root, 1371 result = acpi_add_single_object(&device, acpi_root,
1373 NULL, 1372 NULL,
1374 ACPI_BUS_TYPE_POWER_BUTTON, 1373 ACPI_BUS_TYPE_POWER_BUTTON,
1375 &ops); 1374 &ops);
1376 } 1375 }
1377 1376
1378 if (acpi_fadt.sleep_button == 0) { 1377 if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
1379 result = acpi_add_single_object(&device, acpi_root, 1378 result = acpi_add_single_object(&device, acpi_root,
1380 NULL, 1379 NULL,
1381 ACPI_BUS_TYPE_SLEEP_BUTTON, 1380 ACPI_BUS_TYPE_SLEEP_BUTTON,
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c
index 3496257803..ccc11b33d8 100644
--- a/drivers/acpi/sleep/proc.c
+++ b/drivers/acpi/sleep/proc.c
@@ -73,7 +73,7 @@ acpi_system_write_sleep(struct file *file,
73static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset) 73static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
74{ 74{
75 u32 sec, min, hr; 75 u32 sec, min, hr;
76 u32 day, mo, yr; 76 u32 day, mo, yr, cent = 0;
77 unsigned char rtc_control = 0; 77 unsigned char rtc_control = 0;
78 unsigned long flags; 78 unsigned long flags;
79 79
@@ -87,20 +87,19 @@ static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
87 rtc_control = CMOS_READ(RTC_CONTROL); 87 rtc_control = CMOS_READ(RTC_CONTROL);
88 88
89 /* If we ever get an FACP with proper values... */ 89 /* If we ever get an FACP with proper values... */
90 if (acpi_gbl_FADT->day_alrm) 90 if (acpi_gbl_FADT.day_alarm)
91 /* ACPI spec: only low 6 its should be cared */ 91 /* ACPI spec: only low 6 its should be cared */
92 day = CMOS_READ(acpi_gbl_FADT->day_alrm) & 0x3F; 92 day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F;
93 else 93 else
94 day = CMOS_READ(RTC_DAY_OF_MONTH); 94 day = CMOS_READ(RTC_DAY_OF_MONTH);
95 if (acpi_gbl_FADT->mon_alrm) 95 if (acpi_gbl_FADT.month_alarm)
96 mo = CMOS_READ(acpi_gbl_FADT->mon_alrm); 96 mo = CMOS_READ(acpi_gbl_FADT.month_alarm);
97 else 97 else
98 mo = CMOS_READ(RTC_MONTH); 98 mo = CMOS_READ(RTC_MONTH);
99 if (acpi_gbl_FADT->century) 99 if (acpi_gbl_FADT.century)
100 yr = CMOS_READ(acpi_gbl_FADT->century) * 100 + 100 cent = CMOS_READ(acpi_gbl_FADT.century);
101 CMOS_READ(RTC_YEAR); 101
102 else 102 yr = CMOS_READ(RTC_YEAR);
103 yr = CMOS_READ(RTC_YEAR);
104 103
105 spin_unlock_irqrestore(&rtc_lock, flags); 104 spin_unlock_irqrestore(&rtc_lock, flags);
106 105
@@ -111,10 +110,11 @@ static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
111 BCD_TO_BIN(day); 110 BCD_TO_BIN(day);
112 BCD_TO_BIN(mo); 111 BCD_TO_BIN(mo);
113 BCD_TO_BIN(yr); 112 BCD_TO_BIN(yr);
113 BCD_TO_BIN(cent);
114 } 114 }
115 115
116 /* we're trusting the FADT (see above) */ 116 /* we're trusting the FADT (see above) */
117 if (!acpi_gbl_FADT->century) 117 if (!acpi_gbl_FADT.century)
118 /* If we're not trusting the FADT, we should at least make it 118 /* If we're not trusting the FADT, we should at least make it
119 * right for _this_ century... ehm, what is _this_ century? 119 * right for _this_ century... ehm, what is _this_ century?
120 * 120 *
@@ -134,6 +134,8 @@ static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
134 * 134 *
135 */ 135 */
136 yr += 2000; 136 yr += 2000;
137 else
138 yr += cent * 100;
137 139
138 seq_printf(seq, "%4.4u-", yr); 140 seq_printf(seq, "%4.4u-", yr);
139 (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo); 141 (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo);
@@ -317,12 +319,12 @@ acpi_system_write_alarm(struct file *file,
317 * offsets into the CMOS RAM here -- which for some reason are pointing 319 * offsets into the CMOS RAM here -- which for some reason are pointing
318 * to the RTC area of memory. 320 * to the RTC area of memory.
319 */ 321 */
320 if (acpi_gbl_FADT->day_alrm) 322 if (acpi_gbl_FADT.day_alarm)
321 CMOS_WRITE(day, acpi_gbl_FADT->day_alrm); 323 CMOS_WRITE(day, acpi_gbl_FADT.day_alarm);
322 if (acpi_gbl_FADT->mon_alrm) 324 if (acpi_gbl_FADT.month_alarm)
323 CMOS_WRITE(mo, acpi_gbl_FADT->mon_alrm); 325 CMOS_WRITE(mo, acpi_gbl_FADT.month_alarm);
324 if (acpi_gbl_FADT->century) 326 if (acpi_gbl_FADT.century)
325 CMOS_WRITE(yr / 100, acpi_gbl_FADT->century); 327 CMOS_WRITE(yr / 100, acpi_gbl_FADT.century);
326 /* enable the rtc alarm interrupt */ 328 /* enable the rtc alarm interrupt */
327 rtc_control |= RTC_AIE; 329 rtc_control |= RTC_AIE;
328 CMOS_WRITE(rtc_control, RTC_CONTROL); 330 CMOS_WRITE(rtc_control, RTC_CONTROL);
diff --git a/drivers/acpi/sleep/wakeup.c b/drivers/acpi/sleep/wakeup.c
index af1dbabaf0..fab8f2694f 100644
--- a/drivers/acpi/sleep/wakeup.c
+++ b/drivers/acpi/sleep/wakeup.c
@@ -183,11 +183,11 @@ late_initcall(acpi_wakeup_device_init);
183#endif 183#endif
184 184
185/* 185/*
186 * Disable all wakeup GPEs before power off. 186 * Disable all wakeup GPEs before entering requested sleep state.
187 * 187 * @sleep_state: ACPI state
188 * Since acpi_enter_sleep_state() will disable all 188 * Since acpi_enter_sleep_state() will disable all
189 * RUNTIME GPEs, we simply mark all GPES that 189 * RUNTIME GPEs, we simply mark all GPES that
190 * are not enabled for wakeup from S5 as RUNTIME. 190 * are not enabled for wakeup from requested state as RUNTIME.
191 */ 191 */
192void acpi_gpe_sleep_prepare(u32 sleep_state) 192void acpi_gpe_sleep_prepare(u32 sleep_state)
193{ 193{
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index 407b0e0281..7147b0bdab 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -44,7 +44,6 @@ ACPI_MODULE_NAME("acpi_system")
44#define ACPI_SYSTEM_FILE_EVENT "event" 44#define ACPI_SYSTEM_FILE_EVENT "event"
45#define ACPI_SYSTEM_FILE_DSDT "dsdt" 45#define ACPI_SYSTEM_FILE_DSDT "dsdt"
46#define ACPI_SYSTEM_FILE_FADT "fadt" 46#define ACPI_SYSTEM_FILE_FADT "fadt"
47extern struct fadt_descriptor acpi_fadt;
48 47
49/* 48/*
50 * Make ACPICA version work as module param 49 * Make ACPICA version work as module param
@@ -96,17 +95,16 @@ acpi_system_read_dsdt(struct file *file,
96 char __user * buffer, size_t count, loff_t * ppos) 95 char __user * buffer, size_t count, loff_t * ppos)
97{ 96{
98 acpi_status status = AE_OK; 97 acpi_status status = AE_OK;
99 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL }; 98 struct acpi_table_header *dsdt = NULL;
100 ssize_t res; 99 ssize_t res;
101 100
102 101
103 status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt); 102 status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
104 if (ACPI_FAILURE(status)) 103 if (ACPI_FAILURE(status))
105 return -ENODEV; 104 return -ENODEV;
106 105
107 res = simple_read_from_buffer(buffer, count, ppos, 106 res = simple_read_from_buffer(buffer, count, ppos,
108 dsdt.pointer, dsdt.length); 107 dsdt, dsdt->length);
109 kfree(dsdt.pointer);
110 108
111 return res; 109 return res;
112} 110}
@@ -123,17 +121,16 @@ acpi_system_read_fadt(struct file *file,
123 char __user * buffer, size_t count, loff_t * ppos) 121 char __user * buffer, size_t count, loff_t * ppos)
124{ 122{
125 acpi_status status = AE_OK; 123 acpi_status status = AE_OK;
126 struct acpi_buffer fadt = { ACPI_ALLOCATE_BUFFER, NULL }; 124 struct acpi_table_header *fadt = NULL;
127 ssize_t res; 125 ssize_t res;
128 126
129 127
130 status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &fadt); 128 status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
131 if (ACPI_FAILURE(status)) 129 if (ACPI_FAILURE(status))
132 return -ENODEV; 130 return -ENODEV;
133 131
134 res = simple_read_from_buffer(buffer, count, ppos, 132 res = simple_read_from_buffer(buffer, count, ppos,
135 fadt.pointer, fadt.length); 133 fadt, fadt->length);
136 kfree(fadt.pointer);
137 134
138 return res; 135 return res;
139} 136}
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index bfb3bfcf9e..ba4cb20031 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -38,154 +38,97 @@
38 38
39#define ACPI_MAX_TABLES 128 39#define ACPI_MAX_TABLES 128
40 40
41static char *acpi_table_signatures[ACPI_TABLE_COUNT] = {
42 [ACPI_TABLE_UNKNOWN] = "????",
43 [ACPI_APIC] = "APIC",
44 [ACPI_BOOT] = "BOOT",
45 [ACPI_DBGP] = "DBGP",
46 [ACPI_DSDT] = "DSDT",
47 [ACPI_ECDT] = "ECDT",
48 [ACPI_ETDT] = "ETDT",
49 [ACPI_FADT] = "FACP",
50 [ACPI_FACS] = "FACS",
51 [ACPI_OEMX] = "OEM",
52 [ACPI_PSDT] = "PSDT",
53 [ACPI_SBST] = "SBST",
54 [ACPI_SLIT] = "SLIT",
55 [ACPI_SPCR] = "SPCR",
56 [ACPI_SRAT] = "SRAT",
57 [ACPI_SSDT] = "SSDT",
58 [ACPI_SPMI] = "SPMI",
59 [ACPI_HPET] = "HPET",
60 [ACPI_MCFG] = "MCFG",
61};
62
63static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" }; 41static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
64static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" }; 42static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
65 43
66/* System Description Table (RSDT/XSDT) */ 44static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata;
67struct acpi_table_sdt {
68 unsigned long pa;
69 enum acpi_table_id id;
70 unsigned long size;
71} __attribute__ ((packed));
72
73static unsigned long sdt_pa; /* Physical Address */
74static unsigned long sdt_count; /* Table count */
75 45
76static struct acpi_table_sdt sdt_entry[ACPI_MAX_TABLES] __initdata; 46void acpi_table_print_madt_entry(struct acpi_subtable_header * header)
77
78void acpi_table_print(struct acpi_table_header *header, unsigned long phys_addr)
79{
80 char *name = NULL;
81
82 if (!header)
83 return;
84
85 /* Some table signatures aren't good table names */
86
87 if (!strncmp((char *)&header->signature,
88 acpi_table_signatures[ACPI_APIC],
89 sizeof(header->signature))) {
90 name = "MADT";
91 } else if (!strncmp((char *)&header->signature,
92 acpi_table_signatures[ACPI_FADT],
93 sizeof(header->signature))) {
94 name = "FADT";
95 } else
96 name = header->signature;
97
98 printk(KERN_DEBUG PREFIX
99 "%.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n", name,
100 header->revision, header->oem_id, header->oem_table_id,
101 header->oem_revision, header->asl_compiler_id,
102 header->asl_compiler_revision, (void *)phys_addr);
103}
104
105void acpi_table_print_madt_entry(acpi_table_entry_header * header)
106{ 47{
107 if (!header) 48 if (!header)
108 return; 49 return;
109 50
110 switch (header->type) { 51 switch (header->type) {
111 52
112 case ACPI_MADT_LAPIC: 53 case ACPI_MADT_TYPE_LOCAL_APIC:
113 { 54 {
114 struct acpi_table_lapic *p = 55 struct acpi_madt_local_apic *p =
115 (struct acpi_table_lapic *)header; 56 (struct acpi_madt_local_apic *)header;
116 printk(KERN_INFO PREFIX 57 printk(KERN_INFO PREFIX
117 "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n", 58 "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
118 p->acpi_id, p->id, 59 p->processor_id, p->id,
119 p->flags.enabled ? "enabled" : "disabled"); 60 (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
120 } 61 }
121 break; 62 break;
122 63
123 case ACPI_MADT_IOAPIC: 64 case ACPI_MADT_TYPE_IO_APIC:
124 { 65 {
125 struct acpi_table_ioapic *p = 66 struct acpi_madt_io_apic *p =
126 (struct acpi_table_ioapic *)header; 67 (struct acpi_madt_io_apic *)header;
127 printk(KERN_INFO PREFIX 68 printk(KERN_INFO PREFIX
128 "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n", 69 "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
129 p->id, p->address, p->global_irq_base); 70 p->id, p->address, p->global_irq_base);
130 } 71 }
131 break; 72 break;
132 73
133 case ACPI_MADT_INT_SRC_OVR: 74 case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
134 { 75 {
135 struct acpi_table_int_src_ovr *p = 76 struct acpi_madt_interrupt_override *p =
136 (struct acpi_table_int_src_ovr *)header; 77 (struct acpi_madt_interrupt_override *)header;
137 printk(KERN_INFO PREFIX 78 printk(KERN_INFO PREFIX
138 "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n", 79 "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
139 p->bus, p->bus_irq, p->global_irq, 80 p->bus, p->source_irq, p->global_irq,
140 mps_inti_flags_polarity[p->flags.polarity], 81 mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
141 mps_inti_flags_trigger[p->flags.trigger]); 82 mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2]);
142 if (p->flags.reserved) 83 if (p->inti_flags &
84 ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK))
143 printk(KERN_INFO PREFIX 85 printk(KERN_INFO PREFIX
144 "INT_SRC_OVR unexpected reserved flags: 0x%x\n", 86 "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
145 p->flags.reserved); 87 p->inti_flags &
88 ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK));
146 89
147 } 90 }
148 break; 91 break;
149 92
150 case ACPI_MADT_NMI_SRC: 93 case ACPI_MADT_TYPE_NMI_SOURCE:
151 { 94 {
152 struct acpi_table_nmi_src *p = 95 struct acpi_madt_nmi_source *p =
153 (struct acpi_table_nmi_src *)header; 96 (struct acpi_madt_nmi_source *)header;
154 printk(KERN_INFO PREFIX 97 printk(KERN_INFO PREFIX
155 "NMI_SRC (%s %s global_irq %d)\n", 98 "NMI_SRC (%s %s global_irq %d)\n",
156 mps_inti_flags_polarity[p->flags.polarity], 99 mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
157 mps_inti_flags_trigger[p->flags.trigger], 100 mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
158 p->global_irq); 101 p->global_irq);
159 } 102 }
160 break; 103 break;
161 104
162 case ACPI_MADT_LAPIC_NMI: 105 case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
163 { 106 {
164 struct acpi_table_lapic_nmi *p = 107 struct acpi_madt_local_apic_nmi *p =
165 (struct acpi_table_lapic_nmi *)header; 108 (struct acpi_madt_local_apic_nmi *)header;
166 printk(KERN_INFO PREFIX 109 printk(KERN_INFO PREFIX
167 "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n", 110 "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
168 p->acpi_id, 111 p->processor_id,
169 mps_inti_flags_polarity[p->flags.polarity], 112 mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK ],
170 mps_inti_flags_trigger[p->flags.trigger], 113 mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
171 p->lint); 114 p->lint);
172 } 115 }
173 break; 116 break;
174 117
175 case ACPI_MADT_LAPIC_ADDR_OVR: 118 case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
176 { 119 {
177 struct acpi_table_lapic_addr_ovr *p = 120 struct acpi_madt_local_apic_override *p =
178 (struct acpi_table_lapic_addr_ovr *)header; 121 (struct acpi_madt_local_apic_override *)header;
179 printk(KERN_INFO PREFIX 122 printk(KERN_INFO PREFIX
180 "LAPIC_ADDR_OVR (address[%p])\n", 123 "LAPIC_ADDR_OVR (address[%p])\n",
181 (void *)(unsigned long)p->address); 124 (void *)(unsigned long)p->address);
182 } 125 }
183 break; 126 break;
184 127
185 case ACPI_MADT_IOSAPIC: 128 case ACPI_MADT_TYPE_IO_SAPIC:
186 { 129 {
187 struct acpi_table_iosapic *p = 130 struct acpi_madt_io_sapic *p =
188 (struct acpi_table_iosapic *)header; 131 (struct acpi_madt_io_sapic *)header;
189 printk(KERN_INFO PREFIX 132 printk(KERN_INFO PREFIX
190 "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n", 133 "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
191 p->id, (void *)(unsigned long)p->address, 134 p->id, (void *)(unsigned long)p->address,
@@ -193,26 +136,26 @@ void acpi_table_print_madt_entry(acpi_table_entry_header * header)
193 } 136 }
194 break; 137 break;
195 138
196 case ACPI_MADT_LSAPIC: 139 case ACPI_MADT_TYPE_LOCAL_SAPIC:
197 { 140 {
198 struct acpi_table_lsapic *p = 141 struct acpi_madt_local_sapic *p =
199 (struct acpi_table_lsapic *)header; 142 (struct acpi_madt_local_sapic *)header;
200 printk(KERN_INFO PREFIX 143 printk(KERN_INFO PREFIX
201 "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n", 144 "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
202 p->acpi_id, p->id, p->eid, 145 p->processor_id, p->id, p->eid,
203 p->flags.enabled ? "enabled" : "disabled"); 146 (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
204 } 147 }
205 break; 148 break;
206 149
207 case ACPI_MADT_PLAT_INT_SRC: 150 case ACPI_MADT_TYPE_INTERRUPT_SOURCE:
208 { 151 {
209 struct acpi_table_plat_int_src *p = 152 struct acpi_madt_interrupt_source *p =
210 (struct acpi_table_plat_int_src *)header; 153 (struct acpi_madt_interrupt_source *)header;
211 printk(KERN_INFO PREFIX 154 printk(KERN_INFO PREFIX
212 "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n", 155 "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
213 mps_inti_flags_polarity[p->flags.polarity], 156 mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
214 mps_inti_flags_trigger[p->flags.trigger], 157 mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
215 p->type, p->id, p->eid, p->iosapic_vector, 158 p->type, p->id, p->eid, p->io_sapic_vector,
216 p->global_irq); 159 p->global_irq);
217 } 160 }
218 break; 161 break;
@@ -225,342 +168,76 @@ void acpi_table_print_madt_entry(acpi_table_entry_header * header)
225 } 168 }
226} 169}
227 170
228static int
229acpi_table_compute_checksum(void *table_pointer, unsigned long length)
230{
231 u8 *p = (u8 *) table_pointer;
232 unsigned long remains = length;
233 unsigned long sum = 0;
234
235 if (!p || !length)
236 return -EINVAL;
237
238 while (remains--)
239 sum += *p++;
240
241 return (sum & 0xFF);
242}
243 171
244/*
245 * acpi_get_table_header_early()
246 * for acpi_blacklisted(), acpi_table_get_sdt()
247 */
248int __init 172int __init
249acpi_get_table_header_early(enum acpi_table_id id, 173acpi_table_parse_madt_family(char *id,
250 struct acpi_table_header **header)
251{
252 unsigned int i;
253 enum acpi_table_id temp_id;
254
255 /* DSDT is different from the rest */
256 if (id == ACPI_DSDT)
257 temp_id = ACPI_FADT;
258 else
259 temp_id = id;
260
261 /* Locate the table. */
262
263 for (i = 0; i < sdt_count; i++) {
264 if (sdt_entry[i].id != temp_id)
265 continue;
266 *header = (void *)
267 __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
268 if (!*header) {
269 printk(KERN_WARNING PREFIX "Unable to map %s\n",
270 acpi_table_signatures[temp_id]);
271 return -ENODEV;
272 }
273 break;
274 }
275
276 if (!*header) {
277 printk(KERN_WARNING PREFIX "%s not present\n",
278 acpi_table_signatures[id]);
279 return -ENODEV;
280 }
281
282 /* Map the DSDT header via the pointer in the FADT */
283 if (id == ACPI_DSDT) {
284 struct fadt_descriptor *fadt =
285 (struct fadt_descriptor *)*header;
286
287 if (fadt->revision == 3 && fadt->Xdsdt) {
288 *header = (void *)__acpi_map_table(fadt->Xdsdt,
289 sizeof(struct
290 acpi_table_header));
291 } else if (fadt->V1_dsdt) {
292 *header = (void *)__acpi_map_table(fadt->V1_dsdt,
293 sizeof(struct
294 acpi_table_header));
295 } else
296 *header = NULL;
297
298 if (!*header) {
299 printk(KERN_WARNING PREFIX "Unable to map DSDT\n");
300 return -ENODEV;
301 }
302 }
303
304 return 0;
305}
306
307int __init
308acpi_table_parse_madt_family(enum acpi_table_id id,
309 unsigned long madt_size, 174 unsigned long madt_size,
310 int entry_id, 175 int entry_id,
311 acpi_madt_entry_handler handler, 176 acpi_madt_entry_handler handler,
312 unsigned int max_entries) 177 unsigned int max_entries)
313{ 178{
314 void *madt = NULL; 179 struct acpi_table_header *madt = NULL;
315 acpi_table_entry_header *entry; 180 struct acpi_subtable_header *entry;
316 unsigned int count = 0; 181 unsigned int count = 0;
317 unsigned long madt_end; 182 unsigned long madt_end;
318 unsigned int i;
319 183
320 if (!handler) 184 if (!handler)
321 return -EINVAL; 185 return -EINVAL;
322 186
323 /* Locate the MADT (if exists). There should only be one. */ 187 /* Locate the MADT (if exists). There should only be one. */
324 188 acpi_get_table(id, 0, &madt);
325 for (i = 0; i < sdt_count; i++) {
326 if (sdt_entry[i].id != id)
327 continue;
328 madt = (void *)
329 __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
330 if (!madt) {
331 printk(KERN_WARNING PREFIX "Unable to map %s\n",
332 acpi_table_signatures[id]);
333 return -ENODEV;
334 }
335 break;
336 }
337 189
338 if (!madt) { 190 if (!madt) {
339 printk(KERN_WARNING PREFIX "%s not present\n", 191 printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
340 acpi_table_signatures[id]);
341 return -ENODEV; 192 return -ENODEV;
342 } 193 }
343 194
344 madt_end = (unsigned long)madt + sdt_entry[i].size; 195 madt_end = (unsigned long)madt + madt->length;
345 196
346 /* Parse all entries looking for a match. */ 197 /* Parse all entries looking for a match. */
347 198
348 entry = (acpi_table_entry_header *) 199 entry = (struct acpi_subtable_header *)
349 ((unsigned long)madt + madt_size); 200 ((unsigned long)madt + madt_size);
350 201
351 while (((unsigned long)entry) + sizeof(acpi_table_entry_header) < 202 while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
352 madt_end) { 203 madt_end) {
353 if (entry->type == entry_id 204 if (entry->type == entry_id
354 && (!max_entries || count++ < max_entries)) 205 && (!max_entries || count++ < max_entries))
355 if (handler(entry, madt_end)) 206 if (handler(entry, madt_end))
356 return -EINVAL; 207 return -EINVAL;
357 208
358 entry = (acpi_table_entry_header *) 209 entry = (struct acpi_subtable_header *)
359 ((unsigned long)entry + entry->length); 210 ((unsigned long)entry + entry->length);
360 } 211 }
361 if (max_entries && count > max_entries) { 212 if (max_entries && count > max_entries) {
362 printk(KERN_WARNING PREFIX "[%s:0x%02x] ignored %i entries of " 213 printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of "
363 "%i found\n", acpi_table_signatures[id], entry_id, 214 "%i found\n", id, entry_id, count - max_entries, count);
364 count - max_entries, count);
365 } 215 }
366 216
367 return count; 217 return count;
368} 218}
369 219
370int __init 220int __init
371acpi_table_parse_madt(enum acpi_madt_entry_id id, 221acpi_table_parse_madt(enum acpi_madt_type id,
372 acpi_madt_entry_handler handler, unsigned int max_entries) 222 acpi_madt_entry_handler handler, unsigned int max_entries)
373{ 223{
374 return acpi_table_parse_madt_family(ACPI_APIC, 224 return acpi_table_parse_madt_family(ACPI_SIG_MADT,
375 sizeof(struct acpi_table_madt), id, 225 sizeof(struct acpi_table_madt), id,
376 handler, max_entries); 226 handler, max_entries);
377} 227}
378 228
379int __init acpi_table_parse(enum acpi_table_id id, acpi_table_handler handler) 229int __init acpi_table_parse(char *id, acpi_table_handler handler)
380{ 230{
381 int count = 0; 231 struct acpi_table_header *table = NULL;
382 unsigned int i = 0;
383
384 if (!handler) 232 if (!handler)
385 return -EINVAL; 233 return -EINVAL;
386 234
387 for (i = 0; i < sdt_count; i++) { 235 acpi_get_table(id, 0, &table);
388 if (sdt_entry[i].id != id) 236 if (table) {
389 continue; 237 handler(table);
390 count++; 238 return 1;
391 if (count == 1) 239 } else
392 handler(sdt_entry[i].pa, sdt_entry[i].size); 240 return 0;
393
394 else
395 printk(KERN_WARNING PREFIX
396 "%d duplicate %s table ignored.\n", count,
397 acpi_table_signatures[id]);
398 }
399
400 return count;
401}
402
403static int __init acpi_table_get_sdt(struct acpi_table_rsdp *rsdp)
404{
405 struct acpi_table_header *header = NULL;
406 unsigned int i, id = 0;
407
408 if (!rsdp)
409 return -EINVAL;
410
411 /* First check XSDT (but only on ACPI 2.0-compatible systems) */
412
413 if ((rsdp->revision >= 2) &&
414 (((struct acpi20_table_rsdp *)rsdp)->xsdt_address)) {
415
416 struct acpi_table_xsdt *mapped_xsdt = NULL;
417
418 sdt_pa = ((struct acpi20_table_rsdp *)rsdp)->xsdt_address;
419
420 /* map in just the header */
421 header = (struct acpi_table_header *)
422 __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
423
424 if (!header) {
425 printk(KERN_WARNING PREFIX
426 "Unable to map XSDT header\n");
427 return -ENODEV;
428 }
429
430 /* remap in the entire table before processing */
431 mapped_xsdt = (struct acpi_table_xsdt *)
432 __acpi_map_table(sdt_pa, header->length);
433 if (!mapped_xsdt) {
434 printk(KERN_WARNING PREFIX "Unable to map XSDT\n");
435 return -ENODEV;
436 }
437 header = &mapped_xsdt->header;
438
439 if (strncmp(header->signature, "XSDT", 4)) {
440 printk(KERN_WARNING PREFIX
441 "XSDT signature incorrect\n");
442 return -ENODEV;
443 }
444
445 if (acpi_table_compute_checksum(header, header->length)) {
446 printk(KERN_WARNING PREFIX "Invalid XSDT checksum\n");
447 return -ENODEV;
448 }
449
450 sdt_count =
451 (header->length - sizeof(struct acpi_table_header)) >> 3;
452 if (sdt_count > ACPI_MAX_TABLES) {
453 printk(KERN_WARNING PREFIX
454 "Truncated %lu XSDT entries\n",
455 (sdt_count - ACPI_MAX_TABLES));
456 sdt_count = ACPI_MAX_TABLES;
457 }
458
459 for (i = 0; i < sdt_count; i++)
460 sdt_entry[i].pa = (unsigned long)mapped_xsdt->entry[i];
461 }
462
463 /* Then check RSDT */
464
465 else if (rsdp->rsdt_address) {
466
467 struct acpi_table_rsdt *mapped_rsdt = NULL;
468
469 sdt_pa = rsdp->rsdt_address;
470
471 /* map in just the header */
472 header = (struct acpi_table_header *)
473 __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
474 if (!header) {
475 printk(KERN_WARNING PREFIX
476 "Unable to map RSDT header\n");
477 return -ENODEV;
478 }
479
480 /* remap in the entire table before processing */
481 mapped_rsdt = (struct acpi_table_rsdt *)
482 __acpi_map_table(sdt_pa, header->length);
483 if (!mapped_rsdt) {
484 printk(KERN_WARNING PREFIX "Unable to map RSDT\n");
485 return -ENODEV;
486 }
487 header = &mapped_rsdt->header;
488
489 if (strncmp(header->signature, "RSDT", 4)) {
490 printk(KERN_WARNING PREFIX
491 "RSDT signature incorrect\n");
492 return -ENODEV;
493 }
494
495 if (acpi_table_compute_checksum(header, header->length)) {
496 printk(KERN_WARNING PREFIX "Invalid RSDT checksum\n");
497 return -ENODEV;
498 }
499
500 sdt_count =
501 (header->length - sizeof(struct acpi_table_header)) >> 2;
502 if (sdt_count > ACPI_MAX_TABLES) {
503 printk(KERN_WARNING PREFIX
504 "Truncated %lu RSDT entries\n",
505 (sdt_count - ACPI_MAX_TABLES));
506 sdt_count = ACPI_MAX_TABLES;
507 }
508
509 for (i = 0; i < sdt_count; i++)
510 sdt_entry[i].pa = (unsigned long)mapped_rsdt->entry[i];
511 }
512
513 else {
514 printk(KERN_WARNING PREFIX
515 "No System Description Table (RSDT/XSDT) specified in RSDP\n");
516 return -ENODEV;
517 }
518
519 acpi_table_print(header, sdt_pa);
520
521 for (i = 0; i < sdt_count; i++) {
522
523 /* map in just the header */
524 header = (struct acpi_table_header *)
525 __acpi_map_table(sdt_entry[i].pa,
526 sizeof(struct acpi_table_header));
527 if (!header)
528 continue;
529
530 /* remap in the entire table before processing */
531 header = (struct acpi_table_header *)
532 __acpi_map_table(sdt_entry[i].pa, header->length);
533 if (!header)
534 continue;
535
536 acpi_table_print(header, sdt_entry[i].pa);
537
538 if (acpi_table_compute_checksum(header, header->length)) {
539 printk(KERN_WARNING " >>> ERROR: Invalid checksum\n");
540 continue;
541 }
542
543 sdt_entry[i].size = header->length;
544
545 for (id = 0; id < ACPI_TABLE_COUNT; id++) {
546 if (!strncmp((char *)&header->signature,
547 acpi_table_signatures[id],
548 sizeof(header->signature))) {
549 sdt_entry[i].id = id;
550 }
551 }
552 }
553
554 /*
555 * The DSDT is *not* in the RSDT (why not? no idea.) but we want
556 * to print its info, because this is what people usually blacklist
557 * against. Unfortunately, we don't know the phys_addr, so just
558 * print 0. Maybe no one will notice.
559 */
560 if (!acpi_get_table_header_early(ACPI_DSDT, &header))
561 acpi_table_print(header, 0);
562
563 return 0;
564} 241}
565 242
566/* 243/*
@@ -568,54 +245,13 @@ static int __init acpi_table_get_sdt(struct acpi_table_rsdp *rsdp)
568 * 245 *
569 * find RSDP, find and checksum SDT/XSDT. 246 * find RSDP, find and checksum SDT/XSDT.
570 * checksum all tables, print SDT/XSDT 247 * checksum all tables, print SDT/XSDT
571 * 248 *
572 * result: sdt_entry[] is initialized 249 * result: sdt_entry[] is initialized
573 */ 250 */
574 251
252
575int __init acpi_table_init(void) 253int __init acpi_table_init(void)
576{ 254{
577 struct acpi_table_rsdp *rsdp = NULL; 255 acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
578 unsigned long rsdp_phys = 0;
579 int result = 0;
580
581 /* Locate and map the Root System Description Table (RSDP) */
582
583 rsdp_phys = acpi_find_rsdp();
584 if (!rsdp_phys) {
585 printk(KERN_ERR PREFIX "Unable to locate RSDP\n");
586 return -ENODEV;
587 }
588
589 rsdp = (struct acpi_table_rsdp *)__acpi_map_table(rsdp_phys,
590 sizeof(struct acpi_table_rsdp));
591 if (!rsdp) {
592 printk(KERN_WARNING PREFIX "Unable to map RSDP\n");
593 return -ENODEV;
594 }
595
596 printk(KERN_DEBUG PREFIX
597 "RSDP (v%3.3d %6.6s ) @ 0x%p\n",
598 rsdp->revision, rsdp->oem_id, (void *)rsdp_phys);
599
600 if (rsdp->revision < 2)
601 result =
602 acpi_table_compute_checksum(rsdp,
603 sizeof(struct acpi_table_rsdp));
604 else
605 result =
606 acpi_table_compute_checksum(rsdp,
607 ((struct acpi20_table_rsdp *)
608 rsdp)->length);
609
610 if (result) {
611 printk(KERN_WARNING " >>> ERROR: Invalid checksum\n");
612 return -ENODEV;
613 }
614
615 /* Locate and map the System Description table (RSDT/XSDT) */
616
617 if (acpi_table_get_sdt(rsdp))
618 return -ENODEV;
619
620 return 0; 256 return 0;
621} 257}
diff --git a/drivers/acpi/tables/Makefile b/drivers/acpi/tables/Makefile
index aa4c69594d..0a7d7afac2 100644
--- a/drivers/acpi/tables/Makefile
+++ b/drivers/acpi/tables/Makefile
@@ -2,7 +2,6 @@
2# Makefile for all Linux ACPI interpreter subdirectories 2# Makefile for all Linux ACPI interpreter subdirectories
3# 3#
4 4
5obj-y := tbconvrt.o tbget.o tbrsdt.o tbxface.o \ 5obj-y := tbxface.o tbinstal.o tbutils.o tbfind.o tbfadt.o
6 tbgetall.o tbinstal.o tbutils.o tbxfroot.o
7 6
8EXTRA_CFLAGS += $(ACPI_CFLAGS) 7EXTRA_CFLAGS += $(ACPI_CFLAGS)
diff --git a/drivers/acpi/tables/tbconvrt.c b/drivers/acpi/tables/tbconvrt.c
deleted file mode 100644
index d697fcb35d..0000000000
--- a/drivers/acpi/tables/tbconvrt.c
+++ /dev/null
@@ -1,622 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: tbconvrt - ACPI Table conversion utilities
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
47#define _COMPONENT ACPI_TABLES
48ACPI_MODULE_NAME("tbconvrt")
49
50/* Local prototypes */
51static void
52acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
53 u8 register_bit_width,
54 acpi_physical_address address);
55
56static void
57acpi_tb_convert_fadt1(struct fadt_descriptor *local_fadt,
58 struct fadt_descriptor_rev1 *original_fadt);
59
60static void
61acpi_tb_convert_fadt2(struct fadt_descriptor *local_fadt,
62 struct fadt_descriptor *original_fadt);
63
64u8 acpi_fadt_is_v1;
65ACPI_EXPORT_SYMBOL(acpi_fadt_is_v1)
66
67/*******************************************************************************
68 *
69 * FUNCTION: acpi_tb_get_table_count
70 *
71 * PARAMETERS: RSDP - Pointer to the RSDP
72 * RSDT - Pointer to the RSDT/XSDT
73 *
74 * RETURN: The number of tables pointed to by the RSDT or XSDT.
75 *
76 * DESCRIPTION: Calculate the number of tables. Automatically handles either
77 * an RSDT or XSDT.
78 *
79 ******************************************************************************/
80
81u32
82acpi_tb_get_table_count(struct rsdp_descriptor *RSDP,
83 struct acpi_table_header *RSDT)
84{
85 u32 pointer_size;
86
87 ACPI_FUNCTION_ENTRY();
88
89 /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */
90
91 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
92 pointer_size = sizeof(u32);
93 } else {
94 pointer_size = sizeof(u64);
95 }
96
97 /*
98 * Determine the number of tables pointed to by the RSDT/XSDT.
99 * This is defined by the ACPI Specification to be the number of
100 * pointers contained within the RSDT/XSDT. The size of the pointers
101 * is architecture-dependent.
102 */
103 return ((RSDT->length -
104 sizeof(struct acpi_table_header)) / pointer_size);
105}
106
107/*******************************************************************************
108 *
109 * FUNCTION: acpi_tb_convert_to_xsdt
110 *
111 * PARAMETERS: table_info - Info about the RSDT
112 *
113 * RETURN: Status
114 *
115 * DESCRIPTION: Convert an RSDT to an XSDT (internal common format)
116 *
117 ******************************************************************************/
118
119acpi_status acpi_tb_convert_to_xsdt(struct acpi_table_desc *table_info)
120{
121 acpi_size table_size;
122 u32 i;
123 struct xsdt_descriptor *new_table;
124
125 ACPI_FUNCTION_ENTRY();
126
127 /* Compute size of the converted XSDT */
128
129 table_size = ((acpi_size) acpi_gbl_rsdt_table_count * sizeof(u64)) +
130 sizeof(struct acpi_table_header);
131
132 /* Allocate an XSDT */
133
134 new_table = ACPI_ALLOCATE_ZEROED(table_size);
135 if (!new_table) {
136 return (AE_NO_MEMORY);
137 }
138
139 /* Copy the header and set the length */
140
141 ACPI_MEMCPY(new_table, table_info->pointer,
142 sizeof(struct acpi_table_header));
143 new_table->length = (u32) table_size;
144
145 /* Copy the table pointers */
146
147 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
148
149 /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */
150
151 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
152 ACPI_STORE_ADDRESS(new_table->table_offset_entry[i],
153 (ACPI_CAST_PTR
154 (struct rsdt_descriptor,
155 table_info->pointer))->
156 table_offset_entry[i]);
157 } else {
158 new_table->table_offset_entry[i] =
159 (ACPI_CAST_PTR(struct xsdt_descriptor,
160 table_info->pointer))->
161 table_offset_entry[i];
162 }
163 }
164
165 /* Delete the original table (either mapped or in a buffer) */
166
167 acpi_tb_delete_single_table(table_info);
168
169 /* Point the table descriptor to the new table */
170
171 table_info->pointer =
172 ACPI_CAST_PTR(struct acpi_table_header, new_table);
173 table_info->length = table_size;
174 table_info->allocation = ACPI_MEM_ALLOCATED;
175
176 return (AE_OK);
177}
178
179/*******************************************************************************
180 *
181 * FUNCTION: acpi_tb_init_generic_address
182 *
183 * PARAMETERS: new_gas_struct - GAS struct to be initialized
184 * register_bit_width - Width of this register
185 * Address - Address of the register
186 *
187 * RETURN: None
188 *
189 * DESCRIPTION: Initialize a GAS structure.
190 *
191 ******************************************************************************/
192
193static void
194acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
195 u8 register_bit_width,
196 acpi_physical_address address)
197{
198
199 ACPI_STORE_ADDRESS(new_gas_struct->address, address);
200
201 new_gas_struct->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO;
202 new_gas_struct->register_bit_width = register_bit_width;
203 new_gas_struct->register_bit_offset = 0;
204 new_gas_struct->access_width = 0;
205}
206
207/*******************************************************************************
208 *
209 * FUNCTION: acpi_tb_convert_fadt1
210 *
211 * PARAMETERS: local_fadt - Pointer to new FADT
212 * original_fadt - Pointer to old FADT
213 *
214 * RETURN: None, populates local_fadt
215 *
216 * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format
217 *
218 ******************************************************************************/
219
220static void
221acpi_tb_convert_fadt1(struct fadt_descriptor *local_fadt,
222 struct fadt_descriptor_rev1 *original_fadt)
223{
224
225 /* ACPI 1.0 FACS */
226 /* The BIOS stored FADT should agree with Revision 1.0 */
227 acpi_fadt_is_v1 = 1;
228
229 /*
230 * Copy the table header and the common part of the tables.
231 *
232 * The 2.0 table is an extension of the 1.0 table, so the entire 1.0
233 * table can be copied first, then expand some fields to 64 bits.
234 */
235 ACPI_MEMCPY(local_fadt, original_fadt,
236 sizeof(struct fadt_descriptor_rev1));
237
238 /* Convert table pointers to 64-bit fields */
239
240 ACPI_STORE_ADDRESS(local_fadt->xfirmware_ctrl,
241 local_fadt->V1_firmware_ctrl);
242 ACPI_STORE_ADDRESS(local_fadt->Xdsdt, local_fadt->V1_dsdt);
243
244 /*
245 * System Interrupt Model isn't used in ACPI 2.0
246 * (local_fadt->Reserved1 = 0;)
247 */
248
249 /*
250 * This field is set by the OEM to convey the preferred power management
251 * profile to OSPM. It doesn't have any 1.0 equivalence. Since we don't
252 * know what kind of 32-bit system this is, we will use "unspecified".
253 */
254 local_fadt->prefer_PM_profile = PM_UNSPECIFIED;
255
256 /*
257 * Processor Performance State Control. This is the value OSPM writes to
258 * the SMI_CMD register to assume processor performance state control
259 * responsibility. There isn't any equivalence in 1.0, but as many 1.x
260 * ACPI tables contain _PCT and _PSS we also keep this value, unless
261 * acpi_strict is set.
262 */
263 if (acpi_strict)
264 local_fadt->pstate_cnt = 0;
265
266 /*
267 * Support for the _CST object and C States change notification.
268 * This data item hasn't any 1.0 equivalence so leave it zero.
269 */
270 local_fadt->cst_cnt = 0;
271
272 /*
273 * FADT Rev 2 was an interim FADT released between ACPI 1.0 and ACPI 2.0.
274 * It primarily adds the FADT reset mechanism.
275 */
276 if ((original_fadt->revision == 2) &&
277 (original_fadt->length ==
278 sizeof(struct fadt_descriptor_rev2_minus))) {
279 /*
280 * Grab the entire generic address struct, plus the 1-byte reset value
281 * that immediately follows.
282 */
283 ACPI_MEMCPY(&local_fadt->reset_register,
284 &(ACPI_CAST_PTR(struct fadt_descriptor_rev2_minus,
285 original_fadt))->reset_register,
286 sizeof(struct acpi_generic_address) + 1);
287 } else {
288 /*
289 * Since there isn't any equivalence in 1.0 and since it is highly
290 * likely that a 1.0 system has legacy support.
291 */
292 local_fadt->iapc_boot_arch = BAF_LEGACY_DEVICES;
293 }
294
295 /*
296 * Convert the V1.0 block addresses to V2.0 GAS structures
297 */
298 acpi_tb_init_generic_address(&local_fadt->xpm1a_evt_blk,
299 local_fadt->pm1_evt_len,
300 (acpi_physical_address) local_fadt->
301 V1_pm1a_evt_blk);
302 acpi_tb_init_generic_address(&local_fadt->xpm1b_evt_blk,
303 local_fadt->pm1_evt_len,
304 (acpi_physical_address) local_fadt->
305 V1_pm1b_evt_blk);
306 acpi_tb_init_generic_address(&local_fadt->xpm1a_cnt_blk,
307 local_fadt->pm1_cnt_len,
308 (acpi_physical_address) local_fadt->
309 V1_pm1a_cnt_blk);
310 acpi_tb_init_generic_address(&local_fadt->xpm1b_cnt_blk,
311 local_fadt->pm1_cnt_len,
312 (acpi_physical_address) local_fadt->
313 V1_pm1b_cnt_blk);
314 acpi_tb_init_generic_address(&local_fadt->xpm2_cnt_blk,
315 local_fadt->pm2_cnt_len,
316 (acpi_physical_address) local_fadt->
317 V1_pm2_cnt_blk);
318 acpi_tb_init_generic_address(&local_fadt->xpm_tmr_blk,
319 local_fadt->pm_tm_len,
320 (acpi_physical_address) local_fadt->
321 V1_pm_tmr_blk);
322 acpi_tb_init_generic_address(&local_fadt->xgpe0_blk, 0,
323 (acpi_physical_address) local_fadt->
324 V1_gpe0_blk);
325 acpi_tb_init_generic_address(&local_fadt->xgpe1_blk, 0,
326 (acpi_physical_address) local_fadt->
327 V1_gpe1_blk);
328
329 /* Create separate GAS structs for the PM1 Enable registers */
330
331 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
332 (u8) ACPI_DIV_2(acpi_gbl_FADT->
333 pm1_evt_len),
334 (acpi_physical_address)
335 (local_fadt->xpm1a_evt_blk.address +
336 ACPI_DIV_2(acpi_gbl_FADT->pm1_evt_len)));
337
338 /* PM1B is optional; leave null if not present */
339
340 if (local_fadt->xpm1b_evt_blk.address) {
341 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
342 (u8) ACPI_DIV_2(acpi_gbl_FADT->
343 pm1_evt_len),
344 (acpi_physical_address)
345 (local_fadt->xpm1b_evt_blk.
346 address +
347 ACPI_DIV_2(acpi_gbl_FADT->
348 pm1_evt_len)));
349 }
350}
351
352/*******************************************************************************
353 *
354 * FUNCTION: acpi_tb_convert_fadt2
355 *
356 * PARAMETERS: local_fadt - Pointer to new FADT
357 * original_fadt - Pointer to old FADT
358 *
359 * RETURN: None, populates local_fadt
360 *
361 * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format.
362 * Handles optional "X" fields.
363 *
364 ******************************************************************************/
365
366static void
367acpi_tb_convert_fadt2(struct fadt_descriptor *local_fadt,
368 struct fadt_descriptor *original_fadt)
369{
370
371 /* We have an ACPI 2.0 FADT but we must copy it to our local buffer */
372
373 ACPI_MEMCPY(local_fadt, original_fadt, sizeof(struct fadt_descriptor));
374
375 /*
376 * "X" fields are optional extensions to the original V1.0 fields, so
377 * we must selectively expand V1.0 fields if the corresponding X field
378 * is zero.
379 */
380 if (!(local_fadt->xfirmware_ctrl)) {
381 ACPI_STORE_ADDRESS(local_fadt->xfirmware_ctrl,
382 local_fadt->V1_firmware_ctrl);
383 }
384
385 if (!(local_fadt->Xdsdt)) {
386 ACPI_STORE_ADDRESS(local_fadt->Xdsdt, local_fadt->V1_dsdt);
387 }
388
389 if (!(local_fadt->xpm1a_evt_blk.address)) {
390 acpi_tb_init_generic_address(&local_fadt->xpm1a_evt_blk,
391 local_fadt->pm1_evt_len,
392 (acpi_physical_address)
393 local_fadt->V1_pm1a_evt_blk);
394 }
395
396 if (!(local_fadt->xpm1b_evt_blk.address)) {
397 acpi_tb_init_generic_address(&local_fadt->xpm1b_evt_blk,
398 local_fadt->pm1_evt_len,
399 (acpi_physical_address)
400 local_fadt->V1_pm1b_evt_blk);
401 }
402
403 if (!(local_fadt->xpm1a_cnt_blk.address)) {
404 acpi_tb_init_generic_address(&local_fadt->xpm1a_cnt_blk,
405 local_fadt->pm1_cnt_len,
406 (acpi_physical_address)
407 local_fadt->V1_pm1a_cnt_blk);
408 }
409
410 if (!(local_fadt->xpm1b_cnt_blk.address)) {
411 acpi_tb_init_generic_address(&local_fadt->xpm1b_cnt_blk,
412 local_fadt->pm1_cnt_len,
413 (acpi_physical_address)
414 local_fadt->V1_pm1b_cnt_blk);
415 }
416
417 if (!(local_fadt->xpm2_cnt_blk.address)) {
418 acpi_tb_init_generic_address(&local_fadt->xpm2_cnt_blk,
419 local_fadt->pm2_cnt_len,
420 (acpi_physical_address)
421 local_fadt->V1_pm2_cnt_blk);
422 }
423
424 if (!(local_fadt->xpm_tmr_blk.address)) {
425 acpi_tb_init_generic_address(&local_fadt->xpm_tmr_blk,
426 local_fadt->pm_tm_len,
427 (acpi_physical_address)
428 local_fadt->V1_pm_tmr_blk);
429 }
430
431 if (!(local_fadt->xgpe0_blk.address)) {
432 acpi_tb_init_generic_address(&local_fadt->xgpe0_blk,
433 0,
434 (acpi_physical_address)
435 local_fadt->V1_gpe0_blk);
436 }
437
438 if (!(local_fadt->xgpe1_blk.address)) {
439 acpi_tb_init_generic_address(&local_fadt->xgpe1_blk,
440 0,
441 (acpi_physical_address)
442 local_fadt->V1_gpe1_blk);
443 }
444
445 /* Create separate GAS structs for the PM1 Enable registers */
446
447 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
448 (u8) ACPI_DIV_2(acpi_gbl_FADT->
449 pm1_evt_len),
450 (acpi_physical_address)
451 (local_fadt->xpm1a_evt_blk.address +
452 ACPI_DIV_2(acpi_gbl_FADT->pm1_evt_len)));
453
454 acpi_gbl_xpm1a_enable.address_space_id =
455 local_fadt->xpm1a_evt_blk.address_space_id;
456
457 /* PM1B is optional; leave null if not present */
458
459 if (local_fadt->xpm1b_evt_blk.address) {
460 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
461 (u8) ACPI_DIV_2(acpi_gbl_FADT->
462 pm1_evt_len),
463 (acpi_physical_address)
464 (local_fadt->xpm1b_evt_blk.
465 address +
466 ACPI_DIV_2(acpi_gbl_FADT->
467 pm1_evt_len)));
468
469 acpi_gbl_xpm1b_enable.address_space_id =
470 local_fadt->xpm1b_evt_blk.address_space_id;
471 }
472}
473
474/*******************************************************************************
475 *
476 * FUNCTION: acpi_tb_convert_table_fadt
477 *
478 * PARAMETERS: None
479 *
480 * RETURN: Status
481 *
482 * DESCRIPTION: Converts a BIOS supplied ACPI 1.0 FADT to a local
483 * ACPI 2.0 FADT. If the BIOS supplied a 2.0 FADT then it is simply
484 * copied to the local FADT. The ACPI CA software uses this
485 * local FADT. Thus a significant amount of special #ifdef
486 * type codeing is saved.
487 *
488 ******************************************************************************/
489
490acpi_status acpi_tb_convert_table_fadt(void)
491{
492 struct fadt_descriptor *local_fadt;
493 struct acpi_table_desc *table_desc;
494
495 ACPI_FUNCTION_TRACE(tb_convert_table_fadt);
496
497 /*
498 * acpi_gbl_FADT is valid. Validate the FADT length. The table must be
499 * at least as long as the version 1.0 FADT
500 */
501 if (acpi_gbl_FADT->length < sizeof(struct fadt_descriptor_rev1)) {
502 ACPI_ERROR((AE_INFO, "FADT is invalid, too short: 0x%X",
503 acpi_gbl_FADT->length));
504 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
505 }
506
507 /* Allocate buffer for the ACPI 2.0(+) FADT */
508
509 local_fadt = ACPI_ALLOCATE_ZEROED(sizeof(struct fadt_descriptor));
510 if (!local_fadt) {
511 return_ACPI_STATUS(AE_NO_MEMORY);
512 }
513
514 if (acpi_gbl_FADT->revision >= FADT2_REVISION_ID) {
515 if (acpi_gbl_FADT->length < sizeof(struct fadt_descriptor)) {
516
517 /* Length is too short to be a V2.0 table */
518
519 ACPI_WARNING((AE_INFO,
520 "Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table",
521 acpi_gbl_FADT->length,
522 acpi_gbl_FADT->revision));
523
524 acpi_tb_convert_fadt1(local_fadt,
525 (void *)acpi_gbl_FADT);
526 } else {
527 /* Valid V2.0 table */
528
529 acpi_tb_convert_fadt2(local_fadt, acpi_gbl_FADT);
530 }
531 } else {
532 /* Valid V1.0 table */
533
534 acpi_tb_convert_fadt1(local_fadt, (void *)acpi_gbl_FADT);
535 }
536
537 /* Global FADT pointer will point to the new common V2.0 FADT */
538
539 acpi_gbl_FADT = local_fadt;
540 acpi_gbl_FADT->length = sizeof(struct fadt_descriptor);
541
542 /* Free the original table */
543
544 table_desc = acpi_gbl_table_lists[ACPI_TABLE_ID_FADT].next;
545 acpi_tb_delete_single_table(table_desc);
546
547 /* Install the new table */
548
549 table_desc->pointer =
550 ACPI_CAST_PTR(struct acpi_table_header, acpi_gbl_FADT);
551 table_desc->allocation = ACPI_MEM_ALLOCATED;
552 table_desc->length = sizeof(struct fadt_descriptor);
553
554 /* Dump the entire FADT */
555
556 ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
557 "Hex dump of common internal FADT, size %d (%X)\n",
558 acpi_gbl_FADT->length, acpi_gbl_FADT->length));
559
560 ACPI_DUMP_BUFFER(ACPI_CAST_PTR(u8, acpi_gbl_FADT),
561 acpi_gbl_FADT->length);
562
563 return_ACPI_STATUS(AE_OK);
564}
565
566/*******************************************************************************
567 *
568 * FUNCTION: acpi_tb_build_common_facs
569 *
570 * PARAMETERS: table_info - Info for currently installed FACS
571 *
572 * RETURN: Status
573 *
574 * DESCRIPTION: Convert ACPI 1.0 and ACPI 2.0 FACS to a common internal
575 * table format.
576 *
577 ******************************************************************************/
578
579acpi_status acpi_tb_build_common_facs(struct acpi_table_desc *table_info)
580{
581
582 ACPI_FUNCTION_TRACE(tb_build_common_facs);
583
584 /* Absolute minimum length is 24, but the ACPI spec says 64 */
585
586 if (acpi_gbl_FACS->length < 24) {
587 ACPI_ERROR((AE_INFO, "Invalid FACS table length: 0x%X",
588 acpi_gbl_FACS->length));
589 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
590 }
591
592 if (acpi_gbl_FACS->length < 64) {
593 ACPI_WARNING((AE_INFO,
594 "FACS is shorter than the ACPI specification allows: 0x%X, using anyway",
595 acpi_gbl_FACS->length));
596 }
597
598 /* Copy fields to the new FACS */
599
600 acpi_gbl_common_fACS.global_lock = &(acpi_gbl_FACS->global_lock);
601
602 if ((acpi_gbl_RSDP->revision < 2) ||
603 (acpi_gbl_FACS->length < 32) ||
604 (!(acpi_gbl_FACS->xfirmware_waking_vector))) {
605
606 /* ACPI 1.0 FACS or short table or optional X_ field is zero */
607
608 acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR(u64,
609 &
610 (acpi_gbl_FACS->
611 firmware_waking_vector));
612 acpi_gbl_common_fACS.vector_width = 32;
613 } else {
614 /* ACPI 2.0 FACS with valid X_ field */
615
616 acpi_gbl_common_fACS.firmware_waking_vector =
617 &acpi_gbl_FACS->xfirmware_waking_vector;
618 acpi_gbl_common_fACS.vector_width = 64;
619 }
620
621 return_ACPI_STATUS(AE_OK);
622}
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c
new file mode 100644
index 0000000000..807c7116e9
--- /dev/null
+++ b/drivers/acpi/tables/tbfadt.c
@@ -0,0 +1,434 @@
1/******************************************************************************
2 *
3 * Module Name: tbfadt - FADT table utilities
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
47#define _COMPONENT ACPI_TABLES
48ACPI_MODULE_NAME("tbfadt")
49
50/* Local prototypes */
51static void inline
52acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
53 u8 bit_width, u64 address);
54
55static void acpi_tb_convert_fadt(void);
56
57static void acpi_tb_validate_fadt(void);
58
59/* Table for conversion of FADT to common internal format and FADT validation */
60
61typedef struct acpi_fadt_info {
62 char *name;
63 u8 target;
64 u8 source;
65 u8 length;
66 u8 type;
67
68} acpi_fadt_info;
69
70#define ACPI_FADT_REQUIRED 1
71#define ACPI_FADT_SEPARATE_LENGTH 2
72
73static struct acpi_fadt_info fadt_info_table[] = {
74 {"Pm1aEventBlock", ACPI_FADT_OFFSET(xpm1a_event_block),
75 ACPI_FADT_OFFSET(pm1a_event_block),
76 ACPI_FADT_OFFSET(pm1_event_length), ACPI_FADT_REQUIRED},
77
78 {"Pm1bEventBlock", ACPI_FADT_OFFSET(xpm1b_event_block),
79 ACPI_FADT_OFFSET(pm1b_event_block),
80 ACPI_FADT_OFFSET(pm1_event_length), 0},
81
82 {"Pm1aControlBlock", ACPI_FADT_OFFSET(xpm1a_control_block),
83 ACPI_FADT_OFFSET(pm1a_control_block),
84 ACPI_FADT_OFFSET(pm1_control_length), ACPI_FADT_REQUIRED},
85
86 {"Pm1bControlBlock", ACPI_FADT_OFFSET(xpm1b_control_block),
87 ACPI_FADT_OFFSET(pm1b_control_block),
88 ACPI_FADT_OFFSET(pm1_control_length), 0},
89
90 {"Pm2ControlBlock", ACPI_FADT_OFFSET(xpm2_control_block),
91 ACPI_FADT_OFFSET(pm2_control_block),
92 ACPI_FADT_OFFSET(pm2_control_length), ACPI_FADT_SEPARATE_LENGTH},
93
94 {"PmTimerBlock", ACPI_FADT_OFFSET(xpm_timer_block),
95 ACPI_FADT_OFFSET(pm_timer_block),
96 ACPI_FADT_OFFSET(pm_timer_length), ACPI_FADT_REQUIRED},
97
98 {"Gpe0Block", ACPI_FADT_OFFSET(xgpe0_block),
99 ACPI_FADT_OFFSET(gpe0_block),
100 ACPI_FADT_OFFSET(gpe0_block_length), ACPI_FADT_SEPARATE_LENGTH},
101
102 {"Gpe1Block", ACPI_FADT_OFFSET(xgpe1_block),
103 ACPI_FADT_OFFSET(gpe1_block),
104 ACPI_FADT_OFFSET(gpe1_block_length), ACPI_FADT_SEPARATE_LENGTH}
105};
106
107#define ACPI_FADT_INFO_ENTRIES (sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info))
108
109/*******************************************************************************
110 *
111 * FUNCTION: acpi_tb_init_generic_address
112 *
113 * PARAMETERS: generic_address - GAS struct to be initialized
114 * bit_width - Width of this register
115 * Address - Address of the register
116 *
117 * RETURN: None
118 *
119 * DESCRIPTION: Initialize a Generic Address Structure (GAS)
120 * See the ACPI specification for a full description and
121 * definition of this structure.
122 *
123 ******************************************************************************/
124
125static void inline
126acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
127 u8 bit_width, u64 address)
128{
129
130 /*
131 * The 64-bit Address field is non-aligned in the byte packed
132 * GAS struct.
133 */
134 ACPI_MOVE_64_TO_64(&generic_address->address, &address);
135
136 /* All other fields are byte-wide */
137
138 generic_address->space_id = ACPI_ADR_SPACE_SYSTEM_IO;
139 generic_address->bit_width = bit_width;
140 generic_address->bit_offset = 0;
141 generic_address->access_width = 0;
142}
143
144/*******************************************************************************
145 *
146 * FUNCTION: acpi_tb_parse_fadt
147 *
148 * PARAMETERS: table_index - Index for the FADT
149 * Flags - Flags
150 *
151 * RETURN: None
152 *
153 * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
154 * (FADT contains the addresses of the DSDT and FACS)
155 *
156 ******************************************************************************/
157
158void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags)
159{
160 u32 length;
161 struct acpi_table_header *table;
162
163 /*
164 * The FADT has multiple versions with different lengths,
165 * and it contains pointers to both the DSDT and FACS tables.
166 *
167 * Get a local copy of the FADT and convert it to a common format
168 * Map entire FADT, assumed to be smaller than one page.
169 */
170 length = acpi_gbl_root_table_list.tables[table_index].length;
171
172 table =
173 acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
174 address, length);
175 if (!table) {
176 return;
177 }
178
179 /*
180 * Validate the FADT checksum before we copy the table. Ignore
181 * checksum error as we want to try to get the DSDT and FACS.
182 */
183 (void)acpi_tb_verify_checksum(table, length);
184
185 /* Obtain a local copy of the FADT in common ACPI 2.0+ format */
186
187 acpi_tb_create_local_fadt(table, length);
188
189 /* All done with the real FADT, unmap it */
190
191 acpi_os_unmap_memory(table, length);
192
193 /* Obtain the DSDT and FACS tables via their addresses within the FADT */
194
195 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
196 flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
197
198 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs,
199 flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
200}
201
202/*******************************************************************************
203 *
204 * FUNCTION: acpi_tb_create_local_fadt
205 *
206 * PARAMETERS: Table - Pointer to BIOS FADT
207 * Length - Length of the table
208 *
209 * RETURN: None
210 *
211 * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
212 * Performs validation on some important FADT fields.
213 *
214 ******************************************************************************/
215
216void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
217{
218
219 /*
220 * Check if the FADT is larger than what we know about (ACPI 2.0 version).
221 * Truncate the table, but make some noise.
222 */
223 if (length > sizeof(struct acpi_table_fadt)) {
224 ACPI_WARNING((AE_INFO,
225 "FADT (revision %u) is longer than ACPI 2.0 version, truncating length 0x%X to 0x%zX",
226 table->revision, (unsigned)length,
227 sizeof(struct acpi_table_fadt)));
228 }
229
230 /* Copy the entire FADT locally. Zero first for tb_convert_fadt */
231
232 ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
233
234 ACPI_MEMCPY(&acpi_gbl_FADT, table,
235 ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
236
237 /*
238 * 1) Convert the local copy of the FADT to the common internal format
239 * 2) Validate some of the important values within the FADT
240 */
241 acpi_tb_convert_fadt();
242 acpi_tb_validate_fadt();
243}
244
245/*******************************************************************************
246 *
247 * FUNCTION: acpi_tb_convert_fadt
248 *
249 * PARAMETERS: None, uses acpi_gbl_FADT
250 *
251 * RETURN: None
252 *
253 * DESCRIPTION: Converts all versions of the FADT to a common internal format.
254 * -> Expand all 32-bit addresses to 64-bit.
255 *
256 * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt),
257 * and must contain a copy of the actual FADT.
258 *
259 * ACPICA will use the "X" fields of the FADT for all addresses.
260 *
261 * "X" fields are optional extensions to the original V1.0 fields. Even if
262 * they are present in the structure, they can be optionally not used by
263 * setting them to zero. Therefore, we must selectively expand V1.0 fields
264 * if the corresponding X field is zero.
265 *
266 * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding
267 * "X" fields.
268 *
269 * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by
270 * expanding the corresponding ACPI 1.0 field.
271 *
272 ******************************************************************************/
273
274static void acpi_tb_convert_fadt(void)
275{
276 u8 pm1_register_length;
277 struct acpi_generic_address *target;
278 acpi_native_uint i;
279
280 /* Update the local FADT table header length */
281
282 acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
283
284 /* Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary */
285
286 if (!acpi_gbl_FADT.Xfacs) {
287 acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
288 }
289
290 if (!acpi_gbl_FADT.Xdsdt) {
291 acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
292 }
293
294 /*
295 * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address
296 * structures as necessary.
297 */
298 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
299 target =
300 ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
301 fadt_info_table[i].target);
302
303 /* Expand only if the X target is null */
304
305 if (!target->address) {
306 acpi_tb_init_generic_address(target,
307 *ACPI_ADD_PTR(u8,
308 &acpi_gbl_FADT,
309 fadt_info_table
310 [i].length),
311 (u64) * ACPI_ADD_PTR(u32,
312 &acpi_gbl_FADT,
313 fadt_info_table
314 [i].
315 source));
316 }
317 }
318
319 /*
320 * Calculate separate GAS structs for the PM1 Enable registers.
321 * These addresses do not appear (directly) in the FADT, so it is
322 * useful to calculate them once, here.
323 *
324 * The PM event blocks are split into two register blocks, first is the
325 * PM Status Register block, followed immediately by the PM Enable Register
326 * block. Each is of length (pm1_event_length/2)
327 */
328 pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
329
330 /* The PM1A register block is required */
331
332 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
333 pm1_register_length,
334 (acpi_gbl_FADT.xpm1a_event_block.address +
335 pm1_register_length));
336 /* Don't forget to copy space_id of the GAS */
337 acpi_gbl_xpm1a_enable.space_id = acpi_gbl_FADT.xpm1a_event_block.space_id;
338
339 /* The PM1B register block is optional, ignore if not present */
340
341 if (acpi_gbl_FADT.xpm1b_event_block.address) {
342 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
343 pm1_register_length,
344 (acpi_gbl_FADT.xpm1b_event_block.
345 address + pm1_register_length));
346 /* Don't forget to copy space_id of the GAS */
347 acpi_gbl_xpm1b_enable.space_id = acpi_gbl_FADT.xpm1a_event_block.space_id;
348
349 }
350}
351
352/******************************************************************************
353 *
354 * FUNCTION: acpi_tb_validate_fadt
355 *
356 * PARAMETERS: Table - Pointer to the FADT to be validated
357 *
358 * RETURN: None
359 *
360 * DESCRIPTION: Validate various important fields within the FADT. If a problem
361 * is found, issue a message, but no status is returned.
362 * Used by both the table manager and the disassembler.
363 *
364 * Possible additional checks:
365 * (acpi_gbl_FADT.pm1_event_length >= 4)
366 * (acpi_gbl_FADT.pm1_control_length >= 2)
367 * (acpi_gbl_FADT.pm_timer_length >= 4)
368 * Gpe block lengths must be multiple of 2
369 *
370 ******************************************************************************/
371
372static void acpi_tb_validate_fadt(void)
373{
374 u32 *address32;
375 struct acpi_generic_address *address64;
376 u8 length;
377 acpi_native_uint i;
378
379 /* Examine all of the 64-bit extended address fields (X fields) */
380
381 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
382
383 /* Generate pointers to the 32-bit and 64-bit addresses and get the length */
384
385 address64 =
386 ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
387 fadt_info_table[i].target);
388 address32 =
389 ACPI_ADD_PTR(u32, &acpi_gbl_FADT,
390 fadt_info_table[i].source);
391 length =
392 *ACPI_ADD_PTR(u8, &acpi_gbl_FADT,
393 fadt_info_table[i].length);
394
395 if (fadt_info_table[i].type & ACPI_FADT_REQUIRED) {
396 /*
397 * Field is required (Pm1a_event, Pm1a_control, pm_timer).
398 * Both the address and length must be non-zero.
399 */
400 if (!address64->address || !length) {
401 ACPI_ERROR((AE_INFO,
402 "Required field \"%s\" has zero address and/or length: %8.8X%8.8X/%X",
403 fadt_info_table[i].name,
404 ACPI_FORMAT_UINT64(address64->
405 address),
406 length));
407 }
408 } else if (fadt_info_table[i].type & ACPI_FADT_SEPARATE_LENGTH) {
409 /*
410 * Field is optional (PM2Control, GPE0, GPE1) AND has its own
411 * length field. If present, both the address and length must be valid.
412 */
413 if ((address64->address && !length)
414 || (!address64->address && length)) {
415 ACPI_WARNING((AE_INFO,
416 "Optional field \"%s\" has zero address or length: %8.8X%8.8X/%X",
417 fadt_info_table[i].name,
418 ACPI_FORMAT_UINT64(address64->
419 address),
420 length));
421 }
422 }
423
424 /* If both 32- and 64-bit addresses are valid (non-zero), they must match */
425
426 if (address64->address && *address32 &&
427 (address64->address != (u64) * address32)) {
428 ACPI_ERROR((AE_INFO,
429 "32/64X address mismatch in \"%s\": [%8.8X] [%8.8X%8.8X], using 64X",
430 fadt_info_table[i].name, *address32,
431 ACPI_FORMAT_UINT64(address64->address)));
432 }
433 }
434}
diff --git a/drivers/acpi/tables/tbfind.c b/drivers/acpi/tables/tbfind.c
new file mode 100644
index 0000000000..058c064948
--- /dev/null
+++ b/drivers/acpi/tables/tbfind.c
@@ -0,0 +1,126 @@
1/******************************************************************************
2 *
3 * Module Name: tbfind - find table
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
47#define _COMPONENT ACPI_TABLES
48ACPI_MODULE_NAME("tbfind")
49
50/*******************************************************************************
51 *
52 * FUNCTION: acpi_tb_find_table
53 *
54 * PARAMETERS: Signature - String with ACPI table signature
55 * oem_id - String with the table OEM ID
56 * oem_table_id - String with the OEM Table ID
57 * table_index - Where the table index is returned
58 *
59 * RETURN: Status and table index
60 *
61 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
62 * Signature, OEM ID and OEM Table ID. Returns an index that can
63 * be used to get the table header or entire table.
64 *
65 ******************************************************************************/
66acpi_status
67acpi_tb_find_table(char *signature,
68 char *oem_id,
69 char *oem_table_id, acpi_native_uint * table_index)
70{
71 acpi_native_uint i;
72 acpi_status status;
73
74 ACPI_FUNCTION_TRACE(tb_find_table);
75
76 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
77 if (ACPI_MEMCMP(&(acpi_gbl_root_table_list.tables[i].signature),
78 signature, ACPI_NAME_SIZE)) {
79
80 /* Not the requested table */
81
82 continue;
83 }
84
85 /* Table with matching signature has been found */
86
87 if (!acpi_gbl_root_table_list.tables[i].pointer) {
88
89 /* Table is not currently mapped, map it */
90
91 status =
92 acpi_tb_verify_table(&acpi_gbl_root_table_list.
93 tables[i]);
94 if (ACPI_FAILURE(status)) {
95 return_ACPI_STATUS(status);
96 }
97
98 if (!acpi_gbl_root_table_list.tables[i].pointer) {
99 continue;
100 }
101 }
102
103 /* Check for table match on all IDs */
104
105 if (!ACPI_MEMCMP
106 (acpi_gbl_root_table_list.tables[i].pointer->signature,
107 signature, ACPI_NAME_SIZE) && (!oem_id[0]
108 ||
109 !ACPI_MEMCMP
110 (acpi_gbl_root_table_list.
111 tables[i].pointer->oem_id,
112 oem_id, ACPI_OEM_ID_SIZE))
113 && (!oem_table_id[0]
114 || !ACPI_MEMCMP(acpi_gbl_root_table_list.tables[i].
115 pointer->oem_table_id, oem_table_id,
116 ACPI_OEM_TABLE_ID_SIZE))) {
117 *table_index = i;
118
119 ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
120 "Found table [%4.4s]\n", signature));
121 return_ACPI_STATUS(AE_OK);
122 }
123 }
124
125 return_ACPI_STATUS(AE_NOT_FOUND);
126}
diff --git a/drivers/acpi/tables/tbget.c b/drivers/acpi/tables/tbget.c
deleted file mode 100644
index 11e2d4454e..0000000000
--- a/drivers/acpi/tables/tbget.c
+++ /dev/null
@@ -1,471 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: tbget - ACPI Table get* routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
47#define _COMPONENT ACPI_TABLES
48ACPI_MODULE_NAME("tbget")
49
50/* Local prototypes */
51static acpi_status
52acpi_tb_get_this_table(struct acpi_pointer *address,
53 struct acpi_table_header *header,
54 struct acpi_table_desc *table_info);
55
56static acpi_status
57acpi_tb_table_override(struct acpi_table_header *header,
58 struct acpi_table_desc *table_info);
59
60/*******************************************************************************
61 *
62 * FUNCTION: acpi_tb_get_table
63 *
64 * PARAMETERS: Address - Address of table to retrieve. Can be
65 * Logical or Physical
66 * table_info - Where table info is returned
67 *
68 * RETURN: None
69 *
70 * DESCRIPTION: Get entire table of unknown size.
71 *
72 ******************************************************************************/
73
74acpi_status
75acpi_tb_get_table(struct acpi_pointer *address,
76 struct acpi_table_desc *table_info)
77{
78 acpi_status status;
79 struct acpi_table_header header;
80
81 ACPI_FUNCTION_TRACE(tb_get_table);
82
83 /* Get the header in order to get signature and table size */
84
85 status = acpi_tb_get_table_header(address, &header);
86 if (ACPI_FAILURE(status)) {
87 return_ACPI_STATUS(status);
88 }
89
90 /* Get the entire table */
91
92 status = acpi_tb_get_table_body(address, &header, table_info);
93 if (ACPI_FAILURE(status)) {
94 ACPI_EXCEPTION((AE_INFO, status,
95 "Could not get ACPI table (size %X)",
96 header.length));
97 return_ACPI_STATUS(status);
98 }
99
100 return_ACPI_STATUS(AE_OK);
101}
102
103/*******************************************************************************
104 *
105 * FUNCTION: acpi_tb_get_table_header
106 *
107 * PARAMETERS: Address - Address of table to retrieve. Can be
108 * Logical or Physical
109 * return_header - Where the table header is returned
110 *
111 * RETURN: Status
112 *
113 * DESCRIPTION: Get an ACPI table header. Works in both physical or virtual
114 * addressing mode. Works with both physical or logical pointers.
115 * Table is either copied or mapped, depending on the pointer
116 * type and mode of the processor.
117 *
118 ******************************************************************************/
119
120acpi_status
121acpi_tb_get_table_header(struct acpi_pointer *address,
122 struct acpi_table_header *return_header)
123{
124 acpi_status status = AE_OK;
125 struct acpi_table_header *header = NULL;
126
127 ACPI_FUNCTION_TRACE(tb_get_table_header);
128
129 /*
130 * Flags contains the current processor mode (Virtual or Physical
131 * addressing) The pointer_type is either Logical or Physical
132 */
133 switch (address->pointer_type) {
134 case ACPI_PHYSMODE_PHYSPTR:
135 case ACPI_LOGMODE_LOGPTR:
136
137 /* Pointer matches processor mode, copy the header */
138
139 ACPI_MEMCPY(return_header, address->pointer.logical,
140 sizeof(struct acpi_table_header));
141 break;
142
143 case ACPI_LOGMODE_PHYSPTR:
144
145 /* Create a logical address for the physical pointer */
146
147 status = acpi_os_map_memory(address->pointer.physical,
148 sizeof(struct acpi_table_header),
149 (void *)&header);
150 if (ACPI_FAILURE(status)) {
151 ACPI_ERROR((AE_INFO,
152 "Could not map memory at %8.8X%8.8X for table header",
153 ACPI_FORMAT_UINT64(address->pointer.
154 physical)));
155 return_ACPI_STATUS(status);
156 }
157
158 /* Copy header and delete mapping */
159
160 ACPI_MEMCPY(return_header, header,
161 sizeof(struct acpi_table_header));
162 acpi_os_unmap_memory(header, sizeof(struct acpi_table_header));
163 break;
164
165 default:
166
167 ACPI_ERROR((AE_INFO, "Invalid address flags %X",
168 address->pointer_type));
169 return_ACPI_STATUS(AE_BAD_PARAMETER);
170 }
171
172 ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n",
173 return_header->signature));
174
175 return_ACPI_STATUS(AE_OK);
176}
177
178/*******************************************************************************
179 *
180 * FUNCTION: acpi_tb_get_table_body
181 *
182 * PARAMETERS: Address - Address of table to retrieve. Can be
183 * Logical or Physical
184 * Header - Header of the table to retrieve
185 * table_info - Where the table info is returned
186 *
187 * RETURN: Status
188 *
189 * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
190 * replace the table with a newer version (table override.)
191 * Works in both physical or virtual
192 * addressing mode. Works with both physical or logical pointers.
193 * Table is either copied or mapped, depending on the pointer
194 * type and mode of the processor.
195 *
196 ******************************************************************************/
197
198acpi_status
199acpi_tb_get_table_body(struct acpi_pointer *address,
200 struct acpi_table_header *header,
201 struct acpi_table_desc *table_info)
202{
203 acpi_status status;
204
205 ACPI_FUNCTION_TRACE(tb_get_table_body);
206
207 if (!table_info || !address) {
208 return_ACPI_STATUS(AE_BAD_PARAMETER);
209 }
210
211 /* Attempt table override. */
212
213 status = acpi_tb_table_override(header, table_info);
214 if (ACPI_SUCCESS(status)) {
215
216 /* Table was overridden by the host OS */
217
218 return_ACPI_STATUS(status);
219 }
220
221 /* No override, get the original table */
222
223 status = acpi_tb_get_this_table(address, header, table_info);
224 return_ACPI_STATUS(status);
225}
226
227/*******************************************************************************
228 *
229 * FUNCTION: acpi_tb_table_override
230 *
231 * PARAMETERS: Header - Pointer to table header
232 * table_info - Return info if table is overridden
233 *
234 * RETURN: None
235 *
236 * DESCRIPTION: Attempts override of current table with a new one if provided
237 * by the host OS.
238 *
239 ******************************************************************************/
240
241static acpi_status
242acpi_tb_table_override(struct acpi_table_header *header,
243 struct acpi_table_desc *table_info)
244{
245 struct acpi_table_header *new_table;
246 acpi_status status;
247 struct acpi_pointer address;
248
249 ACPI_FUNCTION_TRACE(tb_table_override);
250
251 /*
252 * The OSL will examine the header and decide whether to override this
253 * table. If it decides to override, a table will be returned in new_table,
254 * which we will then copy.
255 */
256 status = acpi_os_table_override(header, &new_table);
257 if (ACPI_FAILURE(status)) {
258
259 /* Some severe error from the OSL, but we basically ignore it */
260
261 ACPI_EXCEPTION((AE_INFO, status,
262 "Could not override ACPI table"));
263 return_ACPI_STATUS(status);
264 }
265
266 if (!new_table) {
267
268 /* No table override */
269
270 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
271 }
272
273 /*
274 * We have a new table to override the old one. Get a copy of
275 * the new one. We know that the new table has a logical pointer.
276 */
277 address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
278 address.pointer.logical = new_table;
279
280 status = acpi_tb_get_this_table(&address, new_table, table_info);
281 if (ACPI_FAILURE(status)) {
282 ACPI_EXCEPTION((AE_INFO, status, "Could not copy ACPI table"));
283 return_ACPI_STATUS(status);
284 }
285
286 /* Copy the table info */
287
288 ACPI_INFO((AE_INFO, "Table [%4.4s] replaced by host OS",
289 table_info->pointer->signature));
290
291 return_ACPI_STATUS(AE_OK);
292}
293
294/*******************************************************************************
295 *
296 * FUNCTION: acpi_tb_get_this_table
297 *
298 * PARAMETERS: Address - Address of table to retrieve. Can be
299 * Logical or Physical
300 * Header - Header of the table to retrieve
301 * table_info - Where the table info is returned
302 *
303 * RETURN: Status
304 *
305 * DESCRIPTION: Get an entire ACPI table. Works in both physical or virtual
306 * addressing mode. Works with both physical or logical pointers.
307 * Table is either copied or mapped, depending on the pointer
308 * type and mode of the processor.
309 *
310 ******************************************************************************/
311
312static acpi_status
313acpi_tb_get_this_table(struct acpi_pointer *address,
314 struct acpi_table_header *header,
315 struct acpi_table_desc *table_info)
316{
317 struct acpi_table_header *full_table = NULL;
318 u8 allocation;
319 acpi_status status = AE_OK;
320
321 ACPI_FUNCTION_TRACE(tb_get_this_table);
322
323 /* Validate minimum length */
324
325 if (header->length < sizeof(struct acpi_table_header)) {
326 ACPI_ERROR((AE_INFO,
327 "Table length (%X) is smaller than minimum (%zX)",
328 header->length, sizeof(struct acpi_table_header)));
329
330 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
331 }
332
333 /*
334 * Flags contains the current processor mode (Virtual or Physical
335 * addressing) The pointer_type is either Logical or Physical
336 */
337 switch (address->pointer_type) {
338 case ACPI_PHYSMODE_PHYSPTR:
339 case ACPI_LOGMODE_LOGPTR:
340
341 /* Pointer matches processor mode, copy the table to a new buffer */
342
343 full_table = ACPI_ALLOCATE(header->length);
344 if (!full_table) {
345 ACPI_ERROR((AE_INFO,
346 "Could not allocate table memory for [%4.4s] length %X",
347 header->signature, header->length));
348 return_ACPI_STATUS(AE_NO_MEMORY);
349 }
350
351 /* Copy the entire table (including header) to the local buffer */
352
353 ACPI_MEMCPY(full_table, address->pointer.logical,
354 header->length);
355
356 /* Save allocation type */
357
358 allocation = ACPI_MEM_ALLOCATED;
359 break;
360
361 case ACPI_LOGMODE_PHYSPTR:
362
363 /*
364 * Just map the table's physical memory
365 * into our address space.
366 */
367 status = acpi_os_map_memory(address->pointer.physical,
368 (acpi_size) header->length,
369 ACPI_CAST_PTR(void, &full_table));
370 if (ACPI_FAILURE(status)) {
371 ACPI_ERROR((AE_INFO,
372 "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X",
373 header->signature,
374 ACPI_FORMAT_UINT64(address->pointer.
375 physical),
376 header->length));
377 return (status);
378 }
379
380 /* Save allocation type */
381
382 allocation = ACPI_MEM_MAPPED;
383 break;
384
385 default:
386
387 ACPI_ERROR((AE_INFO, "Invalid address flags %X",
388 address->pointer_type));
389 return_ACPI_STATUS(AE_BAD_PARAMETER);
390 }
391
392 /*
393 * Validate checksum for _most_ tables,
394 * even the ones whose signature we don't recognize
395 */
396 if (table_info->type != ACPI_TABLE_ID_FACS) {
397 status = acpi_tb_verify_table_checksum(full_table);
398
399#if (!ACPI_CHECKSUM_ABORT)
400 if (ACPI_FAILURE(status)) {
401
402 /* Ignore the error if configuration says so */
403
404 status = AE_OK;
405 }
406#endif
407 }
408
409 /* Return values */
410
411 table_info->pointer = full_table;
412 table_info->length = (acpi_size) header->length;
413 table_info->allocation = allocation;
414
415 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
416 "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
417 full_table->signature,
418 ACPI_FORMAT_UINT64(address->pointer.physical),
419 full_table));
420
421 return_ACPI_STATUS(status);
422}
423
424/*******************************************************************************
425 *
426 * FUNCTION: acpi_tb_get_table_ptr
427 *
428 * PARAMETERS: table_type - one of the defined table types
429 * Instance - Which table of this type
430 * return_table - pointer to location to place the pointer for
431 * return
432 *
433 * RETURN: Status
434 *
435 * DESCRIPTION: This function is called to get the pointer to an ACPI table.
436 *
437 ******************************************************************************/
438
439acpi_status
440acpi_tb_get_table_ptr(acpi_table_type table_type,
441 u32 instance, struct acpi_table_header **return_table)
442{
443 struct acpi_table_desc *table_desc;
444 u32 i;
445
446 ACPI_FUNCTION_TRACE(tb_get_table_ptr);
447
448 if (table_type > ACPI_TABLE_ID_MAX) {
449 return_ACPI_STATUS(AE_BAD_PARAMETER);
450 }
451
452 /* Check for instance out of range of the current table count */
453
454 if (instance > acpi_gbl_table_lists[table_type].count) {
455 return_ACPI_STATUS(AE_NOT_EXIST);
456 }
457
458 /*
459 * Walk the list to get the desired table
460 * Note: Instance is one-based
461 */
462 table_desc = acpi_gbl_table_lists[table_type].next;
463 for (i = 1; i < instance; i++) {
464 table_desc = table_desc->next;
465 }
466
467 /* We are now pointing to the requested table's descriptor */
468
469 *return_table = table_desc->pointer;
470 return_ACPI_STATUS(AE_OK);
471}
diff --git a/drivers/acpi/tables/tbgetall.c b/drivers/acpi/tables/tbgetall.c
deleted file mode 100644
index ad982112e4..0000000000
--- a/drivers/acpi/tables/tbgetall.c
+++ /dev/null
@@ -1,311 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: tbgetall - Get all required ACPI tables
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
47#define _COMPONENT ACPI_TABLES
48ACPI_MODULE_NAME("tbgetall")
49
50/* Local prototypes */
51static acpi_status
52acpi_tb_get_primary_table(struct acpi_pointer *address,
53 struct acpi_table_desc *table_info);
54
55static acpi_status
56acpi_tb_get_secondary_table(struct acpi_pointer *address,
57 acpi_string signature,
58 struct acpi_table_desc *table_info);
59
60/*******************************************************************************
61 *
62 * FUNCTION: acpi_tb_get_primary_table
63 *
64 * PARAMETERS: Address - Physical address of table to retrieve
65 * *table_info - Where the table info is returned
66 *
67 * RETURN: Status
68 *
69 * DESCRIPTION: Maps the physical address of table into a logical address
70 *
71 ******************************************************************************/
72
73static acpi_status
74acpi_tb_get_primary_table(struct acpi_pointer *address,
75 struct acpi_table_desc *table_info)
76{
77 acpi_status status;
78 struct acpi_table_header header;
79
80 ACPI_FUNCTION_TRACE(tb_get_primary_table);
81
82 /* Ignore a NULL address in the RSDT */
83
84 if (!address->pointer.value) {
85 return_ACPI_STATUS(AE_OK);
86 }
87
88 /* Get the header in order to get signature and table size */
89
90 status = acpi_tb_get_table_header(address, &header);
91 if (ACPI_FAILURE(status)) {
92 return_ACPI_STATUS(status);
93 }
94
95 /* Clear the table_info */
96
97 ACPI_MEMSET(table_info, 0, sizeof(struct acpi_table_desc));
98
99 /*
100 * Check the table signature and make sure it is recognized.
101 * Also checks the header checksum
102 */
103 table_info->pointer = &header;
104 status = acpi_tb_recognize_table(table_info, ACPI_TABLE_PRIMARY);
105 if (ACPI_FAILURE(status)) {
106 return_ACPI_STATUS(status);
107 }
108
109 /* Get the entire table */
110
111 status = acpi_tb_get_table_body(address, &header, table_info);
112 if (ACPI_FAILURE(status)) {
113 return_ACPI_STATUS(status);
114 }
115
116 /* Install the table */
117
118 status = acpi_tb_install_table(table_info);
119 return_ACPI_STATUS(status);
120}
121
122/*******************************************************************************
123 *
124 * FUNCTION: acpi_tb_get_secondary_table
125 *
126 * PARAMETERS: Address - Physical address of table to retrieve
127 * *table_info - Where the table info is returned
128 *
129 * RETURN: Status
130 *
131 * DESCRIPTION: Maps the physical address of table into a logical address
132 *
133 ******************************************************************************/
134
135static acpi_status
136acpi_tb_get_secondary_table(struct acpi_pointer *address,
137 acpi_string signature,
138 struct acpi_table_desc *table_info)
139{
140 acpi_status status;
141 struct acpi_table_header header;
142
143 ACPI_FUNCTION_TRACE_STR(tb_get_secondary_table, signature);
144
145 /* Get the header in order to match the signature */
146
147 status = acpi_tb_get_table_header(address, &header);
148 if (ACPI_FAILURE(status)) {
149 return_ACPI_STATUS(status);
150 }
151
152 /* Signature must match request */
153
154 if (!ACPI_COMPARE_NAME(header.signature, signature)) {
155 ACPI_ERROR((AE_INFO,
156 "Incorrect table signature - wanted [%s] found [%4.4s]",
157 signature, header.signature));
158 return_ACPI_STATUS(AE_BAD_SIGNATURE);
159 }
160
161 /*
162 * Check the table signature and make sure it is recognized.
163 * Also checks the header checksum
164 */
165 table_info->pointer = &header;
166 status = acpi_tb_recognize_table(table_info, ACPI_TABLE_SECONDARY);
167 if (ACPI_FAILURE(status)) {
168 return_ACPI_STATUS(status);
169 }
170
171 /* Get the entire table */
172
173 status = acpi_tb_get_table_body(address, &header, table_info);
174 if (ACPI_FAILURE(status)) {
175 return_ACPI_STATUS(status);
176 }
177
178 /* Install the table */
179
180 status = acpi_tb_install_table(table_info);
181 return_ACPI_STATUS(status);
182}
183
184/*******************************************************************************
185 *
186 * FUNCTION: acpi_tb_get_required_tables
187 *
188 * PARAMETERS: None
189 *
190 * RETURN: Status
191 *
192 * DESCRIPTION: Load and validate tables other than the RSDT. The RSDT must
193 * already be loaded and validated.
194 *
195 * Get the minimum set of ACPI tables, namely:
196 *
197 * 1) FADT (via RSDT in loop below)
198 * 2) FACS (via FADT)
199 * 3) DSDT (via FADT)
200 *
201 ******************************************************************************/
202
203acpi_status acpi_tb_get_required_tables(void)
204{
205 acpi_status status = AE_OK;
206 u32 i;
207 struct acpi_table_desc table_info;
208 struct acpi_pointer address;
209
210 ACPI_FUNCTION_TRACE(tb_get_required_tables);
211
212 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%d ACPI tables in RSDT\n",
213 acpi_gbl_rsdt_table_count));
214
215 address.pointer_type = acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
216
217 /*
218 * Loop through all table pointers found in RSDT.
219 * This will NOT include the FACS and DSDT - we must get
220 * them after the loop.
221 *
222 * The only tables we are interested in getting here is the FADT and
223 * any SSDTs.
224 */
225 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
226
227 /* Get the table address from the common internal XSDT */
228
229 address.pointer.value = acpi_gbl_XSDT->table_offset_entry[i];
230
231 /*
232 * Get the tables needed by this subsystem (FADT and any SSDTs).
233 * NOTE: All other tables are completely ignored at this time.
234 */
235 status = acpi_tb_get_primary_table(&address, &table_info);
236 if ((status != AE_OK) && (status != AE_TABLE_NOT_SUPPORTED)) {
237 ACPI_WARNING((AE_INFO,
238 "%s, while getting table at %8.8X%8.8X",
239 acpi_format_exception(status),
240 ACPI_FORMAT_UINT64(address.pointer.
241 value)));
242 }
243 }
244
245 /* We must have a FADT to continue */
246
247 if (!acpi_gbl_FADT) {
248 ACPI_ERROR((AE_INFO, "No FADT present in RSDT/XSDT"));
249 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
250 }
251
252 /*
253 * Convert the FADT to a common format. This allows earlier revisions of
254 * the table to coexist with newer versions, using common access code.
255 */
256 status = acpi_tb_convert_table_fadt();
257 if (ACPI_FAILURE(status)) {
258 ACPI_ERROR((AE_INFO,
259 "Could not convert FADT to internal common format"));
260 return_ACPI_STATUS(status);
261 }
262
263 /* Get the FACS (Pointed to by the FADT) */
264
265 address.pointer.value = acpi_gbl_FADT->xfirmware_ctrl;
266
267 status = acpi_tb_get_secondary_table(&address, FACS_SIG, &table_info);
268 if (ACPI_FAILURE(status)) {
269 ACPI_EXCEPTION((AE_INFO, status,
270 "Could not get/install the FACS"));
271 return_ACPI_STATUS(status);
272 }
273
274 /*
275 * Create the common FACS pointer table
276 * (Contains pointers to the original table)
277 */
278 status = acpi_tb_build_common_facs(&table_info);
279 if (ACPI_FAILURE(status)) {
280 return_ACPI_STATUS(status);
281 }
282
283 /* Get/install the DSDT (Pointed to by the FADT) */
284
285 address.pointer.value = acpi_gbl_FADT->Xdsdt;
286
287 status = acpi_tb_get_secondary_table(&address, DSDT_SIG, &table_info);
288 if (ACPI_FAILURE(status)) {
289 ACPI_ERROR((AE_INFO, "Could not get/install the DSDT"));
290 return_ACPI_STATUS(status);
291 }
292
293 /* Set Integer Width (32/64) based upon DSDT revision */
294
295 acpi_ut_set_integer_width(acpi_gbl_DSDT->revision);
296
297 /* Dump the entire DSDT */
298
299 ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
300 "Hex dump of entire DSDT, size %d (0x%X), Integer width = %d\n",
301 acpi_gbl_DSDT->length, acpi_gbl_DSDT->length,
302 acpi_gbl_integer_bit_width));
303
304 ACPI_DUMP_BUFFER(ACPI_CAST_PTR(u8, acpi_gbl_DSDT),
305 acpi_gbl_DSDT->length);
306
307 /* Always delete the RSDP mapping, we are done with it */
308
309 acpi_tb_delete_tables_by_type(ACPI_TABLE_ID_RSDP);
310 return_ACPI_STATUS(status);
311}
diff --git a/drivers/acpi/tables/tbinstal.c b/drivers/acpi/tables/tbinstal.c
index 1668a232fb..0e7b121a99 100644
--- a/drivers/acpi/tables/tbinstal.c
+++ b/drivers/acpi/tables/tbinstal.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -42,510 +42,498 @@
42 */ 42 */
43 43
44#include <acpi/acpi.h> 44#include <acpi/acpi.h>
45#include <acpi/acnamesp.h>
45#include <acpi/actables.h> 46#include <acpi/actables.h>
46 47
47#define _COMPONENT ACPI_TABLES 48#define _COMPONENT ACPI_TABLES
48ACPI_MODULE_NAME("tbinstal") 49ACPI_MODULE_NAME("tbinstal")
49 50
50/* Local prototypes */ 51/******************************************************************************
51static acpi_status
52acpi_tb_match_signature(char *signature,
53 struct acpi_table_desc *table_info, u8 search_type);
54
55/*******************************************************************************
56 * 52 *
57 * FUNCTION: acpi_tb_match_signature 53 * FUNCTION: acpi_tb_verify_table
58 * 54 *
59 * PARAMETERS: Signature - Table signature to match 55 * PARAMETERS: table_desc - table
60 * table_info - Return data
61 * search_type - Table type to match (primary/secondary)
62 * 56 *
63 * RETURN: Status 57 * RETURN: Status
64 * 58 *
65 * DESCRIPTION: Compare signature against the list of "ACPI-subsystem-owned" 59 * DESCRIPTION: this function is called to verify and map table
66 * tables (DSDT/FADT/SSDT, etc.) Returns the table_type_iD on match.
67 * 60 *
68 ******************************************************************************/ 61 *****************************************************************************/
69 62acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
70static acpi_status
71acpi_tb_match_signature(char *signature,
72 struct acpi_table_desc *table_info, u8 search_type)
73{ 63{
74 acpi_native_uint i; 64 acpi_status status = AE_OK;
75 65
76 ACPI_FUNCTION_TRACE(tb_match_signature); 66 ACPI_FUNCTION_TRACE(tb_verify_table);
77 67
78 /* Search for a signature match among the known table types */ 68 /* Map the table if necessary */
79 69
80 for (i = 0; i < (ACPI_TABLE_ID_MAX + 1); i++) { 70 if (!table_desc->pointer) {
81 if (!(acpi_gbl_table_data[i].flags & search_type)) { 71 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
82 continue; 72 ACPI_TABLE_ORIGIN_MAPPED) {
73 table_desc->pointer =
74 acpi_os_map_memory(table_desc->address,
75 table_desc->length);
83 } 76 }
77 if (!table_desc->pointer) {
78 return_ACPI_STATUS(AE_NO_MEMORY);
79 }
80 }
84 81
85 if (!ACPI_STRNCMP(signature, acpi_gbl_table_data[i].signature, 82 /* FACS is the odd table, has no standard ACPI header and no checksum */
86 acpi_gbl_table_data[i].sig_length)) {
87
88 /* Found a signature match, return index if requested */
89 83
90 if (table_info) { 84 if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) {
91 table_info->type = (u8) i;
92 }
93 85
94 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 86 /* Always calculate checksum, ignore bad checksum if requested */
95 "Table [%4.4s] is an ACPI table consumed by the core subsystem\n",
96 (char *)acpi_gbl_table_data[i].
97 signature));
98 87
99 return_ACPI_STATUS(AE_OK); 88 status =
100 } 89 acpi_tb_verify_checksum(table_desc->pointer,
90 table_desc->length);
101 } 91 }
102 92
103 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 93 return_ACPI_STATUS(status);
104 "Table [%4.4s] is not an ACPI table consumed by the core subsystem - ignored\n",
105 (char *)signature));
106
107 return_ACPI_STATUS(AE_TABLE_NOT_SUPPORTED);
108} 94}
109 95
110/******************************************************************************* 96/*******************************************************************************
111 * 97 *
112 * FUNCTION: acpi_tb_install_table 98 * FUNCTION: acpi_tb_add_table
113 * 99 *
114 * PARAMETERS: table_info - Return value from acpi_tb_get_table_body 100 * PARAMETERS: table_desc - Table descriptor
101 * table_index - Where the table index is returned
115 * 102 *
116 * RETURN: Status 103 * RETURN: Status
117 * 104 *
118 * DESCRIPTION: Install the table into the global data structures. 105 * DESCRIPTION: This function is called to add the ACPI table
119 * 106 *
120 ******************************************************************************/ 107 ******************************************************************************/
121 108
122acpi_status acpi_tb_install_table(struct acpi_table_desc *table_info) 109acpi_status
110acpi_tb_add_table(struct acpi_table_desc *table_desc,
111 acpi_native_uint * table_index)
123{ 112{
124 acpi_status status; 113 acpi_native_uint i;
125 114 acpi_native_uint length;
126 ACPI_FUNCTION_TRACE(tb_install_table); 115 acpi_status status = AE_OK;
127 116
128 /* Lock tables while installing */ 117 ACPI_FUNCTION_TRACE(tb_add_table);
129 118
130 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES); 119 if (!table_desc->pointer) {
131 if (ACPI_FAILURE(status)) { 120 status = acpi_tb_verify_table(table_desc);
132 ACPI_EXCEPTION((AE_INFO, status, 121 if (ACPI_FAILURE(status) || !table_desc->pointer) {
133 "Could not acquire table mutex")); 122 return_ACPI_STATUS(status);
134 return_ACPI_STATUS(status); 123 }
135 } 124 }
136 125
137 /* 126 /* The table must be either an SSDT or a PSDT */
138 * Ignore a table that is already installed. For example, some BIOS 127
139 * ASL code will repeatedly attempt to load the same SSDT. 128 if ((!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_PSDT))
140 */ 129 &&
141 status = acpi_tb_is_table_installed(table_info); 130 (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT)))
142 if (ACPI_FAILURE(status)) { 131 {
143 goto unlock_and_exit; 132 ACPI_ERROR((AE_INFO,
133 "Table has invalid signature [%4.4s], must be SSDT or PSDT",
134 table_desc->pointer->signature));
135 return_ACPI_STATUS(AE_BAD_SIGNATURE);
144 } 136 }
145 137
146 /* Install the table into the global data structure */ 138 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
139
140 /* Check if table is already registered */
141
142 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
143 if (!acpi_gbl_root_table_list.tables[i].pointer) {
144 status =
145 acpi_tb_verify_table(&acpi_gbl_root_table_list.
146 tables[i]);
147 if (ACPI_FAILURE(status)
148 || !acpi_gbl_root_table_list.tables[i].pointer) {
149 continue;
150 }
151 }
152
153 length = ACPI_MIN(table_desc->length,
154 acpi_gbl_root_table_list.tables[i].length);
155 if (ACPI_MEMCMP(table_desc->pointer,
156 acpi_gbl_root_table_list.tables[i].pointer,
157 length)) {
158 continue;
159 }
160
161 /* Table is already registered */
162
163 acpi_tb_delete_table(table_desc);
164 *table_index = i;
165 goto release;
166 }
147 167
148 status = acpi_tb_init_table_descriptor(table_info->type, table_info); 168 /*
169 * Add the table to the global table list
170 */
171 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
172 table_desc->length, table_desc->flags,
173 table_index);
149 if (ACPI_FAILURE(status)) { 174 if (ACPI_FAILURE(status)) {
150 ACPI_EXCEPTION((AE_INFO, status, 175 goto release;
151 "Could not install table [%4.4s]",
152 table_info->pointer->signature));
153 } 176 }
154 177
155 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s located at %p\n", 178 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
156 acpi_gbl_table_data[table_info->type].name,
157 table_info->pointer));
158 179
159 unlock_and_exit: 180 release:
160 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 181 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
161 return_ACPI_STATUS(status); 182 return_ACPI_STATUS(status);
162} 183}
163 184
164/******************************************************************************* 185/*******************************************************************************
165 * 186 *
166 * FUNCTION: acpi_tb_recognize_table 187 * FUNCTION: acpi_tb_resize_root_table_list
167 * 188 *
168 * PARAMETERS: table_info - Return value from acpi_tb_get_table_body 189 * PARAMETERS: None
169 * search_type - Table type to match (primary/secondary)
170 * 190 *
171 * RETURN: Status 191 * RETURN: Status
172 * 192 *
173 * DESCRIPTION: Check a table signature for a match against known table types 193 * DESCRIPTION: Expand the size of global table array
174 *
175 * NOTE: All table pointers are validated as follows:
176 * 1) Table pointer must point to valid physical memory
177 * 2) Signature must be 4 ASCII chars, even if we don't recognize the
178 * name
179 * 3) Table must be readable for length specified in the header
180 * 4) Table checksum must be valid (with the exception of the FACS
181 * which has no checksum for some odd reason)
182 * 194 *
183 ******************************************************************************/ 195 ******************************************************************************/
184 196
185acpi_status 197acpi_status acpi_tb_resize_root_table_list(void)
186acpi_tb_recognize_table(struct acpi_table_desc *table_info, u8 search_type)
187{ 198{
188 struct acpi_table_header *table_header; 199 struct acpi_table_desc *tables;
189 acpi_status status;
190 200
191 ACPI_FUNCTION_TRACE(tb_recognize_table); 201 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
192 202
193 /* Ensure that we have a valid table pointer */ 203 /* allow_resize flag is a parameter to acpi_initialize_tables */
194 204
195 table_header = (struct acpi_table_header *)table_info->pointer; 205 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
196 if (!table_header) { 206 ACPI_ERROR((AE_INFO,
197 return_ACPI_STATUS(AE_BAD_PARAMETER); 207 "Resize of Root Table Array is not allowed"));
208 return_ACPI_STATUS(AE_SUPPORT);
198 } 209 }
199 210
200 /* 211 /* Increase the Table Array size */
201 * We only "recognize" a limited number of ACPI tables -- namely, the 212
202 * ones that are used by the subsystem (DSDT, FADT, etc.) 213 tables = ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list.size +
203 * 214 ACPI_ROOT_TABLE_SIZE_INCREMENT)
204 * An AE_TABLE_NOT_SUPPORTED means that the table was not recognized. 215 * sizeof(struct acpi_table_desc));
205 * This can be any one of many valid ACPI tables, it just isn't one of 216 if (!tables) {
206 * the tables that is consumed by the core subsystem 217 ACPI_ERROR((AE_INFO,
207 */ 218 "Could not allocate new root table array"));
208 status = acpi_tb_match_signature(table_header->signature, 219 return_ACPI_STATUS(AE_NO_MEMORY);
209 table_info, search_type);
210 if (ACPI_FAILURE(status)) {
211 return_ACPI_STATUS(status);
212 } 220 }
213 221
214 status = acpi_tb_validate_table_header(table_header); 222 /* Copy and free the previous table array */
215 if (ACPI_FAILURE(status)) { 223
216 return_ACPI_STATUS(status); 224 if (acpi_gbl_root_table_list.tables) {
225 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
226 acpi_gbl_root_table_list.size *
227 sizeof(struct acpi_table_desc));
228
229 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
230 ACPI_FREE(acpi_gbl_root_table_list.tables);
231 }
217 } 232 }
218 233
219 /* Return the table type and length via the info struct */ 234 acpi_gbl_root_table_list.tables = tables;
235 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
236 acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
220 237
221 table_info->length = (acpi_size) table_header->length; 238 return_ACPI_STATUS(AE_OK);
222 return_ACPI_STATUS(status);
223} 239}
224 240
225/******************************************************************************* 241/*******************************************************************************
226 * 242 *
227 * FUNCTION: acpi_tb_init_table_descriptor 243 * FUNCTION: acpi_tb_store_table
228 * 244 *
229 * PARAMETERS: table_type - The type of the table 245 * PARAMETERS: Address - Table address
230 * table_info - A table info struct 246 * Table - Table header
247 * Length - Table length
248 * Flags - flags
231 * 249 *
232 * RETURN: None. 250 * RETURN: Status and table index.
233 * 251 *
234 * DESCRIPTION: Install a table into the global data structs. 252 * DESCRIPTION: Add an ACPI table to the global table list
235 * 253 *
236 ******************************************************************************/ 254 ******************************************************************************/
237 255
238acpi_status 256acpi_status
239acpi_tb_init_table_descriptor(acpi_table_type table_type, 257acpi_tb_store_table(acpi_physical_address address,
240 struct acpi_table_desc *table_info) 258 struct acpi_table_header *table,
259 u32 length, u8 flags, acpi_native_uint * table_index)
241{ 260{
242 struct acpi_table_list *list_head; 261 acpi_status status = AE_OK;
243 struct acpi_table_desc *table_desc;
244 acpi_status status;
245
246 ACPI_FUNCTION_TRACE_U32(tb_init_table_descriptor, table_type);
247 262
248 /* Allocate a descriptor for this table */ 263 /* Ensure that there is room for the table in the Root Table List */
249 264
250 table_desc = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_table_desc)); 265 if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
251 if (!table_desc) { 266 status = acpi_tb_resize_root_table_list();
252 return_ACPI_STATUS(AE_NO_MEMORY); 267 if (ACPI_FAILURE(status)) {
268 return (status);
269 }
253 } 270 }
254 271
255 /* Get a new owner ID for the table */ 272 /* Initialize added table */
273
274 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
275 address = address;
276 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
277 pointer = table;
278 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
279 length;
280 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
281 owner_id = 0;
282 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
283 flags;
284
285 ACPI_MOVE_32_TO_32(&
286 (acpi_gbl_root_table_list.
287 tables[acpi_gbl_root_table_list.count].signature),
288 table->signature);
289
290 *table_index = acpi_gbl_root_table_list.count;
291 acpi_gbl_root_table_list.count++;
292 return (status);
293}
256 294
257 status = acpi_ut_allocate_owner_id(&table_desc->owner_id); 295/*******************************************************************************
258 if (ACPI_FAILURE(status)) { 296 *
259 goto error_exit1; 297 * FUNCTION: acpi_tb_delete_table
260 } 298 *
299 * PARAMETERS: table_index - Table index
300 *
301 * RETURN: None
302 *
303 * DESCRIPTION: Delete one internal ACPI table
304 *
305 ******************************************************************************/
261 306
262 /* Install the table into the global data structure */ 307void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
308{
309 /* Table must be mapped or allocated */
310 if (!table_desc->pointer) {
311 return;
312 }
313 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
314 case ACPI_TABLE_ORIGIN_MAPPED:
315 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
316 break;
317 case ACPI_TABLE_ORIGIN_ALLOCATED:
318 ACPI_FREE(table_desc->pointer);
319 break;
320 default:;
321 }
263 322
264 list_head = &acpi_gbl_table_lists[table_type]; 323 table_desc->pointer = NULL;
324}
265 325
266 /* 326/*******************************************************************************
267 * Two major types of tables: 1) Only one instance is allowed. This 327 *
268 * includes most ACPI tables such as the DSDT. 2) Multiple instances of 328 * FUNCTION: acpi_tb_terminate
269 * the table are allowed. This includes SSDT and PSDTs. 329 *
270 */ 330 * PARAMETERS: None
271 if (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags)) { 331 *
272 /* 332 * RETURN: None
273 * Only one table allowed, and a table has alread been installed 333 *
274 * at this location, so return an error. 334 * DESCRIPTION: Delete all internal ACPI tables
275 */ 335 *
276 if (list_head->next) { 336 ******************************************************************************/
277 status = AE_ALREADY_EXISTS;
278 goto error_exit2;
279 }
280 337
281 table_desc->next = list_head->next; 338void acpi_tb_terminate(void)
282 list_head->next = table_desc; 339{
340 acpi_native_uint i;
283 341
284 if (table_desc->next) { 342 ACPI_FUNCTION_TRACE(tb_terminate);
285 table_desc->next->prev = table_desc;
286 }
287 343
288 list_head->count++; 344 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
289 } else {
290 /*
291 * Link the new table in to the list of tables of this type.
292 * Insert at the end of the list, order IS IMPORTANT.
293 *
294 * table_desc->Prev & Next are already NULL from calloc()
295 */
296 list_head->count++;
297
298 if (!list_head->next) {
299 list_head->next = table_desc;
300 } else {
301 table_desc->next = list_head->next;
302 345
303 while (table_desc->next->next) { 346 /* Delete the individual tables */
304 table_desc->next = table_desc->next->next;
305 }
306 347
307 table_desc->next->next = table_desc; 348 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
308 table_desc->prev = table_desc->next; 349 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
309 table_desc->next = NULL;
310 }
311 } 350 }
312 351
313 /* Finish initialization of the table descriptor */
314
315 table_desc->loaded_into_namespace = FALSE;
316 table_desc->type = (u8) table_type;
317 table_desc->pointer = table_info->pointer;
318 table_desc->length = table_info->length;
319 table_desc->allocation = table_info->allocation;
320 table_desc->aml_start = (u8 *) (table_desc->pointer + 1),
321 table_desc->aml_length = (u32)
322 (table_desc->length - (u32) sizeof(struct acpi_table_header));
323
324 /* 352 /*
325 * Set the appropriate global pointer (if there is one) to point to the 353 * Delete the root table array if allocated locally. Array cannot be
326 * newly installed table 354 * mapped, so we don't need to check for that flag.
327 */ 355 */
328 if (acpi_gbl_table_data[table_type].global_ptr) { 356 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
329 *(acpi_gbl_table_data[table_type].global_ptr) = 357 ACPI_FREE(acpi_gbl_root_table_list.tables);
330 table_info->pointer;
331 } 358 }
332 359
333 /* Return Data */ 360 acpi_gbl_root_table_list.tables = NULL;
334 361 acpi_gbl_root_table_list.flags = 0;
335 table_info->owner_id = table_desc->owner_id; 362 acpi_gbl_root_table_list.count = 0;
336 table_info->installed_desc = table_desc;
337 return_ACPI_STATUS(AE_OK);
338
339 /* Error exit with cleanup */
340
341 error_exit2:
342
343 acpi_ut_release_owner_id(&table_desc->owner_id);
344 363
345 error_exit1: 364 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
346 365 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
347 ACPI_FREE(table_desc);
348 return_ACPI_STATUS(status);
349} 366}
350 367
351/******************************************************************************* 368/*******************************************************************************
352 * 369 *
353 * FUNCTION: acpi_tb_delete_all_tables 370 * FUNCTION: acpi_tb_delete_namespace_by_owner
354 * 371 *
355 * PARAMETERS: None. 372 * PARAMETERS: table_index - Table index
356 * 373 *
357 * RETURN: None. 374 * RETURN: None
358 * 375 *
359 * DESCRIPTION: Delete all internal ACPI tables 376 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
360 * 377 *
361 ******************************************************************************/ 378 ******************************************************************************/
362 379
363void acpi_tb_delete_all_tables(void) 380void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index)
364{ 381{
365 acpi_table_type type; 382 acpi_owner_id owner_id;
366 383
367 /* 384 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
368 * Free memory allocated for ACPI tables 385 if (table_index < acpi_gbl_root_table_list.count) {
369 * Memory can either be mapped or allocated 386 owner_id =
370 */ 387 acpi_gbl_root_table_list.tables[table_index].owner_id;
371 for (type = 0; type < (ACPI_TABLE_ID_MAX + 1); type++) { 388 } else {
372 acpi_tb_delete_tables_by_type(type); 389 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
390 return;
373 } 391 }
392
393 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
394 acpi_ns_delete_namespace_by_owner(owner_id);
374} 395}
375 396
376/******************************************************************************* 397/*******************************************************************************
377 * 398 *
378 * FUNCTION: acpi_tb_delete_tables_by_type 399 * FUNCTION: acpi_tb_allocate_owner_id
379 * 400 *
380 * PARAMETERS: Type - The table type to be deleted 401 * PARAMETERS: table_index - Table index
381 * 402 *
382 * RETURN: None. 403 * RETURN: Status
383 * 404 *
384 * DESCRIPTION: Delete an internal ACPI table 405 * DESCRIPTION: Allocates owner_id in table_desc
385 * Locks the ACPI table mutex
386 * 406 *
387 ******************************************************************************/ 407 ******************************************************************************/
388 408
389void acpi_tb_delete_tables_by_type(acpi_table_type type) 409acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index)
390{ 410{
391 struct acpi_table_desc *table_desc; 411 acpi_status status = AE_BAD_PARAMETER;
392 u32 count;
393 u32 i;
394 412
395 ACPI_FUNCTION_TRACE_U32(tb_delete_tables_by_type, type); 413 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
396 414
397 if (type > ACPI_TABLE_ID_MAX) { 415 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
398 return_VOID; 416 if (table_index < acpi_gbl_root_table_list.count) {
399 } 417 status = acpi_ut_allocate_owner_id
400 418 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
401 if (ACPI_FAILURE(acpi_ut_acquire_mutex(ACPI_MTX_TABLES))) {
402 return;
403 }
404
405 /* Clear the appropriate "typed" global table pointer */
406
407 switch (type) {
408 case ACPI_TABLE_ID_RSDP:
409 acpi_gbl_RSDP = NULL;
410 break;
411
412 case ACPI_TABLE_ID_DSDT:
413 acpi_gbl_DSDT = NULL;
414 break;
415
416 case ACPI_TABLE_ID_FADT:
417 acpi_gbl_FADT = NULL;
418 break;
419
420 case ACPI_TABLE_ID_FACS:
421 acpi_gbl_FACS = NULL;
422 break;
423
424 case ACPI_TABLE_ID_XSDT:
425 acpi_gbl_XSDT = NULL;
426 break;
427
428 case ACPI_TABLE_ID_SSDT:
429 case ACPI_TABLE_ID_PSDT:
430 default:
431 break;
432 }
433
434 /*
435 * Free the table
436 * 1) Get the head of the list
437 */
438 table_desc = acpi_gbl_table_lists[type].next;
439 count = acpi_gbl_table_lists[type].count;
440
441 /*
442 * 2) Walk the entire list, deleting both the allocated tables
443 * and the table descriptors
444 */
445 for (i = 0; i < count; i++) {
446 table_desc = acpi_tb_uninstall_table(table_desc);
447 } 419 }
448 420
449 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 421 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
450 return_VOID; 422 return_ACPI_STATUS(status);
451} 423}
452 424
453/******************************************************************************* 425/*******************************************************************************
454 * 426 *
455 * FUNCTION: acpi_tb_delete_single_table 427 * FUNCTION: acpi_tb_release_owner_id
456 * 428 *
457 * PARAMETERS: table_info - A table info struct 429 * PARAMETERS: table_index - Table index
458 * 430 *
459 * RETURN: None. 431 * RETURN: Status
460 * 432 *
461 * DESCRIPTION: Low-level free for a single ACPI table. Handles cases where 433 * DESCRIPTION: Releases owner_id in table_desc
462 * the table was allocated a buffer or was mapped.
463 * 434 *
464 ******************************************************************************/ 435 ******************************************************************************/
465 436
466void acpi_tb_delete_single_table(struct acpi_table_desc *table_desc) 437acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index)
467{ 438{
439 acpi_status status = AE_BAD_PARAMETER;
468 440
469 /* Must have a valid table descriptor and pointer */ 441 ACPI_FUNCTION_TRACE(tb_release_owner_id);
470 442
471 if ((!table_desc) || (!table_desc->pointer)) { 443 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
472 return; 444 if (table_index < acpi_gbl_root_table_list.count) {
445 acpi_ut_release_owner_id(&
446 (acpi_gbl_root_table_list.
447 tables[table_index].owner_id));
448 status = AE_OK;
473 } 449 }
474 450
475 /* Valid table, determine type of memory allocation */ 451 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
476 452 return_ACPI_STATUS(status);
477 switch (table_desc->allocation) {
478 case ACPI_MEM_NOT_ALLOCATED:
479 break;
480
481 case ACPI_MEM_ALLOCATED:
482
483 ACPI_FREE(table_desc->pointer);
484 break;
485
486 case ACPI_MEM_MAPPED:
487
488 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
489 break;
490
491 default:
492 break;
493 }
494} 453}
495 454
496/******************************************************************************* 455/*******************************************************************************
497 * 456 *
498 * FUNCTION: acpi_tb_uninstall_table 457 * FUNCTION: acpi_tb_get_owner_id
499 * 458 *
500 * PARAMETERS: table_info - A table info struct 459 * PARAMETERS: table_index - Table index
460 * owner_id - Where the table owner_id is returned
501 * 461 *
502 * RETURN: Pointer to the next table in the list (of same type) 462 * RETURN: Status
503 * 463 *
504 * DESCRIPTION: Free the memory associated with an internal ACPI table that 464 * DESCRIPTION: returns owner_id for the ACPI table
505 * is either installed or has never been installed.
506 * Table mutex should be locked.
507 * 465 *
508 ******************************************************************************/ 466 ******************************************************************************/
509 467
510struct acpi_table_desc *acpi_tb_uninstall_table(struct acpi_table_desc 468acpi_status
511 *table_desc) 469acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id)
512{ 470{
513 struct acpi_table_desc *next_desc; 471 acpi_status status = AE_BAD_PARAMETER;
514 472
515 ACPI_FUNCTION_TRACE_PTR(tb_uninstall_table, table_desc); 473 ACPI_FUNCTION_TRACE(tb_get_owner_id);
516 474
517 if (!table_desc) { 475 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
518 return_PTR(NULL); 476 if (table_index < acpi_gbl_root_table_list.count) {
477 *owner_id =
478 acpi_gbl_root_table_list.tables[table_index].owner_id;
479 status = AE_OK;
519 } 480 }
520 481
521 /* Unlink the descriptor from the doubly linked list */ 482 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
483 return_ACPI_STATUS(status);
484}
522 485
523 if (table_desc->prev) { 486/*******************************************************************************
524 table_desc->prev->next = table_desc->next; 487 *
525 } else { 488 * FUNCTION: acpi_tb_is_table_loaded
526 /* Is first on list, update list head */ 489 *
490 * PARAMETERS: table_index - Table index
491 *
492 * RETURN: Table Loaded Flag
493 *
494 ******************************************************************************/
527 495
528 acpi_gbl_table_lists[table_desc->type].next = table_desc->next; 496u8 acpi_tb_is_table_loaded(acpi_native_uint table_index)
529 } 497{
498 u8 is_loaded = FALSE;
530 499
531 if (table_desc->next) { 500 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
532 table_desc->next->prev = table_desc->prev; 501 if (table_index < acpi_gbl_root_table_list.count) {
502 is_loaded = (u8)
503 (acpi_gbl_root_table_list.tables[table_index].
504 flags & ACPI_TABLE_IS_LOADED);
533 } 505 }
534 506
535 /* Free the memory allocated for the table itself */ 507 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
536 508 return (is_loaded);
537 acpi_tb_delete_single_table(table_desc); 509}
538
539 /* Free the owner ID associated with this table */
540
541 acpi_ut_release_owner_id(&table_desc->owner_id);
542 510
543 /* Free the table descriptor */ 511/*******************************************************************************
512 *
513 * FUNCTION: acpi_tb_set_table_loaded_flag
514 *
515 * PARAMETERS: table_index - Table index
516 * is_loaded - TRUE if table is loaded, FALSE otherwise
517 *
518 * RETURN: None
519 *
520 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
521 *
522 ******************************************************************************/
544 523
545 next_desc = table_desc->next; 524void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded)
546 ACPI_FREE(table_desc); 525{
547 526
548 /* Return pointer to the next descriptor */ 527 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
528 if (table_index < acpi_gbl_root_table_list.count) {
529 if (is_loaded) {
530 acpi_gbl_root_table_list.tables[table_index].flags |=
531 ACPI_TABLE_IS_LOADED;
532 } else {
533 acpi_gbl_root_table_list.tables[table_index].flags &=
534 ~ACPI_TABLE_IS_LOADED;
535 }
536 }
549 537
550 return_PTR(next_desc); 538 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
551} 539}
diff --git a/drivers/acpi/tables/tbrsdt.c b/drivers/acpi/tables/tbrsdt.c
deleted file mode 100644
index 86a5fca9b7..0000000000
--- a/drivers/acpi/tables/tbrsdt.c
+++ /dev/null
@@ -1,307 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: tbrsdt - ACPI RSDT table utilities
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
47#define _COMPONENT ACPI_TABLES
48ACPI_MODULE_NAME("tbrsdt")
49
50/*******************************************************************************
51 *
52 * FUNCTION: acpi_tb_verify_rsdp
53 *
54 * PARAMETERS: Address - RSDP (Pointer to RSDT)
55 *
56 * RETURN: Status
57 *
58 * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
59 *
60 ******************************************************************************/
61acpi_status acpi_tb_verify_rsdp(struct acpi_pointer *address)
62{
63 struct acpi_table_desc table_info;
64 acpi_status status;
65 struct rsdp_descriptor *rsdp;
66
67 ACPI_FUNCTION_TRACE(tb_verify_rsdp);
68
69 switch (address->pointer_type) {
70 case ACPI_LOGICAL_POINTER:
71
72 rsdp = address->pointer.logical;
73 break;
74
75 case ACPI_PHYSICAL_POINTER:
76 /*
77 * Obtain access to the RSDP structure
78 */
79 status = acpi_os_map_memory(address->pointer.physical,
80 sizeof(struct rsdp_descriptor),
81 ACPI_CAST_PTR(void, &rsdp));
82 if (ACPI_FAILURE(status)) {
83 return_ACPI_STATUS(status);
84 }
85 break;
86
87 default:
88 return_ACPI_STATUS(AE_BAD_PARAMETER);
89 }
90
91 /* Verify RSDP signature and checksum */
92
93 status = acpi_tb_validate_rsdp(rsdp);
94 if (ACPI_FAILURE(status)) {
95 goto cleanup;
96 }
97
98 /* RSDP is ok. Init the table info */
99
100 table_info.pointer = ACPI_CAST_PTR(struct acpi_table_header, rsdp);
101 table_info.length = sizeof(struct rsdp_descriptor);
102
103 if (address->pointer_type == ACPI_PHYSICAL_POINTER) {
104 table_info.allocation = ACPI_MEM_MAPPED;
105 } else {
106 table_info.allocation = ACPI_MEM_NOT_ALLOCATED;
107 }
108
109 /* Save the table pointers and allocation info */
110
111 status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_RSDP, &table_info);
112 if (ACPI_FAILURE(status)) {
113 goto cleanup;
114 }
115
116 /* Save the RSDP in a global for easy access */
117
118 acpi_gbl_RSDP =
119 ACPI_CAST_PTR(struct rsdp_descriptor, table_info.pointer);
120 return_ACPI_STATUS(status);
121
122 /* Error exit */
123 cleanup:
124
125 if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) {
126 acpi_os_unmap_memory(rsdp, sizeof(struct rsdp_descriptor));
127 }
128 return_ACPI_STATUS(status);
129}
130
131/*******************************************************************************
132 *
133 * FUNCTION: acpi_tb_get_rsdt_address
134 *
135 * PARAMETERS: out_address - Where the address is returned
136 *
137 * RETURN: None, Address
138 *
139 * DESCRIPTION: Extract the address of either the RSDT or XSDT, depending on the
140 * version of the RSDP and whether the XSDT pointer is valid
141 *
142 ******************************************************************************/
143
144void acpi_tb_get_rsdt_address(struct acpi_pointer *out_address)
145{
146
147 ACPI_FUNCTION_ENTRY();
148
149 out_address->pointer_type =
150 acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
151
152 /* Use XSDT if it is present */
153
154 if ((acpi_gbl_RSDP->revision >= 2) &&
155 acpi_gbl_RSDP->xsdt_physical_address) {
156 out_address->pointer.value =
157 acpi_gbl_RSDP->xsdt_physical_address;
158 acpi_gbl_root_table_type = ACPI_TABLE_TYPE_XSDT;
159 } else {
160 /* No XSDT, use the RSDT */
161
162 out_address->pointer.value =
163 acpi_gbl_RSDP->rsdt_physical_address;
164 acpi_gbl_root_table_type = ACPI_TABLE_TYPE_RSDT;
165 }
166}
167
168/*******************************************************************************
169 *
170 * FUNCTION: acpi_tb_validate_rsdt
171 *
172 * PARAMETERS: table_ptr - Addressable pointer to the RSDT.
173 *
174 * RETURN: Status
175 *
176 * DESCRIPTION: Validate signature for the RSDT or XSDT
177 *
178 ******************************************************************************/
179
180acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr)
181{
182 char *signature;
183
184 ACPI_FUNCTION_ENTRY();
185
186 /* Validate minimum length */
187
188 if (table_ptr->length < sizeof(struct acpi_table_header)) {
189 ACPI_ERROR((AE_INFO,
190 "RSDT/XSDT length (%X) is smaller than minimum (%zX)",
191 table_ptr->length,
192 sizeof(struct acpi_table_header)));
193
194 return (AE_INVALID_TABLE_LENGTH);
195 }
196
197 /* Search for appropriate signature, RSDT or XSDT */
198
199 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
200 signature = RSDT_SIG;
201 } else {
202 signature = XSDT_SIG;
203 }
204
205 if (!ACPI_COMPARE_NAME(table_ptr->signature, signature)) {
206
207 /* Invalid RSDT or XSDT signature */
208
209 ACPI_ERROR((AE_INFO,
210 "Invalid signature where RSDP indicates RSDT/XSDT should be located. RSDP:"));
211
212 ACPI_DUMP_BUFFER(acpi_gbl_RSDP, 20);
213
214 ACPI_ERROR((AE_INFO,
215 "RSDT/XSDT signature at %X is invalid",
216 acpi_gbl_RSDP->rsdt_physical_address));
217
218 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
219 ACPI_ERROR((AE_INFO, "Looking for RSDT"));
220 } else {
221 ACPI_ERROR((AE_INFO, "Looking for XSDT"));
222 }
223
224 ACPI_DUMP_BUFFER(ACPI_CAST_PTR(char, table_ptr), 48);
225 return (AE_BAD_SIGNATURE);
226 }
227
228 return (AE_OK);
229}
230
231/*******************************************************************************
232 *
233 * FUNCTION: acpi_tb_get_table_rsdt
234 *
235 * PARAMETERS: None
236 *
237 * RETURN: Status
238 *
239 * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
240 *
241 ******************************************************************************/
242
243acpi_status acpi_tb_get_table_rsdt(void)
244{
245 struct acpi_table_desc table_info;
246 acpi_status status;
247 struct acpi_pointer address;
248
249 ACPI_FUNCTION_TRACE(tb_get_table_rsdt);
250
251 /* Get the RSDT/XSDT via the RSDP */
252
253 acpi_tb_get_rsdt_address(&address);
254
255 table_info.type = ACPI_TABLE_ID_XSDT;
256 status = acpi_tb_get_table(&address, &table_info);
257 if (ACPI_FAILURE(status)) {
258 ACPI_EXCEPTION((AE_INFO, status,
259 "Could not get the RSDT/XSDT"));
260 return_ACPI_STATUS(status);
261 }
262
263 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
264 "RSDP located at %p, points to RSDT physical=%8.8X%8.8X\n",
265 acpi_gbl_RSDP,
266 ACPI_FORMAT_UINT64(address.pointer.value)));
267
268 /* Check the RSDT or XSDT signature */
269
270 status = acpi_tb_validate_rsdt(table_info.pointer);
271 if (ACPI_FAILURE(status)) {
272 goto error_cleanup;
273 }
274
275 /* Get the number of tables defined in the RSDT or XSDT */
276
277 acpi_gbl_rsdt_table_count = acpi_tb_get_table_count(acpi_gbl_RSDP,
278 table_info.pointer);
279
280 /* Convert and/or copy to an XSDT structure */
281
282 status = acpi_tb_convert_to_xsdt(&table_info);
283 if (ACPI_FAILURE(status)) {
284 goto error_cleanup;
285 }
286
287 /* Save the table pointers and allocation info */
288
289 status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_XSDT, &table_info);
290 if (ACPI_FAILURE(status)) {
291 goto error_cleanup;
292 }
293
294 acpi_gbl_XSDT =
295 ACPI_CAST_PTR(struct xsdt_descriptor, table_info.pointer);
296
297 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT));
298 return_ACPI_STATUS(status);
299
300 error_cleanup:
301
302 /* Free table allocated by acpi_tb_get_table */
303
304 acpi_tb_delete_single_table(&table_info);
305
306 return_ACPI_STATUS(status);
307}
diff --git a/drivers/acpi/tables/tbutils.c b/drivers/acpi/tables/tbutils.c
index 209a401801..4a2f99e2fc 100644
--- a/drivers/acpi/tables/tbutils.c
+++ b/drivers/acpi/tables/tbutils.c
@@ -1,11 +1,11 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2 *
3 * Module Name: tbutils - Table manipulation utilities 3 * Module Name: tbutils - table utilities
4 * 4 *
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -48,137 +48,119 @@
48ACPI_MODULE_NAME("tbutils") 48ACPI_MODULE_NAME("tbutils")
49 49
50/* Local prototypes */ 50/* Local prototypes */
51#ifdef ACPI_OBSOLETE_FUNCTIONS 51static acpi_physical_address
52acpi_status 52acpi_tb_get_root_table_entry(u8 * table_entry,
53acpi_tb_handle_to_object(u16 table_id, struct acpi_table_desc **table_desc); 53 acpi_native_uint table_entry_size);
54#endif
55 54
56/******************************************************************************* 55/*******************************************************************************
57 * 56 *
58 * FUNCTION: acpi_tb_is_table_installed 57 * FUNCTION: acpi_tb_tables_loaded
59 *
60 * PARAMETERS: new_table_desc - Descriptor for new table being installed
61 * 58 *
62 * RETURN: Status - AE_ALREADY_EXISTS if the table is already installed 59 * PARAMETERS: None
63 * 60 *
64 * DESCRIPTION: Determine if an ACPI table is already installed 61 * RETURN: TRUE if required ACPI tables are loaded
65 * 62 *
66 * MUTEX: Table data structures should be locked 63 * DESCRIPTION: Determine if the minimum required ACPI tables are present
64 * (FADT, FACS, DSDT)
67 * 65 *
68 ******************************************************************************/ 66 ******************************************************************************/
69 67
70acpi_status acpi_tb_is_table_installed(struct acpi_table_desc *new_table_desc) 68u8 acpi_tb_tables_loaded(void)
71{ 69{
72 struct acpi_table_desc *table_desc;
73
74 ACPI_FUNCTION_TRACE(tb_is_table_installed);
75 70
76 /* Get the list descriptor and first table descriptor */ 71 if (acpi_gbl_root_table_list.count >= 3) {
77 72 return (TRUE);
78 table_desc = acpi_gbl_table_lists[new_table_desc->type].next; 73 }
79 74
80 /* Examine all installed tables of this type */ 75 return (FALSE);
76}
81 77
82 while (table_desc) { 78/*******************************************************************************
83 /* 79 *
84 * If the table lengths match, perform a full bytewise compare. This 80 * FUNCTION: acpi_tb_print_table_header
85 * means that we will allow tables with duplicate oem_table_id(s), as 81 *
86 * long as the tables are different in some way. 82 * PARAMETERS: Address - Table physical address
87 * 83 * Header - Table header
88 * Checking if the table has been loaded into the namespace means that 84 *
89 * we don't check for duplicate tables during the initial installation 85 * RETURN: None
90 * of tables within the RSDT/XSDT. 86 *
91 */ 87 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
92 if ((table_desc->loaded_into_namespace) && 88 *
93 (table_desc->pointer->length == 89 ******************************************************************************/
94 new_table_desc->pointer->length)
95 &&
96 (!ACPI_MEMCMP
97 (table_desc->pointer, new_table_desc->pointer,
98 new_table_desc->pointer->length))) {
99
100 /* Match: this table is already installed */
101
102 ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
103 "Table [%4.4s] already installed: Rev %X OemTableId [%8.8s]\n",
104 new_table_desc->pointer->signature,
105 new_table_desc->pointer->revision,
106 new_table_desc->pointer->
107 oem_table_id));
108
109 new_table_desc->owner_id = table_desc->owner_id;
110 new_table_desc->installed_desc = table_desc;
111
112 return_ACPI_STATUS(AE_ALREADY_EXISTS);
113 }
114 90
115 /* Get next table on the list */ 91void
92acpi_tb_print_table_header(acpi_physical_address address,
93 struct acpi_table_header *header)
94{
116 95
117 table_desc = table_desc->next; 96 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
97
98 /* FACS only has signature and length fields of common table header */
99
100 ACPI_INFO((AE_INFO, "%4.4s @ 0x%p/0x%04X",
101 header->signature, ACPI_CAST_PTR(void, address),
102 header->length));
103 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
104
105 /* RSDP has no common fields */
106
107 ACPI_INFO((AE_INFO, "RSDP @ 0x%p/0x%04X (v%3.3d %6.6s)",
108 ACPI_CAST_PTR(void, address),
109 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
110 revision >
111 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
112 header)->length : 20,
113 ACPI_CAST_PTR(struct acpi_table_rsdp,
114 header)->revision,
115 ACPI_CAST_PTR(struct acpi_table_rsdp,
116 header)->oem_id));
117 } else {
118 /* Standard ACPI table with full common header */
119
120 ACPI_INFO((AE_INFO,
121 "%4.4s @ 0x%p/0x%04X (v%3.3d %6.6s %8.8s 0x%08X %4.4s 0x%08X)",
122 header->signature, ACPI_CAST_PTR(void, address),
123 header->length, header->revision, header->oem_id,
124 header->oem_table_id, header->oem_revision,
125 header->asl_compiler_id,
126 header->asl_compiler_revision));
118 } 127 }
119
120 return_ACPI_STATUS(AE_OK);
121} 128}
122 129
123/******************************************************************************* 130/*******************************************************************************
124 * 131 *
125 * FUNCTION: acpi_tb_validate_table_header 132 * FUNCTION: acpi_tb_validate_checksum
126 * 133 *
127 * PARAMETERS: table_header - Logical pointer to the table 134 * PARAMETERS: Table - ACPI table to verify
135 * Length - Length of entire table
128 * 136 *
129 * RETURN: Status 137 * RETURN: Status
130 * 138 *
131 * DESCRIPTION: Check an ACPI table header for validity 139 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
132 * 140 * exception on bad checksum.
133 * NOTE: Table pointers are validated as follows:
134 * 1) Table pointer must point to valid physical memory
135 * 2) Signature must be 4 ASCII chars, even if we don't recognize the
136 * name
137 * 3) Table must be readable for length specified in the header
138 * 4) Table checksum must be valid (with the exception of the FACS
139 * which has no checksum because it contains variable fields)
140 * 141 *
141 ******************************************************************************/ 142 ******************************************************************************/
142 143
143acpi_status 144acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
144acpi_tb_validate_table_header(struct acpi_table_header *table_header)
145{ 145{
146 acpi_name signature; 146 u8 checksum;
147
148 ACPI_FUNCTION_ENTRY();
149
150 /* Verify that this is a valid address */
151
152 if (!acpi_os_readable(table_header, sizeof(struct acpi_table_header))) {
153 ACPI_ERROR((AE_INFO,
154 "Cannot read table header at %p", table_header));
155
156 return (AE_BAD_ADDRESS);
157 }
158 147
159 /* Ensure that the signature is 4 ASCII characters */ 148 /* Compute the checksum on the table */
160 149
161 ACPI_MOVE_32_TO_32(&signature, table_header->signature); 150 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
162 if (!acpi_ut_valid_acpi_name(signature)) {
163 ACPI_ERROR((AE_INFO, "Invalid table signature 0x%8.8X",
164 signature));
165 151
166 ACPI_DUMP_BUFFER(table_header, 152 /* Checksum ok? (should be zero) */
167 sizeof(struct acpi_table_header));
168 return (AE_BAD_SIGNATURE);
169 }
170 153
171 /* Validate the table length */ 154 if (checksum) {
155 ACPI_WARNING((AE_INFO,
156 "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X",
157 table->signature, table->checksum,
158 (u8) (table->checksum - checksum)));
172 159
173 if (table_header->length < sizeof(struct acpi_table_header)) { 160#if (ACPI_CHECKSUM_ABORT)
174 ACPI_ERROR((AE_INFO,
175 "Invalid length 0x%X in table with signature %4.4s",
176 (u32) table_header->length,
177 ACPI_CAST_PTR(char, &signature)));
178 161
179 ACPI_DUMP_BUFFER(table_header, 162 return (AE_BAD_CHECKSUM);
180 sizeof(struct acpi_table_header)); 163#endif
181 return (AE_BAD_HEADER);
182 } 164 }
183 165
184 return (AE_OK); 166 return (AE_OK);
@@ -186,157 +168,320 @@ acpi_tb_validate_table_header(struct acpi_table_header *table_header)
186 168
187/******************************************************************************* 169/*******************************************************************************
188 * 170 *
189 * FUNCTION: acpi_tb_sum_table 171 * FUNCTION: acpi_tb_checksum
190 * 172 *
191 * PARAMETERS: Buffer - Buffer to sum 173 * PARAMETERS: Buffer - Pointer to memory region to be checked
192 * Length - Size of the buffer 174 * Length - Length of this memory region
193 * 175 *
194 * RETURN: 8 bit sum of buffer 176 * RETURN: Checksum (u8)
195 * 177 *
196 * DESCRIPTION: Computes an 8 bit sum of the buffer(length) and returns it. 178 * DESCRIPTION: Calculates circular checksum of memory region.
197 * 179 *
198 ******************************************************************************/ 180 ******************************************************************************/
199 181
200u8 acpi_tb_sum_table(void *buffer, u32 length) 182u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length)
201{ 183{
202 acpi_native_uint i;
203 u8 sum = 0; 184 u8 sum = 0;
185 u8 *end = buffer + length;
204 186
205 if (!buffer || !length) { 187 while (buffer < end) {
206 return (0); 188 sum = (u8) (sum + *(buffer++));
207 } 189 }
208 190
209 for (i = 0; i < length; i++) { 191 return sum;
210 sum = (u8) (sum + ((u8 *) buffer)[i]);
211 }
212 return (sum);
213} 192}
214 193
215/******************************************************************************* 194/*******************************************************************************
216 * 195 *
217 * FUNCTION: acpi_tb_generate_checksum 196 * FUNCTION: acpi_tb_install_table
218 * 197 *
219 * PARAMETERS: Table - Pointer to a valid ACPI table (with a 198 * PARAMETERS: Address - Physical address of DSDT or FACS
220 * standard ACPI header) 199 * Flags - Flags
200 * Signature - Table signature, NULL if no need to
201 * match
202 * table_index - Index into root table array
221 * 203 *
222 * RETURN: 8 bit checksum of buffer 204 * RETURN: None
223 * 205 *
224 * DESCRIPTION: Computes an 8 bit checksum of the table. 206 * DESCRIPTION: Install an ACPI table into the global data structure.
225 * 207 *
226 ******************************************************************************/ 208 ******************************************************************************/
227 209
228u8 acpi_tb_generate_checksum(struct acpi_table_header * table) 210void
211acpi_tb_install_table(acpi_physical_address address,
212 u8 flags, char *signature, acpi_native_uint table_index)
229{ 213{
230 u8 checksum; 214 struct acpi_table_header *table;
215
216 if (!address) {
217 ACPI_ERROR((AE_INFO,
218 "Null physical address for ACPI table [%s]",
219 signature));
220 return;
221 }
222
223 /* Map just the table header */
224
225 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
226 if (!table) {
227 return;
228 }
229
230 /* If a particular signature is expected, signature must match */
231
232 if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) {
233 ACPI_ERROR((AE_INFO,
234 "Invalid signature 0x%X for ACPI table [%s]",
235 *ACPI_CAST_PTR(u32, table->signature), signature));
236 goto unmap_and_exit;
237 }
231 238
232 /* Sum the entire table as-is */ 239 /* Initialize the table entry */
233 240
234 checksum = acpi_tb_sum_table(table, table->length); 241 acpi_gbl_root_table_list.tables[table_index].address = address;
242 acpi_gbl_root_table_list.tables[table_index].length = table->length;
243 acpi_gbl_root_table_list.tables[table_index].flags = flags;
235 244
236 /* Subtract off the existing checksum value in the table */ 245 ACPI_MOVE_32_TO_32(&
246 (acpi_gbl_root_table_list.tables[table_index].
247 signature), table->signature);
237 248
238 checksum = (u8) (checksum - table->checksum); 249 acpi_tb_print_table_header(address, table);
239 250
240 /* Compute the final checksum */ 251 if (table_index == ACPI_TABLE_INDEX_DSDT) {
241 252
242 checksum = (u8) (0 - checksum); 253 /* Global integer width is based upon revision of the DSDT */
243 return (checksum); 254
255 acpi_ut_set_integer_width(table->revision);
256 }
257
258 unmap_and_exit:
259 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
244} 260}
245 261
246/******************************************************************************* 262/*******************************************************************************
247 * 263 *
248 * FUNCTION: acpi_tb_set_checksum 264 * FUNCTION: acpi_tb_get_root_table_entry
249 * 265 *
250 * PARAMETERS: Table - Pointer to a valid ACPI table (with a 266 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
251 * standard ACPI header) 267 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
252 * 268 *
253 * RETURN: None. Sets the table checksum field 269 * RETURN: Physical address extracted from the root table
254 * 270 *
255 * DESCRIPTION: Computes an 8 bit checksum of the table and inserts the 271 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
256 * checksum into the table header. 272 * both 32-bit and 64-bit platforms
273 *
274 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
275 * 64-bit platforms.
257 * 276 *
258 ******************************************************************************/ 277 ******************************************************************************/
259 278
260void acpi_tb_set_checksum(struct acpi_table_header *table) 279static acpi_physical_address
280acpi_tb_get_root_table_entry(u8 * table_entry,
281 acpi_native_uint table_entry_size)
261{ 282{
283 u64 address64;
284
285 /*
286 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
287 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
288 */
289 if (table_entry_size == sizeof(u32)) {
290 /*
291 * 32-bit platform, RSDT: Return 32-bit table entry
292 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
293 */
294 return ((acpi_physical_address)
295 (*ACPI_CAST_PTR(u32, table_entry)));
296 } else {
297 /*
298 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
299 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, return 64-bit
300 */
301 ACPI_MOVE_64_TO_64(&address64, table_entry);
262 302
263 table->checksum = acpi_tb_generate_checksum(table); 303#if ACPI_MACHINE_WIDTH == 32
304 if (address64 > ACPI_UINT32_MAX) {
305
306 /* Will truncate 64-bit address to 32 bits, issue warning */
307
308 ACPI_WARNING((AE_INFO,
309 "64-bit Physical Address in XSDT is too large (%8.8X%8.8X), truncating",
310 ACPI_FORMAT_UINT64(address64)));
311 }
312#endif
313 return ((acpi_physical_address) (address64));
314 }
264} 315}
265 316
266/******************************************************************************* 317/*******************************************************************************
267 * 318 *
268 * FUNCTION: acpi_tb_verify_table_checksum 319 * FUNCTION: acpi_tb_parse_root_table
320 *
321 * PARAMETERS: Rsdp - Pointer to the RSDP
322 * Flags - Flags
269 * 323 *
270 * PARAMETERS: *table_header - ACPI table to verify 324 * RETURN: Status
271 * 325 *
272 * RETURN: 8 bit checksum of table 326 * DESCRIPTION: This function is called to parse the Root System Description
327 * Table (RSDT or XSDT)
273 * 328 *
274 * DESCRIPTION: Generates an 8 bit checksum of table and returns and compares 329 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
275 * it to the existing checksum value. 330 * be mapped and cannot be copied because it contains the actual
331 * memory location of the ACPI Global Lock.
276 * 332 *
277 ******************************************************************************/ 333 ******************************************************************************/
278 334
279acpi_status 335acpi_status __init
280acpi_tb_verify_table_checksum(struct acpi_table_header *table_header) 336acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
281{ 337{
282 u8 checksum; 338 struct acpi_table_rsdp *rsdp;
339 acpi_native_uint table_entry_size;
340 acpi_native_uint i;
341 u32 table_count;
342 struct acpi_table_header *table;
343 acpi_physical_address address;
344 u32 length;
345 u8 *table_entry;
346 acpi_status status;
347
348 ACPI_FUNCTION_TRACE(tb_parse_root_table);
349
350 /*
351 * Map the entire RSDP and extract the address of the RSDT or XSDT
352 */
353 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
354 if (!rsdp) {
355 return_ACPI_STATUS(AE_NO_MEMORY);
356 }
283 357
284 ACPI_FUNCTION_TRACE(tb_verify_table_checksum); 358 acpi_tb_print_table_header(rsdp_address,
359 ACPI_CAST_PTR(struct acpi_table_header,
360 rsdp));
285 361
286 /* Compute the checksum on the table */ 362 /* Differentiate between RSDT and XSDT root tables */
287 363
288 checksum = acpi_tb_generate_checksum(table_header); 364 if (rsdp->revision > 1 && rsdp->xsdt_physical_address) {
365 /*
366 * Root table is an XSDT (64-bit physical addresses). We must use the
367 * XSDT if the revision is > 1 and the XSDT pointer is present, as per
368 * the ACPI specification.
369 */
370 address = (acpi_physical_address) rsdp->xsdt_physical_address;
371 table_entry_size = sizeof(u64);
372 } else {
373 /* Root table is an RSDT (32-bit physical addresses) */
289 374
290 /* Checksum ok? */ 375 address = (acpi_physical_address) rsdp->rsdt_physical_address;
376 table_entry_size = sizeof(u32);
377 }
291 378
292 if (checksum == table_header->checksum) { 379 /*
293 return_ACPI_STATUS(AE_OK); 380 * It is not possible to map more than one entry in some environments,
381 * so unmap the RSDP here before mapping other tables
382 */
383 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
384
385 /* Map the RSDT/XSDT table header to get the full table length */
386
387 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
388 if (!table) {
389 return_ACPI_STATUS(AE_NO_MEMORY);
294 } 390 }
295 391
296 ACPI_WARNING((AE_INFO, 392 acpi_tb_print_table_header(address, table);
297 "Incorrect checksum in table [%4.4s] - is %2.2X, should be %2.2X",
298 table_header->signature, table_header->checksum,
299 checksum));
300 393
301 return_ACPI_STATUS(AE_BAD_CHECKSUM); 394 /* Get the length of the full table, verify length and map entire table */
302}
303 395
304#ifdef ACPI_OBSOLETE_FUNCTIONS 396 length = table->length;
305/******************************************************************************* 397 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
306 *
307 * FUNCTION: acpi_tb_handle_to_object
308 *
309 * PARAMETERS: table_id - Id for which the function is searching
310 * table_desc - Pointer to return the matching table
311 * descriptor.
312 *
313 * RETURN: Search the tables to find one with a matching table_id and
314 * return a pointer to that table descriptor.
315 *
316 ******************************************************************************/
317 398
318acpi_status 399 if (length < sizeof(struct acpi_table_header)) {
319acpi_tb_handle_to_object(u16 table_id, 400 ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT",
320 struct acpi_table_desc **return_table_desc) 401 length));
321{ 402 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
322 u32 i; 403 }
323 struct acpi_table_desc *table_desc;
324 404
325 ACPI_FUNCTION_NAME(tb_handle_to_object); 405 table = acpi_os_map_memory(address, length);
406 if (!table) {
407 return_ACPI_STATUS(AE_NO_MEMORY);
408 }
409
410 /* Validate the root table checksum */
411
412 status = acpi_tb_verify_checksum(table, length);
413 if (ACPI_FAILURE(status)) {
414 acpi_os_unmap_memory(table, length);
415 return_ACPI_STATUS(status);
416 }
326 417
327 for (i = 0; i < ACPI_TABLE_MAX; i++) { 418 /* Calculate the number of tables described in the root table */
328 table_desc = acpi_gbl_table_lists[i].next; 419
329 while (table_desc) { 420 table_count =
330 if (table_desc->table_id == table_id) { 421 (u32) ((table->length -
331 *return_table_desc = table_desc; 422 sizeof(struct acpi_table_header)) / table_entry_size);
332 return (AE_OK); 423
424 /*
425 * First two entries in the table array are reserved for the DSDT and FACS,
426 * which are not actually present in the RSDT/XSDT - they come from the FADT
427 */
428 table_entry =
429 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
430 acpi_gbl_root_table_list.count = 2;
431
432 /*
433 * Initialize the root table array from the RSDT/XSDT
434 */
435 for (i = 0; i < table_count; i++) {
436 if (acpi_gbl_root_table_list.count >=
437 acpi_gbl_root_table_list.size) {
438
439 /* There is no more room in the root table array, attempt resize */
440
441 status = acpi_tb_resize_root_table_list();
442 if (ACPI_FAILURE(status)) {
443 ACPI_WARNING((AE_INFO,
444 "Truncating %u table entries!",
445 (unsigned)
446 (acpi_gbl_root_table_list.size -
447 acpi_gbl_root_table_list.
448 count)));
449 break;
333 } 450 }
451 }
452
453 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
334 454
335 table_desc = table_desc->next; 455 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
456 address =
457 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
458
459 table_entry += table_entry_size;
460 acpi_gbl_root_table_list.count++;
461 }
462
463 /*
464 * It is not possible to map more than one entry in some environments,
465 * so unmap the root table here before mapping other tables
466 */
467 acpi_os_unmap_memory(table, length);
468
469 /*
470 * Complete the initialization of the root table array by examining
471 * the header of each table
472 */
473 for (i = 2; i < acpi_gbl_root_table_list.count; i++) {
474 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
475 address, flags, NULL, i);
476
477 /* Special case for FADT - get the DSDT and FACS */
478
479 if (ACPI_COMPARE_NAME
480 (&acpi_gbl_root_table_list.tables[i].signature,
481 ACPI_SIG_FADT)) {
482 acpi_tb_parse_fadt(i, flags);
336 } 483 }
337 } 484 }
338 485
339 ACPI_ERROR((AE_INFO, "TableId=%X does not exist", table_id)); 486 return_ACPI_STATUS(AE_OK);
340 return (AE_BAD_PARAMETER);
341} 487}
342#endif
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index 7767987be1..807978d538 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2006, R. Byron Moore 9 * Copyright (C) 2000 - 2007, R. Byron Moore
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -49,81 +49,158 @@
49#define _COMPONENT ACPI_TABLES 49#define _COMPONENT ACPI_TABLES
50ACPI_MODULE_NAME("tbxface") 50ACPI_MODULE_NAME("tbxface")
51 51
52/* Local prototypes */
53static acpi_status acpi_tb_load_namespace(void);
54
52/******************************************************************************* 55/*******************************************************************************
53 * 56 *
54 * FUNCTION: acpi_load_tables 57 * FUNCTION: acpi_allocate_root_table
55 * 58 *
56 * PARAMETERS: None 59 * PARAMETERS: initial_table_count - Size of initial_table_array, in number of
60 * struct acpi_table_desc structures
57 * 61 *
58 * RETURN: Status 62 * RETURN: Status
59 * 63 *
60 * DESCRIPTION: This function is called to load the ACPI tables from the 64 * DESCRIPTION: Allocate a root table array. Used by i_aSL compiler and
61 * provided RSDT 65 * acpi_initialize_tables.
62 * 66 *
63 ******************************************************************************/ 67 ******************************************************************************/
64acpi_status acpi_load_tables(void) 68
69acpi_status acpi_allocate_root_table(u32 initial_table_count)
65{ 70{
66 struct acpi_pointer rsdp_address;
67 acpi_status status;
68 71
69 ACPI_FUNCTION_TRACE(acpi_load_tables); 72 acpi_gbl_root_table_list.size = initial_table_count;
73 acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE;
70 74
71 /* Get the RSDP */ 75 return (acpi_tb_resize_root_table_list());
76}
72 77
73 status = acpi_os_get_root_pointer(ACPI_LOGICAL_ADDRESSING, 78/*******************************************************************************
74 &rsdp_address); 79 *
75 if (ACPI_FAILURE(status)) { 80 * FUNCTION: acpi_initialize_tables
76 ACPI_EXCEPTION((AE_INFO, status, "Could not get the RSDP")); 81 *
77 goto error_exit; 82 * PARAMETERS: initial_table_array - Pointer to an array of pre-allocated
78 } 83 * struct acpi_table_desc structures. If NULL, the
84 * array is dynamically allocated.
85 * initial_table_count - Size of initial_table_array, in number of
86 * struct acpi_table_desc structures
87 * allow_realloc - Flag to tell Table Manager if resize of
88 * pre-allocated array is allowed. Ignored
89 * if initial_table_array is NULL.
90 *
91 * RETURN: Status
92 *
93 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
94 *
95 * NOTE: Allows static allocation of the initial table array in order
96 * to avoid the use of dynamic memory in confined environments
97 * such as the kernel boot sequence where it may not be available.
98 *
99 * If the host OS memory managers are initialized, use NULL for
100 * initial_table_array, and the table will be dynamically allocated.
101 *
102 ******************************************************************************/
79 103
80 /* Map and validate the RSDP */ 104acpi_status __init
105acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
106 u32 initial_table_count, u8 allow_resize)
107{
108 acpi_physical_address rsdp_address;
109 acpi_status status;
81 110
82 acpi_gbl_table_flags = rsdp_address.pointer_type; 111 ACPI_FUNCTION_TRACE(acpi_initialize_tables);
83 112
84 status = acpi_tb_verify_rsdp(&rsdp_address); 113 /*
85 if (ACPI_FAILURE(status)) { 114 * Set up the Root Table Array
86 ACPI_EXCEPTION((AE_INFO, status, "During RSDP validation")); 115 * Allocate the table array if requested
87 goto error_exit; 116 */
117 if (!initial_table_array) {
118 status = acpi_allocate_root_table(initial_table_count);
119 if (ACPI_FAILURE(status)) {
120 return_ACPI_STATUS(status);
121 }
122 } else {
123 /* Root Table Array has been statically allocated by the host */
124
125 ACPI_MEMSET(initial_table_array, 0,
126 initial_table_count *
127 sizeof(struct acpi_table_desc));
128
129 acpi_gbl_root_table_list.tables = initial_table_array;
130 acpi_gbl_root_table_list.size = initial_table_count;
131 acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN;
132 if (allow_resize) {
133 acpi_gbl_root_table_list.flags |=
134 ACPI_ROOT_ALLOW_RESIZE;
135 }
88 } 136 }
89 137
90 /* Get the RSDT via the RSDP */ 138 /* Get the address of the RSDP */
91 139
92 status = acpi_tb_get_table_rsdt(); 140 rsdp_address = acpi_os_get_root_pointer();
93 if (ACPI_FAILURE(status)) { 141 if (!rsdp_address) {
94 ACPI_EXCEPTION((AE_INFO, status, "Could not load RSDT")); 142 return_ACPI_STATUS(AE_NOT_FOUND);
95 goto error_exit;
96 } 143 }
97 144
98 /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */ 145 /*
146 * Get the root table (RSDT or XSDT) and extract all entries to the local
147 * Root Table Array. This array contains the information of the RSDT/XSDT
148 * in a common, more useable format.
149 */
150 status =
151 acpi_tb_parse_root_table(rsdp_address, ACPI_TABLE_ORIGIN_MAPPED);
152 return_ACPI_STATUS(status);
153}
99 154
100 status = acpi_tb_get_required_tables(); 155/*******************************************************************************
101 if (ACPI_FAILURE(status)) { 156 *
102 ACPI_EXCEPTION((AE_INFO, status, 157 * FUNCTION: acpi_reallocate_root_table
103 "Could not get all required tables (DSDT/FADT/FACS)")); 158 *
104 goto error_exit; 159 * PARAMETERS: None
160 *
161 * RETURN: Status
162 *
163 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
164 * root list from the previously provided scratch area. Should
165 * be called once dynamic memory allocation is available in the
166 * kernel
167 *
168 ******************************************************************************/
169acpi_status acpi_reallocate_root_table(void)
170{
171 struct acpi_table_desc *tables;
172 acpi_size new_size;
173
174 ACPI_FUNCTION_TRACE(acpi_reallocate_root_table);
175
176 /*
177 * Only reallocate the root table if the host provided a static buffer
178 * for the table array in the call to acpi_initialize_tables.
179 */
180 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
181 return_ACPI_STATUS(AE_SUPPORT);
105 } 182 }
106 183
107 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n")); 184 new_size =
185 (acpi_gbl_root_table_list.count +
186 ACPI_ROOT_TABLE_SIZE_INCREMENT) * sizeof(struct acpi_table_desc);
108 187
109 /* Load the namespace from the tables */ 188 /* Create new array and copy the old array */
110 189
111 status = acpi_ns_load_namespace(); 190 tables = ACPI_ALLOCATE_ZEROED(new_size);
112 if (ACPI_FAILURE(status)) { 191 if (!tables) {
113 ACPI_EXCEPTION((AE_INFO, status, "Could not load namespace")); 192 return_ACPI_STATUS(AE_NO_MEMORY);
114 goto error_exit;
115 } 193 }
116 194
117 return_ACPI_STATUS(AE_OK); 195 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, new_size);
118 196
119 error_exit: 197 acpi_gbl_root_table_list.size = acpi_gbl_root_table_list.count;
120 ACPI_EXCEPTION((AE_INFO, status, "Could not load tables")); 198 acpi_gbl_root_table_list.tables = tables;
121 return_ACPI_STATUS(status); 199 acpi_gbl_root_table_list.flags =
122} 200 ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE;
123 201
124ACPI_EXPORT_SYMBOL(acpi_load_tables) 202 return_ACPI_STATUS(AE_OK);
125 203}
126#ifdef ACPI_FUTURE_USAGE
127/******************************************************************************* 204/*******************************************************************************
128 * 205 *
129 * FUNCTION: acpi_load_table 206 * FUNCTION: acpi_load_table
@@ -142,289 +219,405 @@ ACPI_EXPORT_SYMBOL(acpi_load_tables)
142acpi_status acpi_load_table(struct acpi_table_header *table_ptr) 219acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
143{ 220{
144 acpi_status status; 221 acpi_status status;
145 struct acpi_table_desc table_info; 222 acpi_native_uint table_index;
146 struct acpi_pointer address; 223 struct acpi_table_desc table_desc;
147 224
148 ACPI_FUNCTION_TRACE(acpi_load_table); 225 if (!table_ptr)
226 return AE_BAD_PARAMETER;
149 227
150 if (!table_ptr) { 228 ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
151 return_ACPI_STATUS(AE_BAD_PARAMETER); 229 table_desc.pointer = table_ptr;
152 } 230 table_desc.length = table_ptr->length;
153 231 table_desc.flags = ACPI_TABLE_ORIGIN_UNKNOWN;
154 /* Copy the table to a local buffer */
155 232
156 address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING; 233 /*
157 address.pointer.logical = table_ptr; 234 * Install the new table into the local data structures
158 235 */
159 status = acpi_tb_get_table_body(&address, table_ptr, &table_info); 236 status = acpi_tb_add_table(&table_desc, &table_index);
160 if (ACPI_FAILURE(status)) { 237 if (ACPI_FAILURE(status)) {
161 return_ACPI_STATUS(status); 238 return status;
162 } 239 }
240 status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
241 return status;
242}
163 243
164 /* Check signature for a valid table type */ 244ACPI_EXPORT_SYMBOL(acpi_load_table)
165
166 status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL);
167 if (ACPI_FAILURE(status)) {
168 return_ACPI_STATUS(status);
169 }
170 245
171 /* Install the new table into the local data structures */ 246/******************************************************************************
247 *
248 * FUNCTION: acpi_get_table_header
249 *
250 * PARAMETERS: Signature - ACPI signature of needed table
251 * Instance - Which instance (for SSDTs)
252 * out_table_header - The pointer to the table header to fill
253 *
254 * RETURN: Status and pointer to mapped table header
255 *
256 * DESCRIPTION: Finds an ACPI table header.
257 *
258 * NOTE: Caller is responsible in unmapping the header with
259 * acpi_os_unmap_memory
260 *
261 *****************************************************************************/
262acpi_status
263acpi_get_table_header(char *signature,
264 acpi_native_uint instance,
265 struct acpi_table_header *out_table_header)
266{
267 acpi_native_uint i;
268 acpi_native_uint j;
269 struct acpi_table_header *header;
172 270
173 status = acpi_tb_install_table(&table_info); 271 /* Parameter validation */
174 if (ACPI_FAILURE(status)) {
175 if (status == AE_ALREADY_EXISTS) {
176 272
177 /* Table already exists, no error */ 273 if (!signature || !out_table_header) {
274 return (AE_BAD_PARAMETER);
275 }
178 276
179 status = AE_OK; 277 /*
278 * Walk the root table list
279 */
280 for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
281 if (!ACPI_COMPARE_NAME
282 (&(acpi_gbl_root_table_list.tables[i].signature),
283 signature)) {
284 continue;
180 } 285 }
181 286
182 /* Free table allocated by acpi_tb_get_table_body */ 287 if (++j < instance) {
288 continue;
289 }
183 290
184 acpi_tb_delete_single_table(&table_info); 291 if (!acpi_gbl_root_table_list.tables[i].pointer) {
185 return_ACPI_STATUS(status); 292 if ((acpi_gbl_root_table_list.tables[i].
293 flags & ACPI_TABLE_ORIGIN_MASK) ==
294 ACPI_TABLE_ORIGIN_MAPPED) {
295 header =
296 acpi_os_map_memory(acpi_gbl_root_table_list.
297 tables[i].address,
298 sizeof(struct
299 acpi_table_header));
300 if (!header) {
301 return AE_NO_MEMORY;
302 }
303 ACPI_MEMCPY(out_table_header, header,
304 sizeof(struct acpi_table_header));
305 acpi_os_unmap_memory(header,
306 sizeof(struct
307 acpi_table_header));
308 } else {
309 return AE_NOT_FOUND;
310 }
311 } else {
312 ACPI_MEMCPY(out_table_header,
313 acpi_gbl_root_table_list.tables[i].pointer,
314 sizeof(struct acpi_table_header));
315 }
316 return (AE_OK);
186 } 317 }
187 318
188 /* Convert the table to common format if necessary */ 319 return (AE_NOT_FOUND);
189 320}
190 switch (table_info.type) {
191 case ACPI_TABLE_ID_FADT:
192
193 status = acpi_tb_convert_table_fadt();
194 break;
195
196 case ACPI_TABLE_ID_FACS:
197
198 status = acpi_tb_build_common_facs(&table_info);
199 break;
200 321
201 default: 322ACPI_EXPORT_SYMBOL(acpi_get_table_header)
202 /* Load table into namespace if it contains executable AML */
203 323
204 status =
205 acpi_ns_load_table(table_info.installed_desc,
206 acpi_gbl_root_node);
207 break;
208 }
209 324
210 if (ACPI_FAILURE(status)) { 325/******************************************************************************
326 *
327 * FUNCTION: acpi_unload_table_id
328 *
329 * PARAMETERS: id - Owner ID of the table to be removed.
330 *
331 * RETURN: Status
332 *
333 * DESCRIPTION: This routine is used to force the unload of a table (by id)
334 *
335 ******************************************************************************/
336acpi_status acpi_unload_table_id(acpi_owner_id id)
337{
338 int i;
339 acpi_status status = AE_NOT_EXIST;
211 340
212 /* Uninstall table and free the buffer */ 341 ACPI_FUNCTION_TRACE(acpi_unload_table);
213 342
214 (void)acpi_tb_uninstall_table(table_info.installed_desc); 343 /* Find table from the requested type list */
344 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
345 if (id != acpi_gbl_root_table_list.tables[i].owner_id) {
346 continue;
347 }
348 /*
349 * Delete all namespace objects owned by this table. Note that these
350 * objects can appear anywhere in the namespace by virtue of the AML
351 * "Scope" operator. Thus, we need to track ownership by an ID, not
352 * simply a position within the hierarchy
353 */
354 acpi_tb_delete_namespace_by_owner(i);
355 acpi_tb_release_owner_id(i);
356 acpi_tb_set_table_loaded_flag(i, FALSE);
215 } 357 }
216
217 return_ACPI_STATUS(status); 358 return_ACPI_STATUS(status);
218} 359}
219 360
220ACPI_EXPORT_SYMBOL(acpi_load_table) 361ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
221 362
222/******************************************************************************* 363/*******************************************************************************
223 * 364 *
224 * FUNCTION: acpi_unload_table 365 * FUNCTION: acpi_get_table
225 * 366 *
226 * PARAMETERS: table_type - Type of table to be unloaded 367 * PARAMETERS: Signature - ACPI signature of needed table
368 * Instance - Which instance (for SSDTs)
369 * out_table - Where the pointer to the table is returned
227 * 370 *
228 * RETURN: Status 371 * RETURN: Status and pointer to table
229 * 372 *
230 * DESCRIPTION: This routine is used to force the unload of a table 373 * DESCRIPTION: Finds and verifies an ACPI table.
231 * 374 *
232 ******************************************************************************/ 375 *****************************************************************************/
233acpi_status acpi_unload_table(acpi_table_type table_type) 376acpi_status
377acpi_get_table(char *signature,
378 acpi_native_uint instance, struct acpi_table_header ** out_table)
234{ 379{
235 struct acpi_table_desc *table_desc; 380 acpi_native_uint i;
236 381 acpi_native_uint j;
237 ACPI_FUNCTION_TRACE(acpi_unload_table); 382 acpi_status status;
238 383
239 /* Parameter validation */ 384 /* Parameter validation */
240 385
241 if (table_type > ACPI_TABLE_ID_MAX) { 386 if (!signature || !out_table) {
242 return_ACPI_STATUS(AE_BAD_PARAMETER); 387 return (AE_BAD_PARAMETER);
243 } 388 }
244 389
245 /* Find all tables of the requested type */ 390 /*
391 * Walk the root table list
392 */
393 for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
394 if (!ACPI_COMPARE_NAME
395 (&(acpi_gbl_root_table_list.tables[i].signature),
396 signature)) {
397 continue;
398 }
246 399
247 table_desc = acpi_gbl_table_lists[table_type].next; 400 if (++j < instance) {
248 if (!table_desc) { 401 continue;
249 return_ACPI_STATUS(AE_NOT_EXIST); 402 }
250 }
251 403
252 while (table_desc) { 404 status =
253 /* 405 acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]);
254 * Delete all namespace objects owned by this table. Note that these 406 if (ACPI_SUCCESS(status)) {
255 * objects can appear anywhere in the namespace by virtue of the AML 407 *out_table = acpi_gbl_root_table_list.tables[i].pointer;
256 * "Scope" operator. Thus, we need to track ownership by an ID, not 408 }
257 * simply a position within the hierarchy
258 */
259 acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
260 table_desc = table_desc->next;
261 }
262 409
263 /* Delete (or unmap) all tables of this type */ 410 if (!acpi_gbl_permanent_mmap) {
411 acpi_gbl_root_table_list.tables[i].pointer = 0;
412 }
264 413
265 acpi_tb_delete_tables_by_type(table_type); 414 return (status);
266 return_ACPI_STATUS(AE_OK); 415 }
416
417 return (AE_NOT_FOUND);
267} 418}
268 419
269ACPI_EXPORT_SYMBOL(acpi_unload_table) 420ACPI_EXPORT_SYMBOL(acpi_get_table)
270 421
271/******************************************************************************* 422/*******************************************************************************
272 * 423 *
273 * FUNCTION: acpi_get_table_header 424 * FUNCTION: acpi_get_table_by_index
274 * 425 *
275 * PARAMETERS: table_type - one of the defined table types 426 * PARAMETERS: table_index - Table index
276 * Instance - the non zero instance of the table, allows 427 * Table - Where the pointer to the table is returned
277 * support for multiple tables of the same type
278 * see acpi_gbl_acpi_table_flag
279 * out_table_header - pointer to the struct acpi_table_header if successful
280 * 428 *
281 * DESCRIPTION: This function is called to get an ACPI table header. The caller 429 * RETURN: Status and pointer to the table
282 * supplies an pointer to a data area sufficient to contain an ACPI
283 * struct acpi_table_header structure.
284 * 430 *
285 * The header contains a length field that can be used to determine 431 * DESCRIPTION: Obtain a table by an index into the global table list.
286 * the size of the buffer needed to contain the entire table. This
287 * function is not valid for the RSD PTR table since it does not
288 * have a standard header and is fixed length.
289 * 432 *
290 ******************************************************************************/ 433 ******************************************************************************/
291acpi_status 434acpi_status
292acpi_get_table_header(acpi_table_type table_type, 435acpi_get_table_by_index(acpi_native_uint table_index,
293 u32 instance, struct acpi_table_header *out_table_header) 436 struct acpi_table_header ** table)
294{ 437{
295 struct acpi_table_header *tbl_ptr;
296 acpi_status status; 438 acpi_status status;
297 439
298 ACPI_FUNCTION_TRACE(acpi_get_table_header); 440 ACPI_FUNCTION_TRACE(acpi_get_table_by_index);
441
442 /* Parameter validation */
299 443
300 if ((instance == 0) || 444 if (!table) {
301 (table_type == ACPI_TABLE_ID_RSDP) || (!out_table_header)) {
302 return_ACPI_STATUS(AE_BAD_PARAMETER); 445 return_ACPI_STATUS(AE_BAD_PARAMETER);
303 } 446 }
304 447
305 /* Check the table type and instance */ 448 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
306 449
307 if ((table_type > ACPI_TABLE_ID_MAX) || 450 /* Validate index */
308 (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) && 451
309 instance > 1)) { 452 if (table_index >= acpi_gbl_root_table_list.count) {
453 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
310 return_ACPI_STATUS(AE_BAD_PARAMETER); 454 return_ACPI_STATUS(AE_BAD_PARAMETER);
311 } 455 }
312 456
313 /* Get a pointer to the entire table */ 457 if (!acpi_gbl_root_table_list.tables[table_index].pointer) {
314
315 status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
316 if (ACPI_FAILURE(status)) {
317 return_ACPI_STATUS(status);
318 }
319 458
320 /* The function will return a NULL pointer if the table is not loaded */ 459 /* Table is not mapped, map it */
321 460
322 if (tbl_ptr == NULL) { 461 status =
323 return_ACPI_STATUS(AE_NOT_EXIST); 462 acpi_tb_verify_table(&acpi_gbl_root_table_list.
463 tables[table_index]);
464 if (ACPI_FAILURE(status)) {
465 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
466 return_ACPI_STATUS(status);
467 }
324 } 468 }
325 469
326 /* Copy the header to the caller's buffer */ 470 *table = acpi_gbl_root_table_list.tables[table_index].pointer;
327 471 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
328 ACPI_MEMCPY(ACPI_CAST_PTR(void, out_table_header), 472 return_ACPI_STATUS(AE_OK);
329 ACPI_CAST_PTR(void, tbl_ptr),
330 sizeof(struct acpi_table_header));
331
332 return_ACPI_STATUS(status);
333} 473}
334 474
335ACPI_EXPORT_SYMBOL(acpi_get_table_header) 475ACPI_EXPORT_SYMBOL(acpi_get_table_by_index)
336#endif /* ACPI_FUTURE_USAGE */
337 476
338/******************************************************************************* 477/*******************************************************************************
339 * 478 *
340 * FUNCTION: acpi_get_table 479 * FUNCTION: acpi_tb_load_namespace
341 * 480 *
342 * PARAMETERS: table_type - one of the defined table types 481 * PARAMETERS: None
343 * Instance - the non zero instance of the table, allows
344 * support for multiple tables of the same type
345 * see acpi_gbl_acpi_table_flag
346 * ret_buffer - pointer to a structure containing a buffer to
347 * receive the table
348 * 482 *
349 * RETURN: Status 483 * RETURN: Status
350 * 484 *
351 * DESCRIPTION: This function is called to get an ACPI table. The caller 485 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
352 * supplies an out_buffer large enough to contain the entire ACPI 486 * the RSDT/XSDT.
353 * table. The caller should call the acpi_get_table_header function
354 * first to determine the buffer size needed. Upon completion
355 * the out_buffer->Length field will indicate the number of bytes
356 * copied into the out_buffer->buf_ptr buffer. This table will be
357 * a complete table including the header.
358 * 487 *
359 ******************************************************************************/ 488 ******************************************************************************/
360acpi_status 489static acpi_status acpi_tb_load_namespace(void)
361acpi_get_table(acpi_table_type table_type,
362 u32 instance, struct acpi_buffer *ret_buffer)
363{ 490{
364 struct acpi_table_header *tbl_ptr;
365 acpi_status status; 491 acpi_status status;
366 acpi_size table_length; 492 struct acpi_table_header *table;
493 acpi_native_uint i;
367 494
368 ACPI_FUNCTION_TRACE(acpi_get_table); 495 ACPI_FUNCTION_TRACE(tb_load_namespace);
369 496
370 /* Parameter validation */ 497 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
371 498
372 if (instance == 0) { 499 /*
373 return_ACPI_STATUS(AE_BAD_PARAMETER); 500 * Load the namespace. The DSDT is required, but any SSDT and PSDT tables
501 * are optional.
502 */
503 if (!acpi_gbl_root_table_list.count ||
504 !ACPI_COMPARE_NAME(&
505 (acpi_gbl_root_table_list.
506 tables[ACPI_TABLE_INDEX_DSDT].signature),
507 ACPI_SIG_DSDT)
508 ||
509 ACPI_FAILURE(acpi_tb_verify_table
510 (&acpi_gbl_root_table_list.
511 tables[ACPI_TABLE_INDEX_DSDT]))) {
512 status = AE_NO_ACPI_TABLES;
513 goto unlock_and_exit;
374 } 514 }
375 515
376 status = acpi_ut_validate_buffer(ret_buffer); 516 /*
377 if (ACPI_FAILURE(status)) { 517 * Find DSDT table
378 return_ACPI_STATUS(status); 518 */
519 status =
520 acpi_os_table_override(acpi_gbl_root_table_list.
521 tables[ACPI_TABLE_INDEX_DSDT].pointer,
522 &table);
523 if (ACPI_SUCCESS(status) && table) {
524 /*
525 * DSDT table has been found
526 */
527 acpi_tb_delete_table(&acpi_gbl_root_table_list.
528 tables[ACPI_TABLE_INDEX_DSDT]);
529 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer =
530 table;
531 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].length =
532 table->length;
533 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].flags =
534 ACPI_TABLE_ORIGIN_UNKNOWN;
535
536 ACPI_INFO((AE_INFO, "Table DSDT replaced by host OS"));
537 acpi_tb_print_table_header(0, table);
379 } 538 }
380 539
381 /* Check the table type and instance */ 540 status =
541 acpi_tb_verify_table(&acpi_gbl_root_table_list.
542 tables[ACPI_TABLE_INDEX_DSDT]);
543 if (ACPI_FAILURE(status)) {
382 544
383 if ((table_type > ACPI_TABLE_ID_MAX) || 545 /* A valid DSDT is required */
384 (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) && 546
385 instance > 1)) { 547 status = AE_NO_ACPI_TABLES;
386 return_ACPI_STATUS(AE_BAD_PARAMETER); 548 goto unlock_and_exit;
387 } 549 }
388 550
389 /* Get a pointer to the entire table */ 551 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
390 552
391 status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr); 553 /*
554 * Load and parse tables.
555 */
556 status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node);
392 if (ACPI_FAILURE(status)) { 557 if (ACPI_FAILURE(status)) {
393 return_ACPI_STATUS(status); 558 return_ACPI_STATUS(status);
394 } 559 }
395 560
396 /* 561 /*
397 * acpi_tb_get_table_ptr will return a NULL pointer if the 562 * Load any SSDT or PSDT tables. Note: Loop leaves tables locked
398 * table is not loaded.
399 */ 563 */
400 if (tbl_ptr == NULL) { 564 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
401 return_ACPI_STATUS(AE_NOT_EXIST); 565 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
566 if ((!ACPI_COMPARE_NAME
567 (&(acpi_gbl_root_table_list.tables[i].signature),
568 ACPI_SIG_SSDT)
569 &&
570 !ACPI_COMPARE_NAME(&
571 (acpi_gbl_root_table_list.tables[i].
572 signature), ACPI_SIG_PSDT))
573 ||
574 ACPI_FAILURE(acpi_tb_verify_table
575 (&acpi_gbl_root_table_list.tables[i]))) {
576 continue;
577 }
578
579 /* Ignore errors while loading tables, get as many as possible */
580
581 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
582 (void)acpi_ns_load_table(i, acpi_gbl_root_node);
583 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
402 } 584 }
403 585
404 /* Get the table length */ 586 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
405 587
406 if (table_type == ACPI_TABLE_ID_RSDP) { 588 unlock_and_exit:
589 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
590 return_ACPI_STATUS(status);
591}
407 592
408 /* RSD PTR is the only "table" without a header */ 593/*******************************************************************************
594 *
595 * FUNCTION: acpi_load_tables
596 *
597 * PARAMETERS: None
598 *
599 * RETURN: Status
600 *
601 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
602 *
603 ******************************************************************************/
409 604
410 table_length = sizeof(struct rsdp_descriptor); 605acpi_status acpi_load_tables(void)
411 } else { 606{
412 table_length = (acpi_size) tbl_ptr->length; 607 acpi_status status;
413 }
414 608
415 /* Validate/Allocate/Clear caller buffer */ 609 ACPI_FUNCTION_TRACE(acpi_load_tables);
416 610
417 status = acpi_ut_initialize_buffer(ret_buffer, table_length); 611 /*
612 * Load the namespace from the tables
613 */
614 status = acpi_tb_load_namespace();
418 if (ACPI_FAILURE(status)) { 615 if (ACPI_FAILURE(status)) {
419 return_ACPI_STATUS(status); 616 ACPI_EXCEPTION((AE_INFO, status,
617 "While loading namespace from ACPI tables"));
420 } 618 }
421 619
422 /* Copy the table to the buffer */ 620 return_ACPI_STATUS(status);
423
424 ACPI_MEMCPY(ACPI_CAST_PTR(void, ret_buffer->pointer),
425 ACPI_CAST_PTR(void, tbl_ptr), table_length);
426
427 return_ACPI_STATUS(AE_OK);
428} 621}
429 622
430ACPI_EXPORT_SYMBOL(acpi_get_table) 623ACPI_EXPORT_SYMBOL(acpi_load_tables)
diff --git a/drivers/acpi/tables/tbxfroot.c b/drivers/acpi/tables/tbxfroot.c
index da2648bbdb..cf8fa51418 100644
--- a/drivers/acpi/tables/tbxfroot.c
+++ b/drivers/acpi/tables/tbxfroot.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -48,16 +48,15 @@
48ACPI_MODULE_NAME("tbxfroot") 48ACPI_MODULE_NAME("tbxfroot")
49 49
50/* Local prototypes */ 50/* Local prototypes */
51static acpi_status
52acpi_tb_find_rsdp(struct acpi_table_desc *table_info, u32 flags);
53
54static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length); 51static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length);
55 52
53static acpi_status acpi_tb_validate_rsdp(struct acpi_table_rsdp *rsdp);
54
56/******************************************************************************* 55/*******************************************************************************
57 * 56 *
58 * FUNCTION: acpi_tb_validate_rsdp 57 * FUNCTION: acpi_tb_validate_rsdp
59 * 58 *
60 * PARAMETERS: Rsdp - Pointer to unvalidated RSDP 59 * PARAMETERS: Rsdp - Pointer to unvalidated RSDP
61 * 60 *
62 * RETURN: Status 61 * RETURN: Status
63 * 62 *
@@ -65,14 +64,18 @@ static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length);
65 * 64 *
66 ******************************************************************************/ 65 ******************************************************************************/
67 66
68acpi_status acpi_tb_validate_rsdp(struct rsdp_descriptor *rsdp) 67static acpi_status acpi_tb_validate_rsdp(struct acpi_table_rsdp *rsdp)
69{ 68{
70 ACPI_FUNCTION_ENTRY(); 69 ACPI_FUNCTION_ENTRY();
71 70
72 /* 71 /*
73 * The signature and checksum must both be correct 72 * The signature and checksum must both be correct
73 *
74 * Note: Sometimes there exists more than one RSDP in memory; the valid
75 * RSDP has a valid checksum, all others have an invalid checksum.
74 */ 76 */
75 if (ACPI_STRNCMP((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0) { 77 if (ACPI_STRNCMP((char *)rsdp, ACPI_SIG_RSDP, sizeof(ACPI_SIG_RSDP) - 1)
78 != 0) {
76 79
77 /* Nope, BAD Signature */ 80 /* Nope, BAD Signature */
78 81
@@ -81,14 +84,14 @@ acpi_status acpi_tb_validate_rsdp(struct rsdp_descriptor *rsdp)
81 84
82 /* Check the standard checksum */ 85 /* Check the standard checksum */
83 86
84 if (acpi_tb_sum_table(rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) { 87 if (acpi_tb_checksum((u8 *) rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) {
85 return (AE_BAD_CHECKSUM); 88 return (AE_BAD_CHECKSUM);
86 } 89 }
87 90
88 /* Check extended checksum if table version >= 2 */ 91 /* Check extended checksum if table version >= 2 */
89 92
90 if ((rsdp->revision >= 2) && 93 if ((rsdp->revision >= 2) &&
91 (acpi_tb_sum_table(rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0)) { 94 (acpi_tb_checksum((u8 *) rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0)) {
92 return (AE_BAD_CHECKSUM); 95 return (AE_BAD_CHECKSUM);
93 } 96 }
94 97
@@ -97,314 +100,123 @@ acpi_status acpi_tb_validate_rsdp(struct rsdp_descriptor *rsdp)
97 100
98/******************************************************************************* 101/*******************************************************************************
99 * 102 *
100 * FUNCTION: acpi_tb_find_table 103 * FUNCTION: acpi_tb_find_rsdp
101 *
102 * PARAMETERS: Signature - String with ACPI table signature
103 * oem_id - String with the table OEM ID
104 * oem_table_id - String with the OEM Table ID
105 * table_ptr - Where the table pointer is returned
106 *
107 * RETURN: Status
108 * 104 *
109 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the 105 * PARAMETERS: table_address - Where the table pointer is returned
110 * Signature, OEM ID and OEM Table ID.
111 * 106 *
112 ******************************************************************************/ 107 * RETURN: Status, RSDP physical address
113
114acpi_status
115acpi_tb_find_table(char *signature,
116 char *oem_id,
117 char *oem_table_id, struct acpi_table_header ** table_ptr)
118{
119 acpi_status status;
120 struct acpi_table_header *table;
121
122 ACPI_FUNCTION_TRACE(tb_find_table);
123
124 /* Validate string lengths */
125
126 if ((ACPI_STRLEN(signature) > ACPI_NAME_SIZE) ||
127 (ACPI_STRLEN(oem_id) > sizeof(table->oem_id)) ||
128 (ACPI_STRLEN(oem_table_id) > sizeof(table->oem_table_id))) {
129 return_ACPI_STATUS(AE_AML_STRING_LIMIT);
130 }
131
132 if (ACPI_COMPARE_NAME(signature, DSDT_SIG)) {
133 /*
134 * The DSDT pointer is contained in the FADT, not the RSDT.
135 * This code should suffice, because the only code that would perform
136 * a "find" on the DSDT is the data_table_region() AML opcode -- in
137 * which case, the DSDT is guaranteed to be already loaded.
138 * If this becomes insufficient, the FADT will have to be found first.
139 */
140 if (!acpi_gbl_DSDT) {
141 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
142 }
143 table = acpi_gbl_DSDT;
144 } else {
145 /* Find the table */
146
147 status = acpi_get_firmware_table(signature, 1,
148 ACPI_LOGICAL_ADDRESSING,
149 &table);
150 if (ACPI_FAILURE(status)) {
151 return_ACPI_STATUS(status);
152 }
153 }
154
155 /* Check oem_id and oem_table_id */
156
157 if ((oem_id[0] &&
158 ACPI_STRNCMP(oem_id, table->oem_id,
159 sizeof(table->oem_id))) ||
160 (oem_table_id[0] &&
161 ACPI_STRNCMP(oem_table_id, table->oem_table_id,
162 sizeof(table->oem_table_id)))) {
163 return_ACPI_STATUS(AE_AML_NAME_NOT_FOUND);
164 }
165
166 ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Found table [%4.4s]\n",
167 table->signature));
168
169 *table_ptr = table;
170 return_ACPI_STATUS(AE_OK);
171}
172
173/*******************************************************************************
174 *
175 * FUNCTION: acpi_get_firmware_table
176 * 108 *
177 * PARAMETERS: Signature - Any ACPI table signature 109 * DESCRIPTION: Search lower 1_mbyte of memory for the root system descriptor
178 * Instance - the non zero instance of the table, allows 110 * pointer structure. If it is found, set *RSDP to point to it.
179 * support for multiple tables of the same type
180 * Flags - Physical/Virtual support
181 * table_pointer - Where a buffer containing the table is
182 * returned
183 * 111 *
184 * RETURN: Status 112 * NOTE1: The RSDP must be either in the first 1_k of the Extended
113 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
114 * Only a 32-bit physical address is necessary.
185 * 115 *
186 * DESCRIPTION: This function is called to get an ACPI table. A buffer is 116 * NOTE2: This function is always available, regardless of the
187 * allocated for the table and returned in table_pointer. 117 * initialization state of the rest of ACPI.
188 * This table will be a complete table including the header.
189 * 118 *
190 ******************************************************************************/ 119 ******************************************************************************/
191 120
192acpi_status 121acpi_status acpi_find_root_pointer(acpi_native_uint * table_address)
193acpi_get_firmware_table(acpi_string signature,
194 u32 instance,
195 u32 flags, struct acpi_table_header **table_pointer)
196{ 122{
197 acpi_status status; 123 u8 *table_ptr;
198 struct acpi_pointer address; 124 u8 *mem_rover;
199 struct acpi_table_header *header = NULL; 125 u32 physical_address;
200 struct acpi_table_desc *table_info = NULL;
201 struct acpi_table_desc *rsdt_info;
202 u32 table_count;
203 u32 i;
204 u32 j;
205
206 ACPI_FUNCTION_TRACE(acpi_get_firmware_table);
207
208 /*
209 * Ensure that at least the table manager is initialized. We don't
210 * require that the entire ACPI subsystem is up for this interface.
211 * If we have a buffer, we must have a length too
212 */
213 if ((instance == 0) || (!signature) || (!table_pointer)) {
214 return_ACPI_STATUS(AE_BAD_PARAMETER);
215 }
216
217 /* Ensure that we have a RSDP */
218
219 if (!acpi_gbl_RSDP) {
220
221 /* Get the RSDP */
222
223 status = acpi_os_get_root_pointer(flags, &address);
224 if (ACPI_FAILURE(status)) {
225 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "RSDP not found\n"));
226 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
227 }
228
229 /* Map and validate the RSDP */
230
231 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
232 status = acpi_os_map_memory(address.pointer.physical,
233 sizeof(struct
234 rsdp_descriptor),
235 (void *)&acpi_gbl_RSDP);
236 if (ACPI_FAILURE(status)) {
237 return_ACPI_STATUS(status);
238 }
239 } else {
240 acpi_gbl_RSDP = address.pointer.logical;
241 }
242
243 /* The RDSP signature and checksum must both be correct */
244
245 status = acpi_tb_validate_rsdp(acpi_gbl_RSDP);
246 if (ACPI_FAILURE(status)) {
247 return_ACPI_STATUS(status);
248 }
249 }
250
251 /* Get the RSDT address via the RSDP */
252
253 acpi_tb_get_rsdt_address(&address);
254 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
255 "RSDP located at %p, RSDT physical=%8.8X%8.8X\n",
256 acpi_gbl_RSDP,
257 ACPI_FORMAT_UINT64(address.pointer.value)));
258 126
259 /* Insert processor_mode flags */ 127 ACPI_FUNCTION_TRACE(acpi_find_root_pointer);
260 128
261 address.pointer_type |= flags; 129 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
262 130
263 /* Get and validate the RSDT */ 131 table_ptr = acpi_os_map_memory((acpi_physical_address)
132 ACPI_EBDA_PTR_LOCATION,
133 ACPI_EBDA_PTR_LENGTH);
134 if (!table_ptr) {
135 ACPI_ERROR((AE_INFO,
136 "Could not map memory at %8.8X for length %X",
137 ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
264 138
265 rsdt_info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_table_desc));
266 if (!rsdt_info) {
267 return_ACPI_STATUS(AE_NO_MEMORY); 139 return_ACPI_STATUS(AE_NO_MEMORY);
268 } 140 }
269 141
270 status = acpi_tb_get_table(&address, rsdt_info); 142 ACPI_MOVE_16_TO_32(&physical_address, table_ptr);
271 if (ACPI_FAILURE(status)) {
272 goto cleanup;
273 }
274
275 status = acpi_tb_validate_rsdt(rsdt_info->pointer);
276 if (ACPI_FAILURE(status)) {
277 goto cleanup;
278 }
279 143
280 /* Allocate a scratch table header and table descriptor */ 144 /* Convert segment part to physical address */
281 145
282 header = ACPI_ALLOCATE(sizeof(struct acpi_table_header)); 146 physical_address <<= 4;
283 if (!header) { 147 acpi_os_unmap_memory(table_ptr, ACPI_EBDA_PTR_LENGTH);
284 status = AE_NO_MEMORY;
285 goto cleanup;
286 }
287 148
288 table_info = ACPI_ALLOCATE(sizeof(struct acpi_table_desc)); 149 /* EBDA present? */
289 if (!table_info) {
290 status = AE_NO_MEMORY;
291 goto cleanup;
292 }
293 150
294 /* Get the number of table pointers within the RSDT */ 151 if (physical_address > 0x400) {
295
296 table_count =
297 acpi_tb_get_table_count(acpi_gbl_RSDP, rsdt_info->pointer);
298 address.pointer_type = acpi_gbl_table_flags | flags;
299
300 /*
301 * Search the RSDT/XSDT for the correct instance of the
302 * requested table
303 */
304 for (i = 0, j = 0; i < table_count; i++) {
305 /* 152 /*
306 * Get the next table pointer, handle RSDT vs. XSDT 153 * 1b) Search EBDA paragraphs (EBDA is required to be a
307 * RSDT pointers are 32 bits, XSDT pointers are 64 bits 154 * minimum of 1_k length)
308 */ 155 */
309 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { 156 table_ptr = acpi_os_map_memory((acpi_native_uint)
310 address.pointer.value = 157 physical_address,
311 (ACPI_CAST_PTR 158 ACPI_EBDA_WINDOW_SIZE);
312 (struct rsdt_descriptor, 159 if (!table_ptr) {
313 rsdt_info->pointer))->table_offset_entry[i]; 160 ACPI_ERROR((AE_INFO,
314 } else { 161 "Could not map memory at %8.8X for length %X",
315 address.pointer.value = 162 physical_address, ACPI_EBDA_WINDOW_SIZE));
316 (ACPI_CAST_PTR
317 (struct xsdt_descriptor,
318 rsdt_info->pointer))->table_offset_entry[i];
319 }
320
321 /* Get the table header */
322 163
323 status = acpi_tb_get_table_header(&address, header); 164 return_ACPI_STATUS(AE_NO_MEMORY);
324 if (ACPI_FAILURE(status)) {
325 goto cleanup;
326 } 165 }
327 166
328 /* Compare table signatures and table instance */ 167 mem_rover =
329 168 acpi_tb_scan_memory_for_rsdp(table_ptr,
330 if (ACPI_COMPARE_NAME(header->signature, signature)) { 169 ACPI_EBDA_WINDOW_SIZE);
331 170 acpi_os_unmap_memory(table_ptr, ACPI_EBDA_WINDOW_SIZE);
332 /* An instance of the table was found */
333 171
334 j++; 172 if (mem_rover) {
335 if (j >= instance) {
336 173
337 /* Found the correct instance, get the entire table */ 174 /* Return the physical address */
338 175
339 status = 176 physical_address +=
340 acpi_tb_get_table_body(&address, header, 177 (u32) ACPI_PTR_DIFF(mem_rover, table_ptr);
341 table_info);
342 if (ACPI_FAILURE(status)) {
343 goto cleanup;
344 }
345 178
346 *table_pointer = table_info->pointer; 179 *table_address = physical_address;
347 goto cleanup; 180 return_ACPI_STATUS(AE_OK);
348 }
349 } 181 }
350 } 182 }
351 183
352 /* Did not find the table */ 184 /*
185 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
186 */
187 table_ptr = acpi_os_map_memory((acpi_physical_address)
188 ACPI_HI_RSDP_WINDOW_BASE,
189 ACPI_HI_RSDP_WINDOW_SIZE);
353 190
354 status = AE_NOT_EXIST; 191 if (!table_ptr) {
192 ACPI_ERROR((AE_INFO,
193 "Could not map memory at %8.8X for length %X",
194 ACPI_HI_RSDP_WINDOW_BASE,
195 ACPI_HI_RSDP_WINDOW_SIZE));
355 196
356 cleanup: 197 return_ACPI_STATUS(AE_NO_MEMORY);
357 if (rsdt_info->pointer) {
358 acpi_os_unmap_memory(rsdt_info->pointer,
359 (acpi_size) rsdt_info->pointer->length);
360 } 198 }
361 ACPI_FREE(rsdt_info);
362 199
363 if (header) { 200 mem_rover =
364 ACPI_FREE(header); 201 acpi_tb_scan_memory_for_rsdp(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
365 } 202 acpi_os_unmap_memory(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
366 if (table_info) {
367 ACPI_FREE(table_info);
368 }
369 return_ACPI_STATUS(status);
370}
371 203
372ACPI_EXPORT_SYMBOL(acpi_get_firmware_table) 204 if (mem_rover) {
373 205
374/* TBD: Move to a new file */ 206 /* Return the physical address */
375#if ACPI_MACHINE_WIDTH != 16
376/*******************************************************************************
377 *
378 * FUNCTION: acpi_find_root_pointer
379 *
380 * PARAMETERS: Flags - Logical/Physical addressing
381 * rsdp_address - Where to place the RSDP address
382 *
383 * RETURN: Status, Physical address of the RSDP
384 *
385 * DESCRIPTION: Find the RSDP
386 *
387 ******************************************************************************/
388acpi_status acpi_find_root_pointer(u32 flags, struct acpi_pointer *rsdp_address)
389{
390 struct acpi_table_desc table_info;
391 acpi_status status;
392
393 ACPI_FUNCTION_TRACE(acpi_find_root_pointer);
394
395 /* Get the RSDP */
396 207
397 status = acpi_tb_find_rsdp(&table_info, flags); 208 physical_address = (u32)
398 if (ACPI_FAILURE(status)) { 209 (ACPI_HI_RSDP_WINDOW_BASE +
399 ACPI_EXCEPTION((AE_INFO, status, 210 ACPI_PTR_DIFF(mem_rover, table_ptr));
400 "RSDP structure not found - Flags=%X", flags));
401 211
402 return_ACPI_STATUS(AE_NO_ACPI_TABLES); 212 *table_address = physical_address;
213 return_ACPI_STATUS(AE_OK);
403 } 214 }
404 215
405 rsdp_address->pointer_type = ACPI_PHYSICAL_POINTER; 216 /* A valid RSDP was not found */
406 rsdp_address->pointer.physical = table_info.physical_address; 217
407 return_ACPI_STATUS(AE_OK); 218 ACPI_ERROR((AE_INFO, "A valid RSDP was not found"));
219 return_ACPI_STATUS(AE_NOT_FOUND);
408} 220}
409 221
410ACPI_EXPORT_SYMBOL(acpi_find_root_pointer) 222ACPI_EXPORT_SYMBOL(acpi_find_root_pointer)
@@ -440,7 +252,7 @@ static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length)
440 252
441 status = 253 status =
442 acpi_tb_validate_rsdp(ACPI_CAST_PTR 254 acpi_tb_validate_rsdp(ACPI_CAST_PTR
443 (struct rsdp_descriptor, mem_rover)); 255 (struct acpi_table_rsdp, mem_rover));
444 if (ACPI_SUCCESS(status)) { 256 if (ACPI_SUCCESS(status)) {
445 257
446 /* Sig and checksum valid, we have found a real RSDP */ 258 /* Sig and checksum valid, we have found a real RSDP */
@@ -461,189 +273,3 @@ static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length)
461 start_address)); 273 start_address));
462 return_PTR(NULL); 274 return_PTR(NULL);
463} 275}
464
465/*******************************************************************************
466 *
467 * FUNCTION: acpi_tb_find_rsdp
468 *
469 * PARAMETERS: table_info - Where the table info is returned
470 * Flags - Current memory mode (logical vs.
471 * physical addressing)
472 *
473 * RETURN: Status, RSDP physical address
474 *
475 * DESCRIPTION: Search lower 1_mbyte of memory for the root system descriptor
476 * pointer structure. If it is found, set *RSDP to point to it.
477 *
478 * NOTE1: The RSDP must be either in the first 1_k of the Extended
479 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
480 * Only a 32-bit physical address is necessary.
481 *
482 * NOTE2: This function is always available, regardless of the
483 * initialization state of the rest of ACPI.
484 *
485 ******************************************************************************/
486
487static acpi_status
488acpi_tb_find_rsdp(struct acpi_table_desc *table_info, u32 flags)
489{
490 u8 *table_ptr;
491 u8 *mem_rover;
492 u32 physical_address;
493 acpi_status status;
494
495 ACPI_FUNCTION_TRACE(tb_find_rsdp);
496
497 /*
498 * Scan supports either logical addressing or physical addressing
499 */
500 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
501
502 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
503
504 status = acpi_os_map_memory((acpi_physical_address)
505 ACPI_EBDA_PTR_LOCATION,
506 ACPI_EBDA_PTR_LENGTH,
507 (void *)&table_ptr);
508 if (ACPI_FAILURE(status)) {
509 ACPI_ERROR((AE_INFO,
510 "Could not map memory at %8.8X for length %X",
511 ACPI_EBDA_PTR_LOCATION,
512 ACPI_EBDA_PTR_LENGTH));
513
514 return_ACPI_STATUS(status);
515 }
516
517 ACPI_MOVE_16_TO_32(&physical_address, table_ptr);
518
519 /* Convert segment part to physical address */
520
521 physical_address <<= 4;
522 acpi_os_unmap_memory(table_ptr, ACPI_EBDA_PTR_LENGTH);
523
524 /* EBDA present? */
525
526 if (physical_address > 0x400) {
527 /*
528 * 1b) Search EBDA paragraphs (EBDA is required to be a
529 * minimum of 1_k length)
530 */
531 status = acpi_os_map_memory((acpi_physical_address)
532 physical_address,
533 ACPI_EBDA_WINDOW_SIZE,
534 (void *)&table_ptr);
535 if (ACPI_FAILURE(status)) {
536 ACPI_ERROR((AE_INFO,
537 "Could not map memory at %8.8X for length %X",
538 physical_address,
539 ACPI_EBDA_WINDOW_SIZE));
540
541 return_ACPI_STATUS(status);
542 }
543
544 mem_rover = acpi_tb_scan_memory_for_rsdp(table_ptr,
545 ACPI_EBDA_WINDOW_SIZE);
546 acpi_os_unmap_memory(table_ptr, ACPI_EBDA_WINDOW_SIZE);
547
548 if (mem_rover) {
549
550 /* Return the physical address */
551
552 physical_address +=
553 (u32) ACPI_PTR_DIFF(mem_rover, table_ptr);
554
555 table_info->physical_address =
556 (acpi_physical_address) physical_address;
557 return_ACPI_STATUS(AE_OK);
558 }
559 }
560
561 /*
562 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
563 */
564 status = acpi_os_map_memory((acpi_physical_address)
565 ACPI_HI_RSDP_WINDOW_BASE,
566 ACPI_HI_RSDP_WINDOW_SIZE,
567 (void *)&table_ptr);
568
569 if (ACPI_FAILURE(status)) {
570 ACPI_ERROR((AE_INFO,
571 "Could not map memory at %8.8X for length %X",
572 ACPI_HI_RSDP_WINDOW_BASE,
573 ACPI_HI_RSDP_WINDOW_SIZE));
574
575 return_ACPI_STATUS(status);
576 }
577
578 mem_rover =
579 acpi_tb_scan_memory_for_rsdp(table_ptr,
580 ACPI_HI_RSDP_WINDOW_SIZE);
581 acpi_os_unmap_memory(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
582
583 if (mem_rover) {
584
585 /* Return the physical address */
586
587 physical_address = (u32)
588 (ACPI_HI_RSDP_WINDOW_BASE +
589 ACPI_PTR_DIFF(mem_rover, table_ptr));
590
591 table_info->physical_address =
592 (acpi_physical_address) physical_address;
593 return_ACPI_STATUS(AE_OK);
594 }
595 }
596
597 /*
598 * Physical addressing
599 */
600 else {
601 /* 1a) Get the location of the EBDA */
602
603 ACPI_MOVE_16_TO_32(&physical_address, ACPI_EBDA_PTR_LOCATION);
604 physical_address <<= 4; /* Convert segment to physical address */
605
606 /* EBDA present? */
607
608 if (physical_address > 0x400) {
609 /*
610 * 1b) Search EBDA paragraphs (EBDA is required to be a minimum of
611 * 1_k length)
612 */
613 mem_rover =
614 acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
615 (physical_address),
616 ACPI_EBDA_WINDOW_SIZE);
617 if (mem_rover) {
618
619 /* Return the physical address */
620
621 table_info->physical_address =
622 ACPI_TO_INTEGER(mem_rover);
623 return_ACPI_STATUS(AE_OK);
624 }
625 }
626
627 /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
628
629 mem_rover =
630 acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
631 (ACPI_HI_RSDP_WINDOW_BASE),
632 ACPI_HI_RSDP_WINDOW_SIZE);
633 if (mem_rover) {
634
635 /* Found it, return the physical address */
636
637 table_info->physical_address =
638 ACPI_TO_INTEGER(mem_rover);
639 return_ACPI_STATUS(AE_OK);
640 }
641 }
642
643 /* A valid RSDP was not found */
644
645 ACPI_ERROR((AE_INFO, "No valid RSDP was found"));
646 return_ACPI_STATUS(AE_NOT_FOUND);
647}
648
649#endif
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 3650654f87..f76d3168c2 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -663,7 +663,7 @@ static void acpi_thermal_run(unsigned long data)
663static void acpi_thermal_check(void *data) 663static void acpi_thermal_check(void *data)
664{ 664{
665 int result = 0; 665 int result = 0;
666 struct acpi_thermal *tz = (struct acpi_thermal *)data; 666 struct acpi_thermal *tz = data;
667 unsigned long sleep_time = 0; 667 unsigned long sleep_time = 0;
668 int i = 0; 668 int i = 0;
669 struct acpi_thermal_state state; 669 struct acpi_thermal_state state;
@@ -778,7 +778,7 @@ static struct proc_dir_entry *acpi_thermal_dir;
778 778
779static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset) 779static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
780{ 780{
781 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 781 struct acpi_thermal *tz = seq->private;
782 782
783 783
784 if (!tz) 784 if (!tz)
@@ -813,7 +813,7 @@ static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
813static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset) 813static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
814{ 814{
815 int result = 0; 815 int result = 0;
816 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 816 struct acpi_thermal *tz = seq->private;
817 817
818 818
819 if (!tz) 819 if (!tz)
@@ -837,7 +837,7 @@ static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
837 837
838static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset) 838static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
839{ 839{
840 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 840 struct acpi_thermal *tz = seq->private;
841 int i = 0; 841 int i = 0;
842 int j = 0; 842 int j = 0;
843 843
@@ -893,8 +893,8 @@ acpi_thermal_write_trip_points(struct file *file,
893 const char __user * buffer, 893 const char __user * buffer,
894 size_t count, loff_t * ppos) 894 size_t count, loff_t * ppos)
895{ 895{
896 struct seq_file *m = (struct seq_file *)file->private_data; 896 struct seq_file *m = file->private_data;
897 struct acpi_thermal *tz = (struct acpi_thermal *)m->private; 897 struct acpi_thermal *tz = m->private;
898 898
899 char *limit_string; 899 char *limit_string;
900 int num, critical, hot, passive; 900 int num, critical, hot, passive;
@@ -902,12 +902,10 @@ acpi_thermal_write_trip_points(struct file *file,
902 int i = 0; 902 int i = 0;
903 903
904 904
905 limit_string = kmalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL); 905 limit_string = kzalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL);
906 if (!limit_string) 906 if (!limit_string)
907 return -ENOMEM; 907 return -ENOMEM;
908 908
909 memset(limit_string, 0, ACPI_THERMAL_MAX_LIMIT_STR_LEN);
910
911 active = kmalloc(ACPI_THERMAL_MAX_ACTIVE * sizeof(int), GFP_KERNEL); 909 active = kmalloc(ACPI_THERMAL_MAX_ACTIVE * sizeof(int), GFP_KERNEL);
912 if (!active) { 910 if (!active) {
913 kfree(limit_string); 911 kfree(limit_string);
@@ -953,7 +951,7 @@ acpi_thermal_write_trip_points(struct file *file,
953 951
954static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset) 952static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
955{ 953{
956 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 954 struct acpi_thermal *tz = seq->private;
957 955
958 956
959 if (!tz) 957 if (!tz)
@@ -984,8 +982,8 @@ acpi_thermal_write_cooling_mode(struct file *file,
984 const char __user * buffer, 982 const char __user * buffer,
985 size_t count, loff_t * ppos) 983 size_t count, loff_t * ppos)
986{ 984{
987 struct seq_file *m = (struct seq_file *)file->private_data; 985 struct seq_file *m = file->private_data;
988 struct acpi_thermal *tz = (struct acpi_thermal *)m->private; 986 struct acpi_thermal *tz = m->private;
989 int result = 0; 987 int result = 0;
990 char mode_string[12] = { '\0' }; 988 char mode_string[12] = { '\0' };
991 989
@@ -1014,7 +1012,7 @@ acpi_thermal_write_cooling_mode(struct file *file,
1014 1012
1015static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset) 1013static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1016{ 1014{
1017 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 1015 struct acpi_thermal *tz = seq->private;
1018 1016
1019 1017
1020 if (!tz) 1018 if (!tz)
@@ -1043,8 +1041,8 @@ acpi_thermal_write_polling(struct file *file,
1043 const char __user * buffer, 1041 const char __user * buffer,
1044 size_t count, loff_t * ppos) 1042 size_t count, loff_t * ppos)
1045{ 1043{
1046 struct seq_file *m = (struct seq_file *)file->private_data; 1044 struct seq_file *m = file->private_data;
1047 struct acpi_thermal *tz = (struct acpi_thermal *)m->private; 1045 struct acpi_thermal *tz = m->private;
1048 int result = 0; 1046 int result = 0;
1049 char polling_string[12] = { '\0' }; 1047 char polling_string[12] = { '\0' };
1050 int seconds = 0; 1048 int seconds = 0;
@@ -1170,7 +1168,7 @@ static int acpi_thermal_remove_fs(struct acpi_device *device)
1170 1168
1171static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) 1169static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1172{ 1170{
1173 struct acpi_thermal *tz = (struct acpi_thermal *)data; 1171 struct acpi_thermal *tz = data;
1174 struct acpi_device *device = NULL; 1172 struct acpi_device *device = NULL;
1175 1173
1176 1174
@@ -1271,10 +1269,9 @@ static int acpi_thermal_add(struct acpi_device *device)
1271 if (!device) 1269 if (!device)
1272 return -EINVAL; 1270 return -EINVAL;
1273 1271
1274 tz = kmalloc(sizeof(struct acpi_thermal), GFP_KERNEL); 1272 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1275 if (!tz) 1273 if (!tz)
1276 return -ENOMEM; 1274 return -ENOMEM;
1277 memset(tz, 0, sizeof(struct acpi_thermal));
1278 1275
1279 tz->device = device; 1276 tz->device = device;
1280 strcpy(tz->name, device->pnp.bus_id); 1277 strcpy(tz->name, device->pnp.bus_id);
@@ -1324,7 +1321,7 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1324 if (!device || !acpi_driver_data(device)) 1321 if (!device || !acpi_driver_data(device))
1325 return -EINVAL; 1322 return -EINVAL;
1326 1323
1327 tz = (struct acpi_thermal *)acpi_driver_data(device); 1324 tz = acpi_driver_data(device);
1328 1325
1329 /* avoid timer adding new defer task */ 1326 /* avoid timer adding new defer task */
1330 tz->zombie = 1; 1327 tz->zombie = 1;
@@ -1364,7 +1361,7 @@ static int acpi_thermal_resume(struct acpi_device *device)
1364 if (!device || !acpi_driver_data(device)) 1361 if (!device || !acpi_driver_data(device))
1365 return -EINVAL; 1362 return -EINVAL;
1366 1363
1367 tz = (struct acpi_thermal *)acpi_driver_data(device); 1364 tz = acpi_driver_data(device);
1368 1365
1369 acpi_thermal_get_temperature(tz); 1366 acpi_thermal_get_temperature(tz);
1370 1367
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c
index 7fe0b7ae97..d9b651ffcd 100644
--- a/drivers/acpi/toshiba_acpi.c
+++ b/drivers/acpi/toshiba_acpi.c
@@ -41,6 +41,8 @@
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/types.h> 42#include <linux/types.h>
43#include <linux/proc_fs.h> 43#include <linux/proc_fs.h>
44#include <linux/backlight.h>
45
44#include <asm/uaccess.h> 46#include <asm/uaccess.h>
45 47
46#include <acpi/acpi_drivers.h> 48#include <acpi/acpi_drivers.h>
@@ -210,6 +212,7 @@ static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
210} 212}
211 213
212static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; 214static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
215static struct backlight_device *toshiba_backlight_device;
213static int force_fan; 216static int force_fan;
214static int last_key_event; 217static int last_key_event;
215static int key_event_valid; 218static int key_event_valid;
@@ -271,14 +274,23 @@ dispatch_write(struct file *file, const char __user * buffer,
271 return result; 274 return result;
272} 275}
273 276
274static char *read_lcd(char *p) 277static int get_lcd(struct backlight_device *bd)
275{ 278{
276 u32 hci_result; 279 u32 hci_result;
277 u32 value; 280 u32 value;
278 281
279 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result); 282 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
280 if (hci_result == HCI_SUCCESS) { 283 if (hci_result == HCI_SUCCESS) {
281 value = value >> HCI_LCD_BRIGHTNESS_SHIFT; 284 return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
285 } else
286 return -EFAULT;
287}
288
289static char *read_lcd(char *p)
290{
291 int value = get_lcd(NULL);
292
293 if (value >= 0) {
282 p += sprintf(p, "brightness: %d\n", value); 294 p += sprintf(p, "brightness: %d\n", value);
283 p += sprintf(p, "brightness_levels: %d\n", 295 p += sprintf(p, "brightness_levels: %d\n",
284 HCI_LCD_BRIGHTNESS_LEVELS); 296 HCI_LCD_BRIGHTNESS_LEVELS);
@@ -289,22 +301,37 @@ static char *read_lcd(char *p)
289 return p; 301 return p;
290} 302}
291 303
304static int set_lcd(int value)
305{
306 u32 hci_result;
307
308 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
309 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
310 if (hci_result != HCI_SUCCESS)
311 return -EFAULT;
312
313 return 0;
314}
315
316static int set_lcd_status(struct backlight_device *bd)
317{
318 return set_lcd(bd->props->brightness);
319}
320
292static unsigned long write_lcd(const char *buffer, unsigned long count) 321static unsigned long write_lcd(const char *buffer, unsigned long count)
293{ 322{
294 int value; 323 int value;
295 u32 hci_result; 324 int ret;
296 325
297 if (sscanf(buffer, " brightness : %i", &value) == 1 && 326 if (sscanf(buffer, " brightness : %i", &value) == 1 &&
298 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) { 327 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
299 value = value << HCI_LCD_BRIGHTNESS_SHIFT; 328 ret = set_lcd(value);
300 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result); 329 if (ret == 0)
301 if (hci_result != HCI_SUCCESS) 330 ret = count;
302 return -EFAULT;
303 } else { 331 } else {
304 return -EINVAL; 332 ret = -EINVAL;
305 } 333 }
306 334 return ret;
307 return count;
308} 335}
309 336
310static char *read_video(char *p) 337static char *read_video(char *p)
@@ -506,6 +533,26 @@ static acpi_status __exit remove_device(void)
506 return AE_OK; 533 return AE_OK;
507} 534}
508 535
536static struct backlight_properties toshiba_backlight_data = {
537 .owner = THIS_MODULE,
538 .get_brightness = get_lcd,
539 .update_status = set_lcd_status,
540 .max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1,
541};
542
543static void __exit toshiba_acpi_exit(void)
544{
545 if (toshiba_backlight_device)
546 backlight_device_unregister(toshiba_backlight_device);
547
548 remove_device();
549
550 if (toshiba_proc_dir)
551 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
552
553 return;
554}
555
509static int __init toshiba_acpi_init(void) 556static int __init toshiba_acpi_init(void)
510{ 557{
511 acpi_status status = AE_OK; 558 acpi_status status = AE_OK;
@@ -546,17 +593,16 @@ static int __init toshiba_acpi_init(void)
546 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 593 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
547 } 594 }
548 595
549 return (ACPI_SUCCESS(status)) ? 0 : -ENODEV; 596 toshiba_backlight_device = backlight_device_register("toshiba",NULL,
550} 597 NULL,
551 598 &toshiba_backlight_data);
552static void __exit toshiba_acpi_exit(void) 599 if (IS_ERR(toshiba_backlight_device)) {
553{ 600 printk(KERN_ERR "Could not register toshiba backlight device\n");
554 remove_device(); 601 toshiba_backlight_device = NULL;
555 602 toshiba_acpi_exit();
556 if (toshiba_proc_dir) 603 }
557 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
558 604
559 return; 605 return (ACPI_SUCCESS(status)) ? 0 : -ENODEV;
560} 606}
561 607
562module_init(toshiba_acpi_init); 608module_init(toshiba_acpi_init);
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index f6cbc0b1bf..55a7648074 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -42,6 +42,7 @@
42 */ 42 */
43 43
44#include <acpi/acpi.h> 44#include <acpi/acpi.h>
45#include <acpi/acdebug.h>
45 46
46#define _COMPONENT ACPI_UTILITIES 47#define _COMPONENT ACPI_UTILITIES
47ACPI_MODULE_NAME("utalloc") 48ACPI_MODULE_NAME("utalloc")
@@ -142,6 +143,14 @@ acpi_status acpi_ut_create_caches(void)
142 143
143acpi_status acpi_ut_delete_caches(void) 144acpi_status acpi_ut_delete_caches(void)
144{ 145{
146#ifdef ACPI_DBG_TRACK_ALLOCATIONS
147 char buffer[7];
148
149 if (acpi_gbl_display_final_mem_stats) {
150 ACPI_STRCPY(buffer, "MEMORY");
151 acpi_db_display_statistics(buffer);
152 }
153#endif
145 154
146 (void)acpi_os_delete_cache(acpi_gbl_namespace_cache); 155 (void)acpi_os_delete_cache(acpi_gbl_namespace_cache);
147 acpi_gbl_namespace_cache = NULL; 156 acpi_gbl_namespace_cache = NULL;
diff --git a/drivers/acpi/utilities/utcache.c b/drivers/acpi/utilities/utcache.c
index 1a1f810915..870f6edeb5 100644
--- a/drivers/acpi/utilities/utcache.c
+++ b/drivers/acpi/utilities/utcache.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -289,6 +289,14 @@ void *acpi_os_acquire_object(struct acpi_memory_list *cache)
289 289
290 ACPI_MEM_TRACKING(cache->total_allocated++); 290 ACPI_MEM_TRACKING(cache->total_allocated++);
291 291
292#ifdef ACPI_DBG_TRACK_ALLOCATIONS
293 if ((cache->total_allocated - cache->total_freed) >
294 cache->max_occupied) {
295 cache->max_occupied =
296 cache->total_allocated - cache->total_freed;
297 }
298#endif
299
292 /* Avoid deadlock with ACPI_ALLOCATE_ZEROED */ 300 /* Avoid deadlock with ACPI_ALLOCATE_ZEROED */
293 301
294 status = acpi_ut_release_mutex(ACPI_MTX_CACHES); 302 status = acpi_ut_release_mutex(ACPI_MTX_CACHES);
diff --git a/drivers/acpi/utilities/utcopy.c b/drivers/acpi/utilities/utcopy.c
index 5e1a80d1bc..84d529db0a 100644
--- a/drivers/acpi/utilities/utcopy.c
+++ b/drivers/acpi/utilities/utcopy.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -719,6 +719,15 @@ acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
719 acpi_ut_add_reference(source_desc->reference.object); 719 acpi_ut_add_reference(source_desc->reference.object);
720 break; 720 break;
721 721
722 case ACPI_TYPE_REGION:
723 /*
724 * We copied the Region Handler, so we now must add a reference
725 */
726 if (dest_desc->region.handler) {
727 acpi_ut_add_reference(dest_desc->region.handler);
728 }
729 break;
730
722 default: 731 default:
723 /* Nothing to do for other simple objects */ 732 /* Nothing to do for other simple objects */
724 break; 733 break;
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
index bb1eaf9aa6..61ad4f2dae 100644
--- a/drivers/acpi/utilities/utdebug.c
+++ b/drivers/acpi/utilities/utdebug.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -180,8 +180,8 @@ acpi_ut_debug_print(u32 requested_debug_level,
180 if (thread_id != acpi_gbl_prev_thread_id) { 180 if (thread_id != acpi_gbl_prev_thread_id) {
181 if (ACPI_LV_THREADS & acpi_dbg_level) { 181 if (ACPI_LV_THREADS & acpi_dbg_level) {
182 acpi_os_printf 182 acpi_os_printf
183 ("\n**** Context Switch from TID %X to TID %X ****\n\n", 183 ("\n**** Context Switch from TID %lX to TID %lX ****\n\n",
184 (u32) acpi_gbl_prev_thread_id, (u32) thread_id); 184 (unsigned long)acpi_gbl_prev_thread_id, (unsigned long)thread_id);
185 } 185 }
186 186
187 acpi_gbl_prev_thread_id = thread_id; 187 acpi_gbl_prev_thread_id = thread_id;
@@ -194,7 +194,7 @@ acpi_ut_debug_print(u32 requested_debug_level,
194 acpi_os_printf("%8s-%04ld ", module_name, line_number); 194 acpi_os_printf("%8s-%04ld ", module_name, line_number);
195 195
196 if (ACPI_LV_THREADS & acpi_dbg_level) { 196 if (ACPI_LV_THREADS & acpi_dbg_level) {
197 acpi_os_printf("[%04lX] ", thread_id); 197 acpi_os_printf("[%04lX] ", (unsigned long)thread_id);
198 } 198 }
199 199
200 acpi_os_printf("[%02ld] %-22.22s: ", 200 acpi_os_printf("[%02ld] %-22.22s: ",
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index 9d3f1149ba..f777cebdc4 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -158,16 +158,20 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
158 "***** Mutex %p, OS Mutex %p\n", 158 "***** Mutex %p, OS Mutex %p\n",
159 object, object->mutex.os_mutex)); 159 object, object->mutex.os_mutex));
160 160
161 if (object->mutex.os_mutex != ACPI_GLOBAL_LOCK) { 161 if (object->mutex.os_mutex == acpi_gbl_global_lock_mutex) {
162 acpi_ex_unlink_mutex(object); 162
163 acpi_os_delete_mutex(object->mutex.os_mutex); 163 /* Global Lock has extra semaphore */
164 } else {
165 /* Global Lock "mutex" is actually a counting semaphore */
166 164
167 (void) 165 (void)
168 acpi_os_delete_semaphore 166 acpi_os_delete_semaphore
169 (acpi_gbl_global_lock_semaphore); 167 (acpi_gbl_global_lock_semaphore);
170 acpi_gbl_global_lock_semaphore = NULL; 168 acpi_gbl_global_lock_semaphore = NULL;
169
170 acpi_os_delete_mutex(object->mutex.os_mutex);
171 acpi_gbl_global_lock_mutex = NULL;
172 } else {
173 acpi_ex_unlink_mutex(object);
174 acpi_os_delete_mutex(object->mutex.os_mutex);
171 } 175 }
172 break; 176 break;
173 177
diff --git a/drivers/acpi/utilities/uteval.c b/drivers/acpi/utilities/uteval.c
index d6d7121583..13d5879cd9 100644
--- a/drivers/acpi/utilities/uteval.c
+++ b/drivers/acpi/utilities/uteval.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/utilities/utglobal.c b/drivers/acpi/utilities/utglobal.c
index 014030af8b..af33358a96 100644
--- a/drivers/acpi/utilities/utglobal.c
+++ b/drivers/acpi/utilities/utglobal.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -46,89 +46,9 @@
46#include <acpi/acpi.h> 46#include <acpi/acpi.h>
47#include <acpi/acnamesp.h> 47#include <acpi/acnamesp.h>
48 48
49ACPI_EXPORT_SYMBOL(acpi_gbl_FADT)
49#define _COMPONENT ACPI_UTILITIES 50#define _COMPONENT ACPI_UTILITIES
50ACPI_MODULE_NAME("utglobal") 51 ACPI_MODULE_NAME("utglobal")
51
52/*******************************************************************************
53 *
54 * FUNCTION: acpi_format_exception
55 *
56 * PARAMETERS: Status - The acpi_status code to be formatted
57 *
58 * RETURN: A string containing the exception text. A valid pointer is
59 * always returned.
60 *
61 * DESCRIPTION: This function translates an ACPI exception into an ASCII string.
62 *
63 ******************************************************************************/
64const char *acpi_format_exception(acpi_status status)
65{
66 acpi_status sub_status;
67 const char *exception = NULL;
68
69 ACPI_FUNCTION_ENTRY();
70
71 /*
72 * Status is composed of two parts, a "type" and an actual code
73 */
74 sub_status = (status & ~AE_CODE_MASK);
75
76 switch (status & AE_CODE_MASK) {
77 case AE_CODE_ENVIRONMENTAL:
78
79 if (sub_status <= AE_CODE_ENV_MAX) {
80 exception = acpi_gbl_exception_names_env[sub_status];
81 }
82 break;
83
84 case AE_CODE_PROGRAMMER:
85
86 if (sub_status <= AE_CODE_PGM_MAX) {
87 exception =
88 acpi_gbl_exception_names_pgm[sub_status - 1];
89 }
90 break;
91
92 case AE_CODE_ACPI_TABLES:
93
94 if (sub_status <= AE_CODE_TBL_MAX) {
95 exception =
96 acpi_gbl_exception_names_tbl[sub_status - 1];
97 }
98 break;
99
100 case AE_CODE_AML:
101
102 if (sub_status <= AE_CODE_AML_MAX) {
103 exception =
104 acpi_gbl_exception_names_aml[sub_status - 1];
105 }
106 break;
107
108 case AE_CODE_CONTROL:
109
110 if (sub_status <= AE_CODE_CTRL_MAX) {
111 exception =
112 acpi_gbl_exception_names_ctrl[sub_status - 1];
113 }
114 break;
115
116 default:
117 break;
118 }
119
120 if (!exception) {
121
122 /* Exception code was not recognized */
123
124 ACPI_ERROR((AE_INFO,
125 "Unknown exception code: 0x%8.8X", status));
126
127 exception = "UNKNOWN_STATUS_CODE";
128 }
129
130 return (ACPI_CAST_PTR(const char, exception));
131}
132 52
133/******************************************************************************* 53/*******************************************************************************
134 * 54 *
@@ -163,8 +83,6 @@ u32 acpi_gbl_startup_flags = 0;
163 83
164u8 acpi_gbl_shutdown = TRUE; 84u8 acpi_gbl_shutdown = TRUE;
165 85
166const u8 acpi_gbl_decode_to8bit[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
167
168const char *acpi_gbl_sleep_state_names[ACPI_S_STATE_COUNT] = { 86const char *acpi_gbl_sleep_state_names[ACPI_S_STATE_COUNT] = {
169 "\\_S0_", 87 "\\_S0_",
170 "\\_S1_", 88 "\\_S1_",
@@ -183,10 +101,45 @@ const char *acpi_gbl_highest_dstate_names[4] = {
183 101
184/******************************************************************************* 102/*******************************************************************************
185 * 103 *
186 * Namespace globals 104 * FUNCTION: acpi_format_exception
105 *
106 * PARAMETERS: Status - The acpi_status code to be formatted
107 *
108 * RETURN: A string containing the exception text. A valid pointer is
109 * always returned.
110 *
111 * DESCRIPTION: This function translates an ACPI exception into an ASCII string
112 * It is here instead of utxface.c so it is always present.
187 * 113 *
188 ******************************************************************************/ 114 ******************************************************************************/
189 115
116const char *acpi_format_exception(acpi_status status)
117{
118 const char *exception = NULL;
119
120 ACPI_FUNCTION_ENTRY();
121
122 exception = acpi_ut_validate_exception(status);
123 if (!exception) {
124
125 /* Exception code was not recognized */
126
127 ACPI_ERROR((AE_INFO,
128 "Unknown exception code: 0x%8.8X", status));
129
130 exception = "UNKNOWN_STATUS_CODE";
131 }
132
133 return (ACPI_CAST_PTR(const char, exception));
134}
135
136ACPI_EXPORT_SYMBOL(acpi_format_exception)
137
138/*******************************************************************************
139 *
140 * Namespace globals
141 *
142 ******************************************************************************/
190/* 143/*
191 * Predefined ACPI Names (Built-in to the Interpreter) 144 * Predefined ACPI Names (Built-in to the Interpreter)
192 * 145 *
@@ -280,53 +233,6 @@ char acpi_ut_hex_to_ascii_char(acpi_integer integer, u32 position)
280 return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]); 233 return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]);
281} 234}
282 235
283/*******************************************************************************
284 *
285 * Table name globals
286 *
287 * NOTE: This table includes ONLY the ACPI tables that the subsystem consumes.
288 * it is NOT an exhaustive list of all possible ACPI tables. All ACPI tables
289 * that are not used by the subsystem are simply ignored.
290 *
291 * Do NOT add any table to this list that is not consumed directly by this
292 * subsystem (No MADT, ECDT, SBST, etc.)
293 *
294 ******************************************************************************/
295
296struct acpi_table_list acpi_gbl_table_lists[ACPI_TABLE_ID_MAX + 1];
297
298struct acpi_table_support acpi_gbl_table_data[ACPI_TABLE_ID_MAX + 1] = {
299 /*********** Name, Signature, Global typed pointer Signature size, Type How many allowed?, Contains valid AML? */
300
301 /* RSDP 0 */ {RSDP_NAME, RSDP_SIG, NULL, sizeof(RSDP_SIG) - 1,
302 ACPI_TABLE_ROOT | ACPI_TABLE_SINGLE}
303 ,
304 /* DSDT 1 */ {DSDT_SIG, DSDT_SIG, (void *)&acpi_gbl_DSDT,
305 sizeof(DSDT_SIG) - 1,
306 ACPI_TABLE_SECONDARY | ACPI_TABLE_SINGLE |
307 ACPI_TABLE_EXECUTABLE}
308 ,
309 /* FADT 2 */ {FADT_SIG, FADT_SIG, (void *)&acpi_gbl_FADT,
310 sizeof(FADT_SIG) - 1,
311 ACPI_TABLE_PRIMARY | ACPI_TABLE_SINGLE}
312 ,
313 /* FACS 3 */ {FACS_SIG, FACS_SIG, (void *)&acpi_gbl_FACS,
314 sizeof(FACS_SIG) - 1,
315 ACPI_TABLE_SECONDARY | ACPI_TABLE_SINGLE}
316 ,
317 /* PSDT 4 */ {PSDT_SIG, PSDT_SIG, NULL, sizeof(PSDT_SIG) - 1,
318 ACPI_TABLE_PRIMARY | ACPI_TABLE_MULTIPLE |
319 ACPI_TABLE_EXECUTABLE}
320 ,
321 /* SSDT 5 */ {SSDT_SIG, SSDT_SIG, NULL, sizeof(SSDT_SIG) - 1,
322 ACPI_TABLE_PRIMARY | ACPI_TABLE_MULTIPLE |
323 ACPI_TABLE_EXECUTABLE}
324 ,
325 /* XSDT 6 */ {XSDT_SIG, XSDT_SIG, NULL, sizeof(RSDT_SIG) - 1,
326 ACPI_TABLE_ROOT | ACPI_TABLE_SINGLE}
327 ,
328};
329
330/****************************************************************************** 236/******************************************************************************
331 * 237 *
332 * Event and Hardware globals 238 * Event and Hardware globals
@@ -612,7 +518,7 @@ char *acpi_ut_get_node_name(void *object)
612 /* Name must be a valid ACPI name */ 518 /* Name must be a valid ACPI name */
613 519
614 if (!acpi_ut_valid_acpi_name(node->name.integer)) { 520 if (!acpi_ut_valid_acpi_name(node->name.integer)) {
615 node->name.integer = acpi_ut_repair_name(node->name.integer); 521 node->name.integer = acpi_ut_repair_name(node->name.ascii);
616 } 522 }
617 523
618 /* Return the name */ 524 /* Return the name */
@@ -751,13 +657,6 @@ void acpi_ut_init_globals(void)
751 return; 657 return;
752 } 658 }
753 659
754 /* ACPI table structure */
755
756 for (i = 0; i < (ACPI_TABLE_ID_MAX + 1); i++) {
757 acpi_gbl_table_lists[i].next = NULL;
758 acpi_gbl_table_lists[i].count = 0;
759 }
760
761 /* Mutex locked flags */ 660 /* Mutex locked flags */
762 661
763 for (i = 0; i < ACPI_NUM_MUTEX; i++) { 662 for (i = 0; i < ACPI_NUM_MUTEX; i++) {
@@ -773,6 +672,7 @@ void acpi_ut_init_globals(void)
773 672
774 /* GPE support */ 673 /* GPE support */
775 674
675 acpi_gpe_count = 0;
776 acpi_gbl_gpe_xrupt_list_head = NULL; 676 acpi_gbl_gpe_xrupt_list_head = NULL;
777 acpi_gbl_gpe_fadt_blocks[0] = NULL; 677 acpi_gbl_gpe_fadt_blocks[0] = NULL;
778 acpi_gbl_gpe_fadt_blocks[1] = NULL; 678 acpi_gbl_gpe_fadt_blocks[1] = NULL;
@@ -784,25 +684,15 @@ void acpi_ut_init_globals(void)
784 acpi_gbl_exception_handler = NULL; 684 acpi_gbl_exception_handler = NULL;
785 acpi_gbl_init_handler = NULL; 685 acpi_gbl_init_handler = NULL;
786 686
787 /* Global "typed" ACPI table pointers */
788
789 acpi_gbl_RSDP = NULL;
790 acpi_gbl_XSDT = NULL;
791 acpi_gbl_FACS = NULL;
792 acpi_gbl_FADT = NULL;
793 acpi_gbl_DSDT = NULL;
794
795 /* Global Lock support */ 687 /* Global Lock support */
796 688
797 acpi_gbl_global_lock_semaphore = NULL; 689 acpi_gbl_global_lock_semaphore = NULL;
690 acpi_gbl_global_lock_mutex = NULL;
798 acpi_gbl_global_lock_acquired = FALSE; 691 acpi_gbl_global_lock_acquired = FALSE;
799 acpi_gbl_global_lock_thread_count = 0;
800 acpi_gbl_global_lock_handle = 0; 692 acpi_gbl_global_lock_handle = 0;
801 693
802 /* Miscellaneous variables */ 694 /* Miscellaneous variables */
803 695
804 acpi_gbl_table_flags = ACPI_PHYSICAL_POINTER;
805 acpi_gbl_rsdp_original_location = 0;
806 acpi_gbl_cm_single_step = FALSE; 696 acpi_gbl_cm_single_step = FALSE;
807 acpi_gbl_db_terminate_threads = FALSE; 697 acpi_gbl_db_terminate_threads = FALSE;
808 acpi_gbl_shutdown = FALSE; 698 acpi_gbl_shutdown = FALSE;
@@ -837,8 +727,13 @@ void acpi_ut_init_globals(void)
837 acpi_gbl_lowest_stack_pointer = ACPI_SIZE_MAX; 727 acpi_gbl_lowest_stack_pointer = ACPI_SIZE_MAX;
838#endif 728#endif
839 729
730#ifdef ACPI_DBG_TRACK_ALLOCATIONS
731 acpi_gbl_display_final_mem_stats = FALSE;
732#endif
733
840 return_VOID; 734 return_VOID;
841} 735}
842 736
843ACPI_EXPORT_SYMBOL(acpi_dbg_level) 737ACPI_EXPORT_SYMBOL(acpi_dbg_level)
844ACPI_EXPORT_SYMBOL(acpi_dbg_layer) 738ACPI_EXPORT_SYMBOL(acpi_dbg_layer)
739ACPI_EXPORT_SYMBOL(acpi_gpe_count)
diff --git a/drivers/acpi/utilities/utinit.c b/drivers/acpi/utilities/utinit.c
index ff76055eb7..ad3c0d0a5c 100644
--- a/drivers/acpi/utilities/utinit.c
+++ b/drivers/acpi/utilities/utinit.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -44,119 +44,14 @@
44#include <acpi/acpi.h> 44#include <acpi/acpi.h>
45#include <acpi/acnamesp.h> 45#include <acpi/acnamesp.h>
46#include <acpi/acevents.h> 46#include <acpi/acevents.h>
47#include <acpi/actables.h>
47 48
48#define _COMPONENT ACPI_UTILITIES 49#define _COMPONENT ACPI_UTILITIES
49ACPI_MODULE_NAME("utinit") 50ACPI_MODULE_NAME("utinit")
50 51
51/* Local prototypes */ 52/* Local prototypes */
52static void
53acpi_ut_fadt_register_error(char *register_name, u32 value, u8 offset);
54
55static void acpi_ut_terminate(void); 53static void acpi_ut_terminate(void);
56 54
57/*******************************************************************************
58 *
59 * FUNCTION: acpi_ut_fadt_register_error
60 *
61 * PARAMETERS: register_name - Pointer to string identifying register
62 * Value - Actual register contents value
63 * Offset - Byte offset in the FADT
64 *
65 * RETURN: AE_BAD_VALUE
66 *
67 * DESCRIPTION: Display failure message
68 *
69 ******************************************************************************/
70
71static void
72acpi_ut_fadt_register_error(char *register_name, u32 value, u8 offset)
73{
74
75 ACPI_WARNING((AE_INFO,
76 "Invalid FADT value %s=%X at offset %X FADT=%p",
77 register_name, value, offset, acpi_gbl_FADT));
78}
79
80/******************************************************************************
81 *
82 * FUNCTION: acpi_ut_validate_fadt
83 *
84 * PARAMETERS: None
85 *
86 * RETURN: Status
87 *
88 * DESCRIPTION: Validate various ACPI registers in the FADT
89 *
90 ******************************************************************************/
91
92acpi_status acpi_ut_validate_fadt(void)
93{
94
95 /*
96 * Verify Fixed ACPI Description Table fields,
97 * but don't abort on any problems, just display error
98 */
99 if (acpi_gbl_FADT->pm1_evt_len < 4) {
100 acpi_ut_fadt_register_error("PM1_EVT_LEN",
101 (u32) acpi_gbl_FADT->pm1_evt_len,
102 ACPI_FADT_OFFSET(pm1_evt_len));
103 }
104
105 if (!acpi_gbl_FADT->pm1_cnt_len) {
106 acpi_ut_fadt_register_error("PM1_CNT_LEN", 0,
107 ACPI_FADT_OFFSET(pm1_cnt_len));
108 }
109
110 if (!acpi_gbl_FADT->xpm1a_evt_blk.address) {
111 acpi_ut_fadt_register_error("X_PM1a_EVT_BLK", 0,
112 ACPI_FADT_OFFSET(xpm1a_evt_blk.
113 address));
114 }
115
116 if (!acpi_gbl_FADT->xpm1a_cnt_blk.address) {
117 acpi_ut_fadt_register_error("X_PM1a_CNT_BLK", 0,
118 ACPI_FADT_OFFSET(xpm1a_cnt_blk.
119 address));
120 }
121
122 if (!acpi_gbl_FADT->xpm_tmr_blk.address) {
123 acpi_ut_fadt_register_error("X_PM_TMR_BLK", 0,
124 ACPI_FADT_OFFSET(xpm_tmr_blk.
125 address));
126 }
127
128 if ((acpi_gbl_FADT->xpm2_cnt_blk.address &&
129 !acpi_gbl_FADT->pm2_cnt_len)) {
130 acpi_ut_fadt_register_error("PM2_CNT_LEN",
131 (u32) acpi_gbl_FADT->pm2_cnt_len,
132 ACPI_FADT_OFFSET(pm2_cnt_len));
133 }
134
135 if (acpi_gbl_FADT->pm_tm_len < 4) {
136 acpi_ut_fadt_register_error("PM_TM_LEN",
137 (u32) acpi_gbl_FADT->pm_tm_len,
138 ACPI_FADT_OFFSET(pm_tm_len));
139 }
140
141 /* Length of GPE blocks must be a multiple of 2 */
142
143 if (acpi_gbl_FADT->xgpe0_blk.address &&
144 (acpi_gbl_FADT->gpe0_blk_len & 1)) {
145 acpi_ut_fadt_register_error("(x)GPE0_BLK_LEN",
146 (u32) acpi_gbl_FADT->gpe0_blk_len,
147 ACPI_FADT_OFFSET(gpe0_blk_len));
148 }
149
150 if (acpi_gbl_FADT->xgpe1_blk.address &&
151 (acpi_gbl_FADT->gpe1_blk_len & 1)) {
152 acpi_ut_fadt_register_error("(x)GPE1_BLK_LEN",
153 (u32) acpi_gbl_FADT->gpe1_blk_len,
154 ACPI_FADT_OFFSET(gpe1_blk_len));
155 }
156
157 return (AE_OK);
158}
159
160/****************************************************************************** 55/******************************************************************************
161 * 56 *
162 * FUNCTION: acpi_ut_terminate 57 * FUNCTION: acpi_ut_terminate
@@ -178,7 +73,6 @@ static void acpi_ut_terminate(void)
178 73
179 ACPI_FUNCTION_TRACE(ut_terminate); 74 ACPI_FUNCTION_TRACE(ut_terminate);
180 75
181 /* Free global tables, etc. */
182 /* Free global GPE blocks and related info structures */ 76 /* Free global GPE blocks and related info structures */
183 77
184 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; 78 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
@@ -239,6 +133,10 @@ void acpi_ut_subsystem_shutdown(void)
239 133
240 acpi_ns_terminate(); 134 acpi_ns_terminate();
241 135
136 /* Delete the ACPI tables */
137
138 acpi_tb_terminate();
139
242 /* Close the globals */ 140 /* Close the globals */
243 141
244 acpi_ut_terminate(); 142 acpi_ut_terminate();
diff --git a/drivers/acpi/utilities/utmath.c b/drivers/acpi/utilities/utmath.c
index 19d74bedce..0c56a0d20b 100644
--- a/drivers/acpi/utilities/utmath.c
+++ b/drivers/acpi/utilities/utmath.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
index 6d8a8211be..50133fffe4 100644
--- a/drivers/acpi/utilities/utmisc.c
+++ b/drivers/acpi/utilities/utmisc.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -51,6 +51,78 @@ ACPI_MODULE_NAME("utmisc")
51 51
52/******************************************************************************* 52/*******************************************************************************
53 * 53 *
54 * FUNCTION: acpi_ut_validate_exception
55 *
56 * PARAMETERS: Status - The acpi_status code to be formatted
57 *
58 * RETURN: A string containing the exception text. NULL if exception is
59 * not valid.
60 *
61 * DESCRIPTION: This function validates and translates an ACPI exception into
62 * an ASCII string.
63 *
64 ******************************************************************************/
65const char *acpi_ut_validate_exception(acpi_status status)
66{
67 acpi_status sub_status;
68 const char *exception = NULL;
69
70 ACPI_FUNCTION_ENTRY();
71
72 /*
73 * Status is composed of two parts, a "type" and an actual code
74 */
75 sub_status = (status & ~AE_CODE_MASK);
76
77 switch (status & AE_CODE_MASK) {
78 case AE_CODE_ENVIRONMENTAL:
79
80 if (sub_status <= AE_CODE_ENV_MAX) {
81 exception = acpi_gbl_exception_names_env[sub_status];
82 }
83 break;
84
85 case AE_CODE_PROGRAMMER:
86
87 if (sub_status <= AE_CODE_PGM_MAX) {
88 exception =
89 acpi_gbl_exception_names_pgm[sub_status - 1];
90 }
91 break;
92
93 case AE_CODE_ACPI_TABLES:
94
95 if (sub_status <= AE_CODE_TBL_MAX) {
96 exception =
97 acpi_gbl_exception_names_tbl[sub_status - 1];
98 }
99 break;
100
101 case AE_CODE_AML:
102
103 if (sub_status <= AE_CODE_AML_MAX) {
104 exception =
105 acpi_gbl_exception_names_aml[sub_status - 1];
106 }
107 break;
108
109 case AE_CODE_CONTROL:
110
111 if (sub_status <= AE_CODE_CTRL_MAX) {
112 exception =
113 acpi_gbl_exception_names_ctrl[sub_status - 1];
114 }
115 break;
116
117 default:
118 break;
119 }
120
121 return (ACPI_CAST_PTR(const char, exception));
122}
123
124/*******************************************************************************
125 *
54 * FUNCTION: acpi_ut_is_aml_table 126 * FUNCTION: acpi_ut_is_aml_table
55 * 127 *
56 * PARAMETERS: Table - An ACPI table 128 * PARAMETERS: Table - An ACPI table
@@ -62,14 +134,15 @@ ACPI_MODULE_NAME("utmisc")
62 * data tables that do not contain AML code. 134 * data tables that do not contain AML code.
63 * 135 *
64 ******************************************************************************/ 136 ******************************************************************************/
137
65u8 acpi_ut_is_aml_table(struct acpi_table_header *table) 138u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
66{ 139{
67 140
68 /* These are the only tables that contain executable AML */ 141 /* These are the only tables that contain executable AML */
69 142
70 if (ACPI_COMPARE_NAME(table->signature, DSDT_SIG) || 143 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) ||
71 ACPI_COMPARE_NAME(table->signature, PSDT_SIG) || 144 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) ||
72 ACPI_COMPARE_NAME(table->signature, SSDT_SIG)) { 145 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
73 return (TRUE); 146 return (TRUE);
74 } 147 }
75 148
@@ -418,7 +491,7 @@ u32 acpi_ut_dword_byte_swap(u32 value)
418void acpi_ut_set_integer_width(u8 revision) 491void acpi_ut_set_integer_width(u8 revision)
419{ 492{
420 493
421 if (revision <= 1) { 494 if (revision < 2) {
422 495
423 /* 32-bit case */ 496 /* 32-bit case */
424 497
@@ -582,26 +655,25 @@ u8 acpi_ut_valid_acpi_name(u32 name)
582 * 655 *
583 ******************************************************************************/ 656 ******************************************************************************/
584 657
585acpi_name acpi_ut_repair_name(acpi_name name) 658acpi_name acpi_ut_repair_name(char *name)
586{ 659{
587 char *name_ptr = ACPI_CAST_PTR(char, &name);
588 char new_name[ACPI_NAME_SIZE];
589 acpi_native_uint i; 660 acpi_native_uint i;
661 char new_name[ACPI_NAME_SIZE];
590 662
591 for (i = 0; i < ACPI_NAME_SIZE; i++) { 663 for (i = 0; i < ACPI_NAME_SIZE; i++) {
592 new_name[i] = name_ptr[i]; 664 new_name[i] = name[i];
593 665
594 /* 666 /*
595 * Replace a bad character with something printable, yet technically 667 * Replace a bad character with something printable, yet technically
596 * still invalid. This prevents any collisions with existing "good" 668 * still invalid. This prevents any collisions with existing "good"
597 * names in the namespace. 669 * names in the namespace.
598 */ 670 */
599 if (!acpi_ut_valid_acpi_char(name_ptr[i], i)) { 671 if (!acpi_ut_valid_acpi_char(name[i], i)) {
600 new_name[i] = '*'; 672 new_name[i] = '*';
601 } 673 }
602 } 674 }
603 675
604 return (*ACPI_CAST_PTR(u32, new_name)); 676 return (*(u32 *) new_name);
605} 677}
606 678
607/******************************************************************************* 679/*******************************************************************************
@@ -996,9 +1068,13 @@ acpi_ut_info(char *module_name, u32 line_number, char *format, ...)
996{ 1068{
997 va_list args; 1069 va_list args;
998 1070
999 acpi_os_printf("ACPI (%s-%04d): ", module_name, line_number); 1071 /*
1072 * Removed module_name, line_number, and acpica version, not needed
1073 * for info output
1074 */
1075 acpi_os_printf("ACPI: ");
1000 1076
1001 va_start(args, format); 1077 va_start(args, format);
1002 acpi_os_vprintf(format, args); 1078 acpi_os_vprintf(format, args);
1003 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); 1079 acpi_os_printf("\n");
1004} 1080}
diff --git a/drivers/acpi/utilities/utmutex.c b/drivers/acpi/utilities/utmutex.c
index c39062a047..cbad2ef598 100644
--- a/drivers/acpi/utilities/utmutex.c
+++ b/drivers/acpi/utilities/utmutex.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -243,23 +243,24 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
243#endif 243#endif
244 244
245 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 245 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
246 "Thread %X attempting to acquire Mutex [%s]\n", 246 "Thread %lX attempting to acquire Mutex [%s]\n",
247 (u32) this_thread_id, acpi_ut_get_mutex_name(mutex_id))); 247 (unsigned long) this_thread_id,
248 acpi_ut_get_mutex_name(mutex_id)));
248 249
249 status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex, 250 status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex,
250 ACPI_WAIT_FOREVER); 251 ACPI_WAIT_FOREVER);
251 if (ACPI_SUCCESS(status)) { 252 if (ACPI_SUCCESS(status)) {
252 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 253 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
253 "Thread %X acquired Mutex [%s]\n", 254 "Thread %lX acquired Mutex [%s]\n",
254 (u32) this_thread_id, 255 (unsigned long) this_thread_id,
255 acpi_ut_get_mutex_name(mutex_id))); 256 acpi_ut_get_mutex_name(mutex_id)));
256 257
257 acpi_gbl_mutex_info[mutex_id].use_count++; 258 acpi_gbl_mutex_info[mutex_id].use_count++;
258 acpi_gbl_mutex_info[mutex_id].thread_id = this_thread_id; 259 acpi_gbl_mutex_info[mutex_id].thread_id = this_thread_id;
259 } else { 260 } else {
260 ACPI_EXCEPTION((AE_INFO, status, 261 ACPI_EXCEPTION((AE_INFO, status,
261 "Thread %X could not acquire Mutex [%X]", 262 "Thread %lX could not acquire Mutex [%X]",
262 (u32) this_thread_id, mutex_id)); 263 (unsigned long) this_thread_id, mutex_id));
263 } 264 }
264 265
265 return (status); 266 return (status);
@@ -285,7 +286,8 @@ acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id)
285 286
286 this_thread_id = acpi_os_get_thread_id(); 287 this_thread_id = acpi_os_get_thread_id();
287 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 288 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
288 "Thread %X releasing Mutex [%s]\n", (u32) this_thread_id, 289 "Thread %lX releasing Mutex [%s]\n",
290 (unsigned long) this_thread_id,
289 acpi_ut_get_mutex_name(mutex_id))); 291 acpi_ut_get_mutex_name(mutex_id)));
290 292
291 if (mutex_id > ACPI_MAX_MUTEX) { 293 if (mutex_id > ACPI_MAX_MUTEX) {
diff --git a/drivers/acpi/utilities/utobject.c b/drivers/acpi/utilities/utobject.c
index ba7d8ac702..4696124759 100644
--- a/drivers/acpi/utilities/utobject.c
+++ b/drivers/acpi/utilities/utobject.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/utilities/utresrc.c b/drivers/acpi/utilities/utresrc.c
index 5a2de92831..e8fe1ba6cc 100644
--- a/drivers/acpi/utilities/utresrc.c
+++ b/drivers/acpi/utilities/utresrc.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/utilities/utstate.c b/drivers/acpi/utilities/utstate.c
index eaa13d05c8..edcaafad0a 100644
--- a/drivers/acpi/utilities/utstate.c
+++ b/drivers/acpi/utilities/utstate.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/utilities/utxface.c b/drivers/acpi/utilities/utxface.c
index 3538f69c82..de3276f4f4 100644
--- a/drivers/acpi/utilities/utxface.c
+++ b/drivers/acpi/utilities/utxface.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore 8 * Copyright (C) 2000 - 2007, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -67,6 +67,7 @@ acpi_status acpi_initialize_subsystem(void)
67 67
68 ACPI_FUNCTION_TRACE(acpi_initialize_subsystem); 68 ACPI_FUNCTION_TRACE(acpi_initialize_subsystem);
69 69
70 acpi_gbl_startup_flags = ACPI_SUBSYSTEM_INITIALIZE;
70 ACPI_DEBUG_EXEC(acpi_ut_init_stack_ptr_trace()); 71 ACPI_DEBUG_EXEC(acpi_ut_init_stack_ptr_trace());
71 72
72 /* Initialize the OS-Dependent layer */ 73 /* Initialize the OS-Dependent layer */
@@ -127,20 +128,6 @@ acpi_status acpi_enable_subsystem(u32 flags)
127 128
128 ACPI_FUNCTION_TRACE(acpi_enable_subsystem); 129 ACPI_FUNCTION_TRACE(acpi_enable_subsystem);
129 130
130 /*
131 * We must initialize the hardware before we can enable ACPI.
132 * The values from the FADT are validated here.
133 */
134 if (!(flags & ACPI_NO_HARDWARE_INIT)) {
135 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
136 "[Init] Initializing ACPI hardware\n"));
137
138 status = acpi_hw_initialize();
139 if (ACPI_FAILURE(status)) {
140 return_ACPI_STATUS(status);
141 }
142 }
143
144 /* Enable ACPI mode */ 131 /* Enable ACPI mode */
145 132
146 if (!(flags & ACPI_NO_ACPI_ENABLE)) { 133 if (!(flags & ACPI_NO_ACPI_ENABLE)) {
@@ -398,7 +385,6 @@ acpi_status acpi_get_system_info(struct acpi_buffer * out_buffer)
398{ 385{
399 struct acpi_system_info *info_ptr; 386 struct acpi_system_info *info_ptr;
400 acpi_status status; 387 acpi_status status;
401 u32 i;
402 388
403 ACPI_FUNCTION_TRACE(acpi_get_system_info); 389 ACPI_FUNCTION_TRACE(acpi_get_system_info);
404 390
@@ -431,9 +417,7 @@ acpi_status acpi_get_system_info(struct acpi_buffer * out_buffer)
431 417
432 /* Timer resolution - 24 or 32 bits */ 418 /* Timer resolution - 24 or 32 bits */
433 419
434 if (!acpi_gbl_FADT) { 420 if (acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) {
435 info_ptr->timer_resolution = 0;
436 } else if (acpi_gbl_FADT->tmr_val_ext == 0) {
437 info_ptr->timer_resolution = 24; 421 info_ptr->timer_resolution = 24;
438 } else { 422 } else {
439 info_ptr->timer_resolution = 32; 423 info_ptr->timer_resolution = 32;
@@ -449,13 +433,6 @@ acpi_status acpi_get_system_info(struct acpi_buffer * out_buffer)
449 info_ptr->debug_layer = acpi_dbg_layer; 433 info_ptr->debug_layer = acpi_dbg_layer;
450 info_ptr->debug_level = acpi_dbg_level; 434 info_ptr->debug_level = acpi_dbg_level;
451 435
452 /* Current status of the ACPI tables, per table type */
453
454 info_ptr->num_table_types = ACPI_TABLE_ID_MAX + 1;
455 for (i = 0; i < (ACPI_TABLE_ID_MAX + 1); i++) {
456 info_ptr->table_info[i].count = acpi_gbl_table_lists[i].count;
457 }
458
459 return_ACPI_STATUS(AE_OK); 436 return_ACPI_STATUS(AE_OK);
460} 437}
461 438
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index d0d84c43a9..68a809fa7b 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -83,7 +83,7 @@ acpi_extract_package(union acpi_object *package,
83 return AE_BAD_DATA; 83 return AE_BAD_DATA;
84 } 84 }
85 85
86 format_string = (char *)format->pointer; 86 format_string = format->pointer;
87 87
88 /* 88 /*
89 * Calculate size_required. 89 * Calculate size_required.
@@ -262,11 +262,10 @@ acpi_evaluate_integer(acpi_handle handle,
262 if (!data) 262 if (!data)
263 return AE_BAD_PARAMETER; 263 return AE_BAD_PARAMETER;
264 264
265 element = kmalloc(sizeof(union acpi_object), irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL); 265 element = kzalloc(sizeof(union acpi_object), irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
266 if (!element) 266 if (!element)
267 return AE_NO_MEMORY; 267 return AE_NO_MEMORY;
268 268
269 memset(element, 0, sizeof(union acpi_object));
270 buffer.length = sizeof(union acpi_object); 269 buffer.length = sizeof(union acpi_object);
271 buffer.pointer = element; 270 buffer.pointer = element;
272 status = acpi_evaluate_object(handle, pathname, arguments, &buffer); 271 status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
@@ -321,12 +320,11 @@ acpi_evaluate_string(acpi_handle handle,
321 return AE_BAD_DATA; 320 return AE_BAD_DATA;
322 } 321 }
323 322
324 *data = kmalloc(element->string.length + 1, GFP_KERNEL); 323 *data = kzalloc(element->string.length + 1, GFP_KERNEL);
325 if (!data) { 324 if (!data) {
326 printk(KERN_ERR PREFIX "Memory allocation\n"); 325 printk(KERN_ERR PREFIX "Memory allocation\n");
327 return -ENOMEM; 326 return -ENOMEM;
328 } 327 }
329 memset(*data, 0, element->string.length + 1);
330 328
331 memcpy(*data, element->string.pointer, element->string.length); 329 memcpy(*data, element->string.pointer, element->string.length);
332 330
@@ -361,7 +359,7 @@ acpi_evaluate_reference(acpi_handle handle,
361 if (ACPI_FAILURE(status)) 359 if (ACPI_FAILURE(status))
362 goto end; 360 goto end;
363 361
364 package = (union acpi_object *)buffer.pointer; 362 package = buffer.pointer;
365 363
366 if ((buffer.length == 0) || !package) { 364 if ((buffer.length == 0) || !package) {
367 printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n", 365 printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n",
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 6e99eea689..e0b97add8c 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> 4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org> 5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
6 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
6 * 7 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * 9 *
@@ -31,6 +32,7 @@
31#include <linux/proc_fs.h> 32#include <linux/proc_fs.h>
32#include <linux/seq_file.h> 33#include <linux/seq_file.h>
33 34
35#include <linux/backlight.h>
34#include <asm/uaccess.h> 36#include <asm/uaccess.h>
35 37
36#include <acpi/acpi_bus.h> 38#include <acpi/acpi_bus.h>
@@ -47,14 +49,20 @@
47#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83 49#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
48#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84 50#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
49 51
50#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x82 52#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
51#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x83 53#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
52#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x84 54#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
53#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x85 55#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
54#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x86 56#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
55 57
56#define ACPI_VIDEO_HEAD_INVALID (~0u - 1) 58#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
57#define ACPI_VIDEO_HEAD_END (~0u) 59#define ACPI_VIDEO_HEAD_END (~0u)
60#define MAX_NAME_LEN 20
61
62#define ACPI_VIDEO_DISPLAY_CRT 1
63#define ACPI_VIDEO_DISPLAY_TV 2
64#define ACPI_VIDEO_DISPLAY_DVI 3
65#define ACPI_VIDEO_DISPLAY_LCD 4
58 66
59#define _COMPONENT ACPI_VIDEO_COMPONENT 67#define _COMPONENT ACPI_VIDEO_COMPONENT
60ACPI_MODULE_NAME("acpi_video") 68ACPI_MODULE_NAME("acpi_video")
@@ -130,20 +138,21 @@ struct acpi_video_device_flags {
130 u8 crt:1; 138 u8 crt:1;
131 u8 lcd:1; 139 u8 lcd:1;
132 u8 tvout:1; 140 u8 tvout:1;
141 u8 dvi:1;
133 u8 bios:1; 142 u8 bios:1;
134 u8 unknown:1; 143 u8 unknown:1;
135 u8 reserved:3; 144 u8 reserved:2;
136}; 145};
137 146
138struct acpi_video_device_cap { 147struct acpi_video_device_cap {
139 u8 _ADR:1; /*Return the unique ID */ 148 u8 _ADR:1; /*Return the unique ID */
140 u8 _BCL:1; /*Query list of brightness control levels supported */ 149 u8 _BCL:1; /*Query list of brightness control levels supported */
141 u8 _BCM:1; /*Set the brightness level */ 150 u8 _BCM:1; /*Set the brightness level */
151 u8 _BQC:1; /* Get current brightness level */
142 u8 _DDC:1; /*Return the EDID for this device */ 152 u8 _DDC:1; /*Return the EDID for this device */
143 u8 _DCS:1; /*Return status of output device */ 153 u8 _DCS:1; /*Return status of output device */
144 u8 _DGS:1; /*Query graphics state */ 154 u8 _DGS:1; /*Query graphics state */
145 u8 _DSS:1; /*Device state set */ 155 u8 _DSS:1; /*Device state set */
146 u8 _reserved:1;
147}; 156};
148 157
149struct acpi_video_device_brightness { 158struct acpi_video_device_brightness {
@@ -160,6 +169,8 @@ struct acpi_video_device {
160 struct acpi_video_bus *video; 169 struct acpi_video_bus *video;
161 struct acpi_device *dev; 170 struct acpi_device *dev;
162 struct acpi_video_device_brightness *brightness; 171 struct acpi_video_device_brightness *brightness;
172 struct backlight_device *backlight;
173 struct backlight_properties *data;
163}; 174};
164 175
165/* bus */ 176/* bus */
@@ -254,11 +265,35 @@ static void acpi_video_device_bind(struct acpi_video_bus *video,
254 struct acpi_video_device *device); 265 struct acpi_video_device *device);
255static int acpi_video_device_enumerate(struct acpi_video_bus *video); 266static int acpi_video_device_enumerate(struct acpi_video_bus *video);
256static int acpi_video_switch_output(struct acpi_video_bus *video, int event); 267static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
268static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
269 int level);
270static int acpi_video_device_lcd_get_level_current(
271 struct acpi_video_device *device,
272 unsigned long *level);
257static int acpi_video_get_next_level(struct acpi_video_device *device, 273static int acpi_video_get_next_level(struct acpi_video_device *device,
258 u32 level_current, u32 event); 274 u32 level_current, u32 event);
259static void acpi_video_switch_brightness(struct acpi_video_device *device, 275static void acpi_video_switch_brightness(struct acpi_video_device *device,
260 int event); 276 int event);
261 277
278/*backlight device sysfs support*/
279static int acpi_video_get_brightness(struct backlight_device *bd)
280{
281 unsigned long cur_level;
282 struct acpi_video_device *vd =
283 (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
284 acpi_video_device_lcd_get_level_current(vd, &cur_level);
285 return (int) cur_level;
286}
287
288static int acpi_video_set_brightness(struct backlight_device *bd)
289{
290 int request_level = bd->props->brightness;
291 struct acpi_video_device *vd =
292 (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
293 acpi_video_device_lcd_set_level(vd, request_level);
294 return 0;
295}
296
262/* -------------------------------------------------------------------------- 297/* --------------------------------------------------------------------------
263 Video Management 298 Video Management
264 -------------------------------------------------------------------------- */ 299 -------------------------------------------------------------------------- */
@@ -384,7 +419,7 @@ acpi_video_device_EDID(struct acpi_video_device *device,
384 if (ACPI_FAILURE(status)) 419 if (ACPI_FAILURE(status))
385 return -ENODEV; 420 return -ENODEV;
386 421
387 obj = (union acpi_object *)buffer.pointer; 422 obj = buffer.pointer;
388 423
389 if (obj && obj->type == ACPI_TYPE_BUFFER) 424 if (obj && obj->type == ACPI_TYPE_BUFFER)
390 *edid = obj; 425 *edid = obj;
@@ -496,6 +531,7 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
496 acpi_integer status; 531 acpi_integer status;
497 acpi_handle h_dummy1; 532 acpi_handle h_dummy1;
498 int i; 533 int i;
534 u32 max_level = 0;
499 union acpi_object *obj = NULL; 535 union acpi_object *obj = NULL;
500 struct acpi_video_device_brightness *br = NULL; 536 struct acpi_video_device_brightness *br = NULL;
501 537
@@ -511,6 +547,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
511 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) { 547 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
512 device->cap._BCM = 1; 548 device->cap._BCM = 1;
513 } 549 }
550 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
551 device->cap._BQC = 1;
514 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) { 552 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
515 device->cap._DDC = 1; 553 device->cap._DDC = 1;
516 } 554 }
@@ -530,11 +568,10 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
530 int count = 0; 568 int count = 0;
531 union acpi_object *o; 569 union acpi_object *o;
532 570
533 br = kmalloc(sizeof(*br), GFP_KERNEL); 571 br = kzalloc(sizeof(*br), GFP_KERNEL);
534 if (!br) { 572 if (!br) {
535 printk(KERN_ERR "can't allocate memory\n"); 573 printk(KERN_ERR "can't allocate memory\n");
536 } else { 574 } else {
537 memset(br, 0, sizeof(*br));
538 br->levels = kmalloc(obj->package.count * 575 br->levels = kmalloc(obj->package.count *
539 sizeof *(br->levels), GFP_KERNEL); 576 sizeof *(br->levels), GFP_KERNEL);
540 if (!br->levels) 577 if (!br->levels)
@@ -548,6 +585,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
548 continue; 585 continue;
549 } 586 }
550 br->levels[count] = (u32) o->integer.value; 587 br->levels[count] = (u32) o->integer.value;
588 if (br->levels[count] > max_level)
589 max_level = br->levels[count];
551 count++; 590 count++;
552 } 591 }
553 out: 592 out:
@@ -566,6 +605,37 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
566 605
567 kfree(obj); 606 kfree(obj);
568 607
608 if (device->cap._BCL && device->cap._BCM && device->cap._BQC){
609 unsigned long tmp;
610 static int count = 0;
611 char *name;
612 struct backlight_properties *acpi_video_data;
613
614 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
615 if (!name)
616 return;
617
618 acpi_video_data = kzalloc(
619 sizeof(struct backlight_properties),
620 GFP_KERNEL);
621 if (!acpi_video_data){
622 kfree(name);
623 return;
624 }
625 acpi_video_data->owner = THIS_MODULE;
626 acpi_video_data->get_brightness =
627 acpi_video_get_brightness;
628 acpi_video_data->update_status =
629 acpi_video_set_brightness;
630 sprintf(name, "acpi_video%d", count++);
631 device->data = acpi_video_data;
632 acpi_video_data->max_brightness = max_level;
633 acpi_video_device_lcd_get_level_current(device, &tmp);
634 acpi_video_data->brightness = (int)tmp;
635 device->backlight = backlight_device_register(name,
636 NULL, device, acpi_video_data);
637 kfree(name);
638 }
569 return; 639 return;
570} 640}
571 641
@@ -652,8 +722,7 @@ static struct proc_dir_entry *acpi_video_dir;
652 722
653static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset) 723static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
654{ 724{
655 struct acpi_video_device *dev = 725 struct acpi_video_device *dev = seq->private;
656 (struct acpi_video_device *)seq->private;
657 726
658 727
659 if (!dev) 728 if (!dev)
@@ -667,6 +736,8 @@ static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
667 seq_printf(seq, "LCD\n"); 736 seq_printf(seq, "LCD\n");
668 else if (dev->flags.tvout) 737 else if (dev->flags.tvout)
669 seq_printf(seq, "TVOUT\n"); 738 seq_printf(seq, "TVOUT\n");
739 else if (dev->flags.dvi)
740 seq_printf(seq, "DVI\n");
670 else 741 else
671 seq_printf(seq, "UNKNOWN\n"); 742 seq_printf(seq, "UNKNOWN\n");
672 743
@@ -686,8 +757,7 @@ acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
686static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset) 757static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
687{ 758{
688 int status; 759 int status;
689 struct acpi_video_device *dev = 760 struct acpi_video_device *dev = seq->private;
690 (struct acpi_video_device *)seq->private;
691 unsigned long state; 761 unsigned long state;
692 762
693 763
@@ -725,8 +795,8 @@ acpi_video_device_write_state(struct file *file,
725 size_t count, loff_t * data) 795 size_t count, loff_t * data)
726{ 796{
727 int status; 797 int status;
728 struct seq_file *m = (struct seq_file *)file->private_data; 798 struct seq_file *m = file->private_data;
729 struct acpi_video_device *dev = (struct acpi_video_device *)m->private; 799 struct acpi_video_device *dev = m->private;
730 char str[12] = { 0 }; 800 char str[12] = { 0 };
731 u32 state = 0; 801 u32 state = 0;
732 802
@@ -752,8 +822,7 @@ acpi_video_device_write_state(struct file *file,
752static int 822static int
753acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset) 823acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
754{ 824{
755 struct acpi_video_device *dev = 825 struct acpi_video_device *dev = seq->private;
756 (struct acpi_video_device *)seq->private;
757 int i; 826 int i;
758 827
759 828
@@ -782,8 +851,8 @@ acpi_video_device_write_brightness(struct file *file,
782 const char __user * buffer, 851 const char __user * buffer,
783 size_t count, loff_t * data) 852 size_t count, loff_t * data)
784{ 853{
785 struct seq_file *m = (struct seq_file *)file->private_data; 854 struct seq_file *m = file->private_data;
786 struct acpi_video_device *dev = (struct acpi_video_device *)m->private; 855 struct acpi_video_device *dev = m->private;
787 char str[4] = { 0 }; 856 char str[4] = { 0 };
788 unsigned int level = 0; 857 unsigned int level = 0;
789 int i; 858 int i;
@@ -815,8 +884,7 @@ acpi_video_device_write_brightness(struct file *file,
815 884
816static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset) 885static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
817{ 886{
818 struct acpi_video_device *dev = 887 struct acpi_video_device *dev = seq->private;
819 (struct acpi_video_device *)seq->private;
820 int status; 888 int status;
821 int i; 889 int i;
822 union acpi_object *edid = NULL; 890 union acpi_object *edid = NULL;
@@ -864,7 +932,7 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
864 if (!device) 932 if (!device)
865 return -ENODEV; 933 return -ENODEV;
866 934
867 vid_dev = (struct acpi_video_device *)acpi_driver_data(device); 935 vid_dev = acpi_driver_data(device);
868 if (!vid_dev) 936 if (!vid_dev)
869 return -ENODEV; 937 return -ENODEV;
870 938
@@ -929,7 +997,7 @@ static int acpi_video_device_remove_fs(struct acpi_device *device)
929{ 997{
930 struct acpi_video_device *vid_dev; 998 struct acpi_video_device *vid_dev;
931 999
932 vid_dev = (struct acpi_video_device *)acpi_driver_data(device); 1000 vid_dev = acpi_driver_data(device);
933 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir) 1001 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
934 return -ENODEV; 1002 return -ENODEV;
935 1003
@@ -948,7 +1016,7 @@ static int acpi_video_device_remove_fs(struct acpi_device *device)
948/* video bus */ 1016/* video bus */
949static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset) 1017static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
950{ 1018{
951 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 1019 struct acpi_video_bus *video = seq->private;
952 1020
953 1021
954 if (!video) 1022 if (!video)
@@ -973,7 +1041,7 @@ static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
973 1041
974static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset) 1042static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
975{ 1043{
976 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 1044 struct acpi_video_bus *video = seq->private;
977 1045
978 1046
979 if (!video) 1047 if (!video)
@@ -993,7 +1061,7 @@ static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
993 1061
994static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset) 1062static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
995{ 1063{
996 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 1064 struct acpi_video_bus *video = seq->private;
997 unsigned long options; 1065 unsigned long options;
998 int status; 1066 int status;
999 1067
@@ -1031,7 +1099,7 @@ acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1031 1099
1032static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset) 1100static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1033{ 1101{
1034 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 1102 struct acpi_video_bus *video = seq->private;
1035 int status; 1103 int status;
1036 unsigned long id; 1104 unsigned long id;
1037 1105
@@ -1052,7 +1120,7 @@ static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1052 1120
1053static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset) 1121static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1054{ 1122{
1055 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 1123 struct acpi_video_bus *video = seq->private;
1056 1124
1057 1125
1058 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting); 1126 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
@@ -1077,8 +1145,8 @@ acpi_video_bus_write_POST(struct file *file,
1077 size_t count, loff_t * data) 1145 size_t count, loff_t * data)
1078{ 1146{
1079 int status; 1147 int status;
1080 struct seq_file *m = (struct seq_file *)file->private_data; 1148 struct seq_file *m = file->private_data;
1081 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private; 1149 struct acpi_video_bus *video = m->private;
1082 char str[12] = { 0 }; 1150 char str[12] = { 0 };
1083 unsigned long opt, options; 1151 unsigned long opt, options;
1084 1152
@@ -1117,8 +1185,8 @@ acpi_video_bus_write_DOS(struct file *file,
1117 size_t count, loff_t * data) 1185 size_t count, loff_t * data)
1118{ 1186{
1119 int status; 1187 int status;
1120 struct seq_file *m = (struct seq_file *)file->private_data; 1188 struct seq_file *m = file->private_data;
1121 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private; 1189 struct acpi_video_bus *video = m->private;
1122 char str[12] = { 0 }; 1190 char str[12] = { 0 };
1123 unsigned long opt; 1191 unsigned long opt;
1124 1192
@@ -1148,7 +1216,7 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1148 struct acpi_video_bus *video; 1216 struct acpi_video_bus *video;
1149 1217
1150 1218
1151 video = (struct acpi_video_bus *)acpi_driver_data(device); 1219 video = acpi_driver_data(device);
1152 1220
1153 if (!acpi_device_dir(device)) { 1221 if (!acpi_device_dir(device)) {
1154 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 1222 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
@@ -1224,7 +1292,7 @@ static int acpi_video_bus_remove_fs(struct acpi_device *device)
1224 struct acpi_video_bus *video; 1292 struct acpi_video_bus *video;
1225 1293
1226 1294
1227 video = (struct acpi_video_bus *)acpi_driver_data(device); 1295 video = acpi_driver_data(device);
1228 1296
1229 if (acpi_device_dir(device)) { 1297 if (acpi_device_dir(device)) {
1230 remove_proc_entry("info", acpi_device_dir(device)); 1298 remove_proc_entry("info", acpi_device_dir(device));
@@ -1244,6 +1312,16 @@ static int acpi_video_bus_remove_fs(struct acpi_device *device)
1244 -------------------------------------------------------------------------- */ 1312 -------------------------------------------------------------------------- */
1245 1313
1246/* device interface */ 1314/* device interface */
1315static struct acpi_video_device_attrib*
1316acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1317{
1318 int count;
1319
1320 for(count = 0; count < video->attached_count; count++)
1321 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1322 return &(video->attached_array[count].value.attrib);
1323 return NULL;
1324}
1247 1325
1248static int 1326static int
1249acpi_video_bus_get_one_device(struct acpi_device *device, 1327acpi_video_bus_get_one_device(struct acpi_device *device,
@@ -1252,7 +1330,7 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1252 unsigned long device_id; 1330 unsigned long device_id;
1253 int status; 1331 int status;
1254 struct acpi_video_device *data; 1332 struct acpi_video_device *data;
1255 1333 struct acpi_video_device_attrib* attribute;
1256 1334
1257 if (!device || !video) 1335 if (!device || !video)
1258 return -EINVAL; 1336 return -EINVAL;
@@ -1261,12 +1339,10 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1261 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); 1339 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1262 if (ACPI_SUCCESS(status)) { 1340 if (ACPI_SUCCESS(status)) {
1263 1341
1264 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL); 1342 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1265 if (!data) 1343 if (!data)
1266 return -ENOMEM; 1344 return -ENOMEM;
1267 1345
1268 memset(data, 0, sizeof(struct acpi_video_device));
1269
1270 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); 1346 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1271 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); 1347 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1272 acpi_driver_data(device) = data; 1348 acpi_driver_data(device) = data;
@@ -1275,20 +1351,30 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1275 data->video = video; 1351 data->video = video;
1276 data->dev = device; 1352 data->dev = device;
1277 1353
1278 switch (device_id & 0xffff) { 1354 attribute = acpi_video_get_device_attr(video, device_id);
1279 case 0x0100: 1355
1280 data->flags.crt = 1; 1356 if((attribute != NULL) && attribute->device_id_scheme) {
1281 break; 1357 switch (attribute->display_type) {
1282 case 0x0400: 1358 case ACPI_VIDEO_DISPLAY_CRT:
1283 data->flags.lcd = 1; 1359 data->flags.crt = 1;
1284 break; 1360 break;
1285 case 0x0200: 1361 case ACPI_VIDEO_DISPLAY_TV:
1286 data->flags.tvout = 1; 1362 data->flags.tvout = 1;
1287 break; 1363 break;
1288 default: 1364 case ACPI_VIDEO_DISPLAY_DVI:
1365 data->flags.dvi = 1;
1366 break;
1367 case ACPI_VIDEO_DISPLAY_LCD:
1368 data->flags.lcd = 1;
1369 break;
1370 default:
1371 data->flags.unknown = 1;
1372 break;
1373 }
1374 if(attribute->bios_can_detect)
1375 data->flags.bios = 1;
1376 } else
1289 data->flags.unknown = 1; 1377 data->flags.unknown = 1;
1290 break;
1291 }
1292 1378
1293 acpi_video_device_bind(video, data); 1379 acpi_video_device_bind(video, data);
1294 acpi_video_device_find_cap(data); 1380 acpi_video_device_find_cap(data);
@@ -1401,7 +1487,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1401 return status; 1487 return status;
1402 } 1488 }
1403 1489
1404 dod = (union acpi_object *)buffer.pointer; 1490 dod = buffer.pointer;
1405 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { 1491 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1406 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data")); 1492 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1407 status = -EFAULT; 1493 status = -EFAULT;
@@ -1424,7 +1510,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1424 1510
1425 count = 0; 1511 count = 0;
1426 for (i = 0; i < dod->package.count; i++) { 1512 for (i = 0; i < dod->package.count; i++) {
1427 obj = (union acpi_object *)&dod->package.elements[i]; 1513 obj = &dod->package.elements[i];
1428 1514
1429 if (obj->type != ACPI_TYPE_INTEGER) { 1515 if (obj->type != ACPI_TYPE_INTEGER) {
1430 printk(KERN_ERR PREFIX "Invalid _DOD data\n"); 1516 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
@@ -1507,8 +1593,34 @@ static int
1507acpi_video_get_next_level(struct acpi_video_device *device, 1593acpi_video_get_next_level(struct acpi_video_device *device,
1508 u32 level_current, u32 event) 1594 u32 level_current, u32 event)
1509{ 1595{
1510 /*Fix me */ 1596 int min, max, min_above, max_below, i, l;
1511 return level_current; 1597 max = max_below = 0;
1598 min = min_above = 255;
1599 for (i = 0; i < device->brightness->count; i++) {
1600 l = device->brightness->levels[i];
1601 if (l < min)
1602 min = l;
1603 if (l > max)
1604 max = l;
1605 if (l < min_above && l > level_current)
1606 min_above = l;
1607 if (l > max_below && l < level_current)
1608 max_below = l;
1609 }
1610
1611 switch (event) {
1612 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1613 return (level_current < max) ? min_above : min;
1614 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1615 return (level_current < max) ? min_above : max;
1616 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1617 return (level_current > min) ? max_below : min;
1618 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1619 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1620 return 0;
1621 default:
1622 return level_current;
1623 }
1512} 1624}
1513 1625
1514static void 1626static void
@@ -1566,7 +1678,10 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1566 status = acpi_remove_notify_handler(device->dev->handle, 1678 status = acpi_remove_notify_handler(device->dev->handle,
1567 ACPI_DEVICE_NOTIFY, 1679 ACPI_DEVICE_NOTIFY,
1568 acpi_video_device_notify); 1680 acpi_video_device_notify);
1569 1681 if (device->backlight){
1682 backlight_device_unregister(device->backlight);
1683 kfree(device->data);
1684 }
1570 return 0; 1685 return 0;
1571} 1686}
1572 1687
@@ -1610,7 +1725,7 @@ static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1610 1725
1611static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data) 1726static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1612{ 1727{
1613 struct acpi_video_bus *video = (struct acpi_video_bus *)data; 1728 struct acpi_video_bus *video = data;
1614 struct acpi_device *device = NULL; 1729 struct acpi_device *device = NULL;
1615 1730
1616 printk("video bus notify\n"); 1731 printk("video bus notify\n");
@@ -1652,12 +1767,9 @@ static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1652 1767
1653static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) 1768static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1654{ 1769{
1655 struct acpi_video_device *video_device = 1770 struct acpi_video_device *video_device = data;
1656 (struct acpi_video_device *)data;
1657 struct acpi_device *device = NULL; 1771 struct acpi_device *device = NULL;
1658 1772
1659
1660 printk("video device notify\n");
1661 if (!video_device) 1773 if (!video_device)
1662 return; 1774 return;
1663 1775
@@ -1694,10 +1806,9 @@ static int acpi_video_bus_add(struct acpi_device *device)
1694 if (!device) 1806 if (!device)
1695 return -EINVAL; 1807 return -EINVAL;
1696 1808
1697 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL); 1809 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1698 if (!video) 1810 if (!video)
1699 return -ENOMEM; 1811 return -ENOMEM;
1700 memset(video, 0, sizeof(struct acpi_video_bus));
1701 1812
1702 video->device = device; 1813 video->device = device;
1703 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); 1814 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
@@ -1755,7 +1866,7 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
1755 if (!device || !acpi_driver_data(device)) 1866 if (!device || !acpi_driver_data(device))
1756 return -EINVAL; 1867 return -EINVAL;
1757 1868
1758 video = (struct acpi_video_bus *)acpi_driver_data(device); 1869 video = acpi_driver_data(device);
1759 1870
1760 acpi_video_bus_stop_devices(video); 1871 acpi_video_bus_stop_devices(video);
1761 1872
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 984ab28438..1c94b43d2c 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -19,6 +19,10 @@ config ATA
19 19
20if ATA 20if ATA
21 21
22config ATA_NONSTANDARD
23 bool
24 default n
25
22config SATA_AHCI 26config SATA_AHCI
23 tristate "AHCI SATA support" 27 tristate "AHCI SATA support"
24 depends on PCI 28 depends on PCI
@@ -40,9 +44,9 @@ config ATA_PIIX
40 tristate "Intel PIIX/ICH SATA support" 44 tristate "Intel PIIX/ICH SATA support"
41 depends on PCI 45 depends on PCI
42 help 46 help
43 This option enables support for ICH5/6/7/8 Serial ATA. 47 This option enables support for ICH5/6/7/8 Serial ATA
44 If PATA support was enabled previously, this enables 48 and support for PATA on the Intel PIIX3/PIIX4/ICH series
45 support for select Intel PIIX/ICH PATA host controllers. 49 PATA host controllers.
46 50
47 If unsure, say N. 51 If unsure, say N.
48 52
@@ -381,7 +385,7 @@ config PATA_OPTI
381 If unsure, say N. 385 If unsure, say N.
382 386
383config PATA_OPTIDMA 387config PATA_OPTIDMA
384 tristate "OPTI FireStar PATA support (Veyr Experimental)" 388 tristate "OPTI FireStar PATA support (Very Experimental)"
385 depends on PCI && EXPERIMENTAL 389 depends on PCI && EXPERIMENTAL
386 help 390 help
387 This option enables DMA/PIO support for the later OPTi 391 This option enables DMA/PIO support for the later OPTi
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index f36da488a2..48616c6fee 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -75,6 +75,7 @@ enum {
75 AHCI_CMD_CLR_BUSY = (1 << 10), 75 AHCI_CMD_CLR_BUSY = (1 << 10),
76 76
77 RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ 77 RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */
78 RX_FIS_SDB = 0x58, /* offset of SDB FIS data */
78 RX_FIS_UNK = 0x60, /* offset of Unknown FIS data */ 79 RX_FIS_UNK = 0x60, /* offset of Unknown FIS data */
79 80
80 board_ahci = 0, 81 board_ahci = 0,
@@ -202,6 +203,10 @@ struct ahci_port_priv {
202 dma_addr_t cmd_tbl_dma; 203 dma_addr_t cmd_tbl_dma;
203 void *rx_fis; 204 void *rx_fis;
204 dma_addr_t rx_fis_dma; 205 dma_addr_t rx_fis_dma;
206 /* for NCQ spurious interrupt analysis */
207 int ncq_saw_spurious_sdb_cnt;
208 unsigned int ncq_saw_d2h:1;
209 unsigned int ncq_saw_dmas:1;
205}; 210};
206 211
207static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); 212static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg);
@@ -361,7 +366,7 @@ static const struct pci_device_id ahci_pci_tbl[] = {
361 { PCI_VDEVICE(INTEL, 0x27c1), board_ahci }, /* ICH7 */ 366 { PCI_VDEVICE(INTEL, 0x27c1), board_ahci }, /* ICH7 */
362 { PCI_VDEVICE(INTEL, 0x27c5), board_ahci }, /* ICH7M */ 367 { PCI_VDEVICE(INTEL, 0x27c5), board_ahci }, /* ICH7M */
363 { PCI_VDEVICE(INTEL, 0x27c3), board_ahci }, /* ICH7R */ 368 { PCI_VDEVICE(INTEL, 0x27c3), board_ahci }, /* ICH7R */
364 { PCI_VDEVICE(AL, 0x5288), board_ahci }, /* ULi M5288 */ 369 { PCI_VDEVICE(AL, 0x5288), board_ahci_ign_iferr }, /* ULi M5288 */
365 { PCI_VDEVICE(INTEL, 0x2681), board_ahci }, /* ESB2 */ 370 { PCI_VDEVICE(INTEL, 0x2681), board_ahci }, /* ESB2 */
366 { PCI_VDEVICE(INTEL, 0x2682), board_ahci }, /* ESB2 */ 371 { PCI_VDEVICE(INTEL, 0x2682), board_ahci }, /* ESB2 */
367 { PCI_VDEVICE(INTEL, 0x2683), board_ahci }, /* ESB2 */ 372 { PCI_VDEVICE(INTEL, 0x2683), board_ahci }, /* ESB2 */
@@ -402,6 +407,14 @@ static const struct pci_device_id ahci_pci_tbl[] = {
402 { PCI_VDEVICE(NVIDIA, 0x044d), board_ahci }, /* MCP65 */ 407 { PCI_VDEVICE(NVIDIA, 0x044d), board_ahci }, /* MCP65 */
403 { PCI_VDEVICE(NVIDIA, 0x044e), board_ahci }, /* MCP65 */ 408 { PCI_VDEVICE(NVIDIA, 0x044e), board_ahci }, /* MCP65 */
404 { PCI_VDEVICE(NVIDIA, 0x044f), board_ahci }, /* MCP65 */ 409 { PCI_VDEVICE(NVIDIA, 0x044f), board_ahci }, /* MCP65 */
410 { PCI_VDEVICE(NVIDIA, 0x045c), board_ahci }, /* MCP65 */
411 { PCI_VDEVICE(NVIDIA, 0x045d), board_ahci }, /* MCP65 */
412 { PCI_VDEVICE(NVIDIA, 0x045e), board_ahci }, /* MCP65 */
413 { PCI_VDEVICE(NVIDIA, 0x045f), board_ahci }, /* MCP65 */
414 { PCI_VDEVICE(NVIDIA, 0x0550), board_ahci }, /* MCP67 */
415 { PCI_VDEVICE(NVIDIA, 0x0551), board_ahci }, /* MCP67 */
416 { PCI_VDEVICE(NVIDIA, 0x0552), board_ahci }, /* MCP67 */
417 { PCI_VDEVICE(NVIDIA, 0x0553), board_ahci }, /* MCP67 */
405 { PCI_VDEVICE(NVIDIA, 0x0554), board_ahci }, /* MCP67 */ 418 { PCI_VDEVICE(NVIDIA, 0x0554), board_ahci }, /* MCP67 */
406 { PCI_VDEVICE(NVIDIA, 0x0555), board_ahci }, /* MCP67 */ 419 { PCI_VDEVICE(NVIDIA, 0x0555), board_ahci }, /* MCP67 */
407 { PCI_VDEVICE(NVIDIA, 0x0556), board_ahci }, /* MCP67 */ 420 { PCI_VDEVICE(NVIDIA, 0x0556), board_ahci }, /* MCP67 */
@@ -578,35 +591,18 @@ static void ahci_power_down(void __iomem *port_mmio, u32 cap)
578{ 591{
579 u32 cmd, scontrol; 592 u32 cmd, scontrol;
580 593
581 cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK; 594 if (!(cap & HOST_CAP_SSS))
582 595 return;
583 if (cap & HOST_CAP_SSC) {
584 /* enable transitions to slumber mode */
585 scontrol = readl(port_mmio + PORT_SCR_CTL);
586 if ((scontrol & 0x0f00) > 0x100) {
587 scontrol &= ~0xf00;
588 writel(scontrol, port_mmio + PORT_SCR_CTL);
589 }
590
591 /* put device into slumber mode */
592 writel(cmd | PORT_CMD_ICC_SLUMBER, port_mmio + PORT_CMD);
593
594 /* wait for the transition to complete */
595 ata_wait_register(port_mmio + PORT_CMD, PORT_CMD_ICC_SLUMBER,
596 PORT_CMD_ICC_SLUMBER, 1, 50);
597 }
598 596
599 /* put device into listen mode */ 597 /* put device into listen mode, first set PxSCTL.DET to 0 */
600 if (cap & HOST_CAP_SSS) { 598 scontrol = readl(port_mmio + PORT_SCR_CTL);
601 /* first set PxSCTL.DET to 0 */ 599 scontrol &= ~0xf;
602 scontrol = readl(port_mmio + PORT_SCR_CTL); 600 writel(scontrol, port_mmio + PORT_SCR_CTL);
603 scontrol &= ~0xf;
604 writel(scontrol, port_mmio + PORT_SCR_CTL);
605 601
606 /* then set PxCMD.SUD to 0 */ 602 /* then set PxCMD.SUD to 0 */
607 cmd &= ~PORT_CMD_SPIN_UP; 603 cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK;
608 writel(cmd, port_mmio + PORT_CMD); 604 cmd &= ~PORT_CMD_SPIN_UP;
609 } 605 writel(cmd, port_mmio + PORT_CMD);
610} 606}
611 607
612static void ahci_init_port(void __iomem *port_mmio, u32 cap, 608static void ahci_init_port(void __iomem *port_mmio, u32 cap,
@@ -645,8 +641,6 @@ static int ahci_reset_controller(void __iomem *mmio, struct pci_dev *pdev)
645 u32 cap_save, impl_save, tmp; 641 u32 cap_save, impl_save, tmp;
646 642
647 cap_save = readl(mmio + HOST_CAP); 643 cap_save = readl(mmio + HOST_CAP);
648 cap_save &= ( (1<<28) | (1<<17) );
649 cap_save |= (1 << 27);
650 impl_save = readl(mmio + HOST_PORTS_IMPL); 644 impl_save = readl(mmio + HOST_PORTS_IMPL);
651 645
652 /* global controller reset */ 646 /* global controller reset */
@@ -909,7 +903,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
909 903
910 /* clear D2H reception area to properly wait for D2H FIS */ 904 /* clear D2H reception area to properly wait for D2H FIS */
911 ata_tf_init(ap->device, &tf); 905 ata_tf_init(ap->device, &tf);
912 tf.command = 0xff; 906 tf.command = 0x80;
913 ata_tf_to_fis(&tf, d2h_fis, 0); 907 ata_tf_to_fis(&tf, d2h_fis, 0);
914 908
915 rc = sata_std_hardreset(ap, class); 909 rc = sata_std_hardreset(ap, class);
@@ -1120,8 +1114,9 @@ static void ahci_host_intr(struct ata_port *ap)
1120 void __iomem *mmio = ap->host->mmio_base; 1114 void __iomem *mmio = ap->host->mmio_base;
1121 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1115 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1122 struct ata_eh_info *ehi = &ap->eh_info; 1116 struct ata_eh_info *ehi = &ap->eh_info;
1117 struct ahci_port_priv *pp = ap->private_data;
1123 u32 status, qc_active; 1118 u32 status, qc_active;
1124 int rc; 1119 int rc, known_irq = 0;
1125 1120
1126 status = readl(port_mmio + PORT_IRQ_STAT); 1121 status = readl(port_mmio + PORT_IRQ_STAT);
1127 writel(status, port_mmio + PORT_IRQ_STAT); 1122 writel(status, port_mmio + PORT_IRQ_STAT);
@@ -1148,17 +1143,53 @@ static void ahci_host_intr(struct ata_port *ap)
1148 1143
1149 /* hmmm... a spurious interupt */ 1144 /* hmmm... a spurious interupt */
1150 1145
1151 /* some devices send D2H reg with I bit set during NCQ command phase */ 1146 /* if !NCQ, ignore. No modern ATA device has broken HSM
1152 if (ap->sactive && (status & PORT_IRQ_D2H_REG_FIS)) 1147 * implementation for non-NCQ commands.
1148 */
1149 if (!ap->sactive)
1153 return; 1150 return;
1154 1151
1155 /* ignore interim PIO setup fis interrupts */ 1152 if (status & PORT_IRQ_D2H_REG_FIS) {
1156 if (ata_tag_valid(ap->active_tag) && (status & PORT_IRQ_PIOS_FIS)) 1153 if (!pp->ncq_saw_d2h)
1157 return; 1154 ata_port_printk(ap, KERN_INFO,
1155 "D2H reg with I during NCQ, "
1156 "this message won't be printed again\n");
1157 pp->ncq_saw_d2h = 1;
1158 known_irq = 1;
1159 }
1160
1161 if (status & PORT_IRQ_DMAS_FIS) {
1162 if (!pp->ncq_saw_dmas)
1163 ata_port_printk(ap, KERN_INFO,
1164 "DMAS FIS during NCQ, "
1165 "this message won't be printed again\n");
1166 pp->ncq_saw_dmas = 1;
1167 known_irq = 1;
1168 }
1169
1170 if (status & PORT_IRQ_SDB_FIS &&
1171 pp->ncq_saw_spurious_sdb_cnt < 10) {
1172 /* SDB FIS containing spurious completions might be
1173 * dangerous, we need to know more about them. Print
1174 * more of it.
1175 */
1176 const u32 *f = pp->rx_fis + RX_FIS_SDB;
1177
1178 ata_port_printk(ap, KERN_INFO, "Spurious SDB FIS during NCQ "
1179 "issue=0x%x SAct=0x%x FIS=%08x:%08x%s\n",
1180 readl(port_mmio + PORT_CMD_ISSUE),
1181 readl(port_mmio + PORT_SCR_ACT),
1182 le32_to_cpu(f[0]), le32_to_cpu(f[1]),
1183 pp->ncq_saw_spurious_sdb_cnt < 10 ?
1184 "" : ", shutting up");
1185
1186 pp->ncq_saw_spurious_sdb_cnt++;
1187 known_irq = 1;
1188 }
1158 1189
1159 if (ata_ratelimit()) 1190 if (!known_irq)
1160 ata_port_printk(ap, KERN_INFO, "spurious interrupt " 1191 ata_port_printk(ap, KERN_INFO, "spurious interrupt "
1161 "(irq_stat 0x%x active_tag %d sactive 0x%x)\n", 1192 "(irq_stat 0x%x active_tag 0x%x sactive 0x%x)\n",
1162 status, ap->active_tag, ap->sactive); 1193 status, ap->active_tag, ap->sactive);
1163} 1194}
1164 1195
@@ -1251,7 +1282,7 @@ static void ahci_thaw(struct ata_port *ap)
1251 /* clear IRQ */ 1282 /* clear IRQ */
1252 tmp = readl(port_mmio + PORT_IRQ_STAT); 1283 tmp = readl(port_mmio + PORT_IRQ_STAT);
1253 writel(tmp, port_mmio + PORT_IRQ_STAT); 1284 writel(tmp, port_mmio + PORT_IRQ_STAT);
1254 writel(1 << ap->id, mmio + HOST_IRQ_STAT); 1285 writel(1 << ap->port_no, mmio + HOST_IRQ_STAT);
1255 1286
1256 /* turn IRQ back on */ 1287 /* turn IRQ back on */
1257 writel(DEF_PORT_IRQ, port_mmio + PORT_IRQ_MASK); 1288 writel(DEF_PORT_IRQ, port_mmio + PORT_IRQ_MASK);
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index 908751d27e..24af56081b 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -64,6 +64,7 @@ static void generic_error_handler(struct ata_port *ap)
64/** 64/**
65 * generic_set_mode - mode setting 65 * generic_set_mode - mode setting
66 * @ap: interface to set up 66 * @ap: interface to set up
67 * @unused: returned device on error
67 * 68 *
68 * Use a non standard set_mode function. We don't want to be tuned. 69 * Use a non standard set_mode function. We don't want to be tuned.
69 * The BIOS configured everything. Our job is not to fiddle. We 70 * The BIOS configured everything. Our job is not to fiddle. We
@@ -71,7 +72,7 @@ static void generic_error_handler(struct ata_port *ap)
71 * and respect them. 72 * and respect them.
72 */ 73 */
73 74
74static void generic_set_mode(struct ata_port *ap) 75static int generic_set_mode(struct ata_port *ap, struct ata_device **unused)
75{ 76{
76 int dma_enabled = 0; 77 int dma_enabled = 0;
77 int i; 78 int i;
@@ -82,7 +83,7 @@ static void generic_set_mode(struct ata_port *ap)
82 83
83 for (i = 0; i < ATA_MAX_DEVICES; i++) { 84 for (i = 0; i < ATA_MAX_DEVICES; i++) {
84 struct ata_device *dev = &ap->device[i]; 85 struct ata_device *dev = &ap->device[i];
85 if (ata_dev_enabled(dev)) { 86 if (ata_dev_ready(dev)) {
86 /* We don't really care */ 87 /* We don't really care */
87 dev->pio_mode = XFER_PIO_0; 88 dev->pio_mode = XFER_PIO_0;
88 dev->dma_mode = XFER_MW_DMA_0; 89 dev->dma_mode = XFER_MW_DMA_0;
@@ -99,6 +100,7 @@ static void generic_set_mode(struct ata_port *ap)
99 } 100 }
100 } 101 }
101 } 102 }
103 return 0;
102} 104}
103 105
104static struct scsi_host_template generic_sht = { 106static struct scsi_host_template generic_sht = {
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index c7de0bb159..47701b286f 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -226,14 +226,26 @@ static const struct pci_device_id piix_pci_tbl[] = {
226 { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 226 { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
227 /* 2801GBM/GHM (ICH7M, identical to ICH6M) */ 227 /* 2801GBM/GHM (ICH7M, identical to ICH6M) */
228 { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci }, 228 { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci },
229 /* Enterprise Southbridge 2 (where's the datasheet?) */ 229 /* Enterprise Southbridge 2 (631xESB/632xESB) */
230 { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 230 { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
231 /* SATA Controller 1 IDE (ICH8, no datasheet yet) */ 231 /* SATA Controller 1 IDE (ICH8) */
232 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 232 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
233 /* SATA Controller 2 IDE (ICH8, ditto) */ 233 /* SATA Controller 2 IDE (ICH8) */
234 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 234 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
235 /* Mobile SATA Controller IDE (ICH8M, ditto) */ 235 /* Mobile SATA Controller IDE (ICH8M) */
236 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 236 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
237 /* SATA Controller IDE (ICH9) */
238 { 0x8086, 0x2920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
239 /* SATA Controller IDE (ICH9) */
240 { 0x8086, 0x2921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
241 /* SATA Controller IDE (ICH9) */
242 { 0x8086, 0x2926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
243 /* SATA Controller IDE (ICH9M) */
244 { 0x8086, 0x2928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
245 /* SATA Controller IDE (ICH9M) */
246 { 0x8086, 0x292d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
247 /* SATA Controller IDE (ICH9M) */
248 { 0x8086, 0x292e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
237 249
238 { } /* terminate list */ 250 { } /* terminate list */
239}; 251};
@@ -330,7 +342,7 @@ static const struct ata_port_operations ich_pata_ops = {
330 342
331 .port_start = ata_port_start, 343 .port_start = ata_port_start,
332 .port_stop = ata_port_stop, 344 .port_stop = ata_port_stop,
333 .host_stop = ata_host_stop, 345 .host_stop = piix_host_stop,
334}; 346};
335 347
336static const struct ata_port_operations piix_sata_ops = { 348static const struct ata_port_operations piix_sata_ops = {
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 011c0a8a2d..667acd2833 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -1037,7 +1037,7 @@ static unsigned int ata_id_xfermask(const u16 *id)
1037 * the PIO timing number for the maximum. Turn it into 1037 * the PIO timing number for the maximum. Turn it into
1038 * a mask. 1038 * a mask.
1039 */ 1039 */
1040 u8 mode = id[ATA_ID_OLD_PIO_MODES] & 0xFF; 1040 u8 mode = (id[ATA_ID_OLD_PIO_MODES] >> 8) & 0xFF;
1041 if (mode < 5) /* Valid PIO range */ 1041 if (mode < 5) /* Valid PIO range */
1042 pio_mask = (2 << mode) - 1; 1042 pio_mask = (2 << mode) - 1;
1043 else 1043 else
@@ -1250,6 +1250,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1250 1250
1251 ata_sg_init(qc, sg, n_elem); 1251 ata_sg_init(qc, sg, n_elem);
1252 qc->nsect = buflen / ATA_SECT_SIZE; 1252 qc->nsect = buflen / ATA_SECT_SIZE;
1253 qc->nbytes = buflen;
1253 } 1254 }
1254 1255
1255 qc->private_data = &wait; 1256 qc->private_data = &wait;
@@ -1332,7 +1333,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1332} 1333}
1333 1334
1334/** 1335/**
1335 * ata_exec_internal_sg - execute libata internal command 1336 * ata_exec_internal - execute libata internal command
1336 * @dev: Device to which the command is sent 1337 * @dev: Device to which the command is sent
1337 * @tf: Taskfile registers for the command and the result 1338 * @tf: Taskfile registers for the command and the result
1338 * @cdb: CDB for packet command 1339 * @cdb: CDB for packet command
@@ -1353,11 +1354,17 @@ unsigned ata_exec_internal(struct ata_device *dev,
1353 struct ata_taskfile *tf, const u8 *cdb, 1354 struct ata_taskfile *tf, const u8 *cdb,
1354 int dma_dir, void *buf, unsigned int buflen) 1355 int dma_dir, void *buf, unsigned int buflen)
1355{ 1356{
1356 struct scatterlist sg; 1357 struct scatterlist *psg = NULL, sg;
1358 unsigned int n_elem = 0;
1357 1359
1358 sg_init_one(&sg, buf, buflen); 1360 if (dma_dir != DMA_NONE) {
1361 WARN_ON(!buf);
1362 sg_init_one(&sg, buf, buflen);
1363 psg = &sg;
1364 n_elem++;
1365 }
1359 1366
1360 return ata_exec_internal_sg(dev, tf, cdb, dma_dir, &sg, 1); 1367 return ata_exec_internal_sg(dev, tf, cdb, dma_dir, psg, n_elem);
1361} 1368}
1362 1369
1363/** 1370/**
@@ -2425,18 +2432,8 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2425 int i, rc = 0, used_dma = 0, found = 0; 2432 int i, rc = 0, used_dma = 0, found = 0;
2426 2433
2427 /* has private set_mode? */ 2434 /* has private set_mode? */
2428 if (ap->ops->set_mode) { 2435 if (ap->ops->set_mode)
2429 /* FIXME: make ->set_mode handle no device case and 2436 return ap->ops->set_mode(ap, r_failed_dev);
2430 * return error code and failing device on failure.
2431 */
2432 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2433 if (ata_dev_ready(&ap->device[i])) {
2434 ap->ops->set_mode(ap);
2435 break;
2436 }
2437 }
2438 return 0;
2439 }
2440 2437
2441 /* step 1: calculate xfer_mask */ 2438 /* step 1: calculate xfer_mask */
2442 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2439 for (i = 0; i < ATA_MAX_DEVICES; i++) {
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 08ad44b3e4..748435807d 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1796,7 +1796,7 @@ static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
1796 *r_failed_dev = dev; 1796 *r_failed_dev = dev;
1797 1797
1798 DPRINTK("EXIT\n"); 1798 DPRINTK("EXIT\n");
1799 return 0; 1799 return rc;
1800} 1800}
1801 1801
1802/** 1802/**
@@ -1979,6 +1979,10 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1979 1979
1980 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; 1980 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
1981 1981
1982 /* collect port action mask recorded in dev actions */
1983 ehc->i.action |= ehc->i.dev_action[i] & ~ATA_EH_PERDEV_MASK;
1984 ehc->i.dev_action[i] &= ATA_EH_PERDEV_MASK;
1985
1982 /* process hotplug request */ 1986 /* process hotplug request */
1983 if (dev->flags & ATA_DFLAG_DETACH) 1987 if (dev->flags & ATA_DFLAG_DETACH)
1984 ata_eh_detach_dev(dev); 1988 ata_eh_detach_dev(dev);
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 664e1377b5..73902d3357 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -51,7 +51,7 @@
51 51
52#define SECTOR_SIZE 512 52#define SECTOR_SIZE 512
53 53
54typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd); 54typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc);
55 55
56static struct ata_device * __ata_scsi_find_dev(struct ata_port *ap, 56static struct ata_device * __ata_scsi_find_dev(struct ata_port *ap,
57 const struct scsi_device *scsidev); 57 const struct scsi_device *scsidev);
@@ -273,8 +273,8 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
273{ 273{
274 int rc = 0; 274 int rc = 0;
275 u8 scsi_cmd[MAX_COMMAND_SIZE]; 275 u8 scsi_cmd[MAX_COMMAND_SIZE];
276 u8 args[7]; 276 u8 args[7], *sensebuf = NULL;
277 struct scsi_sense_hdr sshdr; 277 int cmd_result;
278 278
279 if (arg == NULL) 279 if (arg == NULL)
280 return -EINVAL; 280 return -EINVAL;
@@ -282,10 +282,14 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
282 if (copy_from_user(args, arg, sizeof(args))) 282 if (copy_from_user(args, arg, sizeof(args)))
283 return -EFAULT; 283 return -EFAULT;
284 284
285 sensebuf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_NOIO);
286 if (!sensebuf)
287 return -ENOMEM;
288
285 memset(scsi_cmd, 0, sizeof(scsi_cmd)); 289 memset(scsi_cmd, 0, sizeof(scsi_cmd));
286 scsi_cmd[0] = ATA_16; 290 scsi_cmd[0] = ATA_16;
287 scsi_cmd[1] = (3 << 1); /* Non-data */ 291 scsi_cmd[1] = (3 << 1); /* Non-data */
288 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */ 292 scsi_cmd[2] = 0x20; /* cc but no off.line or data xfer */
289 scsi_cmd[4] = args[1]; 293 scsi_cmd[4] = args[1];
290 scsi_cmd[6] = args[2]; 294 scsi_cmd[6] = args[2];
291 scsi_cmd[8] = args[3]; 295 scsi_cmd[8] = args[3];
@@ -295,11 +299,46 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
295 299
296 /* Good values for timeout and retries? Values below 300 /* Good values for timeout and retries? Values below
297 from scsi_ioctl_send_command() for default case... */ 301 from scsi_ioctl_send_command() for default case... */
298 if (scsi_execute_req(scsidev, scsi_cmd, DMA_NONE, NULL, 0, &sshdr, 302 cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0,
299 (10*HZ), 5)) 303 sensebuf, (10*HZ), 5, 0);
304
305 if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
306 u8 *desc = sensebuf + 8;
307 cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
308
309 /* If we set cc then ATA pass-through will cause a
310 * check condition even if no error. Filter that. */
311 if (cmd_result & SAM_STAT_CHECK_CONDITION) {
312 struct scsi_sense_hdr sshdr;
313 scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE,
314 &sshdr);
315 if (sshdr.sense_key==0 &&
316 sshdr.asc==0 && sshdr.ascq==0)
317 cmd_result &= ~SAM_STAT_CHECK_CONDITION;
318 }
319
320 /* Send userspace ATA registers */
321 if (sensebuf[0] == 0x72 && /* format is "descriptor" */
322 desc[0] == 0x09) {/* code is "ATA Descriptor" */
323 args[0] = desc[13]; /* status */
324 args[1] = desc[3]; /* error */
325 args[2] = desc[5]; /* sector count (0:7) */
326 args[3] = desc[7]; /* lbal */
327 args[4] = desc[9]; /* lbam */
328 args[5] = desc[11]; /* lbah */
329 args[6] = desc[12]; /* select */
330 if (copy_to_user(arg, args, sizeof(args)))
331 rc = -EFAULT;
332 }
333 }
334
335 if (cmd_result) {
300 rc = -EIO; 336 rc = -EIO;
337 goto error;
338 }
301 339
302 /* Need code to retrieve data from check condition? */ 340 error:
341 kfree(sensebuf);
303 return rc; 342 return rc;
304} 343}
305 344
@@ -372,7 +411,7 @@ struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev,
372 if (cmd->use_sg) { 411 if (cmd->use_sg) {
373 qc->__sg = (struct scatterlist *) cmd->request_buffer; 412 qc->__sg = (struct scatterlist *) cmd->request_buffer;
374 qc->n_elem = cmd->use_sg; 413 qc->n_elem = cmd->use_sg;
375 } else { 414 } else if (cmd->request_bufflen) {
376 qc->__sg = &qc->sgent; 415 qc->__sg = &qc->sgent;
377 qc->n_elem = 1; 416 qc->n_elem = 1;
378 } 417 }
@@ -935,7 +974,6 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
935/** 974/**
936 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command 975 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
937 * @qc: Storage for translated ATA taskfile 976 * @qc: Storage for translated ATA taskfile
938 * @scsicmd: SCSI command to translate
939 * 977 *
940 * Sets up an ATA taskfile to issue STANDBY (to stop) or READ VERIFY 978 * Sets up an ATA taskfile to issue STANDBY (to stop) or READ VERIFY
941 * (to start). Perhaps these commands should be preceded by 979 * (to start). Perhaps these commands should be preceded by
@@ -948,22 +986,25 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
948 * RETURNS: 986 * RETURNS:
949 * Zero on success, non-zero on error. 987 * Zero on success, non-zero on error.
950 */ 988 */
951 989static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc)
952static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc,
953 const u8 *scsicmd)
954{ 990{
991 struct scsi_cmnd *scmd = qc->scsicmd;
955 struct ata_taskfile *tf = &qc->tf; 992 struct ata_taskfile *tf = &qc->tf;
993 const u8 *cdb = scmd->cmnd;
994
995 if (scmd->cmd_len < 5)
996 goto invalid_fld;
956 997
957 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; 998 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
958 tf->protocol = ATA_PROT_NODATA; 999 tf->protocol = ATA_PROT_NODATA;
959 if (scsicmd[1] & 0x1) { 1000 if (cdb[1] & 0x1) {
960 ; /* ignore IMMED bit, violates sat-r05 */ 1001 ; /* ignore IMMED bit, violates sat-r05 */
961 } 1002 }
962 if (scsicmd[4] & 0x2) 1003 if (cdb[4] & 0x2)
963 goto invalid_fld; /* LOEJ bit set not supported */ 1004 goto invalid_fld; /* LOEJ bit set not supported */
964 if (((scsicmd[4] >> 4) & 0xf) != 0) 1005 if (((cdb[4] >> 4) & 0xf) != 0)
965 goto invalid_fld; /* power conditions not supported */ 1006 goto invalid_fld; /* power conditions not supported */
966 if (scsicmd[4] & 0x1) { 1007 if (cdb[4] & 0x1) {
967 tf->nsect = 1; /* 1 sector, lba=0 */ 1008 tf->nsect = 1; /* 1 sector, lba=0 */
968 1009
969 if (qc->dev->flags & ATA_DFLAG_LBA) { 1010 if (qc->dev->flags & ATA_DFLAG_LBA) {
@@ -981,11 +1022,10 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc,
981 } 1022 }
982 1023
983 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ 1024 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */
984 } else { 1025 } else
985 tf->nsect = 0; /* time period value (0 implies now) */ 1026 /* Issue ATA STANDBY IMMEDIATE command */
986 tf->command = ATA_CMD_STANDBY; 1027 tf->command = ATA_CMD_STANDBYNOW1;
987 /* Consider: ATA STANDBY IMMEDIATE command */ 1028
988 }
989 /* 1029 /*
990 * Standby and Idle condition timers could be implemented but that 1030 * Standby and Idle condition timers could be implemented but that
991 * would require libata to implement the Power condition mode page 1031 * would require libata to implement the Power condition mode page
@@ -996,7 +1036,7 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc,
996 return 0; 1036 return 0;
997 1037
998invalid_fld: 1038invalid_fld:
999 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); 1039 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x0);
1000 /* "Invalid field in cbd" */ 1040 /* "Invalid field in cbd" */
1001 return 1; 1041 return 1;
1002} 1042}
@@ -1005,7 +1045,6 @@ invalid_fld:
1005/** 1045/**
1006 * ata_scsi_flush_xlat - Translate SCSI SYNCHRONIZE CACHE command 1046 * ata_scsi_flush_xlat - Translate SCSI SYNCHRONIZE CACHE command
1007 * @qc: Storage for translated ATA taskfile 1047 * @qc: Storage for translated ATA taskfile
1008 * @scsicmd: SCSI command to translate (ignored)
1009 * 1048 *
1010 * Sets up an ATA taskfile to issue FLUSH CACHE or 1049 * Sets up an ATA taskfile to issue FLUSH CACHE or
1011 * FLUSH CACHE EXT. 1050 * FLUSH CACHE EXT.
@@ -1016,8 +1055,7 @@ invalid_fld:
1016 * RETURNS: 1055 * RETURNS:
1017 * Zero on success, non-zero on error. 1056 * Zero on success, non-zero on error.
1018 */ 1057 */
1019 1058static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc)
1020static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
1021{ 1059{
1022 struct ata_taskfile *tf = &qc->tf; 1060 struct ata_taskfile *tf = &qc->tf;
1023 1061
@@ -1034,7 +1072,7 @@ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, const u8 *scs
1034 1072
1035/** 1073/**
1036 * scsi_6_lba_len - Get LBA and transfer length 1074 * scsi_6_lba_len - Get LBA and transfer length
1037 * @scsicmd: SCSI command to translate 1075 * @cdb: SCSI command to translate
1038 * 1076 *
1039 * Calculate LBA and transfer length for 6-byte commands. 1077 * Calculate LBA and transfer length for 6-byte commands.
1040 * 1078 *
@@ -1042,18 +1080,17 @@ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, const u8 *scs
1042 * @plba: the LBA 1080 * @plba: the LBA
1043 * @plen: the transfer length 1081 * @plen: the transfer length
1044 */ 1082 */
1045 1083static void scsi_6_lba_len(const u8 *cdb, u64 *plba, u32 *plen)
1046static void scsi_6_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1047{ 1084{
1048 u64 lba = 0; 1085 u64 lba = 0;
1049 u32 len = 0; 1086 u32 len = 0;
1050 1087
1051 VPRINTK("six-byte command\n"); 1088 VPRINTK("six-byte command\n");
1052 1089
1053 lba |= ((u64)scsicmd[2]) << 8; 1090 lba |= ((u64)cdb[2]) << 8;
1054 lba |= ((u64)scsicmd[3]); 1091 lba |= ((u64)cdb[3]);
1055 1092
1056 len |= ((u32)scsicmd[4]); 1093 len |= ((u32)cdb[4]);
1057 1094
1058 *plba = lba; 1095 *plba = lba;
1059 *plen = len; 1096 *plen = len;
@@ -1061,7 +1098,7 @@ static void scsi_6_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1061 1098
1062/** 1099/**
1063 * scsi_10_lba_len - Get LBA and transfer length 1100 * scsi_10_lba_len - Get LBA and transfer length
1064 * @scsicmd: SCSI command to translate 1101 * @cdb: SCSI command to translate
1065 * 1102 *
1066 * Calculate LBA and transfer length for 10-byte commands. 1103 * Calculate LBA and transfer length for 10-byte commands.
1067 * 1104 *
@@ -1069,21 +1106,20 @@ static void scsi_6_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1069 * @plba: the LBA 1106 * @plba: the LBA
1070 * @plen: the transfer length 1107 * @plen: the transfer length
1071 */ 1108 */
1072 1109static void scsi_10_lba_len(const u8 *cdb, u64 *plba, u32 *plen)
1073static void scsi_10_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1074{ 1110{
1075 u64 lba = 0; 1111 u64 lba = 0;
1076 u32 len = 0; 1112 u32 len = 0;
1077 1113
1078 VPRINTK("ten-byte command\n"); 1114 VPRINTK("ten-byte command\n");
1079 1115
1080 lba |= ((u64)scsicmd[2]) << 24; 1116 lba |= ((u64)cdb[2]) << 24;
1081 lba |= ((u64)scsicmd[3]) << 16; 1117 lba |= ((u64)cdb[3]) << 16;
1082 lba |= ((u64)scsicmd[4]) << 8; 1118 lba |= ((u64)cdb[4]) << 8;
1083 lba |= ((u64)scsicmd[5]); 1119 lba |= ((u64)cdb[5]);
1084 1120
1085 len |= ((u32)scsicmd[7]) << 8; 1121 len |= ((u32)cdb[7]) << 8;
1086 len |= ((u32)scsicmd[8]); 1122 len |= ((u32)cdb[8]);
1087 1123
1088 *plba = lba; 1124 *plba = lba;
1089 *plen = len; 1125 *plen = len;
@@ -1091,7 +1127,7 @@ static void scsi_10_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1091 1127
1092/** 1128/**
1093 * scsi_16_lba_len - Get LBA and transfer length 1129 * scsi_16_lba_len - Get LBA and transfer length
1094 * @scsicmd: SCSI command to translate 1130 * @cdb: SCSI command to translate
1095 * 1131 *
1096 * Calculate LBA and transfer length for 16-byte commands. 1132 * Calculate LBA and transfer length for 16-byte commands.
1097 * 1133 *
@@ -1099,27 +1135,26 @@ static void scsi_10_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1099 * @plba: the LBA 1135 * @plba: the LBA
1100 * @plen: the transfer length 1136 * @plen: the transfer length
1101 */ 1137 */
1102 1138static void scsi_16_lba_len(const u8 *cdb, u64 *plba, u32 *plen)
1103static void scsi_16_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1104{ 1139{
1105 u64 lba = 0; 1140 u64 lba = 0;
1106 u32 len = 0; 1141 u32 len = 0;
1107 1142
1108 VPRINTK("sixteen-byte command\n"); 1143 VPRINTK("sixteen-byte command\n");
1109 1144
1110 lba |= ((u64)scsicmd[2]) << 56; 1145 lba |= ((u64)cdb[2]) << 56;
1111 lba |= ((u64)scsicmd[3]) << 48; 1146 lba |= ((u64)cdb[3]) << 48;
1112 lba |= ((u64)scsicmd[4]) << 40; 1147 lba |= ((u64)cdb[4]) << 40;
1113 lba |= ((u64)scsicmd[5]) << 32; 1148 lba |= ((u64)cdb[5]) << 32;
1114 lba |= ((u64)scsicmd[6]) << 24; 1149 lba |= ((u64)cdb[6]) << 24;
1115 lba |= ((u64)scsicmd[7]) << 16; 1150 lba |= ((u64)cdb[7]) << 16;
1116 lba |= ((u64)scsicmd[8]) << 8; 1151 lba |= ((u64)cdb[8]) << 8;
1117 lba |= ((u64)scsicmd[9]); 1152 lba |= ((u64)cdb[9]);
1118 1153
1119 len |= ((u32)scsicmd[10]) << 24; 1154 len |= ((u32)cdb[10]) << 24;
1120 len |= ((u32)scsicmd[11]) << 16; 1155 len |= ((u32)cdb[11]) << 16;
1121 len |= ((u32)scsicmd[12]) << 8; 1156 len |= ((u32)cdb[12]) << 8;
1122 len |= ((u32)scsicmd[13]); 1157 len |= ((u32)cdb[13]);
1123 1158
1124 *plba = lba; 1159 *plba = lba;
1125 *plen = len; 1160 *plen = len;
@@ -1128,7 +1163,6 @@ static void scsi_16_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1128/** 1163/**
1129 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one 1164 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one
1130 * @qc: Storage for translated ATA taskfile 1165 * @qc: Storage for translated ATA taskfile
1131 * @scsicmd: SCSI command to translate
1132 * 1166 *
1133 * Converts SCSI VERIFY command to an ATA READ VERIFY command. 1167 * Converts SCSI VERIFY command to an ATA READ VERIFY command.
1134 * 1168 *
@@ -1138,23 +1172,28 @@ static void scsi_16_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1138 * RETURNS: 1172 * RETURNS:
1139 * Zero on success, non-zero on error. 1173 * Zero on success, non-zero on error.
1140 */ 1174 */
1141 1175static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc)
1142static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
1143{ 1176{
1177 struct scsi_cmnd *scmd = qc->scsicmd;
1144 struct ata_taskfile *tf = &qc->tf; 1178 struct ata_taskfile *tf = &qc->tf;
1145 struct ata_device *dev = qc->dev; 1179 struct ata_device *dev = qc->dev;
1146 u64 dev_sectors = qc->dev->n_sectors; 1180 u64 dev_sectors = qc->dev->n_sectors;
1181 const u8 *cdb = scmd->cmnd;
1147 u64 block; 1182 u64 block;
1148 u32 n_block; 1183 u32 n_block;
1149 1184
1150 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 1185 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
1151 tf->protocol = ATA_PROT_NODATA; 1186 tf->protocol = ATA_PROT_NODATA;
1152 1187
1153 if (scsicmd[0] == VERIFY) 1188 if (cdb[0] == VERIFY) {
1154 scsi_10_lba_len(scsicmd, &block, &n_block); 1189 if (scmd->cmd_len < 10)
1155 else if (scsicmd[0] == VERIFY_16) 1190 goto invalid_fld;
1156 scsi_16_lba_len(scsicmd, &block, &n_block); 1191 scsi_10_lba_len(cdb, &block, &n_block);
1157 else 1192 } else if (cdb[0] == VERIFY_16) {
1193 if (scmd->cmd_len < 16)
1194 goto invalid_fld;
1195 scsi_16_lba_len(cdb, &block, &n_block);
1196 } else
1158 goto invalid_fld; 1197 goto invalid_fld;
1159 1198
1160 if (!n_block) 1199 if (!n_block)
@@ -1229,24 +1268,23 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc
1229 return 0; 1268 return 0;
1230 1269
1231invalid_fld: 1270invalid_fld:
1232 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); 1271 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x0);
1233 /* "Invalid field in cbd" */ 1272 /* "Invalid field in cbd" */
1234 return 1; 1273 return 1;
1235 1274
1236out_of_range: 1275out_of_range:
1237 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x21, 0x0); 1276 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x21, 0x0);
1238 /* "Logical Block Address out of range" */ 1277 /* "Logical Block Address out of range" */
1239 return 1; 1278 return 1;
1240 1279
1241nothing_to_do: 1280nothing_to_do:
1242 qc->scsicmd->result = SAM_STAT_GOOD; 1281 scmd->result = SAM_STAT_GOOD;
1243 return 1; 1282 return 1;
1244} 1283}
1245 1284
1246/** 1285/**
1247 * ata_scsi_rw_xlat - Translate SCSI r/w command into an ATA one 1286 * ata_scsi_rw_xlat - Translate SCSI r/w command into an ATA one
1248 * @qc: Storage for translated ATA taskfile 1287 * @qc: Storage for translated ATA taskfile
1249 * @scsicmd: SCSI command to translate
1250 * 1288 *
1251 * Converts any of six SCSI read/write commands into the 1289 * Converts any of six SCSI read/write commands into the
1252 * ATA counterpart, including starting sector (LBA), 1290 * ATA counterpart, including starting sector (LBA),
@@ -1262,29 +1300,33 @@ nothing_to_do:
1262 * RETURNS: 1300 * RETURNS:
1263 * Zero on success, non-zero on error. 1301 * Zero on success, non-zero on error.
1264 */ 1302 */
1265 1303static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc)
1266static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
1267{ 1304{
1305 struct scsi_cmnd *scmd = qc->scsicmd;
1306 const u8 *cdb = scmd->cmnd;
1268 unsigned int tf_flags = 0; 1307 unsigned int tf_flags = 0;
1269 u64 block; 1308 u64 block;
1270 u32 n_block; 1309 u32 n_block;
1271 int rc; 1310 int rc;
1272 1311
1273 if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 || 1312 if (cdb[0] == WRITE_10 || cdb[0] == WRITE_6 || cdb[0] == WRITE_16)
1274 scsicmd[0] == WRITE_16)
1275 tf_flags |= ATA_TFLAG_WRITE; 1313 tf_flags |= ATA_TFLAG_WRITE;
1276 1314
1277 /* Calculate the SCSI LBA, transfer length and FUA. */ 1315 /* Calculate the SCSI LBA, transfer length and FUA. */
1278 switch (scsicmd[0]) { 1316 switch (cdb[0]) {
1279 case READ_10: 1317 case READ_10:
1280 case WRITE_10: 1318 case WRITE_10:
1281 scsi_10_lba_len(scsicmd, &block, &n_block); 1319 if (unlikely(scmd->cmd_len < 10))
1282 if (unlikely(scsicmd[1] & (1 << 3))) 1320 goto invalid_fld;
1321 scsi_10_lba_len(cdb, &block, &n_block);
1322 if (unlikely(cdb[1] & (1 << 3)))
1283 tf_flags |= ATA_TFLAG_FUA; 1323 tf_flags |= ATA_TFLAG_FUA;
1284 break; 1324 break;
1285 case READ_6: 1325 case READ_6:
1286 case WRITE_6: 1326 case WRITE_6:
1287 scsi_6_lba_len(scsicmd, &block, &n_block); 1327 if (unlikely(scmd->cmd_len < 6))
1328 goto invalid_fld;
1329 scsi_6_lba_len(cdb, &block, &n_block);
1288 1330
1289 /* for 6-byte r/w commands, transfer length 0 1331 /* for 6-byte r/w commands, transfer length 0
1290 * means 256 blocks of data, not 0 block. 1332 * means 256 blocks of data, not 0 block.
@@ -1294,8 +1336,10 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1294 break; 1336 break;
1295 case READ_16: 1337 case READ_16:
1296 case WRITE_16: 1338 case WRITE_16:
1297 scsi_16_lba_len(scsicmd, &block, &n_block); 1339 if (unlikely(scmd->cmd_len < 16))
1298 if (unlikely(scsicmd[1] & (1 << 3))) 1340 goto invalid_fld;
1341 scsi_16_lba_len(cdb, &block, &n_block);
1342 if (unlikely(cdb[1] & (1 << 3)))
1299 tf_flags |= ATA_TFLAG_FUA; 1343 tf_flags |= ATA_TFLAG_FUA;
1300 break; 1344 break;
1301 default: 1345 default:
@@ -1326,17 +1370,17 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1326 goto out_of_range; 1370 goto out_of_range;
1327 /* treat all other errors as -EINVAL, fall through */ 1371 /* treat all other errors as -EINVAL, fall through */
1328invalid_fld: 1372invalid_fld:
1329 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); 1373 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x0);
1330 /* "Invalid field in cbd" */ 1374 /* "Invalid field in cbd" */
1331 return 1; 1375 return 1;
1332 1376
1333out_of_range: 1377out_of_range:
1334 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x21, 0x0); 1378 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x21, 0x0);
1335 /* "Logical Block Address out of range" */ 1379 /* "Logical Block Address out of range" */
1336 return 1; 1380 return 1;
1337 1381
1338nothing_to_do: 1382nothing_to_do:
1339 qc->scsicmd->result = SAM_STAT_GOOD; 1383 scmd->result = SAM_STAT_GOOD;
1340 return 1; 1384 return 1;
1341} 1385}
1342 1386
@@ -1456,7 +1500,6 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
1456 ata_xlat_func_t xlat_func) 1500 ata_xlat_func_t xlat_func)
1457{ 1501{
1458 struct ata_queued_cmd *qc; 1502 struct ata_queued_cmd *qc;
1459 u8 *scsicmd = cmd->cmnd;
1460 int is_io = xlat_func == ata_scsi_rw_xlat; 1503 int is_io = xlat_func == ata_scsi_rw_xlat;
1461 1504
1462 VPRINTK("ENTER\n"); 1505 VPRINTK("ENTER\n");
@@ -1488,7 +1531,7 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
1488 1531
1489 qc->complete_fn = ata_scsi_qc_complete; 1532 qc->complete_fn = ata_scsi_qc_complete;
1490 1533
1491 if (xlat_func(qc, scsicmd)) 1534 if (xlat_func(qc))
1492 goto early_finish; 1535 goto early_finish;
1493 1536
1494 /* select device, send command to hardware */ 1537 /* select device, send command to hardware */
@@ -1539,7 +1582,7 @@ static unsigned int ata_scsi_rbuf_get(struct scsi_cmnd *cmd, u8 **buf_out)
1539 struct scatterlist *sg; 1582 struct scatterlist *sg;
1540 1583
1541 sg = (struct scatterlist *) cmd->request_buffer; 1584 sg = (struct scatterlist *) cmd->request_buffer;
1542 buf = kmap_atomic(sg->page, KM_USER0) + sg->offset; 1585 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
1543 buflen = sg->length; 1586 buflen = sg->length;
1544 } else { 1587 } else {
1545 buf = cmd->request_buffer; 1588 buf = cmd->request_buffer;
@@ -1567,7 +1610,7 @@ static inline void ata_scsi_rbuf_put(struct scsi_cmnd *cmd, u8 *buf)
1567 struct scatterlist *sg; 1610 struct scatterlist *sg;
1568 1611
1569 sg = (struct scatterlist *) cmd->request_buffer; 1612 sg = (struct scatterlist *) cmd->request_buffer;
1570 kunmap_atomic(buf - sg->offset, KM_USER0); 1613 kunmap_atomic(buf - sg->offset, KM_IRQ0);
1571 } 1614 }
1572} 1615}
1573 1616
@@ -2344,7 +2387,6 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc)
2344/** 2387/**
2345 * atapi_xlat - Initialize PACKET taskfile 2388 * atapi_xlat - Initialize PACKET taskfile
2346 * @qc: command structure to be initialized 2389 * @qc: command structure to be initialized
2347 * @scsicmd: SCSI CDB associated with this PACKET command
2348 * 2390 *
2349 * LOCKING: 2391 * LOCKING:
2350 * spin_lock_irqsave(host lock) 2392 * spin_lock_irqsave(host lock)
@@ -2352,25 +2394,25 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc)
2352 * RETURNS: 2394 * RETURNS:
2353 * Zero on success, non-zero on failure. 2395 * Zero on success, non-zero on failure.
2354 */ 2396 */
2355 2397static unsigned int atapi_xlat(struct ata_queued_cmd *qc)
2356static unsigned int atapi_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
2357{ 2398{
2358 struct scsi_cmnd *cmd = qc->scsicmd; 2399 struct scsi_cmnd *scmd = qc->scsicmd;
2359 struct ata_device *dev = qc->dev; 2400 struct ata_device *dev = qc->dev;
2360 int using_pio = (dev->flags & ATA_DFLAG_PIO); 2401 int using_pio = (dev->flags & ATA_DFLAG_PIO);
2361 int nodata = (cmd->sc_data_direction == DMA_NONE); 2402 int nodata = (scmd->sc_data_direction == DMA_NONE);
2362 2403
2363 if (!using_pio) 2404 if (!using_pio)
2364 /* Check whether ATAPI DMA is safe */ 2405 /* Check whether ATAPI DMA is safe */
2365 if (ata_check_atapi_dma(qc)) 2406 if (ata_check_atapi_dma(qc))
2366 using_pio = 1; 2407 using_pio = 1;
2367 2408
2368 memcpy(&qc->cdb, scsicmd, dev->cdb_len); 2409 memset(qc->cdb, 0, dev->cdb_len);
2410 memcpy(qc->cdb, scmd->cmnd, scmd->cmd_len);
2369 2411
2370 qc->complete_fn = atapi_qc_complete; 2412 qc->complete_fn = atapi_qc_complete;
2371 2413
2372 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 2414 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
2373 if (cmd->sc_data_direction == DMA_TO_DEVICE) { 2415 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
2374 qc->tf.flags |= ATA_TFLAG_WRITE; 2416 qc->tf.flags |= ATA_TFLAG_WRITE;
2375 DPRINTK("direction: write\n"); 2417 DPRINTK("direction: write\n");
2376 } 2418 }
@@ -2392,12 +2434,12 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
2392 qc->tf.protocol = ATA_PROT_ATAPI_DMA; 2434 qc->tf.protocol = ATA_PROT_ATAPI_DMA;
2393 qc->tf.feature |= ATAPI_PKT_DMA; 2435 qc->tf.feature |= ATAPI_PKT_DMA;
2394 2436
2395 if (atapi_dmadir && (cmd->sc_data_direction != DMA_TO_DEVICE)) 2437 if (atapi_dmadir && (scmd->sc_data_direction != DMA_TO_DEVICE))
2396 /* some SATA bridges need us to indicate data xfer direction */ 2438 /* some SATA bridges need us to indicate data xfer direction */
2397 qc->tf.feature |= ATAPI_DMADIR; 2439 qc->tf.feature |= ATAPI_DMADIR;
2398 } 2440 }
2399 2441
2400 qc->nbytes = cmd->request_bufflen; 2442 qc->nbytes = scmd->request_bufflen;
2401 2443
2402 return 0; 2444 return 0;
2403} 2445}
@@ -2517,28 +2559,27 @@ ata_scsi_map_proto(u8 byte1)
2517/** 2559/**
2518 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile 2560 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile
2519 * @qc: command structure to be initialized 2561 * @qc: command structure to be initialized
2520 * @scsicmd: SCSI command to convert
2521 * 2562 *
2522 * Handles either 12 or 16-byte versions of the CDB. 2563 * Handles either 12 or 16-byte versions of the CDB.
2523 * 2564 *
2524 * RETURNS: 2565 * RETURNS:
2525 * Zero on success, non-zero on failure. 2566 * Zero on success, non-zero on failure.
2526 */ 2567 */
2527static unsigned int 2568static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
2528ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2529{ 2569{
2530 struct ata_taskfile *tf = &(qc->tf); 2570 struct ata_taskfile *tf = &(qc->tf);
2531 struct scsi_cmnd *cmd = qc->scsicmd; 2571 struct scsi_cmnd *scmd = qc->scsicmd;
2532 struct ata_device *dev = qc->dev; 2572 struct ata_device *dev = qc->dev;
2573 const u8 *cdb = scmd->cmnd;
2533 2574
2534 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN) 2575 if ((tf->protocol = ata_scsi_map_proto(cdb[1])) == ATA_PROT_UNKNOWN)
2535 goto invalid_fld; 2576 goto invalid_fld;
2536 2577
2537 /* We may not issue DMA commands if no DMA mode is set */ 2578 /* We may not issue DMA commands if no DMA mode is set */
2538 if (tf->protocol == ATA_PROT_DMA && dev->dma_mode == 0) 2579 if (tf->protocol == ATA_PROT_DMA && dev->dma_mode == 0)
2539 goto invalid_fld; 2580 goto invalid_fld;
2540 2581
2541 if (scsicmd[1] & 0xe0) 2582 if (cdb[1] & 0xe0)
2542 /* PIO multi not supported yet */ 2583 /* PIO multi not supported yet */
2543 goto invalid_fld; 2584 goto invalid_fld;
2544 2585
@@ -2546,18 +2587,18 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2546 * 12 and 16 byte CDBs use different offsets to 2587 * 12 and 16 byte CDBs use different offsets to
2547 * provide the various register values. 2588 * provide the various register values.
2548 */ 2589 */
2549 if (scsicmd[0] == ATA_16) { 2590 if (cdb[0] == ATA_16) {
2550 /* 2591 /*
2551 * 16-byte CDB - may contain extended commands. 2592 * 16-byte CDB - may contain extended commands.
2552 * 2593 *
2553 * If that is the case, copy the upper byte register values. 2594 * If that is the case, copy the upper byte register values.
2554 */ 2595 */
2555 if (scsicmd[1] & 0x01) { 2596 if (cdb[1] & 0x01) {
2556 tf->hob_feature = scsicmd[3]; 2597 tf->hob_feature = cdb[3];
2557 tf->hob_nsect = scsicmd[5]; 2598 tf->hob_nsect = cdb[5];
2558 tf->hob_lbal = scsicmd[7]; 2599 tf->hob_lbal = cdb[7];
2559 tf->hob_lbam = scsicmd[9]; 2600 tf->hob_lbam = cdb[9];
2560 tf->hob_lbah = scsicmd[11]; 2601 tf->hob_lbah = cdb[11];
2561 tf->flags |= ATA_TFLAG_LBA48; 2602 tf->flags |= ATA_TFLAG_LBA48;
2562 } else 2603 } else
2563 tf->flags &= ~ATA_TFLAG_LBA48; 2604 tf->flags &= ~ATA_TFLAG_LBA48;
@@ -2565,26 +2606,26 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2565 /* 2606 /*
2566 * Always copy low byte, device and command registers. 2607 * Always copy low byte, device and command registers.
2567 */ 2608 */
2568 tf->feature = scsicmd[4]; 2609 tf->feature = cdb[4];
2569 tf->nsect = scsicmd[6]; 2610 tf->nsect = cdb[6];
2570 tf->lbal = scsicmd[8]; 2611 tf->lbal = cdb[8];
2571 tf->lbam = scsicmd[10]; 2612 tf->lbam = cdb[10];
2572 tf->lbah = scsicmd[12]; 2613 tf->lbah = cdb[12];
2573 tf->device = scsicmd[13]; 2614 tf->device = cdb[13];
2574 tf->command = scsicmd[14]; 2615 tf->command = cdb[14];
2575 } else { 2616 } else {
2576 /* 2617 /*
2577 * 12-byte CDB - incapable of extended commands. 2618 * 12-byte CDB - incapable of extended commands.
2578 */ 2619 */
2579 tf->flags &= ~ATA_TFLAG_LBA48; 2620 tf->flags &= ~ATA_TFLAG_LBA48;
2580 2621
2581 tf->feature = scsicmd[3]; 2622 tf->feature = cdb[3];
2582 tf->nsect = scsicmd[4]; 2623 tf->nsect = cdb[4];
2583 tf->lbal = scsicmd[5]; 2624 tf->lbal = cdb[5];
2584 tf->lbam = scsicmd[6]; 2625 tf->lbam = cdb[6];
2585 tf->lbah = scsicmd[7]; 2626 tf->lbah = cdb[7];
2586 tf->device = scsicmd[8]; 2627 tf->device = cdb[8];
2587 tf->command = scsicmd[9]; 2628 tf->command = cdb[9];
2588 } 2629 }
2589 /* 2630 /*
2590 * If slave is possible, enforce correct master/slave bit 2631 * If slave is possible, enforce correct master/slave bit
@@ -2611,7 +2652,7 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2611 */ 2652 */
2612 tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE); 2653 tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE);
2613 2654
2614 if (cmd->sc_data_direction == DMA_TO_DEVICE) 2655 if (scmd->sc_data_direction == DMA_TO_DEVICE)
2615 tf->flags |= ATA_TFLAG_WRITE; 2656 tf->flags |= ATA_TFLAG_WRITE;
2616 2657
2617 /* 2658 /*
@@ -2620,7 +2661,7 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2620 * TODO: find out if we need to do more here to 2661 * TODO: find out if we need to do more here to
2621 * cover scatter/gather case. 2662 * cover scatter/gather case.
2622 */ 2663 */
2623 qc->nsect = cmd->request_bufflen / ATA_SECT_SIZE; 2664 qc->nsect = scmd->request_bufflen / ATA_SECT_SIZE;
2624 2665
2625 /* request result TF */ 2666 /* request result TF */
2626 qc->flags |= ATA_QCFLAG_RESULT_TF; 2667 qc->flags |= ATA_QCFLAG_RESULT_TF;
@@ -2628,7 +2669,7 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2628 return 0; 2669 return 0;
2629 2670
2630 invalid_fld: 2671 invalid_fld:
2631 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x00); 2672 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x00);
2632 /* "Invalid field in cdb" */ 2673 /* "Invalid field in cdb" */
2633 return 1; 2674 return 1;
2634} 2675}
@@ -2701,22 +2742,29 @@ static inline void ata_scsi_dump_cdb(struct ata_port *ap,
2701#endif 2742#endif
2702} 2743}
2703 2744
2704static inline int __ata_scsi_queuecmd(struct scsi_cmnd *cmd, 2745static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
2705 void (*done)(struct scsi_cmnd *), 2746 void (*done)(struct scsi_cmnd *),
2706 struct ata_device *dev) 2747 struct ata_device *dev)
2707{ 2748{
2708 int rc = 0; 2749 int rc = 0;
2709 2750
2751 if (unlikely(!scmd->cmd_len)) {
2752 ata_dev_printk(dev, KERN_WARNING, "WARNING: zero len CDB\n");
2753 scmd->result = DID_ERROR << 16;
2754 done(scmd);
2755 return 0;
2756 }
2757
2710 if (dev->class == ATA_DEV_ATA) { 2758 if (dev->class == ATA_DEV_ATA) {
2711 ata_xlat_func_t xlat_func = ata_get_xlat_func(dev, 2759 ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
2712 cmd->cmnd[0]); 2760 scmd->cmnd[0]);
2713 2761
2714 if (xlat_func) 2762 if (xlat_func)
2715 rc = ata_scsi_translate(dev, cmd, done, xlat_func); 2763 rc = ata_scsi_translate(dev, scmd, done, xlat_func);
2716 else 2764 else
2717 ata_scsi_simulate(dev, cmd, done); 2765 ata_scsi_simulate(dev, scmd, done);
2718 } else 2766 } else
2719 rc = ata_scsi_translate(dev, cmd, done, atapi_xlat); 2767 rc = ata_scsi_translate(dev, scmd, done, atapi_xlat);
2720 2768
2721 return rc; 2769 return rc;
2722} 2770}
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 10ee22ae5c..12c88c5880 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -827,7 +827,8 @@ void ata_bmdma_error_handler(struct ata_port *ap)
827 */ 827 */
828void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc) 828void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc)
829{ 829{
830 ata_bmdma_stop(qc); 830 if (qc->ap->ioaddr.bmdma_addr)
831 ata_bmdma_stop(qc);
831} 832}
832 833
833#ifdef CONFIG_PCI 834#ifdef CONFIG_PCI
@@ -870,7 +871,8 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
870 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS; 871 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS;
871 bmdma = pci_resource_start(pdev, 4); 872 bmdma = pci_resource_start(pdev, 4);
872 if (bmdma) { 873 if (bmdma) {
873 if (inb(bmdma + 2) & 0x80) 874 if ((!(port[p]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
875 (inb(bmdma + 2) & 0x80))
874 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 876 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
875 probe_ent->port[p].bmdma_addr = bmdma; 877 probe_ent->port[p].bmdma_addr = bmdma;
876 } 878 }
@@ -886,7 +888,8 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
886 bmdma = pci_resource_start(pdev, 4); 888 bmdma = pci_resource_start(pdev, 4);
887 if (bmdma) { 889 if (bmdma) {
888 bmdma += 8; 890 bmdma += 8;
889 if(inb(bmdma + 2) & 0x80) 891 if ((!(port[p]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
892 (inb(bmdma + 2) & 0x80))
890 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 893 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
891 probe_ent->port[p].bmdma_addr = bmdma; 894 probe_ent->port[p].bmdma_addr = bmdma;
892 } 895 }
@@ -914,13 +917,14 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
914 probe_ent->irq_flags = IRQF_SHARED; 917 probe_ent->irq_flags = IRQF_SHARED;
915 918
916 if (port_mask & ATA_PORT_PRIMARY) { 919 if (port_mask & ATA_PORT_PRIMARY) {
917 probe_ent->irq = ATA_PRIMARY_IRQ; 920 probe_ent->irq = ATA_PRIMARY_IRQ(pdev);
918 probe_ent->port[0].cmd_addr = ATA_PRIMARY_CMD; 921 probe_ent->port[0].cmd_addr = ATA_PRIMARY_CMD;
919 probe_ent->port[0].altstatus_addr = 922 probe_ent->port[0].altstatus_addr =
920 probe_ent->port[0].ctl_addr = ATA_PRIMARY_CTL; 923 probe_ent->port[0].ctl_addr = ATA_PRIMARY_CTL;
921 if (bmdma) { 924 if (bmdma) {
922 probe_ent->port[0].bmdma_addr = bmdma; 925 probe_ent->port[0].bmdma_addr = bmdma;
923 if (inb(bmdma + 2) & 0x80) 926 if ((!(port[0]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
927 (inb(bmdma + 2) & 0x80))
924 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 928 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
925 } 929 }
926 ata_std_ports(&probe_ent->port[0]); 930 ata_std_ports(&probe_ent->port[0]);
@@ -929,15 +933,16 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
929 933
930 if (port_mask & ATA_PORT_SECONDARY) { 934 if (port_mask & ATA_PORT_SECONDARY) {
931 if (probe_ent->irq) 935 if (probe_ent->irq)
932 probe_ent->irq2 = ATA_SECONDARY_IRQ; 936 probe_ent->irq2 = ATA_SECONDARY_IRQ(pdev);
933 else 937 else
934 probe_ent->irq = ATA_SECONDARY_IRQ; 938 probe_ent->irq = ATA_SECONDARY_IRQ(pdev);
935 probe_ent->port[1].cmd_addr = ATA_SECONDARY_CMD; 939 probe_ent->port[1].cmd_addr = ATA_SECONDARY_CMD;
936 probe_ent->port[1].altstatus_addr = 940 probe_ent->port[1].altstatus_addr =
937 probe_ent->port[1].ctl_addr = ATA_SECONDARY_CTL; 941 probe_ent->port[1].ctl_addr = ATA_SECONDARY_CTL;
938 if (bmdma) { 942 if (bmdma) {
939 probe_ent->port[1].bmdma_addr = bmdma + 8; 943 probe_ent->port[1].bmdma_addr = bmdma + 8;
940 if (inb(bmdma + 10) & 0x80) 944 if ((!(port[1]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
945 (inb(bmdma + 10) & 0x80))
941 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 946 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
942 } 947 }
943 ata_std_ports(&probe_ent->port[1]); 948 ata_std_ports(&probe_ent->port[1]);
@@ -1027,13 +1032,15 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1027#endif 1032#endif
1028 } 1033 }
1029 1034
1030 rc = pci_request_regions(pdev, DRV_NAME); 1035 if (!legacy_mode) {
1031 if (rc) { 1036 rc = pci_request_regions(pdev, DRV_NAME);
1032 disable_dev_on_err = 0; 1037 if (rc) {
1033 goto err_out; 1038 disable_dev_on_err = 0;
1034 } 1039 goto err_out;
1035 1040 }
1036 if (legacy_mode) { 1041 } else {
1042 /* Deal with combined mode hack. This side of the logic all
1043 goes away once the combined mode hack is killed in 2.6.21 */
1037 if (!request_region(ATA_PRIMARY_CMD, 8, "libata")) { 1044 if (!request_region(ATA_PRIMARY_CMD, 8, "libata")) {
1038 struct resource *conflict, res; 1045 struct resource *conflict, res;
1039 res.start = ATA_PRIMARY_CMD; 1046 res.start = ATA_PRIMARY_CMD;
@@ -1071,6 +1078,13 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1071 } 1078 }
1072 } else 1079 } else
1073 legacy_mode |= ATA_PORT_SECONDARY; 1080 legacy_mode |= ATA_PORT_SECONDARY;
1081
1082 if (legacy_mode & ATA_PORT_PRIMARY)
1083 pci_request_region(pdev, 1, DRV_NAME);
1084 if (legacy_mode & ATA_PORT_SECONDARY)
1085 pci_request_region(pdev, 3, DRV_NAME);
1086 /* If there is a DMA resource, allocate it */
1087 pci_request_region(pdev, 4, DRV_NAME);
1074 } 1088 }
1075 1089
1076 /* we have legacy mode, but all ports are unavailable */ 1090 /* we have legacy mode, but all ports are unavailable */
@@ -1114,11 +1128,20 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1114err_out_ent: 1128err_out_ent:
1115 kfree(probe_ent); 1129 kfree(probe_ent);
1116err_out_regions: 1130err_out_regions:
1117 if (legacy_mode & ATA_PORT_PRIMARY) 1131 /* All this conditional stuff is needed for the combined mode hack
1118 release_region(ATA_PRIMARY_CMD, 8); 1132 until 2.6.21 when it can go */
1119 if (legacy_mode & ATA_PORT_SECONDARY) 1133 if (legacy_mode) {
1120 release_region(ATA_SECONDARY_CMD, 8); 1134 pci_release_region(pdev, 4);
1121 pci_release_regions(pdev); 1135 if (legacy_mode & ATA_PORT_PRIMARY) {
1136 release_region(ATA_PRIMARY_CMD, 8);
1137 pci_release_region(pdev, 1);
1138 }
1139 if (legacy_mode & ATA_PORT_SECONDARY) {
1140 release_region(ATA_SECONDARY_CMD, 8);
1141 pci_release_region(pdev, 3);
1142 }
1143 } else
1144 pci_release_regions(pdev);
1122err_out: 1145err_out:
1123 if (disable_dev_on_err) 1146 if (disable_dev_on_err)
1124 pci_disable_device(pdev); 1147 pci_disable_device(pdev);
diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
index 6f6672c551..504e1dbfff 100644
--- a/drivers/ata/pata_atiixp.c
+++ b/drivers/ata/pata_atiixp.c
@@ -36,15 +36,22 @@ enum {
36static int atiixp_pre_reset(struct ata_port *ap) 36static int atiixp_pre_reset(struct ata_port *ap)
37{ 37{
38 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 38 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
39 static struct pci_bits atiixp_enable_bits[] = { 39 static const struct pci_bits atiixp_enable_bits[] = {
40 { 0x48, 1, 0x01, 0x00 }, 40 { 0x48, 1, 0x01, 0x00 },
41 { 0x48, 1, 0x08, 0x00 } 41 { 0x48, 1, 0x08, 0x00 }
42 }; 42 };
43 u8 udma;
43 44
44 if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no])) 45 if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no]))
45 return -ENOENT; 46 return -ENOENT;
46 47
47 ap->cbl = ATA_CBL_PATA80; 48 /* Hack from drivers/ide/pci. Really we want to know how to do the
49 raw detection not play follow the bios mode guess */
50 pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ap->port_no, &udma);
51 if ((udma & 0x07) >= 0x04 || (udma & 0x70) >= 0x40)
52 ap->cbl = ATA_CBL_PATA80;
53 else
54 ap->cbl = ATA_CBL_PATA40;
48 return ata_std_prereset(ap); 55 return ata_std_prereset(ap);
49} 56}
50 57
diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index 15841a5636..449162cbf9 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -197,7 +197,7 @@ static void cmd64x_set_piomode(struct ata_port *ap, struct ata_device *adev)
197static void cmd64x_set_dmamode(struct ata_port *ap, struct ata_device *adev) 197static void cmd64x_set_dmamode(struct ata_port *ap, struct ata_device *adev)
198{ 198{
199 static const u8 udma_data[] = { 199 static const u8 udma_data[] = {
200 0x31, 0x21, 0x11, 0x25, 0x15, 0x05 200 0x30, 0x20, 0x10, 0x20, 0x10, 0x00
201 }; 201 };
202 static const u8 mwdma_data[] = { 202 static const u8 mwdma_data[] = {
203 0x30, 0x20, 0x10 203 0x30, 0x20, 0x10
@@ -213,12 +213,21 @@ static void cmd64x_set_dmamode(struct ata_port *ap, struct ata_device *adev)
213 pci_read_config_byte(pdev, pciD, &regD); 213 pci_read_config_byte(pdev, pciD, &regD);
214 pci_read_config_byte(pdev, pciU, &regU); 214 pci_read_config_byte(pdev, pciU, &regU);
215 215
216 regD &= ~(0x20 << shift); 216 /* DMA bits off */
217 regU &= ~(0x35 << shift); 217 regD &= ~(0x20 << adev->devno);
218 /* DMA control bits */
219 regU &= ~(0x30 << shift);
220 /* DMA timing bits */
221 regU &= ~(0x05 << adev->devno);
218 222
219 if (adev->dma_mode >= XFER_UDMA_0) 223 if (adev->dma_mode >= XFER_UDMA_0) {
224 /* Merge thge timing value */
220 regU |= udma_data[adev->dma_mode - XFER_UDMA_0] << shift; 225 regU |= udma_data[adev->dma_mode - XFER_UDMA_0] << shift;
221 else 226 /* Merge the control bits */
227 regU |= 1 << adev->devno; /* UDMA on */
228 if (adev->dma_mode > 2) /* 15nS timing */
229 regU |= 4 << adev->devno;
230 } else
222 regD |= mwdma_data[adev->dma_mode - XFER_MW_DMA_0] << shift; 231 regD |= mwdma_data[adev->dma_mode - XFER_MW_DMA_0] << shift;
223 232
224 regD |= 0x20 << adev->devno; 233 regD |= 0x20 << adev->devno;
@@ -239,8 +248,8 @@ static void cmd648_bmdma_stop(struct ata_queued_cmd *qc)
239 struct ata_port *ap = qc->ap; 248 struct ata_port *ap = qc->ap;
240 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 249 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
241 u8 dma_intr; 250 u8 dma_intr;
242 int dma_reg = ap->port_no ? ARTTIM23_INTR_CH1 : CFR_INTR_CH0; 251 int dma_mask = ap->port_no ? ARTTIM23_INTR_CH1 : CFR_INTR_CH0;
243 int dma_mask = ap->port_no ? ARTTIM2 : CFR; 252 int dma_reg = ap->port_no ? ARTTIM2 : CFR;
244 253
245 ata_bmdma_stop(qc); 254 ata_bmdma_stop(qc);
246 255
diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
index 1c628014da..b1ca207e35 100644
--- a/drivers/ata/pata_cs5530.c
+++ b/drivers/ata/pata_cs5530.c
@@ -372,7 +372,8 @@ static int cs5530_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
372static int cs5530_reinit_one(struct pci_dev *pdev) 372static int cs5530_reinit_one(struct pci_dev *pdev)
373{ 373{
374 /* If we fail on resume we are doomed */ 374 /* If we fail on resume we are doomed */
375 BUG_ON(cs5530_init_chip()); 375 if (cs5530_init_chip())
376 BUG();
376 return ata_pci_device_resume(pdev); 377 return ata_pci_device_resume(pdev);
377} 378}
378 379
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 47082df719..dfb306057c 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -25,7 +25,7 @@
25#include <linux/libata.h> 25#include <linux/libata.h>
26 26
27#define DRV_NAME "pata_hpt37x" 27#define DRV_NAME "pata_hpt37x"
28#define DRV_VERSION "0.5.1" 28#define DRV_VERSION "0.5.2"
29 29
30struct hpt_clock { 30struct hpt_clock {
31 u8 xfer_speed; 31 u8 xfer_speed;
@@ -416,7 +416,7 @@ static const char *bad_ata100_5[] = {
416 416
417static unsigned long hpt370_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 417static unsigned long hpt370_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask)
418{ 418{
419 if (adev->class != ATA_DEV_ATA) { 419 if (adev->class == ATA_DEV_ATA) {
420 if (hpt_dma_blacklisted(adev, "UDMA", bad_ata33)) 420 if (hpt_dma_blacklisted(adev, "UDMA", bad_ata33))
421 mask &= ~ATA_MASK_UDMA; 421 mask &= ~ATA_MASK_UDMA;
422 if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5)) 422 if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5))
@@ -749,7 +749,7 @@ static void hpt37x_bmdma_stop(struct ata_queued_cmd *qc)
749{ 749{
750 struct ata_port *ap = qc->ap; 750 struct ata_port *ap = qc->ap;
751 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 751 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
752 int mscreg = 0x50 + 2 * ap->port_no; 752 int mscreg = 0x50 + 4 * ap->port_no;
753 u8 bwsr_stat, msc_stat; 753 u8 bwsr_stat, msc_stat;
754 754
755 pci_read_config_byte(pdev, 0x6A, &bwsr_stat); 755 pci_read_config_byte(pdev, 0x6A, &bwsr_stat);
diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index f6817b4093..886fab9aa6 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -25,7 +25,7 @@
25#include <linux/libata.h> 25#include <linux/libata.h>
26 26
27#define DRV_NAME "pata_hpt3x2n" 27#define DRV_NAME "pata_hpt3x2n"
28#define DRV_VERSION "0.3" 28#define DRV_VERSION "0.3.2"
29 29
30enum { 30enum {
31 HPT_PCI_FAST = (1 << 31), 31 HPT_PCI_FAST = (1 << 31),
@@ -297,11 +297,11 @@ static int hpt3x2n_pair_idle(struct ata_port *ap)
297 return 0; 297 return 0;
298} 298}
299 299
300static int hpt3x2n_use_dpll(struct ata_port *ap, int reading) 300static int hpt3x2n_use_dpll(struct ata_port *ap, int writing)
301{ 301{
302 long flags = (long)ap->host->private_data; 302 long flags = (long)ap->host->private_data;
303 /* See if we should use the DPLL */ 303 /* See if we should use the DPLL */
304 if (reading == 0) 304 if (writing)
305 return USE_DPLL; /* Needed for write */ 305 return USE_DPLL; /* Needed for write */
306 if (flags & PCI66) 306 if (flags & PCI66)
307 return USE_DPLL; /* Needed at 66Mhz */ 307 return USE_DPLL; /* Needed at 66Mhz */
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index 0b56ff3d1c..e8afd48643 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -476,6 +476,7 @@ static unsigned int it821x_passthru_qc_issue_prot(struct ata_queued_cmd *qc)
476/** 476/**
477 * it821x_smart_set_mode - mode setting 477 * it821x_smart_set_mode - mode setting
478 * @ap: interface to set up 478 * @ap: interface to set up
479 * @unused: device that failed (error only)
479 * 480 *
480 * Use a non standard set_mode function. We don't want to be tuned. 481 * Use a non standard set_mode function. We don't want to be tuned.
481 * The BIOS configured everything. Our job is not to fiddle. We 482 * The BIOS configured everything. Our job is not to fiddle. We
@@ -483,7 +484,7 @@ static unsigned int it821x_passthru_qc_issue_prot(struct ata_queued_cmd *qc)
483 * and respect them. 484 * and respect them.
484 */ 485 */
485 486
486static void it821x_smart_set_mode(struct ata_port *ap) 487static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused)
487{ 488{
488 int dma_enabled = 0; 489 int dma_enabled = 0;
489 int i; 490 int i;
@@ -512,6 +513,7 @@ static void it821x_smart_set_mode(struct ata_port *ap)
512 } 513 }
513 } 514 }
514 } 515 }
516 return 0;
515} 517}
516 518
517/** 519/**
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index cb8924109f..23b8aab3eb 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -23,9 +23,9 @@
23#include <scsi/scsi_host.h> 23#include <scsi/scsi_host.h>
24 24
25#define DRV_NAME "pata_ixp4xx_cf" 25#define DRV_NAME "pata_ixp4xx_cf"
26#define DRV_VERSION "0.1.1" 26#define DRV_VERSION "0.1.1ac1"
27 27
28static void ixp4xx_set_mode(struct ata_port *ap) 28static int ixp4xx_set_mode(struct ata_port *ap, struct ata_device *adev)
29{ 29{
30 int i; 30 int i;
31 31
@@ -38,6 +38,7 @@ static void ixp4xx_set_mode(struct ata_port *ap)
38 dev->flags |= ATA_DFLAG_PIO; 38 dev->flags |= ATA_DFLAG_PIO;
39 } 39 }
40 } 40 }
41 return 0;
41} 42}
42 43
43static void ixp4xx_phy_reset(struct ata_port *ap) 44static void ixp4xx_phy_reset(struct ata_port *ap)
diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
index 2d661cb4df..d50264af28 100644
--- a/drivers/ata/pata_jmicron.c
+++ b/drivers/ata/pata_jmicron.c
@@ -204,20 +204,12 @@ static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *i
204 204
205 u32 reg; 205 u32 reg;
206 206
207 if (id->driver_data != 368) { 207 /* PATA controller is fn 1, AHCI is fn 0 */
208 /* Put the controller into AHCI mode in case the AHCI driver 208 if (id->driver_data != 368 && PCI_FUNC(pdev->devfn) != 1)
209 has not yet been loaded. This can be done with either 209 return -ENODEV;
210 function present */
211 210
212 /* FIXME: We may want a way to override this in future */ 211 /* The 365/66 have two PATA channels, redirect the second */
213 pci_write_config_byte(pdev, 0x41, 0xa1); 212 if (id->driver_data == 365 || id->driver_data == 366) {
214
215 /* PATA controller is fn 1, AHCI is fn 0 */
216 if (PCI_FUNC(pdev->devfn) != 1)
217 return -ENODEV;
218 }
219 if ( id->driver_data == 365 || id->driver_data == 366) {
220 /* The 365/66 have two PATA channels, redirect the second */
221 pci_read_config_dword(pdev, 0x80, &reg); 213 pci_read_config_dword(pdev, 0x80, &reg);
222 reg |= (1 << 24); /* IDE1 to PATA IDE secondary */ 214 reg |= (1 << 24); /* IDE1 to PATA IDE secondary */
223 pci_write_config_dword(pdev, 0x80, reg); 215 pci_write_config_dword(pdev, 0x80, reg);
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index c7d1738e4e..581cb33c6f 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -96,6 +96,7 @@ static int pio_mask = 0x1F; /* PIO range for autospeed devices */
96/** 96/**
97 * legacy_set_mode - mode setting 97 * legacy_set_mode - mode setting
98 * @ap: IDE interface 98 * @ap: IDE interface
99 * @unused: Device that failed when error is returned
99 * 100 *
100 * Use a non standard set_mode function. We don't want to be tuned. 101 * Use a non standard set_mode function. We don't want to be tuned.
101 * 102 *
@@ -105,7 +106,7 @@ static int pio_mask = 0x1F; /* PIO range for autospeed devices */
105 * expand on this as per hdparm in the base kernel. 106 * expand on this as per hdparm in the base kernel.
106 */ 107 */
107 108
108static void legacy_set_mode(struct ata_port *ap) 109static int legacy_set_mode(struct ata_port *ap, struct ata_device **unused)
109{ 110{
110 int i; 111 int i;
111 112
@@ -118,6 +119,7 @@ static void legacy_set_mode(struct ata_port *ap)
118 dev->flags |= ATA_DFLAG_PIO; 119 dev->flags |= ATA_DFLAG_PIO;
119 } 120 }
120 } 121 }
122 return 0;
121} 123}
122 124
123static struct scsi_host_template legacy_sht = { 125static struct scsi_host_template legacy_sht = {
@@ -698,8 +700,10 @@ static __init int legacy_init_one(int port, unsigned long io, unsigned long ctrl
698 goto fail_io; 700 goto fail_io;
699 701
700 pdev = platform_device_register_simple(DRV_NAME, nr_legacy_host, NULL, 0); 702 pdev = platform_device_register_simple(DRV_NAME, nr_legacy_host, NULL, 0);
701 if (pdev == NULL) 703 if (IS_ERR(pdev)) {
704 ret = PTR_ERR(pdev);
702 goto fail_dev; 705 goto fail_dev;
706 }
703 707
704 if (ht6560a & mask) { 708 if (ht6560a & mask) {
705 ops = &ht6560a_port_ops; 709 ops = &ht6560a_port_ops;
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 443b1d85c6..40ae11cbfd 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -30,7 +30,7 @@ static int pio_mask = 1;
30 * Provide our own set_mode() as we don't want to change anything that has 30 * Provide our own set_mode() as we don't want to change anything that has
31 * already been configured.. 31 * already been configured..
32 */ 32 */
33static void pata_platform_set_mode(struct ata_port *ap) 33static int pata_platform_set_mode(struct ata_port *ap, struct ata_device **unused)
34{ 34{
35 int i; 35 int i;
36 36
@@ -44,6 +44,7 @@ static void pata_platform_set_mode(struct ata_port *ap)
44 dev->flags |= ATA_DFLAG_PIO; 44 dev->flags |= ATA_DFLAG_PIO;
45 } 45 }
46 } 46 }
47 return 0;
47} 48}
48 49
49static void pata_platform_host_stop(struct ata_host *host) 50static void pata_platform_host_stop(struct ata_host *host)
diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
index 36f621abc3..afc0d990e7 100644
--- a/drivers/ata/pata_qdi.c
+++ b/drivers/ata/pata_qdi.c
@@ -247,8 +247,8 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
247 */ 247 */
248 248
249 pdev = platform_device_register_simple(DRV_NAME, nr_qdi_host, NULL, 0); 249 pdev = platform_device_register_simple(DRV_NAME, nr_qdi_host, NULL, 0);
250 if (pdev == NULL) 250 if (IS_ERR(pdev))
251 return -ENOMEM; 251 return PTR_ERR(pdev);
252 252
253 memset(&ae, 0, sizeof(struct ata_probe_ent)); 253 memset(&ae, 0, sizeof(struct ata_probe_ent));
254 INIT_LIST_HEAD(&ae.node); 254 INIT_LIST_HEAD(&ae.node);
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index 3677c642c9..cec0729225 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -52,19 +52,20 @@ static void rz1000_error_handler(struct ata_port *ap)
52/** 52/**
53 * rz1000_set_mode - mode setting function 53 * rz1000_set_mode - mode setting function
54 * @ap: ATA interface 54 * @ap: ATA interface
55 * @unused: returned device on set_mode failure
55 * 56 *
56 * Use a non standard set_mode function. We don't want to be tuned. We 57 * Use a non standard set_mode function. We don't want to be tuned. We
57 * would prefer to be BIOS generic but for the fact our hardware is 58 * would prefer to be BIOS generic but for the fact our hardware is
58 * whacked out. 59 * whacked out.
59 */ 60 */
60 61
61static void rz1000_set_mode(struct ata_port *ap) 62static int rz1000_set_mode(struct ata_port *ap, struct ata_device **unused)
62{ 63{
63 int i; 64 int i;
64 65
65 for (i = 0; i < ATA_MAX_DEVICES; i++) { 66 for (i = 0; i < ATA_MAX_DEVICES; i++) {
66 struct ata_device *dev = &ap->device[i]; 67 struct ata_device *dev = &ap->device[i];
67 if (ata_dev_enabled(dev)) { 68 if (ata_dev_ready(dev)) {
68 /* We don't really care */ 69 /* We don't really care */
69 dev->pio_mode = XFER_PIO_0; 70 dev->pio_mode = XFER_PIO_0;
70 dev->xfer_mode = XFER_PIO_0; 71 dev->xfer_mode = XFER_PIO_0;
@@ -72,6 +73,7 @@ static void rz1000_set_mode(struct ata_port *ap)
72 dev->flags |= ATA_DFLAG_PIO; 73 dev->flags |= ATA_DFLAG_PIO;
73 } 74 }
74 } 75 }
76 return 0;
75} 77}
76 78
77 79
@@ -105,8 +107,6 @@ static struct ata_port_operations rz1000_port_ops = {
105 .exec_command = ata_exec_command, 107 .exec_command = ata_exec_command,
106 .dev_select = ata_std_dev_select, 108 .dev_select = ata_std_dev_select,
107 109
108 .error_handler = rz1000_error_handler,
109
110 .bmdma_setup = ata_bmdma_setup, 110 .bmdma_setup = ata_bmdma_setup,
111 .bmdma_start = ata_bmdma_start, 111 .bmdma_start = ata_bmdma_start,
112 .bmdma_stop = ata_bmdma_stop, 112 .bmdma_stop = ata_bmdma_stop,
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index 32cf0bfa89..e8dfd8fc3f 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -135,7 +135,7 @@ static void sil680_error_handler(struct ata_port *ap)
135static void sil680_set_piomode(struct ata_port *ap, struct ata_device *adev) 135static void sil680_set_piomode(struct ata_port *ap, struct ata_device *adev)
136{ 136{
137 static u16 speed_p[5] = { 0x328A, 0x2283, 0x1104, 0x10C3, 0x10C1 }; 137 static u16 speed_p[5] = { 0x328A, 0x2283, 0x1104, 0x10C3, 0x10C1 };
138 static u16 speed_t[5] = { 0x328A, 0x1281, 0x1281, 0x10C3, 0x10C1 }; 138 static u16 speed_t[5] = { 0x328A, 0x2283, 0x1281, 0x10C3, 0x10C1 };
139 139
140 unsigned long tfaddr = sil680_selreg(ap, 0x02); 140 unsigned long tfaddr = sil680_selreg(ap, 0x02);
141 unsigned long addr = sil680_seldev(ap, adev, 0x04); 141 unsigned long addr = sil680_seldev(ap, adev, 0x04);
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index cc09d47fb9..f0b6c3b714 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -23,6 +23,7 @@
23 * VIA VT8233c - UDMA100 23 * VIA VT8233c - UDMA100
24 * VIA VT8235 - UDMA133 24 * VIA VT8235 - UDMA133
25 * VIA VT8237 - UDMA133 25 * VIA VT8237 - UDMA133
26 * VIA VT8237S - UDMA133
26 * VIA VT8251 - UDMA133 27 * VIA VT8251 - UDMA133
27 * 28 *
28 * Most registers remain compatible across chips. Others start reserved 29 * Most registers remain compatible across chips. Others start reserved
@@ -61,7 +62,7 @@
61#include <linux/libata.h> 62#include <linux/libata.h>
62 63
63#define DRV_NAME "pata_via" 64#define DRV_NAME "pata_via"
64#define DRV_VERSION "0.2.0" 65#define DRV_VERSION "0.2.1"
65 66
66/* 67/*
67 * The following comes directly from Vojtech Pavlik's ide/pci/via82cxxx 68 * The following comes directly from Vojtech Pavlik's ide/pci/via82cxxx
@@ -95,6 +96,7 @@ static const struct via_isa_bridge {
95 u8 rev_max; 96 u8 rev_max;
96 u16 flags; 97 u16 flags;
97} via_isa_bridges[] = { 98} via_isa_bridges[] = {
99 { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
98 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 100 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
99 { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 101 { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
100 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_NO_ENABLES}, 102 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_NO_ENABLES},
@@ -161,10 +163,15 @@ static int via_pre_reset(struct ata_port *ap)
161 return -ENOENT; 163 return -ENOENT;
162 } 164 }
163 165
164 if ((config->flags & VIA_UDMA) >= VIA_UDMA_66) 166 if ((config->flags & VIA_UDMA) >= VIA_UDMA_100)
165 ap->cbl = via_cable_detect(ap); 167 ap->cbl = via_cable_detect(ap);
166 else 168 /* The UDMA66 series has no cable detect so do drive side detect */
169 else if ((config->flags & VIA_UDMA) < VIA_UDMA_66)
167 ap->cbl = ATA_CBL_PATA40; 170 ap->cbl = ATA_CBL_PATA40;
171 else
172 ap->cbl = ATA_CBL_PATA_UNK;
173
174
168 return ata_std_prereset(ap); 175 return ata_std_prereset(ap);
169} 176}
170 177
@@ -390,7 +397,7 @@ static void via_config_fifo(struct pci_dev *pdev, unsigned int flags)
390 enable &= 3; 397 enable &= 3;
391 398
392 if (flags & VIA_SET_FIFO) { 399 if (flags & VIA_SET_FIFO) {
393 u8 fifo_setting[4] = {0x00, 0x60, 0x00, 0x20}; 400 static const u8 fifo_setting[4] = {0x00, 0x60, 0x00, 0x20};
394 u8 fifo; 401 u8 fifo;
395 402
396 pci_read_config_byte(pdev, 0x43, &fifo); 403 pci_read_config_byte(pdev, 0x43, &fifo);
diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
index 3ea345cde5..5d1f518e1c 100644
--- a/drivers/ata/pata_winbond.c
+++ b/drivers/ata/pata_winbond.c
@@ -206,8 +206,8 @@ static __init int winbond_init_one(unsigned long port)
206 */ 206 */
207 207
208 pdev = platform_device_register_simple(DRV_NAME, nr_winbond_host, NULL, 0); 208 pdev = platform_device_register_simple(DRV_NAME, nr_winbond_host, NULL, 0);
209 if (pdev == NULL) 209 if (IS_ERR(pdev))
210 return -ENOMEM; 210 return PTR_ERR(pdev);
211 211
212 memset(&ae, 0, sizeof(struct ata_probe_ent)); 212 memset(&ae, 0, sizeof(struct ata_probe_ent));
213 INIT_LIST_HEAD(&ae.node); 213 INIT_LIST_HEAD(&ae.node);
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index 1b8e0eb9e0..aae0b5201c 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -523,8 +523,7 @@ static const struct ata_port_info mv_port_info[] = {
523 }, 523 },
524 { /* chip_7042 */ 524 { /* chip_7042 */
525 .sht = &mv_sht, 525 .sht = &mv_sht,
526 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS | 526 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
527 MV_FLAG_DUAL_HC),
528 .pio_mask = 0x1f, /* pio0-4 */ 527 .pio_mask = 0x1f, /* pio0-4 */
529 .udma_mask = 0x7f, /* udma0-6 */ 528 .udma_mask = 0x7f, /* udma0-6 */
530 .port_ops = &mv_iie_ops, 529 .port_ops = &mv_iie_ops,
@@ -545,6 +544,8 @@ static const struct pci_device_id mv_pci_tbl[] = {
545 544
546 { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x }, 545 { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x },
547 546
547 { PCI_VDEVICE(TTI, 0x2310), chip_7042 },
548
548 { } /* terminate list */ 549 { } /* terminate list */
549}; 550};
550 551
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 0d316eb3c2..f7a963eb1f 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -270,14 +270,6 @@ static const struct pci_device_id nv_pci_tbl[] = {
270 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA), GENERIC }, 270 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA), GENERIC },
271 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2), GENERIC }, 271 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2), GENERIC },
272 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3), GENERIC }, 272 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3), GENERIC },
273 { PCI_VDEVICE(NVIDIA, 0x045c), GENERIC }, /* MCP65 */
274 { PCI_VDEVICE(NVIDIA, 0x045d), GENERIC }, /* MCP65 */
275 { PCI_VDEVICE(NVIDIA, 0x045e), GENERIC }, /* MCP65 */
276 { PCI_VDEVICE(NVIDIA, 0x045f), GENERIC }, /* MCP65 */
277 { PCI_VDEVICE(NVIDIA, 0x0550), GENERIC }, /* MCP67 */
278 { PCI_VDEVICE(NVIDIA, 0x0551), GENERIC }, /* MCP67 */
279 { PCI_VDEVICE(NVIDIA, 0x0552), GENERIC }, /* MCP67 */
280 { PCI_VDEVICE(NVIDIA, 0x0553), GENERIC }, /* MCP67 */
281 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, 273 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
282 PCI_ANY_ID, PCI_ANY_ID, 274 PCI_ANY_ID, PCI_ANY_ID,
283 PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC }, 275 PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC },
@@ -708,7 +700,6 @@ static void nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err)
708static int nv_host_intr(struct ata_port *ap, u8 irq_stat) 700static int nv_host_intr(struct ata_port *ap, u8 irq_stat)
709{ 701{
710 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag); 702 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
711 int handled;
712 703
713 /* freeze if hotplugged */ 704 /* freeze if hotplugged */
714 if (unlikely(irq_stat & (NV_INT_ADDED | NV_INT_REMOVED))) { 705 if (unlikely(irq_stat & (NV_INT_ADDED | NV_INT_REMOVED))) {
@@ -727,13 +718,7 @@ static int nv_host_intr(struct ata_port *ap, u8 irq_stat)
727 } 718 }
728 719
729 /* handle interrupt */ 720 /* handle interrupt */
730 handled = ata_host_intr(ap, qc); 721 return ata_host_intr(ap, qc);
731 if (unlikely(!handled)) {
732 /* spurious, clear it */
733 ata_check_status(ap);
734 }
735
736 return 1;
737} 722}
738 723
739static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance) 724static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
@@ -760,6 +745,11 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
760 if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) { 745 if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) {
761 u8 irq_stat = readb(host->mmio_base + NV_INT_STATUS_CK804) 746 u8 irq_stat = readb(host->mmio_base + NV_INT_STATUS_CK804)
762 >> (NV_INT_PORT_SHIFT * i); 747 >> (NV_INT_PORT_SHIFT * i);
748 if(ata_tag_valid(ap->active_tag))
749 /** NV_INT_DEV indication seems unreliable at times
750 at least in ADMA mode. Force it on always when a
751 command is active, to prevent losing interrupts. */
752 irq_stat |= NV_INT_DEV;
763 handled += nv_host_intr(ap, irq_stat); 753 handled += nv_host_intr(ap, irq_stat);
764 continue; 754 continue;
765 } 755 }
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
index db32d15b7f..46d8a94669 100644
--- a/drivers/ata/sata_svw.c
+++ b/drivers/ata/sata_svw.c
@@ -56,6 +56,8 @@
56#define DRV_VERSION "2.0" 56#define DRV_VERSION "2.0"
57 57
58enum { 58enum {
59 K2_FLAG_NO_ATAPI_DMA = (1 << 29),
60
59 /* Taskfile registers offsets */ 61 /* Taskfile registers offsets */
60 K2_SATA_TF_CMD_OFFSET = 0x00, 62 K2_SATA_TF_CMD_OFFSET = 0x00,
61 K2_SATA_TF_DATA_OFFSET = 0x00, 63 K2_SATA_TF_DATA_OFFSET = 0x00,
@@ -83,11 +85,33 @@ enum {
83 85
84 /* Port stride */ 86 /* Port stride */
85 K2_SATA_PORT_OFFSET = 0x100, 87 K2_SATA_PORT_OFFSET = 0x100,
88
89 board_svw4 = 0,
90 board_svw8 = 1,
91};
92
93static const struct k2_board_info {
94 unsigned int n_ports;
95 unsigned long port_flags;
96} k2_board_info[] = {
97 /* board_svw4 */
98 { 4, K2_FLAG_NO_ATAPI_DMA },
99
100 /* board_svw8 */
101 { 8, K2_FLAG_NO_ATAPI_DMA },
86}; 102};
87 103
88static u8 k2_stat_check_status(struct ata_port *ap); 104static u8 k2_stat_check_status(struct ata_port *ap);
89 105
90 106
107static int k2_sata_check_atapi_dma(struct ata_queued_cmd *qc)
108{
109 if (qc->ap->flags & K2_FLAG_NO_ATAPI_DMA)
110 return -1; /* ATAPI DMA not supported */
111
112 return 0;
113}
114
91static u32 k2_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 115static u32 k2_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
92{ 116{
93 if (sc_reg > SCR_CONTROL) 117 if (sc_reg > SCR_CONTROL)
@@ -111,26 +135,31 @@ static void k2_sata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
111 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; 135 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
112 136
113 if (tf->ctl != ap->last_ctl) { 137 if (tf->ctl != ap->last_ctl) {
114 writeb(tf->ctl, ioaddr->ctl_addr); 138 writeb(tf->ctl, (void __iomem *) ioaddr->ctl_addr);
115 ap->last_ctl = tf->ctl; 139 ap->last_ctl = tf->ctl;
116 ata_wait_idle(ap); 140 ata_wait_idle(ap);
117 } 141 }
118 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { 142 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
119 writew(tf->feature | (((u16)tf->hob_feature) << 8), ioaddr->feature_addr); 143 writew(tf->feature | (((u16)tf->hob_feature) << 8),
120 writew(tf->nsect | (((u16)tf->hob_nsect) << 8), ioaddr->nsect_addr); 144 (void __iomem *) ioaddr->feature_addr);
121 writew(tf->lbal | (((u16)tf->hob_lbal) << 8), ioaddr->lbal_addr); 145 writew(tf->nsect | (((u16)tf->hob_nsect) << 8),
122 writew(tf->lbam | (((u16)tf->hob_lbam) << 8), ioaddr->lbam_addr); 146 (void __iomem *) ioaddr->nsect_addr);
123 writew(tf->lbah | (((u16)tf->hob_lbah) << 8), ioaddr->lbah_addr); 147 writew(tf->lbal | (((u16)tf->hob_lbal) << 8),
148 (void __iomem *) ioaddr->lbal_addr);
149 writew(tf->lbam | (((u16)tf->hob_lbam) << 8),
150 (void __iomem *) ioaddr->lbam_addr);
151 writew(tf->lbah | (((u16)tf->hob_lbah) << 8),
152 (void __iomem *) ioaddr->lbah_addr);
124 } else if (is_addr) { 153 } else if (is_addr) {
125 writew(tf->feature, ioaddr->feature_addr); 154 writew(tf->feature, (void __iomem *) ioaddr->feature_addr);
126 writew(tf->nsect, ioaddr->nsect_addr); 155 writew(tf->nsect, (void __iomem *) ioaddr->nsect_addr);
127 writew(tf->lbal, ioaddr->lbal_addr); 156 writew(tf->lbal, (void __iomem *) ioaddr->lbal_addr);
128 writew(tf->lbam, ioaddr->lbam_addr); 157 writew(tf->lbam, (void __iomem *) ioaddr->lbam_addr);
129 writew(tf->lbah, ioaddr->lbah_addr); 158 writew(tf->lbah, (void __iomem *) ioaddr->lbah_addr);
130 } 159 }
131 160
132 if (tf->flags & ATA_TFLAG_DEVICE) 161 if (tf->flags & ATA_TFLAG_DEVICE)
133 writeb(tf->device, ioaddr->device_addr); 162 writeb(tf->device, (void __iomem *) ioaddr->device_addr);
134 163
135 ata_wait_idle(ap); 164 ata_wait_idle(ap);
136} 165}
@@ -142,12 +171,12 @@ static void k2_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
142 u16 nsect, lbal, lbam, lbah, feature; 171 u16 nsect, lbal, lbam, lbah, feature;
143 172
144 tf->command = k2_stat_check_status(ap); 173 tf->command = k2_stat_check_status(ap);
145 tf->device = readw(ioaddr->device_addr); 174 tf->device = readw((void __iomem *)ioaddr->device_addr);
146 feature = readw(ioaddr->error_addr); 175 feature = readw((void __iomem *)ioaddr->error_addr);
147 nsect = readw(ioaddr->nsect_addr); 176 nsect = readw((void __iomem *)ioaddr->nsect_addr);
148 lbal = readw(ioaddr->lbal_addr); 177 lbal = readw((void __iomem *)ioaddr->lbal_addr);
149 lbam = readw(ioaddr->lbam_addr); 178 lbam = readw((void __iomem *)ioaddr->lbam_addr);
150 lbah = readw(ioaddr->lbah_addr); 179 lbah = readw((void __iomem *)ioaddr->lbah_addr);
151 180
152 tf->feature = feature; 181 tf->feature = feature;
153 tf->nsect = nsect; 182 tf->nsect = nsect;
@@ -313,6 +342,7 @@ static const struct ata_port_operations k2_sata_ops = {
313 .check_status = k2_stat_check_status, 342 .check_status = k2_stat_check_status,
314 .exec_command = ata_exec_command, 343 .exec_command = ata_exec_command,
315 .dev_select = ata_std_dev_select, 344 .dev_select = ata_std_dev_select,
345 .check_atapi_dma = k2_sata_check_atapi_dma,
316 .bmdma_setup = k2_bmdma_setup_mmio, 346 .bmdma_setup = k2_bmdma_setup_mmio,
317 .bmdma_start = k2_bmdma_start_mmio, 347 .bmdma_start = k2_bmdma_start_mmio,
318 .bmdma_stop = ata_bmdma_stop, 348 .bmdma_stop = ata_bmdma_stop,
@@ -359,6 +389,8 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
359 struct ata_probe_ent *probe_ent = NULL; 389 struct ata_probe_ent *probe_ent = NULL;
360 unsigned long base; 390 unsigned long base;
361 void __iomem *mmio_base; 391 void __iomem *mmio_base;
392 const struct k2_board_info *board_info =
393 &k2_board_info[ent->driver_data];
362 int pci_dev_busy = 0; 394 int pci_dev_busy = 0;
363 int rc; 395 int rc;
364 int i; 396 int i;
@@ -424,7 +456,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
424 456
425 probe_ent->sht = &k2_sata_sht; 457 probe_ent->sht = &k2_sata_sht;
426 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 458 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
427 ATA_FLAG_MMIO; 459 ATA_FLAG_MMIO | board_info->port_flags;
428 probe_ent->port_ops = &k2_sata_ops; 460 probe_ent->port_ops = &k2_sata_ops;
429 probe_ent->n_ports = 4; 461 probe_ent->n_ports = 4;
430 probe_ent->irq = pdev->irq; 462 probe_ent->irq = pdev->irq;
@@ -441,7 +473,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
441 /* different controllers have different number of ports - currently 4 or 8 */ 473 /* different controllers have different number of ports - currently 4 or 8 */
442 /* All ports are on the same function. Multi-function device is no 474 /* All ports are on the same function. Multi-function device is no
443 * longer available. This should not be seen in any system. */ 475 * longer available. This should not be seen in any system. */
444 for (i = 0; i < ent->driver_data; i++) 476 for (i = 0; i < board_info->n_ports; i++)
445 k2_sata_setup_port(&probe_ent->port[i], base + i * K2_SATA_PORT_OFFSET); 477 k2_sata_setup_port(&probe_ent->port[i], base + i * K2_SATA_PORT_OFFSET);
446 478
447 pci_set_master(pdev); 479 pci_set_master(pdev);
@@ -469,11 +501,11 @@ err_out:
469 * controller 501 * controller
470 * */ 502 * */
471static const struct pci_device_id k2_sata_pci_tbl[] = { 503static const struct pci_device_id k2_sata_pci_tbl[] = {
472 { PCI_VDEVICE(SERVERWORKS, 0x0240), 4 }, 504 { PCI_VDEVICE(SERVERWORKS, 0x0240), board_svw4 },
473 { PCI_VDEVICE(SERVERWORKS, 0x0241), 4 }, 505 { PCI_VDEVICE(SERVERWORKS, 0x0241), board_svw4 },
474 { PCI_VDEVICE(SERVERWORKS, 0x0242), 8 }, 506 { PCI_VDEVICE(SERVERWORKS, 0x0242), board_svw8 },
475 { PCI_VDEVICE(SERVERWORKS, 0x024a), 4 }, 507 { PCI_VDEVICE(SERVERWORKS, 0x024a), board_svw4 },
476 { PCI_VDEVICE(SERVERWORKS, 0x024b), 4 }, 508 { PCI_VDEVICE(SERVERWORKS, 0x024b), board_svw4 },
477 509
478 { } 510 { }
479}; 511};
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index 5c603ca3a5..a43aec62d5 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -128,7 +128,8 @@ static const struct ata_port_operations uli_ops = {
128 128
129static struct ata_port_info uli_port_info = { 129static struct ata_port_info uli_port_info = {
130 .sht = &uli_sht, 130 .sht = &uli_sht,
131 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, 131 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
132 ATA_FLAG_IGN_SIMPLEX,
132 .pio_mask = 0x1f, /* pio0-4 */ 133 .pio_mask = 0x1f, /* pio0-4 */
133 .udma_mask = 0x7f, /* udma0-6 */ 134 .udma_mask = 0x7f, /* udma0-6 */
134 .port_ops = &uli_ops, 135 .port_ops = &uli_ops,
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index 1c7f19aecc..d3d5c0d570 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -74,9 +74,11 @@ enum {
74static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 74static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
75static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg); 75static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg);
76static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 76static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
77static void svia_noop_freeze(struct ata_port *ap);
77static void vt6420_error_handler(struct ata_port *ap); 78static void vt6420_error_handler(struct ata_port *ap);
78 79
79static const struct pci_device_id svia_pci_tbl[] = { 80static const struct pci_device_id svia_pci_tbl[] = {
81 { PCI_VDEVICE(VIA, 0x5337), vt6420 },
80 { PCI_VDEVICE(VIA, 0x0591), vt6420 }, 82 { PCI_VDEVICE(VIA, 0x0591), vt6420 },
81 { PCI_VDEVICE(VIA, 0x3149), vt6420 }, 83 { PCI_VDEVICE(VIA, 0x3149), vt6420 },
82 { PCI_VDEVICE(VIA, 0x3249), vt6421 }, 84 { PCI_VDEVICE(VIA, 0x3249), vt6421 },
@@ -127,7 +129,7 @@ static const struct ata_port_operations vt6420_sata_ops = {
127 .qc_issue = ata_qc_issue_prot, 129 .qc_issue = ata_qc_issue_prot,
128 .data_xfer = ata_pio_data_xfer, 130 .data_xfer = ata_pio_data_xfer,
129 131
130 .freeze = ata_bmdma_freeze, 132 .freeze = svia_noop_freeze,
131 .thaw = ata_bmdma_thaw, 133 .thaw = ata_bmdma_thaw,
132 .error_handler = vt6420_error_handler, 134 .error_handler = vt6420_error_handler,
133 .post_internal_cmd = ata_bmdma_post_internal_cmd, 135 .post_internal_cmd = ata_bmdma_post_internal_cmd,
@@ -203,6 +205,15 @@ static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
203 outl(val, ap->ioaddr.scr_addr + (4 * sc_reg)); 205 outl(val, ap->ioaddr.scr_addr + (4 * sc_reg));
204} 206}
205 207
208static void svia_noop_freeze(struct ata_port *ap)
209{
210 /* Some VIA controllers choke if ATA_NIEN is manipulated in
211 * certain way. Leave it alone and just clear pending IRQ.
212 */
213 ata_chk_status(ap);
214 ata_bmdma_irq_clear(ap);
215}
216
206/** 217/**
207 * vt6420_prereset - prereset for vt6420 218 * vt6420_prereset - prereset for vt6420
208 * @ap: target ATA port 219 * @ap: target ATA port
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index e654b990b9..0fa1b89f76 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -149,21 +149,26 @@ static void vsc_sata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
149 vsc_intr_mask_update(ap, tf->ctl & ATA_NIEN); 149 vsc_intr_mask_update(ap, tf->ctl & ATA_NIEN);
150 } 150 }
151 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { 151 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
152 writew(tf->feature | (((u16)tf->hob_feature) << 8), ioaddr->feature_addr); 152 writew(tf->feature | (((u16)tf->hob_feature) << 8),
153 writew(tf->nsect | (((u16)tf->hob_nsect) << 8), ioaddr->nsect_addr); 153 (void __iomem *) ioaddr->feature_addr);
154 writew(tf->lbal | (((u16)tf->hob_lbal) << 8), ioaddr->lbal_addr); 154 writew(tf->nsect | (((u16)tf->hob_nsect) << 8),
155 writew(tf->lbam | (((u16)tf->hob_lbam) << 8), ioaddr->lbam_addr); 155 (void __iomem *) ioaddr->nsect_addr);
156 writew(tf->lbah | (((u16)tf->hob_lbah) << 8), ioaddr->lbah_addr); 156 writew(tf->lbal | (((u16)tf->hob_lbal) << 8),
157 (void __iomem *) ioaddr->lbal_addr);
158 writew(tf->lbam | (((u16)tf->hob_lbam) << 8),
159 (void __iomem *) ioaddr->lbam_addr);
160 writew(tf->lbah | (((u16)tf->hob_lbah) << 8),
161 (void __iomem *) ioaddr->lbah_addr);
157 } else if (is_addr) { 162 } else if (is_addr) {
158 writew(tf->feature, ioaddr->feature_addr); 163 writew(tf->feature, (void __iomem *) ioaddr->feature_addr);
159 writew(tf->nsect, ioaddr->nsect_addr); 164 writew(tf->nsect, (void __iomem *) ioaddr->nsect_addr);
160 writew(tf->lbal, ioaddr->lbal_addr); 165 writew(tf->lbal, (void __iomem *) ioaddr->lbal_addr);
161 writew(tf->lbam, ioaddr->lbam_addr); 166 writew(tf->lbam, (void __iomem *) ioaddr->lbam_addr);
162 writew(tf->lbah, ioaddr->lbah_addr); 167 writew(tf->lbah, (void __iomem *) ioaddr->lbah_addr);
163 } 168 }
164 169
165 if (tf->flags & ATA_TFLAG_DEVICE) 170 if (tf->flags & ATA_TFLAG_DEVICE)
166 writeb(tf->device, ioaddr->device_addr); 171 writeb(tf->device, (void __iomem *) ioaddr->device_addr);
167 172
168 ata_wait_idle(ap); 173 ata_wait_idle(ap);
169} 174}
@@ -175,12 +180,12 @@ static void vsc_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
175 u16 nsect, lbal, lbam, lbah, feature; 180 u16 nsect, lbal, lbam, lbah, feature;
176 181
177 tf->command = ata_check_status(ap); 182 tf->command = ata_check_status(ap);
178 tf->device = readw(ioaddr->device_addr); 183 tf->device = readw((void __iomem *) ioaddr->device_addr);
179 feature = readw(ioaddr->error_addr); 184 feature = readw((void __iomem *) ioaddr->error_addr);
180 nsect = readw(ioaddr->nsect_addr); 185 nsect = readw((void __iomem *) ioaddr->nsect_addr);
181 lbal = readw(ioaddr->lbal_addr); 186 lbal = readw((void __iomem *) ioaddr->lbal_addr);
182 lbam = readw(ioaddr->lbam_addr); 187 lbam = readw((void __iomem *) ioaddr->lbam_addr);
183 lbah = readw(ioaddr->lbah_addr); 188 lbah = readw((void __iomem *) ioaddr->lbah_addr);
184 189
185 tf->feature = feature; 190 tf->feature = feature;
186 tf->nsect = nsect; 191 tf->nsect = nsect;
@@ -327,8 +332,8 @@ static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned lon
327 port->ctl_addr = base + VSC_SATA_TF_CTL_OFFSET; 332 port->ctl_addr = base + VSC_SATA_TF_CTL_OFFSET;
328 port->bmdma_addr = base + VSC_SATA_DMA_CMD_OFFSET; 333 port->bmdma_addr = base + VSC_SATA_DMA_CMD_OFFSET;
329 port->scr_addr = base + VSC_SATA_SCR_STATUS_OFFSET; 334 port->scr_addr = base + VSC_SATA_SCR_STATUS_OFFSET;
330 writel(0, base + VSC_SATA_UP_DESCRIPTOR_OFFSET); 335 writel(0, (void __iomem *) base + VSC_SATA_UP_DESCRIPTOR_OFFSET);
331 writel(0, base + VSC_SATA_UP_DATA_BUFFER_OFFSET); 336 writel(0, (void __iomem *) base + VSC_SATA_UP_DATA_BUFFER_OFFSET);
332} 337}
333 338
334 339
diff --git a/drivers/atm/Kconfig b/drivers/atm/Kconfig
index 2ddd76fdbc..33687454eb 100644
--- a/drivers/atm/Kconfig
+++ b/drivers/atm/Kconfig
@@ -167,10 +167,6 @@ config ATM_ZATM_DEBUG
167 Note that extended debugging may create certain race conditions 167 Note that extended debugging may create certain race conditions
168 itself. Enable this ONLY if you suspect problems with the driver. 168 itself. Enable this ONLY if you suspect problems with the driver.
169 169
170# bool 'Rolfs TI TNETA1570' CONFIG_ATM_TNETA1570 y
171# if [ "$CONFIG_ATM_TNETA1570" = "y" ]; then
172# bool ' Enable extended debugging' CONFIG_ATM_TNETA1570_DEBUG n
173# fi
174config ATM_NICSTAR 170config ATM_NICSTAR
175 tristate "IDT 77201 (NICStAR) (ForeRunnerLE)" 171 tristate "IDT 77201 (NICStAR) (ForeRunnerLE)"
176 depends on PCI && ATM && !64BIT 172 depends on PCI && ATM && !64BIT
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index 3a7b21ff30..4aeb3d062f 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -172,25 +172,6 @@ fore200e_irq_itoa(int irq)
172} 172}
173 173
174 174
175static void*
176fore200e_kmalloc(int size, gfp_t flags)
177{
178 void *chunk = kzalloc(size, flags);
179
180 if (!chunk)
181 printk(FORE200E "kmalloc() failed, requested size = %d, flags = 0x%x\n", size, flags);
182
183 return chunk;
184}
185
186
187static void
188fore200e_kfree(void* chunk)
189{
190 kfree(chunk);
191}
192
193
194/* allocate and align a chunk of memory intended to hold the data behing exchanged 175/* allocate and align a chunk of memory intended to hold the data behing exchanged
195 between the driver and the adapter (using streaming DVMA) */ 176 between the driver and the adapter (using streaming DVMA) */
196 177
@@ -206,7 +187,7 @@ fore200e_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk, int size, i
206 chunk->align_size = size; 187 chunk->align_size = size;
207 chunk->direction = direction; 188 chunk->direction = direction;
208 189
209 chunk->alloc_addr = fore200e_kmalloc(chunk->alloc_size, GFP_KERNEL | GFP_DMA); 190 chunk->alloc_addr = kzalloc(chunk->alloc_size, GFP_KERNEL | GFP_DMA);
210 if (chunk->alloc_addr == NULL) 191 if (chunk->alloc_addr == NULL)
211 return -ENOMEM; 192 return -ENOMEM;
212 193
@@ -228,7 +209,7 @@ fore200e_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
228{ 209{
229 fore200e->bus->dma_unmap(fore200e, chunk->dma_addr, chunk->dma_size, chunk->direction); 210 fore200e->bus->dma_unmap(fore200e, chunk->dma_addr, chunk->dma_size, chunk->direction);
230 211
231 fore200e_kfree(chunk->alloc_addr); 212 kfree(chunk->alloc_addr);
232} 213}
233 214
234 215
@@ -882,7 +863,7 @@ fore200e_sba_detect(const struct fore200e_bus* bus, int index)
882 return NULL; 863 return NULL;
883 } 864 }
884 865
885 fore200e = fore200e_kmalloc(sizeof(struct fore200e), GFP_KERNEL); 866 fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
886 if (fore200e == NULL) 867 if (fore200e == NULL)
887 return NULL; 868 return NULL;
888 869
@@ -1505,7 +1486,7 @@ fore200e_open(struct atm_vcc *vcc)
1505 1486
1506 spin_unlock_irqrestore(&fore200e->q_lock, flags); 1487 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1507 1488
1508 fore200e_vcc = fore200e_kmalloc(sizeof(struct fore200e_vcc), GFP_ATOMIC); 1489 fore200e_vcc = kzalloc(sizeof(struct fore200e_vcc), GFP_ATOMIC);
1509 if (fore200e_vcc == NULL) { 1490 if (fore200e_vcc == NULL) {
1510 vc_map->vcc = NULL; 1491 vc_map->vcc = NULL;
1511 return -ENOMEM; 1492 return -ENOMEM;
@@ -1526,7 +1507,7 @@ fore200e_open(struct atm_vcc *vcc)
1526 if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) { 1507 if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) {
1527 up(&fore200e->rate_sf); 1508 up(&fore200e->rate_sf);
1528 1509
1529 fore200e_kfree(fore200e_vcc); 1510 kfree(fore200e_vcc);
1530 vc_map->vcc = NULL; 1511 vc_map->vcc = NULL;
1531 return -EAGAIN; 1512 return -EAGAIN;
1532 } 1513 }
@@ -1554,7 +1535,7 @@ fore200e_open(struct atm_vcc *vcc)
1554 1535
1555 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr; 1536 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1556 1537
1557 fore200e_kfree(fore200e_vcc); 1538 kfree(fore200e_vcc);
1558 return -EINVAL; 1539 return -EINVAL;
1559 } 1540 }
1560 1541
@@ -1630,7 +1611,7 @@ fore200e_close(struct atm_vcc* vcc)
1630 clear_bit(ATM_VF_PARTIAL,&vcc->flags); 1611 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
1631 1612
1632 ASSERT(fore200e_vcc); 1613 ASSERT(fore200e_vcc);
1633 fore200e_kfree(fore200e_vcc); 1614 kfree(fore200e_vcc);
1634} 1615}
1635 1616
1636 1617
@@ -1831,7 +1812,7 @@ fore200e_getstats(struct fore200e* fore200e)
1831 u32 stats_dma_addr; 1812 u32 stats_dma_addr;
1832 1813
1833 if (fore200e->stats == NULL) { 1814 if (fore200e->stats == NULL) {
1834 fore200e->stats = fore200e_kmalloc(sizeof(struct stats), GFP_KERNEL | GFP_DMA); 1815 fore200e->stats = kzalloc(sizeof(struct stats), GFP_KERNEL | GFP_DMA);
1835 if (fore200e->stats == NULL) 1816 if (fore200e->stats == NULL)
1836 return -ENOMEM; 1817 return -ENOMEM;
1837 } 1818 }
@@ -2002,17 +1983,6 @@ fore200e_setloop(struct fore200e* fore200e, int loop_mode)
2002} 1983}
2003 1984
2004 1985
2005static inline unsigned int
2006fore200e_swap(unsigned int in)
2007{
2008#if defined(__LITTLE_ENDIAN)
2009 return swab32(in);
2010#else
2011 return in;
2012#endif
2013}
2014
2015
2016static int 1986static int
2017fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg) 1987fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg)
2018{ 1988{
@@ -2021,19 +1991,19 @@ fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg)
2021 if (fore200e_getstats(fore200e) < 0) 1991 if (fore200e_getstats(fore200e) < 0)
2022 return -EIO; 1992 return -EIO;
2023 1993
2024 tmp.section_bip = fore200e_swap(fore200e->stats->oc3.section_bip8_errors); 1994 tmp.section_bip = cpu_to_be32(fore200e->stats->oc3.section_bip8_errors);
2025 tmp.line_bip = fore200e_swap(fore200e->stats->oc3.line_bip24_errors); 1995 tmp.line_bip = cpu_to_be32(fore200e->stats->oc3.line_bip24_errors);
2026 tmp.path_bip = fore200e_swap(fore200e->stats->oc3.path_bip8_errors); 1996 tmp.path_bip = cpu_to_be32(fore200e->stats->oc3.path_bip8_errors);
2027 tmp.line_febe = fore200e_swap(fore200e->stats->oc3.line_febe_errors); 1997 tmp.line_febe = cpu_to_be32(fore200e->stats->oc3.line_febe_errors);
2028 tmp.path_febe = fore200e_swap(fore200e->stats->oc3.path_febe_errors); 1998 tmp.path_febe = cpu_to_be32(fore200e->stats->oc3.path_febe_errors);
2029 tmp.corr_hcs = fore200e_swap(fore200e->stats->oc3.corr_hcs_errors); 1999 tmp.corr_hcs = cpu_to_be32(fore200e->stats->oc3.corr_hcs_errors);
2030 tmp.uncorr_hcs = fore200e_swap(fore200e->stats->oc3.ucorr_hcs_errors); 2000 tmp.uncorr_hcs = cpu_to_be32(fore200e->stats->oc3.ucorr_hcs_errors);
2031 tmp.tx_cells = fore200e_swap(fore200e->stats->aal0.cells_transmitted) + 2001 tmp.tx_cells = cpu_to_be32(fore200e->stats->aal0.cells_transmitted) +
2032 fore200e_swap(fore200e->stats->aal34.cells_transmitted) + 2002 cpu_to_be32(fore200e->stats->aal34.cells_transmitted) +
2033 fore200e_swap(fore200e->stats->aal5.cells_transmitted); 2003 cpu_to_be32(fore200e->stats->aal5.cells_transmitted);
2034 tmp.rx_cells = fore200e_swap(fore200e->stats->aal0.cells_received) + 2004 tmp.rx_cells = cpu_to_be32(fore200e->stats->aal0.cells_received) +
2035 fore200e_swap(fore200e->stats->aal34.cells_received) + 2005 cpu_to_be32(fore200e->stats->aal34.cells_received) +
2036 fore200e_swap(fore200e->stats->aal5.cells_received); 2006 cpu_to_be32(fore200e->stats->aal5.cells_received);
2037 2007
2038 if (arg) 2008 if (arg)
2039 return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0; 2009 return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0;
@@ -2146,7 +2116,7 @@ fore200e_irq_request(struct fore200e* fore200e)
2146static int __devinit 2116static int __devinit
2147fore200e_get_esi(struct fore200e* fore200e) 2117fore200e_get_esi(struct fore200e* fore200e)
2148{ 2118{
2149 struct prom_data* prom = fore200e_kmalloc(sizeof(struct prom_data), GFP_KERNEL | GFP_DMA); 2119 struct prom_data* prom = kzalloc(sizeof(struct prom_data), GFP_KERNEL | GFP_DMA);
2150 int ok, i; 2120 int ok, i;
2151 2121
2152 if (!prom) 2122 if (!prom)
@@ -2154,7 +2124,7 @@ fore200e_get_esi(struct fore200e* fore200e)
2154 2124
2155 ok = fore200e->bus->prom_read(fore200e, prom); 2125 ok = fore200e->bus->prom_read(fore200e, prom);
2156 if (ok < 0) { 2126 if (ok < 0) {
2157 fore200e_kfree(prom); 2127 kfree(prom);
2158 return -EBUSY; 2128 return -EBUSY;
2159 } 2129 }
2160 2130
@@ -2169,7 +2139,7 @@ fore200e_get_esi(struct fore200e* fore200e)
2169 fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ]; 2139 fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ];
2170 } 2140 }
2171 2141
2172 fore200e_kfree(prom); 2142 kfree(prom);
2173 2143
2174 return 0; 2144 return 0;
2175} 2145}
@@ -2194,7 +2164,7 @@ fore200e_alloc_rx_buf(struct fore200e* fore200e)
2194 DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme, magn); 2164 DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme, magn);
2195 2165
2196 /* allocate the array of receive buffers */ 2166 /* allocate the array of receive buffers */
2197 buffer = bsq->buffer = fore200e_kmalloc(nbr * sizeof(struct buffer), GFP_KERNEL); 2167 buffer = bsq->buffer = kzalloc(nbr * sizeof(struct buffer), GFP_KERNEL);
2198 2168
2199 if (buffer == NULL) 2169 if (buffer == NULL)
2200 return -ENOMEM; 2170 return -ENOMEM;
@@ -2217,7 +2187,7 @@ fore200e_alloc_rx_buf(struct fore200e* fore200e)
2217 2187
2218 while (i > 0) 2188 while (i > 0)
2219 fore200e_chunk_free(fore200e, &buffer[ --i ].data); 2189 fore200e_chunk_free(fore200e, &buffer[ --i ].data);
2220 fore200e_kfree(buffer); 2190 kfree(buffer);
2221 2191
2222 return -ENOMEM; 2192 return -ENOMEM;
2223 } 2193 }
@@ -2736,7 +2706,7 @@ fore200e_pca_detect(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent
2736 goto out; 2706 goto out;
2737 } 2707 }
2738 2708
2739 fore200e = fore200e_kmalloc(sizeof(struct fore200e), GFP_KERNEL); 2709 fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
2740 if (fore200e == NULL) { 2710 if (fore200e == NULL) {
2741 err = -ENOMEM; 2711 err = -ENOMEM;
2742 goto out_disable; 2712 goto out_disable;
@@ -2999,8 +2969,8 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
2999 " 4b5b:\n" 2969 " 4b5b:\n"
3000 " crc_header_errors:\t\t%10u\n" 2970 " crc_header_errors:\t\t%10u\n"
3001 " framing_errors:\t\t%10u\n", 2971 " framing_errors:\t\t%10u\n",
3002 fore200e_swap(fore200e->stats->phy.crc_header_errors), 2972 cpu_to_be32(fore200e->stats->phy.crc_header_errors),
3003 fore200e_swap(fore200e->stats->phy.framing_errors)); 2973 cpu_to_be32(fore200e->stats->phy.framing_errors));
3004 2974
3005 if (!left--) 2975 if (!left--)
3006 return sprintf(page, "\n" 2976 return sprintf(page, "\n"
@@ -3012,13 +2982,13 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3012 " path_febe_errors:\t\t%10u\n" 2982 " path_febe_errors:\t\t%10u\n"
3013 " corr_hcs_errors:\t\t%10u\n" 2983 " corr_hcs_errors:\t\t%10u\n"
3014 " ucorr_hcs_errors:\t\t%10u\n", 2984 " ucorr_hcs_errors:\t\t%10u\n",
3015 fore200e_swap(fore200e->stats->oc3.section_bip8_errors), 2985 cpu_to_be32(fore200e->stats->oc3.section_bip8_errors),
3016 fore200e_swap(fore200e->stats->oc3.path_bip8_errors), 2986 cpu_to_be32(fore200e->stats->oc3.path_bip8_errors),
3017 fore200e_swap(fore200e->stats->oc3.line_bip24_errors), 2987 cpu_to_be32(fore200e->stats->oc3.line_bip24_errors),
3018 fore200e_swap(fore200e->stats->oc3.line_febe_errors), 2988 cpu_to_be32(fore200e->stats->oc3.line_febe_errors),
3019 fore200e_swap(fore200e->stats->oc3.path_febe_errors), 2989 cpu_to_be32(fore200e->stats->oc3.path_febe_errors),
3020 fore200e_swap(fore200e->stats->oc3.corr_hcs_errors), 2990 cpu_to_be32(fore200e->stats->oc3.corr_hcs_errors),
3021 fore200e_swap(fore200e->stats->oc3.ucorr_hcs_errors)); 2991 cpu_to_be32(fore200e->stats->oc3.ucorr_hcs_errors));
3022 2992
3023 if (!left--) 2993 if (!left--)
3024 return sprintf(page,"\n" 2994 return sprintf(page,"\n"
@@ -3029,12 +2999,12 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3029 " vpi no conn:\t\t%10u\n" 2999 " vpi no conn:\t\t%10u\n"
3030 " vci out of range:\t\t%10u\n" 3000 " vci out of range:\t\t%10u\n"
3031 " vci no conn:\t\t%10u\n", 3001 " vci no conn:\t\t%10u\n",
3032 fore200e_swap(fore200e->stats->atm.cells_transmitted), 3002 cpu_to_be32(fore200e->stats->atm.cells_transmitted),
3033 fore200e_swap(fore200e->stats->atm.cells_received), 3003 cpu_to_be32(fore200e->stats->atm.cells_received),
3034 fore200e_swap(fore200e->stats->atm.vpi_bad_range), 3004 cpu_to_be32(fore200e->stats->atm.vpi_bad_range),
3035 fore200e_swap(fore200e->stats->atm.vpi_no_conn), 3005 cpu_to_be32(fore200e->stats->atm.vpi_no_conn),
3036 fore200e_swap(fore200e->stats->atm.vci_bad_range), 3006 cpu_to_be32(fore200e->stats->atm.vci_bad_range),
3037 fore200e_swap(fore200e->stats->atm.vci_no_conn)); 3007 cpu_to_be32(fore200e->stats->atm.vci_no_conn));
3038 3008
3039 if (!left--) 3009 if (!left--)
3040 return sprintf(page,"\n" 3010 return sprintf(page,"\n"
@@ -3042,9 +3012,9 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3042 " TX:\t\t\t%10u\n" 3012 " TX:\t\t\t%10u\n"
3043 " RX:\t\t\t%10u\n" 3013 " RX:\t\t\t%10u\n"
3044 " dropped:\t\t\t%10u\n", 3014 " dropped:\t\t\t%10u\n",
3045 fore200e_swap(fore200e->stats->aal0.cells_transmitted), 3015 cpu_to_be32(fore200e->stats->aal0.cells_transmitted),
3046 fore200e_swap(fore200e->stats->aal0.cells_received), 3016 cpu_to_be32(fore200e->stats->aal0.cells_received),
3047 fore200e_swap(fore200e->stats->aal0.cells_dropped)); 3017 cpu_to_be32(fore200e->stats->aal0.cells_dropped));
3048 3018
3049 if (!left--) 3019 if (!left--)
3050 return sprintf(page,"\n" 3020 return sprintf(page,"\n"
@@ -3060,15 +3030,15 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3060 " RX:\t\t\t%10u\n" 3030 " RX:\t\t\t%10u\n"
3061 " dropped:\t\t\t%10u\n" 3031 " dropped:\t\t\t%10u\n"
3062 " protocol errors:\t\t%10u\n", 3032 " protocol errors:\t\t%10u\n",
3063 fore200e_swap(fore200e->stats->aal34.cells_transmitted), 3033 cpu_to_be32(fore200e->stats->aal34.cells_transmitted),
3064 fore200e_swap(fore200e->stats->aal34.cells_received), 3034 cpu_to_be32(fore200e->stats->aal34.cells_received),
3065 fore200e_swap(fore200e->stats->aal34.cells_dropped), 3035 cpu_to_be32(fore200e->stats->aal34.cells_dropped),
3066 fore200e_swap(fore200e->stats->aal34.cells_crc_errors), 3036 cpu_to_be32(fore200e->stats->aal34.cells_crc_errors),
3067 fore200e_swap(fore200e->stats->aal34.cells_protocol_errors), 3037 cpu_to_be32(fore200e->stats->aal34.cells_protocol_errors),
3068 fore200e_swap(fore200e->stats->aal34.cspdus_transmitted), 3038 cpu_to_be32(fore200e->stats->aal34.cspdus_transmitted),
3069 fore200e_swap(fore200e->stats->aal34.cspdus_received), 3039 cpu_to_be32(fore200e->stats->aal34.cspdus_received),
3070 fore200e_swap(fore200e->stats->aal34.cspdus_dropped), 3040 cpu_to_be32(fore200e->stats->aal34.cspdus_dropped),
3071 fore200e_swap(fore200e->stats->aal34.cspdus_protocol_errors)); 3041 cpu_to_be32(fore200e->stats->aal34.cspdus_protocol_errors));
3072 3042
3073 if (!left--) 3043 if (!left--)
3074 return sprintf(page,"\n" 3044 return sprintf(page,"\n"
@@ -3084,15 +3054,15 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3084 " dropped:\t\t\t%10u\n" 3054 " dropped:\t\t\t%10u\n"
3085 " CRC errors:\t\t%10u\n" 3055 " CRC errors:\t\t%10u\n"
3086 " protocol errors:\t\t%10u\n", 3056 " protocol errors:\t\t%10u\n",
3087 fore200e_swap(fore200e->stats->aal5.cells_transmitted), 3057 cpu_to_be32(fore200e->stats->aal5.cells_transmitted),
3088 fore200e_swap(fore200e->stats->aal5.cells_received), 3058 cpu_to_be32(fore200e->stats->aal5.cells_received),
3089 fore200e_swap(fore200e->stats->aal5.cells_dropped), 3059 cpu_to_be32(fore200e->stats->aal5.cells_dropped),
3090 fore200e_swap(fore200e->stats->aal5.congestion_experienced), 3060 cpu_to_be32(fore200e->stats->aal5.congestion_experienced),
3091 fore200e_swap(fore200e->stats->aal5.cspdus_transmitted), 3061 cpu_to_be32(fore200e->stats->aal5.cspdus_transmitted),
3092 fore200e_swap(fore200e->stats->aal5.cspdus_received), 3062 cpu_to_be32(fore200e->stats->aal5.cspdus_received),
3093 fore200e_swap(fore200e->stats->aal5.cspdus_dropped), 3063 cpu_to_be32(fore200e->stats->aal5.cspdus_dropped),
3094 fore200e_swap(fore200e->stats->aal5.cspdus_crc_errors), 3064 cpu_to_be32(fore200e->stats->aal5.cspdus_crc_errors),
3095 fore200e_swap(fore200e->stats->aal5.cspdus_protocol_errors)); 3065 cpu_to_be32(fore200e->stats->aal5.cspdus_protocol_errors));
3096 3066
3097 if (!left--) 3067 if (!left--)
3098 return sprintf(page,"\n" 3068 return sprintf(page,"\n"
@@ -3103,11 +3073,11 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3103 " large b2:\t\t\t%10u\n" 3073 " large b2:\t\t\t%10u\n"
3104 " RX PDUs:\t\t\t%10u\n" 3074 " RX PDUs:\t\t\t%10u\n"
3105 " TX PDUs:\t\t\t%10lu\n", 3075 " TX PDUs:\t\t\t%10lu\n",
3106 fore200e_swap(fore200e->stats->aux.small_b1_failed), 3076 cpu_to_be32(fore200e->stats->aux.small_b1_failed),
3107 fore200e_swap(fore200e->stats->aux.large_b1_failed), 3077 cpu_to_be32(fore200e->stats->aux.large_b1_failed),
3108 fore200e_swap(fore200e->stats->aux.small_b2_failed), 3078 cpu_to_be32(fore200e->stats->aux.small_b2_failed),
3109 fore200e_swap(fore200e->stats->aux.large_b2_failed), 3079 cpu_to_be32(fore200e->stats->aux.large_b2_failed),
3110 fore200e_swap(fore200e->stats->aux.rpd_alloc_failed), 3080 cpu_to_be32(fore200e->stats->aux.rpd_alloc_failed),
3111 fore200e->tx_sat); 3081 fore200e->tx_sat);
3112 3082
3113 if (!left--) 3083 if (!left--)
diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
index 4dc10105d6..f96446c358 100644
--- a/drivers/atm/horizon.c
+++ b/drivers/atm/horizon.c
@@ -1845,7 +1845,7 @@ static u16 __devinit read_bia (const hrz_dev * dev, u16 addr)
1845 1845
1846/********** initialise a card **********/ 1846/********** initialise a card **********/
1847 1847
1848static int __init hrz_init (hrz_dev * dev) { 1848static int __devinit hrz_init (hrz_dev * dev) {
1849 int onefivefive; 1849 int onefivefive;
1850 1850
1851 u16 chan; 1851 u16 chan;
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 4bad2870c4..64558f45e6 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -127,6 +127,7 @@ static ssize_t firmware_loading_show(struct device *dev,
127/** 127/**
128 * firmware_loading_store - set value in the 'loading' control file 128 * firmware_loading_store - set value in the 'loading' control file
129 * @dev: device pointer 129 * @dev: device pointer
130 * @attr: device attribute pointer
130 * @buf: buffer to scan for loading control value 131 * @buf: buffer to scan for loading control value
131 * @count: number of bytes in @buf 132 * @count: number of bytes in @buf
132 * 133 *
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index 97f7f535f4..bb022ed4a8 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -30,8 +30,6 @@ new_skb(ulong len)
30 skb->nh.raw = skb->mac.raw = skb->data; 30 skb->nh.raw = skb->mac.raw = skb->data;
31 skb->protocol = __constant_htons(ETH_P_AOE); 31 skb->protocol = __constant_htons(ETH_P_AOE);
32 skb->priority = 0; 32 skb->priority = 0;
33 skb_put(skb, len);
34 memset(skb->head, 0, len);
35 skb->next = skb->prev = NULL; 33 skb->next = skb->prev = NULL;
36 34
37 /* tell the network layer not to perform IP checksums 35 /* tell the network layer not to perform IP checksums
@@ -122,8 +120,8 @@ aoecmd_ata_rw(struct aoedev *d, struct frame *f)
122 skb = f->skb; 120 skb = f->skb;
123 h = (struct aoe_hdr *) skb->mac.raw; 121 h = (struct aoe_hdr *) skb->mac.raw;
124 ah = (struct aoe_atahdr *) (h+1); 122 ah = (struct aoe_atahdr *) (h+1);
125 skb->len = sizeof *h + sizeof *ah; 123 skb_put(skb, sizeof *h + sizeof *ah);
126 memset(h, 0, ETH_ZLEN); 124 memset(h, 0, skb->len);
127 f->tag = aoehdr_atainit(d, h); 125 f->tag = aoehdr_atainit(d, h);
128 f->waited = 0; 126 f->waited = 0;
129 f->buf = buf; 127 f->buf = buf;
@@ -149,7 +147,6 @@ aoecmd_ata_rw(struct aoedev *d, struct frame *f)
149 skb->len += bcnt; 147 skb->len += bcnt;
150 skb->data_len = bcnt; 148 skb->data_len = bcnt;
151 } else { 149 } else {
152 skb->len = ETH_ZLEN;
153 writebit = 0; 150 writebit = 0;
154 } 151 }
155 152
@@ -206,6 +203,7 @@ aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff **tail)
206 printk(KERN_INFO "aoe: skb alloc failure\n"); 203 printk(KERN_INFO "aoe: skb alloc failure\n");
207 continue; 204 continue;
208 } 205 }
206 skb_put(skb, sizeof *h + sizeof *ch);
209 skb->dev = ifp; 207 skb->dev = ifp;
210 if (sl_tail == NULL) 208 if (sl_tail == NULL)
211 sl_tail = skb; 209 sl_tail = skb;
@@ -243,6 +241,7 @@ freeframe(struct aoedev *d)
243 continue; 241 continue;
244 if (atomic_read(&skb_shinfo(f->skb)->dataref) == 1) { 242 if (atomic_read(&skb_shinfo(f->skb)->dataref) == 1) {
245 skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0; 243 skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0;
244 skb_trim(f->skb, 0);
246 return f; 245 return f;
247 } 246 }
248 n++; 247 n++;
@@ -698,8 +697,8 @@ aoecmd_ata_id(struct aoedev *d)
698 skb = f->skb; 697 skb = f->skb;
699 h = (struct aoe_hdr *) skb->mac.raw; 698 h = (struct aoe_hdr *) skb->mac.raw;
700 ah = (struct aoe_atahdr *) (h+1); 699 ah = (struct aoe_atahdr *) (h+1);
701 skb->len = ETH_ZLEN; 700 skb_put(skb, sizeof *h + sizeof *ah);
702 memset(h, 0, ETH_ZLEN); 701 memset(h, 0, skb->len);
703 f->tag = aoehdr_atainit(d, h); 702 f->tag = aoehdr_atainit(d, h);
704 f->waited = 0; 703 f->waited = 0;
705 704
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index d719a5d8f4..05dfe35752 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -225,6 +225,8 @@ static inline CommandList_struct *removeQ(CommandList_struct **Qptr,
225 225
226#include "cciss_scsi.c" /* For SCSI tape support */ 226#include "cciss_scsi.c" /* For SCSI tape support */
227 227
228#define RAID_UNKNOWN 6
229
228#ifdef CONFIG_PROC_FS 230#ifdef CONFIG_PROC_FS
229 231
230/* 232/*
@@ -232,7 +234,6 @@ static inline CommandList_struct *removeQ(CommandList_struct **Qptr,
232 */ 234 */
233#define ENG_GIG 1000000000 235#define ENG_GIG 1000000000
234#define ENG_GIG_FACTOR (ENG_GIG/512) 236#define ENG_GIG_FACTOR (ENG_GIG/512)
235#define RAID_UNKNOWN 6
236static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG", 237static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG",
237 "UNKNOWN" 238 "UNKNOWN"
238}; 239};
@@ -1907,6 +1908,7 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
1907 "does not support reading geometry\n"); 1908 "does not support reading geometry\n");
1908 drv->heads = 255; 1909 drv->heads = 255;
1909 drv->sectors = 32; // Sectors per track 1910 drv->sectors = 32; // Sectors per track
1911 drv->raid_level = RAID_UNKNOWN;
1910 } else { 1912 } else {
1911 drv->heads = inq_buff->data_byte[6]; 1913 drv->heads = inq_buff->data_byte[6];
1912 drv->sectors = inq_buff->data_byte[7]; 1914 drv->sectors = inq_buff->data_byte[7];
@@ -2491,7 +2493,7 @@ static void do_cciss_request(request_queue_t *q)
2491 c->Request.Type.Type = TYPE_CMD; // It is a command. 2493 c->Request.Type.Type = TYPE_CMD; // It is a command.
2492 c->Request.Type.Attribute = ATTR_SIMPLE; 2494 c->Request.Type.Attribute = ATTR_SIMPLE;
2493 c->Request.Type.Direction = 2495 c->Request.Type.Direction =
2494 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; 2496 (rq_data_dir(creq) == READ) ? XFER_READ : XFER_WRITE;
2495 c->Request.Timeout = 0; // Don't time out 2497 c->Request.Timeout = 0; // Don't time out
2496 c->Request.CDB[0] = 2498 c->Request.CDB[0] =
2497 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; 2499 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 7c95c76295..62462190e0 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -765,47 +765,34 @@ static inline struct bio *pkt_get_list_first(struct bio **list_head, struct bio
765 */ 765 */
766static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc) 766static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc)
767{ 767{
768 char sense[SCSI_SENSE_BUFFERSIZE]; 768 request_queue_t *q = bdev_get_queue(pd->bdev);
769 request_queue_t *q;
770 struct request *rq; 769 struct request *rq;
771 DECLARE_COMPLETION_ONSTACK(wait); 770 int ret = 0;
772 int err = 0;
773 771
774 q = bdev_get_queue(pd->bdev); 772 rq = blk_get_request(q, (cgc->data_direction == CGC_DATA_WRITE) ?
773 WRITE : READ, __GFP_WAIT);
774
775 if (cgc->buflen) {
776 if (blk_rq_map_kern(q, rq, cgc->buffer, cgc->buflen, __GFP_WAIT))
777 goto out;
778 }
779
780 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
781 memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE);
782 if (sizeof(rq->cmd) > CDROM_PACKET_SIZE)
783 memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE);
775 784
776 rq = blk_get_request(q, (cgc->data_direction == CGC_DATA_WRITE) ? WRITE : READ,
777 __GFP_WAIT);
778 rq->errors = 0;
779 rq->rq_disk = pd->bdev->bd_disk;
780 rq->bio = NULL;
781 rq->buffer = NULL;
782 rq->timeout = 60*HZ; 785 rq->timeout = 60*HZ;
783 rq->data = cgc->buffer;
784 rq->data_len = cgc->buflen;
785 rq->sense = sense;
786 memset(sense, 0, sizeof(sense));
787 rq->sense_len = 0;
788 rq->cmd_type = REQ_TYPE_BLOCK_PC; 786 rq->cmd_type = REQ_TYPE_BLOCK_PC;
789 rq->cmd_flags |= REQ_HARDBARRIER; 787 rq->cmd_flags |= REQ_HARDBARRIER;
790 if (cgc->quiet) 788 if (cgc->quiet)
791 rq->cmd_flags |= REQ_QUIET; 789 rq->cmd_flags |= REQ_QUIET;
792 memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE);
793 if (sizeof(rq->cmd) > CDROM_PACKET_SIZE)
794 memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE);
795 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
796
797 rq->ref_count++;
798 rq->end_io_data = &wait;
799 rq->end_io = blk_end_sync_rq;
800 elv_add_request(q, rq, ELEVATOR_INSERT_BACK, 1);
801 generic_unplug_device(q);
802 wait_for_completion(&wait);
803
804 if (rq->errors)
805 err = -EIO;
806 790
791 blk_execute_rq(rq->q, pd->bdev->bd_disk, rq, 0);
792 ret = rq->errors;
793out:
807 blk_put_request(rq); 794 blk_put_request(rq);
808 return err; 795 return ret;
809} 796}
810 797
811/* 798/*
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index e19ba4ebcd..68592c3360 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -49,6 +49,7 @@
49#include <asm/iseries/hv_lp_event.h> 49#include <asm/iseries/hv_lp_event.h>
50#include <asm/iseries/hv_lp_config.h> 50#include <asm/iseries/hv_lp_config.h>
51#include <asm/iseries/vio.h> 51#include <asm/iseries/vio.h>
52#include <asm/firmware.h>
52 53
53MODULE_DESCRIPTION("iSeries Virtual DASD"); 54MODULE_DESCRIPTION("iSeries Virtual DASD");
54MODULE_AUTHOR("Dave Boutcher"); 55MODULE_AUTHOR("Dave Boutcher");
@@ -769,6 +770,11 @@ static int __init viodasd_init(void)
769{ 770{
770 int rc; 771 int rc;
771 772
773 if (!firmware_has_feature(FW_FEATURE_ISERIES)) {
774 rc = -ENODEV;
775 goto early_fail;
776 }
777
772 /* Try to open to our host lp */ 778 /* Try to open to our host lp */
773 if (viopath_hostLp == HvLpIndexInvalid) 779 if (viopath_hostLp == HvLpIndexInvalid)
774 vio_set_hostlp(); 780 vio_set_hostlp();
diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c
index fdea58ae16..6bdf593081 100644
--- a/drivers/bluetooth/hci_usb.c
+++ b/drivers/bluetooth/hci_usb.c
@@ -117,15 +117,23 @@ static struct usb_device_id blacklist_ids[] = {
117 117
118 /* IBM/Lenovo ThinkPad with Broadcom chip */ 118 /* IBM/Lenovo ThinkPad with Broadcom chip */
119 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = HCI_WRONG_SCO_MTU }, 119 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = HCI_WRONG_SCO_MTU },
120 { USB_DEVICE(0x0a5c, 0x2110), .driver_info = HCI_WRONG_SCO_MTU },
120 121
121 /* ANYCOM Bluetooth USB-200 and USB-250 */ 122 /* ANYCOM Bluetooth USB-200 and USB-250 */
122 { USB_DEVICE(0x0a5c, 0x2111), .driver_info = HCI_RESET }, 123 { USB_DEVICE(0x0a5c, 0x2111), .driver_info = HCI_RESET },
123 124
125 /* HP laptop with Broadcom chip */
126 { USB_DEVICE(0x03f0, 0x171d), .driver_info = HCI_WRONG_SCO_MTU },
127
128 /* Dell laptop with Broadcom chip */
129 { USB_DEVICE(0x413c, 0x8126), .driver_info = HCI_WRONG_SCO_MTU },
130
124 /* Microsoft Wireless Transceiver for Bluetooth 2.0 */ 131 /* Microsoft Wireless Transceiver for Bluetooth 2.0 */
125 { USB_DEVICE(0x045e, 0x009c), .driver_info = HCI_RESET }, 132 { USB_DEVICE(0x045e, 0x009c), .driver_info = HCI_RESET },
126 133
127 /* Kensington Bluetooth USB adapter */ 134 /* Kensington Bluetooth USB adapter */
128 { USB_DEVICE(0x047d, 0x105d), .driver_info = HCI_RESET }, 135 { USB_DEVICE(0x047d, 0x105d), .driver_info = HCI_RESET },
136 { USB_DEVICE(0x047d, 0x105e), .driver_info = HCI_WRONG_SCO_MTU },
129 137
130 /* ISSC Bluetooth Adapter v3.1 */ 138 /* ISSC Bluetooth Adapter v3.1 */
131 { USB_DEVICE(0x1131, 0x1001), .driver_info = HCI_RESET }, 139 { USB_DEVICE(0x1131, 0x1001), .driver_info = HCI_RESET },
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index e4a2f8f3a1..3105dddf59 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -337,6 +337,12 @@ static const char *mrw_address_space[] = { "DMA", "GAA" };
337/* used in the audio ioctls */ 337/* used in the audio ioctls */
338#define CHECKAUDIO if ((ret=check_for_audio_disc(cdi, cdo))) return ret 338#define CHECKAUDIO if ((ret=check_for_audio_disc(cdi, cdo))) return ret
339 339
340/*
341 * Another popular OS uses 7 seconds as the hard timeout for default
342 * commands, so it is a good choice for us as well.
343 */
344#define CDROM_DEF_TIMEOUT (7 * HZ)
345
340/* Not-exported routines. */ 346/* Not-exported routines. */
341static int open_for_data(struct cdrom_device_info * cdi); 347static int open_for_data(struct cdrom_device_info * cdi);
342static int check_for_audio_disc(struct cdrom_device_info * cdi, 348static int check_for_audio_disc(struct cdrom_device_info * cdi,
@@ -1528,7 +1534,7 @@ void init_cdrom_command(struct packet_command *cgc, void *buf, int len,
1528 cgc->buffer = (char *) buf; 1534 cgc->buffer = (char *) buf;
1529 cgc->buflen = len; 1535 cgc->buflen = len;
1530 cgc->data_direction = type; 1536 cgc->data_direction = type;
1531 cgc->timeout = 5*HZ; 1537 cgc->timeout = CDROM_DEF_TIMEOUT;
1532} 1538}
1533 1539
1534/* DVD handling */ 1540/* DVD handling */
@@ -2139,8 +2145,7 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
2139 cdi->last_sense = s->sense_key; 2145 cdi->last_sense = s->sense_key;
2140 } 2146 }
2141 2147
2142 rq->bio = bio; 2148 if (blk_rq_unmap_user(bio))
2143 if (blk_rq_unmap_user(rq))
2144 ret = -EFAULT; 2149 ret = -EFAULT;
2145 2150
2146 if (ret) 2151 if (ret)
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index 54ca931e19..93fbf84dcc 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -47,6 +47,7 @@
47#include <asm/iseries/hv_types.h> 47#include <asm/iseries/hv_types.h>
48#include <asm/iseries/hv_lp_event.h> 48#include <asm/iseries/hv_lp_event.h>
49#include <asm/iseries/vio.h> 49#include <asm/iseries/vio.h>
50#include <asm/firmware.h>
50 51
51#define VIOCD_DEVICE "iseries/vcd" 52#define VIOCD_DEVICE "iseries/vcd"
52 53
@@ -748,6 +749,9 @@ static int __init viocd_init(void)
748 struct proc_dir_entry *e; 749 struct proc_dir_entry *e;
749 int ret = 0; 750 int ret = 0;
750 751
752 if (!firmware_has_feature(FW_FEATURE_ISERIES))
753 return -ENODEV;
754
751 if (viopath_hostLp == HvLpIndexInvalid) { 755 if (viopath_hostLp == HvLpIndexInvalid) {
752 vio_set_hostlp(); 756 vio_set_hostlp();
753 /* If we don't have a host, bail out */ 757 /* If we don't have a host, bail out */
diff --git a/drivers/char/agp/agp.h b/drivers/char/agp/agp.h
index 8b3317fd46..1d59e2a5b9 100644
--- a/drivers/char/agp/agp.h
+++ b/drivers/char/agp/agp.h
@@ -225,6 +225,10 @@ struct agp_bridge_data {
225#define I810_GMS_DISABLE 0x00000000 225#define I810_GMS_DISABLE 0x00000000
226#define I810_PGETBL_CTL 0x2020 226#define I810_PGETBL_CTL 0x2020
227#define I810_PGETBL_ENABLED 0x00000001 227#define I810_PGETBL_ENABLED 0x00000001
228#define I965_PGETBL_SIZE_MASK 0x0000000e
229#define I965_PGETBL_SIZE_512KB (0 << 1)
230#define I965_PGETBL_SIZE_256KB (1 << 1)
231#define I965_PGETBL_SIZE_128KB (2 << 1)
228#define I810_DRAM_CTL 0x3000 232#define I810_DRAM_CTL 0x3000
229#define I810_DRAM_ROW_0 0x00000001 233#define I810_DRAM_ROW_0 0x00000001
230#define I810_DRAM_ROW_0_SDRAM 0x00000001 234#define I810_DRAM_ROW_0_SDRAM 0x00000001
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
index 51d0d562d0..c85c8cadb6 100644
--- a/drivers/char/agp/amd-k7-agp.c
+++ b/drivers/char/agp/amd-k7-agp.c
@@ -101,6 +101,11 @@ static int amd_create_gatt_pages(int nr_tables)
101 for (i = 0; i < nr_tables; i++) { 101 for (i = 0; i < nr_tables; i++) {
102 entry = kzalloc(sizeof(struct amd_page_map), GFP_KERNEL); 102 entry = kzalloc(sizeof(struct amd_page_map), GFP_KERNEL);
103 if (entry == NULL) { 103 if (entry == NULL) {
104 while (i > 0) {
105 kfree(tables[i-1]);
106 i--;
107 }
108 kfree(tables);
104 retval = -ENOMEM; 109 retval = -ENOMEM;
105 break; 110 break;
106 } 111 }
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 2f2c4efff8..93d2209fee 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -650,6 +650,15 @@ static struct pci_device_id agp_amd64_pci_table[] = {
650 .subvendor = PCI_ANY_ID, 650 .subvendor = PCI_ANY_ID,
651 .subdevice = PCI_ANY_ID, 651 .subdevice = PCI_ANY_ID,
652 }, 652 },
653 /* VIA K8M890 / K8N890 */
654 {
655 .class = (PCI_CLASS_BRIDGE_HOST << 8),
656 .class_mask = ~0,
657 .vendor = PCI_VENDOR_ID_VIA,
658 .device = PCI_DEVICE_ID_VIA_VT3336,
659 .subvendor = PCI_ANY_ID,
660 .subdevice = PCI_ANY_ID,
661 },
653 /* VIA K8T890 */ 662 /* VIA K8T890 */
654 { 663 {
655 .class = (PCI_CLASS_BRIDGE_HOST << 8), 664 .class = (PCI_CLASS_BRIDGE_HOST << 8),
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index f244c66827..9987dc2e0c 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -41,18 +41,18 @@ static struct gatt_mask ati_generic_masks[] =
41}; 41};
42 42
43 43
44typedef struct _ati_page_map { 44struct ati_page_map {
45 unsigned long *real; 45 unsigned long *real;
46 unsigned long __iomem *remapped; 46 unsigned long __iomem *remapped;
47} ati_page_map; 47};
48 48
49static struct _ati_generic_private { 49static struct _ati_generic_private {
50 volatile u8 __iomem *registers; 50 volatile u8 __iomem *registers;
51 ati_page_map **gatt_pages; 51 struct ati_page_map **gatt_pages;
52 int num_tables; 52 int num_tables;
53} ati_generic_private; 53} ati_generic_private;
54 54
55static int ati_create_page_map(ati_page_map *page_map) 55static int ati_create_page_map(struct ati_page_map *page_map)
56{ 56{
57 int i, err = 0; 57 int i, err = 0;
58 58
@@ -82,7 +82,7 @@ static int ati_create_page_map(ati_page_map *page_map)
82} 82}
83 83
84 84
85static void ati_free_page_map(ati_page_map *page_map) 85static void ati_free_page_map(struct ati_page_map *page_map)
86{ 86{
87 unmap_page_from_agp(virt_to_page(page_map->real)); 87 unmap_page_from_agp(virt_to_page(page_map->real));
88 iounmap(page_map->remapped); 88 iounmap(page_map->remapped);
@@ -94,8 +94,8 @@ static void ati_free_page_map(ati_page_map *page_map)
94static void ati_free_gatt_pages(void) 94static void ati_free_gatt_pages(void)
95{ 95{
96 int i; 96 int i;
97 ati_page_map **tables; 97 struct ati_page_map **tables;
98 ati_page_map *entry; 98 struct ati_page_map *entry;
99 99
100 tables = ati_generic_private.gatt_pages; 100 tables = ati_generic_private.gatt_pages;
101 for (i = 0; i < ati_generic_private.num_tables; i++) { 101 for (i = 0; i < ati_generic_private.num_tables; i++) {
@@ -112,30 +112,30 @@ static void ati_free_gatt_pages(void)
112 112
113static int ati_create_gatt_pages(int nr_tables) 113static int ati_create_gatt_pages(int nr_tables)
114{ 114{
115 ati_page_map **tables; 115 struct ati_page_map **tables;
116 ati_page_map *entry; 116 struct ati_page_map *entry;
117 int retval = 0; 117 int retval = 0;
118 int i; 118 int i;
119 119
120 tables = kzalloc((nr_tables + 1) * sizeof(ati_page_map *),GFP_KERNEL); 120 tables = kzalloc((nr_tables + 1) * sizeof(struct ati_page_map *),GFP_KERNEL);
121 if (tables == NULL) 121 if (tables == NULL)
122 return -ENOMEM; 122 return -ENOMEM;
123 123
124 for (i = 0; i < nr_tables; i++) { 124 for (i = 0; i < nr_tables; i++) {
125 entry = kzalloc(sizeof(ati_page_map), GFP_KERNEL); 125 entry = kzalloc(sizeof(struct ati_page_map), GFP_KERNEL);
126 if (entry == NULL) { 126 if (entry == NULL) {
127 while (i>0) { 127 while (i > 0) {
128 kfree (tables[i-1]); 128 kfree(tables[i-1]);
129 i--; 129 i--;
130 } 130 }
131 kfree (tables); 131 kfree(tables);
132 tables = NULL;
133 retval = -ENOMEM; 132 retval = -ENOMEM;
134 break; 133 break;
135 } 134 }
136 tables[i] = entry; 135 tables[i] = entry;
137 retval = ati_create_page_map(entry); 136 retval = ati_create_page_map(entry);
138 if (retval != 0) break; 137 if (retval != 0)
138 break;
139 } 139 }
140 ati_generic_private.num_tables = nr_tables; 140 ati_generic_private.num_tables = nr_tables;
141 ati_generic_private.gatt_pages = tables; 141 ati_generic_private.gatt_pages = tables;
@@ -340,7 +340,7 @@ static int ati_remove_memory(struct agp_memory * mem, off_t pg_start,
340static int ati_create_gatt_table(struct agp_bridge_data *bridge) 340static int ati_create_gatt_table(struct agp_bridge_data *bridge)
341{ 341{
342 struct aper_size_info_lvl2 *value; 342 struct aper_size_info_lvl2 *value;
343 ati_page_map page_dir; 343 struct ati_page_map page_dir;
344 unsigned long addr; 344 unsigned long addr;
345 int retval; 345 int retval;
346 u32 temp; 346 u32 temp;
@@ -400,7 +400,7 @@ static int ati_create_gatt_table(struct agp_bridge_data *bridge)
400 400
401static int ati_free_gatt_table(struct agp_bridge_data *bridge) 401static int ati_free_gatt_table(struct agp_bridge_data *bridge)
402{ 402{
403 ati_page_map page_dir; 403 struct ati_page_map page_dir;
404 404
405 page_dir.real = (unsigned long *)agp_bridge->gatt_table_real; 405 page_dir.real = (unsigned long *)agp_bridge->gatt_table_real;
406 page_dir.remapped = (unsigned long __iomem *)agp_bridge->gatt_table; 406 page_dir.remapped = (unsigned long __iomem *)agp_bridge->gatt_table;
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index 883a36a278..3491d6f84b 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -965,6 +965,9 @@ int agp_generic_insert_memory(struct agp_memory * mem, off_t pg_start, int type)
965 if (!bridge) 965 if (!bridge)
966 return -EINVAL; 966 return -EINVAL;
967 967
968 if (mem->page_count == 0)
969 return 0;
970
968 temp = bridge->current_size; 971 temp = bridge->current_size;
969 972
970 switch (bridge->driver->size_type) { 973 switch (bridge->driver->size_type) {
@@ -1016,8 +1019,8 @@ int agp_generic_insert_memory(struct agp_memory * mem, off_t pg_start, int type)
1016 1019
1017 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 1020 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
1018 writel(bridge->driver->mask_memory(bridge, mem->memory[i], mem->type), bridge->gatt_table+j); 1021 writel(bridge->driver->mask_memory(bridge, mem->memory[i], mem->type), bridge->gatt_table+j);
1019 readl(bridge->gatt_table+j); /* PCI Posting. */
1020 } 1022 }
1023 readl(bridge->gatt_table+j-1); /* PCI Posting. */
1021 1024
1022 bridge->driver->tlb_flush(mem); 1025 bridge->driver->tlb_flush(mem);
1023 return 0; 1026 return 0;
@@ -1034,6 +1037,9 @@ int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
1034 if (!bridge) 1037 if (!bridge)
1035 return -EINVAL; 1038 return -EINVAL;
1036 1039
1040 if (mem->page_count == 0)
1041 return 0;
1042
1037 if (type != 0 || mem->type != 0) { 1043 if (type != 0 || mem->type != 0) {
1038 /* The generic routines know nothing of memory types */ 1044 /* The generic routines know nothing of memory types */
1039 return -EINVAL; 1045 return -EINVAL;
@@ -1042,10 +1048,9 @@ int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
1042 /* AK: bogus, should encode addresses > 4GB */ 1048 /* AK: bogus, should encode addresses > 4GB */
1043 for (i = pg_start; i < (mem->page_count + pg_start); i++) { 1049 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
1044 writel(bridge->scratch_page, bridge->gatt_table+i); 1050 writel(bridge->scratch_page, bridge->gatt_table+i);
1045 readl(bridge->gatt_table+i); /* PCI Posting. */
1046 } 1051 }
1052 readl(bridge->gatt_table+i-1); /* PCI Posting. */
1047 1053
1048 global_cache_flush();
1049 bridge->driver->tlb_flush(mem); 1054 bridge->driver->tlb_flush(mem);
1050 return 0; 1055 return 0;
1051} 1056}
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 555b3a8ab4..a3011de51f 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -207,6 +207,9 @@ static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
207 int i, j, num_entries; 207 int i, j, num_entries;
208 void *temp; 208 void *temp;
209 209
210 if (mem->page_count == 0)
211 return 0;
212
210 temp = agp_bridge->current_size; 213 temp = agp_bridge->current_size;
211 num_entries = A_SIZE_FIX(temp)->num_entries; 214 num_entries = A_SIZE_FIX(temp)->num_entries;
212 215
@@ -221,12 +224,16 @@ static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
221 if (type != 0 || mem->type != 0) { 224 if (type != 0 || mem->type != 0) {
222 if ((type == AGP_DCACHE_MEMORY) && (mem->type == AGP_DCACHE_MEMORY)) { 225 if ((type == AGP_DCACHE_MEMORY) && (mem->type == AGP_DCACHE_MEMORY)) {
223 /* special insert */ 226 /* special insert */
224 global_cache_flush(); 227 if (!mem->is_flushed) {
228 global_cache_flush();
229 mem->is_flushed = TRUE;
230 }
231
225 for (i = pg_start; i < (pg_start + mem->page_count); i++) { 232 for (i = pg_start; i < (pg_start + mem->page_count); i++) {
226 writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID, intel_i810_private.registers+I810_PTE_BASE+(i*4)); 233 writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID, intel_i810_private.registers+I810_PTE_BASE+(i*4));
227 readl(intel_i810_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
228 } 234 }
229 global_cache_flush(); 235 readl(intel_i810_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI Posting. */
236
230 agp_bridge->driver->tlb_flush(mem); 237 agp_bridge->driver->tlb_flush(mem);
231 return 0; 238 return 0;
232 } 239 }
@@ -236,14 +243,17 @@ static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
236 } 243 }
237 244
238insert: 245insert:
239 global_cache_flush(); 246 if (!mem->is_flushed) {
247 global_cache_flush();
248 mem->is_flushed = TRUE;
249 }
250
240 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 251 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
241 writel(agp_bridge->driver->mask_memory(agp_bridge, 252 writel(agp_bridge->driver->mask_memory(agp_bridge,
242 mem->memory[i], mem->type), 253 mem->memory[i], mem->type),
243 intel_i810_private.registers+I810_PTE_BASE+(j*4)); 254 intel_i810_private.registers+I810_PTE_BASE+(j*4));
244 readl(intel_i810_private.registers+I810_PTE_BASE+(j*4)); /* PCI Posting. */
245 } 255 }
246 global_cache_flush(); 256 readl(intel_i810_private.registers+I810_PTE_BASE+((j-1)*4)); /* PCI Posting. */
247 257
248 agp_bridge->driver->tlb_flush(mem); 258 agp_bridge->driver->tlb_flush(mem);
249 return 0; 259 return 0;
@@ -254,12 +264,14 @@ static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
254{ 264{
255 int i; 265 int i;
256 266
267 if (mem->page_count == 0)
268 return 0;
269
257 for (i = pg_start; i < (mem->page_count + pg_start); i++) { 270 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
258 writel(agp_bridge->scratch_page, intel_i810_private.registers+I810_PTE_BASE+(i*4)); 271 writel(agp_bridge->scratch_page, intel_i810_private.registers+I810_PTE_BASE+(i*4));
259 readl(intel_i810_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
260 } 272 }
273 readl(intel_i810_private.registers+I810_PTE_BASE+((i-1)*4));
261 274
262 global_cache_flush();
263 agp_bridge->driver->tlb_flush(mem); 275 agp_bridge->driver->tlb_flush(mem);
264 return 0; 276 return 0;
265} 277}
@@ -370,6 +382,11 @@ static struct _intel_i830_private {
370 struct pci_dev *i830_dev; /* device one */ 382 struct pci_dev *i830_dev; /* device one */
371 volatile u8 __iomem *registers; 383 volatile u8 __iomem *registers;
372 volatile u32 __iomem *gtt; /* I915G */ 384 volatile u32 __iomem *gtt; /* I915G */
385 /* gtt_entries is the number of gtt entries that are already mapped
386 * to stolen memory. Stolen memory is larger than the memory mapped
387 * through gtt_entries, as it includes some reserved space for the BIOS
388 * popup and for the GTT.
389 */
373 int gtt_entries; 390 int gtt_entries;
374} intel_i830_private; 391} intel_i830_private;
375 392
@@ -380,14 +397,41 @@ static void intel_i830_init_gtt_entries(void)
380 u8 rdct; 397 u8 rdct;
381 int local = 0; 398 int local = 0;
382 static const int ddt[4] = { 0, 16, 32, 64 }; 399 static const int ddt[4] = { 0, 16, 32, 64 };
383 int size; 400 int size; /* reserved space (in kb) at the top of stolen memory */
384 401
385 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl); 402 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
386 403
387 /* We obtain the size of the GTT, which is also stored (for some 404 if (IS_I965) {
388 * reason) at the top of stolen memory. Then we add 4KB to that 405 u32 pgetbl_ctl;
389 * for the video BIOS popup, which is also stored in there. */ 406
390 size = agp_bridge->driver->fetch_size() + 4; 407 pci_read_config_dword(agp_bridge->dev, I810_PGETBL_CTL,
408 &pgetbl_ctl);
409 /* The 965 has a field telling us the size of the GTT,
410 * which may be larger than what is necessary to map the
411 * aperture.
412 */
413 switch (pgetbl_ctl & I965_PGETBL_SIZE_MASK) {
414 case I965_PGETBL_SIZE_128KB:
415 size = 128;
416 break;
417 case I965_PGETBL_SIZE_256KB:
418 size = 256;
419 break;
420 case I965_PGETBL_SIZE_512KB:
421 size = 512;
422 break;
423 default:
424 printk(KERN_INFO PFX "Unknown page table size, "
425 "assuming 512KB\n");
426 size = 512;
427 }
428 size += 4; /* add in BIOS popup space */
429 } else {
430 /* On previous hardware, the GTT size was just what was
431 * required to map the aperture.
432 */
433 size = agp_bridge->driver->fetch_size() + 4;
434 }
391 435
392 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB || 436 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
393 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) { 437 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
@@ -576,6 +620,9 @@ static int intel_i830_insert_entries(struct agp_memory *mem,off_t pg_start, int
576 int i,j,num_entries; 620 int i,j,num_entries;
577 void *temp; 621 void *temp;
578 622
623 if (mem->page_count == 0)
624 return 0;
625
579 temp = agp_bridge->current_size; 626 temp = agp_bridge->current_size;
580 num_entries = A_SIZE_FIX(temp)->num_entries; 627 num_entries = A_SIZE_FIX(temp)->num_entries;
581 628
@@ -598,16 +645,18 @@ static int intel_i830_insert_entries(struct agp_memory *mem,off_t pg_start, int
598 (mem->type != 0 && mem->type != AGP_PHYS_MEMORY)) 645 (mem->type != 0 && mem->type != AGP_PHYS_MEMORY))
599 return -EINVAL; 646 return -EINVAL;
600 647
601 global_cache_flush(); /* FIXME: Necessary ?*/ 648 if (!mem->is_flushed) {
649 global_cache_flush();
650 mem->is_flushed = TRUE;
651 }
602 652
603 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 653 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
604 writel(agp_bridge->driver->mask_memory(agp_bridge, 654 writel(agp_bridge->driver->mask_memory(agp_bridge,
605 mem->memory[i], mem->type), 655 mem->memory[i], mem->type),
606 intel_i830_private.registers+I810_PTE_BASE+(j*4)); 656 intel_i830_private.registers+I810_PTE_BASE+(j*4));
607 readl(intel_i830_private.registers+I810_PTE_BASE+(j*4)); /* PCI Posting. */
608 } 657 }
658 readl(intel_i830_private.registers+I810_PTE_BASE+((j-1)*4));
609 659
610 global_cache_flush();
611 agp_bridge->driver->tlb_flush(mem); 660 agp_bridge->driver->tlb_flush(mem);
612 return 0; 661 return 0;
613} 662}
@@ -617,7 +666,8 @@ static int intel_i830_remove_entries(struct agp_memory *mem,off_t pg_start,
617{ 666{
618 int i; 667 int i;
619 668
620 global_cache_flush(); 669 if (mem->page_count == 0)
670 return 0;
621 671
622 if (pg_start < intel_i830_private.gtt_entries) { 672 if (pg_start < intel_i830_private.gtt_entries) {
623 printk (KERN_INFO PFX "Trying to disable local/stolen memory\n"); 673 printk (KERN_INFO PFX "Trying to disable local/stolen memory\n");
@@ -626,10 +676,9 @@ static int intel_i830_remove_entries(struct agp_memory *mem,off_t pg_start,
626 676
627 for (i = pg_start; i < (mem->page_count + pg_start); i++) { 677 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
628 writel(agp_bridge->scratch_page, intel_i830_private.registers+I810_PTE_BASE+(i*4)); 678 writel(agp_bridge->scratch_page, intel_i830_private.registers+I810_PTE_BASE+(i*4));
629 readl(intel_i830_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
630 } 679 }
680 readl(intel_i830_private.registers+I810_PTE_BASE+((i-1)*4));
631 681
632 global_cache_flush();
633 agp_bridge->driver->tlb_flush(mem); 682 agp_bridge->driver->tlb_flush(mem);
634 return 0; 683 return 0;
635} 684}
@@ -686,6 +735,9 @@ static int intel_i915_insert_entries(struct agp_memory *mem,off_t pg_start,
686 int i,j,num_entries; 735 int i,j,num_entries;
687 void *temp; 736 void *temp;
688 737
738 if (mem->page_count == 0)
739 return 0;
740
689 temp = agp_bridge->current_size; 741 temp = agp_bridge->current_size;
690 num_entries = A_SIZE_FIX(temp)->num_entries; 742 num_entries = A_SIZE_FIX(temp)->num_entries;
691 743
@@ -708,15 +760,17 @@ static int intel_i915_insert_entries(struct agp_memory *mem,off_t pg_start,
708 (mem->type != 0 && mem->type != AGP_PHYS_MEMORY)) 760 (mem->type != 0 && mem->type != AGP_PHYS_MEMORY))
709 return -EINVAL; 761 return -EINVAL;
710 762
711 global_cache_flush(); 763 if (!mem->is_flushed) {
764 global_cache_flush();
765 mem->is_flushed = TRUE;
766 }
712 767
713 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 768 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
714 writel(agp_bridge->driver->mask_memory(agp_bridge, 769 writel(agp_bridge->driver->mask_memory(agp_bridge,
715 mem->memory[i], mem->type), intel_i830_private.gtt+j); 770 mem->memory[i], mem->type), intel_i830_private.gtt+j);
716 readl(intel_i830_private.gtt+j); /* PCI Posting. */
717 } 771 }
772 readl(intel_i830_private.gtt+j-1);
718 773
719 global_cache_flush();
720 agp_bridge->driver->tlb_flush(mem); 774 agp_bridge->driver->tlb_flush(mem);
721 return 0; 775 return 0;
722} 776}
@@ -726,7 +780,8 @@ static int intel_i915_remove_entries(struct agp_memory *mem,off_t pg_start,
726{ 780{
727 int i; 781 int i;
728 782
729 global_cache_flush(); 783 if (mem->page_count == 0)
784 return 0;
730 785
731 if (pg_start < intel_i830_private.gtt_entries) { 786 if (pg_start < intel_i830_private.gtt_entries) {
732 printk (KERN_INFO PFX "Trying to disable local/stolen memory\n"); 787 printk (KERN_INFO PFX "Trying to disable local/stolen memory\n");
@@ -735,30 +790,34 @@ static int intel_i915_remove_entries(struct agp_memory *mem,off_t pg_start,
735 790
736 for (i = pg_start; i < (mem->page_count + pg_start); i++) { 791 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
737 writel(agp_bridge->scratch_page, intel_i830_private.gtt+i); 792 writel(agp_bridge->scratch_page, intel_i830_private.gtt+i);
738 readl(intel_i830_private.gtt+i);
739 } 793 }
794 readl(intel_i830_private.gtt+i-1);
740 795
741 global_cache_flush();
742 agp_bridge->driver->tlb_flush(mem); 796 agp_bridge->driver->tlb_flush(mem);
743 return 0; 797 return 0;
744} 798}
745 799
746static int intel_i915_fetch_size(void) 800/* Return the aperture size by just checking the resource length. The effect
801 * described in the spec of the MSAC registers is just changing of the
802 * resource size.
803 */
804static int intel_i9xx_fetch_size(void)
747{ 805{
748 struct aper_size_info_fixed *values; 806 int num_sizes = sizeof(intel_i830_sizes) / sizeof(*intel_i830_sizes);
749 u32 temp, offset; 807 int aper_size; /* size in megabytes */
808 int i;
750 809
751#define I915_256MB_ADDRESS_MASK (1<<27) 810 aper_size = pci_resource_len(intel_i830_private.i830_dev, 2) / MB(1);
752 811
753 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes); 812 for (i = 0; i < num_sizes; i++) {
813 if (aper_size == intel_i830_sizes[i].size) {
814 agp_bridge->current_size = intel_i830_sizes + i;
815 agp_bridge->previous_size = agp_bridge->current_size;
816 return aper_size;
817 }
818 }
754 819
755 pci_read_config_dword(intel_i830_private.i830_dev, I915_GMADDR, &temp); 820 return 0;
756 if (temp & I915_256MB_ADDRESS_MASK)
757 offset = 0; /* 128MB aperture */
758 else
759 offset = 2; /* 256MB aperture */
760 agp_bridge->previous_size = agp_bridge->current_size = (void *)(values + offset);
761 return values[offset].size;
762} 821}
763 822
764/* The intel i915 automatically initializes the agp aperture during POST. 823/* The intel i915 automatically initializes the agp aperture during POST.
@@ -821,40 +880,9 @@ static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
821 return addr | bridge->driver->masks[type].mask; 880 return addr | bridge->driver->masks[type].mask;
822} 881}
823 882
824static int intel_i965_fetch_size(void)
825{
826 struct aper_size_info_fixed *values;
827 u32 offset = 0;
828 u8 temp;
829
830#define I965_512MB_ADDRESS_MASK (3<<1)
831
832 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
833
834 pci_read_config_byte(intel_i830_private.i830_dev, I965_MSAC, &temp);
835 temp &= I965_512MB_ADDRESS_MASK;
836 switch (temp) {
837 case 0x00:
838 offset = 0; /* 128MB */
839 break;
840 case 0x06:
841 offset = 3; /* 512MB */
842 break;
843 default:
844 case 0x02:
845 offset = 2; /* 256MB */
846 break;
847 }
848
849 agp_bridge->previous_size = agp_bridge->current_size = (void *)(values + offset);
850
851 /* The i965 GTT is always sized as if it had a 512kB aperture size */
852 return 512;
853}
854
855/* The intel i965 automatically initializes the agp aperture during POST. 883/* The intel i965 automatically initializes the agp aperture during POST.
856+ * Use the memory already set aside for in the GTT. 884 * Use the memory already set aside for in the GTT.
857+ */ 885 */
858static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge) 886static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
859{ 887{
860 int page_order; 888 int page_order;
@@ -1574,7 +1602,7 @@ static struct agp_bridge_driver intel_915_driver = {
1574 .num_aperture_sizes = 4, 1602 .num_aperture_sizes = 4,
1575 .needs_scratch_page = TRUE, 1603 .needs_scratch_page = TRUE,
1576 .configure = intel_i915_configure, 1604 .configure = intel_i915_configure,
1577 .fetch_size = intel_i915_fetch_size, 1605 .fetch_size = intel_i9xx_fetch_size,
1578 .cleanup = intel_i915_cleanup, 1606 .cleanup = intel_i915_cleanup,
1579 .tlb_flush = intel_i810_tlbflush, 1607 .tlb_flush = intel_i810_tlbflush,
1580 .mask_memory = intel_i810_mask_memory, 1608 .mask_memory = intel_i810_mask_memory,
@@ -1598,7 +1626,7 @@ static struct agp_bridge_driver intel_i965_driver = {
1598 .num_aperture_sizes = 4, 1626 .num_aperture_sizes = 4,
1599 .needs_scratch_page = TRUE, 1627 .needs_scratch_page = TRUE,
1600 .configure = intel_i915_configure, 1628 .configure = intel_i915_configure,
1601 .fetch_size = intel_i965_fetch_size, 1629 .fetch_size = intel_i9xx_fetch_size,
1602 .cleanup = intel_i915_cleanup, 1630 .cleanup = intel_i915_cleanup,
1603 .tlb_flush = intel_i810_tlbflush, 1631 .tlb_flush = intel_i810_tlbflush,
1604 .mask_memory = intel_i965_mask_memory, 1632 .mask_memory = intel_i965_mask_memory,
@@ -1927,6 +1955,15 @@ static int agp_intel_resume(struct pci_dev *pdev)
1927 1955
1928 pci_restore_state(pdev); 1956 pci_restore_state(pdev);
1929 1957
1958 /* We should restore our graphics device's config space,
1959 * as host bridge (00:00) resumes before graphics device (02:00),
1960 * then our access to its pci space can work right.
1961 */
1962 if (intel_i810_private.i810_dev)
1963 pci_restore_state(intel_i810_private.i810_dev);
1964 if (intel_i830_private.i830_dev)
1965 pci_restore_state(intel_i830_private.i830_dev);
1966
1930 if (bridge->driver == &intel_generic_driver) 1967 if (bridge->driver == &intel_generic_driver)
1931 intel_configure(); 1968 intel_configure();
1932 else if (bridge->driver == &intel_850_driver) 1969 else if (bridge->driver == &intel_850_driver)
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index d73be4c2db..902648db7e 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -281,10 +281,11 @@ static int __devinit agp_sgi_init(void)
281 else 281 else
282 return 0; 282 return 0;
283 283
284 sgi_tioca_agp_bridges = 284 sgi_tioca_agp_bridges = kmalloc(tioca_gart_found *
285 (struct agp_bridge_data **)kmalloc(tioca_gart_found * 285 sizeof(struct agp_bridge_data *),
286 sizeof(struct agp_bridge_data *), 286 GFP_KERNEL);
287 GFP_KERNEL); 287 if (!sgi_tioca_agp_bridges)
288 return -ENOMEM;
288 289
289 j = 0; 290 j = 0;
290 list_for_each_entry(info, &tioca_list, ca_list) { 291 list_for_each_entry(info, &tioca_list, ca_list) {
diff --git a/drivers/char/agp/via-agp.c b/drivers/char/agp/via-agp.c
index c149ac9ce9..2ded7a280d 100644
--- a/drivers/char/agp/via-agp.c
+++ b/drivers/char/agp/via-agp.c
@@ -380,9 +380,23 @@ static struct agp_device_ids via_agp_device_ids[] __devinitdata =
380 /* P4M800CE */ 380 /* P4M800CE */
381 { 381 {
382 .device_id = PCI_DEVICE_ID_VIA_P4M800CE, 382 .device_id = PCI_DEVICE_ID_VIA_P4M800CE,
383 .chipset_name = "P4M800CE", 383 .chipset_name = "VT3314",
384 },
385 /* CX700 */
386 {
387 .device_id = PCI_DEVICE_ID_VIA_CX700,
388 .chipset_name = "CX700",
389 },
390 /* VT3336 */
391 {
392 .device_id = PCI_DEVICE_ID_VIA_VT3336,
393 .chipset_name = "VT3336",
394 },
395 /* P4M890 */
396 {
397 .device_id = PCI_DEVICE_ID_VIA_P4M890,
398 .chipset_name = "P4M890",
384 }, 399 },
385
386 { }, /* dummy final entry, always present */ 400 { }, /* dummy final entry, always present */
387}; 401};
388 402
@@ -524,6 +538,9 @@ static const struct pci_device_id agp_via_pci_table[] = {
524 ID(PCI_DEVICE_ID_VIA_83_87XX_1), 538 ID(PCI_DEVICE_ID_VIA_83_87XX_1),
525 ID(PCI_DEVICE_ID_VIA_3296_0), 539 ID(PCI_DEVICE_ID_VIA_3296_0),
526 ID(PCI_DEVICE_ID_VIA_P4M800CE), 540 ID(PCI_DEVICE_ID_VIA_P4M800CE),
541 ID(PCI_DEVICE_ID_VIA_CX700),
542 ID(PCI_DEVICE_ID_VIA_VT3336),
543 ID(PCI_DEVICE_ID_VIA_P4M890),
527 { } 544 { }
528}; 545};
529 546
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
index 0bbb04f239..6dcdceb812 100644
--- a/drivers/char/drm/drmP.h
+++ b/drivers/char/drm/drmP.h
@@ -561,8 +561,7 @@ struct drm_driver {
561 int (*context_dtor) (struct drm_device * dev, int context); 561 int (*context_dtor) (struct drm_device * dev, int context);
562 int (*kernel_context_switch) (struct drm_device * dev, int old, 562 int (*kernel_context_switch) (struct drm_device * dev, int old,
563 int new); 563 int new);
564 void (*kernel_context_switch_unlock) (struct drm_device * dev, 564 void (*kernel_context_switch_unlock) (struct drm_device * dev);
565 drm_lock_t *lock);
566 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence); 565 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
567 int (*vblank_wait2) (struct drm_device * dev, unsigned int *sequence); 566 int (*vblank_wait2) (struct drm_device * dev, unsigned int *sequence);
568 int (*dri_library_name) (struct drm_device *dev, char *buf); 567 int (*dri_library_name) (struct drm_device *dev, char *buf);
@@ -1143,9 +1142,5 @@ extern void *drm_calloc(size_t nmemb, size_t size, int area);
1143extern unsigned long drm_core_get_map_ofs(drm_map_t * map); 1142extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
1144extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev); 1143extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
1145 1144
1146#ifndef pci_pretty_name
1147#define pci_pretty_name(dev) ""
1148#endif
1149
1150#endif /* __KERNEL__ */ 1145#endif /* __KERNEL__ */
1151#endif 1146#endif
diff --git a/drivers/char/drm/drm_lock.c b/drivers/char/drm/drm_lock.c
index 116ed0f2ac..e9993ba461 100644
--- a/drivers/char/drm/drm_lock.c
+++ b/drivers/char/drm/drm_lock.c
@@ -182,7 +182,7 @@ int drm_unlock(struct inode *inode, struct file *filp,
182 * modules but is required by the Sparc driver. 182 * modules but is required by the Sparc driver.
183 */ 183 */
184 if (dev->driver->kernel_context_switch_unlock) 184 if (dev->driver->kernel_context_switch_unlock)
185 dev->driver->kernel_context_switch_unlock(dev, &lock); 185 dev->driver->kernel_context_switch_unlock(dev);
186 else { 186 else {
187 drm_lock_transfer(dev, &dev->lock.hw_lock->lock, 187 drm_lock_transfer(dev, &dev->lock.hw_lock->lock,
188 DRM_KERNEL_CONTEXT); 188 DRM_KERNEL_CONTEXT);
diff --git a/drivers/char/drm/drm_stub.c b/drivers/char/drm/drm_stub.c
index 5fd6dc0870..120d10256f 100644
--- a/drivers/char/drm/drm_stub.c
+++ b/drivers/char/drm/drm_stub.c
@@ -211,14 +211,16 @@ int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
211 if (!dev) 211 if (!dev)
212 return -ENOMEM; 212 return -ENOMEM;
213 213
214 pci_enable_device(pdev); 214 ret = pci_enable_device(pdev);
215 if (ret)
216 goto err_g1;
215 217
216 if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) { 218 if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
217 printk(KERN_ERR "DRM: Fill_in_dev failed.\n"); 219 printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
218 goto err_g1; 220 goto err_g2;
219 } 221 }
220 if ((ret = drm_get_head(dev, &dev->primary))) 222 if ((ret = drm_get_head(dev, &dev->primary)))
221 goto err_g1; 223 goto err_g2;
222 224
223 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", 225 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
224 driver->name, driver->major, driver->minor, driver->patchlevel, 226 driver->name, driver->major, driver->minor, driver->patchlevel,
@@ -226,7 +228,9 @@ int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
226 228
227 return 0; 229 return 0;
228 230
229 err_g1: 231err_g2:
232 pci_disable_device(pdev);
233err_g1:
230 drm_free(dev, sizeof(*dev), DRM_MEM_STUB); 234 drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
231 return ret; 235 return ret;
232} 236}
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
index ba4b8de83c..cc8e2ebe12 100644
--- a/drivers/char/drm/drm_sysfs.c
+++ b/drivers/char/drm/drm_sysfs.c
@@ -45,8 +45,8 @@ struct class *drm_sysfs_create(struct module *owner, char *name)
45 int err; 45 int err;
46 46
47 class = class_create(owner, name); 47 class = class_create(owner, name);
48 if (!class) { 48 if (IS_ERR(class)) {
49 err = -ENOMEM; 49 err = PTR_ERR(class);
50 goto err_out; 50 goto err_out;
51 } 51 }
52 52
@@ -113,8 +113,8 @@ struct class_device *drm_sysfs_device_add(struct class *cs, drm_head_t *head)
113 MKDEV(DRM_MAJOR, head->minor), 113 MKDEV(DRM_MAJOR, head->minor),
114 &(head->dev->pdev)->dev, 114 &(head->dev->pdev)->dev,
115 "card%d", head->minor); 115 "card%d", head->minor);
116 if (!class_dev) { 116 if (IS_ERR(class_dev)) {
117 err = -ENOMEM; 117 err = PTR_ERR(class_dev);
118 goto err_out; 118 goto err_out;
119 } 119 }
120 120
diff --git a/drivers/char/drm/i915_irq.c b/drivers/char/drm/i915_irq.c
index e5463b111f..78c1ae28f1 100644
--- a/drivers/char/drm/i915_irq.c
+++ b/drivers/char/drm/i915_irq.c
@@ -46,88 +46,167 @@ static void i915_vblank_tasklet(drm_device_t *dev)
46{ 46{
47 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 47 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
48 unsigned long irqflags; 48 unsigned long irqflags;
49 struct list_head *list, *tmp; 49 struct list_head *list, *tmp, hits, *hit;
50 int nhits, nrects, slice[2], upper[2], lower[2], i;
51 unsigned counter[2] = { atomic_read(&dev->vbl_received),
52 atomic_read(&dev->vbl_received2) };
53 drm_drawable_info_t *drw;
54 drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv;
55 u32 cpp = dev_priv->cpp;
56 u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
57 XY_SRC_COPY_BLT_WRITE_ALPHA |
58 XY_SRC_COPY_BLT_WRITE_RGB)
59 : XY_SRC_COPY_BLT_CMD;
60 u32 pitchropcpp = (sarea_priv->pitch * cpp) | (0xcc << 16) |
61 (cpp << 23) | (1 << 24);
62 RING_LOCALS;
50 63
51 DRM_DEBUG("\n"); 64 DRM_DEBUG("\n");
52 65
66 INIT_LIST_HEAD(&hits);
67
68 nhits = nrects = 0;
69
53 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags); 70 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
54 71
72 /* Find buffer swaps scheduled for this vertical blank */
55 list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) { 73 list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) {
56 drm_i915_vbl_swap_t *vbl_swap = 74 drm_i915_vbl_swap_t *vbl_swap =
57 list_entry(list, drm_i915_vbl_swap_t, head); 75 list_entry(list, drm_i915_vbl_swap_t, head);
58 atomic_t *counter = vbl_swap->pipe ? &dev->vbl_received2 :
59 &dev->vbl_received;
60
61 if ((atomic_read(counter) - vbl_swap->sequence) <= (1<<23)) {
62 drm_drawable_info_t *drw;
63
64 spin_unlock(&dev_priv->swaps_lock);
65
66 spin_lock(&dev->drw_lock);
67
68 drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
69
70 if (drw) {
71 int i, num_rects = drw->num_rects;
72 drm_clip_rect_t *rect = drw->rects;
73 drm_i915_sarea_t *sarea_priv =
74 dev_priv->sarea_priv;
75 u32 cpp = dev_priv->cpp;
76 u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
77 XY_SRC_COPY_BLT_WRITE_ALPHA |
78 XY_SRC_COPY_BLT_WRITE_RGB)
79 : XY_SRC_COPY_BLT_CMD;
80 u32 pitchropcpp = (sarea_priv->pitch * cpp) |
81 (0xcc << 16) | (cpp << 23) |
82 (1 << 24);
83 RING_LOCALS;
84
85 i915_kernel_lost_context(dev);
86
87 BEGIN_LP_RING(6);
88
89 OUT_RING(GFX_OP_DRAWRECT_INFO);
90 OUT_RING(0);
91 OUT_RING(0);
92 OUT_RING(sarea_priv->width |
93 sarea_priv->height << 16);
94 OUT_RING(sarea_priv->width |
95 sarea_priv->height << 16);
96 OUT_RING(0);
97 76
98 ADVANCE_LP_RING(); 77 if ((counter[vbl_swap->pipe] - vbl_swap->sequence) > (1<<23))
78 continue;
79
80 list_del(list);
81 dev_priv->swaps_pending--;
99 82
100 sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT; 83 spin_unlock(&dev_priv->swaps_lock);
84 spin_lock(&dev->drw_lock);
101 85
102 for (i = 0; i < num_rects; i++, rect++) { 86 drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
103 BEGIN_LP_RING(8); 87
88 if (!drw) {
89 spin_unlock(&dev->drw_lock);
90 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
91 spin_lock(&dev_priv->swaps_lock);
92 continue;
93 }
104 94
105 OUT_RING(cmd); 95 list_for_each(hit, &hits) {
106 OUT_RING(pitchropcpp); 96 drm_i915_vbl_swap_t *swap_cmp =
107 OUT_RING((rect->y1 << 16) | rect->x1); 97 list_entry(hit, drm_i915_vbl_swap_t, head);
108 OUT_RING((rect->y2 << 16) | rect->x2); 98 drm_drawable_info_t *drw_cmp =
109 OUT_RING(sarea_priv->front_offset); 99 drm_get_drawable_info(dev, swap_cmp->drw_id);
110 OUT_RING((rect->y1 << 16) | rect->x1);
111 OUT_RING(pitchropcpp & 0xffff);
112 OUT_RING(sarea_priv->back_offset);
113 100
114 ADVANCE_LP_RING(); 101 if (drw_cmp &&
115 } 102 drw_cmp->rects[0].y1 > drw->rects[0].y1) {
103 list_add_tail(list, hit);
104 break;
116 } 105 }
106 }
117 107
118 spin_unlock(&dev->drw_lock); 108 spin_unlock(&dev->drw_lock);
119 109
120 spin_lock(&dev_priv->swaps_lock); 110 /* List of hits was empty, or we reached the end of it */
111 if (hit == &hits)
112 list_add_tail(list, hits.prev);
121 113
122 list_del(list); 114 nhits++;
123 115
124 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER); 116 spin_lock(&dev_priv->swaps_lock);
117 }
118
119 if (nhits == 0) {
120 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
121 return;
122 }
123
124 spin_unlock(&dev_priv->swaps_lock);
125 125
126 dev_priv->swaps_pending--; 126 i915_kernel_lost_context(dev);
127
128 BEGIN_LP_RING(6);
129
130 OUT_RING(GFX_OP_DRAWRECT_INFO);
131 OUT_RING(0);
132 OUT_RING(0);
133 OUT_RING(sarea_priv->width | sarea_priv->height << 16);
134 OUT_RING(sarea_priv->width | sarea_priv->height << 16);
135 OUT_RING(0);
136
137 ADVANCE_LP_RING();
138
139 sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT;
140
141 upper[0] = upper[1] = 0;
142 slice[0] = max(sarea_priv->pipeA_h / nhits, 1);
143 slice[1] = max(sarea_priv->pipeB_h / nhits, 1);
144 lower[0] = sarea_priv->pipeA_y + slice[0];
145 lower[1] = sarea_priv->pipeB_y + slice[0];
146
147 spin_lock(&dev->drw_lock);
148
149 /* Emit blits for buffer swaps, partitioning both outputs into as many
150 * slices as there are buffer swaps scheduled in order to avoid tearing
151 * (based on the assumption that a single buffer swap would always
152 * complete before scanout starts).
153 */
154 for (i = 0; i++ < nhits;
155 upper[0] = lower[0], lower[0] += slice[0],
156 upper[1] = lower[1], lower[1] += slice[1]) {
157 if (i == nhits)
158 lower[0] = lower[1] = sarea_priv->height;
159
160 list_for_each(hit, &hits) {
161 drm_i915_vbl_swap_t *swap_hit =
162 list_entry(hit, drm_i915_vbl_swap_t, head);
163 drm_clip_rect_t *rect;
164 int num_rects, pipe;
165 unsigned short top, bottom;
166
167 drw = drm_get_drawable_info(dev, swap_hit->drw_id);
168
169 if (!drw)
170 continue;
171
172 rect = drw->rects;
173 pipe = swap_hit->pipe;
174 top = upper[pipe];
175 bottom = lower[pipe];
176
177 for (num_rects = drw->num_rects; num_rects--; rect++) {
178 int y1 = max(rect->y1, top);
179 int y2 = min(rect->y2, bottom);
180
181 if (y1 >= y2)
182 continue;
183
184 BEGIN_LP_RING(8);
185
186 OUT_RING(cmd);
187 OUT_RING(pitchropcpp);
188 OUT_RING((y1 << 16) | rect->x1);
189 OUT_RING((y2 << 16) | rect->x2);
190 OUT_RING(sarea_priv->front_offset);
191 OUT_RING((y1 << 16) | rect->x1);
192 OUT_RING(pitchropcpp & 0xffff);
193 OUT_RING(sarea_priv->back_offset);
194
195 ADVANCE_LP_RING();
196 }
127 } 197 }
128 } 198 }
129 199
130 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags); 200 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
201
202 list_for_each_safe(hit, tmp, &hits) {
203 drm_i915_vbl_swap_t *swap_hit =
204 list_entry(hit, drm_i915_vbl_swap_t, head);
205
206 list_del(hit);
207
208 drm_free(swap_hit, sizeof(*swap_hit), DRM_MEM_DRIVER);
209 }
131} 210}
132 211
133irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) 212irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
@@ -421,7 +500,7 @@ int i915_vblank_swap(DRM_IOCTL_ARGS)
421 500
422 if (!drm_get_drawable_info(dev, swap.drawable)) { 501 if (!drm_get_drawable_info(dev, swap.drawable)) {
423 spin_unlock_irqrestore(&dev->drw_lock, irqflags); 502 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
424 DRM_ERROR("Invalid drawable ID %d\n", swap.drawable); 503 DRM_DEBUG("Invalid drawable ID %d\n", swap.drawable);
425 return DRM_ERR(EINVAL); 504 return DRM_ERR(EINVAL);
426 } 505 }
427 506
diff --git a/drivers/char/drm/r128_drm.h b/drivers/char/drm/r128_drm.h
index 5d835b006f..6e8af313f2 100644
--- a/drivers/char/drm/r128_drm.h
+++ b/drivers/char/drm/r128_drm.h
@@ -1,7 +1,8 @@
1/* r128_drm.h -- Public header for the r128 driver -*- linux-c -*- 1/* r128_drm.h -- Public header for the r128 driver -*- linux-c -*-
2 * Created: Wed Apr 5 19:24:19 2000 by kevin@precisioninsight.com 2 * Created: Wed Apr 5 19:24:19 2000 by kevin@precisioninsight.com
3 */ 3 */
4/* Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. 4/*
5 * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All rights reserved. 7 * All rights reserved.
7 * 8 *
diff --git a/drivers/char/drm/r128_drv.h b/drivers/char/drm/r128_drv.h
index 94abffb2cc..f1efb49de8 100644
--- a/drivers/char/drm/r128_drv.h
+++ b/drivers/char/drm/r128_drv.h
@@ -1,7 +1,8 @@
1/* r128_drv.h -- Private header for r128 driver -*- linux-c -*- 1/* r128_drv.h -- Private header for r128 driver -*- linux-c -*-
2 * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com 2 * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com
3 */ 3 */
4/* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 4/*
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All rights reserved. 7 * All rights reserved.
7 * 8 *
diff --git a/drivers/char/drm/r128_state.c b/drivers/char/drm/r128_state.c
index a080cdd608..17b11e7d8f 100644
--- a/drivers/char/drm/r128_state.c
+++ b/drivers/char/drm/r128_state.c
@@ -1,7 +1,8 @@
1/* r128_state.c -- State support for r128 -*- linux-c -*- 1/* r128_state.c -- State support for r128 -*- linux-c -*-
2 * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com 2 * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com
3 */ 3 */
4/* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 4/*
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
5 * All Rights Reserved. 6 * All Rights Reserved.
6 * 7 *
7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * Permission is hereby granted, free of charge, to any person obtaining a
diff --git a/drivers/char/drm/r300_cmdbuf.c b/drivers/char/drm/r300_cmdbuf.c
index d14477ba36..032a022ec6 100644
--- a/drivers/char/drm/r300_cmdbuf.c
+++ b/drivers/char/drm/r300_cmdbuf.c
@@ -242,26 +242,6 @@ static __inline__ int r300_check_range(unsigned reg, int count)
242 return 0; 242 return 0;
243} 243}
244 244
245/*
246 * we expect offsets passed to the framebuffer to be either within video
247 * memory or within AGP space
248 */
249static __inline__ int r300_check_offset(drm_radeon_private_t *dev_priv,
250 u32 offset)
251{
252 /* we realy want to check against end of video aperture
253 but this value is not being kept.
254 This code is correct for now (does the same thing as the
255 code that sets MC_FB_LOCATION) in radeon_cp.c */
256 if (offset >= dev_priv->fb_location &&
257 offset < (dev_priv->fb_location + dev_priv->fb_size))
258 return 0;
259 if (offset >= dev_priv->gart_vm_start &&
260 offset < (dev_priv->gart_vm_start + dev_priv->gart_size))
261 return 0;
262 return 1;
263}
264
265static __inline__ int r300_emit_carefully_checked_packet0(drm_radeon_private_t * 245static __inline__ int r300_emit_carefully_checked_packet0(drm_radeon_private_t *
266 dev_priv, 246 dev_priv,
267 drm_radeon_kcmd_buffer_t 247 drm_radeon_kcmd_buffer_t
@@ -290,7 +270,7 @@ static __inline__ int r300_emit_carefully_checked_packet0(drm_radeon_private_t *
290 case MARK_SAFE: 270 case MARK_SAFE:
291 break; 271 break;
292 case MARK_CHECK_OFFSET: 272 case MARK_CHECK_OFFSET:
293 if (r300_check_offset(dev_priv, (u32) values[i])) { 273 if (!radeon_check_offset(dev_priv, (u32) values[i])) {
294 DRM_ERROR 274 DRM_ERROR
295 ("Offset failed range check (reg=%04x sz=%d)\n", 275 ("Offset failed range check (reg=%04x sz=%d)\n",
296 reg, sz); 276 reg, sz);
@@ -452,7 +432,7 @@ static __inline__ int r300_emit_3d_load_vbpntr(drm_radeon_private_t *dev_priv,
452 i = 1; 432 i = 1;
453 while ((k < narrays) && (i < (count + 1))) { 433 while ((k < narrays) && (i < (count + 1))) {
454 i++; /* skip attribute field */ 434 i++; /* skip attribute field */
455 if (r300_check_offset(dev_priv, payload[i])) { 435 if (!radeon_check_offset(dev_priv, payload[i])) {
456 DRM_ERROR 436 DRM_ERROR
457 ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n", 437 ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n",
458 k, i); 438 k, i);
@@ -463,7 +443,7 @@ static __inline__ int r300_emit_3d_load_vbpntr(drm_radeon_private_t *dev_priv,
463 if (k == narrays) 443 if (k == narrays)
464 break; 444 break;
465 /* have one more to process, they come in pairs */ 445 /* have one more to process, they come in pairs */
466 if (r300_check_offset(dev_priv, payload[i])) { 446 if (!radeon_check_offset(dev_priv, payload[i])) {
467 DRM_ERROR 447 DRM_ERROR
468 ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n", 448 ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n",
469 k, i); 449 k, i);
@@ -508,7 +488,7 @@ static __inline__ int r300_emit_bitblt_multi(drm_radeon_private_t *dev_priv,
508 if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL 488 if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL
509 | RADEON_GMC_DST_PITCH_OFFSET_CNTL)) { 489 | RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
510 offset = cmd[2] << 10; 490 offset = cmd[2] << 10;
511 ret = r300_check_offset(dev_priv, offset); 491 ret = !radeon_check_offset(dev_priv, offset);
512 if (ret) { 492 if (ret) {
513 DRM_ERROR("Invalid bitblt first offset is %08X\n", offset); 493 DRM_ERROR("Invalid bitblt first offset is %08X\n", offset);
514 return DRM_ERR(EINVAL); 494 return DRM_ERR(EINVAL);
@@ -518,7 +498,7 @@ static __inline__ int r300_emit_bitblt_multi(drm_radeon_private_t *dev_priv,
518 if ((cmd[1] & RADEON_GMC_SRC_PITCH_OFFSET_CNTL) && 498 if ((cmd[1] & RADEON_GMC_SRC_PITCH_OFFSET_CNTL) &&
519 (cmd[1] & RADEON_GMC_DST_PITCH_OFFSET_CNTL)) { 499 (cmd[1] & RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
520 offset = cmd[3] << 10; 500 offset = cmd[3] << 10;
521 ret = r300_check_offset(dev_priv, offset); 501 ret = !radeon_check_offset(dev_priv, offset);
522 if (ret) { 502 if (ret) {
523 DRM_ERROR("Invalid bitblt second offset is %08X\n", offset); 503 DRM_ERROR("Invalid bitblt second offset is %08X\n", offset);
524 return DRM_ERR(EINVAL); 504 return DRM_ERR(EINVAL);
@@ -551,7 +531,7 @@ static __inline__ int r300_emit_indx_buffer(drm_radeon_private_t *dev_priv,
551 DRM_ERROR("Invalid indx_buffer reg address %08X\n", cmd[1]); 531 DRM_ERROR("Invalid indx_buffer reg address %08X\n", cmd[1]);
552 return DRM_ERR(EINVAL); 532 return DRM_ERR(EINVAL);
553 } 533 }
554 ret = r300_check_offset(dev_priv, cmd[2]); 534 ret = !radeon_check_offset(dev_priv, cmd[2]);
555 if (ret) { 535 if (ret) {
556 DRM_ERROR("Invalid indx_buffer offset is %08X\n", cmd[2]); 536 DRM_ERROR("Invalid indx_buffer offset is %08X\n", cmd[2]);
557 return DRM_ERR(EINVAL); 537 return DRM_ERR(EINVAL);
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h
index f45cd7f147..8b105f1460 100644
--- a/drivers/char/drm/radeon_drv.h
+++ b/drivers/char/drm/radeon_drv.h
@@ -303,6 +303,21 @@ extern int radeon_no_wb;
303extern drm_ioctl_desc_t radeon_ioctls[]; 303extern drm_ioctl_desc_t radeon_ioctls[];
304extern int radeon_max_ioctl; 304extern int radeon_max_ioctl;
305 305
306/* Check whether the given hardware address is inside the framebuffer or the
307 * GART area.
308 */
309static __inline__ int radeon_check_offset(drm_radeon_private_t *dev_priv,
310 u64 off)
311{
312 u32 fb_start = dev_priv->fb_location;
313 u32 fb_end = fb_start + dev_priv->fb_size - 1;
314 u32 gart_start = dev_priv->gart_vm_start;
315 u32 gart_end = gart_start + dev_priv->gart_size - 1;
316
317 return ((off >= fb_start && off <= fb_end) ||
318 (off >= gart_start && off <= gart_end));
319}
320
306 /* radeon_cp.c */ 321 /* radeon_cp.c */
307extern int radeon_cp_init(DRM_IOCTL_ARGS); 322extern int radeon_cp_init(DRM_IOCTL_ARGS);
308extern int radeon_cp_start(DRM_IOCTL_ARGS); 323extern int radeon_cp_start(DRM_IOCTL_ARGS);
diff --git a/drivers/char/drm/radeon_irq.c b/drivers/char/drm/radeon_irq.c
index d60519de88..3ff0baa2fb 100644
--- a/drivers/char/drm/radeon_irq.c
+++ b/drivers/char/drm/radeon_irq.c
@@ -1,5 +1,5 @@
1/* radeon_irq.c -- IRQ handling for radeon -*- linux-c -*- 1/* radeon_irq.c -- IRQ handling for radeon -*- linux-c -*- */
2 * 2/*
3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 * 4 *
5 * The Weather Channel (TM) funded Tungsten Graphics to develop the 5 * The Weather Channel (TM) funded Tungsten Graphics to develop the
diff --git a/drivers/char/drm/radeon_mem.c b/drivers/char/drm/radeon_mem.c
index 030a6fad0d..517cad8b6e 100644
--- a/drivers/char/drm/radeon_mem.c
+++ b/drivers/char/drm/radeon_mem.c
@@ -1,5 +1,5 @@
1/* radeon_mem.c -- Simple GART/fb memory manager for radeon -*- linux-c -*- 1/* radeon_mem.c -- Simple GART/fb memory manager for radeon -*- linux-c -*- */
2 * 2/*
3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 * 4 *
5 * The Weather Channel (TM) funded Tungsten Graphics to develop the 5 * The Weather Channel (TM) funded Tungsten Graphics to develop the
diff --git a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c
index 6e04fdd732..938eccb78c 100644
--- a/drivers/char/drm/radeon_state.c
+++ b/drivers/char/drm/radeon_state.c
@@ -43,10 +43,7 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
43 u32 *offset) 43 u32 *offset)
44{ 44{
45 u64 off = *offset; 45 u64 off = *offset;
46 u32 fb_start = dev_priv->fb_location; 46 u32 fb_end = dev_priv->fb_location + dev_priv->fb_size - 1;
47 u32 fb_end = fb_start + dev_priv->fb_size - 1;
48 u32 gart_start = dev_priv->gart_vm_start;
49 u32 gart_end = gart_start + dev_priv->gart_size - 1;
50 struct drm_radeon_driver_file_fields *radeon_priv; 47 struct drm_radeon_driver_file_fields *radeon_priv;
51 48
52 /* Hrm ... the story of the offset ... So this function converts 49 /* Hrm ... the story of the offset ... So this function converts
@@ -66,8 +63,7 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
66 /* First, the best case, the offset already lands in either the 63 /* First, the best case, the offset already lands in either the
67 * framebuffer or the GART mapped space 64 * framebuffer or the GART mapped space
68 */ 65 */
69 if ((off >= fb_start && off <= fb_end) || 66 if (radeon_check_offset(dev_priv, off))
70 (off >= gart_start && off <= gart_end))
71 return 0; 67 return 0;
72 68
73 /* Ok, that didn't happen... now check if we have a zero based 69 /* Ok, that didn't happen... now check if we have a zero based
@@ -81,11 +77,10 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
81 77
82 /* Finally, assume we aimed at a GART offset if beyond the fb */ 78 /* Finally, assume we aimed at a GART offset if beyond the fb */
83 if (off > fb_end) 79 if (off > fb_end)
84 off = off - fb_end - 1 + gart_start; 80 off = off - fb_end - 1 + dev_priv->gart_vm_start;
85 81
86 /* Now recheck and fail if out of bounds */ 82 /* Now recheck and fail if out of bounds */
87 if ((off >= fb_start && off <= fb_end) || 83 if (radeon_check_offset(dev_priv, off)) {
88 (off >= gart_start && off <= gart_end)) {
89 DRM_DEBUG("offset fixed up to 0x%x\n", (unsigned int)off); 84 DRM_DEBUG("offset fixed up to 0x%x\n", (unsigned int)off);
90 *offset = off; 85 *offset = off;
91 return 0; 86 return 0;
diff --git a/drivers/char/drm/savage_bci.c b/drivers/char/drm/savage_bci.c
index a9a84f88df..b94fab5568 100644
--- a/drivers/char/drm/savage_bci.c
+++ b/drivers/char/drm/savage_bci.c
@@ -963,8 +963,8 @@ static int savage_bci_event_emit(DRM_IOCTL_ARGS)
963 963
964 event.count = savage_bci_emit_event(dev_priv, event.flags); 964 event.count = savage_bci_emit_event(dev_priv, event.flags);
965 event.count |= dev_priv->event_wrap << 16; 965 event.count |= dev_priv->event_wrap << 16;
966 DRM_COPY_TO_USER_IOCTL(&((drm_savage_event_emit_t __user *) data)-> 966 DRM_COPY_TO_USER_IOCTL((drm_savage_event_emit_t __user *) data,
967 count, event.count, sizeof(event.count)); 967 event, sizeof(event));
968 return 0; 968 return 0;
969} 969}
970 970
diff --git a/drivers/char/hw_random/amd-rng.c b/drivers/char/hw_random/amd-rng.c
index 71e4e0f3fd..556fd81fa8 100644
--- a/drivers/char/hw_random/amd-rng.c
+++ b/drivers/char/hw_random/amd-rng.c
@@ -144,7 +144,7 @@ static void __exit mod_exit(void)
144 hwrng_unregister(&amd_rng); 144 hwrng_unregister(&amd_rng);
145} 145}
146 146
147subsys_initcall(mod_init); 147module_init(mod_init);
148module_exit(mod_exit); 148module_exit(mod_exit);
149 149
150MODULE_AUTHOR("The Linux Kernel team"); 150MODULE_AUTHOR("The Linux Kernel team");
diff --git a/drivers/char/hw_random/geode-rng.c b/drivers/char/hw_random/geode-rng.c
index d37ced0d13..8e8658dcd2 100644
--- a/drivers/char/hw_random/geode-rng.c
+++ b/drivers/char/hw_random/geode-rng.c
@@ -125,7 +125,7 @@ static void __exit mod_exit(void)
125 iounmap(mem); 125 iounmap(mem);
126} 126}
127 127
128subsys_initcall(mod_init); 128module_init(mod_init);
129module_exit(mod_exit); 129module_exit(mod_exit);
130 130
131MODULE_DESCRIPTION("H/W RNG driver for AMD Geode LX CPUs"); 131MODULE_DESCRIPTION("H/W RNG driver for AMD Geode LX CPUs");
diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index 8efbc9c0e5..f22e78e3c7 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -143,6 +143,11 @@ static const struct pci_device_id pci_tbl[] = {
143}; 143};
144MODULE_DEVICE_TABLE(pci, pci_tbl); 144MODULE_DEVICE_TABLE(pci, pci_tbl);
145 145
146static __initdata int no_fwh_detect;
147module_param(no_fwh_detect, int, 0);
148MODULE_PARM_DESC(no_fwh_detect, "Skip FWH detection:\n"
149 " positive value - skip if FWH space locked read-only\n"
150 " negative value - skip always");
146 151
147static inline u8 hwstatus_get(void __iomem *mem) 152static inline u8 hwstatus_get(void __iomem *mem)
148{ 153{
@@ -240,6 +245,11 @@ static int __init mod_init(void)
240 if (!dev) 245 if (!dev)
241 goto out; /* Device not found. */ 246 goto out; /* Device not found. */
242 247
248 if (no_fwh_detect < 0) {
249 pci_dev_put(dev);
250 goto fwh_done;
251 }
252
243 /* Check for Intel 82802 */ 253 /* Check for Intel 82802 */
244 if (dev->device < 0x2640) { 254 if (dev->device < 0x2640) {
245 fwh_dec_en1_off = FWH_DEC_EN1_REG_OLD; 255 fwh_dec_en1_off = FWH_DEC_EN1_REG_OLD;
@@ -252,6 +262,23 @@ static int __init mod_init(void)
252 pci_read_config_byte(dev, fwh_dec_en1_off, &fwh_dec_en1_val); 262 pci_read_config_byte(dev, fwh_dec_en1_off, &fwh_dec_en1_val);
253 pci_read_config_byte(dev, bios_cntl_off, &bios_cntl_val); 263 pci_read_config_byte(dev, bios_cntl_off, &bios_cntl_val);
254 264
265 if ((bios_cntl_val &
266 (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK))
267 == BIOS_CNTL_LOCK_ENABLE_MASK) {
268 static __initdata /*const*/ char warning[] =
269 KERN_WARNING PFX "Firmware space is locked read-only. If you can't or\n"
270 KERN_WARNING PFX "don't want to disable this in firmware setup, and if\n"
271 KERN_WARNING PFX "you are certain that your system has a functional\n"
272 KERN_WARNING PFX "RNG, try using the 'no_fwh_detect' option.\n";
273
274 pci_dev_put(dev);
275 if (no_fwh_detect)
276 goto fwh_done;
277 printk(warning);
278 err = -EBUSY;
279 goto out;
280 }
281
255 mem = ioremap_nocache(INTEL_FWH_ADDR, INTEL_FWH_ADDR_LEN); 282 mem = ioremap_nocache(INTEL_FWH_ADDR, INTEL_FWH_ADDR_LEN);
256 if (mem == NULL) { 283 if (mem == NULL) {
257 pci_dev_put(dev); 284 pci_dev_put(dev);
@@ -280,8 +307,7 @@ static int __init mod_init(void)
280 pci_write_config_byte(dev, 307 pci_write_config_byte(dev,
281 fwh_dec_en1_off, 308 fwh_dec_en1_off,
282 fwh_dec_en1_val | FWH_F8_EN_MASK); 309 fwh_dec_en1_val | FWH_F8_EN_MASK);
283 if (!(bios_cntl_val & 310 if (!(bios_cntl_val & BIOS_CNTL_WRITE_ENABLE_MASK))
284 (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK)))
285 pci_write_config_byte(dev, 311 pci_write_config_byte(dev,
286 bios_cntl_off, 312 bios_cntl_off,
287 bios_cntl_val | BIOS_CNTL_WRITE_ENABLE_MASK); 313 bios_cntl_val | BIOS_CNTL_WRITE_ENABLE_MASK);
@@ -315,6 +341,8 @@ static int __init mod_init(void)
315 goto out; 341 goto out;
316 } 342 }
317 343
344fwh_done:
345
318 err = -ENOMEM; 346 err = -ENOMEM;
319 mem = ioremap(INTEL_RNG_ADDR, INTEL_RNG_ADDR_LEN); 347 mem = ioremap(INTEL_RNG_ADDR, INTEL_RNG_ADDR_LEN);
320 if (!mem) 348 if (!mem)
@@ -350,7 +378,7 @@ static void __exit mod_exit(void)
350 iounmap(mem); 378 iounmap(mem);
351} 379}
352 380
353subsys_initcall(mod_init); 381module_init(mod_init);
354module_exit(mod_exit); 382module_exit(mod_exit);
355 383
356MODULE_DESCRIPTION("H/W RNG driver for Intel chipsets"); 384MODULE_DESCRIPTION("H/W RNG driver for Intel chipsets");
diff --git a/drivers/char/hw_random/ixp4xx-rng.c b/drivers/char/hw_random/ixp4xx-rng.c
index c9caff57db..bab43ca32a 100644
--- a/drivers/char/hw_random/ixp4xx-rng.c
+++ b/drivers/char/hw_random/ixp4xx-rng.c
@@ -64,7 +64,7 @@ static void __exit ixp4xx_rng_exit(void)
64 iounmap(rng_base); 64 iounmap(rng_base);
65} 65}
66 66
67subsys_initcall(ixp4xx_rng_init); 67module_init(ixp4xx_rng_init);
68module_exit(ixp4xx_rng_exit); 68module_exit(ixp4xx_rng_exit);
69 69
70MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>"); 70MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 0e786b617b..9ebf84d186 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -176,7 +176,7 @@ static void __exit mod_exit(void)
176 hwrng_unregister(&via_rng); 176 hwrng_unregister(&via_rng);
177} 177}
178 178
179subsys_initcall(mod_init); 179module_init(mod_init);
180module_exit(mod_exit); 180module_exit(mod_exit);
181 181
182MODULE_DESCRIPTION("H/W RNG driver for VIA chipsets"); 182MODULE_DESCRIPTION("H/W RNG driver for VIA chipsets");
diff --git a/drivers/char/ip2/i2ellis.h b/drivers/char/ip2/i2ellis.h
index 5eabe47b0b..433305062f 100644
--- a/drivers/char/ip2/i2ellis.h
+++ b/drivers/char/ip2/i2ellis.h
@@ -606,9 +606,9 @@ static int iiDownloadAll(i2eBordStrPtr, loadHdrStrPtr, int, int);
606// code and returning. 606// code and returning.
607// 607//
608#define COMPLETE(pB,code) \ 608#define COMPLETE(pB,code) \
609 if(1){ \ 609 do { \
610 pB->i2eError = code; \ 610 pB->i2eError = code; \
611 return (code == I2EE_GOOD);\ 611 return (code == I2EE_GOOD);\
612 } 612 } while (0)
613 613
614#endif // I2ELLIS_H 614#endif // I2ELLIS_H
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 4e4691a538..53582b53da 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -3649,8 +3649,6 @@ static void ipmi_timeout_handler(long timeout_period)
3649 unsigned long flags; 3649 unsigned long flags;
3650 int i; 3650 int i;
3651 3651
3652 INIT_LIST_HEAD(&timeouts);
3653
3654 rcu_read_lock(); 3652 rcu_read_lock();
3655 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { 3653 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3656 /* See if any waiting messages need to be processed. */ 3654 /* See if any waiting messages need to be processed. */
@@ -3671,6 +3669,7 @@ static void ipmi_timeout_handler(long timeout_period)
3671 /* Go through the seq table and find any messages that 3669 /* Go through the seq table and find any messages that
3672 have timed out, putting them in the timeouts 3670 have timed out, putting them in the timeouts
3673 list. */ 3671 list. */
3672 INIT_LIST_HEAD(&timeouts);
3674 spin_lock_irqsave(&intf->seq_lock, flags); 3673 spin_lock_irqsave(&intf->seq_lock, flags);
3675 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) 3674 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++)
3676 check_msg_timeout(intf, &(intf->seq_table[i]), 3675 check_msg_timeout(intf, &(intf->seq_table[i]),
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index f1afd26a50..a7b33d2f59 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -1802,7 +1802,7 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
1802 return -ENODEV; 1802 return -ENODEV;
1803 } 1803 }
1804 1804
1805 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) 1805 if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
1806 addr_space = IPMI_MEM_ADDR_SPACE; 1806 addr_space = IPMI_MEM_ADDR_SPACE;
1807 else 1807 else
1808 addr_space = IPMI_IO_ADDR_SPACE; 1808 addr_space = IPMI_IO_ADDR_SPACE;
@@ -1848,19 +1848,19 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
1848 info->irq_setup = NULL; 1848 info->irq_setup = NULL;
1849 } 1849 }
1850 1850
1851 if (spmi->addr.register_bit_width) { 1851 if (spmi->addr.bit_width) {
1852 /* A (hopefully) properly formed register bit width. */ 1852 /* A (hopefully) properly formed register bit width. */
1853 info->io.regspacing = spmi->addr.register_bit_width / 8; 1853 info->io.regspacing = spmi->addr.bit_width / 8;
1854 } else { 1854 } else {
1855 info->io.regspacing = DEFAULT_REGSPACING; 1855 info->io.regspacing = DEFAULT_REGSPACING;
1856 } 1856 }
1857 info->io.regsize = info->io.regspacing; 1857 info->io.regsize = info->io.regspacing;
1858 info->io.regshift = spmi->addr.register_bit_offset; 1858 info->io.regshift = spmi->addr.bit_offset;
1859 1859
1860 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 1860 if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
1861 info->io_setup = mem_setup; 1861 info->io_setup = mem_setup;
1862 info->io.addr_type = IPMI_IO_ADDR_SPACE; 1862 info->io.addr_type = IPMI_IO_ADDR_SPACE;
1863 } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) { 1863 } else if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
1864 info->io_setup = port_setup; 1864 info->io_setup = port_setup;
1865 info->io.addr_type = IPMI_MEM_ADDR_SPACE; 1865 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
1866 } else { 1866 } else {
@@ -1888,10 +1888,8 @@ static __devinit void acpi_find_bmc(void)
1888 return; 1888 return;
1889 1889
1890 for (i = 0; ; i++) { 1890 for (i = 0; ; i++) {
1891 status = acpi_get_firmware_table("SPMI", i+1, 1891 status = acpi_get_table(ACPI_SIG_SPMI, i+1,
1892 ACPI_LOGICAL_ADDRESSING, 1892 (struct acpi_table_header **)&spmi);
1893 (struct acpi_table_header **)
1894 &spmi);
1895 if (status != AE_OK) 1893 if (status != AE_OK)
1896 return; 1894 return;
1897 1895
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 78280380a9..6b634e8d95 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -216,13 +216,13 @@ static int set_param_str(const char *val, struct kernel_param *kp)
216{ 216{
217 action_fn fn = (action_fn) kp->arg; 217 action_fn fn = (action_fn) kp->arg;
218 int rv = 0; 218 int rv = 0;
219 char *dup, *s; 219 char valcp[16];
220 char *s;
220 221
221 dup = kstrdup(val, GFP_KERNEL); 222 strncpy(valcp, val, 16);
222 if (!dup) 223 valcp[15] = '\0';
223 return -ENOMEM;
224 224
225 s = strstrip(dup); 225 s = strstrip(valcp);
226 226
227 down_read(&register_sem); 227 down_read(&register_sem);
228 rv = fn(s, NULL); 228 rv = fn(s, NULL);
@@ -235,7 +235,6 @@ static int set_param_str(const char *val, struct kernel_param *kp)
235 235
236 out_unlock: 236 out_unlock:
237 up_read(&register_sem); 237 up_read(&register_sem);
238 kfree(dup);
239 return rv; 238 return rv;
240} 239}
241 240
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 5a747e6859..01084abffd 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -230,6 +230,20 @@ static struct isi_port isi_ports[PORT_COUNT];
230 * it wants to talk. 230 * it wants to talk.
231 */ 231 */
232 232
233static inline int WaitTillCardIsFree(u16 base)
234{
235 unsigned int count = 0;
236 unsigned int a = in_atomic(); /* do we run under spinlock? */
237
238 while (!(inw(base + 0xe) & 0x1) && count++ < 100)
239 if (a)
240 mdelay(1);
241 else
242 msleep(1);
243
244 return !(inw(base + 0xe) & 0x1);
245}
246
233static int lock_card(struct isi_board *card) 247static int lock_card(struct isi_board *card)
234{ 248{
235 char retries; 249 char retries;
@@ -276,69 +290,71 @@ static void unlock_card(struct isi_board *card)
276 * ISI Card specific ops ... 290 * ISI Card specific ops ...
277 */ 291 */
278 292
293/* card->lock HAS to be held */
279static void raise_dtr(struct isi_port *port) 294static void raise_dtr(struct isi_port *port)
280{ 295{
281 struct isi_board *card = port->card; 296 struct isi_board *card = port->card;
282 unsigned long base = card->base; 297 unsigned long base = card->base;
283 u16 channel = port->channel; 298 u16 channel = port->channel;
284 299
285 if (!lock_card(card)) 300 if (WaitTillCardIsFree(base))
286 return; 301 return;
287 302
288 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 303 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
289 outw(0x0504, base); 304 outw(0x0504, base);
290 InterruptTheCard(base); 305 InterruptTheCard(base);
291 port->status |= ISI_DTR; 306 port->status |= ISI_DTR;
292 unlock_card(card);
293} 307}
294 308
309/* card->lock HAS to be held */
295static inline void drop_dtr(struct isi_port *port) 310static inline void drop_dtr(struct isi_port *port)
296{ 311{
297 struct isi_board *card = port->card; 312 struct isi_board *card = port->card;
298 unsigned long base = card->base; 313 unsigned long base = card->base;
299 u16 channel = port->channel; 314 u16 channel = port->channel;
300 315
301 if (!lock_card(card)) 316 if (WaitTillCardIsFree(base))
302 return; 317 return;
303 318
304 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 319 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
305 outw(0x0404, base); 320 outw(0x0404, base);
306 InterruptTheCard(base); 321 InterruptTheCard(base);
307 port->status &= ~ISI_DTR; 322 port->status &= ~ISI_DTR;
308 unlock_card(card);
309} 323}
310 324
325/* card->lock HAS to be held */
311static inline void raise_rts(struct isi_port *port) 326static inline void raise_rts(struct isi_port *port)
312{ 327{
313 struct isi_board *card = port->card; 328 struct isi_board *card = port->card;
314 unsigned long base = card->base; 329 unsigned long base = card->base;
315 u16 channel = port->channel; 330 u16 channel = port->channel;
316 331
317 if (!lock_card(card)) 332 if (WaitTillCardIsFree(base))
318 return; 333 return;
319 334
320 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 335 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
321 outw(0x0a04, base); 336 outw(0x0a04, base);
322 InterruptTheCard(base); 337 InterruptTheCard(base);
323 port->status |= ISI_RTS; 338 port->status |= ISI_RTS;
324 unlock_card(card);
325} 339}
340
341/* card->lock HAS to be held */
326static inline void drop_rts(struct isi_port *port) 342static inline void drop_rts(struct isi_port *port)
327{ 343{
328 struct isi_board *card = port->card; 344 struct isi_board *card = port->card;
329 unsigned long base = card->base; 345 unsigned long base = card->base;
330 u16 channel = port->channel; 346 u16 channel = port->channel;
331 347
332 if (!lock_card(card)) 348 if (WaitTillCardIsFree(base))
333 return; 349 return;
334 350
335 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 351 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
336 outw(0x0804, base); 352 outw(0x0804, base);
337 InterruptTheCard(base); 353 InterruptTheCard(base);
338 port->status &= ~ISI_RTS; 354 port->status &= ~ISI_RTS;
339 unlock_card(card);
340} 355}
341 356
357/* card->lock MUST NOT be held */
342static inline void raise_dtr_rts(struct isi_port *port) 358static inline void raise_dtr_rts(struct isi_port *port)
343{ 359{
344 struct isi_board *card = port->card; 360 struct isi_board *card = port->card;
@@ -355,35 +371,20 @@ static inline void raise_dtr_rts(struct isi_port *port)
355 unlock_card(card); 371 unlock_card(card);
356} 372}
357 373
374/* card->lock HAS to be held */
358static void drop_dtr_rts(struct isi_port *port) 375static void drop_dtr_rts(struct isi_port *port)
359{ 376{
360 struct isi_board *card = port->card; 377 struct isi_board *card = port->card;
361 unsigned long base = card->base; 378 unsigned long base = card->base;
362 u16 channel = port->channel; 379 u16 channel = port->channel;
363 380
364 if (!lock_card(card)) 381 if (WaitTillCardIsFree(base))
365 return; 382 return;
366 383
367 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 384 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
368 outw(0x0c04, base); 385 outw(0x0c04, base);
369 InterruptTheCard(base); 386 InterruptTheCard(base);
370 port->status &= ~(ISI_RTS | ISI_DTR); 387 port->status &= ~(ISI_RTS | ISI_DTR);
371 unlock_card(card);
372}
373
374static inline void kill_queue(struct isi_port *port, short queue)
375{
376 struct isi_board *card = port->card;
377 unsigned long base = card->base;
378 u16 channel = port->channel;
379
380 if (!lock_card(card))
381 return;
382
383 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
384 outw((queue << 8) | 0x06, base);
385 InterruptTheCard(base);
386 unlock_card(card);
387} 388}
388 389
389/* 390/*
@@ -744,7 +745,7 @@ static void isicom_config_port(struct isi_port *port)
744 else 745 else
745 raise_dtr(port); 746 raise_dtr(port);
746 747
747 if (lock_card(card)) { 748 if (WaitTillCardIsFree(base) == 0) {
748 outw(0x8000 | (channel << shift_count) |0x03, base); 749 outw(0x8000 | (channel << shift_count) |0x03, base);
749 outw(linuxb_to_isib[baud] << 8 | 0x03, base); 750 outw(linuxb_to_isib[baud] << 8 | 0x03, base);
750 channel_setup = 0; 751 channel_setup = 0;
@@ -772,7 +773,6 @@ static void isicom_config_port(struct isi_port *port)
772 } 773 }
773 outw(channel_setup, base); 774 outw(channel_setup, base);
774 InterruptTheCard(base); 775 InterruptTheCard(base);
775 unlock_card(card);
776 } 776 }
777 if (C_CLOCAL(tty)) 777 if (C_CLOCAL(tty))
778 port->flags &= ~ASYNC_CHECK_CD; 778 port->flags &= ~ASYNC_CHECK_CD;
@@ -791,12 +791,11 @@ static void isicom_config_port(struct isi_port *port)
791 if (I_IXOFF(tty)) 791 if (I_IXOFF(tty))
792 flow_ctrl |= ISICOM_INITIATE_XONXOFF; 792 flow_ctrl |= ISICOM_INITIATE_XONXOFF;
793 793
794 if (lock_card(card)) { 794 if (WaitTillCardIsFree(base) == 0) {
795 outw(0x8000 | (channel << shift_count) |0x04, base); 795 outw(0x8000 | (channel << shift_count) |0x04, base);
796 outw(flow_ctrl << 8 | 0x05, base); 796 outw(flow_ctrl << 8 | 0x05, base);
797 outw((STOP_CHAR(tty)) << 8 | (START_CHAR(tty)), base); 797 outw((STOP_CHAR(tty)) << 8 | (START_CHAR(tty)), base);
798 InterruptTheCard(base); 798 InterruptTheCard(base);
799 unlock_card(card);
800 } 799 }
801 800
802 /* rx enabled -> enable port for rx on the card */ 801 /* rx enabled -> enable port for rx on the card */
@@ -821,10 +820,9 @@ static inline void isicom_setup_board(struct isi_board *bp)
821 } 820 }
822 port = bp->ports; 821 port = bp->ports;
823 bp->status |= BOARD_ACTIVE; 822 bp->status |= BOARD_ACTIVE;
824 spin_unlock_irqrestore(&bp->card_lock, flags);
825 for (channel = 0; channel < bp->port_count; channel++, port++) 823 for (channel = 0; channel < bp->port_count; channel++, port++)
826 drop_dtr_rts(port); 824 drop_dtr_rts(port);
827 return; 825 spin_unlock_irqrestore(&bp->card_lock, flags);
828} 826}
829 827
830static int isicom_setup_port(struct isi_port *port) 828static int isicom_setup_port(struct isi_port *port)
@@ -857,7 +855,12 @@ static int isicom_setup_port(struct isi_port *port)
857 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; 855 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
858 856
859 /* discard any residual data */ 857 /* discard any residual data */
860 kill_queue(port, ISICOM_KILLTX | ISICOM_KILLRX); 858 if (WaitTillCardIsFree(card->base) == 0) {
859 outw(0x8000 | (port->channel << card->shift_count) | 0x02,
860 card->base);
861 outw(((ISICOM_KILLTX | ISICOM_KILLRX) << 8) | 0x06, card->base);
862 InterruptTheCard(card->base);
863 }
861 864
862 isicom_config_port(port); 865 isicom_config_port(port);
863 port->flags |= ASYNC_INITIALIZED; 866 port->flags |= ASYNC_INITIALIZED;
@@ -983,28 +986,22 @@ static int isicom_open(struct tty_struct *tty, struct file *filp)
983 986
984static inline void isicom_shutdown_board(struct isi_board *bp) 987static inline void isicom_shutdown_board(struct isi_board *bp)
985{ 988{
986 unsigned long flags;
987
988 spin_lock_irqsave(&bp->card_lock, flags);
989 if (bp->status & BOARD_ACTIVE) { 989 if (bp->status & BOARD_ACTIVE) {
990 bp->status &= ~BOARD_ACTIVE; 990 bp->status &= ~BOARD_ACTIVE;
991 } 991 }
992 spin_unlock_irqrestore(&bp->card_lock, flags);
993} 992}
994 993
994/* card->lock HAS to be held */
995static void isicom_shutdown_port(struct isi_port *port) 995static void isicom_shutdown_port(struct isi_port *port)
996{ 996{
997 struct isi_board *card = port->card; 997 struct isi_board *card = port->card;
998 struct tty_struct *tty; 998 struct tty_struct *tty;
999 unsigned long flags;
1000 999
1001 tty = port->tty; 1000 tty = port->tty;
1002 1001
1003 spin_lock_irqsave(&card->card_lock, flags); 1002 if (!(port->flags & ASYNC_INITIALIZED))
1004 if (!(port->flags & ASYNC_INITIALIZED)) {
1005 spin_unlock_irqrestore(&card->card_lock, flags);
1006 return; 1003 return;
1007 } 1004
1008 if (port->xmit_buf) { 1005 if (port->xmit_buf) {
1009 free_page((unsigned long) port->xmit_buf); 1006 free_page((unsigned long) port->xmit_buf);
1010 port->xmit_buf = NULL; 1007 port->xmit_buf = NULL;
@@ -1012,7 +1009,6 @@ static void isicom_shutdown_port(struct isi_port *port)
1012 port->flags &= ~ASYNC_INITIALIZED; 1009 port->flags &= ~ASYNC_INITIALIZED;
1013 /* 3rd October 2000 : Vinayak P Risbud */ 1010 /* 3rd October 2000 : Vinayak P Risbud */
1014 port->tty = NULL; 1011 port->tty = NULL;
1015 spin_unlock_irqrestore(&card->card_lock, flags);
1016 1012
1017 /*Fix done by Anil .S on 30-04-2001 1013 /*Fix done by Anil .S on 30-04-2001
1018 remote login through isi port has dtr toggle problem 1014 remote login through isi port has dtr toggle problem
@@ -1258,10 +1254,12 @@ static int isicom_tiocmset(struct tty_struct *tty, struct file *file,
1258 unsigned int set, unsigned int clear) 1254 unsigned int set, unsigned int clear)
1259{ 1255{
1260 struct isi_port *port = tty->driver_data; 1256 struct isi_port *port = tty->driver_data;
1257 unsigned long flags;
1261 1258
1262 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) 1259 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
1263 return -ENODEV; 1260 return -ENODEV;
1264 1261
1262 spin_lock_irqsave(&port->card->card_lock, flags);
1265 if (set & TIOCM_RTS) 1263 if (set & TIOCM_RTS)
1266 raise_rts(port); 1264 raise_rts(port);
1267 if (set & TIOCM_DTR) 1265 if (set & TIOCM_DTR)
@@ -1271,6 +1269,7 @@ static int isicom_tiocmset(struct tty_struct *tty, struct file *file,
1271 drop_rts(port); 1269 drop_rts(port);
1272 if (clear & TIOCM_DTR) 1270 if (clear & TIOCM_DTR)
1273 drop_dtr(port); 1271 drop_dtr(port);
1272 spin_unlock_irqrestore(&port->card->card_lock, flags);
1274 1273
1275 return 0; 1274 return 0;
1276} 1275}
@@ -1303,7 +1302,10 @@ static int isicom_set_serial_info(struct isi_port *port,
1303 (newinfo.flags & ASYNC_FLAGS)); 1302 (newinfo.flags & ASYNC_FLAGS));
1304 } 1303 }
1305 if (reconfig_port) { 1304 if (reconfig_port) {
1305 unsigned long flags;
1306 spin_lock_irqsave(&port->card->card_lock, flags);
1306 isicom_config_port(port); 1307 isicom_config_port(port);
1308 spin_unlock_irqrestore(&port->card->card_lock, flags);
1307 } 1309 }
1308 return 0; 1310 return 0;
1309} 1311}
@@ -1384,6 +1386,7 @@ static void isicom_set_termios(struct tty_struct *tty,
1384 struct ktermios *old_termios) 1386 struct ktermios *old_termios)
1385{ 1387{
1386 struct isi_port *port = tty->driver_data; 1388 struct isi_port *port = tty->driver_data;
1389 unsigned long flags;
1387 1390
1388 if (isicom_paranoia_check(port, tty->name, "isicom_set_termios")) 1391 if (isicom_paranoia_check(port, tty->name, "isicom_set_termios"))
1389 return; 1392 return;
@@ -1392,7 +1395,9 @@ static void isicom_set_termios(struct tty_struct *tty,
1392 tty->termios->c_iflag == old_termios->c_iflag) 1395 tty->termios->c_iflag == old_termios->c_iflag)
1393 return; 1396 return;
1394 1397
1398 spin_lock_irqsave(&port->card->card_lock, flags);
1395 isicom_config_port(port); 1399 isicom_config_port(port);
1400 spin_unlock_irqrestore(&port->card->card_lock, flags);
1396 1401
1397 if ((old_termios->c_cflag & CRTSCTS) && 1402 if ((old_termios->c_cflag & CRTSCTS) &&
1398 !(tty->termios->c_cflag & CRTSCTS)) { 1403 !(tty->termios->c_cflag & CRTSCTS)) {
@@ -1469,11 +1474,15 @@ static void do_isicom_hangup(struct work_struct *work)
1469static void isicom_hangup(struct tty_struct *tty) 1474static void isicom_hangup(struct tty_struct *tty)
1470{ 1475{
1471 struct isi_port *port = tty->driver_data; 1476 struct isi_port *port = tty->driver_data;
1477 unsigned long flags;
1472 1478
1473 if (isicom_paranoia_check(port, tty->name, "isicom_hangup")) 1479 if (isicom_paranoia_check(port, tty->name, "isicom_hangup"))
1474 return; 1480 return;
1475 1481
1482 spin_lock_irqsave(&port->card->card_lock, flags);
1476 isicom_shutdown_port(port); 1483 isicom_shutdown_port(port);
1484 spin_unlock_irqrestore(&port->card->card_lock, flags);
1485
1477 port->count = 0; 1486 port->count = 0;
1478 port->flags &= ~ASYNC_NORMAL_ACTIVE; 1487 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1479 port->tty = NULL; 1488 port->tty = NULL;
@@ -1578,16 +1587,6 @@ end:
1578 return retval; 1587 return retval;
1579} 1588}
1580 1589
1581static inline int WaitTillCardIsFree(u16 base)
1582{
1583 unsigned long count = 0;
1584
1585 while (!(inw(base + 0xe) & 0x1) && count++ < 100)
1586 msleep(5);
1587
1588 return !(inw(base + 0xe) & 0x1);
1589}
1590
1591static int __devinit load_firmware(struct pci_dev *pdev, 1590static int __devinit load_firmware(struct pci_dev *pdev,
1592 const unsigned int index, const unsigned int signature) 1591 const unsigned int index, const unsigned int signature)
1593{ 1592{
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 4f1813e047..f5c160caf9 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -293,8 +293,8 @@ static int mmap_kmem(struct file * file, struct vm_area_struct * vma)
293{ 293{
294 unsigned long pfn; 294 unsigned long pfn;
295 295
296 /* Turn a pfn offset into an absolute pfn */ 296 /* Turn a kernel-virtual address into a physical page frame */
297 pfn = PFN_DOWN(virt_to_phys((void *)PAGE_OFFSET)) + vma->vm_pgoff; 297 pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT;
298 298
299 /* 299 /*
300 * RED-PEN: on some architectures there is more mapped memory 300 * RED-PEN: on some architectures there is more mapped memory
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index c063359baf..83f604b192 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -717,6 +717,7 @@ static int mxser_init(void)
717 717
718 /* Initialize the tty_driver structure */ 718 /* Initialize the tty_driver structure */
719 memset(mxvar_sdriver, 0, sizeof(struct tty_driver)); 719 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
720 mxvar_sdriver->owner = THIS_MODULE;
720 mxvar_sdriver->magic = TTY_DRIVER_MAGIC; 721 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
721 mxvar_sdriver->name = "ttyMI"; 722 mxvar_sdriver->name = "ttyMI";
722 mxvar_sdriver->major = ttymajor; 723 mxvar_sdriver->major = ttymajor;
diff --git a/drivers/char/mxser_new.c b/drivers/char/mxser_new.c
index cd989dce7c..1bb030b3a5 100644
--- a/drivers/char/mxser_new.c
+++ b/drivers/char/mxser_new.c
@@ -2690,6 +2690,7 @@ static int __init mxser_module_init(void)
2690 MXSER_VERSION); 2690 MXSER_VERSION);
2691 2691
2692 /* Initialize the tty_driver structure */ 2692 /* Initialize the tty_driver structure */
2693 mxvar_sdriver->owner = THIS_MODULE;
2693 mxvar_sdriver->magic = TTY_DRIVER_MAGIC; 2694 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
2694 mxvar_sdriver->name = "ttyMI"; 2695 mxvar_sdriver->name = "ttyMI";
2695 mxvar_sdriver->major = ttymajor; 2696 mxvar_sdriver->major = ttymajor;
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index e1d70e8b62..664f36c98e 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -113,7 +113,12 @@ static int rtc_has_irq = 1;
113#define hpet_set_rtc_irq_bit(arg) 0 113#define hpet_set_rtc_irq_bit(arg) 0
114#define hpet_rtc_timer_init() do { } while (0) 114#define hpet_rtc_timer_init() do { } while (0)
115#define hpet_rtc_dropped_irq() 0 115#define hpet_rtc_dropped_irq() 0
116static irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id) {return 0;} 116#ifdef RTC_IRQ
117static irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id)
118{
119 return 0;
120}
121#endif
117#else 122#else
118extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id); 123extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id);
119#endif 124#endif
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index 13935235e0..7fd3cd5ddf 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -215,7 +215,7 @@ static void sysrq_handle_showstate_blocked(int key, struct tty_struct *tty)
215} 215}
216static struct sysrq_key_op sysrq_showstate_blocked_op = { 216static struct sysrq_key_op sysrq_showstate_blocked_op = {
217 .handler = sysrq_handle_showstate_blocked, 217 .handler = sysrq_handle_showstate_blocked,
218 .help_msg = "showBlockedTasks", 218 .help_msg = "shoW-blocked-tasks",
219 .action_msg = "Show Blocked State", 219 .action_msg = "Show Blocked State",
220 .enable_mask = SYSRQ_ENABLE_DUMP, 220 .enable_mask = SYSRQ_ENABLE_DUMP,
221}; 221};
@@ -315,15 +315,16 @@ static struct sysrq_key_op *sysrq_key_table[36] = {
315 &sysrq_loglevel_op, /* 9 */ 315 &sysrq_loglevel_op, /* 9 */
316 316
317 /* 317 /*
318 * Don't use for system provided sysrqs, it is handled specially on 318 * a: Don't use for system provided sysrqs, it is handled specially on
319 * sparc and will never arrive 319 * sparc and will never arrive.
320 */ 320 */
321 NULL, /* a */ 321 NULL, /* a */
322 &sysrq_reboot_op, /* b */ 322 &sysrq_reboot_op, /* b */
323 &sysrq_crashdump_op, /* c */ 323 &sysrq_crashdump_op, /* c & ibm_emac driver debug */
324 &sysrq_showlocks_op, /* d */ 324 &sysrq_showlocks_op, /* d */
325 &sysrq_term_op, /* e */ 325 &sysrq_term_op, /* e */
326 &sysrq_moom_op, /* f */ 326 &sysrq_moom_op, /* f */
327 /* g: May be registered by ppc for kgdb */
327 NULL, /* g */ 328 NULL, /* g */
328 NULL, /* h */ 329 NULL, /* h */
329 &sysrq_kill_op, /* i */ 330 &sysrq_kill_op, /* i */
@@ -332,18 +333,19 @@ static struct sysrq_key_op *sysrq_key_table[36] = {
332 NULL, /* l */ 333 NULL, /* l */
333 &sysrq_showmem_op, /* m */ 334 &sysrq_showmem_op, /* m */
334 &sysrq_unrt_op, /* n */ 335 &sysrq_unrt_op, /* n */
335 /* This will often be registered as 'Off' at init time */ 336 /* o: This will often be registered as 'Off' at init time */
336 NULL, /* o */ 337 NULL, /* o */
337 &sysrq_showregs_op, /* p */ 338 &sysrq_showregs_op, /* p */
338 NULL, /* q */ 339 NULL, /* q */
339 &sysrq_unraw_op, /* r */ 340 &sysrq_unraw_op, /* r */
340 &sysrq_sync_op, /* s */ 341 &sysrq_sync_op, /* s */
341 &sysrq_showstate_op, /* t */ 342 &sysrq_showstate_op, /* t */
342 &sysrq_mountro_op, /* u */ 343 &sysrq_mountro_op, /* u */
343 /* May be assigned at init time by SMP VOYAGER */ 344 /* v: May be registered at init time by SMP VOYAGER */
344 NULL, /* v */ 345 NULL, /* v */
345 NULL, /* w */ 346 &sysrq_showstate_blocked_op, /* w */
346 &sysrq_showstate_blocked_op, /* x */ 347 /* x: May be registered on ppc/powerpc for xmon */
348 NULL, /* x */
347 NULL, /* y */ 349 NULL, /* y */
348 NULL /* z */ 350 NULL /* z */
349}; 351};
diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c
index 244d30a03f..4fac2bdf62 100644
--- a/drivers/char/tlclk.c
+++ b/drivers/char/tlclk.c
@@ -186,6 +186,7 @@ static int got_event; /* if events processing have been done */
186static void switchover_timeout(unsigned long data); 186static void switchover_timeout(unsigned long data);
187static struct timer_list switchover_timer = 187static struct timer_list switchover_timer =
188 TIMER_INITIALIZER(switchover_timeout , 0, 0); 188 TIMER_INITIALIZER(switchover_timeout , 0, 0);
189static unsigned long tlclk_timer_data;
189 190
190static struct tlclk_alarms *alarm_events; 191static struct tlclk_alarms *alarm_events;
191 192
@@ -197,10 +198,19 @@ static irqreturn_t tlclk_interrupt(int irq, void *dev_id);
197 198
198static DECLARE_WAIT_QUEUE_HEAD(wq); 199static DECLARE_WAIT_QUEUE_HEAD(wq);
199 200
201static unsigned long useflags;
202static DEFINE_MUTEX(tlclk_mutex);
203
200static int tlclk_open(struct inode *inode, struct file *filp) 204static int tlclk_open(struct inode *inode, struct file *filp)
201{ 205{
202 int result; 206 int result;
203 207
208 if (test_and_set_bit(0, &useflags))
209 return -EBUSY;
210 /* this legacy device is always one per system and it doesn't
211 * know how to handle multiple concurrent clients.
212 */
213
204 /* Make sure there is no interrupt pending while 214 /* Make sure there is no interrupt pending while
205 * initialising interrupt handler */ 215 * initialising interrupt handler */
206 inb(TLCLK_REG6); 216 inb(TLCLK_REG6);
@@ -221,6 +231,7 @@ static int tlclk_open(struct inode *inode, struct file *filp)
221static int tlclk_release(struct inode *inode, struct file *filp) 231static int tlclk_release(struct inode *inode, struct file *filp)
222{ 232{
223 free_irq(telclk_interrupt, tlclk_interrupt); 233 free_irq(telclk_interrupt, tlclk_interrupt);
234 clear_bit(0, &useflags);
224 235
225 return 0; 236 return 0;
226} 237}
@@ -230,26 +241,25 @@ static ssize_t tlclk_read(struct file *filp, char __user *buf, size_t count,
230{ 241{
231 if (count < sizeof(struct tlclk_alarms)) 242 if (count < sizeof(struct tlclk_alarms))
232 return -EIO; 243 return -EIO;
244 if (mutex_lock_interruptible(&tlclk_mutex))
245 return -EINTR;
246
233 247
234 wait_event_interruptible(wq, got_event); 248 wait_event_interruptible(wq, got_event);
235 if (copy_to_user(buf, alarm_events, sizeof(struct tlclk_alarms))) 249 if (copy_to_user(buf, alarm_events, sizeof(struct tlclk_alarms))) {
250 mutex_unlock(&tlclk_mutex);
236 return -EFAULT; 251 return -EFAULT;
252 }
237 253
238 memset(alarm_events, 0, sizeof(struct tlclk_alarms)); 254 memset(alarm_events, 0, sizeof(struct tlclk_alarms));
239 got_event = 0; 255 got_event = 0;
240 256
257 mutex_unlock(&tlclk_mutex);
241 return sizeof(struct tlclk_alarms); 258 return sizeof(struct tlclk_alarms);
242} 259}
243 260
244static ssize_t tlclk_write(struct file *filp, const char __user *buf, size_t count,
245 loff_t *f_pos)
246{
247 return 0;
248}
249
250static const struct file_operations tlclk_fops = { 261static const struct file_operations tlclk_fops = {
251 .read = tlclk_read, 262 .read = tlclk_read,
252 .write = tlclk_write,
253 .open = tlclk_open, 263 .open = tlclk_open,
254 .release = tlclk_release, 264 .release = tlclk_release,
255 265
@@ -540,7 +550,7 @@ static ssize_t store_select_amcb1_transmit_clock(struct device *d,
540 SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x7); 550 SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x7);
541 switch (val) { 551 switch (val) {
542 case CLK_8_592MHz: 552 case CLK_8_592MHz:
543 SET_PORT_BITS(TLCLK_REG0, 0xfc, 1); 553 SET_PORT_BITS(TLCLK_REG0, 0xfc, 2);
544 break; 554 break;
545 case CLK_11_184MHz: 555 case CLK_11_184MHz:
546 SET_PORT_BITS(TLCLK_REG0, 0xfc, 0); 556 SET_PORT_BITS(TLCLK_REG0, 0xfc, 0);
@@ -549,7 +559,7 @@ static ssize_t store_select_amcb1_transmit_clock(struct device *d,
549 SET_PORT_BITS(TLCLK_REG0, 0xfc, 3); 559 SET_PORT_BITS(TLCLK_REG0, 0xfc, 3);
550 break; 560 break;
551 case CLK_44_736MHz: 561 case CLK_44_736MHz:
552 SET_PORT_BITS(TLCLK_REG0, 0xfc, 2); 562 SET_PORT_BITS(TLCLK_REG0, 0xfc, 1);
553 break; 563 break;
554 } 564 }
555 } else 565 } else
@@ -807,8 +817,6 @@ static int __init tlclk_init(void)
807 &tlclk_attribute_group); 817 &tlclk_attribute_group);
808 if (ret) { 818 if (ret) {
809 printk(KERN_ERR "tlclk: failed to create sysfs device attributes.\n"); 819 printk(KERN_ERR "tlclk: failed to create sysfs device attributes.\n");
810 sysfs_remove_group(&tlclk_device->dev.kobj,
811 &tlclk_attribute_group);
812 goto out5; 820 goto out5;
813 } 821 }
814 822
@@ -841,11 +849,13 @@ static void __exit tlclk_cleanup(void)
841 849
842static void switchover_timeout(unsigned long data) 850static void switchover_timeout(unsigned long data)
843{ 851{
844 if ((data & 1)) { 852 unsigned long flags = *(unsigned long *) data;
845 if ((inb(TLCLK_REG1) & 0x08) != (data & 0x08)) 853
854 if ((flags & 1)) {
855 if ((inb(TLCLK_REG1) & 0x08) != (flags & 0x08))
846 alarm_events->switchover_primary++; 856 alarm_events->switchover_primary++;
847 } else { 857 } else {
848 if ((inb(TLCLK_REG1) & 0x08) != (data & 0x08)) 858 if ((inb(TLCLK_REG1) & 0x08) != (flags & 0x08))
849 alarm_events->switchover_secondary++; 859 alarm_events->switchover_secondary++;
850 } 860 }
851 861
@@ -903,8 +913,9 @@ static irqreturn_t tlclk_interrupt(int irq, void *dev_id)
903 913
904 /* TIMEOUT in ~10ms */ 914 /* TIMEOUT in ~10ms */
905 switchover_timer.expires = jiffies + msecs_to_jiffies(10); 915 switchover_timer.expires = jiffies + msecs_to_jiffies(10);
906 switchover_timer.data = inb(TLCLK_REG1); 916 tlclk_timer_data = inb(TLCLK_REG1);
907 add_timer(&switchover_timer); 917 switchover_timer.data = (unsigned long) &tlclk_timer_data;
918 mod_timer(&switchover_timer, switchover_timer.expires);
908 } else { 919 } else {
909 got_event = 1; 920 got_event = 1;
910 wake_up(&wq); 921 wake_up(&wq);
diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
index a611972024..7fca5f470b 100644
--- a/drivers/char/tpm/tpm_bios.c
+++ b/drivers/char/tpm/tpm_bios.c
@@ -372,10 +372,8 @@ static int read_log(struct tpm_bios_log *log)
372 } 372 }
373 373
374 /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */ 374 /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
375 status = acpi_get_firmware_table(ACPI_TCPA_SIG, 1, 375 status = acpi_get_table(ACPI_SIG_TCPA, 1,
376 ACPI_LOGICAL_ADDRESSING, 376 (struct acpi_table_header **)&buff);
377 (struct acpi_table_header **)
378 &buff);
379 377
380 if (ACPI_FAILURE(status)) { 378 if (ACPI_FAILURE(status)) {
381 printk(KERN_ERR "%s: ERROR - Could not get TCPA table\n", 379 printk(KERN_ERR "%s: ERROR - Could not get TCPA table\n",
@@ -409,7 +407,7 @@ static int read_log(struct tpm_bios_log *log)
409 407
410 log->bios_event_log_end = log->bios_event_log + len; 408 log->bios_event_log_end = log->bios_event_log + len;
411 409
412 acpi_os_map_memory(start, len, (void *) &virt); 410 virt = acpi_os_map_memory(start, len);
413 411
414 memcpy(log->bios_event_log, virt, len); 412 memcpy(log->bios_event_log, virt, len);
415 413
diff --git a/drivers/char/viocons.c b/drivers/char/viocons.c
index 0e0da443cb..8de6b95aeb 100644
--- a/drivers/char/viocons.c
+++ b/drivers/char/viocons.c
@@ -42,6 +42,7 @@
42#include <linux/tty_flip.h> 42#include <linux/tty_flip.h>
43#include <linux/sysrq.h> 43#include <linux/sysrq.h>
44 44
45#include <asm/firmware.h>
45#include <asm/iseries/vio.h> 46#include <asm/iseries/vio.h>
46#include <asm/iseries/hv_lp_event.h> 47#include <asm/iseries/hv_lp_event.h>
47#include <asm/iseries/hv_call_event.h> 48#include <asm/iseries/hv_call_event.h>
@@ -1060,6 +1061,9 @@ static int __init viocons_init2(void)
1060 atomic_t wait_flag; 1061 atomic_t wait_flag;
1061 int rc; 1062 int rc;
1062 1063
1064 if (!firmware_has_feature(FW_FEATURE_ISERIES))
1065 return -ENODEV;
1066
1063 /* +2 for fudge */ 1067 /* +2 for fudge */
1064 rc = viopath_open(HvLpConfig_getPrimaryLpIndex(), 1068 rc = viopath_open(HvLpConfig_getPrimaryLpIndex(),
1065 viomajorsubtype_chario, VIOCHAR_WINDOW + 2); 1069 viomajorsubtype_chario, VIOCHAR_WINDOW + 2);
@@ -1145,6 +1149,9 @@ static int __init viocons_init(void)
1145{ 1149{
1146 int i; 1150 int i;
1147 1151
1152 if (!firmware_has_feature(FW_FEATURE_ISERIES))
1153 return -ENODEV;
1154
1148 printk(VIOCONS_KERN_INFO "registering console\n"); 1155 printk(VIOCONS_KERN_INFO "registering console\n");
1149 for (i = 0; i < VTTY_PORTS; i++) { 1156 for (i = 0; i < VTTY_PORTS; i++) {
1150 port_info[i].lp = HvLpIndexInvalid; 1157 port_info[i].lp = HvLpIndexInvalid;
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index 94d79cb8ce..9438512b17 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -49,7 +49,7 @@
49 49
50#include <asm/uaccess.h> 50#include <asm/uaccess.h>
51#include <asm/ioctls.h> 51#include <asm/ioctls.h>
52 52#include <asm/firmware.h>
53#include <asm/vio.h> 53#include <asm/vio.h>
54#include <asm/iseries/vio.h> 54#include <asm/iseries/vio.h>
55#include <asm/iseries/hv_lp_event.h> 55#include <asm/iseries/hv_lp_event.h>
@@ -997,6 +997,9 @@ int __init viotap_init(void)
997 int ret; 997 int ret;
998 struct proc_dir_entry *e; 998 struct proc_dir_entry *e;
999 999
1000 if (!firmware_has_feature(FW_FEATURE_ISERIES))
1001 return -ENODEV;
1002
1000 op_struct_list = NULL; 1003 op_struct_list = NULL;
1001 if ((ret = add_op_structs(VIOTAPE_MAXREQ)) < 0) { 1004 if ((ret = add_op_structs(VIOTAPE_MAXREQ)) < 0) {
1002 printk(VIOTAPE_KERN_WARN "couldn't allocate op structs\n"); 1005 printk(VIOTAPE_KERN_WARN "couldn't allocate op structs\n");
diff --git a/drivers/char/vr41xx_giu.c b/drivers/char/vr41xx_giu.c
index a744dad9cf..0cea8d4907 100644
--- a/drivers/char/vr41xx_giu.c
+++ b/drivers/char/vr41xx_giu.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2002 MontaVista Software Inc. 4 * Copyright (C) 2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com> 5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
6 * Copyright (C) 2003-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 6 * Copyright (C) 2003-2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
7 * 7 *
8 * 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
9 * 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
@@ -125,30 +125,17 @@ static inline uint16_t giu_clear(uint16_t offset, uint16_t clear)
125 return data; 125 return data;
126} 126}
127 127
128static unsigned int startup_giuint_low_irq(unsigned int irq) 128static void ack_giuint_low(unsigned int irq)
129{ 129{
130 unsigned int pin; 130 giu_write(GIUINTSTATL, 1 << GPIO_PIN_OF_IRQ(irq));
131
132 pin = GPIO_PIN_OF_IRQ(irq);
133 giu_write(GIUINTSTATL, 1 << pin);
134 giu_set(GIUINTENL, 1 << pin);
135
136 return 0;
137} 131}
138 132
139static void shutdown_giuint_low_irq(unsigned int irq) 133static void mask_giuint_low(unsigned int irq)
140{ 134{
141 giu_clear(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq)); 135 giu_clear(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
142} 136}
143 137
144static void enable_giuint_low_irq(unsigned int irq) 138static void mask_ack_giuint_low(unsigned int irq)
145{
146 giu_set(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
147}
148
149#define disable_giuint_low_irq shutdown_giuint_low_irq
150
151static void ack_giuint_low_irq(unsigned int irq)
152{ 139{
153 unsigned int pin; 140 unsigned int pin;
154 141
@@ -157,46 +144,30 @@ static void ack_giuint_low_irq(unsigned int irq)
157 giu_write(GIUINTSTATL, 1 << pin); 144 giu_write(GIUINTSTATL, 1 << pin);
158} 145}
159 146
160static void end_giuint_low_irq(unsigned int irq) 147static void unmask_giuint_low(unsigned int irq)
161{ 148{
162 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) 149 giu_set(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
163 giu_set(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
164} 150}
165 151
166static struct hw_interrupt_type giuint_low_irq_type = { 152static struct irq_chip giuint_low_irq_chip = {
167 .typename = "GIUINTL", 153 .name = "GIUINTL",
168 .startup = startup_giuint_low_irq, 154 .ack = ack_giuint_low,
169 .shutdown = shutdown_giuint_low_irq, 155 .mask = mask_giuint_low,
170 .enable = enable_giuint_low_irq, 156 .mask_ack = mask_ack_giuint_low,
171 .disable = disable_giuint_low_irq, 157 .unmask = unmask_giuint_low,
172 .ack = ack_giuint_low_irq,
173 .end = end_giuint_low_irq,
174}; 158};
175 159
176static unsigned int startup_giuint_high_irq(unsigned int irq) 160static void ack_giuint_high(unsigned int irq)
177{ 161{
178 unsigned int pin; 162 giu_write(GIUINTSTATH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
179
180 pin = GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET;
181 giu_write(GIUINTSTATH, 1 << pin);
182 giu_set(GIUINTENH, 1 << pin);
183
184 return 0;
185} 163}
186 164
187static void shutdown_giuint_high_irq(unsigned int irq) 165static void mask_giuint_high(unsigned int irq)
188{ 166{
189 giu_clear(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET)); 167 giu_clear(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
190} 168}
191 169
192static void enable_giuint_high_irq(unsigned int irq) 170static void mask_ack_giuint_high(unsigned int irq)
193{
194 giu_set(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
195}
196
197#define disable_giuint_high_irq shutdown_giuint_high_irq
198
199static void ack_giuint_high_irq(unsigned int irq)
200{ 171{
201 unsigned int pin; 172 unsigned int pin;
202 173
@@ -205,20 +176,17 @@ static void ack_giuint_high_irq(unsigned int irq)
205 giu_write(GIUINTSTATH, 1 << pin); 176 giu_write(GIUINTSTATH, 1 << pin);
206} 177}
207 178
208static void end_giuint_high_irq(unsigned int irq) 179static void unmask_giuint_high(unsigned int irq)
209{ 180{
210 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) 181 giu_set(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
211 giu_set(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
212} 182}
213 183
214static struct hw_interrupt_type giuint_high_irq_type = { 184static struct irq_chip giuint_high_irq_chip = {
215 .typename = "GIUINTH", 185 .name = "GIUINTH",
216 .startup = startup_giuint_high_irq, 186 .ack = ack_giuint_high,
217 .shutdown = shutdown_giuint_high_irq, 187 .mask = mask_giuint_high,
218 .enable = enable_giuint_high_irq, 188 .mask_ack = mask_ack_giuint_high,
219 .disable = disable_giuint_high_irq, 189 .unmask = unmask_giuint_high,
220 .ack = ack_giuint_high_irq,
221 .end = end_giuint_high_irq,
222}; 190};
223 191
224static int giu_get_irq(unsigned int irq) 192static int giu_get_irq(unsigned int irq)
@@ -282,9 +250,15 @@ void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger, irq_signal_
282 break; 250 break;
283 } 251 }
284 } 252 }
253 set_irq_chip_and_handler(GIU_IRQ(pin),
254 &giuint_low_irq_chip,
255 handle_edge_irq);
285 } else { 256 } else {
286 giu_clear(GIUINTTYPL, mask); 257 giu_clear(GIUINTTYPL, mask);
287 giu_clear(GIUINTHTSELL, mask); 258 giu_clear(GIUINTHTSELL, mask);
259 set_irq_chip_and_handler(GIU_IRQ(pin),
260 &giuint_low_irq_chip,
261 handle_level_irq);
288 } 262 }
289 giu_write(GIUINTSTATL, mask); 263 giu_write(GIUINTSTATL, mask);
290 } else if (pin < GIUINT_HIGH_MAX) { 264 } else if (pin < GIUINT_HIGH_MAX) {
@@ -311,9 +285,15 @@ void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger, irq_signal_
311 break; 285 break;
312 } 286 }
313 } 287 }
288 set_irq_chip_and_handler(GIU_IRQ(pin),
289 &giuint_high_irq_chip,
290 handle_edge_irq);
314 } else { 291 } else {
315 giu_clear(GIUINTTYPH, mask); 292 giu_clear(GIUINTTYPH, mask);
316 giu_clear(GIUINTHTSELH, mask); 293 giu_clear(GIUINTHTSELH, mask);
294 set_irq_chip_and_handler(GIU_IRQ(pin),
295 &giuint_high_irq_chip,
296 handle_level_irq);
317 } 297 }
318 giu_write(GIUINTSTATH, mask); 298 giu_write(GIUINTSTATH, mask);
319 } 299 }
@@ -617,10 +597,11 @@ static const struct file_operations gpio_fops = {
617static int __devinit giu_probe(struct platform_device *dev) 597static int __devinit giu_probe(struct platform_device *dev)
618{ 598{
619 unsigned long start, size, flags = 0; 599 unsigned long start, size, flags = 0;
620 unsigned int nr_pins = 0; 600 unsigned int nr_pins = 0, trigger, i, pin;
621 struct resource *res1, *res2 = NULL; 601 struct resource *res1, *res2 = NULL;
622 void *base; 602 void *base;
623 int retval, i; 603 struct irq_chip *chip;
604 int retval;
624 605
625 switch (current_cpu_data.cputype) { 606 switch (current_cpu_data.cputype) {
626 case CPU_VR4111: 607 case CPU_VR4111:
@@ -688,11 +669,20 @@ static int __devinit giu_probe(struct platform_device *dev)
688 giu_write(GIUINTENL, 0); 669 giu_write(GIUINTENL, 0);
689 giu_write(GIUINTENH, 0); 670 giu_write(GIUINTENH, 0);
690 671
672 trigger = giu_read(GIUINTTYPH) << 16;
673 trigger |= giu_read(GIUINTTYPL);
691 for (i = GIU_IRQ_BASE; i <= GIU_IRQ_LAST; i++) { 674 for (i = GIU_IRQ_BASE; i <= GIU_IRQ_LAST; i++) {
692 if (i < GIU_IRQ(GIUINT_HIGH_OFFSET)) 675 pin = GPIO_PIN_OF_IRQ(i);
693 irq_desc[i].chip = &giuint_low_irq_type; 676 if (pin < GIUINT_HIGH_OFFSET)
677 chip = &giuint_low_irq_chip;
694 else 678 else
695 irq_desc[i].chip = &giuint_high_irq_type; 679 chip = &giuint_high_irq_chip;
680
681 if (trigger & (1 << pin))
682 set_irq_chip_and_handler(i, chip, handle_edge_irq);
683 else
684 set_irq_chip_and_handler(i, chip, handle_level_irq);
685
696 } 686 }
697 687
698 return cascade_irq(GIUINT_IRQ, giu_get_irq); 688 return cascade_irq(GIUINT_IRQ, giu_get_irq);
diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
index 3ece692313..5c9f67f98d 100644
--- a/drivers/connector/cn_proc.c
+++ b/drivers/connector/cn_proc.c
@@ -28,6 +28,7 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/connector.h> 29#include <linux/connector.h>
30#include <asm/atomic.h> 30#include <asm/atomic.h>
31#include <asm/unaligned.h>
31 32
32#include <linux/cn_proc.h> 33#include <linux/cn_proc.h>
33 34
@@ -60,7 +61,7 @@ void proc_fork_connector(struct task_struct *task)
60 ev = (struct proc_event*)msg->data; 61 ev = (struct proc_event*)msg->data;
61 get_seq(&msg->seq, &ev->cpu); 62 get_seq(&msg->seq, &ev->cpu);
62 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 63 ktime_get_ts(&ts); /* get high res monotonic timestamp */
63 ev->timestamp_ns = timespec_to_ns(&ts); 64 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
64 ev->what = PROC_EVENT_FORK; 65 ev->what = PROC_EVENT_FORK;
65 ev->event_data.fork.parent_pid = task->real_parent->pid; 66 ev->event_data.fork.parent_pid = task->real_parent->pid;
66 ev->event_data.fork.parent_tgid = task->real_parent->tgid; 67 ev->event_data.fork.parent_tgid = task->real_parent->tgid;
@@ -88,7 +89,7 @@ void proc_exec_connector(struct task_struct *task)
88 ev = (struct proc_event*)msg->data; 89 ev = (struct proc_event*)msg->data;
89 get_seq(&msg->seq, &ev->cpu); 90 get_seq(&msg->seq, &ev->cpu);
90 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 91 ktime_get_ts(&ts); /* get high res monotonic timestamp */
91 ev->timestamp_ns = timespec_to_ns(&ts); 92 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
92 ev->what = PROC_EVENT_EXEC; 93 ev->what = PROC_EVENT_EXEC;
93 ev->event_data.exec.process_pid = task->pid; 94 ev->event_data.exec.process_pid = task->pid;
94 ev->event_data.exec.process_tgid = task->tgid; 95 ev->event_data.exec.process_tgid = task->tgid;
@@ -124,7 +125,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
124 return; 125 return;
125 get_seq(&msg->seq, &ev->cpu); 126 get_seq(&msg->seq, &ev->cpu);
126 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 127 ktime_get_ts(&ts); /* get high res monotonic timestamp */
127 ev->timestamp_ns = timespec_to_ns(&ts); 128 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
128 129
129 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 130 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
130 msg->ack = 0; /* not used */ 131 msg->ack = 0; /* not used */
@@ -146,7 +147,7 @@ void proc_exit_connector(struct task_struct *task)
146 ev = (struct proc_event*)msg->data; 147 ev = (struct proc_event*)msg->data;
147 get_seq(&msg->seq, &ev->cpu); 148 get_seq(&msg->seq, &ev->cpu);
148 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 149 ktime_get_ts(&ts); /* get high res monotonic timestamp */
149 ev->timestamp_ns = timespec_to_ns(&ts); 150 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
150 ev->what = PROC_EVENT_EXIT; 151 ev->what = PROC_EVENT_EXIT;
151 ev->event_data.exit.process_pid = task->pid; 152 ev->event_data.exit.process_pid = task->pid;
152 ev->event_data.exit.process_tgid = task->tgid; 153 ev->event_data.exit.process_tgid = task->tgid;
@@ -181,7 +182,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
181 ev = (struct proc_event*)msg->data; 182 ev = (struct proc_event*)msg->data;
182 msg->seq = rcvd_seq; 183 msg->seq = rcvd_seq;
183 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 184 ktime_get_ts(&ts); /* get high res monotonic timestamp */
184 ev->timestamp_ns = timespec_to_ns(&ts); 185 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
185 ev->cpu = -1; 186 ev->cpu = -1;
186 ev->what = PROC_EVENT_NONE; 187 ev->what = PROC_EVENT_NONE;
187 ev->event_data.ack.err = err; 188 ev->event_data.ack.err = err;
diff --git a/drivers/connector/cn_queue.c b/drivers/connector/cn_queue.c
index b418b16e91..296f51002b 100644
--- a/drivers/connector/cn_queue.c
+++ b/drivers/connector/cn_queue.c
@@ -34,7 +34,7 @@
34void cn_queue_wrapper(struct work_struct *work) 34void cn_queue_wrapper(struct work_struct *work)
35{ 35{
36 struct cn_callback_entry *cbq = 36 struct cn_callback_entry *cbq =
37 container_of(work, struct cn_callback_entry, work.work); 37 container_of(work, struct cn_callback_entry, work);
38 struct cn_callback_data *d = &cbq->data; 38 struct cn_callback_data *d = &cbq->data;
39 39
40 d->callback(d->callback_priv); 40 d->callback(d->callback_priv);
@@ -59,13 +59,12 @@ static struct cn_callback_entry *cn_queue_alloc_callback_entry(char *name, struc
59 memcpy(&cbq->id.id, id, sizeof(struct cb_id)); 59 memcpy(&cbq->id.id, id, sizeof(struct cb_id));
60 cbq->data.callback = callback; 60 cbq->data.callback = callback;
61 61
62 INIT_DELAYED_WORK(&cbq->work, &cn_queue_wrapper); 62 INIT_WORK(&cbq->work, &cn_queue_wrapper);
63 return cbq; 63 return cbq;
64} 64}
65 65
66static void cn_queue_free_callback(struct cn_callback_entry *cbq) 66static void cn_queue_free_callback(struct cn_callback_entry *cbq)
67{ 67{
68 cancel_delayed_work(&cbq->work);
69 flush_workqueue(cbq->pdev->cn_queue); 68 flush_workqueue(cbq->pdev->cn_queue);
70 69
71 kfree(cbq); 70 kfree(cbq);
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index 5e7cd45d10..a44db75bc2 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -135,17 +135,15 @@ static int cn_call_callback(struct cn_msg *msg, void (*destruct_data)(void *), v
135 spin_lock_bh(&dev->cbdev->queue_lock); 135 spin_lock_bh(&dev->cbdev->queue_lock);
136 list_for_each_entry(__cbq, &dev->cbdev->queue_list, callback_entry) { 136 list_for_each_entry(__cbq, &dev->cbdev->queue_list, callback_entry) {
137 if (cn_cb_equal(&__cbq->id.id, &msg->id)) { 137 if (cn_cb_equal(&__cbq->id.id, &msg->id)) {
138 if (likely(!test_bit(WORK_STRUCT_PENDING, 138 if (likely(!work_pending(&__cbq->work) &&
139 &__cbq->work.work.management) &&
140 __cbq->data.ddata == NULL)) { 139 __cbq->data.ddata == NULL)) {
141 __cbq->data.callback_priv = msg; 140 __cbq->data.callback_priv = msg;
142 141
143 __cbq->data.ddata = data; 142 __cbq->data.ddata = data;
144 __cbq->data.destruct_data = destruct_data; 143 __cbq->data.destruct_data = destruct_data;
145 144
146 if (queue_delayed_work( 145 if (queue_work(dev->cbdev->cn_queue,
147 dev->cbdev->cn_queue, 146 &__cbq->work))
148 &__cbq->work, 0))
149 err = 0; 147 err = 0;
150 } else { 148 } else {
151 struct cn_callback_data *d; 149 struct cn_callback_data *d;
@@ -159,12 +157,11 @@ static int cn_call_callback(struct cn_msg *msg, void (*destruct_data)(void *), v
159 d->destruct_data = destruct_data; 157 d->destruct_data = destruct_data;
160 d->free = __cbq; 158 d->free = __cbq;
161 159
162 INIT_DELAYED_WORK(&__cbq->work, 160 INIT_WORK(&__cbq->work,
163 &cn_queue_wrapper); 161 &cn_queue_wrapper);
164 162
165 if (queue_delayed_work( 163 if (queue_work(dev->cbdev->cn_queue,
166 dev->cbdev->cn_queue, 164 &__cbq->work))
167 &__cbq->work, 0))
168 err = 0; 165 err = 0;
169 else { 166 else {
170 kfree(__cbq); 167 kfree(__cbq);
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 9fb2edf366..a45cc89e38 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -722,8 +722,13 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
722 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 722 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
723 723
724 dprintk("CPU already managed, adding link\n"); 724 dprintk("CPU already managed, adding link\n");
725 sysfs_create_link(&sys_dev->kobj, 725 ret = sysfs_create_link(&sys_dev->kobj,
726 &managed_policy->kobj, "cpufreq"); 726 &managed_policy->kobj,
727 "cpufreq");
728 if (ret) {
729 mutex_unlock(&policy->lock);
730 goto err_out_driver_exit;
731 }
727 732
728 cpufreq_debug_enable_ratelimit(); 733 cpufreq_debug_enable_ratelimit();
729 mutex_unlock(&policy->lock); 734 mutex_unlock(&policy->lock);
@@ -770,8 +775,12 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
770 dprintk("CPU %u already managed, adding link\n", j); 775 dprintk("CPU %u already managed, adding link\n", j);
771 cpufreq_cpu_get(cpu); 776 cpufreq_cpu_get(cpu);
772 cpu_sys_dev = get_cpu_sysdev(j); 777 cpu_sys_dev = get_cpu_sysdev(j);
773 sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj, 778 ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
774 "cpufreq"); 779 "cpufreq");
780 if (ret) {
781 mutex_unlock(&policy->lock);
782 goto err_out_unregister;
783 }
775 } 784 }
776 785
777 policy->governor = NULL; /* to assure that the starting sequence is 786 policy->governor = NULL; /* to assure that the starting sequence is
@@ -959,7 +968,7 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq,
959 968
960 969
961/** 970/**
962 * cpufreq_quick_get - get the CPU frequency (in kHz) frpm policy->cur 971 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
963 * @cpu: CPU number 972 * @cpu: CPU number
964 * 973 *
965 * This is the last known freq, without actually getting it from the driver. 974 * This is the last known freq, without actually getting it from the driver.
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 6742b1adf2..91ad342a60 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -285,6 +285,7 @@ cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val,
285 stat = cpufreq_stats_table[freq->cpu]; 285 stat = cpufreq_stats_table[freq->cpu];
286 if (!stat) 286 if (!stat)
287 return 0; 287 return 0;
288
288 old_index = freq_table_get_index(stat, freq->old); 289 old_index = freq_table_get_index(stat, freq->old);
289 new_index = freq_table_get_index(stat, freq->new); 290 new_index = freq_table_get_index(stat, freq->new);
290 291
@@ -292,6 +293,9 @@ cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val,
292 if (old_index == new_index) 293 if (old_index == new_index)
293 return 0; 294 return 0;
294 295
296 if (old_index == -1 || new_index == -1)
297 return 0;
298
295 spin_lock(&cpufreq_stats_lock); 299 spin_lock(&cpufreq_stats_lock);
296 stat->last_index = new_index; 300 stat->last_index = new_index;
297#ifdef CONFIG_CPU_FREQ_STAT_DETAILS 301#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 5ab5e393b8..c6281ccd4f 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -122,8 +122,6 @@ struct efivar_entry {
122 struct kobject kobj; 122 struct kobject kobj;
123}; 123};
124 124
125#define get_efivar_entry(n) list_entry(n, struct efivar_entry, list)
126
127struct efivar_attribute { 125struct efivar_attribute {
128 struct attribute attr; 126 struct attribute attr;
129 ssize_t (*show) (struct efivar_entry *entry, char *buf); 127 ssize_t (*show) (struct efivar_entry *entry, char *buf);
@@ -386,9 +384,6 @@ static struct sysfs_ops efivar_attr_ops = {
386static void efivar_release(struct kobject *kobj) 384static void efivar_release(struct kobject *kobj)
387{ 385{
388 struct efivar_entry *var = container_of(kobj, struct efivar_entry, kobj); 386 struct efivar_entry *var = container_of(kobj, struct efivar_entry, kobj);
389 spin_lock(&efivars_lock);
390 list_del(&var->list);
391 spin_unlock(&efivars_lock);
392 kfree(var); 387 kfree(var);
393} 388}
394 389
@@ -430,9 +425,8 @@ static ssize_t
430efivar_create(struct subsystem *sub, const char *buf, size_t count) 425efivar_create(struct subsystem *sub, const char *buf, size_t count)
431{ 426{
432 struct efi_variable *new_var = (struct efi_variable *)buf; 427 struct efi_variable *new_var = (struct efi_variable *)buf;
433 struct efivar_entry *search_efivar = NULL; 428 struct efivar_entry *search_efivar, *n;
434 unsigned long strsize1, strsize2; 429 unsigned long strsize1, strsize2;
435 struct list_head *pos, *n;
436 efi_status_t status = EFI_NOT_FOUND; 430 efi_status_t status = EFI_NOT_FOUND;
437 int found = 0; 431 int found = 0;
438 432
@@ -444,8 +438,7 @@ efivar_create(struct subsystem *sub, const char *buf, size_t count)
444 /* 438 /*
445 * Does this variable already exist? 439 * Does this variable already exist?
446 */ 440 */
447 list_for_each_safe(pos, n, &efivar_list) { 441 list_for_each_entry_safe(search_efivar, n, &efivar_list, list) {
448 search_efivar = get_efivar_entry(pos);
449 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); 442 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024);
450 strsize2 = utf8_strsize(new_var->VariableName, 1024); 443 strsize2 = utf8_strsize(new_var->VariableName, 1024);
451 if (strsize1 == strsize2 && 444 if (strsize1 == strsize2 &&
@@ -490,9 +483,8 @@ static ssize_t
490efivar_delete(struct subsystem *sub, const char *buf, size_t count) 483efivar_delete(struct subsystem *sub, const char *buf, size_t count)
491{ 484{
492 struct efi_variable *del_var = (struct efi_variable *)buf; 485 struct efi_variable *del_var = (struct efi_variable *)buf;
493 struct efivar_entry *search_efivar = NULL; 486 struct efivar_entry *search_efivar, *n;
494 unsigned long strsize1, strsize2; 487 unsigned long strsize1, strsize2;
495 struct list_head *pos, *n;
496 efi_status_t status = EFI_NOT_FOUND; 488 efi_status_t status = EFI_NOT_FOUND;
497 int found = 0; 489 int found = 0;
498 490
@@ -504,8 +496,7 @@ efivar_delete(struct subsystem *sub, const char *buf, size_t count)
504 /* 496 /*
505 * Does this variable already exist? 497 * Does this variable already exist?
506 */ 498 */
507 list_for_each_safe(pos, n, &efivar_list) { 499 list_for_each_entry_safe(search_efivar, n, &efivar_list, list) {
508 search_efivar = get_efivar_entry(pos);
509 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); 500 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024);
510 strsize2 = utf8_strsize(del_var->VariableName, 1024); 501 strsize2 = utf8_strsize(del_var->VariableName, 1024);
511 if (strsize1 == strsize2 && 502 if (strsize1 == strsize2 &&
@@ -537,9 +528,9 @@ efivar_delete(struct subsystem *sub, const char *buf, size_t count)
537 spin_unlock(&efivars_lock); 528 spin_unlock(&efivars_lock);
538 return -EIO; 529 return -EIO;
539 } 530 }
531 list_del(&search_efivar->list);
540 /* We need to release this lock before unregistering. */ 532 /* We need to release this lock before unregistering. */
541 spin_unlock(&efivars_lock); 533 spin_unlock(&efivars_lock);
542
543 efivar_unregister(search_efivar); 534 efivar_unregister(search_efivar);
544 535
545 /* It's dead Jim.... */ 536 /* It's dead Jim.... */
@@ -768,10 +759,14 @@ out_free:
768static void __exit 759static void __exit
769efivars_exit(void) 760efivars_exit(void)
770{ 761{
771 struct list_head *pos, *n; 762 struct efivar_entry *entry, *n;
772 763
773 list_for_each_safe(pos, n, &efivar_list) 764 list_for_each_entry_safe(entry, n, &efivar_list, list) {
774 efivar_unregister(get_efivar_entry(pos)); 765 spin_lock(&efivars_lock);
766 list_del(&entry->list);
767 spin_unlock(&efivars_lock);
768 efivar_unregister(entry);
769 }
775 770
776 subsystem_unregister(&vars_subsys); 771 subsystem_unregister(&vars_subsys);
777 firmware_unregister(&efi_subsys); 772 firmware_unregister(&efi_subsys);
diff --git a/drivers/firmware/pcdp.c b/drivers/firmware/pcdp.c
index c2ad72fefd..2b4b76e8bd 100644
--- a/drivers/firmware/pcdp.c
+++ b/drivers/firmware/pcdp.c
@@ -26,7 +26,7 @@ setup_serial_console(struct pcdp_uart *uart)
26 static char options[64], *p = options; 26 static char options[64], *p = options;
27 char parity; 27 char parity;
28 28
29 mmio = (uart->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY); 29 mmio = (uart->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
30 p += sprintf(p, "console=uart,%s,0x%lx", 30 p += sprintf(p, "console=uart,%s,0x%lx",
31 mmio ? "mmio" : "io", uart->addr.address); 31 mmio ? "mmio" : "io", uart->addr.address);
32 if (uart->baud) { 32 if (uart->baud) {
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 96d4a0bb22..ec796ad087 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -6,13 +6,21 @@ menu "HID Devices"
6 6
7config HID 7config HID
8 tristate "Generic HID support" 8 tristate "Generic HID support"
9 depends on INPUT
9 default y 10 default y
10 ---help--- 11 ---help---
11 Say Y here if you want generic HID support to connect keyboards, 12 A human interface device (HID) is a type of computer device that
12 mice, joysticks, graphic tablets, or any other HID based devices 13 interacts directly with and takes input from humans. The term "HID"
13 to your computer. You also need to select particular types of 14 most commonly used to refer to the USB-HID specification, but other
14 HID devices you want to compile support for, in the particular 15 devices (such as, but not strictly limited to, Bluetooth) are
15 driver menu (USB, Bluetooth) 16 designed using HID specification (this involves certain keyboards,
17 mice, tablets, etc). This option compiles into kernel the generic
18 HID layer code (parser, usages, etc.), which can then be used by
19 transport-specific HID implementation (like USB or Bluetooth).
20
21 For docs and specs, see http://www.usb.org/developers/hidpage/
22
23 If unsure, say Y
16 24
17endmenu 25endmenu
18 26
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 18c2b3cf6b..49f18f5b25 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -40,18 +40,10 @@
40 40
41#define DRIVER_VERSION "v2.6" 41#define DRIVER_VERSION "v2.6"
42#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik" 42#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik"
43#define DRIVER_DESC "USB HID core driver" 43#define DRIVER_DESC "HID core driver"
44#define DRIVER_LICENSE "GPL" 44#define DRIVER_LICENSE "GPL"
45 45
46/* 46/*
47 * Module parameters.
48 */
49
50static unsigned int hid_mousepoll_interval;
51module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
52MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
53
54/*
55 * Register a new report for a device. 47 * Register a new report for a device.
56 */ 48 */
57 49
@@ -551,6 +543,7 @@ void hid_free_device(struct hid_device *device)
551 } 543 }
552 544
553 kfree(device->rdesc); 545 kfree(device->rdesc);
546 kfree(device->collection);
554 kfree(device); 547 kfree(device);
555} 548}
556EXPORT_SYMBOL_GPL(hid_free_device); 549EXPORT_SYMBOL_GPL(hid_free_device);
@@ -656,7 +649,7 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
656 for (i = 0; i < HID_REPORT_TYPES; i++) 649 for (i = 0; i < HID_REPORT_TYPES; i++)
657 INIT_LIST_HEAD(&device->report_enum[i].report_list); 650 INIT_LIST_HEAD(&device->report_enum[i].report_list);
658 651
659 if (!(device->rdesc = (__u8 *)kmalloc(size, GFP_KERNEL))) { 652 if (!(device->rdesc = kmalloc(size, GFP_KERNEL))) {
660 kfree(device->collection); 653 kfree(device->collection);
661 kfree(device); 654 kfree(device);
662 return NULL; 655 return NULL;
@@ -888,6 +881,10 @@ static void hid_output_field(struct hid_field *field, __u8 *data)
888 unsigned size = field->report_size; 881 unsigned size = field->report_size;
889 unsigned n; 882 unsigned n;
890 883
884 /* make sure the unused bits in the last byte are zeros */
885 if (count > 0 && size > 0)
886 data[(count*size-1)/8] = 0;
887
891 for (n = 0; n < count; n++) { 888 for (n = 0; n < count; n++) {
892 if (field->logical_minimum < 0) /* signed values */ 889 if (field->logical_minimum < 0) /* signed values */
893 implement(data, offset + n * size, size, s32ton(field->value[n], size)); 890 implement(data, offset + n * size, size, s32ton(field->value[n], size));
@@ -955,7 +952,7 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i
955 } 952 }
956 953
957#ifdef DEBUG_DATA 954#ifdef DEBUG_DATA
958 printk(KERN_DEBUG __FILE__ ": report (size %u) (%snumbered)\n", len, report_enum->numbered ? "" : "un"); 955 printk(KERN_DEBUG __FILE__ ": report (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un");
959#endif 956#endif
960 957
961 n = 0; /* Normally report number is 0 */ 958 n = 0; /* Normally report number is 0 */
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 14cdf09316..c7a6833f68 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -30,12 +30,16 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/usb/input.h>
34 33
35#undef DEBUG 34#undef DEBUG
36 35
37#include <linux/hid.h> 36#include <linux/hid.h>
38 37
38static int hid_pb_fnmode = 1;
39module_param_named(pb_fnmode, hid_pb_fnmode, int, 0644);
40MODULE_PARM_DESC(pb_fnmode,
41 "Mode of fn key on PowerBooks (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)");
42
39#define unk KEY_UNKNOWN 43#define unk KEY_UNKNOWN
40 44
41static const unsigned char hid_keyboard[256] = { 45static const unsigned char hid_keyboard[256] = {
@@ -68,6 +72,7 @@ static const struct {
68#define map_led(c) do { usage->code = c; usage->type = EV_LED; bit = input->ledbit; max = LED_MAX; } while (0) 72#define map_led(c) do { usage->code = c; usage->type = EV_LED; bit = input->ledbit; max = LED_MAX; } while (0)
69 73
70#define map_abs_clear(c) do { map_abs(c); clear_bit(c, bit); } while (0) 74#define map_abs_clear(c) do { map_abs(c); clear_bit(c, bit); } while (0)
75#define map_rel_clear(c) do { map_rel(c); clear_bit(c, bit); } while (0)
71#define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0) 76#define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0)
72 77
73#ifdef CONFIG_USB_HIDINPUT_POWERBOOK 78#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
@@ -154,7 +159,7 @@ static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
154 return 1; 159 return 1;
155 } 160 }
156 161
157 if (hid->pb_fnmode) { 162 if (hid_pb_fnmode) {
158 int do_translate; 163 int do_translate;
159 164
160 trans = find_translation(powerbook_fn_keys, usage->code); 165 trans = find_translation(powerbook_fn_keys, usage->code);
@@ -163,8 +168,8 @@ static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
163 do_translate = 1; 168 do_translate = 1;
164 else if (trans->flags & POWERBOOK_FLAG_FKEY) 169 else if (trans->flags & POWERBOOK_FLAG_FKEY)
165 do_translate = 170 do_translate =
166 (hid->pb_fnmode == 2 && (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)) || 171 (hid_pb_fnmode == 2 && (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)) ||
167 (hid->pb_fnmode == 1 && !(hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)); 172 (hid_pb_fnmode == 1 && !(hid->quirks & HID_QUIRK_POWERBOOK_FN_ON));
168 else 173 else
169 do_translate = (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON); 174 do_translate = (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON);
170 175
@@ -292,7 +297,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
292 } 297 }
293 } 298 }
294 299
295 map_key(code); 300 map_key_clear(code);
296 break; 301 break;
297 302
298 303
@@ -343,9 +348,9 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
343 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ: 348 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ:
344 case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL: 349 case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL:
345 if (field->flags & HID_MAIN_ITEM_RELATIVE) 350 if (field->flags & HID_MAIN_ITEM_RELATIVE)
346 map_rel(usage->hid & 0xf); 351 map_rel_clear(usage->hid & 0xf);
347 else 352 else
348 map_abs(usage->hid & 0xf); 353 map_abs_clear(usage->hid & 0xf);
349 break; 354 break;
350 355
351 case HID_GD_HATSWITCH: 356 case HID_GD_HATSWITCH:
@@ -363,9 +368,22 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
363 break; 368 break;
364 369
365 case HID_UP_LED: 370 case HID_UP_LED:
366 if (((usage->hid - 1) & 0xffff) >= LED_MAX) 371
367 goto ignore; 372 switch (usage->hid & 0xffff) { /* HID-Value: */
368 map_led((usage->hid - 1) & 0xffff); 373 case 0x01: map_led (LED_NUML); break; /* "Num Lock" */
374 case 0x02: map_led (LED_CAPSL); break; /* "Caps Lock" */
375 case 0x03: map_led (LED_SCROLLL); break; /* "Scroll Lock" */
376 case 0x04: map_led (LED_COMPOSE); break; /* "Compose" */
377 case 0x05: map_led (LED_KANA); break; /* "Kana" */
378 case 0x27: map_led (LED_SLEEP); break; /* "Stand-By" */
379 case 0x4c: map_led (LED_SUSPEND); break; /* "System Suspend" */
380 case 0x09: map_led (LED_MUTE); break; /* "Mute" */
381 case 0x4b: map_led (LED_MISC); break; /* "Generic Indicator" */
382 case 0x19: map_led (LED_MAIL); break; /* "Message Waiting" */
383 case 0x4d: map_led (LED_CHARGING); break; /* "External Power Connected" */
384
385 default: goto ignore;
386 }
369 break; 387 break;
370 388
371 case HID_UP_DIGITIZER: 389 case HID_UP_DIGITIZER:
@@ -415,12 +433,33 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
415 case 0x000: goto ignore; 433 case 0x000: goto ignore;
416 case 0x034: map_key_clear(KEY_SLEEP); break; 434 case 0x034: map_key_clear(KEY_SLEEP); break;
417 case 0x036: map_key_clear(BTN_MISC); break; 435 case 0x036: map_key_clear(BTN_MISC); break;
436 case 0x040: map_key_clear(KEY_MENU); break;
418 case 0x045: map_key_clear(KEY_RADIO); break; 437 case 0x045: map_key_clear(KEY_RADIO); break;
438
439 case 0x083: map_key_clear(KEY_LAST); break;
440 case 0x088: map_key_clear(KEY_PC); break;
441 case 0x089: map_key_clear(KEY_TV); break;
419 case 0x08a: map_key_clear(KEY_WWW); break; 442 case 0x08a: map_key_clear(KEY_WWW); break;
443 case 0x08b: map_key_clear(KEY_DVD); break;
444 case 0x08c: map_key_clear(KEY_PHONE); break;
420 case 0x08d: map_key_clear(KEY_PROGRAM); break; 445 case 0x08d: map_key_clear(KEY_PROGRAM); break;
446 case 0x08e: map_key_clear(KEY_VIDEOPHONE); break;
447 case 0x08f: map_key_clear(KEY_GAMES); break;
448 case 0x090: map_key_clear(KEY_MEMO); break;
449 case 0x091: map_key_clear(KEY_CD); break;
450 case 0x092: map_key_clear(KEY_VCR); break;
451 case 0x093: map_key_clear(KEY_TUNER); break;
452 case 0x094: map_key_clear(KEY_EXIT); break;
421 case 0x095: map_key_clear(KEY_HELP); break; 453 case 0x095: map_key_clear(KEY_HELP); break;
454 case 0x096: map_key_clear(KEY_TAPE); break;
455 case 0x097: map_key_clear(KEY_TV2); break;
456 case 0x098: map_key_clear(KEY_SAT); break;
457 case 0x09a: map_key_clear(KEY_PVR); break;
458
422 case 0x09c: map_key_clear(KEY_CHANNELUP); break; 459 case 0x09c: map_key_clear(KEY_CHANNELUP); break;
423 case 0x09d: map_key_clear(KEY_CHANNELDOWN); break; 460 case 0x09d: map_key_clear(KEY_CHANNELDOWN); break;
461 case 0x0a0: map_key_clear(KEY_VCR2); break;
462
424 case 0x0b0: map_key_clear(KEY_PLAY); break; 463 case 0x0b0: map_key_clear(KEY_PLAY); break;
425 case 0x0b1: map_key_clear(KEY_PAUSE); break; 464 case 0x0b1: map_key_clear(KEY_PAUSE); break;
426 case 0x0b2: map_key_clear(KEY_RECORD); break; 465 case 0x0b2: map_key_clear(KEY_RECORD); break;
@@ -430,6 +469,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
430 case 0x0b6: map_key_clear(KEY_PREVIOUSSONG); break; 469 case 0x0b6: map_key_clear(KEY_PREVIOUSSONG); break;
431 case 0x0b7: map_key_clear(KEY_STOPCD); break; 470 case 0x0b7: map_key_clear(KEY_STOPCD); break;
432 case 0x0b8: map_key_clear(KEY_EJECTCD); break; 471 case 0x0b8: map_key_clear(KEY_EJECTCD); break;
472
433 case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break; 473 case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break;
434 case 0x0e0: map_abs_clear(ABS_VOLUME); break; 474 case 0x0e0: map_abs_clear(ABS_VOLUME); break;
435 case 0x0e2: map_key_clear(KEY_MUTE); break; 475 case 0x0e2: map_key_clear(KEY_MUTE); break;
@@ -437,11 +477,30 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
437 case 0x0e9: map_key_clear(KEY_VOLUMEUP); break; 477 case 0x0e9: map_key_clear(KEY_VOLUMEUP); break;
438 case 0x0ea: map_key_clear(KEY_VOLUMEDOWN); break; 478 case 0x0ea: map_key_clear(KEY_VOLUMEDOWN); break;
439 case 0x183: map_key_clear(KEY_CONFIG); break; 479 case 0x183: map_key_clear(KEY_CONFIG); break;
480 case 0x184: map_key_clear(KEY_WORDPROCESSOR); break;
481 case 0x185: map_key_clear(KEY_EDITOR); break;
482 case 0x186: map_key_clear(KEY_SPREADSHEET); break;
483 case 0x187: map_key_clear(KEY_GRAPHICSEDITOR); break;
484 case 0x188: map_key_clear(KEY_PRESENTATION); break;
485 case 0x189: map_key_clear(KEY_DATABASE); break;
440 case 0x18a: map_key_clear(KEY_MAIL); break; 486 case 0x18a: map_key_clear(KEY_MAIL); break;
487 case 0x18b: map_key_clear(KEY_NEWS); break;
488 case 0x18c: map_key_clear(KEY_VOICEMAIL); break;
489 case 0x18d: map_key_clear(KEY_ADDRESSBOOK); break;
490 case 0x18e: map_key_clear(KEY_CALENDAR); break;
491 case 0x191: map_key_clear(KEY_FINANCE); break;
441 case 0x192: map_key_clear(KEY_CALC); break; 492 case 0x192: map_key_clear(KEY_CALC); break;
442 case 0x194: map_key_clear(KEY_FILE); break; 493 case 0x194: map_key_clear(KEY_FILE); break;
494 case 0x196: map_key_clear(KEY_WWW); break;
495 case 0x19e: map_key_clear(KEY_COFFEE); break;
496 case 0x1a6: map_key_clear(KEY_HELP); break;
443 case 0x1a7: map_key_clear(KEY_DOCUMENTS); break; 497 case 0x1a7: map_key_clear(KEY_DOCUMENTS); break;
498 case 0x1bc: map_key_clear(KEY_MESSENGER); break;
499 case 0x1bd: map_key_clear(KEY_INFO); break;
444 case 0x201: map_key_clear(KEY_NEW); break; 500 case 0x201: map_key_clear(KEY_NEW); break;
501 case 0x202: map_key_clear(KEY_OPEN); break;
502 case 0x203: map_key_clear(KEY_CLOSE); break;
503 case 0x204: map_key_clear(KEY_EXIT); break;
445 case 0x207: map_key_clear(KEY_SAVE); break; 504 case 0x207: map_key_clear(KEY_SAVE); break;
446 case 0x208: map_key_clear(KEY_PRINT); break; 505 case 0x208: map_key_clear(KEY_PRINT); break;
447 case 0x209: map_key_clear(KEY_PROPS); break; 506 case 0x209: map_key_clear(KEY_PROPS); break;
@@ -456,10 +515,15 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
456 case 0x226: map_key_clear(KEY_STOP); break; 515 case 0x226: map_key_clear(KEY_STOP); break;
457 case 0x227: map_key_clear(KEY_REFRESH); break; 516 case 0x227: map_key_clear(KEY_REFRESH); break;
458 case 0x22a: map_key_clear(KEY_BOOKMARKS); break; 517 case 0x22a: map_key_clear(KEY_BOOKMARKS); break;
518 case 0x22d: map_key_clear(KEY_ZOOMIN); break;
519 case 0x22e: map_key_clear(KEY_ZOOMOUT); break;
520 case 0x22f: map_key_clear(KEY_ZOOMRESET); break;
459 case 0x233: map_key_clear(KEY_SCROLLUP); break; 521 case 0x233: map_key_clear(KEY_SCROLLUP); break;
460 case 0x234: map_key_clear(KEY_SCROLLDOWN); break; 522 case 0x234: map_key_clear(KEY_SCROLLDOWN); break;
461 case 0x238: map_rel(REL_HWHEEL); break; 523 case 0x238: map_rel_clear(REL_HWHEEL); break;
524 case 0x25f: map_key_clear(KEY_CANCEL); break;
462 case 0x279: map_key_clear(KEY_REDO); break; 525 case 0x279: map_key_clear(KEY_REDO); break;
526
463 case 0x289: map_key_clear(KEY_REPLY); break; 527 case 0x289: map_key_clear(KEY_REPLY); break;
464 case 0x28b: map_key_clear(KEY_FORWARDMAIL); break; 528 case 0x28b: map_key_clear(KEY_FORWARDMAIL); break;
465 case 0x28c: map_key_clear(KEY_SEND); break; 529 case 0x28c: map_key_clear(KEY_SEND); break;
diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c
index 31c4200270..b80f6ed5ac 100644
--- a/drivers/hwmon/hwmon-vid.c
+++ b/drivers/hwmon/hwmon-vid.c
@@ -93,7 +93,7 @@ int vid_from_reg(int val, u8 vrm)
93 case 110: /* Intel Conroe */ 93 case 110: /* Intel Conroe */
94 /* compute in uV, round to mV */ 94 /* compute in uV, round to mV */
95 val &= 0xff; 95 val &= 0xff;
96 if(((val & 0x7e) == 0xfe) || (!(val & 0x7e))) 96 if (val < 0x02 || val > 0xb2)
97 return 0; 97 return 0;
98 return((1600000 - (val - 2) * 6250 + 500) / 1000); 98 return((1600000 - (val - 2) * 6250 + 500) / 1000);
99 case 24: /* Opteron processor */ 99 case 24: /* Opteron processor */
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index c12ac5abc2..253ffaf156 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -117,6 +117,7 @@ static const u16 W83793_REG_IN[][3] = {
117/* Low Bits of Vcore A/B Vtt Read/High/Low */ 117/* Low Bits of Vcore A/B Vtt Read/High/Low */
118static const u16 W83793_REG_IN_LOW_BITS[] = { 0x1b, 0x68, 0x69 }; 118static const u16 W83793_REG_IN_LOW_BITS[] = { 0x1b, 0x68, 0x69 };
119static u8 scale_in[] = { 2, 2, 2, 16, 16, 16, 8, 24, 24, 16 }; 119static u8 scale_in[] = { 2, 2, 2, 16, 16, 16, 8, 24, 24, 16 };
120static u8 scale_in_add[] = { 0, 0, 0, 0, 0, 0, 0, 150, 150, 0 };
120 121
121#define W83793_REG_FAN(index) (0x23 + 2 * (index)) /* High byte */ 122#define W83793_REG_FAN(index) (0x23 + 2 * (index)) /* High byte */
122#define W83793_REG_FAN_MIN(index) (0x90 + 2 * (index)) /* High byte */ 123#define W83793_REG_FAN_MIN(index) (0x90 + 2 * (index)) /* High byte */
@@ -203,6 +204,8 @@ struct w83793_data {
203 u8 temp_fan_map[6]; /* Temp controls which pwm fan, bit field */ 204 u8 temp_fan_map[6]; /* Temp controls which pwm fan, bit field */
204 205
205 u8 has_pwm; 206 u8 has_pwm;
207 u8 has_temp;
208 u8 has_vid;
206 u8 pwm_enable; /* Register value, each Temp has 1 bit */ 209 u8 pwm_enable; /* Register value, each Temp has 1 bit */
207 u8 pwm_uptime; /* Register value */ 210 u8 pwm_uptime; /* Register value */
208 u8 pwm_downtime; /* Register value */ 211 u8 pwm_downtime; /* Register value */
@@ -500,7 +503,7 @@ store_temp(struct device *dev, struct device_attribute *attr,
500 each has 4 mode:(2 bits) 503 each has 4 mode:(2 bits)
501 0: Stop monitor 504 0: Stop monitor
502 1: Use internal temp sensor(default) 505 1: Use internal temp sensor(default)
503 2: Use sensor in AMD CPU and get result by AMDSI 506 2: Reserved
504 3: Use sensor in Intel CPU and get result by PECI 507 3: Use sensor in Intel CPU and get result by PECI
505 508
506 TR1-TR2 509 TR1-TR2
@@ -509,8 +512,8 @@ store_temp(struct device *dev, struct device_attribute *attr,
509 1: To enable temp sensors monitor 512 1: To enable temp sensors monitor
510*/ 513*/
511 514
512/* 0 disable, 5 AMDSI, 6 PECI */ 515/* 0 disable, 6 PECI */
513static u8 TO_TEMP_MODE[] = { 0, 0, 5, 6 }; 516static u8 TO_TEMP_MODE[] = { 0, 0, 0, 6 };
514 517
515static ssize_t 518static ssize_t
516show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) 519show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf)
@@ -550,11 +553,10 @@ store_temp_mode(struct device *dev, struct device_attribute *attr,
550 u8 val = simple_strtoul(buf, NULL, 10); 553 u8 val = simple_strtoul(buf, NULL, 10);
551 554
552 /* transform the sysfs interface values into table above */ 555 /* transform the sysfs interface values into table above */
553 if ((val == 5 || val == 6) && (index < 4)) { 556 if ((val == 6) && (index < 4)) {
554 val -= 3; 557 val -= 3;
555 } else if ((val == 3 && index < 4) 558 } else if ((val == 3 && index < 4)
556 || (val == 4 && index >= 4) 559 || (val == 4 && index >= 4)) {
557 || val == 0) {
558 /* transform diode or thermistor into internal enable */ 560 /* transform diode or thermistor into internal enable */
559 val = !!val; 561 val = !!val;
560 } else { 562 } else {
@@ -839,7 +841,9 @@ show_in(struct device *dev, struct device_attribute *attr, char *buf)
839 val <<= 2; 841 val <<= 2;
840 val += (data->in_low_bits[nr] >> (index * 2)) & 0x3; 842 val += (data->in_low_bits[nr] >> (index * 2)) & 0x3;
841 } 843 }
842 return sprintf(buf, "%d\n", val * scale_in[index]); 844 /* voltage inputs 5VDD and 5VSB needs 150mV offset */
845 val = val * scale_in[index] + scale_in_add[index];
846 return sprintf(buf, "%d\n", val);
843} 847}
844 848
845static ssize_t 849static ssize_t
@@ -859,6 +863,10 @@ store_in(struct device *dev, struct device_attribute *attr,
859 scale_in[index] / 2) / scale_in[index]; 863 scale_in[index] / 2) / scale_in[index];
860 mutex_lock(&data->update_lock); 864 mutex_lock(&data->update_lock);
861 if (index > 2) { 865 if (index > 2) {
866 /* fix the limit values of 5VDD and 5VSB to ALARM mechanism */
867 if (1 == nr || 2 == nr) {
868 val -= scale_in_add[index] / scale_in[index];
869 }
862 val = SENSORS_LIMIT(val, 0, 255); 870 val = SENSORS_LIMIT(val, 0, 255);
863 } else { 871 } else {
864 val = SENSORS_LIMIT(val, 0, 0x3FF); 872 val = SENSORS_LIMIT(val, 0, 0x3FF);
@@ -979,12 +987,6 @@ static struct sensor_device_attribute_2 w83793_sensor_attr_2[] = {
979 SENSOR_ATTR_IN(7), 987 SENSOR_ATTR_IN(7),
980 SENSOR_ATTR_IN(8), 988 SENSOR_ATTR_IN(8),
981 SENSOR_ATTR_IN(9), 989 SENSOR_ATTR_IN(9),
982 SENSOR_ATTR_TEMP(1),
983 SENSOR_ATTR_TEMP(2),
984 SENSOR_ATTR_TEMP(3),
985 SENSOR_ATTR_TEMP(4),
986 SENSOR_ATTR_TEMP(5),
987 SENSOR_ATTR_TEMP(6),
988 SENSOR_ATTR_FAN(1), 990 SENSOR_ATTR_FAN(1),
989 SENSOR_ATTR_FAN(2), 991 SENSOR_ATTR_FAN(2),
990 SENSOR_ATTR_FAN(3), 992 SENSOR_ATTR_FAN(3),
@@ -995,6 +997,15 @@ static struct sensor_device_attribute_2 w83793_sensor_attr_2[] = {
995 SENSOR_ATTR_PWM(3), 997 SENSOR_ATTR_PWM(3),
996}; 998};
997 999
1000static struct sensor_device_attribute_2 w83793_temp[] = {
1001 SENSOR_ATTR_TEMP(1),
1002 SENSOR_ATTR_TEMP(2),
1003 SENSOR_ATTR_TEMP(3),
1004 SENSOR_ATTR_TEMP(4),
1005 SENSOR_ATTR_TEMP(5),
1006 SENSOR_ATTR_TEMP(6),
1007};
1008
998/* Fan6-Fan12 */ 1009/* Fan6-Fan12 */
999static struct sensor_device_attribute_2 w83793_left_fan[] = { 1010static struct sensor_device_attribute_2 w83793_left_fan[] = {
1000 SENSOR_ATTR_FAN(6), 1011 SENSOR_ATTR_FAN(6),
@@ -1015,9 +1026,12 @@ static struct sensor_device_attribute_2 w83793_left_pwm[] = {
1015 SENSOR_ATTR_PWM(8), 1026 SENSOR_ATTR_PWM(8),
1016}; 1027};
1017 1028
1018static struct sensor_device_attribute_2 sda_single_files[] = { 1029static struct sensor_device_attribute_2 w83793_vid[] = {
1019 SENSOR_ATTR_2(cpu0_vid, S_IRUGO, show_vid, NULL, NOT_USED, 0), 1030 SENSOR_ATTR_2(cpu0_vid, S_IRUGO, show_vid, NULL, NOT_USED, 0),
1020 SENSOR_ATTR_2(cpu1_vid, S_IRUGO, show_vid, NULL, NOT_USED, 1), 1031 SENSOR_ATTR_2(cpu1_vid, S_IRUGO, show_vid, NULL, NOT_USED, 1),
1032};
1033
1034static struct sensor_device_attribute_2 sda_single_files[] = {
1021 SENSOR_ATTR_2(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm, 1035 SENSOR_ATTR_2(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm,
1022 NOT_USED, NOT_USED), 1036 NOT_USED, NOT_USED),
1023 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep, 1037 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep,
@@ -1070,11 +1084,17 @@ static int w83793_detach_client(struct i2c_client *client)
1070 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) 1084 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
1071 device_remove_file(dev, &sda_single_files[i].dev_attr); 1085 device_remove_file(dev, &sda_single_files[i].dev_attr);
1072 1086
1087 for (i = 0; i < ARRAY_SIZE(w83793_vid); i++)
1088 device_remove_file(dev, &w83793_vid[i].dev_attr);
1089
1073 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) 1090 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++)
1074 device_remove_file(dev, &w83793_left_fan[i].dev_attr); 1091 device_remove_file(dev, &w83793_left_fan[i].dev_attr);
1075 1092
1076 for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++) 1093 for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++)
1077 device_remove_file(dev, &w83793_left_pwm[i].dev_attr); 1094 device_remove_file(dev, &w83793_left_pwm[i].dev_attr);
1095
1096 for (i = 0; i < ARRAY_SIZE(w83793_temp); i++)
1097 device_remove_file(dev, &w83793_temp[i].dev_attr);
1078 } 1098 }
1079 1099
1080 if ((err = i2c_detach_client(client))) 1100 if ((err = i2c_detach_client(client)))
@@ -1187,6 +1207,7 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1187 struct w83793_data *data; 1207 struct w83793_data *data;
1188 int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; 1208 int files_fan = ARRAY_SIZE(w83793_left_fan) / 7;
1189 int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5; 1209 int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5;
1210 int files_temp = ARRAY_SIZE(w83793_temp) / 6;
1190 int err = 0; 1211 int err = 0;
1191 1212
1192 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1213 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
@@ -1313,6 +1334,44 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1313 data->has_pwm |= 0x80; 1334 data->has_pwm |= 0x80;
1314 } 1335 }
1315 1336
1337 tmp = w83793_read_value(client, W83793_REG_FANIN_SEL);
1338 if ((tmp & 0x01) && (val & 0x08)) { /* fan 9, second location */
1339 data->has_fan |= 0x100;
1340 }
1341 if ((tmp & 0x02) && (val & 0x10)) { /* fan 10, second location */
1342 data->has_fan |= 0x200;
1343 }
1344 if ((tmp & 0x04) && (val & 0x20)) { /* fan 11, second location */
1345 data->has_fan |= 0x400;
1346 }
1347 if ((tmp & 0x08) && (val & 0x40)) { /* fan 12, second location */
1348 data->has_fan |= 0x800;
1349 }
1350
1351 /* check the temp1-6 mode, ignore former AMDSI selected inputs */
1352 tmp = w83793_read_value(client,W83793_REG_TEMP_MODE[0]);
1353 if (tmp & 0x01)
1354 data->has_temp |= 0x01;
1355 if (tmp & 0x04)
1356 data->has_temp |= 0x02;
1357 if (tmp & 0x10)
1358 data->has_temp |= 0x04;
1359 if (tmp & 0x40)
1360 data->has_temp |= 0x08;
1361
1362 tmp = w83793_read_value(client,W83793_REG_TEMP_MODE[1]);
1363 if (tmp & 0x01)
1364 data->has_temp |= 0x10;
1365 if (tmp & 0x02)
1366 data->has_temp |= 0x20;
1367
1368 /* Detect the VID usage and ignore unused input */
1369 tmp = w83793_read_value(client, W83793_REG_MFC);
1370 if (!(tmp & 0x29))
1371 data->has_vid |= 0x1; /* has VIDA */
1372 if (tmp & 0x80)
1373 data->has_vid |= 0x2; /* has VIDB */
1374
1316 /* Register sysfs hooks */ 1375 /* Register sysfs hooks */
1317 for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) { 1376 for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) {
1318 err = device_create_file(dev, 1377 err = device_create_file(dev,
@@ -1321,6 +1380,14 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1321 goto exit_remove; 1380 goto exit_remove;
1322 } 1381 }
1323 1382
1383 for (i = 0; i < ARRAY_SIZE(w83793_vid); i++) {
1384 if (!(data->has_vid & (1 << i)))
1385 continue;
1386 err = device_create_file(dev, &w83793_vid[i].dev_attr);
1387 if (err)
1388 goto exit_remove;
1389 }
1390
1324 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { 1391 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
1325 err = device_create_file(dev, &sda_single_files[i].dev_attr); 1392 err = device_create_file(dev, &sda_single_files[i].dev_attr);
1326 if (err) 1393 if (err)
@@ -1328,6 +1395,19 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1328 1395
1329 } 1396 }
1330 1397
1398 for (i = 0; i < 6; i++) {
1399 int j;
1400 if (!(data->has_temp & (1 << i)))
1401 continue;
1402 for (j = 0; j < files_temp; j++) {
1403 err = device_create_file(dev,
1404 &w83793_temp[(i) * files_temp
1405 + j].dev_attr);
1406 if (err)
1407 goto exit_remove;
1408 }
1409 }
1410
1331 for (i = 5; i < 12; i++) { 1411 for (i = 5; i < 12; i++) {
1332 int j; 1412 int j;
1333 if (!(data->has_fan & (1 << i))) 1413 if (!(data->has_fan & (1 << i)))
@@ -1371,12 +1451,18 @@ exit_remove:
1371 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) 1451 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
1372 device_remove_file(dev, &sda_single_files[i].dev_attr); 1452 device_remove_file(dev, &sda_single_files[i].dev_attr);
1373 1453
1454 for (i = 0; i < ARRAY_SIZE(w83793_vid); i++)
1455 device_remove_file(dev, &w83793_vid[i].dev_attr);
1456
1374 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) 1457 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++)
1375 device_remove_file(dev, &w83793_left_fan[i].dev_attr); 1458 device_remove_file(dev, &w83793_left_fan[i].dev_attr);
1376 1459
1377 for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++) 1460 for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++)
1378 device_remove_file(dev, &w83793_left_pwm[i].dev_attr); 1461 device_remove_file(dev, &w83793_left_pwm[i].dev_attr);
1379 1462
1463 for (i = 0; i < ARRAY_SIZE(w83793_temp); i++)
1464 device_remove_file(dev, &w83793_temp[i].dev_attr);
1465
1380 if (data->lm75[0] != NULL) { 1466 if (data->lm75[0] != NULL) {
1381 i2c_detach_client(data->lm75[0]); 1467 i2c_detach_client(data->lm75[0]);
1382 kfree(data->lm75[0]); 1468 kfree(data->lm75[0]);
@@ -1428,6 +1514,8 @@ static void w83793_update_nonvolatile(struct device *dev)
1428 } 1514 }
1429 1515
1430 for (i = 0; i < ARRAY_SIZE(data->temp_fan_map); i++) { 1516 for (i = 0; i < ARRAY_SIZE(data->temp_fan_map); i++) {
1517 if (!(data->has_temp & (1 << i)))
1518 continue;
1431 data->temp_fan_map[i] = 1519 data->temp_fan_map[i] =
1432 w83793_read_value(client, W83793_REG_TEMP_FAN_MAP(i)); 1520 w83793_read_value(client, W83793_REG_TEMP_FAN_MAP(i));
1433 for (j = 1; j < 5; j++) { 1521 for (j = 1; j < 5; j++) {
@@ -1510,9 +1598,12 @@ static struct w83793_data *w83793_update_device(struct device *dev)
1510 w83793_read_value(client, W83793_REG_FAN(i) + 1); 1598 w83793_read_value(client, W83793_REG_FAN(i) + 1);
1511 } 1599 }
1512 1600
1513 for (i = 0; i < ARRAY_SIZE(data->temp); i++) 1601 for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
1602 if (!(data->has_temp & (1 << i)))
1603 continue;
1514 data->temp[i][TEMP_READ] = 1604 data->temp[i][TEMP_READ] =
1515 w83793_read_value(client, W83793_REG_TEMP[i][TEMP_READ]); 1605 w83793_read_value(client, W83793_REG_TEMP[i][TEMP_READ]);
1606 }
1516 1607
1517 data->temp_low_bits = 1608 data->temp_low_bits =
1518 w83793_read_value(client, W83793_REG_TEMP_LOW_BITS); 1609 w83793_read_value(client, W83793_REG_TEMP_LOW_BITS);
@@ -1527,8 +1618,10 @@ static struct w83793_data *w83793_update_device(struct device *dev)
1527 for (i = 0; i < ARRAY_SIZE(data->alarms); i++) 1618 for (i = 0; i < ARRAY_SIZE(data->alarms); i++)
1528 data->alarms[i] = 1619 data->alarms[i] =
1529 w83793_read_value(client, W83793_REG_ALARM(i)); 1620 w83793_read_value(client, W83793_REG_ALARM(i));
1530 data->vid[0] = w83793_read_value(client, W83793_REG_VID_INA); 1621 if (data->has_vid & 0x01)
1531 data->vid[1] = w83793_read_value(client, W83793_REG_VID_INB); 1622 data->vid[0] = w83793_read_value(client, W83793_REG_VID_INA);
1623 if (data->has_vid & 0x02)
1624 data->vid[1] = w83793_read_value(client, W83793_REG_VID_INB);
1532 w83793_update_nonvolatile(dev); 1625 w83793_update_nonvolatile(dev);
1533 data->last_updated = jiffies; 1626 data->last_updated = jiffies;
1534 data->valid = 1; 1627 data->valid = 1;
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index e1989f3a26..9367c4cfe9 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -564,13 +564,4 @@ config I2C_PNX
564 This driver can also be built as a module. If so, the module 564 This driver can also be built as a module. If so, the module
565 will be called i2c-pnx. 565 will be called i2c-pnx.
566 566
567config I2C_PNX_EARLY
568 bool "Early initialization for I2C on PNXxxxx"
569 depends on I2C_PNX=y
570 help
571 Under certain circumstances one may need to make sure I2C on PNXxxxx
572 is initialized earlier than some other driver that depends on it
573 (for instance, that might be USB in case of PNX4008). With this
574 option turned on you can guarantee that.
575
576endmenu 567endmenu
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index bbc8e3a7ff..490173611d 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -529,6 +529,8 @@ mv64xxx_i2c_probe(struct platform_device *pd)
529 platform_set_drvdata(pd, drv_data); 529 platform_set_drvdata(pd, drv_data);
530 i2c_set_adapdata(&drv_data->adapter, drv_data); 530 i2c_set_adapdata(&drv_data->adapter, drv_data);
531 531
532 mv64xxx_i2c_hw_init(drv_data);
533
532 if (request_irq(drv_data->irq, mv64xxx_i2c_intr, 0, 534 if (request_irq(drv_data->irq, mv64xxx_i2c_intr, 0,
533 MV64XXX_I2C_CTLR_NAME, drv_data)) { 535 MV64XXX_I2C_CTLR_NAME, drv_data)) {
534 dev_err(&drv_data->adapter.dev, 536 dev_err(&drv_data->adapter.dev,
@@ -542,8 +544,6 @@ mv64xxx_i2c_probe(struct platform_device *pd)
542 goto exit_free_irq; 544 goto exit_free_irq;
543 } 545 }
544 546
545 mv64xxx_i2c_hw_init(drv_data);
546
547 return 0; 547 return 0;
548 548
549 exit_free_irq: 549 exit_free_irq:
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index de0bca77e9..17376feb1a 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -305,8 +305,7 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap)
305 return 0; 305 return 0;
306} 306}
307 307
308static irqreturn_t 308static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)
309i2c_pnx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
310{ 309{
311 u32 stat, ctl; 310 u32 stat, ctl;
312 struct i2c_adapter *adap = dev_id; 311 struct i2c_adapter *adap = dev_id;
@@ -699,10 +698,6 @@ MODULE_AUTHOR("Vitaly Wool, Dennis Kovalev <source@mvista.com>");
699MODULE_DESCRIPTION("I2C driver for Philips IP3204-based I2C busses"); 698MODULE_DESCRIPTION("I2C driver for Philips IP3204-based I2C busses");
700MODULE_LICENSE("GPL"); 699MODULE_LICENSE("GPL");
701 700
702#ifdef CONFIG_I2C_PNX_EARLY
703/* We need to make sure I2C is initialized before USB */ 701/* We need to make sure I2C is initialized before USB */
704subsys_initcall(i2c_adap_pnx_init); 702subsys_initcall(i2c_adap_pnx_init);
705#else
706mudule_init(i2c_adap_pnx_init);
707#endif
708module_exit(i2c_adap_pnx_exit); 703module_exit(i2c_adap_pnx_exit);
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index 420377c864..3fcb646e20 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -209,6 +209,7 @@ m41t00_set(void *arg)
209 buf[m41t00_chip->hour] = (buf[m41t00_chip->hour] & ~0x3f) | (hour& 0x3f); 209 buf[m41t00_chip->hour] = (buf[m41t00_chip->hour] & ~0x3f) | (hour& 0x3f);
210 buf[m41t00_chip->day] = (buf[m41t00_chip->day] & ~0x3f) | (day & 0x3f); 210 buf[m41t00_chip->day] = (buf[m41t00_chip->day] & ~0x3f) | (day & 0x3f);
211 buf[m41t00_chip->mon] = (buf[m41t00_chip->mon] & ~0x1f) | (mon & 0x1f); 211 buf[m41t00_chip->mon] = (buf[m41t00_chip->mon] & ~0x1f) | (mon & 0x1f);
212 buf[m41t00_chip->year] = year;
212 213
213 if (i2c_master_send(save_client, wbuf, 9) < 0) 214 if (i2c_master_send(save_client, wbuf, 9) < 0)
214 dev_err(&save_client->dev, "m41t00_set: Write error\n"); 215 dev_err(&save_client->dev, "m41t00_set: Write error\n");
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 3e31f1d265..b05378a3d6 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -95,16 +95,32 @@ struct device_driver i2c_adapter_driver = {
95 .bus = &i2c_bus_type, 95 .bus = &i2c_bus_type,
96}; 96};
97 97
98/* ------------------------------------------------------------------------- */
99
100/* I2C bus adapters -- one roots each I2C or SMBUS segment */
101
98static void i2c_adapter_class_dev_release(struct class_device *dev) 102static void i2c_adapter_class_dev_release(struct class_device *dev)
99{ 103{
100 struct i2c_adapter *adap = class_dev_to_i2c_adapter(dev); 104 struct i2c_adapter *adap = class_dev_to_i2c_adapter(dev);
101 complete(&adap->class_dev_released); 105 complete(&adap->class_dev_released);
102} 106}
103 107
108static ssize_t i2c_adapter_show_name(struct class_device *cdev, char *buf)
109{
110 struct i2c_adapter *adap = class_dev_to_i2c_adapter(cdev);
111 return sprintf(buf, "%s\n", adap->name);
112}
113
114static struct class_device_attribute i2c_adapter_attrs[] = {
115 __ATTR(name, S_IRUGO, i2c_adapter_show_name, NULL),
116 { },
117};
118
104struct class i2c_adapter_class = { 119struct class i2c_adapter_class = {
105 .owner = THIS_MODULE, 120 .owner = THIS_MODULE,
106 .name = "i2c-adapter", 121 .name = "i2c-adapter",
107 .release = &i2c_adapter_class_dev_release, 122 .class_dev_attrs = i2c_adapter_attrs,
123 .release = &i2c_adapter_class_dev_release,
108}; 124};
109 125
110static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) 126static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
@@ -175,8 +191,12 @@ int i2c_add_adapter(struct i2c_adapter *adap)
175 * If the parent pointer is not set up, 191 * If the parent pointer is not set up,
176 * we add this adapter to the host bus. 192 * we add this adapter to the host bus.
177 */ 193 */
178 if (adap->dev.parent == NULL) 194 if (adap->dev.parent == NULL) {
179 adap->dev.parent = &platform_bus; 195 adap->dev.parent = &platform_bus;
196 printk(KERN_WARNING "**WARNING** I2C adapter driver [%s] "
197 "forgot to specify physical device; fix it!\n",
198 adap->name);
199 }
180 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); 200 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
181 adap->dev.driver = &i2c_adapter_driver; 201 adap->dev.driver = &i2c_adapter_driver;
182 adap->dev.release = &i2c_adapter_dev_release; 202 adap->dev.release = &i2c_adapter_dev_release;
diff --git a/drivers/ide/ide-pnp.c b/drivers/ide/ide-pnp.c
index df7d1504f8..98410ca044 100644
--- a/drivers/ide/ide-pnp.c
+++ b/drivers/ide/ide-pnp.c
@@ -73,3 +73,8 @@ void __init pnpide_init(void)
73{ 73{
74 pnp_register_driver(&idepnp_driver); 74 pnp_register_driver(&idepnp_driver);
75} 75}
76
77void __exit pnpide_exit(void)
78{
79 pnp_unregister_driver(&idepnp_driver);
80}
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 16890769dc..6c9bd5165b 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -1781,8 +1781,9 @@ done:
1781 return 1; 1781 return 1;
1782} 1782}
1783 1783
1784extern void pnpide_init(void); 1784extern void __init pnpide_init(void);
1785extern void h8300_ide_init(void); 1785extern void __exit pnpide_exit(void);
1786extern void __init h8300_ide_init(void);
1786 1787
1787/* 1788/*
1788 * probe_for_hwifs() finds/initializes "known" IDE interfaces 1789 * probe_for_hwifs() finds/initializes "known" IDE interfaces
@@ -2087,13 +2088,17 @@ int __init init_module (void)
2087 return ide_init(); 2088 return ide_init();
2088} 2089}
2089 2090
2090void cleanup_module (void) 2091void __exit cleanup_module (void)
2091{ 2092{
2092 int index; 2093 int index;
2093 2094
2094 for (index = 0; index < MAX_HWIFS; ++index) 2095 for (index = 0; index < MAX_HWIFS; ++index)
2095 ide_unregister(index); 2096 ide_unregister(index);
2096 2097
2098#ifdef CONFIG_BLK_DEV_IDEPNP
2099 pnpide_exit();
2100#endif
2101
2097#ifdef CONFIG_PROC_FS 2102#ifdef CONFIG_PROC_FS
2098 proc_ide_destroy(); 2103 proc_ide_destroy();
2099#endif 2104#endif
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index f286079d23..d261bfbad2 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -441,7 +441,7 @@ static struct pci_driver driver = {
441 .probe = aec62xx_init_one, 441 .probe = aec62xx_init_one,
442}; 442};
443 443
444static int aec62xx_ide_init(void) 444static int __init aec62xx_ide_init(void)
445{ 445{
446 return ide_pci_register_driver(&driver); 446 return ide_pci_register_driver(&driver);
447} 447}
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 89109be516..68df77ec50 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -907,7 +907,7 @@ static struct pci_driver driver = {
907 .probe = alim15x3_init_one, 907 .probe = alim15x3_init_one,
908}; 908};
909 909
910static int ali15x3_ide_init(void) 910static int __init ali15x3_ide_init(void)
911{ 911{
912 return ide_pci_register_driver(&driver); 912 return ide_pci_register_driver(&driver);
913} 913}
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 753fe0e214..a4336995a4 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -544,7 +544,7 @@ static struct pci_driver driver = {
544 .probe = amd74xx_probe, 544 .probe = amd74xx_probe,
545}; 545};
546 546
547static int amd74xx_ide_init(void) 547static int __init amd74xx_ide_init(void)
548{ 548{
549 return ide_pci_register_driver(&driver); 549 return ide_pci_register_driver(&driver);
550} 550}
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index d55b938b1a..982ac31fa9 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -46,6 +46,8 @@ static atiixp_ide_timing mdma_timing[] = {
46 46
47static int save_mdma_mode[4]; 47static int save_mdma_mode[4];
48 48
49static DEFINE_SPINLOCK(atiixp_lock);
50
49/** 51/**
50 * atiixp_ratemask - compute rate mask for ATIIXP IDE 52 * atiixp_ratemask - compute rate mask for ATIIXP IDE
51 * @drive: IDE drive to compute for 53 * @drive: IDE drive to compute for
@@ -105,7 +107,7 @@ static int atiixp_ide_dma_host_on(ide_drive_t *drive)
105 unsigned long flags; 107 unsigned long flags;
106 u16 tmp16; 108 u16 tmp16;
107 109
108 spin_lock_irqsave(&ide_lock, flags); 110 spin_lock_irqsave(&atiixp_lock, flags);
109 111
110 pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &tmp16); 112 pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &tmp16);
111 if (save_mdma_mode[drive->dn]) 113 if (save_mdma_mode[drive->dn])
@@ -114,7 +116,7 @@ static int atiixp_ide_dma_host_on(ide_drive_t *drive)
114 tmp16 |= (1 << drive->dn); 116 tmp16 |= (1 << drive->dn);
115 pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, tmp16); 117 pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, tmp16);
116 118
117 spin_unlock_irqrestore(&ide_lock, flags); 119 spin_unlock_irqrestore(&atiixp_lock, flags);
118 120
119 return __ide_dma_host_on(drive); 121 return __ide_dma_host_on(drive);
120} 122}
@@ -125,13 +127,13 @@ static int atiixp_ide_dma_host_off(ide_drive_t *drive)
125 unsigned long flags; 127 unsigned long flags;
126 u16 tmp16; 128 u16 tmp16;
127 129
128 spin_lock_irqsave(&ide_lock, flags); 130 spin_lock_irqsave(&atiixp_lock, flags);
129 131
130 pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &tmp16); 132 pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &tmp16);
131 tmp16 &= ~(1 << drive->dn); 133 tmp16 &= ~(1 << drive->dn);
132 pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, tmp16); 134 pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, tmp16);
133 135
134 spin_unlock_irqrestore(&ide_lock, flags); 136 spin_unlock_irqrestore(&atiixp_lock, flags);
135 137
136 return __ide_dma_host_off(drive); 138 return __ide_dma_host_off(drive);
137} 139}
@@ -152,7 +154,7 @@ static void atiixp_tuneproc(ide_drive_t *drive, u8 pio)
152 u32 pio_timing_data; 154 u32 pio_timing_data;
153 u16 pio_mode_data; 155 u16 pio_mode_data;
154 156
155 spin_lock_irqsave(&ide_lock, flags); 157 spin_lock_irqsave(&atiixp_lock, flags);
156 158
157 pci_read_config_word(dev, ATIIXP_IDE_PIO_MODE, &pio_mode_data); 159 pci_read_config_word(dev, ATIIXP_IDE_PIO_MODE, &pio_mode_data);
158 pio_mode_data &= ~(0x07 << (drive->dn * 4)); 160 pio_mode_data &= ~(0x07 << (drive->dn * 4));
@@ -165,7 +167,7 @@ static void atiixp_tuneproc(ide_drive_t *drive, u8 pio)
165 (pio_timing[pio].command_width << (timing_shift + 4)); 167 (pio_timing[pio].command_width << (timing_shift + 4));
166 pci_write_config_dword(dev, ATIIXP_IDE_PIO_TIMING, pio_timing_data); 168 pci_write_config_dword(dev, ATIIXP_IDE_PIO_TIMING, pio_timing_data);
167 169
168 spin_unlock_irqrestore(&ide_lock, flags); 170 spin_unlock_irqrestore(&atiixp_lock, flags);
169} 171}
170 172
171/** 173/**
@@ -189,7 +191,7 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed)
189 191
190 speed = ide_rate_filter(atiixp_ratemask(drive), xferspeed); 192 speed = ide_rate_filter(atiixp_ratemask(drive), xferspeed);
191 193
192 spin_lock_irqsave(&ide_lock, flags); 194 spin_lock_irqsave(&atiixp_lock, flags);
193 195
194 save_mdma_mode[drive->dn] = 0; 196 save_mdma_mode[drive->dn] = 0;
195 if (speed >= XFER_UDMA_0) { 197 if (speed >= XFER_UDMA_0) {
@@ -208,7 +210,7 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed)
208 } 210 }
209 } 211 }
210 212
211 spin_unlock_irqrestore(&ide_lock, flags); 213 spin_unlock_irqrestore(&atiixp_lock, flags);
212 214
213 if (speed >= XFER_SW_DMA_0) 215 if (speed >= XFER_SW_DMA_0)
214 pio = atiixp_dma_2_pio(speed); 216 pio = atiixp_dma_2_pio(speed);
@@ -289,8 +291,12 @@ fast_ata_pio:
289 291
290static void __devinit init_hwif_atiixp(ide_hwif_t *hwif) 292static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
291{ 293{
294 u8 udma_mode = 0;
295 u8 ch = hwif->channel;
296 struct pci_dev *pdev = hwif->pci_dev;
297
292 if (!hwif->irq) 298 if (!hwif->irq)
293 hwif->irq = hwif->channel ? 15 : 14; 299 hwif->irq = ch ? 15 : 14;
294 300
295 hwif->autodma = 0; 301 hwif->autodma = 0;
296 hwif->tuneproc = &atiixp_tuneproc; 302 hwif->tuneproc = &atiixp_tuneproc;
@@ -306,8 +312,12 @@ static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
306 hwif->mwdma_mask = 0x06; 312 hwif->mwdma_mask = 0x06;
307 hwif->swdma_mask = 0x04; 313 hwif->swdma_mask = 0x04;
308 314
309 /* FIXME: proper cable detection needed */ 315 pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ch, &udma_mode);
310 hwif->udma_four = 1; 316 if ((udma_mode & 0x07) >= 0x04 || (udma_mode & 0x70) >= 0x40)
317 hwif->udma_four = 1;
318 else
319 hwif->udma_four = 0;
320
311 hwif->ide_dma_host_on = &atiixp_ide_dma_host_on; 321 hwif->ide_dma_host_on = &atiixp_ide_dma_host_on;
312 hwif->ide_dma_host_off = &atiixp_ide_dma_host_off; 322 hwif->ide_dma_host_off = &atiixp_ide_dma_host_off;
313 hwif->ide_dma_check = &atiixp_dma_check; 323 hwif->ide_dma_check = &atiixp_dma_check;
@@ -318,19 +328,6 @@ static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
318 hwif->drives[0].autodma = hwif->autodma; 328 hwif->drives[0].autodma = hwif->autodma;
319} 329}
320 330
321static void __devinit init_hwif_sb600_legacy(ide_hwif_t *hwif)
322{
323
324 hwif->atapi_dma = 1;
325 hwif->ultra_mask = 0x7f;
326 hwif->mwdma_mask = 0x07;
327 hwif->swdma_mask = 0x07;
328
329 if (!noautodma)
330 hwif->autodma = 1;
331 hwif->drives[0].autodma = hwif->autodma;
332 hwif->drives[1].autodma = hwif->autodma;
333}
334 331
335static ide_pci_device_t atiixp_pci_info[] __devinitdata = { 332static ide_pci_device_t atiixp_pci_info[] __devinitdata = {
336 { /* 0 */ 333 { /* 0 */
@@ -341,12 +338,13 @@ static ide_pci_device_t atiixp_pci_info[] __devinitdata = {
341 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, 338 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
342 .bootable = ON_BOARD, 339 .bootable = ON_BOARD,
343 },{ /* 1 */ 340 },{ /* 1 */
344 .name = "ATI SB600 SATA Legacy IDE", 341 .name = "SB600_PATA",
345 .init_hwif = init_hwif_sb600_legacy, 342 .init_hwif = init_hwif_atiixp,
346 .channels = 2, 343 .channels = 1,
347 .autodma = AUTODMA, 344 .autodma = AUTODMA,
348 .bootable = ON_BOARD, 345 .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}},
349 } 346 .bootable = ON_BOARD,
347 },
350}; 348};
351 349
352/** 350/**
@@ -367,8 +365,7 @@ static struct pci_device_id atiixp_pci_tbl[] = {
367 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 365 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
368 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 366 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
369 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 367 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
370 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 368 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
371 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, PCI_ANY_ID, PCI_ANY_ID, (PCI_CLASS_STORAGE_IDE<<8)|0x8a, 0xffff05, 1},
372 { 0, }, 369 { 0, },
373}; 370};
374MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl); 371MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
@@ -379,7 +376,7 @@ static struct pci_driver driver = {
379 .probe = atiixp_init_one, 376 .probe = atiixp_init_one,
380}; 377};
381 378
382static int atiixp_ide_init(void) 379static int __init atiixp_ide_init(void)
383{ 380{
384 return ide_pci_register_driver(&driver); 381 return ide_pci_register_driver(&driver);
385} 382}
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 20c32716bb..aee947e8fc 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -793,7 +793,7 @@ static struct pci_driver driver = {
793 .probe = cmd64x_init_one, 793 .probe = cmd64x_init_one,
794}; 794};
795 795
796static int cmd64x_ide_init(void) 796static int __init cmd64x_ide_init(void)
797{ 797{
798 return ide_pci_register_driver(&driver); 798 return ide_pci_register_driver(&driver);
799} 799}
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index 079f7c8672..ba6786aabf 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -260,7 +260,7 @@ static struct pci_driver driver = {
260 .probe = cs5520_init_one, 260 .probe = cs5520_init_one,
261}; 261};
262 262
263static int cs5520_ide_init(void) 263static int __init cs5520_ide_init(void)
264{ 264{
265 return ide_pci_register_driver(&driver); 265 return ide_pci_register_driver(&driver);
266} 266}
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index ae405fa322..9bf5fdfc5b 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -374,7 +374,7 @@ static struct pci_driver driver = {
374 .probe = cs5530_init_one, 374 .probe = cs5530_init_one,
375}; 375};
376 376
377static int cs5530_ide_init(void) 377static int __init cs5530_ide_init(void)
378{ 378{
379 return ide_pci_register_driver(&driver); 379 return ide_pci_register_driver(&driver);
380} 380}
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 64330c459b..9eafcbf444 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -519,7 +519,7 @@ static struct pci_driver driver = {
519 .probe = cy82c693_init_one, 519 .probe = cy82c693_init_one,
520}; 520};
521 521
522static int cy82c693_ide_init(void) 522static int __init cy82c693_ide_init(void)
523{ 523{
524 return ide_pci_register_driver(&driver); 524 return ide_pci_register_driver(&driver);
525} 525}
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 9f30688049..b408c6c517 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -185,36 +185,6 @@ static ide_pci_device_t generic_chipsets[] __devinitdata = {
185 .channels = 2, 185 .channels = 2,
186 .autodma = AUTODMA, 186 .autodma = AUTODMA,
187 .bootable = OFF_BOARD, 187 .bootable = OFF_BOARD,
188 },{ /* 15 */
189 .name = "JMB361",
190 .init_hwif = init_hwif_generic,
191 .channels = 2,
192 .autodma = AUTODMA,
193 .bootable = OFF_BOARD,
194 },{ /* 16 */
195 .name = "JMB363",
196 .init_hwif = init_hwif_generic,
197 .channels = 2,
198 .autodma = AUTODMA,
199 .bootable = OFF_BOARD,
200 },{ /* 17 */
201 .name = "JMB365",
202 .init_hwif = init_hwif_generic,
203 .channels = 2,
204 .autodma = AUTODMA,
205 .bootable = OFF_BOARD,
206 },{ /* 18 */
207 .name = "JMB366",
208 .init_hwif = init_hwif_generic,
209 .channels = 2,
210 .autodma = AUTODMA,
211 .bootable = OFF_BOARD,
212 },{ /* 19 */
213 .name = "JMB368",
214 .init_hwif = init_hwif_generic,
215 .channels = 2,
216 .autodma = AUTODMA,
217 .bootable = OFF_BOARD,
218 } 188 }
219}; 189};
220 190
@@ -281,11 +251,6 @@ static struct pci_device_id generic_pci_tbl[] = {
281 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12}, 251 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12},
282 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13}, 252 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13},
283 { PCI_VENDOR_ID_NETCELL,PCI_DEVICE_ID_REVOLUTION, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14}, 253 { PCI_VENDOR_ID_NETCELL,PCI_DEVICE_ID_REVOLUTION, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14},
284 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 15},
285 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 16},
286 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 17},
287 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 18},
288 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 19},
289 /* Must come last. If you add entries adjust this table appropriately and the init_one code */ 254 /* Must come last. If you add entries adjust this table appropriately and the init_one code */
290 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 0}, 255 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 0},
291 { 0, }, 256 { 0, },
@@ -298,7 +263,7 @@ static struct pci_driver driver = {
298 .probe = generic_init_one, 263 .probe = generic_init_one,
299}; 264};
300 265
301static int generic_ide_init(void) 266static int __init generic_ide_init(void)
302{ 267{
303 return ide_pci_register_driver(&driver); 268 return ide_pci_register_driver(&driver);
304} 269}
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index b46cb04229..ce7b08f08a 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -265,7 +265,7 @@ static struct pci_driver driver = {
265 .probe = hpt34x_init_one, 265 .probe = hpt34x_init_one,
266}; 266};
267 267
268static int hpt34x_ide_init(void) 268static int __init hpt34x_ide_init(void)
269{ 269{
270 return ide_pci_register_driver(&driver); 270 return ide_pci_register_driver(&driver);
271} 271}
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 08119da06d..b486442dd5 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -1613,7 +1613,7 @@ static struct pci_driver driver = {
1613 .probe = hpt366_init_one, 1613 .probe = hpt366_init_one,
1614}; 1614};
1615 1615
1616static int hpt366_ide_init(void) 1616static int __init hpt366_ide_init(void)
1617{ 1617{
1618 return ide_pci_register_driver(&driver); 1618 return ide_pci_register_driver(&driver);
1619} 1619}
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index c1cec236ec..f07bbbed17 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -86,15 +86,16 @@ static int __devinit ata66_jmicron(ide_hwif_t *hwif)
86 { 86 {
87 case PORT_PATA0: 87 case PORT_PATA0:
88 if (control & (1 << 3)) /* 40/80 pin primary */ 88 if (control & (1 << 3)) /* 40/80 pin primary */
89 return 1; 89 return 0;
90 return 0; 90 return 1;
91 case PORT_PATA1: 91 case PORT_PATA1:
92 if (control5 & (1 << 19)) /* 40/80 pin secondary */ 92 if (control5 & (1 << 19)) /* 40/80 pin secondary */
93 return 0; 93 return 0;
94 return 1; 94 return 1;
95 case PORT_SATA: 95 case PORT_SATA:
96 return 1; 96 break;
97 } 97 }
98 return 1; /* Avoid bogus "control reaches end of non-void function" */
98} 99}
99 100
100static void jmicron_tuneproc (ide_drive_t *drive, byte mode_wanted) 101static void jmicron_tuneproc (ide_drive_t *drive, byte mode_wanted)
@@ -240,11 +241,11 @@ static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_devi
240} 241}
241 242
242static struct pci_device_id jmicron_pci_tbl[] = { 243static struct pci_device_id jmicron_pci_tbl[] = {
243 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361), 0}, 244 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
244 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363), 1}, 245 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
245 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365), 2}, 246 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
246 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366), 3}, 247 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
247 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368), 4}, 248 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
248 { 0, }, 249 { 0, },
249}; 250};
250 251
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index d95714bcee..8aaea4ea55 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -302,7 +302,7 @@ static struct pci_driver driver = {
302 .probe = ns87415_init_one, 302 .probe = ns87415_init_one,
303}; 303};
304 304
305static int ns87415_ide_init(void) 305static int __init ns87415_ide_init(void)
306{ 306{
307 return ide_pci_register_driver(&driver); 307 return ide_pci_register_driver(&driver);
308} 308}
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index 7a7c2ef78a..22bbf613f9 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -382,7 +382,7 @@ static struct pci_driver driver = {
382 .probe = opti621_init_one, 382 .probe = opti621_init_one,
383}; 383};
384 384
385static int opti621_ide_init(void) 385static int __init opti621_ide_init(void)
386{ 386{
387 return ide_pci_register_driver(&driver); 387 return ide_pci_register_driver(&driver);
388} 388}
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 7cb48576e4..77a9aaa7da 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -756,7 +756,7 @@ static struct pci_driver driver = {
756 .probe = pdc202new_init_one, 756 .probe = pdc202new_init_one,
757}; 757};
758 758
759static int pdc202new_ide_init(void) 759static int __init pdc202new_ide_init(void)
760{ 760{
761 return ide_pci_register_driver(&driver); 761 return ide_pci_register_driver(&driver);
762} 762}
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index 184cdacdde..143239c093 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -719,7 +719,7 @@ static struct pci_driver driver = {
719 .probe = pdc202xx_init_one, 719 .probe = pdc202xx_init_one,
720}; 720};
721 721
722static int pdc202xx_ide_init(void) 722static int __init pdc202xx_ide_init(void)
723{ 723{
724 return ide_pci_register_driver(&driver); 724 return ide_pci_register_driver(&driver);
725} 725}
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index b1e9a8eba6..edb37f3d55 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -1,13 +1,14 @@
1/* 1/*
2 * linux/drivers/ide/pci/piix.c Version 0.44 March 20, 2003 2 * linux/drivers/ide/pci/piix.c Version 0.45 May 12, 2006
3 * 3 *
4 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer 4 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
5 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 5 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
6 * Copyright (C) 2003 Red Hat Inc <alan@redhat.com> 6 * Copyright (C) 2003 Red Hat Inc <alan@redhat.com>
7 * Copyright (C) 2006 MontaVista Software, Inc. <source@mvista.com>
7 * 8 *
8 * May be copied or modified under the terms of the GNU General Public License 9 * May be copied or modified under the terms of the GNU General Public License
9 * 10 *
10 * PIO mode setting function for Intel chipsets. 11 * PIO mode setting function for Intel chipsets.
11 * For use instead of BIOS settings. 12 * For use instead of BIOS settings.
12 * 13 *
13 * 40-41 14 * 40-41
@@ -25,7 +26,7 @@
25 * sitre = word42 & 0x4000; secondary 26 * sitre = word42 & 0x4000; secondary
26 * 27 *
27 * 44 8421|8421 hdd|hdb 28 * 44 8421|8421 hdd|hdb
28 * 29 *
29 * 48 8421 hdd|hdc|hdb|hda udma enabled 30 * 48 8421 hdd|hdc|hdb|hda udma enabled
30 * 31 *
31 * 0001 hda 32 * 0001 hda
@@ -353,56 +354,24 @@ static int piix_tune_chipset (ide_drive_t *drive, u8 xferspeed)
353} 354}
354 355
355/** 356/**
356 * piix_faulty_dma0 - check for DMA0 errata
357 * @hwif: IDE interface to check
358 *
359 * If an ICH/ICH0/ICH2 interface is is operating in multi-word
360 * DMA mode with 600nS cycle time the IDE PIO prefetch buffer will
361 * inadvertently provide an extra piece of secondary data to the primary
362 * device resulting in data corruption.
363 *
364 * With such a device this test function returns true. This allows
365 * our tuning code to follow Intel recommendations and use PIO on
366 * such devices.
367 */
368
369static int piix_faulty_dma0(ide_hwif_t *hwif)
370{
371 switch(hwif->pci_dev->device)
372 {
373 case PCI_DEVICE_ID_INTEL_82801AA_1: /* ICH */
374 case PCI_DEVICE_ID_INTEL_82801AB_1: /* ICH0 */
375 case PCI_DEVICE_ID_INTEL_82801BA_8: /* ICH2 */
376 case PCI_DEVICE_ID_INTEL_82801BA_9: /* ICH2 */
377 return 1;
378 }
379 return 0;
380}
381
382/**
383 * piix_config_drive_for_dma - configure drive for DMA 357 * piix_config_drive_for_dma - configure drive for DMA
384 * @drive: IDE drive to configure 358 * @drive: IDE drive to configure
385 * 359 *
386 * Set up a PIIX interface channel for the best available speed. 360 * Set up a PIIX interface channel for the best available speed.
387 * We prefer UDMA if it is available and then MWDMA. If DMA is 361 * We prefer UDMA if it is available and then MWDMA. If DMA is
388 * not available we switch to PIO and return 0. 362 * not available we switch to PIO and return 0.
389 */ 363 */
390 364
391static int piix_config_drive_for_dma (ide_drive_t *drive) 365static int piix_config_drive_for_dma (ide_drive_t *drive)
392{ 366{
393 u8 speed = ide_dma_speed(drive, piix_ratemask(drive)); 367 u8 speed = ide_dma_speed(drive, piix_ratemask(drive));
394 368
395 /* Some ICH devices cannot support DMA mode 0 */ 369 /*
396 if(speed == XFER_MW_DMA_0 && piix_faulty_dma0(HWIF(drive))) 370 * If no DMA speed was available or the chipset has DMA bugs
397 speed = 0; 371 * then disable DMA and use PIO
398 372 */
399 /* If no DMA speed was available or the chipset has DMA bugs 373 if (!speed || no_piix_dma)
400 then disable DMA and use PIO */ 374 return 0;
401
402 if (!speed || no_piix_dma) {
403 u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL);
404 speed = piix_dma_2_pio(XFER_PIO_0 + tspeed);
405 }
406 375
407 (void) piix_tune_chipset(drive, speed); 376 (void) piix_tune_chipset(drive, speed);
408 return ide_dma_enable(drive); 377 return ide_dma_enable(drive);
@@ -425,17 +394,16 @@ static int piix_config_drive_xfer_rate (ide_drive_t *drive)
425 394
426 if ((id->capability & 1) && drive->autodma) { 395 if ((id->capability & 1) && drive->autodma) {
427 396
428 if (ide_use_dma(drive)) { 397 if (ide_use_dma(drive) && piix_config_drive_for_dma(drive))
429 if (piix_config_drive_for_dma(drive)) 398 return hwif->ide_dma_on(drive);
430 return hwif->ide_dma_on(drive);
431 }
432 399
433 goto fast_ata_pio; 400 goto fast_ata_pio;
434 401
435 } else if ((id->capability & 8) || (id->field_valid & 2)) { 402 } else if ((id->capability & 8) || (id->field_valid & 2)) {
436fast_ata_pio: 403fast_ata_pio:
437 /* Find best PIO mode. */ 404 /* Find best PIO mode. */
438 hwif->tuneproc(drive, 255); 405 (void) hwif->speedproc(drive, XFER_PIO_0 +
406 ide_get_best_pio_mode(drive, 255, 4, NULL));
439 return hwif->ide_dma_off_quietly(drive); 407 return hwif->ide_dma_off_quietly(drive);
440 } 408 }
441 /* IORDY not supported */ 409 /* IORDY not supported */
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c
index 5f6950c2d1..c185531105 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/pci/rz1000.c
@@ -77,7 +77,7 @@ static struct pci_driver driver = {
77 .probe = rz1000_init_one, 77 .probe = rz1000_init_one,
78}; 78};
79 79
80static int rz1000_ide_init(void) 80static int __init rz1000_ide_init(void)
81{ 81{
82 return ide_pci_register_driver(&driver); 82 return ide_pci_register_driver(&driver);
83} 83}
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index ff80937d94..8d762d323f 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -507,7 +507,7 @@ static struct pci_driver driver = {
507#endif 507#endif
508}; 508};
509 509
510static int sc1200_ide_init(void) 510static int __init sc1200_ide_init(void)
511{ 511{
512 return ide_pci_register_driver(&driver); 512 return ide_pci_register_driver(&driver);
513} 513}
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index 057548d072..ea9a28a458 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -666,7 +666,7 @@ static struct pci_driver driver = {
666 .probe = svwks_init_one, 666 .probe = svwks_init_one,
667}; 667};
668 668
669static int svwks_ide_init(void) 669static int __init svwks_ide_init(void)
670{ 670{
671 return ide_pci_register_driver(&driver); 671 return ide_pci_register_driver(&driver);
672} 672}
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index cfad09accf..b0bf018092 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -762,8 +762,7 @@ static struct ioc4_submodule ioc4_ide_submodule = {
762/* .is_remove = ioc4_ide_remove_one, */ 762/* .is_remove = ioc4_ide_remove_one, */
763}; 763};
764 764
765static int __devinit 765static int __init ioc4_ide_init(void)
766ioc4_ide_init(void)
767{ 766{
768 return ioc4_register_submodule(&ioc4_ide_submodule); 767 return ioc4_register_submodule(&ioc4_ide_submodule);
769} 768}
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 697f566fb9..4ff89c7d99 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -1096,7 +1096,7 @@ static struct pci_driver driver = {
1096 .probe = siimage_init_one, 1096 .probe = siimage_init_one,
1097}; 1097};
1098 1098
1099static int siimage_ide_init(void) 1099static int __init siimage_ide_init(void)
1100{ 1100{
1101 return ide_pci_register_driver(&driver); 1101 return ide_pci_register_driver(&driver);
1102} 1102}
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 6b313139b5..1afff659ab 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -968,7 +968,7 @@ static struct pci_driver driver = {
968 .probe = sis5513_init_one, 968 .probe = sis5513_init_one,
969}; 969};
970 970
971static int sis5513_ide_init(void) 971static int __init sis5513_ide_init(void)
972{ 972{
973 return ide_pci_register_driver(&driver); 973 return ide_pci_register_driver(&driver);
974} 974}
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 5afefe8692..170a261990 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -492,7 +492,7 @@ static struct pci_driver driver = {
492 .probe = sl82c105_init_one, 492 .probe = sl82c105_init_one,
493}; 493};
494 494
495static int sl82c105_ide_init(void) 495static int __init sl82c105_ide_init(void)
496{ 496{
497 return ide_pci_register_driver(&driver); 497 return ide_pci_register_driver(&driver);
498} 498}
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 4a1853af3b..90e79c0844 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -1,9 +1,10 @@
1/* 1/*
2 * linux/drivers/ide/pci/slc90e66.c Version 0.11 September 11, 2002 2 * linux/drivers/ide/pci/slc90e66.c Version 0.12 May 12, 2006
3 * 3 *
4 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2006 MontaVista Software, Inc. <source@mvista.com>
5 * 6 *
6 * This a look-a-like variation of the ICH0 PIIX4 Ultra-66, 7 * This is a look-alike variation of the ICH0 PIIX4 Ultra-66,
7 * but this keeps the ISA-Bridge and slots alive. 8 * but this keeps the ISA-Bridge and slots alive.
8 * 9 *
9 */ 10 */
@@ -158,10 +159,8 @@ static int slc90e66_config_drive_for_dma (ide_drive_t *drive)
158{ 159{
159 u8 speed = ide_dma_speed(drive, slc90e66_ratemask(drive)); 160 u8 speed = ide_dma_speed(drive, slc90e66_ratemask(drive));
160 161
161 if (!(speed)) { 162 if (!speed)
162 u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); 163 return 0;
163 speed = slc90e66_dma_2_pio(XFER_PIO_0 + tspeed);
164 }
165 164
166 (void) slc90e66_tune_chipset(drive, speed); 165 (void) slc90e66_tune_chipset(drive, speed);
167 return ide_dma_enable(drive); 166 return ide_dma_enable(drive);
@@ -176,16 +175,15 @@ static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive)
176 175
177 if (id && (id->capability & 1) && drive->autodma) { 176 if (id && (id->capability & 1) && drive->autodma) {
178 177
179 if (ide_use_dma(drive)) { 178 if (ide_use_dma(drive) && slc90e66_config_drive_for_dma(drive))
180 if (slc90e66_config_drive_for_dma(drive)) 179 return hwif->ide_dma_on(drive);
181 return hwif->ide_dma_on(drive);
182 }
183 180
184 goto fast_ata_pio; 181 goto fast_ata_pio;
185 182
186 } else if ((id->capability & 8) || (id->field_valid & 2)) { 183 } else if ((id->capability & 8) || (id->field_valid & 2)) {
187fast_ata_pio: 184fast_ata_pio:
188 hwif->tuneproc(drive, 5); 185 (void) hwif->speedproc(drive, XFER_PIO_0 +
186 ide_get_best_pio_mode(drive, 255, 4, NULL));
189 return hwif->ide_dma_off_quietly(drive); 187 return hwif->ide_dma_off_quietly(drive);
190 } 188 }
191 /* IORDY not supported */ 189 /* IORDY not supported */
@@ -255,7 +253,7 @@ static struct pci_driver driver = {
255 .probe = slc90e66_init_one, 253 .probe = slc90e66_init_one,
256}; 254};
257 255
258static int slc90e66_ide_init(void) 256static int __init slc90e66_ide_init(void)
259{ 257{
260 return ide_pci_register_driver(&driver); 258 return ide_pci_register_driver(&driver);
261} 259}
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index 56d84931d6..b13cce1fd1 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -173,7 +173,7 @@ static struct pci_driver driver = {
173 .probe = triflex_init_one, 173 .probe = triflex_init_one,
174}; 174};
175 175
176static int triflex_ide_init(void) 176static int __init triflex_ide_init(void)
177{ 177{
178 return ide_pci_register_driver(&driver); 178 return ide_pci_register_driver(&driver);
179} 179}
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index 2a282529bf..174b88c478 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -355,7 +355,7 @@ static struct pci_driver driver = {
355 .probe = trm290_init_one, 355 .probe = trm290_init_one,
356}; 356};
357 357
358static int trm290_ide_init(void) 358static int __init trm290_ide_init(void)
359{ 359{
360 return ide_pci_register_driver(&driver); 360 return ide_pci_register_driver(&driver);
361} 361}
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 61f1a9665a..6fb6e50b82 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -78,6 +78,8 @@ static struct via_isa_bridge {
78 u8 rev_max; 78 u8 rev_max;
79 u16 flags; 79 u16 flags;
80} via_isa_bridges[] = { 80} via_isa_bridges[] = {
81 { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
82 { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
81 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 83 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
82 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 84 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
83 { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 85 { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
@@ -123,7 +125,7 @@ struct via82cxxx_dev
123static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing) 125static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing)
124{ 126{
125 struct pci_dev *dev = hwif->pci_dev; 127 struct pci_dev *dev = hwif->pci_dev;
126 struct via82cxxx_dev *vdev = ide_get_hwifdata(hwif); 128 struct via82cxxx_dev *vdev = pci_get_drvdata(hwif->pci_dev);
127 u8 t; 129 u8 t;
128 130
129 if (~vdev->via_config->flags & VIA_BAD_AST) { 131 if (~vdev->via_config->flags & VIA_BAD_AST) {
@@ -162,7 +164,7 @@ static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing)
162static int via_set_drive(ide_drive_t *drive, u8 speed) 164static int via_set_drive(ide_drive_t *drive, u8 speed)
163{ 165{
164 ide_drive_t *peer = HWIF(drive)->drives + (~drive->dn & 1); 166 ide_drive_t *peer = HWIF(drive)->drives + (~drive->dn & 1);
165 struct via82cxxx_dev *vdev = ide_get_hwifdata(drive->hwif); 167 struct via82cxxx_dev *vdev = pci_get_drvdata(drive->hwif->pci_dev);
166 struct ide_timing t, p; 168 struct ide_timing t, p;
167 unsigned int T, UT; 169 unsigned int T, UT;
168 170
@@ -225,7 +227,7 @@ static void via82cxxx_tune_drive(ide_drive_t *drive, u8 pio)
225static int via82cxxx_ide_dma_check (ide_drive_t *drive) 227static int via82cxxx_ide_dma_check (ide_drive_t *drive)
226{ 228{
227 ide_hwif_t *hwif = HWIF(drive); 229 ide_hwif_t *hwif = HWIF(drive);
228 struct via82cxxx_dev *vdev = ide_get_hwifdata(hwif); 230 struct via82cxxx_dev *vdev = pci_get_drvdata(hwif->pci_dev);
229 u16 w80 = hwif->udma_four; 231 u16 w80 = hwif->udma_four;
230 232
231 u16 speed = ide_find_best_mode(drive, 233 u16 speed = ide_find_best_mode(drive,
@@ -262,6 +264,53 @@ static struct via_isa_bridge *via_config_find(struct pci_dev **isa)
262 return via_config; 264 return via_config;
263} 265}
264 266
267/*
268 * Check and handle 80-wire cable presence
269 */
270static void __devinit via_cable_detect(struct via82cxxx_dev *vdev, u32 u)
271{
272 int i;
273
274 switch (vdev->via_config->flags & VIA_UDMA) {
275 case VIA_UDMA_66:
276 for (i = 24; i >= 0; i -= 8)
277 if (((u >> (i & 16)) & 8) &&
278 ((u >> i) & 0x20) &&
279 (((u >> i) & 7) < 2)) {
280 /*
281 * 2x PCI clock and
282 * UDMA w/ < 3T/cycle
283 */
284 vdev->via_80w |= (1 << (1 - (i >> 4)));
285 }
286 break;
287
288 case VIA_UDMA_100:
289 for (i = 24; i >= 0; i -= 8)
290 if (((u >> i) & 0x10) ||
291 (((u >> i) & 0x20) &&
292 (((u >> i) & 7) < 4))) {
293 /* BIOS 80-wire bit or
294 * UDMA w/ < 60ns/cycle
295 */
296 vdev->via_80w |= (1 << (1 - (i >> 4)));
297 }
298 break;
299
300 case VIA_UDMA_133:
301 for (i = 24; i >= 0; i -= 8)
302 if (((u >> i) & 0x10) ||
303 (((u >> i) & 0x20) &&
304 (((u >> i) & 7) < 6))) {
305 /* BIOS 80-wire bit or
306 * UDMA w/ < 60ns/cycle
307 */
308 vdev->via_80w |= (1 << (1 - (i >> 4)));
309 }
310 break;
311 }
312}
313
265/** 314/**
266 * init_chipset_via82cxxx - initialization handler 315 * init_chipset_via82cxxx - initialization handler
267 * @dev: PCI device 316 * @dev: PCI device
@@ -274,14 +323,22 @@ static struct via_isa_bridge *via_config_find(struct pci_dev **isa)
274static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev, const char *name) 323static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev, const char *name)
275{ 324{
276 struct pci_dev *isa = NULL; 325 struct pci_dev *isa = NULL;
326 struct via82cxxx_dev *vdev;
277 struct via_isa_bridge *via_config; 327 struct via_isa_bridge *via_config;
278 u8 t, v; 328 u8 t, v;
279 unsigned int u; 329 u32 u;
330
331 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
332 if (!vdev) {
333 printk(KERN_ERR "VP_IDE: out of memory :(\n");
334 return -ENOMEM;
335 }
336 pci_set_drvdata(dev, vdev);
280 337
281 /* 338 /*
282 * Find the ISA bridge to see how good the IDE is. 339 * Find the ISA bridge to see how good the IDE is.
283 */ 340 */
284 via_config = via_config_find(&isa); 341 vdev->via_config = via_config = via_config_find(&isa);
285 342
286 /* We checked this earlier so if it fails here deeep badness 343 /* We checked this earlier so if it fails here deeep badness
287 is involved */ 344 is involved */
@@ -289,16 +346,17 @@ static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev, const
289 BUG_ON(!via_config->id); 346 BUG_ON(!via_config->id);
290 347
291 /* 348 /*
292 * Setup or disable Clk66 if appropriate 349 * Detect cable and configure Clk66
293 */ 350 */
351 pci_read_config_dword(dev, VIA_UDMA_TIMING, &u);
352
353 via_cable_detect(vdev, u);
294 354
295 if ((via_config->flags & VIA_UDMA) == VIA_UDMA_66) { 355 if ((via_config->flags & VIA_UDMA) == VIA_UDMA_66) {
296 /* Enable Clk66 */ 356 /* Enable Clk66 */
297 pci_read_config_dword(dev, VIA_UDMA_TIMING, &u);
298 pci_write_config_dword(dev, VIA_UDMA_TIMING, u|0x80008); 357 pci_write_config_dword(dev, VIA_UDMA_TIMING, u|0x80008);
299 } else if (via_config->flags & VIA_BAD_CLK66) { 358 } else if (via_config->flags & VIA_BAD_CLK66) {
300 /* Would cause trouble on 596a and 686 */ 359 /* Would cause trouble on 596a and 686 */
301 pci_read_config_dword(dev, VIA_UDMA_TIMING, &u);
302 pci_write_config_dword(dev, VIA_UDMA_TIMING, u & ~0x80008); 360 pci_write_config_dword(dev, VIA_UDMA_TIMING, u & ~0x80008);
303 } 361 }
304 362
@@ -367,75 +425,11 @@ static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev, const
367 return 0; 425 return 0;
368} 426}
369 427
370/*
371 * Check and handle 80-wire cable presence
372 */
373static void __devinit via_cable_detect(struct pci_dev *dev, struct via82cxxx_dev *vdev)
374{
375 unsigned int u;
376 int i;
377 pci_read_config_dword(dev, VIA_UDMA_TIMING, &u);
378
379 switch (vdev->via_config->flags & VIA_UDMA) {
380
381 case VIA_UDMA_66:
382 for (i = 24; i >= 0; i -= 8)
383 if (((u >> (i & 16)) & 8) &&
384 ((u >> i) & 0x20) &&
385 (((u >> i) & 7) < 2)) {
386 /*
387 * 2x PCI clock and
388 * UDMA w/ < 3T/cycle
389 */
390 vdev->via_80w |= (1 << (1 - (i >> 4)));
391 }
392 break;
393
394 case VIA_UDMA_100:
395 for (i = 24; i >= 0; i -= 8)
396 if (((u >> i) & 0x10) ||
397 (((u >> i) & 0x20) &&
398 (((u >> i) & 7) < 4))) {
399 /* BIOS 80-wire bit or
400 * UDMA w/ < 60ns/cycle
401 */
402 vdev->via_80w |= (1 << (1 - (i >> 4)));
403 }
404 break;
405
406 case VIA_UDMA_133:
407 for (i = 24; i >= 0; i -= 8)
408 if (((u >> i) & 0x10) ||
409 (((u >> i) & 0x20) &&
410 (((u >> i) & 7) < 6))) {
411 /* BIOS 80-wire bit or
412 * UDMA w/ < 60ns/cycle
413 */
414 vdev->via_80w |= (1 << (1 - (i >> 4)));
415 }
416 break;
417
418 }
419}
420
421static void __devinit init_hwif_via82cxxx(ide_hwif_t *hwif) 428static void __devinit init_hwif_via82cxxx(ide_hwif_t *hwif)
422{ 429{
423 struct via82cxxx_dev *vdev = kmalloc(sizeof(struct via82cxxx_dev), 430 struct via82cxxx_dev *vdev = pci_get_drvdata(hwif->pci_dev);
424 GFP_KERNEL);
425 struct pci_dev *isa = NULL;
426 int i; 431 int i;
427 432
428 if (vdev == NULL) {
429 printk(KERN_ERR "VP_IDE: out of memory :(\n");
430 return;
431 }
432
433 memset(vdev, 0, sizeof(struct via82cxxx_dev));
434 ide_set_hwifdata(hwif, vdev);
435
436 vdev->via_config = via_config_find(&isa);
437 via_cable_detect(hwif->pci_dev, vdev);
438
439 hwif->autodma = 0; 433 hwif->autodma = 0;
440 434
441 hwif->tuneproc = &via82cxxx_tune_drive; 435 hwif->tuneproc = &via82cxxx_tune_drive;
@@ -512,6 +506,7 @@ static struct pci_device_id via_pci_tbl[] = {
512 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C576_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 506 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C576_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
513 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 507 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
514 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_6410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, 508 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_6410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
509 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_SATA_EIDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
515 { 0, }, 510 { 0, },
516}; 511};
517MODULE_DEVICE_TABLE(pci, via_pci_tbl); 512MODULE_DEVICE_TABLE(pci, via_pci_tbl);
@@ -522,7 +517,7 @@ static struct pci_driver driver = {
522 .probe = via_init_one, 517 .probe = via_init_one,
523}; 518};
524 519
525static int via_ide_init(void) 520static int __init via_ide_init(void)
526{ 521{
527 return ide_pci_register_driver(&driver); 522 return ide_pci_register_driver(&driver);
528} 523}
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index e68b80b734..4325aac773 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -490,11 +490,11 @@ static int sbp2util_create_command_orb_pool(struct sbp2_lu *lu)
490 spin_unlock_irqrestore(&lu->cmd_orb_lock, flags); 490 spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
491 return -ENOMEM; 491 return -ENOMEM;
492 } 492 }
493 cmd->command_orb_dma = dma_map_single(&hi->host->device, 493 cmd->command_orb_dma = dma_map_single(hi->host->device.parent,
494 &cmd->command_orb, 494 &cmd->command_orb,
495 sizeof(struct sbp2_command_orb), 495 sizeof(struct sbp2_command_orb),
496 DMA_TO_DEVICE); 496 DMA_TO_DEVICE);
497 cmd->sge_dma = dma_map_single(&hi->host->device, 497 cmd->sge_dma = dma_map_single(hi->host->device.parent,
498 &cmd->scatter_gather_element, 498 &cmd->scatter_gather_element,
499 sizeof(cmd->scatter_gather_element), 499 sizeof(cmd->scatter_gather_element),
500 DMA_BIDIRECTIONAL); 500 DMA_BIDIRECTIONAL);
@@ -516,10 +516,11 @@ static void sbp2util_remove_command_orb_pool(struct sbp2_lu *lu)
516 if (!list_empty(&lu->cmd_orb_completed)) 516 if (!list_empty(&lu->cmd_orb_completed))
517 list_for_each_safe(lh, next, &lu->cmd_orb_completed) { 517 list_for_each_safe(lh, next, &lu->cmd_orb_completed) {
518 cmd = list_entry(lh, struct sbp2_command_info, list); 518 cmd = list_entry(lh, struct sbp2_command_info, list);
519 dma_unmap_single(&host->device, cmd->command_orb_dma, 519 dma_unmap_single(host->device.parent,
520 cmd->command_orb_dma,
520 sizeof(struct sbp2_command_orb), 521 sizeof(struct sbp2_command_orb),
521 DMA_TO_DEVICE); 522 DMA_TO_DEVICE);
522 dma_unmap_single(&host->device, cmd->sge_dma, 523 dma_unmap_single(host->device.parent, cmd->sge_dma,
523 sizeof(cmd->scatter_gather_element), 524 sizeof(cmd->scatter_gather_element),
524 DMA_BIDIRECTIONAL); 525 DMA_BIDIRECTIONAL);
525 kfree(cmd); 526 kfree(cmd);
@@ -601,17 +602,17 @@ static void sbp2util_mark_command_completed(struct sbp2_lu *lu,
601 602
602 if (cmd->cmd_dma) { 603 if (cmd->cmd_dma) {
603 if (cmd->dma_type == CMD_DMA_SINGLE) 604 if (cmd->dma_type == CMD_DMA_SINGLE)
604 dma_unmap_single(&host->device, cmd->cmd_dma, 605 dma_unmap_single(host->device.parent, cmd->cmd_dma,
605 cmd->dma_size, cmd->dma_dir); 606 cmd->dma_size, cmd->dma_dir);
606 else if (cmd->dma_type == CMD_DMA_PAGE) 607 else if (cmd->dma_type == CMD_DMA_PAGE)
607 dma_unmap_page(&host->device, cmd->cmd_dma, 608 dma_unmap_page(host->device.parent, cmd->cmd_dma,
608 cmd->dma_size, cmd->dma_dir); 609 cmd->dma_size, cmd->dma_dir);
609 /* XXX: Check for CMD_DMA_NONE bug */ 610 /* XXX: Check for CMD_DMA_NONE bug */
610 cmd->dma_type = CMD_DMA_NONE; 611 cmd->dma_type = CMD_DMA_NONE;
611 cmd->cmd_dma = 0; 612 cmd->cmd_dma = 0;
612 } 613 }
613 if (cmd->sge_buffer) { 614 if (cmd->sge_buffer) {
614 dma_unmap_sg(&host->device, cmd->sge_buffer, 615 dma_unmap_sg(host->device.parent, cmd->sge_buffer,
615 cmd->dma_size, cmd->dma_dir); 616 cmd->dma_size, cmd->dma_dir);
616 cmd->sge_buffer = NULL; 617 cmd->sge_buffer = NULL;
617 } 618 }
@@ -836,37 +837,37 @@ static int sbp2_start_device(struct sbp2_lu *lu)
836 struct sbp2_fwhost_info *hi = lu->hi; 837 struct sbp2_fwhost_info *hi = lu->hi;
837 int error; 838 int error;
838 839
839 lu->login_response = dma_alloc_coherent(&hi->host->device, 840 lu->login_response = dma_alloc_coherent(hi->host->device.parent,
840 sizeof(struct sbp2_login_response), 841 sizeof(struct sbp2_login_response),
841 &lu->login_response_dma, GFP_KERNEL); 842 &lu->login_response_dma, GFP_KERNEL);
842 if (!lu->login_response) 843 if (!lu->login_response)
843 goto alloc_fail; 844 goto alloc_fail;
844 845
845 lu->query_logins_orb = dma_alloc_coherent(&hi->host->device, 846 lu->query_logins_orb = dma_alloc_coherent(hi->host->device.parent,
846 sizeof(struct sbp2_query_logins_orb), 847 sizeof(struct sbp2_query_logins_orb),
847 &lu->query_logins_orb_dma, GFP_KERNEL); 848 &lu->query_logins_orb_dma, GFP_KERNEL);
848 if (!lu->query_logins_orb) 849 if (!lu->query_logins_orb)
849 goto alloc_fail; 850 goto alloc_fail;
850 851
851 lu->query_logins_response = dma_alloc_coherent(&hi->host->device, 852 lu->query_logins_response = dma_alloc_coherent(hi->host->device.parent,
852 sizeof(struct sbp2_query_logins_response), 853 sizeof(struct sbp2_query_logins_response),
853 &lu->query_logins_response_dma, GFP_KERNEL); 854 &lu->query_logins_response_dma, GFP_KERNEL);
854 if (!lu->query_logins_response) 855 if (!lu->query_logins_response)
855 goto alloc_fail; 856 goto alloc_fail;
856 857
857 lu->reconnect_orb = dma_alloc_coherent(&hi->host->device, 858 lu->reconnect_orb = dma_alloc_coherent(hi->host->device.parent,
858 sizeof(struct sbp2_reconnect_orb), 859 sizeof(struct sbp2_reconnect_orb),
859 &lu->reconnect_orb_dma, GFP_KERNEL); 860 &lu->reconnect_orb_dma, GFP_KERNEL);
860 if (!lu->reconnect_orb) 861 if (!lu->reconnect_orb)
861 goto alloc_fail; 862 goto alloc_fail;
862 863
863 lu->logout_orb = dma_alloc_coherent(&hi->host->device, 864 lu->logout_orb = dma_alloc_coherent(hi->host->device.parent,
864 sizeof(struct sbp2_logout_orb), 865 sizeof(struct sbp2_logout_orb),
865 &lu->logout_orb_dma, GFP_KERNEL); 866 &lu->logout_orb_dma, GFP_KERNEL);
866 if (!lu->logout_orb) 867 if (!lu->logout_orb)
867 goto alloc_fail; 868 goto alloc_fail;
868 869
869 lu->login_orb = dma_alloc_coherent(&hi->host->device, 870 lu->login_orb = dma_alloc_coherent(hi->host->device.parent,
870 sizeof(struct sbp2_login_orb), 871 sizeof(struct sbp2_login_orb),
871 &lu->login_orb_dma, GFP_KERNEL); 872 &lu->login_orb_dma, GFP_KERNEL);
872 if (!lu->login_orb) 873 if (!lu->login_orb)
@@ -929,32 +930,32 @@ static void sbp2_remove_device(struct sbp2_lu *lu)
929 list_del(&lu->lu_list); 930 list_del(&lu->lu_list);
930 931
931 if (lu->login_response) 932 if (lu->login_response)
932 dma_free_coherent(&hi->host->device, 933 dma_free_coherent(hi->host->device.parent,
933 sizeof(struct sbp2_login_response), 934 sizeof(struct sbp2_login_response),
934 lu->login_response, 935 lu->login_response,
935 lu->login_response_dma); 936 lu->login_response_dma);
936 if (lu->login_orb) 937 if (lu->login_orb)
937 dma_free_coherent(&hi->host->device, 938 dma_free_coherent(hi->host->device.parent,
938 sizeof(struct sbp2_login_orb), 939 sizeof(struct sbp2_login_orb),
939 lu->login_orb, 940 lu->login_orb,
940 lu->login_orb_dma); 941 lu->login_orb_dma);
941 if (lu->reconnect_orb) 942 if (lu->reconnect_orb)
942 dma_free_coherent(&hi->host->device, 943 dma_free_coherent(hi->host->device.parent,
943 sizeof(struct sbp2_reconnect_orb), 944 sizeof(struct sbp2_reconnect_orb),
944 lu->reconnect_orb, 945 lu->reconnect_orb,
945 lu->reconnect_orb_dma); 946 lu->reconnect_orb_dma);
946 if (lu->logout_orb) 947 if (lu->logout_orb)
947 dma_free_coherent(&hi->host->device, 948 dma_free_coherent(hi->host->device.parent,
948 sizeof(struct sbp2_logout_orb), 949 sizeof(struct sbp2_logout_orb),
949 lu->logout_orb, 950 lu->logout_orb,
950 lu->logout_orb_dma); 951 lu->logout_orb_dma);
951 if (lu->query_logins_orb) 952 if (lu->query_logins_orb)
952 dma_free_coherent(&hi->host->device, 953 dma_free_coherent(hi->host->device.parent,
953 sizeof(struct sbp2_query_logins_orb), 954 sizeof(struct sbp2_query_logins_orb),
954 lu->query_logins_orb, 955 lu->query_logins_orb,
955 lu->query_logins_orb_dma); 956 lu->query_logins_orb_dma);
956 if (lu->query_logins_response) 957 if (lu->query_logins_response)
957 dma_free_coherent(&hi->host->device, 958 dma_free_coherent(hi->host->device.parent,
958 sizeof(struct sbp2_query_logins_response), 959 sizeof(struct sbp2_query_logins_response),
959 lu->query_logins_response, 960 lu->query_logins_response,
960 lu->query_logins_response_dma); 961 lu->query_logins_response_dma);
@@ -1445,7 +1446,7 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
1445 1446
1446 cmd->dma_size = sgpnt[0].length; 1447 cmd->dma_size = sgpnt[0].length;
1447 cmd->dma_type = CMD_DMA_PAGE; 1448 cmd->dma_type = CMD_DMA_PAGE;
1448 cmd->cmd_dma = dma_map_page(&hi->host->device, 1449 cmd->cmd_dma = dma_map_page(hi->host->device.parent,
1449 sgpnt[0].page, sgpnt[0].offset, 1450 sgpnt[0].page, sgpnt[0].offset,
1450 cmd->dma_size, cmd->dma_dir); 1451 cmd->dma_size, cmd->dma_dir);
1451 1452
@@ -1457,8 +1458,8 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
1457 &cmd->scatter_gather_element[0]; 1458 &cmd->scatter_gather_element[0];
1458 u32 sg_count, sg_len; 1459 u32 sg_count, sg_len;
1459 dma_addr_t sg_addr; 1460 dma_addr_t sg_addr;
1460 int i, count = dma_map_sg(&hi->host->device, sgpnt, scsi_use_sg, 1461 int i, count = dma_map_sg(hi->host->device.parent, sgpnt,
1461 dma_dir); 1462 scsi_use_sg, dma_dir);
1462 1463
1463 cmd->dma_size = scsi_use_sg; 1464 cmd->dma_size = scsi_use_sg;
1464 cmd->sge_buffer = sgpnt; 1465 cmd->sge_buffer = sgpnt;
@@ -1508,7 +1509,8 @@ static void sbp2_prep_command_orb_no_sg(struct sbp2_command_orb *orb,
1508 cmd->dma_dir = dma_dir; 1509 cmd->dma_dir = dma_dir;
1509 cmd->dma_size = scsi_request_bufflen; 1510 cmd->dma_size = scsi_request_bufflen;
1510 cmd->dma_type = CMD_DMA_SINGLE; 1511 cmd->dma_type = CMD_DMA_SINGLE;
1511 cmd->cmd_dma = dma_map_single(&hi->host->device, scsi_request_buffer, 1512 cmd->cmd_dma = dma_map_single(hi->host->device.parent,
1513 scsi_request_buffer,
1512 cmd->dma_size, cmd->dma_dir); 1514 cmd->dma_size, cmd->dma_dir);
1513 orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); 1515 orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
1514 orb->misc |= ORB_SET_DIRECTION(orb_direction); 1516 orb->misc |= ORB_SET_DIRECTION(orb_direction);
@@ -1626,10 +1628,11 @@ static void sbp2_link_orb_command(struct sbp2_lu *lu,
1626 size_t length; 1628 size_t length;
1627 unsigned long flags; 1629 unsigned long flags;
1628 1630
1629 dma_sync_single_for_device(&hi->host->device, cmd->command_orb_dma, 1631 dma_sync_single_for_device(hi->host->device.parent,
1632 cmd->command_orb_dma,
1630 sizeof(struct sbp2_command_orb), 1633 sizeof(struct sbp2_command_orb),
1631 DMA_TO_DEVICE); 1634 DMA_TO_DEVICE);
1632 dma_sync_single_for_device(&hi->host->device, cmd->sge_dma, 1635 dma_sync_single_for_device(hi->host->device.parent, cmd->sge_dma,
1633 sizeof(cmd->scatter_gather_element), 1636 sizeof(cmd->scatter_gather_element),
1634 DMA_BIDIRECTIONAL); 1637 DMA_BIDIRECTIONAL);
1635 1638
@@ -1655,14 +1658,15 @@ static void sbp2_link_orb_command(struct sbp2_lu *lu,
1655 * The target's fetch agent may or may not have read this 1658 * The target's fetch agent may or may not have read this
1656 * previous ORB yet. 1659 * previous ORB yet.
1657 */ 1660 */
1658 dma_sync_single_for_cpu(&hi->host->device, last_orb_dma, 1661 dma_sync_single_for_cpu(hi->host->device.parent, last_orb_dma,
1659 sizeof(struct sbp2_command_orb), 1662 sizeof(struct sbp2_command_orb),
1660 DMA_TO_DEVICE); 1663 DMA_TO_DEVICE);
1661 last_orb->next_ORB_lo = cpu_to_be32(cmd->command_orb_dma); 1664 last_orb->next_ORB_lo = cpu_to_be32(cmd->command_orb_dma);
1662 wmb(); 1665 wmb();
1663 /* Tells hardware that this pointer is valid */ 1666 /* Tells hardware that this pointer is valid */
1664 last_orb->next_ORB_hi = 0; 1667 last_orb->next_ORB_hi = 0;
1665 dma_sync_single_for_device(&hi->host->device, last_orb_dma, 1668 dma_sync_single_for_device(hi->host->device.parent,
1669 last_orb_dma,
1666 sizeof(struct sbp2_command_orb), 1670 sizeof(struct sbp2_command_orb),
1667 DMA_TO_DEVICE); 1671 DMA_TO_DEVICE);
1668 addr += SBP2_DOORBELL_OFFSET; 1672 addr += SBP2_DOORBELL_OFFSET;
@@ -1790,10 +1794,11 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
1790 else 1794 else
1791 cmd = sbp2util_find_command_for_orb(lu, sb->ORB_offset_lo); 1795 cmd = sbp2util_find_command_for_orb(lu, sb->ORB_offset_lo);
1792 if (cmd) { 1796 if (cmd) {
1793 dma_sync_single_for_cpu(&hi->host->device, cmd->command_orb_dma, 1797 dma_sync_single_for_cpu(hi->host->device.parent,
1798 cmd->command_orb_dma,
1794 sizeof(struct sbp2_command_orb), 1799 sizeof(struct sbp2_command_orb),
1795 DMA_TO_DEVICE); 1800 DMA_TO_DEVICE);
1796 dma_sync_single_for_cpu(&hi->host->device, cmd->sge_dma, 1801 dma_sync_single_for_cpu(hi->host->device.parent, cmd->sge_dma,
1797 sizeof(cmd->scatter_gather_element), 1802 sizeof(cmd->scatter_gather_element),
1798 DMA_BIDIRECTIONAL); 1803 DMA_BIDIRECTIONAL);
1799 /* Grab SCSI command pointers and check status. */ 1804 /* Grab SCSI command pointers and check status. */
@@ -1882,16 +1887,6 @@ static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt,
1882 if (unlikely(SCpnt->device->lun)) 1887 if (unlikely(SCpnt->device->lun))
1883 goto done; 1888 goto done;
1884 1889
1885 /* handle the request sense command here (auto-request sense) */
1886 if (SCpnt->cmnd[0] == REQUEST_SENSE) {
1887 memcpy(SCpnt->request_buffer, SCpnt->sense_buffer,
1888 SCpnt->request_bufflen);
1889 memset(SCpnt->sense_buffer, 0, sizeof(SCpnt->sense_buffer));
1890 sbp2scsi_complete_command(lu, SBP2_SCSI_STATUS_GOOD, SCpnt,
1891 done);
1892 return 0;
1893 }
1894
1895 if (unlikely(!hpsb_node_entry_valid(lu->ne))) { 1890 if (unlikely(!hpsb_node_entry_valid(lu->ne))) {
1896 SBP2_ERR("Bus reset in progress - rejecting command"); 1891 SBP2_ERR("Bus reset in progress - rejecting command");
1897 result = DID_BUS_BUSY << 16; 1892 result = DID_BUS_BUSY << 16;
@@ -1931,10 +1926,11 @@ static void sbp2scsi_complete_all_commands(struct sbp2_lu *lu, u32 status)
1931 while (!list_empty(&lu->cmd_orb_inuse)) { 1926 while (!list_empty(&lu->cmd_orb_inuse)) {
1932 lh = lu->cmd_orb_inuse.next; 1927 lh = lu->cmd_orb_inuse.next;
1933 cmd = list_entry(lh, struct sbp2_command_info, list); 1928 cmd = list_entry(lh, struct sbp2_command_info, list);
1934 dma_sync_single_for_cpu(&hi->host->device, cmd->command_orb_dma, 1929 dma_sync_single_for_cpu(hi->host->device.parent,
1930 cmd->command_orb_dma,
1935 sizeof(struct sbp2_command_orb), 1931 sizeof(struct sbp2_command_orb),
1936 DMA_TO_DEVICE); 1932 DMA_TO_DEVICE);
1937 dma_sync_single_for_cpu(&hi->host->device, cmd->sge_dma, 1933 dma_sync_single_for_cpu(hi->host->device.parent, cmd->sge_dma,
1938 sizeof(cmd->scatter_gather_element), 1934 sizeof(cmd->scatter_gather_element),
1939 DMA_BIDIRECTIONAL); 1935 DMA_BIDIRECTIONAL);
1940 sbp2util_mark_command_completed(lu, cmd); 1936 sbp2util_mark_command_completed(lu, cmd);
@@ -2024,6 +2020,8 @@ static int sbp2scsi_slave_configure(struct scsi_device *sdev)
2024 blk_queue_dma_alignment(sdev->request_queue, (512 - 1)); 2020 blk_queue_dma_alignment(sdev->request_queue, (512 - 1));
2025 sdev->use_10_for_rw = 1; 2021 sdev->use_10_for_rw = 1;
2026 2022
2023 if (sdev->type == TYPE_ROM)
2024 sdev->use_10_for_ms = 1;
2027 if (sdev->type == TYPE_DISK && 2025 if (sdev->type == TYPE_DISK &&
2028 lu->workarounds & SBP2_WORKAROUND_MODE_SENSE_8) 2026 lu->workarounds & SBP2_WORKAROUND_MODE_SENSE_8)
2029 sdev->skip_ms_page_8 = 1; 2027 sdev->skip_ms_page_8 = 1;
@@ -2059,11 +2057,12 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
2059 spin_lock_irqsave(&lu->cmd_orb_lock, flags); 2057 spin_lock_irqsave(&lu->cmd_orb_lock, flags);
2060 cmd = sbp2util_find_command_for_SCpnt(lu, SCpnt); 2058 cmd = sbp2util_find_command_for_SCpnt(lu, SCpnt);
2061 if (cmd) { 2059 if (cmd) {
2062 dma_sync_single_for_cpu(&hi->host->device, 2060 dma_sync_single_for_cpu(hi->host->device.parent,
2063 cmd->command_orb_dma, 2061 cmd->command_orb_dma,
2064 sizeof(struct sbp2_command_orb), 2062 sizeof(struct sbp2_command_orb),
2065 DMA_TO_DEVICE); 2063 DMA_TO_DEVICE);
2066 dma_sync_single_for_cpu(&hi->host->device, cmd->sge_dma, 2064 dma_sync_single_for_cpu(hi->host->device.parent,
2065 cmd->sge_dma,
2067 sizeof(cmd->scatter_gather_element), 2066 sizeof(cmd->scatter_gather_element),
2068 DMA_BIDIRECTIONAL); 2067 DMA_BIDIRECTIONAL);
2069 sbp2util_mark_command_completed(lu, cmd); 2068 sbp2util_mark_command_completed(lu, cmd);
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 533193d4e5..9e0ab048c8 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -1088,10 +1088,21 @@ static int cma_iw_handler(struct iw_cm_id *iw_id, struct iw_cm_event *iw_event)
1088 *sin = iw_event->local_addr; 1088 *sin = iw_event->local_addr;
1089 sin = (struct sockaddr_in *) &id_priv->id.route.addr.dst_addr; 1089 sin = (struct sockaddr_in *) &id_priv->id.route.addr.dst_addr;
1090 *sin = iw_event->remote_addr; 1090 *sin = iw_event->remote_addr;
1091 if (iw_event->status) 1091 switch (iw_event->status) {
1092 event.event = RDMA_CM_EVENT_REJECTED; 1092 case 0:
1093 else
1094 event.event = RDMA_CM_EVENT_ESTABLISHED; 1093 event.event = RDMA_CM_EVENT_ESTABLISHED;
1094 break;
1095 case -ECONNRESET:
1096 case -ECONNREFUSED:
1097 event.event = RDMA_CM_EVENT_REJECTED;
1098 break;
1099 case -ETIMEDOUT:
1100 event.event = RDMA_CM_EVENT_UNREACHABLE;
1101 break;
1102 default:
1103 event.event = RDMA_CM_EVENT_CONNECT_ERROR;
1104 break;
1105 }
1095 break; 1106 break;
1096 case IW_CM_EVENT_ESTABLISHED: 1107 case IW_CM_EVENT_ESTABLISHED:
1097 event.event = RDMA_CM_EVENT_ESTABLISHED; 1108 event.event = RDMA_CM_EVENT_ESTABLISHED;
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index 81a5cdc573..e2e8d329b4 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -209,10 +209,21 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
209 if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST) { 209 if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST) {
210 if (!ctx->backlog) { 210 if (!ctx->backlog) {
211 ret = -EDQUOT; 211 ret = -EDQUOT;
212 kfree(uevent);
212 goto out; 213 goto out;
213 } 214 }
214 ctx->backlog--; 215 ctx->backlog--;
216 } else if (!ctx->uid) {
217 /*
218 * We ignore events for new connections until userspace has set
219 * their context. This can only happen if an error occurs on a
220 * new connection before the user accepts it. This is okay,
221 * since the accept will just fail later.
222 */
223 kfree(uevent);
224 goto out;
215 } 225 }
226
216 list_add_tail(&uevent->list, &ctx->file->event_list); 227 list_add_tail(&uevent->list, &ctx->file->event_list);
217 wake_up_interruptible(&ctx->file->poll_wait); 228 wake_up_interruptible(&ctx->file->poll_wait);
218out: 229out:
diff --git a/drivers/infiniband/hw/ehca/ehca_cq.c b/drivers/infiniband/hw/ehca/ehca_cq.c
index 93995b658d..6074c897f5 100644
--- a/drivers/infiniband/hw/ehca/ehca_cq.c
+++ b/drivers/infiniband/hw/ehca/ehca_cq.c
@@ -344,8 +344,11 @@ int ehca_destroy_cq(struct ib_cq *cq)
344 unsigned long flags; 344 unsigned long flags;
345 345
346 spin_lock_irqsave(&ehca_cq_idr_lock, flags); 346 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
347 while (my_cq->nr_callbacks) 347 while (my_cq->nr_callbacks) {
348 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
348 yield(); 349 yield();
350 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
351 }
349 352
350 idr_remove(&ehca_cq_idr, my_cq->token); 353 idr_remove(&ehca_cq_idr, my_cq->token);
351 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags); 354 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
diff --git a/drivers/infiniband/hw/ehca/ehca_hca.c b/drivers/infiniband/hw/ehca/ehca_hca.c
index e1b618c5f6..b7be950ab4 100644
--- a/drivers/infiniband/hw/ehca/ehca_hca.c
+++ b/drivers/infiniband/hw/ehca/ehca_hca.c
@@ -50,7 +50,7 @@ int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
50 ib_device); 50 ib_device);
51 struct hipz_query_hca *rblock; 51 struct hipz_query_hca *rblock;
52 52
53 rblock = ehca_alloc_fw_ctrlblock(); 53 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
54 if (!rblock) { 54 if (!rblock) {
55 ehca_err(&shca->ib_device, "Can't allocate rblock memory."); 55 ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
56 return -ENOMEM; 56 return -ENOMEM;
@@ -110,7 +110,7 @@ int ehca_query_port(struct ib_device *ibdev,
110 ib_device); 110 ib_device);
111 struct hipz_query_port *rblock; 111 struct hipz_query_port *rblock;
112 112
113 rblock = ehca_alloc_fw_ctrlblock(); 113 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
114 if (!rblock) { 114 if (!rblock) {
115 ehca_err(&shca->ib_device, "Can't allocate rblock memory."); 115 ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
116 return -ENOMEM; 116 return -ENOMEM;
@@ -179,7 +179,7 @@ int ehca_query_pkey(struct ib_device *ibdev, u8 port, u16 index, u16 *pkey)
179 return -EINVAL; 179 return -EINVAL;
180 } 180 }
181 181
182 rblock = ehca_alloc_fw_ctrlblock(); 182 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
183 if (!rblock) { 183 if (!rblock) {
184 ehca_err(&shca->ib_device, "Can't allocate rblock memory."); 184 ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
185 return -ENOMEM; 185 return -ENOMEM;
@@ -212,7 +212,7 @@ int ehca_query_gid(struct ib_device *ibdev, u8 port,
212 return -EINVAL; 212 return -EINVAL;
213 } 213 }
214 214
215 rblock = ehca_alloc_fw_ctrlblock(); 215 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
216 if (!rblock) { 216 if (!rblock) {
217 ehca_err(&shca->ib_device, "Can't allocate rblock memory."); 217 ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
218 return -ENOMEM; 218 return -ENOMEM;
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.c b/drivers/infiniband/hw/ehca/ehca_irq.c
index c3ea746e90..c069be8cbc 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.c
+++ b/drivers/infiniband/hw/ehca/ehca_irq.c
@@ -138,7 +138,7 @@ int ehca_error_data(struct ehca_shca *shca, void *data,
138 u64 *rblock; 138 u64 *rblock;
139 unsigned long block_count; 139 unsigned long block_count;
140 140
141 rblock = ehca_alloc_fw_ctrlblock(); 141 rblock = ehca_alloc_fw_ctrlblock(GFP_ATOMIC);
142 if (!rblock) { 142 if (!rblock) {
143 ehca_err(&shca->ib_device, "Cannot allocate rblock memory."); 143 ehca_err(&shca->ib_device, "Cannot allocate rblock memory.");
144 ret = -ENOMEM; 144 ret = -ENOMEM;
@@ -440,7 +440,8 @@ void ehca_tasklet_eq(unsigned long data)
440 cq = idr_find(&ehca_cq_idr, token); 440 cq = idr_find(&ehca_cq_idr, token);
441 441
442 if (cq == NULL) { 442 if (cq == NULL) {
443 spin_unlock(&ehca_cq_idr_lock); 443 spin_unlock_irqrestore(&ehca_cq_idr_lock,
444 flags);
444 break; 445 break;
445 } 446 }
446 447
diff --git a/drivers/infiniband/hw/ehca/ehca_iverbs.h b/drivers/infiniband/hw/ehca/ehca_iverbs.h
index 3720e3032c..cd7789f0d0 100644
--- a/drivers/infiniband/hw/ehca/ehca_iverbs.h
+++ b/drivers/infiniband/hw/ehca/ehca_iverbs.h
@@ -180,10 +180,10 @@ int ehca_mmap_register(u64 physical,void **mapped,
180int ehca_munmap(unsigned long addr, size_t len); 180int ehca_munmap(unsigned long addr, size_t len);
181 181
182#ifdef CONFIG_PPC_64K_PAGES 182#ifdef CONFIG_PPC_64K_PAGES
183void *ehca_alloc_fw_ctrlblock(void); 183void *ehca_alloc_fw_ctrlblock(gfp_t flags);
184void ehca_free_fw_ctrlblock(void *ptr); 184void ehca_free_fw_ctrlblock(void *ptr);
185#else 185#else
186#define ehca_alloc_fw_ctrlblock() ((void *) get_zeroed_page(GFP_KERNEL)) 186#define ehca_alloc_fw_ctrlblock(flags) ((void *) get_zeroed_page(flags))
187#define ehca_free_fw_ctrlblock(ptr) free_page((unsigned long)(ptr)) 187#define ehca_free_fw_ctrlblock(ptr) free_page((unsigned long)(ptr))
188#endif 188#endif
189 189
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index cc47e4c13a..6574fbbaea 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -106,9 +106,9 @@ static struct timer_list poll_eqs_timer;
106#ifdef CONFIG_PPC_64K_PAGES 106#ifdef CONFIG_PPC_64K_PAGES
107static struct kmem_cache *ctblk_cache = NULL; 107static struct kmem_cache *ctblk_cache = NULL;
108 108
109void *ehca_alloc_fw_ctrlblock(void) 109void *ehca_alloc_fw_ctrlblock(gfp_t flags)
110{ 110{
111 void *ret = kmem_cache_zalloc(ctblk_cache, GFP_KERNEL); 111 void *ret = kmem_cache_zalloc(ctblk_cache, flags);
112 if (!ret) 112 if (!ret)
113 ehca_gen_err("Out of memory for ctblk"); 113 ehca_gen_err("Out of memory for ctblk");
114 return ret; 114 return ret;
@@ -206,7 +206,7 @@ int ehca_sense_attributes(struct ehca_shca *shca)
206 u64 h_ret; 206 u64 h_ret;
207 struct hipz_query_hca *rblock; 207 struct hipz_query_hca *rblock;
208 208
209 rblock = ehca_alloc_fw_ctrlblock(); 209 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
210 if (!rblock) { 210 if (!rblock) {
211 ehca_gen_err("Cannot allocate rblock memory."); 211 ehca_gen_err("Cannot allocate rblock memory.");
212 return -ENOMEM; 212 return -ENOMEM;
@@ -258,7 +258,7 @@ static int init_node_guid(struct ehca_shca *shca)
258 int ret = 0; 258 int ret = 0;
259 struct hipz_query_hca *rblock; 259 struct hipz_query_hca *rblock;
260 260
261 rblock = ehca_alloc_fw_ctrlblock(); 261 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
262 if (!rblock) { 262 if (!rblock) {
263 ehca_err(&shca->ib_device, "Can't allocate rblock memory."); 263 ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
264 return -ENOMEM; 264 return -ENOMEM;
@@ -469,7 +469,7 @@ static ssize_t ehca_show_##name(struct device *dev, \
469 \ 469 \
470 shca = dev->driver_data; \ 470 shca = dev->driver_data; \
471 \ 471 \
472 rblock = ehca_alloc_fw_ctrlblock(); \ 472 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); \
473 if (!rblock) { \ 473 if (!rblock) { \
474 dev_err(dev, "Can't allocate rblock memory."); \ 474 dev_err(dev, "Can't allocate rblock memory."); \
475 return 0; \ 475 return 0; \
diff --git a/drivers/infiniband/hw/ehca/ehca_mrmw.c b/drivers/infiniband/hw/ehca/ehca_mrmw.c
index 0a5e2214cc..cfb362a102 100644
--- a/drivers/infiniband/hw/ehca/ehca_mrmw.c
+++ b/drivers/infiniband/hw/ehca/ehca_mrmw.c
@@ -1013,7 +1013,7 @@ int ehca_reg_mr_rpages(struct ehca_shca *shca,
1013 u32 i; 1013 u32 i;
1014 u64 *kpage; 1014 u64 *kpage;
1015 1015
1016 kpage = ehca_alloc_fw_ctrlblock(); 1016 kpage = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
1017 if (!kpage) { 1017 if (!kpage) {
1018 ehca_err(&shca->ib_device, "kpage alloc failed"); 1018 ehca_err(&shca->ib_device, "kpage alloc failed");
1019 ret = -ENOMEM; 1019 ret = -ENOMEM;
@@ -1124,7 +1124,7 @@ inline int ehca_rereg_mr_rereg1(struct ehca_shca *shca,
1124 ehca_mrmw_map_acl(acl, &hipz_acl); 1124 ehca_mrmw_map_acl(acl, &hipz_acl);
1125 ehca_mrmw_set_pgsize_hipz_acl(&hipz_acl); 1125 ehca_mrmw_set_pgsize_hipz_acl(&hipz_acl);
1126 1126
1127 kpage = ehca_alloc_fw_ctrlblock(); 1127 kpage = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
1128 if (!kpage) { 1128 if (!kpage) {
1129 ehca_err(&shca->ib_device, "kpage alloc failed"); 1129 ehca_err(&shca->ib_device, "kpage alloc failed");
1130 ret = -ENOMEM; 1130 ret = -ENOMEM;
diff --git a/drivers/infiniband/hw/ehca/ehca_qp.c b/drivers/infiniband/hw/ehca/ehca_qp.c
index c6c9cef203..34b85556d0 100644
--- a/drivers/infiniband/hw/ehca/ehca_qp.c
+++ b/drivers/infiniband/hw/ehca/ehca_qp.c
@@ -807,7 +807,7 @@ static int internal_modify_qp(struct ib_qp *ibqp,
807 unsigned long spl_flags = 0; 807 unsigned long spl_flags = 0;
808 808
809 /* do query_qp to obtain current attr values */ 809 /* do query_qp to obtain current attr values */
810 mqpcb = ehca_alloc_fw_ctrlblock(); 810 mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
811 if (!mqpcb) { 811 if (!mqpcb) {
812 ehca_err(ibqp->device, "Could not get zeroed page for mqpcb " 812 ehca_err(ibqp->device, "Could not get zeroed page for mqpcb "
813 "ehca_qp=%p qp_num=%x ", my_qp, ibqp->qp_num); 813 "ehca_qp=%p qp_num=%x ", my_qp, ibqp->qp_num);
@@ -1273,7 +1273,7 @@ int ehca_query_qp(struct ib_qp *qp,
1273 return -EINVAL; 1273 return -EINVAL;
1274 } 1274 }
1275 1275
1276 qpcb = ehca_alloc_fw_ctrlblock(); 1276 qpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
1277 if (!qpcb) { 1277 if (!qpcb) {
1278 ehca_err(qp->device,"Out of memory for qpcb " 1278 ehca_err(qp->device,"Out of memory for qpcb "
1279 "ehca_qp=%p qp_num=%x", my_qp, qp->qp_num); 1279 "ehca_qp=%p qp_num=%x", my_qp, qp->qp_num);
diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
index 283d50b76c..1159c8a0f2 100644
--- a/drivers/infiniband/hw/mthca/mthca_cq.c
+++ b/drivers/infiniband/hw/mthca/mthca_cq.c
@@ -54,6 +54,10 @@ enum {
54 MTHCA_CQ_ENTRY_SIZE = 0x20 54 MTHCA_CQ_ENTRY_SIZE = 0x20
55}; 55};
56 56
57enum {
58 MTHCA_ATOMIC_BYTE_LEN = 8
59};
60
57/* 61/*
58 * Must be packed because start is 64 bits but only aligned to 32 bits. 62 * Must be packed because start is 64 bits but only aligned to 32 bits.
59 */ 63 */
@@ -599,11 +603,11 @@ static inline int mthca_poll_one(struct mthca_dev *dev,
599 break; 603 break;
600 case MTHCA_OPCODE_ATOMIC_CS: 604 case MTHCA_OPCODE_ATOMIC_CS:
601 entry->opcode = IB_WC_COMP_SWAP; 605 entry->opcode = IB_WC_COMP_SWAP;
602 entry->byte_len = be32_to_cpu(cqe->byte_cnt); 606 entry->byte_len = MTHCA_ATOMIC_BYTE_LEN;
603 break; 607 break;
604 case MTHCA_OPCODE_ATOMIC_FA: 608 case MTHCA_OPCODE_ATOMIC_FA:
605 entry->opcode = IB_WC_FETCH_ADD; 609 entry->opcode = IB_WC_FETCH_ADD;
606 entry->byte_len = be32_to_cpu(cqe->byte_cnt); 610 entry->byte_len = MTHCA_ATOMIC_BYTE_LEN;
607 break; 611 break;
608 case MTHCA_OPCODE_BIND_MW: 612 case MTHCA_OPCODE_BIND_MW:
609 entry->opcode = IB_WC_BIND_MW; 613 entry->opcode = IB_WC_BIND_MW;
diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
index 0491ec7a7c..44bc6cc734 100644
--- a/drivers/infiniband/hw/mthca/mthca_main.c
+++ b/drivers/infiniband/hw/mthca/mthca_main.c
@@ -80,24 +80,61 @@ static int tune_pci = 0;
80module_param(tune_pci, int, 0444); 80module_param(tune_pci, int, 0444);
81MODULE_PARM_DESC(tune_pci, "increase PCI burst from the default set by BIOS if nonzero"); 81MODULE_PARM_DESC(tune_pci, "increase PCI burst from the default set by BIOS if nonzero");
82 82
83struct mutex mthca_device_mutex; 83DEFINE_MUTEX(mthca_device_mutex);
84
85#define MTHCA_DEFAULT_NUM_QP (1 << 16)
86#define MTHCA_DEFAULT_RDB_PER_QP (1 << 2)
87#define MTHCA_DEFAULT_NUM_CQ (1 << 16)
88#define MTHCA_DEFAULT_NUM_MCG (1 << 13)
89#define MTHCA_DEFAULT_NUM_MPT (1 << 17)
90#define MTHCA_DEFAULT_NUM_MTT (1 << 20)
91#define MTHCA_DEFAULT_NUM_UDAV (1 << 15)
92#define MTHCA_DEFAULT_NUM_RESERVED_MTTS (1 << 18)
93#define MTHCA_DEFAULT_NUM_UARC_SIZE (1 << 18)
94
95static struct mthca_profile hca_profile = {
96 .num_qp = MTHCA_DEFAULT_NUM_QP,
97 .rdb_per_qp = MTHCA_DEFAULT_RDB_PER_QP,
98 .num_cq = MTHCA_DEFAULT_NUM_CQ,
99 .num_mcg = MTHCA_DEFAULT_NUM_MCG,
100 .num_mpt = MTHCA_DEFAULT_NUM_MPT,
101 .num_mtt = MTHCA_DEFAULT_NUM_MTT,
102 .num_udav = MTHCA_DEFAULT_NUM_UDAV, /* Tavor only */
103 .fmr_reserved_mtts = MTHCA_DEFAULT_NUM_RESERVED_MTTS, /* Tavor only */
104 .uarc_size = MTHCA_DEFAULT_NUM_UARC_SIZE, /* Arbel only */
105};
106
107module_param_named(num_qp, hca_profile.num_qp, int, 0444);
108MODULE_PARM_DESC(num_qp, "maximum number of QPs per HCA");
109
110module_param_named(rdb_per_qp, hca_profile.rdb_per_qp, int, 0444);
111MODULE_PARM_DESC(rdb_per_qp, "number of RDB buffers per QP");
112
113module_param_named(num_cq, hca_profile.num_cq, int, 0444);
114MODULE_PARM_DESC(num_cq, "maximum number of CQs per HCA");
115
116module_param_named(num_mcg, hca_profile.num_mcg, int, 0444);
117MODULE_PARM_DESC(num_mcg, "maximum number of multicast groups per HCA");
118
119module_param_named(num_mpt, hca_profile.num_mpt, int, 0444);
120MODULE_PARM_DESC(num_mpt,
121 "maximum number of memory protection table entries per HCA");
122
123module_param_named(num_mtt, hca_profile.num_mtt, int, 0444);
124MODULE_PARM_DESC(num_mtt,
125 "maximum number of memory translation table segments per HCA");
126
127module_param_named(num_udav, hca_profile.num_udav, int, 0444);
128MODULE_PARM_DESC(num_udav, "maximum number of UD address vectors per HCA");
129
130module_param_named(fmr_reserved_mtts, hca_profile.fmr_reserved_mtts, int, 0444);
131MODULE_PARM_DESC(fmr_reserved_mtts,
132 "number of memory translation table segments reserved for FMR");
84 133
85static const char mthca_version[] __devinitdata = 134static const char mthca_version[] __devinitdata =
86 DRV_NAME ": Mellanox InfiniBand HCA driver v" 135 DRV_NAME ": Mellanox InfiniBand HCA driver v"
87 DRV_VERSION " (" DRV_RELDATE ")\n"; 136 DRV_VERSION " (" DRV_RELDATE ")\n";
88 137
89static struct mthca_profile default_profile = {
90 .num_qp = 1 << 16,
91 .rdb_per_qp = 4,
92 .num_cq = 1 << 16,
93 .num_mcg = 1 << 13,
94 .num_mpt = 1 << 17,
95 .num_mtt = 1 << 20,
96 .num_udav = 1 << 15, /* Tavor only */
97 .fmr_reserved_mtts = 1 << 18, /* Tavor only */
98 .uarc_size = 1 << 18, /* Arbel only */
99};
100
101static int mthca_tune_pci(struct mthca_dev *mdev) 138static int mthca_tune_pci(struct mthca_dev *mdev)
102{ 139{
103 int cap; 140 int cap;
@@ -303,7 +340,7 @@ static int mthca_init_tavor(struct mthca_dev *mdev)
303 goto err_disable; 340 goto err_disable;
304 } 341 }
305 342
306 profile = default_profile; 343 profile = hca_profile;
307 profile.num_uar = dev_lim.uar_size / PAGE_SIZE; 344 profile.num_uar = dev_lim.uar_size / PAGE_SIZE;
308 profile.uarc_size = 0; 345 profile.uarc_size = 0;
309 if (mdev->mthca_flags & MTHCA_FLAG_SRQ) 346 if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
@@ -621,7 +658,7 @@ static int mthca_init_arbel(struct mthca_dev *mdev)
621 goto err_stop_fw; 658 goto err_stop_fw;
622 } 659 }
623 660
624 profile = default_profile; 661 profile = hca_profile;
625 profile.num_uar = dev_lim.uar_size / PAGE_SIZE; 662 profile.num_uar = dev_lim.uar_size / PAGE_SIZE;
626 profile.num_udav = 0; 663 profile.num_udav = 0;
627 if (mdev->mthca_flags & MTHCA_FLAG_SRQ) 664 if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
@@ -1278,11 +1315,55 @@ static struct pci_driver mthca_driver = {
1278 .remove = __devexit_p(mthca_remove_one) 1315 .remove = __devexit_p(mthca_remove_one)
1279}; 1316};
1280 1317
1318static void __init __mthca_check_profile_val(const char *name, int *pval,
1319 int pval_default)
1320{
1321 /* value must be positive and power of 2 */
1322 int old_pval = *pval;
1323
1324 if (old_pval <= 0)
1325 *pval = pval_default;
1326 else
1327 *pval = roundup_pow_of_two(old_pval);
1328
1329 if (old_pval != *pval) {
1330 printk(KERN_WARNING PFX "Invalid value %d for %s in module parameter.\n",
1331 old_pval, name);
1332 printk(KERN_WARNING PFX "Corrected %s to %d.\n", name, *pval);
1333 }
1334}
1335
1336#define mthca_check_profile_val(name, default) \
1337 __mthca_check_profile_val(#name, &hca_profile.name, default)
1338
1339static void __init mthca_validate_profile(void)
1340{
1341 mthca_check_profile_val(num_qp, MTHCA_DEFAULT_NUM_QP);
1342 mthca_check_profile_val(rdb_per_qp, MTHCA_DEFAULT_RDB_PER_QP);
1343 mthca_check_profile_val(num_cq, MTHCA_DEFAULT_NUM_CQ);
1344 mthca_check_profile_val(num_mcg, MTHCA_DEFAULT_NUM_MCG);
1345 mthca_check_profile_val(num_mpt, MTHCA_DEFAULT_NUM_MPT);
1346 mthca_check_profile_val(num_mtt, MTHCA_DEFAULT_NUM_MTT);
1347 mthca_check_profile_val(num_udav, MTHCA_DEFAULT_NUM_UDAV);
1348 mthca_check_profile_val(fmr_reserved_mtts, MTHCA_DEFAULT_NUM_RESERVED_MTTS);
1349
1350 if (hca_profile.fmr_reserved_mtts >= hca_profile.num_mtt) {
1351 printk(KERN_WARNING PFX "Invalid fmr_reserved_mtts module parameter %d.\n",
1352 hca_profile.fmr_reserved_mtts);
1353 printk(KERN_WARNING PFX "(Must be smaller than num_mtt %d)\n",
1354 hca_profile.num_mtt);
1355 hca_profile.fmr_reserved_mtts = hca_profile.num_mtt / 2;
1356 printk(KERN_WARNING PFX "Corrected fmr_reserved_mtts to %d.\n",
1357 hca_profile.fmr_reserved_mtts);
1358 }
1359}
1360
1281static int __init mthca_init(void) 1361static int __init mthca_init(void)
1282{ 1362{
1283 int ret; 1363 int ret;
1284 1364
1285 mutex_init(&mthca_device_mutex); 1365 mthca_validate_profile();
1366
1286 ret = mthca_catas_init(); 1367 ret = mthca_catas_init();
1287 if (ret) 1368 if (ret)
1288 return ret; 1369 return ret;
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index 15cc2f6eb4..6b19645d94 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -232,7 +232,7 @@ void *mthca_table_find(struct mthca_icm_table *table, int obj)
232 232
233 list_for_each_entry(chunk, &icm->chunk_list, list) { 233 list_for_each_entry(chunk, &icm->chunk_list, list) {
234 for (i = 0; i < chunk->npages; ++i) { 234 for (i = 0; i < chunk->npages; ++i) {
235 if (chunk->mem[i].length >= offset) { 235 if (chunk->mem[i].length > offset) {
236 page = chunk->mem[i].page; 236 page = chunk->mem[i].page;
237 goto out; 237 goto out;
238 } 238 }
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 7ec7c4b937..7b96751695 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -1100,10 +1100,11 @@ static struct ib_fmr *mthca_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
1100 struct mthca_fmr *fmr; 1100 struct mthca_fmr *fmr;
1101 int err; 1101 int err;
1102 1102
1103 fmr = kmemdup(fmr_attr, sizeof *fmr, GFP_KERNEL); 1103 fmr = kmalloc(sizeof *fmr, GFP_KERNEL);
1104 if (!fmr) 1104 if (!fmr)
1105 return ERR_PTR(-ENOMEM); 1105 return ERR_PTR(-ENOMEM);
1106 1106
1107 memcpy(&fmr->attr, fmr_attr, sizeof *fmr_attr);
1107 err = mthca_fmr_alloc(to_mdev(pd->device), to_mpd(pd)->pd_num, 1108 err = mthca_fmr_alloc(to_mdev(pd->device), to_mpd(pd)->pd_num,
1108 convert_access(mr_access_flags), fmr); 1109 convert_access(mr_access_flags), fmr);
1109 1110
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index d844a2569b..5f5214c033 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -429,13 +429,18 @@ int mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_m
429{ 429{
430 struct mthca_dev *dev = to_mdev(ibqp->device); 430 struct mthca_dev *dev = to_mdev(ibqp->device);
431 struct mthca_qp *qp = to_mqp(ibqp); 431 struct mthca_qp *qp = to_mqp(ibqp);
432 int err; 432 int err = 0;
433 struct mthca_mailbox *mailbox; 433 struct mthca_mailbox *mailbox = NULL;
434 struct mthca_qp_param *qp_param; 434 struct mthca_qp_param *qp_param;
435 struct mthca_qp_context *context; 435 struct mthca_qp_context *context;
436 int mthca_state; 436 int mthca_state;
437 u8 status; 437 u8 status;
438 438
439 if (qp->state == IB_QPS_RESET) {
440 qp_attr->qp_state = IB_QPS_RESET;
441 goto done;
442 }
443
439 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 444 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
440 if (IS_ERR(mailbox)) 445 if (IS_ERR(mailbox))
441 return PTR_ERR(mailbox); 446 return PTR_ERR(mailbox);
@@ -454,7 +459,6 @@ int mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_m
454 mthca_state = be32_to_cpu(context->flags) >> 28; 459 mthca_state = be32_to_cpu(context->flags) >> 28;
455 460
456 qp_attr->qp_state = to_ib_qp_state(mthca_state); 461 qp_attr->qp_state = to_ib_qp_state(mthca_state);
457 qp_attr->cur_qp_state = qp_attr->qp_state;
458 qp_attr->path_mtu = context->mtu_msgmax >> 5; 462 qp_attr->path_mtu = context->mtu_msgmax >> 5;
459 qp_attr->path_mig_state = 463 qp_attr->path_mig_state =
460 to_ib_mig_state((be32_to_cpu(context->flags) >> 11) & 0x3); 464 to_ib_mig_state((be32_to_cpu(context->flags) >> 11) & 0x3);
@@ -464,11 +468,6 @@ int mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_m
464 qp_attr->dest_qp_num = be32_to_cpu(context->remote_qpn) & 0xffffff; 468 qp_attr->dest_qp_num = be32_to_cpu(context->remote_qpn) & 0xffffff;
465 qp_attr->qp_access_flags = 469 qp_attr->qp_access_flags =
466 to_ib_qp_access_flags(be32_to_cpu(context->params2)); 470 to_ib_qp_access_flags(be32_to_cpu(context->params2));
467 qp_attr->cap.max_send_wr = qp->sq.max;
468 qp_attr->cap.max_recv_wr = qp->rq.max;
469 qp_attr->cap.max_send_sge = qp->sq.max_gs;
470 qp_attr->cap.max_recv_sge = qp->rq.max_gs;
471 qp_attr->cap.max_inline_data = qp->max_inline_data;
472 471
473 if (qp->transport == RC || qp->transport == UC) { 472 if (qp->transport == RC || qp->transport == UC) {
474 to_ib_ah_attr(dev, &qp_attr->ah_attr, &context->pri_path); 473 to_ib_ah_attr(dev, &qp_attr->ah_attr, &context->pri_path);
@@ -495,7 +494,16 @@ int mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_m
495 qp_attr->retry_cnt = (be32_to_cpu(context->params1) >> 16) & 0x7; 494 qp_attr->retry_cnt = (be32_to_cpu(context->params1) >> 16) & 0x7;
496 qp_attr->rnr_retry = context->pri_path.rnr_retry >> 5; 495 qp_attr->rnr_retry = context->pri_path.rnr_retry >> 5;
497 qp_attr->alt_timeout = context->alt_path.ackto >> 3; 496 qp_attr->alt_timeout = context->alt_path.ackto >> 3;
498 qp_init_attr->cap = qp_attr->cap; 497
498done:
499 qp_attr->cur_qp_state = qp_attr->qp_state;
500 qp_attr->cap.max_send_wr = qp->sq.max;
501 qp_attr->cap.max_recv_wr = qp->rq.max;
502 qp_attr->cap.max_send_sge = qp->sq.max_gs;
503 qp_attr->cap.max_recv_sge = qp->rq.max_gs;
504 qp_attr->cap.max_inline_data = qp->max_inline_data;
505
506 qp_init_attr->cap = qp_attr->cap;
499 507
500out: 508out:
501 mthca_free_mailbox(dev, mailbox); 509 mthca_free_mailbox(dev, mailbox);
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
index 9b2041e25d..dd221eda3e 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.c
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
@@ -177,7 +177,7 @@ iscsi_iser_mtask_xmit(struct iscsi_conn *conn,
177 * - if yes, the mtask is recycled at iscsi_complete_pdu 177 * - if yes, the mtask is recycled at iscsi_complete_pdu
178 * - if no, the mtask is recycled at iser_snd_completion 178 * - if no, the mtask is recycled at iser_snd_completion
179 */ 179 */
180 if (error && error != -EAGAIN) 180 if (error && error != -ENOBUFS)
181 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); 181 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
182 182
183 return error; 183 return error;
@@ -241,7 +241,7 @@ iscsi_iser_ctask_xmit(struct iscsi_conn *conn,
241 error = iscsi_iser_ctask_xmit_unsol_data(conn, ctask); 241 error = iscsi_iser_ctask_xmit_unsol_data(conn, ctask);
242 242
243 iscsi_iser_ctask_xmit_exit: 243 iscsi_iser_ctask_xmit_exit:
244 if (error && error != -EAGAIN) 244 if (error && error != -ENOBUFS)
245 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); 245 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
246 return error; 246 return error;
247} 247}
diff --git a/drivers/infiniband/ulp/iser/iser_initiator.c b/drivers/infiniband/ulp/iser/iser_initiator.c
index e73c87b9be..0a7d1ab60e 100644
--- a/drivers/infiniband/ulp/iser/iser_initiator.c
+++ b/drivers/infiniband/ulp/iser/iser_initiator.c
@@ -304,18 +304,14 @@ int iser_conn_set_full_featured_mode(struct iscsi_conn *conn)
304static int 304static int
305iser_check_xmit(struct iscsi_conn *conn, void *task) 305iser_check_xmit(struct iscsi_conn *conn, void *task)
306{ 306{
307 int rc = 0;
308 struct iscsi_iser_conn *iser_conn = conn->dd_data; 307 struct iscsi_iser_conn *iser_conn = conn->dd_data;
309 308
310 write_lock_bh(conn->recv_lock);
311 if (atomic_read(&iser_conn->ib_conn->post_send_buf_count) == 309 if (atomic_read(&iser_conn->ib_conn->post_send_buf_count) ==
312 ISER_QP_MAX_REQ_DTOS) { 310 ISER_QP_MAX_REQ_DTOS) {
313 iser_dbg("%ld can't xmit task %p, suspending tx\n",jiffies,task); 311 iser_dbg("%ld can't xmit task %p\n",jiffies,task);
314 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx); 312 return -ENOBUFS;
315 rc = -EAGAIN;
316 } 313 }
317 write_unlock_bh(conn->recv_lock); 314 return 0;
318 return rc;
319} 315}
320 316
321 317
@@ -340,7 +336,7 @@ int iser_send_command(struct iscsi_conn *conn,
340 return -EPERM; 336 return -EPERM;
341 } 337 }
342 if (iser_check_xmit(conn, ctask)) 338 if (iser_check_xmit(conn, ctask))
343 return -EAGAIN; 339 return -ENOBUFS;
344 340
345 edtl = ntohl(hdr->data_length); 341 edtl = ntohl(hdr->data_length);
346 342
@@ -426,7 +422,7 @@ int iser_send_data_out(struct iscsi_conn *conn,
426 } 422 }
427 423
428 if (iser_check_xmit(conn, ctask)) 424 if (iser_check_xmit(conn, ctask))
429 return -EAGAIN; 425 return -ENOBUFS;
430 426
431 itt = ntohl(hdr->itt); 427 itt = ntohl(hdr->itt);
432 data_seg_len = ntoh24(hdr->dlength); 428 data_seg_len = ntoh24(hdr->dlength);
@@ -498,7 +494,7 @@ int iser_send_control(struct iscsi_conn *conn,
498 } 494 }
499 495
500 if (iser_check_xmit(conn,mtask)) 496 if (iser_check_xmit(conn,mtask))
501 return -EAGAIN; 497 return -ENOBUFS;
502 498
503 /* build the tx desc regd header and add it to the tx desc dto */ 499 /* build the tx desc regd header and add it to the tx desc dto */
504 mdesc->type = ISCSI_TX_CONTROL; 500 mdesc->type = ISCSI_TX_CONTROL;
@@ -605,6 +601,7 @@ void iser_snd_completion(struct iser_desc *tx_desc)
605 struct iscsi_iser_conn *iser_conn = ib_conn->iser_conn; 601 struct iscsi_iser_conn *iser_conn = ib_conn->iser_conn;
606 struct iscsi_conn *conn = iser_conn->iscsi_conn; 602 struct iscsi_conn *conn = iser_conn->iscsi_conn;
607 struct iscsi_mgmt_task *mtask; 603 struct iscsi_mgmt_task *mtask;
604 int resume_tx = 0;
608 605
609 iser_dbg("Initiator, Data sent dto=0x%p\n", dto); 606 iser_dbg("Initiator, Data sent dto=0x%p\n", dto);
610 607
@@ -613,15 +610,16 @@ void iser_snd_completion(struct iser_desc *tx_desc)
613 if (tx_desc->type == ISCSI_TX_DATAOUT) 610 if (tx_desc->type == ISCSI_TX_DATAOUT)
614 kmem_cache_free(ig.desc_cache, tx_desc); 611 kmem_cache_free(ig.desc_cache, tx_desc);
615 612
613 if (atomic_read(&iser_conn->ib_conn->post_send_buf_count) ==
614 ISER_QP_MAX_REQ_DTOS)
615 resume_tx = 1;
616
616 atomic_dec(&ib_conn->post_send_buf_count); 617 atomic_dec(&ib_conn->post_send_buf_count);
617 618
618 write_lock(conn->recv_lock); 619 if (resume_tx) {
619 if (conn->suspend_tx) {
620 iser_dbg("%ld resuming tx\n",jiffies); 620 iser_dbg("%ld resuming tx\n",jiffies);
621 clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
622 scsi_queue_work(conn->session->host, &conn->xmitwork); 621 scsi_queue_work(conn->session->host, &conn->xmitwork);
623 } 622 }
624 write_unlock(conn->recv_lock);
625 623
626 if (tx_desc->type == ISCSI_TX_CONTROL) { 624 if (tx_desc->type == ISCSI_TX_CONTROL) {
627 /* this arithmetic is legal by libiscsi dd_data allocation */ 625 /* this arithmetic is legal by libiscsi dd_data allocation */
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index e9b6a6f07d..72611fd151 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -1621,18 +1621,30 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
1621 switch (token) { 1621 switch (token) {
1622 case SRP_OPT_ID_EXT: 1622 case SRP_OPT_ID_EXT:
1623 p = match_strdup(args); 1623 p = match_strdup(args);
1624 if (!p) {
1625 ret = -ENOMEM;
1626 goto out;
1627 }
1624 target->id_ext = cpu_to_be64(simple_strtoull(p, NULL, 16)); 1628 target->id_ext = cpu_to_be64(simple_strtoull(p, NULL, 16));
1625 kfree(p); 1629 kfree(p);
1626 break; 1630 break;
1627 1631
1628 case SRP_OPT_IOC_GUID: 1632 case SRP_OPT_IOC_GUID:
1629 p = match_strdup(args); 1633 p = match_strdup(args);
1634 if (!p) {
1635 ret = -ENOMEM;
1636 goto out;
1637 }
1630 target->ioc_guid = cpu_to_be64(simple_strtoull(p, NULL, 16)); 1638 target->ioc_guid = cpu_to_be64(simple_strtoull(p, NULL, 16));
1631 kfree(p); 1639 kfree(p);
1632 break; 1640 break;
1633 1641
1634 case SRP_OPT_DGID: 1642 case SRP_OPT_DGID:
1635 p = match_strdup(args); 1643 p = match_strdup(args);
1644 if (!p) {
1645 ret = -ENOMEM;
1646 goto out;
1647 }
1636 if (strlen(p) != 32) { 1648 if (strlen(p) != 32) {
1637 printk(KERN_WARNING PFX "bad dest GID parameter '%s'\n", p); 1649 printk(KERN_WARNING PFX "bad dest GID parameter '%s'\n", p);
1638 kfree(p); 1650 kfree(p);
@@ -1656,6 +1668,10 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
1656 1668
1657 case SRP_OPT_SERVICE_ID: 1669 case SRP_OPT_SERVICE_ID:
1658 p = match_strdup(args); 1670 p = match_strdup(args);
1671 if (!p) {
1672 ret = -ENOMEM;
1673 goto out;
1674 }
1659 target->service_id = cpu_to_be64(simple_strtoull(p, NULL, 16)); 1675 target->service_id = cpu_to_be64(simple_strtoull(p, NULL, 16));
1660 kfree(p); 1676 kfree(p);
1661 break; 1677 break;
@@ -1693,6 +1709,10 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
1693 1709
1694 case SRP_OPT_INITIATOR_EXT: 1710 case SRP_OPT_INITIATOR_EXT:
1695 p = match_strdup(args); 1711 p = match_strdup(args);
1712 if (!p) {
1713 ret = -ENOMEM;
1714 goto out;
1715 }
1696 target->initiator_ext = cpu_to_be64(simple_strtoull(p, NULL, 16)); 1716 target->initiator_ext = cpu_to_be64(simple_strtoull(p, NULL, 16));
1697 kfree(p); 1717 kfree(p);
1698 break; 1718 break;
@@ -1898,7 +1918,7 @@ static void srp_add_one(struct ib_device *device)
1898 */ 1918 */
1899 srp_dev->fmr_page_shift = max(9, ffs(dev_attr->page_size_cap) - 1); 1919 srp_dev->fmr_page_shift = max(9, ffs(dev_attr->page_size_cap) - 1);
1900 srp_dev->fmr_page_size = 1 << srp_dev->fmr_page_shift; 1920 srp_dev->fmr_page_size = 1 << srp_dev->fmr_page_shift;
1901 srp_dev->fmr_page_mask = ~((unsigned long) srp_dev->fmr_page_size - 1); 1921 srp_dev->fmr_page_mask = ~((u64) srp_dev->fmr_page_size - 1);
1902 1922
1903 INIT_LIST_HEAD(&srp_dev->dev_list); 1923 INIT_LIST_HEAD(&srp_dev->dev_list);
1904 1924
diff --git a/drivers/infiniband/ulp/srp/ib_srp.h b/drivers/infiniband/ulp/srp/ib_srp.h
index 868a540ef7..c21772317b 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.h
+++ b/drivers/infiniband/ulp/srp/ib_srp.h
@@ -87,7 +87,7 @@ struct srp_device {
87 struct ib_fmr_pool *fmr_pool; 87 struct ib_fmr_pool *fmr_pool;
88 int fmr_page_shift; 88 int fmr_page_shift;
89 int fmr_page_size; 89 int fmr_page_size;
90 unsigned long fmr_page_mask; 90 u64 fmr_page_mask;
91}; 91};
92 92
93struct srp_host { 93struct srp_host {
diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index 16583d7175..c67e84ec2d 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -187,7 +187,7 @@ static irqreturn_t amikbd_interrupt(int irq, void *dummy)
187 187
188static int __init amikbd_init(void) 188static int __init amikbd_init(void)
189{ 189{
190 int i, j; 190 int i, j, err;
191 191
192 if (!AMIGAHW_PRESENT(AMI_KEYBOARD)) 192 if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
193 return -ENODEV; 193 return -ENODEV;
diff --git a/drivers/input/keyboard/sunkbd.c b/drivers/input/keyboard/sunkbd.c
index 3826db9403..cc02383664 100644
--- a/drivers/input/keyboard/sunkbd.c
+++ b/drivers/input/keyboard/sunkbd.c
@@ -225,7 +225,7 @@ static void sunkbd_reinit(struct work_struct *work)
225static void sunkbd_enable(struct sunkbd *sunkbd, int enable) 225static void sunkbd_enable(struct sunkbd *sunkbd, int enable)
226{ 226{
227 serio_pause_rx(sunkbd->serio); 227 serio_pause_rx(sunkbd->serio);
228 sunkbd->enabled = 1; 228 sunkbd->enabled = enable;
229 serio_continue_rx(sunkbd->serio); 229 serio_continue_rx(sunkbd->serio);
230} 230}
231 231
diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index 54adba2d8e..d9ca55891c 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -16,6 +16,7 @@ static int i8042_aux_irq = -1;
16#define I8042_MUX_PHYS_DESC "sparcps2/serio%d" 16#define I8042_MUX_PHYS_DESC "sparcps2/serio%d"
17 17
18static void __iomem *kbd_iobase; 18static void __iomem *kbd_iobase;
19static struct resource *kbd_res;
19 20
20#define I8042_COMMAND_REG (kbd_iobase + 0x64UL) 21#define I8042_COMMAND_REG (kbd_iobase + 0x64UL)
21#define I8042_DATA_REG (kbd_iobase + 0x60UL) 22#define I8042_DATA_REG (kbd_iobase + 0x60UL)
@@ -60,6 +61,7 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
60 i8042_kbd_irq = irq; 61 i8042_kbd_irq = irq;
61 kbd_iobase = of_ioremap(&kbd->resource[0], 62 kbd_iobase = of_ioremap(&kbd->resource[0],
62 0, 8, "kbd"); 63 0, 8, "kbd");
64 kbd_res = &kbd->resource[0];
63 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) || 65 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) ||
64 !strcmp(dp->name, OBP_PS2MS_NAME2)) { 66 !strcmp(dp->name, OBP_PS2MS_NAME2)) {
65 struct of_device *ms = of_find_device_by_node(dp); 67 struct of_device *ms = of_find_device_by_node(dp);
@@ -77,7 +79,7 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
77 79
78static int __devexit sparc_i8042_remove(struct of_device *op) 80static int __devexit sparc_i8042_remove(struct of_device *op)
79{ 81{
80 of_iounmap(kbd_iobase, 8); 82 of_iounmap(kbd_res, kbd_iobase, 8);
81 83
82 return 0; 84 return 0;
83} 85}
@@ -119,7 +121,7 @@ static int __init i8042_platform_init(void)
119 if (i8042_kbd_irq == -1 || 121 if (i8042_kbd_irq == -1 ||
120 i8042_aux_irq == -1) { 122 i8042_aux_irq == -1) {
121 if (kbd_iobase) { 123 if (kbd_iobase) {
122 of_iounmap(kbd_iobase, 8); 124 of_iounmap(kbd_res, kbd_iobase, 8);
123 kbd_iobase = (void __iomem *) NULL; 125 kbd_iobase = (void __iomem *) NULL;
124 } 126 }
125 return -ENODEV; 127 return -ENODEV;
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index 95eff3b291..4f75cce6fd 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -356,16 +356,17 @@ static struct cardstate *alloc_cs(struct gigaset_driver *drv)
356{ 356{
357 unsigned long flags; 357 unsigned long flags;
358 unsigned i; 358 unsigned i;
359 static struct cardstate *ret = NULL; 359 struct cardstate *ret = NULL;
360 360
361 spin_lock_irqsave(&drv->lock, flags); 361 spin_lock_irqsave(&drv->lock, flags);
362 for (i = 0; i < drv->minors; ++i) { 362 for (i = 0; i < drv->minors; ++i) {
363 if (!(drv->flags[i] & VALID_MINOR)) { 363 if (!(drv->flags[i] & VALID_MINOR)) {
364 drv->flags[i] = VALID_MINOR; 364 if (try_module_get(drv->owner)) {
365 ret = drv->cs + i; 365 drv->flags[i] = VALID_MINOR;
366 } 366 ret = drv->cs + i;
367 if (ret) 367 }
368 break; 368 break;
369 }
369 } 370 }
370 spin_unlock_irqrestore(&drv->lock, flags); 371 spin_unlock_irqrestore(&drv->lock, flags);
371 return ret; 372 return ret;
@@ -376,6 +377,8 @@ static void free_cs(struct cardstate *cs)
376 unsigned long flags; 377 unsigned long flags;
377 struct gigaset_driver *drv = cs->driver; 378 struct gigaset_driver *drv = cs->driver;
378 spin_lock_irqsave(&drv->lock, flags); 379 spin_lock_irqsave(&drv->lock, flags);
380 if (drv->flags[cs->minor_index] & VALID_MINOR)
381 module_put(drv->owner);
379 drv->flags[cs->minor_index] = 0; 382 drv->flags[cs->minor_index] = 0;
380 spin_unlock_irqrestore(&drv->lock, flags); 383 spin_unlock_irqrestore(&drv->lock, flags);
381} 384}
@@ -579,7 +582,7 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
579 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 582 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
580 skb_reserve(bcs->skb, HW_HDR_LEN); 583 skb_reserve(bcs->skb, HW_HDR_LEN);
581 else { 584 else {
582 warn("could not allocate skb\n"); 585 warn("could not allocate skb");
583 bcs->inputstate |= INS_skip_frame; 586 bcs->inputstate |= INS_skip_frame;
584 } 587 }
585 588
@@ -632,17 +635,25 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
632 int i; 635 int i;
633 636
634 gig_dbg(DEBUG_INIT, "allocating cs"); 637 gig_dbg(DEBUG_INIT, "allocating cs");
635 cs = alloc_cs(drv); 638 if (!(cs = alloc_cs(drv))) {
636 if (!cs) 639 err("maximum number of devices exceeded");
637 goto error; 640 return NULL;
641 }
642 mutex_init(&cs->mutex);
643 mutex_lock(&cs->mutex);
644
638 gig_dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1); 645 gig_dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1);
639 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL); 646 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
640 if (!cs->bcs) 647 if (!cs->bcs) {
648 err("out of memory");
641 goto error; 649 goto error;
650 }
642 gig_dbg(DEBUG_INIT, "allocating inbuf"); 651 gig_dbg(DEBUG_INIT, "allocating inbuf");
643 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL); 652 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
644 if (!cs->inbuf) 653 if (!cs->inbuf) {
654 err("out of memory");
645 goto error; 655 goto error;
656 }
646 657
647 cs->cs_init = 0; 658 cs->cs_init = 0;
648 cs->channels = channels; 659 cs->channels = channels;
@@ -654,8 +665,6 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
654 spin_lock_init(&cs->ev_lock); 665 spin_lock_init(&cs->ev_lock);
655 cs->ev_tail = 0; 666 cs->ev_tail = 0;
656 cs->ev_head = 0; 667 cs->ev_head = 0;
657 mutex_init(&cs->mutex);
658 mutex_lock(&cs->mutex);
659 668
660 tasklet_init(&cs->event_tasklet, &gigaset_handle_event, 669 tasklet_init(&cs->event_tasklet, &gigaset_handle_event,
661 (unsigned long) cs); 670 (unsigned long) cs);
@@ -684,8 +693,10 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
684 693
685 for (i = 0; i < channels; ++i) { 694 for (i = 0; i < channels; ++i) {
686 gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i); 695 gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i);
687 if (!gigaset_initbcs(cs->bcs + i, cs, i)) 696 if (!gigaset_initbcs(cs->bcs + i, cs, i)) {
697 err("could not allocate channel %d data", i);
688 goto error; 698 goto error;
699 }
689 } 700 }
690 701
691 ++cs->cs_init; 702 ++cs->cs_init;
@@ -720,8 +731,10 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
720 make_valid(cs, VALID_ID); 731 make_valid(cs, VALID_ID);
721 ++cs->cs_init; 732 ++cs->cs_init;
722 gig_dbg(DEBUG_INIT, "setting up hw"); 733 gig_dbg(DEBUG_INIT, "setting up hw");
723 if (!cs->ops->initcshw(cs)) 734 if (!cs->ops->initcshw(cs)) {
735 err("could not allocate device specific data");
724 goto error; 736 goto error;
737 }
725 738
726 ++cs->cs_init; 739 ++cs->cs_init;
727 740
@@ -743,8 +756,8 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
743 mutex_unlock(&cs->mutex); 756 mutex_unlock(&cs->mutex);
744 return cs; 757 return cs;
745 758
746error: if (cs) 759error:
747 mutex_unlock(&cs->mutex); 760 mutex_unlock(&cs->mutex);
748 gig_dbg(DEBUG_INIT, "failed"); 761 gig_dbg(DEBUG_INIT, "failed");
749 gigaset_freecs(cs); 762 gigaset_freecs(cs);
750 return NULL; 763 return NULL;
@@ -1040,7 +1053,6 @@ void gigaset_freedriver(struct gigaset_driver *drv)
1040 spin_unlock_irqrestore(&driver_lock, flags); 1053 spin_unlock_irqrestore(&driver_lock, flags);
1041 1054
1042 gigaset_if_freedriver(drv); 1055 gigaset_if_freedriver(drv);
1043 module_put(drv->owner);
1044 1056
1045 kfree(drv->cs); 1057 kfree(drv->cs);
1046 kfree(drv->flags); 1058 kfree(drv->flags);
@@ -1072,10 +1084,6 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1072 if (!drv) 1084 if (!drv)
1073 return NULL; 1085 return NULL;
1074 1086
1075 if (!try_module_get(owner))
1076 goto out1;
1077
1078 drv->cs = NULL;
1079 drv->have_tty = 0; 1087 drv->have_tty = 0;
1080 drv->minor = minor; 1088 drv->minor = minor;
1081 drv->minors = minors; 1089 drv->minors = minors;
@@ -1087,11 +1095,11 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1087 1095
1088 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL); 1096 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
1089 if (!drv->cs) 1097 if (!drv->cs)
1090 goto out2; 1098 goto error;
1091 1099
1092 drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL); 1100 drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL);
1093 if (!drv->flags) 1101 if (!drv->flags)
1094 goto out3; 1102 goto error;
1095 1103
1096 for (i = 0; i < minors; ++i) { 1104 for (i = 0; i < minors; ++i) {
1097 drv->flags[i] = 0; 1105 drv->flags[i] = 0;
@@ -1108,11 +1116,8 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1108 1116
1109 return drv; 1117 return drv;
1110 1118
1111out3: 1119error:
1112 kfree(drv->cs); 1120 kfree(drv->cs);
1113out2:
1114 module_put(owner);
1115out1:
1116 kfree(drv); 1121 kfree(drv);
1117 return NULL; 1122 return NULL;
1118} 1123}
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index 1726131b20..4e3f127e40 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -2339,6 +2339,7 @@ static struct ippp_ccp_reset_state *isdn_ppp_ccp_reset_alloc_state(struct ippp_s
2339 rs->state = CCPResetIdle; 2339 rs->state = CCPResetIdle;
2340 rs->is = is; 2340 rs->is = is;
2341 rs->id = id; 2341 rs->id = id;
2342 init_timer(&rs->timer);
2342 rs->timer.data = (unsigned long)rs; 2343 rs->timer.data = (unsigned long)rs;
2343 rs->timer.function = isdn_ppp_ccp_timer_callback; 2344 rs->timer.function = isdn_ppp_ccp_timer_callback;
2344 is->reset->rs[id] = rs; 2345 is->reset->rs[id] = rs;
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 930e04ce1a..2db1ca4c68 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -52,6 +52,8 @@
52#define KVM_MAX_VCPUS 1 52#define KVM_MAX_VCPUS 1
53#define KVM_MEMORY_SLOTS 4 53#define KVM_MEMORY_SLOTS 4
54#define KVM_NUM_MMU_PAGES 256 54#define KVM_NUM_MMU_PAGES 256
55#define KVM_MIN_FREE_MMU_PAGES 5
56#define KVM_REFILL_PAGES 25
55 57
56#define FX_IMAGE_SIZE 512 58#define FX_IMAGE_SIZE 512
57#define FX_IMAGE_ALIGN 16 59#define FX_IMAGE_ALIGN 16
@@ -89,14 +91,54 @@ typedef unsigned long hva_t;
89typedef u64 hpa_t; 91typedef u64 hpa_t;
90typedef unsigned long hfn_t; 92typedef unsigned long hfn_t;
91 93
94#define NR_PTE_CHAIN_ENTRIES 5
95
96struct kvm_pte_chain {
97 u64 *parent_ptes[NR_PTE_CHAIN_ENTRIES];
98 struct hlist_node link;
99};
100
101/*
102 * kvm_mmu_page_role, below, is defined as:
103 *
104 * bits 0:3 - total guest paging levels (2-4, or zero for real mode)
105 * bits 4:7 - page table level for this shadow (1-4)
106 * bits 8:9 - page table quadrant for 2-level guests
107 * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode)
108 */
109union kvm_mmu_page_role {
110 unsigned word;
111 struct {
112 unsigned glevels : 4;
113 unsigned level : 4;
114 unsigned quadrant : 2;
115 unsigned pad_for_nice_hex_output : 6;
116 unsigned metaphysical : 1;
117 };
118};
119
92struct kvm_mmu_page { 120struct kvm_mmu_page {
93 struct list_head link; 121 struct list_head link;
122 struct hlist_node hash_link;
123
124 /*
125 * The following two entries are used to key the shadow page in the
126 * hash table.
127 */
128 gfn_t gfn;
129 union kvm_mmu_page_role role;
130
94 hpa_t page_hpa; 131 hpa_t page_hpa;
95 unsigned long slot_bitmap; /* One bit set per slot which has memory 132 unsigned long slot_bitmap; /* One bit set per slot which has memory
96 * in this shadow page. 133 * in this shadow page.
97 */ 134 */
98 int global; /* Set if all ptes in this page are global */ 135 int global; /* Set if all ptes in this page are global */
99 u64 *parent_pte; 136 int multimapped; /* More than one parent_pte? */
137 int root_count; /* Currently serving as active root */
138 union {
139 u64 *parent_pte; /* !multimapped */
140 struct hlist_head parent_ptes; /* multimapped, kvm_pte_chain */
141 };
100}; 142};
101 143
102struct vmcs { 144struct vmcs {
@@ -117,14 +159,26 @@ struct kvm_vcpu;
117struct kvm_mmu { 159struct kvm_mmu {
118 void (*new_cr3)(struct kvm_vcpu *vcpu); 160 void (*new_cr3)(struct kvm_vcpu *vcpu);
119 int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err); 161 int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err);
120 void (*inval_page)(struct kvm_vcpu *vcpu, gva_t gva);
121 void (*free)(struct kvm_vcpu *vcpu); 162 void (*free)(struct kvm_vcpu *vcpu);
122 gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva); 163 gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva);
123 hpa_t root_hpa; 164 hpa_t root_hpa;
124 int root_level; 165 int root_level;
125 int shadow_root_level; 166 int shadow_root_level;
167
168 u64 *pae_root;
126}; 169};
127 170
171#define KVM_NR_MEM_OBJS 20
172
173struct kvm_mmu_memory_cache {
174 int nobjs;
175 void *objects[KVM_NR_MEM_OBJS];
176};
177
178/*
179 * We don't want allocation failures within the mmu code, so we preallocate
180 * enough memory for a single page fault in a cache.
181 */
128struct kvm_guest_debug { 182struct kvm_guest_debug {
129 int enabled; 183 int enabled;
130 unsigned long bp[4]; 184 unsigned long bp[4];
@@ -173,6 +227,7 @@ struct kvm_vcpu {
173 struct mutex mutex; 227 struct mutex mutex;
174 int cpu; 228 int cpu;
175 int launched; 229 int launched;
230 int interrupt_window_open;
176 unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */ 231 unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
177#define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long) 232#define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long)
178 unsigned long irq_pending[NR_IRQ_WORDS]; 233 unsigned long irq_pending[NR_IRQ_WORDS];
@@ -184,8 +239,10 @@ struct kvm_vcpu {
184 unsigned long cr3; 239 unsigned long cr3;
185 unsigned long cr4; 240 unsigned long cr4;
186 unsigned long cr8; 241 unsigned long cr8;
242 u64 pdptrs[4]; /* pae */
187 u64 shadow_efer; 243 u64 shadow_efer;
188 u64 apic_base; 244 u64 apic_base;
245 u64 ia32_misc_enable_msr;
189 int nmsrs; 246 int nmsrs;
190 struct vmx_msr_entry *guest_msrs; 247 struct vmx_msr_entry *guest_msrs;
191 struct vmx_msr_entry *host_msrs; 248 struct vmx_msr_entry *host_msrs;
@@ -194,6 +251,12 @@ struct kvm_vcpu {
194 struct kvm_mmu_page page_header_buf[KVM_NUM_MMU_PAGES]; 251 struct kvm_mmu_page page_header_buf[KVM_NUM_MMU_PAGES];
195 struct kvm_mmu mmu; 252 struct kvm_mmu mmu;
196 253
254 struct kvm_mmu_memory_cache mmu_pte_chain_cache;
255 struct kvm_mmu_memory_cache mmu_rmap_desc_cache;
256
257 gfn_t last_pt_write_gfn;
258 int last_pt_write_count;
259
197 struct kvm_guest_debug guest_debug; 260 struct kvm_guest_debug guest_debug;
198 261
199 char fx_buf[FX_BUF_SIZE]; 262 char fx_buf[FX_BUF_SIZE];
@@ -231,10 +294,16 @@ struct kvm {
231 spinlock_t lock; /* protects everything except vcpus */ 294 spinlock_t lock; /* protects everything except vcpus */
232 int nmemslots; 295 int nmemslots;
233 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS]; 296 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS];
297 /*
298 * Hash table of struct kvm_mmu_page.
299 */
234 struct list_head active_mmu_pages; 300 struct list_head active_mmu_pages;
301 int n_free_mmu_pages;
302 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
235 struct kvm_vcpu vcpus[KVM_MAX_VCPUS]; 303 struct kvm_vcpu vcpus[KVM_MAX_VCPUS];
236 int memory_config_version; 304 int memory_config_version;
237 int busy; 305 int busy;
306 unsigned long rmap_overflow;
238}; 307};
239 308
240struct kvm_stat { 309struct kvm_stat {
@@ -247,6 +316,9 @@ struct kvm_stat {
247 u32 io_exits; 316 u32 io_exits;
248 u32 mmio_exits; 317 u32 mmio_exits;
249 u32 signal_exits; 318 u32 signal_exits;
319 u32 irq_window_exits;
320 u32 halt_exits;
321 u32 request_irq_exits;
250 u32 irq_exits; 322 u32 irq_exits;
251}; 323};
252 324
@@ -278,8 +350,8 @@ struct kvm_arch_ops {
278 struct kvm_segment *var, int seg); 350 struct kvm_segment *var, int seg);
279 void (*set_segment)(struct kvm_vcpu *vcpu, 351 void (*set_segment)(struct kvm_vcpu *vcpu,
280 struct kvm_segment *var, int seg); 352 struct kvm_segment *var, int seg);
281 int (*is_long_mode)(struct kvm_vcpu *vcpu);
282 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l); 353 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);
354 void (*decache_cr0_cr4_guest_bits)(struct kvm_vcpu *vcpu);
283 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0); 355 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0);
284 void (*set_cr0_no_modeswitch)(struct kvm_vcpu *vcpu, 356 void (*set_cr0_no_modeswitch)(struct kvm_vcpu *vcpu,
285 unsigned long cr0); 357 unsigned long cr0);
@@ -320,10 +392,11 @@ int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module);
320void kvm_exit_arch(void); 392void kvm_exit_arch(void);
321 393
322void kvm_mmu_destroy(struct kvm_vcpu *vcpu); 394void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
323int kvm_mmu_init(struct kvm_vcpu *vcpu); 395int kvm_mmu_create(struct kvm_vcpu *vcpu);
396int kvm_mmu_setup(struct kvm_vcpu *vcpu);
324 397
325int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); 398int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
326void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot); 399void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot);
327 400
328hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa); 401hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa);
329#define HPA_MSB ((sizeof(hpa_t) * 8) - 1) 402#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
@@ -375,9 +448,8 @@ void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr0);
375void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0); 448void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0);
376void lmsw(struct kvm_vcpu *vcpu, unsigned long msw); 449void lmsw(struct kvm_vcpu *vcpu, unsigned long msw);
377 450
378#ifdef CONFIG_X86_64 451int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
379void set_efer(struct kvm_vcpu *vcpu, u64 efer); 452int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data);
380#endif
381 453
382void fx_init(struct kvm_vcpu *vcpu); 454void fx_init(struct kvm_vcpu *vcpu);
383 455
@@ -397,12 +469,34 @@ int kvm_write_guest(struct kvm_vcpu *vcpu,
397 469
398unsigned long segment_base(u16 selector); 470unsigned long segment_base(u16 selector);
399 471
472void kvm_mmu_pre_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes);
473void kvm_mmu_post_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes);
474int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
475void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
476
477static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
478 u32 error_code)
479{
480 if (unlikely(vcpu->kvm->n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES))
481 kvm_mmu_free_some_pages(vcpu);
482 return vcpu->mmu.page_fault(vcpu, gva, error_code);
483}
484
400static inline struct page *_gfn_to_page(struct kvm *kvm, gfn_t gfn) 485static inline struct page *_gfn_to_page(struct kvm *kvm, gfn_t gfn)
401{ 486{
402 struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn); 487 struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
403 return (slot) ? slot->phys_mem[gfn - slot->base_gfn] : NULL; 488 return (slot) ? slot->phys_mem[gfn - slot->base_gfn] : NULL;
404} 489}
405 490
491static inline int is_long_mode(struct kvm_vcpu *vcpu)
492{
493#ifdef CONFIG_X86_64
494 return vcpu->shadow_efer & EFER_LME;
495#else
496 return 0;
497#endif
498}
499
406static inline int is_pae(struct kvm_vcpu *vcpu) 500static inline int is_pae(struct kvm_vcpu *vcpu)
407{ 501{
408 return vcpu->cr4 & CR4_PAE_MASK; 502 return vcpu->cr4 & CR4_PAE_MASK;
@@ -533,19 +627,4 @@ static inline u32 get_rdx_init_val(void)
533#define TSS_REDIRECTION_SIZE (256 / 8) 627#define TSS_REDIRECTION_SIZE (256 / 8)
534#define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1) 628#define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)
535 629
536#ifdef CONFIG_X86_64
537
538/*
539 * When emulating 32-bit mode, cr3 is only 32 bits even on x86_64. Therefore
540 * we need to allocate shadow page tables in the first 4GB of memory, which
541 * happens to fit the DMA32 zone.
542 */
543#define GFP_KVM_MMU (GFP_KERNEL | __GFP_DMA32)
544
545#else
546
547#define GFP_KVM_MMU GFP_KERNEL
548
549#endif
550
551#endif 630#endif
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index fd1bb87054..b10972ed0c 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -58,6 +58,9 @@ static struct kvm_stats_debugfs_item {
58 { "io_exits", &kvm_stat.io_exits }, 58 { "io_exits", &kvm_stat.io_exits },
59 { "mmio_exits", &kvm_stat.mmio_exits }, 59 { "mmio_exits", &kvm_stat.mmio_exits },
60 { "signal_exits", &kvm_stat.signal_exits }, 60 { "signal_exits", &kvm_stat.signal_exits },
61 { "irq_window", &kvm_stat.irq_window_exits },
62 { "halt_exits", &kvm_stat.halt_exits },
63 { "request_irq", &kvm_stat.request_irq_exits },
61 { "irq_exits", &kvm_stat.irq_exits }, 64 { "irq_exits", &kvm_stat.irq_exits },
62 { 0, 0 } 65 { 0, 0 }
63}; 66};
@@ -113,6 +116,11 @@ unsigned long segment_base(u16 selector)
113} 116}
114EXPORT_SYMBOL_GPL(segment_base); 117EXPORT_SYMBOL_GPL(segment_base);
115 118
119static inline int valid_vcpu(int n)
120{
121 return likely(n >= 0 && n < KVM_MAX_VCPUS);
122}
123
116int kvm_read_guest(struct kvm_vcpu *vcpu, 124int kvm_read_guest(struct kvm_vcpu *vcpu,
117 gva_t addr, 125 gva_t addr,
118 unsigned long size, 126 unsigned long size,
@@ -222,6 +230,7 @@ static int kvm_dev_open(struct inode *inode, struct file *filp)
222 struct kvm_vcpu *vcpu = &kvm->vcpus[i]; 230 struct kvm_vcpu *vcpu = &kvm->vcpus[i];
223 231
224 mutex_init(&vcpu->mutex); 232 mutex_init(&vcpu->mutex);
233 vcpu->kvm = kvm;
225 vcpu->mmu.root_hpa = INVALID_PAGE; 234 vcpu->mmu.root_hpa = INVALID_PAGE;
226 INIT_LIST_HEAD(&vcpu->free_pages); 235 INIT_LIST_HEAD(&vcpu->free_pages);
227 } 236 }
@@ -240,7 +249,8 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
240 if (!dont || free->phys_mem != dont->phys_mem) 249 if (!dont || free->phys_mem != dont->phys_mem)
241 if (free->phys_mem) { 250 if (free->phys_mem) {
242 for (i = 0; i < free->npages; ++i) 251 for (i = 0; i < free->npages; ++i)
243 __free_page(free->phys_mem[i]); 252 if (free->phys_mem[i])
253 __free_page(free->phys_mem[i]);
244 vfree(free->phys_mem); 254 vfree(free->phys_mem);
245 } 255 }
246 256
@@ -262,8 +272,10 @@ static void kvm_free_physmem(struct kvm *kvm)
262 272
263static void kvm_free_vcpu(struct kvm_vcpu *vcpu) 273static void kvm_free_vcpu(struct kvm_vcpu *vcpu)
264{ 274{
265 kvm_arch_ops->vcpu_free(vcpu); 275 vcpu_load(vcpu->kvm, vcpu_slot(vcpu));
266 kvm_mmu_destroy(vcpu); 276 kvm_mmu_destroy(vcpu);
277 vcpu_put(vcpu);
278 kvm_arch_ops->vcpu_free(vcpu);
267} 279}
268 280
269static void kvm_free_vcpus(struct kvm *kvm) 281static void kvm_free_vcpus(struct kvm *kvm)
@@ -289,14 +301,17 @@ static void inject_gp(struct kvm_vcpu *vcpu)
289 kvm_arch_ops->inject_gp(vcpu, 0); 301 kvm_arch_ops->inject_gp(vcpu, 0);
290} 302}
291 303
292static int pdptrs_have_reserved_bits_set(struct kvm_vcpu *vcpu, 304/*
293 unsigned long cr3) 305 * Load the pae pdptrs. Return true is they are all valid.
306 */
307static int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3)
294{ 308{
295 gfn_t pdpt_gfn = cr3 >> PAGE_SHIFT; 309 gfn_t pdpt_gfn = cr3 >> PAGE_SHIFT;
296 unsigned offset = (cr3 & (PAGE_SIZE-1)) >> 5; 310 unsigned offset = ((cr3 & (PAGE_SIZE-1)) >> 5) << 2;
297 int i; 311 int i;
298 u64 pdpte; 312 u64 pdpte;
299 u64 *pdpt; 313 u64 *pdpt;
314 int ret;
300 struct kvm_memory_slot *memslot; 315 struct kvm_memory_slot *memslot;
301 316
302 spin_lock(&vcpu->kvm->lock); 317 spin_lock(&vcpu->kvm->lock);
@@ -304,16 +319,23 @@ static int pdptrs_have_reserved_bits_set(struct kvm_vcpu *vcpu,
304 /* FIXME: !memslot - emulate? 0xff? */ 319 /* FIXME: !memslot - emulate? 0xff? */
305 pdpt = kmap_atomic(gfn_to_page(memslot, pdpt_gfn), KM_USER0); 320 pdpt = kmap_atomic(gfn_to_page(memslot, pdpt_gfn), KM_USER0);
306 321
322 ret = 1;
307 for (i = 0; i < 4; ++i) { 323 for (i = 0; i < 4; ++i) {
308 pdpte = pdpt[offset + i]; 324 pdpte = pdpt[offset + i];
309 if ((pdpte & 1) && (pdpte & 0xfffffff0000001e6ull)) 325 if ((pdpte & 1) && (pdpte & 0xfffffff0000001e6ull)) {
310 break; 326 ret = 0;
327 goto out;
328 }
311 } 329 }
312 330
331 for (i = 0; i < 4; ++i)
332 vcpu->pdptrs[i] = pdpt[offset + i];
333
334out:
313 kunmap_atomic(pdpt, KM_USER0); 335 kunmap_atomic(pdpt, KM_USER0);
314 spin_unlock(&vcpu->kvm->lock); 336 spin_unlock(&vcpu->kvm->lock);
315 337
316 return i != 4; 338 return ret;
317} 339}
318 340
319void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) 341void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
@@ -359,8 +381,7 @@ void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
359 } 381 }
360 } else 382 } else
361#endif 383#endif
362 if (is_pae(vcpu) && 384 if (is_pae(vcpu) && !load_pdptrs(vcpu, vcpu->cr3)) {
363 pdptrs_have_reserved_bits_set(vcpu, vcpu->cr3)) {
364 printk(KERN_DEBUG "set_cr0: #GP, pdptrs " 385 printk(KERN_DEBUG "set_cr0: #GP, pdptrs "
365 "reserved bits\n"); 386 "reserved bits\n");
366 inject_gp(vcpu); 387 inject_gp(vcpu);
@@ -381,6 +402,7 @@ EXPORT_SYMBOL_GPL(set_cr0);
381 402
382void lmsw(struct kvm_vcpu *vcpu, unsigned long msw) 403void lmsw(struct kvm_vcpu *vcpu, unsigned long msw)
383{ 404{
405 kvm_arch_ops->decache_cr0_cr4_guest_bits(vcpu);
384 set_cr0(vcpu, (vcpu->cr0 & ~0x0ful) | (msw & 0x0f)); 406 set_cr0(vcpu, (vcpu->cr0 & ~0x0ful) | (msw & 0x0f));
385} 407}
386EXPORT_SYMBOL_GPL(lmsw); 408EXPORT_SYMBOL_GPL(lmsw);
@@ -393,7 +415,7 @@ void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
393 return; 415 return;
394 } 416 }
395 417
396 if (kvm_arch_ops->is_long_mode(vcpu)) { 418 if (is_long_mode(vcpu)) {
397 if (!(cr4 & CR4_PAE_MASK)) { 419 if (!(cr4 & CR4_PAE_MASK)) {
398 printk(KERN_DEBUG "set_cr4: #GP, clearing PAE while " 420 printk(KERN_DEBUG "set_cr4: #GP, clearing PAE while "
399 "in long mode\n"); 421 "in long mode\n");
@@ -401,7 +423,7 @@ void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
401 return; 423 return;
402 } 424 }
403 } else if (is_paging(vcpu) && !is_pae(vcpu) && (cr4 & CR4_PAE_MASK) 425 } else if (is_paging(vcpu) && !is_pae(vcpu) && (cr4 & CR4_PAE_MASK)
404 && pdptrs_have_reserved_bits_set(vcpu, vcpu->cr3)) { 426 && !load_pdptrs(vcpu, vcpu->cr3)) {
405 printk(KERN_DEBUG "set_cr4: #GP, pdptrs reserved bits\n"); 427 printk(KERN_DEBUG "set_cr4: #GP, pdptrs reserved bits\n");
406 inject_gp(vcpu); 428 inject_gp(vcpu);
407 } 429 }
@@ -420,7 +442,7 @@ EXPORT_SYMBOL_GPL(set_cr4);
420 442
421void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) 443void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
422{ 444{
423 if (kvm_arch_ops->is_long_mode(vcpu)) { 445 if (is_long_mode(vcpu)) {
424 if ( cr3 & CR3_L_MODE_RESEVED_BITS) { 446 if ( cr3 & CR3_L_MODE_RESEVED_BITS) {
425 printk(KERN_DEBUG "set_cr3: #GP, reserved bits\n"); 447 printk(KERN_DEBUG "set_cr3: #GP, reserved bits\n");
426 inject_gp(vcpu); 448 inject_gp(vcpu);
@@ -433,7 +455,7 @@ void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
433 return; 455 return;
434 } 456 }
435 if (is_paging(vcpu) && is_pae(vcpu) && 457 if (is_paging(vcpu) && is_pae(vcpu) &&
436 pdptrs_have_reserved_bits_set(vcpu, cr3)) { 458 !load_pdptrs(vcpu, cr3)) {
437 printk(KERN_DEBUG "set_cr3: #GP, pdptrs " 459 printk(KERN_DEBUG "set_cr3: #GP, pdptrs "
438 "reserved bits\n"); 460 "reserved bits\n");
439 inject_gp(vcpu); 461 inject_gp(vcpu);
@@ -443,7 +465,19 @@ void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
443 465
444 vcpu->cr3 = cr3; 466 vcpu->cr3 = cr3;
445 spin_lock(&vcpu->kvm->lock); 467 spin_lock(&vcpu->kvm->lock);
446 vcpu->mmu.new_cr3(vcpu); 468 /*
469 * Does the new cr3 value map to physical memory? (Note, we
470 * catch an invalid cr3 even in real-mode, because it would
471 * cause trouble later on when we turn on paging anyway.)
472 *
473 * A real CPU would silently accept an invalid cr3 and would
474 * attempt to use it - with largely undefined (and often hard
475 * to debug) behavior on the guest side.
476 */
477 if (unlikely(!gfn_to_memslot(vcpu->kvm, cr3 >> PAGE_SHIFT)))
478 inject_gp(vcpu);
479 else
480 vcpu->mmu.new_cr3(vcpu);
447 spin_unlock(&vcpu->kvm->lock); 481 spin_unlock(&vcpu->kvm->lock);
448} 482}
449EXPORT_SYMBOL_GPL(set_cr3); 483EXPORT_SYMBOL_GPL(set_cr3);
@@ -494,7 +528,7 @@ static int kvm_dev_ioctl_create_vcpu(struct kvm *kvm, int n)
494 struct kvm_vcpu *vcpu; 528 struct kvm_vcpu *vcpu;
495 529
496 r = -EINVAL; 530 r = -EINVAL;
497 if (n < 0 || n >= KVM_MAX_VCPUS) 531 if (!valid_vcpu(n))
498 goto out; 532 goto out;
499 533
500 vcpu = &kvm->vcpus[n]; 534 vcpu = &kvm->vcpus[n];
@@ -511,17 +545,18 @@ static int kvm_dev_ioctl_create_vcpu(struct kvm *kvm, int n)
511 vcpu->guest_fx_image = vcpu->host_fx_image + FX_IMAGE_SIZE; 545 vcpu->guest_fx_image = vcpu->host_fx_image + FX_IMAGE_SIZE;
512 546
513 vcpu->cpu = -1; /* First load will set up TR */ 547 vcpu->cpu = -1; /* First load will set up TR */
514 vcpu->kvm = kvm;
515 r = kvm_arch_ops->vcpu_create(vcpu); 548 r = kvm_arch_ops->vcpu_create(vcpu);
516 if (r < 0) 549 if (r < 0)
517 goto out_free_vcpus; 550 goto out_free_vcpus;
518 551
519 kvm_arch_ops->vcpu_load(vcpu); 552 r = kvm_mmu_create(vcpu);
553 if (r < 0)
554 goto out_free_vcpus;
520 555
521 r = kvm_arch_ops->vcpu_setup(vcpu); 556 kvm_arch_ops->vcpu_load(vcpu);
557 r = kvm_mmu_setup(vcpu);
522 if (r >= 0) 558 if (r >= 0)
523 r = kvm_mmu_init(vcpu); 559 r = kvm_arch_ops->vcpu_setup(vcpu);
524
525 vcpu_put(vcpu); 560 vcpu_put(vcpu);
526 561
527 if (r < 0) 562 if (r < 0)
@@ -626,6 +661,7 @@ raced:
626 | __GFP_ZERO); 661 | __GFP_ZERO);
627 if (!new.phys_mem[i]) 662 if (!new.phys_mem[i])
628 goto out_free; 663 goto out_free;
664 new.phys_mem[i]->private = 0;
629 } 665 }
630 } 666 }
631 667
@@ -680,6 +716,13 @@ out:
680 return r; 716 return r;
681} 717}
682 718
719static void do_remove_write_access(struct kvm_vcpu *vcpu, int slot)
720{
721 spin_lock(&vcpu->kvm->lock);
722 kvm_mmu_slot_remove_write_access(vcpu, slot);
723 spin_unlock(&vcpu->kvm->lock);
724}
725
683/* 726/*
684 * Get (and clear) the dirty memory log for a memory slot. 727 * Get (and clear) the dirty memory log for a memory slot.
685 */ 728 */
@@ -689,6 +732,7 @@ static int kvm_dev_ioctl_get_dirty_log(struct kvm *kvm,
689 struct kvm_memory_slot *memslot; 732 struct kvm_memory_slot *memslot;
690 int r, i; 733 int r, i;
691 int n; 734 int n;
735 int cleared;
692 unsigned long any = 0; 736 unsigned long any = 0;
693 737
694 spin_lock(&kvm->lock); 738 spin_lock(&kvm->lock);
@@ -719,15 +763,17 @@ static int kvm_dev_ioctl_get_dirty_log(struct kvm *kvm,
719 763
720 764
721 if (any) { 765 if (any) {
722 spin_lock(&kvm->lock); 766 cleared = 0;
723 kvm_mmu_slot_remove_write_access(kvm, log->slot);
724 spin_unlock(&kvm->lock);
725 memset(memslot->dirty_bitmap, 0, n);
726 for (i = 0; i < KVM_MAX_VCPUS; ++i) { 767 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
727 struct kvm_vcpu *vcpu = vcpu_load(kvm, i); 768 struct kvm_vcpu *vcpu = vcpu_load(kvm, i);
728 769
729 if (!vcpu) 770 if (!vcpu)
730 continue; 771 continue;
772 if (!cleared) {
773 do_remove_write_access(vcpu, log->slot);
774 memset(memslot->dirty_bitmap, 0, n);
775 cleared = 1;
776 }
731 kvm_arch_ops->tlb_flush(vcpu); 777 kvm_arch_ops->tlb_flush(vcpu);
732 vcpu_put(vcpu); 778 vcpu_put(vcpu);
733 } 779 }
@@ -855,6 +901,27 @@ static int emulator_read_emulated(unsigned long addr,
855 } 901 }
856} 902}
857 903
904static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
905 unsigned long val, int bytes)
906{
907 struct kvm_memory_slot *m;
908 struct page *page;
909 void *virt;
910
911 if (((gpa + bytes - 1) >> PAGE_SHIFT) != (gpa >> PAGE_SHIFT))
912 return 0;
913 m = gfn_to_memslot(vcpu->kvm, gpa >> PAGE_SHIFT);
914 if (!m)
915 return 0;
916 page = gfn_to_page(m, gpa >> PAGE_SHIFT);
917 kvm_mmu_pre_write(vcpu, gpa, bytes);
918 virt = kmap_atomic(page, KM_USER0);
919 memcpy(virt + offset_in_page(gpa), &val, bytes);
920 kunmap_atomic(virt, KM_USER0);
921 kvm_mmu_post_write(vcpu, gpa, bytes);
922 return 1;
923}
924
858static int emulator_write_emulated(unsigned long addr, 925static int emulator_write_emulated(unsigned long addr,
859 unsigned long val, 926 unsigned long val,
860 unsigned int bytes, 927 unsigned int bytes,
@@ -866,6 +933,9 @@ static int emulator_write_emulated(unsigned long addr,
866 if (gpa == UNMAPPED_GVA) 933 if (gpa == UNMAPPED_GVA)
867 return X86EMUL_PROPAGATE_FAULT; 934 return X86EMUL_PROPAGATE_FAULT;
868 935
936 if (emulator_write_phys(vcpu, gpa, val, bytes))
937 return X86EMUL_CONTINUE;
938
869 vcpu->mmio_needed = 1; 939 vcpu->mmio_needed = 1;
870 vcpu->mmio_phys_addr = gpa; 940 vcpu->mmio_phys_addr = gpa;
871 vcpu->mmio_size = bytes; 941 vcpu->mmio_size = bytes;
@@ -890,6 +960,30 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
890 return emulator_write_emulated(addr, new, bytes, ctxt); 960 return emulator_write_emulated(addr, new, bytes, ctxt);
891} 961}
892 962
963#ifdef CONFIG_X86_32
964
965static int emulator_cmpxchg8b_emulated(unsigned long addr,
966 unsigned long old_lo,
967 unsigned long old_hi,
968 unsigned long new_lo,
969 unsigned long new_hi,
970 struct x86_emulate_ctxt *ctxt)
971{
972 static int reported;
973 int r;
974
975 if (!reported) {
976 reported = 1;
977 printk(KERN_WARNING "kvm: emulating exchange8b as write\n");
978 }
979 r = emulator_write_emulated(addr, new_lo, 4, ctxt);
980 if (r != X86EMUL_CONTINUE)
981 return r;
982 return emulator_write_emulated(addr+4, new_hi, 4, ctxt);
983}
984
985#endif
986
893static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg) 987static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg)
894{ 988{
895 return kvm_arch_ops->get_segment_base(vcpu, seg); 989 return kvm_arch_ops->get_segment_base(vcpu, seg);
@@ -897,18 +991,15 @@ static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg)
897 991
898int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address) 992int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address)
899{ 993{
900 spin_lock(&vcpu->kvm->lock);
901 vcpu->mmu.inval_page(vcpu, address);
902 spin_unlock(&vcpu->kvm->lock);
903 kvm_arch_ops->invlpg(vcpu, address);
904 return X86EMUL_CONTINUE; 994 return X86EMUL_CONTINUE;
905} 995}
906 996
907int emulate_clts(struct kvm_vcpu *vcpu) 997int emulate_clts(struct kvm_vcpu *vcpu)
908{ 998{
909 unsigned long cr0 = vcpu->cr0; 999 unsigned long cr0;
910 1000
911 cr0 &= ~CR0_TS_MASK; 1001 kvm_arch_ops->decache_cr0_cr4_guest_bits(vcpu);
1002 cr0 = vcpu->cr0 & ~CR0_TS_MASK;
912 kvm_arch_ops->set_cr0(vcpu, cr0); 1003 kvm_arch_ops->set_cr0(vcpu, cr0);
913 return X86EMUL_CONTINUE; 1004 return X86EMUL_CONTINUE;
914} 1005}
@@ -967,6 +1058,9 @@ struct x86_emulate_ops emulate_ops = {
967 .read_emulated = emulator_read_emulated, 1058 .read_emulated = emulator_read_emulated,
968 .write_emulated = emulator_write_emulated, 1059 .write_emulated = emulator_write_emulated,
969 .cmpxchg_emulated = emulator_cmpxchg_emulated, 1060 .cmpxchg_emulated = emulator_cmpxchg_emulated,
1061#ifdef CONFIG_X86_32
1062 .cmpxchg8b_emulated = emulator_cmpxchg8b_emulated,
1063#endif
970}; 1064};
971 1065
972int emulate_instruction(struct kvm_vcpu *vcpu, 1066int emulate_instruction(struct kvm_vcpu *vcpu,
@@ -1016,6 +1110,8 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
1016 } 1110 }
1017 1111
1018 if (r) { 1112 if (r) {
1113 if (kvm_mmu_unprotect_page_virt(vcpu, cr2))
1114 return EMULATE_DONE;
1019 if (!vcpu->mmio_needed) { 1115 if (!vcpu->mmio_needed) {
1020 report_emulation_failure(&emulate_ctxt); 1116 report_emulation_failure(&emulate_ctxt);
1021 return EMULATE_FAIL; 1117 return EMULATE_FAIL;
@@ -1061,6 +1157,7 @@ void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,
1061 1157
1062unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr) 1158unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr)
1063{ 1159{
1160 kvm_arch_ops->decache_cr0_cr4_guest_bits(vcpu);
1064 switch (cr) { 1161 switch (cr) {
1065 case 0: 1162 case 0:
1066 return vcpu->cr0; 1163 return vcpu->cr0;
@@ -1098,6 +1195,54 @@ void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long val,
1098 } 1195 }
1099} 1196}
1100 1197
1198int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
1199{
1200 u64 data;
1201
1202 switch (msr) {
1203 case 0xc0010010: /* SYSCFG */
1204 case 0xc0010015: /* HWCR */
1205 case MSR_IA32_PLATFORM_ID:
1206 case MSR_IA32_P5_MC_ADDR:
1207 case MSR_IA32_P5_MC_TYPE:
1208 case MSR_IA32_MC0_CTL:
1209 case MSR_IA32_MCG_STATUS:
1210 case MSR_IA32_MCG_CAP:
1211 case MSR_IA32_MC0_MISC:
1212 case MSR_IA32_MC0_MISC+4:
1213 case MSR_IA32_MC0_MISC+8:
1214 case MSR_IA32_MC0_MISC+12:
1215 case MSR_IA32_MC0_MISC+16:
1216 case MSR_IA32_UCODE_REV:
1217 case MSR_IA32_PERF_STATUS:
1218 /* MTRR registers */
1219 case 0xfe:
1220 case 0x200 ... 0x2ff:
1221 data = 0;
1222 break;
1223 case 0xcd: /* fsb frequency */
1224 data = 3;
1225 break;
1226 case MSR_IA32_APICBASE:
1227 data = vcpu->apic_base;
1228 break;
1229 case MSR_IA32_MISC_ENABLE:
1230 data = vcpu->ia32_misc_enable_msr;
1231 break;
1232#ifdef CONFIG_X86_64
1233 case MSR_EFER:
1234 data = vcpu->shadow_efer;
1235 break;
1236#endif
1237 default:
1238 printk(KERN_ERR "kvm: unhandled rdmsr: 0x%x\n", msr);
1239 return 1;
1240 }
1241 *pdata = data;
1242 return 0;
1243}
1244EXPORT_SYMBOL_GPL(kvm_get_msr_common);
1245
1101/* 1246/*
1102 * Reads an msr value (of 'msr_index') into 'pdata'. 1247 * Reads an msr value (of 'msr_index') into 'pdata'.
1103 * Returns 0 on success, non-0 otherwise. 1248 * Returns 0 on success, non-0 otherwise.
@@ -1110,7 +1255,7 @@ static int get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
1110 1255
1111#ifdef CONFIG_X86_64 1256#ifdef CONFIG_X86_64
1112 1257
1113void set_efer(struct kvm_vcpu *vcpu, u64 efer) 1258static void set_efer(struct kvm_vcpu *vcpu, u64 efer)
1114{ 1259{
1115 if (efer & EFER_RESERVED_BITS) { 1260 if (efer & EFER_RESERVED_BITS) {
1116 printk(KERN_DEBUG "set_efer: 0x%llx #GP, reserved bits\n", 1261 printk(KERN_DEBUG "set_efer: 0x%llx #GP, reserved bits\n",
@@ -1133,10 +1278,39 @@ void set_efer(struct kvm_vcpu *vcpu, u64 efer)
1133 1278
1134 vcpu->shadow_efer = efer; 1279 vcpu->shadow_efer = efer;
1135} 1280}
1136EXPORT_SYMBOL_GPL(set_efer);
1137 1281
1138#endif 1282#endif
1139 1283
1284int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1285{
1286 switch (msr) {
1287#ifdef CONFIG_X86_64
1288 case MSR_EFER:
1289 set_efer(vcpu, data);
1290 break;
1291#endif
1292 case MSR_IA32_MC0_STATUS:
1293 printk(KERN_WARNING "%s: MSR_IA32_MC0_STATUS 0x%llx, nop\n",
1294 __FUNCTION__, data);
1295 break;
1296 case MSR_IA32_UCODE_REV:
1297 case MSR_IA32_UCODE_WRITE:
1298 case 0x200 ... 0x2ff: /* MTRRs */
1299 break;
1300 case MSR_IA32_APICBASE:
1301 vcpu->apic_base = data;
1302 break;
1303 case MSR_IA32_MISC_ENABLE:
1304 vcpu->ia32_misc_enable_msr = data;
1305 break;
1306 default:
1307 printk(KERN_ERR "kvm: unhandled wrmsr: 0x%x\n", msr);
1308 return 1;
1309 }
1310 return 0;
1311}
1312EXPORT_SYMBOL_GPL(kvm_set_msr_common);
1313
1140/* 1314/*
1141 * Writes msr value into into the appropriate "register". 1315 * Writes msr value into into the appropriate "register".
1142 * Returns 0 on success, non-0 otherwise. 1316 * Returns 0 on success, non-0 otherwise.
@@ -1179,7 +1353,7 @@ static int kvm_dev_ioctl_run(struct kvm *kvm, struct kvm_run *kvm_run)
1179 struct kvm_vcpu *vcpu; 1353 struct kvm_vcpu *vcpu;
1180 int r; 1354 int r;
1181 1355
1182 if (kvm_run->vcpu < 0 || kvm_run->vcpu >= KVM_MAX_VCPUS) 1356 if (!valid_vcpu(kvm_run->vcpu))
1183 return -EINVAL; 1357 return -EINVAL;
1184 1358
1185 vcpu = vcpu_load(kvm, kvm_run->vcpu); 1359 vcpu = vcpu_load(kvm, kvm_run->vcpu);
@@ -1208,7 +1382,7 @@ static int kvm_dev_ioctl_get_regs(struct kvm *kvm, struct kvm_regs *regs)
1208{ 1382{
1209 struct kvm_vcpu *vcpu; 1383 struct kvm_vcpu *vcpu;
1210 1384
1211 if (regs->vcpu < 0 || regs->vcpu >= KVM_MAX_VCPUS) 1385 if (!valid_vcpu(regs->vcpu))
1212 return -EINVAL; 1386 return -EINVAL;
1213 1387
1214 vcpu = vcpu_load(kvm, regs->vcpu); 1388 vcpu = vcpu_load(kvm, regs->vcpu);
@@ -1254,7 +1428,7 @@ static int kvm_dev_ioctl_set_regs(struct kvm *kvm, struct kvm_regs *regs)
1254{ 1428{
1255 struct kvm_vcpu *vcpu; 1429 struct kvm_vcpu *vcpu;
1256 1430
1257 if (regs->vcpu < 0 || regs->vcpu >= KVM_MAX_VCPUS) 1431 if (!valid_vcpu(regs->vcpu))
1258 return -EINVAL; 1432 return -EINVAL;
1259 1433
1260 vcpu = vcpu_load(kvm, regs->vcpu); 1434 vcpu = vcpu_load(kvm, regs->vcpu);
@@ -1301,7 +1475,7 @@ static int kvm_dev_ioctl_get_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1301 struct kvm_vcpu *vcpu; 1475 struct kvm_vcpu *vcpu;
1302 struct descriptor_table dt; 1476 struct descriptor_table dt;
1303 1477
1304 if (sregs->vcpu < 0 || sregs->vcpu >= KVM_MAX_VCPUS) 1478 if (!valid_vcpu(sregs->vcpu))
1305 return -EINVAL; 1479 return -EINVAL;
1306 vcpu = vcpu_load(kvm, sregs->vcpu); 1480 vcpu = vcpu_load(kvm, sregs->vcpu);
1307 if (!vcpu) 1481 if (!vcpu)
@@ -1324,6 +1498,7 @@ static int kvm_dev_ioctl_get_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1324 sregs->gdt.limit = dt.limit; 1498 sregs->gdt.limit = dt.limit;
1325 sregs->gdt.base = dt.base; 1499 sregs->gdt.base = dt.base;
1326 1500
1501 kvm_arch_ops->decache_cr0_cr4_guest_bits(vcpu);
1327 sregs->cr0 = vcpu->cr0; 1502 sregs->cr0 = vcpu->cr0;
1328 sregs->cr2 = vcpu->cr2; 1503 sregs->cr2 = vcpu->cr2;
1329 sregs->cr3 = vcpu->cr3; 1504 sregs->cr3 = vcpu->cr3;
@@ -1353,7 +1528,7 @@ static int kvm_dev_ioctl_set_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1353 int i; 1528 int i;
1354 struct descriptor_table dt; 1529 struct descriptor_table dt;
1355 1530
1356 if (sregs->vcpu < 0 || sregs->vcpu >= KVM_MAX_VCPUS) 1531 if (!valid_vcpu(sregs->vcpu))
1357 return -EINVAL; 1532 return -EINVAL;
1358 vcpu = vcpu_load(kvm, sregs->vcpu); 1533 vcpu = vcpu_load(kvm, sregs->vcpu);
1359 if (!vcpu) 1534 if (!vcpu)
@@ -1388,11 +1563,15 @@ static int kvm_dev_ioctl_set_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1388#endif 1563#endif
1389 vcpu->apic_base = sregs->apic_base; 1564 vcpu->apic_base = sregs->apic_base;
1390 1565
1566 kvm_arch_ops->decache_cr0_cr4_guest_bits(vcpu);
1567
1391 mmu_reset_needed |= vcpu->cr0 != sregs->cr0; 1568 mmu_reset_needed |= vcpu->cr0 != sregs->cr0;
1392 kvm_arch_ops->set_cr0_no_modeswitch(vcpu, sregs->cr0); 1569 kvm_arch_ops->set_cr0_no_modeswitch(vcpu, sregs->cr0);
1393 1570
1394 mmu_reset_needed |= vcpu->cr4 != sregs->cr4; 1571 mmu_reset_needed |= vcpu->cr4 != sregs->cr4;
1395 kvm_arch_ops->set_cr4(vcpu, sregs->cr4); 1572 kvm_arch_ops->set_cr4(vcpu, sregs->cr4);
1573 if (!is_long_mode(vcpu) && is_pae(vcpu))
1574 load_pdptrs(vcpu, vcpu->cr3);
1396 1575
1397 if (mmu_reset_needed) 1576 if (mmu_reset_needed)
1398 kvm_mmu_reset_context(vcpu); 1577 kvm_mmu_reset_context(vcpu);
@@ -1412,6 +1591,9 @@ static int kvm_dev_ioctl_set_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1412/* 1591/*
1413 * List of msr numbers which we expose to userspace through KVM_GET_MSRS 1592 * List of msr numbers which we expose to userspace through KVM_GET_MSRS
1414 * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. 1593 * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
1594 *
1595 * This list is modified at module load time to reflect the
1596 * capabilities of the host cpu.
1415 */ 1597 */
1416static u32 msrs_to_save[] = { 1598static u32 msrs_to_save[] = {
1417 MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP, 1599 MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
@@ -1422,6 +1604,26 @@ static u32 msrs_to_save[] = {
1422 MSR_IA32_TIME_STAMP_COUNTER, 1604 MSR_IA32_TIME_STAMP_COUNTER,
1423}; 1605};
1424 1606
1607static unsigned num_msrs_to_save;
1608
1609static u32 emulated_msrs[] = {
1610 MSR_IA32_MISC_ENABLE,
1611};
1612
1613static __init void kvm_init_msr_list(void)
1614{
1615 u32 dummy[2];
1616 unsigned i, j;
1617
1618 for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) {
1619 if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0)
1620 continue;
1621 if (j < i)
1622 msrs_to_save[j] = msrs_to_save[i];
1623 j++;
1624 }
1625 num_msrs_to_save = j;
1626}
1425 1627
1426/* 1628/*
1427 * Adapt set_msr() to msr_io()'s calling convention 1629 * Adapt set_msr() to msr_io()'s calling convention
@@ -1444,7 +1646,7 @@ static int __msr_io(struct kvm *kvm, struct kvm_msrs *msrs,
1444 struct kvm_vcpu *vcpu; 1646 struct kvm_vcpu *vcpu;
1445 int i; 1647 int i;
1446 1648
1447 if (msrs->vcpu < 0 || msrs->vcpu >= KVM_MAX_VCPUS) 1649 if (!valid_vcpu(msrs->vcpu))
1448 return -EINVAL; 1650 return -EINVAL;
1449 1651
1450 vcpu = vcpu_load(kvm, msrs->vcpu); 1652 vcpu = vcpu_load(kvm, msrs->vcpu);
@@ -1537,7 +1739,7 @@ static int kvm_dev_ioctl_interrupt(struct kvm *kvm, struct kvm_interrupt *irq)
1537{ 1739{
1538 struct kvm_vcpu *vcpu; 1740 struct kvm_vcpu *vcpu;
1539 1741
1540 if (irq->vcpu < 0 || irq->vcpu >= KVM_MAX_VCPUS) 1742 if (!valid_vcpu(irq->vcpu))
1541 return -EINVAL; 1743 return -EINVAL;
1542 if (irq->irq < 0 || irq->irq >= 256) 1744 if (irq->irq < 0 || irq->irq >= 256)
1543 return -EINVAL; 1745 return -EINVAL;
@@ -1559,7 +1761,7 @@ static int kvm_dev_ioctl_debug_guest(struct kvm *kvm,
1559 struct kvm_vcpu *vcpu; 1761 struct kvm_vcpu *vcpu;
1560 int r; 1762 int r;
1561 1763
1562 if (dbg->vcpu < 0 || dbg->vcpu >= KVM_MAX_VCPUS) 1764 if (!valid_vcpu(dbg->vcpu))
1563 return -EINVAL; 1765 return -EINVAL;
1564 vcpu = vcpu_load(kvm, dbg->vcpu); 1766 vcpu = vcpu_load(kvm, dbg->vcpu);
1565 if (!vcpu) 1767 if (!vcpu)
@@ -1579,6 +1781,9 @@ static long kvm_dev_ioctl(struct file *filp,
1579 int r = -EINVAL; 1781 int r = -EINVAL;
1580 1782
1581 switch (ioctl) { 1783 switch (ioctl) {
1784 case KVM_GET_API_VERSION:
1785 r = KVM_API_VERSION;
1786 break;
1582 case KVM_CREATE_VCPU: { 1787 case KVM_CREATE_VCPU: {
1583 r = kvm_dev_ioctl_create_vcpu(kvm, arg); 1788 r = kvm_dev_ioctl_create_vcpu(kvm, arg);
1584 if (r) 1789 if (r)
@@ -1592,12 +1797,12 @@ static long kvm_dev_ioctl(struct file *filp,
1592 if (copy_from_user(&kvm_run, (void *)arg, sizeof kvm_run)) 1797 if (copy_from_user(&kvm_run, (void *)arg, sizeof kvm_run))
1593 goto out; 1798 goto out;
1594 r = kvm_dev_ioctl_run(kvm, &kvm_run); 1799 r = kvm_dev_ioctl_run(kvm, &kvm_run);
1595 if (r < 0) 1800 if (r < 0 && r != -EINTR)
1596 goto out; 1801 goto out;
1597 r = -EFAULT; 1802 if (copy_to_user((void *)arg, &kvm_run, sizeof kvm_run)) {
1598 if (copy_to_user((void *)arg, &kvm_run, sizeof kvm_run)) 1803 r = -EFAULT;
1599 goto out; 1804 goto out;
1600 r = 0; 1805 }
1601 break; 1806 break;
1602 } 1807 }
1603 case KVM_GET_REGS: { 1808 case KVM_GET_REGS: {
@@ -1730,17 +1935,23 @@ static long kvm_dev_ioctl(struct file *filp,
1730 if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list)) 1935 if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list))
1731 goto out; 1936 goto out;
1732 n = msr_list.nmsrs; 1937 n = msr_list.nmsrs;
1733 msr_list.nmsrs = ARRAY_SIZE(msrs_to_save); 1938 msr_list.nmsrs = num_msrs_to_save + ARRAY_SIZE(emulated_msrs);
1734 if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list)) 1939 if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list))
1735 goto out; 1940 goto out;
1736 r = -E2BIG; 1941 r = -E2BIG;
1737 if (n < ARRAY_SIZE(msrs_to_save)) 1942 if (n < num_msrs_to_save)
1738 goto out; 1943 goto out;
1739 r = -EFAULT; 1944 r = -EFAULT;
1740 if (copy_to_user(user_msr_list->indices, &msrs_to_save, 1945 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
1741 sizeof msrs_to_save)) 1946 num_msrs_to_save * sizeof(u32)))
1947 goto out;
1948 if (copy_to_user(user_msr_list->indices
1949 + num_msrs_to_save * sizeof(u32),
1950 &emulated_msrs,
1951 ARRAY_SIZE(emulated_msrs) * sizeof(u32)))
1742 goto out; 1952 goto out;
1743 r = 0; 1953 r = 0;
1954 break;
1744 } 1955 }
1745 default: 1956 default:
1746 ; 1957 ;
@@ -1838,17 +2049,22 @@ int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
1838{ 2049{
1839 int r; 2050 int r;
1840 2051
1841 kvm_arch_ops = ops; 2052 if (kvm_arch_ops) {
2053 printk(KERN_ERR "kvm: already loaded the other module\n");
2054 return -EEXIST;
2055 }
1842 2056
1843 if (!kvm_arch_ops->cpu_has_kvm_support()) { 2057 if (!ops->cpu_has_kvm_support()) {
1844 printk(KERN_ERR "kvm: no hardware support\n"); 2058 printk(KERN_ERR "kvm: no hardware support\n");
1845 return -EOPNOTSUPP; 2059 return -EOPNOTSUPP;
1846 } 2060 }
1847 if (kvm_arch_ops->disabled_by_bios()) { 2061 if (ops->disabled_by_bios()) {
1848 printk(KERN_ERR "kvm: disabled by bios\n"); 2062 printk(KERN_ERR "kvm: disabled by bios\n");
1849 return -EOPNOTSUPP; 2063 return -EOPNOTSUPP;
1850 } 2064 }
1851 2065
2066 kvm_arch_ops = ops;
2067
1852 r = kvm_arch_ops->hardware_setup(); 2068 r = kvm_arch_ops->hardware_setup();
1853 if (r < 0) 2069 if (r < 0)
1854 return r; 2070 return r;
@@ -1880,6 +2096,7 @@ void kvm_exit_arch(void)
1880 unregister_reboot_notifier(&kvm_reboot_notifier); 2096 unregister_reboot_notifier(&kvm_reboot_notifier);
1881 on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1); 2097 on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1);
1882 kvm_arch_ops->hardware_unsetup(); 2098 kvm_arch_ops->hardware_unsetup();
2099 kvm_arch_ops = NULL;
1883} 2100}
1884 2101
1885static __init int kvm_init(void) 2102static __init int kvm_init(void)
@@ -1889,6 +2106,8 @@ static __init int kvm_init(void)
1889 2106
1890 kvm_init_debug(); 2107 kvm_init_debug();
1891 2108
2109 kvm_init_msr_list();
2110
1892 if ((bad_page = alloc_page(GFP_KERNEL)) == NULL) { 2111 if ((bad_page = alloc_page(GFP_KERNEL)) == NULL) {
1893 r = -ENOMEM; 2112 r = -ENOMEM;
1894 goto out; 2113 goto out;
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 3d367cbfe1..22c426cd8c 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -26,7 +26,31 @@
26#include "vmx.h" 26#include "vmx.h"
27#include "kvm.h" 27#include "kvm.h"
28 28
29#undef MMU_DEBUG
30
31#undef AUDIT
32
33#ifdef AUDIT
34static void kvm_mmu_audit(struct kvm_vcpu *vcpu, const char *msg);
35#else
36static void kvm_mmu_audit(struct kvm_vcpu *vcpu, const char *msg) {}
37#endif
38
39#ifdef MMU_DEBUG
40
41#define pgprintk(x...) do { if (dbg) printk(x); } while (0)
42#define rmap_printk(x...) do { if (dbg) printk(x); } while (0)
43
44#else
45
29#define pgprintk(x...) do { } while (0) 46#define pgprintk(x...) do { } while (0)
47#define rmap_printk(x...) do { } while (0)
48
49#endif
50
51#if defined(MMU_DEBUG) || defined(AUDIT)
52static int dbg = 1;
53#endif
30 54
31#define ASSERT(x) \ 55#define ASSERT(x) \
32 if (!(x)) { \ 56 if (!(x)) { \
@@ -34,8 +58,10 @@
34 __FILE__, __LINE__, #x); \ 58 __FILE__, __LINE__, #x); \
35 } 59 }
36 60
37#define PT64_ENT_PER_PAGE 512 61#define PT64_PT_BITS 9
38#define PT32_ENT_PER_PAGE 1024 62#define PT64_ENT_PER_PAGE (1 << PT64_PT_BITS)
63#define PT32_PT_BITS 10
64#define PT32_ENT_PER_PAGE (1 << PT32_PT_BITS)
39 65
40#define PT_WRITABLE_SHIFT 1 66#define PT_WRITABLE_SHIFT 1
41 67
@@ -117,6 +143,7 @@
117#define PFERR_PRESENT_MASK (1U << 0) 143#define PFERR_PRESENT_MASK (1U << 0)
118#define PFERR_WRITE_MASK (1U << 1) 144#define PFERR_WRITE_MASK (1U << 1)
119#define PFERR_USER_MASK (1U << 2) 145#define PFERR_USER_MASK (1U << 2)
146#define PFERR_FETCH_MASK (1U << 4)
120 147
121#define PT64_ROOT_LEVEL 4 148#define PT64_ROOT_LEVEL 4
122#define PT32_ROOT_LEVEL 2 149#define PT32_ROOT_LEVEL 2
@@ -125,6 +152,13 @@
125#define PT_DIRECTORY_LEVEL 2 152#define PT_DIRECTORY_LEVEL 2
126#define PT_PAGE_TABLE_LEVEL 1 153#define PT_PAGE_TABLE_LEVEL 1
127 154
155#define RMAP_EXT 4
156
157struct kvm_rmap_desc {
158 u64 *shadow_ptes[RMAP_EXT];
159 struct kvm_rmap_desc *more;
160};
161
128static int is_write_protection(struct kvm_vcpu *vcpu) 162static int is_write_protection(struct kvm_vcpu *vcpu)
129{ 163{
130 return vcpu->cr0 & CR0_WP_MASK; 164 return vcpu->cr0 & CR0_WP_MASK;
@@ -135,6 +169,11 @@ static int is_cpuid_PSE36(void)
135 return 1; 169 return 1;
136} 170}
137 171
172static int is_nx(struct kvm_vcpu *vcpu)
173{
174 return vcpu->shadow_efer & EFER_NX;
175}
176
138static int is_present_pte(unsigned long pte) 177static int is_present_pte(unsigned long pte)
139{ 178{
140 return pte & PT_PRESENT_MASK; 179 return pte & PT_PRESENT_MASK;
@@ -150,32 +189,272 @@ static int is_io_pte(unsigned long pte)
150 return pte & PT_SHADOW_IO_MARK; 189 return pte & PT_SHADOW_IO_MARK;
151} 190}
152 191
192static int is_rmap_pte(u64 pte)
193{
194 return (pte & (PT_WRITABLE_MASK | PT_PRESENT_MASK))
195 == (PT_WRITABLE_MASK | PT_PRESENT_MASK);
196}
197
198static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
199 size_t objsize, int min)
200{
201 void *obj;
202
203 if (cache->nobjs >= min)
204 return 0;
205 while (cache->nobjs < ARRAY_SIZE(cache->objects)) {
206 obj = kzalloc(objsize, GFP_NOWAIT);
207 if (!obj)
208 return -ENOMEM;
209 cache->objects[cache->nobjs++] = obj;
210 }
211 return 0;
212}
213
214static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc)
215{
216 while (mc->nobjs)
217 kfree(mc->objects[--mc->nobjs]);
218}
219
220static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu)
221{
222 int r;
223
224 r = mmu_topup_memory_cache(&vcpu->mmu_pte_chain_cache,
225 sizeof(struct kvm_pte_chain), 4);
226 if (r)
227 goto out;
228 r = mmu_topup_memory_cache(&vcpu->mmu_rmap_desc_cache,
229 sizeof(struct kvm_rmap_desc), 1);
230out:
231 return r;
232}
233
234static void mmu_free_memory_caches(struct kvm_vcpu *vcpu)
235{
236 mmu_free_memory_cache(&vcpu->mmu_pte_chain_cache);
237 mmu_free_memory_cache(&vcpu->mmu_rmap_desc_cache);
238}
239
240static void *mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc,
241 size_t size)
242{
243 void *p;
244
245 BUG_ON(!mc->nobjs);
246 p = mc->objects[--mc->nobjs];
247 memset(p, 0, size);
248 return p;
249}
250
251static void mmu_memory_cache_free(struct kvm_mmu_memory_cache *mc, void *obj)
252{
253 if (mc->nobjs < KVM_NR_MEM_OBJS)
254 mc->objects[mc->nobjs++] = obj;
255 else
256 kfree(obj);
257}
258
259static struct kvm_pte_chain *mmu_alloc_pte_chain(struct kvm_vcpu *vcpu)
260{
261 return mmu_memory_cache_alloc(&vcpu->mmu_pte_chain_cache,
262 sizeof(struct kvm_pte_chain));
263}
264
265static void mmu_free_pte_chain(struct kvm_vcpu *vcpu,
266 struct kvm_pte_chain *pc)
267{
268 mmu_memory_cache_free(&vcpu->mmu_pte_chain_cache, pc);
269}
270
271static struct kvm_rmap_desc *mmu_alloc_rmap_desc(struct kvm_vcpu *vcpu)
272{
273 return mmu_memory_cache_alloc(&vcpu->mmu_rmap_desc_cache,
274 sizeof(struct kvm_rmap_desc));
275}
276
277static void mmu_free_rmap_desc(struct kvm_vcpu *vcpu,
278 struct kvm_rmap_desc *rd)
279{
280 mmu_memory_cache_free(&vcpu->mmu_rmap_desc_cache, rd);
281}
282
283/*
284 * Reverse mapping data structures:
285 *
286 * If page->private bit zero is zero, then page->private points to the
287 * shadow page table entry that points to page_address(page).
288 *
289 * If page->private bit zero is one, (then page->private & ~1) points
290 * to a struct kvm_rmap_desc containing more mappings.
291 */
292static void rmap_add(struct kvm_vcpu *vcpu, u64 *spte)
293{
294 struct page *page;
295 struct kvm_rmap_desc *desc;
296 int i;
297
298 if (!is_rmap_pte(*spte))
299 return;
300 page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
301 if (!page->private) {
302 rmap_printk("rmap_add: %p %llx 0->1\n", spte, *spte);
303 page->private = (unsigned long)spte;
304 } else if (!(page->private & 1)) {
305 rmap_printk("rmap_add: %p %llx 1->many\n", spte, *spte);
306 desc = mmu_alloc_rmap_desc(vcpu);
307 desc->shadow_ptes[0] = (u64 *)page->private;
308 desc->shadow_ptes[1] = spte;
309 page->private = (unsigned long)desc | 1;
310 } else {
311 rmap_printk("rmap_add: %p %llx many->many\n", spte, *spte);
312 desc = (struct kvm_rmap_desc *)(page->private & ~1ul);
313 while (desc->shadow_ptes[RMAP_EXT-1] && desc->more)
314 desc = desc->more;
315 if (desc->shadow_ptes[RMAP_EXT-1]) {
316 desc->more = mmu_alloc_rmap_desc(vcpu);
317 desc = desc->more;
318 }
319 for (i = 0; desc->shadow_ptes[i]; ++i)
320 ;
321 desc->shadow_ptes[i] = spte;
322 }
323}
324
325static void rmap_desc_remove_entry(struct kvm_vcpu *vcpu,
326 struct page *page,
327 struct kvm_rmap_desc *desc,
328 int i,
329 struct kvm_rmap_desc *prev_desc)
330{
331 int j;
332
333 for (j = RMAP_EXT - 1; !desc->shadow_ptes[j] && j > i; --j)
334 ;
335 desc->shadow_ptes[i] = desc->shadow_ptes[j];
336 desc->shadow_ptes[j] = 0;
337 if (j != 0)
338 return;
339 if (!prev_desc && !desc->more)
340 page->private = (unsigned long)desc->shadow_ptes[0];
341 else
342 if (prev_desc)
343 prev_desc->more = desc->more;
344 else
345 page->private = (unsigned long)desc->more | 1;
346 mmu_free_rmap_desc(vcpu, desc);
347}
348
349static void rmap_remove(struct kvm_vcpu *vcpu, u64 *spte)
350{
351 struct page *page;
352 struct kvm_rmap_desc *desc;
353 struct kvm_rmap_desc *prev_desc;
354 int i;
355
356 if (!is_rmap_pte(*spte))
357 return;
358 page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
359 if (!page->private) {
360 printk(KERN_ERR "rmap_remove: %p %llx 0->BUG\n", spte, *spte);
361 BUG();
362 } else if (!(page->private & 1)) {
363 rmap_printk("rmap_remove: %p %llx 1->0\n", spte, *spte);
364 if ((u64 *)page->private != spte) {
365 printk(KERN_ERR "rmap_remove: %p %llx 1->BUG\n",
366 spte, *spte);
367 BUG();
368 }
369 page->private = 0;
370 } else {
371 rmap_printk("rmap_remove: %p %llx many->many\n", spte, *spte);
372 desc = (struct kvm_rmap_desc *)(page->private & ~1ul);
373 prev_desc = NULL;
374 while (desc) {
375 for (i = 0; i < RMAP_EXT && desc->shadow_ptes[i]; ++i)
376 if (desc->shadow_ptes[i] == spte) {
377 rmap_desc_remove_entry(vcpu, page,
378 desc, i,
379 prev_desc);
380 return;
381 }
382 prev_desc = desc;
383 desc = desc->more;
384 }
385 BUG();
386 }
387}
388
389static void rmap_write_protect(struct kvm_vcpu *vcpu, u64 gfn)
390{
391 struct kvm *kvm = vcpu->kvm;
392 struct page *page;
393 struct kvm_memory_slot *slot;
394 struct kvm_rmap_desc *desc;
395 u64 *spte;
396
397 slot = gfn_to_memslot(kvm, gfn);
398 BUG_ON(!slot);
399 page = gfn_to_page(slot, gfn);
400
401 while (page->private) {
402 if (!(page->private & 1))
403 spte = (u64 *)page->private;
404 else {
405 desc = (struct kvm_rmap_desc *)(page->private & ~1ul);
406 spte = desc->shadow_ptes[0];
407 }
408 BUG_ON(!spte);
409 BUG_ON((*spte & PT64_BASE_ADDR_MASK) !=
410 page_to_pfn(page) << PAGE_SHIFT);
411 BUG_ON(!(*spte & PT_PRESENT_MASK));
412 BUG_ON(!(*spte & PT_WRITABLE_MASK));
413 rmap_printk("rmap_write_protect: spte %p %llx\n", spte, *spte);
414 rmap_remove(vcpu, spte);
415 kvm_arch_ops->tlb_flush(vcpu);
416 *spte &= ~(u64)PT_WRITABLE_MASK;
417 }
418}
419
420static int is_empty_shadow_page(hpa_t page_hpa)
421{
422 u64 *pos;
423 u64 *end;
424
425 for (pos = __va(page_hpa), end = pos + PAGE_SIZE / sizeof(u64);
426 pos != end; pos++)
427 if (*pos != 0) {
428 printk(KERN_ERR "%s: %p %llx\n", __FUNCTION__,
429 pos, *pos);
430 return 0;
431 }
432 return 1;
433}
434
153static void kvm_mmu_free_page(struct kvm_vcpu *vcpu, hpa_t page_hpa) 435static void kvm_mmu_free_page(struct kvm_vcpu *vcpu, hpa_t page_hpa)
154{ 436{
155 struct kvm_mmu_page *page_head = page_header(page_hpa); 437 struct kvm_mmu_page *page_head = page_header(page_hpa);
156 438
439 ASSERT(is_empty_shadow_page(page_hpa));
157 list_del(&page_head->link); 440 list_del(&page_head->link);
158 page_head->page_hpa = page_hpa; 441 page_head->page_hpa = page_hpa;
159 list_add(&page_head->link, &vcpu->free_pages); 442 list_add(&page_head->link, &vcpu->free_pages);
443 ++vcpu->kvm->n_free_mmu_pages;
160} 444}
161 445
162static int is_empty_shadow_page(hpa_t page_hpa) 446static unsigned kvm_page_table_hashfn(gfn_t gfn)
163{ 447{
164 u32 *pos; 448 return gfn;
165 u32 *end;
166 for (pos = __va(page_hpa), end = pos + PAGE_SIZE / sizeof(u32);
167 pos != end; pos++)
168 if (*pos != 0)
169 return 0;
170 return 1;
171} 449}
172 450
173static hpa_t kvm_mmu_alloc_page(struct kvm_vcpu *vcpu, u64 *parent_pte) 451static struct kvm_mmu_page *kvm_mmu_alloc_page(struct kvm_vcpu *vcpu,
452 u64 *parent_pte)
174{ 453{
175 struct kvm_mmu_page *page; 454 struct kvm_mmu_page *page;
176 455
177 if (list_empty(&vcpu->free_pages)) 456 if (list_empty(&vcpu->free_pages))
178 return INVALID_PAGE; 457 return NULL;
179 458
180 page = list_entry(vcpu->free_pages.next, struct kvm_mmu_page, link); 459 page = list_entry(vcpu->free_pages.next, struct kvm_mmu_page, link);
181 list_del(&page->link); 460 list_del(&page->link);
@@ -183,8 +462,239 @@ static hpa_t kvm_mmu_alloc_page(struct kvm_vcpu *vcpu, u64 *parent_pte)
183 ASSERT(is_empty_shadow_page(page->page_hpa)); 462 ASSERT(is_empty_shadow_page(page->page_hpa));
184 page->slot_bitmap = 0; 463 page->slot_bitmap = 0;
185 page->global = 1; 464 page->global = 1;
465 page->multimapped = 0;
186 page->parent_pte = parent_pte; 466 page->parent_pte = parent_pte;
187 return page->page_hpa; 467 --vcpu->kvm->n_free_mmu_pages;
468 return page;
469}
470
471static void mmu_page_add_parent_pte(struct kvm_vcpu *vcpu,
472 struct kvm_mmu_page *page, u64 *parent_pte)
473{
474 struct kvm_pte_chain *pte_chain;
475 struct hlist_node *node;
476 int i;
477
478 if (!parent_pte)
479 return;
480 if (!page->multimapped) {
481 u64 *old = page->parent_pte;
482
483 if (!old) {
484 page->parent_pte = parent_pte;
485 return;
486 }
487 page->multimapped = 1;
488 pte_chain = mmu_alloc_pte_chain(vcpu);
489 INIT_HLIST_HEAD(&page->parent_ptes);
490 hlist_add_head(&pte_chain->link, &page->parent_ptes);
491 pte_chain->parent_ptes[0] = old;
492 }
493 hlist_for_each_entry(pte_chain, node, &page->parent_ptes, link) {
494 if (pte_chain->parent_ptes[NR_PTE_CHAIN_ENTRIES-1])
495 continue;
496 for (i = 0; i < NR_PTE_CHAIN_ENTRIES; ++i)
497 if (!pte_chain->parent_ptes[i]) {
498 pte_chain->parent_ptes[i] = parent_pte;
499 return;
500 }
501 }
502 pte_chain = mmu_alloc_pte_chain(vcpu);
503 BUG_ON(!pte_chain);
504 hlist_add_head(&pte_chain->link, &page->parent_ptes);
505 pte_chain->parent_ptes[0] = parent_pte;
506}
507
508static void mmu_page_remove_parent_pte(struct kvm_vcpu *vcpu,
509 struct kvm_mmu_page *page,
510 u64 *parent_pte)
511{
512 struct kvm_pte_chain *pte_chain;
513 struct hlist_node *node;
514 int i;
515
516 if (!page->multimapped) {
517 BUG_ON(page->parent_pte != parent_pte);
518 page->parent_pte = NULL;
519 return;
520 }
521 hlist_for_each_entry(pte_chain, node, &page->parent_ptes, link)
522 for (i = 0; i < NR_PTE_CHAIN_ENTRIES; ++i) {
523 if (!pte_chain->parent_ptes[i])
524 break;
525 if (pte_chain->parent_ptes[i] != parent_pte)
526 continue;
527 while (i + 1 < NR_PTE_CHAIN_ENTRIES
528 && pte_chain->parent_ptes[i + 1]) {
529 pte_chain->parent_ptes[i]
530 = pte_chain->parent_ptes[i + 1];
531 ++i;
532 }
533 pte_chain->parent_ptes[i] = NULL;
534 if (i == 0) {
535 hlist_del(&pte_chain->link);
536 mmu_free_pte_chain(vcpu, pte_chain);
537 if (hlist_empty(&page->parent_ptes)) {
538 page->multimapped = 0;
539 page->parent_pte = NULL;
540 }
541 }
542 return;
543 }
544 BUG();
545}
546
547static struct kvm_mmu_page *kvm_mmu_lookup_page(struct kvm_vcpu *vcpu,
548 gfn_t gfn)
549{
550 unsigned index;
551 struct hlist_head *bucket;
552 struct kvm_mmu_page *page;
553 struct hlist_node *node;
554
555 pgprintk("%s: looking for gfn %lx\n", __FUNCTION__, gfn);
556 index = kvm_page_table_hashfn(gfn) % KVM_NUM_MMU_PAGES;
557 bucket = &vcpu->kvm->mmu_page_hash[index];
558 hlist_for_each_entry(page, node, bucket, hash_link)
559 if (page->gfn == gfn && !page->role.metaphysical) {
560 pgprintk("%s: found role %x\n",
561 __FUNCTION__, page->role.word);
562 return page;
563 }
564 return NULL;
565}
566
567static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
568 gfn_t gfn,
569 gva_t gaddr,
570 unsigned level,
571 int metaphysical,
572 u64 *parent_pte)
573{
574 union kvm_mmu_page_role role;
575 unsigned index;
576 unsigned quadrant;
577 struct hlist_head *bucket;
578 struct kvm_mmu_page *page;
579 struct hlist_node *node;
580
581 role.word = 0;
582 role.glevels = vcpu->mmu.root_level;
583 role.level = level;
584 role.metaphysical = metaphysical;
585 if (vcpu->mmu.root_level <= PT32_ROOT_LEVEL) {
586 quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level));
587 quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1;
588 role.quadrant = quadrant;
589 }
590 pgprintk("%s: looking gfn %lx role %x\n", __FUNCTION__,
591 gfn, role.word);
592 index = kvm_page_table_hashfn(gfn) % KVM_NUM_MMU_PAGES;
593 bucket = &vcpu->kvm->mmu_page_hash[index];
594 hlist_for_each_entry(page, node, bucket, hash_link)
595 if (page->gfn == gfn && page->role.word == role.word) {
596 mmu_page_add_parent_pte(vcpu, page, parent_pte);
597 pgprintk("%s: found\n", __FUNCTION__);
598 return page;
599 }
600 page = kvm_mmu_alloc_page(vcpu, parent_pte);
601 if (!page)
602 return page;
603 pgprintk("%s: adding gfn %lx role %x\n", __FUNCTION__, gfn, role.word);
604 page->gfn = gfn;
605 page->role = role;
606 hlist_add_head(&page->hash_link, bucket);
607 if (!metaphysical)
608 rmap_write_protect(vcpu, gfn);
609 return page;
610}
611
612static void kvm_mmu_page_unlink_children(struct kvm_vcpu *vcpu,
613 struct kvm_mmu_page *page)
614{
615 unsigned i;
616 u64 *pt;
617 u64 ent;
618
619 pt = __va(page->page_hpa);
620
621 if (page->role.level == PT_PAGE_TABLE_LEVEL) {
622 for (i = 0; i < PT64_ENT_PER_PAGE; ++i) {
623 if (pt[i] & PT_PRESENT_MASK)
624 rmap_remove(vcpu, &pt[i]);
625 pt[i] = 0;
626 }
627 kvm_arch_ops->tlb_flush(vcpu);
628 return;
629 }
630
631 for (i = 0; i < PT64_ENT_PER_PAGE; ++i) {
632 ent = pt[i];
633
634 pt[i] = 0;
635 if (!(ent & PT_PRESENT_MASK))
636 continue;
637 ent &= PT64_BASE_ADDR_MASK;
638 mmu_page_remove_parent_pte(vcpu, page_header(ent), &pt[i]);
639 }
640}
641
642static void kvm_mmu_put_page(struct kvm_vcpu *vcpu,
643 struct kvm_mmu_page *page,
644 u64 *parent_pte)
645{
646 mmu_page_remove_parent_pte(vcpu, page, parent_pte);
647}
648
649static void kvm_mmu_zap_page(struct kvm_vcpu *vcpu,
650 struct kvm_mmu_page *page)
651{
652 u64 *parent_pte;
653
654 while (page->multimapped || page->parent_pte) {
655 if (!page->multimapped)
656 parent_pte = page->parent_pte;
657 else {
658 struct kvm_pte_chain *chain;
659
660 chain = container_of(page->parent_ptes.first,
661 struct kvm_pte_chain, link);
662 parent_pte = chain->parent_ptes[0];
663 }
664 BUG_ON(!parent_pte);
665 kvm_mmu_put_page(vcpu, page, parent_pte);
666 *parent_pte = 0;
667 }
668 kvm_mmu_page_unlink_children(vcpu, page);
669 if (!page->root_count) {
670 hlist_del(&page->hash_link);
671 kvm_mmu_free_page(vcpu, page->page_hpa);
672 } else {
673 list_del(&page->link);
674 list_add(&page->link, &vcpu->kvm->active_mmu_pages);
675 }
676}
677
678static int kvm_mmu_unprotect_page(struct kvm_vcpu *vcpu, gfn_t gfn)
679{
680 unsigned index;
681 struct hlist_head *bucket;
682 struct kvm_mmu_page *page;
683 struct hlist_node *node, *n;
684 int r;
685
686 pgprintk("%s: looking for gfn %lx\n", __FUNCTION__, gfn);
687 r = 0;
688 index = kvm_page_table_hashfn(gfn) % KVM_NUM_MMU_PAGES;
689 bucket = &vcpu->kvm->mmu_page_hash[index];
690 hlist_for_each_entry_safe(page, node, n, bucket, hash_link)
691 if (page->gfn == gfn && !page->role.metaphysical) {
692 pgprintk("%s: gfn %lx role %x\n", __FUNCTION__, gfn,
693 page->role.word);
694 kvm_mmu_zap_page(vcpu, page);
695 r = 1;
696 }
697 return r;
188} 698}
189 699
190static void page_header_update_slot(struct kvm *kvm, void *pte, gpa_t gpa) 700static void page_header_update_slot(struct kvm *kvm, void *pte, gpa_t gpa)
@@ -225,35 +735,6 @@ hpa_t gva_to_hpa(struct kvm_vcpu *vcpu, gva_t gva)
225 return gpa_to_hpa(vcpu, gpa); 735 return gpa_to_hpa(vcpu, gpa);
226} 736}
227 737
228
229static void release_pt_page_64(struct kvm_vcpu *vcpu, hpa_t page_hpa,
230 int level)
231{
232 ASSERT(vcpu);
233 ASSERT(VALID_PAGE(page_hpa));
234 ASSERT(level <= PT64_ROOT_LEVEL && level > 0);
235
236 if (level == 1)
237 memset(__va(page_hpa), 0, PAGE_SIZE);
238 else {
239 u64 *pos;
240 u64 *end;
241
242 for (pos = __va(page_hpa), end = pos + PT64_ENT_PER_PAGE;
243 pos != end; pos++) {
244 u64 current_ent = *pos;
245
246 *pos = 0;
247 if (is_present_pte(current_ent))
248 release_pt_page_64(vcpu,
249 current_ent &
250 PT64_BASE_ADDR_MASK,
251 level - 1);
252 }
253 }
254 kvm_mmu_free_page(vcpu, page_hpa);
255}
256
257static void nonpaging_new_cr3(struct kvm_vcpu *vcpu) 738static void nonpaging_new_cr3(struct kvm_vcpu *vcpu)
258{ 739{
259} 740}
@@ -266,52 +747,109 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
266 for (; ; level--) { 747 for (; ; level--) {
267 u32 index = PT64_INDEX(v, level); 748 u32 index = PT64_INDEX(v, level);
268 u64 *table; 749 u64 *table;
750 u64 pte;
269 751
270 ASSERT(VALID_PAGE(table_addr)); 752 ASSERT(VALID_PAGE(table_addr));
271 table = __va(table_addr); 753 table = __va(table_addr);
272 754
273 if (level == 1) { 755 if (level == 1) {
756 pte = table[index];
757 if (is_present_pte(pte) && is_writeble_pte(pte))
758 return 0;
274 mark_page_dirty(vcpu->kvm, v >> PAGE_SHIFT); 759 mark_page_dirty(vcpu->kvm, v >> PAGE_SHIFT);
275 page_header_update_slot(vcpu->kvm, table, v); 760 page_header_update_slot(vcpu->kvm, table, v);
276 table[index] = p | PT_PRESENT_MASK | PT_WRITABLE_MASK | 761 table[index] = p | PT_PRESENT_MASK | PT_WRITABLE_MASK |
277 PT_USER_MASK; 762 PT_USER_MASK;
763 rmap_add(vcpu, &table[index]);
278 return 0; 764 return 0;
279 } 765 }
280 766
281 if (table[index] == 0) { 767 if (table[index] == 0) {
282 hpa_t new_table = kvm_mmu_alloc_page(vcpu, 768 struct kvm_mmu_page *new_table;
283 &table[index]); 769 gfn_t pseudo_gfn;
284 770
285 if (!VALID_PAGE(new_table)) { 771 pseudo_gfn = (v & PT64_DIR_BASE_ADDR_MASK)
772 >> PAGE_SHIFT;
773 new_table = kvm_mmu_get_page(vcpu, pseudo_gfn,
774 v, level - 1,
775 1, &table[index]);
776 if (!new_table) {
286 pgprintk("nonpaging_map: ENOMEM\n"); 777 pgprintk("nonpaging_map: ENOMEM\n");
287 return -ENOMEM; 778 return -ENOMEM;
288 } 779 }
289 780
290 if (level == PT32E_ROOT_LEVEL) 781 table[index] = new_table->page_hpa | PT_PRESENT_MASK
291 table[index] = new_table | PT_PRESENT_MASK; 782 | PT_WRITABLE_MASK | PT_USER_MASK;
292 else
293 table[index] = new_table | PT_PRESENT_MASK |
294 PT_WRITABLE_MASK | PT_USER_MASK;
295 } 783 }
296 table_addr = table[index] & PT64_BASE_ADDR_MASK; 784 table_addr = table[index] & PT64_BASE_ADDR_MASK;
297 } 785 }
298} 786}
299 787
300static void nonpaging_flush(struct kvm_vcpu *vcpu) 788static void mmu_free_roots(struct kvm_vcpu *vcpu)
301{ 789{
302 hpa_t root = vcpu->mmu.root_hpa; 790 int i;
791 struct kvm_mmu_page *page;
303 792
304 ++kvm_stat.tlb_flush; 793#ifdef CONFIG_X86_64
305 pgprintk("nonpaging_flush\n"); 794 if (vcpu->mmu.shadow_root_level == PT64_ROOT_LEVEL) {
306 ASSERT(VALID_PAGE(root)); 795 hpa_t root = vcpu->mmu.root_hpa;
307 release_pt_page_64(vcpu, root, vcpu->mmu.shadow_root_level); 796
308 root = kvm_mmu_alloc_page(vcpu, NULL); 797 ASSERT(VALID_PAGE(root));
309 ASSERT(VALID_PAGE(root)); 798 page = page_header(root);
310 vcpu->mmu.root_hpa = root; 799 --page->root_count;
311 if (is_paging(vcpu)) 800 vcpu->mmu.root_hpa = INVALID_PAGE;
312 root |= (vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK)); 801 return;
313 kvm_arch_ops->set_cr3(vcpu, root); 802 }
314 kvm_arch_ops->tlb_flush(vcpu); 803#endif
804 for (i = 0; i < 4; ++i) {
805 hpa_t root = vcpu->mmu.pae_root[i];
806
807 ASSERT(VALID_PAGE(root));
808 root &= PT64_BASE_ADDR_MASK;
809 page = page_header(root);
810 --page->root_count;
811 vcpu->mmu.pae_root[i] = INVALID_PAGE;
812 }
813 vcpu->mmu.root_hpa = INVALID_PAGE;
814}
815
816static void mmu_alloc_roots(struct kvm_vcpu *vcpu)
817{
818 int i;
819 gfn_t root_gfn;
820 struct kvm_mmu_page *page;
821
822 root_gfn = vcpu->cr3 >> PAGE_SHIFT;
823
824#ifdef CONFIG_X86_64
825 if (vcpu->mmu.shadow_root_level == PT64_ROOT_LEVEL) {
826 hpa_t root = vcpu->mmu.root_hpa;
827
828 ASSERT(!VALID_PAGE(root));
829 page = kvm_mmu_get_page(vcpu, root_gfn, 0,
830 PT64_ROOT_LEVEL, 0, NULL);
831 root = page->page_hpa;
832 ++page->root_count;
833 vcpu->mmu.root_hpa = root;
834 return;
835 }
836#endif
837 for (i = 0; i < 4; ++i) {
838 hpa_t root = vcpu->mmu.pae_root[i];
839
840 ASSERT(!VALID_PAGE(root));
841 if (vcpu->mmu.root_level == PT32E_ROOT_LEVEL)
842 root_gfn = vcpu->pdptrs[i] >> PAGE_SHIFT;
843 else if (vcpu->mmu.root_level == 0)
844 root_gfn = 0;
845 page = kvm_mmu_get_page(vcpu, root_gfn, i << 30,
846 PT32_ROOT_LEVEL, !is_paging(vcpu),
847 NULL);
848 root = page->page_hpa;
849 ++page->root_count;
850 vcpu->mmu.pae_root[i] = root | PT_PRESENT_MASK;
851 }
852 vcpu->mmu.root_hpa = __pa(vcpu->mmu.pae_root);
315} 853}
316 854
317static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr) 855static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr)
@@ -322,43 +860,29 @@ static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr)
322static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva, 860static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
323 u32 error_code) 861 u32 error_code)
324{ 862{
325 int ret;
326 gpa_t addr = gva; 863 gpa_t addr = gva;
864 hpa_t paddr;
865 int r;
866
867 r = mmu_topup_memory_caches(vcpu);
868 if (r)
869 return r;
327 870
328 ASSERT(vcpu); 871 ASSERT(vcpu);
329 ASSERT(VALID_PAGE(vcpu->mmu.root_hpa)); 872 ASSERT(VALID_PAGE(vcpu->mmu.root_hpa));
330 873
331 for (;;) {
332 hpa_t paddr;
333
334 paddr = gpa_to_hpa(vcpu , addr & PT64_BASE_ADDR_MASK);
335 874
336 if (is_error_hpa(paddr)) 875 paddr = gpa_to_hpa(vcpu , addr & PT64_BASE_ADDR_MASK);
337 return 1;
338 876
339 ret = nonpaging_map(vcpu, addr & PAGE_MASK, paddr); 877 if (is_error_hpa(paddr))
340 if (ret) { 878 return 1;
341 nonpaging_flush(vcpu);
342 continue;
343 }
344 break;
345 }
346 return ret;
347}
348 879
349static void nonpaging_inval_page(struct kvm_vcpu *vcpu, gva_t addr) 880 return nonpaging_map(vcpu, addr & PAGE_MASK, paddr);
350{
351} 881}
352 882
353static void nonpaging_free(struct kvm_vcpu *vcpu) 883static void nonpaging_free(struct kvm_vcpu *vcpu)
354{ 884{
355 hpa_t root; 885 mmu_free_roots(vcpu);
356
357 ASSERT(vcpu);
358 root = vcpu->mmu.root_hpa;
359 if (VALID_PAGE(root))
360 release_pt_page_64(vcpu, root, vcpu->mmu.shadow_root_level);
361 vcpu->mmu.root_hpa = INVALID_PAGE;
362} 886}
363 887
364static int nonpaging_init_context(struct kvm_vcpu *vcpu) 888static int nonpaging_init_context(struct kvm_vcpu *vcpu)
@@ -367,40 +891,31 @@ static int nonpaging_init_context(struct kvm_vcpu *vcpu)
367 891
368 context->new_cr3 = nonpaging_new_cr3; 892 context->new_cr3 = nonpaging_new_cr3;
369 context->page_fault = nonpaging_page_fault; 893 context->page_fault = nonpaging_page_fault;
370 context->inval_page = nonpaging_inval_page;
371 context->gva_to_gpa = nonpaging_gva_to_gpa; 894 context->gva_to_gpa = nonpaging_gva_to_gpa;
372 context->free = nonpaging_free; 895 context->free = nonpaging_free;
373 context->root_level = PT32E_ROOT_LEVEL; 896 context->root_level = 0;
374 context->shadow_root_level = PT32E_ROOT_LEVEL; 897 context->shadow_root_level = PT32E_ROOT_LEVEL;
375 context->root_hpa = kvm_mmu_alloc_page(vcpu, NULL); 898 mmu_alloc_roots(vcpu);
376 ASSERT(VALID_PAGE(context->root_hpa)); 899 ASSERT(VALID_PAGE(context->root_hpa));
377 kvm_arch_ops->set_cr3(vcpu, context->root_hpa); 900 kvm_arch_ops->set_cr3(vcpu, context->root_hpa);
378 return 0; 901 return 0;
379} 902}
380 903
381
382static void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu) 904static void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu)
383{ 905{
384 struct kvm_mmu_page *page, *npage;
385
386 list_for_each_entry_safe(page, npage, &vcpu->kvm->active_mmu_pages,
387 link) {
388 if (page->global)
389 continue;
390
391 if (!page->parent_pte)
392 continue;
393
394 *page->parent_pte = 0;
395 release_pt_page_64(vcpu, page->page_hpa, 1);
396 }
397 ++kvm_stat.tlb_flush; 906 ++kvm_stat.tlb_flush;
398 kvm_arch_ops->tlb_flush(vcpu); 907 kvm_arch_ops->tlb_flush(vcpu);
399} 908}
400 909
401static void paging_new_cr3(struct kvm_vcpu *vcpu) 910static void paging_new_cr3(struct kvm_vcpu *vcpu)
402{ 911{
912 pgprintk("%s: cr3 %lx\n", __FUNCTION__, vcpu->cr3);
913 mmu_free_roots(vcpu);
914 if (unlikely(vcpu->kvm->n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES))
915 kvm_mmu_free_some_pages(vcpu);
916 mmu_alloc_roots(vcpu);
403 kvm_mmu_flush_tlb(vcpu); 917 kvm_mmu_flush_tlb(vcpu);
918 kvm_arch_ops->set_cr3(vcpu, vcpu->mmu.root_hpa);
404} 919}
405 920
406static void mark_pagetable_nonglobal(void *shadow_pte) 921static void mark_pagetable_nonglobal(void *shadow_pte)
@@ -412,7 +927,8 @@ static inline void set_pte_common(struct kvm_vcpu *vcpu,
412 u64 *shadow_pte, 927 u64 *shadow_pte,
413 gpa_t gaddr, 928 gpa_t gaddr,
414 int dirty, 929 int dirty,
415 u64 access_bits) 930 u64 access_bits,
931 gfn_t gfn)
416{ 932{
417 hpa_t paddr; 933 hpa_t paddr;
418 934
@@ -420,13 +936,10 @@ static inline void set_pte_common(struct kvm_vcpu *vcpu,
420 if (!dirty) 936 if (!dirty)
421 access_bits &= ~PT_WRITABLE_MASK; 937 access_bits &= ~PT_WRITABLE_MASK;
422 938
423 if (access_bits & PT_WRITABLE_MASK) 939 paddr = gpa_to_hpa(vcpu, gaddr & PT64_BASE_ADDR_MASK);
424 mark_page_dirty(vcpu->kvm, gaddr >> PAGE_SHIFT);
425 940
426 *shadow_pte |= access_bits; 941 *shadow_pte |= access_bits;
427 942
428 paddr = gpa_to_hpa(vcpu, gaddr & PT64_BASE_ADDR_MASK);
429
430 if (!(*shadow_pte & PT_GLOBAL_MASK)) 943 if (!(*shadow_pte & PT_GLOBAL_MASK))
431 mark_pagetable_nonglobal(shadow_pte); 944 mark_pagetable_nonglobal(shadow_pte);
432 945
@@ -434,10 +947,31 @@ static inline void set_pte_common(struct kvm_vcpu *vcpu,
434 *shadow_pte |= gaddr; 947 *shadow_pte |= gaddr;
435 *shadow_pte |= PT_SHADOW_IO_MARK; 948 *shadow_pte |= PT_SHADOW_IO_MARK;
436 *shadow_pte &= ~PT_PRESENT_MASK; 949 *shadow_pte &= ~PT_PRESENT_MASK;
437 } else { 950 return;
438 *shadow_pte |= paddr;
439 page_header_update_slot(vcpu->kvm, shadow_pte, gaddr);
440 } 951 }
952
953 *shadow_pte |= paddr;
954
955 if (access_bits & PT_WRITABLE_MASK) {
956 struct kvm_mmu_page *shadow;
957
958 shadow = kvm_mmu_lookup_page(vcpu, gfn);
959 if (shadow) {
960 pgprintk("%s: found shadow page for %lx, marking ro\n",
961 __FUNCTION__, gfn);
962 access_bits &= ~PT_WRITABLE_MASK;
963 if (is_writeble_pte(*shadow_pte)) {
964 *shadow_pte &= ~PT_WRITABLE_MASK;
965 kvm_arch_ops->tlb_flush(vcpu);
966 }
967 }
968 }
969
970 if (access_bits & PT_WRITABLE_MASK)
971 mark_page_dirty(vcpu->kvm, gaddr >> PAGE_SHIFT);
972
973 page_header_update_slot(vcpu->kvm, shadow_pte, gaddr);
974 rmap_add(vcpu, shadow_pte);
441} 975}
442 976
443static void inject_page_fault(struct kvm_vcpu *vcpu, 977static void inject_page_fault(struct kvm_vcpu *vcpu,
@@ -464,51 +998,6 @@ static inline int fix_read_pf(u64 *shadow_ent)
464 return 0; 998 return 0;
465} 999}
466 1000
467static int may_access(u64 pte, int write, int user)
468{
469
470 if (user && !(pte & PT_USER_MASK))
471 return 0;
472 if (write && !(pte & PT_WRITABLE_MASK))
473 return 0;
474 return 1;
475}
476
477/*
478 * Remove a shadow pte.
479 */
480static void paging_inval_page(struct kvm_vcpu *vcpu, gva_t addr)
481{
482 hpa_t page_addr = vcpu->mmu.root_hpa;
483 int level = vcpu->mmu.shadow_root_level;
484
485 ++kvm_stat.invlpg;
486
487 for (; ; level--) {
488 u32 index = PT64_INDEX(addr, level);
489 u64 *table = __va(page_addr);
490
491 if (level == PT_PAGE_TABLE_LEVEL ) {
492 table[index] = 0;
493 return;
494 }
495
496 if (!is_present_pte(table[index]))
497 return;
498
499 page_addr = table[index] & PT64_BASE_ADDR_MASK;
500
501 if (level == PT_DIRECTORY_LEVEL &&
502 (table[index] & PT_SHADOW_PS_MARK)) {
503 table[index] = 0;
504 release_pt_page_64(vcpu, page_addr, PT_PAGE_TABLE_LEVEL);
505
506 kvm_arch_ops->tlb_flush(vcpu);
507 return;
508 }
509 }
510}
511
512static void paging_free(struct kvm_vcpu *vcpu) 1001static void paging_free(struct kvm_vcpu *vcpu)
513{ 1002{
514 nonpaging_free(vcpu); 1003 nonpaging_free(vcpu);
@@ -522,37 +1011,40 @@ static void paging_free(struct kvm_vcpu *vcpu)
522#include "paging_tmpl.h" 1011#include "paging_tmpl.h"
523#undef PTTYPE 1012#undef PTTYPE
524 1013
525static int paging64_init_context(struct kvm_vcpu *vcpu) 1014static int paging64_init_context_common(struct kvm_vcpu *vcpu, int level)
526{ 1015{
527 struct kvm_mmu *context = &vcpu->mmu; 1016 struct kvm_mmu *context = &vcpu->mmu;
528 1017
529 ASSERT(is_pae(vcpu)); 1018 ASSERT(is_pae(vcpu));
530 context->new_cr3 = paging_new_cr3; 1019 context->new_cr3 = paging_new_cr3;
531 context->page_fault = paging64_page_fault; 1020 context->page_fault = paging64_page_fault;
532 context->inval_page = paging_inval_page;
533 context->gva_to_gpa = paging64_gva_to_gpa; 1021 context->gva_to_gpa = paging64_gva_to_gpa;
534 context->free = paging_free; 1022 context->free = paging_free;
535 context->root_level = PT64_ROOT_LEVEL; 1023 context->root_level = level;
536 context->shadow_root_level = PT64_ROOT_LEVEL; 1024 context->shadow_root_level = level;
537 context->root_hpa = kvm_mmu_alloc_page(vcpu, NULL); 1025 mmu_alloc_roots(vcpu);
538 ASSERT(VALID_PAGE(context->root_hpa)); 1026 ASSERT(VALID_PAGE(context->root_hpa));
539 kvm_arch_ops->set_cr3(vcpu, context->root_hpa | 1027 kvm_arch_ops->set_cr3(vcpu, context->root_hpa |
540 (vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK))); 1028 (vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK)));
541 return 0; 1029 return 0;
542} 1030}
543 1031
1032static int paging64_init_context(struct kvm_vcpu *vcpu)
1033{
1034 return paging64_init_context_common(vcpu, PT64_ROOT_LEVEL);
1035}
1036
544static int paging32_init_context(struct kvm_vcpu *vcpu) 1037static int paging32_init_context(struct kvm_vcpu *vcpu)
545{ 1038{
546 struct kvm_mmu *context = &vcpu->mmu; 1039 struct kvm_mmu *context = &vcpu->mmu;
547 1040
548 context->new_cr3 = paging_new_cr3; 1041 context->new_cr3 = paging_new_cr3;
549 context->page_fault = paging32_page_fault; 1042 context->page_fault = paging32_page_fault;
550 context->inval_page = paging_inval_page;
551 context->gva_to_gpa = paging32_gva_to_gpa; 1043 context->gva_to_gpa = paging32_gva_to_gpa;
552 context->free = paging_free; 1044 context->free = paging_free;
553 context->root_level = PT32_ROOT_LEVEL; 1045 context->root_level = PT32_ROOT_LEVEL;
554 context->shadow_root_level = PT32E_ROOT_LEVEL; 1046 context->shadow_root_level = PT32E_ROOT_LEVEL;
555 context->root_hpa = kvm_mmu_alloc_page(vcpu, NULL); 1047 mmu_alloc_roots(vcpu);
556 ASSERT(VALID_PAGE(context->root_hpa)); 1048 ASSERT(VALID_PAGE(context->root_hpa));
557 kvm_arch_ops->set_cr3(vcpu, context->root_hpa | 1049 kvm_arch_ops->set_cr3(vcpu, context->root_hpa |
558 (vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK))); 1050 (vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK)));
@@ -561,14 +1053,7 @@ static int paging32_init_context(struct kvm_vcpu *vcpu)
561 1053
562static int paging32E_init_context(struct kvm_vcpu *vcpu) 1054static int paging32E_init_context(struct kvm_vcpu *vcpu)
563{ 1055{
564 int ret; 1056 return paging64_init_context_common(vcpu, PT32E_ROOT_LEVEL);
565
566 if ((ret = paging64_init_context(vcpu)))
567 return ret;
568
569 vcpu->mmu.root_level = PT32E_ROOT_LEVEL;
570 vcpu->mmu.shadow_root_level = PT32E_ROOT_LEVEL;
571 return 0;
572} 1057}
573 1058
574static int init_kvm_mmu(struct kvm_vcpu *vcpu) 1059static int init_kvm_mmu(struct kvm_vcpu *vcpu)
@@ -578,7 +1063,7 @@ static int init_kvm_mmu(struct kvm_vcpu *vcpu)
578 1063
579 if (!is_paging(vcpu)) 1064 if (!is_paging(vcpu))
580 return nonpaging_init_context(vcpu); 1065 return nonpaging_init_context(vcpu);
581 else if (kvm_arch_ops->is_long_mode(vcpu)) 1066 else if (is_long_mode(vcpu))
582 return paging64_init_context(vcpu); 1067 return paging64_init_context(vcpu);
583 else if (is_pae(vcpu)) 1068 else if (is_pae(vcpu))
584 return paging32E_init_context(vcpu); 1069 return paging32E_init_context(vcpu);
@@ -597,41 +1082,161 @@ static void destroy_kvm_mmu(struct kvm_vcpu *vcpu)
597 1082
598int kvm_mmu_reset_context(struct kvm_vcpu *vcpu) 1083int kvm_mmu_reset_context(struct kvm_vcpu *vcpu)
599{ 1084{
1085 int r;
1086
600 destroy_kvm_mmu(vcpu); 1087 destroy_kvm_mmu(vcpu);
601 return init_kvm_mmu(vcpu); 1088 r = init_kvm_mmu(vcpu);
1089 if (r < 0)
1090 goto out;
1091 r = mmu_topup_memory_caches(vcpu);
1092out:
1093 return r;
602} 1094}
603 1095
604static void free_mmu_pages(struct kvm_vcpu *vcpu) 1096void kvm_mmu_pre_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes)
605{ 1097{
606 while (!list_empty(&vcpu->free_pages)) { 1098 gfn_t gfn = gpa >> PAGE_SHIFT;
1099 struct kvm_mmu_page *page;
1100 struct kvm_mmu_page *child;
1101 struct hlist_node *node, *n;
1102 struct hlist_head *bucket;
1103 unsigned index;
1104 u64 *spte;
1105 u64 pte;
1106 unsigned offset = offset_in_page(gpa);
1107 unsigned pte_size;
1108 unsigned page_offset;
1109 unsigned misaligned;
1110 int level;
1111 int flooded = 0;
1112
1113 pgprintk("%s: gpa %llx bytes %d\n", __FUNCTION__, gpa, bytes);
1114 if (gfn == vcpu->last_pt_write_gfn) {
1115 ++vcpu->last_pt_write_count;
1116 if (vcpu->last_pt_write_count >= 3)
1117 flooded = 1;
1118 } else {
1119 vcpu->last_pt_write_gfn = gfn;
1120 vcpu->last_pt_write_count = 1;
1121 }
1122 index = kvm_page_table_hashfn(gfn) % KVM_NUM_MMU_PAGES;
1123 bucket = &vcpu->kvm->mmu_page_hash[index];
1124 hlist_for_each_entry_safe(page, node, n, bucket, hash_link) {
1125 if (page->gfn != gfn || page->role.metaphysical)
1126 continue;
1127 pte_size = page->role.glevels == PT32_ROOT_LEVEL ? 4 : 8;
1128 misaligned = (offset ^ (offset + bytes - 1)) & ~(pte_size - 1);
1129 if (misaligned || flooded) {
1130 /*
1131 * Misaligned accesses are too much trouble to fix
1132 * up; also, they usually indicate a page is not used
1133 * as a page table.
1134 *
1135 * If we're seeing too many writes to a page,
1136 * it may no longer be a page table, or we may be
1137 * forking, in which case it is better to unmap the
1138 * page.
1139 */
1140 pgprintk("misaligned: gpa %llx bytes %d role %x\n",
1141 gpa, bytes, page->role.word);
1142 kvm_mmu_zap_page(vcpu, page);
1143 continue;
1144 }
1145 page_offset = offset;
1146 level = page->role.level;
1147 if (page->role.glevels == PT32_ROOT_LEVEL) {
1148 page_offset <<= 1; /* 32->64 */
1149 page_offset &= ~PAGE_MASK;
1150 }
1151 spte = __va(page->page_hpa);
1152 spte += page_offset / sizeof(*spte);
1153 pte = *spte;
1154 if (is_present_pte(pte)) {
1155 if (level == PT_PAGE_TABLE_LEVEL)
1156 rmap_remove(vcpu, spte);
1157 else {
1158 child = page_header(pte & PT64_BASE_ADDR_MASK);
1159 mmu_page_remove_parent_pte(vcpu, child, spte);
1160 }
1161 }
1162 *spte = 0;
1163 }
1164}
1165
1166void kvm_mmu_post_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes)
1167{
1168}
1169
1170int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva)
1171{
1172 gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, gva);
1173
1174 return kvm_mmu_unprotect_page(vcpu, gpa >> PAGE_SHIFT);
1175}
1176
1177void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
1178{
1179 while (vcpu->kvm->n_free_mmu_pages < KVM_REFILL_PAGES) {
607 struct kvm_mmu_page *page; 1180 struct kvm_mmu_page *page;
608 1181
1182 page = container_of(vcpu->kvm->active_mmu_pages.prev,
1183 struct kvm_mmu_page, link);
1184 kvm_mmu_zap_page(vcpu, page);
1185 }
1186}
1187EXPORT_SYMBOL_GPL(kvm_mmu_free_some_pages);
1188
1189static void free_mmu_pages(struct kvm_vcpu *vcpu)
1190{
1191 struct kvm_mmu_page *page;
1192
1193 while (!list_empty(&vcpu->kvm->active_mmu_pages)) {
1194 page = container_of(vcpu->kvm->active_mmu_pages.next,
1195 struct kvm_mmu_page, link);
1196 kvm_mmu_zap_page(vcpu, page);
1197 }
1198 while (!list_empty(&vcpu->free_pages)) {
609 page = list_entry(vcpu->free_pages.next, 1199 page = list_entry(vcpu->free_pages.next,
610 struct kvm_mmu_page, link); 1200 struct kvm_mmu_page, link);
611 list_del(&page->link); 1201 list_del(&page->link);
612 __free_page(pfn_to_page(page->page_hpa >> PAGE_SHIFT)); 1202 __free_page(pfn_to_page(page->page_hpa >> PAGE_SHIFT));
613 page->page_hpa = INVALID_PAGE; 1203 page->page_hpa = INVALID_PAGE;
614 } 1204 }
1205 free_page((unsigned long)vcpu->mmu.pae_root);
615} 1206}
616 1207
617static int alloc_mmu_pages(struct kvm_vcpu *vcpu) 1208static int alloc_mmu_pages(struct kvm_vcpu *vcpu)
618{ 1209{
1210 struct page *page;
619 int i; 1211 int i;
620 1212
621 ASSERT(vcpu); 1213 ASSERT(vcpu);
622 1214
623 for (i = 0; i < KVM_NUM_MMU_PAGES; i++) { 1215 for (i = 0; i < KVM_NUM_MMU_PAGES; i++) {
624 struct page *page;
625 struct kvm_mmu_page *page_header = &vcpu->page_header_buf[i]; 1216 struct kvm_mmu_page *page_header = &vcpu->page_header_buf[i];
626 1217
627 INIT_LIST_HEAD(&page_header->link); 1218 INIT_LIST_HEAD(&page_header->link);
628 if ((page = alloc_page(GFP_KVM_MMU)) == NULL) 1219 if ((page = alloc_page(GFP_KERNEL)) == NULL)
629 goto error_1; 1220 goto error_1;
630 page->private = (unsigned long)page_header; 1221 page->private = (unsigned long)page_header;
631 page_header->page_hpa = (hpa_t)page_to_pfn(page) << PAGE_SHIFT; 1222 page_header->page_hpa = (hpa_t)page_to_pfn(page) << PAGE_SHIFT;
632 memset(__va(page_header->page_hpa), 0, PAGE_SIZE); 1223 memset(__va(page_header->page_hpa), 0, PAGE_SIZE);
633 list_add(&page_header->link, &vcpu->free_pages); 1224 list_add(&page_header->link, &vcpu->free_pages);
1225 ++vcpu->kvm->n_free_mmu_pages;
634 } 1226 }
1227
1228 /*
1229 * When emulating 32-bit mode, cr3 is only 32 bits even on x86_64.
1230 * Therefore we need to allocate shadow page tables in the first
1231 * 4GB of memory, which happens to fit the DMA32 zone.
1232 */
1233 page = alloc_page(GFP_KERNEL | __GFP_DMA32);
1234 if (!page)
1235 goto error_1;
1236 vcpu->mmu.pae_root = page_address(page);
1237 for (i = 0; i < 4; ++i)
1238 vcpu->mmu.pae_root[i] = INVALID_PAGE;
1239
635 return 0; 1240 return 0;
636 1241
637error_1: 1242error_1:
@@ -639,22 +1244,22 @@ error_1:
639 return -ENOMEM; 1244 return -ENOMEM;
640} 1245}
641 1246
642int kvm_mmu_init(struct kvm_vcpu *vcpu) 1247int kvm_mmu_create(struct kvm_vcpu *vcpu)
643{ 1248{
644 int r;
645
646 ASSERT(vcpu); 1249 ASSERT(vcpu);
647 ASSERT(!VALID_PAGE(vcpu->mmu.root_hpa)); 1250 ASSERT(!VALID_PAGE(vcpu->mmu.root_hpa));
648 ASSERT(list_empty(&vcpu->free_pages)); 1251 ASSERT(list_empty(&vcpu->free_pages));
649 1252
650 if ((r = alloc_mmu_pages(vcpu))) 1253 return alloc_mmu_pages(vcpu);
651 return r; 1254}
652 1255
653 if ((r = init_kvm_mmu(vcpu))) { 1256int kvm_mmu_setup(struct kvm_vcpu *vcpu)
654 free_mmu_pages(vcpu); 1257{
655 return r; 1258 ASSERT(vcpu);
656 } 1259 ASSERT(!VALID_PAGE(vcpu->mmu.root_hpa));
657 return 0; 1260 ASSERT(!list_empty(&vcpu->free_pages));
1261
1262 return init_kvm_mmu(vcpu);
658} 1263}
659 1264
660void kvm_mmu_destroy(struct kvm_vcpu *vcpu) 1265void kvm_mmu_destroy(struct kvm_vcpu *vcpu)
@@ -663,10 +1268,12 @@ void kvm_mmu_destroy(struct kvm_vcpu *vcpu)
663 1268
664 destroy_kvm_mmu(vcpu); 1269 destroy_kvm_mmu(vcpu);
665 free_mmu_pages(vcpu); 1270 free_mmu_pages(vcpu);
1271 mmu_free_memory_caches(vcpu);
666} 1272}
667 1273
668void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot) 1274void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot)
669{ 1275{
1276 struct kvm *kvm = vcpu->kvm;
670 struct kvm_mmu_page *page; 1277 struct kvm_mmu_page *page;
671 1278
672 list_for_each_entry(page, &kvm->active_mmu_pages, link) { 1279 list_for_each_entry(page, &kvm->active_mmu_pages, link) {
@@ -679,8 +1286,169 @@ void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot)
679 pt = __va(page->page_hpa); 1286 pt = __va(page->page_hpa);
680 for (i = 0; i < PT64_ENT_PER_PAGE; ++i) 1287 for (i = 0; i < PT64_ENT_PER_PAGE; ++i)
681 /* avoid RMW */ 1288 /* avoid RMW */
682 if (pt[i] & PT_WRITABLE_MASK) 1289 if (pt[i] & PT_WRITABLE_MASK) {
1290 rmap_remove(vcpu, &pt[i]);
683 pt[i] &= ~PT_WRITABLE_MASK; 1291 pt[i] &= ~PT_WRITABLE_MASK;
1292 }
1293 }
1294}
1295
1296#ifdef AUDIT
1297
1298static const char *audit_msg;
1299
1300static gva_t canonicalize(gva_t gva)
1301{
1302#ifdef CONFIG_X86_64
1303 gva = (long long)(gva << 16) >> 16;
1304#endif
1305 return gva;
1306}
1307
1308static void audit_mappings_page(struct kvm_vcpu *vcpu, u64 page_pte,
1309 gva_t va, int level)
1310{
1311 u64 *pt = __va(page_pte & PT64_BASE_ADDR_MASK);
1312 int i;
1313 gva_t va_delta = 1ul << (PAGE_SHIFT + 9 * (level - 1));
1314
1315 for (i = 0; i < PT64_ENT_PER_PAGE; ++i, va += va_delta) {
1316 u64 ent = pt[i];
1317
1318 if (!ent & PT_PRESENT_MASK)
1319 continue;
684 1320
1321 va = canonicalize(va);
1322 if (level > 1)
1323 audit_mappings_page(vcpu, ent, va, level - 1);
1324 else {
1325 gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, va);
1326 hpa_t hpa = gpa_to_hpa(vcpu, gpa);
1327
1328 if ((ent & PT_PRESENT_MASK)
1329 && (ent & PT64_BASE_ADDR_MASK) != hpa)
1330 printk(KERN_ERR "audit error: (%s) levels %d"
1331 " gva %lx gpa %llx hpa %llx ent %llx\n",
1332 audit_msg, vcpu->mmu.root_level,
1333 va, gpa, hpa, ent);
1334 }
1335 }
1336}
1337
1338static void audit_mappings(struct kvm_vcpu *vcpu)
1339{
1340 int i;
1341
1342 if (vcpu->mmu.root_level == 4)
1343 audit_mappings_page(vcpu, vcpu->mmu.root_hpa, 0, 4);
1344 else
1345 for (i = 0; i < 4; ++i)
1346 if (vcpu->mmu.pae_root[i] & PT_PRESENT_MASK)
1347 audit_mappings_page(vcpu,
1348 vcpu->mmu.pae_root[i],
1349 i << 30,
1350 2);
1351}
1352
1353static int count_rmaps(struct kvm_vcpu *vcpu)
1354{
1355 int nmaps = 0;
1356 int i, j, k;
1357
1358 for (i = 0; i < KVM_MEMORY_SLOTS; ++i) {
1359 struct kvm_memory_slot *m = &vcpu->kvm->memslots[i];
1360 struct kvm_rmap_desc *d;
1361
1362 for (j = 0; j < m->npages; ++j) {
1363 struct page *page = m->phys_mem[j];
1364
1365 if (!page->private)
1366 continue;
1367 if (!(page->private & 1)) {
1368 ++nmaps;
1369 continue;
1370 }
1371 d = (struct kvm_rmap_desc *)(page->private & ~1ul);
1372 while (d) {
1373 for (k = 0; k < RMAP_EXT; ++k)
1374 if (d->shadow_ptes[k])
1375 ++nmaps;
1376 else
1377 break;
1378 d = d->more;
1379 }
1380 }
1381 }
1382 return nmaps;
1383}
1384
1385static int count_writable_mappings(struct kvm_vcpu *vcpu)
1386{
1387 int nmaps = 0;
1388 struct kvm_mmu_page *page;
1389 int i;
1390
1391 list_for_each_entry(page, &vcpu->kvm->active_mmu_pages, link) {
1392 u64 *pt = __va(page->page_hpa);
1393
1394 if (page->role.level != PT_PAGE_TABLE_LEVEL)
1395 continue;
1396
1397 for (i = 0; i < PT64_ENT_PER_PAGE; ++i) {
1398 u64 ent = pt[i];
1399
1400 if (!(ent & PT_PRESENT_MASK))
1401 continue;
1402 if (!(ent & PT_WRITABLE_MASK))
1403 continue;
1404 ++nmaps;
1405 }
685 } 1406 }
1407 return nmaps;
686} 1408}
1409
1410static void audit_rmap(struct kvm_vcpu *vcpu)
1411{
1412 int n_rmap = count_rmaps(vcpu);
1413 int n_actual = count_writable_mappings(vcpu);
1414
1415 if (n_rmap != n_actual)
1416 printk(KERN_ERR "%s: (%s) rmap %d actual %d\n",
1417 __FUNCTION__, audit_msg, n_rmap, n_actual);
1418}
1419
1420static void audit_write_protection(struct kvm_vcpu *vcpu)
1421{
1422 struct kvm_mmu_page *page;
1423
1424 list_for_each_entry(page, &vcpu->kvm->active_mmu_pages, link) {
1425 hfn_t hfn;
1426 struct page *pg;
1427
1428 if (page->role.metaphysical)
1429 continue;
1430
1431 hfn = gpa_to_hpa(vcpu, (gpa_t)page->gfn << PAGE_SHIFT)
1432 >> PAGE_SHIFT;
1433 pg = pfn_to_page(hfn);
1434 if (pg->private)
1435 printk(KERN_ERR "%s: (%s) shadow page has writable"
1436 " mappings: gfn %lx role %x\n",
1437 __FUNCTION__, audit_msg, page->gfn,
1438 page->role.word);
1439 }
1440}
1441
1442static void kvm_mmu_audit(struct kvm_vcpu *vcpu, const char *msg)
1443{
1444 int olddbg = dbg;
1445
1446 dbg = 0;
1447 audit_msg = msg;
1448 audit_rmap(vcpu);
1449 audit_write_protection(vcpu);
1450 audit_mappings(vcpu);
1451 dbg = olddbg;
1452}
1453
1454#endif
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index a9771b4c5b..149fa45fd9 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -32,6 +32,11 @@
32 #define SHADOW_PT_INDEX(addr, level) PT64_INDEX(addr, level) 32 #define SHADOW_PT_INDEX(addr, level) PT64_INDEX(addr, level)
33 #define PT_LEVEL_MASK(level) PT64_LEVEL_MASK(level) 33 #define PT_LEVEL_MASK(level) PT64_LEVEL_MASK(level)
34 #define PT_PTE_COPY_MASK PT64_PTE_COPY_MASK 34 #define PT_PTE_COPY_MASK PT64_PTE_COPY_MASK
35 #ifdef CONFIG_X86_64
36 #define PT_MAX_FULL_LEVELS 4
37 #else
38 #define PT_MAX_FULL_LEVELS 2
39 #endif
35#elif PTTYPE == 32 40#elif PTTYPE == 32
36 #define pt_element_t u32 41 #define pt_element_t u32
37 #define guest_walker guest_walker32 42 #define guest_walker guest_walker32
@@ -42,6 +47,7 @@
42 #define SHADOW_PT_INDEX(addr, level) PT64_INDEX(addr, level) 47 #define SHADOW_PT_INDEX(addr, level) PT64_INDEX(addr, level)
43 #define PT_LEVEL_MASK(level) PT32_LEVEL_MASK(level) 48 #define PT_LEVEL_MASK(level) PT32_LEVEL_MASK(level)
44 #define PT_PTE_COPY_MASK PT32_PTE_COPY_MASK 49 #define PT_PTE_COPY_MASK PT32_PTE_COPY_MASK
50 #define PT_MAX_FULL_LEVELS 2
45#else 51#else
46 #error Invalid PTTYPE value 52 #error Invalid PTTYPE value
47#endif 53#endif
@@ -52,93 +58,157 @@
52 */ 58 */
53struct guest_walker { 59struct guest_walker {
54 int level; 60 int level;
61 gfn_t table_gfn[PT_MAX_FULL_LEVELS];
55 pt_element_t *table; 62 pt_element_t *table;
63 pt_element_t *ptep;
56 pt_element_t inherited_ar; 64 pt_element_t inherited_ar;
65 gfn_t gfn;
66 u32 error_code;
57}; 67};
58 68
59static void FNAME(init_walker)(struct guest_walker *walker, 69/*
60 struct kvm_vcpu *vcpu) 70 * Fetch a guest pte for a guest virtual address
71 */
72static int FNAME(walk_addr)(struct guest_walker *walker,
73 struct kvm_vcpu *vcpu, gva_t addr,
74 int write_fault, int user_fault, int fetch_fault)
61{ 75{
62 hpa_t hpa; 76 hpa_t hpa;
63 struct kvm_memory_slot *slot; 77 struct kvm_memory_slot *slot;
78 pt_element_t *ptep;
79 pt_element_t root;
80 gfn_t table_gfn;
64 81
82 pgprintk("%s: addr %lx\n", __FUNCTION__, addr);
65 walker->level = vcpu->mmu.root_level; 83 walker->level = vcpu->mmu.root_level;
66 slot = gfn_to_memslot(vcpu->kvm, 84 walker->table = NULL;
67 (vcpu->cr3 & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT); 85 root = vcpu->cr3;
68 hpa = safe_gpa_to_hpa(vcpu, vcpu->cr3 & PT64_BASE_ADDR_MASK); 86#if PTTYPE == 64
87 if (!is_long_mode(vcpu)) {
88 walker->ptep = &vcpu->pdptrs[(addr >> 30) & 3];
89 root = *walker->ptep;
90 if (!(root & PT_PRESENT_MASK))
91 goto not_present;
92 --walker->level;
93 }
94#endif
95 table_gfn = (root & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
96 walker->table_gfn[walker->level - 1] = table_gfn;
97 pgprintk("%s: table_gfn[%d] %lx\n", __FUNCTION__,
98 walker->level - 1, table_gfn);
99 slot = gfn_to_memslot(vcpu->kvm, table_gfn);
100 hpa = safe_gpa_to_hpa(vcpu, root & PT64_BASE_ADDR_MASK);
69 walker->table = kmap_atomic(pfn_to_page(hpa >> PAGE_SHIFT), KM_USER0); 101 walker->table = kmap_atomic(pfn_to_page(hpa >> PAGE_SHIFT), KM_USER0);
70 102
71 ASSERT((!kvm_arch_ops->is_long_mode(vcpu) && is_pae(vcpu)) || 103 ASSERT((!is_long_mode(vcpu) && is_pae(vcpu)) ||
72 (vcpu->cr3 & ~(PAGE_MASK | CR3_FLAGS_MASK)) == 0); 104 (vcpu->cr3 & ~(PAGE_MASK | CR3_FLAGS_MASK)) == 0);
73 105
74 walker->table = (pt_element_t *)( (unsigned long)walker->table |
75 (unsigned long)(vcpu->cr3 & ~(PAGE_MASK | CR3_FLAGS_MASK)) );
76 walker->inherited_ar = PT_USER_MASK | PT_WRITABLE_MASK; 106 walker->inherited_ar = PT_USER_MASK | PT_WRITABLE_MASK;
107
108 for (;;) {
109 int index = PT_INDEX(addr, walker->level);
110 hpa_t paddr;
111
112 ptep = &walker->table[index];
113 ASSERT(((unsigned long)walker->table & PAGE_MASK) ==
114 ((unsigned long)ptep & PAGE_MASK));
115
116 if (!is_present_pte(*ptep))
117 goto not_present;
118
119 if (write_fault && !is_writeble_pte(*ptep))
120 if (user_fault || is_write_protection(vcpu))
121 goto access_error;
122
123 if (user_fault && !(*ptep & PT_USER_MASK))
124 goto access_error;
125
126#if PTTYPE == 64
127 if (fetch_fault && is_nx(vcpu) && (*ptep & PT64_NX_MASK))
128 goto access_error;
129#endif
130
131 if (!(*ptep & PT_ACCESSED_MASK))
132 *ptep |= PT_ACCESSED_MASK; /* avoid rmw */
133
134 if (walker->level == PT_PAGE_TABLE_LEVEL) {
135 walker->gfn = (*ptep & PT_BASE_ADDR_MASK)
136 >> PAGE_SHIFT;
137 break;
138 }
139
140 if (walker->level == PT_DIRECTORY_LEVEL
141 && (*ptep & PT_PAGE_SIZE_MASK)
142 && (PTTYPE == 64 || is_pse(vcpu))) {
143 walker->gfn = (*ptep & PT_DIR_BASE_ADDR_MASK)
144 >> PAGE_SHIFT;
145 walker->gfn += PT_INDEX(addr, PT_PAGE_TABLE_LEVEL);
146 break;
147 }
148
149 if (walker->level != 3 || is_long_mode(vcpu))
150 walker->inherited_ar &= walker->table[index];
151 table_gfn = (*ptep & PT_BASE_ADDR_MASK) >> PAGE_SHIFT;
152 paddr = safe_gpa_to_hpa(vcpu, *ptep & PT_BASE_ADDR_MASK);
153 kunmap_atomic(walker->table, KM_USER0);
154 walker->table = kmap_atomic(pfn_to_page(paddr >> PAGE_SHIFT),
155 KM_USER0);
156 --walker->level;
157 walker->table_gfn[walker->level - 1 ] = table_gfn;
158 pgprintk("%s: table_gfn[%d] %lx\n", __FUNCTION__,
159 walker->level - 1, table_gfn);
160 }
161 walker->ptep = ptep;
162 pgprintk("%s: pte %llx\n", __FUNCTION__, (u64)*ptep);
163 return 1;
164
165not_present:
166 walker->error_code = 0;
167 goto err;
168
169access_error:
170 walker->error_code = PFERR_PRESENT_MASK;
171
172err:
173 if (write_fault)
174 walker->error_code |= PFERR_WRITE_MASK;
175 if (user_fault)
176 walker->error_code |= PFERR_USER_MASK;
177 if (fetch_fault)
178 walker->error_code |= PFERR_FETCH_MASK;
179 return 0;
77} 180}
78 181
79static void FNAME(release_walker)(struct guest_walker *walker) 182static void FNAME(release_walker)(struct guest_walker *walker)
80{ 183{
81 kunmap_atomic(walker->table, KM_USER0); 184 if (walker->table)
185 kunmap_atomic(walker->table, KM_USER0);
82} 186}
83 187
84static void FNAME(set_pte)(struct kvm_vcpu *vcpu, u64 guest_pte, 188static void FNAME(set_pte)(struct kvm_vcpu *vcpu, u64 guest_pte,
85 u64 *shadow_pte, u64 access_bits) 189 u64 *shadow_pte, u64 access_bits, gfn_t gfn)
86{ 190{
87 ASSERT(*shadow_pte == 0); 191 ASSERT(*shadow_pte == 0);
88 access_bits &= guest_pte; 192 access_bits &= guest_pte;
89 *shadow_pte = (guest_pte & PT_PTE_COPY_MASK); 193 *shadow_pte = (guest_pte & PT_PTE_COPY_MASK);
90 set_pte_common(vcpu, shadow_pte, guest_pte & PT_BASE_ADDR_MASK, 194 set_pte_common(vcpu, shadow_pte, guest_pte & PT_BASE_ADDR_MASK,
91 guest_pte & PT_DIRTY_MASK, access_bits); 195 guest_pte & PT_DIRTY_MASK, access_bits, gfn);
92} 196}
93 197
94static void FNAME(set_pde)(struct kvm_vcpu *vcpu, u64 guest_pde, 198static void FNAME(set_pde)(struct kvm_vcpu *vcpu, u64 guest_pde,
95 u64 *shadow_pte, u64 access_bits, 199 u64 *shadow_pte, u64 access_bits, gfn_t gfn)
96 int index)
97{ 200{
98 gpa_t gaddr; 201 gpa_t gaddr;
99 202
100 ASSERT(*shadow_pte == 0); 203 ASSERT(*shadow_pte == 0);
101 access_bits &= guest_pde; 204 access_bits &= guest_pde;
102 gaddr = (guest_pde & PT_DIR_BASE_ADDR_MASK) + PAGE_SIZE * index; 205 gaddr = (gpa_t)gfn << PAGE_SHIFT;
103 if (PTTYPE == 32 && is_cpuid_PSE36()) 206 if (PTTYPE == 32 && is_cpuid_PSE36())
104 gaddr |= (guest_pde & PT32_DIR_PSE36_MASK) << 207 gaddr |= (guest_pde & PT32_DIR_PSE36_MASK) <<
105 (32 - PT32_DIR_PSE36_SHIFT); 208 (32 - PT32_DIR_PSE36_SHIFT);
106 *shadow_pte = guest_pde & PT_PTE_COPY_MASK; 209 *shadow_pte = guest_pde & PT_PTE_COPY_MASK;
107 set_pte_common(vcpu, shadow_pte, gaddr, 210 set_pte_common(vcpu, shadow_pte, gaddr,
108 guest_pde & PT_DIRTY_MASK, access_bits); 211 guest_pde & PT_DIRTY_MASK, access_bits, gfn);
109}
110
111/*
112 * Fetch a guest pte from a specific level in the paging hierarchy.
113 */
114static pt_element_t *FNAME(fetch_guest)(struct kvm_vcpu *vcpu,
115 struct guest_walker *walker,
116 int level,
117 gva_t addr)
118{
119
120 ASSERT(level > 0 && level <= walker->level);
121
122 for (;;) {
123 int index = PT_INDEX(addr, walker->level);
124 hpa_t paddr;
125
126 ASSERT(((unsigned long)walker->table & PAGE_MASK) ==
127 ((unsigned long)&walker->table[index] & PAGE_MASK));
128 if (level == walker->level ||
129 !is_present_pte(walker->table[index]) ||
130 (walker->level == PT_DIRECTORY_LEVEL &&
131 (walker->table[index] & PT_PAGE_SIZE_MASK) &&
132 (PTTYPE == 64 || is_pse(vcpu))))
133 return &walker->table[index];
134 if (walker->level != 3 || kvm_arch_ops->is_long_mode(vcpu))
135 walker->inherited_ar &= walker->table[index];
136 paddr = safe_gpa_to_hpa(vcpu, walker->table[index] & PT_BASE_ADDR_MASK);
137 kunmap_atomic(walker->table, KM_USER0);
138 walker->table = kmap_atomic(pfn_to_page(paddr >> PAGE_SHIFT),
139 KM_USER0);
140 --walker->level;
141 }
142} 212}
143 213
144/* 214/*
@@ -150,15 +220,26 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
150 hpa_t shadow_addr; 220 hpa_t shadow_addr;
151 int level; 221 int level;
152 u64 *prev_shadow_ent = NULL; 222 u64 *prev_shadow_ent = NULL;
223 pt_element_t *guest_ent = walker->ptep;
224
225 if (!is_present_pte(*guest_ent))
226 return NULL;
153 227
154 shadow_addr = vcpu->mmu.root_hpa; 228 shadow_addr = vcpu->mmu.root_hpa;
155 level = vcpu->mmu.shadow_root_level; 229 level = vcpu->mmu.shadow_root_level;
230 if (level == PT32E_ROOT_LEVEL) {
231 shadow_addr = vcpu->mmu.pae_root[(addr >> 30) & 3];
232 shadow_addr &= PT64_BASE_ADDR_MASK;
233 --level;
234 }
156 235
157 for (; ; level--) { 236 for (; ; level--) {
158 u32 index = SHADOW_PT_INDEX(addr, level); 237 u32 index = SHADOW_PT_INDEX(addr, level);
159 u64 *shadow_ent = ((u64 *)__va(shadow_addr)) + index; 238 u64 *shadow_ent = ((u64 *)__va(shadow_addr)) + index;
160 pt_element_t *guest_ent; 239 struct kvm_mmu_page *shadow_page;
161 u64 shadow_pte; 240 u64 shadow_pte;
241 int metaphysical;
242 gfn_t table_gfn;
162 243
163 if (is_present_pte(*shadow_ent) || is_io_pte(*shadow_ent)) { 244 if (is_present_pte(*shadow_ent) || is_io_pte(*shadow_ent)) {
164 if (level == PT_PAGE_TABLE_LEVEL) 245 if (level == PT_PAGE_TABLE_LEVEL)
@@ -168,21 +249,6 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
168 continue; 249 continue;
169 } 250 }
170 251
171 if (PTTYPE == 32 && level > PT32_ROOT_LEVEL) {
172 ASSERT(level == PT32E_ROOT_LEVEL);
173 guest_ent = FNAME(fetch_guest)(vcpu, walker,
174 PT32_ROOT_LEVEL, addr);
175 } else
176 guest_ent = FNAME(fetch_guest)(vcpu, walker,
177 level, addr);
178
179 if (!is_present_pte(*guest_ent))
180 return NULL;
181
182 /* Don't set accessed bit on PAE PDPTRs */
183 if (vcpu->mmu.root_level != 3 || walker->level != 3)
184 *guest_ent |= PT_ACCESSED_MASK;
185
186 if (level == PT_PAGE_TABLE_LEVEL) { 252 if (level == PT_PAGE_TABLE_LEVEL) {
187 253
188 if (walker->level == PT_DIRECTORY_LEVEL) { 254 if (walker->level == PT_DIRECTORY_LEVEL) {
@@ -190,21 +256,30 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
190 *prev_shadow_ent |= PT_SHADOW_PS_MARK; 256 *prev_shadow_ent |= PT_SHADOW_PS_MARK;
191 FNAME(set_pde)(vcpu, *guest_ent, shadow_ent, 257 FNAME(set_pde)(vcpu, *guest_ent, shadow_ent,
192 walker->inherited_ar, 258 walker->inherited_ar,
193 PT_INDEX(addr, PT_PAGE_TABLE_LEVEL)); 259 walker->gfn);
194 } else { 260 } else {
195 ASSERT(walker->level == PT_PAGE_TABLE_LEVEL); 261 ASSERT(walker->level == PT_PAGE_TABLE_LEVEL);
196 FNAME(set_pte)(vcpu, *guest_ent, shadow_ent, walker->inherited_ar); 262 FNAME(set_pte)(vcpu, *guest_ent, shadow_ent,
263 walker->inherited_ar,
264 walker->gfn);
197 } 265 }
198 return shadow_ent; 266 return shadow_ent;
199 } 267 }
200 268
201 shadow_addr = kvm_mmu_alloc_page(vcpu, shadow_ent); 269 if (level - 1 == PT_PAGE_TABLE_LEVEL
202 if (!VALID_PAGE(shadow_addr)) 270 && walker->level == PT_DIRECTORY_LEVEL) {
203 return ERR_PTR(-ENOMEM); 271 metaphysical = 1;
204 shadow_pte = shadow_addr | PT_PRESENT_MASK; 272 table_gfn = (*guest_ent & PT_BASE_ADDR_MASK)
205 if (vcpu->mmu.root_level > 3 || level != 3) 273 >> PAGE_SHIFT;
206 shadow_pte |= PT_ACCESSED_MASK 274 } else {
207 | PT_WRITABLE_MASK | PT_USER_MASK; 275 metaphysical = 0;
276 table_gfn = walker->table_gfn[level - 2];
277 }
278 shadow_page = kvm_mmu_get_page(vcpu, table_gfn, addr, level-1,
279 metaphysical, shadow_ent);
280 shadow_addr = shadow_page->page_hpa;
281 shadow_pte = shadow_addr | PT_PRESENT_MASK | PT_ACCESSED_MASK
282 | PT_WRITABLE_MASK | PT_USER_MASK;
208 *shadow_ent = shadow_pte; 283 *shadow_ent = shadow_pte;
209 prev_shadow_ent = shadow_ent; 284 prev_shadow_ent = shadow_ent;
210 } 285 }
@@ -221,14 +296,16 @@ static int FNAME(fix_write_pf)(struct kvm_vcpu *vcpu,
221 u64 *shadow_ent, 296 u64 *shadow_ent,
222 struct guest_walker *walker, 297 struct guest_walker *walker,
223 gva_t addr, 298 gva_t addr,
224 int user) 299 int user,
300 int *write_pt)
225{ 301{
226 pt_element_t *guest_ent; 302 pt_element_t *guest_ent;
227 int writable_shadow; 303 int writable_shadow;
228 gfn_t gfn; 304 gfn_t gfn;
305 struct kvm_mmu_page *page;
229 306
230 if (is_writeble_pte(*shadow_ent)) 307 if (is_writeble_pte(*shadow_ent))
231 return 0; 308 return !user || (*shadow_ent & PT_USER_MASK);
232 309
233 writable_shadow = *shadow_ent & PT_SHADOW_WRITABLE_MASK; 310 writable_shadow = *shadow_ent & PT_SHADOW_WRITABLE_MASK;
234 if (user) { 311 if (user) {
@@ -250,17 +327,35 @@ static int FNAME(fix_write_pf)(struct kvm_vcpu *vcpu,
250 *shadow_ent &= ~PT_USER_MASK; 327 *shadow_ent &= ~PT_USER_MASK;
251 } 328 }
252 329
253 guest_ent = FNAME(fetch_guest)(vcpu, walker, PT_PAGE_TABLE_LEVEL, addr); 330 guest_ent = walker->ptep;
254 331
255 if (!is_present_pte(*guest_ent)) { 332 if (!is_present_pte(*guest_ent)) {
256 *shadow_ent = 0; 333 *shadow_ent = 0;
257 return 0; 334 return 0;
258 } 335 }
259 336
260 gfn = (*guest_ent & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT; 337 gfn = walker->gfn;
338
339 if (user) {
340 /*
341 * Usermode page faults won't be for page table updates.
342 */
343 while ((page = kvm_mmu_lookup_page(vcpu, gfn)) != NULL) {
344 pgprintk("%s: zap %lx %x\n",
345 __FUNCTION__, gfn, page->role.word);
346 kvm_mmu_zap_page(vcpu, page);
347 }
348 } else if (kvm_mmu_lookup_page(vcpu, gfn)) {
349 pgprintk("%s: found shadow page for %lx, marking ro\n",
350 __FUNCTION__, gfn);
351 *guest_ent |= PT_DIRTY_MASK;
352 *write_pt = 1;
353 return 0;
354 }
261 mark_page_dirty(vcpu->kvm, gfn); 355 mark_page_dirty(vcpu->kvm, gfn);
262 *shadow_ent |= PT_WRITABLE_MASK; 356 *shadow_ent |= PT_WRITABLE_MASK;
263 *guest_ent |= PT_DIRTY_MASK; 357 *guest_ent |= PT_DIRTY_MASK;
358 rmap_add(vcpu, shadow_ent);
264 359
265 return 1; 360 return 1;
266} 361}
@@ -276,75 +371,73 @@ static int FNAME(fix_write_pf)(struct kvm_vcpu *vcpu,
276 * - normal guest page fault due to the guest pte marked not present, not 371 * - normal guest page fault due to the guest pte marked not present, not
277 * writable, or not executable 372 * writable, or not executable
278 * 373 *
279 * Returns: 1 if we need to emulate the instruction, 0 otherwise 374 * Returns: 1 if we need to emulate the instruction, 0 otherwise, or
375 * a negative value on error.
280 */ 376 */
281static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, 377static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
282 u32 error_code) 378 u32 error_code)
283{ 379{
284 int write_fault = error_code & PFERR_WRITE_MASK; 380 int write_fault = error_code & PFERR_WRITE_MASK;
285 int pte_present = error_code & PFERR_PRESENT_MASK;
286 int user_fault = error_code & PFERR_USER_MASK; 381 int user_fault = error_code & PFERR_USER_MASK;
382 int fetch_fault = error_code & PFERR_FETCH_MASK;
287 struct guest_walker walker; 383 struct guest_walker walker;
288 u64 *shadow_pte; 384 u64 *shadow_pte;
289 int fixed; 385 int fixed;
386 int write_pt = 0;
387 int r;
388
389 pgprintk("%s: addr %lx err %x\n", __FUNCTION__, addr, error_code);
390 kvm_mmu_audit(vcpu, "pre page fault");
391
392 r = mmu_topup_memory_caches(vcpu);
393 if (r)
394 return r;
290 395
291 /* 396 /*
292 * Look up the shadow pte for the faulting address. 397 * Look up the shadow pte for the faulting address.
293 */ 398 */
294 for (;;) { 399 r = FNAME(walk_addr)(&walker, vcpu, addr, write_fault, user_fault,
295 FNAME(init_walker)(&walker, vcpu); 400 fetch_fault);
296 shadow_pte = FNAME(fetch)(vcpu, addr, &walker);
297 if (IS_ERR(shadow_pte)) { /* must be -ENOMEM */
298 nonpaging_flush(vcpu);
299 FNAME(release_walker)(&walker);
300 continue;
301 }
302 break;
303 }
304 401
305 /* 402 /*
306 * The page is not mapped by the guest. Let the guest handle it. 403 * The page is not mapped by the guest. Let the guest handle it.
307 */ 404 */
308 if (!shadow_pte) { 405 if (!r) {
309 inject_page_fault(vcpu, addr, error_code); 406 pgprintk("%s: guest page fault\n", __FUNCTION__);
407 inject_page_fault(vcpu, addr, walker.error_code);
310 FNAME(release_walker)(&walker); 408 FNAME(release_walker)(&walker);
311 return 0; 409 return 0;
312 } 410 }
313 411
412 shadow_pte = FNAME(fetch)(vcpu, addr, &walker);
413 pgprintk("%s: shadow pte %p %llx\n", __FUNCTION__,
414 shadow_pte, *shadow_pte);
415
314 /* 416 /*
315 * Update the shadow pte. 417 * Update the shadow pte.
316 */ 418 */
317 if (write_fault) 419 if (write_fault)
318 fixed = FNAME(fix_write_pf)(vcpu, shadow_pte, &walker, addr, 420 fixed = FNAME(fix_write_pf)(vcpu, shadow_pte, &walker, addr,
319 user_fault); 421 user_fault, &write_pt);
320 else 422 else
321 fixed = fix_read_pf(shadow_pte); 423 fixed = fix_read_pf(shadow_pte);
322 424
425 pgprintk("%s: updated shadow pte %p %llx\n", __FUNCTION__,
426 shadow_pte, *shadow_pte);
427
323 FNAME(release_walker)(&walker); 428 FNAME(release_walker)(&walker);
324 429
325 /* 430 /*
326 * mmio: emulate if accessible, otherwise its a guest fault. 431 * mmio: emulate if accessible, otherwise its a guest fault.
327 */ 432 */
328 if (is_io_pte(*shadow_pte)) { 433 if (is_io_pte(*shadow_pte)) {
329 if (may_access(*shadow_pte, write_fault, user_fault)) 434 return 1;
330 return 1;
331 pgprintk("%s: io work, no access\n", __FUNCTION__);
332 inject_page_fault(vcpu, addr,
333 error_code | PFERR_PRESENT_MASK);
334 return 0;
335 }
336
337 /*
338 * pte not present, guest page fault.
339 */
340 if (pte_present && !fixed) {
341 inject_page_fault(vcpu, addr, error_code);
342 return 0;
343 } 435 }
344 436
345 ++kvm_stat.pf_fixed; 437 ++kvm_stat.pf_fixed;
438 kvm_mmu_audit(vcpu, "post page fault (fixed)");
346 439
347 return 0; 440 return write_pt;
348} 441}
349 442
350static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr) 443static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
@@ -353,9 +446,8 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
353 pt_element_t guest_pte; 446 pt_element_t guest_pte;
354 gpa_t gpa; 447 gpa_t gpa;
355 448
356 FNAME(init_walker)(&walker, vcpu); 449 FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0, 0);
357 guest_pte = *FNAME(fetch_guest)(vcpu, &walker, PT_PAGE_TABLE_LEVEL, 450 guest_pte = *walker.ptep;
358 vaddr);
359 FNAME(release_walker)(&walker); 451 FNAME(release_walker)(&walker);
360 452
361 if (!is_present_pte(guest_pte)) 453 if (!is_present_pte(guest_pte))
@@ -389,3 +481,4 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
389#undef PT_PTE_COPY_MASK 481#undef PT_PTE_COPY_MASK
390#undef PT_NON_PTE_COPY_MASK 482#undef PT_NON_PTE_COPY_MASK
391#undef PT_DIR_BASE_ADDR_MASK 483#undef PT_DIR_BASE_ADDR_MASK
484#undef PT_MAX_FULL_LEVELS
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 0e6bc8c649..c79df79307 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -17,6 +17,7 @@
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
19#include <linux/highmem.h> 19#include <linux/highmem.h>
20#include <linux/profile.h>
20#include <asm/desc.h> 21#include <asm/desc.h>
21 22
22#include "kvm_svm.h" 23#include "kvm_svm.h"
@@ -166,11 +167,6 @@ static inline void write_dr7(unsigned long val)
166 asm volatile ("mov %0, %%dr7" :: "r" (val)); 167 asm volatile ("mov %0, %%dr7" :: "r" (val));
167} 168}
168 169
169static inline int svm_is_long_mode(struct kvm_vcpu *vcpu)
170{
171 return vcpu->svm->vmcb->save.efer & KVM_EFER_LMA;
172}
173
174static inline void force_new_asid(struct kvm_vcpu *vcpu) 170static inline void force_new_asid(struct kvm_vcpu *vcpu)
175{ 171{
176 vcpu->svm->asid_generation--; 172 vcpu->svm->asid_generation--;
@@ -240,13 +236,15 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
240 236
241 vcpu->rip = vcpu->svm->vmcb->save.rip = vcpu->svm->next_rip; 237 vcpu->rip = vcpu->svm->vmcb->save.rip = vcpu->svm->next_rip;
242 vcpu->svm->vmcb->control.int_state &= ~SVM_INTERRUPT_SHADOW_MASK; 238 vcpu->svm->vmcb->control.int_state &= ~SVM_INTERRUPT_SHADOW_MASK;
239
240 vcpu->interrupt_window_open = 1;
243} 241}
244 242
245static int has_svm(void) 243static int has_svm(void)
246{ 244{
247 uint32_t eax, ebx, ecx, edx; 245 uint32_t eax, ebx, ecx, edx;
248 246
249 if (current_cpu_data.x86_vendor != X86_VENDOR_AMD) { 247 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) {
250 printk(KERN_INFO "has_svm: not amd\n"); 248 printk(KERN_INFO "has_svm: not amd\n");
251 return 0; 249 return 0;
252 } 250 }
@@ -402,11 +400,11 @@ static __init int svm_hardware_setup(void)
402 set_msr_interception(msrpm_va, MSR_GS_BASE, 1, 1); 400 set_msr_interception(msrpm_va, MSR_GS_BASE, 1, 1);
403 set_msr_interception(msrpm_va, MSR_FS_BASE, 1, 1); 401 set_msr_interception(msrpm_va, MSR_FS_BASE, 1, 1);
404 set_msr_interception(msrpm_va, MSR_KERNEL_GS_BASE, 1, 1); 402 set_msr_interception(msrpm_va, MSR_KERNEL_GS_BASE, 1, 1);
405 set_msr_interception(msrpm_va, MSR_STAR, 1, 1);
406 set_msr_interception(msrpm_va, MSR_LSTAR, 1, 1); 403 set_msr_interception(msrpm_va, MSR_LSTAR, 1, 1);
407 set_msr_interception(msrpm_va, MSR_CSTAR, 1, 1); 404 set_msr_interception(msrpm_va, MSR_CSTAR, 1, 1);
408 set_msr_interception(msrpm_va, MSR_SYSCALL_MASK, 1, 1); 405 set_msr_interception(msrpm_va, MSR_SYSCALL_MASK, 1, 1);
409#endif 406#endif
407 set_msr_interception(msrpm_va, MSR_K6_STAR, 1, 1);
410 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_CS, 1, 1); 408 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_CS, 1, 1);
411 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_ESP, 1, 1); 409 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_ESP, 1, 1);
412 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_EIP, 1, 1); 410 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_EIP, 1, 1);
@@ -500,11 +498,11 @@ static void init_vmcb(struct vmcb *vmcb)
500 /* (1ULL << INTERCEPT_SELECTIVE_CR0) | */ 498 /* (1ULL << INTERCEPT_SELECTIVE_CR0) | */
501 (1ULL << INTERCEPT_CPUID) | 499 (1ULL << INTERCEPT_CPUID) |
502 (1ULL << INTERCEPT_HLT) | 500 (1ULL << INTERCEPT_HLT) |
503 (1ULL << INTERCEPT_INVLPG) |
504 (1ULL << INTERCEPT_INVLPGA) | 501 (1ULL << INTERCEPT_INVLPGA) |
505 (1ULL << INTERCEPT_IOIO_PROT) | 502 (1ULL << INTERCEPT_IOIO_PROT) |
506 (1ULL << INTERCEPT_MSR_PROT) | 503 (1ULL << INTERCEPT_MSR_PROT) |
507 (1ULL << INTERCEPT_TASK_SWITCH) | 504 (1ULL << INTERCEPT_TASK_SWITCH) |
505 (1ULL << INTERCEPT_SHUTDOWN) |
508 (1ULL << INTERCEPT_VMRUN) | 506 (1ULL << INTERCEPT_VMRUN) |
509 (1ULL << INTERCEPT_VMMCALL) | 507 (1ULL << INTERCEPT_VMMCALL) |
510 (1ULL << INTERCEPT_VMLOAD) | 508 (1ULL << INTERCEPT_VMLOAD) |
@@ -575,6 +573,8 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu)
575 memset(vcpu->svm->db_regs, 0, sizeof(vcpu->svm->db_regs)); 573 memset(vcpu->svm->db_regs, 0, sizeof(vcpu->svm->db_regs));
576 init_vmcb(vcpu->svm->vmcb); 574 init_vmcb(vcpu->svm->vmcb);
577 575
576 fx_init(vcpu);
577
578 return 0; 578 return 0;
579 579
580out2: 580out2:
@@ -681,14 +681,14 @@ static void svm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
681 681
682static void svm_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt) 682static void svm_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
683{ 683{
684 dt->limit = vcpu->svm->vmcb->save.ldtr.limit; 684 dt->limit = vcpu->svm->vmcb->save.idtr.limit;
685 dt->base = vcpu->svm->vmcb->save.ldtr.base; 685 dt->base = vcpu->svm->vmcb->save.idtr.base;
686} 686}
687 687
688static void svm_set_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt) 688static void svm_set_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
689{ 689{
690 vcpu->svm->vmcb->save.ldtr.limit = dt->limit; 690 vcpu->svm->vmcb->save.idtr.limit = dt->limit;
691 vcpu->svm->vmcb->save.ldtr.base = dt->base ; 691 vcpu->svm->vmcb->save.idtr.base = dt->base ;
692} 692}
693 693
694static void svm_get_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt) 694static void svm_get_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
@@ -703,6 +703,10 @@ static void svm_set_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
703 vcpu->svm->vmcb->save.gdtr.base = dt->base ; 703 vcpu->svm->vmcb->save.gdtr.base = dt->base ;
704} 704}
705 705
706static void svm_decache_cr0_cr4_guest_bits(struct kvm_vcpu *vcpu)
707{
708}
709
706static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) 710static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
707{ 711{
708#ifdef CONFIG_X86_64 712#ifdef CONFIG_X86_64
@@ -850,6 +854,7 @@ static int pf_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
850 u64 fault_address; 854 u64 fault_address;
851 u32 error_code; 855 u32 error_code;
852 enum emulation_result er; 856 enum emulation_result er;
857 int r;
853 858
854 if (is_external_interrupt(exit_int_info)) 859 if (is_external_interrupt(exit_int_info))
855 push_irq(vcpu, exit_int_info & SVM_EVTINJ_VEC_MASK); 860 push_irq(vcpu, exit_int_info & SVM_EVTINJ_VEC_MASK);
@@ -858,7 +863,12 @@ static int pf_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
858 863
859 fault_address = vcpu->svm->vmcb->control.exit_info_2; 864 fault_address = vcpu->svm->vmcb->control.exit_info_2;
860 error_code = vcpu->svm->vmcb->control.exit_info_1; 865 error_code = vcpu->svm->vmcb->control.exit_info_1;
861 if (!vcpu->mmu.page_fault(vcpu, fault_address, error_code)) { 866 r = kvm_mmu_page_fault(vcpu, fault_address, error_code);
867 if (r < 0) {
868 spin_unlock(&vcpu->kvm->lock);
869 return r;
870 }
871 if (!r) {
862 spin_unlock(&vcpu->kvm->lock); 872 spin_unlock(&vcpu->kvm->lock);
863 return 1; 873 return 1;
864 } 874 }
@@ -883,6 +893,19 @@ static int pf_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
883 return 0; 893 return 0;
884} 894}
885 895
896static int shutdown_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
897{
898 /*
899 * VMCB is undefined after a SHUTDOWN intercept
900 * so reinitialize it.
901 */
902 memset(vcpu->svm->vmcb, 0, PAGE_SIZE);
903 init_vmcb(vcpu->svm->vmcb);
904
905 kvm_run->exit_reason = KVM_EXIT_SHUTDOWN;
906 return 0;
907}
908
886static int io_get_override(struct kvm_vcpu *vcpu, 909static int io_get_override(struct kvm_vcpu *vcpu,
887 struct vmcb_seg **seg, 910 struct vmcb_seg **seg,
888 int *addr_override) 911 int *addr_override)
@@ -1034,10 +1057,11 @@ static int halt_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1034{ 1057{
1035 vcpu->svm->next_rip = vcpu->svm->vmcb->save.rip + 1; 1058 vcpu->svm->next_rip = vcpu->svm->vmcb->save.rip + 1;
1036 skip_emulated_instruction(vcpu); 1059 skip_emulated_instruction(vcpu);
1037 if (vcpu->irq_summary && (vcpu->svm->vmcb->save.rflags & X86_EFLAGS_IF)) 1060 if (vcpu->irq_summary)
1038 return 1; 1061 return 1;
1039 1062
1040 kvm_run->exit_reason = KVM_EXIT_HLT; 1063 kvm_run->exit_reason = KVM_EXIT_HLT;
1064 ++kvm_stat.halt_exits;
1041 return 0; 1065 return 0;
1042} 1066}
1043 1067
@@ -1071,20 +1095,6 @@ static int emulate_on_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_ru
1071static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data) 1095static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
1072{ 1096{
1073 switch (ecx) { 1097 switch (ecx) {
1074 case MSR_IA32_MC0_CTL:
1075 case MSR_IA32_MCG_STATUS:
1076 case MSR_IA32_MCG_CAP:
1077 case MSR_IA32_MC0_MISC:
1078 case MSR_IA32_MC0_MISC+4:
1079 case MSR_IA32_MC0_MISC+8:
1080 case MSR_IA32_MC0_MISC+12:
1081 case MSR_IA32_MC0_MISC+16:
1082 case MSR_IA32_UCODE_REV:
1083 /* MTRR registers */
1084 case 0xfe:
1085 case 0x200 ... 0x2ff:
1086 *data = 0;
1087 break;
1088 case MSR_IA32_TIME_STAMP_COUNTER: { 1098 case MSR_IA32_TIME_STAMP_COUNTER: {
1089 u64 tsc; 1099 u64 tsc;
1090 1100
@@ -1092,16 +1102,10 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
1092 *data = vcpu->svm->vmcb->control.tsc_offset + tsc; 1102 *data = vcpu->svm->vmcb->control.tsc_offset + tsc;
1093 break; 1103 break;
1094 } 1104 }
1095 case MSR_EFER: 1105 case MSR_K6_STAR:
1096 *data = vcpu->shadow_efer;
1097 break;
1098 case MSR_IA32_APICBASE:
1099 *data = vcpu->apic_base;
1100 break;
1101#ifdef CONFIG_X86_64
1102 case MSR_STAR:
1103 *data = vcpu->svm->vmcb->save.star; 1106 *data = vcpu->svm->vmcb->save.star;
1104 break; 1107 break;
1108#ifdef CONFIG_X86_64
1105 case MSR_LSTAR: 1109 case MSR_LSTAR:
1106 *data = vcpu->svm->vmcb->save.lstar; 1110 *data = vcpu->svm->vmcb->save.lstar;
1107 break; 1111 break;
@@ -1125,8 +1129,7 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
1125 *data = vcpu->svm->vmcb->save.sysenter_esp; 1129 *data = vcpu->svm->vmcb->save.sysenter_esp;
1126 break; 1130 break;
1127 default: 1131 default:
1128 printk(KERN_ERR "kvm: unhandled rdmsr: 0x%x\n", ecx); 1132 return kvm_get_msr_common(vcpu, ecx, data);
1129 return 1;
1130 } 1133 }
1131 return 0; 1134 return 0;
1132} 1135}
@@ -1150,15 +1153,6 @@ static int rdmsr_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1150static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) 1153static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
1151{ 1154{
1152 switch (ecx) { 1155 switch (ecx) {
1153#ifdef CONFIG_X86_64
1154 case MSR_EFER:
1155 set_efer(vcpu, data);
1156 break;
1157#endif
1158 case MSR_IA32_MC0_STATUS:
1159 printk(KERN_WARNING "%s: MSR_IA32_MC0_STATUS 0x%llx, nop\n"
1160 , __FUNCTION__, data);
1161 break;
1162 case MSR_IA32_TIME_STAMP_COUNTER: { 1156 case MSR_IA32_TIME_STAMP_COUNTER: {
1163 u64 tsc; 1157 u64 tsc;
1164 1158
@@ -1166,17 +1160,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
1166 vcpu->svm->vmcb->control.tsc_offset = data - tsc; 1160 vcpu->svm->vmcb->control.tsc_offset = data - tsc;
1167 break; 1161 break;
1168 } 1162 }
1169 case MSR_IA32_UCODE_REV: 1163 case MSR_K6_STAR:
1170 case MSR_IA32_UCODE_WRITE:
1171 case 0x200 ... 0x2ff: /* MTRRs */
1172 break;
1173 case MSR_IA32_APICBASE:
1174 vcpu->apic_base = data;
1175 break;
1176#ifdef CONFIG_X86_64_
1177 case MSR_STAR:
1178 vcpu->svm->vmcb->save.star = data; 1164 vcpu->svm->vmcb->save.star = data;
1179 break; 1165 break;
1166#ifdef CONFIG_X86_64
1180 case MSR_LSTAR: 1167 case MSR_LSTAR:
1181 vcpu->svm->vmcb->save.lstar = data; 1168 vcpu->svm->vmcb->save.lstar = data;
1182 break; 1169 break;
@@ -1200,8 +1187,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
1200 vcpu->svm->vmcb->save.sysenter_esp = data; 1187 vcpu->svm->vmcb->save.sysenter_esp = data;
1201 break; 1188 break;
1202 default: 1189 default:
1203 printk(KERN_ERR "kvm: unhandled wrmsr: %x\n", ecx); 1190 return kvm_set_msr_common(vcpu, ecx, data);
1204 return 1;
1205 } 1191 }
1206 return 0; 1192 return 0;
1207} 1193}
@@ -1227,6 +1213,23 @@ static int msr_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1227 return rdmsr_interception(vcpu, kvm_run); 1213 return rdmsr_interception(vcpu, kvm_run);
1228} 1214}
1229 1215
1216static int interrupt_window_interception(struct kvm_vcpu *vcpu,
1217 struct kvm_run *kvm_run)
1218{
1219 /*
1220 * If the user space waits to inject interrupts, exit as soon as
1221 * possible
1222 */
1223 if (kvm_run->request_interrupt_window &&
1224 !vcpu->irq_summary) {
1225 ++kvm_stat.irq_window_exits;
1226 kvm_run->exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN;
1227 return 0;
1228 }
1229
1230 return 1;
1231}
1232
1230static int (*svm_exit_handlers[])(struct kvm_vcpu *vcpu, 1233static int (*svm_exit_handlers[])(struct kvm_vcpu *vcpu,
1231 struct kvm_run *kvm_run) = { 1234 struct kvm_run *kvm_run) = {
1232 [SVM_EXIT_READ_CR0] = emulate_on_interception, 1235 [SVM_EXIT_READ_CR0] = emulate_on_interception,
@@ -1251,6 +1254,7 @@ static int (*svm_exit_handlers[])(struct kvm_vcpu *vcpu,
1251 [SVM_EXIT_NMI] = nop_on_interception, 1254 [SVM_EXIT_NMI] = nop_on_interception,
1252 [SVM_EXIT_SMI] = nop_on_interception, 1255 [SVM_EXIT_SMI] = nop_on_interception,
1253 [SVM_EXIT_INIT] = nop_on_interception, 1256 [SVM_EXIT_INIT] = nop_on_interception,
1257 [SVM_EXIT_VINTR] = interrupt_window_interception,
1254 /* [SVM_EXIT_CR0_SEL_WRITE] = emulate_on_interception, */ 1258 /* [SVM_EXIT_CR0_SEL_WRITE] = emulate_on_interception, */
1255 [SVM_EXIT_CPUID] = cpuid_interception, 1259 [SVM_EXIT_CPUID] = cpuid_interception,
1256 [SVM_EXIT_HLT] = halt_interception, 1260 [SVM_EXIT_HLT] = halt_interception,
@@ -1259,6 +1263,7 @@ static int (*svm_exit_handlers[])(struct kvm_vcpu *vcpu,
1259 [SVM_EXIT_IOIO] = io_interception, 1263 [SVM_EXIT_IOIO] = io_interception,
1260 [SVM_EXIT_MSR] = msr_interception, 1264 [SVM_EXIT_MSR] = msr_interception,
1261 [SVM_EXIT_TASK_SWITCH] = task_switch_interception, 1265 [SVM_EXIT_TASK_SWITCH] = task_switch_interception,
1266 [SVM_EXIT_SHUTDOWN] = shutdown_interception,
1262 [SVM_EXIT_VMRUN] = invalid_op_interception, 1267 [SVM_EXIT_VMRUN] = invalid_op_interception,
1263 [SVM_EXIT_VMMCALL] = invalid_op_interception, 1268 [SVM_EXIT_VMMCALL] = invalid_op_interception,
1264 [SVM_EXIT_VMLOAD] = invalid_op_interception, 1269 [SVM_EXIT_VMLOAD] = invalid_op_interception,
@@ -1319,15 +1324,11 @@ static void pre_svm_run(struct kvm_vcpu *vcpu)
1319} 1324}
1320 1325
1321 1326
1322static inline void kvm_try_inject_irq(struct kvm_vcpu *vcpu) 1327static inline void kvm_do_inject_irq(struct kvm_vcpu *vcpu)
1323{ 1328{
1324 struct vmcb_control_area *control; 1329 struct vmcb_control_area *control;
1325 1330
1326 if (!vcpu->irq_summary)
1327 return;
1328
1329 control = &vcpu->svm->vmcb->control; 1331 control = &vcpu->svm->vmcb->control;
1330
1331 control->int_vector = pop_irq(vcpu); 1332 control->int_vector = pop_irq(vcpu);
1332 control->int_ctl &= ~V_INTR_PRIO_MASK; 1333 control->int_ctl &= ~V_INTR_PRIO_MASK;
1333 control->int_ctl |= V_IRQ_MASK | 1334 control->int_ctl |= V_IRQ_MASK |
@@ -1342,6 +1343,59 @@ static void kvm_reput_irq(struct kvm_vcpu *vcpu)
1342 control->int_ctl &= ~V_IRQ_MASK; 1343 control->int_ctl &= ~V_IRQ_MASK;
1343 push_irq(vcpu, control->int_vector); 1344 push_irq(vcpu, control->int_vector);
1344 } 1345 }
1346
1347 vcpu->interrupt_window_open =
1348 !(control->int_state & SVM_INTERRUPT_SHADOW_MASK);
1349}
1350
1351static void do_interrupt_requests(struct kvm_vcpu *vcpu,
1352 struct kvm_run *kvm_run)
1353{
1354 struct vmcb_control_area *control = &vcpu->svm->vmcb->control;
1355
1356 vcpu->interrupt_window_open =
1357 (!(control->int_state & SVM_INTERRUPT_SHADOW_MASK) &&
1358 (vcpu->svm->vmcb->save.rflags & X86_EFLAGS_IF));
1359
1360 if (vcpu->interrupt_window_open && vcpu->irq_summary)
1361 /*
1362 * If interrupts enabled, and not blocked by sti or mov ss. Good.
1363 */
1364 kvm_do_inject_irq(vcpu);
1365
1366 /*
1367 * Interrupts blocked. Wait for unblock.
1368 */
1369 if (!vcpu->interrupt_window_open &&
1370 (vcpu->irq_summary || kvm_run->request_interrupt_window)) {
1371 control->intercept |= 1ULL << INTERCEPT_VINTR;
1372 } else
1373 control->intercept &= ~(1ULL << INTERCEPT_VINTR);
1374}
1375
1376static void post_kvm_run_save(struct kvm_vcpu *vcpu,
1377 struct kvm_run *kvm_run)
1378{
1379 kvm_run->ready_for_interrupt_injection = (vcpu->interrupt_window_open &&
1380 vcpu->irq_summary == 0);
1381 kvm_run->if_flag = (vcpu->svm->vmcb->save.rflags & X86_EFLAGS_IF) != 0;
1382 kvm_run->cr8 = vcpu->cr8;
1383 kvm_run->apic_base = vcpu->apic_base;
1384}
1385
1386/*
1387 * Check if userspace requested an interrupt window, and that the
1388 * interrupt window is open.
1389 *
1390 * No need to exit to userspace if we already have an interrupt queued.
1391 */
1392static int dm_request_for_irq_injection(struct kvm_vcpu *vcpu,
1393 struct kvm_run *kvm_run)
1394{
1395 return (!vcpu->irq_summary &&
1396 kvm_run->request_interrupt_window &&
1397 vcpu->interrupt_window_open &&
1398 (vcpu->svm->vmcb->save.rflags & X86_EFLAGS_IF));
1345} 1399}
1346 1400
1347static void save_db_regs(unsigned long *db_regs) 1401static void save_db_regs(unsigned long *db_regs)
@@ -1365,9 +1419,11 @@ static int svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1365 u16 fs_selector; 1419 u16 fs_selector;
1366 u16 gs_selector; 1420 u16 gs_selector;
1367 u16 ldt_selector; 1421 u16 ldt_selector;
1422 int r;
1368 1423
1369again: 1424again:
1370 kvm_try_inject_irq(vcpu); 1425 if (!vcpu->mmio_read_completed)
1426 do_interrupt_requests(vcpu, kvm_run);
1371 1427
1372 clgi(); 1428 clgi();
1373 1429
@@ -1387,6 +1443,10 @@ again:
1387 save_db_regs(vcpu->svm->host_db_regs); 1443 save_db_regs(vcpu->svm->host_db_regs);
1388 load_db_regs(vcpu->svm->db_regs); 1444 load_db_regs(vcpu->svm->db_regs);
1389 } 1445 }
1446
1447 fx_save(vcpu->host_fx_image);
1448 fx_restore(vcpu->guest_fx_image);
1449
1390 asm volatile ( 1450 asm volatile (
1391#ifdef CONFIG_X86_64 1451#ifdef CONFIG_X86_64
1392 "push %%rbx; push %%rcx; push %%rdx;" 1452 "push %%rbx; push %%rcx; push %%rdx;"
@@ -1496,6 +1556,9 @@ again:
1496#endif 1556#endif
1497 : "cc", "memory" ); 1557 : "cc", "memory" );
1498 1558
1559 fx_save(vcpu->guest_fx_image);
1560 fx_restore(vcpu->host_fx_image);
1561
1499 if ((vcpu->svm->vmcb->save.dr7 & 0xff)) 1562 if ((vcpu->svm->vmcb->save.dr7 & 0xff))
1500 load_db_regs(vcpu->svm->host_db_regs); 1563 load_db_regs(vcpu->svm->host_db_regs);
1501 1564
@@ -1512,6 +1575,13 @@ again:
1512 1575
1513 reload_tss(vcpu); 1576 reload_tss(vcpu);
1514 1577
1578 /*
1579 * Profile KVM exit RIPs:
1580 */
1581 if (unlikely(prof_on == KVM_PROFILING))
1582 profile_hit(KVM_PROFILING,
1583 (void *)(unsigned long)vcpu->svm->vmcb->save.rip);
1584
1515 stgi(); 1585 stgi();
1516 1586
1517 kvm_reput_irq(vcpu); 1587 kvm_reput_irq(vcpu);
@@ -1521,18 +1591,28 @@ again:
1521 if (vcpu->svm->vmcb->control.exit_code == SVM_EXIT_ERR) { 1591 if (vcpu->svm->vmcb->control.exit_code == SVM_EXIT_ERR) {
1522 kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY; 1592 kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY;
1523 kvm_run->exit_reason = vcpu->svm->vmcb->control.exit_code; 1593 kvm_run->exit_reason = vcpu->svm->vmcb->control.exit_code;
1594 post_kvm_run_save(vcpu, kvm_run);
1524 return 0; 1595 return 0;
1525 } 1596 }
1526 1597
1527 if (handle_exit(vcpu, kvm_run)) { 1598 r = handle_exit(vcpu, kvm_run);
1599 if (r > 0) {
1528 if (signal_pending(current)) { 1600 if (signal_pending(current)) {
1529 ++kvm_stat.signal_exits; 1601 ++kvm_stat.signal_exits;
1602 post_kvm_run_save(vcpu, kvm_run);
1603 return -EINTR;
1604 }
1605
1606 if (dm_request_for_irq_injection(vcpu, kvm_run)) {
1607 ++kvm_stat.request_irq_exits;
1608 post_kvm_run_save(vcpu, kvm_run);
1530 return -EINTR; 1609 return -EINTR;
1531 } 1610 }
1532 kvm_resched(vcpu); 1611 kvm_resched(vcpu);
1533 goto again; 1612 goto again;
1534 } 1613 }
1535 return 0; 1614 post_kvm_run_save(vcpu, kvm_run);
1615 return r;
1536} 1616}
1537 1617
1538static void svm_flush_tlb(struct kvm_vcpu *vcpu) 1618static void svm_flush_tlb(struct kvm_vcpu *vcpu)
@@ -1598,8 +1678,8 @@ static struct kvm_arch_ops svm_arch_ops = {
1598 .get_segment_base = svm_get_segment_base, 1678 .get_segment_base = svm_get_segment_base,
1599 .get_segment = svm_get_segment, 1679 .get_segment = svm_get_segment,
1600 .set_segment = svm_set_segment, 1680 .set_segment = svm_set_segment,
1601 .is_long_mode = svm_is_long_mode,
1602 .get_cs_db_l_bits = svm_get_cs_db_l_bits, 1681 .get_cs_db_l_bits = svm_get_cs_db_l_bits,
1682 .decache_cr0_cr4_guest_bits = svm_decache_cr0_cr4_guest_bits,
1603 .set_cr0 = svm_set_cr0, 1683 .set_cr0 = svm_set_cr0,
1604 .set_cr0_no_modeswitch = svm_set_cr0, 1684 .set_cr0_no_modeswitch = svm_set_cr0,
1605 .set_cr3 = svm_set_cr3, 1685 .set_cr3 = svm_set_cr3,
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index f0f0b1a781..54c35c0b31 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -21,12 +21,12 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/highmem.h> 23#include <linux/highmem.h>
24#include <linux/profile.h>
24#include <asm/io.h> 25#include <asm/io.h>
25#include <asm/desc.h> 26#include <asm/desc.h>
26 27
27#include "segment_descriptor.h" 28#include "segment_descriptor.h"
28 29
29#define MSR_IA32_FEATURE_CONTROL 0x03a
30 30
31MODULE_AUTHOR("Qumranet"); 31MODULE_AUTHOR("Qumranet");
32MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
@@ -117,7 +117,7 @@ static void vmcs_clear(struct vmcs *vmcs)
117static void __vcpu_clear(void *arg) 117static void __vcpu_clear(void *arg)
118{ 118{
119 struct kvm_vcpu *vcpu = arg; 119 struct kvm_vcpu *vcpu = arg;
120 int cpu = smp_processor_id(); 120 int cpu = raw_smp_processor_id();
121 121
122 if (vcpu->cpu == cpu) 122 if (vcpu->cpu == cpu)
123 vmcs_clear(vcpu->vmcs); 123 vmcs_clear(vcpu->vmcs);
@@ -153,15 +153,21 @@ static u64 vmcs_read64(unsigned long field)
153#endif 153#endif
154} 154}
155 155
156static noinline void vmwrite_error(unsigned long field, unsigned long value)
157{
158 printk(KERN_ERR "vmwrite error: reg %lx value %lx (err %d)\n",
159 field, value, vmcs_read32(VM_INSTRUCTION_ERROR));
160 dump_stack();
161}
162
156static void vmcs_writel(unsigned long field, unsigned long value) 163static void vmcs_writel(unsigned long field, unsigned long value)
157{ 164{
158 u8 error; 165 u8 error;
159 166
160 asm volatile (ASM_VMX_VMWRITE_RAX_RDX "; setna %0" 167 asm volatile (ASM_VMX_VMWRITE_RAX_RDX "; setna %0"
161 : "=q"(error) : "a"(value), "d"(field) : "cc" ); 168 : "=q"(error) : "a"(value), "d"(field) : "cc" );
162 if (error) 169 if (unlikely(error))
163 printk(KERN_ERR "vmwrite error: reg %lx value %lx (err %d)\n", 170 vmwrite_error(field, value);
164 field, value, vmcs_read32(VM_INSTRUCTION_ERROR));
165} 171}
166 172
167static void vmcs_write16(unsigned long field, u16 value) 173static void vmcs_write16(unsigned long field, u16 value)
@@ -264,6 +270,7 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
264 if (interruptibility & 3) 270 if (interruptibility & 3)
265 vmcs_write32(GUEST_INTERRUPTIBILITY_INFO, 271 vmcs_write32(GUEST_INTERRUPTIBILITY_INFO,
266 interruptibility & ~3); 272 interruptibility & ~3);
273 vcpu->interrupt_window_open = 1;
267} 274}
268 275
269static void vmx_inject_gp(struct kvm_vcpu *vcpu, unsigned error_code) 276static void vmx_inject_gp(struct kvm_vcpu *vcpu, unsigned error_code)
@@ -344,8 +351,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
344 data = vmcs_readl(GUEST_GS_BASE); 351 data = vmcs_readl(GUEST_GS_BASE);
345 break; 352 break;
346 case MSR_EFER: 353 case MSR_EFER:
347 data = vcpu->shadow_efer; 354 return kvm_get_msr_common(vcpu, msr_index, pdata);
348 break;
349#endif 355#endif
350 case MSR_IA32_TIME_STAMP_COUNTER: 356 case MSR_IA32_TIME_STAMP_COUNTER:
351 data = guest_read_tsc(); 357 data = guest_read_tsc();
@@ -359,31 +365,13 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
359 case MSR_IA32_SYSENTER_ESP: 365 case MSR_IA32_SYSENTER_ESP:
360 data = vmcs_read32(GUEST_SYSENTER_ESP); 366 data = vmcs_read32(GUEST_SYSENTER_ESP);
361 break; 367 break;
362 case MSR_IA32_MC0_CTL:
363 case MSR_IA32_MCG_STATUS:
364 case MSR_IA32_MCG_CAP:
365 case MSR_IA32_MC0_MISC:
366 case MSR_IA32_MC0_MISC+4:
367 case MSR_IA32_MC0_MISC+8:
368 case MSR_IA32_MC0_MISC+12:
369 case MSR_IA32_MC0_MISC+16:
370 case MSR_IA32_UCODE_REV:
371 /* MTRR registers */
372 case 0xfe:
373 case 0x200 ... 0x2ff:
374 data = 0;
375 break;
376 case MSR_IA32_APICBASE:
377 data = vcpu->apic_base;
378 break;
379 default: 368 default:
380 msr = find_msr_entry(vcpu, msr_index); 369 msr = find_msr_entry(vcpu, msr_index);
381 if (!msr) { 370 if (msr) {
382 printk(KERN_ERR "kvm: unhandled rdmsr: %x\n", msr_index); 371 data = msr->data;
383 return 1; 372 break;
384 } 373 }
385 data = msr->data; 374 return kvm_get_msr_common(vcpu, msr_index, pdata);
386 break;
387 } 375 }
388 376
389 *pdata = data; 377 *pdata = data;
@@ -400,6 +388,8 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
400 struct vmx_msr_entry *msr; 388 struct vmx_msr_entry *msr;
401 switch (msr_index) { 389 switch (msr_index) {
402#ifdef CONFIG_X86_64 390#ifdef CONFIG_X86_64
391 case MSR_EFER:
392 return kvm_set_msr_common(vcpu, msr_index, data);
403 case MSR_FS_BASE: 393 case MSR_FS_BASE:
404 vmcs_writel(GUEST_FS_BASE, data); 394 vmcs_writel(GUEST_FS_BASE, data);
405 break; 395 break;
@@ -416,32 +406,17 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
416 case MSR_IA32_SYSENTER_ESP: 406 case MSR_IA32_SYSENTER_ESP:
417 vmcs_write32(GUEST_SYSENTER_ESP, data); 407 vmcs_write32(GUEST_SYSENTER_ESP, data);
418 break; 408 break;
419#ifdef __x86_64
420 case MSR_EFER:
421 set_efer(vcpu, data);
422 break;
423 case MSR_IA32_MC0_STATUS:
424 printk(KERN_WARNING "%s: MSR_IA32_MC0_STATUS 0x%llx, nop\n"
425 , __FUNCTION__, data);
426 break;
427#endif
428 case MSR_IA32_TIME_STAMP_COUNTER: { 409 case MSR_IA32_TIME_STAMP_COUNTER: {
429 guest_write_tsc(data); 410 guest_write_tsc(data);
430 break; 411 break;
431 } 412 }
432 case MSR_IA32_UCODE_REV:
433 case MSR_IA32_UCODE_WRITE:
434 case 0x200 ... 0x2ff: /* MTRRs */
435 break;
436 case MSR_IA32_APICBASE:
437 vcpu->apic_base = data;
438 break;
439 default: 413 default:
440 msr = find_msr_entry(vcpu, msr_index); 414 msr = find_msr_entry(vcpu, msr_index);
441 if (!msr) { 415 if (msr) {
442 printk(KERN_ERR "kvm: unhandled wrmsr: 0x%x\n", msr_index); 416 msr->data = data;
443 return 1; 417 break;
444 } 418 }
419 return kvm_set_msr_common(vcpu, msr_index, data);
445 msr->data = data; 420 msr->data = data;
446 break; 421 break;
447 } 422 }
@@ -551,11 +526,11 @@ static __init void setup_vmcs_descriptor(void)
551{ 526{
552 u32 vmx_msr_low, vmx_msr_high; 527 u32 vmx_msr_low, vmx_msr_high;
553 528
554 rdmsr(MSR_IA32_VMX_BASIC_MSR, vmx_msr_low, vmx_msr_high); 529 rdmsr(MSR_IA32_VMX_BASIC, vmx_msr_low, vmx_msr_high);
555 vmcs_descriptor.size = vmx_msr_high & 0x1fff; 530 vmcs_descriptor.size = vmx_msr_high & 0x1fff;
556 vmcs_descriptor.order = get_order(vmcs_descriptor.size); 531 vmcs_descriptor.order = get_order(vmcs_descriptor.size);
557 vmcs_descriptor.revision_id = vmx_msr_low; 532 vmcs_descriptor.revision_id = vmx_msr_low;
558}; 533}
559 534
560static struct vmcs *alloc_vmcs_cpu(int cpu) 535static struct vmcs *alloc_vmcs_cpu(int cpu)
561{ 536{
@@ -574,7 +549,7 @@ static struct vmcs *alloc_vmcs_cpu(int cpu)
574 549
575static struct vmcs *alloc_vmcs(void) 550static struct vmcs *alloc_vmcs(void)
576{ 551{
577 return alloc_vmcs_cpu(smp_processor_id()); 552 return alloc_vmcs_cpu(raw_smp_processor_id());
578} 553}
579 554
580static void free_vmcs(struct vmcs *vmcs) 555static void free_vmcs(struct vmcs *vmcs)
@@ -726,6 +701,7 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
726 vmcs_write32(GUEST_SS_AR_BYTES, 0xf3); 701 vmcs_write32(GUEST_SS_AR_BYTES, 0xf3);
727 702
728 vmcs_write32(GUEST_CS_AR_BYTES, 0xf3); 703 vmcs_write32(GUEST_CS_AR_BYTES, 0xf3);
704 vmcs_write32(GUEST_CS_LIMIT, 0xffff);
729 vmcs_write16(GUEST_CS_SELECTOR, vmcs_readl(GUEST_CS_BASE) >> 4); 705 vmcs_write16(GUEST_CS_SELECTOR, vmcs_readl(GUEST_CS_BASE) >> 4);
730 706
731 fix_rmode_seg(VCPU_SREG_ES, &vcpu->rmode.es); 707 fix_rmode_seg(VCPU_SREG_ES, &vcpu->rmode.es);
@@ -768,6 +744,15 @@ static void exit_lmode(struct kvm_vcpu *vcpu)
768 744
769#endif 745#endif
770 746
747static void vmx_decache_cr0_cr4_guest_bits(struct kvm_vcpu *vcpu)
748{
749 vcpu->cr0 &= KVM_GUEST_CR0_MASK;
750 vcpu->cr0 |= vmcs_readl(GUEST_CR0) & ~KVM_GUEST_CR0_MASK;
751
752 vcpu->cr4 &= KVM_GUEST_CR4_MASK;
753 vcpu->cr4 |= vmcs_readl(GUEST_CR4) & ~KVM_GUEST_CR4_MASK;
754}
755
771static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) 756static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
772{ 757{
773 if (vcpu->rmode.active && (cr0 & CR0_PE_MASK)) 758 if (vcpu->rmode.active && (cr0 & CR0_PE_MASK))
@@ -897,11 +882,6 @@ static void vmx_set_segment(struct kvm_vcpu *vcpu,
897 vmcs_write32(sf->ar_bytes, ar); 882 vmcs_write32(sf->ar_bytes, ar);
898} 883}
899 884
900static int vmx_is_long_mode(struct kvm_vcpu *vcpu)
901{
902 return vmcs_read32(VM_ENTRY_CONTROLS) & VM_ENTRY_CONTROLS_IA32E_MASK;
903}
904
905static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l) 885static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
906{ 886{
907 u32 ar = vmcs_read32(GUEST_CS_AR_BYTES); 887 u32 ar = vmcs_read32(GUEST_CS_AR_BYTES);
@@ -1048,8 +1028,6 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1048 vmcs_writel(GUEST_RIP, 0xfff0); 1028 vmcs_writel(GUEST_RIP, 0xfff0);
1049 vmcs_writel(GUEST_RSP, 0); 1029 vmcs_writel(GUEST_RSP, 0);
1050 1030
1051 vmcs_writel(GUEST_CR3, 0);
1052
1053 //todo: dr0 = dr1 = dr2 = dr3 = 0; dr6 = 0xffff0ff0 1031 //todo: dr0 = dr1 = dr2 = dr3 = 0; dr6 = 0xffff0ff0
1054 vmcs_writel(GUEST_DR7, 0x400); 1032 vmcs_writel(GUEST_DR7, 0x400);
1055 1033
@@ -1075,18 +1053,17 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1075 vmcs_write64(GUEST_IA32_DEBUGCTL, 0); 1053 vmcs_write64(GUEST_IA32_DEBUGCTL, 0);
1076 1054
1077 /* Control */ 1055 /* Control */
1078 vmcs_write32_fixedbits(MSR_IA32_VMX_PINBASED_CTLS_MSR, 1056 vmcs_write32_fixedbits(MSR_IA32_VMX_PINBASED_CTLS,
1079 PIN_BASED_VM_EXEC_CONTROL, 1057 PIN_BASED_VM_EXEC_CONTROL,
1080 PIN_BASED_EXT_INTR_MASK /* 20.6.1 */ 1058 PIN_BASED_EXT_INTR_MASK /* 20.6.1 */
1081 | PIN_BASED_NMI_EXITING /* 20.6.1 */ 1059 | PIN_BASED_NMI_EXITING /* 20.6.1 */
1082 ); 1060 );
1083 vmcs_write32_fixedbits(MSR_IA32_VMX_PROCBASED_CTLS_MSR, 1061 vmcs_write32_fixedbits(MSR_IA32_VMX_PROCBASED_CTLS,
1084 CPU_BASED_VM_EXEC_CONTROL, 1062 CPU_BASED_VM_EXEC_CONTROL,
1085 CPU_BASED_HLT_EXITING /* 20.6.2 */ 1063 CPU_BASED_HLT_EXITING /* 20.6.2 */
1086 | CPU_BASED_CR8_LOAD_EXITING /* 20.6.2 */ 1064 | CPU_BASED_CR8_LOAD_EXITING /* 20.6.2 */
1087 | CPU_BASED_CR8_STORE_EXITING /* 20.6.2 */ 1065 | CPU_BASED_CR8_STORE_EXITING /* 20.6.2 */
1088 | CPU_BASED_UNCOND_IO_EXITING /* 20.6.2 */ 1066 | CPU_BASED_UNCOND_IO_EXITING /* 20.6.2 */
1089 | CPU_BASED_INVDPG_EXITING
1090 | CPU_BASED_MOV_DR_EXITING 1067 | CPU_BASED_MOV_DR_EXITING
1091 | CPU_BASED_USE_TSC_OFFSETING /* 21.3 */ 1068 | CPU_BASED_USE_TSC_OFFSETING /* 21.3 */
1092 ); 1069 );
@@ -1131,14 +1108,6 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1131 rdmsrl(MSR_IA32_SYSENTER_EIP, a); 1108 rdmsrl(MSR_IA32_SYSENTER_EIP, a);
1132 vmcs_writel(HOST_IA32_SYSENTER_EIP, a); /* 22.2.3 */ 1109 vmcs_writel(HOST_IA32_SYSENTER_EIP, a); /* 22.2.3 */
1133 1110
1134 ret = -ENOMEM;
1135 vcpu->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
1136 if (!vcpu->guest_msrs)
1137 goto out;
1138 vcpu->host_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
1139 if (!vcpu->host_msrs)
1140 goto out_free_guest_msrs;
1141
1142 for (i = 0; i < NR_VMX_MSR; ++i) { 1111 for (i = 0; i < NR_VMX_MSR; ++i) {
1143 u32 index = vmx_msr_index[i]; 1112 u32 index = vmx_msr_index[i];
1144 u32 data_low, data_high; 1113 u32 data_low, data_high;
@@ -1147,6 +1116,8 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1147 1116
1148 if (rdmsr_safe(index, &data_low, &data_high) < 0) 1117 if (rdmsr_safe(index, &data_low, &data_high) < 0)
1149 continue; 1118 continue;
1119 if (wrmsr_safe(index, data_low, data_high) < 0)
1120 continue;
1150 data = data_low | ((u64)data_high << 32); 1121 data = data_low | ((u64)data_high << 32);
1151 vcpu->host_msrs[j].index = index; 1122 vcpu->host_msrs[j].index = index;
1152 vcpu->host_msrs[j].reserved = 0; 1123 vcpu->host_msrs[j].reserved = 0;
@@ -1163,7 +1134,7 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1163 virt_to_phys(vcpu->guest_msrs + NR_BAD_MSRS)); 1134 virt_to_phys(vcpu->guest_msrs + NR_BAD_MSRS));
1164 vmcs_writel(VM_EXIT_MSR_LOAD_ADDR, 1135 vmcs_writel(VM_EXIT_MSR_LOAD_ADDR,
1165 virt_to_phys(vcpu->host_msrs + NR_BAD_MSRS)); 1136 virt_to_phys(vcpu->host_msrs + NR_BAD_MSRS));
1166 vmcs_write32_fixedbits(MSR_IA32_VMX_EXIT_CTLS_MSR, VM_EXIT_CONTROLS, 1137 vmcs_write32_fixedbits(MSR_IA32_VMX_EXIT_CTLS, VM_EXIT_CONTROLS,
1167 (HOST_IS_64 << 9)); /* 22.2,1, 20.7.1 */ 1138 (HOST_IS_64 << 9)); /* 22.2,1, 20.7.1 */
1168 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, nr_good_msrs); /* 22.2.2 */ 1139 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, nr_good_msrs); /* 22.2.2 */
1169 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, nr_good_msrs); /* 22.2.2 */ 1140 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, nr_good_msrs); /* 22.2.2 */
@@ -1171,7 +1142,7 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1171 1142
1172 1143
1173 /* 22.2.1, 20.8.1 */ 1144 /* 22.2.1, 20.8.1 */
1174 vmcs_write32_fixedbits(MSR_IA32_VMX_ENTRY_CTLS_MSR, 1145 vmcs_write32_fixedbits(MSR_IA32_VMX_ENTRY_CTLS,
1175 VM_ENTRY_CONTROLS, 0); 1146 VM_ENTRY_CONTROLS, 0);
1176 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */ 1147 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */
1177 1148
@@ -1192,8 +1163,6 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1192 1163
1193 return 0; 1164 return 0;
1194 1165
1195out_free_guest_msrs:
1196 kfree(vcpu->guest_msrs);
1197out: 1166out:
1198 return ret; 1167 return ret;
1199} 1168}
@@ -1261,21 +1230,34 @@ static void kvm_do_inject_irq(struct kvm_vcpu *vcpu)
1261 irq | INTR_TYPE_EXT_INTR | INTR_INFO_VALID_MASK); 1230 irq | INTR_TYPE_EXT_INTR | INTR_INFO_VALID_MASK);
1262} 1231}
1263 1232
1264static void kvm_try_inject_irq(struct kvm_vcpu *vcpu) 1233
1234static void do_interrupt_requests(struct kvm_vcpu *vcpu,
1235 struct kvm_run *kvm_run)
1265{ 1236{
1266 if ((vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF) 1237 u32 cpu_based_vm_exec_control;
1267 && (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0) 1238
1239 vcpu->interrupt_window_open =
1240 ((vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF) &&
1241 (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0);
1242
1243 if (vcpu->interrupt_window_open &&
1244 vcpu->irq_summary &&
1245 !(vmcs_read32(VM_ENTRY_INTR_INFO_FIELD) & INTR_INFO_VALID_MASK))
1268 /* 1246 /*
1269 * Interrupts enabled, and not blocked by sti or mov ss. Good. 1247 * If interrupts enabled, and not blocked by sti or mov ss. Good.
1270 */ 1248 */
1271 kvm_do_inject_irq(vcpu); 1249 kvm_do_inject_irq(vcpu);
1272 else 1250
1251 cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
1252 if (!vcpu->interrupt_window_open &&
1253 (vcpu->irq_summary || kvm_run->request_interrupt_window))
1273 /* 1254 /*
1274 * Interrupts blocked. Wait for unblock. 1255 * Interrupts blocked. Wait for unblock.
1275 */ 1256 */
1276 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, 1257 cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_INTR_PENDING;
1277 vmcs_read32(CPU_BASED_VM_EXEC_CONTROL) 1258 else
1278 | CPU_BASED_VIRTUAL_INTR_PENDING); 1259 cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_INTR_PENDING;
1260 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
1279} 1261}
1280 1262
1281static void kvm_guest_debug_pre(struct kvm_vcpu *vcpu) 1263static void kvm_guest_debug_pre(struct kvm_vcpu *vcpu)
@@ -1314,6 +1296,7 @@ static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1314 unsigned long cr2, rip; 1296 unsigned long cr2, rip;
1315 u32 vect_info; 1297 u32 vect_info;
1316 enum emulation_result er; 1298 enum emulation_result er;
1299 int r;
1317 1300
1318 vect_info = vmcs_read32(IDT_VECTORING_INFO_FIELD); 1301 vect_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
1319 intr_info = vmcs_read32(VM_EXIT_INTR_INFO); 1302 intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
@@ -1342,7 +1325,12 @@ static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1342 cr2 = vmcs_readl(EXIT_QUALIFICATION); 1325 cr2 = vmcs_readl(EXIT_QUALIFICATION);
1343 1326
1344 spin_lock(&vcpu->kvm->lock); 1327 spin_lock(&vcpu->kvm->lock);
1345 if (!vcpu->mmu.page_fault(vcpu, cr2, error_code)) { 1328 r = kvm_mmu_page_fault(vcpu, cr2, error_code);
1329 if (r < 0) {
1330 spin_unlock(&vcpu->kvm->lock);
1331 return r;
1332 }
1333 if (!r) {
1346 spin_unlock(&vcpu->kvm->lock); 1334 spin_unlock(&vcpu->kvm->lock);
1347 return 1; 1335 return 1;
1348 } 1336 }
@@ -1462,17 +1450,6 @@ static int handle_io(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1462 return 0; 1450 return 0;
1463} 1451}
1464 1452
1465static int handle_invlpg(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1466{
1467 u64 address = vmcs_read64(EXIT_QUALIFICATION);
1468 int instruction_length = vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
1469 spin_lock(&vcpu->kvm->lock);
1470 vcpu->mmu.inval_page(vcpu, address);
1471 spin_unlock(&vcpu->kvm->lock);
1472 vmcs_writel(GUEST_RIP, vmcs_readl(GUEST_RIP) + instruction_length);
1473 return 1;
1474}
1475
1476static int handle_cr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 1453static int handle_cr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1477{ 1454{
1478 u64 exit_qualification; 1455 u64 exit_qualification;
@@ -1612,23 +1589,40 @@ static int handle_wrmsr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1612 return 1; 1589 return 1;
1613} 1590}
1614 1591
1592static void post_kvm_run_save(struct kvm_vcpu *vcpu,
1593 struct kvm_run *kvm_run)
1594{
1595 kvm_run->if_flag = (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF) != 0;
1596 kvm_run->cr8 = vcpu->cr8;
1597 kvm_run->apic_base = vcpu->apic_base;
1598 kvm_run->ready_for_interrupt_injection = (vcpu->interrupt_window_open &&
1599 vcpu->irq_summary == 0);
1600}
1601
1615static int handle_interrupt_window(struct kvm_vcpu *vcpu, 1602static int handle_interrupt_window(struct kvm_vcpu *vcpu,
1616 struct kvm_run *kvm_run) 1603 struct kvm_run *kvm_run)
1617{ 1604{
1618 /* Turn off interrupt window reporting. */ 1605 /*
1619 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, 1606 * If the user space waits to inject interrupts, exit as soon as
1620 vmcs_read32(CPU_BASED_VM_EXEC_CONTROL) 1607 * possible
1621 & ~CPU_BASED_VIRTUAL_INTR_PENDING); 1608 */
1609 if (kvm_run->request_interrupt_window &&
1610 !vcpu->irq_summary) {
1611 kvm_run->exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN;
1612 ++kvm_stat.irq_window_exits;
1613 return 0;
1614 }
1622 return 1; 1615 return 1;
1623} 1616}
1624 1617
1625static int handle_halt(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 1618static int handle_halt(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1626{ 1619{
1627 skip_emulated_instruction(vcpu); 1620 skip_emulated_instruction(vcpu);
1628 if (vcpu->irq_summary && (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF)) 1621 if (vcpu->irq_summary)
1629 return 1; 1622 return 1;
1630 1623
1631 kvm_run->exit_reason = KVM_EXIT_HLT; 1624 kvm_run->exit_reason = KVM_EXIT_HLT;
1625 ++kvm_stat.halt_exits;
1632 return 0; 1626 return 0;
1633} 1627}
1634 1628
@@ -1642,7 +1636,6 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu,
1642 [EXIT_REASON_EXCEPTION_NMI] = handle_exception, 1636 [EXIT_REASON_EXCEPTION_NMI] = handle_exception,
1643 [EXIT_REASON_EXTERNAL_INTERRUPT] = handle_external_interrupt, 1637 [EXIT_REASON_EXTERNAL_INTERRUPT] = handle_external_interrupt,
1644 [EXIT_REASON_IO_INSTRUCTION] = handle_io, 1638 [EXIT_REASON_IO_INSTRUCTION] = handle_io,
1645 [EXIT_REASON_INVLPG] = handle_invlpg,
1646 [EXIT_REASON_CR_ACCESS] = handle_cr, 1639 [EXIT_REASON_CR_ACCESS] = handle_cr,
1647 [EXIT_REASON_DR_ACCESS] = handle_dr, 1640 [EXIT_REASON_DR_ACCESS] = handle_dr,
1648 [EXIT_REASON_CPUID] = handle_cpuid, 1641 [EXIT_REASON_CPUID] = handle_cpuid,
@@ -1679,11 +1672,27 @@ static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1679 return 0; 1672 return 0;
1680} 1673}
1681 1674
1675/*
1676 * Check if userspace requested an interrupt window, and that the
1677 * interrupt window is open.
1678 *
1679 * No need to exit to userspace if we already have an interrupt queued.
1680 */
1681static int dm_request_for_irq_injection(struct kvm_vcpu *vcpu,
1682 struct kvm_run *kvm_run)
1683{
1684 return (!vcpu->irq_summary &&
1685 kvm_run->request_interrupt_window &&
1686 vcpu->interrupt_window_open &&
1687 (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF));
1688}
1689
1682static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 1690static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1683{ 1691{
1684 u8 fail; 1692 u8 fail;
1685 u16 fs_sel, gs_sel, ldt_sel; 1693 u16 fs_sel, gs_sel, ldt_sel;
1686 int fs_gs_ldt_reload_needed; 1694 int fs_gs_ldt_reload_needed;
1695 int r;
1687 1696
1688again: 1697again:
1689 /* 1698 /*
@@ -1710,9 +1719,8 @@ again:
1710 vmcs_writel(HOST_GS_BASE, segment_base(gs_sel)); 1719 vmcs_writel(HOST_GS_BASE, segment_base(gs_sel));
1711#endif 1720#endif
1712 1721
1713 if (vcpu->irq_summary && 1722 if (!vcpu->mmio_read_completed)
1714 !(vmcs_read32(VM_ENTRY_INTR_INFO_FIELD) & INTR_INFO_VALID_MASK)) 1723 do_interrupt_requests(vcpu, kvm_run);
1715 kvm_try_inject_irq(vcpu);
1716 1724
1717 if (vcpu->guest_debug.enabled) 1725 if (vcpu->guest_debug.enabled)
1718 kvm_guest_debug_pre(vcpu); 1726 kvm_guest_debug_pre(vcpu);
@@ -1819,7 +1827,7 @@ again:
1819#endif 1827#endif
1820 "setbe %0 \n\t" 1828 "setbe %0 \n\t"
1821 "popf \n\t" 1829 "popf \n\t"
1822 : "=g" (fail) 1830 : "=q" (fail)
1823 : "r"(vcpu->launched), "d"((unsigned long)HOST_RSP), 1831 : "r"(vcpu->launched), "d"((unsigned long)HOST_RSP),
1824 "c"(vcpu), 1832 "c"(vcpu),
1825 [rax]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RAX])), 1833 [rax]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RAX])),
@@ -1849,15 +1857,23 @@ again:
1849 1857
1850 fx_save(vcpu->guest_fx_image); 1858 fx_save(vcpu->guest_fx_image);
1851 fx_restore(vcpu->host_fx_image); 1859 fx_restore(vcpu->host_fx_image);
1860 vcpu->interrupt_window_open = (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0;
1852 1861
1853#ifndef CONFIG_X86_64 1862#ifndef CONFIG_X86_64
1854 asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS)); 1863 asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
1855#endif 1864#endif
1856 1865
1866 /*
1867 * Profile KVM exit RIPs:
1868 */
1869 if (unlikely(prof_on == KVM_PROFILING))
1870 profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));
1871
1857 kvm_run->exit_type = 0; 1872 kvm_run->exit_type = 0;
1858 if (fail) { 1873 if (fail) {
1859 kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY; 1874 kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY;
1860 kvm_run->exit_reason = vmcs_read32(VM_INSTRUCTION_ERROR); 1875 kvm_run->exit_reason = vmcs_read32(VM_INSTRUCTION_ERROR);
1876 r = 0;
1861 } else { 1877 } else {
1862 if (fs_gs_ldt_reload_needed) { 1878 if (fs_gs_ldt_reload_needed) {
1863 load_ldt(ldt_sel); 1879 load_ldt(ldt_sel);
@@ -1877,17 +1893,28 @@ again:
1877 } 1893 }
1878 vcpu->launched = 1; 1894 vcpu->launched = 1;
1879 kvm_run->exit_type = KVM_EXIT_TYPE_VM_EXIT; 1895 kvm_run->exit_type = KVM_EXIT_TYPE_VM_EXIT;
1880 if (kvm_handle_exit(kvm_run, vcpu)) { 1896 r = kvm_handle_exit(kvm_run, vcpu);
1897 if (r > 0) {
1881 /* Give scheduler a change to reschedule. */ 1898 /* Give scheduler a change to reschedule. */
1882 if (signal_pending(current)) { 1899 if (signal_pending(current)) {
1883 ++kvm_stat.signal_exits; 1900 ++kvm_stat.signal_exits;
1901 post_kvm_run_save(vcpu, kvm_run);
1902 return -EINTR;
1903 }
1904
1905 if (dm_request_for_irq_injection(vcpu, kvm_run)) {
1906 ++kvm_stat.request_irq_exits;
1907 post_kvm_run_save(vcpu, kvm_run);
1884 return -EINTR; 1908 return -EINTR;
1885 } 1909 }
1910
1886 kvm_resched(vcpu); 1911 kvm_resched(vcpu);
1887 goto again; 1912 goto again;
1888 } 1913 }
1889 } 1914 }
1890 return 0; 1915
1916 post_kvm_run_save(vcpu, kvm_run);
1917 return r;
1891} 1918}
1892 1919
1893static void vmx_flush_tlb(struct kvm_vcpu *vcpu) 1920static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
@@ -1943,13 +1970,33 @@ static int vmx_create_vcpu(struct kvm_vcpu *vcpu)
1943{ 1970{
1944 struct vmcs *vmcs; 1971 struct vmcs *vmcs;
1945 1972
1973 vcpu->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
1974 if (!vcpu->guest_msrs)
1975 return -ENOMEM;
1976
1977 vcpu->host_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
1978 if (!vcpu->host_msrs)
1979 goto out_free_guest_msrs;
1980
1946 vmcs = alloc_vmcs(); 1981 vmcs = alloc_vmcs();
1947 if (!vmcs) 1982 if (!vmcs)
1948 return -ENOMEM; 1983 goto out_free_msrs;
1984
1949 vmcs_clear(vmcs); 1985 vmcs_clear(vmcs);
1950 vcpu->vmcs = vmcs; 1986 vcpu->vmcs = vmcs;
1951 vcpu->launched = 0; 1987 vcpu->launched = 0;
1988
1952 return 0; 1989 return 0;
1990
1991out_free_msrs:
1992 kfree(vcpu->host_msrs);
1993 vcpu->host_msrs = NULL;
1994
1995out_free_guest_msrs:
1996 kfree(vcpu->guest_msrs);
1997 vcpu->guest_msrs = NULL;
1998
1999 return -ENOMEM;
1953} 2000}
1954 2001
1955static struct kvm_arch_ops vmx_arch_ops = { 2002static struct kvm_arch_ops vmx_arch_ops = {
@@ -1972,8 +2019,8 @@ static struct kvm_arch_ops vmx_arch_ops = {
1972 .get_segment_base = vmx_get_segment_base, 2019 .get_segment_base = vmx_get_segment_base,
1973 .get_segment = vmx_get_segment, 2020 .get_segment = vmx_get_segment,
1974 .set_segment = vmx_set_segment, 2021 .set_segment = vmx_set_segment,
1975 .is_long_mode = vmx_is_long_mode,
1976 .get_cs_db_l_bits = vmx_get_cs_db_l_bits, 2022 .get_cs_db_l_bits = vmx_get_cs_db_l_bits,
2023 .decache_cr0_cr4_guest_bits = vmx_decache_cr0_cr4_guest_bits,
1977 .set_cr0 = vmx_set_cr0, 2024 .set_cr0 = vmx_set_cr0,
1978 .set_cr0_no_modeswitch = vmx_set_cr0_no_modeswitch, 2025 .set_cr0_no_modeswitch = vmx_set_cr0_no_modeswitch,
1979 .set_cr3 = vmx_set_cr3, 2026 .set_cr3 = vmx_set_cr3,
diff --git a/drivers/kvm/vmx.h b/drivers/kvm/vmx.h
index 7972783415..4c0ab15183 100644
--- a/drivers/kvm/vmx.h
+++ b/drivers/kvm/vmx.h
@@ -286,11 +286,11 @@ enum vmcs_field {
286 286
287#define CR4_VMXE 0x2000 287#define CR4_VMXE 0x2000
288 288
289#define MSR_IA32_VMX_BASIC_MSR 0x480 289#define MSR_IA32_VMX_BASIC 0x480
290#define MSR_IA32_FEATURE_CONTROL 0x03a 290#define MSR_IA32_FEATURE_CONTROL 0x03a
291#define MSR_IA32_VMX_PINBASED_CTLS_MSR 0x481 291#define MSR_IA32_VMX_PINBASED_CTLS 0x481
292#define MSR_IA32_VMX_PROCBASED_CTLS_MSR 0x482 292#define MSR_IA32_VMX_PROCBASED_CTLS 0x482
293#define MSR_IA32_VMX_EXIT_CTLS_MSR 0x483 293#define MSR_IA32_VMX_EXIT_CTLS 0x483
294#define MSR_IA32_VMX_ENTRY_CTLS_MSR 0x484 294#define MSR_IA32_VMX_ENTRY_CTLS 0x484
295 295
296#endif 296#endif
diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index 1bff3e925f..7513cddb92 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -61,6 +61,7 @@
61#define ModRM (1<<6) 61#define ModRM (1<<6)
62/* Destination is only written; never read. */ 62/* Destination is only written; never read. */
63#define Mov (1<<7) 63#define Mov (1<<7)
64#define BitOp (1<<8)
64 65
65static u8 opcode_table[256] = { 66static u8 opcode_table[256] = {
66 /* 0x00 - 0x07 */ 67 /* 0x00 - 0x07 */
@@ -148,7 +149,7 @@ static u8 opcode_table[256] = {
148 0, 0, ByteOp | DstMem | SrcNone | ModRM, DstMem | SrcNone | ModRM 149 0, 0, ByteOp | DstMem | SrcNone | ModRM, DstMem | SrcNone | ModRM
149}; 150};
150 151
151static u8 twobyte_table[256] = { 152static u16 twobyte_table[256] = {
152 /* 0x00 - 0x0F */ 153 /* 0x00 - 0x0F */
153 0, SrcMem | ModRM | DstReg, 0, 0, 0, 0, ImplicitOps, 0, 154 0, SrcMem | ModRM | DstReg, 0, 0, 0, 0, ImplicitOps, 0,
154 0, 0, 0, 0, 0, ImplicitOps | ModRM, 0, 0, 155 0, 0, 0, 0, 0, ImplicitOps | ModRM, 0, 0,
@@ -180,16 +181,16 @@ static u8 twobyte_table[256] = {
180 /* 0x90 - 0x9F */ 181 /* 0x90 - 0x9F */
181 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 182 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
182 /* 0xA0 - 0xA7 */ 183 /* 0xA0 - 0xA7 */
183 0, 0, 0, DstMem | SrcReg | ModRM, 0, 0, 0, 0, 184 0, 0, 0, DstMem | SrcReg | ModRM | BitOp, 0, 0, 0, 0,
184 /* 0xA8 - 0xAF */ 185 /* 0xA8 - 0xAF */
185 0, 0, 0, DstMem | SrcReg | ModRM, 0, 0, 0, 0, 186 0, 0, 0, DstMem | SrcReg | ModRM | BitOp, 0, 0, 0, 0,
186 /* 0xB0 - 0xB7 */ 187 /* 0xB0 - 0xB7 */
187 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, 0, 188 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, 0,
188 DstMem | SrcReg | ModRM, 189 DstMem | SrcReg | ModRM | BitOp,
189 0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov, 190 0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov,
190 DstReg | SrcMem16 | ModRM | Mov, 191 DstReg | SrcMem16 | ModRM | Mov,
191 /* 0xB8 - 0xBF */ 192 /* 0xB8 - 0xBF */
192 0, 0, DstMem | SrcImmByte | ModRM, DstMem | SrcReg | ModRM, 193 0, 0, DstMem | SrcImmByte | ModRM, DstMem | SrcReg | ModRM | BitOp,
193 0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov, 194 0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov,
194 DstReg | SrcMem16 | ModRM | Mov, 195 DstReg | SrcMem16 | ModRM | Mov,
195 /* 0xC0 - 0xCF */ 196 /* 0xC0 - 0xCF */
@@ -469,7 +470,8 @@ static int read_descriptor(struct x86_emulate_ctxt *ctxt,
469int 470int
470x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) 471x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
471{ 472{
472 u8 b, d, sib, twobyte = 0, rex_prefix = 0; 473 unsigned d;
474 u8 b, sib, twobyte = 0, rex_prefix = 0;
473 u8 modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0; 475 u8 modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
474 unsigned long *override_base = NULL; 476 unsigned long *override_base = NULL;
475 unsigned int op_bytes, ad_bytes, lock_prefix = 0, rep_prefix = 0, i; 477 unsigned int op_bytes, ad_bytes, lock_prefix = 0, rep_prefix = 0, i;
@@ -726,46 +728,6 @@ done_prefixes:
726 ; 728 ;
727 } 729 }
728 730
729 /* Decode and fetch the destination operand: register or memory. */
730 switch (d & DstMask) {
731 case ImplicitOps:
732 /* Special instructions do their own operand decoding. */
733 goto special_insn;
734 case DstReg:
735 dst.type = OP_REG;
736 if ((d & ByteOp)
737 && !(twobyte_table && (b == 0xb6 || b == 0xb7))) {
738 dst.ptr = decode_register(modrm_reg, _regs,
739 (rex_prefix == 0));
740 dst.val = *(u8 *) dst.ptr;
741 dst.bytes = 1;
742 } else {
743 dst.ptr = decode_register(modrm_reg, _regs, 0);
744 switch ((dst.bytes = op_bytes)) {
745 case 2:
746 dst.val = *(u16 *)dst.ptr;
747 break;
748 case 4:
749 dst.val = *(u32 *)dst.ptr;
750 break;
751 case 8:
752 dst.val = *(u64 *)dst.ptr;
753 break;
754 }
755 }
756 break;
757 case DstMem:
758 dst.type = OP_MEM;
759 dst.ptr = (unsigned long *)cr2;
760 dst.bytes = (d & ByteOp) ? 1 : op_bytes;
761 if (!(d & Mov) && /* optimisation - avoid slow emulated read */
762 ((rc = ops->read_emulated((unsigned long)dst.ptr,
763 &dst.val, dst.bytes, ctxt)) != 0))
764 goto done;
765 break;
766 }
767 dst.orig_val = dst.val;
768
769 /* 731 /*
770 * Decode and fetch the source operand: register, memory 732 * Decode and fetch the source operand: register, memory
771 * or immediate. 733 * or immediate.
@@ -838,6 +800,50 @@ done_prefixes:
838 break; 800 break;
839 } 801 }
840 802
803 /* Decode and fetch the destination operand: register or memory. */
804 switch (d & DstMask) {
805 case ImplicitOps:
806 /* Special instructions do their own operand decoding. */
807 goto special_insn;
808 case DstReg:
809 dst.type = OP_REG;
810 if ((d & ByteOp)
811 && !(twobyte_table && (b == 0xb6 || b == 0xb7))) {
812 dst.ptr = decode_register(modrm_reg, _regs,
813 (rex_prefix == 0));
814 dst.val = *(u8 *) dst.ptr;
815 dst.bytes = 1;
816 } else {
817 dst.ptr = decode_register(modrm_reg, _regs, 0);
818 switch ((dst.bytes = op_bytes)) {
819 case 2:
820 dst.val = *(u16 *)dst.ptr;
821 break;
822 case 4:
823 dst.val = *(u32 *)dst.ptr;
824 break;
825 case 8:
826 dst.val = *(u64 *)dst.ptr;
827 break;
828 }
829 }
830 break;
831 case DstMem:
832 dst.type = OP_MEM;
833 dst.ptr = (unsigned long *)cr2;
834 dst.bytes = (d & ByteOp) ? 1 : op_bytes;
835 if (d & BitOp) {
836 dst.ptr += src.val / BITS_PER_LONG;
837 dst.bytes = sizeof(long);
838 }
839 if (!(d & Mov) && /* optimisation - avoid slow emulated read */
840 ((rc = ops->read_emulated((unsigned long)dst.ptr,
841 &dst.val, dst.bytes, ctxt)) != 0))
842 goto done;
843 break;
844 }
845 dst.orig_val = dst.val;
846
841 if (twobyte) 847 if (twobyte)
842 goto twobyte_insn; 848 goto twobyte_insn;
843 849
@@ -1323,7 +1329,7 @@ twobyte_special_insn:
1323 ctxt)) != 0)) 1329 ctxt)) != 0))
1324 goto done; 1330 goto done;
1325 if ((old_lo != _regs[VCPU_REGS_RAX]) 1331 if ((old_lo != _regs[VCPU_REGS_RAX])
1326 || (old_hi != _regs[VCPU_REGS_RDI])) { 1332 || (old_hi != _regs[VCPU_REGS_RDX])) {
1327 _regs[VCPU_REGS_RAX] = old_lo; 1333 _regs[VCPU_REGS_RAX] = old_lo;
1328 _regs[VCPU_REGS_RDX] = old_hi; 1334 _regs[VCPU_REGS_RDX] = old_hi;
1329 _eflags &= ~EFLG_ZF; 1335 _eflags &= ~EFLG_ZF;
diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c
index fb1edc1c9e..50914439d8 100644
--- a/drivers/leds/leds-s3c24xx.c
+++ b/drivers/leds/leds-s3c24xx.c
@@ -16,7 +16,7 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/leds.h> 17#include <linux/leds.h>
18 18
19#include <asm/arch/hardware.h> 19#include <asm/hardware.h>
20#include <asm/arch/regs-gpio.h> 20#include <asm/arch/regs-gpio.h>
21#include <asm/arch/leds-gpio.h> 21#include <asm/arch/leds-gpio.h>
22 22
diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
index 6c29fe727c..801a974342 100644
--- a/drivers/macintosh/via-pmu-backlight.c
+++ b/drivers/macintosh/via-pmu-backlight.c
@@ -147,7 +147,7 @@ void __init pmu_backlight_init()
147 147
148 snprintf(name, sizeof(name), "pmubl"); 148 snprintf(name, sizeof(name), "pmubl");
149 149
150 bd = backlight_device_register(name, NULL, &pmu_backlight_data); 150 bd = backlight_device_register(name, NULL, NULL, &pmu_backlight_data);
151 if (IS_ERR(bd)) { 151 if (IS_ERR(bd)) {
152 printk("pmubl: Backlight registration failed\n"); 152 printk("pmubl: Backlight registration failed\n");
153 goto error; 153 goto error;
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index c8558d4ed5..8ca75e52f6 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -44,6 +44,7 @@
44#include <linux/sysdev.h> 44#include <linux/sysdev.h>
45#include <linux/freezer.h> 45#include <linux/freezer.h>
46#include <linux/syscalls.h> 46#include <linux/syscalls.h>
47#include <linux/suspend.h>
47#include <linux/cpu.h> 48#include <linux/cpu.h>
48#include <asm/prom.h> 49#include <asm/prom.h>
49#include <asm/machdep.h> 50#include <asm/machdep.h>
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 5432d07c07..11108165e2 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -479,9 +479,12 @@ static int bitmap_read_sb(struct bitmap *bitmap)
479 int err = -EINVAL; 479 int err = -EINVAL;
480 480
481 /* page 0 is the superblock, read it... */ 481 /* page 0 is the superblock, read it... */
482 if (bitmap->file) 482 if (bitmap->file) {
483 bitmap->sb_page = read_page(bitmap->file, 0, bitmap, PAGE_SIZE); 483 loff_t isize = i_size_read(bitmap->file->f_mapping->host);
484 else { 484 int bytes = isize > PAGE_SIZE ? PAGE_SIZE : isize;
485
486 bitmap->sb_page = read_page(bitmap->file, 0, bitmap, bytes);
487 } else {
485 bitmap->sb_page = read_sb_page(bitmap->mddev, bitmap->offset, 0); 488 bitmap->sb_page = read_sb_page(bitmap->mddev, bitmap->offset, 0);
486 } 489 }
487 if (IS_ERR(bitmap->sb_page)) { 490 if (IS_ERR(bitmap->sb_page)) {
@@ -877,7 +880,8 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
877 int count; 880 int count;
878 /* unmap the old page, we're done with it */ 881 /* unmap the old page, we're done with it */
879 if (index == num_pages-1) 882 if (index == num_pages-1)
880 count = bytes - index * PAGE_SIZE; 883 count = bytes + sizeof(bitmap_super_t)
884 - index * PAGE_SIZE;
881 else 885 else
882 count = PAGE_SIZE; 886 count = PAGE_SIZE;
883 if (index == 0) { 887 if (index == 0) {
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index fe7c56e104..3668b170ea 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1116,7 +1116,8 @@ static int __bind(struct mapped_device *md, struct dm_table *t)
1116 if (size != get_capacity(md->disk)) 1116 if (size != get_capacity(md->disk))
1117 memset(&md->geometry, 0, sizeof(md->geometry)); 1117 memset(&md->geometry, 0, sizeof(md->geometry));
1118 1118
1119 __set_size(md, size); 1119 if (md->suspended_bdev)
1120 __set_size(md, size);
1120 if (size == 0) 1121 if (size == 0)
1121 return 0; 1122 return 0;
1122 1123
@@ -1264,6 +1265,11 @@ int dm_swap_table(struct mapped_device *md, struct dm_table *table)
1264 if (!dm_suspended(md)) 1265 if (!dm_suspended(md))
1265 goto out; 1266 goto out;
1266 1267
1268 /* without bdev, the device size cannot be changed */
1269 if (!md->suspended_bdev)
1270 if (get_capacity(md->disk) != dm_table_get_size(table))
1271 goto out;
1272
1267 __unbind(md); 1273 __unbind(md);
1268 r = __bind(md, table); 1274 r = __bind(md, table);
1269 1275
@@ -1341,11 +1347,14 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
1341 /* This does not get reverted if there's an error later. */ 1347 /* This does not get reverted if there's an error later. */
1342 dm_table_presuspend_targets(map); 1348 dm_table_presuspend_targets(map);
1343 1349
1344 md->suspended_bdev = bdget_disk(md->disk, 0); 1350 /* bdget() can stall if the pending I/Os are not flushed */
1345 if (!md->suspended_bdev) { 1351 if (!noflush) {
1346 DMWARN("bdget failed in dm_suspend"); 1352 md->suspended_bdev = bdget_disk(md->disk, 0);
1347 r = -ENOMEM; 1353 if (!md->suspended_bdev) {
1348 goto flush_and_out; 1354 DMWARN("bdget failed in dm_suspend");
1355 r = -ENOMEM;
1356 goto flush_and_out;
1357 }
1349 } 1358 }
1350 1359
1351 /* 1360 /*
@@ -1473,8 +1482,10 @@ int dm_resume(struct mapped_device *md)
1473 1482
1474 unlock_fs(md); 1483 unlock_fs(md);
1475 1484
1476 bdput(md->suspended_bdev); 1485 if (md->suspended_bdev) {
1477 md->suspended_bdev = NULL; 1486 bdput(md->suspended_bdev);
1487 md->suspended_bdev = NULL;
1488 }
1478 1489
1479 clear_bit(DMF_SUSPENDED, &md->flags); 1490 clear_bit(DMF_SUSPENDED, &md->flags);
1480 1491
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 21e2a7b088..e8807ea537 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1633,7 +1633,8 @@ repeat:
1633 * and 'events' is odd, we can roll back to the previous clean state */ 1633 * and 'events' is odd, we can roll back to the previous clean state */
1634 if (nospares 1634 if (nospares
1635 && (mddev->in_sync && mddev->recovery_cp == MaxSector) 1635 && (mddev->in_sync && mddev->recovery_cp == MaxSector)
1636 && (mddev->events & 1)) 1636 && (mddev->events & 1)
1637 && mddev->events != 1)
1637 mddev->events--; 1638 mddev->events--;
1638 else { 1639 else {
1639 /* otherwise we have to go forward and ... */ 1640 /* otherwise we have to go forward and ... */
@@ -1792,7 +1793,8 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1792 else { 1793 else {
1793 mddev_t *mddev = rdev->mddev; 1794 mddev_t *mddev = rdev->mddev;
1794 kick_rdev_from_array(rdev); 1795 kick_rdev_from_array(rdev);
1795 md_update_sb(mddev, 1); 1796 if (mddev->pers)
1797 md_update_sb(mddev, 1);
1796 md_new_event(mddev); 1798 md_new_event(mddev);
1797 err = 0; 1799 err = 0;
1798 } 1800 }
@@ -2004,6 +2006,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
2004 2006
2005 rdev->desc_nr = -1; 2007 rdev->desc_nr = -1;
2006 rdev->saved_raid_disk = -1; 2008 rdev->saved_raid_disk = -1;
2009 rdev->raid_disk = -1;
2007 rdev->flags = 0; 2010 rdev->flags = 0;
2008 rdev->data_offset = 0; 2011 rdev->data_offset = 0;
2009 rdev->sb_events = 0; 2012 rdev->sb_events = 0;
@@ -2233,7 +2236,6 @@ static int update_raid_disks(mddev_t *mddev, int raid_disks);
2233static ssize_t 2236static ssize_t
2234raid_disks_store(mddev_t *mddev, const char *buf, size_t len) 2237raid_disks_store(mddev_t *mddev, const char *buf, size_t len)
2235{ 2238{
2236 /* can only set raid_disks if array is not yet active */
2237 char *e; 2239 char *e;
2238 int rv = 0; 2240 int rv = 0;
2239 unsigned long n = simple_strtoul(buf, &e, 10); 2241 unsigned long n = simple_strtoul(buf, &e, 10);
@@ -2631,7 +2633,7 @@ metadata_store(mddev_t *mddev, const char *buf, size_t len)
2631 return -EINVAL; 2633 return -EINVAL;
2632 buf = e+1; 2634 buf = e+1;
2633 minor = simple_strtoul(buf, &e, 10); 2635 minor = simple_strtoul(buf, &e, 10);
2634 if (e==buf || *e != '\n') 2636 if (e==buf || (*e && *e != '\n') )
2635 return -EINVAL; 2637 return -EINVAL;
2636 if (major >= sizeof(super_types)/sizeof(super_types[0]) || 2638 if (major >= sizeof(super_types)/sizeof(super_types[0]) ||
2637 super_types[major].name == NULL) 2639 super_types[major].name == NULL)
@@ -3562,6 +3564,8 @@ static int get_bitmap_file(mddev_t * mddev, void __user * arg)
3562 char *ptr, *buf = NULL; 3564 char *ptr, *buf = NULL;
3563 int err = -ENOMEM; 3565 int err = -ENOMEM;
3564 3566
3567 md_allow_write(mddev);
3568
3565 file = kmalloc(sizeof(*file), GFP_KERNEL); 3569 file = kmalloc(sizeof(*file), GFP_KERNEL);
3566 if (!file) 3570 if (!file)
3567 goto out; 3571 goto out;
@@ -3980,6 +3984,7 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
3980 mddev->major_version = info->major_version; 3984 mddev->major_version = info->major_version;
3981 mddev->minor_version = info->minor_version; 3985 mddev->minor_version = info->minor_version;
3982 mddev->patch_version = info->patch_version; 3986 mddev->patch_version = info->patch_version;
3987 mddev->persistent = !info->not_persistent;
3983 return 0; 3988 return 0;
3984 } 3989 }
3985 mddev->major_version = MD_MAJOR_VERSION; 3990 mddev->major_version = MD_MAJOR_VERSION;
@@ -4304,9 +4309,10 @@ static int md_ioctl(struct inode *inode, struct file *file,
4304 * Commands querying/configuring an existing array: 4309 * Commands querying/configuring an existing array:
4305 */ 4310 */
4306 /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY, 4311 /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY,
4307 * RUN_ARRAY, and SET_BITMAP_FILE are allowed */ 4312 * RUN_ARRAY, and GET_ and SET_BITMAP_FILE are allowed */
4308 if (!mddev->raid_disks && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY 4313 if (!mddev->raid_disks && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY
4309 && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE) { 4314 && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE
4315 && cmd != GET_BITMAP_FILE) {
4310 err = -ENODEV; 4316 err = -ENODEV;
4311 goto abort_unlock; 4317 goto abort_unlock;
4312 } 4318 }
@@ -5028,6 +5034,33 @@ void md_write_end(mddev_t *mddev)
5028 } 5034 }
5029} 5035}
5030 5036
5037/* md_allow_write(mddev)
5038 * Calling this ensures that the array is marked 'active' so that writes
5039 * may proceed without blocking. It is important to call this before
5040 * attempting a GFP_KERNEL allocation while holding the mddev lock.
5041 * Must be called with mddev_lock held.
5042 */
5043void md_allow_write(mddev_t *mddev)
5044{
5045 if (!mddev->pers)
5046 return;
5047 if (mddev->ro)
5048 return;
5049
5050 spin_lock_irq(&mddev->write_lock);
5051 if (mddev->in_sync) {
5052 mddev->in_sync = 0;
5053 set_bit(MD_CHANGE_CLEAN, &mddev->flags);
5054 if (mddev->safemode_delay &&
5055 mddev->safemode == 0)
5056 mddev->safemode = 1;
5057 spin_unlock_irq(&mddev->write_lock);
5058 md_update_sb(mddev, 0);
5059 } else
5060 spin_unlock_irq(&mddev->write_lock);
5061}
5062EXPORT_SYMBOL_GPL(md_allow_write);
5063
5031static DECLARE_WAIT_QUEUE_HEAD(resync_wait); 5064static DECLARE_WAIT_QUEUE_HEAD(resync_wait);
5032 5065
5033#define SYNC_MARKS 10 5066#define SYNC_MARKS 10
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index b30f74be39..97ee870b26 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -775,6 +775,7 @@ static int make_request(request_queue_t *q, struct bio * bio)
775 struct bio_list bl; 775 struct bio_list bl;
776 struct page **behind_pages = NULL; 776 struct page **behind_pages = NULL;
777 const int rw = bio_data_dir(bio); 777 const int rw = bio_data_dir(bio);
778 const int do_sync = bio_sync(bio);
778 int do_barriers; 779 int do_barriers;
779 780
780 /* 781 /*
@@ -835,7 +836,7 @@ static int make_request(request_queue_t *q, struct bio * bio)
835 read_bio->bi_sector = r1_bio->sector + mirror->rdev->data_offset; 836 read_bio->bi_sector = r1_bio->sector + mirror->rdev->data_offset;
836 read_bio->bi_bdev = mirror->rdev->bdev; 837 read_bio->bi_bdev = mirror->rdev->bdev;
837 read_bio->bi_end_io = raid1_end_read_request; 838 read_bio->bi_end_io = raid1_end_read_request;
838 read_bio->bi_rw = READ; 839 read_bio->bi_rw = READ | do_sync;
839 read_bio->bi_private = r1_bio; 840 read_bio->bi_private = r1_bio;
840 841
841 generic_make_request(read_bio); 842 generic_make_request(read_bio);
@@ -906,7 +907,7 @@ static int make_request(request_queue_t *q, struct bio * bio)
906 mbio->bi_sector = r1_bio->sector + conf->mirrors[i].rdev->data_offset; 907 mbio->bi_sector = r1_bio->sector + conf->mirrors[i].rdev->data_offset;
907 mbio->bi_bdev = conf->mirrors[i].rdev->bdev; 908 mbio->bi_bdev = conf->mirrors[i].rdev->bdev;
908 mbio->bi_end_io = raid1_end_write_request; 909 mbio->bi_end_io = raid1_end_write_request;
909 mbio->bi_rw = WRITE | do_barriers; 910 mbio->bi_rw = WRITE | do_barriers | do_sync;
910 mbio->bi_private = r1_bio; 911 mbio->bi_private = r1_bio;
911 912
912 if (behind_pages) { 913 if (behind_pages) {
@@ -941,6 +942,8 @@ static int make_request(request_queue_t *q, struct bio * bio)
941 blk_plug_device(mddev->queue); 942 blk_plug_device(mddev->queue);
942 spin_unlock_irqrestore(&conf->device_lock, flags); 943 spin_unlock_irqrestore(&conf->device_lock, flags);
943 944
945 if (do_sync)
946 md_wakeup_thread(mddev->thread);
944#if 0 947#if 0
945 while ((bio = bio_list_pop(&bl)) != NULL) 948 while ((bio = bio_list_pop(&bl)) != NULL)
946 generic_make_request(bio); 949 generic_make_request(bio);
@@ -1263,6 +1266,11 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
1263 sbio->bi_sector = r1_bio->sector + 1266 sbio->bi_sector = r1_bio->sector +
1264 conf->mirrors[i].rdev->data_offset; 1267 conf->mirrors[i].rdev->data_offset;
1265 sbio->bi_bdev = conf->mirrors[i].rdev->bdev; 1268 sbio->bi_bdev = conf->mirrors[i].rdev->bdev;
1269 for (j = 0; j < vcnt ; j++)
1270 memcpy(page_address(sbio->bi_io_vec[j].bv_page),
1271 page_address(pbio->bi_io_vec[j].bv_page),
1272 PAGE_SIZE);
1273
1266 } 1274 }
1267 } 1275 }
1268 } 1276 }
@@ -1541,6 +1549,7 @@ static void raid1d(mddev_t *mddev)
1541 * We already have a nr_pending reference on these rdevs. 1549 * We already have a nr_pending reference on these rdevs.
1542 */ 1550 */
1543 int i; 1551 int i;
1552 const int do_sync = bio_sync(r1_bio->master_bio);
1544 clear_bit(R1BIO_BarrierRetry, &r1_bio->state); 1553 clear_bit(R1BIO_BarrierRetry, &r1_bio->state);
1545 clear_bit(R1BIO_Barrier, &r1_bio->state); 1554 clear_bit(R1BIO_Barrier, &r1_bio->state);
1546 for (i=0; i < conf->raid_disks; i++) 1555 for (i=0; i < conf->raid_disks; i++)
@@ -1561,7 +1570,7 @@ static void raid1d(mddev_t *mddev)
1561 conf->mirrors[i].rdev->data_offset; 1570 conf->mirrors[i].rdev->data_offset;
1562 bio->bi_bdev = conf->mirrors[i].rdev->bdev; 1571 bio->bi_bdev = conf->mirrors[i].rdev->bdev;
1563 bio->bi_end_io = raid1_end_write_request; 1572 bio->bi_end_io = raid1_end_write_request;
1564 bio->bi_rw = WRITE; 1573 bio->bi_rw = WRITE | do_sync;
1565 bio->bi_private = r1_bio; 1574 bio->bi_private = r1_bio;
1566 r1_bio->bios[i] = bio; 1575 r1_bio->bios[i] = bio;
1567 generic_make_request(bio); 1576 generic_make_request(bio);
@@ -1593,6 +1602,7 @@ static void raid1d(mddev_t *mddev)
1593 (unsigned long long)r1_bio->sector); 1602 (unsigned long long)r1_bio->sector);
1594 raid_end_bio_io(r1_bio); 1603 raid_end_bio_io(r1_bio);
1595 } else { 1604 } else {
1605 const int do_sync = bio_sync(r1_bio->master_bio);
1596 r1_bio->bios[r1_bio->read_disk] = 1606 r1_bio->bios[r1_bio->read_disk] =
1597 mddev->ro ? IO_BLOCKED : NULL; 1607 mddev->ro ? IO_BLOCKED : NULL;
1598 r1_bio->read_disk = disk; 1608 r1_bio->read_disk = disk;
@@ -1608,7 +1618,7 @@ static void raid1d(mddev_t *mddev)
1608 bio->bi_sector = r1_bio->sector + rdev->data_offset; 1618 bio->bi_sector = r1_bio->sector + rdev->data_offset;
1609 bio->bi_bdev = rdev->bdev; 1619 bio->bi_bdev = rdev->bdev;
1610 bio->bi_end_io = raid1_end_read_request; 1620 bio->bi_end_io = raid1_end_read_request;
1611 bio->bi_rw = READ; 1621 bio->bi_rw = READ | do_sync;
1612 bio->bi_private = r1_bio; 1622 bio->bi_private = r1_bio;
1613 unplug = 1; 1623 unplug = 1;
1614 generic_make_request(bio); 1624 generic_make_request(bio);
@@ -2094,6 +2104,8 @@ static int raid1_reshape(mddev_t *mddev)
2094 return -EINVAL; 2104 return -EINVAL;
2095 } 2105 }
2096 2106
2107 md_allow_write(mddev);
2108
2097 raid_disks = mddev->raid_disks + mddev->delta_disks; 2109 raid_disks = mddev->raid_disks + mddev->delta_disks;
2098 2110
2099 if (raid_disks < conf->raid_disks) { 2111 if (raid_disks < conf->raid_disks) {
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index f0141910bb..a9401c017e 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -782,6 +782,7 @@ static int make_request(request_queue_t *q, struct bio * bio)
782 int i; 782 int i;
783 int chunk_sects = conf->chunk_mask + 1; 783 int chunk_sects = conf->chunk_mask + 1;
784 const int rw = bio_data_dir(bio); 784 const int rw = bio_data_dir(bio);
785 const int do_sync = bio_sync(bio);
785 struct bio_list bl; 786 struct bio_list bl;
786 unsigned long flags; 787 unsigned long flags;
787 788
@@ -863,7 +864,7 @@ static int make_request(request_queue_t *q, struct bio * bio)
863 mirror->rdev->data_offset; 864 mirror->rdev->data_offset;
864 read_bio->bi_bdev = mirror->rdev->bdev; 865 read_bio->bi_bdev = mirror->rdev->bdev;
865 read_bio->bi_end_io = raid10_end_read_request; 866 read_bio->bi_end_io = raid10_end_read_request;
866 read_bio->bi_rw = READ; 867 read_bio->bi_rw = READ | do_sync;
867 read_bio->bi_private = r10_bio; 868 read_bio->bi_private = r10_bio;
868 869
869 generic_make_request(read_bio); 870 generic_make_request(read_bio);
@@ -909,7 +910,7 @@ static int make_request(request_queue_t *q, struct bio * bio)
909 conf->mirrors[d].rdev->data_offset; 910 conf->mirrors[d].rdev->data_offset;
910 mbio->bi_bdev = conf->mirrors[d].rdev->bdev; 911 mbio->bi_bdev = conf->mirrors[d].rdev->bdev;
911 mbio->bi_end_io = raid10_end_write_request; 912 mbio->bi_end_io = raid10_end_write_request;
912 mbio->bi_rw = WRITE; 913 mbio->bi_rw = WRITE | do_sync;
913 mbio->bi_private = r10_bio; 914 mbio->bi_private = r10_bio;
914 915
915 atomic_inc(&r10_bio->remaining); 916 atomic_inc(&r10_bio->remaining);
@@ -922,6 +923,9 @@ static int make_request(request_queue_t *q, struct bio * bio)
922 blk_plug_device(mddev->queue); 923 blk_plug_device(mddev->queue);
923 spin_unlock_irqrestore(&conf->device_lock, flags); 924 spin_unlock_irqrestore(&conf->device_lock, flags);
924 925
926 if (do_sync)
927 md_wakeup_thread(mddev->thread);
928
925 return 0; 929 return 0;
926} 930}
927 931
@@ -1563,6 +1567,7 @@ static void raid10d(mddev_t *mddev)
1563 (unsigned long long)r10_bio->sector); 1567 (unsigned long long)r10_bio->sector);
1564 raid_end_bio_io(r10_bio); 1568 raid_end_bio_io(r10_bio);
1565 } else { 1569 } else {
1570 const int do_sync = bio_sync(r10_bio->master_bio);
1566 rdev = conf->mirrors[mirror].rdev; 1571 rdev = conf->mirrors[mirror].rdev;
1567 if (printk_ratelimit()) 1572 if (printk_ratelimit())
1568 printk(KERN_ERR "raid10: %s: redirecting sector %llu to" 1573 printk(KERN_ERR "raid10: %s: redirecting sector %llu to"
@@ -1574,7 +1579,7 @@ static void raid10d(mddev_t *mddev)
1574 bio->bi_sector = r10_bio->devs[r10_bio->read_slot].addr 1579 bio->bi_sector = r10_bio->devs[r10_bio->read_slot].addr
1575 + rdev->data_offset; 1580 + rdev->data_offset;
1576 bio->bi_bdev = rdev->bdev; 1581 bio->bi_bdev = rdev->bdev;
1577 bio->bi_rw = READ; 1582 bio->bi_rw = READ | do_sync;
1578 bio->bi_private = r10_bio; 1583 bio->bi_private = r10_bio;
1579 bio->bi_end_io = raid10_end_read_request; 1584 bio->bi_end_io = raid10_end_read_request;
1580 unplug = 1; 1585 unplug = 1;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index be008f034a..467c16982d 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -405,6 +405,8 @@ static int resize_stripes(raid5_conf_t *conf, int newsize)
405 if (newsize <= conf->pool_size) 405 if (newsize <= conf->pool_size)
406 return 0; /* never bother to shrink */ 406 return 0; /* never bother to shrink */
407 407
408 md_allow_write(conf->mddev);
409
408 /* Step 1 */ 410 /* Step 1 */
409 sc = kmem_cache_create(conf->cache_name[1-conf->active_name], 411 sc = kmem_cache_create(conf->cache_name[1-conf->active_name],
410 sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), 412 sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev),
@@ -2678,7 +2680,7 @@ static int chunk_aligned_read(request_queue_t *q, struct bio * raid_bio)
2678 mdk_rdev_t *rdev; 2680 mdk_rdev_t *rdev;
2679 2681
2680 if (!in_chunk_boundary(mddev, raid_bio)) { 2682 if (!in_chunk_boundary(mddev, raid_bio)) {
2681 printk("chunk_aligned_read : non aligned\n"); 2683 PRINTK("chunk_aligned_read : non aligned\n");
2682 return 0; 2684 return 0;
2683 } 2685 }
2684 /* 2686 /*
@@ -3250,6 +3252,7 @@ raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
3250 else 3252 else
3251 break; 3253 break;
3252 } 3254 }
3255 md_allow_write(mddev);
3253 while (new > conf->max_nr_stripes) { 3256 while (new > conf->max_nr_stripes) {
3254 if (grow_one_stripe(conf)) 3257 if (grow_one_stripe(conf))
3255 conf->max_nr_stripes++; 3258 conf->max_nr_stripes++;
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c
index 8eaa88fd8b..9a8dd8764c 100644
--- a/drivers/media/common/ir-functions.c
+++ b/drivers/media/common/ir-functions.c
@@ -23,6 +23,7 @@
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/jiffies.h>
26#include <media/ir-common.h> 27#include <media/ir-common.h>
27 28
28/* -------------------------------------------------------------------------- */ 29/* -------------------------------------------------------------------------- */
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index ebf4dc5190..76e9c36597 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -605,7 +605,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
605 { &utype, sizeof utype }, 605 { &utype, sizeof utype },
606 { priv->ule_skb->data, priv->ule_skb->len - 4 } 606 { priv->ule_skb->data, priv->ule_skb->len - 4 }
607 }; 607 };
608 unsigned long ule_crc = ~0L, expected_crc; 608 u32 ule_crc = ~0L, expected_crc;
609 if (priv->ule_dbit) { 609 if (priv->ule_dbit) {
610 /* Set D-bit for CRC32 verification, 610 /* Set D-bit for CRC32 verification,
611 * if it was set originally. */ 611 * if it was set originally. */
@@ -618,7 +618,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
618 *((u8 *)priv->ule_skb->tail - 2) << 8 | 618 *((u8 *)priv->ule_skb->tail - 2) << 8 |
619 *((u8 *)priv->ule_skb->tail - 1); 619 *((u8 *)priv->ule_skb->tail - 1);
620 if (ule_crc != expected_crc) { 620 if (ule_crc != expected_crc) {
621 printk(KERN_WARNING "%lu: CRC32 check FAILED: %#lx / %#lx, SNDU len %d type %#x, ts_remain %d, next 2: %x.\n", 621 printk(KERN_WARNING "%lu: CRC32 check FAILED: %08x / %08x, SNDU len %d type %#x, ts_remain %d, next 2: %x.\n",
622 priv->ts_count, ule_crc, expected_crc, priv->ule_sndu_len, priv->ule_sndu_type, ts_remain, ts_remain > 2 ? *(unsigned short *)from_where : 0); 622 priv->ts_count, ule_crc, expected_crc, priv->ule_sndu_len, priv->ule_sndu_type, ts_remain, ts_remain > 2 ? *(unsigned short *)from_where : 0);
623 623
624#ifdef ULE_DEBUG 624#ifdef ULE_DEBUG
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
index d48622e76b..badc468170 100644
--- a/drivers/media/dvb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
@@ -90,9 +90,11 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
90 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle); 90 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle);
91 91
92 for (i = 0; i < ARRAY_SIZE(haupp_rc_keys); i++) { 92 for (i = 0; i < ARRAY_SIZE(haupp_rc_keys); i++) {
93 deb_rc("c: %x, d: %x\n",haupp_rc_keys[i].data,haupp_rc_keys[i].custom);
94 if (haupp_rc_keys[i].data == data && 93 if (haupp_rc_keys[i].data == data &&
95 haupp_rc_keys[i].custom == custom) { 94 haupp_rc_keys[i].custom == custom) {
95
96 deb_rc("c: %x, d: %x\n",haupp_rc_keys[i].data,haupp_rc_keys[i].custom);
97
96 *event = haupp_rc_keys[i].event; 98 *event = haupp_rc_keys[i].event;
97 *state = REMOTE_KEY_PRESSED; 99 *state = REMOTE_KEY_PRESSED;
98 if (st->old_toggle == toggle) { 100 if (st->old_toggle == toggle) {
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index 5da6617800..23aa75a27c 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -515,7 +515,7 @@ static int dib3000mc_autosearch_start(struct dvb_frontend *demod, struct dibx000
515 fchan.vit_alpha = 1; fchan.vit_code_rate_hp = 2; fchan.vit_code_rate_lp = 2; 515 fchan.vit_alpha = 1; fchan.vit_code_rate_hp = 2; fchan.vit_code_rate_lp = 2;
516 fchan.vit_hrch = 0; fchan.vit_select_hp = 1; 516 fchan.vit_hrch = 0; fchan.vit_select_hp = 1;
517 517
518 dib3000mc_set_channel_cfg(state, &fchan, 7); 518 dib3000mc_set_channel_cfg(state, &fchan, 11);
519 519
520 reg = dib3000mc_read_word(state, 0); 520 reg = dib3000mc_read_word(state, 0);
521 dib3000mc_write_word(state, 0, reg | (1 << 8)); 521 dib3000mc_write_word(state, 0, reg | (1 << 8));
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 29a11c1db1..57357db31b 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -668,7 +668,7 @@ config VIDEO_M32R_AR_M64278
668 668
669config VIDEO_CAFE_CCIC 669config VIDEO_CAFE_CCIC
670 tristate "Marvell 88ALP01 (Cafe) CMOS Camera Controller support" 670 tristate "Marvell 88ALP01 (Cafe) CMOS Camera Controller support"
671 depends on I2C && VIDEO_V4L2 671 depends on PCI && I2C && VIDEO_V4L2
672 select VIDEO_OV7670 672 select VIDEO_OV7670
673 ---help--- 673 ---help---
674 This is a video4linux2 driver for the Marvell 88ALP01 integrated 674 This is a video4linux2 driver for the Marvell 88ALP01 integrated
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 3c8e4742dc..ab8f970760 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -4050,8 +4050,8 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4050 (unsigned long long)pci_resource_start(dev,0)); 4050 (unsigned long long)pci_resource_start(dev,0));
4051 schedule(); 4051 schedule();
4052 4052
4053 btv->bt848_mmio=ioremap(pci_resource_start(dev,0), 0x1000); 4053 btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
4054 if (NULL == ioremap(pci_resource_start(dev,0), 0x1000)) { 4054 if (NULL == btv->bt848_mmio) {
4055 printk("bttv%d: ioremap() failed\n", btv->c.nr); 4055 printk("bttv%d: ioremap() failed\n", btv->c.nr);
4056 result = -EIO; 4056 result = -EIO;
4057 goto fail1; 4057 goto fail1;
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index e347c7ebc9..3083c8075d 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -2166,7 +2166,7 @@ static void cafe_pci_remove(struct pci_dev *pdev)
2166 struct cafe_camera *cam = cafe_find_by_pdev(pdev); 2166 struct cafe_camera *cam = cafe_find_by_pdev(pdev);
2167 2167
2168 if (cam == NULL) { 2168 if (cam == NULL) {
2169 cam_warn(cam, "pci_remove on unknown pdev %p\n", pdev); 2169 printk(KERN_WARNING "pci_remove on unknown pdev %p\n", pdev);
2170 return; 2170 return;
2171 } 2171 }
2172 mutex_lock(&cam->s_mutex); 2172 mutex_lock(&cam->s_mutex);
diff --git a/drivers/media/video/cpia2/cpia2_usb.c b/drivers/media/video/cpia2/cpia2_usb.c
index 28dc6a1a1e..d8e929863a 100644
--- a/drivers/media/video/cpia2/cpia2_usb.c
+++ b/drivers/media/video/cpia2/cpia2_usb.c
@@ -640,6 +640,10 @@ static int submit_urbs(struct camera_data *cam)
640 cam->sbuf[i].data = 640 cam->sbuf[i].data =
641 kmalloc(FRAMES_PER_DESC * FRAME_SIZE_PER_DESC, GFP_KERNEL); 641 kmalloc(FRAMES_PER_DESC * FRAME_SIZE_PER_DESC, GFP_KERNEL);
642 if (!cam->sbuf[i].data) { 642 if (!cam->sbuf[i].data) {
643 while (--i >= 0) {
644 kfree(cam->sbuf[i].data);
645 cam->sbuf[i].data = NULL;
646 }
643 return -ENOMEM; 647 return -ENOMEM;
644 } 648 }
645 } 649 }
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 657e0b9691..2f5ca71e02 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -742,7 +742,6 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
742 742
743 if (old == NULL || old->width != new->width || old->height != new->height || 743 if (old == NULL || old->width != new->width || old->height != new->height ||
744 old->video_encoding != new->video_encoding) { 744 old->video_encoding != new->video_encoding) {
745 int is_scaling;
746 u16 w = new->width; 745 u16 w = new->width;
747 u16 h = new->height; 746 u16 h = new->height;
748 747
@@ -752,20 +751,18 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
752 } 751 }
753 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_SIZE, 2, h, w); 752 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_SIZE, 2, h, w);
754 if (err) return err; 753 if (err) return err;
754 }
755 755
756 if (new->width != 720 || new->height != (new->is_50hz ? 576 : 480)) {
756 /* Adjust temporal filter if necessary. The problem with the temporal 757 /* Adjust temporal filter if necessary. The problem with the temporal
757 filter is that it works well with full resolution capturing, but 758 filter is that it works well with full resolution capturing, but
758 not when the capture window is scaled (the filter introduces 759 not when the capture window is scaled (the filter introduces
759 a ghosting effect). So if the capture window changed, and there is 760 a ghosting effect). So if the capture window is scaled, then
760 no updated filter value, then the filter is set depending on whether 761 force the filter to 0.
761 the new window is full resolution or not.
762 762
763 For full resolution a setting of 8 really improves the video 763 For full resolution the filter really improves the video
764 quality, especially if the original video quality is suboptimal. */ 764 quality, especially if the original video quality is suboptimal. */
765 is_scaling = new->width != 720 || new->height != (new->is_50hz ? 576 : 480); 765 temporal = 0;
766 if (old && old->video_temporal_filter == temporal) {
767 temporal = is_scaling ? 0 : 8;
768 }
769 } 766 }
770 767
771 if (old == NULL || old->stream_type != new->stream_type) { 768 if (old == NULL || old->stream_type != new->stream_type) {
@@ -866,6 +863,7 @@ invalid:
866void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix) 863void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix)
867{ 864{
868 int is_mpeg1 = p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1; 865 int is_mpeg1 = p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
866 int temporal = p->video_temporal_filter;
869 867
870 /* Stream */ 868 /* Stream */
871 printk(KERN_INFO "%s: Stream: %s\n", 869 printk(KERN_INFO "%s: Stream: %s\n",
@@ -922,10 +920,13 @@ void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix)
922 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE), 920 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE),
923 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE), 921 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE),
924 p->video_spatial_filter); 922 p->video_spatial_filter);
923 if (p->width != 720 || p->height != (p->is_50hz ? 576 : 480)) {
924 temporal = 0;
925 }
925 printk(KERN_INFO "%s: Temporal Filter: %s, %d\n", 926 printk(KERN_INFO "%s: Temporal Filter: %s, %d\n",
926 prefix, 927 prefix,
927 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE), 928 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE),
928 p->video_temporal_filter); 929 temporal);
929 printk(KERN_INFO "%s: Median Filter: %s, Luma [%d, %d], Chroma [%d, %d]\n", 930 printk(KERN_INFO "%s: Median Filter: %s, Luma [%d, %d], Chroma [%d, %d]\n",
930 prefix, 931 prefix,
931 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE), 932 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE),
diff --git a/drivers/media/video/cx25840/cx25840-vbi.c b/drivers/media/video/cx25840/cx25840-vbi.c
index f85f208432..ced13febed 100644
--- a/drivers/media/video/cx25840/cx25840-vbi.c
+++ b/drivers/media/video/cx25840/cx25840-vbi.c
@@ -128,7 +128,14 @@ void cx25840_vbi_setup(struct i2c_client *client)
128 uv_lpf=1; 128 uv_lpf=1;
129 129
130 src_decimation=0x21f; 130 src_decimation=0x21f;
131 if (std == V4L2_STD_PAL_M) { 131 if (std == V4L2_STD_PAL_60) {
132 vblank=26;
133 vblank656=26;
134 burst=0x5b;
135 luma_lpf=2;
136 comb=0x20;
137 sc=0x0a8263;
138 } else if (std == V4L2_STD_PAL_M) {
132 vblank=20; 139 vblank=20;
133 vblank656=24; 140 vblank656=24;
134 burst=0x61; 141 burst=0x61;
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index c791708b13..434b78ab37 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1632,7 +1632,7 @@ const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids);
1632/* ----------------------------------------------------------------------- */ 1632/* ----------------------------------------------------------------------- */
1633/* some leadtek specific stuff */ 1633/* some leadtek specific stuff */
1634 1634
1635static void __devinit leadtek_eeprom(struct cx88_core *core, u8 *eeprom_data) 1635static void leadtek_eeprom(struct cx88_core *core, u8 *eeprom_data)
1636{ 1636{
1637 /* This is just for the "Winfast 2000XP Expert" board ATM; I don't have data on 1637 /* This is just for the "Winfast 2000XP Expert" board ATM; I don't have data on
1638 * any others. 1638 * any others.
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 453af5e943..18997361c7 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -633,12 +633,12 @@ int cx88_reset(struct cx88_core *core)
633 633
634static unsigned int inline norm_swidth(struct cx88_tvnorm *norm) 634static unsigned int inline norm_swidth(struct cx88_tvnorm *norm)
635{ 635{
636 return (norm->id & V4L2_STD_625_50) ? 922 : 754; 636 return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 754 : 922;
637} 637}
638 638
639static unsigned int inline norm_hdelay(struct cx88_tvnorm *norm) 639static unsigned int inline norm_hdelay(struct cx88_tvnorm *norm)
640{ 640{
641 return (norm->id & V4L2_STD_625_50) ? 186 : 135; 641 return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 135 : 186;
642} 642}
643 643
644static unsigned int inline norm_vdelay(struct cx88_tvnorm *norm) 644static unsigned int inline norm_vdelay(struct cx88_tvnorm *norm)
@@ -648,24 +648,33 @@ static unsigned int inline norm_vdelay(struct cx88_tvnorm *norm)
648 648
649static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm) 649static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm)
650{ 650{
651 static const unsigned int ntsc = 28636360;
652 static const unsigned int pal = 35468950;
653 static const unsigned int palm = 28604892;
654
655 if (norm->id & V4L2_STD_PAL_M) 651 if (norm->id & V4L2_STD_PAL_M)
656 return palm; 652 return 28604892; // 3.575611 MHz
653
654 if (norm->id & (V4L2_STD_PAL_Nc))
655 return 28656448; // 3.582056 MHz
656
657 if (norm->id & V4L2_STD_NTSC) // All NTSC/M and variants
658 return 28636360; // 3.57954545 MHz +/- 10 Hz
657 659
658 return (norm->id & V4L2_STD_625_50) ? pal : ntsc; 660 /* SECAM have also different sub carrier for chroma,
661 but step_db and step_dr, at cx88_set_tvnorm already handles that.
662
663 The same FSC applies to PAL/BGDKIH, PAL/60, NTSC/4.43 and PAL/N
664 */
665
666 return 35468950; // 4.43361875 MHz +/- 5 Hz
659} 667}
660 668
661static unsigned int inline norm_htotal(struct cx88_tvnorm *norm) 669static unsigned int inline norm_htotal(struct cx88_tvnorm *norm)
662{ 670{
663 /* Should always be Line Draw Time / (4*FSC) */
664 671
665 if (norm->id & V4L2_STD_PAL_M) 672 unsigned int fsc4=norm_fsc8(norm)/2;
666 return 909;
667 673
668 return (norm->id & V4L2_STD_625_50) ? 1135 : 910; 674 /* returns 4*FSC / vtotal / frames per seconds */
675 return (norm->id & V4L2_STD_625_50) ?
676 ((fsc4+312)/625+12)/25 :
677 ((fsc4+262)/525*1001+15000)/30000;
669} 678}
670 679
671static unsigned int inline norm_vbipack(struct cx88_tvnorm *norm) 680static unsigned int inline norm_vbipack(struct cx88_tvnorm *norm)
@@ -692,7 +701,7 @@ int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int heig
692 value &= 0x3fe; 701 value &= 0x3fe;
693 cx_write(MO_HDELAY_EVEN, value); 702 cx_write(MO_HDELAY_EVEN, value);
694 cx_write(MO_HDELAY_ODD, value); 703 cx_write(MO_HDELAY_ODD, value);
695 dprintk(1,"set_scale: hdelay 0x%04x\n", value); 704 dprintk(1,"set_scale: hdelay 0x%04x (width %d)\n", value,swidth);
696 705
697 value = (swidth * 4096 / width) - 4096; 706 value = (swidth * 4096 / width) - 4096;
698 cx_write(MO_HSCALE_EVEN, value); 707 cx_write(MO_HSCALE_EVEN, value);
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index 3482e0114d..2bd84d351a 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -38,6 +38,7 @@
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/moduleparam.h> 39#include <linux/moduleparam.h>
40#include <linux/errno.h> 40#include <linux/errno.h>
41#include <linux/freezer.h>
41#include <linux/kernel.h> 42#include <linux/kernel.h>
42#include <linux/slab.h> 43#include <linux/slab.h>
43#include <linux/mm.h> 44#include <linux/mm.h>
@@ -961,6 +962,7 @@ int cx88_audio_thread(void *data)
961 msleep_interruptible(1000); 962 msleep_interruptible(1000);
962 if (kthread_should_stop()) 963 if (kthread_should_stop())
963 break; 964 break;
965 try_to_freeze();
964 966
965 /* just monitor the audio status for now ... */ 967 /* just monitor the audio status for now ... */
966 memset(&t, 0, sizeof(t)); 968 memset(&t, 0, sizeof(t));
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 7054e941f1..a9575ad8ca 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -91,7 +91,7 @@ struct cx88_tvnorm {
91 91
92static unsigned int inline norm_maxw(struct cx88_tvnorm *norm) 92static unsigned int inline norm_maxw(struct cx88_tvnorm *norm)
93{ 93{
94 return (norm->id & V4L2_STD_625_50) ? 768 : 640; 94 return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 720 : 768;
95} 95}
96 96
97 97
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 2a461dde48..36e72c207a 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -1674,9 +1674,9 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1674 if (dev->has_msp34xx) { 1674 if (dev->has_msp34xx) {
1675 /* Send a reset to other chips via gpio */ 1675 /* Send a reset to other chips via gpio */
1676 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1); 1676 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
1677 udelay(2500); 1677 msleep(3);
1678 em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1); 1678 em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
1679 udelay(2500); 1679 msleep(3);
1680 1680
1681 } 1681 }
1682 video_mux(dev, 0); 1682 video_mux(dev, 0);
diff --git a/drivers/media/video/ks0127.c b/drivers/media/video/ks0127.c
index c1a377f797..b6cd21e6da 100644
--- a/drivers/media/video/ks0127.c
+++ b/drivers/media/video/ks0127.c
@@ -712,13 +712,13 @@ static int ks0127_command(struct i2c_client *client,
712 *iarg = 0; 712 *iarg = 0;
713 status = ks0127_read(ks, KS_STAT); 713 status = ks0127_read(ks, KS_STAT);
714 if (!(status & 0x20)) /* NOVID not set */ 714 if (!(status & 0x20)) /* NOVID not set */
715 *iarg = (*iarg & DECODER_STATUS_GOOD); 715 *iarg = (*iarg | DECODER_STATUS_GOOD);
716 if ((status & 0x01)) /* CLOCK set */ 716 if ((status & 0x01)) /* CLOCK set */
717 *iarg = (*iarg & DECODER_STATUS_COLOR); 717 *iarg = (*iarg | DECODER_STATUS_COLOR);
718 if ((status & 0x08)) /* PALDET set */ 718 if ((status & 0x08)) /* PALDET set */
719 *iarg = (*iarg & DECODER_STATUS_PAL); 719 *iarg = (*iarg | DECODER_STATUS_PAL);
720 else 720 else
721 *iarg = (*iarg & DECODER_STATUS_NTSC); 721 *iarg = (*iarg | DECODER_STATUS_NTSC);
722 break; 722 break;
723 723
724 //Catch any unknown command 724 //Catch any unknown command
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index b083338823..616a35da19 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -923,7 +923,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
923 struct video_picture *p = arg; 923 struct video_picture *p = arg;
924 if (p->depth != 16) 924 if (p->depth != 16)
925 return -EINVAL; 925 return -EINVAL;
926 if (p->palette != VIDEO_PALETTE_YUV422) 926 if (p->palette != VIDEO_PALETTE_YUV422 && p->palette != VIDEO_PALETTE_YUYV)
927 return -EINVAL; 927 return -EINVAL;
928 mutex_lock(&meye.lock); 928 mutex_lock(&meye.lock);
929 sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS, 929 sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS,
@@ -978,7 +978,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
978 978
979 if (vm->frame >= gbuffers || vm->frame < 0) 979 if (vm->frame >= gbuffers || vm->frame < 0)
980 return -EINVAL; 980 return -EINVAL;
981 if (vm->format != VIDEO_PALETTE_YUV422) 981 if (vm->format != VIDEO_PALETTE_YUV422 && vm->format != VIDEO_PALETTE_YUYV)
982 return -EINVAL; 982 return -EINVAL;
983 if (vm->height * vm->width * 2 > gbufsize) 983 if (vm->height * vm->width * 2 > gbufsize)
984 return -EINVAL; 984 return -EINVAL;
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index e1b56dc13c..2fb9fe6a1a 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -633,10 +633,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
633 if (((rt->input >> (4 + i * 4)) & 0xf) == 0) 633 if (((rt->input >> (4 + i * 4)) & 0xf) == 0)
634 extern_input = 0; 634 extern_input = 0;
635 } 635 }
636 if (extern_input) 636 state->mode = extern_input ? MSP_MODE_EXTERN : MSP_MODE_AM_DETECT;
637 state->mode = MSP_MODE_EXTERN; 637 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
638 else
639 state->mode = MSP_MODE_AM_DETECT;
640 msp_set_scart(client, sc_in, 0); 638 msp_set_scart(client, sc_in, 0);
641 msp_set_scart(client, sc1_out, 1); 639 msp_set_scart(client, sc1_out, 1);
642 msp_set_scart(client, sc2_out, 2); 640 msp_set_scart(client, sc2_out, 2);
@@ -951,7 +949,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
951 if (thread_func) { 949 if (thread_func) {
952 state->kthread = kthread_run(thread_func, client, "msp34xx"); 950 state->kthread = kthread_run(thread_func, client, "msp34xx");
953 951
954 if (state->kthread == NULL) 952 if (IS_ERR(state->kthread))
955 v4l_warn(client, "kernel_thread() failed\n"); 953 v4l_warn(client, "kernel_thread() failed\n");
956 msp_wake_thread(client); 954 msp_wake_thread(client);
957 } 955 }
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index 4c7f85b566..e1821eb82f 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -483,7 +483,6 @@ int msp3400c_thread(void *data)
483 /* no carrier scan, just unmute */ 483 /* no carrier scan, just unmute */
484 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); 484 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n");
485 state->scan_in_progress = 0; 485 state->scan_in_progress = 0;
486 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
487 msp_set_audio(client); 486 msp_set_audio(client);
488 continue; 487 continue;
489 } 488 }
@@ -851,12 +850,15 @@ static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in)
851 source = 1; /* stereo or A|B */ 850 source = 1; /* stereo or A|B */
852 matrix = 0x20; 851 matrix = 0x20;
853 break; 852 break;
854 case V4L2_TUNER_MODE_STEREO:
855 case V4L2_TUNER_MODE_LANG1: 853 case V4L2_TUNER_MODE_LANG1:
856 default:
857 source = 3; /* stereo or A */ 854 source = 3; /* stereo or A */
858 matrix = 0x00; 855 matrix = 0x00;
859 break; 856 break;
857 case V4L2_TUNER_MODE_STEREO:
858 default:
859 source = 3; /* stereo or A */
860 matrix = 0x20;
861 break;
860 } 862 }
861 863
862 if (in == MSP_DSP_IN_TUNER) 864 if (in == MSP_DSP_IN_TUNER)
@@ -1030,6 +1032,9 @@ static int msp34xxg_detect_stereo(struct i2c_client *client)
1030 int is_stereo = status & 0x40; 1032 int is_stereo = status & 0x40;
1031 int oldrx = state->rxsubchans; 1033 int oldrx = state->rxsubchans;
1032 1034
1035 if (state->mode == MSP_MODE_EXTERN)
1036 return 0;
1037
1033 state->rxsubchans = 0; 1038 state->rxsubchans = 0;
1034 if (is_stereo) 1039 if (is_stereo)
1035 state->rxsubchans = V4L2_TUNER_SUB_STEREO; 1040 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 4dead84aff..ae984bbe36 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -2570,6 +2570,7 @@ struct saa7134_board saa7134_boards[] = {
2570 .radio_type = UNSET, 2570 .radio_type = UNSET,
2571 .tuner_addr = ADDR_UNSET, 2571 .tuner_addr = ADDR_UNSET,
2572 .radio_addr = ADDR_UNSET, 2572 .radio_addr = ADDR_UNSET,
2573 .gpiomask = 1 << 21,
2573 .inputs = {{ 2574 .inputs = {{
2574 .name = name_tv, 2575 .name = name_tv,
2575 .vmux = 1, 2576 .vmux = 1,
@@ -2578,15 +2579,20 @@ struct saa7134_board saa7134_boards[] = {
2578 },{ 2579 },{
2579 .name = name_comp1, 2580 .name = name_comp1,
2580 .vmux = 3, 2581 .vmux = 3,
2581 .amux = LINE1, 2582 .amux = LINE2, /* unconfirmed, taken from Philips driver */
2583 },{
2584 .name = name_comp2,
2585 .vmux = 0, /* untested, Composite over S-Video */
2586 .amux = LINE2,
2582 },{ 2587 },{
2583 .name = name_svideo, 2588 .name = name_svideo,
2584 .vmux = 0, 2589 .vmux = 8,
2585 .amux = LINE1, 2590 .amux = LINE2,
2586 }}, 2591 }},
2587 .radio = { 2592 .radio = {
2588 .name = name_radio, 2593 .name = name_radio,
2589 .amux = LINE1, 2594 .amux = TV,
2595 .gpio = 0x0200000,
2590 }, 2596 },
2591 }, 2597 },
2592 [SAA7134_BOARD_CINERGY250PCI] = { 2598 [SAA7134_BOARD_CINERGY250PCI] = {
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index fa83398790..c33f6a69a2 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -50,9 +50,9 @@ static unsigned int antenna_pwr = 0;
50module_param(antenna_pwr, int, 0444); 50module_param(antenna_pwr, int, 0444);
51MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)"); 51MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
52 52
53static int use_frontent = 0; 53static int use_frontend = 0;
54module_param(use_frontent, int, 0644); 54module_param(use_frontend, int, 0644);
55MODULE_PARM_DESC(use_frontent,"for cards with multiple frontends (0: terrestrial, 1: satellite)"); 55MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
56 56
57/* ------------------------------------------------------------------ */ 57/* ------------------------------------------------------------------ */
58static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on) 58static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
@@ -1303,7 +1303,7 @@ static int dvb_init(struct saa7134_dev *dev)
1303 } 1303 }
1304 break; 1304 break;
1305 case SAA7134_BOARD_FLYDVB_TRIO: 1305 case SAA7134_BOARD_FLYDVB_TRIO:
1306 if(! use_frontent) { //terrestrial 1306 if(! use_frontend) { //terrestrial
1307 dev->dvb.frontend = dvb_attach(tda10046_attach, 1307 dev->dvb.frontend = dvb_attach(tda10046_attach,
1308 &lifeview_trio_config, 1308 &lifeview_trio_config,
1309 &dev->i2c_adap); 1309 &dev->i2c_adap);
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 705daaa2a4..ee4a493032 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -267,6 +267,10 @@ static int tuner_fixup_std(struct tuner *t)
267{ 267{
268 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) { 268 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) {
269 switch (pal[0]) { 269 switch (pal[0]) {
270 case '6':
271 tuner_dbg ("insmod fixup: PAL => PAL-60\n");
272 t->std = V4L2_STD_PAL_60;
273 break;
270 case 'b': 274 case 'b':
271 case 'B': 275 case 'B':
272 case 'g': 276 case 'g':
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 2624e3f7dd..4e7c1fa668 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -184,7 +184,7 @@ hauppauge_tuner[] =
184 { TUNER_ABSENT, "Thompson DTT757"}, 184 { TUNER_ABSENT, "Thompson DTT757"},
185 /* 80-89 */ 185 /* 80-89 */
186 { TUNER_ABSENT, "Philips FQ1216LME MK3"}, 186 { TUNER_ABSENT, "Philips FQ1216LME MK3"},
187 { TUNER_ABSENT, "LG TAPC G701D"}, 187 { TUNER_LG_PAL_NEW_TAPC, "LG TAPC G701D"},
188 { TUNER_LG_NTSC_NEW_TAPC, "LG TAPC H791F"}, 188 { TUNER_LG_NTSC_NEW_TAPC, "LG TAPC H791F"},
189 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MB 3"}, 189 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MB 3"},
190 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MI 3"}, 190 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MI 3"},
diff --git a/drivers/media/video/usbvideo/quickcam_messenger.h b/drivers/media/video/usbvideo/quickcam_messenger.h
index baab9c081b..17ace394d9 100644
--- a/drivers/media/video/usbvideo/quickcam_messenger.h
+++ b/drivers/media/video/usbvideo/quickcam_messenger.h
@@ -35,27 +35,13 @@ struct rgb {
35}; 35};
36 36
37struct bayL0 { 37struct bayL0 {
38#ifdef __BIG_ENDIAN
39 u8 r;
40 u8 g;
41#elif __LITTLE_ENDIAN
42 u8 g; 38 u8 g;
43 u8 r; 39 u8 r;
44#else
45#error not byte order defined
46#endif
47}; 40};
48 41
49struct bayL1 { 42struct bayL1 {
50#ifdef __BIG_ENDIAN
51 u8 g;
52 u8 b;
53#elif __LITTLE_ENDIAN
54 u8 b; 43 u8 b;
55 u8 g; 44 u8 g;
56#else
57#error not byte order defined
58#endif
59}; 45};
60 46
61struct cam_size { 47struct cam_size {
diff --git a/drivers/media/video/usbvision/usbvision-cards.c b/drivers/media/video/usbvision/usbvision-cards.c
index 134eb9865d..a40e583851 100644
--- a/drivers/media/video/usbvision/usbvision-cards.c
+++ b/drivers/media/video/usbvision/usbvision-cards.c
@@ -39,8 +39,8 @@ struct usbvision_device_data_st usbvision_device_data[] = {
39 {0x0573, 0x0400, -1, CODEC_SAA7113, 4, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "D-Link V100"}, 39 {0x0573, 0x0400, -1, CODEC_SAA7113, 4, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "D-Link V100"},
40 {0x0573, 0x2000, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, -1, -1, -1, "X10 USB Camera"}, 40 {0x0573, 0x2000, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, -1, -1, -1, "X10 USB Camera"},
41 {0x0573, 0x2d00, -1, CODEC_SAA7111, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, -1, 3, 7, "Osprey 50"}, 41 {0x0573, 0x2d00, -1, CODEC_SAA7111, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, -1, 3, 7, "Osprey 50"},
42 {0x0573, 0x2d01, -1, CODEC_SAA7113, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Hauppauge USB-Live Model 600"}, 42 {0x0573, 0x2d01, -1, CODEC_SAA7113, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Hauppauge USB-Live Model 600"},
43 {0x0573, 0x2101, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 2, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Zoran Co. PMD (Nogatech) AV-grabber Manhattan"}, 43 {0x0573, 0x2101, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 2, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Zoran Co. PMD (Nogatech) AV-grabber Manhattan"},
44 {0x0573, 0x4100, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "Nogatech USB-TV (NTSC) FM"}, 44 {0x0573, 0x4100, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "Nogatech USB-TV (NTSC) FM"},
45 {0x0573, 0x4110, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "PNY USB-TV (NTSC) FM"}, 45 {0x0573, 0x4110, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "PNY USB-TV (NTSC) FM"},
46 {0x0573, 0x4450, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "PixelView PlayTv-USB PRO (PAL) FM"}, 46 {0x0573, 0x4450, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "PixelView PlayTv-USB PRO (PAL) FM"},
@@ -71,10 +71,10 @@ struct usbvision_device_data_st usbvision_device_data[] = {
71 {0x0573, 0x4d37, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_FM1216ME_MK3, -1, -1, 0, 3, 7, "Hauppauge WinTV USB device Model 40219 Rev E189"}, 71 {0x0573, 0x4d37, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_FM1216ME_MK3, -1, -1, 0, 3, 7, "Hauppauge WinTV USB device Model 40219 Rev E189"},
72 {0x0768, 0x0006, -1, CODEC_SAA7113, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, 5, 5, -1, "Camtel Technology USB TV Genie Pro FM Model TVB330"}, 72 {0x0768, 0x0006, -1, CODEC_SAA7113, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, 5, 5, -1, "Camtel Technology USB TV Genie Pro FM Model TVB330"},
73 {0x07d0, 0x0001, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Digital Video Creator I"}, 73 {0x07d0, 0x0001, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Digital Video Creator I"},
74 {0x07d0, 0x0002, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 82, 20, 7, "Global Village GV-007 (NTSC)"}, 74 {0x07d0, 0x0002, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 82, 20, 7, "Global Village GV-007 (NTSC)"},
75 {0x07d0, 0x0003, 0, CODEC_SAA7113, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-50 Rev 1 (NTSC)"}, 75 {0x07d0, 0x0003, 0, CODEC_SAA7113, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-50 Rev 1 (NTSC)"},
76 {0x07d0, 0x0004, 0, CODEC_SAA7113, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-80 Rev 1 (PAL)"}, 76 {0x07d0, 0x0004, 0, CODEC_SAA7113, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-80 Rev 1 (PAL)"},
77 {0x07d0, 0x0005, 0, CODEC_SAA7113, 2, V4L2_STD_SECAM, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-90 Rev 1 (SECAM)"}, 77 {0x07d0, 0x0005, 0, CODEC_SAA7113, 2, V4L2_STD_SECAM, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-90 Rev 1 (SECAM)"},
78 {0x2304, 0x010d, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 0, 0, 1, TUNER_TEMIC_4066FY5_PAL_I, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (PAL)"}, 78 {0x2304, 0x010d, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 0, 0, 1, TUNER_TEMIC_4066FY5_PAL_I, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (PAL)"},
79 {0x2304, 0x0109, -1, CODEC_SAA7111, 3, V4L2_STD_SECAM, 1, 0, 1, 1, TUNER_PHILIPS_SECAM, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (SECAM)"}, 79 {0x2304, 0x0109, -1, CODEC_SAA7111, 3, V4L2_STD_SECAM, 1, 0, 1, 1, TUNER_PHILIPS_SECAM, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (SECAM)"},
80 {0x2304, 0x0110, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1,128, 23, -1, "Pinnacle Studio PCTV USB (PAL) FM"}, 80 {0x2304, 0x0110, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1,128, 23, -1, "Pinnacle Studio PCTV USB (PAL) FM"},
@@ -86,7 +86,7 @@ struct usbvision_device_data_st usbvision_device_data[] = {
86 {0x2304, 0x0300, -1, CODEC_SAA7113, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Pinnacle Studio Linx Video input cable (NTSC)"}, 86 {0x2304, 0x0300, -1, CODEC_SAA7113, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Pinnacle Studio Linx Video input cable (NTSC)"},
87 {0x2304, 0x0301, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Pinnacle Studio Linx Video input cable (PAL)"}, 87 {0x2304, 0x0301, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Pinnacle Studio Linx Video input cable (PAL)"},
88 {0x2304, 0x0419, -1, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_TEMIC_4009FR5_PAL, -1, -1, 0, 3, 7, "Pinnacle PCTV Bungee USB (PAL) FM"}, 88 {0x2304, 0x0419, -1, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_TEMIC_4009FR5_PAL, -1, -1, 0, 3, 7, "Pinnacle PCTV Bungee USB (PAL) FM"},
89 {0x2400, 0x4200, -1, CODEC_SAA7111, 3, VIDEO_MODE_NTSC, 1, 0, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB"}, 89 {0x2400, 0x4200, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 0, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB"},
90 {} /* Terminating entry */ 90 {} /* Terminating entry */
91}; 91};
92 92
@@ -148,7 +148,6 @@ struct usb_device_id usbvision_table [] = {
148 { USB_DEVICE(0x2304, 0x0300) }, /* Pinnacle Studio Linx Video input cable (NTSC) */ 148 { USB_DEVICE(0x2304, 0x0300) }, /* Pinnacle Studio Linx Video input cable (NTSC) */
149 { USB_DEVICE(0x2304, 0x0301) }, /* Pinnacle Studio Linx Video input cable (PAL) */ 149 { USB_DEVICE(0x2304, 0x0301) }, /* Pinnacle Studio Linx Video input cable (PAL) */
150 { USB_DEVICE(0x2304, 0x0419) }, /* Pinnacle PCTV Bungee USB (PAL) FM */ 150 { USB_DEVICE(0x2304, 0x0419) }, /* Pinnacle PCTV Bungee USB (PAL) FM */
151
152 { USB_DEVICE(0x2400, 0x4200) }, /* Hauppauge WinTv-USB2 Model 42012 */ 151 { USB_DEVICE(0x2400, 0x4200) }, /* Hauppauge WinTv-USB2 Model 42012 */
153 152
154 { } /* Terminating entry */ 153 { } /* Terminating entry */
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index 797b97baf9..a807d971e2 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -118,7 +118,7 @@ static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision);
118 * This is used when initializing the contents of the area. 118 * This is used when initializing the contents of the area.
119 */ 119 */
120 120
121void *usbvision_rvmalloc(unsigned long size) 121static void *usbvision_rvmalloc(unsigned long size)
122{ 122{
123 void *mem; 123 void *mem;
124 unsigned long adr; 124 unsigned long adr;
@@ -181,7 +181,7 @@ static void usbvision_hexdump(const unsigned char *data, int len)
181/******************************** 181/********************************
182 * scratch ring buffer handling 182 * scratch ring buffer handling
183 ********************************/ 183 ********************************/
184int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of data actually in the buffer */ 184static int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of data actually in the buffer */
185{ 185{
186 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr; 186 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr;
187 if (len < 0) { 187 if (len < 0) {
@@ -194,7 +194,7 @@ int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of
194 194
195 195
196/* This returns the free space left in the buffer */ 196/* This returns the free space left in the buffer */
197int scratch_free(struct usb_usbvision *usbvision) 197static int scratch_free(struct usb_usbvision *usbvision)
198{ 198{
199 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr; 199 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr;
200 if (free <= 0) { 200 if (free <= 0) {
@@ -211,7 +211,8 @@ int scratch_free(struct usb_usbvision *usbvision)
211 211
212 212
213/* This puts data into the buffer */ 213/* This puts data into the buffer */
214int scratch_put(struct usb_usbvision *usbvision, unsigned char *data, int len) 214static int scratch_put(struct usb_usbvision *usbvision, unsigned char *data,
215 int len)
215{ 216{
216 int len_part; 217 int len_part;
217 218
@@ -237,7 +238,7 @@ int scratch_put(struct usb_usbvision *usbvision, unsigned char *data, int len)
237} 238}
238 239
239/* This marks the write_ptr as position of new frame header */ 240/* This marks the write_ptr as position of new frame header */
240void scratch_mark_header(struct usb_usbvision *usbvision) 241static void scratch_mark_header(struct usb_usbvision *usbvision)
241{ 242{
242 PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr); 243 PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr);
243 244
@@ -248,7 +249,8 @@ void scratch_mark_header(struct usb_usbvision *usbvision)
248} 249}
249 250
250/* This gets data from the buffer at the given "ptr" position */ 251/* This gets data from the buffer at the given "ptr" position */
251int scratch_get_extra(struct usb_usbvision *usbvision, unsigned char *data, int *ptr, int len) 252static int scratch_get_extra(struct usb_usbvision *usbvision,
253 unsigned char *data, int *ptr, int len)
252{ 254{
253 int len_part; 255 int len_part;
254 if (*ptr + len < scratch_buf_size) { 256 if (*ptr + len < scratch_buf_size) {
@@ -274,7 +276,8 @@ int scratch_get_extra(struct usb_usbvision *usbvision, unsigned char *data, int
274 276
275 277
276/* This sets the scratch extra read pointer */ 278/* This sets the scratch extra read pointer */
277void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, int len) 279static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr,
280 int len)
278{ 281{
279 *ptr = (usbvision->scratch_read_ptr + len)%scratch_buf_size; 282 *ptr = (usbvision->scratch_read_ptr + len)%scratch_buf_size;
280 283
@@ -283,7 +286,7 @@ void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, int len)
283 286
284 287
285/*This increments the scratch extra read pointer */ 288/*This increments the scratch extra read pointer */
286void scratch_inc_extra_ptr(int *ptr, int len) 289static void scratch_inc_extra_ptr(int *ptr, int len)
287{ 290{
288 *ptr = (*ptr + len) % scratch_buf_size; 291 *ptr = (*ptr + len) % scratch_buf_size;
289 292
@@ -292,7 +295,8 @@ void scratch_inc_extra_ptr(int *ptr, int len)
292 295
293 296
294/* This gets data from the buffer */ 297/* This gets data from the buffer */
295int scratch_get(struct usb_usbvision *usbvision, unsigned char *data, int len) 298static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data,
299 int len)
296{ 300{
297 int len_part; 301 int len_part;
298 if (usbvision->scratch_read_ptr + len < scratch_buf_size) { 302 if (usbvision->scratch_read_ptr + len < scratch_buf_size) {
@@ -318,7 +322,8 @@ int scratch_get(struct usb_usbvision *usbvision, unsigned char *data, int len)
318 322
319 323
320/* This sets read pointer to next header and returns it */ 324/* This sets read pointer to next header and returns it */
321int scratch_get_header(struct usb_usbvision *usbvision,struct usbvision_frame_header *header) 325static int scratch_get_header(struct usb_usbvision *usbvision,
326 struct usbvision_frame_header *header)
322{ 327{
323 int errCode = 0; 328 int errCode = 0;
324 329
@@ -346,7 +351,7 @@ int scratch_get_header(struct usb_usbvision *usbvision,struct usbvision_frame_he
346 351
347 352
348/*This removes len bytes of old data from the buffer */ 353/*This removes len bytes of old data from the buffer */
349void scratch_rm_old(struct usb_usbvision *usbvision, int len) 354static void scratch_rm_old(struct usb_usbvision *usbvision, int len)
350{ 355{
351 356
352 usbvision->scratch_read_ptr += len; 357 usbvision->scratch_read_ptr += len;
@@ -356,7 +361,7 @@ void scratch_rm_old(struct usb_usbvision *usbvision, int len)
356 361
357 362
358/*This resets the buffer - kills all data in it too */ 363/*This resets the buffer - kills all data in it too */
359void scratch_reset(struct usb_usbvision *usbvision) 364static void scratch_reset(struct usb_usbvision *usbvision)
360{ 365{
361 PDEBUG(DBG_SCRATCH, "\n"); 366 PDEBUG(DBG_SCRATCH, "\n");
362 367
@@ -369,7 +374,7 @@ void scratch_reset(struct usb_usbvision *usbvision)
369 374
370int usbvision_scratch_alloc(struct usb_usbvision *usbvision) 375int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
371{ 376{
372 usbvision->scratch = vmalloc(scratch_buf_size); 377 usbvision->scratch = vmalloc_32(scratch_buf_size);
373 scratch_reset(usbvision); 378 scratch_reset(usbvision);
374 if(usbvision->scratch == NULL) { 379 if(usbvision->scratch == NULL) {
375 err("%s: unable to allocate %d bytes for scratch", 380 err("%s: unable to allocate %d bytes for scratch",
@@ -399,8 +404,8 @@ void usbvision_scratch_free(struct usb_usbvision *usbvision)
399 * 1: Draw a colored grid 404 * 1: Draw a colored grid
400 * 405 *
401 */ 406 */
402void usbvision_testpattern(struct usb_usbvision *usbvision, int fullframe, 407static void usbvision_testpattern(struct usb_usbvision *usbvision,
403 int pmode) 408 int fullframe, int pmode)
404{ 409{
405 static const char proc[] = "usbvision_testpattern"; 410 static const char proc[] = "usbvision_testpattern";
406 struct usbvision_frame *frame; 411 struct usbvision_frame *frame;
@@ -480,7 +485,7 @@ void usbvision_testpattern(struct usb_usbvision *usbvision, int fullframe,
480int usbvision_decompress_alloc(struct usb_usbvision *usbvision) 485int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
481{ 486{
482 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; 487 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
483 usbvision->IntraFrameBuffer = vmalloc(IFB_size); 488 usbvision->IntraFrameBuffer = vmalloc_32(IFB_size);
484 if (usbvision->IntraFrameBuffer == NULL) { 489 if (usbvision->IntraFrameBuffer == NULL) {
485 err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size); 490 err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size);
486 return -ENOMEM; 491 return -ENOMEM;
@@ -2199,6 +2204,7 @@ int usbvision_power_on(struct usb_usbvision *usbvision)
2199 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); 2204 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
2200 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2205 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2201 USBVISION_SSPND_EN | USBVISION_RES2); 2206 USBVISION_SSPND_EN | USBVISION_RES2);
2207
2202 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2208 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2203 USBVISION_SSPND_EN | USBVISION_PWR_VID); 2209 USBVISION_SSPND_EN | USBVISION_PWR_VID);
2204 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2210 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
@@ -2305,7 +2311,7 @@ int usbvision_restart_isoc(struct usb_usbvision *usbvision)
2305 usbvision->Vin_Reg2_Preset)) < 0) return ret; 2311 usbvision->Vin_Reg2_Preset)) < 0) return ret;
2306 2312
2307 /* TODO: schedule timeout */ 2313 /* TODO: schedule timeout */
2308 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) && 0x01) != 1); 2314 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1);
2309 2315
2310 return 0; 2316 return 0;
2311} 2317}
@@ -2346,40 +2352,6 @@ int usbvision_setup(struct usb_usbvision *usbvision,int format)
2346 return USBVISION_IS_OPERATIONAL(usbvision); 2352 return USBVISION_IS_OPERATIONAL(usbvision);
2347} 2353}
2348 2354
2349
2350int usbvision_sbuf_alloc(struct usb_usbvision *usbvision)
2351{
2352 int i, errCode = 0;
2353 const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
2354
2355 /* Clean pointers so we know if we allocated something */
2356 for (i = 0; i < USBVISION_NUMSBUF; i++)
2357 usbvision->sbuf[i].data = NULL;
2358
2359 for (i = 0; i < USBVISION_NUMSBUF; i++) {
2360 usbvision->sbuf[i].data = kzalloc(sb_size, GFP_KERNEL);
2361 if (usbvision->sbuf[i].data == NULL) {
2362 err("%s: unable to allocate %d bytes for sbuf", __FUNCTION__, sb_size);
2363 errCode = -ENOMEM;
2364 break;
2365 }
2366 }
2367 return errCode;
2368}
2369
2370
2371void usbvision_sbuf_free(struct usb_usbvision *usbvision)
2372{
2373 int i;
2374
2375 for (i = 0; i < USBVISION_NUMSBUF; i++) {
2376 if (usbvision->sbuf[i].data != NULL) {
2377 kfree(usbvision->sbuf[i].data);
2378 usbvision->sbuf[i].data = NULL;
2379 }
2380 }
2381}
2382
2383/* 2355/*
2384 * usbvision_init_isoc() 2356 * usbvision_init_isoc()
2385 * 2357 *
@@ -2388,6 +2360,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2388{ 2360{
2389 struct usb_device *dev = usbvision->dev; 2361 struct usb_device *dev = usbvision->dev;
2390 int bufIdx, errCode, regValue; 2362 int bufIdx, errCode, regValue;
2363 const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
2391 2364
2392 if (!USBVISION_IS_OPERATIONAL(usbvision)) 2365 if (!USBVISION_IS_OPERATIONAL(usbvision))
2393 return -EFAULT; 2366 return -EFAULT;
@@ -2423,6 +2396,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2423 return -ENOMEM; 2396 return -ENOMEM;
2424 } 2397 }
2425 usbvision->sbuf[bufIdx].urb = urb; 2398 usbvision->sbuf[bufIdx].urb = urb;
2399 usbvision->sbuf[bufIdx].data = usb_buffer_alloc(usbvision->dev, sb_size, GFP_KERNEL,&urb->transfer_dma);
2426 urb->dev = dev; 2400 urb->dev = dev;
2427 urb->context = usbvision; 2401 urb->context = usbvision;
2428 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); 2402 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp);
@@ -2464,6 +2438,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2464void usbvision_stop_isoc(struct usb_usbvision *usbvision) 2438void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2465{ 2439{
2466 int bufIdx, errCode, regValue; 2440 int bufIdx, errCode, regValue;
2441 const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
2467 2442
2468 if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL)) 2443 if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL))
2469 return; 2444 return;
@@ -2471,6 +2446,12 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2471 /* Unschedule all of the iso td's */ 2446 /* Unschedule all of the iso td's */
2472 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) { 2447 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) {
2473 usb_kill_urb(usbvision->sbuf[bufIdx].urb); 2448 usb_kill_urb(usbvision->sbuf[bufIdx].urb);
2449 if (usbvision->sbuf[bufIdx].data){
2450 usb_buffer_free(usbvision->dev,
2451 sb_size,
2452 usbvision->sbuf[bufIdx].data,
2453 usbvision->sbuf[bufIdx].urb->transfer_dma);
2454 }
2474 usb_free_urb(usbvision->sbuf[bufIdx].urb); 2455 usb_free_urb(usbvision->sbuf[bufIdx].urb);
2475 usbvision->sbuf[bufIdx].urb = NULL; 2456 usbvision->sbuf[bufIdx].urb = NULL;
2476 } 2457 }
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c
index 0f3fba7ea6..858252c150 100644
--- a/drivers/media/video/usbvision/usbvision-i2c.c
+++ b/drivers/media/video/usbvision/usbvision-i2c.c
@@ -58,7 +58,6 @@ static int usbvision_i2c_read(void *data, unsigned char addr, char *buf,
58static inline int try_write_address(struct i2c_adapter *i2c_adap, 58static inline int try_write_address(struct i2c_adapter *i2c_adap,
59 unsigned char addr, int retries) 59 unsigned char addr, int retries)
60{ 60{
61 struct i2c_algo_usb_data *adap = i2c_adap->algo_data;
62 void *data; 61 void *data;
63 int i, ret = -1; 62 int i, ret = -1;
64 char buf[4]; 63 char buf[4];
@@ -69,10 +68,10 @@ static inline int try_write_address(struct i2c_adapter *i2c_adap,
69 ret = (usbvision_i2c_write(data, addr, buf, 1)); 68 ret = (usbvision_i2c_write(data, addr, buf, 1));
70 if (ret == 1) 69 if (ret == 1)
71 break; /* success! */ 70 break; /* success! */
72 udelay(5 /*adap->udelay */ ); 71 udelay(5);
73 if (i == retries) /* no success */ 72 if (i == retries) /* no success */
74 break; 73 break;
75 udelay(adap->udelay); 74 udelay(10);
76 } 75 }
77 if (i) { 76 if (i) {
78 PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr); 77 PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr);
@@ -84,7 +83,6 @@ static inline int try_write_address(struct i2c_adapter *i2c_adap,
84static inline int try_read_address(struct i2c_adapter *i2c_adap, 83static inline int try_read_address(struct i2c_adapter *i2c_adap,
85 unsigned char addr, int retries) 84 unsigned char addr, int retries)
86{ 85{
87 struct i2c_algo_usb_data *adap = i2c_adap->algo_data;
88 void *data; 86 void *data;
89 int i, ret = -1; 87 int i, ret = -1;
90 char buf[4]; 88 char buf[4];
@@ -94,10 +92,10 @@ static inline int try_read_address(struct i2c_adapter *i2c_adap,
94 ret = (usbvision_i2c_read(data, addr, buf, 1)); 92 ret = (usbvision_i2c_read(data, addr, buf, 1));
95 if (ret == 1) 93 if (ret == 1)
96 break; /* success! */ 94 break; /* success! */
97 udelay(5 /*adap->udelay */ ); 95 udelay(5);
98 if (i == retries) /* no success */ 96 if (i == retries) /* no success */
99 break; 97 break;
100 udelay(adap->udelay); 98 udelay(10);
101 } 99 }
102 if (i) { 100 if (i) {
103 PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr); 101 PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr);
@@ -213,7 +211,7 @@ static struct i2c_algorithm i2c_usb_algo = {
213/* 211/*
214 * registering functions to load algorithms at runtime 212 * registering functions to load algorithms at runtime
215 */ 213 */
216int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap) 214static int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap)
217{ 215{
218 PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]"); 216 PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
219 PDEBUG(DBG_ALGO, "ALGO debugging is enabled [i2c]"); 217 PDEBUG(DBG_ALGO, "ALGO debugging is enabled [i2c]");
@@ -248,15 +246,12 @@ int usbvision_i2c_usb_del_bus(struct i2c_adapter *adap)
248/* usbvision specific I2C functions */ 246/* usbvision specific I2C functions */
249/* ----------------------------------------------------------------------- */ 247/* ----------------------------------------------------------------------- */
250static struct i2c_adapter i2c_adap_template; 248static struct i2c_adapter i2c_adap_template;
251static struct i2c_algo_usb_data i2c_algo_template;
252static struct i2c_client i2c_client_template; 249static struct i2c_client i2c_client_template;
253 250
254int usbvision_init_i2c(struct usb_usbvision *usbvision) 251int usbvision_init_i2c(struct usb_usbvision *usbvision)
255{ 252{
256 memcpy(&usbvision->i2c_adap, &i2c_adap_template, 253 memcpy(&usbvision->i2c_adap, &i2c_adap_template,
257 sizeof(struct i2c_adapter)); 254 sizeof(struct i2c_adapter));
258 memcpy(&usbvision->i2c_algo, &i2c_algo_template,
259 sizeof(struct i2c_algo_usb_data));
260 memcpy(&usbvision->i2c_client, &i2c_client_template, 255 memcpy(&usbvision->i2c_client, &i2c_client_template,
261 sizeof(struct i2c_client)); 256 sizeof(struct i2c_client));
262 257
@@ -266,9 +261,7 @@ int usbvision_init_i2c(struct usb_usbvision *usbvision)
266 261
267 i2c_set_adapdata(&usbvision->i2c_adap, usbvision); 262 i2c_set_adapdata(&usbvision->i2c_adap, usbvision);
268 i2c_set_clientdata(&usbvision->i2c_client, usbvision); 263 i2c_set_clientdata(&usbvision->i2c_client, usbvision);
269 i2c_set_algo_usb_data(&usbvision->i2c_algo, usbvision);
270 264
271 usbvision->i2c_adap.algo_data = &usbvision->i2c_algo;
272 usbvision->i2c_client.adapter = &usbvision->i2c_adap; 265 usbvision->i2c_client.adapter = &usbvision->i2c_adap;
273 266
274 if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) { 267 if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) {
@@ -297,7 +290,6 @@ int usbvision_init_i2c(struct usb_usbvision *usbvision)
297void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd, 290void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,
298 void *arg) 291 void *arg)
299{ 292{
300 BUG_ON(NULL == usbvision->i2c_adap.algo_data);
301 i2c_clients_command(&usbvision->i2c_adap, cmd, arg); 293 i2c_clients_command(&usbvision->i2c_adap, cmd, arg);
302} 294}
303 295
@@ -327,6 +319,9 @@ static int attach_inform(struct i2c_client *client)
327 case 0x4a: 319 case 0x4a:
328 PDEBUG(DBG_I2C,"attach_inform: saa7113 detected."); 320 PDEBUG(DBG_I2C,"attach_inform: saa7113 detected.");
329 break; 321 break;
322 case 0x48:
323 PDEBUG(DBG_I2C,"attach_inform: saa7111 detected.");
324 break;
330 case 0xa0: 325 case 0xa0:
331 PDEBUG(DBG_I2C,"attach_inform: eeprom detected."); 326 PDEBUG(DBG_I2C,"attach_inform: eeprom detected.");
332 break; 327 break;
@@ -531,21 +526,10 @@ static int usbvision_i2c_read(void *data, unsigned char addr, char *buf,
531 return rdcount; 526 return rdcount;
532} 527}
533 528
534static struct i2c_algo_usb_data i2c_algo_template = {
535 .data = NULL,
536 .inb = usbvision_i2c_read,
537 .outb = usbvision_i2c_write,
538 .udelay = 10,
539 .mdelay = 10,
540 .timeout = 100,
541};
542
543static struct i2c_adapter i2c_adap_template = { 529static struct i2c_adapter i2c_adap_template = {
544 .owner = THIS_MODULE, 530 .owner = THIS_MODULE,
545 .name = "usbvision", 531 .name = "usbvision",
546 .id = I2C_HW_B_BT848, /* FIXME */ 532 .id = I2C_HW_B_BT848, /* FIXME */
547 .algo = NULL,
548 .algo_data = NULL,
549 .client_register = attach_inform, 533 .client_register = attach_inform,
550 .client_unregister = detach_inform, 534 .client_unregister = detach_inform,
551#ifdef I2C_ADAP_CLASS_TV_ANALOG 535#ifdef I2C_ADAP_CLASS_TV_ANALOG
@@ -559,9 +543,6 @@ static struct i2c_client i2c_client_template = {
559 .name = "usbvision internal", 543 .name = "usbvision internal",
560}; 544};
561 545
562EXPORT_SYMBOL(usbvision_i2c_usb_add_bus);
563EXPORT_SYMBOL(usbvision_i2c_usb_del_bus);
564
565/* 546/*
566 * Overrides for Emacs so that we follow Linus's tabbing style. 547 * Overrides for Emacs so that we follow Linus's tabbing style.
567 * --------------------------------------------------------------------------- 548 * ---------------------------------------------------------------------------
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 864446c012..7243337b77 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -204,7 +204,7 @@ MODULE_ALIAS(DRIVER_ALIAS);
204 204
205static inline struct usb_usbvision *cd_to_usbvision(struct class_device *cd) 205static inline struct usb_usbvision *cd_to_usbvision(struct class_device *cd)
206{ 206{
207 struct video_device *vdev = to_video_device(cd); 207 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
208 return video_get_drvdata(vdev); 208 return video_get_drvdata(vdev);
209} 209}
210 210
@@ -214,81 +214,85 @@ static ssize_t show_version(struct class_device *cd, char *buf)
214} 214}
215static CLASS_DEVICE_ATTR(version, S_IRUGO, show_version, NULL); 215static CLASS_DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
216 216
217static ssize_t show_model(struct class_device *class_dev, char *buf) 217static ssize_t show_model(struct class_device *cd, char *buf)
218{ 218{
219 struct video_device *vdev = to_video_device(class_dev); 219 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
220 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 220 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
221 return sprintf(buf, "%s\n", usbvision_device_data[usbvision->DevModel].ModelString); 221 return sprintf(buf, "%s\n", usbvision_device_data[usbvision->DevModel].ModelString);
222} 222}
223static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL); 223static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
224 224
225static ssize_t show_hue(struct class_device *class_dev, char *buf) 225static ssize_t show_hue(struct class_device *cd, char *buf)
226{ 226{
227 struct video_device *vdev = to_video_device(class_dev); 227 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
228 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 228 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
229 struct v4l2_control ctrl; 229 struct v4l2_control ctrl;
230 ctrl.id = V4L2_CID_HUE; 230 ctrl.id = V4L2_CID_HUE;
231 ctrl.value = 0; 231 ctrl.value = 0;
232 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 232 if(usbvision->user)
233 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
233 return sprintf(buf, "%d\n", ctrl.value >> 8); 234 return sprintf(buf, "%d\n", ctrl.value >> 8);
234} 235}
235static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); 236static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
236 237
237static ssize_t show_contrast(struct class_device *class_dev, char *buf) 238static ssize_t show_contrast(struct class_device *cd, char *buf)
238{ 239{
239 struct video_device *vdev = to_video_device(class_dev); 240 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
240 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 241 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
241 struct v4l2_control ctrl; 242 struct v4l2_control ctrl;
242 ctrl.id = V4L2_CID_CONTRAST; 243 ctrl.id = V4L2_CID_CONTRAST;
243 ctrl.value = 0; 244 ctrl.value = 0;
244 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 245 if(usbvision->user)
246 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
245 return sprintf(buf, "%d\n", ctrl.value >> 8); 247 return sprintf(buf, "%d\n", ctrl.value >> 8);
246} 248}
247static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); 249static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
248 250
249static ssize_t show_brightness(struct class_device *class_dev, char *buf) 251static ssize_t show_brightness(struct class_device *cd, char *buf)
250{ 252{
251 struct video_device *vdev = to_video_device(class_dev); 253 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
252 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 254 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
253 struct v4l2_control ctrl; 255 struct v4l2_control ctrl;
254 ctrl.id = V4L2_CID_BRIGHTNESS; 256 ctrl.id = V4L2_CID_BRIGHTNESS;
255 ctrl.value = 0; 257 ctrl.value = 0;
256 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 258 if(usbvision->user)
259 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
257 return sprintf(buf, "%d\n", ctrl.value >> 8); 260 return sprintf(buf, "%d\n", ctrl.value >> 8);
258} 261}
259static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); 262static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
260 263
261static ssize_t show_saturation(struct class_device *class_dev, char *buf) 264static ssize_t show_saturation(struct class_device *cd, char *buf)
262{ 265{
263 struct video_device *vdev = to_video_device(class_dev); 266 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
264 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 267 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
265 struct v4l2_control ctrl; 268 struct v4l2_control ctrl;
266 ctrl.id = V4L2_CID_SATURATION; 269 ctrl.id = V4L2_CID_SATURATION;
267 ctrl.value = 0; 270 ctrl.value = 0;
268 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 271 if(usbvision->user)
272 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
269 return sprintf(buf, "%d\n", ctrl.value >> 8); 273 return sprintf(buf, "%d\n", ctrl.value >> 8);
270} 274}
271static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); 275static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
272 276
273static ssize_t show_streaming(struct class_device *class_dev, char *buf) 277static ssize_t show_streaming(struct class_device *cd, char *buf)
274{ 278{
275 struct video_device *vdev = to_video_device(class_dev); 279 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
276 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 280 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
277 return sprintf(buf, "%s\n", YES_NO(usbvision->streaming==Stream_On?1:0)); 281 return sprintf(buf, "%s\n", YES_NO(usbvision->streaming==Stream_On?1:0));
278} 282}
279static CLASS_DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL); 283static CLASS_DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL);
280 284
281static ssize_t show_compression(struct class_device *class_dev, char *buf) 285static ssize_t show_compression(struct class_device *cd, char *buf)
282{ 286{
283 struct video_device *vdev = to_video_device(class_dev); 287 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
284 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 288 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
285 return sprintf(buf, "%s\n", YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS)); 289 return sprintf(buf, "%s\n", YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS));
286} 290}
287static CLASS_DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL); 291static CLASS_DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL);
288 292
289static ssize_t show_device_bridge(struct class_device *class_dev, char *buf) 293static ssize_t show_device_bridge(struct class_device *cd, char *buf)
290{ 294{
291 struct video_device *vdev = to_video_device(class_dev); 295 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
292 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 296 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
293 return sprintf(buf, "%d\n", usbvision->bridgeType); 297 return sprintf(buf, "%d\n", usbvision->bridgeType);
294} 298}
@@ -297,31 +301,71 @@ static CLASS_DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL);
297static void usbvision_create_sysfs(struct video_device *vdev) 301static void usbvision_create_sysfs(struct video_device *vdev)
298{ 302{
299 int res; 303 int res;
300 if (vdev) { 304 if (!vdev)
301 res=video_device_create_file(vdev, &class_device_attr_version); 305 return;
302 res=video_device_create_file(vdev, &class_device_attr_model); 306 do {
303 res=video_device_create_file(vdev, &class_device_attr_hue); 307 res=class_device_create_file(&vdev->class_dev,
304 res=video_device_create_file(vdev, &class_device_attr_contrast); 308 &class_device_attr_version);
305 res=video_device_create_file(vdev, &class_device_attr_brightness); 309 if (res<0)
306 res=video_device_create_file(vdev, &class_device_attr_saturation); 310 break;
307 res=video_device_create_file(vdev, &class_device_attr_streaming); 311 res=class_device_create_file(&vdev->class_dev,
308 res=video_device_create_file(vdev, &class_device_attr_compression); 312 &class_device_attr_model);
309 res=video_device_create_file(vdev, &class_device_attr_bridge); 313 if (res<0)
310 } 314 break;
315 res=class_device_create_file(&vdev->class_dev,
316 &class_device_attr_hue);
317 if (res<0)
318 break;
319 res=class_device_create_file(&vdev->class_dev,
320 &class_device_attr_contrast);
321 if (res<0)
322 break;
323 res=class_device_create_file(&vdev->class_dev,
324 &class_device_attr_brightness);
325 if (res<0)
326 break;
327 res=class_device_create_file(&vdev->class_dev,
328 &class_device_attr_saturation);
329 if (res<0)
330 break;
331 res=class_device_create_file(&vdev->class_dev,
332 &class_device_attr_streaming);
333 if (res<0)
334 break;
335 res=class_device_create_file(&vdev->class_dev,
336 &class_device_attr_compression);
337 if (res<0)
338 break;
339 res=class_device_create_file(&vdev->class_dev,
340 &class_device_attr_bridge);
341 if (res>=0)
342 return;
343 } while (0);
344
345 err("%s error: %d\n", __FUNCTION__, res);
311} 346}
312 347
313static void usbvision_remove_sysfs(struct video_device *vdev) 348static void usbvision_remove_sysfs(struct video_device *vdev)
314{ 349{
315 if (vdev) { 350 if (vdev) {
316 video_device_remove_file(vdev, &class_device_attr_version); 351 class_device_remove_file(&vdev->class_dev,
317 video_device_remove_file(vdev, &class_device_attr_model); 352 &class_device_attr_version);
318 video_device_remove_file(vdev, &class_device_attr_hue); 353 class_device_remove_file(&vdev->class_dev,
319 video_device_remove_file(vdev, &class_device_attr_contrast); 354 &class_device_attr_model);
320 video_device_remove_file(vdev, &class_device_attr_brightness); 355 class_device_remove_file(&vdev->class_dev,
321 video_device_remove_file(vdev, &class_device_attr_saturation); 356 &class_device_attr_hue);
322 video_device_remove_file(vdev, &class_device_attr_streaming); 357 class_device_remove_file(&vdev->class_dev,
323 video_device_remove_file(vdev, &class_device_attr_compression); 358 &class_device_attr_contrast);
324 video_device_remove_file(vdev, &class_device_attr_bridge); 359 class_device_remove_file(&vdev->class_dev,
360 &class_device_attr_brightness);
361 class_device_remove_file(&vdev->class_dev,
362 &class_device_attr_saturation);
363 class_device_remove_file(&vdev->class_dev,
364 &class_device_attr_streaming);
365 class_device_remove_file(&vdev->class_dev,
366 &class_device_attr_compression);
367 class_device_remove_file(&vdev->class_dev,
368 &class_device_attr_bridge);
325 } 369 }
326} 370}
327 371
@@ -353,20 +397,15 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
353 if(!errCode) { 397 if(!errCode) {
354 /* Allocate memory for the scratch ring buffer */ 398 /* Allocate memory for the scratch ring buffer */
355 errCode = usbvision_scratch_alloc(usbvision); 399 errCode = usbvision_scratch_alloc(usbvision);
356 if(!errCode) { 400 if ((!errCode) && (isocMode==ISOC_MODE_COMPRESS)) {
357 /* Allocate memory for the USB S buffers */ 401 /* Allocate intermediate decompression buffers only if needed */
358 errCode = usbvision_sbuf_alloc(usbvision); 402 errCode = usbvision_decompress_alloc(usbvision);
359 if ((!errCode) && (usbvision->isocMode==ISOC_MODE_COMPRESS)) {
360 /* Allocate intermediate decompression buffers only if needed */
361 errCode = usbvision_decompress_alloc(usbvision);
362 }
363 } 403 }
364 } 404 }
365 if (errCode) { 405 if (errCode) {
366 /* Deallocate all buffers if trouble */ 406 /* Deallocate all buffers if trouble */
367 usbvision_frames_free(usbvision); 407 usbvision_frames_free(usbvision);
368 usbvision_scratch_free(usbvision); 408 usbvision_scratch_free(usbvision);
369 usbvision_sbuf_free(usbvision);
370 usbvision_decompress_free(usbvision); 409 usbvision_decompress_free(usbvision);
371 } 410 }
372 } 411 }
@@ -437,9 +476,8 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
437 usbvision_stop_isoc(usbvision); 476 usbvision_stop_isoc(usbvision);
438 477
439 usbvision_decompress_free(usbvision); 478 usbvision_decompress_free(usbvision);
440 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size); 479 usbvision_frames_free(usbvision);
441 usbvision_scratch_free(usbvision); 480 usbvision_scratch_free(usbvision);
442 usbvision_sbuf_free(usbvision);
443 481
444 usbvision->user--; 482 usbvision->user--;
445 483
@@ -1042,7 +1080,6 @@ static ssize_t usbvision_v4l2_read(struct file *file, char *buf,
1042 int noblock = file->f_flags & O_NONBLOCK; 1080 int noblock = file->f_flags & O_NONBLOCK;
1043 unsigned long lock_flags; 1081 unsigned long lock_flags;
1044 1082
1045 int frmx = -1;
1046 int ret,i; 1083 int ret,i;
1047 struct usbvision_frame *frame; 1084 struct usbvision_frame *frame;
1048 1085
@@ -1117,7 +1154,7 @@ static ssize_t usbvision_v4l2_read(struct file *file, char *buf,
1117 frame->bytes_read = 0; 1154 frame->bytes_read = 0;
1118 1155
1119 /* Mark it as available to be used again. */ 1156 /* Mark it as available to be used again. */
1120 usbvision->frame[frmx].grabstate = FrameState_Unused; 1157 frame->grabstate = FrameState_Unused;
1121/* } */ 1158/* } */
1122 1159
1123 return count; 1160 return count;
@@ -1884,7 +1921,7 @@ static struct usb_driver usbvision_driver = {
1884 * This procedure preprocesses CustomDevice parameter if any 1921 * This procedure preprocesses CustomDevice parameter if any
1885 * 1922 *
1886 */ 1923 */
1887void customdevice_process(void) 1924static void customdevice_process(void)
1888{ 1925{
1889 usbvision_device_data[0]=usbvision_device_data[1]; 1926 usbvision_device_data[0]=usbvision_device_data[1];
1890 usbvision_table[0]=usbvision_table[1]; 1927 usbvision_table[0]=usbvision_table[1];
@@ -1939,22 +1976,22 @@ void customdevice_process(void)
1939 { 1976 {
1940 case 'P': 1977 case 'P':
1941 PDEBUG(DBG_PROBE, "VideoNorm=PAL"); 1978 PDEBUG(DBG_PROBE, "VideoNorm=PAL");
1942 usbvision_device_data[0].VideoNorm=VIDEO_MODE_PAL; 1979 usbvision_device_data[0].VideoNorm=V4L2_STD_PAL;
1943 break; 1980 break;
1944 1981
1945 case 'S': 1982 case 'S':
1946 PDEBUG(DBG_PROBE, "VideoNorm=SECAM"); 1983 PDEBUG(DBG_PROBE, "VideoNorm=SECAM");
1947 usbvision_device_data[0].VideoNorm=VIDEO_MODE_SECAM; 1984 usbvision_device_data[0].VideoNorm=V4L2_STD_SECAM;
1948 break; 1985 break;
1949 1986
1950 case 'N': 1987 case 'N':
1951 PDEBUG(DBG_PROBE, "VideoNorm=NTSC"); 1988 PDEBUG(DBG_PROBE, "VideoNorm=NTSC");
1952 usbvision_device_data[0].VideoNorm=VIDEO_MODE_NTSC; 1989 usbvision_device_data[0].VideoNorm=V4L2_STD_NTSC;
1953 break; 1990 break;
1954 1991
1955 default: 1992 default:
1956 PDEBUG(DBG_PROBE, "VideoNorm=PAL (by default)"); 1993 PDEBUG(DBG_PROBE, "VideoNorm=PAL (by default)");
1957 usbvision_device_data[0].VideoNorm=VIDEO_MODE_PAL; 1994 usbvision_device_data[0].VideoNorm=V4L2_STD_PAL;
1958 break; 1995 break;
1959 } 1996 }
1960 goto2next(parse); 1997 goto2next(parse);
diff --git a/drivers/media/video/usbvision/usbvision.h b/drivers/media/video/usbvision/usbvision.h
index 0e7e3d653c..e2bcaba938 100644
--- a/drivers/media/video/usbvision/usbvision.h
+++ b/drivers/media/video/usbvision/usbvision.h
@@ -219,18 +219,6 @@ enum {
219 ((udevice)->last_error == 0) && \ 219 ((udevice)->last_error == 0) && \
220 (!(udevice)->remove_pending)) 220 (!(udevice)->remove_pending))
221 221
222/* I2C structures */
223struct i2c_algo_usb_data {
224 void *data; /* private data for lowlevel routines */
225 int (*inb) (void *data, unsigned char addr, char *buf, short len);
226 int (*outb) (void *data, unsigned char addr, char *buf, short len);
227
228 /* local settings */
229 int udelay;
230 int mdelay;
231 int timeout;
232};
233
234#define I2C_USB_ADAP_MAX 16 222#define I2C_USB_ADAP_MAX 16
235 223
236/* ----------------------------------------------------------------- */ 224/* ----------------------------------------------------------------- */
@@ -383,7 +371,6 @@ struct usb_usbvision {
383 371
384 /* i2c Declaration Section*/ 372 /* i2c Declaration Section*/
385 struct i2c_adapter i2c_adap; 373 struct i2c_adapter i2c_adap;
386 struct i2c_algo_usb_data i2c_algo;
387 struct i2c_client i2c_client; 374 struct i2c_client i2c_client;
388 375
389 struct urb *ctrlUrb; 376 struct urb *ctrlUrb;
@@ -489,19 +476,8 @@ struct usb_usbvision {
489/* i2c-algo-usb declaration */ 476/* i2c-algo-usb declaration */
490/* --------------------------------------------------------------- */ 477/* --------------------------------------------------------------- */
491 478
492int usbvision_i2c_usb_add_bus(struct i2c_adapter *);
493int usbvision_i2c_usb_del_bus(struct i2c_adapter *); 479int usbvision_i2c_usb_del_bus(struct i2c_adapter *);
494 480
495static inline void *i2c_get_algo_usb_data (struct i2c_algo_usb_data *dev)
496{
497 return dev->data;
498}
499
500static inline void i2c_set_algo_usb_data (struct i2c_algo_usb_data *dev, void *data)
501{
502 dev->data = data;
503}
504
505 481
506/* ----------------------------------------------------------------------- */ 482/* ----------------------------------------------------------------------- */
507/* usbvision specific I2C functions */ 483/* usbvision specific I2C functions */
@@ -510,7 +486,6 @@ int usbvision_init_i2c(struct usb_usbvision *usbvision);
510void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,void *arg); 486void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,void *arg);
511 487
512/* defined in usbvision-core.c */ 488/* defined in usbvision-core.c */
513void *usbvision_rvmalloc(unsigned long size);
514void usbvision_rvfree(void *mem, unsigned long size); 489void usbvision_rvfree(void *mem, unsigned long size);
515int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg); 490int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg);
516int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg, 491int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
@@ -520,8 +495,6 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision);
520void usbvision_frames_free(struct usb_usbvision *usbvision); 495void usbvision_frames_free(struct usb_usbvision *usbvision);
521int usbvision_scratch_alloc(struct usb_usbvision *usbvision); 496int usbvision_scratch_alloc(struct usb_usbvision *usbvision);
522void usbvision_scratch_free(struct usb_usbvision *usbvision); 497void usbvision_scratch_free(struct usb_usbvision *usbvision);
523int usbvision_sbuf_alloc(struct usb_usbvision *usbvision);
524void usbvision_sbuf_free(struct usb_usbvision *usbvision);
525int usbvision_decompress_alloc(struct usb_usbvision *usbvision); 498int usbvision_decompress_alloc(struct usb_usbvision *usbvision);
526void usbvision_decompress_free(struct usb_usbvision *usbvision); 499void usbvision_decompress_free(struct usb_usbvision *usbvision);
527 500
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 752c82c37f..b87d571e04 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -90,8 +90,15 @@ MODULE_LICENSE("GPL");
90char *v4l2_norm_to_name(v4l2_std_id id) 90char *v4l2_norm_to_name(v4l2_std_id id)
91{ 91{
92 char *name; 92 char *name;
93 u32 myid = id;
93 94
94 switch (id) { 95 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
96 64 bit comparations. So, on that architecture, with some gcc variants,
97 compilation fails. Currently, the max value is 30bit wide.
98 */
99 BUG_ON(myid != id);
100
101 switch (myid) {
95 case V4L2_STD_PAL: 102 case V4L2_STD_PAL:
96 name="PAL"; break; 103 name="PAL"; break;
97 case V4L2_STD_PAL_BG: 104 case V4L2_STD_PAL_BG:
diff --git a/drivers/media/video/video-buf.c b/drivers/media/video/video-buf.c
index f429f49901..6504a58668 100644
--- a/drivers/media/video/video-buf.c
+++ b/drivers/media/video/video-buf.c
@@ -700,6 +700,7 @@ videobuf_qbuf(struct videobuf_queue *q,
700 goto done; 700 goto done;
701 } 701 }
702 if (buf->state == STATE_QUEUED || 702 if (buf->state == STATE_QUEUED ||
703 buf->state == STATE_PREPARED ||
703 buf->state == STATE_ACTIVE) { 704 buf->state == STATE_ACTIVE) {
704 dprintk(1,"qbuf: buffer is already queued or active.\n"); 705 dprintk(1,"qbuf: buffer is already queued or active.\n");
705 goto done; 706 goto done;
@@ -1229,7 +1230,7 @@ videobuf_vm_nopage(struct vm_area_struct *vma, unsigned long vaddr,
1229 vaddr,vma->vm_start,vma->vm_end); 1230 vaddr,vma->vm_start,vma->vm_end);
1230 if (vaddr > vma->vm_end) 1231 if (vaddr > vma->vm_end)
1231 return NOPAGE_SIGBUS; 1232 return NOPAGE_SIGBUS;
1232 page = alloc_page(GFP_USER); 1233 page = alloc_page(GFP_USER | __GFP_DMA32);
1233 if (!page) 1234 if (!page)
1234 return NOPAGE_OOM; 1235 return NOPAGE_OOM;
1235 clear_user_page(page_address(page), vaddr, page); 1236 clear_user_page(page_address(page), vaddr, page);
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 474ddb7796..d4cf556667 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -270,10 +270,15 @@ static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
270 char *p,*s,*basep; 270 char *p,*s,*basep;
271 struct page *pg; 271 struct page *pg;
272 u8 chr,r,g,b,color; 272 u8 chr,r,g,b,color;
273 unsigned long flags;
274 spinlock_t spinlock;
275
276 spin_lock_init(&spinlock);
273 277
274 /* Get first addr pointed to pixel position */ 278 /* Get first addr pointed to pixel position */
275 oldpg=get_addr_pos(pos,pages,to_addr); 279 oldpg=get_addr_pos(pos,pages,to_addr);
276 pg=pfn_to_page(sg_dma_address(to_addr[oldpg].sg) >> PAGE_SHIFT); 280 pg=pfn_to_page(sg_dma_address(to_addr[oldpg].sg) >> PAGE_SHIFT);
281 spin_lock_irqsave(&spinlock,flags);
277 basep = kmap_atomic(pg, KM_BOUNCE_READ)+to_addr[oldpg].sg->offset; 282 basep = kmap_atomic(pg, KM_BOUNCE_READ)+to_addr[oldpg].sg->offset;
278 283
279 /* We will just duplicate the second pixel at the packet */ 284 /* We will just duplicate the second pixel at the packet */
@@ -376,6 +381,8 @@ static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
376 381
377end: 382end:
378 kunmap_atomic(basep, KM_BOUNCE_READ); 383 kunmap_atomic(basep, KM_BOUNCE_READ);
384 spin_unlock_irqrestore(&spinlock,flags);
385
379} 386}
380static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf) 387static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
381{ 388{
@@ -535,9 +542,9 @@ static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
535 542
536 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi"); 543 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi");
537 544
538 if (dma_q->kthread == NULL) { 545 if (IS_ERR(dma_q->kthread)) {
539 printk(KERN_ERR "vivi: kernel_thread() failed\n"); 546 printk(KERN_ERR "vivi: kernel_thread() failed\n");
540 return -EINVAL; 547 return PTR_ERR(dma_q->kthread);
541 } 548 }
542 dprintk(1,"returning from %s\n",__FUNCTION__); 549 dprintk(1,"returning from %s\n",__FUNCTION__);
543 return 0; 550 return 0;
@@ -1363,7 +1370,9 @@ static void __exit vivi_exit(void)
1363 struct vivi_dev *h; 1370 struct vivi_dev *h;
1364 struct list_head *list; 1371 struct list_head *list;
1365 1372
1366 list_for_each(list,&vivi_devlist) { 1373 while (!list_empty(&vivi_devlist)) {
1374 list = vivi_devlist.next;
1375 list_del(list);
1367 h = list_entry(list, struct vivi_dev, vivi_devlist); 1376 h = list_entry(list, struct vivi_dev, vivi_devlist);
1368 kfree (h); 1377 kfree (h);
1369 } 1378 }
diff --git a/drivers/media/video/w9966.c b/drivers/media/video/w9966.c
index 4bdc886abc..8d14f308f1 100644
--- a/drivers/media/video/w9966.c
+++ b/drivers/media/video/w9966.c
@@ -789,7 +789,7 @@ static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file,
789 case VIDIOCSPICT: 789 case VIDIOCSPICT:
790 { 790 {
791 struct video_picture *vpic = arg; 791 struct video_picture *vpic = arg;
792 if (vpic->depth != 16 || vpic->palette != VIDEO_PALETTE_YUV422) 792 if (vpic->depth != 16 || (vpic->palette != VIDEO_PALETTE_YUV422 && vpic->palette != VIDEO_PALETTE_YUYV))
793 return -EINVAL; 793 return -EINVAL;
794 794
795 cam->brightness = vpic->brightness >> 8; 795 cam->brightness = vpic->brightness >> 8;
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
index ddce2fb834..9f403af7b0 100644
--- a/drivers/media/video/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -1827,8 +1827,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1827 int err = 0; 1827 int err = 0;
1828 1828
1829 /* Work around to avoid FP arithmetics */ 1829 /* Work around to avoid FP arithmetics */
1830 #define __SC(x) ((x) << 10) 1830 #define SC(x) ((x) << 10)
1831 #define __UNSC(x) ((x) >> 10) 1831 #define UNSC(x) ((x) >> 10)
1832 1832
1833 /* Make sure we are using a supported resolution */ 1833 /* Make sure we are using a supported resolution */
1834 if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width, 1834 if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width,
@@ -1836,15 +1836,15 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1836 goto error; 1836 goto error;
1837 1837
1838 /* Scaling factors */ 1838 /* Scaling factors */
1839 fw = __SC(win.width) / cam->maxwidth; 1839 fw = SC(win.width) / cam->maxwidth;
1840 fh = __SC(win.height) / cam->maxheight; 1840 fh = SC(win.height) / cam->maxheight;
1841 1841
1842 /* Set up the width and height values used by the chip */ 1842 /* Set up the width and height values used by the chip */
1843 if ((win.width > cam->maxwidth) || (win.height > cam->maxheight)) { 1843 if ((win.width > cam->maxwidth) || (win.height > cam->maxheight)) {
1844 cam->vpp_flag |= VPP_UPSCALE; 1844 cam->vpp_flag |= VPP_UPSCALE;
1845 /* Calculate largest w,h mantaining the same w/h ratio */ 1845 /* Calculate largest w,h mantaining the same w/h ratio */
1846 w = (fw >= fh) ? cam->maxwidth : __SC(win.width)/fh; 1846 w = (fw >= fh) ? cam->maxwidth : SC(win.width)/fh;
1847 h = (fw >= fh) ? __SC(win.height)/fw : cam->maxheight; 1847 h = (fw >= fh) ? SC(win.height)/fw : cam->maxheight;
1848 if (w < cam->minwidth) /* just in case */ 1848 if (w < cam->minwidth) /* just in case */
1849 w = cam->minwidth; 1849 w = cam->minwidth;
1850 if (h < cam->minheight) /* just in case */ 1850 if (h < cam->minheight) /* just in case */
@@ -1861,8 +1861,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1861 1861
1862 /* Calculate cropped area manteining the right w/h ratio */ 1862 /* Calculate cropped area manteining the right w/h ratio */
1863 if (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE)) { 1863 if (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE)) {
1864 cw = (fw >= fh) ? cam->maxwidth : __SC(win.width)/fh; 1864 cw = (fw >= fh) ? cam->maxwidth : SC(win.width)/fh;
1865 ch = (fw >= fh) ? __SC(win.height)/fw : cam->maxheight; 1865 ch = (fw >= fh) ? SC(win.height)/fw : cam->maxheight;
1866 } else { 1866 } else {
1867 cw = w; 1867 cw = w;
1868 ch = h; 1868 ch = h;
@@ -1901,8 +1901,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1901 /* We have to scale win.x and win.y offsets */ 1901 /* We have to scale win.x and win.y offsets */
1902 if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE)) 1902 if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE))
1903 || (cam->vpp_flag & VPP_UPSCALE) ) { 1903 || (cam->vpp_flag & VPP_UPSCALE) ) {
1904 ax = __SC(win.x)/fw; 1904 ax = SC(win.x)/fw;
1905 ay = __SC(win.y)/fh; 1905 ay = SC(win.y)/fh;
1906 } else { 1906 } else {
1907 ax = win.x; 1907 ax = win.x;
1908 ay = win.y; 1908 ay = win.y;
@@ -1917,8 +1917,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1917 /* Adjust win.x, win.y */ 1917 /* Adjust win.x, win.y */
1918 if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE)) 1918 if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE))
1919 || (cam->vpp_flag & VPP_UPSCALE) ) { 1919 || (cam->vpp_flag & VPP_UPSCALE) ) {
1920 win.x = __UNSC(ax*fw); 1920 win.x = UNSC(ax*fw);
1921 win.y = __UNSC(ay*fh); 1921 win.y = UNSC(ay*fh);
1922 } else { 1922 } else {
1923 win.x = ax; 1923 win.x = ax;
1924 win.y = ay; 1924 win.y = ay;
diff --git a/drivers/media/video/zoran_device.c b/drivers/media/video/zoran_device.c
index 168e431d7c..b0752767ee 100644
--- a/drivers/media/video/zoran_device.c
+++ b/drivers/media/video/zoran_device.c
@@ -429,7 +429,7 @@ zr36057_set_vfe (struct zoran *zr,
429 reg |= (HorDcm << ZR36057_VFESPFR_HorDcm); 429 reg |= (HorDcm << ZR36057_VFESPFR_HorDcm);
430 reg |= (VerDcm << ZR36057_VFESPFR_VerDcm); 430 reg |= (VerDcm << ZR36057_VFESPFR_VerDcm);
431 reg |= (DispMode << ZR36057_VFESPFR_DispMode); 431 reg |= (DispMode << ZR36057_VFESPFR_DispMode);
432 if (format->palette != VIDEO_PALETTE_YUV422) 432 if (format->palette != VIDEO_PALETTE_YUV422 && format->palette != VIDEO_PALETTE_YUYV)
433 reg |= ZR36057_VFESPFR_LittleEndian; 433 reg |= ZR36057_VFESPFR_LittleEndian;
434 /* RJ: I don't know, why the following has to be the opposite 434 /* RJ: I don't know, why the following has to be the opposite
435 * of the corresponding ZR36060 setting, but only this way 435 * of the corresponding ZR36060 setting, but only this way
@@ -441,6 +441,7 @@ zr36057_set_vfe (struct zoran *zr,
441 reg |= ZR36057_VFESPFR_TopField; 441 reg |= ZR36057_VFESPFR_TopField;
442 switch (format->palette) { 442 switch (format->palette) {
443 443
444 case VIDEO_PALETTE_YUYV:
444 case VIDEO_PALETTE_YUV422: 445 case VIDEO_PALETTE_YUV422:
445 reg |= ZR36057_VFESPFR_YUV422; 446 reg |= ZR36057_VFESPFR_YUV422;
446 break; 447 break;
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 6e068cf104..b3f28a03b6 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -5,7 +5,7 @@
5 * For use with LSI Logic PCI chip/adapter(s) 5 * For use with LSI Logic PCI chip/adapter(s)
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2005 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsil.com)
10 * 10 *
11 */ 11 */
@@ -73,6 +73,7 @@
73MODULE_AUTHOR(MODULEAUTHOR); 73MODULE_AUTHOR(MODULEAUTHOR);
74MODULE_DESCRIPTION(my_NAME); 74MODULE_DESCRIPTION(my_NAME);
75MODULE_LICENSE("GPL"); 75MODULE_LICENSE("GPL");
76MODULE_VERSION(my_VERSION);
76 77
77/* 78/*
78 * cmd line parameters 79 * cmd line parameters
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index a4afad4eca..e316708f76 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -5,7 +5,7 @@
5 * LSIFC9xx/LSI409xx Fibre Channel 5 * LSIFC9xx/LSI409xx Fibre Channel
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2005 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsil.com)
10 * 10 *
11 */ 11 */
@@ -72,11 +72,11 @@
72#endif 72#endif
73 73
74#ifndef COPYRIGHT 74#ifndef COPYRIGHT
75#define COPYRIGHT "Copyright (c) 1999-2005 " MODULEAUTHOR 75#define COPYRIGHT "Copyright (c) 1999-2007 " MODULEAUTHOR
76#endif 76#endif
77 77
78#define MPT_LINUX_VERSION_COMMON "3.04.02" 78#define MPT_LINUX_VERSION_COMMON "3.04.03"
79#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.04.02" 79#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.04.03"
80#define WHAT_MAGIC_STRING "@" "(" "#" ")" 80#define WHAT_MAGIC_STRING "@" "(" "#" ")"
81 81
82#define show_mptmod_ver(s,ver) \ 82#define show_mptmod_ver(s,ver) \
@@ -1059,7 +1059,7 @@ extern int mpt_stm_index; /* needed by mptstm.c */
1059/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1059/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1060#endif /* } __KERNEL__ */ 1060#endif /* } __KERNEL__ */
1061 1061
1062#if defined(__alpha__) || defined(__sparc_v9__) || defined(__ia64__) || defined(__x86_64__) 1062#if defined(__alpha__) || defined(__sparc_v9__) || defined(__ia64__) || defined(__x86_64__) || defined(__powerpc__)
1063#define CAST_U32_TO_PTR(x) ((void *)(u64)x) 1063#define CAST_U32_TO_PTR(x) ((void *)(u64)x)
1064#define CAST_PTR_TO_U32(x) ((u32)(u64)x) 1064#define CAST_PTR_TO_U32(x) ((u32)(u64)x)
1065#else 1065#else
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 30975ccd99..504632da43 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -4,7 +4,7 @@
4 * For use with LSI Logic PCI chip/adapters 4 * For use with LSI Logic PCI chip/adapters
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * 6 *
7 * Copyright (c) 1999-2005 LSI Logic Corporation 7 * Copyright (c) 1999-2007 LSI Logic Corporation
8 * (mailto:mpt_linux_developer@lsil.com) 8 * (mailto:mpt_linux_developer@lsil.com)
9 * 9 *
10 */ 10 */
@@ -66,7 +66,7 @@
66#include <scsi/scsi_host.h> 66#include <scsi/scsi_host.h>
67#include <scsi/scsi_tcq.h> 67#include <scsi/scsi_tcq.h>
68 68
69#define COPYRIGHT "Copyright (c) 1999-2005 LSI Logic Corporation" 69#define COPYRIGHT "Copyright (c) 1999-2007 LSI Logic Corporation"
70#define MODULEAUTHOR "LSI Logic Corporation" 70#define MODULEAUTHOR "LSI Logic Corporation"
71#include "mptbase.h" 71#include "mptbase.h"
72#include "mptctl.h" 72#include "mptctl.h"
@@ -79,6 +79,7 @@
79MODULE_AUTHOR(MODULEAUTHOR); 79MODULE_AUTHOR(MODULEAUTHOR);
80MODULE_DESCRIPTION(my_NAME); 80MODULE_DESCRIPTION(my_NAME);
81MODULE_LICENSE("GPL"); 81MODULE_LICENSE("GPL");
82MODULE_VERSION(my_VERSION);
82 83
83/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 84/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
84 85
diff --git a/drivers/message/fusion/mptctl.h b/drivers/message/fusion/mptctl.h
index 043941882c..e65a1cf5eb 100644
--- a/drivers/message/fusion/mptctl.h
+++ b/drivers/message/fusion/mptctl.h
@@ -5,7 +5,7 @@
5 * LSIFC9xx/LSI409xx Fibre Channel 5 * LSIFC9xx/LSI409xx Fibre Channel
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2005 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsil.com)
10 * 10 *
11 */ 11 */
diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c
index ca2f9107f1..c819c23b55 100644
--- a/drivers/message/fusion/mptfc.c
+++ b/drivers/message/fusion/mptfc.c
@@ -3,7 +3,7 @@
3 * For use with LSI Logic PCI chip/adapter(s) 3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2005 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsil.com)
8 * 8 *
9 */ 9 */
@@ -75,6 +75,7 @@
75MODULE_AUTHOR(MODULEAUTHOR); 75MODULE_AUTHOR(MODULEAUTHOR);
76MODULE_DESCRIPTION(my_NAME); 76MODULE_DESCRIPTION(my_NAME);
77MODULE_LICENSE("GPL"); 77MODULE_LICENSE("GPL");
78MODULE_VERSION(my_VERSION);
78 79
79/* Command line args */ 80/* Command line args */
80#define MPTFC_DEV_LOSS_TMO (60) 81#define MPTFC_DEV_LOSS_TMO (60)
diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c
index b7c4407c5e..2936204d8a 100644
--- a/drivers/message/fusion/mptlan.c
+++ b/drivers/message/fusion/mptlan.c
@@ -4,7 +4,7 @@
4 * For use with LSI Logic Fibre Channel PCI chip/adapters 4 * For use with LSI Logic Fibre Channel PCI chip/adapters
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * 6 *
7 * Copyright (c) 2000-2005 LSI Logic Corporation 7 * Copyright (c) 2000-2007 LSI Logic Corporation
8 * 8 *
9 */ 9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -56,9 +56,11 @@
56#include <linux/module.h> 56#include <linux/module.h>
57#include <linux/fs.h> 57#include <linux/fs.h>
58 58
59#define my_VERSION MPT_LINUX_VERSION_COMMON
59#define MYNAM "mptlan" 60#define MYNAM "mptlan"
60 61
61MODULE_LICENSE("GPL"); 62MODULE_LICENSE("GPL");
63MODULE_VERSION(my_VERSION);
62 64
63/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 65/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
64/* 66/*
diff --git a/drivers/message/fusion/mptlan.h b/drivers/message/fusion/mptlan.h
index 3726ecba57..70ab75e7c2 100644
--- a/drivers/message/fusion/mptlan.h
+++ b/drivers/message/fusion/mptlan.h
@@ -4,7 +4,7 @@
4 * For use with LSI Logic Fibre Channel PCI chip/adapters 4 * For use with LSI Logic Fibre Channel PCI chip/adapters
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * 6 *
7 * Copyright (c) 2000-2005 LSI Logic Corporation 7 * Copyright (c) 2000-2007 LSI Logic Corporation
8 * 8 *
9 */ 9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 4f0c530e47..09e9a9d964 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -3,9 +3,9 @@
3 * For use with LSI Logic PCI chip/adapter(s) 3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2005 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsil.com)
8 * Copyright (c) 2005-2006 Dell 8 * Copyright (c) 2005-2007 Dell
9 */ 9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
11/* 11/*
@@ -75,6 +75,7 @@
75MODULE_AUTHOR(MODULEAUTHOR); 75MODULE_AUTHOR(MODULEAUTHOR);
76MODULE_DESCRIPTION(my_NAME); 76MODULE_DESCRIPTION(my_NAME);
77MODULE_LICENSE("GPL"); 77MODULE_LICENSE("GPL");
78MODULE_VERSION(my_VERSION);
78 79
79static int mpt_pt_clear; 80static int mpt_pt_clear;
80module_param(mpt_pt_clear, int, 0); 81module_param(mpt_pt_clear, int, 0);
@@ -245,7 +246,8 @@ static void mptsas_print_device_pg0(SasDevicePage0_t *pg0)
245 printk("Parent Handle=0x%X\n" ,le16_to_cpu(pg0->ParentDevHandle)); 246 printk("Parent Handle=0x%X\n" ,le16_to_cpu(pg0->ParentDevHandle));
246 printk("Enclosure Handle=0x%X\n", le16_to_cpu(pg0->EnclosureHandle)); 247 printk("Enclosure Handle=0x%X\n", le16_to_cpu(pg0->EnclosureHandle));
247 printk("Slot=0x%X\n", le16_to_cpu(pg0->Slot)); 248 printk("Slot=0x%X\n", le16_to_cpu(pg0->Slot));
248 printk("SAS Address=0x%llX\n", le64_to_cpu(sas_address)); 249 printk("SAS Address=0x%llX\n", (unsigned long long)
250 le64_to_cpu(sas_address));
249 printk("Target ID=0x%X\n", pg0->TargetID); 251 printk("Target ID=0x%X\n", pg0->TargetID);
250 printk("Bus=0x%X\n", pg0->Bus); 252 printk("Bus=0x%X\n", pg0->Bus);
251 /* The PhyNum field specifies the PHY number of the parent 253 /* The PhyNum field specifies the PHY number of the parent
@@ -349,9 +351,9 @@ mptsas_port_delete(struct mptsas_portinfo_details * port_details)
349 phy_info = port_info->phy_info; 351 phy_info = port_info->phy_info;
350 352
351 dsaswideprintk((KERN_DEBUG "%s: [%p]: num_phys=%02d " 353 dsaswideprintk((KERN_DEBUG "%s: [%p]: num_phys=%02d "
352 "bitmask=0x%016llX\n", 354 "bitmask=0x%016llX\n", __FUNCTION__, port_details,
353 __FUNCTION__, port_details, port_details->num_phys, 355 port_details->num_phys, (unsigned long long)
354 port_details->phy_bitmask)); 356 port_details->phy_bitmask));
355 357
356 for (i = 0; i < port_info->num_phys; i++, phy_info++) { 358 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
357 if(phy_info->port_details != port_details) 359 if(phy_info->port_details != port_details)
@@ -476,7 +478,7 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
476 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) { 478 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
477 sas_address = phy_info->attached.sas_address; 479 sas_address = phy_info->attached.sas_address;
478 dsaswideprintk((KERN_DEBUG "phy_id=%d sas_address=0x%018llX\n", 480 dsaswideprintk((KERN_DEBUG "phy_id=%d sas_address=0x%018llX\n",
479 i, sas_address)); 481 i, (unsigned long long)sas_address));
480 if (!sas_address) 482 if (!sas_address)
481 continue; 483 continue;
482 port_details = phy_info->port_details; 484 port_details = phy_info->port_details;
@@ -495,8 +497,8 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
495 (1 << phy_info->phy_id); 497 (1 << phy_info->phy_id);
496 phy_info->sas_port_add_phy=1; 498 phy_info->sas_port_add_phy=1;
497 dsaswideprintk((KERN_DEBUG "\t\tForming port\n\t\t" 499 dsaswideprintk((KERN_DEBUG "\t\tForming port\n\t\t"
498 "phy_id=%d sas_address=0x%018llX\n", 500 "phy_id=%d sas_address=0x%018llX\n",
499 i, sas_address)); 501 i, (unsigned long long)sas_address));
500 phy_info->port_details = port_details; 502 phy_info->port_details = port_details;
501 } 503 }
502 504
@@ -512,8 +514,9 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
512 if (phy_info_cmp->port_details == port_details ) 514 if (phy_info_cmp->port_details == port_details )
513 continue; 515 continue;
514 dsaswideprintk((KERN_DEBUG 516 dsaswideprintk((KERN_DEBUG
515 "\t\tphy_id=%d sas_address=0x%018llX\n", 517 "\t\tphy_id=%d sas_address=0x%018llX\n",
516 j, phy_info_cmp->attached.sas_address)); 518 j, (unsigned long long)
519 phy_info_cmp->attached.sas_address));
517 if (phy_info_cmp->port_details) { 520 if (phy_info_cmp->port_details) {
518 port_details->rphy = 521 port_details->rphy =
519 mptsas_get_rphy(phy_info_cmp); 522 mptsas_get_rphy(phy_info_cmp);
@@ -546,11 +549,10 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
546 if (!port_details) 549 if (!port_details)
547 continue; 550 continue;
548 dsaswideprintk((KERN_DEBUG 551 dsaswideprintk((KERN_DEBUG
549 "%s: [%p]: phy_id=%02d num_phys=%02d " 552 "%s: [%p]: phy_id=%02d num_phys=%02d "
550 "bitmask=0x%016llX\n", 553 "bitmask=0x%016llX\n", __FUNCTION__,
551 __FUNCTION__, 554 port_details, i, port_details->num_phys,
552 port_details, i, port_details->num_phys, 555 (unsigned long long)port_details->phy_bitmask));
553 port_details->phy_bitmask));
554 dsaswideprintk((KERN_DEBUG"\t\tport = %p rphy=%p\n", 556 dsaswideprintk((KERN_DEBUG"\t\tport = %p rphy=%p\n",
555 port_details->port, port_details->rphy)); 557 port_details->port, port_details->rphy));
556 } 558 }
@@ -2079,8 +2081,10 @@ mptsas_persist_clear_table(struct work_struct *work)
2079static void 2081static void
2080mptsas_reprobe_lun(struct scsi_device *sdev, void *data) 2082mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
2081{ 2083{
2084 int rc;
2085
2082 sdev->no_uld_attach = data ? 1 : 0; 2086 sdev->no_uld_attach = data ? 1 : 0;
2083 scsi_device_reprobe(sdev); 2087 rc = scsi_device_reprobe(sdev);
2084} 2088}
2085 2089
2086static void 2090static void
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index 2c72c36b81..f0cca3ea93 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -3,7 +3,7 @@
3 * For use with LSI Logic PCI chip/adapter(s) 3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2005 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsil.com)
8 * 8 *
9 */ 9 */
@@ -76,6 +76,7 @@
76MODULE_AUTHOR(MODULEAUTHOR); 76MODULE_AUTHOR(MODULEAUTHOR);
77MODULE_DESCRIPTION(my_NAME); 77MODULE_DESCRIPTION(my_NAME);
78MODULE_LICENSE("GPL"); 78MODULE_LICENSE("GPL");
79MODULE_VERSION(my_VERSION);
79 80
80/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 81/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
81 82
@@ -701,6 +702,17 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
701 break; 702 break;
702 } 703 }
703 } 704 }
705 } else if (ioc->bus_type == FC) {
706 /*
707 * The FC IOC may kill a request for variety of
708 * reasons, some of which may be recovered by a
709 * retry, some which are unlikely to be
710 * recovered. Return DID_ERROR instead of
711 * DID_RESET to permit retry of the command,
712 * just not an infinite number of them
713 */
714 sc->result = DID_ERROR << 16;
715 break;
704 } 716 }
705 717
706 /* 718 /*
@@ -2688,7 +2700,8 @@ mptscsih_initTarget(MPT_SCSI_HOST *hd, VirtTarget *vtarget,
2688 struct scsi_device *sdev) 2700 struct scsi_device *sdev)
2689{ 2701{
2690 dinitprintk((MYIOC_s_INFO_FMT "initTarget bus=%d id=%d lun=%d hd=%p\n", 2702 dinitprintk((MYIOC_s_INFO_FMT "initTarget bus=%d id=%d lun=%d hd=%p\n",
2691 hd->ioc->name, vtarget->bus_id, vtarget->target_id, lun, hd)); 2703 hd->ioc->name, vtarget->bus_id, vtarget->target_id,
2704 sdev->lun, hd));
2692 2705
2693 /* Is LUN supported? If so, upper 2 bits will be 0 2706 /* Is LUN supported? If so, upper 2 bits will be 0
2694 * in first byte of inquiry data. 2707 * in first byte of inquiry data.
@@ -2770,7 +2783,7 @@ mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *target,
2770 else { 2783 else {
2771 factor = MPT_ULTRA320; 2784 factor = MPT_ULTRA320;
2772 if (scsi_device_qas(sdev)) { 2785 if (scsi_device_qas(sdev)) {
2773 ddvtprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", byte56, id)); 2786 ddvtprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", scsi_device_qas(sdev), id));
2774 noQas = 0; 2787 noQas = 0;
2775 } 2788 }
2776 if (sdev->type == TYPE_TAPE && 2789 if (sdev->type == TYPE_TAPE &&
diff --git a/drivers/message/fusion/mptscsih.h b/drivers/message/fusion/mptscsih.h
index 14a5b6c2e2..187c8af089 100644
--- a/drivers/message/fusion/mptscsih.h
+++ b/drivers/message/fusion/mptscsih.h
@@ -5,7 +5,7 @@
5 * LSIFC9xx/LSI409xx Fibre Channel 5 * LSIFC9xx/LSI409xx Fibre Channel
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2005 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsil.com)
10 * 10 *
11 */ 11 */
diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c
index 36641da592..203c661d2c 100644
--- a/drivers/message/fusion/mptspi.c
+++ b/drivers/message/fusion/mptspi.c
@@ -3,7 +3,7 @@
3 * For use with LSI Logic PCI chip/adapter(s) 3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2005 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsil.com)
8 * 8 *
9 */ 9 */
@@ -77,6 +77,7 @@
77MODULE_AUTHOR(MODULEAUTHOR); 77MODULE_AUTHOR(MODULEAUTHOR);
78MODULE_DESCRIPTION(my_NAME); 78MODULE_DESCRIPTION(my_NAME);
79MODULE_LICENSE("GPL"); 79MODULE_LICENSE("GPL");
80MODULE_VERSION(my_VERSION);
80 81
81/* Command line args */ 82/* Command line args */
82static int mpt_saf_te = MPTSCSIH_SAF_TE; 83static int mpt_saf_te = MPTSCSIH_SAF_TE;
diff --git a/drivers/message/i2o/exec-osm.c b/drivers/message/i2o/exec-osm.c
index a539d3b61e..5278aad92b 100644
--- a/drivers/message/i2o/exec-osm.c
+++ b/drivers/message/i2o/exec-osm.c
@@ -367,7 +367,7 @@ static int i2o_exec_remove(struct device *dev)
367 367
368/** 368/**
369 * i2o_exec_lct_modified - Called on LCT NOTIFY reply 369 * i2o_exec_lct_modified - Called on LCT NOTIFY reply
370 * @work: work struct for a specific controller 370 * @_work: work struct for a specific controller
371 * 371 *
372 * This function handles asynchronus LCT NOTIFY replies. It parses the 372 * This function handles asynchronus LCT NOTIFY replies. It parses the
373 * new LCT and if the buffer for the LCT was to small sends a LCT NOTIFY 373 * new LCT and if the buffer for the LCT was to small sends a LCT NOTIFY
diff --git a/drivers/misc/msi-laptop.c b/drivers/misc/msi-laptop.c
index fdb7153f44..8e5e07e4c1 100644
--- a/drivers/misc/msi-laptop.c
+++ b/drivers/misc/msi-laptop.c
@@ -317,7 +317,8 @@ static int __init msi_init(void)
317 317
318 /* Register backlight stuff */ 318 /* Register backlight stuff */
319 319
320 msibl_device = backlight_device_register("msi-laptop-bl", NULL, &msibl_props); 320 msibl_device = backlight_device_register("msi-laptop-bl", NULL, NULL,
321 &msibl_props);
321 if (IS_ERR(msibl_device)) 322 if (IS_ERR(msibl_device))
322 return PTR_ERR(msibl_device); 323 return PTR_ERR(msibl_device);
323 324
diff --git a/drivers/mmc/at91_mci.c b/drivers/mmc/at91_mci.c
index 08a33c33f6..aa152f3185 100644
--- a/drivers/mmc/at91_mci.c
+++ b/drivers/mmc/at91_mci.c
@@ -768,7 +768,7 @@ static irqreturn_t at91_mmc_det_irq(int irq, void *_host)
768 return IRQ_HANDLED; 768 return IRQ_HANDLED;
769} 769}
770 770
771int at91_mci_get_ro(struct mmc_host *mmc) 771static int at91_mci_get_ro(struct mmc_host *mmc)
772{ 772{
773 int read_only = 0; 773 int read_only = 0;
774 struct at91mci_host *host = mmc_priv(mmc); 774 struct at91mci_host *host = mmc_priv(mmc);
@@ -794,7 +794,7 @@ static const struct mmc_host_ops at91_mci_ops = {
794/* 794/*
795 * Probe for the device 795 * Probe for the device
796 */ 796 */
797static int at91_mci_probe(struct platform_device *pdev) 797static int __init at91_mci_probe(struct platform_device *pdev)
798{ 798{
799 struct mmc_host *mmc; 799 struct mmc_host *mmc;
800 struct at91mci_host *host; 800 struct at91mci_host *host;
@@ -910,7 +910,7 @@ static int at91_mci_probe(struct platform_device *pdev)
910/* 910/*
911 * Remove a device 911 * Remove a device
912 */ 912 */
913static int at91_mci_remove(struct platform_device *pdev) 913static int __exit at91_mci_remove(struct platform_device *pdev)
914{ 914{
915 struct mmc_host *mmc = platform_get_drvdata(pdev); 915 struct mmc_host *mmc = platform_get_drvdata(pdev);
916 struct at91mci_host *host; 916 struct at91mci_host *host;
@@ -972,8 +972,7 @@ static int at91_mci_resume(struct platform_device *pdev)
972#endif 972#endif
973 973
974static struct platform_driver at91_mci_driver = { 974static struct platform_driver at91_mci_driver = {
975 .probe = at91_mci_probe, 975 .remove = __exit_p(at91_mci_remove),
976 .remove = at91_mci_remove,
977 .suspend = at91_mci_suspend, 976 .suspend = at91_mci_suspend,
978 .resume = at91_mci_resume, 977 .resume = at91_mci_resume,
979 .driver = { 978 .driver = {
@@ -984,7 +983,7 @@ static struct platform_driver at91_mci_driver = {
984 983
985static int __init at91_mci_init(void) 984static int __init at91_mci_init(void)
986{ 985{
987 return platform_driver_register(&at91_mci_driver); 986 return platform_driver_probe(&at91_mci_driver, at91_mci_probe);
988} 987}
989 988
990static void __exit at91_mci_exit(void) 989static void __exit at91_mci_exit(void)
diff --git a/drivers/mmc/imxmmc.c b/drivers/mmc/imxmmc.c
index 06e7fcd192..bfb9ff6932 100644
--- a/drivers/mmc/imxmmc.c
+++ b/drivers/mmc/imxmmc.c
@@ -351,9 +351,6 @@ static void imxmci_start_cmd(struct imxmci_host *host, struct mmc_command *cmd,
351 case MMC_RSP_R3: /* short */ 351 case MMC_RSP_R3: /* short */
352 cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R3; 352 cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R3;
353 break; 353 break;
354 case MMC_RSP_R6: /* short CRC */
355 cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R6;
356 break;
357 default: 354 default:
358 break; 355 break;
359 } 356 }
diff --git a/drivers/mmc/mmci.c b/drivers/mmc/mmci.c
index e9b80e9202..ccfe6561be 100644
--- a/drivers/mmc/mmci.c
+++ b/drivers/mmc/mmci.c
@@ -42,6 +42,8 @@ mmci_request_end(struct mmci_host *host, struct mmc_request *mrq)
42{ 42{
43 writel(0, host->base + MMCICOMMAND); 43 writel(0, host->base + MMCICOMMAND);
44 44
45 BUG_ON(host->data);
46
45 host->mrq = NULL; 47 host->mrq = NULL;
46 host->cmd = NULL; 48 host->cmd = NULL;
47 49
@@ -198,6 +200,8 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd,
198 } 200 }
199 201
200 if (!cmd->data || cmd->error != MMC_ERR_NONE) { 202 if (!cmd->data || cmd->error != MMC_ERR_NONE) {
203 if (host->data)
204 mmci_stop_data(host);
201 mmci_request_end(host, cmd->mrq); 205 mmci_request_end(host, cmd->mrq);
202 } else if (!(cmd->data->flags & MMC_DATA_READ)) { 206 } else if (!(cmd->data->flags & MMC_DATA_READ)) {
203 mmci_start_data(host, cmd->data); 207 mmci_start_data(host, cmd->data);
diff --git a/drivers/mmc/omap.c b/drivers/mmc/omap.c
index 435d331e77..d30540b276 100644
--- a/drivers/mmc/omap.c
+++ b/drivers/mmc/omap.c
@@ -91,7 +91,6 @@
91 91
92 92
93#define DRIVER_NAME "mmci-omap" 93#define DRIVER_NAME "mmci-omap"
94#define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE))
95 94
96/* Specifies how often in millisecs to poll for card status changes 95/* Specifies how often in millisecs to poll for card status changes
97 * when the cover switch is open */ 96 * when the cover switch is open */
@@ -204,18 +203,22 @@ mmc_omap_start_command(struct mmc_omap_host *host, struct mmc_command *cmd)
204 cmdtype = 0; 203 cmdtype = 0;
205 204
206 /* Our hardware needs to know exact type */ 205 /* Our hardware needs to know exact type */
207 switch (RSP_TYPE(mmc_resp_type(cmd))) { 206 switch (mmc_resp_type(cmd)) {
208 case RSP_TYPE(MMC_RSP_R1): 207 case MMC_RSP_NONE:
209 /* resp 1, resp 1b */ 208 break;
209 case MMC_RSP_R1:
210 case MMC_RSP_R1B:
211 /* resp 1, 1b, 6, 7 */
210 resptype = 1; 212 resptype = 1;
211 break; 213 break;
212 case RSP_TYPE(MMC_RSP_R2): 214 case MMC_RSP_R2:
213 resptype = 2; 215 resptype = 2;
214 break; 216 break;
215 case RSP_TYPE(MMC_RSP_R3): 217 case MMC_RSP_R3:
216 resptype = 3; 218 resptype = 3;
217 break; 219 break;
218 default: 220 default:
221 dev_err(mmc_dev(host->mmc), "Invalid response type: %04x\n", mmc_resp_type(cmd));
219 break; 222 break;
220 } 223 }
221 224
@@ -581,9 +584,9 @@ static void mmc_omap_switch_timer(unsigned long arg)
581 schedule_work(&host->switch_work); 584 schedule_work(&host->switch_work);
582} 585}
583 586
584static void mmc_omap_switch_handler(void *data) 587static void mmc_omap_switch_handler(struct work_struct *work)
585{ 588{
586 struct mmc_omap_host *host = (struct mmc_omap_host *) data; 589 struct mmc_omap_host *host = container_of(work, struct mmc_omap_host, switch_work);
587 struct mmc_card *card; 590 struct mmc_card *card;
588 static int complained = 0; 591 static int complained = 0;
589 int cards = 0, cover_open; 592 int cards = 0, cover_open;
@@ -1116,7 +1119,7 @@ static int __init mmc_omap_probe(struct platform_device *pdev)
1116 platform_set_drvdata(pdev, host); 1119 platform_set_drvdata(pdev, host);
1117 1120
1118 if (host->switch_pin >= 0) { 1121 if (host->switch_pin >= 0) {
1119 INIT_WORK(&host->switch_work, mmc_omap_switch_handler, host); 1122 INIT_WORK(&host->switch_work, mmc_omap_switch_handler);
1120 init_timer(&host->switch_timer); 1123 init_timer(&host->switch_timer);
1121 host->switch_timer.function = mmc_omap_switch_timer; 1124 host->switch_timer.function = mmc_omap_switch_timer;
1122 host->switch_timer.data = (unsigned long) host; 1125 host->switch_timer.data = (unsigned long) host;
diff --git a/drivers/mmc/pxamci.c b/drivers/mmc/pxamci.c
index 45a9283ce4..6073d998b1 100644
--- a/drivers/mmc/pxamci.c
+++ b/drivers/mmc/pxamci.c
@@ -171,7 +171,7 @@ static void pxamci_start_cmd(struct pxamci_host *host, struct mmc_command *cmd,
171 171
172#define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE)) 172#define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE))
173 switch (RSP_TYPE(mmc_resp_type(cmd))) { 173 switch (RSP_TYPE(mmc_resp_type(cmd))) {
174 case RSP_TYPE(MMC_RSP_R1): /* r1, r1b, r6 */ 174 case RSP_TYPE(MMC_RSP_R1): /* r1, r1b, r6, r7 */
175 cmdat |= CMDAT_RESP_SHORT; 175 cmdat |= CMDAT_RESP_SHORT;
176 break; 176 break;
177 case RSP_TYPE(MMC_RSP_R3): 177 case RSP_TYPE(MMC_RSP_R3):
diff --git a/drivers/mmc/tifm_sd.c b/drivers/mmc/tifm_sd.c
index f18ad998b3..fa4a52886b 100644
--- a/drivers/mmc/tifm_sd.c
+++ b/drivers/mmc/tifm_sd.c
@@ -173,9 +173,6 @@ static unsigned int tifm_sd_op_flags(struct mmc_command *cmd)
173 case MMC_RSP_R3: 173 case MMC_RSP_R3:
174 rc |= TIFM_MMCSD_RSP_R3; 174 rc |= TIFM_MMCSD_RSP_R3;
175 break; 175 break;
176 case MMC_RSP_R6:
177 rc |= TIFM_MMCSD_RSP_R6;
178 break;
179 default: 176 default:
180 BUG(); 177 BUG();
181 } 178 }
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index a304b34c26..26f75c2994 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -164,9 +164,15 @@ config MTD_CHAR
164 memory chips, and also use ioctl() to obtain information about 164 memory chips, and also use ioctl() to obtain information about
165 the device, or to erase parts of it. 165 the device, or to erase parts of it.
166 166
167config MTD_BLKDEVS
168 tristate "Common interface to block layer for MTD 'translation layers'"
169 depends on MTD && BLOCK
170 default n
171
167config MTD_BLOCK 172config MTD_BLOCK
168 tristate "Caching block device access to MTD devices" 173 tristate "Caching block device access to MTD devices"
169 depends on MTD && BLOCK 174 depends on MTD && BLOCK
175 select MTD_BLKDEVS
170 ---help--- 176 ---help---
171 Although most flash chips have an erase size too large to be useful 177 Although most flash chips have an erase size too large to be useful
172 as block devices, it is possible to use MTD devices which are based 178 as block devices, it is possible to use MTD devices which are based
@@ -189,6 +195,7 @@ config MTD_BLOCK
189config MTD_BLOCK_RO 195config MTD_BLOCK_RO
190 tristate "Readonly block device access to MTD devices" 196 tristate "Readonly block device access to MTD devices"
191 depends on MTD_BLOCK!=y && MTD && BLOCK 197 depends on MTD_BLOCK!=y && MTD && BLOCK
198 select MTD_BLKDEVS
192 help 199 help
193 This allows you to mount read-only file systems (such as cramfs) 200 This allows you to mount read-only file systems (such as cramfs)
194 from an MTD device, without the overhead (and danger) of the caching 201 from an MTD device, without the overhead (and danger) of the caching
@@ -200,6 +207,7 @@ config MTD_BLOCK_RO
200config FTL 207config FTL
201 tristate "FTL (Flash Translation Layer) support" 208 tristate "FTL (Flash Translation Layer) support"
202 depends on MTD && BLOCK 209 depends on MTD && BLOCK
210 select MTD_BLKDEVS
203 ---help--- 211 ---help---
204 This provides support for the original Flash Translation Layer which 212 This provides support for the original Flash Translation Layer which
205 is part of the PCMCIA specification. It uses a kind of pseudo- 213 is part of the PCMCIA specification. It uses a kind of pseudo-
@@ -216,6 +224,7 @@ config FTL
216config NFTL 224config NFTL
217 tristate "NFTL (NAND Flash Translation Layer) support" 225 tristate "NFTL (NAND Flash Translation Layer) support"
218 depends on MTD && BLOCK 226 depends on MTD && BLOCK
227 select MTD_BLKDEVS
219 ---help--- 228 ---help---
220 This provides support for the NAND Flash Translation Layer which is 229 This provides support for the NAND Flash Translation Layer which is
221 used on M-Systems' DiskOnChip devices. It uses a kind of pseudo- 230 used on M-Systems' DiskOnChip devices. It uses a kind of pseudo-
@@ -239,6 +248,7 @@ config NFTL_RW
239config INFTL 248config INFTL
240 tristate "INFTL (Inverse NAND Flash Translation Layer) support" 249 tristate "INFTL (Inverse NAND Flash Translation Layer) support"
241 depends on MTD && BLOCK 250 depends on MTD && BLOCK
251 select MTD_BLKDEVS
242 ---help--- 252 ---help---
243 This provides support for the Inverse NAND Flash Translation 253 This provides support for the Inverse NAND Flash Translation
244 Layer which is used on M-Systems' newer DiskOnChip devices. It 254 Layer which is used on M-Systems' newer DiskOnChip devices. It
@@ -256,6 +266,7 @@ config INFTL
256config RFD_FTL 266config RFD_FTL
257 tristate "Resident Flash Disk (Flash Translation Layer) support" 267 tristate "Resident Flash Disk (Flash Translation Layer) support"
258 depends on MTD && BLOCK 268 depends on MTD && BLOCK
269 select MTD_BLKDEVS
259 ---help--- 270 ---help---
260 This provides support for the flash translation layer known 271 This provides support for the flash translation layer known
261 as the Resident Flash Disk (RFD), as used by the Embedded BIOS 272 as the Resident Flash Disk (RFD), as used by the Embedded BIOS
@@ -265,8 +276,8 @@ config RFD_FTL
265 276
266config SSFDC 277config SSFDC
267 tristate "NAND SSFDC (SmartMedia) read only translation layer" 278 tristate "NAND SSFDC (SmartMedia) read only translation layer"
268 depends on MTD 279 depends on MTD && BLOCK
269 default n 280 select MTD_BLKDEVS
270 help 281 help
271 This enables read only access to SmartMedia formatted NAND 282 This enables read only access to SmartMedia formatted NAND
272 flash. You can mount it with FAT file system. 283 flash. You can mount it with FAT file system.
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 1e36b9aed9..c130e6261a 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -15,13 +15,14 @@ obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
15 15
16# 'Users' - code which presents functionality to userspace. 16# 'Users' - code which presents functionality to userspace.
17obj-$(CONFIG_MTD_CHAR) += mtdchar.o 17obj-$(CONFIG_MTD_CHAR) += mtdchar.o
18obj-$(CONFIG_MTD_BLOCK) += mtdblock.o mtd_blkdevs.o 18obj-$(CONFIG_MTD_BLKDEVS) += mtd_blkdevs.o
19obj-$(CONFIG_MTD_BLOCK_RO) += mtdblock_ro.o mtd_blkdevs.o 19obj-$(CONFIG_MTD_BLOCK) += mtdblock.o
20obj-$(CONFIG_FTL) += ftl.o mtd_blkdevs.o 20obj-$(CONFIG_MTD_BLOCK_RO) += mtdblock_ro.o
21obj-$(CONFIG_NFTL) += nftl.o mtd_blkdevs.o 21obj-$(CONFIG_FTL) += ftl.o
22obj-$(CONFIG_INFTL) += inftl.o mtd_blkdevs.o 22obj-$(CONFIG_NFTL) += nftl.o
23obj-$(CONFIG_RFD_FTL) += rfd_ftl.o mtd_blkdevs.o 23obj-$(CONFIG_INFTL) += inftl.o
24obj-$(CONFIG_SSFDC) += ssfdc.o mtd_blkdevs.o 24obj-$(CONFIG_RFD_FTL) += rfd_ftl.o
25obj-$(CONFIG_SSFDC) += ssfdc.o
25 26
26nftl-objs := nftlcore.o nftlmount.o 27nftl-objs := nftlcore.o nftlmount.o
27inftl-objs := inftlcore.o inftlmount.o 28inftl-objs := inftlcore.o inftlmount.o
diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
index 6a45be0456..52d51eb91c 100644
--- a/drivers/mtd/afs.c
+++ b/drivers/mtd/afs.c
@@ -207,11 +207,10 @@ static int parse_afs_partitions(struct mtd_info *mtd,
207 if (!sz) 207 if (!sz)
208 return ret; 208 return ret;
209 209
210 parts = kmalloc(sz, GFP_KERNEL); 210 parts = kzalloc(sz, GFP_KERNEL);
211 if (!parts) 211 if (!parts)
212 return -ENOMEM; 212 return -ENOMEM;
213 213
214 memset(parts, 0, sz);
215 str = (char *)(parts + idx); 214 str = (char *)(parts + idx);
216 215
217 /* 216 /*
diff --git a/drivers/mtd/chips/amd_flash.c b/drivers/mtd/chips/amd_flash.c
index 16eaca69fb..e7999f15d8 100644
--- a/drivers/mtd/chips/amd_flash.c
+++ b/drivers/mtd/chips/amd_flash.c
@@ -643,13 +643,12 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
643 int reg_idx; 643 int reg_idx;
644 int offset; 644 int offset;
645 645
646 mtd = (struct mtd_info*)kmalloc(sizeof(*mtd), GFP_KERNEL); 646 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
647 if (!mtd) { 647 if (!mtd) {
648 printk(KERN_WARNING 648 printk(KERN_WARNING
649 "%s: kmalloc failed for info structure\n", map->name); 649 "%s: kmalloc failed for info structure\n", map->name);
650 return NULL; 650 return NULL;
651 } 651 }
652 memset(mtd, 0, sizeof(*mtd));
653 mtd->priv = map; 652 mtd->priv = map;
654 653
655 memset(&temp, 0, sizeof(temp)); 654 memset(&temp, 0, sizeof(temp));
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 296159ec51..f69184a92e 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -337,12 +337,11 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
337 struct mtd_info *mtd; 337 struct mtd_info *mtd;
338 int i; 338 int i;
339 339
340 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 340 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
341 if (!mtd) { 341 if (!mtd) {
342 printk(KERN_ERR "Failed to allocate memory for MTD device\n"); 342 printk(KERN_ERR "Failed to allocate memory for MTD device\n");
343 return NULL; 343 return NULL;
344 } 344 }
345 memset(mtd, 0, sizeof(*mtd));
346 mtd->priv = map; 345 mtd->priv = map;
347 mtd->type = MTD_NORFLASH; 346 mtd->type = MTD_NORFLASH;
348 347
@@ -2224,6 +2223,8 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
2224 case FL_CFI_QUERY: 2223 case FL_CFI_QUERY:
2225 case FL_JEDEC_QUERY: 2224 case FL_JEDEC_QUERY:
2226 if (chip->oldstate == FL_READY) { 2225 if (chip->oldstate == FL_READY) {
2226 /* place the chip in a known state before suspend */
2227 map_write(map, CMD(0xFF), cfi->chips[i].start);
2227 chip->oldstate = chip->state; 2228 chip->oldstate = chip->state;
2228 chip->state = FL_PM_SUSPENDED; 2229 chip->state = FL_PM_SUSPENDED;
2229 /* No need to wake_up() on this state change - 2230 /* No need to wake_up() on this state change -
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 702ae4cd86..e3acd398fb 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -48,6 +48,7 @@
48#define MANUFACTURER_ATMEL 0x001F 48#define MANUFACTURER_ATMEL 0x001F
49#define MANUFACTURER_SST 0x00BF 49#define MANUFACTURER_SST 0x00BF
50#define SST49LF004B 0x0060 50#define SST49LF004B 0x0060
51#define SST49LF040B 0x0050
51#define SST49LF008A 0x005a 52#define SST49LF008A 0x005a
52#define AT49BV6416 0x00d6 53#define AT49BV6416 0x00d6
53 54
@@ -233,6 +234,7 @@ static struct cfi_fixup cfi_fixup_table[] = {
233}; 234};
234static struct cfi_fixup jedec_fixup_table[] = { 235static struct cfi_fixup jedec_fixup_table[] = {
235 { MANUFACTURER_SST, SST49LF004B, fixup_use_fwh_lock, NULL, }, 236 { MANUFACTURER_SST, SST49LF004B, fixup_use_fwh_lock, NULL, },
237 { MANUFACTURER_SST, SST49LF040B, fixup_use_fwh_lock, NULL, },
236 { MANUFACTURER_SST, SST49LF008A, fixup_use_fwh_lock, NULL, }, 238 { MANUFACTURER_SST, SST49LF008A, fixup_use_fwh_lock, NULL, },
237 { 0, 0, NULL, NULL } 239 { 0, 0, NULL, NULL }
238}; 240};
@@ -255,12 +257,11 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
255 struct mtd_info *mtd; 257 struct mtd_info *mtd;
256 int i; 258 int i;
257 259
258 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 260 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
259 if (!mtd) { 261 if (!mtd) {
260 printk(KERN_WARNING "Failed to allocate memory for MTD device\n"); 262 printk(KERN_WARNING "Failed to allocate memory for MTD device\n");
261 return NULL; 263 return NULL;
262 } 264 }
263 memset(mtd, 0, sizeof(*mtd));
264 mtd->priv = map; 265 mtd->priv = map;
265 mtd->type = MTD_NORFLASH; 266 mtd->type = MTD_NORFLASH;
266 267
@@ -519,10 +520,12 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
519 if (mode == FL_WRITING) /* FIXME: Erase-suspend-program appears broken. */ 520 if (mode == FL_WRITING) /* FIXME: Erase-suspend-program appears broken. */
520 goto sleep; 521 goto sleep;
521 522
522 if (!(mode == FL_READY || mode == FL_POINT 523 if (!( mode == FL_READY
524 || mode == FL_POINT
523 || !cfip 525 || !cfip
524 || (mode == FL_WRITING && (cfip->EraseSuspend & 0x2)) 526 || (mode == FL_WRITING && (cfip->EraseSuspend & 0x2))
525 || (mode == FL_WRITING && (cfip->EraseSuspend & 0x1)))) 527 || (mode == FL_WRITING && (cfip->EraseSuspend & 0x1)
528 )))
526 goto sleep; 529 goto sleep;
527 530
528 /* We could check to see if we're trying to access the sector 531 /* We could check to see if we're trying to access the sector
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index fae70a5db5..d56849f5f1 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -172,7 +172,7 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
172 int i,j; 172 int i,j;
173 unsigned long devsize = (1<<cfi->cfiq->DevSize) * cfi->interleave; 173 unsigned long devsize = (1<<cfi->cfiq->DevSize) * cfi->interleave;
174 174
175 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 175 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
176 //printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips); 176 //printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips);
177 177
178 if (!mtd) { 178 if (!mtd) {
@@ -181,7 +181,6 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
181 return NULL; 181 return NULL;
182 } 182 }
183 183
184 memset(mtd, 0, sizeof(*mtd));
185 mtd->priv = map; 184 mtd->priv = map;
186 mtd->type = MTD_NORFLASH; 185 mtd->type = MTD_NORFLASH;
187 mtd->size = devsize * cfi->numchips; 186 mtd->size = devsize * cfi->numchips;
diff --git a/drivers/mtd/chips/gen_probe.c b/drivers/mtd/chips/gen_probe.c
index cdb0f590b4..2eb696d7b9 100644
--- a/drivers/mtd/chips/gen_probe.c
+++ b/drivers/mtd/chips/gen_probe.c
@@ -40,7 +40,7 @@ struct mtd_info *mtd_do_chip_probe(struct map_info *map, struct chip_probe *cp)
40 if (mtd) { 40 if (mtd) {
41 if (mtd->size > map->size) { 41 if (mtd->size > map->size) {
42 printk(KERN_WARNING "Reducing visibility of %ldKiB chip to %ldKiB\n", 42 printk(KERN_WARNING "Reducing visibility of %ldKiB chip to %ldKiB\n",
43 (unsigned long)mtd->size >> 10, 43 (unsigned long)mtd->size >> 10,
44 (unsigned long)map->size >> 10); 44 (unsigned long)map->size >> 10);
45 mtd->size = map->size; 45 mtd->size = map->size;
46 } 46 }
@@ -113,13 +113,12 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
113 } 113 }
114 114
115 mapsize = (max_chips + BITS_PER_LONG-1) / BITS_PER_LONG; 115 mapsize = (max_chips + BITS_PER_LONG-1) / BITS_PER_LONG;
116 chip_map = kmalloc(mapsize, GFP_KERNEL); 116 chip_map = kzalloc(mapsize, GFP_KERNEL);
117 if (!chip_map) { 117 if (!chip_map) {
118 printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name); 118 printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name);
119 kfree(cfi.cfiq); 119 kfree(cfi.cfiq);
120 return NULL; 120 return NULL;
121 } 121 }
122 memset (chip_map, 0, mapsize);
123 122
124 set_bit(0, chip_map); /* Mark first chip valid */ 123 set_bit(0, chip_map); /* Mark first chip valid */
125 124
diff --git a/drivers/mtd/chips/jedec.c b/drivers/mtd/chips/jedec.c
index 2c3f019197..14e57b2bf8 100644
--- a/drivers/mtd/chips/jedec.c
+++ b/drivers/mtd/chips/jedec.c
@@ -116,11 +116,10 @@ static struct mtd_info *jedec_probe(struct map_info *map)
116 char Part[200]; 116 char Part[200];
117 memset(&priv,0,sizeof(priv)); 117 memset(&priv,0,sizeof(priv));
118 118
119 MTD = kmalloc(sizeof(struct mtd_info) + sizeof(struct jedec_private), GFP_KERNEL); 119 MTD = kzalloc(sizeof(struct mtd_info) + sizeof(struct jedec_private), GFP_KERNEL);
120 if (!MTD) 120 if (!MTD)
121 return NULL; 121 return NULL;
122 122
123 memset(MTD, 0, sizeof(struct mtd_info) + sizeof(struct jedec_private));
124 priv = (struct jedec_private *)&MTD[1]; 123 priv = (struct jedec_private *)&MTD[1];
125 124
126 my_bank_size = map->size; 125 my_bank_size = map->size;
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index 1154dac715..58e561e876 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -154,6 +154,7 @@
154#define SST39SF010A 0x00B5 154#define SST39SF010A 0x00B5
155#define SST39SF020A 0x00B6 155#define SST39SF020A 0x00B6
156#define SST49LF004B 0x0060 156#define SST49LF004B 0x0060
157#define SST49LF040B 0x0050
157#define SST49LF008A 0x005a 158#define SST49LF008A 0x005a
158#define SST49LF030A 0x001C 159#define SST49LF030A 0x001C
159#define SST49LF040A 0x0051 160#define SST49LF040A 0x0051
@@ -1401,6 +1402,20 @@ static const struct amd_flash_info jedec_table[] = {
1401 } 1402 }
1402 }, { 1403 }, {
1403 .mfr_id = MANUFACTURER_SST, 1404 .mfr_id = MANUFACTURER_SST,
1405 .dev_id = SST49LF040B,
1406 .name = "SST 49LF040B",
1407 .uaddr = {
1408 [0] = MTD_UADDR_0x5555_0x2AAA /* x8 */
1409 },
1410 .DevSize = SIZE_512KiB,
1411 .CmdSet = P_ID_AMD_STD,
1412 .NumEraseRegions= 1,
1413 .regions = {
1414 ERASEINFO(0x01000,128),
1415 }
1416 }, {
1417
1418 .mfr_id = MANUFACTURER_SST,
1404 .dev_id = SST49LF004B, 1419 .dev_id = SST49LF004B,
1405 .name = "SST 49LF004B", 1420 .name = "SST 49LF004B",
1406 .uaddr = { 1421 .uaddr = {
@@ -1874,7 +1889,7 @@ static int cfi_jedec_setup(struct cfi_private *p_cfi, int index)
1874 1889
1875 1890
1876/* 1891/*
1877 * There is a BIG problem properly ID'ing the JEDEC devic and guaranteeing 1892 * There is a BIG problem properly ID'ing the JEDEC device and guaranteeing
1878 * the mapped address, unlock addresses, and proper chip ID. This function 1893 * the mapped address, unlock addresses, and proper chip ID. This function
1879 * attempts to minimize errors. It is doubtfull that this probe will ever 1894 * attempts to minimize errors. It is doubtfull that this probe will ever
1880 * be perfect - consequently there should be some module parameters that 1895 * be perfect - consequently there should be some module parameters that
diff --git a/drivers/mtd/chips/map_absent.c b/drivers/mtd/chips/map_absent.c
index ac01a949b6..fc478c0f93 100644
--- a/drivers/mtd/chips/map_absent.c
+++ b/drivers/mtd/chips/map_absent.c
@@ -47,13 +47,11 @@ static struct mtd_info *map_absent_probe(struct map_info *map)
47{ 47{
48 struct mtd_info *mtd; 48 struct mtd_info *mtd;
49 49
50 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 50 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
51 if (!mtd) { 51 if (!mtd) {
52 return NULL; 52 return NULL;
53 } 53 }
54 54
55 memset(mtd, 0, sizeof(*mtd));
56
57 map->fldrv = &map_absent_chipdrv; 55 map->fldrv = &map_absent_chipdrv;
58 mtd->priv = map; 56 mtd->priv = map;
59 mtd->name = map->name; 57 mtd->name = map->name;
diff --git a/drivers/mtd/chips/map_ram.c b/drivers/mtd/chips/map_ram.c
index 3a66680abf..5cb6d52636 100644
--- a/drivers/mtd/chips/map_ram.c
+++ b/drivers/mtd/chips/map_ram.c
@@ -55,12 +55,10 @@ static struct mtd_info *map_ram_probe(struct map_info *map)
55#endif 55#endif
56 /* OK. It seems to be RAM. */ 56 /* OK. It seems to be RAM. */
57 57
58 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 58 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
59 if (!mtd) 59 if (!mtd)
60 return NULL; 60 return NULL;
61 61
62 memset(mtd, 0, sizeof(*mtd));
63
64 map->fldrv = &mapram_chipdrv; 62 map->fldrv = &mapram_chipdrv;
65 mtd->priv = map; 63 mtd->priv = map;
66 mtd->name = map->name; 64 mtd->name = map->name;
diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c
index 1b328b1378..cb27f85507 100644
--- a/drivers/mtd/chips/map_rom.c
+++ b/drivers/mtd/chips/map_rom.c
@@ -31,12 +31,10 @@ static struct mtd_info *map_rom_probe(struct map_info *map)
31{ 31{
32 struct mtd_info *mtd; 32 struct mtd_info *mtd;
33 33
34 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 34 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
35 if (!mtd) 35 if (!mtd)
36 return NULL; 36 return NULL;
37 37
38 memset(mtd, 0, sizeof(*mtd));
39
40 map->fldrv = &maprom_chipdrv; 38 map->fldrv = &maprom_chipdrv;
41 mtd->priv = map; 39 mtd->priv = map;
42 mtd->name = map->name; 40 mtd->name = map->name;
diff --git a/drivers/mtd/chips/sharp.c b/drivers/mtd/chips/sharp.c
index 967abbecdf..c9cd3d21cc 100644
--- a/drivers/mtd/chips/sharp.c
+++ b/drivers/mtd/chips/sharp.c
@@ -112,18 +112,16 @@ static struct mtd_info *sharp_probe(struct map_info *map)
112 struct sharp_info *sharp = NULL; 112 struct sharp_info *sharp = NULL;
113 int width; 113 int width;
114 114
115 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 115 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
116 if(!mtd) 116 if(!mtd)
117 return NULL; 117 return NULL;
118 118
119 sharp = kmalloc(sizeof(*sharp), GFP_KERNEL); 119 sharp = kzalloc(sizeof(*sharp), GFP_KERNEL);
120 if(!sharp) { 120 if(!sharp) {
121 kfree(mtd); 121 kfree(mtd);
122 return NULL; 122 return NULL;
123 } 123 }
124 124
125 memset(mtd, 0, sizeof(*mtd));
126
127 width = sharp_probe_map(map,mtd); 125 width = sharp_probe_map(map,mtd);
128 if(!width){ 126 if(!width){
129 kfree(mtd); 127 kfree(mtd);
@@ -143,7 +141,6 @@ static struct mtd_info *sharp_probe(struct map_info *map)
143 mtd->writesize = 1; 141 mtd->writesize = 1;
144 mtd->name = map->name; 142 mtd->name = map->name;
145 143
146 memset(sharp, 0, sizeof(*sharp));
147 sharp->chipshift = 23; 144 sharp->chipshift = 23;
148 sharp->numchips = 1; 145 sharp->numchips = 1;
149 sharp->chips[0].start = 0; 146 sharp->chips[0].start = 0;
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index a7a7bfe338..23fab14f16 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -163,13 +163,12 @@ static struct mtd_partition * newpart(char *s,
163 *num_parts = this_part + 1; 163 *num_parts = this_part + 1;
164 alloc_size = *num_parts * sizeof(struct mtd_partition) + 164 alloc_size = *num_parts * sizeof(struct mtd_partition) +
165 extra_mem_size; 165 extra_mem_size;
166 parts = kmalloc(alloc_size, GFP_KERNEL); 166 parts = kzalloc(alloc_size, GFP_KERNEL);
167 if (!parts) 167 if (!parts)
168 { 168 {
169 printk(KERN_ERR ERRP "out of memory\n"); 169 printk(KERN_ERR ERRP "out of memory\n");
170 return NULL; 170 return NULL;
171 } 171 }
172 memset(parts, 0, alloc_size);
173 extra_mem = (unsigned char *)(parts + *num_parts); 172 extra_mem = (unsigned char *)(parts + *num_parts);
174 } 173 }
175 /* enter this partition (offset will be calculated later if it is zero at this point) */ 174 /* enter this partition (offset will be calculated later if it is zero at this point) */
@@ -346,7 +345,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
346 * 345 *
347 * This function needs to be visible for bootloaders. 346 * This function needs to be visible for bootloaders.
348 */ 347 */
349int mtdpart_setup(char *s) 348static int mtdpart_setup(char *s)
350{ 349{
351 cmdline = s; 350 cmdline = s;
352 return 1; 351 return 1;
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 401c6a294b..6d917a4daa 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -295,10 +295,9 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
295 if (!devname) 295 if (!devname)
296 return NULL; 296 return NULL;
297 297
298 dev = kmalloc(sizeof(struct block2mtd_dev), GFP_KERNEL); 298 dev = kzalloc(sizeof(struct block2mtd_dev), GFP_KERNEL);
299 if (!dev) 299 if (!dev)
300 return NULL; 300 return NULL;
301 memset(dev, 0, sizeof(*dev));
302 301
303 /* Get a handle on the device */ 302 /* Get a handle on the device */
304 bdev = open_bdev_excl(devname, O_RDWR, NULL); 303 bdev = open_bdev_excl(devname, O_RDWR, NULL);
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 334e078ffa..78c2511ae9 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -437,7 +437,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
437 * or JEDEC get-id commands. Try them ... 437 * or JEDEC get-id commands. Try them ...
438 */ 438 */
439 DEBUG(MTD_DEBUG_LEVEL1, "%s: no chip id\n", 439 DEBUG(MTD_DEBUG_LEVEL1, "%s: no chip id\n",
440 flash->spi->dev.bus_id); 440 spi->dev.bus_id);
441 return -ENODEV; 441 return -ENODEV;
442 } 442 }
443 443
@@ -447,7 +447,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
447 } 447 }
448 if (i == ARRAY_SIZE(m25p_data)) { 448 if (i == ARRAY_SIZE(m25p_data)) {
449 DEBUG(MTD_DEBUG_LEVEL1, "%s: unrecognized id %s\n", 449 DEBUG(MTD_DEBUG_LEVEL1, "%s: unrecognized id %s\n",
450 flash->spi->dev.bus_id, data->type); 450 spi->dev.bus_id, data->type);
451 return -ENODEV; 451 return -ENODEV;
452 } 452 }
453 453
diff --git a/drivers/mtd/devices/ms02-nv.c b/drivers/mtd/devices/ms02-nv.c
index 08dfb899b2..9cff119a20 100644
--- a/drivers/mtd/devices/ms02-nv.c
+++ b/drivers/mtd/devices/ms02-nv.c
@@ -131,11 +131,10 @@ static int __init ms02nv_init_one(ulong addr)
131 int ret = -ENODEV; 131 int ret = -ENODEV;
132 132
133 /* The module decodes 8MiB of address space. */ 133 /* The module decodes 8MiB of address space. */
134 mod_res = kmalloc(sizeof(*mod_res), GFP_KERNEL); 134 mod_res = kzalloc(sizeof(*mod_res), GFP_KERNEL);
135 if (!mod_res) 135 if (!mod_res)
136 return -ENOMEM; 136 return -ENOMEM;
137 137
138 memset(mod_res, 0, sizeof(*mod_res));
139 mod_res->name = ms02nv_name; 138 mod_res->name = ms02nv_name;
140 mod_res->start = addr; 139 mod_res->start = addr;
141 mod_res->end = addr + MS02NV_SLOT_SIZE - 1; 140 mod_res->end = addr + MS02NV_SLOT_SIZE - 1;
@@ -153,24 +152,21 @@ static int __init ms02nv_init_one(ulong addr)
153 } 152 }
154 153
155 ret = -ENOMEM; 154 ret = -ENOMEM;
156 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 155 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
157 if (!mtd) 156 if (!mtd)
158 goto err_out_mod_res_rel; 157 goto err_out_mod_res_rel;
159 memset(mtd, 0, sizeof(*mtd)); 158 mp = kzalloc(sizeof(*mp), GFP_KERNEL);
160 mp = kmalloc(sizeof(*mp), GFP_KERNEL);
161 if (!mp) 159 if (!mp)
162 goto err_out_mtd; 160 goto err_out_mtd;
163 memset(mp, 0, sizeof(*mp));
164 161
165 mtd->priv = mp; 162 mtd->priv = mp;
166 mp->resource.module = mod_res; 163 mp->resource.module = mod_res;
167 164
168 /* Firmware's diagnostic NVRAM area. */ 165 /* Firmware's diagnostic NVRAM area. */
169 diag_res = kmalloc(sizeof(*diag_res), GFP_KERNEL); 166 diag_res = kzalloc(sizeof(*diag_res), GFP_KERNEL);
170 if (!diag_res) 167 if (!diag_res)
171 goto err_out_mp; 168 goto err_out_mp;
172 169
173 memset(diag_res, 0, sizeof(*diag_res));
174 diag_res->name = ms02nv_res_diag_ram; 170 diag_res->name = ms02nv_res_diag_ram;
175 diag_res->start = addr; 171 diag_res->start = addr;
176 diag_res->end = addr + MS02NV_RAM - 1; 172 diag_res->end = addr + MS02NV_RAM - 1;
@@ -180,11 +176,10 @@ static int __init ms02nv_init_one(ulong addr)
180 mp->resource.diag_ram = diag_res; 176 mp->resource.diag_ram = diag_res;
181 177
182 /* User-available general-purpose NVRAM area. */ 178 /* User-available general-purpose NVRAM area. */
183 user_res = kmalloc(sizeof(*user_res), GFP_KERNEL); 179 user_res = kzalloc(sizeof(*user_res), GFP_KERNEL);
184 if (!user_res) 180 if (!user_res)
185 goto err_out_diag_res; 181 goto err_out_diag_res;
186 182
187 memset(user_res, 0, sizeof(*user_res));
188 user_res->name = ms02nv_res_user_ram; 183 user_res->name = ms02nv_res_user_ram;
189 user_res->start = addr + MS02NV_RAM; 184 user_res->start = addr + MS02NV_RAM;
190 user_res->end = addr + size - 1; 185 user_res->end = addr + size - 1;
@@ -194,11 +189,10 @@ static int __init ms02nv_init_one(ulong addr)
194 mp->resource.user_ram = user_res; 189 mp->resource.user_ram = user_res;
195 190
196 /* Control and status register. */ 191 /* Control and status register. */
197 csr_res = kmalloc(sizeof(*csr_res), GFP_KERNEL); 192 csr_res = kzalloc(sizeof(*csr_res), GFP_KERNEL);
198 if (!csr_res) 193 if (!csr_res)
199 goto err_out_user_res; 194 goto err_out_user_res;
200 195
201 memset(csr_res, 0, sizeof(*csr_res));
202 csr_res->name = ms02nv_res_csr; 196 csr_res->name = ms02nv_res_csr;
203 csr_res->start = addr + MS02NV_CSR; 197 csr_res->start = addr + MS02NV_CSR;
204 csr_res->end = addr + MS02NV_CSR + 3; 198 csr_res->end = addr + MS02NV_CSR + 3;
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index 0a7e86859b..a987e917f4 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -480,7 +480,7 @@ add_dataflash(struct spi_device *spi, char *name,
480 device->writesize = pagesize; 480 device->writesize = pagesize;
481 device->owner = THIS_MODULE; 481 device->owner = THIS_MODULE;
482 device->type = MTD_DATAFLASH; 482 device->type = MTD_DATAFLASH;
483 device->flags = MTD_CAP_NORFLASH; 483 device->flags = MTD_WRITEABLE;
484 device->erase = dataflash_erase; 484 device->erase = dataflash_erase;
485 device->read = dataflash_read; 485 device->read = dataflash_read;
486 device->write = dataflash_write; 486 device->write = dataflash_write;
@@ -536,7 +536,7 @@ static int __devinit dataflash_probe(struct spi_device *spi)
536 if (status <= 0 || status == 0xff) { 536 if (status <= 0 || status == 0xff) {
537 DEBUG(MTD_DEBUG_LEVEL1, "%s: status error %d\n", 537 DEBUG(MTD_DEBUG_LEVEL1, "%s: status error %d\n",
538 spi->dev.bus_id, status); 538 spi->dev.bus_id, status);
539 if (status == 0xff) 539 if (status == 0 || status == 0xff)
540 status = -ENODEV; 540 status = -ENODEV;
541 return status; 541 return status;
542 } 542 }
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 6c7337f9eb..56cc1ca7ff 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -126,12 +126,10 @@ static int register_device(char *name, unsigned long start, unsigned long len)
126 struct phram_mtd_list *new; 126 struct phram_mtd_list *new;
127 int ret = -ENOMEM; 127 int ret = -ENOMEM;
128 128
129 new = kmalloc(sizeof(*new), GFP_KERNEL); 129 new = kzalloc(sizeof(*new), GFP_KERNEL);
130 if (!new) 130 if (!new)
131 goto out0; 131 goto out0;
132 132
133 memset(new, 0, sizeof(*new));
134
135 ret = -EIO; 133 ret = -EIO;
136 new->mtd.priv = ioremap(start, len); 134 new->mtd.priv = ioremap(start, len);
137 if (!new->mtd.priv) { 135 if (!new->mtd.priv) {
diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c
index 542a0c0090..5f49248a48 100644
--- a/drivers/mtd/devices/slram.c
+++ b/drivers/mtd/devices/slram.c
@@ -168,19 +168,16 @@ static int register_device(char *name, unsigned long start, unsigned long length
168 E("slram: Cannot allocate new MTD device.\n"); 168 E("slram: Cannot allocate new MTD device.\n");
169 return(-ENOMEM); 169 return(-ENOMEM);
170 } 170 }
171 (*curmtd)->mtdinfo = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); 171 (*curmtd)->mtdinfo = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
172 (*curmtd)->next = NULL; 172 (*curmtd)->next = NULL;
173 173
174 if ((*curmtd)->mtdinfo) { 174 if ((*curmtd)->mtdinfo) {
175 memset((char *)(*curmtd)->mtdinfo, 0, sizeof(struct mtd_info));
176 (*curmtd)->mtdinfo->priv = 175 (*curmtd)->mtdinfo->priv =
177 kmalloc(sizeof(slram_priv_t), GFP_KERNEL); 176 kzalloc(sizeof(slram_priv_t), GFP_KERNEL);
178 177
179 if (!(*curmtd)->mtdinfo->priv) { 178 if (!(*curmtd)->mtdinfo->priv) {
180 kfree((*curmtd)->mtdinfo); 179 kfree((*curmtd)->mtdinfo);
181 (*curmtd)->mtdinfo = NULL; 180 (*curmtd)->mtdinfo = NULL;
182 } else {
183 memset((*curmtd)->mtdinfo->priv,0,sizeof(slram_priv_t));
184 } 181 }
185 } 182 }
186 183
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index 8a878b34ec..24235d4f1d 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -1033,7 +1033,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
1033{ 1033{
1034 partition_t *partition; 1034 partition_t *partition;
1035 1035
1036 partition = kmalloc(sizeof(partition_t), GFP_KERNEL); 1036 partition = kzalloc(sizeof(partition_t), GFP_KERNEL);
1037 1037
1038 if (!partition) { 1038 if (!partition) {
1039 printk(KERN_WARNING "No memory to scan for FTL on %s\n", 1039 printk(KERN_WARNING "No memory to scan for FTL on %s\n",
@@ -1041,8 +1041,6 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
1041 return; 1041 return;
1042 } 1042 }
1043 1043
1044 memset(partition, 0, sizeof(partition_t));
1045
1046 partition->mbd.mtd = mtd; 1044 partition->mbd.mtd = mtd;
1047 1045
1048 if ((scan_header(partition) == 0) && 1046 if ((scan_header(partition) == 0) &&
@@ -1054,7 +1052,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
1054 le32_to_cpu(partition->header.FormattedSize) >> 10); 1052 le32_to_cpu(partition->header.FormattedSize) >> 10);
1055#endif 1053#endif
1056 partition->mbd.size = le32_to_cpu(partition->header.FormattedSize) >> 9; 1054 partition->mbd.size = le32_to_cpu(partition->header.FormattedSize) >> 9;
1057 partition->mbd.blksize = SECTOR_SIZE; 1055
1058 partition->mbd.tr = tr; 1056 partition->mbd.tr = tr;
1059 partition->mbd.devnum = -1; 1057 partition->mbd.devnum = -1;
1060 if (!add_mtd_blktrans_dev((void *)partition)) 1058 if (!add_mtd_blktrans_dev((void *)partition))
@@ -1076,6 +1074,7 @@ struct mtd_blktrans_ops ftl_tr = {
1076 .name = "ftl", 1074 .name = "ftl",
1077 .major = FTL_MAJOR, 1075 .major = FTL_MAJOR,
1078 .part_bits = PART_BITS, 1076 .part_bits = PART_BITS,
1077 .blksize = SECTOR_SIZE,
1079 .readsect = ftl_readsect, 1078 .readsect = ftl_readsect,
1080 .writesect = ftl_writesect, 1079 .writesect = ftl_writesect,
1081 .getgeo = ftl_getgeo, 1080 .getgeo = ftl_getgeo,
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index 4116535805..b0e396504e 100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
@@ -67,17 +67,16 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
67 67
68 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: add_mtd for %s\n", mtd->name); 68 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: add_mtd for %s\n", mtd->name);
69 69
70 inftl = kmalloc(sizeof(*inftl), GFP_KERNEL); 70 inftl = kzalloc(sizeof(*inftl), GFP_KERNEL);
71 71
72 if (!inftl) { 72 if (!inftl) {
73 printk(KERN_WARNING "INFTL: Out of memory for data structures\n"); 73 printk(KERN_WARNING "INFTL: Out of memory for data structures\n");
74 return; 74 return;
75 } 75 }
76 memset(inftl, 0, sizeof(*inftl));
77 76
78 inftl->mbd.mtd = mtd; 77 inftl->mbd.mtd = mtd;
79 inftl->mbd.devnum = -1; 78 inftl->mbd.devnum = -1;
80 inftl->mbd.blksize = 512; 79
81 inftl->mbd.tr = tr; 80 inftl->mbd.tr = tr;
82 81
83 if (INFTL_mount(inftl) < 0) { 82 if (INFTL_mount(inftl) < 0) {
@@ -163,10 +162,9 @@ int inftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
163 ops.ooblen = len; 162 ops.ooblen = len;
164 ops.oobbuf = buf; 163 ops.oobbuf = buf;
165 ops.datbuf = NULL; 164 ops.datbuf = NULL;
166 ops.len = len;
167 165
168 res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 166 res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
169 *retlen = ops.retlen; 167 *retlen = ops.oobretlen;
170 return res; 168 return res;
171} 169}
172 170
@@ -184,10 +182,9 @@ int inftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
184 ops.ooblen = len; 182 ops.ooblen = len;
185 ops.oobbuf = buf; 183 ops.oobbuf = buf;
186 ops.datbuf = NULL; 184 ops.datbuf = NULL;
187 ops.len = len;
188 185
189 res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 186 res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
190 *retlen = ops.retlen; 187 *retlen = ops.oobretlen;
191 return res; 188 return res;
192} 189}
193 190
@@ -945,6 +942,7 @@ static struct mtd_blktrans_ops inftl_tr = {
945 .name = "inftl", 942 .name = "inftl",
946 .major = INFTL_MAJOR, 943 .major = INFTL_MAJOR,
947 .part_bits = INFTL_PARTN_BITS, 944 .part_bits = INFTL_PARTN_BITS,
945 .blksize = 512,
948 .getgeo = inftl_getgeo, 946 .getgeo = inftl_getgeo,
949 .readsect = inftl_readblock, 947 .readsect = inftl_readblock,
950 .writesect = inftl_writeblock, 948 .writesect = inftl_writeblock,
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index d132ed571f..f457315579 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -60,6 +60,15 @@ config MTD_PHYSMAP_BANKWIDTH
60 Ignore this option if you use run-time physmap configuration 60 Ignore this option if you use run-time physmap configuration
61 (i.e., run-time calling physmap_configure()). 61 (i.e., run-time calling physmap_configure()).
62 62
63config MTD_PHYSMAP_OF
64 tristate "Flash device in physical memory map based on OF descirption"
65 depends on PPC_OF && (MTD_CFI || MTD_JEDECPROBE || MTD_ROM)
66 help
67 This provides a 'mapping' driver which allows the NOR Flash and
68 ROM driver code to communicate with chips which are mapped
69 physically into the CPU's memory. The mapping description here is
70 taken from OF device tree.
71
63config MTD_SUN_UFLASH 72config MTD_SUN_UFLASH
64 tristate "Sun Microsystems userflash support" 73 tristate "Sun Microsystems userflash support"
65 depends on SPARC && MTD_CFI 74 depends on SPARC && MTD_CFI
@@ -184,6 +193,24 @@ config MTD_ICHXROM
184 193
185 BE VERY CAREFUL. 194 BE VERY CAREFUL.
186 195
196config MTD_ESB2ROM
197 tristate "BIOS flash chip on Intel ESB Controller Hub 2"
198 depends on X86 && MTD_JEDECPROBE && PCI
199 help
200 Support for treating the BIOS flash chip on ESB2 motherboards
201 as an MTD device - with this you can reprogram your BIOS.
202
203 BE VERY CAREFUL.
204
205config MTD_CK804XROM
206 tristate "BIOS flash chip on Nvidia CK804"
207 depends on X86 && MTD_JEDECPROBE
208 help
209 Support for treating the BIOS flash chip on nvidia motherboards
210 as an MTD device - with this you can reprogram your BIOS.
211
212 BE VERY CAREFUL.
213
187config MTD_SCB2_FLASH 214config MTD_SCB2_FLASH
188 tristate "BIOS flash chip on Intel SCB2 boards" 215 tristate "BIOS flash chip on Intel SCB2 boards"
189 depends on X86 && MTD_JEDECPROBE 216 depends on X86 && MTD_JEDECPROBE
@@ -355,50 +382,6 @@ config MTD_TQM834x
355 TQ Components TQM834x boards. If you have one of these boards 382 TQ Components TQM834x boards. If you have one of these boards
356 and would like to use the flash chips on it, say 'Y'. 383 and would like to use the flash chips on it, say 'Y'.
357 384
358config MTD_CSTM_MIPS_IXX
359 tristate "Flash chip mapping on ITE QED-4N-S01B, Globespan IVR or custom board"
360 depends on MIPS && MTD_CFI && MTD_JEDECPROBE && MTD_PARTITIONS
361 help
362 This provides a mapping driver for the Integrated Technology
363 Express, Inc (ITE) QED-4N-S01B eval board and the Globespan IVR
364 Reference Board. It provides the necessary addressing, length,
365 buswidth, vpp code and addition setup of the flash device for
366 these boards. In addition, this mapping driver can be used for
367 other boards via setting of the CONFIG_MTD_CSTM_MIPS_IXX_START/
368 LEN/BUSWIDTH parameters. This mapping will provide one mtd device
369 using one partition. The start address can be offset from the
370 beginning of flash and the len can be less than the total flash
371 device size to allow a window into the flash. Both CFI and JEDEC
372 probes are called.
373
374config MTD_CSTM_MIPS_IXX_START
375 hex "Physical start address of flash mapping"
376 depends on MTD_CSTM_MIPS_IXX
377 default "0x8000000"
378 help
379 This is the physical memory location that the MTD driver will
380 use for the flash chips on your particular target board.
381 Refer to the memory map which should hopefully be in the
382 documentation for your board.
383
384config MTD_CSTM_MIPS_IXX_LEN
385 hex "Physical length of flash mapping"
386 depends on MTD_CSTM_MIPS_IXX
387 default "0x4000000"
388 help
389 This is the total length that the MTD driver will use for the
390 flash chips on your particular board. Refer to the memory
391 map which should hopefully be in the documentation for your
392 board.
393
394config MTD_CSTM_MIPS_IXX_BUSWIDTH
395 int "Bus width in octets"
396 depends on MTD_CSTM_MIPS_IXX
397 default "2"
398 help
399 This is the total bus width of the mapping of the flash chips
400 on your particular board.
401
402config MTD_OCELOT 385config MTD_OCELOT
403 tristate "Momenco Ocelot boot flash device" 386 tristate "Momenco Ocelot boot flash device"
404 depends on MIPS && MOMENCO_OCELOT 387 depends on MIPS && MOMENCO_OCELOT
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index 191c1928bb..071d0bf922 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -12,12 +12,13 @@ obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
12obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o 12obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
13obj-$(CONFIG_MTD_BAST) += bast-flash.o 13obj-$(CONFIG_MTD_BAST) += bast-flash.o
14obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o 14obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o
15obj-$(CONFIG_MTD_CSTM_MIPS_IXX) += cstm_mips_ixx.o
16obj-$(CONFIG_MTD_DC21285) += dc21285.o 15obj-$(CONFIG_MTD_DC21285) += dc21285.o
17obj-$(CONFIG_MTD_DILNETPC) += dilnetpc.o 16obj-$(CONFIG_MTD_DILNETPC) += dilnetpc.o
18obj-$(CONFIG_MTD_L440GX) += l440gx.o 17obj-$(CONFIG_MTD_L440GX) += l440gx.o
19obj-$(CONFIG_MTD_AMD76XROM) += amd76xrom.o 18obj-$(CONFIG_MTD_AMD76XROM) += amd76xrom.o
19obj-$(CONFIG_MTD_ESB2ROM) += esb2rom.o
20obj-$(CONFIG_MTD_ICHXROM) += ichxrom.o 20obj-$(CONFIG_MTD_ICHXROM) += ichxrom.o
21obj-$(CONFIG_MTD_CK804XROM) += ck804xrom.o
21obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o 22obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o
22obj-$(CONFIG_MTD_LUBBOCK) += lubbock-flash.o 23obj-$(CONFIG_MTD_LUBBOCK) += lubbock-flash.o
23obj-$(CONFIG_MTD_MAINSTONE) += mainstone-flash.o 24obj-$(CONFIG_MTD_MAINSTONE) += mainstone-flash.o
@@ -25,6 +26,7 @@ obj-$(CONFIG_MTD_MBX860) += mbx860.o
25obj-$(CONFIG_MTD_CEIVA) += ceiva.o 26obj-$(CONFIG_MTD_CEIVA) += ceiva.o
26obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o 27obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o
27obj-$(CONFIG_MTD_PHYSMAP) += physmap.o 28obj-$(CONFIG_MTD_PHYSMAP) += physmap.o
29obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o
28obj-$(CONFIG_MTD_PNC2000) += pnc2000.o 30obj-$(CONFIG_MTD_PNC2000) += pnc2000.o
29obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o 31obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
30obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o 32obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index 797caffb20..78b671172b 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -7,6 +7,7 @@
7 7
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/version.h>
10#include <linux/kernel.h> 11#include <linux/kernel.h>
11#include <linux/init.h> 12#include <linux/init.h>
12#include <asm/io.h> 13#include <asm/io.h>
@@ -44,6 +45,23 @@ struct amd76xrom_map_info {
44 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN]; 45 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN];
45}; 46};
46 47
48/* The 2 bits controlling the window size are often set to allow reading
49 * the BIOS, but too small to allow writing, since the lock registers are
50 * 4MiB lower in the address space than the data.
51 *
52 * This is intended to prevent flashing the bios, perhaps accidentally.
53 *
54 * This parameter allows the normal driver to over-ride the BIOS settings.
55 *
56 * The bits are 6 and 7. If both bits are set, it is a 5MiB window.
57 * If only the 7 Bit is set, it is a 4MiB window. Otherwise, a
58 * 64KiB window.
59 *
60 */
61static uint win_size_bits;
62module_param(win_size_bits, uint, 0);
63MODULE_PARM_DESC(win_size_bits, "ROM window size bits override for 0x43 byte, normally set by BIOS.");
64
47static struct amd76xrom_window amd76xrom_window = { 65static struct amd76xrom_window amd76xrom_window = {
48 .maps = LIST_HEAD_INIT(amd76xrom_window.maps), 66 .maps = LIST_HEAD_INIT(amd76xrom_window.maps),
49}; 67};
@@ -95,6 +113,16 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
95 /* Remember the pci dev I find the window in - already have a ref */ 113 /* Remember the pci dev I find the window in - already have a ref */
96 window->pdev = pdev; 114 window->pdev = pdev;
97 115
116 /* Enable the selected rom window. This is often incorrectly
117 * set up by the BIOS, and the 4MiB offset for the lock registers
118 * requires the full 5MiB of window space.
119 *
120 * This 'write, then read' approach leaves the bits for
121 * other uses of the hardware info.
122 */
123 pci_read_config_byte(pdev, 0x43, &byte);
124 pci_write_config_byte(pdev, 0x43, byte | win_size_bits );
125
98 /* Assume the rom window is properly setup, and find it's size */ 126 /* Assume the rom window is properly setup, and find it's size */
99 pci_read_config_byte(pdev, 0x43, &byte); 127 pci_read_config_byte(pdev, 0x43, &byte);
100 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6))) { 128 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6))) {
@@ -129,12 +157,6 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
129 (unsigned long long)window->rsrc.end); 157 (unsigned long long)window->rsrc.end);
130 } 158 }
131 159
132#if 0
133
134 /* Enable the selected rom window */
135 pci_read_config_byte(pdev, 0x43, &byte);
136 pci_write_config_byte(pdev, 0x43, byte | rwindow->segen_bits);
137#endif
138 160
139 /* Enable writes through the rom window */ 161 /* Enable writes through the rom window */
140 pci_read_config_byte(pdev, 0x40, &byte); 162 pci_read_config_byte(pdev, 0x40, &byte);
diff --git a/drivers/mtd/maps/bast-flash.c b/drivers/mtd/maps/bast-flash.c
index e074bb6787..fc3b2672d1 100644
--- a/drivers/mtd/maps/bast-flash.c
+++ b/drivers/mtd/maps/bast-flash.c
@@ -131,7 +131,7 @@ static int bast_flash_probe(struct platform_device *pdev)
131 131
132 info->map.phys = res->start; 132 info->map.phys = res->start;
133 info->map.size = res->end - res->start + 1; 133 info->map.size = res->end - res->start + 1;
134 info->map.name = pdev->dev.bus_id; 134 info->map.name = pdev->dev.bus_id;
135 info->map.bankwidth = 2; 135 info->map.bankwidth = 2;
136 136
137 if (info->map.size > AREA_MAXSIZE) 137 if (info->map.size > AREA_MAXSIZE)
diff --git a/drivers/mtd/maps/ceiva.c b/drivers/mtd/maps/ceiva.c
index 0402c21e29..629e6e2641 100644
--- a/drivers/mtd/maps/ceiva.c
+++ b/drivers/mtd/maps/ceiva.c
@@ -122,10 +122,9 @@ static int __init clps_setup_mtd(struct clps_info *clps, int nr, struct mtd_info
122 /* 122 /*
123 * Allocate the map_info structs in one go. 123 * Allocate the map_info structs in one go.
124 */ 124 */
125 maps = kmalloc(sizeof(struct map_info) * nr, GFP_KERNEL); 125 maps = kzalloc(sizeof(struct map_info) * nr, GFP_KERNEL);
126 if (!maps) 126 if (!maps)
127 return -ENOMEM; 127 return -ENOMEM;
128 memset(maps, 0, sizeof(struct map_info) * nr);
129 /* 128 /*
130 * Claim and then map the memory regions. 129 * Claim and then map the memory regions.
131 */ 130 */
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
new file mode 100644
index 0000000000..238d42e88e
--- /dev/null
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -0,0 +1,356 @@
1/*
2 * ck804xrom.c
3 *
4 * Normal mappings of chips in physical memory
5 *
6 * Dave Olsen <dolsen@lnxi.com>
7 * Ryan Jackson <rjackson@lnxi.com>
8 */
9
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/version.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <asm/io.h>
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/map.h>
18#include <linux/mtd/cfi.h>
19#include <linux/mtd/flashchip.h>
20#include <linux/pci.h>
21#include <linux/pci_ids.h>
22#include <linux/list.h>
23
24
25#define MOD_NAME KBUILD_BASENAME
26
27#define ADDRESS_NAME_LEN 18
28
29#define ROM_PROBE_STEP_SIZE (64*1024)
30
31struct ck804xrom_window {
32 void __iomem *virt;
33 unsigned long phys;
34 unsigned long size;
35 struct list_head maps;
36 struct resource rsrc;
37 struct pci_dev *pdev;
38};
39
40struct ck804xrom_map_info {
41 struct list_head list;
42 struct map_info map;
43 struct mtd_info *mtd;
44 struct resource rsrc;
45 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN];
46};
47
48
49/* The 2 bits controlling the window size are often set to allow reading
50 * the BIOS, but too small to allow writing, since the lock registers are
51 * 4MiB lower in the address space than the data.
52 *
53 * This is intended to prevent flashing the bios, perhaps accidentally.
54 *
55 * This parameter allows the normal driver to override the BIOS settings.
56 *
57 * The bits are 6 and 7. If both bits are set, it is a 5MiB window.
58 * If only the 7 Bit is set, it is a 4MiB window. Otherwise, a
59 * 64KiB window.
60 *
61 */
62static uint win_size_bits = 0;
63module_param(win_size_bits, uint, 0);
64MODULE_PARM_DESC(win_size_bits, "ROM window size bits override for 0x88 byte, normally set by BIOS.");
65
66static struct ck804xrom_window ck804xrom_window = {
67 .maps = LIST_HEAD_INIT(ck804xrom_window.maps),
68};
69
70static void ck804xrom_cleanup(struct ck804xrom_window *window)
71{
72 struct ck804xrom_map_info *map, *scratch;
73 u8 byte;
74
75 if (window->pdev) {
76 /* Disable writes through the rom window */
77 pci_read_config_byte(window->pdev, 0x6d, &byte);
78 pci_write_config_byte(window->pdev, 0x6d, byte & ~1);
79 }
80
81 /* Free all of the mtd devices */
82 list_for_each_entry_safe(map, scratch, &window->maps, list) {
83 if (map->rsrc.parent)
84 release_resource(&map->rsrc);
85
86 del_mtd_device(map->mtd);
87 map_destroy(map->mtd);
88 list_del(&map->list);
89 kfree(map);
90 }
91 if (window->rsrc.parent)
92 release_resource(&window->rsrc);
93
94 if (window->virt) {
95 iounmap(window->virt);
96 window->virt = NULL;
97 window->phys = 0;
98 window->size = 0;
99 }
100 pci_dev_put(window->pdev);
101}
102
103
104static int __devinit ck804xrom_init_one (struct pci_dev *pdev,
105 const struct pci_device_id *ent)
106{
107 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
108 u8 byte;
109 struct ck804xrom_window *window = &ck804xrom_window;
110 struct ck804xrom_map_info *map = NULL;
111 unsigned long map_top;
112
113 /* Remember the pci dev I find the window in */
114 window->pdev = pci_dev_get(pdev);
115
116 /* Enable the selected rom window. This is often incorrectly
117 * set up by the BIOS, and the 4MiB offset for the lock registers
118 * requires the full 5MiB of window space.
119 *
120 * This 'write, then read' approach leaves the bits for
121 * other uses of the hardware info.
122 */
123 pci_read_config_byte(pdev, 0x88, &byte);
124 pci_write_config_byte(pdev, 0x88, byte | win_size_bits );
125
126
127 /* Assume the rom window is properly setup, and find it's size */
128 pci_read_config_byte(pdev, 0x88, &byte);
129
130 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6)))
131 window->phys = 0xffb00000; /* 5MiB */
132 else if ((byte & (1<<7)) == (1<<7))
133 window->phys = 0xffc00000; /* 4MiB */
134 else
135 window->phys = 0xffff0000; /* 64KiB */
136
137 window->size = 0xffffffffUL - window->phys + 1UL;
138
139 /*
140 * Try to reserve the window mem region. If this fails then
141 * it is likely due to a fragment of the window being
142 * "reserved" by the BIOS. In the case that the
143 * request_mem_region() fails then once the rom size is
144 * discovered we will try to reserve the unreserved fragment.
145 */
146 window->rsrc.name = MOD_NAME;
147 window->rsrc.start = window->phys;
148 window->rsrc.end = window->phys + window->size - 1;
149 window->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
150 if (request_resource(&iomem_resource, &window->rsrc)) {
151 window->rsrc.parent = NULL;
152 printk(KERN_ERR MOD_NAME
153 " %s(): Unable to register resource"
154 " 0x%.016llx-0x%.016llx - kernel bug?\n",
155 __func__,
156 (unsigned long long)window->rsrc.start,
157 (unsigned long long)window->rsrc.end);
158 }
159
160
161 /* Enable writes through the rom window */
162 pci_read_config_byte(pdev, 0x6d, &byte);
163 pci_write_config_byte(pdev, 0x6d, byte | 1);
164
165 /* FIXME handle registers 0x80 - 0x8C the bios region locks */
166
167 /* For write accesses caches are useless */
168 window->virt = ioremap_nocache(window->phys, window->size);
169 if (!window->virt) {
170 printk(KERN_ERR MOD_NAME ": ioremap(%08lx, %08lx) failed\n",
171 window->phys, window->size);
172 goto out;
173 }
174
175 /* Get the first address to look for a rom chip at */
176 map_top = window->phys;
177#if 1
178 /* The probe sequence run over the firmware hub lock
179 * registers sets them to 0x7 (no access).
180 * Probe at most the last 4MiB of the address space.
181 */
182 if (map_top < 0xffc00000)
183 map_top = 0xffc00000;
184#endif
185 /* Loop through and look for rom chips. Since we don't know the
186 * starting address for each chip, probe every ROM_PROBE_STEP_SIZE
187 * bytes from the starting address of the window.
188 */
189 while((map_top - 1) < 0xffffffffUL) {
190 struct cfi_private *cfi;
191 unsigned long offset;
192 int i;
193
194 if (!map)
195 map = kmalloc(sizeof(*map), GFP_KERNEL);
196
197 if (!map) {
198 printk(KERN_ERR MOD_NAME ": kmalloc failed");
199 goto out;
200 }
201 memset(map, 0, sizeof(*map));
202 INIT_LIST_HEAD(&map->list);
203 map->map.name = map->map_name;
204 map->map.phys = map_top;
205 offset = map_top - window->phys;
206 map->map.virt = (void __iomem *)
207 (((unsigned long)(window->virt)) + offset);
208 map->map.size = 0xffffffffUL - map_top + 1UL;
209 /* Set the name of the map to the address I am trying */
210 sprintf(map->map_name, "%s @%08lx",
211 MOD_NAME, map->map.phys);
212
213 /* There is no generic VPP support */
214 for(map->map.bankwidth = 32; map->map.bankwidth;
215 map->map.bankwidth >>= 1)
216 {
217 char **probe_type;
218 /* Skip bankwidths that are not supported */
219 if (!map_bankwidth_supported(map->map.bankwidth))
220 continue;
221
222 /* Setup the map methods */
223 simple_map_init(&map->map);
224
225 /* Try all of the probe methods */
226 probe_type = rom_probe_types;
227 for(; *probe_type; probe_type++) {
228 map->mtd = do_map_probe(*probe_type, &map->map);
229 if (map->mtd)
230 goto found;
231 }
232 }
233 map_top += ROM_PROBE_STEP_SIZE;
234 continue;
235 found:
236 /* Trim the size if we are larger than the map */
237 if (map->mtd->size > map->map.size) {
238 printk(KERN_WARNING MOD_NAME
239 " rom(%u) larger than window(%lu). fixing...\n",
240 map->mtd->size, map->map.size);
241 map->mtd->size = map->map.size;
242 }
243 if (window->rsrc.parent) {
244 /*
245 * Registering the MTD device in iomem may not be possible
246 * if there is a BIOS "reserved" and BUSY range. If this
247 * fails then continue anyway.
248 */
249 map->rsrc.name = map->map_name;
250 map->rsrc.start = map->map.phys;
251 map->rsrc.end = map->map.phys + map->mtd->size - 1;
252 map->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
253 if (request_resource(&window->rsrc, &map->rsrc)) {
254 printk(KERN_ERR MOD_NAME
255 ": cannot reserve MTD resource\n");
256 map->rsrc.parent = NULL;
257 }
258 }
259
260 /* Make the whole region visible in the map */
261 map->map.virt = window->virt;
262 map->map.phys = window->phys;
263 cfi = map->map.fldrv_priv;
264 for(i = 0; i < cfi->numchips; i++)
265 cfi->chips[i].start += offset;
266
267 /* Now that the mtd devices is complete claim and export it */
268 map->mtd->owner = THIS_MODULE;
269 if (add_mtd_device(map->mtd)) {
270 map_destroy(map->mtd);
271 map->mtd = NULL;
272 goto out;
273 }
274
275
276 /* Calculate the new value of map_top */
277 map_top += map->mtd->size;
278
279 /* File away the map structure */
280 list_add(&map->list, &window->maps);
281 map = NULL;
282 }
283
284 out:
285 /* Free any left over map structures */
286 if (map)
287 kfree(map);
288
289 /* See if I have any map structures */
290 if (list_empty(&window->maps)) {
291 ck804xrom_cleanup(window);
292 return -ENODEV;
293 }
294 return 0;
295}
296
297
298static void __devexit ck804xrom_remove_one (struct pci_dev *pdev)
299{
300 struct ck804xrom_window *window = &ck804xrom_window;
301
302 ck804xrom_cleanup(window);
303}
304
305static struct pci_device_id ck804xrom_pci_tbl[] = {
306 { PCI_VENDOR_ID_NVIDIA, 0x0051,
307 PCI_ANY_ID, PCI_ANY_ID, }, /* nvidia ck804 */
308 { 0, }
309};
310
311MODULE_DEVICE_TABLE(pci, ck804xrom_pci_tbl);
312
313#if 0
314static struct pci_driver ck804xrom_driver = {
315 .name = MOD_NAME,
316 .id_table = ck804xrom_pci_tbl,
317 .probe = ck804xrom_init_one,
318 .remove = ck804xrom_remove_one,
319};
320#endif
321
322static int __init init_ck804xrom(void)
323{
324 struct pci_dev *pdev;
325 struct pci_device_id *id;
326 int retVal;
327 pdev = NULL;
328
329 for(id = ck804xrom_pci_tbl; id->vendor; id++) {
330 pdev = pci_find_device(id->vendor, id->device, NULL);
331 if (pdev)
332 break;
333 }
334 if (pdev) {
335 retVal = ck804xrom_init_one(pdev, &ck804xrom_pci_tbl[0]);
336 pci_dev_put(pdev);
337 return retVal;
338 }
339 return -ENXIO;
340#if 0
341 return pci_module_init(&ck804xrom_driver);
342#endif
343}
344
345static void __exit cleanup_ck804xrom(void)
346{
347 ck804xrom_remove_one(ck804xrom_window.pdev);
348}
349
350module_init(init_ck804xrom);
351module_exit(cleanup_ck804xrom);
352
353MODULE_LICENSE("GPL");
354MODULE_AUTHOR("Eric Biederman <ebiederman@lnxi.com>, Dave Olsen <dolsen@lnxi.com>");
355MODULE_DESCRIPTION("MTD map driver for BIOS chips on the Nvidia ck804 southbridge");
356
diff --git a/drivers/mtd/maps/cstm_mips_ixx.c b/drivers/mtd/maps/cstm_mips_ixx.c
deleted file mode 100644
index df2c38ef10..0000000000
--- a/drivers/mtd/maps/cstm_mips_ixx.c
+++ /dev/null
@@ -1,283 +0,0 @@
1/*
2 * $Id: cstm_mips_ixx.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $
3 *
4 * Mapping of a custom board with both AMD CFI and JEDEC flash in partitions.
5 * Config with both CFI and JEDEC device support.
6 *
7 * Basically physmap.c with the addition of partitions and
8 * an array of mapping info to accomodate more than one flash type per board.
9 *
10 * Copyright 2000 MontaVista Software Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33#include <linux/module.h>
34#include <linux/types.h>
35#include <linux/kernel.h>
36#include <linux/init.h>
37#include <asm/io.h>
38#include <linux/mtd/mtd.h>
39#include <linux/mtd/map.h>
40#include <linux/mtd/partitions.h>
41#include <linux/delay.h>
42
43#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
44#define CC_GCR 0xB4013818
45#define CC_GPBCR 0xB401380A
46#define CC_GPBDR 0xB4013808
47#define CC_M68K_DEVICE 1
48#define CC_M68K_FUNCTION 6
49#define CC_CONFADDR 0xB8004000
50#define CC_CONFDATA 0xB8004004
51#define CC_FC_FCR 0xB8002004
52#define CC_FC_DCR 0xB8002008
53#define CC_GPACR 0xB4013802
54#define CC_GPAICR 0xB4013804
55#endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
56
57#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
58void cstm_mips_ixx_set_vpp(struct map_info *map,int vpp)
59{
60 static DEFINE_SPINLOCK(vpp_lock);
61 static int vpp_count = 0;
62 unsigned long flags;
63
64 spin_lock_irqsave(&vpp_lock, flags);
65
66 if (vpp) {
67 if (!vpp_count++) {
68 __u16 data;
69 __u8 data1;
70 static u8 first = 1;
71
72 // Set GPIO port B pin3 to high
73 data = *(__u16 *)(CC_GPBCR);
74 data = (data & 0xff0f) | 0x0040;
75 *(__u16 *)CC_GPBCR = data;
76 *(__u8 *)CC_GPBDR = (*(__u8*)CC_GPBDR) | 0x08;
77 if (first) {
78 first = 0;
79 /* need to have this delay for first
80 enabling vpp after powerup */
81 udelay(40);
82 }
83 }
84 } else {
85 if (!--vpp_count) {
86 __u16 data;
87
88 // Set GPIO port B pin3 to high
89 data = *(__u16 *)(CC_GPBCR);
90 data = (data & 0xff3f) | 0x0040;
91 *(__u16 *)CC_GPBCR = data;
92 *(__u8 *)CC_GPBDR = (*(__u8*)CC_GPBDR) & 0xf7;
93 }
94 }
95 spin_unlock_irqrestore(&vpp_lock, flags);
96}
97#endif
98
99/* board and partition description */
100
101#define MAX_PHYSMAP_PARTITIONS 8
102struct cstm_mips_ixx_info {
103 char *name;
104 unsigned long window_addr;
105 unsigned long window_size;
106 int bankwidth;
107 int num_partitions;
108};
109
110#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
111#define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
112const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
113{
114 { // 28F128J3A in 2x16 configuration
115 "big flash", // name
116 0x08000000, // window_addr
117 0x02000000, // window_size
118 4, // bankwidth
119 1, // num_partitions
120 }
121
122};
123static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP_PARTITIONS] = {
124{ // 28F128J3A in 2x16 configuration
125 {
126 .name = "main partition ",
127 .size = 0x02000000, // 128 x 2 x 128k byte sectors
128 .offset = 0,
129 },
130},
131};
132#else /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
133#define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
134const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
135{
136 {
137 "MTD flash", // name
138 CONFIG_MTD_CSTM_MIPS_IXX_START, // window_addr
139 CONFIG_MTD_CSTM_MIPS_IXX_LEN, // window_size
140 CONFIG_MTD_CSTM_MIPS_IXX_BUSWIDTH, // bankwidth
141 1, // num_partitions
142 },
143
144};
145static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP_PARTITIONS] = {
146{
147 {
148 .name = "main partition",
149 .size = CONFIG_MTD_CSTM_MIPS_IXX_LEN,
150 .offset = 0,
151 },
152},
153};
154#endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
155
156struct map_info cstm_mips_ixx_map[PHYSMAP_NUMBER];
157
158int __init init_cstm_mips_ixx(void)
159{
160 int i;
161 int jedec;
162 struct mtd_info *mymtd;
163 struct mtd_partition *parts;
164
165 /* Initialize mapping */
166 for (i=0;i<PHYSMAP_NUMBER;i++) {
167 printk(KERN_NOTICE "cstm_mips_ixx flash device: 0x%lx at 0x%lx\n",
168 cstm_mips_ixx_board_desc[i].window_size, cstm_mips_ixx_board_desc[i].window_addr);
169
170
171 cstm_mips_ixx_map[i].phys = cstm_mips_ixx_board_desc[i].window_addr;
172 cstm_mips_ixx_map[i].virt = ioremap(cstm_mips_ixx_board_desc[i].window_addr, cstm_mips_ixx_board_desc[i].window_size);
173 if (!cstm_mips_ixx_map[i].virt) {
174 int j = 0;
175 printk(KERN_WARNING "Failed to ioremap\n");
176 for (j = 0; j < i; j++) {
177 if (cstm_mips_ixx_map[j].virt) {
178 iounmap(cstm_mips_ixx_map[j].virt);
179 cstm_mips_ixx_map[j].virt = NULL;
180 }
181 }
182 return -EIO;
183 }
184 cstm_mips_ixx_map[i].name = cstm_mips_ixx_board_desc[i].name;
185 cstm_mips_ixx_map[i].size = cstm_mips_ixx_board_desc[i].window_size;
186 cstm_mips_ixx_map[i].bankwidth = cstm_mips_ixx_board_desc[i].bankwidth;
187#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
188 cstm_mips_ixx_map[i].set_vpp = cstm_mips_ixx_set_vpp;
189#endif
190 simple_map_init(&cstm_mips_ixx_map[i]);
191 //printk(KERN_NOTICE "cstm_mips_ixx: ioremap is %x\n",(unsigned int)(cstm_mips_ixx_map[i].virt));
192 }
193
194#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
195 setup_ITE_IVR_flash();
196#endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
197
198 for (i=0;i<PHYSMAP_NUMBER;i++) {
199 parts = &cstm_mips_ixx_partitions[i][0];
200 jedec = 0;
201 mymtd = (struct mtd_info *)do_map_probe("cfi_probe", &cstm_mips_ixx_map[i]);
202 //printk(KERN_NOTICE "phymap %d cfi_probe: mymtd is %x\n",i,(unsigned int)mymtd);
203 if (!mymtd) {
204 jedec = 1;
205 mymtd = (struct mtd_info *)do_map_probe("jedec", &cstm_mips_ixx_map[i]);
206 printk(KERN_NOTICE "cstm_mips_ixx %d jedec: mymtd is %x\n",i,(unsigned int)mymtd);
207 }
208 if (mymtd) {
209 mymtd->owner = THIS_MODULE;
210
211 cstm_mips_ixx_map[i].map_priv_2 = (unsigned long)mymtd;
212 add_mtd_partitions(mymtd, parts, cstm_mips_ixx_board_desc[i].num_partitions);
213 }
214 else {
215 for (i = 0; i < PHYSMAP_NUMBER; i++) {
216 if (cstm_mips_ixx_map[i].virt) {
217 iounmap(cstm_mips_ixx_map[i].virt);
218 cstm_mips_ixx_map[i].virt = NULL;
219 }
220 }
221 return -ENXIO;
222 }
223 }
224 return 0;
225}
226
227static void __exit cleanup_cstm_mips_ixx(void)
228{
229 int i;
230 struct mtd_info *mymtd;
231
232 for (i=0;i<PHYSMAP_NUMBER;i++) {
233 mymtd = (struct mtd_info *)cstm_mips_ixx_map[i].map_priv_2;
234 if (mymtd) {
235 del_mtd_partitions(mymtd);
236 map_destroy(mymtd);
237 }
238 if (cstm_mips_ixx_map[i].virt) {
239 iounmap((void *)cstm_mips_ixx_map[i].virt);
240 cstm_mips_ixx_map[i].virt = 0;
241 }
242 }
243}
244#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
245void PCISetULongByOffset(__u32 DevNumber, __u32 FuncNumber, __u32 Offset, __u32 data)
246{
247 __u32 offset;
248
249 offset = ( unsigned long )( 0x80000000 | ( DevNumber << 11 ) + ( FuncNumber << 8 ) + Offset) ;
250
251 *(__u32 *)CC_CONFADDR = offset;
252 *(__u32 *)CC_CONFDATA = data;
253}
254void setup_ITE_IVR_flash()
255{
256 __u32 size, base;
257
258 size = 0x0e000000; // 32MiB
259 base = (0x08000000) >> 8 >>1; // Bug: we must shift one more bit
260
261 /* need to set ITE flash to 32 bits instead of default 8 */
262#ifdef CONFIG_MIPS_IVR
263 *(__u32 *)CC_FC_FCR = 0x55;
264 *(__u32 *)CC_GPACR = 0xfffc;
265#else
266 *(__u32 *)CC_FC_FCR = 0x77;
267#endif
268 /* turn bursting off */
269 *(__u32 *)CC_FC_DCR = 0x0;
270
271 /* setup for one chip 4 byte PCI access */
272 PCISetULongByOffset(CC_M68K_DEVICE, CC_M68K_FUNCTION, 0x60, size | base);
273 PCISetULongByOffset(CC_M68K_DEVICE, CC_M68K_FUNCTION, 0x64, 0x02);
274}
275#endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
276
277module_init(init_cstm_mips_ixx);
278module_exit(cleanup_cstm_mips_ixx);
279
280
281MODULE_LICENSE("GPL");
282MODULE_AUTHOR("Alice Hennessy <ahennessy@mvista.com>");
283MODULE_DESCRIPTION("MTD map driver for ITE 8172G and Globespan IVR boards");
diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c
new file mode 100644
index 0000000000..a9d808a617
--- /dev/null
+++ b/drivers/mtd/maps/esb2rom.c
@@ -0,0 +1,450 @@
1/*
2 * esb2rom.c
3 *
4 * Normal mappings of flash chips in physical memory
5 * through the Intel ESB2 Southbridge.
6 *
7 * This was derived from ichxrom.c in May 2006 by
8 * Lew Glendenning <lglendenning@lnxi.com>
9 *
10 * Eric Biederman, of course, was a major help in this effort.
11 */
12
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/version.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <asm/io.h>
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h>
21#include <linux/mtd/cfi.h>
22#include <linux/mtd/flashchip.h>
23#include <linux/pci.h>
24#include <linux/pci_ids.h>
25#include <linux/list.h>
26
27#define MOD_NAME KBUILD_BASENAME
28
29#define ADDRESS_NAME_LEN 18
30
31#define ROM_PROBE_STEP_SIZE (64*1024) /* 64KiB */
32
33#define BIOS_CNTL 0xDC
34#define BIOS_LOCK_ENABLE 0x02
35#define BIOS_WRITE_ENABLE 0x01
36
37/* This became a 16-bit register, and EN2 has disappeared */
38#define FWH_DEC_EN1 0xD8
39#define FWH_F8_EN 0x8000
40#define FWH_F0_EN 0x4000
41#define FWH_E8_EN 0x2000
42#define FWH_E0_EN 0x1000
43#define FWH_D8_EN 0x0800
44#define FWH_D0_EN 0x0400
45#define FWH_C8_EN 0x0200
46#define FWH_C0_EN 0x0100
47#define FWH_LEGACY_F_EN 0x0080
48#define FWH_LEGACY_E_EN 0x0040
49/* reserved 0x0020 and 0x0010 */
50#define FWH_70_EN 0x0008
51#define FWH_60_EN 0x0004
52#define FWH_50_EN 0x0002
53#define FWH_40_EN 0x0001
54
55/* these are 32-bit values */
56#define FWH_SEL1 0xD0
57#define FWH_SEL2 0xD4
58
59#define FWH_8MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
60 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \
61 FWH_70_EN | FWH_60_EN | FWH_50_EN | FWH_40_EN)
62
63#define FWH_7MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
64 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \
65 FWH_70_EN | FWH_60_EN | FWH_50_EN)
66
67#define FWH_6MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
68 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \
69 FWH_70_EN | FWH_60_EN)
70
71#define FWH_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
72 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \
73 FWH_70_EN)
74
75#define FWH_4MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
76 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN)
77
78#define FWH_3_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
79 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN)
80
81#define FWH_3MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
82 FWH_D8_EN | FWH_D0_EN)
83
84#define FWH_2_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
85 FWH_D8_EN)
86
87#define FWH_2MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN)
88
89#define FWH_1_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN)
90
91#define FWH_1MiB (FWH_F8_EN | FWH_F0_EN)
92
93#define FWH_0_5MiB (FWH_F8_EN)
94
95
96struct esb2rom_window {
97 void __iomem* virt;
98 unsigned long phys;
99 unsigned long size;
100 struct list_head maps;
101 struct resource rsrc;
102 struct pci_dev *pdev;
103};
104
105struct esb2rom_map_info {
106 struct list_head list;
107 struct map_info map;
108 struct mtd_info *mtd;
109 struct resource rsrc;
110 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN];
111};
112
113static struct esb2rom_window esb2rom_window = {
114 .maps = LIST_HEAD_INIT(esb2rom_window.maps),
115};
116
117static void esb2rom_cleanup(struct esb2rom_window *window)
118{
119 struct esb2rom_map_info *map, *scratch;
120 u8 byte;
121
122 /* Disable writes through the rom window */
123 pci_read_config_byte(window->pdev, BIOS_CNTL, &byte);
124 pci_write_config_byte(window->pdev, BIOS_CNTL,
125 byte & ~BIOS_WRITE_ENABLE);
126
127 /* Free all of the mtd devices */
128 list_for_each_entry_safe(map, scratch, &window->maps, list) {
129 if (map->rsrc.parent)
130 release_resource(&map->rsrc);
131 del_mtd_device(map->mtd);
132 map_destroy(map->mtd);
133 list_del(&map->list);
134 kfree(map);
135 }
136 if (window->rsrc.parent)
137 release_resource(&window->rsrc);
138 if (window->virt) {
139 iounmap(window->virt);
140 window->virt = NULL;
141 window->phys = 0;
142 window->size = 0;
143 }
144 pci_dev_put(window->pdev);
145}
146
147static int __devinit esb2rom_init_one(struct pci_dev *pdev,
148 const struct pci_device_id *ent)
149{
150 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
151 struct esb2rom_window *window = &esb2rom_window;
152 struct esb2rom_map_info *map = NULL;
153 unsigned long map_top;
154 u8 byte;
155 u16 word;
156
157 /* For now I just handle the ecb2 and I assume there
158 * are not a lot of resources up at the top of the address
159 * space. It is possible to handle other devices in the
160 * top 16MiB but it is very painful. Also since
161 * you can only really attach a FWH to an ICHX there
162 * a number of simplifications you can make.
163 *
164 * Also you can page firmware hubs if an 8MiB window isn't enough
165 * but don't currently handle that case either.
166 */
167 window->pdev = pci_dev_get(pdev);
168
169 /* RLG: experiment 2. Force the window registers to the widest values */
170
171/*
172 pci_read_config_word(pdev, FWH_DEC_EN1, &word);
173 printk(KERN_DEBUG "Original FWH_DEC_EN1 : %x\n", word);
174 pci_write_config_byte(pdev, FWH_DEC_EN1, 0xff);
175 pci_read_config_byte(pdev, FWH_DEC_EN1, &byte);
176 printk(KERN_DEBUG "New FWH_DEC_EN1 : %x\n", byte);
177
178 pci_read_config_byte(pdev, FWH_DEC_EN2, &byte);
179 printk(KERN_DEBUG "Original FWH_DEC_EN2 : %x\n", byte);
180 pci_write_config_byte(pdev, FWH_DEC_EN2, 0x0f);
181 pci_read_config_byte(pdev, FWH_DEC_EN2, &byte);
182 printk(KERN_DEBUG "New FWH_DEC_EN2 : %x\n", byte);
183*/
184
185 /* Find a region continuous to the end of the ROM window */
186 window->phys = 0;
187 pci_read_config_word(pdev, FWH_DEC_EN1, &word);
188 printk(KERN_DEBUG "pci_read_config_byte : %x\n", word);
189
190 if ((word & FWH_8MiB) == FWH_8MiB)
191 window->phys = 0xff400000;
192 else if ((word & FWH_7MiB) == FWH_7MiB)
193 window->phys = 0xff500000;
194 else if ((word & FWH_6MiB) == FWH_6MiB)
195 window->phys = 0xff600000;
196 else if ((word & FWH_5MiB) == FWH_5MiB)
197 window->phys = 0xFF700000;
198 else if ((word & FWH_4MiB) == FWH_4MiB)
199 window->phys = 0xffc00000;
200 else if ((word & FWH_3_5MiB) == FWH_3_5MiB)
201 window->phys = 0xffc80000;
202 else if ((word & FWH_3MiB) == FWH_3MiB)
203 window->phys = 0xffd00000;
204 else if ((word & FWH_2_5MiB) == FWH_2_5MiB)
205 window->phys = 0xffd80000;
206 else if ((word & FWH_2MiB) == FWH_2MiB)
207 window->phys = 0xffe00000;
208 else if ((word & FWH_1_5MiB) == FWH_1_5MiB)
209 window->phys = 0xffe80000;
210 else if ((word & FWH_1MiB) == FWH_1MiB)
211 window->phys = 0xfff00000;
212 else if ((word & FWH_0_5MiB) == FWH_0_5MiB)
213 window->phys = 0xfff80000;
214
215 /* reserved 0x0020 and 0x0010 */
216 window->phys -= 0x400000UL;
217 window->size = (0xffffffffUL - window->phys) + 1UL;
218
219 /* Enable writes through the rom window */
220 pci_read_config_byte(pdev, BIOS_CNTL, &byte);
221 if (!(byte & BIOS_WRITE_ENABLE) && (byte & (BIOS_LOCK_ENABLE))) {
222 /* The BIOS will generate an error if I enable
223 * this device, so don't even try.
224 */
225 printk(KERN_ERR MOD_NAME ": firmware access control, I can't enable writes\n");
226 goto out;
227 }
228 pci_write_config_byte(pdev, BIOS_CNTL, byte | BIOS_WRITE_ENABLE);
229
230 /*
231 * Try to reserve the window mem region. If this fails then
232 * it is likely due to the window being "reseved" by the BIOS.
233 */
234 window->rsrc.name = MOD_NAME;
235 window->rsrc.start = window->phys;
236 window->rsrc.end = window->phys + window->size - 1;
237 window->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
238 if (request_resource(&iomem_resource, &window->rsrc)) {
239 window->rsrc.parent = NULL;
240 printk(KERN_DEBUG MOD_NAME
241 ": %s(): Unable to register resource"
242 " 0x%.08llx-0x%.08llx - kernel bug?\n",
243 __func__,
244 (unsigned long long)window->rsrc.start,
245 (unsigned long long)window->rsrc.end);
246 }
247
248 /* Map the firmware hub into my address space. */
249 window->virt = ioremap_nocache(window->phys, window->size);
250 if (!window->virt) {
251 printk(KERN_ERR MOD_NAME ": ioremap(%08lx, %08lx) failed\n",
252 window->phys, window->size);
253 goto out;
254 }
255
256 /* Get the first address to look for an rom chip at */
257 map_top = window->phys;
258 if ((window->phys & 0x3fffff) != 0) {
259 /* if not aligned on 4MiB, look 4MiB lower in address space */
260 map_top = window->phys + 0x400000;
261 }
262#if 1
263 /* The probe sequence run over the firmware hub lock
264 * registers sets them to 0x7 (no access).
265 * (Insane hardware design, but most copied Intel's.)
266 * ==> Probe at most the last 4M of the address space.
267 */
268 if (map_top < 0xffc00000)
269 map_top = 0xffc00000;
270#endif
271 /* Loop through and look for rom chips */
272 while ((map_top - 1) < 0xffffffffUL) {
273 struct cfi_private *cfi;
274 unsigned long offset;
275 int i;
276
277 if (!map)
278 map = kmalloc(sizeof(*map), GFP_KERNEL);
279 if (!map) {
280 printk(KERN_ERR MOD_NAME ": kmalloc failed");
281 goto out;
282 }
283 memset(map, 0, sizeof(*map));
284 INIT_LIST_HEAD(&map->list);
285 map->map.name = map->map_name;
286 map->map.phys = map_top;
287 offset = map_top - window->phys;
288 map->map.virt = (void __iomem *)
289 (((unsigned long)(window->virt)) + offset);
290 map->map.size = 0xffffffffUL - map_top + 1UL;
291 /* Set the name of the map to the address I am trying */
292 sprintf(map->map_name, "%s @%08lx",
293 MOD_NAME, map->map.phys);
294
295 /* Firmware hubs only use vpp when being programmed
296 * in a factory setting. So in-place programming
297 * needs to use a different method.
298 */
299 for(map->map.bankwidth = 32; map->map.bankwidth;
300 map->map.bankwidth >>= 1) {
301 char **probe_type;
302 /* Skip bankwidths that are not supported */
303 if (!map_bankwidth_supported(map->map.bankwidth))
304 continue;
305
306 /* Setup the map methods */
307 simple_map_init(&map->map);
308
309 /* Try all of the probe methods */
310 probe_type = rom_probe_types;
311 for(; *probe_type; probe_type++) {
312 map->mtd = do_map_probe(*probe_type, &map->map);
313 if (map->mtd)
314 goto found;
315 }
316 }
317 map_top += ROM_PROBE_STEP_SIZE;
318 continue;
319 found:
320 /* Trim the size if we are larger than the map */
321 if (map->mtd->size > map->map.size) {
322 printk(KERN_WARNING MOD_NAME
323 " rom(%u) larger than window(%lu). fixing...\n",
324 map->mtd->size, map->map.size);
325 map->mtd->size = map->map.size;
326 }
327 if (window->rsrc.parent) {
328 /*
329 * Registering the MTD device in iomem may not be possible
330 * if there is a BIOS "reserved" and BUSY range. If this
331 * fails then continue anyway.
332 */
333 map->rsrc.name = map->map_name;
334 map->rsrc.start = map->map.phys;
335 map->rsrc.end = map->map.phys + map->mtd->size - 1;
336 map->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
337 if (request_resource(&window->rsrc, &map->rsrc)) {
338 printk(KERN_ERR MOD_NAME
339 ": cannot reserve MTD resource\n");
340 map->rsrc.parent = NULL;
341 }
342 }
343
344 /* Make the whole region visible in the map */
345 map->map.virt = window->virt;
346 map->map.phys = window->phys;
347 cfi = map->map.fldrv_priv;
348 for(i = 0; i < cfi->numchips; i++)
349 cfi->chips[i].start += offset;
350
351 /* Now that the mtd devices is complete claim and export it */
352 map->mtd->owner = THIS_MODULE;
353 if (add_mtd_device(map->mtd)) {
354 map_destroy(map->mtd);
355 map->mtd = NULL;
356 goto out;
357 }
358
359 /* Calculate the new value of map_top */
360 map_top += map->mtd->size;
361
362 /* File away the map structure */
363 list_add(&map->list, &window->maps);
364 map = NULL;
365 }
366
367 out:
368 /* Free any left over map structures */
369 kfree(map);
370
371 /* See if I have any map structures */
372 if (list_empty(&window->maps)) {
373 esb2rom_cleanup(window);
374 return -ENODEV;
375 }
376 return 0;
377}
378
379static void __devexit esb2rom_remove_one (struct pci_dev *pdev)
380{
381 struct esb2rom_window *window = &esb2rom_window;
382 esb2rom_cleanup(window);
383}
384
385static struct pci_device_id esb2rom_pci_tbl[] __devinitdata = {
386 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0,
387 PCI_ANY_ID, PCI_ANY_ID, },
388 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
389 PCI_ANY_ID, PCI_ANY_ID, },
390 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0,
391 PCI_ANY_ID, PCI_ANY_ID, },
392 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
393 PCI_ANY_ID, PCI_ANY_ID, },
394 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1,
395 PCI_ANY_ID, PCI_ANY_ID, },
396 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0,
397 PCI_ANY_ID, PCI_ANY_ID, },
398 { 0, },
399};
400
401#if 0
402MODULE_DEVICE_TABLE(pci, esb2rom_pci_tbl);
403
404static struct pci_driver esb2rom_driver = {
405 .name = MOD_NAME,
406 .id_table = esb2rom_pci_tbl,
407 .probe = esb2rom_init_one,
408 .remove = esb2rom_remove_one,
409};
410#endif
411
412static int __init init_esb2rom(void)
413{
414 struct pci_dev *pdev;
415 struct pci_device_id *id;
416 int retVal;
417
418 pdev = NULL;
419 for (id = esb2rom_pci_tbl; id->vendor; id++) {
420 printk(KERN_DEBUG "device id = %x\n", id->device);
421 pdev = pci_get_device(id->vendor, id->device, NULL);
422 if (pdev) {
423 printk(KERN_DEBUG "matched device = %x\n", id->device);
424 break;
425 }
426 }
427 if (pdev) {
428 printk(KERN_DEBUG "matched device id %x\n", id->device);
429 retVal = esb2rom_init_one(pdev, &esb2rom_pci_tbl[0]);
430 pci_dev_put(pdev);
431 printk(KERN_DEBUG "retVal = %d\n", retVal);
432 return retVal;
433 }
434 return -ENXIO;
435#if 0
436 return pci_register_driver(&esb2rom_driver);
437#endif
438}
439
440static void __exit cleanup_esb2rom(void)
441{
442 esb2rom_remove_one(esb2rom_window.pdev);
443}
444
445module_init(init_esb2rom);
446module_exit(cleanup_esb2rom);
447
448MODULE_LICENSE("GPL");
449MODULE_AUTHOR("Lew Glendenning <lglendenning@lnxi.com>");
450MODULE_DESCRIPTION("MTD map driver for BIOS chips on the ESB2 southbridge");
diff --git a/drivers/mtd/maps/integrator-flash.c b/drivers/mtd/maps/integrator-flash.c
index c8db01b3e4..6946d802e6 100644
--- a/drivers/mtd/maps/integrator-flash.c
+++ b/drivers/mtd/maps/integrator-flash.c
@@ -75,14 +75,12 @@ static int armflash_probe(struct platform_device *dev)
75 int err; 75 int err;
76 void __iomem *base; 76 void __iomem *base;
77 77
78 info = kmalloc(sizeof(struct armflash_info), GFP_KERNEL); 78 info = kzalloc(sizeof(struct armflash_info), GFP_KERNEL);
79 if (!info) { 79 if (!info) {
80 err = -ENOMEM; 80 err = -ENOMEM;
81 goto out; 81 goto out;
82 } 82 }
83 83
84 memset(info, 0, sizeof(struct armflash_info));
85
86 info->plat = plat; 84 info->plat = plat;
87 if (plat && plat->init) { 85 if (plat && plat->init) {
88 err = plat->init(); 86 err = plat->init();
diff --git a/drivers/mtd/maps/nettel.c b/drivers/mtd/maps/nettel.c
index f9e8e5bcbc..9f53c655af 100644
--- a/drivers/mtd/maps/nettel.c
+++ b/drivers/mtd/maps/nettel.c
@@ -20,6 +20,7 @@
20#include <linux/mtd/partitions.h> 20#include <linux/mtd/partitions.h>
21#include <linux/mtd/cfi.h> 21#include <linux/mtd/cfi.h>
22#include <linux/reboot.h> 22#include <linux/reboot.h>
23#include <linux/err.h>
23#include <linux/kdev_t.h> 24#include <linux/kdev_t.h>
24#include <linux/root_dev.h> 25#include <linux/root_dev.h>
25#include <asm/io.h> 26#include <asm/io.h>
@@ -178,7 +179,7 @@ int nettel_eraseconfig(void)
178 179
179 init_waitqueue_head(&wait_q); 180 init_waitqueue_head(&wait_q);
180 mtd = get_mtd_device(NULL, 2); 181 mtd = get_mtd_device(NULL, 2);
181 if (mtd) { 182 if (!IS_ERR(mtd)) {
182 nettel_erase.mtd = mtd; 183 nettel_erase.mtd = mtd;
183 nettel_erase.callback = nettel_erasecallback; 184 nettel_erase.callback = nettel_erasecallback;
184 nettel_erase.callback = NULL; 185 nettel_erase.callback = NULL;
@@ -471,7 +472,7 @@ out_unmap2:
471 iounmap(nettel_amd_map.virt); 472 iounmap(nettel_amd_map.virt);
472 473
473 return(rc); 474 return(rc);
474 475
475} 476}
476 477
477/****************************************************************************/ 478/****************************************************************************/
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c
index 418afffb2d..e8d9ae5356 100644
--- a/drivers/mtd/maps/omap_nor.c
+++ b/drivers/mtd/maps/omap_nor.c
@@ -78,12 +78,10 @@ static int __devinit omapflash_probe(struct platform_device *pdev)
78 struct resource *res = pdev->resource; 78 struct resource *res = pdev->resource;
79 unsigned long size = res->end - res->start + 1; 79 unsigned long size = res->end - res->start + 1;
80 80
81 info = kmalloc(sizeof(struct omapflash_info), GFP_KERNEL); 81 info = kzalloc(sizeof(struct omapflash_info), GFP_KERNEL);
82 if (!info) 82 if (!info)
83 return -ENOMEM; 83 return -ENOMEM;
84 84
85 memset(info, 0, sizeof(struct omapflash_info));
86
87 if (!request_mem_region(res->start, size, "flash")) { 85 if (!request_mem_region(res->start, size, "flash")) {
88 err = -EBUSY; 86 err = -EBUSY;
89 goto out_free_info; 87 goto out_free_info;
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index 995347b1be..eaeb56a407 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -735,11 +735,10 @@ static int pcmciamtd_probe(struct pcmcia_device *link)
735 struct pcmciamtd_dev *dev; 735 struct pcmciamtd_dev *dev;
736 736
737 /* Create new memory card device */ 737 /* Create new memory card device */
738 dev = kmalloc(sizeof(*dev), GFP_KERNEL); 738 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
739 if (!dev) return -ENOMEM; 739 if (!dev) return -ENOMEM;
740 DEBUG(1, "dev=0x%p", dev); 740 DEBUG(1, "dev=0x%p", dev);
741 741
742 memset(dev, 0, sizeof(*dev));
743 dev->p_dev = link; 742 dev->p_dev = link;
744 link->priv = dev; 743 link->priv = dev;
745 744
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index d1717763f7..28c5ffd752 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -89,15 +89,14 @@ static int physmap_flash_probe(struct platform_device *dev)
89 return -ENODEV; 89 return -ENODEV;
90 90
91 printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n", 91 printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n",
92 (unsigned long long)dev->resource->end - dev->resource->start + 1, 92 (unsigned long long)(dev->resource->end - dev->resource->start + 1),
93 (unsigned long long)dev->resource->start); 93 (unsigned long long)dev->resource->start);
94 94
95 info = kmalloc(sizeof(struct physmap_flash_info), GFP_KERNEL); 95 info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
96 if (info == NULL) { 96 if (info == NULL) {
97 err = -ENOMEM; 97 err = -ENOMEM;
98 goto err_out; 98 goto err_out;
99 } 99 }
100 memset(info, 0, sizeof(*info));
101 100
102 platform_set_drvdata(dev, info); 101 platform_set_drvdata(dev, info);
103 102
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
new file mode 100644
index 0000000000..7efe744ad3
--- /dev/null
+++ b/drivers/mtd/maps/physmap_of.c
@@ -0,0 +1,255 @@
1/*
2 * Normal mappings of chips in physical memory for OF devices
3 *
4 * Copyright (C) 2006 MontaVista Software Inc.
5 * Author: Vitaly Wool <vwool@ru.mvista.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 as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/slab.h>
18#include <linux/device.h>
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h>
21#include <linux/mtd/partitions.h>
22#include <linux/mtd/physmap.h>
23#include <asm/io.h>
24#include <asm/prom.h>
25#include <asm/of_device.h>
26#include <asm/of_platform.h>
27
28struct physmap_flash_info {
29 struct mtd_info *mtd;
30 struct map_info map;
31 struct resource *res;
32#ifdef CONFIG_MTD_PARTITIONS
33 int nr_parts;
34 struct mtd_partition *parts;
35#endif
36};
37
38static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
39#ifdef CONFIG_MTD_PARTITIONS
40static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
41#endif
42
43#ifdef CONFIG_MTD_PARTITIONS
44static int parse_flash_partitions(struct device_node *node,
45 struct mtd_partition **parts)
46{
47 int i, plen, retval = -ENOMEM;
48 const u32 *part;
49 const char *name;
50
51 part = get_property(node, "partitions", &plen);
52 if (part == NULL)
53 goto err;
54
55 retval = plen / (2 * sizeof(u32));
56 *parts = kzalloc(retval * sizeof(struct mtd_partition), GFP_KERNEL);
57 if (*parts == NULL) {
58 printk(KERN_ERR "Can't allocate the flash partition data!\n");
59 goto err;
60 }
61
62 name = get_property(node, "partition-names", &plen);
63
64 for (i = 0; i < retval; i++) {
65 (*parts)[i].offset = *part++;
66 (*parts)[i].size = *part & ~1;
67 if (*part++ & 1) /* bit 0 set signifies read only partition */
68 (*parts)[i].mask_flags = MTD_WRITEABLE;
69
70 if (name != NULL && plen > 0) {
71 int len = strlen(name) + 1;
72
73 (*parts)[i].name = (char *)name;
74 plen -= len;
75 name += len;
76 } else
77 (*parts)[i].name = "unnamed";
78 }
79err:
80 return retval;
81}
82#endif
83
84static int of_physmap_remove(struct of_device *dev)
85{
86 struct physmap_flash_info *info;
87
88 info = dev_get_drvdata(&dev->dev);
89 if (info == NULL)
90 return 0;
91 dev_set_drvdata(&dev->dev, NULL);
92
93 if (info->mtd != NULL) {
94#ifdef CONFIG_MTD_PARTITIONS
95 if (info->nr_parts) {
96 del_mtd_partitions(info->mtd);
97 kfree(info->parts);
98 } else {
99 del_mtd_device(info->mtd);
100 }
101#else
102 del_mtd_device(info->mtd);
103#endif
104 map_destroy(info->mtd);
105 }
106
107 if (info->map.virt != NULL)
108 iounmap(info->map.virt);
109
110 if (info->res != NULL) {
111 release_resource(info->res);
112 kfree(info->res);
113 }
114
115 return 0;
116}
117
118static int __devinit of_physmap_probe(struct of_device *dev, const struct of_device_id *match)
119{
120 struct device_node *dp = dev->node;
121 struct resource res;
122 struct physmap_flash_info *info;
123 const char **probe_type;
124 const char *of_probe;
125 const u32 *width;
126 int err;
127
128
129 if (of_address_to_resource(dp, 0, &res)) {
130 dev_err(&dev->dev, "Can't get the flash mapping!\n");
131 err = -EINVAL;
132 goto err_out;
133 }
134
135 dev_dbg(&dev->dev, "physmap flash device: %.8llx at %.8llx\n",
136 (unsigned long long)res.end - res.start + 1,
137 (unsigned long long)res.start);
138
139 info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
140 if (info == NULL) {
141 err = -ENOMEM;
142 goto err_out;
143 }
144 memset(info, 0, sizeof(*info));
145
146 dev_set_drvdata(&dev->dev, info);
147
148 info->res = request_mem_region(res.start, res.end - res.start + 1,
149 dev->dev.bus_id);
150 if (info->res == NULL) {
151 dev_err(&dev->dev, "Could not reserve memory region\n");
152 err = -ENOMEM;
153 goto err_out;
154 }
155
156 width = get_property(dp, "bank-width", NULL);
157 if (width == NULL) {
158 dev_err(&dev->dev, "Can't get the flash bank width!\n");
159 err = -EINVAL;
160 goto err_out;
161 }
162
163 info->map.name = dev->dev.bus_id;
164 info->map.phys = res.start;
165 info->map.size = res.end - res.start + 1;
166 info->map.bankwidth = *width;
167
168 info->map.virt = ioremap(info->map.phys, info->map.size);
169 if (info->map.virt == NULL) {
170 dev_err(&dev->dev, "Failed to ioremap flash region\n");
171 err = EIO;
172 goto err_out;
173 }
174
175 simple_map_init(&info->map);
176
177 of_probe = get_property(dp, "probe-type", NULL);
178 if (of_probe == NULL) {
179 probe_type = rom_probe_types;
180 for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
181 info->mtd = do_map_probe(*probe_type, &info->map);
182 } else if (!strcmp(of_probe, "CFI"))
183 info->mtd = do_map_probe("cfi_probe", &info->map);
184 else if (!strcmp(of_probe, "JEDEC"))
185 info->mtd = do_map_probe("jedec_probe", &info->map);
186 else {
187 if (strcmp(of_probe, "ROM"))
188 dev_dbg(&dev->dev, "map_probe: don't know probe type "
189 "'%s', mapping as rom\n");
190 info->mtd = do_map_probe("mtd_rom", &info->map);
191 }
192 if (info->mtd == NULL) {
193 dev_err(&dev->dev, "map_probe failed\n");
194 err = -ENXIO;
195 goto err_out;
196 }
197 info->mtd->owner = THIS_MODULE;
198
199#ifdef CONFIG_MTD_PARTITIONS
200 err = parse_mtd_partitions(info->mtd, part_probe_types, &info->parts, 0);
201 if (err > 0) {
202 add_mtd_partitions(info->mtd, info->parts, err);
203 } else if ((err = parse_flash_partitions(dp, &info->parts)) > 0) {
204 dev_info(&dev->dev, "Using OF partition information\n");
205 add_mtd_partitions(info->mtd, info->parts, err);
206 info->nr_parts = err;
207 } else
208#endif
209
210 add_mtd_device(info->mtd);
211 return 0;
212
213err_out:
214 of_physmap_remove(dev);
215 return err;
216
217 return 0;
218
219
220}
221
222static struct of_device_id of_physmap_match[] = {
223 {
224 .type = "rom",
225 .compatible = "direct-mapped"
226 },
227 { },
228};
229
230MODULE_DEVICE_TABLE(of, of_physmap_match);
231
232
233static struct of_platform_driver of_physmap_flash_driver = {
234 .name = "physmap-flash",
235 .match_table = of_physmap_match,
236 .probe = of_physmap_probe,
237 .remove = of_physmap_remove,
238};
239
240static int __init of_physmap_init(void)
241{
242 return of_register_platform_driver(&of_physmap_flash_driver);
243}
244
245static void __exit of_physmap_exit(void)
246{
247 of_unregister_platform_driver(&of_physmap_flash_driver);
248}
249
250module_init(of_physmap_init);
251module_exit(of_physmap_exit);
252
253MODULE_LICENSE("GPL");
254MODULE_AUTHOR("Vitaly Wool <vwool@ru.mvista.com>");
255MODULE_DESCRIPTION("Configurable MTD map driver for OF");
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 5d3c75451c..2b6504ecbb 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -147,14 +147,13 @@ static int platram_probe(struct platform_device *pdev)
147 147
148 pdata = pdev->dev.platform_data; 148 pdata = pdev->dev.platform_data;
149 149
150 info = kmalloc(sizeof(*info), GFP_KERNEL); 150 info = kzalloc(sizeof(*info), GFP_KERNEL);
151 if (info == NULL) { 151 if (info == NULL) {
152 dev_err(&pdev->dev, "no memory for flash info\n"); 152 dev_err(&pdev->dev, "no memory for flash info\n");
153 err = -ENOMEM; 153 err = -ENOMEM;
154 goto exit_error; 154 goto exit_error;
155 } 155 }
156 156
157 memset(info, 0, sizeof(*info));
158 platform_set_drvdata(pdev, info); 157 platform_set_drvdata(pdev, info);
159 158
160 info->dev = &pdev->dev; 159 info->dev = &pdev->dev;
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index 950bf1c578..f904e6bd02 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -273,14 +273,12 @@ sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *plat)
273 /* 273 /*
274 * Allocate the map_info structs in one go. 274 * Allocate the map_info structs in one go.
275 */ 275 */
276 info = kmalloc(size, GFP_KERNEL); 276 info = kzalloc(size, GFP_KERNEL);
277 if (!info) { 277 if (!info) {
278 ret = -ENOMEM; 278 ret = -ENOMEM;
279 goto out; 279 goto out;
280 } 280 }
281 281
282 memset(info, 0, size);
283
284 if (plat->init) { 282 if (plat->init) {
285 ret = plat->init(); 283 ret = plat->init();
286 if (ret) 284 if (ret)
diff --git a/drivers/mtd/maps/tqm834x.c b/drivers/mtd/maps/tqm834x.c
index 58e5912bd3..9adc970e55 100644
--- a/drivers/mtd/maps/tqm834x.c
+++ b/drivers/mtd/maps/tqm834x.c
@@ -132,20 +132,16 @@ static int __init init_tqm834x_mtd(void)
132 132
133 pr_debug("%s: chip probing count %d\n", __FUNCTION__, idx); 133 pr_debug("%s: chip probing count %d\n", __FUNCTION__, idx);
134 134
135 map_banks[idx] = 135 map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL);
136 (struct map_info *)kmalloc(sizeof(struct map_info),
137 GFP_KERNEL);
138 if (map_banks[idx] == NULL) { 136 if (map_banks[idx] == NULL) {
139 ret = -ENOMEM; 137 ret = -ENOMEM;
140 goto error_mem; 138 goto error_mem;
141 } 139 }
142 memset((void *)map_banks[idx], 0, sizeof(struct map_info)); 140 map_banks[idx]->name = kzalloc(16, GFP_KERNEL);
143 map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
144 if (map_banks[idx]->name == NULL) { 141 if (map_banks[idx]->name == NULL) {
145 ret = -ENOMEM; 142 ret = -ENOMEM;
146 goto error_mem; 143 goto error_mem;
147 } 144 }
148 memset((void *)map_banks[idx]->name, 0, 16);
149 145
150 sprintf(map_banks[idx]->name, "TQM834x-%d", idx); 146 sprintf(map_banks[idx]->name, "TQM834x-%d", idx);
151 map_banks[idx]->size = flash_size; 147 map_banks[idx]->size = flash_size;
diff --git a/drivers/mtd/maps/tqm8xxl.c b/drivers/mtd/maps/tqm8xxl.c
index 19578ba84e..37e4ded9b6 100644
--- a/drivers/mtd/maps/tqm8xxl.c
+++ b/drivers/mtd/maps/tqm8xxl.c
@@ -134,14 +134,13 @@ int __init init_tqm_mtd(void)
134 134
135 printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx); 135 printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx);
136 136
137 map_banks[idx] = (struct map_info *)kmalloc(sizeof(struct map_info), GFP_KERNEL); 137 map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL);
138 if(map_banks[idx] == NULL) { 138 if(map_banks[idx] == NULL) {
139 ret = -ENOMEM; 139 ret = -ENOMEM;
140 /* FIXME: What if some MTD devices were probed already? */ 140 /* FIXME: What if some MTD devices were probed already? */
141 goto error_mem; 141 goto error_mem;
142 } 142 }
143 143
144 memset((void *)map_banks[idx], 0, sizeof(struct map_info));
145 map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL); 144 map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
146 145
147 if (!map_banks[idx]->name) { 146 if (!map_banks[idx]->name) {
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 178b53b56b..b879a66daa 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -42,19 +42,20 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
42 unsigned long block, nsect; 42 unsigned long block, nsect;
43 char *buf; 43 char *buf;
44 44
45 block = req->sector; 45 block = req->sector << 9 >> tr->blkshift;
46 nsect = req->current_nr_sectors; 46 nsect = req->current_nr_sectors << 9 >> tr->blkshift;
47
47 buf = req->buffer; 48 buf = req->buffer;
48 49
49 if (!blk_fs_request(req)) 50 if (!blk_fs_request(req))
50 return 0; 51 return 0;
51 52
52 if (block + nsect > get_capacity(req->rq_disk)) 53 if (req->sector + req->current_nr_sectors > get_capacity(req->rq_disk))
53 return 0; 54 return 0;
54 55
55 switch(rq_data_dir(req)) { 56 switch(rq_data_dir(req)) {
56 case READ: 57 case READ:
57 for (; nsect > 0; nsect--, block++, buf += 512) 58 for (; nsect > 0; nsect--, block++, buf += tr->blksize)
58 if (tr->readsect(dev, block, buf)) 59 if (tr->readsect(dev, block, buf))
59 return 0; 60 return 0;
60 return 1; 61 return 1;
@@ -63,7 +64,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
63 if (!tr->writesect) 64 if (!tr->writesect)
64 return 0; 65 return 0;
65 66
66 for (; nsect > 0; nsect--, block++, buf += 512) 67 for (; nsect > 0; nsect--, block++, buf += tr->blksize)
67 if (tr->writesect(dev, block, buf)) 68 if (tr->writesect(dev, block, buf))
68 return 0; 69 return 0;
69 return 1; 70 return 1;
@@ -297,7 +298,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
297 298
298 /* 2.5 has capacity in units of 512 bytes while still 299 /* 2.5 has capacity in units of 512 bytes while still
299 having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */ 300 having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */
300 set_capacity(gd, (new->size * new->blksize) >> 9); 301 set_capacity(gd, (new->size * tr->blksize) >> 9);
301 302
302 gd->private_data = new; 303 gd->private_data = new;
303 new->blkcore_priv = gd; 304 new->blkcore_priv = gd;
@@ -372,12 +373,10 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
372 if (!blktrans_notifier.list.next) 373 if (!blktrans_notifier.list.next)
373 register_mtd_user(&blktrans_notifier); 374 register_mtd_user(&blktrans_notifier);
374 375
375 tr->blkcore_priv = kmalloc(sizeof(*tr->blkcore_priv), GFP_KERNEL); 376 tr->blkcore_priv = kzalloc(sizeof(*tr->blkcore_priv), GFP_KERNEL);
376 if (!tr->blkcore_priv) 377 if (!tr->blkcore_priv)
377 return -ENOMEM; 378 return -ENOMEM;
378 379
379 memset(tr->blkcore_priv, 0, sizeof(*tr->blkcore_priv));
380
381 mutex_lock(&mtd_table_mutex); 380 mutex_lock(&mtd_table_mutex);
382 381
383 ret = register_blkdev(tr->major, tr->name); 382 ret = register_blkdev(tr->major, tr->name);
@@ -401,6 +400,8 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
401 } 400 }
402 401
403 tr->blkcore_priv->rq->queuedata = tr; 402 tr->blkcore_priv->rq->queuedata = tr;
403 blk_queue_hardsect_size(tr->blkcore_priv->rq, tr->blksize);
404 tr->blkshift = ffs(tr->blksize) - 1;
404 405
405 ret = kernel_thread(mtd_blktrans_thread, tr, CLONE_KERNEL); 406 ret = kernel_thread(mtd_blktrans_thread, tr, CLONE_KERNEL);
406 if (ret < 0) { 407 if (ret < 0) {
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 04ed34694b..952da30b17 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -278,11 +278,10 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
278 } 278 }
279 279
280 /* OK, it's not open. Create cache info for it */ 280 /* OK, it's not open. Create cache info for it */
281 mtdblk = kmalloc(sizeof(struct mtdblk_dev), GFP_KERNEL); 281 mtdblk = kzalloc(sizeof(struct mtdblk_dev), GFP_KERNEL);
282 if (!mtdblk) 282 if (!mtdblk)
283 return -ENOMEM; 283 return -ENOMEM;
284 284
285 memset(mtdblk, 0, sizeof(*mtdblk));
286 mtdblk->count = 1; 285 mtdblk->count = 1;
287 mtdblk->mtd = mtd; 286 mtdblk->mtd = mtd;
288 287
@@ -339,16 +338,14 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)
339 338
340static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) 339static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
341{ 340{
342 struct mtd_blktrans_dev *dev = kmalloc(sizeof(*dev), GFP_KERNEL); 341 struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
343 342
344 if (!dev) 343 if (!dev)
345 return; 344 return;
346 345
347 memset(dev, 0, sizeof(*dev));
348
349 dev->mtd = mtd; 346 dev->mtd = mtd;
350 dev->devnum = mtd->index; 347 dev->devnum = mtd->index;
351 dev->blksize = 512; 348
352 dev->size = mtd->size >> 9; 349 dev->size = mtd->size >> 9;
353 dev->tr = tr; 350 dev->tr = tr;
354 351
@@ -368,6 +365,7 @@ static struct mtd_blktrans_ops mtdblock_tr = {
368 .name = "mtdblock", 365 .name = "mtdblock",
369 .major = 31, 366 .major = 31,
370 .part_bits = 0, 367 .part_bits = 0,
368 .blksize = 512,
371 .open = mtdblock_open, 369 .open = mtdblock_open,
372 .flush = mtdblock_flush, 370 .flush = mtdblock_flush,
373 .release = mtdblock_release, 371 .release = mtdblock_release,
diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c
index 29563ed258..f79dbb49b1 100644
--- a/drivers/mtd/mtdblock_ro.c
+++ b/drivers/mtd/mtdblock_ro.c
@@ -33,16 +33,14 @@ static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
33 33
34static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) 34static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
35{ 35{
36 struct mtd_blktrans_dev *dev = kmalloc(sizeof(*dev), GFP_KERNEL); 36 struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
37 37
38 if (!dev) 38 if (!dev)
39 return; 39 return;
40 40
41 memset(dev, 0, sizeof(*dev));
42
43 dev->mtd = mtd; 41 dev->mtd = mtd;
44 dev->devnum = mtd->index; 42 dev->devnum = mtd->index;
45 dev->blksize = 512; 43
46 dev->size = mtd->size >> 9; 44 dev->size = mtd->size >> 9;
47 dev->tr = tr; 45 dev->tr = tr;
48 dev->readonly = 1; 46 dev->readonly = 1;
@@ -60,6 +58,7 @@ static struct mtd_blktrans_ops mtdblock_tr = {
60 .name = "mtdblock", 58 .name = "mtdblock",
61 .major = 31, 59 .major = 31,
62 .part_bits = 0, 60 .part_bits = 0,
61 .blksize = 512,
63 .readsect = mtdblock_readsect, 62 .readsect = mtdblock_readsect,
64 .writesect = mtdblock_writesect, 63 .writesect = mtdblock_writesect,
65 .add_mtd = mtdblock_add_mtd, 64 .add_mtd = mtdblock_add_mtd,
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 5b6acfcb2b..3013d0883b 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -7,6 +7,7 @@
7 7
8#include <linux/device.h> 8#include <linux/device.h>
9#include <linux/fs.h> 9#include <linux/fs.h>
10#include <linux/err.h>
10#include <linux/init.h> 11#include <linux/init.h>
11#include <linux/kernel.h> 12#include <linux/kernel.h>
12#include <linux/module.h> 13#include <linux/module.h>
@@ -100,8 +101,8 @@ static int mtd_open(struct inode *inode, struct file *file)
100 101
101 mtd = get_mtd_device(NULL, devnum); 102 mtd = get_mtd_device(NULL, devnum);
102 103
103 if (!mtd) 104 if (IS_ERR(mtd))
104 return -ENODEV; 105 return PTR_ERR(mtd);
105 106
106 if (MTD_ABSENT == mtd->type) { 107 if (MTD_ABSENT == mtd->type) {
107 put_mtd_device(mtd); 108 put_mtd_device(mtd);
@@ -431,7 +432,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
431 if(!(file->f_mode & 2)) 432 if(!(file->f_mode & 2))
432 return -EPERM; 433 return -EPERM;
433 434
434 erase=kmalloc(sizeof(struct erase_info),GFP_KERNEL); 435 erase=kzalloc(sizeof(struct erase_info),GFP_KERNEL);
435 if (!erase) 436 if (!erase)
436 ret = -ENOMEM; 437 ret = -ENOMEM;
437 else { 438 else {
@@ -440,7 +441,6 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
440 441
441 init_waitqueue_head(&waitq); 442 init_waitqueue_head(&waitq);
442 443
443 memset (erase,0,sizeof(struct erase_info));
444 if (copy_from_user(&erase->addr, argp, 444 if (copy_from_user(&erase->addr, argp,
445 sizeof(struct erase_info_user))) { 445 sizeof(struct erase_info_user))) {
446 kfree(erase); 446 kfree(erase);
@@ -499,13 +499,12 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
499 if (ret) 499 if (ret)
500 return ret; 500 return ret;
501 501
502 ops.len = buf.length;
503 ops.ooblen = buf.length; 502 ops.ooblen = buf.length;
504 ops.ooboffs = buf.start & (mtd->oobsize - 1); 503 ops.ooboffs = buf.start & (mtd->oobsize - 1);
505 ops.datbuf = NULL; 504 ops.datbuf = NULL;
506 ops.mode = MTD_OOB_PLACE; 505 ops.mode = MTD_OOB_PLACE;
507 506
508 if (ops.ooboffs && ops.len > (mtd->oobsize - ops.ooboffs)) 507 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs))
509 return -EINVAL; 508 return -EINVAL;
510 509
511 ops.oobbuf = kmalloc(buf.length, GFP_KERNEL); 510 ops.oobbuf = kmalloc(buf.length, GFP_KERNEL);
@@ -520,7 +519,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
520 buf.start &= ~(mtd->oobsize - 1); 519 buf.start &= ~(mtd->oobsize - 1);
521 ret = mtd->write_oob(mtd, buf.start, &ops); 520 ret = mtd->write_oob(mtd, buf.start, &ops);
522 521
523 if (copy_to_user(argp + sizeof(uint32_t), &ops.retlen, 522 if (copy_to_user(argp + sizeof(uint32_t), &ops.oobretlen,
524 sizeof(uint32_t))) 523 sizeof(uint32_t)))
525 ret = -EFAULT; 524 ret = -EFAULT;
526 525
@@ -548,7 +547,6 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
548 if (ret) 547 if (ret)
549 return ret; 548 return ret;
550 549
551 ops.len = buf.length;
552 ops.ooblen = buf.length; 550 ops.ooblen = buf.length;
553 ops.ooboffs = buf.start & (mtd->oobsize - 1); 551 ops.ooboffs = buf.start & (mtd->oobsize - 1);
554 ops.datbuf = NULL; 552 ops.datbuf = NULL;
@@ -564,10 +562,10 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
564 buf.start &= ~(mtd->oobsize - 1); 562 buf.start &= ~(mtd->oobsize - 1);
565 ret = mtd->read_oob(mtd, buf.start, &ops); 563 ret = mtd->read_oob(mtd, buf.start, &ops);
566 564
567 if (put_user(ops.retlen, (uint32_t __user *)argp)) 565 if (put_user(ops.oobretlen, (uint32_t __user *)argp))
568 ret = -EFAULT; 566 ret = -EFAULT;
569 else if (ops.retlen && copy_to_user(buf.ptr, ops.oobbuf, 567 else if (ops.oobretlen && copy_to_user(buf.ptr, ops.oobbuf,
570 ops.retlen)) 568 ops.oobretlen))
571 ret = -EFAULT; 569 ret = -EFAULT;
572 570
573 kfree(ops.oobbuf); 571 kfree(ops.oobbuf);
@@ -616,6 +614,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
616 memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos)); 614 memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos));
617 memcpy(&oi.oobfree, mtd->ecclayout->oobfree, 615 memcpy(&oi.oobfree, mtd->ecclayout->oobfree,
618 sizeof(oi.oobfree)); 616 sizeof(oi.oobfree));
617 oi.eccbytes = mtd->ecclayout->eccbytes;
619 618
620 if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo))) 619 if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo)))
621 return -EFAULT; 620 return -EFAULT;
@@ -715,7 +714,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
715 if (!mtd->ecclayout) 714 if (!mtd->ecclayout)
716 return -EOPNOTSUPP; 715 return -EOPNOTSUPP;
717 716
718 if (copy_to_user(argp, &mtd->ecclayout, 717 if (copy_to_user(argp, mtd->ecclayout,
719 sizeof(struct nand_ecclayout))) 718 sizeof(struct nand_ecclayout)))
720 return -EFAULT; 719 return -EFAULT;
721 break; 720 break;
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 1fea631b58..06902683bc 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -247,7 +247,7 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
247 struct mtd_oob_ops devops = *ops; 247 struct mtd_oob_ops devops = *ops;
248 int i, err, ret = 0; 248 int i, err, ret = 0;
249 249
250 ops->retlen = 0; 250 ops->retlen = ops->oobretlen = 0;
251 251
252 for (i = 0; i < concat->num_subdev; i++) { 252 for (i = 0; i < concat->num_subdev; i++) {
253 struct mtd_info *subdev = concat->subdev[i]; 253 struct mtd_info *subdev = concat->subdev[i];
@@ -263,6 +263,7 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
263 263
264 err = subdev->read_oob(subdev, from, &devops); 264 err = subdev->read_oob(subdev, from, &devops);
265 ops->retlen += devops.retlen; 265 ops->retlen += devops.retlen;
266 ops->oobretlen += devops.oobretlen;
266 267
267 /* Save information about bitflips! */ 268 /* Save information about bitflips! */
268 if (unlikely(err)) { 269 if (unlikely(err)) {
@@ -278,14 +279,18 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
278 return err; 279 return err;
279 } 280 }
280 281
281 devops.len = ops->len - ops->retlen; 282 if (devops.datbuf) {
282 if (!devops.len) 283 devops.len = ops->len - ops->retlen;
283 return ret; 284 if (!devops.len)
284 285 return ret;
285 if (devops.datbuf)
286 devops.datbuf += devops.retlen; 286 devops.datbuf += devops.retlen;
287 if (devops.oobbuf) 287 }
288 devops.oobbuf += devops.ooblen; 288 if (devops.oobbuf) {
289 devops.ooblen = ops->ooblen - ops->oobretlen;
290 if (!devops.ooblen)
291 return ret;
292 devops.oobbuf += ops->oobretlen;
293 }
289 294
290 from = 0; 295 from = 0;
291 } 296 }
@@ -321,14 +326,18 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
321 if (err) 326 if (err)
322 return err; 327 return err;
323 328
324 devops.len = ops->len - ops->retlen; 329 if (devops.datbuf) {
325 if (!devops.len) 330 devops.len = ops->len - ops->retlen;
326 return 0; 331 if (!devops.len)
327 332 return 0;
328 if (devops.datbuf)
329 devops.datbuf += devops.retlen; 333 devops.datbuf += devops.retlen;
330 if (devops.oobbuf) 334 }
331 devops.oobbuf += devops.ooblen; 335 if (devops.oobbuf) {
336 devops.ooblen = ops->ooblen - ops->oobretlen;
337 if (!devops.ooblen)
338 return 0;
339 devops.oobbuf += devops.oobretlen;
340 }
332 to = 0; 341 to = 0;
333 } 342 }
334 return -EINVAL; 343 return -EINVAL;
@@ -699,14 +708,13 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
699 708
700 /* allocate the device structure */ 709 /* allocate the device structure */
701 size = SIZEOF_STRUCT_MTD_CONCAT(num_devs); 710 size = SIZEOF_STRUCT_MTD_CONCAT(num_devs);
702 concat = kmalloc(size, GFP_KERNEL); 711 concat = kzalloc(size, GFP_KERNEL);
703 if (!concat) { 712 if (!concat) {
704 printk 713 printk
705 ("memory allocation error while creating concatenated device \"%s\"\n", 714 ("memory allocation error while creating concatenated device \"%s\"\n",
706 name); 715 name);
707 return NULL; 716 return NULL;
708 } 717 }
709 memset(concat, 0, size);
710 concat->subdev = (struct mtd_info **) (concat + 1); 718 concat->subdev = (struct mtd_info **) (concat + 1);
711 719
712 /* 720 /*
@@ -764,6 +772,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
764 concat->mtd.ecc_stats.badblocks += 772 concat->mtd.ecc_stats.badblocks +=
765 subdev[i]->ecc_stats.badblocks; 773 subdev[i]->ecc_stats.badblocks;
766 if (concat->mtd.writesize != subdev[i]->writesize || 774 if (concat->mtd.writesize != subdev[i]->writesize ||
775 concat->mtd.subpage_sft != subdev[i]->subpage_sft ||
767 concat->mtd.oobsize != subdev[i]->oobsize || 776 concat->mtd.oobsize != subdev[i]->oobsize ||
768 concat->mtd.ecctype != subdev[i]->ecctype || 777 concat->mtd.ecctype != subdev[i]->ecctype ||
769 concat->mtd.eccsize != subdev[i]->eccsize || 778 concat->mtd.eccsize != subdev[i]->eccsize ||
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index c4d26de743..7070110aba 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -15,6 +15,7 @@
15#include <linux/timer.h> 15#include <linux/timer.h>
16#include <linux/major.h> 16#include <linux/major.h>
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/err.h>
18#include <linux/ioctl.h> 19#include <linux/ioctl.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/mtd/compatmac.h> 21#include <linux/mtd/compatmac.h>
@@ -192,14 +193,14 @@ int unregister_mtd_user (struct mtd_notifier *old)
192 * Given a number and NULL address, return the num'th entry in the device 193 * Given a number and NULL address, return the num'th entry in the device
193 * table, if any. Given an address and num == -1, search the device table 194 * table, if any. Given an address and num == -1, search the device table
194 * for a device with that address and return if it's still present. Given 195 * for a device with that address and return if it's still present. Given
195 * both, return the num'th driver only if its address matches. Return NULL 196 * both, return the num'th driver only if its address matches. Return
196 * if not. 197 * error code if not.
197 */ 198 */
198 199
199struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) 200struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
200{ 201{
201 struct mtd_info *ret = NULL; 202 struct mtd_info *ret = NULL;
202 int i; 203 int i, err = -ENODEV;
203 204
204 mutex_lock(&mtd_table_mutex); 205 mutex_lock(&mtd_table_mutex);
205 206
@@ -213,14 +214,73 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
213 ret = NULL; 214 ret = NULL;
214 } 215 }
215 216
216 if (ret && !try_module_get(ret->owner)) 217 if (!ret)
217 ret = NULL; 218 goto out_unlock;
219
220 if (!try_module_get(ret->owner))
221 goto out_unlock;
218 222
219 if (ret) 223 if (ret->get_device) {
220 ret->usecount++; 224 err = ret->get_device(ret);
225 if (err)
226 goto out_put;
227 }
221 228
229 ret->usecount++;
222 mutex_unlock(&mtd_table_mutex); 230 mutex_unlock(&mtd_table_mutex);
223 return ret; 231 return ret;
232
233out_put:
234 module_put(ret->owner);
235out_unlock:
236 mutex_unlock(&mtd_table_mutex);
237 return ERR_PTR(err);
238}
239
240/**
241 * get_mtd_device_nm - obtain a validated handle for an MTD device by
242 * device name
243 * @name: MTD device name to open
244 *
245 * This function returns MTD device description structure in case of
246 * success and an error code in case of failure.
247 */
248
249struct mtd_info *get_mtd_device_nm(const char *name)
250{
251 int i, err = -ENODEV;
252 struct mtd_info *mtd = NULL;
253
254 mutex_lock(&mtd_table_mutex);
255
256 for (i = 0; i < MAX_MTD_DEVICES; i++) {
257 if (mtd_table[i] && !strcmp(name, mtd_table[i]->name)) {
258 mtd = mtd_table[i];
259 break;
260 }
261 }
262
263 if (!mtd)
264 goto out_unlock;
265
266 if (!try_module_get(mtd->owner))
267 goto out_unlock;
268
269 if (mtd->get_device) {
270 err = mtd->get_device(mtd);
271 if (err)
272 goto out_put;
273 }
274
275 mtd->usecount++;
276 mutex_unlock(&mtd_table_mutex);
277 return mtd;
278
279out_put:
280 module_put(mtd->owner);
281out_unlock:
282 mutex_unlock(&mtd_table_mutex);
283 return ERR_PTR(err);
224} 284}
225 285
226void put_mtd_device(struct mtd_info *mtd) 286void put_mtd_device(struct mtd_info *mtd)
@@ -229,6 +289,8 @@ void put_mtd_device(struct mtd_info *mtd)
229 289
230 mutex_lock(&mtd_table_mutex); 290 mutex_lock(&mtd_table_mutex);
231 c = --mtd->usecount; 291 c = --mtd->usecount;
292 if (mtd->put_device)
293 mtd->put_device(mtd);
232 mutex_unlock(&mtd_table_mutex); 294 mutex_unlock(&mtd_table_mutex);
233 BUG_ON(c < 0); 295 BUG_ON(c < 0);
234 296
@@ -236,7 +298,7 @@ void put_mtd_device(struct mtd_info *mtd)
236} 298}
237 299
238/* default_mtd_writev - default mtd writev method for MTD devices that 300/* default_mtd_writev - default mtd writev method for MTD devices that
239 * dont implement their own 301 * don't implement their own
240 */ 302 */
241 303
242int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, 304int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
@@ -264,13 +326,14 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
264 return ret; 326 return ret;
265} 327}
266 328
267EXPORT_SYMBOL(add_mtd_device); 329EXPORT_SYMBOL_GPL(add_mtd_device);
268EXPORT_SYMBOL(del_mtd_device); 330EXPORT_SYMBOL_GPL(del_mtd_device);
269EXPORT_SYMBOL(get_mtd_device); 331EXPORT_SYMBOL_GPL(get_mtd_device);
270EXPORT_SYMBOL(put_mtd_device); 332EXPORT_SYMBOL_GPL(get_mtd_device_nm);
271EXPORT_SYMBOL(register_mtd_user); 333EXPORT_SYMBOL_GPL(put_mtd_device);
272EXPORT_SYMBOL(unregister_mtd_user); 334EXPORT_SYMBOL_GPL(register_mtd_user);
273EXPORT_SYMBOL(default_mtd_writev); 335EXPORT_SYMBOL_GPL(unregister_mtd_user);
336EXPORT_SYMBOL_GPL(default_mtd_writev);
274 337
275#ifdef CONFIG_PROC_FS 338#ifdef CONFIG_PROC_FS
276 339
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 06a930372b..bafd2fba87 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -94,7 +94,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
94 94
95 if (from >= mtd->size) 95 if (from >= mtd->size)
96 return -EINVAL; 96 return -EINVAL;
97 if (from + ops->len > mtd->size) 97 if (ops->datbuf && from + ops->len > mtd->size)
98 return -EINVAL; 98 return -EINVAL;
99 res = part->master->read_oob(part->master, from + part->offset, ops); 99 res = part->master->read_oob(part->master, from + part->offset, ops);
100 100
@@ -161,7 +161,7 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to,
161 161
162 if (to >= mtd->size) 162 if (to >= mtd->size)
163 return -EINVAL; 163 return -EINVAL;
164 if (to + ops->len > mtd->size) 164 if (ops->datbuf && to + ops->len > mtd->size)
165 return -EINVAL; 165 return -EINVAL;
166 return part->master->write_oob(part->master, to + part->offset, ops); 166 return part->master->write_oob(part->master, to + part->offset, ops);
167} 167}
@@ -323,14 +323,13 @@ int add_mtd_partitions(struct mtd_info *master,
323 for (i = 0; i < nbparts; i++) { 323 for (i = 0; i < nbparts; i++) {
324 324
325 /* allocate the partition structure */ 325 /* allocate the partition structure */
326 slave = kmalloc (sizeof(*slave), GFP_KERNEL); 326 slave = kzalloc (sizeof(*slave), GFP_KERNEL);
327 if (!slave) { 327 if (!slave) {
328 printk ("memory allocation error while creating partitions for \"%s\"\n", 328 printk ("memory allocation error while creating partitions for \"%s\"\n",
329 master->name); 329 master->name);
330 del_mtd_partitions(master); 330 del_mtd_partitions(master);
331 return -ENOMEM; 331 return -ENOMEM;
332 } 332 }
333 memset(slave, 0, sizeof(*slave));
334 list_add(&slave->list, &mtd_partitions); 333 list_add(&slave->list, &mtd_partitions);
335 334
336 /* set up the MTD object for this partition */ 335 /* set up the MTD object for this partition */
@@ -341,6 +340,7 @@ int add_mtd_partitions(struct mtd_info *master,
341 slave->mtd.oobsize = master->oobsize; 340 slave->mtd.oobsize = master->oobsize;
342 slave->mtd.ecctype = master->ecctype; 341 slave->mtd.ecctype = master->ecctype;
343 slave->mtd.eccsize = master->eccsize; 342 slave->mtd.eccsize = master->eccsize;
343 slave->mtd.subpage_sft = master->subpage_sft;
344 344
345 slave->mtd.name = parts[i].name; 345 slave->mtd.name = parts[i].name;
346 slave->mtd.bank_size = master->bank_size; 346 slave->mtd.bank_size = master->bank_size;
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 1831340e5f..358f55a82d 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -90,6 +90,7 @@ config MTD_NAND_RTC_FROM4
90 depends on MTD_NAND && SH_SOLUTION_ENGINE 90 depends on MTD_NAND && SH_SOLUTION_ENGINE
91 select REED_SOLOMON 91 select REED_SOLOMON
92 select REED_SOLOMON_DEC8 92 select REED_SOLOMON_DEC8
93 select BITREVERSE
93 help 94 help
94 This enables the driver for the Renesas Technology AG-AND 95 This enables the driver for the Renesas Technology AG-AND
95 flash interface board (FROM_BOARD4) 96 flash interface board (FROM_BOARD4)
@@ -132,6 +133,7 @@ config MTD_NAND_S3C2410_HWECC
132config MTD_NAND_NDFC 133config MTD_NAND_NDFC
133 tristate "NDFC NanD Flash Controller" 134 tristate "NDFC NanD Flash Controller"
134 depends on MTD_NAND && 44x 135 depends on MTD_NAND && 44x
136 select MTD_NAND_ECC_SMC
135 help 137 help
136 NDFC Nand Flash Controllers are integrated in EP44x SoCs 138 NDFC Nand Flash Controllers are integrated in EP44x SoCs
137 139
@@ -219,6 +221,13 @@ config MTD_NAND_SHARPSL
219 tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)" 221 tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)"
220 depends on MTD_NAND && ARCH_PXA 222 depends on MTD_NAND && ARCH_PXA
221 223
224config MTD_NAND_CAFE
225 tristate "NAND support for OLPC CAFÉ chip"
226 depends on PCI
227 help
228 Use NAND flash attached to the CAFÉ chip designed for the $100
229 laptop.
230
222config MTD_NAND_CS553X 231config MTD_NAND_CS553X
223 tristate "NAND support for CS5535/CS5536 (AMD Geode companion chip)" 232 tristate "NAND support for CS5535/CS5536 (AMD Geode companion chip)"
224 depends on MTD_NAND && X86_32 && (X86_PC || X86_GENERICARCH) 233 depends on MTD_NAND && X86_32 && (X86_PC || X86_GENERICARCH)
@@ -232,6 +241,13 @@ config MTD_NAND_CS553X
232 241
233 If you say "m", the module will be called "cs553x_nand.ko". 242 If you say "m", the module will be called "cs553x_nand.ko".
234 243
244config MTD_NAND_AT91
245 bool "Support for NAND Flash / SmartMedia on AT91"
246 depends on MTD_NAND && ARCH_AT91
247 help
248 Enables support for NAND Flash / Smart Media Card interface
249 on Atmel AT91 processors.
250
235config MTD_NAND_NANDSIM 251config MTD_NAND_NANDSIM
236 tristate "Support for NAND Flash Simulator" 252 tristate "Support for NAND Flash Simulator"
237 depends on MTD_NAND && MTD_PARTITIONS 253 depends on MTD_NAND && MTD_PARTITIONS
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index f74759351c..f7a53f0b70 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -6,6 +6,7 @@
6obj-$(CONFIG_MTD_NAND) += nand.o nand_ecc.o 6obj-$(CONFIG_MTD_NAND) += nand.o nand_ecc.o
7obj-$(CONFIG_MTD_NAND_IDS) += nand_ids.o 7obj-$(CONFIG_MTD_NAND_IDS) += nand_ids.o
8 8
9obj-$(CONFIG_MTD_NAND_CAFE) += cafe_nand.o
9obj-$(CONFIG_MTD_NAND_SPIA) += spia.o 10obj-$(CONFIG_MTD_NAND_SPIA) += spia.o
10obj-$(CONFIG_MTD_NAND_AMS_DELTA) += ams-delta.o 11obj-$(CONFIG_MTD_NAND_AMS_DELTA) += ams-delta.o
11obj-$(CONFIG_MTD_NAND_TOTO) += toto.o 12obj-$(CONFIG_MTD_NAND_TOTO) += toto.o
@@ -22,5 +23,7 @@ obj-$(CONFIG_MTD_NAND_TS7250) += ts7250.o
22obj-$(CONFIG_MTD_NAND_NANDSIM) += nandsim.o 23obj-$(CONFIG_MTD_NAND_NANDSIM) += nandsim.o
23obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o 24obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o
24obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o 25obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o
26obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o
25 27
26nand-objs = nand_base.o nand_bbt.o 28nand-objs := nand_base.o nand_bbt.o
29cafe_nand-objs := cafe.o cafe_ecc.o
diff --git a/drivers/mtd/nand/at91_nand.c b/drivers/mtd/nand/at91_nand.c
new file mode 100644
index 0000000000..14b80cc90a
--- /dev/null
+++ b/drivers/mtd/nand/at91_nand.c
@@ -0,0 +1,223 @@
1/*
2 * drivers/mtd/nand/at91_nand.c
3 *
4 * Copyright (C) 2003 Rick Bronson
5 *
6 * Derived from drivers/mtd/nand/autcpu12.c
7 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
8 *
9 * Derived from drivers/mtd/spia.c
10 * Copyright (C) 2000 Steven J. Hill (sjhill@cotw.com)
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 */
17
18#include <linux/slab.h>
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/mtd/mtd.h>
22#include <linux/mtd/nand.h>
23#include <linux/mtd/partitions.h>
24
25#include <asm/io.h>
26#include <asm/sizes.h>
27
28#include <asm/hardware.h>
29#include <asm/arch/board.h>
30#include <asm/arch/gpio.h>
31
32struct at91_nand_host {
33 struct nand_chip nand_chip;
34 struct mtd_info mtd;
35 void __iomem *io_base;
36 struct at91_nand_data *board;
37};
38
39/*
40 * Hardware specific access to control-lines
41 */
42static void at91_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
43{
44 struct nand_chip *nand_chip = mtd->priv;
45 struct at91_nand_host *host = nand_chip->priv;
46
47 if (cmd == NAND_CMD_NONE)
48 return;
49
50 if (ctrl & NAND_CLE)
51 writeb(cmd, host->io_base + (1 << host->board->cle));
52 else
53 writeb(cmd, host->io_base + (1 << host->board->ale));
54}
55
56/*
57 * Read the Device Ready pin.
58 */
59static int at91_nand_device_ready(struct mtd_info *mtd)
60{
61 struct nand_chip *nand_chip = mtd->priv;
62 struct at91_nand_host *host = nand_chip->priv;
63
64 return at91_get_gpio_value(host->board->rdy_pin);
65}
66
67/*
68 * Enable NAND.
69 */
70static void at91_nand_enable(struct at91_nand_host *host)
71{
72 if (host->board->enable_pin)
73 at91_set_gpio_value(host->board->enable_pin, 0);
74}
75
76/*
77 * Disable NAND.
78 */
79static void at91_nand_disable(struct at91_nand_host *host)
80{
81 if (host->board->enable_pin)
82 at91_set_gpio_value(host->board->enable_pin, 1);
83}
84
85/*
86 * Probe for the NAND device.
87 */
88static int __init at91_nand_probe(struct platform_device *pdev)
89{
90 struct at91_nand_host *host;
91 struct mtd_info *mtd;
92 struct nand_chip *nand_chip;
93 int res;
94
95#ifdef CONFIG_MTD_PARTITIONS
96 struct mtd_partition *partitions = NULL;
97 int num_partitions = 0;
98#endif
99
100 /* Allocate memory for the device structure (and zero it) */
101 host = kzalloc(sizeof(struct at91_nand_host), GFP_KERNEL);
102 if (!host) {
103 printk(KERN_ERR "at91_nand: failed to allocate device structure.\n");
104 return -ENOMEM;
105 }
106
107 host->io_base = ioremap(pdev->resource[0].start,
108 pdev->resource[0].end - pdev->resource[0].start + 1);
109 if (host->io_base == NULL) {
110 printk(KERN_ERR "at91_nand: ioremap failed\n");
111 kfree(host);
112 return -EIO;
113 }
114
115 mtd = &host->mtd;
116 nand_chip = &host->nand_chip;
117 host->board = pdev->dev.platform_data;
118
119 nand_chip->priv = host; /* link the private data structures */
120 mtd->priv = nand_chip;
121 mtd->owner = THIS_MODULE;
122
123 /* Set address of NAND IO lines */
124 nand_chip->IO_ADDR_R = host->io_base;
125 nand_chip->IO_ADDR_W = host->io_base;
126 nand_chip->cmd_ctrl = at91_nand_cmd_ctrl;
127 nand_chip->dev_ready = at91_nand_device_ready;
128 nand_chip->ecc.mode = NAND_ECC_SOFT; /* enable ECC */
129 nand_chip->chip_delay = 20; /* 20us command delay time */
130
131 if (host->board->bus_width_16) /* 16-bit bus width */
132 nand_chip->options |= NAND_BUSWIDTH_16;
133
134 platform_set_drvdata(pdev, host);
135 at91_nand_enable(host);
136
137 if (host->board->det_pin) {
138 if (at91_get_gpio_value(host->board->det_pin)) {
139 printk ("No SmartMedia card inserted.\n");
140 res = ENXIO;
141 goto out;
142 }
143 }
144
145 /* Scan to find existance of the device */
146 if (nand_scan(mtd, 1)) {
147 res = -ENXIO;
148 goto out;
149 }
150
151#ifdef CONFIG_MTD_PARTITIONS
152 if (host->board->partition_info)
153 partitions = host->board->partition_info(mtd->size, &num_partitions);
154
155 if ((!partitions) || (num_partitions == 0)) {
156 printk(KERN_ERR "at91_nand: No parititions defined, or unsupported device.\n");
157 res = ENXIO;
158 goto release;
159 }
160
161 res = add_mtd_partitions(mtd, partitions, num_partitions);
162#else
163 res = add_mtd_device(mtd);
164#endif
165
166 if (!res)
167 return res;
168
169release:
170 nand_release(mtd);
171out:
172 at91_nand_disable(host);
173 platform_set_drvdata(pdev, NULL);
174 iounmap(host->io_base);
175 kfree(host);
176 return res;
177}
178
179/*
180 * Remove a NAND device.
181 */
182static int __devexit at91_nand_remove(struct platform_device *pdev)
183{
184 struct at91_nand_host *host = platform_get_drvdata(pdev);
185 struct mtd_info *mtd = &host->mtd;
186
187 nand_release(mtd);
188
189 at91_nand_disable(host);
190
191 iounmap(host->io_base);
192 kfree(host);
193
194 return 0;
195}
196
197static struct platform_driver at91_nand_driver = {
198 .probe = at91_nand_probe,
199 .remove = at91_nand_remove,
200 .driver = {
201 .name = "at91_nand",
202 .owner = THIS_MODULE,
203 },
204};
205
206static int __init at91_nand_init(void)
207{
208 return platform_driver_register(&at91_nand_driver);
209}
210
211
212static void __exit at91_nand_exit(void)
213{
214 platform_driver_unregister(&at91_nand_driver);
215}
216
217
218module_init(at91_nand_init);
219module_exit(at91_nand_exit);
220
221MODULE_LICENSE("GPL");
222MODULE_AUTHOR("Rick Bronson");
223MODULE_DESCRIPTION("NAND/SmartMedia driver for AT91RM9200");
diff --git a/drivers/mtd/nand/cafe.c b/drivers/mtd/nand/cafe.c
new file mode 100644
index 0000000000..65f9bd3cee
--- /dev/null
+++ b/drivers/mtd/nand/cafe.c
@@ -0,0 +1,771 @@
1/*
2 * Driver for One Laptop Per Child ‘CAFÉ’ controller, aka Marvell 88ALP01
3 *
4 * Copyright © 2006 Red Hat, Inc.
5 * Copyright © 2006 David Woodhouse <dwmw2@infradead.org>
6 */
7
8#define DEBUG
9
10#include <linux/device.h>
11#undef DEBUG
12#include <linux/mtd/mtd.h>
13#include <linux/mtd/nand.h>
14#include <linux/pci.h>
15#include <linux/delay.h>
16#include <linux/interrupt.h>
17#include <linux/dma-mapping.h>
18#include <asm/io.h>
19
20#define CAFE_NAND_CTRL1 0x00
21#define CAFE_NAND_CTRL2 0x04
22#define CAFE_NAND_CTRL3 0x08
23#define CAFE_NAND_STATUS 0x0c
24#define CAFE_NAND_IRQ 0x10
25#define CAFE_NAND_IRQ_MASK 0x14
26#define CAFE_NAND_DATA_LEN 0x18
27#define CAFE_NAND_ADDR1 0x1c
28#define CAFE_NAND_ADDR2 0x20
29#define CAFE_NAND_TIMING1 0x24
30#define CAFE_NAND_TIMING2 0x28
31#define CAFE_NAND_TIMING3 0x2c
32#define CAFE_NAND_NONMEM 0x30
33#define CAFE_NAND_ECC_RESULT 0x3C
34#define CAFE_NAND_DMA_CTRL 0x40
35#define CAFE_NAND_DMA_ADDR0 0x44
36#define CAFE_NAND_DMA_ADDR1 0x48
37#define CAFE_NAND_ECC_SYN01 0x50
38#define CAFE_NAND_ECC_SYN23 0x54
39#define CAFE_NAND_ECC_SYN45 0x58
40#define CAFE_NAND_ECC_SYN67 0x5c
41#define CAFE_NAND_READ_DATA 0x1000
42#define CAFE_NAND_WRITE_DATA 0x2000
43
44#define CAFE_GLOBAL_CTRL 0x3004
45#define CAFE_GLOBAL_IRQ 0x3008
46#define CAFE_GLOBAL_IRQ_MASK 0x300c
47#define CAFE_NAND_RESET 0x3034
48
49int cafe_correct_ecc(unsigned char *buf,
50 unsigned short *chk_syndrome_list);
51
52struct cafe_priv {
53 struct nand_chip nand;
54 struct pci_dev *pdev;
55 void __iomem *mmio;
56 uint32_t ctl1;
57 uint32_t ctl2;
58 int datalen;
59 int nr_data;
60 int data_pos;
61 int page_addr;
62 dma_addr_t dmaaddr;
63 unsigned char *dmabuf;
64};
65
66static int usedma = 1;
67module_param(usedma, int, 0644);
68
69static int skipbbt = 0;
70module_param(skipbbt, int, 0644);
71
72static int debug = 0;
73module_param(debug, int, 0644);
74
75static int regdebug = 0;
76module_param(regdebug, int, 0644);
77
78static int checkecc = 1;
79module_param(checkecc, int, 0644);
80
81static int slowtiming = 0;
82module_param(slowtiming, int, 0644);
83
84/* Hrm. Why isn't this already conditional on something in the struct device? */
85#define cafe_dev_dbg(dev, args...) do { if (debug) dev_dbg(dev, ##args); } while(0)
86
87/* Make it easier to switch to PIO if we need to */
88#define cafe_readl(cafe, addr) readl((cafe)->mmio + CAFE_##addr)
89#define cafe_writel(cafe, datum, addr) writel(datum, (cafe)->mmio + CAFE_##addr)
90
91static int cafe_device_ready(struct mtd_info *mtd)
92{
93 struct cafe_priv *cafe = mtd->priv;
94 int result = !!(cafe_readl(cafe, NAND_STATUS) | 0x40000000);
95 uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
96
97 cafe_writel(cafe, irqs, NAND_IRQ);
98
99 cafe_dev_dbg(&cafe->pdev->dev, "NAND device is%s ready, IRQ %x (%x) (%x,%x)\n",
100 result?"":" not", irqs, cafe_readl(cafe, NAND_IRQ),
101 cafe_readl(cafe, GLOBAL_IRQ), cafe_readl(cafe, GLOBAL_IRQ_MASK));
102
103 return result;
104}
105
106
107static void cafe_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
108{
109 struct cafe_priv *cafe = mtd->priv;
110
111 if (usedma)
112 memcpy(cafe->dmabuf + cafe->datalen, buf, len);
113 else
114 memcpy_toio(cafe->mmio + CAFE_NAND_WRITE_DATA + cafe->datalen, buf, len);
115
116 cafe->datalen += len;
117
118 cafe_dev_dbg(&cafe->pdev->dev, "Copy 0x%x bytes to write buffer. datalen 0x%x\n",
119 len, cafe->datalen);
120}
121
122static void cafe_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
123{
124 struct cafe_priv *cafe = mtd->priv;
125
126 if (usedma)
127 memcpy(buf, cafe->dmabuf + cafe->datalen, len);
128 else
129 memcpy_fromio(buf, cafe->mmio + CAFE_NAND_READ_DATA + cafe->datalen, len);
130
131 cafe_dev_dbg(&cafe->pdev->dev, "Copy 0x%x bytes from position 0x%x in read buffer.\n",
132 len, cafe->datalen);
133 cafe->datalen += len;
134}
135
136static uint8_t cafe_read_byte(struct mtd_info *mtd)
137{
138 struct cafe_priv *cafe = mtd->priv;
139 uint8_t d;
140
141 cafe_read_buf(mtd, &d, 1);
142 cafe_dev_dbg(&cafe->pdev->dev, "Read %02x\n", d);
143
144 return d;
145}
146
147static void cafe_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
148 int column, int page_addr)
149{
150 struct cafe_priv *cafe = mtd->priv;
151 int adrbytes = 0;
152 uint32_t ctl1;
153 uint32_t doneint = 0x80000000;
154
155 cafe_dev_dbg(&cafe->pdev->dev, "cmdfunc %02x, 0x%x, 0x%x\n",
156 command, column, page_addr);
157
158 if (command == NAND_CMD_ERASE2 || command == NAND_CMD_PAGEPROG) {
159 /* Second half of a command we already calculated */
160 cafe_writel(cafe, cafe->ctl2 | 0x100 | command, NAND_CTRL2);
161 ctl1 = cafe->ctl1;
162 cafe->ctl2 &= ~(1<<30);
163 cafe_dev_dbg(&cafe->pdev->dev, "Continue command, ctl1 %08x, #data %d\n",
164 cafe->ctl1, cafe->nr_data);
165 goto do_command;
166 }
167 /* Reset ECC engine */
168 cafe_writel(cafe, 0, NAND_CTRL2);
169
170 /* Emulate NAND_CMD_READOOB on large-page chips */
171 if (mtd->writesize > 512 &&
172 command == NAND_CMD_READOOB) {
173 column += mtd->writesize;
174 command = NAND_CMD_READ0;
175 }
176
177 /* FIXME: Do we need to send read command before sending data
178 for small-page chips, to position the buffer correctly? */
179
180 if (column != -1) {
181 cafe_writel(cafe, column, NAND_ADDR1);
182 adrbytes = 2;
183 if (page_addr != -1)
184 goto write_adr2;
185 } else if (page_addr != -1) {
186 cafe_writel(cafe, page_addr & 0xffff, NAND_ADDR1);
187 page_addr >>= 16;
188 write_adr2:
189 cafe_writel(cafe, page_addr, NAND_ADDR2);
190 adrbytes += 2;
191 if (mtd->size > mtd->writesize << 16)
192 adrbytes++;
193 }
194
195 cafe->data_pos = cafe->datalen = 0;
196
197 /* Set command valid bit */
198 ctl1 = 0x80000000 | command;
199
200 /* Set RD or WR bits as appropriate */
201 if (command == NAND_CMD_READID || command == NAND_CMD_STATUS) {
202 ctl1 |= (1<<26); /* rd */
203 /* Always 5 bytes, for now */
204 cafe->datalen = 4;
205 /* And one address cycle -- even for STATUS, since the controller doesn't work without */
206 adrbytes = 1;
207 } else if (command == NAND_CMD_READ0 || command == NAND_CMD_READ1 ||
208 command == NAND_CMD_READOOB || command == NAND_CMD_RNDOUT) {
209 ctl1 |= 1<<26; /* rd */
210 /* For now, assume just read to end of page */
211 cafe->datalen = mtd->writesize + mtd->oobsize - column;
212 } else if (command == NAND_CMD_SEQIN)
213 ctl1 |= 1<<25; /* wr */
214
215 /* Set number of address bytes */
216 if (adrbytes)
217 ctl1 |= ((adrbytes-1)|8) << 27;
218
219 if (command == NAND_CMD_SEQIN || command == NAND_CMD_ERASE1) {
220 /* Ignore the first command of a pair; the hardware
221 deals with them both at once, later */
222 cafe->ctl1 = ctl1;
223 cafe_dev_dbg(&cafe->pdev->dev, "Setup for delayed command, ctl1 %08x, dlen %x\n",
224 cafe->ctl1, cafe->datalen);
225 return;
226 }
227 /* RNDOUT and READ0 commands need a following byte */
228 if (command == NAND_CMD_RNDOUT)
229 cafe_writel(cafe, cafe->ctl2 | 0x100 | NAND_CMD_RNDOUTSTART, NAND_CTRL2);
230 else if (command == NAND_CMD_READ0 && mtd->writesize > 512)
231 cafe_writel(cafe, cafe->ctl2 | 0x100 | NAND_CMD_READSTART, NAND_CTRL2);
232
233 do_command:
234 cafe_dev_dbg(&cafe->pdev->dev, "dlen %x, ctl1 %x, ctl2 %x\n",
235 cafe->datalen, ctl1, cafe_readl(cafe, NAND_CTRL2));
236
237 /* NB: The datasheet lies -- we really should be subtracting 1 here */
238 cafe_writel(cafe, cafe->datalen, NAND_DATA_LEN);
239 cafe_writel(cafe, 0x90000000, NAND_IRQ);
240 if (usedma && (ctl1 & (3<<25))) {
241 uint32_t dmactl = 0xc0000000 + cafe->datalen;
242 /* If WR or RD bits set, set up DMA */
243 if (ctl1 & (1<<26)) {
244 /* It's a read */
245 dmactl |= (1<<29);
246 /* ... so it's done when the DMA is done, not just
247 the command. */
248 doneint = 0x10000000;
249 }
250 cafe_writel(cafe, dmactl, NAND_DMA_CTRL);
251 }
252 cafe->datalen = 0;
253
254 if (unlikely(regdebug)) {
255 int i;
256 printk("About to write command %08x to register 0\n", ctl1);
257 for (i=4; i< 0x5c; i+=4)
258 printk("Register %x: %08x\n", i, readl(cafe->mmio + i));
259 }
260
261 cafe_writel(cafe, ctl1, NAND_CTRL1);
262 /* Apply this short delay always to ensure that we do wait tWB in
263 * any case on any machine. */
264 ndelay(100);
265
266 if (1) {
267 int c = 500000;
268 uint32_t irqs;
269
270 while (c--) {
271 irqs = cafe_readl(cafe, NAND_IRQ);
272 if (irqs & doneint)
273 break;
274 udelay(1);
275 if (!(c % 100000))
276 cafe_dev_dbg(&cafe->pdev->dev, "Wait for ready, IRQ %x\n", irqs);
277 cpu_relax();
278 }
279 cafe_writel(cafe, doneint, NAND_IRQ);
280 cafe_dev_dbg(&cafe->pdev->dev, "Command %x completed after %d usec, irqs %x (%x)\n",
281 command, 500000-c, irqs, cafe_readl(cafe, NAND_IRQ));
282 }
283
284 WARN_ON(cafe->ctl2 & (1<<30));
285
286 switch (command) {
287
288 case NAND_CMD_CACHEDPROG:
289 case NAND_CMD_PAGEPROG:
290 case NAND_CMD_ERASE1:
291 case NAND_CMD_ERASE2:
292 case NAND_CMD_SEQIN:
293 case NAND_CMD_RNDIN:
294 case NAND_CMD_STATUS:
295 case NAND_CMD_DEPLETE1:
296 case NAND_CMD_RNDOUT:
297 case NAND_CMD_STATUS_ERROR:
298 case NAND_CMD_STATUS_ERROR0:
299 case NAND_CMD_STATUS_ERROR1:
300 case NAND_CMD_STATUS_ERROR2:
301 case NAND_CMD_STATUS_ERROR3:
302 cafe_writel(cafe, cafe->ctl2, NAND_CTRL2);
303 return;
304 }
305 nand_wait_ready(mtd);
306 cafe_writel(cafe, cafe->ctl2, NAND_CTRL2);
307}
308
309static void cafe_select_chip(struct mtd_info *mtd, int chipnr)
310{
311 //struct cafe_priv *cafe = mtd->priv;
312 // cafe_dev_dbg(&cafe->pdev->dev, "select_chip %d\n", chipnr);
313}
314
315static int cafe_nand_interrupt(int irq, void *id)
316{
317 struct mtd_info *mtd = id;
318 struct cafe_priv *cafe = mtd->priv;
319 uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
320 cafe_writel(cafe, irqs & ~0x90000000, NAND_IRQ);
321 if (!irqs)
322 return IRQ_NONE;
323
324 cafe_dev_dbg(&cafe->pdev->dev, "irq, bits %x (%x)\n", irqs, cafe_readl(cafe, NAND_IRQ));
325 return IRQ_HANDLED;
326}
327
328static void cafe_nand_bug(struct mtd_info *mtd)
329{
330 BUG();
331}
332
333static int cafe_nand_write_oob(struct mtd_info *mtd,
334 struct nand_chip *chip, int page)
335{
336 int status = 0;
337
338 chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, page);
339 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
340 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
341 status = chip->waitfunc(mtd, chip);
342
343 return status & NAND_STATUS_FAIL ? -EIO : 0;
344}
345
346/* Don't use -- use nand_read_oob_std for now */
347static int cafe_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
348 int page, int sndcmd)
349{
350 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
351 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
352 return 1;
353}
354/**
355 * cafe_nand_read_page_syndrome - {REPLACABLE] hardware ecc syndrom based page read
356 * @mtd: mtd info structure
357 * @chip: nand chip info structure
358 * @buf: buffer to store read data
359 *
360 * The hw generator calculates the error syndrome automatically. Therefor
361 * we need a special oob layout and handling.
362 */
363static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
364 uint8_t *buf)
365{
366 struct cafe_priv *cafe = mtd->priv;
367
368 cafe_dev_dbg(&cafe->pdev->dev, "ECC result %08x SYN1,2 %08x\n",
369 cafe_readl(cafe, NAND_ECC_RESULT),
370 cafe_readl(cafe, NAND_ECC_SYN01));
371
372 chip->read_buf(mtd, buf, mtd->writesize);
373 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
374
375 if (checkecc && cafe_readl(cafe, NAND_ECC_RESULT) & (1<<18)) {
376 unsigned short syn[8];
377 int i;
378
379 for (i=0; i<8; i+=2) {
380 uint32_t tmp = cafe_readl(cafe, NAND_ECC_SYN01 + (i*2));
381 syn[i] = tmp & 0xfff;
382 syn[i+1] = (tmp >> 16) & 0xfff;
383 }
384
385 if ((i = cafe_correct_ecc(buf, syn)) < 0) {
386 dev_dbg(&cafe->pdev->dev, "Failed to correct ECC at %08x\n",
387 cafe_readl(cafe, NAND_ADDR2) * 2048);
388 for (i=0; i< 0x5c; i+=4)
389 printk("Register %x: %08x\n", i, readl(cafe->mmio + i));
390 mtd->ecc_stats.failed++;
391 } else {
392 dev_dbg(&cafe->pdev->dev, "Corrected %d symbol errors\n", i);
393 mtd->ecc_stats.corrected += i;
394 }
395 }
396
397
398 return 0;
399}
400
401static struct nand_ecclayout cafe_oobinfo_2048 = {
402 .eccbytes = 14,
403 .eccpos = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
404 .oobfree = {{14, 50}}
405};
406
407/* Ick. The BBT code really ought to be able to work this bit out
408 for itself from the above, at least for the 2KiB case */
409static uint8_t cafe_bbt_pattern_2048[] = { 'B', 'b', 't', '0' };
410static uint8_t cafe_mirror_pattern_2048[] = { '1', 't', 'b', 'B' };
411
412static uint8_t cafe_bbt_pattern_512[] = { 0xBB };
413static uint8_t cafe_mirror_pattern_512[] = { 0xBC };
414
415
416static struct nand_bbt_descr cafe_bbt_main_descr_2048 = {
417 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
418 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
419 .offs = 14,
420 .len = 4,
421 .veroffs = 18,
422 .maxblocks = 4,
423 .pattern = cafe_bbt_pattern_2048
424};
425
426static struct nand_bbt_descr cafe_bbt_mirror_descr_2048 = {
427 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
428 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
429 .offs = 14,
430 .len = 4,
431 .veroffs = 18,
432 .maxblocks = 4,
433 .pattern = cafe_mirror_pattern_2048
434};
435
436static struct nand_ecclayout cafe_oobinfo_512 = {
437 .eccbytes = 14,
438 .eccpos = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
439 .oobfree = {{14, 2}}
440};
441
442static struct nand_bbt_descr cafe_bbt_main_descr_512 = {
443 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
444 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
445 .offs = 14,
446 .len = 1,
447 .veroffs = 15,
448 .maxblocks = 4,
449 .pattern = cafe_bbt_pattern_512
450};
451
452static struct nand_bbt_descr cafe_bbt_mirror_descr_512 = {
453 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
454 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
455 .offs = 14,
456 .len = 1,
457 .veroffs = 15,
458 .maxblocks = 4,
459 .pattern = cafe_mirror_pattern_512
460};
461
462
463static void cafe_nand_write_page_lowlevel(struct mtd_info *mtd,
464 struct nand_chip *chip, const uint8_t *buf)
465{
466 struct cafe_priv *cafe = mtd->priv;
467
468 chip->write_buf(mtd, buf, mtd->writesize);
469 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
470
471 /* Set up ECC autogeneration */
472 cafe->ctl2 |= (1<<30);
473}
474
475static int cafe_nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
476 const uint8_t *buf, int page, int cached, int raw)
477{
478 int status;
479
480 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
481
482 if (unlikely(raw))
483 chip->ecc.write_page_raw(mtd, chip, buf);
484 else
485 chip->ecc.write_page(mtd, chip, buf);
486
487 /*
488 * Cached progamming disabled for now, Not sure if its worth the
489 * trouble. The speed gain is not very impressive. (2.3->2.6Mib/s)
490 */
491 cached = 0;
492
493 if (!cached || !(chip->options & NAND_CACHEPRG)) {
494
495 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
496 status = chip->waitfunc(mtd, chip);
497 /*
498 * See if operation failed and additional status checks are
499 * available
500 */
501 if ((status & NAND_STATUS_FAIL) && (chip->errstat))
502 status = chip->errstat(mtd, chip, FL_WRITING, status,
503 page);
504
505 if (status & NAND_STATUS_FAIL)
506 return -EIO;
507 } else {
508 chip->cmdfunc(mtd, NAND_CMD_CACHEDPROG, -1, -1);
509 status = chip->waitfunc(mtd, chip);
510 }
511
512#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
513 /* Send command to read back the data */
514 chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
515
516 if (chip->verify_buf(mtd, buf, mtd->writesize))
517 return -EIO;
518#endif
519 return 0;
520}
521
522static int cafe_nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
523{
524 return 0;
525}
526
527static int __devinit cafe_nand_probe(struct pci_dev *pdev,
528 const struct pci_device_id *ent)
529{
530 struct mtd_info *mtd;
531 struct cafe_priv *cafe;
532 uint32_t ctrl;
533 int err = 0;
534
535 err = pci_enable_device(pdev);
536 if (err)
537 return err;
538
539 pci_set_master(pdev);
540
541 mtd = kzalloc(sizeof(*mtd) + sizeof(struct cafe_priv), GFP_KERNEL);
542 if (!mtd) {
543 dev_warn(&pdev->dev, "failed to alloc mtd_info\n");
544 return -ENOMEM;
545 }
546 cafe = (void *)(&mtd[1]);
547
548 mtd->priv = cafe;
549 mtd->owner = THIS_MODULE;
550
551 cafe->pdev = pdev;
552 cafe->mmio = pci_iomap(pdev, 0, 0);
553 if (!cafe->mmio) {
554 dev_warn(&pdev->dev, "failed to iomap\n");
555 err = -ENOMEM;
556 goto out_free_mtd;
557 }
558 cafe->dmabuf = dma_alloc_coherent(&cafe->pdev->dev, 2112 + sizeof(struct nand_buffers),
559 &cafe->dmaaddr, GFP_KERNEL);
560 if (!cafe->dmabuf) {
561 err = -ENOMEM;
562 goto out_ior;
563 }
564 cafe->nand.buffers = (void *)cafe->dmabuf + 2112;
565
566 cafe->nand.cmdfunc = cafe_nand_cmdfunc;
567 cafe->nand.dev_ready = cafe_device_ready;
568 cafe->nand.read_byte = cafe_read_byte;
569 cafe->nand.read_buf = cafe_read_buf;
570 cafe->nand.write_buf = cafe_write_buf;
571 cafe->nand.select_chip = cafe_select_chip;
572
573 cafe->nand.chip_delay = 0;
574
575 /* Enable the following for a flash based bad block table */
576 cafe->nand.options = NAND_USE_FLASH_BBT | NAND_NO_AUTOINCR | NAND_OWN_BUFFERS;
577
578 if (skipbbt) {
579 cafe->nand.options |= NAND_SKIP_BBTSCAN;
580 cafe->nand.block_bad = cafe_nand_block_bad;
581 }
582
583 /* Start off by resetting the NAND controller completely */
584 cafe_writel(cafe, 1, NAND_RESET);
585 cafe_writel(cafe, 0, NAND_RESET);
586
587 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK);
588
589 /* Timings from Marvell's test code (not verified or calculated by us) */
590 if (!slowtiming) {
591 cafe_writel(cafe, 0x01010a0a, NAND_TIMING1);
592 cafe_writel(cafe, 0x24121212, NAND_TIMING2);
593 cafe_writel(cafe, 0x11000000, NAND_TIMING3);
594 } else {
595 cafe_writel(cafe, 0xffffffff, NAND_TIMING1);
596 cafe_writel(cafe, 0xffffffff, NAND_TIMING2);
597 cafe_writel(cafe, 0xffffffff, NAND_TIMING3);
598 }
599 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK);
600 err = request_irq(pdev->irq, &cafe_nand_interrupt, SA_SHIRQ, "CAFE NAND", mtd);
601 if (err) {
602 dev_warn(&pdev->dev, "Could not register IRQ %d\n", pdev->irq);
603
604 goto out_free_dma;
605 }
606#if 1
607 /* Disable master reset, enable NAND clock */
608 ctrl = cafe_readl(cafe, GLOBAL_CTRL);
609 ctrl &= 0xffffeff0;
610 ctrl |= 0x00007000;
611 cafe_writel(cafe, ctrl | 0x05, GLOBAL_CTRL);
612 cafe_writel(cafe, ctrl | 0x0a, GLOBAL_CTRL);
613 cafe_writel(cafe, 0, NAND_DMA_CTRL);
614
615 cafe_writel(cafe, 0x7006, GLOBAL_CTRL);
616 cafe_writel(cafe, 0x700a, GLOBAL_CTRL);
617
618 /* Set up DMA address */
619 cafe_writel(cafe, cafe->dmaaddr & 0xffffffff, NAND_DMA_ADDR0);
620 if (sizeof(cafe->dmaaddr) > 4)
621 /* Shift in two parts to shut the compiler up */
622 cafe_writel(cafe, (cafe->dmaaddr >> 16) >> 16, NAND_DMA_ADDR1);
623 else
624 cafe_writel(cafe, 0, NAND_DMA_ADDR1);
625
626 cafe_dev_dbg(&cafe->pdev->dev, "Set DMA address to %x (virt %p)\n",
627 cafe_readl(cafe, NAND_DMA_ADDR0), cafe->dmabuf);
628
629 /* Enable NAND IRQ in global IRQ mask register */
630 cafe_writel(cafe, 0x80000007, GLOBAL_IRQ_MASK);
631 cafe_dev_dbg(&cafe->pdev->dev, "Control %x, IRQ mask %x\n",
632 cafe_readl(cafe, GLOBAL_CTRL), cafe_readl(cafe, GLOBAL_IRQ_MASK));
633#endif
634#if 1
635 mtd->writesize=2048;
636 mtd->oobsize = 0x40;
637 memset(cafe->dmabuf, 0x5a, 2112);
638 cafe->nand.cmdfunc(mtd, NAND_CMD_READID, 0, -1);
639 cafe->nand.read_byte(mtd);
640 cafe->nand.read_byte(mtd);
641 cafe->nand.read_byte(mtd);
642 cafe->nand.read_byte(mtd);
643 cafe->nand.read_byte(mtd);
644#endif
645#if 0
646 cafe->nand.cmdfunc(mtd, NAND_CMD_READ0, 0, 0);
647 // nand_wait_ready(mtd);
648 cafe->nand.read_byte(mtd);
649 cafe->nand.read_byte(mtd);
650 cafe->nand.read_byte(mtd);
651 cafe->nand.read_byte(mtd);
652#endif
653#if 0
654 writel(0x84600070, cafe->mmio);
655 udelay(10);
656 cafe_dev_dbg(&cafe->pdev->dev, "Status %x\n", cafe_readl(cafe, NAND_NONMEM));
657#endif
658 /* Scan to find existance of the device */
659 if (nand_scan_ident(mtd, 1)) {
660 err = -ENXIO;
661 goto out_irq;
662 }
663
664 cafe->ctl2 = 1<<27; /* Reed-Solomon ECC */
665 if (mtd->writesize == 2048)
666 cafe->ctl2 |= 1<<29; /* 2KiB page size */
667
668 /* Set up ECC according to the type of chip we found */
669 if (mtd->writesize == 2048) {
670 cafe->nand.ecc.layout = &cafe_oobinfo_2048;
671 cafe->nand.bbt_td = &cafe_bbt_main_descr_2048;
672 cafe->nand.bbt_md = &cafe_bbt_mirror_descr_2048;
673 } else if (mtd->writesize == 512) {
674 cafe->nand.ecc.layout = &cafe_oobinfo_512;
675 cafe->nand.bbt_td = &cafe_bbt_main_descr_512;
676 cafe->nand.bbt_md = &cafe_bbt_mirror_descr_512;
677 } else {
678 printk(KERN_WARNING "Unexpected NAND flash writesize %d. Aborting\n",
679 mtd->writesize);
680 goto out_irq;
681 }
682 cafe->nand.ecc.mode = NAND_ECC_HW_SYNDROME;
683 cafe->nand.ecc.size = mtd->writesize;
684 cafe->nand.ecc.bytes = 14;
685 cafe->nand.ecc.hwctl = (void *)cafe_nand_bug;
686 cafe->nand.ecc.calculate = (void *)cafe_nand_bug;
687 cafe->nand.ecc.correct = (void *)cafe_nand_bug;
688 cafe->nand.write_page = cafe_nand_write_page;
689 cafe->nand.ecc.write_page = cafe_nand_write_page_lowlevel;
690 cafe->nand.ecc.write_oob = cafe_nand_write_oob;
691 cafe->nand.ecc.read_page = cafe_nand_read_page;
692 cafe->nand.ecc.read_oob = cafe_nand_read_oob;
693
694 err = nand_scan_tail(mtd);
695 if (err)
696 goto out_irq;
697
698 pci_set_drvdata(pdev, mtd);
699 add_mtd_device(mtd);
700 goto out;
701
702 out_irq:
703 /* Disable NAND IRQ in global IRQ mask register */
704 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK);
705 free_irq(pdev->irq, mtd);
706 out_free_dma:
707 dma_free_coherent(&cafe->pdev->dev, 2112, cafe->dmabuf, cafe->dmaaddr);
708 out_ior:
709 pci_iounmap(pdev, cafe->mmio);
710 out_free_mtd:
711 kfree(mtd);
712 out:
713 return err;
714}
715
716static void __devexit cafe_nand_remove(struct pci_dev *pdev)
717{
718 struct mtd_info *mtd = pci_get_drvdata(pdev);
719 struct cafe_priv *cafe = mtd->priv;
720
721 del_mtd_device(mtd);
722 /* Disable NAND IRQ in global IRQ mask register */
723 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK);
724 free_irq(pdev->irq, mtd);
725 nand_release(mtd);
726 pci_iounmap(pdev, cafe->mmio);
727 dma_free_coherent(&cafe->pdev->dev, 2112, cafe->dmabuf, cafe->dmaaddr);
728 kfree(mtd);
729}
730
731static struct pci_device_id cafe_nand_tbl[] = {
732 { 0x11ab, 0x4100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MEMORY_FLASH << 8, 0xFFFF0 }
733};
734
735MODULE_DEVICE_TABLE(pci, cafe_nand_tbl);
736
737static struct pci_driver cafe_nand_pci_driver = {
738 .name = "CAFÉ NAND",
739 .id_table = cafe_nand_tbl,
740 .probe = cafe_nand_probe,
741 .remove = __devexit_p(cafe_nand_remove),
742#ifdef CONFIG_PMx
743 .suspend = cafe_nand_suspend,
744 .resume = cafe_nand_resume,
745#endif
746};
747
748static int cafe_nand_init(void)
749{
750 return pci_register_driver(&cafe_nand_pci_driver);
751}
752
753static void cafe_nand_exit(void)
754{
755 pci_unregister_driver(&cafe_nand_pci_driver);
756}
757module_init(cafe_nand_init);
758module_exit(cafe_nand_exit);
759
760MODULE_LICENSE("GPL");
761MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
762MODULE_DESCRIPTION("NAND flash driver for OLPC CAFE chip");
763
764/* Correct ECC for 2048 bytes of 0xff:
765 41 a0 71 65 54 27 f3 93 ec a9 be ed 0b a1 */
766
767/* dwmw2's B-test board, in case of completely screwing it:
768Bad eraseblock 2394 at 0x12b40000
769Bad eraseblock 2627 at 0x14860000
770Bad eraseblock 3349 at 0x1a2a0000
771*/
diff --git a/drivers/mtd/nand/cafe_ecc.c b/drivers/mtd/nand/cafe_ecc.c
new file mode 100644
index 0000000000..1b9fa05a44
--- /dev/null
+++ b/drivers/mtd/nand/cafe_ecc.c
@@ -0,0 +1,1381 @@
1/* Error correction for CAFÉ NAND controller
2 *
3 * © 2006 Marvell, Inc.
4 * Author: Tom Chiou
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 Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/errno.h>
24
25static unsigned short gf4096_mul(unsigned short, unsigned short);
26static unsigned short gf64_mul(unsigned short, unsigned short);
27static unsigned short gf4096_inv(unsigned short);
28static unsigned short err_pos(unsigned short);
29static void find_4bit_err_coefs(unsigned short, unsigned short, unsigned short,
30 unsigned short, unsigned short, unsigned short,
31 unsigned short, unsigned short, unsigned short *);
32static void zero_4x5_col3(unsigned short[4][5]);
33static void zero_4x5_col2(unsigned short[4][5]);
34static void zero_4x5_col1(unsigned short[4][5]);
35static void swap_4x5_rows(unsigned short[4][5], int, int, int);
36static void swap_2x3_rows(unsigned short m[2][3]);
37static void solve_4x5(unsigned short m[4][5], unsigned short *, int *);
38static void sort_coefs(int *, unsigned short *, int);
39static void find_4bit_err_pats(unsigned short, unsigned short, unsigned short,
40 unsigned short, unsigned short, unsigned short,
41 unsigned short, unsigned short, unsigned short *);
42static void find_3bit_err_coefs(unsigned short, unsigned short, unsigned short,
43 unsigned short, unsigned short, unsigned short,
44 unsigned short *);
45static void zero_3x4_col2(unsigned short[3][4]);
46static void zero_3x4_col1(unsigned short[3][4]);
47static void swap_3x4_rows(unsigned short[3][4], int, int, int);
48static void solve_3x4(unsigned short[3][4], unsigned short *, int *);
49static void find_3bit_err_pats(unsigned short, unsigned short, unsigned short,
50 unsigned short, unsigned short, unsigned short,
51 unsigned short *);
52
53static void find_2bit_err_pats(unsigned short, unsigned short, unsigned short,
54 unsigned short, unsigned short *);
55static void find_2x2_soln(unsigned short, unsigned short, unsigned short,
56 unsigned short, unsigned short, unsigned short,
57 unsigned short *);
58static void solve_2x3(unsigned short[2][3], unsigned short *);
59static int chk_no_err_only(unsigned short *, unsigned short *);
60static int chk_1_err_only(unsigned short *, unsigned short *);
61static int chk_2_err_only(unsigned short *, unsigned short *);
62static int chk_3_err_only(unsigned short *, unsigned short *);
63static int chk_4_err_only(unsigned short *, unsigned short *);
64
65static unsigned short gf64_mul(unsigned short a, unsigned short b)
66{
67 unsigned short tmp1, tmp2, tmp3, tmp4, tmp5;
68 unsigned short c_bit0, c_bit1, c_bit2, c_bit3, c_bit4, c_bit5, c;
69
70 tmp1 = ((a) ^ (a >> 5));
71 tmp2 = ((a >> 4) ^ (a >> 5));
72 tmp3 = ((a >> 3) ^ (a >> 4));
73 tmp4 = ((a >> 2) ^ (a >> 3));
74 tmp5 = ((a >> 1) ^ (a >> 2));
75
76 c_bit0 = ((a & b) ^ ((a >> 5) & (b >> 1)) ^ ((a >> 4) & (b >> 2)) ^
77 ((a >> 3) & (b >> 3)) ^ ((a >> 2) & (b >> 4)) ^ ((a >> 1) & (b >> 5))) & 0x1;
78
79 c_bit1 = (((a >> 1) & b) ^ (tmp1 & (b >> 1)) ^ (tmp2 & (b >> 2)) ^
80 (tmp3 & (b >> 3)) ^ (tmp4 & (b >> 4)) ^ (tmp5 & (b >> 5))) & 0x1;
81
82 c_bit2 = (((a >> 2) & b) ^ ((a >> 1) & (b >> 1)) ^ (tmp1 & (b >> 2)) ^
83 (tmp2 & (b >> 3)) ^ (tmp3 & (b >> 4)) ^ (tmp4 & (b >> 5))) & 0x1;
84
85 c_bit3 = (((a >> 3) & b) ^ ((a >> 2) & (b >> 1)) ^ ((a >> 1) & (b >> 2)) ^
86 (tmp1 & (b >> 3)) ^ (tmp2 & (b >> 4)) ^ (tmp3 & (b >> 5))) & 0x1;
87
88 c_bit4 = (((a >> 4) & b) ^ ((a >> 3) & (b >> 1)) ^ ((a >> 2) & (b >> 2)) ^
89 ((a >> 1) & (b >> 3)) ^ (tmp1 & (b >> 4)) ^ (tmp2 & (b >> 5))) & 0x1;
90
91 c_bit5 = (((a >> 5) & b) ^ ((a >> 4) & (b >> 1)) ^ ((a >> 3) & (b >> 2)) ^
92 ((a >> 2) & (b >> 3)) ^ ((a >> 1) & (b >> 4)) ^ (tmp1 & (b >> 5))) & 0x1;
93
94 c = c_bit0 | (c_bit1 << 1) | (c_bit2 << 2) | (c_bit3 << 3) | (c_bit4 << 4) | (c_bit5 << 5);
95
96 return c;
97}
98
99static unsigned short gf4096_mul(unsigned short a, unsigned short b)
100{
101 unsigned short ah, al, bh, bl, alxah, blxbh, ablh, albl, ahbh, ahbhB, c;
102
103 ah = (a >> 6) & 0x3f;
104 al = a & 0x3f;
105 bh = (b >> 6) & 0x3f;
106 bl = b & 0x3f;
107 alxah = al ^ ah;
108 blxbh = bl ^ bh;
109
110 ablh = gf64_mul(alxah, blxbh);
111 albl = gf64_mul(al, bl);
112 ahbh = gf64_mul(ah, bh);
113
114 ahbhB = ((ahbh & 0x1) << 5) |
115 ((ahbh & 0x20) >> 1) |
116 ((ahbh & 0x10) >> 1) | ((ahbh & 0x8) >> 1) | ((ahbh & 0x4) >> 1) | (((ahbh >> 1) ^ ahbh) & 0x1);
117
118 c = ((ablh ^ albl) << 6) | (ahbhB ^ albl);
119 return c;
120}
121
122static void find_2bit_err_pats(unsigned short s0, unsigned short s1, unsigned short r0, unsigned short r1, unsigned short *pats)
123{
124 find_2x2_soln(0x1, 0x1, r0, r1, s0, s1, pats);
125}
126
127static void find_3bit_err_coefs(unsigned short s0, unsigned short s1,
128 unsigned short s2, unsigned short s3, unsigned short s4, unsigned short s5, unsigned short *coefs)
129{
130 unsigned short m[3][4];
131 int row_order[3];
132
133 row_order[0] = 0;
134 row_order[1] = 1;
135 row_order[2] = 2;
136 m[0][0] = s2;
137 m[0][1] = s1;
138 m[0][2] = s0;
139 m[0][3] = s3;
140 m[1][0] = s3;
141 m[1][1] = s2;
142 m[1][2] = s1;
143 m[1][3] = s4;
144 m[2][0] = s4;
145 m[2][1] = s3;
146 m[2][2] = s2;
147 m[2][3] = s5;
148
149 if (m[0][2] != 0x0) {
150 zero_3x4_col2(m);
151 } else if (m[1][2] != 0x0) {
152 swap_3x4_rows(m, 0, 1, 4);
153 zero_3x4_col2(m);
154 } else if (m[2][2] != 0x0) {
155 swap_3x4_rows(m, 0, 2, 4);
156 zero_3x4_col2(m);
157 } else {
158 printk(KERN_ERR "Error: find_3bit_err_coefs, s0,s1,s2 all zeros!\n");
159 }
160
161 if (m[1][1] != 0x0) {
162 zero_3x4_col1(m);
163 } else if (m[2][1] != 0x0) {
164 swap_3x4_rows(m, 1, 2, 4);
165 zero_3x4_col1(m);
166 } else {
167 printk(KERN_ERR "Error: find_3bit_err_coefs, cannot resolve col 1!\n");
168 }
169
170 /* solve coefs */
171 solve_3x4(m, coefs, row_order);
172}
173
174static void zero_3x4_col2(unsigned short m[3][4])
175{
176 unsigned short minv1, minv2;
177
178 minv1 = gf4096_mul(m[1][2], gf4096_inv(m[0][2]));
179 minv2 = gf4096_mul(m[2][2], gf4096_inv(m[0][2]));
180 m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv1);
181 m[1][1] = m[1][1] ^ gf4096_mul(m[0][1], minv1);
182 m[1][3] = m[1][3] ^ gf4096_mul(m[0][3], minv1);
183 m[2][0] = m[2][0] ^ gf4096_mul(m[0][0], minv2);
184 m[2][1] = m[2][1] ^ gf4096_mul(m[0][1], minv2);
185 m[2][3] = m[2][3] ^ gf4096_mul(m[0][3], minv2);
186}
187
188static void zero_3x4_col1(unsigned short m[3][4])
189{
190 unsigned short minv;
191 minv = gf4096_mul(m[2][1], gf4096_inv(m[1][1]));
192 m[2][0] = m[2][0] ^ gf4096_mul(m[1][0], minv);
193 m[2][3] = m[2][3] ^ gf4096_mul(m[1][3], minv);
194}
195
196static void swap_3x4_rows(unsigned short m[3][4], int i, int j, int col_width)
197{
198 unsigned short tmp0;
199 int cnt;
200 for (cnt = 0; cnt < col_width; cnt++) {
201 tmp0 = m[i][cnt];
202 m[i][cnt] = m[j][cnt];
203 m[j][cnt] = tmp0;
204 }
205}
206
207static void solve_3x4(unsigned short m[3][4], unsigned short *coefs, int *row_order)
208{
209 unsigned short tmp[3];
210 tmp[0] = gf4096_mul(m[2][3], gf4096_inv(m[2][0]));
211 tmp[1] = gf4096_mul((gf4096_mul(tmp[0], m[1][0]) ^ m[1][3]), gf4096_inv(m[1][1]));
212 tmp[2] = gf4096_mul((gf4096_mul(tmp[0], m[0][0]) ^ gf4096_mul(tmp[1], m[0][1]) ^ m[0][3]), gf4096_inv(m[0][2]));
213 sort_coefs(row_order, tmp, 3);
214 coefs[0] = tmp[0];
215 coefs[1] = tmp[1];
216 coefs[2] = tmp[2];
217}
218
219static void find_3bit_err_pats(unsigned short s0, unsigned short s1,
220 unsigned short s2, unsigned short r0,
221 unsigned short r1, unsigned short r2,
222 unsigned short *pats)
223{
224 find_2x2_soln(r0 ^ r2, r1 ^ r2,
225 gf4096_mul(r0, r0 ^ r2), gf4096_mul(r1, r1 ^ r2),
226 gf4096_mul(s0, r2) ^ s1, gf4096_mul(s1, r2) ^ s2, pats);
227 pats[2] = s0 ^ pats[0] ^ pats[1];
228}
229
230static void find_4bit_err_coefs(unsigned short s0, unsigned short s1,
231 unsigned short s2, unsigned short s3,
232 unsigned short s4, unsigned short s5,
233 unsigned short s6, unsigned short s7,
234 unsigned short *coefs)
235{
236 unsigned short m[4][5];
237 int row_order[4];
238
239 row_order[0] = 0;
240 row_order[1] = 1;
241 row_order[2] = 2;
242 row_order[3] = 3;
243
244 m[0][0] = s3;
245 m[0][1] = s2;
246 m[0][2] = s1;
247 m[0][3] = s0;
248 m[0][4] = s4;
249 m[1][0] = s4;
250 m[1][1] = s3;
251 m[1][2] = s2;
252 m[1][3] = s1;
253 m[1][4] = s5;
254 m[2][0] = s5;
255 m[2][1] = s4;
256 m[2][2] = s3;
257 m[2][3] = s2;
258 m[2][4] = s6;
259 m[3][0] = s6;
260 m[3][1] = s5;
261 m[3][2] = s4;
262 m[3][3] = s3;
263 m[3][4] = s7;
264
265 if (m[0][3] != 0x0) {
266 zero_4x5_col3(m);
267 } else if (m[1][3] != 0x0) {
268 swap_4x5_rows(m, 0, 1, 5);
269 zero_4x5_col3(m);
270 } else if (m[2][3] != 0x0) {
271 swap_4x5_rows(m, 0, 2, 5);
272 zero_4x5_col3(m);
273 } else if (m[3][3] != 0x0) {
274 swap_4x5_rows(m, 0, 3, 5);
275 zero_4x5_col3(m);
276 } else {
277 printk(KERN_ERR "Error: find_4bit_err_coefs, s0,s1,s2,s3 all zeros!\n");
278 }
279
280 if (m[1][2] != 0x0) {
281 zero_4x5_col2(m);
282 } else if (m[2][2] != 0x0) {
283 swap_4x5_rows(m, 1, 2, 5);
284 zero_4x5_col2(m);
285 } else if (m[3][2] != 0x0) {
286 swap_4x5_rows(m, 1, 3, 5);
287 zero_4x5_col2(m);
288 } else {
289 printk(KERN_ERR "Error: find_4bit_err_coefs, cannot resolve col 2!\n");
290 }
291
292 if (m[2][1] != 0x0) {
293 zero_4x5_col1(m);
294 } else if (m[3][1] != 0x0) {
295 swap_4x5_rows(m, 2, 3, 5);
296 zero_4x5_col1(m);
297 } else {
298 printk(KERN_ERR "Error: find_4bit_err_coefs, cannot resolve col 1!\n");
299 }
300
301 solve_4x5(m, coefs, row_order);
302}
303
304static void zero_4x5_col3(unsigned short m[4][5])
305{
306 unsigned short minv1, minv2, minv3;
307
308 minv1 = gf4096_mul(m[1][3], gf4096_inv(m[0][3]));
309 minv2 = gf4096_mul(m[2][3], gf4096_inv(m[0][3]));
310 minv3 = gf4096_mul(m[3][3], gf4096_inv(m[0][3]));
311
312 m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv1);
313 m[1][1] = m[1][1] ^ gf4096_mul(m[0][1], minv1);
314 m[1][2] = m[1][2] ^ gf4096_mul(m[0][2], minv1);
315 m[1][4] = m[1][4] ^ gf4096_mul(m[0][4], minv1);
316 m[2][0] = m[2][0] ^ gf4096_mul(m[0][0], minv2);
317 m[2][1] = m[2][1] ^ gf4096_mul(m[0][1], minv2);
318 m[2][2] = m[2][2] ^ gf4096_mul(m[0][2], minv2);
319 m[2][4] = m[2][4] ^ gf4096_mul(m[0][4], minv2);
320 m[3][0] = m[3][0] ^ gf4096_mul(m[0][0], minv3);
321 m[3][1] = m[3][1] ^ gf4096_mul(m[0][1], minv3);
322 m[3][2] = m[3][2] ^ gf4096_mul(m[0][2], minv3);
323 m[3][4] = m[3][4] ^ gf4096_mul(m[0][4], minv3);
324}
325
326static void zero_4x5_col2(unsigned short m[4][5])
327{
328 unsigned short minv2, minv3;
329
330 minv2 = gf4096_mul(m[2][2], gf4096_inv(m[1][2]));
331 minv3 = gf4096_mul(m[3][2], gf4096_inv(m[1][2]));
332
333 m[2][0] = m[2][0] ^ gf4096_mul(m[1][0], minv2);
334 m[2][1] = m[2][1] ^ gf4096_mul(m[1][1], minv2);
335 m[2][4] = m[2][4] ^ gf4096_mul(m[1][4], minv2);
336 m[3][0] = m[3][0] ^ gf4096_mul(m[1][0], minv3);
337 m[3][1] = m[3][1] ^ gf4096_mul(m[1][1], minv3);
338 m[3][4] = m[3][4] ^ gf4096_mul(m[1][4], minv3);
339}
340
341static void zero_4x5_col1(unsigned short m[4][5])
342{
343 unsigned short minv;
344
345 minv = gf4096_mul(m[3][1], gf4096_inv(m[2][1]));
346
347 m[3][0] = m[3][0] ^ gf4096_mul(m[2][0], minv);
348 m[3][4] = m[3][4] ^ gf4096_mul(m[2][4], minv);
349}
350
351static void swap_4x5_rows(unsigned short m[4][5], int i, int j, int col_width)
352{
353 unsigned short tmp0;
354 int cnt;
355
356 for (cnt = 0; cnt < col_width; cnt++) {
357 tmp0 = m[i][cnt];
358 m[i][cnt] = m[j][cnt];
359 m[j][cnt] = tmp0;
360 }
361}
362
363static void solve_4x5(unsigned short m[4][5], unsigned short *coefs, int *row_order)
364{
365 unsigned short tmp[4];
366
367 tmp[0] = gf4096_mul(m[3][4], gf4096_inv(m[3][0]));
368 tmp[1] = gf4096_mul((gf4096_mul(tmp[0], m[2][0]) ^ m[2][4]), gf4096_inv(m[2][1]));
369 tmp[2] = gf4096_mul((gf4096_mul(tmp[0], m[1][0]) ^ gf4096_mul(tmp[1], m[1][1]) ^ m[1][4]), gf4096_inv(m[1][2]));
370 tmp[3] = gf4096_mul((gf4096_mul(tmp[0], m[0][0]) ^
371 gf4096_mul(tmp[1], m[0][1]) ^ gf4096_mul(tmp[2], m[0][2]) ^ m[0][4]), gf4096_inv(m[0][3]));
372 sort_coefs(row_order, tmp, 4);
373 coefs[0] = tmp[0];
374 coefs[1] = tmp[1];
375 coefs[2] = tmp[2];
376 coefs[3] = tmp[3];
377}
378
379static void sort_coefs(int *order, unsigned short *soln, int len)
380{
381 int cnt, start_cnt, least_ord, least_cnt;
382 unsigned short tmp0;
383 for (start_cnt = 0; start_cnt < len; start_cnt++) {
384 for (cnt = start_cnt; cnt < len; cnt++) {
385 if (cnt == start_cnt) {
386 least_ord = order[cnt];
387 least_cnt = start_cnt;
388 } else {
389 if (least_ord > order[cnt]) {
390 least_ord = order[cnt];
391 least_cnt = cnt;
392 }
393 }
394 }
395 if (least_cnt != start_cnt) {
396 tmp0 = order[least_cnt];
397 order[least_cnt] = order[start_cnt];
398 order[start_cnt] = tmp0;
399 tmp0 = soln[least_cnt];
400 soln[least_cnt] = soln[start_cnt];
401 soln[start_cnt] = tmp0;
402 }
403 }
404}
405
406static void find_4bit_err_pats(unsigned short s0, unsigned short s1,
407 unsigned short s2, unsigned short s3,
408 unsigned short z1, unsigned short z2,
409 unsigned short z3, unsigned short z4,
410 unsigned short *pats)
411{
412 unsigned short z4_z1, z3z4_z3z3, z4_z2, s0z4_s1, z1z4_z1z1,
413 z4_z3, z2z4_z2z2, s1z4_s2, z3z3z4_z3z3z3, z1z1z4_z1z1z1, z2z2z4_z2z2z2, s2z4_s3;
414 unsigned short tmp0, tmp1, tmp2, tmp3;
415
416 z4_z1 = z4 ^ z1;
417 z3z4_z3z3 = gf4096_mul(z3, z4) ^ gf4096_mul(z3, z3);
418 z4_z2 = z4 ^ z2;
419 s0z4_s1 = gf4096_mul(s0, z4) ^ s1;
420 z1z4_z1z1 = gf4096_mul(z1, z4) ^ gf4096_mul(z1, z1);
421 z4_z3 = z4 ^ z3;
422 z2z4_z2z2 = gf4096_mul(z2, z4) ^ gf4096_mul(z2, z2);
423 s1z4_s2 = gf4096_mul(s1, z4) ^ s2;
424 z3z3z4_z3z3z3 = gf4096_mul(gf4096_mul(z3, z3), z4) ^ gf4096_mul(gf4096_mul(z3, z3), z3);
425 z1z1z4_z1z1z1 = gf4096_mul(gf4096_mul(z1, z1), z4) ^ gf4096_mul(gf4096_mul(z1, z1), z1);
426 z2z2z4_z2z2z2 = gf4096_mul(gf4096_mul(z2, z2), z4) ^ gf4096_mul(gf4096_mul(z2, z2), z2);
427 s2z4_s3 = gf4096_mul(s2, z4) ^ s3;
428
429 //find err pat 0,1
430 find_2x2_soln(gf4096_mul(z4_z1, z3z4_z3z3) ^
431 gf4096_mul(z1z4_z1z1, z4_z3), gf4096_mul(z4_z2,
432 z3z4_z3z3) ^
433 gf4096_mul(z2z4_z2z2, z4_z3), gf4096_mul(z1z4_z1z1,
434 z3z3z4_z3z3z3) ^
435 gf4096_mul(z1z1z4_z1z1z1, z3z4_z3z3),
436 gf4096_mul(z2z4_z2z2,
437 z3z3z4_z3z3z3) ^ gf4096_mul(z2z2z4_z2z2z2,
438 z3z4_z3z3),
439 gf4096_mul(s0z4_s1, z3z4_z3z3) ^ gf4096_mul(s1z4_s2,
440 z4_z3),
441 gf4096_mul(s1z4_s2, z3z3z4_z3z3z3) ^ gf4096_mul(s2z4_s3, z3z4_z3z3), pats);
442 tmp0 = pats[0];
443 tmp1 = pats[1];
444 tmp2 = pats[0] ^ pats[1] ^ s0;
445 tmp3 = gf4096_mul(pats[0], z1) ^ gf4096_mul(pats[1], z2) ^ s1;
446
447 //find err pat 2,3
448 find_2x2_soln(0x1, 0x1, z3, z4, tmp2, tmp3, pats);
449 pats[2] = pats[0];
450 pats[3] = pats[1];
451 pats[0] = tmp0;
452 pats[1] = tmp1;
453}
454
455static void find_2x2_soln(unsigned short c00, unsigned short c01,
456 unsigned short c10, unsigned short c11,
457 unsigned short lval0, unsigned short lval1,
458 unsigned short *soln)
459{
460 unsigned short m[2][3];
461 m[0][0] = c00;
462 m[0][1] = c01;
463 m[0][2] = lval0;
464 m[1][0] = c10;
465 m[1][1] = c11;
466 m[1][2] = lval1;
467
468 if (m[0][1] != 0x0) {
469 /* */
470 } else if (m[1][1] != 0x0) {
471 swap_2x3_rows(m);
472 } else {
473 printk(KERN_ERR "Warning: find_2bit_err_coefs, s0,s1 all zeros!\n");
474 }
475
476 solve_2x3(m, soln);
477}
478
479static void swap_2x3_rows(unsigned short m[2][3])
480{
481 unsigned short tmp0;
482 int cnt;
483
484 for (cnt = 0; cnt < 3; cnt++) {
485 tmp0 = m[0][cnt];
486 m[0][cnt] = m[1][cnt];
487 m[1][cnt] = tmp0;
488 }
489}
490
491static void solve_2x3(unsigned short m[2][3], unsigned short *coefs)
492{
493 unsigned short minv;
494
495 minv = gf4096_mul(m[1][1], gf4096_inv(m[0][1]));
496 m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv);
497 m[1][2] = m[1][2] ^ gf4096_mul(m[0][2], minv);
498 coefs[0] = gf4096_mul(m[1][2], gf4096_inv(m[1][0]));
499 coefs[1] = gf4096_mul((gf4096_mul(coefs[0], m[0][0]) ^ m[0][2]), gf4096_inv(m[0][1]));
500}
501
502static unsigned char gf64_inv[64] = {
503 0, 1, 33, 62, 49, 43, 31, 44, 57, 37, 52, 28, 46, 40, 22, 25,
504 61, 54, 51, 39, 26, 35, 14, 24, 23, 15, 20, 34, 11, 53, 45, 6,
505 63, 2, 27, 21, 56, 9, 50, 19, 13, 47, 48, 5, 7, 30, 12, 41,
506 42, 4, 38, 18, 10, 29, 17, 60, 36, 8, 59, 58, 55, 16, 3, 32
507};
508
509static unsigned short gf4096_inv(unsigned short din)
510{
511 unsigned short alahxal, ah2B, deno, inv, bl, bh;
512 unsigned short ah, al, ahxal;
513 unsigned short dout;
514
515 ah = (din >> 6) & 0x3f;
516 al = din & 0x3f;
517 ahxal = ah ^ al;
518 ah2B = (((ah ^ (ah >> 3)) & 0x1) << 5) |
519 ((ah >> 1) & 0x10) |
520 ((((ah >> 5) ^ (ah >> 2)) & 0x1) << 3) |
521 ((ah >> 2) & 0x4) | ((((ah >> 4) ^ (ah >> 1)) & 0x1) << 1) | (ah & 0x1);
522 alahxal = gf64_mul(ahxal, al);
523 deno = alahxal ^ ah2B;
524 inv = gf64_inv[deno];
525 bl = gf64_mul(inv, ahxal);
526 bh = gf64_mul(inv, ah);
527 dout = ((bh & 0x3f) << 6) | (bl & 0x3f);
528 return (((bh & 0x3f) << 6) | (bl & 0x3f));
529}
530
531static unsigned short err_pos_lut[4096] = {
532 0xfff, 0x000, 0x451, 0xfff, 0xfff, 0x3cf, 0xfff, 0x041,
533 0xfff, 0xfff, 0xfff, 0xfff, 0x28a, 0xfff, 0x492, 0xfff,
534 0x145, 0xfff, 0xfff, 0x514, 0xfff, 0x082, 0xfff, 0xfff,
535 0xfff, 0x249, 0x38e, 0x410, 0xfff, 0x104, 0x208, 0x1c7,
536 0xfff, 0xfff, 0xfff, 0xfff, 0x2cb, 0xfff, 0xfff, 0xfff,
537 0x0c3, 0x34d, 0x4d3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
538 0xfff, 0xfff, 0xfff, 0x186, 0xfff, 0xfff, 0xfff, 0xfff,
539 0xfff, 0x30c, 0x555, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
540 0xfff, 0xfff, 0xfff, 0x166, 0xfff, 0xfff, 0xfff, 0xfff,
541 0x385, 0x14e, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e1,
542 0xfff, 0xfff, 0xfff, 0xfff, 0x538, 0xfff, 0x16d, 0xfff,
543 0xfff, 0xfff, 0x45b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
544 0xfff, 0xfff, 0xfff, 0x29c, 0x2cc, 0x30b, 0x2b3, 0xfff,
545 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0b3, 0xfff, 0x2f7,
546 0xfff, 0x32b, 0xfff, 0xfff, 0xfff, 0xfff, 0x0a7, 0xfff,
547 0xfff, 0x2da, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
548 0xfff, 0x07e, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
549 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x11c, 0xfff, 0xfff,
550 0xfff, 0xfff, 0xfff, 0x22f, 0xfff, 0x1f4, 0xfff, 0xfff,
551 0x2b0, 0x504, 0xfff, 0x114, 0xfff, 0xfff, 0xfff, 0x21d,
552 0xfff, 0xfff, 0xfff, 0xfff, 0x00d, 0x3c4, 0x340, 0x10f,
553 0xfff, 0xfff, 0x266, 0x02e, 0xfff, 0xfff, 0xfff, 0x4f8,
554 0x337, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
555 0xfff, 0xfff, 0xfff, 0x07b, 0x168, 0xfff, 0xfff, 0x0fe,
556 0xfff, 0xfff, 0x51a, 0xfff, 0x458, 0xfff, 0x36d, 0xfff,
557 0xfff, 0xfff, 0xfff, 0x073, 0x37d, 0x415, 0x550, 0xfff,
558 0xfff, 0xfff, 0x23b, 0x4b4, 0xfff, 0xfff, 0xfff, 0x1a1,
559 0xfff, 0xfff, 0x3aa, 0xfff, 0x117, 0x04d, 0x341, 0xfff,
560 0xfff, 0xfff, 0xfff, 0x518, 0x03e, 0x0f2, 0xfff, 0xfff,
561 0xfff, 0xfff, 0xfff, 0x363, 0xfff, 0x0b9, 0xfff, 0xfff,
562 0x241, 0xfff, 0xfff, 0x049, 0xfff, 0xfff, 0xfff, 0xfff,
563 0x15f, 0x52d, 0xfff, 0xfff, 0xfff, 0x29e, 0xfff, 0xfff,
564 0xfff, 0xfff, 0x4cf, 0x0fc, 0xfff, 0x36f, 0x3d3, 0xfff,
565 0x228, 0xfff, 0xfff, 0x45e, 0xfff, 0xfff, 0xfff, 0xfff,
566 0x238, 0xfff, 0xfff, 0xfff, 0xfff, 0x47f, 0xfff, 0xfff,
567 0x43a, 0x265, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3e8,
568 0xfff, 0xfff, 0x01a, 0xfff, 0xfff, 0xfff, 0xfff, 0x21e,
569 0x1fc, 0x40b, 0xfff, 0xfff, 0xfff, 0x2d0, 0x159, 0xfff,
570 0xfff, 0x313, 0xfff, 0xfff, 0x05c, 0x4cc, 0xfff, 0xfff,
571 0x0f6, 0x3d5, 0xfff, 0xfff, 0xfff, 0x54f, 0xfff, 0xfff,
572 0xfff, 0x172, 0x1e4, 0x07c, 0xfff, 0xfff, 0xfff, 0xfff,
573 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x53c, 0x1ad, 0x535,
574 0x19b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
575 0xfff, 0xfff, 0x092, 0xfff, 0x2be, 0xfff, 0xfff, 0x482,
576 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0e6, 0xfff, 0xfff,
577 0xfff, 0xfff, 0xfff, 0x476, 0xfff, 0x51d, 0xfff, 0xfff,
578 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
579 0xfff, 0xfff, 0x342, 0x2b5, 0x22e, 0x09a, 0xfff, 0x08d,
580 0x44f, 0x3ed, 0xfff, 0xfff, 0xfff, 0xfff, 0x3d1, 0xfff,
581 0xfff, 0x543, 0xfff, 0x48f, 0xfff, 0x3d2, 0xfff, 0x0d5,
582 0x113, 0x0ec, 0x427, 0xfff, 0xfff, 0xfff, 0x4c4, 0xfff,
583 0xfff, 0x50a, 0xfff, 0x144, 0xfff, 0x105, 0x39f, 0x294,
584 0x164, 0xfff, 0x31a, 0xfff, 0xfff, 0x49a, 0xfff, 0x130,
585 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
586 0x1be, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
587 0xfff, 0xfff, 0x49e, 0x371, 0xfff, 0xfff, 0xfff, 0xfff,
588 0xfff, 0xfff, 0xfff, 0xfff, 0x0e8, 0x49c, 0x0f4, 0xfff,
589 0x338, 0x1a7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
590 0xfff, 0x36c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
591 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
592 0xfff, 0x1ae, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
593 0xfff, 0x31b, 0xfff, 0xfff, 0x2dd, 0x522, 0xfff, 0xfff,
594 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2f4,
595 0x3c6, 0x30d, 0xfff, 0xfff, 0xfff, 0xfff, 0x34c, 0x18f,
596 0x30a, 0xfff, 0x01f, 0x079, 0xfff, 0xfff, 0x54d, 0x46b,
597 0x28c, 0x37f, 0xfff, 0xfff, 0xfff, 0xfff, 0x355, 0xfff,
598 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x14f, 0xfff, 0xfff,
599 0xfff, 0xfff, 0xfff, 0x359, 0x3fe, 0x3c5, 0xfff, 0xfff,
600 0xfff, 0xfff, 0x423, 0xfff, 0xfff, 0x34a, 0x22c, 0xfff,
601 0x25a, 0xfff, 0xfff, 0x4ad, 0xfff, 0x28d, 0xfff, 0xfff,
602 0xfff, 0xfff, 0xfff, 0x547, 0xfff, 0xfff, 0xfff, 0xfff,
603 0x2e2, 0xfff, 0xfff, 0x1d5, 0xfff, 0x2a8, 0xfff, 0xfff,
604 0x03f, 0xfff, 0xfff, 0xfff, 0xfff, 0x3eb, 0x0fa, 0xfff,
605 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x55b, 0xfff,
606 0x08e, 0xfff, 0x3ae, 0xfff, 0x3a4, 0xfff, 0x282, 0x158,
607 0xfff, 0x382, 0xfff, 0xfff, 0x499, 0xfff, 0xfff, 0x08a,
608 0xfff, 0xfff, 0xfff, 0x456, 0x3be, 0xfff, 0x1e2, 0xfff,
609 0xfff, 0xfff, 0xfff, 0xfff, 0x559, 0xfff, 0x1a0, 0xfff,
610 0xfff, 0x0b4, 0xfff, 0xfff, 0xfff, 0x2df, 0xfff, 0xfff,
611 0xfff, 0x07f, 0x4f5, 0xfff, 0xfff, 0x27c, 0x133, 0x017,
612 0xfff, 0x3fd, 0xfff, 0xfff, 0xfff, 0x44d, 0x4cd, 0x17a,
613 0x0d7, 0x537, 0xfff, 0xfff, 0x353, 0xfff, 0xfff, 0x351,
614 0x366, 0xfff, 0x44a, 0xfff, 0x1a6, 0xfff, 0xfff, 0xfff,
615 0x291, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1e3,
616 0xfff, 0xfff, 0xfff, 0xfff, 0x389, 0xfff, 0x07a, 0xfff,
617 0x1b6, 0x2ed, 0xfff, 0xfff, 0xfff, 0xfff, 0x24e, 0x074,
618 0xfff, 0xfff, 0x3dc, 0xfff, 0x4e3, 0xfff, 0xfff, 0xfff,
619 0xfff, 0x4eb, 0xfff, 0xfff, 0x3b8, 0x4de, 0xfff, 0x19c,
620 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x262,
621 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x076, 0x4e8, 0x3da,
622 0xfff, 0x531, 0xfff, 0xfff, 0x14a, 0xfff, 0x0a2, 0x433,
623 0x3df, 0x1e9, 0xfff, 0xfff, 0xfff, 0xfff, 0x3e7, 0x285,
624 0x2d8, 0xfff, 0xfff, 0xfff, 0x349, 0x18d, 0x098, 0xfff,
625 0x0df, 0x4bf, 0xfff, 0xfff, 0x0b2, 0xfff, 0x346, 0x24d,
626 0xfff, 0xfff, 0xfff, 0x24f, 0x4fa, 0x2f9, 0xfff, 0xfff,
627 0x3c9, 0xfff, 0x2b4, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
628 0xfff, 0x056, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
629 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
630 0xfff, 0x179, 0xfff, 0x0e9, 0x3f0, 0x33d, 0xfff, 0xfff,
631 0xfff, 0xfff, 0xfff, 0x1fd, 0xfff, 0xfff, 0x526, 0xfff,
632 0xfff, 0xfff, 0x53d, 0xfff, 0xfff, 0xfff, 0x170, 0x331,
633 0xfff, 0x068, 0xfff, 0xfff, 0xfff, 0x3f7, 0xfff, 0x3d8,
634 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
635 0xfff, 0x09f, 0x556, 0xfff, 0xfff, 0x02d, 0xfff, 0xfff,
636 0x553, 0xfff, 0xfff, 0xfff, 0x1f0, 0xfff, 0xfff, 0x4d6,
637 0x41e, 0xfff, 0xfff, 0xfff, 0xfff, 0x4d5, 0xfff, 0xfff,
638 0xfff, 0xfff, 0xfff, 0x248, 0xfff, 0xfff, 0xfff, 0x0a3,
639 0xfff, 0x217, 0xfff, 0xfff, 0xfff, 0x4f1, 0x209, 0xfff,
640 0xfff, 0x475, 0x234, 0x52b, 0x398, 0xfff, 0x08b, 0xfff,
641 0xfff, 0xfff, 0xfff, 0x2c2, 0xfff, 0xfff, 0xfff, 0xfff,
642 0xfff, 0xfff, 0x268, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
643 0xfff, 0x4a3, 0xfff, 0x0aa, 0xfff, 0x1d9, 0xfff, 0xfff,
644 0xfff, 0xfff, 0x155, 0xfff, 0xfff, 0xfff, 0xfff, 0x0bf,
645 0x539, 0xfff, 0xfff, 0x2f1, 0x545, 0xfff, 0xfff, 0xfff,
646 0xfff, 0xfff, 0xfff, 0x2a7, 0x06f, 0xfff, 0x378, 0xfff,
647 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x25e, 0xfff,
648 0xfff, 0xfff, 0xfff, 0x15d, 0x02a, 0xfff, 0xfff, 0x0bc,
649 0x235, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
650 0x150, 0xfff, 0x1a9, 0xfff, 0xfff, 0xfff, 0xfff, 0x381,
651 0xfff, 0x04e, 0x270, 0x13f, 0xfff, 0xfff, 0x405, 0xfff,
652 0x3cd, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
653 0xfff, 0x2ef, 0xfff, 0x06a, 0xfff, 0xfff, 0xfff, 0x34f,
654 0x212, 0xfff, 0xfff, 0x0e2, 0xfff, 0x083, 0x298, 0xfff,
655 0xfff, 0xfff, 0x0c2, 0xfff, 0xfff, 0x52e, 0xfff, 0x488,
656 0xfff, 0xfff, 0xfff, 0x36b, 0xfff, 0xfff, 0xfff, 0x442,
657 0x091, 0xfff, 0x41c, 0xfff, 0xfff, 0x3a5, 0xfff, 0x4e6,
658 0xfff, 0xfff, 0x40d, 0x31d, 0xfff, 0xfff, 0xfff, 0x4c1,
659 0x053, 0xfff, 0x418, 0x13c, 0xfff, 0x350, 0xfff, 0x0ae,
660 0xfff, 0xfff, 0x41f, 0xfff, 0x470, 0xfff, 0x4ca, 0xfff,
661 0xfff, 0xfff, 0x02b, 0x450, 0xfff, 0x1f8, 0xfff, 0xfff,
662 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x293, 0xfff,
663 0xfff, 0xfff, 0xfff, 0x411, 0xfff, 0xfff, 0xfff, 0xfff,
664 0xfff, 0xfff, 0xfff, 0xfff, 0x0b8, 0xfff, 0xfff, 0xfff,
665 0x3e1, 0xfff, 0xfff, 0xfff, 0xfff, 0x43c, 0xfff, 0x2b2,
666 0x2ab, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ec,
667 0xfff, 0xfff, 0xfff, 0x3f8, 0x034, 0xfff, 0xfff, 0xfff,
668 0xfff, 0xfff, 0xfff, 0x11a, 0xfff, 0x541, 0x45c, 0x134,
669 0x1cc, 0xfff, 0xfff, 0xfff, 0x469, 0xfff, 0xfff, 0x44b,
670 0x161, 0xfff, 0xfff, 0xfff, 0x055, 0xfff, 0xfff, 0xfff,
671 0xfff, 0x307, 0xfff, 0xfff, 0xfff, 0xfff, 0x2d1, 0xfff,
672 0xfff, 0xfff, 0x124, 0x37b, 0x26b, 0x336, 0xfff, 0xfff,
673 0x2e4, 0x3cb, 0xfff, 0xfff, 0x0f8, 0x3c8, 0xfff, 0xfff,
674 0xfff, 0x461, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4b5,
675 0x2cf, 0xfff, 0xfff, 0xfff, 0x20f, 0xfff, 0x35a, 0xfff,
676 0x490, 0xfff, 0x185, 0xfff, 0xfff, 0xfff, 0xfff, 0x42e,
677 0xfff, 0xfff, 0xfff, 0xfff, 0x54b, 0xfff, 0xfff, 0xfff,
678 0x146, 0xfff, 0x412, 0xfff, 0xfff, 0xfff, 0x1ff, 0xfff,
679 0xfff, 0x3e0, 0xfff, 0xfff, 0xfff, 0xfff, 0x2d5, 0xfff,
680 0x4df, 0x505, 0xfff, 0x413, 0xfff, 0x1a5, 0xfff, 0x3b2,
681 0xfff, 0xfff, 0xfff, 0x35b, 0xfff, 0x116, 0xfff, 0xfff,
682 0x171, 0x4d0, 0xfff, 0x154, 0x12d, 0xfff, 0xfff, 0xfff,
683 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x468, 0x4db, 0xfff,
684 0xfff, 0x1df, 0xfff, 0xfff, 0xfff, 0xfff, 0x05a, 0xfff,
685 0x0f1, 0x403, 0xfff, 0x22b, 0x2e0, 0xfff, 0xfff, 0xfff,
686 0x2b7, 0x373, 0xfff, 0xfff, 0xfff, 0xfff, 0x13e, 0xfff,
687 0xfff, 0xfff, 0x0d0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
688 0x329, 0x1d2, 0x3fa, 0x047, 0xfff, 0x2f2, 0xfff, 0xfff,
689 0x141, 0x0ac, 0x1d7, 0xfff, 0x07d, 0xfff, 0xfff, 0xfff,
690 0x1c1, 0xfff, 0x487, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
691 0xfff, 0xfff, 0xfff, 0x045, 0xfff, 0xfff, 0xfff, 0xfff,
692 0x288, 0x0cd, 0xfff, 0xfff, 0xfff, 0xfff, 0x226, 0x1d8,
693 0xfff, 0x153, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4cb,
694 0x528, 0xfff, 0xfff, 0xfff, 0x20a, 0x343, 0x3a1, 0xfff,
695 0xfff, 0xfff, 0x2d7, 0x2d3, 0x1aa, 0x4c5, 0xfff, 0xfff,
696 0xfff, 0x42b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
697 0xfff, 0xfff, 0xfff, 0xfff, 0x3e9, 0xfff, 0x20b, 0x260,
698 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x37c, 0x2fd,
699 0xfff, 0xfff, 0x2c8, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
700 0xfff, 0x31e, 0xfff, 0x335, 0xfff, 0xfff, 0xfff, 0xfff,
701 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
702 0xfff, 0xfff, 0x135, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
703 0xfff, 0xfff, 0x35c, 0x4dd, 0x129, 0xfff, 0xfff, 0xfff,
704 0xfff, 0xfff, 0x1ef, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
705 0xfff, 0x34e, 0xfff, 0xfff, 0xfff, 0xfff, 0x407, 0xfff,
706 0xfff, 0xfff, 0xfff, 0xfff, 0x3ad, 0xfff, 0xfff, 0xfff,
707 0x379, 0xfff, 0xfff, 0x1d0, 0x38d, 0xfff, 0xfff, 0x1e8,
708 0x184, 0x3c1, 0x1c4, 0xfff, 0x1f9, 0xfff, 0xfff, 0x424,
709 0xfff, 0xfff, 0xfff, 0xfff, 0x1d3, 0x0d4, 0xfff, 0x4e9,
710 0xfff, 0xfff, 0xfff, 0x530, 0x107, 0xfff, 0x106, 0x04f,
711 0xfff, 0xfff, 0x4c7, 0x503, 0xfff, 0xfff, 0xfff, 0xfff,
712 0xfff, 0x15c, 0xfff, 0x23f, 0xfff, 0xfff, 0xfff, 0xfff,
713 0xfff, 0xfff, 0xfff, 0xfff, 0x4f3, 0xfff, 0xfff, 0x3c7,
714 0xfff, 0x278, 0xfff, 0xfff, 0x0a6, 0xfff, 0xfff, 0xfff,
715 0x122, 0x1cf, 0xfff, 0x327, 0xfff, 0x2e5, 0xfff, 0x29d,
716 0xfff, 0xfff, 0x3f1, 0xfff, 0xfff, 0x48d, 0xfff, 0xfff,
717 0xfff, 0xfff, 0x054, 0xfff, 0xfff, 0xfff, 0xfff, 0x178,
718 0x27e, 0x4e0, 0x352, 0x02f, 0x09c, 0xfff, 0x2a0, 0xfff,
719 0xfff, 0x46a, 0x457, 0xfff, 0xfff, 0x501, 0xfff, 0x2ba,
720 0xfff, 0xfff, 0xfff, 0x54e, 0x2e7, 0xfff, 0xfff, 0xfff,
721 0xfff, 0xfff, 0x551, 0xfff, 0xfff, 0x1db, 0x2aa, 0xfff,
722 0xfff, 0x4bc, 0xfff, 0xfff, 0x395, 0xfff, 0x0de, 0xfff,
723 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x455, 0xfff, 0x17e,
724 0xfff, 0x221, 0x4a7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
725 0x388, 0xfff, 0xfff, 0xfff, 0x308, 0xfff, 0xfff, 0xfff,
726 0x20e, 0x4b9, 0xfff, 0x273, 0x20c, 0x09e, 0xfff, 0x057,
727 0xfff, 0xfff, 0xfff, 0xfff, 0x3f2, 0xfff, 0x1a8, 0x3a6,
728 0x14c, 0xfff, 0xfff, 0x071, 0xfff, 0xfff, 0x53a, 0xfff,
729 0xfff, 0xfff, 0xfff, 0x109, 0xfff, 0xfff, 0x399, 0xfff,
730 0x061, 0x4f0, 0x39e, 0x244, 0xfff, 0x035, 0xfff, 0xfff,
731 0x305, 0x47e, 0x297, 0xfff, 0xfff, 0x2b8, 0xfff, 0xfff,
732 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1bc, 0xfff, 0x2fc,
733 0xfff, 0xfff, 0x554, 0xfff, 0xfff, 0xfff, 0xfff, 0x3b6,
734 0xfff, 0xfff, 0xfff, 0x515, 0x397, 0xfff, 0xfff, 0x12f,
735 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e5,
736 0xfff, 0x4fc, 0xfff, 0xfff, 0x05e, 0xfff, 0xfff, 0xfff,
737 0xfff, 0xfff, 0x0a8, 0x3af, 0x015, 0xfff, 0xfff, 0xfff,
738 0xfff, 0x138, 0xfff, 0xfff, 0xfff, 0x540, 0xfff, 0xfff,
739 0xfff, 0x027, 0x523, 0x2f0, 0xfff, 0xfff, 0xfff, 0xfff,
740 0xfff, 0xfff, 0x16c, 0xfff, 0x27d, 0xfff, 0xfff, 0xfff,
741 0xfff, 0x04c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4dc,
742 0xfff, 0xfff, 0x059, 0x301, 0xfff, 0xfff, 0xfff, 0xfff,
743 0xfff, 0xfff, 0xfff, 0x1a3, 0xfff, 0x15a, 0xfff, 0xfff,
744 0x0a5, 0xfff, 0x435, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
745 0xfff, 0x051, 0xfff, 0xfff, 0x131, 0xfff, 0x4f4, 0xfff,
746 0xfff, 0xfff, 0xfff, 0x441, 0xfff, 0x4fb, 0xfff, 0x03b,
747 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ed, 0x274,
748 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d3, 0x55e, 0x1b3,
749 0xfff, 0x0bd, 0xfff, 0xfff, 0xfff, 0xfff, 0x225, 0xfff,
750 0xfff, 0xfff, 0xfff, 0xfff, 0x4b7, 0xfff, 0xfff, 0x2ff,
751 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4c3, 0xfff,
752 0x383, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2f6,
753 0xfff, 0xfff, 0x1ee, 0xfff, 0x03d, 0xfff, 0xfff, 0xfff,
754 0xfff, 0xfff, 0x26f, 0x1dc, 0xfff, 0x0db, 0xfff, 0xfff,
755 0xfff, 0xfff, 0xfff, 0x0ce, 0xfff, 0xfff, 0x127, 0x03a,
756 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x311, 0xfff,
757 0xfff, 0x13d, 0x09d, 0x47b, 0x2a6, 0x50d, 0x510, 0x19a,
758 0xfff, 0x354, 0x414, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
759 0xfff, 0xfff, 0x44c, 0x3b0, 0xfff, 0x23d, 0x429, 0xfff,
760 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
761 0x4c0, 0x416, 0xfff, 0x05b, 0xfff, 0xfff, 0x137, 0xfff,
762 0x25f, 0x49f, 0xfff, 0x279, 0x013, 0xfff, 0xfff, 0xfff,
763 0x269, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
764 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3d0, 0xfff, 0xfff,
765 0xfff, 0xfff, 0xfff, 0xfff, 0x077, 0xfff, 0xfff, 0x3fb,
766 0xfff, 0xfff, 0xfff, 0xfff, 0x271, 0x3a0, 0xfff, 0xfff,
767 0x40f, 0xfff, 0xfff, 0x3de, 0xfff, 0xfff, 0xfff, 0xfff,
768 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ab, 0x26a,
769 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x489, 0xfff, 0xfff,
770 0x252, 0xfff, 0xfff, 0xfff, 0xfff, 0x1b7, 0x42f, 0xfff,
771 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3b7,
772 0xfff, 0x2bb, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
773 0xfff, 0xfff, 0xfff, 0x0f7, 0x01d, 0xfff, 0x067, 0xfff,
774 0xfff, 0xfff, 0xfff, 0x4e2, 0xfff, 0xfff, 0x4bb, 0xfff,
775 0xfff, 0xfff, 0x17b, 0xfff, 0x0ee, 0xfff, 0xfff, 0xfff,
776 0xfff, 0xfff, 0x36e, 0xfff, 0xfff, 0xfff, 0x533, 0xfff,
777 0xfff, 0xfff, 0x4d4, 0x356, 0xfff, 0xfff, 0x375, 0xfff,
778 0xfff, 0xfff, 0xfff, 0x4a4, 0x513, 0xfff, 0xfff, 0xfff,
779 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4ff, 0xfff, 0x2af,
780 0xfff, 0xfff, 0x026, 0xfff, 0x0ad, 0xfff, 0xfff, 0xfff,
781 0xfff, 0x26e, 0xfff, 0xfff, 0xfff, 0xfff, 0x493, 0xfff,
782 0x463, 0x4d2, 0x4be, 0xfff, 0xfff, 0xfff, 0xfff, 0x4f2,
783 0x0b6, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
784 0xfff, 0x32d, 0x315, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
785 0xfff, 0x13a, 0x4a1, 0xfff, 0x27a, 0xfff, 0xfff, 0xfff,
786 0x47a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
787 0x334, 0xfff, 0xfff, 0xfff, 0xfff, 0x54c, 0xfff, 0xfff,
788 0xfff, 0x0c9, 0x007, 0xfff, 0xfff, 0x12e, 0xfff, 0x0ff,
789 0xfff, 0xfff, 0x3f5, 0x509, 0xfff, 0xfff, 0xfff, 0xfff,
790 0x1c3, 0x2ad, 0xfff, 0xfff, 0x47c, 0x261, 0xfff, 0xfff,
791 0xfff, 0xfff, 0xfff, 0x152, 0xfff, 0xfff, 0xfff, 0x339,
792 0xfff, 0x243, 0x1c0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
793 0x063, 0xfff, 0xfff, 0x254, 0xfff, 0xfff, 0x173, 0xfff,
794 0x0c7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
795 0xfff, 0x362, 0x259, 0x485, 0x374, 0x0dc, 0x3ab, 0xfff,
796 0x1c5, 0x534, 0x544, 0xfff, 0xfff, 0x508, 0xfff, 0x402,
797 0x408, 0xfff, 0x0e7, 0xfff, 0xfff, 0x00a, 0x205, 0xfff,
798 0xfff, 0x2b9, 0xfff, 0xfff, 0xfff, 0x465, 0xfff, 0xfff,
799 0xfff, 0xfff, 0xfff, 0xfff, 0x23a, 0xfff, 0xfff, 0xfff,
800 0xfff, 0x147, 0x19d, 0x115, 0x214, 0xfff, 0x090, 0x368,
801 0xfff, 0x210, 0xfff, 0xfff, 0x280, 0x52a, 0x163, 0x148,
802 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x326, 0xfff, 0xfff,
803 0xfff, 0xfff, 0xfff, 0x2de, 0xfff, 0xfff, 0xfff, 0xfff,
804 0x206, 0x2c1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
805 0x189, 0xfff, 0xfff, 0xfff, 0xfff, 0x367, 0xfff, 0x1a4,
806 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x443, 0xfff, 0x27b,
807 0xfff, 0xfff, 0x251, 0x549, 0xfff, 0xfff, 0xfff, 0xfff,
808 0xfff, 0xfff, 0x188, 0x04b, 0xfff, 0xfff, 0xfff, 0x31f,
809 0x4a6, 0xfff, 0x246, 0x1de, 0x156, 0xfff, 0xfff, 0xfff,
810 0x3a9, 0xfff, 0xfff, 0xfff, 0x2fa, 0xfff, 0x128, 0x0d1,
811 0x449, 0x255, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
812 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
813 0xfff, 0xfff, 0xfff, 0xfff, 0x258, 0xfff, 0xfff, 0xfff,
814 0x532, 0xfff, 0xfff, 0xfff, 0x303, 0x517, 0xfff, 0xfff,
815 0x2a9, 0x24a, 0xfff, 0xfff, 0x231, 0xfff, 0xfff, 0xfff,
816 0xfff, 0xfff, 0x4b6, 0x516, 0xfff, 0xfff, 0x0e4, 0x0eb,
817 0xfff, 0x4e4, 0xfff, 0x275, 0xfff, 0xfff, 0x031, 0xfff,
818 0xfff, 0xfff, 0xfff, 0xfff, 0x025, 0x21a, 0xfff, 0x0cc,
819 0x45f, 0x3d9, 0x289, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
820 0xfff, 0xfff, 0x23e, 0xfff, 0xfff, 0xfff, 0x438, 0x097,
821 0x419, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
822 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
823 0xfff, 0xfff, 0x0a9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
824 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
825 0x37e, 0x0e0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x431,
826 0x372, 0xfff, 0xfff, 0xfff, 0x1ba, 0x06e, 0xfff, 0x1b1,
827 0xfff, 0xfff, 0x12a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
828 0xfff, 0xfff, 0x193, 0xfff, 0xfff, 0xfff, 0xfff, 0x10a,
829 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x048, 0x1b4,
830 0xfff, 0xfff, 0xfff, 0xfff, 0x295, 0x140, 0x108, 0xfff,
831 0xfff, 0xfff, 0xfff, 0x16f, 0xfff, 0x0a4, 0x37a, 0xfff,
832 0x29a, 0xfff, 0x284, 0xfff, 0xfff, 0xfff, 0xfff, 0x4c6,
833 0x2a2, 0x3a3, 0xfff, 0x201, 0xfff, 0xfff, 0xfff, 0x4bd,
834 0x005, 0x54a, 0x3b5, 0x204, 0x2ee, 0x11d, 0x436, 0xfff,
835 0xfff, 0xfff, 0xfff, 0xfff, 0x3ec, 0xfff, 0xfff, 0xfff,
836 0xfff, 0xfff, 0xfff, 0xfff, 0x11f, 0x498, 0x21c, 0xfff,
837 0xfff, 0xfff, 0x3d6, 0xfff, 0x4ab, 0xfff, 0x432, 0x2eb,
838 0x542, 0x4fd, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
839 0xfff, 0xfff, 0xfff, 0x4ce, 0xfff, 0xfff, 0x2fb, 0xfff,
840 0xfff, 0x2e1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
841 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1b9, 0x037, 0x0dd,
842 0xfff, 0xfff, 0xfff, 0x2bf, 0x521, 0x496, 0x095, 0xfff,
843 0xfff, 0x328, 0x070, 0x1bf, 0xfff, 0x393, 0xfff, 0xfff,
844 0x102, 0xfff, 0xfff, 0x21b, 0xfff, 0x142, 0x263, 0x519,
845 0xfff, 0x2a5, 0x177, 0xfff, 0x14d, 0x471, 0x4ae, 0xfff,
846 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
847 0x1f6, 0xfff, 0x481, 0xfff, 0xfff, 0xfff, 0x151, 0xfff,
848 0xfff, 0xfff, 0x085, 0x33f, 0xfff, 0xfff, 0xfff, 0x084,
849 0xfff, 0xfff, 0xfff, 0x345, 0x3a2, 0xfff, 0xfff, 0x0a0,
850 0x0da, 0x024, 0xfff, 0xfff, 0xfff, 0x1bd, 0xfff, 0x55c,
851 0x467, 0x445, 0xfff, 0xfff, 0xfff, 0x052, 0xfff, 0xfff,
852 0xfff, 0xfff, 0x51e, 0xfff, 0xfff, 0x39d, 0xfff, 0x35f,
853 0xfff, 0x376, 0x3ee, 0xfff, 0xfff, 0xfff, 0xfff, 0x448,
854 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x16a,
855 0xfff, 0x036, 0x38f, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
856 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x211,
857 0xfff, 0xfff, 0xfff, 0x230, 0xfff, 0xfff, 0x3ba, 0xfff,
858 0xfff, 0xfff, 0x3ce, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
859 0xfff, 0xfff, 0xfff, 0x229, 0xfff, 0x176, 0xfff, 0xfff,
860 0xfff, 0xfff, 0xfff, 0x00b, 0xfff, 0x162, 0x018, 0xfff,
861 0xfff, 0x233, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
862 0x400, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
863 0xfff, 0xfff, 0xfff, 0x12b, 0xfff, 0xfff, 0xfff, 0xfff,
864 0xfff, 0x3f4, 0xfff, 0x0f0, 0xfff, 0x1ac, 0xfff, 0xfff,
865 0x119, 0xfff, 0x2c0, 0xfff, 0xfff, 0xfff, 0x49b, 0xfff,
866 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x23c, 0xfff,
867 0x4b3, 0x010, 0x064, 0xfff, 0xfff, 0x4ba, 0xfff, 0xfff,
868 0xfff, 0xfff, 0xfff, 0x3c2, 0xfff, 0xfff, 0xfff, 0xfff,
869 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x006, 0x196, 0xfff,
870 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x100, 0x191, 0xfff,
871 0x1ea, 0x29f, 0xfff, 0xfff, 0xfff, 0x276, 0xfff, 0xfff,
872 0x2b1, 0x3b9, 0xfff, 0x03c, 0xfff, 0xfff, 0xfff, 0x180,
873 0xfff, 0x08f, 0xfff, 0xfff, 0x19e, 0x019, 0xfff, 0x0b0,
874 0x0fd, 0x332, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
875 0xfff, 0x06b, 0x2e8, 0xfff, 0x446, 0xfff, 0xfff, 0x004,
876 0x247, 0x197, 0xfff, 0x112, 0x169, 0x292, 0xfff, 0x302,
877 0xfff, 0xfff, 0x33b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
878 0xfff, 0xfff, 0xfff, 0x287, 0x21f, 0xfff, 0x3ea, 0xfff,
879 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e7, 0xfff, 0xfff,
880 0xfff, 0xfff, 0xfff, 0x3a8, 0xfff, 0xfff, 0x2bc, 0xfff,
881 0x484, 0x296, 0xfff, 0x1c9, 0x08c, 0x1e5, 0x48a, 0xfff,
882 0x360, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
883 0x1ca, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
884 0xfff, 0xfff, 0xfff, 0x10d, 0xfff, 0xfff, 0xfff, 0xfff,
885 0xfff, 0xfff, 0x066, 0x2ea, 0x28b, 0x25b, 0xfff, 0x072,
886 0xfff, 0xfff, 0xfff, 0xfff, 0x2b6, 0xfff, 0xfff, 0x272,
887 0xfff, 0xfff, 0x525, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
888 0x2ca, 0xfff, 0xfff, 0xfff, 0x299, 0xfff, 0xfff, 0xfff,
889 0x558, 0x41a, 0xfff, 0x4f7, 0x557, 0xfff, 0x4a0, 0x344,
890 0x12c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x125,
891 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
892 0x40e, 0xfff, 0xfff, 0x502, 0xfff, 0x103, 0x3e6, 0xfff,
893 0x527, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
894 0xfff, 0xfff, 0xfff, 0x45d, 0xfff, 0xfff, 0xfff, 0xfff,
895 0x44e, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d2, 0x4c9, 0x35e,
896 0x459, 0x2d9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x17d,
897 0x0c4, 0xfff, 0xfff, 0xfff, 0x3ac, 0x390, 0x094, 0xfff,
898 0x483, 0x0ab, 0xfff, 0x253, 0xfff, 0x391, 0xfff, 0xfff,
899 0xfff, 0xfff, 0x123, 0x0ef, 0xfff, 0xfff, 0xfff, 0x330,
900 0x38c, 0xfff, 0xfff, 0x2ae, 0xfff, 0xfff, 0xfff, 0x042,
901 0x012, 0x06d, 0xfff, 0xfff, 0xfff, 0x32a, 0x3db, 0x364,
902 0x2dc, 0xfff, 0x30f, 0x3d7, 0x4a5, 0x050, 0xfff, 0xfff,
903 0x029, 0xfff, 0xfff, 0xfff, 0xfff, 0x1d1, 0xfff, 0xfff,
904 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x480, 0xfff,
905 0x4ed, 0x081, 0x0a1, 0xfff, 0xfff, 0xfff, 0x30e, 0x52f,
906 0x257, 0xfff, 0xfff, 0x447, 0xfff, 0xfff, 0xfff, 0xfff,
907 0xfff, 0xfff, 0xfff, 0x401, 0x3cc, 0xfff, 0xfff, 0x0fb,
908 0x2c9, 0x42a, 0x314, 0x33e, 0x3bd, 0x318, 0xfff, 0x10e,
909 0x2a1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x24c,
910 0x506, 0xfff, 0x267, 0xfff, 0xfff, 0x219, 0xfff, 0x1eb,
911 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
912 0x309, 0x3e2, 0x46c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
913 0x384, 0xfff, 0xfff, 0xfff, 0xfff, 0x50c, 0xfff, 0x24b,
914 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x038,
915 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x194,
916 0x143, 0x3e3, 0xfff, 0xfff, 0xfff, 0x4c2, 0xfff, 0xfff,
917 0x0e1, 0x25c, 0xfff, 0x237, 0xfff, 0x1fe, 0xfff, 0xfff,
918 0xfff, 0x065, 0x2a4, 0xfff, 0x386, 0x55a, 0x11b, 0xfff,
919 0xfff, 0x192, 0xfff, 0x183, 0x00e, 0xfff, 0xfff, 0xfff,
920 0xfff, 0xfff, 0xfff, 0x4b2, 0x18e, 0xfff, 0xfff, 0xfff,
921 0xfff, 0x486, 0x4ef, 0x0c6, 0x380, 0xfff, 0x4a8, 0xfff,
922 0x0c5, 0xfff, 0xfff, 0xfff, 0xfff, 0x093, 0x1b8, 0xfff,
923 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2e6,
924 0xfff, 0x0f3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
925 0x28e, 0xfff, 0x53b, 0x420, 0x22a, 0x33a, 0xfff, 0x387,
926 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2a3, 0xfff, 0xfff,
927 0xfff, 0x428, 0x500, 0xfff, 0xfff, 0x120, 0x2c6, 0x290,
928 0x2f5, 0x0e3, 0xfff, 0x0b7, 0xfff, 0x319, 0x474, 0xfff,
929 0xfff, 0xfff, 0x529, 0x014, 0xfff, 0x41b, 0x40a, 0x18b,
930 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d9,
931 0xfff, 0x38a, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ce, 0xfff,
932 0xfff, 0xfff, 0xfff, 0xfff, 0x3b1, 0xfff, 0xfff, 0x05d,
933 0x2c4, 0xfff, 0xfff, 0x4af, 0xfff, 0x030, 0xfff, 0xfff,
934 0x203, 0xfff, 0x277, 0x256, 0xfff, 0xfff, 0xfff, 0x4f9,
935 0xfff, 0x2c7, 0xfff, 0x466, 0x016, 0x1cd, 0xfff, 0x167,
936 0xfff, 0xfff, 0x0c8, 0xfff, 0x43d, 0xfff, 0xfff, 0x020,
937 0xfff, 0xfff, 0x232, 0x1cb, 0x1e0, 0xfff, 0xfff, 0x347,
938 0xfff, 0x478, 0xfff, 0x365, 0xfff, 0xfff, 0xfff, 0xfff,
939 0x358, 0xfff, 0x10b, 0xfff, 0x35d, 0xfff, 0xfff, 0xfff,
940 0xfff, 0xfff, 0x452, 0x22d, 0xfff, 0xfff, 0x47d, 0xfff,
941 0x2f3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x460, 0xfff,
942 0xfff, 0xfff, 0x50b, 0xfff, 0xfff, 0xfff, 0x2ec, 0xfff,
943 0xfff, 0xfff, 0xfff, 0xfff, 0x4b1, 0x422, 0xfff, 0xfff,
944 0xfff, 0x2d4, 0xfff, 0x239, 0xfff, 0xfff, 0xfff, 0x439,
945 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
946 0xfff, 0x491, 0x075, 0xfff, 0xfff, 0xfff, 0x06c, 0xfff,
947 0xfff, 0x0f9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
948 0xfff, 0x139, 0xfff, 0x4f6, 0xfff, 0xfff, 0x409, 0xfff,
949 0xfff, 0x15b, 0xfff, 0xfff, 0x348, 0xfff, 0xfff, 0xfff,
950 0xfff, 0x4a2, 0x49d, 0xfff, 0x033, 0x175, 0xfff, 0x039,
951 0xfff, 0x312, 0x40c, 0xfff, 0xfff, 0x325, 0xfff, 0xfff,
952 0xfff, 0xfff, 0xfff, 0xfff, 0x4aa, 0xfff, 0xfff, 0xfff,
953 0xfff, 0xfff, 0xfff, 0x165, 0x3bc, 0x48c, 0x310, 0x096,
954 0xfff, 0xfff, 0x250, 0x1a2, 0xfff, 0xfff, 0xfff, 0xfff,
955 0x20d, 0x2ac, 0xfff, 0xfff, 0x39b, 0xfff, 0x377, 0xfff,
956 0x512, 0x495, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
957 0xfff, 0xfff, 0xfff, 0xfff, 0x357, 0x4ea, 0xfff, 0xfff,
958 0xfff, 0xfff, 0x198, 0xfff, 0xfff, 0xfff, 0x434, 0x04a,
959 0xfff, 0xfff, 0xfff, 0xfff, 0x062, 0xfff, 0x1d6, 0x1c8,
960 0xfff, 0x1f3, 0x281, 0xfff, 0x462, 0xfff, 0xfff, 0xfff,
961 0x4b0, 0xfff, 0x207, 0xfff, 0xfff, 0xfff, 0xfff, 0x3dd,
962 0xfff, 0xfff, 0x55d, 0xfff, 0x552, 0x494, 0x1af, 0xfff,
963 0xfff, 0xfff, 0xfff, 0xfff, 0x227, 0xfff, 0xfff, 0x069,
964 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x43e,
965 0x0b5, 0xfff, 0x524, 0x2d2, 0xfff, 0xfff, 0xfff, 0x28f,
966 0xfff, 0x01b, 0x50e, 0xfff, 0xfff, 0x1bb, 0xfff, 0xfff,
967 0x41d, 0xfff, 0x32e, 0x48e, 0xfff, 0x1f7, 0x224, 0xfff,
968 0xfff, 0xfff, 0xfff, 0xfff, 0x394, 0xfff, 0xfff, 0xfff,
969 0xfff, 0x52c, 0xfff, 0xfff, 0xfff, 0x392, 0xfff, 0x1e7,
970 0xfff, 0xfff, 0x3f9, 0x3a7, 0xfff, 0x51f, 0xfff, 0x0bb,
971 0x118, 0x3ca, 0xfff, 0x1dd, 0xfff, 0x48b, 0xfff, 0xfff,
972 0xfff, 0xfff, 0x50f, 0xfff, 0x0d6, 0xfff, 0x1fa, 0xfff,
973 0x11e, 0xfff, 0xfff, 0xfff, 0xfff, 0x4d7, 0xfff, 0x078,
974 0x008, 0xfff, 0x25d, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
975 0x032, 0x33c, 0xfff, 0x4d9, 0x160, 0xfff, 0xfff, 0x300,
976 0x0b1, 0xfff, 0x322, 0xfff, 0x4ec, 0xfff, 0xfff, 0x200,
977 0x00c, 0x369, 0x473, 0xfff, 0xfff, 0x32c, 0xfff, 0xfff,
978 0xfff, 0xfff, 0xfff, 0xfff, 0x53e, 0x3d4, 0x417, 0xfff,
979 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
980 0x34b, 0x001, 0x39a, 0x02c, 0xfff, 0xfff, 0x2ce, 0x00f,
981 0xfff, 0x0ba, 0xfff, 0xfff, 0xfff, 0xfff, 0x060, 0xfff,
982 0x406, 0xfff, 0xfff, 0xfff, 0x4ee, 0x4ac, 0xfff, 0x43f,
983 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x29b, 0xfff, 0xfff,
984 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x216,
985 0x190, 0xfff, 0x396, 0x464, 0xfff, 0xfff, 0x323, 0xfff,
986 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2e9, 0xfff, 0x26d,
987 0x2cd, 0x040, 0xfff, 0xfff, 0xfff, 0xfff, 0x38b, 0x3c0,
988 0xfff, 0xfff, 0xfff, 0x1f2, 0xfff, 0x0ea, 0xfff, 0xfff,
989 0x472, 0xfff, 0x1fb, 0xfff, 0xfff, 0x0af, 0x27f, 0xfff,
990 0xfff, 0xfff, 0x479, 0x023, 0xfff, 0x0d8, 0x3b3, 0xfff,
991 0xfff, 0xfff, 0x121, 0xfff, 0xfff, 0x3bf, 0xfff, 0xfff,
992 0x16b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
993 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
994 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
995 0x45a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
996 0xfff, 0x0be, 0xfff, 0xfff, 0xfff, 0x111, 0xfff, 0x220,
997 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
998 0xfff, 0xfff, 0x09b, 0x218, 0xfff, 0x022, 0x202, 0xfff,
999 0x4c8, 0xfff, 0x0ed, 0xfff, 0xfff, 0x182, 0xfff, 0xfff,
1000 0xfff, 0x17f, 0x213, 0xfff, 0x321, 0x36a, 0xfff, 0x086,
1001 0xfff, 0xfff, 0xfff, 0x43b, 0x088, 0xfff, 0xfff, 0xfff,
1002 0xfff, 0x26c, 0xfff, 0x2f8, 0x3b4, 0xfff, 0xfff, 0xfff,
1003 0x132, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x333, 0x444,
1004 0x0c1, 0x4d8, 0x46d, 0x264, 0xfff, 0xfff, 0xfff, 0xfff,
1005 0x426, 0xfff, 0xfff, 0xfff, 0xfff, 0x2fe, 0xfff, 0xfff,
1006 0xfff, 0xfff, 0x011, 0xfff, 0x05f, 0xfff, 0xfff, 0xfff,
1007 0xfff, 0x10c, 0x101, 0xfff, 0xfff, 0xfff, 0xfff, 0x110,
1008 0xfff, 0x044, 0x304, 0x361, 0x404, 0xfff, 0x51b, 0x099,
1009 0xfff, 0x440, 0xfff, 0xfff, 0xfff, 0x222, 0xfff, 0xfff,
1010 0xfff, 0xfff, 0x1b5, 0xfff, 0x136, 0x430, 0xfff, 0x1da,
1011 0xfff, 0xfff, 0xfff, 0x043, 0xfff, 0x17c, 0xfff, 0xfff,
1012 0xfff, 0x01c, 0xfff, 0xfff, 0xfff, 0x425, 0x236, 0xfff,
1013 0x317, 0xfff, 0xfff, 0x437, 0x3fc, 0xfff, 0x1f1, 0xfff,
1014 0x324, 0xfff, 0xfff, 0x0ca, 0x306, 0xfff, 0x548, 0xfff,
1015 0x46e, 0xfff, 0xfff, 0xfff, 0x4b8, 0x1c2, 0x286, 0xfff,
1016 0xfff, 0x087, 0x18a, 0x19f, 0xfff, 0xfff, 0xfff, 0xfff,
1017 0x18c, 0xfff, 0x215, 0xfff, 0xfff, 0xfff, 0xfff, 0x283,
1018 0xfff, 0xfff, 0xfff, 0x126, 0xfff, 0xfff, 0x370, 0xfff,
1019 0x53f, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x31c, 0xfff,
1020 0x4d1, 0xfff, 0xfff, 0xfff, 0x021, 0xfff, 0x157, 0xfff,
1021 0xfff, 0x028, 0x16e, 0xfff, 0x421, 0xfff, 0x1c6, 0xfff,
1022 0xfff, 0x511, 0xfff, 0xfff, 0x39c, 0x46f, 0x1b2, 0xfff,
1023 0xfff, 0x316, 0xfff, 0xfff, 0x009, 0xfff, 0xfff, 0x195,
1024 0xfff, 0x240, 0x546, 0xfff, 0xfff, 0x520, 0xfff, 0xfff,
1025 0xfff, 0xfff, 0xfff, 0xfff, 0x454, 0xfff, 0xfff, 0xfff,
1026 0x3f3, 0xfff, 0xfff, 0x187, 0xfff, 0x4a9, 0xfff, 0xfff,
1027 0xfff, 0xfff, 0xfff, 0xfff, 0x51c, 0x453, 0x1e6, 0xfff,
1028 0xfff, 0xfff, 0x1b0, 0xfff, 0x477, 0xfff, 0xfff, 0xfff,
1029 0x4fe, 0xfff, 0x32f, 0xfff, 0xfff, 0x15e, 0x1d4, 0xfff,
1030 0x0e5, 0xfff, 0xfff, 0xfff, 0x242, 0x14b, 0x046, 0xfff,
1031 0x3f6, 0x3bb, 0x3e4, 0xfff, 0xfff, 0x2e3, 0xfff, 0x245,
1032 0xfff, 0x149, 0xfff, 0xfff, 0xfff, 0x2db, 0xfff, 0xfff,
1033 0x181, 0xfff, 0x089, 0x2c5, 0xfff, 0x1f5, 0xfff, 0x2d6,
1034 0x507, 0xfff, 0x42d, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
1035 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
1036 0x080, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
1037 0xfff, 0xfff, 0xfff, 0xfff, 0x3c3, 0x320, 0xfff, 0x1e1,
1038 0xfff, 0x0f5, 0x13b, 0xfff, 0xfff, 0xfff, 0x003, 0x4da,
1039 0xfff, 0xfff, 0xfff, 0x42c, 0xfff, 0xfff, 0x0cb, 0xfff,
1040 0x536, 0x2c3, 0xfff, 0xfff, 0xfff, 0xfff, 0x199, 0xfff,
1041 0xfff, 0x0c0, 0xfff, 0x01e, 0x497, 0xfff, 0xfff, 0x3e5,
1042 0xfff, 0xfff, 0xfff, 0x0cf, 0xfff, 0x2bd, 0xfff, 0x223,
1043 0xfff, 0x3ff, 0xfff, 0x058, 0x174, 0x3ef, 0xfff, 0x002
1044};
1045
1046static unsigned short err_pos(unsigned short din)
1047{
1048 BUG_ON(din > 4096);
1049 return err_pos_lut[din];
1050}
1051static int chk_no_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1052{
1053 if ((chk_syndrome_list[0] | chk_syndrome_list[1] |
1054 chk_syndrome_list[2] | chk_syndrome_list[3] |
1055 chk_syndrome_list[4] | chk_syndrome_list[5] |
1056 chk_syndrome_list[6] | chk_syndrome_list[7]) != 0x0) {
1057 return -EINVAL;
1058 } else {
1059 err_info[0] = 0x0;
1060 return 0;
1061 }
1062}
1063static int chk_1_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1064{
1065 unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
1066 tmp0 = gf4096_mul(chk_syndrome_list[1], gf4096_inv(chk_syndrome_list[0]));
1067 tmp1 = gf4096_mul(chk_syndrome_list[2], gf4096_inv(chk_syndrome_list[1]));
1068 tmp2 = gf4096_mul(chk_syndrome_list[3], gf4096_inv(chk_syndrome_list[2]));
1069 tmp3 = gf4096_mul(chk_syndrome_list[4], gf4096_inv(chk_syndrome_list[3]));
1070 tmp4 = gf4096_mul(chk_syndrome_list[5], gf4096_inv(chk_syndrome_list[4]));
1071 tmp5 = gf4096_mul(chk_syndrome_list[6], gf4096_inv(chk_syndrome_list[5]));
1072 tmp6 = gf4096_mul(chk_syndrome_list[7], gf4096_inv(chk_syndrome_list[6]));
1073 if ((tmp0 == tmp1) & (tmp1 == tmp2) & (tmp2 == tmp3) & (tmp3 == tmp4) & (tmp4 == tmp5) & (tmp5 == tmp6)) {
1074 err_info[0] = 0x1; // encode 1-symbol error as 0x1
1075 err_info[1] = err_pos(tmp0);
1076 err_info[1] = (unsigned short)(0x55e - err_info[1]);
1077 err_info[5] = chk_syndrome_list[0];
1078 return 0;
1079 } else
1080 return -EINVAL;
1081}
1082static int chk_2_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1083{
1084 unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1085 unsigned short coefs[4];
1086 unsigned short err_pats[4];
1087 int found_num_root = 0;
1088 unsigned short bit2_root0, bit2_root1;
1089 unsigned short bit2_root0_inv, bit2_root1_inv;
1090 unsigned short err_loc_eqn, test_root;
1091 unsigned short bit2_loc0, bit2_loc1;
1092 unsigned short bit2_pat0, bit2_pat1;
1093
1094 find_2x2_soln(chk_syndrome_list[1],
1095 chk_syndrome_list[0],
1096 chk_syndrome_list[2], chk_syndrome_list[1], chk_syndrome_list[2], chk_syndrome_list[3], coefs);
1097 for (test_root = 0x1; test_root < 0xfff; test_root++) {
1098 err_loc_eqn =
1099 gf4096_mul(coefs[1], gf4096_mul(test_root, test_root)) ^ gf4096_mul(coefs[0], test_root) ^ 0x1;
1100 if (err_loc_eqn == 0x0) {
1101 if (found_num_root == 0) {
1102 bit2_root0 = test_root;
1103 found_num_root = 1;
1104 } else if (found_num_root == 1) {
1105 bit2_root1 = test_root;
1106 found_num_root = 2;
1107 break;
1108 }
1109 }
1110 }
1111 if (found_num_root != 2)
1112 return -EINVAL;
1113 else {
1114 bit2_root0_inv = gf4096_inv(bit2_root0);
1115 bit2_root1_inv = gf4096_inv(bit2_root1);
1116 find_2bit_err_pats(chk_syndrome_list[0],
1117 chk_syndrome_list[1], bit2_root0_inv, bit2_root1_inv, err_pats);
1118 bit2_pat0 = err_pats[0];
1119 bit2_pat1 = err_pats[1];
1120 //for(x+1)
1121 tmp0 = gf4096_mul(gf4096_mul(bit2_root0_inv, bit2_root0_inv), gf4096_mul(bit2_root0_inv, bit2_root0_inv)); //rinv0^4
1122 tmp1 = gf4096_mul(bit2_root0_inv, tmp0); //rinv0^5
1123 tmp2 = gf4096_mul(bit2_root0_inv, tmp1); //rinv0^6
1124 tmp3 = gf4096_mul(bit2_root0_inv, tmp2); //rinv0^7
1125 tmp4 = gf4096_mul(gf4096_mul(bit2_root1_inv, bit2_root1_inv), gf4096_mul(bit2_root1_inv, bit2_root1_inv)); //rinv1^4
1126 tmp5 = gf4096_mul(bit2_root1_inv, tmp4); //rinv1^5
1127 tmp6 = gf4096_mul(bit2_root1_inv, tmp5); //rinv1^6
1128 tmp7 = gf4096_mul(bit2_root1_inv, tmp6); //rinv1^7
1129 //check if only 2-bit error
1130 if ((chk_syndrome_list[4] ==
1131 (gf4096_mul(bit2_pat0, tmp0) ^
1132 gf4096_mul(bit2_pat1,
1133 tmp4))) & (chk_syndrome_list[5] ==
1134 (gf4096_mul(bit2_pat0, tmp1) ^
1135 gf4096_mul(bit2_pat1,
1136 tmp5))) &
1137 (chk_syndrome_list[6] ==
1138 (gf4096_mul(bit2_pat0, tmp2) ^
1139 gf4096_mul(bit2_pat1,
1140 tmp6))) & (chk_syndrome_list[7] ==
1141 (gf4096_mul(bit2_pat0, tmp3) ^ gf4096_mul(bit2_pat1, tmp7)))) {
1142 if ((err_pos(bit2_root0_inv) == 0xfff) | (err_pos(bit2_root1_inv) == 0xfff)) {
1143 return -EINVAL;
1144 } else {
1145 bit2_loc0 = 0x55e - err_pos(bit2_root0_inv);
1146 bit2_loc1 = 0x55e - err_pos(bit2_root1_inv);
1147 err_info[0] = 0x2; // encode 2-symbol error as 0x2
1148 err_info[1] = bit2_loc0;
1149 err_info[2] = bit2_loc1;
1150 err_info[5] = bit2_pat0;
1151 err_info[6] = bit2_pat1;
1152 return 0;
1153 }
1154 } else
1155 return -EINVAL;
1156 }
1157}
1158static int chk_3_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1159{
1160 unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
1161 unsigned short coefs[4];
1162 unsigned short err_pats[4];
1163 int found_num_root = 0;
1164 unsigned short bit3_root0, bit3_root1, bit3_root2;
1165 unsigned short bit3_root0_inv, bit3_root1_inv, bit3_root2_inv;
1166 unsigned short err_loc_eqn, test_root;
1167
1168 find_3bit_err_coefs(chk_syndrome_list[0], chk_syndrome_list[1],
1169 chk_syndrome_list[2], chk_syndrome_list[3],
1170 chk_syndrome_list[4], chk_syndrome_list[5], coefs);
1171
1172 for (test_root = 0x1; test_root < 0xfff; test_root++) {
1173 err_loc_eqn = gf4096_mul(coefs[2],
1174 gf4096_mul(gf4096_mul(test_root, test_root),
1175 test_root)) ^ gf4096_mul(coefs[1], gf4096_mul(test_root, test_root))
1176 ^ gf4096_mul(coefs[0], test_root) ^ 0x1;
1177
1178 if (err_loc_eqn == 0x0) {
1179 if (found_num_root == 0) {
1180 bit3_root0 = test_root;
1181 found_num_root = 1;
1182 } else if (found_num_root == 1) {
1183 bit3_root1 = test_root;
1184 found_num_root = 2;
1185 } else if (found_num_root == 2) {
1186 bit3_root2 = test_root;
1187 found_num_root = 3;
1188 break;
1189 }
1190 }
1191 }
1192 if (found_num_root != 3)
1193 return -EINVAL;
1194 else {
1195 bit3_root0_inv = gf4096_inv(bit3_root0);
1196 bit3_root1_inv = gf4096_inv(bit3_root1);
1197 bit3_root2_inv = gf4096_inv(bit3_root2);
1198
1199 find_3bit_err_pats(chk_syndrome_list[0], chk_syndrome_list[1],
1200 chk_syndrome_list[2], bit3_root0_inv,
1201 bit3_root1_inv, bit3_root2_inv, err_pats);
1202
1203 //check if only 3-bit error
1204 tmp0 = gf4096_mul(bit3_root0_inv, bit3_root0_inv);
1205 tmp0 = gf4096_mul(tmp0, tmp0);
1206 tmp0 = gf4096_mul(tmp0, bit3_root0_inv);
1207 tmp0 = gf4096_mul(tmp0, bit3_root0_inv); //rinv0^6
1208 tmp1 = gf4096_mul(tmp0, bit3_root0_inv); //rinv0^7
1209 tmp2 = gf4096_mul(bit3_root1_inv, bit3_root1_inv);
1210 tmp2 = gf4096_mul(tmp2, tmp2);
1211 tmp2 = gf4096_mul(tmp2, bit3_root1_inv);
1212 tmp2 = gf4096_mul(tmp2, bit3_root1_inv); //rinv1^6
1213 tmp3 = gf4096_mul(tmp2, bit3_root1_inv); //rinv1^7
1214 tmp4 = gf4096_mul(bit3_root2_inv, bit3_root2_inv);
1215 tmp4 = gf4096_mul(tmp4, tmp4);
1216 tmp4 = gf4096_mul(tmp4, bit3_root2_inv);
1217 tmp4 = gf4096_mul(tmp4, bit3_root2_inv); //rinv2^6
1218 tmp5 = gf4096_mul(tmp4, bit3_root2_inv); //rinv2^7
1219
1220 //check if only 3 errors
1221 if ((chk_syndrome_list[6] == (gf4096_mul(err_pats[0], tmp0) ^
1222 gf4096_mul(err_pats[1], tmp2) ^
1223 gf4096_mul(err_pats[2], tmp4))) &
1224 (chk_syndrome_list[7] == (gf4096_mul(err_pats[0], tmp1) ^
1225 gf4096_mul(err_pats[1], tmp3) ^ gf4096_mul(err_pats[2], tmp5)))) {
1226 if ((err_pos(bit3_root0_inv) == 0xfff) |
1227 (err_pos(bit3_root1_inv) == 0xfff) | (err_pos(bit3_root2_inv) == 0xfff)) {
1228 return -EINVAL;
1229 } else {
1230 err_info[0] = 0x3;
1231 err_info[1] = (0x55e - err_pos(bit3_root0_inv));
1232 err_info[2] = (0x55e - err_pos(bit3_root1_inv));
1233 err_info[3] = (0x55e - err_pos(bit3_root2_inv));
1234 err_info[5] = err_pats[0];
1235 err_info[6] = err_pats[1];
1236 err_info[7] = err_pats[2];
1237 return 0;
1238 }
1239 } else
1240 return -EINVAL;
1241 }
1242}
1243static int chk_4_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1244{
1245 unsigned short coefs[4];
1246 unsigned short err_pats[4];
1247 int found_num_root = 0;
1248 unsigned short bit4_root0, bit4_root1, bit4_root2, bit4_root3;
1249 unsigned short bit4_root0_inv, bit4_root1_inv, bit4_root2_inv, bit4_root3_inv;
1250 unsigned short err_loc_eqn, test_root;
1251
1252 find_4bit_err_coefs(chk_syndrome_list[0],
1253 chk_syndrome_list[1],
1254 chk_syndrome_list[2],
1255 chk_syndrome_list[3],
1256 chk_syndrome_list[4],
1257 chk_syndrome_list[5], chk_syndrome_list[6], chk_syndrome_list[7], coefs);
1258
1259 for (test_root = 0x1; test_root < 0xfff; test_root++) {
1260 err_loc_eqn =
1261 gf4096_mul(coefs[3],
1262 gf4096_mul(gf4096_mul
1263 (gf4096_mul(test_root, test_root),
1264 test_root),
1265 test_root)) ^ gf4096_mul(coefs[2],
1266 gf4096_mul
1267 (gf4096_mul(test_root, test_root), test_root))
1268 ^ gf4096_mul(coefs[1], gf4096_mul(test_root, test_root)) ^ gf4096_mul(coefs[0], test_root)
1269 ^ 0x1;
1270 if (err_loc_eqn == 0x0) {
1271 if (found_num_root == 0) {
1272 bit4_root0 = test_root;
1273 found_num_root = 1;
1274 } else if (found_num_root == 1) {
1275 bit4_root1 = test_root;
1276 found_num_root = 2;
1277 } else if (found_num_root == 2) {
1278 bit4_root2 = test_root;
1279 found_num_root = 3;
1280 } else {
1281 found_num_root = 4;
1282 bit4_root3 = test_root;
1283 break;
1284 }
1285 }
1286 }
1287 if (found_num_root != 4) {
1288 return -EINVAL;
1289 } else {
1290 bit4_root0_inv = gf4096_inv(bit4_root0);
1291 bit4_root1_inv = gf4096_inv(bit4_root1);
1292 bit4_root2_inv = gf4096_inv(bit4_root2);
1293 bit4_root3_inv = gf4096_inv(bit4_root3);
1294 find_4bit_err_pats(chk_syndrome_list[0],
1295 chk_syndrome_list[1],
1296 chk_syndrome_list[2],
1297 chk_syndrome_list[3],
1298 bit4_root0_inv, bit4_root1_inv, bit4_root2_inv, bit4_root3_inv, err_pats);
1299 err_info[0] = 0x4;
1300 err_info[1] = (0x55e - err_pos(bit4_root0_inv));
1301 err_info[2] = (0x55e - err_pos(bit4_root1_inv));
1302 err_info[3] = (0x55e - err_pos(bit4_root2_inv));
1303 err_info[4] = (0x55e - err_pos(bit4_root3_inv));
1304 err_info[5] = err_pats[0];
1305 err_info[6] = err_pats[1];
1306 err_info[7] = err_pats[2];
1307 err_info[8] = err_pats[3];
1308 return 0;
1309 }
1310}
1311
1312void correct_12bit_symbol(unsigned char *buf, unsigned short sym,
1313 unsigned short val)
1314{
1315 if (unlikely(sym > 1366)) {
1316 printk(KERN_ERR "Error: symbol %d out of range; cannot correct\n", sym);
1317 } else if (sym == 0) {
1318 buf[0] ^= val;
1319 } else if (sym & 1) {
1320 buf[1+(3*(sym-1))/2] ^= (val >> 4);
1321 buf[2+(3*(sym-1))/2] ^= ((val & 0xf) << 4);
1322 } else {
1323 buf[2+(3*(sym-2))/2] ^= (val >> 8);
1324 buf[3+(3*(sym-2))/2] ^= (val & 0xff);
1325 }
1326}
1327
1328static int debugecc = 0;
1329module_param(debugecc, int, 0644);
1330
1331int cafe_correct_ecc(unsigned char *buf,
1332 unsigned short *chk_syndrome_list)
1333{
1334 unsigned short err_info[9];
1335 int i;
1336
1337 if (debugecc) {
1338 printk(KERN_WARNING "cafe_correct_ecc invoked. Syndromes %x %x %x %x %x %x %x %x\n",
1339 chk_syndrome_list[0], chk_syndrome_list[1],
1340 chk_syndrome_list[2], chk_syndrome_list[3],
1341 chk_syndrome_list[4], chk_syndrome_list[5],
1342 chk_syndrome_list[6], chk_syndrome_list[7]);
1343 for (i=0; i < 2048; i+=16) {
1344 printk(KERN_WARNING "D %04x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
1345 i,
1346 buf[i], buf[i+1], buf[i+2], buf[i+3],
1347 buf[i+4], buf[i+5], buf[i+6], buf[i+7],
1348 buf[i+8], buf[i+9], buf[i+10], buf[i+11],
1349 buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
1350 }
1351 for ( ; i < 2112; i+=16) {
1352 printk(KERN_WARNING "O %02x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
1353 i - 2048,
1354 buf[i], buf[i+1], buf[i+2], buf[i+3],
1355 buf[i+4], buf[i+5], buf[i+6], buf[i+7],
1356 buf[i+8], buf[i+9], buf[i+10], buf[i+11],
1357 buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
1358 }
1359 }
1360
1361
1362
1363 if (chk_no_err_only(chk_syndrome_list, err_info) &&
1364 chk_1_err_only(chk_syndrome_list, err_info) &&
1365 chk_2_err_only(chk_syndrome_list, err_info) &&
1366 chk_3_err_only(chk_syndrome_list, err_info) &&
1367 chk_4_err_only(chk_syndrome_list, err_info)) {
1368 return -EIO;
1369 }
1370
1371 for (i=0; i < err_info[0]; i++) {
1372 if (debugecc)
1373 printk(KERN_WARNING "Correct symbol %d with 0x%03x\n",
1374 err_info[1+i], err_info[5+i]);
1375
1376 correct_12bit_symbol(buf, err_info[1+i], err_info[5+i]);
1377 }
1378
1379 return err_info[0];
1380}
1381
diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
index 94924d52a9..8296305c82 100644
--- a/drivers/mtd/nand/cs553x_nand.c
+++ b/drivers/mtd/nand/cs553x_nand.c
@@ -11,7 +11,7 @@
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12 * 12 *
13 * Overview: 13 * Overview:
14 * This is a device driver for the NAND flash controller found on 14 * This is a device driver for the NAND flash controller found on
15 * the AMD CS5535/CS5536 companion chipsets for the Geode processor. 15 * the AMD CS5535/CS5536 companion chipsets for the Geode processor.
16 * 16 *
17 */ 17 */
@@ -303,7 +303,7 @@ static int __init cs553x_init(void)
303 err = cs553x_init_one(i, !!(val & FLSH_MEM_IO), val & 0xFFFFFFFF); 303 err = cs553x_init_one(i, !!(val & FLSH_MEM_IO), val & 0xFFFFFFFF);
304 } 304 }
305 305
306 /* Register all devices together here. This means we can easily hack it to 306 /* Register all devices together here. This means we can easily hack it to
307 do mtdconcat etc. if we want to. */ 307 do mtdconcat etc. if we want to. */
308 for (i = 0; i < NR_CS553X_CONTROLLERS; i++) { 308 for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
309 if (cs553x_mtd[i]) { 309 if (cs553x_mtd[i]) {
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index 6107f53285..12608c13cc 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -1635,13 +1635,12 @@ static int __init doc_probe(unsigned long physadr)
1635 1635
1636 len = sizeof(struct mtd_info) + 1636 len = sizeof(struct mtd_info) +
1637 sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * sizeof(struct nand_bbt_descr)); 1637 sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * sizeof(struct nand_bbt_descr));
1638 mtd = kmalloc(len, GFP_KERNEL); 1638 mtd = kzalloc(len, GFP_KERNEL);
1639 if (!mtd) { 1639 if (!mtd) {
1640 printk(KERN_ERR "DiskOnChip kmalloc (%d bytes) failed!\n", len); 1640 printk(KERN_ERR "DiskOnChip kmalloc (%d bytes) failed!\n", len);
1641 ret = -ENOMEM; 1641 ret = -ENOMEM;
1642 goto fail; 1642 goto fail;
1643 } 1643 }
1644 memset(mtd, 0, len);
1645 1644
1646 nand = (struct nand_chip *) (mtd + 1); 1645 nand = (struct nand_chip *) (mtd + 1);
1647 doc = (struct doc_priv *) (nand + 1); 1646 doc = (struct doc_priv *) (nand + 1);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 41bfcae1fb..dfe56e03e4 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -362,7 +362,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
362 * access 362 * access
363 */ 363 */
364 ofs += mtd->oobsize; 364 ofs += mtd->oobsize;
365 chip->ops.len = 2; 365 chip->ops.len = chip->ops.ooblen = 2;
366 chip->ops.datbuf = NULL; 366 chip->ops.datbuf = NULL;
367 chip->ops.oobbuf = buf; 367 chip->ops.oobbuf = buf;
368 chip->ops.ooboffs = chip->badblockpos & ~0x01; 368 chip->ops.ooboffs = chip->badblockpos & ~0x01;
@@ -755,7 +755,7 @@ static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
755} 755}
756 756
757/** 757/**
758 * nand_read_page_swecc - {REPLACABLE] software ecc based page read function 758 * nand_read_page_swecc - [REPLACABLE] software ecc based page read function
759 * @mtd: mtd info structure 759 * @mtd: mtd info structure
760 * @chip: nand chip info structure 760 * @chip: nand chip info structure
761 * @buf: buffer to store read data 761 * @buf: buffer to store read data
@@ -795,7 +795,7 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
795} 795}
796 796
797/** 797/**
798 * nand_read_page_hwecc - {REPLACABLE] hardware ecc based page read function 798 * nand_read_page_hwecc - [REPLACABLE] hardware ecc based page read function
799 * @mtd: mtd info structure 799 * @mtd: mtd info structure
800 * @chip: nand chip info structure 800 * @chip: nand chip info structure
801 * @buf: buffer to store read data 801 * @buf: buffer to store read data
@@ -839,7 +839,7 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
839} 839}
840 840
841/** 841/**
842 * nand_read_page_syndrome - {REPLACABLE] hardware ecc syndrom based page read 842 * nand_read_page_syndrome - [REPLACABLE] hardware ecc syndrom based page read
843 * @mtd: mtd info structure 843 * @mtd: mtd info structure
844 * @chip: nand chip info structure 844 * @chip: nand chip info structure
845 * @buf: buffer to store read data 845 * @buf: buffer to store read data
@@ -897,12 +897,11 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
897 * @chip: nand chip structure 897 * @chip: nand chip structure
898 * @oob: oob destination address 898 * @oob: oob destination address
899 * @ops: oob ops structure 899 * @ops: oob ops structure
900 * @len: size of oob to transfer
900 */ 901 */
901static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, 902static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob,
902 struct mtd_oob_ops *ops) 903 struct mtd_oob_ops *ops, size_t len)
903{ 904{
904 size_t len = ops->ooblen;
905
906 switch(ops->mode) { 905 switch(ops->mode) {
907 906
908 case MTD_OOB_PLACE: 907 case MTD_OOB_PLACE:
@@ -960,6 +959,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
960 int sndcmd = 1; 959 int sndcmd = 1;
961 int ret = 0; 960 int ret = 0;
962 uint32_t readlen = ops->len; 961 uint32_t readlen = ops->len;
962 uint32_t oobreadlen = ops->ooblen;
963 uint8_t *bufpoi, *oob, *buf; 963 uint8_t *bufpoi, *oob, *buf;
964 964
965 stats = mtd->ecc_stats; 965 stats = mtd->ecc_stats;
@@ -971,7 +971,6 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
971 page = realpage & chip->pagemask; 971 page = realpage & chip->pagemask;
972 972
973 col = (int)(from & (mtd->writesize - 1)); 973 col = (int)(from & (mtd->writesize - 1));
974 chip->oob_poi = chip->buffers->oobrbuf;
975 974
976 buf = ops->datbuf; 975 buf = ops->datbuf;
977 oob = ops->oobbuf; 976 oob = ops->oobbuf;
@@ -1007,10 +1006,17 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1007 1006
1008 if (unlikely(oob)) { 1007 if (unlikely(oob)) {
1009 /* Raw mode does data:oob:data:oob */ 1008 /* Raw mode does data:oob:data:oob */
1010 if (ops->mode != MTD_OOB_RAW) 1009 if (ops->mode != MTD_OOB_RAW) {
1011 oob = nand_transfer_oob(chip, oob, ops); 1010 int toread = min(oobreadlen,
1012 else 1011 chip->ecc.layout->oobavail);
1013 buf = nand_transfer_oob(chip, buf, ops); 1012 if (toread) {
1013 oob = nand_transfer_oob(chip,
1014 oob, ops, toread);
1015 oobreadlen -= toread;
1016 }
1017 } else
1018 buf = nand_transfer_oob(chip,
1019 buf, ops, mtd->oobsize);
1014 } 1020 }
1015 1021
1016 if (!(chip->options & NAND_NO_READRDY)) { 1022 if (!(chip->options & NAND_NO_READRDY)) {
@@ -1057,6 +1063,8 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1057 } 1063 }
1058 1064
1059 ops->retlen = ops->len - (size_t) readlen; 1065 ops->retlen = ops->len - (size_t) readlen;
1066 if (oob)
1067 ops->oobretlen = ops->ooblen - oobreadlen;
1060 1068
1061 if (ret) 1069 if (ret)
1062 return ret; 1070 return ret;
@@ -1257,12 +1265,18 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1257 int page, realpage, chipnr, sndcmd = 1; 1265 int page, realpage, chipnr, sndcmd = 1;
1258 struct nand_chip *chip = mtd->priv; 1266 struct nand_chip *chip = mtd->priv;
1259 int blkcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1; 1267 int blkcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1;
1260 int readlen = ops->len; 1268 int readlen = ops->ooblen;
1269 int len;
1261 uint8_t *buf = ops->oobbuf; 1270 uint8_t *buf = ops->oobbuf;
1262 1271
1263 DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08Lx, len = %i\n", 1272 DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08Lx, len = %i\n",
1264 (unsigned long long)from, readlen); 1273 (unsigned long long)from, readlen);
1265 1274
1275 if (ops->mode == MTD_OOB_RAW)
1276 len = mtd->oobsize;
1277 else
1278 len = chip->ecc.layout->oobavail;
1279
1266 chipnr = (int)(from >> chip->chip_shift); 1280 chipnr = (int)(from >> chip->chip_shift);
1267 chip->select_chip(mtd, chipnr); 1281 chip->select_chip(mtd, chipnr);
1268 1282
@@ -1270,11 +1284,11 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1270 realpage = (int)(from >> chip->page_shift); 1284 realpage = (int)(from >> chip->page_shift);
1271 page = realpage & chip->pagemask; 1285 page = realpage & chip->pagemask;
1272 1286
1273 chip->oob_poi = chip->buffers->oobrbuf;
1274
1275 while(1) { 1287 while(1) {
1276 sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd); 1288 sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd);
1277 buf = nand_transfer_oob(chip, buf, ops); 1289
1290 len = min(len, readlen);
1291 buf = nand_transfer_oob(chip, buf, ops, len);
1278 1292
1279 if (!(chip->options & NAND_NO_READRDY)) { 1293 if (!(chip->options & NAND_NO_READRDY)) {
1280 /* 1294 /*
@@ -1289,7 +1303,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1289 nand_wait_ready(mtd); 1303 nand_wait_ready(mtd);
1290 } 1304 }
1291 1305
1292 readlen -= ops->ooblen; 1306 readlen -= len;
1293 if (!readlen) 1307 if (!readlen)
1294 break; 1308 break;
1295 1309
@@ -1311,7 +1325,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1311 sndcmd = 1; 1325 sndcmd = 1;
1312 } 1326 }
1313 1327
1314 ops->retlen = ops->len; 1328 ops->oobretlen = ops->ooblen;
1315 return 0; 1329 return 0;
1316} 1330}
1317 1331
@@ -1332,7 +1346,7 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from,
1332 ops->retlen = 0; 1346 ops->retlen = 0;
1333 1347
1334 /* Do not allow reads past end of device */ 1348 /* Do not allow reads past end of device */
1335 if ((from + ops->len) > mtd->size) { 1349 if (ops->datbuf && (from + ops->len) > mtd->size) {
1336 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: " 1350 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1337 "Attempt read beyond end of device\n"); 1351 "Attempt read beyond end of device\n");
1338 return -EINVAL; 1352 return -EINVAL;
@@ -1375,7 +1389,7 @@ static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1375} 1389}
1376 1390
1377/** 1391/**
1378 * nand_write_page_swecc - {REPLACABLE] software ecc based page write function 1392 * nand_write_page_swecc - [REPLACABLE] software ecc based page write function
1379 * @mtd: mtd info structure 1393 * @mtd: mtd info structure
1380 * @chip: nand chip info structure 1394 * @chip: nand chip info structure
1381 * @buf: data buffer 1395 * @buf: data buffer
@@ -1401,7 +1415,7 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1401} 1415}
1402 1416
1403/** 1417/**
1404 * nand_write_page_hwecc - {REPLACABLE] hardware ecc based page write function 1418 * nand_write_page_hwecc - [REPLACABLE] hardware ecc based page write function
1405 * @mtd: mtd info structure 1419 * @mtd: mtd info structure
1406 * @chip: nand chip info structure 1420 * @chip: nand chip info structure
1407 * @buf: data buffer 1421 * @buf: data buffer
@@ -1429,7 +1443,7 @@ static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1429} 1443}
1430 1444
1431/** 1445/**
1432 * nand_write_page_syndrome - {REPLACABLE] hardware ecc syndrom based page write 1446 * nand_write_page_syndrome - [REPLACABLE] hardware ecc syndrom based page write
1433 * @mtd: mtd info structure 1447 * @mtd: mtd info structure
1434 * @chip: nand chip info structure 1448 * @chip: nand chip info structure
1435 * @buf: data buffer 1449 * @buf: data buffer
@@ -1577,7 +1591,7 @@ static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob,
1577 return NULL; 1591 return NULL;
1578} 1592}
1579 1593
1580#define NOTALIGNED(x) (x & (mtd->writesize-1)) != 0 1594#define NOTALIGNED(x) (x & (chip->subpagesize - 1)) != 0
1581 1595
1582/** 1596/**
1583 * nand_do_write_ops - [Internal] NAND write with ECC 1597 * nand_do_write_ops - [Internal] NAND write with ECC
@@ -1590,15 +1604,16 @@ static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob,
1590static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, 1604static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1591 struct mtd_oob_ops *ops) 1605 struct mtd_oob_ops *ops)
1592{ 1606{
1593 int chipnr, realpage, page, blockmask; 1607 int chipnr, realpage, page, blockmask, column;
1594 struct nand_chip *chip = mtd->priv; 1608 struct nand_chip *chip = mtd->priv;
1595 uint32_t writelen = ops->len; 1609 uint32_t writelen = ops->len;
1596 uint8_t *oob = ops->oobbuf; 1610 uint8_t *oob = ops->oobbuf;
1597 uint8_t *buf = ops->datbuf; 1611 uint8_t *buf = ops->datbuf;
1598 int bytes = mtd->writesize; 1612 int ret, subpage;
1599 int ret;
1600 1613
1601 ops->retlen = 0; 1614 ops->retlen = 0;
1615 if (!writelen)
1616 return 0;
1602 1617
1603 /* reject writes, which are not page aligned */ 1618 /* reject writes, which are not page aligned */
1604 if (NOTALIGNED(to) || NOTALIGNED(ops->len)) { 1619 if (NOTALIGNED(to) || NOTALIGNED(ops->len)) {
@@ -1607,8 +1622,11 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1607 return -EINVAL; 1622 return -EINVAL;
1608 } 1623 }
1609 1624
1610 if (!writelen) 1625 column = to & (mtd->writesize - 1);
1611 return 0; 1626 subpage = column || (writelen & (mtd->writesize - 1));
1627
1628 if (subpage && oob)
1629 return -EINVAL;
1612 1630
1613 chipnr = (int)(to >> chip->chip_shift); 1631 chipnr = (int)(to >> chip->chip_shift);
1614 chip->select_chip(mtd, chipnr); 1632 chip->select_chip(mtd, chipnr);
@@ -1626,15 +1644,29 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1626 (chip->pagebuf << chip->page_shift) < (to + ops->len)) 1644 (chip->pagebuf << chip->page_shift) < (to + ops->len))
1627 chip->pagebuf = -1; 1645 chip->pagebuf = -1;
1628 1646
1629 chip->oob_poi = chip->buffers->oobwbuf; 1647 /* If we're not given explicit OOB data, let it be 0xFF */
1648 if (likely(!oob))
1649 memset(chip->oob_poi, 0xff, mtd->oobsize);
1630 1650
1631 while(1) { 1651 while(1) {
1652 int bytes = mtd->writesize;
1632 int cached = writelen > bytes && page != blockmask; 1653 int cached = writelen > bytes && page != blockmask;
1654 uint8_t *wbuf = buf;
1655
1656 /* Partial page write ? */
1657 if (unlikely(column || writelen < (mtd->writesize - 1))) {
1658 cached = 0;
1659 bytes = min_t(int, bytes - column, (int) writelen);
1660 chip->pagebuf = -1;
1661 memset(chip->buffers->databuf, 0xff, mtd->writesize);
1662 memcpy(&chip->buffers->databuf[column], buf, bytes);
1663 wbuf = chip->buffers->databuf;
1664 }
1633 1665
1634 if (unlikely(oob)) 1666 if (unlikely(oob))
1635 oob = nand_fill_oob(chip, oob, ops); 1667 oob = nand_fill_oob(chip, oob, ops);
1636 1668
1637 ret = chip->write_page(mtd, chip, buf, page, cached, 1669 ret = chip->write_page(mtd, chip, wbuf, page, cached,
1638 (ops->mode == MTD_OOB_RAW)); 1670 (ops->mode == MTD_OOB_RAW));
1639 if (ret) 1671 if (ret)
1640 break; 1672 break;
@@ -1643,6 +1675,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1643 if (!writelen) 1675 if (!writelen)
1644 break; 1676 break;
1645 1677
1678 column = 0;
1646 buf += bytes; 1679 buf += bytes;
1647 realpage++; 1680 realpage++;
1648 1681
@@ -1655,10 +1688,9 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1655 } 1688 }
1656 } 1689 }
1657 1690
1658 if (unlikely(oob))
1659 memset(chip->oob_poi, 0xff, mtd->oobsize);
1660
1661 ops->retlen = ops->len - writelen; 1691 ops->retlen = ops->len - writelen;
1692 if (unlikely(oob))
1693 ops->oobretlen = ops->ooblen;
1662 return ret; 1694 return ret;
1663} 1695}
1664 1696
@@ -1714,10 +1746,10 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1714 struct nand_chip *chip = mtd->priv; 1746 struct nand_chip *chip = mtd->priv;
1715 1747
1716 DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", 1748 DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n",
1717 (unsigned int)to, (int)ops->len); 1749 (unsigned int)to, (int)ops->ooblen);
1718 1750
1719 /* Do not allow write past end of page */ 1751 /* Do not allow write past end of page */
1720 if ((ops->ooboffs + ops->len) > mtd->oobsize) { 1752 if ((ops->ooboffs + ops->ooblen) > mtd->oobsize) {
1721 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: " 1753 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: "
1722 "Attempt to write past end of page\n"); 1754 "Attempt to write past end of page\n");
1723 return -EINVAL; 1755 return -EINVAL;
@@ -1745,7 +1777,6 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1745 if (page == chip->pagebuf) 1777 if (page == chip->pagebuf)
1746 chip->pagebuf = -1; 1778 chip->pagebuf = -1;
1747 1779
1748 chip->oob_poi = chip->buffers->oobwbuf;
1749 memset(chip->oob_poi, 0xff, mtd->oobsize); 1780 memset(chip->oob_poi, 0xff, mtd->oobsize);
1750 nand_fill_oob(chip, ops->oobbuf, ops); 1781 nand_fill_oob(chip, ops->oobbuf, ops);
1751 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); 1782 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask);
@@ -1754,7 +1785,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1754 if (status) 1785 if (status)
1755 return status; 1786 return status;
1756 1787
1757 ops->retlen = ops->len; 1788 ops->oobretlen = ops->ooblen;
1758 1789
1759 return 0; 1790 return 0;
1760} 1791}
@@ -1774,7 +1805,7 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
1774 ops->retlen = 0; 1805 ops->retlen = 0;
1775 1806
1776 /* Do not allow writes past end of device */ 1807 /* Do not allow writes past end of device */
1777 if ((to + ops->len) > mtd->size) { 1808 if (ops->datbuf && (to + ops->len) > mtd->size) {
1778 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: " 1809 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1779 "Attempt read beyond end of device\n"); 1810 "Attempt read beyond end of device\n");
1780 return -EINVAL; 1811 return -EINVAL;
@@ -2188,8 +2219,8 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2188 /* Newer devices have all the information in additional id bytes */ 2219 /* Newer devices have all the information in additional id bytes */
2189 if (!type->pagesize) { 2220 if (!type->pagesize) {
2190 int extid; 2221 int extid;
2191 /* The 3rd id byte contains non relevant data ATM */ 2222 /* The 3rd id byte holds MLC / multichip data */
2192 extid = chip->read_byte(mtd); 2223 chip->cellinfo = chip->read_byte(mtd);
2193 /* The 4th id byte is the important one */ 2224 /* The 4th id byte is the important one */
2194 extid = chip->read_byte(mtd); 2225 extid = chip->read_byte(mtd);
2195 /* Calc pagesize */ 2226 /* Calc pagesize */
@@ -2349,8 +2380,8 @@ int nand_scan_tail(struct mtd_info *mtd)
2349 if (!chip->buffers) 2380 if (!chip->buffers)
2350 return -ENOMEM; 2381 return -ENOMEM;
2351 2382
2352 /* Preset the internal oob write buffer */ 2383 /* Set the internal oob buffer location, just after the page data */
2353 memset(chip->buffers->oobwbuf, 0xff, mtd->oobsize); 2384 chip->oob_poi = chip->buffers->databuf + mtd->writesize;
2354 2385
2355 /* 2386 /*
2356 * If no default placement scheme is given, select an appropriate one 2387 * If no default placement scheme is given, select an appropriate one
@@ -2469,6 +2500,24 @@ int nand_scan_tail(struct mtd_info *mtd)
2469 } 2500 }
2470 chip->ecc.total = chip->ecc.steps * chip->ecc.bytes; 2501 chip->ecc.total = chip->ecc.steps * chip->ecc.bytes;
2471 2502
2503 /*
2504 * Allow subpage writes up to ecc.steps. Not possible for MLC
2505 * FLASH.
2506 */
2507 if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
2508 !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) {
2509 switch(chip->ecc.steps) {
2510 case 2:
2511 mtd->subpage_sft = 1;
2512 break;
2513 case 4:
2514 case 8:
2515 mtd->subpage_sft = 2;
2516 break;
2517 }
2518 }
2519 chip->subpagesize = mtd->writesize >> mtd->subpage_sft;
2520
2472 /* Initialize state */ 2521 /* Initialize state */
2473 chip->state = FL_READY; 2522 chip->state = FL_READY;
2474 2523
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 9402653eb0..5e121ceaa5 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -333,7 +333,6 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd,
333 struct mtd_oob_ops ops; 333 struct mtd_oob_ops ops;
334 int j, ret; 334 int j, ret;
335 335
336 ops.len = mtd->oobsize;
337 ops.ooblen = mtd->oobsize; 336 ops.ooblen = mtd->oobsize;
338 ops.oobbuf = buf; 337 ops.oobbuf = buf;
339 ops.ooboffs = 0; 338 ops.ooboffs = 0;
@@ -676,10 +675,10 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
676 "bad block table\n"); 675 "bad block table\n");
677 } 676 }
678 /* Read oob data */ 677 /* Read oob data */
679 ops.len = (len >> this->page_shift) * mtd->oobsize; 678 ops.ooblen = (len >> this->page_shift) * mtd->oobsize;
680 ops.oobbuf = &buf[len]; 679 ops.oobbuf = &buf[len];
681 res = mtd->read_oob(mtd, to + mtd->writesize, &ops); 680 res = mtd->read_oob(mtd, to + mtd->writesize, &ops);
682 if (res < 0 || ops.retlen != ops.len) 681 if (res < 0 || ops.oobretlen != ops.ooblen)
683 goto outerr; 682 goto outerr;
684 683
685 /* Calc the byte offset in the buffer */ 684 /* Calc the byte offset in the buffer */
@@ -961,14 +960,12 @@ int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
961 struct nand_bbt_descr *md = this->bbt_md; 960 struct nand_bbt_descr *md = this->bbt_md;
962 961
963 len = mtd->size >> (this->bbt_erase_shift + 2); 962 len = mtd->size >> (this->bbt_erase_shift + 2);
964 /* Allocate memory (2bit per block) */ 963 /* Allocate memory (2bit per block) and clear the memory bad block table */
965 this->bbt = kmalloc(len, GFP_KERNEL); 964 this->bbt = kzalloc(len, GFP_KERNEL);
966 if (!this->bbt) { 965 if (!this->bbt) {
967 printk(KERN_ERR "nand_scan_bbt: Out of memory\n"); 966 printk(KERN_ERR "nand_scan_bbt: Out of memory\n");
968 return -ENOMEM; 967 return -ENOMEM;
969 } 968 }
970 /* Clear the memory bad block table */
971 memset(this->bbt, 0x00, len);
972 969
973 /* If no primary table decriptor is given, scan the device 970 /* If no primary table decriptor is given, scan the device
974 * to build a memory based bad block table 971 * to build a memory based bad block table
diff --git a/drivers/mtd/nand/nand_ecc.c b/drivers/mtd/nand/nand_ecc.c
index dd438ca47d..fde593e5e6 100644
--- a/drivers/mtd/nand/nand_ecc.c
+++ b/drivers/mtd/nand/nand_ecc.c
@@ -112,7 +112,7 @@ int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
112 tmp2 |= (reg2 & 0x01) << 0; /* B7 -> B0 */ 112 tmp2 |= (reg2 & 0x01) << 0; /* B7 -> B0 */
113 113
114 /* Calculate final ECC code */ 114 /* Calculate final ECC code */
115#ifdef CONFIG_NAND_ECC_SMC 115#ifdef CONFIG_MTD_NAND_ECC_SMC
116 ecc_code[0] = ~tmp2; 116 ecc_code[0] = ~tmp2;
117 ecc_code[1] = ~tmp1; 117 ecc_code[1] = ~tmp1;
118#else 118#else
@@ -148,7 +148,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat,
148{ 148{
149 uint8_t s0, s1, s2; 149 uint8_t s0, s1, s2;
150 150
151#ifdef CONFIG_NAND_ECC_SMC 151#ifdef CONFIG_MTD_NAND_ECC_SMC
152 s0 = calc_ecc[0] ^ read_ecc[0]; 152 s0 = calc_ecc[0] ^ read_ecc[0];
153 s1 = calc_ecc[1] ^ read_ecc[1]; 153 s1 = calc_ecc[1] ^ read_ecc[1];
154 s2 = calc_ecc[2] ^ read_ecc[2]; 154 s2 = calc_ecc[2] ^ read_ecc[2];
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 545ff252d8..c3bca9590a 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -37,10 +37,6 @@
37#include <linux/mtd/nand.h> 37#include <linux/mtd/nand.h>
38#include <linux/mtd/partitions.h> 38#include <linux/mtd/partitions.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#ifdef CONFIG_NS_ABS_POS
41#include <asm/io.h>
42#endif
43
44 40
45/* Default simulator parameters values */ 41/* Default simulator parameters values */
46#if !defined(CONFIG_NANDSIM_FIRST_ID_BYTE) || \ 42#if !defined(CONFIG_NANDSIM_FIRST_ID_BYTE) || \
@@ -164,7 +160,7 @@ MODULE_PARM_DESC(dbg, "Output debug information if not zero");
164/* After a command is input, the simulator goes to one of the following states */ 160/* After a command is input, the simulator goes to one of the following states */
165#define STATE_CMD_READ0 0x00000001 /* read data from the beginning of page */ 161#define STATE_CMD_READ0 0x00000001 /* read data from the beginning of page */
166#define STATE_CMD_READ1 0x00000002 /* read data from the second half of page */ 162#define STATE_CMD_READ1 0x00000002 /* read data from the second half of page */
167#define STATE_CMD_READSTART 0x00000003 /* read data second command (large page devices) */ 163#define STATE_CMD_READSTART 0x00000003 /* read data second command (large page devices) */
168#define STATE_CMD_PAGEPROG 0x00000004 /* start page programm */ 164#define STATE_CMD_PAGEPROG 0x00000004 /* start page programm */
169#define STATE_CMD_READOOB 0x00000005 /* read OOB area */ 165#define STATE_CMD_READOOB 0x00000005 /* read OOB area */
170#define STATE_CMD_ERASE1 0x00000006 /* sector erase first command */ 166#define STATE_CMD_ERASE1 0x00000006 /* sector erase first command */
@@ -231,6 +227,14 @@ MODULE_PARM_DESC(dbg, "Output debug information if not zero");
231#define NS_MAX_PREVSTATES 1 227#define NS_MAX_PREVSTATES 1
232 228
233/* 229/*
230 * A union to represent flash memory contents and flash buffer.
231 */
232union ns_mem {
233 u_char *byte; /* for byte access */
234 uint16_t *word; /* for 16-bit word access */
235};
236
237/*
234 * The structure which describes all the internal simulator data. 238 * The structure which describes all the internal simulator data.
235 */ 239 */
236struct nandsim { 240struct nandsim {
@@ -247,17 +251,11 @@ struct nandsim {
247 uint16_t npstates; /* number of previous states saved */ 251 uint16_t npstates; /* number of previous states saved */
248 uint16_t stateidx; /* current state index */ 252 uint16_t stateidx; /* current state index */
249 253
250 /* The simulated NAND flash image */ 254 /* The simulated NAND flash pages array */
251 union flash_media { 255 union ns_mem *pages;
252 u_char *byte;
253 uint16_t *word;
254 } mem;
255 256
256 /* Internal buffer of page + OOB size bytes */ 257 /* Internal buffer of page + OOB size bytes */
257 union internal_buffer { 258 union ns_mem buf;
258 u_char *byte; /* for byte access */
259 uint16_t *word; /* for 16-bit word access */
260 } buf;
261 259
262 /* NAND flash "geometry" */ 260 /* NAND flash "geometry" */
263 struct nandsin_geometry { 261 struct nandsin_geometry {
@@ -346,12 +344,49 @@ static struct mtd_info *nsmtd;
346static u_char ns_verify_buf[NS_LARGEST_PAGE_SIZE]; 344static u_char ns_verify_buf[NS_LARGEST_PAGE_SIZE];
347 345
348/* 346/*
347 * Allocate array of page pointers and initialize the array to NULL
348 * pointers.
349 *
350 * RETURNS: 0 if success, -ENOMEM if memory alloc fails.
351 */
352static int alloc_device(struct nandsim *ns)
353{
354 int i;
355
356 ns->pages = vmalloc(ns->geom.pgnum * sizeof(union ns_mem));
357 if (!ns->pages) {
358 NS_ERR("alloc_map: unable to allocate page array\n");
359 return -ENOMEM;
360 }
361 for (i = 0; i < ns->geom.pgnum; i++) {
362 ns->pages[i].byte = NULL;
363 }
364
365 return 0;
366}
367
368/*
369 * Free any allocated pages, and free the array of page pointers.
370 */
371static void free_device(struct nandsim *ns)
372{
373 int i;
374
375 if (ns->pages) {
376 for (i = 0; i < ns->geom.pgnum; i++) {
377 if (ns->pages[i].byte)
378 kfree(ns->pages[i].byte);
379 }
380 vfree(ns->pages);
381 }
382}
383
384/*
349 * Initialize the nandsim structure. 385 * Initialize the nandsim structure.
350 * 386 *
351 * RETURNS: 0 if success, -ERRNO if failure. 387 * RETURNS: 0 if success, -ERRNO if failure.
352 */ 388 */
353static int 389static int init_nandsim(struct mtd_info *mtd)
354init_nandsim(struct mtd_info *mtd)
355{ 390{
356 struct nand_chip *chip = (struct nand_chip *)mtd->priv; 391 struct nand_chip *chip = (struct nand_chip *)mtd->priv;
357 struct nandsim *ns = (struct nandsim *)(chip->priv); 392 struct nandsim *ns = (struct nandsim *)(chip->priv);
@@ -405,7 +440,7 @@ init_nandsim(struct mtd_info *mtd)
405 } 440 }
406 } else { 441 } else {
407 if (ns->geom.totsz <= (128 << 20)) { 442 if (ns->geom.totsz <= (128 << 20)) {
408 ns->geom.pgaddrbytes = 5; 443 ns->geom.pgaddrbytes = 4;
409 ns->geom.secaddrbytes = 2; 444 ns->geom.secaddrbytes = 2;
410 } else { 445 } else {
411 ns->geom.pgaddrbytes = 5; 446 ns->geom.pgaddrbytes = 5;
@@ -439,23 +474,8 @@ init_nandsim(struct mtd_info *mtd)
439 printk("sector address bytes: %u\n", ns->geom.secaddrbytes); 474 printk("sector address bytes: %u\n", ns->geom.secaddrbytes);
440 printk("options: %#x\n", ns->options); 475 printk("options: %#x\n", ns->options);
441 476
442 /* Map / allocate and initialize the flash image */ 477 if (alloc_device(ns) != 0)
443#ifdef CONFIG_NS_ABS_POS 478 goto error;
444 ns->mem.byte = ioremap(CONFIG_NS_ABS_POS, ns->geom.totszoob);
445 if (!ns->mem.byte) {
446 NS_ERR("init_nandsim: failed to map the NAND flash image at address %p\n",
447 (void *)CONFIG_NS_ABS_POS);
448 return -ENOMEM;
449 }
450#else
451 ns->mem.byte = vmalloc(ns->geom.totszoob);
452 if (!ns->mem.byte) {
453 NS_ERR("init_nandsim: unable to allocate %u bytes for flash image\n",
454 ns->geom.totszoob);
455 return -ENOMEM;
456 }
457 memset(ns->mem.byte, 0xFF, ns->geom.totszoob);
458#endif
459 479
460 /* Allocate / initialize the internal buffer */ 480 /* Allocate / initialize the internal buffer */
461 ns->buf.byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL); 481 ns->buf.byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL);
@@ -474,11 +494,7 @@ init_nandsim(struct mtd_info *mtd)
474 return 0; 494 return 0;
475 495
476error: 496error:
477#ifdef CONFIG_NS_ABS_POS 497 free_device(ns);
478 iounmap(ns->mem.byte);
479#else
480 vfree(ns->mem.byte);
481#endif
482 498
483 return -ENOMEM; 499 return -ENOMEM;
484} 500}
@@ -486,16 +502,10 @@ error:
486/* 502/*
487 * Free the nandsim structure. 503 * Free the nandsim structure.
488 */ 504 */
489static void 505static void free_nandsim(struct nandsim *ns)
490free_nandsim(struct nandsim *ns)
491{ 506{
492 kfree(ns->buf.byte); 507 kfree(ns->buf.byte);
493 508 free_device(ns);
494#ifdef CONFIG_NS_ABS_POS
495 iounmap(ns->mem.byte);
496#else
497 vfree(ns->mem.byte);
498#endif
499 509
500 return; 510 return;
501} 511}
@@ -503,8 +513,7 @@ free_nandsim(struct nandsim *ns)
503/* 513/*
504 * Returns the string representation of 'state' state. 514 * Returns the string representation of 'state' state.
505 */ 515 */
506static char * 516static char *get_state_name(uint32_t state)
507get_state_name(uint32_t state)
508{ 517{
509 switch (NS_STATE(state)) { 518 switch (NS_STATE(state)) {
510 case STATE_CMD_READ0: 519 case STATE_CMD_READ0:
@@ -562,8 +571,7 @@ get_state_name(uint32_t state)
562 * 571 *
563 * RETURNS: 1 if wrong command, 0 if right. 572 * RETURNS: 1 if wrong command, 0 if right.
564 */ 573 */
565static int 574static int check_command(int cmd)
566check_command(int cmd)
567{ 575{
568 switch (cmd) { 576 switch (cmd) {
569 577
@@ -589,8 +597,7 @@ check_command(int cmd)
589/* 597/*
590 * Returns state after command is accepted by command number. 598 * Returns state after command is accepted by command number.
591 */ 599 */
592static uint32_t 600static uint32_t get_state_by_command(unsigned command)
593get_state_by_command(unsigned command)
594{ 601{
595 switch (command) { 602 switch (command) {
596 case NAND_CMD_READ0: 603 case NAND_CMD_READ0:
@@ -626,8 +633,7 @@ get_state_by_command(unsigned command)
626/* 633/*
627 * Move an address byte to the correspondent internal register. 634 * Move an address byte to the correspondent internal register.
628 */ 635 */
629static inline void 636static inline void accept_addr_byte(struct nandsim *ns, u_char bt)
630accept_addr_byte(struct nandsim *ns, u_char bt)
631{ 637{
632 uint byte = (uint)bt; 638 uint byte = (uint)bt;
633 639
@@ -645,8 +651,7 @@ accept_addr_byte(struct nandsim *ns, u_char bt)
645/* 651/*
646 * Switch to STATE_READY state. 652 * Switch to STATE_READY state.
647 */ 653 */
648static inline void 654static inline void switch_to_ready_state(struct nandsim *ns, u_char status)
649switch_to_ready_state(struct nandsim *ns, u_char status)
650{ 655{
651 NS_DBG("switch_to_ready_state: switch to %s state\n", get_state_name(STATE_READY)); 656 NS_DBG("switch_to_ready_state: switch to %s state\n", get_state_name(STATE_READY));
652 657
@@ -705,8 +710,7 @@ switch_to_ready_state(struct nandsim *ns, u_char status)
705 * -1 - several matches. 710 * -1 - several matches.
706 * 0 - operation is found. 711 * 0 - operation is found.
707 */ 712 */
708static int 713static int find_operation(struct nandsim *ns, uint32_t flag)
709find_operation(struct nandsim *ns, uint32_t flag)
710{ 714{
711 int opsfound = 0; 715 int opsfound = 0;
712 int i, j, idx = 0; 716 int i, j, idx = 0;
@@ -791,14 +795,93 @@ find_operation(struct nandsim *ns, uint32_t flag)
791} 795}
792 796
793/* 797/*
798 * Returns a pointer to the current page.
799 */
800static inline union ns_mem *NS_GET_PAGE(struct nandsim *ns)
801{
802 return &(ns->pages[ns->regs.row]);
803}
804
805/*
806 * Retuns a pointer to the current byte, within the current page.
807 */
808static inline u_char *NS_PAGE_BYTE_OFF(struct nandsim *ns)
809{
810 return NS_GET_PAGE(ns)->byte + ns->regs.column + ns->regs.off;
811}
812
813/*
814 * Fill the NAND buffer with data read from the specified page.
815 */
816static void read_page(struct nandsim *ns, int num)
817{
818 union ns_mem *mypage;
819
820 mypage = NS_GET_PAGE(ns);
821 if (mypage->byte == NULL) {
822 NS_DBG("read_page: page %d not allocated\n", ns->regs.row);
823 memset(ns->buf.byte, 0xFF, num);
824 } else {
825 NS_DBG("read_page: page %d allocated, reading from %d\n",
826 ns->regs.row, ns->regs.column + ns->regs.off);
827 memcpy(ns->buf.byte, NS_PAGE_BYTE_OFF(ns), num);
828 }
829}
830
831/*
832 * Erase all pages in the specified sector.
833 */
834static void erase_sector(struct nandsim *ns)
835{
836 union ns_mem *mypage;
837 int i;
838
839 mypage = NS_GET_PAGE(ns);
840 for (i = 0; i < ns->geom.pgsec; i++) {
841 if (mypage->byte != NULL) {
842 NS_DBG("erase_sector: freeing page %d\n", ns->regs.row+i);
843 kfree(mypage->byte);
844 mypage->byte = NULL;
845 }
846 mypage++;
847 }
848}
849
850/*
851 * Program the specified page with the contents from the NAND buffer.
852 */
853static int prog_page(struct nandsim *ns, int num)
854{
855 int i;
856 union ns_mem *mypage;
857 u_char *pg_off;
858
859 mypage = NS_GET_PAGE(ns);
860 if (mypage->byte == NULL) {
861 NS_DBG("prog_page: allocating page %d\n", ns->regs.row);
862 mypage->byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL);
863 if (mypage->byte == NULL) {
864 NS_ERR("prog_page: error allocating memory for page %d\n", ns->regs.row);
865 return -1;
866 }
867 memset(mypage->byte, 0xFF, ns->geom.pgszoob);
868 }
869
870 pg_off = NS_PAGE_BYTE_OFF(ns);
871 for (i = 0; i < num; i++)
872 pg_off[i] &= ns->buf.byte[i];
873
874 return 0;
875}
876
877/*
794 * If state has any action bit, perform this action. 878 * If state has any action bit, perform this action.
795 * 879 *
796 * RETURNS: 0 if success, -1 if error. 880 * RETURNS: 0 if success, -1 if error.
797 */ 881 */
798static int 882static int do_state_action(struct nandsim *ns, uint32_t action)
799do_state_action(struct nandsim *ns, uint32_t action)
800{ 883{
801 int i, num; 884 int num;
802 int busdiv = ns->busw == 8 ? 1 : 2; 885 int busdiv = ns->busw == 8 ? 1 : 2;
803 886
804 action &= ACTION_MASK; 887 action &= ACTION_MASK;
@@ -822,7 +905,7 @@ do_state_action(struct nandsim *ns, uint32_t action)
822 break; 905 break;
823 } 906 }
824 num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; 907 num = ns->geom.pgszoob - ns->regs.off - ns->regs.column;
825 memcpy(ns->buf.byte, ns->mem.byte + NS_RAW_OFFSET(ns) + ns->regs.off, num); 908 read_page(ns, num);
826 909
827 NS_DBG("do_state_action: (ACTION_CPY:) copy %d bytes to int buf, raw offset %d\n", 910 NS_DBG("do_state_action: (ACTION_CPY:) copy %d bytes to int buf, raw offset %d\n",
828 num, NS_RAW_OFFSET(ns) + ns->regs.off); 911 num, NS_RAW_OFFSET(ns) + ns->regs.off);
@@ -863,7 +946,7 @@ do_state_action(struct nandsim *ns, uint32_t action)
863 ns->regs.row, NS_RAW_OFFSET(ns)); 946 ns->regs.row, NS_RAW_OFFSET(ns));
864 NS_LOG("erase sector %d\n", ns->regs.row >> (ns->geom.secshift - ns->geom.pgshift)); 947 NS_LOG("erase sector %d\n", ns->regs.row >> (ns->geom.secshift - ns->geom.pgshift));
865 948
866 memset(ns->mem.byte + NS_RAW_OFFSET(ns), 0xFF, ns->geom.secszoob); 949 erase_sector(ns);
867 950
868 NS_MDELAY(erase_delay); 951 NS_MDELAY(erase_delay);
869 952
@@ -886,8 +969,8 @@ do_state_action(struct nandsim *ns, uint32_t action)
886 return -1; 969 return -1;
887 } 970 }
888 971
889 for (i = 0; i < num; i++) 972 if (prog_page(ns, num) == -1)
890 ns->mem.byte[NS_RAW_OFFSET(ns) + ns->regs.off + i] &= ns->buf.byte[i]; 973 return -1;
891 974
892 NS_DBG("do_state_action: copy %d bytes from int buf to (%#x, %#x), raw off = %d\n", 975 NS_DBG("do_state_action: copy %d bytes from int buf to (%#x, %#x), raw off = %d\n",
893 num, ns->regs.row, ns->regs.column, NS_RAW_OFFSET(ns) + ns->regs.off); 976 num, ns->regs.row, ns->regs.column, NS_RAW_OFFSET(ns) + ns->regs.off);
@@ -928,8 +1011,7 @@ do_state_action(struct nandsim *ns, uint32_t action)
928/* 1011/*
929 * Switch simulator's state. 1012 * Switch simulator's state.
930 */ 1013 */
931static void 1014static void switch_state(struct nandsim *ns)
932switch_state(struct nandsim *ns)
933{ 1015{
934 if (ns->op) { 1016 if (ns->op) {
935 /* 1017 /*
@@ -1070,8 +1152,7 @@ switch_state(struct nandsim *ns)
1070 } 1152 }
1071} 1153}
1072 1154
1073static u_char 1155static u_char ns_nand_read_byte(struct mtd_info *mtd)
1074ns_nand_read_byte(struct mtd_info *mtd)
1075{ 1156{
1076 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1157 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
1077 u_char outb = 0x00; 1158 u_char outb = 0x00;
@@ -1144,8 +1225,7 @@ ns_nand_read_byte(struct mtd_info *mtd)
1144 return outb; 1225 return outb;
1145} 1226}
1146 1227
1147static void 1228static void ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1148ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1149{ 1229{
1150 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1230 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
1151 1231
@@ -1308,15 +1388,13 @@ static void ns_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int bitmask)
1308 ns_nand_write_byte(mtd, cmd); 1388 ns_nand_write_byte(mtd, cmd);
1309} 1389}
1310 1390
1311static int 1391static int ns_device_ready(struct mtd_info *mtd)
1312ns_device_ready(struct mtd_info *mtd)
1313{ 1392{
1314 NS_DBG("device_ready\n"); 1393 NS_DBG("device_ready\n");
1315 return 1; 1394 return 1;
1316} 1395}
1317 1396
1318static uint16_t 1397static uint16_t ns_nand_read_word(struct mtd_info *mtd)
1319ns_nand_read_word(struct mtd_info *mtd)
1320{ 1398{
1321 struct nand_chip *chip = (struct nand_chip *)mtd->priv; 1399 struct nand_chip *chip = (struct nand_chip *)mtd->priv;
1322 1400
@@ -1325,8 +1403,7 @@ ns_nand_read_word(struct mtd_info *mtd)
1325 return chip->read_byte(mtd) | (chip->read_byte(mtd) << 8); 1403 return chip->read_byte(mtd) | (chip->read_byte(mtd) << 8);
1326} 1404}
1327 1405
1328static void 1406static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
1329ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
1330{ 1407{
1331 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1408 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
1332 1409
@@ -1353,8 +1430,7 @@ ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
1353 } 1430 }
1354} 1431}
1355 1432
1356static void 1433static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
1357ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
1358{ 1434{
1359 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1435 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
1360 1436
@@ -1407,8 +1483,7 @@ ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
1407 return; 1483 return;
1408} 1484}
1409 1485
1410static int 1486static int ns_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
1411ns_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
1412{ 1487{
1413 ns_nand_read_buf(mtd, (u_char *)&ns_verify_buf[0], len); 1488 ns_nand_read_buf(mtd, (u_char *)&ns_verify_buf[0], len);
1414 1489
@@ -1436,14 +1511,12 @@ static int __init ns_init_module(void)
1436 } 1511 }
1437 1512
1438 /* Allocate and initialize mtd_info, nand_chip and nandsim structures */ 1513 /* Allocate and initialize mtd_info, nand_chip and nandsim structures */
1439 nsmtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip) 1514 nsmtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip)
1440 + sizeof(struct nandsim), GFP_KERNEL); 1515 + sizeof(struct nandsim), GFP_KERNEL);
1441 if (!nsmtd) { 1516 if (!nsmtd) {
1442 NS_ERR("unable to allocate core structures.\n"); 1517 NS_ERR("unable to allocate core structures.\n");
1443 return -ENOMEM; 1518 return -ENOMEM;
1444 } 1519 }
1445 memset(nsmtd, 0, sizeof(struct mtd_info) + sizeof(struct nand_chip) +
1446 sizeof(struct nandsim));
1447 chip = (struct nand_chip *)(nsmtd + 1); 1520 chip = (struct nand_chip *)(nsmtd + 1);
1448 nsmtd->priv = (void *)chip; 1521 nsmtd->priv = (void *)chip;
1449 nand = (struct nandsim *)(chip + 1); 1522 nand = (struct nandsim *)(chip + 1);
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index 039c759cfb..fd7a8d5ba2 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -56,7 +56,7 @@ static void ndfc_select_chip(struct mtd_info *mtd, int chip)
56 ccr |= NDFC_CCR_BS(chip + pchip->chip_offset); 56 ccr |= NDFC_CCR_BS(chip + pchip->chip_offset);
57 } else 57 } else
58 ccr |= NDFC_CCR_RESET_CE; 58 ccr |= NDFC_CCR_RESET_CE;
59 writel(ccr, ndfc->ndfcbase + NDFC_CCR); 59 __raw_writel(ccr, ndfc->ndfcbase + NDFC_CCR);
60} 60}
61 61
62static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) 62static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
diff --git a/drivers/mtd/nand/rtc_from4.c b/drivers/mtd/nand/rtc_from4.c
index f8c4964532..9189ec8f24 100644
--- a/drivers/mtd/nand/rtc_from4.c
+++ b/drivers/mtd/nand/rtc_from4.c
@@ -24,6 +24,7 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/rslib.h> 26#include <linux/rslib.h>
27#include <linux/bitrev.h>
27#include <linux/module.h> 28#include <linux/module.h>
28#include <linux/mtd/compatmac.h> 29#include <linux/mtd/compatmac.h>
29#include <linux/mtd/mtd.h> 30#include <linux/mtd/mtd.h>
@@ -152,47 +153,6 @@ static struct nand_ecclayout rtc_from4_nand_oobinfo = {
152 .oobfree = {{32, 32}} 153 .oobfree = {{32, 32}}
153}; 154};
154 155
155/* Aargh. I missed the reversed bit order, when I
156 * was talking to Renesas about the FPGA.
157 *
158 * The table is used for bit reordering and inversion
159 * of the ecc byte which we get from the FPGA
160 */
161static uint8_t revbits[256] = {
162 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
163 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
164 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
165 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
166 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
167 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
168 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
169 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
170 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
171 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
172 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
173 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
174 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
175 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
176 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
177 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
178 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
179 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
180 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
181 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
182 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
183 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
184 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
185 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
186 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
187 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
188 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
189 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
190 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
191 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
192 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
193 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
194};
195
196#endif 156#endif
197 157
198/* 158/*
@@ -397,7 +357,7 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
397 /* Read the syndrom pattern from the FPGA and correct the bitorder */ 357 /* Read the syndrom pattern from the FPGA and correct the bitorder */
398 rs_ecc = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC); 358 rs_ecc = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC);
399 for (i = 0; i < 8; i++) { 359 for (i = 0; i < 8; i++) {
400 ecc[i] = revbits[(*rs_ecc) & 0xFF]; 360 ecc[i] = bitrev8(*rs_ecc);
401 rs_ecc++; 361 rs_ecc++;
402 } 362 }
403 363
@@ -496,7 +456,7 @@ static int rtc_from4_errstat(struct mtd_info *mtd, struct nand_chip *this,
496 rtn = nand_do_read(mtd, page, len, &retlen, buf); 456 rtn = nand_do_read(mtd, page, len, &retlen, buf);
497 457
498 /* if read failed or > 1-bit error corrected */ 458 /* if read failed or > 1-bit error corrected */
499 if (rtn || (mtd->ecc_stats.corrected - corrected) > 1) { 459 if (rtn || (mtd->ecc_stats.corrected - corrected) > 1)
500 er_stat |= 1 << 1; 460 er_stat |= 1 << 1;
501 kfree(buf); 461 kfree(buf);
502 } 462 }
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index ff5cef24d5..8b3203571e 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -283,7 +283,7 @@ static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd,
283 unsigned int ctrl) 283 unsigned int ctrl)
284{ 284{
285 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 285 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
286 286
287 if (cmd == NAND_CMD_NONE) 287 if (cmd == NAND_CMD_NONE)
288 return; 288 return;
289 289
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index b5a5f8da47..4b1ba4fcfc 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -57,17 +57,16 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
57 57
58 DEBUG(MTD_DEBUG_LEVEL1, "NFTL: add_mtd for %s\n", mtd->name); 58 DEBUG(MTD_DEBUG_LEVEL1, "NFTL: add_mtd for %s\n", mtd->name);
59 59
60 nftl = kmalloc(sizeof(struct NFTLrecord), GFP_KERNEL); 60 nftl = kzalloc(sizeof(struct NFTLrecord), GFP_KERNEL);
61 61
62 if (!nftl) { 62 if (!nftl) {
63 printk(KERN_WARNING "NFTL: out of memory for data structures\n"); 63 printk(KERN_WARNING "NFTL: out of memory for data structures\n");
64 return; 64 return;
65 } 65 }
66 memset(nftl, 0, sizeof(*nftl));
67 66
68 nftl->mbd.mtd = mtd; 67 nftl->mbd.mtd = mtd;
69 nftl->mbd.devnum = -1; 68 nftl->mbd.devnum = -1;
70 nftl->mbd.blksize = 512; 69
71 nftl->mbd.tr = tr; 70 nftl->mbd.tr = tr;
72 71
73 if (NFTL_mount(nftl) < 0) { 72 if (NFTL_mount(nftl) < 0) {
@@ -147,10 +146,9 @@ int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
147 ops.ooblen = len; 146 ops.ooblen = len;
148 ops.oobbuf = buf; 147 ops.oobbuf = buf;
149 ops.datbuf = NULL; 148 ops.datbuf = NULL;
150 ops.len = len;
151 149
152 res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 150 res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
153 *retlen = ops.retlen; 151 *retlen = ops.oobretlen;
154 return res; 152 return res;
155} 153}
156 154
@@ -168,10 +166,9 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
168 ops.ooblen = len; 166 ops.ooblen = len;
169 ops.oobbuf = buf; 167 ops.oobbuf = buf;
170 ops.datbuf = NULL; 168 ops.datbuf = NULL;
171 ops.len = len;
172 169
173 res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 170 res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
174 *retlen = ops.retlen; 171 *retlen = ops.oobretlen;
175 return res; 172 return res;
176} 173}
177 174
@@ -797,6 +794,7 @@ static struct mtd_blktrans_ops nftl_tr = {
797 .name = "nftl", 794 .name = "nftl",
798 .major = NFTL_MAJOR, 795 .major = NFTL_MAJOR,
799 .part_bits = NFTL_PARTN_BITS, 796 .part_bits = NFTL_PARTN_BITS,
797 .blksize = 512,
800 .getgeo = nftl_getgeo, 798 .getgeo = nftl_getgeo,
801 .readsect = nftl_readblock, 799 .readsect = nftl_readblock,
802#ifdef CONFIG_NFTL_RW 800#ifdef CONFIG_NFTL_RW
diff --git a/drivers/mtd/onenand/generic.c b/drivers/mtd/onenand/generic.c
index af06a80f44..3d44d040a4 100644
--- a/drivers/mtd/onenand/generic.c
+++ b/drivers/mtd/onenand/generic.c
@@ -45,12 +45,10 @@ static int __devinit generic_onenand_probe(struct device *dev)
45 unsigned long size = res->end - res->start + 1; 45 unsigned long size = res->end - res->start + 1;
46 int err; 46 int err;
47 47
48 info = kmalloc(sizeof(struct onenand_info), GFP_KERNEL); 48 info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
49 if (!info) 49 if (!info)
50 return -ENOMEM; 50 return -ENOMEM;
51 51
52 memset(info, 0, sizeof(struct onenand_info));
53
54 if (!request_mem_region(res->start, size, dev->driver->name)) { 52 if (!request_mem_region(res->start, size, dev->driver->name)) {
55 err = -EBUSY; 53 err = -EBUSY;
56 goto out_free_info; 54 goto out_free_info;
@@ -63,6 +61,7 @@ static int __devinit generic_onenand_probe(struct device *dev)
63 } 61 }
64 62
65 info->onenand.mmcontrol = pdata->mmcontrol; 63 info->onenand.mmcontrol = pdata->mmcontrol;
64 info->onenand.irq = platform_get_irq(pdev, 0);
66 65
67 info->mtd.name = pdev->dev.bus_id; 66 info->mtd.name = pdev->dev.bus_id;
68 info->mtd.priv = &info->onenand; 67 info->mtd.priv = &info->onenand;
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 8ed68b28af..2da6bb2635 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -13,6 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/interrupt.h>
16#include <linux/jiffies.h> 17#include <linux/jiffies.h>
17#include <linux/mtd/mtd.h> 18#include <linux/mtd/mtd.h>
18#include <linux/mtd/onenand.h> 19#include <linux/mtd/onenand.h>
@@ -191,8 +192,6 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le
191 struct onenand_chip *this = mtd->priv; 192 struct onenand_chip *this = mtd->priv;
192 int value, readcmd = 0, block_cmd = 0; 193 int value, readcmd = 0, block_cmd = 0;
193 int block, page; 194 int block, page;
194 /* Now we use page size operation */
195 int sectors = 4, count = 4;
196 195
197 /* Address translation */ 196 /* Address translation */
198 switch (cmd) { 197 switch (cmd) {
@@ -244,6 +243,8 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le
244 } 243 }
245 244
246 if (page != -1) { 245 if (page != -1) {
246 /* Now we use page size operation */
247 int sectors = 4, count = 4;
247 int dataram; 248 int dataram;
248 249
249 switch (cmd) { 250 switch (cmd) {
@@ -297,7 +298,7 @@ static int onenand_wait(struct mtd_info *mtd, int state)
297 unsigned long timeout; 298 unsigned long timeout;
298 unsigned int flags = ONENAND_INT_MASTER; 299 unsigned int flags = ONENAND_INT_MASTER;
299 unsigned int interrupt = 0; 300 unsigned int interrupt = 0;
300 unsigned int ctrl, ecc; 301 unsigned int ctrl;
301 302
302 /* The 20 msec is enough */ 303 /* The 20 msec is enough */
303 timeout = jiffies + msecs_to_jiffies(20); 304 timeout = jiffies + msecs_to_jiffies(20);
@@ -309,7 +310,6 @@ static int onenand_wait(struct mtd_info *mtd, int state)
309 310
310 if (state != FL_READING) 311 if (state != FL_READING)
311 cond_resched(); 312 cond_resched();
312 touch_softlockup_watchdog();
313 } 313 }
314 /* To get correct interrupt status in timeout case */ 314 /* To get correct interrupt status in timeout case */
315 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT); 315 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
@@ -317,28 +317,126 @@ static int onenand_wait(struct mtd_info *mtd, int state)
317 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS); 317 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS);
318 318
319 if (ctrl & ONENAND_CTRL_ERROR) { 319 if (ctrl & ONENAND_CTRL_ERROR) {
320 /* It maybe occur at initial bad block */
321 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: controller error = 0x%04x\n", ctrl); 320 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: controller error = 0x%04x\n", ctrl);
322 /* Clear other interrupt bits for preventing ECC error */ 321 if (ctrl & ONENAND_CTRL_LOCK)
323 interrupt &= ONENAND_INT_MASTER; 322 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: it's locked error.\n");
324 } 323 return ctrl;
325
326 if (ctrl & ONENAND_CTRL_LOCK) {
327 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: it's locked error = 0x%04x\n", ctrl);
328 return -EACCES;
329 } 324 }
330 325
331 if (interrupt & ONENAND_INT_READ) { 326 if (interrupt & ONENAND_INT_READ) {
332 ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS); 327 int ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS);
333 if (ecc & ONENAND_ECC_2BIT_ALL) { 328 if (ecc) {
334 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: ECC error = 0x%04x\n", ecc); 329 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: ECC error = 0x%04x\n", ecc);
335 return -EBADMSG; 330 if (ecc & ONENAND_ECC_2BIT_ALL) {
331 mtd->ecc_stats.failed++;
332 return ecc;
333 } else if (ecc & ONENAND_ECC_1BIT_ALL)
334 mtd->ecc_stats.corrected++;
336 } 335 }
337 } 336 }
338 337
339 return 0; 338 return 0;
340} 339}
341 340
341/*
342 * onenand_interrupt - [DEFAULT] onenand interrupt handler
343 * @param irq onenand interrupt number
344 * @param dev_id interrupt data
345 *
346 * complete the work
347 */
348static irqreturn_t onenand_interrupt(int irq, void *data)
349{
350 struct onenand_chip *this = (struct onenand_chip *) data;
351
352 /* To handle shared interrupt */
353 if (!this->complete.done)
354 complete(&this->complete);
355
356 return IRQ_HANDLED;
357}
358
359/*
360 * onenand_interrupt_wait - [DEFAULT] wait until the command is done
361 * @param mtd MTD device structure
362 * @param state state to select the max. timeout value
363 *
364 * Wait for command done.
365 */
366static int onenand_interrupt_wait(struct mtd_info *mtd, int state)
367{
368 struct onenand_chip *this = mtd->priv;
369
370 wait_for_completion(&this->complete);
371
372 return onenand_wait(mtd, state);
373}
374
375/*
376 * onenand_try_interrupt_wait - [DEFAULT] try interrupt wait
377 * @param mtd MTD device structure
378 * @param state state to select the max. timeout value
379 *
380 * Try interrupt based wait (It is used one-time)
381 */
382static int onenand_try_interrupt_wait(struct mtd_info *mtd, int state)
383{
384 struct onenand_chip *this = mtd->priv;
385 unsigned long remain, timeout;
386
387 /* We use interrupt wait first */
388 this->wait = onenand_interrupt_wait;
389
390 timeout = msecs_to_jiffies(100);
391 remain = wait_for_completion_timeout(&this->complete, timeout);
392 if (!remain) {
393 printk(KERN_INFO "OneNAND: There's no interrupt. "
394 "We use the normal wait\n");
395
396 /* Release the irq */
397 free_irq(this->irq, this);
398
399 this->wait = onenand_wait;
400 }
401
402 return onenand_wait(mtd, state);
403}
404
405/*
406 * onenand_setup_wait - [OneNAND Interface] setup onenand wait method
407 * @param mtd MTD device structure
408 *
409 * There's two method to wait onenand work
410 * 1. polling - read interrupt status register
411 * 2. interrupt - use the kernel interrupt method
412 */
413static void onenand_setup_wait(struct mtd_info *mtd)
414{
415 struct onenand_chip *this = mtd->priv;
416 int syscfg;
417
418 init_completion(&this->complete);
419
420 if (this->irq <= 0) {
421 this->wait = onenand_wait;
422 return;
423 }
424
425 if (request_irq(this->irq, &onenand_interrupt,
426 IRQF_SHARED, "onenand", this)) {
427 /* If we can't get irq, use the normal wait */
428 this->wait = onenand_wait;
429 return;
430 }
431
432 /* Enable interrupt */
433 syscfg = this->read_word(this->base + ONENAND_REG_SYS_CFG1);
434 syscfg |= ONENAND_SYS_CFG1_IOBE;
435 this->write_word(syscfg, this->base + ONENAND_REG_SYS_CFG1);
436
437 this->wait = onenand_try_interrupt_wait;
438}
439
342/** 440/**
343 * onenand_bufferram_offset - [DEFAULT] BufferRAM offset 441 * onenand_bufferram_offset - [DEFAULT] BufferRAM offset
344 * @param mtd MTD data structure 442 * @param mtd MTD data structure
@@ -609,9 +707,10 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
609 size_t *retlen, u_char *buf) 707 size_t *retlen, u_char *buf)
610{ 708{
611 struct onenand_chip *this = mtd->priv; 709 struct onenand_chip *this = mtd->priv;
710 struct mtd_ecc_stats stats;
612 int read = 0, column; 711 int read = 0, column;
613 int thislen; 712 int thislen;
614 int ret = 0; 713 int ret = 0, boundary = 0;
615 714
616 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len); 715 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
617 716
@@ -627,38 +726,61 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
627 726
628 /* TODO handling oob */ 727 /* TODO handling oob */
629 728
630 while (read < len) { 729 stats = mtd->ecc_stats;
631 thislen = min_t(int, mtd->writesize, len - read); 730
632 731 /* Read-while-load method */
633 column = from & (mtd->writesize - 1); 732
634 if (column + thislen > mtd->writesize) 733 /* Do first load to bufferRAM */
635 thislen = mtd->writesize - column; 734 if (read < len) {
636 735 if (!onenand_check_bufferram(mtd, from)) {
637 if (!onenand_check_bufferram(mtd, from)) { 736 this->command(mtd, ONENAND_CMD_READ, from, mtd->writesize);
638 this->command(mtd, ONENAND_CMD_READ, from, mtd->writesize); 737 ret = this->wait(mtd, FL_READING);
639 738 onenand_update_bufferram(mtd, from, !ret);
640 ret = this->wait(mtd, FL_READING); 739 }
641 /* First copy data and check return value for ECC handling */ 740 }
642 onenand_update_bufferram(mtd, from, 1); 741
643 } 742 thislen = min_t(int, mtd->writesize, len - read);
644 743 column = from & (mtd->writesize - 1);
645 this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen); 744 if (column + thislen > mtd->writesize)
646 745 thislen = mtd->writesize - column;
647 read += thislen; 746
648 747 while (!ret) {
649 if (read == len) 748 /* If there is more to load then start next load */
650 break; 749 from += thislen;
651 750 if (read + thislen < len) {
652 if (ret) { 751 this->command(mtd, ONENAND_CMD_READ, from, mtd->writesize);
653 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read: read failed = %d\n", ret); 752 /*
654 goto out; 753 * Chip boundary handling in DDP
655 } 754 * Now we issued chip 1 read and pointed chip 1
656 755 * bufferam so we have to point chip 0 bufferam.
657 from += thislen; 756 */
658 buf += thislen; 757 if (this->device_id & ONENAND_DEVICE_IS_DDP &&
659 } 758 unlikely(from == (this->chipsize >> 1))) {
759 this->write_word(0, this->base + ONENAND_REG_START_ADDRESS2);
760 boundary = 1;
761 } else
762 boundary = 0;
763 ONENAND_SET_PREV_BUFFERRAM(this);
764 }
765 /* While load is going, read from last bufferRAM */
766 this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen);
767 /* See if we are done */
768 read += thislen;
769 if (read == len)
770 break;
771 /* Set up for next read from bufferRAM */
772 if (unlikely(boundary))
773 this->write_word(0x8000, this->base + ONENAND_REG_START_ADDRESS2);
774 ONENAND_SET_NEXT_BUFFERRAM(this);
775 buf += thislen;
776 thislen = min_t(int, mtd->writesize, len - read);
777 column = 0;
778 cond_resched();
779 /* Now wait for load */
780 ret = this->wait(mtd, FL_READING);
781 onenand_update_bufferram(mtd, from, !ret);
782 }
660 783
661out:
662 /* Deselect and wake up anyone waiting on the device */ 784 /* Deselect and wake up anyone waiting on the device */
663 onenand_release_device(mtd); 785 onenand_release_device(mtd);
664 786
@@ -668,7 +790,14 @@ out:
668 * retlen == desired len and result == -EBADMSG 790 * retlen == desired len and result == -EBADMSG
669 */ 791 */
670 *retlen = read; 792 *retlen = read;
671 return ret; 793
794 if (mtd->ecc_stats.failed - stats.failed)
795 return -EBADMSG;
796
797 if (ret)
798 return ret;
799
800 return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0;
672} 801}
673 802
674/** 803/**
@@ -705,6 +834,8 @@ int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
705 column = from & (mtd->oobsize - 1); 834 column = from & (mtd->oobsize - 1);
706 835
707 while (read < len) { 836 while (read < len) {
837 cond_resched();
838
708 thislen = mtd->oobsize - column; 839 thislen = mtd->oobsize - column;
709 thislen = min_t(int, thislen, len); 840 thislen = min_t(int, thislen, len);
710 841
@@ -717,16 +848,16 @@ int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
717 848
718 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen); 849 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
719 850
851 if (ret) {
852 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: read failed = 0x%x\n", ret);
853 goto out;
854 }
855
720 read += thislen; 856 read += thislen;
721 857
722 if (read == len) 858 if (read == len)
723 break; 859 break;
724 860
725 if (ret) {
726 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: read failed = %d\n", ret);
727 goto out;
728 }
729
730 buf += thislen; 861 buf += thislen;
731 862
732 /* Read more? */ 863 /* Read more? */
@@ -756,8 +887,8 @@ static int onenand_read_oob(struct mtd_info *mtd, loff_t from,
756{ 887{
757 BUG_ON(ops->mode != MTD_OOB_PLACE); 888 BUG_ON(ops->mode != MTD_OOB_PLACE);
758 889
759 return onenand_do_read_oob(mtd, from + ops->ooboffs, ops->len, 890 return onenand_do_read_oob(mtd, from + ops->ooboffs, ops->ooblen,
760 &ops->retlen, ops->oobbuf); 891 &ops->oobretlen, ops->oobbuf);
761} 892}
762 893
763#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE 894#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
@@ -804,6 +935,10 @@ static int onenand_verify_page(struct mtd_info *mtd, u_char *buf, loff_t addr)
804 void __iomem *dataram0, *dataram1; 935 void __iomem *dataram0, *dataram1;
805 int ret = 0; 936 int ret = 0;
806 937
938 /* In partial page write, just skip it */
939 if ((addr & (mtd->writesize - 1)) != 0)
940 return 0;
941
807 this->command(mtd, ONENAND_CMD_READ, addr, mtd->writesize); 942 this->command(mtd, ONENAND_CMD_READ, addr, mtd->writesize);
808 943
809 ret = this->wait(mtd, FL_READING); 944 ret = this->wait(mtd, FL_READING);
@@ -826,7 +961,7 @@ static int onenand_verify_page(struct mtd_info *mtd, u_char *buf, loff_t addr)
826#define onenand_verify_oob(...) (0) 961#define onenand_verify_oob(...) (0)
827#endif 962#endif
828 963
829#define NOTALIGNED(x) ((x & (mtd->writesize - 1)) != 0) 964#define NOTALIGNED(x) ((x & (this->subpagesize - 1)) != 0)
830 965
831/** 966/**
832 * onenand_write - [MTD Interface] write buffer to FLASH 967 * onenand_write - [MTD Interface] write buffer to FLASH
@@ -844,6 +979,7 @@ static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
844 struct onenand_chip *this = mtd->priv; 979 struct onenand_chip *this = mtd->priv;
845 int written = 0; 980 int written = 0;
846 int ret = 0; 981 int ret = 0;
982 int column, subpage;
847 983
848 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); 984 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
849 985
@@ -862,45 +998,63 @@ static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
862 return -EINVAL; 998 return -EINVAL;
863 } 999 }
864 1000
1001 column = to & (mtd->writesize - 1);
1002 subpage = column || (len & (mtd->writesize - 1));
1003
865 /* Grab the lock and see if the device is available */ 1004 /* Grab the lock and see if the device is available */
866 onenand_get_device(mtd, FL_WRITING); 1005 onenand_get_device(mtd, FL_WRITING);
867 1006
868 /* Loop until all data write */ 1007 /* Loop until all data write */
869 while (written < len) { 1008 while (written < len) {
870 int thislen = min_t(int, mtd->writesize, len - written); 1009 int bytes = mtd->writesize;
871 1010 int thislen = min_t(int, bytes, len - written);
872 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->writesize); 1011 u_char *wbuf = (u_char *) buf;
1012
1013 cond_resched();
1014
1015 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, bytes);
1016
1017 /* Partial page write */
1018 if (subpage) {
1019 bytes = min_t(int, bytes - column, (int) len);
1020 memset(this->page_buf, 0xff, mtd->writesize);
1021 memcpy(this->page_buf + column, buf, bytes);
1022 wbuf = this->page_buf;
1023 /* Even though partial write, we need page size */
1024 thislen = mtd->writesize;
1025 }
873 1026
874 this->write_bufferram(mtd, ONENAND_DATARAM, buf, 0, thislen); 1027 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, thislen);
875 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize); 1028 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
876 1029
877 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize); 1030 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize);
878 1031
879 onenand_update_bufferram(mtd, to, 1); 1032 /* In partial page write we don't update bufferram */
1033 onenand_update_bufferram(mtd, to, !subpage);
880 1034
881 ret = this->wait(mtd, FL_WRITING); 1035 ret = this->wait(mtd, FL_WRITING);
882 if (ret) { 1036 if (ret) {
883 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: write filaed %d\n", ret); 1037 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: write filaed %d\n", ret);
884 goto out; 1038 break;
885 } 1039 }
886 1040
887 written += thislen;
888
889 /* Only check verify write turn on */ 1041 /* Only check verify write turn on */
890 ret = onenand_verify_page(mtd, (u_char *) buf, to); 1042 ret = onenand_verify_page(mtd, (u_char *) wbuf, to);
891 if (ret) { 1043 if (ret) {
892 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: verify failed %d\n", ret); 1044 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: verify failed %d\n", ret);
893 goto out; 1045 break;
894 } 1046 }
895 1047
1048 written += thislen;
1049
896 if (written == len) 1050 if (written == len)
897 break; 1051 break;
898 1052
1053 column = 0;
899 to += thislen; 1054 to += thislen;
900 buf += thislen; 1055 buf += thislen;
901 } 1056 }
902 1057
903out:
904 /* Deselect and wake up anyone waiting on the device */ 1058 /* Deselect and wake up anyone waiting on the device */
905 onenand_release_device(mtd); 1059 onenand_release_device(mtd);
906 1060
@@ -944,6 +1098,8 @@ static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
944 while (written < len) { 1098 while (written < len) {
945 int thislen = min_t(int, mtd->oobsize, len - written); 1099 int thislen = min_t(int, mtd->oobsize, len - written);
946 1100
1101 cond_resched();
1102
947 column = to & (mtd->oobsize - 1); 1103 column = to & (mtd->oobsize - 1);
948 1104
949 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize); 1105 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize);
@@ -999,8 +1155,8 @@ static int onenand_write_oob(struct mtd_info *mtd, loff_t to,
999{ 1155{
1000 BUG_ON(ops->mode != MTD_OOB_PLACE); 1156 BUG_ON(ops->mode != MTD_OOB_PLACE);
1001 1157
1002 return onenand_do_write_oob(mtd, to + ops->ooboffs, ops->len, 1158 return onenand_do_write_oob(mtd, to + ops->ooboffs, ops->ooblen,
1003 &ops->retlen, ops->oobbuf); 1159 &ops->oobretlen, ops->oobbuf);
1004} 1160}
1005 1161
1006/** 1162/**
@@ -1071,6 +1227,7 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
1071 instr->state = MTD_ERASING; 1227 instr->state = MTD_ERASING;
1072 1228
1073 while (len) { 1229 while (len) {
1230 cond_resched();
1074 1231
1075 /* Check if we have a bad block, we do not erase bad blocks */ 1232 /* Check if we have a bad block, we do not erase bad blocks */
1076 if (onenand_block_checkbad(mtd, addr, 0, 0)) { 1233 if (onenand_block_checkbad(mtd, addr, 0, 0)) {
@@ -1084,10 +1241,7 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
1084 ret = this->wait(mtd, FL_ERASING); 1241 ret = this->wait(mtd, FL_ERASING);
1085 /* Check, if it is write protected */ 1242 /* Check, if it is write protected */
1086 if (ret) { 1243 if (ret) {
1087 if (ret == -EPERM) 1244 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift));
1088 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Device is write protected!!!\n");
1089 else
1090 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift));
1091 instr->state = MTD_ERASE_FAILED; 1245 instr->state = MTD_ERASE_FAILED;
1092 instr->fail_addr = addr; 1246 instr->fail_addr = addr;
1093 goto erase_exit; 1247 goto erase_exit;
@@ -1129,7 +1283,6 @@ static void onenand_sync(struct mtd_info *mtd)
1129 onenand_release_device(mtd); 1283 onenand_release_device(mtd);
1130} 1284}
1131 1285
1132
1133/** 1286/**
1134 * onenand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad 1287 * onenand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad
1135 * @param mtd MTD device structure 1288 * @param mtd MTD device structure
@@ -1196,32 +1349,38 @@ static int onenand_block_markbad(struct mtd_info *mtd, loff_t ofs)
1196} 1349}
1197 1350
1198/** 1351/**
1199 * onenand_unlock - [MTD Interface] Unlock block(s) 1352 * onenand_do_lock_cmd - [OneNAND Interface] Lock or unlock block(s)
1200 * @param mtd MTD device structure 1353 * @param mtd MTD device structure
1201 * @param ofs offset relative to mtd start 1354 * @param ofs offset relative to mtd start
1202 * @param len number of bytes to unlock 1355 * @param len number of bytes to lock or unlock
1203 * 1356 *
1204 * Unlock one or more blocks 1357 * Lock or unlock one or more blocks
1205 */ 1358 */
1206static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len) 1359static int onenand_do_lock_cmd(struct mtd_info *mtd, loff_t ofs, size_t len, int cmd)
1207{ 1360{
1208 struct onenand_chip *this = mtd->priv; 1361 struct onenand_chip *this = mtd->priv;
1209 int start, end, block, value, status; 1362 int start, end, block, value, status;
1363 int wp_status_mask;
1210 1364
1211 start = ofs >> this->erase_shift; 1365 start = ofs >> this->erase_shift;
1212 end = len >> this->erase_shift; 1366 end = len >> this->erase_shift;
1213 1367
1368 if (cmd == ONENAND_CMD_LOCK)
1369 wp_status_mask = ONENAND_WP_LS;
1370 else
1371 wp_status_mask = ONENAND_WP_US;
1372
1214 /* Continuous lock scheme */ 1373 /* Continuous lock scheme */
1215 if (this->options & ONENAND_HAS_CONT_LOCK) { 1374 if (this->options & ONENAND_HAS_CONT_LOCK) {
1216 /* Set start block address */ 1375 /* Set start block address */
1217 this->write_word(start, this->base + ONENAND_REG_START_BLOCK_ADDRESS); 1376 this->write_word(start, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1218 /* Set end block address */ 1377 /* Set end block address */
1219 this->write_word(start + end - 1, this->base + ONENAND_REG_END_BLOCK_ADDRESS); 1378 this->write_word(start + end - 1, this->base + ONENAND_REG_END_BLOCK_ADDRESS);
1220 /* Write unlock command */ 1379 /* Write lock command */
1221 this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0); 1380 this->command(mtd, cmd, 0, 0);
1222 1381
1223 /* There's no return value */ 1382 /* There's no return value */
1224 this->wait(mtd, FL_UNLOCKING); 1383 this->wait(mtd, FL_LOCKING);
1225 1384
1226 /* Sanity check */ 1385 /* Sanity check */
1227 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) 1386 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
@@ -1230,7 +1389,7 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1230 1389
1231 /* Check lock status */ 1390 /* Check lock status */
1232 status = this->read_word(this->base + ONENAND_REG_WP_STATUS); 1391 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
1233 if (!(status & ONENAND_WP_US)) 1392 if (!(status & wp_status_mask))
1234 printk(KERN_ERR "wp status = 0x%x\n", status); 1393 printk(KERN_ERR "wp status = 0x%x\n", status);
1235 1394
1236 return 0; 1395 return 0;
@@ -1246,11 +1405,11 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1246 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2); 1405 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2);
1247 /* Set start block address */ 1406 /* Set start block address */
1248 this->write_word(block, this->base + ONENAND_REG_START_BLOCK_ADDRESS); 1407 this->write_word(block, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1249 /* Write unlock command */ 1408 /* Write lock command */
1250 this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0); 1409 this->command(mtd, cmd, 0, 0);
1251 1410
1252 /* There's no return value */ 1411 /* There's no return value */
1253 this->wait(mtd, FL_UNLOCKING); 1412 this->wait(mtd, FL_LOCKING);
1254 1413
1255 /* Sanity check */ 1414 /* Sanity check */
1256 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) 1415 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
@@ -1259,7 +1418,7 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1259 1418
1260 /* Check lock status */ 1419 /* Check lock status */
1261 status = this->read_word(this->base + ONENAND_REG_WP_STATUS); 1420 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
1262 if (!(status & ONENAND_WP_US)) 1421 if (!(status & wp_status_mask))
1263 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status); 1422 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status);
1264 } 1423 }
1265 1424
@@ -1267,6 +1426,32 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1267} 1426}
1268 1427
1269/** 1428/**
1429 * onenand_lock - [MTD Interface] Lock block(s)
1430 * @param mtd MTD device structure
1431 * @param ofs offset relative to mtd start
1432 * @param len number of bytes to unlock
1433 *
1434 * Lock one or more blocks
1435 */
1436static int onenand_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
1437{
1438 return onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_LOCK);
1439}
1440
1441/**
1442 * onenand_unlock - [MTD Interface] Unlock block(s)
1443 * @param mtd MTD device structure
1444 * @param ofs offset relative to mtd start
1445 * @param len number of bytes to unlock
1446 *
1447 * Unlock one or more blocks
1448 */
1449static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1450{
1451 return onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_UNLOCK);
1452}
1453
1454/**
1270 * onenand_check_lock_status - [OneNAND Interface] Check lock status 1455 * onenand_check_lock_status - [OneNAND Interface] Check lock status
1271 * @param this onenand chip data structure 1456 * @param this onenand chip data structure
1272 * 1457 *
@@ -1310,7 +1495,7 @@ static int onenand_unlock_all(struct mtd_info *mtd)
1310 this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0); 1495 this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0);
1311 1496
1312 /* There's no return value */ 1497 /* There's no return value */
1313 this->wait(mtd, FL_UNLOCKING); 1498 this->wait(mtd, FL_LOCKING);
1314 1499
1315 /* Sanity check */ 1500 /* Sanity check */
1316 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) 1501 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
@@ -1334,7 +1519,7 @@ static int onenand_unlock_all(struct mtd_info *mtd)
1334 return 0; 1519 return 0;
1335 } 1520 }
1336 1521
1337 mtd->unlock(mtd, 0x0, this->chipsize); 1522 onenand_unlock(mtd, 0x0, this->chipsize);
1338 1523
1339 return 0; 1524 return 0;
1340} 1525}
@@ -1762,7 +1947,7 @@ static int onenand_probe(struct mtd_info *mtd)
1762 /* Read manufacturer and device IDs from Register */ 1947 /* Read manufacturer and device IDs from Register */
1763 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID); 1948 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID);
1764 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID); 1949 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID);
1765 ver_id= this->read_word(this->base + ONENAND_REG_VERSION_ID); 1950 ver_id = this->read_word(this->base + ONENAND_REG_VERSION_ID);
1766 1951
1767 /* Check OneNAND device */ 1952 /* Check OneNAND device */
1768 if (maf_id != bram_maf_id || dev_id != bram_dev_id) 1953 if (maf_id != bram_maf_id || dev_id != bram_dev_id)
@@ -1846,7 +2031,7 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
1846 if (!this->command) 2031 if (!this->command)
1847 this->command = onenand_command; 2032 this->command = onenand_command;
1848 if (!this->wait) 2033 if (!this->wait)
1849 this->wait = onenand_wait; 2034 onenand_setup_wait(mtd);
1850 2035
1851 if (!this->read_bufferram) 2036 if (!this->read_bufferram)
1852 this->read_bufferram = onenand_read_bufferram; 2037 this->read_bufferram = onenand_read_bufferram;
@@ -1883,23 +2068,30 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
1883 init_waitqueue_head(&this->wq); 2068 init_waitqueue_head(&this->wq);
1884 spin_lock_init(&this->chip_lock); 2069 spin_lock_init(&this->chip_lock);
1885 2070
2071 /*
2072 * Allow subpage writes up to oobsize.
2073 */
1886 switch (mtd->oobsize) { 2074 switch (mtd->oobsize) {
1887 case 64: 2075 case 64:
1888 this->ecclayout = &onenand_oob_64; 2076 this->ecclayout = &onenand_oob_64;
2077 mtd->subpage_sft = 2;
1889 break; 2078 break;
1890 2079
1891 case 32: 2080 case 32:
1892 this->ecclayout = &onenand_oob_32; 2081 this->ecclayout = &onenand_oob_32;
2082 mtd->subpage_sft = 1;
1893 break; 2083 break;
1894 2084
1895 default: 2085 default:
1896 printk(KERN_WARNING "No OOB scheme defined for oobsize %d\n", 2086 printk(KERN_WARNING "No OOB scheme defined for oobsize %d\n",
1897 mtd->oobsize); 2087 mtd->oobsize);
2088 mtd->subpage_sft = 0;
1898 /* To prevent kernel oops */ 2089 /* To prevent kernel oops */
1899 this->ecclayout = &onenand_oob_32; 2090 this->ecclayout = &onenand_oob_32;
1900 break; 2091 break;
1901 } 2092 }
1902 2093
2094 this->subpagesize = mtd->writesize >> mtd->subpage_sft;
1903 mtd->ecclayout = this->ecclayout; 2095 mtd->ecclayout = this->ecclayout;
1904 2096
1905 /* Fill in remaining MTD driver data */ 2097 /* Fill in remaining MTD driver data */
@@ -1922,7 +2114,7 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
1922 mtd->lock_user_prot_reg = onenand_lock_user_prot_reg; 2114 mtd->lock_user_prot_reg = onenand_lock_user_prot_reg;
1923#endif 2115#endif
1924 mtd->sync = onenand_sync; 2116 mtd->sync = onenand_sync;
1925 mtd->lock = NULL; 2117 mtd->lock = onenand_lock;
1926 mtd->unlock = onenand_unlock; 2118 mtd->unlock = onenand_unlock;
1927 mtd->suspend = onenand_suspend; 2119 mtd->suspend = onenand_suspend;
1928 mtd->resume = onenand_resume; 2120 mtd->resume = onenand_resume;
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index 1b00dac3d7..98f8fd1c63 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -93,13 +93,15 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
93 ret = onenand_do_read_oob(mtd, from + j * mtd->writesize + bd->offs, 93 ret = onenand_do_read_oob(mtd, from + j * mtd->writesize + bd->offs,
94 readlen, &retlen, &buf[0]); 94 readlen, &retlen, &buf[0]);
95 95
96 if (ret) 96 /* If it is a initial bad block, just ignore it */
97 if (ret && !(ret & ONENAND_CTRL_LOAD))
97 return ret; 98 return ret;
98 99
99 if (check_short_pattern(&buf[j * scanlen], scanlen, mtd->writesize, bd)) { 100 if (check_short_pattern(&buf[j * scanlen], scanlen, mtd->writesize, bd)) {
100 bbm->bbt[i >> 3] |= 0x03 << (i & 0x6); 101 bbm->bbt[i >> 3] |= 0x03 << (i & 0x6);
101 printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n", 102 printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
102 i >> 1, (unsigned int) from); 103 i >> 1, (unsigned int) from);
104 mtd->ecc_stats.badblocks++;
103 break; 105 break;
104 } 106 }
105 } 107 }
@@ -177,14 +179,12 @@ int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
177 int len, ret = 0; 179 int len, ret = 0;
178 180
179 len = mtd->size >> (this->erase_shift + 2); 181 len = mtd->size >> (this->erase_shift + 2);
180 /* Allocate memory (2bit per block) */ 182 /* Allocate memory (2bit per block) and clear the memory bad block table */
181 bbm->bbt = kmalloc(len, GFP_KERNEL); 183 bbm->bbt = kzalloc(len, GFP_KERNEL);
182 if (!bbm->bbt) { 184 if (!bbm->bbt) {
183 printk(KERN_ERR "onenand_scan_bbt: Out of memory\n"); 185 printk(KERN_ERR "onenand_scan_bbt: Out of memory\n");
184 return -ENOMEM; 186 return -ENOMEM;
185 } 187 }
186 /* Clear the memory bad block table */
187 memset(bbm->bbt, 0x00, len);
188 188
189 /* Set the bad block position */ 189 /* Set the bad block position */
190 bbm->badblockpos = ONENAND_BADBLOCK_POS; 190 bbm->badblockpos = ONENAND_BADBLOCK_POS;
@@ -230,14 +230,12 @@ int onenand_default_bbt(struct mtd_info *mtd)
230 struct onenand_chip *this = mtd->priv; 230 struct onenand_chip *this = mtd->priv;
231 struct bbm_info *bbm; 231 struct bbm_info *bbm;
232 232
233 this->bbm = kmalloc(sizeof(struct bbm_info), GFP_KERNEL); 233 this->bbm = kzalloc(sizeof(struct bbm_info), GFP_KERNEL);
234 if (!this->bbm) 234 if (!this->bbm)
235 return -ENOMEM; 235 return -ENOMEM;
236 236
237 bbm = this->bbm; 237 bbm = this->bbm;
238 238
239 memset(bbm, 0, sizeof(struct bbm_info));
240
241 /* 1KB page has same configuration as 2KB page */ 239 /* 1KB page has same configuration as 2KB page */
242 if (!bbm->badblock_pattern) 240 if (!bbm->badblock_pattern)
243 bbm->badblock_pattern = &largepage_memorybased; 241 bbm->badblock_pattern = &largepage_memorybased;
diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c
index 5b58523e4d..035cd9b0cc 100644
--- a/drivers/mtd/redboot.c
+++ b/drivers/mtd/redboot.c
@@ -96,7 +96,19 @@ static int parse_redboot_partitions(struct mtd_info *master,
96 */ 96 */
97 if (swab32(buf[i].size) == master->erasesize) { 97 if (swab32(buf[i].size) == master->erasesize) {
98 int j; 98 int j;
99 for (j = 0; j < numslots && buf[j].name[0] != 0xff; ++j) { 99 for (j = 0; j < numslots; ++j) {
100
101 /* A single 0xff denotes a deleted entry.
102 * Two of them in a row is the end of the table.
103 */
104 if (buf[j].name[0] == 0xff) {
105 if (buf[j].name[1] == 0xff) {
106 break;
107 } else {
108 continue;
109 }
110 }
111
100 /* The unsigned long fields were written with the 112 /* The unsigned long fields were written with the
101 * wrong byte sex, name and pad have no byte sex. 113 * wrong byte sex, name and pad have no byte sex.
102 */ 114 */
@@ -110,6 +122,9 @@ static int parse_redboot_partitions(struct mtd_info *master,
110 } 122 }
111 } 123 }
112 break; 124 break;
125 } else {
126 /* re-calculate of real numslots */
127 numslots = buf[i].size / sizeof(struct fis_image_desc);
113 } 128 }
114 } 129 }
115 if (i == numslots) { 130 if (i == numslots) {
@@ -123,8 +138,13 @@ static int parse_redboot_partitions(struct mtd_info *master,
123 for (i = 0; i < numslots; i++) { 138 for (i = 0; i < numslots; i++) {
124 struct fis_list *new_fl, **prev; 139 struct fis_list *new_fl, **prev;
125 140
126 if (buf[i].name[0] == 0xff) 141 if (buf[i].name[0] == 0xff) {
127 continue; 142 if (buf[i].name[1] == 0xff) {
143 break;
144 } else {
145 continue;
146 }
147 }
128 if (!redboot_checksum(&buf[i])) 148 if (!redboot_checksum(&buf[i]))
129 break; 149 break;
130 150
@@ -165,15 +185,13 @@ static int parse_redboot_partitions(struct mtd_info *master,
165 } 185 }
166 } 186 }
167#endif 187#endif
168 parts = kmalloc(sizeof(*parts)*nrparts + nulllen + namelen, GFP_KERNEL); 188 parts = kzalloc(sizeof(*parts)*nrparts + nulllen + namelen, GFP_KERNEL);
169 189
170 if (!parts) { 190 if (!parts) {
171 ret = -ENOMEM; 191 ret = -ENOMEM;
172 goto out; 192 goto out;
173 } 193 }
174 194
175 memset(parts, 0, sizeof(*parts)*nrparts + nulllen + namelen);
176
177 nullname = (char *)&parts[nrparts]; 195 nullname = (char *)&parts[nrparts];
178#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED 196#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
179 if (nulllen > 0) { 197 if (nulllen > 0) {
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 0f3baa5d9c..d4b1ba8f23 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -787,7 +787,6 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
787 787
788 if (scan_header(part) == 0) { 788 if (scan_header(part) == 0) {
789 part->mbd.size = part->sector_count; 789 part->mbd.size = part->sector_count;
790 part->mbd.blksize = SECTOR_SIZE;
791 part->mbd.tr = tr; 790 part->mbd.tr = tr;
792 part->mbd.devnum = -1; 791 part->mbd.devnum = -1;
793 if (!(mtd->flags & MTD_WRITEABLE)) 792 if (!(mtd->flags & MTD_WRITEABLE))
@@ -829,6 +828,8 @@ struct mtd_blktrans_ops rfd_ftl_tr = {
829 .name = "rfd", 828 .name = "rfd",
830 .major = RFD_FTL_MAJOR, 829 .major = RFD_FTL_MAJOR,
831 .part_bits = PART_BITS, 830 .part_bits = PART_BITS,
831 .blksize = SECTOR_SIZE,
832
832 .readsect = rfd_ftl_readsect, 833 .readsect = rfd_ftl_readsect,
833 .writesect = rfd_ftl_writesect, 834 .writesect = rfd_ftl_writesect,
834 .getgeo = rfd_ftl_getgeo, 835 .getgeo = rfd_ftl_getgeo,
diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c
index 79d3bb659b..a5f3d60047 100644
--- a/drivers/mtd/ssfdc.c
+++ b/drivers/mtd/ssfdc.c
@@ -172,13 +172,12 @@ static int read_raw_oob(struct mtd_info *mtd, loff_t offs, uint8_t *buf)
172 172
173 ops.mode = MTD_OOB_RAW; 173 ops.mode = MTD_OOB_RAW;
174 ops.ooboffs = 0; 174 ops.ooboffs = 0;
175 ops.ooblen = mtd->oobsize; 175 ops.ooblen = OOB_SIZE;
176 ops.len = OOB_SIZE;
177 ops.oobbuf = buf; 176 ops.oobbuf = buf;
178 ops.datbuf = NULL; 177 ops.datbuf = NULL;
179 178
180 ret = mtd->read_oob(mtd, offs, &ops); 179 ret = mtd->read_oob(mtd, offs, &ops);
181 if (ret < 0 || ops.retlen != OOB_SIZE) 180 if (ret < 0 || ops.oobretlen != OOB_SIZE)
182 return -1; 181 return -1;
183 182
184 return 0; 183 return 0;
@@ -312,7 +311,6 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
312 311
313 ssfdc->mbd.mtd = mtd; 312 ssfdc->mbd.mtd = mtd;
314 ssfdc->mbd.devnum = -1; 313 ssfdc->mbd.devnum = -1;
315 ssfdc->mbd.blksize = SECTOR_SIZE;
316 ssfdc->mbd.tr = tr; 314 ssfdc->mbd.tr = tr;
317 ssfdc->mbd.readonly = 1; 315 ssfdc->mbd.readonly = 1;
318 316
@@ -447,6 +445,7 @@ static struct mtd_blktrans_ops ssfdcr_tr = {
447 .name = "ssfdc", 445 .name = "ssfdc",
448 .major = SSFDCR_MAJOR, 446 .major = SSFDCR_MAJOR,
449 .part_bits = SSFDCR_PARTN_BITS, 447 .part_bits = SSFDCR_PARTN_BITS,
448 .blksize = SECTOR_SIZE,
450 .getgeo = ssfdcr_getgeo, 449 .getgeo = ssfdcr_getgeo,
451 .readsect = ssfdcr_readsect, 450 .readsect = ssfdcr_readsect,
452 .add_mtd = ssfdcr_add_mtd, 451 .add_mtd = ssfdcr_add_mtd,
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index 458dd9f830..6f93a765e5 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -617,13 +617,15 @@ rx_next:
617 * this round of polling 617 * this round of polling
618 */ 618 */
619 if (rx_work) { 619 if (rx_work) {
620 unsigned long flags;
621
620 if (cpr16(IntrStatus) & cp_rx_intr_mask) 622 if (cpr16(IntrStatus) & cp_rx_intr_mask)
621 goto rx_status_loop; 623 goto rx_status_loop;
622 624
623 local_irq_disable(); 625 local_irq_save(flags);
624 cpw16_f(IntrMask, cp_intr_mask); 626 cpw16_f(IntrMask, cp_intr_mask);
625 __netif_rx_complete(dev); 627 __netif_rx_complete(dev);
626 local_irq_enable(); 628 local_irq_restore(flags);
627 629
628 return 0; /* done */ 630 return 0; /* done */
629 } 631 }
@@ -763,17 +765,18 @@ static int cp_start_xmit (struct sk_buff *skb, struct net_device *dev)
763 struct cp_private *cp = netdev_priv(dev); 765 struct cp_private *cp = netdev_priv(dev);
764 unsigned entry; 766 unsigned entry;
765 u32 eor, flags; 767 u32 eor, flags;
768 unsigned long intr_flags;
766#if CP_VLAN_TAG_USED 769#if CP_VLAN_TAG_USED
767 u32 vlan_tag = 0; 770 u32 vlan_tag = 0;
768#endif 771#endif
769 int mss = 0; 772 int mss = 0;
770 773
771 spin_lock_irq(&cp->lock); 774 spin_lock_irqsave(&cp->lock, intr_flags);
772 775
773 /* This is a hard error, log it. */ 776 /* This is a hard error, log it. */
774 if (TX_BUFFS_AVAIL(cp) <= (skb_shinfo(skb)->nr_frags + 1)) { 777 if (TX_BUFFS_AVAIL(cp) <= (skb_shinfo(skb)->nr_frags + 1)) {
775 netif_stop_queue(dev); 778 netif_stop_queue(dev);
776 spin_unlock_irq(&cp->lock); 779 spin_unlock_irqrestore(&cp->lock, intr_flags);
777 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n", 780 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
778 dev->name); 781 dev->name);
779 return 1; 782 return 1;
@@ -906,7 +909,7 @@ static int cp_start_xmit (struct sk_buff *skb, struct net_device *dev)
906 if (TX_BUFFS_AVAIL(cp) <= (MAX_SKB_FRAGS + 1)) 909 if (TX_BUFFS_AVAIL(cp) <= (MAX_SKB_FRAGS + 1))
907 netif_stop_queue(dev); 910 netif_stop_queue(dev);
908 911
909 spin_unlock_irq(&cp->lock); 912 spin_unlock_irqrestore(&cp->lock, intr_flags);
910 913
911 cpw8(TxPoll, NormalTxPoll); 914 cpw8(TxPoll, NormalTxPoll);
912 dev->trans_start = jiffies; 915 dev->trans_start = jiffies;
diff --git a/drivers/net/82596.c b/drivers/net/82596.c
index 8236f26ffd..640d7ca2eb 100644
--- a/drivers/net/82596.c
+++ b/drivers/net/82596.c
@@ -1066,8 +1066,8 @@ static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
1066 short length = skb->len; 1066 short length = skb->len;
1067 dev->trans_start = jiffies; 1067 dev->trans_start = jiffies;
1068 1068
1069 DEB(DEB_STARTTX,printk(KERN_DEBUG "%s: i596_start_xmit(%x,%x) called\n", dev->name, 1069 DEB(DEB_STARTTX,printk(KERN_DEBUG "%s: i596_start_xmit(%x,%p) called\n",
1070 skb->len, (unsigned int)skb->data)); 1070 dev->name, skb->len, skb->data));
1071 1071
1072 if (skb->len < ETH_ZLEN) { 1072 if (skb->len < ETH_ZLEN) {
1073 if (skb_padto(skb, ETH_ZLEN)) 1073 if (skb_padto(skb, ETH_ZLEN))
@@ -1246,7 +1246,8 @@ struct net_device * __init i82596_probe(int unit)
1246 dev->priv = (void *)(dev->mem_start); 1246 dev->priv = (void *)(dev->mem_start);
1247 1247
1248 lp = dev->priv; 1248 lp = dev->priv;
1249 DEB(DEB_INIT,printk(KERN_DEBUG "%s: lp at 0x%08lx (%d bytes), lp->scb at 0x%08lx\n", 1249 DEB(DEB_INIT,printk(KERN_DEBUG "%s: lp at 0x%08lx (%zd bytes), "
1250 "lp->scb at 0x%08lx\n",
1250 dev->name, (unsigned long)lp, 1251 dev->name, (unsigned long)lp,
1251 sizeof(struct i596_private), (unsigned long)&lp->scb)); 1252 sizeof(struct i596_private), (unsigned long)&lp->scb));
1252 memset((void *) lp, 0, sizeof(struct i596_private)); 1253 memset((void *) lp, 0, sizeof(struct i596_private));
diff --git a/drivers/net/Space.c b/drivers/net/Space.c
index 602ed31a5d..9305eb9b1b 100644
--- a/drivers/net/Space.c
+++ b/drivers/net/Space.c
@@ -349,22 +349,11 @@ static void __init trif_probe2(int unit)
349#endif 349#endif
350 350
351 351
352/*
353 * The loopback device is global so it can be directly referenced
354 * by the network code. Also, it must be first on device list.
355 */
356extern int loopback_init(void);
357
358/* Statically configured drivers -- order matters here. */ 352/* Statically configured drivers -- order matters here. */
359static int __init net_olddevs_init(void) 353static int __init net_olddevs_init(void)
360{ 354{
361 int num; 355 int num;
362 356
363 if (loopback_init()) {
364 printk(KERN_ERR "Network loopback device setup failed\n");
365 }
366
367
368#ifdef CONFIG_SBNI 357#ifdef CONFIG_SBNI
369 for (num = 0; num < 8; ++num) 358 for (num = 0; num < 8; ++num)
370 sbni_probe(num); 359 sbni_probe(num);
diff --git a/drivers/net/arm/ep93xx_eth.c b/drivers/net/arm/ep93xx_eth.c
index 8ebd68e2af..dd698b033a 100644
--- a/drivers/net/arm/ep93xx_eth.c
+++ b/drivers/net/arm/ep93xx_eth.c
@@ -780,12 +780,10 @@ static struct ethtool_ops ep93xx_ethtool_ops = {
780struct net_device *ep93xx_dev_alloc(struct ep93xx_eth_data *data) 780struct net_device *ep93xx_dev_alloc(struct ep93xx_eth_data *data)
781{ 781{
782 struct net_device *dev; 782 struct net_device *dev;
783 struct ep93xx_priv *ep;
784 783
785 dev = alloc_etherdev(sizeof(struct ep93xx_priv)); 784 dev = alloc_etherdev(sizeof(struct ep93xx_priv));
786 if (dev == NULL) 785 if (dev == NULL)
787 return NULL; 786 return NULL;
788 ep = netdev_priv(dev);
789 787
790 memcpy(dev->dev_addr, data->dev_addr, ETH_ALEN); 788 memcpy(dev->dev_addr, data->dev_addr, ETH_ALEN);
791 789
@@ -840,9 +838,9 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
840 struct ep93xx_priv *ep; 838 struct ep93xx_priv *ep;
841 int err; 839 int err;
842 840
843 data = pdev->dev.platform_data;
844 if (pdev == NULL) 841 if (pdev == NULL)
845 return -ENODEV; 842 return -ENODEV;
843 data = pdev->dev.platform_data;
846 844
847 dev = ep93xx_dev_alloc(data); 845 dev = ep93xx_dev_alloc(data);
848 if (dev == NULL) { 846 if (dev == NULL) {
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index 474a4e3438..303a8d94ad 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -110,6 +110,11 @@ MODULE_DEVICE_TABLE(pci, b44_pci_tbl);
110 110
111static void b44_halt(struct b44 *); 111static void b44_halt(struct b44 *);
112static void b44_init_rings(struct b44 *); 112static void b44_init_rings(struct b44 *);
113
114#define B44_FULL_RESET 1
115#define B44_FULL_RESET_SKIP_PHY 2
116#define B44_PARTIAL_RESET 3
117
113static void b44_init_hw(struct b44 *, int); 118static void b44_init_hw(struct b44 *, int);
114 119
115static int dma_desc_align_mask; 120static int dma_desc_align_mask;
@@ -752,7 +757,7 @@ static void b44_recycle_rx(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
752 dest_idx * sizeof(dest_desc), 757 dest_idx * sizeof(dest_desc),
753 DMA_BIDIRECTIONAL); 758 DMA_BIDIRECTIONAL);
754 759
755 pci_dma_sync_single_for_device(bp->pdev, src_desc->addr, 760 pci_dma_sync_single_for_device(bp->pdev, le32_to_cpu(src_desc->addr),
756 RX_PKT_BUF_SZ, 761 RX_PKT_BUF_SZ,
757 PCI_DMA_FROMDEVICE); 762 PCI_DMA_FROMDEVICE);
758} 763}
@@ -879,12 +884,14 @@ static int b44_poll(struct net_device *netdev, int *budget)
879 } 884 }
880 885
881 if (bp->istat & ISTAT_ERRORS) { 886 if (bp->istat & ISTAT_ERRORS) {
882 spin_lock_irq(&bp->lock); 887 unsigned long flags;
888
889 spin_lock_irqsave(&bp->lock, flags);
883 b44_halt(bp); 890 b44_halt(bp);
884 b44_init_rings(bp); 891 b44_init_rings(bp);
885 b44_init_hw(bp, 1); 892 b44_init_hw(bp, B44_FULL_RESET_SKIP_PHY);
886 netif_wake_queue(bp->dev); 893 netif_wake_queue(bp->dev);
887 spin_unlock_irq(&bp->lock); 894 spin_unlock_irqrestore(&bp->lock, flags);
888 done = 1; 895 done = 1;
889 } 896 }
890 897
@@ -952,7 +959,7 @@ static void b44_tx_timeout(struct net_device *dev)
952 959
953 b44_halt(bp); 960 b44_halt(bp);
954 b44_init_rings(bp); 961 b44_init_rings(bp);
955 b44_init_hw(bp, 1); 962 b44_init_hw(bp, B44_FULL_RESET);
956 963
957 spin_unlock_irq(&bp->lock); 964 spin_unlock_irq(&bp->lock);
958 965
@@ -1069,7 +1076,7 @@ static int b44_change_mtu(struct net_device *dev, int new_mtu)
1069 b44_halt(bp); 1076 b44_halt(bp);
1070 dev->mtu = new_mtu; 1077 dev->mtu = new_mtu;
1071 b44_init_rings(bp); 1078 b44_init_rings(bp);
1072 b44_init_hw(bp, 1); 1079 b44_init_hw(bp, B44_FULL_RESET);
1073 spin_unlock_irq(&bp->lock); 1080 spin_unlock_irq(&bp->lock);
1074 1081
1075 b44_enable_ints(bp); 1082 b44_enable_ints(bp);
@@ -1366,12 +1373,12 @@ static int b44_set_mac_addr(struct net_device *dev, void *p)
1366 * packet processing. Invoked with bp->lock held. 1373 * packet processing. Invoked with bp->lock held.
1367 */ 1374 */
1368static void __b44_set_rx_mode(struct net_device *); 1375static void __b44_set_rx_mode(struct net_device *);
1369static void b44_init_hw(struct b44 *bp, int full_reset) 1376static void b44_init_hw(struct b44 *bp, int reset_kind)
1370{ 1377{
1371 u32 val; 1378 u32 val;
1372 1379
1373 b44_chip_reset(bp); 1380 b44_chip_reset(bp);
1374 if (full_reset) { 1381 if (reset_kind == B44_FULL_RESET) {
1375 b44_phy_reset(bp); 1382 b44_phy_reset(bp);
1376 b44_setup_phy(bp); 1383 b44_setup_phy(bp);
1377 } 1384 }
@@ -1388,7 +1395,10 @@ static void b44_init_hw(struct b44 *bp, int full_reset)
1388 bw32(bp, B44_TXMAXLEN, bp->dev->mtu + ETH_HLEN + 8 + RX_HEADER_LEN); 1395 bw32(bp, B44_TXMAXLEN, bp->dev->mtu + ETH_HLEN + 8 + RX_HEADER_LEN);
1389 1396
1390 bw32(bp, B44_TX_WMARK, 56); /* XXX magic */ 1397 bw32(bp, B44_TX_WMARK, 56); /* XXX magic */
1391 if (full_reset) { 1398 if (reset_kind == B44_PARTIAL_RESET) {
1399 bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
1400 (bp->rx_offset << DMARX_CTRL_ROSHIFT)));
1401 } else {
1392 bw32(bp, B44_DMATX_CTRL, DMATX_CTRL_ENABLE); 1402 bw32(bp, B44_DMATX_CTRL, DMATX_CTRL_ENABLE);
1393 bw32(bp, B44_DMATX_ADDR, bp->tx_ring_dma + bp->dma_offset); 1403 bw32(bp, B44_DMATX_ADDR, bp->tx_ring_dma + bp->dma_offset);
1394 bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE | 1404 bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
@@ -1399,9 +1409,6 @@ static void b44_init_hw(struct b44 *bp, int full_reset)
1399 bp->rx_prod = bp->rx_pending; 1409 bp->rx_prod = bp->rx_pending;
1400 1410
1401 bw32(bp, B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ); 1411 bw32(bp, B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ);
1402 } else {
1403 bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
1404 (bp->rx_offset << DMARX_CTRL_ROSHIFT)));
1405 } 1412 }
1406 1413
1407 val = br32(bp, B44_ENET_CTRL); 1414 val = br32(bp, B44_ENET_CTRL);
@@ -1418,7 +1425,7 @@ static int b44_open(struct net_device *dev)
1418 goto out; 1425 goto out;
1419 1426
1420 b44_init_rings(bp); 1427 b44_init_rings(bp);
1421 b44_init_hw(bp, 1); 1428 b44_init_hw(bp, B44_FULL_RESET);
1422 1429
1423 b44_check_phy(bp); 1430 b44_check_phy(bp);
1424 1431
@@ -1627,7 +1634,7 @@ static int b44_close(struct net_device *dev)
1627 netif_poll_enable(dev); 1634 netif_poll_enable(dev);
1628 1635
1629 if (bp->flags & B44_FLAG_WOL_ENABLE) { 1636 if (bp->flags & B44_FLAG_WOL_ENABLE) {
1630 b44_init_hw(bp, 0); 1637 b44_init_hw(bp, B44_PARTIAL_RESET);
1631 b44_setup_wol(bp); 1638 b44_setup_wol(bp);
1632 } 1639 }
1633 1640
@@ -1903,7 +1910,7 @@ static int b44_set_ringparam(struct net_device *dev,
1903 1910
1904 b44_halt(bp); 1911 b44_halt(bp);
1905 b44_init_rings(bp); 1912 b44_init_rings(bp);
1906 b44_init_hw(bp, 1); 1913 b44_init_hw(bp, B44_FULL_RESET);
1907 netif_wake_queue(bp->dev); 1914 netif_wake_queue(bp->dev);
1908 spin_unlock_irq(&bp->lock); 1915 spin_unlock_irq(&bp->lock);
1909 1916
@@ -1946,7 +1953,7 @@ static int b44_set_pauseparam(struct net_device *dev,
1946 if (bp->flags & B44_FLAG_PAUSE_AUTO) { 1953 if (bp->flags & B44_FLAG_PAUSE_AUTO) {
1947 b44_halt(bp); 1954 b44_halt(bp);
1948 b44_init_rings(bp); 1955 b44_init_rings(bp);
1949 b44_init_hw(bp, 1); 1956 b44_init_hw(bp, B44_FULL_RESET);
1950 } else { 1957 } else {
1951 __b44_set_flow_ctrl(bp, bp->flags); 1958 __b44_set_flow_ctrl(bp, bp->flags);
1952 } 1959 }
@@ -2302,7 +2309,7 @@ static int b44_suspend(struct pci_dev *pdev, pm_message_t state)
2302 2309
2303 free_irq(dev->irq, dev); 2310 free_irq(dev->irq, dev);
2304 if (bp->flags & B44_FLAG_WOL_ENABLE) { 2311 if (bp->flags & B44_FLAG_WOL_ENABLE) {
2305 b44_init_hw(bp, 0); 2312 b44_init_hw(bp, B44_PARTIAL_RESET);
2306 b44_setup_wol(bp); 2313 b44_setup_wol(bp);
2307 } 2314 }
2308 pci_disable_device(pdev); 2315 pci_disable_device(pdev);
@@ -2313,21 +2320,32 @@ static int b44_resume(struct pci_dev *pdev)
2313{ 2320{
2314 struct net_device *dev = pci_get_drvdata(pdev); 2321 struct net_device *dev = pci_get_drvdata(pdev);
2315 struct b44 *bp = netdev_priv(dev); 2322 struct b44 *bp = netdev_priv(dev);
2323 int rc = 0;
2316 2324
2317 pci_restore_state(pdev); 2325 pci_restore_state(pdev);
2318 pci_enable_device(pdev); 2326 rc = pci_enable_device(pdev);
2327 if (rc) {
2328 printk(KERN_ERR PFX "%s: pci_enable_device failed\n",
2329 dev->name);
2330 return rc;
2331 }
2332
2319 pci_set_master(pdev); 2333 pci_set_master(pdev);
2320 2334
2321 if (!netif_running(dev)) 2335 if (!netif_running(dev))
2322 return 0; 2336 return 0;
2323 2337
2324 if (request_irq(dev->irq, b44_interrupt, IRQF_SHARED, dev->name, dev)) 2338 rc = request_irq(dev->irq, b44_interrupt, IRQF_SHARED, dev->name, dev);
2339 if (rc) {
2325 printk(KERN_ERR PFX "%s: request_irq failed\n", dev->name); 2340 printk(KERN_ERR PFX "%s: request_irq failed\n", dev->name);
2341 pci_disable_device(pdev);
2342 return rc;
2343 }
2326 2344
2327 spin_lock_irq(&bp->lock); 2345 spin_lock_irq(&bp->lock);
2328 2346
2329 b44_init_rings(bp); 2347 b44_init_rings(bp);
2330 b44_init_hw(bp, 1); 2348 b44_init_hw(bp, B44_FULL_RESET);
2331 netif_device_attach(bp->dev); 2349 netif_device_attach(bp->dev);
2332 spin_unlock_irq(&bp->lock); 2350 spin_unlock_irq(&bp->lock);
2333 2351
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 7d824cf8ee..ee7b75b976 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -57,8 +57,8 @@
57 57
58#define DRV_MODULE_NAME "bnx2" 58#define DRV_MODULE_NAME "bnx2"
59#define PFX DRV_MODULE_NAME ": " 59#define PFX DRV_MODULE_NAME ": "
60#define DRV_MODULE_VERSION "1.5.1" 60#define DRV_MODULE_VERSION "1.5.5"
61#define DRV_MODULE_RELDATE "November 15, 2006" 61#define DRV_MODULE_RELDATE "February 1, 2007"
62 62
63#define RUN_AT(x) (jiffies + (x)) 63#define RUN_AT(x) (jiffies + (x))
64 64
@@ -217,9 +217,16 @@ static inline u32 bnx2_tx_avail(struct bnx2 *bp)
217 u32 diff; 217 u32 diff;
218 218
219 smp_mb(); 219 smp_mb();
220 diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons); 220
221 if (diff > MAX_TX_DESC_CNT) 221 /* The ring uses 256 indices for 255 entries, one of them
222 diff = (diff & MAX_TX_DESC_CNT) - 1; 222 * needs to be skipped.
223 */
224 diff = bp->tx_prod - bp->tx_cons;
225 if (unlikely(diff >= TX_DESC_CNT)) {
226 diff &= 0xffff;
227 if (diff == TX_DESC_CNT)
228 diff = MAX_TX_DESC_CNT;
229 }
223 return (bp->tx_ring_size - diff); 230 return (bp->tx_ring_size - diff);
224} 231}
225 232
@@ -1338,8 +1345,6 @@ bnx2_init_copper_phy(struct bnx2 *bp)
1338{ 1345{
1339 u32 val; 1346 u32 val;
1340 1347
1341 bp->phy_flags |= PHY_CRC_FIX_FLAG;
1342
1343 if (bp->phy_flags & PHY_CRC_FIX_FLAG) { 1348 if (bp->phy_flags & PHY_CRC_FIX_FLAG) {
1344 bnx2_write_phy(bp, 0x18, 0x0c00); 1349 bnx2_write_phy(bp, 0x18, 0x0c00);
1345 bnx2_write_phy(bp, 0x17, 0x000a); 1350 bnx2_write_phy(bp, 0x17, 0x000a);
@@ -1351,6 +1356,14 @@ bnx2_init_copper_phy(struct bnx2 *bp)
1351 bnx2_write_phy(bp, 0x18, 0x0400); 1356 bnx2_write_phy(bp, 0x18, 0x0400);
1352 } 1357 }
1353 1358
1359 if (bp->phy_flags & PHY_DIS_EARLY_DAC_FLAG) {
1360 bnx2_write_phy(bp, MII_BNX2_DSP_ADDRESS,
1361 MII_BNX2_DSP_EXPAND_REG | 0x8);
1362 bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &val);
1363 val &= ~(1 << 8);
1364 bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val);
1365 }
1366
1354 if (bp->dev->mtu > 1500) { 1367 if (bp->dev->mtu > 1500) {
1355 /* Set extended packet length bit */ 1368 /* Set extended packet length bit */
1356 bnx2_write_phy(bp, 0x18, 0x7); 1369 bnx2_write_phy(bp, 0x18, 0x7);
@@ -3078,7 +3091,7 @@ bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
3078 int buf_size) 3091 int buf_size)
3079{ 3092{
3080 u32 written, offset32, len32; 3093 u32 written, offset32, len32;
3081 u8 *buf, start[4], end[4], *flash_buffer = NULL; 3094 u8 *buf, start[4], end[4], *align_buf = NULL, *flash_buffer = NULL;
3082 int rc = 0; 3095 int rc = 0;
3083 int align_start, align_end; 3096 int align_start, align_end;
3084 3097
@@ -3089,7 +3102,7 @@ bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
3089 3102
3090 if ((align_start = (offset32 & 3))) { 3103 if ((align_start = (offset32 & 3))) {
3091 offset32 &= ~3; 3104 offset32 &= ~3;
3092 len32 += align_start; 3105 len32 += (4 - align_start);
3093 if ((rc = bnx2_nvram_read(bp, offset32, start, 4))) 3106 if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
3094 return rc; 3107 return rc;
3095 } 3108 }
@@ -3106,16 +3119,17 @@ bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
3106 } 3119 }
3107 3120
3108 if (align_start || align_end) { 3121 if (align_start || align_end) {
3109 buf = kmalloc(len32, GFP_KERNEL); 3122 align_buf = kmalloc(len32, GFP_KERNEL);
3110 if (buf == 0) 3123 if (align_buf == NULL)
3111 return -ENOMEM; 3124 return -ENOMEM;
3112 if (align_start) { 3125 if (align_start) {
3113 memcpy(buf, start, 4); 3126 memcpy(align_buf, start, 4);
3114 } 3127 }
3115 if (align_end) { 3128 if (align_end) {
3116 memcpy(buf + len32 - 4, end, 4); 3129 memcpy(align_buf + len32 - 4, end, 4);
3117 } 3130 }
3118 memcpy(buf + align_start, data_buf, buf_size); 3131 memcpy(align_buf + align_start, data_buf, buf_size);
3132 buf = align_buf;
3119 } 3133 }
3120 3134
3121 if (bp->flash_info->buffered == 0) { 3135 if (bp->flash_info->buffered == 0) {
@@ -3249,11 +3263,8 @@ bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
3249 } 3263 }
3250 3264
3251nvram_write_end: 3265nvram_write_end:
3252 if (bp->flash_info->buffered == 0) 3266 kfree(flash_buffer);
3253 kfree(flash_buffer); 3267 kfree(align_buf);
3254
3255 if (align_start || align_end)
3256 kfree(buf);
3257 return rc; 3268 return rc;
3258} 3269}
3259 3270
@@ -3998,7 +4009,7 @@ bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
3998 if (!skb) 4009 if (!skb)
3999 return -ENOMEM; 4010 return -ENOMEM;
4000 packet = skb_put(skb, pkt_size); 4011 packet = skb_put(skb, pkt_size);
4001 memcpy(packet, bp->mac_addr, 6); 4012 memcpy(packet, bp->dev->dev_addr, 6);
4002 memset(packet + 6, 0x0, 8); 4013 memset(packet + 6, 0x0, 8);
4003 for (i = 14; i < pkt_size; i++) 4014 for (i = 14; i < pkt_size; i++)
4004 packet[i] = (unsigned char) (i & 0xff); 4015 packet[i] = (unsigned char) (i & 0xff);
@@ -5638,6 +5649,44 @@ poll_bnx2(struct net_device *dev)
5638} 5649}
5639#endif 5650#endif
5640 5651
5652static void __devinit
5653bnx2_get_5709_media(struct bnx2 *bp)
5654{
5655 u32 val = REG_RD(bp, BNX2_MISC_DUAL_MEDIA_CTRL);
5656 u32 bond_id = val & BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID;
5657 u32 strap;
5658
5659 if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_C)
5660 return;
5661 else if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
5662 bp->phy_flags |= PHY_SERDES_FLAG;
5663 return;
5664 }
5665
5666 if (val & BNX2_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE)
5667 strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
5668 else
5669 strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
5670
5671 if (PCI_FUNC(bp->pdev->devfn) == 0) {
5672 switch (strap) {
5673 case 0x4:
5674 case 0x5:
5675 case 0x6:
5676 bp->phy_flags |= PHY_SERDES_FLAG;
5677 return;
5678 }
5679 } else {
5680 switch (strap) {
5681 case 0x1:
5682 case 0x2:
5683 case 0x4:
5684 bp->phy_flags |= PHY_SERDES_FLAG;
5685 return;
5686 }
5687 }
5688}
5689
5641static int __devinit 5690static int __devinit
5642bnx2_init_board(struct pci_dev *pdev, struct net_device *dev) 5691bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5643{ 5692{
@@ -5804,9 +5853,11 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5804 reg = REG_RD_IND(bp, BNX2_SHM_HDR_SIGNATURE); 5853 reg = REG_RD_IND(bp, BNX2_SHM_HDR_SIGNATURE);
5805 5854
5806 if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) == 5855 if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) ==
5807 BNX2_SHM_HDR_SIGNATURE_SIG) 5856 BNX2_SHM_HDR_SIGNATURE_SIG) {
5808 bp->shmem_base = REG_RD_IND(bp, BNX2_SHM_HDR_ADDR_0); 5857 u32 off = PCI_FUNC(pdev->devfn) << 2;
5809 else 5858
5859 bp->shmem_base = REG_RD_IND(bp, BNX2_SHM_HDR_ADDR_0 + off);
5860 } else
5810 bp->shmem_base = HOST_VIEW_SHMEM_BASE; 5861 bp->shmem_base = HOST_VIEW_SHMEM_BASE;
5811 5862
5812 /* Get the permanent MAC address. First we need to make sure the 5863 /* Get the permanent MAC address. First we need to make sure the
@@ -5858,10 +5909,9 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5858 bp->phy_addr = 1; 5909 bp->phy_addr = 1;
5859 5910
5860 /* Disable WOL support if we are running on a SERDES chip. */ 5911 /* Disable WOL support if we are running on a SERDES chip. */
5861 if (CHIP_NUM(bp) == CHIP_NUM_5709) { 5912 if (CHIP_NUM(bp) == CHIP_NUM_5709)
5862 if (CHIP_BOND_ID(bp) != BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) 5913 bnx2_get_5709_media(bp);
5863 bp->phy_flags |= PHY_SERDES_FLAG; 5914 else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT)
5864 } else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT)
5865 bp->phy_flags |= PHY_SERDES_FLAG; 5915 bp->phy_flags |= PHY_SERDES_FLAG;
5866 5916
5867 if (bp->phy_flags & PHY_SERDES_FLAG) { 5917 if (bp->phy_flags & PHY_SERDES_FLAG) {
@@ -5873,7 +5923,11 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5873 if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G) 5923 if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G)
5874 bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG; 5924 bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG;
5875 } 5925 }
5876 } 5926 } else if (CHIP_NUM(bp) == CHIP_NUM_5706 ||
5927 CHIP_NUM(bp) == CHIP_NUM_5708)
5928 bp->phy_flags |= PHY_CRC_FIX_FLAG;
5929 else if (CHIP_ID(bp) == CHIP_ID_5709_A0)
5930 bp->phy_flags |= PHY_DIS_EARLY_DAC_FLAG;
5877 5931
5878 if ((CHIP_ID(bp) == CHIP_ID_5708_A0) || 5932 if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
5879 (CHIP_ID(bp) == CHIP_ID_5708_B0) || 5933 (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h
index 13b6f9b11e..ccbdf81c65 100644
--- a/drivers/net/bnx2.h
+++ b/drivers/net/bnx2.h
@@ -6288,6 +6288,10 @@ struct l2_fhdr {
6288 6288
6289#define BCM5708S_TX_ACTL3 0x17 6289#define BCM5708S_TX_ACTL3 0x17
6290 6290
6291#define MII_BNX2_DSP_RW_PORT 0x15
6292#define MII_BNX2_DSP_ADDRESS 0x17
6293#define MII_BNX2_DSP_EXPAND_REG 0x0f00
6294
6291#define MIN_ETHERNET_PACKET_SIZE 60 6295#define MIN_ETHERNET_PACKET_SIZE 60
6292#define MAX_ETHERNET_PACKET_SIZE 1514 6296#define MAX_ETHERNET_PACKET_SIZE 1514
6293#define MAX_ETHERNET_JUMBO_PACKET_SIZE 9014 6297#define MAX_ETHERNET_JUMBO_PACKET_SIZE 9014
@@ -6489,6 +6493,7 @@ struct bnx2 {
6489#define PHY_INT_MODE_MASK_FLAG 0x300 6493#define PHY_INT_MODE_MASK_FLAG 0x300
6490#define PHY_INT_MODE_AUTO_POLLING_FLAG 0x100 6494#define PHY_INT_MODE_AUTO_POLLING_FLAG 0x100
6491#define PHY_INT_MODE_LINK_READY_FLAG 0x200 6495#define PHY_INT_MODE_LINK_READY_FLAG 0x200
6496#define PHY_DIS_EARLY_DAC_FLAG 0x400
6492 6497
6493 u32 chip_id; 6498 u32 chip_id;
6494 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */ 6499 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
@@ -6512,6 +6517,7 @@ struct bnx2 {
6512#define CHIP_ID_5708_A0 0x57080000 6517#define CHIP_ID_5708_A0 0x57080000
6513#define CHIP_ID_5708_B0 0x57081000 6518#define CHIP_ID_5708_B0 0x57081000
6514#define CHIP_ID_5708_B1 0x57081010 6519#define CHIP_ID_5708_B1 0x57081010
6520#define CHIP_ID_5709_A0 0x57090000
6515 6521
6516#define CHIP_BOND_ID(bp) (((bp)->chip_id) & 0xf) 6522#define CHIP_BOND_ID(bp) (((bp)->chip_id) & 0xf)
6517 6523
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index dc434fb6da..0978c9ac6d 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -151,8 +151,8 @@ struct slave {
151 struct slave *next; 151 struct slave *next;
152 struct slave *prev; 152 struct slave *prev;
153 int delay; 153 int delay;
154 u32 jiffies; 154 unsigned long jiffies;
155 u32 last_arp_rx; 155 unsigned long last_arp_rx;
156 s8 link; /* one of BOND_LINK_XXXX */ 156 s8 link; /* one of BOND_LINK_XXXX */
157 s8 state; /* one of BOND_STATE_XXXX */ 157 s8 state; /* one of BOND_STATE_XXXX */
158 u32 original_flags; 158 u32 original_flags;
@@ -242,7 +242,8 @@ extern inline int slave_do_arp_validate(struct bonding *bond, struct slave *slav
242 return bond->params.arp_validate & (1 << slave->state); 242 return bond->params.arp_validate & (1 << slave->state);
243} 243}
244 244
245extern inline u32 slave_last_rx(struct bonding *bond, struct slave *slave) 245extern inline unsigned long slave_last_rx(struct bonding *bond,
246 struct slave *slave)
246{ 247{
247 if (slave_do_arp_validate(bond, slave)) 248 if (slave_do_arp_validate(bond, slave))
248 return slave->last_arp_rx; 249 return slave->last_arp_rx;
diff --git a/drivers/net/chelsio/my3126.c b/drivers/net/chelsio/my3126.c
index c7731b6f9d..82fed1dd50 100644
--- a/drivers/net/chelsio/my3126.c
+++ b/drivers/net/chelsio/my3126.c
@@ -170,9 +170,10 @@ static struct cphy *my3126_phy_create(adapter_t *adapter,
170{ 170{
171 struct cphy *cphy = kzalloc(sizeof (*cphy), GFP_KERNEL); 171 struct cphy *cphy = kzalloc(sizeof (*cphy), GFP_KERNEL);
172 172
173 if (cphy) 173 if (!cphy)
174 cphy_init(cphy, adapter, phy_addr, &my3126_ops, mdio_ops); 174 return NULL;
175 175
176 cphy_init(cphy, adapter, phy_addr, &my3126_ops, mdio_ops);
176 INIT_DELAYED_WORK(&cphy->phy_update, my3216_poll); 177 INIT_DELAYED_WORK(&cphy->phy_update, my3216_poll);
177 cphy->bmsr = 0; 178 cphy->bmsr = 0;
178 179
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index c2ae2a2462..0cefef5e3f 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -2718,12 +2718,11 @@ static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
2718 struct net_device *netdev = pci_get_drvdata(pdev); 2718 struct net_device *netdev = pci_get_drvdata(pdev);
2719 struct nic *nic = netdev_priv(netdev); 2719 struct nic *nic = netdev_priv(netdev);
2720 2720
2721#ifdef CONFIG_E100_NAPI
2722 if (netif_running(netdev)) 2721 if (netif_running(netdev))
2723 netif_poll_disable(nic->netdev); 2722 netif_poll_disable(nic->netdev);
2724#endif
2725 del_timer_sync(&nic->watchdog); 2723 del_timer_sync(&nic->watchdog);
2726 netif_carrier_off(nic->netdev); 2724 netif_carrier_off(nic->netdev);
2725 netif_device_detach(netdev);
2727 2726
2728 pci_save_state(pdev); 2727 pci_save_state(pdev);
2729 2728
@@ -2736,6 +2735,7 @@ static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
2736 } 2735 }
2737 2736
2738 pci_disable_device(pdev); 2737 pci_disable_device(pdev);
2738 free_irq(pdev->irq, netdev);
2739 pci_set_power_state(pdev, PCI_D3hot); 2739 pci_set_power_state(pdev, PCI_D3hot);
2740 2740
2741 return 0; 2741 return 0;
@@ -2759,16 +2759,13 @@ static int e100_resume(struct pci_dev *pdev)
2759} 2759}
2760#endif /* CONFIG_PM */ 2760#endif /* CONFIG_PM */
2761 2761
2762
2763static void e100_shutdown(struct pci_dev *pdev) 2762static void e100_shutdown(struct pci_dev *pdev)
2764{ 2763{
2765 struct net_device *netdev = pci_get_drvdata(pdev); 2764 struct net_device *netdev = pci_get_drvdata(pdev);
2766 struct nic *nic = netdev_priv(netdev); 2765 struct nic *nic = netdev_priv(netdev);
2767 2766
2768#ifdef CONFIG_E100_NAPI
2769 if (netif_running(netdev)) 2767 if (netif_running(netdev))
2770 netif_poll_disable(nic->netdev); 2768 netif_poll_disable(nic->netdev);
2771#endif
2772 del_timer_sync(&nic->watchdog); 2769 del_timer_sync(&nic->watchdog);
2773 netif_carrier_off(nic->netdev); 2770 netif_carrier_off(nic->netdev);
2774 2771
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index da459f7177..fb96c87f9e 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -100,6 +100,9 @@ static const struct e1000_stats e1000_gstrings_stats[] = {
100 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) }, 100 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
101 { "rx_header_split", E1000_STAT(rx_hdr_split) }, 101 { "rx_header_split", E1000_STAT(rx_hdr_split) },
102 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) }, 102 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
103 { "tx_smbus", E1000_STAT(stats.mgptc) },
104 { "rx_smbus", E1000_STAT(stats.mgprc) },
105 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
103}; 106};
104 107
105#define E1000_QUEUE_STATS_LEN 0 108#define E1000_QUEUE_STATS_LEN 0
diff --git a/drivers/net/e1000/e1000_hw.c b/drivers/net/e1000/e1000_hw.c
index 3655d902b0..9be4469930 100644
--- a/drivers/net/e1000/e1000_hw.c
+++ b/drivers/net/e1000/e1000_hw.c
@@ -308,141 +308,160 @@ e1000_phy_init_script(struct e1000_hw *hw)
308int32_t 308int32_t
309e1000_set_mac_type(struct e1000_hw *hw) 309e1000_set_mac_type(struct e1000_hw *hw)
310{ 310{
311 DEBUGFUNC("e1000_set_mac_type"); 311 DEBUGFUNC("e1000_set_mac_type");
312 312
313 switch (hw->device_id) { 313 switch (hw->device_id) {
314 case E1000_DEV_ID_82542: 314 case E1000_DEV_ID_82542:
315 switch (hw->revision_id) { 315 switch (hw->revision_id) {
316 case E1000_82542_2_0_REV_ID: 316 case E1000_82542_2_0_REV_ID:
317 hw->mac_type = e1000_82542_rev2_0; 317 hw->mac_type = e1000_82542_rev2_0;
318 break; 318 break;
319 case E1000_82542_2_1_REV_ID: 319 case E1000_82542_2_1_REV_ID:
320 hw->mac_type = e1000_82542_rev2_1; 320 hw->mac_type = e1000_82542_rev2_1;
321 break; 321 break;
322 default: 322 default:
323 /* Invalid 82542 revision ID */ 323 /* Invalid 82542 revision ID */
324 return -E1000_ERR_MAC_TYPE; 324 return -E1000_ERR_MAC_TYPE;
325 } 325 }
326 break; 326 break;
327 case E1000_DEV_ID_82543GC_FIBER: 327 case E1000_DEV_ID_82543GC_FIBER:
328 case E1000_DEV_ID_82543GC_COPPER: 328 case E1000_DEV_ID_82543GC_COPPER:
329 hw->mac_type = e1000_82543; 329 hw->mac_type = e1000_82543;
330 break; 330 break;
331 case E1000_DEV_ID_82544EI_COPPER: 331 case E1000_DEV_ID_82544EI_COPPER:
332 case E1000_DEV_ID_82544EI_FIBER: 332 case E1000_DEV_ID_82544EI_FIBER:
333 case E1000_DEV_ID_82544GC_COPPER: 333 case E1000_DEV_ID_82544GC_COPPER:
334 case E1000_DEV_ID_82544GC_LOM: 334 case E1000_DEV_ID_82544GC_LOM:
335 hw->mac_type = e1000_82544; 335 hw->mac_type = e1000_82544;
336 break; 336 break;
337 case E1000_DEV_ID_82540EM: 337 case E1000_DEV_ID_82540EM:
338 case E1000_DEV_ID_82540EM_LOM: 338 case E1000_DEV_ID_82540EM_LOM:
339 case E1000_DEV_ID_82540EP: 339 case E1000_DEV_ID_82540EP:
340 case E1000_DEV_ID_82540EP_LOM: 340 case E1000_DEV_ID_82540EP_LOM:
341 case E1000_DEV_ID_82540EP_LP: 341 case E1000_DEV_ID_82540EP_LP:
342 hw->mac_type = e1000_82540; 342 hw->mac_type = e1000_82540;
343 break; 343 break;
344 case E1000_DEV_ID_82545EM_COPPER: 344 case E1000_DEV_ID_82545EM_COPPER:
345 case E1000_DEV_ID_82545EM_FIBER: 345 case E1000_DEV_ID_82545EM_FIBER:
346 hw->mac_type = e1000_82545; 346 hw->mac_type = e1000_82545;
347 break; 347 break;
348 case E1000_DEV_ID_82545GM_COPPER: 348 case E1000_DEV_ID_82545GM_COPPER:
349 case E1000_DEV_ID_82545GM_FIBER: 349 case E1000_DEV_ID_82545GM_FIBER:
350 case E1000_DEV_ID_82545GM_SERDES: 350 case E1000_DEV_ID_82545GM_SERDES:
351 hw->mac_type = e1000_82545_rev_3; 351 hw->mac_type = e1000_82545_rev_3;
352 break; 352 break;
353 case E1000_DEV_ID_82546EB_COPPER: 353 case E1000_DEV_ID_82546EB_COPPER:
354 case E1000_DEV_ID_82546EB_FIBER: 354 case E1000_DEV_ID_82546EB_FIBER:
355 case E1000_DEV_ID_82546EB_QUAD_COPPER: 355 case E1000_DEV_ID_82546EB_QUAD_COPPER:
356 hw->mac_type = e1000_82546; 356 hw->mac_type = e1000_82546;
357 break; 357 break;
358 case E1000_DEV_ID_82546GB_COPPER: 358 case E1000_DEV_ID_82546GB_COPPER:
359 case E1000_DEV_ID_82546GB_FIBER: 359 case E1000_DEV_ID_82546GB_FIBER:
360 case E1000_DEV_ID_82546GB_SERDES: 360 case E1000_DEV_ID_82546GB_SERDES:
361 case E1000_DEV_ID_82546GB_PCIE: 361 case E1000_DEV_ID_82546GB_PCIE:
362 case E1000_DEV_ID_82546GB_QUAD_COPPER: 362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: 363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
364 hw->mac_type = e1000_82546_rev_3; 364 hw->mac_type = e1000_82546_rev_3;
365 break; 365 break;
366 case E1000_DEV_ID_82541EI: 366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE: 367 case E1000_DEV_ID_82541EI_MOBILE:
368 case E1000_DEV_ID_82541ER_LOM: 368 case E1000_DEV_ID_82541ER_LOM:
369 hw->mac_type = e1000_82541; 369 hw->mac_type = e1000_82541;
370 break; 370 break;
371 case E1000_DEV_ID_82541ER: 371 case E1000_DEV_ID_82541ER:
372 case E1000_DEV_ID_82541GI: 372 case E1000_DEV_ID_82541GI:
373 case E1000_DEV_ID_82541GI_LF: 373 case E1000_DEV_ID_82541GI_LF:
374 case E1000_DEV_ID_82541GI_MOBILE: 374 case E1000_DEV_ID_82541GI_MOBILE:
375 hw->mac_type = e1000_82541_rev_2; 375 hw->mac_type = e1000_82541_rev_2;
376 break; 376 break;
377 case E1000_DEV_ID_82547EI: 377 case E1000_DEV_ID_82547EI:
378 case E1000_DEV_ID_82547EI_MOBILE: 378 case E1000_DEV_ID_82547EI_MOBILE:
379 hw->mac_type = e1000_82547; 379 hw->mac_type = e1000_82547;
380 break; 380 break;
381 case E1000_DEV_ID_82547GI: 381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2; 382 hw->mac_type = e1000_82547_rev_2;
383 break; 383 break;
384 case E1000_DEV_ID_82571EB_COPPER: 384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER: 385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES: 386 case E1000_DEV_ID_82571EB_SERDES:
387 case E1000_DEV_ID_82571EB_QUAD_COPPER: 387 case E1000_DEV_ID_82571EB_QUAD_COPPER:
388 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: 388 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
389 hw->mac_type = e1000_82571; 389 hw->mac_type = e1000_82571;
390 break; 390 break;
391 case E1000_DEV_ID_82572EI_COPPER: 391 case E1000_DEV_ID_82572EI_COPPER:
392 case E1000_DEV_ID_82572EI_FIBER: 392 case E1000_DEV_ID_82572EI_FIBER:
393 case E1000_DEV_ID_82572EI_SERDES: 393 case E1000_DEV_ID_82572EI_SERDES:
394 case E1000_DEV_ID_82572EI: 394 case E1000_DEV_ID_82572EI:
395 hw->mac_type = e1000_82572; 395 hw->mac_type = e1000_82572;
396 break; 396 break;
397 case E1000_DEV_ID_82573E: 397 case E1000_DEV_ID_82573E:
398 case E1000_DEV_ID_82573E_IAMT: 398 case E1000_DEV_ID_82573E_IAMT:
399 case E1000_DEV_ID_82573L: 399 case E1000_DEV_ID_82573L:
400 hw->mac_type = e1000_82573; 400 hw->mac_type = e1000_82573;
401 break; 401 break;
402 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT: 402 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
403 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT: 403 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
404 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT: 404 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
405 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: 405 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
406 hw->mac_type = e1000_80003es2lan; 406 hw->mac_type = e1000_80003es2lan;
407 break; 407 break;
408 case E1000_DEV_ID_ICH8_IGP_M_AMT: 408 case E1000_DEV_ID_ICH8_IGP_M_AMT:
409 case E1000_DEV_ID_ICH8_IGP_AMT: 409 case E1000_DEV_ID_ICH8_IGP_AMT:
410 case E1000_DEV_ID_ICH8_IGP_C: 410 case E1000_DEV_ID_ICH8_IGP_C:
411 case E1000_DEV_ID_ICH8_IFE: 411 case E1000_DEV_ID_ICH8_IFE:
412 case E1000_DEV_ID_ICH8_IFE_GT: 412 case E1000_DEV_ID_ICH8_IFE_GT:
413 case E1000_DEV_ID_ICH8_IFE_G: 413 case E1000_DEV_ID_ICH8_IFE_G:
414 case E1000_DEV_ID_ICH8_IGP_M: 414 case E1000_DEV_ID_ICH8_IGP_M:
415 hw->mac_type = e1000_ich8lan; 415 hw->mac_type = e1000_ich8lan;
416 break; 416 break;
417 default: 417 default:
418 /* Should never have loaded on this device */ 418 /* Should never have loaded on this device */
419 return -E1000_ERR_MAC_TYPE; 419 return -E1000_ERR_MAC_TYPE;
420 } 420 }
421 421
422 switch (hw->mac_type) { 422 switch (hw->mac_type) {
423 case e1000_ich8lan: 423 case e1000_ich8lan:
424 hw->swfwhw_semaphore_present = TRUE; 424 hw->swfwhw_semaphore_present = TRUE;
425 hw->asf_firmware_present = TRUE; 425 hw->asf_firmware_present = TRUE;
426 break; 426 break;
427 case e1000_80003es2lan: 427 case e1000_80003es2lan:
428 hw->swfw_sync_present = TRUE; 428 hw->swfw_sync_present = TRUE;
429 /* fall through */ 429 /* fall through */
430 case e1000_82571: 430 case e1000_82571:
431 case e1000_82572: 431 case e1000_82572:
432 case e1000_82573: 432 case e1000_82573:
433 hw->eeprom_semaphore_present = TRUE; 433 hw->eeprom_semaphore_present = TRUE;
434 /* fall through */ 434 /* fall through */
435 case e1000_82541: 435 case e1000_82541:
436 case e1000_82547: 436 case e1000_82547:
437 case e1000_82541_rev_2: 437 case e1000_82541_rev_2:
438 case e1000_82547_rev_2: 438 case e1000_82547_rev_2:
439 hw->asf_firmware_present = TRUE; 439 hw->asf_firmware_present = TRUE;
440 break; 440 break;
441 default: 441 default:
442 break; 442 break;
443 } 443 }
444 444
445 return E1000_SUCCESS; 445 /* The 82543 chip does not count tx_carrier_errors properly in
446 * FD mode
447 */
448 if (hw->mac_type == e1000_82543)
449 hw->bad_tx_carr_stats_fd = TRUE;
450
451 /* capable of receiving management packets to the host */
452 if (hw->mac_type >= e1000_82571)
453 hw->has_manc2h = TRUE;
454
455 /* In rare occasions, ESB2 systems would end up started without
456 * the RX unit being turned on.
457 */
458 if (hw->mac_type == e1000_80003es2lan)
459 hw->rx_needs_kicking = TRUE;
460
461 if (hw->mac_type > e1000_82544)
462 hw->has_smbus = TRUE;
463
464 return E1000_SUCCESS;
446} 465}
447 466
448/***************************************************************************** 467/*****************************************************************************
@@ -6575,7 +6594,7 @@ e1000_get_bus_info(struct e1000_hw *hw)
6575 switch (hw->mac_type) { 6594 switch (hw->mac_type) {
6576 case e1000_82542_rev2_0: 6595 case e1000_82542_rev2_0:
6577 case e1000_82542_rev2_1: 6596 case e1000_82542_rev2_1:
6578 hw->bus_type = e1000_bus_type_unknown; 6597 hw->bus_type = e1000_bus_type_pci;
6579 hw->bus_speed = e1000_bus_speed_unknown; 6598 hw->bus_speed = e1000_bus_speed_unknown;
6580 hw->bus_width = e1000_bus_width_unknown; 6599 hw->bus_width = e1000_bus_width_unknown;
6581 break; 6600 break;
@@ -7817,9 +7836,8 @@ e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7817 fwsm = E1000_READ_REG(hw, FWSM); 7836 fwsm = E1000_READ_REG(hw, FWSM);
7818 factps = E1000_READ_REG(hw, FACTPS); 7837 factps = E1000_READ_REG(hw, FACTPS);
7819 7838
7820 if (((fwsm & E1000_FWSM_MODE_MASK) == 7839 if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) ==
7821 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) && 7840 e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG))
7822 (factps & E1000_FACTPS_MNGCG))
7823 return TRUE; 7841 return TRUE;
7824 } else 7842 } else
7825 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) 7843 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index 3321fb13bf..d671058833 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -1301,165 +1301,170 @@ struct e1000_ffvt_entry {
1301#define E1000_82542_RSSIR E1000_RSSIR 1301#define E1000_82542_RSSIR E1000_RSSIR
1302#define E1000_82542_KUMCTRLSTA E1000_KUMCTRLSTA 1302#define E1000_82542_KUMCTRLSTA E1000_KUMCTRLSTA
1303#define E1000_82542_SW_FW_SYNC E1000_SW_FW_SYNC 1303#define E1000_82542_SW_FW_SYNC E1000_SW_FW_SYNC
1304#define E1000_82542_MANC2H E1000_MANC2H
1304 1305
1305/* Statistics counters collected by the MAC */ 1306/* Statistics counters collected by the MAC */
1306struct e1000_hw_stats { 1307struct e1000_hw_stats {
1307 uint64_t crcerrs; 1308 uint64_t crcerrs;
1308 uint64_t algnerrc; 1309 uint64_t algnerrc;
1309 uint64_t symerrs; 1310 uint64_t symerrs;
1310 uint64_t rxerrc; 1311 uint64_t rxerrc;
1311 uint64_t txerrc; 1312 uint64_t txerrc;
1312 uint64_t mpc; 1313 uint64_t mpc;
1313 uint64_t scc; 1314 uint64_t scc;
1314 uint64_t ecol; 1315 uint64_t ecol;
1315 uint64_t mcc; 1316 uint64_t mcc;
1316 uint64_t latecol; 1317 uint64_t latecol;
1317 uint64_t colc; 1318 uint64_t colc;
1318 uint64_t dc; 1319 uint64_t dc;
1319 uint64_t tncrs; 1320 uint64_t tncrs;
1320 uint64_t sec; 1321 uint64_t sec;
1321 uint64_t cexterr; 1322 uint64_t cexterr;
1322 uint64_t rlec; 1323 uint64_t rlec;
1323 uint64_t xonrxc; 1324 uint64_t xonrxc;
1324 uint64_t xontxc; 1325 uint64_t xontxc;
1325 uint64_t xoffrxc; 1326 uint64_t xoffrxc;
1326 uint64_t xofftxc; 1327 uint64_t xofftxc;
1327 uint64_t fcruc; 1328 uint64_t fcruc;
1328 uint64_t prc64; 1329 uint64_t prc64;
1329 uint64_t prc127; 1330 uint64_t prc127;
1330 uint64_t prc255; 1331 uint64_t prc255;
1331 uint64_t prc511; 1332 uint64_t prc511;
1332 uint64_t prc1023; 1333 uint64_t prc1023;
1333 uint64_t prc1522; 1334 uint64_t prc1522;
1334 uint64_t gprc; 1335 uint64_t gprc;
1335 uint64_t bprc; 1336 uint64_t bprc;
1336 uint64_t mprc; 1337 uint64_t mprc;
1337 uint64_t gptc; 1338 uint64_t gptc;
1338 uint64_t gorcl; 1339 uint64_t gorcl;
1339 uint64_t gorch; 1340 uint64_t gorch;
1340 uint64_t gotcl; 1341 uint64_t gotcl;
1341 uint64_t gotch; 1342 uint64_t gotch;
1342 uint64_t rnbc; 1343 uint64_t rnbc;
1343 uint64_t ruc; 1344 uint64_t ruc;
1344 uint64_t rfc; 1345 uint64_t rfc;
1345 uint64_t roc; 1346 uint64_t roc;
1346 uint64_t rlerrc; 1347 uint64_t rlerrc;
1347 uint64_t rjc; 1348 uint64_t rjc;
1348 uint64_t mgprc; 1349 uint64_t mgprc;
1349 uint64_t mgpdc; 1350 uint64_t mgpdc;
1350 uint64_t mgptc; 1351 uint64_t mgptc;
1351 uint64_t torl; 1352 uint64_t torl;
1352 uint64_t torh; 1353 uint64_t torh;
1353 uint64_t totl; 1354 uint64_t totl;
1354 uint64_t toth; 1355 uint64_t toth;
1355 uint64_t tpr; 1356 uint64_t tpr;
1356 uint64_t tpt; 1357 uint64_t tpt;
1357 uint64_t ptc64; 1358 uint64_t ptc64;
1358 uint64_t ptc127; 1359 uint64_t ptc127;
1359 uint64_t ptc255; 1360 uint64_t ptc255;
1360 uint64_t ptc511; 1361 uint64_t ptc511;
1361 uint64_t ptc1023; 1362 uint64_t ptc1023;
1362 uint64_t ptc1522; 1363 uint64_t ptc1522;
1363 uint64_t mptc; 1364 uint64_t mptc;
1364 uint64_t bptc; 1365 uint64_t bptc;
1365 uint64_t tsctc; 1366 uint64_t tsctc;
1366 uint64_t tsctfc; 1367 uint64_t tsctfc;
1367 uint64_t iac; 1368 uint64_t iac;
1368 uint64_t icrxptc; 1369 uint64_t icrxptc;
1369 uint64_t icrxatc; 1370 uint64_t icrxatc;
1370 uint64_t ictxptc; 1371 uint64_t ictxptc;
1371 uint64_t ictxatc; 1372 uint64_t ictxatc;
1372 uint64_t ictxqec; 1373 uint64_t ictxqec;
1373 uint64_t ictxqmtc; 1374 uint64_t ictxqmtc;
1374 uint64_t icrxdmtc; 1375 uint64_t icrxdmtc;
1375 uint64_t icrxoc; 1376 uint64_t icrxoc;
1376}; 1377};
1377 1378
1378/* Structure containing variables used by the shared code (e1000_hw.c) */ 1379/* Structure containing variables used by the shared code (e1000_hw.c) */
1379struct e1000_hw { 1380struct e1000_hw {
1380 uint8_t __iomem *hw_addr; 1381 uint8_t __iomem *hw_addr;
1381 uint8_t __iomem *flash_address; 1382 uint8_t __iomem *flash_address;
1382 e1000_mac_type mac_type; 1383 e1000_mac_type mac_type;
1383 e1000_phy_type phy_type; 1384 e1000_phy_type phy_type;
1384 uint32_t phy_init_script; 1385 uint32_t phy_init_script;
1385 e1000_media_type media_type; 1386 e1000_media_type media_type;
1386 void *back; 1387 void *back;
1387 struct e1000_shadow_ram *eeprom_shadow_ram; 1388 struct e1000_shadow_ram *eeprom_shadow_ram;
1388 uint32_t flash_bank_size; 1389 uint32_t flash_bank_size;
1389 uint32_t flash_base_addr; 1390 uint32_t flash_base_addr;
1390 e1000_fc_type fc; 1391 e1000_fc_type fc;
1391 e1000_bus_speed bus_speed; 1392 e1000_bus_speed bus_speed;
1392 e1000_bus_width bus_width; 1393 e1000_bus_width bus_width;
1393 e1000_bus_type bus_type; 1394 e1000_bus_type bus_type;
1394 struct e1000_eeprom_info eeprom; 1395 struct e1000_eeprom_info eeprom;
1395 e1000_ms_type master_slave; 1396 e1000_ms_type master_slave;
1396 e1000_ms_type original_master_slave; 1397 e1000_ms_type original_master_slave;
1397 e1000_ffe_config ffe_config_state; 1398 e1000_ffe_config ffe_config_state;
1398 uint32_t asf_firmware_present; 1399 uint32_t asf_firmware_present;
1399 uint32_t eeprom_semaphore_present; 1400 uint32_t eeprom_semaphore_present;
1400 uint32_t swfw_sync_present; 1401 uint32_t swfw_sync_present;
1401 uint32_t swfwhw_semaphore_present; 1402 uint32_t swfwhw_semaphore_present;
1402 unsigned long io_base; 1403 unsigned long io_base;
1403 uint32_t phy_id; 1404 uint32_t phy_id;
1404 uint32_t phy_revision; 1405 uint32_t phy_revision;
1405 uint32_t phy_addr; 1406 uint32_t phy_addr;
1406 uint32_t original_fc; 1407 uint32_t original_fc;
1407 uint32_t txcw; 1408 uint32_t txcw;
1408 uint32_t autoneg_failed; 1409 uint32_t autoneg_failed;
1409 uint32_t max_frame_size; 1410 uint32_t max_frame_size;
1410 uint32_t min_frame_size; 1411 uint32_t min_frame_size;
1411 uint32_t mc_filter_type; 1412 uint32_t mc_filter_type;
1412 uint32_t num_mc_addrs; 1413 uint32_t num_mc_addrs;
1413 uint32_t collision_delta; 1414 uint32_t collision_delta;
1414 uint32_t tx_packet_delta; 1415 uint32_t tx_packet_delta;
1415 uint32_t ledctl_default; 1416 uint32_t ledctl_default;
1416 uint32_t ledctl_mode1; 1417 uint32_t ledctl_mode1;
1417 uint32_t ledctl_mode2; 1418 uint32_t ledctl_mode2;
1418 boolean_t tx_pkt_filtering; 1419 boolean_t tx_pkt_filtering;
1419 struct e1000_host_mng_dhcp_cookie mng_cookie; 1420 struct e1000_host_mng_dhcp_cookie mng_cookie;
1420 uint16_t phy_spd_default; 1421 uint16_t phy_spd_default;
1421 uint16_t autoneg_advertised; 1422 uint16_t autoneg_advertised;
1422 uint16_t pci_cmd_word; 1423 uint16_t pci_cmd_word;
1423 uint16_t fc_high_water; 1424 uint16_t fc_high_water;
1424 uint16_t fc_low_water; 1425 uint16_t fc_low_water;
1425 uint16_t fc_pause_time; 1426 uint16_t fc_pause_time;
1426 uint16_t current_ifs_val; 1427 uint16_t current_ifs_val;
1427 uint16_t ifs_min_val; 1428 uint16_t ifs_min_val;
1428 uint16_t ifs_max_val; 1429 uint16_t ifs_max_val;
1429 uint16_t ifs_step_size; 1430 uint16_t ifs_step_size;
1430 uint16_t ifs_ratio; 1431 uint16_t ifs_ratio;
1431 uint16_t device_id; 1432 uint16_t device_id;
1432 uint16_t vendor_id; 1433 uint16_t vendor_id;
1433 uint16_t subsystem_id; 1434 uint16_t subsystem_id;
1434 uint16_t subsystem_vendor_id; 1435 uint16_t subsystem_vendor_id;
1435 uint8_t revision_id; 1436 uint8_t revision_id;
1436 uint8_t autoneg; 1437 uint8_t autoneg;
1437 uint8_t mdix; 1438 uint8_t mdix;
1438 uint8_t forced_speed_duplex; 1439 uint8_t forced_speed_duplex;
1439 uint8_t wait_autoneg_complete; 1440 uint8_t wait_autoneg_complete;
1440 uint8_t dma_fairness; 1441 uint8_t dma_fairness;
1441 uint8_t mac_addr[NODE_ADDRESS_SIZE]; 1442 uint8_t mac_addr[NODE_ADDRESS_SIZE];
1442 uint8_t perm_mac_addr[NODE_ADDRESS_SIZE]; 1443 uint8_t perm_mac_addr[NODE_ADDRESS_SIZE];
1443 boolean_t disable_polarity_correction; 1444 boolean_t disable_polarity_correction;
1444 boolean_t speed_downgraded; 1445 boolean_t speed_downgraded;
1445 e1000_smart_speed smart_speed; 1446 e1000_smart_speed smart_speed;
1446 e1000_dsp_config dsp_config_state; 1447 e1000_dsp_config dsp_config_state;
1447 boolean_t get_link_status; 1448 boolean_t get_link_status;
1448 boolean_t serdes_link_down; 1449 boolean_t serdes_link_down;
1449 boolean_t tbi_compatibility_en; 1450 boolean_t tbi_compatibility_en;
1450 boolean_t tbi_compatibility_on; 1451 boolean_t tbi_compatibility_on;
1451 boolean_t laa_is_present; 1452 boolean_t laa_is_present;
1452 boolean_t phy_reset_disable; 1453 boolean_t phy_reset_disable;
1453 boolean_t initialize_hw_bits_disable; 1454 boolean_t initialize_hw_bits_disable;
1454 boolean_t fc_send_xon; 1455 boolean_t fc_send_xon;
1455 boolean_t fc_strict_ieee; 1456 boolean_t fc_strict_ieee;
1456 boolean_t report_tx_early; 1457 boolean_t report_tx_early;
1457 boolean_t adaptive_ifs; 1458 boolean_t adaptive_ifs;
1458 boolean_t ifs_params_forced; 1459 boolean_t ifs_params_forced;
1459 boolean_t in_ifs_mode; 1460 boolean_t in_ifs_mode;
1460 boolean_t mng_reg_access_disabled; 1461 boolean_t mng_reg_access_disabled;
1461 boolean_t leave_av_bit_off; 1462 boolean_t leave_av_bit_off;
1462 boolean_t kmrn_lock_loss_workaround_disabled; 1463 boolean_t kmrn_lock_loss_workaround_disabled;
1464 boolean_t bad_tx_carr_stats_fd;
1465 boolean_t has_manc2h;
1466 boolean_t rx_needs_kicking;
1467 boolean_t has_smbus;
1463}; 1468};
1464 1469
1465 1470
@@ -2418,6 +2423,7 @@ struct e1000_host_command_info {
2418#define E1000_PBA_8K 0x0008 /* 8KB, default Rx allocation */ 2423#define E1000_PBA_8K 0x0008 /* 8KB, default Rx allocation */
2419#define E1000_PBA_12K 0x000C /* 12KB, default Rx allocation */ 2424#define E1000_PBA_12K 0x000C /* 12KB, default Rx allocation */
2420#define E1000_PBA_16K 0x0010 /* 16KB, default TX allocation */ 2425#define E1000_PBA_16K 0x0010 /* 16KB, default TX allocation */
2426#define E1000_PBA_20K 0x0014
2421#define E1000_PBA_22K 0x0016 2427#define E1000_PBA_22K 0x0016
2422#define E1000_PBA_24K 0x0018 2428#define E1000_PBA_24K 0x0018
2423#define E1000_PBA_30K 0x001E 2429#define E1000_PBA_30K 0x001E
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 73f3a85fd2..c6259c7127 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -213,6 +213,12 @@ static void e1000_netpoll (struct net_device *netdev);
213 213
214extern void e1000_check_options(struct e1000_adapter *adapter); 214extern void e1000_check_options(struct e1000_adapter *adapter);
215 215
216#define COPYBREAK_DEFAULT 256
217static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
218module_param(copybreak, uint, 0644);
219MODULE_PARM_DESC(copybreak,
220 "Maximum size of packet that is copied to a new buffer on receive");
221
216static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, 222static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
217 pci_channel_state_t state); 223 pci_channel_state_t state);
218static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev); 224static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
@@ -264,7 +270,13 @@ e1000_init_module(void)
264 printk(KERN_INFO "%s\n", e1000_copyright); 270 printk(KERN_INFO "%s\n", e1000_copyright);
265 271
266 ret = pci_register_driver(&e1000_driver); 272 ret = pci_register_driver(&e1000_driver);
267 273 if (copybreak != COPYBREAK_DEFAULT) {
274 if (copybreak == 0)
275 printk(KERN_INFO "e1000: copybreak disabled\n");
276 else
277 printk(KERN_INFO "e1000: copybreak enabled for "
278 "packets <= %u bytes\n", copybreak);
279 }
268 return ret; 280 return ret;
269} 281}
270 282
@@ -464,6 +476,52 @@ e1000_get_hw_control(struct e1000_adapter *adapter)
464 } 476 }
465} 477}
466 478
479static void
480e1000_init_manageability(struct e1000_adapter *adapter)
481{
482 if (adapter->en_mng_pt) {
483 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
484
485 /* disable hardware interception of ARP */
486 manc &= ~(E1000_MANC_ARP_EN);
487
488 /* enable receiving management packets to the host */
489 /* this will probably generate destination unreachable messages
490 * from the host OS, but the packets will be handled on SMBUS */
491 if (adapter->hw.has_manc2h) {
492 uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
493
494 manc |= E1000_MANC_EN_MNG2HOST;
495#define E1000_MNG2HOST_PORT_623 (1 << 5)
496#define E1000_MNG2HOST_PORT_664 (1 << 6)
497 manc2h |= E1000_MNG2HOST_PORT_623;
498 manc2h |= E1000_MNG2HOST_PORT_664;
499 E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
500 }
501
502 E1000_WRITE_REG(&adapter->hw, MANC, manc);
503 }
504}
505
506static void
507e1000_release_manageability(struct e1000_adapter *adapter)
508{
509 if (adapter->en_mng_pt) {
510 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
511
512 /* re-enable hardware interception of ARP */
513 manc |= E1000_MANC_ARP_EN;
514
515 if (adapter->hw.has_manc2h)
516 manc &= ~E1000_MANC_EN_MNG2HOST;
517
518 /* don't explicitly have to mess with MANC2H since
519 * MANC has an enable disable that gates MANC2H */
520
521 E1000_WRITE_REG(&adapter->hw, MANC, manc);
522 }
523}
524
467int 525int
468e1000_up(struct e1000_adapter *adapter) 526e1000_up(struct e1000_adapter *adapter)
469{ 527{
@@ -475,6 +533,7 @@ e1000_up(struct e1000_adapter *adapter)
475 e1000_set_multi(netdev); 533 e1000_set_multi(netdev);
476 534
477 e1000_restore_vlan(adapter); 535 e1000_restore_vlan(adapter);
536 e1000_init_manageability(adapter);
478 537
479 e1000_configure_tx(adapter); 538 e1000_configure_tx(adapter);
480 e1000_setup_rctl(adapter); 539 e1000_setup_rctl(adapter);
@@ -497,7 +556,8 @@ e1000_up(struct e1000_adapter *adapter)
497 556
498 clear_bit(__E1000_DOWN, &adapter->flags); 557 clear_bit(__E1000_DOWN, &adapter->flags);
499 558
500 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); 559 /* fire a link change interrupt to start the watchdog */
560 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
501 return 0; 561 return 0;
502} 562}
503 563
@@ -614,16 +674,34 @@ e1000_reinit_locked(struct e1000_adapter *adapter)
614void 674void
615e1000_reset(struct e1000_adapter *adapter) 675e1000_reset(struct e1000_adapter *adapter)
616{ 676{
617 uint32_t pba, manc; 677 uint32_t pba = 0, tx_space, min_tx_space, min_rx_space;
618 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF; 678 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
679 boolean_t legacy_pba_adjust = FALSE;
619 680
620 /* Repartition Pba for greater than 9k mtu 681 /* Repartition Pba for greater than 9k mtu
621 * To take effect CTRL.RST is required. 682 * To take effect CTRL.RST is required.
622 */ 683 */
623 684
624 switch (adapter->hw.mac_type) { 685 switch (adapter->hw.mac_type) {
686 case e1000_82542_rev2_0:
687 case e1000_82542_rev2_1:
688 case e1000_82543:
689 case e1000_82544:
690 case e1000_82540:
691 case e1000_82541:
692 case e1000_82541_rev_2:
693 legacy_pba_adjust = TRUE;
694 pba = E1000_PBA_48K;
695 break;
696 case e1000_82545:
697 case e1000_82545_rev_3:
698 case e1000_82546:
699 case e1000_82546_rev_3:
700 pba = E1000_PBA_48K;
701 break;
625 case e1000_82547: 702 case e1000_82547:
626 case e1000_82547_rev_2: 703 case e1000_82547_rev_2:
704 legacy_pba_adjust = TRUE;
627 pba = E1000_PBA_30K; 705 pba = E1000_PBA_30K;
628 break; 706 break;
629 case e1000_82571: 707 case e1000_82571:
@@ -632,27 +710,80 @@ e1000_reset(struct e1000_adapter *adapter)
632 pba = E1000_PBA_38K; 710 pba = E1000_PBA_38K;
633 break; 711 break;
634 case e1000_82573: 712 case e1000_82573:
635 pba = E1000_PBA_12K; 713 pba = E1000_PBA_20K;
636 break; 714 break;
637 case e1000_ich8lan: 715 case e1000_ich8lan:
638 pba = E1000_PBA_8K; 716 pba = E1000_PBA_8K;
639 break; 717 case e1000_undefined:
640 default: 718 case e1000_num_macs:
641 pba = E1000_PBA_48K;
642 break; 719 break;
643 } 720 }
644 721
645 if ((adapter->hw.mac_type != e1000_82573) && 722 if (legacy_pba_adjust == TRUE) {
646 (adapter->netdev->mtu > E1000_RXBUFFER_8192)) 723 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
647 pba -= 8; /* allocate more FIFO for Tx */ 724 pba -= 8; /* allocate more FIFO for Tx */
648 725
726 if (adapter->hw.mac_type == e1000_82547) {
727 adapter->tx_fifo_head = 0;
728 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
729 adapter->tx_fifo_size =
730 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
731 atomic_set(&adapter->tx_fifo_stall, 0);
732 }
733 } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
734 /* adjust PBA for jumbo frames */
735 E1000_WRITE_REG(&adapter->hw, PBA, pba);
736
737 /* To maintain wire speed transmits, the Tx FIFO should be
738 * large enough to accomodate two full transmit packets,
739 * rounded up to the next 1KB and expressed in KB. Likewise,
740 * the Rx FIFO should be large enough to accomodate at least
741 * one full receive packet and is similarly rounded up and
742 * expressed in KB. */
743 pba = E1000_READ_REG(&adapter->hw, PBA);
744 /* upper 16 bits has Tx packet buffer allocation size in KB */
745 tx_space = pba >> 16;
746 /* lower 16 bits has Rx packet buffer allocation size in KB */
747 pba &= 0xffff;
748 /* don't include ethernet FCS because hardware appends/strips */
749 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
750 VLAN_TAG_SIZE;
751 min_tx_space = min_rx_space;
752 min_tx_space *= 2;
753 E1000_ROUNDUP(min_tx_space, 1024);
754 min_tx_space >>= 10;
755 E1000_ROUNDUP(min_rx_space, 1024);
756 min_rx_space >>= 10;
757
758 /* If current Tx allocation is less than the min Tx FIFO size,
759 * and the min Tx FIFO size is less than the current Rx FIFO
760 * allocation, take space away from current Rx allocation */
761 if (tx_space < min_tx_space &&
762 ((min_tx_space - tx_space) < pba)) {
763 pba = pba - (min_tx_space - tx_space);
764
765 /* PCI/PCIx hardware has PBA alignment constraints */
766 switch (adapter->hw.mac_type) {
767 case e1000_82545 ... e1000_82546_rev_3:
768 pba &= ~(E1000_PBA_8K - 1);
769 break;
770 default:
771 break;
772 }
649 773
650 if (adapter->hw.mac_type == e1000_82547) { 774 /* if short on rx space, rx wins and must trump tx
651 adapter->tx_fifo_head = 0; 775 * adjustment or use Early Receive if available */
652 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; 776 if (pba < min_rx_space) {
653 adapter->tx_fifo_size = 777 switch (adapter->hw.mac_type) {
654 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; 778 case e1000_82573:
655 atomic_set(&adapter->tx_fifo_stall, 0); 779 /* ERT enabled in e1000_configure_rx */
780 break;
781 default:
782 pba = min_rx_space;
783 break;
784 }
785 }
786 }
656 } 787 }
657 788
658 E1000_WRITE_REG(&adapter->hw, PBA, pba); 789 E1000_WRITE_REG(&adapter->hw, PBA, pba);
@@ -685,6 +816,20 @@ e1000_reset(struct e1000_adapter *adapter)
685 if (e1000_init_hw(&adapter->hw)) 816 if (e1000_init_hw(&adapter->hw))
686 DPRINTK(PROBE, ERR, "Hardware Error\n"); 817 DPRINTK(PROBE, ERR, "Hardware Error\n");
687 e1000_update_mng_vlan(adapter); 818 e1000_update_mng_vlan(adapter);
819
820 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
821 if (adapter->hw.mac_type >= e1000_82544 &&
822 adapter->hw.mac_type <= e1000_82547_rev_2 &&
823 adapter->hw.autoneg == 1 &&
824 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
825 uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
826 /* clear phy power management bit if we are in gig only mode,
827 * which if enabled will attempt negotiation to 100Mb, which
828 * can cause a loss of link at power off or driver unload */
829 ctrl &= ~E1000_CTRL_SWDPIN3;
830 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
831 }
832
688 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ 833 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
689 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE); 834 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
690 835
@@ -705,14 +850,7 @@ e1000_reset(struct e1000_adapter *adapter)
705 phy_data); 850 phy_data);
706 } 851 }
707 852
708 if ((adapter->en_mng_pt) && 853 e1000_release_manageability(adapter);
709 (adapter->hw.mac_type >= e1000_82540) &&
710 (adapter->hw.mac_type < e1000_82571) &&
711 (adapter->hw.media_type == e1000_media_type_copper)) {
712 manc = E1000_READ_REG(&adapter->hw, MANC);
713 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
714 E1000_WRITE_REG(&adapter->hw, MANC, manc);
715 }
716} 854}
717 855
718/** 856/**
@@ -1078,22 +1216,13 @@ e1000_remove(struct pci_dev *pdev)
1078{ 1216{
1079 struct net_device *netdev = pci_get_drvdata(pdev); 1217 struct net_device *netdev = pci_get_drvdata(pdev);
1080 struct e1000_adapter *adapter = netdev_priv(netdev); 1218 struct e1000_adapter *adapter = netdev_priv(netdev);
1081 uint32_t manc;
1082#ifdef CONFIG_E1000_NAPI 1219#ifdef CONFIG_E1000_NAPI
1083 int i; 1220 int i;
1084#endif 1221#endif
1085 1222
1086 flush_scheduled_work(); 1223 flush_scheduled_work();
1087 1224
1088 if (adapter->hw.mac_type >= e1000_82540 && 1225 e1000_release_manageability(adapter);
1089 adapter->hw.mac_type < e1000_82571 &&
1090 adapter->hw.media_type == e1000_media_type_copper) {
1091 manc = E1000_READ_REG(&adapter->hw, MANC);
1092 if (manc & E1000_MANC_SMBUS_EN) {
1093 manc |= E1000_MANC_ARP_EN;
1094 E1000_WRITE_REG(&adapter->hw, MANC, manc);
1095 }
1096 }
1097 1226
1098 /* Release control of h/w to f/w. If f/w is AMT enabled, this 1227 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1099 * would have already happened in close and is redundant. */ 1228 * would have already happened in close and is redundant. */
@@ -1531,9 +1660,9 @@ e1000_configure_tx(struct e1000_adapter *adapter)
1531 } 1660 }
1532 1661
1533 /* Set the default values for the Tx Inter Packet Gap timer */ 1662 /* Set the default values for the Tx Inter Packet Gap timer */
1534 1663 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
1535 if (hw->media_type == e1000_media_type_fiber || 1664 (hw->media_type == e1000_media_type_fiber ||
1536 hw->media_type == e1000_media_type_internal_serdes) 1665 hw->media_type == e1000_media_type_internal_serdes))
1537 tipg = DEFAULT_82543_TIPG_IPGT_FIBER; 1666 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1538 else 1667 else
1539 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; 1668 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
@@ -2528,6 +2657,13 @@ e1000_watchdog(unsigned long data)
2528 netif_wake_queue(netdev); 2657 netif_wake_queue(netdev);
2529 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ); 2658 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2530 adapter->smartspeed = 0; 2659 adapter->smartspeed = 0;
2660 } else {
2661 /* make sure the receive unit is started */
2662 if (adapter->hw.rx_needs_kicking) {
2663 struct e1000_hw *hw = &adapter->hw;
2664 uint32_t rctl = E1000_READ_REG(hw, RCTL);
2665 E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
2666 }
2531 } 2667 }
2532 } else { 2668 } else {
2533 if (netif_carrier_ok(netdev)) { 2669 if (netif_carrier_ok(netdev)) {
@@ -2628,29 +2764,34 @@ static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2628 if (packets == 0) 2764 if (packets == 0)
2629 goto update_itr_done; 2765 goto update_itr_done;
2630 2766
2631
2632 switch (itr_setting) { 2767 switch (itr_setting) {
2633 case lowest_latency: 2768 case lowest_latency:
2634 if ((packets < 5) && (bytes > 512)) 2769 /* jumbo frames get bulk treatment*/
2770 if (bytes/packets > 8000)
2771 retval = bulk_latency;
2772 else if ((packets < 5) && (bytes > 512))
2635 retval = low_latency; 2773 retval = low_latency;
2636 break; 2774 break;
2637 case low_latency: /* 50 usec aka 20000 ints/s */ 2775 case low_latency: /* 50 usec aka 20000 ints/s */
2638 if (bytes > 10000) { 2776 if (bytes > 10000) {
2639 if ((packets < 10) || 2777 /* jumbo frames need bulk latency setting */
2640 ((bytes/packets) > 1200)) 2778 if (bytes/packets > 8000)
2779 retval = bulk_latency;
2780 else if ((packets < 10) || ((bytes/packets) > 1200))
2641 retval = bulk_latency; 2781 retval = bulk_latency;
2642 else if ((packets > 35)) 2782 else if ((packets > 35))
2643 retval = lowest_latency; 2783 retval = lowest_latency;
2644 } else if (packets <= 2 && bytes < 512) 2784 } else if (bytes/packets > 2000)
2785 retval = bulk_latency;
2786 else if (packets <= 2 && bytes < 512)
2645 retval = lowest_latency; 2787 retval = lowest_latency;
2646 break; 2788 break;
2647 case bulk_latency: /* 250 usec aka 4000 ints/s */ 2789 case bulk_latency: /* 250 usec aka 4000 ints/s */
2648 if (bytes > 25000) { 2790 if (bytes > 25000) {
2649 if (packets > 35) 2791 if (packets > 35)
2650 retval = low_latency; 2792 retval = low_latency;
2651 } else { 2793 } else if (bytes < 6000) {
2652 if (bytes < 6000) 2794 retval = low_latency;
2653 retval = low_latency;
2654 } 2795 }
2655 break; 2796 break;
2656 } 2797 }
@@ -2679,17 +2820,20 @@ static void e1000_set_itr(struct e1000_adapter *adapter)
2679 adapter->tx_itr, 2820 adapter->tx_itr,
2680 adapter->total_tx_packets, 2821 adapter->total_tx_packets,
2681 adapter->total_tx_bytes); 2822 adapter->total_tx_bytes);
2823 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2824 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2825 adapter->tx_itr = low_latency;
2826
2682 adapter->rx_itr = e1000_update_itr(adapter, 2827 adapter->rx_itr = e1000_update_itr(adapter,
2683 adapter->rx_itr, 2828 adapter->rx_itr,
2684 adapter->total_rx_packets, 2829 adapter->total_rx_packets,
2685 adapter->total_rx_bytes); 2830 adapter->total_rx_bytes);
2831 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2832 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2833 adapter->rx_itr = low_latency;
2686 2834
2687 current_itr = max(adapter->rx_itr, adapter->tx_itr); 2835 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2688 2836
2689 /* conservative mode eliminates the lowest_latency setting */
2690 if (current_itr == lowest_latency && (adapter->itr_setting == 3))
2691 current_itr = low_latency;
2692
2693 switch (current_itr) { 2837 switch (current_itr) {
2694 /* counts and packets in update_itr are dependent on these numbers */ 2838 /* counts and packets in update_itr are dependent on these numbers */
2695 case lowest_latency: 2839 case lowest_latency:
@@ -3168,6 +3312,16 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3168 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) { 3312 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
3169 switch (adapter->hw.mac_type) { 3313 switch (adapter->hw.mac_type) {
3170 unsigned int pull_size; 3314 unsigned int pull_size;
3315 case e1000_82544:
3316 /* Make sure we have room to chop off 4 bytes,
3317 * and that the end alignment will work out to
3318 * this hardware's requirements
3319 * NOTE: this is a TSO only workaround
3320 * if end byte alignment not correct move us
3321 * into the next dword */
3322 if ((unsigned long)(skb->tail - 1) & 4)
3323 break;
3324 /* fall through */
3171 case e1000_82571: 3325 case e1000_82571:
3172 case e1000_82572: 3326 case e1000_82572:
3173 case e1000_82573: 3327 case e1000_82573:
@@ -3419,12 +3573,11 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
3419 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; 3573 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3420 3574
3421 netdev->mtu = new_mtu; 3575 netdev->mtu = new_mtu;
3576 adapter->hw.max_frame_size = max_frame;
3422 3577
3423 if (netif_running(netdev)) 3578 if (netif_running(netdev))
3424 e1000_reinit_locked(adapter); 3579 e1000_reinit_locked(adapter);
3425 3580
3426 adapter->hw.max_frame_size = max_frame;
3427
3428 return 0; 3581 return 0;
3429} 3582}
3430 3583
@@ -3573,6 +3726,11 @@ e1000_update_stats(struct e1000_adapter *adapter)
3573 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; 3726 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3574 adapter->net_stats.tx_window_errors = adapter->stats.latecol; 3727 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3575 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; 3728 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3729 if (adapter->hw.bad_tx_carr_stats_fd &&
3730 adapter->link_duplex == FULL_DUPLEX) {
3731 adapter->net_stats.tx_carrier_errors = 0;
3732 adapter->stats.tncrs = 0;
3733 }
3576 3734
3577 /* Tx Dropped needs to be maintained elsewhere */ 3735 /* Tx Dropped needs to be maintained elsewhere */
3578 3736
@@ -3590,6 +3748,13 @@ e1000_update_stats(struct e1000_adapter *adapter)
3590 adapter->phy_stats.receive_errors += phy_tmp; 3748 adapter->phy_stats.receive_errors += phy_tmp;
3591 } 3749 }
3592 3750
3751 /* Management Stats */
3752 if (adapter->hw.has_smbus) {
3753 adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
3754 adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
3755 adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
3756 }
3757
3593 spin_unlock_irqrestore(&adapter->stats_lock, flags); 3758 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3594} 3759}
3595#ifdef CONFIG_PCI_MSI 3760#ifdef CONFIG_PCI_MSI
@@ -3868,11 +4033,11 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
3868 cleaned = (i == eop); 4033 cleaned = (i == eop);
3869 4034
3870 if (cleaned) { 4035 if (cleaned) {
3871 /* this packet count is wrong for TSO but has a 4036 struct sk_buff *skb = buffer_info->skb;
3872 * tendency to make dynamic ITR change more 4037 unsigned int segs = skb_shinfo(skb)->gso_segs;
3873 * towards bulk */ 4038 total_tx_packets += segs;
3874 total_tx_packets++; 4039 total_tx_packets++;
3875 total_tx_bytes += buffer_info->skb->len; 4040 total_tx_bytes += skb->len;
3876 } 4041 }
3877 e1000_unmap_and_free_tx_resource(adapter, buffer_info); 4042 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3878 tx_desc->upper.data = 0; 4043 tx_desc->upper.data = 0;
@@ -4094,8 +4259,7 @@ e1000_clean_rx_irq(struct e1000_adapter *adapter,
4094 /* code added for copybreak, this should improve 4259 /* code added for copybreak, this should improve
4095 * performance for small packets with large amounts 4260 * performance for small packets with large amounts
4096 * of reassembly being done in the stack */ 4261 * of reassembly being done in the stack */
4097#define E1000_CB_LENGTH 256 4262 if (length < copybreak) {
4098 if (length < E1000_CB_LENGTH) {
4099 struct sk_buff *new_skb = 4263 struct sk_buff *new_skb =
4100 netdev_alloc_skb(netdev, length + NET_IP_ALIGN); 4264 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
4101 if (new_skb) { 4265 if (new_skb) {
@@ -4253,7 +4417,7 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4253 4417
4254 /* page alloc/put takes too long and effects small packet 4418 /* page alloc/put takes too long and effects small packet
4255 * throughput, so unsplit small packets and save the alloc/put*/ 4419 * throughput, so unsplit small packets and save the alloc/put*/
4256 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) { 4420 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
4257 u8 *vaddr; 4421 u8 *vaddr;
4258 /* there is no documentation about how to call 4422 /* there is no documentation about how to call
4259 * kmap_atomic, so we can't hold the mapping 4423 * kmap_atomic, so we can't hold the mapping
@@ -4998,7 +5162,7 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4998{ 5162{
4999 struct net_device *netdev = pci_get_drvdata(pdev); 5163 struct net_device *netdev = pci_get_drvdata(pdev);
5000 struct e1000_adapter *adapter = netdev_priv(netdev); 5164 struct e1000_adapter *adapter = netdev_priv(netdev);
5001 uint32_t ctrl, ctrl_ext, rctl, manc, status; 5165 uint32_t ctrl, ctrl_ext, rctl, status;
5002 uint32_t wufc = adapter->wol; 5166 uint32_t wufc = adapter->wol;
5003#ifdef CONFIG_PM 5167#ifdef CONFIG_PM
5004 int retval = 0; 5168 int retval = 0;
@@ -5067,16 +5231,12 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5067 pci_enable_wake(pdev, PCI_D3cold, 0); 5231 pci_enable_wake(pdev, PCI_D3cold, 0);
5068 } 5232 }
5069 5233
5070 if (adapter->hw.mac_type >= e1000_82540 && 5234 e1000_release_manageability(adapter);
5071 adapter->hw.mac_type < e1000_82571 && 5235
5072 adapter->hw.media_type == e1000_media_type_copper) { 5236 /* make sure adapter isn't asleep if manageability is enabled */
5073 manc = E1000_READ_REG(&adapter->hw, MANC); 5237 if (adapter->en_mng_pt) {
5074 if (manc & E1000_MANC_SMBUS_EN) { 5238 pci_enable_wake(pdev, PCI_D3hot, 1);
5075 manc |= E1000_MANC_ARP_EN; 5239 pci_enable_wake(pdev, PCI_D3cold, 1);
5076 E1000_WRITE_REG(&adapter->hw, MANC, manc);
5077 pci_enable_wake(pdev, PCI_D3hot, 1);
5078 pci_enable_wake(pdev, PCI_D3cold, 1);
5079 }
5080 } 5240 }
5081 5241
5082 if (adapter->hw.phy_type == e1000_phy_igp_3) 5242 if (adapter->hw.phy_type == e1000_phy_igp_3)
@@ -5102,7 +5262,7 @@ e1000_resume(struct pci_dev *pdev)
5102{ 5262{
5103 struct net_device *netdev = pci_get_drvdata(pdev); 5263 struct net_device *netdev = pci_get_drvdata(pdev);
5104 struct e1000_adapter *adapter = netdev_priv(netdev); 5264 struct e1000_adapter *adapter = netdev_priv(netdev);
5105 uint32_t manc, err; 5265 uint32_t err;
5106 5266
5107 pci_set_power_state(pdev, PCI_D0); 5267 pci_set_power_state(pdev, PCI_D0);
5108 e1000_pci_restore_state(adapter); 5268 e1000_pci_restore_state(adapter);
@@ -5122,19 +5282,13 @@ e1000_resume(struct pci_dev *pdev)
5122 e1000_reset(adapter); 5282 e1000_reset(adapter);
5123 E1000_WRITE_REG(&adapter->hw, WUS, ~0); 5283 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5124 5284
5285 e1000_init_manageability(adapter);
5286
5125 if (netif_running(netdev)) 5287 if (netif_running(netdev))
5126 e1000_up(adapter); 5288 e1000_up(adapter);
5127 5289
5128 netif_device_attach(netdev); 5290 netif_device_attach(netdev);
5129 5291
5130 if (adapter->hw.mac_type >= e1000_82540 &&
5131 adapter->hw.mac_type < e1000_82571 &&
5132 adapter->hw.media_type == e1000_media_type_copper) {
5133 manc = E1000_READ_REG(&adapter->hw, MANC);
5134 manc &= ~(E1000_MANC_ARP_EN);
5135 E1000_WRITE_REG(&adapter->hw, MANC, manc);
5136 }
5137
5138 /* If the controller is 82573 and f/w is AMT, do not set 5292 /* If the controller is 82573 and f/w is AMT, do not set
5139 * DRV_LOAD until the interface is up. For all other cases, 5293 * DRV_LOAD until the interface is up. For all other cases,
5140 * let the f/w know that the h/w is now under the control 5294 * let the f/w know that the h/w is now under the control
@@ -5235,7 +5389,8 @@ static void e1000_io_resume(struct pci_dev *pdev)
5235{ 5389{
5236 struct net_device *netdev = pci_get_drvdata(pdev); 5390 struct net_device *netdev = pci_get_drvdata(pdev);
5237 struct e1000_adapter *adapter = netdev->priv; 5391 struct e1000_adapter *adapter = netdev->priv;
5238 uint32_t manc, swsm; 5392
5393 e1000_init_manageability(adapter);
5239 5394
5240 if (netif_running(netdev)) { 5395 if (netif_running(netdev)) {
5241 if (e1000_up(adapter)) { 5396 if (e1000_up(adapter)) {
@@ -5246,26 +5401,14 @@ static void e1000_io_resume(struct pci_dev *pdev)
5246 5401
5247 netif_device_attach(netdev); 5402 netif_device_attach(netdev);
5248 5403
5249 if (adapter->hw.mac_type >= e1000_82540 && 5404 /* If the controller is 82573 and f/w is AMT, do not set
5250 adapter->hw.mac_type < e1000_82571 && 5405 * DRV_LOAD until the interface is up. For all other cases,
5251 adapter->hw.media_type == e1000_media_type_copper) { 5406 * let the f/w know that the h/w is now under the control
5252 manc = E1000_READ_REG(&adapter->hw, MANC); 5407 * of the driver. */
5253 manc &= ~(E1000_MANC_ARP_EN); 5408 if (adapter->hw.mac_type != e1000_82573 ||
5254 E1000_WRITE_REG(&adapter->hw, MANC, manc); 5409 !e1000_check_mng_mode(&adapter->hw))
5255 } 5410 e1000_get_hw_control(adapter);
5256
5257 switch (adapter->hw.mac_type) {
5258 case e1000_82573:
5259 swsm = E1000_READ_REG(&adapter->hw, SWSM);
5260 E1000_WRITE_REG(&adapter->hw, SWSM,
5261 swsm | E1000_SWSM_DRV_LOAD);
5262 break;
5263 default:
5264 break;
5265 }
5266 5411
5267 if (netif_running(netdev))
5268 mod_timer(&adapter->watchdog_timer, jiffies);
5269} 5412}
5270 5413
5271/* e1000_main.c */ 5414/* e1000_main.c */
diff --git a/drivers/net/e1000/e1000_param.c b/drivers/net/e1000/e1000_param.c
index cbfcd7f288..cf2a279307 100644
--- a/drivers/net/e1000/e1000_param.c
+++ b/drivers/net/e1000/e1000_param.c
@@ -487,7 +487,9 @@ e1000_check_options(struct e1000_adapter *adapter)
487 e1000_validate_option(&adapter->itr, &opt, 487 e1000_validate_option(&adapter->itr, &opt,
488 adapter); 488 adapter);
489 /* save the setting, because the dynamic bits change itr */ 489 /* save the setting, because the dynamic bits change itr */
490 adapter->itr_setting = adapter->itr; 490 /* clear the lower two bits because they are
491 * used as control */
492 adapter->itr_setting = adapter->itr & ~3;
491 break; 493 break;
492 } 494 }
493 } else { 495 } else {
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index 39ad9f73d1..272e1ec51a 100644
--- a/drivers/net/ehea/ehea.h
+++ b/drivers/net/ehea/ehea.h
@@ -39,7 +39,7 @@
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41#define DRV_NAME "ehea" 41#define DRV_NAME "ehea"
42#define DRV_VERSION "EHEA_0043" 42#define DRV_VERSION "EHEA_0045"
43 43
44#define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \ 44#define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \
45 | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR) 45 | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index 83fa32f723..9de2d38a53 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -558,12 +558,12 @@ static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
558 u32 qp_token; 558 u32 qp_token;
559 559
560 eqe = ehea_poll_eq(port->qp_eq); 560 eqe = ehea_poll_eq(port->qp_eq);
561 ehea_debug("eqe=%p", eqe); 561
562 while (eqe) { 562 while (eqe) {
563 ehea_debug("*eqe=%lx", *(u64*)eqe);
564 eqe = ehea_poll_eq(port->qp_eq);
565 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry); 563 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
566 ehea_debug("next eqe=%p", eqe); 564 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
565 eqe->entry, qp_token);
566 eqe = ehea_poll_eq(port->qp_eq);
567 } 567 }
568 568
569 return IRQ_HANDLED; 569 return IRQ_HANDLED;
@@ -575,8 +575,9 @@ static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
575 int i; 575 int i;
576 576
577 for (i = 0; i < adapter->num_ports; i++) 577 for (i = 0; i < adapter->num_ports; i++)
578 if (adapter->port[i]->logical_port_id == logical_port) 578 if (adapter->port[i])
579 return adapter->port[i]; 579 if (adapter->port[i]->logical_port_id == logical_port)
580 return adapter->port[i];
580 return NULL; 581 return NULL;
581} 582}
582 583
@@ -642,6 +643,8 @@ int ehea_sense_port_attr(struct ehea_port *port)
642 break; 643 break;
643 } 644 }
644 645
646 port->autoneg = 1;
647
645 /* Number of default QPs */ 648 /* Number of default QPs */
646 port->num_def_qps = cb0->num_default_qps; 649 port->num_def_qps = cb0->num_default_qps;
647 650
@@ -728,10 +731,7 @@ int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
728 } 731 }
729 } else { 732 } else {
730 if (hret == H_AUTHORITY) { 733 if (hret == H_AUTHORITY) {
731 ehea_info("Hypervisor denied setting port speed. Either" 734 ehea_info("Hypervisor denied setting port speed");
732 " this partition is not authorized to set "
733 "port speed or another partition has modified"
734 " port speed first.");
735 ret = -EPERM; 735 ret = -EPERM;
736 } else { 736 } else {
737 ret = -EIO; 737 ret = -EIO;
@@ -998,7 +998,7 @@ static int ehea_configure_port(struct ehea_port *port)
998 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1); 998 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
999 999
1000 for (i = 0; i < port->num_def_qps; i++) 1000 for (i = 0; i < port->num_def_qps; i++)
1001 cb0->default_qpn_arr[i] = port->port_res[i].qp->init_attr.qp_nr; 1001 cb0->default_qpn_arr[i] = port->port_res[0].qp->init_attr.qp_nr;
1002 1002
1003 if (netif_msg_ifup(port)) 1003 if (netif_msg_ifup(port))
1004 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port"); 1004 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
@@ -1485,11 +1485,12 @@ out:
1485 1485
1486static void ehea_promiscuous_error(u64 hret, int enable) 1486static void ehea_promiscuous_error(u64 hret, int enable)
1487{ 1487{
1488 ehea_info("Hypervisor denied %sabling promiscuous mode.%s", 1488 if (hret == H_AUTHORITY)
1489 enable == 1 ? "en" : "dis", 1489 ehea_info("Hypervisor denied %sabling promiscuous mode",
1490 hret != H_AUTHORITY ? "" : " Another partition owning a " 1490 enable == 1 ? "en" : "dis");
1491 "logical port on the same physical port might have altered " 1491 else
1492 "promiscuous mode first."); 1492 ehea_error("failed %sabling promiscuous mode",
1493 enable == 1 ? "en" : "dis");
1493} 1494}
1494 1495
1495static void ehea_promiscuous(struct net_device *dev, int enable) 1496static void ehea_promiscuous(struct net_device *dev, int enable)
@@ -2267,6 +2268,8 @@ static void ehea_tx_watchdog(struct net_device *dev)
2267int ehea_sense_adapter_attr(struct ehea_adapter *adapter) 2268int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2268{ 2269{
2269 struct hcp_query_ehea *cb; 2270 struct hcp_query_ehea *cb;
2271 struct device_node *lhea_dn = NULL;
2272 struct device_node *eth_dn = NULL;
2270 u64 hret; 2273 u64 hret;
2271 int ret; 2274 int ret;
2272 2275
@@ -2283,7 +2286,18 @@ int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2283 goto out_herr; 2286 goto out_herr;
2284 } 2287 }
2285 2288
2286 adapter->num_ports = cb->num_ports; 2289 /* Determine the number of available logical ports
2290 * by counting the child nodes of the lhea OFDT entry
2291 */
2292 adapter->num_ports = 0;
2293 lhea_dn = of_find_node_by_name(lhea_dn, "lhea");
2294 do {
2295 eth_dn = of_get_next_child(lhea_dn, eth_dn);
2296 if (eth_dn)
2297 adapter->num_ports++;
2298 } while ( eth_dn );
2299 of_node_put(lhea_dn);
2300
2287 adapter->max_mc_mac = cb->max_mc_mac - 1; 2301 adapter->max_mc_mac = cb->max_mc_mac - 1;
2288 ret = 0; 2302 ret = 0;
2289 2303
@@ -2302,6 +2316,7 @@ static int ehea_setup_single_port(struct ehea_port *port,
2302 struct ehea_adapter *adapter = port->adapter; 2316 struct ehea_adapter *adapter = port->adapter;
2303 struct hcp_ehea_port_cb4 *cb4; 2317 struct hcp_ehea_port_cb4 *cb4;
2304 u32 *dn_log_port_id; 2318 u32 *dn_log_port_id;
2319 int jumbo = 0;
2305 2320
2306 sema_init(&port->port_lock, 1); 2321 sema_init(&port->port_lock, 1);
2307 port->state = EHEA_PORT_DOWN; 2322 port->state = EHEA_PORT_DOWN;
@@ -2334,8 +2349,6 @@ static int ehea_setup_single_port(struct ehea_port *port,
2334 2349
2335 INIT_LIST_HEAD(&port->mc_list->list); 2350 INIT_LIST_HEAD(&port->mc_list->list);
2336 2351
2337 ehea_set_portspeed(port, EHEA_SPEED_AUTONEG);
2338
2339 ret = ehea_sense_port_attr(port); 2352 ret = ehea_sense_port_attr(port);
2340 if (ret) 2353 if (ret)
2341 goto out; 2354 goto out;
@@ -2345,13 +2358,25 @@ static int ehea_setup_single_port(struct ehea_port *port,
2345 if (!cb4) { 2358 if (!cb4) {
2346 ehea_error("no mem for cb4"); 2359 ehea_error("no mem for cb4");
2347 } else { 2360 } else {
2348 cb4->jumbo_frame = 1; 2361 hret = ehea_h_query_ehea_port(adapter->handle,
2349 hret = ehea_h_modify_ehea_port(adapter->handle, 2362 port->logical_port_id,
2350 port->logical_port_id, 2363 H_PORT_CB4,
2351 H_PORT_CB4, H_PORT_CB4_JUMBO, 2364 H_PORT_CB4_JUMBO, cb4);
2352 cb4); 2365
2353 if (hret != H_SUCCESS) { 2366 if (hret == H_SUCCESS) {
2354 ehea_info("Jumbo frames not activated"); 2367 if (cb4->jumbo_frame)
2368 jumbo = 1;
2369 else {
2370 cb4->jumbo_frame = 1;
2371 hret = ehea_h_modify_ehea_port(adapter->handle,
2372 port->
2373 logical_port_id,
2374 H_PORT_CB4,
2375 H_PORT_CB4_JUMBO,
2376 cb4);
2377 if (hret == H_SUCCESS)
2378 jumbo = 1;
2379 }
2355 } 2380 }
2356 kfree(cb4); 2381 kfree(cb4);
2357 } 2382 }
@@ -2390,6 +2415,9 @@ static int ehea_setup_single_port(struct ehea_port *port,
2390 goto out_free; 2415 goto out_free;
2391 } 2416 }
2392 2417
2418 ehea_info("%s: Jumbo frames are %sabled", dev->name,
2419 jumbo == 1 ? "en" : "dis");
2420
2393 port->netdev = dev; 2421 port->netdev = dev;
2394 ret = 0; 2422 ret = 0;
2395 goto out; 2423 goto out;
@@ -2471,14 +2499,16 @@ static int __devinit ehea_probe(struct ibmebus_dev *dev,
2471 2499
2472 adapter_handle = (u64*)get_property(dev->ofdev.node, "ibm,hea-handle", 2500 adapter_handle = (u64*)get_property(dev->ofdev.node, "ibm,hea-handle",
2473 NULL); 2501 NULL);
2474 if (!adapter_handle) { 2502 if (adapter_handle)
2503 adapter->handle = *adapter_handle;
2504
2505 if (!adapter->handle) {
2475 dev_err(&dev->ofdev.dev, "failed getting handle for adapter" 2506 dev_err(&dev->ofdev.dev, "failed getting handle for adapter"
2476 " '%s'\n", dev->ofdev.node->full_name); 2507 " '%s'\n", dev->ofdev.node->full_name);
2477 ret = -ENODEV; 2508 ret = -ENODEV;
2478 goto out_free_ad; 2509 goto out_free_ad;
2479 } 2510 }
2480 2511
2481 adapter->handle = *adapter_handle;
2482 adapter->pd = EHEA_PD_ID; 2512 adapter->pd = EHEA_PD_ID;
2483 2513
2484 dev->ofdev.dev.driver_data = adapter; 2514 dev->ofdev.dev.driver_data = adapter;
@@ -2568,6 +2598,7 @@ static int __devexit ehea_remove(struct ibmebus_dev *dev)
2568 destroy_workqueue(adapter->ehea_wq); 2598 destroy_workqueue(adapter->ehea_wq);
2569 2599
2570 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter); 2600 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter);
2601 tasklet_kill(&adapter->neq_tasklet);
2571 2602
2572 ehea_destroy_eq(adapter->neq); 2603 ehea_destroy_eq(adapter->neq);
2573 2604
diff --git a/drivers/net/ehea/ehea_phyp.c b/drivers/net/ehea/ehea_phyp.c
index 0cfc2bc1a2..37716e05e8 100644
--- a/drivers/net/ehea/ehea_phyp.c
+++ b/drivers/net/ehea/ehea_phyp.c
@@ -94,6 +94,7 @@ static long ehea_plpar_hcall9(unsigned long opcode,
94{ 94{
95 long ret; 95 long ret;
96 int i, sleep_msecs; 96 int i, sleep_msecs;
97 u8 cb_cat;
97 98
98 for (i = 0; i < 5; i++) { 99 for (i = 0; i < 5; i++) {
99 ret = plpar_hcall9(opcode, outs, 100 ret = plpar_hcall9(opcode, outs,
@@ -106,7 +107,13 @@ static long ehea_plpar_hcall9(unsigned long opcode,
106 continue; 107 continue;
107 } 108 }
108 109
109 if (ret < H_SUCCESS) 110 cb_cat = EHEA_BMASK_GET(H_MEHEAPORT_CAT, arg2);
111
112 if ((ret < H_SUCCESS) && !(((ret == H_AUTHORITY)
113 && (opcode == H_MODIFY_HEA_PORT))
114 && (((cb_cat == H_PORT_CB4) && ((arg3 == H_PORT_CB4_JUMBO)
115 || (arg3 == H_PORT_CB4_SPEED))) || ((cb_cat == H_PORT_CB7)
116 && (arg3 == H_PORT_CB7_DUCQPN)))))
110 ehea_error("opcode=%lx ret=%lx" 117 ehea_error("opcode=%lx ret=%lx"
111 " arg1=%lx arg2=%lx arg3=%lx arg4=%lx" 118 " arg1=%lx arg2=%lx arg3=%lx arg4=%lx"
112 " arg5=%lx arg6=%lx arg7=%lx arg8=%lx" 119 " arg5=%lx arg6=%lx arg7=%lx arg8=%lx"
@@ -120,7 +127,6 @@ static long ehea_plpar_hcall9(unsigned long opcode,
120 outs[0], outs[1], outs[2], outs[3], 127 outs[0], outs[1], outs[2], outs[3],
121 outs[4], outs[5], outs[6], outs[7], 128 outs[4], outs[5], outs[6], outs[7],
122 outs[8]); 129 outs[8]);
123
124 return ret; 130 return ret;
125 } 131 }
126 132
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index 439f413382..93f2b7a221 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -3,8 +3,7 @@
3 * 3 *
4 * Note: This driver is a cleanroom reimplementation based on reverse 4 * Note: This driver is a cleanroom reimplementation based on reverse
5 * engineered documentation written by Carl-Daniel Hailfinger 5 * engineered documentation written by Carl-Daniel Hailfinger
6 * and Andrew de Quincey. It's neither supported nor endorsed 6 * and Andrew de Quincey.
7 * by NVIDIA Corp. Use at your own risk.
8 * 7 *
9 * NVIDIA, nForce and other NVIDIA marks are trademarks or registered 8 * NVIDIA, nForce and other NVIDIA marks are trademarks or registered
10 * trademarks of NVIDIA Corporation in the United States and other 9 * trademarks of NVIDIA Corporation in the United States and other
@@ -14,7 +13,7 @@
14 * Copyright (C) 2004 Andrew de Quincey (wol support) 13 * Copyright (C) 2004 Andrew de Quincey (wol support)
15 * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane 14 * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane
16 * IRQ rate fixes, bigendian fixes, cleanups, verification) 15 * IRQ rate fixes, bigendian fixes, cleanups, verification)
17 * Copyright (c) 2004 NVIDIA Corporation 16 * Copyright (c) 2004,5,6 NVIDIA Corporation
18 * 17 *
19 * This program is free software; you can redistribute it and/or modify 18 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by 19 * it under the terms of the GNU General Public License as published by
@@ -235,6 +234,7 @@ enum {
235#define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000 234#define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
236#define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000 235#define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
237#define NVREG_XMITCTL_HOST_LOADED 0x00004000 236#define NVREG_XMITCTL_HOST_LOADED 0x00004000
237#define NVREG_XMITCTL_TX_PATH_EN 0x01000000
238 NvRegTransmitterStatus = 0x088, 238 NvRegTransmitterStatus = 0x088,
239#define NVREG_XMITSTAT_BUSY 0x01 239#define NVREG_XMITSTAT_BUSY 0x01
240 240
@@ -250,6 +250,7 @@ enum {
250#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE 250#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
251 NvRegReceiverControl = 0x094, 251 NvRegReceiverControl = 0x094,
252#define NVREG_RCVCTL_START 0x01 252#define NVREG_RCVCTL_START 0x01
253#define NVREG_RCVCTL_RX_PATH_EN 0x01000000
253 NvRegReceiverStatus = 0x98, 254 NvRegReceiverStatus = 0x98,
254#define NVREG_RCVSTAT_BUSY 0x01 255#define NVREG_RCVSTAT_BUSY 0x01
255 256
@@ -1170,16 +1171,21 @@ static void nv_start_rx(struct net_device *dev)
1170{ 1171{
1171 struct fe_priv *np = netdev_priv(dev); 1172 struct fe_priv *np = netdev_priv(dev);
1172 u8 __iomem *base = get_hwbase(dev); 1173 u8 __iomem *base = get_hwbase(dev);
1174 u32 rx_ctrl = readl(base + NvRegReceiverControl);
1173 1175
1174 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name); 1176 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
1175 /* Already running? Stop it. */ 1177 /* Already running? Stop it. */
1176 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) { 1178 if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) {
1177 writel(0, base + NvRegReceiverControl); 1179 rx_ctrl &= ~NVREG_RCVCTL_START;
1180 writel(rx_ctrl, base + NvRegReceiverControl);
1178 pci_push(base); 1181 pci_push(base);
1179 } 1182 }
1180 writel(np->linkspeed, base + NvRegLinkSpeed); 1183 writel(np->linkspeed, base + NvRegLinkSpeed);
1181 pci_push(base); 1184 pci_push(base);
1182 writel(NVREG_RCVCTL_START, base + NvRegReceiverControl); 1185 rx_ctrl |= NVREG_RCVCTL_START;
1186 if (np->mac_in_use)
1187 rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN;
1188 writel(rx_ctrl, base + NvRegReceiverControl);
1183 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n", 1189 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
1184 dev->name, np->duplex, np->linkspeed); 1190 dev->name, np->duplex, np->linkspeed);
1185 pci_push(base); 1191 pci_push(base);
@@ -1187,39 +1193,59 @@ static void nv_start_rx(struct net_device *dev)
1187 1193
1188static void nv_stop_rx(struct net_device *dev) 1194static void nv_stop_rx(struct net_device *dev)
1189{ 1195{
1196 struct fe_priv *np = netdev_priv(dev);
1190 u8 __iomem *base = get_hwbase(dev); 1197 u8 __iomem *base = get_hwbase(dev);
1198 u32 rx_ctrl = readl(base + NvRegReceiverControl);
1191 1199
1192 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name); 1200 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
1193 writel(0, base + NvRegReceiverControl); 1201 if (!np->mac_in_use)
1202 rx_ctrl &= ~NVREG_RCVCTL_START;
1203 else
1204 rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN;
1205 writel(rx_ctrl, base + NvRegReceiverControl);
1194 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0, 1206 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1195 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX, 1207 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
1196 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy"); 1208 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy");
1197 1209
1198 udelay(NV_RXSTOP_DELAY2); 1210 udelay(NV_RXSTOP_DELAY2);
1199 writel(0, base + NvRegLinkSpeed); 1211 if (!np->mac_in_use)
1212 writel(0, base + NvRegLinkSpeed);
1200} 1213}
1201 1214
1202static void nv_start_tx(struct net_device *dev) 1215static void nv_start_tx(struct net_device *dev)
1203{ 1216{
1217 struct fe_priv *np = netdev_priv(dev);
1204 u8 __iomem *base = get_hwbase(dev); 1218 u8 __iomem *base = get_hwbase(dev);
1219 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
1205 1220
1206 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name); 1221 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
1207 writel(NVREG_XMITCTL_START, base + NvRegTransmitterControl); 1222 tx_ctrl |= NVREG_XMITCTL_START;
1223 if (np->mac_in_use)
1224 tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN;
1225 writel(tx_ctrl, base + NvRegTransmitterControl);
1208 pci_push(base); 1226 pci_push(base);
1209} 1227}
1210 1228
1211static void nv_stop_tx(struct net_device *dev) 1229static void nv_stop_tx(struct net_device *dev)
1212{ 1230{
1231 struct fe_priv *np = netdev_priv(dev);
1213 u8 __iomem *base = get_hwbase(dev); 1232 u8 __iomem *base = get_hwbase(dev);
1233 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
1214 1234
1215 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name); 1235 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
1216 writel(0, base + NvRegTransmitterControl); 1236 if (!np->mac_in_use)
1237 tx_ctrl &= ~NVREG_XMITCTL_START;
1238 else
1239 tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN;
1240 writel(tx_ctrl, base + NvRegTransmitterControl);
1217 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0, 1241 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1218 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX, 1242 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
1219 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy"); 1243 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy");
1220 1244
1221 udelay(NV_TXSTOP_DELAY2); 1245 udelay(NV_TXSTOP_DELAY2);
1222 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll); 1246 if (!np->mac_in_use)
1247 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV,
1248 base + NvRegTransmitPoll);
1223} 1249}
1224 1250
1225static void nv_txrx_reset(struct net_device *dev) 1251static void nv_txrx_reset(struct net_device *dev)
@@ -2576,14 +2602,15 @@ static int nv_napi_poll(struct net_device *dev, int *budget)
2576 int pkts, limit = min(*budget, dev->quota); 2602 int pkts, limit = min(*budget, dev->quota);
2577 struct fe_priv *np = netdev_priv(dev); 2603 struct fe_priv *np = netdev_priv(dev);
2578 u8 __iomem *base = get_hwbase(dev); 2604 u8 __iomem *base = get_hwbase(dev);
2605 unsigned long flags;
2579 2606
2580 pkts = nv_rx_process(dev, limit); 2607 pkts = nv_rx_process(dev, limit);
2581 2608
2582 if (nv_alloc_rx(dev)) { 2609 if (nv_alloc_rx(dev)) {
2583 spin_lock_irq(&np->lock); 2610 spin_lock_irqsave(&np->lock, flags);
2584 if (!np->in_shutdown) 2611 if (!np->in_shutdown)
2585 mod_timer(&np->oom_kick, jiffies + OOM_REFILL); 2612 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2586 spin_unlock_irq(&np->lock); 2613 spin_unlock_irqrestore(&np->lock, flags);
2587 } 2614 }
2588 2615
2589 if (pkts < limit) { 2616 if (pkts < limit) {
@@ -2591,13 +2618,15 @@ static int nv_napi_poll(struct net_device *dev, int *budget)
2591 netif_rx_complete(dev); 2618 netif_rx_complete(dev);
2592 2619
2593 /* re-enable receive interrupts */ 2620 /* re-enable receive interrupts */
2594 spin_lock_irq(&np->lock); 2621 spin_lock_irqsave(&np->lock, flags);
2622
2595 np->irqmask |= NVREG_IRQ_RX_ALL; 2623 np->irqmask |= NVREG_IRQ_RX_ALL;
2596 if (np->msi_flags & NV_MSI_X_ENABLED) 2624 if (np->msi_flags & NV_MSI_X_ENABLED)
2597 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask); 2625 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2598 else 2626 else
2599 writel(np->irqmask, base + NvRegIrqMask); 2627 writel(np->irqmask, base + NvRegIrqMask);
2600 spin_unlock_irq(&np->lock); 2628
2629 spin_unlock_irqrestore(&np->lock, flags);
2601 return 0; 2630 return 0;
2602 } else { 2631 } else {
2603 /* used up our quantum, so reschedule */ 2632 /* used up our quantum, so reschedule */
@@ -4146,20 +4175,6 @@ static int nv_mgmt_acquire_sema(struct net_device *dev)
4146 return 0; 4175 return 0;
4147} 4176}
4148 4177
4149/* Indicate to mgmt unit whether driver is loaded or not */
4150static void nv_mgmt_driver_loaded(struct net_device *dev, int loaded)
4151{
4152 u8 __iomem *base = get_hwbase(dev);
4153 u32 tx_ctrl;
4154
4155 tx_ctrl = readl(base + NvRegTransmitterControl);
4156 if (loaded)
4157 tx_ctrl |= NVREG_XMITCTL_HOST_LOADED;
4158 else
4159 tx_ctrl &= ~NVREG_XMITCTL_HOST_LOADED;
4160 writel(tx_ctrl, base + NvRegTransmitterControl);
4161}
4162
4163static int nv_open(struct net_device *dev) 4178static int nv_open(struct net_device *dev)
4164{ 4179{
4165 struct fe_priv *np = netdev_priv(dev); 4180 struct fe_priv *np = netdev_priv(dev);
@@ -4657,33 +4672,24 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
4657 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus); 4672 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
4658 4673
4659 if (id->driver_data & DEV_HAS_MGMT_UNIT) { 4674 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
4660 writel(0x1, base + 0x204); pci_push(base);
4661 msleep(500);
4662 /* management unit running on the mac? */ 4675 /* management unit running on the mac? */
4663 np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST; 4676 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) {
4664 if (np->mac_in_use) { 4677 np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST;
4665 u32 mgmt_sync; 4678 dprintk(KERN_INFO "%s: mgmt unit is running. mac in use %x.\n", pci_name(pci_dev), np->mac_in_use);
4666 /* management unit setup the phy already? */ 4679 for (i = 0; i < 5000; i++) {
4667 mgmt_sync = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK; 4680 msleep(1);
4668 if (mgmt_sync == NVREG_XMITCTL_SYNC_NOT_READY) { 4681 if (nv_mgmt_acquire_sema(dev)) {
4669 if (!nv_mgmt_acquire_sema(dev)) { 4682 /* management unit setup the phy already? */
4670 for (i = 0; i < 5000; i++) { 4683 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
4671 msleep(1); 4684 NVREG_XMITCTL_SYNC_PHY_INIT) {
4672 mgmt_sync = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK; 4685 /* phy is inited by mgmt unit */
4673 if (mgmt_sync == NVREG_XMITCTL_SYNC_NOT_READY) 4686 phyinitialized = 1;
4674 continue; 4687 dprintk(KERN_INFO "%s: Phy already initialized by mgmt unit.\n", pci_name(pci_dev));
4675 if (mgmt_sync == NVREG_XMITCTL_SYNC_PHY_INIT) 4688 } else {
4676 phyinitialized = 1; 4689 /* we need to init the phy */
4677 break;
4678 } 4690 }
4679 } else { 4691 break;
4680 /* we need to init the phy */
4681 } 4692 }
4682 } else if (mgmt_sync == NVREG_XMITCTL_SYNC_PHY_INIT) {
4683 /* phy is inited by SMU */
4684 phyinitialized = 1;
4685 } else {
4686 /* we need to init the phy */
4687 } 4693 }
4688 } 4694 }
4689 } 4695 }
@@ -4722,10 +4728,12 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
4722 if (!phyinitialized) { 4728 if (!phyinitialized) {
4723 /* reset it */ 4729 /* reset it */
4724 phy_init(dev); 4730 phy_init(dev);
4725 } 4731 } else {
4726 4732 /* see if it is a gigabit phy */
4727 if (id->driver_data & DEV_HAS_MGMT_UNIT) { 4733 u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4728 nv_mgmt_driver_loaded(dev, 1); 4734 if (mii_status & PHY_GIGABIT) {
4735 np->gigabit = PHY_GIGABIT;
4736 }
4729 } 4737 }
4730 4738
4731 /* set default link speed settings */ 4739 /* set default link speed settings */
@@ -4747,8 +4755,6 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
4747out_error: 4755out_error:
4748 if (phystate_orig) 4756 if (phystate_orig)
4749 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl); 4757 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
4750 if (np->mac_in_use)
4751 nv_mgmt_driver_loaded(dev, 0);
4752 pci_set_drvdata(pci_dev, NULL); 4758 pci_set_drvdata(pci_dev, NULL);
4753out_freering: 4759out_freering:
4754 free_rings(dev); 4760 free_rings(dev);
@@ -4778,9 +4784,6 @@ static void __devexit nv_remove(struct pci_dev *pci_dev)
4778 writel(np->orig_mac[0], base + NvRegMacAddrA); 4784 writel(np->orig_mac[0], base + NvRegMacAddrA);
4779 writel(np->orig_mac[1], base + NvRegMacAddrB); 4785 writel(np->orig_mac[1], base + NvRegMacAddrB);
4780 4786
4781 if (np->mac_in_use)
4782 nv_mgmt_driver_loaded(dev, 0);
4783
4784 /* free all structures */ 4787 /* free all structures */
4785 free_rings(dev); 4788 free_rings(dev);
4786 iounmap(get_hwbase(dev)); 4789 iounmap(get_hwbase(dev));
diff --git a/drivers/net/fs_enet/mac-fec.c b/drivers/net/fs_enet/mac-fec.c
index c2c5fd419b..ff68394773 100644
--- a/drivers/net/fs_enet/mac-fec.c
+++ b/drivers/net/fs_enet/mac-fec.c
@@ -104,9 +104,9 @@ static int do_pd_setup(struct fs_enet_private *fep)
104 fep->interrupt = platform_get_irq_byname(pdev,"interrupt"); 104 fep->interrupt = platform_get_irq_byname(pdev,"interrupt");
105 if (fep->interrupt < 0) 105 if (fep->interrupt < 0)
106 return -EINVAL; 106 return -EINVAL;
107 107
108 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); 108 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
109 fep->fec.fecp =(void*)r->start; 109 fep->fec.fecp = ioremap(r->start, r->end - r->start + 1);
110 110
111 if(fep->fec.fecp == NULL) 111 if(fep->fec.fecp == NULL)
112 return -EINVAL; 112 return -EINVAL;
@@ -319,11 +319,14 @@ static void restart(struct net_device *dev)
319 * Clear any outstanding interrupt. 319 * Clear any outstanding interrupt.
320 */ 320 */
321 FW(fecp, ievent, 0xffc0); 321 FW(fecp, ievent, 0xffc0);
322#ifndef CONFIG_PPC_MERGE
322 FW(fecp, ivec, (fep->interrupt / 2) << 29); 323 FW(fecp, ivec, (fep->interrupt / 2) << 29);
323 324#else
325 FW(fecp, ivec, (virq_to_hw(fep->interrupt) / 2) << 29);
326#endif
324 327
325 /* 328 /*
326 * adjust to speed (only for DUET & RMII) 329 * adjust to speed (only for DUET & RMII)
327 */ 330 */
328#ifdef CONFIG_DUET 331#ifdef CONFIG_DUET
329 if (fpi->use_rmii) { 332 if (fpi->use_rmii) {
@@ -418,6 +421,7 @@ static void stop(struct net_device *dev)
418 421
419static void pre_request_irq(struct net_device *dev, int irq) 422static void pre_request_irq(struct net_device *dev, int irq)
420{ 423{
424#ifndef CONFIG_PPC_MERGE
421 immap_t *immap = fs_enet_immap; 425 immap_t *immap = fs_enet_immap;
422 u32 siel; 426 u32 siel;
423 427
@@ -431,6 +435,7 @@ static void pre_request_irq(struct net_device *dev, int irq)
431 siel &= ~(0x80000000 >> (irq & ~1)); 435 siel &= ~(0x80000000 >> (irq & ~1));
432 out_be32(&immap->im_siu_conf.sc_siel, siel); 436 out_be32(&immap->im_siu_conf.sc_siel, siel);
433 } 437 }
438#endif
434} 439}
435 440
436static void post_free_irq(struct net_device *dev, int irq) 441static void post_free_irq(struct net_device *dev, int irq)
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
index 95ec5872c5..afd7fca7c6 100644
--- a/drivers/net/fs_enet/mac-scc.c
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -121,13 +121,13 @@ static int do_pd_setup(struct fs_enet_private *fep)
121 return -EINVAL; 121 return -EINVAL;
122 122
123 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); 123 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
124 fep->scc.sccp = (void *)r->start; 124 fep->scc.sccp = ioremap(r->start, r->end - r->start + 1);
125 125
126 if (fep->scc.sccp == NULL) 126 if (fep->scc.sccp == NULL)
127 return -EINVAL; 127 return -EINVAL;
128 128
129 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pram"); 129 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pram");
130 fep->scc.ep = (void *)r->start; 130 fep->scc.ep = ioremap(r->start, r->end - r->start + 1);
131 131
132 if (fep->scc.ep == NULL) 132 if (fep->scc.ep == NULL)
133 return -EINVAL; 133 return -EINVAL;
@@ -397,6 +397,7 @@ static void stop(struct net_device *dev)
397 397
398static void pre_request_irq(struct net_device *dev, int irq) 398static void pre_request_irq(struct net_device *dev, int irq)
399{ 399{
400#ifndef CONFIG_PPC_MERGE
400 immap_t *immap = fs_enet_immap; 401 immap_t *immap = fs_enet_immap;
401 u32 siel; 402 u32 siel;
402 403
@@ -410,6 +411,7 @@ static void pre_request_irq(struct net_device *dev, int irq)
410 siel &= ~(0x80000000 >> (irq & ~1)); 411 siel &= ~(0x80000000 >> (irq & ~1));
411 out_be32(&immap->im_siu_conf.sc_siel, siel); 412 out_be32(&immap->im_siu_conf.sc_siel, siel);
412 } 413 }
414#endif
413} 415}
414 416
415static void post_free_irq(struct net_device *dev, int irq) 417static void post_free_irq(struct net_device *dev, int irq)
diff --git a/drivers/net/hamradio/Kconfig b/drivers/net/hamradio/Kconfig
index 896aa02000..feb0ada7a0 100644
--- a/drivers/net/hamradio/Kconfig
+++ b/drivers/net/hamradio/Kconfig
@@ -113,7 +113,7 @@ config SCC_TRXECHO
113 113
114config BAYCOM_SER_FDX 114config BAYCOM_SER_FDX
115 tristate "BAYCOM ser12 fullduplex driver for AX.25" 115 tristate "BAYCOM ser12 fullduplex driver for AX.25"
116 depends on AX25 116 depends on AX25 && !S390
117 select CRC_CCITT 117 select CRC_CCITT
118 ---help--- 118 ---help---
119 This is one of two drivers for Baycom style simple amateur radio 119 This is one of two drivers for Baycom style simple amateur radio
@@ -133,7 +133,7 @@ config BAYCOM_SER_FDX
133 133
134config BAYCOM_SER_HDX 134config BAYCOM_SER_HDX
135 tristate "BAYCOM ser12 halfduplex driver for AX.25" 135 tristate "BAYCOM ser12 halfduplex driver for AX.25"
136 depends on AX25 136 depends on AX25 && !S390
137 select CRC_CCITT 137 select CRC_CCITT
138 ---help--- 138 ---help---
139 This is one of two drivers for Baycom style simple amateur radio 139 This is one of two drivers for Baycom style simple amateur radio
@@ -181,7 +181,7 @@ config BAYCOM_EPP
181 181
182config YAM 182config YAM
183 tristate "YAM driver for AX.25" 183 tristate "YAM driver for AX.25"
184 depends on AX25 184 depends on AX25 && !S390
185 help 185 help
186 The YAM is a modem for packet radio which connects to the serial 186 The YAM is a modem for packet radio which connects to the serial
187 port and includes some of the functions of a Terminal Node 187 port and includes some of the functions of a Terminal Node
diff --git a/drivers/net/ibm_emac/ibm_emac_phy.c b/drivers/net/ibm_emac/ibm_emac_phy.c
index 4a97024061..9074f76ee2 100644
--- a/drivers/net/ibm_emac/ibm_emac_phy.c
+++ b/drivers/net/ibm_emac/ibm_emac_phy.c
@@ -309,7 +309,7 @@ int mii_phy_probe(struct mii_phy *phy, int address)
309{ 309{
310 struct mii_phy_def *def; 310 struct mii_phy_def *def;
311 int i; 311 int i;
312 u32 id; 312 int id;
313 313
314 phy->autoneg = AUTONEG_DISABLE; 314 phy->autoneg = AUTONEG_DISABLE;
315 phy->advertising = 0; 315 phy->advertising = 0;
@@ -324,6 +324,8 @@ int mii_phy_probe(struct mii_phy *phy, int address)
324 324
325 /* Read ID and find matching entry */ 325 /* Read ID and find matching entry */
326 id = (phy_read(phy, MII_PHYSID1) << 16) | phy_read(phy, MII_PHYSID2); 326 id = (phy_read(phy, MII_PHYSID1) << 16) | phy_read(phy, MII_PHYSID2);
327 if (id < 0)
328 return -ENODEV;
327 for (i = 0; (def = mii_phy_table[i]) != NULL; i++) 329 for (i = 0; (def = mii_phy_table[i]) != NULL; i++)
328 if ((id & def->phy_id_mask) == def->phy_id) 330 if ((id & def->phy_id_mask) == def->phy_id)
329 break; 331 break;
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index c26a4b8e55..ca2b21f9d4 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -154,8 +154,8 @@ static int ifb_xmit(struct sk_buff *skb, struct net_device *dev)
154 int ret = 0; 154 int ret = 0;
155 u32 from = G_TC_FROM(skb->tc_verd); 155 u32 from = G_TC_FROM(skb->tc_verd);
156 156
157 stats->tx_packets++; 157 stats->rx_packets++;
158 stats->tx_bytes+=skb->len; 158 stats->rx_bytes+=skb->len;
159 159
160 if (!from || !skb->input_dev) { 160 if (!from || !skb->input_dev) {
161dropped: 161dropped:
diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
index 3ca1082ec7..340ee99652 100644
--- a/drivers/net/irda/irda-usb.c
+++ b/drivers/net/irda/irda-usb.c
@@ -441,25 +441,13 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
441 goto drop; 441 goto drop;
442 } 442 }
443 443
444 /* Make sure there is room for IrDA-USB header. The actual 444 memcpy(self->tx_buff + self->header_length, skb->data, skb->len);
445 * allocation will be done lower in skb_push().
446 * Also, we don't use directly skb_cow(), because it require
447 * headroom >= 16, which force unnecessary copies - Jean II */
448 if (skb_headroom(skb) < self->header_length) {
449 IRDA_DEBUG(0, "%s(), Insuficient skb headroom.\n", __FUNCTION__);
450 if (skb_cow(skb, self->header_length)) {
451 IRDA_WARNING("%s(), failed skb_cow() !!!\n", __FUNCTION__);
452 goto drop;
453 }
454 }
455 445
456 /* Change setting for next frame */ 446 /* Change setting for next frame */
457
458 if (self->capability & IUC_STIR421X) { 447 if (self->capability & IUC_STIR421X) {
459 __u8 turnaround_time; 448 __u8 turnaround_time;
460 __u8* frame; 449 __u8* frame = self->tx_buff;
461 turnaround_time = get_turnaround_time( skb ); 450 turnaround_time = get_turnaround_time( skb );
462 frame= skb_push(skb, self->header_length);
463 irda_usb_build_header(self, frame, 0); 451 irda_usb_build_header(self, frame, 0);
464 frame[2] = turnaround_time; 452 frame[2] = turnaround_time;
465 if ((skb->len != 0) && 453 if ((skb->len != 0) &&
@@ -472,17 +460,17 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
472 frame[1] = 0; 460 frame[1] = 0;
473 } 461 }
474 } else { 462 } else {
475 irda_usb_build_header(self, skb_push(skb, self->header_length), 0); 463 irda_usb_build_header(self, self->tx_buff, 0);
476 } 464 }
477 465
478 /* FIXME: Make macro out of this one */ 466 /* FIXME: Make macro out of this one */
479 ((struct irda_skb_cb *)skb->cb)->context = self; 467 ((struct irda_skb_cb *)skb->cb)->context = self;
480 468
481 usb_fill_bulk_urb(urb, self->usbdev, 469 usb_fill_bulk_urb(urb, self->usbdev,
482 usb_sndbulkpipe(self->usbdev, self->bulk_out_ep), 470 usb_sndbulkpipe(self->usbdev, self->bulk_out_ep),
483 skb->data, IRDA_SKB_MAX_MTU, 471 self->tx_buff, skb->len + self->header_length,
484 write_bulk_callback, skb); 472 write_bulk_callback, skb);
485 urb->transfer_buffer_length = skb->len; 473
486 /* This flag (URB_ZERO_PACKET) indicates that what we send is not 474 /* This flag (URB_ZERO_PACKET) indicates that what we send is not
487 * a continuous stream of data but separate packets. 475 * a continuous stream of data but separate packets.
488 * In this case, the USB layer will insert an empty USB frame (TD) 476 * In this case, the USB layer will insert an empty USB frame (TD)
@@ -1455,6 +1443,9 @@ static inline void irda_usb_close(struct irda_usb_cb *self)
1455 /* Remove the speed buffer */ 1443 /* Remove the speed buffer */
1456 kfree(self->speed_buff); 1444 kfree(self->speed_buff);
1457 self->speed_buff = NULL; 1445 self->speed_buff = NULL;
1446
1447 kfree(self->tx_buff);
1448 self->tx_buff = NULL;
1458} 1449}
1459 1450
1460/********************** USB CONFIG SUBROUTINES **********************/ 1451/********************** USB CONFIG SUBROUTINES **********************/
@@ -1524,8 +1515,6 @@ static inline int irda_usb_parse_endpoints(struct irda_usb_cb *self, struct usb_
1524 1515
1525 IRDA_DEBUG(0, "%s(), And our endpoints are : in=%02X, out=%02X (%d), int=%02X\n", 1516 IRDA_DEBUG(0, "%s(), And our endpoints are : in=%02X, out=%02X (%d), int=%02X\n",
1526 __FUNCTION__, self->bulk_in_ep, self->bulk_out_ep, self->bulk_out_mtu, self->bulk_int_ep); 1517 __FUNCTION__, self->bulk_in_ep, self->bulk_out_ep, self->bulk_out_mtu, self->bulk_int_ep);
1527 /* Should be 8, 16, 32 or 64 bytes */
1528 IRDA_ASSERT(self->bulk_out_mtu == 64, ;);
1529 1518
1530 return((self->bulk_in_ep != 0) && (self->bulk_out_ep != 0)); 1519 return((self->bulk_in_ep != 0) && (self->bulk_out_ep != 0));
1531} 1520}
@@ -1753,9 +1742,14 @@ static int irda_usb_probe(struct usb_interface *intf,
1753 1742
1754 memset(self->speed_buff, 0, IRDA_USB_SPEED_MTU); 1743 memset(self->speed_buff, 0, IRDA_USB_SPEED_MTU);
1755 1744
1745 self->tx_buff = kzalloc(IRDA_SKB_MAX_MTU + self->header_length,
1746 GFP_KERNEL);
1747 if (self->tx_buff == NULL)
1748 goto err_out_4;
1749
1756 ret = irda_usb_open(self); 1750 ret = irda_usb_open(self);
1757 if (ret) 1751 if (ret)
1758 goto err_out_4; 1752 goto err_out_5;
1759 1753
1760 IRDA_MESSAGE("IrDA: Registered device %s\n", net->name); 1754 IRDA_MESSAGE("IrDA: Registered device %s\n", net->name);
1761 usb_set_intfdata(intf, self); 1755 usb_set_intfdata(intf, self);
@@ -1766,14 +1760,14 @@ static int irda_usb_probe(struct usb_interface *intf,
1766 self->needspatch = (ret < 0); 1760 self->needspatch = (ret < 0);
1767 if (self->needspatch) { 1761 if (self->needspatch) {
1768 IRDA_ERROR("STIR421X: Couldn't upload patch\n"); 1762 IRDA_ERROR("STIR421X: Couldn't upload patch\n");
1769 goto err_out_5; 1763 goto err_out_6;
1770 } 1764 }
1771 1765
1772 /* replace IrDA class descriptor with what patched device is now reporting */ 1766 /* replace IrDA class descriptor with what patched device is now reporting */
1773 irda_desc = irda_usb_find_class_desc (self->usbintf); 1767 irda_desc = irda_usb_find_class_desc (self->usbintf);
1774 if (irda_desc == NULL) { 1768 if (irda_desc == NULL) {
1775 ret = -ENODEV; 1769 ret = -ENODEV;
1776 goto err_out_5; 1770 goto err_out_6;
1777 } 1771 }
1778 if (self->irda_desc) 1772 if (self->irda_desc)
1779 kfree (self->irda_desc); 1773 kfree (self->irda_desc);
@@ -1782,9 +1776,10 @@ static int irda_usb_probe(struct usb_interface *intf,
1782 } 1776 }
1783 1777
1784 return 0; 1778 return 0;
1785 1779err_out_6:
1786err_out_5:
1787 unregister_netdev(self->netdev); 1780 unregister_netdev(self->netdev);
1781err_out_5:
1782 kfree(self->tx_buff);
1788err_out_4: 1783err_out_4:
1789 kfree(self->speed_buff); 1784 kfree(self->speed_buff);
1790err_out_3: 1785err_out_3:
diff --git a/drivers/net/irda/irda-usb.h b/drivers/net/irda/irda-usb.h
index 6b2271f18e..e846c38224 100644
--- a/drivers/net/irda/irda-usb.h
+++ b/drivers/net/irda/irda-usb.h
@@ -156,6 +156,7 @@ struct irda_usb_cb {
156 struct irlap_cb *irlap; /* The link layer we are binded to */ 156 struct irlap_cb *irlap; /* The link layer we are binded to */
157 struct qos_info qos; 157 struct qos_info qos;
158 char *speed_buff; /* Buffer for speed changes */ 158 char *speed_buff; /* Buffer for speed changes */
159 char *tx_buff;
159 160
160 struct timeval stamp; 161 struct timeval stamp;
161 struct timeval now; 162 struct timeval now;
diff --git a/drivers/net/irda/stir4200.c b/drivers/net/irda/stir4200.c
index c14a74634f..20d306fea4 100644
--- a/drivers/net/irda/stir4200.c
+++ b/drivers/net/irda/stir4200.c
@@ -59,7 +59,7 @@
59#include <asm/byteorder.h> 59#include <asm/byteorder.h>
60#include <asm/unaligned.h> 60#include <asm/unaligned.h>
61 61
62MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); 62MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
63MODULE_DESCRIPTION("IrDA-USB Dongle Driver for SigmaTel STIr4200"); 63MODULE_DESCRIPTION("IrDA-USB Dongle Driver for SigmaTel STIr4200");
64MODULE_LICENSE("GPL"); 64MODULE_LICENSE("GPL");
65 65
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index 18c68193bf..e2b1af6184 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -166,7 +166,7 @@ static void vlsi_proc_pdev(struct seq_file *seq, struct pci_dev *pdev)
166 unsigned i; 166 unsigned i;
167 167
168 seq_printf(seq, "\n%s (vid/did: %04x/%04x)\n", 168 seq_printf(seq, "\n%s (vid/did: %04x/%04x)\n",
169 PCIDEV_NAME(pdev), (int)pdev->vendor, (int)pdev->device); 169 pci_name(pdev), (int)pdev->vendor, (int)pdev->device);
170 seq_printf(seq, "pci-power-state: %u\n", (unsigned) pdev->current_state); 170 seq_printf(seq, "pci-power-state: %u\n", (unsigned) pdev->current_state);
171 seq_printf(seq, "resources: irq=%u / io=0x%04x / dma_mask=0x%016Lx\n", 171 seq_printf(seq, "resources: irq=%u / io=0x%04x / dma_mask=0x%016Lx\n",
172 pdev->irq, (unsigned)pci_resource_start(pdev, 0), (unsigned long long)pdev->dma_mask); 172 pdev->irq, (unsigned)pci_resource_start(pdev, 0), (unsigned long long)pdev->dma_mask);
@@ -1401,7 +1401,7 @@ static void vlsi_tx_timeout(struct net_device *ndev)
1401 1401
1402 if (vlsi_start_hw(idev)) 1402 if (vlsi_start_hw(idev))
1403 IRDA_ERROR("%s: failed to restart hw - %s(%s) unusable!\n", 1403 IRDA_ERROR("%s: failed to restart hw - %s(%s) unusable!\n",
1404 __FUNCTION__, PCIDEV_NAME(idev->pdev), ndev->name); 1404 __FUNCTION__, pci_name(idev->pdev), ndev->name);
1405 else 1405 else
1406 netif_start_queue(ndev); 1406 netif_start_queue(ndev);
1407} 1407}
@@ -1643,7 +1643,7 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1643 pdev->current_state = 0; /* hw must be running now */ 1643 pdev->current_state = 0; /* hw must be running now */
1644 1644
1645 IRDA_MESSAGE("%s: IrDA PCI controller %s detected\n", 1645 IRDA_MESSAGE("%s: IrDA PCI controller %s detected\n",
1646 drivername, PCIDEV_NAME(pdev)); 1646 drivername, pci_name(pdev));
1647 1647
1648 if ( !pci_resource_start(pdev,0) 1648 if ( !pci_resource_start(pdev,0)
1649 || !(pci_resource_flags(pdev,0) & IORESOURCE_IO) ) { 1649 || !(pci_resource_flags(pdev,0) & IORESOURCE_IO) ) {
@@ -1728,7 +1728,7 @@ static void __devexit vlsi_irda_remove(struct pci_dev *pdev)
1728 1728
1729 pci_set_drvdata(pdev, NULL); 1729 pci_set_drvdata(pdev, NULL);
1730 1730
1731 IRDA_MESSAGE("%s: %s removed\n", drivername, PCIDEV_NAME(pdev)); 1731 IRDA_MESSAGE("%s: %s removed\n", drivername, pci_name(pdev));
1732} 1732}
1733 1733
1734#ifdef CONFIG_PM 1734#ifdef CONFIG_PM
@@ -1748,7 +1748,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1748 1748
1749 if (!ndev) { 1749 if (!ndev) {
1750 IRDA_ERROR("%s - %s: no netdevice \n", 1750 IRDA_ERROR("%s - %s: no netdevice \n",
1751 __FUNCTION__, PCIDEV_NAME(pdev)); 1751 __FUNCTION__, pci_name(pdev));
1752 return 0; 1752 return 0;
1753 } 1753 }
1754 idev = ndev->priv; 1754 idev = ndev->priv;
@@ -1759,7 +1759,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1759 pdev->current_state = state.event; 1759 pdev->current_state = state.event;
1760 } 1760 }
1761 else 1761 else
1762 IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, PCIDEV_NAME(pdev), pdev->current_state, state.event); 1762 IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, pci_name(pdev), pdev->current_state, state.event);
1763 up(&idev->sem); 1763 up(&idev->sem);
1764 return 0; 1764 return 0;
1765 } 1765 }
@@ -1787,7 +1787,7 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1787 1787
1788 if (!ndev) { 1788 if (!ndev) {
1789 IRDA_ERROR("%s - %s: no netdevice \n", 1789 IRDA_ERROR("%s - %s: no netdevice \n",
1790 __FUNCTION__, PCIDEV_NAME(pdev)); 1790 __FUNCTION__, pci_name(pdev));
1791 return 0; 1791 return 0;
1792 } 1792 }
1793 idev = ndev->priv; 1793 idev = ndev->priv;
@@ -1795,7 +1795,7 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1795 if (pdev->current_state == 0) { 1795 if (pdev->current_state == 0) {
1796 up(&idev->sem); 1796 up(&idev->sem);
1797 IRDA_WARNING("%s - %s: already resumed\n", 1797 IRDA_WARNING("%s - %s: already resumed\n",
1798 __FUNCTION__, PCIDEV_NAME(pdev)); 1798 __FUNCTION__, pci_name(pdev));
1799 return 0; 1799 return 0;
1800 } 1800 }
1801 1801
diff --git a/drivers/net/irda/vlsi_ir.h b/drivers/net/irda/vlsi_ir.h
index c37f0bc4c7..2d3b773d8e 100644
--- a/drivers/net/irda/vlsi_ir.h
+++ b/drivers/net/irda/vlsi_ir.h
@@ -41,39 +41,6 @@
41#define PCI_CLASS_SUBCLASS_MASK 0xffff 41#define PCI_CLASS_SUBCLASS_MASK 0xffff
42#endif 42#endif
43 43
44/* in recent 2.5 interrupt handlers have non-void return value */
45#ifndef IRQ_RETVAL
46typedef void irqreturn_t;
47#define IRQ_NONE
48#define IRQ_HANDLED
49#define IRQ_RETVAL(x)
50#endif
51
52/* some stuff need to check kernelversion. Not all 2.5 stuff was present
53 * in early 2.5.x - the test is merely to separate 2.4 from 2.5
54 */
55#include <linux/version.h>
56
57#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
58
59/* PDE() introduced in 2.5.4 */
60#ifdef CONFIG_PROC_FS
61#define PDE(inode) ((inode)->i_private)
62#endif
63
64/* irda crc16 calculation exported in 2.5.42 */
65#define irda_calc_crc16(fcs,buf,len) (GOOD_FCS)
66
67/* we use this for unified pci device name access */
68#define PCIDEV_NAME(pdev) ((pdev)->name)
69
70#else /* 2.5 or later */
71
72/* whatever we get from the associated struct device - bus:slot:dev.fn id */
73#define PCIDEV_NAME(pdev) (pci_name(pdev))
74
75#endif
76
77/* ================================================================ */ 44/* ================================================================ */
78 45
79/* non-standard PCI registers */ 46/* non-standard PCI registers */
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index d6f4f185bf..2194b56723 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -73,7 +73,7 @@
73#include <asm/abs_addr.h> 73#include <asm/abs_addr.h>
74#include <asm/iseries/mf.h> 74#include <asm/iseries/mf.h>
75#include <asm/uaccess.h> 75#include <asm/uaccess.h>
76 76#include <asm/firmware.h>
77#include <asm/iseries/hv_lp_config.h> 77#include <asm/iseries/hv_lp_config.h>
78#include <asm/iseries/hv_types.h> 78#include <asm/iseries/hv_types.h>
79#include <asm/iseries/hv_lp_event.h> 79#include <asm/iseries/hv_lp_event.h>
@@ -1668,7 +1668,7 @@ static struct vio_driver veth_driver = {
1668 * Module initialization/cleanup 1668 * Module initialization/cleanup
1669 */ 1669 */
1670 1670
1671void __exit veth_module_cleanup(void) 1671static void __exit veth_module_cleanup(void)
1672{ 1672{
1673 int i; 1673 int i;
1674 struct veth_lpar_connection *cnx; 1674 struct veth_lpar_connection *cnx;
@@ -1697,11 +1697,14 @@ void __exit veth_module_cleanup(void)
1697} 1697}
1698module_exit(veth_module_cleanup); 1698module_exit(veth_module_cleanup);
1699 1699
1700int __init veth_module_init(void) 1700static int __init veth_module_init(void)
1701{ 1701{
1702 int i; 1702 int i;
1703 int rc; 1703 int rc;
1704 1704
1705 if (!firmware_has_feature(FW_FEATURE_ISERIES))
1706 return -ENODEV;
1707
1705 this_lp = HvLpConfig_getLpIndex_outline(); 1708 this_lp = HvLpConfig_getLpIndex_outline();
1706 1709
1707 for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) { 1710 for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) {
diff --git a/drivers/net/ixgb/ixgb.h b/drivers/net/ixgb/ixgb.h
index 50ffe90488..f4aba4355b 100644
--- a/drivers/net/ixgb/ixgb.h
+++ b/drivers/net/ixgb/ixgb.h
@@ -171,6 +171,7 @@ struct ixgb_adapter {
171 171
172 /* TX */ 172 /* TX */
173 struct ixgb_desc_ring tx_ring ____cacheline_aligned_in_smp; 173 struct ixgb_desc_ring tx_ring ____cacheline_aligned_in_smp;
174 unsigned int restart_queue;
174 unsigned long timeo_start; 175 unsigned long timeo_start;
175 uint32_t tx_cmd_type; 176 uint32_t tx_cmd_type;
176 uint64_t hw_csum_tx_good; 177 uint64_t hw_csum_tx_good;
diff --git a/drivers/net/ixgb/ixgb_ethtool.c b/drivers/net/ixgb/ixgb_ethtool.c
index cd22523fb0..82c044d6e0 100644
--- a/drivers/net/ixgb/ixgb_ethtool.c
+++ b/drivers/net/ixgb/ixgb_ethtool.c
@@ -79,6 +79,7 @@ static struct ixgb_stats ixgb_gstrings_stats[] = {
79 {"tx_window_errors", IXGB_STAT(net_stats.tx_window_errors)}, 79 {"tx_window_errors", IXGB_STAT(net_stats.tx_window_errors)},
80 {"tx_deferred_ok", IXGB_STAT(stats.dc)}, 80 {"tx_deferred_ok", IXGB_STAT(stats.dc)},
81 {"tx_timeout_count", IXGB_STAT(tx_timeout_count) }, 81 {"tx_timeout_count", IXGB_STAT(tx_timeout_count) },
82 {"tx_restart_queue", IXGB_STAT(restart_queue) },
82 {"rx_long_length_errors", IXGB_STAT(stats.roc)}, 83 {"rx_long_length_errors", IXGB_STAT(stats.roc)},
83 {"rx_short_length_errors", IXGB_STAT(stats.ruc)}, 84 {"rx_short_length_errors", IXGB_STAT(stats.ruc)},
84#ifdef NETIF_F_TSO 85#ifdef NETIF_F_TSO
diff --git a/drivers/net/ixgb/ixgb_hw.c b/drivers/net/ixgb/ixgb_hw.c
index 02089b64e4..ecbf45861c 100644
--- a/drivers/net/ixgb/ixgb_hw.c
+++ b/drivers/net/ixgb/ixgb_hw.c
@@ -399,8 +399,9 @@ ixgb_init_rx_addrs(struct ixgb_hw *hw)
399 /* Zero out the other 15 receive addresses. */ 399 /* Zero out the other 15 receive addresses. */
400 DEBUGOUT("Clearing RAR[1-15]\n"); 400 DEBUGOUT("Clearing RAR[1-15]\n");
401 for(i = 1; i < IXGB_RAR_ENTRIES; i++) { 401 for(i = 1; i < IXGB_RAR_ENTRIES; i++) {
402 IXGB_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); 402 /* Write high reg first to disable the AV bit first */
403 IXGB_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); 403 IXGB_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
404 IXGB_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
404 } 405 }
405 406
406 return; 407 return;
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index e628126c9c..a083a91892 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -36,7 +36,7 @@ static char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
36#else 36#else
37#define DRIVERNAPI "-NAPI" 37#define DRIVERNAPI "-NAPI"
38#endif 38#endif
39#define DRV_VERSION "1.0.117-k2"DRIVERNAPI 39#define DRV_VERSION "1.0.126-k2"DRIVERNAPI
40char ixgb_driver_version[] = DRV_VERSION; 40char ixgb_driver_version[] = DRV_VERSION;
41static char ixgb_copyright[] = "Copyright (c) 1999-2006 Intel Corporation."; 41static char ixgb_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
42 42
@@ -1287,6 +1287,7 @@ ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1287 struct ixgb_buffer *buffer_info; 1287 struct ixgb_buffer *buffer_info;
1288 int len = skb->len; 1288 int len = skb->len;
1289 unsigned int offset = 0, size, count = 0, i; 1289 unsigned int offset = 0, size, count = 0, i;
1290 unsigned int mss = skb_shinfo(skb)->gso_size;
1290 1291
1291 unsigned int nr_frags = skb_shinfo(skb)->nr_frags; 1292 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
1292 unsigned int f; 1293 unsigned int f;
@@ -1298,6 +1299,11 @@ ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1298 while(len) { 1299 while(len) {
1299 buffer_info = &tx_ring->buffer_info[i]; 1300 buffer_info = &tx_ring->buffer_info[i];
1300 size = min(len, IXGB_MAX_DATA_PER_TXD); 1301 size = min(len, IXGB_MAX_DATA_PER_TXD);
1302 /* Workaround for premature desc write-backs
1303 * in TSO mode. Append 4-byte sentinel desc */
1304 if (unlikely(mss && !nr_frags && size == len && size > 8))
1305 size -= 4;
1306
1301 buffer_info->length = size; 1307 buffer_info->length = size;
1302 WARN_ON(buffer_info->dma != 0); 1308 WARN_ON(buffer_info->dma != 0);
1303 buffer_info->dma = 1309 buffer_info->dma =
@@ -1324,6 +1330,13 @@ ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1324 while(len) { 1330 while(len) {
1325 buffer_info = &tx_ring->buffer_info[i]; 1331 buffer_info = &tx_ring->buffer_info[i];
1326 size = min(len, IXGB_MAX_DATA_PER_TXD); 1332 size = min(len, IXGB_MAX_DATA_PER_TXD);
1333
1334 /* Workaround for premature desc write-backs
1335 * in TSO mode. Append 4-byte sentinel desc */
1336 if (unlikely(mss && !nr_frags && size == len
1337 && size > 8))
1338 size -= 4;
1339
1327 buffer_info->length = size; 1340 buffer_info->length = size;
1328 buffer_info->dma = 1341 buffer_info->dma =
1329 pci_map_page(adapter->pdev, 1342 pci_map_page(adapter->pdev,
@@ -1398,11 +1411,43 @@ ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
1398 IXGB_WRITE_REG(&adapter->hw, TDT, i); 1411 IXGB_WRITE_REG(&adapter->hw, TDT, i);
1399} 1412}
1400 1413
1414static int __ixgb_maybe_stop_tx(struct net_device *netdev, int size)
1415{
1416 struct ixgb_adapter *adapter = netdev_priv(netdev);
1417 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1418
1419 netif_stop_queue(netdev);
1420 /* Herbert's original patch had:
1421 * smp_mb__after_netif_stop_queue();
1422 * but since that doesn't exist yet, just open code it. */
1423 smp_mb();
1424
1425 /* We need to check again in a case another CPU has just
1426 * made room available. */
1427 if (likely(IXGB_DESC_UNUSED(tx_ring) < size))
1428 return -EBUSY;
1429
1430 /* A reprieve! */
1431 netif_start_queue(netdev);
1432 ++adapter->restart_queue;
1433 return 0;
1434}
1435
1436static int ixgb_maybe_stop_tx(struct net_device *netdev,
1437 struct ixgb_desc_ring *tx_ring, int size)
1438{
1439 if (likely(IXGB_DESC_UNUSED(tx_ring) >= size))
1440 return 0;
1441 return __ixgb_maybe_stop_tx(netdev, size);
1442}
1443
1444
1401/* Tx Descriptors needed, worst case */ 1445/* Tx Descriptors needed, worst case */
1402#define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \ 1446#define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \
1403 (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) 1447 (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
1404#define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) + \ 1448#define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) /* skb->date */ + \
1405 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1 1449 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1 /* for context */ \
1450 + 1 /* one more needed for sentinel TSO workaround */
1406 1451
1407static int 1452static int
1408ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev) 1453ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
@@ -1430,7 +1475,8 @@ ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1430 spin_lock_irqsave(&adapter->tx_lock, flags); 1475 spin_lock_irqsave(&adapter->tx_lock, flags);
1431#endif 1476#endif
1432 1477
1433 if(unlikely(IXGB_DESC_UNUSED(&adapter->tx_ring) < DESC_NEEDED)) { 1478 if (unlikely(ixgb_maybe_stop_tx(netdev, &adapter->tx_ring,
1479 DESC_NEEDED))) {
1434 netif_stop_queue(netdev); 1480 netif_stop_queue(netdev);
1435 spin_unlock_irqrestore(&adapter->tx_lock, flags); 1481 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1436 return NETDEV_TX_BUSY; 1482 return NETDEV_TX_BUSY;
@@ -1468,8 +1514,7 @@ ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1468 1514
1469#ifdef NETIF_F_LLTX 1515#ifdef NETIF_F_LLTX
1470 /* Make sure there is space in the ring for the next send. */ 1516 /* Make sure there is space in the ring for the next send. */
1471 if(unlikely(IXGB_DESC_UNUSED(&adapter->tx_ring) < DESC_NEEDED)) 1517 ixgb_maybe_stop_tx(netdev, &adapter->tx_ring, DESC_NEEDED);
1472 netif_stop_queue(netdev);
1473 1518
1474 spin_unlock_irqrestore(&adapter->tx_lock, flags); 1519 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1475 1520
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index 82c10dec1b..2b739fd584 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -229,9 +229,11 @@ struct net_device loopback_dev = {
229}; 229};
230 230
231/* Setup and register the loopback device. */ 231/* Setup and register the loopback device. */
232int __init loopback_init(void) 232static int __init loopback_init(void)
233{ 233{
234 return register_netdev(&loopback_dev); 234 return register_netdev(&loopback_dev);
235}; 235};
236 236
237module_init(loopback_init);
238
237EXPORT_SYMBOL(loopback_dev); 239EXPORT_SYMBOL(loopback_dev);
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index c41ae4286e..b3bf864227 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -314,6 +314,13 @@ int mv643xx_eth_free_tx_descs(struct net_device *dev, int force)
314 314
315 while (mp->tx_desc_count > 0) { 315 while (mp->tx_desc_count > 0) {
316 spin_lock_irqsave(&mp->lock, flags); 316 spin_lock_irqsave(&mp->lock, flags);
317
318 /* tx_desc_count might have changed before acquiring the lock */
319 if (mp->tx_desc_count <= 0) {
320 spin_unlock_irqrestore(&mp->lock, flags);
321 return released;
322 }
323
317 tx_index = mp->tx_used_desc_q; 324 tx_index = mp->tx_used_desc_q;
318 desc = &mp->p_tx_desc_area[tx_index]; 325 desc = &mp->p_tx_desc_area[tx_index];
319 cmd_sts = desc->cmd_sts; 326 cmd_sts = desc->cmd_sts;
@@ -332,13 +339,13 @@ int mv643xx_eth_free_tx_descs(struct net_device *dev, int force)
332 if (skb) 339 if (skb)
333 mp->tx_skb[tx_index] = NULL; 340 mp->tx_skb[tx_index] = NULL;
334 341
335 spin_unlock_irqrestore(&mp->lock, flags);
336
337 if (cmd_sts & ETH_ERROR_SUMMARY) { 342 if (cmd_sts & ETH_ERROR_SUMMARY) {
338 printk("%s: Error in TX\n", dev->name); 343 printk("%s: Error in TX\n", dev->name);
339 mp->stats.tx_errors++; 344 mp->stats.tx_errors++;
340 } 345 }
341 346
347 spin_unlock_irqrestore(&mp->lock, flags);
348
342 if (cmd_sts & ETH_TX_FIRST_DESC) 349 if (cmd_sts & ETH_TX_FIRST_DESC)
343 dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE); 350 dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE);
344 else 351 else
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 94ac168be5..61cbd4a604 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -71,7 +71,7 @@
71#include "myri10ge_mcp.h" 71#include "myri10ge_mcp.h"
72#include "myri10ge_mcp_gen_header.h" 72#include "myri10ge_mcp_gen_header.h"
73 73
74#define MYRI10GE_VERSION_STR "1.1.0" 74#define MYRI10GE_VERSION_STR "1.2.0"
75 75
76MODULE_DESCRIPTION("Myricom 10G driver (10GbE)"); 76MODULE_DESCRIPTION("Myricom 10G driver (10GbE)");
77MODULE_AUTHOR("Maintainer: help@myri.com"); 77MODULE_AUTHOR("Maintainer: help@myri.com");
@@ -199,8 +199,6 @@ struct myri10ge_priv {
199 unsigned long serial_number; 199 unsigned long serial_number;
200 int vendor_specific_offset; 200 int vendor_specific_offset;
201 int fw_multicast_support; 201 int fw_multicast_support;
202 u32 devctl;
203 u16 msi_flags;
204 u32 read_dma; 202 u32 read_dma;
205 u32 write_dma; 203 u32 write_dma;
206 u32 read_write_dma; 204 u32 read_write_dma;
@@ -228,7 +226,7 @@ module_param(myri10ge_small_bytes, int, S_IRUGO | S_IWUSR);
228MODULE_PARM_DESC(myri10ge_small_bytes, "Threshold of small packets\n"); 226MODULE_PARM_DESC(myri10ge_small_bytes, "Threshold of small packets\n");
229 227
230static int myri10ge_msi = 1; /* enable msi by default */ 228static int myri10ge_msi = 1; /* enable msi by default */
231module_param(myri10ge_msi, int, S_IRUGO); 229module_param(myri10ge_msi, int, S_IRUGO | S_IWUSR);
232MODULE_PARM_DESC(myri10ge_msi, "Enable Message Signalled Interrupts\n"); 230MODULE_PARM_DESC(myri10ge_msi, "Enable Message Signalled Interrupts\n");
233 231
234static int myri10ge_intr_coal_delay = 25; 232static int myri10ge_intr_coal_delay = 25;
@@ -276,6 +274,10 @@ static int myri10ge_fill_thresh = 256;
276module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR); 274module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR);
277MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed\n"); 275MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed\n");
278 276
277static int myri10ge_wcfifo = 1;
278module_param(myri10ge_wcfifo, int, S_IRUGO);
279MODULE_PARM_DESC(myri10ge_wcfifo, "Enable WC Fifo when WC is enabled\n");
280
279#define MYRI10GE_FW_OFFSET 1024*1024 281#define MYRI10GE_FW_OFFSET 1024*1024
280#define MYRI10GE_HIGHPART_TO_U32(X) \ 282#define MYRI10GE_HIGHPART_TO_U32(X) \
281(sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0) 283(sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0)
@@ -721,12 +723,10 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
721 status |= 723 status |=
722 myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_ACK_OFFSET, &cmd, 0); 724 myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_ACK_OFFSET, &cmd, 0);
723 mgp->irq_claim = (__iomem __be32 *) (mgp->sram + cmd.data0); 725 mgp->irq_claim = (__iomem __be32 *) (mgp->sram + cmd.data0);
724 if (!mgp->msi_enabled) { 726 status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_DEASSERT_OFFSET,
725 status |= myri10ge_send_cmd 727 &cmd, 0);
726 (mgp, MXGEFW_CMD_GET_IRQ_DEASSERT_OFFSET, &cmd, 0); 728 mgp->irq_deassert = (__iomem __be32 *) (mgp->sram + cmd.data0);
727 mgp->irq_deassert = (__iomem __be32 *) (mgp->sram + cmd.data0);
728 729
729 }
730 status |= myri10ge_send_cmd 730 status |= myri10ge_send_cmd
731 (mgp, MXGEFW_CMD_GET_INTR_COAL_DELAY_OFFSET, &cmd, 0); 731 (mgp, MXGEFW_CMD_GET_INTR_COAL_DELAY_OFFSET, &cmd, 0);
732 mgp->intr_coal_delay_ptr = (__iomem __be32 *) (mgp->sram + cmd.data0); 732 mgp->intr_coal_delay_ptr = (__iomem __be32 *) (mgp->sram + cmd.data0);
@@ -1619,6 +1619,41 @@ static void myri10ge_free_rings(struct net_device *dev)
1619 mgp->tx.req_list = NULL; 1619 mgp->tx.req_list = NULL;
1620} 1620}
1621 1621
1622static int myri10ge_request_irq(struct myri10ge_priv *mgp)
1623{
1624 struct pci_dev *pdev = mgp->pdev;
1625 int status;
1626
1627 if (myri10ge_msi) {
1628 status = pci_enable_msi(pdev);
1629 if (status != 0)
1630 dev_err(&pdev->dev,
1631 "Error %d setting up MSI; falling back to xPIC\n",
1632 status);
1633 else
1634 mgp->msi_enabled = 1;
1635 } else {
1636 mgp->msi_enabled = 0;
1637 }
1638 status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED,
1639 mgp->dev->name, mgp);
1640 if (status != 0) {
1641 dev_err(&pdev->dev, "failed to allocate IRQ\n");
1642 if (mgp->msi_enabled)
1643 pci_disable_msi(pdev);
1644 }
1645 return status;
1646}
1647
1648static void myri10ge_free_irq(struct myri10ge_priv *mgp)
1649{
1650 struct pci_dev *pdev = mgp->pdev;
1651
1652 free_irq(pdev->irq, mgp);
1653 if (mgp->msi_enabled)
1654 pci_disable_msi(pdev);
1655}
1656
1622static int myri10ge_open(struct net_device *dev) 1657static int myri10ge_open(struct net_device *dev)
1623{ 1658{
1624 struct myri10ge_priv *mgp; 1659 struct myri10ge_priv *mgp;
@@ -1634,10 +1669,13 @@ static int myri10ge_open(struct net_device *dev)
1634 status = myri10ge_reset(mgp); 1669 status = myri10ge_reset(mgp);
1635 if (status != 0) { 1670 if (status != 0) {
1636 printk(KERN_ERR "myri10ge: %s: failed reset\n", dev->name); 1671 printk(KERN_ERR "myri10ge: %s: failed reset\n", dev->name);
1637 mgp->running = MYRI10GE_ETH_STOPPED; 1672 goto abort_with_nothing;
1638 return -ENXIO;
1639 } 1673 }
1640 1674
1675 status = myri10ge_request_irq(mgp);
1676 if (status != 0)
1677 goto abort_with_nothing;
1678
1641 /* decide what small buffer size to use. For good TCP rx 1679 /* decide what small buffer size to use. For good TCP rx
1642 * performance, it is important to not receive 1514 byte 1680 * performance, it is important to not receive 1514 byte
1643 * frames into jumbo buffers, as it confuses the socket buffer 1681 * frames into jumbo buffers, as it confuses the socket buffer
@@ -1677,10 +1715,10 @@ static int myri10ge_open(struct net_device *dev)
1677 "myri10ge: %s: failed to get ring sizes or locations\n", 1715 "myri10ge: %s: failed to get ring sizes or locations\n",
1678 dev->name); 1716 dev->name);
1679 mgp->running = MYRI10GE_ETH_STOPPED; 1717 mgp->running = MYRI10GE_ETH_STOPPED;
1680 return -ENXIO; 1718 goto abort_with_irq;
1681 } 1719 }
1682 1720
1683 if (mgp->mtrr >= 0) { 1721 if (myri10ge_wcfifo && mgp->mtrr >= 0) {
1684 mgp->tx.wc_fifo = (u8 __iomem *) mgp->sram + MXGEFW_ETH_SEND_4; 1722 mgp->tx.wc_fifo = (u8 __iomem *) mgp->sram + MXGEFW_ETH_SEND_4;
1685 mgp->rx_small.wc_fifo = 1723 mgp->rx_small.wc_fifo =
1686 (u8 __iomem *) mgp->sram + MXGEFW_ETH_RECV_SMALL; 1724 (u8 __iomem *) mgp->sram + MXGEFW_ETH_RECV_SMALL;
@@ -1708,7 +1746,7 @@ static int myri10ge_open(struct net_device *dev)
1708 1746
1709 status = myri10ge_allocate_rings(dev); 1747 status = myri10ge_allocate_rings(dev);
1710 if (status != 0) 1748 if (status != 0)
1711 goto abort_with_nothing; 1749 goto abort_with_irq;
1712 1750
1713 /* now give firmware buffers sizes, and MTU */ 1751 /* now give firmware buffers sizes, and MTU */
1714 cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN; 1752 cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN;
@@ -1771,6 +1809,9 @@ static int myri10ge_open(struct net_device *dev)
1771abort_with_rings: 1809abort_with_rings:
1772 myri10ge_free_rings(dev); 1810 myri10ge_free_rings(dev);
1773 1811
1812abort_with_irq:
1813 myri10ge_free_irq(mgp);
1814
1774abort_with_nothing: 1815abort_with_nothing:
1775 mgp->running = MYRI10GE_ETH_STOPPED; 1816 mgp->running = MYRI10GE_ETH_STOPPED;
1776 return -ENOMEM; 1817 return -ENOMEM;
@@ -1807,7 +1848,7 @@ static int myri10ge_close(struct net_device *dev)
1807 printk(KERN_ERR "myri10ge: %s never got down irq\n", dev->name); 1848 printk(KERN_ERR "myri10ge: %s never got down irq\n", dev->name);
1808 1849
1809 netif_tx_disable(dev); 1850 netif_tx_disable(dev);
1810 1851 myri10ge_free_irq(mgp);
1811 myri10ge_free_rings(dev); 1852 myri10ge_free_rings(dev);
1812 1853
1813 mgp->running = MYRI10GE_ETH_STOPPED; 1854 mgp->running = MYRI10GE_ETH_STOPPED;
@@ -2481,34 +2522,6 @@ static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
2481 } 2522 }
2482} 2523}
2483 2524
2484static void myri10ge_save_state(struct myri10ge_priv *mgp)
2485{
2486 struct pci_dev *pdev = mgp->pdev;
2487 int cap;
2488
2489 pci_save_state(pdev);
2490 /* now save PCIe and MSI state that Linux will not
2491 * save for us */
2492 cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
2493 pci_read_config_dword(pdev, cap + PCI_EXP_DEVCTL, &mgp->devctl);
2494 cap = pci_find_capability(pdev, PCI_CAP_ID_MSI);
2495 pci_read_config_word(pdev, cap + PCI_MSI_FLAGS, &mgp->msi_flags);
2496}
2497
2498static void myri10ge_restore_state(struct myri10ge_priv *mgp)
2499{
2500 struct pci_dev *pdev = mgp->pdev;
2501 int cap;
2502
2503 /* restore PCIe and MSI state that linux will not */
2504 cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
2505 pci_write_config_dword(pdev, cap + PCI_CAP_ID_EXP, mgp->devctl);
2506 cap = pci_find_capability(pdev, PCI_CAP_ID_MSI);
2507 pci_write_config_word(pdev, cap + PCI_MSI_FLAGS, mgp->msi_flags);
2508
2509 pci_restore_state(pdev);
2510}
2511
2512#ifdef CONFIG_PM 2525#ifdef CONFIG_PM
2513 2526
2514static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state) 2527static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state)
@@ -2529,11 +2542,10 @@ static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state)
2529 rtnl_unlock(); 2542 rtnl_unlock();
2530 } 2543 }
2531 myri10ge_dummy_rdma(mgp, 0); 2544 myri10ge_dummy_rdma(mgp, 0);
2532 free_irq(pdev->irq, mgp); 2545 pci_save_state(pdev);
2533 myri10ge_save_state(mgp);
2534 pci_disable_device(pdev); 2546 pci_disable_device(pdev);
2535 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 2547
2536 return 0; 2548 return pci_set_power_state(pdev, pci_choose_state(pdev, state));
2537} 2549}
2538 2550
2539static int myri10ge_resume(struct pci_dev *pdev) 2551static int myri10ge_resume(struct pci_dev *pdev)
@@ -2555,34 +2567,33 @@ static int myri10ge_resume(struct pci_dev *pdev)
2555 mgp->dev->name); 2567 mgp->dev->name);
2556 return -EIO; 2568 return -EIO;
2557 } 2569 }
2558 myri10ge_restore_state(mgp); 2570
2571 status = pci_restore_state(pdev);
2572 if (status)
2573 return status;
2559 2574
2560 status = pci_enable_device(pdev); 2575 status = pci_enable_device(pdev);
2561 if (status < 0) { 2576 if (status) {
2562 dev_err(&pdev->dev, "failed to enable device\n"); 2577 dev_err(&pdev->dev, "failed to enable device\n");
2563 return -EIO; 2578 return status;
2564 } 2579 }
2565 2580
2566 pci_set_master(pdev); 2581 pci_set_master(pdev);
2567 2582
2568 status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED,
2569 netdev->name, mgp);
2570 if (status != 0) {
2571 dev_err(&pdev->dev, "failed to allocate IRQ\n");
2572 goto abort_with_enabled;
2573 }
2574
2575 myri10ge_reset(mgp); 2583 myri10ge_reset(mgp);
2576 myri10ge_dummy_rdma(mgp, 1); 2584 myri10ge_dummy_rdma(mgp, 1);
2577 2585
2578 /* Save configuration space to be restored if the 2586 /* Save configuration space to be restored if the
2579 * nic resets due to a parity error */ 2587 * nic resets due to a parity error */
2580 myri10ge_save_state(mgp); 2588 pci_save_state(pdev);
2581 2589
2582 if (netif_running(netdev)) { 2590 if (netif_running(netdev)) {
2583 rtnl_lock(); 2591 rtnl_lock();
2584 myri10ge_open(netdev); 2592 status = myri10ge_open(netdev);
2585 rtnl_unlock(); 2593 rtnl_unlock();
2594 if (status != 0)
2595 goto abort_with_enabled;
2596
2586 } 2597 }
2587 netif_device_attach(netdev); 2598 netif_device_attach(netdev);
2588 2599
@@ -2640,7 +2651,11 @@ static void myri10ge_watchdog(struct work_struct *work)
2640 * when the driver was loaded, or the last time the 2651 * when the driver was loaded, or the last time the
2641 * nic was resumed from power saving mode. 2652 * nic was resumed from power saving mode.
2642 */ 2653 */
2643 myri10ge_restore_state(mgp); 2654 pci_restore_state(mgp->pdev);
2655
2656 /* save state again for accounting reasons */
2657 pci_save_state(mgp->pdev);
2658
2644 } else { 2659 } else {
2645 /* if we get back -1's from our slot, perhaps somebody 2660 /* if we get back -1's from our slot, perhaps somebody
2646 * powered off our card. Don't try to reset it in 2661 * powered off our card. Don't try to reset it in
@@ -2856,23 +2871,6 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2856 goto abort_with_firmware; 2871 goto abort_with_firmware;
2857 } 2872 }
2858 2873
2859 if (myri10ge_msi) {
2860 status = pci_enable_msi(pdev);
2861 if (status != 0)
2862 dev_err(&pdev->dev,
2863 "Error %d setting up MSI; falling back to xPIC\n",
2864 status);
2865 else
2866 mgp->msi_enabled = 1;
2867 }
2868
2869 status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED,
2870 netdev->name, mgp);
2871 if (status != 0) {
2872 dev_err(&pdev->dev, "failed to allocate IRQ\n");
2873 goto abort_with_firmware;
2874 }
2875
2876 pci_set_drvdata(pdev, mgp); 2874 pci_set_drvdata(pdev, mgp);
2877 if ((myri10ge_initial_mtu + ETH_HLEN) > MYRI10GE_MAX_ETHER_MTU) 2875 if ((myri10ge_initial_mtu + ETH_HLEN) > MYRI10GE_MAX_ETHER_MTU)
2878 myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN; 2876 myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN;
@@ -2884,7 +2882,6 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2884 netdev->hard_start_xmit = myri10ge_xmit; 2882 netdev->hard_start_xmit = myri10ge_xmit;
2885 netdev->get_stats = myri10ge_get_stats; 2883 netdev->get_stats = myri10ge_get_stats;
2886 netdev->base_addr = mgp->iomem_base; 2884 netdev->base_addr = mgp->iomem_base;
2887 netdev->irq = pdev->irq;
2888 netdev->change_mtu = myri10ge_change_mtu; 2885 netdev->change_mtu = myri10ge_change_mtu;
2889 netdev->set_multicast_list = myri10ge_set_multicast_list; 2886 netdev->set_multicast_list = myri10ge_set_multicast_list;
2890 netdev->set_mac_address = myri10ge_set_mac_address; 2887 netdev->set_mac_address = myri10ge_set_mac_address;
@@ -2894,9 +2891,18 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2894 netdev->poll = myri10ge_poll; 2891 netdev->poll = myri10ge_poll;
2895 netdev->weight = myri10ge_napi_weight; 2892 netdev->weight = myri10ge_napi_weight;
2896 2893
2894 /* make sure we can get an irq, and that MSI can be
2895 * setup (if available). Also ensure netdev->irq
2896 * is set to correct value if MSI is enabled */
2897 status = myri10ge_request_irq(mgp);
2898 if (status != 0)
2899 goto abort_with_firmware;
2900 netdev->irq = pdev->irq;
2901 myri10ge_free_irq(mgp);
2902
2897 /* Save configuration space to be restored if the 2903 /* Save configuration space to be restored if the
2898 * nic resets due to a parity error */ 2904 * nic resets due to a parity error */
2899 myri10ge_save_state(mgp); 2905 pci_save_state(pdev);
2900 2906
2901 /* Setup the watchdog timer */ 2907 /* Setup the watchdog timer */
2902 setup_timer(&mgp->watchdog_timer, myri10ge_watchdog_timer, 2908 setup_timer(&mgp->watchdog_timer, myri10ge_watchdog_timer,
@@ -2907,19 +2913,17 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2907 status = register_netdev(netdev); 2913 status = register_netdev(netdev);
2908 if (status != 0) { 2914 if (status != 0) {
2909 dev_err(&pdev->dev, "register_netdev failed: %d\n", status); 2915 dev_err(&pdev->dev, "register_netdev failed: %d\n", status);
2910 goto abort_with_irq; 2916 goto abort_with_state;
2911 } 2917 }
2912 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n", 2918 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n",
2913 (mgp->msi_enabled ? "MSI" : "xPIC"), 2919 (mgp->msi_enabled ? "MSI" : "xPIC"),
2914 pdev->irq, mgp->tx.boundary, mgp->fw_name, 2920 netdev->irq, mgp->tx.boundary, mgp->fw_name,
2915 (mgp->mtrr >= 0 ? "Enabled" : "Disabled")); 2921 (mgp->mtrr >= 0 ? "Enabled" : "Disabled"));
2916 2922
2917 return 0; 2923 return 0;
2918 2924
2919abort_with_irq: 2925abort_with_state:
2920 free_irq(pdev->irq, mgp); 2926 pci_restore_state(pdev);
2921 if (mgp->msi_enabled)
2922 pci_disable_msi(pdev);
2923 2927
2924abort_with_firmware: 2928abort_with_firmware:
2925 myri10ge_dummy_rdma(mgp, 0); 2929 myri10ge_dummy_rdma(mgp, 0);
@@ -2970,12 +2974,12 @@ static void myri10ge_remove(struct pci_dev *pdev)
2970 flush_scheduled_work(); 2974 flush_scheduled_work();
2971 netdev = mgp->dev; 2975 netdev = mgp->dev;
2972 unregister_netdev(netdev); 2976 unregister_netdev(netdev);
2973 free_irq(pdev->irq, mgp);
2974 if (mgp->msi_enabled)
2975 pci_disable_msi(pdev);
2976 2977
2977 myri10ge_dummy_rdma(mgp, 0); 2978 myri10ge_dummy_rdma(mgp, 0);
2978 2979
2980 /* avoid a memory leak */
2981 pci_restore_state(pdev);
2982
2979 bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry); 2983 bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry);
2980 dma_free_coherent(&pdev->dev, bytes, 2984 dma_free_coherent(&pdev->dev, bytes,
2981 mgp->rx_done.entry, mgp->rx_done.bus); 2985 mgp->rx_done.entry, mgp->rx_done.bus);
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index b5410bee5f..e8598b8092 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -63,12 +63,11 @@
63 63
64#include "netxen_nic_hw.h" 64#include "netxen_nic_hw.h"
65 65
66#define NETXEN_NIC_BUILD_NO "1" 66#define NETXEN_NIC_BUILD_NO "2"
67#define _NETXEN_NIC_LINUX_MAJOR 3 67#define _NETXEN_NIC_LINUX_MAJOR 3
68#define _NETXEN_NIC_LINUX_MINOR 3 68#define _NETXEN_NIC_LINUX_MINOR 3
69#define _NETXEN_NIC_LINUX_SUBVERSION 2 69#define _NETXEN_NIC_LINUX_SUBVERSION 3
70#define NETXEN_NIC_LINUX_VERSIONID "3.3.2" "-" NETXEN_NIC_BUILD_NO 70#define NETXEN_NIC_LINUX_VERSIONID "3.3.3" "-" NETXEN_NIC_BUILD_NO
71#define NETXEN_NIC_FW_VERSIONID "3.3.2"
72 71
73#define RCV_DESC_RINGSIZE \ 72#define RCV_DESC_RINGSIZE \
74 (sizeof(struct rcv_desc) * adapter->max_rx_desc_count) 73 (sizeof(struct rcv_desc) * adapter->max_rx_desc_count)
@@ -137,7 +136,7 @@ extern struct workqueue_struct *netxen_workq;
137#define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START 136#define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START
138 137
139#define MAX_RX_BUFFER_LENGTH 1760 138#define MAX_RX_BUFFER_LENGTH 1760
140#define MAX_RX_JUMBO_BUFFER_LENGTH 9046 139#define MAX_RX_JUMBO_BUFFER_LENGTH 8062
141#define MAX_RX_LRO_BUFFER_LENGTH ((48*1024)-512) 140#define MAX_RX_LRO_BUFFER_LENGTH ((48*1024)-512)
142#define RX_DMA_MAP_LEN (MAX_RX_BUFFER_LENGTH - 2) 141#define RX_DMA_MAP_LEN (MAX_RX_BUFFER_LENGTH - 2)
143#define RX_JUMBO_DMA_MAP_LEN \ 142#define RX_JUMBO_DMA_MAP_LEN \
@@ -199,9 +198,9 @@ enum {
199 (RCV_DESC_NORMAL))) 198 (RCV_DESC_NORMAL)))
200 199
201#define MAX_CMD_DESCRIPTORS 1024 200#define MAX_CMD_DESCRIPTORS 1024
202#define MAX_RCV_DESCRIPTORS 32768 201#define MAX_RCV_DESCRIPTORS 16384
203#define MAX_JUMBO_RCV_DESCRIPTORS 4096 202#define MAX_JUMBO_RCV_DESCRIPTORS 1024
204#define MAX_LRO_RCV_DESCRIPTORS 2048 203#define MAX_LRO_RCV_DESCRIPTORS 64
205#define MAX_RCVSTATUS_DESCRIPTORS MAX_RCV_DESCRIPTORS 204#define MAX_RCVSTATUS_DESCRIPTORS MAX_RCV_DESCRIPTORS
206#define MAX_JUMBO_RCV_DESC MAX_JUMBO_RCV_DESCRIPTORS 205#define MAX_JUMBO_RCV_DESC MAX_JUMBO_RCV_DESCRIPTORS
207#define MAX_RCV_DESC MAX_RCV_DESCRIPTORS 206#define MAX_RCV_DESC MAX_RCV_DESCRIPTORS
@@ -240,49 +239,39 @@ extern unsigned long long netxen_dma_mask;
240 239
241typedef u32 netxen_ctx_msg; 240typedef u32 netxen_ctx_msg;
242 241
243#define _netxen_set_bits(config_word, start, bits, val) {\
244 unsigned long long mask = (((1ULL << (bits)) - 1) << (start)); \
245 unsigned long long value = (val); \
246 (config_word) &= ~mask; \
247 (config_word) |= (((value) << (start)) & mask); \
248}
249
250#define netxen_set_msg_peg_id(config_word, val) \ 242#define netxen_set_msg_peg_id(config_word, val) \
251 _netxen_set_bits(config_word, 0, 2, val) 243 ((config_word) &= ~3, (config_word) |= val & 3)
252#define netxen_set_msg_privid(config_word) \ 244#define netxen_set_msg_privid(config_word) \
253 set_bit(2, (unsigned long*)&config_word) 245 ((config_word) |= 1 << 2)
254#define netxen_set_msg_count(config_word, val) \ 246#define netxen_set_msg_count(config_word, val) \
255 _netxen_set_bits(config_word, 3, 15, val) 247 ((config_word) &= ~(0x7fff<<3), (config_word) |= (val & 0x7fff) << 3)
256#define netxen_set_msg_ctxid(config_word, val) \ 248#define netxen_set_msg_ctxid(config_word, val) \
257 _netxen_set_bits(config_word, 18, 10, val) 249 ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18)
258#define netxen_set_msg_opcode(config_word, val) \ 250#define netxen_set_msg_opcode(config_word, val) \
259 _netxen_set_bits(config_word, 28, 4, val) 251 ((config_word) &= ~(0xf<<24), (config_word) |= (val & 0xf) << 24)
260 252
261struct netxen_rcv_context { 253struct netxen_rcv_context {
262 u32 rcv_ring_addr_lo; 254 __le64 rcv_ring_addr;
263 u32 rcv_ring_addr_hi; 255 __le32 rcv_ring_size;
264 u32 rcv_ring_size; 256 __le32 rsrvd;
265 u32 rsrvd;
266}; 257};
267 258
268struct netxen_ring_ctx { 259struct netxen_ring_ctx {
269 260
270 /* one command ring */ 261 /* one command ring */
271 u64 cmd_consumer_offset; 262 __le64 cmd_consumer_offset;
272 u32 cmd_ring_addr_lo; 263 __le64 cmd_ring_addr;
273 u32 cmd_ring_addr_hi; 264 __le32 cmd_ring_size;
274 u32 cmd_ring_size; 265 __le32 rsrvd;
275 u32 rsrvd;
276 266
277 /* three receive rings */ 267 /* three receive rings */
278 struct netxen_rcv_context rcv_ctx[3]; 268 struct netxen_rcv_context rcv_ctx[3];
279 269
280 /* one status ring */ 270 /* one status ring */
281 u32 sts_ring_addr_lo; 271 __le64 sts_ring_addr;
282 u32 sts_ring_addr_hi; 272 __le32 sts_ring_size;
283 u32 sts_ring_size;
284 273
285 u32 ctx_id; 274 __le32 ctx_id;
286} __attribute__ ((aligned(64))); 275} __attribute__ ((aligned(64)));
287 276
288/* 277/*
@@ -306,81 +295,85 @@ struct netxen_ring_ctx {
306 ((cmd_desc)->port_ctxid |= ((var) & 0x0F)) 295 ((cmd_desc)->port_ctxid |= ((var) & 0x0F))
307 296
308#define netxen_set_cmd_desc_flags(cmd_desc, val) \ 297#define netxen_set_cmd_desc_flags(cmd_desc, val) \
309 _netxen_set_bits((cmd_desc)->flags_opcode, 0, 7, val) 298 ((cmd_desc)->flags_opcode &= ~cpu_to_le16(0x7f), \
299 (cmd_desc)->flags_opcode |= cpu_to_le16((val) & 0x7f))
310#define netxen_set_cmd_desc_opcode(cmd_desc, val) \ 300#define netxen_set_cmd_desc_opcode(cmd_desc, val) \
311 _netxen_set_bits((cmd_desc)->flags_opcode, 7, 6, val) 301 ((cmd_desc)->flags_opcode &= ~cpu_to_le16(0x3f<<7), \
302 (cmd_desc)->flags_opcode |= cpu_to_le16((val) & (0x3f<<7)))
312 303
313#define netxen_set_cmd_desc_num_of_buff(cmd_desc, val) \ 304#define netxen_set_cmd_desc_num_of_buff(cmd_desc, val) \
314 _netxen_set_bits((cmd_desc)->num_of_buffers_total_length, 0, 8, val); 305 ((cmd_desc)->num_of_buffers_total_length &= ~cpu_to_le32(0xff), \
306 (cmd_desc)->num_of_buffers_total_length |= cpu_to_le32((val) & 0xff))
315#define netxen_set_cmd_desc_totallength(cmd_desc, val) \ 307#define netxen_set_cmd_desc_totallength(cmd_desc, val) \
316 _netxen_set_bits((cmd_desc)->num_of_buffers_total_length, 8, 24, val); 308 ((cmd_desc)->num_of_buffers_total_length &= cpu_to_le32(0xff), \
309 (cmd_desc)->num_of_buffers_total_length |= cpu_to_le32(val << 24))
317 310
318#define netxen_get_cmd_desc_opcode(cmd_desc) \ 311#define netxen_get_cmd_desc_opcode(cmd_desc) \
319 (((cmd_desc)->flags_opcode >> 7) & 0x003F) 312 ((le16_to_cpu((cmd_desc)->flags_opcode) >> 7) & 0x003F)
320#define netxen_get_cmd_desc_totallength(cmd_desc) \ 313#define netxen_get_cmd_desc_totallength(cmd_desc) \
321 (((cmd_desc)->num_of_buffers_total_length >> 8) & 0x0FFFFFF) 314 (le32_to_cpu((cmd_desc)->num_of_buffers_total_length) >> 8)
322 315
323struct cmd_desc_type0 { 316struct cmd_desc_type0 {
324 u8 tcp_hdr_offset; /* For LSO only */ 317 u8 tcp_hdr_offset; /* For LSO only */
325 u8 ip_hdr_offset; /* For LSO only */ 318 u8 ip_hdr_offset; /* For LSO only */
326 /* Bit pattern: 0-6 flags, 7-12 opcode, 13-15 unused */ 319 /* Bit pattern: 0-6 flags, 7-12 opcode, 13-15 unused */
327 u16 flags_opcode; 320 __le16 flags_opcode;
328 /* Bit pattern: 0-7 total number of segments, 321 /* Bit pattern: 0-7 total number of segments,
329 8-31 Total size of the packet */ 322 8-31 Total size of the packet */
330 u32 num_of_buffers_total_length; 323 __le32 num_of_buffers_total_length;
331 union { 324 union {
332 struct { 325 struct {
333 u32 addr_low_part2; 326 __le32 addr_low_part2;
334 u32 addr_high_part2; 327 __le32 addr_high_part2;
335 }; 328 };
336 u64 addr_buffer2; 329 __le64 addr_buffer2;
337 }; 330 };
338 331
339 u16 reference_handle; /* changed to u16 to add mss */ 332 __le16 reference_handle; /* changed to u16 to add mss */
340 u16 mss; /* passed by NDIS_PACKET for LSO */ 333 __le16 mss; /* passed by NDIS_PACKET for LSO */
341 /* Bit pattern 0-3 port, 0-3 ctx id */ 334 /* Bit pattern 0-3 port, 0-3 ctx id */
342 u8 port_ctxid; 335 u8 port_ctxid;
343 u8 total_hdr_length; /* LSO only : MAC+IP+TCP Hdr size */ 336 u8 total_hdr_length; /* LSO only : MAC+IP+TCP Hdr size */
344 u16 conn_id; /* IPSec offoad only */ 337 __le16 conn_id; /* IPSec offoad only */
345 338
346 union { 339 union {
347 struct { 340 struct {
348 u32 addr_low_part3; 341 __le32 addr_low_part3;
349 u32 addr_high_part3; 342 __le32 addr_high_part3;
350 }; 343 };
351 u64 addr_buffer3; 344 __le64 addr_buffer3;
352 }; 345 };
353 union { 346 union {
354 struct { 347 struct {
355 u32 addr_low_part1; 348 __le32 addr_low_part1;
356 u32 addr_high_part1; 349 __le32 addr_high_part1;
357 }; 350 };
358 u64 addr_buffer1; 351 __le64 addr_buffer1;
359 }; 352 };
360 353
361 u16 buffer1_length; 354 __le16 buffer1_length;
362 u16 buffer2_length; 355 __le16 buffer2_length;
363 u16 buffer3_length; 356 __le16 buffer3_length;
364 u16 buffer4_length; 357 __le16 buffer4_length;
365 358
366 union { 359 union {
367 struct { 360 struct {
368 u32 addr_low_part4; 361 __le32 addr_low_part4;
369 u32 addr_high_part4; 362 __le32 addr_high_part4;
370 }; 363 };
371 u64 addr_buffer4; 364 __le64 addr_buffer4;
372 }; 365 };
373 366
374 u64 unused; 367 __le64 unused;
375 368
376} __attribute__ ((aligned(64))); 369} __attribute__ ((aligned(64)));
377 370
378/* Note: sizeof(rcv_desc) should always be a mutliple of 2 */ 371/* Note: sizeof(rcv_desc) should always be a mutliple of 2 */
379struct rcv_desc { 372struct rcv_desc {
380 u16 reference_handle; 373 __le16 reference_handle;
381 u16 reserved; 374 __le16 reserved;
382 u32 buffer_length; /* allocated buffer length (usually 2K) */ 375 __le32 buffer_length; /* allocated buffer length (usually 2K) */
383 u64 addr_buffer; 376 __le64 addr_buffer;
384}; 377};
385 378
386/* opcode field in status_desc */ 379/* opcode field in status_desc */
@@ -406,36 +399,36 @@ struct rcv_desc {
406 (((status_desc)->lro & 0x80) >> 7) 399 (((status_desc)->lro & 0x80) >> 7)
407 400
408#define netxen_get_sts_port(status_desc) \ 401#define netxen_get_sts_port(status_desc) \
409 ((status_desc)->status_desc_data & 0x0F) 402 (le64_to_cpu((status_desc)->status_desc_data) & 0x0F)
410#define netxen_get_sts_status(status_desc) \ 403#define netxen_get_sts_status(status_desc) \
411 (((status_desc)->status_desc_data >> 4) & 0x0F) 404 ((le64_to_cpu((status_desc)->status_desc_data) >> 4) & 0x0F)
412#define netxen_get_sts_type(status_desc) \ 405#define netxen_get_sts_type(status_desc) \
413 (((status_desc)->status_desc_data >> 8) & 0x0F) 406 ((le64_to_cpu((status_desc)->status_desc_data) >> 8) & 0x0F)
414#define netxen_get_sts_totallength(status_desc) \ 407#define netxen_get_sts_totallength(status_desc) \
415 (((status_desc)->status_desc_data >> 12) & 0xFFFF) 408 ((le64_to_cpu((status_desc)->status_desc_data) >> 12) & 0xFFFF)
416#define netxen_get_sts_refhandle(status_desc) \ 409#define netxen_get_sts_refhandle(status_desc) \
417 (((status_desc)->status_desc_data >> 28) & 0xFFFF) 410 ((le64_to_cpu((status_desc)->status_desc_data) >> 28) & 0xFFFF)
418#define netxen_get_sts_prot(status_desc) \ 411#define netxen_get_sts_prot(status_desc) \
419 (((status_desc)->status_desc_data >> 44) & 0x0F) 412 ((le64_to_cpu((status_desc)->status_desc_data) >> 44) & 0x0F)
420#define netxen_get_sts_owner(status_desc) \ 413#define netxen_get_sts_owner(status_desc) \
421 (((status_desc)->status_desc_data >> 56) & 0x03) 414 ((le64_to_cpu((status_desc)->status_desc_data) >> 56) & 0x03)
422#define netxen_get_sts_opcode(status_desc) \ 415#define netxen_get_sts_opcode(status_desc) \
423 (((status_desc)->status_desc_data >> 58) & 0x03F) 416 ((le64_to_cpu((status_desc)->status_desc_data) >> 58) & 0x03F)
424 417
425#define netxen_clear_sts_owner(status_desc) \ 418#define netxen_clear_sts_owner(status_desc) \
426 ((status_desc)->status_desc_data &= \ 419 ((status_desc)->status_desc_data &= \
427 ~(((unsigned long long)3) << 56 )) 420 ~cpu_to_le64(((unsigned long long)3) << 56 ))
428#define netxen_set_sts_owner(status_desc, val) \ 421#define netxen_set_sts_owner(status_desc, val) \
429 ((status_desc)->status_desc_data |= \ 422 ((status_desc)->status_desc_data |= \
430 (((unsigned long long)((val) & 0x3)) << 56 )) 423 cpu_to_le64(((unsigned long long)((val) & 0x3)) << 56 ))
431 424
432struct status_desc { 425struct status_desc {
433 /* Bit pattern: 0-3 port, 4-7 status, 8-11 type, 12-27 total_length 426 /* Bit pattern: 0-3 port, 4-7 status, 8-11 type, 12-27 total_length
434 28-43 reference_handle, 44-47 protocol, 48-52 unused 427 28-43 reference_handle, 44-47 protocol, 48-52 unused
435 53-55 desc_cnt, 56-57 owner, 58-63 opcode 428 53-55 desc_cnt, 56-57 owner, 58-63 opcode
436 */ 429 */
437 u64 status_desc_data; 430 __le64 status_desc_data;
438 u32 hash_value; 431 __le32 hash_value;
439 u8 hash_type; 432 u8 hash_type;
440 u8 msg_type; 433 u8 msg_type;
441 u8 unused; 434 u8 unused;
@@ -852,8 +845,6 @@ struct netxen_adapter {
852 spinlock_t tx_lock; 845 spinlock_t tx_lock;
853 spinlock_t lock; 846 spinlock_t lock;
854 struct work_struct watchdog_task; 847 struct work_struct watchdog_task;
855 struct work_struct tx_timeout_task;
856 struct net_device *netdev;
857 struct timer_list watchdog_timer; 848 struct timer_list watchdog_timer;
858 849
859 u32 curr_window; 850 u32 curr_window;
@@ -887,7 +878,6 @@ struct netxen_adapter {
887 struct netxen_recv_context recv_ctx[MAX_RCV_CTX]; 878 struct netxen_recv_context recv_ctx[MAX_RCV_CTX];
888 879
889 int is_up; 880 int is_up;
890 int number;
891 struct netxen_dummy_dma dummy_dma; 881 struct netxen_dummy_dma dummy_dma;
892 882
893 /* Context interface shared between card and host */ 883 /* Context interface shared between card and host */
@@ -950,6 +940,7 @@ struct netxen_port {
950 struct pci_dev *pdev; 940 struct pci_dev *pdev;
951 struct net_device_stats net_stats; 941 struct net_device_stats net_stats;
952 struct netxen_port_stats stats; 942 struct netxen_port_stats stats;
943 struct work_struct tx_timeout_task;
953}; 944};
954 945
955#define PCI_OFFSET_FIRST_RANGE(adapter, off) \ 946#define PCI_OFFSET_FIRST_RANGE(adapter, off) \
@@ -1008,9 +999,9 @@ void netxen_niu_gbe_set_mii_mode(struct netxen_adapter *adapter, int port,
1008void netxen_niu_gbe_set_gmii_mode(struct netxen_adapter *adapter, int port, 999void netxen_niu_gbe_set_gmii_mode(struct netxen_adapter *adapter, int port,
1009 long enable); 1000 long enable);
1010int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long phy, long reg, 1001int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long phy, long reg,
1011 __le32 * readval); 1002 __u32 * readval);
1012int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter, long phy, 1003int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter, long phy,
1013 long reg, __le32 val); 1004 long reg, __u32 val);
1014 1005
1015/* Functions available from netxen_nic_hw.c */ 1006/* Functions available from netxen_nic_hw.c */
1016int netxen_nic_set_mtu_xgb(struct netxen_port *port, int new_mtu); 1007int netxen_nic_set_mtu_xgb(struct netxen_port *port, int new_mtu);
@@ -1027,14 +1018,6 @@ int netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data,
1027 int len); 1018 int len);
1028int netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data, 1019int netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data,
1029 int len); 1020 int len);
1030int netxen_nic_hw_read_ioctl(struct netxen_adapter *adapter, u64 off,
1031 void *data, int len);
1032int netxen_nic_hw_write_ioctl(struct netxen_adapter *adapter, u64 off,
1033 void *data, int len);
1034int netxen_nic_pci_mem_write_ioctl(struct netxen_adapter *adapter,
1035 u64 off, void *data, int size);
1036int netxen_nic_pci_mem_read_ioctl(struct netxen_adapter *adapter,
1037 u64 off, void *data, int size);
1038void netxen_crb_writelit_adapter(struct netxen_adapter *adapter, 1021void netxen_crb_writelit_adapter(struct netxen_adapter *adapter,
1039 unsigned long off, int data); 1022 unsigned long off, int data);
1040 1023
@@ -1067,9 +1050,6 @@ void netxen_tso_check(struct netxen_adapter *adapter,
1067 struct cmd_desc_type0 *desc, struct sk_buff *skb); 1050 struct cmd_desc_type0 *desc, struct sk_buff *skb);
1068int netxen_nic_hw_resources(struct netxen_adapter *adapter); 1051int netxen_nic_hw_resources(struct netxen_adapter *adapter);
1069void netxen_nic_clear_stats(struct netxen_adapter *adapter); 1052void netxen_nic_clear_stats(struct netxen_adapter *adapter);
1070int
1071netxen_nic_do_ioctl(struct netxen_adapter *adapter, void *u_data,
1072 struct netxen_port *port);
1073int netxen_nic_rx_has_work(struct netxen_adapter *adapter); 1053int netxen_nic_rx_has_work(struct netxen_adapter *adapter);
1074int netxen_nic_tx_has_work(struct netxen_adapter *adapter); 1054int netxen_nic_tx_has_work(struct netxen_adapter *adapter);
1075void netxen_watchdog_task(struct work_struct *work); 1055void netxen_watchdog_task(struct work_struct *work);
diff --git a/drivers/net/netxen/netxen_nic_ethtool.c b/drivers/net/netxen/netxen_nic_ethtool.c
index 2ab4885cc9..c381d77a73 100644
--- a/drivers/net/netxen/netxen_nic_ethtool.c
+++ b/drivers/net/netxen/netxen_nic_ethtool.c
@@ -42,7 +42,6 @@
42#include "netxen_nic_hw.h" 42#include "netxen_nic_hw.h"
43#include "netxen_nic.h" 43#include "netxen_nic.h"
44#include "netxen_nic_phan_reg.h" 44#include "netxen_nic_phan_reg.h"
45#include "netxen_nic_ioctl.h"
46 45
47struct netxen_nic_stats { 46struct netxen_nic_stats {
48 char stat_string[ETH_GSTRING_LEN]; 47 char stat_string[ETH_GSTRING_LEN];
@@ -79,8 +78,7 @@ static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
79 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)}, 78 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
80}; 79};
81 80
82#define NETXEN_NIC_STATS_LEN \ 81#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
83 sizeof(netxen_nic_gstrings_stats) / sizeof(struct netxen_nic_stats)
84 82
85static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = { 83static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
86 "Register_Test_offline", "EEPROM_Test_offline", 84 "Register_Test_offline", "EEPROM_Test_offline",
@@ -220,7 +218,7 @@ netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
220{ 218{
221 struct netxen_port *port = netdev_priv(dev); 219 struct netxen_port *port = netdev_priv(dev);
222 struct netxen_adapter *adapter = port->adapter; 220 struct netxen_adapter *adapter = port->adapter;
223 __le32 status; 221 __u32 status;
224 222
225 /* read which mode */ 223 /* read which mode */
226 if (adapter->ahw.board_type == NETXEN_NIC_GBE) { 224 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
@@ -228,7 +226,7 @@ netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
228 if (adapter->phy_write 226 if (adapter->phy_write
229 && adapter->phy_write(adapter, port->portnum, 227 && adapter->phy_write(adapter, port->portnum,
230 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, 228 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
231 (__le32) ecmd->autoneg) != 0) 229 ecmd->autoneg) != 0)
232 return -EIO; 230 return -EIO;
233 else 231 else
234 port->link_autoneg = ecmd->autoneg; 232 port->link_autoneg = ecmd->autoneg;
@@ -281,7 +279,7 @@ static int netxen_nic_get_regs_len(struct net_device *dev)
281} 279}
282 280
283struct netxen_niu_regs { 281struct netxen_niu_regs {
284 __le32 reg[NETXEN_NIC_REGS_COUNT]; 282 __u32 reg[NETXEN_NIC_REGS_COUNT];
285}; 283};
286 284
287static struct netxen_niu_regs niu_registers[] = { 285static struct netxen_niu_regs niu_registers[] = {
@@ -374,7 +372,7 @@ netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
374{ 372{
375 struct netxen_port *port = netdev_priv(dev); 373 struct netxen_port *port = netdev_priv(dev);
376 struct netxen_adapter *adapter = port->adapter; 374 struct netxen_adapter *adapter = port->adapter;
377 __le32 mode, *regs_buff = p; 375 __u32 mode, *regs_buff = p;
378 void __iomem *addr; 376 void __iomem *addr;
379 int i, window; 377 int i, window;
380 378
@@ -417,7 +415,7 @@ static u32 netxen_nic_get_link(struct net_device *dev)
417{ 415{
418 struct netxen_port *port = netdev_priv(dev); 416 struct netxen_port *port = netdev_priv(dev);
419 struct netxen_adapter *adapter = port->adapter; 417 struct netxen_adapter *adapter = port->adapter;
420 __le32 status; 418 __u32 status;
421 419
422 /* read which mode */ 420 /* read which mode */
423 if (adapter->ahw.board_type == NETXEN_NIC_GBE) { 421 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
@@ -484,13 +482,13 @@ netxen_nic_get_pauseparam(struct net_device *dev,
484{ 482{
485 struct netxen_port *port = netdev_priv(dev); 483 struct netxen_port *port = netdev_priv(dev);
486 struct netxen_adapter *adapter = port->adapter; 484 struct netxen_adapter *adapter = port->adapter;
487 __le32 val; 485 __u32 val;
488 486
489 if (adapter->ahw.board_type == NETXEN_NIC_GBE) { 487 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
490 /* get flow control settings */ 488 /* get flow control settings */
491 netxen_nic_read_w0(adapter, 489 netxen_nic_read_w0(adapter,
492 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), 490 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
493 (u32 *) & val); 491 &val);
494 pause->rx_pause = netxen_gb_get_rx_flowctl(val); 492 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
495 pause->tx_pause = netxen_gb_get_tx_flowctl(val); 493 pause->tx_pause = netxen_gb_get_tx_flowctl(val);
496 /* get autoneg settings */ 494 /* get autoneg settings */
@@ -504,7 +502,7 @@ netxen_nic_set_pauseparam(struct net_device *dev,
504{ 502{
505 struct netxen_port *port = netdev_priv(dev); 503 struct netxen_port *port = netdev_priv(dev);
506 struct netxen_adapter *adapter = port->adapter; 504 struct netxen_adapter *adapter = port->adapter;
507 __le32 val; 505 __u32 val;
508 unsigned int autoneg; 506 unsigned int autoneg;
509 507
510 /* read mode */ 508 /* read mode */
@@ -524,13 +522,13 @@ netxen_nic_set_pauseparam(struct net_device *dev,
524 522
525 netxen_nic_write_w0(adapter, 523 netxen_nic_write_w0(adapter,
526 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), 524 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
527 *(u32 *) (&val)); 525 *&val);
528 /* set autoneg */ 526 /* set autoneg */
529 autoneg = pause->autoneg; 527 autoneg = pause->autoneg;
530 if (adapter->phy_write 528 if (adapter->phy_write
531 && adapter->phy_write(adapter, port->portnum, 529 && adapter->phy_write(adapter, port->portnum,
532 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, 530 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
533 (__le32) autoneg) != 0) 531 autoneg) != 0)
534 return -EIO; 532 return -EIO;
535 else { 533 else {
536 port->link_autoneg = pause->autoneg; 534 port->link_autoneg = pause->autoneg;
@@ -545,7 +543,7 @@ static int netxen_nic_reg_test(struct net_device *dev)
545 struct netxen_port *port = netdev_priv(dev); 543 struct netxen_port *port = netdev_priv(dev);
546 struct netxen_adapter *adapter = port->adapter; 544 struct netxen_adapter *adapter = port->adapter;
547 u32 data_read, data_written, save; 545 u32 data_read, data_written, save;
548 __le32 mode; 546 __u32 mode;
549 547
550 /* 548 /*
551 * first test the "Read Only" registers by writing which mode 549 * first test the "Read Only" registers by writing which mode
@@ -711,7 +709,6 @@ netxen_nic_get_ethtool_stats(struct net_device *dev,
711 (netxen_nic_gstrings_stats[index].sizeof_stat == 709 (netxen_nic_gstrings_stats[index].sizeof_stat ==
712 sizeof(u64)) ? *(u64 *) p : *(u32 *) p; 710 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
713 } 711 }
714
715} 712}
716 713
717struct ethtool_ops netxen_nic_ethtool_ops = { 714struct ethtool_ops netxen_nic_ethtool_ops = {
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index 9147b6048d..f263232f49 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -95,7 +95,7 @@ void netxen_nic_set_multi(struct net_device *netdev)
95 struct netxen_port *port = netdev_priv(netdev); 95 struct netxen_port *port = netdev_priv(netdev);
96 struct netxen_adapter *adapter = port->adapter; 96 struct netxen_adapter *adapter = port->adapter;
97 struct dev_mc_list *mc_ptr; 97 struct dev_mc_list *mc_ptr;
98 __le32 netxen_mac_addr_cntl_data = 0; 98 __u32 netxen_mac_addr_cntl_data = 0;
99 99
100 mc_ptr = netdev->mc_list; 100 mc_ptr = netdev->mc_list;
101 if (netdev->flags & IFF_PROMISC) { 101 if (netdev->flags & IFF_PROMISC) {
@@ -236,8 +236,9 @@ int netxen_nic_hw_resources(struct netxen_adapter *adapter)
236 } 236 }
237 memset(addr, 0, sizeof(struct netxen_ring_ctx)); 237 memset(addr, 0, sizeof(struct netxen_ring_ctx));
238 adapter->ctx_desc = (struct netxen_ring_ctx *)addr; 238 adapter->ctx_desc = (struct netxen_ring_ctx *)addr;
239 adapter->ctx_desc->cmd_consumer_offset = adapter->ctx_desc_phys_addr 239 adapter->ctx_desc->cmd_consumer_offset =
240 + sizeof(struct netxen_ring_ctx); 240 cpu_to_le64(adapter->ctx_desc_phys_addr +
241 sizeof(struct netxen_ring_ctx));
241 adapter->cmd_consumer = (uint32_t *) (((char *)addr) + 242 adapter->cmd_consumer = (uint32_t *) (((char *)addr) +
242 sizeof(struct netxen_ring_ctx)); 243 sizeof(struct netxen_ring_ctx));
243 244
@@ -253,11 +254,10 @@ int netxen_nic_hw_resources(struct netxen_adapter *adapter)
253 return -ENOMEM; 254 return -ENOMEM;
254 } 255 }
255 256
256 adapter->ctx_desc->cmd_ring_addr_lo = 257 adapter->ctx_desc->cmd_ring_addr =
257 hw->cmd_desc_phys_addr & 0xffffffffUL; 258 cpu_to_le64(hw->cmd_desc_phys_addr);
258 adapter->ctx_desc->cmd_ring_addr_hi = 259 adapter->ctx_desc->cmd_ring_size =
259 ((u64) hw->cmd_desc_phys_addr >> 32); 260 cpu_to_le32(adapter->max_tx_desc_count);
260 adapter->ctx_desc->cmd_ring_size = adapter->max_tx_desc_count;
261 261
262 hw->cmd_desc_head = (struct cmd_desc_type0 *)addr; 262 hw->cmd_desc_head = (struct cmd_desc_type0 *)addr;
263 263
@@ -278,12 +278,10 @@ int netxen_nic_hw_resources(struct netxen_adapter *adapter)
278 return err; 278 return err;
279 } 279 }
280 rcv_desc->desc_head = (struct rcv_desc *)addr; 280 rcv_desc->desc_head = (struct rcv_desc *)addr;
281 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_addr_lo = 281 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_addr =
282 rcv_desc->phys_addr & 0xffffffffUL; 282 cpu_to_le64(rcv_desc->phys_addr);
283 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_addr_hi =
284 ((u64) rcv_desc->phys_addr >> 32);
285 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_size = 283 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_size =
286 rcv_desc->max_rx_desc_count; 284 cpu_to_le32(rcv_desc->max_rx_desc_count);
287 } 285 }
288 286
289 addr = netxen_alloc(adapter->ahw.pdev, STATUS_DESC_RINGSIZE, 287 addr = netxen_alloc(adapter->ahw.pdev, STATUS_DESC_RINGSIZE,
@@ -297,11 +295,10 @@ int netxen_nic_hw_resources(struct netxen_adapter *adapter)
297 return err; 295 return err;
298 } 296 }
299 recv_ctx->rcv_status_desc_head = (struct status_desc *)addr; 297 recv_ctx->rcv_status_desc_head = (struct status_desc *)addr;
300 adapter->ctx_desc->sts_ring_addr_lo = 298 adapter->ctx_desc->sts_ring_addr =
301 recv_ctx->rcv_status_desc_phys_addr & 0xffffffffUL; 299 cpu_to_le64(recv_ctx->rcv_status_desc_phys_addr);
302 adapter->ctx_desc->sts_ring_addr_hi = 300 adapter->ctx_desc->sts_ring_size =
303 ((u64) recv_ctx->rcv_status_desc_phys_addr >> 32); 301 cpu_to_le32(adapter->max_rx_desc_count);
304 adapter->ctx_desc->sts_ring_size = adapter->max_rx_desc_count;
305 302
306 } 303 }
307 /* Window = 1 */ 304 /* Window = 1 */
@@ -376,7 +373,7 @@ void netxen_tso_check(struct netxen_adapter *adapter,
376 ((skb->nh.iph)->ihl * sizeof(u32)) + 373 ((skb->nh.iph)->ihl * sizeof(u32)) +
377 ((skb->h.th)->doff * sizeof(u32)); 374 ((skb->h.th)->doff * sizeof(u32));
378 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO); 375 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO);
379 } else if (skb->ip_summed == CHECKSUM_COMPLETE) { 376 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
380 if (skb->nh.iph->protocol == IPPROTO_TCP) { 377 if (skb->nh.iph->protocol == IPPROTO_TCP) {
381 netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT); 378 netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT);
382 } else if (skb->nh.iph->protocol == IPPROTO_UDP) { 379 } else if (skb->nh.iph->protocol == IPPROTO_UDP) {
@@ -387,10 +384,6 @@ void netxen_tso_check(struct netxen_adapter *adapter,
387 } 384 }
388 adapter->stats.xmitcsummed++; 385 adapter->stats.xmitcsummed++;
389 desc->tcp_hdr_offset = skb->h.raw - skb->data; 386 desc->tcp_hdr_offset = skb->h.raw - skb->data;
390 netxen_set_cmd_desc_totallength(desc,
391 cpu_to_le32
392 (netxen_get_cmd_desc_totallength
393 (desc)));
394 desc->ip_hdr_offset = skb->nh.raw - skb->data; 387 desc->ip_hdr_offset = skb->nh.raw - skb->data;
395} 388}
396 389
@@ -867,9 +860,9 @@ netxen_crb_writelit_adapter(struct netxen_adapter *adapter, unsigned long off,
867void netxen_nic_set_link_parameters(struct netxen_port *port) 860void netxen_nic_set_link_parameters(struct netxen_port *port)
868{ 861{
869 struct netxen_adapter *adapter = port->adapter; 862 struct netxen_adapter *adapter = port->adapter;
870 __le32 status; 863 __u32 status;
871 __le32 autoneg; 864 __u32 autoneg;
872 __le32 mode; 865 __u32 mode;
873 866
874 netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode); 867 netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
875 if (netxen_get_niu_enable_ge(mode)) { /* Gb 10/100/1000 Mbps mode */ 868 if (netxen_get_niu_enable_ge(mode)) { /* Gb 10/100/1000 Mbps mode */
@@ -984,7 +977,8 @@ void netxen_nic_flash_print(struct netxen_adapter *adapter)
984 _NETXEN_NIC_LINUX_MAJOR, fw_major); 977 _NETXEN_NIC_LINUX_MAJOR, fw_major);
985 adapter->driver_mismatch = 1; 978 adapter->driver_mismatch = 1;
986 } 979 }
987 if (fw_minor != _NETXEN_NIC_LINUX_MINOR) { 980 if (fw_minor != _NETXEN_NIC_LINUX_MINOR &&
981 fw_minor != (_NETXEN_NIC_LINUX_MINOR + 1)) {
988 printk(KERN_ERR "The mismatch in driver version and firmware " 982 printk(KERN_ERR "The mismatch in driver version and firmware "
989 "version minor number\n" 983 "version minor number\n"
990 "Driver version minor number = %d \t" 984 "Driver version minor number = %d \t"
@@ -997,297 +991,3 @@ void netxen_nic_flash_print(struct netxen_adapter *adapter)
997 fw_major, fw_minor); 991 fw_major, fw_minor);
998} 992}
999 993
1000int netxen_crb_read_val(struct netxen_adapter *adapter, unsigned long off)
1001{
1002 int data;
1003 netxen_nic_hw_read_wx(adapter, off, &data, 4);
1004 return data;
1005}
1006
1007int netxen_nic_hw_write_ioctl(struct netxen_adapter *adapter, u64 off,
1008 void *data, int len)
1009{
1010 void *addr;
1011 u64 offset = off;
1012 u8 *mem_ptr = NULL;
1013 unsigned long mem_base;
1014 unsigned long mem_page;
1015
1016 if (ADDR_IN_WINDOW1(off)) {
1017 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1018 if (!addr) {
1019 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1020 offset = NETXEN_CRB_NORMAL(off);
1021 mem_page = offset & PAGE_MASK;
1022 if (mem_page != ((offset + len - 1) & PAGE_MASK))
1023 mem_ptr =
1024 ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1025 else
1026 mem_ptr =
1027 ioremap(mem_base + mem_page, PAGE_SIZE);
1028 if (mem_ptr == 0UL) {
1029 return 1;
1030 }
1031 addr = mem_ptr;
1032 addr += offset & (PAGE_SIZE - 1);
1033 }
1034 } else {
1035 addr = pci_base_offset(adapter, off);
1036 if (!addr) {
1037 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1038 mem_page = off & PAGE_MASK;
1039 if (mem_page != ((off + len - 1) & PAGE_MASK))
1040 mem_ptr =
1041 ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1042 else
1043 mem_ptr =
1044 ioremap(mem_base + mem_page, PAGE_SIZE);
1045 if (mem_ptr == 0UL) {
1046 return 1;
1047 }
1048 addr = mem_ptr;
1049 addr += off & (PAGE_SIZE - 1);
1050 }
1051 netxen_nic_pci_change_crbwindow(adapter, 0);
1052 }
1053 switch (len) {
1054 case 1:
1055 writeb(*(u8 *) data, addr);
1056 break;
1057 case 2:
1058 writew(*(u16 *) data, addr);
1059 break;
1060 case 4:
1061 writel(*(u32 *) data, addr);
1062 break;
1063 case 8:
1064 writeq(*(u64 *) data, addr);
1065 break;
1066 default:
1067 DPRINTK(INFO,
1068 "writing data %lx to offset %llx, num words=%d\n",
1069 *(unsigned long *)data, off, (len >> 3));
1070
1071 netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
1072 (len >> 3));
1073 break;
1074 }
1075
1076 if (!ADDR_IN_WINDOW1(off))
1077 netxen_nic_pci_change_crbwindow(adapter, 1);
1078 if (mem_ptr)
1079 iounmap(mem_ptr);
1080 return 0;
1081}
1082
1083int netxen_nic_hw_read_ioctl(struct netxen_adapter *adapter, u64 off,
1084 void *data, int len)
1085{
1086 void *addr;
1087 u64 offset;
1088 u8 *mem_ptr = NULL;
1089 unsigned long mem_base;
1090 unsigned long mem_page;
1091
1092 if (ADDR_IN_WINDOW1(off)) {
1093 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1094 if (!addr) {
1095 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1096 offset = NETXEN_CRB_NORMAL(off);
1097 mem_page = offset & PAGE_MASK;
1098 if (mem_page != ((offset + len - 1) & PAGE_MASK))
1099 mem_ptr =
1100 ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1101 else
1102 mem_ptr =
1103 ioremap(mem_base + mem_page, PAGE_SIZE);
1104 if (mem_ptr == 0UL) {
1105 *(u8 *) data = 0;
1106 return 1;
1107 }
1108 addr = mem_ptr;
1109 addr += offset & (PAGE_SIZE - 1);
1110 }
1111 } else {
1112 addr = pci_base_offset(adapter, off);
1113 if (!addr) {
1114 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1115 mem_page = off & PAGE_MASK;
1116 if (mem_page != ((off + len - 1) & PAGE_MASK))
1117 mem_ptr =
1118 ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1119 else
1120 mem_ptr =
1121 ioremap(mem_base + mem_page, PAGE_SIZE);
1122 if (mem_ptr == 0UL)
1123 return 1;
1124 addr = mem_ptr;
1125 addr += off & (PAGE_SIZE - 1);
1126 }
1127 netxen_nic_pci_change_crbwindow(adapter, 0);
1128 }
1129 switch (len) {
1130 case 1:
1131 *(u8 *) data = readb(addr);
1132 break;
1133 case 2:
1134 *(u16 *) data = readw(addr);
1135 break;
1136 case 4:
1137 *(u32 *) data = readl(addr);
1138 break;
1139 case 8:
1140 *(u64 *) data = readq(addr);
1141 break;
1142 default:
1143 netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
1144 (len >> 3));
1145 break;
1146 }
1147 if (!ADDR_IN_WINDOW1(off))
1148 netxen_nic_pci_change_crbwindow(adapter, 1);
1149 if (mem_ptr)
1150 iounmap(mem_ptr);
1151 return 0;
1152}
1153
1154int netxen_nic_pci_mem_write_ioctl(struct netxen_adapter *adapter, u64 off,
1155 void *data, int size)
1156{
1157 void *addr;
1158 int ret = 0;
1159 u8 *mem_ptr = NULL;
1160 unsigned long mem_base;
1161 unsigned long mem_page;
1162
1163 if (data == NULL || off > (128 * 1024 * 1024)) {
1164 printk(KERN_ERR "%s: data: %p off:%llx\n",
1165 netxen_nic_driver_name, data, off);
1166 return 1;
1167 }
1168 off = netxen_nic_pci_set_window(adapter, off);
1169 /* Corner case : Malicious user tried to break the driver by reading
1170 last few bytes in ranges and tries to read further addresses.
1171 */
1172 if (!pci_base(adapter, off + size - 1) && pci_base(adapter, off)) {
1173 printk(KERN_ERR "%s: Invalid access to memory address range"
1174 " 0x%llx - 0x%llx\n", netxen_nic_driver_name, off,
1175 off + size);
1176 return 1;
1177 }
1178 addr = pci_base_offset(adapter, off);
1179 DPRINTK(INFO, "writing data %llx to offset %llx\n",
1180 *(unsigned long long *)data, off);
1181 if (!addr) {
1182 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1183 mem_page = off & PAGE_MASK;
1184 /* Map two pages whenever user tries to access addresses in two
1185 consecutive pages.
1186 */
1187 if (mem_page != ((off + size - 1) & PAGE_MASK))
1188 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1189 else
1190 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
1191 if (mem_ptr == 0UL) {
1192 return 1;
1193 }
1194 addr = mem_ptr;
1195 addr += off & (PAGE_SIZE - 1);
1196 }
1197 switch (size) {
1198 case 1:
1199 writeb(*(u8 *) data, addr);
1200 break;
1201 case 2:
1202 writew(*(u16 *) data, addr);
1203 break;
1204 case 4:
1205 writel(*(u32 *) data, addr);
1206 break;
1207 case 8:
1208 writeq(*(u64 *) data, addr);
1209 break;
1210 default:
1211 DPRINTK(INFO,
1212 "writing data %lx to offset %llx, num words=%d\n",
1213 *(unsigned long *)data, off, (size >> 3));
1214
1215 netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
1216 (size >> 3));
1217 break;
1218 }
1219
1220 if (mem_ptr)
1221 iounmap(mem_ptr);
1222 DPRINTK(INFO, "wrote %llx\n", *(unsigned long long *)data);
1223
1224 return ret;
1225}
1226
1227int netxen_nic_pci_mem_read_ioctl(struct netxen_adapter *adapter,
1228 u64 off, void *data, int size)
1229{
1230 void *addr;
1231 int ret = 0;
1232 u8 *mem_ptr = NULL;
1233 unsigned long mem_base;
1234 unsigned long mem_page;
1235
1236 if (data == NULL || off > (128 * 1024 * 1024)) {
1237 printk(KERN_ERR "%s: data: %p off:%llx\n",
1238 netxen_nic_driver_name, data, off);
1239 return 1;
1240 }
1241 off = netxen_nic_pci_set_window(adapter, off);
1242 /* Corner case : Malicious user tried to break the driver by reading
1243 last few bytes in ranges and tries to read further addresses.
1244 */
1245 if (!pci_base(adapter, off + size - 1) && pci_base(adapter, off)) {
1246 printk(KERN_ERR "%s: Invalid access to memory address range"
1247 " 0x%llx - 0x%llx\n", netxen_nic_driver_name, off,
1248 off + size);
1249 return 1;
1250 }
1251 addr = pci_base_offset(adapter, off);
1252 if (!addr) {
1253 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1254 mem_page = off & PAGE_MASK;
1255 /* Map two pages whenever user tries to access addresses in two
1256 consecutive pages.
1257 */
1258 if (mem_page != ((off + size - 1) & PAGE_MASK))
1259 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1260 else
1261 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
1262 if (mem_ptr == 0UL) {
1263 *(u8 *) data = 0;
1264 return 1;
1265 }
1266 addr = mem_ptr;
1267 addr += off & (PAGE_SIZE - 1);
1268 }
1269 switch (size) {
1270 case 1:
1271 *(u8 *) data = readb(addr);
1272 break;
1273 case 2:
1274 *(u16 *) data = readw(addr);
1275 break;
1276 case 4:
1277 *(u32 *) data = readl(addr);
1278 break;
1279 case 8:
1280 *(u64 *) data = readq(addr);
1281 break;
1282 default:
1283 netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
1284 (size >> 3));
1285 break;
1286 }
1287
1288 if (mem_ptr)
1289 iounmap(mem_ptr);
1290 DPRINTK(INFO, "read %llx\n", *(unsigned long long *)data);
1291
1292 return ret;
1293}
diff --git a/drivers/net/netxen/netxen_nic_hw.h b/drivers/net/netxen/netxen_nic_hw.h
index 0685633a9c..ab1112eb1b 100644
--- a/drivers/net/netxen/netxen_nic_hw.h
+++ b/drivers/net/netxen/netxen_nic_hw.h
@@ -124,28 +124,28 @@ typedef enum {
124 */ 124 */
125 125
126#define netxen_gb_enable_tx(config_word) \ 126#define netxen_gb_enable_tx(config_word) \
127 set_bit(0, (unsigned long*)(&config_word)) 127 ((config_word) |= 1 << 0)
128#define netxen_gb_enable_rx(config_word) \ 128#define netxen_gb_enable_rx(config_word) \
129 set_bit(2, (unsigned long*)(&config_word)) 129 ((config_word) |= 1 << 2)
130#define netxen_gb_tx_flowctl(config_word) \ 130#define netxen_gb_tx_flowctl(config_word) \
131 set_bit(4, (unsigned long*)(&config_word)) 131 ((config_word) |= 1 << 4)
132#define netxen_gb_rx_flowctl(config_word) \ 132#define netxen_gb_rx_flowctl(config_word) \
133 set_bit(5, (unsigned long*)(&config_word)) 133 ((config_word) |= 1 << 5)
134#define netxen_gb_tx_reset_pb(config_word) \ 134#define netxen_gb_tx_reset_pb(config_word) \
135 set_bit(16, (unsigned long*)(&config_word)) 135 ((config_word) |= 1 << 16)
136#define netxen_gb_rx_reset_pb(config_word) \ 136#define netxen_gb_rx_reset_pb(config_word) \
137 set_bit(17, (unsigned long*)(&config_word)) 137 ((config_word) |= 1 << 17)
138#define netxen_gb_tx_reset_mac(config_word) \ 138#define netxen_gb_tx_reset_mac(config_word) \
139 set_bit(18, (unsigned long*)(&config_word)) 139 ((config_word) |= 1 << 18)
140#define netxen_gb_rx_reset_mac(config_word) \ 140#define netxen_gb_rx_reset_mac(config_word) \
141 set_bit(19, (unsigned long*)(&config_word)) 141 ((config_word) |= 1 << 19)
142#define netxen_gb_soft_reset(config_word) \ 142#define netxen_gb_soft_reset(config_word) \
143 set_bit(31, (unsigned long*)(&config_word)) 143 ((config_word) |= 1 << 31)
144 144
145#define netxen_gb_unset_tx_flowctl(config_word) \ 145#define netxen_gb_unset_tx_flowctl(config_word) \
146 clear_bit(4, (unsigned long *)(&config_word)) 146 ((config_word) &= ~(1 << 4))
147#define netxen_gb_unset_rx_flowctl(config_word) \ 147#define netxen_gb_unset_rx_flowctl(config_word) \
148 clear_bit(5, (unsigned long*)(&config_word)) 148 ((config_word) &= ~(1 << 5))
149 149
150#define netxen_gb_get_tx_synced(config_word) \ 150#define netxen_gb_get_tx_synced(config_word) \
151 _netxen_crb_get_bit((config_word), 1) 151 _netxen_crb_get_bit((config_word), 1)
@@ -171,15 +171,15 @@ typedef enum {
171 */ 171 */
172 172
173#define netxen_gb_set_duplex(config_word) \ 173#define netxen_gb_set_duplex(config_word) \
174 set_bit(0, (unsigned long*)&config_word) 174 ((config_word) |= 1 << 0)
175#define netxen_gb_set_crc_enable(config_word) \ 175#define netxen_gb_set_crc_enable(config_word) \
176 set_bit(1, (unsigned long*)&config_word) 176 ((config_word) |= 1 << 1)
177#define netxen_gb_set_padshort(config_word) \ 177#define netxen_gb_set_padshort(config_word) \
178 set_bit(2, (unsigned long*)&config_word) 178 ((config_word) |= 1 << 2)
179#define netxen_gb_set_checklength(config_word) \ 179#define netxen_gb_set_checklength(config_word) \
180 set_bit(4, (unsigned long*)&config_word) 180 ((config_word) |= 1 << 4)
181#define netxen_gb_set_hugeframes(config_word) \ 181#define netxen_gb_set_hugeframes(config_word) \
182 set_bit(5, (unsigned long*)&config_word) 182 ((config_word) |= 1 << 5)
183#define netxen_gb_set_preamblelen(config_word, val) \ 183#define netxen_gb_set_preamblelen(config_word, val) \
184 ((config_word) |= ((val) << 12) & 0xF000) 184 ((config_word) |= ((val) << 12) & 0xF000)
185#define netxen_gb_set_intfmode(config_word, val) \ 185#define netxen_gb_set_intfmode(config_word, val) \
@@ -190,9 +190,9 @@ typedef enum {
190#define netxen_gb_set_mii_mgmt_clockselect(config_word, val) \ 190#define netxen_gb_set_mii_mgmt_clockselect(config_word, val) \
191 ((config_word) |= ((val) & 0x07)) 191 ((config_word) |= ((val) & 0x07))
192#define netxen_gb_mii_mgmt_reset(config_word) \ 192#define netxen_gb_mii_mgmt_reset(config_word) \
193 set_bit(31, (unsigned long*)&config_word) 193 ((config_word) |= 1 << 31)
194#define netxen_gb_mii_mgmt_unset(config_word) \ 194#define netxen_gb_mii_mgmt_unset(config_word) \
195 clear_bit(31, (unsigned long*)&config_word) 195 ((config_word) &= ~(1 << 31))
196 196
197/* 197/*
198 * NIU GB MII Mgmt Command Register (applies to GB0, GB1, GB2, GB3) 198 * NIU GB MII Mgmt Command Register (applies to GB0, GB1, GB2, GB3)
@@ -201,7 +201,7 @@ typedef enum {
201 */ 201 */
202 202
203#define netxen_gb_mii_mgmt_set_read_cycle(config_word) \ 203#define netxen_gb_mii_mgmt_set_read_cycle(config_word) \
204 set_bit(0, (unsigned long*)&config_word) 204 ((config_word) |= 1 << 0)
205#define netxen_gb_mii_mgmt_reg_addr(config_word, val) \ 205#define netxen_gb_mii_mgmt_reg_addr(config_word, val) \
206 ((config_word) |= ((val) & 0x1F)) 206 ((config_word) |= ((val) & 0x1F))
207#define netxen_gb_mii_mgmt_phy_addr(config_word, val) \ 207#define netxen_gb_mii_mgmt_phy_addr(config_word, val) \
@@ -274,9 +274,9 @@ typedef enum {
274#define netxen_set_phy_speed(config_word, val) \ 274#define netxen_set_phy_speed(config_word, val) \
275 ((config_word) |= ((val & 0x03) << 14)) 275 ((config_word) |= ((val & 0x03) << 14))
276#define netxen_set_phy_duplex(config_word) \ 276#define netxen_set_phy_duplex(config_word) \
277 set_bit(13, (unsigned long*)&config_word) 277 ((config_word) |= 1 << 13)
278#define netxen_clear_phy_duplex(config_word) \ 278#define netxen_clear_phy_duplex(config_word) \
279 clear_bit(13, (unsigned long*)&config_word) 279 ((config_word) &= ~(1 << 13))
280 280
281#define netxen_get_phy_jabber(config_word) \ 281#define netxen_get_phy_jabber(config_word) \
282 _netxen_crb_get_bit(config_word, 0) 282 _netxen_crb_get_bit(config_word, 0)
@@ -350,11 +350,11 @@ typedef enum {
350 _netxen_crb_get_bit(config_word, 15) 350 _netxen_crb_get_bit(config_word, 15)
351 351
352#define netxen_set_phy_int_link_status_changed(config_word) \ 352#define netxen_set_phy_int_link_status_changed(config_word) \
353 set_bit(10, (unsigned long*)&config_word) 353 ((config_word) |= 1 << 10)
354#define netxen_set_phy_int_autoneg_completed(config_word) \ 354#define netxen_set_phy_int_autoneg_completed(config_word) \
355 set_bit(11, (unsigned long*)&config_word) 355 ((config_word) |= 1 << 11)
356#define netxen_set_phy_int_speed_changed(config_word) \ 356#define netxen_set_phy_int_speed_changed(config_word) \
357 set_bit(14, (unsigned long*)&config_word) 357 ((config_word) |= 1 << 14)
358 358
359/* 359/*
360 * NIU Mode Register. 360 * NIU Mode Register.
@@ -382,22 +382,22 @@ typedef enum {
382 */ 382 */
383 383
384#define netxen_set_gb_drop_gb0(config_word) \ 384#define netxen_set_gb_drop_gb0(config_word) \
385 set_bit(0, (unsigned long*)&config_word) 385 ((config_word) |= 1 << 0)
386#define netxen_set_gb_drop_gb1(config_word) \ 386#define netxen_set_gb_drop_gb1(config_word) \
387 set_bit(1, (unsigned long*)&config_word) 387 ((config_word) |= 1 << 1)
388#define netxen_set_gb_drop_gb2(config_word) \ 388#define netxen_set_gb_drop_gb2(config_word) \
389 set_bit(2, (unsigned long*)&config_word) 389 ((config_word) |= 1 << 2)
390#define netxen_set_gb_drop_gb3(config_word) \ 390#define netxen_set_gb_drop_gb3(config_word) \
391 set_bit(3, (unsigned long*)&config_word) 391 ((config_word) |= 1 << 3)
392 392
393#define netxen_clear_gb_drop_gb0(config_word) \ 393#define netxen_clear_gb_drop_gb0(config_word) \
394 clear_bit(0, (unsigned long*)&config_word) 394 ((config_word) &= ~(1 << 0))
395#define netxen_clear_gb_drop_gb1(config_word) \ 395#define netxen_clear_gb_drop_gb1(config_word) \
396 clear_bit(1, (unsigned long*)&config_word) 396 ((config_word) &= ~(1 << 1))
397#define netxen_clear_gb_drop_gb2(config_word) \ 397#define netxen_clear_gb_drop_gb2(config_word) \
398 clear_bit(2, (unsigned long*)&config_word) 398 ((config_word) &= ~(1 << 2))
399#define netxen_clear_gb_drop_gb3(config_word) \ 399#define netxen_clear_gb_drop_gb3(config_word) \
400 clear_bit(3, (unsigned long*)&config_word) 400 ((config_word) &= ~(1 << 3))
401 401
402/* 402/*
403 * NIU XG MAC Config Register 403 * NIU XG MAC Config Register
@@ -413,7 +413,7 @@ typedef enum {
413 */ 413 */
414 414
415#define netxen_xg_soft_reset(config_word) \ 415#define netxen_xg_soft_reset(config_word) \
416 set_bit(4, (unsigned long*)&config_word) 416 ((config_word) |= 1 << 4)
417 417
418/* 418/*
419 * MAC Control Register 419 * MAC Control Register
@@ -433,19 +433,19 @@ typedef enum {
433#define netxen_nic_mcr_set_id_pool0(config, val) \ 433#define netxen_nic_mcr_set_id_pool0(config, val) \
434 ((config) |= ((val) &0x03)) 434 ((config) |= ((val) &0x03))
435#define netxen_nic_mcr_set_enable_xtnd0(config) \ 435#define netxen_nic_mcr_set_enable_xtnd0(config) \
436 (set_bit(3, (unsigned long *)&(config))) 436 ((config) |= 1 << 3)
437#define netxen_nic_mcr_set_id_pool1(config, val) \ 437#define netxen_nic_mcr_set_id_pool1(config, val) \
438 ((config) |= (((val) & 0x03) << 4)) 438 ((config) |= (((val) & 0x03) << 4))
439#define netxen_nic_mcr_set_enable_xtnd1(config) \ 439#define netxen_nic_mcr_set_enable_xtnd1(config) \
440 (set_bit(6, (unsigned long *)&(config))) 440 ((config) |= 1 << 6)
441#define netxen_nic_mcr_set_id_pool2(config, val) \ 441#define netxen_nic_mcr_set_id_pool2(config, val) \
442 ((config) |= (((val) & 0x03) << 8)) 442 ((config) |= (((val) & 0x03) << 8))
443#define netxen_nic_mcr_set_enable_xtnd2(config) \ 443#define netxen_nic_mcr_set_enable_xtnd2(config) \
444 (set_bit(10, (unsigned long *)&(config))) 444 ((config) |= 1 << 10)
445#define netxen_nic_mcr_set_id_pool3(config, val) \ 445#define netxen_nic_mcr_set_id_pool3(config, val) \
446 ((config) |= (((val) & 0x03) << 12)) 446 ((config) |= (((val) & 0x03) << 12))
447#define netxen_nic_mcr_set_enable_xtnd3(config) \ 447#define netxen_nic_mcr_set_enable_xtnd3(config) \
448 (set_bit(14, (unsigned long *)&(config))) 448 ((config) |= 1 << 14)
449#define netxen_nic_mcr_set_mode_select(config, val) \ 449#define netxen_nic_mcr_set_mode_select(config, val) \
450 ((config) |= (((val) & 0x03) << 24)) 450 ((config) |= (((val) & 0x03) << 24))
451#define netxen_nic_mcr_set_enable_pool(config, val) \ 451#define netxen_nic_mcr_set_enable_pool(config, val) \
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c
index 869725f0bb..973af96337 100644
--- a/drivers/net/netxen/netxen_nic_init.c
+++ b/drivers/net/netxen/netxen_nic_init.c
@@ -35,7 +35,6 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include "netxen_nic.h" 36#include "netxen_nic.h"
37#include "netxen_nic_hw.h" 37#include "netxen_nic_hw.h"
38#include "netxen_nic_ioctl.h"
39#include "netxen_nic_phan_reg.h" 38#include "netxen_nic_phan_reg.h"
40 39
41struct crb_addr_pair { 40struct crb_addr_pair {
@@ -691,8 +690,7 @@ int netxen_nic_rx_has_work(struct netxen_adapter *adapter)
691 desc_head = recv_ctx->rcv_status_desc_head; 690 desc_head = recv_ctx->rcv_status_desc_head;
692 desc = &desc_head[consumer]; 691 desc = &desc_head[consumer];
693 692
694 if (((le16_to_cpu(netxen_get_sts_owner(desc))) 693 if (netxen_get_sts_owner(desc) & STATUS_OWNER_HOST)
695 & STATUS_OWNER_HOST))
696 return 1; 694 return 1;
697 } 695 }
698 696
@@ -788,11 +786,11 @@ netxen_process_rcv(struct netxen_adapter *adapter, int ctxid,
788 struct netxen_port *port = adapter->port[netxen_get_sts_port(desc)]; 786 struct netxen_port *port = adapter->port[netxen_get_sts_port(desc)];
789 struct pci_dev *pdev = port->pdev; 787 struct pci_dev *pdev = port->pdev;
790 struct net_device *netdev = port->netdev; 788 struct net_device *netdev = port->netdev;
791 int index = le16_to_cpu(netxen_get_sts_refhandle(desc)); 789 int index = netxen_get_sts_refhandle(desc);
792 struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctxid]); 790 struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctxid]);
793 struct netxen_rx_buffer *buffer; 791 struct netxen_rx_buffer *buffer;
794 struct sk_buff *skb; 792 struct sk_buff *skb;
795 u32 length = le16_to_cpu(netxen_get_sts_totallength(desc)); 793 u32 length = netxen_get_sts_totallength(desc);
796 u32 desc_ctx; 794 u32 desc_ctx;
797 struct netxen_rcv_desc_ctx *rcv_desc; 795 struct netxen_rcv_desc_ctx *rcv_desc;
798 int ret; 796 int ret;
@@ -919,9 +917,7 @@ u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctxid, int max)
919 */ 917 */
920 while (count < max) { 918 while (count < max) {
921 desc = &desc_head[consumer]; 919 desc = &desc_head[consumer];
922 if (! 920 if (!(netxen_get_sts_owner(desc) & STATUS_OWNER_HOST)) {
923 (le16_to_cpu(netxen_get_sts_owner(desc)) &
924 STATUS_OWNER_HOST)) {
925 DPRINTK(ERR, "desc %p ownedby %x\n", desc, 921 DPRINTK(ERR, "desc %p ownedby %x\n", desc,
926 netxen_get_sts_owner(desc)); 922 netxen_get_sts_owner(desc));
927 break; 923 break;
@@ -1023,7 +1019,7 @@ int netxen_process_cmd_ring(unsigned long data)
1023 && netif_carrier_ok(port->netdev)) 1019 && netif_carrier_ok(port->netdev))
1024 && ((jiffies - port->netdev->trans_start) > 1020 && ((jiffies - port->netdev->trans_start) >
1025 port->netdev->watchdog_timeo)) { 1021 port->netdev->watchdog_timeo)) {
1026 SCHEDULE_WORK(&port->adapter->tx_timeout_task); 1022 SCHEDULE_WORK(&port->tx_timeout_task);
1027 } 1023 }
1028 1024
1029 last_consumer = get_next_index(last_consumer, 1025 last_consumer = get_next_index(last_consumer,
@@ -1138,13 +1134,13 @@ void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx, u32 ringid)
1138 */ 1134 */
1139 dma = pci_map_single(pdev, skb->data, rcv_desc->dma_size, 1135 dma = pci_map_single(pdev, skb->data, rcv_desc->dma_size,
1140 PCI_DMA_FROMDEVICE); 1136 PCI_DMA_FROMDEVICE);
1141 pdesc->addr_buffer = dma; 1137 pdesc->addr_buffer = cpu_to_le64(dma);
1142 buffer->skb = skb; 1138 buffer->skb = skb;
1143 buffer->state = NETXEN_BUFFER_BUSY; 1139 buffer->state = NETXEN_BUFFER_BUSY;
1144 buffer->dma = dma; 1140 buffer->dma = dma;
1145 /* make a rcv descriptor */ 1141 /* make a rcv descriptor */
1146 pdesc->reference_handle = buffer->ref_handle; 1142 pdesc->reference_handle = cpu_to_le16(buffer->ref_handle);
1147 pdesc->buffer_length = rcv_desc->dma_size; 1143 pdesc->buffer_length = cpu_to_le32(rcv_desc->dma_size);
1148 DPRINTK(INFO, "done writing descripter\n"); 1144 DPRINTK(INFO, "done writing descripter\n");
1149 producer = 1145 producer =
1150 get_next_index(producer, rcv_desc->max_rx_desc_count); 1146 get_next_index(producer, rcv_desc->max_rx_desc_count);
@@ -1232,8 +1228,8 @@ void netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, uint32_t ctx,
1232 PCI_DMA_FROMDEVICE); 1228 PCI_DMA_FROMDEVICE);
1233 1229
1234 /* make a rcv descriptor */ 1230 /* make a rcv descriptor */
1235 pdesc->reference_handle = le16_to_cpu(buffer->ref_handle); 1231 pdesc->reference_handle = cpu_to_le16(buffer->ref_handle);
1236 pdesc->buffer_length = le16_to_cpu(rcv_desc->dma_size); 1232 pdesc->buffer_length = cpu_to_le32(rcv_desc->dma_size);
1237 pdesc->addr_buffer = cpu_to_le64(buffer->dma); 1233 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
1238 DPRINTK(INFO, "done writing descripter\n"); 1234 DPRINTK(INFO, "done writing descripter\n");
1239 producer = 1235 producer =
@@ -1273,52 +1269,6 @@ int netxen_nic_tx_has_work(struct netxen_adapter *adapter)
1273 return 0; 1269 return 0;
1274} 1270}
1275 1271
1276int
1277netxen_nic_fill_statistics(struct netxen_adapter *adapter,
1278 struct netxen_port *port,
1279 struct netxen_statistics *netxen_stats)
1280{
1281 void __iomem *addr;
1282
1283 if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
1284 netxen_nic_pci_change_crbwindow(adapter, 0);
1285 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_TX_BYTE_CNT,
1286 &(netxen_stats->tx_bytes));
1287 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_TX_FRAME_CNT,
1288 &(netxen_stats->tx_packets));
1289 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_RX_BYTE_CNT,
1290 &(netxen_stats->rx_bytes));
1291 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_RX_FRAME_CNT,
1292 &(netxen_stats->rx_packets));
1293 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_AGGR_ERROR_CNT,
1294 &(netxen_stats->rx_errors));
1295 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_CRC_ERROR_CNT,
1296 &(netxen_stats->rx_crc_errors));
1297 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
1298 &(netxen_stats->
1299 rx_long_length_error));
1300 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
1301 &(netxen_stats->
1302 rx_short_length_error));
1303
1304 netxen_nic_pci_change_crbwindow(adapter, 1);
1305 } else {
1306 spin_lock_bh(&adapter->tx_lock);
1307 netxen_stats->tx_bytes = port->stats.txbytes;
1308 netxen_stats->tx_packets = port->stats.xmitedframes +
1309 port->stats.xmitfinished;
1310 netxen_stats->rx_bytes = port->stats.rxbytes;
1311 netxen_stats->rx_packets = port->stats.no_rcv;
1312 netxen_stats->rx_errors = port->stats.rcvdbadskb;
1313 netxen_stats->tx_errors = port->stats.nocmddescriptor;
1314 netxen_stats->rx_short_length_error = port->stats.uplcong;
1315 netxen_stats->rx_long_length_error = port->stats.uphcong;
1316 netxen_stats->rx_crc_errors = 0;
1317 netxen_stats->rx_mac_errors = 0;
1318 spin_unlock_bh(&adapter->tx_lock);
1319 }
1320 return 0;
1321}
1322 1272
1323void netxen_nic_clear_stats(struct netxen_adapter *adapter) 1273void netxen_nic_clear_stats(struct netxen_adapter *adapter)
1324{ 1274{
@@ -1332,193 +1282,3 @@ void netxen_nic_clear_stats(struct netxen_adapter *adapter)
1332 } 1282 }
1333} 1283}
1334 1284
1335int
1336netxen_nic_clear_statistics(struct netxen_adapter *adapter,
1337 struct netxen_port *port)
1338{
1339 int data = 0;
1340
1341 netxen_nic_pci_change_crbwindow(adapter, 0);
1342
1343 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_TX_BYTE_CNT, &data);
1344 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_TX_FRAME_CNT,
1345 &data);
1346 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_RX_BYTE_CNT, &data);
1347 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_RX_FRAME_CNT,
1348 &data);
1349 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_AGGR_ERROR_CNT,
1350 &data);
1351 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_CRC_ERROR_CNT,
1352 &data);
1353 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
1354 &data);
1355 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
1356 &data);
1357
1358 netxen_nic_pci_change_crbwindow(adapter, 1);
1359 netxen_nic_clear_stats(adapter);
1360 return 0;
1361}
1362
1363int
1364netxen_nic_do_ioctl(struct netxen_adapter *adapter, void *u_data,
1365 struct netxen_port *port)
1366{
1367 struct netxen_nic_ioctl_data data;
1368 struct netxen_nic_ioctl_data *up_data;
1369 int retval = 0;
1370 struct netxen_statistics netxen_stats;
1371
1372 up_data = (void *)u_data;
1373
1374 DPRINTK(INFO, "doing ioctl for %p\n", adapter);
1375 if (copy_from_user(&data, (void __user *)up_data, sizeof(data))) {
1376 /* evil user tried to crash the kernel */
1377 DPRINTK(ERR, "bad copy from userland: %d\n", (int)sizeof(data));
1378 retval = -EFAULT;
1379 goto error_out;
1380 }
1381
1382 /* Shouldn't access beyond legal limits of "char u[64];" member */
1383 if (!data.ptr && (data.size > sizeof(data.u))) {
1384 /* evil user tried to crash the kernel */
1385 DPRINTK(ERR, "bad size: %d\n", data.size);
1386 retval = -EFAULT;
1387 goto error_out;
1388 }
1389
1390 switch (data.cmd) {
1391 case netxen_nic_cmd_pci_read:
1392 if ((retval = netxen_nic_hw_read_ioctl(adapter, data.off,
1393 &(data.u), data.size)))
1394 goto error_out;
1395 if (copy_to_user
1396 ((void __user *)&(up_data->u), &(data.u), data.size)) {
1397 DPRINTK(ERR, "bad copy to userland: %d\n",
1398 (int)sizeof(data));
1399 retval = -EFAULT;
1400 goto error_out;
1401 }
1402 data.rv = 0;
1403 break;
1404
1405 case netxen_nic_cmd_pci_write:
1406 if ((retval = netxen_nic_hw_write_ioctl(adapter, data.off,
1407 &(data.u), data.size)))
1408 goto error_out;
1409 data.rv = 0;
1410 break;
1411
1412 case netxen_nic_cmd_pci_mem_read:
1413 if (netxen_nic_pci_mem_read_ioctl(adapter, data.off, &(data.u),
1414 data.size)) {
1415 DPRINTK(ERR, "Failed to read the data.\n");
1416 retval = -EFAULT;
1417 goto error_out;
1418 }
1419 if (copy_to_user
1420 ((void __user *)&(up_data->u), &(data.u), data.size)) {
1421 DPRINTK(ERR, "bad copy to userland: %d\n",
1422 (int)sizeof(data));
1423 retval = -EFAULT;
1424 goto error_out;
1425 }
1426 data.rv = 0;
1427 break;
1428
1429 case netxen_nic_cmd_pci_mem_write:
1430 if ((retval = netxen_nic_pci_mem_write_ioctl(adapter, data.off,
1431 &(data.u),
1432 data.size)))
1433 goto error_out;
1434 data.rv = 0;
1435 break;
1436
1437 case netxen_nic_cmd_pci_config_read:
1438 switch (data.size) {
1439 case 1:
1440 data.rv = pci_read_config_byte(adapter->ahw.pdev,
1441 data.off,
1442 (char *)&(data.u));
1443 break;
1444 case 2:
1445 data.rv = pci_read_config_word(adapter->ahw.pdev,
1446 data.off,
1447 (short *)&(data.u));
1448 break;
1449 case 4:
1450 data.rv = pci_read_config_dword(adapter->ahw.pdev,
1451 data.off,
1452 (u32 *) & (data.u));
1453 break;
1454 }
1455 if (copy_to_user
1456 ((void __user *)&(up_data->u), &(data.u), data.size)) {
1457 DPRINTK(ERR, "bad copy to userland: %d\n",
1458 (int)sizeof(data));
1459 retval = -EFAULT;
1460 goto error_out;
1461 }
1462 break;
1463
1464 case netxen_nic_cmd_pci_config_write:
1465 switch (data.size) {
1466 case 1:
1467 data.rv = pci_write_config_byte(adapter->ahw.pdev,
1468 data.off,
1469 *(char *)&(data.u));
1470 break;
1471 case 2:
1472 data.rv = pci_write_config_word(adapter->ahw.pdev,
1473 data.off,
1474 *(short *)&(data.u));
1475 break;
1476 case 4:
1477 data.rv = pci_write_config_dword(adapter->ahw.pdev,
1478 data.off,
1479 *(u32 *) & (data.u));
1480 break;
1481 }
1482 break;
1483
1484 case netxen_nic_cmd_get_stats:
1485 data.rv =
1486 netxen_nic_fill_statistics(adapter, port, &netxen_stats);
1487 if (copy_to_user
1488 ((void __user *)(up_data->ptr), (void *)&netxen_stats,
1489 sizeof(struct netxen_statistics))) {
1490 DPRINTK(ERR, "bad copy to userland: %d\n",
1491 (int)sizeof(netxen_stats));
1492 retval = -EFAULT;
1493 goto error_out;
1494 }
1495 up_data->rv = data.rv;
1496 break;
1497
1498 case netxen_nic_cmd_clear_stats:
1499 data.rv = netxen_nic_clear_statistics(adapter, port);
1500 up_data->rv = data.rv;
1501 break;
1502
1503 case netxen_nic_cmd_get_version:
1504 if (copy_to_user
1505 ((void __user *)&(up_data->u), NETXEN_NIC_LINUX_VERSIONID,
1506 sizeof(NETXEN_NIC_LINUX_VERSIONID))) {
1507 DPRINTK(ERR, "bad copy to userland: %d\n",
1508 (int)sizeof(data));
1509 retval = -EFAULT;
1510 goto error_out;
1511 }
1512 break;
1513
1514 default:
1515 DPRINTK(INFO, "bad command %d for %p\n", data.cmd, adapter);
1516 retval = -EOPNOTSUPP;
1517 goto error_out;
1518 }
1519 put_user(data.rv, (&(up_data->rv)));
1520 DPRINTK(INFO, "done ioctl for %p well.\n", adapter);
1521
1522 error_out:
1523 return retval;
1524}
diff --git a/drivers/net/netxen/netxen_nic_ioctl.h b/drivers/net/netxen/netxen_nic_ioctl.h
deleted file mode 100644
index 1221fa5275..0000000000
--- a/drivers/net/netxen/netxen_nic_ioctl.h
+++ /dev/null
@@ -1,77 +0,0 @@
1/*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 * MA 02111-1307, USA.
19 *
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
22 *
23 * Contact Information:
24 * info@netxen.com
25 * NetXen,
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
28 */
29
30#ifndef __NETXEN_NIC_IOCTL_H__
31#define __NETXEN_NIC_IOCTL_H__
32
33#include <linux/sockios.h>
34
35#define NETXEN_CMD_START SIOCDEVPRIVATE
36#define NETXEN_NIC_CMD (NETXEN_CMD_START + 1)
37#define NETXEN_NIC_NAME (NETXEN_CMD_START + 2)
38#define NETXEN_NIC_NAME_LEN 16
39#define NETXEN_NIC_NAME_RSP "NETXEN-UNM"
40
41typedef enum {
42 netxen_nic_cmd_none = 0,
43 netxen_nic_cmd_pci_read,
44 netxen_nic_cmd_pci_write,
45 netxen_nic_cmd_pci_mem_read,
46 netxen_nic_cmd_pci_mem_write,
47 netxen_nic_cmd_pci_config_read,
48 netxen_nic_cmd_pci_config_write,
49 netxen_nic_cmd_get_stats,
50 netxen_nic_cmd_clear_stats,
51 netxen_nic_cmd_get_version
52} netxen_nic_ioctl_cmd_t;
53
54struct netxen_nic_ioctl_data {
55 u32 cmd;
56 u32 unused1;
57 u64 off;
58 u32 size;
59 u32 rv;
60 char u[64];
61 void *ptr;
62};
63
64struct netxen_statistics {
65 u64 rx_packets;
66 u64 tx_packets;
67 u64 rx_bytes;
68 u64 rx_errors;
69 u64 tx_bytes;
70 u64 tx_errors;
71 u64 rx_crc_errors;
72 u64 rx_short_length_error;
73 u64 rx_long_length_error;
74 u64 rx_mac_errors;
75};
76
77#endif /* __NETXEN_NIC_IOCTL_H_ */
diff --git a/drivers/net/netxen/netxen_nic_isr.c b/drivers/net/netxen/netxen_nic_isr.c
index 1b45f50fa6..be366e4800 100644
--- a/drivers/net/netxen/netxen_nic_isr.c
+++ b/drivers/net/netxen/netxen_nic_isr.c
@@ -79,7 +79,7 @@ void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 portno,
79void netxen_handle_port_int(struct netxen_adapter *adapter, u32 portno, 79void netxen_handle_port_int(struct netxen_adapter *adapter, u32 portno,
80 u32 enable) 80 u32 enable)
81{ 81{
82 __le32 int_src; 82 __u32 int_src;
83 struct netxen_port *port; 83 struct netxen_port *port;
84 84
85 /* This should clear the interrupt source */ 85 /* This should clear the interrupt source */
@@ -110,7 +110,7 @@ void netxen_handle_port_int(struct netxen_adapter *adapter, u32 portno,
110 /* write it down later.. */ 110 /* write it down later.. */
111 if ((netxen_get_phy_int_speed_changed(int_src)) 111 if ((netxen_get_phy_int_speed_changed(int_src))
112 || (netxen_get_phy_int_link_status_changed(int_src))) { 112 || (netxen_get_phy_int_link_status_changed(int_src))) {
113 __le32 status; 113 __u32 status;
114 114
115 DPRINTK(INFO, "SPEED CHANGED OR LINK STATUS CHANGED \n"); 115 DPRINTK(INFO, "SPEED CHANGED OR LINK STATUS CHANGED \n");
116 116
@@ -157,7 +157,8 @@ void netxen_nic_isr_other(struct netxen_adapter *adapter)
157 for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++) { 157 for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++) {
158 linkup = val & 1; 158 linkup = val & 1;
159 if (linkup != (qg_linksup & 1)) { 159 if (linkup != (qg_linksup & 1)) {
160 printk(KERN_INFO "%s: PORT %d link %s\n", 160 printk(KERN_INFO "%s: %s PORT %d link %s\n",
161 adapter->port[portno]->netdev->name,
161 netxen_nic_driver_name, portno, 162 netxen_nic_driver_name, portno,
162 ((linkup == 0) ? "down" : "up")); 163 ((linkup == 0) ? "down" : "up"));
163 netxen_indicate_link_status(adapter, portno, linkup); 164 netxen_indicate_link_status(adapter, portno, linkup);
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 575b71b672..69c1b9d23a 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -38,7 +38,6 @@
38#include "netxen_nic.h" 38#include "netxen_nic.h"
39#define DEFINE_GLOBAL_RECV_CRB 39#define DEFINE_GLOBAL_RECV_CRB
40#include "netxen_nic_phan_reg.h" 40#include "netxen_nic_phan_reg.h"
41#include "netxen_nic_ioctl.h"
42 41
43#include <linux/dma-mapping.h> 42#include <linux/dma-mapping.h>
44#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
@@ -53,8 +52,6 @@ char netxen_nic_driver_name[] = "netxen-nic";
53static char netxen_nic_driver_string[] = "NetXen Network Driver version " 52static char netxen_nic_driver_string[] = "NetXen Network Driver version "
54 NETXEN_NIC_LINUX_VERSIONID; 53 NETXEN_NIC_LINUX_VERSIONID;
55 54
56struct netxen_adapter *g_adapter = NULL;
57
58#define NETXEN_NETDEV_WEIGHT 120 55#define NETXEN_NETDEV_WEIGHT 120
59#define NETXEN_ADAPTER_UP_MAGIC 777 56#define NETXEN_ADAPTER_UP_MAGIC 777
60#define NETXEN_NIC_PEG_TUNE 0 57#define NETXEN_NIC_PEG_TUNE 0
@@ -75,8 +72,6 @@ static void netxen_tx_timeout(struct net_device *netdev);
75static void netxen_tx_timeout_task(struct work_struct *work); 72static void netxen_tx_timeout_task(struct work_struct *work);
76static void netxen_watchdog(unsigned long); 73static void netxen_watchdog(unsigned long);
77static int netxen_handle_int(struct netxen_adapter *, struct net_device *); 74static int netxen_handle_int(struct netxen_adapter *, struct net_device *);
78static int netxen_nic_ioctl(struct net_device *netdev,
79 struct ifreq *ifr, int cmd);
80static int netxen_nic_poll(struct net_device *dev, int *budget); 75static int netxen_nic_poll(struct net_device *dev, int *budget);
81#ifdef CONFIG_NET_POLL_CONTROLLER 76#ifdef CONFIG_NET_POLL_CONTROLLER
82static void netxen_nic_poll_controller(struct net_device *netdev); 77static void netxen_nic_poll_controller(struct net_device *netdev);
@@ -90,6 +85,8 @@ static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
90 {PCI_DEVICE(0x4040, 0x0003)}, 85 {PCI_DEVICE(0x4040, 0x0003)},
91 {PCI_DEVICE(0x4040, 0x0004)}, 86 {PCI_DEVICE(0x4040, 0x0004)},
92 {PCI_DEVICE(0x4040, 0x0005)}, 87 {PCI_DEVICE(0x4040, 0x0005)},
88 {PCI_DEVICE(0x4040, 0x0024)},
89 {PCI_DEVICE(0x4040, 0x0025)},
93 {0,} 90 {0,}
94}; 91};
95 92
@@ -120,7 +117,7 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
120 void __iomem *mem_ptr1 = NULL; 117 void __iomem *mem_ptr1 = NULL;
121 void __iomem *mem_ptr2 = NULL; 118 void __iomem *mem_ptr2 = NULL;
122 119
123 u8 *db_ptr = NULL; 120 u8 __iomem *db_ptr = NULL;
124 unsigned long mem_base, mem_len, db_base, db_len; 121 unsigned long mem_base, mem_len, db_base, db_len;
125 int pci_using_dac, i, err; 122 int pci_using_dac, i, err;
126 int ring; 123 int ring;
@@ -129,7 +126,6 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
129 struct netxen_cmd_buffer *cmd_buf_arr = NULL; 126 struct netxen_cmd_buffer *cmd_buf_arr = NULL;
130 u64 mac_addr[FLASH_NUM_PORTS + 1]; 127 u64 mac_addr[FLASH_NUM_PORTS + 1];
131 int valid_mac = 0; 128 int valid_mac = 0;
132 static int netxen_cards_found = 0;
133 129
134 printk(KERN_INFO "%s \n", netxen_nic_driver_string); 130 printk(KERN_INFO "%s \n", netxen_nic_driver_string);
135 /* In current scheme, we use only PCI function 0 */ 131 /* In current scheme, we use only PCI function 0 */
@@ -195,7 +191,7 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
195 db_len); 191 db_len);
196 192
197 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES); 193 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
198 if (db_ptr == 0UL) { 194 if (!db_ptr) {
199 printk(KERN_ERR "%s: Failed to allocate doorbell map.", 195 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
200 netxen_nic_driver_name); 196 netxen_nic_driver_name);
201 err = -EIO; 197 err = -EIO;
@@ -220,9 +216,6 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
220 goto err_out_dbunmap; 216 goto err_out_dbunmap;
221 } 217 }
222 218
223 if (netxen_cards_found == 0) {
224 g_adapter = adapter;
225 }
226 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS; 219 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS;
227 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS; 220 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS;
228 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS; 221 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
@@ -383,7 +376,6 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
383 netdev->set_multicast_list = netxen_nic_set_multi; 376 netdev->set_multicast_list = netxen_nic_set_multi;
384 netdev->set_mac_address = netxen_nic_set_mac; 377 netdev->set_mac_address = netxen_nic_set_mac;
385 netdev->change_mtu = netxen_nic_change_mtu; 378 netdev->change_mtu = netxen_nic_change_mtu;
386 netdev->do_ioctl = netxen_nic_ioctl;
387 netdev->tx_timeout = netxen_tx_timeout; 379 netdev->tx_timeout = netxen_tx_timeout;
388 netdev->watchdog_timeo = HZ; 380 netdev->watchdog_timeo = HZ;
389 381
@@ -428,8 +420,7 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
428 netdev->dev_addr); 420 netdev->dev_addr);
429 } 421 }
430 } 422 }
431 adapter->netdev = netdev; 423 INIT_WORK(&port->tx_timeout_task, netxen_tx_timeout_task);
432 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
433 netif_carrier_off(netdev); 424 netif_carrier_off(netdev);
434 netif_stop_queue(netdev); 425 netif_stop_queue(netdev);
435 426
@@ -444,6 +435,11 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
444 adapter->port[i] = port; 435 adapter->port[i] = port;
445 } 436 }
446 437
438 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
439 netxen_pinit_from_rom(adapter, 0);
440 udelay(500);
441 netxen_load_firmware(adapter);
442 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
447 /* 443 /*
448 * delay a while to ensure that the Pegs are up & running. 444 * delay a while to ensure that the Pegs are up & running.
449 * Otherwise, we might see some flaky behaviour. 445 * Otherwise, we might see some flaky behaviour.
@@ -461,7 +457,6 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
461 break; 457 break;
462 } 458 }
463 459
464 adapter->number = netxen_cards_found;
465 adapter->driver_mismatch = 0; 460 adapter->driver_mismatch = 0;
466 461
467 return 0; 462 return 0;
@@ -531,6 +526,8 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev)
531 526
532 netxen_nic_stop_all_ports(adapter); 527 netxen_nic_stop_all_ports(adapter);
533 /* leave the hw in the same state as reboot */ 528 /* leave the hw in the same state as reboot */
529 netxen_pinit_from_rom(adapter, 0);
530 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
534 netxen_load_firmware(adapter); 531 netxen_load_firmware(adapter);
535 netxen_free_adapter_offload(adapter); 532 netxen_free_adapter_offload(adapter);
536 533
@@ -822,7 +819,7 @@ static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
822 pbuf = &adapter->cmd_buf_arr[producer]; 819 pbuf = &adapter->cmd_buf_arr[producer];
823 if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { 820 if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) {
824 pbuf->mss = skb_shinfo(skb)->gso_size; 821 pbuf->mss = skb_shinfo(skb)->gso_size;
825 hwdesc->mss = skb_shinfo(skb)->gso_size; 822 hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
826 } else { 823 } else {
827 pbuf->mss = 0; 824 pbuf->mss = 0;
828 hwdesc->mss = 0; 825 hwdesc->mss = 0;
@@ -885,7 +882,7 @@ static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
885 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); 882 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
886 break; 883 break;
887 case 3: 884 case 3:
888 hwdesc->buffer4_length = temp_len; 885 hwdesc->buffer4_length = cpu_to_le16(temp_len);
889 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); 886 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
890 break; 887 break;
891 } 888 }
@@ -956,11 +953,6 @@ static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
956static void netxen_watchdog(unsigned long v) 953static void netxen_watchdog(unsigned long v)
957{ 954{
958 struct netxen_adapter *adapter = (struct netxen_adapter *)v; 955 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
959 if (adapter != g_adapter) {
960 printk("%s: ***BUG*** adapter[%p] != g_adapter[%p]\n",
961 __FUNCTION__, adapter, g_adapter);
962 return;
963 }
964 956
965 SCHEDULE_WORK(&adapter->watchdog_task); 957 SCHEDULE_WORK(&adapter->watchdog_task);
966} 958}
@@ -969,23 +961,23 @@ static void netxen_tx_timeout(struct net_device *netdev)
969{ 961{
970 struct netxen_port *port = (struct netxen_port *)netdev_priv(netdev); 962 struct netxen_port *port = (struct netxen_port *)netdev_priv(netdev);
971 963
972 SCHEDULE_WORK(&port->adapter->tx_timeout_task); 964 SCHEDULE_WORK(&port->tx_timeout_task);
973} 965}
974 966
975static void netxen_tx_timeout_task(struct work_struct *work) 967static void netxen_tx_timeout_task(struct work_struct *work)
976{ 968{
977 struct netxen_adapter *adapter = 969 struct netxen_port *port =
978 container_of(work, struct netxen_adapter, tx_timeout_task); 970 container_of(work, struct netxen_port, tx_timeout_task);
979 struct net_device *netdev = adapter->netdev; 971 struct net_device *netdev = port->netdev;
980 unsigned long flags; 972 unsigned long flags;
981 973
982 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n", 974 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
983 netxen_nic_driver_name, netdev->name); 975 netxen_nic_driver_name, netdev->name);
984 976
985 spin_lock_irqsave(&adapter->lock, flags); 977 spin_lock_irqsave(&port->adapter->lock, flags);
986 netxen_nic_close(netdev); 978 netxen_nic_close(netdev);
987 netxen_nic_open(netdev); 979 netxen_nic_open(netdev);
988 spin_unlock_irqrestore(&adapter->lock, flags); 980 spin_unlock_irqrestore(&port->adapter->lock, flags);
989 netdev->trans_start = jiffies; 981 netdev->trans_start = jiffies;
990 netif_wake_queue(netdev); 982 netif_wake_queue(netdev);
991} 983}
@@ -1137,47 +1129,6 @@ static void netxen_nic_poll_controller(struct net_device *netdev)
1137 enable_irq(adapter->irq); 1129 enable_irq(adapter->irq);
1138} 1130}
1139#endif 1131#endif
1140/*
1141 * netxen_nic_ioctl () We provide the tcl/phanmon support through these
1142 * ioctls.
1143 */
1144static int
1145netxen_nic_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
1146{
1147 int err = 0;
1148 unsigned long nr_bytes = 0;
1149 struct netxen_port *port = netdev_priv(netdev);
1150 struct netxen_adapter *adapter = port->adapter;
1151 char dev_name[NETXEN_NIC_NAME_LEN];
1152
1153 DPRINTK(INFO, "doing ioctl for %s\n", netdev->name);
1154 switch (cmd) {
1155 case NETXEN_NIC_CMD:
1156 err = netxen_nic_do_ioctl(adapter, (void *)ifr->ifr_data, port);
1157 break;
1158
1159 case NETXEN_NIC_NAME:
1160 DPRINTK(INFO, "ioctl cmd for NetXen\n");
1161 if (ifr->ifr_data) {
1162 sprintf(dev_name, "%s-%d", NETXEN_NIC_NAME_RSP,
1163 port->portnum);
1164 nr_bytes =
1165 copy_to_user((char __user *)ifr->ifr_data, dev_name,
1166 NETXEN_NIC_NAME_LEN);
1167 if (nr_bytes)
1168 err = -EIO;
1169
1170 }
1171 break;
1172
1173 default:
1174 DPRINTK(INFO, "ioctl cmd %x not supported\n", cmd);
1175 err = -EOPNOTSUPP;
1176 break;
1177 }
1178
1179 return err;
1180}
1181 1132
1182static struct pci_driver netxen_driver = { 1133static struct pci_driver netxen_driver = {
1183 .name = netxen_nic_driver_name, 1134 .name = netxen_nic_driver_name,
@@ -1193,7 +1144,7 @@ static int __init netxen_init_module(void)
1193 if ((netxen_workq = create_singlethread_workqueue("netxen")) == 0) 1144 if ((netxen_workq = create_singlethread_workqueue("netxen")) == 0)
1194 return -ENOMEM; 1145 return -ENOMEM;
1195 1146
1196 return pci_module_init(&netxen_driver); 1147 return pci_register_driver(&netxen_driver);
1197} 1148}
1198 1149
1199module_init(netxen_init_module); 1150module_init(netxen_init_module);
diff --git a/drivers/net/netxen/netxen_nic_niu.c b/drivers/net/netxen/netxen_nic_niu.c
index 4987dc765d..40d7003a37 100644
--- a/drivers/net/netxen/netxen_nic_niu.c
+++ b/drivers/net/netxen/netxen_nic_niu.c
@@ -89,15 +89,15 @@ static inline int phy_unlock(struct netxen_adapter *adapter)
89 * 89 *
90 */ 90 */
91int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long phy, 91int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long phy,
92 long reg, __le32 * readval) 92 long reg, __u32 * readval)
93{ 93{
94 long timeout = 0; 94 long timeout = 0;
95 long result = 0; 95 long result = 0;
96 long restore = 0; 96 long restore = 0;
97 __le32 address; 97 __u32 address;
98 __le32 command; 98 __u32 command;
99 __le32 status; 99 __u32 status;
100 __le32 mac_cfg0; 100 __u32 mac_cfg0;
101 101
102 if (phy_lock(adapter) != 0) { 102 if (phy_lock(adapter) != 0) {
103 return -1; 103 return -1;
@@ -112,7 +112,7 @@ int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long phy,
112 &mac_cfg0, 4)) 112 &mac_cfg0, 4))
113 return -EIO; 113 return -EIO;
114 if (netxen_gb_get_soft_reset(mac_cfg0)) { 114 if (netxen_gb_get_soft_reset(mac_cfg0)) {
115 __le32 temp; 115 __u32 temp;
116 temp = 0; 116 temp = 0;
117 netxen_gb_tx_reset_pb(temp); 117 netxen_gb_tx_reset_pb(temp);
118 netxen_gb_rx_reset_pb(temp); 118 netxen_gb_rx_reset_pb(temp);
@@ -184,15 +184,15 @@ int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long phy,
184 * 184 *
185 */ 185 */
186int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter, 186int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter,
187 long phy, long reg, __le32 val) 187 long phy, long reg, __u32 val)
188{ 188{
189 long timeout = 0; 189 long timeout = 0;
190 long result = 0; 190 long result = 0;
191 long restore = 0; 191 long restore = 0;
192 __le32 address; 192 __u32 address;
193 __le32 command; 193 __u32 command;
194 __le32 status; 194 __u32 status;
195 __le32 mac_cfg0; 195 __u32 mac_cfg0;
196 196
197 /* 197 /*
198 * MII mgmt all goes through port 0 MAC interface, so it 198 * MII mgmt all goes through port 0 MAC interface, so it
@@ -203,7 +203,7 @@ int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter,
203 &mac_cfg0, 4)) 203 &mac_cfg0, 4))
204 return -EIO; 204 return -EIO;
205 if (netxen_gb_get_soft_reset(mac_cfg0)) { 205 if (netxen_gb_get_soft_reset(mac_cfg0)) {
206 __le32 temp; 206 __u32 temp;
207 temp = 0; 207 temp = 0;
208 netxen_gb_tx_reset_pb(temp); 208 netxen_gb_tx_reset_pb(temp);
209 netxen_gb_rx_reset_pb(temp); 209 netxen_gb_rx_reset_pb(temp);
@@ -269,7 +269,7 @@ int netxen_niu_gbe_enable_phy_interrupts(struct netxen_adapter *adapter,
269 int port) 269 int port)
270{ 270{
271 int result = 0; 271 int result = 0;
272 __le32 enable = 0; 272 __u32 enable = 0;
273 netxen_set_phy_int_link_status_changed(enable); 273 netxen_set_phy_int_link_status_changed(enable);
274 netxen_set_phy_int_autoneg_completed(enable); 274 netxen_set_phy_int_autoneg_completed(enable);
275 netxen_set_phy_int_speed_changed(enable); 275 netxen_set_phy_int_speed_changed(enable);
@@ -402,7 +402,7 @@ void netxen_niu_gbe_set_gmii_mode(struct netxen_adapter *adapter,
402int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port) 402int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port)
403{ 403{
404 int result = 0; 404 int result = 0;
405 __le32 status; 405 __u32 status;
406 if (adapter->disable_phy_interrupts) 406 if (adapter->disable_phy_interrupts)
407 adapter->disable_phy_interrupts(adapter, port); 407 adapter->disable_phy_interrupts(adapter, port);
408 mdelay(2); 408 mdelay(2);
@@ -410,7 +410,7 @@ int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port)
410 if (0 == 410 if (0 ==
411 netxen_niu_gbe_phy_read(adapter, port, 411 netxen_niu_gbe_phy_read(adapter, port,
412 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, 412 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
413 (__le32 *) & status)) { 413 &status)) {
414 if (netxen_get_phy_link(status)) { 414 if (netxen_get_phy_link(status)) {
415 if (netxen_get_phy_speed(status) == 2) { 415 if (netxen_get_phy_speed(status) == 2) {
416 netxen_niu_gbe_set_gmii_mode(adapter, port, 1); 416 netxen_niu_gbe_set_gmii_mode(adapter, port, 1);
@@ -489,7 +489,7 @@ int netxen_niu_gbe_handle_phy_interrupt(struct netxen_adapter *adapter,
489 int port, long enable) 489 int port, long enable)
490{ 490{
491 int result = 0; 491 int result = 0;
492 __le32 int_src; 492 __u32 int_src;
493 493
494 printk(KERN_INFO PFX "NETXEN: Handling PHY interrupt on port %d" 494 printk(KERN_INFO PFX "NETXEN: Handling PHY interrupt on port %d"
495 " (device enable = %d)\n", (int)port, (int)enable); 495 " (device enable = %d)\n", (int)port, (int)enable);
@@ -530,7 +530,7 @@ int netxen_niu_gbe_handle_phy_interrupt(struct netxen_adapter *adapter,
530 printk(KERN_INFO PFX "autoneg_error "); 530 printk(KERN_INFO PFX "autoneg_error ");
531 if ((netxen_get_phy_int_speed_changed(int_src)) 531 if ((netxen_get_phy_int_speed_changed(int_src))
532 || (netxen_get_phy_int_link_status_changed(int_src))) { 532 || (netxen_get_phy_int_link_status_changed(int_src))) {
533 __le32 status; 533 __u32 status;
534 534
535 printk(KERN_INFO PFX 535 printk(KERN_INFO PFX
536 "speed_changed or link status changed"); 536 "speed_changed or link status changed");
@@ -583,9 +583,9 @@ int netxen_niu_gbe_handle_phy_interrupt(struct netxen_adapter *adapter,
583int netxen_niu_macaddr_get(struct netxen_adapter *adapter, 583int netxen_niu_macaddr_get(struct netxen_adapter *adapter,
584 int phy, netxen_ethernet_macaddr_t * addr) 584 int phy, netxen_ethernet_macaddr_t * addr)
585{ 585{
586 u64 result = 0; 586 u32 stationhigh;
587 __le32 stationhigh; 587 u32 stationlow;
588 __le32 stationlow; 588 u8 val[8];
589 589
590 if (addr == NULL) 590 if (addr == NULL)
591 return -EINVAL; 591 return -EINVAL;
@@ -598,10 +598,10 @@ int netxen_niu_macaddr_get(struct netxen_adapter *adapter,
598 if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy), 598 if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy),
599 &stationlow, 4)) 599 &stationlow, 4))
600 return -EIO; 600 return -EIO;
601 ((__le32 *)val)[1] = cpu_to_le32(stationhigh);
602 ((__le32 *)val)[0] = cpu_to_le32(stationlow);
601 603
602 result = (u64) netxen_gb_get_stationaddress_low(stationlow); 604 memcpy(addr, val + 2, 6);
603 result |= (u64) stationhigh << 16;
604 memcpy(*addr, &result, sizeof(netxen_ethernet_macaddr_t));
605 605
606 return 0; 606 return 0;
607} 607}
@@ -613,24 +613,25 @@ int netxen_niu_macaddr_get(struct netxen_adapter *adapter,
613int netxen_niu_macaddr_set(struct netxen_port *port, 613int netxen_niu_macaddr_set(struct netxen_port *port,
614 netxen_ethernet_macaddr_t addr) 614 netxen_ethernet_macaddr_t addr)
615{ 615{
616 __le32 temp = 0; 616 u8 temp[4];
617 u32 val;
617 struct netxen_adapter *adapter = port->adapter; 618 struct netxen_adapter *adapter = port->adapter;
618 int phy = port->portnum; 619 int phy = port->portnum;
619 unsigned char mac_addr[6]; 620 unsigned char mac_addr[6];
620 int i; 621 int i;
621 622
622 for (i = 0; i < 10; i++) { 623 for (i = 0; i < 10; i++) {
623 memcpy(&temp, addr, 2); 624 temp[0] = temp[1] = 0;
624 temp <<= 16; 625 memcpy(temp + 2, addr, 2);
626 val = le32_to_cpu(*(__le32 *)temp);
625 if (netxen_nic_hw_write_wx 627 if (netxen_nic_hw_write_wx
626 (adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy), &temp, 4)) 628 (adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy), &val, 4))
627 return -EIO; 629 return -EIO;
628 630
629 temp = 0; 631 memcpy(temp, ((u8 *) addr) + 2, sizeof(__le32));
630 632 val = le32_to_cpu(*(__le32 *)temp);
631 memcpy(&temp, ((u8 *) addr) + 2, sizeof(__le32));
632 if (netxen_nic_hw_write_wx 633 if (netxen_nic_hw_write_wx
633 (adapter, NETXEN_NIU_GB_STATION_ADDR_0(phy), &temp, 4)) 634 (adapter, NETXEN_NIU_GB_STATION_ADDR_0(phy), &val, 4))
634 return -2; 635 return -2;
635 636
636 netxen_niu_macaddr_get(adapter, phy, 637 netxen_niu_macaddr_get(adapter, phy,
@@ -659,9 +660,9 @@ int netxen_niu_macaddr_set(struct netxen_port *port,
659int netxen_niu_enable_gbe_port(struct netxen_adapter *adapter, 660int netxen_niu_enable_gbe_port(struct netxen_adapter *adapter,
660 int port, netxen_niu_gbe_ifmode_t mode) 661 int port, netxen_niu_gbe_ifmode_t mode)
661{ 662{
662 __le32 mac_cfg0; 663 __u32 mac_cfg0;
663 __le32 mac_cfg1; 664 __u32 mac_cfg1;
664 __le32 mii_cfg; 665 __u32 mii_cfg;
665 666
666 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) 667 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
667 return -EINVAL; 668 return -EINVAL;
@@ -736,7 +737,7 @@ int netxen_niu_enable_gbe_port(struct netxen_adapter *adapter,
736/* Disable a GbE interface */ 737/* Disable a GbE interface */
737int netxen_niu_disable_gbe_port(struct netxen_adapter *adapter, int port) 738int netxen_niu_disable_gbe_port(struct netxen_adapter *adapter, int port)
738{ 739{
739 __le32 mac_cfg0; 740 __u32 mac_cfg0;
740 741
741 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) 742 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
742 return -EINVAL; 743 return -EINVAL;
@@ -752,7 +753,7 @@ int netxen_niu_disable_gbe_port(struct netxen_adapter *adapter, int port)
752/* Disable an XG interface */ 753/* Disable an XG interface */
753int netxen_niu_disable_xg_port(struct netxen_adapter *adapter, int port) 754int netxen_niu_disable_xg_port(struct netxen_adapter *adapter, int port)
754{ 755{
755 __le32 mac_cfg; 756 __u32 mac_cfg;
756 757
757 if (port != 0) 758 if (port != 0)
758 return -EINVAL; 759 return -EINVAL;
@@ -769,7 +770,7 @@ int netxen_niu_disable_xg_port(struct netxen_adapter *adapter, int port)
769int netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter, int port, 770int netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter, int port,
770 netxen_niu_prom_mode_t mode) 771 netxen_niu_prom_mode_t mode)
771{ 772{
772 __le32 reg; 773 __u32 reg;
773 774
774 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) 775 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
775 return -EINVAL; 776 return -EINVAL;
@@ -826,22 +827,21 @@ int netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter, int port,
826int netxen_niu_xg_macaddr_set(struct netxen_port *port, 827int netxen_niu_xg_macaddr_set(struct netxen_port *port,
827 netxen_ethernet_macaddr_t addr) 828 netxen_ethernet_macaddr_t addr)
828{ 829{
829 __le32 temp = 0; 830 u8 temp[4];
831 u32 val;
830 struct netxen_adapter *adapter = port->adapter; 832 struct netxen_adapter *adapter = port->adapter;
831 833
832 memcpy(&temp, addr, 2); 834 temp[0] = temp[1] = 0;
833 temp = cpu_to_le32(temp); 835 memcpy(temp + 2, addr, 2);
834 temp <<= 16; 836 val = le32_to_cpu(*(__le32 *)temp);
835 if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1, 837 if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1,
836 &temp, 4)) 838 &val, 4))
837 return -EIO; 839 return -EIO;
838 840
839 temp = 0;
840
841 memcpy(&temp, ((u8 *) addr) + 2, sizeof(__le32)); 841 memcpy(&temp, ((u8 *) addr) + 2, sizeof(__le32));
842 temp = cpu_to_le32(temp); 842 val = le32_to_cpu(*(__le32 *)temp);
843 if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_HI, 843 if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_HI,
844 &temp, 4)) 844 &val, 4))
845 return -EIO; 845 return -EIO;
846 846
847 return 0; 847 return 0;
@@ -854,9 +854,9 @@ int netxen_niu_xg_macaddr_set(struct netxen_port *port,
854int netxen_niu_xg_macaddr_get(struct netxen_adapter *adapter, int phy, 854int netxen_niu_xg_macaddr_get(struct netxen_adapter *adapter, int phy,
855 netxen_ethernet_macaddr_t * addr) 855 netxen_ethernet_macaddr_t * addr)
856{ 856{
857 __le32 stationhigh; 857 u32 stationhigh;
858 __le32 stationlow; 858 u32 stationlow;
859 u64 result; 859 u8 val[8];
860 860
861 if (addr == NULL) 861 if (addr == NULL)
862 return -EINVAL; 862 return -EINVAL;
@@ -869,10 +869,10 @@ int netxen_niu_xg_macaddr_get(struct netxen_adapter *adapter, int phy,
869 if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1, 869 if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1,
870 &stationlow, 4)) 870 &stationlow, 4))
871 return -EIO; 871 return -EIO;
872 ((__le32 *)val)[1] = cpu_to_le32(stationhigh);
873 ((__le32 *)val)[0] = cpu_to_le32(stationlow);
872 874
873 result = ((u64) stationlow) >> 16; 875 memcpy(addr, val + 2, 6);
874 result |= (u64) stationhigh << 16;
875 memcpy(*addr, &result, sizeof(netxen_ethernet_macaddr_t));
876 876
877 return 0; 877 return 0;
878} 878}
@@ -880,7 +880,7 @@ int netxen_niu_xg_macaddr_get(struct netxen_adapter *adapter, int phy,
880int netxen_niu_xg_set_promiscuous_mode(struct netxen_adapter *adapter, 880int netxen_niu_xg_set_promiscuous_mode(struct netxen_adapter *adapter,
881 int port, netxen_niu_prom_mode_t mode) 881 int port, netxen_niu_prom_mode_t mode)
882{ 882{
883 __le32 reg; 883 __u32 reg;
884 884
885 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS)) 885 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
886 return -EINVAL; 886 return -EINVAL;
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index 794cc61819..448bf4a780 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -281,7 +281,6 @@ static int tc574_probe(struct pcmcia_device *link)
281 link->conf.Attributes = CONF_ENABLE_IRQ; 281 link->conf.Attributes = CONF_ENABLE_IRQ;
282 link->conf.IntType = INT_MEMORY_AND_IO; 282 link->conf.IntType = INT_MEMORY_AND_IO;
283 link->conf.ConfigIndex = 1; 283 link->conf.ConfigIndex = 1;
284 link->conf.Present = PRESENT_OPTION;
285 284
286 /* The EL3-specific entries in the device structure. */ 285 /* The EL3-specific entries in the device structure. */
287 dev->hard_start_xmit = &el3_start_xmit; 286 dev->hard_start_xmit = &el3_start_xmit;
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 1e73ff7d5d..461e8274ef 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -195,7 +195,6 @@ static int tc589_probe(struct pcmcia_device *link)
195 link->conf.Attributes = CONF_ENABLE_IRQ; 195 link->conf.Attributes = CONF_ENABLE_IRQ;
196 link->conf.IntType = INT_MEMORY_AND_IO; 196 link->conf.IntType = INT_MEMORY_AND_IO;
197 link->conf.ConfigIndex = 1; 197 link->conf.ConfigIndex = 1;
198 link->conf.Present = PRESENT_OPTION;
199 198
200 /* The EL3-specific entries in the device structure. */ 199 /* The EL3-specific entries in the device structure. */
201 SET_MODULE_OWNER(dev); 200 SET_MODULE_OWNER(dev);
@@ -607,11 +606,14 @@ static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
607{ 606{
608 kio_addr_t ioaddr = dev->base_addr; 607 kio_addr_t ioaddr = dev->base_addr;
609 struct el3_private *priv = netdev_priv(dev); 608 struct el3_private *priv = netdev_priv(dev);
609 unsigned long flags;
610 610
611 DEBUG(3, "%s: el3_start_xmit(length = %ld) called, " 611 DEBUG(3, "%s: el3_start_xmit(length = %ld) called, "
612 "status %4.4x.\n", dev->name, (long)skb->len, 612 "status %4.4x.\n", dev->name, (long)skb->len,
613 inw(ioaddr + EL3_STATUS)); 613 inw(ioaddr + EL3_STATUS));
614 614
615 spin_lock_irqsave(&priv->lock, flags);
616
615 priv->stats.tx_bytes += skb->len; 617 priv->stats.tx_bytes += skb->len;
616 618
617 /* Put out the doubleword header... */ 619 /* Put out the doubleword header... */
@@ -629,6 +631,7 @@ static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
629 631
630 dev_kfree_skb(skb); 632 dev_kfree_skb(skb);
631 pop_tx_status(dev); 633 pop_tx_status(dev);
634 spin_unlock_irqrestore(&priv->lock, flags);
632 635
633 return 0; 636 return 0;
634} 637}
@@ -730,14 +733,13 @@ static void media_check(unsigned long arg)
730 733
731 if (!netif_device_present(dev)) goto reschedule; 734 if (!netif_device_present(dev)) goto reschedule;
732 735
733 EL3WINDOW(1);
734 /* Check for pending interrupt with expired latency timer: with 736 /* Check for pending interrupt with expired latency timer: with
735 this, we can limp along even if the interrupt is blocked */ 737 this, we can limp along even if the interrupt is blocked */
736 if ((inw(ioaddr + EL3_STATUS) & IntLatch) && 738 if ((inw(ioaddr + EL3_STATUS) & IntLatch) &&
737 (inb(ioaddr + EL3_TIMER) == 0xff)) { 739 (inb(ioaddr + EL3_TIMER) == 0xff)) {
738 if (!lp->fast_poll) 740 if (!lp->fast_poll)
739 printk(KERN_WARNING "%s: interrupt(s) dropped!\n", dev->name); 741 printk(KERN_WARNING "%s: interrupt(s) dropped!\n", dev->name);
740 el3_interrupt(dev->irq, lp); 742 el3_interrupt(dev->irq, dev);
741 lp->fast_poll = HZ; 743 lp->fast_poll = HZ;
742 } 744 }
743 if (lp->fast_poll) { 745 if (lp->fast_poll) {
diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c
index 91f65e91cd..0d1c7a41c9 100644
--- a/drivers/net/pcmcia/com20020_cs.c
+++ b/drivers/net/pcmcia/com20020_cs.c
@@ -173,7 +173,6 @@ static int com20020_probe(struct pcmcia_device *p_dev)
173 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID; 173 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
174 p_dev->conf.Attributes = CONF_ENABLE_IRQ; 174 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
175 p_dev->conf.IntType = INT_MEMORY_AND_IO; 175 p_dev->conf.IntType = INT_MEMORY_AND_IO;
176 p_dev->conf.Present = PRESENT_OPTION;
177 176
178 p_dev->irq.Instance = info->dev = dev; 177 p_dev->irq.Instance = info->dev = dev;
179 p_dev->priv = info; 178 p_dev->priv = info;
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index 2b1238e2db..d88e9b2e93 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -1617,6 +1617,7 @@ static struct pcmcia_device_id pcnet_ids[] = {
1617 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FastEther PCC-TX", 0x5261440f, 0x485e85d9), 1617 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FastEther PCC-TX", 0x5261440f, 0x485e85d9),
1618 PCMCIA_DEVICE_PROD_ID12("Corega,K.K.", "Ethernet LAN Card", 0x110d26d9, 0x9fd2f0a2), 1618 PCMCIA_DEVICE_PROD_ID12("Corega,K.K.", "Ethernet LAN Card", 0x110d26d9, 0x9fd2f0a2),
1619 PCMCIA_DEVICE_PROD_ID12("corega,K.K.", "Ethernet LAN Card", 0x9791a90e, 0x9fd2f0a2), 1619 PCMCIA_DEVICE_PROD_ID12("corega,K.K.", "Ethernet LAN Card", 0x9791a90e, 0x9fd2f0a2),
1620 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "(CG-LAPCCTXD)", 0x5261440f, 0x73ec0d88),
1620 PCMCIA_DEVICE_PROD_ID12("CouplerlessPCMCIA", "100BASE", 0xee5af0ad, 0x7c2add04), 1621 PCMCIA_DEVICE_PROD_ID12("CouplerlessPCMCIA", "100BASE", 0xee5af0ad, 0x7c2add04),
1621 PCMCIA_DEVICE_PROD_ID12("CyQ've", "ELA-010", 0x77008979, 0x9d8d445d), 1622 PCMCIA_DEVICE_PROD_ID12("CyQ've", "ELA-010", 0x77008979, 0x9d8d445d),
1622 PCMCIA_DEVICE_PROD_ID12("CyQ've", "ELA-110E 10/100M LAN Card", 0x77008979, 0xfd184814), 1623 PCMCIA_DEVICE_PROD_ID12("CyQ've", "ELA-110E 10/100M LAN Card", 0x77008979, 0xfd184814),
@@ -1667,6 +1668,7 @@ static struct pcmcia_device_id pcnet_ids[] = {
1667 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN100TX", 0x88fcdeda, 0x6d772737), 1668 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN100TX", 0x88fcdeda, 0x6d772737),
1668 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN100TE", 0x88fcdeda, 0x0e714bee), 1669 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN100TE", 0x88fcdeda, 0x0e714bee),
1669 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN20T", 0x88fcdeda, 0x81090922), 1670 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN20T", 0x88fcdeda, 0x81090922),
1671 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN10TE", 0x88fcdeda, 0xc1e2521c),
1670 PCMCIA_DEVICE_PROD_ID12("LONGSHINE", "PCMCIA Ethernet Card", 0xf866b0b0, 0x6f6652e0), 1672 PCMCIA_DEVICE_PROD_ID12("LONGSHINE", "PCMCIA Ethernet Card", 0xf866b0b0, 0x6f6652e0),
1671 PCMCIA_DEVICE_PROD_ID12("MACNICA", "ME1-JEIDA", 0x20841b68, 0xaf8a3578), 1673 PCMCIA_DEVICE_PROD_ID12("MACNICA", "ME1-JEIDA", 0x20841b68, 0xaf8a3578),
1672 PCMCIA_DEVICE_PROD_ID12("Macsense", "MPC-10", 0xd830297f, 0xd265c307), 1674 PCMCIA_DEVICE_PROD_ID12("Macsense", "MPC-10", 0xd830297f, 0xd265c307),
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index 8478dca3d8..5879e7c369 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -576,7 +576,6 @@ xirc2ps_probe(struct pcmcia_device *link)
576 link->conf.Attributes = CONF_ENABLE_IRQ; 576 link->conf.Attributes = CONF_ENABLE_IRQ;
577 link->conf.IntType = INT_MEMORY_AND_IO; 577 link->conf.IntType = INT_MEMORY_AND_IO;
578 link->conf.ConfigIndex = 1; 578 link->conf.ConfigIndex = 1;
579 link->conf.Present = PRESENT_OPTION;
580 link->irq.Handler = xirc2ps_interrupt; 579 link->irq.Handler = xirc2ps_interrupt;
581 link->irq.Instance = dev; 580 link->irq.Instance = dev;
582 581
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c
index 096d4a100b..86135397f4 100644
--- a/drivers/net/phy/fixed.c
+++ b/drivers/net/phy/fixed.c
@@ -349,7 +349,7 @@ static int __init fixed_init(void)
349 fixed_mdio_register_device(0, 100, 1); 349 fixed_mdio_register_device(0, 100, 1);
350#endif 350#endif
351 351
352#ifdef CONFIX_FIXED_MII_10_FDX 352#ifdef CONFIG_FIXED_MII_10_FDX
353 fixed_mdio_register_device(0, 10, 1); 353 fixed_mdio_register_device(0, 10, 1);
354#endif 354#endif
355 return 0; 355 return 0;
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index e175f3910b..9765fa6614 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -286,6 +286,7 @@ int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd)
286 286
287 return 0; 287 return 0;
288} 288}
289EXPORT_SYMBOL(phy_ethtool_sset);
289 290
290int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd) 291int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd)
291{ 292{
@@ -302,7 +303,7 @@ int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd)
302 303
303 return 0; 304 return 0;
304} 305}
305 306EXPORT_SYMBOL(phy_ethtool_gset);
306 307
307/* Note that this function is currently incompatible with the 308/* Note that this function is currently incompatible with the
308 * PHYCONTROL layer. It changes registers without regard to 309 * PHYCONTROL layer. It changes registers without regard to
diff --git a/drivers/net/qla3xxx.c b/drivers/net/qla3xxx.c
index d79d141a60..8844c20eac 100644
--- a/drivers/net/qla3xxx.c
+++ b/drivers/net/qla3xxx.c
@@ -208,6 +208,15 @@ static void ql_write_common_reg(struct ql3_adapter *qdev,
208 return; 208 return;
209} 209}
210 210
211static void ql_write_nvram_reg(struct ql3_adapter *qdev,
212 u32 __iomem *reg, u32 value)
213{
214 writel(value, reg);
215 readl(reg);
216 udelay(1);
217 return;
218}
219
211static void ql_write_page0_reg(struct ql3_adapter *qdev, 220static void ql_write_page0_reg(struct ql3_adapter *qdev,
212 u32 __iomem *reg, u32 value) 221 u32 __iomem *reg, u32 value)
213{ 222{
@@ -336,9 +345,9 @@ static void fm93c56a_select(struct ql3_adapter *qdev)
336 qdev->mem_map_registers; 345 qdev->mem_map_registers;
337 346
338 qdev->eeprom_cmd_data = AUBURN_EEPROM_CS_1; 347 qdev->eeprom_cmd_data = AUBURN_EEPROM_CS_1;
339 ql_write_common_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg, 348 ql_write_nvram_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg,
340 ISP_NVRAM_MASK | qdev->eeprom_cmd_data); 349 ISP_NVRAM_MASK | qdev->eeprom_cmd_data);
341 ql_write_common_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg, 350 ql_write_nvram_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg,
342 ((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data)); 351 ((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
343} 352}
344 353
@@ -355,14 +364,14 @@ static void fm93c56a_cmd(struct ql3_adapter *qdev, u32 cmd, u32 eepromAddr)
355 qdev->mem_map_registers; 364 qdev->mem_map_registers;
356 365
357 /* Clock in a zero, then do the start bit */ 366 /* Clock in a zero, then do the start bit */
358 ql_write_common_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg, 367 ql_write_nvram_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg,
359 ISP_NVRAM_MASK | qdev->eeprom_cmd_data | 368 ISP_NVRAM_MASK | qdev->eeprom_cmd_data |
360 AUBURN_EEPROM_DO_1); 369 AUBURN_EEPROM_DO_1);
361 ql_write_common_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg, 370 ql_write_nvram_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg,
362 ISP_NVRAM_MASK | qdev-> 371 ISP_NVRAM_MASK | qdev->
363 eeprom_cmd_data | AUBURN_EEPROM_DO_1 | 372 eeprom_cmd_data | AUBURN_EEPROM_DO_1 |
364 AUBURN_EEPROM_CLK_RISE); 373 AUBURN_EEPROM_CLK_RISE);
365 ql_write_common_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg, 374 ql_write_nvram_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg,
366 ISP_NVRAM_MASK | qdev-> 375 ISP_NVRAM_MASK | qdev->
367 eeprom_cmd_data | AUBURN_EEPROM_DO_1 | 376 eeprom_cmd_data | AUBURN_EEPROM_DO_1 |
368 AUBURN_EEPROM_CLK_FALL); 377 AUBURN_EEPROM_CLK_FALL);
@@ -378,20 +387,20 @@ static void fm93c56a_cmd(struct ql3_adapter *qdev, u32 cmd, u32 eepromAddr)
378 * If the bit changed, then change the DO state to 387 * If the bit changed, then change the DO state to
379 * match 388 * match
380 */ 389 */
381 ql_write_common_reg(qdev, 390 ql_write_nvram_reg(qdev,
382 &port_regs->CommonRegs. 391 &port_regs->CommonRegs.
383 serialPortInterfaceReg, 392 serialPortInterfaceReg,
384 ISP_NVRAM_MASK | qdev-> 393 ISP_NVRAM_MASK | qdev->
385 eeprom_cmd_data | dataBit); 394 eeprom_cmd_data | dataBit);
386 previousBit = dataBit; 395 previousBit = dataBit;
387 } 396 }
388 ql_write_common_reg(qdev, 397 ql_write_nvram_reg(qdev,
389 &port_regs->CommonRegs. 398 &port_regs->CommonRegs.
390 serialPortInterfaceReg, 399 serialPortInterfaceReg,
391 ISP_NVRAM_MASK | qdev-> 400 ISP_NVRAM_MASK | qdev->
392 eeprom_cmd_data | dataBit | 401 eeprom_cmd_data | dataBit |
393 AUBURN_EEPROM_CLK_RISE); 402 AUBURN_EEPROM_CLK_RISE);
394 ql_write_common_reg(qdev, 403 ql_write_nvram_reg(qdev,
395 &port_regs->CommonRegs. 404 &port_regs->CommonRegs.
396 serialPortInterfaceReg, 405 serialPortInterfaceReg,
397 ISP_NVRAM_MASK | qdev-> 406 ISP_NVRAM_MASK | qdev->
@@ -412,20 +421,20 @@ static void fm93c56a_cmd(struct ql3_adapter *qdev, u32 cmd, u32 eepromAddr)
412 * If the bit changed, then change the DO state to 421 * If the bit changed, then change the DO state to
413 * match 422 * match
414 */ 423 */
415 ql_write_common_reg(qdev, 424 ql_write_nvram_reg(qdev,
416 &port_regs->CommonRegs. 425 &port_regs->CommonRegs.
417 serialPortInterfaceReg, 426 serialPortInterfaceReg,
418 ISP_NVRAM_MASK | qdev-> 427 ISP_NVRAM_MASK | qdev->
419 eeprom_cmd_data | dataBit); 428 eeprom_cmd_data | dataBit);
420 previousBit = dataBit; 429 previousBit = dataBit;
421 } 430 }
422 ql_write_common_reg(qdev, 431 ql_write_nvram_reg(qdev,
423 &port_regs->CommonRegs. 432 &port_regs->CommonRegs.
424 serialPortInterfaceReg, 433 serialPortInterfaceReg,
425 ISP_NVRAM_MASK | qdev-> 434 ISP_NVRAM_MASK | qdev->
426 eeprom_cmd_data | dataBit | 435 eeprom_cmd_data | dataBit |
427 AUBURN_EEPROM_CLK_RISE); 436 AUBURN_EEPROM_CLK_RISE);
428 ql_write_common_reg(qdev, 437 ql_write_nvram_reg(qdev,
429 &port_regs->CommonRegs. 438 &port_regs->CommonRegs.
430 serialPortInterfaceReg, 439 serialPortInterfaceReg,
431 ISP_NVRAM_MASK | qdev-> 440 ISP_NVRAM_MASK | qdev->
@@ -443,7 +452,7 @@ static void fm93c56a_deselect(struct ql3_adapter *qdev)
443 struct ql3xxx_port_registers __iomem *port_regs = 452 struct ql3xxx_port_registers __iomem *port_regs =
444 qdev->mem_map_registers; 453 qdev->mem_map_registers;
445 qdev->eeprom_cmd_data = AUBURN_EEPROM_CS_0; 454 qdev->eeprom_cmd_data = AUBURN_EEPROM_CS_0;
446 ql_write_common_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg, 455 ql_write_nvram_reg(qdev, &port_regs->CommonRegs.serialPortInterfaceReg,
447 ISP_NVRAM_MASK | qdev->eeprom_cmd_data); 456 ISP_NVRAM_MASK | qdev->eeprom_cmd_data);
448} 457}
449 458
@@ -461,12 +470,12 @@ static void fm93c56a_datain(struct ql3_adapter *qdev, unsigned short *value)
461 /* Read the data bits */ 470 /* Read the data bits */
462 /* The first bit is a dummy. Clock right over it. */ 471 /* The first bit is a dummy. Clock right over it. */
463 for (i = 0; i < dataBits; i++) { 472 for (i = 0; i < dataBits; i++) {
464 ql_write_common_reg(qdev, 473 ql_write_nvram_reg(qdev,
465 &port_regs->CommonRegs. 474 &port_regs->CommonRegs.
466 serialPortInterfaceReg, 475 serialPortInterfaceReg,
467 ISP_NVRAM_MASK | qdev->eeprom_cmd_data | 476 ISP_NVRAM_MASK | qdev->eeprom_cmd_data |
468 AUBURN_EEPROM_CLK_RISE); 477 AUBURN_EEPROM_CLK_RISE);
469 ql_write_common_reg(qdev, 478 ql_write_nvram_reg(qdev,
470 &port_regs->CommonRegs. 479 &port_regs->CommonRegs.
471 serialPortInterfaceReg, 480 serialPortInterfaceReg,
472 ISP_NVRAM_MASK | qdev->eeprom_cmd_data | 481 ISP_NVRAM_MASK | qdev->eeprom_cmd_data |
@@ -3370,7 +3379,6 @@ static int __devinit ql3xxx_probe(struct pci_dev *pdev,
3370 SET_MODULE_OWNER(ndev); 3379 SET_MODULE_OWNER(ndev);
3371 SET_NETDEV_DEV(ndev, &pdev->dev); 3380 SET_NETDEV_DEV(ndev, &pdev->dev);
3372 3381
3373 ndev->features = NETIF_F_LLTX;
3374 if (pci_using_dac) 3382 if (pci_using_dac)
3375 ndev->features |= NETIF_F_HIGHDMA; 3383 ndev->features |= NETIF_F_HIGHDMA;
3376 3384
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index f83b41d4cb..577babd4c9 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -225,7 +225,6 @@ MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl);
225 225
226static int rx_copybreak = 200; 226static int rx_copybreak = 200;
227static int use_dac; 227static int use_dac;
228static int ignore_parity_err;
229static struct { 228static struct {
230 u32 msg_enable; 229 u32 msg_enable;
231} debug = { -1 }; 230} debug = { -1 };
@@ -471,8 +470,6 @@ module_param(use_dac, int, 0);
471MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot."); 470MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot.");
472module_param_named(debug, debug.msg_enable, int, 0); 471module_param_named(debug, debug.msg_enable, int, 0);
473MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); 472MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)");
474module_param_named(ignore_parity_err, ignore_parity_err, bool, 0);
475MODULE_PARM_DESC(ignore_parity_err, "Ignore PCI parity error as target. Default: false");
476MODULE_LICENSE("GPL"); 473MODULE_LICENSE("GPL");
477MODULE_VERSION(RTL8169_VERSION); 474MODULE_VERSION(RTL8169_VERSION);
478 475
@@ -1885,7 +1882,6 @@ static void rtl8169_hw_start(struct net_device *dev)
1885 (tp->mac_version == RTL_GIGA_MAC_VER_02) || 1882 (tp->mac_version == RTL_GIGA_MAC_VER_02) ||
1886 (tp->mac_version == RTL_GIGA_MAC_VER_03) || 1883 (tp->mac_version == RTL_GIGA_MAC_VER_03) ||
1887 (tp->mac_version == RTL_GIGA_MAC_VER_04)) 1884 (tp->mac_version == RTL_GIGA_MAC_VER_04))
1888 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
1889 rtl8169_set_rx_tx_config_registers(tp); 1885 rtl8169_set_rx_tx_config_registers(tp);
1890 1886
1891 cmd = RTL_R16(CPlusCmd); 1887 cmd = RTL_R16(CPlusCmd);
@@ -2388,7 +2384,7 @@ static void rtl8169_pcierr_interrupt(struct net_device *dev)
2388 * 2384 *
2389 * Feel free to adjust to your needs. 2385 * Feel free to adjust to your needs.
2390 */ 2386 */
2391 if (ignore_parity_err) 2387 if (pdev->broken_parity_status)
2392 pci_cmd &= ~PCI_COMMAND_PARITY; 2388 pci_cmd &= ~PCI_COMMAND_PARITY;
2393 else 2389 else
2394 pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; 2390 pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY;
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 250cdbeefd..1dd66b8ea0 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -556,10 +556,9 @@ static int init_shared_mem(struct s2io_nic *nic)
556 } 556 }
557 } 557 }
558 558
559 nic->ufo_in_band_v = kmalloc((sizeof(u64) * size), GFP_KERNEL); 559 nic->ufo_in_band_v = kcalloc(size, sizeof(u64), GFP_KERNEL);
560 if (!nic->ufo_in_band_v) 560 if (!nic->ufo_in_band_v)
561 return -ENOMEM; 561 return -ENOMEM;
562 memset(nic->ufo_in_band_v, 0, size);
563 562
564 /* Allocation and initialization of RXDs in Rings */ 563 /* Allocation and initialization of RXDs in Rings */
565 size = 0; 564 size = 0;
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index b70ed79d41..45d91b1591 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -1562,7 +1562,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
1562 for (i = 0; i < MAC_ADDR_LEN / 2; i++) { 1562 for (i = 0; i < MAC_ADDR_LEN / 2; i++) {
1563 __le16 w = sis190_read_eeprom(ioaddr, EEPROMMACAddr + i); 1563 __le16 w = sis190_read_eeprom(ioaddr, EEPROMMACAddr + i);
1564 1564
1565 ((u16 *)dev->dev_addr)[0] = le16_to_cpu(w); 1565 ((u16 *)dev->dev_addr)[i] = le16_to_cpu(w);
1566 } 1566 }
1567 1567
1568 sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr, EEPROMInfo)); 1568 sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr, EEPROMInfo));
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 8a39376f87..45283f3f95 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -60,7 +60,7 @@
60#define LINK_HZ (HZ/2) 60#define LINK_HZ (HZ/2)
61 61
62MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver"); 62MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver");
63MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); 63MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
64MODULE_LICENSE("GPL"); 64MODULE_LICENSE("GPL");
65MODULE_VERSION(DRV_VERSION); 65MODULE_VERSION(DRV_VERSION);
66 66
@@ -2920,6 +2920,7 @@ static int skge_poll(struct net_device *dev, int *budget)
2920 struct skge_hw *hw = skge->hw; 2920 struct skge_hw *hw = skge->hw;
2921 struct skge_ring *ring = &skge->rx_ring; 2921 struct skge_ring *ring = &skge->rx_ring;
2922 struct skge_element *e; 2922 struct skge_element *e;
2923 unsigned long flags;
2923 int to_do = min(dev->quota, *budget); 2924 int to_do = min(dev->quota, *budget);
2924 int work_done = 0; 2925 int work_done = 0;
2925 2926
@@ -2957,12 +2958,12 @@ static int skge_poll(struct net_device *dev, int *budget)
2957 if (work_done >= to_do) 2958 if (work_done >= to_do)
2958 return 1; /* not done */ 2959 return 1; /* not done */
2959 2960
2960 spin_lock_irq(&hw->hw_lock); 2961 spin_lock_irqsave(&hw->hw_lock, flags);
2961 __netif_rx_complete(dev); 2962 __netif_rx_complete(dev);
2962 hw->intr_mask |= irqmask[skge->port]; 2963 hw->intr_mask |= irqmask[skge->port];
2963 skge_write32(hw, B0_IMSK, hw->intr_mask); 2964 skge_write32(hw, B0_IMSK, hw->intr_mask);
2964 skge_read32(hw, B0_IMSK); 2965 skge_read32(hw, B0_IMSK);
2965 spin_unlock_irq(&hw->hw_lock); 2966 spin_unlock_irqrestore(&hw->hw_lock, flags);
2966 2967
2967 return 0; 2968 return 0;
2968} 2969}
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index fb1d2c30c1..822dd0b131 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -569,8 +569,8 @@ static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
569 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) 569 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
570 onoff = !onoff; 570 onoff = !onoff;
571 571
572 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
572 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1); 573 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
573
574 if (onoff) 574 if (onoff)
575 /* Turn off phy power saving */ 575 /* Turn off phy power saving */
576 reg1 &= ~phy_power[port]; 576 reg1 &= ~phy_power[port];
@@ -579,6 +579,7 @@ static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
579 579
580 sky2_pci_write32(hw, PCI_DEV_REG1, reg1); 580 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
581 sky2_pci_read32(hw, PCI_DEV_REG1); 581 sky2_pci_read32(hw, PCI_DEV_REG1);
582 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
582 udelay(100); 583 udelay(100);
583} 584}
584 585
@@ -1511,6 +1512,13 @@ static int sky2_down(struct net_device *dev)
1511 imask &= ~portirq_msk[port]; 1512 imask &= ~portirq_msk[port];
1512 sky2_write32(hw, B0_IMSK, imask); 1513 sky2_write32(hw, B0_IMSK, imask);
1513 1514
1515 /*
1516 * Both ports share the NAPI poll on port 0, so if necessary undo the
1517 * the disable that is done in dev_close.
1518 */
1519 if (sky2->port == 0 && hw->ports > 1)
1520 netif_poll_enable(dev);
1521
1514 sky2_gmac_reset(hw, port); 1522 sky2_gmac_reset(hw, port);
1515 1523
1516 /* Stop transmitter */ 1524 /* Stop transmitter */
@@ -3658,6 +3666,6 @@ module_init(sky2_init_module);
3658module_exit(sky2_cleanup_module); 3666module_exit(sky2_cleanup_module);
3659 3667
3660MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver"); 3668MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver");
3661MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); 3669MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
3662MODULE_LICENSE("GPL"); 3670MODULE_LICENSE("GPL");
3663MODULE_VERSION(DRV_VERSION); 3671MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 2c4343395a..880d9fdd7c 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -148,6 +148,8 @@ struct smc911x_local {
148 int tx_throttle; 148 int tx_throttle;
149 spinlock_t lock; 149 spinlock_t lock;
150 150
151 struct net_device *netdev;
152
151#ifdef SMC_USE_DMA 153#ifdef SMC_USE_DMA
152 /* DMA needs the physical address of the chip */ 154 /* DMA needs the physical address of the chip */
153 u_long physaddr; 155 u_long physaddr;
@@ -948,10 +950,11 @@ static void smc911x_phy_check_media(struct net_device *dev, int init)
948 * of autonegotiation.) If the RPC ANEG bit is cleared, the selection 950 * of autonegotiation.) If the RPC ANEG bit is cleared, the selection
949 * is controlled by the RPC SPEED and RPC DPLX bits. 951 * is controlled by the RPC SPEED and RPC DPLX bits.
950 */ 952 */
951static void smc911x_phy_configure(void *data) 953static void smc911x_phy_configure(struct work_struct *work)
952{ 954{
953 struct net_device *dev = data; 955 struct smc911x_local *lp = container_of(work, struct smc911x_local,
954 struct smc911x_local *lp = netdev_priv(dev); 956 phy_configure);
957 struct net_device *dev = lp->netdev;
955 unsigned long ioaddr = dev->base_addr; 958 unsigned long ioaddr = dev->base_addr;
956 int phyaddr = lp->mii.phy_id; 959 int phyaddr = lp->mii.phy_id;
957 int my_phy_caps; /* My PHY capabilities */ 960 int my_phy_caps; /* My PHY capabilities */
@@ -1331,7 +1334,7 @@ smc911x_rx_dma_irq(int dma, void *data)
1331static void smc911x_poll_controller(struct net_device *dev) 1334static void smc911x_poll_controller(struct net_device *dev)
1332{ 1335{
1333 disable_irq(dev->irq); 1336 disable_irq(dev->irq);
1334 smc911x_interrupt(dev->irq, dev, NULL); 1337 smc911x_interrupt(dev->irq, dev);
1335 enable_irq(dev->irq); 1338 enable_irq(dev->irq);
1336} 1339}
1337#endif 1340#endif
@@ -1495,6 +1498,8 @@ static void smc911x_set_multicast_list(struct net_device *dev)
1495static int 1498static int
1496smc911x_open(struct net_device *dev) 1499smc911x_open(struct net_device *dev)
1497{ 1500{
1501 struct smc911x_local *lp = netdev_priv(dev);
1502
1498 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__); 1503 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
1499 1504
1500 /* 1505 /*
@@ -1511,7 +1516,7 @@ smc911x_open(struct net_device *dev)
1511 smc911x_reset(dev); 1516 smc911x_reset(dev);
1512 1517
1513 /* Configure the PHY, initialize the link state */ 1518 /* Configure the PHY, initialize the link state */
1514 smc911x_phy_configure(dev); 1519 smc911x_phy_configure(&lp->phy_configure);
1515 1520
1516 /* Turn on Tx + Rx */ 1521 /* Turn on Tx + Rx */
1517 smc911x_enable(dev); 1522 smc911x_enable(dev);
@@ -2060,7 +2065,7 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
2060 dev->poll_controller = smc911x_poll_controller; 2065 dev->poll_controller = smc911x_poll_controller;
2061#endif 2066#endif
2062 2067
2063 INIT_WORK(&lp->phy_configure, smc911x_phy_configure, dev); 2068 INIT_WORK(&lp->phy_configure, smc911x_phy_configure);
2064 lp->mii.phy_id_mask = 0x1f; 2069 lp->mii.phy_id_mask = 0x1f;
2065 lp->mii.reg_num_mask = 0x1f; 2070 lp->mii.reg_num_mask = 0x1f;
2066 lp->mii.force_media = 0; 2071 lp->mii.force_media = 0;
@@ -2154,6 +2159,7 @@ static int smc911x_drv_probe(struct platform_device *pdev)
2154{ 2159{
2155 struct net_device *ndev; 2160 struct net_device *ndev;
2156 struct resource *res; 2161 struct resource *res;
2162 struct smc911x_local *lp;
2157 unsigned int *addr; 2163 unsigned int *addr;
2158 int ret; 2164 int ret;
2159 2165
@@ -2183,6 +2189,8 @@ static int smc911x_drv_probe(struct platform_device *pdev)
2183 2189
2184 ndev->dma = (unsigned char)-1; 2190 ndev->dma = (unsigned char)-1;
2185 ndev->irq = platform_get_irq(pdev, 0); 2191 ndev->irq = platform_get_irq(pdev, 0);
2192 lp = netdev_priv(ndev);
2193 lp->netdev = ndev;
2186 2194
2187 addr = ioremap(res->start, SMC911X_IO_EXTENT); 2195 addr = ioremap(res->start, SMC911X_IO_EXTENT);
2188 if (!addr) { 2196 if (!addr) {
@@ -2204,7 +2212,6 @@ out:
2204 } 2212 }
2205#ifdef SMC_USE_DMA 2213#ifdef SMC_USE_DMA
2206 else { 2214 else {
2207 struct smc911x_local *lp = netdev_priv(ndev);
2208 lp->physaddr = res->start; 2215 lp->physaddr = res->start;
2209 lp->dev = &pdev->dev; 2216 lp->dev = &pdev->dev;
2210 } 2217 }
@@ -2275,7 +2282,7 @@ static int smc911x_drv_resume(struct platform_device *dev)
2275 smc911x_reset(ndev); 2282 smc911x_reset(ndev);
2276 smc911x_enable(ndev); 2283 smc911x_enable(ndev);
2277 if (lp->phy_type != 0) 2284 if (lp->phy_type != 0)
2278 smc911x_phy_configure(ndev); 2285 smc911x_phy_configure(&lp->phy_configure);
2279 netif_device_attach(ndev); 2286 netif_device_attach(ndev);
2280 } 2287 }
2281 } 2288 }
diff --git a/drivers/net/spider_net.c b/drivers/net/spider_net.c
index ebb6aa39f9..8ea2fc1b96 100644
--- a/drivers/net/spider_net.c
+++ b/drivers/net/spider_net.c
@@ -1925,6 +1925,8 @@ spider_net_stop(struct net_device *netdev)
1925 /* release chains */ 1925 /* release chains */
1926 spider_net_release_tx_chain(card, 1); 1926 spider_net_release_tx_chain(card, 1);
1927 1927
1928 spider_net_free_rx_chain_contents(card);
1929
1928 spider_net_free_chain(card, &card->tx_chain); 1930 spider_net_free_chain(card, &card->tx_chain);
1929 spider_net_free_chain(card, &card->rx_chain); 1931 spider_net_free_chain(card, &card->rx_chain);
1930 1932
diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c
index 785e4a535f..616be8d0fa 100644
--- a/drivers/net/sungem.c
+++ b/drivers/net/sungem.c
@@ -90,7 +90,8 @@
90 90
91#define ADVERTISE_MASK (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | \ 91#define ADVERTISE_MASK (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | \
92 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \ 92 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \
93 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full) 93 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full | \
94 SUPPORTED_Pause | SUPPORTED_Autoneg)
94 95
95#define DRV_NAME "sungem" 96#define DRV_NAME "sungem"
96#define DRV_VERSION "0.98" 97#define DRV_VERSION "0.98"
diff --git a/drivers/net/sungem_phy.c b/drivers/net/sungem_phy.c
index 49800b2590..d21991ee88 100644
--- a/drivers/net/sungem_phy.c
+++ b/drivers/net/sungem_phy.c
@@ -3,10 +3,9 @@
3 * 3 *
4 * This file could be shared with other drivers. 4 * This file could be shared with other drivers.
5 * 5 *
6 * (c) 2002, Benjamin Herrenscmidt (benh@kernel.crashing.org) 6 * (c) 2002-2007, Benjamin Herrenscmidt (benh@kernel.crashing.org)
7 * 7 *
8 * TODO: 8 * TODO:
9 * - Implement WOL
10 * - Add support for PHYs that provide an IRQ line 9 * - Add support for PHYs that provide an IRQ line
11 * - Eventually moved the entire polling state machine in 10 * - Eventually moved the entire polling state machine in
12 * there (out of the eth driver), so that it can easily be 11 * there (out of the eth driver), so that it can easily be
@@ -152,6 +151,44 @@ static int bcm5221_suspend(struct mii_phy* phy)
152 return 0; 151 return 0;
153} 152}
154 153
154static int bcm5241_init(struct mii_phy* phy)
155{
156 u16 data;
157
158 data = phy_read(phy, MII_BCM5221_TEST);
159 phy_write(phy, MII_BCM5221_TEST,
160 data | MII_BCM5221_TEST_ENABLE_SHADOWS);
161
162 data = phy_read(phy, MII_BCM5221_SHDOW_AUX_STAT2);
163 phy_write(phy, MII_BCM5221_SHDOW_AUX_STAT2,
164 data | MII_BCM5221_SHDOW_AUX_STAT2_APD);
165
166 data = phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
167 phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
168 data & ~MII_BCM5241_SHDOW_AUX_MODE4_STANDBYPWR);
169
170 data = phy_read(phy, MII_BCM5221_TEST);
171 phy_write(phy, MII_BCM5221_TEST,
172 data & ~MII_BCM5221_TEST_ENABLE_SHADOWS);
173
174 return 0;
175}
176
177static int bcm5241_suspend(struct mii_phy* phy)
178{
179 u16 data;
180
181 data = phy_read(phy, MII_BCM5221_TEST);
182 phy_write(phy, MII_BCM5221_TEST,
183 data | MII_BCM5221_TEST_ENABLE_SHADOWS);
184
185 data = phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
186 phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
187 data | MII_BCM5241_SHDOW_AUX_MODE4_STANDBYPWR);
188
189 return 0;
190}
191
155static int bcm5400_init(struct mii_phy* phy) 192static int bcm5400_init(struct mii_phy* phy)
156{ 193{
157 u16 data; 194 u16 data;
@@ -373,6 +410,10 @@ static int bcm54xx_setup_aneg(struct mii_phy *phy, u32 advertise)
373 adv |= ADVERTISE_100HALF; 410 adv |= ADVERTISE_100HALF;
374 if (advertise & ADVERTISED_100baseT_Full) 411 if (advertise & ADVERTISED_100baseT_Full)
375 adv |= ADVERTISE_100FULL; 412 adv |= ADVERTISE_100FULL;
413 if (advertise & ADVERTISED_Pause)
414 adv |= ADVERTISE_PAUSE_CAP;
415 if (advertise & ADVERTISED_Asym_Pause)
416 adv |= ADVERTISE_PAUSE_ASYM;
376 phy_write(phy, MII_ADVERTISE, adv); 417 phy_write(phy, MII_ADVERTISE, adv);
377 418
378 /* Setup 1000BT advertise */ 419 /* Setup 1000BT advertise */
@@ -436,12 +477,15 @@ static int bcm54xx_read_link(struct mii_phy *phy)
436 val = phy_read(phy, MII_BCM5400_AUXSTATUS); 477 val = phy_read(phy, MII_BCM5400_AUXSTATUS);
437 link_mode = ((val & MII_BCM5400_AUXSTATUS_LINKMODE_MASK) >> 478 link_mode = ((val & MII_BCM5400_AUXSTATUS_LINKMODE_MASK) >>
438 MII_BCM5400_AUXSTATUS_LINKMODE_SHIFT); 479 MII_BCM5400_AUXSTATUS_LINKMODE_SHIFT);
439 phy->duplex = phy_BCM5400_link_table[link_mode][0] ? DUPLEX_FULL : DUPLEX_HALF; 480 phy->duplex = phy_BCM5400_link_table[link_mode][0] ?
481 DUPLEX_FULL : DUPLEX_HALF;
440 phy->speed = phy_BCM5400_link_table[link_mode][2] ? 482 phy->speed = phy_BCM5400_link_table[link_mode][2] ?
441 SPEED_1000 : 483 SPEED_1000 :
442 (phy_BCM5400_link_table[link_mode][1] ? SPEED_100 : SPEED_10); 484 (phy_BCM5400_link_table[link_mode][1] ?
485 SPEED_100 : SPEED_10);
443 val = phy_read(phy, MII_LPA); 486 val = phy_read(phy, MII_LPA);
444 phy->pause = ((val & LPA_PAUSE) != 0); 487 phy->pause = (phy->duplex == DUPLEX_FULL) &&
488 ((val & LPA_PAUSE) != 0);
445 } 489 }
446 /* On non-aneg, we assume what we put in BMCR is the speed, 490 /* On non-aneg, we assume what we put in BMCR is the speed,
447 * though magic-aneg shouldn't prevent this case from occurring 491 * though magic-aneg shouldn't prevent this case from occurring
@@ -450,6 +494,28 @@ static int bcm54xx_read_link(struct mii_phy *phy)
450 return 0; 494 return 0;
451} 495}
452 496
497static int marvell88e1111_init(struct mii_phy* phy)
498{
499 u16 rev;
500
501 /* magic init sequence for rev 0 */
502 rev = phy_read(phy, MII_PHYSID2) & 0x000f;
503 if (rev == 0) {
504 phy_write(phy, 0x1d, 0x000a);
505 phy_write(phy, 0x1e, 0x0821);
506
507 phy_write(phy, 0x1d, 0x0006);
508 phy_write(phy, 0x1e, 0x8600);
509
510 phy_write(phy, 0x1d, 0x000b);
511 phy_write(phy, 0x1e, 0x0100);
512
513 phy_write(phy, 0x1d, 0x0004);
514 phy_write(phy, 0x1e, 0x4850);
515 }
516 return 0;
517}
518
453static int marvell_setup_aneg(struct mii_phy *phy, u32 advertise) 519static int marvell_setup_aneg(struct mii_phy *phy, u32 advertise)
454{ 520{
455 u16 ctl, adv; 521 u16 ctl, adv;
@@ -471,6 +537,10 @@ static int marvell_setup_aneg(struct mii_phy *phy, u32 advertise)
471 adv |= ADVERTISE_100HALF; 537 adv |= ADVERTISE_100HALF;
472 if (advertise & ADVERTISED_100baseT_Full) 538 if (advertise & ADVERTISED_100baseT_Full)
473 adv |= ADVERTISE_100FULL; 539 adv |= ADVERTISE_100FULL;
540 if (advertise & ADVERTISED_Pause)
541 adv |= ADVERTISE_PAUSE_CAP;
542 if (advertise & ADVERTISED_Asym_Pause)
543 adv |= ADVERTISE_PAUSE_ASYM;
474 phy_write(phy, MII_ADVERTISE, adv); 544 phy_write(phy, MII_ADVERTISE, adv);
475 545
476 /* Setup 1000BT advertise & enable crossover detect 546 /* Setup 1000BT advertise & enable crossover detect
@@ -549,7 +619,7 @@ static int marvell_setup_forced(struct mii_phy *phy, int speed, int fd)
549 619
550static int marvell_read_link(struct mii_phy *phy) 620static int marvell_read_link(struct mii_phy *phy)
551{ 621{
552 u16 status; 622 u16 status, pmask;
553 623
554 if (phy->autoneg) { 624 if (phy->autoneg) {
555 status = phy_read(phy, MII_M1011_PHY_SPEC_STATUS); 625 status = phy_read(phy, MII_M1011_PHY_SPEC_STATUS);
@@ -565,7 +635,9 @@ static int marvell_read_link(struct mii_phy *phy)
565 phy->duplex = DUPLEX_FULL; 635 phy->duplex = DUPLEX_FULL;
566 else 636 else
567 phy->duplex = DUPLEX_HALF; 637 phy->duplex = DUPLEX_HALF;
568 phy->pause = 0; /* XXX Check against spec ! */ 638 pmask = MII_M1011_PHY_SPEC_STATUS_TX_PAUSE |
639 MII_M1011_PHY_SPEC_STATUS_RX_PAUSE;
640 phy->pause = (status & pmask) == pmask;
569 } 641 }
570 /* On non-aneg, we assume what we put in BMCR is the speed, 642 /* On non-aneg, we assume what we put in BMCR is the speed,
571 * though magic-aneg shouldn't prevent this case from occurring 643 * though magic-aneg shouldn't prevent this case from occurring
@@ -595,6 +667,10 @@ static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise)
595 adv |= ADVERTISE_100HALF; 667 adv |= ADVERTISE_100HALF;
596 if (advertise & ADVERTISED_100baseT_Full) 668 if (advertise & ADVERTISED_100baseT_Full)
597 adv |= ADVERTISE_100FULL; 669 adv |= ADVERTISE_100FULL;
670 if (advertise & ADVERTISED_Pause)
671 adv |= ADVERTISE_PAUSE_CAP;
672 if (advertise & ADVERTISED_Asym_Pause)
673 adv |= ADVERTISE_PAUSE_ASYM;
598 phy_write(phy, MII_ADVERTISE, adv); 674 phy_write(phy, MII_ADVERTISE, adv);
599 675
600 /* Start/Restart aneg */ 676 /* Start/Restart aneg */
@@ -666,7 +742,8 @@ static int genmii_read_link(struct mii_phy *phy)
666 phy->speed = SPEED_100; 742 phy->speed = SPEED_100;
667 else 743 else
668 phy->speed = SPEED_10; 744 phy->speed = SPEED_10;
669 phy->pause = 0; 745 phy->pause = (phy->duplex == DUPLEX_FULL) &&
746 ((lpa & LPA_PAUSE) != 0);
670 } 747 }
671 /* On non-aneg, we assume what we put in BMCR is the speed, 748 /* On non-aneg, we assume what we put in BMCR is the speed,
672 * though magic-aneg shouldn't prevent this case from occurring 749 * though magic-aneg shouldn't prevent this case from occurring
@@ -676,11 +753,19 @@ static int genmii_read_link(struct mii_phy *phy)
676} 753}
677 754
678 755
679#define MII_BASIC_FEATURES (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | \ 756#define MII_BASIC_FEATURES \
680 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \ 757 (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | \
681 SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII) 758 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \
682#define MII_GBIT_FEATURES (MII_BASIC_FEATURES | \ 759 SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII | \
683 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full) 760 SUPPORTED_Pause)
761
762/* On gigabit capable PHYs, we advertise Pause support but not asym pause
763 * support for now as I'm not sure it's supported and Darwin doesn't do
764 * it neither. --BenH.
765 */
766#define MII_GBIT_FEATURES \
767 (MII_BASIC_FEATURES | \
768 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)
684 769
685/* Broadcom BCM 5201 */ 770/* Broadcom BCM 5201 */
686static struct mii_phy_ops bcm5201_phy_ops = { 771static struct mii_phy_ops bcm5201_phy_ops = {
@@ -720,6 +805,24 @@ static struct mii_phy_def bcm5221_phy_def = {
720 .ops = &bcm5221_phy_ops 805 .ops = &bcm5221_phy_ops
721}; 806};
722 807
808/* Broadcom BCM 5241 */
809static struct mii_phy_ops bcm5241_phy_ops = {
810 .suspend = bcm5241_suspend,
811 .init = bcm5241_init,
812 .setup_aneg = genmii_setup_aneg,
813 .setup_forced = genmii_setup_forced,
814 .poll_link = genmii_poll_link,
815 .read_link = genmii_read_link,
816};
817static struct mii_phy_def bcm5241_phy_def = {
818 .phy_id = 0x0143bc30,
819 .phy_id_mask = 0xfffffff0,
820 .name = "BCM5241",
821 .features = MII_BASIC_FEATURES,
822 .magic_aneg = 1,
823 .ops = &bcm5241_phy_ops
824};
825
723/* Broadcom BCM 5400 */ 826/* Broadcom BCM 5400 */
724static struct mii_phy_ops bcm5400_phy_ops = { 827static struct mii_phy_ops bcm5400_phy_ops = {
725 .init = bcm5400_init, 828 .init = bcm5400_init,
@@ -854,11 +957,8 @@ static struct mii_phy_def bcm5462V_phy_def = {
854 .ops = &bcm5462V_phy_ops 957 .ops = &bcm5462V_phy_ops
855}; 958};
856 959
857/* Marvell 88E1101 (Apple seem to deal with 2 different revs, 960/* Marvell 88E1101 amd 88E1111 */
858 * I masked out the 8 last bits to get both, but some specs 961static struct mii_phy_ops marvell88e1101_phy_ops = {
859 * would be useful here) --BenH.
860 */
861static struct mii_phy_ops marvell_phy_ops = {
862 .suspend = generic_suspend, 962 .suspend = generic_suspend,
863 .setup_aneg = marvell_setup_aneg, 963 .setup_aneg = marvell_setup_aneg,
864 .setup_forced = marvell_setup_forced, 964 .setup_forced = marvell_setup_forced,
@@ -866,13 +966,41 @@ static struct mii_phy_ops marvell_phy_ops = {
866 .read_link = marvell_read_link 966 .read_link = marvell_read_link
867}; 967};
868 968
869static struct mii_phy_def marvell_phy_def = { 969static struct mii_phy_ops marvell88e1111_phy_ops = {
870 .phy_id = 0x01410c00, 970 .init = marvell88e1111_init,
871 .phy_id_mask = 0xffffff00, 971 .suspend = generic_suspend,
872 .name = "Marvell 88E1101", 972 .setup_aneg = marvell_setup_aneg,
973 .setup_forced = marvell_setup_forced,
974 .poll_link = genmii_poll_link,
975 .read_link = marvell_read_link
976};
977
978/* two revs in darwin for the 88e1101 ... I could use a datasheet
979 * to get the proper names...
980 */
981static struct mii_phy_def marvell88e1101v1_phy_def = {
982 .phy_id = 0x01410c20,
983 .phy_id_mask = 0xfffffff0,
984 .name = "Marvell 88E1101v1",
985 .features = MII_GBIT_FEATURES,
986 .magic_aneg = 1,
987 .ops = &marvell88e1101_phy_ops
988};
989static struct mii_phy_def marvell88e1101v2_phy_def = {
990 .phy_id = 0x01410c60,
991 .phy_id_mask = 0xfffffff0,
992 .name = "Marvell 88E1101v2",
993 .features = MII_GBIT_FEATURES,
994 .magic_aneg = 1,
995 .ops = &marvell88e1101_phy_ops
996};
997static struct mii_phy_def marvell88e1111_phy_def = {
998 .phy_id = 0x01410cc0,
999 .phy_id_mask = 0xfffffff0,
1000 .name = "Marvell 88E1111",
873 .features = MII_GBIT_FEATURES, 1001 .features = MII_GBIT_FEATURES,
874 .magic_aneg = 1, 1002 .magic_aneg = 1,
875 .ops = &marvell_phy_ops 1003 .ops = &marvell88e1111_phy_ops
876}; 1004};
877 1005
878/* Generic implementation for most 10/100 PHYs */ 1006/* Generic implementation for most 10/100 PHYs */
@@ -895,6 +1023,7 @@ static struct mii_phy_def genmii_phy_def = {
895static struct mii_phy_def* mii_phy_table[] = { 1023static struct mii_phy_def* mii_phy_table[] = {
896 &bcm5201_phy_def, 1024 &bcm5201_phy_def,
897 &bcm5221_phy_def, 1025 &bcm5221_phy_def,
1026 &bcm5241_phy_def,
898 &bcm5400_phy_def, 1027 &bcm5400_phy_def,
899 &bcm5401_phy_def, 1028 &bcm5401_phy_def,
900 &bcm5411_phy_def, 1029 &bcm5411_phy_def,
@@ -902,7 +1031,9 @@ static struct mii_phy_def* mii_phy_table[] = {
902 &bcm5421k2_phy_def, 1031 &bcm5421k2_phy_def,
903 &bcm5461_phy_def, 1032 &bcm5461_phy_def,
904 &bcm5462V_phy_def, 1033 &bcm5462V_phy_def,
905 &marvell_phy_def, 1034 &marvell88e1101v1_phy_def,
1035 &marvell88e1101v2_phy_def,
1036 &marvell88e1111_phy_def,
906 &genmii_phy_def, 1037 &genmii_phy_def,
907 NULL 1038 NULL
908}; 1039};
diff --git a/drivers/net/sungem_phy.h b/drivers/net/sungem_phy.h
index 8ee1ca0471..1d70ba6f9f 100644
--- a/drivers/net/sungem_phy.h
+++ b/drivers/net/sungem_phy.h
@@ -30,7 +30,7 @@ struct mii_phy_def
30struct mii_phy 30struct mii_phy
31{ 31{
32 struct mii_phy_def* def; 32 struct mii_phy_def* def;
33 int advertising; 33 u32 advertising;
34 int mii_id; 34 int mii_id;
35 35
36 /* 1: autoneg enabled, 0: disabled */ 36 /* 1: autoneg enabled, 0: disabled */
@@ -85,6 +85,9 @@ extern int mii_phy_probe(struct mii_phy *phy, int mii_id);
85#define MII_BCM5221_SHDOW_AUX_MODE4_IDDQMODE 0x0001 85#define MII_BCM5221_SHDOW_AUX_MODE4_IDDQMODE 0x0001
86#define MII_BCM5221_SHDOW_AUX_MODE4_CLKLOPWR 0x0004 86#define MII_BCM5221_SHDOW_AUX_MODE4_CLKLOPWR 0x0004
87 87
88/* MII BCM5241 Additional registers */
89#define MII_BCM5241_SHDOW_AUX_MODE4_STANDBYPWR 0x0008
90
88/* MII BCM5400 1000-BASET Control register */ 91/* MII BCM5400 1000-BASET Control register */
89#define MII_BCM5400_GB_CONTROL 0x09 92#define MII_BCM5400_GB_CONTROL 0x09
90#define MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP 0x0200 93#define MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP 0x0200
@@ -115,5 +118,7 @@ extern int mii_phy_probe(struct mii_phy *phy, int mii_id);
115#define MII_M1011_PHY_SPEC_STATUS_SPD_MASK 0xc000 118#define MII_M1011_PHY_SPEC_STATUS_SPD_MASK 0xc000
116#define MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX 0x2000 119#define MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX 0x2000
117#define MII_M1011_PHY_SPEC_STATUS_RESOLVED 0x0800 120#define MII_M1011_PHY_SPEC_STATUS_RESOLVED 0x0800
121#define MII_M1011_PHY_SPEC_STATUS_TX_PAUSE 0x0008
122#define MII_M1011_PHY_SPEC_STATUS_RX_PAUSE 0x0004
118 123
119#endif /* __SUNGEM_PHY_H__ */ 124#endif /* __SUNGEM_PHY_H__ */
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 571320ae87..f4bf62c2a7 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -68,8 +68,8 @@
68 68
69#define DRV_MODULE_NAME "tg3" 69#define DRV_MODULE_NAME "tg3"
70#define PFX DRV_MODULE_NAME ": " 70#define PFX DRV_MODULE_NAME ": "
71#define DRV_MODULE_VERSION "3.70" 71#define DRV_MODULE_VERSION "3.72"
72#define DRV_MODULE_RELDATE "December 1, 2006" 72#define DRV_MODULE_RELDATE "January 8, 2007"
73 73
74#define TG3_DEF_MAC_MODE 0 74#define TG3_DEF_MAC_MODE 0
75#define TG3_DEF_RX_MODE 0 75#define TG3_DEF_RX_MODE 0
@@ -959,6 +959,13 @@ static int tg3_phy_reset(struct tg3 *tp)
959 u32 phy_status; 959 u32 phy_status;
960 int err; 960 int err;
961 961
962 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
963 u32 val;
964
965 val = tr32(GRC_MISC_CFG);
966 tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ);
967 udelay(40);
968 }
962 err = tg3_readphy(tp, MII_BMSR, &phy_status); 969 err = tg3_readphy(tp, MII_BMSR, &phy_status);
963 err |= tg3_readphy(tp, MII_BMSR, &phy_status); 970 err |= tg3_readphy(tp, MII_BMSR, &phy_status);
964 if (err != 0) 971 if (err != 0)
@@ -1008,7 +1015,12 @@ out:
1008 else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) { 1015 else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
1009 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); 1016 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
1010 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); 1017 tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
1011 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); 1018 if (tp->tg3_flags2 & TG3_FLG2_PHY_ADJUST_TRIM) {
1019 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b);
1020 tg3_writephy(tp, MII_TG3_TEST1,
1021 MII_TG3_TEST1_TRIM_EN | 0x4);
1022 } else
1023 tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
1012 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); 1024 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
1013 } 1025 }
1014 /* Set Extended packet length bit (bit 14) on all chips that */ 1026 /* Set Extended packet length bit (bit 14) on all chips that */
@@ -1170,7 +1182,15 @@ static void tg3_power_down_phy(struct tg3 *tp)
1170 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) 1182 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
1171 return; 1183 return;
1172 1184
1173 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) { 1185 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
1186 u32 val;
1187
1188 tg3_bmcr_reset(tp);
1189 val = tr32(GRC_MISC_CFG);
1190 tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ);
1191 udelay(40);
1192 return;
1193 } else {
1174 tg3_writephy(tp, MII_TG3_EXT_CTRL, 1194 tg3_writephy(tp, MII_TG3_EXT_CTRL,
1175 MII_TG3_EXT_CTRL_FORCE_LED_OFF); 1195 MII_TG3_EXT_CTRL_FORCE_LED_OFF);
1176 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2); 1196 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
@@ -4426,7 +4446,7 @@ static void tg3_free_consistent(struct tg3 *tp)
4426 */ 4446 */
4427static int tg3_alloc_consistent(struct tg3 *tp) 4447static int tg3_alloc_consistent(struct tg3 *tp)
4428{ 4448{
4429 tp->rx_std_buffers = kmalloc((sizeof(struct ring_info) * 4449 tp->rx_std_buffers = kzalloc((sizeof(struct ring_info) *
4430 (TG3_RX_RING_SIZE + 4450 (TG3_RX_RING_SIZE +
4431 TG3_RX_JUMBO_RING_SIZE)) + 4451 TG3_RX_JUMBO_RING_SIZE)) +
4432 (sizeof(struct tx_ring_info) * 4452 (sizeof(struct tx_ring_info) *
@@ -4435,13 +4455,6 @@ static int tg3_alloc_consistent(struct tg3 *tp)
4435 if (!tp->rx_std_buffers) 4455 if (!tp->rx_std_buffers)
4436 return -ENOMEM; 4456 return -ENOMEM;
4437 4457
4438 memset(tp->rx_std_buffers, 0,
4439 (sizeof(struct ring_info) *
4440 (TG3_RX_RING_SIZE +
4441 TG3_RX_JUMBO_RING_SIZE)) +
4442 (sizeof(struct tx_ring_info) *
4443 TG3_TX_RING_SIZE));
4444
4445 tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE]; 4458 tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
4446 tp->tx_buffers = (struct tx_ring_info *) 4459 tp->tx_buffers = (struct tx_ring_info *)
4447 &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE]; 4460 &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
@@ -6988,6 +7001,8 @@ static int tg3_open(struct net_device *dev)
6988 struct tg3 *tp = netdev_priv(dev); 7001 struct tg3 *tp = netdev_priv(dev);
6989 int err; 7002 int err;
6990 7003
7004 netif_carrier_off(tp->dev);
7005
6991 tg3_full_lock(tp, 0); 7006 tg3_full_lock(tp, 0);
6992 7007
6993 err = tg3_set_power_state(tp, PCI_D0); 7008 err = tg3_set_power_state(tp, PCI_D0);
@@ -7981,6 +7996,10 @@ static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
7981 tp->link_config.duplex = cmd->duplex; 7996 tp->link_config.duplex = cmd->duplex;
7982 } 7997 }
7983 7998
7999 tp->link_config.orig_speed = tp->link_config.speed;
8000 tp->link_config.orig_duplex = tp->link_config.duplex;
8001 tp->link_config.orig_autoneg = tp->link_config.autoneg;
8002
7984 if (netif_running(dev)) 8003 if (netif_running(dev))
7985 tg3_setup_phy(tp, 1); 8004 tg3_setup_phy(tp, 1);
7986 8005
@@ -10789,9 +10808,11 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10789 10808
10790 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { 10809 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
10791 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || 10810 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
10792 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 10811 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
10793 tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG; 10812 tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
10794 else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) 10813 if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M)
10814 tp->tg3_flags2 |= TG3_FLG2_PHY_ADJUST_TRIM;
10815 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
10795 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG; 10816 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
10796 } 10817 }
10797 10818
@@ -11923,6 +11944,8 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11923 */ 11944 */
11924 pci_save_state(tp->pdev); 11945 pci_save_state(tp->pdev);
11925 11946
11947 pci_set_drvdata(pdev, dev);
11948
11926 err = register_netdev(dev); 11949 err = register_netdev(dev);
11927 if (err) { 11950 if (err) {
11928 printk(KERN_ERR PFX "Cannot register net device, " 11951 printk(KERN_ERR PFX "Cannot register net device, "
@@ -11930,8 +11953,6 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11930 goto err_out_iounmap; 11953 goto err_out_iounmap;
11931 } 11954 }
11932 11955
11933 pci_set_drvdata(pdev, dev);
11934
11935 printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %s Ethernet ", 11956 printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %s Ethernet ",
11936 dev->name, 11957 dev->name,
11937 tp->board_part_number, 11958 tp->board_part_number,
@@ -11962,8 +11983,6 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11962 (pdev->dma_mask == DMA_32BIT_MASK) ? 32 : 11983 (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
11963 (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64)); 11984 (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
11964 11985
11965 netif_carrier_off(tp->dev);
11966
11967 return 0; 11986 return 0;
11968 11987
11969err_out_iounmap: 11988err_out_iounmap:
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index dfaf4ed127..80f59ac7ec 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -1350,6 +1350,7 @@
1350#define GRC_MISC_CFG_BOARD_ID_5788 0x00010000 1350#define GRC_MISC_CFG_BOARD_ID_5788 0x00010000
1351#define GRC_MISC_CFG_BOARD_ID_5788M 0x00018000 1351#define GRC_MISC_CFG_BOARD_ID_5788M 0x00018000
1352#define GRC_MISC_CFG_BOARD_ID_AC91002A1 0x00018000 1352#define GRC_MISC_CFG_BOARD_ID_AC91002A1 0x00018000
1353#define GRC_MISC_CFG_EPHY_IDDQ 0x00200000
1353#define GRC_MISC_CFG_KEEP_GPHY_POWER 0x04000000 1354#define GRC_MISC_CFG_KEEP_GPHY_POWER 0x04000000
1354#define GRC_LOCAL_CTRL 0x00006808 1355#define GRC_LOCAL_CTRL 0x00006808
1355#define GRC_LCLCTRL_INT_ACTIVE 0x00000001 1356#define GRC_LCLCTRL_INT_ACTIVE 0x00000001
@@ -1657,6 +1658,9 @@
1657#define MII_TG3_EPHY_TEST 0x1f /* 5906 PHY register */ 1658#define MII_TG3_EPHY_TEST 0x1f /* 5906 PHY register */
1658#define MII_TG3_EPHY_SHADOW_EN 0x80 1659#define MII_TG3_EPHY_SHADOW_EN 0x80
1659 1660
1661#define MII_TG3_TEST1 0x1e
1662#define MII_TG3_TEST1_TRIM_EN 0x0010
1663
1660/* There are two ways to manage the TX descriptors on the tigon3. 1664/* There are two ways to manage the TX descriptors on the tigon3.
1661 * Either the descriptors are in host DMA'able memory, or they 1665 * Either the descriptors are in host DMA'able memory, or they
1662 * exist only in the cards on-chip SRAM. All 16 send bds are under 1666 * exist only in the cards on-chip SRAM. All 16 send bds are under
@@ -2255,6 +2259,7 @@ struct tg3 {
2255#define TG3_FLG2_1SHOT_MSI 0x10000000 2259#define TG3_FLG2_1SHOT_MSI 0x10000000
2256#define TG3_FLG2_PHY_JITTER_BUG 0x20000000 2260#define TG3_FLG2_PHY_JITTER_BUG 0x20000000
2257#define TG3_FLG2_NO_FWARE_REPORTED 0x40000000 2261#define TG3_FLG2_NO_FWARE_REPORTED 0x40000000
2262#define TG3_FLG2_PHY_ADJUST_TRIM 0x80000000
2258 2263
2259 u32 split_mode_max_reqs; 2264 u32 split_mode_max_reqs;
2260#define SPLIT_MODE_5704_MAX_REQ 3 2265#define SPLIT_MODE_5704_MAX_REQ 3
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 8243150f5b..7e4b23c7c1 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -29,6 +29,7 @@
29#include <linux/fsl_devices.h> 29#include <linux/fsl_devices.h>
30#include <linux/ethtool.h> 30#include <linux/ethtool.h>
31#include <linux/mii.h> 31#include <linux/mii.h>
32#include <linux/workqueue.h>
32 33
33#include <asm/of_platform.h> 34#include <asm/of_platform.h>
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
@@ -472,7 +473,7 @@ static void put_enet_addr_container(struct enet_addr_container *enet_addr_cont)
472 kfree(enet_addr_cont); 473 kfree(enet_addr_cont);
473} 474}
474 475
475static int set_mac_addr(__be16 __iomem *reg, u8 *mac) 476static void set_mac_addr(__be16 __iomem *reg, u8 *mac)
476{ 477{
477 out_be16(&reg[0], ((u16)mac[5] << 8) | mac[4]); 478 out_be16(&reg[0], ((u16)mac[5] << 8) | mac[4]);
478 out_be16(&reg[1], ((u16)mac[3] << 8) | mac[2]); 479 out_be16(&reg[1], ((u16)mac[3] << 8) | mac[2]);
@@ -3920,10 +3921,11 @@ static irqreturn_t phy_interrupt(int irq, void *dev_id)
3920} 3921}
3921 3922
3922/* Scheduled by the phy_interrupt/timer to handle PHY changes */ 3923/* Scheduled by the phy_interrupt/timer to handle PHY changes */
3923static void ugeth_phy_change(void *data) 3924static void ugeth_phy_change(struct work_struct *work)
3924{ 3925{
3925 struct net_device *dev = (struct net_device *)data; 3926 struct ucc_geth_private *ugeth =
3926 struct ucc_geth_private *ugeth = netdev_priv(dev); 3927 container_of(work, struct ucc_geth_private, tq);
3928 struct net_device *dev = ugeth->dev;
3927 struct ucc_geth *ug_regs; 3929 struct ucc_geth *ug_regs;
3928 int result = 0; 3930 int result = 0;
3929 3931
@@ -4080,7 +4082,7 @@ static int ucc_geth_open(struct net_device *dev)
4080#endif /* CONFIG_UGETH_NAPI */ 4082#endif /* CONFIG_UGETH_NAPI */
4081 4083
4082 /* Set up the PHY change work queue */ 4084 /* Set up the PHY change work queue */
4083 INIT_WORK(&ugeth->tq, ugeth_phy_change, dev); 4085 INIT_WORK(&ugeth->tq, ugeth_phy_change);
4084 4086
4085 init_timer(&ugeth->phy_info_timer); 4087 init_timer(&ugeth->phy_info_timer);
4086 ugeth->phy_info_timer.function = &ugeth_phy_startup_timer; 4088 ugeth->phy_info_timer.function = &ugeth_phy_startup_timer;
diff --git a/drivers/net/ucc_geth_phy.c b/drivers/net/ucc_geth_phy.c
index 5360ec05ea..3c86592ce0 100644
--- a/drivers/net/ucc_geth_phy.c
+++ b/drivers/net/ucc_geth_phy.c
@@ -68,8 +68,31 @@ static int gbit_config_aneg(struct ugeth_mii_info *mii_info);
68static int genmii_config_aneg(struct ugeth_mii_info *mii_info); 68static int genmii_config_aneg(struct ugeth_mii_info *mii_info);
69static int genmii_update_link(struct ugeth_mii_info *mii_info); 69static int genmii_update_link(struct ugeth_mii_info *mii_info);
70static int genmii_read_status(struct ugeth_mii_info *mii_info); 70static int genmii_read_status(struct ugeth_mii_info *mii_info);
71u16 phy_read(struct ugeth_mii_info *mii_info, u16 regnum); 71
72void phy_write(struct ugeth_mii_info *mii_info, u16 regnum, u16 val); 72static u16 ucc_geth_phy_read(struct ugeth_mii_info *mii_info, u16 regnum)
73{
74 u16 retval;
75 unsigned long flags;
76
77 ugphy_vdbg("%s: IN", __FUNCTION__);
78
79 spin_lock_irqsave(&mii_info->mdio_lock, flags);
80 retval = mii_info->mdio_read(mii_info->dev, mii_info->mii_id, regnum);
81 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
82
83 return retval;
84}
85
86static void ucc_geth_phy_write(struct ugeth_mii_info *mii_info, u16 regnum, u16 val)
87{
88 unsigned long flags;
89
90 ugphy_vdbg("%s: IN", __FUNCTION__);
91
92 spin_lock_irqsave(&mii_info->mdio_lock, flags);
93 mii_info->mdio_write(mii_info->dev, mii_info->mii_id, regnum, val);
94 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
95}
73 96
74/* Write value to the PHY for this device to the register at regnum, */ 97/* Write value to the PHY for this device to the register at regnum, */
75/* waiting until the write is done before it returns. All PHY */ 98/* waiting until the write is done before it returns. All PHY */
@@ -184,7 +207,7 @@ static void config_genmii_advert(struct ugeth_mii_info *mii_info)
184 advertise = mii_info->advertising; 207 advertise = mii_info->advertising;
185 208
186 /* Setup standard advertisement */ 209 /* Setup standard advertisement */
187 adv = phy_read(mii_info, MII_ADVERTISE); 210 adv = ucc_geth_phy_read(mii_info, MII_ADVERTISE);
188 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); 211 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
189 if (advertise & ADVERTISED_10baseT_Half) 212 if (advertise & ADVERTISED_10baseT_Half)
190 adv |= ADVERTISE_10HALF; 213 adv |= ADVERTISE_10HALF;
@@ -194,7 +217,7 @@ static void config_genmii_advert(struct ugeth_mii_info *mii_info)
194 adv |= ADVERTISE_100HALF; 217 adv |= ADVERTISE_100HALF;
195 if (advertise & ADVERTISED_100baseT_Full) 218 if (advertise & ADVERTISED_100baseT_Full)
196 adv |= ADVERTISE_100FULL; 219 adv |= ADVERTISE_100FULL;
197 phy_write(mii_info, MII_ADVERTISE, adv); 220 ucc_geth_phy_write(mii_info, MII_ADVERTISE, adv);
198} 221}
199 222
200static void genmii_setup_forced(struct ugeth_mii_info *mii_info) 223static void genmii_setup_forced(struct ugeth_mii_info *mii_info)
@@ -204,7 +227,7 @@ static void genmii_setup_forced(struct ugeth_mii_info *mii_info)
204 227
205 ugphy_vdbg("%s: IN", __FUNCTION__); 228 ugphy_vdbg("%s: IN", __FUNCTION__);
206 229
207 ctrl = phy_read(mii_info, MII_BMCR); 230 ctrl = ucc_geth_phy_read(mii_info, MII_BMCR);
208 231
209 ctrl &= 232 ctrl &=
210 ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_SPEED1000 | BMCR_ANENABLE); 233 ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_SPEED1000 | BMCR_ANENABLE);
@@ -234,7 +257,7 @@ static void genmii_setup_forced(struct ugeth_mii_info *mii_info)
234 break; 257 break;
235 } 258 }
236 259
237 phy_write(mii_info, MII_BMCR, ctrl); 260 ucc_geth_phy_write(mii_info, MII_BMCR, ctrl);
238} 261}
239 262
240/* Enable and Restart Autonegotiation */ 263/* Enable and Restart Autonegotiation */
@@ -244,9 +267,9 @@ static void genmii_restart_aneg(struct ugeth_mii_info *mii_info)
244 267
245 ugphy_vdbg("%s: IN", __FUNCTION__); 268 ugphy_vdbg("%s: IN", __FUNCTION__);
246 269
247 ctl = phy_read(mii_info, MII_BMCR); 270 ctl = ucc_geth_phy_read(mii_info, MII_BMCR);
248 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); 271 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
249 phy_write(mii_info, MII_BMCR, ctl); 272 ucc_geth_phy_write(mii_info, MII_BMCR, ctl);
250} 273}
251 274
252static int gbit_config_aneg(struct ugeth_mii_info *mii_info) 275static int gbit_config_aneg(struct ugeth_mii_info *mii_info)
@@ -261,14 +284,14 @@ static int gbit_config_aneg(struct ugeth_mii_info *mii_info)
261 config_genmii_advert(mii_info); 284 config_genmii_advert(mii_info);
262 advertise = mii_info->advertising; 285 advertise = mii_info->advertising;
263 286
264 adv = phy_read(mii_info, MII_1000BASETCONTROL); 287 adv = ucc_geth_phy_read(mii_info, MII_1000BASETCONTROL);
265 adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP | 288 adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP |
266 MII_1000BASETCONTROL_HALFDUPLEXCAP); 289 MII_1000BASETCONTROL_HALFDUPLEXCAP);
267 if (advertise & SUPPORTED_1000baseT_Half) 290 if (advertise & SUPPORTED_1000baseT_Half)
268 adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP; 291 adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP;
269 if (advertise & SUPPORTED_1000baseT_Full) 292 if (advertise & SUPPORTED_1000baseT_Full)
270 adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP; 293 adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP;
271 phy_write(mii_info, MII_1000BASETCONTROL, adv); 294 ucc_geth_phy_write(mii_info, MII_1000BASETCONTROL, adv);
272 295
273 /* Start/Restart aneg */ 296 /* Start/Restart aneg */
274 genmii_restart_aneg(mii_info); 297 genmii_restart_aneg(mii_info);
@@ -298,10 +321,10 @@ static int genmii_update_link(struct ugeth_mii_info *mii_info)
298 ugphy_vdbg("%s: IN", __FUNCTION__); 321 ugphy_vdbg("%s: IN", __FUNCTION__);
299 322
300 /* Do a fake read */ 323 /* Do a fake read */
301 phy_read(mii_info, MII_BMSR); 324 ucc_geth_phy_read(mii_info, MII_BMSR);
302 325
303 /* Read link and autonegotiation status */ 326 /* Read link and autonegotiation status */
304 status = phy_read(mii_info, MII_BMSR); 327 status = ucc_geth_phy_read(mii_info, MII_BMSR);
305 if ((status & BMSR_LSTATUS) == 0) 328 if ((status & BMSR_LSTATUS) == 0)
306 mii_info->link = 0; 329 mii_info->link = 0;
307 else 330 else
@@ -329,7 +352,7 @@ static int genmii_read_status(struct ugeth_mii_info *mii_info)
329 return err; 352 return err;
330 353
331 if (mii_info->autoneg) { 354 if (mii_info->autoneg) {
332 status = phy_read(mii_info, MII_LPA); 355 status = ucc_geth_phy_read(mii_info, MII_LPA);
333 356
334 if (status & (LPA_10FULL | LPA_100FULL)) 357 if (status & (LPA_10FULL | LPA_100FULL))
335 mii_info->duplex = DUPLEX_FULL; 358 mii_info->duplex = DUPLEX_FULL;
@@ -352,9 +375,9 @@ static int marvell_init(struct ugeth_mii_info *mii_info)
352{ 375{
353 ugphy_vdbg("%s: IN", __FUNCTION__); 376 ugphy_vdbg("%s: IN", __FUNCTION__);
354 377
355 phy_write(mii_info, 0x14, 0x0cd2); 378 ucc_geth_phy_write(mii_info, 0x14, 0x0cd2);
356 phy_write(mii_info, MII_BMCR, 379 ucc_geth_phy_write(mii_info, MII_BMCR,
357 phy_read(mii_info, MII_BMCR) | BMCR_RESET); 380 ucc_geth_phy_read(mii_info, MII_BMCR) | BMCR_RESET);
358 msleep(4000); 381 msleep(4000);
359 382
360 return 0; 383 return 0;
@@ -367,13 +390,13 @@ static int marvell_config_aneg(struct ugeth_mii_info *mii_info)
367 /* The Marvell PHY has an errata which requires 390 /* The Marvell PHY has an errata which requires
368 * that certain registers get written in order 391 * that certain registers get written in order
369 * to restart autonegotiation */ 392 * to restart autonegotiation */
370 phy_write(mii_info, MII_BMCR, BMCR_RESET); 393 ucc_geth_phy_write(mii_info, MII_BMCR, BMCR_RESET);
371 394
372 phy_write(mii_info, 0x1d, 0x1f); 395 ucc_geth_phy_write(mii_info, 0x1d, 0x1f);
373 phy_write(mii_info, 0x1e, 0x200c); 396 ucc_geth_phy_write(mii_info, 0x1e, 0x200c);
374 phy_write(mii_info, 0x1d, 0x5); 397 ucc_geth_phy_write(mii_info, 0x1d, 0x5);
375 phy_write(mii_info, 0x1e, 0); 398 ucc_geth_phy_write(mii_info, 0x1e, 0);
376 phy_write(mii_info, 0x1e, 0x100); 399 ucc_geth_phy_write(mii_info, 0x1e, 0x100);
377 400
378 gbit_config_aneg(mii_info); 401 gbit_config_aneg(mii_info);
379 402
@@ -398,7 +421,7 @@ static int marvell_read_status(struct ugeth_mii_info *mii_info)
398 * are as set */ 421 * are as set */
399 if (mii_info->autoneg && mii_info->link) { 422 if (mii_info->autoneg && mii_info->link) {
400 int speed; 423 int speed;
401 status = phy_read(mii_info, MII_M1011_PHY_SPEC_STATUS); 424 status = ucc_geth_phy_read(mii_info, MII_M1011_PHY_SPEC_STATUS);
402 425
403 /* Get the duplexity */ 426 /* Get the duplexity */
404 if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX) 427 if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)
@@ -430,7 +453,7 @@ static int marvell_ack_interrupt(struct ugeth_mii_info *mii_info)
430 ugphy_vdbg("%s: IN", __FUNCTION__); 453 ugphy_vdbg("%s: IN", __FUNCTION__);
431 454
432 /* Clear the interrupts by reading the reg */ 455 /* Clear the interrupts by reading the reg */
433 phy_read(mii_info, MII_M1011_IEVENT); 456 ucc_geth_phy_read(mii_info, MII_M1011_IEVENT);
434 457
435 return 0; 458 return 0;
436} 459}
@@ -440,9 +463,9 @@ static int marvell_config_intr(struct ugeth_mii_info *mii_info)
440 ugphy_vdbg("%s: IN", __FUNCTION__); 463 ugphy_vdbg("%s: IN", __FUNCTION__);
441 464
442 if (mii_info->interrupts == MII_INTERRUPT_ENABLED) 465 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
443 phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT); 466 ucc_geth_phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
444 else 467 else
445 phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR); 468 ucc_geth_phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
446 469
447 return 0; 470 return 0;
448} 471}
@@ -451,9 +474,9 @@ static int cis820x_init(struct ugeth_mii_info *mii_info)
451{ 474{
452 ugphy_vdbg("%s: IN", __FUNCTION__); 475 ugphy_vdbg("%s: IN", __FUNCTION__);
453 476
454 phy_write(mii_info, MII_CIS8201_AUX_CONSTAT, 477 ucc_geth_phy_write(mii_info, MII_CIS8201_AUX_CONSTAT,
455 MII_CIS8201_AUXCONSTAT_INIT); 478 MII_CIS8201_AUXCONSTAT_INIT);
456 phy_write(mii_info, MII_CIS8201_EXT_CON1, MII_CIS8201_EXTCON1_INIT); 479 ucc_geth_phy_write(mii_info, MII_CIS8201_EXT_CON1, MII_CIS8201_EXTCON1_INIT);
457 480
458 return 0; 481 return 0;
459} 482}
@@ -477,7 +500,7 @@ static int cis820x_read_status(struct ugeth_mii_info *mii_info)
477 if (mii_info->autoneg && mii_info->link) { 500 if (mii_info->autoneg && mii_info->link) {
478 int speed; 501 int speed;
479 502
480 status = phy_read(mii_info, MII_CIS8201_AUX_CONSTAT); 503 status = ucc_geth_phy_read(mii_info, MII_CIS8201_AUX_CONSTAT);
481 if (status & MII_CIS8201_AUXCONSTAT_DUPLEX) 504 if (status & MII_CIS8201_AUXCONSTAT_DUPLEX)
482 mii_info->duplex = DUPLEX_FULL; 505 mii_info->duplex = DUPLEX_FULL;
483 else 506 else
@@ -505,7 +528,7 @@ static int cis820x_ack_interrupt(struct ugeth_mii_info *mii_info)
505{ 528{
506 ugphy_vdbg("%s: IN", __FUNCTION__); 529 ugphy_vdbg("%s: IN", __FUNCTION__);
507 530
508 phy_read(mii_info, MII_CIS8201_ISTAT); 531 ucc_geth_phy_read(mii_info, MII_CIS8201_ISTAT);
509 532
510 return 0; 533 return 0;
511} 534}
@@ -515,9 +538,9 @@ static int cis820x_config_intr(struct ugeth_mii_info *mii_info)
515 ugphy_vdbg("%s: IN", __FUNCTION__); 538 ugphy_vdbg("%s: IN", __FUNCTION__);
516 539
517 if (mii_info->interrupts == MII_INTERRUPT_ENABLED) 540 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
518 phy_write(mii_info, MII_CIS8201_IMASK, MII_CIS8201_IMASK_MASK); 541 ucc_geth_phy_write(mii_info, MII_CIS8201_IMASK, MII_CIS8201_IMASK_MASK);
519 else 542 else
520 phy_write(mii_info, MII_CIS8201_IMASK, 0); 543 ucc_geth_phy_write(mii_info, MII_CIS8201_IMASK, 0);
521 544
522 return 0; 545 return 0;
523} 546}
@@ -541,7 +564,7 @@ static int dm9161_read_status(struct ugeth_mii_info *mii_info)
541 /* If we aren't autonegotiating, assume speeds 564 /* If we aren't autonegotiating, assume speeds
542 * are as set */ 565 * are as set */
543 if (mii_info->autoneg && mii_info->link) { 566 if (mii_info->autoneg && mii_info->link) {
544 status = phy_read(mii_info, MII_DM9161_SCSR); 567 status = ucc_geth_phy_read(mii_info, MII_DM9161_SCSR);
545 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H)) 568 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H))
546 mii_info->speed = SPEED_100; 569 mii_info->speed = SPEED_100;
547 else 570 else
@@ -572,7 +595,7 @@ static void dm9161_timer(unsigned long data)
572{ 595{
573 struct ugeth_mii_info *mii_info = (struct ugeth_mii_info *)data; 596 struct ugeth_mii_info *mii_info = (struct ugeth_mii_info *)data;
574 struct dm9161_private *priv = mii_info->priv; 597 struct dm9161_private *priv = mii_info->priv;
575 u16 status = phy_read(mii_info, MII_BMSR); 598 u16 status = ucc_geth_phy_read(mii_info, MII_BMSR);
576 599
577 ugphy_vdbg("%s: IN", __FUNCTION__); 600 ugphy_vdbg("%s: IN", __FUNCTION__);
578 601
@@ -599,11 +622,11 @@ static int dm9161_init(struct ugeth_mii_info *mii_info)
599 /* Reset is not done yet */ 622 /* Reset is not done yet */
600 priv->resetdone = 0; 623 priv->resetdone = 0;
601 624
602 phy_write(mii_info, MII_BMCR, 625 ucc_geth_phy_write(mii_info, MII_BMCR,
603 phy_read(mii_info, MII_BMCR) | BMCR_RESET); 626 ucc_geth_phy_read(mii_info, MII_BMCR) | BMCR_RESET);
604 627
605 phy_write(mii_info, MII_BMCR, 628 ucc_geth_phy_write(mii_info, MII_BMCR,
606 phy_read(mii_info, MII_BMCR) & ~BMCR_ISOLATE); 629 ucc_geth_phy_read(mii_info, MII_BMCR) & ~BMCR_ISOLATE);
607 630
608 config_genmii_advert(mii_info); 631 config_genmii_advert(mii_info);
609 /* Start/Restart aneg */ 632 /* Start/Restart aneg */
@@ -634,7 +657,7 @@ static int dm9161_ack_interrupt(struct ugeth_mii_info *mii_info)
634 ugphy_vdbg("%s: IN", __FUNCTION__); 657 ugphy_vdbg("%s: IN", __FUNCTION__);
635 658
636 /* Clear the interrupts by reading the reg */ 659 /* Clear the interrupts by reading the reg */
637 phy_read(mii_info, MII_DM9161_INTR); 660 ucc_geth_phy_read(mii_info, MII_DM9161_INTR);
638 661
639 662
640 return 0; 663 return 0;
@@ -645,9 +668,9 @@ static int dm9161_config_intr(struct ugeth_mii_info *mii_info)
645 ugphy_vdbg("%s: IN", __FUNCTION__); 668 ugphy_vdbg("%s: IN", __FUNCTION__);
646 669
647 if (mii_info->interrupts == MII_INTERRUPT_ENABLED) 670 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
648 phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT); 671 ucc_geth_phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT);
649 else 672 else
650 phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP); 673 ucc_geth_phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP);
651 674
652 return 0; 675 return 0;
653} 676}
@@ -718,31 +741,6 @@ static struct phy_info *phy_info[] = {
718 NULL 741 NULL
719}; 742};
720 743
721u16 phy_read(struct ugeth_mii_info *mii_info, u16 regnum)
722{
723 u16 retval;
724 unsigned long flags;
725
726 ugphy_vdbg("%s: IN", __FUNCTION__);
727
728 spin_lock_irqsave(&mii_info->mdio_lock, flags);
729 retval = mii_info->mdio_read(mii_info->dev, mii_info->mii_id, regnum);
730 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
731
732 return retval;
733}
734
735void phy_write(struct ugeth_mii_info *mii_info, u16 regnum, u16 val)
736{
737 unsigned long flags;
738
739 ugphy_vdbg("%s: IN", __FUNCTION__);
740
741 spin_lock_irqsave(&mii_info->mdio_lock, flags);
742 mii_info->mdio_write(mii_info->dev, mii_info->mii_id, regnum, val);
743 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
744}
745
746/* Use the PHY ID registers to determine what type of PHY is attached 744/* Use the PHY ID registers to determine what type of PHY is attached
747 * to device dev. return a struct phy_info structure describing that PHY 745 * to device dev. return a struct phy_info structure describing that PHY
748 */ 746 */
@@ -757,11 +755,11 @@ struct phy_info *get_phy_info(struct ugeth_mii_info *mii_info)
757 ugphy_vdbg("%s: IN", __FUNCTION__); 755 ugphy_vdbg("%s: IN", __FUNCTION__);
758 756
759 /* Grab the bits from PHYIR1, and put them in the upper half */ 757 /* Grab the bits from PHYIR1, and put them in the upper half */
760 phy_reg = phy_read(mii_info, MII_PHYSID1); 758 phy_reg = ucc_geth_phy_read(mii_info, MII_PHYSID1);
761 phy_ID = (phy_reg & 0xffff) << 16; 759 phy_ID = (phy_reg & 0xffff) << 16;
762 760
763 /* Grab the bits from PHYIR2, and put them in the lower half */ 761 /* Grab the bits from PHYIR2, and put them in the lower half */
764 phy_reg = phy_read(mii_info, MII_PHYSID2); 762 phy_reg = ucc_geth_phy_read(mii_info, MII_PHYSID2);
765 phy_ID |= (phy_reg & 0xffff); 763 phy_ID |= (phy_reg & 0xffff);
766 764
767 /* loop through all the known PHY types, and find one that */ 765 /* loop through all the known PHY types, and find one that */
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index 4587f23f4e..8e5d82051b 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -265,15 +265,19 @@ static int velocity_set_media_mode(struct velocity_info *vptr, u32 mii_status);
265static int velocity_suspend(struct pci_dev *pdev, pm_message_t state); 265static int velocity_suspend(struct pci_dev *pdev, pm_message_t state);
266static int velocity_resume(struct pci_dev *pdev); 266static int velocity_resume(struct pci_dev *pdev);
267 267
268static DEFINE_SPINLOCK(velocity_dev_list_lock);
269static LIST_HEAD(velocity_dev_list);
270
271#endif
272
273#if defined(CONFIG_PM) && defined(CONFIG_INET)
274
268static int velocity_netdev_event(struct notifier_block *nb, unsigned long notification, void *ptr); 275static int velocity_netdev_event(struct notifier_block *nb, unsigned long notification, void *ptr);
269 276
270static struct notifier_block velocity_inetaddr_notifier = { 277static struct notifier_block velocity_inetaddr_notifier = {
271 .notifier_call = velocity_netdev_event, 278 .notifier_call = velocity_netdev_event,
272}; 279};
273 280
274static DEFINE_SPINLOCK(velocity_dev_list_lock);
275static LIST_HEAD(velocity_dev_list);
276
277static void velocity_register_notifier(void) 281static void velocity_register_notifier(void)
278{ 282{
279 register_inetaddr_notifier(&velocity_inetaddr_notifier); 283 register_inetaddr_notifier(&velocity_inetaddr_notifier);
@@ -284,12 +288,12 @@ static void velocity_unregister_notifier(void)
284 unregister_inetaddr_notifier(&velocity_inetaddr_notifier); 288 unregister_inetaddr_notifier(&velocity_inetaddr_notifier);
285} 289}
286 290
287#else /* CONFIG_PM */ 291#else
288 292
289#define velocity_register_notifier() do {} while (0) 293#define velocity_register_notifier() do {} while (0)
290#define velocity_unregister_notifier() do {} while (0) 294#define velocity_unregister_notifier() do {} while (0)
291 295
292#endif /* !CONFIG_PM */ 296#endif
293 297
294/* 298/*
295 * Internal board variants. At the moment we have only one 299 * Internal board variants. At the moment we have only one
@@ -3292,6 +3296,8 @@ static int velocity_resume(struct pci_dev *pdev)
3292 return 0; 3296 return 0;
3293} 3297}
3294 3298
3299#ifdef CONFIG_INET
3300
3295static int velocity_netdev_event(struct notifier_block *nb, unsigned long notification, void *ptr) 3301static int velocity_netdev_event(struct notifier_block *nb, unsigned long notification, void *ptr)
3296{ 3302{
3297 struct in_ifaddr *ifa = (struct in_ifaddr *) ptr; 3303 struct in_ifaddr *ifa = (struct in_ifaddr *) ptr;
@@ -3312,4 +3318,6 @@ static int velocity_netdev_event(struct notifier_block *nb, unsigned long notifi
3312 } 3318 }
3313 return NOTIFY_DONE; 3319 return NOTIFY_DONE;
3314} 3320}
3321
3322#endif
3315#endif 3323#endif
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
index 2ec2e5afce..91b752e3d0 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
@@ -2701,8 +2701,8 @@ static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
2701 sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI); 2701 sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
2702 2702
2703 /* extract core_id, core_rev, core_vendor */ 2703 /* extract core_id, core_rev, core_vendor */
2704 core_id = (sb_id_hi & 0xFFF0) >> 4; 2704 core_id = (sb_id_hi & 0x8FF0) >> 4;
2705 core_rev = (sb_id_hi & 0xF); 2705 core_rev = ((sb_id_hi & 0xF) | ((sb_id_hi & 0x7000) >> 8));
2706 core_vendor = (sb_id_hi & 0xFFFF0000) >> 16; 2706 core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
2707 2707
2708 dprintk(KERN_INFO PFX "Core %d: ID 0x%x, rev 0x%x, vendor 0x%x\n", 2708 dprintk(KERN_INFO PFX "Core %d: ID 0x%x, rev 0x%x, vendor 0x%x\n",
@@ -2873,7 +2873,10 @@ static int bcm43xx_wireless_core_init(struct bcm43xx_private *bcm,
2873 sbimconfiglow = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW); 2873 sbimconfiglow = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
2874 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK; 2874 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
2875 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK; 2875 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
2876 sbimconfiglow |= 0x32; 2876 if (bcm->bustype == BCM43xx_BUSTYPE_PCI)
2877 sbimconfiglow |= 0x32;
2878 else
2879 sbimconfiglow |= 0x53;
2877 bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow); 2880 bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow);
2878 } 2881 }
2879 2882
@@ -3077,7 +3080,7 @@ static int bcm43xx_setup_backplane_pci_connection(struct bcm43xx_private *bcm,
3077 if (err) 3080 if (err)
3078 goto out; 3081 goto out;
3079 3082
3080 if (bcm->current_core->rev < 6 || 3083 if (bcm->current_core->rev < 6 &&
3081 bcm->current_core->id == BCM43xx_COREID_PCI) { 3084 bcm->current_core->id == BCM43xx_COREID_PCI) {
3082 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBINTVEC); 3085 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBINTVEC);
3083 value |= (1 << backplane_flag_nr); 3086 value |= (1 << backplane_flag_nr);
diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index 0e94fbbf7a..b85857a848 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -2664,7 +2664,7 @@ static void __ipw2100_rx_process(struct ipw2100_priv *priv)
2664 break; 2664 break;
2665 } 2665 }
2666#endif 2666#endif
2667 if (stats.len < sizeof(u->rx_data.header)) 2667 if (stats.len < sizeof(struct ieee80211_hdr_3addr))
2668 break; 2668 break;
2669 switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) { 2669 switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
2670 case IEEE80211_FTYPE_MGMT: 2670 case IEEE80211_FTYPE_MGMT:
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index 644b4741ef..a009ab5177 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -406,7 +406,6 @@ static int netwave_probe(struct pcmcia_device *link)
406 link->conf.Attributes = CONF_ENABLE_IRQ; 406 link->conf.Attributes = CONF_ENABLE_IRQ;
407 link->conf.IntType = INT_MEMORY_AND_IO; 407 link->conf.IntType = INT_MEMORY_AND_IO;
408 link->conf.ConfigIndex = 1; 408 link->conf.ConfigIndex = 1;
409 link->conf.Present = PRESENT_OPTION;
410 409
411 /* Netwave private struct init. link/dev/node already taken care of, 410 /* Netwave private struct init. link/dev/node already taken care of,
412 * other stuff zero'd - Jean II */ 411 * other stuff zero'd - Jean II */
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 88e10c9bc4..47b2ccb6a6 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -331,7 +331,6 @@ static int ray_probe(struct pcmcia_device *p_dev)
331 p_dev->conf.Attributes = CONF_ENABLE_IRQ; 331 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
332 p_dev->conf.IntType = INT_MEMORY_AND_IO; 332 p_dev->conf.IntType = INT_MEMORY_AND_IO;
333 p_dev->conf.ConfigIndex = 1; 333 p_dev->conf.ConfigIndex = 1;
334 p_dev->conf.Present = PRESENT_OPTION;
335 334
336 p_dev->priv = dev; 335 p_dev->priv = dev;
337 p_dev->irq.Instance = dev; 336 p_dev->irq.Instance = dev;
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 583e0d655a..c250f08c8d 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -1928,7 +1928,6 @@ static int wl3501_probe(struct pcmcia_device *p_dev)
1928 p_dev->conf.Attributes = CONF_ENABLE_IRQ; 1928 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
1929 p_dev->conf.IntType = INT_MEMORY_AND_IO; 1929 p_dev->conf.IntType = INT_MEMORY_AND_IO;
1930 p_dev->conf.ConfigIndex = 1; 1930 p_dev->conf.ConfigIndex = 1;
1931 p_dev->conf.Present = PRESENT_OPTION;
1932 1931
1933 dev = alloc_etherdev(sizeof(struct wl3501_card)); 1932 dev = alloc_etherdev(sizeof(struct wl3501_card));
1934 if (!dev) 1933 if (!dev)
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index 00ca704ece..a08524191b 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -41,6 +41,8 @@ static void housekeeping_disable(struct zd_mac *mac);
41 41
42static void set_multicast_hash_handler(struct work_struct *work); 42static void set_multicast_hash_handler(struct work_struct *work);
43 43
44static void do_rx(unsigned long mac_ptr);
45
44int zd_mac_init(struct zd_mac *mac, 46int zd_mac_init(struct zd_mac *mac,
45 struct net_device *netdev, 47 struct net_device *netdev,
46 struct usb_interface *intf) 48 struct usb_interface *intf)
@@ -53,6 +55,10 @@ int zd_mac_init(struct zd_mac *mac,
53 INIT_DELAYED_WORK(&mac->set_rts_cts_work, set_rts_cts_work); 55 INIT_DELAYED_WORK(&mac->set_rts_cts_work, set_rts_cts_work);
54 INIT_DELAYED_WORK(&mac->set_basic_rates_work, set_basic_rates_work); 56 INIT_DELAYED_WORK(&mac->set_basic_rates_work, set_basic_rates_work);
55 57
58 skb_queue_head_init(&mac->rx_queue);
59 tasklet_init(&mac->rx_tasklet, do_rx, (unsigned long)mac);
60 tasklet_disable(&mac->rx_tasklet);
61
56 ieee_init(ieee); 62 ieee_init(ieee);
57 softmac_init(ieee80211_priv(netdev)); 63 softmac_init(ieee80211_priv(netdev));
58 zd_chip_init(&mac->chip, netdev, intf); 64 zd_chip_init(&mac->chip, netdev, intf);
@@ -140,6 +146,8 @@ out:
140void zd_mac_clear(struct zd_mac *mac) 146void zd_mac_clear(struct zd_mac *mac)
141{ 147{
142 flush_workqueue(zd_workqueue); 148 flush_workqueue(zd_workqueue);
149 skb_queue_purge(&mac->rx_queue);
150 tasklet_kill(&mac->rx_tasklet);
143 zd_chip_clear(&mac->chip); 151 zd_chip_clear(&mac->chip);
144 ZD_ASSERT(!spin_is_locked(&mac->lock)); 152 ZD_ASSERT(!spin_is_locked(&mac->lock));
145 ZD_MEMCLEAR(mac, sizeof(struct zd_mac)); 153 ZD_MEMCLEAR(mac, sizeof(struct zd_mac));
@@ -168,6 +176,8 @@ int zd_mac_open(struct net_device *netdev)
168 struct zd_chip *chip = &mac->chip; 176 struct zd_chip *chip = &mac->chip;
169 int r; 177 int r;
170 178
179 tasklet_enable(&mac->rx_tasklet);
180
171 r = zd_chip_enable_int(chip); 181 r = zd_chip_enable_int(chip);
172 if (r < 0) 182 if (r < 0)
173 goto out; 183 goto out;
@@ -218,6 +228,8 @@ int zd_mac_stop(struct net_device *netdev)
218 */ 228 */
219 229
220 zd_chip_disable_rx(chip); 230 zd_chip_disable_rx(chip);
231 skb_queue_purge(&mac->rx_queue);
232 tasklet_disable(&mac->rx_tasklet);
221 housekeeping_disable(mac); 233 housekeeping_disable(mac);
222 ieee80211softmac_stop(netdev); 234 ieee80211softmac_stop(netdev);
223 235
@@ -470,13 +482,13 @@ static void bssinfo_change(struct net_device *netdev, u32 changes)
470 482
471 if (changes & IEEE80211SOFTMAC_BSSINFOCHG_RATES) { 483 if (changes & IEEE80211SOFTMAC_BSSINFOCHG_RATES) {
472 /* Set RTS rate to highest available basic rate */ 484 /* Set RTS rate to highest available basic rate */
473 u8 rate = ieee80211softmac_highest_supported_rate(softmac, 485 u8 hi_rate = ieee80211softmac_highest_supported_rate(softmac,
474 &bssinfo->supported_rates, 1); 486 &bssinfo->supported_rates, 1);
475 rate = rate_to_zd_rate(rate); 487 hi_rate = rate_to_zd_rate(hi_rate);
476 488
477 spin_lock_irqsave(&mac->lock, flags); 489 spin_lock_irqsave(&mac->lock, flags);
478 if (rate != mac->rts_rate) { 490 if (hi_rate != mac->rts_rate) {
479 mac->rts_rate = rate; 491 mac->rts_rate = hi_rate;
480 need_set_rts_cts = 1; 492 need_set_rts_cts = 1;
481 } 493 }
482 spin_unlock_irqrestore(&mac->lock, flags); 494 spin_unlock_irqrestore(&mac->lock, flags);
@@ -1072,43 +1084,75 @@ static int fill_rx_stats(struct ieee80211_rx_stats *stats,
1072 return 0; 1084 return 0;
1073} 1085}
1074 1086
1075int zd_mac_rx(struct zd_mac *mac, const u8 *buffer, unsigned int length) 1087static void zd_mac_rx(struct zd_mac *mac, struct sk_buff *skb)
1076{ 1088{
1077 int r; 1089 int r;
1078 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); 1090 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1079 struct ieee80211_rx_stats stats; 1091 struct ieee80211_rx_stats stats;
1080 const struct rx_status *status; 1092 const struct rx_status *status;
1081 struct sk_buff *skb;
1082 1093
1083 if (length < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN + 1094 if (skb->len < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN +
1084 IEEE80211_FCS_LEN + sizeof(struct rx_status)) 1095 IEEE80211_FCS_LEN + sizeof(struct rx_status))
1085 return -EINVAL; 1096 {
1097 dev_dbg_f(zd_mac_dev(mac), "Packet with length %u to small.\n",
1098 skb->len);
1099 goto free_skb;
1100 }
1086 1101
1087 r = fill_rx_stats(&stats, &status, mac, buffer, length); 1102 r = fill_rx_stats(&stats, &status, mac, skb->data, skb->len);
1088 if (r) 1103 if (r) {
1089 return r; 1104 /* Only packets with rx errors are included here. */
1105 goto free_skb;
1106 }
1090 1107
1091 length -= ZD_PLCP_HEADER_SIZE+IEEE80211_FCS_LEN+ 1108 __skb_pull(skb, ZD_PLCP_HEADER_SIZE);
1092 sizeof(struct rx_status); 1109 __skb_trim(skb, skb->len -
1093 buffer += ZD_PLCP_HEADER_SIZE; 1110 (IEEE80211_FCS_LEN + sizeof(struct rx_status)));
1094 1111
1095 update_qual_rssi(mac, buffer, length, stats.signal, stats.rssi); 1112 update_qual_rssi(mac, skb->data, skb->len, stats.signal,
1113 status->signal_strength);
1096 1114
1097 r = filter_rx(ieee, buffer, length, &stats); 1115 r = filter_rx(ieee, skb->data, skb->len, &stats);
1098 if (r <= 0) 1116 if (r <= 0) {
1099 return r; 1117 if (r < 0)
1118 dev_dbg_f(zd_mac_dev(mac), "Error in packet.\n");
1119 goto free_skb;
1120 }
1100 1121
1101 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length);
1102 if (!skb)
1103 return -ENOMEM;
1104 if (ieee->iw_mode == IW_MODE_MONITOR) 1122 if (ieee->iw_mode == IW_MODE_MONITOR)
1105 fill_rt_header(skb_put(skb, sizeof(struct zd_rt_hdr)), mac, 1123 fill_rt_header(skb_push(skb, sizeof(struct zd_rt_hdr)), mac,
1106 &stats, status); 1124 &stats, status);
1107 memcpy(skb_put(skb, length), buffer, length);
1108 1125
1109 r = ieee80211_rx(ieee, skb, &stats); 1126 r = ieee80211_rx(ieee, skb, &stats);
1110 if (!r) 1127 if (r)
1111 dev_kfree_skb_any(skb); 1128 return;
1129free_skb:
1130 /* We are always in a soft irq. */
1131 dev_kfree_skb(skb);
1132}
1133
1134static void do_rx(unsigned long mac_ptr)
1135{
1136 struct zd_mac *mac = (struct zd_mac *)mac_ptr;
1137 struct sk_buff *skb;
1138
1139 while ((skb = skb_dequeue(&mac->rx_queue)) != NULL)
1140 zd_mac_rx(mac, skb);
1141}
1142
1143int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length)
1144{
1145 struct sk_buff *skb;
1146
1147 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length);
1148 if (!skb) {
1149 dev_warn(zd_mac_dev(mac), "Could not allocate skb.\n");
1150 return -ENOMEM;
1151 }
1152 skb_reserve(skb, sizeof(struct zd_rt_hdr));
1153 memcpy(__skb_put(skb, length), buffer, length);
1154 skb_queue_tail(&mac->rx_queue, skb);
1155 tasklet_schedule(&mac->rx_tasklet);
1112 return 0; 1156 return 0;
1113} 1157}
1114 1158
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.h b/drivers/net/wireless/zd1211rw/zd_mac.h
index f0cf05dc7d..faf4c7828d 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.h
+++ b/drivers/net/wireless/zd1211rw/zd_mac.h
@@ -138,6 +138,9 @@ struct zd_mac {
138 struct delayed_work set_rts_cts_work; 138 struct delayed_work set_rts_cts_work;
139 struct delayed_work set_basic_rates_work; 139 struct delayed_work set_basic_rates_work;
140 140
141 struct tasklet_struct rx_tasklet;
142 struct sk_buff_head rx_queue;
143
141 unsigned int stats_count; 144 unsigned int stats_count;
142 u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE]; 145 u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE];
143 u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE]; 146 u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE];
@@ -193,7 +196,7 @@ int zd_mac_stop(struct net_device *netdev);
193int zd_mac_set_mac_address(struct net_device *dev, void *p); 196int zd_mac_set_mac_address(struct net_device *dev, void *p);
194void zd_mac_set_multicast_list(struct net_device *netdev); 197void zd_mac_set_multicast_list(struct net_device *netdev);
195 198
196int zd_mac_rx(struct zd_mac *mac, const u8 *buffer, unsigned int length); 199int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length);
197 200
198int zd_mac_set_regdomain(struct zd_mac *zd_mac, u8 regdomain); 201int zd_mac_set_regdomain(struct zd_mac *zd_mac, u8 regdomain);
199u8 zd_mac_get_regdomain(struct zd_mac *zd_mac); 202u8 zd_mac_get_regdomain(struct zd_mac *zd_mac);
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index aa782e8875..605e96e740 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -598,13 +598,13 @@ static void handle_rx_packet(struct zd_usb *usb, const u8 *buffer,
598 n = l+k; 598 n = l+k;
599 if (n > length) 599 if (n > length)
600 return; 600 return;
601 zd_mac_rx(mac, buffer+l, k); 601 zd_mac_rx_irq(mac, buffer+l, k);
602 if (i >= 2) 602 if (i >= 2)
603 return; 603 return;
604 l = (n+3) & ~3; 604 l = (n+3) & ~3;
605 } 605 }
606 } else { 606 } else {
607 zd_mac_rx(mac, buffer, length); 607 zd_mac_rx_irq(mac, buffer, length);
608 } 608 }
609} 609}
610 610
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index f1dd81a1d5..3cfb0a3575 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -19,7 +19,7 @@ config PCI_MSI
19 19
20config PCI_MULTITHREAD_PROBE 20config PCI_MULTITHREAD_PROBE
21 bool "PCI Multi-threaded probe (EXPERIMENTAL)" 21 bool "PCI Multi-threaded probe (EXPERIMENTAL)"
22 depends on PCI && EXPERIMENTAL 22 depends on PCI && EXPERIMENTAL && BROKEN
23 help 23 help
24 Say Y here if you want the PCI core to spawn a new thread for 24 Say Y here if you want the PCI core to spawn a new thread for
25 every PCI device that is probed. This can cause a huge 25 every PCI device that is probed. This can cause a huge
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 0b9d0db159..fca978fb15 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -773,13 +773,13 @@ static int get_gsi_base(acpi_handle handle, u32 *gsi_base)
773 goto out; 773 goto out;
774 774
775 table = obj->buffer.pointer; 775 table = obj->buffer.pointer;
776 switch (((acpi_table_entry_header *)table)->type) { 776 switch (((struct acpi_subtable_header *)table)->type) {
777 case ACPI_MADT_IOSAPIC: 777 case ACPI_MADT_TYPE_IO_SAPIC:
778 *gsi_base = ((struct acpi_table_iosapic *)table)->global_irq_base; 778 *gsi_base = ((struct acpi_madt_io_sapic *)table)->global_irq_base;
779 result = 0; 779 result = 0;
780 break; 780 break;
781 case ACPI_MADT_IOAPIC: 781 case ACPI_MADT_TYPE_IO_APIC:
782 *gsi_base = ((struct acpi_table_ioapic *)table)->global_irq_base; 782 *gsi_base = ((struct acpi_madt_io_apic *)table)->global_irq_base;
783 result = 0; 783 result = 0;
784 break; 784 break;
785 default: 785 default:
@@ -1682,7 +1682,7 @@ int __init acpiphp_glue_init(void)
1682 * 1682 *
1683 * This function frees all data allocated in acpiphp_glue_init() 1683 * This function frees all data allocated in acpiphp_glue_init()
1684 */ 1684 */
1685void __exit acpiphp_glue_exit(void) 1685void acpiphp_glue_exit(void)
1686{ 1686{
1687 acpi_pci_unregister_driver(&acpi_pci_hp_driver); 1687 acpi_pci_unregister_driver(&acpi_pci_hp_driver);
1688} 1688}
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index bd40aee10e..7f03881a8b 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -319,13 +319,12 @@ static int ibm_get_table_from_acpi(char **bufp)
319 if (bufp == NULL) 319 if (bufp == NULL)
320 goto read_table_done; 320 goto read_table_done;
321 321
322 lbuf = kmalloc(size, GFP_KERNEL); 322 lbuf = kzalloc(size, GFP_KERNEL);
323 dbg("%s: element count: %i, ASL table size: %i, &table = 0x%p\n", 323 dbg("%s: element count: %i, ASL table size: %i, &table = 0x%p\n",
324 __FUNCTION__, package->package.count, size, lbuf); 324 __FUNCTION__, package->package.count, size, lbuf);
325 325
326 if (lbuf) { 326 if (lbuf) {
327 *bufp = lbuf; 327 *bufp = lbuf;
328 memset(lbuf, 0, size);
329 } else { 328 } else {
330 size = -ENOMEM; 329 size = -ENOMEM;
331 goto read_table_done; 330 goto read_table_done;
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
index b771196a65..3009193f00 100644
--- a/drivers/pci/hotplug/rpaphp_slot.c
+++ b/drivers/pci/hotplug/rpaphp_slot.c
@@ -47,21 +47,11 @@ static ssize_t location_read_file (struct hotplug_slot *php_slot, char *buf)
47 return retval; 47 return retval;
48} 48}
49 49
50static struct hotplug_slot_attribute hotplug_slot_attr_location = { 50static struct hotplug_slot_attribute php_attr_location = {
51 .attr = {.name = "phy_location", .mode = S_IFREG | S_IRUGO}, 51 .attr = {.name = "phy_location", .mode = S_IFREG | S_IRUGO},
52 .show = location_read_file, 52 .show = location_read_file,
53}; 53};
54 54
55static void rpaphp_sysfs_add_attr_location (struct hotplug_slot *slot)
56{
57 sysfs_create_file(&slot->kobj, &hotplug_slot_attr_location.attr);
58}
59
60static void rpaphp_sysfs_remove_attr_location (struct hotplug_slot *slot)
61{
62 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_location.attr);
63}
64
65/* free up the memory used by a slot */ 55/* free up the memory used by a slot */
66static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot) 56static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot)
67{ 57{
@@ -145,7 +135,7 @@ int rpaphp_deregister_slot(struct slot *slot)
145 list_del(&slot->rpaphp_slot_list); 135 list_del(&slot->rpaphp_slot_list);
146 136
147 /* remove "phy_location" file */ 137 /* remove "phy_location" file */
148 rpaphp_sysfs_remove_attr_location(php_slot); 138 sysfs_remove_file(&php_slot->kobj, &php_attr_location.attr);
149 139
150 retval = pci_hp_deregister(php_slot); 140 retval = pci_hp_deregister(php_slot);
151 if (retval) 141 if (retval)
@@ -160,36 +150,45 @@ EXPORT_SYMBOL_GPL(rpaphp_deregister_slot);
160 150
161int rpaphp_register_slot(struct slot *slot) 151int rpaphp_register_slot(struct slot *slot)
162{ 152{
153 struct hotplug_slot *php_slot = slot->hotplug_slot;
163 int retval; 154 int retval;
164 155
165 dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n", 156 dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n",
166 __FUNCTION__, slot->dn->full_name, slot->index, slot->name, 157 __FUNCTION__, slot->dn->full_name, slot->index, slot->name,
167 slot->power_domain, slot->type); 158 slot->power_domain, slot->type);
159
168 /* should not try to register the same slot twice */ 160 /* should not try to register the same slot twice */
169 if (is_registered(slot)) { /* should't be here */ 161 if (is_registered(slot)) {
170 err("rpaphp_register_slot: slot[%s] is already registered\n", slot->name); 162 err("rpaphp_register_slot: slot[%s] is already registered\n", slot->name);
171 rpaphp_release_slot(slot->hotplug_slot); 163 retval = -EAGAIN;
172 return -EAGAIN; 164 goto register_fail;
173 } 165 }
174 retval = pci_hp_register(slot->hotplug_slot); 166
167 retval = pci_hp_register(php_slot);
175 if (retval) { 168 if (retval) {
176 err("pci_hp_register failed with error %d\n", retval); 169 err("pci_hp_register failed with error %d\n", retval);
177 rpaphp_release_slot(slot->hotplug_slot); 170 goto register_fail;
178 return retval;
179 } 171 }
180
181 /* create "phy_locatoin" file */
182 rpaphp_sysfs_add_attr_location(slot->hotplug_slot);
183 172
184 /* add slot to our internal list */ 173 /* create "phy_location" file */
185 dbg("%s adding slot[%s] to rpaphp_slot_list\n", 174 retval = sysfs_create_file(&php_slot->kobj, &php_attr_location.attr);
186 __FUNCTION__, slot->name); 175 if (retval) {
176 err("sysfs_create_file failed with error %d\n", retval);
177 goto sysfs_fail;
178 }
187 179
180 /* add slot to our internal list */
188 list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head); 181 list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head);
189 info("Slot [%s](PCI location=%s) registered\n", slot->name, 182 info("Slot [%s](PCI location=%s) registered\n", slot->name,
190 slot->location); 183 slot->location);
191 num_slots++; 184 num_slots++;
192 return 0; 185 return 0;
186
187sysfs_fail:
188 pci_hp_deregister(php_slot);
189register_fail:
190 rpaphp_release_slot(php_slot);
191 return retval;
193} 192}
194 193
195int rpaphp_get_power_status(struct slot *slot, u8 * value) 194int rpaphp_get_power_status(struct slot *slot, u8 * value)
diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
index 5d188c5583..78cf0711d1 100644
--- a/drivers/pci/hotplug/sgi_hotplug.c
+++ b/drivers/pci/hotplug/sgi_hotplug.c
@@ -28,6 +28,8 @@
28#include <asm/sn/sn_feature_sets.h> 28#include <asm/sn/sn_feature_sets.h>
29#include <asm/sn/sn_sal.h> 29#include <asm/sn/sn_sal.h>
30#include <asm/sn/types.h> 30#include <asm/sn/types.h>
31#include <linux/acpi.h>
32#include <asm/sn/acpi.h>
31 33
32#include "../pci.h" 34#include "../pci.h"
33 35
@@ -35,14 +37,17 @@ MODULE_LICENSE("GPL");
35MODULE_AUTHOR("SGI (prarit@sgi.com, dickie@sgi.com, habeck@sgi.com)"); 37MODULE_AUTHOR("SGI (prarit@sgi.com, dickie@sgi.com, habeck@sgi.com)");
36MODULE_DESCRIPTION("SGI Altix Hot Plug PCI Controller Driver"); 38MODULE_DESCRIPTION("SGI Altix Hot Plug PCI Controller Driver");
37 39
38#define PCIIO_ASIC_TYPE_TIOCA 4 40
41/* SAL call error codes. Keep in sync with prom header io/include/pcibr.h */
39#define PCI_SLOT_ALREADY_UP 2 /* slot already up */ 42#define PCI_SLOT_ALREADY_UP 2 /* slot already up */
40#define PCI_SLOT_ALREADY_DOWN 3 /* slot already down */ 43#define PCI_SLOT_ALREADY_DOWN 3 /* slot already down */
41#define PCI_L1_ERR 7 /* L1 console command error */ 44#define PCI_L1_ERR 7 /* L1 console command error */
42#define PCI_EMPTY_33MHZ 15 /* empty 33 MHz bus */ 45#define PCI_EMPTY_33MHZ 15 /* empty 33 MHz bus */
46
47
48#define PCIIO_ASIC_TYPE_TIOCA 4
43#define PCI_L1_QSIZE 128 /* our L1 message buffer size */ 49#define PCI_L1_QSIZE 128 /* our L1 message buffer size */
44#define SN_MAX_HP_SLOTS 32 /* max hotplug slots */ 50#define SN_MAX_HP_SLOTS 32 /* max hotplug slots */
45#define SGI_HOTPLUG_PROM_REV 0x0430 /* Min. required PROM version */
46#define SN_SLOT_NAME_SIZE 33 /* size of name string */ 51#define SN_SLOT_NAME_SIZE 33 /* size of name string */
47 52
48/* internal list head */ 53/* internal list head */
@@ -227,7 +232,7 @@ static void sn_bus_free_data(struct pci_dev *dev)
227} 232}
228 233
229static int sn_slot_enable(struct hotplug_slot *bss_hotplug_slot, 234static int sn_slot_enable(struct hotplug_slot *bss_hotplug_slot,
230 int device_num) 235 int device_num, char **ssdt)
231{ 236{
232 struct slot *slot = bss_hotplug_slot->private; 237 struct slot *slot = bss_hotplug_slot->private;
233 struct pcibus_info *pcibus_info; 238 struct pcibus_info *pcibus_info;
@@ -240,7 +245,8 @@ static int sn_slot_enable(struct hotplug_slot *bss_hotplug_slot,
240 * Power-on and initialize the slot in the SN 245 * Power-on and initialize the slot in the SN
241 * PCI infrastructure. 246 * PCI infrastructure.
242 */ 247 */
243 rc = sal_pcibr_slot_enable(pcibus_info, device_num, &resp); 248 rc = sal_pcibr_slot_enable(pcibus_info, device_num, &resp, ssdt);
249
244 250
245 if (rc == PCI_SLOT_ALREADY_UP) { 251 if (rc == PCI_SLOT_ALREADY_UP) {
246 dev_dbg(slot->pci_bus->self, "is already active\n"); 252 dev_dbg(slot->pci_bus->self, "is already active\n");
@@ -335,6 +341,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
335 int func, num_funcs; 341 int func, num_funcs;
336 int new_ppb = 0; 342 int new_ppb = 0;
337 int rc; 343 int rc;
344 char *ssdt = NULL;
338 void pcibios_fixup_device_resources(struct pci_dev *); 345 void pcibios_fixup_device_resources(struct pci_dev *);
339 346
340 /* Serialize the Linux PCI infrastructure */ 347 /* Serialize the Linux PCI infrastructure */
@@ -342,14 +349,29 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
342 349
343 /* 350 /*
344 * Power-on and initialize the slot in the SN 351 * Power-on and initialize the slot in the SN
345 * PCI infrastructure. 352 * PCI infrastructure. Also, retrieve the ACPI SSDT
353 * table for the slot (if ACPI capable PROM).
346 */ 354 */
347 rc = sn_slot_enable(bss_hotplug_slot, slot->device_num); 355 rc = sn_slot_enable(bss_hotplug_slot, slot->device_num, &ssdt);
348 if (rc) { 356 if (rc) {
349 mutex_unlock(&sn_hotplug_mutex); 357 mutex_unlock(&sn_hotplug_mutex);
350 return rc; 358 return rc;
351 } 359 }
352 360
361 if (ssdt)
362 ssdt = __va(ssdt);
363 /* Add the new SSDT for the slot to the ACPI namespace */
364 if (SN_ACPI_BASE_SUPPORT() && ssdt) {
365 acpi_status ret;
366
367 ret = acpi_load_table((struct acpi_table_header *)ssdt);
368 if (ACPI_FAILURE(ret)) {
369 printk(KERN_ERR "%s: acpi_load_table failed (0x%x)\n",
370 __FUNCTION__, ret);
371 /* try to continue on */
372 }
373 }
374
353 num_funcs = pci_scan_slot(slot->pci_bus, 375 num_funcs = pci_scan_slot(slot->pci_bus,
354 PCI_DEVFN(slot->device_num + 1, 0)); 376 PCI_DEVFN(slot->device_num + 1, 0));
355 if (!num_funcs) { 377 if (!num_funcs) {
@@ -374,7 +396,10 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
374 * pdi_host_pcidev_info). 396 * pdi_host_pcidev_info).
375 */ 397 */
376 pcibios_fixup_device_resources(dev); 398 pcibios_fixup_device_resources(dev);
377 sn_pci_fixup_slot(dev); 399 if (SN_ACPI_BASE_SUPPORT())
400 sn_acpi_slot_fixup(dev);
401 else
402 sn_io_slot_fixup(dev);
378 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { 403 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
379 unsigned char sec_bus; 404 unsigned char sec_bus;
380 pci_read_config_byte(dev, PCI_SECONDARY_BUS, 405 pci_read_config_byte(dev, PCI_SECONDARY_BUS,
@@ -388,6 +413,63 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
388 } 413 }
389 } 414 }
390 415
416 /*
417 * Add the slot's devices to the ACPI infrastructure */
418 if (SN_ACPI_BASE_SUPPORT() && ssdt) {
419 unsigned long adr;
420 struct acpi_device *pdevice;
421 struct acpi_device *device;
422 acpi_handle phandle;
423 acpi_handle chandle = NULL;
424 acpi_handle rethandle;
425 acpi_status ret;
426
427 phandle = PCI_CONTROLLER(slot->pci_bus)->acpi_handle;
428
429 if (acpi_bus_get_device(phandle, &pdevice)) {
430 dev_dbg(slot->pci_bus->self,
431 "no parent device, assuming NULL\n");
432 pdevice = NULL;
433 }
434
435 /*
436 * Walk the rootbus node's immediate children looking for
437 * the slot's device node(s). There can be more than
438 * one for multifunction devices.
439 */
440 for (;;) {
441 rethandle = NULL;
442 ret = acpi_get_next_object(ACPI_TYPE_DEVICE,
443 phandle, chandle,
444 &rethandle);
445
446 if (ret == AE_NOT_FOUND || rethandle == NULL)
447 break;
448
449 chandle = rethandle;
450
451 ret = acpi_evaluate_integer(chandle, METHOD_NAME__ADR,
452 NULL, &adr);
453
454 if (ACPI_SUCCESS(ret) &&
455 (adr>>16) == (slot->device_num + 1)) {
456
457 ret = acpi_bus_add(&device, pdevice, chandle,
458 ACPI_BUS_TYPE_DEVICE);
459 if (ACPI_FAILURE(ret)) {
460 printk(KERN_ERR "%s: acpi_bus_add "
461 "failed (0x%x) for slot %d "
462 "func %d\n", __FUNCTION__,
463 ret, (int)(adr>>16),
464 (int)(adr&0xffff));
465 /* try to continue on */
466 } else {
467 acpi_bus_start(device);
468 }
469 }
470 }
471 }
472
391 /* Call the driver for the new device */ 473 /* Call the driver for the new device */
392 pci_bus_add_devices(slot->pci_bus); 474 pci_bus_add_devices(slot->pci_bus);
393 /* Call the drivers for the new devices subordinate to PPB */ 475 /* Call the drivers for the new devices subordinate to PPB */
@@ -412,6 +494,7 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
412 struct pci_dev *dev; 494 struct pci_dev *dev;
413 int func; 495 int func;
414 int rc; 496 int rc;
497 acpi_owner_id ssdt_id = 0;
415 498
416 /* Acquire update access to the bus */ 499 /* Acquire update access to the bus */
417 mutex_lock(&sn_hotplug_mutex); 500 mutex_lock(&sn_hotplug_mutex);
@@ -422,6 +505,52 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
422 if (rc) 505 if (rc)
423 goto leaving; 506 goto leaving;
424 507
508 /* free the ACPI resources for the slot */
509 if (SN_ACPI_BASE_SUPPORT() &&
510 PCI_CONTROLLER(slot->pci_bus)->acpi_handle) {
511 unsigned long adr;
512 struct acpi_device *device;
513 acpi_handle phandle;
514 acpi_handle chandle = NULL;
515 acpi_handle rethandle;
516 acpi_status ret;
517
518 /* Get the rootbus node pointer */
519 phandle = PCI_CONTROLLER(slot->pci_bus)->acpi_handle;
520
521 /*
522 * Walk the rootbus node's immediate children looking for
523 * the slot's device node(s). There can be more than
524 * one for multifunction devices.
525 */
526 for (;;) {
527 rethandle = NULL;
528 ret = acpi_get_next_object(ACPI_TYPE_DEVICE,
529 phandle, chandle,
530 &rethandle);
531
532 if (ret == AE_NOT_FOUND || rethandle == NULL)
533 break;
534
535 chandle = rethandle;
536
537 ret = acpi_evaluate_integer(chandle,
538 METHOD_NAME__ADR,
539 NULL, &adr);
540 if (ACPI_SUCCESS(ret) &&
541 (adr>>16) == (slot->device_num + 1)) {
542 /* retain the owner id */
543 acpi_get_id(chandle, &ssdt_id);
544
545 ret = acpi_bus_get_device(chandle,
546 &device);
547 if (ACPI_SUCCESS(ret))
548 acpi_bus_trim(device, 1);
549 }
550 }
551
552 }
553
425 /* Free the SN resources assigned to the Linux device.*/ 554 /* Free the SN resources assigned to the Linux device.*/
426 for (func = 0; func < 8; func++) { 555 for (func = 0; func < 8; func++) {
427 dev = pci_get_slot(slot->pci_bus, 556 dev = pci_get_slot(slot->pci_bus,
@@ -434,6 +563,18 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
434 } 563 }
435 } 564 }
436 565
566 /* Remove the SSDT for the slot from the ACPI namespace */
567 if (SN_ACPI_BASE_SUPPORT() && ssdt_id) {
568 acpi_status ret;
569 ret = acpi_unload_table_id(ssdt_id);
570 if (ACPI_FAILURE(ret)) {
571 printk(KERN_ERR "%s: acpi_unload_table_id "
572 "failed (0x%x) for id %d\n",
573 __FUNCTION__, ret, ssdt_id);
574 /* try to continue on */
575 }
576 }
577
437 /* free the collected sysdata pointers */ 578 /* free the collected sysdata pointers */
438 sn_bus_free_sysdata(); 579 sn_bus_free_sysdata();
439 580
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index 5075769584..3ca6a4f574 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -47,11 +47,17 @@ extern int shpchp_poll_time;
47extern int shpchp_debug; 47extern int shpchp_debug;
48extern struct workqueue_struct *shpchp_wq; 48extern struct workqueue_struct *shpchp_wq;
49 49
50/*#define dbg(format, arg...) do { if (shpchp_debug) printk(KERN_DEBUG "%s: " format, MY_NAME , ## arg); } while (0)*/ 50#define dbg(format, arg...) \
51#define dbg(format, arg...) do { if (shpchp_debug) printk("%s: " format, MY_NAME , ## arg); } while (0) 51 do { \
52#define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg) 52 if (shpchp_debug) \
53#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) 53 printk("%s: " format, MY_NAME , ## arg); \
54#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 54 } while (0)
55#define err(format, arg...) \
56 printk(KERN_ERR "%s: " format, MY_NAME , ## arg)
57#define info(format, arg...) \
58 printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
59#define warn(format, arg...) \
60 printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
55 61
56#define SLOT_NAME_SIZE 10 62#define SLOT_NAME_SIZE 10
57struct slot { 63struct slot {
@@ -83,34 +89,27 @@ struct event_info {
83struct controller { 89struct controller {
84 struct mutex crit_sect; /* critical section mutex */ 90 struct mutex crit_sect; /* critical section mutex */
85 struct mutex cmd_lock; /* command lock */ 91 struct mutex cmd_lock; /* command lock */
86 struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */
87 int num_slots; /* Number of slots on ctlr */ 92 int num_slots; /* Number of slots on ctlr */
88 int slot_num_inc; /* 1 or -1 */ 93 int slot_num_inc; /* 1 or -1 */
89 struct pci_dev *pci_dev; 94 struct pci_dev *pci_dev;
90 struct list_head slot_list; 95 struct list_head slot_list;
91 struct hpc_ops *hpc_ops; 96 struct hpc_ops *hpc_ops;
92 wait_queue_head_t queue; /* sleep & wake process */ 97 wait_queue_head_t queue; /* sleep & wake process */
93 u8 bus;
94 u8 device;
95 u8 function;
96 u8 slot_device_offset; 98 u8 slot_device_offset;
97 u8 add_support;
98 u32 pcix_misc2_reg; /* for amd pogo errata */ 99 u32 pcix_misc2_reg; /* for amd pogo errata */
99 enum pci_bus_speed speed;
100 u32 first_slot; /* First physical slot number */ 100 u32 first_slot; /* First physical slot number */
101 u8 slot_bus; /* Bus where the slots handled by this controller sit */
102 u32 cap_offset; 101 u32 cap_offset;
103 unsigned long mmio_base; 102 unsigned long mmio_base;
104 unsigned long mmio_size; 103 unsigned long mmio_size;
104 void __iomem *creg;
105 struct timer_list poll_timer;
105}; 106};
106 107
107
108/* Define AMD SHPC ID */ 108/* Define AMD SHPC ID */
109#define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450 109#define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450
110#define PCI_DEVICE_ID_AMD_POGO_7458 0x7458 110#define PCI_DEVICE_ID_AMD_POGO_7458 0x7458
111 111
112/* AMD PCIX bridge registers */ 112/* AMD PCIX bridge registers */
113
114#define PCIX_MEM_BASE_LIMIT_OFFSET 0x1C 113#define PCIX_MEM_BASE_LIMIT_OFFSET 0x1C
115#define PCIX_MISCII_OFFSET 0x48 114#define PCIX_MISCII_OFFSET 0x48
116#define PCIX_MISC_BRIDGE_ERRORS_OFFSET 0x80 115#define PCIX_MISC_BRIDGE_ERRORS_OFFSET 0x80
@@ -145,8 +144,6 @@ struct controller {
145#define POWERON_STATE 3 144#define POWERON_STATE 3
146#define POWEROFF_STATE 4 145#define POWEROFF_STATE 4
147 146
148#define PCI_TO_PCI_BRIDGE_CLASS 0x00060400
149
150/* Error messages */ 147/* Error messages */
151#define INTERLOCK_OPEN 0x00000002 148#define INTERLOCK_OPEN 0x00000002
152#define ADD_NOT_SUPPORTED 0x00000003 149#define ADD_NOT_SUPPORTED 0x00000003
@@ -158,50 +155,32 @@ struct controller {
158#define WRONG_BUS_FREQUENCY 0x0000000D 155#define WRONG_BUS_FREQUENCY 0x0000000D
159#define POWER_FAILURE 0x0000000E 156#define POWER_FAILURE 0x0000000E
160 157
161#define REMOVE_NOT_SUPPORTED 0x00000003
162
163#define DISABLE_CARD 1
164
165/*
166 * error Messages
167 */
168#define msg_initialization_err "Initialization failure, error=%d\n"
169#define msg_button_on "PCI slot #%s - powering on due to button press.\n"
170#define msg_button_off "PCI slot #%s - powering off due to button press.\n"
171#define msg_button_cancel "PCI slot #%s - action canceled due to button press.\n"
172
173/* sysfs functions for the hotplug controller info */
174extern int __must_check shpchp_create_ctrl_files(struct controller *ctrl); 158extern int __must_check shpchp_create_ctrl_files(struct controller *ctrl);
175 159extern void shpchp_remove_ctrl_files(struct controller *ctrl);
176extern int shpchp_sysfs_enable_slot(struct slot *slot); 160extern int shpchp_sysfs_enable_slot(struct slot *slot);
177extern int shpchp_sysfs_disable_slot(struct slot *slot); 161extern int shpchp_sysfs_disable_slot(struct slot *slot);
178 162extern u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl);
179extern u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id); 163extern u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl);
180extern u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id); 164extern u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl);
181extern u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id); 165extern u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl);
182extern u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id); 166extern int shpchp_configure_device(struct slot *p_slot);
183 167extern int shpchp_unconfigure_device(struct slot *p_slot);
184/* pci functions */ 168extern void cleanup_slots(struct controller *ctrl);
185extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num); 169extern void queue_pushbutton_work(struct work_struct *work);
186extern int shpchp_configure_device(struct slot *p_slot); 170extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
187extern int shpchp_unconfigure_device(struct slot *p_slot);
188extern void shpchp_remove_ctrl_files(struct controller *ctrl);
189extern void cleanup_slots(struct controller *ctrl);
190extern void queue_pushbutton_work(struct work_struct *work);
191
192 171
193#ifdef CONFIG_ACPI 172#ifdef CONFIG_ACPI
194static inline int get_hp_params_from_firmware(struct pci_dev *dev, 173static inline int get_hp_params_from_firmware(struct pci_dev *dev,
195 struct hotplug_params *hpp) 174 struct hotplug_params *hpp)
196{ 175{
197 if (ACPI_FAILURE(acpi_get_hp_params_from_firmware(dev->bus, hpp))) 176 if (ACPI_FAILURE(acpi_get_hp_params_from_firmware(dev->bus, hpp)))
198 return -ENODEV; 177 return -ENODEV;
199 return 0; 178 return 0;
200} 179}
201#define get_hp_hw_control_from_firmware(pdev) \ 180#define get_hp_hw_control_from_firmware(pdev) \
202 do { \ 181 do { \
203 if (DEVICE_ACPI_HANDLE(&(pdev->dev))) \ 182 if (DEVICE_ACPI_HANDLE(&(pdev->dev))) \
204 acpi_run_oshp(DEVICE_ACPI_HANDLE(&(pdev->dev))); \ 183 acpi_run_oshp(DEVICE_ACPI_HANDLE(&(pdev->dev)));\
205 } while (0) 184 } while (0)
206#else 185#else
207#define get_hp_params_from_firmware(dev, hpp) (-ENODEV) 186#define get_hp_params_from_firmware(dev, hpp) (-ENODEV)
@@ -222,108 +201,40 @@ struct ctrl_reg {
222 volatile u32 serr_loc; 201 volatile u32 serr_loc;
223 volatile u32 serr_intr_enable; 202 volatile u32 serr_intr_enable;
224 volatile u32 slot1; 203 volatile u32 slot1;
225 volatile u32 slot2;
226 volatile u32 slot3;
227 volatile u32 slot4;
228 volatile u32 slot5;
229 volatile u32 slot6;
230 volatile u32 slot7;
231 volatile u32 slot8;
232 volatile u32 slot9;
233 volatile u32 slot10;
234 volatile u32 slot11;
235 volatile u32 slot12;
236} __attribute__ ((packed)); 204} __attribute__ ((packed));
237 205
238/* offsets to the controller registers based on the above structure layout */ 206/* offsets to the controller registers based on the above structure layout */
239enum ctrl_offsets { 207enum ctrl_offsets {
240 BASE_OFFSET = offsetof(struct ctrl_reg, base_offset), 208 BASE_OFFSET = offsetof(struct ctrl_reg, base_offset),
241 SLOT_AVAIL1 = offsetof(struct ctrl_reg, slot_avail1), 209 SLOT_AVAIL1 = offsetof(struct ctrl_reg, slot_avail1),
242 SLOT_AVAIL2 = offsetof(struct ctrl_reg, slot_avail2), 210 SLOT_AVAIL2 = offsetof(struct ctrl_reg, slot_avail2),
243 SLOT_CONFIG = offsetof(struct ctrl_reg, slot_config), 211 SLOT_CONFIG = offsetof(struct ctrl_reg, slot_config),
244 SEC_BUS_CONFIG = offsetof(struct ctrl_reg, sec_bus_config), 212 SEC_BUS_CONFIG = offsetof(struct ctrl_reg, sec_bus_config),
245 MSI_CTRL = offsetof(struct ctrl_reg, msi_ctrl), 213 MSI_CTRL = offsetof(struct ctrl_reg, msi_ctrl),
246 PROG_INTERFACE = offsetof(struct ctrl_reg, prog_interface), 214 PROG_INTERFACE = offsetof(struct ctrl_reg, prog_interface),
247 CMD = offsetof(struct ctrl_reg, cmd), 215 CMD = offsetof(struct ctrl_reg, cmd),
248 CMD_STATUS = offsetof(struct ctrl_reg, cmd_status), 216 CMD_STATUS = offsetof(struct ctrl_reg, cmd_status),
249 INTR_LOC = offsetof(struct ctrl_reg, intr_loc), 217 INTR_LOC = offsetof(struct ctrl_reg, intr_loc),
250 SERR_LOC = offsetof(struct ctrl_reg, serr_loc), 218 SERR_LOC = offsetof(struct ctrl_reg, serr_loc),
251 SERR_INTR_ENABLE = offsetof(struct ctrl_reg, serr_intr_enable), 219 SERR_INTR_ENABLE = offsetof(struct ctrl_reg, serr_intr_enable),
252 SLOT1 = offsetof(struct ctrl_reg, slot1), 220 SLOT1 = offsetof(struct ctrl_reg, slot1),
253 SLOT2 = offsetof(struct ctrl_reg, slot2),
254 SLOT3 = offsetof(struct ctrl_reg, slot3),
255 SLOT4 = offsetof(struct ctrl_reg, slot4),
256 SLOT5 = offsetof(struct ctrl_reg, slot5),
257 SLOT6 = offsetof(struct ctrl_reg, slot6),
258 SLOT7 = offsetof(struct ctrl_reg, slot7),
259 SLOT8 = offsetof(struct ctrl_reg, slot8),
260 SLOT9 = offsetof(struct ctrl_reg, slot9),
261 SLOT10 = offsetof(struct ctrl_reg, slot10),
262 SLOT11 = offsetof(struct ctrl_reg, slot11),
263 SLOT12 = offsetof(struct ctrl_reg, slot12),
264};
265typedef u8(*php_intr_callback_t) (u8 hp_slot, void *instance_id);
266struct php_ctlr_state_s {
267 struct php_ctlr_state_s *pnext;
268 struct pci_dev *pci_dev;
269 unsigned int irq;
270 unsigned long flags; /* spinlock's */
271 u32 slot_device_offset;
272 u32 num_slots;
273 struct timer_list int_poll_timer; /* Added for poll event */
274 php_intr_callback_t attention_button_callback;
275 php_intr_callback_t switch_change_callback;
276 php_intr_callback_t presence_change_callback;
277 php_intr_callback_t power_fault_callback;
278 void *callback_instance_id;
279 void __iomem *creg; /* Ptr to controller register space */
280}; 221};
281/* Inline functions */
282 222
283 223static inline struct slot *get_slot(struct hotplug_slot *hotplug_slot)
284/* Inline functions to check the sanity of a pointer that is passed to us */
285static inline int slot_paranoia_check (struct slot *slot, const char *function)
286{
287 if (!slot) {
288 dbg("%s - slot == NULL", function);
289 return -1;
290 }
291 if (!slot->hotplug_slot) {
292 dbg("%s - slot->hotplug_slot == NULL!", function);
293 return -1;
294 }
295 return 0;
296}
297
298static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function)
299{ 224{
300 struct slot *slot; 225 return hotplug_slot->private;
301
302 if (!hotplug_slot) {
303 dbg("%s - hotplug_slot == NULL\n", function);
304 return NULL;
305 }
306
307 slot = (struct slot *)hotplug_slot->private;
308 if (slot_paranoia_check (slot, function))
309 return NULL;
310 return slot;
311} 226}
312 227
313static inline struct slot *shpchp_find_slot (struct controller *ctrl, u8 device) 228static inline struct slot *shpchp_find_slot(struct controller *ctrl, u8 device)
314{ 229{
315 struct slot *slot; 230 struct slot *slot;
316 231
317 if (!ctrl)
318 return NULL;
319
320 list_for_each_entry(slot, &ctrl->slot_list, slot_list) { 232 list_for_each_entry(slot, &ctrl->slot_list, slot_list) {
321 if (slot->device == device) 233 if (slot->device == device)
322 return slot; 234 return slot;
323 } 235 }
324 236
325 err("%s: slot (device=0x%x) not found\n", __FUNCTION__, device); 237 err("%s: slot (device=0x%x) not found\n", __FUNCTION__, device);
326
327 return NULL; 238 return NULL;
328} 239}
329 240
@@ -400,44 +311,27 @@ static inline void amd_pogo_errata_restore_misc_reg(struct slot *p_slot)
400 pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, pcix_misc2_temp); 311 pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, pcix_misc2_temp);
401} 312}
402 313
403enum php_ctlr_type {
404 PCI,
405 ISA,
406 ACPI
407};
408
409int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
410
411int shpc_get_ctlr_slot_config( struct controller *ctrl,
412 int *num_ctlr_slots,
413 int *first_device_num,
414 int *physical_slot_num,
415 int *updown,
416 int *flags);
417
418struct hpc_ops { 314struct hpc_ops {
419 int (*power_on_slot ) (struct slot *slot); 315 int (*power_on_slot)(struct slot *slot);
420 int (*slot_enable ) (struct slot *slot); 316 int (*slot_enable)(struct slot *slot);
421 int (*slot_disable ) (struct slot *slot); 317 int (*slot_disable)(struct slot *slot);
422 int (*set_bus_speed_mode) (struct slot *slot, enum pci_bus_speed speed); 318 int (*set_bus_speed_mode)(struct slot *slot, enum pci_bus_speed speed);
423 int (*get_power_status) (struct slot *slot, u8 *status); 319 int (*get_power_status)(struct slot *slot, u8 *status);
424 int (*get_attention_status) (struct slot *slot, u8 *status); 320 int (*get_attention_status)(struct slot *slot, u8 *status);
425 int (*set_attention_status) (struct slot *slot, u8 status); 321 int (*set_attention_status)(struct slot *slot, u8 status);
426 int (*get_latch_status) (struct slot *slot, u8 *status); 322 int (*get_latch_status)(struct slot *slot, u8 *status);
427 int (*get_adapter_status) (struct slot *slot, u8 *status); 323 int (*get_adapter_status)(struct slot *slot, u8 *status);
428 324 int (*get_max_bus_speed)(struct slot *slot, enum pci_bus_speed *speed);
429 int (*get_max_bus_speed) (struct slot *slot, enum pci_bus_speed *speed); 325 int (*get_cur_bus_speed)(struct slot *slot, enum pci_bus_speed *speed);
430 int (*get_cur_bus_speed) (struct slot *slot, enum pci_bus_speed *speed); 326 int (*get_adapter_speed)(struct slot *slot, enum pci_bus_speed *speed);
431 int (*get_adapter_speed) (struct slot *slot, enum pci_bus_speed *speed); 327 int (*get_mode1_ECC_cap)(struct slot *slot, u8 *mode);
432 int (*get_mode1_ECC_cap) (struct slot *slot, u8 *mode); 328 int (*get_prog_int)(struct slot *slot, u8 *prog_int);
433 int (*get_prog_int) (struct slot *slot, u8 *prog_int); 329 int (*query_power_fault)(struct slot *slot);
434 330 void (*green_led_on)(struct slot *slot);
435 int (*query_power_fault) (struct slot *slot); 331 void (*green_led_off)(struct slot *slot);
436 void (*green_led_on) (struct slot *slot); 332 void (*green_led_blink)(struct slot *slot);
437 void (*green_led_off) (struct slot *slot); 333 void (*release_ctlr)(struct controller *ctrl);
438 void (*green_led_blink) (struct slot *slot); 334 int (*check_cmd_status)(struct controller *ctrl);
439 void (*release_ctlr) (struct controller *ctrl);
440 int (*check_cmd_status) (struct controller *ctrl);
441}; 335};
442 336
443#endif /* _SHPCHP_H */ 337#endif /* _SHPCHP_H */
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index 4eac85b3d9..590cd3cbe0 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -104,23 +104,6 @@ static void make_slot_name(struct slot *slot)
104 slot->bus, slot->number); 104 slot->bus, slot->number);
105} 105}
106 106
107
108
109
110static int
111shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun,
112 u8 busnum, u8 devnum)
113{
114 int offset = devnum - ctrl->slot_device_offset;
115
116 dbg("%s: ctrl->slot_num_inc %d, offset %d\n", __FUNCTION__,
117 ctrl->slot_num_inc, offset);
118 *sun = (u8) (ctrl->first_slot + ctrl->slot_num_inc *offset);
119 return 0;
120}
121
122
123
124static int init_slots(struct controller *ctrl) 107static int init_slots(struct controller *ctrl)
125{ 108{
126 struct slot *slot; 109 struct slot *slot;
@@ -128,7 +111,6 @@ static int init_slots(struct controller *ctrl)
128 struct hotplug_slot_info *info; 111 struct hotplug_slot_info *info;
129 int retval = -ENOMEM; 112 int retval = -ENOMEM;
130 int i; 113 int i;
131 u32 sun;
132 114
133 for (i = 0; i < ctrl->num_slots; i++) { 115 for (i = 0; i < ctrl->num_slots; i++) {
134 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 116 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
@@ -149,16 +131,11 @@ static int init_slots(struct controller *ctrl)
149 131
150 slot->hp_slot = i; 132 slot->hp_slot = i;
151 slot->ctrl = ctrl; 133 slot->ctrl = ctrl;
152 slot->bus = ctrl->slot_bus; 134 slot->bus = ctrl->pci_dev->subordinate->number;
153 slot->device = ctrl->slot_device_offset + i; 135 slot->device = ctrl->slot_device_offset + i;
154 slot->hpc_ops = ctrl->hpc_ops; 136 slot->hpc_ops = ctrl->hpc_ops;
137 slot->number = ctrl->first_slot + (ctrl->slot_num_inc * i);
155 mutex_init(&slot->lock); 138 mutex_init(&slot->lock);
156
157 if (shpchprm_get_physical_slot_number(ctrl, &sun,
158 slot->bus, slot->device))
159 goto error_info;
160
161 slot->number = sun;
162 INIT_DELAYED_WORK(&slot->work, queue_pushbutton_work); 139 INIT_DELAYED_WORK(&slot->work, queue_pushbutton_work);
163 140
164 /* register this slot with the hotplug pci core */ 141 /* register this slot with the hotplug pci core */
@@ -211,42 +188,12 @@ void cleanup_slots(struct controller *ctrl)
211 } 188 }
212} 189}
213 190
214static int get_ctlr_slot_config(struct controller *ctrl)
215{
216 int num_ctlr_slots;
217 int first_device_num;
218 int physical_slot_num;
219 int updown;
220 int rc;
221 int flags;
222
223 rc = shpc_get_ctlr_slot_config(ctrl, &num_ctlr_slots,
224 &first_device_num, &physical_slot_num,
225 &updown, &flags);
226 if (rc) {
227 err("%s: get_ctlr_slot_config fail for b:d (%x:%x)\n",
228 __FUNCTION__, ctrl->bus, ctrl->device);
229 return -1;
230 }
231
232 ctrl->num_slots = num_ctlr_slots;
233 ctrl->slot_device_offset = first_device_num;
234 ctrl->first_slot = physical_slot_num;
235 ctrl->slot_num_inc = updown; /* either -1 or 1 */
236
237 dbg("%s: num_slot(0x%x) 1st_dev(0x%x) psn(0x%x) updown(%d) for b:d "
238 "(%x:%x)\n", __FUNCTION__, num_ctlr_slots, first_device_num,
239 physical_slot_num, updown, ctrl->bus, ctrl->device);
240
241 return 0;
242}
243
244/* 191/*
245 * set_attention_status - Turns the Amber LED for a slot on, off or blink 192 * set_attention_status - Turns the Amber LED for a slot on, off or blink
246 */ 193 */
247static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status) 194static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
248{ 195{
249 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 196 struct slot *slot = get_slot(hotplug_slot);
250 197
251 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 198 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
252 199
@@ -258,7 +205,7 @@ static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
258 205
259static int enable_slot (struct hotplug_slot *hotplug_slot) 206static int enable_slot (struct hotplug_slot *hotplug_slot)
260{ 207{
261 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 208 struct slot *slot = get_slot(hotplug_slot);
262 209
263 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 210 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
264 211
@@ -267,7 +214,7 @@ static int enable_slot (struct hotplug_slot *hotplug_slot)
267 214
268static int disable_slot (struct hotplug_slot *hotplug_slot) 215static int disable_slot (struct hotplug_slot *hotplug_slot)
269{ 216{
270 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 217 struct slot *slot = get_slot(hotplug_slot);
271 218
272 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 219 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
273 220
@@ -276,7 +223,7 @@ static int disable_slot (struct hotplug_slot *hotplug_slot)
276 223
277static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value) 224static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
278{ 225{
279 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 226 struct slot *slot = get_slot(hotplug_slot);
280 int retval; 227 int retval;
281 228
282 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 229 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -290,7 +237,7 @@ static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
290 237
291static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value) 238static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
292{ 239{
293 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 240 struct slot *slot = get_slot(hotplug_slot);
294 int retval; 241 int retval;
295 242
296 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 243 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -304,7 +251,7 @@ static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
304 251
305static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value) 252static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
306{ 253{
307 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 254 struct slot *slot = get_slot(hotplug_slot);
308 int retval; 255 int retval;
309 256
310 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 257 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -318,7 +265,7 @@ static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
318 265
319static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value) 266static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
320{ 267{
321 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 268 struct slot *slot = get_slot(hotplug_slot);
322 int retval; 269 int retval;
323 270
324 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 271 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -332,7 +279,7 @@ static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
332 279
333static int get_address (struct hotplug_slot *hotplug_slot, u32 *value) 280static int get_address (struct hotplug_slot *hotplug_slot, u32 *value)
334{ 281{
335 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 282 struct slot *slot = get_slot(hotplug_slot);
336 struct pci_bus *bus = slot->ctrl->pci_dev->subordinate; 283 struct pci_bus *bus = slot->ctrl->pci_dev->subordinate;
337 284
338 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 285 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -344,7 +291,7 @@ static int get_address (struct hotplug_slot *hotplug_slot, u32 *value)
344 291
345static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 292static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
346{ 293{
347 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 294 struct slot *slot = get_slot(hotplug_slot);
348 int retval; 295 int retval;
349 296
350 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 297 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -358,7 +305,7 @@ static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
358 305
359static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 306static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
360{ 307{
361 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 308 struct slot *slot = get_slot(hotplug_slot);
362 int retval; 309 int retval;
363 310
364 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 311 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -385,9 +332,6 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
385{ 332{
386 int rc; 333 int rc;
387 struct controller *ctrl; 334 struct controller *ctrl;
388 struct slot *t_slot;
389 int first_device_num; /* first PCI device number */
390 int num_ctlr_slots; /* number of slots implemented */
391 335
392 if (!is_shpc_capable(pdev)) 336 if (!is_shpc_capable(pdev))
393 return -ENODEV; 337 return -ENODEV;
@@ -408,47 +352,13 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
408 352
409 pci_set_drvdata(pdev, ctrl); 353 pci_set_drvdata(pdev, ctrl);
410 354
411 ctrl->bus = pdev->bus->number;
412 ctrl->slot_bus = pdev->subordinate->number;
413 ctrl->device = PCI_SLOT(pdev->devfn);
414 ctrl->function = PCI_FUNC(pdev->devfn);
415
416 dbg("ctrl bus=0x%x, device=%x, function=%x, irq=%x\n",
417 ctrl->bus, ctrl->device, ctrl->function, pdev->irq);
418
419 /*
420 * Save configuration headers for this and subordinate PCI buses
421 */
422 rc = get_ctlr_slot_config(ctrl);
423 if (rc) {
424 err(msg_initialization_err, rc);
425 goto err_out_release_ctlr;
426 }
427 first_device_num = ctrl->slot_device_offset;
428 num_ctlr_slots = ctrl->num_slots;
429
430 ctrl->add_support = 1;
431
432 /* Setup the slot information structures */ 355 /* Setup the slot information structures */
433 rc = init_slots(ctrl); 356 rc = init_slots(ctrl);
434 if (rc) { 357 if (rc) {
435 err(msg_initialization_err, 6); 358 err("%s: slot initialization failed\n", SHPC_MODULE_NAME);
436 goto err_out_release_ctlr; 359 goto err_out_release_ctlr;
437 } 360 }
438 361
439 /* Now hpc_functions (slot->hpc_ops->functions) are ready */
440 t_slot = shpchp_find_slot(ctrl, first_device_num);
441
442 /* Check for operation bus speed */
443 rc = t_slot->hpc_ops->get_cur_bus_speed(t_slot, &ctrl->speed);
444 dbg("%s: t_slot->hp_slot %x\n", __FUNCTION__,t_slot->hp_slot);
445
446 if (rc || ctrl->speed == PCI_SPEED_UNKNOWN) {
447 err(SHPC_MODULE_NAME ": Can't get current bus speed. "
448 "Set to 33MHz PCI.\n");
449 ctrl->speed = PCI_SPEED_33MHz;
450 }
451
452 rc = shpchp_create_ctrl_files(ctrl); 362 rc = shpchp_create_ctrl_files(ctrl);
453 if (rc) 363 if (rc)
454 goto err_cleanup_slots; 364 goto err_cleanup_slots;
diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c
index 158ac78360..6bb84734cd 100644
--- a/drivers/pci/hotplug/shpchp_ctrl.c
+++ b/drivers/pci/hotplug/shpchp_ctrl.c
@@ -57,9 +57,8 @@ static int queue_interrupt_event(struct slot *p_slot, u32 event_type)
57 return 0; 57 return 0;
58} 58}
59 59
60u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id) 60u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl)
61{ 61{
62 struct controller *ctrl = (struct controller *) inst_id;
63 struct slot *p_slot; 62 struct slot *p_slot;
64 u32 event_type; 63 u32 event_type;
65 64
@@ -81,9 +80,8 @@ u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id)
81 80
82} 81}
83 82
84u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id) 83u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl)
85{ 84{
86 struct controller *ctrl = (struct controller *) inst_id;
87 struct slot *p_slot; 85 struct slot *p_slot;
88 u8 getstatus; 86 u8 getstatus;
89 u32 event_type; 87 u32 event_type;
@@ -120,9 +118,8 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
120 return 1; 118 return 1;
121} 119}
122 120
123u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id) 121u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl)
124{ 122{
125 struct controller *ctrl = (struct controller *) inst_id;
126 struct slot *p_slot; 123 struct slot *p_slot;
127 u32 event_type; 124 u32 event_type;
128 125
@@ -154,9 +151,8 @@ u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id)
154 return 1; 151 return 1;
155} 152}
156 153
157u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id) 154u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl)
158{ 155{
159 struct controller *ctrl = (struct controller *) inst_id;
160 struct slot *p_slot; 156 struct slot *p_slot;
161 u32 event_type; 157 u32 event_type;
162 158
@@ -497,10 +493,12 @@ static void handle_button_press_event(struct slot *p_slot)
497 p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 493 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
498 if (getstatus) { 494 if (getstatus) {
499 p_slot->state = BLINKINGOFF_STATE; 495 p_slot->state = BLINKINGOFF_STATE;
500 info(msg_button_off, p_slot->name); 496 info("PCI slot #%s - powering off due to button "
497 "press.\n", p_slot->name);
501 } else { 498 } else {
502 p_slot->state = BLINKINGON_STATE; 499 p_slot->state = BLINKINGON_STATE;
503 info(msg_button_on, p_slot->name); 500 info("PCI slot #%s - powering on due to button "
501 "press.\n", p_slot->name);
504 } 502 }
505 /* blink green LED and turn off amber */ 503 /* blink green LED and turn off amber */
506 p_slot->hpc_ops->green_led_blink(p_slot); 504 p_slot->hpc_ops->green_led_blink(p_slot);
@@ -523,7 +521,8 @@ static void handle_button_press_event(struct slot *p_slot)
523 else 521 else
524 p_slot->hpc_ops->green_led_off(p_slot); 522 p_slot->hpc_ops->green_led_off(p_slot);
525 p_slot->hpc_ops->set_attention_status(p_slot, 0); 523 p_slot->hpc_ops->set_attention_status(p_slot, 0);
526 info(msg_button_cancel, p_slot->name); 524 info("PCI slot #%s - action canceled due to button press\n",
525 p_slot->name);
527 p_slot->state = STATIC_STATE; 526 p_slot->state = STATIC_STATE;
528 break; 527 break;
529 case POWEROFF_STATE: 528 case POWEROFF_STATE:
diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c
index 83a5226ba9..b7bede4b7c 100644
--- a/drivers/pci/hotplug/shpchp_hpc.c
+++ b/drivers/pci/hotplug/shpchp_hpc.c
@@ -212,44 +212,40 @@
212#define SLOT_SERR_INT_MASK 0x3 212#define SLOT_SERR_INT_MASK 0x3
213 213
214DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */ 214DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
215static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */
216static int ctlr_seq_num = 0; /* Controller sequenc # */
217static spinlock_t list_lock;
218
219static atomic_t shpchp_num_controllers = ATOMIC_INIT(0); 215static atomic_t shpchp_num_controllers = ATOMIC_INIT(0);
220 216
221static irqreturn_t shpc_isr(int irq, void *dev_id); 217static irqreturn_t shpc_isr(int irq, void *dev_id);
222static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec); 218static void start_int_poll_timer(struct controller *ctrl, int sec);
223static int hpc_check_cmd_status(struct controller *ctrl); 219static int hpc_check_cmd_status(struct controller *ctrl);
224 220
225static inline u8 shpc_readb(struct controller *ctrl, int reg) 221static inline u8 shpc_readb(struct controller *ctrl, int reg)
226{ 222{
227 return readb(ctrl->hpc_ctlr_handle->creg + reg); 223 return readb(ctrl->creg + reg);
228} 224}
229 225
230static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val) 226static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val)
231{ 227{
232 writeb(val, ctrl->hpc_ctlr_handle->creg + reg); 228 writeb(val, ctrl->creg + reg);
233} 229}
234 230
235static inline u16 shpc_readw(struct controller *ctrl, int reg) 231static inline u16 shpc_readw(struct controller *ctrl, int reg)
236{ 232{
237 return readw(ctrl->hpc_ctlr_handle->creg + reg); 233 return readw(ctrl->creg + reg);
238} 234}
239 235
240static inline void shpc_writew(struct controller *ctrl, int reg, u16 val) 236static inline void shpc_writew(struct controller *ctrl, int reg, u16 val)
241{ 237{
242 writew(val, ctrl->hpc_ctlr_handle->creg + reg); 238 writew(val, ctrl->creg + reg);
243} 239}
244 240
245static inline u32 shpc_readl(struct controller *ctrl, int reg) 241static inline u32 shpc_readl(struct controller *ctrl, int reg)
246{ 242{
247 return readl(ctrl->hpc_ctlr_handle->creg + reg); 243 return readl(ctrl->creg + reg);
248} 244}
249 245
250static inline void shpc_writel(struct controller *ctrl, int reg, u32 val) 246static inline void shpc_writel(struct controller *ctrl, int reg, u32 val)
251{ 247{
252 writel(val, ctrl->hpc_ctlr_handle->creg + reg); 248 writel(val, ctrl->creg + reg);
253} 249}
254 250
255static inline int shpc_indirect_read(struct controller *ctrl, int index, 251static inline int shpc_indirect_read(struct controller *ctrl, int index,
@@ -268,21 +264,20 @@ static inline int shpc_indirect_read(struct controller *ctrl, int index,
268/* 264/*
269 * This is the interrupt polling timeout function. 265 * This is the interrupt polling timeout function.
270 */ 266 */
271static void int_poll_timeout(unsigned long lphp_ctlr) 267static void int_poll_timeout(unsigned long data)
272{ 268{
273 struct php_ctlr_state_s *php_ctlr = 269 struct controller *ctrl = (struct controller *)data;
274 (struct php_ctlr_state_s *)lphp_ctlr;
275 270
276 DBG_ENTER_ROUTINE 271 DBG_ENTER_ROUTINE
277 272
278 /* Poll for interrupt events. regs == NULL => polling */ 273 /* Poll for interrupt events. regs == NULL => polling */
279 shpc_isr(0, php_ctlr->callback_instance_id); 274 shpc_isr(0, ctrl);
280 275
281 init_timer(&php_ctlr->int_poll_timer); 276 init_timer(&ctrl->poll_timer);
282 if (!shpchp_poll_time) 277 if (!shpchp_poll_time)
283 shpchp_poll_time = 2; /* default polling interval is 2 sec */ 278 shpchp_poll_time = 2; /* default polling interval is 2 sec */
284 279
285 start_int_poll_timer(php_ctlr, shpchp_poll_time); 280 start_int_poll_timer(ctrl, shpchp_poll_time);
286 281
287 DBG_LEAVE_ROUTINE 282 DBG_LEAVE_ROUTINE
288} 283}
@@ -290,16 +285,16 @@ static void int_poll_timeout(unsigned long lphp_ctlr)
290/* 285/*
291 * This function starts the interrupt polling timer. 286 * This function starts the interrupt polling timer.
292 */ 287 */
293static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec) 288static void start_int_poll_timer(struct controller *ctrl, int sec)
294{ 289{
295 /* Clamp to sane value */ 290 /* Clamp to sane value */
296 if ((sec <= 0) || (sec > 60)) 291 if ((sec <= 0) || (sec > 60))
297 sec = 2; 292 sec = 2;
298 293
299 php_ctlr->int_poll_timer.function = &int_poll_timeout; 294 ctrl->poll_timer.function = &int_poll_timeout;
300 php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr; 295 ctrl->poll_timer.data = (unsigned long)ctrl;
301 php_ctlr->int_poll_timer.expires = jiffies + sec * HZ; 296 ctrl->poll_timer.expires = jiffies + sec * HZ;
302 add_timer(&php_ctlr->int_poll_timer); 297 add_timer(&ctrl->poll_timer);
303} 298}
304 299
305static inline int is_ctrl_busy(struct controller *ctrl) 300static inline int is_ctrl_busy(struct controller *ctrl)
@@ -666,33 +661,8 @@ static void hpc_set_green_led_blink(struct slot *slot)
666 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK); 661 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK);
667} 662}
668 663
669int shpc_get_ctlr_slot_config(struct controller *ctrl,
670 int *num_ctlr_slots, /* number of slots in this HPC */
671 int *first_device_num, /* PCI dev num of the first slot in this SHPC */
672 int *physical_slot_num, /* phy slot num of the first slot in this SHPC */
673 int *updown, /* physical_slot_num increament: 1 or -1 */
674 int *flags)
675{
676 u32 slot_config;
677
678 DBG_ENTER_ROUTINE
679
680 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
681 *first_device_num = (slot_config & FIRST_DEV_NUM) >> 8;
682 *num_ctlr_slots = slot_config & SLOT_NUM;
683 *physical_slot_num = (slot_config & PSN) >> 16;
684 *updown = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
685
686 dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num);
687
688 DBG_LEAVE_ROUTINE
689 return 0;
690}
691
692static void hpc_release_ctlr(struct controller *ctrl) 664static void hpc_release_ctlr(struct controller *ctrl)
693{ 665{
694 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
695 struct php_ctlr_state_s *p, *p_prev;
696 int i; 666 int i;
697 u32 slot_reg, serr_int; 667 u32 slot_reg, serr_int;
698 668
@@ -722,40 +692,15 @@ static void hpc_release_ctlr(struct controller *ctrl)
722 serr_int &= ~SERR_INTR_RSVDZ_MASK; 692 serr_int &= ~SERR_INTR_RSVDZ_MASK;
723 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); 693 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
724 694
725 if (shpchp_poll_mode) { 695 if (shpchp_poll_mode)
726 del_timer(&php_ctlr->int_poll_timer); 696 del_timer(&ctrl->poll_timer);
727 } else { 697 else {
728 if (php_ctlr->irq) { 698 free_irq(ctrl->pci_dev->irq, ctrl);
729 free_irq(php_ctlr->irq, ctrl); 699 pci_disable_msi(ctrl->pci_dev);
730 php_ctlr->irq = 0;
731 pci_disable_msi(php_ctlr->pci_dev);
732 }
733 }
734
735 if (php_ctlr->pci_dev) {
736 iounmap(php_ctlr->creg);
737 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
738 php_ctlr->pci_dev = NULL;
739 }
740
741 spin_lock(&list_lock);
742 p = php_ctlr_list_head;
743 p_prev = NULL;
744 while (p) {
745 if (p == php_ctlr) {
746 if (p_prev)
747 p_prev->pnext = p->pnext;
748 else
749 php_ctlr_list_head = p->pnext;
750 break;
751 } else {
752 p_prev = p;
753 p = p->pnext;
754 }
755 } 700 }
756 spin_unlock(&list_lock);
757 701
758 kfree(php_ctlr); 702 iounmap(ctrl->creg);
703 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
759 704
760 /* 705 /*
761 * If this is the last controller to be released, destroy the 706 * If this is the last controller to be released, destroy the
@@ -764,8 +709,7 @@ static void hpc_release_ctlr(struct controller *ctrl)
764 if (atomic_dec_and_test(&shpchp_num_controllers)) 709 if (atomic_dec_and_test(&shpchp_num_controllers))
765 destroy_workqueue(shpchp_wq); 710 destroy_workqueue(shpchp_wq);
766 711
767DBG_LEAVE_ROUTINE 712 DBG_LEAVE_ROUTINE
768
769} 713}
770 714
771static int hpc_power_on_slot(struct slot * slot) 715static int hpc_power_on_slot(struct slot * slot)
@@ -891,7 +835,6 @@ static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
891static irqreturn_t shpc_isr(int irq, void *dev_id) 835static irqreturn_t shpc_isr(int irq, void *dev_id)
892{ 836{
893 struct controller *ctrl = (struct controller *)dev_id; 837 struct controller *ctrl = (struct controller *)dev_id;
894 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
895 u32 serr_int, slot_reg, intr_loc, intr_loc2; 838 u32 serr_int, slot_reg, intr_loc, intr_loc2;
896 int hp_slot; 839 int hp_slot;
897 840
@@ -942,20 +885,16 @@ static irqreturn_t shpc_isr(int irq, void *dev_id)
942 __FUNCTION__, hp_slot, slot_reg); 885 __FUNCTION__, hp_slot, slot_reg);
943 886
944 if (slot_reg & MRL_CHANGE_DETECTED) 887 if (slot_reg & MRL_CHANGE_DETECTED)
945 php_ctlr->switch_change_callback( 888 shpchp_handle_switch_change(hp_slot, ctrl);
946 hp_slot, php_ctlr->callback_instance_id);
947 889
948 if (slot_reg & BUTTON_PRESS_DETECTED) 890 if (slot_reg & BUTTON_PRESS_DETECTED)
949 php_ctlr->attention_button_callback( 891 shpchp_handle_attention_button(hp_slot, ctrl);
950 hp_slot, php_ctlr->callback_instance_id);
951 892
952 if (slot_reg & PRSNT_CHANGE_DETECTED) 893 if (slot_reg & PRSNT_CHANGE_DETECTED)
953 php_ctlr->presence_change_callback( 894 shpchp_handle_presence_change(hp_slot, ctrl);
954 hp_slot , php_ctlr->callback_instance_id);
955 895
956 if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED)) 896 if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED))
957 php_ctlr->power_fault_callback( 897 shpchp_handle_power_fault(hp_slot, ctrl);
958 hp_slot, php_ctlr->callback_instance_id);
959 898
960 /* Clear all slot events */ 899 /* Clear all slot events */
961 slot_reg &= ~SLOT_REG_RSVDZ_MASK; 900 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
@@ -1114,10 +1053,8 @@ static struct hpc_ops shpchp_hpc_ops = {
1114 .release_ctlr = hpc_release_ctlr, 1053 .release_ctlr = hpc_release_ctlr,
1115}; 1054};
1116 1055
1117int shpc_init(struct controller * ctrl, struct pci_dev * pdev) 1056int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
1118{ 1057{
1119 struct php_ctlr_state_s *php_ctlr, *p;
1120 void *instance_id = ctrl;
1121 int rc = -1, num_slots = 0; 1058 int rc = -1, num_slots = 0;
1122 u8 hp_slot; 1059 u8 hp_slot;
1123 u32 shpc_base_offset; 1060 u32 shpc_base_offset;
@@ -1128,16 +1065,6 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1128 1065
1129 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */ 1066 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
1130 1067
1131 spin_lock_init(&list_lock);
1132 php_ctlr = kzalloc(sizeof(*php_ctlr), GFP_KERNEL);
1133
1134 if (!php_ctlr) { /* allocate controller state data */
1135 err("%s: HPC controller memory allocation error!\n", __FUNCTION__);
1136 goto abort;
1137 }
1138
1139 php_ctlr->pci_dev = pdev; /* save pci_dev in context */
1140
1141 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device == 1068 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
1142 PCI_DEVICE_ID_AMD_GOLAM_7450)) { 1069 PCI_DEVICE_ID_AMD_GOLAM_7450)) {
1143 /* amd shpc driver doesn't use Base Offset; assume 0 */ 1070 /* amd shpc driver doesn't use Base Offset; assume 0 */
@@ -1147,20 +1074,20 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1147 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC); 1074 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
1148 if (!ctrl->cap_offset) { 1075 if (!ctrl->cap_offset) {
1149 err("%s : cap_offset == 0\n", __FUNCTION__); 1076 err("%s : cap_offset == 0\n", __FUNCTION__);
1150 goto abort_free_ctlr; 1077 goto abort;
1151 } 1078 }
1152 dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset); 1079 dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
1153 1080
1154 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset); 1081 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
1155 if (rc) { 1082 if (rc) {
1156 err("%s: cannot read base_offset\n", __FUNCTION__); 1083 err("%s: cannot read base_offset\n", __FUNCTION__);
1157 goto abort_free_ctlr; 1084 goto abort;
1158 } 1085 }
1159 1086
1160 rc = shpc_indirect_read(ctrl, 3, &tempdword); 1087 rc = shpc_indirect_read(ctrl, 3, &tempdword);
1161 if (rc) { 1088 if (rc) {
1162 err("%s: cannot read slot config\n", __FUNCTION__); 1089 err("%s: cannot read slot config\n", __FUNCTION__);
1163 goto abort_free_ctlr; 1090 goto abort;
1164 } 1091 }
1165 num_slots = tempdword & SLOT_NUM; 1092 num_slots = tempdword & SLOT_NUM;
1166 dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots); 1093 dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
@@ -1170,7 +1097,7 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1170 if (rc) { 1097 if (rc) {
1171 err("%s: cannot read creg (index = %d)\n", 1098 err("%s: cannot read creg (index = %d)\n",
1172 __FUNCTION__, i); 1099 __FUNCTION__, i);
1173 goto abort_free_ctlr; 1100 goto abort;
1174 } 1101 }
1175 dbg("%s: offset %d: value %x\n", __FUNCTION__,i, 1102 dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
1176 tempdword); 1103 tempdword);
@@ -1187,24 +1114,24 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1187 rc = pci_enable_device(pdev); 1114 rc = pci_enable_device(pdev);
1188 if (rc) { 1115 if (rc) {
1189 err("%s: pci_enable_device failed\n", __FUNCTION__); 1116 err("%s: pci_enable_device failed\n", __FUNCTION__);
1190 goto abort_free_ctlr; 1117 goto abort;
1191 } 1118 }
1192 1119
1193 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) { 1120 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
1194 err("%s: cannot reserve MMIO region\n", __FUNCTION__); 1121 err("%s: cannot reserve MMIO region\n", __FUNCTION__);
1195 rc = -1; 1122 rc = -1;
1196 goto abort_free_ctlr; 1123 goto abort;
1197 } 1124 }
1198 1125
1199 php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size); 1126 ctrl->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
1200 if (!php_ctlr->creg) { 1127 if (!ctrl->creg) {
1201 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__, 1128 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
1202 ctrl->mmio_size, ctrl->mmio_base); 1129 ctrl->mmio_size, ctrl->mmio_base);
1203 release_mem_region(ctrl->mmio_base, ctrl->mmio_size); 1130 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
1204 rc = -1; 1131 rc = -1;
1205 goto abort_free_ctlr; 1132 goto abort;
1206 } 1133 }
1207 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg); 1134 dbg("%s: ctrl->creg %p\n", __FUNCTION__, ctrl->creg);
1208 1135
1209 mutex_init(&ctrl->crit_sect); 1136 mutex_init(&ctrl->crit_sect);
1210 mutex_init(&ctrl->cmd_lock); 1137 mutex_init(&ctrl->cmd_lock);
@@ -1212,23 +1139,14 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1212 /* Setup wait queue */ 1139 /* Setup wait queue */
1213 init_waitqueue_head(&ctrl->queue); 1140 init_waitqueue_head(&ctrl->queue);
1214 1141
1215 /* Find the IRQ */
1216 php_ctlr->irq = pdev->irq;
1217 php_ctlr->attention_button_callback = shpchp_handle_attention_button,
1218 php_ctlr->switch_change_callback = shpchp_handle_switch_change;
1219 php_ctlr->presence_change_callback = shpchp_handle_presence_change;
1220 php_ctlr->power_fault_callback = shpchp_handle_power_fault;
1221 php_ctlr->callback_instance_id = instance_id;
1222
1223 ctrl->hpc_ctlr_handle = php_ctlr;
1224 ctrl->hpc_ops = &shpchp_hpc_ops; 1142 ctrl->hpc_ops = &shpchp_hpc_ops;
1225 1143
1226 /* Return PCI Controller Info */ 1144 /* Return PCI Controller Info */
1227 slot_config = shpc_readl(ctrl, SLOT_CONFIG); 1145 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
1228 php_ctlr->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8; 1146 ctrl->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8;
1229 php_ctlr->num_slots = slot_config & SLOT_NUM; 1147 ctrl->num_slots = slot_config & SLOT_NUM;
1230 dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset); 1148 ctrl->first_slot = (slot_config & PSN) >> 16;
1231 dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots); 1149 ctrl->slot_num_inc = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
1232 1150
1233 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */ 1151 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
1234 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); 1152 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
@@ -1243,7 +1161,7 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1243 /* Mask the MRL sensor SERR Mask of individual slot in 1161 /* Mask the MRL sensor SERR Mask of individual slot in
1244 * Slot SERR-INT Mask & clear all the existing event if any 1162 * Slot SERR-INT Mask & clear all the existing event if any
1245 */ 1163 */
1246 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) { 1164 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
1247 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); 1165 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
1248 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__, 1166 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1249 hp_slot, slot_reg); 1167 hp_slot, slot_reg);
@@ -1255,24 +1173,27 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1255 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); 1173 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
1256 } 1174 }
1257 1175
1258 if (shpchp_poll_mode) {/* Install interrupt polling code */ 1176 if (shpchp_poll_mode) {
1259 /* Install and start the interrupt polling timer */ 1177 /* Install interrupt polling timer. Start with 10 sec delay */
1260 init_timer(&php_ctlr->int_poll_timer); 1178 init_timer(&ctrl->poll_timer);
1261 start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */ 1179 start_int_poll_timer(ctrl, 10);
1262 } else { 1180 } else {
1263 /* Installs the interrupt handler */ 1181 /* Installs the interrupt handler */
1264 rc = pci_enable_msi(pdev); 1182 rc = pci_enable_msi(pdev);
1265 if (rc) { 1183 if (rc) {
1266 info("Can't get msi for the hotplug controller\n"); 1184 info("Can't get msi for the hotplug controller\n");
1267 info("Use INTx for the hotplug controller\n"); 1185 info("Use INTx for the hotplug controller\n");
1268 } else 1186 }
1269 php_ctlr->irq = pdev->irq;
1270 1187
1271 rc = request_irq(php_ctlr->irq, shpc_isr, IRQF_SHARED, MY_NAME, (void *) ctrl); 1188 rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED,
1272 dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc); 1189 MY_NAME, (void *)ctrl);
1190 dbg("%s: request_irq %d for hpc%d (returns %d)\n",
1191 __FUNCTION__, ctrl->pci_dev->irq,
1192 atomic_read(&shpchp_num_controllers), rc);
1273 if (rc) { 1193 if (rc) {
1274 err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq); 1194 err("Can't get irq %d for the hotplug controller\n",
1275 goto abort_free_ctlr; 1195 ctrl->pci_dev->irq);
1196 goto abort_iounmap;
1276 } 1197 }
1277 } 1198 }
1278 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__, 1199 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
@@ -1280,24 +1201,6 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1280 PCI_FUNC(pdev->devfn), pdev->irq); 1201 PCI_FUNC(pdev->devfn), pdev->irq);
1281 get_hp_hw_control_from_firmware(pdev); 1202 get_hp_hw_control_from_firmware(pdev);
1282 1203
1283 /* Add this HPC instance into the HPC list */
1284 spin_lock(&list_lock);
1285 if (php_ctlr_list_head == 0) {
1286 php_ctlr_list_head = php_ctlr;
1287 p = php_ctlr_list_head;
1288 p->pnext = NULL;
1289 } else {
1290 p = php_ctlr_list_head;
1291
1292 while (p->pnext)
1293 p = p->pnext;
1294
1295 p->pnext = php_ctlr;
1296 }
1297 spin_unlock(&list_lock);
1298
1299 ctlr_seq_num++;
1300
1301 /* 1204 /*
1302 * If this is the first controller to be initialized, 1205 * If this is the first controller to be initialized,
1303 * initialize the shpchpd work queue 1206 * initialize the shpchpd work queue
@@ -1306,14 +1209,14 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1306 shpchp_wq = create_singlethread_workqueue("shpchpd"); 1209 shpchp_wq = create_singlethread_workqueue("shpchpd");
1307 if (!shpchp_wq) { 1210 if (!shpchp_wq) {
1308 rc = -ENOMEM; 1211 rc = -ENOMEM;
1309 goto abort_free_ctlr; 1212 goto abort_iounmap;
1310 } 1213 }
1311 } 1214 }
1312 1215
1313 /* 1216 /*
1314 * Unmask all event interrupts of all slots 1217 * Unmask all event interrupts of all slots
1315 */ 1218 */
1316 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) { 1219 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
1317 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); 1220 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
1318 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__, 1221 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1319 hp_slot, slot_reg); 1222 hp_slot, slot_reg);
@@ -1336,10 +1239,8 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1336 return 0; 1239 return 0;
1337 1240
1338 /* We end up here for the many possible ways to fail this API. */ 1241 /* We end up here for the many possible ways to fail this API. */
1339abort_free_ctlr: 1242abort_iounmap:
1340 if (php_ctlr->creg) 1243 iounmap(ctrl->creg);
1341 iounmap(php_ctlr->creg);
1342 kfree(php_ctlr);
1343abort: 1244abort:
1344 DBG_LEAVE_ROUTINE 1245 DBG_LEAVE_ROUTINE
1345 return rc; 1246 return rc;
diff --git a/drivers/pci/htirq.c b/drivers/pci/htirq.c
index 0a8d1cce9f..279c940a00 100644
--- a/drivers/pci/htirq.c
+++ b/drivers/pci/htirq.c
@@ -99,14 +99,7 @@ int __ht_create_irq(struct pci_dev *dev, int idx, ht_irq_update_t *update)
99 int pos; 99 int pos;
100 int irq; 100 int irq;
101 101
102 pos = pci_find_capability(dev, PCI_CAP_ID_HT); 102 pos = pci_find_ht_capability(dev, HT_CAPTYPE_IRQ);
103 while (pos) {
104 u8 subtype;
105 pci_read_config_byte(dev, pos + 3, &subtype);
106 if (subtype == HT_CAPTYPE_IRQ)
107 break;
108 pos = pci_find_next_capability(dev, pos, PCI_CAP_ID_HT);
109 }
110 if (!pos) 103 if (!pos)
111 return -EINVAL; 104 return -EINVAL;
112 105
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index e5ae3a0c13..92d5e8db0d 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -150,8 +150,7 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
150} 150}
151 151
152/** 152/**
153 * pci_match_device - Tell if a PCI device structure has a matching 153 * pci_match_device - Tell if a PCI device structure has a matching PCI device id structure
154 * PCI device id structure
155 * @drv: the PCI driver to match against 154 * @drv: the PCI driver to match against
156 * @dev: the PCI device structure to match against 155 * @dev: the PCI device structure to match against
157 * 156 *
@@ -162,14 +161,9 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
162const struct pci_device_id *pci_match_device(struct pci_driver *drv, 161const struct pci_device_id *pci_match_device(struct pci_driver *drv,
163 struct pci_dev *dev) 162 struct pci_dev *dev)
164{ 163{
165 const struct pci_device_id *id;
166 struct pci_dynid *dynid; 164 struct pci_dynid *dynid;
167 165
168 id = pci_match_id(drv->id_table, dev); 166 /* Look at the dynamic ids first, before the static ones */
169 if (id)
170 return id;
171
172 /* static ids didn't match, lets look at the dynamic ones */
173 spin_lock(&drv->dynids.lock); 167 spin_lock(&drv->dynids.lock);
174 list_for_each_entry(dynid, &drv->dynids.list, node) { 168 list_for_each_entry(dynid, &drv->dynids.list, node) {
175 if (pci_match_one_device(&dynid->id, dev)) { 169 if (pci_match_one_device(&dynid->id, dev)) {
@@ -178,7 +172,8 @@ const struct pci_device_id *pci_match_device(struct pci_driver *drv,
178 } 172 }
179 } 173 }
180 spin_unlock(&drv->dynids.lock); 174 spin_unlock(&drv->dynids.lock);
181 return NULL; 175
176 return pci_match_id(drv->id_table, dev);
182} 177}
183 178
184static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, 179static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
@@ -357,6 +352,8 @@ static int pci_device_resume_early(struct device * dev)
357 struct pci_dev * pci_dev = to_pci_dev(dev); 352 struct pci_dev * pci_dev = to_pci_dev(dev);
358 struct pci_driver * drv = pci_dev->driver; 353 struct pci_driver * drv = pci_dev->driver;
359 354
355 pci_fixup_device(pci_fixup_resume, pci_dev);
356
360 if (drv && drv->resume_early) 357 if (drv && drv->resume_early)
361 error = drv->resume_early(pci_dev); 358 error = drv->resume_early(pci_dev);
362 return error; 359 return error;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 5a14b73cf3..206c834d26 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -68,12 +68,14 @@ pci_max_busnr(void)
68 68
69#endif /* 0 */ 69#endif /* 0 */
70 70
71static int __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn, u8 pos, int cap) 71#define PCI_FIND_CAP_TTL 48
72
73static int __pci_find_next_cap_ttl(struct pci_bus *bus, unsigned int devfn,
74 u8 pos, int cap, int *ttl)
72{ 75{
73 u8 id; 76 u8 id;
74 int ttl = 48;
75 77
76 while (ttl--) { 78 while ((*ttl)--) {
77 pci_bus_read_config_byte(bus, devfn, pos, &pos); 79 pci_bus_read_config_byte(bus, devfn, pos, &pos);
78 if (pos < 0x40) 80 if (pos < 0x40)
79 break; 81 break;
@@ -89,6 +91,14 @@ static int __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn, u8 pos,
89 return 0; 91 return 0;
90} 92}
91 93
94static int __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn,
95 u8 pos, int cap)
96{
97 int ttl = PCI_FIND_CAP_TTL;
98
99 return __pci_find_next_cap_ttl(bus, devfn, pos, cap, &ttl);
100}
101
92int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap) 102int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap)
93{ 103{
94 return __pci_find_next_cap(dev->bus, dev->devfn, 104 return __pci_find_next_cap(dev->bus, dev->devfn,
@@ -96,10 +106,10 @@ int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap)
96} 106}
97EXPORT_SYMBOL_GPL(pci_find_next_capability); 107EXPORT_SYMBOL_GPL(pci_find_next_capability);
98 108
99static int __pci_bus_find_cap(struct pci_bus *bus, unsigned int devfn, u8 hdr_type, int cap) 109static int __pci_bus_find_cap_start(struct pci_bus *bus,
110 unsigned int devfn, u8 hdr_type)
100{ 111{
101 u16 status; 112 u16 status;
102 u8 pos;
103 113
104 pci_bus_read_config_word(bus, devfn, PCI_STATUS, &status); 114 pci_bus_read_config_word(bus, devfn, PCI_STATUS, &status);
105 if (!(status & PCI_STATUS_CAP_LIST)) 115 if (!(status & PCI_STATUS_CAP_LIST))
@@ -108,15 +118,14 @@ static int __pci_bus_find_cap(struct pci_bus *bus, unsigned int devfn, u8 hdr_ty
108 switch (hdr_type) { 118 switch (hdr_type) {
109 case PCI_HEADER_TYPE_NORMAL: 119 case PCI_HEADER_TYPE_NORMAL:
110 case PCI_HEADER_TYPE_BRIDGE: 120 case PCI_HEADER_TYPE_BRIDGE:
111 pos = PCI_CAPABILITY_LIST; 121 return PCI_CAPABILITY_LIST;
112 break;
113 case PCI_HEADER_TYPE_CARDBUS: 122 case PCI_HEADER_TYPE_CARDBUS:
114 pos = PCI_CB_CAPABILITY_LIST; 123 return PCI_CB_CAPABILITY_LIST;
115 break;
116 default: 124 default:
117 return 0; 125 return 0;
118 } 126 }
119 return __pci_find_next_cap(bus, devfn, pos, cap); 127
128 return 0;
120} 129}
121 130
122/** 131/**
@@ -140,7 +149,13 @@ static int __pci_bus_find_cap(struct pci_bus *bus, unsigned int devfn, u8 hdr_ty
140 */ 149 */
141int pci_find_capability(struct pci_dev *dev, int cap) 150int pci_find_capability(struct pci_dev *dev, int cap)
142{ 151{
143 return __pci_bus_find_cap(dev->bus, dev->devfn, dev->hdr_type, cap); 152 int pos;
153
154 pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
155 if (pos)
156 pos = __pci_find_next_cap(dev->bus, dev->devfn, pos, cap);
157
158 return pos;
144} 159}
145 160
146/** 161/**
@@ -158,11 +173,16 @@ int pci_find_capability(struct pci_dev *dev, int cap)
158 */ 173 */
159int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap) 174int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap)
160{ 175{
176 int pos;
161 u8 hdr_type; 177 u8 hdr_type;
162 178
163 pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type); 179 pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type);
164 180
165 return __pci_bus_find_cap(bus, devfn, hdr_type & 0x7f, cap); 181 pos = __pci_bus_find_cap_start(bus, devfn, hdr_type & 0x7f);
182 if (pos)
183 pos = __pci_find_next_cap(bus, devfn, pos, cap);
184
185 return pos;
166} 186}
167 187
168/** 188/**
@@ -214,6 +234,75 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap)
214} 234}
215EXPORT_SYMBOL_GPL(pci_find_ext_capability); 235EXPORT_SYMBOL_GPL(pci_find_ext_capability);
216 236
237static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap)
238{
239 int rc, ttl = PCI_FIND_CAP_TTL;
240 u8 cap, mask;
241
242 if (ht_cap == HT_CAPTYPE_SLAVE || ht_cap == HT_CAPTYPE_HOST)
243 mask = HT_3BIT_CAP_MASK;
244 else
245 mask = HT_5BIT_CAP_MASK;
246
247 pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn, pos,
248 PCI_CAP_ID_HT, &ttl);
249 while (pos) {
250 rc = pci_read_config_byte(dev, pos + 3, &cap);
251 if (rc != PCIBIOS_SUCCESSFUL)
252 return 0;
253
254 if ((cap & mask) == ht_cap)
255 return pos;
256
257 pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn,
258 pos + PCI_CAP_LIST_NEXT,
259 PCI_CAP_ID_HT, &ttl);
260 }
261
262 return 0;
263}
264/**
265 * pci_find_next_ht_capability - query a device's Hypertransport capabilities
266 * @dev: PCI device to query
267 * @pos: Position from which to continue searching
268 * @ht_cap: Hypertransport capability code
269 *
270 * To be used in conjunction with pci_find_ht_capability() to search for
271 * all capabilities matching @ht_cap. @pos should always be a value returned
272 * from pci_find_ht_capability().
273 *
274 * NB. To be 100% safe against broken PCI devices, the caller should take
275 * steps to avoid an infinite loop.
276 */
277int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap)
278{
279 return __pci_find_next_ht_cap(dev, pos + PCI_CAP_LIST_NEXT, ht_cap);
280}
281EXPORT_SYMBOL_GPL(pci_find_next_ht_capability);
282
283/**
284 * pci_find_ht_capability - query a device's Hypertransport capabilities
285 * @dev: PCI device to query
286 * @ht_cap: Hypertransport capability code
287 *
288 * Tell if a device supports a given Hypertransport capability.
289 * Returns an address within the device's PCI configuration space
290 * or 0 in case the device does not support the request capability.
291 * The address points to the PCI capability, of type PCI_CAP_ID_HT,
292 * which has a Hypertransport capability matching @ht_cap.
293 */
294int pci_find_ht_capability(struct pci_dev *dev, int ht_cap)
295{
296 int pos;
297
298 pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
299 if (pos)
300 pos = __pci_find_next_ht_cap(dev, pos, ht_cap);
301
302 return pos;
303}
304EXPORT_SYMBOL_GPL(pci_find_ht_capability);
305
217/** 306/**
218 * pci_find_parent_resource - return resource region of parent bus of given region 307 * pci_find_parent_resource - return resource region of parent bus of given region
219 * @dev: PCI device structure contains resources to be searched 308 * @dev: PCI device structure contains resources to be searched
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index b4da795461..f17e7ed2b2 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -90,7 +90,7 @@ static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
90 return -ENODEV; 90 return -ENODEV;
91 91
92 pci_set_master(dev); 92 pci_set_master(dev);
93 if (!dev->irq) { 93 if (!dev->irq && dev->pin) {
94 printk(KERN_WARNING 94 printk(KERN_WARNING
95 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n", 95 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n",
96 __FUNCTION__, dev->device, dev->vendor); 96 __FUNCTION__, dev->device, dev->vendor);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 6a3c1e7289..0e0401dd02 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -639,6 +639,8 @@ static void pci_read_irq(struct pci_dev *dev)
639 dev->irq = irq; 639 dev->irq = irq;
640} 640}
641 641
642#define LEGACY_IO_RESOURCE (IORESOURCE_IO | IORESOURCE_PCI_FIXED)
643
642/** 644/**
643 * pci_setup_device - fill in class and map information of a device 645 * pci_setup_device - fill in class and map information of a device
644 * @dev: the device structure to fill 646 * @dev: the device structure to fill
@@ -692,18 +694,18 @@ static int pci_setup_device(struct pci_dev * dev)
692 if ((progif & 1) == 0) { 694 if ((progif & 1) == 0) {
693 dev->resource[0].start = 0x1F0; 695 dev->resource[0].start = 0x1F0;
694 dev->resource[0].end = 0x1F7; 696 dev->resource[0].end = 0x1F7;
695 dev->resource[0].flags = IORESOURCE_IO; 697 dev->resource[0].flags = LEGACY_IO_RESOURCE;
696 dev->resource[1].start = 0x3F6; 698 dev->resource[1].start = 0x3F6;
697 dev->resource[1].end = 0x3F6; 699 dev->resource[1].end = 0x3F6;
698 dev->resource[1].flags = IORESOURCE_IO; 700 dev->resource[1].flags = LEGACY_IO_RESOURCE;
699 } 701 }
700 if ((progif & 4) == 0) { 702 if ((progif & 4) == 0) {
701 dev->resource[2].start = 0x170; 703 dev->resource[2].start = 0x170;
702 dev->resource[2].end = 0x177; 704 dev->resource[2].end = 0x177;
703 dev->resource[2].flags = IORESOURCE_IO; 705 dev->resource[2].flags = LEGACY_IO_RESOURCE;
704 dev->resource[3].start = 0x376; 706 dev->resource[3].start = 0x376;
705 dev->resource[3].end = 0x376; 707 dev->resource[3].end = 0x376;
706 dev->resource[3].flags = IORESOURCE_IO; 708 dev->resource[3].flags = LEGACY_IO_RESOURCE;
707 } 709 }
708 } 710 }
709 break; 711 break;
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 9ca9b9bf61..c913ea4e54 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -36,7 +36,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_MELLANOX,PCI_DEVICE_ID_MELLANOX_TAVOR_BRID
36 36
37/* Deal with broken BIOS'es that neglect to enable passive release, 37/* Deal with broken BIOS'es that neglect to enable passive release,
38 which can cause problems in combination with the 82441FX/PPro MTRRs */ 38 which can cause problems in combination with the 82441FX/PPro MTRRs */
39static void __devinit quirk_passive_release(struct pci_dev *dev) 39static void quirk_passive_release(struct pci_dev *dev)
40{ 40{
41 struct pci_dev *d = NULL; 41 struct pci_dev *d = NULL;
42 unsigned char dlc; 42 unsigned char dlc;
@@ -53,6 +53,7 @@ static void __devinit quirk_passive_release(struct pci_dev *dev)
53 } 53 }
54} 54}
55DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_passive_release ); 55DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_passive_release );
56DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_passive_release );
56 57
57/* The VIA VP2/VP3/MVP3 seem to have some 'features'. There may be a workaround 58/* The VIA VP2/VP3/MVP3 seem to have some 'features'. There may be a workaround
58 but VIA don't answer queries. If you happen to have good contacts at VIA 59 but VIA don't answer queries. If you happen to have good contacts at VIA
@@ -134,7 +135,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82439TX, quir
134 * Updated based on further information from the site and also on 135 * Updated based on further information from the site and also on
135 * information provided by VIA 136 * information provided by VIA
136 */ 137 */
137static void __devinit quirk_vialatency(struct pci_dev *dev) 138static void quirk_vialatency(struct pci_dev *dev)
138{ 139{
139 struct pci_dev *p; 140 struct pci_dev *p;
140 u8 rev; 141 u8 rev;
@@ -185,6 +186,10 @@ exit:
185DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, quirk_vialatency ); 186DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, quirk_vialatency );
186DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8371_1, quirk_vialatency ); 187DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8371_1, quirk_vialatency );
187DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, quirk_vialatency ); 188DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, quirk_vialatency );
189/* Must restore this on a resume from RAM */
190DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, quirk_vialatency );
191DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8371_1, quirk_vialatency );
192DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, quirk_vialatency );
188 193
189/* 194/*
190 * VIA Apollo VP3 needs ETBF on BT848/878 195 * VIA Apollo VP3 needs ETBF on BT848/878
@@ -532,7 +537,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_vt8235
532 * TODO: When we have device-specific interrupt routers, 537 * TODO: When we have device-specific interrupt routers,
533 * this code will go away from quirks. 538 * this code will go away from quirks.
534 */ 539 */
535static void __devinit quirk_via_ioapic(struct pci_dev *dev) 540static void quirk_via_ioapic(struct pci_dev *dev)
536{ 541{
537 u8 tmp; 542 u8 tmp;
538 543
@@ -548,6 +553,7 @@ static void __devinit quirk_via_ioapic(struct pci_dev *dev)
548 pci_write_config_byte (dev, 0x58, tmp); 553 pci_write_config_byte (dev, 0x58, tmp);
549} 554}
550DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic ); 555DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic );
556DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic );
551 557
552/* 558/*
553 * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit. 559 * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit.
@@ -555,7 +561,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_i
555 * Set this bit to get rid of cycle wastage. 561 * Set this bit to get rid of cycle wastage.
556 * Otherwise uncritical. 562 * Otherwise uncritical.
557 */ 563 */
558static void __devinit quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev) 564static void quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev)
559{ 565{
560 u8 misc_control2; 566 u8 misc_control2;
561#define BYPASS_APIC_DEASSERT 8 567#define BYPASS_APIC_DEASSERT 8
@@ -567,6 +573,7 @@ static void __devinit quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev)
567 } 573 }
568} 574}
569DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); 575DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
576DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
570 577
571/* 578/*
572 * The AMD io apic can hang the box when an apic irq is masked. 579 * The AMD io apic can hang the box when an apic irq is masked.
@@ -600,7 +607,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_ANY_ID, quirk_ioapic_rmw );
600#define AMD8131_revB0 0x11 607#define AMD8131_revB0 0x11
601#define AMD8131_MISC 0x40 608#define AMD8131_MISC 0x40
602#define AMD8131_NIOAMODE_BIT 0 609#define AMD8131_NIOAMODE_BIT 0
603static void __init quirk_amd_8131_ioapic(struct pci_dev *dev) 610static void quirk_amd_8131_ioapic(struct pci_dev *dev)
604{ 611{
605 unsigned char revid, tmp; 612 unsigned char revid, tmp;
606 613
@@ -616,6 +623,7 @@ static void __init quirk_amd_8131_ioapic(struct pci_dev *dev)
616 } 623 }
617} 624}
618DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); 625DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic);
626DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic);
619#endif /* CONFIG_X86_IO_APIC */ 627#endif /* CONFIG_X86_IO_APIC */
620 628
621 629
@@ -641,48 +649,67 @@ static void __devinit quirk_via_acpi(struct pci_dev *d)
641DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_acpi ); 649DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_acpi );
642DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_acpi ); 650DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_acpi );
643 651
652
644/* 653/*
645 * Via 686A/B: The PCI_INTERRUPT_LINE register for the on-chip 654 * VIA bridges which have VLink
646 * devices, USB0/1, AC97, MC97, and ACPI, has an unusual feature:
647 * when written, it makes an internal connection to the PIC.
648 * For these devices, this register is defined to be 4 bits wide.
649 * Normally this is fine. However for IO-APIC motherboards, or
650 * non-x86 architectures (yes Via exists on PPC among other places),
651 * we must mask the PCI_INTERRUPT_LINE value versus 0xf to get
652 * interrupts delivered properly.
653 *
654 * Some of the on-chip devices are actually '586 devices' so they are
655 * listed here.
656 */ 655 */
657 656
658static int via_irq_fixup_needed = -1; 657static int via_vlink_dev_lo = -1, via_vlink_dev_hi = 18;
659 658
660/* 659static void quirk_via_bridge(struct pci_dev *dev)
661 * As some VIA hardware is available in PCI-card form, we need to restrict 660{
662 * this quirk to VIA PCI hardware built onto VIA-based motherboards only. 661 /* See what bridge we have and find the device ranges */
663 * We try to locate a VIA southbridge before deciding whether the quirk 662 switch (dev->device) {
664 * should be applied. 663 case PCI_DEVICE_ID_VIA_82C686:
664 /* The VT82C686 is special, it attaches to PCI and can have
665 any device number. All its subdevices are functions of
666 that single device. */
667 via_vlink_dev_lo = PCI_SLOT(dev->devfn);
668 via_vlink_dev_hi = PCI_SLOT(dev->devfn);
669 break;
670 case PCI_DEVICE_ID_VIA_8237:
671 case PCI_DEVICE_ID_VIA_8237A:
672 via_vlink_dev_lo = 15;
673 break;
674 case PCI_DEVICE_ID_VIA_8235:
675 via_vlink_dev_lo = 16;
676 break;
677 case PCI_DEVICE_ID_VIA_8231:
678 case PCI_DEVICE_ID_VIA_8233_0:
679 case PCI_DEVICE_ID_VIA_8233A:
680 case PCI_DEVICE_ID_VIA_8233C_0:
681 via_vlink_dev_lo = 17;
682 break;
683 }
684}
685DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_bridge);
686DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, quirk_via_bridge);
687DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_0, quirk_via_bridge);
688DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233A, quirk_via_bridge);
689DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233C_0, quirk_via_bridge);
690DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_via_bridge);
691DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_bridge);
692DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A, quirk_via_bridge);
693
694/**
695 * quirk_via_vlink - VIA VLink IRQ number update
696 * @dev: PCI device
697 *
698 * If the device we are dealing with is on a PIC IRQ we need to
699 * ensure that the IRQ line register which usually is not relevant
700 * for PCI cards, is actually written so that interrupts get sent
701 * to the right place.
702 * We only do this on systems where a VIA south bridge was detected,
703 * and only for VIA devices on the motherboard (see quirk_via_bridge
704 * above).
665 */ 705 */
666static const struct pci_device_id via_irq_fixup_tbl[] = { 706
667 { 707static void quirk_via_vlink(struct pci_dev *dev)
668 .vendor = PCI_VENDOR_ID_VIA,
669 .device = PCI_ANY_ID,
670 .subvendor = PCI_ANY_ID,
671 .subdevice = PCI_ANY_ID,
672 .class = PCI_CLASS_BRIDGE_ISA << 8,
673 .class_mask = 0xffff00,
674 },
675 { 0, },
676};
677
678static void quirk_via_irq(struct pci_dev *dev)
679{ 708{
680 u8 irq, new_irq; 709 u8 irq, new_irq;
681 710
682 if (via_irq_fixup_needed == -1) 711 /* Check if we have VLink at all */
683 via_irq_fixup_needed = pci_dev_present(via_irq_fixup_tbl); 712 if (via_vlink_dev_lo == -1)
684
685 if (!via_irq_fixup_needed)
686 return; 713 return;
687 714
688 new_irq = dev->irq; 715 new_irq = dev->irq;
@@ -691,15 +718,23 @@ static void quirk_via_irq(struct pci_dev *dev)
691 if (!new_irq || new_irq > 15) 718 if (!new_irq || new_irq > 15)
692 return; 719 return;
693 720
721 /* Internal device ? */
722 if (dev->bus->number != 0 || PCI_SLOT(dev->devfn) > via_vlink_dev_hi ||
723 PCI_SLOT(dev->devfn) < via_vlink_dev_lo)
724 return;
725
726 /* This is an internal VLink device on a PIC interrupt. The BIOS
727 ought to have set this but may not have, so we redo it */
728
694 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq); 729 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
695 if (new_irq != irq) { 730 if (new_irq != irq) {
696 printk(KERN_INFO "PCI: VIA IRQ fixup for %s, from %d to %d\n", 731 printk(KERN_INFO "PCI: VIA VLink IRQ fixup for %s, from %d to %d\n",
697 pci_name(dev), irq, new_irq); 732 pci_name(dev), irq, new_irq);
698 udelay(15); /* unknown if delay really needed */ 733 udelay(15); /* unknown if delay really needed */
699 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq); 734 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq);
700 } 735 }
701} 736}
702DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_irq); 737DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_vlink);
703 738
704/* 739/*
705 * VIA VT82C598 has its device ID settable and many BIOSes 740 * VIA VT82C598 has its device ID settable and many BIOSes
@@ -720,13 +755,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C597_0, quirk_vt
720 * do this even if the Linux CardBus driver is not loaded, because 755 * do this even if the Linux CardBus driver is not loaded, because
721 * the Linux i82365 driver does not (and should not) handle CardBus. 756 * the Linux i82365 driver does not (and should not) handle CardBus.
722 */ 757 */
723static void __devinit quirk_cardbus_legacy(struct pci_dev *dev) 758static void quirk_cardbus_legacy(struct pci_dev *dev)
724{ 759{
725 if ((PCI_CLASS_BRIDGE_CARDBUS << 8) ^ dev->class) 760 if ((PCI_CLASS_BRIDGE_CARDBUS << 8) ^ dev->class)
726 return; 761 return;
727 pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0); 762 pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0);
728} 763}
729DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); 764DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy);
765DECLARE_PCI_FIXUP_RESUME(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy);
730 766
731/* 767/*
732 * Following the PCI ordering rules is optional on the AMD762. I'm not 768 * Following the PCI ordering rules is optional on the AMD762. I'm not
@@ -735,7 +771,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy);
735 * To be fair to AMD, it follows the spec by default, its BIOS people 771 * To be fair to AMD, it follows the spec by default, its BIOS people
736 * who turn it off! 772 * who turn it off!
737 */ 773 */
738static void __devinit quirk_amd_ordering(struct pci_dev *dev) 774static void quirk_amd_ordering(struct pci_dev *dev)
739{ 775{
740 u32 pcic; 776 u32 pcic;
741 pci_read_config_dword(dev, 0x4C, &pcic); 777 pci_read_config_dword(dev, 0x4C, &pcic);
@@ -749,6 +785,7 @@ static void __devinit quirk_amd_ordering(struct pci_dev *dev)
749 } 785 }
750} 786}
751DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering ); 787DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering );
788DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering );
752 789
753/* 790/*
754 * DreamWorks provided workaround for Dunord I-3000 problem 791 * DreamWorks provided workaround for Dunord I-3000 problem
@@ -784,7 +821,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA, 0x605, quirk_transparent_bridge
784 * datasheets found at http://www.national.com/ds/GX for info on what 821 * datasheets found at http://www.national.com/ds/GX for info on what
785 * these bits do. <christer@weinigel.se> 822 * these bits do. <christer@weinigel.se>
786 */ 823 */
787static void __init quirk_mediagx_master(struct pci_dev *dev) 824static void quirk_mediagx_master(struct pci_dev *dev)
788{ 825{
789 u8 reg; 826 u8 reg;
790 pci_read_config_byte(dev, 0x41, &reg); 827 pci_read_config_byte(dev, 0x41, &reg);
@@ -795,13 +832,14 @@ static void __init quirk_mediagx_master(struct pci_dev *dev)
795 } 832 }
796} 833}
797DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master ); 834DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master );
835DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master );
798 836
799/* 837/*
800 * Ensure C0 rev restreaming is off. This is normally done by 838 * Ensure C0 rev restreaming is off. This is normally done by
801 * the BIOS but in the odd case it is not the results are corruption 839 * the BIOS but in the odd case it is not the results are corruption
802 * hence the presence of a Linux check 840 * hence the presence of a Linux check
803 */ 841 */
804static void __init quirk_disable_pxb(struct pci_dev *pdev) 842static void quirk_disable_pxb(struct pci_dev *pdev)
805{ 843{
806 u16 config; 844 u16 config;
807 u8 rev; 845 u8 rev;
@@ -817,7 +855,25 @@ static void __init quirk_disable_pxb(struct pci_dev *pdev)
817 } 855 }
818} 856}
819DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb ); 857DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb );
858DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb );
859
860
861static void __devinit quirk_sb600_sata(struct pci_dev *pdev)
862{
863 /* set sb600 sata to ahci mode */
864 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
865 u8 tmp;
866
867 pci_read_config_byte(pdev, 0x40, &tmp);
868 pci_write_config_byte(pdev, 0x40, tmp|1);
869 pci_write_config_byte(pdev, 0x9, 1);
870 pci_write_config_byte(pdev, 0xa, 6);
871 pci_write_config_byte(pdev, 0x40, tmp);
820 872
873 pdev->class = 0x010601;
874 }
875}
876DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_sb600_sata);
821 877
822/* 878/*
823 * Serverworks CSB5 IDE does not fully support native mode 879 * Serverworks CSB5 IDE does not fully support native mode
@@ -874,7 +930,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82375, quirk_e
874 * runs everywhere at present we suppress the printk output in most 930 * runs everywhere at present we suppress the printk output in most
875 * irrelevant cases. 931 * irrelevant cases.
876 */ 932 */
877static void __init k8t_sound_hostbridge(struct pci_dev *dev) 933static void k8t_sound_hostbridge(struct pci_dev *dev)
878{ 934{
879 unsigned char val; 935 unsigned char val;
880 936
@@ -893,8 +949,8 @@ static void __init k8t_sound_hostbridge(struct pci_dev *dev)
893 } 949 }
894} 950}
895DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, k8t_sound_hostbridge); 951DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, k8t_sound_hostbridge);
952DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, k8t_sound_hostbridge);
896 953
897#ifndef CONFIG_ACPI_SLEEP
898/* 954/*
899 * On ASUS P4B boards, the SMBus PCI Device within the ICH2/4 southbridge 955 * On ASUS P4B boards, the SMBus PCI Device within the ICH2/4 southbridge
900 * is not activated. The myth is that Asus said that they do not want the 956 * is not activated. The myth is that Asus said that they do not want the
@@ -906,12 +962,8 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, k8t_sound_ho
906 * bridge. Unfortunately, this device has no subvendor/subdevice ID. So it 962 * bridge. Unfortunately, this device has no subvendor/subdevice ID. So it
907 * becomes necessary to do this tweak in two steps -- I've chosen the Host 963 * becomes necessary to do this tweak in two steps -- I've chosen the Host
908 * bridge as trigger. 964 * bridge as trigger.
909 *
910 * Actually, leaving it unhidden and not redoing the quirk over suspend2ram
911 * will cause thermal management to break down, and causing machine to
912 * overheat.
913 */ 965 */
914static int __initdata asus_hides_smbus; 966static int asus_hides_smbus;
915 967
916static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev) 968static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
917{ 969{
@@ -958,6 +1010,11 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
958 case 0x186a: /* M6Ne notebook */ 1010 case 0x186a: /* M6Ne notebook */
959 asus_hides_smbus = 1; 1011 asus_hides_smbus = 1;
960 } 1012 }
1013 if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB)
1014 switch (dev->subsystem_device) {
1015 case 0x80f2: /* P4P800-X */
1016 asus_hides_smbus = 1;
1017 }
961 if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) { 1018 if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) {
962 switch (dev->subsystem_device) { 1019 switch (dev->subsystem_device) {
963 case 0x1882: /* M6V notebook */ 1020 case 0x1882: /* M6V notebook */
@@ -1019,7 +1076,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855PM_HB, as
1019DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge ); 1076DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge );
1020DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge ); 1077DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge );
1021 1078
1022static void __init asus_hides_smbus_lpc(struct pci_dev *dev) 1079static void asus_hides_smbus_lpc(struct pci_dev *dev)
1023{ 1080{
1024 u16 val; 1081 u16 val;
1025 1082
@@ -1042,8 +1099,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asu
1042DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc ); 1099DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc );
1043DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc ); 1100DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc );
1044DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc ); 1101DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc );
1102DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc );
1103DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc );
1104DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc );
1105DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc );
1106DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc );
1107DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc );
1045 1108
1046static void __init asus_hides_smbus_lpc_ich6(struct pci_dev *dev) 1109static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
1047{ 1110{
1048 u32 val, rcba; 1111 u32 val, rcba;
1049 void __iomem *base; 1112 void __iomem *base;
@@ -1059,19 +1122,19 @@ static void __init asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
1059 printk(KERN_INFO "PCI: Enabled ICH6/i801 SMBus device\n"); 1122 printk(KERN_INFO "PCI: Enabled ICH6/i801 SMBus device\n");
1060} 1123}
1061DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6 ); 1124DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6 );
1062 1125DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6 );
1063#endif
1064 1126
1065/* 1127/*
1066 * SiS 96x south bridge: BIOS typically hides SMBus device... 1128 * SiS 96x south bridge: BIOS typically hides SMBus device...
1067 */ 1129 */
1068static void __init quirk_sis_96x_smbus(struct pci_dev *dev) 1130static void quirk_sis_96x_smbus(struct pci_dev *dev)
1069{ 1131{
1070 u8 val = 0; 1132 u8 val = 0;
1071 printk(KERN_INFO "Enabling SiS 96x SMBus.\n");
1072 pci_read_config_byte(dev, 0x77, &val);
1073 pci_write_config_byte(dev, 0x77, val & ~0x10);
1074 pci_read_config_byte(dev, 0x77, &val); 1133 pci_read_config_byte(dev, 0x77, &val);
1134 if (val & 0x10) {
1135 printk(KERN_INFO "Enabling SiS 96x SMBus.\n");
1136 pci_write_config_byte(dev, 0x77, val & ~0x10);
1137 }
1075} 1138}
1076 1139
1077/* 1140/*
@@ -1086,7 +1149,7 @@ static int __devinitdata sis_96x_compatible = 0;
1086 1149
1087#define SIS_DETECT_REGISTER 0x40 1150#define SIS_DETECT_REGISTER 0x40
1088 1151
1089static void __init quirk_sis_503(struct pci_dev *dev) 1152static void quirk_sis_503(struct pci_dev *dev)
1090{ 1153{
1091 u8 reg; 1154 u8 reg;
1092 u16 devid; 1155 u16 devid;
@@ -1103,11 +1166,12 @@ static void __init quirk_sis_503(struct pci_dev *dev)
1103 printk(KERN_WARNING "Uncovering SIS%x that hid as a SIS503 (compatible=%d)\n", devid, sis_96x_compatible); 1166 printk(KERN_WARNING "Uncovering SIS%x that hid as a SIS503 (compatible=%d)\n", devid, sis_96x_compatible);
1104 1167
1105 /* 1168 /*
1106 * Ok, it now shows up as a 96x.. The 96x quirks are after 1169 * Ok, it now shows up as a 96x.. run the 96x quirk by
1107 * the 503 quirk in the quirk table, so they'll automatically 1170 * hand in case it has already been processed.
1108 * run and enable things like the SMBus device 1171 * (depends on link order, which is apparently not guaranteed)
1109 */ 1172 */
1110 dev->device = devid; 1173 dev->device = devid;
1174 quirk_sis_96x_smbus(dev);
1111} 1175}
1112 1176
1113static void __init quirk_sis_96x_compatible(struct pci_dev *dev) 1177static void __init quirk_sis_96x_compatible(struct pci_dev *dev)
@@ -1122,13 +1186,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_651, quirk_sis_96x_
1122DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_735, quirk_sis_96x_compatible ); 1186DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_735, quirk_sis_96x_compatible );
1123 1187
1124DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503 ); 1188DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503 );
1189DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503 );
1125/* 1190/*
1126 * On ASUS A8V and A8V Deluxe boards, the onboard AC97 audio controller 1191 * On ASUS A8V and A8V Deluxe boards, the onboard AC97 audio controller
1127 * and MC97 modem controller are disabled when a second PCI soundcard is 1192 * and MC97 modem controller are disabled when a second PCI soundcard is
1128 * present. This patch, tweaking the VT8237 ISA bridge, enables them. 1193 * present. This patch, tweaking the VT8237 ISA bridge, enables them.
1129 * -- bjd 1194 * -- bjd
1130 */ 1195 */
1131static void __init asus_hides_ac97_lpc(struct pci_dev *dev) 1196static void asus_hides_ac97_lpc(struct pci_dev *dev)
1132{ 1197{
1133 u8 val; 1198 u8 val;
1134 int asus_hides_ac97 = 0; 1199 int asus_hides_ac97 = 0;
@@ -1159,6 +1224,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_
1159DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus ); 1224DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus );
1160DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus ); 1225DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus );
1161 1226
1227DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc );
1228
1229
1230DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus );
1231DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus );
1232DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus );
1233DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus );
1234
1162#if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE) 1235#if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE)
1163 1236
1164/* 1237/*
@@ -1167,7 +1240,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_
1167 * the PCI scanning. 1240 * the PCI scanning.
1168 */ 1241 */
1169 1242
1170static void __devinit quirk_jmicron_dualfn(struct pci_dev *pdev) 1243static void quirk_jmicron_dualfn(struct pci_dev *pdev)
1171{ 1244{
1172 u32 conf; 1245 u32 conf;
1173 u8 hdr; 1246 u8 hdr;
@@ -1189,8 +1262,8 @@ static void __devinit quirk_jmicron_dualfn(struct pci_dev *pdev)
1189 pci_read_config_dword(pdev, 0x40, &conf); 1262 pci_read_config_dword(pdev, 0x40, &conf);
1190 /* Enable dual function mode, AHCI on fn 0, IDE fn1 */ 1263 /* Enable dual function mode, AHCI on fn 0, IDE fn1 */
1191 /* Set the class codes correctly and then direct IDE 0 */ 1264 /* Set the class codes correctly and then direct IDE 0 */
1192 conf &= ~0x000F0200; /* Clear bit 9 and 16-19 */ 1265 conf &= ~0x000FF200; /* Clear bit 9 and 12-19 */
1193 conf |= 0x00C20002; /* Set bit 1, 17, 22, 23 */ 1266 conf |= 0x00C2A102; /* Set 1, 8, 13, 15, 17, 22, 23 */
1194 pci_write_config_dword(pdev, 0x40, conf); 1267 pci_write_config_dword(pdev, 0x40, conf);
1195 1268
1196 /* Reconfigure so that the PCI scanner discovers the 1269 /* Reconfigure so that the PCI scanner discovers the
@@ -1205,6 +1278,7 @@ static void __devinit quirk_jmicron_dualfn(struct pci_dev *pdev)
1205} 1278}
1206 1279
1207DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn); 1280DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn);
1281DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn);
1208 1282
1209#endif 1283#endif
1210 1284
@@ -1532,6 +1606,8 @@ extern struct pci_fixup __start_pci_fixups_final[];
1532extern struct pci_fixup __end_pci_fixups_final[]; 1606extern struct pci_fixup __end_pci_fixups_final[];
1533extern struct pci_fixup __start_pci_fixups_enable[]; 1607extern struct pci_fixup __start_pci_fixups_enable[];
1534extern struct pci_fixup __end_pci_fixups_enable[]; 1608extern struct pci_fixup __end_pci_fixups_enable[];
1609extern struct pci_fixup __start_pci_fixups_resume[];
1610extern struct pci_fixup __end_pci_fixups_resume[];
1535 1611
1536 1612
1537void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev) 1613void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
@@ -1559,6 +1635,11 @@ void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
1559 end = __end_pci_fixups_enable; 1635 end = __end_pci_fixups_enable;
1560 break; 1636 break;
1561 1637
1638 case pci_fixup_resume:
1639 start = __start_pci_fixups_resume;
1640 end = __end_pci_fixups_resume;
1641 break;
1642
1562 default: 1643 default:
1563 /* stupid compiler warning, you would think with an enum... */ 1644 /* stupid compiler warning, you would think with an enum... */
1564 return; 1645 return;
@@ -1596,7 +1677,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x1460, quirk_p64h2_1k_io);
1596 * Force it to be linked by setting the corresponding control bit in the 1677 * Force it to be linked by setting the corresponding control bit in the
1597 * config space. 1678 * config space.
1598 */ 1679 */
1599static void __devinit quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev) 1680static void quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev)
1600{ 1681{
1601 uint8_t b; 1682 uint8_t b;
1602 if (pci_read_config_byte(dev, 0xf41, &b) == 0) { 1683 if (pci_read_config_byte(dev, 0xf41, &b) == 0) {
@@ -1610,6 +1691,8 @@ static void __devinit quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev)
1610} 1691}
1611DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, 1692DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1612 quirk_nvidia_ck804_pcie_aer_ext_cap); 1693 quirk_nvidia_ck804_pcie_aer_ext_cap);
1694DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1695 quirk_nvidia_ck804_pcie_aer_ext_cap);
1613 1696
1614#ifdef CONFIG_PCI_MSI 1697#ifdef CONFIG_PCI_MSI
1615/* To disable MSI globally */ 1698/* To disable MSI globally */
@@ -1644,19 +1727,23 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_
1644 * return 1 if a HT MSI capability is found and enabled */ 1727 * return 1 if a HT MSI capability is found and enabled */
1645static int __devinit msi_ht_cap_enabled(struct pci_dev *dev) 1728static int __devinit msi_ht_cap_enabled(struct pci_dev *dev)
1646{ 1729{
1647 u8 pos; 1730 int pos, ttl = 48;
1648 int ttl; 1731
1649 for (pos = pci_find_capability(dev, PCI_CAP_ID_HT), ttl = 48; 1732 pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
1650 pos && ttl; 1733 while (pos && ttl--) {
1651 pos = pci_find_next_capability(dev, pos, PCI_CAP_ID_HT), ttl--) { 1734 u8 flags;
1652 u32 cap_hdr; 1735
1653 /* MSI mapping section according to Hypertransport spec */ 1736 if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
1654 if (pci_read_config_dword(dev, pos, &cap_hdr) == 0 1737 &flags) == 0)
1655 && (cap_hdr & 0xf8000000) == 0xa8000000 /* MSI mapping */) { 1738 {
1656 printk(KERN_INFO "PCI: Found HT MSI mapping on %s with capability %s\n", 1739 printk(KERN_INFO "PCI: Found %s HT MSI Mapping on %s\n",
1657 pci_name(dev), cap_hdr & 0x10000 ? "enabled" : "disabled"); 1740 flags & HT_MSI_FLAGS_ENABLE ?
1658 return (cap_hdr & 0x10000) != 0; /* MSI mapping cap enabled */ 1741 "enabled" : "disabled", pci_name(dev));
1742 return (flags & HT_MSI_FLAGS_ENABLE) != 0;
1659 } 1743 }
1744
1745 pos = pci_find_next_ht_capability(dev, pos,
1746 HT_CAPTYPE_MSI_MAPPING);
1660 } 1747 }
1661 return 0; 1748 return 0;
1662} 1749}
@@ -1688,8 +1775,9 @@ static void __devinit quirk_nvidia_ck804_msi_ht_cap(struct pci_dev *dev)
1688 * a single one having MSI is enough to be sure that MSI are supported. 1775 * a single one having MSI is enough to be sure that MSI are supported.
1689 */ 1776 */
1690 pdev = pci_get_slot(dev->bus, 0); 1777 pdev = pci_get_slot(dev->bus, 0);
1691 if (dev->subordinate && !msi_ht_cap_enabled(dev) 1778 if (!pdev)
1692 && !msi_ht_cap_enabled(pdev)) { 1779 return;
1780 if (!msi_ht_cap_enabled(dev) && !msi_ht_cap_enabled(pdev)) {
1693 printk(KERN_WARNING "PCI: MSI quirk detected. " 1781 printk(KERN_WARNING "PCI: MSI quirk detected. "
1694 "MSI disabled on chipset %s.\n", 1782 "MSI disabled on chipset %s.\n",
1695 pci_name(dev)); 1783 pci_name(dev));
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 2f13eba5d5..b2653c4afe 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -193,6 +193,15 @@ static struct pci_dev * pci_find_subsys(unsigned int vendor,
193 struct pci_dev *dev; 193 struct pci_dev *dev;
194 194
195 WARN_ON(in_interrupt()); 195 WARN_ON(in_interrupt());
196
197 /*
198 * pci_find_subsys() can be called on the ide_setup() path, super-early
199 * in boot. But the down_read() will enable local interrupts, which
200 * can cause some machines to crash. So here we detect and flag that
201 * situation and bail out early.
202 */
203 if (unlikely(list_empty(&pci_devices)))
204 return NULL;
196 down_read(&pci_bus_sem); 205 down_read(&pci_bus_sem);
197 n = from ? from->global_list.next : pci_devices.next; 206 n = from ? from->global_list.next : pci_devices.next;
198 207
@@ -259,6 +268,15 @@ pci_get_subsys(unsigned int vendor, unsigned int device,
259 struct pci_dev *dev; 268 struct pci_dev *dev;
260 269
261 WARN_ON(in_interrupt()); 270 WARN_ON(in_interrupt());
271
272 /*
273 * pci_get_subsys() can potentially be called by drivers super-early
274 * in boot. But the down_read() will enable local interrupts, which
275 * can cause some machines to crash. So here we detect and flag that
276 * situation and bail out early.
277 */
278 if (unlikely(list_empty(&pci_devices)))
279 return NULL;
262 down_read(&pci_bus_sem); 280 down_read(&pci_bus_sem);
263 n = from ? from->global_list.next : pci_devices.next; 281 n = from ? from->global_list.next : pci_devices.next;
264 282
@@ -413,6 +431,24 @@ exit:
413 return dev; 431 return dev;
414} 432}
415 433
434const struct pci_device_id *pci_find_present(const struct pci_device_id *ids)
435{
436 struct pci_dev *dev;
437 const struct pci_device_id *found = NULL;
438
439 WARN_ON(in_interrupt());
440 down_read(&pci_bus_sem);
441 while (ids->vendor || ids->subvendor || ids->class_mask) {
442 list_for_each_entry(dev, &pci_devices, global_list) {
443 if ((found = pci_match_one_device(ids, dev)) != NULL)
444 break;
445 }
446 ids++;
447 }
448 up_read(&pci_bus_sem);
449 return found;
450}
451
416/** 452/**
417 * pci_dev_present - Returns 1 if device matching the device list is present, 0 if not. 453 * pci_dev_present - Returns 1 if device matching the device list is present, 0 if not.
418 * @ids: A pointer to a null terminated list of struct pci_device_id structures 454 * @ids: A pointer to a null terminated list of struct pci_device_id structures
@@ -426,25 +462,11 @@ exit:
426 */ 462 */
427int pci_dev_present(const struct pci_device_id *ids) 463int pci_dev_present(const struct pci_device_id *ids)
428{ 464{
429 struct pci_dev *dev; 465 return pci_find_present(ids) == NULL ? 0 : 1;
430 int found = 0;
431
432 WARN_ON(in_interrupt());
433 down_read(&pci_bus_sem);
434 while (ids->vendor || ids->subvendor || ids->class_mask) {
435 list_for_each_entry(dev, &pci_devices, global_list) {
436 if (pci_match_one_device(ids, dev)) {
437 found = 1;
438 goto exit;
439 }
440 }
441 ids++;
442 }
443exit:
444 up_read(&pci_bus_sem);
445 return found;
446} 466}
467
447EXPORT_SYMBOL(pci_dev_present); 468EXPORT_SYMBOL(pci_dev_present);
469EXPORT_SYMBOL(pci_find_present);
448 470
449EXPORT_SYMBOL(pci_find_device); 471EXPORT_SYMBOL(pci_find_device);
450EXPORT_SYMBOL(pci_find_device_reverse); 472EXPORT_SYMBOL(pci_find_device_reverse);
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 8f7bcf56f1..89f3036f0d 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -41,7 +41,7 @@
41 * have a P2P bridge below a cardbus bridge, we need 4K. 41 * have a P2P bridge below a cardbus bridge, we need 4K.
42 */ 42 */
43#define CARDBUS_IO_SIZE (256) 43#define CARDBUS_IO_SIZE (256)
44#define CARDBUS_MEM_SIZE (32*1024*1024) 44#define CARDBUS_MEM_SIZE (64*1024*1024)
45 45
46static void __devinit 46static void __devinit
47pbus_assign_resources_sorted(struct pci_bus *bus) 47pbus_assign_resources_sorted(struct pci_bus *bus)
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index ab78e4bbdd..cb4ced3560 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -33,11 +33,22 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
33 u32 new, check, mask; 33 u32 new, check, mask;
34 int reg; 34 int reg;
35 35
36 /* Ignore resources for unimplemented BARs and unused resource slots 36 /*
37 for 64 bit BARs. */ 37 * Ignore resources for unimplemented BARs and unused resource slots
38 * for 64 bit BARs.
39 */
38 if (!res->flags) 40 if (!res->flags)
39 return; 41 return;
40 42
43 /*
44 * Ignore non-moveable resources. This might be legacy resources for
45 * which no functional BAR register exists or another important
46 * system resource we should better not move around in system address
47 * space.
48 */
49 if (res->flags & IORESOURCE_PCI_FIXED)
50 return;
51
41 pcibios_resource_to_bus(dev, &region, res); 52 pcibios_resource_to_bus(dev, &region, res);
42 53
43 pr_debug(" got res [%llx:%llx] bus [%lx:%lx] flags %lx for " 54 pr_debug(" got res [%llx:%llx] bus [%lx:%lx] flags %lx for "
@@ -212,6 +223,10 @@ pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
212 resource_size_t r_align; 223 resource_size_t r_align;
213 224
214 r = &dev->resource[i]; 225 r = &dev->resource[i];
226
227 if (r->flags & IORESOURCE_PCI_FIXED)
228 continue;
229
215 r_align = r->end - r->start; 230 r_align = r->end - r->start;
216 231
217 if (!(r->flags) || r->parent) 232 if (!(r->flags) || r->parent)
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 4f654c901c..a724ab49a7 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -33,6 +33,8 @@
33 33
34#include <asm/mach/time.h> 34#include <asm/mach/time.h>
35 35
36#include <asm/arch/at91_rtc.h>
37
36 38
37#define AT91_RTC_FREQ 1 39#define AT91_RTC_FREQ 1
38#define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ 40#define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 1460f6b769..e7851e3739 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * An I2C driver for the Ricoh RS5C372 RTC 2 * An I2C driver for Ricoh RS5C372 and RV5C38[67] RTCs
3 * 3 *
4 * Copyright (C) 2005 Pavel Mironchik <pmironchik@optifacio.net> 4 * Copyright (C) 2005 Pavel Mironchik <pmironchik@optifacio.net>
5 * Copyright (C) 2006 Tower Technologies 5 * Copyright (C) 2006 Tower Technologies
@@ -13,7 +13,7 @@
13#include <linux/rtc.h> 13#include <linux/rtc.h>
14#include <linux/bcd.h> 14#include <linux/bcd.h>
15 15
16#define DRV_VERSION "0.3" 16#define DRV_VERSION "0.4"
17 17
18/* Addresses to scan */ 18/* Addresses to scan */
19static unsigned short normal_i2c[] = { /* 0x32,*/ I2C_CLIENT_END }; 19static unsigned short normal_i2c[] = { /* 0x32,*/ I2C_CLIENT_END };
@@ -21,6 +21,13 @@ static unsigned short normal_i2c[] = { /* 0x32,*/ I2C_CLIENT_END };
21/* Insmod parameters */ 21/* Insmod parameters */
22I2C_CLIENT_INSMOD; 22I2C_CLIENT_INSMOD;
23 23
24
25/*
26 * Ricoh has a family of I2C based RTCs, which differ only slightly from
27 * each other. Differences center on pinout (e.g. how many interrupts,
28 * output clock, etc) and how the control registers are used. The '372
29 * is significant only because that's the one this driver first supported.
30 */
24#define RS5C372_REG_SECS 0 31#define RS5C372_REG_SECS 0
25#define RS5C372_REG_MINS 1 32#define RS5C372_REG_MINS 1
26#define RS5C372_REG_HOURS 2 33#define RS5C372_REG_HOURS 2
@@ -29,59 +36,142 @@ I2C_CLIENT_INSMOD;
29#define RS5C372_REG_MONTH 5 36#define RS5C372_REG_MONTH 5
30#define RS5C372_REG_YEAR 6 37#define RS5C372_REG_YEAR 6
31#define RS5C372_REG_TRIM 7 38#define RS5C372_REG_TRIM 7
39# define RS5C372_TRIM_XSL 0x80
40# define RS5C372_TRIM_MASK 0x7F
41
42#define RS5C_REG_ALARM_A_MIN 8 /* or ALARM_W */
43#define RS5C_REG_ALARM_A_HOURS 9
44#define RS5C_REG_ALARM_A_WDAY 10
45
46#define RS5C_REG_ALARM_B_MIN 11 /* or ALARM_D */
47#define RS5C_REG_ALARM_B_HOURS 12
48#define RS5C_REG_ALARM_B_WDAY 13 /* (ALARM_B only) */
49
50#define RS5C_REG_CTRL1 14
51# define RS5C_CTRL1_AALE (1 << 7) /* or WALE */
52# define RS5C_CTRL1_BALE (1 << 6) /* or DALE */
53# define RV5C387_CTRL1_24 (1 << 5)
54# define RS5C372A_CTRL1_SL1 (1 << 5)
55# define RS5C_CTRL1_CT_MASK (7 << 0)
56# define RS5C_CTRL1_CT0 (0 << 0) /* no periodic irq */
57# define RS5C_CTRL1_CT4 (4 << 0) /* 1 Hz level irq */
58#define RS5C_REG_CTRL2 15
59# define RS5C372_CTRL2_24 (1 << 5)
60# define RS5C_CTRL2_XSTP (1 << 4)
61# define RS5C_CTRL2_CTFG (1 << 2)
62# define RS5C_CTRL2_AAFG (1 << 1) /* or WAFG */
63# define RS5C_CTRL2_BAFG (1 << 0) /* or DAFG */
64
65
66/* to read (style 1) or write registers starting at R */
67#define RS5C_ADDR(R) (((R) << 4) | 0)
68
69
70enum rtc_type {
71 rtc_undef = 0,
72 rtc_rs5c372a,
73 rtc_rs5c372b,
74 rtc_rv5c386,
75 rtc_rv5c387a,
76};
32 77
33#define RS5C372_TRIM_XSL 0x80 78/* REVISIT: this assumes that:
34#define RS5C372_TRIM_MASK 0x7F 79 * - we're in the 21st century, so it's safe to ignore the century
80 * bit for rv5c38[67] (REG_MONTH bit 7);
81 * - we should use ALARM_A not ALARM_B (may be wrong on some boards)
82 */
83struct rs5c372 {
84 struct i2c_client *client;
85 struct rtc_device *rtc;
86 enum rtc_type type;
87 unsigned time24:1;
88 unsigned has_irq:1;
89 char buf[17];
90 char *regs;
91
92 /* on conversion to a "new style" i2c driver, this vanishes */
93 struct i2c_client dev;
94};
35 95
36#define RS5C372_REG_BASE 0 96static int rs5c_get_regs(struct rs5c372 *rs5c)
97{
98 struct i2c_client *client = rs5c->client;
99 struct i2c_msg msgs[] = {
100 { client->addr, I2C_M_RD, sizeof rs5c->buf, rs5c->buf },
101 };
102
103 /* This implements the third reading method from the datasheet, using
104 * an internal address that's reset after each transaction (by STOP)
105 * to 0x0f ... so we read extra registers, and skip the first one.
106 *
107 * The first method doesn't work with the iop3xx adapter driver, on at
108 * least 80219 chips; this works around that bug.
109 */
110 if ((i2c_transfer(client->adapter, msgs, 1)) != 1) {
111 pr_debug("%s: can't read registers\n", rs5c->rtc->name);
112 return -EIO;
113 }
37 114
38static int rs5c372_attach(struct i2c_adapter *adapter); 115 dev_dbg(&client->dev,
39static int rs5c372_detach(struct i2c_client *client); 116 "%02x %02x %02x (%02x) %02x %02x %02x (%02x), "
40static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind); 117 "%02x %02x %02x, %02x %02x %02x; %02x %02x\n",
118 rs5c->regs[0], rs5c->regs[1], rs5c->regs[2], rs5c->regs[3],
119 rs5c->regs[4], rs5c->regs[5], rs5c->regs[6], rs5c->regs[7],
120 rs5c->regs[8], rs5c->regs[9], rs5c->regs[10], rs5c->regs[11],
121 rs5c->regs[12], rs5c->regs[13], rs5c->regs[14], rs5c->regs[15]);
41 122
42struct rs5c372 { 123 return 0;
43 u8 reg_addr; 124}
44 u8 regs[17];
45 struct i2c_msg msg[1];
46 struct i2c_client client;
47 struct rtc_device *rtc;
48};
49 125
50static struct i2c_driver rs5c372_driver = { 126static unsigned rs5c_reg2hr(struct rs5c372 *rs5c, unsigned reg)
51 .driver = { 127{
52 .name = "rs5c372", 128 unsigned hour;
53 },
54 .attach_adapter = &rs5c372_attach,
55 .detach_client = &rs5c372_detach,
56};
57 129
58static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm) 130 if (rs5c->time24)
131 return BCD2BIN(reg & 0x3f);
132
133 hour = BCD2BIN(reg & 0x1f);
134 if (hour == 12)
135 hour = 0;
136 if (reg & 0x20)
137 hour += 12;
138 return hour;
139}
140
141static unsigned rs5c_hr2reg(struct rs5c372 *rs5c, unsigned hour)
59{ 142{
143 if (rs5c->time24)
144 return BIN2BCD(hour);
145
146 if (hour > 12)
147 return 0x20 | BIN2BCD(hour - 12);
148 if (hour == 12)
149 return 0x20 | BIN2BCD(12);
150 if (hour == 0)
151 return BIN2BCD(12);
152 return BIN2BCD(hour);
153}
60 154
61 struct rs5c372 *rs5c372 = i2c_get_clientdata(client); 155static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm)
62 u8 *buf = &(rs5c372->regs[1]); 156{
157 struct rs5c372 *rs5c = i2c_get_clientdata(client);
158 int status = rs5c_get_regs(rs5c);
63 159
64 /* this implements the 3rd reading method, according 160 if (status < 0)
65 * to the datasheet. rs5c372 defaults to internal 161 return status;
66 * address 0xF, so 0x0 is in regs[1]
67 */
68 162
69 if ((i2c_transfer(client->adapter, rs5c372->msg, 1)) != 1) { 163 tm->tm_sec = BCD2BIN(rs5c->regs[RS5C372_REG_SECS] & 0x7f);
70 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 164 tm->tm_min = BCD2BIN(rs5c->regs[RS5C372_REG_MINS] & 0x7f);
71 return -EIO; 165 tm->tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C372_REG_HOURS]);
72 }
73 166
74 tm->tm_sec = BCD2BIN(buf[RS5C372_REG_SECS] & 0x7f); 167 tm->tm_wday = BCD2BIN(rs5c->regs[RS5C372_REG_WDAY] & 0x07);
75 tm->tm_min = BCD2BIN(buf[RS5C372_REG_MINS] & 0x7f); 168 tm->tm_mday = BCD2BIN(rs5c->regs[RS5C372_REG_DAY] & 0x3f);
76 tm->tm_hour = BCD2BIN(buf[RS5C372_REG_HOURS] & 0x3f);
77 tm->tm_wday = BCD2BIN(buf[RS5C372_REG_WDAY] & 0x07);
78 tm->tm_mday = BCD2BIN(buf[RS5C372_REG_DAY] & 0x3f);
79 169
80 /* tm->tm_mon is zero-based */ 170 /* tm->tm_mon is zero-based */
81 tm->tm_mon = BCD2BIN(buf[RS5C372_REG_MONTH] & 0x1f) - 1; 171 tm->tm_mon = BCD2BIN(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1;
82 172
83 /* year is 1900 + tm->tm_year */ 173 /* year is 1900 + tm->tm_year */
84 tm->tm_year = BCD2BIN(buf[RS5C372_REG_YEAR]) + 100; 174 tm->tm_year = BCD2BIN(rs5c->regs[RS5C372_REG_YEAR]) + 100;
85 175
86 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 176 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
87 "mday=%d, mon=%d, year=%d, wday=%d\n", 177 "mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -89,22 +179,25 @@ static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm)
89 tm->tm_sec, tm->tm_min, tm->tm_hour, 179 tm->tm_sec, tm->tm_min, tm->tm_hour,
90 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 180 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
91 181
92 return 0; 182 /* rtc might need initialization */
183 return rtc_valid_tm(tm);
93} 184}
94 185
95static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm) 186static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
96{ 187{
97 unsigned char buf[8] = { RS5C372_REG_BASE }; 188 struct rs5c372 *rs5c = i2c_get_clientdata(client);
189 unsigned char buf[8];
98 190
99 dev_dbg(&client->dev, 191 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d "
100 "%s: secs=%d, mins=%d, hours=%d "
101 "mday=%d, mon=%d, year=%d, wday=%d\n", 192 "mday=%d, mon=%d, year=%d, wday=%d\n",
102 __FUNCTION__, tm->tm_sec, tm->tm_min, tm->tm_hour, 193 __FUNCTION__,
194 tm->tm_sec, tm->tm_min, tm->tm_hour,
103 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 195 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
104 196
197 buf[0] = RS5C_ADDR(RS5C372_REG_SECS);
105 buf[1] = BIN2BCD(tm->tm_sec); 198 buf[1] = BIN2BCD(tm->tm_sec);
106 buf[2] = BIN2BCD(tm->tm_min); 199 buf[2] = BIN2BCD(tm->tm_min);
107 buf[3] = BIN2BCD(tm->tm_hour); 200 buf[3] = rs5c_hr2reg(rs5c, tm->tm_hour);
108 buf[4] = BIN2BCD(tm->tm_wday); 201 buf[4] = BIN2BCD(tm->tm_wday);
109 buf[5] = BIN2BCD(tm->tm_mday); 202 buf[5] = BIN2BCD(tm->tm_mday);
110 buf[6] = BIN2BCD(tm->tm_mon + 1); 203 buf[6] = BIN2BCD(tm->tm_mon + 1);
@@ -118,21 +211,43 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
118 return 0; 211 return 0;
119} 212}
120 213
214#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
215#define NEED_TRIM
216#endif
217
218#if defined(CONFIG_RTC_INTF_SYSFS) || defined(CONFIG_RTC_INTF_SYSFS_MODULE)
219#define NEED_TRIM
220#endif
221
222#ifdef NEED_TRIM
121static int rs5c372_get_trim(struct i2c_client *client, int *osc, int *trim) 223static int rs5c372_get_trim(struct i2c_client *client, int *osc, int *trim)
122{ 224{
123 struct rs5c372 *rs5c372 = i2c_get_clientdata(client); 225 struct rs5c372 *rs5c372 = i2c_get_clientdata(client);
124 u8 tmp = rs5c372->regs[RS5C372_REG_TRIM + 1]; 226 u8 tmp = rs5c372->regs[RS5C372_REG_TRIM];
125 227
126 if (osc) 228 if (osc)
127 *osc = (tmp & RS5C372_TRIM_XSL) ? 32000 : 32768; 229 *osc = (tmp & RS5C372_TRIM_XSL) ? 32000 : 32768;
128 230
129 if (trim) { 231 if (trim) {
130 *trim = tmp & RS5C372_TRIM_MASK; 232 dev_dbg(&client->dev, "%s: raw trim=%x\n", __FUNCTION__, tmp);
131 dev_dbg(&client->dev, "%s: raw trim=%x\n", __FUNCTION__, *trim); 233 tmp &= RS5C372_TRIM_MASK;
234 if (tmp & 0x3e) {
235 int t = tmp & 0x3f;
236
237 if (tmp & 0x40)
238 t = (~t | (s8)0xc0) + 1;
239 else
240 t = t - 1;
241
242 tmp = t * 2;
243 } else
244 tmp = 0;
245 *trim = tmp;
132 } 246 }
133 247
134 return 0; 248 return 0;
135} 249}
250#endif
136 251
137static int rs5c372_rtc_read_time(struct device *dev, struct rtc_time *tm) 252static int rs5c372_rtc_read_time(struct device *dev, struct rtc_time *tm)
138{ 253{
@@ -144,25 +259,190 @@ static int rs5c372_rtc_set_time(struct device *dev, struct rtc_time *tm)
144 return rs5c372_set_datetime(to_i2c_client(dev), tm); 259 return rs5c372_set_datetime(to_i2c_client(dev), tm);
145} 260}
146 261
262#if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE)
263
264static int
265rs5c_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
266{
267 struct i2c_client *client = to_i2c_client(dev);
268 struct rs5c372 *rs5c = i2c_get_clientdata(client);
269 unsigned char buf[2];
270 int status;
271
272 buf[1] = rs5c->regs[RS5C_REG_CTRL1];
273 switch (cmd) {
274 case RTC_UIE_OFF:
275 case RTC_UIE_ON:
276 /* some 327a modes use a different IRQ pin for 1Hz irqs */
277 if (rs5c->type == rtc_rs5c372a
278 && (buf[1] & RS5C372A_CTRL1_SL1))
279 return -ENOIOCTLCMD;
280 case RTC_AIE_OFF:
281 case RTC_AIE_ON:
282 /* these irq management calls only make sense for chips
283 * which are wired up to an IRQ.
284 */
285 if (!rs5c->has_irq)
286 return -ENOIOCTLCMD;
287 break;
288 default:
289 return -ENOIOCTLCMD;
290 }
291
292 status = rs5c_get_regs(rs5c);
293 if (status < 0)
294 return status;
295
296 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1);
297 switch (cmd) {
298 case RTC_AIE_OFF: /* alarm off */
299 buf[1] &= ~RS5C_CTRL1_AALE;
300 break;
301 case RTC_AIE_ON: /* alarm on */
302 buf[1] |= RS5C_CTRL1_AALE;
303 break;
304 case RTC_UIE_OFF: /* update off */
305 buf[1] &= ~RS5C_CTRL1_CT_MASK;
306 break;
307 case RTC_UIE_ON: /* update on */
308 buf[1] &= ~RS5C_CTRL1_CT_MASK;
309 buf[1] |= RS5C_CTRL1_CT4;
310 break;
311 }
312 if ((i2c_master_send(client, buf, 2)) != 2) {
313 printk(KERN_WARNING "%s: can't update alarm\n",
314 rs5c->rtc->name);
315 status = -EIO;
316 } else
317 rs5c->regs[RS5C_REG_CTRL1] = buf[1];
318 return status;
319}
320
321#else
322#define rs5c_rtc_ioctl NULL
323#endif
324
325
326/* NOTE: Since RTC_WKALM_{RD,SET} were originally defined for EFI,
327 * which only exposes a polled programming interface; and since
328 * these calls map directly to those EFI requests; we don't demand
329 * we have an IRQ for this chip when we go through this API.
330 *
331 * The older x86_pc derived RTC_ALM_{READ,SET} calls require irqs
332 * though, managed through RTC_AIE_{ON,OFF} requests.
333 */
334
335static int rs5c_read_alarm(struct device *dev, struct rtc_wkalrm *t)
336{
337 struct i2c_client *client = to_i2c_client(dev);
338 struct rs5c372 *rs5c = i2c_get_clientdata(client);
339 int status;
340
341 status = rs5c_get_regs(rs5c);
342 if (status < 0)
343 return status;
344
345 /* report alarm time */
346 t->time.tm_sec = 0;
347 t->time.tm_min = BCD2BIN(rs5c->regs[RS5C_REG_ALARM_A_MIN] & 0x7f);
348 t->time.tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C_REG_ALARM_A_HOURS]);
349 t->time.tm_mday = -1;
350 t->time.tm_mon = -1;
351 t->time.tm_year = -1;
352 t->time.tm_wday = -1;
353 t->time.tm_yday = -1;
354 t->time.tm_isdst = -1;
355
356 /* ... and status */
357 t->enabled = !!(rs5c->regs[RS5C_REG_CTRL1] & RS5C_CTRL1_AALE);
358 t->pending = !!(rs5c->regs[RS5C_REG_CTRL2] & RS5C_CTRL2_AAFG);
359
360 return 0;
361}
362
363static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t)
364{
365 struct i2c_client *client = to_i2c_client(dev);
366 struct rs5c372 *rs5c = i2c_get_clientdata(client);
367 int status;
368 unsigned char buf[4];
369
370 /* only handle up to 24 hours in the future, like RTC_ALM_SET */
371 if (t->time.tm_mday != -1
372 || t->time.tm_mon != -1
373 || t->time.tm_year != -1)
374 return -EINVAL;
375
376 /* REVISIT: round up tm_sec */
377
378 /* if needed, disable irq (clears pending status) */
379 status = rs5c_get_regs(rs5c);
380 if (status < 0)
381 return status;
382 if (rs5c->regs[RS5C_REG_CTRL1] & RS5C_CTRL1_AALE) {
383 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1);
384 buf[1] = rs5c->regs[RS5C_REG_CTRL1] & ~RS5C_CTRL1_AALE;
385 if (i2c_master_send(client, buf, 2) != 2) {
386 pr_debug("%s: can't disable alarm\n", rs5c->rtc->name);
387 return -EIO;
388 }
389 rs5c->regs[RS5C_REG_CTRL1] = buf[1];
390 }
391
392 /* set alarm */
393 buf[0] = RS5C_ADDR(RS5C_REG_ALARM_A_MIN);
394 buf[1] = BIN2BCD(t->time.tm_min);
395 buf[2] = rs5c_hr2reg(rs5c, t->time.tm_hour);
396 buf[3] = 0x7f; /* any/all days */
397 if ((i2c_master_send(client, buf, 4)) != 4) {
398 pr_debug("%s: can't set alarm time\n", rs5c->rtc->name);
399 return -EIO;
400 }
401
402 /* ... and maybe enable its irq */
403 if (t->enabled) {
404 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1);
405 buf[1] = rs5c->regs[RS5C_REG_CTRL1] | RS5C_CTRL1_AALE;
406 if ((i2c_master_send(client, buf, 2)) != 2)
407 printk(KERN_WARNING "%s: can't enable alarm\n",
408 rs5c->rtc->name);
409 rs5c->regs[RS5C_REG_CTRL1] = buf[1];
410 }
411
412 return 0;
413}
414
415#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
416
147static int rs5c372_rtc_proc(struct device *dev, struct seq_file *seq) 417static int rs5c372_rtc_proc(struct device *dev, struct seq_file *seq)
148{ 418{
149 int err, osc, trim; 419 int err, osc, trim;
150 420
151 err = rs5c372_get_trim(to_i2c_client(dev), &osc, &trim); 421 err = rs5c372_get_trim(to_i2c_client(dev), &osc, &trim);
152 if (err == 0) { 422 if (err == 0) {
153 seq_printf(seq, "%d.%03d KHz\n", osc / 1000, osc % 1000); 423 seq_printf(seq, "crystal\t\t: %d.%03d KHz\n",
154 seq_printf(seq, "trim\t: %d\n", trim); 424 osc / 1000, osc % 1000);
425 seq_printf(seq, "trim\t\t: %d\n", trim);
155 } 426 }
156 427
157 return 0; 428 return 0;
158} 429}
159 430
431#else
432#define rs5c372_rtc_proc NULL
433#endif
434
160static const struct rtc_class_ops rs5c372_rtc_ops = { 435static const struct rtc_class_ops rs5c372_rtc_ops = {
161 .proc = rs5c372_rtc_proc, 436 .proc = rs5c372_rtc_proc,
437 .ioctl = rs5c_rtc_ioctl,
162 .read_time = rs5c372_rtc_read_time, 438 .read_time = rs5c372_rtc_read_time,
163 .set_time = rs5c372_rtc_set_time, 439 .set_time = rs5c372_rtc_set_time,
440 .read_alarm = rs5c_read_alarm,
441 .set_alarm = rs5c_set_alarm,
164}; 442};
165 443
444#if defined(CONFIG_RTC_INTF_SYSFS) || defined(CONFIG_RTC_INTF_SYSFS_MODULE)
445
166static ssize_t rs5c372_sysfs_show_trim(struct device *dev, 446static ssize_t rs5c372_sysfs_show_trim(struct device *dev,
167 struct device_attribute *attr, char *buf) 447 struct device_attribute *attr, char *buf)
168{ 448{
@@ -172,7 +452,7 @@ static ssize_t rs5c372_sysfs_show_trim(struct device *dev,
172 if (err) 452 if (err)
173 return err; 453 return err;
174 454
175 return sprintf(buf, "0x%2x\n", trim); 455 return sprintf(buf, "%d\n", trim);
176} 456}
177static DEVICE_ATTR(trim, S_IRUGO, rs5c372_sysfs_show_trim, NULL); 457static DEVICE_ATTR(trim, S_IRUGO, rs5c372_sysfs_show_trim, NULL);
178 458
@@ -189,16 +469,35 @@ static ssize_t rs5c372_sysfs_show_osc(struct device *dev,
189} 469}
190static DEVICE_ATTR(osc, S_IRUGO, rs5c372_sysfs_show_osc, NULL); 470static DEVICE_ATTR(osc, S_IRUGO, rs5c372_sysfs_show_osc, NULL);
191 471
192static int rs5c372_attach(struct i2c_adapter *adapter) 472static int rs5c_sysfs_register(struct device *dev)
193{ 473{
194 return i2c_probe(adapter, &addr_data, rs5c372_probe); 474 int err;
475
476 err = device_create_file(dev, &dev_attr_trim);
477 if (err)
478 return err;
479 err = device_create_file(dev, &dev_attr_osc);
480 if (err)
481 device_remove_file(dev, &dev_attr_trim);
482
483 return err;
484}
485
486#else
487static int rs5c_sysfs_register(struct device *dev)
488{
489 return 0;
195} 490}
491#endif /* SYSFS */
492
493static struct i2c_driver rs5c372_driver;
196 494
197static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind) 495static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind)
198{ 496{
199 int err = 0; 497 int err = 0;
200 struct i2c_client *client; 498 struct i2c_client *client;
201 struct rs5c372 *rs5c372; 499 struct rs5c372 *rs5c372;
500 struct rtc_time tm;
202 501
203 dev_dbg(adapter->class_dev.dev, "%s\n", __FUNCTION__); 502 dev_dbg(adapter->class_dev.dev, "%s\n", __FUNCTION__);
204 503
@@ -211,7 +510,15 @@ static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind)
211 err = -ENOMEM; 510 err = -ENOMEM;
212 goto exit; 511 goto exit;
213 } 512 }
214 client = &rs5c372->client; 513
514 /* we read registers 0x0f then 0x00-0x0f; skip the first one */
515 rs5c372->regs=&rs5c372->buf[1];
516
517 /* On conversion to a "new style" i2c driver, we'll be handed
518 * the i2c_client (we won't create it)
519 */
520 client = &rs5c372->dev;
521 rs5c372->client = client;
215 522
216 /* I2C client */ 523 /* I2C client */
217 client->addr = address; 524 client->addr = address;
@@ -222,16 +529,99 @@ static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind)
222 529
223 i2c_set_clientdata(client, rs5c372); 530 i2c_set_clientdata(client, rs5c372);
224 531
225 rs5c372->msg[0].addr = address;
226 rs5c372->msg[0].flags = I2C_M_RD;
227 rs5c372->msg[0].len = sizeof(rs5c372->regs);
228 rs5c372->msg[0].buf = rs5c372->regs;
229
230 /* Inform the i2c layer */ 532 /* Inform the i2c layer */
231 if ((err = i2c_attach_client(client))) 533 if ((err = i2c_attach_client(client)))
232 goto exit_kfree; 534 goto exit_kfree;
233 535
234 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 536 err = rs5c_get_regs(rs5c372);
537 if (err < 0)
538 goto exit_detach;
539
540 /* For "new style" drivers, irq is in i2c_client and chip type
541 * info comes from i2c_client.dev.platform_data. Meanwhile:
542 *
543 * STICK BOARD-SPECIFIC SETUP CODE RIGHT HERE
544 */
545 if (rs5c372->type == rtc_undef) {
546 rs5c372->type = rtc_rs5c372b;
547 dev_warn(&client->dev, "assuming rs5c372b\n");
548 }
549
550 /* clock may be set for am/pm or 24 hr time */
551 switch (rs5c372->type) {
552 case rtc_rs5c372a:
553 case rtc_rs5c372b:
554 /* alarm uses ALARM_A; and nINTRA on 372a, nINTR on 372b.
555 * so does periodic irq, except some 327a modes.
556 */
557 if (rs5c372->regs[RS5C_REG_CTRL2] & RS5C372_CTRL2_24)
558 rs5c372->time24 = 1;
559 break;
560 case rtc_rv5c386:
561 case rtc_rv5c387a:
562 if (rs5c372->regs[RS5C_REG_CTRL1] & RV5C387_CTRL1_24)
563 rs5c372->time24 = 1;
564 /* alarm uses ALARM_W; and nINTRB for alarm and periodic
565 * irq, on both 386 and 387
566 */
567 break;
568 default:
569 dev_err(&client->dev, "unknown RTC type\n");
570 goto exit_detach;
571 }
572
573 /* if the oscillator lost power and no other software (like
574 * the bootloader) set it up, do it here.
575 */
576 if (rs5c372->regs[RS5C_REG_CTRL2] & RS5C_CTRL2_XSTP) {
577 unsigned char buf[3];
578
579 rs5c372->regs[RS5C_REG_CTRL2] &= ~RS5C_CTRL2_XSTP;
580
581 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1);
582 buf[1] = rs5c372->regs[RS5C_REG_CTRL1];
583 buf[2] = rs5c372->regs[RS5C_REG_CTRL2];
584
585 /* use 24hr mode */
586 switch (rs5c372->type) {
587 case rtc_rs5c372a:
588 case rtc_rs5c372b:
589 buf[2] |= RS5C372_CTRL2_24;
590 rs5c372->time24 = 1;
591 break;
592 case rtc_rv5c386:
593 case rtc_rv5c387a:
594 buf[1] |= RV5C387_CTRL1_24;
595 rs5c372->time24 = 1;
596 break;
597 default:
598 /* impossible */
599 break;
600 }
601
602 if ((i2c_master_send(client, buf, 3)) != 3) {
603 dev_err(&client->dev, "setup error\n");
604 goto exit_detach;
605 }
606 rs5c372->regs[RS5C_REG_CTRL1] = buf[1];
607 rs5c372->regs[RS5C_REG_CTRL2] = buf[2];
608 }
609
610 if (rs5c372_get_datetime(client, &tm) < 0)
611 dev_warn(&client->dev, "clock needs to be set\n");
612
613 dev_info(&client->dev, "%s found, %s, driver version " DRV_VERSION "\n",
614 ({ char *s; switch (rs5c372->type) {
615 case rtc_rs5c372a: s = "rs5c372a"; break;
616 case rtc_rs5c372b: s = "rs5c372b"; break;
617 case rtc_rv5c386: s = "rv5c386"; break;
618 case rtc_rv5c387a: s = "rv5c387a"; break;
619 default: s = "chip"; break;
620 }; s;}),
621 rs5c372->time24 ? "24hr" : "am/pm"
622 );
623
624 /* FIXME when client->irq exists, use it to register alarm irq */
235 625
236 rs5c372->rtc = rtc_device_register(rs5c372_driver.driver.name, 626 rs5c372->rtc = rtc_device_register(rs5c372_driver.driver.name,
237 &client->dev, &rs5c372_rtc_ops, THIS_MODULE); 627 &client->dev, &rs5c372_rtc_ops, THIS_MODULE);
@@ -241,18 +631,12 @@ static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind)
241 goto exit_detach; 631 goto exit_detach;
242 } 632 }
243 633
244 err = device_create_file(&client->dev, &dev_attr_trim); 634 err = rs5c_sysfs_register(&client->dev);
245 if (err) 635 if (err)
246 goto exit_devreg; 636 goto exit_devreg;
247 err = device_create_file(&client->dev, &dev_attr_osc);
248 if (err)
249 goto exit_trim;
250 637
251 return 0; 638 return 0;
252 639
253exit_trim:
254 device_remove_file(&client->dev, &dev_attr_trim);
255
256exit_devreg: 640exit_devreg:
257 rtc_device_unregister(rs5c372->rtc); 641 rtc_device_unregister(rs5c372->rtc);
258 642
@@ -266,6 +650,11 @@ exit:
266 return err; 650 return err;
267} 651}
268 652
653static int rs5c372_attach(struct i2c_adapter *adapter)
654{
655 return i2c_probe(adapter, &addr_data, rs5c372_probe);
656}
657
269static int rs5c372_detach(struct i2c_client *client) 658static int rs5c372_detach(struct i2c_client *client)
270{ 659{
271 int err; 660 int err;
@@ -274,6 +663,8 @@ static int rs5c372_detach(struct i2c_client *client)
274 if (rs5c372->rtc) 663 if (rs5c372->rtc)
275 rtc_device_unregister(rs5c372->rtc); 664 rtc_device_unregister(rs5c372->rtc);
276 665
666 /* REVISIT properly destroy the sysfs files ... */
667
277 if ((err = i2c_detach_client(client))) 668 if ((err = i2c_detach_client(client)))
278 return err; 669 return err;
279 670
@@ -281,6 +672,14 @@ static int rs5c372_detach(struct i2c_client *client)
281 return 0; 672 return 0;
282} 673}
283 674
675static struct i2c_driver rs5c372_driver = {
676 .driver = {
677 .name = "rtc-rs5c372",
678 },
679 .attach_adapter = &rs5c372_attach,
680 .detach_client = &rs5c372_detach,
681};
682
284static __init int rs5c372_init(void) 683static __init int rs5c372_init(void)
285{ 684{
286 return i2c_add_driver(&rs5c372_driver); 685 return i2c_add_driver(&rs5c372_driver);
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 72ba1a70f3..198b9f22fb 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -264,8 +264,6 @@ static int sh_rtc_proc(struct device *dev, struct seq_file *seq)
264 unsigned int tmp; 264 unsigned int tmp;
265 265
266 tmp = readb(rtc->regbase + RCR1); 266 tmp = readb(rtc->regbase + RCR1);
267 seq_printf(seq, "alarm_IRQ\t: %s\n",
268 (tmp & RCR1_AIE) ? "yes" : "no");
269 seq_printf(seq, "carry_IRQ\t: %s\n", 267 seq_printf(seq, "carry_IRQ\t: %s\n",
270 (tmp & RCR1_CIE) ? "yes" : "no"); 268 (tmp & RCR1_CIE) ? "yes" : "no");
271 269
@@ -428,6 +426,8 @@ static int sh_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
428 tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */ 426 tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */
429 tm->tm_year = 0xffff; 427 tm->tm_year = 0xffff;
430 428
429 wkalrm->enabled = (readb(rtc->regbase + RCR1) & RCR1_AIE) ? 1 : 0;
430
431 spin_unlock_irq(&rtc->lock); 431 spin_unlock_irq(&rtc->lock);
432 432
433 return 0; 433 return 0;
@@ -492,10 +492,10 @@ static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
492 492
493 spin_lock_irq(&rtc->lock); 493 spin_lock_irq(&rtc->lock);
494 494
495 /* disable alarm interrupt and clear flag */ 495 /* disable alarm interrupt and clear the alarm flag */
496 rcr1 = readb(rtc->regbase + RCR1); 496 rcr1 = readb(rtc->regbase + RCR1);
497 rcr1 &= ~RCR1_AF; 497 rcr1 &= ~(RCR1_AF|RCR1_AIE);
498 writeb(rcr1 & ~RCR1_AIE, rtc->regbase + RCR1); 498 writeb(rcr1, rtc->regbase + RCR1);
499 499
500 rtc->rearm_aie = 0; 500 rtc->rearm_aie = 0;
501 501
@@ -510,8 +510,10 @@ static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
510 mon += 1; 510 mon += 1;
511 sh_rtc_write_alarm_value(rtc, mon, RMONAR); 511 sh_rtc_write_alarm_value(rtc, mon, RMONAR);
512 512
513 /* Restore interrupt activation status */ 513 if (wkalrm->enabled) {
514 writeb(rcr1, rtc->regbase + RCR1); 514 rcr1 |= RCR1_AIE;
515 writeb(rcr1, rtc->regbase + RCR1);
516 }
515 517
516 spin_unlock_irq(&rtc->lock); 518 spin_unlock_irq(&rtc->lock);
517 519
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 9418a59fb3..2ddd0cf071 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -78,7 +78,7 @@ static struct attribute_group rtc_attr_group = {
78 .attrs = rtc_attrs, 78 .attrs = rtc_attrs,
79}; 79};
80 80
81static int __devinit rtc_sysfs_add_device(struct class_device *class_dev, 81static int rtc_sysfs_add_device(struct class_device *class_dev,
82 struct class_interface *class_intf) 82 struct class_interface *class_intf)
83{ 83{
84 int err; 84 int err;
diff --git a/drivers/s390/char/monwriter.c b/drivers/s390/char/monwriter.c
index b9b0fc3f81..cdb24f5281 100644
--- a/drivers/s390/char/monwriter.c
+++ b/drivers/s390/char/monwriter.c
@@ -23,7 +23,7 @@
23#include <asm/appldata.h> 23#include <asm/appldata.h>
24#include <asm/monwriter.h> 24#include <asm/monwriter.h>
25 25
26#define MONWRITE_MAX_DATALEN 4024 26#define MONWRITE_MAX_DATALEN 4010
27 27
28static int mon_max_bufs = 255; 28static int mon_max_bufs = 255;
29static int mon_buf_count; 29static int mon_buf_count;
diff --git a/drivers/s390/char/sclp_cpi.c b/drivers/s390/char/sclp_cpi.c
index f7c10d954e..4f873ae148 100644
--- a/drivers/s390/char/sclp_cpi.c
+++ b/drivers/s390/char/sclp_cpi.c
@@ -49,6 +49,8 @@ static struct sclp_register sclp_cpi_event =
49 .send_mask = EvTyp_CtlProgIdent_Mask 49 .send_mask = EvTyp_CtlProgIdent_Mask
50}; 50};
51 51
52MODULE_LICENSE("GPL");
53
52MODULE_AUTHOR( 54MODULE_AUTHOR(
53 "Martin Peschke, IBM Deutschland Entwicklung GmbH " 55 "Martin Peschke, IBM Deutschland Entwicklung GmbH "
54 "<mpeschke@de.ibm.com>"); 56 "<mpeschke@de.ibm.com>");
diff --git a/drivers/s390/char/vmcp.c b/drivers/s390/char/vmcp.c
index 1678b6c757..a420cd0990 100644
--- a/drivers/s390/char/vmcp.c
+++ b/drivers/s390/char/vmcp.c
@@ -117,7 +117,7 @@ vmcp_write(struct file *file, const char __user * buff, size_t count,
117 return -ENOMEM; 117 return -ENOMEM;
118 } 118 }
119 debug_text_event(vmcp_debug, 1, cmd); 119 debug_text_event(vmcp_debug, 1, cmd);
120 session->resp_size = __cpcmd(cmd, session->response, 120 session->resp_size = cpcmd(cmd, session->response,
121 session->bufsize, 121 session->bufsize,
122 &session->resp_code); 122 &session->resp_code);
123 up(&session->mutex); 123 up(&session->mutex);
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index 7835a714a4..ae1bf231d0 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -2,8 +2,7 @@
2 * drivers/s390/cio/cio.c 2 * drivers/s390/cio/cio.c
3 * S/390 common I/O routines -- low level i/o calls 3 * S/390 common I/O routines -- low level i/o calls
4 * 4 *
5 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH, 5 * Copyright (C) IBM Corp. 1999,2006
6 * IBM Corporation
7 * Author(s): Ingo Adlung (adlung@de.ibm.com) 6 * Author(s): Ingo Adlung (adlung@de.ibm.com)
8 * Cornelia Huck (cornelia.huck@de.ibm.com) 7 * Cornelia Huck (cornelia.huck@de.ibm.com)
9 * Arnd Bergmann (arndb@de.ibm.com) 8 * Arnd Bergmann (arndb@de.ibm.com)
@@ -871,11 +870,36 @@ __clear_subchannel_easy(struct subchannel_id schid)
871 return -EBUSY; 870 return -EBUSY;
872} 871}
873 872
873static int pgm_check_occured;
874
875static void cio_reset_pgm_check_handler(void)
876{
877 pgm_check_occured = 1;
878}
879
880static int stsch_reset(struct subchannel_id schid, volatile struct schib *addr)
881{
882 int rc;
883
884 pgm_check_occured = 0;
885 s390_reset_pgm_handler = cio_reset_pgm_check_handler;
886 rc = stsch(schid, addr);
887 s390_reset_pgm_handler = NULL;
888
889 /* The program check handler could have changed pgm_check_occured */
890 barrier();
891
892 if (pgm_check_occured)
893 return -EIO;
894 else
895 return rc;
896}
897
874static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data) 898static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
875{ 899{
876 struct schib schib; 900 struct schib schib;
877 901
878 if (stsch_err(schid, &schib)) 902 if (stsch_reset(schid, &schib))
879 return -ENXIO; 903 return -ENXIO;
880 if (!schib.pmcw.ena) 904 if (!schib.pmcw.ena)
881 return 0; 905 return 0;
@@ -972,7 +996,7 @@ static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
972 struct schib schib; 996 struct schib schib;
973 struct sch_match_id *match_id = data; 997 struct sch_match_id *match_id = data;
974 998
975 if (stsch_err(schid, &schib)) 999 if (stsch_reset(schid, &schib))
976 return -ENXIO; 1000 return -ENXIO;
977 if (schib.pmcw.dnv && 1001 if (schib.pmcw.dnv &&
978 (schib.pmcw.dev == match_id->devid.devno) && 1002 (schib.pmcw.dev == match_id->devid.devno) &&
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index 4c81d89079..9d6c024468 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -139,6 +139,8 @@ css_register_subchannel(struct subchannel *sch)
139 sch->dev.release = &css_subchannel_release; 139 sch->dev.release = &css_subchannel_release;
140 sch->dev.groups = subch_attr_groups; 140 sch->dev.groups = subch_attr_groups;
141 141
142 css_get_ssd_info(sch);
143
142 /* make it known to the system */ 144 /* make it known to the system */
143 ret = css_sch_device_register(sch); 145 ret = css_sch_device_register(sch);
144 if (ret) { 146 if (ret) {
@@ -146,7 +148,6 @@ css_register_subchannel(struct subchannel *sch)
146 __func__, sch->dev.bus_id); 148 __func__, sch->dev.bus_id);
147 return ret; 149 return ret;
148 } 150 }
149 css_get_ssd_info(sch);
150 return ret; 151 return ret;
151} 152}
152 153
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index 9d4ea449a6..6fd1940842 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -979,12 +979,11 @@ __qdio_outbound_processing(struct qdio_q *q)
979 979
980 if (q->is_iqdio_q) { 980 if (q->is_iqdio_q) {
981 /* 981 /*
982 * for asynchronous queues, we better check, if the fill 982 * for asynchronous queues, we better check, if the sent
983 * level is too high. for synchronous queues, the fill 983 * buffer is already switched from PRIMED to EMPTY.
984 * level will never be that high.
985 */ 984 */
986 if (atomic_read(&q->number_of_buffers_used)> 985 if ((q->queue_type == QDIO_IQDIO_QFMT_ASYNCH) &&
987 IQDIO_FILL_LEVEL_TO_POLL) 986 !qdio_is_outbound_q_done(q))
988 qdio_mark_q(q); 987 qdio_mark_q(q);
989 988
990 } else if (!q->hydra_gives_outbound_pcis) 989 } else if (!q->hydra_gives_outbound_pcis)
@@ -1825,6 +1824,10 @@ qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev,
1825 q->sbal[j]=*(outbound_sbals_array++); 1824 q->sbal[j]=*(outbound_sbals_array++);
1826 1825
1827 q->queue_type=q_format; 1826 q->queue_type=q_format;
1827 if ((q->queue_type == QDIO_IQDIO_QFMT) &&
1828 (no_output_qs > 1) &&
1829 (i == no_output_qs-1))
1830 q->queue_type = QDIO_IQDIO_QFMT_ASYNCH;
1828 q->int_parm=int_parm; 1831 q->int_parm=int_parm;
1829 q->is_input_q=0; 1832 q->is_input_q=0;
1830 q->schid = irq_ptr->schid; 1833 q->schid = irq_ptr->schid;
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index ad60afe5dd..81b5899f40 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -1129,7 +1129,15 @@ static void ap_poll_thread_stop(void)
1129 mutex_unlock(&ap_poll_thread_mutex); 1129 mutex_unlock(&ap_poll_thread_mutex);
1130} 1130}
1131 1131
1132static void ap_reset(void) 1132static void ap_reset_domain(void)
1133{
1134 int i;
1135
1136 for (i = 0; i < AP_DEVICES; i++)
1137 ap_reset_queue(AP_MKQID(i, ap_domain_index));
1138}
1139
1140static void ap_reset_all(void)
1133{ 1141{
1134 int i, j; 1142 int i, j;
1135 1143
@@ -1139,7 +1147,7 @@ static void ap_reset(void)
1139} 1147}
1140 1148
1141static struct reset_call ap_reset_call = { 1149static struct reset_call ap_reset_call = {
1142 .fn = ap_reset, 1150 .fn = ap_reset_all,
1143}; 1151};
1144 1152
1145/** 1153/**
@@ -1229,10 +1237,12 @@ void ap_module_exit(void)
1229 int i; 1237 int i;
1230 struct device *dev; 1238 struct device *dev;
1231 1239
1240 ap_reset_domain();
1232 ap_poll_thread_stop(); 1241 ap_poll_thread_stop();
1233 del_timer_sync(&ap_config_timer); 1242 del_timer_sync(&ap_config_timer);
1234 del_timer_sync(&ap_poll_timer); 1243 del_timer_sync(&ap_poll_timer);
1235 destroy_workqueue(ap_work_queue); 1244 destroy_workqueue(ap_work_queue);
1245 tasklet_kill(&ap_tasklet);
1236 s390_root_dev_unregister(ap_root_device); 1246 s390_root_dev_unregister(ap_root_device);
1237 while ((dev = bus_find_device(&ap_bus_type, NULL, NULL, 1247 while ((dev = bus_find_device(&ap_bus_type, NULL, NULL,
1238 __ap_match_all))) 1248 __ap_match_all)))
diff --git a/drivers/s390/net/Kconfig b/drivers/s390/net/Kconfig
index 1a93fa684e..52625153a4 100644
--- a/drivers/s390/net/Kconfig
+++ b/drivers/s390/net/Kconfig
@@ -27,10 +27,7 @@ config IUCV
27 help 27 help
28 Select this option if you want to use inter-user communication 28 Select this option if you want to use inter-user communication
29 under VM or VIF. If unsure, say "Y" to enable a fast communication 29 under VM or VIF. If unsure, say "Y" to enable a fast communication
30 link between VM guests. At boot time the user ID of the guest needs 30 link between VM guests.
31 to be passed to the kernel. Note that both kernels need to be
32 compiled with this option and both need to be booted with the user ID
33 of the other VM guest.
34 31
35config NETIUCV 32config NETIUCV
36 tristate "IUCV network device support (VM only)" 33 tristate "IUCV network device support (VM only)"
diff --git a/drivers/s390/net/qeth.h b/drivers/s390/net/qeth.h
index 53c358c7d3..e95c281f1e 100644
--- a/drivers/s390/net/qeth.h
+++ b/drivers/s390/net/qeth.h
@@ -710,7 +710,7 @@ struct qeth_reply {
710 int (*callback)(struct qeth_card *,struct qeth_reply *,unsigned long); 710 int (*callback)(struct qeth_card *,struct qeth_reply *,unsigned long);
711 u32 seqno; 711 u32 seqno;
712 unsigned long offset; 712 unsigned long offset;
713 int received; 713 atomic_t received;
714 int rc; 714 int rc;
715 void *param; 715 void *param;
716 struct qeth_card *card; 716 struct qeth_card *card;
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index 2bde4f1fb9..d2efa5ff12 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -471,7 +471,7 @@ qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
471 channel->state == CH_STATE_UP) 471 channel->state == CH_STATE_UP)
472 qeth_issue_next_read(card); 472 qeth_issue_next_read(card);
473 473
474 tasklet_schedule(&channel->irq_tasklet); 474 qeth_irq_tasklet((unsigned long)channel);
475 return; 475 return;
476out: 476out:
477 wake_up(&card->wait_q); 477 wake_up(&card->wait_q);
@@ -951,40 +951,6 @@ qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
951} 951}
952 952
953static int 953static int
954qeth_register_ip_addresses(void *ptr)
955{
956 struct qeth_card *card;
957
958 card = (struct qeth_card *) ptr;
959 daemonize("qeth_reg_ip");
960 QETH_DBF_TEXT(trace,4,"regipth1");
961 if (!qeth_do_run_thread(card, QETH_SET_IP_THREAD))
962 return 0;
963 QETH_DBF_TEXT(trace,4,"regipth2");
964 qeth_set_ip_addr_list(card);
965 qeth_clear_thread_running_bit(card, QETH_SET_IP_THREAD);
966 return 0;
967}
968
969/*
970 * Drive the SET_PROMISC_MODE thread
971 */
972static int
973qeth_set_promisc_mode(void *ptr)
974{
975 struct qeth_card *card = (struct qeth_card *) ptr;
976
977 daemonize("qeth_setprm");
978 QETH_DBF_TEXT(trace,4,"setprm1");
979 if (!qeth_do_run_thread(card, QETH_SET_PROMISC_MODE_THREAD))
980 return 0;
981 QETH_DBF_TEXT(trace,4,"setprm2");
982 qeth_setadp_promisc_mode(card);
983 qeth_clear_thread_running_bit(card, QETH_SET_PROMISC_MODE_THREAD);
984 return 0;
985}
986
987static int
988qeth_recover(void *ptr) 954qeth_recover(void *ptr)
989{ 955{
990 struct qeth_card *card; 956 struct qeth_card *card;
@@ -1047,11 +1013,6 @@ qeth_start_kernel_thread(struct work_struct *work)
1047 if (card->read.state != CH_STATE_UP && 1013 if (card->read.state != CH_STATE_UP &&
1048 card->write.state != CH_STATE_UP) 1014 card->write.state != CH_STATE_UP)
1049 return; 1015 return;
1050
1051 if (qeth_do_start_thread(card, QETH_SET_IP_THREAD))
1052 kernel_thread(qeth_register_ip_addresses, (void *)card,SIGCHLD);
1053 if (qeth_do_start_thread(card, QETH_SET_PROMISC_MODE_THREAD))
1054 kernel_thread(qeth_set_promisc_mode, (void *)card, SIGCHLD);
1055 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD)) 1016 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1056 kernel_thread(qeth_recover, (void *) card, SIGCHLD); 1017 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1057} 1018}
@@ -1074,7 +1035,7 @@ qeth_set_intial_options(struct qeth_card *card)
1074 card->options.layer2 = 1; 1035 card->options.layer2 = 1;
1075 else 1036 else
1076 card->options.layer2 = 0; 1037 card->options.layer2 = 0;
1077 card->options.performance_stats = 1; 1038 card->options.performance_stats = 0;
1078} 1039}
1079 1040
1080/** 1041/**
@@ -1613,8 +1574,6 @@ qeth_issue_next_read(struct qeth_card *card)
1613 return -ENOMEM; 1574 return -ENOMEM;
1614 } 1575 }
1615 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE); 1576 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
1616 wait_event(card->wait_q,
1617 atomic_cmpxchg(&card->read.irq_pending, 0, 1) == 0);
1618 QETH_DBF_TEXT(trace, 6, "noirqpnd"); 1577 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1619 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw, 1578 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1620 (addr_t) iob, 0, 0); 1579 (addr_t) iob, 0, 0);
@@ -1635,6 +1594,7 @@ qeth_alloc_reply(struct qeth_card *card)
1635 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC); 1594 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
1636 if (reply){ 1595 if (reply){
1637 atomic_set(&reply->refcnt, 1); 1596 atomic_set(&reply->refcnt, 1);
1597 atomic_set(&reply->received, 0);
1638 reply->card = card; 1598 reply->card = card;
1639 }; 1599 };
1640 return reply; 1600 return reply;
@@ -1655,31 +1615,6 @@ qeth_put_reply(struct qeth_reply *reply)
1655 kfree(reply); 1615 kfree(reply);
1656} 1616}
1657 1617
1658static void
1659qeth_cmd_timeout(unsigned long data)
1660{
1661 struct qeth_reply *reply, *list_reply, *r;
1662 unsigned long flags;
1663
1664 reply = (struct qeth_reply *) data;
1665 spin_lock_irqsave(&reply->card->lock, flags);
1666 list_for_each_entry_safe(list_reply, r,
1667 &reply->card->cmd_waiter_list, list) {
1668 if (reply == list_reply){
1669 qeth_get_reply(reply);
1670 list_del_init(&reply->list);
1671 spin_unlock_irqrestore(&reply->card->lock, flags);
1672 reply->rc = -ETIME;
1673 reply->received = 1;
1674 wake_up(&reply->wait_q);
1675 qeth_put_reply(reply);
1676 return;
1677 }
1678 }
1679 spin_unlock_irqrestore(&reply->card->lock, flags);
1680}
1681
1682
1683static struct qeth_ipa_cmd * 1618static struct qeth_ipa_cmd *
1684qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob) 1619qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1685{ 1620{
@@ -1745,7 +1680,7 @@ qeth_clear_ipacmd_list(struct qeth_card *card)
1745 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) { 1680 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1746 qeth_get_reply(reply); 1681 qeth_get_reply(reply);
1747 reply->rc = -EIO; 1682 reply->rc = -EIO;
1748 reply->received = 1; 1683 atomic_inc(&reply->received);
1749 list_del_init(&reply->list); 1684 list_del_init(&reply->list);
1750 wake_up(&reply->wait_q); 1685 wake_up(&reply->wait_q);
1751 qeth_put_reply(reply); 1686 qeth_put_reply(reply);
@@ -1814,7 +1749,7 @@ qeth_send_control_data_cb(struct qeth_channel *channel,
1814 &card->cmd_waiter_list); 1749 &card->cmd_waiter_list);
1815 spin_unlock_irqrestore(&card->lock, flags); 1750 spin_unlock_irqrestore(&card->lock, flags);
1816 } else { 1751 } else {
1817 reply->received = 1; 1752 atomic_inc(&reply->received);
1818 wake_up(&reply->wait_q); 1753 wake_up(&reply->wait_q);
1819 } 1754 }
1820 qeth_put_reply(reply); 1755 qeth_put_reply(reply);
@@ -1858,7 +1793,7 @@ qeth_send_control_data(struct qeth_card *card, int len,
1858 int rc; 1793 int rc;
1859 unsigned long flags; 1794 unsigned long flags;
1860 struct qeth_reply *reply = NULL; 1795 struct qeth_reply *reply = NULL;
1861 struct timer_list timer; 1796 unsigned long timeout;
1862 1797
1863 QETH_DBF_TEXT(trace, 2, "sendctl"); 1798 QETH_DBF_TEXT(trace, 2, "sendctl");
1864 1799
@@ -1873,21 +1808,20 @@ qeth_send_control_data(struct qeth_card *card, int len,
1873 reply->seqno = QETH_IDX_COMMAND_SEQNO; 1808 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1874 else 1809 else
1875 reply->seqno = card->seqno.ipa++; 1810 reply->seqno = card->seqno.ipa++;
1876 init_timer(&timer);
1877 timer.function = qeth_cmd_timeout;
1878 timer.data = (unsigned long) reply;
1879 init_waitqueue_head(&reply->wait_q); 1811 init_waitqueue_head(&reply->wait_q);
1880 spin_lock_irqsave(&card->lock, flags); 1812 spin_lock_irqsave(&card->lock, flags);
1881 list_add_tail(&reply->list, &card->cmd_waiter_list); 1813 list_add_tail(&reply->list, &card->cmd_waiter_list);
1882 spin_unlock_irqrestore(&card->lock, flags); 1814 spin_unlock_irqrestore(&card->lock, flags);
1883 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN); 1815 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1884 wait_event(card->wait_q, 1816
1885 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); 1817 while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
1886 qeth_prepare_control_data(card, len, iob); 1818 qeth_prepare_control_data(card, len, iob);
1819
1887 if (IS_IPA(iob->data)) 1820 if (IS_IPA(iob->data))
1888 timer.expires = jiffies + QETH_IPA_TIMEOUT; 1821 timeout = jiffies + QETH_IPA_TIMEOUT;
1889 else 1822 else
1890 timer.expires = jiffies + QETH_TIMEOUT; 1823 timeout = jiffies + QETH_TIMEOUT;
1824
1891 QETH_DBF_TEXT(trace, 6, "noirqpnd"); 1825 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1892 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); 1826 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1893 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, 1827 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
@@ -1906,9 +1840,16 @@ qeth_send_control_data(struct qeth_card *card, int len,
1906 wake_up(&card->wait_q); 1840 wake_up(&card->wait_q);
1907 return rc; 1841 return rc;
1908 } 1842 }
1909 add_timer(&timer); 1843 while (!atomic_read(&reply->received)) {
1910 wait_event(reply->wait_q, reply->received); 1844 if (time_after(jiffies, timeout)) {
1911 del_timer_sync(&timer); 1845 spin_lock_irqsave(&reply->card->lock, flags);
1846 list_del_init(&reply->list);
1847 spin_unlock_irqrestore(&reply->card->lock, flags);
1848 reply->rc = -ETIME;
1849 atomic_inc(&reply->received);
1850 wake_up(&reply->wait_q);
1851 }
1852 };
1912 rc = reply->rc; 1853 rc = reply->rc;
1913 qeth_put_reply(reply); 1854 qeth_put_reply(reply);
1914 return rc; 1855 return rc;
@@ -2466,32 +2407,17 @@ qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2466 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr); 2407 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2467} 2408}
2468 2409
2469static inline __u16 2410static inline void
2470qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb, 2411qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2471 struct qeth_hdr *hdr) 2412 struct qeth_hdr *hdr)
2472{ 2413{
2473 unsigned short vlan_id = 0;
2474#ifdef CONFIG_QETH_VLAN
2475 struct vlan_hdr *vhdr;
2476#endif
2477
2478 skb->pkt_type = PACKET_HOST; 2414 skb->pkt_type = PACKET_HOST;
2479 skb->protocol = qeth_type_trans(skb, skb->dev); 2415 skb->protocol = qeth_type_trans(skb, skb->dev);
2480 if (card->options.checksum_type == NO_CHECKSUMMING) 2416 if (card->options.checksum_type == NO_CHECKSUMMING)
2481 skb->ip_summed = CHECKSUM_UNNECESSARY; 2417 skb->ip_summed = CHECKSUM_UNNECESSARY;
2482 else 2418 else
2483 skb->ip_summed = CHECKSUM_NONE; 2419 skb->ip_summed = CHECKSUM_NONE;
2484#ifdef CONFIG_QETH_VLAN
2485 if (hdr->hdr.l2.flags[2] & (QETH_LAYER2_FLAG_VLAN)) {
2486 vhdr = (struct vlan_hdr *) skb->data;
2487 skb->protocol =
2488 __constant_htons(vhdr->h_vlan_encapsulated_proto);
2489 vlan_id = hdr->hdr.l2.vlan_id;
2490 skb_pull(skb, VLAN_HLEN);
2491 }
2492#endif
2493 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno; 2420 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
2494 return vlan_id;
2495} 2421}
2496 2422
2497static inline __u16 2423static inline __u16
@@ -2560,7 +2486,6 @@ qeth_process_inbound_buffer(struct qeth_card *card,
2560 int offset; 2486 int offset;
2561 int rxrc; 2487 int rxrc;
2562 __u16 vlan_tag = 0; 2488 __u16 vlan_tag = 0;
2563 __u16 *vlan_addr;
2564 2489
2565 /* get first element of current buffer */ 2490 /* get first element of current buffer */
2566 element = (struct qdio_buffer_element *)&buf->buffer->element[0]; 2491 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
@@ -2571,7 +2496,7 @@ qeth_process_inbound_buffer(struct qeth_card *card,
2571 &offset, &hdr))) { 2496 &offset, &hdr))) {
2572 skb->dev = card->dev; 2497 skb->dev = card->dev;
2573 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2) 2498 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2574 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr); 2499 qeth_layer2_rebuild_skb(card, skb, hdr);
2575 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3) 2500 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
2576 vlan_tag = qeth_rebuild_skb(card, skb, hdr); 2501 vlan_tag = qeth_rebuild_skb(card, skb, hdr);
2577 else { /*in case of OSN*/ 2502 else { /*in case of OSN*/
@@ -3968,13 +3893,22 @@ static inline struct sk_buff *
3968qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb, 3893qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb,
3969 struct qeth_hdr **hdr, int ipv) 3894 struct qeth_hdr **hdr, int ipv)
3970{ 3895{
3971 struct sk_buff *new_skb; 3896 struct sk_buff *new_skb, *new_skb2;
3972 3897
3973 QETH_DBF_TEXT(trace, 6, "prepskb"); 3898 QETH_DBF_TEXT(trace, 6, "prepskb");
3974 3899 new_skb = skb;
3975 new_skb = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr)); 3900 new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
3976 if (new_skb == NULL) 3901 if (!new_skb)
3902 return NULL;
3903 new_skb2 = qeth_realloc_headroom(card, new_skb,
3904 sizeof(struct qeth_hdr));
3905 if (!new_skb2) {
3906 __qeth_free_new_skb(skb, new_skb);
3977 return NULL; 3907 return NULL;
3908 }
3909 if (new_skb != skb)
3910 __qeth_free_new_skb(new_skb2, new_skb);
3911 new_skb = new_skb2;
3978 *hdr = __qeth_prepare_skb(card, new_skb, ipv); 3912 *hdr = __qeth_prepare_skb(card, new_skb, ipv);
3979 if (*hdr == NULL) { 3913 if (*hdr == NULL) {
3980 __qeth_free_new_skb(skb, new_skb); 3914 __qeth_free_new_skb(skb, new_skb);
@@ -4844,9 +4778,11 @@ qeth_arp_query(struct qeth_card *card, char __user *udata)
4844 "(0x%x/%d)\n", 4778 "(0x%x/%d)\n",
4845 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc), 4779 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4846 tmp, tmp); 4780 tmp, tmp);
4847 copy_to_user(udata, qinfo.udata, 4); 4781 if (copy_to_user(udata, qinfo.udata, 4))
4782 rc = -EFAULT;
4848 } else { 4783 } else {
4849 copy_to_user(udata, qinfo.udata, qinfo.udata_len); 4784 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
4785 rc = -EFAULT;
4850 } 4786 }
4851 kfree(qinfo.udata); 4787 kfree(qinfo.udata);
4852 return rc; 4788 return rc;
@@ -4992,8 +4928,10 @@ qeth_snmp_command(struct qeth_card *card, char __user *udata)
4992 if (rc) 4928 if (rc)
4993 PRINT_WARN("SNMP command failed on %s: (0x%x)\n", 4929 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
4994 QETH_CARD_IFNAME(card), rc); 4930 QETH_CARD_IFNAME(card), rc);
4995 else 4931 else {
4996 copy_to_user(udata, qinfo.udata, qinfo.udata_len); 4932 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
4933 rc = -EFAULT;
4934 }
4997 4935
4998 kfree(ureq); 4936 kfree(ureq);
4999 kfree(qinfo.udata); 4937 kfree(qinfo.udata);
@@ -5544,12 +5482,10 @@ qeth_set_multicast_list(struct net_device *dev)
5544 qeth_add_multicast_ipv6(card); 5482 qeth_add_multicast_ipv6(card);
5545#endif 5483#endif
5546out: 5484out:
5547 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) 5485 qeth_set_ip_addr_list(card);
5548 schedule_work(&card->kernel_thread_starter);
5549 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) 5486 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
5550 return; 5487 return;
5551 if (qeth_set_thread_start_bit(card, QETH_SET_PROMISC_MODE_THREAD)==0) 5488 qeth_setadp_promisc_mode(card);
5552 schedule_work(&card->kernel_thread_starter);
5553} 5489}
5554 5490
5555static int 5491static int
@@ -6351,6 +6287,42 @@ static struct ethtool_ops qeth_ethtool_ops = {
6351}; 6287};
6352 6288
6353static int 6289static int
6290qeth_hard_header_parse(struct sk_buff *skb, unsigned char *haddr)
6291{
6292 struct qeth_card *card;
6293 struct ethhdr *eth;
6294
6295 card = qeth_get_card_from_dev(skb->dev);
6296 if (card->options.layer2)
6297 goto haveheader;
6298#ifdef CONFIG_QETH_IPV6
6299 /* cause of the manipulated arp constructor and the ARP
6300 flag for OSAE devices we have some nasty exceptions */
6301 if (card->info.type == QETH_CARD_TYPE_OSAE) {
6302 if (!card->options.fake_ll) {
6303 if ((skb->pkt_type==PACKET_OUTGOING) &&
6304 (skb->protocol==ETH_P_IPV6))
6305 goto haveheader;
6306 else
6307 return 0;
6308 } else {
6309 if ((skb->pkt_type==PACKET_OUTGOING) &&
6310 (skb->protocol==ETH_P_IP))
6311 return 0;
6312 else
6313 goto haveheader;
6314 }
6315 }
6316#endif
6317 if (!card->options.fake_ll)
6318 return 0;
6319haveheader:
6320 eth = eth_hdr(skb);
6321 memcpy(haddr, eth->h_source, ETH_ALEN);
6322 return ETH_ALEN;
6323}
6324
6325static int
6354qeth_netdev_init(struct net_device *dev) 6326qeth_netdev_init(struct net_device *dev)
6355{ 6327{
6356 struct qeth_card *card; 6328 struct qeth_card *card;
@@ -6388,7 +6360,10 @@ qeth_netdev_init(struct net_device *dev)
6388 if (card->options.fake_ll && 6360 if (card->options.fake_ll &&
6389 (qeth_get_netdev_flags(card) & IFF_NOARP)) 6361 (qeth_get_netdev_flags(card) & IFF_NOARP))
6390 dev->hard_header = qeth_fake_header; 6362 dev->hard_header = qeth_fake_header;
6391 dev->hard_header_parse = NULL; 6363 if (dev->type == ARPHRD_IEEE802_TR)
6364 dev->hard_header_parse = NULL;
6365 else
6366 dev->hard_header_parse = qeth_hard_header_parse;
6392 dev->set_mac_address = qeth_layer2_set_mac_address; 6367 dev->set_mac_address = qeth_layer2_set_mac_address;
6393 dev->flags |= qeth_get_netdev_flags(card); 6368 dev->flags |= qeth_get_netdev_flags(card);
6394 if ((card->options.fake_broadcast) || 6369 if ((card->options.fake_broadcast) ||
@@ -8235,8 +8210,7 @@ qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8235 } 8210 }
8236 if (!qeth_add_ip(card, ipaddr)) 8211 if (!qeth_add_ip(card, ipaddr))
8237 kfree(ipaddr); 8212 kfree(ipaddr);
8238 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) 8213 qeth_set_ip_addr_list(card);
8239 schedule_work(&card->kernel_thread_starter);
8240 return rc; 8214 return rc;
8241} 8215}
8242 8216
@@ -8264,8 +8238,7 @@ qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8264 return; 8238 return;
8265 if (!qeth_delete_ip(card, ipaddr)) 8239 if (!qeth_delete_ip(card, ipaddr))
8266 kfree(ipaddr); 8240 kfree(ipaddr);
8267 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) 8241 qeth_set_ip_addr_list(card);
8268 schedule_work(&card->kernel_thread_starter);
8269} 8242}
8270 8243
8271/* 8244/*
@@ -8308,8 +8281,7 @@ qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8308 } 8281 }
8309 if (!qeth_add_ip(card, ipaddr)) 8282 if (!qeth_add_ip(card, ipaddr))
8310 kfree(ipaddr); 8283 kfree(ipaddr);
8311 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) 8284 qeth_set_ip_addr_list(card);
8312 schedule_work(&card->kernel_thread_starter);
8313 return 0; 8285 return 0;
8314} 8286}
8315 8287
@@ -8337,8 +8309,7 @@ qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8337 return; 8309 return;
8338 if (!qeth_delete_ip(card, ipaddr)) 8310 if (!qeth_delete_ip(card, ipaddr))
8339 kfree(ipaddr); 8311 kfree(ipaddr);
8340 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) 8312 qeth_set_ip_addr_list(card);
8341 schedule_work(&card->kernel_thread_starter);
8342} 8313}
8343 8314
8344/** 8315/**
@@ -8380,8 +8351,7 @@ qeth_ip_event(struct notifier_block *this,
8380 default: 8351 default:
8381 break; 8352 break;
8382 } 8353 }
8383 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) 8354 qeth_set_ip_addr_list(card);
8384 schedule_work(&card->kernel_thread_starter);
8385out: 8355out:
8386 return NOTIFY_DONE; 8356 return NOTIFY_DONE;
8387} 8357}
@@ -8433,8 +8403,7 @@ qeth_ip6_event(struct notifier_block *this,
8433 default: 8403 default:
8434 break; 8404 break;
8435 } 8405 }
8436 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) 8406 qeth_set_ip_addr_list(card);
8437 schedule_work(&card->kernel_thread_starter);
8438out: 8407out:
8439 return NOTIFY_DONE; 8408 return NOTIFY_DONE;
8440} 8409}
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 99a259c5a0..e1b44d6c0c 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -6,7 +6,7 @@
6 Arnaldo Carvalho de Melo <acme@conectiva.com.br> 6 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7 Brad Strand <linux@3ware.com> 7 Brad Strand <linux@3ware.com>
8 8
9 Copyright (C) 1999-2005 3ware Inc. 9 Copyright (C) 1999-2007 3ware Inc.
10 10
11 Kernel compatiblity By: Andre Hedrick <andre@suse.com> 11 Kernel compatiblity By: Andre Hedrick <andre@suse.com>
12 Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com> 12 Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com>
@@ -191,6 +191,9 @@
191 before shutting down card. 191 before shutting down card.
192 Change to new 'change_queue_depth' api. 192 Change to new 'change_queue_depth' api.
193 Fix 'handled=1' ISR usage, remove bogus IRQ check. 193 Fix 'handled=1' ISR usage, remove bogus IRQ check.
194 1.26.02.002 - Free irq handler in __tw_shutdown().
195 Turn on RCD bit for caching mode page.
196 Serialize reset code.
194*/ 197*/
195 198
196#include <linux/module.h> 199#include <linux/module.h>
@@ -214,7 +217,7 @@
214#include "3w-xxxx.h" 217#include "3w-xxxx.h"
215 218
216/* Globals */ 219/* Globals */
217#define TW_DRIVER_VERSION "1.26.02.001" 220#define TW_DRIVER_VERSION "1.26.02.002"
218static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT]; 221static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT];
219static int tw_device_extension_count = 0; 222static int tw_device_extension_count = 0;
220static int twe_major = -1; 223static int twe_major = -1;
@@ -226,7 +229,7 @@ MODULE_LICENSE("GPL");
226MODULE_VERSION(TW_DRIVER_VERSION); 229MODULE_VERSION(TW_DRIVER_VERSION);
227 230
228/* Function prototypes */ 231/* Function prototypes */
229static int tw_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_reset); 232static int tw_reset_device_extension(TW_Device_Extension *tw_dev);
230 233
231/* Functions */ 234/* Functions */
232 235
@@ -984,24 +987,12 @@ static int tw_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
984 /* Now wait for the command to complete */ 987 /* Now wait for the command to complete */
985 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout); 988 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout);
986 989
987 /* See if we reset while waiting for the ioctl to complete */
988 if (test_bit(TW_IN_RESET, &tw_dev->flags)) {
989 clear_bit(TW_IN_RESET, &tw_dev->flags);
990 retval = -ERESTARTSYS;
991 goto out2;
992 }
993
994 /* We timed out, and didn't get an interrupt */ 990 /* We timed out, and didn't get an interrupt */
995 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) { 991 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) {
996 /* Now we need to reset the board */ 992 /* Now we need to reset the board */
997 printk(KERN_WARNING "3w-xxxx: scsi%d: Character ioctl (0x%x) timed out, resetting card.\n", tw_dev->host->host_no, cmd); 993 printk(KERN_WARNING "3w-xxxx: scsi%d: Character ioctl (0x%x) timed out, resetting card.\n", tw_dev->host->host_no, cmd);
998 retval = -EIO; 994 retval = -EIO;
999 spin_lock_irqsave(tw_dev->host->host_lock, flags); 995 if (tw_reset_device_extension(tw_dev)) {
1000 tw_dev->state[request_id] = TW_S_COMPLETED;
1001 tw_state_request_finish(tw_dev, request_id);
1002 tw_dev->posted_request_count--;
1003 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
1004 if (tw_reset_device_extension(tw_dev, 1)) {
1005 printk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl(): Reset failed for card %d.\n", tw_dev->host->host_no); 996 printk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl(): Reset failed for card %d.\n", tw_dev->host->host_no);
1006 } 997 }
1007 goto out2; 998 goto out2;
@@ -1336,7 +1327,7 @@ static void tw_unmap_scsi_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
1336} /* End tw_unmap_scsi_data() */ 1327} /* End tw_unmap_scsi_data() */
1337 1328
1338/* This function will reset a device extension */ 1329/* This function will reset a device extension */
1339static int tw_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_reset) 1330static int tw_reset_device_extension(TW_Device_Extension *tw_dev)
1340{ 1331{
1341 int i = 0; 1332 int i = 0;
1342 struct scsi_cmnd *srb; 1333 struct scsi_cmnd *srb;
@@ -1382,15 +1373,10 @@ static int tw_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_rese
1382 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset sequence failed.\n", tw_dev->host->host_no); 1373 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset sequence failed.\n", tw_dev->host->host_no);
1383 return 1; 1374 return 1;
1384 } 1375 }
1385 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
1386 1376
1387 /* Wake up any ioctl that was pending before the reset */ 1377 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
1388 if ((tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE) || (ioctl_reset)) { 1378 clear_bit(TW_IN_RESET, &tw_dev->flags);
1389 clear_bit(TW_IN_RESET, &tw_dev->flags); 1379 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1390 } else {
1391 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1392 wake_up(&tw_dev->ioctl_wqueue);
1393 }
1394 1380
1395 return 0; 1381 return 0;
1396} /* End tw_reset_device_extension() */ 1382} /* End tw_reset_device_extension() */
@@ -1437,14 +1423,18 @@ static int tw_scsi_eh_reset(struct scsi_cmnd *SCpnt)
1437 "WARNING: Command (0x%x) timed out, resetting card.\n", 1423 "WARNING: Command (0x%x) timed out, resetting card.\n",
1438 SCpnt->cmnd[0]); 1424 SCpnt->cmnd[0]);
1439 1425
1426 /* Make sure we are not issuing an ioctl or resetting from ioctl */
1427 mutex_lock(&tw_dev->ioctl_lock);
1428
1440 /* Now reset the card and some of the device extension data */ 1429 /* Now reset the card and some of the device extension data */
1441 if (tw_reset_device_extension(tw_dev, 0)) { 1430 if (tw_reset_device_extension(tw_dev)) {
1442 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset failed.\n", tw_dev->host->host_no); 1431 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset failed.\n", tw_dev->host->host_no);
1443 goto out; 1432 goto out;
1444 } 1433 }
1445 1434
1446 retval = SUCCESS; 1435 retval = SUCCESS;
1447out: 1436out:
1437 mutex_unlock(&tw_dev->ioctl_lock);
1448 return retval; 1438 return retval;
1449} /* End tw_scsi_eh_reset() */ 1439} /* End tw_scsi_eh_reset() */
1450 1440
@@ -1660,9 +1650,9 @@ static int tw_scsiop_mode_sense_complete(TW_Device_Extension *tw_dev, int reques
1660 request_buffer[4] = 0x8; /* caching page */ 1650 request_buffer[4] = 0x8; /* caching page */
1661 request_buffer[5] = 0xa; /* page length */ 1651 request_buffer[5] = 0xa; /* page length */
1662 if (*flags & 0x1) 1652 if (*flags & 0x1)
1663 request_buffer[6] = 0x4; /* WCE on */ 1653 request_buffer[6] = 0x5; /* WCE on, RCD on */
1664 else 1654 else
1665 request_buffer[6] = 0x0; /* WCE off */ 1655 request_buffer[6] = 0x1; /* WCE off, RCD on */
1666 tw_transfer_internal(tw_dev, request_id, request_buffer, 1656 tw_transfer_internal(tw_dev, request_id, request_buffer,
1667 sizeof(request_buffer)); 1657 sizeof(request_buffer));
1668 1658
@@ -2012,6 +2002,10 @@ static int tw_scsi_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd
2012 int retval = 1; 2002 int retval = 1;
2013 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; 2003 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
2014 2004
2005 /* If we are resetting due to timed out ioctl, report as busy */
2006 if (test_bit(TW_IN_RESET, &tw_dev->flags))
2007 return SCSI_MLQUEUE_HOST_BUSY;
2008
2015 /* Save done function into Scsi_Cmnd struct */ 2009 /* Save done function into Scsi_Cmnd struct */
2016 SCpnt->scsi_done = done; 2010 SCpnt->scsi_done = done;
2017 2011
@@ -2100,6 +2094,10 @@ static irqreturn_t tw_interrupt(int irq, void *dev_instance)
2100 2094
2101 handled = 1; 2095 handled = 1;
2102 2096
2097 /* If we are resetting, bail */
2098 if (test_bit(TW_IN_RESET, &tw_dev->flags))
2099 goto tw_interrupt_bail;
2100
2103 /* Check controller for errors */ 2101 /* Check controller for errors */
2104 if (tw_check_bits(status_reg_value)) { 2102 if (tw_check_bits(status_reg_value)) {
2105 dprintk(KERN_WARNING "3w-xxxx: tw_interrupt(): Unexpected bits.\n"); 2103 dprintk(KERN_WARNING "3w-xxxx: tw_interrupt(): Unexpected bits.\n");
@@ -2276,6 +2274,9 @@ static void __tw_shutdown(TW_Device_Extension *tw_dev)
2276 /* Disable interrupts */ 2274 /* Disable interrupts */
2277 TW_DISABLE_INTERRUPTS(tw_dev); 2275 TW_DISABLE_INTERRUPTS(tw_dev);
2278 2276
2277 /* Free up the IRQ */
2278 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
2279
2279 printk(KERN_WARNING "3w-xxxx: Shutting down host %d.\n", tw_dev->host->host_no); 2280 printk(KERN_WARNING "3w-xxxx: Shutting down host %d.\n", tw_dev->host->host_no);
2280 2281
2281 /* Tell the card we are shutting down */ 2282 /* Tell the card we are shutting down */
@@ -2444,9 +2445,6 @@ static void tw_remove(struct pci_dev *pdev)
2444 twe_major = -1; 2445 twe_major = -1;
2445 } 2446 }
2446 2447
2447 /* Free up the IRQ */
2448 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
2449
2450 /* Shutdown the card */ 2448 /* Shutdown the card */
2451 __tw_shutdown(tw_dev); 2449 __tw_shutdown(tw_dev);
2452 2450
diff --git a/drivers/scsi/3w-xxxx.h b/drivers/scsi/3w-xxxx.h
index bbd654a2b9..0742e68466 100644
--- a/drivers/scsi/3w-xxxx.h
+++ b/drivers/scsi/3w-xxxx.h
@@ -6,7 +6,7 @@
6 Arnaldo Carvalho de Melo <acme@conectiva.com.br> 6 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7 Brad Strand <linux@3ware.com> 7 Brad Strand <linux@3ware.com>
8 8
9 Copyright (C) 1999-2005 3ware Inc. 9 Copyright (C) 1999-2007 3ware Inc.
10 10
11 Kernel compatiblity By: Andre Hedrick <andre@suse.com> 11 Kernel compatiblity By: Andre Hedrick <andre@suse.com>
12 Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com> 12 Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com>
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 60f5827271..7869c34a4a 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1303,7 +1303,7 @@ config SCSI_LPFC
1303 1303
1304config SCSI_SEAGATE 1304config SCSI_SEAGATE
1305 tristate "Seagate ST-02 and Future Domain TMC-8xx SCSI support" 1305 tristate "Seagate ST-02 and Future Domain TMC-8xx SCSI support"
1306 depends on X86 && ISA && SCSI && BROKEN 1306 depends on X86 && ISA && SCSI
1307 ---help--- 1307 ---help---
1308 These are 8-bit SCSI controllers; the ST-01 is also supported by 1308 These are 8-bit SCSI controllers; the ST-01 is also supported by
1309 this driver. It is explained in section 3.9 of the SCSI-HOWTO, 1309 this driver. It is explained in section 3.9 of the SCSI-HOWTO,
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 359e7ddfdb..d2cf875af5 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -117,8 +117,8 @@ static struct pci_device_id aac_pci_tbl[] = {
117 { 0x9005, 0x0286, 0x9005, 0x029b, 0, 0, 22 }, /* AAR-2820SA (Intruder) */ 117 { 0x9005, 0x0286, 0x9005, 0x029b, 0, 0, 22 }, /* AAR-2820SA (Intruder) */
118 { 0x9005, 0x0286, 0x9005, 0x029c, 0, 0, 23 }, /* AAR-2620SA (Intruder) */ 118 { 0x9005, 0x0286, 0x9005, 0x029c, 0, 0, 23 }, /* AAR-2620SA (Intruder) */
119 { 0x9005, 0x0286, 0x9005, 0x029d, 0, 0, 24 }, /* AAR-2420SA (Intruder) */ 119 { 0x9005, 0x0286, 0x9005, 0x029d, 0, 0, 24 }, /* AAR-2420SA (Intruder) */
120 { 0x9005, 0x0286, 0x9005, 0x029e, 0, 0, 25 }, /* ICP9024R0 (Lancer) */ 120 { 0x9005, 0x0286, 0x9005, 0x029e, 0, 0, 25 }, /* ICP9024RO (Lancer) */
121 { 0x9005, 0x0286, 0x9005, 0x029f, 0, 0, 26 }, /* ICP9014R0 (Lancer) */ 121 { 0x9005, 0x0286, 0x9005, 0x029f, 0, 0, 26 }, /* ICP9014RO (Lancer) */
122 { 0x9005, 0x0286, 0x9005, 0x02a0, 0, 0, 27 }, /* ICP9047MA (Lancer) */ 122 { 0x9005, 0x0286, 0x9005, 0x02a0, 0, 0, 27 }, /* ICP9047MA (Lancer) */
123 { 0x9005, 0x0286, 0x9005, 0x02a1, 0, 0, 28 }, /* ICP9087MA (Lancer) */ 123 { 0x9005, 0x0286, 0x9005, 0x02a1, 0, 0, 28 }, /* ICP9087MA (Lancer) */
124 { 0x9005, 0x0286, 0x9005, 0x02a3, 0, 0, 29 }, /* ICP5445AU (Hurricane44) */ 124 { 0x9005, 0x0286, 0x9005, 0x02a3, 0, 0, 29 }, /* ICP5445AU (Hurricane44) */
@@ -137,15 +137,15 @@ static struct pci_device_id aac_pci_tbl[] = {
137 { 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 41 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */ 137 { 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 41 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
138 { 0x9005, 0x0285, 0x103C, 0x3227, 0, 0, 42 }, /* AAR-2610SA PCI SATA 6ch */ 138 { 0x9005, 0x0285, 0x103C, 0x3227, 0, 0, 42 }, /* AAR-2610SA PCI SATA 6ch */
139 { 0x9005, 0x0285, 0x9005, 0x0296, 0, 0, 43 }, /* ASR-2240S (SabreExpress) */ 139 { 0x9005, 0x0285, 0x9005, 0x0296, 0, 0, 43 }, /* ASR-2240S (SabreExpress) */
140 { 0x9005, 0x0285, 0x9005, 0x0297, 0, 0, 44 }, /* ASR-4005SAS */ 140 { 0x9005, 0x0285, 0x9005, 0x0297, 0, 0, 44 }, /* ASR-4005 */
141 { 0x9005, 0x0285, 0x1014, 0x02F2, 0, 0, 45 }, /* IBM 8i (AvonPark) */ 141 { 0x9005, 0x0285, 0x1014, 0x02F2, 0, 0, 45 }, /* IBM 8i (AvonPark) */
142 { 0x9005, 0x0285, 0x1014, 0x0312, 0, 0, 45 }, /* IBM 8i (AvonPark Lite) */ 142 { 0x9005, 0x0285, 0x1014, 0x0312, 0, 0, 45 }, /* IBM 8i (AvonPark Lite) */
143 { 0x9005, 0x0286, 0x1014, 0x9580, 0, 0, 46 }, /* IBM 8k/8k-l8 (Aurora) */ 143 { 0x9005, 0x0286, 0x1014, 0x9580, 0, 0, 46 }, /* IBM 8k/8k-l8 (Aurora) */
144 { 0x9005, 0x0286, 0x1014, 0x9540, 0, 0, 47 }, /* IBM 8k/8k-l4 (Aurora Lite) */ 144 { 0x9005, 0x0286, 0x1014, 0x9540, 0, 0, 47 }, /* IBM 8k/8k-l4 (Aurora Lite) */
145 { 0x9005, 0x0285, 0x9005, 0x0298, 0, 0, 48 }, /* ASR-4000SAS (BlackBird) */ 145 { 0x9005, 0x0285, 0x9005, 0x0298, 0, 0, 48 }, /* ASR-4000 (BlackBird) */
146 { 0x9005, 0x0285, 0x9005, 0x0299, 0, 0, 49 }, /* ASR-4800SAS (Marauder-X) */ 146 { 0x9005, 0x0285, 0x9005, 0x0299, 0, 0, 49 }, /* ASR-4800SAS (Marauder-X) */
147 { 0x9005, 0x0285, 0x9005, 0x029a, 0, 0, 50 }, /* ASR-4805SAS (Marauder-E) */ 147 { 0x9005, 0x0285, 0x9005, 0x029a, 0, 0, 50 }, /* ASR-4805SAS (Marauder-E) */
148 { 0x9005, 0x0286, 0x9005, 0x02a2, 0, 0, 51 }, /* ASR-3800SAS (Hurricane44) */ 148 { 0x9005, 0x0286, 0x9005, 0x02a2, 0, 0, 51 }, /* ASR-3800 (Hurricane44) */
149 149
150 { 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 52 }, /* Perc 320/DC*/ 150 { 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 52 }, /* Perc 320/DC*/
151 { 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 53 }, /* Adaptec 5400S (Mustang)*/ 151 { 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 53 }, /* Adaptec 5400S (Mustang)*/
@@ -193,8 +193,8 @@ static struct aac_driver_ident aac_drivers[] = {
193 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2820SA ", 1 }, /* AAR-2820SA (Intruder) */ 193 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2820SA ", 1 }, /* AAR-2820SA (Intruder) */
194 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2620SA ", 1 }, /* AAR-2620SA (Intruder) */ 194 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2620SA ", 1 }, /* AAR-2620SA (Intruder) */
195 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2420SA ", 1 }, /* AAR-2420SA (Intruder) */ 195 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2420SA ", 1 }, /* AAR-2420SA (Intruder) */
196 { aac_rkt_init, "aacraid", "ICP ", "ICP9024R0 ", 2 }, /* ICP9024R0 (Lancer) */ 196 { aac_rkt_init, "aacraid", "ICP ", "ICP9024RO ", 2 }, /* ICP9024RO (Lancer) */
197 { aac_rkt_init, "aacraid", "ICP ", "ICP9014R0 ", 1 }, /* ICP9014R0 (Lancer) */ 197 { aac_rkt_init, "aacraid", "ICP ", "ICP9014RO ", 1 }, /* ICP9014RO (Lancer) */
198 { aac_rkt_init, "aacraid", "ICP ", "ICP9047MA ", 1 }, /* ICP9047MA (Lancer) */ 198 { aac_rkt_init, "aacraid", "ICP ", "ICP9047MA ", 1 }, /* ICP9047MA (Lancer) */
199 { aac_rkt_init, "aacraid", "ICP ", "ICP9087MA ", 1 }, /* ICP9087MA (Lancer) */ 199 { aac_rkt_init, "aacraid", "ICP ", "ICP9087MA ", 1 }, /* ICP9087MA (Lancer) */
200 { aac_rkt_init, "aacraid", "ICP ", "ICP5445AU ", 1 }, /* ICP5445AU (Hurricane44) */ 200 { aac_rkt_init, "aacraid", "ICP ", "ICP5445AU ", 1 }, /* ICP5445AU (Hurricane44) */
@@ -212,14 +212,14 @@ static struct aac_driver_ident aac_drivers[] = {
212 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2026ZCR ", 1 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */ 212 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2026ZCR ", 1 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
213 { aac_rx_init, "aacraid", "ADAPTEC ", "AAR-2610SA ", 1 }, /* SATA 6Ch (Bearcat) */ 213 { aac_rx_init, "aacraid", "ADAPTEC ", "AAR-2610SA ", 1 }, /* SATA 6Ch (Bearcat) */
214 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2240S ", 1 }, /* ASR-2240S (SabreExpress) */ 214 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2240S ", 1 }, /* ASR-2240S (SabreExpress) */
215 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4005SAS ", 1 }, /* ASR-4005SAS */ 215 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4005 ", 1 }, /* ASR-4005 */
216 { aac_rx_init, "ServeRAID","IBM ", "ServeRAID 8i ", 1 }, /* IBM 8i (AvonPark) */ 216 { aac_rx_init, "ServeRAID","IBM ", "ServeRAID 8i ", 1 }, /* IBM 8i (AvonPark) */
217 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l8 ", 1 }, /* IBM 8k/8k-l8 (Aurora) */ 217 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l8 ", 1 }, /* IBM 8k/8k-l8 (Aurora) */
218 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l4 ", 1 }, /* IBM 8k/8k-l4 (Aurora Lite) */ 218 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l4 ", 1 }, /* IBM 8k/8k-l4 (Aurora Lite) */
219 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4000SAS ", 1 }, /* ASR-4000SAS (BlackBird & AvonPark) */ 219 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4000 ", 1 }, /* ASR-4000 (BlackBird & AvonPark) */
220 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4800SAS ", 1 }, /* ASR-4800SAS (Marauder-X) */ 220 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4800SAS ", 1 }, /* ASR-4800SAS (Marauder-X) */
221 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4805SAS ", 1 }, /* ASR-4805SAS (Marauder-E) */ 221 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4805SAS ", 1 }, /* ASR-4805SAS (Marauder-E) */
222 { aac_rkt_init, "aacraid", "ADAPTEC ", "ASR-3800SAS ", 1 }, /* ASR-3800SAS (Hurricane44) */ 222 { aac_rkt_init, "aacraid", "ADAPTEC ", "ASR-3800 ", 1 }, /* ASR-3800 (Hurricane44) */
223 223
224 { aac_rx_init, "percraid", "DELL ", "PERC 320/DC ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Perc 320/DC*/ 224 { aac_rx_init, "percraid", "DELL ", "PERC 320/DC ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Perc 320/DC*/
225 { aac_sa_init, "aacraid", "ADAPTEC ", "Adaptec 5400S ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/ 225 { aac_sa_init, "aacraid", "ADAPTEC ", "Adaptec 5400S ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 2b344356a2..306bec355e 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -18215,6 +18215,7 @@ AdvInquiryHandling(
18215} 18215}
18216MODULE_LICENSE("Dual BSD/GPL"); 18216MODULE_LICENSE("Dual BSD/GPL");
18217 18217
18218#ifdef CONFIG_PCI
18218/* PCI Devices supported by this driver */ 18219/* PCI Devices supported by this driver */
18219static struct pci_device_id advansys_pci_tbl[] __devinitdata = { 18220static struct pci_device_id advansys_pci_tbl[] __devinitdata = {
18220 { PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A, 18221 { PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
@@ -18232,4 +18233,4 @@ static struct pci_device_id advansys_pci_tbl[] __devinitdata = {
18232 { } 18233 { }
18233}; 18234};
18234MODULE_DEVICE_TABLE(pci, advansys_pci_tbl); 18235MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
18235 18236#endif /* CONFIG_PCI */
diff --git a/drivers/scsi/ibmvscsi/Makefile b/drivers/scsi/ibmvscsi/Makefile
index 6ac0633d54..f67d9efc7a 100644
--- a/drivers/scsi/ibmvscsi/Makefile
+++ b/drivers/scsi/ibmvscsi/Makefile
@@ -1,7 +1,9 @@
1obj-$(CONFIG_SCSI_IBMVSCSI) += ibmvscsic.o 1obj-$(CONFIG_SCSI_IBMVSCSI) += ibmvscsic.o
2 2
3ibmvscsic-y += ibmvscsi.o 3ibmvscsic-y += ibmvscsi.o
4ifndef CONFIG_PPC_PSERIES
4ibmvscsic-$(CONFIG_PPC_ISERIES) += iseries_vscsi.o 5ibmvscsic-$(CONFIG_PPC_ISERIES) += iseries_vscsi.o
6endif
5ibmvscsic-$(CONFIG_PPC_PSERIES) += rpa_vscsi.o 7ibmvscsic-$(CONFIG_PPC_PSERIES) += rpa_vscsi.o
6 8
7obj-$(CONFIG_SCSI_IBMVSCSIS) += ibmvstgt.o 9obj-$(CONFIG_SCSI_IBMVSCSIS) += ibmvstgt.o
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index d0b139cccb..4376840843 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -749,7 +749,7 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn)
749 if (!offset) 749 if (!offset)
750 crypto_hash_update( 750 crypto_hash_update(
751 &tcp_conn->rx_hash, 751 &tcp_conn->rx_hash,
752 &sg[i], 1); 752 &sg[i], sg[i].length);
753 else 753 else
754 partial_sg_digest_update( 754 partial_sg_digest_update(
755 &tcp_conn->rx_hash, 755 &tcp_conn->rx_hash,
@@ -1777,13 +1777,13 @@ iscsi_tcp_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1777 tcp_conn->tx_hash.tfm = crypto_alloc_hash("crc32c", 0, 1777 tcp_conn->tx_hash.tfm = crypto_alloc_hash("crc32c", 0,
1778 CRYPTO_ALG_ASYNC); 1778 CRYPTO_ALG_ASYNC);
1779 tcp_conn->tx_hash.flags = 0; 1779 tcp_conn->tx_hash.flags = 0;
1780 if (!tcp_conn->tx_hash.tfm) 1780 if (IS_ERR(tcp_conn->tx_hash.tfm))
1781 goto free_tcp_conn; 1781 goto free_tcp_conn;
1782 1782
1783 tcp_conn->rx_hash.tfm = crypto_alloc_hash("crc32c", 0, 1783 tcp_conn->rx_hash.tfm = crypto_alloc_hash("crc32c", 0,
1784 CRYPTO_ALG_ASYNC); 1784 CRYPTO_ALG_ASYNC);
1785 tcp_conn->rx_hash.flags = 0; 1785 tcp_conn->rx_hash.flags = 0;
1786 if (!tcp_conn->rx_hash.tfm) 1786 if (IS_ERR(tcp_conn->rx_hash.tfm))
1787 goto free_tx_tfm; 1787 goto free_tx_tfm;
1788 1788
1789 return cls_conn; 1789 return cls_conn;
@@ -2044,13 +2044,11 @@ iscsi_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
2044 sk = tcp_conn->sock->sk; 2044 sk = tcp_conn->sock->sk;
2045 if (sk->sk_family == PF_INET) { 2045 if (sk->sk_family == PF_INET) {
2046 inet = inet_sk(sk); 2046 inet = inet_sk(sk);
2047 len = sprintf(buf, "%u.%u.%u.%u\n", 2047 len = sprintf(buf, NIPQUAD_FMT "\n",
2048 NIPQUAD(inet->daddr)); 2048 NIPQUAD(inet->daddr));
2049 } else { 2049 } else {
2050 np = inet6_sk(sk); 2050 np = inet6_sk(sk);
2051 len = sprintf(buf, 2051 len = sprintf(buf, NIP6_FMT "\n", NIP6(np->daddr));
2052 "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
2053 NIP6(np->daddr));
2054 } 2052 }
2055 mutex_unlock(&conn->xmitmutex); 2053 mutex_unlock(&conn->xmitmutex);
2056 break; 2054 break;
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index e11b23c641..d37048c96e 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -260,7 +260,7 @@ static int iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
260 } 260 }
261 261
262 if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) { 262 if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) {
263 int senselen; 263 uint16_t senselen;
264 264
265 if (datalen < 2) { 265 if (datalen < 2) {
266invalid_datalen: 266invalid_datalen:
@@ -270,12 +270,12 @@ invalid_datalen:
270 goto out; 270 goto out;
271 } 271 }
272 272
273 senselen = (data[0] << 8) | data[1]; 273 senselen = be16_to_cpu(*(uint16_t *)data);
274 if (datalen < senselen) 274 if (datalen < senselen)
275 goto invalid_datalen; 275 goto invalid_datalen;
276 276
277 memcpy(sc->sense_buffer, data + 2, 277 memcpy(sc->sense_buffer, data + 2,
278 min(senselen, SCSI_SENSE_BUFFERSIZE)); 278 min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
279 debug_scsi("copied %d bytes of sense\n", 279 debug_scsi("copied %d bytes of sense\n",
280 min(senselen, SCSI_SENSE_BUFFERSIZE)); 280 min(senselen, SCSI_SENSE_BUFFERSIZE));
281 } 281 }
diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c
index 066292d399..ec3bbbde6f 100644
--- a/drivers/scsi/lpfc/lpfc_mem.c
+++ b/drivers/scsi/lpfc/lpfc_mem.c
@@ -56,6 +56,9 @@ lpfc_mem_alloc(struct lpfc_hba * phba)
56 56
57 pool->elements = kmalloc(sizeof(struct lpfc_dmabuf) * 57 pool->elements = kmalloc(sizeof(struct lpfc_dmabuf) *
58 LPFC_MBUF_POOL_SIZE, GFP_KERNEL); 58 LPFC_MBUF_POOL_SIZE, GFP_KERNEL);
59 if (!pool->elements)
60 goto fail_free_lpfc_mbuf_pool;
61
59 pool->max_count = 0; 62 pool->max_count = 0;
60 pool->current_count = 0; 63 pool->current_count = 0;
61 for ( i = 0; i < LPFC_MBUF_POOL_SIZE; i++) { 64 for ( i = 0; i < LPFC_MBUF_POOL_SIZE; i++) {
@@ -82,10 +85,11 @@ lpfc_mem_alloc(struct lpfc_hba * phba)
82 fail_free_mbox_pool: 85 fail_free_mbox_pool:
83 mempool_destroy(phba->mbox_mem_pool); 86 mempool_destroy(phba->mbox_mem_pool);
84 fail_free_mbuf_pool: 87 fail_free_mbuf_pool:
85 while (--i) 88 while (i--)
86 pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt, 89 pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
87 pool->elements[i].phys); 90 pool->elements[i].phys);
88 kfree(pool->elements); 91 kfree(pool->elements);
92 fail_free_lpfc_mbuf_pool:
89 pci_pool_destroy(phba->lpfc_mbuf_pool); 93 pci_pool_destroy(phba->lpfc_mbuf_pool);
90 fail_free_dma_buf_pool: 94 fail_free_dma_buf_pool:
91 pci_pool_destroy(phba->lpfc_scsi_dma_buf_pool); 95 pci_pool_destroy(phba->lpfc_scsi_dma_buf_pool);
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index 046223b4ae..b5bdd0d7a8 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -13,8 +13,8 @@
13 * Version : v00.00.03.05 13 * Version : v00.00.03.05
14 * 14 *
15 * Authors: 15 * Authors:
16 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsil.com> 16 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsi.com>
17 * Sumant Patro <Sumant.Patro@lsil.com> 17 * Sumant Patro <Sumant.Patro@lsi.com>
18 * 18 *
19 * List of supported controllers 19 * List of supported controllers
20 * 20 *
@@ -45,7 +45,7 @@
45 45
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47MODULE_VERSION(MEGASAS_VERSION); 47MODULE_VERSION(MEGASAS_VERSION);
48MODULE_AUTHOR("sreenivas.bagalkote@lsil.com"); 48MODULE_AUTHOR("megaraidlinux@lsi.com");
49MODULE_DESCRIPTION("LSI Logic MegaRAID SAS Driver"); 49MODULE_DESCRIPTION("LSI Logic MegaRAID SAS Driver");
50 50
51/* 51/*
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index d72df5dae4..e16fe36143 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -1629,7 +1629,6 @@ static int nsp_cs_probe(struct pcmcia_device *link)
1629 /* General socket configuration */ 1629 /* General socket configuration */
1630 link->conf.Attributes = CONF_ENABLE_IRQ; 1630 link->conf.Attributes = CONF_ENABLE_IRQ;
1631 link->conf.IntType = INT_MEMORY_AND_IO; 1631 link->conf.IntType = INT_MEMORY_AND_IO;
1632 link->conf.Present = PRESENT_OPTION;
1633 1632
1634 ret = nsp_cs_config(link); 1633 ret = nsp_cs_config(link);
1635 1634
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index fb7acea602..5b458d2478 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -545,8 +545,6 @@ SYM53C500_release(struct pcmcia_device *link)
545 */ 545 */
546 if (shost->irq) 546 if (shost->irq)
547 free_irq(shost->irq, shost); 547 free_irq(shost->irq, shost);
548 if (shost->dma_channel != 0xff)
549 free_dma(shost->dma_channel);
550 if (shost->io_port && shost->n_io_port) 548 if (shost->io_port && shost->n_io_port)
551 release_region(shost->io_port, shost->n_io_port); 549 release_region(shost->io_port, shost->n_io_port);
552 550
@@ -895,7 +893,6 @@ SYM53C500_probe(struct pcmcia_device *link)
895 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 893 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
896 link->conf.Attributes = CONF_ENABLE_IRQ; 894 link->conf.Attributes = CONF_ENABLE_IRQ;
897 link->conf.IntType = INT_MEMORY_AND_IO; 895 link->conf.IntType = INT_MEMORY_AND_IO;
898 link->conf.Present = PRESENT_OPTION;
899 896
900 return SYM53C500_config(link); 897 return SYM53C500_config(link);
901} /* SYM53C500_attach */ 898} /* SYM53C500_attach */
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 16af5b79e5..1548d42a3b 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -1341,7 +1341,7 @@ qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1341 int host_status = DID_ERROR; 1341 int host_status = DID_ERROR;
1342 uint16_t comp_status = le16_to_cpu(sts->comp_status); 1342 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1343 uint16_t state_flags = le16_to_cpu(sts->state_flags); 1343 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1344 uint16_t residual_length = le32_to_cpu(sts->residual_length); 1344 uint32_t residual_length = le32_to_cpu(sts->residual_length);
1345 uint16_t scsi_status = le16_to_cpu(sts->scsi_status); 1345 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1346#if DEBUG_QLA1280_INTR 1346#if DEBUG_QLA1280_INTR
1347 static char *reason[] = { 1347 static char *reason[] = {
@@ -1413,8 +1413,10 @@ qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1413 "scsi: Underflow detected - retrying " 1413 "scsi: Underflow detected - retrying "
1414 "command.\n"); 1414 "command.\n");
1415 host_status = DID_ERROR; 1415 host_status = DID_ERROR;
1416 } else 1416 } else {
1417 cp->resid = residual_length;
1417 host_status = DID_OK; 1418 host_status = DID_OK;
1419 }
1418 break; 1420 break;
1419 1421
1420 default: 1422 default:
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index c4fc40f8e8..2c10130d9e 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -1602,6 +1602,7 @@ typedef struct fc_port {
1602 1602
1603#define CT_REJECT_RESPONSE 0x8001 1603#define CT_REJECT_RESPONSE 0x8001
1604#define CT_ACCEPT_RESPONSE 0x8002 1604#define CT_ACCEPT_RESPONSE 0x8002
1605#define CT_REASON_INVALID_COMMAND_CODE 0x01
1605#define CT_REASON_CANNOT_PERFORM 0x09 1606#define CT_REASON_CANNOT_PERFORM 0x09
1606#define CT_EXPL_ALREADY_REGISTERED 0x10 1607#define CT_EXPL_ALREADY_REGISTERED 0x10
1607 1608
@@ -2079,6 +2080,7 @@ typedef struct scsi_qla_host {
2079 uint32_t msi_enabled :1; 2080 uint32_t msi_enabled :1;
2080 uint32_t msix_enabled :1; 2081 uint32_t msix_enabled :1;
2081 uint32_t disable_serdes :1; 2082 uint32_t disable_serdes :1;
2083 uint32_t gpsc_supported :1;
2082 } flags; 2084 } flags;
2083 2085
2084 atomic_t loop_state; 2086 atomic_t loop_state;
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 32ebeec45f..e4dd12f4b8 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -45,7 +45,6 @@ extern void qla2x00_update_fcports(scsi_qla_host_t *);
45extern int qla2x00_abort_isp(scsi_qla_host_t *); 45extern int qla2x00_abort_isp(scsi_qla_host_t *);
46 46
47extern void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *); 47extern void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
48extern void qla2x00_reg_remote_port(scsi_qla_host_t *, fc_port_t *);
49 48
50extern void qla2x00_alloc_fw_dump(scsi_qla_host_t *); 49extern void qla2x00_alloc_fw_dump(scsi_qla_host_t *);
51extern void qla2x00_try_to_stop_firmware(scsi_qla_host_t *); 50extern void qla2x00_try_to_stop_firmware(scsi_qla_host_t *);
diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index 97fbc62ec6..ec5b2dd90d 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -127,8 +127,8 @@ qla2x00_chk_ms_status(scsi_qla_host_t *ha, ms_iocb_entry_t *ms_pkt,
127 ha->host_no, routine, ms_pkt->entry_status)); 127 ha->host_no, routine, ms_pkt->entry_status));
128 } else { 128 } else {
129 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) 129 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
130 comp_status = 130 comp_status = le16_to_cpu(
131 ((struct ct_entry_24xx *)ms_pkt)->comp_status; 131 ((struct ct_entry_24xx *)ms_pkt)->comp_status);
132 else 132 else
133 comp_status = le16_to_cpu(ms_pkt->status); 133 comp_status = le16_to_cpu(ms_pkt->status);
134 switch (comp_status) { 134 switch (comp_status) {
@@ -143,6 +143,7 @@ qla2x00_chk_ms_status(scsi_qla_host_t *ha, ms_iocb_entry_t *ms_pkt,
143 DEBUG2_3(qla2x00_dump_buffer( 143 DEBUG2_3(qla2x00_dump_buffer(
144 (uint8_t *)&ct_rsp->header, 144 (uint8_t *)&ct_rsp->header,
145 sizeof(struct ct_rsp_hdr))); 145 sizeof(struct ct_rsp_hdr)));
146 rval = QLA_INVALID_COMMAND;
146 } else 147 } else
147 rval = QLA_SUCCESS; 148 rval = QLA_SUCCESS;
148 break; 149 break;
@@ -1683,7 +1684,7 @@ qla2x00_gfpn_id(scsi_qla_host_t *ha, sw_info_t *list)
1683 memset(list[i].fabric_port_name, 0, WWN_SIZE); 1684 memset(list[i].fabric_port_name, 0, WWN_SIZE);
1684 1685
1685 /* Prepare common MS IOCB */ 1686 /* Prepare common MS IOCB */
1686 ms_pkt = qla2x00_prep_ms_iocb(ha, GFPN_ID_REQ_SIZE, 1687 ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GFPN_ID_REQ_SIZE,
1687 GFPN_ID_RSP_SIZE); 1688 GFPN_ID_RSP_SIZE);
1688 1689
1689 /* Prepare CT request */ 1690 /* Prepare CT request */
@@ -1784,6 +1785,8 @@ qla2x00_gpsc(scsi_qla_host_t *ha, sw_info_t *list)
1784 1785
1785 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) 1786 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
1786 return QLA_FUNCTION_FAILED; 1787 return QLA_FUNCTION_FAILED;
1788 if (!ha->flags.gpsc_supported)
1789 return QLA_FUNCTION_FAILED;
1787 1790
1788 rval = qla2x00_mgmt_svr_login(ha); 1791 rval = qla2x00_mgmt_svr_login(ha);
1789 if (rval) 1792 if (rval)
@@ -1813,8 +1816,19 @@ qla2x00_gpsc(scsi_qla_host_t *ha, sw_info_t *list)
1813 /*EMPTY*/ 1816 /*EMPTY*/
1814 DEBUG2_3(printk("scsi(%ld): GPSC issue IOCB " 1817 DEBUG2_3(printk("scsi(%ld): GPSC issue IOCB "
1815 "failed (%d).\n", ha->host_no, rval)); 1818 "failed (%d).\n", ha->host_no, rval));
1816 } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, 1819 } else if ((rval = qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp,
1817 "GPSC") != QLA_SUCCESS) { 1820 "GPSC")) != QLA_SUCCESS) {
1821 /* FM command unsupported? */
1822 if (rval == QLA_INVALID_COMMAND &&
1823 ct_rsp->header.reason_code ==
1824 CT_REASON_INVALID_COMMAND_CODE) {
1825 DEBUG2(printk("scsi(%ld): GPSC command "
1826 "unsupported, disabling query...\n",
1827 ha->host_no));
1828 ha->flags.gpsc_supported = 0;
1829 rval = QLA_FUNCTION_FAILED;
1830 break;
1831 }
1818 rval = QLA_FUNCTION_FAILED; 1832 rval = QLA_FUNCTION_FAILED;
1819 } else { 1833 } else {
1820 /* Save portname */ 1834 /* Save portname */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index a823f0bc51..b3dac26ddb 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -2103,40 +2103,7 @@ qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2103 } 2103 }
2104} 2104}
2105 2105
2106/* 2106static void
2107 * qla2x00_update_fcport
2108 * Updates device on list.
2109 *
2110 * Input:
2111 * ha = adapter block pointer.
2112 * fcport = port structure pointer.
2113 *
2114 * Return:
2115 * 0 - Success
2116 * BIT_0 - error
2117 *
2118 * Context:
2119 * Kernel context.
2120 */
2121void
2122qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2123{
2124 fcport->ha = ha;
2125 fcport->login_retry = 0;
2126 fcport->port_login_retry_count = ha->port_down_retry_count *
2127 PORT_RETRY_TIME;
2128 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2129 PORT_RETRY_TIME);
2130 fcport->flags &= ~FCF_LOGIN_NEEDED;
2131
2132 qla2x00_iidma_fcport(ha, fcport);
2133
2134 atomic_set(&fcport->state, FCS_ONLINE);
2135
2136 qla2x00_reg_remote_port(ha, fcport);
2137}
2138
2139void
2140qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport) 2107qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2141{ 2108{
2142 struct fc_rport_identifiers rport_ids; 2109 struct fc_rport_identifiers rport_ids;
@@ -2179,6 +2146,39 @@ qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2179} 2146}
2180 2147
2181/* 2148/*
2149 * qla2x00_update_fcport
2150 * Updates device on list.
2151 *
2152 * Input:
2153 * ha = adapter block pointer.
2154 * fcport = port structure pointer.
2155 *
2156 * Return:
2157 * 0 - Success
2158 * BIT_0 - error
2159 *
2160 * Context:
2161 * Kernel context.
2162 */
2163void
2164qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2165{
2166 fcport->ha = ha;
2167 fcport->login_retry = 0;
2168 fcport->port_login_retry_count = ha->port_down_retry_count *
2169 PORT_RETRY_TIME;
2170 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2171 PORT_RETRY_TIME);
2172 fcport->flags &= ~FCF_LOGIN_NEEDED;
2173
2174 qla2x00_iidma_fcport(ha, fcport);
2175
2176 atomic_set(&fcport->state, FCS_ONLINE);
2177
2178 qla2x00_reg_remote_port(ha, fcport);
2179}
2180
2181/*
2182 * qla2x00_configure_fabric 2182 * qla2x00_configure_fabric
2183 * Setup SNS devices with loop ID's. 2183 * Setup SNS devices with loop ID's.
2184 * 2184 *
@@ -3476,9 +3476,11 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
3476 3476
3477 /* Set host adapter parameters. */ 3477 /* Set host adapter parameters. */
3478 ha->flags.disable_risc_code_load = 0; 3478 ha->flags.disable_risc_code_load = 0;
3479 ha->flags.enable_lip_reset = 1; 3479 ha->flags.enable_lip_reset = 0;
3480 ha->flags.enable_lip_full_login = 1; 3480 ha->flags.enable_lip_full_login =
3481 ha->flags.enable_target_reset = 1; 3481 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3482 ha->flags.enable_target_reset =
3483 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3482 ha->flags.enable_led_scheme = 0; 3484 ha->flags.enable_led_scheme = 0;
3483 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; 3485 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3484 3486
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index d3b6df4d55..39fd17b05b 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -134,11 +134,11 @@ qla2300_intr_handler(int irq, void *dev_id)
134 if (stat & HSR_RISC_PAUSED) { 134 if (stat & HSR_RISC_PAUSED) {
135 hccr = RD_REG_WORD(&reg->hccr); 135 hccr = RD_REG_WORD(&reg->hccr);
136 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8)) 136 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
137 qla_printk(KERN_INFO, ha, 137 qla_printk(KERN_INFO, ha, "Parity error -- "
138 "Parity error -- HCCR=%x.\n", hccr); 138 "HCCR=%x, Dumping firmware!\n", hccr);
139 else 139 else
140 qla_printk(KERN_INFO, ha, 140 qla_printk(KERN_INFO, ha, "RISC paused -- "
141 "RISC paused -- HCCR=%x.\n", hccr); 141 "HCCR=%x, Dumping firmware!\n", hccr);
142 142
143 /* 143 /*
144 * Issue a "HARD" reset in order for the RISC 144 * Issue a "HARD" reset in order for the RISC
@@ -147,6 +147,8 @@ qla2300_intr_handler(int irq, void *dev_id)
147 */ 147 */
148 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC); 148 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
149 RD_REG_WORD(&reg->hccr); 149 RD_REG_WORD(&reg->hccr);
150
151 ha->isp_ops.fw_dump(ha, 1);
150 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); 152 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
151 break; 153 break;
152 } else if ((stat & HSR_RISC_INT) == 0) 154 } else if ((stat & HSR_RISC_INT) == 0)
@@ -475,6 +477,8 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
475 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); 477 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
476 } 478 }
477 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); 479 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
480
481 ha->flags.gpsc_supported = 1;
478 break; 482 break;
479 483
480 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */ 484 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
@@ -1440,8 +1444,7 @@ qla24xx_intr_handler(int irq, void *dev_id)
1440 1444
1441 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, " 1445 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1442 "Dumping firmware!\n", hccr); 1446 "Dumping firmware!\n", hccr);
1443 qla24xx_fw_dump(ha, 1); 1447 ha->isp_ops.fw_dump(ha, 1);
1444
1445 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); 1448 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1446 break; 1449 break;
1447 } else if ((stat & HSRX_RISC_INT) == 0) 1450 } else if ((stat & HSRX_RISC_INT) == 0)
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 4cde76c85c..077e5789be 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -1339,9 +1339,9 @@ qla2x00_lip_reset(scsi_qla_host_t *ha)
1339 1339
1340 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { 1340 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1341 mcp->mb[0] = MBC_LIP_FULL_LOGIN; 1341 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1342 mcp->mb[1] = BIT_0; 1342 mcp->mb[1] = BIT_6;
1343 mcp->mb[2] = 0xff; 1343 mcp->mb[2] = 0;
1344 mcp->mb[3] = 0; 1344 mcp->mb[3] = ha->loop_reset_delay;
1345 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; 1345 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1346 } else { 1346 } else {
1347 mcp->mb[0] = MBC_LIP_RESET; 1347 mcp->mb[0] = MBC_LIP_RESET;
@@ -1823,8 +1823,8 @@ qla2x00_full_login_lip(scsi_qla_host_t *ha)
1823 ha->host_no)); 1823 ha->host_no));
1824 1824
1825 mcp->mb[0] = MBC_LIP_FULL_LOGIN; 1825 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1826 mcp->mb[1] = 0; 1826 mcp->mb[1] = IS_QLA24XX(ha) || IS_QLA54XX(ha) ? BIT_3: 0;
1827 mcp->mb[2] = 0xff; 1827 mcp->mb[2] = 0;
1828 mcp->mb[3] = 0; 1828 mcp->mb[3] = 0;
1829 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; 1829 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1830 mcp->in_mb = MBX_0; 1830 mcp->in_mb = MBX_0;
@@ -2486,7 +2486,7 @@ qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma,
2486 mcp->mb[4] = LSW(MSD(eft_dma)); 2486 mcp->mb[4] = LSW(MSD(eft_dma));
2487 mcp->mb[5] = MSW(MSD(eft_dma)); 2487 mcp->mb[5] = MSW(MSD(eft_dma));
2488 mcp->mb[6] = buffers; 2488 mcp->mb[6] = buffers;
2489 mcp->mb[7] = buffers; 2489 mcp->mb[7] = 0;
2490 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2; 2490 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2;
2491 } 2491 }
2492 mcp->tov = 30; 2492 mcp->tov = 30;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index d03523d3bf..d6445ae841 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1037,48 +1037,49 @@ eh_host_reset_lock:
1037static int 1037static int
1038qla2x00_loop_reset(scsi_qla_host_t *ha) 1038qla2x00_loop_reset(scsi_qla_host_t *ha)
1039{ 1039{
1040 int status = QLA_SUCCESS; 1040 int ret;
1041 struct fc_port *fcport; 1041 struct fc_port *fcport;
1042 1042
1043 if (ha->flags.enable_lip_full_login) {
1044 ret = qla2x00_full_login_lip(ha);
1045 if (ret != QLA_SUCCESS) {
1046 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1047 "full_login_lip=%d.\n", __func__, ha->host_no,
1048 ret));
1049 }
1050 atomic_set(&ha->loop_state, LOOP_DOWN);
1051 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
1052 qla2x00_mark_all_devices_lost(ha, 0);
1053 qla2x00_wait_for_loop_ready(ha);
1054 }
1055
1043 if (ha->flags.enable_lip_reset) { 1056 if (ha->flags.enable_lip_reset) {
1044 status = qla2x00_lip_reset(ha); 1057 ret = qla2x00_lip_reset(ha);
1058 if (ret != QLA_SUCCESS) {
1059 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1060 "lip_reset=%d.\n", __func__, ha->host_no, ret));
1061 }
1062 qla2x00_wait_for_loop_ready(ha);
1045 } 1063 }
1046 1064
1047 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) { 1065 if (ha->flags.enable_target_reset) {
1048 list_for_each_entry(fcport, &ha->fcports, list) { 1066 list_for_each_entry(fcport, &ha->fcports, list) {
1049 if (fcport->port_type != FCT_TARGET) 1067 if (fcport->port_type != FCT_TARGET)
1050 continue; 1068 continue;
1051 1069
1052 status = qla2x00_device_reset(ha, fcport); 1070 ret = qla2x00_device_reset(ha, fcport);
1053 if (status != QLA_SUCCESS) 1071 if (ret != QLA_SUCCESS) {
1054 break; 1072 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1073 "target_reset=%d d_id=%x.\n", __func__,
1074 ha->host_no, ret, fcport->d_id.b24));
1075 }
1055 } 1076 }
1056 } 1077 }
1057 1078
1058 if (status == QLA_SUCCESS &&
1059 ((!ha->flags.enable_target_reset &&
1060 !ha->flags.enable_lip_reset) ||
1061 ha->flags.enable_lip_full_login)) {
1062
1063 status = qla2x00_full_login_lip(ha);
1064 }
1065
1066 /* Issue marker command only when we are going to start the I/O */ 1079 /* Issue marker command only when we are going to start the I/O */
1067 ha->marker_needed = 1; 1080 ha->marker_needed = 1;
1068 1081
1069 if (status) { 1082 return QLA_SUCCESS;
1070 /* Empty */
1071 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1072 __func__,
1073 ha->host_no));
1074 } else {
1075 /* Empty */
1076 DEBUG3(printk("%s(%ld): exiting normally.\n",
1077 __func__,
1078 ha->host_no));
1079 }
1080
1081 return(status);
1082} 1083}
1083 1084
1084/* 1085/*
@@ -1413,7 +1414,9 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1413 1414
1414 sht = &qla2x00_driver_template; 1415 sht = &qla2x00_driver_template;
1415 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 || 1416 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1416 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432) 1417 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1418 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1419 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432)
1417 sht = &qla24xx_driver_template; 1420 sht = &qla24xx_driver_template;
1418 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t)); 1421 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
1419 if (host == NULL) { 1422 if (host == NULL) {
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index 1fa0bce6b2..459e0d6bd2 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,7 +7,7 @@
7/* 7/*
8 * Driver version 8 * Driver version
9 */ 9 */
10#define QLA2XXX_VERSION "8.01.07-k3" 10#define QLA2XXX_VERSION "8.01.07-k4"
11 11
12#define QLA_DRIVER_MAJOR_VER 8 12#define QLA_DRIVER_MAJOR_VER 8
13#define QLA_DRIVER_MINOR_VER 1 13#define QLA_DRIVER_MINOR_VER 1
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 1748e27501..f02f48a882 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -265,13 +265,11 @@ static int scsi_merge_bio(struct request *rq, struct bio *bio)
265 265
266 if (!rq->bio) 266 if (!rq->bio)
267 blk_rq_bio_prep(q, rq, bio); 267 blk_rq_bio_prep(q, rq, bio);
268 else if (!q->back_merge_fn(q, rq, bio)) 268 else if (!ll_back_merge_fn(q, rq, bio))
269 return -EINVAL; 269 return -EINVAL;
270 else { 270 else {
271 rq->biotail->bi_next = bio; 271 rq->biotail->bi_next = bio;
272 rq->biotail = bio; 272 rq->biotail = bio;
273 rq->hard_nr_sectors += bio_sectors(bio);
274 rq->nr_sectors = rq->hard_nr_sectors;
275 } 273 }
276 274
277 return 0; 275 return 0;
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 14e635aa44..b83d03c4de 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -133,12 +133,10 @@ struct async_scan_data {
133/** 133/**
134 * scsi_complete_async_scans - Wait for asynchronous scans to complete 134 * scsi_complete_async_scans - Wait for asynchronous scans to complete
135 * 135 *
136 * Asynchronous scans add themselves to the scanning_hosts list. Once 136 * When this function returns, any host which started scanning before
137 * that list is empty, we know that the scans are complete. Rather than 137 * this function was called will have finished its scan. Hosts which
138 * waking up periodically to check the state of the list, we pretend to be 138 * started scanning after this function was called may or may not have
139 * a scanning task by adding ourselves at the end of the list and going to 139 * finished.
140 * sleep. When the task before us wakes us up, we take ourselves off the
141 * list and return.
142 */ 140 */
143int scsi_complete_async_scans(void) 141int scsi_complete_async_scans(void)
144{ 142{
@@ -171,6 +169,11 @@ int scsi_complete_async_scans(void)
171 169
172 spin_lock(&async_scan_lock); 170 spin_lock(&async_scan_lock);
173 list_del(&data->list); 171 list_del(&data->list);
172 if (!list_empty(&scanning_hosts)) {
173 struct async_scan_data *next = list_entry(scanning_hosts.next,
174 struct async_scan_data, list);
175 complete(&next->prev_finished);
176 }
174 done: 177 done:
175 spin_unlock(&async_scan_lock); 178 spin_unlock(&async_scan_lock);
176 179
@@ -739,6 +742,14 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
739 sdev->no_uld_attach = 1; 742 sdev->no_uld_attach = 1;
740 743
741 switch (sdev->type = (inq_result[0] & 0x1f)) { 744 switch (sdev->type = (inq_result[0] & 0x1f)) {
745 case TYPE_RBC:
746 /* RBC devices can return SCSI-3 compliance and yet
747 * still not support REPORT LUNS, so make them act as
748 * BLIST_NOREPORTLUN unless BLIST_REPORTLUN2 is
749 * specifically set */
750 if ((*bflags & BLIST_REPORTLUN2) == 0)
751 *bflags |= BLIST_NOREPORTLUN;
752 /* fall through */
742 case TYPE_TAPE: 753 case TYPE_TAPE:
743 case TYPE_DISK: 754 case TYPE_DISK:
744 case TYPE_PRINTER: 755 case TYPE_PRINTER:
@@ -749,11 +760,17 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
749 case TYPE_ENCLOSURE: 760 case TYPE_ENCLOSURE:
750 case TYPE_COMM: 761 case TYPE_COMM:
751 case TYPE_RAID: 762 case TYPE_RAID:
752 case TYPE_RBC:
753 sdev->writeable = 1; 763 sdev->writeable = 1;
754 break; 764 break;
755 case TYPE_WORM:
756 case TYPE_ROM: 765 case TYPE_ROM:
766 /* MMC devices can return SCSI-3 compliance and yet
767 * still not support REPORT LUNS, so make them act as
768 * BLIST_NOREPORTLUN unless BLIST_REPORTLUN2 is
769 * specifically set */
770 if ((*bflags & BLIST_REPORTLUN2) == 0)
771 *bflags |= BLIST_NOREPORTLUN;
772 /* fall through */
773 case TYPE_WORM:
757 sdev->writeable = 0; 774 sdev->writeable = 0;
758 break; 775 break;
759 default: 776 default:
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 9c22f13427..ce0d14af33 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -1416,7 +1416,7 @@ static __init int iscsi_transport_init(void)
1416{ 1416{
1417 int err; 1417 int err;
1418 1418
1419 printk(KERN_INFO "Loading iSCSI transport class v%s.", 1419 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
1420 ISCSI_TRANSPORT_VERSION); 1420 ISCSI_TRANSPORT_VERSION);
1421 1421
1422 err = class_register(&iscsi_transport_class); 1422 err = class_register(&iscsi_transport_class);
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index 3fded48314..014d7fea1f 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -122,7 +122,7 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd,
122 if (!sshdr) 122 if (!sshdr)
123 sshdr = &sshdr_tmp; 123 sshdr = &sshdr_tmp;
124 124
125 if (scsi_normalize_sense(sense, sizeof(*sense), 125 if (scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE,
126 sshdr) 126 sshdr)
127 && sshdr->sense_key == UNIT_ATTENTION) 127 && sshdr->sense_key == UNIT_ATTENTION)
128 continue; 128 continue;
diff --git a/drivers/scsi/seagate.c b/drivers/scsi/seagate.c
index 5ffec2721b..ff62e9708e 100644
--- a/drivers/scsi/seagate.c
+++ b/drivers/scsi/seagate.c
@@ -114,6 +114,7 @@
114#define DPRINTK( when, msg... ) do { if ( (DEBUG & (when)) == (when) ) printk( msg ); } while (0) 114#define DPRINTK( when, msg... ) do { if ( (DEBUG & (when)) == (when) ) printk( msg ); } while (0)
115#else 115#else
116#define DPRINTK( when, msg... ) do { } while (0) 116#define DPRINTK( when, msg... ) do { } while (0)
117#define DEBUG 0
117#endif 118#endif
118#define DANY( msg... ) DPRINTK( 0xffff, msg ); 119#define DANY( msg... ) DPRINTK( 0xffff, msg );
119 120
@@ -523,7 +524,7 @@ int __init seagate_st0x_detect (struct scsi_host_template * tpnt)
523#ifdef ARBITRATE 524#ifdef ARBITRATE
524 " ARBITRATE" 525 " ARBITRATE"
525#endif 526#endif
526#ifdef DEBUG 527#if DEBUG
527 " DEBUG" 528 " DEBUG"
528#endif 529#endif
529#ifdef FAST 530#ifdef FAST
@@ -733,7 +734,7 @@ static int internal_command (unsigned char target, unsigned char lun,
733 unsigned char *data = NULL; 734 unsigned char *data = NULL;
734 struct scatterlist *buffer = NULL; 735 struct scatterlist *buffer = NULL;
735 int clock, temp, nobuffs = 0, done = 0, len = 0; 736 int clock, temp, nobuffs = 0, done = 0, len = 0;
736#ifdef DEBUG 737#if DEBUG
737 int transfered = 0, phase = 0, newphase; 738 int transfered = 0, phase = 0, newphase;
738#endif 739#endif
739 register unsigned char status_read; 740 register unsigned char status_read;
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index fae6e95a62..89e9b36b17 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -468,7 +468,7 @@ static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd,
468 } 468 }
469 469
470 ret = cdrom_ioctl(file, &cd->cdi, inode, cmd, arg); 470 ret = cdrom_ioctl(file, &cd->cdi, inode, cmd, arg);
471 if (ret != ENOSYS) 471 if (ret != -ENOSYS)
472 return ret; 472 return ret;
473 473
474 /* 474 /*
diff --git a/drivers/scsi/sun3_NCR5380.c b/drivers/scsi/sun3_NCR5380.c
index 43f5b6aa7d..98e3fe10c1 100644
--- a/drivers/scsi/sun3_NCR5380.c
+++ b/drivers/scsi/sun3_NCR5380.c
@@ -266,7 +266,7 @@ static struct scsi_host_template *the_template = NULL;
266 (struct NCR5380_hostdata *)(in)->hostdata 266 (struct NCR5380_hostdata *)(in)->hostdata
267#define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata) 267#define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata)
268 268
269#define NEXT(cmd) ((struct scsi_cmnd *)((cmd)->host_scribble)) 269#define NEXT(cmd) (*(struct scsi_cmnd **)&((cmd)->host_scribble))
270#define NEXTADDR(cmd) ((struct scsi_cmnd **)&((cmd)->host_scribble)) 270#define NEXTADDR(cmd) ((struct scsi_cmnd **)&((cmd)->host_scribble))
271 271
272#define HOSTNO instance->host_no 272#define HOSTNO instance->host_no
@@ -650,7 +650,7 @@ __inline__ void NCR5380_print_phase(struct Scsi_Host *instance) { };
650#include <linux/interrupt.h> 650#include <linux/interrupt.h>
651 651
652static volatile int main_running = 0; 652static volatile int main_running = 0;
653static DECLARE_WORK(NCR5380_tqueue, (void (*)(void*))NCR5380_main, NULL); 653static DECLARE_WORK(NCR5380_tqueue, NCR5380_main);
654 654
655static __inline__ void queue_main(void) 655static __inline__ void queue_main(void)
656{ 656{
@@ -1031,7 +1031,7 @@ static int NCR5380_queue_command(struct scsi_cmnd *cmd,
1031 * reenable them. This prevents reentrancy and kernel stack overflow. 1031 * reenable them. This prevents reentrancy and kernel stack overflow.
1032 */ 1032 */
1033 1033
1034static void NCR5380_main (void *bl) 1034static void NCR5380_main (struct work_struct *bl)
1035{ 1035{
1036 struct scsi_cmnd *tmp, *prev; 1036 struct scsi_cmnd *tmp, *prev;
1037 struct Scsi_Host *instance = first_instance; 1037 struct Scsi_Host *instance = first_instance;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 51f3c739f7..5261f0af8b 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -2296,7 +2296,7 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count)
2296 local_irq_restore(flags); 2296 local_irq_restore(flags);
2297} 2297}
2298 2298
2299static int serial8250_console_setup(struct console *co, char *options) 2299static int __init serial8250_console_setup(struct console *co, char *options)
2300{ 2300{
2301 struct uart_port *port; 2301 struct uart_port *port;
2302 int baud = 9600; 2302 int baud = 9600;
diff --git a/drivers/serial/amba-pl010.c b/drivers/serial/amba-pl010.c
index 61db697375..f69bd09716 100644
--- a/drivers/serial/amba-pl010.c
+++ b/drivers/serial/amba-pl010.c
@@ -589,6 +589,8 @@ static int __init pl010_console_setup(struct console *co, char *options)
589 */ 589 */
590 if (co->index >= UART_NR) 590 if (co->index >= UART_NR)
591 co->index = 0; 591 co->index = 0;
592 if (!amba_ports[co->index])
593 return -ENODEV;
592 port = &amba_ports[co->index]->port; 594 port = &amba_ports[co->index]->port;
593 595
594 if (options) 596 if (options)
diff --git a/drivers/serial/amba-pl011.c b/drivers/serial/amba-pl011.c
index 9a3b374b2a..44639e7137 100644
--- a/drivers/serial/amba-pl011.c
+++ b/drivers/serial/amba-pl011.c
@@ -661,6 +661,8 @@ static int __init pl011_console_setup(struct console *co, char *options)
661 if (co->index >= UART_NR) 661 if (co->index >= UART_NR)
662 co->index = 0; 662 co->index = 0;
663 uap = amba_ports[co->index]; 663 uap = amba_ports[co->index];
664 if (!uap)
665 return -ENODEV;
664 666
665 uap->port.uartclk = clk_get_rate(uap->clk); 667 uap->port.uartclk = clk_get_rate(uap->clk);
666 668
diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index ed7f7209ea..881f886b91 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -689,9 +689,9 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port, struct
689 struct atmel_uart_data *data = pdev->dev.platform_data; 689 struct atmel_uart_data *data = pdev->dev.platform_data;
690 690
691 port->iotype = UPIO_MEM; 691 port->iotype = UPIO_MEM;
692 port->flags = UPF_BOOT_AUTOCONF; 692 port->flags = UPF_BOOT_AUTOCONF;
693 port->ops = &atmel_pops; 693 port->ops = &atmel_pops;
694 port->fifosize = 1; 694 port->fifosize = 1;
695 port->line = pdev->id; 695 port->line = pdev->id;
696 port->dev = &pdev->dev; 696 port->dev = &pdev->dev;
697 697
@@ -890,7 +890,6 @@ static int atmel_serial_suspend(struct platform_device *pdev, pm_message_t state
890 if (device_may_wakeup(&pdev->dev) && !at91_suspend_entering_slow_clock()) 890 if (device_may_wakeup(&pdev->dev) && !at91_suspend_entering_slow_clock())
891 enable_irq_wake(port->irq); 891 enable_irq_wake(port->irq);
892 else { 892 else {
893 disable_irq_wake(port->irq);
894 uart_suspend_port(&atmel_uart, port); 893 uart_suspend_port(&atmel_uart, port);
895 atmel_port->suspended = 1; 894 atmel_port->suspended = 1;
896 } 895 }
@@ -907,6 +906,8 @@ static int atmel_serial_resume(struct platform_device *pdev)
907 uart_resume_port(&atmel_uart, port); 906 uart_resume_port(&atmel_uart, port);
908 atmel_port->suspended = 0; 907 atmel_port->suspended = 0;
909 } 908 }
909 else
910 disable_irq_wake(port->irq);
910 911
911 return 0; 912 return 0;
912} 913}
diff --git a/drivers/serial/atmel_serial.h b/drivers/serial/atmel_serial.h
index fe1763b2a6..11b44360e1 100644
--- a/drivers/serial/atmel_serial.h
+++ b/drivers/serial/atmel_serial.h
@@ -106,7 +106,7 @@
106#define ATMEL_US_CSR 0x14 /* Channel Status Register */ 106#define ATMEL_US_CSR 0x14 /* Channel Status Register */
107#define ATMEL_US_RHR 0x18 /* Receiver Holding Register */ 107#define ATMEL_US_RHR 0x18 /* Receiver Holding Register */
108#define ATMEL_US_THR 0x1c /* Transmitter Holding Register */ 108#define ATMEL_US_THR 0x1c /* Transmitter Holding Register */
109#define ATMEL_US_SYNH (1 << 15) /* Transmit/Receive Sync [SAM9 only] */ 109#define ATMEL_US_SYNH (1 << 15) /* Transmit/Receive Sync [AT91SAM9261 only] */
110 110
111#define ATMEL_US_BRGR 0x20 /* Baud Rate Generator Register */ 111#define ATMEL_US_BRGR 0x20 /* Baud Rate Generator Register */
112#define ATMEL_US_CD (0xffff << 0) /* Clock Divider */ 112#define ATMEL_US_CD (0xffff << 0) /* Clock Divider */
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 9d11a75663..3c4b6c2437 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -789,7 +789,9 @@ static struct console mpc52xx_console = {
789static int __init 789static int __init
790mpc52xx_console_init(void) 790mpc52xx_console_init(void)
791{ 791{
792#if defined(CONFIG_PPC_MERGE)
792 mpc52xx_uart_of_enumerate(); 793 mpc52xx_uart_of_enumerate();
794#endif
793 register_console(&mpc52xx_console); 795 register_console(&mpc52xx_console);
794 return 0; 796 return 0;
795} 797}
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index 493d5bbb66..145d623695 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -1037,7 +1037,8 @@ static int __devinit sunsab_init_one(struct uart_sunsab_port *up,
1037 err = request_irq(up->port.irq, sunsab_interrupt, 1037 err = request_irq(up->port.irq, sunsab_interrupt,
1038 IRQF_SHARED, "sab", up); 1038 IRQF_SHARED, "sab", up);
1039 if (err) { 1039 if (err) {
1040 of_iounmap(up->port.membase, 1040 of_iounmap(&op->resource[0],
1041 up->port.membase,
1041 sizeof(union sab82532_async_regs)); 1042 sizeof(union sab82532_async_regs));
1042 return err; 1043 return err;
1043 } 1044 }
@@ -1064,7 +1065,8 @@ static int __devinit sab_probe(struct of_device *op, const struct of_device_id *
1064 sizeof(union sab82532_async_regs), 1065 sizeof(union sab82532_async_regs),
1065 (inst * 2) + 1); 1066 (inst * 2) + 1);
1066 if (err) { 1067 if (err) {
1067 of_iounmap(up[0].port.membase, 1068 of_iounmap(&op->resource[0],
1069 up[0].port.membase,
1068 sizeof(union sab82532_async_regs)); 1070 sizeof(union sab82532_async_regs));
1069 free_irq(up[0].port.irq, &up[0]); 1071 free_irq(up[0].port.irq, &up[0]);
1070 return err; 1072 return err;
@@ -1082,10 +1084,13 @@ static int __devinit sab_probe(struct of_device *op, const struct of_device_id *
1082 1084
1083static void __devexit sab_remove_one(struct uart_sunsab_port *up) 1085static void __devexit sab_remove_one(struct uart_sunsab_port *up)
1084{ 1086{
1087 struct of_device *op = to_of_device(up->port.dev);
1088
1085 uart_remove_one_port(&sunsab_reg, &up->port); 1089 uart_remove_one_port(&sunsab_reg, &up->port);
1086 if (!(up->port.line & 1)) 1090 if (!(up->port.line & 1))
1087 free_irq(up->port.irq, up); 1091 free_irq(up->port.irq, up);
1088 of_iounmap(up->port.membase, 1092 of_iounmap(&op->resource[0],
1093 up->port.membase,
1089 sizeof(union sab82532_async_regs)); 1094 sizeof(union sab82532_async_regs));
1090} 1095}
1091 1096
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index 564592b2b2..3ec3df2181 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -1480,13 +1480,13 @@ static int __devinit su_probe(struct of_device *op, const struct of_device_id *m
1480 return 0; 1480 return 0;
1481 1481
1482out_unmap: 1482out_unmap:
1483 of_iounmap(up->port.membase, up->reg_size); 1483 of_iounmap(&op->resource[0], up->port.membase, up->reg_size);
1484 return err; 1484 return err;
1485} 1485}
1486 1486
1487static int __devexit su_remove(struct of_device *dev) 1487static int __devexit su_remove(struct of_device *op)
1488{ 1488{
1489 struct uart_sunsu_port *up = dev_get_drvdata(&dev->dev);; 1489 struct uart_sunsu_port *up = dev_get_drvdata(&op->dev);
1490 1490
1491 if (up->su_type == SU_PORT_MS || 1491 if (up->su_type == SU_PORT_MS ||
1492 up->su_type == SU_PORT_KBD) { 1492 up->su_type == SU_PORT_KBD) {
@@ -1499,9 +1499,9 @@ static int __devexit su_remove(struct of_device *dev)
1499 } 1499 }
1500 1500
1501 if (up->port.membase) 1501 if (up->port.membase)
1502 of_iounmap(up->port.membase, up->reg_size); 1502 of_iounmap(&op->resource[0], up->port.membase, up->reg_size);
1503 1503
1504 dev_set_drvdata(&dev->dev, NULL); 1504 dev_set_drvdata(&op->dev, NULL);
1505 1505
1506 return 0; 1506 return 0;
1507} 1507}
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index 75de919a94..244f796dc6 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -1379,13 +1379,15 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1379 if (!keyboard_mouse) { 1379 if (!keyboard_mouse) {
1380 err = uart_add_one_port(&sunzilog_reg, &up[0].port); 1380 err = uart_add_one_port(&sunzilog_reg, &up[0].port);
1381 if (err) { 1381 if (err) {
1382 of_iounmap(rp, sizeof(struct zilog_layout)); 1382 of_iounmap(&op->resource[0],
1383 rp, sizeof(struct zilog_layout));
1383 return err; 1384 return err;
1384 } 1385 }
1385 err = uart_add_one_port(&sunzilog_reg, &up[1].port); 1386 err = uart_add_one_port(&sunzilog_reg, &up[1].port);
1386 if (err) { 1387 if (err) {
1387 uart_remove_one_port(&sunzilog_reg, &up[0].port); 1388 uart_remove_one_port(&sunzilog_reg, &up[0].port);
1388 of_iounmap(rp, sizeof(struct zilog_layout)); 1389 of_iounmap(&op->resource[0],
1390 rp, sizeof(struct zilog_layout));
1389 return err; 1391 return err;
1390 } 1392 }
1391 } else { 1393 } else {
@@ -1414,18 +1416,18 @@ static void __devexit zs_remove_one(struct uart_sunzilog_port *up)
1414 uart_remove_one_port(&sunzilog_reg, &up->port); 1416 uart_remove_one_port(&sunzilog_reg, &up->port);
1415} 1417}
1416 1418
1417static int __devexit zs_remove(struct of_device *dev) 1419static int __devexit zs_remove(struct of_device *op)
1418{ 1420{
1419 struct uart_sunzilog_port *up = dev_get_drvdata(&dev->dev); 1421 struct uart_sunzilog_port *up = dev_get_drvdata(&op->dev);
1420 struct zilog_layout __iomem *regs; 1422 struct zilog_layout __iomem *regs;
1421 1423
1422 zs_remove_one(&up[0]); 1424 zs_remove_one(&up[0]);
1423 zs_remove_one(&up[1]); 1425 zs_remove_one(&up[1]);
1424 1426
1425 regs = sunzilog_chip_regs[up[0].port.line / 2]; 1427 regs = sunzilog_chip_regs[up[0].port.line / 2];
1426 of_iounmap(regs, sizeof(struct zilog_layout)); 1428 of_iounmap(&op->resource[0], regs, sizeof(struct zilog_layout));
1427 1429
1428 dev_set_drvdata(&dev->dev, NULL); 1430 dev_set_drvdata(&op->dev, NULL);
1429 1431
1430 return 0; 1432 return 0;
1431} 1433}
diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index 92eba89355..db8607e3d5 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -278,8 +278,8 @@ static int ulite_request_port(struct uart_port *port)
278 278
279static void ulite_config_port(struct uart_port *port, int flags) 279static void ulite_config_port(struct uart_port *port, int flags)
280{ 280{
281 ulite_request_port(port); 281 if (!ulite_request_port(port))
282 port->type = PORT_UARTLITE; 282 port->type = PORT_UARTLITE;
283} 283}
284 284
285static int ulite_verify_port(struct uart_port *port, struct serial_struct *ser) 285static int ulite_verify_port(struct uart_port *port, struct serial_struct *ser)
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index 6ed3f1da92..8b41f9cc25 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -1169,8 +1169,9 @@ static int setup(struct spi_device *spi)
1169 spi->bits_per_word - 16 : spi->bits_per_word) 1169 spi->bits_per_word - 16 : spi->bits_per_word)
1170 | SSCR0_SSE 1170 | SSCR0_SSE
1171 | (spi->bits_per_word > 16 ? SSCR0_EDSS : 0); 1171 | (spi->bits_per_word > 16 ? SSCR0_EDSS : 0);
1172 chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) << 4) 1172 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
1173 | (((spi->mode & SPI_CPOL) != 0) << 3); 1173 chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
1174 | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
1174 1175
1175 /* NOTE: PXA25x_SSP _could_ use external clocking ... */ 1176 /* NOTE: PXA25x_SSP _could_ use external clocking ... */
1176 if (drv_data->ssp_type != PXA25x_SSP) 1177 if (drv_data->ssp_type != PXA25x_SSP)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 270e6211c2..6307428d2c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -366,7 +366,6 @@ spi_alloc_master(struct device *dev, unsigned size)
366 366
367 class_device_initialize(&master->cdev); 367 class_device_initialize(&master->cdev);
368 master->cdev.class = &spi_master_class; 368 master->cdev.class = &spi_master_class;
369 kobj_set_kset_s(&master->cdev, spi_master_class.subsys);
370 master->cdev.dev = get_device(dev); 369 master->cdev.dev = get_device(dev);
371 spi_master_set_devdata(master, &master[1]); 370 spi_master_set_devdata(master, &master[1]);
372 371
@@ -466,14 +465,20 @@ EXPORT_SYMBOL_GPL(spi_unregister_master);
466 */ 465 */
467struct spi_master *spi_busnum_to_master(u16 bus_num) 466struct spi_master *spi_busnum_to_master(u16 bus_num)
468{ 467{
469 char name[9]; 468 struct class_device *cdev;
470 struct kobject *bus; 469 struct spi_master *master = NULL;
471 470 struct spi_master *m;
472 snprintf(name, sizeof name, "spi%u", bus_num); 471
473 bus = kset_find_obj(&spi_master_class.subsys.kset, name); 472 down(&spi_master_class.sem);
474 if (bus) 473 list_for_each_entry(cdev, &spi_master_class.children, node) {
475 return container_of(bus, struct spi_master, cdev.kobj); 474 m = container_of(cdev, struct spi_master, cdev);
476 return NULL; 475 if (m->bus_num == bus_num) {
476 master = spi_master_get(m);
477 break;
478 }
479 }
480 up(&spi_master_class.sem);
481 return master;
477} 482}
478EXPORT_SYMBOL_GPL(spi_busnum_to_master); 483EXPORT_SYMBOL_GPL(spi_busnum_to_master);
479 484
diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc83xx.c
index ff0b04895d..e9798bf7b8 100644
--- a/drivers/spi/spi_mpc83xx.c
+++ b/drivers/spi/spi_mpc83xx.c
@@ -112,6 +112,8 @@ u32 mpc83xx_spi_tx_buf_##type(struct mpc83xx_spi *mpc83xx_spi) \
112{ \ 112{ \
113 u32 data; \ 113 u32 data; \
114 const type * tx = mpc83xx_spi->tx; \ 114 const type * tx = mpc83xx_spi->tx; \
115 if (!tx) \
116 return 0; \
115 data = *tx++; \ 117 data = *tx++; \
116 mpc83xx_spi->tx = tx; \ 118 mpc83xx_spi->tx = tx; \
117 return data; \ 119 return data; \
diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
index 2ebe1fc4c3..651379c51a 100644
--- a/drivers/spi/spi_s3c24xx.c
+++ b/drivers/spi/spi_s3c24xx.c
@@ -10,9 +10,6 @@
10 * 10 *
11*/ 11*/
12 12
13
14//#define DEBUG
15
16#include <linux/init.h> 13#include <linux/init.h>
17#include <linux/spinlock.h> 14#include <linux/spinlock.h>
18#include <linux/workqueue.h> 15#include <linux/workqueue.h>
@@ -44,6 +41,9 @@ struct s3c24xx_spi {
44 int len; 41 int len;
45 int count; 42 int count;
46 43
44 int (*set_cs)(struct s3c2410_spi_info *spi,
45 int cs, int pol);
46
47 /* data buffers */ 47 /* data buffers */
48 const unsigned char *tx; 48 const unsigned char *tx;
49 unsigned char *rx; 49 unsigned char *rx;
@@ -64,6 +64,11 @@ static inline struct s3c24xx_spi *to_hw(struct spi_device *sdev)
64 return spi_master_get_devdata(sdev->master); 64 return spi_master_get_devdata(sdev->master);
65} 65}
66 66
67static void s3c24xx_spi_gpiocs(struct s3c2410_spi_info *spi, int cs, int pol)
68{
69 s3c2410_gpio_setpin(spi->pin_cs, pol);
70}
71
67static void s3c24xx_spi_chipsel(struct spi_device *spi, int value) 72static void s3c24xx_spi_chipsel(struct spi_device *spi, int value)
68{ 73{
69 struct s3c24xx_spi *hw = to_hw(spi); 74 struct s3c24xx_spi *hw = to_hw(spi);
@@ -72,10 +77,7 @@ static void s3c24xx_spi_chipsel(struct spi_device *spi, int value)
72 77
73 switch (value) { 78 switch (value) {
74 case BITBANG_CS_INACTIVE: 79 case BITBANG_CS_INACTIVE:
75 if (hw->pdata->set_cs) 80 hw->pdata->set_cs(hw->pdata, spi->chip_select, cspol^1);
76 hw->pdata->set_cs(hw->pdata, value, cspol);
77 else
78 s3c2410_gpio_setpin(hw->pdata->pin_cs, cspol ^ 1);
79 break; 81 break;
80 82
81 case BITBANG_CS_ACTIVE: 83 case BITBANG_CS_ACTIVE:
@@ -96,14 +98,9 @@ static void s3c24xx_spi_chipsel(struct spi_device *spi, int value)
96 /* write new configration */ 98 /* write new configration */
97 99
98 writeb(spcon, hw->regs + S3C2410_SPCON); 100 writeb(spcon, hw->regs + S3C2410_SPCON);
99 101 hw->pdata->set_cs(hw->pdata, spi->chip_select, cspol);
100 if (hw->pdata->set_cs)
101 hw->pdata->set_cs(hw->pdata, value, cspol);
102 else
103 s3c2410_gpio_setpin(hw->pdata->pin_cs, cspol);
104 102
105 break; 103 break;
106
107 } 104 }
108} 105}
109 106
@@ -174,7 +171,7 @@ static int s3c24xx_spi_setup(struct spi_device *spi)
174 171
175static inline unsigned int hw_txbyte(struct s3c24xx_spi *hw, int count) 172static inline unsigned int hw_txbyte(struct s3c24xx_spi *hw, int count)
176{ 173{
177 return hw->tx ? hw->tx[count] : 0xff; 174 return hw->tx ? hw->tx[count] : 0;
178} 175}
179 176
180static int s3c24xx_spi_txrx(struct spi_device *spi, struct spi_transfer *t) 177static int s3c24xx_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
@@ -330,9 +327,12 @@ static int s3c24xx_spi_probe(struct platform_device *pdev)
330 /* setup any gpio we can */ 327 /* setup any gpio we can */
331 328
332 if (!hw->pdata->set_cs) { 329 if (!hw->pdata->set_cs) {
330 hw->set_cs = s3c24xx_spi_gpiocs;
331
333 s3c2410_gpio_setpin(hw->pdata->pin_cs, 1); 332 s3c2410_gpio_setpin(hw->pdata->pin_cs, 1);
334 s3c2410_gpio_cfgpin(hw->pdata->pin_cs, S3C2410_GPIO_OUTPUT); 333 s3c2410_gpio_cfgpin(hw->pdata->pin_cs, S3C2410_GPIO_OUTPUT);
335 } 334 } else
335 hw->set_cs = hw->pdata->set_cs;
336 336
337 /* register our spi controller */ 337 /* register our spi controller */
338 338
diff --git a/drivers/spi/spi_s3c24xx_gpio.c b/drivers/spi/spi_s3c24xx_gpio.c
index a5d2cdfff4..eda53ed04c 100644
--- a/drivers/spi/spi_s3c24xx_gpio.c
+++ b/drivers/spi/spi_s3c24xx_gpio.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/spinlock.h> 17#include <linux/spinlock.h>
18#include <linux/workqueue.h>
18#include <linux/platform_device.h> 19#include <linux/platform_device.h>
19 20
20#include <linux/spi/spi.h> 21#include <linux/spi/spi.h>
@@ -22,7 +23,7 @@
22 23
23#include <asm/arch/regs-gpio.h> 24#include <asm/arch/regs-gpio.h>
24#include <asm/arch/spi-gpio.h> 25#include <asm/arch/spi-gpio.h>
25#include <asm/arch/hardware.h> 26#include <asm/hardware.h>
26 27
27struct s3c2410_spigpio { 28struct s3c2410_spigpio {
28 struct spi_bitbang bitbang; 29 struct spi_bitbang bitbang;
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 6303970e93..6377db1b44 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -130,7 +130,7 @@ MFG:HEWLETT-PACKARD;MDL:DESKJET 970C;CMD:MLC,PCL,PML;CLASS:PRINTER;DESCRIPTION:H
130 130
131struct usblp { 131struct usblp {
132 struct usb_device *dev; /* USB device */ 132 struct usb_device *dev; /* USB device */
133 struct semaphore sem; /* locks this struct, especially "dev" */ 133 struct mutex mut; /* locks this struct, especially "dev" */
134 char *writebuf; /* write transfer_buffer */ 134 char *writebuf; /* write transfer_buffer */
135 char *readbuf; /* read transfer_buffer */ 135 char *readbuf; /* read transfer_buffer */
136 char *statusbuf; /* status transfer_buffer */ 136 char *statusbuf; /* status transfer_buffer */
@@ -217,6 +217,7 @@ static const struct quirk_printer_struct quirk_printers[] = {
217 { 0x0409, 0xbef4, USBLP_QUIRK_BIDIR }, /* NEC Picty760 (HP OEM) */ 217 { 0x0409, 0xbef4, USBLP_QUIRK_BIDIR }, /* NEC Picty760 (HP OEM) */
218 { 0x0409, 0xf0be, USBLP_QUIRK_BIDIR }, /* NEC Picty920 (HP OEM) */ 218 { 0x0409, 0xf0be, USBLP_QUIRK_BIDIR }, /* NEC Picty920 (HP OEM) */
219 { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */ 219 { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */
220 { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@zut.de> */
220 { 0, 0 } 221 { 0, 0 }
221}; 222};
222 223
@@ -465,7 +466,7 @@ static long usblp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
465 int twoints[2]; 466 int twoints[2];
466 int retval = 0; 467 int retval = 0;
467 468
468 down (&usblp->sem); 469 mutex_lock (&usblp->mut);
469 if (!usblp->present) { 470 if (!usblp->present) {
470 retval = -ENODEV; 471 retval = -ENODEV;
471 goto done; 472 goto done;
@@ -644,14 +645,14 @@ static long usblp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
644 } 645 }
645 646
646done: 647done:
647 up (&usblp->sem); 648 mutex_unlock (&usblp->mut);
648 return retval; 649 return retval;
649} 650}
650 651
651static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) 652static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
652{ 653{
653 struct usblp *usblp = file->private_data; 654 struct usblp *usblp = file->private_data;
654 int timeout, rv, err = 0, transfer_length = 0; 655 int timeout, intr, rv, err = 0, transfer_length = 0;
655 size_t writecount = 0; 656 size_t writecount = 0;
656 657
657 while (writecount < count) { 658 while (writecount < count) {
@@ -668,14 +669,16 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
668 if (rv < 0) 669 if (rv < 0)
669 return writecount ? writecount : -EINTR; 670 return writecount ? writecount : -EINTR;
670 } 671 }
671 down (&usblp->sem); 672 intr = mutex_lock_interruptible (&usblp->mut);
673 if (intr)
674 return writecount ? writecount : -EINTR;
672 if (!usblp->present) { 675 if (!usblp->present) {
673 up (&usblp->sem); 676 mutex_unlock (&usblp->mut);
674 return -ENODEV; 677 return -ENODEV;
675 } 678 }
676 679
677 if (usblp->sleeping) { 680 if (usblp->sleeping) {
678 up (&usblp->sem); 681 mutex_unlock (&usblp->mut);
679 return writecount ? writecount : -ENODEV; 682 return writecount ? writecount : -ENODEV;
680 } 683 }
681 684
@@ -687,10 +690,10 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
687 err = usblp->writeurb->status; 690 err = usblp->writeurb->status;
688 } else 691 } else
689 err = usblp_check_status(usblp, err); 692 err = usblp_check_status(usblp, err);
690 up (&usblp->sem); 693 mutex_unlock (&usblp->mut);
691 694
692 /* if the fault was due to disconnect, let khubd's 695 /* if the fault was due to disconnect, let khubd's
693 * call to usblp_disconnect() grab usblp->sem ... 696 * call to usblp_disconnect() grab usblp->mut ...
694 */ 697 */
695 schedule (); 698 schedule ();
696 continue; 699 continue;
@@ -702,7 +705,7 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
702 */ 705 */
703 writecount += transfer_length; 706 writecount += transfer_length;
704 if (writecount == count) { 707 if (writecount == count) {
705 up(&usblp->sem); 708 mutex_unlock(&usblp->mut);
706 break; 709 break;
707 } 710 }
708 711
@@ -714,7 +717,7 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
714 717
715 if (copy_from_user(usblp->writeurb->transfer_buffer, 718 if (copy_from_user(usblp->writeurb->transfer_buffer,
716 buffer + writecount, transfer_length)) { 719 buffer + writecount, transfer_length)) {
717 up(&usblp->sem); 720 mutex_unlock(&usblp->mut);
718 return writecount ? writecount : -EFAULT; 721 return writecount ? writecount : -EFAULT;
719 } 722 }
720 723
@@ -727,10 +730,10 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
727 count = -EIO; 730 count = -EIO;
728 else 731 else
729 count = writecount ? writecount : -ENOMEM; 732 count = writecount ? writecount : -ENOMEM;
730 up (&usblp->sem); 733 mutex_unlock (&usblp->mut);
731 break; 734 break;
732 } 735 }
733 up (&usblp->sem); 736 mutex_unlock (&usblp->mut);
734 } 737 }
735 738
736 return count; 739 return count;
@@ -739,12 +742,14 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
739static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) 742static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
740{ 743{
741 struct usblp *usblp = file->private_data; 744 struct usblp *usblp = file->private_data;
742 int rv; 745 int rv, intr;
743 746
744 if (!usblp->bidir) 747 if (!usblp->bidir)
745 return -EINVAL; 748 return -EINVAL;
746 749
747 down (&usblp->sem); 750 intr = mutex_lock_interruptible (&usblp->mut);
751 if (intr)
752 return -EINTR;
748 if (!usblp->present) { 753 if (!usblp->present) {
749 count = -ENODEV; 754 count = -ENODEV;
750 goto done; 755 goto done;
@@ -757,9 +762,9 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count,
757 count = -EAGAIN; 762 count = -EAGAIN;
758 goto done; 763 goto done;
759 } 764 }
760 up(&usblp->sem); 765 mutex_unlock(&usblp->mut);
761 rv = wait_event_interruptible(usblp->wait, usblp->rcomplete || !usblp->present); 766 rv = wait_event_interruptible(usblp->wait, usblp->rcomplete || !usblp->present);
762 down(&usblp->sem); 767 mutex_lock(&usblp->mut);
763 if (rv < 0) { 768 if (rv < 0) {
764 count = -EINTR; 769 count = -EINTR;
765 goto done; 770 goto done;
@@ -807,7 +812,7 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count,
807 } 812 }
808 813
809done: 814done:
810 up (&usblp->sem); 815 mutex_unlock (&usblp->mut);
811 return count; 816 return count;
812} 817}
813 818
@@ -886,7 +891,7 @@ static int usblp_probe(struct usb_interface *intf,
886 goto abort; 891 goto abort;
887 } 892 }
888 usblp->dev = dev; 893 usblp->dev = dev;
889 init_MUTEX (&usblp->sem); 894 mutex_init (&usblp->mut);
890 init_waitqueue_head(&usblp->wait); 895 init_waitqueue_head(&usblp->wait);
891 usblp->ifnum = intf->cur_altsetting->desc.bInterfaceNumber; 896 usblp->ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
892 usblp->intf = intf; 897 usblp->intf = intf;
@@ -1178,7 +1183,7 @@ static void usblp_disconnect(struct usb_interface *intf)
1178 device_remove_file(&intf->dev, &dev_attr_ieee1284_id); 1183 device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
1179 1184
1180 mutex_lock (&usblp_mutex); 1185 mutex_lock (&usblp_mutex);
1181 down (&usblp->sem); 1186 mutex_lock (&usblp->mut);
1182 usblp->present = 0; 1187 usblp->present = 0;
1183 usb_set_intfdata (intf, NULL); 1188 usb_set_intfdata (intf, NULL);
1184 1189
@@ -1187,7 +1192,7 @@ static void usblp_disconnect(struct usb_interface *intf)
1187 usblp->writebuf, usblp->writeurb->transfer_dma); 1192 usblp->writebuf, usblp->writeurb->transfer_dma);
1188 usb_buffer_free (usblp->dev, USBLP_BUF_SIZE, 1193 usb_buffer_free (usblp->dev, USBLP_BUF_SIZE,
1189 usblp->readbuf, usblp->readurb->transfer_dma); 1194 usblp->readbuf, usblp->readurb->transfer_dma);
1190 up (&usblp->sem); 1195 mutex_unlock (&usblp->mut);
1191 1196
1192 if (!usblp->used) 1197 if (!usblp->used)
1193 usblp_cleanup (usblp); 1198 usblp_cleanup (usblp);
@@ -1200,11 +1205,11 @@ static int usblp_suspend (struct usb_interface *intf, pm_message_t message)
1200 1205
1201 /* this races against normal access and open */ 1206 /* this races against normal access and open */
1202 mutex_lock (&usblp_mutex); 1207 mutex_lock (&usblp_mutex);
1203 down (&usblp->sem); 1208 mutex_lock (&usblp->mut);
1204 /* we take no more IO */ 1209 /* we take no more IO */
1205 usblp->sleeping = 1; 1210 usblp->sleeping = 1;
1206 usblp_unlink_urbs(usblp); 1211 usblp_unlink_urbs(usblp);
1207 up (&usblp->sem); 1212 mutex_unlock (&usblp->mut);
1208 mutex_unlock (&usblp_mutex); 1213 mutex_unlock (&usblp_mutex);
1209 1214
1210 return 0; 1215 return 0;
@@ -1216,12 +1221,12 @@ static int usblp_resume (struct usb_interface *intf)
1216 int r; 1221 int r;
1217 1222
1218 mutex_lock (&usblp_mutex); 1223 mutex_lock (&usblp_mutex);
1219 down (&usblp->sem); 1224 mutex_lock (&usblp->mut);
1220 1225
1221 usblp->sleeping = 0; 1226 usblp->sleeping = 0;
1222 r = handle_bidir (usblp); 1227 r = handle_bidir (usblp);
1223 1228
1224 up (&usblp->sem); 1229 mutex_unlock (&usblp->mut);
1225 mutex_unlock (&usblp_mutex); 1230 mutex_unlock (&usblp_mutex);
1226 1231
1227 return r; 1232 return r;
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index f8324d8d06..3e66b2a997 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -72,22 +72,6 @@ config USB_SUSPEND
72 72
73 If you are unsure about this, say N here. 73 If you are unsure about this, say N here.
74 74
75config USB_MULTITHREAD_PROBE
76 bool "USB Multi-threaded probe (EXPERIMENTAL)"
77 depends on USB && EXPERIMENTAL
78 default n
79 help
80 Say Y here if you want the USB core to spawn a new thread for
81 every USB device that is probed. This can cause a small speedup
82 in boot times on systems with a lot of different USB devices.
83
84 This option should be safe to enable, but if any odd probing
85 problems are found, please disable it, or dynamically turn it
86 off in the /sys/module/usbcore/parameters/multithread_probe
87 file
88
89 When in doubt, say N.
90
91config USB_OTG 75config USB_OTG
92 bool 76 bool
93 depends on USB && EXPERIMENTAL 77 depends on USB && EXPERIMENTAL
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 3ed4cb2d56..4b3a6ab29b 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -962,7 +962,11 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
962 kfree(dr); 962 kfree(dr);
963 return -EFAULT; 963 return -EFAULT;
964 } 964 }
965 snoop(&ps->dev->dev, "control urb\n"); 965 snoop(&ps->dev->dev, "control urb: bRequest=%02x "
966 "bRrequestType=%02x wValue=%04x "
967 "wIndex=%04x wLength=%04x\n",
968 dr->bRequest, dr->bRequestType, dr->wValue,
969 dr->wIndex, dr->wLength);
966 break; 970 break;
967 971
968 case USBDEVFS_URB_TYPE_BULK: 972 case USBDEVFS_URB_TYPE_BULK:
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index c505b767ce..5e628ae3ae 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -268,6 +268,7 @@ static void ep_device_release(struct device *dev)
268 struct ep_device *ep_dev = to_ep_device(dev); 268 struct ep_device *ep_dev = to_ep_device(dev);
269 269
270 dev_dbg(dev, "%s called for %s\n", __FUNCTION__, dev->bus_id); 270 dev_dbg(dev, "%s called for %s\n", __FUNCTION__, dev->bus_id);
271 endpoint_free_minor(ep_dev);
271 kfree(ep_dev); 272 kfree(ep_dev);
272} 273}
273 274
@@ -349,7 +350,6 @@ void usb_remove_ep_files(struct usb_host_endpoint *endpoint)
349 sprintf(name, "ep_%02x", endpoint->desc.bEndpointAddress); 350 sprintf(name, "ep_%02x", endpoint->desc.bEndpointAddress);
350 sysfs_remove_link(&ep_dev->dev.parent->kobj, name); 351 sysfs_remove_link(&ep_dev->dev.parent->kobj, name);
351 sysfs_remove_group(&ep_dev->dev.kobj, &ep_dev_attr_grp); 352 sysfs_remove_group(&ep_dev->dev.kobj, &ep_dev_attr_grp);
352 endpoint_free_minor(ep_dev);
353 device_unregister(&ep_dev->dev); 353 device_unregister(&ep_dev->dev);
354 endpoint->ep_dev = NULL; 354 endpoint->ep_dev = NULL;
355 destroy_endpoint_class(); 355 destroy_endpoint_class();
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 2651c2e2a8..1988224b36 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -88,14 +88,7 @@ static DECLARE_WAIT_QUEUE_HEAD(khubd_wait);
88static struct task_struct *khubd_task; 88static struct task_struct *khubd_task;
89 89
90/* multithreaded probe logic */ 90/* multithreaded probe logic */
91static int multithread_probe = 91static int multithread_probe = 0;
92#ifdef CONFIG_USB_MULTITHREAD_PROBE
93 1;
94#else
95 0;
96#endif
97module_param(multithread_probe, bool, S_IRUGO);
98MODULE_PARM_DESC(multithread_probe, "Run each USB device probe in a new thread");
99 92
100/* cycle leds on hubs that aren't blinking for attention */ 93/* cycle leds on hubs that aren't blinking for attention */
101static int blinkenlights = 0; 94static int blinkenlights = 0;
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 3e0abbb49f..812c733ba8 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -43,14 +43,16 @@
43#include <linux/usb_gadget.h> 43#include <linux/usb_gadget.h>
44 44
45#include <asm/byteorder.h> 45#include <asm/byteorder.h>
46#include <asm/hardware.h>
46#include <asm/io.h> 47#include <asm/io.h>
47#include <asm/irq.h> 48#include <asm/irq.h>
48#include <asm/system.h> 49#include <asm/system.h>
49#include <asm/mach-types.h> 50#include <asm/mach-types.h>
50 51
51#include <asm/arch/hardware.h>
52#include <asm/arch/gpio.h> 52#include <asm/arch/gpio.h>
53#include <asm/arch/board.h> 53#include <asm/arch/board.h>
54#include <asm/arch/cpu.h>
55#include <asm/arch/at91sam9261_matrix.h>
54 56
55#include "at91_udc.h" 57#include "at91_udc.h"
56 58
@@ -78,27 +80,11 @@
78static const char driver_name [] = "at91_udc"; 80static const char driver_name [] = "at91_udc";
79static const char ep0name[] = "ep0"; 81static const char ep0name[] = "ep0";
80 82
81/*-------------------------------------------------------------------------*/
82 83
83/* 84#define at91_udp_read(dev, reg) \
84 * Read from a UDP register. 85 __raw_readl((dev)->udp_baseaddr + (reg))
85 */ 86#define at91_udp_write(dev, reg, val) \
86static inline unsigned long at91_udp_read(unsigned int reg) 87 __raw_writel((val), (dev)->udp_baseaddr + (reg))
87{
88 void __iomem *udp_base = (void __iomem *)AT91_VA_BASE_UDP;
89
90 return __raw_readl(udp_base + reg);
91}
92
93/*
94 * Write to a UDP register.
95 */
96static inline void at91_udp_write(unsigned int reg, unsigned long value)
97{
98 void __iomem *udp_base = (void __iomem *)AT91_VA_BASE_UDP;
99
100 __raw_writel(value, udp_base + reg);
101}
102 88
103/*-------------------------------------------------------------------------*/ 89/*-------------------------------------------------------------------------*/
104 90
@@ -210,13 +196,13 @@ static int proc_udc_show(struct seq_file *s, void *unused)
210 return 0; 196 return 0;
211 } 197 }
212 198
213 tmp = at91_udp_read(AT91_UDP_FRM_NUM); 199 tmp = at91_udp_read(udc, AT91_UDP_FRM_NUM);
214 seq_printf(s, "frame %05x:%s%s frame=%d\n", tmp, 200 seq_printf(s, "frame %05x:%s%s frame=%d\n", tmp,
215 (tmp & AT91_UDP_FRM_OK) ? " ok" : "", 201 (tmp & AT91_UDP_FRM_OK) ? " ok" : "",
216 (tmp & AT91_UDP_FRM_ERR) ? " err" : "", 202 (tmp & AT91_UDP_FRM_ERR) ? " err" : "",
217 (tmp & AT91_UDP_NUM)); 203 (tmp & AT91_UDP_NUM));
218 204
219 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 205 tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT);
220 seq_printf(s, "glbstate %02x:%s" FOURBITS "\n", tmp, 206 seq_printf(s, "glbstate %02x:%s" FOURBITS "\n", tmp,
221 (tmp & AT91_UDP_RMWUPE) ? " rmwupe" : "", 207 (tmp & AT91_UDP_RMWUPE) ? " rmwupe" : "",
222 (tmp & AT91_UDP_RSMINPR) ? " rsminpr" : "", 208 (tmp & AT91_UDP_RSMINPR) ? " rsminpr" : "",
@@ -224,13 +210,13 @@ static int proc_udc_show(struct seq_file *s, void *unused)
224 (tmp & AT91_UDP_CONFG) ? " confg" : "", 210 (tmp & AT91_UDP_CONFG) ? " confg" : "",
225 (tmp & AT91_UDP_FADDEN) ? " fadden" : ""); 211 (tmp & AT91_UDP_FADDEN) ? " fadden" : "");
226 212
227 tmp = at91_udp_read(AT91_UDP_FADDR); 213 tmp = at91_udp_read(udc, AT91_UDP_FADDR);
228 seq_printf(s, "faddr %03x:%s fadd=%d\n", tmp, 214 seq_printf(s, "faddr %03x:%s fadd=%d\n", tmp,
229 (tmp & AT91_UDP_FEN) ? " fen" : "", 215 (tmp & AT91_UDP_FEN) ? " fen" : "",
230 (tmp & AT91_UDP_FADD)); 216 (tmp & AT91_UDP_FADD));
231 217
232 proc_irq_show(s, "imr ", at91_udp_read(AT91_UDP_IMR)); 218 proc_irq_show(s, "imr ", at91_udp_read(udc, AT91_UDP_IMR));
233 proc_irq_show(s, "isr ", at91_udp_read(AT91_UDP_ISR)); 219 proc_irq_show(s, "isr ", at91_udp_read(udc, AT91_UDP_ISR));
234 220
235 if (udc->enabled && udc->vbus) { 221 if (udc->enabled && udc->vbus) {
236 proc_ep_show(s, &udc->ep[0]); 222 proc_ep_show(s, &udc->ep[0]);
@@ -286,6 +272,7 @@ static inline void remove_debug_file(struct at91_udc *udc) {}
286static void done(struct at91_ep *ep, struct at91_request *req, int status) 272static void done(struct at91_ep *ep, struct at91_request *req, int status)
287{ 273{
288 unsigned stopped = ep->stopped; 274 unsigned stopped = ep->stopped;
275 struct at91_udc *udc = ep->udc;
289 276
290 list_del_init(&req->queue); 277 list_del_init(&req->queue);
291 if (req->req.status == -EINPROGRESS) 278 if (req->req.status == -EINPROGRESS)
@@ -301,7 +288,7 @@ static void done(struct at91_ep *ep, struct at91_request *req, int status)
301 288
302 /* ep0 is always ready; other endpoints need a non-empty queue */ 289 /* ep0 is always ready; other endpoints need a non-empty queue */
303 if (list_empty(&ep->queue) && ep->int_mask != (1 << 0)) 290 if (list_empty(&ep->queue) && ep->int_mask != (1 << 0))
304 at91_udp_write(AT91_UDP_IDR, ep->int_mask); 291 at91_udp_write(udc, AT91_UDP_IDR, ep->int_mask);
305} 292}
306 293
307/*-------------------------------------------------------------------------*/ 294/*-------------------------------------------------------------------------*/
@@ -554,8 +541,8 @@ ok:
554 * reset/init endpoint fifo. NOTE: leaves fifo_bank alone, 541 * reset/init endpoint fifo. NOTE: leaves fifo_bank alone,
555 * since endpoint resets don't reset hw pingpong state. 542 * since endpoint resets don't reset hw pingpong state.
556 */ 543 */
557 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask); 544 at91_udp_write(dev, AT91_UDP_RST_EP, ep->int_mask);
558 at91_udp_write(AT91_UDP_RST_EP, 0); 545 at91_udp_write(dev, AT91_UDP_RST_EP, 0);
559 546
560 local_irq_restore(flags); 547 local_irq_restore(flags);
561 return 0; 548 return 0;
@@ -564,6 +551,7 @@ ok:
564static int at91_ep_disable (struct usb_ep * _ep) 551static int at91_ep_disable (struct usb_ep * _ep)
565{ 552{
566 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); 553 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep);
554 struct at91_udc *udc = ep->udc;
567 unsigned long flags; 555 unsigned long flags;
568 556
569 if (ep == &ep->udc->ep[0]) 557 if (ep == &ep->udc->ep[0])
@@ -579,8 +567,8 @@ static int at91_ep_disable (struct usb_ep * _ep)
579 567
580 /* reset fifos and endpoint */ 568 /* reset fifos and endpoint */
581 if (ep->udc->clocked) { 569 if (ep->udc->clocked) {
582 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask); 570 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask);
583 at91_udp_write(AT91_UDP_RST_EP, 0); 571 at91_udp_write(udc, AT91_UDP_RST_EP, 0);
584 __raw_writel(0, ep->creg); 572 __raw_writel(0, ep->creg);
585 } 573 }
586 574
@@ -695,10 +683,10 @@ static int at91_ep_queue(struct usb_ep *_ep,
695 * reconfigures the endpoints. 683 * reconfigures the endpoints.
696 */ 684 */
697 if (dev->wait_for_config_ack) { 685 if (dev->wait_for_config_ack) {
698 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 686 tmp = at91_udp_read(dev, AT91_UDP_GLB_STAT);
699 tmp ^= AT91_UDP_CONFG; 687 tmp ^= AT91_UDP_CONFG;
700 VDBG("toggle config\n"); 688 VDBG("toggle config\n");
701 at91_udp_write(AT91_UDP_GLB_STAT, tmp); 689 at91_udp_write(dev, AT91_UDP_GLB_STAT, tmp);
702 } 690 }
703 if (req->req.length == 0) { 691 if (req->req.length == 0) {
704ep0_in_status: 692ep0_in_status:
@@ -727,7 +715,7 @@ ep0_in_status:
727 715
728 if (req && !status) { 716 if (req && !status) {
729 list_add_tail (&req->queue, &ep->queue); 717 list_add_tail (&req->queue, &ep->queue);
730 at91_udp_write(AT91_UDP_IER, ep->int_mask); 718 at91_udp_write(dev, AT91_UDP_IER, ep->int_mask);
731 } 719 }
732done: 720done:
733 local_irq_restore(flags); 721 local_irq_restore(flags);
@@ -758,6 +746,7 @@ static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
758static int at91_ep_set_halt(struct usb_ep *_ep, int value) 746static int at91_ep_set_halt(struct usb_ep *_ep, int value)
759{ 747{
760 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); 748 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep);
749 struct at91_udc *udc = ep->udc;
761 u32 __iomem *creg; 750 u32 __iomem *creg;
762 u32 csr; 751 u32 csr;
763 unsigned long flags; 752 unsigned long flags;
@@ -785,8 +774,8 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value)
785 csr |= AT91_UDP_FORCESTALL; 774 csr |= AT91_UDP_FORCESTALL;
786 VDBG("halt %s\n", ep->ep.name); 775 VDBG("halt %s\n", ep->ep.name);
787 } else { 776 } else {
788 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask); 777 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask);
789 at91_udp_write(AT91_UDP_RST_EP, 0); 778 at91_udp_write(udc, AT91_UDP_RST_EP, 0);
790 csr &= ~AT91_UDP_FORCESTALL; 779 csr &= ~AT91_UDP_FORCESTALL;
791 } 780 }
792 __raw_writel(csr, creg); 781 __raw_writel(csr, creg);
@@ -813,9 +802,11 @@ static struct usb_ep_ops at91_ep_ops = {
813 802
814static int at91_get_frame(struct usb_gadget *gadget) 803static int at91_get_frame(struct usb_gadget *gadget)
815{ 804{
805 struct at91_udc *udc = to_udc(gadget);
806
816 if (!to_udc(gadget)->clocked) 807 if (!to_udc(gadget)->clocked)
817 return -EINVAL; 808 return -EINVAL;
818 return at91_udp_read(AT91_UDP_FRM_NUM) & AT91_UDP_NUM; 809 return at91_udp_read(udc, AT91_UDP_FRM_NUM) & AT91_UDP_NUM;
819} 810}
820 811
821static int at91_wakeup(struct usb_gadget *gadget) 812static int at91_wakeup(struct usb_gadget *gadget)
@@ -833,11 +824,11 @@ static int at91_wakeup(struct usb_gadget *gadget)
833 824
834 /* NOTE: some "early versions" handle ESR differently ... */ 825 /* NOTE: some "early versions" handle ESR differently ... */
835 826
836 glbstate = at91_udp_read(AT91_UDP_GLB_STAT); 827 glbstate = at91_udp_read(udc, AT91_UDP_GLB_STAT);
837 if (!(glbstate & AT91_UDP_ESR)) 828 if (!(glbstate & AT91_UDP_ESR))
838 goto done; 829 goto done;
839 glbstate |= AT91_UDP_ESR; 830 glbstate |= AT91_UDP_ESR;
840 at91_udp_write(AT91_UDP_GLB_STAT, glbstate); 831 at91_udp_write(udc, AT91_UDP_GLB_STAT, glbstate);
841 832
842done: 833done:
843 local_irq_restore(flags); 834 local_irq_restore(flags);
@@ -861,6 +852,7 @@ static void udc_reinit(struct at91_udc *udc)
861 ep->stopped = 0; 852 ep->stopped = 0;
862 ep->fifo_bank = 0; 853 ep->fifo_bank = 0;
863 ep->ep.maxpacket = ep->maxpacket; 854 ep->ep.maxpacket = ep->maxpacket;
855 ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i);
864 // initialiser une queue par endpoint 856 // initialiser une queue par endpoint
865 INIT_LIST_HEAD(&ep->queue); 857 INIT_LIST_HEAD(&ep->queue);
866 } 858 }
@@ -915,14 +907,41 @@ static void pullup(struct at91_udc *udc, int is_on)
915 if (!udc->enabled || !udc->vbus) 907 if (!udc->enabled || !udc->vbus)
916 is_on = 0; 908 is_on = 0;
917 DBG("%sactive\n", is_on ? "" : "in"); 909 DBG("%sactive\n", is_on ? "" : "in");
910
918 if (is_on) { 911 if (is_on) {
919 clk_on(udc); 912 clk_on(udc);
920 at91_udp_write(AT91_UDP_TXVC, 0); 913 at91_udp_write(udc, AT91_UDP_TXVC, 0);
921 at91_set_gpio_value(udc->board.pullup_pin, 1); 914 if (cpu_is_at91rm9200())
922 } else { 915 at91_set_gpio_value(udc->board.pullup_pin, 1);
916 else if (cpu_is_at91sam9260()) {
917 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
918
919 txvc |= AT91_UDP_TXVC_PUON;
920 at91_udp_write(udc, AT91_UDP_TXVC, txvc);
921 } else if (cpu_is_at91sam9261()) {
922 u32 usbpucr;
923
924 usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR);
925 usbpucr |= AT91_MATRIX_USBPUCR_PUON;
926 at91_sys_write(AT91_MATRIX_USBPUCR, usbpucr);
927 }
928 } else {
923 stop_activity(udc); 929 stop_activity(udc);
924 at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); 930 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
925 at91_set_gpio_value(udc->board.pullup_pin, 0); 931 if (cpu_is_at91rm9200())
932 at91_set_gpio_value(udc->board.pullup_pin, 0);
933 else if (cpu_is_at91sam9260()) {
934 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
935
936 txvc &= ~AT91_UDP_TXVC_PUON;
937 at91_udp_write(udc, AT91_UDP_TXVC, txvc);
938 } else if (cpu_is_at91sam9261()) {
939 u32 usbpucr;
940
941 usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR);
942 usbpucr &= ~AT91_MATRIX_USBPUCR_PUON;
943 at91_sys_write(AT91_MATRIX_USBPUCR, usbpucr);
944 }
926 clk_off(udc); 945 clk_off(udc);
927 } 946 }
928} 947}
@@ -936,7 +955,10 @@ static int at91_vbus_session(struct usb_gadget *gadget, int is_active)
936 // VDBG("vbus %s\n", is_active ? "on" : "off"); 955 // VDBG("vbus %s\n", is_active ? "on" : "off");
937 local_irq_save(flags); 956 local_irq_save(flags);
938 udc->vbus = (is_active != 0); 957 udc->vbus = (is_active != 0);
939 pullup(udc, is_active); 958 if (udc->driver)
959 pullup(udc, is_active);
960 else
961 pullup(udc, 0);
940 local_irq_restore(flags); 962 local_irq_restore(flags);
941 return 0; 963 return 0;
942} 964}
@@ -1086,7 +1108,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1086 1108
1087 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8) 1109 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1088 | USB_REQ_SET_CONFIGURATION: 1110 | USB_REQ_SET_CONFIGURATION:
1089 tmp = at91_udp_read(AT91_UDP_GLB_STAT) & AT91_UDP_CONFG; 1111 tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT) & AT91_UDP_CONFG;
1090 if (pkt.r.wValue) 1112 if (pkt.r.wValue)
1091 udc->wait_for_config_ack = (tmp == 0); 1113 udc->wait_for_config_ack = (tmp == 0);
1092 else 1114 else
@@ -1103,7 +1125,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1103 case ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8) 1125 case ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1104 | USB_REQ_GET_STATUS: 1126 | USB_REQ_GET_STATUS:
1105 tmp = (udc->selfpowered << USB_DEVICE_SELF_POWERED); 1127 tmp = (udc->selfpowered << USB_DEVICE_SELF_POWERED);
1106 if (at91_udp_read(AT91_UDP_GLB_STAT) & AT91_UDP_ESR) 1128 if (at91_udp_read(udc, AT91_UDP_GLB_STAT) & AT91_UDP_ESR)
1107 tmp |= (1 << USB_DEVICE_REMOTE_WAKEUP); 1129 tmp |= (1 << USB_DEVICE_REMOTE_WAKEUP);
1108 PACKET("get device status\n"); 1130 PACKET("get device status\n");
1109 __raw_writeb(tmp, dreg); 1131 __raw_writeb(tmp, dreg);
@@ -1114,17 +1136,17 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1114 | USB_REQ_SET_FEATURE: 1136 | USB_REQ_SET_FEATURE:
1115 if (w_value != USB_DEVICE_REMOTE_WAKEUP) 1137 if (w_value != USB_DEVICE_REMOTE_WAKEUP)
1116 goto stall; 1138 goto stall;
1117 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 1139 tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT);
1118 tmp |= AT91_UDP_ESR; 1140 tmp |= AT91_UDP_ESR;
1119 at91_udp_write(AT91_UDP_GLB_STAT, tmp); 1141 at91_udp_write(udc, AT91_UDP_GLB_STAT, tmp);
1120 goto succeed; 1142 goto succeed;
1121 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8) 1143 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1122 | USB_REQ_CLEAR_FEATURE: 1144 | USB_REQ_CLEAR_FEATURE:
1123 if (w_value != USB_DEVICE_REMOTE_WAKEUP) 1145 if (w_value != USB_DEVICE_REMOTE_WAKEUP)
1124 goto stall; 1146 goto stall;
1125 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 1147 tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT);
1126 tmp &= ~AT91_UDP_ESR; 1148 tmp &= ~AT91_UDP_ESR;
1127 at91_udp_write(AT91_UDP_GLB_STAT, tmp); 1149 at91_udp_write(udc, AT91_UDP_GLB_STAT, tmp);
1128 goto succeed; 1150 goto succeed;
1129 1151
1130 /* 1152 /*
@@ -1206,8 +1228,8 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1206 } else if (ep->is_in) 1228 } else if (ep->is_in)
1207 goto stall; 1229 goto stall;
1208 1230
1209 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask); 1231 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask);
1210 at91_udp_write(AT91_UDP_RST_EP, 0); 1232 at91_udp_write(udc, AT91_UDP_RST_EP, 0);
1211 tmp = __raw_readl(ep->creg); 1233 tmp = __raw_readl(ep->creg);
1212 tmp |= CLR_FX; 1234 tmp |= CLR_FX;
1213 tmp &= ~(SET_FX | AT91_UDP_FORCESTALL); 1235 tmp &= ~(SET_FX | AT91_UDP_FORCESTALL);
@@ -1222,7 +1244,10 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1222#undef w_length 1244#undef w_length
1223 1245
1224 /* pass request up to the gadget driver */ 1246 /* pass request up to the gadget driver */
1225 status = udc->driver->setup(&udc->gadget, &pkt.r); 1247 if (udc->driver)
1248 status = udc->driver->setup(&udc->gadget, &pkt.r);
1249 else
1250 status = -ENODEV;
1226 if (status < 0) { 1251 if (status < 0) {
1227stall: 1252stall:
1228 VDBG("req %02x.%02x protocol STALL; stat %d\n", 1253 VDBG("req %02x.%02x protocol STALL; stat %d\n",
@@ -1300,13 +1325,13 @@ static void handle_ep0(struct at91_udc *udc)
1300 if (udc->wait_for_addr_ack) { 1325 if (udc->wait_for_addr_ack) {
1301 u32 tmp; 1326 u32 tmp;
1302 1327
1303 at91_udp_write(AT91_UDP_FADDR, 1328 at91_udp_write(udc, AT91_UDP_FADDR,
1304 AT91_UDP_FEN | udc->addr); 1329 AT91_UDP_FEN | udc->addr);
1305 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 1330 tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT);
1306 tmp &= ~AT91_UDP_FADDEN; 1331 tmp &= ~AT91_UDP_FADDEN;
1307 if (udc->addr) 1332 if (udc->addr)
1308 tmp |= AT91_UDP_FADDEN; 1333 tmp |= AT91_UDP_FADDEN;
1309 at91_udp_write(AT91_UDP_GLB_STAT, tmp); 1334 at91_udp_write(udc, AT91_UDP_GLB_STAT, tmp);
1310 1335
1311 udc->wait_for_addr_ack = 0; 1336 udc->wait_for_addr_ack = 0;
1312 VDBG("address %d\n", udc->addr); 1337 VDBG("address %d\n", udc->addr);
@@ -1374,28 +1399,28 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
1374 while (rescans--) { 1399 while (rescans--) {
1375 u32 status; 1400 u32 status;
1376 1401
1377 status = at91_udp_read(AT91_UDP_ISR) 1402 status = at91_udp_read(udc, AT91_UDP_ISR)
1378 & at91_udp_read(AT91_UDP_IMR); 1403 & at91_udp_read(udc, AT91_UDP_IMR);
1379 if (!status) 1404 if (!status)
1380 break; 1405 break;
1381 1406
1382 /* USB reset irq: not maskable */ 1407 /* USB reset irq: not maskable */
1383 if (status & AT91_UDP_ENDBUSRES) { 1408 if (status & AT91_UDP_ENDBUSRES) {
1384 at91_udp_write(AT91_UDP_IDR, ~MINIMUS_INTERRUPTUS); 1409 at91_udp_write(udc, AT91_UDP_IDR, ~MINIMUS_INTERRUPTUS);
1385 at91_udp_write(AT91_UDP_IER, MINIMUS_INTERRUPTUS); 1410 at91_udp_write(udc, AT91_UDP_IER, MINIMUS_INTERRUPTUS);
1386 /* Atmel code clears this irq twice */ 1411 /* Atmel code clears this irq twice */
1387 at91_udp_write(AT91_UDP_ICR, AT91_UDP_ENDBUSRES); 1412 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_ENDBUSRES);
1388 at91_udp_write(AT91_UDP_ICR, AT91_UDP_ENDBUSRES); 1413 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_ENDBUSRES);
1389 VDBG("end bus reset\n"); 1414 VDBG("end bus reset\n");
1390 udc->addr = 0; 1415 udc->addr = 0;
1391 stop_activity(udc); 1416 stop_activity(udc);
1392 1417
1393 /* enable ep0 */ 1418 /* enable ep0 */
1394 at91_udp_write(AT91_UDP_CSR(0), 1419 at91_udp_write(udc, AT91_UDP_CSR(0),
1395 AT91_UDP_EPEDS | AT91_UDP_EPTYPE_CTRL); 1420 AT91_UDP_EPEDS | AT91_UDP_EPTYPE_CTRL);
1396 udc->gadget.speed = USB_SPEED_FULL; 1421 udc->gadget.speed = USB_SPEED_FULL;
1397 udc->suspended = 0; 1422 udc->suspended = 0;
1398 at91_udp_write(AT91_UDP_IER, AT91_UDP_EP(0)); 1423 at91_udp_write(udc, AT91_UDP_IER, AT91_UDP_EP(0));
1399 1424
1400 /* 1425 /*
1401 * NOTE: this driver keeps clocks off unless the 1426 * NOTE: this driver keeps clocks off unless the
@@ -1406,9 +1431,9 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
1406 1431
1407 /* host initiated suspend (3+ms bus idle) */ 1432 /* host initiated suspend (3+ms bus idle) */
1408 } else if (status & AT91_UDP_RXSUSP) { 1433 } else if (status & AT91_UDP_RXSUSP) {
1409 at91_udp_write(AT91_UDP_IDR, AT91_UDP_RXSUSP); 1434 at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXSUSP);
1410 at91_udp_write(AT91_UDP_IER, AT91_UDP_RXRSM); 1435 at91_udp_write(udc, AT91_UDP_IER, AT91_UDP_RXRSM);
1411 at91_udp_write(AT91_UDP_ICR, AT91_UDP_RXSUSP); 1436 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXSUSP);
1412 // VDBG("bus suspend\n"); 1437 // VDBG("bus suspend\n");
1413 if (udc->suspended) 1438 if (udc->suspended)
1414 continue; 1439 continue;
@@ -1425,9 +1450,9 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
1425 1450
1426 /* host initiated resume */ 1451 /* host initiated resume */
1427 } else if (status & AT91_UDP_RXRSM) { 1452 } else if (status & AT91_UDP_RXRSM) {
1428 at91_udp_write(AT91_UDP_IDR, AT91_UDP_RXRSM); 1453 at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM);
1429 at91_udp_write(AT91_UDP_IER, AT91_UDP_RXSUSP); 1454 at91_udp_write(udc, AT91_UDP_IER, AT91_UDP_RXSUSP);
1430 at91_udp_write(AT91_UDP_ICR, AT91_UDP_RXRSM); 1455 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM);
1431 // VDBG("bus resume\n"); 1456 // VDBG("bus resume\n");
1432 if (!udc->suspended) 1457 if (!udc->suspended)
1433 continue; 1458 continue;
@@ -1485,8 +1510,6 @@ static struct at91_udc controller = {
1485 }, 1510 },
1486 .udc = &controller, 1511 .udc = &controller,
1487 .maxpacket = 8, 1512 .maxpacket = 8,
1488 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1489 + AT91_UDP_CSR(0)),
1490 .int_mask = 1 << 0, 1513 .int_mask = 1 << 0,
1491 }, 1514 },
1492 .ep[1] = { 1515 .ep[1] = {
@@ -1497,8 +1520,6 @@ static struct at91_udc controller = {
1497 .udc = &controller, 1520 .udc = &controller,
1498 .is_pingpong = 1, 1521 .is_pingpong = 1,
1499 .maxpacket = 64, 1522 .maxpacket = 64,
1500 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1501 + AT91_UDP_CSR(1)),
1502 .int_mask = 1 << 1, 1523 .int_mask = 1 << 1,
1503 }, 1524 },
1504 .ep[2] = { 1525 .ep[2] = {
@@ -1509,8 +1530,6 @@ static struct at91_udc controller = {
1509 .udc = &controller, 1530 .udc = &controller,
1510 .is_pingpong = 1, 1531 .is_pingpong = 1,
1511 .maxpacket = 64, 1532 .maxpacket = 64,
1512 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1513 + AT91_UDP_CSR(2)),
1514 .int_mask = 1 << 2, 1533 .int_mask = 1 << 2,
1515 }, 1534 },
1516 .ep[3] = { 1535 .ep[3] = {
@@ -1521,8 +1540,6 @@ static struct at91_udc controller = {
1521 }, 1540 },
1522 .udc = &controller, 1541 .udc = &controller,
1523 .maxpacket = 8, 1542 .maxpacket = 8,
1524 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1525 + AT91_UDP_CSR(3)),
1526 .int_mask = 1 << 3, 1543 .int_mask = 1 << 3,
1527 }, 1544 },
1528 .ep[4] = { 1545 .ep[4] = {
@@ -1533,8 +1550,6 @@ static struct at91_udc controller = {
1533 .udc = &controller, 1550 .udc = &controller,
1534 .is_pingpong = 1, 1551 .is_pingpong = 1,
1535 .maxpacket = 256, 1552 .maxpacket = 256,
1536 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1537 + AT91_UDP_CSR(4)),
1538 .int_mask = 1 << 4, 1553 .int_mask = 1 << 4,
1539 }, 1554 },
1540 .ep[5] = { 1555 .ep[5] = {
@@ -1545,8 +1560,6 @@ static struct at91_udc controller = {
1545 .udc = &controller, 1560 .udc = &controller,
1546 .is_pingpong = 1, 1561 .is_pingpong = 1,
1547 .maxpacket = 256, 1562 .maxpacket = 256,
1548 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1549 + AT91_UDP_CSR(5)),
1550 .int_mask = 1 << 5, 1563 .int_mask = 1 << 5,
1551 }, 1564 },
1552 /* ep6 and ep7 are also reserved (custom silicon might use them) */ 1565 /* ep6 and ep7 are also reserved (custom silicon might use them) */
@@ -1572,9 +1585,8 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1572 int retval; 1585 int retval;
1573 1586
1574 if (!driver 1587 if (!driver
1575 || driver->speed != USB_SPEED_FULL 1588 || driver->speed < USB_SPEED_FULL
1576 || !driver->bind 1589 || !driver->bind
1577 || !driver->unbind
1578 || !driver->setup) { 1590 || !driver->setup) {
1579 DBG("bad parameter.\n"); 1591 DBG("bad parameter.\n");
1580 return -EINVAL; 1592 return -EINVAL;
@@ -1595,6 +1607,10 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1595 if (retval) { 1607 if (retval) {
1596 DBG("driver->bind() returned %d\n", retval); 1608 DBG("driver->bind() returned %d\n", retval);
1597 udc->driver = NULL; 1609 udc->driver = NULL;
1610 udc->gadget.dev.driver = NULL;
1611 udc->gadget.dev.driver_data = NULL;
1612 udc->enabled = 0;
1613 udc->selfpowered = 0;
1598 return retval; 1614 return retval;
1599 } 1615 }
1600 1616
@@ -1611,12 +1627,12 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
1611{ 1627{
1612 struct at91_udc *udc = &controller; 1628 struct at91_udc *udc = &controller;
1613 1629
1614 if (!driver || driver != udc->driver) 1630 if (!driver || driver != udc->driver || !driver->unbind)
1615 return -EINVAL; 1631 return -EINVAL;
1616 1632
1617 local_irq_disable(); 1633 local_irq_disable();
1618 udc->enabled = 0; 1634 udc->enabled = 0;
1619 at91_udp_write(AT91_UDP_IDR, ~0); 1635 at91_udp_write(udc, AT91_UDP_IDR, ~0);
1620 pullup(udc, 0); 1636 pullup(udc, 0);
1621 local_irq_enable(); 1637 local_irq_enable();
1622 1638
@@ -1641,6 +1657,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1641 struct device *dev = &pdev->dev; 1657 struct device *dev = &pdev->dev;
1642 struct at91_udc *udc; 1658 struct at91_udc *udc;
1643 int retval; 1659 int retval;
1660 struct resource *res;
1644 1661
1645 if (!dev->platform_data) { 1662 if (!dev->platform_data) {
1646 /* small (so we copy it) but critical! */ 1663 /* small (so we copy it) but critical! */
@@ -1658,7 +1675,13 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1658 return -ENODEV; 1675 return -ENODEV;
1659 } 1676 }
1660 1677
1661 if (!request_mem_region(AT91RM9200_BASE_UDP, SZ_16K, driver_name)) { 1678 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1679 if (!res)
1680 return -ENXIO;
1681
1682 if (!request_mem_region(res->start,
1683 res->end - res->start + 1,
1684 driver_name)) {
1662 DBG("someone's using UDC memory\n"); 1685 DBG("someone's using UDC memory\n");
1663 return -EBUSY; 1686 return -EBUSY;
1664 } 1687 }
@@ -1668,15 +1691,23 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1668 udc->gadget.dev.parent = dev; 1691 udc->gadget.dev.parent = dev;
1669 udc->board = *(struct at91_udc_data *) dev->platform_data; 1692 udc->board = *(struct at91_udc_data *) dev->platform_data;
1670 udc->pdev = pdev; 1693 udc->pdev = pdev;
1671 udc_reinit(udc);
1672 udc->enabled = 0; 1694 udc->enabled = 0;
1673 1695
1696 udc->udp_baseaddr = ioremap(res->start, res->end - res->start + 1);
1697 if (!udc->udp_baseaddr) {
1698 release_mem_region(res->start, res->end - res->start + 1);
1699 return -ENOMEM;
1700 }
1701
1702 udc_reinit(udc);
1703
1674 /* get interface and function clocks */ 1704 /* get interface and function clocks */
1675 udc->iclk = clk_get(dev, "udc_clk"); 1705 udc->iclk = clk_get(dev, "udc_clk");
1676 udc->fclk = clk_get(dev, "udpck"); 1706 udc->fclk = clk_get(dev, "udpck");
1677 if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) { 1707 if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
1678 DBG("clocks missing\n"); 1708 DBG("clocks missing\n");
1679 return -ENODEV; 1709 retval = -ENODEV;
1710 goto fail0;
1680 } 1711 }
1681 1712
1682 retval = device_register(&udc->gadget.dev); 1713 retval = device_register(&udc->gadget.dev);
@@ -1685,8 +1716,10 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1685 1716
1686 /* don't do anything until we have both gadget driver and VBUS */ 1717 /* don't do anything until we have both gadget driver and VBUS */
1687 clk_enable(udc->iclk); 1718 clk_enable(udc->iclk);
1688 at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); 1719 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
1689 at91_udp_write(AT91_UDP_IDR, 0xffffffff); 1720 at91_udp_write(udc, AT91_UDP_IDR, 0xffffffff);
1721 /* Clear all pending interrupts - UDP may be used by bootloader. */
1722 at91_udp_write(udc, AT91_UDP_ICR, 0xffffffff);
1690 clk_disable(udc->iclk); 1723 clk_disable(udc->iclk);
1691 1724
1692 /* request UDC and maybe VBUS irqs */ 1725 /* request UDC and maybe VBUS irqs */
@@ -1698,6 +1731,11 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1698 goto fail1; 1731 goto fail1;
1699 } 1732 }
1700 if (udc->board.vbus_pin > 0) { 1733 if (udc->board.vbus_pin > 0) {
1734 /*
1735 * Get the initial state of VBUS - we cannot expect
1736 * a pending interrupt.
1737 */
1738 udc->vbus = at91_get_gpio_value(udc->board.vbus_pin);
1701 if (request_irq(udc->board.vbus_pin, at91_vbus_irq, 1739 if (request_irq(udc->board.vbus_pin, at91_vbus_irq,
1702 IRQF_DISABLED, driver_name, udc)) { 1740 IRQF_DISABLED, driver_name, udc)) {
1703 DBG("request vbus irq %d failed\n", 1741 DBG("request vbus irq %d failed\n",
@@ -1720,7 +1758,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1720fail1: 1758fail1:
1721 device_unregister(&udc->gadget.dev); 1759 device_unregister(&udc->gadget.dev);
1722fail0: 1760fail0:
1723 release_mem_region(AT91RM9200_BASE_UDP, SZ_16K); 1761 release_mem_region(res->start, res->end - res->start + 1);
1724 DBG("%s probe failed, %d\n", driver_name, retval); 1762 DBG("%s probe failed, %d\n", driver_name, retval);
1725 return retval; 1763 return retval;
1726} 1764}
@@ -1728,13 +1766,14 @@ fail0:
1728static int __devexit at91udc_remove(struct platform_device *pdev) 1766static int __devexit at91udc_remove(struct platform_device *pdev)
1729{ 1767{
1730 struct at91_udc *udc = platform_get_drvdata(pdev); 1768 struct at91_udc *udc = platform_get_drvdata(pdev);
1769 struct resource *res;
1731 1770
1732 DBG("remove\n"); 1771 DBG("remove\n");
1733 1772
1734 pullup(udc, 0); 1773 if (udc->driver)
1774 return -EBUSY;
1735 1775
1736 if (udc->driver != 0) 1776 pullup(udc, 0);
1737 usb_gadget_unregister_driver(udc->driver);
1738 1777
1739 device_init_wakeup(&pdev->dev, 0); 1778 device_init_wakeup(&pdev->dev, 0);
1740 remove_debug_file(udc); 1779 remove_debug_file(udc);
@@ -1742,7 +1781,10 @@ static int __devexit at91udc_remove(struct platform_device *pdev)
1742 free_irq(udc->board.vbus_pin, udc); 1781 free_irq(udc->board.vbus_pin, udc);
1743 free_irq(udc->udp_irq, udc); 1782 free_irq(udc->udp_irq, udc);
1744 device_unregister(&udc->gadget.dev); 1783 device_unregister(&udc->gadget.dev);
1745 release_mem_region(AT91RM9200_BASE_UDP, SZ_16K); 1784
1785 iounmap(udc->udp_baseaddr);
1786 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1787 release_mem_region(res->start, res->end - res->start + 1);
1746 1788
1747 clk_put(udc->iclk); 1789 clk_put(udc->iclk);
1748 clk_put(udc->fclk); 1790 clk_put(udc->fclk);
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index 882af42e86..677089baa5 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -51,10 +51,10 @@
51#define AT91_UDP_EP(n) (1 << (n)) /* Endpoint Interrupt Status */ 51#define AT91_UDP_EP(n) (1 << (n)) /* Endpoint Interrupt Status */
52#define AT91_UDP_RXSUSP (1 << 8) /* USB Suspend Interrupt Status */ 52#define AT91_UDP_RXSUSP (1 << 8) /* USB Suspend Interrupt Status */
53#define AT91_UDP_RXRSM (1 << 9) /* USB Resume Interrupt Status */ 53#define AT91_UDP_RXRSM (1 << 9) /* USB Resume Interrupt Status */
54#define AT91_UDP_EXTRSM (1 << 10) /* External Resume Interrupt Status */ 54#define AT91_UDP_EXTRSM (1 << 10) /* External Resume Interrupt Status [AT91RM9200 only] */
55#define AT91_UDP_SOFINT (1 << 11) /* Start of Frame Interrupt Status */ 55#define AT91_UDP_SOFINT (1 << 11) /* Start of Frame Interrupt Status */
56#define AT91_UDP_ENDBUSRES (1 << 12) /* End of Bus Reset Interrpt Status */ 56#define AT91_UDP_ENDBUSRES (1 << 12) /* End of Bus Reset Interrpt Status */
57#define AT91_UDP_WAKEUP (1 << 13) /* USB Wakeup Interrupt Status */ 57#define AT91_UDP_WAKEUP (1 << 13) /* USB Wakeup Interrupt Status [AT91RM9200 only] */
58 58
59#define AT91_UDP_ICR 0x20 /* Interrupt Clear Register */ 59#define AT91_UDP_ICR 0x20 /* Interrupt Clear Register */
60#define AT91_UDP_RST_EP 0x28 /* Reset Endpoint Register */ 60#define AT91_UDP_RST_EP 0x28 /* Reset Endpoint Register */
@@ -84,7 +84,7 @@
84 84
85#define AT91_UDP_TXVC 0x74 /* Transceiver Control Register */ 85#define AT91_UDP_TXVC 0x74 /* Transceiver Control Register */
86#define AT91_UDP_TXVC_TXVDIS (1 << 8) /* Transceiver Disable */ 86#define AT91_UDP_TXVC_TXVDIS (1 << 8) /* Transceiver Disable */
87 87#define AT91_UDP_TXVC_PUON (1 << 9) /* PullUp On [AT91SAM9260 only] */
88 88
89/*-------------------------------------------------------------------------*/ 89/*-------------------------------------------------------------------------*/
90 90
@@ -141,6 +141,7 @@ struct at91_udc {
141 struct clk *iclk, *fclk; 141 struct clk *iclk, *fclk;
142 struct platform_device *pdev; 142 struct platform_device *pdev;
143 struct proc_dir_entry *pde; 143 struct proc_dir_entry *pde;
144 void __iomem *udp_baseaddr;
144 int udp_irq; 145 int udp_irq;
145}; 146};
146 147
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index f1f32d7be5..3c2bc075ef 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -779,7 +779,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
779 return -EINVAL; 779 return -EINVAL;
780 if (dum->driver) 780 if (dum->driver)
781 return -EBUSY; 781 return -EBUSY;
782 if (!driver->bind || !driver->unbind || !driver->setup 782 if (!driver->bind || !driver->setup
783 || driver->speed == USB_SPEED_UNKNOWN) 783 || driver->speed == USB_SPEED_UNKNOWN)
784 return -EINVAL; 784 return -EINVAL;
785 785
@@ -837,7 +837,8 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
837err_bind_driver: 837err_bind_driver:
838 driver_unregister (&driver->driver); 838 driver_unregister (&driver->driver);
839err_register: 839err_register:
840 driver->unbind (&dum->gadget); 840 if (driver->unbind)
841 driver->unbind (&dum->gadget);
841 spin_lock_irq (&dum->lock); 842 spin_lock_irq (&dum->lock);
842 dum->pullup = 0; 843 dum->pullup = 0;
843 set_link_state (dum); 844 set_link_state (dum);
@@ -857,7 +858,7 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
857 858
858 if (!dum) 859 if (!dum)
859 return -ENODEV; 860 return -ENODEV;
860 if (!driver || driver != dum->driver) 861 if (!driver || driver != dum->driver || !driver->unbind)
861 return -EINVAL; 862 return -EINVAL;
862 863
863 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n", 864 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n",
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a265e262a2..72f2ae96fb 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -4100,7 +4100,7 @@ static struct usb_gadget_driver fsg_driver = {
4100#endif 4100#endif
4101 .function = (char *) longname, 4101 .function = (char *) longname,
4102 .bind = fsg_bind, 4102 .bind = fsg_bind,
4103 .unbind = __exit_p(fsg_unbind), 4103 .unbind = fsg_unbind,
4104 .disconnect = fsg_disconnect, 4104 .disconnect = fsg_disconnect,
4105 .setup = fsg_setup, 4105 .setup = fsg_setup,
4106 .suspend = fsg_suspend, 4106 .suspend = fsg_suspend,
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 31351826f2..f1a679656c 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -123,7 +123,7 @@ struct gmidi_device {
123 struct usb_request *req; /* for control responses */ 123 struct usb_request *req; /* for control responses */
124 u8 config; 124 u8 config;
125 struct usb_ep *in_ep, *out_ep; 125 struct usb_ep *in_ep, *out_ep;
126 struct snd_card *card; 126 struct snd_card *card;
127 struct snd_rawmidi *rmidi; 127 struct snd_rawmidi *rmidi;
128 struct snd_rawmidi_substream *in_substream; 128 struct snd_rawmidi_substream *in_substream;
129 struct snd_rawmidi_substream *out_substream; 129 struct snd_rawmidi_substream *out_substream;
@@ -490,7 +490,7 @@ static void gmidi_complete(struct usb_ep *ep, struct usb_request *req)
490 int status = req->status; 490 int status = req->status;
491 491
492 switch (status) { 492 switch (status) {
493 case 0: /* normal completion */ 493 case 0: /* normal completion */
494 if (ep == dev->out_ep) { 494 if (ep == dev->out_ep) {
495 /* we received stuff. 495 /* we received stuff.
496 req is queued again, below */ 496 req is queued again, below */
@@ -505,7 +505,7 @@ static void gmidi_complete(struct usb_ep *ep, struct usb_request *req)
505 break; 505 break;
506 506
507 /* this endpoint is normally active while we're configured */ 507 /* this endpoint is normally active while we're configured */
508 case -ECONNABORTED: /* hardware forced ep reset */ 508 case -ECONNABORTED: /* hardware forced ep reset */
509 case -ECONNRESET: /* request dequeued */ 509 case -ECONNRESET: /* request dequeued */
510 case -ESHUTDOWN: /* disconnect from host */ 510 case -ESHUTDOWN: /* disconnect from host */
511 VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status, 511 VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status,
@@ -656,7 +656,7 @@ gmidi_set_config(struct gmidi_device *dev, unsigned number, gfp_t gfp_flags)
656 case USB_SPEED_LOW: speed = "low"; break; 656 case USB_SPEED_LOW: speed = "low"; break;
657 case USB_SPEED_FULL: speed = "full"; break; 657 case USB_SPEED_FULL: speed = "full"; break;
658 case USB_SPEED_HIGH: speed = "high"; break; 658 case USB_SPEED_HIGH: speed = "high"; break;
659 default: speed = "?"; break; 659 default: speed = "?"; break;
660 } 660 }
661 661
662 dev->config = number; 662 dev->config = number;
@@ -1308,7 +1308,7 @@ static struct usb_gadget_driver gmidi_driver = {
1308 .speed = USB_SPEED_FULL, 1308 .speed = USB_SPEED_FULL,
1309 .function = (char *)longname, 1309 .function = (char *)longname,
1310 .bind = gmidi_bind, 1310 .bind = gmidi_bind,
1311 .unbind = __exit_p(gmidi_unbind), 1311 .unbind = gmidi_unbind,
1312 1312
1313 .setup = gmidi_setup, 1313 .setup = gmidi_setup,
1314 .disconnect = gmidi_disconnect, 1314 .disconnect = gmidi_disconnect,
@@ -1316,7 +1316,7 @@ static struct usb_gadget_driver gmidi_driver = {
1316 .suspend = gmidi_suspend, 1316 .suspend = gmidi_suspend,
1317 .resume = gmidi_resume, 1317 .resume = gmidi_resume,
1318 1318
1319 .driver = { 1319 .driver = {
1320 .name = (char *)shortname, 1320 .name = (char *)shortname,
1321 .owner = THIS_MODULE, 1321 .owner = THIS_MODULE,
1322 }, 1322 },
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 805a982684..d0ef1d6b3f 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1432,7 +1432,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1432 if (!driver 1432 if (!driver
1433 || driver->speed != USB_SPEED_FULL 1433 || driver->speed != USB_SPEED_FULL
1434 || !driver->bind 1434 || !driver->bind
1435 || !driver->unbind
1436 || !driver->disconnect 1435 || !driver->disconnect
1437 || !driver->setup) 1436 || !driver->setup)
1438 return -EINVAL; 1437 return -EINVAL;
@@ -1495,7 +1494,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1495 1494
1496 if (!dev) 1495 if (!dev)
1497 return -ENODEV; 1496 return -ENODEV;
1498 if (!driver || driver != dev->driver) 1497 if (!driver || driver != dev->driver || !driver->unbind)
1499 return -EINVAL; 1498 return -EINVAL;
1500 1499
1501 spin_lock_irqsave(&dev->lock, flags); 1500 spin_lock_irqsave(&dev->lock, flags);
@@ -1808,13 +1807,8 @@ static void goku_remove(struct pci_dev *pdev)
1808 struct goku_udc *dev = pci_get_drvdata(pdev); 1807 struct goku_udc *dev = pci_get_drvdata(pdev);
1809 1808
1810 DBG(dev, "%s\n", __FUNCTION__); 1809 DBG(dev, "%s\n", __FUNCTION__);
1811 /* start with the driver above us */ 1810
1812 if (dev->driver) { 1811 BUG_ON(dev->driver);
1813 /* should have been done already by driver model core */
1814 WARN(dev, "pci remove, driver '%s' is still registered\n",
1815 dev->driver->driver.name);
1816 usb_gadget_unregister_driver(dev->driver);
1817 }
1818 1812
1819#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1813#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1820 remove_proc_entry(proc_node_name, NULL); 1814 remove_proc_entry(proc_node_name, NULL);
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index 4a991564a0..a0a73c08a3 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -422,9 +422,10 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
422 DEBUG("%s: %s\n", __FUNCTION__, driver->driver.name); 422 DEBUG("%s: %s\n", __FUNCTION__, driver->driver.name);
423 423
424 if (!driver 424 if (!driver
425 || driver->speed != USB_SPEED_FULL 425 || driver->speed != USB_SPEED_FULL
426 || !driver->bind 426 || !driver->bind
427 || !driver->unbind || !driver->disconnect || !driver->setup) 427 || !driver->disconnect
428 || !driver->setup)
428 return -EINVAL; 429 return -EINVAL;
429 if (!dev) 430 if (!dev)
430 return -ENODEV; 431 return -ENODEV;
@@ -471,7 +472,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
471 472
472 if (!dev) 473 if (!dev)
473 return -ENODEV; 474 return -ENODEV;
474 if (!driver || driver != dev->driver) 475 if (!driver || driver != dev->driver || !driver->unbind)
475 return -EINVAL; 476 return -EINVAL;
476 477
477 spin_lock_irqsave(&dev->lock, flags); 478 spin_lock_irqsave(&dev->lock, flags);
@@ -2125,9 +2126,11 @@ static int lh7a40x_udc_remove(struct platform_device *pdev)
2125 2126
2126 DEBUG("%s: %p\n", __FUNCTION__, pdev); 2127 DEBUG("%s: %p\n", __FUNCTION__, pdev);
2127 2128
2129 if (dev->driver)
2130 return -EBUSY;
2131
2128 udc_disable(dev); 2132 udc_disable(dev);
2129 remove_proc_files(); 2133 remove_proc_files();
2130 usb_gadget_unregister_driver(dev->driver);
2131 2134
2132 free_irq(IRQ_USBINTR, dev); 2135 free_irq(IRQ_USBINTR, dev);
2133 2136
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 3024c679e3..569eb8ccf2 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -2020,7 +2020,6 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2020 if (!driver 2020 if (!driver
2021 || driver->speed != USB_SPEED_HIGH 2021 || driver->speed != USB_SPEED_HIGH
2022 || !driver->bind 2022 || !driver->bind
2023 || !driver->unbind
2024 || !driver->setup) 2023 || !driver->setup)
2025 return -EINVAL; 2024 return -EINVAL;
2026 if (!dev) 2025 if (!dev)
@@ -2107,7 +2106,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2107 2106
2108 if (!dev) 2107 if (!dev)
2109 return -ENODEV; 2108 return -ENODEV;
2110 if (!driver || driver != dev->driver) 2109 if (!driver || driver != dev->driver || !driver->unbind)
2111 return -EINVAL; 2110 return -EINVAL;
2112 2111
2113 spin_lock_irqsave (&dev->lock, flags); 2112 spin_lock_irqsave (&dev->lock, flags);
@@ -2803,13 +2802,7 @@ static void net2280_remove (struct pci_dev *pdev)
2803{ 2802{
2804 struct net2280 *dev = pci_get_drvdata (pdev); 2803 struct net2280 *dev = pci_get_drvdata (pdev);
2805 2804
2806 /* start with the driver above us */ 2805 BUG_ON(dev->driver);
2807 if (dev->driver) {
2808 /* should have been done already by driver model core */
2809 WARN (dev, "pci remove, driver '%s' is still registered\n",
2810 dev->driver->driver.name);
2811 usb_gadget_unregister_driver (dev->driver);
2812 }
2813 2806
2814 /* then clean up the resources we allocated during probe() */ 2807 /* then clean up the resources we allocated during probe() */
2815 net2280_led_shutdown (dev); 2808 net2280_led_shutdown (dev);
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 030d87c28c..cdcfd42843 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -42,6 +42,7 @@
42#include <linux/usb_gadget.h> 42#include <linux/usb_gadget.h>
43#include <linux/usb/otg.h> 43#include <linux/usb/otg.h>
44#include <linux/dma-mapping.h> 44#include <linux/dma-mapping.h>
45#include <linux/clk.h>
45 46
46#include <asm/byteorder.h> 47#include <asm/byteorder.h>
47#include <asm/io.h> 48#include <asm/io.h>
@@ -60,6 +61,11 @@
60/* bulk DMA seems to be behaving for both IN and OUT */ 61/* bulk DMA seems to be behaving for both IN and OUT */
61#define USE_DMA 62#define USE_DMA
62 63
64/* FIXME: OMAP2 currently has some problem in DMA mode */
65#ifdef CONFIG_ARCH_OMAP2
66#undef USE_DMA
67#endif
68
63/* ISO too */ 69/* ISO too */
64#define USE_ISO 70#define USE_ISO
65 71
@@ -99,7 +105,7 @@ static unsigned fifo_mode = 0;
99 * boot parameter "omap_udc:fifo_mode=42" 105 * boot parameter "omap_udc:fifo_mode=42"
100 */ 106 */
101module_param (fifo_mode, uint, 0); 107module_param (fifo_mode, uint, 0);
102MODULE_PARM_DESC (fifo_mode, "endpoint setup (0 == default)"); 108MODULE_PARM_DESC (fifo_mode, "endpoint configuration");
103 109
104#ifdef USE_DMA 110#ifdef USE_DMA
105static unsigned use_dma = 1; 111static unsigned use_dma = 1;
@@ -122,7 +128,7 @@ static const char driver_desc [] = DRIVER_DESC;
122/*-------------------------------------------------------------------------*/ 128/*-------------------------------------------------------------------------*/
123 129
124/* there's a notion of "current endpoint" for modifying endpoint 130/* there's a notion of "current endpoint" for modifying endpoint
125 * state, and PIO access to its FIFO. 131 * state, and PIO access to its FIFO.
126 */ 132 */
127 133
128static void use_ep(struct omap_ep *ep, u16 select) 134static void use_ep(struct omap_ep *ep, u16 select)
@@ -391,7 +397,7 @@ done(struct omap_ep *ep, struct omap_req *req, int status)
391#define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY) 397#define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY)
392#define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY) 398#define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY)
393 399
394static inline int 400static inline int
395write_packet(u8 *buf, struct omap_req *req, unsigned max) 401write_packet(u8 *buf, struct omap_req *req, unsigned max)
396{ 402{
397 unsigned len; 403 unsigned len;
@@ -456,7 +462,7 @@ static int write_fifo(struct omap_ep *ep, struct omap_req *req)
456 return is_last; 462 return is_last;
457} 463}
458 464
459static inline int 465static inline int
460read_packet(u8 *buf, struct omap_req *req, unsigned avail) 466read_packet(u8 *buf, struct omap_req *req, unsigned avail)
461{ 467{
462 unsigned len; 468 unsigned len;
@@ -542,9 +548,9 @@ static inline dma_addr_t dma_csac(unsigned lch)
542 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is 548 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
543 * read before the DMA controller finished disabling the channel. 549 * read before the DMA controller finished disabling the channel.
544 */ 550 */
545 csac = omap_readw(OMAP_DMA_CSAC(lch)); 551 csac = OMAP_DMA_CSAC_REG(lch);
546 if (csac == 0) 552 if (csac == 0)
547 csac = omap_readw(OMAP_DMA_CSAC(lch)); 553 csac = OMAP_DMA_CSAC_REG(lch);
548 return csac; 554 return csac;
549} 555}
550 556
@@ -555,9 +561,9 @@ static inline dma_addr_t dma_cdac(unsigned lch)
555 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is 561 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
556 * read before the DMA controller finished disabling the channel. 562 * read before the DMA controller finished disabling the channel.
557 */ 563 */
558 cdac = omap_readw(OMAP_DMA_CDAC(lch)); 564 cdac = OMAP_DMA_CDAC_REG(lch);
559 if (cdac == 0) 565 if (cdac == 0)
560 cdac = omap_readw(OMAP_DMA_CDAC(lch)); 566 cdac = OMAP_DMA_CDAC_REG(lch);
561 return cdac; 567 return cdac;
562} 568}
563 569
@@ -582,7 +588,7 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
582} 588}
583 589
584#define DMA_DEST_LAST(x) (cpu_is_omap15xx() \ 590#define DMA_DEST_LAST(x) (cpu_is_omap15xx() \
585 ? omap_readw(OMAP_DMA_CSAC(x)) /* really: CPC */ \ 591 ? OMAP_DMA_CSAC_REG(x) /* really: CPC */ \
586 : dma_cdac(x)) 592 : dma_cdac(x))
587 593
588static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) 594static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start)
@@ -620,17 +626,19 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
620 || (cpu_is_omap15xx() && length < ep->maxpacket)) { 626 || (cpu_is_omap15xx() && length < ep->maxpacket)) {
621 txdma_ctrl = UDC_TXN_EOT | length; 627 txdma_ctrl = UDC_TXN_EOT | length;
622 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 628 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
623 length, 1, sync_mode); 629 length, 1, sync_mode, 0, 0);
624 } else { 630 } else {
625 length = min(length / ep->maxpacket, 631 length = min(length / ep->maxpacket,
626 (unsigned) UDC_TXN_TSC + 1); 632 (unsigned) UDC_TXN_TSC + 1);
627 txdma_ctrl = length; 633 txdma_ctrl = length;
628 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, 634 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
629 ep->ep.maxpacket >> 1, length, sync_mode); 635 ep->ep.maxpacket >> 1, length, sync_mode,
636 0, 0);
630 length *= ep->maxpacket; 637 length *= ep->maxpacket;
631 } 638 }
632 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, 639 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF,
633 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 640 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual,
641 0, 0);
634 642
635 omap_start_dma(ep->lch); 643 omap_start_dma(ep->lch);
636 ep->dma_counter = dma_csac(ep->lch); 644 ep->dma_counter = dma_csac(ep->lch);
@@ -675,9 +683,11 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
675 req->dma_bytes = packets * ep->ep.maxpacket; 683 req->dma_bytes = packets * ep->ep.maxpacket;
676 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, 684 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
677 ep->ep.maxpacket >> 1, packets, 685 ep->ep.maxpacket >> 1, packets,
678 OMAP_DMA_SYNC_ELEMENT); 686 OMAP_DMA_SYNC_ELEMENT,
687 0, 0);
679 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, 688 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
680 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 689 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual,
690 0, 0);
681 ep->dma_counter = DMA_DEST_LAST(ep->lch); 691 ep->dma_counter = DMA_DEST_LAST(ep->lch);
682 692
683 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1); 693 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1);
@@ -820,7 +830,8 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
820 omap_set_dma_dest_params(ep->lch, 830 omap_set_dma_dest_params(ep->lch,
821 OMAP_DMA_PORT_TIPB, 831 OMAP_DMA_PORT_TIPB,
822 OMAP_DMA_AMODE_CONSTANT, 832 OMAP_DMA_AMODE_CONSTANT,
823 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG)); 833 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG),
834 0, 0);
824 } 835 }
825 } else { 836 } else {
826 status = omap_request_dma(OMAP_DMA_USB_W2FC_RX0 - 1 + channel, 837 status = omap_request_dma(OMAP_DMA_USB_W2FC_RX0 - 1 + channel,
@@ -831,7 +842,8 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
831 omap_set_dma_src_params(ep->lch, 842 omap_set_dma_src_params(ep->lch,
832 OMAP_DMA_PORT_TIPB, 843 OMAP_DMA_PORT_TIPB,
833 OMAP_DMA_AMODE_CONSTANT, 844 OMAP_DMA_AMODE_CONSTANT,
834 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG)); 845 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG),
846 0, 0);
835 /* EMIFF */ 847 /* EMIFF */
836 omap_set_dma_dest_burst_mode(ep->lch, 848 omap_set_dma_dest_burst_mode(ep->lch,
837 OMAP_DMA_DATA_BURST_4); 849 OMAP_DMA_DATA_BURST_4);
@@ -846,7 +858,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
846 858
847 /* channel type P: hw synch (fifo) */ 859 /* channel type P: hw synch (fifo) */
848 if (!cpu_is_omap15xx()) 860 if (!cpu_is_omap15xx())
849 omap_writew(2, OMAP_DMA_LCH_CTRL(ep->lch)); 861 OMAP1_DMA_LCH_CTRL_REG(ep->lch) = 2;
850 } 862 }
851 863
852just_restart: 864just_restart:
@@ -893,7 +905,7 @@ static void dma_channel_release(struct omap_ep *ep)
893 else 905 else
894 req = NULL; 906 req = NULL;
895 907
896 active = ((1 << 7) & omap_readl(OMAP_DMA_CCR(ep->lch))) != 0; 908 active = ((1 << 7) & OMAP_DMA_CCR_REG(ep->lch)) != 0;
897 909
898 DBG("%s release %s %cxdma%d %p\n", ep->ep.name, 910 DBG("%s release %s %cxdma%d %p\n", ep->ep.name,
899 active ? "active" : "idle", 911 active ? "active" : "idle",
@@ -1117,7 +1129,7 @@ static int omap_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1117 */ 1129 */
1118 dma_channel_release(ep); 1130 dma_channel_release(ep);
1119 dma_channel_claim(ep, channel); 1131 dma_channel_claim(ep, channel);
1120 } else 1132 } else
1121 done(ep, req, -ECONNRESET); 1133 done(ep, req, -ECONNRESET);
1122 spin_unlock_irqrestore(&ep->udc->lock, flags); 1134 spin_unlock_irqrestore(&ep->udc->lock, flags);
1123 return 0; 1135 return 0;
@@ -1153,7 +1165,7 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
1153 1165
1154 /* IN endpoints must already be idle */ 1166 /* IN endpoints must already be idle */
1155 if ((ep->bEndpointAddress & USB_DIR_IN) 1167 if ((ep->bEndpointAddress & USB_DIR_IN)
1156 && !list_empty(&ep->queue)) { 1168 && !list_empty(&ep->queue)) {
1157 status = -EAGAIN; 1169 status = -EAGAIN;
1158 goto done; 1170 goto done;
1159 } 1171 }
@@ -1298,6 +1310,23 @@ static void pullup_disable(struct omap_udc *udc)
1298 UDC_SYSCON1_REG &= ~UDC_PULLUP_EN; 1310 UDC_SYSCON1_REG &= ~UDC_PULLUP_EN;
1299} 1311}
1300 1312
1313static struct omap_udc *udc;
1314
1315static void omap_udc_enable_clock(int enable)
1316{
1317 if (udc == NULL || udc->dc_clk == NULL || udc->hhc_clk == NULL)
1318 return;
1319
1320 if (enable) {
1321 clk_enable(udc->dc_clk);
1322 clk_enable(udc->hhc_clk);
1323 udelay(100);
1324 } else {
1325 clk_disable(udc->hhc_clk);
1326 clk_disable(udc->dc_clk);
1327 }
1328}
1329
1301/* 1330/*
1302 * Called by whatever detects VBUS sessions: external transceiver 1331 * Called by whatever detects VBUS sessions: external transceiver
1303 * driver, or maybe GPIO0 VBUS IRQ. May request 48 MHz clock. 1332 * driver, or maybe GPIO0 VBUS IRQ. May request 48 MHz clock.
@@ -1318,10 +1347,22 @@ static int omap_vbus_session(struct usb_gadget *gadget, int is_active)
1318 else 1347 else
1319 FUNC_MUX_CTRL_0_REG &= ~VBUS_CTRL_1510; 1348 FUNC_MUX_CTRL_0_REG &= ~VBUS_CTRL_1510;
1320 } 1349 }
1350 if (udc->dc_clk != NULL && is_active) {
1351 if (!udc->clk_requested) {
1352 omap_udc_enable_clock(1);
1353 udc->clk_requested = 1;
1354 }
1355 }
1321 if (can_pullup(udc)) 1356 if (can_pullup(udc))
1322 pullup_enable(udc); 1357 pullup_enable(udc);
1323 else 1358 else
1324 pullup_disable(udc); 1359 pullup_disable(udc);
1360 if (udc->dc_clk != NULL && !is_active) {
1361 if (udc->clk_requested) {
1362 omap_udc_enable_clock(0);
1363 udc->clk_requested = 0;
1364 }
1365 }
1325 spin_unlock_irqrestore(&udc->lock, flags); 1366 spin_unlock_irqrestore(&udc->lock, flags);
1326 return 0; 1367 return 0;
1327} 1368}
@@ -1441,7 +1482,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1441 } 1482 }
1442 } 1483 }
1443 1484
1444 /* IN/OUT packets mean we're in the DATA or STATUS stage. 1485 /* IN/OUT packets mean we're in the DATA or STATUS stage.
1445 * This driver uses only uses protocol stalls (ep0 never halts), 1486 * This driver uses only uses protocol stalls (ep0 never halts),
1446 * and if we got this far the gadget driver already had a 1487 * and if we got this far the gadget driver already had a
1447 * chance to stall. Tries to be forgiving of host oddities. 1488 * chance to stall. Tries to be forgiving of host oddities.
@@ -1509,7 +1550,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1509 } else if (stat == 0) 1550 } else if (stat == 0)
1510 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1551 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1511 UDC_EP_NUM_REG = 0; 1552 UDC_EP_NUM_REG = 0;
1512 1553
1513 /* activate status stage */ 1554 /* activate status stage */
1514 if (stat == 1) { 1555 if (stat == 1) {
1515 done(ep0, req, 0); 1556 done(ep0, req, 0);
@@ -1866,7 +1907,7 @@ static void pio_out_timer(unsigned long _ep)
1866 1907
1867 spin_lock_irqsave(&ep->udc->lock, flags); 1908 spin_lock_irqsave(&ep->udc->lock, flags);
1868 if (!list_empty(&ep->queue) && ep->ackwait) { 1909 if (!list_empty(&ep->queue) && ep->ackwait) {
1869 use_ep(ep, 0); 1910 use_ep(ep, UDC_EP_SEL);
1870 stat_flg = UDC_STAT_FLG_REG; 1911 stat_flg = UDC_STAT_FLG_REG;
1871 1912
1872 if ((stat_flg & UDC_ACK) && (!(stat_flg & UDC_FIFO_EN) 1913 if ((stat_flg & UDC_ACK) && (!(stat_flg & UDC_FIFO_EN)
@@ -1876,12 +1917,12 @@ static void pio_out_timer(unsigned long _ep)
1876 VDBG("%s: lose, %04x\n", ep->ep.name, stat_flg); 1917 VDBG("%s: lose, %04x\n", ep->ep.name, stat_flg);
1877 req = container_of(ep->queue.next, 1918 req = container_of(ep->queue.next,
1878 struct omap_req, queue); 1919 struct omap_req, queue);
1879 UDC_EP_NUM_REG = ep->bEndpointAddress | UDC_EP_SEL;
1880 (void) read_fifo(ep, req); 1920 (void) read_fifo(ep, req);
1881 UDC_EP_NUM_REG = ep->bEndpointAddress; 1921 UDC_EP_NUM_REG = ep->bEndpointAddress;
1882 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1922 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1883 ep->ackwait = 1 + ep->double_buf; 1923 ep->ackwait = 1 + ep->double_buf;
1884 } 1924 } else
1925 deselect_ep();
1885 } 1926 }
1886 mod_timer(&ep->timer, PIO_OUT_TIMEOUT); 1927 mod_timer(&ep->timer, PIO_OUT_TIMEOUT);
1887 spin_unlock_irqrestore(&ep->udc->lock, flags); 1928 spin_unlock_irqrestore(&ep->udc->lock, flags);
@@ -2028,7 +2069,17 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev)
2028 2069
2029/*-------------------------------------------------------------------------*/ 2070/*-------------------------------------------------------------------------*/
2030 2071
2031static struct omap_udc *udc; 2072static inline int machine_needs_vbus_session(void)
2073{
2074 return (machine_is_omap_innovator()
2075 || machine_is_omap_osk()
2076 || machine_is_omap_apollon()
2077#ifndef CONFIG_MACH_OMAP_H4_OTG
2078 || machine_is_omap_h4()
2079#endif
2080 || machine_is_sx1()
2081 );
2082}
2032 2083
2033int usb_gadget_register_driver (struct usb_gadget_driver *driver) 2084int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2034{ 2085{
@@ -2043,7 +2094,6 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2043 // FIXME if otg, check: driver->is_otg 2094 // FIXME if otg, check: driver->is_otg
2044 || driver->speed < USB_SPEED_FULL 2095 || driver->speed < USB_SPEED_FULL
2045 || !driver->bind 2096 || !driver->bind
2046 || !driver->unbind
2047 || !driver->setup) 2097 || !driver->setup)
2048 return -EINVAL; 2098 return -EINVAL;
2049 2099
@@ -2071,6 +2121,9 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2071 udc->gadget.dev.driver = &driver->driver; 2121 udc->gadget.dev.driver = &driver->driver;
2072 spin_unlock_irqrestore(&udc->lock, flags); 2122 spin_unlock_irqrestore(&udc->lock, flags);
2073 2123
2124 if (udc->dc_clk != NULL)
2125 omap_udc_enable_clock(1);
2126
2074 status = driver->bind (&udc->gadget); 2127 status = driver->bind (&udc->gadget);
2075 if (status) { 2128 if (status) {
2076 DBG("bind to %s --> %d\n", driver->driver.name, status); 2129 DBG("bind to %s --> %d\n", driver->driver.name, status);
@@ -2087,9 +2140,11 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2087 status = otg_set_peripheral(udc->transceiver, &udc->gadget); 2140 status = otg_set_peripheral(udc->transceiver, &udc->gadget);
2088 if (status < 0) { 2141 if (status < 0) {
2089 ERR("can't bind to transceiver\n"); 2142 ERR("can't bind to transceiver\n");
2090 driver->unbind (&udc->gadget); 2143 if (driver->unbind) {
2091 udc->gadget.dev.driver = NULL; 2144 driver->unbind (&udc->gadget);
2092 udc->driver = NULL; 2145 udc->gadget.dev.driver = NULL;
2146 udc->driver = NULL;
2147 }
2093 goto done; 2148 goto done;
2094 } 2149 }
2095 } else { 2150 } else {
@@ -2102,10 +2157,12 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2102 /* boards that don't have VBUS sensing can't autogate 48MHz; 2157 /* boards that don't have VBUS sensing can't autogate 48MHz;
2103 * can't enter deep sleep while a gadget driver is active. 2158 * can't enter deep sleep while a gadget driver is active.
2104 */ 2159 */
2105 if (machine_is_omap_innovator() || machine_is_omap_osk()) 2160 if (machine_needs_vbus_session())
2106 omap_vbus_session(&udc->gadget, 1); 2161 omap_vbus_session(&udc->gadget, 1);
2107 2162
2108done: 2163done:
2164 if (udc->dc_clk != NULL)
2165 omap_udc_enable_clock(0);
2109 return status; 2166 return status;
2110} 2167}
2111EXPORT_SYMBOL(usb_gadget_register_driver); 2168EXPORT_SYMBOL(usb_gadget_register_driver);
@@ -2117,10 +2174,13 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2117 2174
2118 if (!udc) 2175 if (!udc)
2119 return -ENODEV; 2176 return -ENODEV;
2120 if (!driver || driver != udc->driver) 2177 if (!driver || driver != udc->driver || !driver->unbind)
2121 return -EINVAL; 2178 return -EINVAL;
2122 2179
2123 if (machine_is_omap_innovator() || machine_is_omap_osk()) 2180 if (udc->dc_clk != NULL)
2181 omap_udc_enable_clock(1);
2182
2183 if (machine_needs_vbus_session())
2124 omap_vbus_session(&udc->gadget, 0); 2184 omap_vbus_session(&udc->gadget, 0);
2125 2185
2126 if (udc->transceiver) 2186 if (udc->transceiver)
@@ -2136,6 +2196,8 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2136 udc->gadget.dev.driver = NULL; 2196 udc->gadget.dev.driver = NULL;
2137 udc->driver = NULL; 2197 udc->driver = NULL;
2138 2198
2199 if (udc->dc_clk != NULL)
2200 omap_udc_enable_clock(0);
2139 DBG("unregistered driver '%s'\n", driver->driver.name); 2201 DBG("unregistered driver '%s'\n", driver->driver.name);
2140 return status; 2202 return status;
2141} 2203}
@@ -2218,7 +2280,7 @@ static char *trx_mode(unsigned m, int enabled)
2218 case 0: return enabled ? "*6wire" : "unused"; 2280 case 0: return enabled ? "*6wire" : "unused";
2219 case 1: return "4wire"; 2281 case 1: return "4wire";
2220 case 2: return "3wire"; 2282 case 2: return "3wire";
2221 case 3: return "6wire"; 2283 case 3: return "6wire";
2222 default: return "unknown"; 2284 default: return "unknown";
2223 } 2285 }
2224} 2286}
@@ -2227,11 +2289,18 @@ static int proc_otg_show(struct seq_file *s)
2227{ 2289{
2228 u32 tmp; 2290 u32 tmp;
2229 u32 trans; 2291 u32 trans;
2292 char *ctrl_name;
2230 2293
2231 tmp = OTG_REV_REG; 2294 tmp = OTG_REV_REG;
2232 trans = USB_TRANSCEIVER_CTRL_REG; 2295 if (cpu_is_omap24xx()) {
2233 seq_printf(s, "\nOTG rev %d.%d, transceiver_ctrl %05x\n", 2296 ctrl_name = "control_devconf";
2234 tmp >> 4, tmp & 0xf, trans); 2297 trans = CONTROL_DEVCONF_REG;
2298 } else {
2299 ctrl_name = "tranceiver_ctrl";
2300 trans = USB_TRANSCEIVER_CTRL_REG;
2301 }
2302 seq_printf(s, "\nOTG rev %d.%d, %s %05x\n",
2303 tmp >> 4, tmp & 0xf, ctrl_name, trans);
2235 tmp = OTG_SYSCON_1_REG; 2304 tmp = OTG_SYSCON_1_REG;
2236 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," 2305 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s,"
2237 FOURBITS "\n", tmp, 2306 FOURBITS "\n", tmp,
@@ -2306,7 +2375,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2306 driver_desc, 2375 driver_desc,
2307 use_dma ? " (dma)" : ""); 2376 use_dma ? " (dma)" : "");
2308 2377
2309 tmp = UDC_REV_REG & 0xff; 2378 tmp = UDC_REV_REG & 0xff;
2310 seq_printf(s, 2379 seq_printf(s,
2311 "UDC rev %d.%d, fifo mode %d, gadget %s\n" 2380 "UDC rev %d.%d, fifo mode %d, gadget %s\n"
2312 "hmc %d, transceiver %s\n", 2381 "hmc %d, transceiver %s\n",
@@ -2314,11 +2383,16 @@ static int proc_udc_show(struct seq_file *s, void *_)
2314 fifo_mode, 2383 fifo_mode,
2315 udc->driver ? udc->driver->driver.name : "(none)", 2384 udc->driver ? udc->driver->driver.name : "(none)",
2316 HMC, 2385 HMC,
2317 udc->transceiver ? udc->transceiver->label : "(none)"); 2386 udc->transceiver
2318 seq_printf(s, "ULPD control %04x req %04x status %04x\n", 2387 ? udc->transceiver->label
2319 __REG16(ULPD_CLOCK_CTRL), 2388 : ((cpu_is_omap1710() || cpu_is_omap24xx())
2320 __REG16(ULPD_SOFT_REQ), 2389 ? "external" : "(none)"));
2321 __REG16(ULPD_STATUS_REQ)); 2390 if (cpu_class_is_omap1()) {
2391 seq_printf(s, "ULPD control %04x req %04x status %04x\n",
2392 __REG16(ULPD_CLOCK_CTRL),
2393 __REG16(ULPD_SOFT_REQ),
2394 __REG16(ULPD_STATUS_REQ));
2395 }
2322 2396
2323 /* OTG controller registers */ 2397 /* OTG controller registers */
2324 if (!cpu_is_omap15xx()) 2398 if (!cpu_is_omap15xx())
@@ -2503,9 +2577,10 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2503 dbuf = 1; 2577 dbuf = 1;
2504 } else { 2578 } else {
2505 /* double-buffering "not supported" on 15xx, 2579 /* double-buffering "not supported" on 15xx,
2506 * and ignored for PIO-IN on 16xx 2580 * and ignored for PIO-IN on newer chips
2581 * (for more reliable behavior)
2507 */ 2582 */
2508 if (!use_dma || cpu_is_omap15xx()) 2583 if (!use_dma || cpu_is_omap15xx() || cpu_is_omap24xx())
2509 dbuf = 0; 2584 dbuf = 0;
2510 2585
2511 switch (maxp) { 2586 switch (maxp) {
@@ -2548,7 +2623,7 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2548 ep->bEndpointAddress = addr; 2623 ep->bEndpointAddress = addr;
2549 ep->bmAttributes = type; 2624 ep->bmAttributes = type;
2550 ep->double_buf = dbuf; 2625 ep->double_buf = dbuf;
2551 ep->udc = udc; 2626 ep->udc = udc;
2552 2627
2553 ep->ep.name = ep->name; 2628 ep->ep.name = ep->name;
2554 ep->ep.ops = &omap_ep_ops; 2629 ep->ep.ops = &omap_ep_ops;
@@ -2708,15 +2783,37 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2708 struct otg_transceiver *xceiv = NULL; 2783 struct otg_transceiver *xceiv = NULL;
2709 const char *type = NULL; 2784 const char *type = NULL;
2710 struct omap_usb_config *config = pdev->dev.platform_data; 2785 struct omap_usb_config *config = pdev->dev.platform_data;
2786 struct clk *dc_clk;
2787 struct clk *hhc_clk;
2711 2788
2712 /* NOTE: "knows" the order of the resources! */ 2789 /* NOTE: "knows" the order of the resources! */
2713 if (!request_mem_region(pdev->resource[0].start, 2790 if (!request_mem_region(pdev->resource[0].start,
2714 pdev->resource[0].end - pdev->resource[0].start + 1, 2791 pdev->resource[0].end - pdev->resource[0].start + 1,
2715 driver_name)) { 2792 driver_name)) {
2716 DBG("request_mem_region failed\n"); 2793 DBG("request_mem_region failed\n");
2717 return -EBUSY; 2794 return -EBUSY;
2718 } 2795 }
2719 2796
2797 if (cpu_is_omap16xx()) {
2798 dc_clk = clk_get(&pdev->dev, "usb_dc_ck");
2799 hhc_clk = clk_get(&pdev->dev, "usb_hhc_ck");
2800 BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk));
2801 /* can't use omap_udc_enable_clock yet */
2802 clk_enable(dc_clk);
2803 clk_enable(hhc_clk);
2804 udelay(100);
2805 }
2806
2807 if (cpu_is_omap24xx()) {
2808 dc_clk = clk_get(&pdev->dev, "usb_fck");
2809 hhc_clk = clk_get(&pdev->dev, "usb_l4_ick");
2810 BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk));
2811 /* can't use omap_udc_enable_clock yet */
2812 clk_enable(dc_clk);
2813 clk_enable(hhc_clk);
2814 udelay(100);
2815 }
2816
2720 INFO("OMAP UDC rev %d.%d%s\n", 2817 INFO("OMAP UDC rev %d.%d%s\n",
2721 UDC_REV_REG >> 4, UDC_REV_REG & 0xf, 2818 UDC_REV_REG >> 4, UDC_REV_REG & 0xf,
2722 config->otg ? ", Mini-AB" : ""); 2819 config->otg ? ", Mini-AB" : "");
@@ -2726,7 +2823,7 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2726 hmc = HMC_1510; 2823 hmc = HMC_1510;
2727 type = "(unknown)"; 2824 type = "(unknown)";
2728 2825
2729 if (machine_is_omap_innovator()) { 2826 if (machine_is_omap_innovator() || machine_is_sx1()) {
2730 /* just set up software VBUS detect, and then 2827 /* just set up software VBUS detect, and then
2731 * later rig it so we always report VBUS. 2828 * later rig it so we always report VBUS.
2732 * FIXME without really sensing VBUS, we can't 2829 * FIXME without really sensing VBUS, we can't
@@ -2755,6 +2852,15 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2755 } 2852 }
2756 2853
2757 hmc = HMC_1610; 2854 hmc = HMC_1610;
2855
2856 if (cpu_is_omap24xx()) {
2857 /* this could be transceiverless in one of the
2858 * "we don't need to know" modes.
2859 */
2860 type = "external";
2861 goto known;
2862 }
2863
2758 switch (hmc) { 2864 switch (hmc) {
2759 case 0: /* POWERUP DEFAULT == 0 */ 2865 case 0: /* POWERUP DEFAULT == 0 */
2760 case 4: 2866 case 4:
@@ -2793,6 +2899,7 @@ bad_on_1710:
2793 goto cleanup0; 2899 goto cleanup0;
2794 } 2900 }
2795 } 2901 }
2902known:
2796 INFO("hmc mode %d, %s transceiver\n", hmc, type); 2903 INFO("hmc mode %d, %s transceiver\n", hmc, type);
2797 2904
2798 /* a "gadget" abstracts/virtualizes the controller */ 2905 /* a "gadget" abstracts/virtualizes the controller */
@@ -2817,8 +2924,8 @@ bad_on_1710:
2817 status = request_irq(pdev->resource[1].start, omap_udc_irq, 2924 status = request_irq(pdev->resource[1].start, omap_udc_irq,
2818 IRQF_SAMPLE_RANDOM, driver_name, udc); 2925 IRQF_SAMPLE_RANDOM, driver_name, udc);
2819 if (status != 0) { 2926 if (status != 0) {
2820 ERR( "can't get irq %ld, err %d\n", 2927 ERR("can't get irq %d, err %d\n",
2821 pdev->resource[1].start, status); 2928 (int) pdev->resource[1].start, status);
2822 goto cleanup1; 2929 goto cleanup1;
2823 } 2930 }
2824 2931
@@ -2826,24 +2933,41 @@ bad_on_1710:
2826 status = request_irq(pdev->resource[2].start, omap_udc_pio_irq, 2933 status = request_irq(pdev->resource[2].start, omap_udc_pio_irq,
2827 IRQF_SAMPLE_RANDOM, "omap_udc pio", udc); 2934 IRQF_SAMPLE_RANDOM, "omap_udc pio", udc);
2828 if (status != 0) { 2935 if (status != 0) {
2829 ERR( "can't get irq %ld, err %d\n", 2936 ERR("can't get irq %d, err %d\n",
2830 pdev->resource[2].start, status); 2937 (int) pdev->resource[2].start, status);
2831 goto cleanup2; 2938 goto cleanup2;
2832 } 2939 }
2833#ifdef USE_ISO 2940#ifdef USE_ISO
2834 status = request_irq(pdev->resource[3].start, omap_udc_iso_irq, 2941 status = request_irq(pdev->resource[3].start, omap_udc_iso_irq,
2835 IRQF_DISABLED, "omap_udc iso", udc); 2942 IRQF_DISABLED, "omap_udc iso", udc);
2836 if (status != 0) { 2943 if (status != 0) {
2837 ERR("can't get irq %ld, err %d\n", 2944 ERR("can't get irq %d, err %d\n",
2838 pdev->resource[3].start, status); 2945 (int) pdev->resource[3].start, status);
2839 goto cleanup3; 2946 goto cleanup3;
2840 } 2947 }
2841#endif 2948#endif
2949 if (cpu_is_omap16xx()) {
2950 udc->dc_clk = dc_clk;
2951 udc->hhc_clk = hhc_clk;
2952 clk_disable(hhc_clk);
2953 clk_disable(dc_clk);
2954 }
2955
2956 if (cpu_is_omap24xx()) {
2957 udc->dc_clk = dc_clk;
2958 udc->hhc_clk = hhc_clk;
2959 /* FIXME OMAP2 don't release hhc & dc clock */
2960#if 0
2961 clk_disable(hhc_clk);
2962 clk_disable(dc_clk);
2963#endif
2964 }
2842 2965
2843 create_proc_file(); 2966 create_proc_file();
2844 device_add(&udc->gadget.dev); 2967 status = device_add(&udc->gadget.dev);
2845 return 0; 2968 if (!status)
2846 2969 return status;
2970 /* If fail, fall through */
2847#ifdef USE_ISO 2971#ifdef USE_ISO
2848cleanup3: 2972cleanup3:
2849 free_irq(pdev->resource[2].start, udc); 2973 free_irq(pdev->resource[2].start, udc);
@@ -2859,8 +2983,17 @@ cleanup1:
2859cleanup0: 2983cleanup0:
2860 if (xceiv) 2984 if (xceiv)
2861 put_device(xceiv->dev); 2985 put_device(xceiv->dev);
2986
2987 if (cpu_is_omap16xx() || cpu_is_omap24xx()) {
2988 clk_disable(hhc_clk);
2989 clk_disable(dc_clk);
2990 clk_put(hhc_clk);
2991 clk_put(dc_clk);
2992 }
2993
2862 release_mem_region(pdev->resource[0].start, 2994 release_mem_region(pdev->resource[0].start,
2863 pdev->resource[0].end - pdev->resource[0].start + 1); 2995 pdev->resource[0].end - pdev->resource[0].start + 1);
2996
2864 return status; 2997 return status;
2865} 2998}
2866 2999
@@ -2870,6 +3003,8 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
2870 3003
2871 if (!udc) 3004 if (!udc)
2872 return -ENODEV; 3005 return -ENODEV;
3006 if (udc->driver)
3007 return -EBUSY;
2873 3008
2874 udc->done = &done; 3009 udc->done = &done;
2875 3010
@@ -2888,6 +3023,13 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
2888 free_irq(pdev->resource[2].start, udc); 3023 free_irq(pdev->resource[2].start, udc);
2889 free_irq(pdev->resource[1].start, udc); 3024 free_irq(pdev->resource[1].start, udc);
2890 3025
3026 if (udc->dc_clk) {
3027 if (udc->clk_requested)
3028 omap_udc_enable_clock(0);
3029 clk_put(udc->hhc_clk);
3030 clk_put(udc->dc_clk);
3031 }
3032
2891 release_mem_region(pdev->resource[0].start, 3033 release_mem_region(pdev->resource[0].start,
2892 pdev->resource[0].end - pdev->resource[0].start + 1); 3034 pdev->resource[0].end - pdev->resource[0].start + 1);
2893 3035
diff --git a/drivers/usb/gadget/omap_udc.h b/drivers/usb/gadget/omap_udc.h
index 652ee46273..1dc398bb9a 100644
--- a/drivers/usb/gadget/omap_udc.h
+++ b/drivers/usb/gadget/omap_udc.h
@@ -175,6 +175,9 @@ struct omap_udc {
175 unsigned ep0_reset_config:1; 175 unsigned ep0_reset_config:1;
176 unsigned ep0_setup:1; 176 unsigned ep0_setup:1;
177 struct completion *done; 177 struct completion *done;
178 struct clk *dc_clk;
179 struct clk *hhc_clk;
180 unsigned clk_requested:1;
178}; 181};
179 182
180/*-------------------------------------------------------------------------*/ 183/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 1ed506e959..b78de96946 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -1623,7 +1623,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1623 if (!driver 1623 if (!driver
1624 || driver->speed < USB_SPEED_FULL 1624 || driver->speed < USB_SPEED_FULL
1625 || !driver->bind 1625 || !driver->bind
1626 || !driver->unbind
1627 || !driver->disconnect 1626 || !driver->disconnect
1628 || !driver->setup) 1627 || !driver->setup)
1629 return -EINVAL; 1628 return -EINVAL;
@@ -1694,7 +1693,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1694 1693
1695 if (!dev) 1694 if (!dev)
1696 return -ENODEV; 1695 return -ENODEV;
1697 if (!driver || driver != dev->driver) 1696 if (!driver || driver != dev->driver || !driver->unbind)
1698 return -EINVAL; 1697 return -EINVAL;
1699 1698
1700 local_irq_disable(); 1699 local_irq_disable();
@@ -2638,9 +2637,11 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
2638{ 2637{
2639 struct pxa2xx_udc *dev = platform_get_drvdata(pdev); 2638 struct pxa2xx_udc *dev = platform_get_drvdata(pdev);
2640 2639
2640 if (dev->driver)
2641 return -EBUSY;
2642
2641 udc_disable(dev); 2643 udc_disable(dev);
2642 remove_proc_files(); 2644 remove_proc_files();
2643 usb_gadget_unregister_driver(dev->driver);
2644 2645
2645 if (dev->got_irq) { 2646 if (dev->got_irq) {
2646 free_irq(IRQ_USB, dev); 2647 free_irq(IRQ_USB, dev);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 2d12bf9f19..f8a3ec6463 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -296,7 +296,7 @@ static struct usb_gadget_driver gs_gadget_driver = {
296#endif /* CONFIG_USB_GADGET_DUALSPEED */ 296#endif /* CONFIG_USB_GADGET_DUALSPEED */
297 .function = GS_LONG_NAME, 297 .function = GS_LONG_NAME,
298 .bind = gs_bind, 298 .bind = gs_bind,
299 .unbind = __exit_p(gs_unbind), 299 .unbind = gs_unbind,
300 .setup = gs_setup, 300 .setup = gs_setup,
301 .disconnect = gs_disconnect, 301 .disconnect = gs_disconnect,
302 .driver = { 302 .driver = {
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index b466581beb..cc405512fa 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -187,7 +187,6 @@ ohci_at91_start (struct usb_hcd *hcd)
187{ 187{
188 struct at91_usbh_data *board = hcd->self.controller->platform_data; 188 struct at91_usbh_data *board = hcd->self.controller->platform_data;
189 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 189 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
190 struct usb_device *root = hcd->self.root_hub;
191 int ret; 190 int ret;
192 191
193 if ((ret = ohci_init(ohci)) < 0) 192 if ((ret = ohci_init(ohci)) < 0)
@@ -221,7 +220,7 @@ static const struct hc_driver ohci_at91_hc_driver = {
221 */ 220 */
222 .start = ohci_at91_start, 221 .start = ohci_at91_start,
223 .stop = ohci_stop, 222 .stop = ohci_stop,
224 .shutdown = ohci_shutdown, 223 .shutdown = ohci_shutdown,
225 224
226 /* 225 /*
227 * managing i/o requests and associated device resources 226 * managing i/o requests and associated device resources
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 24e23c5783..e70b2430e2 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -269,7 +269,7 @@ static const struct hc_driver ohci_au1xxx_hc_driver = {
269 */ 269 */
270 .start = ohci_au1xxx_start, 270 .start = ohci_au1xxx_start,
271 .stop = ohci_stop, 271 .stop = ohci_stop,
272 .shutdown = ohci_shutdown, 272 .shutdown = ohci_shutdown,
273 273
274 /* 274 /*
275 * managing i/o requests and associated device resources 275 * managing i/o requests and associated device resources
@@ -336,7 +336,7 @@ static int ohci_hcd_au1xxx_drv_resume(struct platform_device *dev)
336static struct platform_driver ohci_hcd_au1xxx_driver = { 336static struct platform_driver ohci_hcd_au1xxx_driver = {
337 .probe = ohci_hcd_au1xxx_drv_probe, 337 .probe = ohci_hcd_au1xxx_drv_probe,
338 .remove = ohci_hcd_au1xxx_drv_remove, 338 .remove = ohci_hcd_au1xxx_drv_remove,
339 .shutdown = usb_hcd_platform_shutdown, 339 .shutdown = usb_hcd_platform_shutdown,
340 /*.suspend = ohci_hcd_au1xxx_drv_suspend, */ 340 /*.suspend = ohci_hcd_au1xxx_drv_suspend, */
341 /*.resume = ohci_hcd_au1xxx_drv_resume, */ 341 /*.resume = ohci_hcd_au1xxx_drv_resume, */
342 .driver = { 342 .driver = {
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 0f47a57dac..273d5ddb72 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -16,7 +16,7 @@
16 case PIPE_CONTROL: temp = "ctrl"; break; \ 16 case PIPE_CONTROL: temp = "ctrl"; break; \
17 case PIPE_BULK: temp = "bulk"; break; \ 17 case PIPE_BULK: temp = "bulk"; break; \
18 case PIPE_INTERRUPT: temp = "intr"; break; \ 18 case PIPE_INTERRUPT: temp = "intr"; break; \
19 default: temp = "isoc"; break; \ 19 default: temp = "isoc"; break; \
20 }; temp;}) 20 }; temp;})
21#define pipestring(pipe) edstring(usb_pipetype(pipe)) 21#define pipestring(pipe) edstring(usb_pipetype(pipe))
22 22
@@ -205,13 +205,13 @@ ohci_dump_status (struct ohci_hcd *controller, char **next, unsigned *size)
205 (temp & RH_PS_PSSC) ? " PSSC" : "", \ 205 (temp & RH_PS_PSSC) ? " PSSC" : "", \
206 (temp & RH_PS_PESC) ? " PESC" : "", \ 206 (temp & RH_PS_PESC) ? " PESC" : "", \
207 (temp & RH_PS_CSC) ? " CSC" : "", \ 207 (temp & RH_PS_CSC) ? " CSC" : "", \
208 \ 208 \
209 (temp & RH_PS_LSDA) ? " LSDA" : "", \ 209 (temp & RH_PS_LSDA) ? " LSDA" : "", \
210 (temp & RH_PS_PPS) ? " PPS" : "", \ 210 (temp & RH_PS_PPS) ? " PPS" : "", \
211 (temp & RH_PS_PRS) ? " PRS" : "", \ 211 (temp & RH_PS_PRS) ? " PRS" : "", \
212 (temp & RH_PS_POCI) ? " POCI" : "", \ 212 (temp & RH_PS_POCI) ? " POCI" : "", \
213 (temp & RH_PS_PSS) ? " PSS" : "", \ 213 (temp & RH_PS_PSS) ? " PSS" : "", \
214 \ 214 \
215 (temp & RH_PS_PES) ? " PES" : "", \ 215 (temp & RH_PS_PES) ? " PES" : "", \
216 (temp & RH_PS_CCS) ? " CCS" : "" \ 216 (temp & RH_PS_CCS) ? " CCS" : "" \
217 ); 217 );
@@ -563,7 +563,7 @@ show_periodic (struct class_device *class_dev, char *buf)
563 (info & ED_SKIP) ? " K" : "", 563 (info & ED_SKIP) ? " K" : "",
564 (ed->hwHeadP & 564 (ed->hwHeadP &
565 cpu_to_hc32(ohci, ED_H)) ? 565 cpu_to_hc32(ohci, ED_H)) ?
566 " H" : ""); 566 " H" : "");
567 size -= temp; 567 size -= temp;
568 next += temp; 568 next += temp;
569 569
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
index 1bf5e7a4e7..3348b07f0f 100644
--- a/drivers/usb/host/ohci-ep93xx.c
+++ b/drivers/usb/host/ohci-ep93xx.c
@@ -169,7 +169,7 @@ static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
169static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state) 169static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
170{ 170{
171 struct usb_hcd *hcd = platform_get_drvdata(pdev); 171 struct usb_hcd *hcd = platform_get_drvdata(pdev);
172 struct ochi_hcd *ohci = hcd_to_ohci(hcd); 172 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
173 173
174 if (time_before(jiffies, ohci->next_statechange)) 174 if (time_before(jiffies, ohci->next_statechange))
175 msleep(5); 175 msleep(5);
@@ -204,7 +204,7 @@ static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
204static struct platform_driver ohci_hcd_ep93xx_driver = { 204static struct platform_driver ohci_hcd_ep93xx_driver = {
205 .probe = ohci_hcd_ep93xx_drv_probe, 205 .probe = ohci_hcd_ep93xx_drv_probe,
206 .remove = ohci_hcd_ep93xx_drv_remove, 206 .remove = ohci_hcd_ep93xx_drv_remove,
207 .shutdown = usb_hcd_platform_shutdown, 207 .shutdown = usb_hcd_platform_shutdown,
208#ifdef CONFIG_PM 208#ifdef CONFIG_PM
209 .suspend = ohci_hcd_ep93xx_drv_suspend, 209 .suspend = ohci_hcd_ep93xx_drv_suspend,
210 .resume = ohci_hcd_ep93xx_drv_resume, 210 .resume = ohci_hcd_ep93xx_drv_resume,
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index b28a9b6020..c1c1d871ab 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -3,77 +3,21 @@
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * [ Initialisation is based on Linus' ] 7 * [ Initialisation is based on Linus' ]
8 * [ uhci code and gregs ohci fragments ] 8 * [ uhci code and gregs ohci fragments ]
9 * [ (C) Copyright 1999 Linus Torvalds ] 9 * [ (C) Copyright 1999 Linus Torvalds ]
10 * [ (C) Copyright 1999 Gregory P. Smith] 10 * [ (C) Copyright 1999 Gregory P. Smith]
11 * 11 *
12 * 12 *
13 * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller 13 * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
14 * interfaces (though some non-x86 Intel chips use it). It supports 14 * interfaces (though some non-x86 Intel chips use it). It supports
15 * smarter hardware than UHCI. A download link for the spec available 15 * smarter hardware than UHCI. A download link for the spec available
16 * through the http://www.usb.org website. 16 * through the http://www.usb.org website.
17 * 17 *
18 * History:
19 *
20 * 2004/03/24 LH7A404 support (Durgesh Pattamatta & Marc Singer)
21 * 2004/02/04 use generic dma_* functions instead of pci_* (dsaxena@plexity.net)
22 * 2003/02/24 show registers in sysfs (Kevin Brosius)
23 *
24 * 2002/09/03 get rid of ed hashtables, rework periodic scheduling and
25 * bandwidth accounting; if debugging, show schedules in driverfs
26 * 2002/07/19 fixes to management of ED and schedule state.
27 * 2002/06/09 SA-1111 support (Christopher Hoover)
28 * 2002/06/01 remember frame when HC won't see EDs any more; use that info
29 * to fix urb unlink races caused by interrupt latency assumptions;
30 * minor ED field and function naming updates
31 * 2002/01/18 package as a patch for 2.5.3; this should match the
32 * 2.4.17 kernel modulo some bugs being fixed.
33 *
34 * 2001/10/18 merge pmac cleanup (Benjamin Herrenschmidt) and bugfixes
35 * from post-2.4.5 patches.
36 * 2001/09/20 URB_ZERO_PACKET support; hcca_dma portability, OPTi warning
37 * 2001/09/07 match PCI PM changes, errnos from Linus' tree
38 * 2001/05/05 fork 2.4.5 version into "hcd" framework, cleanup, simplify;
39 * pbook pci quirks gone (please fix pbook pci sw!) (db)
40 *
41 * 2001/04/08 Identify version on module load (gb)
42 * 2001/03/24 td/ed hashing to remove bus_to_virt (Steve Longerbeam);
43 pci_map_single (db)
44 * 2001/03/21 td and dev/ed allocation uses new pci_pool API (db)
45 * 2001/03/07 hcca allocation uses pci_alloc_consistent (Steve Longerbeam)
46 *
47 * 2000/09/26 fixed races in removing the private portion of the urb
48 * 2000/09/07 disable bulk and control lists when unlinking the last
49 * endpoint descriptor in order to avoid unrecoverable errors on
50 * the Lucent chips. (rwc@sgi)
51 * 2000/08/29 use bandwidth claiming hooks (thanks Randy!), fix some
52 * urb unlink probs, indentation fixes
53 * 2000/08/11 various oops fixes mostly affecting iso and cleanup from
54 * device unplugs.
55 * 2000/06/28 use PCI hotplug framework, for better power management
56 * and for Cardbus support (David Brownell)
57 * 2000/earlier: fixes for NEC/Lucent chips; suspend/resume handling
58 * when the controller loses power; handle UE; cleanup; ...
59 *
60 * v5.2 1999/12/07 URB 3rd preview,
61 * v5.1 1999/11/30 URB 2nd preview, cpia, (usb-scsi)
62 * v5.0 1999/11/22 URB Technical preview, Paul Mackerras powerbook susp/resume
63 * i386: HUB, Keyboard, Mouse, Printer
64 *
65 * v4.3 1999/10/27 multiple HCs, bulk_request
66 * v4.2 1999/09/05 ISO API alpha, new dev alloc, neg Error-codes
67 * v4.1 1999/08/27 Randy Dunlap's - ISO API first impl.
68 * v4.0 1999/08/18
69 * v3.0 1999/06/25
70 * v2.1 1999/05/09 code clean up
71 * v2.0 1999/05/04
72 * v1.0 1999/04/27 initial release
73 *
74 * This file is licenced under the GPL. 18 * This file is licenced under the GPL.
75 */ 19 */
76 20
77#include <linux/module.h> 21#include <linux/module.h>
78#include <linux/moduleparam.h> 22#include <linux/moduleparam.h>
79#include <linux/pci.h> 23#include <linux/pci.h>
@@ -89,7 +33,7 @@
89#include <linux/list.h> 33#include <linux/list.h>
90#include <linux/usb.h> 34#include <linux/usb.h>
91#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
92#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
93#include <linux/dmapool.h> 37#include <linux/dmapool.h>
94#include <linux/reboot.h> 38#include <linux/reboot.h>
95 39
@@ -183,11 +127,11 @@ static int ohci_urb_enqueue (
183 int i, size = 0; 127 int i, size = 0;
184 unsigned long flags; 128 unsigned long flags;
185 int retval = 0; 129 int retval = 0;
186 130
187#ifdef OHCI_VERBOSE_DEBUG 131#ifdef OHCI_VERBOSE_DEBUG
188 urb_print (urb, "SUB", usb_pipein (pipe)); 132 urb_print (urb, "SUB", usb_pipein (pipe));
189#endif 133#endif
190 134
191 /* every endpoint has a ed, locate and maybe (re)initialize it */ 135 /* every endpoint has a ed, locate and maybe (re)initialize it */
192 if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval))) 136 if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval)))
193 return -ENOMEM; 137 return -ENOMEM;
@@ -232,7 +176,7 @@ static int ohci_urb_enqueue (
232 memset (urb_priv, 0, sizeof (urb_priv_t) + size * sizeof (struct td *)); 176 memset (urb_priv, 0, sizeof (urb_priv_t) + size * sizeof (struct td *));
233 INIT_LIST_HEAD (&urb_priv->pending); 177 INIT_LIST_HEAD (&urb_priv->pending);
234 urb_priv->length = size; 178 urb_priv->length = size;
235 urb_priv->ed = ed; 179 urb_priv->ed = ed;
236 180
237 /* allocate the TDs (deferring hash chain updates) */ 181 /* allocate the TDs (deferring hash chain updates) */
238 for (i = 0; i < size; i++) { 182 for (i = 0; i < size; i++) {
@@ -242,7 +186,7 @@ static int ohci_urb_enqueue (
242 urb_free_priv (ohci, urb_priv); 186 urb_free_priv (ohci, urb_priv);
243 return -ENOMEM; 187 return -ENOMEM;
244 } 188 }
245 } 189 }
246 190
247 spin_lock_irqsave (&ohci->lock, flags); 191 spin_lock_irqsave (&ohci->lock, flags);
248 192
@@ -313,13 +257,13 @@ static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
313{ 257{
314 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 258 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
315 unsigned long flags; 259 unsigned long flags;
316 260
317#ifdef OHCI_VERBOSE_DEBUG 261#ifdef OHCI_VERBOSE_DEBUG
318 urb_print (urb, "UNLINK", 1); 262 urb_print (urb, "UNLINK", 1);
319#endif 263#endif
320 264
321 spin_lock_irqsave (&ohci->lock, flags); 265 spin_lock_irqsave (&ohci->lock, flags);
322 if (HC_IS_RUNNING(hcd->state)) { 266 if (HC_IS_RUNNING(hcd->state)) {
323 urb_priv_t *urb_priv; 267 urb_priv_t *urb_priv;
324 268
325 /* Unless an IRQ completed the unlink while it was being 269 /* Unless an IRQ completed the unlink while it was being
@@ -512,11 +456,11 @@ static int ohci_init (struct ohci_hcd *ohci)
512 456
513/* Start an OHCI controller, set the BUS operational 457/* Start an OHCI controller, set the BUS operational
514 * resets USB and controller 458 * resets USB and controller
515 * enable interrupts 459 * enable interrupts
516 */ 460 */
517static int ohci_run (struct ohci_hcd *ohci) 461static int ohci_run (struct ohci_hcd *ohci)
518{ 462{
519 u32 mask, temp; 463 u32 mask, temp;
520 int first = ohci->fminterval == 0; 464 int first = ohci->fminterval == 0;
521 struct usb_hcd *hcd = ohci_to_hcd(ohci); 465 struct usb_hcd *hcd = ohci_to_hcd(ohci);
522 466
@@ -534,7 +478,7 @@ static int ohci_run (struct ohci_hcd *ohci)
534 /* also: power/overcurrent flags in roothub.a */ 478 /* also: power/overcurrent flags in roothub.a */
535 } 479 }
536 480
537 /* Reset USB nearly "by the book". RemoteWakeupConnected was 481 /* Reset USB nearly "by the book". RemoteWakeupConnected was
538 * saved if boot firmware (BIOS/SMM/...) told us it's connected, 482 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
539 * or if bus glue did the same (e.g. for PCI add-in cards with 483 * or if bus glue did the same (e.g. for PCI add-in cards with
540 * PCI PM support). 484 * PCI PM support).
@@ -765,9 +709,9 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
765 dl_done_list (ohci); 709 dl_done_list (ohci);
766 spin_unlock (&ohci->lock); 710 spin_unlock (&ohci->lock);
767 if (HC_IS_RUNNING(hcd->state)) 711 if (HC_IS_RUNNING(hcd->state))
768 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable); 712 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable);
769 } 713 }
770 714
771 /* could track INTR_SO to reduce available PCI/... bandwidth */ 715 /* could track INTR_SO to reduce available PCI/... bandwidth */
772 716
773 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled 717 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
@@ -778,12 +722,12 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
778 finish_unlinks (ohci, ohci_frame_no(ohci)); 722 finish_unlinks (ohci, ohci_frame_no(ohci));
779 if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list 723 if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
780 && HC_IS_RUNNING(hcd->state)) 724 && HC_IS_RUNNING(hcd->state))
781 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable); 725 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
782 spin_unlock (&ohci->lock); 726 spin_unlock (&ohci->lock);
783 727
784 if (HC_IS_RUNNING(hcd->state)) { 728 if (HC_IS_RUNNING(hcd->state)) {
785 ohci_writel (ohci, ints, &regs->intrstatus); 729 ohci_writel (ohci, ints, &regs->intrstatus);
786 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable); 730 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
787 // flush those writes 731 // flush those writes
788 (void) ohci_readl (ohci, &ohci->regs->control); 732 (void) ohci_readl (ohci, &ohci->regs->control);
789 } 733 }
@@ -794,7 +738,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
794/*-------------------------------------------------------------------------*/ 738/*-------------------------------------------------------------------------*/
795 739
796static void ohci_stop (struct usb_hcd *hcd) 740static void ohci_stop (struct usb_hcd *hcd)
797{ 741{
798 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 742 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
799 743
800 ohci_dbg (ohci, "stop %s controller (state 0x%02x)\n", 744 ohci_dbg (ohci, "stop %s controller (state 0x%02x)\n",
@@ -812,8 +756,8 @@ static void ohci_stop (struct usb_hcd *hcd)
812 remove_debug_files (ohci); 756 remove_debug_files (ohci);
813 ohci_mem_cleanup (ohci); 757 ohci_mem_cleanup (ohci);
814 if (ohci->hcca) { 758 if (ohci->hcca) {
815 dma_free_coherent (hcd->self.controller, 759 dma_free_coherent (hcd->self.controller,
816 sizeof *ohci->hcca, 760 sizeof *ohci->hcca,
817 ohci->hcca, ohci->hcca_dma); 761 ohci->hcca, ohci->hcca_dma);
818 ohci->hcca = NULL; 762 ohci->hcca = NULL;
819 ohci->hcca_dma = 0; 763 ohci->hcca_dma = 0;
@@ -836,7 +780,7 @@ static int ohci_restart (struct ohci_hcd *ohci)
836 * recycle any "live" eds/tds (and urbs) right away. 780 * recycle any "live" eds/tds (and urbs) right away.
837 * later, khubd disconnect processing will recycle the other state, 781 * later, khubd disconnect processing will recycle the other state,
838 * (either as disconnect/reconnect, or maybe someday as a reset). 782 * (either as disconnect/reconnect, or maybe someday as a reset).
839 */ 783 */
840 spin_lock_irq(&ohci->lock); 784 spin_lock_irq(&ohci->lock);
841 disable (ohci); 785 disable (ohci);
842 usb_root_hub_lost_power(ohci_to_hcd(ohci)->self.root_hub); 786 usb_root_hub_lost_power(ohci_to_hcd(ohci)->self.root_hub);
@@ -875,11 +819,11 @@ static int ohci_restart (struct ohci_hcd *ohci)
875 /* empty the interrupt branches */ 819 /* empty the interrupt branches */
876 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0; 820 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
877 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0; 821 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
878 822
879 /* no EDs to remove */ 823 /* no EDs to remove */
880 ohci->ed_rm_list = NULL; 824 ohci->ed_rm_list = NULL;
881 825
882 /* empty control and bulk lists */ 826 /* empty control and bulk lists */
883 ohci->ed_controltail = NULL; 827 ohci->ed_controltail = NULL;
884 ohci->ed_bulktail = NULL; 828 ohci->ed_bulktail = NULL;
885 829
@@ -941,6 +885,10 @@ MODULE_LICENSE ("GPL");
941#include "ohci-au1xxx.c" 885#include "ohci-au1xxx.c"
942#endif 886#endif
943 887
888#ifdef CONFIG_PNX8550
889#include "ohci-pnx8550.c"
890#endif
891
944#ifdef CONFIG_USB_OHCI_HCD_PPC_SOC 892#ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
945#include "ohci-ppc-soc.c" 893#include "ohci-ppc-soc.c"
946#endif 894#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 2441642cb7..216c9c9d4d 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * OHCI HCD (Host Controller Driver) for USB. 2 * OHCI HCD (Host Controller Driver) for USB.
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * This file is licenced under GPL 7 * This file is licenced under GPL
8 */ 8 */
9 9
@@ -23,13 +23,13 @@
23 (temp & RH_PS_PSSC) ? " PSSC" : "", \ 23 (temp & RH_PS_PSSC) ? " PSSC" : "", \
24 (temp & RH_PS_PESC) ? " PESC" : "", \ 24 (temp & RH_PS_PESC) ? " PESC" : "", \
25 (temp & RH_PS_CSC) ? " CSC" : "", \ 25 (temp & RH_PS_CSC) ? " CSC" : "", \
26 \ 26 \
27 (temp & RH_PS_LSDA) ? " LSDA" : "", \ 27 (temp & RH_PS_LSDA) ? " LSDA" : "", \
28 (temp & RH_PS_PPS) ? " PPS" : "", \ 28 (temp & RH_PS_PPS) ? " PPS" : "", \
29 (temp & RH_PS_PRS) ? " PRS" : "", \ 29 (temp & RH_PS_PRS) ? " PRS" : "", \
30 (temp & RH_PS_POCI) ? " POCI" : "", \ 30 (temp & RH_PS_POCI) ? " POCI" : "", \
31 (temp & RH_PS_PSS) ? " PSS" : "", \ 31 (temp & RH_PS_PSS) ? " PSS" : "", \
32 \ 32 \
33 (temp & RH_PS_PES) ? " PES" : "", \ 33 (temp & RH_PS_PES) ? " PES" : "", \
34 (temp & RH_PS_CCS) ? " CCS" : "" \ 34 (temp & RH_PS_CCS) ? " CCS" : "" \
35 ); 35 );
@@ -484,7 +484,7 @@ ohci_hub_descriptor (
484 temp = 0; 484 temp = 0;
485 if (rh & RH_A_NPS) /* no power switching? */ 485 if (rh & RH_A_NPS) /* no power switching? */
486 temp |= 0x0002; 486 temp |= 0x0002;
487 if (rh & RH_A_PSM) /* per-port power switching? */ 487 if (rh & RH_A_PSM) /* per-port power switching? */
488 temp |= 0x0001; 488 temp |= 0x0001;
489 if (rh & RH_A_NOCP) /* no overcurrent reporting? */ 489 if (rh & RH_A_NOCP) /* no overcurrent reporting? */
490 temp |= 0x0010; 490 temp |= 0x0010;
@@ -555,7 +555,7 @@ static void start_hnp(struct ohci_hcd *ohci);
555#define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) 555#define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
556 556
557/* called from some task, normally khubd */ 557/* called from some task, normally khubd */
558static inline void root_port_reset (struct ohci_hcd *ohci, unsigned port) 558static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
559{ 559{
560 __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; 560 __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port];
561 u32 temp; 561 u32 temp;
@@ -570,10 +570,13 @@ static inline void root_port_reset (struct ohci_hcd *ohci, unsigned port)
570 /* spin until any current reset finishes */ 570 /* spin until any current reset finishes */
571 for (;;) { 571 for (;;) {
572 temp = ohci_readl (ohci, portstat); 572 temp = ohci_readl (ohci, portstat);
573 /* handle e.g. CardBus eject */
574 if (temp == ~(u32)0)
575 return -ESHUTDOWN;
573 if (!(temp & RH_PS_PRS)) 576 if (!(temp & RH_PS_PRS))
574 break; 577 break;
575 udelay (500); 578 udelay (500);
576 } 579 }
577 580
578 if (!(temp & RH_PS_CCS)) 581 if (!(temp & RH_PS_CCS))
579 break; 582 break;
@@ -586,6 +589,8 @@ static inline void root_port_reset (struct ohci_hcd *ohci, unsigned port)
586 now = ohci_readl(ohci, &ohci->regs->fmnumber); 589 now = ohci_readl(ohci, &ohci->regs->fmnumber);
587 } while (tick_before(now, reset_done)); 590 } while (tick_before(now, reset_done));
588 /* caller synchronizes using PRSC */ 591 /* caller synchronizes using PRSC */
592
593 return 0;
589} 594}
590 595
591static int ohci_hub_control ( 596static int ohci_hub_control (
@@ -702,7 +707,7 @@ static int ohci_hub_control (
702 &ohci->regs->roothub.portstatus [wIndex]); 707 &ohci->regs->roothub.portstatus [wIndex]);
703 break; 708 break;
704 case USB_PORT_FEAT_RESET: 709 case USB_PORT_FEAT_RESET:
705 root_port_reset (ohci, wIndex); 710 retval = root_port_reset (ohci, wIndex);
706 break; 711 break;
707 default: 712 default:
708 goto error; 713 goto error;
diff --git a/drivers/usb/host/ohci-lh7a404.c b/drivers/usb/host/ohci-lh7a404.c
index e121d97ed9..e9807cf73a 100644
--- a/drivers/usb/host/ohci-lh7a404.c
+++ b/drivers/usb/host/ohci-lh7a404.c
@@ -38,7 +38,7 @@ static void lh7a404_start_hc(struct platform_device *dev)
38 CSC_PWRCNT |= CSC_PWRCNT_USBH_EN; /* Enable clock */ 38 CSC_PWRCNT |= CSC_PWRCNT_USBH_EN; /* Enable clock */
39 udelay(1000); 39 udelay(1000);
40 USBH_CMDSTATUS = OHCI_HCR; 40 USBH_CMDSTATUS = OHCI_HCR;
41 41
42 printk(KERN_DEBUG __FILE__ 42 printk(KERN_DEBUG __FILE__
43 ": Clock to USB host has been enabled \n"); 43 ": Clock to USB host has been enabled \n");
44} 44}
@@ -89,7 +89,7 @@ int usb_hcd_lh7a404_probe (const struct hc_driver *driver,
89 retval = -EBUSY; 89 retval = -EBUSY;
90 goto err1; 90 goto err1;
91 } 91 }
92 92
93 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 93 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
94 if (!hcd->regs) { 94 if (!hcd->regs) {
95 pr_debug("ioremap failed"); 95 pr_debug("ioremap failed");
@@ -174,7 +174,7 @@ static const struct hc_driver ohci_lh7a404_hc_driver = {
174 */ 174 */
175 .start = ohci_lh7a404_start, 175 .start = ohci_lh7a404_start,
176 .stop = ohci_stop, 176 .stop = ohci_stop,
177 .shutdown = ohci_shutdown, 177 .shutdown = ohci_shutdown,
178 178
179 /* 179 /*
180 * managing i/o requests and associated device resources 180 * managing i/o requests and associated device resources
@@ -242,7 +242,7 @@ static int ohci_hcd_lh7a404_drv_resume(struct platform_device *dev)
242static struct platform_driver ohci_hcd_lh7a404_driver = { 242static struct platform_driver ohci_hcd_lh7a404_driver = {
243 .probe = ohci_hcd_lh7a404_drv_probe, 243 .probe = ohci_hcd_lh7a404_drv_probe,
244 .remove = ohci_hcd_lh7a404_drv_remove, 244 .remove = ohci_hcd_lh7a404_drv_remove,
245 .shutdown = usb_hcd_platform_shutdown, 245 .shutdown = usb_hcd_platform_shutdown,
246 /*.suspend = ohci_hcd_lh7a404_drv_suspend, */ 246 /*.suspend = ohci_hcd_lh7a404_drv_suspend, */
247 /*.resume = ohci_hcd_lh7a404_drv_resume, */ 247 /*.resume = ohci_hcd_lh7a404_drv_resume, */
248 .driver = { 248 .driver = {
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index d976614eeb..2f20d3dc89 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -1,24 +1,24 @@
1/* 1/*
2 * OHCI HCD (Host Controller Driver) for USB. 2 * OHCI HCD (Host Controller Driver) for USB.
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * This file is licenced under the GPL. 7 * This file is licenced under the GPL.
8 */ 8 */
9 9
10/*-------------------------------------------------------------------------*/ 10/*-------------------------------------------------------------------------*/
11 11
12/* 12/*
13 * There's basically three types of memory: 13 * OHCI deals with three types of memory:
14 * - data used only by the HCD ... kmalloc is fine 14 * - data used only by the HCD ... kmalloc is fine
15 * - async and periodic schedules, shared by HC and HCD ... these 15 * - async and periodic schedules, shared by HC and HCD ... these
16 * need to use dma_pool or dma_alloc_coherent 16 * need to use dma_pool or dma_alloc_coherent
17 * - driver buffers, read/written by HC ... the hcd glue or the 17 * - driver buffers, read/written by HC ... the hcd glue or the
18 * device driver provides us with dma addresses 18 * device driver provides us with dma addresses
19 * 19 *
20 * There's also PCI "register" data, which is memory mapped. 20 * There's also "register" data, which is memory mapped.
21 * No memory seen by this driver is pagable. 21 * No memory seen by this driver (or any HCD) may be paged out.
22 */ 22 */
23 23
24/*-------------------------------------------------------------------------*/ 24/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 9c02177de5..27be1f9368 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -447,7 +447,7 @@ static const struct hc_driver ohci_omap_hc_driver = {
447 .reset = ohci_omap_init, 447 .reset = ohci_omap_init,
448 .start = ohci_omap_start, 448 .start = ohci_omap_start,
449 .stop = ohci_omap_stop, 449 .stop = ohci_omap_stop,
450 .shutdown = ohci_shutdown, 450 .shutdown = ohci_shutdown,
451 451
452 /* 452 /*
453 * managing i/o requests and associated device resources 453 * managing i/o requests and associated device resources
@@ -533,7 +533,7 @@ static int ohci_omap_resume(struct platform_device *dev)
533static struct platform_driver ohci_hcd_omap_driver = { 533static struct platform_driver ohci_hcd_omap_driver = {
534 .probe = ohci_hcd_omap_drv_probe, 534 .probe = ohci_hcd_omap_drv_probe,
535 .remove = ohci_hcd_omap_drv_remove, 535 .remove = ohci_hcd_omap_drv_remove,
536 .shutdown = usb_hcd_platform_shutdown, 536 .shutdown = usb_hcd_platform_shutdown,
537#ifdef CONFIG_PM 537#ifdef CONFIG_PM
538 .suspend = ohci_omap_suspend, 538 .suspend = ohci_omap_suspend,
539 .resume = ohci_omap_resume, 539 .resume = ohci_omap_resume,
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index 8744185527..596e0b41e6 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -3,17 +3,17 @@
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * [ Initialisation is based on Linus' ] 7 * [ Initialisation is based on Linus' ]
8 * [ uhci code and gregs ohci fragments ] 8 * [ uhci code and gregs ohci fragments ]
9 * [ (C) Copyright 1999 Linus Torvalds ] 9 * [ (C) Copyright 1999 Linus Torvalds ]
10 * [ (C) Copyright 1999 Gregory P. Smith] 10 * [ (C) Copyright 1999 Gregory P. Smith]
11 * 11 *
12 * PCI Bus Glue 12 * PCI Bus Glue
13 * 13 *
14 * This file is licenced under the GPL. 14 * This file is licenced under the GPL.
15 */ 15 */
16 16
17#ifndef CONFIG_PCI 17#ifndef CONFIG_PCI
18#error "This file is PCI bus glue. CONFIG_PCI must be defined." 18#error "This file is PCI bus glue. CONFIG_PCI must be defined."
19#endif 19#endif
@@ -83,7 +83,7 @@ ohci_pci_start (struct usb_hcd *hcd)
83 pci_dev_put(b); 83 pci_dev_put(b);
84 } 84 }
85 85
86 /* Check for Compaq's ZFMicro chipset, which needs short 86 /* Check for Compaq's ZFMicro chipset, which needs short
87 * delays before control or bulk queues get re-activated 87 * delays before control or bulk queues get re-activated
88 * in finish_unlinks() 88 * in finish_unlinks()
89 */ 89 */
@@ -238,8 +238,8 @@ static struct pci_driver ohci_pci_driver = {
238 .shutdown = usb_hcd_pci_shutdown, 238 .shutdown = usb_hcd_pci_shutdown,
239}; 239};
240 240
241 241
242static int __init ohci_hcd_pci_init (void) 242static int __init ohci_hcd_pci_init (void)
243{ 243{
244 printk (KERN_DEBUG "%s: " DRIVER_INFO " (PCI)\n", hcd_name); 244 printk (KERN_DEBUG "%s: " DRIVER_INFO " (PCI)\n", hcd_name);
245 if (usb_disabled()) 245 if (usb_disabled())
@@ -253,8 +253,8 @@ module_init (ohci_hcd_pci_init);
253 253
254/*-------------------------------------------------------------------------*/ 254/*-------------------------------------------------------------------------*/
255 255
256static void __exit ohci_hcd_pci_cleanup (void) 256static void __exit ohci_hcd_pci_cleanup (void)
257{ 257{
258 pci_unregister_driver (&ohci_pci_driver); 258 pci_unregister_driver (&ohci_pci_driver);
259} 259}
260module_exit (ohci_hcd_pci_cleanup); 260module_exit (ohci_hcd_pci_cleanup);
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
index 7f26f9bdba..3a8cbfb690 100644
--- a/drivers/usb/host/ohci-pnx4008.c
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -4,7 +4,7 @@
4 * driver for Philips PNX4008 USB Host 4 * driver for Philips PNX4008 USB Host
5 * 5 *
6 * Authors: Dmitry Chigirev <source@mvista.com> 6 * Authors: Dmitry Chigirev <source@mvista.com>
7 * Vitaly Wool <vitalywool@gmail.com> 7 * Vitaly Wool <vitalywool@gmail.com>
8 * 8 *
9 * register initialization is based on code examples provided by Philips 9 * register initialization is based on code examples provided by Philips
10 * Copyright (c) 2005 Koninklijke Philips Electronics N.V. 10 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
@@ -29,7 +29,7 @@
29#include <asm/arch/irqs.h> 29#include <asm/arch/irqs.h>
30#include <asm/arch/gpio.h> 30#include <asm/arch/gpio.h>
31 31
32#define USB_CTRL IO_ADDRESS(PNX4008_PWRMAN_BASE + 0x64) 32#define USB_CTRL IO_ADDRESS(PNX4008_PWRMAN_BASE + 0x64)
33 33
34/* USB_CTRL bit defines */ 34/* USB_CTRL bit defines */
35#define USB_SLAVE_HCLK_EN (1 << 24) 35#define USB_SLAVE_HCLK_EN (1 << 24)
diff --git a/drivers/usb/host/ohci-pnx8550.c b/drivers/usb/host/ohci-pnx8550.c
new file mode 100644
index 0000000000..6922b91b17
--- /dev/null
+++ b/drivers/usb/host/ohci-pnx8550.c
@@ -0,0 +1,258 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
7 * (C) Copyright 2005 Embedded Alley Solutions, Inc.
8 *
9 * Bus Glue for PNX8550
10 *
11 * Written by Christopher Hoover <ch@hpl.hp.com>
12 * Based on fragments of previous driver by Russell King et al.
13 *
14 * Modified for LH7A404 from ohci-sa1111.c
15 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
16 *
17 * Modified for PNX8550 from ohci-sa1111.c and sa-omap.c
18 * by Vitaly Wool <vitalywool@gmail.com>
19 *
20 * This file is licenced under the GPL.
21 */
22
23#include <linux/device.h>
24#include <linux/platform_device.h>
25#include <asm/mach-pnx8550/usb.h>
26#include <asm/mach-pnx8550/int.h>
27#include <asm/mach-pnx8550/pci.h>
28
29#ifndef CONFIG_PNX8550
30#error "This file is PNX8550 bus glue. CONFIG_PNX8550 must be defined."
31#endif
32
33extern int usb_disabled(void);
34
35/*-------------------------------------------------------------------------*/
36
37static void pnx8550_start_hc(struct platform_device *dev)
38{
39 /*
40 * Set register CLK48CTL to enable and 48MHz
41 */
42 outl(0x00000003, PCI_BASE | 0x0004770c);
43
44 /*
45 * Set register CLK12CTL to enable and 48MHz
46 */
47 outl(0x00000003, PCI_BASE | 0x00047710);
48
49 udelay(100);
50}
51
52static void pnx8550_stop_hc(struct platform_device *dev)
53{
54 udelay(10);
55}
56
57
58/*-------------------------------------------------------------------------*/
59
60/* configure so an HC device and id are always provided */
61/* always called with process context; sleeping is OK */
62
63
64/**
65 * usb_hcd_pnx8550_probe - initialize pnx8550-based HCDs
66 * Context: !in_interrupt()
67 *
68 * Allocates basic resources for this USB host controller, and
69 * then invokes the start() method for the HCD associated with it
70 * through the hotplug entry's driver_data.
71 *
72 */
73int usb_hcd_pnx8550_probe (const struct hc_driver *driver,
74 struct platform_device *dev)
75{
76 int retval;
77 struct usb_hcd *hcd;
78
79 if (dev->resource[0].flags != IORESOURCE_MEM ||
80 dev->resource[1].flags != IORESOURCE_IRQ) {
81 dev_err (&dev->dev,"invalid resource type\n");
82 return -ENOMEM;
83 }
84
85 hcd = usb_create_hcd (driver, &dev->dev, "pnx8550");
86 if (!hcd)
87 return -ENOMEM;
88 hcd->rsrc_start = dev->resource[0].start;
89 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
90
91 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
92 dev_err(&dev->dev, "request_mem_region [0x%08llx, 0x%08llx] "
93 "failed\n", hcd->rsrc_start, hcd->rsrc_len);
94 retval = -EBUSY;
95 goto err1;
96 }
97
98 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
99 if (!hcd->regs) {
100 dev_err(&dev->dev, "ioremap [[0x%08llx, 0x%08llx] failed\n",
101 hcd->rsrc_start, hcd->rsrc_len);
102 retval = -ENOMEM;
103 goto err2;
104 }
105
106 pnx8550_start_hc(dev);
107
108 ohci_hcd_init(hcd_to_ohci(hcd));
109
110 retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT);
111 if (retval == 0)
112 return retval;
113
114 pnx8550_stop_hc(dev);
115 iounmap(hcd->regs);
116 err2:
117 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
118 err1:
119 usb_put_hcd(hcd);
120 return retval;
121}
122
123
124/* may be called without controller electrically present */
125/* may be called with controller, bus, and devices active */
126
127/**
128 * usb_hcd_pnx8550_remove - shutdown processing for pnx8550-based HCDs
129 * @dev: USB Host Controller being removed
130 * Context: !in_interrupt()
131 *
132 * Reverses the effect of usb_hcd_pnx8550_probe(), first invoking
133 * the HCD's stop() method. It is always called from a thread
134 * context, normally "rmmod", "apmd", or something similar.
135 *
136 */
137void usb_hcd_pnx8550_remove (struct usb_hcd *hcd, struct platform_device *dev)
138{
139 usb_remove_hcd(hcd);
140 pnx8550_stop_hc(dev);
141 iounmap(hcd->regs);
142 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
143 usb_put_hcd(hcd);
144}
145
146/*-------------------------------------------------------------------------*/
147
148static int __devinit
149ohci_pnx8550_start (struct usb_hcd *hcd)
150{
151 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
152 int ret;
153
154 ohci_dbg (ohci, "ohci_pnx8550_start, ohci:%p", ohci);
155
156 if ((ret = ohci_init(ohci)) < 0)
157 return ret;
158
159 if ((ret = ohci_run (ohci)) < 0) {
160 err ("can't start %s", hcd->self.bus_name);
161 ohci_stop (hcd);
162 return ret;
163 }
164
165 return 0;
166}
167
168/*-------------------------------------------------------------------------*/
169
170static const struct hc_driver ohci_pnx8550_hc_driver = {
171 .description = hcd_name,
172 .product_desc = "PNX8550 OHCI",
173 .hcd_priv_size = sizeof(struct ohci_hcd),
174
175 /*
176 * generic hardware linkage
177 */
178 .irq = ohci_irq,
179 .flags = HCD_USB11 | HCD_MEMORY,
180
181 /*
182 * basic lifecycle operations
183 */
184 .start = ohci_pnx8550_start,
185 .stop = ohci_stop,
186
187 /*
188 * managing i/o requests and associated device resources
189 */
190 .urb_enqueue = ohci_urb_enqueue,
191 .urb_dequeue = ohci_urb_dequeue,
192 .endpoint_disable = ohci_endpoint_disable,
193
194 /*
195 * scheduling support
196 */
197 .get_frame_number = ohci_get_frame,
198
199 /*
200 * root hub support
201 */
202 .hub_status_data = ohci_hub_status_data,
203 .hub_control = ohci_hub_control,
204 .hub_irq_enable = ohci_rhsc_enable,
205#ifdef CONFIG_PM
206 .bus_suspend = ohci_bus_suspend,
207 .bus_resume = ohci_bus_resume,
208#endif
209 .start_port_reset = ohci_start_port_reset,
210};
211
212/*-------------------------------------------------------------------------*/
213
214static int ohci_hcd_pnx8550_drv_probe(struct platform_device *pdev)
215{
216 int ret;
217
218 if (usb_disabled())
219 return -ENODEV;
220
221 ret = usb_hcd_pnx8550_probe(&ohci_pnx8550_hc_driver, pdev);
222 return ret;
223}
224
225static int ohci_hcd_pnx8550_drv_remove(struct platform_device *pdev)
226{
227 struct usb_hcd *hcd = platform_get_drvdata(pdev);
228
229 usb_hcd_pnx8550_remove(hcd, pdev);
230 return 0;
231}
232
233MODULE_ALIAS("pnx8550-ohci");
234
235static struct platform_driver ohci_hcd_pnx8550_driver = {
236 .driver = {
237 .name = "pnx8550-ohci",
238 },
239 .probe = ohci_hcd_pnx8550_drv_probe,
240 .remove = ohci_hcd_pnx8550_drv_remove,
241};
242
243static int __init ohci_hcd_pnx8550_init (void)
244{
245 pr_debug (DRIVER_INFO " (pnx8550)");
246 pr_debug ("block sizes: ed %d td %d\n",
247 sizeof (struct ed), sizeof (struct td));
248
249 return platform_driver_register(&ohci_hcd_pnx8550_driver);
250}
251
252static void __exit ohci_hcd_pnx8550_cleanup (void)
253{
254 platform_driver_unregister(&ohci_hcd_pnx8550_driver);
255}
256
257module_init (ohci_hcd_pnx8550_init);
258module_exit (ohci_hcd_pnx8550_cleanup);
diff --git a/drivers/usb/host/ohci-ppc-soc.c b/drivers/usb/host/ohci-ppc-soc.c
index d9d1ae236b..e1a7eb8173 100644
--- a/drivers/usb/host/ohci-ppc-soc.c
+++ b/drivers/usb/host/ohci-ppc-soc.c
@@ -5,7 +5,7 @@
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company 6 * (C) Copyright 2002 Hewlett-Packard Company
7 * (C) Copyright 2003-2005 MontaVista Software Inc. 7 * (C) Copyright 2003-2005 MontaVista Software Inc.
8 * 8 *
9 * Bus Glue for PPC On-Chip OHCI driver 9 * Bus Glue for PPC On-Chip OHCI driver
10 * Tested on Freescale MPC5200 and IBM STB04xxx 10 * Tested on Freescale MPC5200 and IBM STB04xxx
11 * 11 *
@@ -85,7 +85,7 @@ static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
85 err2: 85 err2:
86 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 86 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
87 err1: 87 err1:
88 usb_put_hcd(hcd); 88 usb_put_hcd(hcd);
89 return retval; 89 return retval;
90} 90}
91 91
@@ -148,7 +148,7 @@ static const struct hc_driver ohci_ppc_soc_hc_driver = {
148 */ 148 */
149 .start = ohci_ppc_soc_start, 149 .start = ohci_ppc_soc_start,
150 .stop = ohci_stop, 150 .stop = ohci_stop,
151 .shutdown = ohci_shutdown, 151 .shutdown = ohci_shutdown,
152 152
153 /* 153 /*
154 * managing i/o requests and associated device resources 154 * managing i/o requests and associated device resources
@@ -197,7 +197,7 @@ static int ohci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
197static struct platform_driver ohci_hcd_ppc_soc_driver = { 197static struct platform_driver ohci_hcd_ppc_soc_driver = {
198 .probe = ohci_hcd_ppc_soc_drv_probe, 198 .probe = ohci_hcd_ppc_soc_drv_probe,
199 .remove = ohci_hcd_ppc_soc_drv_remove, 199 .remove = ohci_hcd_ppc_soc_drv_remove,
200 .shutdown = usb_hcd_platform_shutdown, 200 .shutdown = usb_hcd_platform_shutdown,
201#ifdef CONFIG_PM 201#ifdef CONFIG_PM
202 /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/ 202 /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
203 /*.resume = ohci_hcd_ppc_soc_drv_resume,*/ 203 /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index e176b04d7a..3bbea844a9 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -47,7 +47,7 @@ static int pxa27x_ohci_select_pmm( int mode )
47 switch ( mode ) { 47 switch ( mode ) {
48 case PMM_NPS_MODE: 48 case PMM_NPS_MODE:
49 UHCRHDA |= RH_A_NPS; 49 UHCRHDA |= RH_A_NPS;
50 break; 50 break;
51 case PMM_GLOBAL_MODE: 51 case PMM_GLOBAL_MODE:
52 UHCRHDA &= ~(RH_A_NPS & RH_A_PSM); 52 UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
53 break; 53 break;
@@ -60,7 +60,7 @@ static int pxa27x_ohci_select_pmm( int mode )
60 break; 60 break;
61 default: 61 default:
62 printk( KERN_ERR 62 printk( KERN_ERR
63 "Invalid mode %d, set to non-power switch mode.\n", 63 "Invalid mode %d, set to non-power switch mode.\n",
64 mode ); 64 mode );
65 65
66 UHCRHDA |= RH_A_NPS; 66 UHCRHDA |= RH_A_NPS;
@@ -270,7 +270,7 @@ static const struct hc_driver ohci_pxa27x_hc_driver = {
270 */ 270 */
271 .start = ohci_pxa27x_start, 271 .start = ohci_pxa27x_start,
272 .stop = ohci_stop, 272 .stop = ohci_stop,
273 .shutdown = ohci_shutdown, 273 .shutdown = ohci_shutdown,
274 274
275 /* 275 /*
276 * managing i/o requests and associated device resources 276 * managing i/o requests and associated device resources
@@ -359,9 +359,9 @@ static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
359static struct platform_driver ohci_hcd_pxa27x_driver = { 359static struct platform_driver ohci_hcd_pxa27x_driver = {
360 .probe = ohci_hcd_pxa27x_drv_probe, 360 .probe = ohci_hcd_pxa27x_drv_probe,
361 .remove = ohci_hcd_pxa27x_drv_remove, 361 .remove = ohci_hcd_pxa27x_drv_remove,
362 .shutdown = usb_hcd_platform_shutdown, 362 .shutdown = usb_hcd_platform_shutdown,
363#ifdef CONFIG_PM 363#ifdef CONFIG_PM
364 .suspend = ohci_hcd_pxa27x_drv_suspend, 364 .suspend = ohci_hcd_pxa27x_drv_suspend,
365 .resume = ohci_hcd_pxa27x_drv_resume, 365 .resume = ohci_hcd_pxa27x_drv_resume,
366#endif 366#endif
367 .driver = { 367 .driver = {
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index fe1fe2f97c..830a3fe861 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * OHCI HCD (Host Controller Driver) for USB. 2 * OHCI HCD (Host Controller Driver) for USB.
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * This file is licenced under the GPL. 7 * This file is licenced under the GPL.
8 */ 8 */
9 9
@@ -89,7 +89,7 @@ __acquires(ohci->lock)
89 89
90/*-------------------------------------------------------------------------* 90/*-------------------------------------------------------------------------*
91 * ED handling functions 91 * ED handling functions
92 *-------------------------------------------------------------------------*/ 92 *-------------------------------------------------------------------------*/
93 93
94/* search for the right schedule branch to use for a periodic ed. 94/* search for the right schedule branch to use for a periodic ed.
95 * does some load balancing; returns the branch, or negative errno. 95 * does some load balancing; returns the branch, or negative errno.
@@ -107,7 +107,6 @@ static int balance (struct ohci_hcd *ohci, int interval, int load)
107 */ 107 */
108 for (i = 0; i < interval ; i++) { 108 for (i = 0; i < interval ; i++) {
109 if (branch < 0 || ohci->load [branch] > ohci->load [i]) { 109 if (branch < 0 || ohci->load [branch] > ohci->load [i]) {
110#if 1 /* CONFIG_USB_BANDWIDTH */
111 int j; 110 int j;
112 111
113 /* usb 1.1 says 90% of one frame */ 112 /* usb 1.1 says 90% of one frame */
@@ -117,8 +116,7 @@ static int balance (struct ohci_hcd *ohci, int interval, int load)
117 } 116 }
118 if (j < NUM_INTS) 117 if (j < NUM_INTS)
119 continue; 118 continue;
120#endif 119 branch = i;
121 branch = i;
122 } 120 }
123 } 121 }
124 return branch; 122 return branch;
@@ -171,7 +169,7 @@ static void periodic_link (struct ohci_hcd *ohci, struct ed *ed)
171/* link an ed into one of the HC chains */ 169/* link an ed into one of the HC chains */
172 170
173static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed) 171static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
174{ 172{
175 int branch; 173 int branch;
176 174
177 if (ohci_to_hcd(ohci)->state == HC_STATE_QUIESCING) 175 if (ohci_to_hcd(ohci)->state == HC_STATE_QUIESCING)
@@ -248,7 +246,7 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
248 } 246 }
249 ed->branch = branch; 247 ed->branch = branch;
250 periodic_link (ohci, ed); 248 periodic_link (ohci, ed);
251 } 249 }
252 250
253 /* the HC may not see the schedule updates yet, but if it does 251 /* the HC may not see the schedule updates yet, but if it does
254 * then they'll be properly ordered. 252 * then they'll be properly ordered.
@@ -277,7 +275,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
277 *prev = ed->ed_next; 275 *prev = ed->ed_next;
278 } 276 }
279 ohci->load [i] -= ed->load; 277 ohci->load [i] -= ed->load;
280 } 278 }
281 ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->load / ed->interval; 279 ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->load / ed->interval;
282 280
283 ohci_vdbg (ohci, "unlink %sed %p branch %d [%dus.], interval %d\n", 281 ohci_vdbg (ohci, "unlink %sed %p branch %d [%dus.], interval %d\n",
@@ -285,7 +283,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
285 ed, ed->branch, ed->load, ed->interval); 283 ed, ed->branch, ed->load, ed->interval);
286} 284}
287 285
288/* unlink an ed from one of the HC chains. 286/* unlink an ed from one of the HC chains.
289 * just the link to the ed is unlinked. 287 * just the link to the ed is unlinked.
290 * the link from the ed still points to another operational ed or 0 288 * the link from the ed still points to another operational ed or 0
291 * so the HC can eventually finish the processing of the unlinked ed 289 * so the HC can eventually finish the processing of the unlinked ed
@@ -307,7 +305,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
307 * When finish_unlinks() runs later, after SOF interrupt, it will often 305 * When finish_unlinks() runs later, after SOF interrupt, it will often
308 * complete one or more URB unlinks before making that state change. 306 * complete one or more URB unlinks before making that state change.
309 */ 307 */
310static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed) 308static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed)
311{ 309{
312 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP); 310 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP);
313 wmb (); 311 wmb ();
@@ -397,7 +395,7 @@ static struct ed *ed_get (
397 unsigned int pipe, 395 unsigned int pipe,
398 int interval 396 int interval
399) { 397) {
400 struct ed *ed; 398 struct ed *ed;
401 unsigned long flags; 399 unsigned long flags;
402 400
403 spin_lock_irqsave (&ohci->lock, flags); 401 spin_lock_irqsave (&ohci->lock, flags);
@@ -413,9 +411,9 @@ static struct ed *ed_get (
413 goto done; 411 goto done;
414 } 412 }
415 413
416 /* dummy td; end of td list for ed */ 414 /* dummy td; end of td list for ed */
417 td = td_alloc (ohci, GFP_ATOMIC); 415 td = td_alloc (ohci, GFP_ATOMIC);
418 if (!td) { 416 if (!td) {
419 /* out of memory */ 417 /* out of memory */
420 ed_free (ohci, ed); 418 ed_free (ohci, ed);
421 ed = NULL; 419 ed = NULL;
@@ -462,7 +460,7 @@ static struct ed *ed_get (
462 460
463done: 461done:
464 spin_unlock_irqrestore (&ohci->lock, flags); 462 spin_unlock_irqrestore (&ohci->lock, flags);
465 return ed; 463 return ed;
466} 464}
467 465
468/*-------------------------------------------------------------------------*/ 466/*-------------------------------------------------------------------------*/
@@ -474,7 +472,7 @@ done:
474 * and that ed->state is ED_OPER 472 * and that ed->state is ED_OPER
475 */ 473 */
476static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed) 474static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed)
477{ 475{
478 ed->hwINFO |= cpu_to_hc32 (ohci, ED_DEQUEUE); 476 ed->hwINFO |= cpu_to_hc32 (ohci, ED_DEQUEUE);
479 ed_deschedule (ohci, ed); 477 ed_deschedule (ohci, ed);
480 478
@@ -541,7 +539,7 @@ td_fill (struct ohci_hcd *ohci, u32 info,
541 td->ed = urb_priv->ed; 539 td->ed = urb_priv->ed;
542 td->next_dl_td = NULL; 540 td->next_dl_td = NULL;
543 td->index = index; 541 td->index = index;
544 td->urb = urb; 542 td->urb = urb;
545 td->data_dma = data; 543 td->data_dma = data;
546 if (!len) 544 if (!len)
547 data = 0; 545 data = 0;
@@ -553,8 +551,8 @@ td_fill (struct ohci_hcd *ohci, u32 info,
553 (data & 0x0FFF) | 0xE000); 551 (data & 0x0FFF) | 0xE000);
554 td->ed->last_iso = info & 0xffff; 552 td->ed->last_iso = info & 0xffff;
555 } else { 553 } else {
556 td->hwCBP = cpu_to_hc32 (ohci, data); 554 td->hwCBP = cpu_to_hc32 (ohci, data);
557 } 555 }
558 if (data) 556 if (data)
559 td->hwBE = cpu_to_hc32 (ohci, data + len - 1); 557 td->hwBE = cpu_to_hc32 (ohci, data + len - 1);
560 else 558 else
@@ -597,7 +595,7 @@ static void td_submit_urb (
597 * use the device toggle bits for resetting, and rely on the fact 595 * use the device toggle bits for resetting, and rely on the fact
598 * that resetting toggle is meaningless if the endpoint is active. 596 * that resetting toggle is meaningless if the endpoint is active.
599 */ 597 */
600 if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) { 598 if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) {
601 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), 599 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe),
602 is_out, 1); 600 is_out, 1);
603 urb_priv->ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_C); 601 urb_priv->ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_C);
@@ -721,16 +719,16 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
721 list_del (&td->td_list); 719 list_del (&td->td_list);
722 720
723 /* ISO ... drivers see per-TD length/status */ 721 /* ISO ... drivers see per-TD length/status */
724 if (tdINFO & TD_ISO) { 722 if (tdINFO & TD_ISO) {
725 u16 tdPSW = ohci_hwPSW (ohci, td, 0); 723 u16 tdPSW = ohci_hwPSW (ohci, td, 0);
726 int dlen = 0; 724 int dlen = 0;
727 725
728 /* NOTE: assumes FC in tdINFO == 0, and that 726 /* NOTE: assumes FC in tdINFO == 0, and that
729 * only the first of 0..MAXPSW psws is used. 727 * only the first of 0..MAXPSW psws is used.
730 */ 728 */
731 729
732 cc = (tdPSW >> 12) & 0xF; 730 cc = (tdPSW >> 12) & 0xF;
733 if (tdINFO & TD_CC) /* hc didn't touch? */ 731 if (tdINFO & TD_CC) /* hc didn't touch? */
734 return; 732 return;
735 733
736 if (usb_pipeout (urb->pipe)) 734 if (usb_pipeout (urb->pipe))
@@ -758,7 +756,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
758 int type = usb_pipetype (urb->pipe); 756 int type = usb_pipetype (urb->pipe);
759 u32 tdBE = hc32_to_cpup (ohci, &td->hwBE); 757 u32 tdBE = hc32_to_cpup (ohci, &td->hwBE);
760 758
761 cc = TD_CC_GET (tdINFO); 759 cc = TD_CC_GET (tdINFO);
762 760
763 /* update packet status if needed (short is normally ok) */ 761 /* update packet status if needed (short is normally ok) */
764 if (cc == TD_DATAUNDERRUN 762 if (cc == TD_DATAUNDERRUN
@@ -787,7 +785,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
787 urb, td, 1 + td->index, cc, 785 urb, td, 1 + td->index, cc,
788 urb->actual_length, 786 urb->actual_length,
789 urb->transfer_buffer_length); 787 urb->transfer_buffer_length);
790 } 788 }
791} 789}
792 790
793/*-------------------------------------------------------------------------*/ 791/*-------------------------------------------------------------------------*/
@@ -795,7 +793,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
795static inline struct td * 793static inline struct td *
796ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev) 794ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
797{ 795{
798 struct urb *urb = td->urb; 796 struct urb *urb = td->urb;
799 struct ed *ed = td->ed; 797 struct ed *ed = td->ed;
800 struct list_head *tmp = td->td_list.next; 798 struct list_head *tmp = td->td_list.next;
801 __hc32 toggle = ed->hwHeadP & cpu_to_hc32 (ohci, ED_C); 799 __hc32 toggle = ed->hwHeadP & cpu_to_hc32 (ohci, ED_C);
@@ -805,7 +803,7 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
805 */ 803 */
806 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP); 804 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP);
807 wmb (); 805 wmb ();
808 ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_H); 806 ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_H);
809 807
810 /* put any later tds from this urb onto the donelist, after 'td', 808 /* put any later tds from this urb onto the donelist, after 'td',
811 * order won't matter here: no errors, and nothing was transferred. 809 * order won't matter here: no errors, and nothing was transferred.
@@ -833,7 +831,7 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
833 info &= ~cpu_to_hc32 (ohci, TD_CC); 831 info &= ~cpu_to_hc32 (ohci, TD_CC);
834 next->hwINFO = info; 832 next->hwINFO = info;
835 833
836 next->next_dl_td = rev; 834 next->next_dl_td = rev;
837 rev = next; 835 rev = next;
838 836
839 ed->hwHeadP = next->hwNextTD | toggle; 837 ed->hwHeadP = next->hwNextTD | toggle;
@@ -881,8 +879,8 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
881 /* get TD from hc's singly linked list, and 879 /* get TD from hc's singly linked list, and
882 * prepend to ours. ed->td_list changes later. 880 * prepend to ours. ed->td_list changes later.
883 */ 881 */
884 while (td_dma) { 882 while (td_dma) {
885 int cc; 883 int cc;
886 884
887 td = dma_to_td (ohci, td_dma); 885 td = dma_to_td (ohci, td_dma);
888 if (!td) { 886 if (!td) {
@@ -901,10 +899,10 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
901 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H))) 899 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H)))
902 td_rev = ed_halted (ohci, td, cc, td_rev); 900 td_rev = ed_halted (ohci, td, cc, td_rev);
903 901
904 td->next_dl_td = td_rev; 902 td->next_dl_td = td_rev;
905 td_rev = td; 903 td_rev = td;
906 td_dma = hc32_to_cpup (ohci, &td->hwNextTD); 904 td_dma = hc32_to_cpup (ohci, &td->hwNextTD);
907 } 905 }
908 return td_rev; 906 return td_rev;
909} 907}
910 908
@@ -1013,9 +1011,9 @@ rescan_this:
1013 1011
1014 if (modified) 1012 if (modified)
1015 goto rescan_all; 1013 goto rescan_all;
1016 } 1014 }
1017 1015
1018 /* maybe reenable control and bulk lists */ 1016 /* maybe reenable control and bulk lists */
1019 if (HC_IS_RUNNING(ohci_to_hcd(ohci)->state) 1017 if (HC_IS_RUNNING(ohci_to_hcd(ohci)->state)
1020 && ohci_to_hcd(ohci)->state != HC_STATE_QUIESCING 1018 && ohci_to_hcd(ohci)->state != HC_STATE_QUIESCING
1021 && !ohci->ed_rm_list) { 1019 && !ohci->ed_rm_list) {
@@ -1041,20 +1039,20 @@ rescan_this:
1041 &ohci->regs->ed_bulkcurrent); 1039 &ohci->regs->ed_bulkcurrent);
1042 } 1040 }
1043 } 1041 }
1044 1042
1045 /* CLE/BLE to enable, CLF/BLF to (maybe) kickstart */ 1043 /* CLE/BLE to enable, CLF/BLF to (maybe) kickstart */
1046 if (control) { 1044 if (control) {
1047 ohci->hc_control |= control; 1045 ohci->hc_control |= control;
1048 if (ohci->flags & OHCI_QUIRK_ZFMICRO) 1046 if (ohci->flags & OHCI_QUIRK_ZFMICRO)
1049 mdelay(1); 1047 mdelay(1);
1050 ohci_writel (ohci, ohci->hc_control, 1048 ohci_writel (ohci, ohci->hc_control,
1051 &ohci->regs->control); 1049 &ohci->regs->control);
1052 } 1050 }
1053 if (command) { 1051 if (command) {
1054 if (ohci->flags & OHCI_QUIRK_ZFMICRO) 1052 if (ohci->flags & OHCI_QUIRK_ZFMICRO)
1055 mdelay(1); 1053 mdelay(1);
1056 ohci_writel (ohci, command, &ohci->regs->cmdstatus); 1054 ohci_writel (ohci, command, &ohci->regs->cmdstatus);
1057 } 1055 }
1058 } 1056 }
1059} 1057}
1060 1058
@@ -1074,19 +1072,19 @@ dl_done_list (struct ohci_hcd *ohci)
1074{ 1072{
1075 struct td *td = dl_reverse_done_list (ohci); 1073 struct td *td = dl_reverse_done_list (ohci);
1076 1074
1077 while (td) { 1075 while (td) {
1078 struct td *td_next = td->next_dl_td; 1076 struct td *td_next = td->next_dl_td;
1079 struct urb *urb = td->urb; 1077 struct urb *urb = td->urb;
1080 urb_priv_t *urb_priv = urb->hcpriv; 1078 urb_priv_t *urb_priv = urb->hcpriv;
1081 struct ed *ed = td->ed; 1079 struct ed *ed = td->ed;
1082 1080
1083 /* update URB's length and status from TD */ 1081 /* update URB's length and status from TD */
1084 td_done (ohci, urb, td); 1082 td_done (ohci, urb, td);
1085 urb_priv->td_cnt++; 1083 urb_priv->td_cnt++;
1086 1084
1087 /* If all this urb's TDs are done, call complete() */ 1085 /* If all this urb's TDs are done, call complete() */
1088 if (urb_priv->td_cnt == urb_priv->length) 1086 if (urb_priv->td_cnt == urb_priv->length)
1089 finish_urb (ohci, urb); 1087 finish_urb (ohci, urb);
1090 1088
1091 /* clean schedule: unlink EDs that are no longer busy */ 1089 /* clean schedule: unlink EDs that are no longer busy */
1092 if (list_empty (&ed->td_list)) { 1090 if (list_empty (&ed->td_list)) {
@@ -1094,25 +1092,26 @@ dl_done_list (struct ohci_hcd *ohci)
1094 start_ed_unlink (ohci, ed); 1092 start_ed_unlink (ohci, ed);
1095 1093
1096 /* ... reenabling halted EDs only after fault cleanup */ 1094 /* ... reenabling halted EDs only after fault cleanup */
1097 } else if ((ed->hwINFO & cpu_to_hc32 (ohci, ED_SKIP | ED_DEQUEUE)) 1095 } else if ((ed->hwINFO & cpu_to_hc32 (ohci,
1096 ED_SKIP | ED_DEQUEUE))
1098 == cpu_to_hc32 (ohci, ED_SKIP)) { 1097 == cpu_to_hc32 (ohci, ED_SKIP)) {
1099 td = list_entry (ed->td_list.next, struct td, td_list); 1098 td = list_entry (ed->td_list.next, struct td, td_list);
1100 if (!(td->hwINFO & cpu_to_hc32 (ohci, TD_DONE))) { 1099 if (!(td->hwINFO & cpu_to_hc32 (ohci, TD_DONE))) {
1101 ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP); 1100 ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP);
1102 /* ... hc may need waking-up */ 1101 /* ... hc may need waking-up */
1103 switch (ed->type) { 1102 switch (ed->type) {
1104 case PIPE_CONTROL: 1103 case PIPE_CONTROL:
1105 ohci_writel (ohci, OHCI_CLF, 1104 ohci_writel (ohci, OHCI_CLF,
1106 &ohci->regs->cmdstatus); 1105 &ohci->regs->cmdstatus);
1107 break; 1106 break;
1108 case PIPE_BULK: 1107 case PIPE_BULK:
1109 ohci_writel (ohci, OHCI_BLF, 1108 ohci_writel (ohci, OHCI_BLF,
1110 &ohci->regs->cmdstatus); 1109 &ohci->regs->cmdstatus);
1111 break; 1110 break;
1112 } 1111 }
1113 } 1112 }
1114 } 1113 }
1115 1114
1116 td = td_next; 1115 td = td_next;
1117 } 1116 }
1118} 1117}
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index 59e436424d..b350d45033 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -447,7 +447,7 @@ static const struct hc_driver ohci_s3c2410_hc_driver = {
447 */ 447 */
448 .start = ohci_s3c2410_start, 448 .start = ohci_s3c2410_start,
449 .stop = ohci_stop, 449 .stop = ohci_stop,
450 .shutdown = ohci_shutdown, 450 .shutdown = ohci_shutdown,
451 451
452 /* 452 /*
453 * managing i/o requests and associated device resources 453 * managing i/o requests and associated device resources
@@ -492,7 +492,7 @@ static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev)
492static struct platform_driver ohci_hcd_s3c2410_driver = { 492static struct platform_driver ohci_hcd_s3c2410_driver = {
493 .probe = ohci_hcd_s3c2410_drv_probe, 493 .probe = ohci_hcd_s3c2410_drv_probe,
494 .remove = ohci_hcd_s3c2410_drv_remove, 494 .remove = ohci_hcd_s3c2410_drv_remove,
495 .shutdown = usb_hcd_platform_shutdown, 495 .shutdown = usb_hcd_platform_shutdown,
496 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */ 496 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */
497 /*.resume = ohci_hcd_s3c2410_drv_resume, */ 497 /*.resume = ohci_hcd_s3c2410_drv_resume, */
498 .driver = { 498 .driver = {
diff --git a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c
index 71371de32a..fe0090e336 100644
--- a/drivers/usb/host/ohci-sa1111.c
+++ b/drivers/usb/host/ohci-sa1111.c
@@ -4,7 +4,7 @@
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company 6 * (C) Copyright 2002 Hewlett-Packard Company
7 * 7 *
8 * SA1111 Bus Glue 8 * SA1111 Bus Glue
9 * 9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com> 10 * Written by Christopher Hoover <ch@hpl.hp.com>
@@ -12,7 +12,7 @@
12 * 12 *
13 * This file is licenced under the GPL. 13 * This file is licenced under the GPL.
14 */ 14 */
15 15
16#include <asm/hardware.h> 16#include <asm/hardware.h>
17#include <asm/mach-types.h> 17#include <asm/mach-types.h>
18#include <asm/arch/assabet.h> 18#include <asm/arch/assabet.h>
@@ -31,7 +31,7 @@ static void sa1111_start_hc(struct sa1111_dev *dev)
31{ 31{
32 unsigned int usb_rst = 0; 32 unsigned int usb_rst = 0;
33 33
34 printk(KERN_DEBUG __FILE__ 34 printk(KERN_DEBUG __FILE__
35 ": starting SA-1111 OHCI USB Controller\n"); 35 ": starting SA-1111 OHCI USB Controller\n");
36 36
37#ifdef CONFIG_SA1100_BADGE4 37#ifdef CONFIG_SA1100_BADGE4
@@ -65,7 +65,7 @@ static void sa1111_start_hc(struct sa1111_dev *dev)
65static void sa1111_stop_hc(struct sa1111_dev *dev) 65static void sa1111_stop_hc(struct sa1111_dev *dev)
66{ 66{
67 unsigned int usb_rst; 67 unsigned int usb_rst;
68 printk(KERN_DEBUG __FILE__ 68 printk(KERN_DEBUG __FILE__
69 ": stopping SA-1111 OHCI USB Controller\n"); 69 ": stopping SA-1111 OHCI USB Controller\n");
70 70
71 /* 71 /*
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index a2f42a2f47..405257f3e8 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -1,9 +1,9 @@
1/* 1/*
2 * OHCI HCD (Host Controller Driver) for USB. 2 * OHCI HCD (Host Controller Driver) for USB.
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * This file is licenced under the GPL. 7 * This file is licenced under the GPL.
8 */ 8 */
9 9
@@ -14,7 +14,7 @@
14 */ 14 */
15typedef __u32 __bitwise __hc32; 15typedef __u32 __bitwise __hc32;
16typedef __u16 __bitwise __hc16; 16typedef __u16 __bitwise __hc16;
17 17
18/* 18/*
19 * OHCI Endpoint Descriptor (ED) ... holds TD queue 19 * OHCI Endpoint Descriptor (ED) ... holds TD queue
20 * See OHCI spec, section 4.2 20 * See OHCI spec, section 4.2
@@ -24,7 +24,7 @@ typedef __u16 __bitwise __hc16;
24 */ 24 */
25struct ed { 25struct ed {
26 /* first fields are hardware-specified */ 26 /* first fields are hardware-specified */
27 __hc32 hwINFO; /* endpoint config bitmap */ 27 __hc32 hwINFO; /* endpoint config bitmap */
28 /* info bits defined by hcd */ 28 /* info bits defined by hcd */
29#define ED_DEQUEUE (1 << 27) 29#define ED_DEQUEUE (1 << 27)
30 /* info bits defined by the hardware */ 30 /* info bits defined by the hardware */
@@ -52,11 +52,11 @@ struct ed {
52 * usually: OPER --> UNLINK --> (IDLE | OPER) --> ... 52 * usually: OPER --> UNLINK --> (IDLE | OPER) --> ...
53 */ 53 */
54 u8 state; /* ED_{IDLE,UNLINK,OPER} */ 54 u8 state; /* ED_{IDLE,UNLINK,OPER} */
55#define ED_IDLE 0x00 /* NOT linked to HC */ 55#define ED_IDLE 0x00 /* NOT linked to HC */
56#define ED_UNLINK 0x01 /* being unlinked from hc */ 56#define ED_UNLINK 0x01 /* being unlinked from hc */
57#define ED_OPER 0x02 /* IS linked to hc */ 57#define ED_OPER 0x02 /* IS linked to hc */
58 58
59 u8 type; /* PIPE_{BULK,...} */ 59 u8 type; /* PIPE_{BULK,...} */
60 60
61 /* periodic scheduling params (for intr and iso) */ 61 /* periodic scheduling params (for intr and iso) */
62 u8 branch; 62 u8 branch;
@@ -70,7 +70,7 @@ struct ed {
70 70
71#define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */ 71#define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */
72 72
73 73
74/* 74/*
75 * OHCI Transfer Descriptor (TD) ... one per transfer segment 75 * OHCI Transfer Descriptor (TD) ... one per transfer segment
76 * See OHCI spec, sections 4.3.1 (general = control/bulk/interrupt) 76 * See OHCI spec, sections 4.3.1 (general = control/bulk/interrupt)
@@ -107,22 +107,22 @@ struct td {
107 107
108 /* (no hwINFO #defines yet for iso tds) */ 108 /* (no hwINFO #defines yet for iso tds) */
109 109
110 __hc32 hwCBP; /* Current Buffer Pointer (or 0) */ 110 __hc32 hwCBP; /* Current Buffer Pointer (or 0) */
111 __hc32 hwNextTD; /* Next TD Pointer */ 111 __hc32 hwNextTD; /* Next TD Pointer */
112 __hc32 hwBE; /* Memory Buffer End Pointer */ 112 __hc32 hwBE; /* Memory Buffer End Pointer */
113 113
114 /* PSW is only for ISO. Only 1 PSW entry is used, but on 114 /* PSW is only for ISO. Only 1 PSW entry is used, but on
115 * big-endian PPC hardware that's the second entry. 115 * big-endian PPC hardware that's the second entry.
116 */ 116 */
117#define MAXPSW 2 117#define MAXPSW 2
118 __hc16 hwPSW [MAXPSW]; 118 __hc16 hwPSW [MAXPSW];
119 119
120 /* rest are purely for the driver's use */ 120 /* rest are purely for the driver's use */
121 __u8 index; 121 __u8 index;
122 struct ed *ed; 122 struct ed *ed;
123 struct td *td_hash; /* dma-->td hashtable */ 123 struct td *td_hash; /* dma-->td hashtable */
124 struct td *next_dl_td; 124 struct td *next_dl_td;
125 struct urb *urb; 125 struct urb *urb;
126 126
127 dma_addr_t td_dma; /* addr of this TD */ 127 dma_addr_t td_dma; /* addr of this TD */
128 dma_addr_t data_dma; /* addr of data it points to */ 128 dma_addr_t data_dma; /* addr of data it points to */
@@ -152,8 +152,8 @@ struct td {
152#define TD_NOTACCESSED 0x0F 152#define TD_NOTACCESSED 0x0F
153 153
154 154
155/* map OHCI TD status codes (CC) to errno values */ 155/* map OHCI TD status codes (CC) to errno values */
156static const int cc_to_error [16] = { 156static const int cc_to_error [16] = {
157 /* No Error */ 0, 157 /* No Error */ 0,
158 /* CRC Error */ -EILSEQ, 158 /* CRC Error */ -EILSEQ,
159 /* Bit Stuff */ -EPROTO, 159 /* Bit Stuff */ -EPROTO,
@@ -169,7 +169,7 @@ static const int cc_to_error [16] = {
169 /* BufferOver */ -ECOMM, 169 /* BufferOver */ -ECOMM,
170 /* BuffUnder */ -ENOSR, 170 /* BuffUnder */ -ENOSR,
171 /* (for HCD) */ -EALREADY, 171 /* (for HCD) */ -EALREADY,
172 /* (for HCD) */ -EALREADY 172 /* (for HCD) */ -EALREADY
173}; 173};
174 174
175 175
@@ -182,7 +182,7 @@ struct ohci_hcca {
182#define NUM_INTS 32 182#define NUM_INTS 32
183 __hc32 int_table [NUM_INTS]; /* periodic schedule */ 183 __hc32 int_table [NUM_INTS]; /* periodic schedule */
184 184
185 /* 185 /*
186 * OHCI defines u16 frame_no, followed by u16 zero pad. 186 * OHCI defines u16 frame_no, followed by u16 zero pad.
187 * Since some processors can't do 16 bit bus accesses, 187 * Since some processors can't do 16 bit bus accesses,
188 * portable access must be a 32 bits wide. 188 * portable access must be a 32 bits wide.
@@ -262,10 +262,10 @@ struct ohci_regs {
262 * HcCommandStatus (cmdstatus) register masks 262 * HcCommandStatus (cmdstatus) register masks
263 */ 263 */
264#define OHCI_HCR (1 << 0) /* host controller reset */ 264#define OHCI_HCR (1 << 0) /* host controller reset */
265#define OHCI_CLF (1 << 1) /* control list filled */ 265#define OHCI_CLF (1 << 1) /* control list filled */
266#define OHCI_BLF (1 << 2) /* bulk list filled */ 266#define OHCI_BLF (1 << 2) /* bulk list filled */
267#define OHCI_OCR (1 << 3) /* ownership change request */ 267#define OHCI_OCR (1 << 3) /* ownership change request */
268#define OHCI_SOC (3 << 16) /* scheduling overrun count */ 268#define OHCI_SOC (3 << 16) /* scheduling overrun count */
269 269
270/* 270/*
271 * masks used with interrupt registers: 271 * masks used with interrupt registers:
@@ -285,20 +285,20 @@ struct ohci_regs {
285 285
286 286
287/* OHCI ROOT HUB REGISTER MASKS */ 287/* OHCI ROOT HUB REGISTER MASKS */
288 288
289/* roothub.portstatus [i] bits */ 289/* roothub.portstatus [i] bits */
290#define RH_PS_CCS 0x00000001 /* current connect status */ 290#define RH_PS_CCS 0x00000001 /* current connect status */
291#define RH_PS_PES 0x00000002 /* port enable status*/ 291#define RH_PS_PES 0x00000002 /* port enable status*/
292#define RH_PS_PSS 0x00000004 /* port suspend status */ 292#define RH_PS_PSS 0x00000004 /* port suspend status */
293#define RH_PS_POCI 0x00000008 /* port over current indicator */ 293#define RH_PS_POCI 0x00000008 /* port over current indicator */
294#define RH_PS_PRS 0x00000010 /* port reset status */ 294#define RH_PS_PRS 0x00000010 /* port reset status */
295#define RH_PS_PPS 0x00000100 /* port power status */ 295#define RH_PS_PPS 0x00000100 /* port power status */
296#define RH_PS_LSDA 0x00000200 /* low speed device attached */ 296#define RH_PS_LSDA 0x00000200 /* low speed device attached */
297#define RH_PS_CSC 0x00010000 /* connect status change */ 297#define RH_PS_CSC 0x00010000 /* connect status change */
298#define RH_PS_PESC 0x00020000 /* port enable status change */ 298#define RH_PS_PESC 0x00020000 /* port enable status change */
299#define RH_PS_PSSC 0x00040000 /* port suspend status change */ 299#define RH_PS_PSSC 0x00040000 /* port suspend status change */
300#define RH_PS_OCIC 0x00080000 /* over current indicator change */ 300#define RH_PS_OCIC 0x00080000 /* over current indicator change */
301#define RH_PS_PRSC 0x00100000 /* port reset status change */ 301#define RH_PS_PRSC 0x00100000 /* port reset status change */
302 302
303/* roothub.status bits */ 303/* roothub.status bits */
304#define RH_HS_LPS 0x00000001 /* local power status */ 304#define RH_HS_LPS 0x00000001 /* local power status */
@@ -333,7 +333,7 @@ typedef struct urb_priv {
333} urb_priv_t; 333} urb_priv_t;
334 334
335#define TD_HASH_SIZE 64 /* power'o'two */ 335#define TD_HASH_SIZE 64 /* power'o'two */
336// sizeof (struct td) ~= 64 == 2^6 ... 336// sizeof (struct td) ~= 64 == 2^6 ...
337#define TD_HASH_FUNC(td_dma) ((td_dma ^ (td_dma >> 6)) % TD_HASH_SIZE) 337#define TD_HASH_FUNC(td_dma) ((td_dma ^ (td_dma >> 6)) % TD_HASH_SIZE)
338 338
339 339
@@ -364,11 +364,11 @@ struct ohci_hcd {
364 364
365 struct ed *ed_bulktail; /* last in bulk list */ 365 struct ed *ed_bulktail; /* last in bulk list */
366 struct ed *ed_controltail; /* last in ctrl list */ 366 struct ed *ed_controltail; /* last in ctrl list */
367 struct ed *periodic [NUM_INTS]; /* shadow int_table */ 367 struct ed *periodic [NUM_INTS]; /* shadow int_table */
368 368
369 /* 369 /*
370 * OTG controllers and transceivers need software interaction; 370 * OTG controllers and transceivers need software interaction;
371 * other external transceivers should be software-transparent 371 * other external transceivers should be software-transparent
372 */ 372 */
373 struct otg_transceiver *transceiver; 373 struct otg_transceiver *transceiver;
374 374
@@ -385,7 +385,7 @@ struct ohci_hcd {
385 */ 385 */
386 int num_ports; 386 int num_ports;
387 int load [NUM_INTS]; 387 int load [NUM_INTS];
388 u32 hc_control; /* copy of hc control reg */ 388 u32 hc_control; /* copy of hc control reg */
389 unsigned long next_statechange; /* suspend/resume */ 389 unsigned long next_statechange; /* suspend/resume */
390 u32 fminterval; /* saved register */ 390 u32 fminterval; /* saved register */
391 unsigned autostop:1; /* rh auto stopping/stopped */ 391 unsigned autostop:1; /* rh auto stopping/stopped */
@@ -598,11 +598,11 @@ static inline void disable (struct ohci_hcd *ohci)
598} 598}
599 599
600#define FI 0x2edf /* 12000 bits per frame (-1) */ 600#define FI 0x2edf /* 12000 bits per frame (-1) */
601#define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7)) 601#define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7))
602#define FIT (1 << 31) 602#define FIT (1 << 31)
603#define LSTHRESH 0x628 /* lowspeed bit threshold */ 603#define LSTHRESH 0x628 /* lowspeed bit threshold */
604 604
605static void periodic_reinit (struct ohci_hcd *ohci) 605static inline void periodic_reinit (struct ohci_hcd *ohci)
606{ 606{
607 u32 fi = ohci->fminterval & 0x03fff; 607 u32 fi = ohci->fminterval & 0x03fff;
608 u32 fit = ohci_readl(ohci, &ohci->regs->fminterval) & FIT; 608 u32 fit = ohci_readl(ohci, &ohci->regs->fminterval) & FIT;
@@ -626,11 +626,11 @@ static void periodic_reinit (struct ohci_hcd *ohci)
626 temp = ohci_readl (hc, &hc->regs->roothub.register); \ 626 temp = ohci_readl (hc, &hc->regs->roothub.register); \
627 temp; }) 627 temp; })
628 628
629static u32 roothub_a (struct ohci_hcd *hc) 629static inline u32 roothub_a (struct ohci_hcd *hc)
630 { return read_roothub (hc, a, 0xfc0fe000); } 630 { return read_roothub (hc, a, 0xfc0fe000); }
631static inline u32 roothub_b (struct ohci_hcd *hc) 631static inline u32 roothub_b (struct ohci_hcd *hc)
632 { return ohci_readl (hc, &hc->regs->roothub.b); } 632 { return ohci_readl (hc, &hc->regs->roothub.b); }
633static inline u32 roothub_status (struct ohci_hcd *hc) 633static inline u32 roothub_status (struct ohci_hcd *hc)
634 { return ohci_readl (hc, &hc->regs->roothub.status); } 634 { return ohci_readl (hc, &hc->regs->roothub.status); }
635static u32 roothub_portstatus (struct ohci_hcd *hc, int i) 635static inline u32 roothub_portstatus (struct ohci_hcd *hc, int i)
636 { return read_roothub (hc, portstatus [i], 0xffe0fce0); } 636 { return read_roothub (hc, portstatus [i], 0xffe0fce0); }
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index a9d7119e31..a7fa0d7556 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -40,6 +40,7 @@
40#include <linux/moduleparam.h> 40#include <linux/moduleparam.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/ioport.h> 42#include <linux/ioport.h>
43#include <linux/pci_ids.h>
43#include <linux/sched.h> 44#include <linux/sched.h>
44#include <linux/slab.h> 45#include <linux/slab.h>
45#include <linux/smp_lock.h> 46#include <linux/smp_lock.h>
@@ -210,15 +211,16 @@ struct u132 {
210* these cannot be inlines because we need the structure offset!! 211* these cannot be inlines because we need the structure offset!!
211* Does anyone have a better way????? 212* Does anyone have a better way?????
212*/ 213*/
214#define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
215 offsetof(struct ohci_regs, member), 0, data);
216#define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
217 offsetof(struct ohci_regs, member), 0, data);
213#define u132_read_pcimem(u132, member, data) \ 218#define u132_read_pcimem(u132, member, data) \
214 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \ 219 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
215 ohci_regs, member), 0, data); 220 ohci_regs, member), 0, data);
216#define u132_write_pcimem(u132, member, data) \ 221#define u132_write_pcimem(u132, member, data) \
217 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \ 222 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
218 ohci_regs, member), 0, data); 223 ohci_regs, member), 0, data);
219#define u132_write_pcimem_byte(u132, member, data) \
220 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
221 ohci_regs, member), 0x0e, data);
222static inline struct u132 *udev_to_u132(struct u132_udev *udev) 224static inline struct u132 *udev_to_u132(struct u132_udev *udev)
223{ 225{
224 u8 udev_number = udev->udev_number; 226 u8 udev_number = udev->udev_number;
@@ -1574,59 +1576,12 @@ static char *hcfs2string(int state)
1574 return "?"; 1576 return "?";
1575} 1577}
1576 1578
1577static int u132_usb_reset(struct u132 *u132)
1578{
1579 int retval;
1580 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1581 if (retval)
1582 return retval;
1583 u132->hc_control &= OHCI_CTRL_RWC;
1584 retval = u132_write_pcimem(u132, control, u132->hc_control);
1585 if (retval)
1586 return retval;
1587 return 0;
1588}
1589
1590static int u132_init(struct u132 *u132) 1579static int u132_init(struct u132 *u132)
1591{ 1580{
1592 int retval; 1581 int retval;
1593 u32 control; 1582 u32 control;
1594 u132_disable(u132); 1583 u132_disable(u132);
1595 u132->next_statechange = 1584 u132->next_statechange = jiffies;
1596 jiffies; /* SMM owns the HC? not for long! */ {
1597 u32 control;
1598 retval = u132_read_pcimem(u132, control, &control);
1599 if (retval)
1600 return retval;
1601 if (control & OHCI_CTRL_IR) {
1602 u32 temp = 50;
1603 retval = u132_write_pcimem(u132, intrenable,
1604 OHCI_INTR_OC);
1605 if (retval)
1606 return retval;
1607 retval = u132_write_pcimem_byte(u132, cmdstatus,
1608 OHCI_OCR);
1609 if (retval)
1610 return retval;
1611 check:{
1612 retval = u132_read_pcimem(u132, control,
1613 &control);
1614 if (retval)
1615 return retval;
1616 }
1617 if (control & OHCI_CTRL_IR) {
1618 msleep(10);
1619 if (--temp == 0) {
1620 dev_err(&u132->platform_dev->dev, "USB "
1621 "HC takeover failed!(BIOS/SMM b"
1622 "ug) control=%08X\n", control);
1623 return -EBUSY;
1624 }
1625 goto check;
1626 }
1627 u132_usb_reset(u132);
1628 }
1629 }
1630 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE); 1585 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1631 if (retval) 1586 if (retval)
1632 return retval; 1587 return retval;
@@ -1725,7 +1680,7 @@ static int u132_run(struct u132 *u132)
1725 retry:retval = u132_read_pcimem(u132, cmdstatus, &status); 1680 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1726 if (retval) 1681 if (retval)
1727 return retval; 1682 return retval;
1728 retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_HCR); 1683 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1729 if (retval) 1684 if (retval)
1730 return retval; 1685 return retval;
1731 extra:{ 1686 extra:{
@@ -1782,7 +1737,7 @@ static int u132_run(struct u132 *u132)
1782 retval = u132_write_pcimem(u132, control, u132->hc_control); 1737 retval = u132_write_pcimem(u132, control, u132->hc_control);
1783 if (retval) 1738 if (retval)
1784 return retval; 1739 return retval;
1785 retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_BLF); 1740 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1786 if (retval) 1741 if (retval)
1787 return retval; 1742 return retval;
1788 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus); 1743 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
@@ -1839,8 +1794,8 @@ static void u132_hcd_stop(struct usb_hcd *hcd)
1839{ 1794{
1840 struct u132 *u132 = hcd_to_u132(hcd); 1795 struct u132 *u132 = hcd_to_u132(hcd);
1841 if (u132->going > 1) { 1796 if (u132->going > 1) {
1842 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1797 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1843 , u132->going); 1798 "een removed %d\n", u132, hcd, u132->going);
1844 } else if (u132->going > 0) { 1799 } else if (u132->going > 0) {
1845 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" 1800 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1846 "ed\n", hcd); 1801 "ed\n", hcd);
@@ -2545,8 +2500,9 @@ static void u132_endpoint_disable(struct usb_hcd *hcd,
2545{ 2500{
2546 struct u132 *u132 = hcd_to_u132(hcd); 2501 struct u132 *u132 = hcd_to_u132(hcd);
2547 if (u132->going > 2) { 2502 if (u132->going > 2) {
2548 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2503 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2549 , u132->going); 2504 ") has been removed %d\n", u132, hcd, hep,
2505 u132->going);
2550 } else { 2506 } else {
2551 struct u132_endp *endp = hep->hcpriv; 2507 struct u132_endp *endp = hep->hcpriv;
2552 if (endp) 2508 if (endp)
@@ -2790,7 +2746,6 @@ static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2790 } else if (u132->going > 0) { 2746 } else if (u132->going > 0) {
2791 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" 2747 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2792 "ed\n", hcd); 2748 "ed\n", hcd);
2793 dump_stack();
2794 return -ESHUTDOWN; 2749 return -ESHUTDOWN;
2795 } else { 2750 } else {
2796 int i, changed = 0, length = 1; 2751 int i, changed = 0, length = 1;
@@ -3034,12 +2989,15 @@ static int __devexit u132_remove(struct platform_device *pdev)
3034 struct usb_hcd *hcd = platform_get_drvdata(pdev); 2989 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3035 if (hcd) { 2990 if (hcd) {
3036 struct u132 *u132 = hcd_to_u132(hcd); 2991 struct u132 *u132 = hcd_to_u132(hcd);
3037 dump_stack();
3038 if (u132->going++ > 1) { 2992 if (u132->going++ > 1) {
2993 dev_err(&u132->platform_dev->dev, "already being remove"
2994 "d\n");
3039 return -ENODEV; 2995 return -ENODEV;
3040 } else { 2996 } else {
3041 int rings = MAX_U132_RINGS; 2997 int rings = MAX_U132_RINGS;
3042 int endps = MAX_U132_ENDPS; 2998 int endps = MAX_U132_ENDPS;
2999 dev_err(&u132->platform_dev->dev, "removing device u132"
3000 ".%d\n", u132->sequence_num);
3043 msleep(100); 3001 msleep(100);
3044 down(&u132->sw_lock); 3002 down(&u132->sw_lock);
3045 u132_monitor_cancel_work(u132); 3003 u132_monitor_cancel_work(u132);
@@ -3121,10 +3079,24 @@ static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3121static int __devinit u132_probe(struct platform_device *pdev) 3079static int __devinit u132_probe(struct platform_device *pdev)
3122{ 3080{
3123 struct usb_hcd *hcd; 3081 struct usb_hcd *hcd;
3082 int retval;
3083 u32 control;
3084 u32 rh_a = -1;
3085 u32 num_ports;
3124 msleep(100); 3086 msleep(100);
3125 if (u132_exiting > 0) { 3087 if (u132_exiting > 0) {
3126 return -ENODEV; 3088 return -ENODEV;
3127 } /* refuse to confuse usbcore */ 3089 }
3090 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3091 if (retval)
3092 return retval;
3093 retval = ftdi_read_pcimem(pdev, control, &control);
3094 if (retval)
3095 return retval;
3096 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3097 if (retval)
3098 return retval;
3099 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3128 if (pdev->dev.dma_mask) { 3100 if (pdev->dev.dma_mask) {
3129 return -EINVAL; 3101 return -EINVAL;
3130 } 3102 }
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index e87692c31b..e0d4c2358b 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -60,6 +60,11 @@ Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, \
60Alan Stern" 60Alan Stern"
61#define DRIVER_DESC "USB Universal Host Controller Interface driver" 61#define DRIVER_DESC "USB Universal Host Controller Interface driver"
62 62
63/* for flakey hardware, ignore overcurrent indicators */
64static int ignore_oc;
65module_param(ignore_oc, bool, S_IRUGO);
66MODULE_PARM_DESC(ignore_oc, "ignore hardware overcurrent indications");
67
63/* 68/*
64 * debug = 0, no debugging messages 69 * debug = 0, no debugging messages
65 * debug = 1, dump failed URBs except for stalls 70 * debug = 1, dump failed URBs except for stalls
@@ -169,6 +174,11 @@ static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
169{ 174{
170 int port; 175 int port;
171 176
177 /* If we have to ignore overcurrent events then almost by definition
178 * we can't depend on resume-detect interrupts. */
179 if (ignore_oc)
180 return 1;
181
172 switch (to_pci_dev(uhci_dev(uhci))->vendor) { 182 switch (to_pci_dev(uhci_dev(uhci))->vendor) {
173 default: 183 default:
174 break; 184 break;
@@ -199,24 +209,16 @@ static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
199 209
200static int remote_wakeup_is_broken(struct uhci_hcd *uhci) 210static int remote_wakeup_is_broken(struct uhci_hcd *uhci)
201{ 211{
202 static struct dmi_system_id broken_wakeup_table[] = {
203 {
204 .ident = "Asus A7V8X",
205 .matches = {
206 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK"),
207 DMI_MATCH(DMI_BOARD_NAME, "A7V8X"),
208 DMI_MATCH(DMI_BOARD_VERSION, "REV 1.xx"),
209 }
210 },
211 { }
212 };
213 int port; 212 int port;
213 char *sys_info;
214 static char bad_Asus_board[] = "A7V8X";
214 215
215 /* One of Asus's motherboards has a bug which causes it to 216 /* One of Asus's motherboards has a bug which causes it to
216 * wake up immediately from suspend-to-RAM if any of the ports 217 * wake up immediately from suspend-to-RAM if any of the ports
217 * are connected. In such cases we will not set EGSM. 218 * are connected. In such cases we will not set EGSM.
218 */ 219 */
219 if (dmi_check_system(broken_wakeup_table)) { 220 sys_info = dmi_get_system_info(DMI_BOARD_NAME);
221 if (sys_info && !strcmp(sys_info, bad_Asus_board)) {
220 for (port = 0; port < uhci->rh_numports; ++port) { 222 for (port = 0; port < uhci->rh_numports; ++port) {
221 if (inw(uhci->io_addr + USBPORTSC1 + port * 2) & 223 if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
222 USBPORTSC_CCS) 224 USBPORTSC_CCS)
@@ -255,7 +257,9 @@ __acquires(uhci->lock)
255 int_enable = USBINTR_RESUME; 257 int_enable = USBINTR_RESUME;
256 if (remote_wakeup_is_broken(uhci)) 258 if (remote_wakeup_is_broken(uhci))
257 egsm_enable = 0; 259 egsm_enable = 0;
258 if (resume_detect_interrupts_are_broken(uhci) || !egsm_enable) 260 if (resume_detect_interrupts_are_broken(uhci) || !egsm_enable ||
261 !device_may_wakeup(
262 &uhci_to_hcd(uhci)->self.root_hub->dev))
259 uhci->working_RD = int_enable = 0; 263 uhci->working_RD = int_enable = 0;
260 264
261 outw(int_enable, uhci->io_addr + USBINTR); 265 outw(int_enable, uhci->io_addr + USBINTR);
@@ -921,7 +925,8 @@ static int __init uhci_hcd_init(void)
921{ 925{
922 int retval = -ENOMEM; 926 int retval = -ENOMEM;
923 927
924 printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION "\n"); 928 printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION "%s\n",
929 ignore_oc ? ", overcurrent ignored" : "");
925 930
926 if (usb_disabled()) 931 if (usb_disabled())
927 return -ENODEV; 932 return -ENODEV;
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index f8347f1a10..bacc25c53b 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -52,10 +52,20 @@ static int any_ports_active(struct uhci_hcd *uhci)
52static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf) 52static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf)
53{ 53{
54 int port; 54 int port;
55 int mask = RWC_BITS;
56
57 /* Some boards (both VIA and Intel apparently) report bogus
58 * overcurrent indications, causing massive log spam unless
59 * we completely ignore them. This doesn't seem to be a problem
60 * with the chipset so much as with the way it is connected on
61 * the motherboard; if the overcurrent input is left to float
62 * then it may constantly register false positives. */
63 if (ignore_oc)
64 mask &= ~USBPORTSC_OCC;
55 65
56 *buf = 0; 66 *buf = 0;
57 for (port = 0; port < uhci->rh_numports; ++port) { 67 for (port = 0; port < uhci->rh_numports; ++port) {
58 if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) & RWC_BITS) || 68 if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) & mask) ||
59 test_bit(port, &uhci->port_c_suspend)) 69 test_bit(port, &uhci->port_c_suspend))
60 *buf |= (1 << (port + 1)); 70 *buf |= (1 << (port + 1));
61 } 71 }
@@ -263,7 +273,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
263 wPortChange |= USB_PORT_STAT_C_CONNECTION; 273 wPortChange |= USB_PORT_STAT_C_CONNECTION;
264 if (status & USBPORTSC_PEC) 274 if (status & USBPORTSC_PEC)
265 wPortChange |= USB_PORT_STAT_C_ENABLE; 275 wPortChange |= USB_PORT_STAT_C_ENABLE;
266 if (status & USBPORTSC_OCC) 276 if ((status & USBPORTSC_OCC) && !ignore_oc)
267 wPortChange |= USB_PORT_STAT_C_OVERCURRENT; 277 wPortChange |= USB_PORT_STAT_C_OVERCURRENT;
268 278
269 if (test_bit(port, &uhci->port_c_suspend)) { 279 if (test_bit(port, &uhci->port_c_suspend)) {
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 8a62d47857..c7d887540d 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -7,14 +7,13 @@ comment "USB Input Devices"
7config USB_HID 7config USB_HID
8 tristate "USB Human Interface Device (full HID) support" 8 tristate "USB Human Interface Device (full HID) support"
9 default y 9 default y
10 depends on USB && HID 10 depends on USB && INPUT
11 select HID
11 ---help--- 12 ---help---
12 Say Y here if you want full HID support to connect USB keyboards, 13 Say Y here if you want full HID support to connect USB keyboards,
13 mice, joysticks, graphic tablets, or any other HID based devices 14 mice, joysticks, graphic tablets, or any other HID based devices
14 to your computer via USB. You also need to select HID Input layer 15 to your computer via USB, as well as Uninterruptible Power Supply
15 support (below) if you want to use keyboards, mice, joysticks and 16 (UPS) and monitor control devices.
16 the like ... as well as Uninterruptible Power Supply (UPS) and
17 monitor control devices.
18 17
19 You can't use this driver and the HIDBP (Boot Protocol) keyboard 18 You can't use this driver and the HIDBP (Boot Protocol) keyboard
20 and mouse drivers at the same time. More information is available: 19 and mouse drivers at the same time. More information is available:
@@ -28,7 +27,7 @@ config USB_HID
28comment "Input core support is needed for USB HID input layer or HIDBP support" 27comment "Input core support is needed for USB HID input layer or HIDBP support"
29 depends on USB_HID && INPUT=n 28 depends on USB_HID && INPUT=n
30 29
31config USB_HID_POWERBOOK 30config USB_HIDINPUT_POWERBOOK
32 bool "Enable support for iBook/PowerBook special keys" 31 bool "Enable support for iBook/PowerBook special keys"
33 default n 32 default n
34 depends on USB_HID 33 depends on USB_HID
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 89fa688570..c6c9e72e5f 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -56,11 +56,6 @@ static unsigned int hid_mousepoll_interval;
56module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644); 56module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
57MODULE_PARM_DESC(mousepoll, "Polling interval of mice"); 57MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
58 58
59static int usbhid_pb_fnmode = 1;
60module_param_named(pb_fnmode, usbhid_pb_fnmode, int, 0644);
61MODULE_PARM_DESC(pb_fnmode,
62 "Mode of fn key on PowerBooks (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)");
63
64/* 59/*
65 * Input submission and I/O error handler. 60 * Input submission and I/O error handler.
66 */ 61 */
@@ -106,18 +101,18 @@ static void hid_reset(struct work_struct *work)
106 101
107 if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) { 102 if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) {
108 dev_dbg(&usbhid->intf->dev, "clear halt\n"); 103 dev_dbg(&usbhid->intf->dev, "clear halt\n");
109 rc = usb_clear_halt(to_usb_device(hid->dev), usbhid->urbin->pipe); 104 rc = usb_clear_halt(hid_to_usb_dev(hid), usbhid->urbin->pipe);
110 clear_bit(HID_CLEAR_HALT, &usbhid->iofl); 105 clear_bit(HID_CLEAR_HALT, &usbhid->iofl);
111 hid_start_in(hid); 106 hid_start_in(hid);
112 } 107 }
113 108
114 else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) { 109 else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) {
115 dev_dbg(&usbhid->intf->dev, "resetting device\n"); 110 dev_dbg(&usbhid->intf->dev, "resetting device\n");
116 rc = rc_lock = usb_lock_device_for_reset(to_usb_device(hid->dev), usbhid->intf); 111 rc = rc_lock = usb_lock_device_for_reset(hid_to_usb_dev(hid), usbhid->intf);
117 if (rc_lock >= 0) { 112 if (rc_lock >= 0) {
118 rc = usb_reset_composite_device(to_usb_device(hid->dev), usbhid->intf); 113 rc = usb_reset_composite_device(hid_to_usb_dev(hid), usbhid->intf);
119 if (rc_lock) 114 if (rc_lock)
120 usb_unlock_device(to_usb_device(hid->dev)); 115 usb_unlock_device(hid_to_usb_dev(hid));
121 } 116 }
122 clear_bit(HID_RESET_PENDING, &usbhid->iofl); 117 clear_bit(HID_RESET_PENDING, &usbhid->iofl);
123 } 118 }
@@ -129,8 +124,8 @@ static void hid_reset(struct work_struct *work)
129 break; 124 break;
130 default: 125 default:
131 err("can't reset device, %s-%s/input%d, status %d", 126 err("can't reset device, %s-%s/input%d, status %d",
132 to_usb_device(hid->dev)->bus->bus_name, 127 hid_to_usb_dev(hid)->bus->bus_name,
133 to_usb_device(hid->dev)->devpath, 128 hid_to_usb_dev(hid)->devpath,
134 usbhid->ifnum, rc); 129 usbhid->ifnum, rc);
135 /* FALLTHROUGH */ 130 /* FALLTHROUGH */
136 case -EHOSTUNREACH: 131 case -EHOSTUNREACH:
@@ -217,8 +212,8 @@ static void hid_irq_in(struct urb *urb)
217 clear_bit(HID_IN_RUNNING, &usbhid->iofl); 212 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
218 if (status != -EPERM) { 213 if (status != -EPERM) {
219 err("can't resubmit intr, %s-%s/input%d, status %d", 214 err("can't resubmit intr, %s-%s/input%d, status %d",
220 to_usb_device(hid->dev)->bus->bus_name, 215 hid_to_usb_dev(hid)->bus->bus_name,
221 to_usb_device(hid->dev)->devpath, 216 hid_to_usb_dev(hid)->devpath,
222 usbhid->ifnum, status); 217 usbhid->ifnum, status);
223 hid_io_error(hid); 218 hid_io_error(hid);
224 } 219 }
@@ -251,7 +246,7 @@ static int hid_submit_out(struct hid_device *hid)
251 246
252 hid_output_report(report, usbhid->outbuf); 247 hid_output_report(report, usbhid->outbuf);
253 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); 248 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0);
254 usbhid->urbout->dev = to_usb_device(hid->dev); 249 usbhid->urbout->dev = hid_to_usb_dev(hid);
255 250
256 dbg("submitting out urb"); 251 dbg("submitting out urb");
257 252
@@ -276,13 +271,13 @@ static int hid_submit_ctrl(struct hid_device *hid)
276 len = ((report->size - 1) >> 3) + 1 + (report->id > 0); 271 len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
277 if (dir == USB_DIR_OUT) { 272 if (dir == USB_DIR_OUT) {
278 hid_output_report(report, usbhid->ctrlbuf); 273 hid_output_report(report, usbhid->ctrlbuf);
279 usbhid->urbctrl->pipe = usb_sndctrlpipe(to_usb_device(hid->dev), 0); 274 usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0);
280 usbhid->urbctrl->transfer_buffer_length = len; 275 usbhid->urbctrl->transfer_buffer_length = len;
281 } else { 276 } else {
282 int maxpacket, padlen; 277 int maxpacket, padlen;
283 278
284 usbhid->urbctrl->pipe = usb_rcvctrlpipe(to_usb_device(hid->dev), 0); 279 usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0);
285 maxpacket = usb_maxpacket(to_usb_device(hid->dev), usbhid->urbctrl->pipe, 0); 280 maxpacket = usb_maxpacket(hid_to_usb_dev(hid), usbhid->urbctrl->pipe, 0);
286 if (maxpacket > 0) { 281 if (maxpacket > 0) {
287 padlen = (len + maxpacket - 1) / maxpacket; 282 padlen = (len + maxpacket - 1) / maxpacket;
288 padlen *= maxpacket; 283 padlen *= maxpacket;
@@ -292,7 +287,7 @@ static int hid_submit_ctrl(struct hid_device *hid)
292 padlen = 0; 287 padlen = 0;
293 usbhid->urbctrl->transfer_buffer_length = padlen; 288 usbhid->urbctrl->transfer_buffer_length = padlen;
294 } 289 }
295 usbhid->urbctrl->dev = to_usb_device(hid->dev); 290 usbhid->urbctrl->dev = hid_to_usb_dev(hid);
296 291
297 usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir; 292 usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;
298 usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT; 293 usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT;
@@ -582,6 +577,7 @@ void usbhid_init_reports(struct hid_device *hid)
582} 577}
583 578
584#define USB_VENDOR_ID_GTCO 0x078c 579#define USB_VENDOR_ID_GTCO 0x078c
580#define USB_VENDOR_ID_GTCO_IPANEL_2 0x5543
585#define USB_DEVICE_ID_GTCO_90 0x0090 581#define USB_DEVICE_ID_GTCO_90 0x0090
586#define USB_DEVICE_ID_GTCO_100 0x0100 582#define USB_DEVICE_ID_GTCO_100 0x0100
587#define USB_DEVICE_ID_GTCO_101 0x0101 583#define USB_DEVICE_ID_GTCO_101 0x0101
@@ -627,6 +623,8 @@ void usbhid_init_reports(struct hid_device *hid)
627#define USB_DEVICE_ID_GTCO_1004 0x1004 623#define USB_DEVICE_ID_GTCO_1004 0x1004
628#define USB_DEVICE_ID_GTCO_1005 0x1005 624#define USB_DEVICE_ID_GTCO_1005 0x1005
629#define USB_DEVICE_ID_GTCO_1006 0x1006 625#define USB_DEVICE_ID_GTCO_1006 0x1006
626#define USB_DEVICE_ID_GTCO_8 0x0008
627#define USB_DEVICE_ID_GTCO_d 0x000d
630 628
631#define USB_VENDOR_ID_WACOM 0x056a 629#define USB_VENDOR_ID_WACOM 0x056a
632 630
@@ -791,6 +789,9 @@ void usbhid_init_reports(struct hid_device *hid)
791#define USB_VENDOR_ID_LOGITECH 0x046d 789#define USB_VENDOR_ID_LOGITECH 0x046d
792#define USB_DEVICE_ID_LOGITECH_USB_RECEIVER 0xc101 790#define USB_DEVICE_ID_LOGITECH_USB_RECEIVER 0xc101
793 791
792#define USB_VENDOR_ID_IMATION 0x0718
793#define USB_DEVICE_ID_DISC_STAKKA 0xd000
794
794/* 795/*
795 * Alphabetically sorted blacklist by quirk type. 796 * Alphabetically sorted blacklist by quirk type.
796 */ 797 */
@@ -875,6 +876,9 @@ static const struct hid_blacklist {
875 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE }, 876 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE },
876 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE }, 877 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE },
877 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE }, 878 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE },
879 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_8, HID_QUIRK_IGNORE },
880 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_d, HID_QUIRK_IGNORE },
881 { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE },
878 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, 882 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
879 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE }, 883 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE },
880 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE }, 884 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE },
@@ -951,7 +955,7 @@ static const struct hid_blacklist {
951 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD}, 955 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
952 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_POWERBOOK_HAS_FN }, 956 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
953 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN }, 957 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
954 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN }, 958 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
955 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN }, 959 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
956 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN }, 960 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN },
957 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN }, 961 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN },
@@ -1187,7 +1191,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1187 1191
1188 hid->version = le16_to_cpu(hdesc->bcdHID); 1192 hid->version = le16_to_cpu(hdesc->bcdHID);
1189 hid->country = hdesc->bCountryCode; 1193 hid->country = hdesc->bCountryCode;
1190 hid->dev = &dev->dev; 1194 hid->dev = &intf->dev;
1191 usbhid->intf = intf; 1195 usbhid->intf = intf;
1192 usbhid->ifnum = interface->desc.bInterfaceNumber; 1196 usbhid->ifnum = interface->desc.bInterfaceNumber;
1193 1197
@@ -1237,10 +1241,6 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1237 hid->hiddev_hid_event = hiddev_hid_event; 1241 hid->hiddev_hid_event = hiddev_hid_event;
1238 hid->hiddev_report_event = hiddev_report_event; 1242 hid->hiddev_report_event = hiddev_report_event;
1239#endif 1243#endif
1240#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
1241 hid->pb_fnmode = usbhid_pb_fnmode;
1242#endif
1243
1244 return hid; 1244 return hid;
1245 1245
1246fail: 1246fail:
@@ -1282,7 +1282,7 @@ static void hid_disconnect(struct usb_interface *intf)
1282 usb_free_urb(usbhid->urbctrl); 1282 usb_free_urb(usbhid->urbctrl);
1283 usb_free_urb(usbhid->urbout); 1283 usb_free_urb(usbhid->urbout);
1284 1284
1285 hid_free_buffers(to_usb_device(hid->dev), hid); 1285 hid_free_buffers(hid_to_usb_dev(hid), hid);
1286 hid_free_device(hid); 1286 hid_free_device(hid);
1287} 1287}
1288 1288
diff --git a/drivers/usb/input/hid-ff.c b/drivers/usb/input/hid-ff.c
index f8f660ee3f..59ed65e7a6 100644
--- a/drivers/usb/input/hid-ff.c
+++ b/drivers/usb/input/hid-ff.c
@@ -33,6 +33,7 @@
33#include <linux/usb.h> 33#include <linux/usb.h>
34 34
35#include <linux/hid.h> 35#include <linux/hid.h>
36#include "usbhid.h"
36 37
37/* 38/*
38 * This table contains pointers to initializers. To add support for new 39 * This table contains pointers to initializers. To add support for new
@@ -70,8 +71,8 @@ static struct hid_ff_initializer inits[] = {
70int hid_ff_init(struct hid_device* hid) 71int hid_ff_init(struct hid_device* hid)
71{ 72{
72 struct hid_ff_initializer *init; 73 struct hid_ff_initializer *init;
73 int vendor = le16_to_cpu(to_usb_device(hid->dev)->descriptor.idVendor); 74 int vendor = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idVendor);
74 int product = le16_to_cpu(to_usb_device(hid->dev)->descriptor.idProduct); 75 int product = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idProduct);
75 76
76 for (init = inits; init->idVendor; init++) 77 for (init = inits; init->idVendor; init++)
77 if (init->idVendor == vendor && init->idProduct == product) 78 if (init->idVendor == vendor && init->idProduct == product)
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index 114d6c9f64..a8b3d66cd4 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -384,7 +384,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
384 struct hiddev_list *list = file->private_data; 384 struct hiddev_list *list = file->private_data;
385 struct hiddev *hiddev = list->hiddev; 385 struct hiddev *hiddev = list->hiddev;
386 struct hid_device *hid = hiddev->hid; 386 struct hid_device *hid = hiddev->hid;
387 struct usb_device *dev = to_usb_device(hid->dev); 387 struct usb_device *dev = hid_to_usb_dev(hid);
388 struct hiddev_collection_info cinfo; 388 struct hiddev_collection_info cinfo;
389 struct hiddev_report_info rinfo; 389 struct hiddev_report_info rinfo;
390 struct hiddev_field_info finfo; 390 struct hiddev_field_info finfo;
diff --git a/drivers/usb/input/usbhid.h b/drivers/usb/input/usbhid.h
index 830107e525..0023f96d42 100644
--- a/drivers/usb/input/usbhid.h
+++ b/drivers/usb/input/usbhid.h
@@ -80,5 +80,8 @@ struct usbhid_device {
80 80
81}; 81};
82 82
83#define hid_to_usb_dev(hid_dev) \
84 container_of(hid_dev->dev->parent, struct usb_device, dev)
85
83#endif 86#endif
84 87
diff --git a/drivers/usb/input/usbtouchscreen.c b/drivers/usb/input/usbtouchscreen.c
index 7f3c57da9b..86e37a20f8 100644
--- a/drivers/usb/input/usbtouchscreen.c
+++ b/drivers/usb/input/usbtouchscreen.c
@@ -66,7 +66,7 @@ struct usbtouch_device_info {
66 66
67 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len); 67 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
68 int (*get_pkt_len) (unsigned char *pkt, int len); 68 int (*get_pkt_len) (unsigned char *pkt, int len);
69 int (*read_data) (unsigned char *pkt, int *x, int *y, int *touch, int *press); 69 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
70 int (*init) (struct usbtouch_usb *usbtouch); 70 int (*init) (struct usbtouch_usb *usbtouch);
71}; 71};
72 72
@@ -85,6 +85,9 @@ struct usbtouch_usb {
85 struct usbtouch_device_info *type; 85 struct usbtouch_device_info *type;
86 char name[128]; 86 char name[128];
87 char phys[64]; 87 char phys[64];
88
89 int x, y;
90 int touch, press;
88}; 91};
89 92
90 93
@@ -161,14 +164,14 @@ static struct usb_device_id usbtouch_devices[] = {
161#define EGALAX_PKT_TYPE_REPT 0x80 164#define EGALAX_PKT_TYPE_REPT 0x80
162#define EGALAX_PKT_TYPE_DIAG 0x0A 165#define EGALAX_PKT_TYPE_DIAG 0x0A
163 166
164static int egalax_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 167static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
165{ 168{
166 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT) 169 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
167 return 0; 170 return 0;
168 171
169 *x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F); 172 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
170 *y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F); 173 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
171 *touch = pkt[0] & 0x01; 174 dev->touch = pkt[0] & 0x01;
172 175
173 return 1; 176 return 1;
174} 177}
@@ -195,11 +198,11 @@ static int egalax_get_pkt_len(unsigned char *buf, int len)
195 * PanJit Part 198 * PanJit Part
196 */ 199 */
197#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT 200#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
198static int panjit_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 201static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
199{ 202{
200 *x = ((pkt[2] & 0x0F) << 8) | pkt[1]; 203 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
201 *y = ((pkt[4] & 0x0F) << 8) | pkt[3]; 204 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
202 *touch = pkt[0] & 0x01; 205 dev->touch = pkt[0] & 0x01;
203 206
204 return 1; 207 return 1;
205} 208}
@@ -215,11 +218,11 @@ static int panjit_read_data(unsigned char *pkt, int *x, int *y, int *touch, int
215#define MTOUCHUSB_RESET 7 218#define MTOUCHUSB_RESET 7
216#define MTOUCHUSB_REQ_CTRLLR_ID 10 219#define MTOUCHUSB_REQ_CTRLLR_ID 10
217 220
218static int mtouch_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 221static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
219{ 222{
220 *x = (pkt[8] << 8) | pkt[7]; 223 dev->x = (pkt[8] << 8) | pkt[7];
221 *y = (pkt[10] << 8) | pkt[9]; 224 dev->y = (pkt[10] << 8) | pkt[9];
222 *touch = (pkt[2] & 0x40) ? 1 : 0; 225 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
223 226
224 return 1; 227 return 1;
225} 228}
@@ -260,14 +263,32 @@ static int mtouch_init(struct usbtouch_usb *usbtouch)
260 * ITM Part 263 * ITM Part
261 */ 264 */
262#ifdef CONFIG_USB_TOUCHSCREEN_ITM 265#ifdef CONFIG_USB_TOUCHSCREEN_ITM
263static int itm_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 266static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
264{ 267{
265 *x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F); 268 int touch;
266 *y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F); 269 /*
267 *press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F); 270 * ITM devices report invalid x/y data if not touched.
268 *touch = ~pkt[7] & 0x20; 271 * if the screen was touched before but is not touched any more
272 * report touch as 0 with the last valid x/y data once. then stop
273 * reporting data until touched again.
274 */
275 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
276
277 touch = ~pkt[7] & 0x20;
278 if (!touch) {
279 if (dev->touch) {
280 dev->touch = 0;
281 return 1;
282 }
269 283
270 return *touch; 284 return 0;
285 }
286
287 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
288 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
289 dev->touch = touch;
290
291 return 1;
271} 292}
272#endif 293#endif
273 294
@@ -276,7 +297,7 @@ static int itm_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *pr
276 * eTurboTouch part 297 * eTurboTouch part
277 */ 298 */
278#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO 299#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
279static int eturbo_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 300static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
280{ 301{
281 unsigned int shift; 302 unsigned int shift;
282 303
@@ -285,9 +306,9 @@ static int eturbo_read_data(unsigned char *pkt, int *x, int *y, int *touch, int
285 return 0; 306 return 0;
286 307
287 shift = (6 - (pkt[0] & 0x03)); 308 shift = (6 - (pkt[0] & 0x03));
288 *x = ((pkt[3] << 7) | pkt[4]) >> shift; 309 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
289 *y = ((pkt[1] << 7) | pkt[2]) >> shift; 310 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
290 *touch = (pkt[0] & 0x10) ? 1 : 0; 311 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
291 312
292 return 1; 313 return 1;
293} 314}
@@ -307,14 +328,14 @@ static int eturbo_get_pkt_len(unsigned char *buf, int len)
307 * Gunze part 328 * Gunze part
308 */ 329 */
309#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE 330#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
310static int gunze_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 331static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
311{ 332{
312 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80)) 333 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
313 return 0; 334 return 0;
314 335
315 *x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F); 336 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
316 *y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F); 337 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
317 *touch = pkt[0] & 0x20; 338 dev->touch = pkt[0] & 0x20;
318 339
319 return 1; 340 return 1;
320} 341}
@@ -383,11 +404,11 @@ static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
383} 404}
384 405
385 406
386static int dmc_tsc10_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 407static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
387{ 408{
388 *x = ((pkt[2] & 0x03) << 8) | pkt[1]; 409 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
389 *y = ((pkt[4] & 0x03) << 8) | pkt[3]; 410 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
390 *touch = pkt[0] & 0x01; 411 dev->touch = pkt[0] & 0x01;
391 412
392 return 1; 413 return 1;
393} 414}
@@ -492,23 +513,22 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
492static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch, 513static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
493 unsigned char *pkt, int len) 514 unsigned char *pkt, int len)
494{ 515{
495 int x, y, touch, press;
496 struct usbtouch_device_info *type = usbtouch->type; 516 struct usbtouch_device_info *type = usbtouch->type;
497 517
498 if (!type->read_data(pkt, &x, &y, &touch, &press)) 518 if (!type->read_data(usbtouch, pkt))
499 return; 519 return;
500 520
501 input_report_key(usbtouch->input, BTN_TOUCH, touch); 521 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
502 522
503 if (swap_xy) { 523 if (swap_xy) {
504 input_report_abs(usbtouch->input, ABS_X, y); 524 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
505 input_report_abs(usbtouch->input, ABS_Y, x); 525 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
506 } else { 526 } else {
507 input_report_abs(usbtouch->input, ABS_X, x); 527 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
508 input_report_abs(usbtouch->input, ABS_Y, y); 528 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
509 } 529 }
510 if (type->max_press) 530 if (type->max_press)
511 input_report_abs(usbtouch->input, ABS_PRESSURE, press); 531 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
512 input_sync(usbtouch->input); 532 input_sync(usbtouch->input);
513} 533}
514 534
diff --git a/drivers/usb/input/wacom_sys.c b/drivers/usb/input/wacom_sys.c
index e7cc20ab81..12b42746de 100644
--- a/drivers/usb/input/wacom_sys.c
+++ b/drivers/usb/input/wacom_sys.c
@@ -159,13 +159,13 @@ void input_dev_i3s(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
159{ 159{
160 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); 160 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
161 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3); 161 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3);
162 input_set_abs_params(input_dev, ABS_RX, 0, 4097, 0, 0); 162 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
163} 163}
164 164
165void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 165void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
166{ 166{
167 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7); 167 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7);
168 input_set_abs_params(input_dev, ABS_RY, 0, 4097, 0, 0); 168 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
169} 169}
170 170
171void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 171void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
diff --git a/drivers/usb/input/wacom_wac.c b/drivers/usb/input/wacom_wac.c
index 92726fe893..4142e36730 100644
--- a/drivers/usb/input/wacom_wac.c
+++ b/drivers/usb/input/wacom_wac.c
@@ -209,13 +209,15 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
209 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02); 209 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
210 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04); 210 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04);
211 } 211 }
212 }
213
214 if (data[1] & 0x10)
215 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */ 212 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
213 }
216 else 214 else
217 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ 215 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
218 wacom_report_key(wcombo, wacom->tool[0], data[1] & 0x10); 216
217 if (data[1] & 0x10) /* only report prox-in when in area */
218 wacom_report_key(wcombo, wacom->tool[0], 1);
219 if (!(data[1] & 0x90)) /* report prox-out when physically out */
220 wacom_report_key(wcombo, wacom->tool[0], 0);
219 wacom_input_sync(wcombo); 221 wacom_input_sync(wcombo);
220 222
221 /* send pad data */ 223 /* send pad data */
@@ -405,7 +407,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
405 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40)) 407 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
406 return 0; 408 return 0;
407 409
408 if (wacom->features->type >= INTUOS3) { 410 if (wacom->features->type >= INTUOS3S) {
409 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1)); 411 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
410 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1)); 412 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
411 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); 413 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
@@ -423,7 +425,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
423 425
424 if (data[1] & 0x02) { 426 if (data[1] & 0x02) {
425 /* Rotation packet */ 427 /* Rotation packet */
426 if (wacom->features->type >= INTUOS3) { 428 if (wacom->features->type >= INTUOS3S) {
427 /* I3 marker pen rotation reported as wheel 429 /* I3 marker pen rotation reported as wheel
428 * due to valuator limitation 430 * due to valuator limitation
429 */ 431 */
@@ -547,11 +549,11 @@ static struct wacom_features wacom_features[] = {
547 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 63, GRAPHIRE }, 549 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 63, GRAPHIRE },
548 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 63, WACOM_G4 }, 550 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 63, WACOM_G4 },
549 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 63, WACOM_G4 }, 551 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 63, WACOM_G4 },
550 { "Wacom Volito", 8, 5104, 3712, 511, 0, GRAPHIRE }, 552 { "Wacom Volito", 8, 5104, 3712, 511, 63, GRAPHIRE },
551 { "Wacom PenStation2", 8, 3250, 2320, 255, 0, GRAPHIRE }, 553 { "Wacom PenStation2", 8, 3250, 2320, 255, 63, GRAPHIRE },
552 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 0, GRAPHIRE }, 554 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 63, GRAPHIRE },
553 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 0, GRAPHIRE }, 555 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 63, GRAPHIRE },
554 { "Wacom PenPartner2", 8, 3250, 2320, 255, 0, GRAPHIRE }, 556 { "Wacom PenPartner2", 8, 3250, 2320, 255, 63, GRAPHIRE },
555 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 63, INTUOS }, 557 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 63, INTUOS },
556 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, 558 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 63, INTUOS },
557 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 63, INTUOS }, 559 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 63, INTUOS },
@@ -580,7 +582,7 @@ static struct wacom_features wacom_features[] = {
580 { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 63, INTUOS3L }, 582 { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 63, INTUOS3L },
581 { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 63, INTUOS3L }, 583 { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 63, INTUOS3L },
582 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 }, 584 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 },
583 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 15, INTUOS3S }, 585 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S },
584 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ }, 586 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ },
585 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, 587 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 63, INTUOS },
586 { } 588 { }
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index 02cbb7fff2..a7932a72d2 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
281 /* Register backlight device */ 281 /* Register backlight device */
282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d", 282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
283 atomic_inc_return(&count_displays) - 1); 283 atomic_inc_return(&count_displays) - 1);
284 pdata->bd = backlight_device_register(bl_name, pdata, 284 pdata->bd = backlight_device_register(bl_name, NULL, NULL,
285 &appledisplay_bl_data); 285 &appledisplay_bl_data);
286 if (IS_ERR(pdata->bd)) { 286 if (IS_ERR(pdata->bd)) {
287 err("appledisplay: Backlight registration failed"); 287 err("appledisplay: Backlight registration failed");
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
index 6c7f3efb1d..b5332e679c 100644
--- a/drivers/usb/misc/auerswald.c
+++ b/drivers/usb/misc/auerswald.c
@@ -1376,7 +1376,7 @@ static int auerchar_open (struct inode *inode, struct file *file)
1376 } 1376 }
1377 1377
1378 /* we have access to the device. Now lets allocate memory */ 1378 /* we have access to the device. Now lets allocate memory */
1379 ccp = (pauerchar_t) kmalloc(sizeof(auerchar_t), GFP_KERNEL); 1379 ccp = kzalloc(sizeof(auerchar_t), GFP_KERNEL);
1380 if (ccp == NULL) { 1380 if (ccp == NULL) {
1381 err ("out of memory"); 1381 err ("out of memory");
1382 ret = -ENOMEM; 1382 ret = -ENOMEM;
@@ -1384,7 +1384,6 @@ static int auerchar_open (struct inode *inode, struct file *file)
1384 } 1384 }
1385 1385
1386 /* Initialize device descriptor */ 1386 /* Initialize device descriptor */
1387 memset( ccp, 0, sizeof(auerchar_t));
1388 init_MUTEX( &ccp->mutex); 1387 init_MUTEX( &ccp->mutex);
1389 init_MUTEX( &ccp->readmutex); 1388 init_MUTEX( &ccp->readmutex);
1390 auerbuf_init (&ccp->bufctl); 1389 auerbuf_init (&ccp->bufctl);
@@ -1912,14 +1911,13 @@ static int auerswald_probe (struct usb_interface *intf,
1912 return -ENODEV; 1911 return -ENODEV;
1913 1912
1914 /* allocate memory for our device and initialize it */ 1913 /* allocate memory for our device and initialize it */
1915 cp = kmalloc (sizeof(auerswald_t), GFP_KERNEL); 1914 cp = kzalloc (sizeof(auerswald_t), GFP_KERNEL);
1916 if (cp == NULL) { 1915 if (cp == NULL) {
1917 err ("out of memory"); 1916 err ("out of memory");
1918 goto pfail; 1917 goto pfail;
1919 } 1918 }
1920 1919
1921 /* Initialize device descriptor */ 1920 /* Initialize device descriptor */
1922 memset (cp, 0, sizeof(auerswald_t));
1923 init_MUTEX (&cp->mutex); 1921 init_MUTEX (&cp->mutex);
1924 cp->usbdev = usbdev; 1922 cp->usbdev = usbdev;
1925 auerchain_init (&cp->controlchain); 1923 auerchain_init (&cp->controlchain);
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 18b1925032..41c0161abd 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -40,6 +40,7 @@
40#include <linux/init.h> 40#include <linux/init.h>
41#include <linux/list.h> 41#include <linux/list.h>
42#include <linux/ioctl.h> 42#include <linux/ioctl.h>
43#include <linux/pci_ids.h>
43#include <linux/slab.h> 44#include <linux/slab.h>
44#include <linux/module.h> 45#include <linux/module.h>
45#include <linux/kref.h> 46#include <linux/kref.h>
@@ -51,6 +52,10 @@ MODULE_AUTHOR("Tony Olech");
51MODULE_DESCRIPTION("FTDI ELAN driver"); 52MODULE_DESCRIPTION("FTDI ELAN driver");
52MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
53#define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444) 54#define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
55static int distrust_firmware = 1;
56module_param(distrust_firmware, bool, 0);
57MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
58 "t setup");
54extern struct platform_driver u132_platform_driver; 59extern struct platform_driver u132_platform_driver;
55static struct workqueue_struct *status_queue; 60static struct workqueue_struct *status_queue;
56static struct workqueue_struct *command_queue; 61static struct workqueue_struct *command_queue;
@@ -66,7 +71,9 @@ static struct list_head ftdi_static_list;
66* end of the global variables protected by ftdi_module_lock 71* end of the global variables protected by ftdi_module_lock
67*/ 72*/
68#include "usb_u132.h" 73#include "usb_u132.h"
69#define TD_DEVNOTRESP 5 74#include <asm/io.h>
75#include "../core/hcd.h"
76#include "../host/ohci.h"
70/* Define these values to match your devices*/ 77/* Define these values to match your devices*/
71#define USB_FTDI_ELAN_VENDOR_ID 0x0403 78#define USB_FTDI_ELAN_VENDOR_ID 0x0403
72#define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea 79#define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea
@@ -551,7 +558,7 @@ static void ftdi_elan_status_work(struct work_struct *work)
551 } else { 558 } else {
552 dev_err(&ftdi->udev->dev, "initialized failed - trying " 559 dev_err(&ftdi->udev->dev, "initialized failed - trying "
553 "again in 10 seconds\n"); 560 "again in 10 seconds\n");
554 work_delay_in_msec = 10 *1000; 561 work_delay_in_msec = 1 *1000;
555 } 562 }
556 } else if (ftdi->registered == 0) { 563 } else if (ftdi->registered == 0) {
557 work_delay_in_msec = 10; 564 work_delay_in_msec = 10;
@@ -2288,82 +2295,288 @@ static int ftdi_elan_checkingPCI(struct usb_ftdi *ftdi)
2288 } 2295 }
2289} 2296}
2290 2297
2291static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi) 2298
2299#define ftdi_read_pcimem(ftdi, member, data) ftdi_elan_read_pcimem(ftdi, \
2300 offsetof(struct ohci_regs, member), 0, data);
2301#define ftdi_write_pcimem(ftdi, member, data) ftdi_elan_write_pcimem(ftdi, \
2302 offsetof(struct ohci_regs, member), 0, data);
2303#define OHCI_QUIRK_AMD756 0x01
2304#define OHCI_QUIRK_SUPERIO 0x02
2305#define OHCI_QUIRK_INITRESET 0x04
2306#define OHCI_BIG_ENDIAN 0x08
2307#define OHCI_QUIRK_ZFMICRO 0x10
2308#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
2309#define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
2310 OHCI_INTR_WDH)
2311static int ftdi_elan_check_controller(struct usb_ftdi *ftdi, int quirk)
2312{
2313 int devices = 0;
2314 int retval;
2315 u32 hc_control;
2316 int num_ports;
2317 u32 control;
2318 u32 rh_a = -1;
2319 u32 status;
2320 u32 fminterval;
2321 u32 hc_fminterval;
2322 u32 periodicstart;
2323 u32 cmdstatus;
2324 u32 roothub_a;
2325 int mask = OHCI_INTR_INIT;
2326 int sleep_time = 0;
2327 int reset_timeout = 30; /* ... allow extra time */
2328 int temp;
2329 retval = ftdi_write_pcimem(ftdi, intrdisable, OHCI_INTR_MIE);
2330 if (retval)
2331 return retval;
2332 retval = ftdi_read_pcimem(ftdi, control, &control);
2333 if (retval)
2334 return retval;
2335 retval = ftdi_read_pcimem(ftdi, roothub.a, &rh_a);
2336 if (retval)
2337 return retval;
2338 num_ports = rh_a & RH_A_NDP;
2339 retval = ftdi_read_pcimem(ftdi, fminterval, &hc_fminterval);
2340 if (retval)
2341 return retval;
2342 hc_fminterval &= 0x3fff;
2343 if (hc_fminterval != FI) {
2344 }
2345 hc_fminterval |= FSMP(hc_fminterval) << 16;
2346 retval = ftdi_read_pcimem(ftdi, control, &hc_control);
2347 if (retval)
2348 return retval;
2349 switch (hc_control & OHCI_CTRL_HCFS) {
2350 case OHCI_USB_OPER:
2351 sleep_time = 0;
2352 break;
2353 case OHCI_USB_SUSPEND:
2354 case OHCI_USB_RESUME:
2355 hc_control &= OHCI_CTRL_RWC;
2356 hc_control |= OHCI_USB_RESUME;
2357 sleep_time = 10;
2358 break;
2359 default:
2360 hc_control &= OHCI_CTRL_RWC;
2361 hc_control |= OHCI_USB_RESET;
2362 sleep_time = 50;
2363 break;
2364 }
2365 retval = ftdi_write_pcimem(ftdi, control, hc_control);
2366 if (retval)
2367 return retval;
2368 retval = ftdi_read_pcimem(ftdi, control, &control);
2369 if (retval)
2370 return retval;
2371 msleep(sleep_time);
2372 retval = ftdi_read_pcimem(ftdi, roothub.a, &roothub_a);
2373 if (retval)
2374 return retval;
2375 if (!(roothub_a & RH_A_NPS)) { /* power down each port */
2376 for (temp = 0; temp < num_ports; temp++) {
2377 retval = ftdi_write_pcimem(ftdi,
2378 roothub.portstatus[temp], RH_PS_LSDA);
2379 if (retval)
2380 return retval;
2381 }
2382 }
2383 retval = ftdi_read_pcimem(ftdi, control, &control);
2384 if (retval)
2385 return retval;
2386 retry:retval = ftdi_read_pcimem(ftdi, cmdstatus, &status);
2387 if (retval)
2388 return retval;
2389 retval = ftdi_write_pcimem(ftdi, cmdstatus, OHCI_HCR);
2390 if (retval)
2391 return retval;
2392 extra:{
2393 retval = ftdi_read_pcimem(ftdi, cmdstatus, &status);
2394 if (retval)
2395 return retval;
2396 if (0 != (status & OHCI_HCR)) {
2397 if (--reset_timeout == 0) {
2398 dev_err(&ftdi->udev->dev, "USB HC reset timed o"
2399 "ut!\n");
2400 return -ENODEV;
2401 } else {
2402 msleep(5);
2403 goto extra;
2404 }
2405 }
2406 }
2407 if (quirk & OHCI_QUIRK_INITRESET) {
2408 retval = ftdi_write_pcimem(ftdi, control, hc_control);
2409 if (retval)
2410 return retval;
2411 retval = ftdi_read_pcimem(ftdi, control, &control);
2412 if (retval)
2413 return retval;
2414 }
2415 retval = ftdi_write_pcimem(ftdi, ed_controlhead, 0x00000000);
2416 if (retval)
2417 return retval;
2418 retval = ftdi_write_pcimem(ftdi, ed_bulkhead, 0x11000000);
2419 if (retval)
2420 return retval;
2421 retval = ftdi_write_pcimem(ftdi, hcca, 0x00000000);
2422 if (retval)
2423 return retval;
2424 retval = ftdi_read_pcimem(ftdi, fminterval, &fminterval);
2425 if (retval)
2426 return retval;
2427 retval = ftdi_write_pcimem(ftdi, fminterval,
2428 ((fminterval & FIT) ^ FIT) | hc_fminterval);
2429 if (retval)
2430 return retval;
2431 retval = ftdi_write_pcimem(ftdi, periodicstart,
2432 ((9 *hc_fminterval) / 10) & 0x3fff);
2433 if (retval)
2434 return retval;
2435 retval = ftdi_read_pcimem(ftdi, fminterval, &fminterval);
2436 if (retval)
2437 return retval;
2438 retval = ftdi_read_pcimem(ftdi, periodicstart, &periodicstart);
2439 if (retval)
2440 return retval;
2441 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
2442 if (!(quirk & OHCI_QUIRK_INITRESET)) {
2443 quirk |= OHCI_QUIRK_INITRESET;
2444 goto retry;
2445 } else
2446 dev_err(&ftdi->udev->dev, "init err(%08x %04x)\n",
2447 fminterval, periodicstart);
2448 } /* start controller operations */
2449 hc_control &= OHCI_CTRL_RWC;
2450 hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
2451 retval = ftdi_write_pcimem(ftdi, control, hc_control);
2452 if (retval)
2453 return retval;
2454 retval = ftdi_write_pcimem(ftdi, cmdstatus, OHCI_BLF);
2455 if (retval)
2456 return retval;
2457 retval = ftdi_read_pcimem(ftdi, cmdstatus, &cmdstatus);
2458 if (retval)
2459 return retval;
2460 retval = ftdi_read_pcimem(ftdi, control, &control);
2461 if (retval)
2462 return retval;
2463 retval = ftdi_write_pcimem(ftdi, roothub.status, RH_HS_DRWE);
2464 if (retval)
2465 return retval;
2466 retval = ftdi_write_pcimem(ftdi, intrstatus, mask);
2467 if (retval)
2468 return retval;
2469 retval = ftdi_write_pcimem(ftdi, intrdisable,
2470 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
2471 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
2472 OHCI_INTR_SO);
2473 if (retval)
2474 return retval; /* handle root hub init quirks ... */
2475 retval = ftdi_read_pcimem(ftdi, roothub.a, &roothub_a);
2476 if (retval)
2477 return retval;
2478 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
2479 if (quirk & OHCI_QUIRK_SUPERIO) {
2480 roothub_a |= RH_A_NOCP;
2481 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
2482 retval = ftdi_write_pcimem(ftdi, roothub.a, roothub_a);
2483 if (retval)
2484 return retval;
2485 } else if ((quirk & OHCI_QUIRK_AMD756) || distrust_firmware) {
2486 roothub_a |= RH_A_NPS;
2487 retval = ftdi_write_pcimem(ftdi, roothub.a, roothub_a);
2488 if (retval)
2489 return retval;
2490 }
2491 retval = ftdi_write_pcimem(ftdi, roothub.status, RH_HS_LPSC);
2492 if (retval)
2493 return retval;
2494 retval = ftdi_write_pcimem(ftdi, roothub.b,
2495 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
2496 if (retval)
2497 return retval;
2498 retval = ftdi_read_pcimem(ftdi, control, &control);
2499 if (retval)
2500 return retval;
2501 mdelay((roothub_a >> 23) & 0x1fe);
2502 for (temp = 0; temp < num_ports; temp++) {
2503 u32 portstatus;
2504 retval = ftdi_read_pcimem(ftdi, roothub.portstatus[temp],
2505 &portstatus);
2506 if (retval)
2507 return retval;
2508 if (1 & portstatus)
2509 devices += 1;
2510 }
2511 return devices;
2512}
2513
2514static int ftdi_elan_setup_controller(struct usb_ftdi *ftdi, int fn)
2292{ 2515{
2293 u32 latence_timer; 2516 u32 latence_timer;
2294 u32 controlreg;
2295 int UxxxStatus; 2517 int UxxxStatus;
2296 u32 pcidata; 2518 u32 pcidata;
2297 int reg = 0; 2519 int reg = 0;
2298 int foundOHCI = 0; 2520 int activePCIfn = fn << 8;
2299 u8 fn; 2521 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800);
2300 int activePCIfn = 0;
2301 u32 pciVID = 0;
2302 u32 pciPID = 0;
2303 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2304 if (UxxxStatus)
2305 return UxxxStatus;
2306 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000000L);
2307 if (UxxxStatus)
2308 return UxxxStatus;
2309 msleep(750);
2310 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x100);
2311 if (UxxxStatus) 2522 if (UxxxStatus)
2312 return UxxxStatus; 2523 return UxxxStatus;
2313 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x500); 2524 reg = 16;
2525 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
2526 0xFFFFFFFF);
2314 if (UxxxStatus) 2527 if (UxxxStatus)
2315 return UxxxStatus; 2528 return UxxxStatus;
2316 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); 2529 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2530 &pcidata);
2317 if (UxxxStatus) 2531 if (UxxxStatus)
2318 return UxxxStatus; 2532 return UxxxStatus;
2319 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020CL | 0x000); 2533 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
2534 0xF0000000);
2320 if (UxxxStatus) 2535 if (UxxxStatus)
2321 return UxxxStatus; 2536 return UxxxStatus;
2322 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020DL | 0x000); 2537 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2538 &pcidata);
2323 if (UxxxStatus) 2539 if (UxxxStatus)
2324 return UxxxStatus; 2540 return UxxxStatus;
2325 msleep(250); 2541 reg = 12;
2326 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020FL | 0x000); 2542 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2543 &latence_timer);
2327 if (UxxxStatus) 2544 if (UxxxStatus)
2328 return UxxxStatus; 2545 return UxxxStatus;
2329 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); 2546 latence_timer &= 0xFFFF00FF;
2547 latence_timer |= 0x00001600;
2548 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
2549 latence_timer);
2330 if (UxxxStatus) 2550 if (UxxxStatus)
2331 return UxxxStatus; 2551 return UxxxStatus;
2332 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x800); 2552 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2553 &pcidata);
2333 if (UxxxStatus) 2554 if (UxxxStatus)
2334 return UxxxStatus; 2555 return UxxxStatus;
2335 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); 2556 reg = 4;
2557 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
2558 0x06);
2336 if (UxxxStatus) 2559 if (UxxxStatus)
2337 return UxxxStatus; 2560 return UxxxStatus;
2338 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); 2561 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2562 &pcidata);
2339 if (UxxxStatus) 2563 if (UxxxStatus)
2340 return UxxxStatus; 2564 return UxxxStatus;
2341 msleep(1000); 2565 for (reg = 0; reg <= 0x54; reg += 4) {
2342 for (fn = 0; (fn < 4) && (!foundOHCI); fn++) { 2566 UxxxStatus = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2343 activePCIfn = fn << 8;
2344 ftdi->function = fn + 1;
2345 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2346 &pcidata);
2347 if (UxxxStatus) 2567 if (UxxxStatus)
2348 return UxxxStatus; 2568 return UxxxStatus;
2349 pciVID = pcidata & 0xFFFF;
2350 pciPID = (pcidata >> 16) & 0xFFFF;
2351 if ((pciVID == 0x1045) && (pciPID == 0xc861)) {
2352 foundOHCI = 1;
2353 } else if ((pciVID == 0x1033) && (pciPID == 0x0035)) {
2354 foundOHCI = 1;
2355 } else if ((pciVID == 0x10b9) && (pciPID == 0x5237)) {
2356 foundOHCI = 1;
2357 } else if ((pciVID == 0x11c1) && (pciPID == 0x5802)) {
2358 foundOHCI = 1;
2359 } else if ((pciVID == 0x11AB) && (pciPID == 0x1FA6)) {
2360 }
2361 }
2362 if (foundOHCI == 0) {
2363 return -ENXIO;
2364 } 2569 }
2365 ftdi->platform_data.vendor = pciVID; 2570 return 0;
2366 ftdi->platform_data.device = pciPID; 2571}
2572
2573static int ftdi_elan_close_controller(struct usb_ftdi *ftdi, int fn)
2574{
2575 u32 latence_timer;
2576 int UxxxStatus;
2577 u32 pcidata;
2578 int reg = 0;
2579 int activePCIfn = fn << 8;
2367 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800); 2580 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800);
2368 if (UxxxStatus) 2581 if (UxxxStatus)
2369 return UxxxStatus; 2582 return UxxxStatus;
@@ -2377,7 +2590,7 @@ static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi)
2377 if (UxxxStatus) 2590 if (UxxxStatus)
2378 return UxxxStatus; 2591 return UxxxStatus;
2379 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0, 2592 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
2380 0xF0000000); 2593 0x00000000);
2381 if (UxxxStatus) 2594 if (UxxxStatus)
2382 return UxxxStatus; 2595 return UxxxStatus;
2383 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, 2596 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
@@ -2401,7 +2614,7 @@ static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi)
2401 return UxxxStatus; 2614 return UxxxStatus;
2402 reg = 4; 2615 reg = 4;
2403 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00, 2616 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
2404 0x06); 2617 0x00);
2405 if (UxxxStatus) 2618 if (UxxxStatus)
2406 return UxxxStatus; 2619 return UxxxStatus;
2407 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, 2620 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
@@ -2411,159 +2624,139 @@ static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi)
2411 return 0; 2624 return 0;
2412} 2625}
2413 2626
2627static int ftdi_elan_found_controller(struct usb_ftdi *ftdi, int fn, int quirk)
2628{
2629 int result;
2630 int UxxxStatus;
2631 UxxxStatus = ftdi_elan_setup_controller(ftdi, fn);
2632 if (UxxxStatus)
2633 return UxxxStatus;
2634 result = ftdi_elan_check_controller(ftdi, quirk);
2635 UxxxStatus = ftdi_elan_close_controller(ftdi, fn);
2636 if (UxxxStatus)
2637 return UxxxStatus;
2638 return result;
2639}
2640
2641static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi)
2642{
2643 u32 controlreg;
2644 u8 sensebits;
2645 int UxxxStatus;
2646 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2647 if (UxxxStatus)
2648 return UxxxStatus;
2649 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000000L);
2650 if (UxxxStatus)
2651 return UxxxStatus;
2652 msleep(750);
2653 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x100);
2654 if (UxxxStatus)
2655 return UxxxStatus;
2656 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x500);
2657 if (UxxxStatus)
2658 return UxxxStatus;
2659 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2660 if (UxxxStatus)
2661 return UxxxStatus;
2662 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020CL | 0x000);
2663 if (UxxxStatus)
2664 return UxxxStatus;
2665 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020DL | 0x000);
2666 if (UxxxStatus)
2667 return UxxxStatus;
2668 msleep(250);
2669 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020FL | 0x000);
2670 if (UxxxStatus)
2671 return UxxxStatus;
2672 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2673 if (UxxxStatus)
2674 return UxxxStatus;
2675 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x800);
2676 if (UxxxStatus)
2677 return UxxxStatus;
2678 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2679 if (UxxxStatus)
2680 return UxxxStatus;
2681 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2682 if (UxxxStatus)
2683 return UxxxStatus;
2684 msleep(1000);
2685 sensebits = (controlreg >> 16) & 0x000F;
2686 if (0x0D == sensebits)
2687 return 0;
2688 else
2689 return - ENXIO;
2690}
2691
2414static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi) 2692static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi)
2415{ 2693{
2694 int UxxxStatus;
2416 u32 pcidata; 2695 u32 pcidata;
2417 int U132Status; 2696 int reg = 0;
2418 int reg; 2697 u8 fn;
2419 int reset_repeat = 0; 2698 int activePCIfn = 0;
2420 do_reset:reg = 8; 2699 int max_devices = 0;
2421 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x0e, 0x01); 2700 int controllers = 0;
2422 if (U132Status) 2701 int unrecognized = 0;
2423 return U132Status; 2702 ftdi->function = 0;
2424 reset_check:{ 2703 for (fn = 0; (fn < 4); fn++) {
2425 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata); 2704 u32 pciVID = 0;
2426 if (U132Status) 2705 u32 pciPID = 0;
2427 return U132Status; 2706 int devices = 0;
2428 if (pcidata & 1) { 2707 activePCIfn = fn << 8;
2429 msleep(500); 2708 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2430 if (reset_repeat++ > 100) { 2709 &pcidata);
2431 reset_repeat = 0; 2710 if (UxxxStatus)
2432 goto do_reset; 2711 return UxxxStatus;
2433 } else 2712 pciVID = pcidata & 0xFFFF;
2434 goto reset_check; 2713 pciPID = (pcidata >> 16) & 0xFFFF;
2714 if ((pciVID == PCI_VENDOR_ID_OPTI) && (pciPID == 0xc861)) {
2715 devices = ftdi_elan_found_controller(ftdi, fn, 0);
2716 controllers += 1;
2717 } else if ((pciVID == PCI_VENDOR_ID_NEC) && (pciPID == 0x0035))
2718 {
2719 devices = ftdi_elan_found_controller(ftdi, fn, 0);
2720 controllers += 1;
2721 } else if ((pciVID == PCI_VENDOR_ID_AL) && (pciPID == 0x5237)) {
2722 devices = ftdi_elan_found_controller(ftdi, fn, 0);
2723 controllers += 1;
2724 } else if ((pciVID == PCI_VENDOR_ID_ATT) && (pciPID == 0x5802))
2725 {
2726 devices = ftdi_elan_found_controller(ftdi, fn, 0);
2727 controllers += 1;
2728 } else if (pciVID == PCI_VENDOR_ID_AMD && pciPID == 0x740c) {
2729 devices = ftdi_elan_found_controller(ftdi, fn,
2730 OHCI_QUIRK_AMD756);
2731 controllers += 1;
2732 } else if (pciVID == PCI_VENDOR_ID_COMPAQ && pciPID == 0xa0f8) {
2733 devices = ftdi_elan_found_controller(ftdi, fn,
2734 OHCI_QUIRK_ZFMICRO);
2735 controllers += 1;
2736 } else if (0 == pcidata) {
2737 } else
2738 unrecognized += 1;
2739 if (devices > max_devices) {
2740 max_devices = devices;
2741 ftdi->function = fn + 1;
2742 ftdi->platform_data.vendor = pciVID;
2743 ftdi->platform_data.device = pciPID;
2435 } 2744 }
2436 } 2745 }
2437 goto dump_regs; 2746 if (ftdi->function > 0) {
2438 msleep(500); 2747 UxxxStatus = ftdi_elan_setup_controller(ftdi,
2439 reg = 0x28; 2748 ftdi->function - 1);
2440 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x11000000); 2749 if (UxxxStatus)
2441 if (U132Status) 2750 return UxxxStatus;
2442 return U132Status; 2751 return 0;
2443 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata); 2752 } else if (controllers > 0) {
2444 if (U132Status) 2753 return -ENXIO;
2445 return U132Status; 2754 } else if (unrecognized > 0) {
2446 reg = 0x40; 2755 return -ENXIO;
2447 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x2edf); 2756 } else {
2448 if (U132Status) 2757 ftdi->enumerated = 0;
2449 return U132Status; 2758 return -ENXIO;
2450 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2451 if (U132Status)
2452 return U132Status;
2453 reg = 0x34;
2454 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x2edf2edf);
2455 if (U132Status)
2456 return U132Status;
2457 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2458 if (U132Status)
2459 return U132Status;
2460 reg = 4;
2461 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0xA0);
2462 if (U132Status)
2463 return U132Status;
2464 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2465 if (U132Status)
2466 return U132Status;
2467 msleep(250);
2468 reg = 8;
2469 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x0e, 0x04);
2470 if (U132Status)
2471 return U132Status;
2472 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2473 if (U132Status)
2474 return U132Status;
2475 reg = 0x28;
2476 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2477 if (U132Status)
2478 return U132Status;
2479 reg = 8;
2480 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2481 if (U132Status)
2482 return U132Status;
2483 reg = 0x48;
2484 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x00001200);
2485 if (U132Status)
2486 return U132Status;
2487 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2488 if (U132Status)
2489 return U132Status;
2490 reg = 0x54;
2491 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2492 if (U132Status)
2493 return U132Status;
2494 reg = 0x58;
2495 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2496 if (U132Status)
2497 return U132Status;
2498 reg = 0x34;
2499 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x28002edf);
2500 if (U132Status)
2501 return U132Status;
2502 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2503 if (U132Status)
2504 return U132Status;
2505 msleep(100);
2506 reg = 0x50;
2507 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x10000);
2508 if (U132Status)
2509 return U132Status;
2510 reg = 0x54;
2511 power_check:U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2512 if (U132Status)
2513 return U132Status;
2514 if (!(pcidata & 1)) {
2515 msleep(500);
2516 goto power_check;
2517 }
2518 msleep(3000);
2519 reg = 0x54;
2520 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2521 if (U132Status)
2522 return U132Status;
2523 reg = 0x58;
2524 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2525 if (U132Status)
2526 return U132Status;
2527 reg = 0x54;
2528 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x02);
2529 if (U132Status)
2530 return U132Status;
2531 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2532 if (U132Status)
2533 return U132Status;
2534 reg = 0x54;
2535 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x10);
2536 if (U132Status)
2537 return U132Status;
2538 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2539 if (U132Status)
2540 return U132Status;
2541 msleep(750);
2542 reg = 0x54;
2543 if (0) {
2544 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x02);
2545 if (U132Status)
2546 return U132Status;
2547 }
2548 if (0) {
2549 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2550 if (U132Status)
2551 return U132Status;
2552 }
2553 reg = 0x54;
2554 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2555 if (U132Status)
2556 return U132Status;
2557 reg = 0x58;
2558 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2559 if (U132Status)
2560 return U132Status;
2561 dump_regs:for (reg = 0; reg <= 0x54; reg += 4) {
2562 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2563 if (U132Status)
2564 return U132Status;
2565 } 2759 }
2566 return 0;
2567} 2760}
2568 2761
2569 2762
@@ -2688,6 +2881,7 @@ static void ftdi_elan_disconnect(struct usb_interface *interface)
2688 platform_device_unregister(&ftdi->platform_dev); 2881 platform_device_unregister(&ftdi->platform_dev);
2689 ftdi->synchronized = 0; 2882 ftdi->synchronized = 0;
2690 ftdi->enumerated = 0; 2883 ftdi->enumerated = 0;
2884 ftdi->initialized = 0;
2691 ftdi->registered = 0; 2885 ftdi->registered = 0;
2692 } 2886 }
2693 flush_workqueue(status_queue); 2887 flush_workqueue(status_queue);
diff --git a/drivers/usb/misc/phidgetservo.c b/drivers/usb/misc/phidgetservo.c
index 7163f05c5b..0d9de2f739 100644
--- a/drivers/usb/misc/phidgetservo.c
+++ b/drivers/usb/misc/phidgetservo.c
@@ -282,6 +282,7 @@ servo_probe(struct usb_interface *interface, const struct usb_device_id *id)
282 dev->dev = NULL; 282 dev->dev = NULL;
283 goto out; 283 goto out;
284 } 284 }
285 dev_set_drvdata(dev->dev, dev);
285 286
286 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1; 287 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1;
287 288
diff --git a/drivers/usb/misc/sisusbvga/sisusb_con.c b/drivers/usb/misc/sisusbvga/sisusb_con.c
index bf26c3c569..9148694627 100644
--- a/drivers/usb/misc/sisusbvga/sisusb_con.c
+++ b/drivers/usb/misc/sisusbvga/sisusb_con.c
@@ -403,7 +403,7 @@ sisusbcon_putc(struct vc_data *c, int ch, int y, int x)
403 403
404 404
405 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y), 405 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
406 (u32)SISUSB_HADDR(x, y), 2, &written); 406 (long)SISUSB_HADDR(x, y), 2, &written);
407 407
408 mutex_unlock(&sisusb->lock); 408 mutex_unlock(&sisusb->lock);
409} 409}
@@ -438,7 +438,7 @@ sisusbcon_putcs(struct vc_data *c, const unsigned short *s,
438 } 438 }
439 439
440 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y), 440 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
441 (u32)SISUSB_HADDR(x, y), count * 2, &written); 441 (long)SISUSB_HADDR(x, y), count * 2, &written);
442 442
443 mutex_unlock(&sisusb->lock); 443 mutex_unlock(&sisusb->lock);
444} 444}
@@ -492,7 +492,7 @@ sisusbcon_clear(struct vc_data *c, int y, int x, int height, int width)
492 492
493 493
494 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(x, y), 494 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(x, y),
495 (u32)SISUSB_HADDR(x, y), length, &written); 495 (long)SISUSB_HADDR(x, y), length, &written);
496 496
497 mutex_unlock(&sisusb->lock); 497 mutex_unlock(&sisusb->lock);
498} 498}
@@ -564,7 +564,7 @@ sisusbcon_bmove(struct vc_data *c, int sy, int sx,
564 564
565 565
566 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(dx, dy), 566 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(dx, dy),
567 (u32)SISUSB_HADDR(dx, dy), length, &written); 567 (long)SISUSB_HADDR(dx, dy), length, &written);
568 568
569 mutex_unlock(&sisusb->lock); 569 mutex_unlock(&sisusb->lock);
570} 570}
@@ -612,7 +612,7 @@ sisusbcon_switch(struct vc_data *c)
612 length); 612 length);
613 613
614 sisusb_copy_memory(sisusb, (unsigned char *)c->vc_origin, 614 sisusb_copy_memory(sisusb, (unsigned char *)c->vc_origin,
615 (u32)SISUSB_HADDR(0, 0), 615 (long)SISUSB_HADDR(0, 0),
616 length, &written); 616 length, &written);
617 617
618 mutex_unlock(&sisusb->lock); 618 mutex_unlock(&sisusb->lock);
@@ -939,7 +939,7 @@ sisusbcon_scroll_area(struct vc_data *c, struct sisusb_usb_data *sisusb,
939 } 939 }
940 940
941 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(0, t), 941 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(0, t),
942 (u32)SISUSB_HADDR(0, t), length, &written); 942 (long)SISUSB_HADDR(0, t), length, &written);
943 943
944 mutex_unlock(&sisusb->lock); 944 mutex_unlock(&sisusb->lock);
945 945
diff --git a/drivers/usb/misc/trancevibrator.c b/drivers/usb/misc/trancevibrator.c
index 33cd91d11e..67e2fc20ee 100644
--- a/drivers/usb/misc/trancevibrator.c
+++ b/drivers/usb/misc/trancevibrator.c
@@ -120,8 +120,8 @@ static void tv_disconnect(struct usb_interface *interface)
120 struct trancevibrator *dev; 120 struct trancevibrator *dev;
121 121
122 dev = usb_get_intfdata (interface); 122 dev = usb_get_intfdata (interface);
123 usb_set_intfdata(interface, NULL);
124 device_remove_file(&interface->dev, &dev_attr_speed); 123 device_remove_file(&interface->dev, &dev_attr_speed);
124 usb_set_intfdata(interface, NULL);
125 usb_put_dev(dev->udev); 125 usb_put_dev(dev->udev);
126 kfree(dev); 126 kfree(dev);
127} 127}
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
index 95e682e2c9..896449f0cf 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/usb/net/asix.c
@@ -898,7 +898,7 @@ static int ax88772_link_reset(struct usbnet *dev)
898 898
899static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) 899static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
900{ 900{
901 int ret; 901 int ret, embd_phy;
902 void *buf; 902 void *buf;
903 u16 rx_ctl; 903 u16 rx_ctl;
904 struct asix_data *data = (struct asix_data *)&dev->data; 904 struct asix_data *data = (struct asix_data *)&dev->data;
@@ -919,13 +919,15 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
919 AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5)) < 0) 919 AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5)) < 0)
920 goto out2; 920 goto out2;
921 921
922 /* 0x10 is the phy id of the embedded 10/100 ethernet phy */
923 embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
922 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 924 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT,
923 0x0000, 0, 0, buf)) < 0) { 925 embd_phy, 0, 0, buf)) < 0) {
924 dbg("Select PHY #1 failed: %d", ret); 926 dbg("Select PHY #1 failed: %d", ret);
925 goto out2; 927 goto out2;
926 } 928 }
927 929
928 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPPD)) < 0) 930 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL)) < 0)
929 goto out2; 931 goto out2;
930 932
931 msleep(150); 933 msleep(150);
@@ -933,8 +935,14 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
933 goto out2; 935 goto out2;
934 936
935 msleep(150); 937 msleep(150);
936 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL)) < 0) 938 if (embd_phy) {
937 goto out2; 939 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL)) < 0)
940 goto out2;
941 }
942 else {
943 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRTE)) < 0)
944 goto out2;
945 }
938 946
939 msleep(150); 947 msleep(150);
940 rx_ctl = asix_read_rx_ctl(dev); 948 rx_ctl = asix_read_rx_ctl(dev);
diff --git a/drivers/usb/net/gl620a.c b/drivers/usb/net/gl620a.c
index a3242be219..a6f0f4d934 100644
--- a/drivers/usb/net/gl620a.c
+++ b/drivers/usb/net/gl620a.c
@@ -79,160 +79,6 @@ struct gl_header {
79 struct gl_packet packets; 79 struct gl_packet packets;
80}; 80};
81 81
82#ifdef GENELINK_ACK
83
84// FIXME: this code is incomplete, not debugged; it doesn't
85// handle interrupts correctly; it should use the generic
86// status IRQ code (which didn't exist back in 2001).
87
88struct gl_priv {
89 struct urb *irq_urb;
90 char irq_buf [INTERRUPT_BUFSIZE];
91};
92
93static inline int gl_control_write(struct usbnet *dev, u8 request, u16 value)
94{
95 int retval;
96
97 retval = usb_control_msg(dev->udev,
98 usb_sndctrlpipe(dev->udev, 0),
99 request,
100 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
101 value,
102 0, // index
103 0, // data buffer
104 0, // size
105 USB_CTRL_SET_TIMEOUT);
106 return retval;
107}
108
109static void gl_interrupt_complete(struct urb *urb)
110{
111 int status = urb->status;
112
113 switch (status) {
114 case 0:
115 /* success */
116 break;
117 case -ECONNRESET:
118 case -ENOENT:
119 case -ESHUTDOWN:
120 /* this urb is terminated, clean up */
121 dbg("%s - urb shutting down with status: %d",
122 __FUNCTION__, status);
123 return;
124 default:
125 dbg("%s - nonzero urb status received: %d",
126 __FUNCTION__, urb->status);
127 }
128
129 status = usb_submit_urb(urb, GFP_ATOMIC);
130 if (status)
131 err("%s - usb_submit_urb failed with result %d",
132 __FUNCTION__, status);
133}
134
135static int gl_interrupt_read(struct usbnet *dev)
136{
137 struct gl_priv *priv = dev->priv_data;
138 int retval;
139
140 // issue usb interrupt read
141 if (priv && priv->irq_urb) {
142 // submit urb
143 if ((retval = usb_submit_urb(priv->irq_urb, GFP_KERNEL)) != 0)
144 dbg("gl_interrupt_read: submit fail - %X...", retval);
145 else
146 dbg("gl_interrupt_read: submit success...");
147 }
148
149 return 0;
150}
151
152// check whether another side is connected
153static int genelink_check_connect(struct usbnet *dev)
154{
155 int retval;
156
157 dbg("genelink_check_connect...");
158
159 // detect whether another side is connected
160 if ((retval = gl_control_write(dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
161 dbg("%s: genelink_check_connect write fail - %X",
162 dev->net->name, retval);
163 return retval;
164 }
165
166 // usb interrupt read to ack another side
167 if ((retval = gl_interrupt_read(dev)) != 0) {
168 dbg("%s: genelink_check_connect read fail - %X",
169 dev->net->name, retval);
170 return retval;
171 }
172
173 dbg("%s: genelink_check_connect read success", dev->net->name);
174 return 0;
175}
176
177// allocate and initialize the private data for genelink
178static int genelink_init(struct usbnet *dev)
179{
180 struct gl_priv *priv;
181
182 // allocate the private data structure
183 if ((priv = kmalloc(sizeof *priv, GFP_KERNEL)) == 0) {
184 dbg("%s: cannot allocate private data per device",
185 dev->net->name);
186 return -ENOMEM;
187 }
188
189 // allocate irq urb
190 if ((priv->irq_urb = usb_alloc_urb(0, GFP_KERNEL)) == 0) {
191 dbg("%s: cannot allocate private irq urb per device",
192 dev->net->name);
193 kfree(priv);
194 return -ENOMEM;
195 }
196
197 // fill irq urb
198 usb_fill_int_urb(priv->irq_urb, dev->udev,
199 usb_rcvintpipe(dev->udev, GENELINK_INTERRUPT_PIPE),
200 priv->irq_buf, INTERRUPT_BUFSIZE,
201 gl_interrupt_complete, 0,
202 GENELINK_INTERRUPT_INTERVAL);
203
204 // set private data pointer
205 dev->priv_data = priv;
206
207 return 0;
208}
209
210// release the private data
211static int genelink_free(struct usbnet *dev)
212{
213 struct gl_priv *priv = dev->priv_data;
214
215 if (!priv)
216 return 0;
217
218// FIXME: can't cancel here; it's synchronous, and
219// should have happened earlier in any case (interrupt
220// handling needs to be generic)
221
222 // cancel irq urb first
223 usb_kill_urb(priv->irq_urb);
224
225 // free irq urb
226 usb_free_urb(priv->irq_urb);
227
228 // free the private data structure
229 kfree(priv);
230
231 return 0;
232}
233
234#endif
235
236static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 82static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
237{ 83{
238 struct gl_header *header; 84 struct gl_header *header;
diff --git a/drivers/usb/net/rndis_host.c b/drivers/usb/net/rndis_host.c
index ea5f44de3d..a322a16d9c 100644
--- a/drivers/usb/net/rndis_host.c
+++ b/drivers/usb/net/rndis_host.c
@@ -379,6 +379,7 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf)
379{ 379{
380 int retval; 380 int retval;
381 struct net_device *net = dev->net; 381 struct net_device *net = dev->net;
382 struct cdc_state *info = (void *) &dev->data;
382 union { 383 union {
383 void *buf; 384 void *buf;
384 struct rndis_msg_hdr *header; 385 struct rndis_msg_hdr *header;
@@ -397,7 +398,7 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf)
397 return -ENOMEM; 398 return -ENOMEM;
398 retval = usbnet_generic_cdc_bind(dev, intf); 399 retval = usbnet_generic_cdc_bind(dev, intf);
399 if (retval < 0) 400 if (retval < 0)
400 goto done; 401 goto fail;
401 402
402 net->hard_header_len += sizeof (struct rndis_data_hdr); 403 net->hard_header_len += sizeof (struct rndis_data_hdr);
403 404
@@ -412,10 +413,7 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf)
412 if (unlikely(retval < 0)) { 413 if (unlikely(retval < 0)) {
413 /* it might not even be an RNDIS device!! */ 414 /* it might not even be an RNDIS device!! */
414 dev_err(&intf->dev, "RNDIS init failed, %d\n", retval); 415 dev_err(&intf->dev, "RNDIS init failed, %d\n", retval);
415fail: 416 goto fail_and_release;
416 usb_driver_release_interface(driver_of(intf),
417 ((struct cdc_state *)&(dev->data))->data);
418 goto done;
419 } 417 }
420 dev->hard_mtu = le32_to_cpu(u.init_c->max_transfer_size); 418 dev->hard_mtu = le32_to_cpu(u.init_c->max_transfer_size);
421 /* REVISIT: peripheral "alignment" request is ignored ... */ 419 /* REVISIT: peripheral "alignment" request is ignored ... */
@@ -431,7 +429,7 @@ fail:
431 retval = rndis_command(dev, u.header); 429 retval = rndis_command(dev, u.header);
432 if (unlikely(retval < 0)) { 430 if (unlikely(retval < 0)) {
433 dev_err(&intf->dev, "rndis get ethaddr, %d\n", retval); 431 dev_err(&intf->dev, "rndis get ethaddr, %d\n", retval);
434 goto fail; 432 goto fail_and_release;
435 } 433 }
436 tmp = le32_to_cpu(u.get_c->offset); 434 tmp = le32_to_cpu(u.get_c->offset);
437 if (unlikely((tmp + 8) > (1024 - ETH_ALEN) 435 if (unlikely((tmp + 8) > (1024 - ETH_ALEN)
@@ -439,7 +437,7 @@ fail:
439 dev_err(&intf->dev, "rndis ethaddr off %d len %d ?\n", 437 dev_err(&intf->dev, "rndis ethaddr off %d len %d ?\n",
440 tmp, le32_to_cpu(u.get_c->len)); 438 tmp, le32_to_cpu(u.get_c->len));
441 retval = -EDOM; 439 retval = -EDOM;
442 goto fail; 440 goto fail_and_release;
443 } 441 }
444 memcpy(net->dev_addr, tmp + (char *)&u.get_c->request_id, ETH_ALEN); 442 memcpy(net->dev_addr, tmp + (char *)&u.get_c->request_id, ETH_ALEN);
445 443
@@ -455,11 +453,18 @@ fail:
455 retval = rndis_command(dev, u.header); 453 retval = rndis_command(dev, u.header);
456 if (unlikely(retval < 0)) { 454 if (unlikely(retval < 0)) {
457 dev_err(&intf->dev, "rndis set packet filter, %d\n", retval); 455 dev_err(&intf->dev, "rndis set packet filter, %d\n", retval);
458 goto fail; 456 goto fail_and_release;
459 } 457 }
460 458
461 retval = 0; 459 retval = 0;
462done: 460
461 kfree(u.buf);
462 return retval;
463
464fail_and_release:
465 usb_set_intfdata(info->data, NULL);
466 usb_driver_release_interface(driver_of(intf), info->data);
467fail:
463 kfree(u.buf); 468 kfree(u.buf);
464 return retval; 469 return retval;
465} 470}
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
index c54235f73c..e0eecda78e 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/usb/net/rtl8150.c
@@ -124,10 +124,11 @@
124#define RX_URB_FAIL 3 124#define RX_URB_FAIL 3
125 125
126/* Define these values to match your device */ 126/* Define these values to match your device */
127#define VENDOR_ID_REALTEK 0x0bda 127#define VENDOR_ID_REALTEK 0x0bda
128#define VENDOR_ID_MELCO 0x0411 128#define VENDOR_ID_MELCO 0x0411
129#define VENDOR_ID_MICRONET 0x3980 129#define VENDOR_ID_MICRONET 0x3980
130#define VENDOR_ID_LONGSHINE 0x07b8 130#define VENDOR_ID_LONGSHINE 0x07b8
131#define VENDOR_ID_OQO 0x1557
131#define VENDOR_ID_ZYXEL 0x0586 132#define VENDOR_ID_ZYXEL 0x0586
132 133
133#define PRODUCT_ID_RTL8150 0x8150 134#define PRODUCT_ID_RTL8150 0x8150
@@ -144,6 +145,7 @@ static struct usb_device_id rtl8150_table[] = {
144 {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)}, 145 {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
145 {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)}, 146 {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
146 {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)}, 147 {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
148 {USB_DEVICE(VENDOR_ID_OQO, PRODUCT_ID_RTL8150)},
147 {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)}, 149 {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)},
148 {} 150 {}
149}; 151};
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 96c73726d7..f2ca76a9cb 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -19,8 +19,11 @@
19static struct usb_device_id id_table [] = { 19static struct usb_device_id id_table [] = {
20 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */ 20 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */
21 { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin CDMA */ 21 { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin CDMA */
22 { USB_DEVICE(0x1410, 0x1130) }, /* Novatel Wireless S720 CDMA/EV-DO */
23 { USB_DEVICE(0x1410, 0x2110) }, /* Novatel Wireless U720 CDMA/EV-DO */
22 { USB_DEVICE(0x1410, 0x1430) }, /* Novatel Merlin XU870 HSDPA/3G */ 24 { USB_DEVICE(0x1410, 0x1430) }, /* Novatel Merlin XU870 HSDPA/3G */
23 { USB_DEVICE(0x1410, 0x1100) }, /* ExpressCard34 Qualcomm 3G CDMA */ 25 { USB_DEVICE(0x1410, 0x1100) }, /* ExpressCard34 Qualcomm 3G CDMA */
26 { USB_DEVICE(0x413c, 0x8115) }, /* Dell Wireless HSDPA 5500 */
24 { }, 27 { },
25}; 28};
26MODULE_DEVICE_TABLE(usb, id_table); 29MODULE_DEVICE_TABLE(usb, id_table);
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 2f9b7ac326..7ebaffd6ed 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -69,6 +69,7 @@ static struct usb_device_id id_table [] = {
69 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ 69 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
70 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 70 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
71 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 71 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
72 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
72 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ 73 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
73 { } /* Terminating Entry */ 74 { } /* Terminating Entry */
74}; 75};
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 45cdf9bc43..6bc1f404e1 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -962,21 +962,6 @@ static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsi
962 cypress_set_termios(port, &priv->tmp_termios); 962 cypress_set_termios(port, &priv->tmp_termios);
963 return (0); 963 return (0);
964 break; 964 break;
965 /* these are called when setting baud rate from gpsd */
966 case TCGETS:
967 if (copy_to_user((void __user *)arg, port->tty->termios, sizeof(struct termios))) {
968 return -EFAULT;
969 }
970 return (0);
971 break;
972 case TCSETS:
973 if (copy_from_user(port->tty->termios, (void __user *)arg, sizeof(struct termios))) {
974 return -EFAULT;
975 }
976 /* here we need to call cypress_set_termios to invoke the new settings */
977 cypress_set_termios(port, &priv->tmp_termios);
978 return (0);
979 break;
980 /* This code comes from drivers/char/serial.c and ftdi_sio.c */ 965 /* This code comes from drivers/char/serial.c and ftdi_sio.c */
981 case TIOCMIWAIT: 966 case TIOCMIWAIT:
982 while (priv != NULL) { 967 while (priv != NULL) {
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 41b0ad2d56..6986e756f7 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -452,6 +452,7 @@ static struct usb_device_id id_table_combined [] = {
452 { USB_DEVICE(FTDI_VID, LINX_FUTURE_2_PID) }, 452 { USB_DEVICE(FTDI_VID, LINX_FUTURE_2_PID) },
453 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) }, 453 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
454 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) }, 454 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
455 { USB_DEVICE(FTDI_VID, FTDI_CCSMACHX_2_PID) },
455 { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) }, 456 { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) },
456 { USB_DEVICE(INTREPID_VID, INTREPID_VALUECAN_PID) }, 457 { USB_DEVICE(INTREPID_VID, INTREPID_VALUECAN_PID) },
457 { USB_DEVICE(INTREPID_VID, INTREPID_NEOVI_PID) }, 458 { USB_DEVICE(INTREPID_VID, INTREPID_NEOVI_PID) },
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index bae117d359..40dd394de5 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -312,8 +312,9 @@
312 312
313/* CCS Inc. ICDU/ICDU40 product ID - the FT232BM is used in an in-circuit-debugger */ 313/* CCS Inc. ICDU/ICDU40 product ID - the FT232BM is used in an in-circuit-debugger */
314/* unit for PIC16's/PIC18's */ 314/* unit for PIC16's/PIC18's */
315#define FTDI_CCSICDU20_0_PID 0xF9D0 315#define FTDI_CCSICDU20_0_PID 0xF9D0
316#define FTDI_CCSICDU40_1_PID 0xF9D1 316#define FTDI_CCSICDU40_1_PID 0xF9D1
317#define FTDI_CCSMACHX_2_PID 0xF9D2
317 318
318/* Inside Accesso contactless reader (http://www.insidefr.com) */ 319/* Inside Accesso contactless reader (http://www.insidefr.com) */
319#define INSIDE_ACCESSO 0xFAD0 320#define INSIDE_ACCESSO 0xFAD0
diff --git a/drivers/usb/serial/funsoft.c b/drivers/usb/serial/funsoft.c
index 77b977206a..2bebd63d5e 100644
--- a/drivers/usb/serial/funsoft.c
+++ b/drivers/usb/serial/funsoft.c
@@ -14,6 +14,9 @@
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>
18
19static int debug;
17 20
18static struct usb_device_id id_table [] = { 21static struct usb_device_id id_table [] = {
19 { USB_DEVICE(0x1404, 0xcddc) }, 22 { USB_DEVICE(0x1404, 0xcddc) },
@@ -21,6 +24,26 @@ static struct usb_device_id id_table [] = {
21}; 24};
22MODULE_DEVICE_TABLE(usb, id_table); 25MODULE_DEVICE_TABLE(usb, id_table);
23 26
27static int funsoft_ioctl(struct usb_serial_port *port, struct file *file,
28 unsigned int cmd, unsigned long arg)
29{
30 struct ktermios t;
31
32 dbg("%s - port %d, cmd 0x%04x", __FUNCTION__, port->number, cmd);
33
34 if (cmd == TCSETSF) {
35 if (user_termios_to_kernel_termios(&t, (struct termios __user *)arg))
36 return -EFAULT;
37
38 dbg("%s - iflag:%x oflag:%x cflag:%x lflag:%x", __FUNCTION__,
39 t.c_iflag, t.c_oflag, t.c_cflag, t.c_lflag);
40
41 if (!(t.c_lflag & ICANON))
42 return -EINVAL;
43 }
44 return -ENOIOCTLCMD;
45}
46
24static struct usb_driver funsoft_driver = { 47static struct usb_driver funsoft_driver = {
25 .name = "funsoft", 48 .name = "funsoft",
26 .probe = usb_serial_probe, 49 .probe = usb_serial_probe,
@@ -39,6 +62,7 @@ static struct usb_serial_driver funsoft_device = {
39 .num_bulk_in = NUM_DONT_CARE, 62 .num_bulk_in = NUM_DONT_CARE,
40 .num_bulk_out = NUM_DONT_CARE, 63 .num_bulk_out = NUM_DONT_CARE,
41 .num_ports = 1, 64 .num_ports = 1,
65 .ioctl = funsoft_ioctl,
42}; 66};
43 67
44static int __init funsoft_init(void) 68static int __init funsoft_init(void)
@@ -63,3 +87,6 @@ static void __exit funsoft_exit(void)
63module_init(funsoft_init); 87module_init(funsoft_init);
64module_exit(funsoft_exit); 88module_exit(funsoft_exit);
65MODULE_LICENSE("GPL"); 89MODULE_LICENSE("GPL");
90
91module_param(debug, bool, S_IRUGO | S_IWUSR);
92MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 73d755df48..5c4b06a99a 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -87,10 +87,6 @@ static int klsi_105_write_room (struct usb_serial_port *port);
87static void klsi_105_read_bulk_callback (struct urb *urb); 87static void klsi_105_read_bulk_callback (struct urb *urb);
88static void klsi_105_set_termios (struct usb_serial_port *port, 88static void klsi_105_set_termios (struct usb_serial_port *port,
89 struct ktermios *old); 89 struct ktermios *old);
90static int klsi_105_ioctl (struct usb_serial_port *port,
91 struct file * file,
92 unsigned int cmd,
93 unsigned long arg);
94static void klsi_105_throttle (struct usb_serial_port *port); 90static void klsi_105_throttle (struct usb_serial_port *port);
95static void klsi_105_unthrottle (struct usb_serial_port *port); 91static void klsi_105_unthrottle (struct usb_serial_port *port);
96/* 92/*
@@ -140,7 +136,6 @@ static struct usb_serial_driver kl5kusb105d_device = {
140 .chars_in_buffer = klsi_105_chars_in_buffer, 136 .chars_in_buffer = klsi_105_chars_in_buffer,
141 .write_room = klsi_105_write_room, 137 .write_room = klsi_105_write_room,
142 .read_bulk_callback =klsi_105_read_bulk_callback, 138 .read_bulk_callback =klsi_105_read_bulk_callback,
143 .ioctl = klsi_105_ioctl,
144 .set_termios = klsi_105_set_termios, 139 .set_termios = klsi_105_set_termios,
145 /*.break_ctl = klsi_105_break_ctl,*/ 140 /*.break_ctl = klsi_105_break_ctl,*/
146 .tiocmget = klsi_105_tiocmget, 141 .tiocmget = klsi_105_tiocmget,
@@ -899,69 +894,6 @@ static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file,
899*/ 894*/
900 return retval; 895 return retval;
901} 896}
902
903static int klsi_105_ioctl (struct usb_serial_port *port, struct file * file,
904 unsigned int cmd, unsigned long arg)
905{
906 struct klsi_105_private *priv = usb_get_serial_port_data(port);
907 void __user *user_arg = (void __user *)arg;
908
909 dbg("%scmd=0x%x", __FUNCTION__, cmd);
910
911 /* Based on code from acm.c and others */
912 switch (cmd) {
913 case TIOCMIWAIT:
914 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
915 /* TODO */
916 dbg("%s - TIOCMIWAIT not handled", __FUNCTION__);
917 return -ENOIOCTLCMD;
918 case TIOCGICOUNT:
919 /* return count of modemline transitions */
920 /* TODO */
921 dbg("%s - TIOCGICOUNT not handled", __FUNCTION__);
922 return -ENOIOCTLCMD;
923 case TCGETS:
924 /* return current info to caller */
925 dbg("%s - TCGETS data faked/incomplete", __FUNCTION__);
926
927 if (!access_ok(VERIFY_WRITE, user_arg, sizeof(struct termios)))
928 return -EFAULT;
929
930 if (kernel_termios_to_user_termios((struct termios __user *)arg,
931 &priv->termios))
932 return -EFAULT;
933 return 0;
934 case TCSETS:
935 /* set port termios to the one given by the user */
936 dbg("%s - TCSETS not handled", __FUNCTION__);
937
938 if (!access_ok(VERIFY_READ, user_arg, sizeof(struct termios)))
939 return -EFAULT;
940
941 if (user_termios_to_kernel_termios(&priv->termios,
942 (struct termios __user *)arg))
943 return -EFAULT;
944 klsi_105_set_termios(port, &priv->termios);
945 return 0;
946 case TCSETSW: {
947 /* set port termios and try to wait for completion of last
948 * write operation */
949 /* We guess here. If there are not too many write urbs
950 * outstanding, we lie. */
951 /* what is the right way to wait here? schedule() ? */
952 /*
953 while (klsi_105_chars_in_buffer(port) > (NUM_URBS / 4 ) * URB_TRANSFER_BUFFER_SIZE)
954 schedule();
955 */
956 return -ENOIOCTLCMD;
957 }
958 default:
959 dbg("%s: arg not supported - 0x%04x", __FUNCTION__,cmd);
960 return(-ENOIOCTLCMD);
961 break;
962 }
963 return 0;
964} /* klsi_105_ioctl */
965 897
966static void klsi_105_throttle (struct usb_serial_port *port) 898static void klsi_105_throttle (struct usb_serial_port *port)
967{ 899{
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 8cc728a49e..83f661403b 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -2460,12 +2460,6 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2460 tty_ldisc_deref(ld); 2460 tty_ldisc_deref(ld);
2461 return 0; 2461 return 0;
2462 2462
2463 case TCGETS:
2464 if (kernel_termios_to_user_termios
2465 ((struct termios __user *)argp, tty->termios))
2466 return -EFAULT;
2467 return 0;
2468
2469 case TIOCSERGETLSR: 2463 case TIOCSERGETLSR:
2470 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number); 2464 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
2471 return mos7840_get_lsr_info(mos7840_port, argp); 2465 return mos7840_get_lsr_info(mos7840_port, argp);
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 0ae4098718..0fed43a968 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -78,7 +78,9 @@ static int option_send_setup(struct usb_serial_port *port);
78#define OPTION_PRODUCT_FUSION2 0x6300 78#define OPTION_PRODUCT_FUSION2 0x6300
79#define OPTION_PRODUCT_COBRA 0x6500 79#define OPTION_PRODUCT_COBRA 0x6500
80#define OPTION_PRODUCT_COBRA2 0x6600 80#define OPTION_PRODUCT_COBRA2 0x6600
81#define OPTION_PRODUCT_GTMAX36 0x6701
81#define HUAWEI_PRODUCT_E600 0x1001 82#define HUAWEI_PRODUCT_E600 0x1001
83#define HUAWEI_PRODUCT_E220 0x1003
82#define AUDIOVOX_PRODUCT_AIRCARD 0x0112 84#define AUDIOVOX_PRODUCT_AIRCARD 0x0112
83#define NOVATELWIRELESS_PRODUCT_U740 0x1400 85#define NOVATELWIRELESS_PRODUCT_U740 0x1400
84#define ANYDATA_PRODUCT_ID 0x6501 86#define ANYDATA_PRODUCT_ID 0x6501
@@ -89,7 +91,9 @@ static struct usb_device_id option_ids[] = {
89 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) }, 91 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
90 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, 92 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
91 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) }, 93 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
94 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) },
92 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 95 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
96 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
93 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) }, 97 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
94 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 98 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
95 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, 99 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
@@ -102,7 +106,9 @@ static struct usb_device_id option_ids1[] = {
102 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) }, 106 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
103 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, 107 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
104 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) }, 108 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
109 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) },
105 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 110 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
111 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
106 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) }, 112 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
107 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 113 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
108 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, 114 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
@@ -622,6 +628,9 @@ static int option_send_setup(struct usb_serial_port *port)
622 628
623 dbg("%s", __FUNCTION__); 629 dbg("%s", __FUNCTION__);
624 630
631 if (port->number != 0)
632 return 0;
633
625 portdata = usb_get_serial_port_data(port); 634 portdata = usb_get_serial_port_data(port);
626 635
627 if (port->tty) { 636 if (port->tty) {
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index db8b26012c..b49f2a7818 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -153,6 +153,13 @@ UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100,
153 US_SC_DEVICE, US_PR_DEVICE, NULL, 153 US_SC_DEVICE, US_PR_DEVICE, NULL,
154 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 154 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
155 155
156/* Reported by <honkkis@gmail.com> */
157UNUSUAL_DEV( 0x0421, 0x0433, 0x0100, 0x0100,
158 "Nokia",
159 "E70",
160 US_SC_DEVICE, US_PR_DEVICE, NULL,
161 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
162
156/* Reported by Jon Hart <Jon.Hart@web.de> */ 163/* Reported by Jon Hart <Jon.Hart@web.de> */
157UNUSUAL_DEV( 0x0421, 0x0434, 0x0100, 0x0100, 164UNUSUAL_DEV( 0x0421, 0x0434, 0x0100, 0x0100,
158 "Nokia", 165 "Nokia",
@@ -190,6 +197,13 @@ UNUSUAL_DEV( 0x0421, 0x047c, 0x0370, 0x0370,
190 US_SC_DEVICE, US_PR_DEVICE, NULL, 197 US_SC_DEVICE, US_PR_DEVICE, NULL,
191 US_FL_MAX_SECTORS_64 ), 198 US_FL_MAX_SECTORS_64 ),
192 199
200/* Reported by Manuel Osdoba <manuel.osdoba@tu-ilmenau.de> */
201UNUSUAL_DEV( 0x0421, 0x0492, 0x0452, 0x0452,
202 "Nokia",
203 "Nokia 6233",
204 US_SC_DEVICE, US_PR_DEVICE, NULL,
205 US_FL_MAX_SECTORS_64 ),
206
193/* Reported by Alex Corcoles <alex@corcoles.net> */ 207/* Reported by Alex Corcoles <alex@corcoles.net> */
194UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370, 208UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370,
195 "Nokia", 209 "Nokia",
@@ -247,6 +261,18 @@ UNUSUAL_DEV( 0x045a, 0x5210, 0x0101, 0x0101,
247 US_SC_SCSI, US_PR_KARMA, rio_karma_init, 0), 261 US_SC_SCSI, US_PR_KARMA, rio_karma_init, 0),
248#endif 262#endif
249 263
264/*
265 * This virtual floppy is found in Sun equipment (x4600, x4200m2, etc.)
266 * Reported by Pete Zaitcev <zaitcev@redhat.com>
267 * This device chokes on both version of MODE SENSE which we have, so
268 * use_10_for_ms is not effective, and we use US_FL_NO_WP_DETECT.
269 */
270UNUSUAL_DEV( 0x046b, 0xff40, 0x0100, 0x0100,
271 "AMI",
272 "Virtual Floppy",
273 US_SC_DEVICE, US_PR_DEVICE, NULL,
274 US_FL_NO_WP_DETECT),
275
250/* Patch submitted by Philipp Friedrich <philipp@void.at> */ 276/* Patch submitted by Philipp Friedrich <philipp@void.at> */
251UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100, 277UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100,
252 "Kyocera", 278 "Kyocera",
@@ -721,7 +747,7 @@ UNUSUAL_DEV( 0x05ac, 0x1204, 0x0000, 0x9999,
721 "Apple", 747 "Apple",
722 "iPod", 748 "iPod",
723 US_SC_DEVICE, US_PR_DEVICE, NULL, 749 US_SC_DEVICE, US_PR_DEVICE, NULL,
724 US_FL_FIX_CAPACITY ), 750 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ),
725 751
726UNUSUAL_DEV( 0x05ac, 0x1205, 0x0000, 0x9999, 752UNUSUAL_DEV( 0x05ac, 0x1205, 0x0000, 0x9999,
727 "Apple", 753 "Apple",
@@ -1328,6 +1354,15 @@ UNUSUAL_DEV( 0x1210, 0x0003, 0x0100, 0x0100,
1328 US_SC_DEVICE, US_PR_DEVICE, NULL, 1354 US_SC_DEVICE, US_PR_DEVICE, NULL,
1329 US_FL_IGNORE_RESIDUE ), 1355 US_FL_IGNORE_RESIDUE ),
1330 1356
1357/* This prevents the kernel from detecting the virtual cd-drive with the
1358 * Windows drivers. <johann.wilhelm@student.tugraz.at>
1359*/
1360UNUSUAL_DEV( 0x12d1, 0x1003, 0x0000, 0xffff,
1361 "HUAWEI",
1362 "E220 USB-UMTS Install",
1363 US_SC_DEVICE, US_PR_DEVICE, NULL,
1364 US_FL_IGNORE_DEVICE),
1365
1331/* Reported by Vilius Bilinkevicius <vilisas AT xxx DOT lt) */ 1366/* Reported by Vilius Bilinkevicius <vilisas AT xxx DOT lt) */
1332UNUSUAL_DEV( 0x132b, 0x000b, 0x0001, 0x0001, 1367UNUSUAL_DEV( 0x132b, 0x000b, 0x0001, 0x0001,
1333 "Minolta", 1368 "Minolta",
@@ -1342,6 +1377,21 @@ UNUSUAL_DEV( 0x1370, 0x6828, 0x0110, 0x0110,
1342 US_SC_DEVICE, US_PR_DEVICE, NULL, 1377 US_SC_DEVICE, US_PR_DEVICE, NULL,
1343 US_FL_IGNORE_RESIDUE ), 1378 US_FL_IGNORE_RESIDUE ),
1344 1379
1380/* Reported by Francesco Foresti <frafore@tiscali.it> */
1381UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x0201,
1382 "Super Top",
1383 "IDE DEVICE",
1384 US_SC_DEVICE, US_PR_DEVICE, NULL,
1385 US_FL_IGNORE_RESIDUE ),
1386
1387/* Reported by Robert Schedel <r.schedel@yahoo.de>
1388 * Note: this is a 'super top' device like the above 14cd/6600 device */
1389UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1390 "Teac",
1391 "HD-35PUK-B",
1392 US_SC_DEVICE, US_PR_DEVICE, NULL,
1393 US_FL_IGNORE_RESIDUE ),
1394
1345/* patch submitted by Davide Perini <perini.davide@dpsoftware.org> 1395/* patch submitted by Davide Perini <perini.davide@dpsoftware.org>
1346 * and Renato Perini <rperini@email.it> 1396 * and Renato Perini <rperini@email.it>
1347 */ 1397 */
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 3feddf89d1..2e976ffcde 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -1834,7 +1834,7 @@ static void aty128_bl_init(struct aty128fb_par *par)
1834 1834
1835 snprintf(name, sizeof(name), "aty128bl%d", info->node); 1835 snprintf(name, sizeof(name), "aty128bl%d", info->node);
1836 1836
1837 bd = backlight_device_register(name, par, &aty128_bl_data); 1837 bd = backlight_device_register(name, info->dev, par, &aty128_bl_data);
1838 if (IS_ERR(bd)) { 1838 if (IS_ERR(bd)) {
1839 info->bl_dev = NULL; 1839 info->bl_dev = NULL;
1840 printk(KERN_WARNING "aty128: Backlight registration failed\n"); 1840 printk(KERN_WARNING "aty128: Backlight registration failed\n");
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 09684d7a7c..f2ebdd8800 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -2211,7 +2211,7 @@ static void aty_bl_init(struct atyfb_par *par)
2211 2211
2212 snprintf(name, sizeof(name), "atybl%d", info->node); 2212 snprintf(name, sizeof(name), "atybl%d", info->node);
2213 2213
2214 bd = backlight_device_register(name, par, &aty_bl_data); 2214 bd = backlight_device_register(name, info->dev, par, &aty_bl_data);
2215 if (IS_ERR(bd)) { 2215 if (IS_ERR(bd)) {
2216 info->bl_dev = NULL; 2216 info->bl_dev = NULL;
2217 printk(KERN_WARNING "aty: Backlight registration failed\n"); 2217 printk(KERN_WARNING "aty: Backlight registration failed\n");
diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
index 585eb7b9e6..3abfd4a380 100644
--- a/drivers/video/aty/radeon_backlight.c
+++ b/drivers/video/aty/radeon_backlight.c
@@ -163,7 +163,7 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
163 163
164 snprintf(name, sizeof(name), "radeonbl%d", rinfo->info->node); 164 snprintf(name, sizeof(name), "radeonbl%d", rinfo->info->node);
165 165
166 bd = backlight_device_register(name, pdata, &radeon_bl_data); 166 bd = backlight_device_register(name, rinfo->info->dev, pdata, &radeon_bl_data);
167 if (IS_ERR(bd)) { 167 if (IS_ERR(bd)) {
168 rinfo->info->bl_dev = NULL; 168 rinfo->info->bl_dev = NULL;
169 printk("radeonfb: Backlight registration failed\n"); 169 printk("radeonfb: Backlight registration failed\n");
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index db8c191b12..9601bfe309 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -216,8 +216,10 @@ static const struct class_device_attribute bl_class_device_attributes[] = {
216 * Creates and registers new backlight class_device. Returns either an 216 * Creates and registers new backlight class_device. Returns either an
217 * ERR_PTR() or a pointer to the newly allocated device. 217 * ERR_PTR() or a pointer to the newly allocated device.
218 */ 218 */
219struct backlight_device *backlight_device_register(const char *name, void *devdata, 219struct backlight_device *backlight_device_register(const char *name,
220 struct backlight_properties *bp) 220 struct device *dev,
221 void *devdata,
222 struct backlight_properties *bp)
221{ 223{
222 int i, rc; 224 int i, rc;
223 struct backlight_device *new_bd; 225 struct backlight_device *new_bd;
@@ -232,6 +234,7 @@ struct backlight_device *backlight_device_register(const char *name, void *devda
232 new_bd->props = bp; 234 new_bd->props = bp;
233 memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev)); 235 memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev));
234 new_bd->class_dev.class = &backlight_class; 236 new_bd->class_dev.class = &backlight_class;
237 new_bd->class_dev.dev = dev;
235 strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN); 238 strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN);
236 class_set_devdata(&new_bd->class_dev, devdata); 239 class_set_devdata(&new_bd->class_dev, devdata);
237 240
diff --git a/drivers/video/backlight/corgi_bl.c b/drivers/video/backlight/corgi_bl.c
index 61587ca2cd..fde1d95181 100644
--- a/drivers/video/backlight/corgi_bl.c
+++ b/drivers/video/backlight/corgi_bl.c
@@ -121,7 +121,7 @@ static int corgibl_probe(struct platform_device *pdev)
121 machinfo->limit_mask = -1; 121 machinfo->limit_mask = -1;
122 122
123 corgi_backlight_device = backlight_device_register ("corgi-bl", 123 corgi_backlight_device = backlight_device_register ("corgi-bl",
124 NULL, &corgibl_data); 124 &pdev->dev, NULL, &corgibl_data);
125 if (IS_ERR (corgi_backlight_device)) 125 if (IS_ERR (corgi_backlight_device))
126 return PTR_ERR (corgi_backlight_device); 126 return PTR_ERR (corgi_backlight_device);
127 127
diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
index 1c569fb543..c07d8207fb 100644
--- a/drivers/video/backlight/hp680_bl.c
+++ b/drivers/video/backlight/hp680_bl.c
@@ -105,7 +105,7 @@ static struct backlight_properties hp680bl_data = {
105static int __init hp680bl_probe(struct platform_device *dev) 105static int __init hp680bl_probe(struct platform_device *dev)
106{ 106{
107 hp680_backlight_device = backlight_device_register ("hp680-bl", 107 hp680_backlight_device = backlight_device_register ("hp680-bl",
108 NULL, &hp680bl_data); 108 &dev->dev, NULL, &hp680bl_data);
109 if (IS_ERR (hp680_backlight_device)) 109 if (IS_ERR (hp680_backlight_device))
110 return PTR_ERR (hp680_backlight_device); 110 return PTR_ERR (hp680_backlight_device);
111 111
diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
index 2d7905410b..fc812d96c3 100644
--- a/drivers/video/backlight/locomolcd.c
+++ b/drivers/video/backlight/locomolcd.c
@@ -184,7 +184,7 @@ static int locomolcd_probe(struct locomo_dev *ldev)
184 184
185 local_irq_restore(flags); 185 local_irq_restore(flags);
186 186
187 locomolcd_bl_device = backlight_device_register("locomo-bl", NULL, &locomobl_data); 187 locomolcd_bl_device = backlight_device_register("locomo-bl", &ldev->dev, NULL, &locomobl_data);
188 188
189 if (IS_ERR (locomolcd_bl_device)) 189 if (IS_ERR (locomolcd_bl_device))
190 return PTR_ERR (locomolcd_bl_device); 190 return PTR_ERR (locomolcd_bl_device);
diff --git a/drivers/video/bw2.c b/drivers/video/bw2.c
index c66e3d52cb..9bb6257d69 100644
--- a/drivers/video/bw2.c
+++ b/drivers/video/bw2.c
@@ -320,7 +320,7 @@ static int __devinit bw2_init_one(struct of_device *op)
320 all->info.fbops = &bw2_ops; 320 all->info.fbops = &bw2_ops;
321 321
322 all->info.screen_base = 322 all->info.screen_base =
323 sbus_ioremap(&op->resource[0], 0, all->par.fbsize, "bw2 ram"); 323 of_ioremap(&op->resource[0], 0, all->par.fbsize, "bw2 ram");
324 all->info.par = &all->par; 324 all->info.par = &all->par;
325 325
326 bw2_blank(0, &all->info); 326 bw2_blank(0, &all->info);
@@ -329,8 +329,10 @@ static int __devinit bw2_init_one(struct of_device *op)
329 329
330 err= register_framebuffer(&all->info); 330 err= register_framebuffer(&all->info);
331 if (err < 0) { 331 if (err < 0) {
332 of_iounmap(all->par.regs, sizeof(struct bw2_regs)); 332 of_iounmap(&op->resource[0],
333 of_iounmap(all->info.screen_base, all->par.fbsize); 333 all->par.regs, sizeof(struct bw2_regs));
334 of_iounmap(&op->resource[0],
335 all->info.screen_base, all->par.fbsize);
334 kfree(all); 336 kfree(all);
335 return err; 337 return err;
336 } 338 }
@@ -351,18 +353,18 @@ static int __devinit bw2_probe(struct of_device *dev, const struct of_device_id
351 return bw2_init_one(op); 353 return bw2_init_one(op);
352} 354}
353 355
354static int __devexit bw2_remove(struct of_device *dev) 356static int __devexit bw2_remove(struct of_device *op)
355{ 357{
356 struct all_info *all = dev_get_drvdata(&dev->dev); 358 struct all_info *all = dev_get_drvdata(&op->dev);
357 359
358 unregister_framebuffer(&all->info); 360 unregister_framebuffer(&all->info);
359 361
360 of_iounmap(all->par.regs, sizeof(struct bw2_regs)); 362 of_iounmap(&op->resource[0], all->par.regs, sizeof(struct bw2_regs));
361 of_iounmap(all->info.screen_base, all->par.fbsize); 363 of_iounmap(&op->resource[0], all->info.screen_base, all->par.fbsize);
362 364
363 kfree(all); 365 kfree(all);
364 366
365 dev_set_drvdata(&dev->dev, NULL); 367 dev_set_drvdata(&op->dev, NULL);
366 368
367 return 0; 369 return 0;
368} 370}
diff --git a/drivers/video/cg14.c b/drivers/video/cg14.c
index 7f926c619b..ec6a51a582 100644
--- a/drivers/video/cg14.c
+++ b/drivers/video/cg14.c
@@ -452,16 +452,20 @@ struct all_info {
452 struct cg14_par par; 452 struct cg14_par par;
453}; 453};
454 454
455static void cg14_unmap_regs(struct all_info *all) 455static void cg14_unmap_regs(struct of_device *op, struct all_info *all)
456{ 456{
457 if (all->par.regs) 457 if (all->par.regs)
458 of_iounmap(all->par.regs, sizeof(struct cg14_regs)); 458 of_iounmap(&op->resource[0],
459 all->par.regs, sizeof(struct cg14_regs));
459 if (all->par.clut) 460 if (all->par.clut)
460 of_iounmap(all->par.clut, sizeof(struct cg14_clut)); 461 of_iounmap(&op->resource[0],
462 all->par.clut, sizeof(struct cg14_clut));
461 if (all->par.cursor) 463 if (all->par.cursor)
462 of_iounmap(all->par.cursor, sizeof(struct cg14_cursor)); 464 of_iounmap(&op->resource[0],
465 all->par.cursor, sizeof(struct cg14_cursor));
463 if (all->info.screen_base) 466 if (all->info.screen_base)
464 of_iounmap(all->info.screen_base, all->par.fbsize); 467 of_iounmap(&op->resource[1],
468 all->info.screen_base, all->par.fbsize);
465} 469}
466 470
467static int __devinit cg14_init_one(struct of_device *op) 471static int __devinit cg14_init_one(struct of_device *op)
@@ -506,7 +510,7 @@ static int __devinit cg14_init_one(struct of_device *op)
506 510
507 if (!all->par.regs || !all->par.clut || !all->par.cursor || 511 if (!all->par.regs || !all->par.clut || !all->par.cursor ||
508 !all->info.screen_base) 512 !all->info.screen_base)
509 cg14_unmap_regs(all); 513 cg14_unmap_regs(op, all);
510 514
511 is_8mb = (((op->resource[1].end - op->resource[1].start) + 1) == 515 is_8mb = (((op->resource[1].end - op->resource[1].start) + 1) ==
512 (8 * 1024 * 1024)); 516 (8 * 1024 * 1024));
@@ -541,7 +545,7 @@ static int __devinit cg14_init_one(struct of_device *op)
541 __cg14_reset(&all->par); 545 __cg14_reset(&all->par);
542 546
543 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { 547 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
544 cg14_unmap_regs(all); 548 cg14_unmap_regs(op, all);
545 kfree(all); 549 kfree(all);
546 return -ENOMEM; 550 return -ENOMEM;
547 } 551 }
@@ -552,7 +556,7 @@ static int __devinit cg14_init_one(struct of_device *op)
552 err = register_framebuffer(&all->info); 556 err = register_framebuffer(&all->info);
553 if (err < 0) { 557 if (err < 0) {
554 fb_dealloc_cmap(&all->info.cmap); 558 fb_dealloc_cmap(&all->info.cmap);
555 cg14_unmap_regs(all); 559 cg14_unmap_regs(op, all);
556 kfree(all); 560 kfree(all);
557 return err; 561 return err;
558 } 562 }
@@ -574,18 +578,18 @@ static int __devinit cg14_probe(struct of_device *dev, const struct of_device_id
574 return cg14_init_one(op); 578 return cg14_init_one(op);
575} 579}
576 580
577static int __devexit cg14_remove(struct of_device *dev) 581static int __devexit cg14_remove(struct of_device *op)
578{ 582{
579 struct all_info *all = dev_get_drvdata(&dev->dev); 583 struct all_info *all = dev_get_drvdata(&op->dev);
580 584
581 unregister_framebuffer(&all->info); 585 unregister_framebuffer(&all->info);
582 fb_dealloc_cmap(&all->info.cmap); 586 fb_dealloc_cmap(&all->info.cmap);
583 587
584 cg14_unmap_regs(all); 588 cg14_unmap_regs(op, all);
585 589
586 kfree(all); 590 kfree(all);
587 591
588 dev_set_drvdata(&dev->dev, NULL); 592 dev_set_drvdata(&op->dev, NULL);
589 593
590 return 0; 594 return 0;
591} 595}
diff --git a/drivers/video/cg3.c b/drivers/video/cg3.c
index 9c8c753ef4..ada6f7e3a8 100644
--- a/drivers/video/cg3.c
+++ b/drivers/video/cg3.c
@@ -403,8 +403,10 @@ static int __devinit cg3_init_one(struct of_device *op)
403 cg3_do_default_mode(&all->par); 403 cg3_do_default_mode(&all->par);
404 404
405 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { 405 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
406 of_iounmap(all->par.regs, sizeof(struct cg3_regs)); 406 of_iounmap(&op->resource[0],
407 of_iounmap(all->info.screen_base, all->par.fbsize); 407 all->par.regs, sizeof(struct cg3_regs));
408 of_iounmap(&op->resource[0],
409 all->info.screen_base, all->par.fbsize);
408 kfree(all); 410 kfree(all);
409 return -ENOMEM; 411 return -ENOMEM;
410 } 412 }
@@ -415,8 +417,10 @@ static int __devinit cg3_init_one(struct of_device *op)
415 err = register_framebuffer(&all->info); 417 err = register_framebuffer(&all->info);
416 if (err < 0) { 418 if (err < 0) {
417 fb_dealloc_cmap(&all->info.cmap); 419 fb_dealloc_cmap(&all->info.cmap);
418 of_iounmap(all->par.regs, sizeof(struct cg3_regs)); 420 of_iounmap(&op->resource[0],
419 of_iounmap(all->info.screen_base, all->par.fbsize); 421 all->par.regs, sizeof(struct cg3_regs));
422 of_iounmap(&op->resource[0],
423 all->info.screen_base, all->par.fbsize);
420 kfree(all); 424 kfree(all);
421 return err; 425 return err;
422 } 426 }
@@ -436,19 +440,19 @@ static int __devinit cg3_probe(struct of_device *dev, const struct of_device_id
436 return cg3_init_one(op); 440 return cg3_init_one(op);
437} 441}
438 442
439static int __devexit cg3_remove(struct of_device *dev) 443static int __devexit cg3_remove(struct of_device *op)
440{ 444{
441 struct all_info *all = dev_get_drvdata(&dev->dev); 445 struct all_info *all = dev_get_drvdata(&op->dev);
442 446
443 unregister_framebuffer(&all->info); 447 unregister_framebuffer(&all->info);
444 fb_dealloc_cmap(&all->info.cmap); 448 fb_dealloc_cmap(&all->info.cmap);
445 449
446 of_iounmap(all->par.regs, sizeof(struct cg3_regs)); 450 of_iounmap(&op->resource[0], all->par.regs, sizeof(struct cg3_regs));
447 of_iounmap(all->info.screen_base, all->par.fbsize); 451 of_iounmap(&op->resource[0], all->info.screen_base, all->par.fbsize);
448 452
449 kfree(all); 453 kfree(all);
450 454
451 dev_set_drvdata(&dev->dev, NULL); 455 dev_set_drvdata(&op->dev, NULL);
452 456
453 return 0; 457 return 0;
454} 458}
diff --git a/drivers/video/cg6.c b/drivers/video/cg6.c
index 64146be2ee..4dad23a28f 100644
--- a/drivers/video/cg6.c
+++ b/drivers/video/cg6.c
@@ -658,21 +658,26 @@ struct all_info {
658 struct cg6_par par; 658 struct cg6_par par;
659}; 659};
660 660
661static void cg6_unmap_regs(struct all_info *all) 661static void cg6_unmap_regs(struct of_device *op, struct all_info *all)
662{ 662{
663 if (all->par.fbc) 663 if (all->par.fbc)
664 of_iounmap(all->par.fbc, 4096); 664 of_iounmap(&op->resource[0], all->par.fbc, 4096);
665 if (all->par.tec) 665 if (all->par.tec)
666 of_iounmap(all->par.tec, sizeof(struct cg6_tec)); 666 of_iounmap(&op->resource[0],
667 all->par.tec, sizeof(struct cg6_tec));
667 if (all->par.thc) 668 if (all->par.thc)
668 of_iounmap(all->par.thc, sizeof(struct cg6_thc)); 669 of_iounmap(&op->resource[0],
670 all->par.thc, sizeof(struct cg6_thc));
669 if (all->par.bt) 671 if (all->par.bt)
670 of_iounmap(all->par.bt, sizeof(struct bt_regs)); 672 of_iounmap(&op->resource[0],
673 all->par.bt, sizeof(struct bt_regs));
671 if (all->par.fhc) 674 if (all->par.fhc)
672 of_iounmap(all->par.fhc, sizeof(u32)); 675 of_iounmap(&op->resource[0],
676 all->par.fhc, sizeof(u32));
673 677
674 if (all->info.screen_base) 678 if (all->info.screen_base)
675 of_iounmap(all->info.screen_base, all->par.fbsize); 679 of_iounmap(&op->resource[0],
680 all->info.screen_base, all->par.fbsize);
676} 681}
677 682
678static int __devinit cg6_init_one(struct of_device *op) 683static int __devinit cg6_init_one(struct of_device *op)
@@ -720,7 +725,7 @@ static int __devinit cg6_init_one(struct of_device *op)
720 all->par.fbsize, "cgsix ram"); 725 all->par.fbsize, "cgsix ram");
721 if (!all->par.fbc || !all->par.tec || !all->par.thc || 726 if (!all->par.fbc || !all->par.tec || !all->par.thc ||
722 !all->par.bt || !all->par.fhc || !all->info.screen_base) { 727 !all->par.bt || !all->par.fhc || !all->info.screen_base) {
723 cg6_unmap_regs(all); 728 cg6_unmap_regs(op, all);
724 kfree(all); 729 kfree(all);
725 return -ENOMEM; 730 return -ENOMEM;
726 } 731 }
@@ -734,7 +739,7 @@ static int __devinit cg6_init_one(struct of_device *op)
734 cg6_blank(0, &all->info); 739 cg6_blank(0, &all->info);
735 740
736 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { 741 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
737 cg6_unmap_regs(all); 742 cg6_unmap_regs(op, all);
738 kfree(all); 743 kfree(all);
739 return -ENOMEM; 744 return -ENOMEM;
740 } 745 }
@@ -744,7 +749,7 @@ static int __devinit cg6_init_one(struct of_device *op)
744 749
745 err = register_framebuffer(&all->info); 750 err = register_framebuffer(&all->info);
746 if (err < 0) { 751 if (err < 0) {
747 cg6_unmap_regs(all); 752 cg6_unmap_regs(op, all);
748 fb_dealloc_cmap(&all->info.cmap); 753 fb_dealloc_cmap(&all->info.cmap);
749 kfree(all); 754 kfree(all);
750 return err; 755 return err;
@@ -767,18 +772,18 @@ static int __devinit cg6_probe(struct of_device *dev, const struct of_device_id
767 return cg6_init_one(op); 772 return cg6_init_one(op);
768} 773}
769 774
770static int __devexit cg6_remove(struct of_device *dev) 775static int __devexit cg6_remove(struct of_device *op)
771{ 776{
772 struct all_info *all = dev_get_drvdata(&dev->dev); 777 struct all_info *all = dev_get_drvdata(&op->dev);
773 778
774 unregister_framebuffer(&all->info); 779 unregister_framebuffer(&all->info);
775 fb_dealloc_cmap(&all->info.cmap); 780 fb_dealloc_cmap(&all->info.cmap);
776 781
777 cg6_unmap_regs(all); 782 cg6_unmap_regs(op, all);
778 783
779 kfree(all); 784 kfree(all);
780 785
781 dev_set_drvdata(&dev->dev, NULL); 786 dev_set_drvdata(&op->dev, NULL);
782 787
783 return 0; 788 return 0;
784} 789}
diff --git a/drivers/video/ffb.c b/drivers/video/ffb.c
index 949141bd44..15854aec31 100644
--- a/drivers/video/ffb.c
+++ b/drivers/video/ffb.c
@@ -910,7 +910,8 @@ static int ffb_init_one(struct of_device *op)
910 all->par.dac = of_ioremap(&op->resource[1], 0, 910 all->par.dac = of_ioremap(&op->resource[1], 0,
911 sizeof(struct ffb_dac), "ffb dac"); 911 sizeof(struct ffb_dac), "ffb dac");
912 if (!all->par.dac) { 912 if (!all->par.dac) {
913 of_iounmap(all->par.fbc, sizeof(struct ffb_fbc)); 913 of_iounmap(&op->resource[2],
914 all->par.fbc, sizeof(struct ffb_fbc));
914 kfree(all); 915 kfree(all);
915 return -ENOMEM; 916 return -ENOMEM;
916 } 917 }
@@ -968,8 +969,10 @@ static int ffb_init_one(struct of_device *op)
968 969
969 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { 970 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
970 printk(KERN_ERR "ffb: Could not allocate color map.\n"); 971 printk(KERN_ERR "ffb: Could not allocate color map.\n");
971 of_iounmap(all->par.fbc, sizeof(struct ffb_fbc)); 972 of_iounmap(&op->resource[2],
972 of_iounmap(all->par.dac, sizeof(struct ffb_dac)); 973 all->par.fbc, sizeof(struct ffb_fbc));
974 of_iounmap(&op->resource[1],
975 all->par.dac, sizeof(struct ffb_dac));
973 kfree(all); 976 kfree(all);
974 return -ENOMEM; 977 return -ENOMEM;
975 } 978 }
@@ -980,8 +983,10 @@ static int ffb_init_one(struct of_device *op)
980 if (err < 0) { 983 if (err < 0) {
981 printk(KERN_ERR "ffb: Could not register framebuffer.\n"); 984 printk(KERN_ERR "ffb: Could not register framebuffer.\n");
982 fb_dealloc_cmap(&all->info.cmap); 985 fb_dealloc_cmap(&all->info.cmap);
983 of_iounmap(all->par.fbc, sizeof(struct ffb_fbc)); 986 of_iounmap(&op->resource[2],
984 of_iounmap(all->par.dac, sizeof(struct ffb_dac)); 987 all->par.fbc, sizeof(struct ffb_fbc));
988 of_iounmap(&op->resource[1],
989 all->par.dac, sizeof(struct ffb_dac));
985 kfree(all); 990 kfree(all);
986 return err; 991 return err;
987 } 992 }
@@ -1003,19 +1008,19 @@ static int __devinit ffb_probe(struct of_device *dev, const struct of_device_id
1003 return ffb_init_one(op); 1008 return ffb_init_one(op);
1004} 1009}
1005 1010
1006static int __devexit ffb_remove(struct of_device *dev) 1011static int __devexit ffb_remove(struct of_device *op)
1007{ 1012{
1008 struct all_info *all = dev_get_drvdata(&dev->dev); 1013 struct all_info *all = dev_get_drvdata(&op->dev);
1009 1014
1010 unregister_framebuffer(&all->info); 1015 unregister_framebuffer(&all->info);
1011 fb_dealloc_cmap(&all->info.cmap); 1016 fb_dealloc_cmap(&all->info.cmap);
1012 1017
1013 of_iounmap(all->par.fbc, sizeof(struct ffb_fbc)); 1018 of_iounmap(&op->resource[2], all->par.fbc, sizeof(struct ffb_fbc));
1014 of_iounmap(all->par.dac, sizeof(struct ffb_dac)); 1019 of_iounmap(&op->resource[1], all->par.dac, sizeof(struct ffb_dac));
1015 1020
1016 kfree(all); 1021 kfree(all);
1017 1022
1018 dev_set_drvdata(&dev->dev, NULL); 1023 dev_set_drvdata(&op->dev, NULL);
1019 1024
1020 return 0; 1025 return 0;
1021} 1026}
diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
index 3adf6ab076..23a6bcc3e3 100644
--- a/drivers/video/gxt4500.c
+++ b/drivers/video/gxt4500.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Frame buffer device for IBM GXT4500P display adaptor 2 * Frame buffer device for IBM GXT4500P and GXT6000P display adaptors
3 * 3 *
4 * Copyright (C) 2006 Paul Mackerras, IBM Corp. <paulus@samba.org> 4 * Copyright (C) 2006 Paul Mackerras, IBM Corp. <paulus@samba.org>
5 */ 5 */
@@ -11,8 +11,10 @@
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/pci_ids.h> 12#include <linux/pci_ids.h>
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/string.h>
14 15
15#define PCI_DEVICE_ID_IBM_GXT4500P 0x21c 16#define PCI_DEVICE_ID_IBM_GXT4500P 0x21c
17#define PCI_DEVICE_ID_IBM_GXT6000P 0x170
16 18
17/* GXT4500P registers */ 19/* GXT4500P registers */
18 20
@@ -94,6 +96,7 @@ static const unsigned char pixsize[] = {
94#define PLL_M 0x4040 96#define PLL_M 0x4040
95#define PLL_N 0x4044 97#define PLL_N 0x4044
96#define PLL_POSTDIV 0x4048 98#define PLL_POSTDIV 0x4048
99#define PLL_C 0x404c
97 100
98/* Hardware cursor */ 101/* Hardware cursor */
99#define CURSOR_X 0x4078 102#define CURSOR_X 0x4078
@@ -140,6 +143,7 @@ struct gxt4500_par {
140 int pixfmt; /* pixel format, see DFA_PIX_* values */ 143 int pixfmt; /* pixel format, see DFA_PIX_* values */
141 144
142 /* PLL parameters */ 145 /* PLL parameters */
146 int refclk_ps; /* ref clock period in picoseconds */
143 int pll_m; /* ref clock divisor */ 147 int pll_m; /* ref clock divisor */
144 int pll_n; /* VCO divisor */ 148 int pll_n; /* VCO divisor */
145 int pll_pd1; /* first post-divisor */ 149 int pll_pd1; /* first post-divisor */
@@ -166,6 +170,21 @@ static const struct fb_videomode defaultmode __devinitdata = {
166 .vmode = FB_VMODE_NONINTERLACED 170 .vmode = FB_VMODE_NONINTERLACED
167}; 171};
168 172
173/* List of supported cards */
174enum gxt_cards {
175 GXT4500P,
176 GXT6000P
177};
178
179/* Card-specific information */
180static const struct cardinfo {
181 int refclk_ps; /* period of PLL reference clock in ps */
182 const char *cardname;
183} cardinfo[] = {
184 [GXT4500P] = { .refclk_ps = 9259, .cardname = "IBM GXT4500P" },
185 [GXT6000P] = { .refclk_ps = 40000, .cardname = "IBM GXT6000P" },
186};
187
169/* 188/*
170 * The refclk and VCO dividers appear to use a linear feedback shift 189 * The refclk and VCO dividers appear to use a linear feedback shift
171 * register, which gets reloaded when it reaches a terminal value, at 190 * register, which gets reloaded when it reaches a terminal value, at
@@ -203,27 +222,16 @@ static const unsigned char ndivtab[] = {
203/* 130 */ 0x9e, 0x4f, 0x27, 0x93, 0xc9, 0xe4, 0x72, 0x39, 0x1c, 0x0e, 222/* 130 */ 0x9e, 0x4f, 0x27, 0x93, 0xc9, 0xe4, 0x72, 0x39, 0x1c, 0x0e,
204/* 140 */ 0x87, 0xc3, 0x61, 0x30, 0x18, 0x8c, 0xc6, 0x63, 0x31, 0x98, 223/* 140 */ 0x87, 0xc3, 0x61, 0x30, 0x18, 0x8c, 0xc6, 0x63, 0x31, 0x98,
205/* 150 */ 0xcc, 0xe6, 0x73, 0xb9, 0x5c, 0x2e, 0x97, 0x4b, 0xa5, 0xd2, 224/* 150 */ 0xcc, 0xe6, 0x73, 0xb9, 0x5c, 0x2e, 0x97, 0x4b, 0xa5, 0xd2,
206/* 160 */ 0x69, 0xb4, 0xda, 0xed, 0x76, 0xbb, 0x5d, 0xae, 0xd7, 0x6b, 225/* 160 */ 0x69,
207/* 170 */ 0xb5, 0x5a, 0xad, 0x56, 0xab, 0xd5, 0x6a, 0x35, 0x1a, 0x8d,
208/* 180 */ 0x46, 0x23, 0x11, 0x88, 0x44, 0x22, 0x91, 0xc8, 0x64, 0x32,
209/* 190 */ 0x19, 0x0c, 0x86, 0x43, 0x21, 0x10, 0x08, 0x04, 0x02, 0x81,
210/* 200 */ 0x40, 0xa0, 0xd0, 0x68, 0x34, 0x9a, 0xcd, 0x66, 0x33, 0x99,
211/* 210 */ 0x4c, 0xa6, 0x53, 0xa9, 0xd4, 0xea, 0x75, 0x3a, 0x9d, 0xce,
212/* 220 */ 0xe7, 0xf3, 0xf9, 0x7c, 0x3e, 0x1f, 0x8f, 0x47, 0xa3, 0x51,
213/* 230 */ 0xa8, 0x54, 0xaa, 0x55, 0x2a, 0x15, 0x0a, 0x05, 0x82, 0xc1,
214/* 240 */ 0x60, 0xb0, 0x58, 0xac, 0xd6, 0xeb, 0xf5, 0x7a, 0xbd, 0xde,
215/* 250 */ 0x6f, 0x37, 0x1b, 0x0d, 0x06, 0x03, 0x01,
216}; 226};
217 227
218#define REF_PERIOD_PS 9259 /* period of reference clock in ps */
219
220static int calc_pll(int period_ps, struct gxt4500_par *par) 228static int calc_pll(int period_ps, struct gxt4500_par *par)
221{ 229{
222 int m, n, pdiv1, pdiv2, postdiv; 230 int m, n, pdiv1, pdiv2, postdiv;
223 int pll_period, best_error, t; 231 int pll_period, best_error, t, intf;
224 232
225 /* only deal with range 1MHz - 400MHz */ 233 /* only deal with range 5MHz - 300MHz */
226 if (period_ps < 2500 || period_ps > 1000000) 234 if (period_ps < 3333 || period_ps > 200000)
227 return -1; 235 return -1;
228 236
229 best_error = 1000000; 237 best_error = 1000000;
@@ -231,14 +239,17 @@ static int calc_pll(int period_ps, struct gxt4500_par *par)
231 for (pdiv2 = 1; pdiv2 <= pdiv1; ++pdiv2) { 239 for (pdiv2 = 1; pdiv2 <= pdiv1; ++pdiv2) {
232 postdiv = pdiv1 * pdiv2; 240 postdiv = pdiv1 * pdiv2;
233 pll_period = (period_ps + postdiv - 1) / postdiv; 241 pll_period = (period_ps + postdiv - 1) / postdiv;
234 /* keep pll in range 500..1250 MHz */ 242 /* keep pll in range 350..600 MHz */
235 if (pll_period < 800 || pll_period > 2000) 243 if (pll_period < 1666 || pll_period > 2857)
236 continue; 244 continue;
237 for (m = 3; m <= 40; ++m) { 245 for (m = 1; m <= 64; ++m) {
238 n = REF_PERIOD_PS * m * postdiv / period_ps; 246 intf = m * par->refclk_ps;
239 if (n < 5 || n > 256) 247 if (intf > 500000)
248 break;
249 n = intf * postdiv / period_ps;
250 if (n < 3 || n > 160)
240 continue; 251 continue;
241 t = REF_PERIOD_PS * m * postdiv / n; 252 t = par->refclk_ps * m * postdiv / n;
242 t -= period_ps; 253 t -= period_ps;
243 if (t >= 0 && t < best_error) { 254 if (t >= 0 && t < best_error) {
244 par->pll_m = m; 255 par->pll_m = m;
@@ -257,7 +268,7 @@ static int calc_pll(int period_ps, struct gxt4500_par *par)
257 268
258static int calc_pixclock(struct gxt4500_par *par) 269static int calc_pixclock(struct gxt4500_par *par)
259{ 270{
260 return REF_PERIOD_PS * par->pll_m * par->pll_pd1 * par->pll_pd2 271 return par->refclk_ps * par->pll_m * par->pll_pd1 * par->pll_pd2
261 / par->pll_n; 272 / par->pll_n;
262} 273}
263 274
@@ -357,7 +368,7 @@ static int gxt4500_set_par(struct fb_info *info)
357 struct gxt4500_par *par = info->par; 368 struct gxt4500_par *par = info->par;
358 struct fb_var_screeninfo *var = &info->var; 369 struct fb_var_screeninfo *var = &info->var;
359 int err; 370 int err;
360 u32 ctrlreg; 371 u32 ctrlreg, tmp;
361 unsigned int dfa_ctl, pixfmt, stride; 372 unsigned int dfa_ctl, pixfmt, stride;
362 unsigned int wid_tiles, i; 373 unsigned int wid_tiles, i;
363 unsigned int prefetch_pix, htot; 374 unsigned int prefetch_pix, htot;
@@ -376,10 +387,25 @@ static int gxt4500_set_par(struct fb_info *info)
376 writereg(par, DTG_CONTROL, ctrlreg); 387 writereg(par, DTG_CONTROL, ctrlreg);
377 388
378 /* set PLL registers */ 389 /* set PLL registers */
390 tmp = readreg(par, PLL_C) & ~0x7f;
391 if (par->pll_n < 38)
392 tmp |= 0x29;
393 if (par->pll_n < 69)
394 tmp |= 0x35;
395 else if (par->pll_n < 100)
396 tmp |= 0x76;
397 else
398 tmp |= 0x7e;
399 writereg(par, PLL_C, tmp);
379 writereg(par, PLL_M, mdivtab[par->pll_m - 1]); 400 writereg(par, PLL_M, mdivtab[par->pll_m - 1]);
380 writereg(par, PLL_N, ndivtab[par->pll_n - 2]); 401 writereg(par, PLL_N, ndivtab[par->pll_n - 2]);
381 writereg(par, PLL_POSTDIV, 402 tmp = ((8 - par->pll_pd2) << 3) | (8 - par->pll_pd1);
382 ((8 - par->pll_pd1) << 3) | (8 - par->pll_pd2)); 403 if (par->pll_pd1 == 8 || par->pll_pd2 == 8) {
404 /* work around erratum */
405 writereg(par, PLL_POSTDIV, tmp | 0x9);
406 udelay(1);
407 }
408 writereg(par, PLL_POSTDIV, tmp);
383 msleep(20); 409 msleep(20);
384 410
385 /* turn off hardware cursor */ 411 /* turn off hardware cursor */
@@ -483,8 +509,8 @@ static int gxt4500_setcolreg(unsigned int reg, unsigned int red,
483 509
484 if (reg > 1023) 510 if (reg > 1023)
485 return 1; 511 return 1;
486 cmap_entry = ((transp & 0xff00) << 16) | ((blue & 0xff00) << 8) | 512 cmap_entry = ((transp & 0xff00) << 16) | ((red & 0xff00) << 8) |
487 (green & 0xff00) | (red >> 8); 513 (green & 0xff00) | (blue >> 8);
488 writereg(par, CMAP + reg * 4, cmap_entry); 514 writereg(par, CMAP + reg * 4, cmap_entry);
489 515
490 if (reg < 16 && par->pixfmt != DFA_PIX_8BIT) { 516 if (reg < 16 && par->pixfmt != DFA_PIX_8BIT) {
@@ -585,6 +611,7 @@ static int __devinit gxt4500_probe(struct pci_dev *pdev,
585 struct gxt4500_par *par; 611 struct gxt4500_par *par;
586 struct fb_info *info; 612 struct fb_info *info;
587 struct fb_var_screeninfo var; 613 struct fb_var_screeninfo var;
614 enum gxt_cards cardtype;
588 615
589 err = pci_enable_device(pdev); 616 err = pci_enable_device(pdev);
590 if (err) { 617 if (err) {
@@ -613,7 +640,11 @@ static int __devinit gxt4500_probe(struct pci_dev *pdev,
613 goto err_free_fb; 640 goto err_free_fb;
614 } 641 }
615 par = info->par; 642 par = info->par;
643 cardtype = ent->driver_data;
644 par->refclk_ps = cardinfo[cardtype].refclk_ps;
616 info->fix = gxt4500_fix; 645 info->fix = gxt4500_fix;
646 strlcpy(info->fix.id, cardinfo[cardtype].cardname,
647 sizeof(info->fix.id));
617 info->pseudo_palette = par->pseudo_palette; 648 info->pseudo_palette = par->pseudo_palette;
618 649
619 info->fix.mmio_start = reg_phys; 650 info->fix.mmio_start = reg_phys;
@@ -703,8 +734,10 @@ static void __devexit gxt4500_remove(struct pci_dev *pdev)
703 734
704/* supported chipsets */ 735/* supported chipsets */
705static const struct pci_device_id gxt4500_pci_tbl[] = { 736static const struct pci_device_id gxt4500_pci_tbl[] = {
706 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_GXT4500P, 737 { PCI_DEVICE(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_GXT4500P),
707 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 738 .driver_data = GXT4500P },
739 { PCI_DEVICE(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_GXT6000P),
740 .driver_data = GXT6000P },
708 { 0 } 741 { 0 }
709}; 742};
710 743
@@ -735,7 +768,7 @@ static void __exit gxt4500_exit(void)
735module_exit(gxt4500_exit); 768module_exit(gxt4500_exit);
736 769
737MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>"); 770MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
738MODULE_DESCRIPTION("FBDev driver for IBM GXT4500P"); 771MODULE_DESCRIPTION("FBDev driver for IBM GXT4500P/6000P");
739MODULE_LICENSE("GPL"); 772MODULE_LICENSE("GPL");
740module_param(mode_option, charp, 0); 773module_param(mode_option, charp, 0);
741MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\""); 774MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
diff --git a/drivers/video/leo.c b/drivers/video/leo.c
index f3a24338d9..a038aa5a9e 100644
--- a/drivers/video/leo.c
+++ b/drivers/video/leo.c
@@ -530,20 +530,21 @@ struct all_info {
530 struct leo_par par; 530 struct leo_par par;
531}; 531};
532 532
533static void leo_unmap_regs(struct all_info *all) 533static void leo_unmap_regs(struct of_device *op, struct all_info *all)
534{ 534{
535 if (all->par.lc_ss0_usr) 535 if (all->par.lc_ss0_usr)
536 of_iounmap(all->par.lc_ss0_usr, 0x1000); 536 of_iounmap(&op->resource[0], all->par.lc_ss0_usr, 0x1000);
537 if (all->par.ld_ss0) 537 if (all->par.ld_ss0)
538 of_iounmap(all->par.ld_ss0, 0x1000); 538 of_iounmap(&op->resource[0], all->par.ld_ss0, 0x1000);
539 if (all->par.ld_ss1) 539 if (all->par.ld_ss1)
540 of_iounmap(all->par.ld_ss1, 0x1000); 540 of_iounmap(&op->resource[0], all->par.ld_ss1, 0x1000);
541 if (all->par.lx_krn) 541 if (all->par.lx_krn)
542 of_iounmap(all->par.lx_krn, 0x1000); 542 of_iounmap(&op->resource[0], all->par.lx_krn, 0x1000);
543 if (all->par.cursor) 543 if (all->par.cursor)
544 of_iounmap(all->par.cursor, sizeof(struct leo_cursor)); 544 of_iounmap(&op->resource[0],
545 all->par.cursor, sizeof(struct leo_cursor));
545 if (all->info.screen_base) 546 if (all->info.screen_base)
546 of_iounmap(all->info.screen_base, 0x800000); 547 of_iounmap(&op->resource[0], all->info.screen_base, 0x800000);
547} 548}
548 549
549static int __devinit leo_init_one(struct of_device *op) 550static int __devinit leo_init_one(struct of_device *op)
@@ -592,7 +593,7 @@ static int __devinit leo_init_one(struct of_device *op)
592 !all->par.lx_krn || 593 !all->par.lx_krn ||
593 !all->par.cursor || 594 !all->par.cursor ||
594 !all->info.screen_base) { 595 !all->info.screen_base) {
595 leo_unmap_regs(all); 596 leo_unmap_regs(op, all);
596 kfree(all); 597 kfree(all);
597 return -ENOMEM; 598 return -ENOMEM;
598 } 599 }
@@ -607,7 +608,7 @@ static int __devinit leo_init_one(struct of_device *op)
607 leo_blank(0, &all->info); 608 leo_blank(0, &all->info);
608 609
609 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { 610 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
610 leo_unmap_regs(all); 611 leo_unmap_regs(op, all);
611 kfree(all); 612 kfree(all);
612 return -ENOMEM;; 613 return -ENOMEM;;
613 } 614 }
@@ -617,7 +618,7 @@ static int __devinit leo_init_one(struct of_device *op)
617 err = register_framebuffer(&all->info); 618 err = register_framebuffer(&all->info);
618 if (err < 0) { 619 if (err < 0) {
619 fb_dealloc_cmap(&all->info.cmap); 620 fb_dealloc_cmap(&all->info.cmap);
620 leo_unmap_regs(all); 621 leo_unmap_regs(op, all);
621 kfree(all); 622 kfree(all);
622 return err; 623 return err;
623 } 624 }
@@ -638,18 +639,18 @@ static int __devinit leo_probe(struct of_device *dev, const struct of_device_id
638 return leo_init_one(op); 639 return leo_init_one(op);
639} 640}
640 641
641static int __devexit leo_remove(struct of_device *dev) 642static int __devexit leo_remove(struct of_device *op)
642{ 643{
643 struct all_info *all = dev_get_drvdata(&dev->dev); 644 struct all_info *all = dev_get_drvdata(&op->dev);
644 645
645 unregister_framebuffer(&all->info); 646 unregister_framebuffer(&all->info);
646 fb_dealloc_cmap(&all->info.cmap); 647 fb_dealloc_cmap(&all->info.cmap);
647 648
648 leo_unmap_regs(all); 649 leo_unmap_regs(op, all);
649 650
650 kfree(all); 651 kfree(all);
651 652
652 dev_set_drvdata(&dev->dev, NULL); 653 dev_set_drvdata(&op->dev, NULL);
653 654
654 return 0; 655 return 0;
655} 656}
diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
index 5b75ae4e94..df934bd218 100644
--- a/drivers/video/nvidia/nv_backlight.c
+++ b/drivers/video/nvidia/nv_backlight.c
@@ -141,7 +141,7 @@ void nvidia_bl_init(struct nvidia_par *par)
141 141
142 snprintf(name, sizeof(name), "nvidiabl%d", info->node); 142 snprintf(name, sizeof(name), "nvidiabl%d", info->node);
143 143
144 bd = backlight_device_register(name, par, &nvidia_bl_data); 144 bd = backlight_device_register(name, info->dev, par, &nvidia_bl_data);
145 if (IS_ERR(bd)) { 145 if (IS_ERR(bd)) {
146 info->bl_dev = NULL; 146 info->bl_dev = NULL;
147 printk(KERN_WARNING "nvidia: Backlight registration failed\n"); 147 printk(KERN_WARNING "nvidia: Backlight registration failed\n");
diff --git a/drivers/video/p9100.c b/drivers/video/p9100.c
index 56ac51d6a7..637b78bb4b 100644
--- a/drivers/video/p9100.c
+++ b/drivers/video/p9100.c
@@ -297,7 +297,8 @@ static int __devinit p9100_init_one(struct of_device *op)
297 all->info.screen_base = of_ioremap(&op->resource[2], 0, 297 all->info.screen_base = of_ioremap(&op->resource[2], 0,
298 all->par.fbsize, "p9100 ram"); 298 all->par.fbsize, "p9100 ram");
299 if (!all->info.screen_base) { 299 if (!all->info.screen_base) {
300 of_iounmap(all->par.regs, sizeof(struct p9100_regs)); 300 of_iounmap(&op->resource[0],
301 all->par.regs, sizeof(struct p9100_regs));
301 kfree(all); 302 kfree(all);
302 return -ENOMEM; 303 return -ENOMEM;
303 } 304 }
@@ -306,8 +307,10 @@ static int __devinit p9100_init_one(struct of_device *op)
306 p9100_blank(0, &all->info); 307 p9100_blank(0, &all->info);
307 308
308 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { 309 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
309 of_iounmap(all->par.regs, sizeof(struct p9100_regs)); 310 of_iounmap(&op->resource[0],
310 of_iounmap(all->info.screen_base, all->par.fbsize); 311 all->par.regs, sizeof(struct p9100_regs));
312 of_iounmap(&op->resource[2],
313 all->info.screen_base, all->par.fbsize);
311 kfree(all); 314 kfree(all);
312 return -ENOMEM; 315 return -ENOMEM;
313 } 316 }
@@ -317,8 +320,10 @@ static int __devinit p9100_init_one(struct of_device *op)
317 err = register_framebuffer(&all->info); 320 err = register_framebuffer(&all->info);
318 if (err < 0) { 321 if (err < 0) {
319 fb_dealloc_cmap(&all->info.cmap); 322 fb_dealloc_cmap(&all->info.cmap);
320 of_iounmap(all->par.regs, sizeof(struct p9100_regs)); 323 of_iounmap(&op->resource[0],
321 of_iounmap(all->info.screen_base, all->par.fbsize); 324 all->par.regs, sizeof(struct p9100_regs));
325 of_iounmap(&op->resource[2],
326 all->info.screen_base, all->par.fbsize);
322 kfree(all); 327 kfree(all);
323 return err; 328 return err;
324 } 329 }
@@ -340,19 +345,19 @@ static int __devinit p9100_probe(struct of_device *dev, const struct of_device_i
340 return p9100_init_one(op); 345 return p9100_init_one(op);
341} 346}
342 347
343static int __devexit p9100_remove(struct of_device *dev) 348static int __devexit p9100_remove(struct of_device *op)
344{ 349{
345 struct all_info *all = dev_get_drvdata(&dev->dev); 350 struct all_info *all = dev_get_drvdata(&op->dev);
346 351
347 unregister_framebuffer(&all->info); 352 unregister_framebuffer(&all->info);
348 fb_dealloc_cmap(&all->info.cmap); 353 fb_dealloc_cmap(&all->info.cmap);
349 354
350 of_iounmap(all->par.regs, sizeof(struct p9100_regs)); 355 of_iounmap(&op->resource[0], all->par.regs, sizeof(struct p9100_regs));
351 of_iounmap(all->info.screen_base, all->par.fbsize); 356 of_iounmap(&op->resource[2], all->info.screen_base, all->par.fbsize);
352 357
353 kfree(all); 358 kfree(all);
354 359
355 dev_set_drvdata(&dev->dev, NULL); 360 dev_set_drvdata(&op->dev, NULL);
356 361
357 return 0; 362 return 0;
358} 363}
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
index 38eb0b69c2..b4947c8107 100644
--- a/drivers/video/pxafb.c
+++ b/drivers/video/pxafb.c
@@ -1216,7 +1216,7 @@ static int __init pxafb_parse_options(struct device *dev, char *options)
1216 done: 1216 done:
1217 if (res_specified) { 1217 if (res_specified) {
1218 dev_info(dev, "overriding resolution: %dx%d\n", xres, yres); 1218 dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
1219 inf->xres = xres; inf->yres = yres; 1219 inf->modes[0].xres = xres; inf->modes[0].yres = yres;
1220 } 1220 }
1221 if (bpp_specified) 1221 if (bpp_specified)
1222 switch (bpp) { 1222 switch (bpp) {
@@ -1225,48 +1225,48 @@ static int __init pxafb_parse_options(struct device *dev, char *options)
1225 case 4: 1225 case 4:
1226 case 8: 1226 case 8:
1227 case 16: 1227 case 16:
1228 inf->bpp = bpp; 1228 inf->modes[0].bpp = bpp;
1229 dev_info(dev, "overriding bit depth: %d\n", bpp); 1229 dev_info(dev, "overriding bit depth: %d\n", bpp);
1230 break; 1230 break;
1231 default: 1231 default:
1232 dev_err(dev, "Depth %d is not valid\n", bpp); 1232 dev_err(dev, "Depth %d is not valid\n", bpp);
1233 } 1233 }
1234 } else if (!strncmp(this_opt, "pixclock:", 9)) { 1234 } else if (!strncmp(this_opt, "pixclock:", 9)) {
1235 inf->pixclock = simple_strtoul(this_opt+9, NULL, 0); 1235 inf->modes[0].pixclock = simple_strtoul(this_opt+9, NULL, 0);
1236 dev_info(dev, "override pixclock: %ld\n", inf->pixclock); 1236 dev_info(dev, "override pixclock: %ld\n", inf->modes[0].pixclock);
1237 } else if (!strncmp(this_opt, "left:", 5)) { 1237 } else if (!strncmp(this_opt, "left:", 5)) {
1238 inf->left_margin = simple_strtoul(this_opt+5, NULL, 0); 1238 inf->modes[0].left_margin = simple_strtoul(this_opt+5, NULL, 0);
1239 dev_info(dev, "override left: %u\n", inf->left_margin); 1239 dev_info(dev, "override left: %u\n", inf->modes[0].left_margin);
1240 } else if (!strncmp(this_opt, "right:", 6)) { 1240 } else if (!strncmp(this_opt, "right:", 6)) {
1241 inf->right_margin = simple_strtoul(this_opt+6, NULL, 0); 1241 inf->modes[0].right_margin = simple_strtoul(this_opt+6, NULL, 0);
1242 dev_info(dev, "override right: %u\n", inf->right_margin); 1242 dev_info(dev, "override right: %u\n", inf->modes[0].right_margin);
1243 } else if (!strncmp(this_opt, "upper:", 6)) { 1243 } else if (!strncmp(this_opt, "upper:", 6)) {
1244 inf->upper_margin = simple_strtoul(this_opt+6, NULL, 0); 1244 inf->modes[0].upper_margin = simple_strtoul(this_opt+6, NULL, 0);
1245 dev_info(dev, "override upper: %u\n", inf->upper_margin); 1245 dev_info(dev, "override upper: %u\n", inf->modes[0].upper_margin);
1246 } else if (!strncmp(this_opt, "lower:", 6)) { 1246 } else if (!strncmp(this_opt, "lower:", 6)) {
1247 inf->lower_margin = simple_strtoul(this_opt+6, NULL, 0); 1247 inf->modes[0].lower_margin = simple_strtoul(this_opt+6, NULL, 0);
1248 dev_info(dev, "override lower: %u\n", inf->lower_margin); 1248 dev_info(dev, "override lower: %u\n", inf->modes[0].lower_margin);
1249 } else if (!strncmp(this_opt, "hsynclen:", 9)) { 1249 } else if (!strncmp(this_opt, "hsynclen:", 9)) {
1250 inf->hsync_len = simple_strtoul(this_opt+9, NULL, 0); 1250 inf->modes[0].hsync_len = simple_strtoul(this_opt+9, NULL, 0);
1251 dev_info(dev, "override hsynclen: %u\n", inf->hsync_len); 1251 dev_info(dev, "override hsynclen: %u\n", inf->modes[0].hsync_len);
1252 } else if (!strncmp(this_opt, "vsynclen:", 9)) { 1252 } else if (!strncmp(this_opt, "vsynclen:", 9)) {
1253 inf->vsync_len = simple_strtoul(this_opt+9, NULL, 0); 1253 inf->modes[0].vsync_len = simple_strtoul(this_opt+9, NULL, 0);
1254 dev_info(dev, "override vsynclen: %u\n", inf->vsync_len); 1254 dev_info(dev, "override vsynclen: %u\n", inf->modes[0].vsync_len);
1255 } else if (!strncmp(this_opt, "hsync:", 6)) { 1255 } else if (!strncmp(this_opt, "hsync:", 6)) {
1256 if (simple_strtoul(this_opt+6, NULL, 0) == 0) { 1256 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1257 dev_info(dev, "override hsync: Active Low\n"); 1257 dev_info(dev, "override hsync: Active Low\n");
1258 inf->sync &= ~FB_SYNC_HOR_HIGH_ACT; 1258 inf->modes[0].sync &= ~FB_SYNC_HOR_HIGH_ACT;
1259 } else { 1259 } else {
1260 dev_info(dev, "override hsync: Active High\n"); 1260 dev_info(dev, "override hsync: Active High\n");
1261 inf->sync |= FB_SYNC_HOR_HIGH_ACT; 1261 inf->modes[0].sync |= FB_SYNC_HOR_HIGH_ACT;
1262 } 1262 }
1263 } else if (!strncmp(this_opt, "vsync:", 6)) { 1263 } else if (!strncmp(this_opt, "vsync:", 6)) {
1264 if (simple_strtoul(this_opt+6, NULL, 0) == 0) { 1264 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1265 dev_info(dev, "override vsync: Active Low\n"); 1265 dev_info(dev, "override vsync: Active Low\n");
1266 inf->sync &= ~FB_SYNC_VERT_HIGH_ACT; 1266 inf->modes[0].sync &= ~FB_SYNC_VERT_HIGH_ACT;
1267 } else { 1267 } else {
1268 dev_info(dev, "override vsync: Active High\n"); 1268 dev_info(dev, "override vsync: Active High\n");
1269 inf->sync |= FB_SYNC_VERT_HIGH_ACT; 1269 inf->modes[0].sync |= FB_SYNC_VERT_HIGH_ACT;
1270 } 1270 }
1271 } else if (!strncmp(this_opt, "dpc:", 4)) { 1271 } else if (!strncmp(this_opt, "dpc:", 4)) {
1272 if (simple_strtoul(this_opt+4, NULL, 0) == 0) { 1272 if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index 345e8b1c1a..1a13966b7d 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -384,7 +384,7 @@ static void riva_bl_init(struct riva_par *par)
384 384
385 snprintf(name, sizeof(name), "rivabl%d", info->node); 385 snprintf(name, sizeof(name), "rivabl%d", info->node);
386 386
387 bd = backlight_device_register(name, par, &riva_bl_data); 387 bd = backlight_device_register(name, info->dev, par, &riva_bl_data);
388 if (IS_ERR(bd)) { 388 if (IS_ERR(bd)) {
389 info->bl_dev = NULL; 389 info->bl_dev = NULL;
390 printk(KERN_WARNING "riva: Backlight registration failed\n"); 390 printk(KERN_WARNING "riva: Backlight registration failed\n");
diff --git a/drivers/video/sa1100fb.c b/drivers/video/sa1100fb.c
index cd10b18150..5d2a4a4b73 100644
--- a/drivers/video/sa1100fb.c
+++ b/drivers/video/sa1100fb.c
@@ -1200,9 +1200,9 @@ static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
1200 * Our LCD controller task (which is called when we blank or unblank) 1200 * Our LCD controller task (which is called when we blank or unblank)
1201 * via keventd. 1201 * via keventd.
1202 */ 1202 */
1203static void sa1100fb_task(void *dummy) 1203static void sa1100fb_task(struct work_struct *w)
1204{ 1204{
1205 struct sa1100fb_info *fbi = dummy; 1205 struct sa1100fb_info *fbi = container_of(w, struct sa1100fb_info, task);
1206 u_int state = xchg(&fbi->task_state, -1); 1206 u_int state = xchg(&fbi->task_state, -1);
1207 1207
1208 set_ctrlr_state(fbi, state); 1208 set_ctrlr_state(fbi, state);
@@ -1444,7 +1444,7 @@ static struct sa1100fb_info * __init sa1100fb_init_fbinfo(struct device *dev)
1444 fbi->max_bpp / 8; 1444 fbi->max_bpp / 8;
1445 1445
1446 init_waitqueue_head(&fbi->ctrlr_wait); 1446 init_waitqueue_head(&fbi->ctrlr_wait);
1447 INIT_WORK(&fbi->task, sa1100fb_task, fbi); 1447 INIT_WORK(&fbi->task, sa1100fb_task);
1448 init_MUTEX(&fbi->ctrlr_sem); 1448 init_MUTEX(&fbi->ctrlr_sem);
1449 1449
1450 return fbi; 1450 return fbi;
diff --git a/drivers/video/tcx.c b/drivers/video/tcx.c
index 6990ab11cd..5a99669232 100644
--- a/drivers/video/tcx.c
+++ b/drivers/video/tcx.c
@@ -350,18 +350,23 @@ struct all_info {
350 struct tcx_par par; 350 struct tcx_par par;
351}; 351};
352 352
353static void tcx_unmap_regs(struct all_info *all) 353static void tcx_unmap_regs(struct of_device *op, struct all_info *all)
354{ 354{
355 if (all->par.tec) 355 if (all->par.tec)
356 of_iounmap(all->par.tec, sizeof(struct tcx_tec)); 356 of_iounmap(&op->resource[7],
357 all->par.tec, sizeof(struct tcx_tec));
357 if (all->par.thc) 358 if (all->par.thc)
358 of_iounmap(all->par.thc, sizeof(struct tcx_thc)); 359 of_iounmap(&op->resource[9],
360 all->par.thc, sizeof(struct tcx_thc));
359 if (all->par.bt) 361 if (all->par.bt)
360 of_iounmap(all->par.bt, sizeof(struct bt_regs)); 362 of_iounmap(&op->resource[8],
363 all->par.bt, sizeof(struct bt_regs));
361 if (all->par.cplane) 364 if (all->par.cplane)
362 of_iounmap(all->par.cplane, all->par.fbsize * sizeof(u32)); 365 of_iounmap(&op->resource[4],
366 all->par.cplane, all->par.fbsize * sizeof(u32));
363 if (all->info.screen_base) 367 if (all->info.screen_base)
364 of_iounmap(all->info.screen_base, all->par.fbsize); 368 of_iounmap(&op->resource[0],
369 all->info.screen_base, all->par.fbsize);
365} 370}
366 371
367static int __devinit tcx_init_one(struct of_device *op) 372static int __devinit tcx_init_one(struct of_device *op)
@@ -398,7 +403,7 @@ static int __devinit tcx_init_one(struct of_device *op)
398 all->par.fbsize, "tcx ram"); 403 all->par.fbsize, "tcx ram");
399 if (!all->par.tec || !all->par.thc || 404 if (!all->par.tec || !all->par.thc ||
400 !all->par.bt || !all->info.screen_base) { 405 !all->par.bt || !all->info.screen_base) {
401 tcx_unmap_regs(all); 406 tcx_unmap_regs(op, all);
402 kfree(all); 407 kfree(all);
403 return -ENOMEM; 408 return -ENOMEM;
404 } 409 }
@@ -409,7 +414,7 @@ static int __devinit tcx_init_one(struct of_device *op)
409 all->par.fbsize * sizeof(u32), 414 all->par.fbsize * sizeof(u32),
410 "tcx cplane"); 415 "tcx cplane");
411 if (!all->par.cplane) { 416 if (!all->par.cplane) {
412 tcx_unmap_regs(all); 417 tcx_unmap_regs(op, all);
413 kfree(all); 418 kfree(all);
414 return -ENOMEM; 419 return -ENOMEM;
415 } 420 }
@@ -461,7 +466,7 @@ static int __devinit tcx_init_one(struct of_device *op)
461 tcx_blank(FB_BLANK_UNBLANK, &all->info); 466 tcx_blank(FB_BLANK_UNBLANK, &all->info);
462 467
463 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { 468 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
464 tcx_unmap_regs(all); 469 tcx_unmap_regs(op, all);
465 kfree(all); 470 kfree(all);
466 return -ENOMEM; 471 return -ENOMEM;
467 } 472 }
@@ -472,7 +477,7 @@ static int __devinit tcx_init_one(struct of_device *op)
472 err = register_framebuffer(&all->info); 477 err = register_framebuffer(&all->info);
473 if (err < 0) { 478 if (err < 0) {
474 fb_dealloc_cmap(&all->info.cmap); 479 fb_dealloc_cmap(&all->info.cmap);
475 tcx_unmap_regs(all); 480 tcx_unmap_regs(op, all);
476 kfree(all); 481 kfree(all);
477 return err; 482 return err;
478 } 483 }
@@ -495,18 +500,18 @@ static int __devinit tcx_probe(struct of_device *dev, const struct of_device_id
495 return tcx_init_one(op); 500 return tcx_init_one(op);
496} 501}
497 502
498static int __devexit tcx_remove(struct of_device *dev) 503static int __devexit tcx_remove(struct of_device *op)
499{ 504{
500 struct all_info *all = dev_get_drvdata(&dev->dev); 505 struct all_info *all = dev_get_drvdata(&op->dev);
501 506
502 unregister_framebuffer(&all->info); 507 unregister_framebuffer(&all->info);
503 fb_dealloc_cmap(&all->info.cmap); 508 fb_dealloc_cmap(&all->info.cmap);
504 509
505 tcx_unmap_regs(all); 510 tcx_unmap_regs(op, all);
506 511
507 kfree(all); 512 kfree(all);
508 513
509 dev_set_drvdata(&dev->dev, NULL); 514 dev_set_drvdata(&op->dev, NULL);
510 515
511 return 0; 516 return 0;
512} 517}